mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-01-17 22:38:38 +01:00
Add Lua support for partial sim updates
This commit is contained in:
parent
ca93e69b19
commit
06802949ab
@ -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()
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user