Handmade Network»Forums
6 posts
What is the reason for preventing game calling platform layer
Edited by david0 on

It seems like in handmade hero there is a clear seperation between platform layer and game code. I am guessing there is also a renderer in the middle? At least that is what I have understood when I looked at the source code. I was curious why Casey mentioned so many times in the stream to prevent game from calling platform layer. I understand that we have a seperation between them but it's not like a seperation you have between two programs. You don't open any pipes or sockets to connect to each other, you don't have any issues with bandwith over the socket or pipe or whatever. That's just a seperation between two translation units.(I guess not translation units just files because it's a unity build)

I do not understand the benefit of game code not calling platform layer. Let's say on a big game we have some sort of level system where levels contain thausands of assets. Before player walks into a new level we want(probably) some mechanism to start loading assets before. We cannot(as far as I understand) load the assets on game layer because we need some function to open files and write them to a disk which is platform spesific code. But we also cannot do that on platform layer because platform layer shouldn't contain game state, that means we cannot do a switch loop on which level player is on and load that assets because then we check for game layer only things.

I guess Casey some how solved that on some stream? But I don't understand the argument against seperating them with a clear distinction. Why do we give up on the control over the game we had before? Why are we round tripping to other ways to do things instead of directly doing it. I feel like to prevent round tripping we do more round tripping.

I can get the argument of saying well platform layer code can fail and we want as less failure points as possible but you will still need to do the work to get the assets into the game at the end of the day. It shoudn't matter whenever it is done, either you pass a pointer to a huge chunk of memory every frame or just do a direct call.

What advantage do we get exactly because we clearly loose a lot. Also I am not trying to argue or anything if I sound like that I just want to get the reason on why we need something like that.

Mārtiņš Možeiko
2575 posts / 2 projects
What is the reason for preventing game calling platform layer

I do not understand the benefit of game code not calling platform layer.

There's nothing wrong with game code calling into platform layer. As long as you do in very controller way and limit API surface you're exposing then it is perfectly fine. In fact HH code does that.

Before player walks into a new level we want(probably) some mechanism to start loading assets before.

And this is exactly what HandmadeHero code does. Game issues async asset loading for textures & sounds. And whenever they are finished it finalizes them to use.

Another case where it does is for thread pool operations. It can add work to threads (calls into platform layer) and then wait until they are finished. HH does this for lighting calculations.

6 posts
What is the reason for preventing game calling platform layer
Replying to mmozeiko (#29649)

I see, I think I get it wrong then. Casey mentioned about preventing back and forth in the early days of handmade hero. I think I miss understand what he was trying to say. Thanks for the clarification.

6 posts
What is the reason for preventing game calling platform layer
Replying to mmozeiko (#29649)

Also may I ask about the architecture. I don't know how much you know about doom 3's source code but they also have a seperation between game code and platform code if I am not mistaking but they load the game as dll. Is there a reason for loading it as dll or was it something they have done back in the day because performance reasons? I also see this pattern quite a lot in id software and since Casey had some similar architecture if I may ask is there a name to this or somewhere I can learn more about this?

Mārtiņš Možeiko
2575 posts / 2 projects
What is the reason for preventing game calling platform layer
Edited by Mārtiņš Možeiko on
Replying to david0 (#29652)

In Doom/Quake games this is done to allow making different games. Main executable is the engine providing rendering, sound, networking, etc.. and game dll is loaded at runtime without need for users to recompile main executable.

In Handmade Hero case the reason is a bit different. Most of engine is in game code too, but it is dll because it allows hot reloading. Most of the time you'll be modifying and tweaking game code. And to avoid rebuilding & restarting whole process you can just rebuild game dll file and main executable will detect that and reload dll automatically - instantly running new code. This speeds up edit-build-run process, and is a faster way to develop game.

6 posts
What is the reason for preventing game calling platform layer
Edited by david0 on
Replying to mmozeiko (#29653)

I see it made it really clear. Thanks for the answer.