3 ms·
I have been watching the Handmade Hero stream (and following along by typing the same code locally), but I am behind about 2 weeks. So I was really surprised an
by drivers99 12y ago
I have been watching the Handmade Hero stream (and following along by typing the same code locally), but I am behind about 2 weeks. So I was really surprised and delighted to see that this article turned about to be about him and his project.
The way that he is doing cross-platform code for the game is interesting. The platform layer contains main() (or WinMain() in Windows) and is rewritten for each platform. It isn't written as an abstract layer that the game calls. Instead, it sets up a buffer for one frame of video and a circular buffer for sound. Then it calls a function in the game code which is responsible for updating that. The platform code passes a pointer to the video buffer, sound buffer, playing Input (joystick/keyboard), etc. So the game code is completely portable; it is called by the platform code which is native for the actual platform. For example, the Win32 code creates the Window, handles Windows events, initializes DirectSound, and polls XInput for controller state. (It is also why this technique is possible, as they mention, the game layer does not use any external libraries and doesn't allocate its own memory using malloc.)
So, to answer your question: the way to do this, if you're doing the way they do, would be completely different between platforms (Win32 vs unix at the very least), but you don't need to implement it in a generic/abstract way that hides the operating system. They wouldn't write a framework for this. Instead, you would write it into the platform specific code in the (relatively small) platform layer.