Changing engine to shared library

This commit is contained in:
Dynamitos
2023-08-26 15:19:12 +02:00
parent 4ab924f251
commit dcbce27fb2
20 changed files with 93 additions and 47 deletions
+2 -6
View File
@@ -12,6 +12,7 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_COMPILE_WARNING_AS_ERROR OFF) set(CMAKE_COMPILE_WARNING_AS_ERROR OFF)
set(CMAKE_INSTALL_MESSAGE LAZY) set(CMAKE_INSTALL_MESSAGE LAZY)
set(BUILD_SHARED_LIBS OFF) set(BUILD_SHARED_LIBS OFF)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
set(ENGINE_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/src/Engine) set(ENGINE_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/src/Engine)
set(EXTERNAL_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/external) set(EXTERNAL_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/external)
@@ -49,11 +50,6 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_CURRENT_SOURCE_DIR}/bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_CURRENT_SOURCE_DIR}/bin) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_CURRENT_SOURCE_DIR}/bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${CMAKE_CURRENT_SOURCE_DIR}/bin) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${CMAKE_CURRENT_SOURCE_DIR}/bin)
set(Boost_USE_STATIC_LIBS OFF)
if(WIN32)
set(Boost_LIB_PREFIX lib)
endif()
find_package(Vulkan REQUIRED) find_package(Vulkan REQUIRED)
if(WIN32) if(WIN32)
@@ -64,7 +60,7 @@ if(CMAKE_DEBUG_POSTFIX)
add_compile_definitions(SEELE_DEBUG) add_compile_definitions(SEELE_DEBUG)
endif() endif()
add_library(Engine STATIC "") add_library(Engine SHARED "")
target_compile_definitions(Engine PRIVATE GLFW_WINDOWS) target_compile_definitions(Engine PRIVATE GLFW_WINDOWS)
target_include_directories(Engine PRIVATE src/Engine) target_include_directories(Engine PRIVATE src/Engine)
+14 -2
View File
@@ -8,8 +8,20 @@
"generator": "Visual Studio 17 2022 Win64", "generator": "Visual Studio 17 2022 Win64",
"intelliSenseMode": "windows-msvc-x64", "intelliSenseMode": "windows-msvc-x64",
"inheritEnvironments": [ "msvc_x64" ], "inheritEnvironments": [ "msvc_x64" ],
"cmakeCommandArgs": "-DCMAKE_DEBUG_POSTFIX=d -DCMAKE_PLATFORM=x64 -DCMAKE_BUILD_TYPE=Debug", "cmakeCommandArgs": "-DCMAKE_DEBUG_POSTFIX=\"\" -DCMAKE_PLATFORM=x64",
"buildRoot": "C:/Users/Dynamitos/Seele/bin/Debug" "buildRoot": "C:/Users/Dynamitos/Seele/bin/",
"installRoot": "C:/Program Files/Seele"
},
{
"name": "Release",
"generator": "Visual Studio 17 2022 Win64",
"configurationType": "RelWithDebInfo",
"buildRoot": "C:/Users/Dynamitos/Seele/bin/",
"cmakeCommandArgs": "-DCMAKE_DEBUG_POSTFIX=\"\" -DCMAKE_PLATFORM=x64",
"buildCommandArgs": "",
"ctestCommandArgs": "",
"inheritEnvironments": [ "msvc_x64" ],
"intelliSenseMode": "windows-msvc-x64"
} }
] ]
} }
+2
View File
@@ -26,6 +26,8 @@ set(KTX_FEATURE_TOOLS off)
add_subdirectory(${KTX_ROOT} ${KTX_ROOT}) add_subdirectory(${KTX_ROOT} ${KTX_ROOT})
target_compile_options(ktx PUBLIC /WX-)
#--------------------JSON------------------ #--------------------JSON------------------
set(JSON_MultipleHeaders ON CACHE INTERNAL "") set(JSON_MultipleHeaders ON CACHE INTERNAL "")
set(JSON_BuildTests OFF CACHE INTERNAL "") set(JSON_BuildTests OFF CACHE INTERNAL "")
+1 -1
+1 -1
+2 -2
View File
@@ -27,7 +27,7 @@ SceneView::SceneView(Gfx::PGraphics graphics, PWindow owner, const ViewportCreat
//AssetRegistry::importFile("D:\\Private\\Programming\\Unreal Engine\\Assets\\Cube\\cube.obj"); //AssetRegistry::importFile("D:\\Private\\Programming\\Unreal Engine\\Assets\\Cube\\cube.obj");
//AssetRegistry::importFile("D:\\Private\\Programming\\Unreal Engine\\Assets\\Plane\\plane.fbx"); //AssetRegistry::importFile("D:\\Private\\Programming\\Unreal Engine\\Assets\\Plane\\plane.fbx");
cameraSystem.update(viewportCamera, static_cast<float>(Gfx::currentFrameDelta)); cameraSystem.update(viewportCamera, static_cast<float>(Gfx::getCurrentFrameDelta()));
renderGraph.updateViewport(viewport); renderGraph.updateViewport(viewport);
} }
@@ -43,7 +43,7 @@ void SceneView::beginUpdate()
void SceneView::update() void SceneView::update()
{ {
cameraSystem.update(viewportCamera, static_cast<float>(Gfx::currentFrameDelta)); cameraSystem.update(viewportCamera, static_cast<float>(Gfx::getCurrentFrameDelta()));
//co_return; //co_return;
} }
+1 -1
View File
@@ -31,7 +31,7 @@ int main()
graphics->init(initializer); graphics->init(initializer);
PWindowManager windowManager = new WindowManager(); PWindowManager windowManager = new WindowManager();
AssetRegistry::init(std::string("C:/Users/Dynamitos/TrackClear/Assets"), graphics); AssetRegistry::init(std::string("C:/Users/Dynamitos/TrackClear/Assets"), graphics);
AssetImporter::init(graphics, instance); AssetImporter::init(graphics, AssetRegistry::getInstance());
AssetImporter::importFont(FontImportArgs{ AssetImporter::importFont(FontImportArgs{
.filePath = "./fonts/Calibri.ttf", .filePath = "./fonts/Calibri.ttf",
}); });
+7 -1
View File
@@ -10,10 +10,11 @@
#include "MeshAsset.h" #include "MeshAsset.h"
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
#include <iostream> #include <iostream>
#include <fstream>
using namespace Seele; using namespace Seele;
extern AssetRegistry* instance; AssetRegistry* instance = new AssetRegistry();
AssetRegistry::~AssetRegistry() AssetRegistry::~AssetRegistry()
{ {
@@ -96,6 +97,11 @@ AssetRegistry::AssetRegistry()
{ {
} }
AssetRegistry* AssetRegistry::getInstance()
{
return instance;
}
void AssetRegistry::loadRegistry() void AssetRegistry::loadRegistry()
{ {
get().loadRegistryInternal(); get().loadRegistryInternal();
+1
View File
@@ -45,6 +45,7 @@ public:
}; };
AssetFolder* getOrCreateFolder(std::string foldername); AssetFolder* getOrCreateFolder(std::string foldername);
AssetRegistry(); AssetRegistry();
static AssetRegistry* getInstance();
private: private:
static AssetRegistry& get(); static AssetRegistry& get();
+8 -6
View File
@@ -233,36 +233,38 @@ void ShapeBase::addCollider(Array<Vector> verts, Array<uint32> inds, Matrix4 mat
void ShapeBase::visualize() const void ShapeBase::visualize() const
{ {
Array<DebugVertex> verts;
for(uint32 i = 0; i < indices.size(); i+=3) for(uint32 i = 0; i < indices.size(); i+=3)
{ {
gDebugVertices.add(DebugVertex{ verts.add(DebugVertex{
.position = Vector(vertices[indices[i+0]]), .position = Vector(vertices[indices[i+0]]),
.color = Vector(1, 0, 0), .color = Vector(1, 0, 0),
}); });
gDebugVertices.add(DebugVertex{ verts.add(DebugVertex{
.position = Vector(vertices[indices[i+1]]), .position = Vector(vertices[indices[i+1]]),
.color = Vector(1, 0, 0), .color = Vector(1, 0, 0),
}); });
gDebugVertices.add(DebugVertex{ verts.add(DebugVertex{
.position = Vector(vertices[indices[i+1]]), .position = Vector(vertices[indices[i+1]]),
.color = Vector(1, 0, 0), .color = Vector(1, 0, 0),
}); });
gDebugVertices.add(DebugVertex{ verts.add(DebugVertex{
.position = Vector(vertices[indices[i+2]]), .position = Vector(vertices[indices[i+2]]),
.color = Vector(1, 0, 0), .color = Vector(1, 0, 0),
}); });
gDebugVertices.add(DebugVertex{ verts.add(DebugVertex{
.position = Vector(vertices[indices[i+2]]), .position = Vector(vertices[indices[i+2]]),
.color = Vector(1, 0, 0), .color = Vector(1, 0, 0),
}); });
gDebugVertices.add(DebugVertex{ verts.add(DebugVertex{
.position = Vector(vertices[indices[i+0]]), .position = Vector(vertices[indices[i+0]]),
.color = Vector(1, 0, 0), .color = Vector(1, 0, 0),
}); });
} }
addDebugVertices(std::move(verts));
} }
+2 -1
View File
@@ -9,5 +9,6 @@ struct DebugVertex
Vector position; Vector position;
Vector color; Vector color;
}; };
extern Array<DebugVertex> gDebugVertices; void addDebugVertex(DebugVertex vert);
void addDebugVertices(Array<DebugVertex> vert);
} // namespace Seele } // namespace Seele
-2
View File
@@ -3,8 +3,6 @@
using namespace Seele; using namespace Seele;
using namespace Seele::Gfx; using namespace Seele::Gfx;
uint32 Gfx::currentFrameIndex = 0;
double Gfx::currentFrameDelta = 0;
FormatCompatibilityInfo Gfx::getFormatInfo(SeFormat format) FormatCompatibilityInfo Gfx::getFormatInfo(SeFormat format)
{ {
+1 -2
View File
@@ -166,8 +166,7 @@ namespace Gfx
static constexpr bool useAsyncCompute = true; static constexpr bool useAsyncCompute = true;
static constexpr bool waitIdleOnSubmit = true; static constexpr bool waitIdleOnSubmit = true;
static constexpr uint32 numFramesBuffered = 8; static constexpr uint32 numFramesBuffered = 8;
extern uint32 currentFrameIndex; double getCurrentFrameDelta();
extern double currentFrameDelta;
enum class MaterialShadingModel enum class MaterialShadingModel
{ {
+11 -1
View File
@@ -3,7 +3,17 @@
using namespace Seele; using namespace Seele;
Array<DebugVertex> Seele::gDebugVertices; Array<DebugVertex> gDebugVertices;
void Seele::addDebugVertex(DebugVertex vert)
{
gDebugVertices.add(vert);
}
void Seele::addDebugVertices(Array<DebugVertex> verts)
{
gDebugVertices.addAll(verts);
}
DebugPass::DebugPass(Gfx::PGraphics graphics) DebugPass::DebugPass(Gfx::PGraphics graphics)
: RenderPass(graphics) : RenderPass(graphics)
+10 -2
View File
@@ -8,6 +8,12 @@
using namespace Seele; using namespace Seele;
using namespace Seele::Vulkan; using namespace Seele::Vulkan;
double currentFrameDelta = 0;
double Gfx::getCurrentFrameDelta()
{
return currentFrameDelta;
}
void glfwKeyCallback(GLFWwindow* handle, int key, int, int action, int modifier) void glfwKeyCallback(GLFWwindow* handle, int key, int, int action, int modifier)
{ {
Window* window = (Window*)glfwGetWindowUserPointer(handle); Window* window = (Window*)glfwGetWindowUserPointer(handle);
@@ -209,6 +215,8 @@ void Window::recreateSwapchain(const WindowCreateInfo &windowInfo)
createSwapchain(); createSwapchain();
} }
static uint32_t currentFrameIndex = 0;
void Window::present() void Window::present()
{ {
backBufferImages[currentImageIndex]->changeLayout(Gfx::SE_IMAGE_LAYOUT_PRESENT_SRC_KHR); backBufferImages[currentImageIndex]->changeLayout(Gfx::SE_IMAGE_LAYOUT_PRESENT_SRC_KHR);
@@ -230,11 +238,11 @@ void Window::present()
{ {
presentResult = vkQueuePresentKHR(graphics->getGraphicsCommands()->getQueue()->getHandle(), &info); presentResult = vkQueuePresentKHR(graphics->getGraphicsCommands()->getQueue()->getHandle(), &info);
} }
Gfx::currentFrameIndex = (Gfx::currentFrameIndex + 1)%Gfx::numFramesBuffered; currentFrameIndex = (currentFrameIndex + 1) % Gfx::numFramesBuffered;
static double lastFrameTime = 0.f; static double lastFrameTime = 0.f;
double currentTime = glfwGetTime(); double currentTime = glfwGetTime();
double currentDelta = currentTime - lastFrameTime; double currentDelta = currentTime - lastFrameTime;
Gfx::currentFrameDelta = currentDelta; currentFrameDelta = currentDelta;
lastFrameTime = currentTime; lastFrameTime = currentTime;
} }
+12 -2
View File
@@ -1,4 +1,14 @@
#include "MinimalEngine.h" #include "MinimalEngine.h"
#include <mutex>
std::map<void *, void *> registeredObjects; std::map<void*, void*>& getRegisteredObjects()
std::mutex registeredObjectsLock; {
static std::map<void*, void*> map;
return map;
}
std::mutex& getRegisteredObjectLock()
{
static std::mutex lock;
return lock;
}
+9 -8
View File
@@ -23,8 +23,9 @@
typedef WeakPtr<x> W##x; \ typedef WeakPtr<x> W##x; \
} }
extern std::map<void *, void *> registeredObjects; std::map<void*, void*>& getRegisteredObjects();
extern std::mutex registeredObjectsLock; std::mutex& getRegisteredObjectLock();
namespace Seele namespace Seele
{ {
template <typename T, typename Deleter> template <typename T, typename Deleter>
@@ -47,8 +48,8 @@ public:
~RefObject() ~RefObject()
{ {
{ {
std::scoped_lock lock(registeredObjectsLock); std::scoped_lock lock(getRegisteredObjectLock());
registeredObjects.erase(handle); getRegisteredObjects().erase(handle);
} }
// #pragma warning( disable: 4150) // #pragma warning( disable: 4150)
deleter(handle); deleter(handle);
@@ -112,14 +113,14 @@ public:
} }
constexpr RefPtr(T *ptr, Deleter deleter = Deleter()) constexpr RefPtr(T *ptr, Deleter deleter = Deleter())
{ {
std::scoped_lock l(registeredObjectsLock); std::scoped_lock l(getRegisteredObjectLock());
auto registeredObj = registeredObjects.find(ptr); auto registeredObj = getRegisteredObjects().find(ptr);
// get here for thread safetly // get here for thread safetly
auto registeredEnd = registeredObjects.end(); auto registeredEnd = getRegisteredObjects().end();
if (registeredObj == registeredEnd) if (registeredObj == registeredEnd)
{ {
object = new RefObject<T, Deleter>(ptr, std::move(deleter)); object = new RefObject<T, Deleter>(ptr, std::move(deleter));
registeredObjects[ptr] = object; getRegisteredObjects()[ptr] = object;
} }
else else
{ {
+4 -2
View File
@@ -49,14 +49,16 @@ void BVH::colliderCallback(entt::registry& registry, entt::entity entity)
void BVH::visualize() void BVH::visualize()
{ {
Array<DebugVertex> verts;
for (const auto& node : staticNodes) for (const auto& node : staticNodes)
{ {
node.box.visualize(gDebugVertices); node.box.visualize(verts);
} }
for (const auto& node : dynamicNodes) for (const auto& node : dynamicNodes)
{ {
node.box.visualize(gDebugVertices); node.box.visualize(verts);
} }
addDebugVertices(verts);
} }
void BVH::traverseStaticTree(const AABB& aabb, entt::entity source, int32 nodeIndex, Array<Pair<entt::entity, entt::entity>>& overlaps) void BVH::traverseStaticTree(const AABB& aabb, entt::entity source, int32 nodeIndex, Array<Pair<entt::entity, entt::entity>>& overlaps)
+2 -2
View File
@@ -284,11 +284,11 @@ void PhysicsSystem::calculateContacts(entt::entity id1, const ShapeBase& shape1,
const Vector v1 = point2 - point1; const Vector v1 = point2 - point1;
const Vector v2 = point3 - point1; const Vector v2 = point3 - point1;
const Vector faceNormal = glm::normalize(glm::cross(v1, v2)); const Vector faceNormal = glm::normalize(glm::cross(v1, v2));
Seele::gDebugVertices.add(DebugVertex{ addDebugVertex(DebugVertex{
.position = (point1 + point2 + point3) / 3.f, .position = (point1 + point2 + point3) / 3.f,
.color = Vector(1, 0, 0) .color = Vector(1, 0, 0)
}); });
Seele::gDebugVertices.add(DebugVertex{ addDebugVertex(DebugVertex{
.position = faceNormal + (point1 + point2 + point3) / 3.f, .position = faceNormal + (point1 + point2 + point3) / 3.f,
.color = Vector(1, 0, 0) .color = Vector(1, 0, 0)
}); });
+1 -3
View File
@@ -7,8 +7,6 @@
using namespace Seele; using namespace Seele;
AssetRegistry* instance = new AssetRegistry();
GameView::GameView(Gfx::PGraphics graphics, PWindow window, const ViewportCreateInfo &createInfo, std::string dllPath) GameView::GameView(Gfx::PGraphics graphics, PWindow window, const ViewportCreateInfo &createInfo, std::string dllPath)
: View(graphics, window, createInfo, "Game") : View(graphics, window, createInfo, "Game")
, gameInterface(dllPath) , gameInterface(dllPath)
@@ -73,7 +71,7 @@ void GameView::render()
void GameView::reloadGame() void GameView::reloadGame()
{ {
scene = new Scene(graphics); scene = new Scene(graphics);
gameInterface.reload(instance); gameInterface.reload(AssetRegistry::getInstance());
systemGraph = new SystemGraph(); systemGraph = new SystemGraph();
gameInterface.getGame()->setupScene(scene, systemGraph); gameInterface.getGame()->setupScene(scene, systemGraph);