fix lua element update bugs, fixes #244
also add new mode for functions run before the normal update function
This commit is contained in:
parent
84f13cfe63
commit
03e07945e3
@ -699,10 +699,12 @@ int luatpt_element_func(lua_State *l)
|
|||||||
if(element > 0 && element < PT_NUM)
|
if(element > 0 && element < PT_NUM)
|
||||||
{
|
{
|
||||||
lua_el_func[element] = function;
|
lua_el_func[element] = function;
|
||||||
if(replace)
|
if (replace == 2)
|
||||||
lua_el_mode[element] = 2;
|
lua_el_mode[element] = 3; //update before
|
||||||
|
else if (replace)
|
||||||
|
lua_el_mode[element] = 2; //replace
|
||||||
else
|
else
|
||||||
lua_el_mode[element] = 1;
|
lua_el_mode[element] = 1; //update after
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -2381,19 +2381,21 @@ int LuaScriptInterface::elements_property(lua_State * l)
|
|||||||
{
|
{
|
||||||
if(lua_type(l, 3) == LUA_TFUNCTION)
|
if(lua_type(l, 3) == LUA_TFUNCTION)
|
||||||
{
|
{
|
||||||
lua_pushvalue(l, 3);
|
|
||||||
lua_el_func[id] = luaL_ref(l, LUA_REGISTRYINDEX);
|
|
||||||
if (args > 3)
|
if (args > 3)
|
||||||
{
|
{
|
||||||
luaL_checktype(l, 4, LUA_TNUMBER);
|
luaL_checktype(l, 4, LUA_TNUMBER);
|
||||||
int replace = lua_tointeger(l, 4);
|
int replace = lua_tointeger(l, 4);
|
||||||
if (replace == 1)
|
if (replace == 2)
|
||||||
lua_el_mode[id] = 2;
|
lua_el_mode[id] = 3; //update before
|
||||||
|
else if (replace == 1)
|
||||||
|
lua_el_mode[id] = 2; //replace
|
||||||
else
|
else
|
||||||
lua_el_mode[id] = 1;
|
lua_el_mode[id] = 1; //update after
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
lua_el_mode[id] = 1;
|
lua_el_mode[id] = 1;
|
||||||
|
lua_pushvalue(l, 3);
|
||||||
|
lua_el_func[id] = luaL_ref(l, LUA_REGISTRYINDEX);
|
||||||
}
|
}
|
||||||
else if(lua_type(l, 3) == LUA_TBOOLEAN && !lua_toboolean(l, 3))
|
else if(lua_type(l, 3) == LUA_TBOOLEAN && !lua_toboolean(l, 3))
|
||||||
{
|
{
|
||||||
|
@ -3817,6 +3817,15 @@ void Simulation::UpdateParticles(int start, int end)
|
|||||||
|
|
||||||
//call the particle update function, if there is one
|
//call the particle update function, if there is one
|
||||||
#if !defined(RENDERER) && defined(LUACONSOLE)
|
#if !defined(RENDERER) && defined(LUACONSOLE)
|
||||||
|
if (lua_el_mode[parts[i].type] == 3)
|
||||||
|
{
|
||||||
|
if (luacon_elementReplacement(this, i, x, y, surround_space, nt, parts, pmap) || t != parts[i].type)
|
||||||
|
continue;
|
||||||
|
// Need to update variables, in case they've been changed by Lua
|
||||||
|
x = (int)(parts[i].x+0.5f);
|
||||||
|
y = (int)(parts[i].y+0.5f);
|
||||||
|
}
|
||||||
|
|
||||||
if (elements[t].Update && lua_el_mode[t] != 2)
|
if (elements[t].Update && lua_el_mode[t] != 2)
|
||||||
#else
|
#else
|
||||||
if (elements[t].Update)
|
if (elements[t].Update)
|
||||||
@ -3832,9 +3841,9 @@ void Simulation::UpdateParticles(int start, int end)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#if !defined(RENDERER) && defined(LUACONSOLE)
|
#if !defined(RENDERER) && defined(LUACONSOLE)
|
||||||
if(lua_el_mode[t])
|
if (lua_el_mode[parts[i].type] && lua_el_mode[parts[i].type] != 3)
|
||||||
{
|
{
|
||||||
if(luacon_elementReplacement(this, i, x, y, surround_space, nt, parts, pmap))
|
if (luacon_elementReplacement(this, i, x, y, surround_space, nt, parts, pmap) || t != parts[i].type)
|
||||||
continue;
|
continue;
|
||||||
// Need to update variables, in case they've been changed by Lua
|
// Need to update variables, in case they've been changed by Lua
|
||||||
x = (int)(parts[i].x+0.5f);
|
x = (int)(parts[i].x+0.5f);
|
||||||
|
@ -102,6 +102,7 @@ int Element_TUNG::update(UPDATE_FUNC_ARGS)
|
|||||||
{
|
{
|
||||||
sim->part_change_type(i,x,y,PT_BRMT);
|
sim->part_change_type(i,x,y,PT_BRMT);
|
||||||
parts[i].ctype = PT_TUNG;
|
parts[i].ctype = PT_TUNG;
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user