Add enums for gravity/air/edge modes, add more constants to Lua
Constants for the new enums were added, along with walls (in the sim.walls table), x/y center, and a few movement constants
This commit is contained in:
parent
bc51bdf634
commit
29ea811642
@ -1251,8 +1251,8 @@ void GameSave::readPSv(const std::vector<char> &dataVec)
|
||||
auto partP = blockP * CELL;
|
||||
|
||||
if (ver<46) {
|
||||
gravityMode = 0;
|
||||
airMode = 0;
|
||||
gravityMode = GRAV_VERTICAL;
|
||||
airMode = AIR_ON;
|
||||
}
|
||||
|
||||
PlaneAdapter<std::vector<int>> particleIDMap(RES, 0);
|
||||
@ -2295,7 +2295,7 @@ std::pair<bool, std::vector<char>> GameSave::serialiseOPS() const
|
||||
bson_append_string(&b, "platform", IDENT_PLATFORM);
|
||||
bson_append_string(&b, "ident", IDENT);
|
||||
bson_append_finish_object(&b);
|
||||
if (gravityMode == 3)
|
||||
if (gravityMode == GRAV_CUSTOM)
|
||||
{
|
||||
bson_append_double(&b, "customGravityX", double(customGravityX));
|
||||
bson_append_double(&b, "customGravityY", double(customGravityY));
|
||||
|
@ -773,20 +773,20 @@ void GameController::ResetSpark()
|
||||
|
||||
void GameController::SwitchGravity()
|
||||
{
|
||||
gameModel->GetSimulation()->gravityMode = (gameModel->GetSimulation()->gravityMode+1)%4;
|
||||
gameModel->GetSimulation()->gravityMode = (gameModel->GetSimulation()->gravityMode + 1) % NUM_GRAV_MODES;
|
||||
|
||||
switch (gameModel->GetSimulation()->gravityMode)
|
||||
{
|
||||
case 0:
|
||||
case GRAV_VERTICAL:
|
||||
gameModel->SetInfoTip("Gravity: Vertical");
|
||||
break;
|
||||
case 1:
|
||||
case GRAV_OFF:
|
||||
gameModel->SetInfoTip("Gravity: Off");
|
||||
break;
|
||||
case 2:
|
||||
case GRAV_RADIAL:
|
||||
gameModel->SetInfoTip("Gravity: Radial");
|
||||
break;
|
||||
case 3:
|
||||
case GRAV_CUSTOM:
|
||||
gameModel->SetInfoTip("Gravity: Custom");
|
||||
break;
|
||||
}
|
||||
@ -794,23 +794,23 @@ void GameController::SwitchGravity()
|
||||
|
||||
void GameController::SwitchAir()
|
||||
{
|
||||
gameModel->GetSimulation()->air->airMode = (gameModel->GetSimulation()->air->airMode+1)%5;
|
||||
gameModel->GetSimulation()->air->airMode = (gameModel->GetSimulation()->air->airMode + 1) % NUM_AIR_MODES;
|
||||
|
||||
switch (gameModel->GetSimulation()->air->airMode)
|
||||
{
|
||||
case 0:
|
||||
case AIR_ON:
|
||||
gameModel->SetInfoTip("Air: On");
|
||||
break;
|
||||
case 1:
|
||||
case AIR_PRESSURE_OFF:
|
||||
gameModel->SetInfoTip("Air: Pressure Off");
|
||||
break;
|
||||
case 2:
|
||||
case AIR_VELOCITY_OFF:
|
||||
gameModel->SetInfoTip("Air: Velocity Off");
|
||||
break;
|
||||
case 3:
|
||||
case AIR_OFF:
|
||||
gameModel->SetInfoTip("Air: Off");
|
||||
break;
|
||||
case 4:
|
||||
case AIR_NO_UPDATE:
|
||||
gameModel->SetInfoTip("Air: No Update");
|
||||
break;
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ GameModel::GameModel():
|
||||
activeColourPreset(0),
|
||||
colourSelector(false),
|
||||
colour(255, 0, 0, 255),
|
||||
edgeMode(0),
|
||||
edgeMode(EDGE_VOID),
|
||||
ambientAirTemp(R_TEMP + 273.15f),
|
||||
decoSpace(0)
|
||||
{
|
||||
@ -91,7 +91,7 @@ GameModel::GameModel():
|
||||
ren->decorations_enable = prefs.Get("Renderer.Decorations", true);
|
||||
|
||||
//Load config into simulation
|
||||
edgeMode = prefs.Get("Simulation.EdgeMode", 0); // TODO: EdgeMode enum
|
||||
edgeMode = prefs.Get("Simulation.EdgeMode", (int)EDGE_VOID);
|
||||
sim->SetEdgeMode(edgeMode);
|
||||
ambientAirTemp = float(R_TEMP) + 273.15f;
|
||||
{
|
||||
@ -1332,10 +1332,10 @@ void GameModel::FrameStep(int frames)
|
||||
void GameModel::ClearSimulation()
|
||||
{
|
||||
//Load defaults
|
||||
sim->gravityMode = 0;
|
||||
sim->gravityMode = GRAV_VERTICAL;
|
||||
sim->customGravityX = 0.0f;
|
||||
sim->customGravityY = 0.0f;
|
||||
sim->air->airMode = 0;
|
||||
sim->air->airMode = AIR_ON;
|
||||
sim->legacy_enable = false;
|
||||
sim->water_equal_test = false;
|
||||
sim->SetEdgeMode(edgeMode);
|
||||
|
@ -1215,6 +1215,8 @@ void LuaScriptInterface::initSimulationAPI()
|
||||
SETCONST(l, NCELL);
|
||||
SETCONST(l, XRES);
|
||||
SETCONST(l, YRES);
|
||||
SETCONST(l, XCNTR);
|
||||
SETCONST(l, YCNTR);
|
||||
SETCONST(l, NPART);
|
||||
SETCONST(l, NT);
|
||||
SETCONST(l, ST);
|
||||
@ -1229,6 +1231,9 @@ void LuaScriptInterface::initSimulationAPI()
|
||||
SETCONSTF(l, MIN_TEMP);
|
||||
SETCONSTF(l, MAX_PRESSURE);
|
||||
SETCONSTF(l, MIN_PRESSURE);
|
||||
SETCONST(l, ISTP);
|
||||
SETCONSTF(l, CFDS);
|
||||
SETCONSTF(l, SIM_MAXVELOCITY);
|
||||
|
||||
SETCONST(l, TOOL_HEAT);
|
||||
SETCONST(l, TOOL_COOL);
|
||||
@ -1239,6 +1244,7 @@ void LuaScriptInterface::initSimulationAPI()
|
||||
SETCONST(l, TOOL_MIX);
|
||||
SETCONST(l, TOOL_CYCL);
|
||||
lua_pushinteger(l, luacon_sim->tools.size()); lua_setfield(l, -2, "TOOL_WIND");
|
||||
|
||||
SETCONST(l, DECO_DRAW);
|
||||
SETCONST(l, DECO_CLEAR);
|
||||
SETCONST(l, DECO_ADD);
|
||||
@ -1250,6 +1256,53 @@ void LuaScriptInterface::initSimulationAPI()
|
||||
SETCONST(l, PMAPBITS);
|
||||
SETCONST(l, PMAPMASK);
|
||||
|
||||
SETCONST(l, CIRCLE_BRUSH);
|
||||
SETCONST(l, SQUARE_BRUSH);
|
||||
SETCONST(l, TRI_BRUSH);
|
||||
SETCONST(l, BRUSH_NUM);
|
||||
|
||||
SETCONST(l, EDGE_VOID);
|
||||
SETCONST(l, EDGE_SOLID);
|
||||
SETCONST(l, EDGE_LOOP);
|
||||
SETCONST(l, NUM_EDGE_MODES);
|
||||
|
||||
SETCONST(l, AIR_ON);
|
||||
SETCONST(l, AIR_PRESSURE_OFF);
|
||||
SETCONST(l, AIR_VELOCITY_OFF);
|
||||
SETCONST(l, AIR_OFF);
|
||||
SETCONST(l, AIR_NO_UPDATE);
|
||||
SETCONST(l, NUM_AIR_MODES);
|
||||
|
||||
SETCONST(l, GRAV_VERTICAL);
|
||||
SETCONST(l, GRAV_OFF);
|
||||
SETCONST(l, GRAV_RADIAL);
|
||||
SETCONST(l, GRAV_CUSTOM);
|
||||
SETCONST(l, NUM_GRAV_MODES);
|
||||
|
||||
lua_newtable(l);
|
||||
SETCONST(l, WL_ERASE);
|
||||
SETCONST(l, WL_WALLELEC);
|
||||
SETCONST(l, WL_EWALL);
|
||||
SETCONST(l, WL_DETECT);
|
||||
SETCONST(l, WL_STREAM);
|
||||
SETCONST(l, WL_FAN);
|
||||
SETCONST(l, WL_ALLOWLIQUID);
|
||||
SETCONST(l, WL_DESTROYALL);
|
||||
SETCONST(l, WL_WALL);
|
||||
SETCONST(l, WL_ALLOWAIR);
|
||||
SETCONST(l, WL_ALLOWPOWDER);
|
||||
SETCONST(l, WL_ALLOWALLELEC);
|
||||
SETCONST(l, WL_EHOLE);
|
||||
SETCONST(l, WL_ALLOWGAS);
|
||||
SETCONST(l, WL_GRAV);
|
||||
SETCONST(l, WL_ALLOWENERGY);
|
||||
SETCONST(l, WL_BLOCKAIR);
|
||||
SETCONST(l, WL_ERASEALL);
|
||||
SETCONST(l, WL_STASIS);
|
||||
SETCONST(l, WL_FLOODHELPER);
|
||||
SETCONST(l, UI_WALLCOUNT);
|
||||
lua_setfield(l, -2, "walls");
|
||||
|
||||
//Declare FIELD_BLAH constants
|
||||
{
|
||||
int particlePropertiesCount = 0;
|
||||
@ -2301,7 +2354,7 @@ int LuaScriptInterface::simulation_edgeMode(lua_State * l)
|
||||
lua_pushnumber(l, luacon_model->GetEdgeMode());
|
||||
return 1;
|
||||
}
|
||||
int edgeMode = luaL_optint(l, 1, 0);
|
||||
int edgeMode = luaL_optint(l, 1, EDGE_VOID);
|
||||
luacon_model->SetEdgeMode(edgeMode);
|
||||
return 0;
|
||||
}
|
||||
@ -2314,7 +2367,7 @@ int LuaScriptInterface::simulation_gravityMode(lua_State * l)
|
||||
lua_pushnumber(l, luacon_sim->gravityMode);
|
||||
return 1;
|
||||
}
|
||||
int gravityMode = luaL_optint(l, 1, 0);
|
||||
int gravityMode = luaL_optint(l, 1, GRAV_VERTICAL);
|
||||
luacon_sim->gravityMode = gravityMode;
|
||||
return 0;
|
||||
}
|
||||
@ -2347,7 +2400,7 @@ int LuaScriptInterface::simulation_airMode(lua_State * l)
|
||||
lua_pushnumber(l, luacon_sim->air->airMode);
|
||||
return 1;
|
||||
}
|
||||
int airMode = luaL_optint(l, 1, 0);
|
||||
int airMode = luaL_optint(l, 1, AIR_ON);
|
||||
luacon_sim->air->airMode = airMode;
|
||||
return 0;
|
||||
}
|
||||
|
@ -119,7 +119,7 @@ void Air::update_air(void)
|
||||
{
|
||||
const float advDistanceMult = 0.7f;
|
||||
|
||||
if (airMode != 4) //airMode 4 is no air/pressure update
|
||||
if (airMode != AIR_NO_UPDATE) //airMode 4 is no air/pressure update
|
||||
{
|
||||
for (auto i=0; i<YCELLS; i++) //reduces pressure/velocity on the edges every frame
|
||||
{
|
||||
@ -309,21 +309,21 @@ void Air::update_air(void)
|
||||
switch (airMode)
|
||||
{
|
||||
default:
|
||||
case 0: //Default
|
||||
case AIR_ON: //Default
|
||||
break;
|
||||
case 1: //0 Pressure
|
||||
case AIR_PRESSURE_OFF: //0 Pressure
|
||||
dp = 0.0f;
|
||||
break;
|
||||
case 2: //0 Velocity
|
||||
case AIR_VELOCITY_OFF: //0 Velocity
|
||||
dx = 0.0f;
|
||||
dy = 0.0f;
|
||||
break;
|
||||
case 3: //0 Air
|
||||
case AIR_OFF: //0 Air
|
||||
dx = 0.0f;
|
||||
dy = 0.0f;
|
||||
dp = 0.0f;
|
||||
break;
|
||||
case 4: //No Update
|
||||
case AIR_NO_UPDATE: //No Update
|
||||
break;
|
||||
}
|
||||
|
||||
@ -383,7 +383,7 @@ void Air::ApproximateBlockAirMaps()
|
||||
|
||||
Air::Air(Simulation & simulation):
|
||||
sim(simulation),
|
||||
airMode(0),
|
||||
airMode(AIR_ON),
|
||||
ambientAirTemp(R_TEMP + 273.15f)
|
||||
{
|
||||
//Simulation should do this.
|
||||
|
@ -753,8 +753,8 @@ void Simulation::SetEdgeMode(int newEdgeMode)
|
||||
edgeMode = newEdgeMode;
|
||||
switch(edgeMode)
|
||||
{
|
||||
case 0:
|
||||
case 2:
|
||||
case EDGE_VOID:
|
||||
case EDGE_LOOP:
|
||||
for(int i = 0; i<XCELLS; i++)
|
||||
{
|
||||
bmap[0][i] = 0;
|
||||
@ -766,7 +766,7 @@ void Simulation::SetEdgeMode(int newEdgeMode)
|
||||
bmap[i][XCELLS-1] = 0;
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
case EDGE_SOLID:
|
||||
int i;
|
||||
for(i=0; i<XCELLS; i++)
|
||||
{
|
||||
@ -780,7 +780,7 @@ void Simulation::SetEdgeMode(int newEdgeMode)
|
||||
}
|
||||
break;
|
||||
default:
|
||||
SetEdgeMode(0);
|
||||
SetEdgeMode(EDGE_VOID);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1647,7 +1647,7 @@ int Simulation::try_move(int i, int x, int y, int nx, int ny)
|
||||
int Simulation::do_move(int i, int x, int y, float nxf, float nyf)
|
||||
{
|
||||
int nx = (int)(nxf+0.5f), ny = (int)(nyf+0.5f), result;
|
||||
if (edgeMode == 2)
|
||||
if (edgeMode == EDGE_LOOP)
|
||||
{
|
||||
bool x_ok = (nx >= CELL && nx < XRES-CELL);
|
||||
bool y_ok = (ny >= CELL && ny < YRES-CELL);
|
||||
@ -2076,15 +2076,15 @@ void Simulation::GetGravityField(int x, int y, float particleGrav, float newtonG
|
||||
switch (gravityMode)
|
||||
{
|
||||
default:
|
||||
case 0: //normal, vertical gravity
|
||||
case GRAV_VERTICAL: //normal, vertical gravity
|
||||
pGravX = 0;
|
||||
pGravY = particleGrav;
|
||||
break;
|
||||
case 1: //no gravity
|
||||
case GRAV_OFF: //no gravity
|
||||
pGravX = 0;
|
||||
pGravY = 0;
|
||||
break;
|
||||
case 2: //radial gravity
|
||||
case GRAV_RADIAL: //radial gravity
|
||||
{
|
||||
pGravX = 0;
|
||||
pGravY = 0;
|
||||
@ -2098,7 +2098,7 @@ void Simulation::GetGravityField(int x, int y, float particleGrav, float newtonG
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 3: //custom gravity
|
||||
case GRAV_CUSTOM: //custom gravity
|
||||
pGravX = particleGrav * customGravityX;
|
||||
pGravY = particleGrav * customGravityY;
|
||||
break;
|
||||
@ -2885,7 +2885,7 @@ killed:
|
||||
fin_yf += dy;
|
||||
fin_x = (int)(fin_xf+0.5f);
|
||||
fin_y = (int)(fin_yf+0.5f);
|
||||
if (edgeMode == 2)
|
||||
if (edgeMode == EDGE_LOOP)
|
||||
{
|
||||
bool x_ok = (fin_xf >= CELL-.5f && fin_xf < XRES-CELL-.5f);
|
||||
bool y_ok = (fin_yf >= CELL-.5f && fin_yf < YRES-CELL-.5f);
|
||||
@ -2901,7 +2901,7 @@ killed:
|
||||
// nothing found
|
||||
fin_xf = parts[i].x + parts[i].vx;
|
||||
fin_yf = parts[i].y + parts[i].vy;
|
||||
if (edgeMode == 2)
|
||||
if (edgeMode == EDGE_LOOP)
|
||||
{
|
||||
bool x_ok = (fin_xf >= CELL-.5f && fin_xf < XRES-CELL-.5f);
|
||||
bool y_ok = (fin_yf >= CELL-.5f && fin_yf < YRES-CELL-.5f);
|
||||
@ -2945,7 +2945,7 @@ killed:
|
||||
parts[i].y += parts[i].vy;
|
||||
int nx = (int)((float)parts[i].x+0.5f);
|
||||
int ny = (int)((float)parts[i].y+0.5f);
|
||||
if (edgeMode == 2)
|
||||
if (edgeMode == EDGE_LOOP)
|
||||
{
|
||||
bool x_ok = (nx >= CELL && nx < XRES-CELL);
|
||||
bool y_ok = (ny >= CELL && ny < YRES-CELL);
|
||||
@ -3218,7 +3218,7 @@ killed:
|
||||
goto movedone;
|
||||
}
|
||||
}
|
||||
if (elements[t].Falldown>1 && !grav->IsEnabled() && gravityMode==0 && parts[i].vy>fabsf(parts[i].vx))
|
||||
if (elements[t].Falldown>1 && !grav->IsEnabled() && gravityMode==GRAV_VERTICAL && parts[i].vy>fabsf(parts[i].vx))
|
||||
{
|
||||
s = 0;
|
||||
// stagnant is true if FLAG_STAGNANT was set for this particle in previous frame
|
||||
@ -3942,8 +3942,8 @@ Simulation::Simulation():
|
||||
gravWallChanged(false),
|
||||
CGOL(0),
|
||||
GSPEED(1),
|
||||
edgeMode(0),
|
||||
gravityMode(0),
|
||||
edgeMode(EDGE_VOID),
|
||||
gravityMode(GRAV_VERTICAL),
|
||||
customGravityX(0),
|
||||
customGravityY(0),
|
||||
legacy_enable(0),
|
||||
|
@ -133,6 +133,21 @@ constexpr int NGT_BRAN = 23;
|
||||
constexpr auto REPLACE_MODE = UINT32_C(0x00000001);
|
||||
constexpr auto SPECIFIC_DELETE = UINT32_C(0x00000002);
|
||||
|
||||
enum EdgeMode
|
||||
{
|
||||
EDGE_VOID, EDGE_SOLID, EDGE_LOOP, NUM_EDGE_MODES
|
||||
};
|
||||
|
||||
enum AirMode
|
||||
{
|
||||
AIR_ON, AIR_PRESSURE_OFF, AIR_VELOCITY_OFF, AIR_OFF, AIR_NO_UPDATE, NUM_AIR_MODES
|
||||
};
|
||||
|
||||
enum GravityMode
|
||||
{
|
||||
GRAV_VERTICAL, GRAV_OFF, GRAV_RADIAL, GRAV_CUSTOM, NUM_GRAV_MODES
|
||||
};
|
||||
|
||||
struct part_type;
|
||||
struct part_transition;
|
||||
|
||||
|
@ -147,13 +147,13 @@ int Element_STKM_run_stickman(playerst *playerp, UPDATE_FUNC_ARGS)
|
||||
switch (sim->gravityMode)
|
||||
{
|
||||
default:
|
||||
case 0:
|
||||
case GRAV_VERTICAL:
|
||||
gvy = 1;
|
||||
break;
|
||||
case 1:
|
||||
case GRAV_OFF:
|
||||
gvy = gvx = 0.0f;
|
||||
break;
|
||||
case 2:
|
||||
case GRAV_RADIAL:
|
||||
{
|
||||
float gravd;
|
||||
gravd = 0.01f - hypotf((parts[i].x - XCNTR), (parts[i].y - YCNTR));
|
||||
@ -161,7 +161,7 @@ int Element_STKM_run_stickman(playerst *playerp, UPDATE_FUNC_ARGS)
|
||||
gvy = ((float)(parts[i].y - YCNTR) / gravd);
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
case GRAV_CUSTOM:
|
||||
gvx = sim->customGravityX;
|
||||
gvy = sim->customGravityY;
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user