Browse Source

Remove redundant code

pull/7046/head^2
KPhoenix 2 years ago committed by Anders Jenbo
parent
commit
21df8d6703
  1. 22
      Source/engine/actor_position.cpp
  2. 47
      Source/monster.cpp
  3. 21
      Source/player.cpp

22
Source/engine/actor_position.cpp

@ -75,7 +75,6 @@ constexpr RoundedWalkVelocity WalkVelocityForFrames[24] = {
};
struct WalkParameter {
DisplacementOf<int16_t> startingOffset;
VelocityToUse VelocityX;
VelocityToUse VelocityY;
DisplacementOf<int16_t> getVelocity(int8_t numberOfFrames) const
@ -91,15 +90,15 @@ struct WalkParameter {
constexpr std::array<const WalkParameter, 8> WalkParameters { {
// clang-format off
// Direction startingOffset, VelocityX, VelocityY
{ /* South */ { 0, 0 }, VelocityToUse::None, VelocityToUse::Half },
{ /* SouthWest */ { 0, 0 }, VelocityToUse::NegativeHalf, VelocityToUse::Quarter },
{ /* West */ { 0, 0 }, VelocityToUse::NegativeFull, VelocityToUse::None },
{ /* NorthWest */ { 0, 0 }, VelocityToUse::NegativeHalf, VelocityToUse::NegativeQuarter },
{ /* North */ { 0, 0 }, VelocityToUse::None, VelocityToUse::NegativeHalf },
{ /* NorthEast */ { 0, 0 }, VelocityToUse::Half, VelocityToUse::NegativeQuarter },
{ /* East */ { 0, 0 }, VelocityToUse::Full, VelocityToUse::None },
{ /* SouthEast */ { 0, 0 }, VelocityToUse::Half, VelocityToUse::Quarter }
// Direction VelocityX, VelocityY
{ /* South */ VelocityToUse::None, VelocityToUse::Half },
{ /* SouthWest */ VelocityToUse::NegativeHalf, VelocityToUse::Quarter },
{ /* West */ VelocityToUse::NegativeFull, VelocityToUse::None },
{ /* NorthWest */ VelocityToUse::NegativeHalf, VelocityToUse::NegativeQuarter },
{ /* North */ VelocityToUse::None, VelocityToUse::NegativeHalf },
{ /* NorthEast */ VelocityToUse::Half, VelocityToUse::NegativeQuarter },
{ /* East */ VelocityToUse::Full, VelocityToUse::None },
{ /* SouthEast */ VelocityToUse::Half, VelocityToUse::Quarter }
// clang-format on
} };
@ -115,9 +114,8 @@ DisplacementOf<int16_t> ActorPosition::CalculateWalkingOffsetShifted4(Direction
{
int16_t velocityProgress = static_cast<int16_t>(animInfo.getAnimationProgress()) * animInfo.numberOfFrames / AnimationInfo::baseValueFraction;
const WalkParameter &walkParameter = WalkParameters[static_cast<size_t>(dir)];
DisplacementOf<int16_t> offset = walkParameter.startingOffset;
DisplacementOf<int16_t> velocity = walkParameter.getVelocity(animInfo.numberOfFrames);
offset += (velocity * velocityProgress);
DisplacementOf<int16_t> offset = (velocity * velocityProgress);
return offset;
}

47
Source/monster.cpp

@ -710,18 +710,21 @@ void StartSpecialStand(Monster &monster, Direction md)
monster.position.old = monster.position.tile;
}
void Walk(Monster &monster, int xadd, int yadd, Direction endDir)
void WalkInDirection(Monster &monster, Direction endDir)
{
const auto fx = static_cast<WorldTileCoord>(xadd + monster.position.tile.x);
const auto fy = static_cast<WorldTileCoord>(yadd + monster.position.tile.y);
Point dir = { 0, 0 };
dir += endDir;
const auto fx = static_cast<WorldTileCoord>(monster.position.tile.x + dir.x);
const auto fy = static_cast<WorldTileCoord>(monster.position.tile.y + dir.y);
monster.mode = MonsterMode::MoveNorthwards;
monster.position.old = monster.position.tile;
monster.position.future = { fx, fy };
monster.occupyTile(monster.position.future, true);
monster.var1 = xadd;
monster.var2 = yadd;
monster.var3 = static_cast<int>(endDir);
monster.var1 = dir.x;
monster.var2 = dir.y;
monster.var3 = static_cast<int8_t>(endDir);
NewMonsterAnim(monster, MonsterGraphic::Walk, endDir, AnimationDistributionFlags::ProcessAnimationPending, -1);
}
@ -3930,34 +3933,10 @@ bool Walk(Monster &monster, Direction md)
return false;
}
switch (md) {
case Direction::North:
Walk(monster, -1, -1, Direction::North);
break;
case Direction::NorthEast:
Walk(monster, 0, -1, Direction::NorthEast);
break;
case Direction::East:
Walk(monster, 1, -1, Direction::East);
break;
case Direction::SouthEast:
Walk(monster, 1, 0, Direction::SouthEast);
break;
case Direction::South:
Walk(monster, 1, 1, Direction::South);
break;
case Direction::SouthWest:
Walk(monster, 0, 1, Direction::SouthWest);
break;
case Direction::West:
Walk(monster, -1, 1, Direction::West);
break;
case Direction::NorthWest:
Walk(monster, -1, 0, Direction::NorthWest);
break;
case Direction::NoDirection:
break;
}
if (md == Direction::NoDirection)
return true;
WalkInDirection(monster, md);
return true;
}

21
Source/player.cpp

@ -60,7 +60,6 @@ namespace {
struct DirectionSettings {
Direction dir;
DisplacementOf<int8_t> tileAdd;
PLR_MODE walkMode;
void (*walkModeHandler)(Player &, const DirectionSettings &);
};
@ -77,19 +76,19 @@ void UpdatePlayerLightOffset(Player &player)
void Walk(Player &player, const DirectionSettings &walkParams)
{
player.occupyTile(player.position.future, true);
player.position.temp = player.position.tile + walkParams.tileAdd;
player.position.temp = player.position.tile + walkParams.dir;
}
constexpr std::array<const DirectionSettings, 8> WalkSettings { {
// clang-format off
{ Direction::South, { 1, 1 }, PM_WALK_SOUTHWARDS, Walk },
{ Direction::SouthWest, { 0, 1 }, PM_WALK_SOUTHWARDS, Walk },
{ Direction::West, { -1, 1 }, PM_WALK_SIDEWAYS, Walk },
{ Direction::NorthWest, { -1, 0 }, PM_WALK_NORTHWARDS, Walk },
{ Direction::North, { -1, -1 }, PM_WALK_NORTHWARDS, Walk },
{ Direction::NorthEast, { 0, -1 }, PM_WALK_NORTHWARDS, Walk },
{ Direction::East, { 1, -1 }, PM_WALK_SIDEWAYS, Walk },
{ Direction::SouthEast, { 1, 0 }, PM_WALK_SOUTHWARDS, Walk }
{ Direction::South, PM_WALK_SOUTHWARDS, Walk },
{ Direction::SouthWest, PM_WALK_SOUTHWARDS, Walk },
{ Direction::West, PM_WALK_SIDEWAYS, Walk },
{ Direction::NorthWest, PM_WALK_NORTHWARDS, Walk },
{ Direction::North, PM_WALK_NORTHWARDS, Walk },
{ Direction::NorthEast, PM_WALK_NORTHWARDS, Walk },
{ Direction::East, PM_WALK_SIDEWAYS, Walk },
{ Direction::SouthEast, PM_WALK_SOUTHWARDS, Walk }
// clang-format on
} };
@ -123,7 +122,7 @@ void HandleWalkMode(Player &player, Direction dir)
player._pdir = dir;
// The player's tile position after finishing this movement action
player.position.future = player.position.tile + dirModeParams.tileAdd;
player.position.future = player.position.tile + dirModeParams.dir;
dirModeParams.walkModeHandler(player, dirModeParams);

Loading…
Cancel
Save