handmade.network » Forums » Platform & Game code separation
10 posts
#16342 Platform & Game code separation
5 months ago Edited by mindspyke on Sept. 16, 2018, 8:23 p.m. 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
1880 posts / 1 project
#16343 Platform & Game code separation
5 months ago

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.
10 posts
#16349 Platform & Game code separation
5 months ago

alright fair enough :p