From 810ea42f99cf9f56c1ac998ce8a203bea01e97b2 Mon Sep 17 00:00:00 2001 From: Simon Robertshaw Date: Fri, 10 Aug 2012 14:03:23 +0100 Subject: [PATCH] Only render gravity lensing if it's enabled, Ctrl and Shift to alter tool strength (Shift = x10, Ctrl = x0.1) --- SConscript | 1 + build/obj/.empty | 0 src/game/GameController.cpp | 9 +++++++++ src/game/GameModel.cpp | 13 ++++++++++++- src/game/GameModel.h | 4 ++++ src/game/GameView.cpp | 16 ++++++++++++++++ src/game/Tool.cpp | 12 ++++++++---- src/game/Tool.h | 3 +++ src/graphics/Renderer.cpp | 10 ++++++++-- src/simulation/Simulation.cpp | 18 +++++++++--------- src/simulation/Simulation.h | 8 ++++---- 11 files changed, 74 insertions(+), 20 deletions(-) delete mode 100644 build/obj/.empty diff --git a/SConscript b/SConscript index ed885242c..ae2e890b4 100644 --- a/SConscript +++ b/SConscript @@ -221,6 +221,7 @@ if(GetOption('win')): env.Command(['generated/ElementClasses.cpp', 'generated/ElementClasses.h'], Glob('src/simulation/elements/*.cpp'), "python generator.py elements $TARGETS $SOURCES") env.Command(['generated/ToolClasses.cpp', 'generated/ToolClasses.h'], Glob('src/simulation/tools/*.cpp'), "python generator.py tools $TARGETS $SOURCES") t=env.Program(target=programName, source=sources) +Decider('MD5') Default(t) #if(GetOption('release')): diff --git a/build/obj/.empty b/build/obj/.empty deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/game/GameController.cpp b/src/game/GameController.cpp index 3d36b75cb..622752b59 100644 --- a/src/game/GameController.cpp +++ b/src/game/GameController.cpp @@ -248,6 +248,7 @@ void GameController::DrawRect(int toolSelection, ui::Point point1, ui::Point poi Brush * cBrush = gameModel->GetBrush(); if(!activeTool || !cBrush) return; + activeTool->SetStrength(gameModel->GetToolStrength()); activeTool->DrawRect(sim, cBrush, PointTranslate(point1), PointTranslate(point2)); } @@ -258,6 +259,7 @@ void GameController::DrawLine(int toolSelection, ui::Point point1, ui::Point poi Brush * cBrush = gameModel->GetBrush(); if(!activeTool || !cBrush) return; + activeTool->SetStrength(gameModel->GetToolStrength()); activeTool->DrawLine(sim, cBrush, PointTranslate(point1), PointTranslate(point2)); } @@ -268,6 +270,7 @@ void GameController::DrawFill(int toolSelection, ui::Point point) Brush * cBrush = gameModel->GetBrush(); if(!activeTool || !cBrush) return; + activeTool->SetStrength(gameModel->GetToolStrength()); activeTool->DrawFill(sim, cBrush, PointTranslate(point)); } @@ -288,6 +291,7 @@ void GameController::DrawPoints(int toolSelection, queue & pointQueu } } + activeTool->SetStrength(gameModel->GetToolStrength()); if(!pointQueue.empty()) { ui::Point sPoint(0, 0); @@ -595,6 +599,11 @@ void GameController::SetZoomEnabled(bool zoomEnabled) gameModel->SetZoomEnabled(zoomEnabled); } +void GameController::SetToolStrength(float value) +{ + gameModel->SetToolStrength(value); +} + void GameController::SetZoomPosition(ui::Point position) { ui::Point zoomPosition = position-(gameModel->GetZoomSize()/2); diff --git a/src/game/GameModel.cpp b/src/game/GameModel.cpp index 91ddd53e2..3da3074da 100644 --- a/src/game/GameModel.cpp +++ b/src/game/GameModel.cpp @@ -23,7 +23,8 @@ GameModel::GameModel(): clipboard(NULL), stamp(NULL), placeSave(NULL), - colour(255, 0, 0, 255) + colour(255, 0, 0, 255), + toolStrength(1.0f) { sim = new Simulation(); ren = new Renderer(ui::Engine::Ref().g, sim); @@ -295,6 +296,16 @@ void GameModel::AddObserver(GameView * observer){ UpdateQuickOptions(); } +void GameModel::SetToolStrength(float value) +{ + toolStrength = value; +} + +float GameModel::GetToolStrength() +{ + return toolStrength; +} + void GameModel::SetActiveMenu(Menu * menu) { for(int i = 0; i < menuList.size(); i++) diff --git a/src/game/GameModel.h b/src/game/GameModel.h index e41ff2b58..47a6904d0 100644 --- a/src/game/GameModel.h +++ b/src/game/GameModel.h @@ -55,6 +55,7 @@ private: User currentUser; bool colourSelector; ui::Colour colour; + float toolStrength; std::string infoTip; std::string toolTip; @@ -99,6 +100,9 @@ public: void UpdateQuickOptions(); + void SetToolStrength(float value); + float GetToolStrength(); + void SetVote(int direction); SaveInfo * GetSave(); Brush * GetBrush(); diff --git a/src/game/GameView.cpp b/src/game/GameView.cpp index 9b1010d85..817887ed7 100644 --- a/src/game/GameView.cpp +++ b/src/game/GameView.cpp @@ -1538,6 +1538,10 @@ void GameView::enableShiftBehaviour() if(!shiftBehaviour) { shiftBehaviour = true; + if(!ctrlBehaviour) + c->SetToolStrength(10.0f); + else + c->SetToolStrength(1.0f); } } @@ -1546,6 +1550,10 @@ void GameView::disableShiftBehaviour() if(shiftBehaviour) { shiftBehaviour = false; + if(!ctrlBehaviour) + c->SetToolStrength(1.0f); + else + c->SetToolStrength(.1f); } } @@ -1576,6 +1584,10 @@ void GameView::enableCtrlBehaviour() saveSimulationButton->Appearance.TextInactive = ui::Colour(0, 0, 0); searchButton->Appearance.BackgroundInactive = ui::Colour(255, 255, 255); searchButton->Appearance.TextInactive = ui::Colour(0, 0, 0); + if(!shiftBehaviour) + c->SetToolStrength(.1f); + else + c->SetToolStrength(1.0f); } } @@ -1590,6 +1602,10 @@ void GameView::disableCtrlBehaviour() saveSimulationButton->Appearance.TextInactive = ui::Colour(255, 255, 255); searchButton->Appearance.BackgroundInactive = ui::Colour(0, 0, 0); searchButton->Appearance.TextInactive = ui::Colour(255, 255, 255); + if(!shiftBehaviour) + c->SetToolStrength(1.0f); + else + c->SetToolStrength(10.0f); } } diff --git a/src/game/Tool.cpp b/src/game/Tool.cpp index 763fc8252..a93afaff6 100644 --- a/src/game/Tool.cpp +++ b/src/game/Tool.cpp @@ -19,7 +19,8 @@ Tool::Tool(int id, string name, string description, int r, int g, int b, VideoBu colRed(r), colGreen(g), colBlue(b), - textureGen(textureGen) + textureGen(textureGen), + strength(1.0f) { } VideoBuffer * Tool::GetTexture(int width, int height) @@ -39,13 +40,13 @@ string Tool::GetDescription() { return toolDescription; } Tool::~Tool() {} void Tool::Click(Simulation * sim, Brush * brush, ui::Point position) { } void Tool::Draw(Simulation * sim, Brush * brush, ui::Point position) { - sim->ToolBrush(position.X, position.Y, toolID, brush); + sim->ToolBrush(position.X, position.Y, toolID, brush, strength); } void Tool::DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2, bool dragging) { - sim->ToolLine(position1.X, position1.Y, position2.X, position2.Y, toolID, brush); + sim->ToolLine(position1.X, position1.Y, position2.X, position2.Y, toolID, brush, strength); } void Tool::DrawRect(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) { - sim->ToolBox(position1.X, position1.Y, position2.X, position2.Y, toolID, brush); + sim->ToolBox(position1.X, position1.Y, position2.X, position2.Y, toolID, brush, strength); } void Tool::DrawFill(Simulation * sim, Brush * brush, ui::Point position) {}; @@ -82,7 +83,9 @@ void WallTool::DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui if(dragging == false && toolID == WL_FAN && sim->bmap[wallY][wallX]==WL_FAN) { float newFanVelX = (position2.X-position1.X)*0.005f; + newFanVelX *= strength; float newFanVelY = (position2.Y-position1.Y)*0.005f; + newFanVelY *= strength; sim->FloodWalls(position1.X, position1.Y, WL_FLOODHELPER, -1, WL_FAN, 0); for (int j = 0; j < YRES/CELL; j++) for (int i = 0; i < XRES/CELL; i++) @@ -138,6 +141,7 @@ void WindTool::DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui int radiusX, radiusY, sizeX, sizeY; float strength = dragging?0.01f:0.002f; + strength *= this->strength; radiusX = brush->GetRadius().X; radiusY = brush->GetRadius().Y; diff --git a/src/game/Tool.h b/src/game/Tool.h index f6327cf83..c4f44bb27 100644 --- a/src/game/Tool.h +++ b/src/game/Tool.h @@ -25,10 +25,13 @@ protected: int toolID; string toolName; string toolDescription; + float strength; public: Tool(int id, string name, string description, int r, int g, int b, VideoBuffer * (*textureGen)(int, int, int) = NULL); string GetName(); string GetDescription(); + void SetStrength(float value) { strength = value; } + float GetStrength() { return strength; } VideoBuffer * GetTexture(int width, int height); void SetTextureGen(VideoBuffer * (*textureGen)(int, int, int)); virtual ~Tool(); diff --git a/src/graphics/Renderer.cpp b/src/graphics/Renderer.cpp index 162f79e54..ea3c84074 100644 --- a/src/graphics/Renderer.cpp +++ b/src/graphics/Renderer.cpp @@ -308,12 +308,18 @@ void Renderer::FinaliseParts() #endif #if defined(OGLI) && !defined(OGLR) - render_gravlensing(warpVid); + if(display_mode & DISPLAY_WARP) + { + render_gravlensing(warpVid); + } g->draw_image(vid, 0, 0, VIDXRES, VIDYRES, 255); #endif #if !defined(OGLR) && !defined(OGLI) - render_gravlensing(warpVid); + if(display_mode & DISPLAY_WARP) + { + render_gravlensing(warpVid); + } #endif } diff --git a/src/simulation/Simulation.cpp b/src/simulation/Simulation.cpp index 717eb80ed..841984e5e 100644 --- a/src/simulation/Simulation.cpp +++ b/src/simulation/Simulation.cpp @@ -1018,7 +1018,7 @@ int Simulation::Tool(int x, int y, int tool, float strength) return 0; } -int Simulation::ToolBrush(int x, int y, int tool, Brush * cBrush) +int Simulation::ToolBrush(int x, int y, int tool, Brush * cBrush, float strength) { int rx, ry, j, i; if(!cBrush) @@ -1032,11 +1032,11 @@ int Simulation::ToolBrush(int x, int y, int tool, Brush * cBrush) { if ( x+i<0 || y+j<0 || x+i>=XRES || y+j>=YRES) continue; - Tool(x+i, y+j, tool, 1.0f); + Tool(x+i, y+j, tool, strength); } } -void Simulation::ToolLine(int x1, int y1, int x2, int y2, int tool, Brush * cBrush) +void Simulation::ToolLine(int x1, int y1, int x2, int y2, int tool, Brush * cBrush, float strength) { int cp=abs(y2-y1)>abs(x2-x1), x, y, dx, dy, sy, rx, ry; float e, de; @@ -1072,9 +1072,9 @@ void Simulation::ToolLine(int x1, int y1, int x2, int y2, int tool, Brush * cBru for (x=x1; x<=x2; x++) { if (cp) - ToolBrush(y, x, tool, cBrush); + ToolBrush(y, x, tool, cBrush, strength); else - ToolBrush(x, y, tool, cBrush); + ToolBrush(x, y, tool, cBrush, strength); e += de; if (e >= 0.5f) { @@ -1082,15 +1082,15 @@ void Simulation::ToolLine(int x1, int y1, int x2, int y2, int tool, Brush * cBru if ((!(rx+ry)) && ((y1=y2))) { if (cp) - ToolBrush(y, x, tool, cBrush); + ToolBrush(y, x, tool, cBrush, strength); else - ToolBrush(x, y, tool, cBrush); + ToolBrush(x, y, tool, cBrush, strength); } e -= 1.0f; } } } -void Simulation::ToolBox(int x1, int y1, int x2, int y2, int tool, Brush * cBrush) +void Simulation::ToolBox(int x1, int y1, int x2, int y2, int tool, Brush * cBrush, float strength) { int i, j; if (x1>x2) @@ -1107,7 +1107,7 @@ void Simulation::ToolBox(int x1, int y1, int x2, int y2, int tool, Brush * cBrus } for (j=y1; j<=y2; j++) for (i=x1; i<=x2; i++) - ToolBrush(i, j, tool, cBrush); + ToolBrush(i, j, tool, cBrush, strength); } int Simulation::CreateParts(int positionX, int positionY, int c, Brush * cBrush) diff --git a/src/simulation/Simulation.h b/src/simulation/Simulation.h index 9b10df2ff..387d3b3e5 100644 --- a/src/simulation/Simulation.h +++ b/src/simulation/Simulation.h @@ -159,10 +159,10 @@ public: void SetEdgeMode(int newEdgeMode); - int Tool(int x, int y, int tool, float strength); - int ToolBrush(int x, int y, int tool, Brush * cBrush); - void ToolLine(int x1, int y1, int x2, int y2, int tool, Brush * cBrush); - void ToolBox(int x1, int y1, int x2, int y2, int tool, Brush * cBrush); + int Tool(int x, int y, int tool, float strength = 1.0f); + int ToolBrush(int x, int y, int tool, Brush * cBrush, float strength = 1.0f); + void ToolLine(int x1, int y1, int x2, int y2, int tool, Brush * cBrush, float strength = 1.0f); + void ToolBox(int x1, int y1, int x2, int y2, int tool, Brush * cBrush, float strength = 1.0f); void CreateBox(int x1, int y1, int x2, int y2, int c, int flags); int FloodINST(int x, int y, int fullc, int cm);