clear_sim now clears air and gravity maps better, fixes issue #31

This commit is contained in:
Simon Robertshaw 2012-07-29 12:18:07 +01:00
parent 1f914561b2
commit 824bde4ceb
5 changed files with 25 additions and 18 deletions

View File

@ -36,6 +36,15 @@ void Air::make_kernel(void) //used for velocity
for (i=-1; i<2; i++) for (i=-1; i<2; i++)
kernel[(i+1)+3*(j+1)] *= s; 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) void Air::update_airh(void)
{ {
int x, y, i, j; int x, y, i, j;

View File

@ -28,6 +28,7 @@ public:
void make_kernel(void); void make_kernel(void);
void update_airh(void); void update_airh(void);
void update_air(void); void update_air(void);
void Clear();
Air(); Air();
}; };

View File

@ -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() void Gravity::gravity_init()
{ {
ngrav_enable = 0; ngrav_enable = 0;

View File

@ -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 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 mask_free(mask_el *c_mask_el);
void Clear();
void gravity_init(); void gravity_init();
void gravity_cleanup(); void gravity_cleanup();
void gravity_update_async(); void gravity_update_async();

View File

@ -1793,12 +1793,6 @@ void Simulation::clear_sim(void)
pfree = 0; pfree = 0;
parts_lastActiveIndex = 0; parts_lastActiveIndex = 0;
memset(pmap, 0, sizeof(pmap)); 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) if(fvx)
memset(fvx, 0, sizeof(fvx)); memset(fvx, 0, sizeof(fvx));
if(fvy) if(fvy)
@ -1818,18 +1812,10 @@ void Simulation::clear_sim(void)
//memset(fire_b, 0, sizeof(fire_b)); //memset(fire_b, 0, sizeof(fire_b));
//if(gravmask) //if(gravmask)
//memset(gravmask, 0xFFFFFFFF, (XRES/CELL)*(YRES/CELL)*sizeof(unsigned)); //memset(gravmask, 0xFFFFFFFF, (XRES/CELL)*(YRES/CELL)*sizeof(unsigned));
if(gravy) if(grav)
memset(gravy, 0, (XRES/CELL)*(YRES/CELL)*sizeof(float)); grav->Clear();
if(gravx) if(air)
memset(gravx, 0, (XRES/CELL)*(YRES/CELL)*sizeof(float)); air->Clear();
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
}
}
} }
void Simulation::init_can_move() void Simulation::init_can_move()
{ {