mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-08-18 22:21:21 +02:00
add back sim.partNeighbors + some alternate spellings
This commit is contained in:
@@ -438,6 +438,7 @@ void LuaScriptInterface::initSimulationAPI()
|
|||||||
//Methods
|
//Methods
|
||||||
struct luaL_reg simulationAPIMethods [] = {
|
struct luaL_reg simulationAPIMethods [] = {
|
||||||
{"partNeighbours", simulation_partNeighbours},
|
{"partNeighbours", simulation_partNeighbours},
|
||||||
|
{"partNeighbors", simulation_partNeighbours},
|
||||||
{"partChangeType", simulation_partChangeType},
|
{"partChangeType", simulation_partChangeType},
|
||||||
{"partCreate", simulation_partCreate},
|
{"partCreate", simulation_partCreate},
|
||||||
{"partProperty", simulation_partProperty},
|
{"partProperty", simulation_partProperty},
|
||||||
@@ -479,10 +480,13 @@ void LuaScriptInterface::initSimulationAPI()
|
|||||||
{"gravityMode", simulation_gravityMode},
|
{"gravityMode", simulation_gravityMode},
|
||||||
{"airMode", simulation_airMode},
|
{"airMode", simulation_airMode},
|
||||||
{"waterEqualisation", simulation_waterEqualisation},
|
{"waterEqualisation", simulation_waterEqualisation},
|
||||||
|
{"waterEqualization", simulation_waterEqualisation},
|
||||||
{"ambientAirTemp", simulation_ambientAirTemp},
|
{"ambientAirTemp", simulation_ambientAirTemp},
|
||||||
{"elementCount", simulation_elementCount},
|
{"elementCount", simulation_elementCount},
|
||||||
{"parts", simulation_parts},
|
{"parts", simulation_parts},
|
||||||
{"pmap", simulation_pmap},
|
{"pmap", simulation_pmap},
|
||||||
|
{"neighbours", simulation_neighbours},
|
||||||
|
{"neighbors", simulation_neighbours},
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
luaL_register(l, "simulation", simulationAPIMethods);
|
luaL_register(l, "simulation", simulationAPIMethods);
|
||||||
@@ -556,54 +560,41 @@ void LuaScriptInterface::set_map(int x, int y, int width, int height, float valu
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int NeighboursClosure(lua_State * l)
|
|
||||||
{
|
|
||||||
int rx=lua_tointeger(l, lua_upvalueindex(1));
|
|
||||||
int ry=lua_tointeger(l, lua_upvalueindex(2));
|
|
||||||
int sx=lua_tointeger(l, lua_upvalueindex(3));
|
|
||||||
int sy=lua_tointeger(l, lua_upvalueindex(4));
|
|
||||||
int x=lua_tointeger(l, lua_upvalueindex(5));
|
|
||||||
int y=lua_tointeger(l, lua_upvalueindex(6));
|
|
||||||
int i;
|
|
||||||
do
|
|
||||||
{
|
|
||||||
x++;
|
|
||||||
if(x>rx)
|
|
||||||
{
|
|
||||||
x=-rx;
|
|
||||||
y++;
|
|
||||||
if(y>ry)
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
if(sx+x<0 || sy+y<0 || sx+x>=XRES*CELL || sy+y>=YRES*CELL)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
i=luacon_sim->pmap[y+sx][x+sx];
|
|
||||||
} while(!i&0xFF);
|
|
||||||
lua_pushnumber(l, x);
|
|
||||||
lua_replace(l, lua_upvalueindex(5));
|
|
||||||
lua_pushnumber(l, y);
|
|
||||||
lua_replace(l, lua_upvalueindex(6));
|
|
||||||
lua_pushnumber(l, i>>8);
|
|
||||||
lua_pushnumber(l, x+sx);
|
|
||||||
lua_pushnumber(l, y+sy);
|
|
||||||
return 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
int LuaScriptInterface::simulation_partNeighbours(lua_State * l)
|
int LuaScriptInterface::simulation_partNeighbours(lua_State * l)
|
||||||
{
|
{
|
||||||
int x=luaL_checkint(l, 1);
|
lua_newtable(l);
|
||||||
int y=luaL_checkint(l, 2);
|
int id = 0;
|
||||||
int rx=luaL_optint(l, 3, 2);
|
if(lua_gettop(l) == 4)
|
||||||
int ry=luaL_optint(l, 4, 2);
|
{
|
||||||
lua_pushnumber(l, rx);
|
int x = lua_tointeger(l, 1), y = lua_tointeger(l, 2), r = lua_tointeger(l, 3), t = lua_tointeger(l, 4), rx, ry, n;
|
||||||
lua_pushnumber(l, ry);
|
for (rx = -r; rx <= r; rx++)
|
||||||
lua_pushnumber(l, x);
|
for (ry = -r; ry <= r; ry++)
|
||||||
lua_pushnumber(l, y);
|
if (x+rx >= 0 && y+ry >= 0 && x+rx < XRES && y+ry < YRES && (rx || ry))
|
||||||
lua_pushnumber(l, -rx-1);
|
{
|
||||||
lua_pushnumber(l, -ry);
|
n = luacon_sim->pmap[y+ry][x+rx];
|
||||||
lua_pushcclosure(l, NeighboursClosure, 6);
|
if(n && (n&0xFF) == t)
|
||||||
|
{
|
||||||
|
lua_pushinteger(l, n>>8);
|
||||||
|
lua_rawseti(l, -2, id++);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int x = lua_tointeger(l, 1), y = lua_tointeger(l, 2), r = lua_tointeger(l, 3), rx, ry, n;
|
||||||
|
for (rx = -r; rx <= r; rx++)
|
||||||
|
for (ry = -r; ry <= r; ry++)
|
||||||
|
if (x+rx >= 0 && y+ry >= 0 && x+rx < XRES && y+ry < YRES && (rx || ry))
|
||||||
|
{
|
||||||
|
n = luacon_sim->pmap[y+ry][x+rx];
|
||||||
|
if(n)
|
||||||
|
{
|
||||||
|
lua_pushinteger(l, n>>8);
|
||||||
|
lua_rawseti(l, -2, id++);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1557,6 +1548,58 @@ int LuaScriptInterface::simulation_pmap(lua_State * l)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int NeighboursClosure(lua_State * l)
|
||||||
|
{
|
||||||
|
int rx=lua_tointeger(l, lua_upvalueindex(1));
|
||||||
|
int ry=lua_tointeger(l, lua_upvalueindex(2));
|
||||||
|
int sx=lua_tointeger(l, lua_upvalueindex(3));
|
||||||
|
int sy=lua_tointeger(l, lua_upvalueindex(4));
|
||||||
|
int x=lua_tointeger(l, lua_upvalueindex(5));
|
||||||
|
int y=lua_tointeger(l, lua_upvalueindex(6));
|
||||||
|
int i = 0;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
x++;
|
||||||
|
if(x>rx)
|
||||||
|
{
|
||||||
|
x=-rx;
|
||||||
|
y++;
|
||||||
|
if(y>ry)
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if(!(x && y) || sx+x<0 || sy+y<0 || sx+x>=XRES*CELL || sy+y>=YRES*CELL)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
i=luacon_sim->pmap[y+sx][x+sx];
|
||||||
|
} while(!i&0xFF);
|
||||||
|
lua_pushnumber(l, x);
|
||||||
|
lua_replace(l, lua_upvalueindex(5));
|
||||||
|
lua_pushnumber(l, y);
|
||||||
|
lua_replace(l, lua_upvalueindex(6));
|
||||||
|
lua_pushnumber(l, i>>8);
|
||||||
|
lua_pushnumber(l, x+sx);
|
||||||
|
lua_pushnumber(l, y+sy);
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
int LuaScriptInterface::simulation_neighbours(lua_State * l)
|
||||||
|
{
|
||||||
|
int x=luaL_checkint(l, 1);
|
||||||
|
int y=luaL_checkint(l, 2);
|
||||||
|
int rx=luaL_optint(l, 3, 2);
|
||||||
|
int ry=luaL_optint(l, 4, 2);
|
||||||
|
lua_pushnumber(l, rx);
|
||||||
|
lua_pushnumber(l, ry);
|
||||||
|
lua_pushnumber(l, x);
|
||||||
|
lua_pushnumber(l, y);
|
||||||
|
lua_pushnumber(l, -rx-1);
|
||||||
|
lua_pushnumber(l, -ry);
|
||||||
|
lua_pushcclosure(l, NeighboursClosure, 6);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
//// Begin Renderer API
|
//// Begin Renderer API
|
||||||
|
|
||||||
void LuaScriptInterface::initRendererAPI()
|
void LuaScriptInterface::initRendererAPI()
|
||||||
|
@@ -103,6 +103,7 @@ class LuaScriptInterface: public CommandInterface
|
|||||||
static int simulation_elementCount(lua_State * l);
|
static int simulation_elementCount(lua_State * l);
|
||||||
static int simulation_parts(lua_State * l);
|
static int simulation_parts(lua_State * l);
|
||||||
static int simulation_pmap(lua_State * l);
|
static int simulation_pmap(lua_State * l);
|
||||||
|
static int simulation_neighbours(lua_State * l);
|
||||||
|
|
||||||
//Renderer
|
//Renderer
|
||||||
void initRendererAPI();
|
void initRendererAPI();
|
||||||
|
Reference in New Issue
Block a user