1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-12-26 12:06:24 -05:00

Moved more common stuff into the common project.

This commit is contained in:
Tim Sarbin 2019-02-28 18:05:34 -05:00
parent ba96135e01
commit 5ab92737ec
19 changed files with 151 additions and 121 deletions

View File

@ -33,6 +33,9 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON CACHE BOOL "")
set_property(GLOBAL PROPERTY USE_FOLDERS ON) set_property(GLOBAL PROPERTY USE_FOLDERS ON)
# Import the actual projects ------------------------------------------------------------------------------------------- # Import the actual projects -------------------------------------------------------------------------------------------
add_subdirectory(OpenDiablo2.Common)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/OpenDiablo2.Common/include)
add_subdirectory(OpenDiablo2.SDL2) add_subdirectory(OpenDiablo2.SDL2)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/OpenDiablo2.SDL2/include) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/OpenDiablo2.SDL2/include)

View File

@ -0,0 +1,31 @@
project(OpenDiablo2.Common VERSION 0.1 LANGUAGES CXX)
set (SOURCES
src/D2Sprite.cpp
src/D2DataManager.cpp
)
set (HEADERS
include/OpenDiablo2.Common/D2EngineConfig.h
include/OpenDiablo2.Common/D2DataManager.h
include/OpenDiablo2.Common/D2Palette.h
include/OpenDiablo2.Common/D2Point.h
include/OpenDiablo2.Common/D2ResourcePath.h
include/OpenDiablo2.Common/D2Size.h
include/OpenDiablo2.Common/D2Sprite.h
)
add_library(OpenDiablo2.Common SHARED ${SOURCES} ${HEADERS})
target_include_directories(OpenDiablo2.Common
PUBLIC
include
PRIVATE
include
../ExtraUtils
)
set_target_properties(OpenDiablo2.Common PROPERTIES
CXX_STANDARD 17
)

View File

@ -1,12 +1,12 @@
#ifndef OPENDIABLO2_GAME_D2DATAMANAGER_H #ifndef OPENDIABLO2_COMMON_D2DATAMANAGER_H
#define OPENDIABLO2_GAME_D2DATAMANAGER_H #define OPENDIABLO2_COMMON_D2DATAMANAGER_H
#include <memory> #include <memory>
#include <map> #include <map>
#include <string> #include <string>
#include <OpenDiablo2.Game/D2EngineConfig.h> #include <OpenDiablo2.Common/D2EngineConfig.h>
namespace OpenDiablo2::Game { namespace OpenDiablo2::Common {
class D2DataManager { class D2DataManager {
public: public:
@ -18,4 +18,4 @@ private:
} }
#endif // OPENDIABLO2_GAME_D2DATAMANAGER_H #endif // OPENDIABLO2_COMMON_D2DATAMANAGER_H

View File

@ -0,0 +1,16 @@
#ifndef OPENDIABLO2_COMMON_D2ENGINECONFIG_H
#define OPENDIABLO2_COMMON_D2ENGINECONFIG_H
#include <string>
namespace OpenDiablo2::Common
{
struct D2EngineConfig
{
std::string BasePath; // The base path where the MPQ files are located
};
}
#endif //OPENDIABLO2_COMMON_D2ENGINECONFIG_H

View File

@ -1,9 +1,9 @@
#ifndef OPENDIABLO2_GAME_COMMON_D2PALETTE_H #ifndef OPENDIABLO2_COMMON_D2PALETTE_H
#define OPENDIABLO2_GAME_COMMON_D2PALETTE_H #define OPENDIABLO2_COMMON_D2PALETTE_H
#include <string> #include <string>
namespace OpenDiablo2::Game::Common { namespace OpenDiablo2::Common {
class D2Palette { class D2Palette {
public: public:
typedef std::string Entry; typedef std::string Entry;
@ -52,4 +52,4 @@ const D2Palette::Entry D2Palette::Units = "Units";
} }
#endif // OPENDIABLO2_GAME_COMMON_PALETTE_H #endif // OPENDIABLO2_COMMON_D2PALETTE_H

View File

@ -1,7 +1,7 @@
#ifndef OPENDIABLO2_GAME_COMMON_D2POINT_H #ifndef OPENDIABLO2_COMMON_D2POINT_H
#define OPENDIABLO2_GAME_COMMON_D2POINT_H #define OPENDIABLO2_COMMON_D2POINT_H
namespace OpenDiablo2::Game::Common { namespace OpenDiablo2::Common {
struct D2Point { struct D2Point {
int X; int X;
@ -10,4 +10,4 @@ struct D2Point {
} }
#endif // OPENDIABLO2_GAME_COMMON_D2POINT_H #endif // OPENDIABLO2_COMMON_D2POINT_H

View File

@ -1,9 +1,9 @@
#ifndef OPENDIABLO2_GAME_COMMON_D2RESOURCEPATH_H #ifndef OPENDIABLO2_COMMON_D2RESOURCEPATH_H
#define OPENDIABLO2_GAME_COMMON_D2RESOURCEPATH_H #define OPENDIABLO2_COMMON_D2RESOURCEPATH_H
#include <string> #include <string>
namespace OpenDiablo2::Game::Common { namespace OpenDiablo2::Common {
class D2ResourcePath { class D2ResourcePath {
public: public:
@ -464,4 +464,4 @@ const std::string D2ResourcePath::Missiles = "data\\global\\excel\\missiles.txt"
} }
#endif // OPENDIABLO2_GAME_COMMON_D2RESOURCEPATH_H #endif // OPENDIABLO2_COMMON_D2RESOURCEPATH_H

View File

@ -1,7 +1,7 @@
#ifndef OPENDIABLO2_GAME_COMMON_D2SIZE_H #ifndef OPENDIABLO2_COMMON_D2SIZE_H
#define OPENDIABLO2_GAME_COMMON_D2SIZE_H #define OPENDIABLO2_COMMON_D2SIZE_H
namespace OpenDiablo2::Game::Common { namespace OpenDiablo2::Common {
struct D2Size { struct D2Size {
int Width; int Width;
@ -10,4 +10,4 @@ struct D2Size {
} }
#endif // OPENDIABLO2_GAME_COMMON_D2SIZE_H #endif // OPENDIABLO2_COMMON_D2SIZE_H

View File

@ -0,0 +1,28 @@
#ifndef OPENDIABLO2_COMMON_D2SPRITE_H
#define OPENDIABLO2_COMMON_D2SPRITE_H
#include <OpenDiablo2.Common/D2Palette.h>
#include <OpenDiablo2.Common/D2Point.h>
#include <OpenDiablo2.Common/D2Size.h>
namespace OpenDiablo2::Common {
class D2Sprite {
public:
D2Sprite();
D2Sprite(std::string resourcePath, std::string palette, D2Point location, bool cacheFrames = false);
D2Sprite(std::string resourcePath, std::string palette, bool cacheFrames = false);
int Frame;
int TotalFrames;
bool Blend;
bool Darken;
D2Point Location;
D2Size FrameSize;
D2Size LocalFrameSize;
D2Palette::Entry CurrentPalette;
};
}
#endif // OPENDIABLO2_COMMON_D2SPRITE_H

View File

@ -1,11 +1,11 @@
#include <experimental/filesystem> #include <experimental/filesystem>
#include <spdlog/spdlog.h> #include <spdlog/spdlog.h>
#include <StormLib.h> #include <StormLib.h>
#include <OpenDiablo2.Game/D2DataManager.h> #include <OpenDiablo2.Common/D2DataManager.h>
namespace fs = std::experimental::filesystem; namespace fs = std::experimental::filesystem;
OpenDiablo2::Game::D2DataManager::D2DataManager( OpenDiablo2::Common::D2DataManager::D2DataManager(
const D2EngineConfig &engineConfig) const D2EngineConfig &engineConfig)
: fileEntries() : fileEntries()
{ {

View File

@ -0,0 +1,40 @@
#include <OpenDiablo2.Common/D2Sprite.h>
#include <OpenDiablo2.Common/D2Palette.h>
OpenDiablo2::Common::D2Sprite::D2Sprite()
{
}
OpenDiablo2::Common::D2Sprite::D2Sprite(
std::string resourcePath,
std::string palette,
bool cacheFrames)
: Frame (0)
, TotalFrames (0)
, Blend (false)
, Darken (false)
, Location (D2Point {0, 0})
, FrameSize (D2Size {0, 0})
, LocalFrameSize (D2Size {0, 0})
, CurrentPalette (palette)
{
}
OpenDiablo2::Common::D2Sprite::D2Sprite(
std::string resourcePath,
std::string palette,
D2Point location,
bool cacheFrames)
: Frame (0)
, TotalFrames (0)
, Blend (false)
, Darken (false)
, Location (location)
, FrameSize (D2Size {0, 0})
, LocalFrameSize (D2Size {0, 0})
, CurrentPalette (palette)
{
}

View File

@ -1,14 +1,11 @@
set (SOURCES set (SOURCES
src/main.cpp src/main.cpp
src/D2DataManager.cpp
src/D2Engine.cpp src/D2Engine.cpp
src/Scenes/D2MainMenu.cpp src/Scenes/D2MainMenu.cpp
) )
set (HEADERS set (HEADERS
include/OpenDiablo2.Game/D2DataManager.h
include/OpenDiablo2.Game/D2Engine.h include/OpenDiablo2.Game/D2Engine.h
include/OpenDiablo2.Game/D2EngineConfig.h
include/OpenDiablo2.Game/Scenes/D2Scene.h include/OpenDiablo2.Game/Scenes/D2Scene.h
include/OpenDiablo2.Game/Scenes/D2MainMenu.h include/OpenDiablo2.Game/Scenes/D2MainMenu.h
) )
@ -25,6 +22,7 @@ include_directories(OpenDiablo2.Game
target_link_libraries(OpenDiablo2.Game target_link_libraries(OpenDiablo2.Game
OpenDiablo2.SDL2 OpenDiablo2.SDL2
OpenDiablo2.Common
storm storm
stdc++fs stdc++fs
) )

View File

@ -3,11 +3,11 @@
#include <stack> #include <stack>
#include <memory> #include <memory>
#include <OpenDiablo2.Game/D2DataManager.h> #include <OpenDiablo2.Common/D2DataManager.h>
#include <OpenDiablo2.System/D2Graphics.h> #include <OpenDiablo2.System/D2Graphics.h>
#include <OpenDiablo2.System/D2Input.h> #include <OpenDiablo2.System/D2Input.h>
#include <OpenDiablo2.Game/Scenes/D2Scene.h> #include <OpenDiablo2.Game/Scenes/D2Scene.h>
#include "D2EngineConfig.h" #include "OpenDiablo2.Common/D2EngineConfig.h"
namespace OpenDiablo2::Game namespace OpenDiablo2::Game
{ {
@ -16,18 +16,18 @@ namespace OpenDiablo2::Game
class D2Engine : public std::enable_shared_from_this<D2Engine> class D2Engine : public std::enable_shared_from_this<D2Engine>
{ {
public: public:
D2Engine(const D2EngineConfig &config); D2Engine(const Common::D2EngineConfig &config);
// Runs the engine // Runs the engine
void Run(); void Run();
OpenDiablo2::Game::D2DataManager::Ptr dataManager; OpenDiablo2::Common::D2DataManager::Ptr dataManager;
OpenDiablo2::System::D2Graphics::Ptr gfx; OpenDiablo2::System::D2Graphics::Ptr gfx;
OpenDiablo2::System::D2Input::Ptr input; OpenDiablo2::System::D2Input::Ptr input;
private: private:
// Represents the engine configuration // Represents the engine configuration
const D2EngineConfig config; const Common::D2EngineConfig config;
// Indicates the system should keep running (if set to true) // Indicates the system should keep running (if set to true)
bool isRunning = true; bool isRunning = true;

View File

@ -1,16 +0,0 @@
#ifndef OPENDIABLO2_D2ENGINECONFIG_H
#define OPENDIABLO2_D2ENGINECONFIG_H
#include <string>
namespace OpenDiablo2::Game
{
struct D2EngineConfig
{
std::string BasePath; // The base path where the MPQ files are located
};
} // namespace OpenDiablo2::Game
#endif //OPENDIABLO2_D2ENGINECONFIG_H

View File

@ -2,11 +2,11 @@
#include <OpenDiablo2.Game/Scenes/D2MainMenu.h> #include <OpenDiablo2.Game/Scenes/D2MainMenu.h>
OpenDiablo2::Game::D2Engine::D2Engine( OpenDiablo2::Game::D2Engine::D2Engine(
const D2EngineConfig &config) const Common::D2EngineConfig &config)
: config(config) : config(config)
, gfx(std::make_unique<OpenDiablo2::System::D2Graphics>()) , gfx(std::make_unique<OpenDiablo2::System::D2Graphics>())
, input(std::make_unique<OpenDiablo2::System::D2Input>()) , input(std::make_unique<OpenDiablo2::System::D2Input>())
, dataManager(std::make_unique<OpenDiablo2::Game::D2DataManager>(config)) , dataManager(std::make_unique<OpenDiablo2::Common::D2DataManager>(config))
{ } { }
void void

View File

@ -17,7 +17,7 @@ main(
CLI::App app{"OpenDiablo2 - An open source re-implementation of Diablo 2."}; CLI::App app{"OpenDiablo2 - An open source re-implementation of Diablo 2."};
OpenDiablo2::Game::D2EngineConfig engineConfig; OpenDiablo2::Common::D2EngineConfig engineConfig;
engineConfig.BasePath = std::experimental::filesystem::current_path().string(); engineConfig.BasePath = std::experimental::filesystem::current_path().string();
app.add_option("-p,--path", engineConfig.BasePath, "The base path for Diablo 2"); app.add_option("-p,--path", engineConfig.BasePath, "The base path for Diablo 2");

View File

@ -3,7 +3,6 @@ project(OpenDiablo2.SDL2 VERSION 0.1 LANGUAGES CXX)
set (SOURCES set (SOURCES
src/D2Graphics.cpp src/D2Graphics.cpp
src/D2Input.cpp src/D2Input.cpp
src/D2Sprite.cpp
) )
set (HEADERS set (HEADERS
@ -27,6 +26,7 @@ target_include_directories(OpenDiablo2.SDL2
) )
target_link_libraries(OpenDiablo2.SDL2 target_link_libraries(OpenDiablo2.SDL2
OpenDiablo2.Common
${SDL2_LIBRARY} ${SDL2_LIBRARY}
) )

View File

@ -1,30 +0,0 @@
#ifndef OPENDIABLO2_SYSTEM_D2SPRITE_H
#define OPENDIABLO2_SYSTEM_D2SPRITE_H
#include <OpenDiablo2.Common/D2Palette.h>
#include <OpenDiablo2.Common/D2Point.h>
#include <OpenDiablo2.Common/D2Size.h>
namespace OpenDiablo2::System {
class D2Sprite {
public:
D2Sprite();
D2Sprite(std::string resourcePath, std::string palette, Game::Common::D2Point location, bool cacheFrames = false);
D2Sprite(std::string resourcePath, std::string palette, bool cacheFrames = false);
int Frame;
int TotalFrames;
bool Blend;
bool Darken;
OpenDiablo2::Game::Common::D2Point Location;
OpenDiablo2::Game::Common::D2Size FrameSize;
OpenDiablo2::Game::Common::D2Size LocalFrameSize;
OpenDiablo2::Game::Common::D2Palette::Entry CurrentPalette;
};
}
#endif // OPENDIABLO2_SYSTEM_D2SPRITE_H

View File

@ -1,40 +0,0 @@
#include <OpenDiablo2.System/D2Sprite.h>
#include <OpenDiablo2.Common/D2Palette.h>
OpenDiablo2::System::D2Sprite::D2Sprite()
{
}
OpenDiablo2::System::D2Sprite::D2Sprite(
std::string resourcePath,
std::string palette,
bool cacheFrames)
: Frame (0)
, TotalFrames (0)
, Blend (false)
, Darken (false)
, Location (OpenDiablo2::Game::Common::D2Point {0, 0})
, FrameSize (OpenDiablo2::Game::Common::D2Size {0, 0})
, LocalFrameSize (OpenDiablo2::Game::Common::D2Size {0, 0})
, CurrentPalette (palette)
{
}
OpenDiablo2::System::D2Sprite::D2Sprite(
std::string resourcePath,
std::string palette,
Game::Common::D2Point location,
bool cacheFrames)
: Frame (0)
, TotalFrames (0)
, Blend (false)
, Darken (false)
, Location (location)
, FrameSize (OpenDiablo2::Game::Common::D2Size {0, 0})
, LocalFrameSize (OpenDiablo2::Game::Common::D2Size {0, 0})
, CurrentPalette (palette)
{
}