Comment by roflcopter69
7 hours ago
I see `dotnet watch` being mentioned for code hot reload which is such a great feature for quickly iterating on a game. Not having to restart the whole game just because one has changed a few if statements and values really helps staying in the flow.
But I'm still not too enthusiastic about having GC in C# which is why ideally I'd like to start making a small 2D game just with SDL3 and C++ but how could I get this nice hot reload workflow there? I don't have the money to pay for expensive proprietary tools like https://liveplusplus.tech so what can I do? I guess there's the "game as dynamic library" trick from Handmade Hero (see https://www.youtube.com/shorts/seWAIURXxH0) so maybe that would work good enough? Maybe https://github.com/fungos/cr would do most of what's needed here?
Also, how does one even do modern C++ these days? Is it possible to have big C++ code bases that still compile fast these days? Is CMake 4 good™ now? Are modules really there yet? I rely on clangd as LSP for working with C++ but I read that clangd still fundamentally struggles with C++ modules https://chuanqixu9.github.io/c++/2025/12/03/Clangd-support-f... and it's so bad that there has even been some effort going into making a new C++ LSP https://github.com/clice-io/clice
If you implement the actual game logic in a scripting language like Lua, hot reloading becomes trivial. sol2 is a really awesome Lua binding library for C++: https://github.com/ThePhD/sol2
I quite like modern C++, so I really tried to make it work for gamedev, but I think you can't really do it. You can use all the modern C++ features that are not in the standard library though! I am working on a little game the last few months and after a while I just decided to not use any of the C++ standard library (I just use a few C headers) and make my own Vector, Array, Span, String, FlatMap. And using those the game compiles really fast. If I touch a header that is included almost everywhere (the big game state struct), I can compile and link (mold) in ~300ms. If I touch player.cpp I compile in 250ms. That is mostly good enough for me, but I am thinking about the "game code as dynamic library" thing myself.
I always thought CMake was good enough. I use FetchContent for all external dependencies and git submodules + add_directory for all internal dependencies. It took me a while to figure out that this was the simplest thing that works reliably though. I have used vcpkg and conan extensively and have completely given up on them.
I don't use C++ modules, because afaik they are still mostly broken. Without modules clangd works wonderfully and has been working wonderfully for a few years. I really, really like it. I think it can be done! I am missing reflection though, but if I would really want to use it, I'd probably just use clang -ast-dump instead of the new reflection functionality.
Thanks for the reply!
> I quite like modern C++, so I really tried to make it work for gamedev, but I think you can't really do it.
What exactly do you mean? What parts of modern C++ did not work for you?
> You can use all the modern C++ features that are not in the standard library though!
> I just decided to not use any of the C++ standard library (I just use a few C headers)
So what do you do with C++ that C alone couldn't do?
I think the standard library is good, but if you pull in ANY of it's headers you add a couple hundred milliseconds to every translation unit. So when making games (and only then), I avoid the standard library.
What I do like and use is overloading, references, templates, concepts, lambdas, enum classes, user defined literals, constexpr, operator overloading for math (!), little syntax stuff like structured binding declarations, "auto" and range based for. I also made my own little fmt (like https://riki.house/fmt). C++ is a much nicer language than C imo, even without the standard library.
C++ is really not very amenable to this because every change to the contents of a class messes up your entire memory layout. "game as DLL" is definitely a viable solution to that, but so is "game in scripting engine": many games delegate a lot of their mechanics to e.g. Lua precisely because it's so easy to tweak in-engine if you just want to change a bonus from 5% to 10% and so on.
> C++ is really not very amenable to this because every change to the contents of a class messes up your entire memory layout
I think even `dotnet watch` at some point nopes out when you change too much. I think they call it "rude edit" and ask you to completely restart the program in that case. So I don't expect every possible C++ edit to be manageable by hot reload. But changing a few if conditions or constants should be fine or not?
I'm more and more questioning scripting languages in games. What are the main reasons to use something like Lua? I think it's having not to rebuild the engine, no compile times, changing stuff while the game is running and being more accessible to non-programmers. But I think it's rather infuriating, all those points could be less relevant if the tooling for "real" programming languages was better. And with coding agents becoming more wide-spread I guess accessibility to non-programmers also becomes less of a point. I guess it's just my personal dislike for scripting languages in games, but really, it would be so much nicer imo if there was only need for one language that does it all. But seems like a difficult thing to achieve.
You could also offload potentially GC-heavy parts to C++ and write the rest in C#. Depends on the game, but usually most of the game logic that you'll be constantly tinkering with doesn't require all that much memory in the first place.
.NET also now has an (amazing) alternate low-pause/effectively pauseless GC: https://github.com/VSadov/Satori
Builds: https://github.com/hez2010/Satori/releases
how to use? do self-contained publish (but not single file), replace 3 files in the folder with the one from Satori release you can check if it's in use with GC.GetConfigurationVariables().ContainsKey("SatoriGC")
It is a far, far superior experience to touching anything C++.
Oh thanks, that looks very intriguing! The maintainer seems to be a Microsoft employee so there's that? I wonder though, is this a niche hidden gem or really something that more people should consider using? Also, what about compatibility with platforms like Android, iOS or consoles? That'd be very important for gamedev.