summaryrefslogtreecommitdiff
path: root/src/simulation
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-04-16 12:58:20 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-04-16 12:58:20 (GMT)
commit465cb12af436a65871bd149174da0e7479d108bd (patch)
tree31cbd7443d6b56697b7eee145fd8acfd122b354a /src/simulation
parenta0506495ad71a18ba2976d31d437dfd6bd8241f8 (diff)
downloadpowder-465cb12af436a65871bd149174da0e7479d108bd.zip
powder-465cb12af436a65871bd149174da0e7479d108bd.tar.gz
Newtonian gravity working
Diffstat (limited to 'src/simulation')
-rw-r--r--src/simulation/Gravity.cpp21
-rw-r--r--src/simulation/Simulation.cpp14
2 files changed, 25 insertions, 10 deletions
diff --git a/src/simulation/Gravity.cpp b/src/simulation/Gravity.cpp
index d2d7295..1a74566 100644
--- a/src/simulation/Gravity.cpp
+++ b/src/simulation/Gravity.cpp
@@ -37,6 +37,7 @@ void Gravity::bilinear_interpolation(float *src, float *dst, int sw, int sh, int
void Gravity::gravity_init()
{
+ ngrav_enable = 0;
//Allocate full size Gravmaps
th_ogravmap = (float *)calloc((XRES/CELL)*(YRES/CELL), sizeof(float));
th_gravmap = (float *)calloc((XRES/CELL)*(YRES/CELL), sizeof(float));
@@ -210,16 +211,16 @@ void Gravity::grav_fft_init()
if (grav_fft_status) return;
//use fftw malloc function to ensure arrays are aligned, to get better performance
- th_ptgravx = fftwf_malloc(xblock2*yblock2*sizeof(float));
- th_ptgravy = fftwf_malloc(xblock2*yblock2*sizeof(float));
- th_ptgravxt = fftwf_malloc(fft_tsize*sizeof(fftwf_complex));
- th_ptgravyt = fftwf_malloc(fft_tsize*sizeof(fftwf_complex));
- th_gravmapbig = fftwf_malloc(xblock2*yblock2*sizeof(float));
- th_gravmapbigt = fftwf_malloc(fft_tsize*sizeof(fftwf_complex));
- th_gravxbig = fftwf_malloc(xblock2*yblock2*sizeof(float));
- th_gravybig = fftwf_malloc(xblock2*yblock2*sizeof(float));
- th_gravxbigt = fftwf_malloc(fft_tsize*sizeof(fftwf_complex));
- th_gravybigt = fftwf_malloc(fft_tsize*sizeof(fftwf_complex));
+ th_ptgravx = (float*)fftwf_malloc(xblock2*yblock2*sizeof(float));
+ th_ptgravy = (float*)fftwf_malloc(xblock2*yblock2*sizeof(float));
+ th_ptgravxt = (fftwf_complex*)fftwf_malloc(fft_tsize*sizeof(fftwf_complex));
+ th_ptgravyt = (fftwf_complex*)fftwf_malloc(fft_tsize*sizeof(fftwf_complex));
+ th_gravmapbig = (float*)fftwf_malloc(xblock2*yblock2*sizeof(float));
+ th_gravmapbigt = (fftwf_complex*)fftwf_malloc(fft_tsize*sizeof(fftwf_complex));
+ th_gravxbig = (float*)fftwf_malloc(xblock2*yblock2*sizeof(float));
+ th_gravybig = (float*)fftwf_malloc(xblock2*yblock2*sizeof(float));
+ th_gravxbigt = (fftwf_complex*)fftwf_malloc(fft_tsize*sizeof(fftwf_complex));
+ th_gravybigt = (fftwf_complex*)fftwf_malloc(fft_tsize*sizeof(fftwf_complex));
//select best algorithm, could use FFTW_PATIENT or FFTW_EXHAUSTIVE but that increases the time taken to plan, and I don't see much increase in execution speed
plan_ptgravx = fftwf_plan_dft_r2c_2d(yblock2, xblock2, th_ptgravx, th_ptgravxt, FFTW_MEASURE);
diff --git a/src/simulation/Simulation.cpp b/src/simulation/Simulation.cpp
index 764d29d..7fdd6d6 100644
--- a/src/simulation/Simulation.cpp
+++ b/src/simulation/Simulation.cpp
@@ -8,6 +8,9 @@
#include "Gravity.h"
#include "SaveLoader.h"
+#undef LUACONSOLE
+//#include "cat/LuaScriptHelper.h"
+
int Simulation::Load(unsigned char * data, int dataLength)
{
return SaveLoader::Load(data, dataLength, this, true, 0, 0);
@@ -3269,7 +3272,16 @@ void Simulation::update_particles()//doesn't update the particles themselves, bu
#endif
if(!sys_pause||framerender)
+ {
air->update_air();
+ grav->gravity_update_async();
+
+ //Get updated buffer pointers for gravity
+ gravx = grav->gravx;
+ gravy = grav->gravy;
+ gravp = grav->gravp;
+ gravmap = grav->gravmap;
+ }
memset(pmap, 0, sizeof(pmap));
memset(photons, 0, sizeof(photons));
@@ -3424,4 +3436,6 @@ Simulation::Simulation():
init_can_move();
clear_sim();
+
+ grav->gravity_mask();
}