Preprocessor purge round 4: misc function macros

This commit is contained in:
Tamás Bálint Misius 2023-01-04 12:13:30 +01:00
parent b2b06bf009
commit 3eb1609934
No known key found for this signature in database
GPG Key ID: 5B472A12F6ECA9F2
4 changed files with 47 additions and 63 deletions

View File

@ -1896,12 +1896,6 @@ void GameSave::readPSv(const std::vector<char> &dataVec)
}
}
// restrict the minimum version this save can be opened with
#define RESTRICTVERSION(major, minor) if ((major) > minimumMajorVersion || (((major) == minimumMajorVersion && (minor) > minimumMinorVersion))) {\
minimumMajorVersion = major;\
minimumMinorVersion = minor;\
}
std::pair<bool, std::vector<char>> GameSave::serialiseOPS() const
{
int blockX, blockY, blockW, blockH, fullX, fullY, fullW, fullH;
@ -1910,6 +1904,14 @@ std::pair<bool, std::vector<char>> GameSave::serialiseOPS() const
// when building, this number may be increased depending on what elements are used
// or what properties are detected
int minimumMajorVersion = 90, minimumMinorVersion = 2;
auto RESTRICTVERSION = [&minimumMajorVersion, &minimumMinorVersion](int major, int minor) {
// restrict the minimum version this save can be opened with
if (major > minimumMajorVersion || ((major == minimumMajorVersion && minor > minimumMinorVersion)))
{
minimumMajorVersion = major;
minimumMinorVersion = minor;
}
};
//Get coords in blocks
blockX = 0;//orig_x0/CELL;

View File

@ -1,39 +1,26 @@
#pragma once
#define PIXELCHANNELS 3
#ifdef PIX16
# define PIXELSIZE 2
# define PIXPACK(x) ((((x)>>8)&0xF800)|(((x)>>5)&0x07E0)|(((x)>>3)&0x001F)) //16bit RGB in 16bit int: ????
# define PIXRGB(r,g,b) ((((r)<<8)&0xF800)|(((g)<<3)&0x07E0)|(((b)>>3)&0x001F))
# define PIXR(x) (((x)>>8)&0xF8)
# define PIXG(x) (((x)>>3)&0xFC)
# define PIXB(x) (((x)<<3)&0xF8)
#else
# define PIXELSIZE 4
# ifdef PIX32BGRA
# define PIXPACK(x) ((((x)>>16)&0x0000FF)|((x)&0x00FF00)|(((x)<<16)&0xFF0000)) //24bit BGR in 32bit int: 00BBGGRR
# define PIXRGB(r,g,b) (((b)<<16)|((g)<<8)|((r)))// (((b)<<16)|((g)<<8)|(r))
# define PIXR(x) ((x)&0xFF)
# define PIXG(x) (((x)>>8)&0xFF)
# define PIXB(x) ((x)>>16)
# else
# ifdef PIX32BGRA
# define PIXPACK(x) ((((x)>>8)&0x0000FF00)|(((x)<<8)&0x00FF0000)|(((x)<<24)&0xFF000000)) //32bit BGRA in 32bit int: BBGGRRAA
# define PIXRGB(r,g,b) (((b)<<24)|((g)<<16)|((r)<<8))
# define PIXR(x) (((x)>>8)&0xFF)
# define PIXG(x) (((x)>>16)&0xFF)
# define PIXB(x) (((x)>>24)&0xFF)
# else
# define PIXPACK(x) (x) //24bit RGB in 32bit int: 00RRGGBB.
# define PIXRGB(r,g,b) (((r)<<16)|((g)<<8)|(b))
# define PIXR(x) (((x)>>16)&0xFF)
# define PIXG(x) (((x)>>8)&0xFF)
# define PIXB(x) ((x)&0xFF)
# endif
# endif
#endif
#ifdef PIX16
typedef unsigned short pixel;
#else
typedef unsigned int pixel;
#endif
constexpr int PIXELCHANNELS = 3;
constexpr int PIXELSIZE = 4;
constexpr pixel PIXPACK(int x)
{
return x;
}
constexpr pixel PIXRGB(int r, int g, int b)
{
return (r << 16) | (g << 8) | b;
}
constexpr int PIXR(pixel x)
{
return (x >> 16) & 0xFF;
}
constexpr int PIXG(pixel x)
{
return (x >> 8) & 0xFF;
}
constexpr int PIXB(pixel x)
{
return x & 0xFF;
}

View File

@ -2959,11 +2959,7 @@ void LuaScriptInterface::LuaGetProperty(lua_State* l, StructProperty property, i
break;
}
case StructProperty::Colour:
#if PIXELSIZE == 4
lua_pushinteger(l, *((unsigned int*)propertyAddress));
#else
lua_pushinteger(l, *((unsigned short*)propertyAddress));
#endif
break;
case StructProperty::Removed:
lua_pushnil(l);
@ -3004,11 +3000,7 @@ void LuaScriptInterface::LuaSetProperty(lua_State* l, StructProperty property, i
*((String*)propertyAddress) = tpt_lua_checkString(l, stackPos);
break;
case StructProperty::Colour:
#if PIXELSIZE == 4
*((unsigned int*)propertyAddress) = int32_truncate(luaL_checknumber(l, stackPos));
#else
*((unsigned short*)propertyAddress) = int32_truncate(luaL_checknumber(l, stackPos));
#endif
break;
case StructProperty::Removed:
break;

View File

@ -97,7 +97,10 @@ static void changeType(ELEMENT_CHANGETYPE_FUNC_ARGS)
sim->player.spwn = 0;
}
#define INBOND(x, y) ((x)>=0 && (y)>=0 && (x)<XRES && (y)<YRES)
constexpr bool INBOND(int x, int y)
{
return x >= 0 && y >= 0 && x < XRES && y < YRES;
}
int Element_STKM_run_stickman(playerst *playerp, UPDATE_FUNC_ARGS)
{
@ -247,7 +250,7 @@ int Element_STKM_run_stickman(playerst *playerp, UPDATE_FUNC_ARGS)
bool moved = false;
if (dl>dr)
{
if (INBOND(playerp->legs[4], playerp->legs[5]) && !sim->eval_move(t, int(playerp->legs[4]), int(playerp->legs[5]), NULL))
if (INBOND(int(playerp->legs[4]), int(playerp->legs[5])) && !sim->eval_move(t, int(playerp->legs[4]), int(playerp->legs[5]), NULL))
{
playerp->accs[2] = -3*mvy-3*mvx;
playerp->accs[3] = 3*mvx-3*mvy;
@ -258,7 +261,7 @@ int Element_STKM_run_stickman(playerst *playerp, UPDATE_FUNC_ARGS)
}
else
{
if (INBOND(playerp->legs[12], playerp->legs[13]) && !sim->eval_move(t, int(playerp->legs[12]), int(playerp->legs[13]), NULL))
if (INBOND(int(playerp->legs[12]), int(playerp->legs[13])) && !sim->eval_move(t, int(playerp->legs[12]), int(playerp->legs[13]), NULL))
{
playerp->accs[6] = -3*mvy-3*mvx;
playerp->accs[7] = 3*mvx-3*mvy;
@ -297,7 +300,7 @@ int Element_STKM_run_stickman(playerst *playerp, UPDATE_FUNC_ARGS)
bool moved = false;
if (dl<dr)
{
if (INBOND(playerp->legs[4], playerp->legs[5]) && !sim->eval_move(t, int(playerp->legs[4]), int(playerp->legs[5]), NULL))
if (INBOND(int(playerp->legs[4]), int(playerp->legs[5])) && !sim->eval_move(t, int(playerp->legs[4]), int(playerp->legs[5]), NULL))
{
playerp->accs[2] = 3*mvy-3*mvx;
playerp->accs[3] = -3*mvx-3*mvy;
@ -308,7 +311,7 @@ int Element_STKM_run_stickman(playerst *playerp, UPDATE_FUNC_ARGS)
}
else
{
if (INBOND(playerp->legs[12], playerp->legs[13]) && !sim->eval_move(t, int(playerp->legs[12]), int(playerp->legs[13]), NULL))
if (INBOND(int(playerp->legs[12]), int(playerp->legs[13])) && !sim->eval_move(t, int(playerp->legs[12]), int(playerp->legs[13]), NULL))
{
playerp->accs[6] = 3*mvy-3*mvx;
playerp->accs[7] = -3*mvx-3*mvy;
@ -374,8 +377,8 @@ int Element_STKM_run_stickman(playerst *playerp, UPDATE_FUNC_ARGS)
}
}
}
else if ((INBOND(playerp->legs[4], playerp->legs[5]) && !sim->eval_move(t, int(playerp->legs[4]), int(playerp->legs[5]), NULL)) ||
(INBOND(playerp->legs[12], playerp->legs[13]) && !sim->eval_move(t, int(playerp->legs[12]), int(playerp->legs[13]), NULL)))
else if ((INBOND(int(playerp->legs[4]), int(playerp->legs[5])) && !sim->eval_move(t, int(playerp->legs[4]), int(playerp->legs[5]), NULL)) ||
(INBOND(int(playerp->legs[12]), int(playerp->legs[13])) && !sim->eval_move(t, int(playerp->legs[12]), int(playerp->legs[13]), NULL)))
{
parts[i].vx -= 4*mvx;
parts[i].vy -= 4*mvy;
@ -387,10 +390,10 @@ int Element_STKM_run_stickman(playerst *playerp, UPDATE_FUNC_ARGS)
}
//Charge detector wall if foot inside
if (INBOND((int)(playerp->legs[4]+0.5)/CELL, (int)(playerp->legs[5]+0.5)/CELL) &&
if (INBOND(int(playerp->legs[4]+0.5)/CELL, int(playerp->legs[5]+0.5)/CELL) &&
sim->bmap[(int)(playerp->legs[5]+0.5)/CELL][(int)(playerp->legs[4]+0.5)/CELL]==WL_DETECT)
sim->set_emap((int)playerp->legs[4]/CELL, (int)playerp->legs[5]/CELL);
if (INBOND((int)(playerp->legs[12]+0.5)/CELL, (int)(playerp->legs[13]+0.5)/CELL) &&
if (INBOND(int(playerp->legs[12]+0.5)/CELL, int(playerp->legs[13]+0.5)/CELL) &&
sim->bmap[(int)(playerp->legs[13]+0.5)/CELL][(int)(playerp->legs[12]+0.5)/CELL]==WL_DETECT)
sim->set_emap((int)(playerp->legs[12]+0.5)/CELL, (int)(playerp->legs[13]+0.5)/CELL);
@ -547,27 +550,27 @@ int Element_STKM_run_stickman(playerst *playerp, UPDATE_FUNC_ARGS)
playerp->legs[8] += (playerp->legs[8]-parts[i].x)*d;
playerp->legs[9] += (playerp->legs[9]-parts[i].y)*d;
if (INBOND(playerp->legs[4], playerp->legs[5]) && !sim->eval_move(t, int(playerp->legs[4]), int(playerp->legs[5]), NULL))
if (INBOND(int(playerp->legs[4]), int(playerp->legs[5])) && !sim->eval_move(t, int(playerp->legs[4]), int(playerp->legs[5]), NULL))
{
playerp->legs[4] = playerp->legs[6];
playerp->legs[5] = playerp->legs[7];
}
if (INBOND(playerp->legs[12], playerp->legs[13]) && !sim->eval_move(t, int(playerp->legs[12]), int(playerp->legs[13]), NULL))
if (INBOND(int(playerp->legs[12]), int(playerp->legs[13])) && !sim->eval_move(t, int(playerp->legs[12]), int(playerp->legs[13]), NULL))
{
playerp->legs[12] = playerp->legs[14];
playerp->legs[13] = playerp->legs[15];
}
//This makes stick man "pop" from obstacles
if (INBOND(playerp->legs[4], playerp->legs[5]) && !sim->eval_move(t, int(playerp->legs[4]), int(playerp->legs[5]), NULL))
if (INBOND(int(playerp->legs[4]), int(playerp->legs[5])) && !sim->eval_move(t, int(playerp->legs[4]), int(playerp->legs[5]), NULL))
{
float t;
t = playerp->legs[4]; playerp->legs[4] = playerp->legs[6]; playerp->legs[6] = t;
t = playerp->legs[5]; playerp->legs[5] = playerp->legs[7]; playerp->legs[7] = t;
}
if (INBOND(playerp->legs[12], playerp->legs[13]) && !sim->eval_move(t, int(playerp->legs[12]), int(playerp->legs[13]), NULL))
if (INBOND(int(playerp->legs[12]), int(playerp->legs[13])) && !sim->eval_move(t, int(playerp->legs[12]), int(playerp->legs[13]), NULL))
{
float t;
t = playerp->legs[12]; playerp->legs[12] = playerp->legs[14]; playerp->legs[14] = t;