From ef8bd42b49b6a31c7ada63c280984f99d0691f35 Mon Sep 17 00:00:00 2001 From: terminx Date: Thu, 20 Jul 2017 08:57:50 +0000 Subject: [PATCH] Another attempt at fixing the problems caused by my recent changes to gamearrays git-svn-id: https://svn.eduke32.com/eduke32@6372 1a8010ca-5511-0410-912e-c29ae57300e0 --- source/duke3d/src/gamevars.cpp | 56 +++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 21 deletions(-) diff --git a/source/duke3d/src/gamevars.cpp b/source/duke3d/src/gamevars.cpp index f2bffca83..f573e9e36 100644 --- a/source/duke3d/src/gamevars.cpp +++ b/source/duke3d/src/gamevars.cpp @@ -156,14 +156,10 @@ int Gv_ReadSave(int32_t kFile) // Bsprintf(g_szBuf,"CP:%s %d",__FILE__,__LINE__); // AddLog(g_szBuf); - Gv_RefreshPointers(); if (kdfread(&g_gameArrayCount,sizeof(g_gameArrayCount),1,kFile) != 1) goto corrupt; for (bssize_t i=0; i> 3; + int const allocSize = Gv_GetArrayAllocSize(i); aGameArrays[i].flags |= GAMEARRAY_ALLOCATED; aGameArrays[i].pValues = (intptr_t *) Xaligned_alloc(ACTOR_VAR_ALIGNMENT, allocSize); Bmemset(aGameArrays[i].pValues, 0, allocSize); } - aGameArrays[i].size = asize; - aGameArrays[i].flags = dwFlags & ~GAMEARRAY_RESET; - g_gameArrayCount++; hash_add(&h_arrays, aGameArrays[i].szLabel, i, 1); } @@ -574,6 +571,19 @@ static int Gv_GetVarIndex(const char *szGameLabel) return gameVar; } +static int Gv_GetArrayIndex(const char *szArrayLabel) +{ + int const arrayIdx = hash_find(&h_arrays, szArrayLabel); + + if (EDUKE32_PREDICT_FALSE(arrayIdx == -1)) + { + OSD_Printf(OSD_ERROR "Gv_GetArrayIndex(): INTERNAL ERROR: couldn't find array %s!\n", szArrayLabel); + return 0; + } + + return arrayIdx; +} + int __fastcall Gv_GetArrayAllocSize(int const arrayIdx) { if (aGameArrays[arrayIdx].flags & GAMEARRAY_BITMAP) @@ -861,7 +871,7 @@ int __fastcall Gv_GetSpecialVarX(int gameVar) if (EDUKE32_PREDICT_FALSE((unsigned) arrayIndex >= (unsigned) arraySiz)) { - CON_ERRPRINTF("%s %s[%d]\n", gvxerrs[GVX_BADINDEX], aGameArrays[gameVar].szLabel, arrayIndex); + CON_ERRPRINTF("%s %s[%d] %d\n", gvxerrs[GVX_BADINDEX], aGameArrays[gameVar].szLabel, arrayIndex, gameVar); return -1; } @@ -1706,5 +1716,9 @@ void Gv_RefreshPointers(void) # ifdef USE_OPENGL aGameVars[Gv_GetVarIndex("rendmode")].global = (intptr_t)&rendmode; # endif + + aGameArrays[Gv_GetArrayIndex("gotpic")].pValues = (intptr_t *)&gotpic[0]; + aGameArrays[Gv_GetArrayIndex("tilesizx")].pValues = (intptr_t *)&tilesiz[0].x; + aGameArrays[Gv_GetArrayIndex("tilesizy")].pValues = (intptr_t *)&tilesiz[0].y; } #endif