summaryrefslogtreecommitdiff
path: root/src/simulation
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-05-14 23:10:10 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-05-14 23:10:10 (GMT)
commit45563e97e813cfd21724ad1111e5de3e04679e1a (patch)
tree28d6e7d257c8790fa4ac892cb051bd9a86f3681d /src/simulation
parent0b4ad4f25cf168226677f648cf4cadfdb6caa59a (diff)
downloadpowder-45563e97e813cfd21724ad1111e5de3e04679e1a.zip
powder-45563e97e813cfd21724ad1111e5de3e04679e1a.tar.gz
Make flood_prop use PropertyType from StructProperty, Property tool works
Diffstat (limited to 'src/simulation')
-rw-r--r--src/simulation/Simulation.cpp26
-rw-r--r--src/simulation/Simulation.h7
-rw-r--r--src/simulation/elements/BANG.cpp2
3 files changed, 23 insertions, 12 deletions
diff --git a/src/simulation/Simulation.cpp b/src/simulation/Simulation.cpp
index a992ef8..0032bb2 100644
--- a/src/simulation/Simulation.cpp
+++ b/src/simulation/Simulation.cpp
@@ -88,7 +88,7 @@ void Simulation::CreateWallBox(int x1, int y1, int x2, int y2, int c, int flags)
CreateWalls(i, j, 0, 0, c, flags);
}
-int Simulation::flood_prop_2(int x, int y, size_t propoffset, void * propvalue, int proptype, int parttype, char * bitmap)
+int Simulation::flood_prop_2(int x, int y, size_t propoffset, void * propvalue, StructProperty::PropertyType proptype, int parttype, char * bitmap)
{
int x1, x2, i, dy = 1;
x1 = x2 = x;
@@ -111,12 +111,22 @@ int Simulation::flood_prop_2(int x, int y, size_t propoffset, void * propvalue,
for (x=x1; x<=x2; x++)
{
i = pmap[y][x]>>8;
- if(proptype==2){
- *((float*)(((char*)&parts[i])+propoffset)) = *((float*)propvalue);
- } else if(proptype==0) {
- *((int*)(((char*)&parts[i])+propoffset)) = *((int*)propvalue);
- } else if(proptype==1) {
- *((char*)(((char*)&parts[i])+propoffset)) = *((char*)propvalue);
+ switch (proptype) {
+ case StructProperty::Float:
+ *((float*)(((char*)&parts[i])+propoffset)) = *((float*)propvalue);
+ break;
+
+ case StructProperty::ParticleType:
+ case StructProperty::Integer:
+ *((int*)(((char*)&parts[i])+propoffset)) = *((int*)propvalue);
+ break;
+
+ case StructProperty::UInteger:
+ *((unsigned int*)(((char*)&parts[i])+propoffset)) = *((unsigned int*)propvalue);
+ break;
+
+ default:
+ break;
}
bitmap[(y*XRES)+x] = 1;
}
@@ -133,7 +143,7 @@ int Simulation::flood_prop_2(int x, int y, size_t propoffset, void * propvalue,
return 1;
}
-int Simulation::flood_prop(int x, int y, size_t propoffset, void * propvalue, int proptype)
+int Simulation::flood_prop(int x, int y, size_t propoffset, void * propvalue, StructProperty::PropertyType proptype)
{
int r = 0;
char * bitmap = (char *)malloc(XRES*YRES); //Bitmap for checking
diff --git a/src/simulation/Simulation.h b/src/simulation/Simulation.h
index 6a7c733..fe65d41 100644
--- a/src/simulation/Simulation.h
+++ b/src/simulation/Simulation.h
@@ -32,6 +32,7 @@ struct StructProperty
std::string Name;
PropertyType Type;
intptr_t Offset;
+
StructProperty(std::string name, PropertyType type, intptr_t offset):
Name(name),
Type(type),
@@ -54,7 +55,7 @@ struct Particle
unsigned int dcolour;
/** Returns a list of properties, their type and offset within the structure that can be changed
by higher-level processes refering to them by name such as Lua or the property tool **/
- std::vector<StructProperty> GetProperties()
+ static std::vector<StructProperty> GetProperties()
{
std::vector<StructProperty> properties;
properties.push_back(StructProperty("type", StructProperty::ParticleType, offsetof(Particle, type)));
@@ -269,8 +270,8 @@ public:
void create_cherenkov_photon(int pp);
void create_gain_photon(int pp);
inline void kill_part(int i);
- int flood_prop(int x, int y, size_t propoffset, void * propvalue, int proptype);
- int flood_prop_2(int x, int y, size_t propoffset, void * propvalue, int proptype, int parttype, char * bitmap);
+ int flood_prop(int x, int y, size_t propoffset, void * propvalue, StructProperty::PropertyType proptype);
+ int flood_prop_2(int x, int y, size_t propoffset, void * propvalue, StructProperty::PropertyType proptype, int parttype, char * bitmap);
int flood_water(int x, int y, int i, int originaly, int check);
inline void detach(int i);
inline void part_change_type(int i, int x, int y, int t);
diff --git a/src/simulation/elements/BANG.cpp b/src/simulation/elements/BANG.cpp
index ac538ca..ea22b05 100644
--- a/src/simulation/elements/BANG.cpp
+++ b/src/simulation/elements/BANG.cpp
@@ -76,7 +76,7 @@ int Element_BANG::update(UPDATE_FUNC_ARGS)
else if(parts[i].tmp==1)
{
int tempvalue = 2;
- sim->flood_prop(x, y, offsetof(Particle, tmp), &tempvalue, 0);
+ sim->flood_prop(x, y, offsetof(Particle, tmp), &tempvalue, StructProperty::Integer);
}
else if(parts[i].tmp==2)
{