Fix PIPE/PPIP breakage on rotation (fixes #750)

This commit is contained in:
Tamás Bálint Misius 2020-12-15 21:40:15 +01:00
parent 01fe90f73b
commit e9bed49906
No known key found for this signature in database
GPG Key ID: 5B472A12F6ECA9F2
2 changed files with 21 additions and 2 deletions

View File

@ -409,6 +409,10 @@ void GameSave::Transform(matrix2d transform, vector2d translate, vector2d transl
velocityYNew = Allocate2DArray<float>(newBlockWidth, newBlockHeight, 0.0f);
ambientHeatNew = Allocate2DArray<float>(newBlockWidth, newBlockHeight, 0.0f);
// * Patch pipes if the transform is (looks close enough to) a 90-degree counter-clockwise rotation.
bool patchPipe90 = fabsf(transform.a * transform.d - transform.b * transform.c - 1) < 1e-3 && fabs(atan2f(transform.b, transform.a) - (0.5f * M_PI)) < 1e-3;
// rotate and translate signs, parts, walls
for (size_t i = 0; i < signs.size(); i++)
{
@ -442,6 +446,11 @@ void GameSave::Transform(matrix2d transform, vector2d translate, vector2d transl
vel = m2d_multiply_v2d(transform, vel);
particles[i].vx = vel.x;
particles[i].vy = vel.y;
if (patchPipe90 && (particles[i].type == PT_PIPE || particles[i].type == PT_PPIP))
{
void Element_PIPE_patch90(Particle &part);
Element_PIPE_patch90(particles[i]);
}
}
// translate walls and other grid items when the stamp is shifted more than 4 pixels in any direction

View File

@ -81,8 +81,18 @@ constexpr int PPIP_TMPFLAG_TRIGGER_OFF = 0x08000000;
constexpr int PPIP_TMPFLAG_TRIGGER_ON = 0x10000000;
constexpr int PPIP_TMPFLAG_TRIGGERS = 0x1C000000;
signed char pos_1_rx[] = {-1,-1,-1, 0, 0, 1, 1, 1};
signed char pos_1_ry[] = {-1, 0, 1,-1, 1,-1, 0, 1};
signed char pos_1_rx[] = { -1,-1,-1, 0, 0, 1, 1, 1 };
signed char pos_1_ry[] = { -1, 0, 1,-1, 1,-1, 0, 1 };
int pos_1_patch90[] = { 2, 4, 7, 1, 6, 0, 3, 5 };
void Element_PIPE_patch90(Particle &part)
{
auto oldDirForward = (part.tmp & 0x00001C00) >> 10;
auto newDirForward = pos_1_patch90[oldDirForward];
auto oldDirReverse = (part.tmp & 0x0001C000) >> 14;
auto newDirReverse = pos_1_patch90[oldDirReverse];
part.tmp = (part.tmp & 0xFFFE23FF) | (newDirForward << 10) | (newDirReverse << 14);
}
static unsigned int prevColor(unsigned int flags)
{