From d5f58d995e16cdc62a95b719f94ce5d47b598c46 Mon Sep 17 00:00:00 2001 From: Simon Robertshaw Date: Thu, 8 Dec 2011 12:16:50 +0000 Subject: Directly accessible parts array (no pmap yet) diff --git a/includes/luaconsole.h b/includes/luaconsole.h index bb7c744..f116b9f 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 41270f4..cbabc41 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]; @@ -101,6 +102,17 @@ void luacon_open(){ 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); lua_setfield(l, tptElements, "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; -- cgit v0.9.2-21-gd62e From 274df46a37a6c89e8c9e3443674cb38d6c011c67 Mon Sep 17 00:00:00 2001 From: "chaos.powdertoy.co.uk" Date: Thu, 8 Dec 2011 17:44:55 +0000 Subject: Test diff --git a/includes/defines.h b/includes/defines.h index bdf3f8c..467cb6c 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) -- cgit v0.9.2-21-gd62e From 1585eda5f0b7b0dee9469b8e841fc7e0bc5b6a9c Mon Sep 17 00:00:00 2001 From: "chaos.powdertoy.co.uk" Date: Thu, 8 Dec 2011 17:48:51 +0000 Subject: Version Increment diff --git a/includes/defines.h b/includes/defines.h index 467cb6c..8dbfca3 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 -- cgit v0.9.2-21-gd62e From 9dcdccc06693051acb31e8eb5bd1de6a10fbb306 Mon Sep 17 00:00:00 2001 From: Simon Robertshaw Date: Fri, 9 Dec 2011 11:53:19 +0000 Subject: Fix error in element_func where function was being read as the last parameter diff --git a/src/luaconsole.c b/src/luaconsole.c index cbabc41..d0430ef 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; -- cgit v0.9.2-21-gd62e From f5a58d14f2df42f5c8710df3f42d611c4c456c1b Mon Sep 17 00:00:00 2001 From: Simon Robertshaw Date: Fri, 9 Dec 2011 12:06:22 +0000 Subject: Use static table for parts array, Uses a tonne of memory but improves performance a lot. diff --git a/src/luaconsole.c b/src/luaconsole.c index d0430ef..a80ba2f 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); -- cgit v0.9.2-21-gd62e From e519aa911bbd869390b65f079ae088d79550fdda Mon Sep 17 00:00:00 2001 From: Simon Robertshaw Date: Fri, 9 Dec 2011 16:30:33 +0000 Subject: Element transitions also editable now diff --git a/includes/luaconsole.h b/includes/luaconsole.h index f116b9f..fc5e2c4 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 a80ba2f..0f16bda 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; -- cgit v0.9.2-21-gd62e From ffb4c1c5a88534bd1ccb0b33acda6b8837d76b14 Mon Sep 17 00:00:00 2001 From: "chaos.powdertoy.co.uk" Date: Fri, 9 Dec 2011 16:35:39 +0000 Subject: Version Increment diff --git a/includes/defines.h b/includes/defines.h index 8dbfca3..23ac9f8 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 -- cgit v0.9.2-21-gd62e From 799091f0049fb48e19430c861156feba125a7166 Mon Sep 17 00:00:00 2001 From: Simon Robertshaw Date: Sat, 10 Dec 2011 15:50:55 +0000 Subject: Allow both BrE and AmE spellings of colour with Lua diff --git a/src/luaconsole.c b/src/luaconsole.c index 0f16bda..e776304 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; -- cgit v0.9.2-21-gd62e From c7d0bf48b614337b29726bc9bca98047031c6cb4 Mon Sep 17 00:00:00 2001 From: savask Date: Sat, 10 Dec 2011 21:11:15 +0700 Subject: Fixed gravity for stick man. diff --git a/src/elements/stkm.c b/src/elements/stkm.c index f1de549..40e4416 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; -- cgit v0.9.2-21-gd62e From bcfea42d18f14ed851936cfe458e7876b9d54a28 Mon Sep 17 00:00:00 2001 From: jacksonmj Date: Sat, 10 Dec 2011 16:29:23 +0800 Subject: Set BIZR/G/S ctype when loading a save, set BIZS ctype in create_part diff --git a/src/main.c b/src/main.c index eee04cc..ef150ac 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) - { - memset(parts+fp[i], 0, sizeof(particle)); - parts[fp[i]].type = j; - if (j == PT_COAL) - parts[fp[i]].tmp = 50; - if (j == PT_FUSE) - parts[fp[i]].tmp = 50; - if (j == PT_PHOT) - parts[fp[i]].ctype = 0x3fffffff; - if (j == PT_SOAP) - parts[fp[i]].ctype = 0; - parts[fp[i]].x = (float)x; - parts[fp[i]].y = (float)y; - m[(x-x0)+(y-y0)*w] = fp[i]+1; + } + else if (i Date: Sat, 10 Dec 2011 18:42:19 +0000 Subject: Fix spelling error diff --git a/src/luaconsole.c b/src/luaconsole.c index e776304..c60fdf4 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; } -- cgit v0.9.2-21-gd62e From 03352ca1f4115eff5efac7547c3e507bce656496 Mon Sep 17 00:00:00 2001 From: Simon Robertshaw Date: Sat, 10 Dec 2011 19:03:31 +0000 Subject: Fix memory leaks, allow changing of element name (To fix: element names in some arrays out of sync) diff --git a/includes/powder.h b/includes/powder.h index 31d57fa..f6a7b37 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 c9714a1..6d8ffe2 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; -- cgit v0.9.2-21-gd62e From 8ae0384f09f8f94eb9cc3f07e235114e5d589b36 Mon Sep 17 00:00:00 2001 From: Simon Robertshaw Date: Sat, 17 Dec 2011 21:30:00 +0000 Subject: Add option for lua parts array to use native data using ffi diff --git a/src/luaconsole.c b/src/luaconsole.c index 8151328..42495e7 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 ef150ac..f732f2a 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(); -- cgit v0.9.2-21-gd62e From 58b9996958c9dbe2800872659bf4c745c1450e3e Mon Sep 17 00:00:00 2001 From: Simon Robertshaw Date: Sun, 18 Dec 2011 14:41:42 +0000 Subject: More icons for display modes diff --git a/.gitignore b/.gitignore index 3e294cd..eb3ec8b 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 8c34f74..ea3687d 100644 Binary files a/font/font.bin and b/font/font.bin differ diff --git a/includes/font.h b/includes/font.h index c5a9ded..5e2be5b 100644 --- a/includes/font.h +++ b/includes/font.h @@ -222,13 +222,13 @@ char font_data[] = { 0x05, 0x6F, 0xBC, 0xF1, 0xC6, 0x1B, 0x6F, 0xBC, 0xF1, 0xC6, 0x1B, 0x6F, 0x00, 0x00, 0x08, 0xE4, 0x6F, 0xE4, 0x6F, 0xE4, 0x6F, 0xE4, 0x6F, 0xE4, 0x6F, 0xE4, 0x6F, 0xE4, 0x6F, 0xE4, 0x6F, 0xE4, 0x6F, 0x00, 0x00, 0x09, 0x00, 0xE4, 0x03, 0x90, 0x0F, 0x40, 0x3E, 0x00, 0xF9, 0x00, 0xE4, 0x03, 0x90, 0x0F, 0x40, 0x3E, 0x00, 0xF9, 0x00, 0xE4, 0x03, 0x00, 0x00, - 0x06, 0x74, 0xC0, 0x0C, 0xDC, 0xC0, 0x0C, 0xDC, 0xC0, 0x0C, 0x99, 0x31, 0x30, 0x89, 0x41, 0x07, - 0x06, 0x74, 0xC0, 0x0C, 0xDC, 0xC0, 0x0C, 0xDC, 0xC0, 0x0C, 0x99, 0x31, 0x30, 0x89, 0x41, 0x07, - 0x06, 0x74, 0xC0, 0x0C, 0xDC, 0xC0, 0x0C, 0xDC, 0xC0, 0x0C, 0x99, 0x31, 0x30, 0x89, 0x41, 0x07, - 0x06, 0x74, 0xC0, 0x0C, 0xDC, 0xC0, 0x0C, 0xDC, 0xC0, 0x0C, 0x99, 0x31, 0x30, 0x89, 0x41, 0x07, - 0x06, 0x74, 0xC0, 0x0C, 0xDC, 0xC0, 0x0C, 0xDC, 0xC0, 0x0C, 0x99, 0x31, 0x30, 0x89, 0x41, 0x07, - 0x06, 0x74, 0xC0, 0x0C, 0xDC, 0xC0, 0x0C, 0xDC, 0xC0, 0x0C, 0x99, 0x31, 0x30, 0x89, 0x41, 0x07, - 0x06, 0x74, 0xC0, 0x0C, 0xDC, 0xC0, 0x0C, 0xDC, 0xC0, 0x0C, 0x99, 0x31, 0x30, 0x89, 0x41, 0x07, + 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x3F, 0x00, 0xFF, 0x03, 0xF0, 0x3F, 0x00, 0xFF, 0x03, 0xF0, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x0A, 0x08, 0x82, 0xE0, 0xBA, 0x2E, 0x08, 0x82, 0x80, 0x20, 0x08, 0xAE, 0xEB, 0x82, 0x20, 0x08, 0x08, 0x82, 0xE0, 0xBA, 0x2E, 0x08, 0x82, 0x00, 0x00, 0x00, + 0x0A, 0x00, 0x30, 0x00, 0x00, 0x03, 0x30, 0xFC, 0x00, 0x43, 0x07, 0xFC, 0x20, 0x40, 0x07, 0x30, 0x20, 0x00, 0x03, 0x00, 0xFC, 0x00, 0x40, 0x07, 0x00, 0x20, + 0x0A, 0x00, 0x43, 0xC0, 0x20, 0x1D, 0x20, 0x61, 0x00, 0x44, 0x00, 0x00, 0x00, 0x00, 0x84, 0x01, 0x24, 0xB4, 0xF1, 0x01, 0xFE, 0x0F, 0xD0, 0x0F, 0x00, 0xFC, + 0x0A, 0x00, 0x00, 0x00, 0x54, 0x00, 0x90, 0x1A, 0x40, 0xFE, 0x06, 0xE4, 0x6F, 0x40, 0xFE, 0x06, 0x90, 0x1A, 0x00, 0x54, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x0B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x10, 0x88, 0x88, 0x88, 0x55, 0x55, 0x55, 0xFF, 0x00, 0x54, 0x55, 0x55, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x0A, 0x00, 0x01, 0x00, 0x10, 0x00, 0x00, 0x02, 0x00, 0x64, 0x00, 0xA5, 0x6B, 0x01, 0x64, 0x00, 0x00, 0x02, 0x00, 0x10, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x06, 0x74, 0xC0, 0x0C, 0xDC, 0xC0, 0x0C, 0xDC, 0xC0, 0x0C, 0x99, 0x31, 0x30, 0x89, 0x41, 0x07, 0x06, 0x74, 0xC0, 0x0C, 0xDC, 0xC0, 0x0C, 0xDC, 0xC0, 0x0C, 0x99, 0x31, 0x30, 0x89, 0x41, 0x07, 0x06, 0x74, 0xC0, 0x0C, 0xDC, 0xC0, 0x0C, 0xDC, 0xC0, 0x0C, 0x99, 0x31, 0x30, 0x89, 0x41, 0x07, @@ -288,11 +288,11 @@ short font_ptrs[] = { 0x0CA8, 0x0CC2, 0x0CDC, 0x0CF6, 0x0D10, 0x0D2A, 0x0D44, 0x0D5E, 0x0D78, 0x0D92, 0x0DAC, 0x0DC6, 0x0DE0, 0x0DFA, 0x0E14, 0x0E2E, 0x0E46, 0x0E60, 0x0E7A, 0x0E94, 0x0EAE, 0x0EC8, 0x0EE2, 0x0EFC, - 0x0F16, 0x0F24, 0x0F39, 0x0F51, 0x0F61, 0x0F71, 0x0F81, 0x0F91, - 0x0FA1, 0x0FB1, 0x0FC1, 0x0FD1, 0x0FE1, 0x0FF1, 0x1001, 0x1011, - 0x1021, 0x1031, 0x1041, 0x1051, 0x1061, 0x1071, 0x1081, 0x1091, - 0x10A1, 0x10B1, 0x10C1, 0x10D1, 0x10E1, 0x10F1, 0x1101, 0x1111, - 0x1121, 0x1131, 0x1141, 0x1151, 0x1161, 0x1171, 0x1181, 0x1191, + 0x0F16, 0x0F24, 0x0F39, 0x0F51, 0x0F6B, 0x0F85, 0x0F9F, 0x0FB9, + 0x0FD3, 0x0FF0, 0x100A, 0x101A, 0x102A, 0x103A, 0x104A, 0x105A, + 0x106A, 0x107A, 0x108A, 0x109A, 0x10AA, 0x10BA, 0x10CA, 0x10DA, + 0x10EA, 0x10FA, 0x110A, 0x111A, 0x112A, 0x113A, 0x114A, 0x115A, + 0x116A, 0x117A, 0x118A, 0x119A, 0x11AA, 0x11BA, 0x11CA, 0x11DA, }; #endif #endif diff --git a/src/interface.c b/src/interface.c index 92193d9..3f33e9a 100644 --- a/src/interface.c +++ b/src/interface.c @@ -6260,41 +6260,48 @@ void drawIcon(pixel * vid_buf, int x, int y, int cmode) { switch (cmode) { - case CM_VEL: + case 0x98: drawtext(vid_buf, x, y, "\x98", 128, 160, 255, 255); break; - case CM_PRESS: + case 0x99: drawtext(vid_buf, x, y, "\x99", 255, 212, 32, 255); break; - case CM_PERS: + case 0x9A: drawtext(vid_buf, x, y, "\x9A", 212, 212, 212, 255); break; - case CM_FIRE: + case 0x9B: drawtext(vid_buf, x+1, y, "\x9B", 255, 0, 0, 255); drawtext(vid_buf, x+1, y, "\x9C", 255, 255, 64, 255); break; - case CM_BLOB: + case 0xBF: drawtext(vid_buf, x, y, "\xBF", 55, 255, 55, 255); break; - case CM_HEAT: + case 0xBE: drawtext(vid_buf, x+2, y, "\xBE", 255, 0, 0, 255); drawtext(vid_buf, x+2, y, "\xBD", 255, 255, 255, 255); break; - case CM_FANCY: + case 0xC4: drawtext(vid_buf, x, y, "\xC4", 100, 150, 255, 255); break; - case CM_NOTHING: - //drawtext(vid_buf, x, y, "\xD1", 100, 150, 255, 255); - drawtext(vid_buf, x, y, "\x00", 100, 150, 255, 255); - break; - case CM_GRAD: + case 0xD3: drawtext(vid_buf, x, y, "\xD3", 255, 50, 255, 255); break; - case CM_LIFE: - //drawtext(vid_buf, x, y, "\xD1", 255, 50, 255, 255); - drawtext(vid_buf, x, y, "\x00", 255, 50, 255, 255); + case 0xE0: + drawtext(vid_buf, x, y, "\xE0", 255, 255, 255, 255); + break; + case 0xE1: + drawtext(vid_buf, x, y, "\xE1", 255, 255, 160, 255); + break; + case 0xDF: + drawtext(vid_buf, x, y, "\xDF", 200, 255, 255, 255); + break; + case 0xDE: + drawtext(vid_buf, x, y, "\xDE", 255, 255, 255, 255); + break; + case 0xDB: + drawtext(vid_buf, x, y, "\xDB", 255, 255, 200, 255); break; - case CM_CRACK: + case 0xD4: drawtext(vid_buf, x, y, "\xD4", 255, 55, 55, 255); drawtext(vid_buf, x, y, "\xD5", 55, 255, 55, 255); break; @@ -6317,17 +6324,17 @@ void render_ui(pixel * vid_buf, int xcoord, int ycoord, int orientation) int render_optioncount = 6; int render_options[] = {RENDER_EFFE, RENDER_GLOW, RENDER_FIRE, RENDER_BLUR, RENDER_BLOB, RENDER_BASC}; - int render_optionicons[] = {-1, -1, 3, 6, 4, -1}; + int render_optionicons[] = {0xE1, 0xDF, 0x9B, 0xC4, 0xBF, 0xDB}; char * render_desc[] = {"Effects", "Glow", "Fire", "Blur", "Blob", "Basic"}; int display_optioncount = 7; int display_options[] = {DISPLAY_AIRC, DISPLAY_AIRP, DISPLAY_AIRV, DISPLAY_AIRH, DISPLAY_WARP, DISPLAY_PERS, DISPLAY_EFFE}; - int display_optionicons[] = {10, 1, 0, 5, -1, 2, -1}; + int display_optionicons[] = {0xD4, 0x99, 0x98, 0xBE, 0xDE, 0x9A, -1}; char * display_desc[] = {"Air: Cracker", "Air: Pressure", "Air: Velocity", "Air: Heat", "Warp effect", "Persistent", "Effects"}; int colour_optioncount = 3; int colour_options[] = {COLOUR_LIFE, COLOUR_HEAT, COLOUR_GRAD}; - int colour_optionicons[] = {9, 5, 8}; + int colour_optionicons[] = {0xE0, 0xBE, 0xD3}; char * colour_desc[] = {"Life", "Heat", "Heat Gradient"}; yoffset = 16; -- cgit v0.9.2-21-gd62e