From 28831ee5bddc967550f276c32b9b8259a0680ab1 Mon Sep 17 00:00:00 2001 From: Niels Eppenhof Date: Sat, 4 Jan 2025 07:45:11 +0100 Subject: [PATCH] C++20 --- EppoEditor/CMakeLists.txt | 4 +- EppoEditor/Source/EditorLayer.cpp | 27 +++-- .../Source/Panel/ContentBrowserPanel.cpp | 2 +- EppoEditor/Source/Panel/PanelManager.h | 4 +- EppoEditor/Source/ThumbnailCache.cpp | 2 +- EppoEditor/premake5.lua | 2 +- EppoEngine/CMakeLists.txt | 2 +- EppoEngine/Source/Asset/AssetImporter.cpp | 8 +- EppoEngine/Source/Asset/AssetManager.cpp | 7 -- .../Source/Asset/AssetManagerEditor.cpp | 38 +++--- EppoEngine/Source/Core/Buffer.h | 2 +- EppoEngine/Source/Core/Entrypoint.h | 8 +- EppoEngine/Source/Core/Filesystem.cpp | 10 +- EppoEngine/Source/Core/Hash.cpp | 6 +- EppoEngine/Source/Core/Window.cpp | 9 +- EppoEngine/Source/Core/Window.h | 2 +- EppoEngine/Source/Event/ApplicationEvent.h | 4 +- EppoEngine/Source/Event/KeyEvent.h | 2 +- EppoEngine/Source/ImGui/Image.cpp | 5 +- EppoEngine/Source/Physics/RigidBody.cpp | 12 +- EppoEngine/Source/Physics/RigidBody.h | 2 +- .../Platform/Vulkan/VulkanAllocator.cpp | 5 +- .../Source/Platform/Vulkan/VulkanContext.cpp | 4 +- .../Source/Platform/Vulkan/VulkanContext.h | 6 +- .../Platform/Vulkan/VulkanDebugRenderer.cpp | 13 +- .../Platform/Vulkan/VulkanDebugRenderer.h | 4 +- .../Source/Platform/Vulkan/VulkanImage.cpp | 12 +- .../Source/Platform/Vulkan/VulkanImage.h | 2 +- .../Platform/Vulkan/VulkanIndexBuffer.cpp | 18 +-- .../Platform/Vulkan/VulkanIndexBuffer.h | 5 +- .../Platform/Vulkan/VulkanLogicalDevice.cpp | 26 ++-- .../Platform/Vulkan/VulkanLogicalDevice.h | 12 +- .../Platform/Vulkan/VulkanPhysicalDevice.cpp | 67 +++++----- .../Platform/Vulkan/VulkanPhysicalDevice.h | 20 +-- .../Source/Platform/Vulkan/VulkanPipeline.cpp | 22 ++-- .../Platform/Vulkan/VulkanSceneRenderer.cpp | 2 +- .../Source/Platform/Vulkan/VulkanShader.cpp | 31 ++--- .../Source/Platform/Vulkan/VulkanSwapchain.h | 6 +- EppoEngine/Source/Project/Project.cpp | 2 +- EppoEngine/Source/Renderer/DebugRenderer.h | 4 +- EppoEngine/Source/Scene/Components.h | 6 +- EppoEngine/Source/Scene/Scene.cpp | 38 +++--- EppoEngine/Source/Scene/SceneSerializer.cpp | 8 +- EppoEngine/Source/Scripting/ScriptClass.h | 2 +- EppoEngine/Source/Scripting/ScriptEngine.cpp | 114 +++++++++--------- EppoEngine/Source/Scripting/ScriptField.h | 4 +- EppoEngine/Source/Scripting/ScriptGlue.cpp | 5 +- .../Source/Scripting/ScriptInstance.cpp | 6 +- EppoEngine/premake5.lua | 2 +- EppoScripting/EppoScripting.csproj | 79 ++++++++++++ EppoTesting/CMakeLists.txt | 4 +- EppoTesting/premake5.lua | 2 +- 52 files changed, 390 insertions(+), 299 deletions(-) delete mode 100644 EppoEngine/Source/Asset/AssetManager.cpp create mode 100644 EppoScripting/EppoScripting.csproj diff --git a/EppoEditor/CMakeLists.txt b/EppoEditor/CMakeLists.txt index 74692b74..97f716ad 100644 --- a/EppoEditor/CMakeLists.txt +++ b/EppoEditor/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.24) project(EppoEditor VERSION 1.0 LANGUAGES CXX) -set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) # Sources @@ -27,4 +27,4 @@ target_link_libraries(${PROJECT_NAME} PRIVATE ${BULLET_COLLISION_LIBRARY} ${BULLET_DYNAMICS_LIBRARY} ${BULLET_MATH_LIBRARY} ${BULLET_SOFTBODY_LIBRARY} ${mono_LIBRARIES} ${Vulkan_LIBRARY} shaderc_combined spirv-cross-core spirv-cross-glsl -) \ No newline at end of file +) diff --git a/EppoEditor/Source/EditorLayer.cpp b/EppoEditor/Source/EditorLayer.cpp index cf23a392..0fc876c0 100644 --- a/EppoEditor/Source/EditorLayer.cpp +++ b/EppoEditor/Source/EditorLayer.cpp @@ -15,8 +15,21 @@ namespace Eppo static const std::string PROPERTY_PANEL = "PropertyPanel"; static const std::string SCENE_HIERARCHY_PANEL = "SceneHierarchyPanel"; - static bool s_NewProjectPopup = false; - static bool s_PreferencesPopup = false; + namespace + { + bool s_NewProjectPopup = false; + bool s_PreferencesPopup = false; + + void ReplaceToken(std::string& input, const char* token, const std::string& value) + { + size_t pos = 0; + while ((pos = input.find(token, pos)) != std::string::npos) + { + input.replace(pos, strlen(token), value); + pos += strlen(token); + } + } + } EditorLayer::EditorLayer() : Layer("EditorLayer"), m_PanelManager(PanelManager::Get()) @@ -337,16 +350,6 @@ namespace Eppo m_ActiveScene = nullptr; } - static void ReplaceToken(std::string& input, const char* token, const std::string& value) - { - size_t pos = 0; - while ((pos = input.find(token, pos)) != std::string::npos) - { - input.replace(pos, strlen(token), value); - pos += strlen(token); - } - } - void EditorLayer::NewProject(const std::string& name) { // Create project directory diff --git a/EppoEditor/Source/Panel/ContentBrowserPanel.cpp b/EppoEditor/Source/Panel/ContentBrowserPanel.cpp index 95cb6bab..12051081 100644 --- a/EppoEditor/Source/Panel/ContentBrowserPanel.cpp +++ b/EppoEditor/Source/Panel/ContentBrowserPanel.cpp @@ -27,7 +27,7 @@ namespace Eppo ImGui::BeginGroup(); - constexpr char* items[] = { "Meshes", "Scenes", "Scripts", "Textures" }; + const char* items[] = { "Meshes", "Scenes", "Scripts", "Textures" }; static int currentItem = 0; if (ImGui::BeginListBox("##Assets", ImVec2(100.0f, -FLT_MIN))) { diff --git a/EppoEditor/Source/Panel/PanelManager.h b/EppoEditor/Source/Panel/PanelManager.h index 155b932a..1f91af35 100644 --- a/EppoEditor/Source/Panel/PanelManager.h +++ b/EppoEditor/Source/Panel/PanelManager.h @@ -53,9 +53,9 @@ namespace Eppo return it->second.Panel; // TODO: Might not work? dynamic cast to derived class } - bool HasPanel(const std::string& name) + bool HasPanel(const std::string& name) const { - return m_PanelData.find(name) != m_PanelData.end(); + return m_PanelData.contains(name); } static PanelManager& Get(); diff --git a/EppoEditor/Source/ThumbnailCache.cpp b/EppoEditor/Source/ThumbnailCache.cpp index cb438da5..9b0ef374 100644 --- a/EppoEditor/Source/ThumbnailCache.cpp +++ b/EppoEditor/Source/ThumbnailCache.cpp @@ -24,7 +24,7 @@ namespace Eppo Ref ThumbnailCache::GetOrCreateThumbnail(const AssetType type) { - if (m_AssetTypeThumbnails.find(type) == m_AssetTypeThumbnails.end()) + if (!m_AssetTypeThumbnails.contains(type)) return m_AssetTypeThumbnails.at(AssetType::None); return m_AssetTypeThumbnails.at(type); diff --git a/EppoEditor/premake5.lua b/EppoEditor/premake5.lua index b4922581..48b76044 100644 --- a/EppoEditor/premake5.lua +++ b/EppoEditor/premake5.lua @@ -1,7 +1,7 @@ project "EppoEditor" kind "ConsoleApp" language "C++" - cppdialect "C++17" + cppdialect "C++20" staticruntime "Off" targetdir ("%{wks.location}/Bin/" .. OutputDir .. "/%{prj.name}") diff --git a/EppoEngine/CMakeLists.txt b/EppoEngine/CMakeLists.txt index 42a6c519..ca20127e 100644 --- a/EppoEngine/CMakeLists.txt +++ b/EppoEngine/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.24) project(EppoEng VERSION 1.0 LANGUAGES CXX) -set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) # Sources diff --git a/EppoEngine/Source/Asset/AssetImporter.cpp b/EppoEngine/Source/Asset/AssetImporter.cpp index 3f172eec..38f62bcb 100644 --- a/EppoEngine/Source/Asset/AssetImporter.cpp +++ b/EppoEngine/Source/Asset/AssetImporter.cpp @@ -41,8 +41,12 @@ namespace Eppo EPPO_PROFILE_FUNCTION("AssetImporter::ImportScene"); Ref scene = CreateRef(); - SceneSerializer serializer(scene); - serializer.Deserialize(Project::GetAssetFilepath(metadata.Filepath)); + + if (const SceneSerializer serializer(scene); + !serializer.Deserialize(Project::GetAssetFilepath(metadata.Filepath))) + { + EPPO_ERROR("Failed to import scene '{}'", metadata.Filepath); + } return scene; } diff --git a/EppoEngine/Source/Asset/AssetManager.cpp b/EppoEngine/Source/Asset/AssetManager.cpp deleted file mode 100644 index afdb73e8..00000000 --- a/EppoEngine/Source/Asset/AssetManager.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#include "pch.h" -#include "AssetManager.h" - -namespace Eppo -{ - -} diff --git a/EppoEngine/Source/Asset/AssetManagerEditor.cpp b/EppoEngine/Source/Asset/AssetManagerEditor.cpp index a2740feb..847f3490 100644 --- a/EppoEngine/Source/Asset/AssetManagerEditor.cpp +++ b/EppoEngine/Source/Asset/AssetManagerEditor.cpp @@ -8,19 +8,19 @@ namespace Eppo { - static std::map s_AssetExtensionMap = + namespace { - { ".epscene", AssetType::Scene }, - { ".glb", AssetType::Mesh }, - { ".gltf", AssetType::Mesh }, - { ".jpeg", AssetType::Texture }, - { ".jpg", AssetType::Texture }, - { ".png", AssetType::Texture }, - }; - - namespace Utils - { - static AssetType GetAssetTypeFromFileExtension(const std::filesystem::path& extension) + std::map s_AssetExtensionMap = + { + { ".epscene", AssetType::Scene }, + { ".glb", AssetType::Mesh }, + { ".gltf", AssetType::Mesh }, + { ".jpeg", AssetType::Texture }, + { ".jpg", AssetType::Texture }, + { ".png", AssetType::Texture }, + }; + + AssetType GetAssetTypeFromFileExtension(const std::filesystem::path& extension) { if (s_AssetExtensionMap.find(extension) == s_AssetExtensionMap.end()) { @@ -31,7 +31,7 @@ namespace Eppo return s_AssetExtensionMap.at(extension); } - static std::filesystem::path CopyAssetToAssetsDirectory(const std::filesystem::path& filepath) + std::filesystem::path CopyAssetToAssetsDirectory(const std::filesystem::path& filepath) { const AssetType type = GetAssetTypeFromFileExtension(filepath.extension()); std::filesystem::path destPath; @@ -82,7 +82,7 @@ namespace Eppo if (IsAssetLoaded(handle)) return false; - const AssetType type = Utils::GetAssetTypeFromFileExtension(filepath.extension()); + const AssetType type = GetAssetTypeFromFileExtension(filepath.extension()); EPPO_ASSERT(type != AssetType::None) AssetMetadata metadata; @@ -151,12 +151,12 @@ namespace Eppo std::filesystem::path baseCanonical = std::filesystem::canonical(Project::GetAssetsDirectory()); std::filesystem::path targetCanonical = std::filesystem::canonical(Project::GetAssetFilepath(filepath)); - const AssetType type = Utils::GetAssetTypeFromFileExtension(filepath.extension()); + const AssetType type = GetAssetTypeFromFileExtension(filepath.extension()); EPPO_ASSERT(type != AssetType::None) std::filesystem::path newPath; if (std::mismatch(baseCanonical.begin(), baseCanonical.end(), targetCanonical.begin()).first != baseCanonical.end()) - newPath = Utils::CopyAssetToAssetsDirectory(targetCanonical); + newPath = CopyAssetToAssetsDirectory(targetCanonical); AssetMetadata metadata; metadata.Filepath = Project::GetAssetRelativeFilepath(newPath.empty() ? filepath : newPath); @@ -175,16 +175,16 @@ namespace Eppo return asset; } - const AssetMetadata& AssetManagerEditor::GetMetadata(AssetHandle handle) const + const AssetMetadata& AssetManagerEditor::GetMetadata(const AssetHandle handle) const { - auto it = m_AssetData.find(handle); + const auto it = m_AssetData.find(handle); if (it == m_AssetData.end()) return s_NullMetadata; return it->second; } - const std::filesystem::path& AssetManagerEditor::GetFilepath(AssetHandle handle) const + const std::filesystem::path& AssetManagerEditor::GetFilepath(const AssetHandle handle) const { return GetMetadata(handle).Filepath; } diff --git a/EppoEngine/Source/Core/Buffer.h b/EppoEngine/Source/Core/Buffer.h index d1312283..22d220da 100644 --- a/EppoEngine/Source/Core/Buffer.h +++ b/EppoEngine/Source/Core/Buffer.h @@ -109,7 +109,7 @@ namespace Eppo m_Buffer.SetData(value, offset); } - void SetData(void* data, uint32_t size) + void SetData(void* data, const uint32_t size) { m_Buffer.SetData(data, size); } diff --git a/EppoEngine/Source/Core/Entrypoint.h b/EppoEngine/Source/Core/Entrypoint.h index 843813c4..2e31b6d3 100644 --- a/EppoEngine/Source/Core/Entrypoint.h +++ b/EppoEngine/Source/Core/Entrypoint.h @@ -2,15 +2,13 @@ #include "Core/Application.h" -using namespace Eppo; - int main(int argc, char** argv) { - Log::Init(); + Eppo::Log::Init(); - const ApplicationCommandLineArgs args(argc, argv); + const Eppo::ApplicationCommandLineArgs args(argc, argv); - Application* app = CreateApplication(args); + Eppo::Application* app = CreateApplication(args); app->Run(); delete app; diff --git a/EppoEngine/Source/Core/Filesystem.cpp b/EppoEngine/Source/Core/Filesystem.cpp index 46a869a7..ce20ab7d 100644 --- a/EppoEngine/Source/Core/Filesystem.cpp +++ b/EppoEngine/Source/Core/Filesystem.cpp @@ -98,7 +98,7 @@ namespace Eppo return {}; Buffer buffer(static_cast(fileSize)); - stream.read(buffer.As(), fileSize); + stream.read(buffer.As(), static_cast(fileSize)); stream.close(); return buffer; @@ -120,7 +120,7 @@ namespace Eppo { text.resize(size); stream.seekg(0, std::ios::beg); - stream.read(text.data(), text.size()); + stream.read(text.data(), static_cast(text.size())); } return text; @@ -149,10 +149,10 @@ namespace Eppo std::ofstream stream(filepath, std::ios::binary); EPPO_ASSERT(stream) - stream.write((char*)buffer.data(), buffer.size() * sizeof(uint32_t)); + stream.write((char*)buffer.data(), static_cast(buffer.size()) * sizeof(uint32_t)); } - void Filesystem::WriteText(const std::filesystem::path& filepath, const std::string& text, bool overwrite) + void Filesystem::WriteText(const std::filesystem::path& filepath, const std::string& text, const bool overwrite) { EPPO_PROFILE_FUNCTION("Filesystem::WriteText"); @@ -167,6 +167,6 @@ namespace Eppo EPPO_ASSERT(stream) - stream.write(text.c_str(), text.size()); + stream.write(text.c_str(), static_cast(text.size())); } } diff --git a/EppoEngine/Source/Core/Hash.cpp b/EppoEngine/Source/Core/Hash.cpp index 08d38b39..5708fb41 100644 --- a/EppoEngine/Source/Core/Hash.cpp +++ b/EppoEngine/Source/Core/Hash.cpp @@ -3,9 +3,9 @@ namespace Eppo { - namespace Utils + namespace { - static void byteswap64(uint64_t value, void* ptr) + void byteswap64(uint64_t value, void* ptr) { value = ((value & 0xFF00000000000000u) >> 56u) | @@ -50,7 +50,7 @@ namespace Eppo } // Reverse byte order - Utils::byteswap64(hash, &hash); + byteswap64(hash, &hash); return hash; } diff --git a/EppoEngine/Source/Core/Window.cpp b/EppoEngine/Source/Core/Window.cpp index d2f0fdee..96cf663d 100644 --- a/EppoEngine/Source/Core/Window.cpp +++ b/EppoEngine/Source/Core/Window.cpp @@ -9,9 +9,12 @@ namespace Eppo { - static void GLFWErrorCallback(int error, const char* description) + namespace { - EPPO_ERROR("GLFW Error: ({}) {}", error, description); + void GLFWErrorCallback(int error, const char* description) + { + EPPO_ERROR("GLFW Error: ({}) {}", error, description); + } } Window::Window(WindowSpecification specification) @@ -148,7 +151,7 @@ namespace Eppo glfwTerminate(); } - void Window::ProcessEvents() const + void Window::ProcessEvents() { glfwPollEvents(); } diff --git a/EppoEngine/Source/Core/Window.h b/EppoEngine/Source/Core/Window.h index 5b08d30a..b5713ab3 100644 --- a/EppoEngine/Source/Core/Window.h +++ b/EppoEngine/Source/Core/Window.h @@ -32,7 +32,7 @@ namespace Eppo void Init(); void Shutdown() const; - void ProcessEvents() const; + static void ProcessEvents(); void SetEventCallback(const EventCallbackFn& callback) { m_Callback = callback; } void SetWindowTitle(const std::string& name) const; diff --git a/EppoEngine/Source/Event/ApplicationEvent.h b/EppoEngine/Source/Event/ApplicationEvent.h index bb15ee08..0edff180 100644 --- a/EppoEngine/Source/Event/ApplicationEvent.h +++ b/EppoEngine/Source/Event/ApplicationEvent.h @@ -24,8 +24,8 @@ namespace Eppo EVENT_CLASS_TYPE(WindowResize); EVENT_CLASS_CATEGORY(EventCategoryApplication); - uint32_t GetWidth() const { return m_Width; } - uint32_t GetHeight() const { return m_Height; } + [[nodiscard]] uint32_t GetWidth() const { return m_Width; } + [[nodiscard]] uint32_t GetHeight() const { return m_Height; } private: uint32_t m_Width, m_Height; diff --git a/EppoEngine/Source/Event/KeyEvent.h b/EppoEngine/Source/Event/KeyEvent.h index 867241e0..c59773f9 100644 --- a/EppoEngine/Source/Event/KeyEvent.h +++ b/EppoEngine/Source/Event/KeyEvent.h @@ -10,7 +10,7 @@ namespace Eppo public: [[nodiscard]] KeyCode GetKeyCode() const { return m_KeyCode; } - EVENT_CLASS_CATEGORY(EventCategoryInput | EventCategoryKeyboard); + EVENT_CLASS_CATEGORY(EventCategoryInput | EventCategoryKeyboard) protected: explicit KeyEvent(const KeyCode keyCode) diff --git a/EppoEngine/Source/ImGui/Image.cpp b/EppoEngine/Source/ImGui/Image.cpp index 375b7845..7e681251 100644 --- a/EppoEngine/Source/ImGui/Image.cpp +++ b/EppoEngine/Source/ImGui/Image.cpp @@ -15,7 +15,10 @@ namespace Eppo::UI VkDescriptorSet DescriptorSet; }; - static std::unordered_map s_ImageCache; + namespace + { + std::unordered_map s_ImageCache; + } void ClearResources() { diff --git a/EppoEngine/Source/Physics/RigidBody.cpp b/EppoEngine/Source/Physics/RigidBody.cpp index 49676cd8..2f61855f 100644 --- a/EppoEngine/Source/Physics/RigidBody.cpp +++ b/EppoEngine/Source/Physics/RigidBody.cpp @@ -5,19 +5,19 @@ namespace Eppo { - namespace Utils + namespace { - static glm::vec3 BulletToGlm(const btVector3& v) + glm::vec3 BulletToGlm(const btVector3& v) { return { v.getX(), v.getY(), v.getZ() }; } - static glm::quat BulletToGlm(const btQuaternion& q) + glm::quat BulletToGlm(const btQuaternion& q) { return { q.getW(), q.getX(), q.getY(), q.getZ() }; } - static btVector3 GlmToBullet(const glm::vec3& v) + btVector3 GlmToBullet(const glm::vec3& v) { return { v.x, v.y, v.z }; } @@ -37,7 +37,7 @@ namespace Eppo EPPO_PROFILE_FUNCTION("RigidBody::ApplyLinearImpulse"); EPPO_ASSERT(m_Body) - m_Body->applyImpulse(Utils::GlmToBullet(impulse), Utils::GlmToBullet(worldPosition)); + m_Body->applyImpulse(GlmToBullet(impulse), GlmToBullet(worldPosition)); } void RigidBody::ApplyLinearImpulse(const glm::vec3& impulse) const @@ -45,7 +45,7 @@ namespace Eppo EPPO_PROFILE_FUNCTION("RigidBody::ApplyLinearImpulse"); EPPO_ASSERT(m_Body) - m_Body->applyCentralImpulse(Utils::GlmToBullet(impulse)); + m_Body->applyCentralImpulse(GlmToBullet(impulse)); } void RigidBody::ClearBody() diff --git a/EppoEngine/Source/Physics/RigidBody.h b/EppoEngine/Source/Physics/RigidBody.h index 45a80650..82561cbc 100644 --- a/EppoEngine/Source/Physics/RigidBody.h +++ b/EppoEngine/Source/Physics/RigidBody.h @@ -15,7 +15,7 @@ namespace Eppo void ApplyLinearImpulse(const glm::vec3& impulse, const glm::vec3& worldPosition) const; void ApplyLinearImpulse(const glm::vec3& impulse) const; - btRigidBody* GetBody() const { return m_Body; } + [[nodiscard]] btRigidBody* GetBody() const { return m_Body; } void SetBody(btRigidBody* body) { m_Body = body; } void ClearBody(); diff --git a/EppoEngine/Source/Platform/Vulkan/VulkanAllocator.cpp b/EppoEngine/Source/Platform/Vulkan/VulkanAllocator.cpp index a326cfb6..d343e593 100644 --- a/EppoEngine/Source/Platform/Vulkan/VulkanAllocator.cpp +++ b/EppoEngine/Source/Platform/Vulkan/VulkanAllocator.cpp @@ -18,7 +18,10 @@ namespace Eppo } }; - static AllocatorData* s_Data; + namespace + { + AllocatorData* s_Data; + } void VulkanAllocator::Init() { diff --git a/EppoEngine/Source/Platform/Vulkan/VulkanContext.cpp b/EppoEngine/Source/Platform/Vulkan/VulkanContext.cpp index 691e41b2..6f800f1d 100644 --- a/EppoEngine/Source/Platform/Vulkan/VulkanContext.cpp +++ b/EppoEngine/Source/Platform/Vulkan/VulkanContext.cpp @@ -139,12 +139,12 @@ namespace Eppo return std::static_pointer_cast(RendererContext::Get()); } - std::vector VulkanContext::GetRequiredExtensions() const + std::vector VulkanContext::GetRequiredExtensions() { uint32_t glfwExtensionCount = 0; const char** glfwExtensions = glfwGetRequiredInstanceExtensions(&glfwExtensionCount); - std::vector extensions(glfwExtensions, glfwExtensions + glfwExtensionCount); + std::vector extensions(glfwExtensions, glfwExtensions + glfwExtensionCount); if (VulkanConfig::EnableValidation) extensions.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME); diff --git a/EppoEngine/Source/Platform/Vulkan/VulkanContext.h b/EppoEngine/Source/Platform/Vulkan/VulkanContext.h index 0093ae4f..c43994e1 100644 --- a/EppoEngine/Source/Platform/Vulkan/VulkanContext.h +++ b/EppoEngine/Source/Platform/Vulkan/VulkanContext.h @@ -45,11 +45,11 @@ namespace Eppo static Ref Get(); private: - [[nodiscard]] std::vector GetRequiredExtensions() const; + [[nodiscard]] static std::vector GetRequiredExtensions(); private: GLFWwindow* m_WindowHandle = nullptr; - VkDebugUtilsMessengerEXT m_DebugMessenger; + VkDebugUtilsMessengerEXT m_DebugMessenger = nullptr; Ref m_LogicalDevice; Ref m_PhysicalDevice; @@ -59,7 +59,7 @@ namespace Eppo DescriptorLayoutBuilder m_DescriptorLayoutBuilder; GarbageCollector m_GarbageCollector; - TracyVkCtx m_TracyContext; + TracyVkCtx m_TracyContext = nullptr; inline static VkInstance s_Instance; }; diff --git a/EppoEngine/Source/Platform/Vulkan/VulkanDebugRenderer.cpp b/EppoEngine/Source/Platform/Vulkan/VulkanDebugRenderer.cpp index 6135e243..ee3dfa4b 100644 --- a/EppoEngine/Source/Platform/Vulkan/VulkanDebugRenderer.cpp +++ b/EppoEngine/Source/Platform/Vulkan/VulkanDebugRenderer.cpp @@ -6,11 +6,10 @@ namespace Eppo { - void VulkanDebugRenderer::StartDebugLabel(Ref commandBuffer, const std::string& label) + void VulkanDebugRenderer::StartDebugLabel(const Ref& commandBuffer, const std::string& label) { - auto cmd = std::static_pointer_cast(commandBuffer); - - VkCommandBuffer cb = cmd->GetCurrentCommandBuffer(); + const auto cmd = std::static_pointer_cast(commandBuffer); + const VkCommandBuffer cb = cmd->GetCurrentCommandBuffer(); VkDebugUtilsLabelEXT debugLabel{}; debugLabel.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_LABEL_EXT; @@ -23,11 +22,11 @@ namespace Eppo vkCmdBeginDebugUtilsLabelEXT(cb, &debugLabel); } - void VulkanDebugRenderer::EndDebugLabel(Ref commandBuffer) + void VulkanDebugRenderer::EndDebugLabel(const Ref& commandBuffer) { - auto cmd = std::static_pointer_cast(commandBuffer); + const auto cmd = std::static_pointer_cast(commandBuffer); + const VkCommandBuffer cb = cmd->GetCurrentCommandBuffer(); - VkCommandBuffer cb = cmd->GetCurrentCommandBuffer(); vkCmdEndDebugUtilsLabelEXT(cb); } } diff --git a/EppoEngine/Source/Platform/Vulkan/VulkanDebugRenderer.h b/EppoEngine/Source/Platform/Vulkan/VulkanDebugRenderer.h index 6804fdfe..a4fade2c 100644 --- a/EppoEngine/Source/Platform/Vulkan/VulkanDebugRenderer.h +++ b/EppoEngine/Source/Platform/Vulkan/VulkanDebugRenderer.h @@ -9,7 +9,7 @@ namespace Eppo public: VulkanDebugRenderer() = default; - void StartDebugLabel(Ref commandBuffer, const std::string& label) override; - void EndDebugLabel(Ref commandBuffer) override; + void StartDebugLabel(const Ref& commandBuffer, const std::string& label) override; + void EndDebugLabel(const Ref& commandBuffer) override; }; } diff --git a/EppoEngine/Source/Platform/Vulkan/VulkanImage.cpp b/EppoEngine/Source/Platform/Vulkan/VulkanImage.cpp index 9dc0e3a7..c7b0878c 100644 --- a/EppoEngine/Source/Platform/Vulkan/VulkanImage.cpp +++ b/EppoEngine/Source/Platform/Vulkan/VulkanImage.cpp @@ -5,8 +5,8 @@ namespace Eppo { - VulkanImage::VulkanImage(const ImageSpecification& specification) - : m_Specification(specification) + VulkanImage::VulkanImage(ImageSpecification specification) + : m_Specification(std::move(specification)) { EPPO_PROFILE_FUNCTION("VulkanImage::VulkanImage"); @@ -87,7 +87,7 @@ namespace Eppo Ref context = VulkanContext::Get(); VkDevice device = context->GetLogicalDevice()->GetNativeDevice(); - VK_CHECK(vkCreateImageView(device, &imageViewCreateInfo, nullptr, &m_ImageInfo.ImageView), "Failed to create image view!"); + VK_CHECK(vkCreateImageView(device, &imageViewCreateInfo, nullptr, &m_ImageInfo.ImageView), "Failed to create image view!") // Sampler Ref physicalDevice = context->GetPhysicalDevice(); @@ -110,7 +110,7 @@ namespace Eppo samplerCreateInfo.minLod = 0.0f; samplerCreateInfo.maxLod = 0.0f; - VK_CHECK(vkCreateSampler(device, &samplerCreateInfo, nullptr, &m_ImageInfo.Sampler), "Failed to create sampler!"); + VK_CHECK(vkCreateSampler(device, &samplerCreateInfo, nullptr, &m_ImageInfo.Sampler), "Failed to create sampler!") VkCommandBuffer commandBuffer = context->GetLogicalDevice()->GetCommandBuffer(true); @@ -139,7 +139,7 @@ namespace Eppo Release(); } - void VulkanImage::SetData(void* data, uint32_t channels) + void VulkanImage::SetData(void* data, const uint32_t channels) { EPPO_PROFILE_FUNCTION("VulkanImage::SetData"); @@ -246,7 +246,7 @@ namespace Eppo vkCmdPipelineBarrier2(commandBuffer, &depInfo); } - VkImageAspectFlags VulkanImage::GetImageAspectFlags(VkImageLayout layout) + VkImageAspectFlags VulkanImage::GetImageAspectFlags(const VkImageLayout layout) { switch (layout) { diff --git a/EppoEngine/Source/Platform/Vulkan/VulkanImage.h b/EppoEngine/Source/Platform/Vulkan/VulkanImage.h index df135085..c35db01d 100644 --- a/EppoEngine/Source/Platform/Vulkan/VulkanImage.h +++ b/EppoEngine/Source/Platform/Vulkan/VulkanImage.h @@ -18,7 +18,7 @@ namespace Eppo class VulkanImage : public Image { public: - explicit VulkanImage(const ImageSpecification& specification); + explicit VulkanImage(ImageSpecification specification); ~VulkanImage() final; void SetData(void* data, uint32_t channels = 4) override; diff --git a/EppoEngine/Source/Platform/Vulkan/VulkanIndexBuffer.cpp b/EppoEngine/Source/Platform/Vulkan/VulkanIndexBuffer.cpp index 3a35e59b..017f1df0 100644 --- a/EppoEngine/Source/Platform/Vulkan/VulkanIndexBuffer.cpp +++ b/EppoEngine/Source/Platform/Vulkan/VulkanIndexBuffer.cpp @@ -6,7 +6,7 @@ namespace Eppo { - VulkanIndexBuffer::VulkanIndexBuffer(uint32_t size) + VulkanIndexBuffer::VulkanIndexBuffer(const uint32_t size) : m_Size(size), m_IsMemoryMapped(true) { // Create GPU local buffer @@ -39,14 +39,14 @@ namespace Eppo VulkanIndexBuffer::~VulkanIndexBuffer() { - EPPO_MEM_WARN("Releasing index buffer {}", (void*)this); + EPPO_MEM_WARN("Releasing index buffer {}", static_cast(this)); if (m_IsMemoryMapped) VulkanAllocator::UnmapMemory(m_Allocation); VulkanAllocator::DestroyBuffer(m_Buffer, m_Allocation); } - void VulkanIndexBuffer::SetData(Buffer buffer) + void VulkanIndexBuffer::SetData(const Buffer buffer) { // If buffer is bigger than our GPU buffer, recreate buffer if (buffer.Size > m_Size) @@ -78,7 +78,7 @@ namespace Eppo CopyWithStagingBuffer(buffer); } - void VulkanIndexBuffer::CopyWithStagingBuffer(Buffer buffer) const + void VulkanIndexBuffer::CopyWithStagingBuffer(const Buffer buffer) const { // Create staging buffer VkBufferCreateInfo stagingBufferInfo{}; @@ -88,7 +88,7 @@ namespace Eppo stagingBufferInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE; VkBuffer stagingBuffer; - VmaAllocation stagingBufferAlloc = VulkanAllocator::AllocateBuffer(stagingBuffer, stagingBufferInfo, VMA_MEMORY_USAGE_CPU_TO_GPU); + const VmaAllocation stagingBufferAlloc = VulkanAllocator::AllocateBuffer(stagingBuffer, stagingBufferInfo, VMA_MEMORY_USAGE_CPU_TO_GPU); // Copy data to staging buffer void* memData = VulkanAllocator::MapMemory(stagingBufferAlloc); @@ -96,11 +96,11 @@ namespace Eppo VulkanAllocator::UnmapMemory(stagingBufferAlloc); // Copy data from staging buffer to GPU local buffer - Ref context = VulkanContext::Get(); - Ref logicalDevice = context->GetLogicalDevice(); - VkCommandBuffer commandBuffer = logicalDevice->GetCommandBuffer(true); + const Ref context = VulkanContext::Get(); + const Ref logicalDevice = context->GetLogicalDevice(); + const VkCommandBuffer commandBuffer = logicalDevice->GetCommandBuffer(true); - VkBufferCopy copyRegion{}; + VkBufferCopy copyRegion; copyRegion.srcOffset = 0; copyRegion.dstOffset = 0; copyRegion.size = buffer.Size; diff --git a/EppoEngine/Source/Platform/Vulkan/VulkanIndexBuffer.h b/EppoEngine/Source/Platform/Vulkan/VulkanIndexBuffer.h index 1180585e..d5485d29 100644 --- a/EppoEngine/Source/Platform/Vulkan/VulkanIndexBuffer.h +++ b/EppoEngine/Source/Platform/Vulkan/VulkanIndexBuffer.h @@ -1,7 +1,6 @@ #pragma once #include "Platform/Vulkan/VulkanAllocator.h" -#include "Platform/Vulkan/VulkanCommandBuffer.h" #include "Renderer/IndexBuffer.h" namespace Eppo @@ -15,8 +14,8 @@ namespace Eppo void SetData(Buffer buffer) override; - VkBuffer GetBuffer() const { return m_Buffer; } - uint32_t GetIndexCount() const override { return m_Size / sizeof(uint32_t); } + [[nodiscard]] VkBuffer GetBuffer() const { return m_Buffer; } + [[nodiscard]] uint32_t GetIndexCount() const override { return m_Size / sizeof(uint32_t); } private: void CopyWithStagingBuffer(Buffer buffer) const; diff --git a/EppoEngine/Source/Platform/Vulkan/VulkanLogicalDevice.cpp b/EppoEngine/Source/Platform/Vulkan/VulkanLogicalDevice.cpp index 233d216a..2ef12144 100644 --- a/EppoEngine/Source/Platform/Vulkan/VulkanLogicalDevice.cpp +++ b/EppoEngine/Source/Platform/Vulkan/VulkanLogicalDevice.cpp @@ -5,7 +5,7 @@ namespace Eppo { - VulkanLogicalDevice::VulkanLogicalDevice(Ref physicalDevice) + VulkanLogicalDevice::VulkanLogicalDevice(const Ref& physicalDevice) : m_PhysicalDevice(physicalDevice) { // Check if requested extensions are supported by the GPU @@ -15,7 +15,7 @@ namespace Eppo if (!m_PhysicalDevice->IsExtensionSupported(extension)) extensionsSupported = false; } - EPPO_ASSERT(extensionsSupported); + EPPO_ASSERT(extensionsSupported) // Create device queue QueueFamilyIndices indices = m_PhysicalDevice->GetQueueFamilyIndices(); @@ -73,7 +73,7 @@ namespace Eppo deviceCreateInfo.ppEnabledLayerNames = nullptr; } - VK_CHECK(vkCreateDevice(physicalDevice->GetNativeDevice(), &deviceCreateInfo, nullptr, &m_Device), "Failed to create logical device!"); + VK_CHECK(vkCreateDevice(physicalDevice->GetNativeDevice(), &deviceCreateInfo, nullptr, &m_Device), "Failed to create logical device!") // Device queue vkGetDeviceQueue(m_Device, indices.Graphics, 0, &m_GraphicsQueue); @@ -84,13 +84,13 @@ namespace Eppo commandPoolCreateInfo.queueFamilyIndex = indices.Graphics; commandPoolCreateInfo.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; - VK_CHECK(vkCreateCommandPool(m_Device, &commandPoolCreateInfo, nullptr, &m_CommandPool), "Failed to create command pool!"); + VK_CHECK(vkCreateCommandPool(m_Device, &commandPoolCreateInfo, nullptr, &m_CommandPool), "Failed to create command pool!") // Clean up Ref context = VulkanContext::Get(); context->SubmitResourceFree([this]() { - EPPO_MEM_WARN("Releasing logical device and command pool {}", (void*)this); + EPPO_MEM_WARN("Releasing logical device and command pool {}", static_cast(this)); vkDestroyCommandPool(m_Device, m_CommandPool, nullptr); vkDeviceWaitIdle(m_Device); @@ -98,7 +98,7 @@ namespace Eppo }); } - VkCommandBuffer VulkanLogicalDevice::GetCommandBuffer(bool begin) const + VkCommandBuffer VulkanLogicalDevice::GetCommandBuffer(const bool begin) const { EPPO_PROFILE_FUNCTION("VulkanLogicalDevice::GetCommandBuffer"); @@ -110,7 +110,7 @@ namespace Eppo allocateInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; allocateInfo.commandBufferCount = 1; - VK_CHECK(vkAllocateCommandBuffers(m_Device, &allocateInfo, &commandBuffer), "Failed to allocate command buffer!"); + VK_CHECK(vkAllocateCommandBuffers(m_Device, &allocateInfo, &commandBuffer), "Failed to allocate command buffer!") if (begin) { @@ -118,7 +118,7 @@ namespace Eppo beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; beginInfo.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; - VK_CHECK(vkBeginCommandBuffer(commandBuffer, &beginInfo), "Failed to begin command buffer!"); + VK_CHECK(vkBeginCommandBuffer(commandBuffer, &beginInfo), "Failed to begin command buffer!") } return commandBuffer; @@ -136,16 +136,16 @@ namespace Eppo allocateInfo.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY; allocateInfo.commandBufferCount = 1; - VK_CHECK(vkAllocateCommandBuffers(m_Device, &allocateInfo, &commandBuffer), "Failed to allocate command buffer!"); + VK_CHECK(vkAllocateCommandBuffers(m_Device, &allocateInfo, &commandBuffer), "Failed to allocate command buffer!") return commandBuffer; } - void VulkanLogicalDevice::FlushCommandBuffer(VkCommandBuffer commandBuffer) const + void VulkanLogicalDevice::FlushCommandBuffer(const VkCommandBuffer commandBuffer) const { EPPO_PROFILE_FUNCTION("VulkanLogicalDevice::FlushCommandBuffer"); - VK_CHECK(vkEndCommandBuffer(commandBuffer), "Failed to end command buffer!"); + VK_CHECK(vkEndCommandBuffer(commandBuffer), "Failed to end command buffer!") VkSubmitInfo submitInfo{}; submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; @@ -158,9 +158,9 @@ namespace Eppo fenceInfo.flags = 0; VkFence fence; - VK_CHECK(vkCreateFence(m_Device, &fenceInfo, nullptr, &fence), "Failed to create fence!"); + VK_CHECK(vkCreateFence(m_Device, &fenceInfo, nullptr, &fence), "Failed to create fence!") - VK_CHECK(vkQueueSubmit(m_GraphicsQueue, 1, &submitInfo, fence), "Failed to submit work to queue!"); + VK_CHECK(vkQueueSubmit(m_GraphicsQueue, 1, &submitInfo, fence), "Failed to submit work to queue!") vkWaitForFences(m_Device, 1, &fence, VK_TRUE, UINT64_MAX); // Clean up diff --git a/EppoEngine/Source/Platform/Vulkan/VulkanLogicalDevice.h b/EppoEngine/Source/Platform/Vulkan/VulkanLogicalDevice.h index 203abdaf..4fa5762a 100644 --- a/EppoEngine/Source/Platform/Vulkan/VulkanLogicalDevice.h +++ b/EppoEngine/Source/Platform/Vulkan/VulkanLogicalDevice.h @@ -7,16 +7,16 @@ namespace Eppo class VulkanLogicalDevice { public: - VulkanLogicalDevice(Ref physicalDevice); + explicit VulkanLogicalDevice(const Ref& physicalDevice); virtual ~VulkanLogicalDevice() = default; - VkDevice GetNativeDevice() const { return m_Device; } + [[nodiscard]] VkDevice GetNativeDevice() const { return m_Device; } - Ref GetPhysicalDevice() const { return m_PhysicalDevice; } - VkQueue GetGraphicsQueue() const { return m_GraphicsQueue; } + [[nodiscard]] Ref GetPhysicalDevice() const { return m_PhysicalDevice; } + [[nodiscard]] VkQueue GetGraphicsQueue() const { return m_GraphicsQueue; } - VkCommandBuffer GetCommandBuffer(bool begin) const; - VkCommandBuffer GetSecondaryCommandBuffer() const; + [[nodiscard]] VkCommandBuffer GetCommandBuffer(bool begin) const; + [[nodiscard]] VkCommandBuffer GetSecondaryCommandBuffer() const; void FlushCommandBuffer(VkCommandBuffer commandBuffer) const; void FreeCommandBuffer(VkCommandBuffer commandBuffer) const; diff --git a/EppoEngine/Source/Platform/Vulkan/VulkanPhysicalDevice.cpp b/EppoEngine/Source/Platform/Vulkan/VulkanPhysicalDevice.cpp index d2a68da9..c915fba7 100644 --- a/EppoEngine/Source/Platform/Vulkan/VulkanPhysicalDevice.cpp +++ b/EppoEngine/Source/Platform/Vulkan/VulkanPhysicalDevice.cpp @@ -7,19 +7,21 @@ namespace Eppo { - static std::string DecodeDriverVersion(uint32_t driverVersion, uint32_t vendorId) + namespace { - std::string versionStr = "Unknown version"; - - switch (vendorId) + std::string DecodeDriverVersion(const uint32_t driverVersion, const uint32_t vendorId) { - // Nvidia + std::string versionStr = "Unknown version"; + + switch (vendorId) + { + // Nvidia case 0x10DE: { - uint32_t d1 = (driverVersion >> 22) & 0x3ff; - uint32_t d2 = (driverVersion >> 14) & 0x0ff; - uint32_t d3 = (driverVersion >> 6) & 0x0ff; - uint32_t d4 = driverVersion & 0x003f; + const uint32_t d1 = (driverVersion >> 22) & 0x3ff; + const uint32_t d2 = (driverVersion >> 14) & 0x0ff; + const uint32_t d3 = (driverVersion >> 6) & 0x0ff; + const uint32_t d4 = driverVersion & 0x003f; versionStr = std::to_string(d1) + "." + std::to_string(d2) + "." + std::to_string(d3) + "." + std::to_string(d4); break; @@ -28,8 +30,8 @@ namespace Eppo // Intel case 0x8086: { - uint32_t d1 = driverVersion >> 14; - uint32_t d2 = driverVersion & 0x3ff; + const uint32_t d1 = driverVersion >> 14; + const uint32_t d2 = driverVersion & 0x3ff; versionStr = std::to_string(d1) + "." + std::to_string(d2); break; @@ -37,34 +39,35 @@ namespace Eppo default: { - uint32_t d1 = driverVersion >> 22; - uint32_t d2 = (driverVersion >> 12) & 0x3ff; - uint32_t d3 = driverVersion & 0xfff; + const uint32_t d1 = driverVersion >> 22; + const uint32_t d2 = (driverVersion >> 12) & 0x3ff; + const uint32_t d3 = driverVersion & 0xfff; versionStr = std::to_string(d1) + "." + std::to_string(d2) + "." + std::to_string(d3); } + } + + return versionStr; } - return versionStr; + const std::unordered_map s_GpuVendors = { + { 0x1002, "AMD" }, + { 0x1010, "ImgTec" }, + { 0x10DE, "NVIDIA" }, + { 0x13B5, "ARM" }, + { 0x5143, "Qualcomm" }, + { 0x8086, "Intel" } + }; } - static const std::unordered_map s_GpuVendors = { - { 0x1002, "AMD" }, - { 0x1010, "ImgTec" }, - { 0x10DE, "NVIDIA" }, - { 0x13B5, "ARM" }, - { 0x5143, "Qualcomm" }, - { 0x8086, "Intel" } - }; - VulkanPhysicalDevice::VulkanPhysicalDevice() { - auto instance = VulkanContext::GetVulkanInstance(); + const auto instance = VulkanContext::GetVulkanInstance(); // Get physical devices available uint32_t deviceCount = 0; vkEnumeratePhysicalDevices(instance, &deviceCount, nullptr); - EPPO_ASSERT(deviceCount > 0); + EPPO_ASSERT(deviceCount > 0) std::vector devices(deviceCount); vkEnumeratePhysicalDevices(instance, &deviceCount, devices.data()); @@ -85,7 +88,7 @@ namespace Eppo { EPPO_WARN("No discrete GPU found!"); m_PhysicalDevice = devices.back(); - EPPO_ASSERT(m_PhysicalDevice); + EPPO_ASSERT(m_PhysicalDevice) } // Get properties and features from selected device @@ -102,11 +105,11 @@ namespace Eppo // Create surface Ref context = VulkanContext::Get(); - VK_CHECK(glfwCreateWindowSurface(VulkanContext::GetVulkanInstance(), context->GetWindowHandle(), nullptr, &m_Surface), "Failed to create surface!"); + VK_CHECK(glfwCreateWindowSurface(VulkanContext::GetVulkanInstance(), context->GetWindowHandle(), nullptr, &m_Surface), "Failed to create surface!") context->SubmitResourceFree([this]() { - EPPO_WARN("Releasing surface {}", (void*)this); + EPPO_WARN("Releasing surface {}", static_cast(this)); vkDestroySurfaceKHR(VulkanContext::GetVulkanInstance(), m_Surface, nullptr); }); @@ -121,8 +124,8 @@ namespace Eppo vkEnumerateDeviceExtensionProperties(m_PhysicalDevice, nullptr, &extensionCount, availableExtensions.data()); EPPO_INFO("Selected device has {} extensions", availableExtensions.size()); - for (const auto& extension : availableExtensions) - m_SupportedExtensions.emplace_back(extension.extensionName); + for (const auto& [extensionName, specVersion] : availableExtensions) + m_SupportedExtensions.emplace_back(extensionName); // Device image formats // These formats are mandatory to be supported @@ -143,7 +146,7 @@ namespace Eppo } } - bool VulkanPhysicalDevice::IsExtensionSupported(std::string_view extension) + bool VulkanPhysicalDevice::IsExtensionSupported(const std::string_view extension) { return std::find(m_SupportedExtensions.begin(), m_SupportedExtensions.end(), extension) != m_SupportedExtensions.end(); } diff --git a/EppoEngine/Source/Platform/Vulkan/VulkanPhysicalDevice.h b/EppoEngine/Source/Platform/Vulkan/VulkanPhysicalDevice.h index 43969cd0..5403dd65 100644 --- a/EppoEngine/Source/Platform/Vulkan/VulkanPhysicalDevice.h +++ b/EppoEngine/Source/Platform/Vulkan/VulkanPhysicalDevice.h @@ -10,7 +10,7 @@ namespace Eppo int32_t Graphics = -1; int32_t Present = -1; - bool IsComplete() const + [[nodiscard]] bool IsComplete() const { return Graphics > -1 && Present > -1; } @@ -22,21 +22,21 @@ namespace Eppo VulkanPhysicalDevice(); ~VulkanPhysicalDevice() = default; - VkPhysicalDevice GetNativeDevice() const { return m_PhysicalDevice; } - VkSurfaceKHR GetSurface() const { return m_Surface; } + [[nodiscard]] VkPhysicalDevice GetNativeDevice() const { return m_PhysicalDevice; } + [[nodiscard]] VkSurfaceKHR GetSurface() const { return m_Surface; } - QueueFamilyIndices& GetQueueFamilyIndices() { return m_QueueFamilyIndices; } - const QueueFamilyIndices& GetQueueFamilyIndices() const { return m_QueueFamilyIndices; } + [[nodiscard]] QueueFamilyIndices& GetQueueFamilyIndices() { return m_QueueFamilyIndices; } + [[nodiscard]] const QueueFamilyIndices& GetQueueFamilyIndices() const { return m_QueueFamilyIndices; } - const VkPhysicalDeviceProperties& GetDeviceProperties() const { return m_Properties; } - const VkPhysicalDeviceMemoryProperties& GetDeviceMemoryProperties() const { return m_MemoryProperties; } - const VkPhysicalDeviceFeatures& GetDeviceFeatures() const { return m_Features; } + [[nodiscard]] const VkPhysicalDeviceProperties& GetDeviceProperties() const { return m_Properties; } + [[nodiscard]] const VkPhysicalDeviceMemoryProperties& GetDeviceMemoryProperties() const { return m_MemoryProperties; } + [[nodiscard]] const VkPhysicalDeviceFeatures& GetDeviceFeatures() const { return m_Features; } - VkFormat GetSupportedImageFormat(ImageFormat format) { return m_SupportedImageFormats[format]; } + [[nodiscard]] VkFormat GetSupportedImageFormat(const ImageFormat format) { return m_SupportedImageFormats[format]; } bool IsExtensionSupported(std::string_view extension); private: - QueueFamilyIndices FindQueueFamilyIndices() const; + [[nodiscard]] QueueFamilyIndices FindQueueFamilyIndices() const; private: VkPhysicalDevice m_PhysicalDevice; diff --git a/EppoEngine/Source/Platform/Vulkan/VulkanPipeline.cpp b/EppoEngine/Source/Platform/Vulkan/VulkanPipeline.cpp index b3eee084..48a08796 100644 --- a/EppoEngine/Source/Platform/Vulkan/VulkanPipeline.cpp +++ b/EppoEngine/Source/Platform/Vulkan/VulkanPipeline.cpp @@ -8,9 +8,9 @@ namespace Eppo { - namespace Utils + namespace { - static VkPrimitiveTopology TopologyToVkTopology(const PrimitiveTopology topology) + VkPrimitiveTopology TopologyToVkTopology(const PrimitiveTopology topology) { switch (topology) { @@ -22,7 +22,7 @@ namespace Eppo return VK_PRIMITIVE_TOPOLOGY_MAX_ENUM; } - static VkPolygonMode PolygonModeToVkPolygonMode(const PolygonMode mode) + VkPolygonMode PolygonModeToVkPolygonMode(const PolygonMode mode) { switch (mode) { @@ -34,7 +34,7 @@ namespace Eppo return VK_POLYGON_MODE_MAX_ENUM; } - static VkCullModeFlags CullModeToVkCullMode(const CullMode mode) + VkCullModeFlags CullModeToVkCullMode(const CullMode mode) { switch (mode) { @@ -47,7 +47,7 @@ namespace Eppo return VK_CULL_MODE_FLAG_BITS_MAX_ENUM; } - static VkFrontFace CullFrontFaceToVkFrontFace(const CullFrontFace frontFace) + VkFrontFace CullFrontFaceToVkFrontFace(const CullFrontFace frontFace) { switch (frontFace) { @@ -59,7 +59,7 @@ namespace Eppo return VK_FRONT_FACE_MAX_ENUM; } - static VkCompareOp DepthCompareOpToVkCompareOp(const DepthCompareOp op) + VkCompareOp DepthCompareOpToVkCompareOp(const DepthCompareOp op) { switch (op) { @@ -111,7 +111,7 @@ namespace Eppo VkPipelineInputAssemblyStateCreateInfo inputAssemblyStateCreateInfo{}; inputAssemblyStateCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; - inputAssemblyStateCreateInfo.topology = Utils::TopologyToVkTopology(m_Specification.Topology); + inputAssemblyStateCreateInfo.topology = TopologyToVkTopology(m_Specification.Topology); inputAssemblyStateCreateInfo.primitiveRestartEnable = VK_FALSE; VkPipelineViewportStateCreateInfo viewportStateCreateInfo{}; @@ -123,10 +123,10 @@ namespace Eppo rasterizationStateCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; rasterizationStateCreateInfo.depthClampEnable = VK_FALSE; rasterizationStateCreateInfo.rasterizerDiscardEnable = VK_FALSE; - rasterizationStateCreateInfo.polygonMode = Utils::PolygonModeToVkPolygonMode(m_Specification.PolygonMode); + rasterizationStateCreateInfo.polygonMode = PolygonModeToVkPolygonMode(m_Specification.PolygonMode); rasterizationStateCreateInfo.lineWidth = 1.0f; - rasterizationStateCreateInfo.cullMode = Utils::CullModeToVkCullMode(m_Specification.CullMode); - rasterizationStateCreateInfo.frontFace = Utils::CullFrontFaceToVkFrontFace(m_Specification.CullFrontFace); + rasterizationStateCreateInfo.cullMode = CullModeToVkCullMode(m_Specification.CullMode); + rasterizationStateCreateInfo.frontFace = CullFrontFaceToVkFrontFace(m_Specification.CullFrontFace); rasterizationStateCreateInfo.depthBiasEnable = VK_FALSE; rasterizationStateCreateInfo.depthBiasConstantFactor = 0.0f; rasterizationStateCreateInfo.depthBiasClamp = 0.0f; @@ -145,7 +145,7 @@ namespace Eppo depthStencilStateCreateInfo.stencilTestEnable = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO; depthStencilStateCreateInfo.depthTestEnable = m_Specification.TestDepth; depthStencilStateCreateInfo.depthWriteEnable = m_Specification.WriteDepth; - depthStencilStateCreateInfo.depthCompareOp = Utils::DepthCompareOpToVkCompareOp(m_Specification.DepthCompareOp); + depthStencilStateCreateInfo.depthCompareOp = DepthCompareOpToVkCompareOp(m_Specification.DepthCompareOp); depthStencilStateCreateInfo.depthBoundsTestEnable = VK_FALSE; depthStencilStateCreateInfo.minDepthBounds = 0.0f; depthStencilStateCreateInfo.maxDepthBounds = 1.0f; diff --git a/EppoEngine/Source/Platform/Vulkan/VulkanSceneRenderer.cpp b/EppoEngine/Source/Platform/Vulkan/VulkanSceneRenderer.cpp index 8fc38baa..1fcd5072 100644 --- a/EppoEngine/Source/Platform/Vulkan/VulkanSceneRenderer.cpp +++ b/EppoEngine/Source/Platform/Vulkan/VulkanSceneRenderer.cpp @@ -305,7 +305,7 @@ namespace Eppo Flush(); } - void VulkanSceneRenderer::SubmitDrawCommand(EntityType type, Ref drawCommand) + void VulkanSceneRenderer::SubmitDrawCommand(const EntityType type, Ref drawCommand) { EPPO_PROFILE_FUNCTION("VulkanSceneRenderer::SubmitDrawCommand"); diff --git a/EppoEngine/Source/Platform/Vulkan/VulkanShader.cpp b/EppoEngine/Source/Platform/Vulkan/VulkanShader.cpp index b3a9a948..03f8e703 100644 --- a/EppoEngine/Source/Platform/Vulkan/VulkanShader.cpp +++ b/EppoEngine/Source/Platform/Vulkan/VulkanShader.cpp @@ -12,9 +12,9 @@ namespace Eppo { - namespace Utils + namespace { - inline shaderc_shader_kind ShaderStageToShaderCKind(const ShaderStage stage) + shaderc_shader_kind ShaderStageToShaderCKind(const ShaderStage stage) { switch (stage) { @@ -26,7 +26,7 @@ namespace Eppo return static_cast(-1); } - inline VkShaderStageFlagBits ShaderStageToVkShaderStage(const ShaderStage stage) + VkShaderStageFlagBits ShaderStageToVkShaderStage(const ShaderStage stage) { if (stage == ShaderStage::Vertex) return VK_SHADER_STAGE_VERTEX_BIT; if (stage == ShaderStage::Fragment) return VK_SHADER_STAGE_FRAGMENT_BIT; @@ -34,7 +34,7 @@ namespace Eppo return VK_SHADER_STAGE_FLAG_BITS_MAX_ENUM; } - inline VkDescriptorType ShaderResourceTypeToVkDescriptorType(const ShaderResourceType type) + VkDescriptorType ShaderResourceTypeToVkDescriptorType(const ShaderResourceType type) { if (type == ShaderResourceType::UniformBuffer) return VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; if (type == ShaderResourceType::Sampler) return VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; @@ -52,7 +52,7 @@ namespace Eppo const std::string shaderSource = Filesystem::ReadText(GetSpecification().Filepath); // Preprocess by shader stage - auto sources = PreProcess(shaderSource); + const auto sources = PreProcess(shaderSource); // Compile or get cache CompileOrGetCache(sources); @@ -77,7 +77,7 @@ namespace Eppo std::unordered_map shaderSources; // Find stage token - constexpr char* stageToken = "#stage"; + const auto stageToken = "#stage"; const size_t stageTokenLength = strlen(stageToken); size_t pos = source.find(stageToken, 0); @@ -109,7 +109,7 @@ namespace Eppo options.SetIncluder(CreateScope()); options.SetOptimizationLevel(shaderc_optimization_level_zero); - auto result = compiler.PreprocessGlsl(stageSource, Utils::ShaderStageToShaderCKind(stage), GetSpecification().Filepath.string().c_str(), options); + auto result = compiler.PreprocessGlsl(stageSource, ShaderStageToShaderCKind(stage), GetSpecification().Filepath.string().c_str(), options); stageSource = std::string(result.cbegin(), result.cend()); } @@ -128,7 +128,7 @@ namespace Eppo options.SetGenerateDebugInfo(); // Compile source - const shaderc::SpvCompilationResult result = compiler.CompileGlslToSpv(source, Utils::ShaderStageToShaderCKind(stage), GetSpecification().Filepath.string().c_str(), options); + const shaderc::SpvCompilationResult result = compiler.CompileGlslToSpv(source, ShaderStageToShaderCKind(stage), GetSpecification().Filepath.string().c_str(), options); if (result.GetCompilationStatus() != shaderc_compilation_status_success) { EPPO_ERROR("Failed to compile shader with filename: {}", GetSpecification().Filepath); @@ -138,7 +138,6 @@ namespace Eppo m_ShaderBytes[stage] = std::vector(result.cbegin(), result.cend()); - // TODO: // Write cache const std::string cachePath = Utils::GetOrCreateCacheDirectory().string() + "/" + GetName() + "." + Utils::ShaderStageToString(stage); Filesystem::WriteBytes(cachePath, m_ShaderBytes.at(stage)); @@ -165,11 +164,13 @@ namespace Eppo if (Filesystem::Exists(cacheFile) && Filesystem::Exists(cacheHashFile)) { std::string hash = std::to_string(Hash::GenerateFnv(source)); - std::string cacheHash = Filesystem::ReadText(cacheHashFile); - + // Check if cache needs to be busted - if (cacheHash == hash) + if (std::string cacheHash = Filesystem::ReadText(cacheHashFile); + cacheHash == hash) + { cacheVerified = true; + } } if (cacheVerified) @@ -339,7 +340,7 @@ namespace Eppo VkPipelineShaderStageCreateInfo& shaderStageCreateInfo = m_ShaderInfos.emplace_back(); shaderStageCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; - shaderStageCreateInfo.stage = Utils::ShaderStageToVkShaderStage(type); + shaderStageCreateInfo.stage = ShaderStageToVkShaderStage(type); shaderStageCreateInfo.module = shaderModule; shaderStageCreateInfo.pName = "main"; @@ -371,11 +372,11 @@ namespace Eppo // TODO: This is as dirty as code can get if (resource.Binding == 0 && set == 2) { - builder.AddBinding(resource.Binding, Utils::ShaderResourceTypeToVkDescriptorType(resource.ResourceType), 512); + builder.AddBinding(resource.Binding, ShaderResourceTypeToVkDescriptorType(resource.ResourceType), 512); continue; } - builder.AddBinding(resource.Binding, Utils::ShaderResourceTypeToVkDescriptorType(resource.ResourceType), resource.ArraySize); + builder.AddBinding(resource.Binding, ShaderResourceTypeToVkDescriptorType(resource.ResourceType), resource.ArraySize); } m_DescriptorSetLayouts[set] = builder.Build(VK_SHADER_STAGE_ALL); diff --git a/EppoEngine/Source/Platform/Vulkan/VulkanSwapchain.h b/EppoEngine/Source/Platform/Vulkan/VulkanSwapchain.h index 32141882..b9ce09cf 100644 --- a/EppoEngine/Source/Platform/Vulkan/VulkanSwapchain.h +++ b/EppoEngine/Source/Platform/Vulkan/VulkanSwapchain.h @@ -42,9 +42,9 @@ namespace Eppo private: SwapchainSupportDetails QuerySwapchainSupportDetails(const Ref& physicalDevice) const; - VkSurfaceFormatKHR SelectSurfaceFormat(const std::vector& surfaceFormats); - VkPresentModeKHR SelectPresentMode(const std::vector& presentModes); - VkExtent2D SelectExtent(const VkSurfaceCapabilitiesKHR& capabilities); + static VkSurfaceFormatKHR SelectSurfaceFormat(const std::vector& surfaceFormats); + static VkPresentModeKHR SelectPresentMode(const std::vector& presentModes); + static VkExtent2D SelectExtent(const VkSurfaceCapabilitiesKHR& capabilities); private: Ref m_LogicalDevice; diff --git a/EppoEngine/Source/Project/Project.cpp b/EppoEngine/Source/Project/Project.cpp index 26a3b407..f805bc48 100644 --- a/EppoEngine/Source/Project/Project.cpp +++ b/EppoEngine/Source/Project/Project.cpp @@ -97,7 +97,7 @@ namespace Eppo s_ActiveProject->GetAssetManagerEditor()->SerializeAssetRegistry(); - ProjectSerializer serializer(s_ActiveProject); + const ProjectSerializer serializer(s_ActiveProject); return serializer.Serialize(); } } diff --git a/EppoEngine/Source/Renderer/DebugRenderer.h b/EppoEngine/Source/Renderer/DebugRenderer.h index 4986e027..0c3ef882 100644 --- a/EppoEngine/Source/Renderer/DebugRenderer.h +++ b/EppoEngine/Source/Renderer/DebugRenderer.h @@ -9,8 +9,8 @@ namespace Eppo public: virtual ~DebugRenderer() = default; - virtual void StartDebugLabel(Ref commandBuffer, const std::string& label) = 0; - virtual void EndDebugLabel(Ref commandBuffer) = 0; + virtual void StartDebugLabel(const Ref& commandBuffer, const std::string& label) = 0; + virtual void EndDebugLabel(const Ref& commandBuffer) = 0; static Ref Create(); }; diff --git a/EppoEngine/Source/Scene/Components.h b/EppoEngine/Source/Scene/Components.h index d69eaa6d..4822b9ae 100644 --- a/EppoEngine/Source/Scene/Components.h +++ b/EppoEngine/Source/Scene/Components.h @@ -19,6 +19,9 @@ namespace Eppo UUID ID; IDComponent() = default; + explicit IDComponent(const UUID uuid) + : ID(uuid) + {} }; struct TagComponent @@ -28,8 +31,7 @@ namespace Eppo TagComponent() = default; explicit TagComponent(std::string tag) : Tag(std::move(tag)) - { - } + {} }; struct TransformComponent diff --git a/EppoEngine/Source/Scene/Scene.cpp b/EppoEngine/Source/Scene/Scene.cpp index d6d1ff3b..c0f1e8b3 100644 --- a/EppoEngine/Source/Scene/Scene.cpp +++ b/EppoEngine/Source/Scene/Scene.cpp @@ -11,29 +11,29 @@ namespace Eppo { - static auto* s_collisionConfig = new btDefaultCollisionConfiguration(); - static auto* s_collisionDispatcher = new btCollisionDispatcher(s_collisionConfig); - static btBroadphaseInterface* s_broadPhaseInterface = new btDbvtBroadphase(); - static auto* s_Solver = new btSequentialImpulseConstraintSolver(); - - namespace Utils + namespace { - static glm::vec3 BulletToGlm(const btVector3& v) + auto* s_collisionConfig = new btDefaultCollisionConfiguration(); + auto* s_collisionDispatcher = new btCollisionDispatcher(s_collisionConfig); + btBroadphaseInterface* s_broadPhaseInterface = new btDbvtBroadphase(); + auto* s_Solver = new btSequentialImpulseConstraintSolver(); + + glm::vec3 BulletToGlm(const btVector3& v) { return { v.getX(), v.getY(), v.getZ() }; } - static glm::quat BulletToGlm(const btQuaternion& q) + glm::quat BulletToGlm(const btQuaternion& q) { return { q.getW(), q.getX(), q.getY(), q.getZ() }; } - static btVector3 GlmToBullet(const glm::vec3& v) + btVector3 GlmToBullet(const glm::vec3& v) { return { v.x, v.y, v.z }; } - static btQuaternion GlmToBullet(const glm::quat& q) + btQuaternion GlmToBullet(const glm::quat& q) { return { q.x, q.y, q.z, q.w }; } @@ -82,7 +82,7 @@ namespace Eppo body->getMotionState()->getWorldTransform(trans); const auto& position = trans.getOrigin(); - transform.Translation = Utils::BulletToGlm(position); + transform.Translation = BulletToGlm(position); trans.getRotation().getEulerZYX(transform.Rotation.z, transform.Rotation.y, transform.Rotation.x); } @@ -106,16 +106,14 @@ namespace Eppo const SceneCamera* sceneCamera = nullptr; glm::mat4 cameraTransform; + const auto view = m_Registry.view(); + for (const auto e : view) { - const auto view = m_Registry.view(); - for (const auto e : view) - { - auto [transform, camera] = view.get(e); - sceneCamera = &camera.Camera; - cameraTransform = transform.GetTransform(); + auto [transform, camera] = view.get(e); + sceneCamera = &camera.Camera; + cameraTransform = transform.GetTransform(); - break; - } + break; } if (sceneCamera) @@ -309,7 +307,7 @@ namespace Eppo btTransform bTransform; bTransform.setIdentity(); bTransform.setOrigin(btVector3(transform.Translation.x, transform.Translation.y, transform.Translation.z)); - bTransform.setRotation(Utils::GlmToBullet(glm::quat(transform.Rotation))); + bTransform.setRotation(GlmToBullet(glm::quat(transform.Rotation))); const bool isDynamic = rigidbody.Type == RigidBodyComponent::BodyType::Dynamic; btScalar mass(0.0f); diff --git a/EppoEngine/Source/Scene/SceneSerializer.cpp b/EppoEngine/Source/Scene/SceneSerializer.cpp index c5677633..dbd6c422 100644 --- a/EppoEngine/Source/Scene/SceneSerializer.cpp +++ b/EppoEngine/Source/Scene/SceneSerializer.cpp @@ -348,8 +348,8 @@ namespace Eppo out << YAML::Key << "MeshComponent" << YAML::Value; out << YAML::BeginMap; - const auto& c = entity.GetComponent(); - out << YAML::Key << "MeshHandle" << YAML::Value << c.MeshHandle; + const auto& [meshHandle] = entity.GetComponent(); + out << YAML::Key << "MeshHandle" << YAML::Value << meshHandle; out << YAML::EndMap; } @@ -460,9 +460,9 @@ namespace Eppo out << YAML::Key << "PointLightComponent" << YAML::Value; out << YAML::BeginMap; - const auto& c = entity.GetComponent(); + const auto& [color] = entity.GetComponent(); - out << YAML::Key << "Color" << YAML::Value << c.Color; + out << YAML::Key << "Color" << YAML::Value << color; out << YAML::EndMap; } diff --git a/EppoEngine/Source/Scripting/ScriptClass.h b/EppoEngine/Source/Scripting/ScriptClass.h index ead84533..149260a8 100644 --- a/EppoEngine/Source/Scripting/ScriptClass.h +++ b/EppoEngine/Source/Scripting/ScriptClass.h @@ -17,7 +17,7 @@ namespace Eppo [[nodiscard]] MonoObject* Instantiate() const; [[nodiscard]] MonoMethod* GetMethod(const std::string& name, uint32_t paramCount) const; - MonoObject* InvokeMethod(MonoObject* instance, MonoMethod* method, void** params = nullptr); + static MonoObject* InvokeMethod(MonoObject* instance, MonoMethod* method, void** params = nullptr); [[nodiscard]] const std::unordered_map& GetFields() const { return m_Fields; } diff --git a/EppoEngine/Source/Scripting/ScriptEngine.cpp b/EppoEngine/Source/Scripting/ScriptEngine.cpp index c7f882f1..4512dbce 100644 --- a/EppoEngine/Source/Scripting/ScriptEngine.cpp +++ b/EppoEngine/Source/Scripting/ScriptEngine.cpp @@ -16,29 +16,61 @@ namespace Eppo { - static std::unordered_map s_ScriptFieldTypeMap { - { "System.Single", ScriptFieldType::Float }, - { "System.Double", ScriptFieldType::Double }, - { "System.Boolean", ScriptFieldType::Bool }, - { "System.Char", ScriptFieldType::Char }, - { "System.Int16", ScriptFieldType::Int16 }, - { "System.Int32", ScriptFieldType::Int32 }, - { "System.Int64", ScriptFieldType::Int64 }, - { "System.Byte", ScriptFieldType::Byte }, - { "System.UInt16", ScriptFieldType::UInt16 }, - { "System.UInt32", ScriptFieldType::UInt32 }, - { "System.UInt64", ScriptFieldType::UInt64 }, - - { "Eppo.Vector2", ScriptFieldType::Vector2 }, - { "Eppo.Vector3", ScriptFieldType::Vector3 }, - { "Eppo.Vector4", ScriptFieldType::Vector4 }, - - { "Eppo.Entity", ScriptFieldType::Entity }, + struct ScriptEngineData + { + MonoDomain* RootDomain = nullptr; + MonoDomain* AppDomain = nullptr; + + MonoAssembly* CoreAssembly = nullptr; + MonoImage* CoreAssemblyImage = nullptr; + std::filesystem::path CoreAssemblyFilepath; + + MonoAssembly* AppAssembly = nullptr; + MonoImage* AppAssemblyImage = nullptr; + std::filesystem::path AppAssemblyFilepath; + Scope> AppAssemblyFileWatcher; + bool AppAssemblyReloadPending = false; + + Ref EntityClass; + + std::unordered_map> EntityScriptClasses; + std::unordered_map> EntityScriptInstances; + std::unordered_map EntityScriptFields; + + Ref SceneContext; + +#if defined(EPPO_DEBUG) + bool EnableDebugging = true; +#else + bool EnableDebugging = false; +#endif }; - namespace Utils + namespace { - static MonoAssembly* LoadMonoAssembly(const std::filesystem::path& filepath, const bool loadPDB = false) + std::unordered_map s_ScriptFieldTypeMap { + { "System.Single", ScriptFieldType::Float }, + { "System.Double", ScriptFieldType::Double }, + { "System.Boolean", ScriptFieldType::Bool }, + { "System.Char", ScriptFieldType::Char }, + { "System.Int16", ScriptFieldType::Int16 }, + { "System.Int32", ScriptFieldType::Int32 }, + { "System.Int64", ScriptFieldType::Int64 }, + { "System.Byte", ScriptFieldType::Byte }, + { "System.UInt16", ScriptFieldType::UInt16 }, + { "System.UInt32", ScriptFieldType::UInt32 }, + { "System.UInt64", ScriptFieldType::UInt64 }, + + { "Eppo.Vector2", ScriptFieldType::Vector2 }, + { "Eppo.Vector3", ScriptFieldType::Vector3 }, + { "Eppo.Vector4", ScriptFieldType::Vector4 }, + + { "Eppo.Entity", ScriptFieldType::Entity }, + }; + + ScriptEngineData* s_Data; + + MonoAssembly* LoadMonoAssembly(const std::filesystem::path& filepath, const bool loadPDB = false) { ScopedBuffer buffer(Filesystem::ReadBytes(filepath)); @@ -71,7 +103,7 @@ namespace Eppo return assembly; } - static ScriptFieldType MonoTypeToScriptFieldType(MonoType* monoType) + ScriptFieldType MonoTypeToScriptFieldType(MonoType* monoType) { const std::string type = mono_type_get_name(monoType); @@ -85,38 +117,6 @@ namespace Eppo } } - struct ScriptEngineData - { - MonoDomain* RootDomain = nullptr; - MonoDomain* AppDomain = nullptr; - - MonoAssembly* CoreAssembly = nullptr; - MonoImage* CoreAssemblyImage = nullptr; - std::filesystem::path CoreAssemblyFilepath; - - MonoAssembly* AppAssembly = nullptr; - MonoImage* AppAssemblyImage = nullptr; - std::filesystem::path AppAssemblyFilepath; - Scope> AppAssemblyFileWatcher; - bool AppAssemblyReloadPending = false; - - Ref EntityClass; - - std::unordered_map> EntityScriptClasses; - std::unordered_map> EntityScriptInstances; - std::unordered_map EntityScriptFields; - - Ref SceneContext; - - #if defined(EPPO_DEBUG) - bool EnableDebugging = true; - #else - bool EnableDebugging = false; - #endif - }; - - static ScriptEngineData* s_Data; - void ScriptEngine::Init() { EPPO_PROFILE_FUNCTION("ScriptEngine::Init"); @@ -186,7 +186,7 @@ namespace Eppo // Load assembly s_Data->AppAssemblyFilepath = filepath; - s_Data->AppAssembly = Utils::LoadMonoAssembly(filepath, s_Data->EnableDebugging); + s_Data->AppAssembly = LoadMonoAssembly(filepath, s_Data->EnableDebugging); if (s_Data->AppAssembly == nullptr) return false; @@ -366,12 +366,12 @@ namespace Eppo EPPO_PROFILE_FUNCTION("ScriptEngine::LoadCoreAssembly"); // Setup appdomain - s_Data->AppDomain = mono_domain_create_appdomain("EppoScriptRuntime", nullptr); + s_Data->AppDomain = mono_domain_create_appdomain(const_cast("EppoScriptRuntime"), nullptr); mono_domain_set(s_Data->AppDomain, true); // Setup core assembly s_Data->CoreAssemblyFilepath = filepath; - s_Data->CoreAssembly = Utils::LoadMonoAssembly(filepath, s_Data->EnableDebugging); + s_Data->CoreAssembly = LoadMonoAssembly(filepath, s_Data->EnableDebugging); if (s_Data->CoreAssembly == nullptr) return false; @@ -436,7 +436,7 @@ namespace Eppo MonoType* fieldType = mono_field_get_type(field); std::string fieldName = mono_field_get_name(field); - const ScriptFieldType scriptFieldType = Utils::MonoTypeToScriptFieldType(fieldType); + const ScriptFieldType scriptFieldType = MonoTypeToScriptFieldType(fieldType); if (scriptFieldType == ScriptFieldType::None) continue; diff --git a/EppoEngine/Source/Scripting/ScriptField.h b/EppoEngine/Source/Scripting/ScriptField.h index 640a2df0..d9d4b999 100644 --- a/EppoEngine/Source/Scripting/ScriptField.h +++ b/EppoEngine/Source/Scripting/ScriptField.h @@ -20,13 +20,13 @@ namespace Eppo ScriptFieldType Type; std::string Name; - MonoClassField* ClassField; + MonoClassField* ClassField = nullptr; }; class ScriptFieldInstance { public: - ScriptField Field; + ScriptField Field{}; ScriptFieldInstance() { diff --git a/EppoEngine/Source/Scripting/ScriptGlue.cpp b/EppoEngine/Source/Scripting/ScriptGlue.cpp index 76613389..e1e5ff26 100644 --- a/EppoEngine/Source/Scripting/ScriptGlue.cpp +++ b/EppoEngine/Source/Scripting/ScriptGlue.cpp @@ -11,7 +11,10 @@ namespace Eppo { - static std::unordered_map> s_EntityHasComponentFns; + namespace + { + std::unordered_map> s_EntityHasComponentFns; + } #define EPPO_ADD_INTERNAL_CALL(fn) mono_add_internal_call("Eppo.InternalCalls::"#fn, reinterpret_cast(fn)); diff --git a/EppoEngine/Source/Scripting/ScriptInstance.cpp b/EppoEngine/Source/Scripting/ScriptInstance.cpp index 252ceb23..e02070dc 100644 --- a/EppoEngine/Source/Scripting/ScriptInstance.cpp +++ b/EppoEngine/Source/Scripting/ScriptInstance.cpp @@ -20,7 +20,7 @@ namespace Eppo UUID uuid = entity.GetUUID(); void* param = &uuid; - m_ScriptClass->InvokeMethod(m_Instance, m_Constructor, ¶m); + ScriptClass::InvokeMethod(m_Instance, m_Constructor, ¶m); } void ScriptInstance::InvokeOnCreate() const @@ -28,7 +28,7 @@ namespace Eppo EPPO_PROFILE_FUNCTION("ScriptInstance::InvokeOnCreate"); if (m_OnCreate) - m_ScriptClass->InvokeMethod(m_Instance, m_OnCreate); + ScriptClass::InvokeMethod(m_Instance, m_OnCreate); } void ScriptInstance::InvokeOnUpdate(float timestep) const @@ -38,7 +38,7 @@ namespace Eppo if (m_OnUpdate) { void* params = ×tep; - m_ScriptClass->InvokeMethod(m_Instance, m_OnUpdate, ¶ms); + ScriptClass::InvokeMethod(m_Instance, m_OnUpdate, ¶ms); } } diff --git a/EppoEngine/premake5.lua b/EppoEngine/premake5.lua index fe358a7f..d64bf1e2 100644 --- a/EppoEngine/premake5.lua +++ b/EppoEngine/premake5.lua @@ -1,7 +1,7 @@ project "EppoEngine" kind "StaticLib" language "C++" - cppdialect "C++17" + cppdialect "C++20" staticruntime "Off" targetdir ("%{wks.location}/Bin/" .. OutputDir .. "/%{prj.name}") diff --git a/EppoScripting/EppoScripting.csproj b/EppoScripting/EppoScripting.csproj new file mode 100644 index 00000000..0e2db6fc --- /dev/null +++ b/EppoScripting/EppoScripting.csproj @@ -0,0 +1,79 @@ + + + + + Debug + x64 + {0CC98CBB-7889-08F2-41C4-516FAD434DCE} + Library + Properties + EppoScripting + EppoScripting + v4.8 + 512 + true + + + x64 + portable + true + false + ..\EppoEditor\Resources\Scripts\ + ..\EppoEditor\Scripts\Intermediates\Debug\ + $(BaseIntermediateOutputPath) + + prompt + 4 + + + x64 + portable + true + true + ..\EppoEditor\Resources\Scripts\ + ..\EppoEditor\Scripts\Intermediates\Release\ + $(BaseIntermediateOutputPath) + + prompt + 4 + + + x64 + none + false + true + ..\EppoEditor\Resources\Scripts\ + ..\EppoEditor\Scripts\Intermediates\Dist\ + $(BaseIntermediateOutputPath) + + prompt + 4 + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/EppoTesting/CMakeLists.txt b/EppoTesting/CMakeLists.txt index 6dbfcbf0..bf77ac21 100644 --- a/EppoTesting/CMakeLists.txt +++ b/EppoTesting/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.24) project(EppoTesting VERSION 1.0 LANGUAGES CXX) -set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) # Sources @@ -29,4 +29,4 @@ target_link_libraries(${PROJECT_NAME} PRIVATE ${BULLET_COLLISION_LIBRARY} ${BULLET_DYNAMICS_LIBRARY} ${BULLET_MATH_LIBRARY} ${BULLET_SOFTBODY_LIBRARY} ${mono_LIBRARIES} ${Vulkan_LIBRARY} shaderc_combined spirv-cross-core spirv-cross-glsl -) \ No newline at end of file +) diff --git a/EppoTesting/premake5.lua b/EppoTesting/premake5.lua index a78fe8e1..4344b6df 100644 --- a/EppoTesting/premake5.lua +++ b/EppoTesting/premake5.lua @@ -1,7 +1,7 @@ project "EppoTesting" kind "ConsoleApp" language "C++" - cppdialect "C++17" + cppdialect "C++20" staticruntime "Off" targetdir ("%{wks.location}/Bin/" .. OutputDir .. "/%{prj.name}")