Cleanup project
- To prepare being able to instead create games in a different repository
This commit is contained in:
@@ -41,7 +41,7 @@
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<ConfigurationType>StaticLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
@@ -80,6 +80,7 @@
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
<IncludePath>$(VC_IncludePath);$(WindowsSDK_IncludePath);</IncludePath>
|
||||
<OutDir>$(SolutionDir)libs\$(Platform)\$(Configuration)\</OutDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
@@ -117,7 +118,7 @@
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions);GLM_FORCE_LEFT_HANDED;GLFW_INCLUDE_VULKAN;GLM_FORCE_RADIANS;GLM_FORCE_DEPTH_ZERO_TO_ONE;MSDF_ATLAS_PUBLIC=;MSDFGEN_PUBLIC=</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>_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</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<AdditionalIncludeDirectories>$(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)</AdditionalIncludeDirectories>
|
||||
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||
@@ -174,11 +175,9 @@
|
||||
<ClCompile Include="src\copium\asset\AssetManager.cpp" />
|
||||
<ClCompile Include="src\copium\asset\AssetRef.cpp" />
|
||||
<ClCompile Include="src\copium\buffer\RendererVertexBuffer.cpp" />
|
||||
<ClCompile Include="src\copium\core\Application.cpp" />
|
||||
<ClCompile Include="src\copium\buffer\Buffer.cpp" />
|
||||
<ClCompile Include="src\copium\core\Device.cpp" />
|
||||
<ClCompile Include="src\copium\core\ImGuiInstance.cpp" />
|
||||
<ClCompile Include="src\copium\core\Scene.cpp" />
|
||||
<ClCompile Include="src\copium\core\Vulkan.cpp" />
|
||||
<ClCompile Include="src\copium\core\Window.cpp" />
|
||||
<ClCompile Include="src\copium\ecs\ComponentPoolBase.cpp" />
|
||||
@@ -201,7 +200,6 @@
|
||||
<ClCompile Include="src\copium\event\ViewportResize.cpp" />
|
||||
<ClCompile Include="src\copium\event\WindowFocusEvent.cpp" />
|
||||
<ClCompile Include="src\copium\event\WindowResizeEvent.cpp" />
|
||||
<ClCompile Include="src\copium\example\ComponentHandlerBase.cpp" />
|
||||
<ClCompile Include="src\copium\mesh\Mesh.cpp" />
|
||||
<ClCompile Include="src\copium\pipeline\ShaderBinding.cpp" />
|
||||
<ClCompile Include="src\copium\renderer\Batch.cpp" />
|
||||
@@ -223,7 +221,6 @@
|
||||
<ClCompile Include="src\copium\sampler\Image.cpp" />
|
||||
<ClCompile Include="src\copium\buffer\IndexBuffer.cpp" />
|
||||
<ClCompile Include="src\copium\core\Instance.cpp" />
|
||||
<ClCompile Include="src\copium\main.cpp" />
|
||||
<ClCompile Include="src\copium\pipeline\Pipeline.cpp" />
|
||||
<ClCompile Include="src\copium\pipeline\PipelineCreator.cpp" />
|
||||
<ClCompile Include="src\copium\core\QueueFamilies.cpp" />
|
||||
@@ -251,7 +248,6 @@
|
||||
<ClInclude Include="src\copium\buffer\RendererVertexBuffer.h" />
|
||||
<ClInclude Include="src\copium\core\Device.h" />
|
||||
<ClInclude Include="src\copium\core\ImGuiInstance.h" />
|
||||
<ClInclude Include="src\copium\core\Scene.h" />
|
||||
<ClInclude Include="src\copium\core\Vulkan.h" />
|
||||
<ClInclude Include="src\copium\core\Window.h" />
|
||||
<ClInclude Include="src\copium\ecs\ComponentListener.h" />
|
||||
@@ -262,13 +258,6 @@
|
||||
<ClInclude Include="src\copium\ecs\Entity.h" />
|
||||
<ClInclude Include="src\copium\ecs\EntitySet.h" />
|
||||
<ClInclude Include="src\copium\event\ViewportResize.h" />
|
||||
<ClInclude Include="src\copium\example\AnimationSystem.h" />
|
||||
<ClInclude Include="src\copium\example\ComponentHandler.h" />
|
||||
<ClInclude Include="src\copium\example\ComponentHandlerBase.h" />
|
||||
<ClInclude Include="src\copium\example\ComponentHandlers.h" />
|
||||
<ClInclude Include="src\copium\example\DebugSystem.h" />
|
||||
<ClInclude Include="src\copium\example\LevelGeneratorComponentListener.h" />
|
||||
<ClInclude Include="src\copium\example\PickupSystem.h" />
|
||||
<ClInclude Include="src\copium\ecs\Signal.h" />
|
||||
<ClInclude Include="src\copium\ecs\System.h" />
|
||||
<ClInclude Include="src\copium\ecs\SystemBase.h" />
|
||||
@@ -290,26 +279,12 @@
|
||||
<ClInclude Include="src\copium\event\MouseScrollEvent.h" />
|
||||
<ClInclude Include="src\copium\event\WindowFocusEvent.h" />
|
||||
<ClInclude Include="src\copium\event\WindowResizeEvent.h" />
|
||||
<ClInclude Include="src\copium\example\CameraFollowPlayerSystem.h" />
|
||||
<ClInclude Include="src\copium\example\CameraUpdateSystem.h" />
|
||||
<ClInclude Include="src\copium\example\Components.h" />
|
||||
<ClInclude Include="src\copium\example\FrameCountSystem.h" />
|
||||
<ClInclude Include="src\copium\example\HealthChangeSystem.h" />
|
||||
<ClInclude Include="src\copium\example\HealthComponentListener.h" />
|
||||
<ClInclude Include="src\copium\example\HealthDisplaySystem.h" />
|
||||
<ClInclude Include="src\copium\example\PhysicsSystem.h" />
|
||||
<ClInclude Include="src\copium\example\PlayerControllerSystem.h" />
|
||||
<ClInclude Include="src\copium\example\RenderSystem.h" />
|
||||
<ClInclude Include="src\copium\example\MouseFollowSystem.h" />
|
||||
<ClInclude Include="src\copium\example\ColliderSystem.h" />
|
||||
<ClInclude Include="src\copium\example\UiRenderSystem.h" />
|
||||
<ClInclude Include="src\copium\mesh\Mesh.h" />
|
||||
<ClInclude Include="src\copium\pipeline\ShaderBinding.h" />
|
||||
<ClInclude Include="src\copium\renderer\Batch.h" />
|
||||
<ClInclude Include="src\copium\renderer\Renderer.h" />
|
||||
<ClInclude Include="src\copium\renderer\RendererVertex.h" />
|
||||
<ClInclude Include="src\copium\sampler\DepthAttachment.h" />
|
||||
<ClInclude Include="src\copium\core\Application.h" />
|
||||
<ClInclude Include="src\copium\sampler\ColorAttachment.h" />
|
||||
<ClInclude Include="src\copium\buffer\Buffer.h" />
|
||||
<ClInclude Include="src\copium\buffer\CommandBuffer.h" />
|
||||
@@ -317,7 +292,6 @@
|
||||
<ClInclude Include="src\copium\sampler\Glyph.h" />
|
||||
<ClInclude Include="src\copium\sampler\SamplerCreator.h" />
|
||||
<ClInclude Include="src\copium\util\BoundingBox.h" />
|
||||
<ClInclude Include="src\copium\example\CollideSignal.h" />
|
||||
<ClInclude Include="src\copium\util\Common.h" />
|
||||
<ClInclude Include="src\copium\core\DebugMessenger.h" />
|
||||
<ClInclude Include="src\copium\pipeline\DescriptorSet.h" />
|
||||
|
||||
@@ -15,9 +15,6 @@
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="src\copium\core\Application.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\copium\buffer\Buffer.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
@@ -57,9 +54,6 @@
|
||||
<ClCompile Include="src\copium\core\Instance.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\copium\main.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\copium\pipeline\Pipeline.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
@@ -198,9 +192,6 @@
|
||||
<ClCompile Include="src\copium\ecs\Entity.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\copium\core\Scene.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\copium\asset\AssetRef.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
@@ -228,17 +219,11 @@
|
||||
<ClCompile Include="src\copium\event\ViewportResize.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\copium\example\ComponentHandlerBase.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="src\copium\sampler\DepthAttachment.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\copium\core\Application.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\copium\sampler\ColorAttachment.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
@@ -443,9 +428,6 @@
|
||||
<ClInclude Include="src\copium\ecs\ComponentPoolBase.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\copium\core\Scene.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\copium\asset\AssetRef.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
@@ -461,92 +443,29 @@
|
||||
<ClInclude Include="src\copium\ecs\SystemOrderer.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\copium\example\FrameCountSystem.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\copium\example\Components.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\copium\example\MouseFollowSystem.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\copium\example\RenderSystem.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\copium\ecs\Signal.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\copium\event\EventSignal.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\copium\example\CameraUpdateSystem.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\copium\example\PlayerControllerSystem.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\copium\example\PhysicsSystem.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\copium\event\Input.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\copium\event\InputCode.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\copium\example\CameraFollowPlayerSystem.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\copium\example\HealthDisplaySystem.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\copium\example\HealthChangeSystem.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\copium\ecs\ComponentListener.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\copium\example\HealthComponentListener.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\copium\example\ColliderSystem.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\copium\example\CollideSignal.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\copium\example\PickupSystem.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\copium\example\DebugSystem.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\copium\example\UiRenderSystem.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\copium\sampler\SamplerCreator.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\copium\example\AnimationSystem.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\copium\example\LevelGeneratorComponentListener.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\copium\core\ImGuiInstance.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\copium\event\ViewportResize.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\copium\example\ComponentHandler.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\copium\example\ComponentHandlers.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\copium\example\ComponentHandlerBase.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -1,4 +0,0 @@
|
||||
[Texture2D]
|
||||
filepath=res/textures/texture2.png
|
||||
mag-filter=nearest
|
||||
uuid=0964e525-22c3-4d25-d5c6-a162965f6e8d
|
||||
@@ -1,4 +0,0 @@
|
||||
[Texture2D]
|
||||
filepath=res/textures/FileIcon.png
|
||||
mag-filter=linear
|
||||
uuid=e2c32c71-e694-91a9-87dc-8162eda5b7c7
|
||||
@@ -1,3 +0,0 @@
|
||||
[Font]
|
||||
filepath=res/fonts/Roboto-Regular.ttf
|
||||
uuid=3e9ef1a2-59ba-2e4d-b2cd-f5efaa531af7
|
||||
@@ -1,4 +0,0 @@
|
||||
[Texture2D]
|
||||
filepath=res/textures/texture.png
|
||||
mag-filter=nearest
|
||||
uuid=f49a5284-d666-0982-95ca-cf68cc3d4f45
|
||||
@@ -1,3 +0,0 @@
|
||||
[Framebuffer]
|
||||
rendertexture-uuid=e59a549e-bb14-991c-0d95-a8e9351fa074
|
||||
uuid=91455834-b62b-354e-ee3b-50f7dbe74d28
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -1,2 +0,0 @@
|
||||
[RenderTexture]
|
||||
uuid=e59a549e-bb14-991c-0d95-a8e9351fa074
|
||||
@@ -1,4 +0,0 @@
|
||||
[Texture2D]
|
||||
filepath=res/textures/stone.png
|
||||
mag-filter=nearest
|
||||
uuid=0c83bab1-9406-94fe-2068-6ea324dacb27
|
||||
Binary file not shown.
Binary file not shown.
@@ -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]
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 784 B |
Binary file not shown.
|
Before Width: | Height: | Size: 501 B |
Binary file not shown.
|
Before Width: | Height: | Size: 421 KiB |
Binary file not shown.
Binary file not shown.
|
Before Width: | Height: | Size: 2.3 KiB |
@@ -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 <glm/gtc/matrix_transform.hpp>
|
||||
|
||||
#include <imgui.h>
|
||||
|
||||
namespace Copium
|
||||
{
|
||||
const std::vector<Vertex> 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<uint16_t> 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<const ViewportResize&>(event);
|
||||
glm::vec2 size = viewportResizeEvent.GetViewport().GetSize();
|
||||
if (size.x == 0 || size.y == 0)
|
||||
return EventResult::Continue;
|
||||
|
||||
AssetManager::GetAsset<Framebuffer>(framebuffer).Resize(size.x, size.y);
|
||||
descriptorSetImGui->SetSampler(AssetManager::GetAsset<Framebuffer>(framebuffer).GetColorAttachment(), 0);
|
||||
|
||||
return EventResult::Continue;
|
||||
}
|
||||
case EventType::MousePress:
|
||||
{
|
||||
const MousePressEvent& mousePressEvent = static_cast<const MousePressEvent&>(event);
|
||||
CP_INFO("%d", mousePressEvent.GetButton());
|
||||
|
||||
return EventResult::Focus;
|
||||
}
|
||||
case EventType::MouseScroll:
|
||||
{
|
||||
const MouseScrollEvent& mouseScrollEvent = static_cast<const MouseScrollEvent&>(event);
|
||||
CP_INFO("%d %d", mouseScrollEvent.GetScrollX(), mouseScrollEvent.GetScrollY());
|
||||
|
||||
return EventResult::Continue;
|
||||
}
|
||||
case EventType::WindowFocus:
|
||||
{
|
||||
const WindowFocusEvent& windowFocusEvent = static_cast<const WindowFocusEvent&>(event);
|
||||
CP_INFO("Window Focused: %s", windowFocusEvent.IsFocused() ? "true" : "false");
|
||||
|
||||
return EventResult::Continue;
|
||||
}
|
||||
}
|
||||
|
||||
return EventResult::Continue;
|
||||
}
|
||||
|
||||
void Application::InitializeFrameBuffer()
|
||||
{
|
||||
framebuffer = AssetManager::LoadAsset<Framebuffer>("framebuffer.meta");
|
||||
}
|
||||
|
||||
void Application::InitializeScene()
|
||||
{
|
||||
scene = std::make_unique<Scene>(*commandBuffer, *descriptorPool);
|
||||
}
|
||||
|
||||
void Application::InitializeTextureSampler()
|
||||
{
|
||||
texture2D = AssetManager::LoadAsset<Texture2D>("fox.meta");
|
||||
}
|
||||
|
||||
void Application::InitializeDescriptorSets()
|
||||
{
|
||||
descriptorPool = std::make_unique<DescriptorPool>();
|
||||
|
||||
descriptorSet = AssetManager::GetAsset<Pipeline>(graphicsPipeline).CreateDescriptorSet(*descriptorPool, 0);
|
||||
descriptorSet->SetSampler(AssetManager::GetAsset<Texture2D>(texture2D), 1);
|
||||
|
||||
descriptorSetImGui = Vulkan::GetImGuiInstance().CreateDescriptorSet();
|
||||
descriptorSetImGui->SetSampler(AssetManager::GetAsset<Framebuffer>(framebuffer).GetColorAttachment(), 0);
|
||||
}
|
||||
|
||||
void Application::InitializeGraphicsPipeline()
|
||||
{
|
||||
graphicsPipeline = AssetManager::LoadAsset<Pipeline>("pipeline.meta");
|
||||
}
|
||||
|
||||
void Application::InitializeMesh()
|
||||
{
|
||||
mesh = std::make_unique<Mesh>(vertices, indices);
|
||||
}
|
||||
|
||||
void Application::InitializeCommandBuffer()
|
||||
{
|
||||
commandBuffer = std::make_unique<CommandBuffer>(CommandBufferType::Dynamic);
|
||||
}
|
||||
|
||||
void Application::RecordCommandBuffer()
|
||||
{
|
||||
Framebuffer& fb = AssetManager::GetAsset<Framebuffer>(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<Pipeline>(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>(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();
|
||||
}
|
||||
}
|
||||
@@ -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> descriptorPool;
|
||||
std::unique_ptr<DescriptorSet> descriptorSet;
|
||||
std::unique_ptr<DescriptorSet> descriptorSetImGui;
|
||||
std::unique_ptr<Scene> scene;
|
||||
std::unique_ptr<Mesh> mesh;
|
||||
std::unique_ptr<CommandBuffer> 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();
|
||||
};
|
||||
}
|
||||
@@ -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()
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "copium/core/DebugMessenger.h"
|
||||
#include "copium/util/Timer.h"
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <set>
|
||||
@@ -22,8 +21,6 @@ namespace Copium
|
||||
VkQueue presentQueue;
|
||||
// TODO end
|
||||
|
||||
Timer timer;
|
||||
|
||||
public:
|
||||
Instance(const std::string& applicationName);
|
||||
~Instance();
|
||||
|
||||
@@ -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 <glm/glm.hpp>
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
#include <imgui.h>
|
||||
#include <misc/cpp/imgui_stdlib.h>
|
||||
#include <string>
|
||||
|
||||
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<Texture2D>(fileIcon), 0, 0);
|
||||
renderer = std::make_unique<Renderer>();
|
||||
uiRenderer = std::make_unique<Renderer>();
|
||||
descriptorSetRenderer = renderer->GetGraphicsPipeline().CreateDescriptorSet(descriptorPool, 1);
|
||||
uiDescriptorSetRenderer = renderer->GetGraphicsPipeline().CreateDescriptorSet(descriptorPool, 1);
|
||||
ecs = std::make_unique<ECSManager>();
|
||||
|
||||
ecs->AddSystem<PlayerControllerSystem>();
|
||||
ecs->AddSystem<PhysicsSystem>();
|
||||
ecs->AddSystem<ColliderSystem>();
|
||||
ecs->AddSystem<PickupSystem>();
|
||||
ecs->AddSystem<HealthChangeSystem>();
|
||||
ecs->AddSystem<HealthDisplaySystem>();
|
||||
ecs->AddSystem<CameraFollowPlayerSystem>();
|
||||
ecs->AddSystem<CameraUpdateSystem>(&viewMatrix, &projectionMatrix, &invPvMatrix, &uiProjectionMatrix);
|
||||
ecs->AddSystem<MouseFollowSystem>(&invPvMatrix);
|
||||
ecs->AddSystem<FrameCountSystem>();
|
||||
ecs->AddSystem<DebugSystem>(&viewport);
|
||||
ecs->AddSystem<AnimationSystem>();
|
||||
ecs->AddSystem<RenderSystem>(renderer.get(), descriptorSetRenderer.get(), &commandBuffer, &viewMatrix, &projectionMatrix); // better way to store the RenderSystem data?
|
||||
ecs->AddSystem<UiRenderSystem>(uiRenderer.get(), uiDescriptorSetRenderer.get(), &commandBuffer, &uiProjectionMatrix);
|
||||
ecs->SetComponentListener<HealthComponentListener>();
|
||||
ecs->SetComponentListener<LevelGeneratorComponentListener>();
|
||||
|
||||
RegisterComponentHandler<NameComponentHandler>();
|
||||
RegisterComponentHandler<TransformComponentHandler>();
|
||||
RegisterComponentHandler<TextureComponentHandler>();
|
||||
RegisterComponentHandler<TextComponentHandler>();
|
||||
RegisterComponentHandler<StaticColliderComponentHandler>();
|
||||
RegisterComponentHandler<DynamicColliderComponentHandler>();
|
||||
RegisterComponentHandler<PlayerComponentHandler>();
|
||||
RegisterComponentHandler<CameraComponentHandler>(&viewport);
|
||||
RegisterComponentHandler<UuidComponentHandler>();
|
||||
RegisterComponentHandler<PhysicsComponentHandler>();
|
||||
RegisterComponentHandler<HealthComponentHandler>();
|
||||
RegisterComponentHandler<AnimationComponentHandler>();
|
||||
RegisterComponentHandler<DebugComponentHandler>();
|
||||
RegisterFlagComponentHandler<MouseFollowC>("Mouse Follower");
|
||||
RegisterFlagComponentHandler<RenderableC>("Renderable");
|
||||
RegisterFlagComponentHandler<UiRenderableC>("Ui Renderable");
|
||||
RegisterFlagComponentHandler<PickupC>("Pickup");
|
||||
RegisterFlagComponentHandler<LevelGeneratorC>("Level Generator");
|
||||
RegisterFlagComponentHandler<FrameCountC>("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<const ViewportResize&>(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<MetaFile> metaFiles = MetaFile::ReadList(file);
|
||||
|
||||
for (auto& metaFile : metaFiles)
|
||||
{
|
||||
Entity entity = Entity::Create(ecs.get());
|
||||
entity.AddComponent<SerializableC>();
|
||||
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<UuidC>())
|
||||
entity.AddComponent<UuidC>();
|
||||
if (!entity.HasComponent<NameC>())
|
||||
entity.AddComponent<NameC>(String::Format("Entity %d", entity.GetId()));
|
||||
}
|
||||
}
|
||||
|
||||
void Scene::EntityViewGui()
|
||||
{
|
||||
ImGui::Begin("Entity Tree View");
|
||||
ecs->Each<SerializableC>([&](EntityId entityId, SerializableC& serializable) {
|
||||
Entity entity{ecs.get(), entityId};
|
||||
std::string name;
|
||||
if (entity.HasComponent<NameC>())
|
||||
name = entity.GetComponent<NameC>().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<UuidC>().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<UuidC>().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<AssetFile> 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();
|
||||
}
|
||||
}
|
||||
@@ -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 <memory>
|
||||
|
||||
namespace Copium
|
||||
{
|
||||
class Scene
|
||||
{
|
||||
private:
|
||||
std::unique_ptr<Renderer> renderer;
|
||||
std::unique_ptr<Renderer> uiRenderer;
|
||||
std::unique_ptr<ECSManager> ecs;
|
||||
std::unique_ptr<DescriptorSet> descriptorSetRenderer;
|
||||
std::unique_ptr<DescriptorSet> uiDescriptorSetRenderer;
|
||||
std::vector<std::unique_ptr<ComponentHandlerBase>> componentHandlers;
|
||||
AssetHandle fileIcon;
|
||||
std::unique_ptr<DescriptorSet> 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 <typename ComponentHandler, typename... Args>
|
||||
void RegisterComponentHandler(const Args&... args)
|
||||
{
|
||||
componentHandlers.emplace_back(std::make_unique<ComponentHandler>(args...));
|
||||
}
|
||||
|
||||
template <typename Component>
|
||||
void RegisterFlagComponentHandler(const std::string& name)
|
||||
{
|
||||
componentHandlers.emplace_back(std::make_unique<ComponentHandler<Component>>(name, true));
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -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<Instance>("Copium Engine");
|
||||
window = std::make_unique<Window>("Copium Engine", 1440, 810, WindowMode::Windowed);
|
||||
device = std::make_unique<Device>();
|
||||
swapChain = std::make_unique<SwapChain>();
|
||||
imGuiInstance = std::make_unique<ImGuiInstance>();
|
||||
CP_INFO("Initialized Vulkan in %f seconds", timer.Elapsed());
|
||||
|
||||
timer.Start();
|
||||
AssetManager::RegisterAssetType<Texture2D>("Texture2D");
|
||||
AssetManager::RegisterAssetType<ColorAttachment>("RenderTexture");
|
||||
AssetManager::RegisterAssetType<Pipeline>("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<Texture2D>(std::vector<uint8_t>{255, 0, 255, 255}, 1, 1, SamplerCreator{}));
|
||||
CP_INFO("Initialized AssetManager in %f seconds", timer.Elapsed());
|
||||
}
|
||||
|
||||
void Vulkan::Destroy()
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <numeric>
|
||||
#include <limits>
|
||||
|
||||
namespace Copium
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,5 +48,7 @@ namespace Copium
|
||||
static void Update();
|
||||
static void PushViewport(const BoundingBox& viewport);
|
||||
static void PopViewport();
|
||||
|
||||
static std::string KeyToString(int key);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "copium/ecs/System.h"
|
||||
#include "copium/example/Components.h"
|
||||
|
||||
namespace Copium
|
||||
{
|
||||
class AnimationSystem : public System<AnimationC, TextureC>
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "copium/ecs/System.h"
|
||||
#include "copium/example/Components.h"
|
||||
|
||||
namespace Copium
|
||||
{
|
||||
class CameraFollowPlayerSystem : public System<PlayerC, TransformC>
|
||||
{
|
||||
public:
|
||||
void RunEntity(Entity entity, PlayerC& player, TransformC& transform) override
|
||||
{
|
||||
if (!ValidateEntity<TransformC>(player.camera))
|
||||
return;
|
||||
|
||||
TransformC& cameraTransform = player.camera.GetComponent<TransformC>();
|
||||
glm::vec2 wantedPos = transform.position + transform.size * 0.5f;
|
||||
cameraTransform.position -= (cameraTransform.position - wantedPos) * 0.10f;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -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 <glm/gtc/matrix_transform.hpp>
|
||||
|
||||
namespace Copium
|
||||
{
|
||||
class CameraUpdateSystem : public System<CameraC, TransformC>
|
||||
{
|
||||
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<const EventSignal&>(signal);
|
||||
switch (eventSignal.GetEvent().GetType())
|
||||
{
|
||||
case EventType::ViewportResize:
|
||||
{
|
||||
const ViewportResize& viewportResize = static_cast<const ViewportResize&>(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;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -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();
|
||||
};
|
||||
}
|
||||
@@ -1,110 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "copium/ecs/System.h"
|
||||
#include "copium/example/Components.h"
|
||||
#include "copium/example/CollideSignal.h"
|
||||
|
||||
#include <queue>
|
||||
|
||||
namespace Copium
|
||||
{
|
||||
class ColliderSystem : public System<DynamicColliderC, TransformC>
|
||||
{
|
||||
std::queue<CollideSignal> 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<PhysicsC>())
|
||||
firstEntity.GetComponent<PhysicsC>().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<PhysicsC>())
|
||||
firstEntity.GetComponent<PhysicsC>().velocity.y = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
signals.emplace(firstEntity, secondEntity, secondStaticCollider.resolveCollision, xDir, yDir);
|
||||
}
|
||||
|
||||
void RunEntity(Entity entity, DynamicColliderC& dynamicCollider, TransformC& transform) override
|
||||
{
|
||||
manager->Each<DynamicColliderC, TransformC>(
|
||||
[&](EntityId otherEntity, DynamicColliderC& otherDynamicCollider, TransformC& otherTransform)
|
||||
{
|
||||
CollideCheckDynamic(entity, dynamicCollider, transform, Entity{manager, otherEntity}, otherTransform);
|
||||
}
|
||||
);
|
||||
manager->Each<StaticColliderC, TransformC>(
|
||||
[&](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();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -1,125 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "copium/example/ComponentHandlerBase.h"
|
||||
|
||||
#include <imgui.h>
|
||||
#include <misc/cpp/imgui_stdlib.h>
|
||||
|
||||
namespace Copium
|
||||
{
|
||||
template <typename Component>
|
||||
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<Component>())
|
||||
metaFile.AddMetaClass(serializedName, MetaFileClass{});
|
||||
}
|
||||
|
||||
void Deserialize(Entity entity, const MetaFileClass& metaClass) const override
|
||||
{
|
||||
entity.AddComponent<Component>();
|
||||
}
|
||||
|
||||
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>(component);
|
||||
}
|
||||
|
||||
bool HasComponent(Entity entity) const override
|
||||
{
|
||||
return entity.HasComponent<Component>();
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void Gui(Component& component) const {}
|
||||
virtual Component Create(Entity entity) const { return Component{}; }
|
||||
|
||||
void FlagComponentGui(Entity entity) const
|
||||
{
|
||||
bool shouldHaveComponent = entity.HasComponent<Component>();
|
||||
ImGui::Checkbox(name.c_str(), &shouldHaveComponent);
|
||||
if(shouldHaveComponent == entity.HasComponent<Component>())
|
||||
return;
|
||||
|
||||
if (shouldHaveComponent)
|
||||
entity.AddComponent<Component>();
|
||||
else
|
||||
entity.RemoveComponent<Component>();
|
||||
}
|
||||
|
||||
void DataComponentGui(Entity entity) const
|
||||
{
|
||||
if (!entity.HasComponent<Component>())
|
||||
return;
|
||||
|
||||
Component& component = entity.GetComponent<Component>();
|
||||
if (ImGui::CollapsingHeader(name.c_str(), ImGuiTreeNodeFlags_DefaultOpen))
|
||||
{
|
||||
Gui(component);
|
||||
if (ImGui::Button(std::string("Delete " + name).c_str()))
|
||||
entity.RemoveComponent<Component>();
|
||||
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<NameC>().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();
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -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<UuidC>([&](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;
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "copium/ecs/Entity.h"
|
||||
#include "copium/util/MetaFile.h"
|
||||
#include "copium/util/Uuid.h"
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
#include <string>
|
||||
|
||||
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;
|
||||
};
|
||||
}
|
||||
@@ -1,352 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "copium/example/ComponentHandler.h"
|
||||
#include "copium/example/Components.h"
|
||||
|
||||
#include <misc/cpp/imgui_stdlib.h>
|
||||
|
||||
namespace Copium
|
||||
{
|
||||
class NameComponentHandler : public ComponentHandler<NameC>
|
||||
{
|
||||
public:
|
||||
NameComponentHandler() : ComponentHandler{"Name", false} {}
|
||||
|
||||
void Deserialize(Entity entity, const MetaFileClass& metaClass) const override
|
||||
{
|
||||
NameC name;
|
||||
name.name = metaClass.GetValue("name");
|
||||
entity.AddComponent<NameC>(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<TransformC>
|
||||
{
|
||||
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<TransformC>(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<TextureC>
|
||||
{
|
||||
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<TextureC>(texture);
|
||||
}
|
||||
|
||||
protected:
|
||||
void Gui(TextureC& texture) const override
|
||||
{
|
||||
Asset& asset = AssetManager::GetAsset<Texture2D>(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<TextC>
|
||||
{
|
||||
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<TextC>(text);
|
||||
}
|
||||
|
||||
protected:
|
||||
void Gui(TextC& text) const override
|
||||
{
|
||||
Asset& asset = AssetManager::GetAsset<Font>(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>("font.meta")}, "", 20.0f};
|
||||
}
|
||||
};
|
||||
|
||||
class StaticColliderComponentHandler : public ComponentHandler<StaticColliderC>
|
||||
{
|
||||
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<StaticColliderC>(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<DynamicColliderC>
|
||||
{
|
||||
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<DynamicColliderC>(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<PlayerC>
|
||||
{
|
||||
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<PlayerC>(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<CameraC>
|
||||
{
|
||||
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<CameraC>(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<UuidC>
|
||||
{
|
||||
public:
|
||||
UuidComponentHandler() : ComponentHandler{"Uuid", false} {}
|
||||
|
||||
void Deserialize(Entity entity, const MetaFileClass& metaClass) const override
|
||||
{
|
||||
UuidC uuid;
|
||||
uuid.uuid = Uuid{metaClass.GetValue("uuid")};
|
||||
entity.AddComponent<UuidC>(uuid);
|
||||
}
|
||||
|
||||
protected:
|
||||
void ComponentGui(Entity entity) const override {}
|
||||
};
|
||||
|
||||
class HealthComponentHandler : public ComponentHandler<HealthC>
|
||||
{
|
||||
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<HealthC>(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<PhysicsC>
|
||||
{
|
||||
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<PhysicsC>(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<AnimationC>
|
||||
{
|
||||
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<AnimationC>(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<DebugC>
|
||||
{
|
||||
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<DebugC>(debug);
|
||||
}
|
||||
|
||||
protected:
|
||||
void Gui(DebugC& debug) const override
|
||||
{
|
||||
EntityGui("Player", &debug.playerEntity);
|
||||
}
|
||||
|
||||
DebugC Create(Entity entity) const override
|
||||
{
|
||||
return DebugC{Entity{entity.GetManager()}};
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -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 <string>
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
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<Entity> entities;
|
||||
};
|
||||
|
||||
struct NameC
|
||||
{
|
||||
std::string name;
|
||||
};
|
||||
|
||||
struct RenderableC {};
|
||||
struct UiRenderableC {};
|
||||
struct SerializableC {};
|
||||
struct PickupC {};
|
||||
struct MouseFollowC {};
|
||||
struct FrameCountC {};
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "copium/ecs/System.h"
|
||||
#include "copium/example/Components.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace Copium
|
||||
{
|
||||
class DebugSystem : public System<DebugC, TextC, TransformC>
|
||||
{
|
||||
BoundingBox* viewport;
|
||||
public:
|
||||
DebugSystem(BoundingBox* viewport)
|
||||
: viewport{viewport}
|
||||
{}
|
||||
|
||||
void RunEntity(Entity entity, DebugC& debug, TextC& text, TransformC& transform) override
|
||||
{
|
||||
if (!ValidateEntity<PlayerC, TransformC, PhysicsC>(debug.playerEntity))
|
||||
return;
|
||||
|
||||
const PlayerC& player = debug.playerEntity.GetComponent<PlayerC>();
|
||||
const TransformC& playerTransform = debug.playerEntity.GetComponent<TransformC>();
|
||||
const PhysicsC& playerPhysics = debug.playerEntity.GetComponent<PhysicsC>();
|
||||
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<HealthC>())
|
||||
{
|
||||
const HealthC& playerHealth = debug.playerEntity.GetComponent<HealthC>();
|
||||
text.text += String::Format("Health: %d/%d", playerHealth.current, playerHealth.max);
|
||||
}
|
||||
|
||||
const Font& font = AssetManager::GetAsset<Font>(text.font);
|
||||
transform.position.y = viewport->GetSize().y - 10.0f - font.GetBaseHeight() * text.fontSize;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "copium/ecs/System.h"
|
||||
#include "copium/example/Components.h"
|
||||
|
||||
namespace Copium
|
||||
{
|
||||
class FrameCountSystem : public System<FrameCountC, TextC>
|
||||
{
|
||||
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++;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
@@ -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<HealthC>
|
||||
{
|
||||
|
||||
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);
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -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<HealthC>
|
||||
{
|
||||
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<TransformC>(glm::vec2{0.0f, 0.0f}, glm::vec2{0.5f, 0.05f});
|
||||
health.background.AddComponent<ColorC>(glm::vec3{0.152f, 0.14f, 0.207f});
|
||||
health.background.AddComponent<RenderableC>();
|
||||
|
||||
health.foreground = Entity::Create(manager);
|
||||
health.foreground.AddComponent<TransformC>(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<ColorC>(glm::vec3{0.581f, 0.393f, 0.462f});
|
||||
health.foreground.AddComponent<RenderableC>();
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "copium/ecs/System.h"
|
||||
#include "copium/example/Components.h"
|
||||
|
||||
|
||||
namespace Copium
|
||||
{
|
||||
class HealthDisplaySystem : public System<HealthC, TransformC>
|
||||
{
|
||||
void RunEntity(Entity entity, HealthC& health, TransformC& transform) override
|
||||
{
|
||||
TransformC& foregroundTransform = health.foreground.GetComponent<TransformC>();
|
||||
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<TransformC>();
|
||||
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};
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
@@ -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<LevelGeneratorC>
|
||||
{
|
||||
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<TransformC>(glm::vec2{-10.0f, -10.0f + y * 1.0}, glm::vec2{1.0f, 1.0f});
|
||||
if(y == 0 || y == 19)
|
||||
entity.AddComponent<TextureC>(AssetRef{AssetManager::LoadAsset("stone.meta")}, glm::vec2{0.0f, 0.0f}, glm::vec2{0.25f, 1.0f});
|
||||
else
|
||||
entity.AddComponent<TextureC>(AssetRef{AssetManager::LoadAsset("stone.meta")}, glm::vec2{0.75f, 0.0f}, glm::vec2{1.0f, 1.0f});
|
||||
entity.AddComponent<StaticColliderC>(true);
|
||||
entity.AddComponent<RenderableC>();
|
||||
levelGenerator.entities.emplace_back(entity);
|
||||
}
|
||||
{
|
||||
Entity entity = Entity::Create(manager);
|
||||
entity.AddComponent<TransformC>(glm::vec2{10.0f, -10.0f + y * 1.0}, glm::vec2{1.0f, 1.0f});
|
||||
if(y == 0 || y == 19)
|
||||
entity.AddComponent<TextureC>(AssetRef{AssetManager::LoadAsset("stone.meta")}, glm::vec2{0.5f, 0.0f}, glm::vec2{0.75f, 1.0f});
|
||||
else
|
||||
entity.AddComponent<TextureC>(AssetRef{AssetManager::LoadAsset("stone.meta")}, glm::vec2{0.75f, 0.0f}, glm::vec2{1.0f, 1.0f});
|
||||
entity.AddComponent<StaticColliderC>(true);
|
||||
entity.AddComponent<RenderableC>();
|
||||
levelGenerator.entities.emplace_back(entity);
|
||||
}
|
||||
}
|
||||
for (int x = 1; x < 20; x++)
|
||||
{
|
||||
{
|
||||
Entity entity = Entity::Create(manager);
|
||||
entity.AddComponent<TransformC>(glm::vec2{-10.0f + x * 1.0, -10.0f}, glm::vec2{1.0f, 1.0f});
|
||||
entity.AddComponent<TextureC>(AssetRef{AssetManager::LoadAsset("stone.meta")}, glm::vec2{0.25f, 0.0f}, glm::vec2{0.5f, 1.0f});
|
||||
entity.AddComponent<StaticColliderC>(true);
|
||||
entity.AddComponent<RenderableC>();
|
||||
levelGenerator.entities.emplace_back(entity);
|
||||
}
|
||||
{
|
||||
Entity entity = Entity::Create(manager);
|
||||
entity.AddComponent<TransformC>(glm::vec2{-10.0f + x * 1.0, 10.0f}, glm::vec2{1.0f, 1.0f});
|
||||
entity.AddComponent<TextureC>(AssetRef{AssetManager::LoadAsset("stone.meta")}, glm::vec2{0.25f, 0.0f}, glm::vec2{0.5f, 1.0f});
|
||||
entity.AddComponent<StaticColliderC>(true);
|
||||
entity.AddComponent<RenderableC>();
|
||||
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<TransformC>(glm::vec2{-10.0f + x * 1.6f + 0.4f, -10.0f + y * 1.6 + 0.4f}, glm::vec2{0.8f, 0.8f});
|
||||
entity.AddComponent<ColorC>(glm::vec3{x * 0.1f, y * 0.1f, 1.0f});
|
||||
entity.AddComponent<StaticColliderC>(false);
|
||||
entity.AddComponent<PickupC>();
|
||||
entity.AddComponent<RenderableC>();
|
||||
levelGenerator.entities.emplace_back(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Removed(EntityId entityId, LevelGeneratorC& levelGenerator) override
|
||||
{
|
||||
for (auto& entity : levelGenerator.entities)
|
||||
{
|
||||
entity.Destroy();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "copium/ecs/System.h"
|
||||
#include "copium/event/Input.h"
|
||||
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
|
||||
namespace Copium
|
||||
{
|
||||
class MouseFollowSystem : public System<MouseFollowC, TransformC>
|
||||
{
|
||||
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};
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "copium/ecs/System.h"
|
||||
#include "copium/example/Components.h"
|
||||
|
||||
namespace Copium
|
||||
{
|
||||
class PhysicsSystem : public System<PhysicsC, TransformC>
|
||||
{
|
||||
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};
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -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<const CollideSignal&>(signal);
|
||||
if (collideSignal.GetFirst().HasComponent<PickupC>())
|
||||
{
|
||||
if (collideSignal.GetSecond().HasComponent<PlayerC>())
|
||||
{
|
||||
collideSignal.GetFirst().Destroy();
|
||||
}
|
||||
}
|
||||
else if (collideSignal.GetSecond().HasComponent<PickupC>())
|
||||
{
|
||||
if (collideSignal.GetFirst().HasComponent<PlayerC>() && collideSignal.GetFirst().HasComponent<HealthC>())
|
||||
{
|
||||
collideSignal.GetSecond().Destroy();
|
||||
collideSignal.GetFirst().GetComponent<HealthC>().current++;
|
||||
collideSignal.GetSecond().Destroy();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -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<PlayerC, PhysicsC, AnimationC>
|
||||
{
|
||||
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<HealthC>())
|
||||
entity.RemoveComponent<HealthC>();
|
||||
else
|
||||
entity.AddComponent<HealthC>(8, 10);
|
||||
}
|
||||
}
|
||||
|
||||
void Run(const Signal& signal) override
|
||||
{
|
||||
if (signal.GetId() == CollideSignal::GetIdStatic())
|
||||
{
|
||||
const CollideSignal& collideSignal = static_cast<const CollideSignal&>(signal);
|
||||
if (collideSignal.GetFirst().HasComponent<PlayerC>() && collideSignal.WasResolved())
|
||||
{
|
||||
if (collideSignal.GetYDir() == -1)
|
||||
collideSignal.GetFirst().GetComponent<PlayerC>().grounded = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -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 <glm/gtc/matrix_transform.hpp>
|
||||
|
||||
namespace Copium
|
||||
{
|
||||
class RenderSystem : public System<RenderableC, TransformC>
|
||||
{
|
||||
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<TextC>())
|
||||
{
|
||||
const TextC& text = entity.GetComponent<TextC>();
|
||||
renderer->Text(text.text, transform.position, AssetManager::GetAsset<Font>(text.font), text.fontSize);
|
||||
}
|
||||
else if (entity.HasComponent<ColorC>())
|
||||
{
|
||||
const ColorC& color = entity.GetComponent<ColorC>();
|
||||
renderer->Quad(transform.position, transform.size, color.color);
|
||||
}
|
||||
else if (entity.HasComponent<TextureC>())
|
||||
{
|
||||
const TextureC& texture = entity.GetComponent<TextureC>();
|
||||
renderer->Quad(transform.position, transform.size, AssetManager::GetAsset<Sampler>(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<DynamicColliderC, TransformC>([&](EntityId entityId, DynamicColliderC& dynamicCollider, TransformC& transform) { RenderCollider(Entity{manager, entityId}, dynamicCollider, transform); });
|
||||
}
|
||||
|
||||
renderer->End();
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
@@ -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 <glm/gtc/matrix_transform.hpp>
|
||||
|
||||
namespace Copium
|
||||
{
|
||||
class UiRenderSystem : public System<UiRenderableC, TransformC>
|
||||
{
|
||||
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<TextC>())
|
||||
{
|
||||
const TextC& text = entity.GetComponent<TextC>();
|
||||
renderer->Text(text.text, transform.position, AssetManager::GetAsset<Font>(text.font), text.fontSize);
|
||||
}
|
||||
else if (entity.HasComponent<ColorC>())
|
||||
{
|
||||
const ColorC& color = entity.GetComponent<ColorC>();
|
||||
renderer->Quad(transform.position, transform.size, color.color);
|
||||
}
|
||||
else if (entity.HasComponent<TextureC>())
|
||||
{
|
||||
const TextureC& texture = entity.GetComponent<TextureC>();
|
||||
renderer->Quad(transform.position, transform.size, AssetManager::GetAsset<Sampler>(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();
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
@@ -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 <GLFW/glfw3.h>
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -123,6 +123,9 @@ namespace Copium
|
||||
if(trimmedLine.empty())
|
||||
continue;
|
||||
|
||||
if (trimmedLine[0] == '/' && trimmedLine[1] == '/')
|
||||
continue;
|
||||
|
||||
if(trimmedLine == "---")
|
||||
{
|
||||
return;
|
||||
|
||||
@@ -15,4 +15,14 @@ namespace Copium
|
||||
{
|
||||
return std::chrono::duration<double>(std::chrono::high_resolution_clock::now() - startTime).count();
|
||||
}
|
||||
|
||||
double Timer::ElapsedRestart()
|
||||
{
|
||||
std::chrono::time_point<std::chrono::steady_clock> newTime = std::chrono::high_resolution_clock::now();
|
||||
|
||||
double elapsedTime = std::chrono::duration<double>(newTime - startTime).count();
|
||||
startTime = newTime;
|
||||
|
||||
return elapsedTime;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,5 +13,6 @@ namespace Copium
|
||||
|
||||
void Start();
|
||||
double Elapsed();
|
||||
double ElapsedRestart();
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user