Use reduced resolution gravity maps for improved performance

This commit is contained in:
Simon Robertshaw 2011-12-19 21:35:40 +00:00
parent a523dcab79
commit 810adc81fe
11 changed files with 154 additions and 152 deletions

View File

@ -7,20 +7,17 @@ extern int ngrav_enable; //Newtonian gravity
extern int gravwl_timeout;
extern int gravityMode;
extern float gravmap[YRES/CELL][XRES/CELL]; //Maps to be used by the main thread
extern float *gravpf;
extern float *gravxf;
extern float *gravyf;
extern unsigned *gravmaskf;
float *gravmap;//Maps to be used by the main thread
float *gravp;
float *gravy;
float *gravx;
unsigned *gravmask;
extern float th_ogravmap[YRES/CELL][XRES/CELL]; // Maps to be processed by the gravity thread
extern float th_gravmap[YRES/CELL][XRES/CELL];
extern float th_gravx[YRES/CELL][XRES/CELL];
extern float th_gravy[YRES/CELL][XRES/CELL];
extern float *th_gravpf;
extern float *th_gravxf;
extern float *th_gravyf;
extern float th_gravp[YRES/CELL][XRES/CELL];
float *th_ogravmap;// Maps to be processed by the gravity thread
float *th_gravmap;
float *th_gravx;
float *th_gravy;
float *th_gravp;
void gravity_init();
void gravity_cleanup();

View File

@ -19,8 +19,8 @@ int update_GBMB(UPDATE_FUNC_ARGS) {
}
}
if(parts[i].life>20)
gravmap[y/CELL][x/CELL] = 20;
gravmap[(y/CELL)*(XRES/CELL)+(x/CELL)] = 20;
if(parts[i].life<20 && parts[i].life>=1)
gravmap[y/CELL][x/CELL] = -80;
gravmap[(y/CELL)*(XRES/CELL)+(x/CELL)] = -80;
return 0;
}

View File

@ -11,9 +11,9 @@ int update_GPMP(UPDATE_FUNC_ARGS) {
if (parts[i].temp<= -256.0+273.15)
parts[i].temp = -256.0+273.15;
gravmap[y/CELL][x/CELL] = 0.2f*(parts[i].temp-273.15);
gravmap[(y/CELL)*(XRES/CELL)+(x/CELL)] = 0.2f*(parts[i].temp-273.15);
if (y+CELL<YRES && pv[y/CELL+1][x/CELL]<(parts[i].temp-273.15))
gravmap[y/CELL+1][x/CELL] += 0.1f*((parts[i].temp-273.15)-gravmap[y/CELL+1][x/CELL]);
gravmap[(y/CELL+1)*(XRES/CELL)+(x/CELL)] += 0.1f*((parts[i].temp-273.15)-gravmap[(y/CELL+1)*(XRES/CELL)+(x/CELL)]);
for (rx=-2; rx<3; rx++)
for (ry=-2; ry<3; ry++)
if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))

View File

@ -1,6 +1,6 @@
#include <element.h>
int update_NBHL(UPDATE_FUNC_ARGS) {
gravmap[y/CELL][x/CELL] += 0.1f;
gravmap[(y/CELL)*(XRES/CELL)+(x/CELL)] += 0.1f;
return 0;
}

View File

@ -1,6 +1,6 @@
#include <element.h>
int update_NWHL(UPDATE_FUNC_ARGS) {
gravmap[y/CELL][x/CELL] -= 0.1f;
gravmap[(y/CELL)*(XRES/CELL)+(x/CELL)] -= 0.1f;
return 0;
}

View File

@ -80,8 +80,8 @@ int run_stickman(playerst* playerp, UPDATE_FUNC_ARGS) {
}
}
gvx += gravxf[XRES*(int)parts[i].y + (int)parts[i].x];
gvy += gravyf[XRES*(int)parts[i].y + (int)parts[i].x];
gvx += gravx[((int)parts[i].y/CELL)*(XRES/CELL)+((int)parts[i].x/CELL)];
gvy += gravy[((int)parts[i].y/CELL)*(XRES/CELL)+((int)parts[i].x/CELL)];
parts[i].vx -= gvx*dt; //Head up!
parts[i].vy -= gvy*dt;

View File

@ -1427,7 +1427,7 @@ void draw_grav_zones(pixel * vid)
{
for (x=0; x<XRES/CELL; x++)
{
if(gravmaskf[y*CELL*XRES+x*CELL])
if(gravmask[y*(XRES/CELL)+x])
{
for (j=0; j<CELL; j++)//draws the colors
for (i=0; i<CELL; i++)
@ -1449,16 +1449,16 @@ void draw_grav(pixel *vid)
{
for (x=0; x<XRES/CELL; x++)
{
ca = ((y*CELL)*XRES)+(x*CELL);
if(fabsf(gravpf[ca]) <= 0.001f && fabsf(gravyf[ca]) <= 0.001f)
ca = y*(XRES/CELL)+x;
if(fabsf(gravx[ca]) <= 0.001f && fabsf(gravy[ca]) <= 0.001f)
continue;
nx = x*CELL;
ny = y*CELL;
dist = fabsf(gravyf[ca])+fabsf(gravxf[ca]);
dist = fabsf(gravy[ca])+fabsf(gravx[ca]);
for(i = 0; i < 4; i++)
{
nx -= gravxf[ca]*0.5f;
ny -= gravyf[ca]*0.5f;
nx -= gravx[ca]*0.5f;
ny -= gravy[ca]*0.5f;
addpixel(vid, (int)(nx+0.5f), (int)(ny+0.5f), 255, 255, 255, (int)(dist*20.0f));
}
}
@ -2664,11 +2664,11 @@ void draw_parts_fbo()
glUniform1i(glGetUniformLocation(lensProg, "pTex"), 0);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, partsTFX);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, XRES, YRES, GL_RED, GL_FLOAT, gravxf);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, XRES/CELL, YRES/CELL, GL_RED, GL_FLOAT, gravx);
glUniform1i(glGetUniformLocation(lensProg, "tfX"), 1);
glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, partsTFY);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, XRES, YRES, GL_GREEN, GL_FLOAT, gravyf);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, XRES/CELL, YRES/CELL, GL_GREEN, GL_FLOAT, gravy);
glUniform1i(glGetUniformLocation(lensProg, "tfY"), 2);
glActiveTexture(GL_TEXTURE0);
glUniform1fv(glGetUniformLocation(lensProg, "xres"), 1, &xres);
@ -3111,19 +3111,20 @@ void render_signs(pixel *vid_buf)
void render_gravlensing(pixel *src, pixel * dst)
{
int nx, ny, rx, ry, gx, gy, bx, by;
int nx, ny, rx, ry, gx, gy, bx, by, co;
int r, g, b;
pixel t;
for(nx = 0; nx < XRES; nx++)
{
for(ny = 0; ny < YRES; ny++)
{
rx = (int)(nx-gravxf[(ny*XRES)+nx]*0.75f+0.5f);
ry = (int)(ny-gravyf[(ny*XRES)+nx]*0.75f+0.5f);
gx = (int)(nx-gravxf[(ny*XRES)+nx]*0.875f+0.5f);
gy = (int)(ny-gravyf[(ny*XRES)+nx]*0.875f+0.5f);
bx = (int)(nx-gravxf[(ny*XRES)+nx]+0.5f);
by = (int)(ny-gravyf[(ny*XRES)+nx]+0.5f);
co = (ny/CELL)*(XRES/CELL)+(nx/CELL);
rx = (int)(nx-gravx[co]*0.75f+0.5f);
ry = (int)(ny-gravy[co]*0.75f+0.5f);
gx = (int)(nx-gravx[co]*0.875f+0.5f);
gy = (int)(ny-gravy[co]*0.875f+0.5f);
bx = (int)(nx-gravx[co]+0.5f);
by = (int)(ny-gravy[co]+0.5f);
if(rx > 0 && rx < XRES && ry > 0 && ry < YRES && gx > 0 && gx < XRES && gy > 0 && gy < YRES && bx > 0 && bx < XRES && by > 0 && by < YRES)
{
t = dst[ny*(XRES+BARSIZE)+nx];

View File

@ -9,24 +9,22 @@
#endif
float gravmap[YRES/CELL][XRES/CELL]; //Maps to be used by the main thread
float *gravpf;
float *gravyf;
float *gravxf;
unsigned *gravmaskf;
float *gravmap;//Maps to be used by the main thread
float *gravp;
float *gravy;
float *gravx;
unsigned *gravmask;
float th_ogravmap[YRES/CELL][XRES/CELL]; // Maps to be processed by the gravity thread
float th_gravmap[YRES/CELL][XRES/CELL];
float th_gravx[YRES/CELL][XRES/CELL];
float th_gravy[YRES/CELL][XRES/CELL];
float th_gravp[YRES/CELL][XRES/CELL];
float *th_gravpf;
float *th_gravyf;
float *th_gravxf;
float *th_ogravmap;// Maps to be processed by the gravity thread
float *th_gravmap;
float *th_gravx;
float *th_gravy;
float *th_gravp;
int gravwl_timeout = 0;
int gravityMode = 0; // starts enabled in "vertical" mode...
int ngrav_enable = 0; //Newtonian gravity, will be set by save
int ngrav_enable = 0; //Newtonian gravity
int th_gravchanged = 0;
pthread_t gravthread;
pthread_mutex_t gravmutex;
@ -63,13 +61,16 @@ void bilinear_interpolation(float *src, float *dst, int sw, int sh, int rw, int
void gravity_init()
{
//Allocate full size Gravmaps
th_gravyf = calloc(XRES*YRES, sizeof(float));
th_gravxf = calloc(XRES*YRES, sizeof(float));
th_gravpf = calloc(XRES*YRES, sizeof(float));
gravyf = calloc(XRES*YRES, sizeof(float));
gravxf = calloc(XRES*YRES, sizeof(float));
gravpf = calloc(XRES*YRES, sizeof(float));
gravmaskf = malloc(XRES*YRES*sizeof(unsigned));
th_ogravmap = calloc((XRES/CELL)*(YRES/CELL), sizeof(float));
th_gravmap = calloc((XRES/CELL)*(YRES/CELL), sizeof(float));
th_gravy = calloc((XRES/CELL)*(YRES/CELL), sizeof(float));
th_gravx = calloc((XRES/CELL)*(YRES/CELL), sizeof(float));
th_gravp = calloc((XRES/CELL)*(YRES/CELL), sizeof(float));
gravmap = calloc((XRES/CELL)*(YRES/CELL), sizeof(float));
gravy = calloc((XRES/CELL)*(YRES/CELL), sizeof(float));
gravx = calloc((XRES/CELL)*(YRES/CELL), sizeof(float));
gravp = calloc((XRES/CELL)*(YRES/CELL), sizeof(float));
gravmask = calloc((XRES/CELL)*(YRES/CELL), sizeof(unsigned));
}
void gravity_cleanup()
@ -88,22 +89,28 @@ void gravity_update_async()
result = grav_ready;
if(result) //Did the gravity thread finish?
{
memcpy(th_gravmap, gravmap, sizeof(gravmap)); //Move our current gravmap to be processed other thread
if (!sys_pause||framerender){ //Only update if not paused
//Switch the full size gravmaps, we don't really need the two above any more
float *tmpf;
tmpf = gravyf;
gravyf = th_gravyf;
th_gravyf = tmpf;
tmpf = gravxf;
gravxf = th_gravxf;
th_gravxf = tmpf;
tmpf = gravpf;
gravpf = th_gravpf;
th_gravpf = tmpf;
if(th_gravchanged)
{
tmpf = gravy;
gravy = th_gravy;
th_gravy = tmpf;
tmpf = gravx;
gravx = th_gravx;
th_gravx = tmpf;
tmpf = gravp;
gravp = th_gravp;
th_gravp = tmpf;
}
tmpf = gravmap;
gravmap = th_gravmap;
th_gravmap = tmpf;
grav_ready = 0; //Tell the other thread that we're ready for it to continue
pthread_cond_signal(&gravcv);
@ -111,8 +118,8 @@ void gravity_update_async()
}
pthread_mutex_unlock(&gravmutex);
//Apply the gravity mask
membwand(gravyf, gravmaskf, XRES*YRES*sizeof(float), XRES*YRES*sizeof(unsigned));
membwand(gravxf, gravmaskf, XRES*YRES*sizeof(float), XRES*YRES*sizeof(unsigned));
membwand(gravy, gravmask, (XRES/CELL)*(YRES/CELL)*sizeof(float), (XRES/CELL)*(YRES/CELL)*sizeof(unsigned));
membwand(gravx, gravmask, (XRES/CELL)*(YRES/CELL)*sizeof(float), (XRES/CELL)*(YRES/CELL)*sizeof(unsigned));
}
}
@ -120,13 +127,14 @@ void* update_grav_async(void* unused)
{
int done = 0;
int thread_done = 0;
memset(th_ogravmap, 0, sizeof(th_ogravmap));
memset(th_gravmap, 0, sizeof(th_gravmap));
memset(th_gravy, 0, sizeof(th_gravy));
memset(th_gravx, 0, sizeof(th_gravx));
memset(th_gravyf, 0, XRES*YRES*sizeof(float));
memset(th_gravxf, 0, XRES*YRES*sizeof(float));
memset(th_gravpf, 0, XRES*YRES*sizeof(float));
memset(th_ogravmap, 0, (XRES/CELL)*(YRES/CELL)*sizeof(float));
memset(th_gravmap, 0, (XRES/CELL)*(YRES/CELL)*sizeof(float));
memset(th_gravy, 0, (XRES/CELL)*(YRES/CELL)*sizeof(float));
memset(th_gravx, 0, (XRES/CELL)*(YRES/CELL)*sizeof(float));
memset(th_gravp, 0, (XRES/CELL)*(YRES/CELL)*sizeof(float));
//memset(th_gravy, 0, XRES*YRES*sizeof(float));
//memset(th_gravx, 0, XRES*YRES*sizeof(float));
//memset(th_gravp, 0, XRES*YRES*sizeof(float));
#ifdef GRAVFFT
grav_fft_init();
#endif
@ -163,9 +171,9 @@ void start_grav_async()
pthread_create(&gravthread, NULL, update_grav_async, NULL); //Start asynchronous gravity simulation
ngrav_enable = 1;
}
memset(gravyf, 0, XRES*YRES*sizeof(float));
memset(gravxf, 0, XRES*YRES*sizeof(float));
memset(gravpf, 0, XRES*YRES*sizeof(float));
memset(gravy, 0, (XRES/CELL)*(YRES/CELL)*sizeof(float));
memset(gravx, 0, (XRES/CELL)*(YRES/CELL)*sizeof(float));
memset(gravp, 0, (XRES/CELL)*(YRES/CELL)*sizeof(float));
}
void stop_grav_async()
@ -180,9 +188,9 @@ void stop_grav_async()
ngrav_enable = 0;
}
//Clear the grav velocities
memset(gravyf, 0, XRES*YRES*sizeof(float));
memset(gravxf, 0, XRES*YRES*sizeof(float));
memset(gravpf, 0, XRES*YRES*sizeof(float));
memset(gravy, 0, (XRES/CELL)*(YRES/CELL)*sizeof(float));
memset(gravx, 0, (XRES/CELL)*(YRES/CELL)*sizeof(float));
memset(gravp, 0, (XRES/CELL)*(YRES/CELL)*sizeof(float));
}
#ifdef GRAVFFT
@ -269,13 +277,16 @@ void grav_fft_cleanup()
void update_grav()
{
int x, y, changed = 0;
int xblock2 = XRES/CELL*2, yblock2 = YRES/CELL*2;
int i, fft_tsize = (xblock2/2+1)*yblock2;
float mr, mc, pr, pc, gr, gc;
for (y=0; y<YRES/CELL; y++)
{
if(changed)
break;
for (x=0; x<XRES/CELL; x++)
{
if(th_ogravmap[y][x]!=th_gravmap[y][x]){
if(th_ogravmap[y*(XRES/CELL)+x]!=th_gravmap[y*(XRES/CELL)+x]){
changed = 1;
break;
}
@ -283,9 +294,7 @@ void update_grav()
}
if(changed)
{
int xblock2 = XRES/CELL*2, yblock2 = YRES/CELL*2;
int i, fft_tsize = (xblock2/2+1)*yblock2;
float mr, mc, pr, pc, gr, gc;
th_gravchanged = 1;
if (!grav_fft_status) grav_fft_init();
//copy gravmap into padded gravmap array
@ -293,7 +302,7 @@ void update_grav()
{
for (x=0; x<XRES/CELL; x++)
{
th_gravmapbig[(y+YRES/CELL)*xblock2+XRES/CELL+x] = th_gravmap[y][x];
th_gravmapbig[(y+YRES/CELL)*xblock2+XRES/CELL+x] = th_gravmap[y*(XRES/CELL)+x];
}
}
//transform gravmap
@ -323,16 +332,18 @@ void update_grav()
{
for (x=0; x<XRES/CELL; x++)
{
th_gravx[y][x] = th_gravxbig[y*xblock2+x];
th_gravy[y][x] = th_gravybig[y*xblock2+x];
th_gravp[y][x] = sqrtf(pow(th_gravxbig[y*xblock2+x],2)+pow(th_gravybig[y*xblock2+x],2));
th_gravx[y*(XRES/CELL)+x] = th_gravxbig[y*xblock2+x];
th_gravy[y*(XRES/CELL)+x] = th_gravybig[y*xblock2+x];
th_gravp[y*(XRES/CELL)+x] = sqrtf(pow(th_gravxbig[y*xblock2+x],2)+pow(th_gravybig[y*xblock2+x],2));
}
}
}
memcpy(th_ogravmap, th_gravmap, sizeof(th_gravmap));
bilinear_interpolation(th_gravy, th_gravyf, XRES/CELL, YRES/CELL, XRES, YRES);
bilinear_interpolation(th_gravx, th_gravxf, XRES/CELL, YRES/CELL, XRES, YRES);
bilinear_interpolation(th_gravp, th_gravpf, XRES/CELL, YRES/CELL, XRES, YRES);
else
{
th_gravchanged = 0;
}
memcpy(th_ogravmap, th_gravmap, (XRES/CELL)*(YRES/CELL)*sizeof(float));
memset(th_gravmap, 0, (XRES/CELL)*(YRES/CELL)*sizeof(float));
}
#else
@ -342,6 +353,7 @@ void update_grav(void)
{
int x, y, i, j, changed = 0;
float val, distance;
th_gravchanged = 0;
#ifndef GRAV_DIFF
//Find any changed cells
for (i=0; i<YRES/CELL; i++)
@ -350,7 +362,7 @@ void update_grav(void)
break;
for (j=0; j<XRES/CELL; j++)
{
if(th_ogravmap[i][j]!=th_gravmap[i][j]){
if(th_ogravmap[i*(XRES/CELL)+j]!=th_gravmap[i*(XRES/CELL)+j]){
changed = 1;
break;
}
@ -358,16 +370,17 @@ void update_grav(void)
}
if(!changed)
goto fin;
memset(th_gravy, 0, sizeof(th_gravy));
memset(th_gravx, 0, sizeof(th_gravx));
memset(th_gravy, 0, (XRES/CELL)*(YRES/CELL)*sizeof(float));
memset(th_gravx, 0, (XRES/CELL)*(YRES/CELL)*sizeof(float));
#endif
th_gravchanged = 1;
for (i = 0; i < YRES / CELL; i++) {
for (j = 0; j < XRES / CELL; j++) {
#ifdef GRAV_DIFF
if (th_ogravmap[i][j] != th_gravmap[i][j])
if (th_ogravmap[i*(XRES/CELL)+j] != th_gravmap[i*(XRES/CELL)+j])
{
#else
if (th_gravmap[i][j] > 0.0001f || th_gravmap[i][j]<-0.0001f) //Only calculate with populated or changed cells.
if (th_gravmap[i*(XRES/CELL)+j] > 0.0001f || th_gravmap[i*(XRES/CELL)+j]<-0.0001f) //Only calculate with populated or changed cells.
{
#endif
for (y = 0; y < YRES / CELL; y++) {
@ -376,24 +389,21 @@ void update_grav(void)
continue;
distance = sqrt(pow(j - x, 2) + pow(i - y, 2));
#ifdef GRAV_DIFF
val = th_gravmap[i][j] - th_ogravmap[i][j];
val = th_gravmap[i*(XRES/CELL)+j] - th_ogravmap[i*(XRES/CELL)+j];
#else
val = th_gravmap[i][j];
val = th_gravmap[i*(XRES/CELL)+j];
#endif
th_gravx[y][x] += M_GRAV * val * (j - x) / pow(distance, 3);
th_gravy[y][x] += M_GRAV * val * (i - y) / pow(distance, 3);
th_gravp[y][x] += M_GRAV * val / pow(distance, 2);
th_gravx[y*(XRES/CELL)+x] += M_GRAV * val * (j - x) / pow(distance, 3);
th_gravy[y*(XRES/CELL)+x] += M_GRAV * val * (i - y) / pow(distance, 3);
th_gravp[y*(XRES/CELL)+x] += M_GRAV * val / pow(distance, 2);
}
}
}
}
}
bilinear_interpolation(th_gravy, th_gravyf, XRES/CELL, YRES/CELL, XRES, YRES);
bilinear_interpolation(th_gravx, th_gravxf, XRES/CELL, YRES/CELL, XRES, YRES);
bilinear_interpolation(th_gravp, th_gravpf, XRES/CELL, YRES/CELL, XRES, YRES);
fin:
memcpy(th_ogravmap, th_gravmap, sizeof(th_gravmap));
memset(th_gravmap, 0, sizeof(th_gravmap));
memcpy(th_ogravmap, th_gravmap, (XRES/CELL)*(YRES/CELL)*sizeof(float));
memset(th_gravmap, 0, (XRES/CELL)*(YRES/CELL)*sizeof(float));
}
#endif
@ -467,7 +477,7 @@ void gravity_mask()
}
}
c_mask_el = t_mask_el;
memset(gravmaskf, 0, XRES*YRES*sizeof(unsigned));
memset(gravmask, 0, (XRES/CELL)*(YRES/CELL)*sizeof(unsigned));
while(c_mask_el!=NULL)
{
char *cshape = c_mask_el->shape;
@ -480,13 +490,7 @@ void gravity_mask()
maskvalue = 0xFFFFFFFF;
else
maskvalue = 0x00000000;
for (j=0; j<CELL; j++)
{
for (i=0; i<CELL; i++)
{
gravmaskf[(y*CELL+j)*XRES+x*CELL+i] = maskvalue;
}
}
gravmask[y*(XRES/CELL)+x] = maskvalue;
}
}
}

View File

@ -969,7 +969,7 @@ int luatpt_set_gravity(lua_State* l)
for (nx = x1; nx<x1+width; nx++)
for (ny = y1; ny<y1+height; ny++)
{
gravmap[ny][nx] = value;
gravmap[ny*(XRES/CELL)+nx] = value;
}
return 0;
}
@ -980,22 +980,22 @@ int luatpt_reset_gravity_field(lua_State* l)
int x1, y1, width, height;
x1 = abs(luaL_optint(l, 1, 0));
y1 = abs(luaL_optint(l, 2, 0));
width = abs(luaL_optint(l, 3, XRES));
height = abs(luaL_optint(l, 4, YRES));
if(x1 > XRES-1)
x1 = XRES-1;
if(y1 > YRES-1)
y1 = YRES-1;
if(x1+width > XRES-1)
width = XRES-x1;
if(y1+height > YRES-1)
height = YRES-y1;
width = abs(luaL_optint(l, 3, XRES/CELL));
height = abs(luaL_optint(l, 4, YRES/CELL));
if(x1 > (XRES/CELL)-1)
x1 = (XRES/CELL)-1;
if(y1 > (YRES/CELL)-1)
y1 = (YRES/CELL)-1;
if(x1+width > (XRES/CELL)-1)
width = (XRES/CELL)-x1;
if(y1+height > (YRES/CELL)-1)
height = (YRES/CELL)-y1;
for (nx = x1; nx<x1+width; nx++)
for (ny = y1; ny<y1+height; ny++)
{
gravxf[ny*XRES+nx] = 0;
gravyf[ny*XRES+nx] = 0;
gravpf[ny*XRES+nx] = 0;
gravx[ny*(XRES/CELL)+nx] = 0;
gravy[ny*(XRES/CELL)+nx] = 0;
gravp[ny*(XRES/CELL)+nx] = 0;
}
return 0;
}

View File

@ -1153,10 +1153,10 @@ void clear_sim(void)
memset(fire_r, 0, sizeof(fire_r));
memset(fire_g, 0, sizeof(fire_g));
memset(fire_b, 0, sizeof(fire_b));
memset(gravmaskf, 0xFF, XRES*YRES*sizeof(unsigned));
memset(gravyf, 0, XRES*YRES*sizeof(float));
memset(gravxf, 0, XRES*YRES*sizeof(float));
memset(gravpf, 0, XRES*YRES*sizeof(float));
memset(gravmask, 0xFFFFFFFF, (XRES/CELL)*(YRES/CELL)*sizeof(unsigned));
memset(gravy, 0, (XRES/CELL)*(YRES/CELL)*sizeof(float));
memset(gravx, 0, (XRES/CELL)*(YRES/CELL)*sizeof(float));
memset(gravp, 0, (XRES/CELL)*(YRES/CELL)*sizeof(float));
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
@ -2673,7 +2673,7 @@ int main(int argc, char *argv[])
sprintf(heattext, "Empty, Pressure: %3.2f", pv[(y/sdl_scale)/CELL][(x/sdl_scale)/CELL]);
if (DEBUG_MODE)
{
sprintf(coordtext, "X:%d Y:%d. GX: %.2f GY: %.2f", x/sdl_scale, y/sdl_scale, gravxf[((y/sdl_scale)*XRES)+(x/sdl_scale)], gravyf[((y/sdl_scale)*XRES)+(x/sdl_scale)]);
sprintf(coordtext, "X:%d Y:%d. GX: %.2f GY: %.2f", x/sdl_scale, y/sdl_scale, gravx[(((y/sdl_scale)/CELL)*(XRES/CELL))+((x/sdl_scale)/CELL)], gravy[(((y/sdl_scale)/CELL)*(XRES/CELL))+((x/sdl_scale)/CELL)]);
}
}
}

View File

@ -760,13 +760,13 @@ inline int create_part(int p, int x, int y, int tv)//the function for creating a
}
if (t==SPC_PGRV)
{
gravmap[y/CELL][x/CELL] = 5;
return -1;
gravmap[(y/CELL)*(XRES/CELL)+(x/CELL)] = 5;
return -1;
}
if (t==SPC_NGRV)
{
gravmap[y/CELL][x/CELL] = -5;
return -1;
gravmap[(y/CELL)*(XRES/CELL)+(x/CELL)] = -5;
return -1;
}
@ -1801,13 +1801,13 @@ void update_particles_i(pixel *vid, int start, int inc)
if (t==PT_ANAR)
{
// perhaps we should have a ptypes variable for this
pGravX -= gravxf[(y*XRES)+x];
pGravY -= gravyf[(y*XRES)+x];
pGravX -= gravx[(y/CELL)*(XRES/CELL)+(x/CELL)];
pGravY -= gravy[(y/CELL)*(XRES/CELL)+(x/CELL)];
}
else if(t!=PT_STKM && t!=PT_STKM2 && t!=PT_FIGH && !(ptypes[t].properties & TYPE_SOLID))
{
pGravX += gravxf[(y*XRES)+x];
pGravY += gravyf[(y*XRES)+x];
pGravX += gravx[(y/CELL)*(XRES/CELL)+(x/CELL)];
pGravY += gravy[(y/CELL)*(XRES/CELL)+(x/CELL)];
}
//velocity updates for the particle
parts[i].vx *= ptypes[t].loss;
@ -2063,7 +2063,7 @@ void update_particles_i(pixel *vid, int start, int inc)
s = 1;
gravtot = fabs(gravyf[(y*XRES)+x])+fabs(gravxf[(y*XRES)+x]);
gravtot = fabs(gravy[(y/CELL)*(XRES/CELL)+(x/CELL)])+fabs(gravx[(y/CELL)*(XRES/CELL)+(x/CELL)]);
if (pv[y/CELL][x/CELL]>ptransitions[t].phv&&ptransitions[t].pht>-1) {
// particle type change due to high pressure
if (ptransitions[t].pht!=PT_NUM)
@ -2449,8 +2449,8 @@ killed:
pGravX = ptGrav * ((float)(nx - XCNTR) / pGravD);
pGravY = ptGrav * ((float)(ny - YCNTR) / pGravD);
}
pGravX += gravxf[(ny*XRES)+nx];
pGravY += gravyf[(ny*XRES)+nx];
pGravX += gravx[(ny/CELL)*(XRES/CELL)+(nx/CELL)];
pGravY += gravy[(ny/CELL)*(XRES/CELL)+(nx/CELL)];
if (fabsf(pGravY)>fabsf(pGravX))
mv = fabsf(pGravY);
else
@ -2508,8 +2508,8 @@ killed:
pGravX = ptGrav * ((float)(nx - XCNTR) / pGravD);
pGravY = ptGrav * ((float)(ny - YCNTR) / pGravD);
}
pGravX += gravxf[(ny*XRES)+nx];
pGravY += gravyf[(ny*XRES)+nx];
pGravX += gravx[(ny/CELL)*(XRES/CELL)+(nx/CELL)];
pGravY += gravy[(ny/CELL)*(XRES/CELL)+(nx/CELL)];
if (fabsf(pGravY)>fabsf(pGravX))
mv = fabsf(pGravY);
else