r/cpp_questions • u/drofosfera • 6h ago
OPEN How should I go about learning C++ for low-level gamedev?
Good day,
I am an intermediate game developer coming from Unity, and I'd like to deepen my knowledge of game development. Let me tell you about myself first and how I got here.
Over the summer I've learnt a considerable amount. I've learnt about OOP. I can realize design patterns, refactor code according to SOLID principles, and write systems which are clean and scalable. I've come to realize that objects, such as classes and interfaces, aren't just magic words I put into the IDE. They're actual abstract objects which have their own properties and relationships between one another (I'm still in high school so I don't really know any comp sci theory other than what I use to create games). In June I've created a game featuring an AI which uses a complex Hierarchical State Machine governed my emotional dynamics and external events. My implementation of the State machine pattern allowed me to use it all over the game without issue or extra modifications.
I've also learnt about Data-Oriented Design. Over July I've gotten the feel for Unity's Data-Oriented Technology Stack. I've learnt to think in terms of ECS, be cognizant of the memory I'm using, and parallelize code. I've written an N-Body simulation which uses the Barnes-Hut algorithm. Coupled with multi-threading (Jobs) and the Burst compiler, the sim can handle ~100K bodies with collision at a presentable framerate.
In August I've joined a team to participate in the National Technological Olympiad in Russia to go to uni, so I know what "readable" code means, how to use version control and how to write professional, clean and beautiful code. However, that's besides the point.
As I've matured as a programmer, I learnt about the concept of low-level game development. I've come to realize that Unity isn't a magic box. Previously, I didn't even consider that there's something under the hood of the game engine. I just wrote code, clicked buttons, and it all just worked. However with time, I've come to realize that this isn't the case. Unity is yet another program which hides a considerable amount from me. I realized this mainly in July, when I needed to know how the CPU worked more-or-less (when things like cache lines and race conditions became important). Then I realized that I really am at the very tip of this metaphorical iceberg of programming, looking down at the deep water below.
Here's when I've learnt about C++. I know that this language is often regarded as the foundation of just about everything, including games. I've used it briefly before. Long ago, I've written a little Pong project with C++ and built it with CMake, having used SFML to render objects to the window. I've also used C++ to solve simple Codeforces problems, so I do have the rudimentary knowledge of input/output on C++. But that's about it. My aim is to use the language to learn about low-level game development, to "break free" from the game engine and expand the domain of my expertise (maybe to even write my own game engine in the future). I can learn the API of the language rather quickly (e.g. how to write lambdas, how to import libraries, anything I can already do in C#), however I know that's not all that I'll need.
I am aware of the gaps in my skills. I have the high-level knowledge, just not the low-level knowledge. Even though I know how to use DOTS to write parallelized, Data-Oriented systems, I can't really tell you how to resolve even a simple race condition, or what a memory leak actually looks like, or how the CPU and RAM are laid out, or how things actually work on the low level. Even though I can use the API Unity and C# provide to use OOP to write clean and modular code, I don't really know how a class actually works, what differentiates data types from reference types (other than "something, something, pointers, something, something"), and how things actually look like inside memory. Unity hid all those troubles from me. So I know that these gaps must be addressed for me to proceed in my learning journey. I learn fast though (as I've shown), so it's not that big of a deal.
Here's where I need your help. I know that to learn efficiently I first need a plan, a roadmap per se. Given my experience, how should I approach learning low-level gamedev on C++? What stuff do I need to learn about? And in what order? What is your advice?
I'd love to hear from you wonderful people.