diff --git a/Source/automap.cpp b/Source/automap.cpp index ed0590045..cd9fb1b27 100644 --- a/Source/automap.cpp +++ b/Source/automap.cpp @@ -651,7 +651,7 @@ void DrawAutomap(const Surface &out) Automap += AutomapOffset; const Player &myPlayer = *MyPlayer; - Displacement myPlayerOffset = ScrollInfo.offset; + Displacement myPlayerOffset = {}; if (myPlayer.IsWalking()) myPlayerOffset = GetOffsetForWalking(myPlayer.AnimInfo, myPlayer._pdir, true); diff --git a/Source/cursor.cpp b/Source/cursor.cpp index 04cef0ca7..95d79c859 100644 --- a/Source/cursor.cpp +++ b/Source/cursor.cpp @@ -289,7 +289,7 @@ void CheckCursMove() int yo = 0; CalcTileOffset(&xo, &yo); const Player &myPlayer = *MyPlayer; - Displacement offset = ScrollInfo.offset; + Displacement offset = {}; if (myPlayer.IsWalking()) offset = GetOffsetForWalking(myPlayer.AnimInfo, myPlayer._pdir, true); sx -= offset.deltaX - xo; @@ -300,7 +300,7 @@ void CheckCursMove() int fy = myPlayer.position.offset2.deltaY / 256; fx -= (myPlayer.position.offset2.deltaX + myPlayer.position.velocity.deltaX) / 256; fy -= (myPlayer.position.offset2.deltaY + myPlayer.position.velocity.deltaY) / 256; - if (ScrollInfo._sdir != ScrollDirection::None) { + if (myPlayer.IsWalking()) { sx -= fx; sy -= fy; } diff --git a/Source/diablo.cpp b/Source/diablo.cpp index abf37e86a..8175a2c02 100644 --- a/Source/diablo.cpp +++ b/Source/diablo.cpp @@ -931,9 +931,6 @@ void DiabloInitScreen() MousePosition = { gnScreenWidth / 2, gnScreenHeight / 2 }; if (ControlMode == ControlTypes::KeyboardAndMouse) SetCursorPos(MousePosition); - ScrollInfo.tile = { 0, 0 }; - ScrollInfo.offset = { 0, 0 }; - ScrollInfo._sdir = ScrollDirection::None; ClrDiabloMsg(); } diff --git a/Source/engine/render/scrollrt.cpp b/Source/engine/render/scrollrt.cpp index 5bce1999b..74c5fa4ac 100644 --- a/Source/engine/render/scrollrt.cpp +++ b/Source/engine/render/scrollrt.cpp @@ -1011,7 +1011,7 @@ void DrawGame(const Surface &fullOut, Point position) // Adjust by player offset and tile grid alignment Player &myPlayer = *MyPlayer; - Displacement offset = ScrollInfo.offset; + Displacement offset = {}; if (myPlayer.IsWalking()) offset = GetOffsetForWalking(myPlayer.AnimInfo, myPlayer._pdir, true); int sx = offset.deltaX + tileOffset.deltaX; @@ -1052,48 +1052,48 @@ void DrawGame(const Surface &fullOut, Point position) UpdateMissilesRendererData(); // Draw areas moving in and out of the screen - switch (ScrollInfo._sdir) { - case ScrollDirection::North: - sy -= TILE_HEIGHT; - position += Direction::North; - rows += 2; - break; - case ScrollDirection::NorthEast: - sy -= TILE_HEIGHT; - position += Direction::North; - columns++; - rows += 2; - break; - case ScrollDirection::East: - columns++; - break; - case ScrollDirection::SouthEast: - columns++; - rows++; - break; - case ScrollDirection::South: - rows += 2; - break; - case ScrollDirection::SouthWest: - sx -= TILE_WIDTH; - position += Direction::West; - columns++; - rows++; - break; - case ScrollDirection::West: - sx -= TILE_WIDTH; - position += Direction::West; - columns++; - break; - case ScrollDirection::NorthWest: - sx -= TILE_WIDTH / 2; - sy -= TILE_HEIGHT / 2; - position += Direction::NorthWest; - columns++; - rows++; - break; - case ScrollDirection::None: - break; + if (myPlayer.IsWalking()) { + switch (myPlayer._pdir) { + case Direction::North: + sy -= TILE_HEIGHT; + position += Direction::North; + rows += 2; + break; + case Direction::NorthEast: + sy -= TILE_HEIGHT; + position += Direction::North; + columns++; + rows += 2; + break; + case Direction::East: + columns++; + break; + case Direction::SouthEast: + columns++; + rows++; + break; + case Direction::South: + rows += 2; + break; + case Direction::SouthWest: + sx -= TILE_WIDTH; + position += Direction::West; + columns++; + rows++; + break; + case Direction::West: + sx -= TILE_WIDTH; + position += Direction::West; + columns++; + break; + case Direction::NorthWest: + sx -= TILE_WIDTH / 2; + sy -= TILE_HEIGHT / 2; + position += Direction::NorthWest; + columns++; + rows++; + break; + } } DrawFloor(out, position, { sx, sy }, rows, columns); @@ -1503,80 +1503,61 @@ void ClearScreenBuffer() #ifdef _DEBUG void ScrollView() { - bool scroll; - if (!MyPlayer->HoldItem.isEmpty()) return; - scroll = false; - if (MousePosition.x < 20) { if (dmaxPosition.y - 1 <= ViewPosition.y || dminPosition.x >= ViewPosition.x) { if (dmaxPosition.y - 1 > ViewPosition.y) { ViewPosition.y++; - scroll = true; } if (dminPosition.x < ViewPosition.x) { ViewPosition.x--; - scroll = true; } } else { ViewPosition.y++; ViewPosition.x--; - scroll = true; } } if (MousePosition.x > gnScreenWidth - 20) { if (dmaxPosition.x - 1 <= ViewPosition.x || dminPosition.y >= ViewPosition.y) { if (dmaxPosition.x - 1 > ViewPosition.x) { ViewPosition.x++; - scroll = true; } if (dminPosition.y < ViewPosition.y) { ViewPosition.y--; - scroll = true; } } else { ViewPosition.y--; ViewPosition.x++; - scroll = true; } } if (MousePosition.y < 20) { if (dminPosition.y >= ViewPosition.y || dminPosition.x >= ViewPosition.x) { if (dminPosition.y < ViewPosition.y) { ViewPosition.y--; - scroll = true; } if (dminPosition.x < ViewPosition.x) { ViewPosition.x--; - scroll = true; } } else { ViewPosition.x--; ViewPosition.y--; - scroll = true; } } if (MousePosition.y > gnScreenHeight - 20) { if (dmaxPosition.y - 1 <= ViewPosition.y || dmaxPosition.x - 1 <= ViewPosition.x) { if (dmaxPosition.y - 1 > ViewPosition.y) { ViewPosition.y++; - scroll = true; } if (dmaxPosition.x - 1 > ViewPosition.x) { ViewPosition.x++; - scroll = true; } } else { ViewPosition.x++; ViewPosition.y++; - scroll = true; } } - - if (scroll) - ScrollInfo._sdir = ScrollDirection::None; } #endif diff --git a/Source/engine/render/scrollrt.h b/Source/engine/render/scrollrt.h index 6a34b4db3..29af20760 100644 --- a/Source/engine/render/scrollrt.h +++ b/Source/engine/render/scrollrt.h @@ -13,18 +13,6 @@ namespace devilution { -enum class ScrollDirection : uint8_t { - None, - North, - NorthEast, - East, - SouthEast, - South, - SouthWest, - West, - NorthWest, -}; - extern int LightTableIndex; extern uint32_t level_cel_block; extern char arch_draw_type; diff --git a/Source/levels/gendung.cpp b/Source/levels/gendung.cpp index 4c6dc4bad..5cbe65553 100644 --- a/Source/levels/gendung.cpp +++ b/Source/levels/gendung.cpp @@ -34,7 +34,6 @@ bool setlevel; _setlevels setlvlnum; dungeon_type setlvltype; Point ViewPosition; -ScrollStruct ScrollInfo; int MicroTileLen; char TransVal; bool TransList[256]; diff --git a/Source/levels/gendung.h b/Source/levels/gendung.h index f6762f331..4e50dd958 100644 --- a/Source/levels/gendung.h +++ b/Source/levels/gendung.h @@ -102,15 +102,6 @@ enum _difficulty : uint8_t { DIFF_LAST = DIFF_HELL, }; -struct ScrollStruct { - /** @brief Tile offset of camera. */ - Point tile; - /** @brief Pixel offset of camera. */ - Displacement offset; - /** @brief Move direction of camera. */ - ScrollDirection _sdir; -}; - struct THEME_LOC { Rectangle room; int16_t ttval; @@ -173,7 +164,6 @@ extern _setlevels setlvlnum; extern dungeon_type setlvltype; /** Specifies the player viewpoint X,Y-coordinates of the map. */ extern DVL_API_FOR_TEST Point ViewPosition; -extern ScrollStruct ScrollInfo; extern int MicroTileLen; extern char TransVal; /** Specifies the active transparency indices. */ diff --git a/Source/missiles.cpp b/Source/missiles.cpp index 026d24035..5f65106d0 100644 --- a/Source/missiles.cpp +++ b/Source/missiles.cpp @@ -3520,7 +3520,7 @@ void MI_Teleport(Missile &missile) ChangeVisionXY(player._pvid, player.position.tile); } if (&player == MyPlayer) { - ViewPosition = Point { 0, 0 } + (player.position.tile - ScrollInfo.tile); + ViewPosition = player.position.tile; } } diff --git a/Source/player.cpp b/Source/player.cpp index 81e5ae890..85394a24f 100644 --- a/Source/player.cpp +++ b/Source/player.cpp @@ -168,7 +168,6 @@ struct DirectionSettings { DisplacementOf tileAdd; DisplacementOf offset; DisplacementOf map; - ScrollDirection scrollDir; PLR_MODE walkMode; void (*walkModeHandler)(Player &, const DirectionSettings &); }; @@ -269,34 +268,17 @@ constexpr _sfx_id herosounds[enum_size::value][enum_size: constexpr std::array WalkSettings { { // clang-format off - { Direction::South, { 1, 1 }, { 0, -32 }, { 0, 0 }, ScrollDirection::South, PM_WALK_SOUTHWARDS, WalkSouthwards }, - { Direction::SouthWest, { 0, 1 }, { 32, -16 }, { 0, 0 }, ScrollDirection::SouthWest, PM_WALK_SOUTHWARDS, WalkSouthwards }, - { Direction::West, { -1, 1 }, { 32, -16 }, { 0, 1 }, ScrollDirection::West, PM_WALK_SIDEWAYS, WalkSideways }, - { Direction::NorthWest, { -1, 0 }, { 0, 0 }, { 0, 0 }, ScrollDirection::NorthWest, PM_WALK_NORTHWARDS, WalkNorthwards }, - { Direction::North, { -1, -1 }, { 0, 0 }, { 0, 0 }, ScrollDirection::North, PM_WALK_NORTHWARDS, WalkNorthwards }, - { Direction::NorthEast, { 0, -1 }, { 0, 0 }, { 0, 0 }, ScrollDirection::NorthEast, PM_WALK_NORTHWARDS, WalkNorthwards }, - { Direction::East, { 1, -1 }, { -32, -16 }, { 1, 0 }, ScrollDirection::East, PM_WALK_SIDEWAYS, WalkSideways }, - { Direction::SouthEast, { 1, 0 }, { -32, -16 }, { 0, 0 }, ScrollDirection::SouthEast, PM_WALK_SOUTHWARDS, WalkSouthwards } + { Direction::South, { 1, 1 }, { 0, -32 }, { 0, 0 }, PM_WALK_SOUTHWARDS, WalkSouthwards }, + { Direction::SouthWest, { 0, 1 }, { 32, -16 }, { 0, 0 }, PM_WALK_SOUTHWARDS, WalkSouthwards }, + { Direction::West, { -1, 1 }, { 32, -16 }, { 0, 1 }, PM_WALK_SIDEWAYS, WalkSideways }, + { Direction::NorthWest, { -1, 0 }, { 0, 0 }, { 0, 0 }, PM_WALK_NORTHWARDS, WalkNorthwards }, + { Direction::North, { -1, -1 }, { 0, 0 }, { 0, 0 }, PM_WALK_NORTHWARDS, WalkNorthwards }, + { Direction::NorthEast, { 0, -1 }, { 0, 0 }, { 0, 0 }, PM_WALK_NORTHWARDS, WalkNorthwards }, + { Direction::East, { 1, -1 }, { -32, -16 }, { 1, 0 }, PM_WALK_SIDEWAYS, WalkSideways }, + { Direction::SouthEast, { 1, 0 }, { -32, -16 }, { 0, 0 }, PM_WALK_SOUTHWARDS, WalkSouthwards } // clang-format on } }; -void ScrollViewPort(const Player &player, ScrollDirection dir) -{ - ScrollInfo.tile = Point { 0, 0 } + (player.position.tile - ViewPosition); - - if (!*sgOptions.Graphics.zoom) { - if (abs(ScrollInfo.tile.x) >= 3 || abs(ScrollInfo.tile.y) >= 3) { - ScrollInfo._sdir = ScrollDirection::None; - } else { - ScrollInfo._sdir = dir; - } - } else if (abs(ScrollInfo.tile.x) >= 2 || abs(ScrollInfo.tile.y) >= 2) { - ScrollInfo._sdir = ScrollDirection::None; - } else { - ScrollInfo._sdir = dir; - } -} - bool PlrDirOK(const Player &player, Direction dir) { Point position = player.position.tile; @@ -328,10 +310,6 @@ void HandleWalkMode(Player &player, Displacement vel, Direction dir) // The player's tile position after finishing this movement action player.position.future = player.position.tile + dirModeParams.tileAdd; - if (&player == MyPlayer) { - ScrollViewPort(player, dirModeParams.scrollDir); - } - dirModeParams.walkModeHandler(player, dirModeParams); player.position.velocity = vel; @@ -381,8 +359,6 @@ void StartWalkStand(Player &player) player.position.offset = { 0, 0 }; if (&player == MyPlayer) { - ScrollInfo.offset = { 0, 0 }; - ScrollInfo._sdir = ScrollDirection::None; ViewPosition = player.position.tile; } } @@ -406,10 +382,6 @@ void ChangeOffset(Player &player) px -= player.position.offset2.deltaX >> 8; py -= player.position.offset2.deltaY >> 8; - if (&player == MyPlayer && ScrollInfo._sdir != ScrollDirection::None) { - ScrollInfo.offset += { px, py }; - } - PmChangeLightOff(player); } @@ -669,11 +641,6 @@ bool DoWalk(Player &player, int variant) ChangeVisionXY(player._pvid, player.position.tile); } - // Update the "camera" tile position - if (&player == MyPlayer && ScrollInfo._sdir != ScrollDirection::None) { - ViewPosition = Point { 0, 0 } + (player.position.tile - ScrollInfo.tile); - } - if (player.walkpath[0] != WALK_NONE) { StartWalkStand(player); } else { @@ -2819,8 +2786,6 @@ void InitPlayer(Player &player, bool firstTime) if (&player == MyPlayer) { MyPlayerIsDead = false; - ScrollInfo.offset = { 0, 0 }; - ScrollInfo._sdir = ScrollDirection::None; } } @@ -2866,8 +2831,6 @@ void FixPlayerLocation(Player &player, Direction bDir) player.position.offset = { 0, 0 }; player._pdir = bDir; if (&player == MyPlayer) { - ScrollInfo.offset = { 0, 0 }; - ScrollInfo._sdir = ScrollDirection::None; ViewPosition = player.position.tile; } ChangeLightXY(player._plid, player.position.tile); @@ -3507,8 +3470,6 @@ void SyncPlrAnim(Player &player) const player_graphic graphic = player.getGraphic(); if (!HeadlessMode) player.AnimInfo.sprites = player.AnimationData[static_cast(graphic)].spritesForDirection(player._pdir); - // Ensure ScrollInfo is initialized correctly - ScrollViewPort(player, WalkSettings[static_cast(player._pdir)].scrollDir); } void SyncInitPlrPos(Player &player)