Handmade Network»Forums
9 posts
Platform & Game code separation
Edited by mindspyke on Reason: Initial post
Hello I've decided to structure my game the same way as Casey did in (at least) the earlier episodes of HMH.

I have 2 dll's that make up the whole thing. 1 for the platform layer and 1 for the game, which gets dynamically loaded.

In speudo code tt's basically this:

- setup(gameMemory);
- setup(platformAPI);
- setup(graphicsAPI);
- update(memory, platformAPI, graphicsAPI);
- render(graphicsAPI);

(audio would be done in a similar fashion using openAL)

The platform dll is the entry point and then calls the game dll's update & render functions in a loop.
The platform & graphics API structs then hold function pointers to stuff set up by the platform layer...
So the game uses these to load textures from disk or draw stuff.

I figured that this setup should make porting "fairly" simple as I would just need to replace the platform layer and give the game 'all it needs' to run.

However I was wondering... does this separation have any performance issues? And do you guys see any problems for porting this kind of setup to another platform?

Thanks for reading :)
Mārtiņš Možeiko
2202 posts / 1 project
Platform & Game code separation
If all you do is call function once a frame (maybe a few) from one dll to another, then you won't see any performance differences. If you will call thousands and millions times per second, then there could be some measurable difference, but even then it will be small. As Casey has demonstrated you could even unload game dll every frame and load it from disk again, and even then game was running just fine.
9 posts
Platform & Game code separation
alright fair enough :p