Newtonian gravity working
This commit is contained in:
parent
a0506495ad
commit
465cb12af4
14
Makefile
14
Makefile
@ -19,14 +19,16 @@ powder.exe: build/powder.exe
|
|||||||
powder-release: build/powder-release
|
powder-release: build/powder-release
|
||||||
powder: build/powder
|
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: 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-release.exe: LFLAGS := -lmingw32 -lregex -lws2_32 -lSDLmain -lpthread -lSDL -lm -lbz2 -llua -lfftw3f-3 -mwindows
|
||||||
build/powder.exe: CFLAGS += -DWIN32 -DWINCONSOLE
|
build/powder.exe: CFLAGS += -DWIN32
|
||||||
build/powder.exe: LFLAGS := -lmingw32 -lregex -lws2_32 -lSDLmain -lpthread -lSDL -lm -lbz2 -llua #-mwindows
|
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: 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: 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
|
build/powder-release.exe: $(SOURCES) build/powder-res.o
|
||||||
$(CPPC_WIN) $(CFLAGS) $(OFLAGS) $(LDFLAGS) $(SOURCES) $(LFLAGS) build/powder-res.o -o $@
|
$(CPPC_WIN) $(CFLAGS) $(OFLAGS) $(LDFLAGS) $(SOURCES) $(LFLAGS) build/powder-res.o -o $@
|
||||||
|
@ -856,6 +856,7 @@ void GameView::OnDraw()
|
|||||||
ren->draw_air();
|
ren->draw_air();
|
||||||
ren->render_parts();
|
ren->render_parts();
|
||||||
ren->render_fire();
|
ren->render_fire();
|
||||||
|
ren->draw_grav();
|
||||||
ren->DrawWalls();
|
ren->DrawWalls();
|
||||||
if(activeBrush && currentMouse.X > 0 && currentMouse.X < XRES && currentMouse.Y > 0 && currentMouse.Y < YRES)
|
if(activeBrush && currentMouse.X > 0 && currentMouse.X < XRES && currentMouse.Y > 0 && currentMouse.Y < YRES)
|
||||||
{
|
{
|
||||||
|
@ -41,12 +41,15 @@ void OptionsModel::SetAmbientHeatSimulation(bool state)
|
|||||||
|
|
||||||
bool OptionsModel::GetNewtonianGravity()
|
bool OptionsModel::GetNewtonianGravity()
|
||||||
{
|
{
|
||||||
return false;
|
return sim->grav->ngrav_enable?true:false;
|
||||||
//sim->
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void OptionsModel::SetNewtonianGravity(bool state)
|
void OptionsModel::SetNewtonianGravity(bool state)
|
||||||
{
|
{
|
||||||
|
if(state)
|
||||||
|
sim->grav->start_grav_async();
|
||||||
|
else
|
||||||
|
sim->grav->stop_grav_async();
|
||||||
notifySettingsChanged();
|
notifySettingsChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,6 +37,7 @@ void Gravity::bilinear_interpolation(float *src, float *dst, int sw, int sh, int
|
|||||||
|
|
||||||
void Gravity::gravity_init()
|
void Gravity::gravity_init()
|
||||||
{
|
{
|
||||||
|
ngrav_enable = 0;
|
||||||
//Allocate full size Gravmaps
|
//Allocate full size Gravmaps
|
||||||
th_ogravmap = (float *)calloc((XRES/CELL)*(YRES/CELL), sizeof(float));
|
th_ogravmap = (float *)calloc((XRES/CELL)*(YRES/CELL), sizeof(float));
|
||||||
th_gravmap = (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;
|
if (grav_fft_status) return;
|
||||||
|
|
||||||
//use fftw malloc function to ensure arrays are aligned, to get better performance
|
//use fftw malloc function to ensure arrays are aligned, to get better performance
|
||||||
th_ptgravx = fftwf_malloc(xblock2*yblock2*sizeof(float));
|
th_ptgravx = (float*)fftwf_malloc(xblock2*yblock2*sizeof(float));
|
||||||
th_ptgravy = fftwf_malloc(xblock2*yblock2*sizeof(float));
|
th_ptgravy = (float*)fftwf_malloc(xblock2*yblock2*sizeof(float));
|
||||||
th_ptgravxt = fftwf_malloc(fft_tsize*sizeof(fftwf_complex));
|
th_ptgravxt = (fftwf_complex*)fftwf_malloc(fft_tsize*sizeof(fftwf_complex));
|
||||||
th_ptgravyt = fftwf_malloc(fft_tsize*sizeof(fftwf_complex));
|
th_ptgravyt = (fftwf_complex*)fftwf_malloc(fft_tsize*sizeof(fftwf_complex));
|
||||||
th_gravmapbig = fftwf_malloc(xblock2*yblock2*sizeof(float));
|
th_gravmapbig = (float*)fftwf_malloc(xblock2*yblock2*sizeof(float));
|
||||||
th_gravmapbigt = fftwf_malloc(fft_tsize*sizeof(fftwf_complex));
|
th_gravmapbigt = (fftwf_complex*)fftwf_malloc(fft_tsize*sizeof(fftwf_complex));
|
||||||
th_gravxbig = fftwf_malloc(xblock2*yblock2*sizeof(float));
|
th_gravxbig = (float*)fftwf_malloc(xblock2*yblock2*sizeof(float));
|
||||||
th_gravybig = fftwf_malloc(xblock2*yblock2*sizeof(float));
|
th_gravybig = (float*)fftwf_malloc(xblock2*yblock2*sizeof(float));
|
||||||
th_gravxbigt = fftwf_malloc(fft_tsize*sizeof(fftwf_complex));
|
th_gravxbigt = (fftwf_complex*)fftwf_malloc(fft_tsize*sizeof(fftwf_complex));
|
||||||
th_gravybigt = 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
|
//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);
|
plan_ptgravx = fftwf_plan_dft_r2c_2d(yblock2, xblock2, th_ptgravx, th_ptgravxt, FFTW_MEASURE);
|
||||||
|
@ -8,6 +8,9 @@
|
|||||||
#include "Gravity.h"
|
#include "Gravity.h"
|
||||||
#include "SaveLoader.h"
|
#include "SaveLoader.h"
|
||||||
|
|
||||||
|
#undef LUACONSOLE
|
||||||
|
//#include "cat/LuaScriptHelper.h"
|
||||||
|
|
||||||
int Simulation::Load(unsigned char * data, int dataLength)
|
int Simulation::Load(unsigned char * data, int dataLength)
|
||||||
{
|
{
|
||||||
return SaveLoader::Load(data, dataLength, this, true, 0, 0);
|
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
|
#endif
|
||||||
|
|
||||||
if(!sys_pause||framerender)
|
if(!sys_pause||framerender)
|
||||||
|
{
|
||||||
air->update_air();
|
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(pmap, 0, sizeof(pmap));
|
||||||
memset(photons, 0, sizeof(photons));
|
memset(photons, 0, sizeof(photons));
|
||||||
@ -3424,4 +3436,6 @@ Simulation::Simulation():
|
|||||||
|
|
||||||
init_can_move();
|
init_can_move();
|
||||||
clear_sim();
|
clear_sim();
|
||||||
|
|
||||||
|
grav->gravity_mask();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user