Programming games using scene-classes

Started by
14 comments, last by space warp 17 years, 1 month ago
I'm not sure this is where I should post this but I think it's the best choice... Anyway, I was thinking of making a tutorial/article (I tend to mix it) on game programming and I was wondering how many of you would be interested in a tutorial covering "Windows/OpenGL game programming using scene-classes". By this I mean how to separate all the little parts of the game (splash screen, menu, actual game, result screen, etc.) and turning them into seperate classes that can be used by the central WinMain function. This is a very tidy and effective way to keep different parts of the game separated and organized. So, what do you think? Is it a good idea? PS I'm going to bed now (I live in Sweden), but I'll answer any post when I get back.
.sehkteeah erthyahr gahro
Advertisement
You're talking about a set of game states and having a game state manager of sorts run and update everything?

Yes, I used the same format for the demo I just made, and that made things much easier because I didn't end up having dependencies between completely unrelated classes like, a class that ran a level, and one that displayed and managed a menu. I used to have stupid dependencies between things like this.
[size="2"][size=2]Mort, Duke of Sto Helit: NON TIMETIS MESSOR -- Don't Fear The Reaper
No, I'm talking about having every scene in a seperate class with its own functions and members. It's more tidy this way.
.sehkteeah erthyahr gahro
it seems to me that that would only serve to make more code to write. personly i use a single class to handle the game state. i keep it tidy and havent had any problems with my state manager class yet.
Well I suppose it depends on who you're talking with. But if people usualy use state managers then maybe I ought to write the tutorial just to show another way to do it and then people can choose for themselves.
.sehkteeah erthyahr gahro
I think that tutorials are terrible abominations, and tutorials written by people who are not experts or masters in the particular problem domain are even worse. Then there's the fact that most tutorial authors aren't necessarily all that great at communication to begin with, except in code, so all that tutorials end up being is code dumps, which aren't helpful.

Now, all of the above may or may not apply to you at all -- I don't know you; but statistically speaking its likely that you fall somewhere in the category of "not quite experienced enough to write a tutorial," but who knows. I won't assume.

That's less of an issue, however, than the fact that I don't think the concept you're trying to impart is particularly useful. It sounds like you're advocating the construction of large, monolithic hard-coded classes (one for each "state"), possibly with a lot of duplicate functionality, which is brittle, hard to maintain, and doesn't scale well. It might be ideal for quick, small games, but it really isn't a scalable system, especially the way you describe how transitions might work.

Basically, you seem to be advocating a state machine that is hard-coded and monolithic, versus a state machine that is designed to be generic and reusable. Have I misunderstood you? I don't see any advantage to your suggestion as I currently understand it and think that a tutorial on the subject would only serve to increase the spread of bad or misinformation.

First of all, I do NEVER make code-dumps. I said in the first post that I tend to mix tutorial and article writing and I also NEVER make rigid code (sometimes I make code general way beyond what is neccesary but that's another problem).

Second, you have misunderstood. I do not "advocate" a state machine at all. An example of the technique could be a menu. Say there is a MAIN_MENU object that displays the main menu to the user. It has its own program loop and its own message handler. WinMain calls that program loop. The user goes through the displayed menu and presses ENTER. The MAIN_MENU object recieves that message and calls the program loop of a CHILD_MENU object which displays it's contents using it's own draw function. When the user is done with the submenu he/she can select "Back" in order to go back to the main menu. When the CHILD_MENU gets this message it simple exits its program loop and the program has suddenly returned to the main menu.

It looks quite messy when writing it I'll give you that, but it's actually not that much coding. It's really easy to make a general class that can handle anything.
.sehkteeah erthyahr gahro
Quote:
I do not "advocate" a state machine at all. An example of the technique could be a menu. Say there is a MAIN_MENU object that displays the main menu to the user. It has its own program loop and its own message handler. WinMain calls that program loop. The user goes through the displayed menu and presses ENTER. The MAIN_MENU object recieves that message and calls the program loop of a CHILD_MENU object which displays it's contents using it's own draw function. When the user is done with the submenu he/she can select "Back" in order to go back to the main menu. When the CHILD_MENU gets this message it simple exits its program loop and the program has suddenly returned to the main menu.

That is a state machine. It is very nearly the textbook example of a state machine.

That kind of high level overview isn't enough to dissuade me from thinking that the concept still seems brittle -- consider drawing, for example, which is a decently well-structured medium-to-large scale product will be the exact same process regardless of current state, with only minor variations. You seem to imply that each state object will duplicate the render loop. This is wasteful except in the rare instances where your rendering functionality is completely different from state-to-state. There's just a lot of implementation details that you're not covering here that, based on what you've written and how you've written it, could be implemented in extremely poor ways.

Perhaps you should construct a first draft of this article, which would help us get a better handle on what you are going for.
Quote:Original post by jpetrie
That is a state machine. It is very nearly the textbook example of a state machine.


Really? I though state machines where when you had a enum or similar structure to describe the game state and then a ... don't know what to call it ... "router-function" decides what functions to call based on the game state and I'm definetly not doing that. I'm not sure what you mean about the render loop, because there's only one loop actively running no matter how I do it.

And I think you are correct about me making a draft.

[EDIT]
I've gone through the menu-idea and found that I only need one single menu class to handle everything. Not rigid.

[Edited by - space warp on March 21, 2007 3:47:36 PM]
.sehkteeah erthyahr gahro
Quote:Original post by space warp
Really? I though state machines where when you had a enum or similar structure to describe the game state and then a ... don't know what to call it ... "router-function" decides what functions to call based on the game state and I'm definetly not doing that.
No, that's simply one of many idioms used to implement a state machine.

This topic is closed to new replies.

Advertisement