Allow writing to 8 and 16-bit CON arrays

git-svn-id: https://svn.eduke32.com/eduke32@6338 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
terminx 2017-07-08 05:18:43 +00:00
parent cabb918c64
commit b3b40c9581
6 changed files with 93 additions and 74 deletions

View file

@ -124,20 +124,21 @@ enum GamevarFlags_t {
GAMEVAR_SPECIAL = 0x00040000, // flag for structure member shortcut vars
};
enum GamearrayFlags_t {
MAXGAMEARRAYS = (MAXGAMEVARS>>2), // must be strictly smaller than MAXGAMEVARS
MAXARRAYLABEL = MAXVARLABEL,
enum GamearrayFlags_t
{
MAXGAMEARRAYS = (MAXGAMEVARS >> 2), // must be strictly smaller than MAXGAMEVARS
MAXARRAYLABEL = MAXVARLABEL,
GAMEARRAY_READONLY = 0x00001000,
GAMEARRAY_WARN = 0x00002000,
GAMEARRAY_NORMAL = 0x00004000,
GAMEARRAY_OFCHAR = 0x00000001,
GAMEARRAY_OFSHORT = 0x00000002,
GAMEARRAY_OFINT = 0x00000004,
GAMEARRAY_TYPE_MASK = GAMEARRAY_OFCHAR|GAMEARRAY_OFSHORT|GAMEARRAY_OFINT,
GAMEARRAY_NORMAL = 0x00004000,
GAMEARRAY_UINT8 = 0x00000001,
GAMEARRAY_INT16 = 0x00000002,
GAMEARRAY_INT32 = 0x00000004,
GAMEARRAY_TYPE_MASK = GAMEARRAY_UINT8 | GAMEARRAY_INT16 | GAMEARRAY_INT32,
GAMEARRAY_RESET = 0x00000008,
GAMEARRAY_RESET = 0x00000008,
GAMEARRAY_VARSIZE = 0x00000020,
GAMEARRAY_STRIDE2 = 0x00000040,

View file

@ -4615,6 +4615,14 @@ finish_qsprintf:
continue;
}
switch (aGameArrays[tw].flags & GAMEARRAY_TYPE_MASK)
{
case 0: aGameArrays[tw].pValues[arrayIndex] = newValue; break;
case GAMEARRAY_INT32: ((int32_t *)aGameArrays[tw].pValues)[arrayIndex] = newValue; break;
case GAMEARRAY_INT16: ((int16_t *)aGameArrays[tw].pValues)[arrayIndex] = newValue; break;
case GAMEARRAY_UINT8: ((uint8_t *)aGameArrays[tw].pValues)[arrayIndex] = newValue; break;
}
aGameArrays[tw].pValues[arrayIndex]=newValue;
continue;
}
@ -4804,7 +4812,7 @@ finish_qsprintf:
}
Bmemcpy(aGameArrays[destArray].pValues+destArrayIndex, aGameArrays[srcArray].pValues+srcArrayIndex, numElements*GAR_ELTSZ);
break;
case GAMEARRAY_OFINT:
case GAMEARRAY_INT32:
// From int32-sized array. Note that the CON array element
// type is intptr_t, so it is different-sized on 64-bit
// archs, but same-sized on 32-bit ones.
@ -4823,7 +4831,7 @@ finish_qsprintf:
((int32_t *)aGameArrays[srcArray].pValues)[srcArrayIndex++];
}
break;
case GAMEARRAY_OFSHORT:
case GAMEARRAY_INT16:
// From int16_t array. Always different-sized.
if (EDUKE32_PREDICT_FALSE(aGameArrays[srcArray].flags & GAMEARRAY_STRIDE2))
{
@ -4840,7 +4848,7 @@ finish_qsprintf:
((int16_t *)aGameArrays[srcArray].pValues)[srcArrayIndex++];
}
break;
case GAMEARRAY_OFCHAR:
case GAMEARRAY_UINT8:
// From char array. Always different-sized.
if (EDUKE32_PREDICT_FALSE(aGameArrays[srcArray].flags & GAMEARRAY_STRIDE2))
{
@ -6083,11 +6091,11 @@ void G_SaveMapState(void)
int size;
switch (aGameArrays[i].flags & (GAMEARRAY_OFCHAR | GAMEARRAY_OFSHORT | GAMEARRAY_OFINT))
switch (aGameArrays[i].flags & (GAMEARRAY_UINT8 | GAMEARRAY_INT16 | GAMEARRAY_INT32))
{
case GAMEARRAY_OFCHAR: size = sizeof(uint8_t); break;
case GAMEARRAY_OFSHORT: size = sizeof(uint16_t); break;
case GAMEARRAY_OFINT: size = sizeof(uint32_t); break;
case GAMEARRAY_UINT8: size = sizeof(uint8_t); break;
case GAMEARRAY_INT16: size = sizeof(uint16_t); break;
case GAMEARRAY_INT32: size = sizeof(uint32_t); break;
default: size = sizeof(uintptr_t); break;
}
@ -6224,12 +6232,12 @@ void G_RestoreMapState(void)
int size;
switch (aGameArrays[i].flags & (GAMEARRAY_OFCHAR | GAMEARRAY_OFSHORT | GAMEARRAY_OFINT))
switch (aGameArrays[i].flags & (GAMEARRAY_UINT8 | GAMEARRAY_INT16 | GAMEARRAY_INT32))
{
case GAMEARRAY_OFCHAR: size = sizeof(uint8_t); break;
case GAMEARRAY_OFSHORT: size = sizeof(uint16_t); break;
case GAMEARRAY_OFINT: size = sizeof(uint32_t); break;
default: size = sizeof(uintptr_t); break;
case GAMEARRAY_UINT8: size = sizeof(uint8_t); break;
case GAMEARRAY_INT16: size = sizeof(uint16_t); break;
case GAMEARRAY_INT32: size = sizeof(uint32_t); break;
default: size = sizeof(uintptr_t); break;
}
Bmemcpy(&aGameArrays[i].pValues[0], &pSavedState->arrays[i][0], aGameArrays[i].size * size);

View file

@ -387,7 +387,7 @@ void Gv_ResetVars(void) /* this is called during a new game and nowhere else */
int32_t Gv_NewArray(const char *pszLabel, void *pArray, intptr_t arraySize, uint32_t nFlags)
{
int32_t i;
Bassert(arraySize);
if (EDUKE32_PREDICT_FALSE(g_gameArrayCount >= MAXGAMEARRAYS))
{
@ -404,7 +404,8 @@ int32_t Gv_NewArray(const char *pszLabel, void *pArray, intptr_t arraySize, uint
initprintf("%s:%d: error: array name `%s' exceeds limit of %d characters.\n",g_scriptFileName,g_lineNumber,pszLabel, MAXARRAYLABEL);
return 0;
}
i = hash_find(&h_arrays,pszLabel);
int32_t i = hash_find(&h_arrays,pszLabel);
if (EDUKE32_PREDICT_FALSE(i >=0 && !(aGameArrays[i].flags & GAMEARRAY_RESET)))
{
@ -431,21 +432,28 @@ int32_t Gv_NewArray(const char *pszLabel, void *pArray, intptr_t arraySize, uint
if (aGameArrays[i].szLabel != pszLabel)
Bstrcpy(aGameArrays[i].szLabel,pszLabel);
if (!(nFlags & GAMEARRAY_TYPE_MASK))
if (pArray == NULL)
{
Baligned_free(aGameArrays[i].pValues);
if (arraySize != 0)
if (aGameArrays[i].flags & GAMEARRAY_ALLOCATED)
Baligned_free(aGameArrays[i].pValues);
int typeSize;
switch (aGameArrays[i].flags & (GAMEARRAY_UINT8 | GAMEARRAY_INT16 | GAMEARRAY_INT32))
{
aGameArrays[i].pValues = (intptr_t *)Xaligned_alloc(ACTOR_VAR_ALIGNMENT, arraySize * GAR_ELTSZ);
Bmemset(aGameArrays[i].pValues, 0, arraySize * GAR_ELTSZ);
case GAMEARRAY_UINT8: typeSize = sizeof(uint8_t); break;
case GAMEARRAY_INT16: typeSize = sizeof(uint16_t); break;
case GAMEARRAY_INT32: typeSize = sizeof(uint32_t); break;
default: typeSize = sizeof(uintptr_t); break;
}
else
aGameArrays[i].pValues = NULL;
aGameArrays[i].pValues = (intptr_t *)Xaligned_alloc(ACTOR_VAR_ALIGNMENT, arraySize * typeSize);
Bmemset(aGameArrays[i].pValues, 0, arraySize * typeSize);
}
else
aGameArrays[i].pValues=(intptr_t *)pArray;
aGameArrays[i].pValues = (intptr_t *)pArray;
aGameArrays[i].size = arraySize;
aGameArrays[i].size = arraySize;
aGameArrays[i].flags = nFlags & ~GAMEARRAY_RESET;
g_gameArrayCount++;
@ -574,10 +582,10 @@ int __fastcall Gv_GetArrayValue(int const id, int index)
switch (aGameArrays[id].flags & GAMEARRAY_TYPE_MASK)
{
case 0: returnValue = (aGameArrays[id].pValues)[index]; break;
case GAMEARRAY_OFINT: returnValue = ((int32_t *)aGameArrays[id].pValues)[index]; break;
case GAMEARRAY_OFSHORT: returnValue = ((int16_t *)aGameArrays[id].pValues)[index]; break;
case GAMEARRAY_OFCHAR: returnValue = ((uint8_t *)aGameArrays[id].pValues)[index]; break;
case 0: returnValue = (aGameArrays[id].pValues)[index]; break;
case GAMEARRAY_INT32: returnValue = ((int32_t *)aGameArrays[id].pValues)[index]; break;
case GAMEARRAY_INT16: returnValue = ((int16_t *)aGameArrays[id].pValues)[index]; break;
case GAMEARRAY_UINT8: returnValue = ((uint8_t *)aGameArrays[id].pValues)[index]; break;
}
return returnValue;
@ -1526,8 +1534,9 @@ static void Gv_AddSystemVars(void)
# endif
// SYSTEM_GAMEARRAY
Gv_NewArray("tilesizx", (void *)&tilesiz[0].x, MAXTILES, GAMEARRAY_STRIDE2|GAMEARRAY_READONLY|GAMEARRAY_OFSHORT);
Gv_NewArray("tilesizy", (void *)&tilesiz[0].y, MAXTILES, GAMEARRAY_STRIDE2|GAMEARRAY_READONLY|GAMEARRAY_OFSHORT);
Gv_NewArray("tilesizx", (void *)&tilesiz[0].x, MAXTILES, GAMEARRAY_STRIDE2|GAMEARRAY_READONLY|GAMEARRAY_INT16);
Gv_NewArray("tilesizy", (void *)&tilesiz[0].y, MAXTILES, GAMEARRAY_STRIDE2|GAMEARRAY_READONLY|GAMEARRAY_INT16);
Gv_NewArray("walock", (void *) &walock[0], MAXTILES, GAMEARRAY_UINT8);
#endif
}

View file

@ -62,14 +62,15 @@ enum GamearrayFlags_t
GAMEARRAY_READONLY = 0x00001000,
GAMEARRAY_WARN = 0x00002000,
GAMEARRAY_NORMAL = 0x00004000,
GAMEARRAY_OFCHAR = 0x00000001,
GAMEARRAY_OFSHORT = 0x00000002,
GAMEARRAY_OFINT = 0x00000004,
GAMEARRAY_UINT8 = 0x00000001,
GAMEARRAY_INT16 = 0x00000002,
GAMEARRAY_INT32 = 0x00000004,
GAMEARRAY_RESET = 0x00000008,
GAMEARRAY_TYPE_MASK = GAMEARRAY_OFCHAR | GAMEARRAY_OFSHORT | GAMEARRAY_OFINT,
GAMEARRAY_TYPE_MASK = GAMEARRAY_UINT8 | GAMEARRAY_INT16 | GAMEARRAY_INT32,
GAMEARRAY_RESTORE = 0x00000010,
GAMEARRAY_VARSIZE = 0x00000020,
GAMEARRAY_STRIDE2 = 0x00000100,
GAMEARRAY_ALLOCATED = 0100000200, // memory allocated for user array
};
#pragma pack(push,1)

View file

@ -576,7 +576,7 @@ skip_check:
switch (sar->dwFlags & GAMEARRAY_TYPE_MASK)
{
case 0:
case GAMEARRAY_OFINT:
case GAMEARRAY_INT32:
if (sar->dwFlags & GAMEARRAY_STRIDE2)
{
for (; numelts>0; numelts--, sidx += 2)
@ -588,11 +588,11 @@ skip_check:
numelts * sizeof(int32_t));
}
break;
case GAMEARRAY_OFSHORT:
case GAMEARRAY_INT16:
for (; numelts>0; numelts--)
((int32_t *)dar->vals)[didx++] = ((int16_t *)sar->vals)[sidx++];
break;
case GAMEARRAY_OFCHAR:
case GAMEARRAY_UINT8:
for (; numelts>0; numelts--)
((int32_t *)dar->vals)[didx++] = ((uint8_t *)sar->vals)[sidx++];
break;

View file

@ -308,11 +308,11 @@ int32_t __fastcall Gv_GetVarX(int32_t id)
switch (gar->dwFlags & GAMEARRAY_TYPE_MASK)
{
case 0:
case GAMEARRAY_OFINT:
case GAMEARRAY_INT32:
return (((int32_t *)gar->vals)[index] ^ -negateResult) + negateResult;
case GAMEARRAY_OFSHORT:
case GAMEARRAY_INT16:
return (((int16_t *)gar->vals)[index] ^ -negateResult) + negateResult;
case GAMEARRAY_OFCHAR:
case GAMEARRAY_UINT8:
return (((uint8_t *)gar->vals)[index] ^ -negateResult) + negateResult;
default:
M32_ERROR("Gv_GetVarX() (array): WTF??");
@ -410,13 +410,13 @@ void __fastcall Gv_SetVarX(int32_t id, int32_t lValue)
switch (gar->dwFlags & GAMEARRAY_TYPE_MASK)
{
case 0:
case GAMEARRAY_OFINT:
case GAMEARRAY_INT32:
((int32_t *)gar->vals)[index] = lValue;
return;
case GAMEARRAY_OFSHORT:
case GAMEARRAY_INT16:
((int16_t *)gar->vals)[index] = (int16_t)lValue;
return;
case GAMEARRAY_OFCHAR:
case GAMEARRAY_UINT8:
((uint8_t *)gar->vals)[index] = (uint8_t)lValue;
return;
default:
@ -652,38 +652,38 @@ static void Gv_AddSystemVars(void)
g_systemVarCount = g_gameVarCount;
// must be first!
Gv_NewArray(".LOCALS_BASE", NULL, 0, GAMEARRAY_OFINT);
Gv_NewArray(".LOCALS_BASE", NULL, 0, GAMEARRAY_INT32);
Gv_NewArray("highlight", (void *)highlight, hlcnt_id,
GAMEARRAY_READONLY|GAMEARRAY_OFSHORT|GAMEARRAY_VARSIZE);
GAMEARRAY_READONLY|GAMEARRAY_INT16|GAMEARRAY_VARSIZE);
Gv_NewArray("highlightsector", (void *)highlightsector, hlscnt_id,
GAMEARRAY_READONLY|GAMEARRAY_OFSHORT|GAMEARRAY_VARSIZE);
GAMEARRAY_READONLY|GAMEARRAY_INT16|GAMEARRAY_VARSIZE);
Gv_NewArray("hsect", (void *)headspritesect, MAXSECTORS+1, GAMEARRAY_READONLY|GAMEARRAY_OFSHORT);
Gv_NewArray("psect", (void *)prevspritesect, MAXSPRITES, GAMEARRAY_READONLY|GAMEARRAY_OFSHORT);
Gv_NewArray("nsect", (void *)nextspritesect, MAXSPRITES, GAMEARRAY_READONLY|GAMEARRAY_OFSHORT);
Gv_NewArray("hstat", (void *)headspritestat, MAXSTATUS+1, GAMEARRAY_READONLY|GAMEARRAY_OFSHORT);
Gv_NewArray("pstat", (void *)prevspritestat, MAXSPRITES, GAMEARRAY_READONLY|GAMEARRAY_OFSHORT);
Gv_NewArray("nstat", (void *)nextspritestat, MAXSPRITES, GAMEARRAY_READONLY|GAMEARRAY_OFSHORT);
Gv_NewArray("hsect", (void *)headspritesect, MAXSECTORS+1, GAMEARRAY_READONLY|GAMEARRAY_INT16);
Gv_NewArray("psect", (void *)prevspritesect, MAXSPRITES, GAMEARRAY_READONLY|GAMEARRAY_INT16);
Gv_NewArray("nsect", (void *)nextspritesect, MAXSPRITES, GAMEARRAY_READONLY|GAMEARRAY_INT16);
Gv_NewArray("hstat", (void *)headspritestat, MAXSTATUS+1, GAMEARRAY_READONLY|GAMEARRAY_INT16);
Gv_NewArray("pstat", (void *)prevspritestat, MAXSPRITES, GAMEARRAY_READONLY|GAMEARRAY_INT16);
Gv_NewArray("nstat", (void *)nextspritestat, MAXSPRITES, GAMEARRAY_READONLY|GAMEARRAY_INT16);
#ifdef YAX_ENABLE
Gv_NewArray("headsectbunchc", (void *)headsectbunch[0], YAX_MAXBUNCHES, GAMEARRAY_READONLY|GAMEARRAY_OFSHORT);
Gv_NewArray("nextsectbunchc", (void *)nextsectbunch[0], MAXSECTORS, GAMEARRAY_READONLY|GAMEARRAY_OFSHORT);
Gv_NewArray("headsectbunchf", (void *)headsectbunch[1], YAX_MAXBUNCHES, GAMEARRAY_READONLY|GAMEARRAY_OFSHORT);
Gv_NewArray("nextsectbunchf", (void *)nextsectbunch[1], MAXSECTORS, GAMEARRAY_READONLY|GAMEARRAY_OFSHORT);
Gv_NewArray("headsectbunchc", (void *)headsectbunch[0], YAX_MAXBUNCHES, GAMEARRAY_READONLY|GAMEARRAY_INT16);
Gv_NewArray("nextsectbunchc", (void *)nextsectbunch[0], MAXSECTORS, GAMEARRAY_READONLY|GAMEARRAY_INT16);
Gv_NewArray("headsectbunchf", (void *)headsectbunch[1], YAX_MAXBUNCHES, GAMEARRAY_READONLY|GAMEARRAY_INT16);
Gv_NewArray("nextsectbunchf", (void *)nextsectbunch[1], MAXSECTORS, GAMEARRAY_READONLY|GAMEARRAY_INT16);
#endif
Gv_NewArray("editorcolors", (void *)editorcolors, 256, GAMEARRAY_READONLY|GAMEARRAY_OFCHAR);
Gv_NewArray("tilesizx", (void *)&tilesiz[0].x, MAXTILES, GAMEARRAY_STRIDE2|GAMEARRAY_READONLY|GAMEARRAY_OFSHORT);
Gv_NewArray("tilesizy", (void *)&tilesiz[0].y, MAXTILES, GAMEARRAY_STRIDE2|GAMEARRAY_READONLY|GAMEARRAY_OFSHORT);
Gv_NewArray("editorcolors", (void *)editorcolors, 256, GAMEARRAY_READONLY|GAMEARRAY_UINT8);
Gv_NewArray("tilesizx", (void *)&tilesiz[0].x, MAXTILES, GAMEARRAY_STRIDE2|GAMEARRAY_READONLY|GAMEARRAY_INT16);
Gv_NewArray("tilesizy", (void *)&tilesiz[0].y, MAXTILES, GAMEARRAY_STRIDE2|GAMEARRAY_READONLY|GAMEARRAY_INT16);
// Gv_NewArray("picsiz", (void *)picsiz, MAXTILES, GAMEARRAY_READONLY|GAMEARRAY_OFCHAR);
Gv_NewArray("picanm", (void *)picanm, MAXTILES, GAMEARRAY_READONLY|GAMEARRAY_OFINT);
Gv_NewArray("picanm", (void *)picanm, MAXTILES, GAMEARRAY_READONLY|GAMEARRAY_INT32);
Gv_NewArray("show2dsector", (void *)show2dsector, (MAXSECTORS+7)>>3, GAMEARRAY_READONLY|GAMEARRAY_OFCHAR);
Gv_NewArray("show2dwall", (void *)show2dwall, (MAXWALLS+7)>>3, GAMEARRAY_READONLY|GAMEARRAY_OFCHAR);
Gv_NewArray("show2dsprite", (void *)show2dsprite, (MAXSPRITES+7)>>3, GAMEARRAY_READONLY|GAMEARRAY_OFCHAR);
Gv_NewArray("show2dsector", (void *)show2dsector, (MAXSECTORS+7)>>3, GAMEARRAY_READONLY|GAMEARRAY_UINT8);
Gv_NewArray("show2dwall", (void *)show2dwall, (MAXWALLS+7)>>3, GAMEARRAY_READONLY|GAMEARRAY_UINT8);
Gv_NewArray("show2dsprite", (void *)show2dsprite, (MAXSPRITES+7)>>3, GAMEARRAY_READONLY|GAMEARRAY_UINT8);
Gv_NewArray("keystatus", (void *)keystatus, 256, GAMEARRAY_WARN|GAMEARRAY_OFCHAR);
Gv_NewArray("alphakeys", (void *)alphakeys, sizeof(alphakeys), GAMEARRAY_READONLY|GAMEARRAY_OFCHAR);
Gv_NewArray("numberkeys", (void *)numberkeys, sizeof(numberkeys), GAMEARRAY_READONLY|GAMEARRAY_OFCHAR);
Gv_NewArray("keystatus", (void *)keystatus, 256, GAMEARRAY_WARN|GAMEARRAY_UINT8);
Gv_NewArray("alphakeys", (void *)alphakeys, sizeof(alphakeys), GAMEARRAY_READONLY|GAMEARRAY_UINT8);
Gv_NewArray("numberkeys", (void *)numberkeys, sizeof(numberkeys), GAMEARRAY_READONLY|GAMEARRAY_UINT8);
g_systemArrayCount = g_gameArrayCount;
}