handmade.network » Forums » Platform & Game code separation
mindspyke
10 posts
#16342 Platform & Game code separation
2 months, 3 weeks 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:

Platform
- setup(gameMemory);
- setup(platformAPI);
- setup(graphicsAPI);
Game
- 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 :)
mmozeiko
Mārtiņš Možeiko
1831 posts / 1 project
#16343 Platform & Game code separation
2 months, 3 weeks 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.
mindspyke
10 posts
#16349 Platform & Game code separation
2 months, 3 weeks ago

alright fair enough :p