Gravity: only calculate the difference
This commit is contained in:
parent
776ae73f8e
commit
061d6ba7af
@ -43,6 +43,8 @@
|
|||||||
|
|
||||||
#define MAX_DISTANCE sqrt(pow(XRES, 2)+pow(YRES, 2))
|
#define MAX_DISTANCE sqrt(pow(XRES, 2)+pow(YRES, 2))
|
||||||
|
|
||||||
|
#define GRAV_DIFF
|
||||||
|
|
||||||
#define MAXSIGNS 16
|
#define MAXSIGNS 16
|
||||||
#define TAG_MAX 256
|
#define TAG_MAX 256
|
||||||
|
|
||||||
|
32
src/air.c
32
src/air.c
@ -41,6 +41,8 @@ void make_kernel(void) //used for velocity
|
|||||||
void update_grav(void)
|
void update_grav(void)
|
||||||
{
|
{
|
||||||
int x, y, i, j, changed = 0;
|
int x, y, i, j, changed = 0;
|
||||||
|
float val, distance;
|
||||||
|
#ifndef GRAV_DIFF
|
||||||
//Find any changed cells
|
//Find any changed cells
|
||||||
for (i=0; i<YRES/CELL; i++)
|
for (i=0; i<YRES/CELL; i++)
|
||||||
{
|
{
|
||||||
@ -54,24 +56,30 @@ void update_grav(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(changed)
|
|
||||||
{
|
|
||||||
memset(th_gravy, 0, sizeof(th_gravy));
|
memset(th_gravy, 0, sizeof(th_gravy));
|
||||||
memset(th_gravx, 0, sizeof(th_gravx));
|
memset(th_gravx, 0, sizeof(th_gravx));
|
||||||
for (i=0; i<YRES/CELL; i++)
|
#endif
|
||||||
|
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])
|
||||||
{
|
{
|
||||||
for (j=0; j<XRES/CELL; j++)
|
#else
|
||||||
{
|
if ((th_gravmap[i][j] > 0.0001f || th_gravmap[i][j]<-0.0001f) && changed) //Only calculate with populated or changed cells.
|
||||||
if(th_gravmap[i][j]>0.0001f || th_gravmap[i][j]<-0.0001f) //Only calculate with populated or changed cells.
|
|
||||||
for (y=0; y<YRES/CELL; y++)
|
|
||||||
{
|
|
||||||
for (x=0; x<XRES/CELL; x++)
|
|
||||||
{
|
{
|
||||||
|
#endif
|
||||||
|
for (y = 0; y < YRES / CELL; y++) {
|
||||||
|
for (x = 0; x < XRES / CELL; x++) {
|
||||||
if (x == j && y == i)//Ensure it doesn't calculate with itself
|
if (x == j && y == i)//Ensure it doesn't calculate with itself
|
||||||
continue;
|
continue;
|
||||||
float distance = sqrt(pow(j - x, 2) + pow(i - y, 2));
|
distance = sqrt(pow(j - x, 2) + pow(i - y, 2));
|
||||||
th_gravx[y][x] += M_GRAV*th_gravmap[i][j]*(j - x)/pow(distance, 3);
|
#ifdef GRAV_DIFF
|
||||||
th_gravy[y][x] += M_GRAV*th_gravmap[i][j]*(i - y)/pow(distance, 3);
|
val = th_gravmap[i][j] - th_ogravmap[i][j];
|
||||||
|
#else
|
||||||
|
val = th_gravmap[i][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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user