Convert back to a static library

This commit is contained in:
Bailey Harrison 2022-10-02 16:34:51 +01:00
parent 50ca206428
commit d7a79abb1c
10 changed files with 751 additions and 720 deletions

View File

@ -6,7 +6,7 @@ project(engine LANGUAGES CXX
VERSION "0.1.0" VERSION "0.1.0"
) )
add_library(${PROJECT_NAME} SHARED add_library(${PROJECT_NAME} STATIC
"src/engine.cpp" "src/engine.cpp"
"src/window.cpp" "src/window.cpp"
@ -74,6 +74,8 @@ add_library(${PROJECT_NAME} SHARED
target_compile_definitions(${PROJECT_NAME} PRIVATE DEFINITIONS "ENGINE_EXPORTS") target_compile_definitions(${PROJECT_NAME} PRIVATE DEFINITIONS "ENGINE_EXPORTS")
set_property(TARGET ${PROJECT_NAME} PROPERTY WINDOWS_EXPORT_ALL_SYMBOLS ON)
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 20) set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 20)
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD_REQUIRED ON) set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD_REQUIRED ON)
@ -143,8 +145,8 @@ add_subdirectory(dependencies/glm)
target_include_directories(${PROJECT_NAME} PUBLIC dependencies/glm) target_include_directories(${PROJECT_NAME} PUBLIC dependencies/glm)
# spdlog # spdlog
set(SPDLOG_BUILD_SHARED ON CACHE INTERNAL "" FORCE) set(SPDLOG_BUILD_SHARED OFF CACHE INTERNAL "" FORCE)
set(BUILD_SHARED_LIBS ON) set(BUILD_SHARED_LIBS OFF)
add_subdirectory(dependencies/spdlog) add_subdirectory(dependencies/spdlog)
target_link_libraries(${PROJECT_NAME} PUBLIC spdlog) target_link_libraries(${PROJECT_NAME} PUBLIC spdlog)
target_include_directories(${PROJECT_NAME} PUBLIC dependencies/spdlog/include) target_include_directories(${PROJECT_NAME} PUBLIC dependencies/spdlog/include)

View File

@ -2,9 +2,12 @@
#include "engine_api.h" #include "engine_api.h"
class Object; namespace engine {
class Window; class Window;
class Input; class Input;
}
class Object;
class ResourceManager; class ResourceManager;
class ENGINE_API Component { class ENGINE_API Component {
@ -30,8 +33,8 @@ public:
Object& parent; Object& parent;
protected: protected:
Window& win; engine::Window& win;
Input& inp; engine::Input& inp;
ResourceManager& res; ResourceManager& res;
private: private:

View File

@ -11,3 +11,5 @@
# define ENGINE_API # define ENGINE_API
# endif # endif
#endif #endif
#define ENGINE_API

View File

@ -8,7 +8,7 @@
struct SDL_Window; struct SDL_Window;
namespace engine::gfx { namespace engine {
class ENGINE_API GFXDevice { class ENGINE_API GFXDevice {

View File

@ -9,6 +9,8 @@
#include <array> #include <array>
#include <string> #include <string>
namespace engine {
class Window; class Window;
enum class InputDevice : int { enum class InputDevice : int {
@ -87,3 +89,5 @@ private:
void addInputButtonAsAxis(const std::string& name, InputDevice device, int high, int low); void addInputButtonAsAxis(const std::string& name, InputDevice device, int high, int low);
}; };
}

View File

@ -12,8 +12,10 @@
#include <memory> #include <memory>
#include <stdexcept> #include <stdexcept>
namespace engine {
class Window; class Window;
class Input; class Input;
}
class ResourceManager; class ResourceManager;
class SceneRoot; class SceneRoot;
@ -28,8 +30,8 @@ namespace components {
} }
struct GameIO { struct GameIO {
Window * const win; engine::Window * const win;
Input * const input; engine::Input * const input;
ResourceManager * const resMan; ResourceManager * const resMan;
}; };
@ -43,8 +45,8 @@ public:
Object& operator=(const Object&) = delete; Object& operator=(const Object&) = delete;
~Object(); ~Object();
Window& win; engine::Window& win;
Input& inp; engine::Input& inp;
ResourceManager& res; ResourceManager& res;
SceneRoot& root; SceneRoot& root;

View File

@ -17,6 +17,8 @@
ENGINE_API extern const uint64_t BILLION; ENGINE_API extern const uint64_t BILLION;
namespace engine {
class ENGINE_API Window { class ENGINE_API Window {
public: public:
@ -197,3 +199,5 @@ private:
void onMouseMotionEvent(SDL_MouseMotionEvent& e); void onMouseMotionEvent(SDL_MouseMotionEvent& e);
void onMouseWheelEvent(SDL_MouseWheelEvent& e); void onMouseWheelEvent(SDL_MouseWheelEvent& e);
}; };
}

View File

@ -14,11 +14,12 @@
#include <assert.h> #include <assert.h>
#include <array>
#include <iostream> #include <iostream>
#include <optional> #include <optional>
#include <unordered_set> #include <unordered_set>
namespace engine::gfx { namespace engine {
static std::vector<const char*> getRequiredVulkanExtensions(SDL_Window* window) static std::vector<const char*> getRequiredVulkanExtensions(SDL_Window* window)
{ {

View File

@ -5,6 +5,8 @@
#include <string> #include <string>
#include <stdexcept> #include <stdexcept>
namespace engine {
Input::Input(const Window& win) : m_win(win) Input::Input(const Window& win) : m_win(win)
{ {
m_enabledDevices.fill(true); m_enabledDevices.fill(true);
@ -170,7 +172,8 @@ float Input::getAxis(const std::string& axisName) const
if (m_enabledDevices[static_cast<int>(e.device)]) { if (m_enabledDevices[static_cast<int>(e.device)]) {
if (e.isButtonAxis) { if (e.isButtonAxis) {
return getButtonAxis(e.device, e.high, e.low); return getButtonAxis(e.device, e.high, e.low);
} else { }
else {
return getDeviceAxis(e.device, e.axis); return getDeviceAxis(e.device, e.axis);
} }
} }
@ -230,3 +233,5 @@ bool Input::getButtonRelease(const std::string& buttonName) const
} }
return isReleased; return isReleased;
} }
}

View File

@ -7,6 +7,8 @@
const uint64_t BILLION = 1000000000; const uint64_t BILLION = 1000000000;
namespace engine {
Window::Window(const std::string& title) : m_title(title) Window::Window(const std::string& title) : m_title(title)
{ {
@ -168,7 +170,8 @@ void Window::onMouseWheelEvent(SDL_MouseWheelEvent &e)
if (e.direction == SDL_MOUSEWHEEL_NORMAL) { if (e.direction == SDL_MOUSEWHEEL_NORMAL) {
m_mouse.xscroll = e.preciseX; m_mouse.xscroll = e.preciseX;
m_mouse.yscroll = e.preciseY; m_mouse.yscroll = e.preciseY;
} else { // flipped }
else { // flipped
m_mouse.xscroll = -e.preciseX; m_mouse.xscroll = -e.preciseX;
m_mouse.yscroll = -e.preciseY; m_mouse.yscroll = -e.preciseY;
} }
@ -297,7 +300,8 @@ bool Window::setRelativeMouseMode(bool enabled)
int code = SDL_SetRelativeMouseMode(static_cast<SDL_bool>(enabled)); int code = SDL_SetRelativeMouseMode(static_cast<SDL_bool>(enabled));
if (code != 0) { if (code != 0) {
throw std::runtime_error("Unable to set relative mouse mode"); throw std::runtime_error("Unable to set relative mouse mode");
} else { }
else {
return true; return true;
} }
} }
@ -391,7 +395,8 @@ uint64_t Window::getNanos() const
count = SDL_GetPerformanceCounter(); count = SDL_GetPerformanceCounter();
if (m_counterFreq == BILLION) { if (m_counterFreq == BILLION) {
return count; return count;
} else { }
else {
return count * (BILLION / m_counterFreq); return count * (BILLION / m_counterFreq);
} }
} }
@ -440,7 +445,8 @@ bool Window::infoBox(const std::string& title, const std::string& msg)
if (isFullscreen() == false) { if (isFullscreen() == false) {
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_INFORMATION, title.c_str(), msg.c_str(), m_handle); SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_INFORMATION, title.c_str(), msg.c_str(), m_handle);
return true; return true;
} else { }
else {
return false; return false;
} }
} }
@ -452,3 +458,5 @@ void Window::errorBox(const std::string& message)
{ {
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Game Error", message.c_str(), NULL); SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Game Error", message.c_str(), NULL);
} }
}