CShell::[SG]etCurrentWorld() instead of putting it in INDEX console var

The code used to store the world pointer as a console variable
"pwoCurrentWorld" of type INDEX (int32) - that won't work for 64bit, so
I added CShell::SetCurrentWorld() and CShell::GetCurrentWorld() and
store it as a pointer.
This commit is contained in:
Daniel Gibson 2016-04-18 18:52:52 +02:00
parent 78ab018fde
commit 5f5106e363
6 changed files with 28 additions and 26 deletions

View File

@ -148,6 +148,7 @@ CShell::CShell(void)
{ {
// allocate undefined symbol // allocate undefined symbol
_shell_istUndeclared = _shell_ast.Allocate(); _shell_istUndeclared = _shell_ast.Allocate();
pwoCurrentWorld = NULL;
}; };
CShell::~CShell(void) CShell::~CShell(void)
{ {
@ -704,7 +705,6 @@ INDEX CShell::GetINDEX(const CTString &strName)
return -666; return -666;
} }
// get it // get it
STUBBED("64-bit issue"); // the return value is used as a pointer a lot!
return *(INDEX*)pss->ss_pvValue; return *(INDEX*)pss->ss_pvValue;
} }

View File

@ -33,6 +33,8 @@ public:
CTCriticalSection sh_csShell; // critical section for access to shell data CTCriticalSection sh_csShell; // critical section for access to shell data
CDynamicArray<CShellSymbol> sh_assSymbols; // all defined symbols CDynamicArray<CShellSymbol> sh_assSymbols; // all defined symbols
CWorld* pwoCurrentWorld;
// Get a shell symbol by its name. // Get a shell symbol by its name.
CShellSymbol *GetSymbol(const CTString &strName, BOOL bDeclaredOnly); CShellSymbol *GetSymbol(const CTString &strName, BOOL bDeclaredOnly);
// Report error in shell script processing. // Report error in shell script processing.
@ -59,13 +61,23 @@ public:
// get/set symbols // get/set symbols
FLOAT GetFLOAT(const CTString &strName); FLOAT GetFLOAT(const CTString &strName);
void SetFLOAT(const CTString &strName, FLOAT fValue); void SetFLOAT(const CTString &strName, FLOAT fValue);
INDEX GetINDEX(const CTString &strName); // FIXME DG: maybe this should return size_t or uintptr_t? return value is casted to ptr all the time! INDEX GetINDEX(const CTString &strName);
void SetINDEX(const CTString &strName, INDEX iValue); void SetINDEX(const CTString &strName, INDEX iValue);
CTString GetString(const CTString &strName); CTString GetString(const CTString &strName);
void SetString(const CTString &strName, const CTString &strValue); void SetString(const CTString &strName, const CTString &strValue);
CTString GetValue(const CTString &strName); CTString GetValue(const CTString &strName);
void SetValue(const CTString &strName, const CTString &strValue); void SetValue(const CTString &strName, const CTString &strValue);
void SetCurrentWorld(CWorld* pwo)
{
pwoCurrentWorld = pwo;
}
CWorld* GetCurrentWorld(void)
{
return pwoCurrentWorld;
}
}; };
// pointer to global shell object // pointer to global shell object

View File

@ -86,8 +86,6 @@ BOOL _bTempNetwork = FALSE; // set while using temporary second network object
extern BOOL con_bCapture; extern BOOL con_bCapture;
extern CTString con_strCapture; extern CTString con_strCapture;
static CWorld *_pwoCurrentWorld = NULL;
static FLOAT _bStartDemoRecordingNextTime = FALSE; static FLOAT _bStartDemoRecordingNextTime = FALSE;
static FLOAT _bStopDemoRecordingNextTime = FALSE; static FLOAT _bStopDemoRecordingNextTime = FALSE;
static INDEX dem_iRecordedNumber = 0; static INDEX dem_iRecordedNumber = 0;
@ -254,8 +252,7 @@ extern void CacheShadows(void)
{ {
// mute all sounds // mute all sounds
_pSound->Mute(); _pSound->Mute();
STUBBED("64-bit issue"); // GetINDEX() returns int32! CWorld *pwo = _pShell->GetCurrentWorld();
CWorld *pwo = (CWorld*)_pShell->GetINDEX("pwoCurrentWorld");
if( pwo!=NULL) { if( pwo!=NULL) {
pwo->wo_baBrushes.CacheAllShadowmaps(); pwo->wo_baBrushes.CacheAllShadowmaps();
CPrintF( TRANS("All shadows recached")); CPrintF( TRANS("All shadows recached"));
@ -523,8 +520,7 @@ static void StockInfo(void)
INDEX ctEntities=0, ctShadowLayers=0, ctPolys=0, ctPlanes=0, ctEdges=0, ctVertices=0, ctSectors=0; INDEX ctEntities=0, ctShadowLayers=0, ctPolys=0, ctPlanes=0, ctEdges=0, ctVertices=0, ctSectors=0;
SLONG slEntBytes=0, slLyrBytes=0, slPlyBytes=0, slPlnBytes=0, slEdgBytes=0, slVtxBytes=0, slSecBytes=0; SLONG slEntBytes=0, slLyrBytes=0, slPlyBytes=0, slPlnBytes=0, slEdgBytes=0, slVtxBytes=0, slSecBytes=0;
SLONG slCgrBytes=0; SLONG slCgrBytes=0;
STUBBED("64-bit issue"); // GetINDEX() returns int32! CWorld *pwo = _pShell->GetCurrentWorld();
CWorld *pwo = (CWorld*)_pShell->GetINDEX("pwoCurrentWorld");
if( pwo!=NULL) if( pwo!=NULL)
{ {
@ -899,7 +895,6 @@ void CNetworkLibrary::Init(const CTString &strGameID)
_pShell->DeclareSymbol("persistent user CTString ga_strMSLegacy;", (void *)&ga_strMSLegacy); _pShell->DeclareSymbol("persistent user CTString ga_strMSLegacy;", (void *)&ga_strMSLegacy);
_pShell->DeclareSymbol("persistent user INDEX ga_bMSLegacy;", (void *)&ga_bMSLegacy); _pShell->DeclareSymbol("persistent user INDEX ga_bMSLegacy;", (void *)&ga_bMSLegacy);
_pShell->DeclareSymbol("INDEX pwoCurrentWorld;", (void *)&_pwoCurrentWorld);
} }
/* /*
@ -1041,8 +1036,7 @@ void CNetworkLibrary::StartPeerToPeer_t(const CTString &strSessionName,
throw; throw;
} }
// remember the world pointer // remember the world pointer
STUBBED("64-bit issue"); _pShell->SetCurrentWorld(&ga_World);
_pShell->SetINDEX("pwoCurrentWorld", (INDEX)(size_t)&ga_World);
SetProgressDescription(TRANS("starting server")); SetProgressDescription(TRANS("starting server"));
CallProgressHook_t(0.0f); CallProgressHook_t(0.0f);
@ -1279,8 +1273,7 @@ void CNetworkLibrary::JoinSession_t(const CNetworkSession &nsSesssion, INDEX ctL
} }
// remember the world pointer // remember the world pointer
STUBBED("64-bit issue"); _pShell->SetCurrentWorld(&ga_World);
_pShell->SetINDEX("pwoCurrentWorld", (INDEX)(size_t)&ga_World);
// eventually cache all shadowmaps in world (memory eater!) // eventually cache all shadowmaps in world (memory eater!)
if( shd_bCacheAll) ga_World.wo_baBrushes.CacheAllShadowmaps(); if( shd_bCacheAll) ga_World.wo_baBrushes.CacheAllShadowmaps();
@ -1352,8 +1345,7 @@ void CNetworkLibrary::StartDemoPlay_t(const CTFileName &fnDemo) // throw char *
_bNeedPretouch = TRUE; _bNeedPretouch = TRUE;
// remember the world pointer // remember the world pointer
STUBBED("64-bit issue"); _pShell->SetCurrentWorld(&ga_World);
_pShell->SetINDEX("pwoCurrentWorld", (INDEX)(size_t)&ga_World);
// demo synchronization starts at the beginning initially // demo synchronization starts at the beginning initially
ga_fDemoTimer = 0.0f; ga_fDemoTimer = 0.0f;
@ -1562,7 +1554,7 @@ void CNetworkLibrary::StopGame(void)
ga_aplsPlayers.Clear(); ga_aplsPlayers.Clear();
ga_aplsPlayers.New(NET_MAXLOCALPLAYERS); ga_aplsPlayers.New(NET_MAXLOCALPLAYERS);
// remember the world pointer // remember the world pointer
_pShell->SetINDEX("pwoCurrentWorld", (INDEX)NULL); _pShell->SetCurrentWorld(NULL);
// rewind the timer // rewind the timer
_pTimer->SetCurrentTick(0.0f); _pTimer->SetCurrentTick(0.0f);
@ -1686,8 +1678,7 @@ void CNetworkLibrary::ChangeLevel_internal(void)
// remember the world filename // remember the world filename
ga_fnmWorld = ga_fnmNextLevel; ga_fnmWorld = ga_fnmNextLevel;
// remember the world pointer // remember the world pointer
STUBBED("64-bit issue"); _pShell->SetCurrentWorld(&ga_World);
_pShell->SetINDEX("pwoCurrentWorld", (INDEX)(size_t)&ga_World);
// if there is remembered level // if there is remembered level
} else { } else {
// restore it // restore it
@ -2392,8 +2383,7 @@ extern void NET_MakeDefaultState_t(
_pNetwork->ga_fnmWorld = fnmWorld; _pNetwork->ga_fnmWorld = fnmWorld;
_pNetwork->ga_fnmNextLevel = CTString(""); _pNetwork->ga_fnmNextLevel = CTString("");
// remember the world pointer // remember the world pointer
STUBBED("64-bit issue"); _pShell->SetCurrentWorld(&_pNetwork->ga_World);
_pShell->SetINDEX("pwoCurrentWorld", (INDEX)(size_t)&_pNetwork->ga_World);
// reset random number generator // reset random number generator
_pNetwork->ga_sesSessionState.ResetRND(); _pNetwork->ga_sesSessionState.ResetRND();

View File

@ -86,7 +86,7 @@ EntityStats *FindStats(const CTString &strName)
static void MakeWorldStatistics(void) static void MakeWorldStatistics(void)
{ {
// get the world pointer // get the world pointer
CWorld *pwo = (CWorld *)_pShell->GetINDEX("pwoCurrentWorld"); CWorld *pwo = _pShell->GetCurrentWorld();
// if there is no current world // if there is no current world
if (pwo==NULL) { if (pwo==NULL) {
CPrintF("No current world.\n"); CPrintF("No current world.\n");
@ -152,7 +152,7 @@ static void MakeWorldStatistics(void)
static void ReoptimizeAllBrushes(void) static void ReoptimizeAllBrushes(void)
{ {
// get the world pointer // get the world pointer
CWorld *pwo = (CWorld *)_pShell->GetINDEX("pwoCurrentWorld"); CWorld *pwo = _pShell->GetCurrentWorld();
// if there is no current world // if there is no current world
if (pwo==NULL) { if (pwo==NULL) {
CPrintF("No current world.\n"); CPrintF("No current world.\n");

View File

@ -64,7 +64,7 @@ EntityStats *FindStats(const CTString &strName)
static void MakeWorldStatistics(void) static void MakeWorldStatistics(void)
{ {
// get the world pointer // get the world pointer
CWorld *pwo = (CWorld *)_pShell->GetINDEX("pwoCurrentWorld"); CWorld *pwo = _pShell->GetCurrentWorld();
// if there is no current world // if there is no current world
if (pwo==NULL) { if (pwo==NULL) {
CPrintF("No current world.\n"); CPrintF("No current world.\n");
@ -130,7 +130,7 @@ static void MakeWorldStatistics(void)
static void ReoptimizeAllBrushes(void) static void ReoptimizeAllBrushes(void)
{ {
// get the world pointer // get the world pointer
CWorld *pwo = (CWorld *)_pShell->GetINDEX("pwoCurrentWorld"); CWorld *pwo = _pShell->GetCurrentWorld();
// if there is no current world // if there is no current world
if (pwo==NULL) { if (pwo==NULL) {
CPrintF("No current world.\n"); CPrintF("No current world.\n");
@ -157,7 +157,7 @@ static void DoLevelSafetyChecks()
CPrintF("\n**** BEGIN Level safety checking ****\n\n"); CPrintF("\n**** BEGIN Level safety checking ****\n\n");
// get the world pointer // get the world pointer
CWorld *pwo = (CWorld *)_pShell->GetINDEX("pwoCurrentWorld"); CWorld *pwo = _pShell->GetCurrentWorld();
// if there is no current world // if there is no current world
if (pwo==NULL) { if (pwo==NULL) {
CPrintF("Error - no current world.\n"); CPrintF("Error - no current world.\n");

View File

@ -2098,7 +2098,7 @@ BOOL CWorldEditorApp::OnIdle(LONG lCount)
if (pvCurrent!=NULL) { if (pvCurrent!=NULL) {
CWorldEditorDoc *pdocCurrent = pvCurrent->GetDocument(); CWorldEditorDoc *pdocCurrent = pvCurrent->GetDocument();
if (pdocCurrent!=NULL) { if (pdocCurrent!=NULL) {
_pShell->SetINDEX("pwoCurrentWorld", (INDEX)&pdocCurrent->m_woWorld); _pShell->SetCurrentWorld(&pdocCurrent->m_woWorld);
} }
} }