Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start separating game and engine code #1844

Merged
merged 3 commits into from Feb 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/CMakeLists.txt
@@ -1,6 +1,7 @@
add_subdirectory(Core)
add_subdirectory(Interop)
add_subdirectory(Math)
add_subdirectory(Engine)
add_subdirectory(OpenLoco)
add_subdirectory(Resources)
add_subdirectory(Utility)
Expand Down
27 changes: 27 additions & 0 deletions src/Engine/CMakeLists.txt
@@ -0,0 +1,27 @@
set(public_files
"${CMAKE_CURRENT_SOURCE_DIR}/include/OpenLoco/Engine/Map.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/include/OpenLoco/Engine/Types.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/include/OpenLoco/Engine/Ui/Point.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/include/OpenLoco/Engine/Ui/Rect.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/include/OpenLoco/Engine/Ui/Size.hpp"
)

set(private_files
"${CMAKE_CURRENT_SOURCE_DIR}/src/Engine.cpp"
)

loco_add_library(Engine STATIC
PUBLIC_FILES
${public_files}
PRIVATE_FILES
${private_files}
)

target_link_libraries(Engine
PUBLIC
Core
Console
Utility
Interop
Math
)
18 changes: 18 additions & 0 deletions src/Engine/include/OpenLoco/Engine/Types.hpp
@@ -0,0 +1,18 @@
#pragma once

#include <cstdint>
#include <limits>
#include <type_traits>

namespace OpenLoco
{
// To be replaced with std::to_underlying in c++23
template<typename TEnum>
constexpr auto enumValue(TEnum enumerator) noexcept
{
return static_cast<std::underlying_type_t<TEnum>>(enumerator);
}

using coord_t = int16_t;
using tile_coord_t = int16_t;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that reminds me. Basically nothing uses tile_coord_t. It has some users for z which should use the SmallZ/MicroZ types and it has some users for a tile coordinate which should be using TilePos2.

}
Expand Up @@ -11,16 +11,4 @@ namespace OpenLoco::Ui
// Until interop is removed this is a requirement (for global vars mainly)
static_assert(sizeof(Point) == 4);
static_assert(sizeof(Point32) == 8);

struct Size
{
uint16_t width = 0;
uint16_t height = 0;

constexpr Size(const uint16_t _width, const uint16_t _height)
: width(_width)
, height(_height)
{
}
};
}
@@ -1,6 +1,8 @@
#pragma once

#include "UiTypes.hpp"
#include "Point.hpp"
#include "Size.hpp"

#include <algorithm>
#include <cstddef>

Expand Down
18 changes: 18 additions & 0 deletions src/Engine/include/OpenLoco/Engine/Ui/Size.hpp
@@ -0,0 +1,18 @@
#pragma once

#include <cstdint>

namespace OpenLoco::Ui
{
struct Size
{
uint16_t width = 0;
uint16_t height = 0;

constexpr Size(const uint16_t _width, const uint16_t _height)
: width(_width)
, height(_height)
{
}
};
}
Empty file added src/Engine/src/Engine.cpp
Empty file.
5 changes: 2 additions & 3 deletions src/OpenLoco/CMakeLists.txt
Expand Up @@ -352,7 +352,6 @@ set(OLOCO_HEADERS
"${CMAKE_CURRENT_SOURCE_DIR}/src/Map/AnimationManager.h"
"${CMAKE_CURRENT_SOURCE_DIR}/src/Map/BuildingElement.h"
"${CMAKE_CURRENT_SOURCE_DIR}/src/Map/IndustryElement.h"
"${CMAKE_CURRENT_SOURCE_DIR}/src/Map/Map.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/Map/MapGenerator.h"
"${CMAKE_CURRENT_SOURCE_DIR}/src/Map/QuarterTile.h"
"${CMAKE_CURRENT_SOURCE_DIR}/src/Map/RoadElement.h"
Expand Down Expand Up @@ -453,12 +452,10 @@ set(OLOCO_HEADERS
"${CMAKE_CURRENT_SOURCE_DIR}/src/Ui/Cursor.h"
"${CMAKE_CURRENT_SOURCE_DIR}/src/Ui/Dropdown.h"
"${CMAKE_CURRENT_SOURCE_DIR}/src/Ui/ProgressBar.h"
"${CMAKE_CURRENT_SOURCE_DIR}/src/Ui/Rect.h"
"${CMAKE_CURRENT_SOURCE_DIR}/src/Ui/Screenshot.h"
"${CMAKE_CURRENT_SOURCE_DIR}/src/Ui/ScrollFlags.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/Ui/ScrollView.h"
"${CMAKE_CURRENT_SOURCE_DIR}/src/Ui/TextInput.h"
"${CMAKE_CURRENT_SOURCE_DIR}/src/Ui/UiTypes.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/Ui/WindowManager.h"
"${CMAKE_CURRENT_SOURCE_DIR}/src/Ui/WindowType.h"
"${CMAKE_CURRENT_SOURCE_DIR}/src/Vehicles/Orders.h"
Expand Down Expand Up @@ -517,6 +514,7 @@ target_link_libraries(OpenLoco
Interop
Utility
Math
Engine
${SDL2_LIB}
Threads::Threads
yaml-cpp
Expand Down Expand Up @@ -632,6 +630,7 @@ if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
Interop
Utility
Math
Engine
${SDL2_LIB} # These libraries are used in some of our headers try to minimize doing this
yaml-cpp
nonstd::span-lite)
Expand Down
2 changes: 1 addition & 1 deletion src/OpenLoco/src/Audio/Audio.h
@@ -1,8 +1,8 @@
#pragma once

#include "Location.hpp"
#include "Map/Map.hpp"
#include "Types.hpp"
#include <OpenLoco/Engine/Map.hpp>
#include <optional>
#include <string>
#include <tuple>
Expand Down
2 changes: 1 addition & 1 deletion src/OpenLoco/src/Company.h
Expand Up @@ -2,9 +2,9 @@

#include "Economy/Currency.h"
#include "Economy/Expenditures.h"
#include "Map/Map.hpp"
#include "Types.hpp"
#include <OpenLoco/Core/EnumFlags.hpp>
#include <OpenLoco/Engine/Map.hpp>
#include <cstddef>
#include <cstdint>
#include <limits>
Expand Down
2 changes: 1 addition & 1 deletion src/OpenLoco/src/CompanyManager.h
Expand Up @@ -2,9 +2,9 @@

#include "Company.h"
#include "Engine/Limits.h"
#include "Map/Map.hpp"
#include "Types.hpp"
#include <OpenLoco/Core/LocoFixedVector.hpp>
#include <OpenLoco/Engine/Map.hpp>
#include <array>
#include <cstddef>

Expand Down
3 changes: 2 additions & 1 deletion src/OpenLoco/src/Drawing/DrawSprite.h
@@ -1,7 +1,8 @@
#pragma once
#include "Graphics/ImageId.h"
#include "Graphics/PaletteMap.h"
#include "Ui/UiTypes.hpp"
#include <OpenLoco/Engine/Ui/Point.hpp>
#include <OpenLoco/Engine/Ui/Size.hpp>

namespace OpenLoco::Gfx
{
Expand Down
2 changes: 1 addition & 1 deletion src/OpenLoco/src/Drawing/DrawingContext.h
Expand Up @@ -3,8 +3,8 @@
#include "Graphics/Gfx.h"
#include "Graphics/PaletteMap.h"
#include "Types.hpp"
#include "Ui/Rect.h"
#include <OpenLoco/Core/EnumFlags.hpp>
#include <OpenLoco/Engine/Ui/Rect.hpp>
#include <cstdint>

namespace OpenLoco::Drawing
Expand Down
2 changes: 1 addition & 1 deletion src/OpenLoco/src/Drawing/SoftwareDrawingContext.h
Expand Up @@ -4,7 +4,7 @@
#include "Graphics/Gfx.h"
#include "Graphics/PaletteMap.h"
#include "Types.hpp"
#include "Ui/Rect.h"
#include <OpenLoco/Engine/Ui/Rect.hpp>
#include <cstdint>

namespace OpenLoco::Drawing
Expand Down
2 changes: 1 addition & 1 deletion src/OpenLoco/src/Drawing/SoftwareDrawingEngine.h
Expand Up @@ -2,7 +2,7 @@

#include "Graphics/Gfx.h"
#include "SoftwareDrawingContext.h"
#include "Ui/Rect.h"
#include <OpenLoco/Engine/Ui/Rect.hpp>
#include <algorithm>
#include <cstddef>

Expand Down
2 changes: 1 addition & 1 deletion src/OpenLoco/src/Entities/Entity.h
@@ -1,9 +1,9 @@
#pragma once

#include "Location.hpp"
#include "Map/Map.hpp"
#include "Types.hpp"
#include <OpenLoco/Core/EnumFlags.hpp>
#include <OpenLoco/Engine/Map.hpp>
#include <cstdint>
#include <limits>

Expand Down
2 changes: 1 addition & 1 deletion src/OpenLoco/src/Entities/EntityManager.h
@@ -1,7 +1,7 @@
#pragma once

#include "Entity.h"
#include "Map/Map.hpp"
#include <OpenLoco/Engine/Map.hpp>
#include <cstdio>
#include <iterator>

Expand Down
2 changes: 1 addition & 1 deletion src/OpenLoco/src/Entities/EntityTweener.h
@@ -1,7 +1,7 @@
#pragma once

#include "EntityManager.h"
#include "Map/Map.hpp"
#include <OpenLoco/Engine/Map.hpp>
#include <vector>

namespace OpenLoco
Expand Down
2 changes: 1 addition & 1 deletion src/OpenLoco/src/Entities/Misc.h
Expand Up @@ -2,8 +2,8 @@

#include "Economy/Currency.h"
#include "Entity.h"
#include "Map/Map.hpp"
#include "Objects/SteamObject.h"
#include <OpenLoco/Engine/Map.hpp>

namespace OpenLoco
{
Expand Down
3 changes: 1 addition & 2 deletions src/OpenLoco/src/Graphics/Gfx.h
Expand Up @@ -3,9 +3,8 @@
#include "Graphics/PaletteMap.h"
#include "ImageId.h"
#include "Types.hpp"
#include "Ui/Rect.h"
#include "Ui/UiTypes.hpp"
#include <OpenLoco/Core/EnumFlags.hpp>
#include <OpenLoco/Engine/Ui/Rect.hpp>
#include <array>
#include <cstdint>
#include <optional>
Expand Down
2 changes: 1 addition & 1 deletion src/OpenLoco/src/Graphics/RenderTarget.h
@@ -1,6 +1,6 @@
#pragma once

#include "Ui/Rect.h"
#include <OpenLoco/Engine/Ui/Rect.hpp>
#include <cstdint>
#include <optional>

Expand Down
2 changes: 1 addition & 1 deletion src/OpenLoco/src/Input.h
@@ -1,9 +1,9 @@
#pragma once

#include "Ui/UiTypes.hpp"
#include "Ui/WindowManager.h"
#include "Window.h"
#include <OpenLoco/Core/EnumFlags.hpp>
#include <OpenLoco/Engine/Ui/Point.hpp>

namespace OpenLoco::Input
{
Expand Down
2 changes: 1 addition & 1 deletion src/OpenLoco/src/LabelFrame.h
@@ -1,6 +1,6 @@
#pragma once
#include "Ui/Rect.h"
#include "ZoomLevel.hpp"
#include <OpenLoco/Engine/Ui/Rect.hpp>

namespace OpenLoco
{
Expand Down
2 changes: 1 addition & 1 deletion src/OpenLoco/src/Map/Animation.h
@@ -1,6 +1,6 @@
#pragma once

#include "Map.hpp"
#include <OpenLoco/Engine/Map.hpp>

namespace OpenLoco::Map
{
Expand Down
2 changes: 1 addition & 1 deletion src/OpenLoco/src/Map/AnimationManager.h
@@ -1,5 +1,5 @@
#pragma once
#include "Map.hpp"
#include <OpenLoco/Engine/Map.hpp>

namespace OpenLoco::Map::AnimationManager
{
Expand Down
2 changes: 1 addition & 1 deletion src/OpenLoco/src/Map/Tile.h
@@ -1,8 +1,8 @@
#pragma once

#include "Map.hpp"
#include "TileElement.h"
#include "Types.hpp"
#include <OpenLoco/Engine/Map.hpp>
#include <cassert>
#include <cstddef>
#include <cstdint>
Expand Down
2 changes: 1 addition & 1 deletion src/OpenLoco/src/Map/TileElementBase.h
@@ -1,7 +1,7 @@
#pragma once

#include "Map.hpp"
#include "Types.hpp"
#include <OpenLoco/Engine/Map.hpp>
#include <array>
#include <cassert>

Expand Down
2 changes: 1 addition & 1 deletion src/OpenLoco/src/Map/TileManager.cpp
Expand Up @@ -9,7 +9,6 @@
#include "IndustryElement.h"
#include "IndustryManager.h"
#include "Input.h"
#include "Map/Map.hpp"
#include "Objects/BuildingObject.h"
#include "Objects/LandObject.h"
#include "Objects/ObjectManager.h"
Expand All @@ -22,6 +21,7 @@
#include "Ui.h"
#include "ViewportManager.h"
#include "WallElement.h"
#include <OpenLoco/Engine/Map.hpp>
#include <OpenLoco/Interop/Interop.hpp>

using namespace OpenLoco::Interop;
Expand Down
2 changes: 1 addition & 1 deletion src/OpenLoco/src/Map/Track/SubpositionData.h
@@ -1,7 +1,7 @@
#pragma once

#include "Map/Map.hpp"
#include "Types.hpp"
#include <OpenLoco/Engine/Map.hpp>
#include <vector>

namespace OpenLoco
Expand Down
2 changes: 1 addition & 1 deletion src/OpenLoco/src/Map/Track/Track.h
@@ -1,7 +1,7 @@
#pragma once

#include "Map/Map.hpp"
#include "Types.hpp"
#include <OpenLoco/Engine/Map.hpp>
#include <utility>

namespace OpenLoco::Map::Track
Expand Down
2 changes: 1 addition & 1 deletion src/OpenLoco/src/Map/Track/TrackData.h
@@ -1,10 +1,10 @@
#pragma once

#include "Map/Map.hpp"
#include "Map/QuarterTile.h"
#include "Types.hpp"
#include <OpenLoco/Core/EnumFlags.hpp>
#include <OpenLoco/Core/Span.hpp>
#include <OpenLoco/Engine/Map.hpp>
#include <array>
#include <cstddef>
#include <cstdlib>
Expand Down
2 changes: 1 addition & 1 deletion src/OpenLoco/src/Map/Tree.h
@@ -1,6 +1,6 @@
#pragma once

#include "Map.hpp"
#include <OpenLoco/Engine/Map.hpp>
#include <optional>

namespace OpenLoco::Map
Expand Down
2 changes: 1 addition & 1 deletion src/OpenLoco/src/Map/Wave.h
@@ -1,7 +1,7 @@
#pragma once

#include "Location.hpp"
#include "Map.hpp"
#include <OpenLoco/Engine/Map.hpp>

namespace OpenLoco::Map
{
Expand Down
2 changes: 1 addition & 1 deletion src/OpenLoco/src/Objects/DockObject.h
@@ -1,10 +1,10 @@
#pragma once

#include "Map/Map.hpp"
#include "Object.h"
#include "Types.hpp"
#include <OpenLoco/Core/EnumFlags.hpp>
#include <OpenLoco/Core/Span.hpp>
#include <OpenLoco/Engine/Map.hpp>

namespace OpenLoco
{
Expand Down