diff --git a/src/lua/LuaScriptInterface.cpp b/src/lua/LuaScriptInterface.cpp index 0e2c8ba12..ae0eda947 100644 --- a/src/lua/LuaScriptInterface.cpp +++ b/src/lua/LuaScriptInterface.cpp @@ -939,6 +939,8 @@ void LuaScriptInterface::initSimulationAPI() {"listCustomGol", simulation_listCustomGol}, {"addCustomGol", simulation_addCustomGol}, {"removeCustomGol", simulation_removeCustomGol}, + {"lastUpdatedID", simulation_lastUpdatedID}, + {"updateUpTo", simulation_updateUpTo}, {NULL, NULL} }; luaL_register(l, "simulation", simulationAPIMethods); @@ -2477,6 +2479,53 @@ int LuaScriptInterface::simulation_removeCustomGol(lua_State *l) return 1; } +int LuaScriptInterface::simulation_lastUpdatedID(lua_State *l) +{ + if (luacon_sim->debug_mostRecentlyUpdated != -1) + { + lua_pushinteger(l, luacon_sim->debug_mostRecentlyUpdated); + } + else + { + lua_pushnil(l); + } + return 1; +} + +int LuaScriptInterface::simulation_updateUpTo(lua_State *l) +{ + int upTo = NPART - 1; + if (lua_gettop(l) > 0) + { + upTo = luaL_checkinteger(l, 1); + } + if (upTo < 0 || upTo >= NPART) + { + return luaL_error(l, "ID not in valid range"); + } + if (upTo < luacon_sim->debug_currentParticle) + { + upTo = NPART - 1; + } + if (luacon_sim->debug_currentParticle == 0) + { + luacon_sim->framerender = 1; + luacon_sim->BeforeSim(); + luacon_sim->framerender = 0; + } + luacon_sim->UpdateParticles(luacon_sim->debug_currentParticle, upTo); + if (upTo < NPART - 1) + { + luacon_sim->debug_currentParticle = upTo + 1; + } + else + { + luacon_sim->AfterSim(); + luacon_sim->debug_currentParticle = 0; + } + return 0; +} + //// Begin Renderer API void LuaScriptInterface::initRendererAPI() diff --git a/src/lua/LuaScriptInterface.h b/src/lua/LuaScriptInterface.h index b824bfe59..f9e2ac3c8 100644 --- a/src/lua/LuaScriptInterface.h +++ b/src/lua/LuaScriptInterface.h @@ -119,6 +119,8 @@ class LuaScriptInterface: public CommandInterface static int simulation_listCustomGol(lua_State *l); static int simulation_addCustomGol(lua_State *l); static int simulation_removeCustomGol(lua_State *l); + static int simulation_lastUpdatedID(lua_State *l); + static int simulation_updateUpTo(lua_State *l); //Renderer diff --git a/src/simulation/Simulation.cpp b/src/simulation/Simulation.cpp index b75891b40..6c38776b6 100644 --- a/src/simulation/Simulation.cpp +++ b/src/simulation/Simulation.cpp @@ -3484,6 +3484,7 @@ void Simulation::UpdateParticles(int start, int end) for (i = start; i <= end && i <= parts_lastActiveIndex; i++) if (parts[i].type) { + debug_mostRecentlyUpdated = i; t = parts[i].type; x = (int)(parts[i].x+0.5f); @@ -5183,6 +5184,8 @@ void Simulation::BeforeSim() void Simulation::AfterSim() { + debug_mostRecentlyUpdated = -1; + if (emp_trigger_count) { // pitiful attempt at trying to keep code relating to a given element in the same file diff --git a/src/simulation/Simulation.h b/src/simulation/Simulation.h index 6f8120408..7c9cad20f 100644 --- a/src/simulation/Simulation.h +++ b/src/simulation/Simulation.h @@ -55,6 +55,7 @@ public: char can_move[PT_NUM][PT_NUM]; int debug_currentParticle; + int debug_mostRecentlyUpdated = -1; // -1 when between full update loops int parts_lastActiveIndex; int pfree; int NUM_PARTS;