top | item 47216794

(no title)

dxuh | 1 day ago

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.

discuss

order

cyber_kinetist|15 hours ago

Note that if you want to go a bit further, you should make your own minimal build system that replaces CMake. That alone will make your project compile much faster!

I've made my own in Python that generates Ninja files only - and it's surprisingly not that much work (especially if Claude Code can help you).

dxuh|6 hours ago

But CMake only reruns, when CMakeLists.txt has changed. That doesn't happen a lot after the core of the project has been set up for me. Especially not when I am tweaking a game mechanic or something.

Also if you want your project to compile with Ninja on Linux, but also with MSVC and you want cross-compilation (on Linux for Windows) and an Emscripten build (I do want all of those), then rebuilding CMake is quite a lot of work.

roflcopter69|8 hours ago

Sounds interesting! Have you published this somewhere? I wonder how well this works when you want to compile some complex dependencies. Have you compared compile times between your solution and when using CMake?

roflcopter69|1 day ago

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?

dxuh|1 day ago

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.