Add Cyclone Tool and Brush X/Y Arguments (#542)

This commit is contained in:
jombo23 2018-02-13 00:08:00 -05:00 committed by jacob1
parent 30b8078ad2
commit 0a63e1afb5
12 changed files with 62 additions and 14 deletions

View File

@ -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))

View File

@ -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)

View File

@ -177,7 +177,7 @@ public:
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);

View File

@ -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;

View File

@ -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;

View File

@ -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() {}

View File

@ -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;

View File

@ -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)

View File

@ -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;

View File

@ -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;

View File

@ -17,7 +17,7 @@ public:
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

View File

@ -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;