C-CON: Implement tilesizx/y gamearrays in a fashion similar to M32Script's solution: a STRIDE2 flag.

git-svn-id: https://svn.eduke32.com/eduke32@5090 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
hendricks266 2015-03-25 21:30:25 +00:00
parent a14109da20
commit bd0f05a706
3 changed files with 51 additions and 33 deletions

View file

@ -3911,7 +3911,7 @@ finish_qsprintf:
{ {
OSD_Printf(OSDTEXT_GREEN "%s: L=%d %s[%d] =%d\n", keyw[g_tw], g_errorLineNum, OSD_Printf(OSDTEXT_GREEN "%s: L=%d %s[%d] =%d\n", keyw[g_tw], g_errorLineNum,
aGameArrays[lVarID].szLabel, index, aGameArrays[lVarID].szLabel, index,
(int32_t)(m*aGameArrays[lVarID].plValues[index])); (int32_t)(m*Gv_GetGameArrayValue(lVarID, index)));
continue; continue;
} }
else else
@ -4631,16 +4631,10 @@ finish_qsprintf:
} }
const int32_t n = aGameArrays[j].size; const int32_t n = aGameArrays[j].size;
#ifdef BITNESS64
int32_t *const array = (int32_t *)Xmalloc(sizeof(int32_t) * n); int32_t *const array = (int32_t *)Xmalloc(sizeof(int32_t) * n);
for (int32_t k = 0; k < n; k++) array[k] = aGameArrays[j].plValues[k]; for (int32_t k = 0; k < n; k++) array[k] = Gv_GetGameArrayValue(j, k);
#else
int32_t *const array = (int32_t *)aGameArrays[j].plValues;
#endif
fwrite(array, 1, sizeof(int32_t) * n, fil); fwrite(array, 1, sizeof(int32_t) * n, fil);
#ifdef BITNESS64
Bfree(array); Bfree(array);
#endif
fclose(fil); fclose(fil);
continue; continue;
@ -4715,22 +4709,46 @@ finish_qsprintf:
{ {
case 0: case 0:
// CON array to CON array. // CON array to CON array.
if (EDUKE32_PREDICT_FALSE(aGameArrays[si].dwFlags & GAMEARRAY_STRIDE2))
{
for (; numelts>0; --numelts)
(aGameArrays[di].plValues)[didx++] = ((int32_t *)aGameArrays[si].plValues)[sidx+=2];
break;
}
Bmemcpy(aGameArrays[di].plValues+didx, aGameArrays[si].plValues+sidx, numelts*GAR_ELTSZ); Bmemcpy(aGameArrays[di].plValues+didx, aGameArrays[si].plValues+sidx, numelts*GAR_ELTSZ);
break; break;
case GAMEARRAY_OFINT: case GAMEARRAY_OFINT:
// From int32-sized array. Note that the CON array element // From int32-sized array. Note that the CON array element
// type is intptr_t, so it is different-sized on 64-bit // type is intptr_t, so it is different-sized on 64-bit
// archs, but same-sized on 32-bit ones. // archs, but same-sized on 32-bit ones.
if (EDUKE32_PREDICT_FALSE(aGameArrays[si].dwFlags & GAMEARRAY_STRIDE2))
{
for (; numelts>0; --numelts)
(aGameArrays[di].plValues)[didx++] = ((int32_t *)aGameArrays[si].plValues)[sidx+=2];
break;
}
for (; numelts>0; --numelts) for (; numelts>0; --numelts)
(aGameArrays[di].plValues)[didx++] = ((int32_t *)aGameArrays[si].plValues)[sidx++]; (aGameArrays[di].plValues)[didx++] = ((int32_t *)aGameArrays[si].plValues)[sidx++];
break; break;
case GAMEARRAY_OFSHORT: case GAMEARRAY_OFSHORT:
// From int16_t array. Always different-sized. // From int16_t array. Always different-sized.
if (EDUKE32_PREDICT_FALSE(aGameArrays[si].dwFlags & GAMEARRAY_STRIDE2))
{
for (; numelts>0; --numelts)
(aGameArrays[di].plValues)[didx++] = ((int16_t *)aGameArrays[si].plValues)[sidx+=2];
break;
}
for (; numelts>0; --numelts) for (; numelts>0; --numelts)
(aGameArrays[di].plValues)[didx++] = ((int16_t *)aGameArrays[si].plValues)[sidx++]; (aGameArrays[di].plValues)[didx++] = ((int16_t *)aGameArrays[si].plValues)[sidx++];
break; break;
case GAMEARRAY_OFCHAR: case GAMEARRAY_OFCHAR:
// From char array. Always different-sized. // From char array. Always different-sized.
if (EDUKE32_PREDICT_FALSE(aGameArrays[si].dwFlags & GAMEARRAY_STRIDE2))
{
for (; numelts>0; --numelts)
(aGameArrays[di].plValues)[didx++] = ((uint8_t *)aGameArrays[si].plValues)[sidx+=2];
break;
}
for (; numelts>0; --numelts) for (; numelts>0; --numelts)
(aGameArrays[di].plValues)[didx++] = ((uint8_t *)aGameArrays[si].plValues)[sidx++]; (aGameArrays[di].plValues)[didx++] = ((uint8_t *)aGameArrays[si].plValues)[sidx++];
break; break;

View file

@ -594,6 +594,24 @@ static int32_t Gv_GetVarIndex(const char *szGameLabel)
return i; return i;
} }
int32_t __fastcall Gv_GetGameArrayValue(register int32_t const id, register int32_t index)
{
int rv = -1;
if (aGameArrays[id].dwFlags & GAMEARRAY_STRIDE2)
index <<= 1;
switch (aGameArrays[id].dwFlags & GAMEARRAY_TYPE_MASK)
{
case 0: rv = (aGameArrays[id].plValues)[index]; break;
case GAMEARRAY_OFINT: rv = ((int32_t *) aGameArrays[id].plValues)[index]; break;
case GAMEARRAY_OFSHORT: rv = ((int16_t *) aGameArrays[id].plValues)[index]; break;
case GAMEARRAY_OFCHAR: rv = ((uint8_t *) aGameArrays[id].plValues)[index]; break;
}
return rv;
}
int32_t __fastcall Gv_GetVar(int32_t id, int32_t iActor, int32_t iPlayer) int32_t __fastcall Gv_GetVar(int32_t id, int32_t iActor, int32_t iPlayer)
{ {
if (id == g_iThisActorID) if (id == g_iThisActorID)
@ -646,7 +664,7 @@ nastyhacks:
goto badindex; goto badindex;
} }
rv = aGameArrays[id].plValues[index]; rv = Gv_GetGameArrayValue(id, index);
} }
else if (id&(MAXGAMEVARS<<3)) // struct shortcut vars else if (id&(MAXGAMEVARS<<3)) // struct shortcut vars
{ {
@ -892,13 +910,7 @@ int32_t __fastcall Gv_GetSpecialVarX(int32_t id)
return -1; return -1;
} }
switch (aGameArrays[id].dwFlags & GAMEARRAY_TYPE_MASK) rv = Gv_GetGameArrayValue(id, index);
{
case 0: rv = (aGameArrays[id].plValues)[index]; break;
case GAMEARRAY_OFINT: rv = ((int32_t *) aGameArrays[id].plValues)[index]; break;
case GAMEARRAY_OFSHORT: rv = ((int16_t *) aGameArrays[id].plValues)[index]; break;
case GAMEARRAY_OFCHAR: rv = ((uint8_t *) aGameArrays[id].plValues)[index]; break;
}
} }
else if (id & (MAXGAMEVARS << 3)) // struct shortcut vars else if (id & (MAXGAMEVARS << 3)) // struct shortcut vars
{ {
@ -1276,23 +1288,6 @@ void Gv_ResetSystemDefaults(void)
if (g_tile[i].defproj) if (g_tile[i].defproj)
*g_tile[i].proj = *g_tile[i].defproj; *g_tile[i].proj = *g_tile[i].defproj;
#ifndef LUNATIC
int i;
// hackhackhackhackhack
if (i = hash_find(&h_arrays, "tilesizx"), i >= 0)
{
for (int j = 0; j < MAXTILES; j++)
aGameArrays[i].plValues[j] = tilesiz[j].x;
}
if (i = hash_find(&h_arrays, "tilesizy"), i >= 0)
{
for (int j = 0; j < MAXTILES; j++)
aGameArrays[i].plValues[j] = tilesiz[j].y;
}
#endif
//AddLog("EOF:ResetWeaponDefaults"); //AddLog("EOF:ResetWeaponDefaults");
} }
@ -1682,6 +1677,8 @@ static void Gv_AddSystemVars(void)
# endif # endif
// SYSTEM_GAMEARRAY // SYSTEM_GAMEARRAY
Gv_NewArray("tilesizx", (void *)&tilesiz[0].x, MAXTILES, GAMEARRAY_STRIDE2|GAMEARRAY_READONLY|GAMEARRAY_OFINT);
Gv_NewArray("tilesizy", (void *)&tilesiz[0].y, MAXTILES, GAMEARRAY_STRIDE2|GAMEARRAY_READONLY|GAMEARRAY_OFINT);
Gv_NewArray("tilesizx", NULL, MAXTILES, GAMEARRAY_READONLY); Gv_NewArray("tilesizx", NULL, MAXTILES, GAMEARRAY_READONLY);
Gv_NewArray("tilesizy", NULL, MAXTILES, GAMEARRAY_READONLY); Gv_NewArray("tilesizy", NULL, MAXTILES, GAMEARRAY_READONLY);
#endif #endif

View file

@ -70,6 +70,8 @@ enum GamearrayFlags_t {
GAMEARRAY_VARSIZE = 0x00000020, GAMEARRAY_VARSIZE = 0x00000020,
GAMEARRAY_STRIDE2 = 0x00000100,
GAMEARRAY_RESET = 0x00000008, GAMEARRAY_RESET = 0x00000008,
/// GAMEARRAY_NORESET = 0x00000001, /// GAMEARRAY_NORESET = 0x00000001,
}; };
@ -100,6 +102,7 @@ extern gamearray_t aGameArrays[MAXGAMEARRAYS];
extern int32_t g_gameVarCount; extern int32_t g_gameVarCount;
extern int32_t g_gameArrayCount; extern int32_t g_gameArrayCount;
int32_t __fastcall Gv_GetGameArrayValue(register int32_t const id, register int32_t index);
int32_t __fastcall Gv_GetVar(int32_t id, int32_t iActor, int32_t iPlayer); int32_t __fastcall Gv_GetVar(int32_t id, int32_t iActor, int32_t iPlayer);
void __fastcall Gv_SetVar(int32_t const id, int32_t const lValue, int32_t const iActor, int32_t const iPlayer); void __fastcall Gv_SetVar(int32_t const id, int32_t const lValue, int32_t const iActor, int32_t const iPlayer);
int32_t __fastcall Gv_GetVarX(int32_t id); int32_t __fastcall Gv_GetVarX(int32_t id);