1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
|
/**
* @file GlobalStuff.cpp
* @brief Globally accessible stuff
*
* Contains implementation of synced and
* unsynced global stuff
*/
#include "StdAfx.h"
#include "Rendering/GL/myGL.h"
#include "GlobalUnsynced.h"
#include <cstring>
#include <assert.h>
#include "mmgr.h"
#include "Util.h"
#include "Sim/Projectiles/ProjectileHandler.h"
#include "Game/GameHelper.h"
#include "Game/GameSetup.h"
#include "Sync/SyncTracer.h"
#include "Sim/Misc/Team.h"
#include "Game/Player.h"
#include "Sim/Misc/GlobalConstants.h"
#include "Rendering/Textures/TAPalette.h"
#include "Lua/LuaGaia.h"
#include "Lua/LuaRules.h"
#include "SDL_timer.h"
/**
* @brief global unsynced
*
* Global instance of CGlobalUnsyncedStuff
*/
CGlobalUnsyncedStuff* gu;
CR_BIND(CGlobalUnsyncedStuff,);
CR_REG_METADATA(CGlobalUnsyncedStuff, (
CR_MEMBER(teamNanospray), // ??
CR_MEMBER(modGameTime),
CR_MEMBER(gameTime),
CR_MEMBER(lastFrameTime),
CR_MEMBER(lastFrameStart),
CR_MEMBER(weightedSpeedFactor), // ??
CR_MEMBER(drawFrame), // ??
CR_MEMBER(myPlayerNum),
CR_MEMBER(myTeam),
CR_MEMBER(myAllyTeam),
CR_MEMBER(spectating),
CR_MEMBER(spectatingFullView),
CR_MEMBER(spectatingFullSelect),
CR_MEMBER(drawdebug), // ??
CR_MEMBER(active),
CR_MEMBER(viewRange),
CR_MEMBER(timeOffset),
// CR_MEMBER(compressTextures),
CR_MEMBER(drawFog),
CR_MEMBER(usRandSeed),
CR_RESERVED(64)
));
/**
* Initializes variables in CGlobalUnsyncedStuff
*/
CGlobalUnsyncedStuff::CGlobalUnsyncedStuff()
{
boost::uint64_t randnum;
randnum = SDL_GetTicks();
usRandSeed = randnum&0xffffffff;
modGameTime = 0;
gameTime = 0;
lastFrameTime = 0;
drawFrame = 1;
viewSizeX = 100;
viewSizeY = 100;
pixelX = 0.01f;
pixelY = 0.01f;
aspectRatio = 1.0f;
myPlayerNum = 0;
myTeam = 1;
myAllyTeam = 1;
spectating = false;
spectatingFullView = false;
spectatingFullSelect = false;
drawdebug = false;
active = true;
viewRange = MAX_VIEW_RANGE;
timeOffset = 0;
drawFog = true;
teamNanospray = false;
directControl = 0;
compressTextures = false;
atiHacks = false;
supportNPOTs = GLEW_ARB_texture_non_power_of_two;
{
std::string vendor = std::string((char*) glGetString(GL_VENDOR));
StringToLowerInPlace(vendor);
haveATI = (vendor.find("ati ") != string::npos);
if (haveATI) {
std::string renderer = std::string((char*) glGetString(GL_RENDERER));
StringToLowerInPlace(renderer);
supportNPOTs = (renderer.find(" x") == string::npos && renderer.find(" 9") == string::npos); //! x-series doesn't support NPOTs (but hd-series does)
}
}
}
/**
* Destroys variables in CGlobalUnsyncedStuff
*/
CGlobalUnsyncedStuff::~CGlobalUnsyncedStuff()
{
}
/**
* @return unsynced random integer
*
* Returns an unsynced random integer
*/
int CGlobalUnsyncedStuff::usRandInt()
{
usRandSeed = (usRandSeed * 214013L + 2531011L);
return usRandSeed & RANDINT_MAX;
}
/**
* @return unsynced random float
*
* returns an unsynced random float
*/
float CGlobalUnsyncedStuff::usRandFloat()
{
usRandSeed = (usRandSeed * 214013L + 2531011L);
return float(usRandSeed & RANDINT_MAX)/RANDINT_MAX;
}
/**
* @return unsynced random vector
*
* returns an unsynced random vector
*/
float3 CGlobalUnsyncedStuff::usRandVector()
{
float3 ret;
do {
ret.x = usRandFloat() * 2 - 1;
ret.y = usRandFloat() * 2 - 1;
ret.z = usRandFloat() * 2 - 1;
} while (ret.SqLength() > 1);
return ret;
}
void CGlobalUnsyncedStuff::SetMyPlayer(const int mynumber)
{
myPlayerNum = mynumber;
if (gameSetup && gameSetup->playerStartingData.size() > mynumber)
{
myTeam = gameSetup->playerStartingData[myPlayerNum].team;
myAllyTeam = gameSetup->teamStartingData[myTeam].teamAllyteam;
spectating = gameSetup->playerStartingData[myPlayerNum].spectator;
spectatingFullView = gameSetup->playerStartingData[myPlayerNum].spectator;
spectatingFullSelect = gameSetup->playerStartingData[myPlayerNum].spectator;
assert(myPlayerNum >= 0
&& gameSetup->playerStartingData.size() >= static_cast<size_t>(myPlayerNum)
&& myTeam >= 0
&& gameSetup->teamStartingData.size() >= myTeam);
}
}
|