summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorcracker64 <cracker642@gmail.com>2012-07-08 04:00:47 (GMT)
committer cracker64 <cracker642@gmail.com>2012-07-08 04:00:47 (GMT)
commite7035233fd6fda5599512a6c588e32ace134024b (patch)
treeeafc8542e1382822aac06862a855bd8265662678 /src
parent5f3c10a6844aa2196258aa52448c8f753edb8439 (diff)
downloadpowder-e7035233fd6fda5599512a6c588e32ace134024b.zip
powder-e7035233fd6fda5599512a6c588e32ace134024b.tar.gz
Optimization for GoL, Added brush size and mouse wheel to lua!
Diffstat (limited to 'src')
-rw-r--r--src/luaconsole.c13
-rw-r--r--src/main.c18
-rw-r--r--src/powder.c24
-rw-r--r--src/save.c2
4 files changed, 34 insertions, 23 deletions
diff --git a/src/luaconsole.c b/src/luaconsole.c
index d32147c..a6d60ad 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 5841af6..4aae2f4 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<SC_TOTAL; i++)//draw all the menu sections
diff --git a/src/powder.c b/src/powder.c
index 6ce9ab2..8170ab2 100644
--- a/src/powder.c
+++ b/src/powder.c
@@ -1791,14 +1791,14 @@ void update_particles_i(pixel *vid, int start, int inc)
int createdsomething = 0;
CGOL=0;
ISGOL=0;
- for (nx=CELL; nx<XRES-CELL; nx++)
+ for (ny=CELL; ny<YRES-CELL; ny++)
{//go through every particle and set neighbor map
- for (ny=CELL; ny<YRES-CELL; ny++)
+ for (nx=CELL; nx<XRES-CELL; nx++)
{
r = pmap[ny][nx];
if (!r)
{
- gol[nx][ny] = 0;
+ gol[ny][nx] = 0;
continue;
}
else
@@ -1813,7 +1813,7 @@ void update_particles_i(pixel *vid, int start, int inc)
continue;
}
if (parts[r>>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<XRES-CELL; nx++)
+ for (ny=CELL; ny<YRES-CELL; ny++)
{ //go through every particle again, but check neighbor map, then update particles
- for (ny=CELL; ny<YRES-CELL; ny++)
+ for (nx=CELL; nx<XRES-CELL; nx++)
{
r = pmap[ny][nx];
- neighbors = gol2[nx][ny][0];
+ neighbors = gol2[ny][nx][0];
if (neighbors==0 || !((r&0xFF)==PT_LIFE || !(r&0xFF)))
continue;
for ( golnum = 1; golnum<=NGOL; golnum++)
{
goldelete = neighbors;
- if (gol[nx][ny]==0&&grule[golnum][goldelete]>=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 7a846d7..1fcfe7a 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])