Fix Raw Q16 Pointer reading/writing.

parent 86151aad
......@@ -867,6 +867,9 @@ enum GamevarFlags_t {
GAMEVAR_NORESET = 0x00020000, // var values are not reset when restoring map state
GAMEVAR_SPECIAL = 0x00040000, // flag for structure member shortcut vars
GAMEVAR_Q16PTR = 0x00100000,
GAMEVAR_RAWQ16PTR = GAMEVAR_Q16PTR | GAMEVAR_SPECIAL,
GAMEVAR_PTR_MASK = GAMEVAR_INTPTR | GAMEVAR_SHORTPTR | GAMEVAR_Q16PTR | GAMEVAR_RAWQ16PTR,
};
enum GamearrayFlags_t {
......
......@@ -331,7 +331,7 @@ void Gv_DumpValues(void)
OSD_Printf(" // ");
if (aGameVars[i].dwFlags & (GAMEVAR_SYSTEM))
OSD_Printf(" (system)");
if (aGameVars[i].dwFlags & (GAMEVAR_INTPTR|GAMEVAR_SHORTPTR|GAMEVAR_CHARPTR))
if (aGameVars[i].dwFlags & (GAMEVAR_PTR_MASK))
OSD_Printf(" (pointer)");
if (aGameVars[i].dwFlags & (GAMEVAR_READONLY))
OSD_Printf(" (read only)");
......@@ -556,8 +556,7 @@ int __fastcall Gv_GetVar(int id, int iActor, int iPlayer)
id &= ~(MAXGAMEVARS<<1);
}
switch (aGameVars[id].dwFlags & (GAMEVAR_USER_MASK|GAMEVAR_INTPTR|
GAMEVAR_SHORTPTR|GAMEVAR_CHARPTR))
switch (aGameVars[id].dwFlags & (GAMEVAR_USER_MASK|GAMEVAR_PTR_MASK))
{
default:
if (neg) return (-aGameVars[id].val.lValue);
......@@ -578,6 +577,7 @@ int __fastcall Gv_GetVar(int id, int iActor, int iPlayer)
}
if (neg) return (-aGameVars[id].val.plValues[iActor]);
return (aGameVars[id].val.plValues[iActor]);
case GAMEVAR_RAWQ16PTR:
case GAMEVAR_INTPTR:
if (neg) return (-(*((int*)aGameVars[id].val.lValue)));
return ((*((int*)aGameVars[id].val.lValue)));
......@@ -588,8 +588,8 @@ int __fastcall Gv_GetVar(int id, int iActor, int iPlayer)
if (neg) return (-(*((char*)aGameVars[id].val.lValue)));
return ((*((char*)aGameVars[id].val.lValue)));
case GAMEVAR_Q16PTR:
if (neg) return (-(aGameVars[id].dwFlags & GAMEVAR_SPECIAL ? *(int32_t *)aGameVars[id].val.lValue : fix16_to_int(*(fix16_t *)aGameVars[id].val.lValue)));
return aGameVars[id].dwFlags & GAMEVAR_SPECIAL ? *(int32_t *)aGameVars[id].val.lValue : fix16_to_int(*(fix16_t *)aGameVars[id].val.lValue);
if (neg) return (-(fix16_to_int(*(fix16_t *)aGameVars[id].val.lValue)));
return fix16_to_int(*(fix16_t *)aGameVars[id].val.lValue);
break;
}
......@@ -606,8 +606,7 @@ void __fastcall Gv_SetVar(int id, int lValue, int iActor, int iPlayer)
//Bsprintf(g_szBuf,"SGVI: %d ('%s') to %d for %d %d",id,aGameVars[id].szLabel,lValue,iActor,iPlayer);
//AddLog(g_szBuf);
switch (aGameVars[id].dwFlags & (GAMEVAR_USER_MASK|GAMEVAR_INTPTR|
GAMEVAR_SHORTPTR|GAMEVAR_CHARPTR))
switch (aGameVars[id].dwFlags & (GAMEVAR_USER_MASK|GAMEVAR_PTR_MASK))
{
default:
aGameVars[id].val.lValue=lValue;
......@@ -630,6 +629,7 @@ void __fastcall Gv_SetVar(int id, int lValue, int iActor, int iPlayer)
// for the current actor
aGameVars[id].val.plValues[iActor]=lValue;
return;
case GAMEVAR_RAWQ16PTR:
case GAMEVAR_INTPTR:
*((int*)aGameVars[id].val.lValue)=(int)lValue;
return;
......@@ -640,7 +640,7 @@ void __fastcall Gv_SetVar(int id, int lValue, int iActor, int iPlayer)
*((char*)aGameVars[id].val.lValue)=(char)lValue;
return;
case GAMEVAR_Q16PTR:
*(fix16_t *)aGameVars[id].val.lValue = aGameVars[id].dwFlags & GAMEVAR_SPECIAL ? (int32_t)lValue : fix16_from_int((int16_t)lValue);
*(fix16_t *)aGameVars[id].val.lValue = fix16_from_int((int16_t)lValue);
break;
}
}
......@@ -686,8 +686,7 @@ int __fastcall Gv_GetVarX(int id)
id &= ~(MAXGAMEVARS<<1);
}
switch (aGameVars[id].dwFlags & (GAMEVAR_USER_MASK|GAMEVAR_INTPTR|
GAMEVAR_SHORTPTR|GAMEVAR_CHARPTR))
switch (aGameVars[id].dwFlags & (GAMEVAR_USER_MASK|GAMEVAR_PTR_MASK))
{
default:
if (neg) return (-aGameVars[id].val.lValue);
......@@ -698,6 +697,9 @@ int __fastcall Gv_GetVarX(int id)
case GAMEVAR_PERACTOR:
if (neg) return (-aGameVars[id].val.plValues[g_i]);
return (aGameVars[id].val.plValues[g_i]);
case GAMEVAR_RAWQ16PTR:
if (neg) return (-(*((int*)aGameVars[id].val.lValue)));
return (*((int*)aGameVars[id].val.lValue));
case GAMEVAR_INTPTR:
if (neg) return (-(*((int*)aGameVars[id].val.lValue)));
return (*((int*)aGameVars[id].val.lValue));
......@@ -708,8 +710,8 @@ int __fastcall Gv_GetVarX(int id)
if (neg) return (-(*((char*)aGameVars[id].val.lValue)));
return (*((char*)aGameVars[id].val.lValue));
case GAMEVAR_Q16PTR:
if (neg) return (-(aGameVars[id].dwFlags & GAMEVAR_SPECIAL ? *(int32_t *)aGameVars[id].val.lValue : fix16_to_int(*(fix16_t *)aGameVars[id].val.lValue)));
return aGameVars[id].dwFlags & GAMEVAR_SPECIAL ? *(int32_t *)aGameVars[id].val.lValue : fix16_to_int(*(fix16_t *)aGameVars[id].val.lValue);
if (neg) return (-(fix16_to_int(*(fix16_t *)aGameVars[id].val.lValue)));
return fix16_to_int(*(fix16_t *)aGameVars[id].val.lValue);
break;
}
}
......@@ -717,8 +719,7 @@ int __fastcall Gv_GetVarX(int id)
void __fastcall Gv_SetVarX(int id, int lValue)
{
switch (aGameVars[id].dwFlags & (GAMEVAR_USER_MASK|GAMEVAR_INTPTR|
GAMEVAR_SHORTPTR|GAMEVAR_CHARPTR))
switch (aGameVars[id].dwFlags & (GAMEVAR_USER_MASK|GAMEVAR_PTR_MASK))
{
default:
aGameVars[id].val.lValue=lValue;
......@@ -729,6 +730,9 @@ void __fastcall Gv_SetVarX(int id, int lValue)
case GAMEVAR_PERACTOR:
aGameVars[id].val.plValues[g_i]=lValue;
return;
case GAMEVAR_RAWQ16PTR:
*((int*)aGameVars[id].val.lValue) = (int)lValue;
return;
case GAMEVAR_INTPTR:
*((int*)aGameVars[id].val.lValue)=(int)lValue;
return;
......@@ -738,6 +742,9 @@ void __fastcall Gv_SetVarX(int id, int lValue)
case GAMEVAR_CHARPTR:
*((char*)aGameVars[id].val.lValue)=(char)lValue;
return;
case GAMEVAR_Q16PTR:
*((fix16_t*)aGameVars[id].val.lValue)= fix16_from_int((int16_t)lValue);
break;
}
}
......@@ -1362,9 +1369,9 @@ static void Gv_AddSystemVars(void)
Gv_NewVar("cameray",(intptr_t)&ud.camera.y, GAMEVAR_SYSTEM | GAMEVAR_INTPTR | GAMEVAR_SYNCCHECK);
Gv_NewVar("cameraz",(intptr_t)&ud.camera.z, GAMEVAR_SYSTEM | GAMEVAR_INTPTR | GAMEVAR_SYNCCHECK);
Gv_NewVar("cameraang",(intptr_t)&ud.cameraq16ang, GAMEVAR_SYSTEM | GAMEVAR_Q16PTR | GAMEVAR_SYNCCHECK);
Gv_NewVar("cameraq16ang", (intptr_t)&ud.cameraq16ang, GAMEVAR_SYSTEM | GAMEVAR_Q16PTR | GAMEVAR_SPECIAL | GAMEVAR_SYNCCHECK);
Gv_NewVar("cameraq16ang", (intptr_t)&ud.cameraq16ang, GAMEVAR_SYSTEM | GAMEVAR_RAWQ16PTR | GAMEVAR_SYNCCHECK);
Gv_NewVar("camerahoriz",(intptr_t)&ud.cameraq16horiz, GAMEVAR_SYSTEM | GAMEVAR_Q16PTR | GAMEVAR_SYNCCHECK);
Gv_NewVar("cameraq16horiz", (intptr_t)&ud.cameraq16horiz, GAMEVAR_SYSTEM | GAMEVAR_Q16PTR | GAMEVAR_SPECIAL | GAMEVAR_SYNCCHECK);
Gv_NewVar("cameraq16horiz", (intptr_t)&ud.cameraq16horiz, GAMEVAR_SYSTEM | GAMEVAR_RAWQ16PTR | GAMEVAR_SYNCCHECK);
Gv_NewVar("camerasect",(intptr_t)&ud.camerasect, GAMEVAR_SYSTEM | GAMEVAR_SHORTPTR | GAMEVAR_SYNCCHECK);
Gv_NewVar("cameradist",(intptr_t)&g_cameraDistance, GAMEVAR_SYSTEM | GAMEVAR_INTPTR | GAMEVAR_SYNCCHECK);
Gv_NewVar("cameraclock",(intptr_t)&g_cameraClock, GAMEVAR_SYSTEM | GAMEVAR_INTPTR | GAMEVAR_SYNCCHECK);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment