From d5f58d995e16cdc62a95b719f94ce5d47b598c46 Mon Sep 17 00:00:00 2001 From: Simon Robertshaw Date: Thu, 8 Dec 2011 12:16:50 +0000 Subject: [PATCH 01/14] Directly accessible parts array (no pmap yet) --- includes/luaconsole.h | 6 ++ src/luaconsole.c | 149 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 155 insertions(+) diff --git a/includes/luaconsole.h b/includes/luaconsole.h index bb7c744a7..f116b9f6e 100644 --- a/includes/luaconsole.h +++ b/includes/luaconsole.h @@ -29,8 +29,14 @@ int luacon_eval(char *command); int luacon_part_update(int t, int i, int x, int y, int surround_space, int nt); char *luacon_geterror(); void luacon_close(); +int luacon_partsread(lua_State* l); +int luacon_partswrite(lua_State* l); +int luacon_partread(lua_State* l); +int luacon_partwrite(lua_State* l); int luacon_elementread(lua_State* l); int luacon_elementwrite(lua_State* l); +int luacon_particle_getproperty(char * key, int * format); +int luacon_element_getproperty(char * key, int * format); int process_command_lua(pixel *vid_buf, char *console, char *console_error); int getPartIndex_curIdx; diff --git a/src/luaconsole.c b/src/luaconsole.c index 41270f4c1..cbabc41ef 100644 --- a/src/luaconsole.c +++ b/src/luaconsole.c @@ -13,6 +13,7 @@ int *mouseclick_functions = NULL; int tptProperties; //Table for some TPT properties int tptPropertiesVersion; int tptElements; //Table for TPT element names +int tptParts, tptPartsMeta; void luacon_open(){ int i = 0, j; char tmpname[12]; @@ -100,6 +101,17 @@ void luacon_open(){ lua_setfield(l, tptPropertiesVersion, "build"); lua_setfield(l, tptProperties, "version"); + lua_newtable(l); + tptParts = lua_gettop(l); + lua_newtable(l); + tptPartsMeta = lua_gettop(l); + lua_pushcfunction(l, luacon_partswrite); + lua_setfield(l, tptPartsMeta, "__newindex"); + lua_pushcfunction(l, luacon_partsread); + lua_setfield(l, tptPartsMeta, "__index"); + lua_setmetatable(l, tptParts); + lua_setfield(l, tptProperties, "parts"); + lua_newtable(l); tptElements = lua_gettop(l); /*lua_pushinteger(l, PT_NONE); @@ -143,6 +155,143 @@ void luacon_open(){ lua_el_mode[i] = 0; } } +int luacon_partread(lua_State* l){ + int format, offset; + char * tempstring; + int tempinteger; + float tempfloat; + int i; + char * key = mystrdup(luaL_optstring(l, 2, "")); + offset = luacon_particle_getproperty(key, &format); + + //Get Raw Index value for particle + lua_pushstring(l, "id"); + lua_rawget(l, 1); + + i = lua_tointeger (l, lua_gettop(l)); + + lua_pop(l, 1); + + if(i < 0 || i >= PT_NUM || offset==-1) + { + return luaL_error(l, "Invalid property"); + } + switch(format) + { + case 0: + tempinteger = *((int*)(((void*)&parts[i])+offset)); + lua_pushnumber(l, tempinteger); + break; + case 1: + tempfloat = *((float*)(((void*)&parts[i])+offset)); + lua_pushnumber(l, tempfloat); + break; + } + free(key); + return 1; +} +int luacon_partwrite(lua_State* l){ + int format, offset; + char * tempstring; + int tempinteger; + float tempfloat; + int i; + char * key = mystrdup(luaL_optstring(l, 2, "")); + offset = luacon_particle_getproperty(key, &format); + + //Get Raw Index value for particle + lua_pushstring(l, "id"); + lua_rawget(l, 1); + + i = lua_tointeger (l, lua_gettop(l)); + + lua_pop(l, 1); + + if(i < 0 || i >= PT_NUM || offset==-1) + { + return luaL_error(l, "Invalid property"); + } + switch(format) + { + case 0: + *((int*)(((void*)&parts[i])+offset)) = luaL_optinteger(l, 3, 0); + break; + case 1: + *((float*)(((void*)&parts[i])+offset)) = luaL_optnumber(l, 3, 0); + break; + } + free(key); + return 1; +} +int luacon_partsread(lua_State* l){ + int format, offset; + char * tempstring; + int tempinteger; + float tempfloat; + int i, currentPart, currentPartMeta; + + i = luaL_optinteger(l, 2, 0); + + if(i<0 || i>=NPART) + return luaL_error(l, "Out of range"); + + lua_newtable(l); + currentPart = lua_gettop(l); + lua_newtable(l); + currentPartMeta = lua_gettop(l); + lua_pushinteger(l, i); + lua_setfield(l, currentPart, "id"); + lua_pushcfunction(l, luacon_partwrite); + lua_setfield(l, currentPartMeta, "__newindex"); + lua_pushcfunction(l, luacon_partread); + lua_setfield(l, currentPartMeta, "__index"); + lua_setmetatable(l, currentPart); + return 1; +} +int luacon_partswrite(lua_State* l){ + return luaL_error(l, "Not writable"); +} +int luacon_particle_getproperty(char * key, int * format) +{ + int offset; + if (strcmp(key, "type")==0){ + offset = offsetof(particle, type); + *format = 0; + } else if (strcmp(key, "life")==0){ + offset = offsetof(particle, life); + *format = 0; + } else if (strcmp(key, "ctype")==0){ + offset = offsetof(particle, ctype); + *format = 0; + } else if (strcmp(key, "temp")==0){ + offset = offsetof(particle, temp); + *format = 1; + } else if (strcmp(key, "tmp")==0){ + offset = offsetof(particle, tmp); + *format = 0; + } else if (strcmp(key, "tmp2")==0){ + offset = offsetof(particle, tmp2); + *format = 0; + } else if (strcmp(key, "vy")==0){ + offset = offsetof(particle, vy); + *format = 1; + } else if (strcmp(key, "vx")==0){ + offset = offsetof(particle, vx); + *format = 1; + } else if (strcmp(key, "x")==0){ + offset = offsetof(particle, x); + *format = 1; + } else if (strcmp(key, "y")==0){ + offset = offsetof(particle, y); + *format = 1; + } else if (strcmp(key, "dcolour")==0){ + offset = offsetof(particle, dcolour); + *format = 0; + } else { + offset = -1; + } + return offset; +} int luacon_element_getproperty(char * key, int * format) { int offset; From 274df46a37a6c89e8c9e3443674cb38d6c011c67 Mon Sep 17 00:00:00 2001 From: "chaos.powdertoy.co.uk" Date: Thu, 8 Dec 2011 17:44:55 +0000 Subject: [PATCH 02/14] Test --- includes/defines.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/defines.h b/includes/defines.h index bdf3f8c19..467cb6cef 100644 --- a/includes/defines.h +++ b/includes/defines.h @@ -14,7 +14,7 @@ #define BUILD_NUM 116 //VersionInfoEnd -#define IDENT_VERSION "G" //Change this if you're not Simon! It should be a single letter. +#define IDENT_VERSION "G" //Change this if you're not Simon! It should be a single letter #define MTOS_EXPAND(str) #str #define MTOS(str) MTOS_EXPAND(str) From 1585eda5f0b7b0dee9469b8e841fc7e0bc5b6a9c Mon Sep 17 00:00:00 2001 From: "chaos.powdertoy.co.uk" Date: Thu, 8 Dec 2011 17:48:51 +0000 Subject: [PATCH 03/14] Version Increment --- includes/defines.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/defines.h b/includes/defines.h index 467cb6cef..8dbfca345 100644 --- a/includes/defines.h +++ b/includes/defines.h @@ -9,9 +9,9 @@ //VersionInfoStart #define SAVE_VERSION 69 -#define MINOR_VERSION 0 +#define MINOR_VERSION 1 #define BETA -#define BUILD_NUM 116 +#define BUILD_NUM 119 //VersionInfoEnd #define IDENT_VERSION "G" //Change this if you're not Simon! It should be a single letter From 9dcdccc06693051acb31e8eb5bd1de6a10fbb306 Mon Sep 17 00:00:00 2001 From: Simon Robertshaw Date: Fri, 9 Dec 2011 11:53:19 +0000 Subject: [PATCH 04/14] Fix error in element_func where function was being read as the last parameter --- src/luaconsole.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/luaconsole.c b/src/luaconsole.c index cbabc41ef..d0430ef00 100644 --- a/src/luaconsole.c +++ b/src/luaconsole.c @@ -172,9 +172,12 @@ int luacon_partread(lua_State* l){ lua_pop(l, 1); - if(i < 0 || i >= PT_NUM || offset==-1) + if(i < 0 || i >= NPART || offset==-1) { - return luaL_error(l, "Invalid property"); + if(i < 0 || i >= NPART) + return luaL_error(l, "Out of range"); + else + return luaL_error(l, "Invalid property"); } switch(format) { @@ -207,9 +210,12 @@ int luacon_partwrite(lua_State* l){ lua_pop(l, 1); - if(i < 0 || i >= PT_NUM || offset==-1) + if(i < 0 || i >= NPART || offset==-1) { - return luaL_error(l, "Invalid property"); + if(i < 0 || i >= NPART) + return luaL_error(l, "Out of range"); + else + return luaL_error(l, "Invalid property"); } switch(format) { @@ -626,7 +632,9 @@ int luatpt_element_func(lua_State *l) { int element = luaL_optint(l, 2, 0); int replace = luaL_optint(l, 3, 0); - int function = luaL_ref(l, LUA_REGISTRYINDEX); + int function; + lua_pushvalue(l, 1); + function = luaL_ref(l, LUA_REGISTRYINDEX); if(element > 0 && element < PT_NUM) { lua_el_func[element] = function; From f5a58d14f2df42f5c8710df3f42d611c4c456c1b Mon Sep 17 00:00:00 2001 From: Simon Robertshaw Date: Fri, 9 Dec 2011 12:06:22 +0000 Subject: [PATCH 05/14] Use static table for parts array, Uses a tonne of memory but improves performance a lot. --- src/luaconsole.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/luaconsole.c b/src/luaconsole.c index d0430ef00..a80ba2fbe 100644 --- a/src/luaconsole.c +++ b/src/luaconsole.c @@ -101,7 +101,7 @@ void luacon_open(){ lua_setfield(l, tptPropertiesVersion, "build"); lua_setfield(l, tptProperties, "version"); - lua_newtable(l); + /*lua_newtable(l); tptParts = lua_gettop(l); lua_newtable(l); tptPartsMeta = lua_gettop(l); @@ -110,6 +110,26 @@ void luacon_open(){ lua_pushcfunction(l, luacon_partsread); lua_setfield(l, tptPartsMeta, "__index"); lua_setmetatable(l, tptParts); + lua_setfield(l, tptProperties, "parts");*/ + lua_newtable(l); + tptParts = lua_gettop(l); + for(i = 0; i < NPART; i++) + { + int currentPart, currentPartMeta; + lua_newtable(l); + currentPart = lua_gettop(l); + lua_newtable(l); + currentPartMeta = lua_gettop(l); + lua_pushinteger(l, i); + lua_setfield(l, currentPart, "id"); + lua_pushcfunction(l, luacon_partwrite); + lua_setfield(l, currentPartMeta, "__newindex"); + lua_pushcfunction(l, luacon_partread); + lua_setfield(l, currentPartMeta, "__index"); + lua_setmetatable(l, currentPart); + + lua_rawseti (l, tptParts, i); + } lua_setfield(l, tptProperties, "parts"); lua_newtable(l); From e519aa911bbd869390b65f079ae088d79550fdda Mon Sep 17 00:00:00 2001 From: Simon Robertshaw Date: Fri, 9 Dec 2011 16:30:33 +0000 Subject: [PATCH 06/14] Element transitions also editable now --- includes/luaconsole.h | 3 + src/luaconsole.c | 133 +++++++++++++++++++++++++++++++++++++++--- 2 files changed, 127 insertions(+), 9 deletions(-) diff --git a/includes/luaconsole.h b/includes/luaconsole.h index f116b9f6e..fc5e2c436 100644 --- a/includes/luaconsole.h +++ b/includes/luaconsole.h @@ -35,7 +35,10 @@ int luacon_partread(lua_State* l); int luacon_partwrite(lua_State* l); int luacon_elementread(lua_State* l); int luacon_elementwrite(lua_State* l); +int luacon_transitionread(lua_State* l); +int luacon_transitionwrite(lua_State* l); int luacon_particle_getproperty(char * key, int * format); +int luacon_transition_getproperty(char * key, int * format); int luacon_element_getproperty(char * key, int * format); int process_command_lua(pixel *vid_buf, char *console, char *console_error); diff --git a/src/luaconsole.c b/src/luaconsole.c index a80ba2fbe..0f16bda80 100644 --- a/src/luaconsole.c +++ b/src/luaconsole.c @@ -13,7 +13,7 @@ int *mouseclick_functions = NULL; int tptProperties; //Table for some TPT properties int tptPropertiesVersion; int tptElements; //Table for TPT element names -int tptParts, tptPartsMeta; +int tptParts, tptPartsMeta, tptElementTransitions; void luacon_open(){ int i = 0, j; char tmpname[12]; @@ -134,19 +134,12 @@ void luacon_open(){ 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++) { int currentElementMeta, currentElement; 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_newtable(l); currentElement = lua_gettop(l); @@ -166,7 +159,31 @@ void luacon_open(){ lua_setfield(l, tptElements, tmpname); } lua_setfield(l, tptProperties, "el"); - //lua_setglobal(l, "pel"); + + lua_newtable(l); + tptElementTransitions = lua_gettop(l); + for(i = 1; i < PT_NUM; i++) + { + int currentElementMeta, currentElement; + for(j = 0; j < strlen(ptypes[i].name); j++) + tmpname[j] = tolower(ptypes[i].name[j]); + tmpname[strlen(ptypes[i].name)] = 0; + + lua_newtable(l); + currentElement = lua_gettop(l); + lua_newtable(l); + currentElementMeta = lua_gettop(l); + lua_pushinteger(l, i); + lua_setfield(l, currentElement, "value"); + lua_pushcfunction(l, luacon_transitionwrite); + lua_setfield(l, currentElementMeta, "__newindex"); + lua_pushcfunction(l, luacon_transitionread); + lua_setfield(l, currentElementMeta, "__index"); + lua_setmetatable(l, currentElement); + + lua_setfield(l, tptElementTransitions, tmpname); + } + lua_setfield(l, tptProperties, "eltransition"); lua_el_func = calloc(PT_NUM, sizeof(int)); lua_el_mode = calloc(PT_NUM, sizeof(int)); @@ -318,6 +335,104 @@ int luacon_particle_getproperty(char * key, int * format) } return offset; } +int luacon_transition_getproperty(char * key, int * format) +{ + int offset; + if (strcmp(key, "presHighValue")==0){ + offset = offsetof(part_transition, phv); + *format = 1; + } else if (strcmp(key, "presHighType")==0){ + offset = offsetof(part_transition, pht); + *format = 0; + } else if (strcmp(key, "presLowValue")==0){ + offset = offsetof(part_transition, plv); + *format = 1; + } else if (strcmp(key, "presLowType")==0){ + offset = offsetof(part_transition, plt); + *format = 0; + } else if (strcmp(key, "tempHighValue")==0){ + offset = offsetof(part_transition, thv); + *format = 1; + } else if (strcmp(key, "tempHighType")==0){ + offset = offsetof(part_transition, tht); + *format = 0; + } else if (strcmp(key, "tempLowValue")==0){ + offset = offsetof(part_transition, tlv); + *format = 1; + } else if (strcmp(key, "tempLowType")==0){ + offset = offsetof(part_transition, tlt); + *format = 0; + } else { + offset = -1; + } + return offset; +} +int luacon_transitionread(lua_State* l){ + int format, offset; + int tempinteger; + float tempfloat; + int i; + char * key = mystrdup(luaL_optstring(l, 2, "")); + offset = luacon_transition_getproperty(key, &format); + + //Get Raw Index value for element + lua_pushstring(l, "value"); + lua_rawget(l, 1); + + i = lua_tointeger(l, lua_gettop(l)); + + lua_pop(l, 1); + + if(i < 0 || i >= PT_NUM || offset==-1) + { + return luaL_error(l, "Invalid property"); + } + switch(format) + { + case 0: + tempinteger = *((int*)(((void*)&ptransitions[i])+offset)); + lua_pushnumber(l, tempinteger); + break; + case 1: + tempfloat = *((float*)(((void*)&ptransitions[i])+offset)); + lua_pushnumber(l, tempfloat); + break; + } + free(key); + return 1; +} +int luacon_transitionwrite(lua_State* l){ + int format, offset; + int tempinteger; + float tempfloat; + int i; + char * key = mystrdup(luaL_optstring(l, 2, "")); + offset = luacon_transition_getproperty(key, &format); + + //Get Raw Index value for element + lua_pushstring(l, "value"); + lua_rawget(l, 1); + + i = lua_tointeger (l, lua_gettop(l)); + + lua_pop(l, 1); + + if(i < 0 || i >= PT_NUM || offset==-1) + { + return luaL_error(l, "Invalid property"); + } + switch(format) + { + case 0: + *((int*)(((void*)&ptransitions[i])+offset)) = luaL_optinteger(l, 3, 0); + break; + case 1: + *((float*)(((void*)&ptransitions[i])+offset)) = luaL_optnumber(l, 3, 0); + break; + } + free(key); + return 0; +} int luacon_element_getproperty(char * key, int * format) { int offset; From ffb4c1c5a88534bd1ccb0b33acda6b8837d76b14 Mon Sep 17 00:00:00 2001 From: "chaos.powdertoy.co.uk" Date: Fri, 9 Dec 2011 16:35:39 +0000 Subject: [PATCH 07/14] Version Increment --- includes/defines.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/defines.h b/includes/defines.h index 8dbfca345..23ac9f878 100644 --- a/includes/defines.h +++ b/includes/defines.h @@ -9,9 +9,9 @@ //VersionInfoStart #define SAVE_VERSION 69 -#define MINOR_VERSION 1 +#define MINOR_VERSION 2 #define BETA -#define BUILD_NUM 119 +#define BUILD_NUM 120 //VersionInfoEnd #define IDENT_VERSION "G" //Change this if you're not Simon! It should be a single letter From 799091f0049fb48e19430c861156feba125a7166 Mon Sep 17 00:00:00 2001 From: Simon Robertshaw Date: Sat, 10 Dec 2011 15:50:55 +0000 Subject: [PATCH 08/14] Allow both BrE and AmE spellings of colour with Lua --- src/luaconsole.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/luaconsole.c b/src/luaconsole.c index 0f16bda80..e77630437 100644 --- a/src/luaconsole.c +++ b/src/luaconsole.c @@ -330,6 +330,9 @@ int luacon_particle_getproperty(char * key, int * format) } else if (strcmp(key, "dcolour")==0){ offset = offsetof(particle, dcolour); *format = 0; + } else if (strcmp(key, "dcolor")==0){ + offset = offsetof(particle, dcolour); + *format = 0; } else { offset = -1; } @@ -440,6 +443,10 @@ int luacon_element_getproperty(char * key, int * format) offset = offsetof(part_type, pcolors); *format = 0; } + if (strcmp(key, "colour")==0){ + offset = offsetof(part_type, pcolors); + *format = 0; + } else if (strcmp(key, "advection")==0){ offset = offsetof(part_type, advection); *format = 1; @@ -1036,6 +1043,7 @@ int luatpt_set_property(lua_State* l) h = abs(luaL_optint(l, 6, -1)); else h = -1; + //TODO: Use particle_getproperty if (strcmp(prop,"type")==0){ offset = offsetof(particle, type); format = 3; @@ -1177,6 +1185,7 @@ int luatpt_get_property(lua_State* l) return luaL_error(l, "Invalid particle ID '%d'", i); if (parts[i].type) { + //TODO: Use particle_getproperty if (strcmp(prop,"type")==0){ lua_pushinteger(l, parts[i].type); return 1; From c7d0bf48b614337b29726bc9bca98047031c6cb4 Mon Sep 17 00:00:00 2001 From: savask Date: Sat, 10 Dec 2011 21:11:15 +0700 Subject: [PATCH 09/14] Fixed gravity for stick man. --- src/elements/stkm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/elements/stkm.c b/src/elements/stkm.c index f1de549c4..40e441697 100644 --- a/src/elements/stkm.c +++ b/src/elements/stkm.c @@ -80,8 +80,8 @@ int run_stickman(playerst* playerp, UPDATE_FUNC_ARGS) { } } - gvx += gravx[(int)parts[i].y/CELL][(int)parts[i].x/CELL]; - gvy += gravy[(int)parts[i].y/CELL][(int)parts[i].x/CELL]; + gvx += gravxf[XRES*(int)parts[i].y + (int)parts[i].x]; + gvy += gravyf[XRES*(int)parts[i].y + (int)parts[i].x]; parts[i].vx -= gvx*dt; //Head up! parts[i].vy -= gvy*dt; From bcfea42d18f14ed851936cfe458e7876b9d54a28 Mon Sep 17 00:00:00 2001 From: jacksonmj Date: Sat, 10 Dec 2011 16:29:23 +0800 Subject: [PATCH 10/14] Set BIZR/G/S ctype when loading a save, set BIZS ctype in create_part --- src/main.c | 43 ++++++++++++++++++++----------------------- src/powder.c | 2 +- 2 files changed, 21 insertions(+), 24 deletions(-) diff --git a/src/main.c b/src/main.c index eee04cc0f..ef150acb3 100644 --- a/src/main.c +++ b/src/main.c @@ -724,35 +724,32 @@ int parse_save(void *save, int size, int replace, int x0, int y0, unsigned char if (pmap[y][x]) { k = pmap[y][x]>>8; - memset(parts+k, 0, sizeof(particle)); - parts[k].type = j; - if (j == PT_PHOT) - parts[k].ctype = 0x3fffffff; - if (j == PT_SOAP) - parts[k].ctype = 0; - parts[k].x = (float)x; - parts[k].y = (float)y; - m[(x-x0)+(y-y0)*w] = k+1; } - else if (i < nf) + else if (i Date: Sat, 10 Dec 2011 18:42:19 +0000 Subject: [PATCH 11/14] Fix spelling error --- src/luaconsole.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/luaconsole.c b/src/luaconsole.c index e77630437..c60fdf447 100644 --- a/src/luaconsole.c +++ b/src/luaconsole.c @@ -491,7 +491,7 @@ int luacon_element_getproperty(char * key, int * format) offset = offsetof(part_type, explosive); *format = 0; } - else if (strcmp(key, "metlable")==0){ + else if (strcmp(key, "meltable")==0){ offset = offsetof(part_type, meltable); *format = 0; } From 03352ca1f4115eff5efac7547c3e507bce656496 Mon Sep 17 00:00:00 2001 From: Simon Robertshaw Date: Sat, 10 Dec 2011 19:03:31 +0000 Subject: [PATCH 12/14] Fix memory leaks, allow changing of element name (To fix: element names in some arrays out of sync) --- includes/powder.h | 2 +- src/console.c | 4 ++-- src/luaconsole.c | 38 +++++++++++++++++++++++++++++++------- 3 files changed, 34 insertions(+), 10 deletions(-) diff --git a/includes/powder.h b/includes/powder.h index 31d57fa71..f6a7b3733 100644 --- a/includes/powder.h +++ b/includes/powder.h @@ -438,7 +438,7 @@ void STKM_interact(playerst* playerp, int i, int x, int y); struct part_type { - const char *name; + char *name; pixel pcolors; float advection; float airdrag; diff --git a/src/console.c b/src/console.c index c9714a173..6d8ffe2f9 100644 --- a/src/console.c +++ b/src/console.c @@ -20,14 +20,14 @@ int console_parse_type(char *txt, int *element, char *err) else if (strcasecmp(txt,"NONE")==0) i = PT_NONE; if (i>=0 && i= PT_NUM || offset==-1) { + free(key); return luaL_error(l, "Invalid property"); } switch(format) @@ -614,6 +619,25 @@ int luacon_elementwrite(lua_State* l){ break; case 2: tempstring = mystrdup(luaL_optstring(l, 3, "")); + if(strcmp(key, "name")==0) + { + int j = 0; + //Convert to upper case + for(j = 0; j < strlen(tempstring); j++) + tempstring[j] = toupper(tempstring[j]); + if(strlen(tempstring)>4) + { + free(tempstring); + free(key); + return luaL_error(l, "Name too long"); + } + if(console_parse_type(tempstring, NULL, NULL)) + { + free(tempstring); + free(key); + return luaL_error(l, "Name in use"); + } + } *((char**)(((void*)&ptypes[i])+offset)) = tempstring; //Need some way of cleaning up previous values break; From 8ae0384f09f8f94eb9cc3f07e235114e5d589b36 Mon Sep 17 00:00:00 2001 From: Simon Robertshaw Date: Sat, 17 Dec 2011 21:30:00 +0000 Subject: [PATCH 13/14] Add option for lua parts array to use native data using ffi --- src/luaconsole.c | 41 +++++++++++++++++++++++++++++++---------- src/main.c | 7 ++++--- 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/src/luaconsole.c b/src/luaconsole.c index 815132821..42495e796 100644 --- a/src/luaconsole.c +++ b/src/luaconsole.c @@ -101,16 +101,22 @@ void luacon_open(){ lua_setfield(l, tptPropertiesVersion, "build"); lua_setfield(l, tptProperties, "version"); - /*lua_newtable(l); - tptParts = lua_gettop(l); - lua_newtable(l); - tptPartsMeta = lua_gettop(l); - lua_pushcfunction(l, luacon_partswrite); - lua_setfield(l, tptPartsMeta, "__newindex"); - lua_pushcfunction(l, luacon_partsread); - lua_setfield(l, tptPartsMeta, "__index"); - lua_setmetatable(l, tptParts); - lua_setfield(l, tptProperties, "parts");*/ +#ifdef FFI + //LuaJIT's ffi gives us direct access to parts data, no need for nested metatables. HOWEVER, this is in no way safe, it's entirely possible for someone to try to read parts[-10] + lua_pushlightuserdata(l, parts); + lua_setfield(l, tptProperties, "partsdata"); + + luaL_dostring (l, "ffi = require(\"ffi\")\n\ +ffi.cdef[[\n\ +typedef struct { int type; int life, ctype; float x, y, vx, vy; float temp; float pavg[2]; int flags; int tmp; int tmp2; unsigned int dcolour; } particle;\n\ +]]\n\ +tpt.parts = ffi.cast(\"particle *\", tpt.partsdata)\n\ +ffi = nil\n\ +tpt.partsdata = nil"); + //Since ffi is REALLY REALLY dangrous, we'll remove it from the environment completely (TODO) + +#else + //This uses a lot of memory (60MB+), but very good performance lua_newtable(l); tptParts = lua_gettop(l); for(i = 0; i < NPART; i++) @@ -132,6 +138,19 @@ void luacon_open(){ } lua_setfield(l, tptProperties, "parts"); + //Poor performance (nested metatabled created on get/set) but good little memory usage + /*lua_newtable(l); + tptParts = lua_gettop(l); + lua_newtable(l); + tptPartsMeta = lua_gettop(l); + lua_pushcfunction(l, luacon_partswrite); + lua_setfield(l, tptPartsMeta, "__newindex"); + lua_pushcfunction(l, luacon_partsread); + lua_setfield(l, tptPartsMeta, "__index"); + lua_setmetatable(l, tptParts); + lua_setfield(l, tptProperties, "parts");*/ +#endif + lua_newtable(l); tptElements = lua_gettop(l); for(i = 1; i < PT_NUM; i++) @@ -192,6 +211,7 @@ void luacon_open(){ lua_el_mode[i] = 0; } } +#ifndef FFI int luacon_partread(lua_State* l){ int format, offset; char * tempstring; @@ -294,6 +314,7 @@ int luacon_partsread(lua_State* l){ int luacon_partswrite(lua_State* l){ return luaL_error(l, "Not writable"); } +#endif int luacon_particle_getproperty(char * key, int * format) { int offset; diff --git a/src/main.c b/src/main.c index ef150acb3..f732f2ace 100644 --- a/src/main.c +++ b/src/main.c @@ -1666,9 +1666,6 @@ int main(int argc, char *argv[]) fmt.callback = mixaudio; fmt.userdata = NULL; -#ifdef LUACONSOLE - luacon_open(); -#endif #ifdef MT numCores = core_count(); #endif @@ -1679,6 +1676,10 @@ int main(int argc, char *argv[]) init_can_move(); clear_sim(); +#ifdef LUACONSOLE + luacon_open(); +#endif + colour_mode = COLOUR_DEFAULT; init_display_modes(); From 58b9996958c9dbe2800872659bf4c745c1450e3e Mon Sep 17 00:00:00 2001 From: Simon Robertshaw Date: Sun, 18 Dec 2011 14:41:42 +0000 Subject: [PATCH 14/14] More icons for display modes --- .gitignore | 3 ++- font/font.bin | Bin 30980 -> 31028 bytes includes/font.h | 24 ++++++++++++------------ src/interface.c | 45 ++++++++++++++++++++++++++------------------- 4 files changed, 40 insertions(+), 32 deletions(-) diff --git a/.gitignore b/.gitignore index 3e294cd6d..eb3ec8ba2 100644 --- a/.gitignore +++ b/.gitignore @@ -15,4 +15,5 @@ src/python/stdlib/* *.dll *.srv *.bat -*.o \ No newline at end of file +*.o +*.me \ No newline at end of file diff --git a/font/font.bin b/font/font.bin index 8c34f74dbd599356f6300753b99259af7f9a373e..ea3687daf46f9705777a43599360794ad8e32a95 100644 GIT binary patch delta 960 zcmcIiOHRWu5cSweNn!_76~eEgDc!IDRD{HeMTNSde3z6J0tJr2rWdH@B1L7#C3=OP z0MrY>IF6I3D}?CSktfe@{AN5J%;0?nt_lN>538%g*wu44c?|=?%0pG`pC_eKeqmuC zrDr#NM+mnt{a48&EopxB=K*)cD`7GWhSQy~1D)hS2o5Z>MfiBr*n9*o^0OD?<8@;z zm9e#Gng93k?P&vJsA0Q*ilb)hg)?R*t%94WWlMP3|0@Tp5Mk#o#7S%Ei0Y#2G{w;Z z!Za|&NLO2i84|~@t2*|(;X$^`bX3YChg-7tSpFD*VY3$P6$nr;n8zYgMcq@KNvem_ zvlzd-!3hJ-?IFKuwc+DO64SjlaS}PlIyL?A(tyG!3tK+0493s@Ngmk7dJNtP>CN+dL