Game architecture

Started by
21 comments, last by Alberth 7 years, 8 months ago

Im trying to write a 2d game in C++ using SDL2. How should i set up all the media loading(textures and stuff) so that i could access them wherever i need em?

Advertisement
Determine which procedures in which systems need to load media, and pass a reference to the media loading system into those procedures.

So if i have a spritesheet, i pass a refrence of the spritesheet object to all tiles(static refrence) and then use clips to render pieces from it?

Why would a tile need to store its graphical representation? Just its property values would be enough.

Wouldn't it be simpler to pass the reference to the sub-system that draws the map?

Also, assuming you're going to have more than one sprite sheet, make a media store object, that contains all media, and pass that around. That makes it much easier to switch between different sprites, even if they are on different sheets.

can i make the media store to a singelton? Then whereever i need it i can just ask for the instance and then i can render what i need from it.

You can, it's not a great idea though, because it's letting you get sloppy and not think about the impact taking the dependency on the resource loading system actually has on the rest of your code.

if i load in the spritesheet in the beginning(simple game not many sheets will come) that wont have that much imact or will it ?

if i load in the spritesheet in the beginning(simple game not many sheets will come) that wont have that much imact or will it ?

I'm not talking about "impact" in terms of memory, I'm talking about impact in terms of turning your code into brittle spaghetti.

But yes, you should be loading your sprite sheets as early as you can for a small game, regardless of the method by which you then transport them to the rest of your program. For a small game you can probably fit all your resources in RAM at once and loading them up front probably won't create too much of a delay.

Well im trying to plan ahead, but i currently have no idea how to make everything communicate with what they need and also not make it spagetthi.

Would it be good that i write a Module that handles media loading and rendering. And then map or tile calls the render function from media module and renders a given sprite or something ?

Planning ahead is good. But there is danger in planning too far ahead when you don't know what you are doing, that can lead to over-engineering as you try to "plan" for every eventuality. Most of which you won't actually encounter.

Focus instead on what you need now: a way to load your textures, and a way to get those textures to things that need them. So write that. Write a "module" as you say which can load textures from the disk and hand out pointers to those textures when asked (ideally such that if you ask for texture "foo.png," you load it from the disk unless you've already loaded it, in which case you just hand out another pointer to it). Pass this module to anything that would need to access the textures, and move on to writing the next stage of your game.

This topic is closed to new replies.

Advertisement