summaryrefslogtreecommitdiff
path: root/includes
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-01-08 17:39:03 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-01-08 17:39:03 (GMT)
commitb0ea52690ba56a0d0602ad8674b7e5ab2ba3e778 (patch)
tree7d72e0509f4d2643d3be837a337d088ca5949c73 /includes
downloadpowder-b0ea52690ba56a0d0602ad8674b7e5ab2ba3e778.zip
powder-b0ea52690ba56a0d0602ad8674b7e5ab2ba3e778.tar.gz
Initial
Diffstat (limited to 'includes')
-rw-r--r--includes/Air.h33
-rw-r--r--includes/Config.h146
-rw-r--r--includes/Element.h14
-rw-r--r--includes/ElementFunctions.h168
-rw-r--r--includes/ElementGraphics.h52
-rw-r--r--includes/Elements.h280
-rw-r--r--includes/Graphics.h172
-rw-r--r--includes/Gravity.h108
-rw-r--r--includes/Misc.h108
-rw-r--r--includes/Renderer.h60
-rw-r--r--includes/Simulation.h241
-rw-r--r--includes/interface/Button.h42
-rw-r--r--includes/interface/Component.h53
-rw-r--r--includes/interface/Panel.h22
-rw-r--r--includes/interface/Sandbox.h33
-rw-r--r--includes/interface/State.h61
-rw-r--r--includes/interface/Window.h22
17 files changed, 1615 insertions, 0 deletions
diff --git a/includes/Air.h b/includes/Air.h
new file mode 100644
index 0000000..8e4dc25
--- /dev/null
+++ b/includes/Air.h
@@ -0,0 +1,33 @@
+#ifndef AIR_H
+#define AIR_H
+#include "Config.h"
+
+class Simulation;
+
+class Air
+{
+public:
+ int airMode;
+ //Arrays from the simulation
+ unsigned char (*bmap)[XRES/CELL];
+ unsigned char (*emap)[XRES/CELL];
+ float (*fvx)[XRES/CELL];
+ float (*fvy)[XRES/CELL];
+ //
+ float vx[YRES/CELL][XRES/CELL];
+ float ovx[YRES/CELL][XRES/CELL];
+ float vy[YRES/CELL][XRES/CELL];
+ float ovy[YRES/CELL][XRES/CELL];
+ float pv[YRES/CELL][XRES/CELL];
+ float opv[YRES/CELL][XRES/CELL];
+ float hv[YRES/CELL][XRES/CELL];
+ float ohv[YRES/CELL][XRES/CELL]; // Ambient Heat
+ unsigned char bmap_blockair[YRES/CELL][XRES/CELL];
+ float kernel[9];
+ void make_kernel(void);
+ void update_airh(void);
+ void update_air(void);
+ Air();
+};
+
+#endif
diff --git a/includes/Config.h b/includes/Config.h
new file mode 100644
index 0000000..4cb2da3
--- /dev/null
+++ b/includes/Config.h
@@ -0,0 +1,146 @@
+/*
+ * Config.h
+ *
+ * Created on: Jan 5, 2012
+ * Author: Simon
+ */
+
+//#ifndef CONFIG_H_
+//#define CONFIG_H_
+
+
+#ifdef WIN32
+#define PATH_SEP "\\"
+#else
+#define PATH_SEP "/"
+#endif
+
+//VersionInfoStart
+#define SAVE_VERSION 71
+#define MINOR_VERSION 0
+#define BETA
+#define BUILD_NUM 133
+//VersionInfoEnd
+
+#define IDENT_VERSION "G" //Change this if you're not Simon! It should be a single letter
+
+#define MTOS_EXPAND(str) #str
+#define MTOS(str) MTOS_EXPAND(str)
+
+#define SERVER "powdertoy.co.uk"
+#define SCRIPTSERVER "powdertoy.co.uk"
+
+#define LOCAL_SAVE_DIR "Saves"
+
+#define APPDATA_SUBDIR "\\HardWIRED"
+
+#define THUMB_CACHE_SIZE 256
+
+#ifndef M_PI
+#define M_PI 3.14159265f
+#endif
+#ifndef M_GRAV
+#define M_GRAV 6.67300e-1
+#endif
+
+#define IMGCONNS 3
+#define TIMEOUT 100
+#define HTTP_TIMEOUT 10
+
+#ifdef RENDERER
+#define MENUSIZE 0
+#define BARSIZE 0
+#else
+#define MENUSIZE 40
+#define BARSIZE 17
+#endif
+#define XRES 612
+#define YRES 384
+#define NPART XRES*YRES
+
+#define XCNTR 306
+#define YCNTR 192
+
+#define MAX_DISTANCE sqrt(pow(XRES, 2)+pow(YRES, 2))
+
+#define GRAV_DIFF
+
+#define MAXSIGNS 16
+#define TAG_MAX 256
+
+#define ZSIZE_D 16
+#define ZFACTOR_D 8
+extern unsigned char ZFACTOR;
+extern unsigned char ZSIZE;
+
+#define CELL 4
+#define ISTP (CELL/2)
+#define CFDS (4.0f/CELL)
+
+#define AIR_TSTEPP 0.3f
+#define AIR_TSTEPV 0.4f
+#define AIR_VADV 0.3f
+#define AIR_VLOSS 0.999f
+#define AIR_PLOSS 0.9999f
+
+#define GRID_X 5
+#define GRID_Y 4
+#define GRID_P 3
+#define GRID_S 6
+#define GRID_Z 3
+
+#define CATALOGUE_X 4
+#define CATALOGUE_Y 3
+#define CATALOGUE_S 6
+#define CATALOGUE_Z 3
+
+#define STAMP_MAX 240
+
+#define SAVE_OPS
+
+#define NGOL 25
+#define NGOLALT 24 //NGOL should be 24, but use this var until I find out why
+
+#define CIRCLE_BRUSH 0
+#define SQUARE_BRUSH 1
+#define TRI_BRUSH 2
+#define BRUSH_NUM 3
+
+#define SURF_RANGE 10
+#define NORMAL_MIN_EST 3
+#define NORMAL_INTERP 20
+#define NORMAL_FRAC 16
+
+#define REFRACT 0x80000000
+
+/* heavy flint glass, for awesome refraction/dispersion
+ this way you can make roof prisms easily */
+#define GLASS_IOR 1.9
+#define GLASS_DISP 0.07
+
+#ifdef WIN32
+#define strcasecmp stricmp
+#endif
+#if defined(WIN32) && !defined(__GNUC__)
+#define fmin min
+#define fminf min
+#define fmax max
+#define fmaxf max
+#endif
+
+#if defined(WIN32) && !defined(__GNUC__)
+#define TPT_INLINE _inline
+#else
+#define TPT_INLINE inline
+#endif
+
+#define SDEUT
+//#define REALHEAT
+
+#define DEBUG_PARTS 0x0001
+#define DEBUG_PARTCOUNT 0x0002
+#define DEBUG_DRAWTOOL 0x0004
+#define DEBUG_PERFORMANCE_CALC 0x0008
+#define DEBUG_PERFORMANCE_FRAME 0x0010
+
+//#endif /* CONFIG_H_ */
diff --git a/includes/Element.h b/includes/Element.h
new file mode 100644
index 0000000..449bf51
--- /dev/null
+++ b/includes/Element.h
@@ -0,0 +1,14 @@
+#ifndef ELEMENT_H
+#define ELEMENT_H
+// This header should be included by all files in src/elements/
+
+#include <math.h>
+#include "Simulation.h"
+#include "Renderer.h"
+#include "ElementFunctions.h"
+//#include "powder.h"
+#include "Gravity.h"
+#include "Misc.h"
+#include "ElementGraphics.h"
+
+#endif
diff --git a/includes/ElementFunctions.h b/includes/ElementFunctions.h
new file mode 100644
index 0000000..ef80b6f
--- /dev/null
+++ b/includes/ElementFunctions.h
@@ -0,0 +1,168 @@
+/*
+ * ElementFunctions.h
+ *
+ * Created on: Jan 5, 2012
+ * Author: Simon
+ */
+
+#ifndef ELEMENTFUNCTIONS_H_
+#define ELEMENTFUNCTIONS_H_
+#include "Elements.h"
+
+int update_ACID(UPDATE_FUNC_ARGS);
+int update_ANAR(UPDATE_FUNC_ARGS);
+int update_AMTR(UPDATE_FUNC_ARGS);
+int update_ARAY(UPDATE_FUNC_ARGS);
+int update_BCLN(UPDATE_FUNC_ARGS);
+int update_BCOL(UPDATE_FUNC_ARGS);
+int update_BMTL(UPDATE_FUNC_ARGS);
+int update_BRMT(UPDATE_FUNC_ARGS);
+int update_BOMB(UPDATE_FUNC_ARGS);
+int update_BOYL(UPDATE_FUNC_ARGS);
+int update_BTRY(UPDATE_FUNC_ARGS);
+int update_C5(UPDATE_FUNC_ARGS);
+int update_CLNE(UPDATE_FUNC_ARGS);
+int update_COAL(UPDATE_FUNC_ARGS);
+int update_DEUT(UPDATE_FUNC_ARGS);
+int update_DSTW(UPDATE_FUNC_ARGS);
+int update_FOG(UPDATE_FUNC_ARGS);
+int update_FRZW(UPDATE_FUNC_ARGS);
+int update_FRZZ(UPDATE_FUNC_ARGS);
+int update_FSEP(UPDATE_FUNC_ARGS);
+int update_FUSE(UPDATE_FUNC_ARGS);
+int update_FIRW(UPDATE_FUNC_ARGS);
+int update_FWRK(UPDATE_FUNC_ARGS);
+int update_GLAS(UPDATE_FUNC_ARGS);
+int update_GLOW(UPDATE_FUNC_ARGS);
+int update_GOO(UPDATE_FUNC_ARGS);
+int update_HSWC(UPDATE_FUNC_ARGS);
+int update_IRON(UPDATE_FUNC_ARGS);
+int update_ICEI(UPDATE_FUNC_ARGS);
+int update_ISZ(UPDATE_FUNC_ARGS);
+int update_LCRY(UPDATE_FUNC_ARGS);
+int update_MORT(UPDATE_FUNC_ARGS);
+int update_NEUT(UPDATE_FUNC_ARGS);
+int update_NPTCT(UPDATE_FUNC_ARGS);
+int update_PCLN(UPDATE_FUNC_ARGS);
+int update_PHOT(UPDATE_FUNC_ARGS);
+int update_PIPE(UPDATE_FUNC_ARGS);
+int update_PLNT(UPDATE_FUNC_ARGS);
+int update_PLUT(UPDATE_FUNC_ARGS);
+int update_PRTI(UPDATE_FUNC_ARGS);
+int update_PRTO(UPDATE_FUNC_ARGS);
+int update_PYRO(UPDATE_FUNC_ARGS);
+int update_PUMP(UPDATE_FUNC_ARGS);
+int update_QRTZ(UPDATE_FUNC_ARGS);
+int update_RIME(UPDATE_FUNC_ARGS);
+int update_SHLD1(UPDATE_FUNC_ARGS);
+int update_SHLD2(UPDATE_FUNC_ARGS);
+int update_SHLD3(UPDATE_FUNC_ARGS);
+int update_SHLD4(UPDATE_FUNC_ARGS);
+int update_SING(UPDATE_FUNC_ARGS);
+int update_SLTW(UPDATE_FUNC_ARGS);
+int update_SPAWN(UPDATE_FUNC_ARGS);
+int update_SPAWN2(UPDATE_FUNC_ARGS);
+int update_SPNG(UPDATE_FUNC_ARGS);
+int update_SPRK(UPDATE_FUNC_ARGS);
+int update_STKM(UPDATE_FUNC_ARGS);
+int update_STKM2(UPDATE_FUNC_ARGS);
+int update_SWCH(UPDATE_FUNC_ARGS);
+int update_THDR(UPDATE_FUNC_ARGS);
+int update_THRM(UPDATE_FUNC_ARGS);
+int update_URAN(UPDATE_FUNC_ARGS);
+int update_VINE(UPDATE_FUNC_ARGS);
+int update_WARP(UPDATE_FUNC_ARGS);
+int update_WATR(UPDATE_FUNC_ARGS);
+int update_WIFI(UPDATE_FUNC_ARGS);
+int update_WTRV(UPDATE_FUNC_ARGS);
+int update_YEST(UPDATE_FUNC_ARGS);
+int update_SOAP(UPDATE_FUNC_ARGS);
+int update_O2(UPDATE_FUNC_ARGS);
+int update_H2(UPDATE_FUNC_ARGS);
+int update_NBHL(UPDATE_FUNC_ARGS);
+int update_NWHL(UPDATE_FUNC_ARGS);
+int update_MERC(UPDATE_FUNC_ARGS);
+int update_PBCN(UPDATE_FUNC_ARGS);
+int update_GPMP(UPDATE_FUNC_ARGS);
+int update_CLST(UPDATE_FUNC_ARGS);
+int update_DLAY(UPDATE_FUNC_ARGS);
+int update_WIRE(UPDATE_FUNC_ARGS);
+int update_GBMB(UPDATE_FUNC_ARGS);
+int update_CO2(UPDATE_FUNC_ARGS);
+int update_CBNW(UPDATE_FUNC_ARGS);
+int update_STOR(UPDATE_FUNC_ARGS);
+int update_BIZR(UPDATE_FUNC_ARGS);
+int update_PVOD(UPDATE_FUNC_ARGS);
+int update_CONV(UPDATE_FUNC_ARGS);
+int update_CAUS(UPDATE_FUNC_ARGS);
+int update_DEST(UPDATE_FUNC_ARGS);
+int update_EMP(UPDATE_FUNC_ARGS);
+int update_LIGH(UPDATE_FUNC_ARGS);
+int update_FIGH(UPDATE_FUNC_ARGS);
+int update_ELEC(UPDATE_FUNC_ARGS);
+int update_ACEL(UPDATE_FUNC_ARGS);
+int update_DCEL(UPDATE_FUNC_ARGS);
+int update_BANG(UPDATE_FUNC_ARGS);
+int update_IGNT(UPDATE_FUNC_ARGS);
+int update_MISC(UPDATE_FUNC_ARGS);
+int update_legacy_PYRO(UPDATE_FUNC_ARGS);
+int update_legacy_all(UPDATE_FUNC_ARGS);
+int run_stickman(playerst* playerp, UPDATE_FUNC_ARGS);
+void STKM_init_legs(Simulation * sim, playerst* playerp, int i);
+void STKM_interact(Simulation * sim, playerst* playerp, int i, int x, int y);
+
+
+int graphics_FIRE(GRAPHICS_FUNC_ARGS);
+int graphics_SMKE(GRAPHICS_FUNC_ARGS);
+int graphics_PLSM(GRAPHICS_FUNC_ARGS);
+int graphics_DEUT(GRAPHICS_FUNC_ARGS);
+int graphics_PHOT(GRAPHICS_FUNC_ARGS);
+int graphics_NEUT(GRAPHICS_FUNC_ARGS);
+int graphics_LAVA(GRAPHICS_FUNC_ARGS);
+int graphics_SPRK(GRAPHICS_FUNC_ARGS);
+int graphics_QRTZ(GRAPHICS_FUNC_ARGS);
+int graphics_CLST(GRAPHICS_FUNC_ARGS);
+int graphics_CBNW(GRAPHICS_FUNC_ARGS);
+int graphics_SPNG(GRAPHICS_FUNC_ARGS);
+int graphics_LIFE(GRAPHICS_FUNC_ARGS);
+int graphics_DUST(GRAPHICS_FUNC_ARGS);
+int graphics_GRAV(GRAPHICS_FUNC_ARGS);
+int graphics_WIFI(GRAPHICS_FUNC_ARGS);
+int graphics_PRTI(GRAPHICS_FUNC_ARGS);
+int graphics_PRTO(GRAPHICS_FUNC_ARGS);
+int graphics_BIZR(GRAPHICS_FUNC_ARGS);
+int graphics_PIPE(GRAPHICS_FUNC_ARGS);
+int graphics_INVS(GRAPHICS_FUNC_ARGS);
+int graphics_ACID(GRAPHICS_FUNC_ARGS);
+int graphics_FILT(GRAPHICS_FUNC_ARGS);
+int graphics_BRAY(GRAPHICS_FUNC_ARGS);
+int graphics_SWCH(GRAPHICS_FUNC_ARGS);
+int graphics_THDR(GRAPHICS_FUNC_ARGS);
+int graphics_GLOW(GRAPHICS_FUNC_ARGS);
+int graphics_LCRY(GRAPHICS_FUNC_ARGS);
+int graphics_PCLN(GRAPHICS_FUNC_ARGS);
+int graphics_PBCN(GRAPHICS_FUNC_ARGS);
+int graphics_DLAY(GRAPHICS_FUNC_ARGS);
+int graphics_HSWC(GRAPHICS_FUNC_ARGS);
+int graphics_PVOD(GRAPHICS_FUNC_ARGS);
+int graphics_STOR(GRAPHICS_FUNC_ARGS);
+int graphics_PUMP(GRAPHICS_FUNC_ARGS);
+int graphics_GPMP(GRAPHICS_FUNC_ARGS);
+int graphics_HFLM(GRAPHICS_FUNC_ARGS);
+int graphics_FIRW(GRAPHICS_FUNC_ARGS);
+int graphics_BOMB(GRAPHICS_FUNC_ARGS);
+int graphics_GBMB(GRAPHICS_FUNC_ARGS);
+int graphics_COAL(GRAPHICS_FUNC_ARGS);
+int graphics_STKM(GRAPHICS_FUNC_ARGS);
+int graphics_STKM2(GRAPHICS_FUNC_ARGS);
+int graphics_DEST(GRAPHICS_FUNC_ARGS);
+int graphics_EMP(GRAPHICS_FUNC_ARGS);
+int graphics_LIGH(GRAPHICS_FUNC_ARGS);
+int graphics_FIGH(GRAPHICS_FUNC_ARGS);
+int graphics_ELEC(GRAPHICS_FUNC_ARGS);
+int graphics_WIRE(GRAPHICS_FUNC_ARGS);
+int graphics_ACEL(GRAPHICS_FUNC_ARGS);
+int graphics_DCEL(GRAPHICS_FUNC_ARGS);
+int graphics_DEFAULT(GRAPHICS_FUNC_ARGS);
+
+#endif /* ELEMENTFUNCTIONS_H_ */
diff --git a/includes/ElementGraphics.h b/includes/ElementGraphics.h
new file mode 100644
index 0000000..a880e71
--- /dev/null
+++ b/includes/ElementGraphics.h
@@ -0,0 +1,52 @@
+#ifndef PGRAPHICS_H
+#define PGRAPHICS_H
+
+#define PMODE 0x00000FFF
+#define PMODE_NONE 0x00000000
+#define PMODE_FLAT 0x00000001
+#define PMODE_BLOB 0x00000002
+#define PMODE_BLUR 0x00000004
+#define PMODE_GLOW 0x00000008
+#define PMODE_SPARK 0x00000010
+#define PMODE_FLARE 0x00000020
+#define PMODE_LFLARE 0x00000040
+#define PMODE_ADD 0x00000080
+#define PMODE_BLEND 0x00000100
+#define PSPEC_STICKMAN 0x00000200
+
+#define OPTIONS 0x0000F000
+#define NO_DECO 0x00001000
+#define DECO_FIRE 0x00002000
+
+#define FIREMODE 0x00FF0000
+#define FIRE_ADD 0x00010000
+#define FIRE_BLEND 0x00020000
+
+#define EFFECT 0xFF000000
+#define EFFECT_GRAVIN 0x01000000
+#define EFFECT_GRAVOUT 0x02000000
+
+#define RENDER_EFFE OPTIONS | PSPEC_STICKMAN | EFFECT | PMODE_SPARK | PMODE_FLARE | PMODE_LFLARE
+#define RENDER_FIRE OPTIONS | PSPEC_STICKMAN | PMODE_FLAT | PMODE_ADD | PMODE_BLEND | FIREMODE
+#define RENDER_GLOW OPTIONS | PSPEC_STICKMAN | PMODE_FLAT | PMODE_GLOW | PMODE_ADD | PMODE_BLEND
+#define RENDER_BLUR OPTIONS | PSPEC_STICKMAN | PMODE_FLAT | PMODE_BLUR | PMODE_ADD | PMODE_BLEND
+#define RENDER_BLOB OPTIONS | PSPEC_STICKMAN | PMODE_FLAT | PMODE_BLOB | PMODE_ADD | PMODE_BLEND
+#define RENDER_BASC OPTIONS | PSPEC_STICKMAN | PMODE_FLAT | PMODE_ADD | PMODE_BLEND
+#define RENDER_NONE OPTIONS | PSPEC_STICKMAN | PMODE_FLAT
+
+#define COLOUR_HEAT 0x00000001
+#define COLOUR_LIFE 0x00000002
+#define COLOUR_GRAD 0x00000004
+
+#define COLOUR_DEFAULT 0x00000000
+
+#define DISPLAY_AIRC 0x00000001
+#define DISPLAY_AIRP 0x00000002
+#define DISPLAY_AIRV 0x00000004
+#define DISPLAY_AIRH 0x00000008
+#define DISPLAY_AIR 0x0000000F
+#define DISPLAY_WARP 0x00000010
+#define DISPLAY_PERS 0x00000020
+#define DISPLAY_EFFE 0x00000040
+
+#endif
diff --git a/includes/Elements.h b/includes/Elements.h
new file mode 100644
index 0000000..204460c
--- /dev/null
+++ b/includes/Elements.h
@@ -0,0 +1,280 @@
+/*
+ * Elements.h
+ *
+ * Created on: Jan 5, 2012
+ * Author: Simon
+ */
+
+//#ifndef ELEMENTS_H_
+//#define ELEMENTS_H_
+
+//#include "Config.h"
+//#include "Simulation.h"
+
+#define IPL -257.0f
+#define IPH 257.0f
+#define ITL MIN_TEMP-1
+#define ITH MAX_TEMP+1
+// no transition (PT_NONE means kill part)
+#define NT -1
+// special transition - lava ctypes etc need extra code, which is only found and run if ST is given
+#define ST PT_NUM
+
+#define R_TEMP 22
+#define MAX_TEMP 9999
+#define MIN_TEMP 0
+#define O_MAX_TEMP 3500
+#define O_MIN_TEMP -273
+
+#define TYPE_PART 0x00001 //1 Powders
+#define TYPE_LIQUID 0x00002 //2 Liquids
+#define TYPE_SOLID 0x00004 //4 Solids
+#define TYPE_GAS 0x00008 //8 Gasses (Includes plasma)
+#define TYPE_ENERGY 0x00010 //16 Energy (Thunder, Light, Neutrons etc.)
+#define PROP_CONDUCTS 0x00020 //32 Conducts electricity
+#define PROP_BLACK 0x00040 //64 Absorbs Photons (not currently implemented or used, a photwl attribute might be better)
+#define PROP_NEUTPENETRATE 0x00080 //128 Penetrated by neutrons
+#define PROP_NEUTABSORB 0x00100 //256 Absorbs neutrons, reflect is default (not currently implemented or used)
+#define PROP_NEUTPASS 0x00200 //512 Neutrons pass through, such as with glass
+#define PROP_DEADLY 0x00400 //1024 Is deadly for stickman (not currently implemented or used)
+#define PROP_HOT_GLOW 0x00800 //2048 Hot Metal Glow
+#define PROP_LIFE 0x01000 //4096 Is a GoL type
+#define PROP_RADIOACTIVE 0x02000 //8192 Radioactive
+#define PROP_LIFE_DEC 0x04000 //2^14 Life decreases by one every frame if > zero
+#define PROP_LIFE_KILL 0x08000 //2^15 Kill when life value is <= zero
+#define PROP_LIFE_KILL_DEC 0x10000 //2^16 Kill when life value is decremented to <= zero
+#define PROP_SPARKSETTLE 0x20000 //2^17 Allow Sparks/Embers to settle
+
+#define FLAG_STAGNANT 1
+
+#define ST_NONE 0
+#define ST_SOLID 1
+#define ST_LIQUID 2
+#define ST_GAS 3
+
+#define UPDATE_FUNC_ARGS Simulation* sim, int i, int x, int y, int surround_space, int nt, Particle *parts, int pmap[YRES][XRES]
+// to call another update function with same arguments:
+#define UPDATE_FUNC_SUBCALL_ARGS sim, i, x, y, surround_space, nt, parts, pmap
+
+#define GRAPHICS_FUNC_ARGS Renderer * ren, Particle *cpart, int nx, int ny, int *pixel_mode, int* cola, int *colr, int *colg, int *colb, int *firea, int *firer, int *fireg, int *fireb
+#define GRAPHICS_FUNC_SUBCALL_ARGS ren, cpart, nx, ny, pixel_mode, cola, colr, colg, colb, firea, firer, fireg, fireb
+
+#define UI_WALLSTART 222
+#define UI_ACTUALSTART 122
+#define UI_WALLCOUNT 25
+
+#define WL_WALLELEC 122
+#define WL_EWALL 123
+#define WL_DETECT 124
+#define WL_STREAM 125
+#define WL_SIGN 126
+#define WL_FAN 127
+#define WL_FANHELPER 255
+#define WL_ALLOWLIQUID 128
+#define WL_DESTROYALL 129
+#define WL_ERASE 130
+#define WL_WALL 131
+#define WL_ALLOWAIR 132
+#define WL_ALLOWSOLID 133
+#define WL_ALLOWALLELEC 134
+#define WL_EHOLE 135
+
+#define SPC_AIR 236
+#define SPC_HEAT 237
+#define SPC_COOL 238
+#define SPC_VACUUM 239
+#define SPC_WIND 241
+#define SPC_PGRV 243
+#define SPC_NGRV 244
+#define SPC_PROP 246
+
+#define WL_ALLOWGAS 140
+#define WL_GRAV 142
+#define WL_ALLOWENERGY 145
+
+#define NGT_GOL 0
+#define NGT_HLIF 1
+#define NGT_ASIM 2
+#define NGT_2x2 3
+#define NGT_DANI 4
+#define NGT_AMOE 5
+#define NGT_MOVE 6
+#define NGT_PGOL 7
+#define NGT_DMOE 8
+#define NGT_34 9
+#define NGT_LLIF 10
+#define NGT_STAN 11
+#define NGT_SEED 12
+#define NGT_MAZE 13
+#define NGT_COAG 14
+#define NGT_WALL 15
+#define NGT_GNAR 16
+#define NGT_REPL 17
+#define NGT_MYST 18
+#define NGT_LOTE 19
+#define NGT_FRG2 20
+#define NGT_STAR 21
+#define NGT_FROG 22
+#define NGT_BRAN 23
+
+#define PT_NONE 0
+#define PT_DUST 1
+#define PT_WATR 2
+#define PT_OIL 3
+#define PT_FIRE 4
+#define PT_STNE 5
+#define PT_LAVA 6
+#define PT_GUNP 7
+#define PT_NITR 8
+#define PT_CLNE 9
+#define PT_GAS 10
+#define PT_PLEX 11
+#define PT_GOO 12
+#define PT_ICEI 13
+#define PT_METL 14
+#define PT_SPRK 15
+#define PT_SNOW 16
+#define PT_WOOD 17
+#define PT_NEUT 18
+#define PT_PLUT 19
+#define PT_PLNT 20
+#define PT_ACID 21
+#define PT_VOID 22
+#define PT_WTRV 23
+#define PT_CNCT 24
+#define PT_DSTW 25
+#define PT_SALT 26
+#define PT_SLTW 27
+#define PT_DMND 28
+#define PT_BMTL 29
+#define PT_BRMT 30
+#define PT_PHOT 31
+#define PT_URAN 32
+#define PT_WAX 33
+#define PT_MWAX 34
+#define PT_PSCN 35
+#define PT_NSCN 36
+#define PT_LNTG 37
+#define PT_INSL 38
+#define PT_BHOL 39
+#define PT_WHOL 40
+#define PT_RBDM 41
+#define PT_LRBD 42
+#define PT_NTCT 43
+#define PT_SAND 44
+#define PT_GLAS 45
+#define PT_PTCT 46
+#define PT_BGLA 47
+#define PT_THDR 48
+#define PT_PLSM 49
+#define PT_ETRD 50
+#define PT_NICE 51
+#define PT_NBLE 52
+#define PT_BTRY 53
+#define PT_LCRY 54
+#define PT_STKM 55
+#define PT_SWCH 56
+#define PT_SMKE 57
+#define PT_DESL 58
+#define PT_COAL 59
+#define PT_LO2 60
+#define PT_O2 61
+#define PT_INWR 62
+#define PT_YEST 63
+#define PT_DYST 64
+#define PT_THRM 65
+#define PT_GLOW 66
+#define PT_BRCK 67
+#define PT_HFLM 68
+#define PT_FIRW 69
+#define PT_FUSE 70
+#define PT_FSEP 71
+#define PT_AMTR 72
+#define PT_BCOL 73
+#define PT_PCLN 74
+#define PT_HSWC 75
+#define PT_IRON 76
+#define PT_MORT 77
+#define PT_LIFE 78
+#define PT_DLAY 79
+#define PT_CO2 80
+#define PT_DRIC 81
+#define PT_CBNW 82
+#define PT_STOR 83
+#define PT_PVOD 84
+#define PT_CONV 85
+#define PT_CAUS 86
+
+#define PT_LIGH 87
+#define PT_TESC 88
+#define PT_DEST 89
+
+#define PT_SPNG 90
+#define PT_RIME 91
+#define PT_FOG 92
+#define PT_BCLN 93
+#define PT_LOVE 94
+#define PT_DEUT 95
+#define PT_WARP 96
+#define PT_PUMP 97
+#define PT_FWRK 98
+#define PT_PIPE 99
+#define PT_FRZZ 100
+#define PT_FRZW 101
+#define PT_GRAV 102
+#define PT_BIZR 103
+#define PT_BIZRG 104
+#define PT_BIZRS 105
+#define PT_INST 106
+#define PT_ISOZ 107
+#define PT_ISZS 108
+#define PT_PRTI 109
+#define PT_PRTO 110
+#define PT_PSTE 111
+#define PT_PSTS 112
+#define PT_ANAR 113
+#define PT_VINE 114
+#define PT_INVIS 115
+#define PT_EQUALVEL 116 //all particles equal their velocities
+#define PT_SPAWN2 117
+#define PT_SPAWN 118
+#define PT_SHLD1 119
+#define PT_SHLD2 120
+#define PT_SHLD3 121
+#define PT_SHLD4 122
+#define PT_LOLZ 123
+#define PT_WIFI 124
+#define PT_FILT 125
+#define PT_ARAY 126
+#define PT_BRAY 127
+#define PT_STKM2 128
+#define PT_BOMB 129
+#define PT_C5 130
+#define PT_SING 131
+#define PT_QRTZ 132
+#define PT_PQRT 133
+#define PT_EMP 134
+#define PT_BREC 135
+#define PT_ELEC 136
+#define PT_ACEL 137
+#define PT_DCEL 138
+#define PT_BANG 139
+#define PT_IGNT 140
+#define PT_BOYL 141
+
+#define OLD_PT_WIND 147
+#define PT_H2 148
+#define PT_SOAP 149
+#define PT_NBHL 150
+#define PT_NWHL 151
+#define PT_MERC 152
+#define PT_PBCN 153
+#define PT_GPMP 154
+#define PT_CLST 155
+#define PT_WIRE 156
+#define PT_GBMB 157
+#define PT_FIGH 158
+#define PT_NUM 159
+
+
+//#endif /* ELEMENTS_H_ */
diff --git a/includes/Graphics.h b/includes/Graphics.h
new file mode 100644
index 0000000..6cd5b36
--- /dev/null
+++ b/includes/Graphics.h
@@ -0,0 +1,172 @@
+#ifndef GRAPHICS_H
+#define GRAPHICS_H
+
+#include <SDL/SDL.h>
+#include <string>
+#include "Config.h"
+//#include "powder.h"
+
+#ifdef PIX16
+#define PIXELSIZE 2
+#define PIXPACK(x) ((((x)>>8)&0xF800)|(((x)>>5)&0x07E0)|(((x)>>3)&0x001F))
+#define PIXRGB(r,g,b) ((((r)<<8)&0xF800)|(((g)<<3)&0x07E0)|(((b)>>3)&0x001F))
+#define PIXR(x) (((x)>>8)&0xF8)
+#define PIXG(x) (((x)>>3)&0xFC)
+#define PIXB(x) (((x)<<3)&0xF8)
+#else
+#define PIXELSIZE 4
+#ifdef PIX32BGR
+#define PIXPACK(x) ((((x)>>16)&0x0000FF)|((x)&0x00FF00)|(((x)<<16)&0xFF0000))
+#define PIXRGB(r,g,b) (((b)<<16)|((g)<<8)|((r)))// (((b)<<16)|((g)<<8)|(r))
+#define PIXR(x) ((x)&0xFF)
+#define PIXG(x) (((x)>>8)&0xFF)
+#define PIXB(x) ((x)>>16)
+#else
+#ifdef PIX32BGRA
+#define PIXPACK(x) ((((x)>>8)&0x0000FF00)|(((x)<<8)&0x00FF0000)|(((x)<<24)&0xFF000000))
+#define PIXRGB(r,g,b) (((b)<<24)|((g)<<16)|((r)<<8))
+#define PIXR(x) (((x)>>8)&0xFF)
+#define PIXG(x) (((x)>>16)&0xFF)
+#define PIXB(x) (((x)>>24))
+#elif defined(PIX32OGL)
+#define PIXPACK(x) (0xFF000000|((x)&0xFFFFFF))
+#define PIXRGB(r,g,b) (0xFF000000|((r)<<16)|((g)<<8)|((b)))// (((b)<<16)|((g)<<8)|(r))
+#define PIXRGBA(r,g,b,a) (((a)<<24)|((r)<<16)|((g)<<8)|((b)))// (((b)<<16)|((g)<<8)|(r))
+#define PIXA(x) (((x)>>24)&0xFF)
+#define PIXR(x) (((x)>>16)&0xFF)
+#define PIXG(x) (((x)>>8)&0xFF)
+#define PIXB(x) ((x)&0xFF)
+#else
+#define PIXPACK(x) (x)
+#define PIXRGB(r,g,b) (((r)<<16)|((g)<<8)|(b))
+#define PIXR(x) ((x)>>16)
+#define PIXG(x) (((x)>>8)&0xFF)
+#define PIXB(x) ((x)&0xFF)
+#endif
+#endif
+#endif
+
+#ifdef PIX16
+typedef unsigned short pixel;
+#else
+typedef unsigned int pixel;
+#endif
+
+/*extern int emp_decor;
+
+extern unsigned int *render_modes;
+extern unsigned int render_mode;
+extern unsigned int colour_mode;
+extern unsigned int *display_modes;
+extern unsigned int display_mode;
+
+extern SDL_Surface *sdl_scrn;
+extern int sdl_scale;
+
+extern int sandcolour_r;
+extern int sandcolour_g;
+extern int sandcolour_b;
+extern int sandcolour_frame;
+
+extern unsigned char fire_r[YRES/CELL][XRES/CELL];
+extern unsigned char fire_g[YRES/CELL][XRES/CELL];
+extern unsigned char fire_b[YRES/CELL][XRES/CELL];
+
+extern unsigned int fire_alpha[CELL*3][CELL*3];
+extern pixel *pers_bg;
+
+extern char * flm_data;
+extern int flm_data_points;
+extern pixel flm_data_colours[];
+extern float flm_data_pos[];
+
+extern char * plasma_data;
+extern int plasma_data_points;
+extern pixel plasma_data_colours[];
+extern float plasma_data_pos[];*/
+
+class Graphics
+{
+public:
+ SDL_Surface * sdl_scrn;
+ pixel *vid;
+ pixel *render_packed_rgb(void *image, int width, int height, int cmp_size);
+ static char * generate_gradient(pixel * colours, float * points, int pointcount, int size);
+ void draw_other();
+ void draw_rgba_image(unsigned char *data, int x, int y, float a);
+ static void *ptif_pack(pixel *src, int w, int h, int *result_size);
+ static pixel *ptif_unpack(void *datain, int size, int *w, int *h);
+ static pixel *resample_img_nn(pixel *src, int sw, int sh, int rw, int rh);
+ static pixel *resample_img(pixel *src, int sw, int sh, int rw, int rh);
+ static pixel *rescale_img(pixel *src, int sw, int sh, int *qw, int *qh, int f);
+ //void render_gravlensing(pixel *src, pixel * dst);
+ //void sdl_blit_1(int x, int y, int w, int h, pixel *src, int pitch);
+ //void sdl_blit_2(int x, int y, int w, int h, pixel *src, int pitch);
+ //void sdl_blit(int x, int y, int w, int h, pixel *src, int pitch);
+ void drawblob(int x, int y, unsigned char cr, unsigned char cg, unsigned char cb);
+ void draw_tool(int b, int sl, int sr, unsigned pc, unsigned iswall);
+ //int draw_tool_xy(pixel *vid_buf, int x, int y, int b, unsigned pc);
+ //void draw_menu(pixel *vid_buf, int i, int hover);
+ void drawpixel(int x, int y, int r, int g, int b, int a);
+ int addchar(int x, int y, int c, int r, int g, int b, int a);
+ int drawchar(int x, int y, int c, int r, int g, int b, int a);
+ int drawtext(int x, int y, std::string &s, int r, int g, int b, int a);
+ int drawtext(int x, int y, const char *s, int r, int g, int b, int a);
+ int drawtext_outline(int x, int y, const char *s, int r, int g, int b, int a, int olr, int olg, int olb, int ola);
+ int drawtextwrap(int x, int y, int w, const char *s, int r, int g, int b, int a);
+ void drawrect(int x, int y, int w, int h, int r, int g, int b, int a);
+ void fillrect(int x, int y, int w, int h, int r, int g, int b, int a);
+ void clearrect(int x, int y, int w, int h);
+ void drawdots(int x, int y, int h, int r, int g, int b, int a);
+ static int textwidth(char *s);
+ int drawtextmax(int x, int y, int w, char *s, int r, int g, int b, int a);
+ static int textnwidth(char *s, int n);
+ static void textnpos(char *s, int n, int w, int *cx, int *cy);
+ static int textwidthx(char *s, int w);
+ static int textposxy(char *s, int width, int w, int h);
+ static int textwrapheight(char *s, int width);
+ void blendpixel(int x, int y, int r, int g, int b, int a);
+ void draw_icon(int x, int y, char ch, int flag);
+ //void draw_air();
+ //void draw_grav_zones(pixel *vid);
+ //void draw_grav(pixel *vid);
+ void draw_line(int x1, int y1, int x2, int y2, int r, int g, int b, int a);
+ void addpixel(int x, int y, int r, int g, int b, int a);
+ void xor_pixel(int x, int y);
+ void xor_line(int x1, int y1, int x2, int y2);
+ void xor_rect(int x, int y, int w, int h);
+ void blend_line(int x1, int y1, int x2, int y2, int r, int g, int b, int a);
+ //void render_parts(pixel *vid);
+// #ifdef OGLR
+// void draw_parts_fbo();
+// #endif
+// void draw_parts();
+// void draw_walls(pixel *vid);
+// void create_decorations(int x, int y, int rx, int ry, int r, int g, int b, int click, int tool);
+// void create_decoration(int x, int y, int r, int g, int b, int click, int tool);
+// void line_decorations(int x1, int y1, int x2, int y2, int rx, int ry, int r, int g, int b, int click, int tool);
+// void box_decorations(int x1, int y1, int x2, int y2, int r, int g, int b, int click, int tool);
+// void draw_color_menu(pixel *vid_buf, int i, int hover);
+ void draw_wavelengths(int x, int y, int h, int wl);
+ void render_signs();
+// void render_fire(pixel *dst);
+// void prepare_alpha(int size, float intensity);
+ void draw_image(pixel *img, int x, int y, int w, int h, int a);
+ static void dim_copy(pixel *dst, pixel *src);
+ static void dim_copy_pers(pixel *dst, pixel *src);
+ //void render_zoom(pixel *img);
+ //int render_thumb(void *thumb, int size, int bzip2, pixel *vid_buf, int px, int py, int scl);
+ //void render_cursor(pixel *vid, int x, int y, int t, int rx, int ry);
+ //int sdl_open(void);
+ //int draw_debug_info(pixel* vid, int lm, int lx, int ly, int cx, int cy, int line_x, int line_y);
+ void Clear();
+ void Blit();
+ void AttachSDLSurface(SDL_Surface * surface);
+ #ifdef OGLR
+ void clearScreen(float alpha);
+ void ogl_blit(int x, int y, int w, int h, pixel *src, int pitch, int scale);
+ #endif
+ Graphics();
+};
+
+#endif
diff --git a/includes/Gravity.h b/includes/Gravity.h
new file mode 100644
index 0000000..9f36240
--- /dev/null
+++ b/includes/Gravity.h
@@ -0,0 +1,108 @@
+#ifndef GRAVITY_H
+#define GRAVITY_H
+
+#include <pthread.h>
+#include "Config.h"
+#include "Simulation.h"
+
+class Simulation;
+
+struct mask_el {
+ char *shape;
+ char shapeout;
+ void *next;
+};
+typedef struct mask_el mask_el;
+
+
+/*
+ * float *gravmap = NULL;//Maps to be used by the main thread
+ float *gravp = NULL;
+ float *gravy = NULL;
+ float *gravx = NULL;
+ unsigned *gravmask = NULL;
+
+ float *th_ogravmap = NULL;// Maps to be processed by the gravity thread
+ float *th_gravmap = NULL;
+ float *th_gravx = NULL;
+ float *th_gravy = NULL;
+ float *th_gravp = NULL;
+
+ int th_gravchanged = 0;
+
+ pthread_t gravthread;
+ pthread_mutex_t gravmutex;
+ pthread_cond_t gravcv;
+ int grav_ready = 0;
+ int gravthread_done = 0;
+ */
+class Gravity
+{
+private:
+ unsigned *gravmask;
+
+ float *th_ogravmap;
+ float *th_gravmap;
+ float *th_gravx;
+ float *th_gravy;
+ float *th_gravp;
+
+ int th_gravchanged;
+
+ pthread_t gravthread;
+ pthread_mutex_t gravmutex;
+ pthread_cond_t gravcv;
+ int grav_ready;
+ int gravthread_done;
+
+ //Simulation * sim;
+public:
+ float *gravmap;
+ float *gravp;
+ float *gravy;
+ float *gravx;
+ unsigned char (*bmap)[XRES/CELL];
+ int ngrav_enable;
+ void grav_mask_r(int x, int y, char checkmap[YRES/CELL][XRES/CELL], char shape[YRES/CELL][XRES/CELL], char *shapeout);
+ void mask_free(mask_el *c_mask_el);
+
+ void gravity_init();
+ void gravity_cleanup();
+ void gravity_update_async();
+
+ static void *update_grav_async_helper(void * context);
+ void update_grav_async();
+
+ void start_grav_async();
+ void stop_grav_async();
+ void update_grav();
+ void gravity_mask();
+
+ void bilinear_interpolation(float *src, float *dst, int sw, int sh, int rw, int rh);
+
+ #ifdef GRAVFFT
+ void grav_fft_init();
+ void grav_fft_cleanup();
+ #endif
+
+ Gravity();
+};
+
+/*extern int ngrav_enable; //Newtonian gravity
+extern int gravwl_timeout;
+extern int gravityMode;*/
+
+/*float *gravmap;//Maps to be used by the main thread
+float *gravp;
+float *gravy;
+float *gravx;
+unsigned *gravmask;
+
+float *th_ogravmap;// Maps to be processed by the gravity thread
+float *th_gravmap;
+float *th_gravx;
+float *th_gravy;
+float *th_gravp;*/
+
+
+#endif
diff --git a/includes/Misc.h b/includes/Misc.h
new file mode 100644
index 0000000..c5a61ef
--- /dev/null
+++ b/includes/Misc.h
@@ -0,0 +1,108 @@
+#ifndef UTILS_H
+#define UTILS_H
+#include <stdio.h>
+#include <stdlib.h>
+
+#if defined(WIN32) && !defined(__GNUC__)
+#define x86_cpuid(func,af,bf,cf,df) \
+ do {\
+ __asm mov eax, func\
+ __asm cpuid\
+ __asm mov af, eax\
+ __asm mov bf, ebx\
+ __asm mov cf, ecx\
+ __asm mov df, edx\
+ } while(0)
+#else
+#define x86_cpuid(func,af,bf,cf,df) \
+__asm__ __volatile ("cpuid":\
+ "=a" (af), "=b" (bf), "=c" (cf), "=d" (df) : "a" (func));
+#endif
+
+static char hex[] = "0123456789ABCDEF";
+
+char *exe_name(void);
+
+//Signum function
+int isign(float i);
+
+unsigned clamp_flt(float f, float min, float max);
+
+float restrict_flt(float f, float min, float max);
+
+char *mystrdup(char *s);
+
+struct strlist
+{
+ char *str;
+ struct strlist *next;
+};
+
+void strlist_add(struct strlist **list, char *str);
+
+int strlist_find(struct strlist **list, char *str);
+
+void strlist_free(struct strlist **list);
+
+void save_presets(int do_update);
+
+void clean_text(char *text, int vwidth);
+
+void load_presets(void);
+
+void save_string(FILE *f, char *str);
+
+int sregexp(const char *str, char *pattern);
+
+int load_string(FILE *f, char *str, int max);
+
+void strcaturl(char *dst, char *src);
+
+void strappend(char *dst, char *src);
+
+void *file_load(char *fn, int *size);
+
+void clipboard_push_text(char * text);
+
+char * clipboard_pull_text();
+
+extern char *clipboard_text;
+
+int register_extension();
+
+int cpu_check(void);
+
+void HSV_to_RGB(int h,int s,int v,int *r,int *g,int *b);
+
+void RGB_to_HSV(int r,int g,int b,int *h,int *s,int *v);
+
+void membwand(void * dest, void * src, size_t destsize, size_t srcsize);
+// a b
+// c d
+
+struct matrix2d {
+ float a,b,c,d;
+};
+typedef struct matrix2d matrix2d;
+
+// column vector
+struct vector2d {
+ float x,y;
+};
+typedef struct vector2d vector2d;
+
+matrix2d m2d_multiply_m2d(matrix2d m1, matrix2d m2);
+vector2d m2d_multiply_v2d(matrix2d m, vector2d v);
+matrix2d m2d_multiply_float(matrix2d m, float s);
+vector2d v2d_multiply_float(vector2d v, float s);
+
+vector2d v2d_add(vector2d v1, vector2d v2);
+vector2d v2d_sub(vector2d v1, vector2d v2);
+
+matrix2d m2d_new(float me0, float me1, float me2, float me3);
+vector2d v2d_new(float x, float y);
+
+extern vector2d v2d_zero;
+extern matrix2d m2d_identity;
+
+#endif
diff --git a/includes/Renderer.h b/includes/Renderer.h
new file mode 100644
index 0000000..39c8c1a
--- /dev/null
+++ b/includes/Renderer.h
@@ -0,0 +1,60 @@
+#ifndef RENDERER_H
+#define RENDERER_H
+
+#include "Config.h"
+#include "Simulation.h"
+#include "Graphics.h"
+
+class Simulation;
+
+class Graphics;
+
+struct gcache_item
+{
+ int isready;
+ int pixel_mode;
+ int cola, colr, colg, colb;
+ int firea, firer, fireg, fireb;
+};
+typedef struct gcache_item gcache_item;
+
+class Renderer
+{
+public:
+ //TODO: Vectors!
+ unsigned int *render_modes;
+ unsigned int render_mode;
+ unsigned int colour_mode;
+ unsigned int *display_modes;
+ unsigned int display_mode;
+ //
+ unsigned char fire_r[YRES/CELL][XRES/CELL];
+ unsigned char fire_g[YRES/CELL][XRES/CELL];
+ unsigned char fire_b[YRES/CELL][XRES/CELL];
+ unsigned int fire_alpha[CELL*3][CELL*3];
+ char * flm_data;
+ char * plasma_data;
+ int emp_decor;
+ //
+ int decorations_enable;
+ Simulation * sim;
+ Graphics * g;
+ gcache_item *graphicscache;
+ //
+ void draw_walls();
+ void render_signs();
+ void render_gravlensing();
+ void render_fire();
+ void prepare_alpha(int size, float intensity);
+ void render_parts();
+ void draw_grav_zones();
+ void draw_air();
+ void draw_grav();
+ void draw_other();
+ void init_display_modes();
+ void get_sign_pos(int i, int *x0, int *y0, int *w, int *h);
+ void prepare_graphicscache();
+ Renderer(Graphics * g, Simulation * sim);
+};
+
+#endif
diff --git a/includes/Simulation.h b/includes/Simulation.h
new file mode 100644
index 0000000..b3c51af
--- /dev/null
+++ b/includes/Simulation.h
@@ -0,0 +1,241 @@
+/*
+ * Simulation.h
+ *
+ * Created on: Jan 2, 2012
+ * Author: Simon
+ */
+
+#ifndef SIMULATION_H_
+#define SIMULATION_H_
+#include <cstring>
+#include "Config.h"
+#include "Renderer.h"
+#include "Graphics.h"
+#include "Elements.h"
+#include "misc.h"
+
+#define CHANNELS ((int)(MAX_TEMP-73)/100+2)
+
+class Simulation;
+class Renderer;
+class Gravity;
+class Air;
+
+struct Particle
+{
+ int type;
+ int life, ctype;
+ float x, y, vx, vy;
+ float temp;
+ float pavg[2];
+ int flags;
+ int tmp;
+ int tmp2;
+ unsigned int dcolour;
+};
+typedef struct Particle Particle;
+
+struct sign
+{
+ int x,y,ju;
+ char text[256];
+};
+typedef struct sign sign;
+
+struct part_type
+{
+ char *name;
+ pixel pcolors;
+ float advection;
+ float airdrag;
+ float airloss;
+ float loss;
+ float collision;
+ float gravity;
+ float diffusion;
+ float hotair;
+ int falldown;
+ int flammable;
+ int explosive;
+ int meltable;
+ int hardness;
+ int menu;
+ int enabled;
+ int weight;
+ int menusection;
+ float heat;
+ unsigned char hconduct;
+ char *descs;
+ char state;
+ unsigned int properties;
+ int (*update_func) (UPDATE_FUNC_ARGS);
+ int (*graphics_func) (GRAPHICS_FUNC_ARGS);
+};
+typedef struct part_type part_type;
+
+struct part_transition
+{
+ float plv; // transition occurs if pv is lower than this
+ int plt;
+ float phv; // transition occurs if pv is higher than this
+ int pht;
+ float tlv; // transition occurs if t is lower than this
+ int tlt;
+ float thv; // transition occurs if t is higher than this
+ int tht;
+};
+typedef struct part_transition part_transition;
+
+struct playerst
+{
+ char comm; //command cell
+ char pcomm; //previous command
+ int elem; //element power
+ float legs[16]; //legs' positions
+ float accs[8]; //accelerations
+ char spwn; //if stick man was spawned
+ unsigned int frames; //frames since last particle spawn - used when spawning LIGH
+};
+typedef struct playerst playerst;
+
+struct wall_type
+{
+ pixel colour;
+ pixel eglow; // if emap set, add this to fire glow
+ int drawstyle;
+ const char *descs;
+};
+typedef struct wall_type wall_type;
+
+struct gol_menu
+{
+ const char *name;
+ pixel colour;
+ int goltype;
+ const char *description;
+};
+typedef struct gol_menu gol_menu;
+
+//#ifdef _cplusplus
+class Simulation
+{
+private:
+public:
+
+ Gravity * grav;
+ Air * air;
+ part_type ptypes[PT_NUM];
+ part_transition ptransitions[PT_NUM];
+ wall_type wtypes[UI_WALLCOUNT];
+ gol_menu gmenu[NGOL];
+ int goltype[NGOL];
+ int grule[NGOL+1][10];
+ playerst player;
+ playerst player2;
+ playerst fighters[256]; //255 is the maximum number of fighters
+ unsigned char fighcount; //Contains the number of fighters
+ int lighting_recreate;
+ int gravwl_timeout;
+ Particle portalp[CHANNELS][8][80];
+ Particle emptyparticle;
+ int portal_rx[8];
+ int portal_ry[8];
+ int wireless[CHANNELS][2];
+ char can_move[PT_NUM][PT_NUM];
+ int parts_lastActiveIndex;// = NPART-1;
+ int pfree;
+ int NUM_PARTS;
+ int elementCount[PT_NUM];
+ int ISWIRE;
+ sign * signs;
+ //Gol sim
+ int CGOL;
+ int ISGOL;
+ int GSPEED;
+ unsigned char gol[XRES][YRES];
+ unsigned char gol2[XRES][YRES][NGOL+1];
+ //Air sim
+ float (*vx)[XRES/CELL];
+ float (*vy)[XRES/CELL];
+ float (*pv)[XRES/CELL];
+ float (*hv)[XRES/CELL];
+ //Gravity sim
+ float *gravx;//gravx[(YRES/CELL) * (XRES/CELL)];
+ float *gravy;//gravy[(YRES/CELL) * (XRES/CELL)];
+ float *gravp;//gravp[(YRES/CELL) * (XRES/CELL)];
+ float *gravmap;//gravmap[(YRES/CELL) * (XRES/CELL)];
+ //Walls
+ unsigned char bmap[YRES/CELL][XRES/CELL];
+ unsigned char emap[YRES/CELL][XRES/CELL];
+ float fvx[YRES/CELL][XRES/CELL];
+ float fvy[YRES/CELL][XRES/CELL];
+ //Particles
+ Particle parts[NPART];
+ int pmap[YRES][XRES];
+ int photons[YRES][XRES];
+ //
+ int gravityMode;
+ int airMode;
+ int ngrav_enable;
+ int legacy_enable;
+ int aheat_enable;
+ int VINE_MODE;
+ int water_equal_test;
+ int sys_pause;
+ int framerender;
+ int pretty_powder;
+ //
+ int sandcolour_r;
+ int sandcolour_g;
+ int sandcolour_b; //TODO: Make a single variable
+ //Stuff
+ int is_blocking(int t, int x, int y);
+ int is_boundary(int pt, int x, int y);
+ int find_next_boundary(int pt, int *x, int *y, int dm, int *em);
+ int pn_junction_sprk(int x, int y, int pt);
+ void photoelectric_effect(int nx, int ny);
+ unsigned direction_to_map(float dx, float dy, int t);
+ int do_move(int i, int x, int y, float nxf, float nyf);
+ int try_move(int i, int x, int y, int nx, int ny);
+ int eval_move(int pt, int nx, int ny, unsigned *rr);
+ void init_can_move();
+ void create_cherenkov_photon(int pp);
+ void create_gain_photon(int pp);
+ void kill_part(int i);
+ int flood_prop(int x, int y, size_t propoffset, void * propvalue, int proptype);
+ int flood_prop_2(int x, int y, size_t propoffset, void * propvalue, int proptype, int parttype, char * bitmap);
+ int flood_water(int x, int y, int i, int originaly, int check);
+ void detach(int i);
+ void part_change_type(int i, int x, int y, int t);
+ int create_part_add_props(int p, int x, int y, int tv, int rx, int ry);
+ //int InCurrentBrush(int i, int j, int rx, int ry);
+ //int get_brush_flags();
+ int create_part(int p, int x, int y, int t);
+ void delete_part(int x, int y, int flags);
+ int is_wire(int x, int y);
+ int is_wire_off(int x, int y);
+ void set_emap(int x, int y);
+ int parts_avg(int ci, int ni, int t);
+ void create_arc(int sx, int sy, int dx, int dy, int midpoints, int variance, int type, int flags);
+ int nearest_part(int ci, int t, int max_d);
+ void update_particles_i(int start, int inc);
+ void update_particles();
+ void rotate_area(int area_x, int area_y, int area_w, int area_h, int invert);
+ void clear_area(int area_x, int area_y, int area_w, int area_h);
+ void create_box(int x1, int y1, int x2, int y2, int c, int flags);
+ int flood_parts(int x, int y, int c, int cm, int bm, int flags);
+ int create_parts(int x, int y, int rx, int ry, int c, int flags);
+ void create_line(int x1, int y1, int x2, int y2, int rx, int ry, int c, int flags);
+ void *transform_save(void *odata, int *size, matrix2d transform, vector2d translate);
+ void orbitalparts_get(int block1, int block2, int resblock1[], int resblock2[]);
+ void orbitalparts_set(int *block1, int *block2, int resblock1[], int resblock2[]);
+ int get_wavelength_bin(int *wm);
+ int get_normal(int pt, int x, int y, float dx, float dy, float *nx, float *ny);
+ int get_normal_interp(int pt, float x0, float y0, float dx, float dy, float *nx, float *ny);
+ void clear_sim();
+ void UpdateParticles();
+ Simulation();
+};
+//#endif
+
+#endif /* SIMULATION_H_ */
diff --git a/includes/interface/Button.h b/includes/interface/Button.h
new file mode 100644
index 0000000..1b2900e
--- /dev/null
+++ b/includes/interface/Button.h
@@ -0,0 +1,42 @@
+/*
+ * Button.h
+ *
+ * Created on: Jan 8, 2012
+ * Author: Simon
+ */
+
+#ifndef BUTTON_H_
+#define BUTTON_H_
+
+#include <string>
+
+#include "Component.h"
+
+namespace ui
+{
+ class Button : public Component
+ {
+ public:
+ Button(int x, int y, int width, int height, const std::string& buttonText);
+
+ bool Toggleable;
+
+ std::string ButtonText;
+
+ virtual void OnMouseClick(int x, int y, unsigned int button);
+ virtual void OnMouseUnclick(int x, int y, unsigned int button);
+ virtual void OnMouseUp(int x, int y, unsigned int button);
+
+ virtual void OnMouseEnter(int x, int y, int dx, int dy);
+ virtual void OnMouseLeave(int x, int y, int dx, int dy);
+
+ virtual void Draw(void* userdata);
+
+ inline bool GetState() { return state; }
+ virtual void DoAction(); //action of button what ever it may be
+
+ protected:
+ bool isButtonDown, state, isMouseInside;
+ };
+}
+#endif /* BUTTON_H_ */
diff --git a/includes/interface/Component.h b/includes/interface/Component.h
new file mode 100644
index 0000000..a4d02db
--- /dev/null
+++ b/includes/interface/Component.h
@@ -0,0 +1,53 @@
+/*
+ * Component.h
+ *
+ * Created on: Jan 8, 2012
+ * Author: Simon
+ */
+
+#ifndef COMPONENT_H_
+#define COMPONENT_H_
+
+namespace ui
+{
+ class State;
+
+ class Component
+ {
+ public:
+ Component(int x, int y, int width, int height);
+ virtual ~Component();
+
+ inline void LocalizePoint(int& x, int& y) { x -= X; y -= Y; } //convert a global point (point on the state) to a point based on component's position
+ inline void GlobalizePoint(int& x, int& y) { x += X; y += Y; } //convert a local point based on component's position to a global point on the state
+
+ bool Focused;
+ bool Visible;
+ bool Enabled;
+ int Width;
+ int Height;
+ int X;
+ int Y;
+
+ virtual void Tick(float dt);
+ virtual void Draw(void* userdata);
+
+ virtual void OnMouseEnter(int localx, int localy, int dx, int dy);
+ virtual void OnMouseLeave(int localx, int localy, int dx, int dy);
+ virtual void OnMouseMoved(int localx, int localy, int dx, int dy);
+ virtual void OnMouseMovedInside(int localx, int localy, int dx, int dy);
+ virtual void OnMouseHover(int localx, int localy);
+ virtual void OnMouseDown(int localx, int localy, unsigned int button);
+ virtual void OnMouseUp(int localx, int localy, unsigned int button);
+ virtual void OnMouseClick(int localx, int localy, unsigned int button);
+ virtual void OnMouseUnclick(int localx, int localy, unsigned int button);
+ virtual void OnMouseWheel(int localx, int localy, int d);
+ virtual void OnMouseWheelInside(int localx, int localy, int d);
+ virtual void OnMouseWheelFocused(int localx, int localy, int d);
+ virtual void OnKeyPress(int key, bool shift, bool ctrl, bool alt);
+ virtual void OnKeyRelease(int key, bool shift, bool ctrl, bool alt);
+
+ State* Parent;
+ };
+}
+#endif /* COMPONENT_H_ */
diff --git a/includes/interface/Panel.h b/includes/interface/Panel.h
new file mode 100644
index 0000000..9549ff4
--- /dev/null
+++ b/includes/interface/Panel.h
@@ -0,0 +1,22 @@
+/*
+ * Panel.h
+ *
+ * Created on: Jan 8, 2012
+ * Author: Simon
+ */
+
+#ifndef PANEL_H_
+#define PANEL_H_
+
+#include "interface/Component.h"
+
+namespace ui {
+
+class Panel: public ui::Component {
+public:
+ Panel(int x, int y, int width, int height);
+ virtual ~Panel();
+};
+
+} /* namespace ui */
+#endif /* PANEL_H_ */
diff --git a/includes/interface/Sandbox.h b/includes/interface/Sandbox.h
new file mode 100644
index 0000000..10d588f
--- /dev/null
+++ b/includes/interface/Sandbox.h
@@ -0,0 +1,33 @@
+/*
+ * Sandbox.h
+ *
+ * Created on: Jan 8, 2012
+ * Author: Simon
+ */
+
+#ifndef SANDBOX_H_
+#define SANDBOX_H_
+
+#include "Component.h"
+#include "Simulation.h"
+#include "Renderer.h"
+
+namespace ui {
+
+class Sandbox: public ui::Component {
+private:
+ bool isMouseDown;
+ Renderer * ren;
+ Simulation * sim;
+public:
+ Sandbox();
+ virtual void OnMouseMovedInside(int localx, int localy, int dx, int dy);
+ virtual void OnMouseDown(int localx, int localy, unsigned int button);
+ virtual void OnMouseUp(int localx, int localy, unsigned int button);
+ virtual void Draw(void* userdata);
+ virtual void Tick(float delta);
+ virtual ~Sandbox();
+};
+
+} /* namespace ui */
+#endif /* SANDBOX_H_ */
diff --git a/includes/interface/State.h b/includes/interface/State.h
new file mode 100644
index 0000000..00df199
--- /dev/null
+++ b/includes/interface/State.h
@@ -0,0 +1,61 @@
+/*
+ * State.h
+ *
+ * Created on: Jan 8, 2012
+ * Author: Simon
+ */
+
+#ifndef STATE_H_
+#define STATE_H_
+
+#include <vector>
+
+#include "interface/Component.h"
+
+namespace ui {
+
+class State
+{
+public:
+ State(int w, int h);
+ virtual ~State();
+
+ bool AllowExclusiveDrawing; //false will not call draw on objects outside of bounds
+
+ virtual void Tick(float dt);
+ virtual void Draw(void* userdata);
+
+ virtual void OnMouseMove(int x, int y);
+ virtual void OnMouseDown(int x, int y, unsigned int button);
+ virtual void OnMouseUp(int x, int y, unsigned int button);
+ virtual void OnMouseWheel(int x, int y, int d);
+ virtual void OnKeyPress(int key, bool shift, bool ctrl, bool alt);
+ virtual void OnKeyRelease(int key, bool shift, bool ctrl, bool alt);
+
+ virtual void Add(Component *child);
+ virtual void Remove(Component *child);
+
+ inline bool IsFocused(Component* c) { return (c == focusedComponent_); }
+ inline int GetMouseX() { return mouseX; }
+ inline int GetMouseY() { return mouseY; }
+ inline int GetWidth() { return width; }
+ inline int GetHeight() { return height; }
+
+protected:
+ std::vector<Component*> Components;
+
+ int width;
+ int height;
+
+ int mouseX;
+ int mouseY;
+ int mouseXP;
+ int mouseYP;
+
+private:
+ Component* focusedComponent_;
+
+};
+
+} /* namespace ui */
+#endif /* STATE_H_ */
diff --git a/includes/interface/Window.h b/includes/interface/Window.h
new file mode 100644
index 0000000..86a4bcd
--- /dev/null
+++ b/includes/interface/Window.h
@@ -0,0 +1,22 @@
+/*
+ * Window.h
+ *
+ * Created on: Jan 8, 2012
+ * Author: Simon
+ */
+
+#ifndef WINDOW_H_
+#define WINDOW_H_
+
+#include "interface/State.h"
+
+namespace ui {
+
+class Window: public ui::State {
+public:
+ Window();
+ virtual ~Window();
+};
+
+} /* namespace ui */
+#endif /* WINDOW_H_ */