From ff4849587143c223ad2a884b5f63d0a9bf8a2c18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1ty=C3=A1s=20Mustoha?= Date: Sat, 25 May 2024 18:18:41 +0200 Subject: [PATCH] Cleanup in the moving platform path code --- src/common/MovingPlatformPaths.cpp | 228 +++++++++++--------------- src/common/MovingPlatformPaths.h | 42 ++--- src/common/map.cpp | 36 ++-- src/common/map/MapReader17xx.cpp | 52 +++--- src/common/movingplatform.cpp | 34 ++-- src/leveleditor/leveleditor.cpp | 39 ++--- src/smw/objects/blocks/DonutBlock.cpp | 2 +- 7 files changed, 199 insertions(+), 234 deletions(-) diff --git a/src/common/MovingPlatformPaths.cpp b/src/common/MovingPlatformPaths.cpp index c60312d2..df36e561 100644 --- a/src/common/MovingPlatformPaths.cpp +++ b/src/common/MovingPlatformPaths.cpp @@ -15,34 +15,21 @@ extern std::vector players; // Moving Platform Path base class //------------------------------------------------------------------------------ -MovingPlatformPath::MovingPlatformPath(float vel, float startX, float startY, float endX, float endY, bool preview) +MovingPlatformPath::MovingPlatformPath(float speed, Vec2f startPos, Vec2f endPos, bool preview) + : m_startPos(std::move(startPos)) + , m_endPos(std::move(endPos)) + , m_speed(speed) { - dVelocity = vel; - - for (short type = 0; type < 2; type++) { - dVelX[type] = 0.0f; - dVelY[type] = 0.0f; - } - - dPathPointX[0] = startX; - dPathPointY[0] = startY; - dPathPointX[1] = endX; - dPathPointY[1] = endY; - if (preview) { - dPathPointX[0] /= 2.0f; - dPathPointY[0] /= 2.0f; - dPathPointX[1] /= 2.0f; - dPathPointY[1] /= 2.0f; - dVelocity /= 2.0f; + m_startPos /= 2.f; + m_endPos /= 2.f; + m_speed /= 2.f; } - - pPlatform = NULL; } void MovingPlatformPath::Reset() { - //advance the spawn test platform + // advance the spawn test platform if (game_values.spawnstyle == SpawnStyle::Door) { for (short i = 0; i < 36; i++) Move(1); @@ -57,35 +44,27 @@ void MovingPlatformPath::Reset() // Straight Path //------------------------------------------------------------------------------ -StraightPath::StraightPath(float vel, float startX, float startY, float endX, float endY, bool preview) - : MovingPlatformPath(vel, startX, startY, endX, endY, preview) - , iGoalPoint{0, 0} +StraightPath::StraightPath(float speed, Vec2f startPos, Vec2f endPos, bool preview) + : MovingPlatformPath(speed, std::move(startPos), std::move(endPos), preview) { - float dWidth = dPathPointX[1] - dPathPointX[0]; - float dHeight = dPathPointY[1] - dPathPointY[0]; - float dLength = 0.0f; - - //Lock angle to vertical - if (dWidth == 0) { - if (dHeight > 0) - dAngle = HALF_PI; - else - dAngle = THREE_HALF_PI; - - dLength = fabs(dHeight); - } else if (dHeight == 0) { //Lock angle to horizontal - if (dWidth > 0) - dAngle = 0.0f; - else - dAngle = PI; - - dLength = fabs(dWidth); + float width = m_endPos.x - m_startPos.x; + float height = m_endPos.y - m_startPos.y; + float length = 0.f; + + if (width == 0) { + // Lock angle to vertical + m_angle = (height > 0) ? HALF_PI : THREE_HALF_PI; + length = ::fabs(height); + } else if (height == 0) { + // Lock angle to horizontal + m_angle = (width > 0) ? 0.f : PI; + length = ::fabs(width); } else { - dAngle = atan2(dHeight, dWidth); - dLength = sqrt(dHeight * dHeight + dWidth * dWidth); + m_angle = atan2(height, width); + length = ::sqrt(height * height + width * width); } - iSteps = (short)(dLength / dVelocity) + 1; + m_steps = (short)(length / m_speed) + 1; for (short type = 0; type < 2; type++) SetVelocity(type); @@ -93,17 +72,13 @@ StraightPath::StraightPath(float vel, float startX, float startY, float endX, fl bool StraightPath::Move(short type) { - dCurrentX[type] += dVelX[type]; - dCurrentY[type] += dVelY[type]; - - if (++iOnStep[type] >= iSteps) { - iOnStep[type] = 0; - - dCurrentX[type] = dPathPointX[iGoalPoint[type]]; - dCurrentY[type] = dPathPointY[iGoalPoint[type]]; - - iGoalPoint[type] = 1 - iGoalPoint[type]; + m_currentPos[type] += m_velocity[type]; + m_currentStep[type]++; + if (m_currentStep[type] >= m_steps) { + m_currentStep[type] = 0; + m_currentPos[type] = *m_goalPoint[type]; + m_goalPoint[type] = (m_goalPoint[type] == &m_endPos) ? &m_startPos : &m_endPos; SetVelocity(type); } @@ -112,31 +87,27 @@ bool StraightPath::Move(short type) void StraightPath::SetVelocity(short type) { - if (iGoalPoint[type] == 1) { - dVelX[type] = dVelocity * cos(dAngle); - dVelY[type] = dVelocity * sin(dAngle); - } else { - dVelX[type] = -dVelocity * cos(dAngle); - dVelY[type] = -dVelocity * sin(dAngle); + m_velocity[type].x = m_speed * cos(m_angle); + m_velocity[type].y = m_speed * sin(m_angle); + + if (m_goalPoint[type] == &m_startPos) { + m_velocity[type] *= -1.f; } - //Fix rounding errors - if (dVelX[type] < 0.01f && dVelX[type] > -0.01f) - dVelX[type] = 0.0f; + // Fix rounding errors + if (::fabs(m_velocity[type].x) < 0.01f) + m_velocity[type].x = 0.f; - if (dVelY[type] < 0.01f && dVelY[type] > -0.01f) - dVelY[type] = 0.0f; + if (::fabs(m_velocity[type].y) < 0.01f) + m_velocity[type].y = 0.f; } void StraightPath::Reset() { for (short type = 0; type < 2; type++) { - iOnStep[type] = 0; - - dCurrentX[type] = dPathPointX[0]; - dCurrentY[type] = dPathPointY[0]; - - iGoalPoint[type] = 1; + m_currentStep[type] = 0; + m_currentPos[type] = m_startPos; + m_goalPoint[type] = &m_endPos; SetVelocity(type); } @@ -148,40 +119,37 @@ void StraightPath::Reset() // Straight Path Continuous //------------------------------------------------------------------------------ -StraightPathContinuous::StraightPathContinuous(float vel, float startX, float startY, float angle, bool preview) : - StraightPath(vel, startX, startY, 0.0f, 0.0f, preview) +StraightPathContinuous::StraightPathContinuous(float speed, Vec2f startPos, float angle, bool preview) + : StraightPath(speed, std::move(startPos), Vec2f::zero(), preview) { - dAngle = angle; + m_angle = angle; for (short type = 0; type < 2; type++) { - iGoalPoint[type] = 1; + m_goalPoint[type] = &m_endPos; SetVelocity(type); } - dEdgeX = App::screenWidth; - dEdgeY = App::screenHeight; - + m_edge.x = App::screenWidth; + m_edge.y = App::screenHeight; if (preview) { - dEdgeX = App::screenWidth/2; - dEdgeY = App::screenHeight/2; + m_edge /= 2.f; } } bool StraightPathContinuous::Move(short type) { - dCurrentX[type] += dVelX[type]; - dCurrentY[type] += dVelY[type]; + m_currentPos[type] += m_velocity[type]; - float dx = dCurrentX[type] - (float)pPlatform->iHalfWidth; - if (dx < 0.0f) - dCurrentX[type] += dEdgeX; - else if (dx >= dEdgeX) - dCurrentX[type] -= dEdgeX; + float dx = m_currentPos[type].x - (float)m_platform->iHalfWidth; + if (dx < 0.f) + m_currentPos[type].x += m_edge.x; + else if (dx >= m_edge.x) + m_currentPos[type].x -= m_edge.x; - if (dCurrentY[type] + (float)pPlatform->iHalfHeight < 0.0f) - dCurrentY[type] += dEdgeY + (float)pPlatform->iHeight; - else if (dCurrentY[type] - (float)pPlatform->iHalfHeight >= dEdgeY) - dCurrentY[type] -= dEdgeY + (float)pPlatform->iHeight; + if (m_currentPos[type].y + (float)m_platform->iHalfHeight < 0.f) + m_currentPos[type].y += m_edge.y + (float)m_platform->iHeight; + else if (m_currentPos[type].y - (float)m_platform->iHalfHeight >= m_edge.y) + m_currentPos[type].y -= m_edge.y + (float)m_platform->iHeight; return false; } @@ -189,8 +157,7 @@ bool StraightPathContinuous::Move(short type) void StraightPathContinuous::Reset() { for (short type = 0; type < 2; type++) { - dCurrentX[type] = dPathPointX[0]; - dCurrentY[type] = dPathPointY[0]; + m_currentPos[type] = m_startPos; } MovingPlatformPath::Reset(); @@ -199,59 +166,53 @@ void StraightPathContinuous::Reset() //------------------------------------------------------------------------------ // Ellipse Path //------------------------------------------------------------------------------ -EllipsePath::EllipsePath(float vel, float angle, float radiusx, float radiusy, float centerx, float centery, bool preview) : - MovingPlatformPath(vel, centerx, centery, 0.0f, 0.0f, preview) +EllipsePath::EllipsePath(float speed, float angle, Vec2f radius, Vec2f centerPos, bool preview) + : MovingPlatformPath(speed, std::move(centerPos), Vec2f::zero(), preview) + , m_radius(std::move(radius)) + , m_startAngle(angle) { - dStartAngle = angle; - if (preview) { - dRadiusX = radiusx / 2.0f; - dRadiusY = radiusy / 2.0f; - dVelocity *= 2.0f; - } else { - dRadiusX = radiusx; - dRadiusY = radiusy; + m_radius /= 2.f; + m_speed *= 2.f; } for (short type = 0; type < 2; type++) { - dAngle[type] = angle; + m_angle[type] = m_startAngle; SetPosition(type); } } bool EllipsePath::Move(short type) { - float dOldCurrentX = dCurrentX[type]; - float dOldCurrentY = dCurrentY[type]; + Vec2f oldPos = m_currentPos[type]; - dAngle[type] += dVelocity; + m_angle[type] += m_speed; - if (dVelocity < 0.0f) { - while (dAngle[type] < 0.0f) - dAngle[type] += TWO_PI; + if (m_speed < 0.f) { + while (m_angle[type] < 0.f) + m_angle[type] += TWO_PI; } else { - while (dAngle[type] >= TWO_PI) - dAngle[type] -= TWO_PI; + while (m_angle[type] >= TWO_PI) + m_angle[type] -= TWO_PI; } SetPosition(type); - dVelX[type] = dCurrentX[type] - dOldCurrentX; - dVelY[type] = dCurrentY[type] - dOldCurrentY; + m_velocity[type] = m_currentPos[type] - oldPos; return false; } void EllipsePath::SetPosition(short type) { - dCurrentX[type] = dRadiusX * cos(dAngle[type]) + dPathPointX[0]; - dCurrentY[type] = dRadiusY * sin(dAngle[type]) + dPathPointY[0]; + m_currentPos[type].x = m_radius.x * cos(m_angle[type]) + m_startPos.x; + m_currentPos[type].y = m_radius.y * sin(m_angle[type]) + m_startPos.y; } void EllipsePath::Reset() { for (short type = 0; type < 2; type++) { - dAngle[type] = dStartAngle; + m_angle[type] = m_startAngle; SetPosition(type); } @@ -262,27 +223,27 @@ void EllipsePath::Reset() // Falling path (for falling donut blocks) //------------------------------------------------------------------------------ -FallingPath::FallingPath(float startX, float startY) : - MovingPlatformPath(0.0f, startX, startY, 0.0f, 0.0f, false) +FallingPath::FallingPath(Vec2f startPos) + : MovingPlatformPath(0.f, std::move(startPos), Vec2f::zero(), false) {} bool FallingPath::Move(short type) { - dVelY[type] = CapFallingVelocity(dVelY[type] + GRAVITATION); + m_velocity[type].y = CapFallingVelocity(m_velocity[type].y + GRAVITATION); - if (pPlatform->fy - pPlatform->iHalfHeight >= App::screenHeight) { - //If a player is standing on this platform, clear him off + if (m_platform->fy - m_platform->iHalfHeight >= App::screenHeight) { + // If a player is standing on this platform, clear him off for (CPlayer* player : players) { - if (player->platform == pPlatform) { - player->platform = NULL; - player->vely = dVelY[type]; + if (player->platform == m_platform) { + player->platform = nullptr; + player->vely = m_velocity[type].y; } } - pPlatform->fDead = true; + m_platform->fDead = true; } - dCurrentY[type] += dVelY[type]; + m_currentPos[type].y += m_velocity[type].y; return false; } @@ -290,11 +251,10 @@ bool FallingPath::Move(short type) void FallingPath::Reset() { for (short type = 0; type < 2; type++) { - dCurrentX[type] = dPathPointX[0]; - dCurrentY[type] = dPathPointY[0]; + m_currentPos[type] = m_startPos; } - //Skip correctly setting the path "shadow" as a perf optimization - //This does have the risk of a player spawning inside a falling donut block by accident - //MovingPlatformPath::Reset(); + // Skip correctly setting the path "shadow" as a perf optimization + // This does have the risk of a player spawning inside a falling donut block by accident + // MovingPlatformPath::Reset(); } diff --git a/src/common/MovingPlatformPaths.h b/src/common/MovingPlatformPaths.h index c9534a8f..c89407d9 100644 --- a/src/common/MovingPlatformPaths.h +++ b/src/common/MovingPlatformPaths.h @@ -1,5 +1,7 @@ #pragma once +#include "math/Vec2.h" + class MovingPlatform; @@ -14,7 +16,7 @@ enum class PlatformPathType: unsigned char { class MovingPlatformPath { public: - MovingPlatformPath(float vel, float startX, float startY, float endX, float endY, bool preview); + MovingPlatformPath(float speed, Vec2f startPos, Vec2f endPos, bool preview); virtual ~MovingPlatformPath() = default; virtual PlatformPathType typeId() const = 0; @@ -22,18 +24,18 @@ class MovingPlatformPath { virtual void Reset(); void SetPlatform(MovingPlatform* platform) { - pPlatform = platform; + m_platform = platform; } protected: - MovingPlatform* pPlatform; - - float dVelocity; - float dVelX[2], dVelY[2]; + MovingPlatform* m_platform = nullptr; - float dPathPointX[2], dPathPointY[2]; + float m_speed; + Vec2f m_startPos; + Vec2f m_endPos; - float dCurrentX[2], dCurrentY[2]; + Vec2f m_velocity[2]; + Vec2f m_currentPos[2]; friend class MovingPlatform; friend class CMap; @@ -44,7 +46,7 @@ class MovingPlatformPath { class StraightPath : public MovingPlatformPath { public: - StraightPath(float vel, float startX, float startY, float endX, float endY, bool preview); + StraightPath(float speed, Vec2f startPos, Vec2f endPos, bool preview); PlatformPathType typeId() const override { return PlatformPathType::Straight; } bool Move(short type) override; @@ -53,11 +55,11 @@ class StraightPath : public MovingPlatformPath { protected: void SetVelocity(short type); - short iOnStep[2]; - short iSteps; - short iGoalPoint[2]; + float m_angle; + short m_steps; - float dAngle; + unsigned short m_currentStep[2] = {0, 0}; + Vec2f* m_goalPoint[2] = {&m_startPos, &m_startPos}; friend class MovingPlatform; friend class CMap; @@ -68,14 +70,14 @@ class StraightPath : public MovingPlatformPath { class StraightPathContinuous : public StraightPath { public: - StraightPathContinuous(float vel, float startX, float startY, float angle, bool preview); + StraightPathContinuous(float speed, Vec2f startPos, float angle, bool preview); PlatformPathType typeId() const override { return PlatformPathType::StraightContinuous; } bool Move(short type) override; void Reset() override; private: - float dEdgeX, dEdgeY; + Vec2f m_edge; friend class MovingPlatform; friend class CMap; @@ -86,7 +88,7 @@ class StraightPathContinuous : public StraightPath { class EllipsePath : public MovingPlatformPath { public: - EllipsePath(float vel, float dAngle, float dRadiusX, float dRadiusY, float dCenterX, float dCenterY, bool preview); + EllipsePath(float speed, float dAngle, Vec2f radius, Vec2f centerPos, bool preview); PlatformPathType typeId() const override { return PlatformPathType::Ellipse; } bool Move(short type) override; @@ -94,8 +96,10 @@ class EllipsePath : public MovingPlatformPath { void Reset() override; private: - float dRadiusX, dRadiusY; - float dAngle[2], dStartAngle; + Vec2f m_radius; + float m_startAngle; + + float m_angle[2]; friend class MovingPlatform; friend class CMap; @@ -106,7 +110,7 @@ class EllipsePath : public MovingPlatformPath { class FallingPath : public MovingPlatformPath { public: - FallingPath(float startX, float startY); + FallingPath(Vec2f startPos); PlatformPathType typeId() const override { return PlatformPathType::Falling; } bool Move(short type) override; diff --git a/src/common/map.cpp b/src/common/map.cpp index 031a9a6f..f77ed06d 100644 --- a/src/common/map.cpp +++ b/src/common/map.cpp @@ -995,23 +995,23 @@ void CMap::saveMap(const std::string& file) mapfile.write_i32(iPathType); if (auto* path = dynamic_cast(platforms[iPlatform]->pPath)) { - mapfile.write_float(path->dPathPointX[0]); - mapfile.write_float(path->dPathPointY[0]); - mapfile.write_float(path->dPathPointX[1]); - mapfile.write_float(path->dPathPointY[1]); - mapfile.write_float(path->dVelocity); + mapfile.write_float(path->m_startPos.x); + mapfile.write_float(path->m_startPos.y); + mapfile.write_float(path->m_endPos.x); + mapfile.write_float(path->m_endPos.y); + mapfile.write_float(path->m_speed); } else if (auto* path = dynamic_cast(platforms[iPlatform]->pPath)) { - mapfile.write_float(path->dPathPointX[0]); - mapfile.write_float(path->dPathPointY[0]); - mapfile.write_float(path->dAngle); - mapfile.write_float(path->dVelocity); + mapfile.write_float(path->m_startPos.x); + mapfile.write_float(path->m_startPos.y); + mapfile.write_float(path->m_angle); + mapfile.write_float(path->m_speed); } else if (auto* path = dynamic_cast(platforms[iPlatform]->pPath)) { - mapfile.write_float(path->dRadiusX); - mapfile.write_float(path->dRadiusY); - mapfile.write_float(path->dPathPointX[0]); - mapfile.write_float(path->dPathPointY[0]); - mapfile.write_float(path->dAngle[0]); - mapfile.write_float(path->dVelocity); + mapfile.write_float(path->m_radius.x); + mapfile.write_float(path->m_radius.y); + mapfile.write_float(path->m_startPos.x); + mapfile.write_float(path->m_startPos.y); + mapfile.write_float(path->m_angle[0]); + mapfile.write_float(path->m_speed); } } @@ -1753,11 +1753,11 @@ void CMap::drawThumbnailPlatforms(SDL_Surface * targetSurface) MovingPlatformPath * basepath = platform->pPath; if (auto* path = dynamic_cast(basepath)) { - DrawPlatform(path->typeId(), platform->iTileData, ((short)path->dPathPointX[0]) << 1, ((short)path->dPathPointY[0]) << 1, ((short)path->dPathPointX[1]) << 1, ((short)path->dPathPointY[1]) << 1, 0.0f, 0.0f, 0.0f, 2, platform->iTileWidth, platform->iTileHeight, true, true); + DrawPlatform(path->typeId(), platform->iTileData, path->m_startPos.x * 2.f, path->m_startPos.y * 2.f, path->m_endPos.x * 2.f, path->m_endPos.y * 2.f, 0.0f, 0.0f, 0.0f, 2, platform->iTileWidth, platform->iTileHeight, true, true); } else if (auto* path = dynamic_cast(basepath)) { - DrawPlatform(path->typeId(), platform->iTileData, ((short)path->dPathPointX[0]) << 1, ((short)path->dPathPointY[0]) << 1, 0, 0, path->dAngle, 0.0f, 0.0f, 2, platform->iTileWidth, platform->iTileHeight, true, true); + DrawPlatform(path->typeId(), platform->iTileData, path->m_startPos.x * 2.f, path->m_startPos.y * 2.f, 0, 0, path->m_angle, 0.0f, 0.0f, 2, platform->iTileWidth, platform->iTileHeight, true, true); } else if (auto* path = dynamic_cast(basepath)) { - DrawPlatform(path->typeId(), platform->iTileData, ((short)path->dPathPointX[0]) << 1, ((short)path->dPathPointY[0]) << 1, 0, 0, path->dStartAngle, path->dRadiusX * 2, path->dRadiusY * 2, 2, platform->iTileWidth, platform->iTileHeight, true, true); + DrawPlatform(path->typeId(), platform->iTileData, path->m_startPos.x * 2.f, path->m_startPos.y * 2.f, 0, 0, path->m_startAngle, path->m_radius.x * 2, path->m_radius.y * 2, 2, platform->iTileWidth, platform->iTileHeight, true, true); } } diff --git a/src/common/map/MapReader17xx.cpp b/src/common/map/MapReader17xx.cpp index a3926286..971e44d6 100644 --- a/src/common/map/MapReader17xx.cpp +++ b/src/common/map/MapReader17xx.cpp @@ -302,43 +302,43 @@ void MapReader1700::read_platform_tiles(CMap& map, BinaryFile& mapfile, MovingPlatformPath* MapReader1700::read_platform_path_details(BinaryFile& mapfile, short iPathType, bool fPreview) { - MovingPlatformPath* path = NULL; if (iPathType == 0) { //segment path - float fStartX = mapfile.read_float(); - float fStartY = mapfile.read_float(); - float fEndX = mapfile.read_float(); - float fEndY = mapfile.read_float(); - float fVelocity = mapfile.read_float(); + float startX = mapfile.read_float(); + float startY = mapfile.read_float(); + float endX = mapfile.read_float(); + float endY = mapfile.read_float(); + float speed = mapfile.read_float(); - path = new StraightPath(fVelocity, fStartX, fStartY, fEndX, fEndY, fPreview); + return new StraightPath(speed, Vec2f(startX, startY), Vec2f(endX, endY), fPreview); //printf("Read segment path\n"); - //printf("StartX: %.2f StartY:%.2f EndX:%.2f EndY:%.2f Velocity:%.2f\n", fStartX, fStartY, fEndX, fEndY, fVelocity); - } else if (iPathType == 1) { //continuous path - float fStartX = mapfile.read_float(); - float fStartY = mapfile.read_float(); - float fAngle = mapfile.read_float(); - float fVelocity = mapfile.read_float(); + //printf("StartX: %.2f StartY:%.2f EndX:%.2f EndY:%.2f Velocity:%.2f\n", startX, startY, endX, endY, speed); + } + if (iPathType == 1) { //continuous path + float startX = mapfile.read_float(); + float startY = mapfile.read_float(); + float angle = mapfile.read_float(); + float speed = mapfile.read_float(); - path = new StraightPathContinuous(fVelocity, fStartX, fStartY, fAngle, fPreview); + return new StraightPathContinuous(speed, Vec2f(startX, startY), angle, fPreview); //printf("Read continuous path\n"); - //printf("StartX: %.2f StartY:%.2f Angle:%.2f Velocity:%.2f\n", fStartX, fStartY, fAngle, fVelocity); - } else if (iPathType == 2) { //elliptical path - float fRadiusX = mapfile.read_float(); - float fRadiusY = mapfile.read_float(); - float fCenterX = mapfile.read_float(); - float fCenterY = mapfile.read_float(); - float fAngle = mapfile.read_float(); - float fVelocity = mapfile.read_float(); + //printf("StartX: %.2f StartY:%.2f Angle:%.2f Velocity:%.2f\n", startX, startY, angle, speed); + } + if (iPathType == 2) { //elliptical path + float radiusX = mapfile.read_float(); + float radiusY = mapfile.read_float(); + float centerX = mapfile.read_float(); + float centerY = mapfile.read_float(); + float angle = mapfile.read_float(); + float speed = mapfile.read_float(); - path = new EllipsePath(fVelocity, fAngle, fRadiusX, fRadiusY, fCenterX, fCenterY, fPreview); + return new EllipsePath(speed, angle, Vec2f(radiusX, radiusY), Vec2f(centerX, centerY), fPreview); //printf("Read elliptical path\n"); - //printf("CenterX: %.2f CenterY:%.2f Angle:%.2f RadiusX: %.2f RadiusY: %.2f Velocity:%.2f\n", fCenterX, fCenterY, fAngle, fRadiusX, fRadiusY, fVelocity); + //printf("CenterX: %.2f CenterY:%.2f Angle:%.2f RadiusX: %.2f RadiusY: %.2f Velocity:%.2f\n", centerX, centerY, angle, radiusX, radiusY, speed); } - - return path; + return nullptr; } bool MapReader1700::load(CMap& map, BinaryFile& mapfile, ReadType readtype) diff --git a/src/common/movingplatform.cpp b/src/common/movingplatform.cpp index 8f96d483..05364e41 100644 --- a/src/common/movingplatform.cpp +++ b/src/common/movingplatform.cpp @@ -106,8 +106,8 @@ MovingPlatform::MovingPlatform(TilesetTile ** tiledata, MapTile ** tiletypes, sh rDstRect.w = w * iTileSize; rDstRect.h = h * iTileSize; - fVelX = pPath->dVelX[0]; - fVelY = pPath->dVelY[0]; + fVelX = pPath->m_velocity[0].x; + fVelY = pPath->m_velocity[0].y; fOldVelX = fVelX; fOldVelY = fVelY; @@ -132,7 +132,7 @@ MovingPlatform::~MovingPlatform() void MovingPlatform::draw() { //Comment this back in to see the no spawn area of the platform - //SDL_Rect r = {(int)pPath->dCurrentX[1] - iHalfWidth, (int)pPath->dCurrentY[1] - iHalfHeight, iWidth, iHeight}; + //SDL_Rect r = {(int)pPath->m_currentPos[1].x - iHalfWidth, (int)pPath->m_currentPos[1].y - iHalfHeight, iWidth, iHeight}; //SDL_FillRect(blitdest, &r, SDL_MapRGB(blitdest->format, 0, 0, 255)); rDstRect.x = ix - iHalfWidth + x_shake; @@ -237,11 +237,11 @@ void MovingPlatform::draw(short iOffsetX, short iOffsetY) void MovingPlatform::update() { - fOldX = pPath->dCurrentX[0]; - fOldY = pPath->dCurrentY[0]; + fOldX = pPath->m_currentPos[0].x; + fOldY = pPath->m_currentPos[0].y; - fOldVelX = pPath->dVelX[0]; - fOldVelY = pPath->dVelY[0]; + fOldVelX = pPath->m_velocity[0].x; + fOldVelY = pPath->m_velocity[0].y; //Path will affect new fVelX and fVelY to move the platform to it's next location pPath->Move(0); @@ -249,19 +249,19 @@ void MovingPlatform::update() //Will move the path "shadow" to the next location (for spawn collision detection) pPath->Move(1); - fVelX = pPath->dVelX[0]; - fVelY = pPath->dVelY[0]; + fVelX = pPath->m_velocity[0].x; + fVelY = pPath->m_velocity[0].y; - setXf(pPath->dCurrentX[0]); - setYf(pPath->dCurrentY[0]); + setXf(pPath->m_currentPos[0].x); + setYf(pPath->m_currentPos[0].y); } void MovingPlatform::ResetPath() { pPath->Reset(); - setXf(pPath->dCurrentX[0]); - setYf(pPath->dCurrentY[0]); + setXf(pPath->m_currentPos[0].x); + setYf(pPath->m_currentPos[0].y); fOldX = fx; fOldY = fy; @@ -1365,18 +1365,18 @@ short MovingPlatform::coldec_object(IO_MovingObject * object) bool MovingPlatform::IsInNoSpawnZone(short iX, short iY, short w, short h) { - short iTop = (short)pPath->dCurrentY[1] - iHalfHeight; + short iTop = (short)pPath->m_currentPos[1].y - iHalfHeight; if (iY + h < iTop) return false; - short iBottom = (short)pPath->dCurrentY[1] + iHalfHeight; + short iBottom = (short)pPath->m_currentPos[1].y + iHalfHeight; if (iY >= iBottom) return false; - short iLeft = (short)pPath->dCurrentX[1] - iHalfWidth; - short iRight = (short)pPath->dCurrentX[1] + iHalfWidth; + short iLeft = (short)pPath->m_currentPos[1].x - iHalfWidth; + short iRight = (short)pPath->m_currentPos[1].x + iHalfWidth; //Deal with screen side overlap if (iX + w < iLeft) diff --git a/src/leveleditor/leveleditor.cpp b/src/leveleditor/leveleditor.cpp index abc48734..562b9dda 100644 --- a/src/leveleditor/leveleditor.cpp +++ b/src/leveleditor/leveleditor.cpp @@ -4861,23 +4861,23 @@ void loadcurrentmap() g_Platforms[iPlatform].iPathType = g_map->platforms[iPlatform]->pPath->typeId(); if (auto* path = dynamic_cast(g_map->platforms[iPlatform]->pPath)) { - g_Platforms[iPlatform].iVelocity = (int)(path->dVelocity * 4.0f); - g_Platforms[iPlatform].iStartX = (int)(path->dPathPointX[0]); - g_Platforms[iPlatform].iStartY = (int)(path->dPathPointY[0]); - g_Platforms[iPlatform].iEndX = (int)(path->dPathPointX[1]); - g_Platforms[iPlatform].iEndY = (int)(path->dPathPointY[1]); + g_Platforms[iPlatform].iVelocity = (int)(path->m_speed * 4.0f); + g_Platforms[iPlatform].iStartX = (int)(path->m_startPos.x); + g_Platforms[iPlatform].iStartY = (int)(path->m_startPos.y); + g_Platforms[iPlatform].iEndX = (int)(path->m_endPos.x); + g_Platforms[iPlatform].iEndY = (int)(path->m_endPos.y); } else if (auto* path = dynamic_cast(g_map->platforms[iPlatform]->pPath)) { - g_Platforms[iPlatform].iVelocity = (int)(path->dVelocity * 4.0f); - g_Platforms[iPlatform].iStartX = (int)(path->dPathPointX[0]); - g_Platforms[iPlatform].iStartY = (int)(path->dPathPointY[0]); - g_Platforms[iPlatform].fAngle = path->dAngle; + g_Platforms[iPlatform].iVelocity = (int)(path->m_speed * 4.0f); + g_Platforms[iPlatform].iStartX = (int)(path->m_startPos.x); + g_Platforms[iPlatform].iStartY = (int)(path->m_startPos.y); + g_Platforms[iPlatform].fAngle = path->m_angle; } else if (auto* path = dynamic_cast(g_map->platforms[iPlatform]->pPath)) { - g_Platforms[iPlatform].iVelocity = (short)(path->dVelocity / 0.0030f); - g_Platforms[iPlatform].fRadiusX = path->dRadiusX; - g_Platforms[iPlatform].fRadiusY = path->dRadiusY; - g_Platforms[iPlatform].iStartX = (int)(path->dPathPointX[0]); - g_Platforms[iPlatform].iStartY = (int)(path->dPathPointY[0]); - g_Platforms[iPlatform].fAngle = path->dStartAngle; + g_Platforms[iPlatform].iVelocity = (short)(path->m_speed / 0.0030f); + g_Platforms[iPlatform].fRadiusX = path->m_radius.x; + g_Platforms[iPlatform].fRadiusY = path->m_radius.y; + g_Platforms[iPlatform].iStartX = (int)(path->m_startPos.x); + g_Platforms[iPlatform].iStartY = (int)(path->m_startPos.y); + g_Platforms[iPlatform].fAngle = path->m_startAngle; } g_Platforms[iPlatform].UpdatePreview(); @@ -4954,14 +4954,15 @@ void insert_platforms_into_map() float fVelocity = (float)g_Platforms[iPlatform].iVelocity * 0.26f; float fEndX = (float)(g_Platforms[iPlatform].iEndX); float fEndY = (float)(g_Platforms[iPlatform].iEndY); - - path = new StraightPath(fVelocity, fStartX, fStartY, fEndX, fEndY, false); + path = new StraightPath(fVelocity, Vec2f(fStartX, fStartY), Vec2f(fEndX, fEndY), false); } else if (g_Platforms[iPlatform].iPathType == PlatformPathType::StraightContinuous) { float fVelocity = (float)g_Platforms[iPlatform].iVelocity * 0.26f; - path = new StraightPathContinuous(fVelocity, fStartX, fStartY, g_Platforms[iPlatform].fAngle, false); + path = new StraightPathContinuous(fVelocity, Vec2f(fStartX, fStartY), g_Platforms[iPlatform].fAngle, false); } else if (g_Platforms[iPlatform].iPathType == PlatformPathType::Ellipse) { float fVelocity = (float)g_Platforms[iPlatform].iVelocity * 0.0030f; - path = new EllipsePath(fVelocity, g_Platforms[iPlatform].fAngle, g_Platforms[iPlatform].fRadiusX, g_Platforms[iPlatform].fRadiusY, fStartX, fStartY, false); + float radiusX = g_Platforms[iPlatform].fRadiusX; + float radiusY = g_Platforms[iPlatform].fRadiusY; + path = new EllipsePath(fVelocity, g_Platforms[iPlatform].fAngle, Vec2f(radiusX, radiusY), Vec2f(fStartX, fStartY), false); } g_map->AddPermanentPlatform(new MovingPlatform(tiles, types, iWidth, iHeight, iDrawLayer, path, false)); diff --git a/src/smw/objects/blocks/DonutBlock.cpp b/src/smw/objects/blocks/DonutBlock.cpp index 9e87d8cc..8774bdaa 100644 --- a/src/smw/objects/blocks/DonutBlock.cpp +++ b/src/smw/objects/blocks/DonutBlock.cpp @@ -73,7 +73,7 @@ void B_DonutBlock::triggerBehavior(short iPlayerId) typedata[0][0].iType = tile_solid; typedata[0][0].iFlags = tile_flag_solid; - MovingPlatformPath * path = new FallingPath((float)ix + 16.0f, (float)iy + 15.8f); + MovingPlatformPath * path = new FallingPath(Vec2f((float)ix + 16.0f, (float)iy + 15.8f)); MovingPlatform * platform = new MovingPlatform(tiledata, typedata, 1, 1, 2, path, false); platform->SetPlayerId(iPlayerId);