From e7035233fd6fda5599512a6c588e32ace134024b Mon Sep 17 00:00:00 2001 From: cracker64 Date: Sun, 8 Jul 2012 00:00:47 -0400 Subject: [PATCH] Optimization for GoL, Added brush size and mouse wheel to lua! --- includes/defines.h | 4 ++-- includes/luaconsole.h | 4 ++-- src/luaconsole.c | 13 ++++++++++--- src/main.c | 18 +++++++++++------- src/powder.c | 24 ++++++++++++------------ src/save.c | 2 +- 6 files changed, 38 insertions(+), 27 deletions(-) diff --git a/includes/defines.h b/includes/defines.h index 24b52eca1..85b8d3b0c 100644 --- a/includes/defines.h +++ b/includes/defines.h @@ -234,8 +234,8 @@ int ISWIRE; int GSPEED; int love[XRES/9][YRES/9]; int lolz[XRES/9][YRES/9]; -unsigned char gol[XRES][YRES]; -unsigned char gol2[XRES][YRES][NGOL+1]; +unsigned char gol[YRES][XRES]; +unsigned char gol2[YRES][XRES][NGOL+1]; int SEC; int SEC2; int console_mode; diff --git a/includes/luaconsole.h b/includes/luaconsole.h index b4e313b72..818a715c2 100644 --- a/includes/luaconsole.h +++ b/includes/luaconsole.h @@ -43,8 +43,8 @@ int *lua_el_func, *lua_el_mode, *lua_gr_func; void luacon_open(); -int luacon_step(int mx, int my, int selectl, int selectr); -int luacon_mouseevent(int mx, int my, int mb, int event); +int luacon_step(int mx, int my, int selectl, int selectr, int bsx, int bsy); +int luacon_mouseevent(int mx, int my, int mb, int event, int mouse_wheel); int luacon_keyevent(int key, int modifier, int event); int luacon_eval(char *command); int luacon_part_update(int t, int i, int x, int y, int surround_space, int nt); diff --git a/src/luaconsole.c b/src/luaconsole.c index d32147c3f..a6d60ade8 100644 --- a/src/luaconsole.c +++ b/src/luaconsole.c @@ -709,7 +709,7 @@ int luacon_keyevent(int key, int modifier, int event){ } return kpcontinue; } -int luacon_mouseevent(int mx, int my, int mb, int event){ +int luacon_mouseevent(int mx, int my, int mb, int event, int mouse_wheel){ int i = 0, mpcontinue = 1; if(mouseclick_function_count){ for(i = 0; i < mouseclick_function_count && mpcontinue; i++){ @@ -718,7 +718,8 @@ int luacon_mouseevent(int mx, int my, int mb, int event){ lua_pushinteger(l, my); lua_pushinteger(l, mb); lua_pushinteger(l, event); - lua_pcall(l, 4, 1, 0); + lua_pushinteger(l, mouse_wheel); + lua_pcall(l, 5, 1, 0); if(lua_isboolean(l, -1)){ mpcontinue = lua_toboolean(l, -1); } @@ -727,8 +728,11 @@ int luacon_mouseevent(int mx, int my, int mb, int event){ } return mpcontinue; } -int luacon_step(int mx, int my, int selectl, int selectr){ +int luacon_step(int mx, int my, int selectl, int selectr, int bsx, int bsy){ int tempret = 0, tempb, i, callret; + lua_pushinteger(l, bsy); + lua_pushinteger(l, bsx); + lua_pushinteger(l, SLALT); lua_pushinteger(l, selectr); lua_pushinteger(l, selectl); lua_pushinteger(l, my); @@ -737,6 +741,9 @@ int luacon_step(int mx, int my, int selectl, int selectr){ lua_setfield(l, tptProperties, "mousey"); lua_setfield(l, tptProperties, "selectedl"); lua_setfield(l, tptProperties, "selectedr"); + lua_setfield(l, tptProperties, "selecteda"); + lua_setfield(l, tptProperties, "brushx"); + lua_setfield(l, tptProperties, "brushy"); for(i = 0; i<6; i++){ if(step_functions[i]){ loop_time = SDL_GetTicks(); diff --git a/src/main.c b/src/main.c index 5841af640..4aae2f488 100644 --- a/src/main.c +++ b/src/main.c @@ -1778,7 +1778,7 @@ int main(int argc, char *argv[]) if (ZSIZE<2) ZSIZE = 2; ZFACTOR = 256/ZSIZE; - sdl_wheel = 0; + //sdl_wheel = 0; } else //change brush size { @@ -1803,7 +1803,7 @@ int main(int argc, char *argv[]) bsy = 1180; if (bsy<0) bsy = 0; - sdl_wheel = 0; + //sdl_wheel = 0; /*if(su >= PT_NUM) { if(sl < PT_NUM) su = sl; @@ -1818,23 +1818,27 @@ int main(int argc, char *argv[]) #ifdef LUACONSOLE if(bc && bq){ - if(!luacon_mouseevent(x, y, bc, LUACON_MPRESS)){ + if(!luacon_mouseevent(x, y, bc, LUACON_MPRESS, sdl_wheel)){ b = 0; } } else if(bc && !bq){ - if(!luacon_mouseevent(x, y, bc, LUACON_MDOWN)){ + if(!luacon_mouseevent(x, y, bc, LUACON_MDOWN, sdl_wheel)){ b = 0; } } else if(!bc && bq){ - if(!luacon_mouseevent(x, y, bq, LUACON_MUP)){ + if(!luacon_mouseevent(x, y, bq, LUACON_MUP, sdl_wheel)){ b = 0; } } - luacon_step(x, y,sl,sr); + else if (sdl_wheel){ + luacon_mouseevent(x, y, bq, 0, sdl_wheel); + } + + luacon_step(x, y,sl,sr,bsx,bsy); #endif - + sdl_wheel = 0; quickoptions_menu(vid_buf, b, bq, x, y); for (i=0; i>8].tmp == grule[golnum][9]-1) { - gol[nx][ny] = golnum; + gol[ny][nx] = golnum; for ( nnx=-1; nnx<2; nnx++) { for ( nny=-1; nny<2; nny++)//it will count itself as its own neighbor, which is needed, but will have 1 extra for delete check @@ -1821,8 +1821,8 @@ void update_particles_i(pixel *vid, int start, int inc) rt = pmap[((ny+nny+YRES-3*CELL)%(YRES-2*CELL))+CELL][((nx+nnx+XRES-3*CELL)%(XRES-2*CELL))+CELL]; if (!rt || (rt&0xFF)==PT_LIFE) { - gol2[((nx+nnx+XRES-3*CELL)%(XRES-2*CELL))+CELL][((ny+nny+YRES-3*CELL)%(YRES-2*CELL))+CELL][golnum] ++; - gol2[((nx+nnx+XRES-3*CELL)%(XRES-2*CELL))+CELL][((ny+nny+YRES-3*CELL)%(YRES-2*CELL))+CELL][0] ++; + gol2[((ny+nny+YRES-3*CELL)%(YRES-2*CELL))+CELL][((nx+nnx+XRES-3*CELL)%(XRES-2*CELL))+CELL][golnum] ++; + gol2[((ny+nny+YRES-3*CELL)%(YRES-2*CELL))+CELL][((nx+nnx+XRES-3*CELL)%(XRES-2*CELL))+CELL][0] ++; } } } @@ -1836,23 +1836,23 @@ void update_particles_i(pixel *vid, int start, int inc) } } } - for (nx=CELL; nx=2&&gol2[nx][ny][golnum]>=(goldelete%2)+goldelete/2) + if (gol[ny][nx]==0&&grule[golnum][goldelete]>=2&&gol2[ny][nx][golnum]>=(goldelete%2)+goldelete/2) { if (create_part(-1, nx, ny, PT_LIFE|((golnum-1)<<8))) createdsomething = 1; } - else if (gol[nx][ny]==golnum&&(grule[golnum][goldelete-1]==0||grule[golnum][goldelete-1]==2))//subtract 1 because it counted itself + else if (gol[ny][nx]==golnum&&(grule[golnum][goldelete-1]==0||grule[golnum][goldelete-1]==2))//subtract 1 because it counted itself { if (parts[r>>8].tmp==grule[golnum][9]-1) parts[r>>8].tmp --; @@ -1861,7 +1861,7 @@ void update_particles_i(pixel *vid, int start, int inc) parts[r>>8].type = PT_NONE;//using kill_part makes it not work } for ( z = 0; z<=NGOL; z++) - gol2[nx][ny][z] = 0;//this improves performance A LOT compared to the memset, i was getting ~23 more fps with this. + gol2[ny][nx][z] = 0;//this improves performance A LOT compared to the memset, i was getting ~23 more fps with this. } } if (createdsomething) diff --git a/src/save.c b/src/save.c index 7a846d7ec..1fcfe7adf 100644 --- a/src/save.c +++ b/src/save.c @@ -1807,7 +1807,7 @@ int parse_save_PSv(void *save, int size, int replace, int x0, int y0, unsigned c //TODO: Possibly some server side translation j = PT_DUST;//goto corrupt; } - gol[x][y]=0; + gol[y][x]=0; if (j) { if (pmap[y][x])