diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index 07a4dde8cd1..32221f4a1ff 100644 --- a/Source/CMakeLists.txt +++ b/Source/CMakeLists.txt @@ -13,7 +13,6 @@ set(libdevilutionx_SRCS diablo.cpp diablo_msg.cpp doom.cpp - engine.cpp gamemenu.cpp gmenu.cpp help.cpp @@ -112,11 +111,13 @@ set(libdevilutionx_SRCS engine/random.cpp engine/sound_position.cpp engine/surface.cpp + engine/ticks.cpp engine/trn.cpp engine/render/automap_render.cpp engine/render/clx_render.cpp engine/render/dun_render.cpp + engine/render/primitive_render.cpp engine/render/scrollrt.cpp engine/render/text_render.cpp diff --git a/Source/DiabloUI/diabloui.cpp b/Source/DiabloUI/diabloui.cpp index c1289f7b560..b9d754f2614 100644 --- a/Source/DiabloUI/diabloui.cpp +++ b/Source/DiabloUI/diabloui.cpp @@ -21,6 +21,7 @@ #include "engine/dx.h" #include "engine/load_pcx.hpp" #include "engine/render/clx_render.hpp" +#include "engine/ticks.hpp" #include "hwcursor.hpp" #include "utils/algorithm/container.hpp" #include "utils/display.h" diff --git a/Source/appfat.cpp b/Source/appfat.cpp index 6b281b955d4..938f359027c 100644 --- a/Source/appfat.cpp +++ b/Source/appfat.cpp @@ -6,8 +6,13 @@ #include +#include #include +#ifdef USE_SDL1 +#include "utils/sdl2_to_1_2_backports.h" +#endif + #include "diablo.h" #include "multi.h" #include "storm/storm_net.hpp" diff --git a/Source/appfat.h b/Source/appfat.h index 9c98572f7fe..285c368edeb 100644 --- a/Source/appfat.h +++ b/Source/appfat.h @@ -7,8 +7,6 @@ #include -#include - #include "utils/attributes.h" namespace devilution { diff --git a/Source/automap.cpp b/Source/automap.cpp index 23a6c93a670..e46d07f0d92 100644 --- a/Source/automap.cpp +++ b/Source/automap.cpp @@ -14,6 +14,7 @@ #include "engine/load_file.hpp" #include "engine/palette.h" #include "engine/render/automap_render.hpp" +#include "engine/render/primitive_render.hpp" #include "levels/gendung.h" #include "levels/setmaps.h" #include "player.h" diff --git a/Source/control.h b/Source/control.h index 5a757bc19fd..d4e29a4f3c6 100644 --- a/Source/control.h +++ b/Source/control.h @@ -20,7 +20,6 @@ #include "DiabloUI/text_input.hpp" #include "DiabloUI/ui_flags.hpp" -#include "engine.h" #include "engine/displacement.hpp" #include "engine/point.hpp" #include "engine/rectangle.hpp" diff --git a/Source/controls/modifier_hints.h b/Source/controls/modifier_hints.h index 81739781837..030b242920e 100644 --- a/Source/controls/modifier_hints.h +++ b/Source/controls/modifier_hints.h @@ -1,6 +1,6 @@ #pragma once -#include "engine.h" +#include "engine/surface.hpp" namespace devilution { diff --git a/Source/controls/touch/event_handlers.cpp b/Source/controls/touch/event_handlers.cpp index e5ecbb82677..8cfbfdb3868 100644 --- a/Source/controls/touch/event_handlers.cpp +++ b/Source/controls/touch/event_handlers.cpp @@ -4,7 +4,7 @@ #include "controls/plrctrls.h" #include "cursor.h" #include "diablo.h" -#include "engine.h" +#include "engine/render/primitive_render.hpp" #include "engine/render/scrollrt.h" #include "gmenu.h" #include "inv.h" diff --git a/Source/controls/touch/renderers.cpp b/Source/controls/touch/renderers.cpp index 04a3cffe182..15650d18ea8 100644 --- a/Source/controls/touch/renderers.cpp +++ b/Source/controls/touch/renderers.cpp @@ -4,9 +4,9 @@ #include "cursor.h" #include "diablo.h" #include "doom.h" -#include "engine.h" #include "engine/events.hpp" #include "engine/render/clx_render.hpp" +#include "engine/render/primitive_render.hpp" #include "init.h" #include "inv.h" #include "levels/gendung.h" diff --git a/Source/cursor.cpp b/Source/cursor.cpp index 54174b1209c..d05419468c4 100644 --- a/Source/cursor.cpp +++ b/Source/cursor.cpp @@ -17,12 +17,12 @@ #include "control.h" #include "controls/plrctrls.h" #include "doom.h" -#include "engine.h" #include "engine/backbuffer_state.hpp" #include "engine/demomode.h" #include "engine/point.hpp" #include "engine/points_in_rectangle_range.hpp" #include "engine/render/clx_render.hpp" +#include "engine/render/primitive_render.hpp" #include "engine/trn.hpp" #include "hwcursor.hpp" #include "inv.h" diff --git a/Source/cursor.h b/Source/cursor.h index 0e459c43cd9..f69c4fe63ba 100644 --- a/Source/cursor.h +++ b/Source/cursor.h @@ -6,11 +6,11 @@ #pragma once #include -#include -#include -#include "engine.h" #include "engine/clx_sprite.hpp" +#include "engine/point.hpp" +#include "engine/size.hpp" +#include "engine/surface.hpp" #include "utils/attributes.h" #include "utils/enum_traits.h" diff --git a/Source/dead.h b/Source/dead.h index ded4699dd2c..f5298e477f4 100644 --- a/Source/dead.h +++ b/Source/dead.h @@ -5,11 +5,11 @@ */ #pragma once -#include +#include #include -#include "engine.h" #include "engine/clx_sprite.hpp" +#include "engine/direction.hpp" #include "engine/point.hpp" namespace devilution { diff --git a/Source/debug.h b/Source/debug.h index e6218ac79ea..386e4d24ee8 100644 --- a/Source/debug.h +++ b/Source/debug.h @@ -6,13 +6,14 @@ #pragma once #include +#include #include #include #include "diablo.h" -#include "engine.h" #include "engine/clx_sprite.hpp" +#include "engine/point.hpp" namespace devilution { diff --git a/Source/diablo_msg.cpp b/Source/diablo_msg.cpp index 7b2ebe4d607..68f768f42a7 100644 --- a/Source/diablo_msg.cpp +++ b/Source/diablo_msg.cpp @@ -13,6 +13,7 @@ #include "DiabloUI/ui_flags.hpp" #include "engine/clx_sprite.hpp" #include "engine/render/clx_render.hpp" +#include "engine/render/primitive_render.hpp" #include "engine/render/text_render.hpp" #include "panels/info_box.hpp" #include "utils/algorithm/container.hpp" diff --git a/Source/diablo_msg.hpp b/Source/diablo_msg.hpp index 34abaec2fbc..32179ffdb75 100644 --- a/Source/diablo_msg.hpp +++ b/Source/diablo_msg.hpp @@ -6,10 +6,9 @@ #pragma once #include -#include #include -#include "engine.h" +#include "engine/surface.hpp" namespace devilution { diff --git a/Source/doom.cpp b/Source/doom.cpp index 91ba9e27696..b665c649f56 100644 --- a/Source/doom.cpp +++ b/Source/doom.cpp @@ -8,10 +8,10 @@ #include #include "control.h" -#include "engine.h" #include "engine/clx_sprite.hpp" #include "engine/load_cel.hpp" #include "engine/render/clx_render.hpp" +#include "engine/render/primitive_render.hpp" namespace devilution { namespace { diff --git a/Source/doom.h b/Source/doom.h index 5a6b38c2c30..354c04bc6da 100644 --- a/Source/doom.h +++ b/Source/doom.h @@ -5,7 +5,7 @@ */ #pragma once -#include "engine.h" +#include "engine/surface.hpp" namespace devilution { diff --git a/Source/engine/backbuffer_state.cpp b/Source/engine/backbuffer_state.cpp index dee02d01ba0..dfda053918d 100644 --- a/Source/engine/backbuffer_state.cpp +++ b/Source/engine/backbuffer_state.cpp @@ -1,5 +1,6 @@ #include "engine/backbuffer_state.hpp" +#include #include #include "engine/dx.h" diff --git a/Source/engine/clx_sprite.hpp b/Source/engine/clx_sprite.hpp index ae351b4555f..eaf2ca4d00e 100644 --- a/Source/engine/clx_sprite.hpp +++ b/Source/engine/clx_sprite.hpp @@ -25,7 +25,7 @@ #include #include - +#include #include #include diff --git a/Source/engine/displacement.hpp b/Source/engine/displacement.hpp index 341838b562e..6383abe9889 100644 --- a/Source/engine/displacement.hpp +++ b/Source/engine/displacement.hpp @@ -7,6 +7,7 @@ #include #endif +#include "appfat.h" #include "engine/direction.hpp" #include "engine/size.hpp" #include "utils/attributes.h" diff --git a/Source/engine/dx.cpp b/Source/engine/dx.cpp index fac62d516ae..f88639b41cf 100644 --- a/Source/engine/dx.cpp +++ b/Source/engine/dx.cpp @@ -9,7 +9,7 @@ #include #include "controls/plrctrls.h" -#include "engine.h" +#include "engine/render/primitive_render.hpp" #include "options.h" #include "utils/display.h" #include "utils/log.hpp" diff --git a/Source/engine/dx.h b/Source/engine/dx.h index 05a9dc352e6..a505ec894ef 100644 --- a/Source/engine/dx.h +++ b/Source/engine/dx.h @@ -5,7 +5,9 @@ */ #pragma once -#include "engine.h" +#include + +#include "engine/surface.hpp" namespace devilution { diff --git a/Source/engine/events.cpp b/Source/engine/events.cpp index ae791d6651a..e44fd611d00 100644 --- a/Source/engine/events.cpp +++ b/Source/engine/events.cpp @@ -3,8 +3,8 @@ #include #include "controls/input.h" -#include "engine.h" #include "engine/demomode.h" +#include "engine/render/primitive_render.hpp" #include "interfac.h" #include "movie.h" #include "options.h" diff --git a/Source/engine/point.hpp b/Source/engine/point.hpp index eefaa14d986..6b63a8c6e07 100644 --- a/Source/engine/point.hpp +++ b/Source/engine/point.hpp @@ -237,4 +237,47 @@ DVL_ALWAYS_INLINE constexpr PointOf abs(PointOf a) return { std::abs(a.x), std::abs(a.y) }; } +/** + * @brief Calculate the best fit direction between two points + * @param start Tile coordinate + * @param destination Tile coordinate + * @return A value from the direction enum + */ +inline Direction GetDirection(Point start, Point destination) +{ + Direction md; + + int mx = destination.x - start.x; + int my = destination.y - start.y; + if (mx >= 0) { + if (my >= 0) { + if (5 * mx <= (my * 2)) // mx/my <= 0.4, approximation of tan(22.5) + return Direction::SouthWest; + md = Direction::South; + } else { + my = -my; + if (5 * mx <= (my * 2)) + return Direction::NorthEast; + md = Direction::East; + } + if (5 * my <= (mx * 2)) // my/mx <= 0.4 + md = Direction::SouthEast; + } else { + mx = -mx; + if (my >= 0) { + if (5 * mx <= (my * 2)) + return Direction::SouthWest; + md = Direction::West; + } else { + my = -my; + if (5 * mx <= (my * 2)) + return Direction::NorthEast; + md = Direction::North; + } + if (5 * my <= (mx * 2)) + md = Direction::NorthWest; + } + return md; +} + } // namespace devilution diff --git a/Source/engine/render/automap_render.cpp b/Source/engine/render/automap_render.cpp index d45a82e05eb..9f3c3191150 100644 --- a/Source/engine/render/automap_render.cpp +++ b/Source/engine/render/automap_render.cpp @@ -4,10 +4,12 @@ * Line drawing routines for the automap. */ #include "engine/render/automap_render.hpp" -#include "automap.h" #include +#include "automap.h" +#include "engine/render/primitive_render.hpp" + namespace devilution { namespace { diff --git a/Source/engine/render/automap_render.hpp b/Source/engine/render/automap_render.hpp index 75b73479b6d..5e289767bea 100644 --- a/Source/engine/render/automap_render.hpp +++ b/Source/engine/render/automap_render.hpp @@ -12,8 +12,8 @@ #include -#include "engine.h" #include "engine/point.hpp" +#include "engine/surface.hpp" namespace devilution { diff --git a/Source/engine/render/clx_render.hpp b/Source/engine/render/clx_render.hpp index b4e208f8a8b..d7010624d0b 100644 --- a/Source/engine/render/clx_render.hpp +++ b/Source/engine/render/clx_render.hpp @@ -14,9 +14,9 @@ #include #endif -#include "engine.h" #include "engine/clx_sprite.hpp" #include "engine/point.hpp" +#include "engine/surface.hpp" #include "lighting.h" namespace devilution { diff --git a/Source/engine.cpp b/Source/engine/render/primitive_render.cpp similarity index 78% rename from Source/engine.cpp rename to Source/engine/render/primitive_render.cpp index c1705f7ccf3..82506e0b510 100644 --- a/Source/engine.cpp +++ b/Source/engine/render/primitive_render.cpp @@ -1,24 +1,13 @@ -/** - * @file engine.cpp - * - * Implementation of basic engine helper functions: - * - Sprite blitting - * - Drawing - * - Angle calculation - * - RNG - * - Memory allocation - * - File loading - * - Video playback - */ +#include "engine/render/primitive_render.hpp" #include #include #include #include "engine/palette.h" -#include "lighting.h" -#include "movie.h" -#include "options.h" +#include "engine/point.hpp" +#include "engine/size.hpp" +#include "engine/surface.hpp" namespace devilution { namespace { @@ -194,46 +183,4 @@ void UnsafeDrawBorder2px(const Surface &out, Rectangle rect, uint8_t color) std::memset(buf, color, width); } -Direction GetDirection(Point start, Point destination) -{ - Direction md; - - int mx = destination.x - start.x; - int my = destination.y - start.y; - if (mx >= 0) { - if (my >= 0) { - if (5 * mx <= (my * 2)) // mx/my <= 0.4, approximation of tan(22.5) - return Direction::SouthWest; - md = Direction::South; - } else { - my = -my; - if (5 * mx <= (my * 2)) - return Direction::NorthEast; - md = Direction::East; - } - if (5 * my <= (mx * 2)) // my/mx <= 0.4 - md = Direction::SouthEast; - } else { - mx = -mx; - if (my >= 0) { - if (5 * mx <= (my * 2)) - return Direction::SouthWest; - md = Direction::West; - } else { - my = -my; - if (5 * mx <= (my * 2)) - return Direction::NorthEast; - md = Direction::North; - } - if (5 * my <= (mx * 2)) - md = Direction::NorthWest; - } - return md; -} - -int CalculateWidth2(int width) -{ - return (width - 64) / 2; -} - } // namespace devilution diff --git a/Source/engine.h b/Source/engine/render/primitive_render.hpp similarity index 59% rename from Source/engine.h rename to Source/engine/render/primitive_render.hpp index 1ed3cd7aed7..24d874e5f6d 100644 --- a/Source/engine.h +++ b/Source/engine/render/primitive_render.hpp @@ -1,42 +1,11 @@ -/** - * @file engine.h - * - * of basic engine helper functions: - * - Sprite blitting - * - Drawing - * - Angle calculation - * - Memory allocation - * - File loading - * - Video playback - */ #pragma once -#include -#include #include #include -#include -#include - -// We include `cinttypes` here so that it is included before `inttypes.h` -// to work around a bug in older GCC versions on some platforms, -// where including `inttypes.h` before `cinttypes` leads to missing -// defines for `PRIuMAX` et al. SDL transitively includes `inttypes.h`. -// See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97044 -#include -#include -#include - -#ifdef USE_SDL1 -#include "utils/sdl2_to_1_2_backports.h" -#endif - -#include "appfat.h" #include "engine/point.hpp" #include "engine/size.hpp" #include "engine/surface.hpp" -#include "utils/attributes.h" namespace devilution { @@ -100,25 +69,4 @@ void SetHalfTransparentPixel(const Surface &out, Point position, uint8_t color); */ void UnsafeDrawBorder2px(const Surface &out, Rectangle rect, uint8_t color); -/** - * @brief Calculate the best fit direction between two points - * @param start Tile coordinate - * @param destination Tile coordinate - * @return A value from the direction enum - */ -Direction GetDirection(Point start, Point destination); - -/** - * @brief Calculate Width2 from the original Width - * Width2 is needed for savegame compatibility and to render animations centered - * @return Returns Width2 - */ -int CalculateWidth2(int width); - -inline int GetAnimationFrame(int frames, int fps = 60) -{ - int frame = (SDL_GetTicks() / fps) % frames; - return frame > frames ? 0 : frame; -} - } // namespace devilution diff --git a/Source/engine/render/scrollrt.cpp b/Source/engine/render/scrollrt.cpp index d160b269aab..34bafbc9e71 100644 --- a/Source/engine/render/scrollrt.cpp +++ b/Source/engine/render/scrollrt.cpp @@ -716,7 +716,7 @@ void DrawDungeon(const Surface &out, Point tilePosition, Point targetBufferPosit if (lightTableIndex < LightsMax && bDead != 0) { const Corpse &corpse = Corpses[(bDead & 0x1F) - 1]; - const Point position { targetBufferPosition.x - CalculateWidth2(corpse.width), targetBufferPosition.y }; + const Point position { targetBufferPosition.x - CalculateSpriteTileCenterX(corpse.width), targetBufferPosition.y }; const ClxSprite sprite = corpse.spritesForDirection(static_cast((bDead >> 5) & 7))[corpse.frame]; if (corpse.translationPaletteIndex != 0) { const uint8_t *trn = Monsters[corpse.translationPaletteIndex - 1].uniqueMonsterTRN.get(); diff --git a/Source/engine/render/scrollrt.h b/Source/engine/render/scrollrt.h index b75fa994666..8cdf539ff14 100644 --- a/Source/engine/render/scrollrt.h +++ b/Source/engine/render/scrollrt.h @@ -5,11 +5,11 @@ */ #pragma once -#include - -#include "engine.h" #include "engine/animationinfo.h" +#include "engine/direction.hpp" +#include "engine/displacement.hpp" #include "engine/point.hpp" +#include "engine/surface.hpp" namespace devilution { @@ -22,7 +22,7 @@ extern bool frameflag; * @param dir walking direction * @param cameraMode Adjusts the offset relative to the camera */ -Displacement GetOffsetForWalking(const AnimationInfo &animationInfo, const Direction dir, bool cameraMode = false); +Displacement GetOffsetForWalking(const AnimationInfo &animationInfo, Direction dir, bool cameraMode = false); /** * @brief Clear cursor state diff --git a/Source/engine/render/text_render.cpp b/Source/engine/render/text_render.cpp index da2e5d0ce9f..c45bab349eb 100644 --- a/Source/engine/render/text_render.cpp +++ b/Source/engine/render/text_render.cpp @@ -17,7 +17,6 @@ #include "DiabloUI/diabloui.h" #include "DiabloUI/ui_item.h" -#include "engine.h" #include "engine/load_cel.hpp" #include "engine/load_clx.hpp" #include "engine/load_file.hpp" @@ -25,6 +24,8 @@ #include "engine/palette.h" #include "engine/point.hpp" #include "engine/render/clx_render.hpp" +#include "engine/render/primitive_render.hpp" +#include "engine/ticks.hpp" #include "utils/algorithm/container.hpp" #include "utils/display.h" #include "utils/is_of.hpp" @@ -827,7 +828,7 @@ void DrawStringWithColors(const Surface &out, std::string_view fmt, DrawStringFo uint8_t PentSpn2Spin() { - return (SDL_GetTicks() / 50) % 8; + return GetAnimationFrame(8, 50); } bool IsBreakableWhitespace(char32_t c) diff --git a/Source/engine/render/text_render.hpp b/Source/engine/render/text_render.hpp index 0a04698b6f5..c60a4e3941f 100644 --- a/Source/engine/render/text_render.hpp +++ b/Source/engine/render/text_render.hpp @@ -16,7 +16,6 @@ #include #include "DiabloUI/ui_flags.hpp" -#include "engine.h" #include "engine/clx_sprite.hpp" #include "engine/palette.h" #include "engine/rectangle.hpp" diff --git a/Source/engine/ticks.cpp b/Source/engine/ticks.cpp new file mode 100644 index 00000000000..c681ae88594 --- /dev/null +++ b/Source/engine/ticks.cpp @@ -0,0 +1,14 @@ +#include "engine/ticks.hpp" + +#include + +#include + +namespace devilution { + +uint32_t GetAnimationFrame(uint32_t frames, uint32_t fps) +{ + return (SDL_GetTicks() / fps) % frames; +} + +} // namespace devilution diff --git a/Source/engine/ticks.hpp b/Source/engine/ticks.hpp new file mode 100644 index 00000000000..1c529c56d7a --- /dev/null +++ b/Source/engine/ticks.hpp @@ -0,0 +1,9 @@ +#pragma once + +#include + +namespace devilution { + +uint32_t GetAnimationFrame(uint32_t frames, uint32_t fps = 60); + +} // namespace devilution diff --git a/Source/gmenu.cpp b/Source/gmenu.cpp index 56ff96acfde..52b450459d5 100644 --- a/Source/gmenu.cpp +++ b/Source/gmenu.cpp @@ -13,10 +13,10 @@ #include "control.h" #include "controls/axis_direction.h" #include "controls/controller_motion.h" -#include "engine.h" #include "engine/clx_sprite.hpp" #include "engine/load_cel.hpp" #include "engine/render/clx_render.hpp" +#include "engine/render/primitive_render.hpp" #include "engine/render/text_render.hpp" #include "options.h" #include "stores.h" diff --git a/Source/gmenu.h b/Source/gmenu.h index 209da6d2319..563496c2da0 100644 --- a/Source/gmenu.h +++ b/Source/gmenu.h @@ -7,7 +7,7 @@ #include -#include "engine.h" +#include "engine/surface.hpp" namespace devilution { diff --git a/Source/help.h b/Source/help.h index 3bd57860d56..2246a1f4937 100644 --- a/Source/help.h +++ b/Source/help.h @@ -5,7 +5,7 @@ */ #pragma once -#include "engine.h" +#include "engine/surface.hpp" namespace devilution { diff --git a/Source/interfac.cpp b/Source/interfac.cpp index 94144901f09..9effe977e2f 100644 --- a/Source/interfac.cpp +++ b/Source/interfac.cpp @@ -12,7 +12,6 @@ #include #include "control.h" -#include "engine.h" #include "engine/clx_sprite.hpp" #include "engine/dx.h" #include "engine/events.hpp" @@ -20,6 +19,7 @@ #include "engine/load_clx.hpp" #include "engine/palette.h" #include "engine/render/clx_render.hpp" +#include "engine/render/primitive_render.hpp" #include "hwcursor.hpp" #include "init.h" #include "loadsave.h" diff --git a/Source/items.cpp b/Source/items.cpp index f05dbf25e85..9c2e066e097 100644 --- a/Source/items.cpp +++ b/Source/items.cpp @@ -25,6 +25,7 @@ #include "engine/load_cel.hpp" #include "engine/random.hpp" #include "engine/render/clx_render.hpp" +#include "engine/render/primitive_render.hpp" #include "engine/render/text_render.hpp" #include "init.h" #include "inv_iterators.hpp" diff --git a/Source/items.h b/Source/items.h index db4528e1f6d..47e87d07154 100644 --- a/Source/items.h +++ b/Source/items.h @@ -10,10 +10,11 @@ #include "DiabloUI/ui_flags.hpp" #include "cursor.h" -#include "engine.h" #include "engine/animationinfo.h" #include "engine/point.hpp" +#include "engine/surface.hpp" #include "itemdat.h" +#include "levels/dun_tile.hpp" #include "monster.h" #include "utils/is_of.hpp" #include "utils/string_or_view.hpp" @@ -462,7 +463,7 @@ struct Item { [[nodiscard]] Displacement getRenderingOffset(const ClxSprite sprite) const { - return { -CalculateWidth2(sprite.width()), 0 }; + return { -CalculateSpriteTileCenterX(sprite.width()), 0 }; } }; diff --git a/Source/levels/dun_tile.hpp b/Source/levels/dun_tile.hpp index 74d2f594459..f48984adc3a 100644 --- a/Source/levels/dun_tile.hpp +++ b/Source/levels/dun_tile.hpp @@ -131,4 +131,12 @@ constexpr int_fast16_t DunFrameTriangleHeight = 31; constexpr size_t ReencodedTriangleFrameSize = 544 - 32; constexpr size_t ReencodedTrapezoidFrameSize = 800 - 16; +/** + * @return Returns the center of the sprite relative to the center of the tile. + */ +constexpr int CalculateSpriteTileCenterX(int width) +{ + return (width - TILE_WIDTH) / 2; +} + } // namespace devilution diff --git a/Source/levels/setmaps.h b/Source/levels/setmaps.h index 2ca0da0b57d..0d2a8fe5179 100644 --- a/Source/levels/setmaps.h +++ b/Source/levels/setmaps.h @@ -5,10 +5,6 @@ */ #pragma once -#include "engine.h" -#include "engine/point.hpp" -#include "objects.h" - namespace devilution { /** diff --git a/Source/lighting.h b/Source/lighting.h index 9e5e0be1928..aae59976386 100644 --- a/Source/lighting.h +++ b/Source/lighting.h @@ -15,8 +15,9 @@ #include #include "automap.h" -#include "engine.h" +#include "engine/displacement.hpp" #include "engine/point.hpp" +#include "engine/world_tile.hpp" #include "utils/attributes.h" namespace devilution { diff --git a/Source/loadsave.cpp b/Source/loadsave.cpp index 7dcfd21fc50..55303eae8ce 100644 --- a/Source/loadsave.cpp +++ b/Source/loadsave.cpp @@ -22,11 +22,11 @@ #include "cursor.h" #include "dead.h" #include "doom.h" -#include "engine.h" #include "engine/point.hpp" #include "engine/random.hpp" #include "init.h" #include "inv.h" +#include "levels/dun_tile.hpp" #include "lighting.h" #include "menu.h" #include "missiles.h" @@ -1077,7 +1077,7 @@ void SaveItem(SaveHelper &file, const Item &item) // write _iAnimWidth for vanilla compatibility file.WriteLE(ItemAnimWidth); // write _iAnimWidth2 for vanilla compatibility - file.WriteLE(CalculateWidth2(ItemAnimWidth)); + file.WriteLE(CalculateSpriteTileCenterX(ItemAnimWidth)); file.Skip(); // _delFlag, unused since 1.02 file.WriteLE(static_cast(item.selectionRegion)); file.Skip(3); // Alignment @@ -1195,7 +1195,7 @@ void SavePlayer(SaveHelper &file, const Player &player) const int animWidth = player.getSpriteWidth(); file.WriteLE(animWidth); // write _pAnimWidth2 for vanilla compatibility - file.WriteLE(CalculateWidth2(animWidth)); + file.WriteLE(CalculateSpriteTileCenterX(animWidth)); file.Skip(); // Skip _peflag file.WriteLE(player.lightId); file.WriteLE(1); // _pvid @@ -1607,7 +1607,7 @@ void SaveObject(SaveHelper &file, const Object &object) file.WriteLE(object._oAnimLen); file.WriteLE(object._oAnimFrame); file.WriteLE(object._oAnimWidth); - file.WriteLE(CalculateWidth2(static_cast(object._oAnimWidth))); // Write _oAnimWidth2 for vanilla compatibility + file.WriteLE(CalculateSpriteTileCenterX(static_cast(object._oAnimWidth))); // Write _oAnimWidth2 for vanilla compatibility file.WriteLE(object._oDelFlag ? 1 : 0); file.WriteLE(object._oBreak); file.Skip(3); // Alignment diff --git a/Source/lua/modules/dev/quests.cpp b/Source/lua/modules/dev/quests.cpp index 138bd00f195..b4b9148c9ca 100644 --- a/Source/lua/modules/dev/quests.cpp +++ b/Source/lua/modules/dev/quests.cpp @@ -6,7 +6,7 @@ #include -#include "engine.h" +#include "engine/render/primitive_render.hpp" #include "lua/metadoc.hpp" #include "quests.h" #include "utils/is_of.hpp" diff --git a/Source/minitext.cpp b/Source/minitext.cpp index 43762666795..c209a1cc366 100644 --- a/Source/minitext.cpp +++ b/Source/minitext.cpp @@ -11,11 +11,11 @@ #include "DiabloUI/ui_flags.hpp" #include "control.h" -#include "engine.h" #include "engine/clx_sprite.hpp" #include "engine/dx.h" #include "engine/load_cel.hpp" #include "engine/render/clx_render.hpp" +#include "engine/render/primitive_render.hpp" #include "engine/render/text_render.hpp" #include "playerdat.hpp" #include "textdat.h" diff --git a/Source/minitext.h b/Source/minitext.h index 32d9a90091e..9bfdcb6e292 100644 --- a/Source/minitext.h +++ b/Source/minitext.h @@ -5,7 +5,7 @@ */ #pragma once -#include "engine.h" +#include "engine/surface.hpp" #include "textdat.h" namespace devilution { diff --git a/Source/missiles.cpp b/Source/missiles.cpp index 7fb7d99b8bc..f757990e39e 100644 --- a/Source/missiles.cpp +++ b/Source/missiles.cpp @@ -21,8 +21,10 @@ #include "engine/load_file.hpp" #include "engine/points_in_rectangle_range.hpp" #include "engine/random.hpp" +#include "engine/render/primitive_render.hpp" #include "init.h" #include "inv.h" +#include "levels/dun_tile.hpp" #include "levels/trigs.h" #include "lighting.h" #include "monster.h" @@ -2166,7 +2168,7 @@ void InitMissileAnimationFromMonster(Missile &mis, Direction midir, const Monste mis._miAnimDelay = anim.rate; mis._miAnimLen = anim.frames; mis._miAnimWidth = width; - mis._miAnimWidth2 = CalculateWidth2(width); + mis._miAnimWidth2 = CalculateSpriteTileCenterX(width); mis._miAnimAdd = 1; mis.var1 = 0; mis.var2 = 0; diff --git a/Source/missiles.h b/Source/missiles.h index 0411633b0bf..b9af0d8a262 100644 --- a/Source/missiles.h +++ b/Source/missiles.h @@ -9,7 +9,7 @@ #include #include -#include "engine.h" +#include "engine/displacement.hpp" #include "engine/point.hpp" #include "engine/world_tile.hpp" #include "misdat.h" diff --git a/Source/monster.h b/Source/monster.h index b77f52cbf14..17df89efc35 100644 --- a/Source/monster.h +++ b/Source/monster.h @@ -15,7 +15,6 @@ #include #include -#include "engine.h" #include "engine/actor_position.hpp" #include "engine/animationinfo.h" #include "engine/clx_sprite.hpp" @@ -23,6 +22,7 @@ #include "engine/sound.h" #include "engine/world_tile.hpp" #include "init.h" +#include "levels/dun_tile.hpp" #include "misdat.h" #include "monstdat.h" #include "spelldat.h" @@ -468,7 +468,7 @@ struct Monster { // note: missing field _mAFNum [[nodiscard]] Displacement getRenderingOffset(const ClxSprite sprite) const { - Displacement offset = { -CalculateWidth2(sprite.width()), 0 }; + Displacement offset = { -CalculateSpriteTileCenterX(sprite.width()), 0 }; if (isWalking()) offset += GetOffsetForWalking(animInfo, direction); return offset; diff --git a/Source/mpq/mpq_writer.cpp b/Source/mpq/mpq_writer.cpp index 5fbf36ab1fb..c4e4de1d5c0 100644 --- a/Source/mpq/mpq_writer.cpp +++ b/Source/mpq/mpq_writer.cpp @@ -10,7 +10,6 @@ #include "appfat.h" #include "encrypt.h" -#include "engine.h" #include "utils/endian_read.hpp" #include "utils/file_util.h" #include "utils/language.h" diff --git a/Source/objects.h b/Source/objects.h index 7cafbaa9ebe..b9b4dd3d5e3 100644 --- a/Source/objects.h +++ b/Source/objects.h @@ -17,6 +17,7 @@ #include "engine/rectangle.hpp" #include "engine/world_tile.hpp" #include "itemdat.h" +#include "levels/dun_tile.hpp" #include "monster.h" #include "objdat.h" #include "textdat.h" @@ -270,7 +271,7 @@ struct Object { } [[nodiscard]] Displacement getRenderingOffset(const ClxSprite sprite, Point tilePosition) const { - Displacement offset = Displacement { -CalculateWidth2(sprite.width()), 0 }; + Displacement offset = Displacement { -CalculateSpriteTileCenterX(sprite.width()), 0 }; if (position != tilePosition) { // drawing a large or offset object, calculate the correct position for the center of the sprite Displacement worldOffset = position - tilePosition; diff --git a/Source/panels/console.cpp b/Source/panels/console.cpp index 3d7e414f82c..fb76abbf213 100644 --- a/Source/panels/console.cpp +++ b/Source/panels/console.cpp @@ -14,12 +14,12 @@ #include "DiabloUI/text_input.hpp" #include "control.h" -#include "engine.h" #include "engine/assets.hpp" #include "engine/displacement.hpp" #include "engine/dx.h" #include "engine/palette.h" #include "engine/rectangle.hpp" +#include "engine/render/primitive_render.hpp" #include "engine/render/text_render.hpp" #include "engine/size.hpp" #include "engine/surface.hpp" diff --git a/Source/panels/spell_icons.cpp b/Source/panels/spell_icons.cpp index f14670078fd..dbfe26b0cc2 100644 --- a/Source/panels/spell_icons.cpp +++ b/Source/panels/spell_icons.cpp @@ -3,11 +3,11 @@ #include #include -#include "engine.h" #include "engine/load_cel.hpp" #include "engine/load_clx.hpp" #include "engine/palette.h" #include "engine/render/clx_render.hpp" +#include "engine/render/primitive_render.hpp" #include "init.h" namespace devilution { diff --git a/Source/panels/spell_list.cpp b/Source/panels/spell_list.cpp index 5be1f0b643c..3e6ed96f8c4 100644 --- a/Source/panels/spell_list.cpp +++ b/Source/panels/spell_list.cpp @@ -6,9 +6,9 @@ #include "control.h" #include "controls/plrctrls.h" -#include "engine.h" #include "engine/backbuffer_state.hpp" #include "engine/palette.h" +#include "engine/render/primitive_render.hpp" #include "engine/render/text_render.hpp" #include "inv_iterators.hpp" #include "options.h" diff --git a/Source/pfile.cpp b/Source/pfile.cpp index a474d620e58..aa9381d65b1 100644 --- a/Source/pfile.cpp +++ b/Source/pfile.cpp @@ -14,8 +14,8 @@ #include #include "codec.h" -#include "engine.h" #include "engine/load_file.hpp" +#include "engine/render/primitive_render.hpp" #include "init.h" #include "loadsave.h" #include "menu.h" diff --git a/Source/player.h b/Source/player.h index 73860095ef3..fd112c7b3d9 100644 --- a/Source/player.h +++ b/Source/player.h @@ -12,15 +12,16 @@ #include #include "diablo.h" -#include "engine.h" #include "engine/actor_position.hpp" #include "engine/animationinfo.h" #include "engine/clx_sprite.hpp" +#include "engine/displacement.hpp" #include "engine/path.h" #include "engine/point.hpp" #include "interfac.h" #include "items.h" #include "items/validation.h" +#include "levels/dun_tile.hpp" #include "levels/gendung.h" #include "multi.h" #include "playerdat.hpp" @@ -783,7 +784,7 @@ struct Player { } [[nodiscard]] Displacement getRenderingOffset(const ClxSprite sprite) const { - Displacement offset = { -CalculateWidth2(sprite.width()), 0 }; + Displacement offset = { -CalculateSpriteTileCenterX(sprite.width()), 0 }; if (isWalking()) offset += GetOffsetForWalking(AnimInfo, _pdir); return offset; diff --git a/Source/playerdat.hpp b/Source/playerdat.hpp index 4b0bb3fd3d4..7b4ff3e9a42 100644 --- a/Source/playerdat.hpp +++ b/Source/playerdat.hpp @@ -5,6 +5,7 @@ */ #pragma once +#include #include #include "effects.h" diff --git a/Source/plrmsg.cpp b/Source/plrmsg.cpp index bba44697449..51b708218aa 100644 --- a/Source/plrmsg.cpp +++ b/Source/plrmsg.cpp @@ -11,6 +11,7 @@ #include #include "control.h" +#include "engine/render/primitive_render.hpp" #include "engine/render/text_render.hpp" #include "inv.h" #include "qol/chatlog.h" diff --git a/Source/plrmsg.h b/Source/plrmsg.h index e8a17b6d2c3..7d3c0b67f37 100644 --- a/Source/plrmsg.h +++ b/Source/plrmsg.h @@ -12,7 +12,7 @@ #include #include "DiabloUI/ui_flags.hpp" -#include "engine.h" +#include "engine/surface.hpp" #include "player.h" namespace devilution { diff --git a/Source/qol/chatlog.h b/Source/qol/chatlog.h index bbe06521e75..5291684f5fb 100644 --- a/Source/qol/chatlog.h +++ b/Source/qol/chatlog.h @@ -5,7 +5,8 @@ */ #pragma once -#include "engine.h" +#include "DiabloUI/ui_flags.hpp" +#include "engine/surface.hpp" #include "player.h" namespace devilution { diff --git a/Source/qol/itemlabels.cpp b/Source/qol/itemlabels.cpp index 6d0d78394f0..f980434aa22 100644 --- a/Source/qol/itemlabels.cpp +++ b/Source/qol/itemlabels.cpp @@ -13,6 +13,7 @@ #include "cursor.h" #include "engine/point.hpp" #include "engine/render/clx_render.hpp" +#include "engine/render/primitive_render.hpp" #include "gmenu.h" #include "inv.h" #include "options.h" diff --git a/Source/qol/itemlabels.h b/Source/qol/itemlabels.h index f77983502f2..5d4edd7cf14 100644 --- a/Source/qol/itemlabels.h +++ b/Source/qol/itemlabels.h @@ -5,7 +5,8 @@ */ #pragma once -#include "engine.h" +#include "engine/point.hpp" +#include "engine/surface.hpp" namespace devilution { diff --git a/Source/qol/monhealthbar.cpp b/Source/qol/monhealthbar.cpp index 978721baebd..4761be95491 100644 --- a/Source/qol/monhealthbar.cpp +++ b/Source/qol/monhealthbar.cpp @@ -14,6 +14,7 @@ #include "engine/clx_sprite.hpp" #include "engine/load_clx.hpp" #include "engine/render/clx_render.hpp" +#include "engine/render/primitive_render.hpp" #include "options.h" #include "utils/language.h" #include "utils/str_cat.hpp" diff --git a/Source/qol/xpbar.cpp b/Source/qol/xpbar.cpp index eb8df850595..1522a85afb8 100644 --- a/Source/qol/xpbar.cpp +++ b/Source/qol/xpbar.cpp @@ -15,6 +15,7 @@ #include "engine/load_clx.hpp" #include "engine/point.hpp" #include "engine/render/clx_render.hpp" +#include "engine/render/primitive_render.hpp" #include "options.h" #include "playerdat.hpp" #include "utils/format_int.hpp" diff --git a/Source/quests.h b/Source/quests.h index e8b2aea9892..da39f4217a1 100644 --- a/Source/quests.h +++ b/Source/quests.h @@ -7,9 +7,9 @@ #include -#include "engine.h" #include "engine/clx_sprite.hpp" #include "engine/point.hpp" +#include "engine/surface.hpp" #include "levels/gendung.h" #include "monster.h" #include "objdat.h" diff --git a/Source/stores.cpp b/Source/stores.cpp index 469e4058189..e5afd51751e 100644 --- a/Source/stores.cpp +++ b/Source/stores.cpp @@ -17,6 +17,7 @@ #include "engine/load_cel.hpp" #include "engine/random.hpp" #include "engine/render/clx_render.hpp" +#include "engine/render/primitive_render.hpp" #include "engine/render/text_render.hpp" #include "engine/trn.hpp" #include "init.h" diff --git a/Source/stores.h b/Source/stores.h index cea33714bbc..81c4d75ea9d 100644 --- a/Source/stores.h +++ b/Source/stores.h @@ -10,8 +10,8 @@ #include "DiabloUI/ui_flags.hpp" #include "control.h" -#include "engine.h" #include "engine/clx_sprite.hpp" +#include "engine/surface.hpp" #include "utils/attributes.h" namespace devilution { diff --git a/Source/towners.h b/Source/towners.h index 3dc10026d10..e0ae3f05612 100644 --- a/Source/towners.h +++ b/Source/towners.h @@ -11,7 +11,9 @@ #include #include +#include "engine/clx_sprite.hpp" #include "items.h" +#include "levels/dun_tile.hpp" #include "player.h" #include "quests.h" @@ -67,7 +69,7 @@ struct Towner { } [[nodiscard]] Displacement getRenderingOffset() const { - return { -CalculateWidth2(_tAnimWidth), 0 }; + return { -CalculateSpriteTileCenterX(_tAnimWidth), 0 }; } }; diff --git a/test/dead_test.cpp b/test/dead_test.cpp index 6dc94ea6419..75533836b1f 100644 --- a/test/dead_test.cpp +++ b/test/dead_test.cpp @@ -1,7 +1,7 @@ #include #include "dead.h" -#include "engine.h" +#include "engine/render/primitive_render.hpp" #include "levels/gendung.h" using namespace devilution;