Optimization for GoL, Added brush size and mouse wheel to lua!
This commit is contained in:
parent
5f3c10a684
commit
e7035233fd
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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();
|
||||
|
18
src/main.c
18
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);
|
||||
#endif
|
||||
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
|
||||
|
24
src/powder.c
24
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++)
|
||||
{//go through every particle and set neighbor map
|
||||
for (ny=CELL; ny<YRES-CELL; ny++)
|
||||
{//go through every particle and set neighbor map
|
||||
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++)
|
||||
{ //go through every particle again, but check neighbor map, then update particles
|
||||
for (ny=CELL; ny<YRES-CELL; ny++)
|
||||
{ //go through every particle again, but check neighbor map, then update particles
|
||||
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)
|
||||
|
@ -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])
|
||||
|
Reference in New Issue
Block a user