Advertisement
Charybdizs

Game states

Feb 8th, 2015
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.18 KB | None | 0 0
  1. <Charybdizs> I've been struggling with a programming design question
  2. <Charybdizs> http://www.gamedev.net/topic/665255-standard-structure-of-a-large-scale-game/
  3. <Charybdizs> I was wondering if you could shed any light on it
  4. <SSNTails> hey, sorry, i left irc on
  5. <Charybdizs> I knew you were afk, no issue
  6. <SSNTails> well, there really isn't a straight answer to your question
  7. <SSNTails> what we do is have a 'core' engine, and then each game project implements certain function hooks that the core expects to be there
  8. <Charybdizs> I'm not looking so much for a straight answer as much as I am for like
  9. <Charybdizs> SOMETHING other than what I have there
  10. <SSNTails> what you have there is certainly very doomy, heh
  11. <Charybdizs> and more than that, how to handle one time events in a continuing loop
  12. <SSNTails> you could have a base GameType class, that Pinball and Adventure classes inherit from
  13. <SSNTails> and they all implement a base set of functions defined in the GameType parent class
  14. <Charybdizs> without making something stupid like a variable "DidILoadThisCrap"
  15. <SSNTails> like our UI system...
  16. <Charybdizs> Hmmm
  17. <SSNTails> everything that's a part of the UI inherits from a parent class called 'Control'
  18. <SSNTails> A button is a control, an image is a control, a textbox is a control... anything you make custom is a control
  19. <SSNTails> when a class is a control, it is required to implement certain functions
  20. <Charybdizs> but different parts of the game have different UI setups
  21. <Charybdizs> what determines which setup it's currently using?
  22. <SSNTails> have you done any WinForms in C#?
  23. <SSNTails> each window is a 'Form' class
  24. <SSNTails> which can contain a bunch of controls
  25. <SSNTails> so, you make a class called ShopMenu, inherits from Form
  26. <SSNTails> in the ShopMenu constructor, you create Buttons, Images, TextBoxes, etc. and add them to the ShopMenu
  27. <SSNTails> in Wizard2, you just do something like:
  28. <SSNTails> ShopMenu *menu = new ShopMenu();
  29. <SSNTails> FormHandler->AddForm(menu);
  30. <SSNTails> and the menu is created, and pushed to the top of the stack of active screens
  31. <Charybdizs> Nah, I haven't actually
  32. <SSNTails> so you could make a ShopMenu, MultiplayerMenu, OptionsMenu, etc.
  33. <Charybdizs> I've usually written my own gui for the learning experience
  34. <Charybdizs> that sounds very understandable though
  35. <Charybdizs> so yeah basically what you're describing is what I said
  36. <Charybdizs> a menustate
  37. <Charybdizs> that changes depending on what the game currently is doing
  38. <Charybdizs> and you'd use something like an if statement or a switch to alternate between them
  39. <SSNTails> hmm? give me an example
  40. <SSNTails> like if you have a MainMenu, then show an OptionsMenu. Main menu is still there, just behind the Options Menu. User clicks 'Back' from the Options menu, and the Options menu kills itself and the old MainMenu now is in front
  41. <Charybdizs> oh
  42. <Charybdizs> okay that makes sense
  43. <Charybdizs> I misunderstood at first
  44. <SSNTails> you typically let each menu mind its own business
  45. <SSNTails> you dont have other menus killing other menus
  46. <SSNTails> because those other menus don't know what kind of state the menu it is killing is in
  47. <SSNTails> and if that's something stable to do
  48. <Charybdizs> yeah
  49. <Charybdizs> well that makes sense, but I'm trying to imagine how that might work in a game with many different "States" where there might be a different menu format for each one
  50. <SSNTails> like..?
  51. <Charybdizs> ohhhhh
  52. <Charybdizs> I just got it
  53. <Charybdizs> nevermind
  54. <SSNTails> lol whaat
  55. <Charybdizs> so let me get this straight
  56. <Charybdizs> in a system like that, you'd ALWAYS be dealing with an active queue of menus, you'd just have a bunch that all inherit from the basic Form type. Whenever the menu queue is empty, it simply does nothing because there's nothing to do anything WITH. But when a menu is activated, that queue fills and it begins iterating over everthing in it...
  57. <Charybdizs> sorry if I'm confusing. My programming experience is nearly all self taught so I'm not up on a lot of the lingo and usually find my own ways to describe things
  58. <SSNTails> yeah, sort of
  59. <SSNTails> np, i self taught myself too
  60. <SSNTails> for years i was using pointers and not knowing what they were!
  61. <Charybdizs> I invented a type of component based programming all on my own and just last week learned that it's close to an actual practice
  62. <SSNTails> hahahaha
  63. <Charybdizs> So moving on from menus and into more complex situations, like the difference between tetris and an FPS though, you might be dealing with two things that are significantly different from each other and wouldn't be best merged into variants of one loose class type, I think
  64. <SSNTails> Wizard2 does use game states, kind of in a doom-like way
  65. <Charybdizs> You know what, lemme be more specific
  66. <SSNTails> if GameState::NONE, then it only runs the menu system, which relies on that queue of menus
  67. <SSNTails> GameState::LEVEL will run the world functions
  68. <SSNTails> and then run the menu on top
  69. <SSNTails> the HUD itself on top of the world system is also its own menu queue
  70. <SSNTails> and on top of EVERYTHING there is an additional menu queue (the overlay)
  71. <SSNTails> in reality, the world state could become a 'control'
  72. <SSNTails> and put into a menu form
  73. <Charybdizs> I'm designing a turn based strategy a lot along the lines of advance wars and all that. It operates on a 3d field though, and levels are initially made out of blocks of different types, e.g., stone, dirt, water, pavement
  74. <SSNTails> (then you could have multiple worlds at one time.. hah!)
  75. <SSNTails> yeah, i remember you talking a bit about this
  76. <Charybdizs> I have a large amount of the api for the actual levels completed
  77. <Charybdizs> but the confusion
  78. <Charybdizs> is coming in the complete separation between having a playfield where the player moves around their units, having animated battle cutscenes, and having a small overworld area which operates nothing like a turn based strategy
  79. <Charybdizs> and then of course
  80. <Charybdizs> loading and unloading the proper resources for these
  81. <Charybdizs> at the correct times
  82. <Charybdizs> almost none of those features will share any significant code
  83. <SSNTails> i would stuff each part's state into a class
  84. <SSNTails> so in C#...
  85. <SSNTails> I would create an interface
  86. <SSNTails> public interface GameState {
  87. <SSNTails> and define these functions:
  88. <SSNTails> Initialize();
  89. <SSNTails> Update();
  90. <SSNTails> Shutdown();
  91. <SSNTails> }
  92. <SSNTails> then your BattleCutscene, Overworld, etc. classes all inherit from this GameState
  93. <SSNTails> public class OverworldState : IGameState
  94. <SSNTails> (put an I in front of GameState because it's an interface, not a class)
  95. <SSNTails> yes, it takes awhile to wrap your head around interfaces
  96. <SSNTails> essentially what you're building is not a real class, but rather defining functions that all classes which inherit from it are required to have
  97. <SSNTails> SO
  98. <SSNTails> in your main game loop area
  99. <Charybdizs> isn't that the same as an abstract class?
  100. <SSNTails> you have a List<IGameState>
  101. <SSNTails> it's VERY similar to C++'s virtual abstract class
  102. <SSNTails> but i dont think an abstract class FORCES you to implement things
  103. <SSNTails> whereas an interface does
  104. <SSNTails> foreach (IGameState state in myGameStateList)
  105. <SSNTails> {
  106. <SSNTails> state.Update();
  107. <SSNTails> }
  108. <Charybdizs> I know they both exist in C# but I've always used abstracts and haven't been able to figure out the practical differences
  109. <SSNTails> That will call the Update function whether it is a BattleCutscene, Overworld, or whatever
  110. <SSNTails> http://stackoverflow.com/questions/747517/interfaces-vs-abstract-classes
  111. <Charybdizs> "Ability to specify default implementations of methods"
  112. <Charybdizs> ooooh
  113. <Charybdizs> okay
  114. <Charybdizs> this makes sense
  115. <SSNTails> yeah you cant do that with an interface
  116. <SSNTails> (and im not sure you'd WANT to do that in this situation)
  117. <Charybdizs> Hmm, you know what
  118. <Charybdizs> I like
  119. <Charybdizs> wait brb
  120. <SSNTails> some more brain-exploding information: http://stackoverflow.com/questions/56867/interface-vs-base-class
  121. <SSNTails> i gotta sleep. im happy to discuss this more in daylight :)
  122. <Charybdizs> Alright
  123. <Charybdizs> I'll catch you tomorrow then
  124. * SSNTails has quit ()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement