mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-09-01 04:01:56 +02:00
Add gravity field manipulation to Lua api, move gravity processing to after the particle update (Means a delay of 1 frame, but we get the ability to manipulate the field with Lua)
This commit is contained in:
@@ -10,5 +10,9 @@ function do_step()
|
||||
end
|
||||
tpt.drawtext(numberthing, 50, "Oh my god, this is amazing", 255, 255, 255, 255)
|
||||
tpt.drawtext(mousex, mousey, "Oh my god, this is amazing", 255, 255, 255, 255)
|
||||
return true
|
||||
tpt.reset_velocity(10, 10, 20, 20)
|
||||
tpt.reset_gravity_field(10, 10, 20, 20)
|
||||
tpt.set_pressure(10, 10, 20, 20)
|
||||
tpt.set_gravity(75, 45, 1, 1, 8)
|
||||
return false
|
||||
end
|
||||
|
@@ -21,7 +21,9 @@ int luatpt_setpause(lua_State* l);
|
||||
int luatpt_togglepause(lua_State* l);
|
||||
int luatpt_setconsole(lua_State* l);
|
||||
int luatpt_log(lua_State* l);
|
||||
int luatpt_reset_pressure(lua_State* l);
|
||||
int luatpt_set_pressure(lua_State* l);
|
||||
int luatpt_set_gravity(lua_State* l);
|
||||
int luatpt_reset_gravity_field(lua_State* l);
|
||||
int luatpt_reset_velocity(lua_State* l);
|
||||
int luatpt_reset_spark(lua_State* l);
|
||||
int luatpt_set_property(lua_State* l);
|
||||
|
@@ -14,7 +14,9 @@ void luacon_open(){
|
||||
{"toggle_pause", &luatpt_togglepause},
|
||||
{"set_console", &luatpt_setconsole},
|
||||
{"log", &luatpt_log},
|
||||
{"reset_pressure", &luatpt_reset_pressure},
|
||||
{"set_pressure", &luatpt_set_pressure},
|
||||
{"set_gravity", &luatpt_set_gravity},
|
||||
{"reset_gravity_field", &luatpt_reset_gravity_field},
|
||||
{"reset_velocity", &luatpt_reset_velocity},
|
||||
{"reset_spark", &luatpt_reset_spark},
|
||||
{"set_property", &luatpt_set_property},
|
||||
@@ -35,6 +37,7 @@ void luacon_open(){
|
||||
luaL_openlib(l, "tpt", tptluaapi, 0);
|
||||
}
|
||||
int luacon_step(int mx, int my, int mb, int mbq, char key){
|
||||
int tempret = 0;
|
||||
if(step_function && step_function[0]){
|
||||
//Set mouse globals
|
||||
lua_pushinteger(l, mbq);
|
||||
@@ -46,8 +49,12 @@ int luacon_step(int mx, int my, int mb, int mbq, char key){
|
||||
lua_setfield(l, LUA_GLOBALSINDEX, "mouseb");
|
||||
lua_setfield(l, LUA_GLOBALSINDEX, "mousebq");
|
||||
lua_getfield(l, LUA_GLOBALSINDEX, step_function);
|
||||
lua_call(l, 0, 0);
|
||||
return lua_toboolean(l, -1);
|
||||
lua_call(l, 0, 1);
|
||||
if(lua_isboolean(l, -1)){
|
||||
tempret = lua_toboolean(l, -1);
|
||||
lua_pop(l, 1);
|
||||
return tempret;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -171,7 +178,7 @@ int luatpt_log(lua_State* l)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int luatpt_reset_pressure(lua_State* l)
|
||||
int luatpt_set_pressure(lua_State* l)
|
||||
{
|
||||
int nx, ny;
|
||||
int x1, y1, width, height;
|
||||
@@ -202,6 +209,62 @@ int luatpt_reset_pressure(lua_State* l)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int luatpt_set_gravity(lua_State* l)
|
||||
{
|
||||
int nx, ny;
|
||||
int x1, y1, width, height;
|
||||
float value;
|
||||
x1 = abs(luaL_optint(l, 1, 0));
|
||||
y1 = abs(luaL_optint(l, 2, 0));
|
||||
width = abs(luaL_optint(l, 3, XRES/CELL));
|
||||
height = abs(luaL_optint(l, 4, YRES/CELL));
|
||||
value = (float)luaL_optint(l, 5, 0.0f);
|
||||
if(value > 256.0f)
|
||||
value = 256.0f;
|
||||
else if(value < -256.0f)
|
||||
value = -256.0f;
|
||||
|
||||
if(x1 > (XRES/CELL)-1)
|
||||
x1 = (XRES/CELL)-1;
|
||||
if(y1 > (YRES/CELL)-1)
|
||||
y1 = (YRES/CELL)-1;
|
||||
if(x1+width > (XRES/CELL)-1)
|
||||
width = (XRES/CELL)-x1;
|
||||
if(y1+height > (YRES/CELL)-1)
|
||||
height = (YRES/CELL)-y1;
|
||||
for (nx = x1; nx<x1+width; nx++)
|
||||
for (ny = y1; ny<y1+height; ny++)
|
||||
{
|
||||
gravmap[ny][nx] = value;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int luatpt_reset_gravity_field(lua_State* l)
|
||||
{
|
||||
int nx, ny;
|
||||
int x1, y1, width, height;
|
||||
x1 = abs(luaL_optint(l, 1, 0));
|
||||
y1 = abs(luaL_optint(l, 2, 0));
|
||||
width = abs(luaL_optint(l, 3, XRES/CELL));
|
||||
height = abs(luaL_optint(l, 4, YRES/CELL));
|
||||
if(x1 > (XRES/CELL)-1)
|
||||
x1 = (XRES/CELL)-1;
|
||||
if(y1 > (YRES/CELL)-1)
|
||||
y1 = (YRES/CELL)-1;
|
||||
if(x1+width > (XRES/CELL)-1)
|
||||
width = (XRES/CELL)-x1;
|
||||
if(y1+height > (YRES/CELL)-1)
|
||||
height = (YRES/CELL)-y1;
|
||||
for (nx = x1; nx<x1+width; nx++)
|
||||
for (ny = y1; ny<y1+height; ny++)
|
||||
{
|
||||
gravx[ny][nx] = 0;
|
||||
gravy[ny][nx] = 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int luatpt_reset_velocity(lua_State* l)
|
||||
{
|
||||
int nx, ny;
|
||||
|
14
src/main.c
14
src/main.c
@@ -1775,7 +1775,13 @@ int main(int argc, char *argv[])
|
||||
bsy = 1180;
|
||||
if (bsy<0)
|
||||
bsy = 0;
|
||||
|
||||
|
||||
if(ngrav_enable)
|
||||
draw_grav(vid_buf);
|
||||
draw_walls(vid_buf);
|
||||
update_particles(vid_buf); //update everything
|
||||
draw_parts(vid_buf); //draw particles
|
||||
|
||||
if(ngrav_enable){
|
||||
pthread_mutex_lock(&gravmutex);
|
||||
result = grav_ready;
|
||||
@@ -1794,12 +1800,6 @@ int main(int argc, char *argv[])
|
||||
|
||||
if (!sys_pause||framerender) //Only update if not paused
|
||||
memset(gravmap, 0, sizeof(gravmap)); //Clear the old gravmap
|
||||
|
||||
if(ngrav_enable)
|
||||
draw_grav(vid_buf);
|
||||
draw_walls(vid_buf);
|
||||
update_particles(vid_buf); //update everything
|
||||
draw_parts(vid_buf); //draw particles
|
||||
|
||||
if (cmode==CM_PERS)
|
||||
{
|
||||
|
Reference in New Issue
Block a user