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

View File

@ -33,6 +33,8 @@ public:
CTCriticalSection sh_csShell; // critical section for access to shell data
CDynamicArray<CShellSymbol> sh_assSymbols; // all defined symbols
CWorld* pwoCurrentWorld;
// Get a shell symbol by its name.
CShellSymbol *GetSymbol(const CTString &strName, BOOL bDeclaredOnly);
// Report error in shell script processing.
@ -59,13 +61,23 @@ public:
// get/set symbols
FLOAT GetFLOAT(const CTString &strName);
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);
CTString GetString(const CTString &strName);
void SetString(const CTString &strName, const CTString &strValue);
CTString GetValue(const CTString &strName);
void SetValue(const CTString &strName, const CTString &strValue);
void SetCurrentWorld(CWorld* pwo)
{
pwoCurrentWorld = pwo;
}
CWorld* GetCurrentWorld(void)
{
return pwoCurrentWorld;
}
};
// 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 CTString con_strCapture;
static CWorld *_pwoCurrentWorld = NULL;
static FLOAT _bStartDemoRecordingNextTime = FALSE;
static FLOAT _bStopDemoRecordingNextTime = FALSE;
static INDEX dem_iRecordedNumber = 0;
@ -254,8 +252,7 @@ extern void CacheShadows(void)
{
// mute all sounds
_pSound->Mute();
STUBBED("64-bit issue"); // GetINDEX() returns int32!
CWorld *pwo = (CWorld*)_pShell->GetINDEX("pwoCurrentWorld");
CWorld *pwo = _pShell->GetCurrentWorld();
if( pwo!=NULL) {
pwo->wo_baBrushes.CacheAllShadowmaps();
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;
SLONG slEntBytes=0, slLyrBytes=0, slPlyBytes=0, slPlnBytes=0, slEdgBytes=0, slVtxBytes=0, slSecBytes=0;
SLONG slCgrBytes=0;
STUBBED("64-bit issue"); // GetINDEX() returns int32!
CWorld *pwo = (CWorld*)_pShell->GetINDEX("pwoCurrentWorld");
CWorld *pwo = _pShell->GetCurrentWorld();
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 INDEX ga_bMSLegacy;", (void *)&ga_bMSLegacy);
_pShell->DeclareSymbol("INDEX pwoCurrentWorld;", (void *)&_pwoCurrentWorld);
}
/*
@ -1041,8 +1036,7 @@ void CNetworkLibrary::StartPeerToPeer_t(const CTString &strSessionName,
throw;
}
// remember the world pointer
STUBBED("64-bit issue");
_pShell->SetINDEX("pwoCurrentWorld", (INDEX)(size_t)&ga_World);
_pShell->SetCurrentWorld(&ga_World);
SetProgressDescription(TRANS("starting server"));
CallProgressHook_t(0.0f);
@ -1279,8 +1273,7 @@ void CNetworkLibrary::JoinSession_t(const CNetworkSession &nsSesssion, INDEX ctL
}
// remember the world pointer
STUBBED("64-bit issue");
_pShell->SetINDEX("pwoCurrentWorld", (INDEX)(size_t)&ga_World);
_pShell->SetCurrentWorld(&ga_World);
// eventually cache all shadowmaps in world (memory eater!)
if( shd_bCacheAll) ga_World.wo_baBrushes.CacheAllShadowmaps();
@ -1352,8 +1345,7 @@ void CNetworkLibrary::StartDemoPlay_t(const CTFileName &fnDemo) // throw char *
_bNeedPretouch = TRUE;
// remember the world pointer
STUBBED("64-bit issue");
_pShell->SetINDEX("pwoCurrentWorld", (INDEX)(size_t)&ga_World);
_pShell->SetCurrentWorld(&ga_World);
// demo synchronization starts at the beginning initially
ga_fDemoTimer = 0.0f;
@ -1562,7 +1554,7 @@ void CNetworkLibrary::StopGame(void)
ga_aplsPlayers.Clear();
ga_aplsPlayers.New(NET_MAXLOCALPLAYERS);
// remember the world pointer
_pShell->SetINDEX("pwoCurrentWorld", (INDEX)NULL);
_pShell->SetCurrentWorld(NULL);
// rewind the timer
_pTimer->SetCurrentTick(0.0f);
@ -1686,8 +1678,7 @@ void CNetworkLibrary::ChangeLevel_internal(void)
// remember the world filename
ga_fnmWorld = ga_fnmNextLevel;
// remember the world pointer
STUBBED("64-bit issue");
_pShell->SetINDEX("pwoCurrentWorld", (INDEX)(size_t)&ga_World);
_pShell->SetCurrentWorld(&ga_World);
// if there is remembered level
} else {
// restore it
@ -2392,8 +2383,7 @@ extern void NET_MakeDefaultState_t(
_pNetwork->ga_fnmWorld = fnmWorld;
_pNetwork->ga_fnmNextLevel = CTString("");
// remember the world pointer
STUBBED("64-bit issue");
_pShell->SetINDEX("pwoCurrentWorld", (INDEX)(size_t)&_pNetwork->ga_World);
_pShell->SetCurrentWorld(&_pNetwork->ga_World);
// reset random number generator
_pNetwork->ga_sesSessionState.ResetRND();

View File

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

View File

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

View File

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