Jump to content
  • Advertisement
Sign in to follow this  
EstViking

Game architecture

This topic is 695 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Advertisement
Determine which procedures in which systems need to load media, and pass a reference to the media loading system into those procedures.

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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 ?

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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 ?

Edited by EstViking

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!