Skip to content

Commit

Permalink
Split up engine.{h,cpp}
Browse files Browse the repository at this point in the history
Untangles dependencies by splitting up `engine.{h,cpp}` into 3 files:

1. `primitive_render`
2. `ticks` -- only contains `GetAnimationFrame` for now.
3. `GetWidth2` renamed to `CalculateSpriteTileCenterX` and moved to `levels/dun_tile.hpp`.
  • Loading branch information
glebm committed Jan 9, 2025
1 parent cef9449 commit c31836e
Show file tree
Hide file tree
Showing 71 changed files with 172 additions and 179 deletions.
3 changes: 2 additions & 1 deletion Source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ set(libdevilutionx_SRCS
diablo.cpp
diablo_msg.cpp
doom.cpp
engine.cpp
gamemenu.cpp
gmenu.cpp
help.cpp
Expand Down Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions Source/DiabloUI/diabloui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 5 additions & 0 deletions Source/appfat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@

#include <config.h>

#include <SDL.h>
#include <fmt/format.h>

#ifdef USE_SDL1
#include "utils/sdl2_to_1_2_backports.h"
#endif

#include "diablo.h"
#include "multi.h"
#include "storm/storm_net.hpp"
Expand Down
2 changes: 0 additions & 2 deletions Source/appfat.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

#include <string_view>

#include <SDL.h>

#include "utils/attributes.h"

namespace devilution {
Expand Down
1 change: 1 addition & 0 deletions Source/automap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion Source/control.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion Source/controls/modifier_hints.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "engine.h"
#include "engine/surface.hpp"

namespace devilution {

Expand Down
2 changes: 1 addition & 1 deletion Source/controls/touch/event_handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion Source/controls/touch/renderers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion Source/cursor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions Source/cursor.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
#pragma once

#include <cstdint>
#include <optional>
#include <utility>

#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"

Expand Down
4 changes: 2 additions & 2 deletions Source/dead.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
*/
#pragma once

#include <array>
#include <cstddef>
#include <cstdint>

#include "engine.h"
#include "engine/clx_sprite.hpp"
#include "engine/direction.hpp"
#include "engine/point.hpp"

namespace devilution {
Expand Down
3 changes: 2 additions & 1 deletion Source/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
#pragma once

#include <cstdint>
#include <string>
#include <string_view>

#include <ankerl/unordered_dense.h>

#include "diablo.h"
#include "engine.h"
#include "engine/clx_sprite.hpp"
#include "engine/point.hpp"

namespace devilution {

Expand Down
1 change: 1 addition & 0 deletions Source/diablo_msg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 1 addition & 2 deletions Source/diablo_msg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
#pragma once

#include <cstdint>
#include <string>
#include <string_view>

#include "engine.h"
#include "engine/surface.hpp"

namespace devilution {

Expand Down
2 changes: 1 addition & 1 deletion Source/doom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
#include <optional>

#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 {
Expand Down
2 changes: 1 addition & 1 deletion Source/doom.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
#pragma once

#include "engine.h"
#include "engine/surface.hpp"

namespace devilution {

Expand Down
1 change: 1 addition & 0 deletions Source/engine/backbuffer_state.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "engine/backbuffer_state.hpp"

#include <array>
#include <vector>

#include "engine/dx.h"
Expand Down
2 changes: 1 addition & 1 deletion Source/engine/clx_sprite.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

#include <cstddef>
#include <cstdint>

#include <cstring>
#include <iterator>
#include <memory>

Expand Down
1 change: 1 addition & 0 deletions Source/engine/displacement.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <ostream>
#endif

#include "appfat.h"
#include "engine/direction.hpp"
#include "engine/size.hpp"
#include "utils/attributes.h"
Expand Down
2 changes: 1 addition & 1 deletion Source/engine/dx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <cstdint>

#include "controls/plrctrls.h"
#include "engine.h"
#include "engine/render/primitive_render.hpp"
#include "options.h"
#include "utils/display.h"
#include "utils/log.hpp"
Expand Down
4 changes: 3 additions & 1 deletion Source/engine/dx.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
*/
#pragma once

#include "engine.h"
#include <SDL.h>

#include "engine/surface.hpp"

namespace devilution {

Expand Down
2 changes: 1 addition & 1 deletion Source/engine/events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
#include <cstdint>

#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"
Expand Down
43 changes: 43 additions & 0 deletions Source/engine/point.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,4 +237,47 @@ DVL_ALWAYS_INLINE constexpr PointOf<PointCoordT> abs(PointOf<PointCoordT> 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
4 changes: 3 additions & 1 deletion Source/engine/render/automap_render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
* Line drawing routines for the automap.
*/
#include "engine/render/automap_render.hpp"
#include "automap.h"

#include <cstdint>

#include "automap.h"
#include "engine/render/primitive_render.hpp"

namespace devilution {
namespace {

Expand Down
2 changes: 1 addition & 1 deletion Source/engine/render/automap_render.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

#include <cstdint>

#include "engine.h"
#include "engine/point.hpp"
#include "engine/surface.hpp"

namespace devilution {

Expand Down
2 changes: 1 addition & 1 deletion Source/engine/render/clx_render.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
#include <string>
#endif

#include "engine.h"
#include "engine/clx_sprite.hpp"
#include "engine/point.hpp"
#include "engine/surface.hpp"
#include "lighting.h"

namespace devilution {
Expand Down
Loading

0 comments on commit c31836e

Please sign in to comment.