Open World Soccer Forum Index Open World Soccer
Community Forum
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Game states

 
Post new topic   Reply to topic    Open World Soccer Forum Index -> Programming
View previous topic :: View next topic  
Author Message
mkko



Joined: 16 May 2008
Posts: 15

PostPosted: Wed Jun 04, 2008 7:06 pm    Post subject: Game states Reply with quote

Hi,

I haven't had too much time recently but with the time I've had, I've been thinking about the general design of the game. Here are some quite random thoughts, please don't hesitate to ask if something is unclear.

First of all, I think game states are a must for this kind of game. Secondly I think we need something to separate the game states from the initialization and other stuff that will be done only once. This would include some sort of resource managing separated from the use. The actual gameplay should be one of these game states and could be parametrized with the field type, teams and players, weather and things related to the actual gameplay (game time, are there penalties, ...).

I created a relatively simple screen manager class which delegates the messages (such as updating, event handling and drawing) to the active game state and handles the swap from a state to another. This manager is a stack-like container which aims increase the transparency between the game and a state. In this case the game would be the one responsible for resources and other global stuff (such as game settings). I named one piece of state to be called a "screen", as a state can be a combination of multiple overlapping screens (in a way similar to photoshop layers). This way we could easily have the same menus over gameplay as we would have in main menus. Transitions from one state to another is handled by the screen manager and could be triggered by any of the overlapping screens. During a transition the screen manager is responsible for activating and suspending the screens.

A class named Screen is the base class for any screens and holds the state change information. State change information consists of wheter the current state (or even the program) should be ended, if a new state should be created and what the state should be.

However, there are some issues I'm not sure how to deal with. First of all, I haven't been able to decide the most decent way to handle parameters from a state to another. The two major issues with parameters are with the optionality and the type. I really don't like to make the parameter passing fixed (as opposite of generic) from one state to another. Some sort of parameter stack would solve this, but how about the type? There are many ways to solve how to store different types of objects or data into one list, inheritance for example (common base class for all parameter types). Void pointers is one possibility, but I'd avoid them as much as possible as then the data should be dynamically allocated and there are some major annoyances with that.

--

Just for an example, consider invoking replay during gameplay: The gameplay would have it's own data (the positions etc.) and the recorded data for the replay. When the replay should be opened, technically this could be either an overlay screen of the gameplay or as its own state. However, the idea of the overlay screen is to overlap with the underlying screen and this way the both should be drawn and thus the overlay would not be the best possible solution. The parameter passing would be easy with overlays in this case though, because the gameplay would be responsible for the overlay screen and would be able to access it. The recorded data can be relatively large in size, so it might be better if passed as a reference.

The transition from gameplay to replay would be something like this: The gameplay notices that the replay should be opened. It prepares the replay data (if needed) for the replay and updates the state change structure to describe that we want a new state on top of this one and it should be the replay. In addition, the parameter passing should be handled here (pushing it or a reference to it to a stack or something). After these updates the control is returned to the state manager. The state manager reads the state change structure and acts accordingly, suspending the current state and creating a new one. Now the replay could retrieve the parameter somehow or it can be given during the initialization. After the replay has finished, it creates a state change to end the active state and not to create a new one. No parameters are needed to pass. The state manager would react to this by destructing the replay state and resuming the gameplay.

As I mentioned earlier in this post, I've created a test version of this which unfortunately works only in command line. No SDL is used with this. I can provide the source code if needed.

Does this sound too complicated to you (meaning everyone in this project, in case there are others Smile)? I usually get too generic (not that I'd be any good in it) and everything and forget to keep it simple enough.


ps. There aren't too many of us at the moment, but I'd recommend a wiki or something similar to combine ideas and thoughts together. This way we could explicitly separate drafts and random thoughts from decisions. Thanks for having the effort of reading this! Wink
Back to top
View user's profile Send private message
Massimo32
Site Admin


Joined: 11 Nov 2007
Posts: 177
Location: Bolzano, Italy

PostPosted: Thu Jun 05, 2008 10:24 pm    Post subject: Re: Game states Reply with quote

mkko wrote:

As I mentioned earlier in this post, I've created a test version of this which unfortunately works only in command line. No SDL is used with this. I can provide the source code if needed.


Yes, I would like to see the code.

mkko wrote:

Does this sound too complicated to you (meaning everyone in this project, in case there are others Smile)? I usually get too generic (not that I'd be any good in it) and everything and forget to keep it simple enough.


Everything is quite clear to me Wink

mkko wrote:

ps. There aren't too many of us at the moment, but I'd recommend a wiki or something similar to combine ideas and thoughts together. This way we could explicitly separate drafts and random thoughts from decisions. Thanks for having the effort of reading this! Wink


I agree.
Back to top
View user's profile Send private message
mkko



Joined: 16 May 2008
Posts: 15

PostPosted: Sun Jun 08, 2008 8:37 pm    Post subject: Re: Game states Reply with quote

Massimo32 wrote:
mkko wrote:

As I mentioned earlier in this post, I've created a test version of this which unfortunately works only in command line. No SDL is used with this. I can provide the source code if needed.


Yes, I would like to see the code.

Sorry for the holdup, I thought I'd finish an initial version of the parameter passing. I never prefer publishing half-finished code. I'll finish it by the next friday.
Back to top
View user's profile Send private message
mkko



Joined: 16 May 2008
Posts: 15

PostPosted: Thu Jun 12, 2008 8:45 pm    Post subject: Reply with quote

Here's the code. I had to take some time to clean up the code a bit and implement one idea to handle parameters from screen to another.

Some notes about the above code:
  • The Game class owns the ScreenManager, which owns the Screens.
  • ScreenManager delegates the update calls from the Game to the active Screen.
  • Only one Screen is active at a time and the ScreenManager handles the suspending and activating a screen according to the active screen's wishes.
  • The state is changed by modifying the StateChange structure. Note that state does not always equal screen, as a screen can contain an overlay screen and thus the state would consist of a
  • Parameters are passed in a PropertyContext (very similar to a std::map<string, boost::any>) from active screen the the soon-to-be-activated screen. (I had to implement a custom version since the map was difficult to use as a constant object)
  • Finally, the ConsoleScreen is the test screen to see how things work. Typing anything pushes a new screen and gives the input to the newly created screen's title. Giving a dot as a first character of the string pops the current screen. Typing x quits the whole app.

Please don't hesitate to ask or question anything :)
Back to top
View user's profile Send private message
Massimo32
Site Admin


Joined: 11 Nov 2007
Posts: 177
Location: Bolzano, Italy

PostPosted: Sun Jun 15, 2008 9:13 pm    Post subject: Reply with quote

mkko wrote:

Please don't hesitate to ask or question anything Smile


Could you please contact me with jabber?
Back to top
View user's profile Send private message
mkko



Joined: 16 May 2008
Posts: 15

PostPosted: Sun Jun 15, 2008 10:19 pm    Post subject: Reply with quote

Massimo32 wrote:
mkko wrote:

Please don't hesitate to ask or question anything :)


Could you please contact me with jabber?

How about IRC? I don't have a jabber configured and the IRC would a 24/7 for me. I'm in the IRCnet with a nickname "mkko". I can create an account in jabber tomorrow if IRC isn't good enough :)

For now, I'm sorry, but I'd be obligated to leave the laptop for tonight. I've spent time enough already here -- or so I've heard. I'll be in touch tomorrow.
Back to top
View user's profile Send private message
mkko



Joined: 16 May 2008
Posts: 15

PostPosted: Mon Jun 16, 2008 10:00 pm    Post subject: Reply with quote

I'll be away for the rest of the week, but tomorrow evening I'll be available. We have this midsummer party, which basically means that we'll be enjoying the summer at a cottage of a friend of mine -- without any unnecessary electronics :)
Back to top
View user's profile Send private message
mkko



Joined: 16 May 2008
Posts: 15

PostPosted: Tue Jun 24, 2008 7:23 pm    Post subject: Reply with quote

Hmm, what's the state of this project?
Back to top
View user's profile Send private message
Massimo32
Site Admin


Joined: 11 Nov 2007
Posts: 177
Location: Bolzano, Italy

PostPosted: Tue Jun 24, 2008 10:14 pm    Post subject: Reply with quote

mkko wrote:
Hmm, what's the state of this project?


Just released the Windows version:

http://openworldsoccer.sourceforge.net/forum/viewtopic.php?p=117#117
Back to top
View user's profile Send private message
mkko



Joined: 16 May 2008
Posts: 15

PostPosted: Thu Jun 26, 2008 1:43 pm    Post subject: Reply with quote

Massimo32 wrote:
mkko wrote:
Hmm, what's the state of this project?


Just released the Windows version:

http://openworldsoccer.sourceforge.net/forum/viewtopic.php?p=117#117

Nice Smile

When will you think the demo will be complete enough to begin the refactoring and such? Have you thought about the general structure of the architecture? And finally, could the SourceForge host the wiki if such would be created?

Regarding this project, I really don't have anything else on my hands right now and I'd gladly do something.
Back to top
View user's profile Send private message
Massimo32
Site Admin


Joined: 11 Nov 2007
Posts: 177
Location: Bolzano, Italy

PostPosted: Sun Jun 29, 2008 1:39 pm    Post subject: Reply with quote

mkko wrote:

When will you think the demo will be complete enough to begin the refactoring and such?


The next steps will be to clean and refine the demo, and then to implement a friendly match. I hope it will be possible to play the first match by the end of the year.

mkko wrote:

Have you thought about the general structure of the architecture?
And finally, could the SourceForge host the wiki if such would be created?
Regarding this project, I really don't have anything else on my hands right now and I'd gladly do something.


The most important aspect of the game is playability, and we're still not satisfied with the demo, so the other aspects (general structure, menu, community, etc.) are on hold. We simply don't want to repeat the history of YS, which had a lot of features but was always lacking in playability (e.g. no tackling).
Back to top
View user's profile Send private message
mkko



Joined: 16 May 2008
Posts: 15

PostPosted: Tue Jul 01, 2008 9:11 pm    Post subject: Reply with quote

Massimo32 wrote:
mkko wrote:

Have you thought about the general structure of the architecture?
And finally, could the SourceForge host the wiki if such would be created?
Regarding this project, I really don't have anything else on my hands right now and I'd gladly do something.


The most important aspect of the game is playability, and we're still not satisfied with the demo, so the other aspects (general structure, menu, community, etc.) are on hold. We simply don't want to repeat the history of YS, which had a lot of features but was always lacking in playability (e.g. no tackling).

I agree. There's nothing without the perfect playability. As I don't have anything useful to do right now, I'm simply trying to create an object oriented version of the gameplay -- the physics mostly. I haven't had much time lately, but I have some sort of framework finished for the app to test the player and ball control and everything from tackling to heading. I used Qt, but isolated the OWS specific part, so hopefully this would be of an assistance to this project.

Not that this matters much right now, but I think it might work well if we separate physics and rules from each other. Physics would set the rules for players' controls (eg. running, tackling, heading and interaction with the ball) and the rules would be informed about every event that happens in the field. This way rules would control the gameplay's state.

Anyhow, I'll be hanging around as I don't have much on my hands right now. I'll try to see how the demo version works exactly and try to implement an OO version of the little aspects of it. I'll be glad to help if anything is needed. Good luck with the demo!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Open World Soccer Forum Index -> Programming All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
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 vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Get Open World Soccer at SourceForge.net. Fast, secure and Free Open Source software downloads