[HN Gopher] Show HN: I wrote my own RTS game engine in C
___________________________________________________________________
Show HN: I wrote my own RTS game engine in C
Author : epermyakov
Score : 685 points
Date : 2021-05-12 16:44 UTC (6 hours ago)
(HTM) web link (github.com)
(TXT) w3m dump (github.com)
| ghostbrainalpha wrote:
| Do you develop this game on Twitch at all? I'd love to watch the
| work being done.
| optymizer wrote:
| As someone who's working on his own game engine in C, I applaud
| you for releasing an engine, a game and with such great code
| quality!
|
| Thank you for open sourcing it as well. I've already learnt a
| thing or two by skimming the code.
| geniium wrote:
| Well done! Very nice to see that this is still possible :)
| Rendello wrote:
| I love the wooden AT-AT.
| kleer001 wrote:
| I think that's Babba Yaga's house with chicken legs.
| Andrew_nenakhov wrote:
| It got two legs, so it's more like AT-ST
| logical_proof wrote:
| There is an AT-AT right next to them.
| mouldysammich wrote:
| This is very cool, In my head, writing a game engine seems like
| one of the real 'final frontier' projects -- an os, a
| compiler/language, a game engine all feel like similar levels of
| project insane complexity with limitless scope.
|
| Every time I've attempted even the basics of graphics programming
| I very much get scared off when it doesnt click quickly (if
| anyone has tips on how to get into it, it would surely be
| appreciated :))
| idiotsecant wrote:
| Sometimes I feel like i'm an untalented, unproductive waste of
| oxygen.
|
| Then I see a post like this and know for sure that I am.
| [deleted]
| AnIdiotOnTheNet wrote:
| Eh, yeah, it can feel like that, but the probably reality is
| that you just have different priorities in life. Especially as
| you get older and it starts to sink in how finite your time is,
| you can't let yourself be fooled into thinking you _have_ to
| accomplish certain things to be worthy.
|
| I program, rock climb, ride bikes, and write. For any given one
| of those I can easily find 10,000 people who are more
| accomplished than I am and often at a younger age. I accept
| that I will never be that good at any of them, not because I
| _can 't_ be, but because I don't want to invest that much of
| myself into one of them. There's nothing wrong with that.
| weerd wrote:
| Don't discount the creativity, intelligence, and dedication
| it takes to create something like this. Chances are you
| actually _can 't_, even if you did make it a priority.
| ironmagma wrote:
| Nonsense. Sure, they wouldn't make this exact game, but
| neither would the entire rest of the population who is
| capable of making a project like this. Most people are
| roughly the same in terms of physical and mental
| capability, and if you need to convince yourself of that,
| think about how fast a computer can do an arbitrary thing
| versus how fast a human can, or how different a mouse's
| musical intellect is from a human's.
| oogabooga123 wrote:
| > Most people are roughly the same in terms of physical
| and mental capability
|
| This is a story we stop telling kids around the end of
| high school. We tell this story because, as a child,
| being told you're dumb can stunt intellectual growth, or
| being told you're not physically capable can stop kids
| from forming a habit of exercising.
| ironmagma wrote:
| I don't mean it in the way it's sometimes expressed as,
| "you can train anyone to do anything," I mean it in the
| sense that the 50%ile capable person is really all things
| considered, not that different from the 95%ile capable
| person. The range is just not that high. A person can
| only accomplish so much in the day and with the animal
| body we are given. Compare that to a computer, which for
| many tasks, can accomplish things at a rate 10,000,000
| times faster than a human.
| oogabooga123 wrote:
| > I mean it in the sense that the 50%ile capable person
| is really all things considered, not that different from
| the 95%ile capable person.
|
| You must be living on a different planet from me. I can
| kind of see how someone might be tempted to just say "you
| know what, you're right" and let you keep on thinking
| that, though.
| ironmagma wrote:
| Maybe it's born out of all these times I've seen "10x
| engineers" hired, or "very senior" managers who will
| "change everything." There's just not that much that one
| human can do that is fundamentally different from what
| the median human can, so these hires are almost always
| overblown.
| fao_ wrote:
| Both my parents are MENSAns. I agree with the parent
| poster, there isn't specifically anything special about
| being a 95%ile, and most of the members of the 95%ile
| that have joined MENSA aren't massively successful, any
| more than anyone on the middle of the bell curve.
|
| It's not, what you have. It's what you do with it. I
| struggle with some things my parents find easy, vice
| versa, most of the 95%ile that I know have various mental
| health problems or other hidden disabilities that make
| daily life difficult -- especially achieving something
| like this.
|
| And Feynman went far with being just an ordinary person
| supposedly slightly lower on the bell curve.
|
| The only thing that actually tangibly matters is
| dedication and sweat, and how much time and effort you're
| willing to put in to something.
|
| edit: of course, that's not to outright say that an IQ
| test or _however you want to measure cognitive "capital"_
| isn't valuable in some aspect -- it does measure
| _something_ , after all. Less fighter pilots died in
| training once they started selecting using early IQ tests
| (Source is a psych book from the 80s I skimmed a few
| years back :P). But that's an extreme case. For projects
| like this, for most of the things you will ever, ever
| want to do, it outright does not matter and the emphasis
| on it in programming and "intellectual circles" (on the
| internet, I don't think anyone in real life actually
| gives a shit outside of college admissions) is massively
| overblown.
| christiansakai wrote:
| You can still be a consumer/buyer, like me. Together we make
| the world go round and around.
| ysavir wrote:
| It's easy to feel discouraged, but keep in mind:
|
| 1. The author didn't write this overnight. The oldest commits
| go back to Oct. 2017, three and a half years ago. Imagine what
| you could accomplish if you worked on something for three and a
| half years.
|
| 2. There are many things we can do with our time, and
| ultimately we do them all to be happy. Don't measure your own
| worth by how much product you leave behind. Measure it instead
| by how happy you are today. Most likely the OP wrote this code
| because working on it made them happy, and that's great. For
| many of us, though, the activities that make us happy don't
| have biproducts. But that doesn't detract from how happy those
| activities make us. Value the things that you do because they
| make you happy, not because they appear impressive when held
| against some external grading scheme.
|
| Edit: list formatting
| nonbirithm wrote:
| I wish more people like the author of the OP would feel free
| to admit things like they were compelled to finish the
| project because they couldn't see anything else they felt
| like doing with their time, so that's simply where all the
| time went. That would make perfect sense in my mind, and
| restore a notion of calm.
|
| One problem is making assumptions that the author is trying
| to prove something by a clear display of superiority. The
| code itself is of a high quality, from what other people are
| saying. But it's probably only because so much effort was put
| in for three years on it.
|
| Also, I have to wonder how many other doors the author left
| closed because he spent so much time on this project. Was
| there anything else of a similar impact that he contributed
| to for all those years? And what of the other things he may
| have passed up?
|
| Some projects will consume you. They will be the tantalizing
| activity pulling you away from Friday night dinner parties
| with people you don't understand and other miscellaneous
| outings that are comparatively less interesting. You
| constantly think you're leaving something unsaid or undone
| away from a keyboard. In some cases you feel obligated to
| continue for no reason other than having already come so
| close to accomplishing the thing, sunk costs and all.
|
| With some projects, hypothetically, if someone is to see me
| in a cafe with nothing better to do, I'm almost certainly
| going to wrap up my current conversation after a point and
| take out my laptop to continue working. That is how my life
| is structured with those projects. That is how they affect my
| actions day after day. It isn't necessarily a life of glory.
|
| Working on projects and having the finished product in my
| hands is not what brings me happiness; it merely staves off
| misery. It fills a void in my life that was agonizing up to
| that point. My theory is that if your goal is to avoid misery
| and despair at any cost, and have the means to do so, you can
| be driven out of desperation to accomplish substantial
| things. Other people could see what I did and make their own
| guesses as to what it took. But really I was only trying to
| prevent myself from becoming undone. It was simply too
| irritating of a problem for me to leave alone. I'll probably
| never be able to fully explain why. It certainly wasn't
| because I was trying to prove something to other people.
|
| But I'm only speaking from my personal experience. It's not
| like I actually understand why the author did what he did.
| People just don't seem to know at the moment, and maybe
| that's where the air of sadness over suddenly seeing this
| accomplishment come out of nowhere originates. There's
| nothing to counterbalance the impact of learning of its
| existence within a split second with what actually went on
| behind the scenes for many orders of magnitude longer.
| e_tm_ wrote:
| Came here to say this. Kudos to the author.
| markus_zhang wrote:
| How about we setup a plan to develop something similar and
| stick to it for a few months and see what happens?
|
| I mean this is definitely a piece of gem, but nothing is
| exactly high tech or hugely difficult. And if you don't think
| you can make it, you can lower the target and create a, say, a
| 2d rpg engine that emulates Ultima IV or Pool of Radiance,
| those pioneers of RPG. For art assets you can use free
| resources or purchase inexpensive ones.
|
| I really think that's achievable for pretty much every
| programmer. After all in some universities they give you a
| similar task as a project for advanced game programming
| classes.
| p1esk wrote:
| I blame Netflix instead
| hutzlibu wrote:
| Blaming is easy.
|
| Start doing things is easy, too.
|
| Finishing stuff, is hard.
|
| The trick is to gradually work your way up from small,
| completed projects. If you start big, you probably fail big.
| deckard1 wrote:
| Yep. All big projects started as small projects.
|
| The hard part is justifying the time spent on a project.
| You often start a project and feel like it's not the best
| use of your time. That you may be the only one to use the
| project or find value in the project and that's enough to
| kill motivation. Why start a business if the vast majority
| of businesses fail? Why start a business when there is
| already so much competition? Why write a novel when there
| is no hope of selling it? Then there are the "I'm too old
| for..." thoughts.
|
| These thoughts eat away at people.
|
| If someone pointed me to my purpose project and told me if
| I were to keep at it that I would find guaranteed success,
| then I would have an infinite well of energy at my
| disposal. But of course, no one is there to tell you that.
| einpoklum wrote:
| 1. Fight try to measure yourself up against the most talented
| person you can think of. Can you code? Well, then, there are
| plenty of FOSS projects in the languages you know which could
| use your help. Can't code? Not a problem, do QA work then,
| that's important and very useful and not enough people do it
| seriously.
|
| 2. Seek self-fulfillment and purpose in other aspects of your
| life. I am 100% sure the people around you - family, community,
| neighborhood, etc. - could use someone who devotes some time
| for doing good. Sure, it might not be what you had assumed you
| would gain fame and glory doing, but so what?
|
| I'd be more specific but obviously I don't know anything about
| you or where you live or what you do.
| Hydraulix9899 wrote:
| The power is within you to change that, you know?
| etaioinshrdlu wrote:
| Another thing that blew my mind recently was that Rollercoaster
| Tycoon, a fairly complex game, was hand written in x86
| assembly...
|
| Although, this is less crazy when you think about how heavily you
| can use macros, and sort of roll your own high-level language
| yourself.
| m_mueller wrote:
| > use macros, and sort of roll your own high-level language
| yourself.
|
| See also Engelbart & Co. Amazing how productive this approach
| can be.
| ashdev wrote:
| This is super impressive considering it's written in C. Well done
| and keep it up.
| lucasverra wrote:
| Just came to congratulate the human effort! One can only imagine
| the hours of frustation to bypass to produce this (oneman)
| production. Enjoy the first page of HN !
| Dzugaru wrote:
| This is huge. I have a pet RTS project too, and the stuff is
| really complex. The information on large-scale pathfinding for
| example (ClearPath etc.) is scarce. And I do it on Unity3D/C#,
| doing this on homemade engine is pure insanity.
| tomcam wrote:
| Who does the artwork? It's definitely pro quality. Please tell me
| it's not also the developer because I may want to kill myself at
| this point.
| RhodoGSA wrote:
| Looking through the assets on github, it seems he has done some
| work himself and gotten some off OpenGameArt.org
| aiisjustanif wrote:
| Hahaha, my thoughts are similar.
| 6581 wrote:
| According to the Steam page: "I am a one-man development team
| doing everything from writing the engine from scratch in C99 to
| modeling all the 3D assets in Blender."
| tomcam wrote:
| Goodbye, cruel world.
| jart wrote:
| Goodbye, goodbye... goodbye.
| legerdemain wrote:
| Is that a reference to the Monkees' Porpoise Song?
| panopticon wrote:
| 2D art or 3D art? If the former, it looks like some of that is
| from existing art (e.g., "Bear Rider" is clearly from https://e
| n.wikipedia.org/wiki/Bogatyr#/media/File:Viktor_Vas...).
|
| The latter is made by the developer, but I wouldn't call those
| assets "pro quality". This isn't to diminish the astonishing
| amount of effort that went into the project though!
| johnwheeler wrote:
| After seeing this...
|
| Newbie: "I need to start programming!"
|
| Veteran: "I should stop programming."
| charlie_hebert wrote:
| Awesome looking project.
|
| I couldn't find any tests in the project. How do you test things
| and maintain it?
| trevor-e wrote:
| This looks like some high-quality code so I was also looking
| forward to learn how good unit tests look in C. Was surprised
| to not find any, at least for the engine part of the code.
| qwertox wrote:
| The Engine Summary is really impressive for a solo project.
| dilap wrote:
| Are the unit behaviors coded in C, or some scripting/config
| language?
| epermyakov wrote:
| All the fundamental behaviours (movement, combat, resource
| harvesting) are implemented in C.
|
| The engine uses Python as a scripting/config language. You can
| use it to hook into a lot of events pushed from the engine core
| (unit got selected, unit started movement, unit started
| harvesting, etc.) and customize or change the unit behaviours.
| garaetjjte wrote:
| Why Python though (and not lua or something)? It is rather
| annoying to use as embedded language.
| epermyakov wrote:
| My initial idea was that I wanted a more "sexy" language
| for scripting. Python is a lot more popular and (arguably)
| more enjoyable to use than Lua. There's a lot of cool stuff
| like list comprehensions. Plus I had a selfish reason of
| just wanting to learn more Python and fool around with the
| CPython code.
|
| Over the duration of the project, I really did learn to
| appreciate why Lua is embedded into games and Python isn't.
| Lua is really small and you have full control over
| everything. And you're eventually going to need that
| control when you implement features like reflection,
| pausing the game, etc. CPython is this big shared library
| that does its' own thing and you have a lot less control
| over. The parts where it just doesn't expose enough through
| its' API do do what you want is a real huge pain. I ended
| up writing a bunch of code to serialize all the internal
| data structures and this was a massive chore. Also you have
| a lot less control over CPython's performance and memory
| allocations.
|
| I didn't really appreciate these things when I started the
| project so hence I went with Python. But since I ended up
| doing it, I guess you can still enjoy the benefits of it.
| dilap wrote:
| Interesting; thx for the answer!
| kleer001 wrote:
| Oh wow, that's pretty darn cool.
|
| I like the Babba Yaga as a unit, lol!
| SavantIdiot wrote:
| Impressive! And excellent coding style. I attempted to write an
| RTS at least 5 times in the past 30 years and could never stay
| focused, so I'm seriously impressed by this. In C no less!
|
| How did you stay focused? And how did you segment the work? It
| requires progressive refinement to coordinate all of the systems.
| Wondering what order you took.
| Thaxll wrote:
| Looking at: https://www.youtube.com/watch?v=xleJeiOHHh4 the FPS
| seems very bad, is it an issue on the capture side? Nice and
| clean C otherwise!
| abledon wrote:
| yeah what is it like 15 fps? The repo says " It is made in the
| image of old classics, but incorporating some modern ideas."
|
| But does that mean low FPS too?
| bennysomething wrote:
| Can I ask how old are you and how long you've been programming
| for? This is an amazing achievement.
| feinte wrote:
| The devlog videos are great : https://github.com/eduard-
| permyakov/permafrost-engine#devlog
|
| Thank you so much for making this in the open and documenting
| everything !
| OOPMan wrote:
| Why the engine internals exposed using Python 2.7 rather than
| Python 3?
|
| Regardless of how you feel about Python 2 vs Python 3...one is
| officially EOL and the other isn't...
| beaconstudios wrote:
| That's awesome! It's always exciting to see not only low level
| game development, but also RTS development - my favourite
| childhood genre. I think C has much underutilised potential as a
| game dev language, especially as data oriented design (eg ECS) is
| coming into prominence.
|
| I'm also building an open source game in my spare time, although
| it's nowhere near as far along as this (and I'm also a massive
| noob at game dev) - it's a civ-type game in three.js designed to
| showcase bottom up organising behaviour; think age of empires 2,
| if the villagers determined their own behaviour. I shared it on
| HN years ago but shelved it until recently when I was looking for
| a fun project to pick back up -
| https://github.com/ajeffrey/civarium.
| djoldman wrote:
| Quick question: all the goto fail's where fail:
| return false;
|
| This is just to perhaps change return false to something else in
| the future, correct? Else why not just return false everywhere
| instead of goto fail
| alksjdalkj wrote:
| Not sure if this is the author's reason but I find it helpful
| to have a single return point from functions. Much easier to
| follow code paths.
|
| You'll see this in some places in Linux's source too.
| slim wrote:
| Not op, but that's obviously in case you need to do something
| more complicated than returning false later. It's good practice
| namdnay wrote:
| I think it's to cleanly show when he is using his pseudo-
| exception handling system. So goto fail would be "throw"
| unknown_error wrote:
| Wow, this is incredibly impressive!
|
| As a web dev, I feel a moment of satisfaction when I manage to
| make a heading look right on both desktop and mobile. Lol, what
| you've done is several orders of magnitude more difficult... I
| could spend a lifetime coding and not even know how to start
| drawing the first pixel. Kudos!!
| vajrabum wrote:
| I got to poking around and found this reddit posting in which the
| author describes the features of the engine which includes an
| embedded python interpreter and saving restoring python state.
| https://www.reddit.com/r/C_Programming/comments/gwg5u5/openg...
| vajrabum wrote:
| Here's a trailer for a game the developer built using the
| engine https://www.youtube.com/watch?v=xleJeiOHHh4 and a devlog
| describing how he persists python interpreter state.
| https://www.youtube.com/watch?v=ch-zjn05gxQ
| offtop5 wrote:
| Any reason why you went with GPL.
|
| Unless you only want to encourage open source video games, this
| is much more restrictive than an outright commercial license.
| Have you considered dual licensing at all, maybe I send you
| $1,000 or so and I get to use this in a commercial project.
|
| I absolutely love rts's , I love looking at a project like this
| but I don't know if I'd be open to developing an Open source One
| tomcam wrote:
| Amazing work, you mad lad. And not that many lines of code in my
| opinion--you're good. Do you feel you are missing any error
| handling or other infrastructure? How do you feel about C as a
| vehicle for that size project? Looks quite manageable to me.
| epermyakov wrote:
| Over the long development cycle of the project, I've
| accumulated a nice little library of data structures,
| allocators, and utilities (mostly in src/lib). Between those
| and the low-level engine systems such as the task scheduler and
| event system which have a generic API for any other system to
| make use of, I believe I have good foundations in place to
| develop new engine systems relatively easily. Of course, this
| required the initial investment of laying these foundations.
|
| Most error handling just consists of checking the return value
| of a call and propagating it up to the caller if necessary.
| Sometimes I also set an errno-like variable with an error
| message to check it in the top-level code. It's a bit wordy but
| obvious and sufficiently good for all my use cases.
|
| I don't think C limits the size of the project. It's all about
| good organization and coming up with the right higher-level
| protocols/conventions. This, IMHO, is what allows or prevents
| the code size from scaling gracefully.
| tomcam wrote:
| My experience in C as well. Have been questioning my own
| sanity over the years when I read about the language because
| I get such a different impressions of it from people on this
| very site, so it's a relief to get your perspective.
| throwaway88j wrote:
| Are there any features you would like in C that would make
| things easier? I'm writing a c compiler and adding low
| hanging stuff such as removing forward declarations and
| supporting multiple returns. One thing I'm flip flopping on
| is function overloading for example. I'd appreciate your
| opinion.
| epermyakov wrote:
| I guess the "shtick" of C is that it has a small and
| obvious feature set. The readability and style of
| programming follows from that. As you start adding more and
| more language features and constructs, you start getting
| all the other languages that were derived from C and you no
| longer have C.
|
| During the development of the project, I had a thought that
| it would be nice to have a RAII/defer mechanism to get rid
| of repetitive code for freeing resources at the end of a
| function. But I'm not sure if that's really necessary since
| you can just put the 'free' calls at the end of the
| function and insert some labels between them in a kind of
| 'stack'. This perhaps is more in the spirit of the language
| - a bit more wordy, but having less voodoo done by the
| compiler.
| throwaway88j wrote:
| Interesting, I think defer as a statement might not be
| too much magic but it would be too complicated for my
| mostly single-pass approach.
|
| Thank you for your response.
| TravHatesMe wrote:
| Not OP but based on his comment about checking return
| values of stuff.. would be nice to have lightweight
| exceptions. could improve readability and debuggability,
| less if statements, generally easier to propagate errors up
| the call stack. my 2cents.
| visualradio wrote:
| Before substantially modifying the language, make sure your
| parser can still load vanilla C header files with no new
| features.
|
| This way if you accidentally create a new language,
| programmers will still be able to load existing C header
| files without having to manually write and maintain FFI
| bindings.
| hermitdev wrote:
| One question I have (and please don't take this as criticism
| or judgement, it's purely curiosity): why Python 2 and not
| Python 3? Was it because of when you started working on this,
| or were there some architectural/design issues that prevented
| use of Python 3?
| epermyakov wrote:
| Eh, I don't have a great justification why Python 2 should
| be used over Python 3. I made this choice like 3 years ago
| when I didn't know too much about Python. That's it. Since
| I wrote some code against the C API of the interpreter and
| made a whole bunch of scripts already, it's a massive chore
| to migrate. Classic story, I know. If I were to start a
| similar project today, I would attempt to use Python 3
| first.
|
| That being said, I did come across some discussions (ex:
| https://stackoverflow.com/questions/34724057/embed-
| python3-w...) where it is not possible to strip the
| standard library from Python 3. I think the use case of
| embedding strictly the interpreter without any "batteries"
| is not popular and thus has not been that well-maintained.
| I've not tested this in practice, however.
| hermitdev wrote:
| Cool. Thanks for the response. It's definitely an
| interesting project. As a long-time RTS fan, I'll be
| following this project closely. I hope to have some time
| soon to come back and give it a more thorough read.
| nattaylor wrote:
| I was curious about this too and looked around a bit. I see
| he has to do some inspection of python interpreter -- so
| maybe that, coupled with demos already within in python2
| are enough inertia to stay back on version 2.
| Scarbutt wrote:
| Shifting attention to keep every lib updated is a
| distraction from getting things done.
| blux wrote:
| Coming from C++, the main thing I am missing in C is generic
| data structures. Having to resort to macros to implement
| generic vectors (https://github.com/eduard-
| permyakov/permafrost-engine/blob/m...) I find cumbersome to
| say the least. It is also hard to beat the performance of the
| STL data structures when implementing something seemingly
| straightforward like a vector type.
| ilikeisometric wrote:
| The pathfinding video is awesome! Could you do a video on the
| rendering mechanism?
| lelanthran wrote:
| Since it's GPL, maybe someone can package it for Debian?
| tekno45 wrote:
| I hope this inspires someone to make a new kick ass RTS. I really
| miss the OG WC3 days.
| apocolyps6 wrote:
| Check out Back2Warcraft and W3Champions if you haven't yet
| gtirloni wrote:
| I checked the websites and I don't know what I'm looking at.
| What games are being played?
| rubidium wrote:
| Age of Empires 2 has experienced a resurgence recently.
| bfors wrote:
| Some people from Blizzard formed a company named Frost Giant
| and are apparently working on a new RTS.
| grawprog wrote:
| This looks really awesome. The screenshots from the demo game
| take me back to Warcraft 3 days. The code is clear and well
| organized. Everything about this project is well done and
| extremely professional looking.
| jokoon wrote:
| Did you implement netcode? A deterministic approach or not?
|
| I have to admit that would be quite the single feature I would be
| curious to learn about.
|
| All I know about RTS netcode is that if there are N players, each
| players "commits" an order, in a turn by turn manner, and all the
| game code, physics and behavior etc is entirely deterministic,
| which guarantees that all clients are always synchronized and
| don't need to share state (well there is some hashing system to
| detect if there is a bad sync, and I don't know if it's possible
| to rewind and cancel things).
|
| A RTS netcode doesn't seem difficult to implement, but making a
| deterministic RTS doesn't seem so easy, I think, especially if
| you have boids and other pathfinding cool things.
| Arnavion wrote:
| Interesting license choice - GPLv3 with a linking exception so
| that the final binary and other independent libraries are not
| GPLed. Is this common for game engines?
| CraigJPerry wrote:
| Very nice code quality.
|
| C gets a hard time and this code base highlights some of the
| modern features C is missing by its use of perfectly clear
| workarounds. E.g. The prefix "namespacing" done here works just
| fine, easy to understand. The go-style visibility approach is
| growing on me lately and it works well here.
|
| C does deserve some of the criticism right enough, e.g. the same
| macros re-defined in a few places - it'd be nice if c had a
| better way than its version of macros although its not actually a
| problem here because the macros aren't really big enough to have
| subtle sharp edges.
|
| Ahh a beautifully written project, just shows that maybe C is
| entirely workable in the right hands.
| kungito wrote:
| Workable for what? Is this production ready? How many
| refactorings can this code survive? Don't get me wrong, I
| haven't read this code so I'm not talking about this project
| spcifically, but I keep getting triggered by the apologism
| about languages with poor or no types. Can we finally drop this
| myth about "bad languages are good when used by smart people"?
| bsder wrote:
| > Ahh a beautifully written project, just shows that maybe C is
| entirely workable in the right hands.
|
| And because it is in _C_ , you can talk to it from Nim, Python,
| Rust, etc.
|
| And scripting is a very big part of RTS games.
| aydwi wrote:
| > And because it is in C
|
| I'm curious, what difference does it make if it was written
| in, say, Rust, or C++. Wouldn't you still be able to talk to
| it in a similar way? What's so special about C in this
| context?
| steveklabnik wrote:
| You can expose a C ABI from Rust, and some folks do, but it
| takes some work. Some people don't find that acceptable.
| tdhz77 wrote:
| To me, If it solves the problem it's acceptable.
| chris37879 wrote:
| The thing that's always special about C, it's basically the
| default goto programming language for calling from higher
| level code, most languages that support FFI do so by being
| able to communicate with C apis and having tools written
| around C. C also lacks more complex things like classes,
| it's much easier to build up a complex piece of software
| from C building blocks bound to your language. Think of
| like a struct that has a set of functions that operate on
| it. You can map that basically directly to a class
| definition in most higher level languages and then wrap up
| the c implementation details like memory management behind
| the scenes so you can produce a nice clean api in your
| chosen language to use.
|
| This practice is fairly common in python when you're
| dealing with AI (I'm sure there's other examples, but this
| is the one that sticks out to me.) SDKs like TensorFlow are
| written in a lower level language (C++ I think for TF) and
| then FFI called from python, so you can end up with a
| function like initTensorFlow() and calling it is enough to
| bring TF online and ready to start processing other data.
|
| And you may be thinking "Well, I can do all that in rust or
| go or <insert prefered language here>" and of course you
| can, ultimately it's all just a linker and compiler
| deciding where to put code and data in an executable, but C
| is the defacto standard and more tools from more languages
| are going to work well with it than say, rust or go. Which,
| now that I think about it, is probably why Rust supports
| defining a c api for your code, so it's easier to call from
| other platforms. Rust specifically tries to play nice with
| being embedded in existing projects because it makes it
| easier to adopt rust incrementally.
|
| Just my $0.02
| bsder wrote:
| C constructs normally map 1:1 in most languages. It's rare
| for a modern language to not be able to do all the things
| that C does. And, even if it's a little weird, it's not too
| hard to give out an escape hatch because the features
| aren't that advanced.
|
| C++ constructs--not so much.
|
| Does your language allow overloaded functions? If not,
| okay, you have to map that somehow (probably name
| mangling).
|
| Oh, your language has a different notion of inheritance
| than C++, well, now you need to map vtables somehow.
|
| And what does your system do about exceptions?
| Constructors/Destructors? Does it agree with the standard
| library about what a String is? What about memory
| allocation? etc.
|
| Even if the C++ ABI was perfectly described and
| standardized, mapping to it is always going to be error
| prone and clunky relative to the C ABI (which is just a lot
| simpler).
|
| If you want a good example, look at what it takes to use
| Vulkan via the C API/ABI--which is an exemplary
| implementation of an API, in my opinion. Look at the hoops
| you go through with loaders, structs that have type fields
| in them, extension fields so that you can add functionality
| without breaking compatibility, etc. All of that extra
| "gunk" is the kind of thing that C++ hides normally that
| gets terribly exposed when you have to cross an ABI
| boundary.
| visualradio wrote:
| If a project requires an open API like OpenGL, SDL, Vulkan
| which is documented and defined using ANSI C or C99 language
| constructs, then some amount of C is required regardless of the
| merits of the language. With high level language with large
| community maybe someone writes and maintains wrapper, library,
| or FFI binding for you but this relies on economy of scale and
| out-sourcing work. If a programmer doesn't understand a C API
| then writing a binding to a function they don't understand in
| order to test it is a point of friction which encourages
| returning to plain C. Ideally more of the "Better C" languages
| would retain ability to parse and compile vanilla C header
| files without manual binding. Zig attempts this but reduces the
| cognitive simplicity of the language by using structs as
| namespaces for holding local function definitions rather than
| as "plain old data".
| whateveracct wrote:
| > Ideally more of the "Better C" languages would retain
| ability to parse and compile vanilla C header files without
| manual binding.
|
| I've been doing a lot of zero-copy FFI work in Haskell. It
| became quite mechanical to create 100% literal bindings to C
| libs (Pointers and all), and it's nice to use it directly in
| Haskell as-is. I'm hoping I can write a simple tool to do
| exactly what you describe.
| visualradio wrote:
| For programmers which need to consume C APIs ideally the
| tool is the standard compiler. Eeverything gets handled at
| compile time without the need for community-maintained
| cache of bindings. New language designers start with a C
| compiler which handles header files, then extend compiler
| to also parse NewLang files. The in-memory representation
| is loaded from both source types, without throwing away the
| C functionality. In NewLang there is some standard
| namespace and calling convention.
| @importc "stdio.h" num : I32 : 123456789 fd
| : c:int : c:open(c:"file.txt", c:O_RDONLY) ::
| c:print("file:%d number:%d\n", fd, num)
|
| But nothing more, everything else is handled by compiler.
| whateveracct wrote:
| For a "Better C" language, that would be wonderful.
|
| For my Haskell ideas, generating Haskell from headers
| automatically feels like the best route. Especially if
| it's configurable to some degree. It's common that you
| can better type a C API with Haskell than C ever could.
| Usually with techniques like IO, phantom types, GADTs,
| and the new linear types.
| visualradio wrote:
| The chicken-and-egg problem is where programmers don't
| know how the C API works well enough to provide function-
| specific type annotation or library-specific
| configuration settings, but want to try calling the API
| anyway because they are following a tutorial written in C
| or C++. In this situation if there is no "dumb" binding
| mode builtin to the language the programmer is likely to
| abandon the language and go back to writing C or C++
| until they get the IO working and something displayed on
| screen.
| camjohnson26 wrote:
| What's the reason for serializing the full engine state for the
| save/load functionality? Seems like a lot of complexity.
| mcdevilkiller wrote:
| I guess because RTS games are soft-realtime systems and need
| precise control of everything. RTS multiplayer logic is some
| of the most complex I've ever seen, these games are basically
| distributed computing frameworks.
| ludamad wrote:
| As someone who has made a custom engine - and intended at first
| for it to be an RTS engine - kudos. Huge accomplishment :)
| rsweeney21 wrote:
| adfa
| chmod775 wrote:
| After leaving some pretty negative comments on many 'code
| submissions' my expectations were fairly low and I was expecting
| another novice-level project of subpar engineering.
|
| Well. Looks like I'll have to adjust my expectations. This is
| above and far beyond what I would dare criticize or probably
| could produce myself.
|
| Teaches me to not bunch "Show HN: my npm package you should
| totally use in production" with "Show HN: my C passion project of
| 3 years".
| hombre_fatal wrote:
| You couldn't find a way to give the OP props without writing
| yet another negative comment about the code that some people
| submit?
| phnofive wrote:
| It can be a challenge.
| chmod775 wrote:
| Suppose I could but chose not to? It's not like I also listed
| each of them.
|
| I also don't have a problem with people submitting bad code.
|
| I however will speak up when people submit _horrible_ code
| wrapped in a npm package and there 's a real risk of someone
| unsuspecting accidentally using it.
| Taylor_OD wrote:
| If you made me put a number on it 1 and 4 show HN posts that
| hit the front page are pretty impressive. The other 3 get there
| from a mix of "hot" tech, a good title, and a slow news day.
| smoldesu wrote:
| +1 for this. A lot of people lack scope when they submit their
| programs, which is mostly fine since HN ranks posts by upvotes.
| This is really one of those "bigger fish" moments for sure,
| though.
| einpoklum wrote:
| I like how chicken + resources = wooden chicken tank.
| Datenstrom wrote:
| Truly beautiful code. It is so clearly structured and written I
| feel like I could dive in an work on it easily if needed, that is
| quite rare.
| tomcam wrote:
| I love that aspect of it. Maintainable code just makes me feel
| good
| [deleted]
| mr_cyborg wrote:
| This is incredible. Great work!
|
| I recently looked at making a really simple RTS using something
| like Unity and I was surprised how little love that genre gets
| from a lot of engines.
| 0xbeefeed wrote:
| Absolute madlad.
| neatze wrote:
| > Permafrost Engine is licensed under the GPLv3, with a special
| linking exception.
|
| This is most awesome thing, I wish more projects would use
| linking exception!
|
| Just in case someone will reuse code on server side; why not to
| use AGPL instead of GPL ?
| chc wrote:
| What's strange is the README says this, but I don't see a
| linking exception in the actual license.
| neatze wrote:
| It's per source code file, and it is not explicitly defined
| what is and what is not an engine API calls.
___________________________________________________________________
(page generated 2021-05-12 23:00 UTC)