Moved to SDL backend.

This commit is contained in:
Tim Sarbin 2019-02-22 20:14:35 -05:00
parent f46542a05f
commit 8f1a01dfa4
24 changed files with 705 additions and 209 deletions

3
.gitmodules vendored
View File

@ -1,6 +1,3 @@
[submodule "3rdparty/glfw"]
path = 3rdparty/glfw
url = git@github.com:glfw/glfw.git
[submodule "3rdparty/spdlog"]
path = 3rdparty/spdlog
url = git@github.com:gabime/spdlog.git

View File

@ -1,8 +1,2 @@
set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
add_subdirectory(glfw)
add_subdirectory(stormlib)
add_subdirectory(cli11)

1
3rdparty/glfw vendored

@ -1 +0,0 @@
Subproject commit 5f9cbd0ebcc9ca8bfddbf99e78a54fb02dd030d7

View File

@ -1,4 +1,5 @@
cmake_minimum_required(VERSION 3.0)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
message(FATAL_ERROR "Do not build in-source. Please remove CMakeCache.txt and the CMakeFiles/ directory. Then build out-of-source.")
@ -11,12 +12,9 @@ include(CMakeDependentOption)
set(CMAKE_CXX_STANDARD 17)
set(CXX_STANDARD 17)
set(OpenGL_GL_PREFERENCE "GLVND")
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
add_subdirectory(3rdparty)
add_subdirectory(src/OpenDiablo2.OS)
add_subdirectory(src/OpenDiablo2.Graphics)
add_subdirectory(src/OpenDiablo2.SDL2)
add_subdirectory(src/OpenDiablo2.Game)

173
cmake/FindSDL2.cmake Executable file
View File

@ -0,0 +1,173 @@
# This module defines
# SDL2_LIBRARY, the name of the library to link against
# SDL2_FOUND, if false, do not try to link to SDL2
# SDL2_INCLUDE_DIR, where to find SDL.h
#
# This module responds to the the flag:
# SDL2_BUILDING_LIBRARY
# If this is defined, then no SDL2main will be linked in because
# only applications need main().
# Otherwise, it is assumed you are building an application and this
# module will attempt to locate and set the the proper link flags
# as part of the returned SDL2_LIBRARY variable.
#
# Don't forget to include SDLmain.h and SDLmain.m your project for the
# OS X framework based version. (Other versions link to -lSDL2main which
# this module will try to find on your behalf.) Also for OS X, this
# module will automatically add the -framework Cocoa on your behalf.
#
#
# Additional Note: If you see an empty SDL2_LIBRARY_TEMP in your configuration
# and no SDL2_LIBRARY, it means CMake did not find your SDL2 library
# (SDL2.dll, libsdl2.so, SDL2.framework, etc).
# Set SDL2_LIBRARY_TEMP to point to your SDL2 library, and configure again.
# Similarly, if you see an empty SDL2MAIN_LIBRARY, you should set this value
# as appropriate. These values are used to generate the final SDL2_LIBRARY
# variable, but when these values are unset, SDL2_LIBRARY does not get created.
#
#
# $SDL2DIR is an environment variable that would
# correspond to the ./configure --prefix=$SDL2DIR
# used in building SDL2.
# l.e.galup 9-20-02
#
# Modified by Eric Wing.
# Added code to assist with automated building by using environmental variables
# and providing a more controlled/consistent search behavior.
# Added new modifications to recognize OS X frameworks and
# additional Unix paths (FreeBSD, etc).
# Also corrected the header search path to follow "proper" SDL guidelines.
# Added a search for SDL2main which is needed by some platforms.
# Added a search for threads which is needed by some platforms.
# Added needed compile switches for MinGW.
#
# On OSX, this will prefer the Framework version (if found) over others.
# People will have to manually change the cache values of
# SDL2_LIBRARY to override this selection or set the CMake environment
# CMAKE_INCLUDE_PATH to modify the search paths.
#
# Note that the header path has changed from SDL2/SDL.h to just SDL.h
# This needed to change because "proper" SDL convention
# is #include "SDL.h", not <SDL2/SDL.h>. This is done for portability
# reasons because not all systems place things in SDL2/ (see FreeBSD).
#=============================================================================
# Copyright 2003-2009 Kitware, Inc.
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
# (To distribute this file outside of CMake, substitute the full
# License text for the above reference.)
# message("<FindSDL2.cmake>")
SET(SDL2_SEARCH_PATHS
~/Library/Frameworks
/Library/Frameworks
/usr/local
/usr
/sw # Fink
/opt/local # DarwinPorts
/opt/csw # Blastwave
/opt
${SDL2_PATH}
)
FIND_PATH(SDL2_INCLUDE_DIR SDL.h
HINTS
$ENV{SDL2DIR}
PATH_SUFFIXES include/SDL2 include
PATHS ${SDL2_SEARCH_PATHS}
)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(PATH_SUFFIXES lib64 lib/x64 lib)
else()
set(PATH_SUFFIXES lib/x86 lib)
endif()
FIND_LIBRARY(SDL2_LIBRARY_TEMP
NAMES SDL2
HINTS
$ENV{SDL2DIR}
PATH_SUFFIXES ${PATH_SUFFIXES}
PATHS ${SDL2_SEARCH_PATHS}
)
IF(NOT SDL2_BUILDING_LIBRARY)
IF(NOT ${SDL2_INCLUDE_DIR} MATCHES ".framework")
# Non-OS X framework versions expect you to also dynamically link to
# SDL2main. This is mainly for Windows and OS X. Other (Unix) platforms
# seem to provide SDL2main for compatibility even though they don't
# necessarily need it.
FIND_LIBRARY(SDL2MAIN_LIBRARY
NAMES SDL2main
HINTS
$ENV{SDL2DIR}
PATH_SUFFIXES ${PATH_SUFFIXES}
PATHS ${SDL2_SEARCH_PATHS}
)
ENDIF(NOT ${SDL2_INCLUDE_DIR} MATCHES ".framework")
ENDIF(NOT SDL2_BUILDING_LIBRARY)
# SDL2 may require threads on your system.
# The Apple build may not need an explicit flag because one of the
# frameworks may already provide it.
# But for non-OSX systems, I will use the CMake Threads package.
IF(NOT APPLE)
FIND_PACKAGE(Threads)
ENDIF(NOT APPLE)
# MinGW needs an additional link flag, -mwindows
# It's total link flags should look like -lmingw32 -lSDL2main -lSDL2 -mwindows
IF(MINGW)
SET(MINGW32_LIBRARY mingw32 "-mwindows" CACHE STRING "mwindows for MinGW")
ENDIF(MINGW)
IF(SDL2_LIBRARY_TEMP)
# For SDL2main
IF(NOT SDL2_BUILDING_LIBRARY)
IF(SDL2MAIN_LIBRARY)
SET(SDL2_LIBRARY_TEMP ${SDL2MAIN_LIBRARY} ${SDL2_LIBRARY_TEMP})
ENDIF(SDL2MAIN_LIBRARY)
ENDIF(NOT SDL2_BUILDING_LIBRARY)
# For OS X, SDL2 uses Cocoa as a backend so it must link to Cocoa.
# CMake doesn't display the -framework Cocoa string in the UI even
# though it actually is there if I modify a pre-used variable.
# I think it has something to do with the CACHE STRING.
# So I use a temporary variable until the end so I can set the
# "real" variable in one-shot.
IF(APPLE)
SET(SDL2_LIBRARY_TEMP ${SDL2_LIBRARY_TEMP} "-framework Cocoa")
ENDIF(APPLE)
# For threads, as mentioned Apple doesn't need this.
# In fact, there seems to be a problem if I used the Threads package
# and try using this line, so I'm just skipping it entirely for OS X.
IF(NOT APPLE)
SET(SDL2_LIBRARY_TEMP ${SDL2_LIBRARY_TEMP} ${CMAKE_THREAD_LIBS_INIT})
ENDIF(NOT APPLE)
# For MinGW library
IF(MINGW)
SET(SDL2_LIBRARY_TEMP ${MINGW32_LIBRARY} ${SDL2_LIBRARY_TEMP})
ENDIF(MINGW)
# Set the final string here so the GUI reflects the final state.
SET(SDL2_LIBRARY ${SDL2_LIBRARY_TEMP} CACHE STRING "Where the SDL2 Library can be found")
# Set the temp variable to INTERNAL so it is not seen in the CMake GUI
SET(SDL2_LIBRARY_TEMP "${SDL2_LIBRARY_TEMP}" CACHE INTERNAL "")
ENDIF(SDL2_LIBRARY_TEMP)
# message("</FindSDL2.cmake>")
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2 REQUIRED_VARS SDL2_LIBRARY SDL2_INCLUDE_DIR)

100
cmake/FindSDL2_image.cmake Normal file
View File

@ -0,0 +1,100 @@
# Locate SDL_image library
#
# This module defines:
#
# ::
#
# SDL2_IMAGE_LIBRARIES, the name of the library to link against
# SDL2_IMAGE_INCLUDE_DIRS, where to find the headers
# SDL2_IMAGE_FOUND, if false, do not try to link against
# SDL2_IMAGE_VERSION_STRING - human-readable string containing the version of SDL_image
#
#
#
# For backward compatibility the following variables are also set:
#
# ::
#
# SDLIMAGE_LIBRARY (same value as SDL2_IMAGE_LIBRARIES)
# SDLIMAGE_INCLUDE_DIR (same value as SDL2_IMAGE_INCLUDE_DIRS)
# SDLIMAGE_FOUND (same value as SDL2_IMAGE_FOUND)
#
#
#
# $SDLDIR is an environment variable that would correspond to the
# ./configure --prefix=$SDLDIR used in building SDL.
#
# Created by Eric Wing. This was influenced by the FindSDL.cmake
# module, but with modifications to recognize OS X frameworks and
# additional Unix paths (FreeBSD, etc).
#=============================================================================
# Copyright 2005-2009 Kitware, Inc.
# Copyright 2012 Benjamin Eikel
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
# (To distribute this file outside of CMake, substitute the full
# License text for the above reference.)
find_path(SDL2_IMAGE_INCLUDE_DIR SDL_image.h
HINTS
ENV SDL2IMAGEDIR
ENV SDL2DIR
PATH_SUFFIXES SDL2
# path suffixes to search inside ENV{SDLDIR}
include/SDL2 include
PATHS ${SDL2_IMAGE_PATH}
)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(VC_LIB_PATH_SUFFIX lib/x64)
else()
set(VC_LIB_PATH_SUFFIX lib/x86)
endif()
find_library(SDL2_IMAGE_LIBRARY
NAMES SDL2_image
HINTS
ENV SDL2IMAGEDIR
ENV SDL2DIR
PATH_SUFFIXES lib ${VC_LIB_PATH_SUFFIX}
PATHS ${SDL2_IMAGE_PATH}
)
if(SDL2_IMAGE_INCLUDE_DIR AND EXISTS "${SDL2_IMAGE_INCLUDE_DIR}/SDL_image.h")
file(STRINGS "${SDL2_IMAGE_INCLUDE_DIR}/SDL_image.h" SDL2_IMAGE_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SDL_IMAGE_MAJOR_VERSION[ \t]+[0-9]+$")
file(STRINGS "${SDL2_IMAGE_INCLUDE_DIR}/SDL_image.h" SDL2_IMAGE_VERSION_MINOR_LINE REGEX "^#define[ \t]+SDL_IMAGE_MINOR_VERSION[ \t]+[0-9]+$")
file(STRINGS "${SDL2_IMAGE_INCLUDE_DIR}/SDL_image.h" SDL2_IMAGE_VERSION_PATCH_LINE REGEX "^#define[ \t]+SDL_IMAGE_PATCHLEVEL[ \t]+[0-9]+$")
string(REGEX REPLACE "^#define[ \t]+SDL_IMAGE_MAJOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_IMAGE_VERSION_MAJOR "${SDL2_IMAGE_VERSION_MAJOR_LINE}")
string(REGEX REPLACE "^#define[ \t]+SDL_IMAGE_MINOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_IMAGE_VERSION_MINOR "${SDL2_IMAGE_VERSION_MINOR_LINE}")
string(REGEX REPLACE "^#define[ \t]+SDL_IMAGE_PATCHLEVEL[ \t]+([0-9]+)$" "\\1" SDL2_IMAGE_VERSION_PATCH "${SDL2_IMAGE_VERSION_PATCH_LINE}")
set(SDL2_IMAGE_VERSION_STRING ${SDL2_IMAGE_VERSION_MAJOR}.${SDL2_IMAGE_VERSION_MINOR}.${SDL2_IMAGE_VERSION_PATCH})
unset(SDL2_IMAGE_VERSION_MAJOR_LINE)
unset(SDL2_IMAGE_VERSION_MINOR_LINE)
unset(SDL2_IMAGE_VERSION_PATCH_LINE)
unset(SDL2_IMAGE_VERSION_MAJOR)
unset(SDL2_IMAGE_VERSION_MINOR)
unset(SDL2_IMAGE_VERSION_PATCH)
endif()
set(SDL2_IMAGE_LIBRARIES ${SDL2_IMAGE_LIBRARY})
set(SDL2_IMAGE_INCLUDE_DIRS ${SDL2_IMAGE_INCLUDE_DIR})
include(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2_image
REQUIRED_VARS SDL2_IMAGE_LIBRARIES SDL2_IMAGE_INCLUDE_DIRS
VERSION_VAR SDL2_IMAGE_VERSION_STRING)
# for backward compatibility
set(SDLIMAGE_LIBRARY ${SDL2_IMAGE_LIBRARIES})
set(SDLIMAGE_INCLUDE_DIR ${SDL2_IMAGE_INCLUDE_DIRS})
set(SDLIMAGE_FOUND ${SDL2_IMAGE_FOUND})
mark_as_advanced(SDL2_IMAGE_LIBRARY SDL2_IMAGE_INCLUDE_DIR)

100
cmake/FindSDL2_mixer.cmake Normal file
View File

@ -0,0 +1,100 @@
# Locate SDL_MIXER library
#
# This module defines:
#
# ::
#
# SDL2_MIXER_LIBRARIES, the name of the library to link against
# SDL2_MIXER_INCLUDE_DIRS, where to find the headers
# SDL2_MIXER_FOUND, if false, do not try to link against
# SDL2_MIXER_VERSION_STRING - human-readable string containing the version of SDL_MIXER
#
#
#
# For backward compatibility the following variables are also set:
#
# ::
#
# SDLMIXER_LIBRARY (same value as SDL2_MIXER_LIBRARIES)
# SDLMIXER_INCLUDE_DIR (same value as SDL2_MIXER_INCLUDE_DIRS)
# SDLMIXER_FOUND (same value as SDL2_MIXER_FOUND)
#
#
#
# $SDLDIR is an environment variable that would correspond to the
# ./configure --prefix=$SDLDIR used in building SDL.
#
# Created by Eric Wing. This was influenced by the FindSDL.cmake
# module, but with modifications to recognize OS X frameworks and
# additional Unix paths (FreeBSD, etc).
#=============================================================================
# Copyright 2005-2009 Kitware, Inc.
# Copyright 2012 Benjamin Eikel
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
# (To distribute this file outside of CMake, substitute the full
# License text for the above reference.)
find_path(SDL2_MIXER_INCLUDE_DIR SDL_mixer.h
HINTS
ENV SDL2MIXERDIR
ENV SDL2DIR
PATH_SUFFIXES SDL2
# path suffixes to search inside ENV{SDLDIR}
include/SDL2 include
PATHS ${SDL2_MIXER_PATH}
)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(VC_LIB_PATH_SUFFIX lib/x64)
else()
set(VC_LIB_PATH_SUFFIX lib/x86)
endif()
find_library(SDL2_MIXER_LIBRARY
NAMES SDL2_mixer
HINTS
ENV SDL2MIXERDIR
ENV SDL2DIR
PATH_SUFFIXES lib bin ${VC_LIB_PATH_SUFFIX}
PATHS ${SDL2_MIXER_PATH}
)
if(SDL2_MIXER_INCLUDE_DIR AND EXISTS "${SDL2_MIXER_INCLUDE_DIR}/SDL_mixer.h")
file(STRINGS "${SDL2_MIXER_INCLUDE_DIR}/SDL_mixer.h" SDL2_MIXER_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SDL_MIXER_MAJOR_VERSION[ \t]+[0-9]+$")
file(STRINGS "${SDL2_MIXER_INCLUDE_DIR}/SDL_mixer.h" SDL2_MIXER_VERSION_MINOR_LINE REGEX "^#define[ \t]+SDL_MIXER_MINOR_VERSION[ \t]+[0-9]+$")
file(STRINGS "${SDL2_MIXER_INCLUDE_DIR}/SDL_mixer.h" SDL2_MIXER_VERSION_PATCH_LINE REGEX "^#define[ \t]+SDL_MIXER_PATCHLEVEL[ \t]+[0-9]+$")
string(REGEX REPLACE "^#define[ \t]+SDL_MIXER_MAJOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_MIXER_VERSION_MAJOR "${SDL2_MIXER_VERSION_MAJOR_LINE}")
string(REGEX REPLACE "^#define[ \t]+SDL_MIXER_MINOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_MIXER_VERSION_MINOR "${SDL2_MIXER_VERSION_MINOR_LINE}")
string(REGEX REPLACE "^#define[ \t]+SDL_MIXER_PATCHLEVEL[ \t]+([0-9]+)$" "\\1" SDL2_MIXER_VERSION_PATCH "${SDL2_MIXER_VERSION_PATCH_LINE}")
set(SDL2_MIXER_VERSION_STRING ${SDL2_MIXER_VERSION_MAJOR}.${SDL2_MIXER_VERSION_MINOR}.${SDL2_MIXER_VERSION_PATCH})
unset(SDL2_MIXER_VERSION_MAJOR_LINE)
unset(SDL2_MIXER_VERSION_MINOR_LINE)
unset(SDL2_MIXER_VERSION_PATCH_LINE)
unset(SDL2_MIXER_VERSION_MAJOR)
unset(SDL2_MIXER_VERSION_MINOR)
unset(SDL2_MIXER_VERSION_PATCH)
endif()
set(SDL2_MIXER_LIBRARIES ${SDL2_MIXER_LIBRARY})
set(SDL2_MIXER_INCLUDE_DIRS ${SDL2_MIXER_INCLUDE_DIR})
include(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2_mixer
REQUIRED_VARS SDL2_MIXER_LIBRARIES SDL2_MIXER_INCLUDE_DIRS
VERSION_VAR SDL2_MIXER_VERSION_STRING)
# for backward compatibility
set(SDLMIXER_LIBRARY ${SDL2_MIXER_LIBRARIES})
set(SDLMIXER_INCLUDE_DIR ${SDL2_MIXER_INCLUDE_DIRS})
set(SDLMIXER_FOUND ${SDL2_MIXER_FOUND})
mark_as_advanced(SDL2_MIXER_LIBRARY SDL2_MIXER_INCLUDE_DIR)

98
cmake/FindSDL2_ttf.cmake Normal file
View File

@ -0,0 +1,98 @@
# Locate SDL_ttf library
#
# This module defines:
#
# ::
#
# SDL2_TTF_LIBRARIES, the name of the library to link against
# SDL2_TTF_INCLUDE_DIRS, where to find the headers
# SDL2_TTF_FOUND, if false, do not try to link against
# SDL2_TTF_VERSION_STRING - human-readable string containing the version of SDL_ttf
#
#
#
# For backward compatibility the following variables are also set:
#
# ::
#
# SDLTTF_LIBRARY (same value as SDL2_TTF_LIBRARIES)
# SDLTTF_INCLUDE_DIR (same value as SDL2_TTF_INCLUDE_DIRS)
# SDLTTF_FOUND (same value as SDL2_TTF_FOUND)
#
#
#
# $SDLDIR is an environment variable that would correspond to the
# ./configure --prefix=$SDLDIR used in building SDL.
#
# Created by Eric Wing. This was influenced by the FindSDL.cmake
# module, but with modifications to recognize OS X frameworks and
# additional Unix paths (FreeBSD, etc).
#=============================================================================
# Copyright 2005-2009 Kitware, Inc.
# Copyright 2012 Benjamin Eikel
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
# (To distribute this file outside of CMake, substitute the full
# License text for the above reference.)
find_path(SDL2_TTF_INCLUDE_DIR SDL_ttf.h
HINTS
ENV SDL2TTFDIR
ENV SDL2DIR
PATH_SUFFIXES SDL2
# path suffixes to search inside ENV{SDLDIR}
include/SDL2 include
PATHS ${SDL2_TTF_PATH}
)
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
set(VC_LIB_PATH_SUFFIX lib/x64)
else ()
set(VC_LIB_PATH_SUFFIX lib/x86)
endif ()
find_library(SDL2_TTF_LIBRARY
NAMES SDL2_ttf
HINTS
ENV SDL2TTFDIR
ENV SDL2DIR
PATH_SUFFIXES lib ${VC_LIB_PATH_SUFFIX}
PATHS ${SDL2_TTF_PATH}
)
if (SDL2_TTF_INCLUDE_DIR AND EXISTS "${SDL2_TTF_INCLUDE_DIR}/SDL_ttf.h")
file(STRINGS "${SDL2_TTF_INCLUDE_DIR}/SDL_ttf.h" SDL2_TTF_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SDL_TTF_MAJOR_VERSION[ \t]+[0-9]+$")
file(STRINGS "${SDL2_TTF_INCLUDE_DIR}/SDL_ttf.h" SDL2_TTF_VERSION_MINOR_LINE REGEX "^#define[ \t]+SDL_TTF_MINOR_VERSION[ \t]+[0-9]+$")
file(STRINGS "${SDL2_TTF_INCLUDE_DIR}/SDL_ttf.h" SDL2_TTF_VERSION_PATCH_LINE REGEX "^#define[ \t]+SDL_TTF_PATCHLEVEL[ \t]+[0-9]+$")
string(REGEX REPLACE "^#define[ \t]+SDL_TTF_MAJOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_TTF_VERSION_MAJOR "${SDL2_TTF_VERSION_MAJOR_LINE}")
string(REGEX REPLACE "^#define[ \t]+SDL_TTF_MINOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_TTF_VERSION_MINOR "${SDL2_TTF_VERSION_MINOR_LINE}")
string(REGEX REPLACE "^#define[ \t]+SDL_TTF_PATCHLEVEL[ \t]+([0-9]+)$" "\\1" SDL2_TTF_VERSION_PATCH "${SDL2_TTF_VERSION_PATCH_LINE}")
set(SDL2_TTF_VERSION_STRING ${SDL2_TTF_VERSION_MAJOR}.${SDL2_TTF_VERSION_MINOR}.${SDL2_TTF_VERSION_PATCH})
unset(SDL2_TTF_VERSION_MAJOR_LINE)
unset(SDL2_TTF_VERSION_MINOR_LINE)
unset(SDL2_TTF_VERSION_PATCH_LINE)
unset(SDL2_TTF_VERSION_MAJOR)
unset(SDL2_TTF_VERSION_MINOR)
unset(SDL2_TTF_VERSION_PATCH)
endif ()
set(SDL2_TTF_LIBRARIES ${SDL2_TTF_LIBRARY})
set(SDL2_TTF_INCLUDE_DIRS ${SDL2_TTF_INCLUDE_DIR})
include(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2_ttf
REQUIRED_VARS SDL2_TTF_LIBRARIES SDL2_TTF_INCLUDE_DIRS
VERSION_VAR SDL2_TTF_VERSION_STRING)
# for backward compatibility
set(SDLTTF_LIBRARY ${SDL2_TTF_LIBRARIES})
set(SDLTTF_INCLUDE_DIR ${SDL2_TTF_INCLUDE_DIRS})
set(SDLTTF_FOUND ${SDL2_TTF_FOUND})

View File

@ -6,8 +6,7 @@ add_executable(OpenDiablo2
target_link_libraries(OpenDiablo2
PRIVATE
OpenDiablo2.OS
OpenDiablo2.Graphics
OpenDiablo2.SDL2
storm
CLI11
stdc++fs
@ -19,7 +18,7 @@ target_include_directories(OpenDiablo2
PRIVATE
include
../OpenDiablo2.OS/include
../OpenDiablo2.Graphics/include
../OpenDiablo2.SDL2/include
../../3rdparty/spdlog/include
../../3rdparty/stormlib/src
../../3rdparty/cli11/include

View File

@ -1,21 +1,26 @@
#ifndef OPENDIABLO2_D2ENGINE_H
#define OPENDIABLO2_D2ENGINE_H
#include <OpenDiablo2.OS/D2Window.h>
#include <OpenDiablo2.Graphics/D2Graphics.h>
#include <OpenDiablo2.System/D2Graphics.h>
#include <OpenDiablo2.System/D2Input.h>
#include "D2EngineConfig.h"
namespace OpenDiablo2 {
namespace Game {
class D2Engine {
public:
D2Engine();
D2Engine(const D2EngineConfig& config);
void Run();
private:
OpenDiablo2::OS::D2WindowPtr window;
OpenDiablo2::Graphics::D2GraphicsPtr gfx;
const D2EngineConfig config;
OpenDiablo2::System::D2Graphics::Ptr gfx;
OpenDiablo2::System::D2Input::Ptr input;
bool isRunning = true;
};
}
}
#endif //OPENDIABLO2_D2ENGINE_H

View File

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

View File

@ -1,21 +1,25 @@
#include <OpenDiablo2.Game/D2Engine.h>
OpenDiablo2::Game::D2Engine::D2Engine() {
window = std::make_unique<OpenDiablo2::OS::D2Window>();
gfx = std::make_unique<OpenDiablo2::Graphics::D2Graphics>();
OpenDiablo2::Game::D2Engine::D2Engine(const D2EngineConfig &config)
: config(config) {
gfx = std::make_unique<OpenDiablo2::System::D2Graphics>();
input = std::make_unique<OpenDiablo2::System::D2Input>();
}
void
OpenDiablo2::Game::D2Engine::Run() {
window->Initialize();
gfx->InitializeWindow();
while (window->WindowStillOpen()) {
window->PollEvents();
while (isRunning) {
input->ProcessEvents();
if (input->QuitIsRequested()) {
isRunning = false;
break;
}
gfx->Clear();
window->FlipBuffer();
gfx->Present();
}
window->Finalize();
}

View File

@ -7,33 +7,38 @@
#include <StormLib.h>
int
main(int argc, char** argv) {
main(int argc,
char** argv)
{
spdlog::set_level(spdlog::level::trace);
spdlog::set_pattern("[%^%l%$] %v");
spdlog::info("OpenDiablo 2 has started");
CLI::App app{"OpenDiablo2 - An open source re-implementation of Diablo 2."};
std::string basePath = std::experimental::filesystem::current_path();
app.add_option("-p,--path", basePath, "The base path for Diablo 2");
OpenDiablo2::Game::D2EngineConfig engineConfig;
engineConfig.BasePath = std::experimental::filesystem::current_path();
app.add_option("-p,--path", engineConfig.BasePath, "The base path for Diablo 2");
CLI11_PARSE(app, argc, argv);
spdlog::info("Base file path is '" + basePath + "'");
spdlog::info("Base file path is '" + engineConfig.BasePath + "'");
// Sanity-check that files are where we expect them to be...
auto testArchivePath = basePath + std::experimental::filesystem::path::preferred_separator + "d2data.mpq";
auto testFilePath = engineConfig.BasePath + std::experimental::filesystem::path::preferred_separator + "d2data.mpq";
HANDLE mpq = nullptr;
if (!SFileOpenArchive(("flat-file:" + testArchivePath).c_str(), 0, STREAM_FLAG_READ_ONLY, &mpq)) {
if (!SFileOpenArchive(("flat-file:" + testFilePath).c_str(), 0, STREAM_FLAG_READ_ONLY, &mpq)) {
spdlog::error("Diablo 2 content files were not detected. Please make sure the base path is properly set!");
exit(0);
}
SFileCloseFile(mpq);
spdlog::info("Content files were located, starting engine.");
auto engine = std::make_unique<OpenDiablo2::Game::D2Engine>();
// Start up the engine
auto engine = std::make_unique<OpenDiablo2::Game::D2Engine>(engineConfig);
engine->Run();
return 0;

View File

@ -1,28 +0,0 @@
project(OpenDiablo2.Graphics VERSION 0.1 LANGUAGES CXX)
find_package(OpenGL)
add_library(OpenDiablo2.Graphics SHARED
src/D2Graphics.cpp
)
target_include_directories(OpenDiablo2.Graphics
PUBLIC
include
PRIVATE
include
../../3rdparty/bgfx/include
../../3rdparty/spdlog/include
${OPENGL_INCLUDE_DIRS}
)
target_link_libraries(OpenDiablo2.Graphics
PRIVATE
${OPENGL_LIBRARIES}
)
if(MSVC)
target_compile_options(OpenDiablo2.Graphics PRIVATE /W4 /WX)
else(MSVC)
target_compile_options(OpenDiablo2.Graphics PRIVATE -Wall -Wextra -pedantic -Werror)
endif(MSVC)

View File

@ -1,21 +0,0 @@
#ifndef OPENDIABLO2_D2GRAPHICS_H
#define OPENDIABLO2_D2GRAPHICS_H
#include <memory>
namespace OpenDiablo2 {
namespace Graphics {
class D2Graphics {
public:
D2Graphics();
void Clear();
private:
};
typedef std::unique_ptr<D2Graphics> D2GraphicsPtr;
}
}
#endif //OPENDIABLO2_D2GRAPHICS_H

View File

@ -1,18 +0,0 @@
#include <OpenDiablo2.Graphics/D2Graphics.h>
#include <GL/gl.h>
#include "OpenDiablo2.Graphics/D2Graphics.h"
namespace OpenDiablo2 {
namespace Graphics {
D2Graphics::D2Graphics() = default;
void
D2Graphics::Clear() {
glClear(GL_COLOR_BUFFER_BIT);
}
}
}

View File

@ -1,25 +0,0 @@
project(libOpenDiablo2.OS VERSION 0.1 LANGUAGES CXX)
add_library(OpenDiablo2.OS SHARED
src/D2Window.cpp
)
target_include_directories(OpenDiablo2.OS
PUBLIC
include
PRIVATE
include
../../3rdparty/glfw/include
../../3rdparty/spdlog/include
)
target_link_libraries(OpenDiablo2.OS
PRIVATE
glfw
)
if(MSVC)
target_compile_options(OpenDiablo2.OS PRIVATE /W4 /WX)
else(MSVC)
target_compile_options(OpenDiablo2.OS PRIVATE -Wall -Wextra -pedantic -Werror)
endif(MSVC)

View File

@ -1,27 +0,0 @@
#ifndef OPENDIABLO2_WINDOW_H
#define OPENDIABLO2_WINDOW_H
#include <memory>
class GLFWwindow;
namespace OpenDiablo2 { namespace OS {
class D2Window {
public:
D2Window();
void Initialize();
void Finalize();
bool WindowStillOpen();
void FlipBuffer();
void PollEvents();
private:
GLFWwindow* glfwWindow;
};
typedef std::unique_ptr<D2Window> D2WindowPtr;
}}
#endif //OPENDIABLO2_WINDOW_H

View File

@ -1,52 +0,0 @@
#include <OpenDiablo2.OS/D2Window.h>
#include <spdlog/spdlog.h>
#include <GLFW/glfw3.h>
namespace OpenDiablo2 {
namespace OS {
D2Window::D2Window() = default;
void
D2Window::Initialize() {
spdlog::debug("Initializing D2Window");
spdlog::debug("Initializing GLFW");
if (!glfwInit()) {
spdlog::error("Initializing D2Window");
throw std::runtime_error(
"GLFW could not initialize the host window.");
}
spdlog::debug("Creating GLFW window");
glfwWindowHint(GLFW_RESIZABLE, 0);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
glfwWindow = glfwCreateWindow(800, 600, "OpenDiablo 2", nullptr, nullptr);
}
void
D2Window::Finalize() {
spdlog::debug("Destroying GLFW window");
glfwDestroyWindow(glfwWindow);
spdlog::debug("Terminating GLFW");
glfwTerminate();
}
bool
D2Window::WindowStillOpen() {
return !glfwWindowShouldClose(glfwWindow);
}
void
D2Window::PollEvents() {
glfwPollEvents();
}
void
D2Window::FlipBuffer() {
glfwSwapBuffers(glfwWindow);
}
}
}

View File

@ -0,0 +1,32 @@
project(OpenDiablo2.SDL2 VERSION 0.1 LANGUAGES CXX)
add_library(OpenDiablo2.SDL2 SHARED
src/D2Graphics.cpp
src/D2Input.cpp
)
find_package(SDL2 REQUIRED)
find_package(SDL2_image REQUIRED)
target_include_directories(OpenDiablo2.SDL2
PUBLIC
include
PRIVATE
include
../../3rdparty/bgfx/include
../../3rdparty/spdlog/include
${SDL2_INCLUDE_DIR}
${SDL2_IMAGE_INCLUDE_DIR}
)
target_link_libraries(OpenDiablo2.SDL2
PUBLIC
${SDL2_LIBRARY}
${SDL2_IMAGE_LIBRARIES}
)
if(MSVC)
target_compile_options(OpenDiablo2.SDL2 PRIVATE /W4 /WX)
else(MSVC)
target_compile_options(OpenDiablo2.SDL2 PRIVATE -Wall -Wextra -pedantic -Werror)
endif(MSVC)

View File

@ -0,0 +1,44 @@
#ifndef OPENDIABLO2_D2GRAPHICS_H
#define OPENDIABLO2_D2GRAPHICS_H
#include <memory>
#include <SDL2/SDL.h>
#include <spdlog/spdlog.h>
namespace OpenDiablo2 {
namespace System {
struct SDLWindowDestroyer
{
void operator()(SDL_Window* w) const
{
spdlog::debug("Destroying SDL window");
if (w) SDL_DestroyWindow(w);
}
};
struct SDLRendererDestroyer
{
void operator()(SDL_Renderer* r) const
{
spdlog::debug("Destroying SDL renderer");
if (r) SDL_DestroyRenderer(r);
}
};
class D2Graphics {
public:
typedef std::unique_ptr<D2Graphics> Ptr;
D2Graphics();
void InitializeWindow();
void Clear();
void Present();
private:
std::unique_ptr<SDL_Window, SDLWindowDestroyer> window;
std::unique_ptr<SDL_Renderer, SDLRendererDestroyer> renderer;
};
}
}
#endif //OPENDIABLO2_D2GRAPHICS_H

View File

@ -0,0 +1,23 @@
#ifndef OPENDIABLO2_D2INPUT_H
#define OPENDIABLO2_D2INPUT_H
#include <memory>
namespace OpenDiablo2 {
namespace System {
class D2Input {
public:
typedef std::unique_ptr<D2Input> Ptr;
D2Input();
void ProcessEvents();
bool QuitIsRequested();
private:
bool quitIsRequested = false;
};
}
}
#endif //OPENDIABLO2_D2INPUT_H

View File

@ -0,0 +1,53 @@
#include <OpenDiablo2.System/D2Graphics.h>
#include <spdlog/spdlog.h>
#include <string>
#include <SDL2/SDL.h>
#include "OpenDiablo2.System/D2Graphics.h"
namespace OpenDiablo2 {
namespace System {
D2Graphics::D2Graphics() {
atexit(SDL_Quit);
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
spdlog::error("Could not initialize sdl2: " + std::string(SDL_GetError()));
exit(1);
}
}
void
D2Graphics::Clear() {
SDL_RenderClear(renderer.get());
}
void
D2Graphics::InitializeWindow() {
spdlog::debug("Initializing SDL window");
window = std::unique_ptr<SDL_Window, SDLWindowDestroyer>(SDL_CreateWindow("OpenDiablo 2", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
800, 600, SDL_WINDOW_SHOWN));
if (window == nullptr) {
spdlog::error("Could not create sdl2 window: " + std::string(SDL_GetError()));
SDL_Quit();
exit(1);
}
spdlog::debug("Destroying SDL renderer");
renderer = std::unique_ptr<SDL_Renderer, SDLRendererDestroyer>(SDL_CreateRenderer(window.get(), -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC));
if (renderer == nullptr){
spdlog::error("Could not create sdl2 window: " + std::string(SDL_GetError()));
SDL_Quit();
exit(1);
}
}
void
D2Graphics::Present() {
SDL_RenderPresent(renderer.get());
}
}
}

View File

@ -0,0 +1,27 @@
#include <OpenDiablo2.System/D2Input.h>
#include <SDL2/SDL.h>
namespace OpenDiablo2 {
namespace System {
D2Input::D2Input() {
SDL_Init(SDL_INIT_EVENTS);
}
void
D2Input::ProcessEvents() {
SDL_Event event;
while (SDL_PollEvent(&event)) {
if( event.type == SDL_QUIT ) {
quitIsRequested = true;
}
}
}
bool
D2Input::QuitIsRequested() {
return quitIsRequested;
}
}
}