Preprocessor purge round 9: XCELLS and YCELLS
This commit is contained in:
parent
1efafb8d30
commit
27ddf78e0c
@ -76,9 +76,14 @@ constexpr int BARSIZE = 0;
|
||||
constexpr int MENUSIZE = 40;
|
||||
constexpr int BARSIZE = 17;
|
||||
#endif
|
||||
constexpr int XRES = 612;
|
||||
constexpr int YRES = 384;
|
||||
constexpr int NPART = XRES * YRES;
|
||||
//CELL, the size of the pressure, gravity, and wall maps. Larger than 1 to prevent extreme lag
|
||||
constexpr int CELL = 4;
|
||||
constexpr int XCELLS = 153;
|
||||
constexpr int YCELLS = 96;
|
||||
constexpr int NCELL = XCELLS * YCELLS;
|
||||
constexpr int XRES = XCELLS * CELL;
|
||||
constexpr int YRES = YCELLS * CELL;
|
||||
constexpr int NPART = XRES * YRES;
|
||||
|
||||
constexpr int XCNTR = XRES / 2;
|
||||
constexpr int YCNTR = YRES / 2;
|
||||
@ -88,8 +93,6 @@ constexpr int WINDOWH = YRES + MENUSIZE;
|
||||
|
||||
constexpr int MAXSIGNS = 16;
|
||||
|
||||
//CELL, the size of the pressure, gravity, and wall maps. Larger than 1 to prevent extreme lag
|
||||
constexpr int CELL = 4;
|
||||
constexpr int ISTP = CELL / 2;
|
||||
constexpr float CFDS = 4.0f / CELL;
|
||||
constexpr float SIM_MAXVELOCITY = 1e4f;
|
||||
|
@ -451,7 +451,7 @@ void GameSave::readOPS(const std::vector<char> &data)
|
||||
throw ParseException(ParseException::InvalidDimensions, "Save too small");
|
||||
|
||||
//Too large/off screen
|
||||
if (blockX+blockW > XRES/CELL || blockY+blockH > YRES/CELL)
|
||||
if (blockX+blockW > XCELLS || blockY+blockH > YCELLS)
|
||||
throw ParseException(ParseException::InvalidDimensions, "Save too large");
|
||||
|
||||
setSize(blockW, blockH);
|
||||
@ -1300,16 +1300,16 @@ void GameSave::readPSv(const std::vector<char> &dataVec)
|
||||
|
||||
bw = saveData[6];
|
||||
bh = saveData[7];
|
||||
if (bx0+bw > XRES/CELL)
|
||||
bx0 = XRES/CELL - bw;
|
||||
if (by0+bh > YRES/CELL)
|
||||
by0 = YRES/CELL - bh;
|
||||
if (bx0+bw > XCELLS)
|
||||
bx0 = XCELLS - bw;
|
||||
if (by0+bh > YCELLS)
|
||||
by0 = YCELLS - bh;
|
||||
if (bx0 < 0)
|
||||
bx0 = 0;
|
||||
if (by0 < 0)
|
||||
by0 = 0;
|
||||
|
||||
if (saveData[5]!=CELL || bx0+bw>XRES/CELL || by0+bh>YRES/CELL)
|
||||
if (saveData[5]!=CELL || bx0+bw>XCELLS || by0+bh>YCELLS)
|
||||
throw ParseException(ParseException::InvalidDimensions, "Save too large");
|
||||
int size = (unsigned)saveData[8];
|
||||
size |= ((unsigned)saveData[9])<<8;
|
||||
|
@ -315,8 +315,8 @@ void Renderer::DrawBlob(int x, int y, unsigned char cr, unsigned char cg, unsign
|
||||
|
||||
void Renderer::DrawWalls()
|
||||
{
|
||||
for (int y = 0; y < YRES/CELL; y++)
|
||||
for (int x =0; x < XRES/CELL; x++)
|
||||
for (int y = 0; y < YCELLS; y++)
|
||||
for (int x =0; x < XCELLS; x++)
|
||||
if (sim->bmap[y][x])
|
||||
{
|
||||
unsigned char wt = sim->bmap[y][x];
|
||||
@ -604,7 +604,7 @@ void Renderer::render_gravlensing(pixel * source)
|
||||
{
|
||||
for(ny = 0; ny < YRES; ny++)
|
||||
{
|
||||
co = (ny/CELL)*(XRES/CELL)+(nx/CELL);
|
||||
co = (ny/CELL)*XCELLS+(nx/CELL);
|
||||
rx = (int)(nx-sim->gravx[co]*0.75f+0.5f);
|
||||
ry = (int)(ny-sim->gravy[co]*0.75f+0.5f);
|
||||
gx = (int)(nx-sim->gravx[co]*0.875f+0.5f);
|
||||
@ -634,8 +634,8 @@ void Renderer::render_fire()
|
||||
if(!(render_mode & FIREMODE))
|
||||
return;
|
||||
int i,j,x,y,r,g,b,a;
|
||||
for (j=0; j<YRES/CELL; j++)
|
||||
for (i=0; i<XRES/CELL; i++)
|
||||
for (j=0; j<YCELLS; j++)
|
||||
for (i=0; i<XCELLS; i++)
|
||||
{
|
||||
r = fire_r[j][i];
|
||||
g = fire_g[j][i];
|
||||
@ -654,7 +654,7 @@ void Renderer::render_fire()
|
||||
b *= 8;
|
||||
for (y=-1; y<2; y++)
|
||||
for (x=-1; x<2; x++)
|
||||
if ((x || y) && i+x>=0 && j+y>=0 && i+x<XRES/CELL && j+y<YRES/CELL)
|
||||
if ((x || y) && i+x>=0 && j+y>=0 && i+x<XCELLS && j+y<YCELLS)
|
||||
{
|
||||
r += fire_r[j+y][i+x];
|
||||
g += fire_g[j+y][i+x];
|
||||
@ -1291,11 +1291,11 @@ void Renderer::draw_grav()
|
||||
if(!gravityFieldEnabled)
|
||||
return;
|
||||
|
||||
for (y=0; y<YRES/CELL; y++)
|
||||
for (y=0; y<YCELLS; y++)
|
||||
{
|
||||
for (x=0; x<XRES/CELL; x++)
|
||||
for (x=0; x<XCELLS; x++)
|
||||
{
|
||||
ca = y*(XRES/CELL)+x;
|
||||
ca = y*XCELLS+x;
|
||||
if(fabsf(sim->gravx[ca]) <= 0.001f && fabsf(sim->gravy[ca]) <= 0.001f)
|
||||
continue;
|
||||
nx = float(x*CELL);
|
||||
@ -1326,13 +1326,13 @@ void Renderer::draw_air()
|
||||
if(!(display_mode & DISPLAY_AIR))
|
||||
return;
|
||||
int x, y, i, j;
|
||||
float (*pv)[XRES/CELL] = sim->air->pv;
|
||||
float (*hv)[XRES/CELL] = sim->air->hv;
|
||||
float (*vx)[XRES/CELL] = sim->air->vx;
|
||||
float (*vy)[XRES/CELL] = sim->air->vy;
|
||||
float (*pv)[XCELLS] = sim->air->pv;
|
||||
float (*hv)[XCELLS] = sim->air->hv;
|
||||
float (*vx)[XCELLS] = sim->air->vx;
|
||||
float (*vy)[XCELLS] = sim->air->vy;
|
||||
pixel c = 0;
|
||||
for (y=0; y<YRES/CELL; y++)
|
||||
for (x=0; x<XRES/CELL; x++)
|
||||
for (y=0; y<YCELLS; y++)
|
||||
for (x=0; x<XCELLS; x++)
|
||||
{
|
||||
if (display_mode & DISPLAY_AIRP)
|
||||
{
|
||||
@ -1400,11 +1400,11 @@ void Renderer::draw_grav_zones()
|
||||
return;
|
||||
|
||||
int x, y, i, j;
|
||||
for (y=0; y<YRES/CELL; y++)
|
||||
for (y=0; y<YCELLS; y++)
|
||||
{
|
||||
for (x=0; x<XRES/CELL; x++)
|
||||
for (x=0; x<XCELLS; x++)
|
||||
{
|
||||
if(sim->grav->gravmask[y*(XRES/CELL)+x])
|
||||
if(sim->grav->gravmask[y*XCELLS+x])
|
||||
{
|
||||
for (j=0; j<CELL; j++)//draws the colors
|
||||
for (i=0; i<CELL; i++)
|
||||
@ -1624,9 +1624,9 @@ void Renderer::CompileRenderMode()
|
||||
|
||||
void Renderer::ClearAccumulation()
|
||||
{
|
||||
std::fill(&fire_r[0][0], &fire_r[0][0] + (YRES/CELL)*(XRES/CELL), 0);
|
||||
std::fill(&fire_g[0][0], &fire_g[0][0] + (YRES/CELL)*(XRES/CELL), 0);
|
||||
std::fill(&fire_b[0][0], &fire_b[0][0] + (YRES/CELL)*(XRES/CELL), 0);
|
||||
std::fill(&fire_r[0][0], &fire_r[0][0] + NCELL, 0);
|
||||
std::fill(&fire_g[0][0], &fire_g[0][0] + NCELL, 0);
|
||||
std::fill(&fire_b[0][0], &fire_b[0][0] + NCELL, 0);
|
||||
std::fill(persistentVid, persistentVid+(VIDXRES*YRES), 0);
|
||||
}
|
||||
|
||||
|
@ -45,9 +45,9 @@ public:
|
||||
unsigned int display_mode;
|
||||
std::vector<RenderPreset> renderModePresets;
|
||||
//
|
||||
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 char fire_r[YCELLS][XCELLS];
|
||||
unsigned char fire_g[YCELLS][XCELLS];
|
||||
unsigned char fire_b[YCELLS][XCELLS];
|
||||
unsigned int fire_alpha[CELL*3][CELL*3];
|
||||
//
|
||||
bool gravityZonesEnabled;
|
||||
|
@ -88,8 +88,8 @@ void WallTool::DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui
|
||||
float newFanVelY = (position2.Y-position1.Y)*0.005f;
|
||||
newFanVelY *= strength;
|
||||
sim->FloodWalls(position1.X, position1.Y, WL_FLOODHELPER, WL_FAN);
|
||||
for (int j = 0; j < YRES/CELL; j++)
|
||||
for (int i = 0; i < XRES/CELL; i++)
|
||||
for (int j = 0; j < YCELLS; j++)
|
||||
for (int i = 0; i < XCELLS; i++)
|
||||
if (sim->bmap[j][i] == WL_FLOODHELPER)
|
||||
{
|
||||
sim->fvx[j][i] = newFanVelX;
|
||||
|
@ -446,22 +446,22 @@ int luatpt_set_pressure(lua_State* l)
|
||||
float value;
|
||||
x1 = abs(luaL_optint(l, 1, 0));
|
||||
y1 = abs(luaL_optint(l, 2, 0));
|
||||
width = abs(luaL_optint(l, 3, XRES/CELL));
|
||||
height = abs(luaL_optint(l, 4, YRES/CELL));
|
||||
width = abs(luaL_optint(l, 3, XCELLS));
|
||||
height = abs(luaL_optint(l, 4, YCELLS));
|
||||
value = luaL_optnumber(l, 5, 0.0f);
|
||||
if(value > MAX_PRESSURE)
|
||||
value = MAX_PRESSURE;
|
||||
else if(value < MIN_PRESSURE)
|
||||
value = MIN_PRESSURE;
|
||||
|
||||
if(x1 > (XRES/CELL)-1)
|
||||
x1 = (XRES/CELL)-1;
|
||||
if(y1 > (YRES/CELL)-1)
|
||||
y1 = (YRES/CELL)-1;
|
||||
if(x1+width > (XRES/CELL)-1)
|
||||
width = (XRES/CELL)-x1;
|
||||
if(y1+height > (YRES/CELL)-1)
|
||||
height = (YRES/CELL)-y1;
|
||||
if(x1 > XCELLS-1)
|
||||
x1 = XCELLS-1;
|
||||
if(y1 > YCELLS-1)
|
||||
y1 = YCELLS-1;
|
||||
if(x1+width > XCELLS-1)
|
||||
width = XCELLS-x1;
|
||||
if(y1+height > YCELLS-1)
|
||||
height = YCELLS-y1;
|
||||
for (nx = x1; nx<x1+width; nx++)
|
||||
for (ny = y1; ny<y1+height; ny++)
|
||||
{
|
||||
@ -477,26 +477,26 @@ int luatpt_set_gravity(lua_State* l)
|
||||
float value;
|
||||
x1 = abs(luaL_optint(l, 1, 0));
|
||||
y1 = abs(luaL_optint(l, 2, 0));
|
||||
width = abs(luaL_optint(l, 3, XRES/CELL));
|
||||
height = abs(luaL_optint(l, 4, YRES/CELL));
|
||||
width = abs(luaL_optint(l, 3, XCELLS));
|
||||
height = abs(luaL_optint(l, 4, YCELLS));
|
||||
value = luaL_optnumber(l, 5, 0.0f);
|
||||
if(value > MAX_PRESSURE)
|
||||
value = MAX_PRESSURE;
|
||||
else if(value < MIN_PRESSURE)
|
||||
value = MIN_PRESSURE;
|
||||
|
||||
if(x1 > (XRES/CELL)-1)
|
||||
x1 = (XRES/CELL)-1;
|
||||
if(y1 > (YRES/CELL)-1)
|
||||
y1 = (YRES/CELL)-1;
|
||||
if(x1+width > (XRES/CELL)-1)
|
||||
width = (XRES/CELL)-x1;
|
||||
if(y1+height > (YRES/CELL)-1)
|
||||
height = (YRES/CELL)-y1;
|
||||
if(x1 > XCELLS-1)
|
||||
x1 = XCELLS-1;
|
||||
if(y1 > YCELLS-1)
|
||||
y1 = YCELLS-1;
|
||||
if(x1+width > XCELLS-1)
|
||||
width = XCELLS-x1;
|
||||
if(y1+height > YCELLS-1)
|
||||
height = YCELLS-y1;
|
||||
for (nx = x1; nx<x1+width; nx++)
|
||||
for (ny = y1; ny<y1+height; ny++)
|
||||
{
|
||||
luacon_sim->gravmap[ny*(XRES/CELL)+nx] = value;
|
||||
luacon_sim->gravmap[ny*XCELLS+nx] = value;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -507,22 +507,22 @@ int luatpt_reset_gravity_field(lua_State* l)
|
||||
int x1, y1, width, height;
|
||||
x1 = abs(luaL_optint(l, 1, 0));
|
||||
y1 = abs(luaL_optint(l, 2, 0));
|
||||
width = abs(luaL_optint(l, 3, XRES/CELL));
|
||||
height = abs(luaL_optint(l, 4, YRES/CELL));
|
||||
if(x1 > (XRES/CELL)-1)
|
||||
x1 = (XRES/CELL)-1;
|
||||
if(y1 > (YRES/CELL)-1)
|
||||
y1 = (YRES/CELL)-1;
|
||||
if(x1+width > (XRES/CELL)-1)
|
||||
width = (XRES/CELL)-x1;
|
||||
if(y1+height > (YRES/CELL)-1)
|
||||
height = (YRES/CELL)-y1;
|
||||
width = abs(luaL_optint(l, 3, XCELLS));
|
||||
height = abs(luaL_optint(l, 4, YCELLS));
|
||||
if(x1 > XCELLS-1)
|
||||
x1 = XCELLS-1;
|
||||
if(y1 > YCELLS-1)
|
||||
y1 = YCELLS-1;
|
||||
if(x1+width > XCELLS-1)
|
||||
width = XCELLS-x1;
|
||||
if(y1+height > YCELLS-1)
|
||||
height = YCELLS-y1;
|
||||
for (nx = x1; nx<x1+width; nx++)
|
||||
for (ny = y1; ny<y1+height; ny++)
|
||||
{
|
||||
luacon_sim->gravx[ny*(XRES/CELL)+nx] = 0;
|
||||
luacon_sim->gravy[ny*(XRES/CELL)+nx] = 0;
|
||||
luacon_sim->gravp[ny*(XRES/CELL)+nx] = 0;
|
||||
luacon_sim->gravx[ny*XCELLS+nx] = 0;
|
||||
luacon_sim->gravy[ny*XCELLS+nx] = 0;
|
||||
luacon_sim->gravp[ny*XCELLS+nx] = 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -533,16 +533,16 @@ int luatpt_reset_velocity(lua_State* l)
|
||||
int x1, y1, width, height;
|
||||
x1 = abs(luaL_optint(l, 1, 0));
|
||||
y1 = abs(luaL_optint(l, 2, 0));
|
||||
width = abs(luaL_optint(l, 3, XRES/CELL));
|
||||
height = abs(luaL_optint(l, 4, YRES/CELL));
|
||||
if(x1 > (XRES/CELL)-1)
|
||||
x1 = (XRES/CELL)-1;
|
||||
if(y1 > (YRES/CELL)-1)
|
||||
y1 = (YRES/CELL)-1;
|
||||
if(x1+width > (XRES/CELL)-1)
|
||||
width = (XRES/CELL)-x1;
|
||||
if(y1+height > (YRES/CELL)-1)
|
||||
height = (YRES/CELL)-y1;
|
||||
width = abs(luaL_optint(l, 3, XCELLS));
|
||||
height = abs(luaL_optint(l, 4, YCELLS));
|
||||
if(x1 > XCELLS-1)
|
||||
x1 = XCELLS-1;
|
||||
if(y1 > YCELLS-1)
|
||||
y1 = YCELLS-1;
|
||||
if(x1+width > XCELLS-1)
|
||||
width = XCELLS-x1;
|
||||
if(y1+height > YCELLS-1)
|
||||
height = YCELLS-y1;
|
||||
for (nx = x1; nx<x1+width; nx++)
|
||||
for (ny = y1; ny<y1+height; ny++)
|
||||
{
|
||||
@ -697,7 +697,7 @@ int luatpt_get_wallmap(lua_State* l)
|
||||
int x1 = abs(luaL_optint(l, 1, 0));
|
||||
int y1 = abs(luaL_optint(l, 2, 0));
|
||||
|
||||
if(x1 > (XRES/CELL) || y1 > (YRES/CELL))
|
||||
if(x1 > XCELLS || y1 > YCELLS)
|
||||
return luaL_error(l, "Out of range");
|
||||
|
||||
lua_pushinteger(l, luacon_sim->bmap[y1][x1]);
|
||||
@ -730,10 +730,10 @@ int luatpt_set_wallmap(lua_State* l)
|
||||
}
|
||||
if (x < 0 ) x = 0 ;
|
||||
if (y < 0 ) y = 0 ;
|
||||
if (x > XRES / CELL ) x = XRES / CELL ;
|
||||
if (y > YRES / CELL ) y = YRES / CELL ;
|
||||
if (w > XRES / CELL - x) w = XRES / CELL - x;
|
||||
if (h > YRES / CELL - y) h = YRES / CELL - y;
|
||||
if (x > XCELLS ) x = XCELLS ;
|
||||
if (y > YCELLS ) y = YCELLS ;
|
||||
if (w > XCELLS - x) w = XCELLS - x;
|
||||
if (h > YCELLS - y) h = YCELLS - y;
|
||||
for (int yy = y; yy < y + h; ++yy)
|
||||
{
|
||||
for (int xx = x; xx < x + w; ++xx)
|
||||
@ -758,20 +758,20 @@ int luatpt_set_elecmap(lua_State* l)
|
||||
|
||||
x1 = abs(luaL_optint(l, 1, 0));
|
||||
y1 = abs(luaL_optint(l, 2, 0));
|
||||
width = abs(luaL_optint(l, 3, XRES/CELL));
|
||||
height = abs(luaL_optint(l, 4, YRES/CELL));
|
||||
width = abs(luaL_optint(l, 3, XCELLS));
|
||||
height = abs(luaL_optint(l, 4, YCELLS));
|
||||
value = luaL_optint(l, acount, 0);
|
||||
|
||||
if(acount==5) //Draw rect
|
||||
{
|
||||
if(x1 > (XRES/CELL))
|
||||
x1 = (XRES/CELL);
|
||||
if(y1 > (YRES/CELL))
|
||||
y1 = (YRES/CELL);
|
||||
if(x1+width > (XRES/CELL))
|
||||
width = (XRES/CELL)-x1;
|
||||
if(y1+height > (YRES/CELL))
|
||||
height = (YRES/CELL)-y1;
|
||||
if(x1 > XCELLS)
|
||||
x1 = XCELLS;
|
||||
if(y1 > YCELLS)
|
||||
y1 = YCELLS;
|
||||
if(x1+width > XCELLS)
|
||||
width = XCELLS-x1;
|
||||
if(y1+height > YCELLS)
|
||||
height = YCELLS-y1;
|
||||
for (nx = x1; nx<x1+width; nx++)
|
||||
for (ny = y1; ny<y1+height; ny++)
|
||||
{
|
||||
@ -780,10 +780,10 @@ int luatpt_set_elecmap(lua_State* l)
|
||||
}
|
||||
else //Set point
|
||||
{
|
||||
if(x1 > (XRES/CELL))
|
||||
x1 = (XRES/CELL);
|
||||
if(y1 > (YRES/CELL))
|
||||
y1 = (YRES/CELL);
|
||||
if(x1 > XCELLS)
|
||||
x1 = XCELLS;
|
||||
if(y1 > YCELLS)
|
||||
y1 = YCELLS;
|
||||
luacon_sim->emap[y1][x1] = value;
|
||||
}
|
||||
return 0;
|
||||
@ -794,7 +794,7 @@ int luatpt_get_elecmap(lua_State* l)
|
||||
int x1 = abs(luaL_optint(l, 1, 0));
|
||||
int y1 = abs(luaL_optint(l, 2, 0));
|
||||
|
||||
if(x1 > (XRES/CELL) || y1 > (YRES/CELL))
|
||||
if(x1 > XCELLS || y1 > YCELLS)
|
||||
return luaL_error(l, "Out of range");
|
||||
|
||||
lua_pushinteger(l, luacon_sim->emap[y1][x1]);
|
||||
|
@ -953,9 +953,13 @@ void LuaScriptInterface::initSimulationAPI()
|
||||
lua_setglobal(l, "sim");
|
||||
|
||||
//Static values
|
||||
SETCONST(l, CELL);
|
||||
SETCONST(l, XCELLS);
|
||||
SETCONST(l, YCELLS);
|
||||
SETCONST(l, NCELL);
|
||||
SETCONST(l, XRES);
|
||||
SETCONST(l, YRES);
|
||||
SETCONST(l, CELL);
|
||||
SETCONST(l, NPART);
|
||||
SETCONST(l, NT);
|
||||
SETCONST(l, ST);
|
||||
SETCONSTF(l, ITH);
|
||||
@ -1034,14 +1038,14 @@ void LuaScriptInterface::initSimulationAPI()
|
||||
void LuaScriptInterface::set_map(int x, int y, int width, int height, float value, int map) // A function so this won't need to be repeated many times later
|
||||
{
|
||||
int nx, ny;
|
||||
if(x > (XRES/CELL)-1)
|
||||
x = (XRES/CELL)-1;
|
||||
if(y > (YRES/CELL)-1)
|
||||
y = (YRES/CELL)-1;
|
||||
if(x+width > (XRES/CELL)-1)
|
||||
width = (XRES/CELL)-x;
|
||||
if(y+height > (YRES/CELL)-1)
|
||||
height = (YRES/CELL)-y;
|
||||
if(x > XCELLS-1)
|
||||
x = XCELLS-1;
|
||||
if(y > YCELLS-1)
|
||||
y = YCELLS-1;
|
||||
if(x+width > XCELLS-1)
|
||||
width = XCELLS-x;
|
||||
if(y+height > YCELLS-1)
|
||||
height = YCELLS-y;
|
||||
for (nx = x; nx<x+width; nx++)
|
||||
for (ny = y; ny<y+height; ny++)
|
||||
{
|
||||
@ -1054,7 +1058,7 @@ void LuaScriptInterface::set_map(int x, int y, int width, int height, float valu
|
||||
else if (map == 4)
|
||||
luacon_sim->vy[ny][nx] = value;
|
||||
else if (map == 5)
|
||||
luacon_sim->gravmap[ny*XRES/CELL+nx] = value; //gravx/y don't seem to work, but this does. opposite of tpt
|
||||
luacon_sim->gravmap[ny*XCELLS+nx] = value; //gravx/y don't seem to work, but this does. opposite of tpt
|
||||
}
|
||||
}
|
||||
|
||||
@ -1283,7 +1287,7 @@ int LuaScriptInterface::simulation_pressure(lua_State* l)
|
||||
luaL_checktype(l, 2, LUA_TNUMBER);
|
||||
int x = lua_tointeger(l, 1);
|
||||
int y = lua_tointeger(l, 2);
|
||||
if (x*CELL<0 || y*CELL<0 || x*CELL>=XRES || y*CELL>=YRES)
|
||||
if (x<0 || y<0 || x>=XCELLS || y>=YCELLS)
|
||||
return luaL_error(l, "coordinates out of range (%d,%d)", x, y);
|
||||
|
||||
if (argCount == 2)
|
||||
@ -1320,7 +1324,7 @@ int LuaScriptInterface::simulation_ambientHeat(lua_State* l)
|
||||
luaL_checktype(l, 2, LUA_TNUMBER);
|
||||
int x = lua_tointeger(l, 1);
|
||||
int y = lua_tointeger(l, 2);
|
||||
if (x*CELL<0 || y*CELL<0 || x*CELL>=XRES || y*CELL>=YRES)
|
||||
if (x<0 || y<0 || x>=XCELLS || y>=YCELLS)
|
||||
return luaL_error(l, "coordinates out of range (%d,%d)", x, y);
|
||||
|
||||
if (argCount == 2)
|
||||
@ -1357,7 +1361,7 @@ int LuaScriptInterface::simulation_velocityX(lua_State* l)
|
||||
luaL_checktype(l, 2, LUA_TNUMBER);
|
||||
int x = lua_tointeger(l, 1);
|
||||
int y = lua_tointeger(l, 2);
|
||||
if (x*CELL<0 || y*CELL<0 || x*CELL>=XRES || y*CELL>=YRES)
|
||||
if (x<0 || y<0 || x>=XCELLS || y>=YCELLS)
|
||||
return luaL_error(l, "coordinates out of range (%d,%d)", x, y);
|
||||
|
||||
if (argCount == 2)
|
||||
@ -1394,7 +1398,7 @@ int LuaScriptInterface::simulation_velocityY(lua_State* l)
|
||||
luaL_checktype(l, 2, LUA_TNUMBER);
|
||||
int x = lua_tointeger(l, 1);
|
||||
int y = lua_tointeger(l, 2);
|
||||
if (x*CELL<0 || y*CELL<0 || x*CELL>=XRES || y*CELL>=YRES)
|
||||
if (x<0 || y<0 || x>=XCELLS || y>=YCELLS)
|
||||
return luaL_error(l, "coordinates out of range (%d,%d)", x, y);
|
||||
|
||||
if (argCount == 2)
|
||||
@ -1431,12 +1435,12 @@ int LuaScriptInterface::simulation_gravMap(lua_State* l)
|
||||
luaL_checktype(l, 2, LUA_TNUMBER);
|
||||
int x = lua_tointeger(l, 1);
|
||||
int y = lua_tointeger(l, 2);
|
||||
if (x*CELL<0 || y*CELL<0 || x*CELL>=XRES || y*CELL>=YRES)
|
||||
if (x<0 || y<0 || x>=XCELLS || y>=YCELLS)
|
||||
return luaL_error(l, "coordinates out of range (%d,%d)", x, y);
|
||||
|
||||
if (argCount == 2)
|
||||
{
|
||||
lua_pushnumber(l, luacon_sim->gravp[y*XRES/CELL+x]);
|
||||
lua_pushnumber(l, luacon_sim->gravp[y*XCELLS+x]);
|
||||
return 1;
|
||||
}
|
||||
int width = 1, height = 1;
|
||||
@ -1850,27 +1854,27 @@ int LuaScriptInterface::simulation_resetTemp(lua_State * l)
|
||||
|
||||
int LuaScriptInterface::simulation_resetPressure(lua_State * l)
|
||||
{
|
||||
int aCount = lua_gettop(l), width = XRES/CELL, height = YRES/CELL;
|
||||
int aCount = lua_gettop(l), width = XCELLS, height = YCELLS;
|
||||
int x1 = abs(luaL_optint(l, 1, 0));
|
||||
int y1 = abs(luaL_optint(l, 2, 0));
|
||||
if (aCount > 2)
|
||||
{
|
||||
width = abs(luaL_optint(l, 3, XRES/CELL));
|
||||
height = abs(luaL_optint(l, 4, YRES/CELL));
|
||||
width = abs(luaL_optint(l, 3, XCELLS));
|
||||
height = abs(luaL_optint(l, 4, YCELLS));
|
||||
}
|
||||
else if (aCount)
|
||||
{
|
||||
width = 1;
|
||||
height = 1;
|
||||
}
|
||||
if(x1 > (XRES/CELL)-1)
|
||||
x1 = (XRES/CELL)-1;
|
||||
if(y1 > (YRES/CELL)-1)
|
||||
y1 = (YRES/CELL)-1;
|
||||
if(x1+width > (XRES/CELL)-1)
|
||||
width = (XRES/CELL)-x1;
|
||||
if(y1+height > (YRES/CELL)-1)
|
||||
height = (YRES/CELL)-y1;
|
||||
if(x1 > XCELLS-1)
|
||||
x1 = XCELLS-1;
|
||||
if(y1 > YCELLS-1)
|
||||
y1 = YCELLS-1;
|
||||
if(x1+width > XCELLS-1)
|
||||
width = XCELLS-x1;
|
||||
if(y1+height > YCELLS-1)
|
||||
height = YCELLS-y1;
|
||||
for (int nx = x1; nx<x1+width; nx++)
|
||||
for (int ny = y1; ny<y1+height; ny++)
|
||||
{
|
||||
|
@ -567,16 +567,16 @@ AnyType TPTScriptInterface::tptS_reset(std::deque<String> * words)
|
||||
|
||||
if (resetStr == "pressure")
|
||||
{
|
||||
for (int nx = 0; nx < XRES/CELL; nx++)
|
||||
for (int ny = 0; ny < YRES/CELL; ny++)
|
||||
for (int nx = 0; nx < XCELLS; nx++)
|
||||
for (int ny = 0; ny < YCELLS; ny++)
|
||||
{
|
||||
sim->air->pv[ny][nx] = 0;
|
||||
}
|
||||
}
|
||||
else if (resetStr == "velocity")
|
||||
{
|
||||
for (int nx = 0; nx < XRES/CELL; nx++)
|
||||
for (int ny = 0; ny < YRES/CELL; ny++)
|
||||
for (int nx = 0; nx < XCELLS; nx++)
|
||||
for (int ny = 0; ny < YCELLS; ny++)
|
||||
{
|
||||
sim->air->vx[ny][nx] = 0;
|
||||
sim->air->vy[ny][nx] = 0;
|
||||
|
@ -9,19 +9,19 @@
|
||||
|
||||
/*float kernel[9];
|
||||
|
||||
float vx[YRES/CELL][XRES/CELL], ovx[YRES/CELL][XRES/CELL];
|
||||
float vy[YRES/CELL][XRES/CELL], ovy[YRES/CELL][XRES/CELL];
|
||||
float pv[YRES/CELL][XRES/CELL], opv[YRES/CELL][XRES/CELL];
|
||||
unsigned char bmap_blockair[YRES/CELL][XRES/CELL];
|
||||
float vx[YCELLS][XCELLS], ovx[YCELLS][XCELLS];
|
||||
float vy[YCELLS][XCELLS], ovy[YCELLS][XCELLS];
|
||||
float pv[YCELLS][XCELLS], opv[YCELLS][XCELLS];
|
||||
unsigned char bmap_blockair[YCELLS][XCELLS];
|
||||
|
||||
float cb_vx[YRES/CELL][XRES/CELL];
|
||||
float cb_vy[YRES/CELL][XRES/CELL];
|
||||
float cb_pv[YRES/CELL][XRES/CELL];
|
||||
float cb_hv[YRES/CELL][XRES/CELL];
|
||||
float cb_vx[YCELLS][XCELLS];
|
||||
float cb_vy[YCELLS][XCELLS];
|
||||
float cb_pv[YCELLS][XCELLS];
|
||||
float cb_hv[YCELLS][XCELLS];
|
||||
|
||||
float fvx[YRES/CELL][XRES/CELL], fvy[YRES/CELL][XRES/CELL];
|
||||
float fvx[YCELLS][XCELLS], fvy[YCELLS][XCELLS];
|
||||
|
||||
float hv[YRES/CELL][XRES/CELL], ohv[YRES/CELL][XRES/CELL]; // For Ambient Heat */
|
||||
float hv[YCELLS][XCELLS], ohv[YCELLS][XCELLS]; // For Ambient Heat */
|
||||
|
||||
void Air::make_kernel(void) //used for velocity
|
||||
{
|
||||
@ -41,39 +41,39 @@ void Air::make_kernel(void) //used for velocity
|
||||
|
||||
void Air::Clear()
|
||||
{
|
||||
std::fill(&pv[0][0], &pv[0][0]+((XRES/CELL)*(YRES/CELL)), 0.0f);
|
||||
std::fill(&vy[0][0], &vy[0][0]+((XRES/CELL)*(YRES/CELL)), 0.0f);
|
||||
std::fill(&vx[0][0], &vx[0][0]+((XRES/CELL)*(YRES/CELL)), 0.0f);
|
||||
std::fill(&pv[0][0], &pv[0][0]+NCELL, 0.0f);
|
||||
std::fill(&vy[0][0], &vy[0][0]+NCELL, 0.0f);
|
||||
std::fill(&vx[0][0], &vx[0][0]+NCELL, 0.0f);
|
||||
}
|
||||
|
||||
void Air::ClearAirH()
|
||||
{
|
||||
std::fill(&hv[0][0], &hv[0][0]+((XRES/CELL)*(YRES/CELL)), ambientAirTemp);
|
||||
std::fill(&hv[0][0], &hv[0][0]+NCELL, ambientAirTemp);
|
||||
}
|
||||
|
||||
void Air::update_airh(void)
|
||||
{
|
||||
int x, y, i, j;
|
||||
float odh, dh, dx, dy, f, tx, ty;
|
||||
for (i=0; i<YRES/CELL; i++) //reduces pressure/velocity on the edges every frame
|
||||
for (i=0; i<YCELLS; i++) //reduces pressure/velocity on the edges every frame
|
||||
{
|
||||
hv[i][0] = ambientAirTemp;
|
||||
hv[i][1] = ambientAirTemp;
|
||||
hv[i][XRES/CELL-3] = ambientAirTemp;
|
||||
hv[i][XRES/CELL-2] = ambientAirTemp;
|
||||
hv[i][XRES/CELL-1] = ambientAirTemp;
|
||||
hv[i][XCELLS-3] = ambientAirTemp;
|
||||
hv[i][XCELLS-2] = ambientAirTemp;
|
||||
hv[i][XCELLS-1] = ambientAirTemp;
|
||||
}
|
||||
for (i=0; i<XRES/CELL; i++) //reduces pressure/velocity on the edges every frame
|
||||
for (i=0; i<XCELLS; i++) //reduces pressure/velocity on the edges every frame
|
||||
{
|
||||
hv[0][i] = ambientAirTemp;
|
||||
hv[1][i] = ambientAirTemp;
|
||||
hv[YRES/CELL-3][i] = ambientAirTemp;
|
||||
hv[YRES/CELL-2][i] = ambientAirTemp;
|
||||
hv[YRES/CELL-1][i] = ambientAirTemp;
|
||||
hv[YCELLS-3][i] = ambientAirTemp;
|
||||
hv[YCELLS-2][i] = ambientAirTemp;
|
||||
hv[YCELLS-1][i] = ambientAirTemp;
|
||||
}
|
||||
for (y=0; y<YRES/CELL; y++) //update velocity and pressure
|
||||
for (y=0; y<YCELLS; y++) //update velocity and pressure
|
||||
{
|
||||
for (x=0; x<XRES/CELL; x++)
|
||||
for (x=0; x<XCELLS; x++)
|
||||
{
|
||||
dh = 0.0f;
|
||||
dx = 0.0f;
|
||||
@ -82,8 +82,8 @@ void Air::update_airh(void)
|
||||
{
|
||||
for (i=-1; i<2; i++)
|
||||
{
|
||||
if (y+j>0 && y+j<YRES/CELL-2 &&
|
||||
x+i>0 && x+i<XRES/CELL-2 &&
|
||||
if (y+j>0 && y+j<YCELLS-2 &&
|
||||
x+i>0 && x+i<XCELLS-2 &&
|
||||
!(bmap_blockairh[y+j][x+i]&0x8))
|
||||
{
|
||||
f = kernel[i+1+(j+1)*3];
|
||||
@ -106,7 +106,7 @@ void Air::update_airh(void)
|
||||
j = (int)ty;
|
||||
tx -= i;
|
||||
ty -= j;
|
||||
if (i>=2 && i<XRES/CELL-3 && j>=2 && j<YRES/CELL-3)
|
||||
if (i>=2 && i<XCELLS-3 && j>=2 && j<YCELLS-3)
|
||||
{
|
||||
odh = dh;
|
||||
dh *= 1.0f - AIR_VADV;
|
||||
@ -116,7 +116,7 @@ void Air::update_airh(void)
|
||||
dh += AIR_VADV*tx*ty*((bmap_blockairh[j+1][i+1]&0x8) ? odh : hv[j+1][i+1]);
|
||||
}
|
||||
ohv[y][x] = dh;
|
||||
if (x>=2 && x<XRES/CELL-2 && y>=2 && y<YRES/CELL-2)
|
||||
if (x>=2 && x<XCELLS-2 && y>=2 && y<YCELLS-2)
|
||||
{
|
||||
float convGravX, convGravY;
|
||||
sim.GetGravityField(x*CELL, y*CELL, -1.0f, -1.0f, convGravX, convGravY);
|
||||
@ -142,42 +142,42 @@ void Air::update_air(void)
|
||||
|
||||
if (airMode != 4) { //airMode 4 is no air/pressure update
|
||||
|
||||
for (i=0; i<YRES/CELL; i++) //reduces pressure/velocity on the edges every frame
|
||||
for (i=0; i<YCELLS; i++) //reduces pressure/velocity on the edges every frame
|
||||
{
|
||||
pv[i][0] = pv[i][0]*0.8f;
|
||||
pv[i][1] = pv[i][1]*0.8f;
|
||||
pv[i][2] = pv[i][2]*0.8f;
|
||||
pv[i][XRES/CELL-2] = pv[i][XRES/CELL-2]*0.8f;
|
||||
pv[i][XRES/CELL-1] = pv[i][XRES/CELL-1]*0.8f;
|
||||
pv[i][XCELLS-2] = pv[i][XCELLS-2]*0.8f;
|
||||
pv[i][XCELLS-1] = pv[i][XCELLS-1]*0.8f;
|
||||
vx[i][0] = vx[i][0]*0.9f;
|
||||
vx[i][1] = vx[i][1]*0.9f;
|
||||
vx[i][XRES/CELL-2] = vx[i][XRES/CELL-2]*0.9f;
|
||||
vx[i][XRES/CELL-1] = vx[i][XRES/CELL-1]*0.9f;
|
||||
vx[i][XCELLS-2] = vx[i][XCELLS-2]*0.9f;
|
||||
vx[i][XCELLS-1] = vx[i][XCELLS-1]*0.9f;
|
||||
vy[i][0] = vy[i][0]*0.9f;
|
||||
vy[i][1] = vy[i][1]*0.9f;
|
||||
vy[i][XRES/CELL-2] = vy[i][XRES/CELL-2]*0.9f;
|
||||
vy[i][XRES/CELL-1] = vy[i][XRES/CELL-1]*0.9f;
|
||||
vy[i][XCELLS-2] = vy[i][XCELLS-2]*0.9f;
|
||||
vy[i][XCELLS-1] = vy[i][XCELLS-1]*0.9f;
|
||||
}
|
||||
for (i=0; i<XRES/CELL; i++) //reduces pressure/velocity on the edges every frame
|
||||
for (i=0; i<XCELLS; i++) //reduces pressure/velocity on the edges every frame
|
||||
{
|
||||
pv[0][i] = pv[0][i]*0.8f;
|
||||
pv[1][i] = pv[1][i]*0.8f;
|
||||
pv[2][i] = pv[2][i]*0.8f;
|
||||
pv[YRES/CELL-2][i] = pv[YRES/CELL-2][i]*0.8f;
|
||||
pv[YRES/CELL-1][i] = pv[YRES/CELL-1][i]*0.8f;
|
||||
pv[YCELLS-2][i] = pv[YCELLS-2][i]*0.8f;
|
||||
pv[YCELLS-1][i] = pv[YCELLS-1][i]*0.8f;
|
||||
vx[0][i] = vx[0][i]*0.9f;
|
||||
vx[1][i] = vx[1][i]*0.9f;
|
||||
vx[YRES/CELL-2][i] = vx[YRES/CELL-2][i]*0.9f;
|
||||
vx[YRES/CELL-1][i] = vx[YRES/CELL-1][i]*0.9f;
|
||||
vx[YCELLS-2][i] = vx[YCELLS-2][i]*0.9f;
|
||||
vx[YCELLS-1][i] = vx[YCELLS-1][i]*0.9f;
|
||||
vy[0][i] = vy[0][i]*0.9f;
|
||||
vy[1][i] = vy[1][i]*0.9f;
|
||||
vy[YRES/CELL-2][i] = vy[YRES/CELL-2][i]*0.9f;
|
||||
vy[YRES/CELL-1][i] = vy[YRES/CELL-1][i]*0.9f;
|
||||
vy[YCELLS-2][i] = vy[YCELLS-2][i]*0.9f;
|
||||
vy[YCELLS-1][i] = vy[YCELLS-1][i]*0.9f;
|
||||
}
|
||||
|
||||
for (j=1; j<YRES/CELL; j++) //clear some velocities near walls
|
||||
for (j=1; j<YCELLS; j++) //clear some velocities near walls
|
||||
{
|
||||
for (i=1; i<XRES/CELL; i++)
|
||||
for (i=1; i<XCELLS; i++)
|
||||
{
|
||||
if (bmap_blockair[j][i])
|
||||
{
|
||||
@ -189,8 +189,8 @@ void Air::update_air(void)
|
||||
}
|
||||
}
|
||||
|
||||
for (y=1; y<YRES/CELL; y++) //pressure adjustments from velocity
|
||||
for (x=1; x<XRES/CELL; x++)
|
||||
for (y=1; y<YCELLS; y++) //pressure adjustments from velocity
|
||||
for (x=1; x<XCELLS; x++)
|
||||
{
|
||||
dp = 0.0f;
|
||||
dp += vx[y][x-1] - vx[y][x];
|
||||
@ -199,8 +199,8 @@ void Air::update_air(void)
|
||||
pv[y][x] += dp*AIR_TSTEPP;
|
||||
}
|
||||
|
||||
for (y=0; y<YRES/CELL-1; y++) //velocity adjustments from pressure
|
||||
for (x=0; x<XRES/CELL-1; x++)
|
||||
for (y=0; y<YCELLS-1; y++) //velocity adjustments from pressure
|
||||
for (x=0; x<XCELLS-1; x++)
|
||||
{
|
||||
dx = dy = 0.0f;
|
||||
dx += pv[y][x] - pv[y][x+1];
|
||||
@ -215,16 +215,16 @@ void Air::update_air(void)
|
||||
vy[y][x] = 0;
|
||||
}
|
||||
|
||||
for (y=0; y<YRES/CELL; y++) //update velocity and pressure
|
||||
for (x=0; x<XRES/CELL; x++)
|
||||
for (y=0; y<YCELLS; y++) //update velocity and pressure
|
||||
for (x=0; x<XCELLS; x++)
|
||||
{
|
||||
dx = 0.0f;
|
||||
dy = 0.0f;
|
||||
dp = 0.0f;
|
||||
for (j=-1; j<2; j++)
|
||||
for (i=-1; i<2; i++)
|
||||
if (y+j>0 && y+j<YRES/CELL-1 &&
|
||||
x+i>0 && x+i<XRES/CELL-1 &&
|
||||
if (y+j>0 && y+j<YCELLS-1 &&
|
||||
x+i>0 && x+i<XCELLS-1 &&
|
||||
!bmap_blockair[y+j][x+i])
|
||||
{
|
||||
f = kernel[i+1+(j+1)*3];
|
||||
@ -242,7 +242,7 @@ void Air::update_air(void)
|
||||
|
||||
tx = x - dx*advDistanceMult;
|
||||
ty = y - dy*advDistanceMult;
|
||||
if ((dx*advDistanceMult>1.0f || dy*advDistanceMult>1.0f) && (tx>=2 && tx<XRES/CELL-2 && ty>=2 && ty<YRES/CELL-2))
|
||||
if ((dx*advDistanceMult>1.0f || dy*advDistanceMult>1.0f) && (tx>=2 && tx<XCELLS-2 && ty>=2 && ty<YCELLS-2))
|
||||
{
|
||||
// Trying to take velocity from far away, check whether there is an intervening wall. Step from current position to desired source location, looking for walls, with either the x or y step size being 1 cell
|
||||
if (std::abs(dx)>std::abs(dy))
|
||||
@ -281,8 +281,8 @@ void Air::update_air(void)
|
||||
j = (int)ty;
|
||||
tx -= i;
|
||||
ty -= j;
|
||||
if (!bmap_blockair[y][x] && i>=2 && i<=XRES/CELL-3 &&
|
||||
j>=2 && j<=YRES/CELL-3)
|
||||
if (!bmap_blockair[y][x] && i>=2 && i<=XCELLS-3 &&
|
||||
j>=2 && j<=YCELLS-3)
|
||||
{
|
||||
dx *= 1.0f - AIR_VADV;
|
||||
dy *= 1.0f - AIR_VADV;
|
||||
@ -348,8 +348,8 @@ void Air::update_air(void)
|
||||
void Air::Invert()
|
||||
{
|
||||
int nx, ny;
|
||||
for (nx = 0; nx<XRES/CELL; nx++)
|
||||
for (ny = 0; ny<YRES/CELL; ny++)
|
||||
for (nx = 0; nx<XCELLS; nx++)
|
||||
for (ny = 0; ny<YCELLS; ny++)
|
||||
{
|
||||
pv[ny][nx] = -pv[ny][nx];
|
||||
vx[ny][nx] = -vx[ny][nx];
|
||||
@ -394,14 +394,14 @@ Air::Air(Simulation & simulation):
|
||||
{
|
||||
//Simulation should do this.
|
||||
make_kernel();
|
||||
std::fill(&bmap_blockair[0][0], &bmap_blockair[0][0]+((XRES/CELL)*(YRES/CELL)), 0);
|
||||
std::fill(&bmap_blockairh[0][0], &bmap_blockairh[0][0]+((XRES/CELL)*(YRES/CELL)), 0);
|
||||
std::fill(&vx[0][0], &vx[0][0]+((XRES/CELL)*(YRES/CELL)), 0.0f);
|
||||
std::fill(&ovx[0][0], &ovx[0][0]+((XRES/CELL)*(YRES/CELL)), 0.0f);
|
||||
std::fill(&vy[0][0], &vy[0][0]+((XRES/CELL)*(YRES/CELL)), 0.0f);
|
||||
std::fill(&ovy[0][0], &ovy[0][0]+((XRES/CELL)*(YRES/CELL)), 0.0f);
|
||||
std::fill(&hv[0][0], &hv[0][0]+((XRES/CELL)*(YRES/CELL)), 0.0f);
|
||||
std::fill(&ohv[0][0], &ohv[0][0]+((XRES/CELL)*(YRES/CELL)), 0.0f);
|
||||
std::fill(&pv[0][0], &pv[0][0]+((XRES/CELL)*(YRES/CELL)), 0.0f);
|
||||
std::fill(&opv[0][0], &opv[0][0]+((XRES/CELL)*(YRES/CELL)), 0.0f);
|
||||
std::fill(&bmap_blockair[0][0], &bmap_blockair[0][0]+NCELL, 0);
|
||||
std::fill(&bmap_blockairh[0][0], &bmap_blockairh[0][0]+NCELL, 0);
|
||||
std::fill(&vx[0][0], &vx[0][0]+NCELL, 0.0f);
|
||||
std::fill(&ovx[0][0], &ovx[0][0]+NCELL, 0.0f);
|
||||
std::fill(&vy[0][0], &vy[0][0]+NCELL, 0.0f);
|
||||
std::fill(&ovy[0][0], &ovy[0][0]+NCELL, 0.0f);
|
||||
std::fill(&hv[0][0], &hv[0][0]+NCELL, 0.0f);
|
||||
std::fill(&ohv[0][0], &ohv[0][0]+NCELL, 0.0f);
|
||||
std::fill(&pv[0][0], &pv[0][0]+NCELL, 0.0f);
|
||||
std::fill(&opv[0][0], &opv[0][0]+NCELL, 0.0f);
|
||||
}
|
||||
|
@ -10,21 +10,21 @@ public:
|
||||
int airMode;
|
||||
float ambientAirTemp;
|
||||
//Arrays from the simulation
|
||||
unsigned char (*bmap)[XRES/CELL];
|
||||
unsigned char (*emap)[XRES/CELL];
|
||||
float (*fvx)[XRES/CELL];
|
||||
float (*fvy)[XRES/CELL];
|
||||
unsigned char (*bmap)[XCELLS];
|
||||
unsigned char (*emap)[XCELLS];
|
||||
float (*fvx)[XCELLS];
|
||||
float (*fvy)[XCELLS];
|
||||
//
|
||||
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];
|
||||
unsigned char bmap_blockairh[YRES/CELL][XRES/CELL];
|
||||
float vx[YCELLS][XCELLS];
|
||||
float ovx[YCELLS][XCELLS];
|
||||
float vy[YCELLS][XCELLS];
|
||||
float ovy[YCELLS][XCELLS];
|
||||
float pv[YCELLS][XCELLS];
|
||||
float opv[YCELLS][XCELLS];
|
||||
float hv[YCELLS][XCELLS];
|
||||
float ohv[YCELLS][XCELLS]; // Ambient Heat
|
||||
unsigned char bmap_blockair[YCELLS][XCELLS];
|
||||
unsigned char bmap_blockairh[YCELLS][XCELLS];
|
||||
float kernel[9];
|
||||
void make_kernel(void);
|
||||
void update_airh(void);
|
||||
|
@ -14,7 +14,7 @@
|
||||
Gravity::Gravity()
|
||||
{
|
||||
// Allocate full size Gravmaps
|
||||
unsigned int size = (XRES / CELL) * (YRES / CELL);
|
||||
unsigned int size = NCELL;
|
||||
th_ogravmap = new float[size];
|
||||
th_gravmap = new float[size];
|
||||
th_gravy = new float[size];
|
||||
@ -48,7 +48,7 @@ Gravity::~Gravity()
|
||||
|
||||
void Gravity::Clear()
|
||||
{
|
||||
int size = (XRES / CELL) * (YRES / CELL);
|
||||
int size = NCELL;
|
||||
std::fill(gravy, gravy + size, 0.0f);
|
||||
std::fill(gravx, gravx + size, 0.0f);
|
||||
std::fill(gravp, gravp + size, 0.0f);
|
||||
@ -61,8 +61,8 @@ void Gravity::Clear()
|
||||
#ifdef GRAVFFT
|
||||
void Gravity::grav_fft_init()
|
||||
{
|
||||
int xblock2 = XRES/CELL*2;
|
||||
int yblock2 = YRES/CELL*2;
|
||||
int xblock2 = XCELLS*2;
|
||||
int yblock2 = YCELLS*2;
|
||||
int fft_tsize = (xblock2/2+1)*yblock2;
|
||||
float distance, scaleFactor;
|
||||
fftwf_plan plan_ptgravx, plan_ptgravy;
|
||||
@ -87,18 +87,18 @@ void Gravity::grav_fft_init()
|
||||
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 = -float(M_GRAV)/((XRES/CELL)*(YRES/CELL)*4);
|
||||
//NCELL*4 is size of data array, scaling needed because FFTW calculates an unnormalized DFT
|
||||
scaleFactor = -float(M_GRAV)/(NCELL*4);
|
||||
//calculate velocity map caused by a point mass
|
||||
for (int y = 0; y < yblock2; y++)
|
||||
{
|
||||
for (int x = 0; x < xblock2; x++)
|
||||
{
|
||||
if (x == XRES / CELL && y == YRES / CELL)
|
||||
if (x == XCELLS && y == YCELLS)
|
||||
continue;
|
||||
distance = sqrtf(pow(x-(XRES/CELL), 2.0f) + pow(y-(YRES/CELL), 2.0f));
|
||||
th_ptgravx[y * xblock2 + x] = scaleFactor * (x - (XRES / CELL)) / pow(distance, 3);
|
||||
th_ptgravy[y * xblock2 + x] = scaleFactor * (y - (YRES / CELL)) / pow(distance, 3);
|
||||
distance = sqrtf(pow(x-XCELLS, 2.0f) + pow(y-YCELLS, 2.0f));
|
||||
th_ptgravx[y * xblock2 + x] = scaleFactor * (x - XCELLS) / pow(distance, 3);
|
||||
th_ptgravy[y * xblock2 + x] = scaleFactor * (y - YCELLS) / pow(distance, 3);
|
||||
}
|
||||
}
|
||||
th_ptgravx[yblock2 * xblock2 / 2 + xblock2 / 2] = 0.0f;
|
||||
@ -154,9 +154,9 @@ void Gravity::gravity_update_async()
|
||||
if (th_gravchanged && !ignoreNextResult)
|
||||
{
|
||||
#if !defined(GRAVFFT) && defined(GRAV_DIFF)
|
||||
memcpy(gravy, th_gravy, (XRES/CELL)*(YRES/CELL)*sizeof(float));
|
||||
memcpy(gravx, th_gravx, (XRES/CELL)*(YRES/CELL)*sizeof(float));
|
||||
memcpy(gravp, th_gravp, (XRES/CELL)*(YRES/CELL)*sizeof(float));
|
||||
memcpy(gravy, th_gravy, NCELL*sizeof(float));
|
||||
memcpy(gravx, th_gravx, NCELL*sizeof(float));
|
||||
memcpy(gravp, th_gravp, NCELL*sizeof(float));
|
||||
#else
|
||||
// Copy thread gravity maps into this one
|
||||
std::swap(gravy, th_gravy);
|
||||
@ -178,7 +178,7 @@ void Gravity::gravity_update_async()
|
||||
{
|
||||
gravcv.notify_one();
|
||||
}
|
||||
unsigned int size = (XRES / CELL) * (YRES / CELL);
|
||||
unsigned int size = NCELL;
|
||||
membwand(gravy, gravmask, size * sizeof(float), size * sizeof(unsigned));
|
||||
membwand(gravx, gravmask, size * sizeof(float), size * sizeof(unsigned));
|
||||
std::fill(&gravmap[0], &gravmap[0] + size, 0.0f);
|
||||
@ -188,12 +188,11 @@ void Gravity::update_grav_async()
|
||||
{
|
||||
int done = 0;
|
||||
int thread_done = 0;
|
||||
unsigned int size = (XRES / CELL) * (YRES / CELL);
|
||||
std::fill(&th_ogravmap[0], &th_ogravmap[0] + size, 0.0f);
|
||||
std::fill(&th_gravmap[0], &th_gravmap[0] + size, 0.0f);
|
||||
std::fill(&th_gravy[0], &th_gravy[0] + size, 0.0f);
|
||||
std::fill(&th_gravx[0], &th_gravx[0] + size, 0.0f);
|
||||
std::fill(&th_gravp[0], &th_gravp[0] + size, 0.0f);
|
||||
std::fill(&th_ogravmap[0], &th_ogravmap[0] + NCELL, 0.0f);
|
||||
std::fill(&th_gravmap[0], &th_gravmap[0] + NCELL, 0.0f);
|
||||
std::fill(&th_gravy[0], &th_gravy[0] + NCELL, 0.0f);
|
||||
std::fill(&th_gravx[0], &th_gravx[0] + NCELL, 0.0f);
|
||||
std::fill(&th_gravp[0], &th_gravp[0] + NCELL, 0.0f);
|
||||
|
||||
#ifdef GRAVFFT
|
||||
if (!grav_fft_status)
|
||||
@ -231,11 +230,10 @@ void Gravity::start_grav_async()
|
||||
gravthread = std::thread([this]() { update_grav_async(); }); //Start asynchronous gravity simulation
|
||||
enabled = true;
|
||||
|
||||
unsigned int size = (XRES / CELL) * (YRES / CELL);
|
||||
std::fill(&gravy[0], &gravy[0] + size, 0.0f);
|
||||
std::fill(&gravx[0], &gravx[0] + size, 0.0f);
|
||||
std::fill(&gravp[0], &gravp[0] + size, 0.0f);
|
||||
std::fill(&gravmap[0], &gravmap[0] + size, 0.0f);
|
||||
std::fill(&gravy[0], &gravy[0] + NCELL, 0.0f);
|
||||
std::fill(&gravx[0], &gravx[0] + NCELL, 0.0f);
|
||||
std::fill(&gravp[0], &gravp[0] + NCELL, 0.0f);
|
||||
std::fill(&gravmap[0], &gravmap[0] + NCELL, 0.0f);
|
||||
}
|
||||
|
||||
void Gravity::stop_grav_async()
|
||||
@ -251,30 +249,29 @@ void Gravity::stop_grav_async()
|
||||
enabled = false;
|
||||
}
|
||||
// Clear the grav velocities
|
||||
unsigned int size = (XRES / CELL) * (YRES / CELL);
|
||||
std::fill(&gravy[0], &gravy[0] + size, 0.0f);
|
||||
std::fill(&gravx[0], &gravx[0] + size, 0.0f);
|
||||
std::fill(&gravp[0], &gravp[0] + size, 0.0f);
|
||||
std::fill(&gravmap[0], &gravmap[0] + size, 0.0f);
|
||||
std::fill(&gravy[0], &gravy[0] + NCELL, 0.0f);
|
||||
std::fill(&gravx[0], &gravx[0] + NCELL, 0.0f);
|
||||
std::fill(&gravp[0], &gravp[0] + NCELL, 0.0f);
|
||||
std::fill(&gravmap[0], &gravmap[0] + NCELL, 0.0f);
|
||||
}
|
||||
|
||||
#ifdef GRAVFFT
|
||||
void Gravity::update_grav()
|
||||
{
|
||||
int xblock2 = XRES/CELL*2, yblock2 = YRES/CELL*2;
|
||||
int xblock2 = XCELLS*2, yblock2 = YCELLS*2;
|
||||
int fft_tsize = (xblock2/2+1)*yblock2;
|
||||
float mr, mc, pr, pc, gr, gc;
|
||||
if (memcmp(th_ogravmap, th_gravmap, sizeof(float)*(XRES/CELL)*(YRES/CELL)) != 0)
|
||||
if (memcmp(th_ogravmap, th_gravmap, sizeof(float)*NCELL) != 0)
|
||||
{
|
||||
th_gravchanged = 1;
|
||||
|
||||
membwand(th_gravmap, gravmask, (XRES/CELL)*(YRES/CELL)*sizeof(float), (XRES/CELL)*(YRES/CELL)*sizeof(unsigned));
|
||||
membwand(th_gravmap, gravmask, NCELL*sizeof(float), NCELL*sizeof(unsigned));
|
||||
//copy gravmap into padded gravmap array
|
||||
for (int y = 0; y < YRES / CELL; y++)
|
||||
for (int y = 0; y < YCELLS; y++)
|
||||
{
|
||||
for (int x = 0; x < XRES / CELL; x++)
|
||||
for (int x = 0; x < XCELLS; x++)
|
||||
{
|
||||
th_gravmapbig[(y+YRES/CELL)*xblock2+XRES/CELL+x] = th_gravmap[y*(XRES/CELL)+x];
|
||||
th_gravmapbig[(y+YCELLS)*xblock2+XCELLS+x] = th_gravmap[y*XCELLS+x];
|
||||
}
|
||||
}
|
||||
//transform gravmap
|
||||
@ -300,13 +297,13 @@ void Gravity::update_grav()
|
||||
//inverse transform, and copy from padded arrays into normal velocity maps
|
||||
fftwf_execute(plan_gravx_inverse);
|
||||
fftwf_execute(plan_gravy_inverse);
|
||||
for (int y = 0; y < YRES / CELL; y++)
|
||||
for (int y = 0; y < YCELLS; y++)
|
||||
{
|
||||
for (int x = 0; x < XRES / CELL; x++)
|
||||
for (int x = 0; x < XCELLS; x++)
|
||||
{
|
||||
th_gravx[y*(XRES/CELL)+x] = th_gravxbig[y*xblock2+x];
|
||||
th_gravy[y*(XRES/CELL)+x] = th_gravybig[y*xblock2+x];
|
||||
th_gravp[y*(XRES/CELL)+x] = sqrtf(pow(th_gravxbig[y*xblock2+x],2)+pow(th_gravybig[y*xblock2+x],2));
|
||||
th_gravx[y*XCELLS+x] = th_gravxbig[y*xblock2+x];
|
||||
th_gravy[y*XCELLS+x] = th_gravybig[y*xblock2+x];
|
||||
th_gravp[y*XCELLS+x] = sqrtf(pow(th_gravxbig[y*xblock2+x],2)+pow(th_gravybig[y*xblock2+x],2));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -329,13 +326,13 @@ void Gravity::update_grav(void)
|
||||
th_gravchanged = 0;
|
||||
#ifndef GRAV_DIFF
|
||||
//Find any changed cells
|
||||
for (i=0; i<YRES/CELL; i++)
|
||||
for (i=0; i<YCELLS; i++)
|
||||
{
|
||||
if(changed)
|
||||
break;
|
||||
for (j=0; j<XRES/CELL; j++)
|
||||
for (j=0; j<XCELLS; j++)
|
||||
{
|
||||
if(th_ogravmap[i*(XRES/CELL)+j]!=th_gravmap[i*(XRES/CELL)+j]){
|
||||
if(th_ogravmap[i*XCELLS+j]!=th_gravmap[i*XCELLS+j]){
|
||||
changed = 1;
|
||||
break;
|
||||
}
|
||||
@ -343,45 +340,45 @@ void Gravity::update_grav(void)
|
||||
}
|
||||
if(!changed)
|
||||
goto fin;
|
||||
memset(th_gravy, 0, (XRES/CELL)*(YRES/CELL)*sizeof(float));
|
||||
memset(th_gravx, 0, (XRES/CELL)*(YRES/CELL)*sizeof(float));
|
||||
memset(th_gravy, 0, NCELL*sizeof(float));
|
||||
memset(th_gravx, 0, NCELL*sizeof(float));
|
||||
#endif
|
||||
th_gravchanged = 1;
|
||||
membwand(th_gravmap, gravmask, (XRES/CELL)*(YRES/CELL)*sizeof(float), (XRES/CELL)*(YRES/CELL)*sizeof(unsigned));
|
||||
for (i = 0; i < YRES / CELL; i++) {
|
||||
for (j = 0; j < XRES / CELL; j++) {
|
||||
membwand(th_gravmap, gravmask, NCELL*sizeof(float), NCELL*sizeof(unsigned));
|
||||
for (i = 0; i < YCELLS; i++) {
|
||||
for (j = 0; j < XCELLS; j++) {
|
||||
#ifdef GRAV_DIFF
|
||||
if (th_ogravmap[i*(XRES/CELL)+j] != th_gravmap[i*(XRES/CELL)+j])
|
||||
if (th_ogravmap[i*XCELLS+j] != th_gravmap[i*XCELLS+j])
|
||||
{
|
||||
#else
|
||||
if (th_gravmap[i*(XRES/CELL)+j] > 0.0001f || th_gravmap[i*(XRES/CELL)+j]<-0.0001f) //Only calculate with populated or changed cells.
|
||||
if (th_gravmap[i*XCELLS+j] > 0.0001f || th_gravmap[i*XCELLS+j]<-0.0001f) //Only calculate with populated or changed cells.
|
||||
{
|
||||
#endif
|
||||
for (y = 0; y < YRES / CELL; y++) {
|
||||
for (x = 0; x < XRES / CELL; x++) {
|
||||
for (y = 0; y < YCELLS; y++) {
|
||||
for (x = 0; x < XCELLS; x++) {
|
||||
if (x == j && y == i)//Ensure it doesn't calculate with itself
|
||||
continue;
|
||||
distance = sqrt(pow(j - x, 2.0f) + pow(i - y, 2.0f));
|
||||
#ifdef GRAV_DIFF
|
||||
val = th_gravmap[i*(XRES/CELL)+j] - th_ogravmap[i*(XRES/CELL)+j];
|
||||
val = th_gravmap[i*XCELLS+j] - th_ogravmap[i*XCELLS+j];
|
||||
#else
|
||||
val = th_gravmap[i*(XRES/CELL)+j];
|
||||
val = th_gravmap[i*XCELLS+j];
|
||||
#endif
|
||||
th_gravx[y*(XRES/CELL)+x] += M_GRAV * val * (j - x) / pow(distance, 3.0f);
|
||||
th_gravy[y*(XRES/CELL)+x] += M_GRAV * val * (i - y) / pow(distance, 3.0f);
|
||||
th_gravp[y*(XRES/CELL)+x] += M_GRAV * val / pow(distance, 2.0f);
|
||||
th_gravx[y*XCELLS+x] += M_GRAV * val * (j - x) / pow(distance, 3.0f);
|
||||
th_gravy[y*XCELLS+x] += M_GRAV * val * (i - y) / pow(distance, 3.0f);
|
||||
th_gravp[y*XCELLS+x] += M_GRAV * val / pow(distance, 2.0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
memcpy(th_ogravmap, th_gravmap, (XRES/CELL)*(YRES/CELL)*sizeof(float));
|
||||
memcpy(th_ogravmap, th_gravmap, NCELL*sizeof(float));
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
bool Gravity::grav_mask_r(int x, int y, char checkmap[YRES/CELL][XRES/CELL], char shape[YRES/CELL][XRES/CELL])
|
||||
bool Gravity::grav_mask_r(int x, int y, char checkmap[YCELLS][XCELLS], char shape[YCELLS][XCELLS])
|
||||
{
|
||||
int x1, x2;
|
||||
bool ret = false;
|
||||
@ -404,9 +401,9 @@ bool Gravity::grav_mask_r(int x, int y, char checkmap[YRES/CELL][XRES/CELL], cha
|
||||
break;
|
||||
x1--;
|
||||
}
|
||||
while (x2 <= XRES/CELL-1)
|
||||
while (x2 <= XCELLS-1)
|
||||
{
|
||||
if (x2 == XRES/CELL-1)
|
||||
if (x2 == XCELLS-1)
|
||||
{
|
||||
ret = true;
|
||||
break;
|
||||
@ -436,11 +433,11 @@ bool Gravity::grav_mask_r(int x, int y, char checkmap[YRES/CELL][XRES/CELL], cha
|
||||
cs.push(x, y-1);
|
||||
}
|
||||
}
|
||||
if (y < YRES/CELL-1)
|
||||
if (y < YCELLS-1)
|
||||
for (x=x1; x<=x2; x++)
|
||||
if (!checkmap[y+1][x] && bmap[y+1][x] != WL_GRAV)
|
||||
{
|
||||
if (y+1 == YRES/CELL-1)
|
||||
if (y+1 == YCELLS-1)
|
||||
ret = true;
|
||||
cs.push(x, y+1);
|
||||
}
|
||||
@ -464,16 +461,16 @@ void Gravity::mask_free(mask_el *c_mask_el)
|
||||
|
||||
void Gravity::gravity_mask()
|
||||
{
|
||||
char checkmap[YRES/CELL][XRES/CELL];
|
||||
char checkmap[YCELLS][XCELLS];
|
||||
unsigned maskvalue;
|
||||
mask_el *t_mask_el = nullptr;
|
||||
mask_el *c_mask_el = nullptr;
|
||||
if (!gravmask)
|
||||
return;
|
||||
memset(checkmap, 0, sizeof(checkmap));
|
||||
for (int x = 0; x < XRES / CELL; x++)
|
||||
for (int x = 0; x < XCELLS; x++)
|
||||
{
|
||||
for(int y = 0; y < YRES / CELL; y++)
|
||||
for(int y = 0; y < YCELLS; y++)
|
||||
{
|
||||
if (bmap[y][x] != WL_GRAV && checkmap[y][x] == 0)
|
||||
{
|
||||
@ -481,8 +478,8 @@ void Gravity::gravity_mask()
|
||||
if (t_mask_el == nullptr)
|
||||
{
|
||||
t_mask_el = new mask_el[sizeof(mask_el)];
|
||||
t_mask_el->shape = new char[(XRES / CELL) * (YRES / CELL)];
|
||||
std::fill(&t_mask_el->shape[0], &t_mask_el->shape[0] + (XRES / CELL) * (YRES / CELL), 0);
|
||||
t_mask_el->shape = new char[NCELL];
|
||||
std::fill(&t_mask_el->shape[0], &t_mask_el->shape[0] + NCELL, 0);
|
||||
t_mask_el->shapeout = 0;
|
||||
t_mask_el->next = nullptr;
|
||||
c_mask_el = t_mask_el;
|
||||
@ -491,33 +488,33 @@ void Gravity::gravity_mask()
|
||||
{
|
||||
c_mask_el->next = new mask_el[sizeof(mask_el)];
|
||||
c_mask_el = c_mask_el->next;
|
||||
c_mask_el->shape = new char[(XRES / CELL) * (YRES / CELL)];
|
||||
std::fill(&c_mask_el->shape[0], &c_mask_el->shape[0] + (XRES / CELL) * (YRES / CELL), 0);
|
||||
c_mask_el->shape = new char[NCELL];
|
||||
std::fill(&c_mask_el->shape[0], &c_mask_el->shape[0] + NCELL, 0);
|
||||
c_mask_el->shapeout = 0;
|
||||
c_mask_el->next = nullptr;
|
||||
}
|
||||
// Fill the shape
|
||||
if (grav_mask_r(x, y, checkmap, reinterpret_cast<char(*)[XRES/CELL]>(c_mask_el->shape)))
|
||||
if (grav_mask_r(x, y, checkmap, reinterpret_cast<char(*)[XCELLS]>(c_mask_el->shape)))
|
||||
c_mask_el->shapeout = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
c_mask_el = t_mask_el;
|
||||
std::fill(&gravmask[0], &gravmask[0] + (XRES / CELL) * (YRES / CELL), 0);
|
||||
std::fill(&gravmask[0], &gravmask[0] + NCELL, 0);
|
||||
while (c_mask_el != nullptr)
|
||||
{
|
||||
char *cshape = c_mask_el->shape;
|
||||
for (int x = 0; x < XRES / CELL; x++)
|
||||
for (int x = 0; x < XCELLS; x++)
|
||||
{
|
||||
for (int y = 0; y < YRES / CELL; y++)
|
||||
for (int y = 0; y < YCELLS; y++)
|
||||
{
|
||||
if (cshape[y * (XRES / CELL) + x])
|
||||
if (cshape[y * XCELLS + x])
|
||||
{
|
||||
if (c_mask_el->shapeout)
|
||||
maskvalue = 0xFFFFFFFF;
|
||||
else
|
||||
maskvalue = 0x00000000;
|
||||
gravmask[y * (XRES / CELL) + x] = maskvalue;
|
||||
gravmask[y * XCELLS + x] = maskvalue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ private:
|
||||
};
|
||||
using mask_el = struct mask_el;
|
||||
|
||||
bool grav_mask_r(int x, int y, char checkmap[YRES/CELL][XRES/CELL], char shape[YRES/CELL][XRES/CELL]);
|
||||
bool grav_mask_r(int x, int y, char checkmap[YCELLS][XCELLS], char shape[YCELLS][XCELLS]);
|
||||
void mask_free(mask_el *c_mask_el);
|
||||
|
||||
void update_grav();
|
||||
@ -72,7 +72,7 @@ public:
|
||||
float *gravx = nullptr;
|
||||
unsigned *gravmask = nullptr;
|
||||
|
||||
unsigned char (*bmap)[XRES/CELL];
|
||||
unsigned char (*bmap)[XCELLS];
|
||||
|
||||
bool IsEnabled() { return enabled; }
|
||||
|
||||
|
@ -548,22 +548,22 @@ void Simulation::SaveSimOptions(GameSave * gameSave)
|
||||
std::unique_ptr<Snapshot> Simulation::CreateSnapshot()
|
||||
{
|
||||
auto snap = std::make_unique<Snapshot>();
|
||||
snap->AirPressure .insert (snap->AirPressure .begin(), &pv [0][0] , &pv [0][0] + ((XRES / CELL) * (YRES / CELL)));
|
||||
snap->AirVelocityX .insert (snap->AirVelocityX .begin(), &vx [0][0] , &vx [0][0] + ((XRES / CELL) * (YRES / CELL)));
|
||||
snap->AirVelocityY .insert (snap->AirVelocityY .begin(), &vy [0][0] , &vy [0][0] + ((XRES / CELL) * (YRES / CELL)));
|
||||
snap->AmbientHeat .insert (snap->AmbientHeat .begin(), &hv [0][0] , &hv [0][0] + ((XRES / CELL) * (YRES / CELL)));
|
||||
snap->BlockMap .insert (snap->BlockMap .begin(), &bmap[0][0] , &bmap[0][0] + ((XRES / CELL) * (YRES / CELL)));
|
||||
snap->ElecMap .insert (snap->ElecMap .begin(), &emap[0][0] , &emap[0][0] + ((XRES / CELL) * (YRES / CELL)));
|
||||
snap->FanVelocityX .insert (snap->FanVelocityX .begin(), &fvx [0][0] , &fvx [0][0] + ((XRES / CELL) * (YRES / CELL)));
|
||||
snap->FanVelocityY .insert (snap->FanVelocityY .begin(), &fvy [0][0] , &fvy [0][0] + ((XRES / CELL) * (YRES / CELL)));
|
||||
snap->GravVelocityX .insert (snap->GravVelocityX .begin(), &gravx [0] , &gravx [0] + ((XRES / CELL) * (YRES / CELL)));
|
||||
snap->GravVelocityY .insert (snap->GravVelocityY .begin(), &gravy [0] , &gravy [0] + ((XRES / CELL) * (YRES / CELL)));
|
||||
snap->GravValue .insert (snap->GravValue .begin(), &gravp [0] , &gravp [0] + ((XRES / CELL) * (YRES / CELL)));
|
||||
snap->GravMap .insert (snap->GravMap .begin(), &gravmap[0] , &gravmap[0] + ((XRES / CELL) * (YRES / CELL)));
|
||||
snap->Particles .insert (snap->Particles .begin(), &parts [0] , &parts [0] + parts_lastActiveIndex + 1 );
|
||||
snap->PortalParticles.insert (snap->PortalParticles.begin(), &portalp[0][0][0], &portalp[0][0][0] + CHANNELS * 8 * 80 );
|
||||
snap->WirelessData .insert (snap->WirelessData .begin(), &wireless[0][0] , &wireless[0][0] + CHANNELS * 2 );
|
||||
snap->stickmen .insert (snap->stickmen .begin(), &fighters[0] , &fighters[0] + MAX_FIGHTERS );
|
||||
snap->AirPressure .insert (snap->AirPressure .begin(), &pv [0][0] , &pv [0][0] + NCELL);
|
||||
snap->AirVelocityX .insert (snap->AirVelocityX .begin(), &vx [0][0] , &vx [0][0] + NCELL);
|
||||
snap->AirVelocityY .insert (snap->AirVelocityY .begin(), &vy [0][0] , &vy [0][0] + NCELL);
|
||||
snap->AmbientHeat .insert (snap->AmbientHeat .begin(), &hv [0][0] , &hv [0][0] + NCELL);
|
||||
snap->BlockMap .insert (snap->BlockMap .begin(), &bmap[0][0] , &bmap[0][0] + NCELL);
|
||||
snap->ElecMap .insert (snap->ElecMap .begin(), &emap[0][0] , &emap[0][0] + NCELL);
|
||||
snap->FanVelocityX .insert (snap->FanVelocityX .begin(), &fvx [0][0] , &fvx [0][0] + NCELL);
|
||||
snap->FanVelocityY .insert (snap->FanVelocityY .begin(), &fvy [0][0] , &fvy [0][0] + NCELL);
|
||||
snap->GravVelocityX .insert (snap->GravVelocityX .begin(), &gravx [0] , &gravx [0] + NCELL);
|
||||
snap->GravVelocityY .insert (snap->GravVelocityY .begin(), &gravy [0] , &gravy [0] + NCELL);
|
||||
snap->GravValue .insert (snap->GravValue .begin(), &gravp [0] , &gravp [0] + NCELL);
|
||||
snap->GravMap .insert (snap->GravMap .begin(), &gravmap[0] , &gravmap[0] + NCELL);
|
||||
snap->Particles .insert (snap->Particles .begin(), &parts [0] , &parts [0] + parts_lastActiveIndex + 1);
|
||||
snap->PortalParticles.insert (snap->PortalParticles.begin(), &portalp[0][0][0], &portalp[0][0][0] + CHANNELS * 8 * 80);
|
||||
snap->WirelessData .insert (snap->WirelessData .begin(), &wireless[0][0] , &wireless[0][0] + CHANNELS * 2);
|
||||
snap->stickmen .insert (snap->stickmen .begin(), &fighters[0] , &fighters[0] + MAX_FIGHTERS);
|
||||
snap->stickmen .push_back(player2);
|
||||
snap->stickmen .push_back(player);
|
||||
snap->signs = signs;
|
||||
@ -764,9 +764,9 @@ SimulationSample Simulation::GetSample(int x, int y)
|
||||
|
||||
if(grav->IsEnabled())
|
||||
{
|
||||
sample.Gravity = gravp[(y/CELL)*(XRES/CELL)+(x/CELL)];
|
||||
sample.GravityVelocityX = gravx[(y/CELL)*(XRES/CELL)+(x/CELL)];
|
||||
sample.GravityVelocityY = gravy[(y/CELL)*(XRES/CELL)+(x/CELL)];
|
||||
sample.Gravity = gravp[(y/CELL)*XCELLS+(x/CELL)];
|
||||
sample.GravityVelocityX = gravx[(y/CELL)*XCELLS+(x/CELL)];
|
||||
sample.GravityVelocityY = gravy[(y/CELL)*XCELLS+(x/CELL)];
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -988,28 +988,28 @@ void Simulation::SetEdgeMode(int newEdgeMode)
|
||||
{
|
||||
case 0:
|
||||
case 2:
|
||||
for(int i = 0; i<(XRES/CELL); i++)
|
||||
for(int i = 0; i<XCELLS; i++)
|
||||
{
|
||||
bmap[0][i] = 0;
|
||||
bmap[YRES/CELL-1][i] = 0;
|
||||
bmap[YCELLS-1][i] = 0;
|
||||
}
|
||||
for(int i = 1; i<((YRES/CELL)-1); i++)
|
||||
for(int i = 1; i<(YCELLS-1); i++)
|
||||
{
|
||||
bmap[i][0] = 0;
|
||||
bmap[i][XRES/CELL-1] = 0;
|
||||
bmap[i][XCELLS-1] = 0;
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
int i;
|
||||
for(i=0; i<(XRES/CELL); i++)
|
||||
for(i=0; i<XCELLS; i++)
|
||||
{
|
||||
bmap[0][i] = WL_WALL;
|
||||
bmap[YRES/CELL-1][i] = WL_WALL;
|
||||
bmap[YCELLS-1][i] = WL_WALL;
|
||||
}
|
||||
for(i=1; i<((YRES/CELL)-1); i++)
|
||||
for(i=1; i<(YCELLS-1); i++)
|
||||
{
|
||||
bmap[i][0] = WL_WALL;
|
||||
bmap[i][XRES/CELL-1] = WL_WALL;
|
||||
bmap[i][XCELLS-1] = WL_WALL;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@ -1483,7 +1483,7 @@ int Simulation::CreateWalls(int x, int y, int rx, int ry, int wall, Brush * cBru
|
||||
{
|
||||
for (int wallY = y; wallY <= y+ry+ry; wallY++)
|
||||
{
|
||||
if (wallX >= 0 && wallX < XRES/CELL && wallY >= 0 && wallY < YRES/CELL)
|
||||
if (wallX >= 0 && wallX < XCELLS && wallY >= 0 && wallY < YCELLS)
|
||||
{
|
||||
if (wall == WL_FAN)
|
||||
{
|
||||
@ -1498,7 +1498,7 @@ int Simulation::CreateWalls(int x, int y, int rx, int ry, int wall, Brush * cBru
|
||||
for (int tempY = wallY-1; tempY < wallY+2; tempY++)
|
||||
for (int tempX = wallX-1; tempX < wallX+2; tempX++)
|
||||
{
|
||||
if (tempX >= 0 && tempX < XRES/CELL && tempY >= 0 && tempY < YRES/CELL && bmap[tempY][tempX] == WL_STREAM)
|
||||
if (tempX >= 0 && tempX < XCELLS && tempY >= 0 && tempY < YCELLS && bmap[tempY][tempX] == WL_STREAM)
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@ -2158,7 +2158,7 @@ void Simulation::set_emap(int x, int y)
|
||||
break;
|
||||
x1--;
|
||||
}
|
||||
while (x2<XRES/CELL-1)
|
||||
while (x2<XCELLS-1)
|
||||
{
|
||||
if (!is_wire_off(x2+1, y))
|
||||
break;
|
||||
@ -2179,17 +2179,17 @@ void Simulation::set_emap(int x, int y)
|
||||
for (x=x1; x<=x2; x++)
|
||||
if (is_wire_off(x, y-1))
|
||||
{
|
||||
if (x==x1 || x==x2 || y>=YRES/CELL-1 ||
|
||||
if (x==x1 || x==x2 || y>=YCELLS-1 ||
|
||||
is_wire(x-1, y-1) || is_wire(x+1, y-1) ||
|
||||
is_wire(x-1, y+1) || !is_wire(x, y+1) || is_wire(x+1, y+1))
|
||||
set_emap(x, y-1);
|
||||
}
|
||||
|
||||
if (y<YRES/CELL-2 && x1==x2 &&
|
||||
if (y<YCELLS-2 && x1==x2 &&
|
||||
is_wire(x1-1, y+1) && is_wire(x1, y+1) && is_wire(x1+1, y+1) &&
|
||||
!is_wire(x1-1, y+2) && is_wire(x1, y+2) && !is_wire(x1+1, y+2))
|
||||
set_emap(x1, y+2);
|
||||
else if (y<YRES/CELL-1)
|
||||
else if (y<YCELLS-1)
|
||||
for (x=x1; x<=x2; x++)
|
||||
if (is_wire_off(x, y+1))
|
||||
{
|
||||
@ -2300,7 +2300,7 @@ void Simulation::clear_sim(void)
|
||||
//memset(fire_g, 0, sizeof(fire_g));
|
||||
//memset(fire_b, 0, sizeof(fire_b));
|
||||
//if(gravmask)
|
||||
//memset(gravmask, 0xFFFFFFFF, (XRES/CELL)*(YRES/CELL)*sizeof(unsigned));
|
||||
//memset(gravmask, 0xFFFFFFFF, NCELL*sizeof(unsigned));
|
||||
if(grav)
|
||||
grav->Clear();
|
||||
if(air)
|
||||
@ -3365,8 +3365,8 @@ void Simulation::GetGravityField(int x, int y, float particleGrav, float newtonG
|
||||
}
|
||||
if (newtonGrav)
|
||||
{
|
||||
pGravX += newtonGrav*gravx[(y/CELL)*(XRES/CELL)+(x/CELL)];
|
||||
pGravY += newtonGrav*gravy[(y/CELL)*(XRES/CELL)+(x/CELL)];
|
||||
pGravX += newtonGrav*gravx[(y/CELL)*XCELLS+(x/CELL)];
|
||||
pGravY += newtonGrav*gravy[(y/CELL)*XCELLS+(x/CELL)];
|
||||
}
|
||||
}
|
||||
|
||||
@ -4008,7 +4008,7 @@ void Simulation::UpdateParticles(int start, int end)
|
||||
ny = y/CELL + 1;
|
||||
else
|
||||
ny = y/CELL;
|
||||
if (nx>=0 && ny>=0 && nx<XRES/CELL && ny<YRES/CELL)
|
||||
if (nx>=0 && ny>=0 && nx<XCELLS && ny<YCELLS)
|
||||
{
|
||||
if (t!=PT_SPRK)
|
||||
{
|
||||
@ -4037,7 +4037,7 @@ void Simulation::UpdateParticles(int start, int end)
|
||||
|
||||
|
||||
s = 1;
|
||||
gravtot = fabs(gravy[(y/CELL)*(XRES/CELL)+(x/CELL)])+fabs(gravx[(y/CELL)*(XRES/CELL)+(x/CELL)]);
|
||||
gravtot = fabs(gravy[(y/CELL)*XCELLS+(x/CELL)])+fabs(gravx[(y/CELL)*XCELLS+(x/CELL)]);
|
||||
if (elements[t].HighPressureTransition>-1 && pv[y/CELL][x/CELL]>elements[t].HighPressure) {
|
||||
// particle type change due to high pressure
|
||||
if (elements[t].HighPressureTransition!=PT_NUM)
|
||||
@ -5046,9 +5046,9 @@ void Simulation::BeforeSim()
|
||||
{
|
||||
// decrease wall conduction, make walls block air and ambient heat
|
||||
int x, y;
|
||||
for (y = 0; y < YRES/CELL; y++)
|
||||
for (y = 0; y < YCELLS; y++)
|
||||
{
|
||||
for (x = 0; x < XRES/CELL; x++)
|
||||
for (x = 0; x < XCELLS; x++)
|
||||
{
|
||||
if (emap[y][x])
|
||||
emap[y][x] --;
|
||||
|
@ -83,20 +83,20 @@ public:
|
||||
int GSPEED;
|
||||
unsigned int gol[YRES][XRES][5];
|
||||
//Air sim
|
||||
float (*vx)[XRES/CELL];
|
||||
float (*vy)[XRES/CELL];
|
||||
float (*pv)[XRES/CELL];
|
||||
float (*hv)[XRES/CELL];
|
||||
float (*vx)[XCELLS];
|
||||
float (*vy)[XCELLS];
|
||||
float (*pv)[XCELLS];
|
||||
float (*hv)[XCELLS];
|
||||
//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)];
|
||||
float *gravx;//gravx[YCELLS * XCELLS];
|
||||
float *gravy;//gravy[YCELLS * XCELLS];
|
||||
float *gravp;//gravp[YCELLS * XCELLS];
|
||||
float *gravmap;//gravmap[YCELLS * XCELLS];
|
||||
//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];
|
||||
unsigned char bmap[YCELLS][XCELLS];
|
||||
unsigned char emap[YCELLS][XCELLS];
|
||||
float fvx[YCELLS][XCELLS];
|
||||
float fvy[YCELLS][XCELLS];
|
||||
//Particles
|
||||
Particle parts[NPART];
|
||||
int pmap[YRES][XRES];
|
||||
|
@ -54,7 +54,7 @@ void Element::Element_DEUT()
|
||||
static int update(UPDATE_FUNC_ARGS)
|
||||
{
|
||||
int r, rx, ry, trade, np;
|
||||
float gravtot = fabs(sim->gravy[(y/CELL)*(XRES/CELL)+(x/CELL)])+fabs(sim->gravx[(y/CELL)*(XRES/CELL)+(x/CELL)]);
|
||||
float gravtot = fabs(sim->gravy[(y/CELL)*XCELLS+(x/CELL)])+fabs(sim->gravx[(y/CELL)*XCELLS+(x/CELL)]);
|
||||
// Prevent division by 0
|
||||
float temp = std::max(1.0f, (parts[i].temp + 1));
|
||||
auto maxlife = int(((10000/(temp + 1))-1));
|
||||
|
@ -72,9 +72,9 @@ static int update(UPDATE_FUNC_ARGS)
|
||||
}
|
||||
}
|
||||
if (parts[i].life>20)
|
||||
sim->gravmap[(y/CELL)*(XRES/CELL)+(x/CELL)] = 20;
|
||||
sim->gravmap[(y/CELL)*XCELLS+(x/CELL)] = 20;
|
||||
else if (parts[i].life>=1)
|
||||
sim->gravmap[(y/CELL)*(XRES/CELL)+(x/CELL)] = -80;
|
||||
sim->gravmap[(y/CELL)*XCELLS+(x/CELL)] = -80;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -64,7 +64,7 @@ static int update(UPDATE_FUNC_ARGS)
|
||||
if (parts[i].temp<= -256.0f+273.15f)
|
||||
parts[i].temp = -256.0f+273.15f;
|
||||
|
||||
sim->gravmap[(y/CELL)*(XRES/CELL)+(x/CELL)] = 0.2f*(parts[i].temp-273.15);
|
||||
sim->gravmap[(y/CELL)*XCELLS+(x/CELL)] = 0.2f*(parts[i].temp-273.15);
|
||||
for (rx=-2; rx<3; rx++)
|
||||
for (ry=-2; ry<3; ry++)
|
||||
if (BOUNDS_CHECK && (rx || ry))
|
||||
|
@ -59,7 +59,7 @@ static int update(UPDATE_FUNC_ARGS)
|
||||
if (parts[i].tmp <= -100)
|
||||
parts[i].tmp = -100;
|
||||
|
||||
sim->gravmap[(y/CELL)*(XRES/CELL)+(x/CELL)] = 0.2f*parts[i].tmp;
|
||||
sim->gravmap[(y/CELL)*XCELLS+(x/CELL)] = 0.2f*parts[i].tmp;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -48,8 +48,8 @@ void Element::Element_NBHL()
|
||||
static int update(UPDATE_FUNC_ARGS)
|
||||
{
|
||||
if (parts[i].tmp)
|
||||
sim->gravmap[(y/CELL)*(XRES/CELL)+(x/CELL)] += restrict_flt(0.001f*parts[i].tmp, 0.1f, 51.2f);
|
||||
sim->gravmap[(y/CELL)*XCELLS+(x/CELL)] += restrict_flt(0.001f*parts[i].tmp, 0.1f, 51.2f);
|
||||
else
|
||||
sim->gravmap[(y/CELL)*(XRES/CELL)+(x/CELL)] += 0.1f;
|
||||
sim->gravmap[(y/CELL)*XCELLS+(x/CELL)] += 0.1f;
|
||||
return 0;
|
||||
}
|
||||
|
@ -48,8 +48,8 @@ void Element::Element_NWHL()
|
||||
static int update(UPDATE_FUNC_ARGS)
|
||||
{
|
||||
if (parts[i].tmp)
|
||||
sim->gravmap[(y/CELL)*(XRES/CELL)+(x/CELL)] -= restrict_flt(0.001f*parts[i].tmp, 0.1f, 51.2f);
|
||||
sim->gravmap[(y/CELL)*XCELLS+(x/CELL)] -= restrict_flt(0.001f*parts[i].tmp, 0.1f, 51.2f);
|
||||
else
|
||||
sim->gravmap[(y/CELL)*(XRES/CELL)+(x/CELL)] -= 0.1f;
|
||||
sim->gravmap[(y/CELL)*XCELLS+(x/CELL)] -= 0.1f;
|
||||
return 0;
|
||||
}
|
||||
|
@ -76,7 +76,7 @@ static int update(UPDATE_FUNC_ARGS)
|
||||
}
|
||||
if (parts[i].temp > 9973.15 && sim->pv[y/CELL][x/CELL] > 250.0f)
|
||||
{
|
||||
int gravPos = ((y/CELL)*(XRES/CELL))+(x/CELL);
|
||||
int gravPos = ((y/CELL)*XCELLS)+(x/CELL);
|
||||
float gravx = sim->gravx[gravPos];
|
||||
float gravy = sim->gravy[gravPos];
|
||||
if (gravx*gravx + gravy*gravy > 400)
|
||||
|
@ -71,7 +71,7 @@ static int update(UPDATE_FUNC_ARGS)
|
||||
crx = (x/CELL)+rx;
|
||||
for (ry=-1; ry<2; ry++) {
|
||||
cry = (y/CELL)+ry;
|
||||
if (cry >= 0 && crx >= 0 && crx < (XRES/CELL) && cry < (YRES/CELL)) {
|
||||
if (cry >= 0 && crx >= 0 && crx < XCELLS && cry < YCELLS) {
|
||||
sim->pv[cry][crx] += (float)parts[i].tmp;
|
||||
}
|
||||
}
|
||||
|
@ -164,8 +164,8 @@ int Element_STKM_run_stickman(playerst *playerp, UPDATE_FUNC_ARGS)
|
||||
break;
|
||||
}
|
||||
|
||||
gvx += sim->gravx[((int)parts[i].y/CELL)*(XRES/CELL)+((int)parts[i].x/CELL)];
|
||||
gvy += sim->gravy[((int)parts[i].y/CELL)*(XRES/CELL)+((int)parts[i].x/CELL)];
|
||||
gvx += sim->gravx[((int)parts[i].y/CELL)*XCELLS+((int)parts[i].x/CELL)];
|
||||
gvy += sim->gravy[((int)parts[i].y/CELL)*XCELLS+((int)parts[i].x/CELL)];
|
||||
|
||||
float mvx = gvx;
|
||||
float mvy = gvy;
|
||||
|
@ -13,6 +13,6 @@ void SimTool::Tool_NGRV()
|
||||
|
||||
static int perform(Simulation * sim, Particle * cpart, int x, int y, int brushX, int brushYy, float strength)
|
||||
{
|
||||
sim->gravmap[((y/CELL)*(XRES/CELL))+(x/CELL)] = strength*-5.0f;
|
||||
sim->gravmap[((y/CELL)*XCELLS)+(x/CELL)] = strength*-5.0f;
|
||||
return 1;
|
||||
}
|
||||
|
@ -13,6 +13,6 @@ void SimTool::Tool_PGRV()
|
||||
|
||||
static int perform(Simulation * sim, Particle * cpart, int x, int y, int brushX, int brushY, float strength)
|
||||
{
|
||||
sim->gravmap[((y/CELL)*(XRES/CELL))+(x/CELL)] = strength*5.0f;
|
||||
sim->gravmap[((y/CELL)*XCELLS)+(x/CELL)] = strength*5.0f;
|
||||
return 1;
|
||||
}
|
||||
|
Reference in New Issue
Block a user