Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added CyGlobalContext::initStatics() function #1118

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
0378f7d
Merge pull request #154 from caveman2cosmos/master
MattOttawa Jun 8, 2021
f41a380
Merge pull request #155 from caveman2cosmos/master
MattOttawa Jun 10, 2021
bc2f408
Merge pull request #156 from caveman2cosmos/master
MattOttawa Jun 12, 2021
2a3a3d7
switched a unit build types loop to foreach
MattOttawa Jun 12, 2021
21f114b
Merge pull request #157 from caveman2cosmos/master
MattOttawa Jun 15, 2021
8e43b80
Merge pull request #158 from caveman2cosmos/master
MattOttawa Jun 16, 2021
eeb5714
Merge branch 'master' of https://github.com/MattOttawa/Caveman2Cosmos
MattOttawa Jun 16, 2021
9f623fb
deleted change on my master
MattOttawa Jun 16, 2021
0dd22a8
Merge pull request #159 from caveman2cosmos/master
MattOttawa Jun 20, 2021
66f07e0
Merge pull request #160 from caveman2cosmos/master
MattOttawa Jun 21, 2021
80aea90
Merge pull request #161 from caveman2cosmos/master
MattOttawa Jun 23, 2021
6cbb6b7
Merge pull request #162 from caveman2cosmos/master
MattOttawa Jun 27, 2021
48586e3
switched int to enum
MattOttawa Jun 28, 2021
368a6ca
Merge pull request #163 from caveman2cosmos/master
MattOttawa Jul 1, 2021
d27d75b
Merge branch 'master' of https://github.com/MattOttawa/Caveman2Cosmos
MattOttawa Jul 1, 2021
fdb6172
Merge pull request #164 from caveman2cosmos/master
MattOttawa Jul 4, 2021
1c1712d
Merge pull request #165 from caveman2cosmos/master
MattOttawa Jul 7, 2021
e2d636a
Merge pull request #166 from caveman2cosmos/master
MattOttawa Jul 8, 2021
4d2b06c
Merge pull request #167 from caveman2cosmos/master
MattOttawa Jul 8, 2021
f655034
Merge pull request #168 from caveman2cosmos/master
MattOttawa Jul 9, 2021
cdc17f3
Merge pull request #169 from caveman2cosmos/master
MattOttawa Jul 12, 2021
22bc6a9
fixed assert
MattOttawa Jul 12, 2021
8bc59a0
Merge pull request #170 from caveman2cosmos/master
MattOttawa Jul 12, 2021
c16165e
Merge pull request #171 from caveman2cosmos/master
MattOttawa Jul 18, 2021
1fc19a4
Merge pull request #172 from caveman2cosmos/master
MattOttawa Jul 22, 2021
7da4403
Merge pull request #173 from caveman2cosmos/master
MattOttawa Jul 24, 2021
1576e57
Merge pull request #174 from caveman2cosmos/master
MattOttawa Jul 24, 2021
44349f3
made the viewport for every map the same size as earth when viewports…
MattOttawa Jul 26, 2021
03fd762
Merge pull request #175 from caveman2cosmos/master
MattOttawa Jul 27, 2021
9b4f4f1
Merge pull request #176 from caveman2cosmos/master
MattOttawa Jul 29, 2021
7162459
Merge pull request #177 from caveman2cosmos/master
MattOttawa Aug 7, 2021
822edc0
Merge pull request #178 from caveman2cosmos/master
MattOttawa Aug 7, 2021
57b9f77
Merge pull request #179 from caveman2cosmos/master
MattOttawa Aug 8, 2021
8af1493
Merge pull request #180 from caveman2cosmos/master
MattOttawa Aug 15, 2021
9a046e7
added CyGlobalContext::initStatics() function
MattOttawa Aug 15, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions Sources/CvGlobals.cpp
Expand Up @@ -420,6 +420,7 @@ void cvInternalGlobals::init()

CvPlayerAI::initStatics();
CvTeamAI::initStatics();
CyGlobalContext::initStatics();

COPY(m_aiPlotDirectionX, aiPlotDirectionX, int);
COPY(m_aiPlotDirectionY, aiPlotDirectionY, int);
Expand Down
79 changes: 28 additions & 51 deletions Sources/CyGlobalContext.cpp
Expand Up @@ -18,12 +18,20 @@
#include "CyPlayer.h"
#include "CyTeam.h"

CyGlobalContext::CyGlobalContext()
{
}
std::vector<CyPlayer> g_cyPlayers;
std::vector<CyTeam> g_cyTeams;
std::vector<CyMap> g_cyMaps;

CyGlobalContext::~CyGlobalContext()
void CyGlobalContext::initStatics()
{
for (int i = 0; i < MAX_PLAYERS; i++)
g_cyPlayers.push_back(CyPlayer(&GET_PLAYER((PlayerTypes)i)));

for (int i = 0; i < MAX_TEAMS; i++)
g_cyTeams.push_back(CyTeam(&GET_TEAM((TeamTypes)i)));

for (int i = 0; i < NUM_MAPS; i++)
g_cyMaps.push_back(CyMap((MapTypes)i));
}

CyGlobalContext& CyGlobalContext::getInstance()
Expand All @@ -47,75 +55,44 @@ CyGame* CyGlobalContext::getCyGame() const
return &cyGame;
}


CyMap* CyGlobalContext::getCyMap() const
{
static CyMap cyMap(&GC.getMap());
static CyMap cyMap;
return &cyMap;
//return g_cyMaps[CURRENT_MAP];
}

void CyGlobalContext::switchMap(int iMap)
void CyGlobalContext::switchMap(MapTypes eMap)
{
GC.switchMap((MapTypes)iMap);
GC.switchMap(eMap);
}

CyMap* CyGlobalContext::getMapByIndex(int iIndex)
CyMap* CyGlobalContext::getMapByIndex(MapTypes eMap) const
{
static CyMap cyMap;
cyMap = GC.getMapByIndex((MapTypes)iIndex);
return &cyMap;
FASSERT_BOUNDS(0, NUM_MAPS, eMap);
return &g_cyMaps[eMap];
}

CyPlayer* CyGlobalContext::getCyPlayer(int idx) const
CyPlayer* CyGlobalContext::getCyPlayer(PlayerTypes ePlayer) const
{
static CyPlayer cyPlayers[MAX_PLAYERS];
static bool bInit = false;

if (!bInit)
{
for (int i = 0; i < MAX_PLAYERS; i++)
cyPlayers[i] = CyPlayer(&GET_PLAYER((PlayerTypes)i));
bInit = true;
}

if (idx >= 0 && idx < MAX_PLAYERS)
{
return &cyPlayers[idx];
}

FErrorMsg("Player index requested isn't valid");
return NULL;
FASSERT_BOUNDS(0, MAX_PLAYERS, ePlayer);
return ePlayer >= 0 && ePlayer < MAX_PLAYERS ? &g_cyPlayers[ePlayer] : NULL;
}


CyPlayer* CyGlobalContext::getCyActivePlayer() const
{
const PlayerTypes pt = GC.getGame().getActivePlayer();
return pt != NO_PLAYER ? getCyPlayer(pt) : NULL;
return getCyPlayer(GC.getGame().getActivePlayer());
}


CvRandom& CyGlobalContext::getCyASyncRand() const
{
return GC.getASyncRand();
}

CyTeam* CyGlobalContext::getCyTeam(int i) const
CyTeam* CyGlobalContext::getCyTeam(TeamTypes eTeam) const
{
static CyTeam cyTeams[MAX_TEAMS];
static bool bInit=false;

if (!bInit)
{
int j;
for(j=0;j<MAX_TEAMS;j++)
{
cyTeams[j]=CyTeam(&GET_TEAM((TeamTypes)j));
}
bInit = true;
}

return i<MAX_TEAMS ? &cyTeams[i] : NULL;
FASSERT_BOUNDS(0, MAX_TEAMS, eTeam);
return eTeam < MAX_TEAMS ? &g_cyTeams[eTeam] : NULL;
}

int CyGlobalContext::getInfoTypeForString(const char* szInfoType) const
Expand All @@ -133,9 +110,9 @@ int CyGlobalContext::getTypesEnum(const char* szType) const
return GC.getTypesEnum(szType);
}

const CvMapInfo& CyGlobalContext::getMapInfo(int i) const
const CvMapInfo& CyGlobalContext::getMapInfo(MapTypes eMap) const
{
return GC.getMapInfo((MapTypes)i);
return GC.getMapInfo(eMap);
}

const CvEffectInfo* CyGlobalContext::getEffectInfo(int /*EffectTypes*/ i) const
Expand Down
17 changes: 6 additions & 11 deletions Sources/CyGlobalContext.h
Expand Up @@ -10,7 +10,6 @@

#include "CvGlobals.h"

class CvArtFileMgr;
class CyGame;
class CyMap;
class CyPlayer;
Expand All @@ -20,28 +19,24 @@ class CyTeam;
class CyGlobalContext
{
public:
CyGlobalContext();
virtual ~CyGlobalContext();

static CyGlobalContext& getInstance(); // singleton accessor
static void initStatics();

bool isDebugBuild() const;
CyGame* getCyGame() const;
CyMap* getCyMap() const;

void switchMap(int iMap);
CyMap* getMapByIndex(int iIndex);

CyPlayer* getCyPlayer(int idx) const;
void switchMap(MapTypes eMap);
CyMap* getMapByIndex(MapTypes eMap) const;
CyPlayer* getCyPlayer(PlayerTypes ePlayer) const;
CyPlayer* getCyActivePlayer() const;
CvRandom& getCyASyncRand() const;
CyTeam* getCyTeam(int i) const;
CyTeam* getCyTeam(TeamTypes eTeam) const;

int getInfoTypeForString(const char* szInfoType) const;
int getInfoTypeForStringWithHiddenAssert(const char* szInfoType) const;
int getTypesEnum(const char* szType) const;

const CvMapInfo& getMapInfo(int i) const;
const CvMapInfo& getMapInfo(MapTypes eMap) const;
const CvEffectInfo* getEffectInfo(int i) const;
const CvTerrainInfo* getTerrainInfo(int i) const;
const CvBonusClassInfo* getBonusClassInfo(int i) const;
Expand Down
21 changes: 10 additions & 11 deletions Sources/CyMap.cpp
@@ -1,7 +1,3 @@
//
// Python wrapper class for CvMap
//

#include "CvGameCoreDLL.h"
#include "CvArea.h"
#include "CvInitCore.h"
Expand All @@ -14,14 +10,17 @@
#include "CyMap.h"
#include "CyPlot.h"

CyMap::CyMap() : m_pMap(NULL)
{
m_pMap = &GC.getMap();
}
//
// Python wrapper class for CvMap
//

CyMap::CyMap(CvMap* pMap) : m_pMap(pMap)
{
}
CyMap::CyMap()
: m_pMap(&GC.getMap())
{ }

CyMap::CyMap(MapTypes eMap)
: m_pMap(&GC.getMapByIndex(eMap))
{ }

int CyMap::getType()
{
Expand Down
3 changes: 2 additions & 1 deletion Sources/CyMap.h
Expand Up @@ -16,7 +16,8 @@ class CyMap
{
public:
CyMap();
explicit CyMap(CvMap* pMap); // Call from C++
explicit CyMap(MapTypes eMap);

//const CvMapInterfaceBase* getMap() const { return m_pMap; } // Call from C++

int getType();
Expand Down