diff --git a/CMakeLists.txt b/CMakeLists.txt index 6a83b8f..244bbc8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,6 +12,7 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set(CMAKE_COMPILE_WARNING_AS_ERROR OFF) set(CMAKE_INSTALL_MESSAGE LAZY) set(BUILD_SHARED_LIBS OFF) +set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) set(ENGINE_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/src/Engine) 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_RELWITHDEBINFO ${CMAKE_CURRENT_SOURCE_DIR}/bin) -set(Boost_USE_STATIC_LIBS OFF) -if(WIN32) - set(Boost_LIB_PREFIX lib) -endif() - find_package(Vulkan REQUIRED) if(WIN32) @@ -64,7 +60,7 @@ if(CMAKE_DEBUG_POSTFIX) add_compile_definitions(SEELE_DEBUG) endif() -add_library(Engine STATIC "") +add_library(Engine SHARED "") target_compile_definitions(Engine PRIVATE GLFW_WINDOWS) target_include_directories(Engine PRIVATE src/Engine) diff --git a/CMakeSettings.json b/CMakeSettings.json index 9dd9604..7a80985 100644 --- a/CMakeSettings.json +++ b/CMakeSettings.json @@ -8,8 +8,20 @@ "generator": "Visual Studio 17 2022 Win64", "intelliSenseMode": "windows-msvc-x64", "inheritEnvironments": [ "msvc_x64" ], - "cmakeCommandArgs": "-DCMAKE_DEBUG_POSTFIX=d -DCMAKE_PLATFORM=x64 -DCMAKE_BUILD_TYPE=Debug", - "buildRoot": "C:/Users/Dynamitos/Seele/bin/Debug" + "cmakeCommandArgs": "-DCMAKE_DEBUG_POSTFIX=\"\" -DCMAKE_PLATFORM=x64", + "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" } ] } \ No newline at end of file diff --git a/cmake/SuperBuild.cmake b/cmake/SuperBuild.cmake index 6e2062a..6349bcb 100644 --- a/cmake/SuperBuild.cmake +++ b/cmake/SuperBuild.cmake @@ -26,6 +26,8 @@ set(KTX_FEATURE_TOOLS off) add_subdirectory(${KTX_ROOT} ${KTX_ROOT}) +target_compile_options(ktx PUBLIC /WX-) + #--------------------JSON------------------ set(JSON_MultipleHeaders ON CACHE INTERNAL "") set(JSON_BuildTests OFF CACHE INTERNAL "") diff --git a/external/json b/external/json index e110667..bc889af 160000 --- a/external/json +++ b/external/json @@ -1 +1 @@ -Subproject commit e110667d210698b5df3341244bfb4c454ac392f1 +Subproject commit bc889afb4c5bf1c0d8ee29ef35eaaf4c8bef8a5d diff --git a/external/ktx b/external/ktx index 7149d4f..170e758 160000 --- a/external/ktx +++ b/external/ktx @@ -1 +1 @@ -Subproject commit 7149d4fc08bb00c070883d174e46e102a6974a8c +Subproject commit 170e75893e3d232a2c4f241afe199256f8abb6f9 diff --git a/src/Editor/Window/SceneView.cpp b/src/Editor/Window/SceneView.cpp index 394eb23..7a64437 100644 --- a/src/Editor/Window/SceneView.cpp +++ b/src/Editor/Window/SceneView.cpp @@ -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\\Plane\\plane.fbx"); - cameraSystem.update(viewportCamera, static_cast(Gfx::currentFrameDelta)); + cameraSystem.update(viewportCamera, static_cast(Gfx::getCurrentFrameDelta())); renderGraph.updateViewport(viewport); } @@ -43,7 +43,7 @@ void SceneView::beginUpdate() void SceneView::update() { - cameraSystem.update(viewportCamera, static_cast(Gfx::currentFrameDelta)); + cameraSystem.update(viewportCamera, static_cast(Gfx::getCurrentFrameDelta())); //co_return; } diff --git a/src/Editor/main.cpp b/src/Editor/main.cpp index 21f7567..81c7783 100644 --- a/src/Editor/main.cpp +++ b/src/Editor/main.cpp @@ -31,7 +31,7 @@ int main() graphics->init(initializer); PWindowManager windowManager = new WindowManager(); AssetRegistry::init(std::string("C:/Users/Dynamitos/TrackClear/Assets"), graphics); - AssetImporter::init(graphics, instance); + AssetImporter::init(graphics, AssetRegistry::getInstance()); AssetImporter::importFont(FontImportArgs{ .filePath = "./fonts/Calibri.ttf", }); diff --git a/src/Engine/Asset/AssetRegistry.cpp b/src/Engine/Asset/AssetRegistry.cpp index 8db48a2..993320c 100644 --- a/src/Engine/Asset/AssetRegistry.cpp +++ b/src/Engine/Asset/AssetRegistry.cpp @@ -10,10 +10,11 @@ #include "MeshAsset.h" #include #include +#include using namespace Seele; -extern AssetRegistry* instance; +AssetRegistry* instance = new AssetRegistry(); AssetRegistry::~AssetRegistry() { @@ -96,6 +97,11 @@ AssetRegistry::AssetRegistry() { } +AssetRegistry* AssetRegistry::getInstance() +{ + return instance; +} + void AssetRegistry::loadRegistry() { get().loadRegistryInternal(); diff --git a/src/Engine/Asset/AssetRegistry.h b/src/Engine/Asset/AssetRegistry.h index 81a7f36..93d9ec1 100644 --- a/src/Engine/Asset/AssetRegistry.h +++ b/src/Engine/Asset/AssetRegistry.h @@ -45,6 +45,7 @@ public: }; AssetFolder* getOrCreateFolder(std::string foldername); AssetRegistry(); + static AssetRegistry* getInstance(); private: static AssetRegistry& get(); diff --git a/src/Engine/Component/ShapeBase.cpp b/src/Engine/Component/ShapeBase.cpp index 62921eb..d9450b5 100644 --- a/src/Engine/Component/ShapeBase.cpp +++ b/src/Engine/Component/ShapeBase.cpp @@ -233,36 +233,38 @@ void ShapeBase::addCollider(Array verts, Array inds, Matrix4 mat void ShapeBase::visualize() const { + Array verts; for(uint32 i = 0; i < indices.size(); i+=3) { - gDebugVertices.add(DebugVertex{ + verts.add(DebugVertex{ .position = Vector(vertices[indices[i+0]]), .color = Vector(1, 0, 0), }); - gDebugVertices.add(DebugVertex{ + verts.add(DebugVertex{ .position = Vector(vertices[indices[i+1]]), .color = Vector(1, 0, 0), }); - gDebugVertices.add(DebugVertex{ + verts.add(DebugVertex{ .position = Vector(vertices[indices[i+1]]), .color = Vector(1, 0, 0), }); - gDebugVertices.add(DebugVertex{ + verts.add(DebugVertex{ .position = Vector(vertices[indices[i+2]]), .color = Vector(1, 0, 0), }); - gDebugVertices.add(DebugVertex{ + verts.add(DebugVertex{ .position = Vector(vertices[indices[i+2]]), .color = Vector(1, 0, 0), }); - gDebugVertices.add(DebugVertex{ + verts.add(DebugVertex{ .position = Vector(vertices[indices[i+0]]), .color = Vector(1, 0, 0), }); } + addDebugVertices(std::move(verts)); } diff --git a/src/Engine/Graphics/DebugVertex.h b/src/Engine/Graphics/DebugVertex.h index 565c3cd..4f82006 100644 --- a/src/Engine/Graphics/DebugVertex.h +++ b/src/Engine/Graphics/DebugVertex.h @@ -9,5 +9,6 @@ struct DebugVertex Vector position; Vector color; }; -extern Array gDebugVertices; +void addDebugVertex(DebugVertex vert); +void addDebugVertices(Array vert); } // namespace Seele diff --git a/src/Engine/Graphics/GraphicsEnums.cpp b/src/Engine/Graphics/GraphicsEnums.cpp index 63f530c..351fd86 100644 --- a/src/Engine/Graphics/GraphicsEnums.cpp +++ b/src/Engine/Graphics/GraphicsEnums.cpp @@ -3,8 +3,6 @@ using namespace Seele; using namespace Seele::Gfx; -uint32 Gfx::currentFrameIndex = 0; -double Gfx::currentFrameDelta = 0; FormatCompatibilityInfo Gfx::getFormatInfo(SeFormat format) { diff --git a/src/Engine/Graphics/GraphicsEnums.h b/src/Engine/Graphics/GraphicsEnums.h index a53046f..55bdde5 100644 --- a/src/Engine/Graphics/GraphicsEnums.h +++ b/src/Engine/Graphics/GraphicsEnums.h @@ -166,8 +166,7 @@ namespace Gfx static constexpr bool useAsyncCompute = true; static constexpr bool waitIdleOnSubmit = true; static constexpr uint32 numFramesBuffered = 8; -extern uint32 currentFrameIndex; -extern double currentFrameDelta; +double getCurrentFrameDelta(); enum class MaterialShadingModel { diff --git a/src/Engine/Graphics/RenderPass/DebugPass.cpp b/src/Engine/Graphics/RenderPass/DebugPass.cpp index 22c932f..adbadb8 100644 --- a/src/Engine/Graphics/RenderPass/DebugPass.cpp +++ b/src/Engine/Graphics/RenderPass/DebugPass.cpp @@ -3,7 +3,17 @@ using namespace Seele; -Array Seele::gDebugVertices; +Array gDebugVertices; + +void Seele::addDebugVertex(DebugVertex vert) +{ + gDebugVertices.add(vert); +} + +void Seele::addDebugVertices(Array verts) +{ + gDebugVertices.addAll(verts); +} DebugPass::DebugPass(Gfx::PGraphics graphics) : RenderPass(graphics) diff --git a/src/Engine/Graphics/Vulkan/VulkanViewport.cpp b/src/Engine/Graphics/Vulkan/VulkanViewport.cpp index d708a99..5d797f2 100644 --- a/src/Engine/Graphics/Vulkan/VulkanViewport.cpp +++ b/src/Engine/Graphics/Vulkan/VulkanViewport.cpp @@ -8,6 +8,12 @@ using namespace Seele; using namespace Seele::Vulkan; +double currentFrameDelta = 0; +double Gfx::getCurrentFrameDelta() +{ + return currentFrameDelta; +} + void glfwKeyCallback(GLFWwindow* handle, int key, int, int action, int modifier) { Window* window = (Window*)glfwGetWindowUserPointer(handle); @@ -209,6 +215,8 @@ void Window::recreateSwapchain(const WindowCreateInfo &windowInfo) createSwapchain(); } +static uint32_t currentFrameIndex = 0; + void Window::present() { backBufferImages[currentImageIndex]->changeLayout(Gfx::SE_IMAGE_LAYOUT_PRESENT_SRC_KHR); @@ -230,11 +238,11 @@ void Window::present() { presentResult = vkQueuePresentKHR(graphics->getGraphicsCommands()->getQueue()->getHandle(), &info); } - Gfx::currentFrameIndex = (Gfx::currentFrameIndex + 1)%Gfx::numFramesBuffered; + currentFrameIndex = (currentFrameIndex + 1) % Gfx::numFramesBuffered; static double lastFrameTime = 0.f; double currentTime = glfwGetTime(); double currentDelta = currentTime - lastFrameTime; - Gfx::currentFrameDelta = currentDelta; + currentFrameDelta = currentDelta; lastFrameTime = currentTime; } diff --git a/src/Engine/MinimalEngine.cpp b/src/Engine/MinimalEngine.cpp index c1ad5e4..276458a 100644 --- a/src/Engine/MinimalEngine.cpp +++ b/src/Engine/MinimalEngine.cpp @@ -1,4 +1,14 @@ #include "MinimalEngine.h" +#include -std::map registeredObjects; -std::mutex registeredObjectsLock; +std::map& getRegisteredObjects() +{ + static std::map map; + return map; +} + +std::mutex& getRegisteredObjectLock() +{ + static std::mutex lock; + return lock; +} diff --git a/src/Engine/MinimalEngine.h b/src/Engine/MinimalEngine.h index c62f2d7..a732fa2 100644 --- a/src/Engine/MinimalEngine.h +++ b/src/Engine/MinimalEngine.h @@ -23,8 +23,9 @@ typedef WeakPtr W##x; \ } -extern std::map registeredObjects; -extern std::mutex registeredObjectsLock; +std::map& getRegisteredObjects(); +std::mutex& getRegisteredObjectLock(); + namespace Seele { template @@ -47,8 +48,8 @@ public: ~RefObject() { { - std::scoped_lock lock(registeredObjectsLock); - registeredObjects.erase(handle); + std::scoped_lock lock(getRegisteredObjectLock()); + getRegisteredObjects().erase(handle); } // #pragma warning( disable: 4150) deleter(handle); @@ -112,14 +113,14 @@ public: } constexpr RefPtr(T *ptr, Deleter deleter = Deleter()) { - std::scoped_lock l(registeredObjectsLock); - auto registeredObj = registeredObjects.find(ptr); + std::scoped_lock l(getRegisteredObjectLock()); + auto registeredObj = getRegisteredObjects().find(ptr); // get here for thread safetly - auto registeredEnd = registeredObjects.end(); + auto registeredEnd = getRegisteredObjects().end(); if (registeredObj == registeredEnd) { object = new RefObject(ptr, std::move(deleter)); - registeredObjects[ptr] = object; + getRegisteredObjects()[ptr] = object; } else { diff --git a/src/Engine/Physics/BVH.cpp b/src/Engine/Physics/BVH.cpp index 5cc65ef..b701842 100644 --- a/src/Engine/Physics/BVH.cpp +++ b/src/Engine/Physics/BVH.cpp @@ -49,14 +49,16 @@ void BVH::colliderCallback(entt::registry& registry, entt::entity entity) void BVH::visualize() { - for(const auto& node : staticNodes) + Array verts; + 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>& overlaps) diff --git a/src/Engine/Physics/PhysicsSystem.cpp b/src/Engine/Physics/PhysicsSystem.cpp index 955cb65..14c9369 100644 --- a/src/Engine/Physics/PhysicsSystem.cpp +++ b/src/Engine/Physics/PhysicsSystem.cpp @@ -284,11 +284,11 @@ void PhysicsSystem::calculateContacts(entt::entity id1, const ShapeBase& shape1, const Vector v1 = point2 - point1; const Vector v2 = point3 - point1; const Vector faceNormal = glm::normalize(glm::cross(v1, v2)); - Seele::gDebugVertices.add(DebugVertex{ + addDebugVertex(DebugVertex{ .position = (point1 + point2 + point3) / 3.f, .color = Vector(1, 0, 0) }); - Seele::gDebugVertices.add(DebugVertex{ + addDebugVertex(DebugVertex{ .position = faceNormal + (point1 + point2 + point3) / 3.f, .color = Vector(1, 0, 0) }); diff --git a/src/Engine/Window/GameView.cpp b/src/Engine/Window/GameView.cpp index e15ad3d..90c5929 100644 --- a/src/Engine/Window/GameView.cpp +++ b/src/Engine/Window/GameView.cpp @@ -7,8 +7,6 @@ using namespace Seele; -AssetRegistry* instance = new AssetRegistry(); - GameView::GameView(Gfx::PGraphics graphics, PWindow window, const ViewportCreateInfo &createInfo, std::string dllPath) : View(graphics, window, createInfo, "Game") , gameInterface(dllPath) @@ -73,7 +71,7 @@ void GameView::render() void GameView::reloadGame() { scene = new Scene(graphics); - gameInterface.reload(instance); + gameInterface.reload(AssetRegistry::getInstance()); systemGraph = new SystemGraph(); gameInterface.getGame()->setupScene(scene, systemGraph);