From 83e4f885da2506f4ce724630777816c26cf7c8c5 Mon Sep 17 00:00:00 2001 From: cracker64 Date: Sat, 6 Aug 2011 00:16:30 -0300 Subject: [PATCH 1/5] Added tmp2 for tpt.get_property and tpt.set_property --- src/luaconsole.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/luaconsole.c b/src/luaconsole.c index 52096894a..b0c234d62 100644 --- a/src/luaconsole.c +++ b/src/luaconsole.c @@ -437,6 +437,9 @@ int luatpt_set_property(lua_State* l) } else if (strcmp(prop,"tmp")==0){ offset = offsetof(particle, tmp); format = 1; + } else if (strcmp(prop,"tmp2")==0){ + offset = offsetof(particle, tmp2); + format = 1; } else if (strcmp(prop,"vy")==0){ offset = offsetof(particle, vy); format = 2; @@ -577,6 +580,10 @@ int luatpt_get_property(lua_State* l) lua_pushinteger(l, parts[i].tmp); return 1; } + if (strcmp(prop,"tmp2")==0){ + lua_pushinteger(l, parts[i].tmp2); + return 1; + } if (strcmp(prop,"vy")==0){ lua_pushnumber(l, (double)parts[i].vy); return 1; From d20c704d88df23bf1355b4d5350698e5e47e6dc7 Mon Sep 17 00:00:00 2001 From: jacksonmj Date: Fri, 29 Jul 2011 22:06:58 +0800 Subject: [PATCH 2/5] LIFE descriptions --- includes/powder.h | 48 +++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/includes/powder.h b/includes/powder.h index 5299dc06e..6abb47ba1 100644 --- a/includes/powder.h +++ b/includes/powder.h @@ -786,30 +786,30 @@ typedef struct gol_menu gol_menu; static gol_menu gmenu[NGOL] = { - {"GOL", PIXPACK(0x0CAC00), 0, "GOL"}, - {"HLIF", PIXPACK(0xFF0000), 1, "GOL"}, - {"ASIM", PIXPACK(0x0000FF), 2, "GOL"}, - {"2x2", PIXPACK(0xFFFF00), 3, "GOL"}, - {"DANI", PIXPACK(0x00FFFF), 4, "GOL"}, - {"AMOE", PIXPACK(0xFF00FF), 5, "GOL"}, - {"MOVE", PIXPACK(0xFFFFFF), 6, "GOL"}, - {"PGOL", PIXPACK(0xE05010), 7, "GOL"}, - {"DMOE", PIXPACK(0x500000), 8, "GOL"}, - {"34", PIXPACK(0x500050), 9, "GOL"}, - {"LLIF", PIXPACK(0x505050), 10, "GOL"}, - {"STAN", PIXPACK(0x5000FF), 11, "GOL"}, - {"SEED", PIXPACK(0xFBEC7D), 12, "GOL"}, - {"MAZE", PIXPACK(0xA8E4A0), 13, "GOL"}, - {"COAG", PIXPACK(0x9ACD32), 14, "GOL"}, - {"WALL", PIXPACK(0x0047AB), 15, "GOL"}, - {"GNAR", PIXPACK(0xE5B73B), 16, "GOL"}, - {"REPL", PIXPACK(0x259588), 17, "GOL"}, - {"MYST", PIXPACK(0x0C3C00), 18, "GOL"}, - {"LOTE", PIXPACK(0xFF0000), 19, "GOL"}, - {"FRG2", PIXPACK(0x00FF00), 20, "GOL"}, - {"STAR", PIXPACK(0x0000FF), 21, "GOL"}, - {"FROG", PIXPACK(0x00AA00), 22, "GOL"}, - {"BRAN", PIXPACK(0xCCCC00), 23, "GOL"} + {"GOL", PIXPACK(0x0CAC00), 0, "Game Of Life B3/S23"}, + {"HLIF", PIXPACK(0xFF0000), 1, "High Life B36/S23"}, + {"ASIM", PIXPACK(0x0000FF), 2, "Assimilation B345/S4567"}, + {"2x2", PIXPACK(0xFFFF00), 3, "2x2 B36/S125"}, + {"DANI", PIXPACK(0x00FFFF), 4, "Day and Night B3678/S34678"}, + {"AMOE", PIXPACK(0xFF00FF), 5, "Amoeba B357/S1358"}, + {"MOVE", PIXPACK(0xFFFFFF), 6, "'Move' particles. Does not move things.. it is a life type B368/S245"}, + {"PGOL", PIXPACK(0xE05010), 7, "Pseudo Life B357/S238"}, + {"DMOE", PIXPACK(0x500000), 8, "Diamoeba B35678/S5678"}, + {"34", PIXPACK(0x500050), 9, "34 B34/S34"}, + {"LLIF", PIXPACK(0x505050), 10, "Long Life B345/S5"}, + {"STAN", PIXPACK(0x5000FF), 11, "Stains B3678/S235678"}, + {"SEED", PIXPACK(0xFBEC7D), 12, "B2/S"}, + {"MAZE", PIXPACK(0xA8E4A0), 13, "B3/S12345"}, + {"COAG", PIXPACK(0x9ACD32), 14, "B378/S235678"}, + {"WALL", PIXPACK(0x0047AB), 15, "B45678/S2345"}, + {"GNAR", PIXPACK(0xE5B73B), 16, "B1/S1"}, + {"REPL", PIXPACK(0x259588), 17, "B1357/S1357"}, + {"MYST", PIXPACK(0x0C3C00), 18, "B3458/S05678"}, + {"LOTE", PIXPACK(0xFF0000), 19, "Behaves kinda like Living on the Edge S3458/B37/4"}, + {"FRG2", PIXPACK(0x00FF00), 20, "Like Frogs rule S124/B3/3"}, + {"STAR", PIXPACK(0x0000FF), 21, "Like Star Wars rule S3456/B278/6"}, + {"FROG", PIXPACK(0x00AA00), 22, "Frogs S12/B34/3"}, + {"BRAN", PIXPACK(0xCCCC00), 23, "Brian 6 S6/B246/3"} }; static int grule[NGOL+1][10] = From 788b0cd04ce08b1a0d05d4ecd3cc0b8cfdd616c3 Mon Sep 17 00:00:00 2001 From: jacksonmj Date: Fri, 15 Jul 2011 05:16:11 +0800 Subject: [PATCH 3/5] Calculate Newtonian gravity using fast Fourier transforms About 16% slower for one cell changing, same speed for 6 cells changing, and several hundred times faster for whole screen changing. --- Makefile | 4 +- includes/air.h | 5 ++ includes/defines.h | 1 + src/air.c | 161 +++++++++++++++++++++++++++++++++++++++++++++ src/main.c | 8 ++- 5 files changed, 175 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 5ac4ae52d..ef98391ef 100644 --- a/Makefile +++ b/Makefile @@ -7,9 +7,9 @@ PY_INCPATH := $(shell $(PY_BIN) -c "import os.path,sys;print os.path.join(sys.ex PY_LDFLAGS := $(shell $(PY_BIN) -c "import distutils.sysconfig;print distutils.sysconfig.get_config_var('LINKFORSHARED')") PYCOMMAND := $(PY_BIN) getheader.py -CFLAGS := -w -std=c99 -D_POSIX_C_SOURCE=200112L -DLUACONSOLE -Iincludes/ +CFLAGS := -w -std=c99 -D_POSIX_C_SOURCE=200112L -DLUACONSOLE -DGRAVFFT -Iincludes/ OFLAGS := -O3 -ffast-math -ftree-vectorize -funsafe-math-optimizations -LFLAGS := -lpthread -lSDL -lm -lbz2 -lX11 -llua5.1 #-lpython$(PY_VERSION) -L$(PY_LIBPATH) -I$(PY_INCPATH) $(PY_LDFLAGS) +LFLAGS := -lpthread -lSDL -lfftw3f -lm -lbz2 -lX11 -llua5.1 #-lpython$(PY_VERSION) -L$(PY_LIBPATH) -I$(PY_INCPATH) $(PY_LDFLAGS) LFLAGS_X := -lm -lbz2 -lSDLmain -I/Library/Frameworks/Python.framework/Versions/$(PY_VERSION)/include/python$(PY_VERSION) MFLAGS_SSE3 := -march=native -DX86 -DX86_SSE3 -msse3 MFLAGS_SSE2 := -march=native -DX86 -DX86_SSE2 -msse2 diff --git a/includes/air.h b/includes/air.h index b1dc819bc..0f3731054 100644 --- a/includes/air.h +++ b/includes/air.h @@ -41,6 +41,11 @@ void update_airh(void); void update_grav(void); +#ifdef GRAVFFT +void grav_fft_init(); +void grav_fft_cleanup(); +#endif + void update_air(void); #endif diff --git a/includes/defines.h b/includes/defines.h index 3f3760e9c..7c0072209 100644 --- a/includes/defines.h +++ b/includes/defines.h @@ -92,6 +92,7 @@ extern unsigned char ZSIZE; #define BRUSH_NUM 3 +//#define GRAVFFT //#define LUACONSOLE //#define PYCONSOLE //#define PYEXT diff --git a/src/air.c b/src/air.c index 1b83665b3..45d000a17 100644 --- a/src/air.c +++ b/src/air.c @@ -2,6 +2,11 @@ #include #include #include + +#ifdef GRAVFFT +#include +#endif + float kernel[9]; float gravmap[YRES/CELL][XRES/CELL]; //Maps to be used by the main thread @@ -154,6 +159,159 @@ void bilinear_interpolation(float *src, float *dst, int sw, int sh, int rw, int } } +#ifdef GRAVFFT +int grav_fft_status = 0; +float *th_ptgravx, *th_ptgravy, *th_gravmapbig, *th_gravxbig, *th_gravybig; +fftwf_complex *th_ptgravxt, *th_ptgravyt, *th_gravmapbigt, *th_gravxbigt, *th_gravybigt; +fftwf_plan plan_gravmap, plan_gravx_inverse, plan_gravy_inverse; + +void grav_fft_init() +{ + int xblock2 = XRES/CELL*2; + int yblock2 = YRES/CELL*2; + int x, y, fft_tsize = (xblock2/2+1)*yblock2; + float distance, scaleFactor; + fftwf_plan plan_ptgravx, plan_ptgravy; + 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)); + + //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_ptgravy = fftwf_plan_dft_r2c_2d(yblock2, xblock2, th_ptgravy, th_ptgravyt, FFTW_MEASURE); + plan_gravmap = fftwf_plan_dft_r2c_2d(yblock2, xblock2, th_gravmapbig, th_gravmapbigt, FFTW_MEASURE); + plan_gravx_inverse = fftwf_plan_dft_c2r_2d(yblock2, xblock2, th_gravxbigt, th_gravxbig, FFTW_MEASURE); + plan_gravy_inverse = fftwf_plan_dft_c2r_2d(yblock2, xblock2, th_gravybigt, th_gravybig, FFTW_MEASURE); + + //(XRES/CELL)*(YRES/CELL)*4 is size of data array, scaling needed because FFTW calculates an unnormalized DFT + scaleFactor = -M_GRAV/((XRES/CELL)*(YRES/CELL)*4); + //calculate velocity map caused by a point mass + for (y=0; y Date: Wed, 3 Aug 2011 20:54:19 +0800 Subject: [PATCH 4/5] Fix persistent mode photon lines bug --- src/powder.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/powder.c b/src/powder.c index dbf9c45ac..a1fa55ea1 100644 --- a/src/powder.c +++ b/src/powder.c @@ -1031,6 +1031,7 @@ static void create_gain_photon(int pp)//photons from PHOT going through GLOW parts[i].vy = parts[pp].vy; parts[i].temp = parts[pmap[ny][nx] >> 8].temp; parts[i].tmp = 0; + parts[i].pavg[0] = parts[i].pavg[1] = 0.0f; photons[ny][nx] = PT_PHOT|(i<<8); temp_bin = (int)((parts[i].temp-273.0f)*0.25f); @@ -1067,6 +1068,7 @@ static void create_cherenkov_photon(int pp)//photons from NEUT going through GLA parts[i].y = parts[pp].y; parts[i].temp = parts[pmap[ny][nx] >> 8].temp; parts[i].tmp = 0; + parts[i].pavg[0] = parts[i].pavg[1] = 0.0f; photons[ny][nx] = PT_PHOT|(i<<8); if (lr) { From 39e1ffe5bf64c29e81ecf8779dfbbe41bb5173d5 Mon Sep 17 00:00:00 2001 From: jacksonmj Date: Fri, 5 Aug 2011 19:16:09 +0800 Subject: [PATCH 5/5] 0 is a valid menu number (walls) --- src/luaconsole.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/luaconsole.c b/src/luaconsole.c index b0c234d62..dac25ea8f 100644 --- a/src/luaconsole.c +++ b/src/luaconsole.c @@ -1011,8 +1011,8 @@ int luatpt_airheat(lua_State* l) int luatpt_active_menu(lua_State* l) { int menuid; - menuid = luaL_optint(l, 1, 0); - if (menuid < SC_TOTAL && menuid > 0) + menuid = luaL_optint(l, 1, -1); + if (menuid < SC_TOTAL && menuid >= 0) active_menu = menuid; else return luaL_error(l, "Invalid menu");