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
|
/* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */
#include "GlobalSynced.h"
#include <assert.h>
#include <cstring>
#include "ExternalAI/SkirmishAIHandler.h"
#include "Game/GameSetup.h"
#include "Sim/Misc/TeamHandler.h"
#include "Sim/Misc/GlobalConstants.h"
#include "System/Util.h"
#include "System/Log/FramePrefixer.h"
/**
* @brief global synced
*
* Global instance of CGlobalSynced
*/
CGlobalSynced* gs = NULL;
CR_BIND(CGlobalSynced, )
CR_REG_METADATA(CGlobalSynced, (
CR_MEMBER(frameNum),
CR_MEMBER(speedFactor),
CR_MEMBER(wantedSpeedFactor),
CR_MEMBER(paused),
CR_MEMBER(mapx),
CR_MEMBER(mapxm1),
CR_MEMBER(mapxp1),
CR_MEMBER(mapy),
CR_MEMBER(mapym1),
CR_MEMBER(mapyp1),
CR_MEMBER(mapSquares),
CR_MEMBER(hmapx),
CR_MEMBER(hmapy),
CR_MEMBER(pwr2mapx),
CR_MEMBER(pwr2mapy),
CR_MEMBER(tempNum),
CR_MEMBER(godMode),
CR_MEMBER(globalLOS),
CR_MEMBER(cheatEnabled),
CR_MEMBER(noHelperAIs),
CR_MEMBER(editDefsEnabled),
CR_MEMBER(useLuaGaia),
CR_MEMBER(randSeed),
CR_MEMBER(initRandSeed)
))
/**
* Initializes variables in CGlobalSynced
*/
CGlobalSynced::CGlobalSynced()
{
mapx = 512;
mapy = 512;
mapxm1 = mapx - 1;
mapym1 = mapy - 1;
mapxp1 = mapx + 1;
mapyp1 = mapy + 1;
mapSquares = mapx * mapy;
hmapx = mapx>>1;
hmapy = mapy>>1;
pwr2mapx = mapx; //next_power_of_2(mapx);
pwr2mapy = mapy; //next_power_of_2(mapy);
randSeed = 18655;
initRandSeed = randSeed;
frameNum = 0;
speedFactor = 1;
wantedSpeedFactor = 1;
paused = false;
godMode = false;
cheatEnabled = false;
noHelperAIs = false;
editDefsEnabled = false;
tempNum = 2;
useLuaGaia = true;
memset(globalLOS, 0, sizeof(globalLOS));
log_framePrefixer_setFrameNumReference(&frameNum);
teamHandler = new CTeamHandler();
}
CGlobalSynced::~CGlobalSynced()
{
SafeDelete(teamHandler);
log_framePrefixer_setFrameNumReference(NULL);
}
void CGlobalSynced::LoadFromSetup(const CGameSetup* setup)
{
noHelperAIs = setup->noHelperAIs;
useLuaGaia = setup->useLuaGaia;
skirmishAIHandler.LoadFromSetup(*setup);
teamHandler->LoadFromSetup(setup);
}
/**
* @return synced random integer
*
* returns a synced random integer
*/
int CGlobalSynced::randInt()
{
randSeed = (randSeed * 214013L + 2531011L);
return (randSeed >> 16) & RANDINT_MAX;
}
/**
* @return synced random float
*
* returns a synced random float
*/
float CGlobalSynced::randFloat()
{
randSeed = (randSeed * 214013L + 2531011L);
return float((randSeed >> 16) & RANDINT_MAX)/RANDINT_MAX;
}
/**
* @return synced random vector
*
* returns a synced random vector
*/
float3 CGlobalSynced::randVector()
{
float3 ret;
do {
ret.x = randFloat()*2-1;
ret.y = randFloat()*2-1;
ret.z = randFloat()*2-1;
} while(ret.SqLength()>1);
return ret;
}
|