Move more stuff to Editing.cpp

This commit is contained in:
Tamás Bálint Misius 2023-01-22 09:53:30 +01:00
parent 75191e7ac5
commit 9034736708
No known key found for this signature in database
GPG Key ID: 5B472A12F6ECA9F2
5 changed files with 447 additions and 467 deletions

View File

@ -1,10 +1,442 @@
#include "Simulation.h"
#include "Sample.h"
#include "SimTool.h"
#include "Snapshot.h"
#include "Air.h"
#include "Gravity.h"
#include "common/tpt-rand.h"
#include "common/tpt-compat.h"
#include "client/GameSave.h"
#include "ElementClasses.h"
#include "graphics/Renderer.h"
#include "gui/game/Brush.h"
#include <iostream>
#include <cmath>
std::unique_ptr<Snapshot> Simulation::CreateSnapshot()
{
auto snap = std::make_unique<Snapshot>();
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;
return snap;
}
void Simulation::Restore(const Snapshot &snap)
{
std::fill(elementCount, elementCount + PT_NUM, 0);
elementRecount = true;
force_stacking_check = true;
for (auto &part : parts)
{
part.type = 0;
}
std::copy(snap.AirPressure .begin(), snap.AirPressure .end(), &pv[0][0] );
std::copy(snap.AirVelocityX .begin(), snap.AirVelocityX .end(), &vx[0][0] );
std::copy(snap.AirVelocityY .begin(), snap.AirVelocityY .end(), &vy[0][0] );
std::copy(snap.AmbientHeat .begin(), snap.AmbientHeat .end(), &hv[0][0] );
std::copy(snap.BlockMap .begin(), snap.BlockMap .end(), &bmap[0][0] );
std::copy(snap.ElecMap .begin(), snap.ElecMap .end(), &emap[0][0] );
std::copy(snap.FanVelocityX .begin(), snap.FanVelocityX .end(), &fvx[0][0] );
std::copy(snap.FanVelocityY .begin(), snap.FanVelocityY .end(), &fvy[0][0] );
if (grav->IsEnabled())
{
grav->Clear();
std::copy(snap.GravVelocityX.begin(), snap.GravVelocityX.end(), &gravx [0] );
std::copy(snap.GravVelocityY.begin(), snap.GravVelocityY.end(), &gravy [0] );
std::copy(snap.GravValue .begin(), snap.GravValue .end(), &gravp [0] );
std::copy(snap.GravMap .begin(), snap.GravMap .end(), &gravmap[0] );
}
std::copy(snap.Particles .begin(), snap.Particles .end(), &parts[0] );
std::copy(snap.PortalParticles.begin(), snap.PortalParticles.end(), &portalp[0][0][0]);
std::copy(snap.WirelessData .begin(), snap.WirelessData .end(), &wireless[0][0] );
std::copy(snap.stickmen .begin(), snap.stickmen.end() - 2 , &fighters[0] );
player = snap.stickmen[snap.stickmen.size() - 1];
player2 = snap.stickmen[snap.stickmen.size() - 2];
signs = snap.signs;
parts_lastActiveIndex = NPART - 1;
air->RecalculateBlockAirMaps();
RecalcFreeParticles(false);
gravWallChanged = true;
}
void Simulation::clear_area(int area_x, int area_y, int area_w, int area_h)
{
float fx = area_x-.5f, fy = area_y-.5f;
for (int i = 0; i <= parts_lastActiveIndex; i++)
{
if (parts[i].type)
if (parts[i].x >= fx && parts[i].x <= fx+area_w+1 && parts[i].y >= fy && parts[i].y <= fy+area_h+1)
kill_part(i);
}
int cx1 = area_x/CELL, cy1 = area_y/CELL, cx2 = (area_x+area_w)/CELL, cy2 = (area_y+area_h)/CELL;
for (int y = cy1; y <= cy2; y++)
{
for (int x = cx1; x <= cx2; x++)
{
if (bmap[y][x] == WL_GRAV)
gravWallChanged = true;
bmap[y][x] = 0;
emap[y][x] = 0;
}
}
for( int i = signs.size()-1; i >= 0; i--)
{
if (signs[i].text.length() && signs[i].x >= area_x && signs[i].y >= area_y && signs[i].x <= area_x+area_w && signs[i].y <= area_y+area_h)
{
signs.erase(signs.begin()+i);
}
}
}
SimulationSample Simulation::GetSample(int x, int y)
{
SimulationSample sample;
sample.PositionX = x;
sample.PositionY = y;
if (x >= 0 && x < XRES && y >= 0 && y < YRES)
{
if (photons[y][x])
{
sample.particle = parts[ID(photons[y][x])];
sample.ParticleID = ID(photons[y][x]);
}
else if (pmap[y][x])
{
sample.particle = parts[ID(pmap[y][x])];
sample.ParticleID = ID(pmap[y][x]);
}
if (bmap[y/CELL][x/CELL])
{
sample.WallType = bmap[y/CELL][x/CELL];
}
sample.AirPressure = pv[y/CELL][x/CELL];
sample.AirTemperature = hv[y/CELL][x/CELL];
sample.AirVelocityX = vx[y/CELL][x/CELL];
sample.AirVelocityY = vy[y/CELL][x/CELL];
if(grav->IsEnabled())
{
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
sample.isMouseInSim = false;
sample.NumParts = NUM_PARTS;
return sample;
}
void Simulation::SetDecoSpace(int newDecoSpace)
{
switch (newDecoSpace)
{
case 0: // sRGB
default: // anything stupid
deco_space = 0;
break;
case 1: // linear
deco_space = 1;
break;
case 2: // Gamma = 2.2
deco_space = 2;
break;
case 3: // Gamma = 1.8
deco_space = 3;
break;
}
}
int Simulation::Tool(int x, int y, int tool, int brushX, int brushY, float strength)
{
Particle * cpart = NULL;
int r;
if ((r = pmap[y][x]))
cpart = &(parts[ID(r)]);
else if ((r = photons[y][x]))
cpart = &(parts[ID(r)]);
return tools[tool].Perform(this, cpart, x, y, brushX, brushY, strength);
}
int Simulation::CreateWalls(int x, int y, int rx, int ry, int wall, Brush * cBrush)
{
if(cBrush)
{
rx = cBrush->GetRadius().X;
ry = cBrush->GetRadius().Y;
}
ry = ry/CELL;
rx = rx/CELL;
x = x/CELL;
y = y/CELL;
x -= rx;
y -= ry;
for (int wallX = x; wallX <= x+rx+rx; wallX++)
{
for (int wallY = y; wallY <= y+ry+ry; wallY++)
{
if (wallX >= 0 && wallX < XCELLS && wallY >= 0 && wallY < YCELLS)
{
if (wall == WL_FAN)
{
fvx[wallY][wallX] = 0.0f;
fvy[wallY][wallX] = 0.0f;
}
else if (wall == WL_STREAM)
{
wallX = x + rx;
wallY = y + ry;
//streamlines can't be drawn next to each other
for (int tempY = wallY-1; tempY < wallY+2; tempY++)
for (int tempX = wallX-1; tempX < wallX+2; tempX++)
{
if (tempX >= 0 && tempX < XCELLS && tempY >= 0 && tempY < YCELLS && bmap[tempY][tempX] == WL_STREAM)
return 1;
}
}
if (wall == WL_GRAV || bmap[wallY][wallX] == WL_GRAV)
gravWallChanged = true;
if (wall == WL_ERASEALL)
{
for (int i = 0; i < CELL; i++)
for (int j = 0; j < CELL; j++)
{
delete_part(wallX*CELL+i, wallY*CELL+j);
}
for (int i = signs.size()-1; i >= 0; i--)
if (signs[i].x >= wallX*CELL && signs[i].y >= wallY*CELL && signs[i].x <= (wallX+1)*CELL && signs[i].y <= (wallY+1)*CELL)
signs.erase(signs.begin()+i);
bmap[wallY][wallX] = 0;
}
else
bmap[wallY][wallX] = wall;
}
}
}
return 1;
}
void Simulation::CreateWallLine(int x1, int y1, int x2, int y2, int rx, int ry, int wall, Brush * cBrush)
{
int x, y, dx, dy, sy;
bool reverseXY = abs(y2-y1) > abs(x2-x1);
float e = 0.0f, de;
if (reverseXY)
{
y = x1;
x1 = y1;
y1 = y;
y = x2;
x2 = y2;
y2 = y;
}
if (x1 > x2)
{
y = x1;
x1 = x2;
x2 = y;
y = y1;
y1 = y2;
y2 = y;
}
dx = x2 - x1;
dy = abs(y2 - y1);
de = dx ? dy/(float)dx : 0.0f;
y = y1;
sy = (y1<y2) ? 1 : -1;
for (x=x1; x<=x2; x++)
{
if (reverseXY)
CreateWalls(y, x, rx, ry, wall, cBrush);
else
CreateWalls(x, y, rx, ry, wall, cBrush);
e += de;
if (e >= 0.5f)
{
y += sy;
if ((y1<y2) ? (y<=y2) : (y>=y2))
{
if (reverseXY)
CreateWalls(y, x, rx, ry, wall, cBrush);
else
CreateWalls(x, y, rx, ry, wall, cBrush);
}
e -= 1.0f;
}
}
}
void Simulation::CreateWallBox(int x1, int y1, int x2, int y2, int wall)
{
int i, j;
if (x1>x2)
{
i = x2;
x2 = x1;
x1 = i;
}
if (y1>y2)
{
j = y2;
y2 = y1;
y1 = j;
}
for (j=y1; j<=y2; j++)
for (i=x1; i<=x2; i++)
CreateWalls(i, j, 0, 0, wall, NULL);
}
int Simulation::FloodWalls(int x, int y, int wall, int bm)
{
int x1, x2, dy = CELL;
if (bm==-1)
{
if (wall==WL_ERASE || wall==WL_ERASEALL)
{
bm = bmap[y/CELL][x/CELL];
if (!bm)
return 0;
}
else
bm = 0;
}
if (bmap[y/CELL][x/CELL]!=bm)
return 1;
// go left as far as possible
x1 = x2 = x;
while (x1>=CELL)
{
if (bmap[y/CELL][(x1-1)/CELL]!=bm)
{
break;
}
x1--;
}
while (x2<XRES-CELL)
{
if (bmap[y/CELL][(x2+1)/CELL]!=bm)
{
break;
}
x2++;
}
// fill span
for (x=x1; x<=x2; x++)
{
if (!CreateWalls(x, y, 0, 0, wall, NULL))
return 0;
}
// fill children
if (y>=CELL)
for (x=x1; x<=x2; x++)
if (bmap[(y-dy)/CELL][x/CELL]==bm)
if (!FloodWalls(x, y-dy, wall, bm))
return 0;
if (y<YRES-CELL)
for (x=x1; x<=x2; x++)
if (bmap[(y+dy)/CELL][x/CELL]==bm)
if (!FloodWalls(x, y+dy, wall, bm))
return 0;
return 1;
}
int Simulation::CreatePartFlags(int x, int y, int c, int flags)
{
if (x < 0 || y < 0 || x >= XRES || y >= YRES)
{
return 0;
}
if (flags & REPLACE_MODE)
{
// if replace whatever and there's something to replace
// or replace X and there's a non-energy particle on top with type X
// or replace X and there's an energy particle on top with type X
if ((!replaceModeSelected && (photons[y][x] || pmap[y][x])) ||
(!photons[y][x] && pmap[y][x] && TYP(pmap[y][x]) == replaceModeSelected) ||
(photons[y][x] && TYP(photons[y][x]) == replaceModeSelected))
{
if (c)
create_part(photons[y][x] ? ID(photons[y][x]) : ID(pmap[y][x]), x, y, TYP(c), ID(c));
else
delete_part(x, y);
}
return 0;
}
else if (!c)
{
delete_part(x, y);
return 0;
}
else if (flags & SPECIFIC_DELETE)
{
// if delete whatever and there's something to delete
// or delete X and there's a non-energy particle on top with type X
// or delete X and there's an energy particle on top with type X
if ((!replaceModeSelected && (photons[y][x] || pmap[y][x])) ||
(!photons[y][x] && pmap[y][x] && TYP(pmap[y][x]) == replaceModeSelected) ||
(photons[y][x] && TYP(photons[y][x]) == replaceModeSelected))
{
delete_part(x, y);
}
return 0;
}
else
{
return (create_part(-2, x, y, TYP(c), ID(c)) == -1);
}
// I'm sure at least one compiler exists that would complain if this wasn't here
return 0;
}
int Simulation::GetParticleType(ByteString type)
{
type = type.ToUpper();
// alternative names for some elements
if (byteStringEqualsLiteral(type, "C4"))
return PT_PLEX;
else if (byteStringEqualsLiteral(type, "C5"))
return PT_C5;
else if (byteStringEqualsLiteral(type, "NONE"))
return PT_NONE;
for (int i = 1; i < PT_NUM; i++)
{
if (elements[i].Name.size() && elements[i].Enabled && type == elements[i].Name.ToUtf8().ToUpper())
{
return i;
}
}
return -1;
}
void Simulation::ApplyDecoration(int x, int y, int colR_, int colG_, int colB_, int colA_, int mode)
{
int rp;

View File

@ -0,0 +1,7 @@
#include "ToolClasses.h"
std::vector<SimTool> const &GetTools()
{
static std::vector<SimTool> tools;
return tools;
}

View File

@ -2,8 +2,6 @@
#include "Air.h"
#include "ElementClasses.h"
#include "Gravity.h"
#include "Sample.h"
#include "Snapshot.h"
#include "ToolClasses.h"
#include "SimulationData.h"
#include "GOLString.h"
@ -523,98 +521,6 @@ void Simulation::SaveSimOptions(GameSave * gameSave)
gameSave->aheatEnable = aheat_enable;
}
std::unique_ptr<Snapshot> Simulation::CreateSnapshot()
{
auto snap = std::make_unique<Snapshot>();
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;
return snap;
}
void Simulation::Restore(const Snapshot &snap)
{
std::fill(elementCount, elementCount + PT_NUM, 0);
elementRecount = true;
force_stacking_check = true;
for (auto &part : parts)
{
part.type = 0;
}
std::copy(snap.AirPressure .begin(), snap.AirPressure .end(), &pv[0][0] );
std::copy(snap.AirVelocityX .begin(), snap.AirVelocityX .end(), &vx[0][0] );
std::copy(snap.AirVelocityY .begin(), snap.AirVelocityY .end(), &vy[0][0] );
std::copy(snap.AmbientHeat .begin(), snap.AmbientHeat .end(), &hv[0][0] );
std::copy(snap.BlockMap .begin(), snap.BlockMap .end(), &bmap[0][0] );
std::copy(snap.ElecMap .begin(), snap.ElecMap .end(), &emap[0][0] );
std::copy(snap.FanVelocityX .begin(), snap.FanVelocityX .end(), &fvx[0][0] );
std::copy(snap.FanVelocityY .begin(), snap.FanVelocityY .end(), &fvy[0][0] );
if (grav->IsEnabled())
{
grav->Clear();
std::copy(snap.GravVelocityX.begin(), snap.GravVelocityX.end(), &gravx [0] );
std::copy(snap.GravVelocityY.begin(), snap.GravVelocityY.end(), &gravy [0] );
std::copy(snap.GravValue .begin(), snap.GravValue .end(), &gravp [0] );
std::copy(snap.GravMap .begin(), snap.GravMap .end(), &gravmap[0] );
}
std::copy(snap.Particles .begin(), snap.Particles .end(), &parts[0] );
std::copy(snap.PortalParticles.begin(), snap.PortalParticles.end(), &portalp[0][0][0]);
std::copy(snap.WirelessData .begin(), snap.WirelessData .end(), &wireless[0][0] );
std::copy(snap.stickmen .begin(), snap.stickmen.end() - 2 , &fighters[0] );
player = snap.stickmen[snap.stickmen.size() - 1];
player2 = snap.stickmen[snap.stickmen.size() - 2];
signs = snap.signs;
parts_lastActiveIndex = NPART - 1;
air->RecalculateBlockAirMaps();
RecalcFreeParticles(false);
gravWallChanged = true;
}
void Simulation::clear_area(int area_x, int area_y, int area_w, int area_h)
{
float fx = area_x-.5f, fy = area_y-.5f;
for (int i = 0; i <= parts_lastActiveIndex; i++)
{
if (parts[i].type)
if (parts[i].x >= fx && parts[i].x <= fx+area_w+1 && parts[i].y >= fy && parts[i].y <= fy+area_h+1)
kill_part(i);
}
int cx1 = area_x/CELL, cy1 = area_y/CELL, cx2 = (area_x+area_w)/CELL, cy2 = (area_y+area_h)/CELL;
for (int y = cy1; y <= cy2; y++)
{
for (int x = cx1; x <= cx2; x++)
{
if (bmap[y][x] == WL_GRAV)
gravWallChanged = true;
bmap[y][x] = 0;
emap[y][x] = 0;
}
}
for( int i = signs.size()-1; i >= 0; i--)
{
if (signs[i].text.length() && signs[i].x >= area_x && signs[i].y >= area_y && signs[i].x <= area_x+area_w && signs[i].y <= area_y+area_h)
{
signs.erase(signs.begin()+i);
}
}
}
bool Simulation::FloodFillPmapCheck(int x, int y, int type)
{
if (type == 0)
@ -714,46 +620,6 @@ int Simulation::flood_prop(int x, int y, size_t propoffset, PropertyValue propva
return did_something;
}
SimulationSample Simulation::GetSample(int x, int y)
{
SimulationSample sample;
sample.PositionX = x;
sample.PositionY = y;
if (x >= 0 && x < XRES && y >= 0 && y < YRES)
{
if (photons[y][x])
{
sample.particle = parts[ID(photons[y][x])];
sample.ParticleID = ID(photons[y][x]);
}
else if (pmap[y][x])
{
sample.particle = parts[ID(pmap[y][x])];
sample.ParticleID = ID(pmap[y][x]);
}
if (bmap[y/CELL][x/CELL])
{
sample.WallType = bmap[y/CELL][x/CELL];
}
sample.AirPressure = pv[y/CELL][x/CELL];
sample.AirTemperature = hv[y/CELL][x/CELL];
sample.AirVelocityX = vx[y/CELL][x/CELL];
sample.AirVelocityY = vy[y/CELL][x/CELL];
if(grav->IsEnabled())
{
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
sample.isMouseInSim = false;
sample.NumParts = NUM_PARTS;
return sample;
}
int Simulation::FloodINST(int x, int y)
{
int x1, x2;
@ -936,29 +802,6 @@ bool Simulation::flood_water(int x, int y, int i)
return false;
}
void Simulation::SetDecoSpace(int newDecoSpace)
{
switch (newDecoSpace)
{
case 0: // sRGB
default: // anything stupid
deco_space = 0;
break;
case 1: // linear
deco_space = 1;
break;
case 2: // Gamma = 2.2
deco_space = 2;
break;
case 3: // Gamma = 1.8
deco_space = 3;
break;
}
}
void Simulation::SetEdgeMode(int newEdgeMode)
{
edgeMode = newEdgeMode;
@ -995,255 +838,8 @@ void Simulation::SetEdgeMode(int newEdgeMode)
}
}
int Simulation::Tool(int x, int y, int tool, int brushX, int brushY, float strength)
{
Particle * cpart = NULL;
int r;
if ((r = pmap[y][x]))
cpart = &(parts[ID(r)]);
else if ((r = photons[y][x]))
cpart = &(parts[ID(r)]);
return tools[tool].Perform(this, cpart, x, y, brushX, brushY, strength);
}
int Simulation::CreateWalls(int x, int y, int rx, int ry, int wall, Brush * cBrush)
{
if(cBrush)
{
rx = cBrush->GetRadius().X;
ry = cBrush->GetRadius().Y;
}
ry = ry/CELL;
rx = rx/CELL;
x = x/CELL;
y = y/CELL;
x -= rx;
y -= ry;
for (int wallX = x; wallX <= x+rx+rx; wallX++)
{
for (int wallY = y; wallY <= y+ry+ry; wallY++)
{
if (wallX >= 0 && wallX < XCELLS && wallY >= 0 && wallY < YCELLS)
{
if (wall == WL_FAN)
{
fvx[wallY][wallX] = 0.0f;
fvy[wallY][wallX] = 0.0f;
}
else if (wall == WL_STREAM)
{
wallX = x + rx;
wallY = y + ry;
//streamlines can't be drawn next to each other
for (int tempY = wallY-1; tempY < wallY+2; tempY++)
for (int tempX = wallX-1; tempX < wallX+2; tempX++)
{
if (tempX >= 0 && tempX < XCELLS && tempY >= 0 && tempY < YCELLS && bmap[tempY][tempX] == WL_STREAM)
return 1;
}
}
if (wall == WL_GRAV || bmap[wallY][wallX] == WL_GRAV)
gravWallChanged = true;
if (wall == WL_ERASEALL)
{
for (int i = 0; i < CELL; i++)
for (int j = 0; j < CELL; j++)
{
delete_part(wallX*CELL+i, wallY*CELL+j);
}
for (int i = signs.size()-1; i >= 0; i--)
if (signs[i].x >= wallX*CELL && signs[i].y >= wallY*CELL && signs[i].x <= (wallX+1)*CELL && signs[i].y <= (wallY+1)*CELL)
signs.erase(signs.begin()+i);
bmap[wallY][wallX] = 0;
}
else
bmap[wallY][wallX] = wall;
}
}
}
return 1;
}
void Simulation::CreateWallLine(int x1, int y1, int x2, int y2, int rx, int ry, int wall, Brush * cBrush)
{
int x, y, dx, dy, sy;
bool reverseXY = abs(y2-y1) > abs(x2-x1);
float e = 0.0f, de;
if (reverseXY)
{
y = x1;
x1 = y1;
y1 = y;
y = x2;
x2 = y2;
y2 = y;
}
if (x1 > x2)
{
y = x1;
x1 = x2;
x2 = y;
y = y1;
y1 = y2;
y2 = y;
}
dx = x2 - x1;
dy = abs(y2 - y1);
de = dx ? dy/(float)dx : 0.0f;
y = y1;
sy = (y1<y2) ? 1 : -1;
for (x=x1; x<=x2; x++)
{
if (reverseXY)
CreateWalls(y, x, rx, ry, wall, cBrush);
else
CreateWalls(x, y, rx, ry, wall, cBrush);
e += de;
if (e >= 0.5f)
{
y += sy;
if ((y1<y2) ? (y<=y2) : (y>=y2))
{
if (reverseXY)
CreateWalls(y, x, rx, ry, wall, cBrush);
else
CreateWalls(x, y, rx, ry, wall, cBrush);
}
e -= 1.0f;
}
}
}
void Simulation::CreateWallBox(int x1, int y1, int x2, int y2, int wall)
{
int i, j;
if (x1>x2)
{
i = x2;
x2 = x1;
x1 = i;
}
if (y1>y2)
{
j = y2;
y2 = y1;
y1 = j;
}
for (j=y1; j<=y2; j++)
for (i=x1; i<=x2; i++)
CreateWalls(i, j, 0, 0, wall, NULL);
}
int Simulation::FloodWalls(int x, int y, int wall, int bm)
{
int x1, x2, dy = CELL;
if (bm==-1)
{
if (wall==WL_ERASE || wall==WL_ERASEALL)
{
bm = bmap[y/CELL][x/CELL];
if (!bm)
return 0;
}
else
bm = 0;
}
if (bmap[y/CELL][x/CELL]!=bm)
return 1;
// go left as far as possible
x1 = x2 = x;
while (x1>=CELL)
{
if (bmap[y/CELL][(x1-1)/CELL]!=bm)
{
break;
}
x1--;
}
while (x2<XRES-CELL)
{
if (bmap[y/CELL][(x2+1)/CELL]!=bm)
{
break;
}
x2++;
}
// fill span
for (x=x1; x<=x2; x++)
{
if (!CreateWalls(x, y, 0, 0, wall, NULL))
return 0;
}
// fill children
if (y>=CELL)
for (x=x1; x<=x2; x++)
if (bmap[(y-dy)/CELL][x/CELL]==bm)
if (!FloodWalls(x, y-dy, wall, bm))
return 0;
if (y<YRES-CELL)
for (x=x1; x<=x2; x++)
if (bmap[(y+dy)/CELL][x/CELL]==bm)
if (!FloodWalls(x, y+dy, wall, bm))
return 0;
return 1;
}
int Simulation::CreatePartFlags(int x, int y, int c, int flags)
{
if (x < 0 || y < 0 || x >= XRES || y >= YRES)
{
return 0;
}
if (flags & REPLACE_MODE)
{
// if replace whatever and there's something to replace
// or replace X and there's a non-energy particle on top with type X
// or replace X and there's an energy particle on top with type X
if ((!replaceModeSelected && (photons[y][x] || pmap[y][x])) ||
(!photons[y][x] && pmap[y][x] && TYP(pmap[y][x]) == replaceModeSelected) ||
(photons[y][x] && TYP(photons[y][x]) == replaceModeSelected))
{
if (c)
create_part(photons[y][x] ? ID(photons[y][x]) : ID(pmap[y][x]), x, y, TYP(c), ID(c));
else
delete_part(x, y);
}
return 0;
}
else if (!c)
{
delete_part(x, y);
return 0;
}
else if (flags & SPECIFIC_DELETE)
{
// if delete whatever and there's something to delete
// or delete X and there's a non-energy particle on top with type X
// or delete X and there's an energy particle on top with type X
if ((!replaceModeSelected && (photons[y][x] || pmap[y][x])) ||
(!photons[y][x] && pmap[y][x] && TYP(pmap[y][x]) == replaceModeSelected) ||
(photons[y][x] && TYP(photons[y][x]) == replaceModeSelected))
{
delete_part(x, y);
}
return 0;
}
else
{
return (create_part(-2, x, y, TYP(c), ID(c)) == -1);
}
// I'm sure at least one compiler exists that would complain if this wasn't here
return 0;
}
//Now simply creates a 0 pixel radius line without all the complicated flags / other checks
// Now simply creates a 0 pixel radius line without all the complicated flags / other checks
// Would make sense to move to Editing.cpp but SPRK needs it.
void Simulation::CreateLine(int x1, int y1, int x2, int y2, int c)
{
bool reverseXY = abs(y2-y1) > abs(x2-x1);
@ -1482,42 +1078,6 @@ int Simulation::parts_avg(int ci, int ni,int t)
return PT_NONE;
}
// unused function
void Simulation::create_arc(int sx, int sy, int dx, int dy, int midpoints, int variance, int type, int flags)
{
int i;
float xint, yint;
int *xmid, *ymid;
int voffset = variance/2;
xmid = (int *)calloc(midpoints + 2, sizeof(int));
ymid = (int *)calloc(midpoints + 2, sizeof(int));
xint = (float)(dx-sx)/(float)(midpoints+1.0f);
yint = (float)(dy-sy)/(float)(midpoints+1.0f);
xmid[0] = sx;
xmid[midpoints+1] = dx;
ymid[0] = sy;
ymid[midpoints+1] = dy;
for(i = 1; i <= midpoints; i++)
{
ymid[i] = ymid[i-1]+int(yint);
xmid[i] = xmid[i-1]+int(xint);
}
for(i = 0; i <= midpoints; i++)
{
if(i!=midpoints)
{
xmid[i+1] += RNG::Ref().between(0, variance - 1) - voffset;
ymid[i+1] += RNG::Ref().between(0, variance - 1) - voffset;
}
CreateLine(xmid[i], ymid[i], xmid[i+1], ymid[i+1], type);
}
free(xmid);
free(ymid);
}
void Simulation::clear_sim(void)
{
debug_nextToUpdate = 0;
@ -3903,27 +3463,6 @@ movedone:
framerender--;
}
int Simulation::GetParticleType(ByteString type)
{
type = type.ToUpper();
// alternative names for some elements
if (byteStringEqualsLiteral(type, "C4"))
return PT_PLEX;
else if (byteStringEqualsLiteral(type, "C5"))
return PT_C5;
else if (byteStringEqualsLiteral(type, "NONE"))
return PT_NONE;
for (int i = 1; i < PT_NUM; i++)
{
if (elements[i].Name.size() && elements[i].Enabled && type == elements[i].Name.ToUtf8().ToUpper())
{
return i;
}
}
return -1;
}
void Simulation::RecalcFreeParticles(bool do_life_dec)
{
int x, y, t;

View File

@ -160,7 +160,6 @@ public:
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);
void UpdateParticles(int start, int end); // Dispatches an update to the range [start, end).
void SimulateGoL();
void RecalcFreeParticles(bool do_life_dec);

View File

@ -7,11 +7,8 @@ simulation_files = files(
'Particle.cpp',
'SaveRenderer.cpp',
'Sign.cpp',
'SimTool.cpp',
'SimulationData.cpp',
'ToolClasses.cpp',
'Simulation.cpp',
'SnapshotDelta.cpp',
)
subdir('elements')
@ -22,6 +19,12 @@ render_files += simulation_files
powder_files += files(
'Editing.cpp',
'SimTool.cpp',
'ToolClasses.cpp',
'SnapshotDelta.cpp',
)
render_files += files(
'NoToolClasses.cpp',
)
if enable_gravfft
powder_files += files('FftGravity.cpp')