diff --git a/CopiumEngine/CopiumEngine.vcxproj b/CopiumEngine/CopiumEngine.vcxproj index 0da3fe1..5c9d73d 100644 --- a/CopiumEngine/CopiumEngine.vcxproj +++ b/CopiumEngine/CopiumEngine.vcxproj @@ -41,7 +41,7 @@ Unicode - Application + StaticLibrary true v143 Unicode @@ -80,6 +80,7 @@ true $(VC_IncludePath);$(WindowsSDK_IncludePath); + $(SolutionDir)libs\$(Platform)\$(Configuration)\ false @@ -117,7 +118,7 @@ Level3 true - _DEBUG;_CONSOLE;%(PreprocessorDefinitions);GLM_FORCE_LEFT_HANDED;GLFW_INCLUDE_VULKAN;GLM_FORCE_RADIANS;GLM_FORCE_DEPTH_ZERO_TO_ONE;MSDF_ATLAS_PUBLIC=;MSDFGEN_PUBLIC= + _DEBUG;_CONSOLE;%(PreprocessorDefinitions);GLM_FORCE_LEFT_HANDED;GLFW_INCLUDE_VULKAN;GLM_FORCE_RADIANS;GLM_FORCE_DEPTH_ZERO_TO_ONE;MSDF_ATLAS_PUBLIC=;MSDFGEN_PUBLIC=;WIN32 true $(ProjectDir)ext/include/;$(ProjectDir)src/;$(SolutionDir)ext/repos/msdf-atlas-gen/;$(SolutionDir)ext/repos/msdf-atlas-gen/msdfgen/;$(SolutionDir)ext/repos/stb/;$(SolutionDir)ext/repos/glfw/include;$(ProjectDir)ext/repos/glm/;$(VULKAN_SDK)/Include;$(SolutionDir)ext/repos/imgui/;%(AdditionalIncludeDirectories) stdcpp17 @@ -174,11 +175,9 @@ - - @@ -201,7 +200,6 @@ - @@ -223,7 +221,6 @@ - @@ -251,7 +248,6 @@ - @@ -262,13 +258,6 @@ - - - - - - - @@ -290,26 +279,12 @@ - - - - - - - - - - - - - - @@ -317,7 +292,6 @@ - diff --git a/CopiumEngine/CopiumEngine.vcxproj.filters b/CopiumEngine/CopiumEngine.vcxproj.filters index e63805f..18f0ce7 100644 --- a/CopiumEngine/CopiumEngine.vcxproj.filters +++ b/CopiumEngine/CopiumEngine.vcxproj.filters @@ -15,9 +15,6 @@ - - Source Files - Source Files @@ -57,9 +54,6 @@ Source Files - - Source Files - Source Files @@ -198,9 +192,6 @@ Source Files - - Source Files - Source Files @@ -228,17 +219,11 @@ Source Files - - Source Files - Header Files - - Header Files - Header Files @@ -443,9 +428,6 @@ Header Files - - Header Files - Header Files @@ -461,92 +443,29 @@ Header Files - - Header Files - - - Header Files - - - Header Files - - - Header Files - Header Files Header Files - - Header Files - - - Header Files - - - Header Files - Header Files Header Files - - Header Files - - - Header Files - - - Header Files - Header Files - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - Header Files - - Header Files - - - Header Files - Header Files Header Files - - Header Files - - - Header Files - - - Header Files - \ No newline at end of file diff --git a/CopiumEngine/assets/character.meta b/CopiumEngine/assets/character.meta deleted file mode 100644 index a3146a0..0000000 --- a/CopiumEngine/assets/character.meta +++ /dev/null @@ -1,4 +0,0 @@ -[Texture2D] -filepath=res/textures/texture2.png -mag-filter=nearest -uuid=0964e525-22c3-4d25-d5c6-a162965f6e8d diff --git a/CopiumEngine/assets/fileicon.meta b/CopiumEngine/assets/fileicon.meta deleted file mode 100644 index 0d3de0c..0000000 --- a/CopiumEngine/assets/fileicon.meta +++ /dev/null @@ -1,4 +0,0 @@ -[Texture2D] -filepath=res/textures/FileIcon.png -mag-filter=linear -uuid=e2c32c71-e694-91a9-87dc-8162eda5b7c7 diff --git a/CopiumEngine/assets/font.meta b/CopiumEngine/assets/font.meta deleted file mode 100644 index 46c800e..0000000 --- a/CopiumEngine/assets/font.meta +++ /dev/null @@ -1,3 +0,0 @@ -[Font] -filepath=res/fonts/Roboto-Regular.ttf -uuid=3e9ef1a2-59ba-2e4d-b2cd-f5efaa531af7 \ No newline at end of file diff --git a/CopiumEngine/assets/fox.meta b/CopiumEngine/assets/fox.meta deleted file mode 100644 index 3988fda..0000000 --- a/CopiumEngine/assets/fox.meta +++ /dev/null @@ -1,4 +0,0 @@ -[Texture2D] -filepath=res/textures/texture.png -mag-filter=nearest -uuid=f49a5284-d666-0982-95ca-cf68cc3d4f45 diff --git a/CopiumEngine/assets/framebuffer.meta b/CopiumEngine/assets/framebuffer.meta deleted file mode 100644 index 4cb713f..0000000 --- a/CopiumEngine/assets/framebuffer.meta +++ /dev/null @@ -1,3 +0,0 @@ -[Framebuffer] -rendertexture-uuid=e59a549e-bb14-991c-0d95-a8e9351fa074 -uuid=91455834-b62b-354e-ee3b-50f7dbe74d28 \ No newline at end of file diff --git a/CopiumEngine/assets/pipeline.meta b/CopiumEngine/assets/pipeline.meta deleted file mode 100644 index 29400f5..0000000 --- a/CopiumEngine/assets/pipeline.meta +++ /dev/null @@ -1,6 +0,0 @@ -[Pipeline] -vert-filepath=res/shaders/shader.vert -frag-filepath=res/shaders/shader.frag -framebuffer-uuid=91455834-b62b-354e-ee3b-50f7dbe74d28 -type=Mesh -uuid=37082163-6f99-bded-1617-6220c84e3c2a \ No newline at end of file diff --git a/CopiumEngine/assets/renderer.meta b/CopiumEngine/assets/renderer.meta deleted file mode 100644 index 21e6382..0000000 --- a/CopiumEngine/assets/renderer.meta +++ /dev/null @@ -1,6 +0,0 @@ -[Pipeline] -vert-filepath=res/shaders/renderer.vert -frag-filepath=res/shaders/renderer.frag -framebuffer-uuid=91455834-b62b-354e-ee3b-50f7dbe74d28 -type=Renderer -uuid=59c56410-000b-70ca-1ae1-4568fb7856f7 \ No newline at end of file diff --git a/CopiumEngine/assets/rendertexture.meta b/CopiumEngine/assets/rendertexture.meta deleted file mode 100644 index 1c7e6b1..0000000 --- a/CopiumEngine/assets/rendertexture.meta +++ /dev/null @@ -1,2 +0,0 @@ -[RenderTexture] -uuid=e59a549e-bb14-991c-0d95-a8e9351fa074 \ No newline at end of file diff --git a/CopiumEngine/assets/stone.meta b/CopiumEngine/assets/stone.meta deleted file mode 100644 index 14e2cfe..0000000 --- a/CopiumEngine/assets/stone.meta +++ /dev/null @@ -1,4 +0,0 @@ -[Texture2D] -filepath=res/textures/stone.png -mag-filter=nearest -uuid=0c83bab1-9406-94fe-2068-6ea324dacb27 diff --git a/CopiumEngine/res/fonts/Roboto-Regular.ttf b/CopiumEngine/res/fonts/Roboto-Regular.ttf deleted file mode 100644 index 3033308..0000000 Binary files a/CopiumEngine/res/fonts/Roboto-Regular.ttf and /dev/null differ diff --git a/CopiumEngine/res/fonts/Roboto-Thin.ttf b/CopiumEngine/res/fonts/Roboto-Thin.ttf deleted file mode 100644 index 5de65ce..0000000 Binary files a/CopiumEngine/res/fonts/Roboto-Thin.ttf and /dev/null differ diff --git a/CopiumEngine/res/scenes/scene.meta b/CopiumEngine/res/scenes/scene.meta deleted file mode 100644 index 4e97510..0000000 --- a/CopiumEngine/res/scenes/scene.meta +++ /dev/null @@ -1,153 +0,0 @@ -[Name] -name=Level Generator - -[LevelGenerator] - ---- -[Name] -name=Block - -[Transform] -position=0 -8.5 -size=1 1 - -[Texture] -texture-uuid=0c83bab1-9406-94fe-2068-6ea324dacb27 -tex-coord=0.75 0 -tex-size=0.25 1 - -[StaticCollider] -resolve-collision=true - -[Renderable] - ---- -[Name] -name=Pickup - -[Transform] -position=0.1 -0.4 -size=0.8 0.8 - -[Texture] -texture-uuid=3e9ef1a2-59ba-2e4d-b2cd-f5efaa531af7 - -[StaticCollider] -resolve-collision=false - -[Pickup] -[Renderable] - ---- -[Name] -name=Mouse Follower - -[Transform] -position=0.1 0.1 -size=0.2 0.2 - -[Texture] -texture-uuid=f49a5284-d666-0982-95ca-cf68cc3d4f45 - -[MouseFollower] -[Renderable] - ---- -[Name] -name=Fps counter - -[Transform] -position=10 10 -size=0 - -[Text] -font=3e9ef1a2-59ba-2e4d-b2cd-f5efaa531af7 -text=0 fps -font-size=20 - -[FrameCounter] -[UiRenderable] - ---- -[Name] -name=Camera - -[Camera] -static-bounding-box=false -ui-camera=false - -[Transform] -position=0 0 -size=2 2 - -[Uuid] -uuid=a14e2328-ebce-5026-e5ab-495daf8c3660 - ---- -[Name] -name=Ui Camera - -[Camera] -static-bounding-box=false -ui-camera=true - -[Transform] -position=0 0 -size=1 1 - ---- -[Name] -name=Player - -[Player] -camera-uuid=a14e2328-ebce-5026-e5ab-495daf8c3660 - -[Transform] -position=0 2 -size=1 1 - -[Health] -health=10 - -[Physics] -mass=0.1 - -[Texture] -texture-uuid=0964e525-22c3-4d25-d5c6-a162965f6e8d -tex-coord=0 0 -tex-size=0.25 0.25 - -[Animation] -sheet-size=4 4 -sheet-coord=0 3 -images=4 -horizontal=true -time=0.5 - -[DynamicCollider] -resolve-collision=false -collider-offset=0.4375 0 -collider-size=0.125 0.65625 - -[Uuid] -uuid=09617c73-2b1e-0a83-db81-3ae3b5971c11 - -[Renderable] - ---- -[Name] -name=Debug Info - -[Transform] -position=10 800 -size=1 1 - -[Text] -font=3e9ef1a2-59ba-2e4d-b2cd-f5efaa531af7 -text= -font-size=20 - -[Debug] -player-uuid=09617c73-2b1e-0a83-db81-3ae3b5971c11 - -[UiRenderable] diff --git a/CopiumEngine/res/shaders/renderer.frag b/CopiumEngine/res/shaders/renderer.frag deleted file mode 100644 index dc73462..0000000 --- a/CopiumEngine/res/shaders/renderer.frag +++ /dev/null @@ -1,113 +0,0 @@ -#version 450 - -layout(set = 0, binding = 0) uniform sampler2D texSamplers[32]; - -layout(location = 0) in vec3 inColor; -layout(location = 1) in vec2 inTexCoord; -layout(location = 2) in flat int inTexIndex; -layout(location = 3) in flat int inType; - -layout(location = 0) out vec4 outColor; - -vec2 GetTextureSize() -{ - if(inTexIndex == 0) return textureSize(texSamplers[0], 0); - if(inTexIndex == 1) return textureSize(texSamplers[1], 0); - if(inTexIndex == 2) return textureSize(texSamplers[2], 0); - if(inTexIndex == 3) return textureSize(texSamplers[3], 0); - if(inTexIndex == 4) return textureSize(texSamplers[4], 0); - if(inTexIndex == 5) return textureSize(texSamplers[5], 0); - if(inTexIndex == 6) return textureSize(texSamplers[6], 0); - if(inTexIndex == 7) return textureSize(texSamplers[7], 0); - if(inTexIndex == 8) return textureSize(texSamplers[8], 0); - if(inTexIndex == 9) return textureSize(texSamplers[9], 0); - if(inTexIndex == 10) return textureSize(texSamplers[10], 0); - if(inTexIndex == 11) return textureSize(texSamplers[11], 0); - if(inTexIndex == 12) return textureSize(texSamplers[12], 0); - if(inTexIndex == 13) return textureSize(texSamplers[13], 0); - if(inTexIndex == 14) return textureSize(texSamplers[14], 0); - if(inTexIndex == 15) return textureSize(texSamplers[15], 0); - if(inTexIndex == 16) return textureSize(texSamplers[16], 0); - if(inTexIndex == 17) return textureSize(texSamplers[17], 0); - if(inTexIndex == 18) return textureSize(texSamplers[18], 0); - if(inTexIndex == 19) return textureSize(texSamplers[19], 0); - if(inTexIndex == 20) return textureSize(texSamplers[20], 0); - if(inTexIndex == 21) return textureSize(texSamplers[21], 0); - if(inTexIndex == 22) return textureSize(texSamplers[22], 0); - if(inTexIndex == 23) return textureSize(texSamplers[23], 0); - if(inTexIndex == 24) return textureSize(texSamplers[24], 0); - if(inTexIndex == 25) return textureSize(texSamplers[25], 0); - if(inTexIndex == 26) return textureSize(texSamplers[26], 0); - if(inTexIndex == 27) return textureSize(texSamplers[27], 0); - if(inTexIndex == 28) return textureSize(texSamplers[28], 0); - if(inTexIndex == 29) return textureSize(texSamplers[29], 0); - if(inTexIndex == 30) return textureSize(texSamplers[30], 0); - if(inTexIndex == 31) return textureSize(texSamplers[31], 0); - return vec2(0); -} - -vec4 TextureColor() -{ - if(inTexIndex == 0) return texture(texSamplers[0], inTexCoord); - if(inTexIndex == 1) return texture(texSamplers[1], inTexCoord); - if(inTexIndex == 2) return texture(texSamplers[2], inTexCoord); - if(inTexIndex == 3) return texture(texSamplers[3], inTexCoord); - if(inTexIndex == 4) return texture(texSamplers[4], inTexCoord); - if(inTexIndex == 5) return texture(texSamplers[5], inTexCoord); - if(inTexIndex == 6) return texture(texSamplers[6], inTexCoord); - if(inTexIndex == 7) return texture(texSamplers[7], inTexCoord); - if(inTexIndex == 8) return texture(texSamplers[8], inTexCoord); - if(inTexIndex == 9) return texture(texSamplers[9], inTexCoord); - if(inTexIndex == 10) return texture(texSamplers[10], inTexCoord); - if(inTexIndex == 11) return texture(texSamplers[11], inTexCoord); - if(inTexIndex == 12) return texture(texSamplers[12], inTexCoord); - if(inTexIndex == 13) return texture(texSamplers[13], inTexCoord); - if(inTexIndex == 14) return texture(texSamplers[14], inTexCoord); - if(inTexIndex == 15) return texture(texSamplers[15], inTexCoord); - if(inTexIndex == 16) return texture(texSamplers[16], inTexCoord); - if(inTexIndex == 17) return texture(texSamplers[17], inTexCoord); - if(inTexIndex == 18) return texture(texSamplers[18], inTexCoord); - if(inTexIndex == 19) return texture(texSamplers[19], inTexCoord); - if(inTexIndex == 20) return texture(texSamplers[20], inTexCoord); - if(inTexIndex == 21) return texture(texSamplers[21], inTexCoord); - if(inTexIndex == 22) return texture(texSamplers[22], inTexCoord); - if(inTexIndex == 23) return texture(texSamplers[23], inTexCoord); - if(inTexIndex == 24) return texture(texSamplers[24], inTexCoord); - if(inTexIndex == 25) return texture(texSamplers[25], inTexCoord); - if(inTexIndex == 26) return texture(texSamplers[26], inTexCoord); - if(inTexIndex == 27) return texture(texSamplers[27], inTexCoord); - if(inTexIndex == 28) return texture(texSamplers[28], inTexCoord); - if(inTexIndex == 29) return texture(texSamplers[29], inTexCoord); - if(inTexIndex == 30) return texture(texSamplers[30], inTexCoord); - if(inTexIndex == 31) return texture(texSamplers[31], inTexCoord); - return vec4(1, 1, 1, 1); -} - -float median(float r, float g, float b) -{ - return max(min(r, g), min(max(r, g), b)); -} - -float screenPxRange() -{ - float pxRange = 2.0f; - vec2 unitRange = vec2(pxRange) / vec2(GetTextureSize()); - vec2 screenTexSize = vec2(1.0f) / fwidth(inTexCoord); - return max(0.5 * dot(unitRange, screenTexSize), 1.0); -} - -void main() -{ - if(inType == 1) - { - vec3 msd = TextureColor().rgb; - float sd = median(msd.r, msd.g, msd.b); - float screenPxDistance = screenPxRange() * (sd - 0.5); - float opacity = clamp(screenPxDistance + 0.5, 0.0, 1.0); - outColor = vec4(inColor, mix(0.0, 1.0, opacity)); - } - else - { - outColor = vec4(inColor, 1.0) * TextureColor(); - } -} diff --git a/CopiumEngine/res/shaders/renderer.vert b/CopiumEngine/res/shaders/renderer.vert deleted file mode 100644 index e8dfb81..0000000 --- a/CopiumEngine/res/shaders/renderer.vert +++ /dev/null @@ -1,27 +0,0 @@ -#version 450 - -layout(location = 0) in vec2 inPosition; -layout(location = 1) in vec3 inColor; -layout(location = 2) in vec2 inTexCoord; -layout(location = 3) in int inTexIndex; -layout(location = 4) in int inType; - -layout(location = 0) out vec3 fragColor; -layout(location = 1) out vec2 fragTexCoord; -layout(location = 2) out int fragTexIndex; -layout(location = 3) out int fragType; - -layout(set = 1, binding = 0) uniform SceneUniformBufferObject -{ - mat4 projection; - mat4 view; -} ubo; - -void main() -{ - gl_Position = ubo.projection * ubo.view * vec4(inPosition, 0.0, 1.0); - fragColor = inColor; - fragTexCoord = inTexCoord; - fragTexIndex = inTexIndex; - fragType = inType; -} diff --git a/CopiumEngine/res/shaders/shader.frag b/CopiumEngine/res/shaders/shader.frag deleted file mode 100644 index 31bf261..0000000 --- a/CopiumEngine/res/shaders/shader.frag +++ /dev/null @@ -1,16 +0,0 @@ -#version 450 - -layout(set = 0, binding = 1) uniform sampler2D texSampler; - -layout(location = 0) in vec3 inColor; -layout(location = 1) in vec2 inTexCoord; -layout(location = 2) in vec3 inPosition; -layout(location = 3) in vec3 inLightPos; - -layout(location = 0) out vec4 outColor; - -void main() -{ - float scale = 0.45 + max(dot(vec3(0, 1, 0), normalize(inLightPos - inPosition)), 0.0); - outColor = vec4(inColor * texture(texSampler, inTexCoord).rgb * scale, 1.0); -} diff --git a/CopiumEngine/res/shaders/shader.vert b/CopiumEngine/res/shaders/shader.vert deleted file mode 100644 index 02db8af..0000000 --- a/CopiumEngine/res/shaders/shader.vert +++ /dev/null @@ -1,27 +0,0 @@ -#version 450 - -layout(set = 0, binding = 0) uniform SceneUniformBufferObject -{ - mat4 projection; - mat4 view; - mat4 model; - vec3 lightPos; -} ubo; - -layout(location = 0) in vec3 inPosition; -layout(location = 1) in vec3 inColor; -layout(location = 2) in vec2 inTexCoord; - -layout(location = 0) out vec3 outColor; -layout(location = 1) out vec2 outTexCoord; -layout(location = 2) out vec3 outPosition; -layout(location = 3) out vec3 outLightPos; - -void main() -{ - gl_Position = ubo.projection * ubo.view * ubo.model * vec4(inPosition, 1.0); - outColor = inColor; - outTexCoord = inTexCoord; - outPosition = vec3(ubo.model * vec4(inPosition, 1.0)); - outLightPos = ubo.lightPos; -} \ No newline at end of file diff --git a/CopiumEngine/res/textures/FileIcon.png b/CopiumEngine/res/textures/FileIcon.png deleted file mode 100644 index fa3ae22..0000000 Binary files a/CopiumEngine/res/textures/FileIcon.png and /dev/null differ diff --git a/CopiumEngine/res/textures/stone.png b/CopiumEngine/res/textures/stone.png deleted file mode 100644 index 01634fe..0000000 Binary files a/CopiumEngine/res/textures/stone.png and /dev/null differ diff --git a/CopiumEngine/res/textures/texture.png b/CopiumEngine/res/textures/texture.png deleted file mode 100644 index 8d45e99..0000000 Binary files a/CopiumEngine/res/textures/texture.png and /dev/null differ diff --git a/CopiumEngine/res/textures/texture2.aseprite b/CopiumEngine/res/textures/texture2.aseprite deleted file mode 100644 index 28b457b..0000000 Binary files a/CopiumEngine/res/textures/texture2.aseprite and /dev/null differ diff --git a/CopiumEngine/res/textures/texture2.png b/CopiumEngine/res/textures/texture2.png deleted file mode 100644 index 7fd652a..0000000 Binary files a/CopiumEngine/res/textures/texture2.png and /dev/null differ diff --git a/CopiumEngine/src/copium/core/Application.cpp b/CopiumEngine/src/copium/core/Application.cpp deleted file mode 100644 index 68d7cd4..0000000 --- a/CopiumEngine/src/copium/core/Application.cpp +++ /dev/null @@ -1,229 +0,0 @@ -#include "copium/core/Application.h" - -#include "copium/asset/AssetManager.h" -#include "copium/core/Vulkan.h" -#include "copium/event/EventDispatcher.h" -#include "copium/event/Input.h" -#include "copium/event/KeyPressEvent.h" -#include "copium/event/MouseMoveEvent.h" -#include "copium/event/MousePressEvent.h" -#include "copium/event/MouseScrollEvent.h" -#include "copium/event/ViewportResize.h" -#include "copium/event/WindowFocusEvent.h" -#include "copium/mesh/Vertex.h" -#include "copium/sampler/Font.h" - -#include - -#include - -namespace Copium -{ - const std::vector vertices = { - Vertex{{-0.5f, 0.5f, -0.5f}, {1.0f, 0.0f, 0.0f}, {0.0f, 0.0f}}, - Vertex{{-0.5f, 0.5f, 0.5f}, {1.0f, 1.0f, 1.0f}, {0.0f, 1.0f}}, - Vertex{{ 0.5f, 0.5f, 0.5f}, {0.0f, 0.0f, 1.0f}, {1.0f, 1.0f}}, - Vertex{{ 0.5f, 0.5f, -0.5f}, {0.0f, 1.0f, 0.0f}, {1.0f, 0.0f}}, - Vertex{{-0.5f, 0.0f, -0.5f}, {1.0f, 0.0f, 0.0f}, {0.0f, 0.0f}}, - Vertex{{-0.5f, 0.0f, 0.5f}, {1.0f, 1.0f, 1.0f}, {0.0f, 1.0f}}, - Vertex{{ 0.5f, 0.0f, 0.5f}, {0.0f, 0.0f, 1.0f}, {1.0f, 1.0f}}, - Vertex{{ 0.5f, 0.0f, -0.5f}, {0.0f, 1.0f, 0.0f}, {1.0f, 0.0f}}, - }; - - const std::vector indices = { - 0, 1, 2, 2, 3, 0, - 4, 5, 6, 6, 7, 4 - }; - - Application::Application() - { - EventDispatcher::AddEventHandler(this); - InitializeFrameBuffer(); - InitializeGraphicsPipeline(); - InitializeTextureSampler(); - InitializeDescriptorSets(); - InitializeMesh(); - InitializeCommandBuffer(); - InitializeScene(); - } - - Application::~Application() - { - vkDeviceWaitIdle(Vulkan::GetDevice()); - AssetManager::UnloadAsset(texture2D); - AssetManager::UnloadAsset(graphicsPipeline); - AssetManager::UnloadAsset(framebuffer); - EventDispatcher::RemoveEventHandler(this); - } - - bool Application::Update() - { - static Copium::Timer timer; - - if (!Vulkan::GetSwapChain().BeginPresent()) - return true; - - RecordCommandBuffer(); - - Vulkan::GetSwapChain().SubmitToGraphicsQueue(*commandBuffer); - - Vulkan::GetSwapChain().EndPresent(); - return !Vulkan::GetWindow().ShouldClose(); - } - - EventResult Application::OnEvent(const Event& event) - { - scene->OnEvent(event); - switch (event.GetType()) - { - case EventType::ViewportResize: - { - const ViewportResize& viewportResizeEvent = static_cast(event); - glm::vec2 size = viewportResizeEvent.GetViewport().GetSize(); - if (size.x == 0 || size.y == 0) - return EventResult::Continue; - - AssetManager::GetAsset(framebuffer).Resize(size.x, size.y); - descriptorSetImGui->SetSampler(AssetManager::GetAsset(framebuffer).GetColorAttachment(), 0); - - return EventResult::Continue; - } - case EventType::MousePress: - { - const MousePressEvent& mousePressEvent = static_cast(event); - CP_INFO("%d", mousePressEvent.GetButton()); - - return EventResult::Focus; - } - case EventType::MouseScroll: - { - const MouseScrollEvent& mouseScrollEvent = static_cast(event); - CP_INFO("%d %d", mouseScrollEvent.GetScrollX(), mouseScrollEvent.GetScrollY()); - - return EventResult::Continue; - } - case EventType::WindowFocus: - { - const WindowFocusEvent& windowFocusEvent = static_cast(event); - CP_INFO("Window Focused: %s", windowFocusEvent.IsFocused() ? "true" : "false"); - - return EventResult::Continue; - } - } - - return EventResult::Continue; - } - - void Application::InitializeFrameBuffer() - { - framebuffer = AssetManager::LoadAsset("framebuffer.meta"); - } - - void Application::InitializeScene() - { - scene = std::make_unique(*commandBuffer, *descriptorPool); - } - - void Application::InitializeTextureSampler() - { - texture2D = AssetManager::LoadAsset("fox.meta"); - } - - void Application::InitializeDescriptorSets() - { - descriptorPool = std::make_unique(); - - descriptorSet = AssetManager::GetAsset(graphicsPipeline).CreateDescriptorSet(*descriptorPool, 0); - descriptorSet->SetSampler(AssetManager::GetAsset(texture2D), 1); - - descriptorSetImGui = Vulkan::GetImGuiInstance().CreateDescriptorSet(); - descriptorSetImGui->SetSampler(AssetManager::GetAsset(framebuffer).GetColorAttachment(), 0); - } - - void Application::InitializeGraphicsPipeline() - { - graphicsPipeline = AssetManager::LoadAsset("pipeline.meta"); - } - - void Application::InitializeMesh() - { - mesh = std::make_unique(vertices, indices); - } - - void Application::InitializeCommandBuffer() - { - commandBuffer = std::make_unique(CommandBufferType::Dynamic); - } - - void Application::RecordCommandBuffer() - { - Framebuffer& fb = AssetManager::GetAsset(framebuffer); - - // TODO: Move this logic elsewhere - Vulkan::GetImGuiInstance().Begin(); - ImGui::ShowDemoWindow(); - - ImGui::SetNextWindowPos(ImVec2{0, 0}); - ImGui::SetNextWindowSize(ImVec2{(float)Vulkan::GetWindow().GetWidth(), (float)Vulkan::GetWindow().GetHeight()}); - ImGui::Begin("Docker", nullptr, ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoBringToFrontOnFocus); - ImGui::DockSpace(ImGui::GetID("Dockspace")); - ImGui::End(); - ImGui::Begin("Viewport"); - BoundingBox viewport{ImGui::GetCursorScreenPos().x, - ImGui::GetCursorScreenPos().y + ImGui::GetContentRegionAvail().y, - ImGui::GetCursorScreenPos().x + ImGui::GetContentRegionAvail().x, - ImGui::GetCursorScreenPos().y}; - if (viewport.GetSize() != glm::vec2{fb.GetWidth(), fb.GetHeight()}) - { - OnEvent(ViewportResize(viewport)); - CP_INFO("Viewport resize"); - } - ImGui::Image(*descriptorSetImGui, ImGui::GetContentRegionAvail(), ImVec2{0, 1}, ImVec2{1, 0}); - ImGui::End(); - - commandBuffer->Begin(); - - Pipeline& pl = AssetManager::GetAsset(graphicsPipeline); - fb.Bind(*commandBuffer); - pl.Bind(*commandBuffer); - - UpdateUniformBuffer(); - - pl.SetDescriptorSet(*descriptorSet); - pl.BindDescriptorSets(*commandBuffer); - - mesh->Bind(*commandBuffer); - mesh->Render(*commandBuffer); - - // TODO: Move this logic elsewhere and only have the Rendering part here - Input::PushViewport(viewport); - scene->Update(); - Input::PopViewport(); - - fb.Unbind(*commandBuffer); - - Vulkan::GetSwapChain().BeginFrameBuffer(*commandBuffer); - - Vulkan::GetImGuiInstance().End(); - Vulkan::GetImGuiInstance().Render(*commandBuffer); - - Vulkan::GetSwapChain().EndFrameBuffer(*commandBuffer); - commandBuffer->End(); - } - - void Application::UpdateUniformBuffer() - { - static Timer startTimer; - - float time = startTimer.Elapsed(); - Framebuffer& fb = AssetManager::GetAsset(framebuffer); - float aspect = fb.GetWidth() / (float)fb.GetHeight(); - - UniformBuffer& uniformBuffer = descriptorSet->GetUniformBuffer("ubo"); - uniformBuffer.Set("projection", glm::perspective(glm::radians(45.0f), aspect, 0.1f, 10.0f)); - uniformBuffer.Set("view", glm::lookAt(glm::vec3(2.0f, 2.0f, 2.0f), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f))); - uniformBuffer.Set("model", glm::rotate(glm::mat4(1.0f), time * glm::radians(90.0f), glm::vec3(0.0f, 1.0f, 0.0f))); - uniformBuffer.Set("lightPos", (glm::vec3)(glm::rotate(glm::mat4{1.0f}, time * glm::radians(45.0f), glm::vec3(0, 1, 0)) * glm::vec4{0.3, 0.1, 0, 1})); - uniformBuffer.Update(); - } -} \ No newline at end of file diff --git a/CopiumEngine/src/copium/core/Application.h b/CopiumEngine/src/copium/core/Application.h deleted file mode 100644 index ce5dc5d..0000000 --- a/CopiumEngine/src/copium/core/Application.h +++ /dev/null @@ -1,49 +0,0 @@ -#pragma once - -#include "copium/asset/AssetMeta.h" -#include "copium/core/Scene.h" -#include "copium/buffer/Framebuffer.h" -#include "copium/event/EventHandler.h" -#include "copium/mesh/Mesh.h" -#include "copium/pipeline/DescriptorPool.h" -#include "copium/pipeline/DescriptorSet.h" -#include "copium/pipeline/Pipeline.h" -#include "copium/renderer/Renderer.h" - -namespace Copium -{ - class Application final : EventHandler - { - CP_DELETE_COPY_AND_MOVE_CTOR(Application); - private: - AssetHandle framebuffer; - AssetHandle texture2D; - AssetHandle texture2D2; - AssetHandle font; - AssetHandle graphicsPipeline; - std::unique_ptr descriptorPool; - std::unique_ptr descriptorSet; - std::unique_ptr descriptorSetImGui; - std::unique_ptr scene; - std::unique_ptr mesh; - std::unique_ptr commandBuffer; - - public: - Application(); - ~Application(); - - bool Update(); - EventResult OnEvent(const Event& event) override; - private: - void InitializeFrameBuffer(); - void InitializeScene(); - void InitializeTextureSampler(); - void InitializeDescriptorSets(); - void InitializeGraphicsPipeline(); - void InitializeMesh(); - void InitializeCommandBuffer(); - - void RecordCommandBuffer(); - void UpdateUniformBuffer(); - }; -} diff --git a/CopiumEngine/src/copium/core/Instance.cpp b/CopiumEngine/src/copium/core/Instance.cpp index 4618cd1..2d26755 100644 --- a/CopiumEngine/src/copium/core/Instance.cpp +++ b/CopiumEngine/src/copium/core/Instance.cpp @@ -7,10 +7,8 @@ namespace Copium { Instance::Instance(const std::string& applicationName) { - timer.Start(); InitializeInstance(applicationName); InitializeDebugMessenger(); - CP_INFO("Initialized Vulkan in %f seconds", timer.Elapsed()); } Instance::~Instance() diff --git a/CopiumEngine/src/copium/core/Instance.h b/CopiumEngine/src/copium/core/Instance.h index ba8bf5e..e004ef1 100644 --- a/CopiumEngine/src/copium/core/Instance.h +++ b/CopiumEngine/src/copium/core/Instance.h @@ -1,7 +1,6 @@ #pragma once #include "copium/core/DebugMessenger.h" -#include "copium/util/Timer.h" #include #include @@ -22,8 +21,6 @@ namespace Copium VkQueue presentQueue; // TODO end - Timer timer; - public: Instance(const std::string& applicationName); ~Instance(); diff --git a/CopiumEngine/src/copium/core/Scene.cpp b/CopiumEngine/src/copium/core/Scene.cpp deleted file mode 100644 index 7496164..0000000 --- a/CopiumEngine/src/copium/core/Scene.cpp +++ /dev/null @@ -1,250 +0,0 @@ -#include "copium/core/Scene.h" - -#include "copium/asset/AssetManager.h" -#include "copium/asset/AssetMeta.h" -#include "copium/asset/AssetRef.h" -#include "copium/core/Vulkan.h" -#include "copium/ecs/Entity.h" -#include "copium/ecs/System.h" -#include "copium/event/MouseMoveEvent.h" -#include "copium/example/AnimationSystem.h" -#include "copium/example/CameraFollowPlayerSystem.h" -#include "copium/example/CameraUpdateSystem.h" -#include "copium/example/ColliderSystem.h" -#include "copium/example/ComponentHandlers.h" -#include "copium/example/Components.h" -#include "copium/example/DebugSystem.h" -#include "copium/example/FrameCountSystem.h" -#include "copium/example/HealthChangeSystem.h" -#include "copium/example/HealthComponentListener.h" -#include "copium/example/HealthDisplaySystem.h" -#include "copium/example/LevelGeneratorComponentListener.h" -#include "copium/example/MouseFollowSystem.h" -#include "copium/example/PhysicsSystem.h" -#include "copium/example/PickupSystem.h" -#include "copium/example/PlayerControllerSystem.h" -#include "copium/example/RenderSystem.h" -#include "copium/example/UiRenderSystem.h" -#include "copium/event/ViewportResize.h" - -#include -#include -#include -#include -#include - -namespace Copium -{ - Scene::Scene(CommandBuffer& commandBuffer, DescriptorPool& descriptorPool) - : viewport{-1, -1, 1, 1} - { - fileIcon = AssetManager::LoadAsset("fileicon.meta"); - descriptorSetFileIcon = Vulkan::GetImGuiInstance().CreateDescriptorSet(); - descriptorSetFileIcon->SetSampler(AssetManager::GetAsset(fileIcon), 0, 0); - renderer = std::make_unique(); - uiRenderer = std::make_unique(); - descriptorSetRenderer = renderer->GetGraphicsPipeline().CreateDescriptorSet(descriptorPool, 1); - uiDescriptorSetRenderer = renderer->GetGraphicsPipeline().CreateDescriptorSet(descriptorPool, 1); - ecs = std::make_unique(); - - ecs->AddSystem(); - ecs->AddSystem(); - ecs->AddSystem(); - ecs->AddSystem(); - ecs->AddSystem(); - ecs->AddSystem(); - ecs->AddSystem(); - ecs->AddSystem(&viewMatrix, &projectionMatrix, &invPvMatrix, &uiProjectionMatrix); - ecs->AddSystem(&invPvMatrix); - ecs->AddSystem(); - ecs->AddSystem(&viewport); - ecs->AddSystem(); - ecs->AddSystem(renderer.get(), descriptorSetRenderer.get(), &commandBuffer, &viewMatrix, &projectionMatrix); // better way to store the RenderSystem data? - ecs->AddSystem(uiRenderer.get(), uiDescriptorSetRenderer.get(), &commandBuffer, &uiProjectionMatrix); - ecs->SetComponentListener(); - ecs->SetComponentListener(); - - RegisterComponentHandler(); - RegisterComponentHandler(); - RegisterComponentHandler(); - RegisterComponentHandler(); - RegisterComponentHandler(); - RegisterComponentHandler(); - RegisterComponentHandler(); - RegisterComponentHandler(&viewport); - RegisterComponentHandler(); - RegisterComponentHandler(); - RegisterComponentHandler(); - RegisterComponentHandler(); - RegisterComponentHandler(); - RegisterFlagComponentHandler("Mouse Follower"); - RegisterFlagComponentHandler("Renderable"); - RegisterFlagComponentHandler("Ui Renderable"); - RegisterFlagComponentHandler("Pickup"); - RegisterFlagComponentHandler("Level Generator"); - RegisterFlagComponentHandler("Frame Counter"); - - Deserialize("res/scenes/scene.meta"); - } - - Scene::~Scene() - { - AssetManager::UnloadAsset(fileIcon); - } - - void Scene::Update() - { - EntityViewGui(); - ComponentViewGui(); - AssetViewGui(); - ecs->UpdateSystems(); - } - - EventResult Scene::OnEvent(const Event& event) - { - switch (event.GetType()) - { - case EventType::ViewportResize: - const ViewportResize& viewportResizeEvent = static_cast(event); - viewport = viewportResizeEvent.GetViewport(); - break; - } - Input::PushViewport(viewport); - ecs->UpdateSystems(EventSignal{event}); - Input::PopViewport(); - return EventResult::Continue; - } - - void Scene::Deserialize(const std::string& file) - { - std::vector metaFiles = MetaFile::ReadList(file); - - for (auto& metaFile : metaFiles) - { - Entity entity = Entity::Create(ecs.get()); - entity.AddComponent(); - for (auto& [name, metaClass] : metaFile.GetMetaFileClasses()) - { - try - { - bool found = false; - for (auto& componentHandler : componentHandlers) - { - if (name == componentHandler->GetSerializedName()) - { - componentHandler->Deserialize(entity, metaClass); - found = true; - break; - } - } - if (!found) - CP_WARN("Unknown component: %s", name.c_str()); - } - catch (RuntimeException& exception) { CP_ERR("Invalid %s component: %s", name.c_str(), exception.GetErrorMessage().c_str()); } - } - if (!entity.HasComponent()) - entity.AddComponent(); - if (!entity.HasComponent()) - entity.AddComponent(String::Format("Entity %d", entity.GetId())); - } - } - - void Scene::EntityViewGui() - { - ImGui::Begin("Entity Tree View"); - ecs->Each([&](EntityId entityId, SerializableC& serializable) { - Entity entity{ecs.get(), entityId}; - std::string name; - if (entity.HasComponent()) - name = entity.GetComponent().name; - if (name.empty()) - name = String::Format("Entity %u", entity.GetId()); - ImGuiTreeNodeFlags flags = ImGuiTreeNodeFlags_Leaf | ImGuiTreeNodeFlags_NoTreePushOnOpen; - if (selectedEntity == entity) - flags |= ImGuiTreeNodeFlags_Selected; - ImGui::TreeNodeEx(name.c_str(), flags); - - if (ImGui::BeginDragDropSource(ImGuiDragDropFlags_None)) - { - ImGui::SetDragDropPayload("ENTITY_UUID", &entity.GetComponent().uuid, sizeof(Uuid)); - ImGui::Text(name.c_str()); - ImGui::EndDragDropSource(); - } - else if (ImGui::IsMouseReleased(0) && ImGui::IsItemHovered() && !ImGui::IsItemToggledOpen()) - selectedEntity = entity; - - if (ImGui::BeginPopupContextItem()) - { - for (auto& componentHandler : componentHandlers) - { - if (!componentHandler->IsFlagComponent() && !componentHandler->HasComponent(entity)) - { - if (ImGui::Selectable(String::Format("Add %s", componentHandler->GetName().c_str()).c_str())) - { - componentHandler->AddDefaultComponent(entity); - } - } - } - ImGui::EndPopup(); - } - }); - ImGui::End(); - } - - void Scene::ComponentViewGui() - { - ImGui::Begin("Entitiy View"); - if (selectedEntity) - { - ImGui::SeparatorText("Entity"); - ImGui::Text("Uuid: %s", selectedEntity.GetComponent().uuid.ToString().c_str()); - if (ImGui::Button("Delete Entity")) - { - selectedEntity.Destroy(); - selectedEntity.Invalidate(); - } - - ImGui::SeparatorText("Components"); - - for (auto& componentHandler : componentHandlers) - { - componentHandler->ComponentGui(selectedEntity); - } - } - ImGui::End(); - } - - void Scene::AssetViewGui() - { - ImGui::Begin("Asset View"); - std::vector assetFiles = AssetManager::GetAssetFiles(); - float width = 0; - float maxWidth = ImGui::GetWindowContentRegionMax().x; - ImGuiStyle& style = ImGui::GetStyle(); - float defaultSpacing = style.ItemSpacing.x; - style.ItemSpacing.x = 30; - float buttonWidth = 50; - float itemWidth = buttonWidth + style.ItemSpacing.x; - for (int i = 0; i < assetFiles.size(); i++) - { - std::string name = assetFiles[i].GetPath(); - size_t slash = name.find('/'); - if (slash != std::string::npos) - name = name.substr(slash + 1); - ImGui::BeginGroup(); - ImGui::Image(*descriptorSetFileIcon, ImVec2{buttonWidth, buttonWidth}, ImVec2{0, 1}, ImVec2{1, 0}); - - ImGui::PushTextWrapPos(ImGui::GetCursorPos().x + buttonWidth); - ImGui::TextWrapped(name.c_str()); - ImGui::PopTextWrapPos(); - ImGui::EndGroup(); - width += itemWidth; - if (i < assetFiles.size() - 1 && width + itemWidth >= maxWidth) - width = 0; - else - ImGui::SameLine(); - } - style.ItemSpacing.x = defaultSpacing; - ImGui::End(); - } -} \ No newline at end of file diff --git a/CopiumEngine/src/copium/core/Scene.h b/CopiumEngine/src/copium/core/Scene.h deleted file mode 100644 index dfe9d8a..0000000 --- a/CopiumEngine/src/copium/core/Scene.h +++ /dev/null @@ -1,58 +0,0 @@ -#pragma once - -#include "copium/ecs/ECSManager.h" -#include "copium/ecs/Entity.h" -#include "copium/event/Event.h" -#include "copium/event/EventResult.h" -#include "copium/example/Components.h" -#include "copium/example/ComponentHandlerBase.h" -#include "copium/example/ComponentHandler.h" -#include "copium/renderer/Renderer.h" -#include "copium/util/Uuid.h" - -#include - -namespace Copium -{ - class Scene - { - private: - std::unique_ptr renderer; - std::unique_ptr uiRenderer; - std::unique_ptr ecs; - std::unique_ptr descriptorSetRenderer; - std::unique_ptr uiDescriptorSetRenderer; - std::vector> componentHandlers; - AssetHandle fileIcon; - std::unique_ptr descriptorSetFileIcon; - glm::mat4 projectionMatrix; - glm::mat4 viewMatrix; - glm::mat4 invPvMatrix; - glm::mat4 uiProjectionMatrix; - BoundingBox viewport; - - Entity selectedEntity; - public: - Scene(CommandBuffer& commandBuffer, DescriptorPool& descriptorPool); - ~Scene(); - void Update(); - EventResult OnEvent(const Event& event); - private: - void Deserialize(const std::string& file); - void EntityViewGui(); - void ComponentViewGui(); - void AssetViewGui(); - - template - void RegisterComponentHandler(const Args&... args) - { - componentHandlers.emplace_back(std::make_unique(args...)); - } - - template - void RegisterFlagComponentHandler(const std::string& name) - { - componentHandlers.emplace_back(std::make_unique>(name, true)); - } - }; -} \ No newline at end of file diff --git a/CopiumEngine/src/copium/core/Vulkan.cpp b/CopiumEngine/src/copium/core/Vulkan.cpp index bf8229a..65b9a4e 100644 --- a/CopiumEngine/src/copium/core/Vulkan.cpp +++ b/CopiumEngine/src/copium/core/Vulkan.cpp @@ -6,6 +6,7 @@ #include "copium/sampler/Font.h" #include "copium/pipeline/Pipeline.h" #include "copium/buffer/Framebuffer.h" +#include "copium/util/Timer.h" namespace Copium { @@ -18,12 +19,16 @@ namespace Copium void Vulkan::Initialize() { + Timer timer; + timer.Start(); instance = std::make_unique("Copium Engine"); window = std::make_unique("Copium Engine", 1440, 810, WindowMode::Windowed); device = std::make_unique(); swapChain = std::make_unique(); imGuiInstance = std::make_unique(); + CP_INFO("Initialized Vulkan in %f seconds", timer.Elapsed()); + timer.Start(); AssetManager::RegisterAssetType("Texture2D"); AssetManager::RegisterAssetType("RenderTexture"); AssetManager::RegisterAssetType("Pipeline"); @@ -34,6 +39,7 @@ namespace Copium // By looking at where the executable is, since that should always be in the bin folder (it currently isn't though) AssetManager::RegisterAssetDir("assets/"); emptyTexture2D = AssetManager::RegisterRuntimeAsset("empty_texture2d", std::make_unique(std::vector{255, 0, 255, 255}, 1, 1, SamplerCreator{})); + CP_INFO("Initialized AssetManager in %f seconds", timer.Elapsed()); } void Vulkan::Destroy() diff --git a/CopiumEngine/src/copium/core/Window.cpp b/CopiumEngine/src/copium/core/Window.cpp index a22d16e..30ed5de 100644 --- a/CopiumEngine/src/copium/core/Window.cpp +++ b/CopiumEngine/src/copium/core/Window.cpp @@ -55,6 +55,14 @@ namespace Copium return window; } + void Window::GrabMouse(bool grab) + { + if (grab) + glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED); + else + glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL); + } + void Window::InitializeWindow(const std::string& windowName, int width, int height, WindowMode mode) { glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); @@ -160,8 +168,9 @@ namespace Copium { Window* window = (Window*)glfwGetWindowUserPointer(glfwWindow); glm::vec2 pos{xpos / window->width * 2.0 - 1.0, -(ypos / window->height * 2.0 - 1.0)}; + glm::vec2 oldMousePos = Input::GetMousePos(); Input::OnMouseMove(pos); - EventDispatcher::QueueEvent(MouseMoveEvent{pos}); + EventDispatcher::QueueEvent(MouseMoveEvent{pos, pos - oldMousePos}); } void Window::WindowFocusCallback(GLFWwindow* glfwWindow, int focused) diff --git a/CopiumEngine/src/copium/core/Window.h b/CopiumEngine/src/copium/core/Window.h index af90d39..29ac83c 100644 --- a/CopiumEngine/src/copium/core/Window.h +++ b/CopiumEngine/src/copium/core/Window.h @@ -37,6 +37,8 @@ namespace Copium VkSurfaceKHR GetSurface() const; GLFWwindow* GetWindow(); + void GrabMouse(bool grap); + private: void InitializeWindow(const std::string& windowName, int width, int height, WindowMode mode); void InitializeSurface(); diff --git a/CopiumEngine/src/copium/ecs/Config.h b/CopiumEngine/src/copium/ecs/Config.h index fe8b1a4..f01b752 100644 --- a/CopiumEngine/src/copium/ecs/Config.h +++ b/CopiumEngine/src/copium/ecs/Config.h @@ -1,7 +1,7 @@ #pragma once #include -#include +#include namespace Copium { diff --git a/CopiumEngine/src/copium/event/Input.cpp b/CopiumEngine/src/copium/event/Input.cpp index cfa6598..fe27f10 100644 --- a/CopiumEngine/src/copium/event/Input.cpp +++ b/CopiumEngine/src/copium/event/Input.cpp @@ -114,4 +114,133 @@ namespace Copium { mousePosViewport = mousePos; } + + std::string Input::KeyToString(int key) + { + switch (key) + { + case CP_KEY_SPACE: return "Space"; + case CP_KEY_APOSTROPHE: return "\'"; + case CP_KEY_COMMA: return ","; + case CP_KEY_MINUS: return "-"; + case CP_KEY_PERIOD: return "."; + case CP_KEY_SLASH: return "/"; + case CP_KEY_0: return "0"; + case CP_KEY_1: return "1"; + case CP_KEY_2: return "2"; + case CP_KEY_3: return "3"; + case CP_KEY_4: return "4"; + case CP_KEY_5: return "5"; + case CP_KEY_6: return "6"; + case CP_KEY_7: return "7"; + case CP_KEY_8: return "8"; + case CP_KEY_9: return "9"; + case CP_KEY_SEMICOLON: return ";"; + case CP_KEY_EQUAL: return "="; + case CP_KEY_A: return "A"; + case CP_KEY_B: return "B"; + case CP_KEY_C: return "C"; + case CP_KEY_D: return "D"; + case CP_KEY_E: return "E"; + case CP_KEY_F: return "F"; + case CP_KEY_G: return "G"; + case CP_KEY_H: return "H"; + case CP_KEY_I: return "I"; + case CP_KEY_J: return "J"; + case CP_KEY_K: return "K"; + case CP_KEY_L: return "L"; + case CP_KEY_M: return "M"; + case CP_KEY_N: return "N"; + case CP_KEY_O: return "O"; + case CP_KEY_P: return "P"; + case CP_KEY_Q: return "Q"; + case CP_KEY_R: return "R"; + case CP_KEY_S: return "S"; + case CP_KEY_T: return "T"; + case CP_KEY_U: return "U"; + case CP_KEY_V: return "V"; + case CP_KEY_W: return "W"; + case CP_KEY_X: return "X"; + case CP_KEY_Y: return "Y"; + case CP_KEY_Z: return "Z"; + case CP_KEY_LEFT_BRACKET: return "["; + case CP_KEY_BACKSLASH: return "\\"; + case CP_KEY_RIGHT_BRACKET: return "]"; + case CP_KEY_GRAVE_ACCENT: return "Grave Accent ?"; + case CP_KEY_WORLD_1: return "World 1 ?"; + case CP_KEY_WORLD_2: return "World 2 ?"; + case CP_KEY_ESCAPE: return "Escape"; + case CP_KEY_ENTER: return "Enter"; + case CP_KEY_TAB: return "Tab"; + case CP_KEY_BACKSPACE: return "Return"; + case CP_KEY_INSERT: return "Insert"; + case CP_KEY_DELETE: return "Delete"; + case CP_KEY_RIGHT: return "Right Arrow"; + case CP_KEY_LEFT: return "Left Arrow"; + case CP_KEY_DOWN: return "Down Arrow"; + case CP_KEY_UP: return "Up Arrow"; + case CP_KEY_PAGE_UP: return "Page Up"; + case CP_KEY_PAGE_DOWN: return "Page Down"; + case CP_KEY_HOME: return "Home"; + case CP_KEY_END: return "End"; + case CP_KEY_CAPS_LOCK: return "Caps Lock"; + case CP_KEY_SCROLL_LOCK: return "Scroll Lock"; + case CP_KEY_NUM_LOCK: return "Num Lock"; + case CP_KEY_PRINT_SCREEN: return "Print Screen"; + case CP_KEY_PAUSE: return "Pause"; + case CP_KEY_F1: return "F1"; + case CP_KEY_F2: return "F2"; + case CP_KEY_F3: return "F3"; + case CP_KEY_F4: return "F4"; + case CP_KEY_F5: return "F5"; + case CP_KEY_F6: return "F6"; + case CP_KEY_F7: return "F7"; + case CP_KEY_F8: return "F8"; + case CP_KEY_F9: return "F9"; + case CP_KEY_F10: return "F10"; + case CP_KEY_F11: return "F11"; + case CP_KEY_F12: return "F12"; + case CP_KEY_F13: return "F13"; + case CP_KEY_F14: return "F14"; + case CP_KEY_F15: return "F15"; + case CP_KEY_F16: return "F16"; + case CP_KEY_F17: return "F17"; + case CP_KEY_F18: return "F18"; + case CP_KEY_F19: return "F19"; + case CP_KEY_F20: return "F20"; + case CP_KEY_F21: return "F21"; + case CP_KEY_F22: return "F22"; + case CP_KEY_F23: return "F23"; + case CP_KEY_F24: return "F24"; + case CP_KEY_F25: return "F25"; + case CP_KEY_KP_0: return "Keypad 0"; + case CP_KEY_KP_1: return "Keypad 1"; + case CP_KEY_KP_2: return "Keypad 2"; + case CP_KEY_KP_3: return "Keypad 3"; + case CP_KEY_KP_4: return "Keypad 4"; + case CP_KEY_KP_5: return "Keypad 5"; + case CP_KEY_KP_6: return "Keypad 6"; + case CP_KEY_KP_7: return "Keypad 7"; + case CP_KEY_KP_8: return "Keypad 8"; + case CP_KEY_KP_9: return "Keypad 9"; + case CP_KEY_KP_DECIMAL: return "Keypad ,"; + case CP_KEY_KP_DIVIDE: return "Keypad /"; + case CP_KEY_KP_MULTIPLY: return "Keypad *"; + case CP_KEY_KP_SUBTRACT: return "Keypad -"; + case CP_KEY_KP_ADD: return "Keypad +"; + case CP_KEY_KP_ENTER: return "Keypad Enter"; + case CP_KEY_KP_EQUAL: return "Keypad ="; + case CP_KEY_LEFT_SHIFT: return "Left Shift"; + case CP_KEY_LEFT_CONTROL: return "Left Control"; + case CP_KEY_LEFT_ALT: return "Left Alt"; + case CP_KEY_LEFT_SUPER: return "Left Super"; + case CP_KEY_RIGHT_SHIFT: return "Right Shift"; + case CP_KEY_RIGHT_CONTROL: return "Right Control"; + case CP_KEY_RIGHT_ALT: return "Right Alt"; + case CP_KEY_RIGHT_SUPER: return "Right Super"; + case CP_KEY_MENU: return "Menu"; + case CP_KEY_UNBOUND: return "Unbound"; + default: return "Unknown " + std::to_string(key); + } + } } diff --git a/CopiumEngine/src/copium/event/Input.h b/CopiumEngine/src/copium/event/Input.h index 91549d7..8dad684 100644 --- a/CopiumEngine/src/copium/event/Input.h +++ b/CopiumEngine/src/copium/event/Input.h @@ -48,5 +48,7 @@ namespace Copium static void Update(); static void PushViewport(const BoundingBox& viewport); static void PopViewport(); + + static std::string KeyToString(int key); }; } diff --git a/CopiumEngine/src/copium/event/InputCode.h b/CopiumEngine/src/copium/event/InputCode.h index 142c7f1..ebbf50e 100644 --- a/CopiumEngine/src/copium/event/InputCode.h +++ b/CopiumEngine/src/copium/event/InputCode.h @@ -2,6 +2,12 @@ #include "copium/util/Enum.h" +#define CP_MOUSE_LEFT 0 +#define CP_MOUSE_RIGHT 1 +#define CP_MOUSE_MIDDLE 2 +#define CP_MOUSE_BACK 3 +#define CP_MOUSE_FORWARD 4 + #define CP_KEY_SPACE 32 #define CP_KEY_APOSTROPHE 39 #define CP_KEY_COMMA 44 @@ -122,3 +128,4 @@ #define CP_KEY_RIGHT_ALT 346 #define CP_KEY_RIGHT_SUPER 347 #define CP_KEY_MENU 348 +#define CP_KEY_UNBOUND 0xffffffff diff --git a/CopiumEngine/src/copium/event/MouseMoveEvent.cpp b/CopiumEngine/src/copium/event/MouseMoveEvent.cpp index 82c13ed..47f69d2 100644 --- a/CopiumEngine/src/copium/event/MouseMoveEvent.cpp +++ b/CopiumEngine/src/copium/event/MouseMoveEvent.cpp @@ -2,12 +2,17 @@ namespace Copium { - MouseMoveEvent::MouseMoveEvent(glm::vec2 pos) - : Event{EventType::MouseMove}, pos{pos} + MouseMoveEvent::MouseMoveEvent(glm::vec2 pos, glm::vec2 delta) + : Event{EventType::MouseMove}, pos{pos}, delta{delta} {} glm::vec2 MouseMoveEvent::GetPos() const { return pos; } + + glm::vec2 MouseMoveEvent::GetDelta() const + { + return delta; + } } \ No newline at end of file diff --git a/CopiumEngine/src/copium/event/MouseMoveEvent.h b/CopiumEngine/src/copium/event/MouseMoveEvent.h index 6fcad4b..bf75bea 100644 --- a/CopiumEngine/src/copium/event/MouseMoveEvent.h +++ b/CopiumEngine/src/copium/event/MouseMoveEvent.h @@ -10,9 +10,11 @@ namespace Copium { private: glm::vec2 pos; + glm::vec2 delta; public: - MouseMoveEvent(glm::vec2 pos); + MouseMoveEvent(glm::vec2 pos, glm::vec2 delta); glm::vec2 GetPos() const; + glm::vec2 GetDelta() const; }; } diff --git a/CopiumEngine/src/copium/example/AnimationSystem.h b/CopiumEngine/src/copium/example/AnimationSystem.h deleted file mode 100644 index 719a960..0000000 --- a/CopiumEngine/src/copium/example/AnimationSystem.h +++ /dev/null @@ -1,32 +0,0 @@ -#pragma once - -#include "copium/ecs/System.h" -#include "copium/example/Components.h" - -namespace Copium -{ - class AnimationSystem : public System - { - void RunEntity(Entity entity, AnimationC& animation, TextureC& texture) override - { - animation.timeElapsed += 1 / 165.0f; // TODO: Update to real Timestep - if (animation.timeElapsed >= animation.time) - { - animation.timeElapsed -= animation.time; - animation.frame = (animation.frame + 1) % animation.images; - } - if (animation.horizontal) { - texture.texCoord1.x = (animation.sheetCoord.x + animation.frame) / (float)animation.sheetSize.x; - texture.texCoord2.x = (animation.sheetCoord.x + animation.frame + 1) / (float)animation.sheetSize.x; - texture.texCoord1.y = (animation.sheetCoord.y) / (float)animation.sheetSize.y; - texture.texCoord2.y = (animation.sheetCoord.y + 1) / (float)animation.sheetSize.y; - } - else { - texture.texCoord1.x = (animation.sheetCoord.x) / (float)animation.sheetSize.x; - texture.texCoord2.x = (animation.sheetCoord.x + 1) / (float)animation.sheetSize.x; - texture.texCoord1.y = (animation.sheetCoord.y + animation.frame) / (float)animation.sheetSize.y; - texture.texCoord2.y = (animation.sheetCoord.y + animation.frame + 1) / (float)animation.sheetSize.y; - } - } - }; -} diff --git a/CopiumEngine/src/copium/example/CameraFollowPlayerSystem.h b/CopiumEngine/src/copium/example/CameraFollowPlayerSystem.h deleted file mode 100644 index 99d6fcf..0000000 --- a/CopiumEngine/src/copium/example/CameraFollowPlayerSystem.h +++ /dev/null @@ -1,21 +0,0 @@ -#pragma once - -#include "copium/ecs/System.h" -#include "copium/example/Components.h" - -namespace Copium -{ - class CameraFollowPlayerSystem : public System - { - public: - void RunEntity(Entity entity, PlayerC& player, TransformC& transform) override - { - if (!ValidateEntity(player.camera)) - return; - - TransformC& cameraTransform = player.camera.GetComponent(); - glm::vec2 wantedPos = transform.position + transform.size * 0.5f; - cameraTransform.position -= (cameraTransform.position - wantedPos) * 0.10f; - } - }; -} diff --git a/CopiumEngine/src/copium/example/CameraUpdateSystem.h b/CopiumEngine/src/copium/example/CameraUpdateSystem.h deleted file mode 100644 index be67869..0000000 --- a/CopiumEngine/src/copium/example/CameraUpdateSystem.h +++ /dev/null @@ -1,70 +0,0 @@ -#pragma once - -#include "copium/ecs/System.h" -#include "copium/example/Components.h" -#include "copium/event/EventSignal.h" -#include "copium/event/ViewportResize.h" - -#include - -namespace Copium -{ - class CameraUpdateSystem : public System - { - private: - glm::mat4* viewMatrix; - glm::mat4* projectionMatrix; - glm::mat4* invPvMatrix; - glm::mat4* uiProjectionMatrix; - public: - CameraUpdateSystem(glm::mat4* viewMatrix, glm::mat4* projectionMatrix, glm::mat4* invPvMatrix, glm::mat4* uiProjectionMatrix) - : viewMatrix{viewMatrix}, projectionMatrix{projectionMatrix}, invPvMatrix{invPvMatrix}, uiProjectionMatrix{uiProjectionMatrix} - {} - - void RunEntity(Entity entity, CameraC& camera, TransformC& transform) - { - if (camera.uiCamera) - { - *uiProjectionMatrix = glm::ortho(camera.projection.l, camera.projection.r, camera.projection.b, camera.projection.t); - } - else - { - *projectionMatrix = glm::ortho(camera.projection.l, camera.projection.r, camera.projection.b, camera.projection.t); - *viewMatrix = glm::translate(glm::scale(glm::mat4{1}, glm::vec3{1.0f / transform.size.x, 1.0f / transform.size.y, 1.0f}), glm::vec3{-transform.position.x, -transform.position.y, 0.0f}); - *invPvMatrix = glm::inverse((*projectionMatrix) * (*viewMatrix)); - } - } - - void RunEntity(const Signal& signal, Entity entity, CameraC& camera, TransformC& transform) override - { - if (camera.staticBoundingBox) - return; - - if (signal.GetId() != EventSignal::GetIdStatic()) - return; - - const EventSignal& eventSignal = static_cast(signal); - switch (eventSignal.GetEvent().GetType()) - { - case EventType::ViewportResize: - { - const ViewportResize& viewportResize = static_cast(eventSignal.GetEvent()); - if (camera.uiCamera) - { - camera.projection.r = viewportResize.GetViewport().GetSize().x; - camera.projection.t = viewportResize.GetViewport().GetSize().y; - camera.projection.l = 0.0f; - camera.projection.b = 0.0f; - } - else - { - float aspect = viewportResize.GetViewport().GetSize().x / viewportResize.GetViewport().GetSize().y; - camera.projection.r = aspect; - camera.projection.l = -aspect; - } - break; - } - } - } - }; -} diff --git a/CopiumEngine/src/copium/example/CollideSignal.h b/CopiumEngine/src/copium/example/CollideSignal.h deleted file mode 100644 index 37bd4c5..0000000 --- a/CopiumEngine/src/copium/example/CollideSignal.h +++ /dev/null @@ -1,48 +0,0 @@ -#pragma once - -#include "copium/ecs/Signal.h" -#include "copium/ecs/Entity.h" - -namespace Copium -{ - class CollideSignal : public Signal - { - private: - Entity first; - Entity second; - bool resolved; - int xDir; - int yDir; - public: - CollideSignal(Entity first, Entity second, bool resolved, int xDir, int yDir) - : first{first}, second{second}, resolved{resolved}, xDir{xDir}, yDir{yDir} - {} - - Entity GetFirst() const - { - return first; - } - - Entity GetSecond() const - { - return second; - } - - bool WasResolved() const - { - return resolved; - } - - int GetXDir() const - { - return xDir; - } - - int GetYDir() const - { - return yDir; - } - - CP_SIGNAL_DECLERATION_DEFINITION(); - }; -} diff --git a/CopiumEngine/src/copium/example/ColliderSystem.h b/CopiumEngine/src/copium/example/ColliderSystem.h deleted file mode 100644 index 331a217..0000000 --- a/CopiumEngine/src/copium/example/ColliderSystem.h +++ /dev/null @@ -1,110 +0,0 @@ -#pragma once - -#include "copium/ecs/System.h" -#include "copium/example/Components.h" -#include "copium/example/CollideSignal.h" - -#include - -namespace Copium -{ - class ColliderSystem : public System - { - std::queue signals; - - bool Overlap(TransformC& firstTransform, DynamicColliderC& dynamicCollider, TransformC& secondTransform) - { - glm::vec2 firstPosition1 = firstTransform.position + dynamicCollider.colliderOffset * firstTransform.size; - glm::vec2 firstPosition2 = firstTransform.position + (dynamicCollider.colliderOffset + dynamicCollider.colliderSize) * firstTransform.size; - if (firstPosition1.x >= secondTransform.position.x + secondTransform.size.x) - return false; - if (firstPosition1.y >= secondTransform.position.y + secondTransform.size.y) - return false; - if (firstPosition2.x <= secondTransform.position.x) - return false; - if (firstPosition2.y <= secondTransform.position.y) - return false; - return true; - } - - void CollideCheckDynamic(Entity firstEntity, DynamicColliderC& dynamicCollider, TransformC& firstTransform, Entity secondEntity, TransformC& secondTransform) - { - if (firstEntity.GetId() >= secondEntity.GetId()) - return; - if (!Overlap(firstTransform, dynamicCollider, secondTransform)) - return; - signals.emplace(firstEntity, secondEntity, false, 0, 0); - } - - void CollideCheckStatic(Entity firstEntity, DynamicColliderC& dynamicCollider, TransformC& firstTransform, Entity secondEntity, StaticColliderC& secondStaticCollider, TransformC& secondTransform) - { - if (!Overlap(firstTransform, dynamicCollider, secondTransform)) - return; - - int xDir = 0; - if (firstTransform.position.x != dynamicCollider.oldPosition.x) - { - TransformC transform = firstTransform; - transform.position.y = dynamicCollider.oldPosition.y; - - if (Overlap(transform, dynamicCollider, secondTransform)) - { - xDir = dynamicCollider.oldPosition.x < firstTransform.position.x ? 1 : -1; - if (secondStaticCollider.resolveCollision) - { - if (dynamicCollider.oldPosition.x < firstTransform.position.x) - firstTransform.position.x = secondTransform.position.x - firstTransform.size.x * (dynamicCollider.colliderOffset.x + dynamicCollider.colliderSize.x); - else - firstTransform.position.x = secondTransform.position.x + secondTransform.size.x - firstTransform.size.x * dynamicCollider.colliderOffset.x; - if (firstEntity.HasComponent()) - firstEntity.GetComponent().velocity.x = 0; - } - } - } - - int yDir = 0; - if (firstTransform.position.y != dynamicCollider.oldPosition.y) - { - TransformC transform = firstTransform; - transform.position.x = dynamicCollider.oldPosition.x; - - if (Overlap(transform, dynamicCollider, secondTransform)) - { - yDir = dynamicCollider.oldPosition.y < firstTransform.position.y ? 1 : -1; - if (secondStaticCollider.resolveCollision) - { - if (dynamicCollider.oldPosition.y < firstTransform.position.y) - firstTransform.position.y = secondTransform.position.y - firstTransform.size.y * (dynamicCollider.colliderOffset.y + dynamicCollider.colliderSize.y); - else - firstTransform.position.y = secondTransform.position.y + secondTransform.size.y - firstTransform.size.y * dynamicCollider.colliderOffset.y; - if (firstEntity.HasComponent()) - firstEntity.GetComponent().velocity.y = 0; - } - } - } - signals.emplace(firstEntity, secondEntity, secondStaticCollider.resolveCollision, xDir, yDir); - } - - void RunEntity(Entity entity, DynamicColliderC& dynamicCollider, TransformC& transform) override - { - manager->Each( - [&](EntityId otherEntity, DynamicColliderC& otherDynamicCollider, TransformC& otherTransform) - { - CollideCheckDynamic(entity, dynamicCollider, transform, Entity{manager, otherEntity}, otherTransform); - } - ); - manager->Each( - [&](EntityId otherEntity, StaticColliderC& otherStaticCollider, TransformC& otherTransform) - { - CollideCheckStatic(entity, dynamicCollider, transform, Entity{manager, otherEntity}, otherStaticCollider, otherTransform); - } - ); - dynamicCollider.oldPosition = transform.position; - while (!signals.empty()) - { - manager->UpdateSystems(signals.front()); - signals.pop(); - } - } - }; -} \ No newline at end of file diff --git a/CopiumEngine/src/copium/example/ComponentHandler.h b/CopiumEngine/src/copium/example/ComponentHandler.h deleted file mode 100644 index e40b9ba..0000000 --- a/CopiumEngine/src/copium/example/ComponentHandler.h +++ /dev/null @@ -1,125 +0,0 @@ -#pragma once - -#include "copium/example/ComponentHandlerBase.h" - -#include -#include - -namespace Copium -{ - template - class ComponentHandler : public ComponentHandlerBase - { - protected: - std::string name; - std::string serializedName; - bool flagComponent; - public: - ComponentHandler(const std::string& name, bool flagComponent) - : name{name}, flagComponent{flagComponent} - { - serializedName = name; - serializedName.erase(std::remove(serializedName.begin(), serializedName.end(), ' '), serializedName.end()); - } - - void Serialize(Entity entity, MetaFile& metaFile) const override - { - if(entity.HasComponent()) - metaFile.AddMetaClass(serializedName, MetaFileClass{}); - } - - void Deserialize(Entity entity, const MetaFileClass& metaClass) const override - { - entity.AddComponent(); - } - - void ComponentGui(Entity entity) const override - { - if (flagComponent) - FlagComponentGui(entity); - else - DataComponentGui(entity); - } - - const std::string& GetName() const override - { - return name; - } - - const std::string& GetSerializedName() const override - { - return serializedName; - } - - bool IsFlagComponent() const override - { - return flagComponent; - } - - void AddDefaultComponent(Entity entity) const override - { - Component component = Create(entity); - entity.AddComponent(component); - } - - bool HasComponent(Entity entity) const override - { - return entity.HasComponent(); - } - - protected: - virtual void Gui(Component& component) const {} - virtual Component Create(Entity entity) const { return Component{}; } - - void FlagComponentGui(Entity entity) const - { - bool shouldHaveComponent = entity.HasComponent(); - ImGui::Checkbox(name.c_str(), &shouldHaveComponent); - if(shouldHaveComponent == entity.HasComponent()) - return; - - if (shouldHaveComponent) - entity.AddComponent(); - else - entity.RemoveComponent(); - } - - void DataComponentGui(Entity entity) const - { - if (!entity.HasComponent()) - return; - - Component& component = entity.GetComponent(); - if (ImGui::CollapsingHeader(name.c_str(), ImGuiTreeNodeFlags_DefaultOpen)) - { - Gui(component); - if (ImGui::Button(std::string("Delete " + name).c_str())) - entity.RemoveComponent(); - ImGui::NewLine(); - } - } - - void EntityGui(const std::string& name, Entity* entity) const - { - ImGui::Text(name.c_str()); - ImGui::SameLine(); - std::string str; - if (*entity) - str = entity->GetComponent().name; - else - str = "(drag and drop an entity)"; - ImGui::BeginDisabled(); - ImGui::InputText("##EntityGui", &str); - ImGui::EndDisabled(); - if (ImGui::BeginDragDropTarget()) - { - if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("ENTITY_UUID")) - *entity = GetEntity(entity->GetManager(), *(Uuid*)payload->Data); - ImGui::EndDragDropTarget(); - } - ImGui::SameLine(); - if (ImGui::Button("x")) - entity->Invalidate(); - } - }; -} diff --git a/CopiumEngine/src/copium/example/ComponentHandlerBase.cpp b/CopiumEngine/src/copium/example/ComponentHandlerBase.cpp deleted file mode 100644 index 7e5d418..0000000 --- a/CopiumEngine/src/copium/example/ComponentHandlerBase.cpp +++ /dev/null @@ -1,50 +0,0 @@ -#include "copium/example/ComponentHandlerBase.h" - -#include "copium/example/Components.h" - -namespace Copium -{ - glm::vec2 ComponentHandlerBase::ReadVec2Opt(const MetaFileClass& metaClass, const std::string& key, glm::vec2 vec) const - { - if (!metaClass.HasValue(key)) - return vec; - - const std::string& value = metaClass.GetValue(key); - char* endPos; - vec.x = std::strtof(value.c_str(), &endPos); - vec.y = std::strtof(endPos, &endPos); - return vec; - } - - glm::ivec2 ComponentHandlerBase::ReadVec2Opt(const MetaFileClass& metaClass, const std::string& key, glm::ivec2 vec) const - { - if (!metaClass.HasValue(key)) - return vec; - - const std::string& value = metaClass.GetValue(key); - char* endPos; - vec.x = std::strtof(value.c_str(), &endPos); - vec.y = std::strtof(endPos, &endPos); - return vec; - } - - - bool ComponentHandlerBase::ReadBoolOpt(const MetaFileClass& metaClass, const std::string& key, bool vec) const - { - if (!metaClass.HasValue(key)) - return vec; - - const std::string& value = metaClass.GetValue(key); - if (value == "true") - return true; - return false; - } - - Entity ComponentHandlerBase::GetEntity(ECSManager* ecs, const Uuid& uuid) const - { - Entity entity{ecs, ecs->Find([&](EntityId entity, const UuidC& uuidArg) { return uuid == uuidArg.uuid; })}; - CP_ASSERT(entity, "Failed to find entity with Uuid=%s", uuid.ToString().c_str()); - - return entity; - } -} diff --git a/CopiumEngine/src/copium/example/ComponentHandlerBase.h b/CopiumEngine/src/copium/example/ComponentHandlerBase.h deleted file mode 100644 index 93c5f6f..0000000 --- a/CopiumEngine/src/copium/example/ComponentHandlerBase.h +++ /dev/null @@ -1,35 +0,0 @@ -#pragma once - -#include "copium/ecs/Entity.h" -#include "copium/util/MetaFile.h" -#include "copium/util/Uuid.h" - -#include - -#include - -namespace Copium -{ - class ComponentHandlerBase - { - public: - virtual void Serialize(Entity entity, MetaFile& metaFile) const = 0; - virtual void Deserialize(Entity entity, const MetaFileClass& metaClass) const = 0; - virtual void ComponentGui(Entity entity) const = 0; - virtual const std::string& GetName() const = 0; - virtual const std::string& GetSerializedName() const = 0; - virtual bool IsFlagComponent() const = 0; - virtual void AddDefaultComponent(Entity entity) const = 0; - virtual bool HasComponent(Entity entity) const = 0; - - protected: - glm::vec2 ReadVec2Opt(const MetaFileClass& metaClass, const std::string& key, glm::vec2 vec) const; - glm::ivec2 ReadVec2Opt(const MetaFileClass& metaClass, const std::string& key, glm::ivec2 vec) const; - bool ReadBoolOpt(const MetaFileClass& metaClass, const std::string& key, bool vec) const; - - // TODO: I don't like this implementation at all. - // It shouldn't be the ComponentHandlerBases responsibility to know about entities - // But for now I don't know how to solve it in a cleaner way - Entity GetEntity(ECSManager* ecs, const Uuid& uuid) const; - }; -} \ No newline at end of file diff --git a/CopiumEngine/src/copium/example/ComponentHandlers.h b/CopiumEngine/src/copium/example/ComponentHandlers.h deleted file mode 100644 index e4b2193..0000000 --- a/CopiumEngine/src/copium/example/ComponentHandlers.h +++ /dev/null @@ -1,352 +0,0 @@ -#pragma once - -#include "copium/example/ComponentHandler.h" -#include "copium/example/Components.h" - -#include - -namespace Copium -{ - class NameComponentHandler : public ComponentHandler - { - public: - NameComponentHandler() : ComponentHandler{"Name", false} {} - - void Deserialize(Entity entity, const MetaFileClass& metaClass) const override - { - NameC name; - name.name = metaClass.GetValue("name"); - entity.AddComponent(name); - } - - protected: - void Gui(NameC& name) const override - { - ImGui::InputText("Name##Name", &name.name); - } - - NameC Create(Entity entity) const override - { - return NameC{String::Format("Entity %d", entity.GetId())}; - } - }; - - class TransformComponentHandler : public ComponentHandler - { - public: - TransformComponentHandler() : ComponentHandler{"Transform", false} {} - - void Deserialize(Entity entity, const MetaFileClass& metaClass) const override - { - TransformC transform; - transform.position = ReadVec2Opt(metaClass, "position", glm::vec2{0.0f, 0.0f}); - transform.size = ReadVec2Opt(metaClass, "size", glm::vec2{1.0f, 1.0f}); - entity.AddComponent(transform); - } - - protected: - void Gui(TransformC& transform) const override - { - ImGui::DragFloat2("Position", (float*)&transform.position); - ImGui::DragFloat2("Size", (float*)&transform.size); - } - - TransformC Create(Entity entity) const override - { - return TransformC{glm::vec2{0, 0}, glm::vec2{1, 1}}; - } - }; - - class TextureComponentHandler : public ComponentHandler - { - public: - TextureComponentHandler() : ComponentHandler{"Texture", false} {} - - void Deserialize(Entity entity, const MetaFileClass& metaClass) const override - { - TextureC texture; - texture.asset = AssetRef{AssetManager::LoadAsset(Uuid{metaClass.GetValue("texture-uuid")})}; - texture.texCoord1 = ReadVec2Opt(metaClass, "tex-coord", glm::vec2{0.0f, 0.0f}); - texture.texCoord2 = texture.texCoord1 + ReadVec2Opt(metaClass, "tex-size", glm::vec2{1.0f, 1.0f} - texture.texCoord1); - entity.AddComponent(texture); - } - - protected: - void Gui(TextureC& texture) const override - { - Asset& asset = AssetManager::GetAsset(texture.asset); - ImGui::Text("Asset: %s", asset.GetName().c_str()); - ImGui::DragFloat2("Tex Coord 1", (float*)&texture.texCoord1, 0.01, 0.0f, 1.0f); - ImGui::DragFloat2("Tex Coord 2", (float*)&texture.texCoord2, 0.01, 0.0f, 1.0f); - } - - TextureC Create(Entity entity) const override - { - return TextureC{AssetRef{AssetManager::DuplicateAsset(Vulkan::GetEmptyTexture2D())}, glm::vec2{0, 0}, glm::vec2{1, 1}}; - } - }; - - class TextComponentHandler : public ComponentHandler - { - public: - TextComponentHandler() : ComponentHandler{"Text", false} {} - - void Deserialize(Entity entity, const MetaFileClass& metaClass) const override - { - char* endPtr; - TextC text; - text.font = AssetRef{AssetManager::LoadAsset(Uuid{metaClass.GetValue("font")})}; - text.text = metaClass.GetValue("text"); - text.fontSize = std::strtof(metaClass.GetValue("font-size").c_str(), &endPtr); - entity.AddComponent(text); - } - - protected: - void Gui(TextC& text) const override - { - Asset& asset = AssetManager::GetAsset(text.font); - ImGui::Text(asset.GetName().c_str()); - ImGui::InputTextMultiline("Text##Text", &text.text); - ImGui::DragFloat("Font Size", &text.fontSize); - } - - TextC Create(Entity entity) const override - { - return TextC{AssetRef{AssetManager::LoadAsset("font.meta")}, "", 20.0f}; - } - }; - - class StaticColliderComponentHandler : public ComponentHandler - { - public: - StaticColliderComponentHandler() : ComponentHandler{"Static Collider", false} {} - - void Deserialize(Entity entity, const MetaFileClass& metaClass) const override - { - StaticColliderC staticCollider; - staticCollider.resolveCollision = ReadBoolOpt(metaClass, "resolve-collision", true); - entity.AddComponent(staticCollider); - } - - protected: - void Gui(StaticColliderC& staticCollider) const override - { - ImGui::Checkbox("Resolve Collision##StaticCollider", &staticCollider.resolveCollision); - } - - StaticColliderC Create(Entity entity) const override - { - return StaticColliderC{false}; - } - }; - - class DynamicColliderComponentHandler : public ComponentHandler - { - public: - DynamicColliderComponentHandler() : ComponentHandler{"Dynamic Collider", false} {} - - void Deserialize(Entity entity, const MetaFileClass& metaClass) const override - { - DynamicColliderC dynamicCollider; - dynamicCollider.resolveCollision = ReadBoolOpt(metaClass, "resolve-collision", true); - dynamicCollider.colliderOffset = ReadVec2Opt(metaClass, "collider-offset", glm::vec2{0.0f, 0.0f}); - dynamicCollider.colliderSize = ReadVec2Opt(metaClass, "collider-size", glm::vec2{1.0f, 1.0f}); - entity.AddComponent(dynamicCollider); - } - - protected: - void Gui(DynamicColliderC& dynamicCollider) const override - { - ImGui::Checkbox("Resolve Collision##DynamicCollider", &dynamicCollider.resolveCollision); - ImGui::DragFloat2("Collider Offset", (float*)&dynamicCollider.colliderOffset, 0.01); - ImGui::DragFloat2("Collider Size", (float*)&dynamicCollider.colliderSize, 0.01); - } - - DynamicColliderC Create(Entity entity) const override - { - return DynamicColliderC{true, glm::vec2{0, 0}, glm::vec2{1, 1}}; - } - }; - - class PlayerComponentHandler : public ComponentHandler - { - public: - PlayerComponentHandler() : ComponentHandler{"Player", false} {} - - void Deserialize(Entity entity, const MetaFileClass& metaClass) const override - { - PlayerC player; - player.camera = GetEntity(entity.GetManager(), Uuid{metaClass.GetValue("camera-uuid")}); - entity.AddComponent(player); - } - - protected: - void Gui(PlayerC& player) const override - { - EntityGui("Camera", &player.camera); - } - - PlayerC Create(Entity entity) const override - { - return PlayerC{Entity{entity.GetManager()}}; - } - }; - - class CameraComponentHandler : public ComponentHandler - { - private: - BoundingBox* viewport; - public: - CameraComponentHandler(BoundingBox* viewport) : ComponentHandler{"Camera", false}, viewport{viewport} {} - - void Deserialize(Entity entity, const MetaFileClass& metaClass) const override - { - float aspect = viewport->GetSize().x / viewport->GetSize().y; - - CameraC camera; - camera.staticBoundingBox = ReadBoolOpt(metaClass, "static-bounding-box", false); - camera.uiCamera = ReadBoolOpt(metaClass, "ui-camera", false); - if (camera.uiCamera) - camera.projection = BoundingBox(0, 0, Vulkan::GetSwapChain().GetExtent().width, Vulkan::GetSwapChain().GetExtent().height); - else - camera.projection = BoundingBox(-aspect, -1.0f, aspect, 1.0f); - entity.AddComponent(camera); - } - - protected: - void Gui(CameraC& camera) const override - { - ImGui::Checkbox("Static", &camera.staticBoundingBox); - ImGui::Checkbox("Ui camera", &camera.uiCamera); // TODO: If this changes, the bounding box should be modified if it is not static - } - - CameraC Create(Entity entity) const override - { - return CameraC{BoundingBox{-1.0f, -1.0f, 1.0f, 1.0f}, false, false}; - } - }; - - class UuidComponentHandler : public ComponentHandler - { - public: - UuidComponentHandler() : ComponentHandler{"Uuid", false} {} - - void Deserialize(Entity entity, const MetaFileClass& metaClass) const override - { - UuidC uuid; - uuid.uuid = Uuid{metaClass.GetValue("uuid")}; - entity.AddComponent(uuid); - } - - protected: - void ComponentGui(Entity entity) const override {} - }; - - class HealthComponentHandler : public ComponentHandler - { - public: - HealthComponentHandler() : ComponentHandler{"Health", false} {} - - void Deserialize(Entity entity, const MetaFileClass& metaClass) const override - { - char* endPtr; - HealthC health; - health.max = std::strtol(metaClass.GetValue("health").c_str(), &endPtr, 10); - health.current = health.max; - entity.AddComponent(health); - } - - protected: - void Gui(HealthC& health) const override - { - ImGui::DragInt("Max Health", &health.max); - } - - HealthC Create(Entity entity) const override - { - return HealthC{10, 10}; - } - }; - - class PhysicsComponentHandler : public ComponentHandler - { - public: - PhysicsComponentHandler() : ComponentHandler{"Physics", false} {} - - void Deserialize(Entity entity, const MetaFileClass& metaClass) const override - { - char* endPtr; - PhysicsC physics; - physics.mass = std::strtof(metaClass.GetValue("mass").c_str(), &endPtr); - entity.AddComponent(physics); - } - - protected: - void Gui(PhysicsC& physics) const override - { - ImGui::DragFloat("Mass", &physics.mass); - } - - PhysicsC Create(Entity entity) const override - { - return PhysicsC{10.0f}; - } - }; - - class AnimationComponentHandler : public ComponentHandler - { - public: - AnimationComponentHandler() : ComponentHandler{"Animation", false} {} - - void Deserialize(Entity entity, const MetaFileClass& metaClass) const override - { - char* endPtr; - AnimationC animation; - animation.sheetCoord = ReadVec2Opt(metaClass, "sheet-coord", glm::ivec2{0, 0}); - animation.sheetSize = ReadVec2Opt(metaClass, "sheet-size", glm::ivec2{1, 1}); - animation.images = std::strtol(metaClass.GetValue("images").c_str(), &endPtr, 10); - animation.horizontal = ReadBoolOpt(metaClass, "horizontal", true); - animation.time = std::strtof(metaClass.GetValue("time").c_str(), &endPtr); - entity.AddComponent(animation); - } - - protected: - void Gui(AnimationC& animation) const override - { - ImGui::DragInt2("Sheet Size", (int*)&animation.sheetSize); - ImGui::DragInt2("Sheet Coord", (int*)&animation.sheetCoord, 1, 0, std::max(animation.sheetSize.x, animation.sheetSize.y)); - ImGui::DragInt("Images", &animation.images); - ImGui::DragFloat("Frame time", &animation.time); - ImGui::Checkbox("Horizontal", &animation.horizontal); - } - - AnimationC Create(Entity entity) const override - { - return AnimationC{glm::ivec2{0, 0}, glm::ivec2{1, 1}, 1, true, 1.0f}; - } - }; - - class DebugComponentHandler : public ComponentHandler - { - public: - DebugComponentHandler() : ComponentHandler{"Debug", false} {} - - void Deserialize(Entity entity, const MetaFileClass& metaClass) const override - { - DebugC debug; - debug.playerEntity = GetEntity(entity.GetManager(), Uuid{metaClass.GetValue("player-uuid")}); - entity.AddComponent(debug); - } - - protected: - void Gui(DebugC& debug) const override - { - EntityGui("Player", &debug.playerEntity); - } - - DebugC Create(Entity entity) const override - { - return DebugC{Entity{entity.GetManager()}}; - } - }; -} diff --git a/CopiumEngine/src/copium/example/Components.h b/CopiumEngine/src/copium/example/Components.h deleted file mode 100644 index 2e41c85..0000000 --- a/CopiumEngine/src/copium/example/Components.h +++ /dev/null @@ -1,123 +0,0 @@ -#pragma once - -#include "copium/asset/AssetRef.h" -#include "copium/ecs/Entity.h" -#include "copium/util/Uuid.h" -#include "copium/util/BoundingBox.h" - -#include - -#include - -namespace Copium -{ - struct TransformC - { - glm::vec2 position; - glm::vec2 size; - }; - - struct ColorC - { - glm::vec3 color; - }; - - struct TextureC - { - AssetRef asset; - glm::vec2 texCoord1; - glm::vec2 texCoord2; - }; - - struct TextC - { - AssetRef font; - std::string text; - float fontSize; - }; - - struct CameraC - { - BoundingBox projection; - bool staticBoundingBox; - bool uiCamera; - }; - - struct PhysicsC - { - float mass; - - glm::vec2 force{}; - glm::vec2 velocity{}; - }; - - struct PlayerC - { - Entity camera; - - bool grounded = false; - }; - - struct HealthC - { - int current; - int max; - - Entity background{}; - Entity foreground{}; - }; - - struct StaticColliderC - { - bool resolveCollision; - }; - - struct DynamicColliderC - { - bool resolveCollision; - glm::vec2 colliderOffset; - glm::vec2 colliderSize; - - glm::vec2 oldPosition{}; - }; - - - struct DebugC - { - Entity playerEntity; - }; - - struct AnimationC - { - glm::ivec2 sheetCoord; - glm::ivec2 sheetSize; - int images; - bool horizontal; - float time; - - float timeElapsed = 0.0f; - int frame = 0; - }; - - struct UuidC - { - Uuid uuid; - }; - - struct LevelGeneratorC - { - std::vector entities; - }; - - struct NameC - { - std::string name; - }; - - struct RenderableC {}; - struct UiRenderableC {}; - struct SerializableC {}; - struct PickupC {}; - struct MouseFollowC {}; - struct FrameCountC {}; -} \ No newline at end of file diff --git a/CopiumEngine/src/copium/example/DebugSystem.h b/CopiumEngine/src/copium/example/DebugSystem.h deleted file mode 100644 index 5e4381c..0000000 --- a/CopiumEngine/src/copium/example/DebugSystem.h +++ /dev/null @@ -1,43 +0,0 @@ -#pragma once - -#include "copium/ecs/System.h" -#include "copium/example/Components.h" - -#include - -namespace Copium -{ - class DebugSystem : public System - { - BoundingBox* viewport; - public: - DebugSystem(BoundingBox* viewport) - : viewport{viewport} - {} - - void RunEntity(Entity entity, DebugC& debug, TextC& text, TransformC& transform) override - { - if (!ValidateEntity(debug.playerEntity)) - return; - - const PlayerC& player = debug.playerEntity.GetComponent(); - const TransformC& playerTransform = debug.playerEntity.GetComponent(); - const PhysicsC& playerPhysics = debug.playerEntity.GetComponent(); - const glm::vec2& velocity = playerPhysics.velocity; - - text.text = ""; - text.text += String::Format("Position: (%.3f, %.3f)\n", playerTransform.position.x, playerTransform.position.y); - text.text += String::Format("Velocity: (%.3f, %.3f)\n", velocity.x, velocity.y) ; - text.text += String::Format("Grounded: %s\n", player.grounded ? "true" : "false"); - - if (debug.playerEntity.HasComponent()) - { - const HealthC& playerHealth = debug.playerEntity.GetComponent(); - text.text += String::Format("Health: %d/%d", playerHealth.current, playerHealth.max); - } - - const Font& font = AssetManager::GetAsset(text.font); - transform.position.y = viewport->GetSize().y - 10.0f - font.GetBaseHeight() * text.fontSize; - } - }; -} \ No newline at end of file diff --git a/CopiumEngine/src/copium/example/FrameCountSystem.h b/CopiumEngine/src/copium/example/FrameCountSystem.h deleted file mode 100644 index adec050..0000000 --- a/CopiumEngine/src/copium/example/FrameCountSystem.h +++ /dev/null @@ -1,34 +0,0 @@ -#pragma once - -#include "copium/ecs/System.h" -#include "copium/example/Components.h" - -namespace Copium -{ - class FrameCountSystem : public System - { - private: - Timer timer; - int frameCounter = 0; - int fps = 0; - - public: - void RunEntity(Entity entity, FrameCountC& frameCount, TextC& text) - { - text.text = std::to_string(fps) + " fps"; - } - - void Run() override - { - if (timer.Elapsed() >= 1.0) - { - fps = frameCounter; - frameCounter = 0; - timer.Start(); // Not quite accurate since the elapsed time might me 1.1, then we lose 0.1 precision - System::Run(); - } - frameCounter++; - } - }; - -} \ No newline at end of file diff --git a/CopiumEngine/src/copium/example/HealthChangeSystem.h b/CopiumEngine/src/copium/example/HealthChangeSystem.h deleted file mode 100644 index 0de9195..0000000 --- a/CopiumEngine/src/copium/example/HealthChangeSystem.h +++ /dev/null @@ -1,21 +0,0 @@ -#pragma once - -#include "copium/ecs/System.h" -#include "copium/example/Components.h" -#include "copium/event/Input.h" - -namespace Copium -{ - class HealthChangeSystem : public System - { - - void RunEntity(Entity entity, HealthC& health) override - { - if (Input::IsKeyPressed(CP_KEY_K)) - health.current++; - if (Input::IsKeyPressed(CP_KEY_J)) - health.current--; - health.current = std::clamp(health.current, 0, health.max); - } - }; -} diff --git a/CopiumEngine/src/copium/example/HealthComponentListener.h b/CopiumEngine/src/copium/example/HealthComponentListener.h deleted file mode 100644 index 229dfb1..0000000 --- a/CopiumEngine/src/copium/example/HealthComponentListener.h +++ /dev/null @@ -1,36 +0,0 @@ -#pragma once - -#include "copium/ecs/ComponentListener.h" -#include "copium/example/Components.h" -#include "copium/util/Common.h" - -namespace Copium -{ - class HealthComponentListener : public ComponentListener - { - void Added(EntityId entityId, HealthC& health) override - { - CP_ASSERT(!health.background, "Health already has background entity assigned"); - CP_ASSERT(!health.foreground, "Health already has foreground entity assigned"); - - health.background = Entity::Create(manager); - health.background.AddComponent(glm::vec2{0.0f, 0.0f}, glm::vec2{0.5f, 0.05f}); - health.background.AddComponent(glm::vec3{0.152f, 0.14f, 0.207f}); - health.background.AddComponent(); - - health.foreground = Entity::Create(manager); - health.foreground.AddComponent(glm::vec2{0.0f, 0.0f}, glm::vec2{0.5f * std::clamp(health.current, 0, health.max) / (float)health.max, 0.05f}); - health.foreground.AddComponent(glm::vec3{0.581f, 0.393f, 0.462f}); - health.foreground.AddComponent(); - } - - void Removed(EntityId entityId, HealthC& health) override - { - CP_ASSERT(health.background, "Health already removed background entity"); - CP_ASSERT(health.foreground, "Health already removed foreground entity"); - - health.background.Destroy(); - health.foreground.Destroy(); - } - }; -} diff --git a/CopiumEngine/src/copium/example/HealthDisplaySystem.h b/CopiumEngine/src/copium/example/HealthDisplaySystem.h deleted file mode 100644 index 6e566d8..0000000 --- a/CopiumEngine/src/copium/example/HealthDisplaySystem.h +++ /dev/null @@ -1,22 +0,0 @@ -#pragma once - -#include "copium/ecs/System.h" -#include "copium/example/Components.h" - - -namespace Copium -{ - class HealthDisplaySystem : public System - { - void RunEntity(Entity entity, HealthC& health, TransformC& transform) override - { - TransformC& foregroundTransform = health.foreground.GetComponent(); - foregroundTransform.size = glm::vec2{0.5f * std::clamp(health.current, 0, health.max) / (float)health.max, 0.05f}; - foregroundTransform.position = transform.position + glm::vec2{0.0f, transform.size.y * 0.73} + glm::vec2{transform.size.x * 0.5f - 0.25f, 0.0f}; - - TransformC& backgroundTransform = health.background.GetComponent(); - backgroundTransform.position = transform.position + glm::vec2{0.0f, transform.size.y * 0.73} + glm::vec2{transform.size.x * 0.5f - backgroundTransform.size.x * 0.5f, 0.0f}; - } - }; - -} \ No newline at end of file diff --git a/CopiumEngine/src/copium/example/LevelGeneratorComponentListener.h b/CopiumEngine/src/copium/example/LevelGeneratorComponentListener.h deleted file mode 100644 index 26363a5..0000000 --- a/CopiumEngine/src/copium/example/LevelGeneratorComponentListener.h +++ /dev/null @@ -1,82 +0,0 @@ -#pragma once - -#include "copium/asset/AssetManager.h" -#include "copium/ecs/ComponentListener.h" -#include "copium/example/Components.h" - -namespace Copium -{ - class LevelGeneratorComponentListener : public ComponentListener - { - void Added(EntityId entityId, LevelGeneratorC& levelGenerator) override - { - CP_ASSERT(levelGenerator.entities.empty(), "LevelGenerator has already generated the level"); - - for (int y = 0; y < 20; y++) - { - { - Entity entity = Entity::Create(manager); - entity.AddComponent(glm::vec2{-10.0f, -10.0f + y * 1.0}, glm::vec2{1.0f, 1.0f}); - if(y == 0 || y == 19) - entity.AddComponent(AssetRef{AssetManager::LoadAsset("stone.meta")}, glm::vec2{0.0f, 0.0f}, glm::vec2{0.25f, 1.0f}); - else - entity.AddComponent(AssetRef{AssetManager::LoadAsset("stone.meta")}, glm::vec2{0.75f, 0.0f}, glm::vec2{1.0f, 1.0f}); - entity.AddComponent(true); - entity.AddComponent(); - levelGenerator.entities.emplace_back(entity); - } - { - Entity entity = Entity::Create(manager); - entity.AddComponent(glm::vec2{10.0f, -10.0f + y * 1.0}, glm::vec2{1.0f, 1.0f}); - if(y == 0 || y == 19) - entity.AddComponent(AssetRef{AssetManager::LoadAsset("stone.meta")}, glm::vec2{0.5f, 0.0f}, glm::vec2{0.75f, 1.0f}); - else - entity.AddComponent(AssetRef{AssetManager::LoadAsset("stone.meta")}, glm::vec2{0.75f, 0.0f}, glm::vec2{1.0f, 1.0f}); - entity.AddComponent(true); - entity.AddComponent(); - levelGenerator.entities.emplace_back(entity); - } - } - for (int x = 1; x < 20; x++) - { - { - Entity entity = Entity::Create(manager); - entity.AddComponent(glm::vec2{-10.0f + x * 1.0, -10.0f}, glm::vec2{1.0f, 1.0f}); - entity.AddComponent(AssetRef{AssetManager::LoadAsset("stone.meta")}, glm::vec2{0.25f, 0.0f}, glm::vec2{0.5f, 1.0f}); - entity.AddComponent(true); - entity.AddComponent(); - levelGenerator.entities.emplace_back(entity); - } - { - Entity entity = Entity::Create(manager); - entity.AddComponent(glm::vec2{-10.0f + x * 1.0, 10.0f}, glm::vec2{1.0f, 1.0f}); - entity.AddComponent(AssetRef{AssetManager::LoadAsset("stone.meta")}, glm::vec2{0.25f, 0.0f}, glm::vec2{0.5f, 1.0f}); - entity.AddComponent(true); - entity.AddComponent(); - levelGenerator.entities.emplace_back(entity); - } - } - for (int y = 0; y < 10; y++) - { - for (int x = 0; x < 10; x++) - { - Entity entity = Entity::Create(manager); - entity.AddComponent(glm::vec2{-10.0f + x * 1.6f + 0.4f, -10.0f + y * 1.6 + 0.4f}, glm::vec2{0.8f, 0.8f}); - entity.AddComponent(glm::vec3{x * 0.1f, y * 0.1f, 1.0f}); - entity.AddComponent(false); - entity.AddComponent(); - entity.AddComponent(); - levelGenerator.entities.emplace_back(entity); - } - } - } - - void Removed(EntityId entityId, LevelGeneratorC& levelGenerator) override - { - for (auto& entity : levelGenerator.entities) - { - entity.Destroy(); - } - } - }; -} \ No newline at end of file diff --git a/CopiumEngine/src/copium/example/MouseFollowSystem.h b/CopiumEngine/src/copium/example/MouseFollowSystem.h deleted file mode 100644 index 7ba0f10..0000000 --- a/CopiumEngine/src/copium/example/MouseFollowSystem.h +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once - -#include "copium/ecs/System.h" -#include "copium/event/Input.h" - -#include - -namespace Copium -{ - class MouseFollowSystem : public System - { - private: - glm::mat4* invPvMatrix; - public: - MouseFollowSystem(glm::mat4* invPvMatrix) - : invPvMatrix{invPvMatrix} - {} - - void RunEntity(Entity entity, MouseFollowC& mouseFollow, TransformC& transform) - { - transform.position = (*invPvMatrix) * glm::vec4{Input::GetMousePosViewport().x, Input::GetMousePosViewport().y, 0.0f, 1.0f}; - transform.position -= transform.size * glm::vec2{0.5f}; - } - }; -} diff --git a/CopiumEngine/src/copium/example/PhysicsSystem.h b/CopiumEngine/src/copium/example/PhysicsSystem.h deleted file mode 100644 index 19dee26..0000000 --- a/CopiumEngine/src/copium/example/PhysicsSystem.h +++ /dev/null @@ -1,21 +0,0 @@ -#pragma once - -#include "copium/ecs/System.h" -#include "copium/example/Components.h" - -namespace Copium -{ - class PhysicsSystem : public System - { - public: - void RunEntity(Entity entity, PhysicsC& physics, TransformC& transform) override - { - physics.force.y -= 4; // Apply gravity - float timespan = 1 / 165.0f; // My main monitor refresh rate, should be based on the frame rate - physics.velocity += physics.force / physics.mass * timespan; - physics.velocity.x *= 0.7; // friction - transform.position += physics.velocity * timespan; - physics.force = glm::vec2{0.0f}; - } - }; -} diff --git a/CopiumEngine/src/copium/example/PickupSystem.h b/CopiumEngine/src/copium/example/PickupSystem.h deleted file mode 100644 index 91ded0f..0000000 --- a/CopiumEngine/src/copium/example/PickupSystem.h +++ /dev/null @@ -1,37 +0,0 @@ -#pragma once - -#include "copium/ecs/System.h" -#include "copium/example/Components.h" -#include "copium/example/CollideSignal.h" - -namespace Copium -{ - class PickupSystem : public SystemBase - { - void Run() override {} - - void Run(const Signal& signal) override - { - if (signal.GetId() == CollideSignal::GetIdStatic()) - { - const CollideSignal& collideSignal = static_cast(signal); - if (collideSignal.GetFirst().HasComponent()) - { - if (collideSignal.GetSecond().HasComponent()) - { - collideSignal.GetFirst().Destroy(); - } - } - else if (collideSignal.GetSecond().HasComponent()) - { - if (collideSignal.GetFirst().HasComponent() && collideSignal.GetFirst().HasComponent()) - { - collideSignal.GetSecond().Destroy(); - collideSignal.GetFirst().GetComponent().current++; - collideSignal.GetSecond().Destroy(); - } - } - } - } - }; -} diff --git a/CopiumEngine/src/copium/example/PlayerControllerSystem.h b/CopiumEngine/src/copium/example/PlayerControllerSystem.h deleted file mode 100644 index e3462e3..0000000 --- a/CopiumEngine/src/copium/example/PlayerControllerSystem.h +++ /dev/null @@ -1,73 +0,0 @@ -#pragma once - -#include "copium/ecs/System.h" -#include "copium/event/Input.h" -#include "copium/example/Components.h" -#include "copium/example/CollideSignal.h" - -namespace Copium -{ - class PlayerControllerSystem : public System - { - public: - void RunEntity(Entity entity, PlayerC& player, PhysicsC& physics, AnimationC& animation) override - { - if (physics.velocity.y != 0.0f) - player.grounded = false; - const float MAX_JUMP_TIME = 0.2; - float force = 0.0f; - if (Input::IsKeyPressed(CP_KEY_SPACE) && player.grounded) - { - physics.velocity.y = 15; - } - else if (!Input::IsKeyDown(CP_KEY_SPACE)) - { - if (physics.velocity.y > 0) - { - physics.force.y -= 12; - } - } - animation.time = 0.5; - if (Input::IsKeyDown(CP_KEY_A)) { - force -= 1.0f; - animation.sheetCoord.y = 0; - animation.time = 0.2; - } - - if (Input::IsKeyDown(CP_KEY_D)) { - force += 1.0f; - animation.sheetCoord.y = 1; - animation.time = 0.2; - } - - if (force == 0.0f && animation.sheetCoord.y == 1) - animation.sheetCoord.y = 3; - if (force == 0.0f && animation.sheetCoord.y == 0) - animation.sheetCoord.y = 2; - - float magnitude = 75.0f; - physics.force.x += force * magnitude; - - if (Input::IsKeyPressed(CP_KEY_H)) - { - if (entity.HasComponent()) - entity.RemoveComponent(); - else - entity.AddComponent(8, 10); - } - } - - void Run(const Signal& signal) override - { - if (signal.GetId() == CollideSignal::GetIdStatic()) - { - const CollideSignal& collideSignal = static_cast(signal); - if (collideSignal.GetFirst().HasComponent() && collideSignal.WasResolved()) - { - if (collideSignal.GetYDir() == -1) - collideSignal.GetFirst().GetComponent().grounded = true; - } - } - } - }; -} diff --git a/CopiumEngine/src/copium/example/RenderSystem.h b/CopiumEngine/src/copium/example/RenderSystem.h deleted file mode 100644 index 1e94bee..0000000 --- a/CopiumEngine/src/copium/example/RenderSystem.h +++ /dev/null @@ -1,78 +0,0 @@ -#pragma once - -#include "copium/ecs/System.h" -#include "copium/example/Components.h" -#include "copium/renderer/Renderer.h" -#include "copium/asset/AssetManager.h" -#include "copium/core/Vulkan.h" - -#include - -namespace Copium -{ - class RenderSystem : public System - { - private: - // Find better way to store these? - Renderer* renderer; - DescriptorSet* descriptorSet; - CommandBuffer* commandBuffer; - glm::mat4* viewMatrix; - glm::mat4* projectionMatrix; - - bool renderColliders = false; - public: - RenderSystem(Renderer* renderer, DescriptorSet* descriptorSet, CommandBuffer* commandBuffer, glm::mat4* viewMatrix, glm::mat4* projectionMatrix) - : renderer{renderer}, - descriptorSet{descriptorSet}, - commandBuffer{commandBuffer}, - viewMatrix{viewMatrix}, - projectionMatrix{projectionMatrix} - {} - - void RunEntity(Entity entity, RenderableC& renderable, TransformC& transform) override - { - if (entity.HasComponent()) - { - const TextC& text = entity.GetComponent(); - renderer->Text(text.text, transform.position, AssetManager::GetAsset(text.font), text.fontSize); - } - else if (entity.HasComponent()) - { - const ColorC& color = entity.GetComponent(); - renderer->Quad(transform.position, transform.size, color.color); - } - else if (entity.HasComponent()) - { - const TextureC& texture = entity.GetComponent(); - renderer->Quad(transform.position, transform.size, AssetManager::GetAsset(texture.asset), texture.texCoord1, texture.texCoord2); - } - } - - void RenderCollider(Entity entity, DynamicColliderC& dynamicCollider, TransformC& transform) - { - renderer->Quad(transform.position + transform.size * dynamicCollider.colliderOffset, transform.size * dynamicCollider.colliderSize, glm::vec3{0.8, 0.1, 0.1}); - } - - void Run() override - { - if (Input::IsKeyPressed(CP_KEY_K)) - renderColliders = !renderColliders; - UniformBuffer& uniformBuffer = descriptorSet->GetUniformBuffer("ubo"); - uniformBuffer.Set("projection", *projectionMatrix); - uniformBuffer.Set("view", *viewMatrix); - uniformBuffer.Update(); - - renderer->SetDescriptorSet(*descriptorSet); - renderer->Begin(*commandBuffer); - System::Run(); - if (renderColliders) - { - manager->Each([&](EntityId entityId, DynamicColliderC& dynamicCollider, TransformC& transform) { RenderCollider(Entity{manager, entityId}, dynamicCollider, transform); }); - } - - renderer->End(); - } - }; - -} diff --git a/CopiumEngine/src/copium/example/UiRenderSystem.h b/CopiumEngine/src/copium/example/UiRenderSystem.h deleted file mode 100644 index f228d9f..0000000 --- a/CopiumEngine/src/copium/example/UiRenderSystem.h +++ /dev/null @@ -1,62 +0,0 @@ -#pragma once - -#include "copium/ecs/System.h" -#include "copium/example/Components.h" -#include "copium/renderer/Renderer.h" -#include "copium/asset/AssetManager.h" -#include "copium/core/Vulkan.h" - -#include - -namespace Copium -{ - class UiRenderSystem : public System - { - private: - // Find better way to store these? - Renderer* renderer; - DescriptorSet* descriptorSet; - CommandBuffer* commandBuffer; - glm::mat4* projectionMatrix; - public: - UiRenderSystem(Renderer* renderer, DescriptorSet* descriptorSet, CommandBuffer* commandBuffer, glm::mat4* projectionMatrix) - : renderer{renderer}, - descriptorSet{descriptorSet}, - commandBuffer{commandBuffer}, - projectionMatrix{projectionMatrix} - {} - - void RunEntity(Entity entity, UiRenderableC& uiRenderable, TransformC& transform) - { - if (entity.HasComponent()) - { - const TextC& text = entity.GetComponent(); - renderer->Text(text.text, transform.position, AssetManager::GetAsset(text.font), text.fontSize); - } - else if (entity.HasComponent()) - { - const ColorC& color = entity.GetComponent(); - renderer->Quad(transform.position, transform.size, color.color); - } - else if (entity.HasComponent()) - { - const TextureC& texture = entity.GetComponent(); - renderer->Quad(transform.position, transform.size, AssetManager::GetAsset(texture.asset), texture.texCoord1, texture.texCoord2); - } - } - - void Run() override - { - UniformBuffer& uniformBuffer = descriptorSet->GetUniformBuffer("ubo"); - uniformBuffer.Set("projection", *projectionMatrix); - uniformBuffer.Set("view", glm::mat4{1.0f}); - uniformBuffer.Update(); - - renderer->SetDescriptorSet(*descriptorSet); - renderer->Begin(*commandBuffer); - System::Run(); - renderer->End(); - } - }; - -} diff --git a/CopiumEngine/src/copium/main.cpp b/CopiumEngine/src/copium/main.cpp deleted file mode 100644 index b6ab848..0000000 --- a/CopiumEngine/src/copium/main.cpp +++ /dev/null @@ -1,28 +0,0 @@ -#include "copium/core/Application.h" -#include "copium/core/Vulkan.h" -#include "copium/event/EventDispatcher.h" -#include "copium/event/Input.h" -#include "copium/util/Common.h" -#include "copium/util/Timer.h" - -#include - -int main(int argc, char** argv) -{ - CP_ASSERT(glfwInit() == GLFW_TRUE, "Failed to initialize the glfw context"); - - Copium::Vulkan::Initialize(); - { - Copium::Application application; - while (application.Update()) - { - Copium::Input::Update(); - glfwPollEvents(); - Copium::EventDispatcher::Dispatch(); - } - } - Copium::Vulkan::Destroy(); - - glfwTerminate(); - return 0; -} \ No newline at end of file diff --git a/CopiumEngine/src/copium/pipeline/DescriptorPool.h b/CopiumEngine/src/copium/pipeline/DescriptorPool.h index 281d8ab..4df4cc1 100644 --- a/CopiumEngine/src/copium/pipeline/DescriptorPool.h +++ b/CopiumEngine/src/copium/pipeline/DescriptorPool.h @@ -11,7 +11,7 @@ namespace Copium CP_DELETE_COPY_AND_MOVE_CTOR(DescriptorPool); private: VkDescriptorPool descriptorPool; - static const int DESCRIPTOR_SET_COUNT = 100; + static const int DESCRIPTOR_SET_COUNT = 1000000; public: DescriptorPool(); ~DescriptorPool(); diff --git a/CopiumEngine/src/copium/sampler/Sampler.cpp b/CopiumEngine/src/copium/sampler/Sampler.cpp index 920f379..1e454c3 100644 --- a/CopiumEngine/src/copium/sampler/Sampler.cpp +++ b/CopiumEngine/src/copium/sampler/Sampler.cpp @@ -23,9 +23,9 @@ namespace Copium createInfo.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; createInfo.magFilter = samplerCreator.magFilter; createInfo.minFilter = samplerCreator.minFilter; - createInfo.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; - createInfo.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; - createInfo.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; + createInfo.addressModeU = samplerCreator.addressMode; + createInfo.addressModeV = samplerCreator.addressMode; + createInfo.addressModeW = samplerCreator.addressMode; createInfo.anisotropyEnable = VK_TRUE; createInfo.maxAnisotropy = properties.limits.maxSamplerAnisotropy; createInfo.unnormalizedCoordinates = VK_FALSE; diff --git a/CopiumEngine/src/copium/sampler/SamplerCreator.cpp b/CopiumEngine/src/copium/sampler/SamplerCreator.cpp index a9fb7e3..7093892 100644 --- a/CopiumEngine/src/copium/sampler/SamplerCreator.cpp +++ b/CopiumEngine/src/copium/sampler/SamplerCreator.cpp @@ -13,6 +13,8 @@ namespace Copium minFilter = GetFilterFromString(metaClass.GetValue("min-filter")); if (metaClass.HasValue("mag-filter")) magFilter = GetFilterFromString(metaClass.GetValue("mag-filter")); + if (metaClass.HasValue("address-mode")) + addressMode = GetAddressModeFromString(metaClass.GetValue("address-mode")); } void SamplerCreator::SetMinFilter(VkFilter minFilter) @@ -34,4 +36,14 @@ namespace Copium else CP_ABORT("Invalid texture filtering: %s", str.c_str()); } + + VkSamplerAddressMode SamplerCreator::GetAddressModeFromString(const std::string& str) const + { + if (str == "clamp-to-edge") + return VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; + else if (str == "repeat") + return VK_SAMPLER_ADDRESS_MODE_REPEAT; + else + CP_ABORT("Invalid texture address mode: %s", str.c_str()); + } } diff --git a/CopiumEngine/src/copium/sampler/SamplerCreator.h b/CopiumEngine/src/copium/sampler/SamplerCreator.h index f735232..932e8a5 100644 --- a/CopiumEngine/src/copium/sampler/SamplerCreator.h +++ b/CopiumEngine/src/copium/sampler/SamplerCreator.h @@ -9,8 +9,9 @@ namespace Copium { friend class Sampler; private: - VkFilter minFilter = VK_FILTER_LINEAR; - VkFilter magFilter = VK_FILTER_LINEAR; + VkFilter minFilter{VK_FILTER_LINEAR}; + VkFilter magFilter{VK_FILTER_LINEAR}; + VkSamplerAddressMode addressMode{VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE}; public: SamplerCreator(); @@ -21,5 +22,6 @@ namespace Copium private: VkFilter GetFilterFromString(const std::string& str) const; + VkSamplerAddressMode GetAddressModeFromString(const std::string& str) const; }; } diff --git a/CopiumEngine/src/copium/util/MetaFile.cpp b/CopiumEngine/src/copium/util/MetaFile.cpp index 8fad1f8..319e158 100644 --- a/CopiumEngine/src/copium/util/MetaFile.cpp +++ b/CopiumEngine/src/copium/util/MetaFile.cpp @@ -123,6 +123,9 @@ namespace Copium if(trimmedLine.empty()) continue; + if (trimmedLine[0] == '/' && trimmedLine[1] == '/') + continue; + if(trimmedLine == "---") { return; diff --git a/CopiumEngine/src/copium/util/Timer.cpp b/CopiumEngine/src/copium/util/Timer.cpp index 6552ee0..74ef705 100644 --- a/CopiumEngine/src/copium/util/Timer.cpp +++ b/CopiumEngine/src/copium/util/Timer.cpp @@ -15,4 +15,14 @@ namespace Copium { return std::chrono::duration(std::chrono::high_resolution_clock::now() - startTime).count(); } + + double Timer::ElapsedRestart() + { + std::chrono::time_point newTime = std::chrono::high_resolution_clock::now(); + + double elapsedTime = std::chrono::duration(newTime - startTime).count(); + startTime = newTime; + + return elapsedTime; + } } diff --git a/CopiumEngine/src/copium/util/Timer.h b/CopiumEngine/src/copium/util/Timer.h index 0a3b4fc..181df96 100644 --- a/CopiumEngine/src/copium/util/Timer.h +++ b/CopiumEngine/src/copium/util/Timer.h @@ -13,5 +13,6 @@ namespace Copium void Start(); double Elapsed(); + double ElapsedRestart(); }; }