19 ms·
Show HN: I wrote my own RTS game engine in C
- feinte 5y agoThe devlog videos are great : https://github.com/eduard-permyakov/permafrost-engine#devlog https://github.com/eduard-permyakov/permafrost-engine#devlog Thank you so much for making this in the open and documenting everything !
- Rendello 5y agoI love the wooden AT-AT.
- kleer001 5y agoI think that's Babba Yaga's house with chicken legs.
- Andrew_nenakhov 5y agoIt got two legs, so it's more like AT-ST
- logical_proof 5y agoThere is an AT-AT right next to them.
- vajrabum 5y agoI 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/opengl_realtime_strategy_game_engine_in_pure_c/ https://www.reddit.com/r/C_Programming/comments/gwg5u5/openg...
- vajrabum 5y agoHere's a trailer for a game the developer built using the engine https://www.youtube.com/watch?v=xleJeiOHHh4 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 https://www.youtube.com/watch?v=ch-zjn05gxQ
- tomcam 5y agoAmazing 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 5y agoOver 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 5y agoMy 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.
- hermitdev 5y agoOne 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?
- nattaylor 5y ago
- tekno45 5y agoI hope this inspires someone to make a new kick ass RTS. I really miss the OG WC3 days.
- apocolyps6 5y agoCheck out Back2Warcraft and W3Champions if you haven't yet
- gtirloni 5y agoI checked the websites and I don't know what I'm looking at. What games are being played?
- mujina93 5y agoW3Champions is an unofficial amazing work to bring back to warcraft 3 what reforged has taken away (mostly ladder and tournaments, for competitive games). But there's more, since they could provide intercontinental servers that offer low ping for players from different continents. We have for the first time in history pro players from china battling with the ones in europe, european vs NA, etc. Back2Warcraft are the guys that stream and cast most of the competitive games. I suggest you watch them live on twitch when there's some tournament, and/or on youtube for past games. It's a great time for warcraft 3, thanks to the great effort put in by fans. If only the game hadn't been killed by Blizzard :( But there's still plenty of people playing, with classic graphics and W3Champions servers (you still need reforged), and plenty of pros to watch. Enjoy your warcraft 3!
- rubidium 5y agoAge of Empires 2 has experienced a resurgence recently.
- bfors 5y agoSome people from Blizzard formed a company named Frost Giant and are apparently working on a new RTS.
- Arnavion 5y agoInteresting 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?
- qwertox 5y agoThe Engine Summary is really impressive for a solo project.
- kleer001 5y agoOh wow, that's pretty darn cool. I like the Babba Yaga as a unit, lol!
- unknown_error 5y agoWow, 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!!
- intc 5y agoWell. I usually work on system programming but recently started to code a web app (Account manager at c1.fi - Golang, JS, HTML, CSS) and I can say that creating even most simplistic & light weight web app can be rather demanding job. Especially when you need it to render and behave well on both desktop and mobile! =)
- unknown_error 5y agoI don't know that it's "demanding" as much as "tedious"... I feel like our entire field is built as a mountain of hacks upon hacks. How the heck did Javascript become the dominant programming language of worldwide communications?! The ecosystem is so fragile and unstable (https://hackernoon.com/how-it-feels-to-learn-javascript-in-2016-d3a717dd577f https://hackernoon.com/how-it-feels-to-learn-javascript-in-2...) that it seems like most of web dev is keeping up with fashion changes rather than doing anything truly good for the user. Windows Forms supported responsive layouts decades ago, and Visual Studio was a beautiful system to work in... now we have forty dialects of Javascript and twenty thousand CSS mutations served by like four browsers that share mostly the same renderer but still aren't compatible, overseen by standards groups that compete with each other to actually be the standards... sigh... it's like our main output is job security, producing new features to fix the new features from last week, like a ouroboros forever trapped in the matrix. </rant> I just really appreciate people who can code a clean, elegant app, because I can't remember the last time I saw one in the web world!
- ludamad 5y agoAs someone who has made a custom engine - and intended at first for it to be an RTS engine - kudos. Huge accomplishment :)
- chmod775 5y agoAfter 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".
- Taylor_OD 5y agoIf 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 5y ago+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.
- hombre_fatal 5y agoYou couldn’t find a way to give the OP props without writing yet another negative comment about the code that some people submit?
- phnofive 5y agoIt can be a challenge.
- chmod775 5y agoSuppose 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.
- deleted 5y ago[deleted]
- ghostbrainalpha 5y agoDo you develop this game on Twitch at all? I'd love to watch the work being done.
- geniium 5y agoWell done! Very nice to see that this is still possible :)
- etaioinshrdlu 5y agoAnother 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 5y ago> use macros, and sort of roll your own high-level language yourself. See also Engelbart & Co. Amazing how productive this approach can be.
- dilap 5y agoAre the unit behaviors coded in C, or some scripting/config language?
- epermyakov 5y agoAll 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.
- dilap 5y agoInteresting; thx for the answer!
- garaetjjte 5y agoWhy Python though (and not lua or something)? It is rather annoying to use as embedded language.
- epermyakov 5y agoMy 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.
- grawprog 5y agoThis 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.
- Datenstrom 5y agoTruly 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 5y agoI love that aspect of it. Maintainable code just makes me feel good
- 0xbeefeed 5y agoAbsolute madlad.
- idiotsecant 5y agoSometimes 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.
- p1esk 5y agoI blame Netflix instead
- hutzlibu 5y agoBlaming 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 5y agoYep. 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.
- markus_zhang 5y agoI think the pbjective of a project is to...be a time filler, like I can definitely watch Netflix and then Netflix does not satisfy my creative mind so programming something would be a better exercise.
- tomcam 5y agoParent poster might have been committing a wee joke there
- lucasverra 5y agoJust 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 5y agoThis 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 5y agoWho 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.
- aiisjustanif 5y agoHahaha, my thoughts are similar.
- 6581 5y agoAccording 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 5y agoGoodbye, cruel world.
- jart 5y agoGoodbye, goodbye... goodbye.
- legerdemain 5y agoIs that a reference to the Monkees' Porpoise Song?
- hutzlibu 5y agoI think it is Pink Floyd. https://www.youtube.com/watch?v=Zjh80iwj8rg https://www.youtube.com/watch?v=Zjh80iwj8rg
- tomcam 5y agoYou aren’t allowed to participate in my pathetic little joke because being one of the greatest minds on Hacker News deprives you of that luxury ;) [0] I on the other hand can die happy knowing you answered one of my comments! [0] https://news.ycombinator.com/item?id=26271117 https://news.ycombinator.com/item?id=26271117
- CraigJPerry 5y agoVery 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 5y agoWorkable 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"?
- visualradio 5y agoIf 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 5y ago> 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.
- neatze 5y ago> 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 ?
- charlie_hebert 5y agoAwesome looking project. I couldn't find any tests in the project. How do you test things and maintain it?
- trevor-e 5y agoThis 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.
- offtop5 5y agoAny 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
- nly 5y ago$1000 seems low for using years of work in a commercial project . If you wanted to commercialise it you'd have to do revenue share, surely?
- offtop5 5y agoIn that case why wouldn't I just use Unity. For $1,500 a year or whatever, I get to use one of the most supported game engines in the world. Revenue share becomes a very bad idea if you actually expect the game to do well
- Thaxll 5y agoLooking at: https://www.youtube.com/watch?v=xleJeiOHHh4 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!
- djoldman 5y agoQuick 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
- namdnay 5y agoI think it’s to cleanly show when he is using his pseudo-exception handling system. So goto fail would be “throw”
- alksjdalkj 5y agoNot 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 5y agoNot op, but that's obviously in case you need to do something more complicated than returning false later. It's good practice
- lelanthran 5y agoSince it's GPL, maybe someone can package it for Debian?
- rsweeney21 5y agoadfa
- deleted 5y ago[deleted]
- optymizer 5y agoAs 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.
- ashdev 5y agoThis is super impressive considering it's written in C. Well done and keep it up.
- johnwheeler 5y agoAfter seeing this… Newbie: “I need to start programming!” Veteran: “I should stop programming.”
- beaconstudios 5y agoThat'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 https://github.com/ajeffrey/civarium.
- ilikeisometric 5y agoThe pathfinding video is awesome! Could you do a video on the rendering mechanism?
- mr_cyborg 5y agoThis 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.
- SavantIdiot 5y agoImpressive! 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.
- bennysomething 5y agoCan I ask how old are you and how long you've been programming for? This is an amazing achievement.
- OOPMan 5y agoWhy 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...
- einpoklum 5y agoI like how chicken + resources = wooden chicken tank.
- jokoon 5y agoDid 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.
- mouldysammich 5y agoThis 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 :))
- pototo666 5y agoGreat great job! This project reminds me why I could never become an independent developer. Luckily I give up on becoming one 2 months ago.
- darepublic 5y agobootleg warcraft 4, lets go
- mujina93 5y agoLet's go! I waited for 20 years.
- lostgame 5y agoSays ‘build - for Linux, for Windows’ - I’d just like to ask if the Linux build works for MacOS, natively; as well?
- oreally 5y agoIt's cool and all, but looking at the videos the FPS is taking a huge hit. Doesn't matter how the comments are about beautiful code if no consumer can play it.
- wly_cdgr 5y agoSuper cool. What assumptions about RTS design does the engine make? What is particularly easy in the engine, and what's something that's harder than it maybe could be in another RTS engine that made some different decisions?
- rameerez 5y agoWhat an extremely talented individual you are. Thanks for sharing your work and your process in the YouTube videos. As someone who comes from a web dev background and who's completely unfamiliar with developing large projects in C, I'm curious about your setup. What does it look like? In terms of what kind of IDE, OS, interesting tooling, etc. you use on a regular basis to work on this. Also, I've seen the first commit goes back to Oct 2017. Did you work on this full time during the whole time / how many full-time months you would say you devoted to this project? Also, if I may ask – what do you do for a living? Thanks again and congrats on the project!
- Agentlien 5y agoThis is really cool, wonderful project! I love seeing people put so much effort into projects like this. I'm a bit curious about the choice of OpenGL 3.3. When OpenGL 4.0 came out in 2010 it was a game changer for me and I remember it made everything (apart from quick debug drawing) so much nicer. OpenGL 3.3 was released simultaneously and was essentially as much of 4.0 as could be backported for those unable to move over right away. Is this choice a hint at how long you've been writing this, is it comfort and familiarity? I'm not criticising the choice, it obviously works for you. I'm just interested in the reasons.
- epermyakov 5y agoThe reason I kept the minimum OpenGL 3.3 requirement is because it is supported on the biggest range of platforms. OpenGL 4.xx features require some features from newer generation cards. Of course, with time this is becoming less and less relevant. In some parts of the code, I did make use of OpenGL 4.xx features like glMultiDrawIndirect, but this is put behind a check to see if it's supported by the driver and added a slower fallback for OpenGL 3.3.
- atfzl 5y agoWhy didn't you directly use SDL for rendering instead of OpenGL? Was it for performance reasons? OpenGL is deprecated on mac, and SDL use Vulkan on Window and Linux which I guess is better, performance wise than OpenGL.
- epermyakov 5y agoSDL gives you an API for 2D rendering, mostly limited to drawing boxes, lines, and bitmaps. OpenGL lets you program the graphics card for any use case, most commonly 3D graphics with room to add complex effects and post-processing. The SDL API is just nowhere near flexible enough for what I want to achieve. Plus, Vulkan is not really "faster" than OpenGL. It just gives you a different API for programming the same graphics hardware, which in the hands of the right person can be used for writing code which is "faster".
- 5y ago
- mujina93 5y agoAmazing job! If you could tell, how much time did you spend on it daily or weekly? And how much experience in the gamedev industry and/or with C did you already have when you started?
- edem 5y agoFor those who want to see it in action: https://www.youtube.com/channel/UCNklkpsPnNpRhC9oVkpIpLA/videos https://www.youtube.com/channel/UCNklkpsPnNpRhC9oVkpIpLA/vid...
- mildread 5y agoI'm not a software engineer. Can someone contextualize the magnitude of this achievement for me?
- tuckerpo 5y agoImpressive work and a lot of effort for one person, but not earth shattering or ground breaking. There's a whole community of people who do this type of thing - handroll relatively large and complex projects in C with a data-oriented mindset. https://handmade.network/ https://handmade.network/
- hgs3 5y agoNice project! I too am working on my own game engine in C. The language gets a reputation for being inaccessible to mere mortals, but I find it refreshingly simple.
- deleted 5y ago[deleted]