5 Replies - 1203 Views - Last Post: 27 February 2012 - 04:08 PM Rate Topic: -----

#1 Kurupted_Magi  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 15-March 10

C++ and SDL resource management for 2D game

Posted 26 February 2012 - 07:54 AM

Hello all and thank you in advance,

I am trying to find better ways to code what I have already implemented before I move on to new concepts. My first question is about stateManagers. I do not use the singleton pattern (read many random posts with various reasons not to use it), I have gameStateManager which runs the pointer cCurrentGameState->render(), etc. I want to make a transitioning game, this engine should ideally cover both a platformer and a bird's eye RPG (with some recoding, I just mean the base engine), both of which will load different levels and events, such as world map, dungeon, shops, etc. So I then thought, rather then having to store all this data within all the states, I would break the engine into gameStates, and playStates... when gameState reaches gameStatePlay(), gameStatePlay simply runs the usual handleInput, logic, and render for the playStates, just as the low level gameStateManager does. This lets me store all the player data within the base playstate class without storing useless data in the gameStates. Now I have added a seperate mapEditor, which uses editorStates from gameStateEditor. Is this too much usage of the gameState concept? It seems to work pretty well for me, so I was wondering if I am too far off a common implementation of this.

My second question is on image resources. I have my sprite class with nothing but static members, mainly loadImage, applySurface, and my screen pointer. I also have a map pairing imageName enums with actual SDL_Surface pointers, and one pairing clipNumber enums with a wrapper class for a vector of clips, so that each reference in the map can have different amounts of clips with different sizes. I thought it would be better to store all these images, and screen within one static body, since 20 different goblins all use the same sprite sheet, and all need to print to the same screen, and of course, this way I do not need to pass my screen reference to every little entity. The imageMap seems to work very well, I can even add the ability to search through the map at creation of entity type to see if a particular image at creation, creating if it doesnt exist, and destroying the image if the last entity that needs it was just destroyed. The vectored clip map however, seems to take too long to initialize, so if i run past the state that initializes them to fast, the game crashes ><. Plus, the clip map call is half of this line =P

SPRITE::applySurface( cEditorMap.cTiles[x][y].iX, cEditorMap.cTiles[x][y].iY, SPRITE::mImages[ IMAGE_TILEMAP ], SPRITE::screen, SPRITE::mImageClips[IMAGE_TILEMAP]->clips.at( cEditorMap.cTiles[x][y].iTileType ) );

Again, do I have the right idea? I like the imageMap, but am I better off with each entity storing its own clips?

My last question is about collision detection. I only grasp the basics, will look at per-pixel and circular soon, but how can I determine which side the collision comes from with just the basic square collision detection, I tried breaking each entity into 4 collision zones, but that just gave me problems with walking through walls and the like ><. Also, is per-pixel color collision a good way to decide what collision just occured, or is checking multiple colors for multiple entities too taxing each cycle?

Thanks again to all that reply - Kurupted_Magi

Is This A Good Question/Topic? 0
  • +

Replies To: C++ and SDL resource management for 2D game

#2 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 0
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: C++ and SDL resource management for 2D game

Posted 26 February 2012 - 04:21 PM

Why won't you use singletons?
Was This Post Helpful? 0
  • +
  • -

#3 Kurupted_Magi  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 15-March 10

Re: C++ and SDL resource management for 2D game

Posted 27 February 2012 - 03:08 PM

View PostButchDean, on 26 February 2012 - 04:21 PM, said:

Why won't you use singletons?


When trying to understand gamestates, most of the posts I found would argue singleton usage back and forth, so I figured I would learn without singletons. Not saying I will never use them, just saying I am not using them. Wasn't sure if that would change the answers I would receive.
Was This Post Helpful? 0
  • +
  • -

#4 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 0
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: C++ and SDL resource management for 2D game

Posted 27 February 2012 - 03:56 PM

Using them will help your understanding of game states, I don't know why on earth you would believe otherwise.
Was This Post Helpful? 0
  • +
  • -

#5 Kurupted_Magi  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 15-March 10

Re: C++ and SDL resource management for 2D game

Posted 27 February 2012 - 04:04 PM

View PostButchDean, on 27 February 2012 - 03:56 PM, said:

Using them will help your understanding of game states, I don't know why on earth you would believe otherwise.


So nothing in regards to my actual 3 questions? The topic wasn't, "I do not use singletons, please sway my judgement."
Was This Post Helpful? 0
  • +
  • -

#6 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 0
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: C++ and SDL resource management for 2D game

Posted 27 February 2012 - 04:08 PM

No because it's a wall of text. your question isn't clear, and if it's not clear it can't be answered.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1