3 ms·
One reason would be template metaprogramming. In game development and simulations we use numerical computing most of the time, a domain where templates come in
by johnnycerberus 6y ago
One reason would be template metaprogramming. In game development and simulations we use numerical computing most of the time, a domain where templates come in handy. The rest is just C. Modern C++ for highly efficient systems is not C with classes anymore, it is more like C with templates. And also functional constructs for specific components (physics) where it makes sense to use it. I have high hopes that a language like Zig will prove less complex and as powerful as C++ for game dev. It won't be a replacement for C++, just an alternative, hard to believe that anything will dethrone the king.
- simiones 6y agoFrom what I've heard in presentations, many game developers seem to be some of the biggest opponents of templates, especially because of the horrible performance on non-optimized builds of template-heavy code, and in general because of the opaqueness of performance of template-heavy code.
- andi999 6y agoFor numerical computing:yes. For games, dont you just use float (for non-integer values)? Found the video I was thinking about: https://www.youtube.com/watch?v=rX0ItVEVjHc https://www.youtube.com/watch?v=rX0ItVEVjHc from 1:24:00 onwards.
- jasonwatkinspdx 6y agoC++ templates have a poor reputation in the gamedev community. Years ago some companies went too far with it and got burned. EA has their own fork of the STL that's gotten increasingly crufty and behind in performance. AAA game engines also get big, so there's a lot of pressure on avoiding explosions of build time with more advanced template techniques. Gamedev tends to use its own patterns, particularly arena allocation for long lived fixed size tables, or their own internal object / entity / component model . It's not really c with classes or c with templates, just kind of its own dialect.
- verall 6y agoIt's certainly more than just templates, but it's also not the whole hairy c++ - it's C + templates, RAII, and namespaces. It's less template metaprogramming and just templates to generate efficient code - stuff used to be done by abusing the proprocessor can now be handled by a (slightly) more elegant templating engine rather than a string pasting engine. Classes are used for resource management/RAII, like we have a AQUIRE_MUTEX_IN_SCOPE() macro which will release mutex when scope is exited, this is supremely useful and generalized to many resources. Lastly namespaces are huge. In big C codebases you have to be super pendantic about naming modules and APIs consistently because otherwise it becomes a nightmare. C++ does get in the way still sometimes, like when you want to do something slightly dirty for perf reasons, say aliasing between structs. You first write it in a way that makes sense, basically how you would write it in C, but it's UB in C++, so you rewrite it with virtual calls or memcpys such that the compiler should be smart enough to arrive at the same result as C would have with the straightforward implementation. This works great until it doesn't, your last option is to try to solve it with templates, and that hole is very deep.