From dd5e5b1f3a562b5c68e7bc8eae1a8c00e81e9982 Mon Sep 17 00:00:00 2001 From: jacob1 Date: Sun, 8 Oct 2023 12:18:57 -0400 Subject: [PATCH] misc: Fix sim.partNeighbors table being 0-indexed, rename SIM_MAXVELOCITY to MAX_VELOCITY --- src/SimulationConfig.h | 2 +- src/lua/LuaScriptInterface.cpp | 4 ++-- src/simulation/Simulation.cpp | 8 ++++---- src/simulation/elements/VSNS.cpp | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/SimulationConfig.h b/src/SimulationConfig.h index bee3ff9c0..1fd9aef83 100644 --- a/src/SimulationConfig.h +++ b/src/SimulationConfig.h @@ -31,7 +31,7 @@ constexpr int MAXSIGNS = 16; constexpr int ISTP = CELL / 2; constexpr float CFDS = 4.0f / CELL; -constexpr float SIM_MAXVELOCITY = 1e4f; +constexpr float MAX_VELOCITY = 1e4f; //Air constants constexpr float AIR_TSTEPP = 0.3f; diff --git a/src/lua/LuaScriptInterface.cpp b/src/lua/LuaScriptInterface.cpp index bb2bdd323..b16be178f 100644 --- a/src/lua/LuaScriptInterface.cpp +++ b/src/lua/LuaScriptInterface.cpp @@ -1233,7 +1233,7 @@ void LuaScriptInterface::initSimulationAPI() SETCONSTF(l, MIN_PRESSURE); SETCONST(l, ISTP); SETCONSTF(l, CFDS); - SETCONSTF(l, SIM_MAXVELOCITY); + SETCONSTF(l, MAX_VELOCITY); SETCONST(l, TOOL_HEAT); SETCONST(l, TOOL_COOL); @@ -1370,7 +1370,7 @@ void LuaScriptInterface::set_map(int x, int y, int width, int height, float valu int LuaScriptInterface::simulation_partNeighbours(lua_State * l) { lua_newtable(l); - int id = 0; + int id = 1; int x = lua_tointeger(l, 1), y = lua_tointeger(l, 2), r = lua_tointeger(l, 3), rx, ry, n; if(lua_gettop(l) == 5) // this is one more than the number of arguments because a table has just been pushed onto the stack with lua_newtable(l); { diff --git a/src/simulation/Simulation.cpp b/src/simulation/Simulation.cpp index 32d45bb21..1950bf77a 100644 --- a/src/simulation/Simulation.cpp +++ b/src/simulation/Simulation.cpp @@ -2864,11 +2864,11 @@ killed: } else { - if (mv > SIM_MAXVELOCITY) + if (mv > MAX_VELOCITY) { - parts[i].vx *= SIM_MAXVELOCITY/mv; - parts[i].vy *= SIM_MAXVELOCITY/mv; - mv = SIM_MAXVELOCITY; + parts[i].vx *= MAX_VELOCITY/mv; + parts[i].vy *= MAX_VELOCITY/mv; + mv = MAX_VELOCITY; } // interpolate to see if there is anything in the way dx = parts[i].vx*ISTP/mv; diff --git a/src/simulation/elements/VSNS.cpp b/src/simulation/elements/VSNS.cpp index 2b54de686..baefbe56b 100644 --- a/src/simulation/elements/VSNS.cpp +++ b/src/simulation/elements/VSNS.cpp @@ -109,7 +109,7 @@ static int update(UPDATE_FUNC_ARGS) if (TYP(r) == PT_FILT) { int vel = parts[ID(r)].ctype - 0x10000000; - if (vel >= 0 && vel < SIM_MAXVELOCITY) + if (vel >= 0 && vel < MAX_VELOCITY) { doDeserialization = true; Vs = float(vel);