gamemode.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /***********************************************************************************************
  19. *** Confidential - Westwood Studios ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : Commando *
  23. * *
  24. * $Archive:: /Commando/Code/Commando/gamemode.h $*
  25. * *
  26. * $Author:: Tom_s $*
  27. * *
  28. * $Modtime:: 5/04/01 7:08p $*
  29. * *
  30. * $Revision:: 13 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #ifndef GAMEMODE_H
  36. #define GAMEMODE_H
  37. #ifndef ALWAYS_H
  38. #include "always.h"
  39. #endif
  40. #ifndef VECTOR3_H
  41. #include "vector3.h"
  42. #endif
  43. #ifndef WWDEBUG_H
  44. #include "wwdebug.h"
  45. #endif
  46. /*
  47. ** Game modes are objects to manage each of the game's modes and
  48. ** sub-modes. Primarily, each object will provide a Initializing
  49. ** routine to allow it to allocate any required resources, a Shutdown
  50. ** routine to allow it to free said resources, and a Think routine,
  51. ** which will be called each time through the main loop, allowing the
  52. ** mode to perform any necessary periodic tasks.
  53. **
  54. ** Each mode can be Activated, Deactivated, Suspended, or Resumed
  55. */
  56. typedef enum {
  57. GAME_MODE_ACTIVE,
  58. GAME_MODE_INACTIVE,
  59. GAME_MODE_INACTIVE_PENDING,
  60. GAME_MODE_SUSPENDED,
  61. } GameModeState;
  62. class GameModeClass {
  63. protected:
  64. GameModeState State;
  65. public:
  66. GameModeClass() { State = GAME_MODE_INACTIVE; } // starts off inactive
  67. virtual ~GameModeClass() { WWASSERT( State == GAME_MODE_INACTIVE ); } // assert inactive
  68. // gets the current state
  69. GameModeState Get_State() { return State; }
  70. virtual void Activate(); // activates the mode
  71. virtual void Deactivate(); // deactivates the mode (don't shutdown until safe)
  72. virtual void Safely_Deactivate(); // shutdown if requested
  73. virtual void Suspend(); // suspends the mode from thinking, but does not deactivate it
  74. virtual void Resume(); // resumes a suspended mode
  75. virtual bool Is_Inactive( void ) { return ( State == GAME_MODE_INACTIVE ) || ( State == GAME_MODE_INACTIVE_PENDING ); }
  76. virtual bool Is_Suspended( void ) { return ( State == GAME_MODE_SUSPENDED ); }
  77. virtual bool Is_Active( void ) { return ( State == GAME_MODE_ACTIVE ); }
  78. // the virtual functions
  79. virtual const char *Name() = 0; // the name of this mode
  80. virtual void Init() = 0; // called when the mode is activated
  81. virtual void Shutdown() = 0; // called when the mode is deactivated
  82. virtual void Render() = 0; // called each time through the main loop to draw if not inactive
  83. virtual void Think() = 0; // called each time through the main loop to think if not inactive
  84. };
  85. /*
  86. ** Only 1 Major Game mode can be active at any time
  87. */
  88. class GameMajorModeClass : public GameModeClass {
  89. public:
  90. virtual void Activate(); // Override Activate and Deactivate to count
  91. virtual void Deactivate();
  92. private:
  93. static int NumActiveMajorModes;
  94. };
  95. /*
  96. ** GameModeManager - an object to maintain a list of all GameModes
  97. */
  98. class GameModeManager {
  99. public:
  100. /*
  101. ** Add, Remove, Destroy and count the modes
  102. */
  103. static GameModeClass *Add( GameModeClass *mode ); // { GameModeList.Add_Tail( mode ); return mode; }
  104. static void Remove( GameModeClass *mode ); // { GameModeList.Remove( mode ); }
  105. static int Count(); // { return GameModeList.Get_Count(); }
  106. static void Destroy( GameModeClass *mode );
  107. static void Destroy_All( void );
  108. static void List_Active_Game_Modes(void); // diagnostic
  109. //
  110. static void Set_Background_Color( const Vector3 & color ) { BackgroundColor = color; }
  111. /*
  112. ** let all non-inactive, game modes think
  113. */
  114. static void Think( void );
  115. /*
  116. ** let all non-inactive, game modes draw
  117. */
  118. static void Render( void );
  119. /*
  120. ** find a registered game mode by name
  121. */
  122. static GameModeClass *Find( const char * name );
  123. //static bool IsLanNameCollisionDetected;
  124. static void Safely_Deactivate();
  125. static void Hide_Render_Frames(unsigned frame_count); // hide rendering for n frames
  126. private:
  127. static Vector3 BackgroundColor;
  128. };
  129. #endif // GAMEMODE_H