summaryrefslogtreecommitdiff
path: root/src/air.c
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2011-04-24 16:49:33 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2011-04-24 16:49:33 (GMT)
commit3acf9aae2aac9865cead77870010681cb390ba19 (patch)
treedf28d9dc831c0b1716a35fd77d4a3c72baed6601 /src/air.c
parentdb427e4cdd240f46eafc17a76bf27de347ca8a96 (diff)
downloadpowder-3acf9aae2aac9865cead77870010681cb390ba19.zip
powder-3acf9aae2aac9865cead77870010681cb390ba19.tar.gz
Asynchronous thread for gravity processing
Diffstat (limited to 'src/air.c')
-rw-r--r--src/air.c24
1 files changed, 14 insertions, 10 deletions
diff --git a/src/air.c b/src/air.c
index 2947d93..e859e6c 100644
--- a/src/air.c
+++ b/src/air.c
@@ -4,11 +4,15 @@
#include <defines.h>
float kernel[9];
-float ogravmap[YRES/CELL][XRES/CELL];
-float gravmap[YRES/CELL][XRES/CELL];
+float gravmap[YRES/CELL][XRES/CELL]; //Maps to be used by the main thread
float gravx[YRES/CELL][XRES/CELL];
float gravy[YRES/CELL][XRES/CELL];
+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 vx[YRES/CELL][XRES/CELL], ovx[YRES/CELL][XRES/CELL];
float vy[YRES/CELL][XRES/CELL], ovy[YRES/CELL][XRES/CELL];
float pv[YRES/CELL][XRES/CELL], opv[YRES/CELL][XRES/CELL];
@@ -44,7 +48,7 @@ void update_grav(void)
break;
for (j=0; j<XRES/CELL; j++)
{
- if(ogravmap[i][j]!=gravmap[i][j]){
+ if(th_ogravmap[i][j]!=th_gravmap[i][j]){
changed = 1;
break;
}
@@ -52,13 +56,13 @@ void update_grav(void)
}
if(changed)
{
- memset(gravy, 0, sizeof(gravy));
- memset(gravx, 0, sizeof(gravx));
+ memset(th_gravy, 0, sizeof(th_gravy));
+ memset(th_gravx, 0, sizeof(th_gravx));
for (i=0; i<YRES/CELL; i++)
{
for (j=0; j<XRES/CELL; j++)
{
- if(gravmap[i][j]>0.0f) //Only calculate with populated or changed cells.
+ if(th_gravmap[i][j]>0.0f) //Only calculate with populated or changed cells.
for (y=0; y<YRES/CELL; y++)
{
for (x=0; x<XRES/CELL; x++)
@@ -66,15 +70,15 @@ void update_grav(void)
if(x == j && y == i)//Ensure it doesn't calculate with itself
continue;
float distance = sqrt(pow(j - x, 2) + pow(i - y, 2));
- gravx[y][x] += M_GRAV*gravmap[i][j]*(j - x)/pow(distance, 3);
- gravy[y][x] += M_GRAV*gravmap[i][j]*(i - y)/pow(distance, 3);
+ th_gravx[y][x] += M_GRAV*th_gravmap[i][j]*(j - x)/pow(distance, 3);
+ th_gravy[y][x] += M_GRAV*th_gravmap[i][j]*(i - y)/pow(distance, 3);
}
}
}
}
}
- memcpy(ogravmap, gravmap, sizeof(gravmap));
- memset(gravmap, 0, sizeof(gravmap));
+ memcpy(th_ogravmap, th_gravmap, sizeof(th_gravmap));
+ memset(th_gravmap, 0, sizeof(th_gravmap));
}
void update_air(void)
{