custom graphics functions with lua (not finished yet)
This commit is contained in:
parent
f49f4ea241
commit
5edd224344
@ -40,7 +40,7 @@
|
|||||||
#define LUACON_EL_MODIFIED_GRAPHICS 0x2
|
#define LUACON_EL_MODIFIED_GRAPHICS 0x2
|
||||||
#define LUACON_EL_MODIFIED_MENUS 0x4
|
#define LUACON_EL_MODIFIED_MENUS 0x4
|
||||||
|
|
||||||
int *lua_el_func, *lua_el_mode;
|
int *lua_el_func, *lua_el_mode, *lua_gr_func;
|
||||||
|
|
||||||
void luacon_open();
|
void luacon_open();
|
||||||
int luacon_step(int mx, int my, int selectl, int selectr);
|
int luacon_step(int mx, int my, int selectl, int selectr);
|
||||||
@ -48,6 +48,7 @@ int luacon_mouseevent(int mx, int my, int mb, int event);
|
|||||||
int luacon_keyevent(int key, int modifier, int event);
|
int luacon_keyevent(int key, int modifier, int event);
|
||||||
int luacon_eval(char *command);
|
int luacon_eval(char *command);
|
||||||
int luacon_part_update(int t, int i, int x, int y, int surround_space, int nt);
|
int luacon_part_update(int t, int i, int x, int y, int surround_space, int nt);
|
||||||
|
int luacon_graphics_update(int t, int i);
|
||||||
char *luacon_geterror();
|
char *luacon_geterror();
|
||||||
void luacon_close();
|
void luacon_close();
|
||||||
int luacon_partsread(lua_State* l);
|
int luacon_partsread(lua_State* l);
|
||||||
@ -70,6 +71,7 @@ int getPartIndex_curIdx;
|
|||||||
int luatpt_test(lua_State* l);
|
int luatpt_test(lua_State* l);
|
||||||
int luatpt_getelement(lua_State *l);
|
int luatpt_getelement(lua_State *l);
|
||||||
int luatpt_element_func(lua_State *l);
|
int luatpt_element_func(lua_State *l);
|
||||||
|
int luatpt_graphics_func(lua_State *l);
|
||||||
int luatpt_drawtext(lua_State* l);
|
int luatpt_drawtext(lua_State* l);
|
||||||
int luatpt_create(lua_State* l);
|
int luatpt_create(lua_State* l);
|
||||||
int luatpt_setpause(lua_State* l);
|
int luatpt_setpause(lua_State* l);
|
||||||
|
@ -47,6 +47,9 @@
|
|||||||
#include <font.h>
|
#include <font.h>
|
||||||
#include <misc.h>
|
#include <misc.h>
|
||||||
#include "hmap.h"
|
#include "hmap.h"
|
||||||
|
#ifdef LUACONSOLE
|
||||||
|
#include <luaconsole.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(LIN32) || defined(LIN64)
|
#if defined(LIN32) || defined(LIN64)
|
||||||
#include "icon.h"
|
#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
|
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)
|
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
|
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;
|
graphicscache[t].isready = 1;
|
||||||
|
@ -96,6 +96,7 @@ void luacon_open(){
|
|||||||
{"screenshot",&luatpt_screenshot},
|
{"screenshot",&luatpt_screenshot},
|
||||||
{"element",&luatpt_getelement},
|
{"element",&luatpt_getelement},
|
||||||
{"element_func",&luatpt_element_func},
|
{"element_func",&luatpt_element_func},
|
||||||
|
{"graphics_func",&luatpt_graphics_func},
|
||||||
{NULL,NULL}
|
{NULL,NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -213,11 +214,13 @@ tpt.partsdata = nil");
|
|||||||
}
|
}
|
||||||
lua_setfield(l, tptProperties, "eltransition");
|
lua_setfield(l, tptProperties, "eltransition");
|
||||||
|
|
||||||
lua_el_func = calloc(PT_NUM, sizeof(int));
|
lua_el_func = (int*)calloc(PT_NUM, sizeof(int));
|
||||||
lua_el_mode = 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++)
|
for(i = 0; i < PT_NUM; i++)
|
||||||
{
|
{
|
||||||
lua_el_mode[i] = 0;
|
lua_el_mode[i] = 0;
|
||||||
|
lua_gr_func[i] = 0;
|
||||||
}
|
}
|
||||||
lua_sethook(l, &lua_hook, LUA_MASKCOUNT, 4000000);
|
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;
|
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 *luacon_geterror(){
|
||||||
char *error = lua_tostring(l, -1);
|
char *error = lua_tostring(l, -1);
|
||||||
if(error==NULL || !error[0]){
|
if(error==NULL || !error[0]){
|
||||||
@ -869,6 +886,29 @@ int luatpt_element_func(lua_State *l)
|
|||||||
}
|
}
|
||||||
return 0;
|
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)
|
int luatpt_error(lua_State* l)
|
||||||
{
|
{
|
||||||
char *error = "";
|
char *error = "";
|
||||||
|
Reference in New Issue
Block a user