summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-07-25 18:32:36 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-07-25 18:32:36 (GMT)
commitf8766201a688598633e41166225d5e77275a2d5a (patch)
treee90eaf8bf33373596fc39d1eee08fe8ee708be5e /src
parent76070f99e0e9e4817f17dc55489756276b7b58c3 (diff)
downloadpowder-f8766201a688598633e41166225d5e77275a2d5a.zip
powder-f8766201a688598633e41166225d5e77275a2d5a.tar.gz
TPT: Optimization for GoL, Added brush size and mouse wheel to lua! e7035233fd
Diffstat (limited to 'src')
-rw-r--r--src/cat/CommandInterface.h1
-rw-r--r--src/cat/LuaScriptHelper.h4
-rw-r--r--src/cat/LuaScriptInterface.cpp28
-rw-r--r--src/cat/LuaScriptInterface.h3
-rw-r--r--src/game/GameController.cpp7
-rw-r--r--src/game/GameController.h1
-rw-r--r--src/simulation/Simulation.cpp24
-rw-r--r--src/simulation/Simulation.h4
-rw-r--r--src/simulation/elements/PLNT.cpp2
-rw-r--r--src/simulation/elements/STKM.cpp6
10 files changed, 51 insertions, 29 deletions
diff --git a/src/cat/CommandInterface.h b/src/cat/CommandInterface.h
index e0d680c..e89632e 100644
--- a/src/cat/CommandInterface.h
+++ b/src/cat/CommandInterface.h
@@ -25,6 +25,7 @@ public:
int GetParticleType(std::string type);
void Log(LogType type, std::string message);
//void AttachGameModel(GameModel * m);
+ virtual bool OnBrushChanged(int brushType, int rx, int ry) {return true;}
virtual bool OnMouseMove(int x, int y, int dx, int dy) {return true;}
virtual bool OnMouseDown(int x, int y, unsigned button) {return true;}
virtual bool OnMouseUp(int x, int y, unsigned button) {return true;}
diff --git a/src/cat/LuaScriptHelper.h b/src/cat/LuaScriptHelper.h
index 079a32e..2577333 100644
--- a/src/cat/LuaScriptHelper.h
+++ b/src/cat/LuaScriptHelper.h
@@ -30,8 +30,8 @@ int tptElements; //Table for TPT element names
int tptParts, tptPartsMeta, tptElementTransitions, tptPartsCData, tptPartMeta, tptPart, cIndex;
-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/cat/LuaScriptInterface.cpp b/src/cat/LuaScriptInterface.cpp
index 48e7908..3dd9a55 100644
--- a/src/cat/LuaScriptInterface.cpp
+++ b/src/cat/LuaScriptInterface.cpp
@@ -219,6 +219,13 @@ tpt.partsdata = nil");
}
+bool LuaScriptInterface::OnBrushChanged(int brushType, int rx, int ry)
+{
+ luacon_brushx = rx;
+ luacon_brushy = ry;
+ return true;
+}
+
bool LuaScriptInterface::OnMouseMove(int x, int y, int dx, int dy)
{
luacon_mousex = x;
@@ -230,18 +237,18 @@ bool LuaScriptInterface::OnMouseDown(int x, int y, unsigned button)
{
luacon_mousedown = true;
luacon_mousebutton = button;
- return luacon_mouseevent(x, y, button, LUACON_MDOWN);
+ return luacon_mouseevent(x, y, button, LUACON_MDOWN, 0);
}
bool LuaScriptInterface::OnMouseUp(int x, int y, unsigned button)
{
luacon_mousedown = false;
- return luacon_mouseevent(x, y, button, LUACON_MUP);
+ return luacon_mouseevent(x, y, button, LUACON_MUP, 0);
}
bool LuaScriptInterface::OnMouseWheel(int x, int y, int d)
{
- return true;
+ return luacon_mouseevent(x, y, luacon_mousedown?luacon_mousebutton:0, 0, d);
}
bool LuaScriptInterface::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt)
@@ -271,8 +278,8 @@ bool LuaScriptInterface::OnKeyRelease(int key, Uint16 character, bool shift, boo
void LuaScriptInterface::OnTick()
{
if(luacon_mousedown)
- luacon_mouseevent(luacon_mousex, luacon_mousey, luacon_mousebutton, LUACON_MPRESS);
- luacon_step(luacon_mousex, luacon_mousey, luacon_selectedl, luacon_selectedr);
+ luacon_mouseevent(luacon_mousex, luacon_mousey, luacon_mousebutton, LUACON_MPRESS, 0);
+ luacon_step(luacon_mousex, luacon_mousey, luacon_selectedl, luacon_selectedr, luacon_brushx, luacon_brushy);
}
int LuaScriptInterface::Command(std::string command)
@@ -783,7 +790,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++){
@@ -792,7 +799,8 @@ int luacon_mouseevent(int mx, int my, int mb, int event){
lua_pushinteger(luacon_ci->l, my);
lua_pushinteger(luacon_ci->l, mb);
lua_pushinteger(luacon_ci->l, event);
- lua_pcall(luacon_ci->l, 4, 1, 0);
+ lua_pushinteger(luacon_ci->l, mouse_wheel);
+ lua_pcall(luacon_ci->l, 5, 1, 0);
if(lua_isboolean(luacon_ci->l, -1)){
mpcontinue = lua_toboolean(luacon_ci->l, -1);
}
@@ -801,8 +809,10 @@ 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(luacon_ci->l, bsy);
+ lua_pushinteger(luacon_ci->l, bsx);
lua_pushinteger(luacon_ci->l, selectr);
lua_pushinteger(luacon_ci->l, selectl);
lua_pushinteger(luacon_ci->l, my);
@@ -811,6 +821,8 @@ int luacon_step(int mx, int my, int selectl, int selectr){
lua_setfield(luacon_ci->l, tptProperties, "mousey");
lua_setfield(luacon_ci->l, tptProperties, "selectedl");
lua_setfield(luacon_ci->l, tptProperties, "selectedr");
+ lua_setfield(luacon_ci->l, tptProperties, "brushx");
+ lua_setfield(luacon_ci->l, tptProperties, "brushy");
if(step_functions[0]){
//Set mouse globals
for(i = 0; i<6; i++){
diff --git a/src/cat/LuaScriptInterface.h b/src/cat/LuaScriptInterface.h
index febf5c4..4015109 100644
--- a/src/cat/LuaScriptInterface.h
+++ b/src/cat/LuaScriptInterface.h
@@ -34,12 +34,13 @@ extern "C"
#define LUACON_EL_MODIFIED_MENUS 0x4
class LuaScriptInterface: public CommandInterface {
- int luacon_mousex, luacon_mousey, luacon_selectedl, luacon_selectedr, luacon_mousebutton;
+ int luacon_mousex, luacon_mousey, luacon_selectedl, luacon_selectedr, luacon_mousebutton, luacon_brushx, luacon_brushy;
bool luacon_mousedown;
bool currentCommand;
public:
lua_State *l;
LuaScriptInterface(GameModel * m);
+ virtual bool OnBrushChanged(int brushType, int rx, int ry);
virtual bool OnMouseMove(int x, int y, int dx, int dy);
virtual bool OnMouseDown(int x, int y, unsigned button);
virtual bool OnMouseUp(int x, int y, unsigned button);
diff --git a/src/game/GameController.cpp b/src/game/GameController.cpp
index 8fc1aca..4d13e52 100644
--- a/src/game/GameController.cpp
+++ b/src/game/GameController.cpp
@@ -196,6 +196,7 @@ void GameController::AdjustBrushSize(int direction, bool logarithmic)
if(newSize.Y<0)
newSize.Y = 0;
gameModel->GetBrush()->SetRadius(newSize);
+ BrushChanged(gameModel->GetBrushID(), gameModel->GetBrush()->GetRadius().X, gameModel->GetBrush()->GetRadius().Y);
}
void GameController::AdjustZoomSize(int direction, bool logarithmic)
@@ -365,6 +366,11 @@ bool GameController::MouseMove(int x, int y, int dx, int dy)
return commandInterface->OnMouseMove(x, y, dx, dy);
}
+bool GameController::BrushChanged(int brushType, int rx, int ry)
+{
+ return commandInterface->OnBrushChanged(brushType, rx, ry);
+}
+
bool GameController::MouseDown(int x, int y, unsigned button)
{
return commandInterface->OnMouseDown(x, y, button);
@@ -638,6 +644,7 @@ void GameController::Vote(int direction)
void GameController::ChangeBrush()
{
gameModel->SetBrush(gameModel->GetBrushID()+1);
+ BrushChanged(gameModel->GetBrushID(), gameModel->GetBrush()->GetRadius().X, gameModel->GetBrush()->GetRadius().Y);
}
void GameController::ClearSim()
diff --git a/src/game/GameController.h b/src/game/GameController.h
index 2388c5d..441aeeb 100644
--- a/src/game/GameController.h
+++ b/src/game/GameController.h
@@ -55,6 +55,7 @@ public:
~GameController();
GameView * GetView();
+ bool BrushChanged(int brushType, int rx, int ry);
bool MouseMove(int x, int y, int dx, int dy);
bool MouseDown(int x, int y, unsigned button);
bool MouseUp(int x, int y, unsigned button);
diff --git a/src/simulation/Simulation.cpp b/src/simulation/Simulation.cpp
index 9cac3cf..b5d07bc 100644
--- a/src/simulation/Simulation.cpp
+++ b/src/simulation/Simulation.cpp
@@ -3174,14 +3174,14 @@ void Simulation::update_particles_i(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
@@ -3196,7 +3196,7 @@ void Simulation::update_particles_i(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
@@ -3204,8 +3204,8 @@ void Simulation::update_particles_i(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] ++;
}
}
}
@@ -3219,23 +3219,23 @@ void Simulation::update_particles_i(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 --;
@@ -3244,7 +3244,7 @@ void Simulation::update_particles_i(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.
}
}
//memset(gol2, 0, sizeof(gol2));
diff --git a/src/simulation/Simulation.h b/src/simulation/Simulation.h
index 60a010c..7095c66 100644
--- a/src/simulation/Simulation.h
+++ b/src/simulation/Simulation.h
@@ -77,8 +77,8 @@ public:
int CGOL;
int ISGOL;
int GSPEED;
- unsigned char gol[XRES][YRES];
- unsigned char gol2[XRES][YRES][NGOL+1];
+ unsigned char gol[YRES][XRES];
+ unsigned char gol2[YRES][XRES][NGOL+1];
//Air sim
float (*vx)[XRES/CELL];
float (*vy)[XRES/CELL];
diff --git a/src/simulation/elements/PLNT.cpp b/src/simulation/elements/PLNT.cpp
index 92a4fdf..9c87e22 100644
--- a/src/simulation/elements/PLNT.cpp
+++ b/src/simulation/elements/PLNT.cpp
@@ -73,7 +73,7 @@ int Element_PLNT::update(UPDATE_FUNC_ARGS)
sim->kill_part(r>>8);
parts[i].life = rand()%60 + 60;
}
- else if (surround_space && ((r&0xFF)==PT_WOOD) && (1>rand()%20) && (abs(rx+ry)<=2) && (VINE_MODE || parts[i].tmp==1) )
+ else if (surround_space && ((r&0xFF)==PT_WOOD) && (1>rand()%20) && (abs(rx+ry)<=2) && (sim->VINE_MODE || parts[i].tmp==1) )
{
int nnx = rand()%3 -1;
int nny = rand()%3 -1;
diff --git a/src/simulation/elements/STKM.cpp b/src/simulation/elements/STKM.cpp
index fb0ade0..ee35105 100644
--- a/src/simulation/elements/STKM.cpp
+++ b/src/simulation/elements/STKM.cpp
@@ -510,15 +510,15 @@ void Element_STKM::STKM_interact(Simulation * sim, playerst* playerp, int i, int
break;
}
}
- if (((r&0xFF)==PT_BHOL || (r&0xFF)==PT_NBHL) && parts[i].type)
+ if (((r&0xFF)==PT_BHOL || (r&0xFF)==PT_NBHL) && sim->parts[i].type)
{
if (!sim->legacy_enable)
{
- parts[r>>8].temp = restrict_flt(parts[r>>8].temp+parts[i].temp/2, MIN_TEMP, MAX_TEMP);
+ sim->parts[r>>8].temp = restrict_flt(sim->parts[r>>8].temp+sim->parts[i].temp/2, MIN_TEMP, MAX_TEMP);
}
sim->kill_part(i);
}
- if (((r&0xFF)==PT_VOID || ((r&0xFF)==PT_PVOD && parts[r>>8].life==10)) && (!parts[r>>8].ctype || (parts[r>>8].ctype==parts[i].type)!=(parts[r>>8].tmp&1)) && parts[i].type)
+ if (((r&0xFF)==PT_VOID || ((r&0xFF)==PT_PVOD && sim->parts[r>>8].life==10)) && (!sim->parts[r>>8].ctype || (sim->parts[r>>8].ctype==sim->parts[i].type)!=(sim->parts[r>>8].tmp&1)) && sim->parts[i].type)
{
sim->kill_part(i);
}