mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-03-21 06:40:02 +01:00
translate wall grids when shifting stamps by more than 4 pixels
This commit is contained in:
parent
4ff0a9f52c
commit
97c4123533
@ -162,6 +162,7 @@ void GameSave::InitVars()
|
||||
gravityMode = 0;
|
||||
airMode = 0;
|
||||
edgeMode = 0;
|
||||
translated.x = translated.y = 0;
|
||||
}
|
||||
|
||||
bool GameSave::Collapsed()
|
||||
@ -266,6 +267,7 @@ vector2d GameSave::Translate(vector2d translate)
|
||||
Expand();
|
||||
int nx, ny;
|
||||
vector2d pos;
|
||||
vector2d translateReal = translate;
|
||||
float minx = 0, miny = 0, maxx = 0, maxy = 0;
|
||||
// determine minimum and maximum position of all particles / signs
|
||||
for (size_t i = 0; i < signs.size(); i++)
|
||||
@ -320,24 +322,25 @@ vector2d GameSave::Translate(vector2d translate)
|
||||
|
||||
// call Transform to do the transformation we wanted when calling this function
|
||||
translate = v2d_add(translate, v2d_multiply_float(backCorrection, CELL));
|
||||
Transform(m2d_identity, translate,
|
||||
(blockWidth + backCorrection.x + frontCorrection.x) * CELL,
|
||||
(blockHeight + backCorrection.y + frontCorrection.y) * CELL
|
||||
Transform(m2d_identity, translate, translateReal,
|
||||
(blockWidth + backCorrection.x + frontCorrection.x) * CELL,
|
||||
(blockHeight + backCorrection.y + frontCorrection.y) * CELL
|
||||
);
|
||||
|
||||
// return how much we corrected. This is used to offset the position of the current stamp
|
||||
// otherwise it would attempt to recenter it with the current height
|
||||
// otherwise it would attempt to recenter it with the current size
|
||||
return v2d_add(v2d_multiply_float(backCorrection, -CELL), v2d_multiply_float(frontCorrection, CELL));
|
||||
}
|
||||
|
||||
void GameSave::Transform(matrix2d transform, vector2d translate)
|
||||
{
|
||||
if(Collapsed())
|
||||
if (Collapsed())
|
||||
Expand();
|
||||
|
||||
int width = blockWidth*CELL, height = blockHeight*CELL, newWidth, newHeight;
|
||||
vector2d tmp, ctl, cbr;
|
||||
vector2d cornerso[4];
|
||||
vector2d translateReal = translate;
|
||||
// undo any translation caused by rotation
|
||||
cornerso[0] = v2d_new(0,0);
|
||||
cornerso[1] = v2d_new(width-1,0);
|
||||
@ -357,12 +360,15 @@ void GameSave::Transform(matrix2d transform, vector2d translate)
|
||||
translate = v2d_sub(translate,tmp);
|
||||
newWidth = floor(cbr.x+0.5f)-floor(ctl.x+0.5f)+1;
|
||||
newHeight = floor(cbr.y+0.5f)-floor(ctl.y+0.5f)+1;
|
||||
Transform(transform, translate, newWidth, newHeight);
|
||||
Transform(transform, translate, translateReal, newWidth, newHeight);
|
||||
}
|
||||
|
||||
void GameSave::Transform(matrix2d transform, vector2d translate, int newWidth, int newHeight)
|
||||
// transform is a matrix describing how we want to rotate this save
|
||||
// translate can vary depending on whether the save is bring rotated, or if a normal translate caused it to expand
|
||||
// translateReal is the original amount we tried to translate, used to calculate wall shifting
|
||||
void GameSave::Transform(matrix2d transform, vector2d translate, vector2d translateReal, int newWidth, int newHeight)
|
||||
{
|
||||
if(Collapsed())
|
||||
if (Collapsed())
|
||||
Expand();
|
||||
|
||||
if (newWidth>XRES) newWidth = XRES;
|
||||
@ -416,14 +422,30 @@ void GameSave::Transform(matrix2d transform, vector2d translate, int newWidth, i
|
||||
particles[i].vx = vel.x;
|
||||
particles[i].vy = vel.y;
|
||||
}
|
||||
|
||||
// translate walls and other grid items when the stamp is shifted more than 4 pixels in any direction
|
||||
int translateX = 0, translateY = 0;
|
||||
if (translateReal.x > 0 && ((int)translated.x%CELL == 3
|
||||
|| (translated.x < 0 && (int)translated.x%CELL == 0)))
|
||||
translateX = CELL;
|
||||
else if (translateReal.x < 0 && ((int)translated.x%CELL == -3
|
||||
|| (translated.x > 0 && (int)translated.x%CELL == 0)))
|
||||
translateX = -CELL;
|
||||
if (translateReal.y > 0 && ((int)translated.y%CELL == 3
|
||||
|| (translated.y < 0 && (int)translated.y%CELL == 0)))
|
||||
translateY = CELL;
|
||||
else if (translateReal.y < 0 && ((int)translated.y%CELL == -3
|
||||
|| (translated.y > 0 && (int)translated.y%CELL == 0)))
|
||||
translateY = -CELL;
|
||||
|
||||
for (y=0; y<blockHeight; y++)
|
||||
for (x=0; x<blockWidth; x++)
|
||||
{
|
||||
pos = v2d_new(x*CELL+CELL*0.4f, y*CELL+CELL*0.4f);
|
||||
pos = v2d_new(x*CELL+CELL*0.4f+translateX, y*CELL+CELL*0.4f+translateY);
|
||||
pos = v2d_add(m2d_multiply_v2d(transform,pos),translate);
|
||||
nx = pos.x/CELL;
|
||||
ny = pos.y/CELL;
|
||||
if (nx<0 || nx>=newBlockWidth || ny<0 || ny>=newBlockHeight)
|
||||
if (pos.x<0 || nx>=newBlockWidth || pos.y<0 || ny>=newBlockHeight)
|
||||
continue;
|
||||
if (blockMap[y][x])
|
||||
{
|
||||
@ -441,6 +463,7 @@ void GameSave::Transform(matrix2d transform, vector2d translate, int newWidth, i
|
||||
velocityYNew[ny][nx] = velocityY[y][x];
|
||||
ambientHeatNew[ny][nx] = ambientHeat[y][x];
|
||||
}
|
||||
translated = v2d_add(m2d_multiply_v2d(transform, translated), translateReal);
|
||||
|
||||
for (int j = 0; j < blockHeight; j++)
|
||||
{
|
||||
|
@ -78,7 +78,7 @@ public:
|
||||
std::vector<char> Serialise();
|
||||
vector2d Translate(vector2d translate);
|
||||
void Transform(matrix2d transform, vector2d translate);
|
||||
void Transform(matrix2d transform, vector2d translate, int newWidth, int newHeight);
|
||||
void Transform(matrix2d transform, vector2d translate, vector2d translateReal, int newWidth, int newHeight);
|
||||
|
||||
void Expand();
|
||||
void Collapse();
|
||||
@ -103,6 +103,8 @@ public:
|
||||
private:
|
||||
bool expanded;
|
||||
bool hasOriginalData;
|
||||
// number of pixels translated. When translating CELL pixels, shift all CELL grids
|
||||
vector2d translated;
|
||||
|
||||
std::vector<char> originalData;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user