summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2011-11-18 19:38:08 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2011-11-18 19:38:08 (GMT)
commitf50801333214e79492dd72c23f05cd4bc84fcf54 (patch)
tree3b6f934b80c45f1c696c0f8b1ae5f67c743b25b4 /src
parent8a962b2f9605672627c077d2878c03fab53495a4 (diff)
downloadpowder-f50801333214e79492dd72c23f05cd4bc84fcf54.zip
powder-f50801333214e79492dd72c23f05cd4bc84fcf54.tar.gz
New tables in lua API: el and version: element ids and version info respectively. New lua functions: element (get element id from name) and element_func for hooking/overriding element update functions
Diffstat (limited to 'src')
-rw-r--r--src/graphics.c6
-rw-r--r--src/interface.c9
-rw-r--r--src/luaconsole.c92
-rw-r--r--src/powder.c14
4 files changed, 120 insertions, 1 deletions
diff --git a/src/graphics.c b/src/graphics.c
index 039bba3..2f2c367 100644
--- a/src/graphics.c
+++ b/src/graphics.c
@@ -412,6 +412,12 @@ void clearScreen(float alpha)
glClear(GL_COLOR_BUFFER_BIT);
}
+void clearScreenNP(float alpha)
+{
+ glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
+ glClear(GL_COLOR_BUFFER_BIT);
+}
+
void ogl_blit(int x, int y, int w, int h, pixel *src, int pitch, int scale)
{
diff --git a/src/interface.c b/src/interface.c
index b44d1cd..7b83426 100644
--- a/src/interface.c
+++ b/src/interface.c
@@ -5167,6 +5167,10 @@ char *console_ui(pixel *vid_buf,char error[255],char console_more) {
ui_edit_draw(vid_buf, &ed);
ui_edit_process(mx, my, b, &ed);
sdl_blit(0, 0, (XRES+BARSIZE), YRES+MENUSIZE, vid_buf, (XRES+BARSIZE));
+#ifdef OGLR
+ clearScreenNP(1.0f);
+ draw_parts_fbo();
+#endif
if (sdl_key==SDLK_RETURN)
{
currentcommand = malloc(sizeof(command_history));
@@ -6437,7 +6441,10 @@ void render_ui(pixel * vid_buf, int xcoord, int ycoord, int orientation)
}
sdl_blit(0, 0, (XRES+BARSIZE), YRES+MENUSIZE, vid_buf, (XRES+BARSIZE));
-
+#ifdef OGLR
+ clearScreenNP(1.0f);
+ draw_parts_fbo();
+#endif
if (sdl_key==SDLK_RETURN)
break;
if (sdl_key==SDLK_ESCAPE)
diff --git a/src/luaconsole.c b/src/luaconsole.c
index b0b8a53..d0f55d8 100644
--- a/src/luaconsole.c
+++ b/src/luaconsole.c
@@ -11,7 +11,11 @@ int *keypress_functions = NULL;
int mouseclick_function_count = 0;
int *mouseclick_functions = NULL;
int tptProperties; //Table for some TPT properties
+int tptPropertiesVersion;
+int tptElements; //Table for TPT element names
void luacon_open(){
+ int i = 0, j;
+ char tmpname[12];
const static struct luaL_reg tptluaapi [] = {
{"test", &luatpt_test},
{"drawtext", &luatpt_drawtext},
@@ -66,6 +70,8 @@ void luacon_open(){
{"setwindowsize",&luatpt_setwindowsize},
{"watertest",&luatpt_togglewater},
{"screenshot",&luatpt_screenshot},
+ {"element",&luatpt_getelement},
+ {"element_func",&luatpt_element_func},
{NULL,NULL}
};
@@ -83,6 +89,42 @@ void luacon_open(){
lua_setfield(l, tptProperties, "selectedl");
lua_pushinteger(l, 0);
lua_setfield(l, tptProperties, "selectedr");
+
+ lua_newtable(l);
+ tptPropertiesVersion = lua_gettop(l);
+ lua_pushinteger(l, SAVE_VERSION);
+ lua_setfield(l, tptPropertiesVersion, "major");
+ lua_pushinteger(l, MINOR_VERSION);
+ lua_setfield(l, tptPropertiesVersion, "minor");
+ lua_pushinteger(l, BUILD_NUM);
+ lua_setfield(l, tptPropertiesVersion, "build");
+ lua_setfield(l, tptProperties, "version");
+
+ lua_newtable(l);
+ tptElements = lua_gettop(l);
+ lua_pushinteger(l, PT_NONE);
+ lua_setfield(l, tptElements, "none");
+ lua_pushinteger(l, PT_PLEX);
+ lua_setfield(l, tptElements, "c4");
+ lua_pushinteger(l, PT_C5);
+ lua_setfield(l, tptElements, "c5");
+ for(i = 1; i < PT_NUM; i++)
+ {
+ for(j = 0; j < strlen(ptypes[i].name); j++)
+ tmpname[j] = tolower(ptypes[i].name[j]);
+ tmpname[strlen(ptypes[i].name)] = 0;
+ lua_pushinteger(l, i);
+ lua_setfield(l, tptElements, tmpname);
+ }
+ lua_setfield(l, tptProperties, "el");
+ //lua_setglobal(l, "pel");
+
+ lua_el_func = calloc(PT_NUM, sizeof(int));
+ lua_el_mode = calloc(PT_NUM, sizeof(int));
+ for(i = 0; i < PT_NUM; i++)
+ {
+ lua_el_mode[i] = 0;
+ }
}
int luacon_keyevent(int key, int modifier, int event){
int i = 0, kpcontinue = 1;
@@ -151,6 +193,24 @@ int luacon_step(int mx, int my, int selectl, int selectr){
int luacon_eval(char *command){
return luaL_dostring (l, command);
}
+int luacon_part_update(int t, int i, int x, int y, int surround_space, int nt)
+{
+ int retval = 0;
+ if(lua_el_func[t]){
+ lua_rawgeti(l, LUA_REGISTRYINDEX, lua_el_func[t]);
+ lua_pushinteger(l, i);
+ lua_pushinteger(l, x);
+ lua_pushinteger(l, y);
+ lua_pushinteger(l, surround_space);
+ lua_pushinteger(l, nt);
+ lua_pcall(l, 5, 1, 0);
+ if(lua_isboolean(l, -1)){
+ retval = lua_toboolean(l, -1);
+ }
+ lua_pop(l, 1);
+ }
+ return retval;
+}
char *luacon_geterror(){
char *error = lua_tostring(l, -1);
if(error==NULL || !error[0]){
@@ -201,6 +261,38 @@ int luatpt_test(lua_State* l)
printf("Test successful, got %d\n", testint);
return 0;
}
+int luatpt_getelement(lua_State *l)
+{
+ int t;
+ char * name = luaL_optstring(l, 1, "dust");
+ if (!console_parse_type(name, &t, NULL))
+ return luaL_error(l,"Unrecognised element '%s'", name);
+ lua_pushinteger(l, t);
+ return 1;
+}
+int luatpt_element_func(lua_State *l)
+{
+ if(lua_isfunction(l, 1))
+ {
+ int element = luaL_optint(l, 2, 0);
+ int replace = luaL_optint(l, 3, 0);
+ int function = luaL_ref(l, LUA_REGISTRYINDEX);
+ if(element > 0 && element < PT_NUM)
+ {
+ lua_el_func[element] = function;
+ if(replace)
+ lua_el_mode[element] = 2;
+ else
+ lua_el_mode[element] = 1;
+ return 0;
+ }
+ else
+ {
+ return luaL_error(l, "Invalid element");
+ }
+ }
+ return 0;
+}
int luatpt_error(lua_State* l)
{
char *error = "";
diff --git a/src/powder.c b/src/powder.c
index c8c2ef4..fe25750 100644
--- a/src/powder.c
+++ b/src/powder.c
@@ -4,6 +4,9 @@
#include <powder.h>
#include <air.h>
#include <misc.h>
+#ifdef LUACONSOLE
+#include <luaconsole.h>
+#endif
int gravwl_timeout = 0;
@@ -2094,11 +2097,22 @@ void update_particles_i(pixel *vid, int start, int inc)
}
//call the particle update function, if there is one
+#ifdef LUACONSOLE
+ if (ptypes[t].update_func && lua_el_mode[t] != 2)
+#else
if (ptypes[t].update_func)
+#endif
{
if ((*(ptypes[t].update_func))(i,x,y,surround_space,nt))
continue;
}
+#ifdef LUACONSOLE
+ if(lua_el_mode[t])
+ {
+ if(luacon_part_update(t,i,x,y,surround_space,nt))
+ continue;
+ }
+#endif
if (legacy_enable)//if heat sim is off
update_legacy_all(i,x,y,surround_space,nt);