From 061d6ba7afb3c03b35f77ff59d1b70f8076bd6ca Mon Sep 17 00:00:00 2001 From: Simon Robertshaw Date: Tue, 26 Apr 2011 16:15:23 +0100 Subject: [PATCH] Gravity: only calculate the difference --- includes/defines.h | 2 ++ src/air.c | 44 ++++++++++++++++++++++++++------------------ 2 files changed, 28 insertions(+), 18 deletions(-) diff --git a/includes/defines.h b/includes/defines.h index 41eeee081..8867284ee 100644 --- a/includes/defines.h +++ b/includes/defines.h @@ -43,6 +43,8 @@ #define MAX_DISTANCE sqrt(pow(XRES, 2)+pow(YRES, 2)) +#define GRAV_DIFF + #define MAXSIGNS 16 #define TAG_MAX 256 diff --git a/src/air.c b/src/air.c index 740a28e93..4e5122c2a 100644 --- a/src/air.c +++ b/src/air.c @@ -41,6 +41,8 @@ void make_kernel(void) //used for velocity void update_grav(void) { int x, y, i, j, changed = 0; + float val, distance; +#ifndef GRAV_DIFF //Find any changed cells for (i=0; i0.0001f || th_gravmap[i][j]<-0.0001f) //Only calculate with populated or changed cells. - for (y=0; y 0.0001f || th_gravmap[i][j]<-0.0001f) && changed) //Only calculate with populated or changed cells. + { +#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 + continue; + distance = sqrt(pow(j - x, 2) + pow(i - y, 2)); +#ifdef GRAV_DIFF + 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); } + } } } }