diff --git a/Makefile b/Makefile index cb3139e15..46359b7e1 100644 --- a/Makefile +++ b/Makefile @@ -19,14 +19,16 @@ powder.exe: build/powder.exe powder-release: build/powder-release powder: build/powder -build/powder-release.exe: CFLAGS += -DWIN32 -O3 -ffast-math -ftree-vectorize -funsafe-math-optimizations -pipe -msse -msse2 -msse3 -mmmx -build/powder-release.exe: LFLAGS := -lmingw32 -lregex -lws2_32 -lSDLmain -lpthread -lSDL -lm -lbz2 -llua -mwindows -build/powder.exe: CFLAGS += -DWIN32 -DWINCONSOLE -build/powder.exe: LFLAGS := -lmingw32 -lregex -lws2_32 -lSDLmain -lpthread -lSDL -lm -lbz2 -llua #-mwindows +build/powder-release.exe: CFLAGS += -DWIN32 -O3 -ffast-math -ftree-vectorize -funsafe-math-optimizations -pipe -msse -msse2 -msse3 -mmmx +build/powder-release.exe: LFLAGS := -lmingw32 -lregex -lws2_32 -lSDLmain -lpthread -lSDL -lm -lbz2 -llua -lfftw3f-3 -mwindows +build/powder.exe: CFLAGS += -DWIN32 +build/powder.exe: LFLAGS := -lmingw32 -lregex -lws2_32 -lSDLmain -lpthread -lSDL -lm -lbz2 -llua -lfftw3f-3 #-mwindows build/powder-release: CFLAGS += -DLIN32 -O3 -ffast-math -ftree-vectorize -funsafe-math-optimizations -pipe -msse -msse2 -msse3 -mmmx -build/powder-release: LFLAGS := -lSDL -lm -lbz2 -llua +build/powder-release: LFLAGS := -lSDL -lm -lbz2 -llua -lfftw3f build/powder: CFLAGS += -DLIN32 -build/powder: LFLAGS := -lSDL -lm -lbz2 -llua +build/powder: LFLAGS := -lSDL -lm -lbz2 -llua -lfftw3f + +CFLAGS += -DGRAVFFT -DLUACONSOLE build/powder-release.exe: $(SOURCES) build/powder-res.o $(CPPC_WIN) $(CFLAGS) $(OFLAGS) $(LDFLAGS) $(SOURCES) $(LFLAGS) build/powder-res.o -o $@ diff --git a/src/game/GameView.cpp b/src/game/GameView.cpp index 3c4756849..ae93f90dd 100644 --- a/src/game/GameView.cpp +++ b/src/game/GameView.cpp @@ -856,6 +856,7 @@ void GameView::OnDraw() ren->draw_air(); ren->render_parts(); ren->render_fire(); + ren->draw_grav(); ren->DrawWalls(); if(activeBrush && currentMouse.X > 0 && currentMouse.X < XRES && currentMouse.Y > 0 && currentMouse.Y < YRES) { diff --git a/src/options/OptionsModel.cpp b/src/options/OptionsModel.cpp index 3c498e124..c0a69f530 100644 --- a/src/options/OptionsModel.cpp +++ b/src/options/OptionsModel.cpp @@ -41,12 +41,15 @@ void OptionsModel::SetAmbientHeatSimulation(bool state) bool OptionsModel::GetNewtonianGravity() { - return false; - //sim-> + return sim->grav->ngrav_enable?true:false; } void OptionsModel::SetNewtonianGravity(bool state) { + if(state) + sim->grav->start_grav_async(); + else + sim->grav->stop_grav_async(); notifySettingsChanged(); } diff --git a/src/simulation/Gravity.cpp b/src/simulation/Gravity.cpp index d2d72950d..1a7456697 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 764d29dfc..7fdd6d6fe 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(); }