summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJacob1 <jfu614@gmail.com>2012-05-24 17:08:55 (GMT)
committer Jacob1 <jfu614@gmail.com>2012-05-24 17:08:55 (GMT)
commit5edd224344b427f75f0740217e10cb4e44313a5d (patch)
tree740c6b6833b30d26daa161f70177e99c03ccb950 /src
parentf49f4ea2413464ebdfac6ee0be32c1b282839c63 (diff)
downloadpowder-5edd224344b427f75f0740217e10cb4e44313a5d.zip
powder-5edd224344b427f75f0740217e10cb4e44313a5d.tar.gz
custom graphics functions with lua (not finished yet)
Diffstat (limited to 'src')
-rw-r--r--src/graphics.c12
-rw-r--r--src/luaconsole.c44
2 files changed, 54 insertions, 2 deletions
diff --git a/src/graphics.c b/src/graphics.c
index c47c44e..60d23b0 100644
--- a/src/graphics.c
+++ b/src/graphics.c
@@ -47,6 +47,9 @@
#include <font.h>
#include <misc.h>
#include "hmap.h"
+#ifdef LUACONSOLE
+#include <luaconsole.h>
+#endif
#if defined(LIN32) || defined(LIN64)
#include "icon.h"
@@ -1854,8 +1857,17 @@ void render_parts(pixel *vid)
}
else if(!(colour_mode & COLOUR_BASC)) //Don't get special effects for BASIC colour mode
{
+#ifdef LUACONSOLE
+ if (lua_gr_func[t])
+ {
+ colr = luacon_graphics_update(t,i);
+ }
+ else if (ptypes[t].graphics_func)
+ {
+#else
if (ptypes[t].graphics_func)
{
+#endif
if ((*(ptypes[t].graphics_func))(&(parts[i]), nx, ny, &pixel_mode, &cola, &colr, &colg, &colb, &firea, &firer, &fireg, &fireb)) //That's a lot of args, a struct might be better
{
graphicscache[t].isready = 1;
diff --git a/src/luaconsole.c b/src/luaconsole.c
index e0aab5f..46168af 100644
--- a/src/luaconsole.c
+++ b/src/luaconsole.c
@@ -96,6 +96,7 @@ void luacon_open(){
{"screenshot",&luatpt_screenshot},
{"element",&luatpt_getelement},
{"element_func",&luatpt_element_func},
+ {"graphics_func",&luatpt_graphics_func},
{NULL,NULL}
};
@@ -213,11 +214,13 @@ tpt.partsdata = nil");
}
lua_setfield(l, tptProperties, "eltransition");
- lua_el_func = calloc(PT_NUM, sizeof(int));
- lua_el_mode = calloc(PT_NUM, sizeof(int));
+ lua_el_func = (int*)calloc(PT_NUM, sizeof(int));
+ lua_el_mode = (int*)calloc(PT_NUM, sizeof(int));
+ lua_gr_func = (int*)calloc(PT_NUM, sizeof(int));
for(i = 0; i < PT_NUM; i++)
{
lua_el_mode[i] = 0;
+ lua_gr_func[i] = 0;
}
lua_sethook(l, &lua_hook, LUA_MASKCOUNT, 4000000);
}
@@ -785,6 +788,20 @@ int luacon_part_update(int t, int i, int x, int y, int surround_space, int nt)
}
return retval;
}
+int luacon_graphics_update(int t, int i)
+{
+ int retval = 0;
+ if(lua_gr_func[t]){
+ lua_rawgeti(l, LUA_REGISTRYINDEX, lua_gr_func[t]);
+ lua_pushinteger(l, i);
+ lua_pcall(l, 1, 1, 0);
+ if(lua_isnumber(l, -1)){
+ retval = (int)lua_tonumber(l, -1);
+ }
+ lua_pop(l, 1);
+ }
+ return retval;
+}
char *luacon_geterror(){
char *error = lua_tostring(l, -1);
if(error==NULL || !error[0]){
@@ -869,6 +886,29 @@ int luatpt_element_func(lua_State *l)
}
return 0;
}
+int luatpt_graphics_func(lua_State *l)
+{
+ if(lua_isfunction(l, 1))
+ {
+ int element = luaL_optint(l, 2, 0);
+ int function;
+ lua_pushvalue(l, 1);
+ function = luaL_ref(l, LUA_REGISTRYINDEX);
+ if(element > 0 && element < PT_NUM)
+ {
+ lua_gr_func[element] = function;
+ graphicscache[element].isready = 0;
+ return 0;
+ }
+ else
+ {
+ return luaL_error(l, "Invalid element");
+ }
+ }
+ else
+ return luaL_error(l, "Not a function");
+ return 0;
+}
int luatpt_error(lua_State* l)
{
char *error = "";