From 0a63e1afb5a3fe0a7b042a80b7356352d95c4f20 Mon Sep 17 00:00:00 2001 From: jombo23 Date: Tue, 13 Feb 2018 00:08:00 -0500 Subject: [PATCH] Add Cyclone Tool and Brush X/Y Arguments (#542) --- generator.py | 2 +- src/simulation/Simulation.cpp | 11 ++++--- src/simulation/Simulation.h | 2 +- src/simulation/simtools/AirTool.cpp | 2 +- src/simulation/simtools/Cool.cpp | 2 +- src/simulation/simtools/Cyclone.cpp | 45 +++++++++++++++++++++++++++++ src/simulation/simtools/Heat.cpp | 2 +- src/simulation/simtools/Mix.cpp | 2 +- src/simulation/simtools/NGrv.cpp | 2 +- src/simulation/simtools/PGrv.cpp | 2 +- src/simulation/simtools/SimTool.h | 2 +- src/simulation/simtools/Vac.cpp | 2 +- 12 files changed, 62 insertions(+), 14 deletions(-) create mode 100644 src/simulation/simtools/Cyclone.cpp diff --git a/generator.py b/generator.py index 9569a5c1ee..1dedeb83d1 100644 --- a/generator.py +++ b/generator.py @@ -194,7 +194,7 @@ class {0}: public SimTool public: {0}(); virtual ~{0}(); - virtual int Perform(Simulation * sim, Particle * cpart, int x, int y, float strength); + virtual int Perform(Simulation * sim, Particle * cpart, int x, int y, int brushX, int brushY, float strength); }}; """.format(className, str.join("\n", classMembers)) diff --git a/src/simulation/Simulation.cpp b/src/simulation/Simulation.cpp index 146bb34b4a..020a5990dc 100644 --- a/src/simulation/Simulation.cpp +++ b/src/simulation/Simulation.cpp @@ -1192,7 +1192,7 @@ void Simulation::ApplyDecorationFill(Renderer *ren, int x, int y, int colR, int free(bitmap); } -int Simulation::Tool(int x, int y, int tool, float strength) +int Simulation::Tool(int x, int y, int tool, int brushX, int brushY, float strength) { if(tools[tool]) { @@ -1202,7 +1202,7 @@ int Simulation::Tool(int x, int y, int tool, float strength) cpart = &(parts[ID(r)]); else if ((r = photons[y][x])) cpart = &(parts[ID(r)]); - return tools[tool]->Perform(this, cpart, x, y, strength); + return tools[tool]->Perform(this, cpart, x, y, brushX, brushY, strength); } return 0; } @@ -1216,7 +1216,7 @@ int Simulation::ToolBrush(int positionX, int positionY, int tool, Brush * cBrush for(int y = 0; y < sizeY; y++) for(int x = 0; x < sizeX; x++) if(bitmap[(y*sizeX)+x] && (positionX+(x-radiusX) >= 0 && positionY+(y-radiusY) >= 0 && positionX+(x-radiusX) < XRES && positionY+(y-radiusY) < YRES)) - Tool(positionX+(x-radiusX), positionY+(y-radiusY), tool, strength); + Tool(positionX + (x - radiusX), positionY + (y - radiusY), tool, positionX, positionY, strength); } return 0; } @@ -1275,6 +1275,9 @@ void Simulation::ToolLine(int x1, int y1, int x2, int y2, int tool, Brush * cBru } void Simulation::ToolBox(int x1, int y1, int x2, int y2, int tool, float strength) { + int brushX, brushY; + brushX = ((x1 + x2) / 2); + brushY = ((y1 + y2) / 2); int i, j; if (x1>x2) { @@ -1290,7 +1293,7 @@ void Simulation::ToolBox(int x1, int y1, int x2, int y2, int tool, float strengt } for (j=y1; j<=y2; j++) for (i=x1; i<=x2; i++) - Tool(i, j, tool, strength); + Tool(i, j, tool, brushX, brushY, strength); } int Simulation::CreateWalls(int x, int y, int rx, int ry, int wall, Brush * cBrush) diff --git a/src/simulation/Simulation.h b/src/simulation/Simulation.h index 441dcb70fb..e8b89bbf5c 100644 --- a/src/simulation/Simulation.h +++ b/src/simulation/Simulation.h @@ -177,7 +177,7 @@ class Simulation void ApplyDecorationFill(Renderer *ren, int x, int y, int colR, int colG, int colB, int colA, int replaceR, int replaceG, int replaceB); //Drawing Tools like HEAT, AIR, and GRAV - int Tool(int x, int y, int tool, float strength = 1.0f); + int Tool(int x, int y, int tool, int brushX, int brushY, 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, float strength = 1.0f); diff --git a/src/simulation/simtools/AirTool.cpp b/src/simulation/simtools/AirTool.cpp index 506252e2f7..2694de1f68 100644 --- a/src/simulation/simtools/AirTool.cpp +++ b/src/simulation/simtools/AirTool.cpp @@ -9,7 +9,7 @@ Tool_Air::Tool_Air() Description = "Air, creates airflow and pressure."; } -int Tool_Air::Perform(Simulation * sim, Particle * cpart, int x, int y, float strength) +int Tool_Air::Perform(Simulation * sim, Particle * cpart, int x, int y, int brushX, int brushY, float strength) { sim->air->pv[y/CELL][x/CELL] += strength*0.05f; diff --git a/src/simulation/simtools/Cool.cpp b/src/simulation/simtools/Cool.cpp index db49e6115a..5c9ba55c06 100644 --- a/src/simulation/simtools/Cool.cpp +++ b/src/simulation/simtools/Cool.cpp @@ -8,7 +8,7 @@ Tool_Cool::Tool_Cool() Description = "Cools the targeted element."; } -int Tool_Cool::Perform(Simulation * sim, Particle * cpart, int x, int y, float strength) +int Tool_Cool::Perform(Simulation * sim, Particle * cpart, int x, int y, int brushX, int brushY, float strength) { if(!cpart) return 0; diff --git a/src/simulation/simtools/Cyclone.cpp b/src/simulation/simtools/Cyclone.cpp new file mode 100644 index 0000000000..49d6fafa7c --- /dev/null +++ b/src/simulation/simtools/Cyclone.cpp @@ -0,0 +1,45 @@ +#include "ToolClasses.h" +#include "simulation/Air.h" +//#TPT-Directive ToolClass Tool_Cycl TOOL_CYCL 8 +Tool_Cycl::Tool_Cycl() +{ + Identifier = "DEFAULT_TOOL_CYCL"; + Name = "CYCL"; + Colour = PIXPACK(0x132f5b); + Description = "Cyclone. Produces swirling air currents"; +} + +int Tool_Cycl::Perform(Simulation * sim, Particle * cpart, int x, int y, int brushX, int brushY, float strength) +{ + /* + Air velocity calculation. + Air velocity X = cosine of cell angle + Angle of cell is calculated via cells X/Y relation to the brush center and arctangent + Angle has 1.57 radians added to it (90 degrees) in order to make the velocity be at 90 degrees to the centerpoint. + Ditto for X, except X uses sine + */ + // only trigger once per cell (less laggy) + if ((x%CELL) == 0 && (y%CELL) == 0) + { + float *vx = &sim->air->vx[y/CELL][x/CELL]; + float *vy = &sim->air->vy[y/CELL][x/CELL]; + + *vx -= (strength / 16) * (cos(1.57f + (atan2(brushY - y, brushX - x)))); + *vy -= (strength / 16) * (sin(1.57f + (atan2(brushY - y, brushX - x)))); + + // Clamp velocities + if (*vx > 256.0f) + *vx = 256.0f; + else if (*vx < -256.0f) + *vx = -256.0f; + if (*vy > 256.0f) + *vy = 256.0f; + else if (*vy < -256.0f) + *vy = -256.0f; + + } + + return 1; +} + +Tool_Cycl::~Tool_Cycl() {} diff --git a/src/simulation/simtools/Heat.cpp b/src/simulation/simtools/Heat.cpp index dac33477fc..8355a2dafa 100644 --- a/src/simulation/simtools/Heat.cpp +++ b/src/simulation/simtools/Heat.cpp @@ -8,7 +8,7 @@ Tool_Heat::Tool_Heat() Description = "Heats the targeted element."; } -int Tool_Heat::Perform(Simulation * sim, Particle * cpart, int x, int y, float strength) +int Tool_Heat::Perform(Simulation * sim, Particle * cpart, int x, int y, int brushX, int brushY, float strength) { if(!cpart) return 0; diff --git a/src/simulation/simtools/Mix.cpp b/src/simulation/simtools/Mix.cpp index aec342acc3..6065b6e6dc 100755 --- a/src/simulation/simtools/Mix.cpp +++ b/src/simulation/simtools/Mix.cpp @@ -8,7 +8,7 @@ Tool_Mix::Tool_Mix() Description = "Mixes particles."; } -int Tool_Mix::Perform(Simulation * sim, Particle * cpart, int x, int y, float strength) +int Tool_Mix::Perform(Simulation * sim, Particle * cpart, int x, int y, int brushX, int brushY, float strength) { int thisPart = sim->pmap[y][x]; if(!thisPart) diff --git a/src/simulation/simtools/NGrv.cpp b/src/simulation/simtools/NGrv.cpp index c1fa2c198d..81d13d0bb9 100644 --- a/src/simulation/simtools/NGrv.cpp +++ b/src/simulation/simtools/NGrv.cpp @@ -9,7 +9,7 @@ Tool_NGrv::Tool_NGrv() Description = "Creates a short-lasting negative gravity well."; } -int Tool_NGrv::Perform(Simulation * sim, Particle * cpart, int x, int y, float strength) +int Tool_NGrv::Perform(Simulation * sim, Particle * cpart, int x, int y, int brushX, int brushYy, float strength) { sim->gravmap[((y/CELL)*(XRES/CELL))+(x/CELL)] = strength*-5.0f; return 1; diff --git a/src/simulation/simtools/PGrv.cpp b/src/simulation/simtools/PGrv.cpp index a7635707ed..61043b2ff1 100644 --- a/src/simulation/simtools/PGrv.cpp +++ b/src/simulation/simtools/PGrv.cpp @@ -9,7 +9,7 @@ Tool_PGrv::Tool_PGrv() Description = "Creates a short-lasting gravity well."; } -int Tool_PGrv::Perform(Simulation * sim, Particle * cpart, int x, int y, float strength) +int Tool_PGrv::Perform(Simulation * sim, Particle * cpart, int x, int y, int brushX, int brushY, float strength) { sim->gravmap[((y/CELL)*(XRES/CELL))+(x/CELL)] = strength*5.0f; return 1; diff --git a/src/simulation/simtools/SimTool.h b/src/simulation/simtools/SimTool.h index 56cb14947a..f8ccda36e6 100644 --- a/src/simulation/simtools/SimTool.h +++ b/src/simulation/simtools/SimTool.h @@ -17,7 +17,7 @@ class SimTool SimTool(); virtual ~SimTool() {} - virtual int Perform(Simulation * sim, Particle * cpart, int x, int y, float strength) { return 0; } + virtual int Perform(Simulation * sim, Particle * cpart, int x, int y, int brushX, int brushY, float strength) { return 0; } }; #endif diff --git a/src/simulation/simtools/Vac.cpp b/src/simulation/simtools/Vac.cpp index eded57c3cc..f780bbcfbd 100644 --- a/src/simulation/simtools/Vac.cpp +++ b/src/simulation/simtools/Vac.cpp @@ -9,7 +9,7 @@ Tool_Vac::Tool_Vac() Description = "Vacuum, reduces air pressure."; } -int Tool_Vac::Perform(Simulation * sim, Particle * cpart, int x, int y, float strength) +int Tool_Vac::Perform(Simulation * sim, Particle * cpart, int x, int y, int brushX, int brushY, float strength) { sim->air->pv[y/CELL][x/CELL] -= strength*0.05f;