1 /* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */ 2 3 #ifndef _GLOBAL_UNSYNCED_H 4 #define _GLOBAL_UNSYNCED_H 5 6 #include "System/creg/creg_cond.h" 7 #include "System/float3.h" 8 #include "System/UnsyncedRNG.h" 9 10 class CPlayer; 11 class CGameSetup; 12 13 /** 14 * @brief Globally accessible unsynced data 15 * 16 * Contains globally accessible data that does not remain synced 17 */ 18 class CGlobalUnsynced { 19 CR_DECLARE_STRUCT(CGlobalUnsynced) 20 21 CGlobalUnsynced(); 22 ~CGlobalUnsynced(); 23 24 static UnsyncedRNG rng; 25 26 public: RandInt()27 int RandInt() { return rng.RandInt(); } //!< random int [0, (INT_MAX & 0x7FFF)) RandFloat()28 float RandFloat() { return rng.RandFloat(); } //!< random float [0, 1) RandVector()29 float3 RandVector() { return rng.RandVector(); } //!< random vector with length = [0, 1) 30 31 void LoadFromSetup(const CGameSetup* setup); 32 void SetMyPlayer(const int myNumber); 33 CPlayer* GetMyPlayer(); 34 35 /** 36 * @brief minimum FramesPerSecond 37 * 38 * Defines how many Frames per second 39 * should be rendered. To reach it we 40 * will delay simframes. 41 */ 42 static const int minFPS = 2; 43 44 /** 45 * @brief simulation drawing balance 46 * 47 * Defines how much percent of the time 48 * for simulation is minimum spend for 49 * drawing. 50 * This is important when reconnecting, 51 * i.e. it means that 15% of the total 52 * cpu time is spend for drawing and 85% 53 * for reconnecting/simulation. 54 */ 55 static const float reconnectSimDrawBalance; 56 57 /** 58 * @brief simulation frames per second 59 * 60 * Should normally be: 61 * simFPS ~= GAME_SPEED * gs->wantedSpeedFactor; 62 * Only differs if the client lags or reconnects. 63 */ 64 float simFPS; 65 66 /** 67 * @brief average frame time (in ms) 68 */ 69 float avgSimFrameTime; 70 float avgDrawFrameTime; 71 float avgFrameTime; 72 73 /** 74 * @brief mod game time 75 * 76 * How long the game has been going on 77 * (modified with game's speed factor) 78 */ 79 float modGameTime; 80 81 /** 82 * @brief game time 83 * 84 * How long the game has been going on 85 * in real time 86 */ 87 float gameTime; 88 89 /** 90 * @brief start time 91 * 92 * The value of gameTime when the game was started 93 */ 94 float startTime; 95 96 /** 97 * @brief my player num 98 * 99 * Local player's number 100 */ 101 int myPlayerNum; 102 103 /** 104 * @brief my team 105 * @note changes when changing spectated team 106 * 107 * Local player's team 108 */ 109 int myTeam; 110 111 /** 112 * @brief my ally team 113 * @note changes when changing spectated team 114 * 115 * Local player's ally team 116 */ 117 int myAllyTeam; 118 119 /** 120 * @brief my team used when playing 121 * @note changes only from TEAMMSG_JOIN_TEAM and SetMyPlayer 122 * @note if we never joined any team, it's set to -1 123 * 124 * Local player's team 125 */ 126 int myPlayingTeam; 127 128 /** 129 * @brief my ally team 130 * @note changes only from TEAMMSG_JOIN_TEAM and SetMyPlayer 131 * @note if we never joined any team, it's set to -1 132 * 133 * Local player's ally team 134 */ 135 int myPlayingAllyTeam; 136 137 138 /** 139 * @brief spectating 140 * 141 * Whether this player is spectating 142 * (can't give orders, and can see everything if spectateFullView is true) 143 */ 144 bool spectating; 145 146 /** 147 * @brief spectatingFullView 148 * 149 * Whether this player is a spectator, and can see everything 150 * (if set to false, visibility is determined by the current team) 151 */ 152 bool spectatingFullView; 153 154 /** 155 * @brief spectatingFullSelect 156 * 157 * Can all units be selected when spectating? 158 */ 159 bool spectatingFullSelect; 160 161 /** 162 * @brief fpsMode 163 * 164 * if true, player is controlling a unit in FPS mode 165 */ 166 bool fpsMode; 167 168 /** 169 * @brief global quit 170 * 171 * Global boolean indicating whether the user 172 * wants to quit 173 */ 174 volatile bool globalQuit; 175 }; 176 177 extern CGlobalUnsynced* gu; 178 179 #endif /* _GLOBAL_UNSYNCED_H */ 180