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},
|
{"listCustomGol", simulation_listCustomGol},
|
||||||
{"addCustomGol", simulation_addCustomGol},
|
{"addCustomGol", simulation_addCustomGol},
|
||||||
{"removeCustomGol", simulation_removeCustomGol},
|
{"removeCustomGol", simulation_removeCustomGol},
|
||||||
|
{"lastUpdatedID", simulation_lastUpdatedID},
|
||||||
|
{"updateUpTo", simulation_updateUpTo},
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
luaL_register(l, "simulation", simulationAPIMethods);
|
luaL_register(l, "simulation", simulationAPIMethods);
|
||||||
@ -2477,6 +2479,53 @@ int LuaScriptInterface::simulation_removeCustomGol(lua_State *l)
|
|||||||
return 1;
|
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
|
//// Begin Renderer API
|
||||||
|
|
||||||
void LuaScriptInterface::initRendererAPI()
|
void LuaScriptInterface::initRendererAPI()
|
||||||
|
@ -119,6 +119,8 @@ class LuaScriptInterface: public CommandInterface
|
|||||||
static int simulation_listCustomGol(lua_State *l);
|
static int simulation_listCustomGol(lua_State *l);
|
||||||
static int simulation_addCustomGol(lua_State *l);
|
static int simulation_addCustomGol(lua_State *l);
|
||||||
static int simulation_removeCustomGol(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
|
//Renderer
|
||||||
|
@ -3484,6 +3484,7 @@ void Simulation::UpdateParticles(int start, int end)
|
|||||||
for (i = start; i <= end && i <= parts_lastActiveIndex; i++)
|
for (i = start; i <= end && i <= parts_lastActiveIndex; i++)
|
||||||
if (parts[i].type)
|
if (parts[i].type)
|
||||||
{
|
{
|
||||||
|
debug_mostRecentlyUpdated = i;
|
||||||
t = parts[i].type;
|
t = parts[i].type;
|
||||||
|
|
||||||
x = (int)(parts[i].x+0.5f);
|
x = (int)(parts[i].x+0.5f);
|
||||||
@ -5183,6 +5184,8 @@ void Simulation::BeforeSim()
|
|||||||
|
|
||||||
void Simulation::AfterSim()
|
void Simulation::AfterSim()
|
||||||
{
|
{
|
||||||
|
debug_mostRecentlyUpdated = -1;
|
||||||
|
|
||||||
if (emp_trigger_count)
|
if (emp_trigger_count)
|
||||||
{
|
{
|
||||||
// pitiful attempt at trying to keep code relating to a given element in the same file
|
// 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];
|
char can_move[PT_NUM][PT_NUM];
|
||||||
int debug_currentParticle;
|
int debug_currentParticle;
|
||||||
|
int debug_mostRecentlyUpdated = -1; // -1 when between full update loops
|
||||||
int parts_lastActiveIndex;
|
int parts_lastActiveIndex;
|
||||||
int pfree;
|
int pfree;
|
||||||
int NUM_PARTS;
|
int NUM_PARTS;
|
||||||
|
Reference in New Issue
Block a user