It is currently Wed Sep 08, 2010 6:09 am

All times are UTC - 5 hours [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Managing Game States - Articles, blog posts, ideas etc.
PostPosted: Thu Jun 24, 2010 5:08 pm 
User avatar
Joined: Tue Apr 06, 2010 4:54 pm
Posts: 25

Seeing from the poll that "Game States" will not be covered right now, I thought I might post some links to help you guys out meanwhile. This have been very useful for me and has helped me create my own system for managing game states.

Happy reading!

1. Purple Pwny. Includes a couple of good reads at the top of the article and some other useful posts.

2. Game Engineering Note the follow-up post in the end of the article.

3. Mangement with State Hierarchies Pretty hefty pdf-file, might come in handy though.

4. Game-state system The standard way of doing states. This was originally the reason I invested some time in more advanced systems, but I just linked it anyway. I would not recommend this system for larger projects though as it quickly becomes a bunch of spaghetti-code that is hard to maintain.

5. This in combination with this should help as well. Requires that you know some basic to intermediate C# though.

6. Dont know if you noticed it on the forums, but this helped me flesh out my own game state management system.

7. Gamedev.net has an articles section which might contain some tuts. Searching the forums helped me a lot too.

8. You could make your Game/App class (whatever it is called) a singleton. Either following the singleton pattern or making all methods and member variables static.

Feel free to continue the list if you have something to add :)

_________________
- NordCoder


Offline
 Profile  
 Post subject: Re: Managing Game States - Articles, blog posts, ideas etc.
PostPosted: Mon Jun 28, 2010 9:04 am 
Joined: Tue Sep 08, 2009 11:35 pm
Posts: 12

Hey thanks for this NordCoder, these links really helped a lot. I'm sure lots of people will benefit from the consolidation of information here =P.


Offline
 Profile  
 Post subject: Re: Managing Game States - Articles, blog posts, ideas etc.
PostPosted: Wed Jun 30, 2010 9:10 am 
Joined: Tue Jun 22, 2010 10:05 am
Posts: 2

I actually implemented a very similar game state management system to the one in the purple pwny article as I think I had read most of the articles he had referenced as well. Still working on cleaning it up some more but Ill give some examples of changes I made.

Changes I made was to have an vector of StateType which I believe was implemented in the Orge state management example:

typedef StateType{
std::string stateName,
GameState* state
}

and a method to add them
GameStateManager::AddState(std::string stateName, GameState* state);

so the startup of the game would be similar to this.
gameEngine.AddState("Title", new GameState_Title());
gameEngine.AddState("Pause", new GameState_Pause());
gameEngine.AddState("GamePlay", new GameState_GamePlay());
gameEngine.AddState("Menu", new GameState_Menu());
gameEngine.Start("Title"); // The actual game loop is in here and I pass the initial state I want to load and it would the call the private methods OnInit, OnEvent, OnRender etc..

so the methods to change/push states would just take the identifier instead.
ChangeState("GamePlay");

I Also modified the GameState class so that it had a private GameStateManager* gameManager which is initialized OnInit() [possibly better to do it in the constructor] so it doesnt need to be passed into every method that needs to make call backs so wherever you are inside the GameState class you should be able to for example:

gameManager->ChangeState("GamePlay");
gameManager->Stop();

Alternatively you could just make it a singleton and call the methods like so from the GameStateClass.

GameStateManager::GetInstance()->ChangeState("GamePlay");
GameStateManager::GetInstance()->Stop();

Singleton could also be done with all the various GameState implementations, as I said Im still working on it so Im going to be changing some things around Ill probably post it up when I get a chance to finish it.

One thing in particular I want to do is to sort out how to load specific content i.e. passing in a content identifier to the states that require one say a level for the gameplay so it knows to load a different level, possibly overload the Change and Push State methods to take a string identified which would be passed to the GameState OnInit(string identifier) method.

Apart from that its similar to the way its done in that article.


Offline
 Profile  
 Post subject: Re: Managing Game States - Articles, blog posts, ideas etc.
PostPosted: Fri Jul 09, 2010 8:53 am 
User avatar
Joined: Tue Apr 06, 2010 4:54 pm
Posts: 25

Hey Trotts,

Thanks for your insightful reply! :)

I had a few thoughts to add when I was reading your reply.
You could implement an STL map instead of a typedef, something like:

Code:
map<string id, GameState*> States
// Accessing the state:
States["Gameplay"];


Not necessarily a huge improvement, but just a suggestion.

I really like the idea of a private pointer to an instance of a GameStateManager class.

For the level loading, and I'm assuming you are storing your levels in a text file with some kind of format, you could simply pass a string with the path of the file or a struct containing data about the loading if more than a file name is needed, like:

Code:
struct LevelData
{
   string path;
   string name;
   int Noenemies;
   // etc...
};


You could also overload the OnInit() member function. Then it would be possible to make an alternative method only on the state that actually needs one. You could also make OnInit() virtual (or pure virtual) in the GameState/State base class.

_________________
- NordCoder


Offline
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


 Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: