summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-07-29 11:18:07 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-07-29 11:18:07 (GMT)
commit824bde4cebd78aa04c9018171316f7533307e0ce (patch)
treed67afd50f83584e6b8a461193abd34eec929e0db /src
parent1f914561b2049ac779d8a729d9e910c4915b280b (diff)
downloadpowder-824bde4cebd78aa04c9018171316f7533307e0ce.zip
powder-824bde4cebd78aa04c9018171316f7533307e0ce.tar.gz
clear_sim now clears air and gravity maps better, fixes issue #31
Diffstat (limited to 'src')
-rw-r--r--src/simulation/Air.cpp9
-rw-r--r--src/simulation/Air.h1
-rw-r--r--src/simulation/Gravity.cpp9
-rw-r--r--src/simulation/Gravity.h2
-rw-r--r--src/simulation/Simulation.cpp22
5 files changed, 25 insertions, 18 deletions
diff --git a/src/simulation/Air.cpp b/src/simulation/Air.cpp
index ff3ea6e..6d7b5dd 100644
--- a/src/simulation/Air.cpp
+++ b/src/simulation/Air.cpp
@@ -36,6 +36,15 @@ void Air::make_kernel(void) //used for velocity
for (i=-1; i<2; i++)
kernel[(i+1)+3*(j+1)] *= s;
}
+
+void Air::Clear()
+{
+ std::fill(&hv[0][0], &hv[0][0]+((XRES/CELL)*(YRES/CELL)), 273.15f + 22.0f);
+ std::fill(&pv[0][0], &pv[0][0]+((XRES/CELL)*(YRES/CELL)), 0.0f);
+ std::fill(&vy[0][0], &vy[0][0]+((XRES/CELL)*(YRES/CELL)), 0.0f);
+ std::fill(&vx[0][0], &vx[0][0]+((XRES/CELL)*(YRES/CELL)), 0.0f);
+}
+
void Air::update_airh(void)
{
int x, y, i, j;
diff --git a/src/simulation/Air.h b/src/simulation/Air.h
index 2cd93b2..0232b86 100644
--- a/src/simulation/Air.h
+++ b/src/simulation/Air.h
@@ -28,6 +28,7 @@ public:
void make_kernel(void);
void update_airh(void);
void update_air(void);
+ void Clear();
Air();
};
diff --git a/src/simulation/Gravity.cpp b/src/simulation/Gravity.cpp
index 6ef1382..2b7810d 100644
--- a/src/simulation/Gravity.cpp
+++ b/src/simulation/Gravity.cpp
@@ -31,6 +31,15 @@ void Gravity::bilinear_interpolation(float *src, float *dst, int sw, int sh, int
}
}
+void Gravity::Clear()
+{
+ std::fill(gravy, gravy+((XRES/CELL)*(YRES/CELL)), 0.0f);
+ std::fill(gravx, gravx+((XRES/CELL)*(YRES/CELL)), 0.0f);
+ std::fill(gravp, gravp+((XRES/CELL)*(YRES/CELL)), 0.0f);
+ std::fill(gravmap, gravmap+((XRES/CELL)*(YRES/CELL)), 0.0f);
+ std::fill(gravmask, gravmask+((XRES/CELL)*(YRES/CELL)), 0xFFFFFFFF);
+}
+
void Gravity::gravity_init()
{
ngrav_enable = 0;
diff --git a/src/simulation/Gravity.h b/src/simulation/Gravity.h
index e706d6d..e78332a 100644
--- a/src/simulation/Gravity.h
+++ b/src/simulation/Gravity.h
@@ -77,6 +77,8 @@ public:
void grav_mask_r(int x, int y, char checkmap[YRES/CELL][XRES/CELL], char shape[YRES/CELL][XRES/CELL], char *shapeout);
void mask_free(mask_el *c_mask_el);
+ void Clear();
+
void gravity_init();
void gravity_cleanup();
void gravity_update_async();
diff --git a/src/simulation/Simulation.cpp b/src/simulation/Simulation.cpp
index 41af624..2ac72b2 100644
--- a/src/simulation/Simulation.cpp
+++ b/src/simulation/Simulation.cpp
@@ -1793,12 +1793,6 @@ void Simulation::clear_sim(void)
pfree = 0;
parts_lastActiveIndex = 0;
memset(pmap, 0, sizeof(pmap));
- if(pv)
- memset(pv, 0, (XRES/CELL) * (YRES/CELL)*sizeof(float));
- if(vx)
- memset(vx, 0, (XRES/CELL) * (YRES/CELL)*sizeof(float));
- if(vy)
- memset(vy, 0, (XRES/CELL) * (YRES/CELL)*sizeof(float));
if(fvx)
memset(fvx, 0, sizeof(fvx));
if(fvy)
@@ -1818,18 +1812,10 @@ void Simulation::clear_sim(void)
//memset(fire_b, 0, sizeof(fire_b));
//if(gravmask)
//memset(gravmask, 0xFFFFFFFF, (XRES/CELL)*(YRES/CELL)*sizeof(unsigned));
- if(gravy)
- memset(gravy, 0, (XRES/CELL)*(YRES/CELL)*sizeof(float));
- if(gravx)
- memset(gravx, 0, (XRES/CELL)*(YRES/CELL)*sizeof(float));
- if(gravp)
- memset(gravp, 0, (XRES/CELL)*(YRES/CELL)*sizeof(float));
- if(hv)
- for(x = 0; x < XRES/CELL; x++){
- for(y = 0; y < YRES/CELL; y++){
- hv[y][x] = 273.15f+22.0f; //Set to room temperature
- }
- }
+ if(grav)
+ grav->Clear();
+ if(air)
+ air->Clear();
}
void Simulation::init_can_move()
{