summaryrefslogtreecommitdiff
path: root/src/simulation
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-05-12 17:11:20 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-05-12 17:11:20 (GMT)
commitc5798c745675e4866a44228ddf161258e85d39a7 (patch)
tree6788dbb3c89632f8a1f2acc4038a93faa26b6324 /src/simulation
parent16d3895e9c054e908ca8b230719f4294e824a4a2 (diff)
downloadpowder-c5798c745675e4866a44228ddf161258e85d39a7.zip
powder-c5798c745675e4866a44228ddf161258e85d39a7.tar.gz
Tools implemented in a similar way to elements
Diffstat (limited to 'src/simulation')
-rw-r--r--src/simulation/Simulation.cpp109
-rw-r--r--src/simulation/Simulation.h8
-rw-r--r--src/simulation/SimulationData.h3
-rw-r--r--src/simulation/Tools.h7
-rw-r--r--src/simulation/tools/Cool.cpp19
-rw-r--r--src/simulation/tools/Heat.cpp19
-rw-r--r--src/simulation/tools/SimTool.cpp10
-rw-r--r--src/simulation/tools/SimTool.h23
8 files changed, 197 insertions, 1 deletions
diff --git a/src/simulation/Simulation.cpp b/src/simulation/Simulation.cpp
index 354c759..914df7e 100644
--- a/src/simulation/Simulation.cpp
+++ b/src/simulation/Simulation.cpp
@@ -608,6 +608,113 @@ void Simulation::ApplyDecorationLine(int x1, int y1, int x2, int y2, int rx, int
}
}
+int Simulation::Tool(int x, int y, int tool, float strength)
+{
+ if(tools[tool])
+ {
+ Particle * cpart = NULL;
+ int r;
+ if(r = pmap[y][x])
+ cpart = &(parts[r>>8]);
+ else if(r = photons[y][x])
+ cpart = &(parts[r>>8]);
+ return tools[tool]->Perform(this, cpart, x, y, strength);
+ }
+ return 0;
+}
+
+int Simulation::ToolBrush(int x, int y, int tool, Brush * cBrush)
+{
+ int rx, ry, j, i;
+ if(!cBrush)
+ return 0;
+ rx = cBrush->GetRadius().X;
+ ry = cBrush->GetRadius().Y;
+ unsigned char *bitmap = cBrush->GetBitmap();
+ for (j=-ry; j<=ry; j++)
+ for (i=-rx; i<=rx; i++)
+ if(bitmap[(j+ry)*((rx*2)+1)+(i+rx+1)])
+ {
+ if ( x+i<0 || y+j<0 || x+i>=XRES || y+j>=YRES)
+ continue;
+ Tool(x+i, y+j, tool, 1.0f);
+ }
+}
+
+void Simulation::ToolLine(int x1, int y1, int x2, int y2, int tool, Brush * cBrush)
+{
+ int cp=abs(y2-y1)>abs(x2-x1), x, y, dx, dy, sy, rx, ry;
+ float e, de;
+ rx = cBrush->GetRadius().X;
+ ry = cBrush->GetRadius().Y;
+ if (cp)
+ {
+ y = x1;
+ x1 = y1;
+ y1 = y;
+ y = x2;
+ x2 = y2;
+ y2 = y;
+ }
+ if (x1 > x2)
+ {
+ y = x1;
+ x1 = x2;
+ x2 = y;
+ y = y1;
+ y1 = y2;
+ y2 = y;
+ }
+ dx = x2 - x1;
+ dy = abs(y2 - y1);
+ e = 0.0f;
+ if (dx)
+ de = dy/(float)dx;
+ else
+ de = 0.0f;
+ y = y1;
+ sy = (y1<y2) ? 1 : -1;
+ for (x=x1; x<=x2; x++)
+ {
+ if (cp)
+ ToolBrush(y, x, tool, cBrush);
+ else
+ ToolBrush(x, y, tool, cBrush);
+ e += de;
+ if (e >= 0.5f)
+ {
+ y += sy;
+ if ((!(rx+ry)) && ((y1<y2) ? (y<=y2) : (y>=y2)))
+ {
+ if (cp)
+ ToolBrush(y, x, tool, cBrush);
+ else
+ ToolBrush(x, y, tool, cBrush);
+ }
+ e -= 1.0f;
+ }
+ }
+}
+void Simulation::ToolBox(int x1, int y1, int x2, int y2, int tool, Brush * cBrush)
+{
+ int i, j;
+ if (x1>x2)
+ {
+ i = x2;
+ x2 = x1;
+ x1 = i;
+ }
+ if (y1>y2)
+ {
+ j = y2;
+ y2 = y1;
+ y1 = j;
+ }
+ for (j=y1; j<=y2; j++)
+ for (i=x1; i<=x2; i++)
+ ToolBrush(i, j, tool, cBrush);
+}
+
//this creates particles from a brush, don't use if you want to create one particle
int Simulation::CreateParts(int x, int y, int rx, int ry, int c, int flags, Brush * cBrush)
{
@@ -3762,6 +3869,8 @@ Simulation::Simulation():
{
elements[i] = elementList[i];
}
+
+ tools = GetTools();
int golRulesCount;
int * golRulesT = LoadGOLRules(golRulesCount);
diff --git a/src/simulation/Simulation.h b/src/simulation/Simulation.h
index 9ed763a..71f233d 100644
--- a/src/simulation/Simulation.h
+++ b/src/simulation/Simulation.h
@@ -12,11 +12,11 @@
#include "Renderer.h"
#include "Graphics.h"
#include "Elements.h"
+#include "Tools.h"
#include "Misc.h"
#include "game/Brush.h"
#include "Gravity.h"
#include "SimulationData.h"
-//#include "ElementFunctions.h"
#define CHANNELS ((int)(MAX_TEMP-73)/100+2)
@@ -140,6 +140,7 @@ public:
Air * air;
Element * elements;
+ vector<SimTool*> tools;
unsigned int * platent;
wall_type wtypes[UI_WALLCOUNT];
gol_menu gmenu[NGOL];
@@ -244,6 +245,11 @@ public:
void update_particles();
void rotate_area(int area_x, int area_y, int area_w, int area_h, int invert);
void clear_area(int area_x, int area_y, int area_w, int area_h);
+
+ 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);
void CreateBox(int x1, int y1, int x2, int y2, int c, int flags);
int FloodParts(int x, int y, int c, int cm, int bm, int flags);
diff --git a/src/simulation/SimulationData.h b/src/simulation/SimulationData.h
index 5e48e94..c24ce39 100644
--- a/src/simulation/SimulationData.h
+++ b/src/simulation/SimulationData.h
@@ -156,7 +156,10 @@ struct menu_section;
struct wall_type;
+class SimTool;
+
class Element;
+
std::vector<Element*> GetDefaultElements();
gol_menu * LoadGOLMenu(int & golMenuCount);
diff --git a/src/simulation/Tools.h b/src/simulation/Tools.h
new file mode 100644
index 0000000..525701e
--- /dev/null
+++ b/src/simulation/Tools.h
@@ -0,0 +1,7 @@
+#ifndef TOOLS_H_
+#define TOOLS_H_
+
+#include "ToolClasses.h"
+
+
+#endif
diff --git a/src/simulation/tools/Cool.cpp b/src/simulation/tools/Cool.cpp
new file mode 100644
index 0000000..12a6b28
--- /dev/null
+++ b/src/simulation/tools/Cool.cpp
@@ -0,0 +1,19 @@
+#include "simulation/Tools.h"
+//#TPT-Directive ToolClass Tool_Cool TOOL_COOL 1
+Tool_Cool::Tool_Cool()
+{
+ Identifier = "DEFAULT_TOOL_COOL";
+ Name = "COOL";
+ Colour = PIXPACK(0x00DDFF);
+ Description = "Cools particles";
+}
+
+int Tool_Cool::Perform(Simulation * sim, Particle * cpart, int x, int y, float strength)
+{
+ if(!cpart)
+ return 0;
+ cpart->temp -= strength;
+ return 1;
+}
+
+Tool_Cool::~Tool_Cool() {} \ No newline at end of file
diff --git a/src/simulation/tools/Heat.cpp b/src/simulation/tools/Heat.cpp
new file mode 100644
index 0000000..a2c500c
--- /dev/null
+++ b/src/simulation/tools/Heat.cpp
@@ -0,0 +1,19 @@
+#include "simulation/Tools.h"
+//#TPT-Directive ToolClass Tool_Heat TOOL_HEAT 0
+Tool_Heat::Tool_Heat()
+{
+ Identifier = "DEFAULT_TOOL_HEAT";
+ Name = "HEAT";
+ Colour = PIXPACK(0xFFDD00);
+ Description = "Heats particles";
+}
+
+int Tool_Heat::Perform(Simulation * sim, Particle * cpart, int x, int y, float strength)
+{
+ if(!cpart)
+ return 0;
+ cpart->temp += strength;
+ return 1;
+}
+
+Tool_Heat::~Tool_Heat() {} \ No newline at end of file
diff --git a/src/simulation/tools/SimTool.cpp b/src/simulation/tools/SimTool.cpp
new file mode 100644
index 0000000..d7015fa
--- /dev/null
+++ b/src/simulation/tools/SimTool.cpp
@@ -0,0 +1,10 @@
+#include "simulation/Element.h"
+#include "simulation/Tools.h"
+
+SimTool::SimTool():
+Identifier("DEFAULT_TOOL_INVALID"),
+Name(""),
+Colour(PIXPACK(0xFFFFFF)),
+Description("NULL Tool, does NOTHING")
+{
+} \ No newline at end of file
diff --git a/src/simulation/tools/SimTool.h b/src/simulation/tools/SimTool.h
new file mode 100644
index 0000000..0fbcba4
--- /dev/null
+++ b/src/simulation/tools/SimTool.h
@@ -0,0 +1,23 @@
+#ifndef SIMTOOL_H
+#define SIMTOOL_H
+
+#include "simulation/Simulation.h"
+#include "Renderer.h"
+#include "simulation/Elements.h"
+
+class Simulation;
+struct Particle;
+class SimTool
+{
+public:
+ char *Identifier;
+ char *Name;
+ pixel Colour;
+ char *Description;
+
+ SimTool();
+ virtual ~SimTool() {}
+ virtual int Perform(Simulation * sim, Particle * cpart, int x, int y, float strength) {}
+};
+
+#endif \ No newline at end of file