From 824bde4cebd78aa04c9018171316f7533307e0ce Mon Sep 17 00:00:00 2001 From: Simon Robertshaw Date: Sun, 29 Jul 2012 12:18:07 +0100 Subject: [PATCH] clear_sim now clears air and gravity maps better, fixes issue #31 --- src/simulation/Air.cpp | 9 +++++++++ src/simulation/Air.h | 1 + src/simulation/Gravity.cpp | 9 +++++++++ src/simulation/Gravity.h | 2 ++ src/simulation/Simulation.cpp | 22 ++++------------------ 5 files changed, 25 insertions(+), 18 deletions(-) diff --git a/src/simulation/Air.cpp b/src/simulation/Air.cpp index ff3ea6e16..6d7b5dd29 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 2cd93b28c..0232b8635 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 6ef13827a..2b7810d90 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 e706d6dbc..e78332acf 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 41af624cc..2ac72b213 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() {