added functions to iterate through all particles
+ tpt.start_getPartIndex() --starts the iteration + bool tpt.next_getPartIndex() --increases the iteration, returns true if there are more particles to iterate through + int tpt.getPartIndex() --get the current iteration value
This commit is contained in:
parent
87513503ba
commit
be79233101
@ -19,6 +19,8 @@ char *luacon_geterror();
|
||||
void luacon_close();
|
||||
int process_command_lua(pixel *vid_buf, char *console, char *console_error);
|
||||
|
||||
int getPartIndex_curIdx;
|
||||
|
||||
//TPT Interface
|
||||
int luatpt_test(lua_State* l);
|
||||
int luatpt_drawtext(lua_State* l);
|
||||
@ -45,4 +47,8 @@ int luatpt_register_step(lua_State* l);
|
||||
int luatpt_unregister_step(lua_State* l);
|
||||
int luatpt_input(lua_State* l);
|
||||
int luatpt_message_box(lua_State* l);
|
||||
int luatpt_get_numOfParts(lua_State* l);
|
||||
int luatpt_start_getPartIndex(lua_State* l);
|
||||
int luatpt_getPartIndex(lua_State* l);
|
||||
int luatpt_next_getPartIndex(lua_State* l);
|
||||
#endif
|
||||
|
@ -32,6 +32,10 @@ void luacon_open(){
|
||||
{"unregister_step", &luatpt_unregister_step},
|
||||
{"input", &luatpt_input},
|
||||
{"message_box", &luatpt_message_box},
|
||||
{"get_numOfParts", &luatpt_get_numOfParts},
|
||||
{"start_getPartIndex", &luatpt_start_getPartIndex},
|
||||
{"next_getPartIndex", &luatpt_next_getPartIndex},
|
||||
{"getPartIndex", &luatpt_getPartIndex},
|
||||
{NULL,NULL}
|
||||
};
|
||||
|
||||
@ -63,7 +67,7 @@ int luacon_step(int mx, int my, int mb, int mbq, char key){
|
||||
if(lua_isboolean(l, -1)){
|
||||
tempb = lua_toboolean(l, -1);
|
||||
if(tempb){ //Mouse click has been handled, set the global for future calls
|
||||
lua_pushinteger(l, mb);
|
||||
lua_pushinteger(l, mb);
|
||||
lua_setfield(l, LUA_GLOBALSINDEX, "mouseb");
|
||||
}
|
||||
tempret |= tempb;
|
||||
@ -81,7 +85,7 @@ int luacon_eval(char *command){
|
||||
char *luacon_geterror(){
|
||||
char *error = lua_tostring(l, -1);
|
||||
if(error==NULL || !error[0]){
|
||||
error = "failed to execute";
|
||||
error = "failed to execute";
|
||||
}
|
||||
return error;
|
||||
}
|
||||
@ -151,7 +155,7 @@ int luatpt_drawtext(lua_State* l)
|
||||
if (textalpha>255) textalpha = 255;
|
||||
if(vid_buf!=NULL){
|
||||
drawtext(vid_buf, textx, texty, string, textred, textgreen, textblue, textalpha);
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
return luaL_error(l, "Screen buffer does not exist");
|
||||
}
|
||||
@ -177,7 +181,7 @@ int luatpt_create(lua_State* l)
|
||||
retid = create_part(-1, x, y, t);
|
||||
// failing to create a particle often happens (e.g. if space is already occupied) and isn't usually important, so don't raise an error
|
||||
lua_pushinteger(l, retid);
|
||||
return 1;
|
||||
return 1;
|
||||
}
|
||||
return luaL_error(l, "Coordinates out of range (%d,%d)", x, y);
|
||||
}
|
||||
@ -225,12 +229,12 @@ int luatpt_set_pressure(lua_State* l)
|
||||
if(value > 256.0f)
|
||||
value = 256.0f;
|
||||
else if(value < -256.0f)
|
||||
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(y1 > (YRES/CELL)-1)
|
||||
y1 = (YRES/CELL)-1;
|
||||
if(x1+width > (XRES/CELL)-1)
|
||||
width = (XRES/CELL)-x1;
|
||||
if(y1+height > (YRES/CELL)-1)
|
||||
@ -256,12 +260,12 @@ int luatpt_set_gravity(lua_State* l)
|
||||
if(value > 256.0f)
|
||||
value = 256.0f;
|
||||
else if(value < -256.0f)
|
||||
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(y1 > (YRES/CELL)-1)
|
||||
y1 = (YRES/CELL)-1;
|
||||
if(x1+width > (XRES/CELL)-1)
|
||||
width = (XRES/CELL)-x1;
|
||||
if(y1+height > (YRES/CELL)-1)
|
||||
@ -284,8 +288,8 @@ int luatpt_reset_gravity_field(lua_State* l)
|
||||
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(y1 > (YRES/CELL)-1)
|
||||
y1 = (YRES/CELL)-1;
|
||||
if(x1+width > (XRES/CELL)-1)
|
||||
width = (XRES/CELL)-x1;
|
||||
if(y1+height > (YRES/CELL)-1)
|
||||
@ -309,8 +313,8 @@ int luatpt_reset_velocity(lua_State* l)
|
||||
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(y1 > (YRES/CELL)-1)
|
||||
y1 = (YRES/CELL)-1;
|
||||
if(x1+width > (XRES/CELL)-1)
|
||||
width = (XRES/CELL)-x1;
|
||||
if(y1+height > (YRES/CELL)-1)
|
||||
@ -467,8 +471,8 @@ int luatpt_get_property(lua_State* l)
|
||||
int i, y;
|
||||
char *prop;
|
||||
prop = luaL_optstring(l, 1, "");
|
||||
i = abs(luaL_optint(l, 2, 0));
|
||||
y = abs(luaL_optint(l, 3, -1));
|
||||
i = luaL_optint(l, 2, 0);
|
||||
y = luaL_optint(l, 3, -1);
|
||||
if(y!=-1 && y < YRES && y >= 0 && i < XRES && i >= 0){
|
||||
i = pmap[y][i]>>8;
|
||||
if (i >= NPART)
|
||||
@ -746,4 +750,43 @@ int luatpt_message_box(lua_State* l)
|
||||
free(text);
|
||||
return luaL_error(l, "Screen buffer does not exist");;
|
||||
}
|
||||
int luatpt_get_numOfParts(lua_State* l)
|
||||
{
|
||||
lua_pushinteger(l, NUM_PARTS);
|
||||
return 1;
|
||||
}
|
||||
int luatpt_start_getPartIndex(lua_State* l)
|
||||
{
|
||||
getPartIndex_curIdx = -1;
|
||||
return 1;
|
||||
}
|
||||
int luatpt_next_getPartIndex(lua_State* l)
|
||||
{
|
||||
while(1)
|
||||
{
|
||||
getPartIndex_curIdx++;
|
||||
if(getPartIndex_curIdx >= NPART)
|
||||
{
|
||||
getPartIndex_curIdx = 0;
|
||||
lua_pushboolean(l, 0);
|
||||
return 1;
|
||||
}
|
||||
if(parts[getPartIndex_curIdx].type)
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
lua_pushboolean(l, 1);
|
||||
return 1;
|
||||
}
|
||||
int luatpt_getPartIndex(lua_State* l)
|
||||
{
|
||||
if(getPartIndex_curIdx < 0)
|
||||
{
|
||||
lua_pushinteger(l, 0);
|
||||
return 1;
|
||||
}
|
||||
lua_pushinteger(l, getPartIndex_curIdx);
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user