From 41a03cc88951997a4d80c80c5f1bf1fd0f61e708 Mon Sep 17 00:00:00 2001 From: facobackup Date: Wed, 4 Mar 2026 21:12:49 -0300 Subject: [PATCH 01/18] Unified atmosphere settings --- CMakeLists.txt | 16 +-- resources/shaders/GlobalDataBuffer.glsl | 18 --- resources/shaders/MaterialBuffer.glsl | 26 ----- resources/shaders/MeshMetadata.glsl | 19 ++- resources/shaders/VolumeBuffer.glsl | 13 --- resources/shaders/rt/HWRayTracing.rchit | 35 +++--- resources/shaders/rt/HWRayTracing.rgen | 47 ++++++-- .../shaders/rt/HWRayTracingPushConstant.glsl | 2 - resources/shaders/util/LightVisibility.glsl | 27 ++--- resources/shaders/util/PixelShading.glsl | 4 +- resources/shaders/util/VolumeRayTracer.glsl | 49 ++++---- src/context/ApplicationContext.cpp | 2 +- src/context/ApplicationContext.h | 5 - .../dock-spaces/files/FilePreviewPanel.cpp | 13 --- .../dock-spaces/files/FilePreviewPanel.h | 5 - .../dock-spaces/files/FilesHeaderPanel.cpp | 10 +- .../dock-spaces/files/FilesListPanel.cpp | 2 - .../editor/dock-spaces/files/FilesPanel.cpp | 16 +-- .../dock-spaces/hierarchy/HierarchyPanel.cpp | 4 +- .../dock-spaces/inspector/InspectorPanel.cpp | 7 +- .../inspector/MaterialEditPanel.cpp | 62 ---------- .../dock-spaces/inspector/MaterialEditPanel.h | 22 ---- .../dock-spaces/metrics/MetricsPanel.cpp | 1 - .../dock-spaces/viewport/EngineFramePanel.cpp | 9 +- .../dock-spaces/viewport/ViewportPanel.cpp | 9 -- .../editor/panel/FileImportModalPanel.cpp | 33 +++--- src/context/engine/EngineContext.cpp | 55 +++------ src/context/engine/EngineContext.h | 5 +- .../compute-pass/impl/HWRayTracingPass.cpp | 14 ++- .../impl/tools/SelectedDotPass.cpp | 4 +- src/dto/buffers/AtmosphereUBO.h | 21 ++++ src/dto/buffers/GlobalDataUBO.h | 6 - src/dto/buffers/MaterialData.h | 29 ----- src/dto/buffers/MeshMetadata.h | 20 +++- .../push-constant/HWRayTracingPushConstant.h | 2 - src/enum/ComponentType.h | 22 ++-- src/enum/EngineResourceIDs.h | 5 +- src/enum/EntryType.h | 9 +- src/repository/editor/EditorRepository.h | 8 ++ src/repository/engine/EngineRepository.cpp | 41 +------ src/repository/engine/EngineRepository.h | 11 -- src/repository/inspection/FilesRepository.cpp | 17 --- src/repository/inspection/FilesRepository.h | 27 ----- src/repository/streaming/StreamingService.cpp | 8 -- src/repository/streaming/StreamingService.h | 10 +- src/repository/world/WorldRepository.cpp | 43 +++---- src/repository/world/WorldRepository.h | 6 +- .../world/components/AtmosphereComponent.cpp | 108 +++++++++++++++++ .../world/components/AtmosphereComponent.h | 45 ++++++++ .../world/components/MeshComponent.cpp | 43 ------- .../world/components/MeshComponent.h | 26 ----- .../world/components/PrimitiveComponent.cpp | 76 ++++++++++++ .../world/components/PrimitiveComponent.h} | 24 ++-- .../world/components/VolumeComponent.cpp | 5 - .../world/components/VolumeComponent.h | 16 +-- src/service/files/FilesService.cpp | 20 ---- src/service/files/FilesService.h | 2 - src/service/lights/LightService.cpp | 58 +++------- src/service/lights/LightService.h | 21 ---- src/service/material/MaterialFileData.cpp | 59 ---------- .../material/MaterialImporterService.cpp | 23 +--- .../material/MaterialImporterService.h | 9 +- src/service/material/MaterialInstance.h | 24 ---- src/service/material/MaterialService.cpp | 109 +++++------------- src/service/material/MaterialService.h | 23 +--- src/service/mesh/EntityAssetData.h | 42 ++++++- src/service/mesh/MeshService.cpp | 45 +++++--- src/service/mesh/MeshService.h | 3 +- src/service/mesh/SceneImporterService.cpp | 11 +- src/service/mesh/SceneImporterService.h | 4 +- src/service/picking/PickingService.cpp | 4 +- src/service/raytracing/RayTracingService.cpp | 43 +++---- src/service/raytracing/RayTracingService.h | 8 +- src/service/transform/TransformService.cpp | 2 +- src/service/volumes/VolumeService.cpp | 16 --- .../voxel/impl/SparseVoxelOctreeBuilder.h | 2 +- src/util/UIUtil.h | 2 - 77 files changed, 677 insertions(+), 1015 deletions(-) delete mode 100644 resources/shaders/MaterialBuffer.glsl delete mode 100644 resources/shaders/VolumeBuffer.glsl delete mode 100644 src/context/editor/dock-spaces/inspector/MaterialEditPanel.cpp delete mode 100644 src/context/editor/dock-spaces/inspector/MaterialEditPanel.h create mode 100644 src/dto/buffers/AtmosphereUBO.h delete mode 100644 src/dto/buffers/MaterialData.h delete mode 100644 src/repository/inspection/FilesRepository.cpp delete mode 100644 src/repository/inspection/FilesRepository.h create mode 100644 src/repository/world/components/AtmosphereComponent.cpp create mode 100644 src/repository/world/components/AtmosphereComponent.h delete mode 100644 src/repository/world/components/MeshComponent.cpp delete mode 100644 src/repository/world/components/MeshComponent.h create mode 100644 src/repository/world/components/PrimitiveComponent.cpp rename src/{service/material/MaterialFileData.h => repository/world/components/PrimitiveComponent.h} (51%) delete mode 100644 src/service/material/MaterialFileData.cpp delete mode 100644 src/service/material/MaterialInstance.h diff --git a/CMakeLists.txt b/CMakeLists.txt index c9cdbc7b..96862a67 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -112,6 +112,7 @@ add_executable( src/repository/runtime/RuntimeRepository.h src/service/buffer/BufferInstance.cpp src/service/buffer/BufferInstance.h + src/dto/buffers/AtmosphereUBO.h src/service/mesh/MeshService.cpp src/service/mesh/MeshService.h src/service/mesh/MeshData.h @@ -154,7 +155,7 @@ add_executable( src/repository/world/impl/EntityComponent.h src/enum/ComponentType.h src/repository/world/impl/AbstractComponent.h - src/repository/world/components/MeshComponent.h + src/repository/world/components/PrimitiveComponent.h src/repository/world/components/TransformComponent.h src/enum/ShadingMode.h src/context/editor/dock-spaces/hierarchy/HierarchyHeaderPanel.cpp @@ -163,7 +164,7 @@ add_executable( src/service/selection/SelectionService.h src/repository/world/impl/EntityComponent.cpp src/repository/world/components/TransformComponent.cpp - src/repository/world/components/MeshComponent.cpp + src/repository/world/components/PrimitiveComponent.cpp src/context/editor/abstract/form/types/ResourceField.cpp src/context/editor/abstract/form/types/ResourceField.h src/context/editor/abstract/form/types/ColorField.cpp @@ -202,7 +203,6 @@ add_executable( src/service/voxel/impl/VoxelData.h src/service/mesh/SceneData.h src/service/mesh/EntityAssetData.h - src/service/material/MaterialFileData.h src/context/engine/render-pass/impl/PostProcessingPass.cpp src/context/engine/render-pass/impl/PostProcessingPass.h src/context/engine/compute-pass/impl/HWRayTracingPass.cpp @@ -244,14 +244,8 @@ add_executable( src/context/engine/passes/AbstractPass.cpp src/context/engine/passes/AbstractPass.h src/util/ImageUtils.h - src/service/material/MaterialInstance.h src/service/material/MaterialService.cpp src/service/material/MaterialService.h - src/service/material/MaterialFileData.cpp - src/repository/inspection/FilesRepository.cpp - src/repository/inspection/FilesRepository.h - src/context/editor/dock-spaces/inspector/MaterialEditPanel.cpp - src/context/editor/dock-spaces/inspector/MaterialEditPanel.h src/enum/LightType.h src/context/engine/compute-pass/impl/AccumulationPass.cpp src/context/engine/compute-pass/impl/AccumulationPass.h @@ -259,11 +253,12 @@ add_executable( src/service/lights/LightService.h src/repository/world/components/VolumeComponent.cpp src/repository/world/components/VolumeComponent.h + src/repository/world/components/AtmosphereComponent.cpp + src/repository/world/components/AtmosphereComponent.h src/service/descriptor/DescriptorBinding.h src/service/notification/AsyncTask.h src/service/voxel/VoxelImporterService.cpp src/service/voxel/VoxelImporterService.h - src/dto/buffers/MaterialData.h src/dto/buffers/VolumeData.h src/service/volumes/VolumeService.cpp src/service/volumes/VolumeService.h @@ -297,6 +292,7 @@ add_executable( src/context/engine/compute-pass/impl/TemporalAccumulationPass.h src/context/engine/compute-pass/impl/SpatialFilterPass.cpp src/context/engine/compute-pass/impl/SpatialFilterPass.h + src/repository/world/components/AtmosphereComponent.cpp ) diff --git a/resources/shaders/GlobalDataBuffer.glsl b/resources/shaders/GlobalDataBuffer.glsl index 62bdd11d..4cf207c2 100644 --- a/resources/shaders/GlobalDataBuffer.glsl +++ b/resources/shaders/GlobalDataBuffer.glsl @@ -8,11 +8,8 @@ layout (set = 0, binding = 0) uniform GlobalDataBlock { mat4 invProj; mat4 previousProjView; vec3 cameraWorldPosition; - vec3 sunColor; - vec3 sunPosition; vec2 outputRes; - uint volumeCount; uint lightsCount; uint debugFlag; @@ -23,19 +20,4 @@ layout (set = 0, binding = 0) uniform GlobalDataBlock { } globalData; -bool intersectBox(vec3 ro, vec3 rd, vec3 dimensions, out float tEntry, out float tExit) { - vec3 boxMin = -dimensions * 0.5; - vec3 boxMax = dimensions * 0.5; - vec3 invRd = 1.0 / rd; - - vec3 t0s = (boxMin - ro) * invRd; - vec3 t1s = (boxMax - ro) * invRd; - vec3 tsmaller = min(t0s, t1s); - vec3 tbigger = max(t0s, t1s); - - tEntry = max(max(tsmaller.x, tsmaller.y), tsmaller.z); - tExit = min(min(tbigger.x, tbigger.y), tbigger.z); - - return (tExit >= max(tEntry, 0.0)); -} #endif \ No newline at end of file diff --git a/resources/shaders/MaterialBuffer.glsl b/resources/shaders/MaterialBuffer.glsl deleted file mode 100644 index 9798ac08..00000000 --- a/resources/shaders/MaterialBuffer.glsl +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef MATERIAL_V -#define MATERIAL_V -struct MaterialData { - vec3 albedo; - float roughness; - float metallic; - float transmission; - float thickness; - float ior; - uint isEmissive; - - uint useAlbedoTexture; - uint useNormalTexture; - uint useRoughnessTexture; - uint useMetallicTexture; - - uint albedoTexture; - uint normalTexture; - uint roughnessTexture; - uint metallicTexture; -}; - -layout (set = 0, binding = MATERIAL_SET) readonly buffer Materials { - MaterialData items[]; -} materialBuffer; -#endif diff --git a/resources/shaders/MeshMetadata.glsl b/resources/shaders/MeshMetadata.glsl index 5022112d..2521a089 100644 --- a/resources/shaders/MeshMetadata.glsl +++ b/resources/shaders/MeshMetadata.glsl @@ -5,9 +5,26 @@ struct MeshMetadata { uint renderIndex; - uint materialIndex; uint64_t vertexBufferAddress; uint64_t indexBufferAddress; + + vec3 albedo; + float roughness; + float metallic; + float transmission; + float thickness; + float ior; + uint isEmissive; + + uint useAlbedoTexture; + uint useNormalTexture; + uint useRoughnessTexture; + uint useMetallicTexture; + + uint albedoTexture; + uint normalTexture; + uint roughnessTexture; + uint metallicTexture; }; layout (set = 0, binding = MESH_METADATA_SET) readonly buffer MeshMetadatas { diff --git a/resources/shaders/VolumeBuffer.glsl b/resources/shaders/VolumeBuffer.glsl deleted file mode 100644 index e8da13d6..00000000 --- a/resources/shaders/VolumeBuffer.glsl +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef VOLUME_V -#define VOLUME_V -struct Volume { - vec4 color; - vec3 position; - vec3 dataA; - vec3 dataB; //For volumes: -}; - -layout(set = 0, binding = VOLUME_SET) readonly buffer Volumes { - Volume items[]; -} volumesBuffer; -#endif diff --git a/resources/shaders/rt/HWRayTracing.rchit b/resources/shaders/rt/HWRayTracing.rchit index 6f96d602..f1ee83d2 100644 --- a/resources/shaders/rt/HWRayTracing.rchit +++ b/resources/shaders/rt/HWRayTracing.rchit @@ -4,12 +4,10 @@ #extension GL_EXT_buffer_reference2 : require #include "../util/HWRayTracingUtil.glsl" -#define MATERIAL_SET 7 -#include "../MaterialBuffer.glsl" -#define MESH_METADATA_SET 8 +#define MESH_METADATA_SET 7 #include "../MeshMetadata.glsl" -layout (set = 0, binding = 9) uniform sampler2D textureArray[]; +layout (set = 0, binding = 8) uniform sampler2D textureArray[]; layout (location = 0) rayPayloadInEXT RayPayload payload; hitAttributeEXT vec2 attribs; // Barycentric coordinates for the hit @@ -73,27 +71,26 @@ void main() { float ior = 1.45; bool isEmissive = false; - if (matIndex != 0u) { - MaterialData mat = materialBuffer.items[matIndex]; - if (mat.useAlbedoTexture == 1u) { - baseColor = texture(textureArray[nonuniformEXT(mat.albedoTexture)], uv).rgb; + if (matIndex != 0u) { + if (metadata.useAlbedoTexture == 1u) { + baseColor = texture(textureArray[nonuniformEXT(metadata.albedoTexture)], uv).rgb; } else { - baseColor = mat.albedo; + baseColor = metadata.albedo; } - if (mat.useRoughnessTexture == 1u) { - roughness = texture(textureArray[nonuniformEXT(mat.roughnessTexture)], uv).r; + if (metadata.useRoughnessTexture == 1u) { + roughness = texture(textureArray[nonuniformEXT(metadata.roughnessTexture)], uv).r; } else { - roughness = mat.roughness; + roughness = metadata.roughness; } - if (mat.useMetallicTexture == 1u) { - metallic = texture(textureArray[nonuniformEXT(mat.metallicTexture)], uv).r; + if (metadata.useMetallicTexture == 1u) { + metallic = texture(textureArray[nonuniformEXT(metadata.metallicTexture)], uv).r; } else { - metallic = mat.metallic; + metallic = metadata.metallic; } - transmission = mat.transmission; - thickness = mat.thickness; - ior = mat.ior; - isEmissive = mat.isEmissive == 1u; + transmission = metadata.transmission; + thickness = metadata.thickness; + ior = metadata.ior; + isEmissive = metadata.isEmissive == 1u; } payload.material.baseColor = baseColor; diff --git a/resources/shaders/rt/HWRayTracing.rgen b/resources/shaders/rt/HWRayTracing.rgen index 5b29db03..ba7aeb59 100644 --- a/resources/shaders/rt/HWRayTracing.rgen +++ b/resources/shaders/rt/HWRayTracing.rgen @@ -13,20 +13,47 @@ layout (set = 0, binding = 4, rgba16f) uniform image2D gBufferNormal; layout (location = 0) rayPayloadEXT RayPayload payload; +bool intersectBox(vec3 ro, vec3 rd, vec3 dimensions, out float tEntry, out float tExit) { + vec3 boxMin = -dimensions * 0.5; + vec3 boxMax = dimensions * 0.5; + vec3 invRd = 1.0 / rd; + + vec3 t0s = (boxMin - ro) * invRd; + vec3 t1s = (boxMax - ro) * invRd; + vec3 tsmaller = min(t0s, t1s); + vec3 tbigger = max(t0s, t1s); + + tEntry = max(max(tsmaller.x, tsmaller.y), tsmaller.z); + tExit = min(min(tbigger.x, tbigger.y), tbigger.z); + + return (tExit >= max(tEntry, 0.0)); +} + #define LIGHT_SET 5 #include "../LightBuffer.glsl" -#define VOLUME_SET 6 -#include "../VolumeBuffer.glsl" -#define MATERIAL_SET 7 -#include "../MaterialBuffer.glsl" -#define MESH_METADATA_SET 8 + + +layout (set = 0, binding = 6) uniform AtmosphereDataBlock { + vec3 albedo; + vec3 volumeScale; + uint isAtmosphereEnabled; + uint isVolumeEnabled; + uint volumeShadowSteps; + float density; + float g; + float scatteringAlbedo; + int samples; + + vec3 sunPosition; +} atmosphereData; + +#define MESH_METADATA_SET 7 #include "../MeshMetadata.glsl" #include "../util/DisneyBSDF.glsl" #include "../util/PixelShading.glsl" #include "../util/VolumeRayTracer.glsl" - #include "../GBufferUtil.glsl" #ifdef DEBUG @@ -67,13 +94,13 @@ void main() { payload.hit = false; payload.renderIndex = 0; - if(pushConstants.shouldTrace == 1){ + if (pushConstants.shouldTrace == 1) { traceRayEXT(topLevelAS, gl_RayFlagsOpaqueEXT, 0xFF, 0, 0, 0, rayOrigin, 0.001, rayDirection, 10000.0, 0); } if (!payload.hit) { - if (pushConstants.isAtmosphereEnabled != 0) { - finalColor = calculate_sky_luminance_rgb(normalize(globalData.sunPosition), rayDirection, 2.0f) * 0.05f; + if (atmosphereData.isAtmosphereEnabled != 0) { + finalColor = calculate_sky_luminance_rgb(normalize(atmosphereData.sunPosition), rayDirection, 2.0f) * 0.05f; } imageStore(gBufferPositionIndex, ivec2(gl_LaunchIDEXT.xy), vec4(0.0, 0.0, 0.0, 0.0)); imageStore(gBufferNormal, ivec2(gl_LaunchIDEXT.xy), vec4(0.0, 0.0, 0.0, 0.0)); @@ -88,7 +115,7 @@ void main() { interaction.anyHit = true; #ifdef DEBUG - if (globalData.debugFlag != LIT) { + if (globalData.debugFlag != LIT) { bool shouldReturn = true; if (globalData.debugFlag == NORMAL) { finalColor = interaction.normal; diff --git a/resources/shaders/rt/HWRayTracingPushConstant.glsl b/resources/shaders/rt/HWRayTracingPushConstant.glsl index 78d566ee..01dd0e81 100644 --- a/resources/shaders/rt/HWRayTracingPushConstant.glsl +++ b/resources/shaders/rt/HWRayTracingPushConstant.glsl @@ -3,8 +3,6 @@ layout(push_constant) uniform PushConstants { float pathTracerMultiplier; - uint volumeShadowSteps; - uint isAtmosphereEnabled; uint multipleImportanceSampling; uint pathTracerSamples; diff --git a/resources/shaders/util/LightVisibility.glsl b/resources/shaders/util/LightVisibility.glsl index 92796b16..d3006d7a 100644 --- a/resources/shaders/util/LightVisibility.glsl +++ b/resources/shaders/util/LightVisibility.glsl @@ -1,6 +1,6 @@ #ifndef V_T #define V_T -vec3 visibilityTest(const in Light light, in vec3 point, vec3 wi) { +vec3 visibilityTest(const in Light light, in vec3 point, vec3 wi) { float bias = max(.05, 1e-4 * length(point)); vec3 shadowsPosition = point + bias * wi;// Offset to avoid self-intersection @@ -20,29 +20,20 @@ vec3 visibilityTest(const in Light light, in vec3 point, vec3 wi) { float sigmaT = 0; vec3 vColor = vec3(1); bool anyHit = false; - for (uint i = 0; i < globalData.volumeCount; i++) { - Volume volume = volumesBuffer.items[i]; - - float tEntry, tExit; - vec3 roLocal = shadowsPosition - volume.position; - bool intersects = intersectBox(roLocal, wi, volume.dataA, tEntry, tExit); - if (!intersects) continue; - - if (tEntry > lightDistance){ - continue; - } + float tEntry, tExit; + vec3 roLocal = shadowsPosition; + bool intersects = intersectBox(roLocal, wi, atmosphereData.volumeScale, tEntry, tExit); + if (intersects && tEntry < lightDistance) { anyHit = true; - sigmaT = volume.dataB.x; + sigmaT = atmosphereData.density; distanceInVolume = tExit - tEntry; transmittance *= exp(-sigmaT * distanceInVolume); - vColor = volume.color.rgb; - if (transmittance < 1e-3) { - break; - } + vColor = atmosphereData.albedo; } - return attenuation * vec3(transmittance * exp(-sigmaT * distanceInVolume ) * vColor); + + return attenuation * vec3(transmittance * exp(-sigmaT * distanceInVolume) * vColor); } #endif \ No newline at end of file diff --git a/resources/shaders/util/PixelShading.glsl b/resources/shaders/util/PixelShading.glsl index 789e6d47..8514b173 100644 --- a/resources/shaders/util/PixelShading.glsl +++ b/resources/shaders/util/PixelShading.glsl @@ -67,8 +67,8 @@ vec3 calculateIndirectLighting(MaterialInfo material, SurfaceInteraction interac traceRayEXT(topLevelAS, gl_RayFlagsOpaqueEXT, 0xFF, 0, 0, 0, rayOrigin, 0.001, wi, 1000.0, 0); if (!payload.hit) { - if (pushConstants.isAtmosphereEnabled != 0) { - bounceInfo.material.baseColor = calculate_sky_luminance_rgb(normalize(globalData.sunPosition), wi, 2.0f) * 0.05f; + if (atmosphereData.isAtmosphereEnabled != 0) { + bounceInfo.material.baseColor = calculate_sky_luminance_rgb(normalize(atmosphereData.sunPosition), wi, 2.0f) * 0.05f; bounceInfo.material.isEmissive = true; bounceInfo.interaction.point = rayOrigin + wi * 1000.0; // Placeholder point for atmosphere computeRadiance(bounceInfo); diff --git a/resources/shaders/util/VolumeRayTracer.glsl b/resources/shaders/util/VolumeRayTracer.glsl index 4d651a74..d4d4e764 100644 --- a/resources/shaders/util/VolumeRayTracer.glsl +++ b/resources/shaders/util/VolumeRayTracer.glsl @@ -20,33 +20,33 @@ float hash(vec3 p) { } float densityVariation(vec3 p, float baseDensity) { -// float noise = hash(p * 0.5); + // float noise = hash(p * 0.5); return baseDensity; //* (0.5 + 0.5 * noise); } // Henyey–Greenstein phase function float phaseHenyeyGreenstein(vec3 wo, vec3 wi, float g) { float cosTheta = dot(wo, wi); - float denom = 1.0 + g*g - 2.0 * g * cosTheta; - return (1.0 - g*g) / (4.0 * 3.14159265359 * pow(denom, 1.5)); + float denom = 1.0 + g * g - 2.0 * g * cosTheta; + return (1.0 - g * g) / (4.0 * 3.14159265359 * pow(denom, 1.5)); } -vec4 integrateVolume(vec3 ro, vec3 rd, in Volume volume, float sceneDepth) { - vec3 roLocal = ro - volume.position; +vec4 integrateVolume(vec3 ro, vec3 rd, float sceneDepth) { + vec3 roLocal = ro; float tEntry, tExit; - bool intersects = intersectBox(roLocal, rd, volume.dataA, tEntry, tExit); + bool intersects = intersectBox(roLocal, rd, atmosphereData.volumeScale, tEntry, tExit); if (!intersects) { return vec4(0.0); } - if (tEntry > sceneDepth){ + if (tEntry > sceneDepth) { return vec4(0.0); } tEntry = max(tEntry, 0.0); - int steps = int(volume.color.a); + int steps = int(atmosphereData.samples); float dt = (tExit - tEntry) / float(steps); vec3 scattering = vec3(0.0); @@ -55,14 +55,14 @@ vec4 integrateVolume(vec3 ro, vec3 rd, in Volume volume, float sceneDepth) { for (int i = 0; i < steps; i++) { float tCurrent = tEntry + dt * (float(i) + 0.5); vec3 pos = ro + rd * tCurrent; - vec3 localPos = pos - volume.position; + vec3 localPos = pos ; - float density = densityVariation(localPos, volume.dataB.x); + float density = densityVariation(localPos, atmosphereData.density); - float scatteringAlbedo = volume.dataB.y;// fraction of extinction that is scattering + float scatteringAlbedo = atmosphereData.scatteringAlbedo;// fraction of extinction that is scattering float scatteringCoefficient = density * scatteringAlbedo; - float absorptionCoefficient = density * (1.0 - scatteringAlbedo); - float extinctionCoefficient = scatteringCoefficient + absorptionCoefficient; + float absorptionCoefficient = density * (1.0 - scatteringAlbedo); + float extinctionCoefficient = scatteringCoefficient + absorptionCoefficient; vec3 inScattered = vec3(0.0); for (int li = 0; li < int(globalData.lightsCount); li++) { @@ -83,16 +83,16 @@ vec4 integrateVolume(vec3 ro, vec3 rd, in Volume volume, float sceneDepth) { vec3 L = normalize(samplePos - pos); float lightDist = length(samplePos - pos); - float dtShadow = lightDist / float(pushConstants.volumeShadowSteps); + float dtShadow = lightDist / float(atmosphereData.volumeShadowSteps); float opticalDepth = 0.0; - for (int j = 0; j < int(pushConstants.volumeShadowSteps); j++) { + for (int j = 0; j < int(atmosphereData.volumeShadowSteps); j++) { float tShadow = float(j) * dtShadow; vec3 posShadow = pos + L * tShadow; - vec3 localShadow = posShadow - volume.position; - opticalDepth += densityVariation(localShadow, volume.dataB.x) * dtShadow; + vec3 localShadow = posShadow; + opticalDepth += densityVariation(localShadow, atmosphereData.density) * dtShadow; } float lightTransmittance = exp(-opticalDepth); - float g = volume.dataB.z;// phase function asymmetry parameter; 0.0 for isotropic + float g = atmosphereData.g;// phase function asymmetry parameter; 0.0 for isotropic float phase = phaseHenyeyGreenstein(rd, L, g); inScattered += light.color.rgb * light.color.a * lightTransmittance * phase; } @@ -100,15 +100,16 @@ vec4 integrateVolume(vec3 ro, vec3 rd, in Volume volume, float sceneDepth) { viewTransmittance *= exp(-extinctionCoefficient * dt); } float volumeAlpha = 1.0 - viewTransmittance; - return vec4(scattering * volume.color.rgb, volumeAlpha); + return vec4(scattering * atmosphereData.albedo, volumeAlpha); } -void traceVolumes(inout vec4 finalColor, vec3 worldPosition, vec3 rayDirection){ +void traceVolumes(inout vec4 finalColor, vec3 worldPosition, vec3 rayDirection) { + if (atmosphereData.isVolumeEnabled == 0) { + return; + } vec3 rayOrigin = globalData.cameraWorldPosition; float sceneDepth = length(worldPosition.rgb - rayOrigin); - for (uint i = 0; i < globalData.volumeCount; i++) { - Volume volume = volumesBuffer.items[i]; - finalColor += integrateVolume(rayOrigin, rayDirection, volume, sceneDepth); - } + finalColor += integrateVolume(rayOrigin, rayDirection, sceneDepth); + } \ No newline at end of file diff --git a/src/context/ApplicationContext.cpp b/src/context/ApplicationContext.cpp index 1827b4f0..75fa7640 100644 --- a/src/context/ApplicationContext.cpp +++ b/src/context/ApplicationContext.cpp @@ -13,7 +13,7 @@ namespace Metal { std::unique_ptr ApplicationContext::CONTEXT = nullptr; - ApplicationContext &CTX { + ApplicationContext &ApplicationContext::Get() { if (CONTEXT == nullptr) { throw std::runtime_error("Context not initialized"); } diff --git a/src/context/ApplicationContext.h b/src/context/ApplicationContext.h index ea94bd01..09bc13a5 100644 --- a/src/context/ApplicationContext.h +++ b/src/context/ApplicationContext.h @@ -26,7 +26,6 @@ #include "../service/camera/CameraService.h" #include "../repository/world/impl/WorldGridRepository.h" -#include "../repository/inspection/FilesRepository.h" #include "../repository/world/WorldRepository.h" #include "../repository/runtime/RuntimeRepository.h" #include "../repository/streaming/StreamingService.h" @@ -67,9 +66,6 @@ namespace Metal { GuiContext guiContext{}; GLFWContext glfwContext{}; - // // ----------- CORE REPOSITORIES - // ----------- CORE REPOSITORIES - // ----------- Services NotificationService notificationService; AsyncTaskService asyncTaskService; @@ -103,7 +99,6 @@ namespace Metal { // ----------- Services // ----------- Repository - FilesRepository fileInspection{}; WorldGridRepository worldGridRepository{}; WorldRepository worldRepository{}; RuntimeRepository runtimeRepository{}; diff --git a/src/context/editor/dock-spaces/files/FilePreviewPanel.cpp b/src/context/editor/dock-spaces/files/FilePreviewPanel.cpp index 5003b87e..7b0a2376 100644 --- a/src/context/editor/dock-spaces/files/FilePreviewPanel.cpp +++ b/src/context/editor/dock-spaces/files/FilePreviewPanel.cpp @@ -3,19 +3,12 @@ #include "../../../../util/UIUtil.h" #include "../../../../dto/file/FSEntry.h" #include "../../../../context/ApplicationContext.h" -#include "../../../../common/interface/Icons.h" #include "../../../../service/texture/TextureInstance.h" -#include "../inspector/MaterialEditPanel.h" namespace Metal { FilePreviewPanel::FilePreviewPanel(FilesContext &filesContext) : filesContext(filesContext) { } - void FilePreviewPanel::onInitialize() { - materialInspection = new MaterialEditPanel(); - appendChild(materialInspection); - } - void FilePreviewPanel::onSync() { if (filesContext.selected.empty()) { ImGui::Text("Select a file to preview"); @@ -51,12 +44,7 @@ namespace Metal { CTX.guiContext.renderImage(texture, renderWidth, renderHeight); ImGui::Separator(); } - } else if (selected->type == EntryType::MATERIAL) { - CTX.fileInspection.materialId = selected->getId(); - materialInspection->onSync(); - ImGui::Separator(); } - if (ImGui::BeginTable((id + "metadata").c_str(), 2, ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg)) { ImGui::TableSetupColumn("Property"); ImGui::TableSetupColumn("Value"); @@ -76,7 +64,6 @@ namespace Metal { case EntryType::MESH: typeLabel = "Mesh"; break; case EntryType::TEXTURE: typeLabel = "Texture"; break; case EntryType::VOLUME: typeLabel = "Volume"; break; - case EntryType::MATERIAL: typeLabel = "Material"; break; case EntryType::DIRECTORY: typeLabel = "Directory"; break; default: typeLabel = "Unknown"; break; } diff --git a/src/context/editor/dock-spaces/files/FilePreviewPanel.h b/src/context/editor/dock-spaces/files/FilePreviewPanel.h index 5e381cc4..689ac058 100644 --- a/src/context/editor/dock-spaces/files/FilePreviewPanel.h +++ b/src/context/editor/dock-spaces/files/FilePreviewPanel.h @@ -5,17 +5,12 @@ #include "FilesContext.h" namespace Metal { - class MaterialEditPanel; - class FilePreviewPanel final : public AbstractPanel { FilesContext &filesContext; - MaterialEditPanel *materialInspection = nullptr; public: explicit FilePreviewPanel(FilesContext &filesContext); - void onInitialize() override; - void onSync() override; }; } diff --git a/src/context/editor/dock-spaces/files/FilesHeaderPanel.cpp b/src/context/editor/dock-spaces/files/FilesHeaderPanel.cpp index 8767846f..3924fb73 100644 --- a/src/context/editor/dock-spaces/files/FilesHeaderPanel.cpp +++ b/src/context/editor/dock-spaces/files/FilesHeaderPanel.cpp @@ -35,15 +35,7 @@ namespace Metal { ImGui::SameLine(); ImGui::Text(filesContext.pathToCurrentDirectory.c_str()); - UIUtil::DynamicSpacing(264); - - if (UIUtil::ButtonSimple(Icons::format_paint + id, UIUtil::ONLY_ICON_BUTTON_SIZE, - UIUtil::ONLY_ICON_BUTTON_SIZE)) { - CTX.filesService.createMaterial(filesContext.currentDirectory->absolutePath, filesContext.currentDirectory); - FilesService::GetEntries(filesContext.currentDirectory); - } - UIUtil::RenderTooltip("Create material"); - ImGui::SameLine(); + UIUtil::DynamicSpacing(200); ImGui::SetNextItemWidth(100); editorMode = IndexOfValue(filesContext.filterType); diff --git a/src/context/editor/dock-spaces/files/FilesListPanel.cpp b/src/context/editor/dock-spaces/files/FilesListPanel.cpp index 10d0f27b..54f75cd0 100644 --- a/src/context/editor/dock-spaces/files/FilesListPanel.cpp +++ b/src/context/editor/dock-spaces/files/FilesListPanel.cpp @@ -196,8 +196,6 @@ namespace Metal { break; case EntryType::VOLUME: typeLabel = "Volume"; break; - case EntryType::MATERIAL: typeLabel = "Material"; - break; default: typeLabel = ""; break; } diff --git a/src/context/editor/dock-spaces/files/FilesPanel.cpp b/src/context/editor/dock-spaces/files/FilesPanel.cpp index bfb9a569..a23068e7 100644 --- a/src/context/editor/dock-spaces/files/FilesPanel.cpp +++ b/src/context/editor/dock-spaces/files/FilesPanel.cpp @@ -32,17 +32,17 @@ namespace Metal { } }); if (!files.empty()) { - CTX.fileInspection.pendingImports = files; - CTX.fileInspection.importSettingsMap.clear(); - for (const auto& file : CTX.fileInspection.pendingImports) { + CTX.editorRepository.pendingImports = files; + CTX.editorRepository.importSettingsMap.clear(); + for (const auto& file : CTX.editorRepository.pendingImports) { if (CTX.sceneImporterService.isCompatible(file)) { - CTX.fileInspection.importSettingsMap.emplace(file, std::make_shared()); + CTX.editorRepository.importSettingsMap.emplace(file, std::make_shared()); } else { - CTX.fileInspection.importSettingsMap.emplace(file, std::make_shared()); + CTX.editorRepository.importSettingsMap.emplace(file, std::make_shared()); } } - CTX.fileInspection.selectedFileForSettings = CTX.fileInspection.pendingImports[0]; - CTX.fileInspection.targetImportDirectory = filesContext.currentDirectory; + CTX.editorRepository.selectedFileForSettings = CTX.editorRepository.pendingImports[0]; + CTX.editorRepository.targetImportDirectory = filesContext.currentDirectory; } }; } @@ -124,7 +124,7 @@ namespace Metal { void FilesPanel::openResource(FSEntry *root) { switch (root->type) { case EntryType::MESH: { - CTX.meshService.createMeshEntity(root->name, root->getId(), ""); + CTX.meshService.createMeshEntity(root->name, root->getId(), nullptr); break; } case EntryType::SCENE: { diff --git a/src/context/editor/dock-spaces/hierarchy/HierarchyPanel.cpp b/src/context/editor/dock-spaces/hierarchy/HierarchyPanel.cpp index 6db2000b..24171b3b 100644 --- a/src/context/editor/dock-spaces/hierarchy/HierarchyPanel.cpp +++ b/src/context/editor/dock-spaces/hierarchy/HierarchyPanel.cpp @@ -130,8 +130,8 @@ namespace Metal { const char *HierarchyPanel::GetIcon(const EntityID entityId) const { const auto entity = static_cast(entityId); - if (world->registry.all_of(entity)) { - return ComponentTypes::IconOf(ComponentTypes::MESH); + if (world->registry.all_of(entity)) { + return ComponentTypes::IconOf(ComponentTypes::PRIMITIVE); } if (world->registry.all_of >(entity)) { return ComponentTypes::IconOf(ComponentTypes::SPHERE_LIGHT); diff --git a/src/context/editor/dock-spaces/inspector/InspectorPanel.cpp b/src/context/editor/dock-spaces/inspector/InspectorPanel.cpp index 6b438f70..3af42e36 100644 --- a/src/context/editor/dock-spaces/inspector/InspectorPanel.cpp +++ b/src/context/editor/dock-spaces/inspector/InspectorPanel.cpp @@ -48,8 +48,8 @@ namespace Metal { if (selectedEntity != nullptr) { additionalInspection.push_back(selectedEntity); - if (repo.registry.all_of(entity)) { - additionalInspection.push_back((Inspectable *) &repo.registry.get(entity)); + if (repo.registry.all_of(entity)) { + additionalInspection.push_back((Inspectable *) &repo.registry.get(entity)); } if (repo.registry.all_of(entity)) { additionalInspection.push_back((Inspectable *) &repo.registry.get(entity)); @@ -61,6 +61,9 @@ namespace Metal { if (repo.registry.all_of(entity)) { additionalInspection.push_back((Inspectable *) &repo.registry.get(entity)); } + if (repo.registry.all_of(entity)) { + additionalInspection.push_back((Inspectable *) &repo.registry.get(entity)); + } } } else { selectedEntity = nullptr; diff --git a/src/context/editor/dock-spaces/inspector/MaterialEditPanel.cpp b/src/context/editor/dock-spaces/inspector/MaterialEditPanel.cpp deleted file mode 100644 index 2a127070..00000000 --- a/src/context/editor/dock-spaces/inspector/MaterialEditPanel.cpp +++ /dev/null @@ -1,62 +0,0 @@ -#include "MaterialEditPanel.h" - -#include "../../../ApplicationContext.h" -#include "../../../../util/UIUtil.h" -#include "../../../../util/serialization-definitions.h" -#include "../../../../service/material/MaterialFileData.h" -#include "../../../../enum/engine-definitions.h" - -namespace Metal { - void MaterialEditPanel::onInitialize() { - formPanel = new FormPanel(); - appendChild(formPanel); - } - - void MaterialEditPanel::saveChanges() { - CTX.engineContext.setGISettingsUpdated(true); - data->freezeVersion(); - DUMP_TEMPLATE(CTX.getAssetDirectory() + FORMAT_FILE_MATERIAL(prevSelection), *data) - CTX.notificationService.pushMessage("Material was saved", NotificationSeverities::SUCCESS); - - CTX.materialService.dispose(prevSelection); - } - - void MaterialEditPanel::onSync() { - if (prevSelection != CTX.fileInspection.materialId) { - delete data; - data = CTX.materialService.stream(CTX.fileInspection.materialId); - prevSelection = CTX.fileInspection.materialId; - formPanel->resetForm(); - } - if (prevSelection.empty()) { - return; - } - ImGui::Spacing(); - bool changed = data->isNotFrozen(); - if (changed) { - ImGui::PushStyleColor(ImGuiCol_Button, CTX.editorRepository.accent); // Orange-ish - } - if (ImGui::Button(("Save" + id + "save1").c_str())) { - saveChanges(); - } - if (changed) { - ImGui::PopStyleColor(); - } - ImGui::Spacing(); - - formPanel->setInspection(data); - formPanel->onSync(); - - ImGui::Spacing(); - changed = data->isNotFrozen(); - if (changed) { - ImGui::PushStyleColor(ImGuiCol_Button, CTX.editorRepository.accent); // Orange-ish - } - if (ImGui::Button(("Save" + id + "save").c_str())) { - saveChanges(); - } - if (changed) { - ImGui::PopStyleColor(); - } - } -} // Metal diff --git a/src/context/editor/dock-spaces/inspector/MaterialEditPanel.h b/src/context/editor/dock-spaces/inspector/MaterialEditPanel.h deleted file mode 100644 index 1f02daee..00000000 --- a/src/context/editor/dock-spaces/inspector/MaterialEditPanel.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef MATERIALINSPECTION_H -#define MATERIALINSPECTION_H -#include "../../abstract/AbstractPanel.h" -#include "../../abstract/form/FormPanel.h" - -namespace Metal { - struct MaterialFileData; - - class MaterialEditPanel final : public AbstractPanel { - std::string prevSelection; - MaterialFileData *data = nullptr; - FormPanel *formPanel = nullptr; - public: - void onInitialize() override; - - void saveChanges(); - - void onSync() override; - }; -} // Metal - -#endif //MATERIALINSPECTION_H diff --git a/src/context/editor/dock-spaces/metrics/MetricsPanel.cpp b/src/context/editor/dock-spaces/metrics/MetricsPanel.cpp index 1ff17f73..fc27f0e2 100644 --- a/src/context/editor/dock-spaces/metrics/MetricsPanel.cpp +++ b/src/context/editor/dock-spaces/metrics/MetricsPanel.cpp @@ -23,7 +23,6 @@ namespace Metal { void MetricsPanel::onSync() { drawResourceList("Meshes", CTX.meshService, id); - drawResourceList("Materials", CTX.materialService, id); drawResourceList("Voxels", CTX.voxelService, id); drawResourceList("Framebuffers", CTX.framebufferService, id); drawResourceList("Textures", CTX.textureService, id); diff --git a/src/context/editor/dock-spaces/viewport/EngineFramePanel.cpp b/src/context/editor/dock-spaces/viewport/EngineFramePanel.cpp index 1b151545..31df28a7 100644 --- a/src/context/editor/dock-spaces/viewport/EngineFramePanel.cpp +++ b/src/context/editor/dock-spaces/viewport/EngineFramePanel.cpp @@ -12,9 +12,8 @@ #include "../../../../dto/buffers/GlobalDataUBO.h" #include "../../../../dto/buffers/TileInfoUBO.h" #include "../../../../dto/buffers/LightData.h" -#include "../../../../dto/buffers/VolumeData.h" -#include "../../../../dto/buffers/MaterialData.h" #include "../../../../dto/buffers/MeshMetadata.h" +#include "../../../../dto/buffers/AtmosphereUBO.h" #include "ViewportHeaderPanel.h" #include "ImGuizmo.h" #include @@ -27,14 +26,10 @@ namespace Metal { engineFrame = EngineFrameBuilder() .addBuffer(RID_GLOBAL_DATA, sizeof(GlobalDataUBO), VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, UNIFORM_BUFFER) - .addBuffer(RID_TILE_INFO, sizeof(TileInfoUBO), + .addBuffer(RID_ATMOSPHERE_DATA, sizeof(AtmosphereUBO), VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, UNIFORM_BUFFER) .addBuffer(RID_LIGHT_BUFFER, MAX_LIGHTS * sizeof(LightData), VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, STORAGE_BUFFER) - .addBuffer(RID_VOLUMES_BUFFER, MAX_VOLUMES * sizeof(VolumeData), - VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, STORAGE_BUFFER) - .addBuffer(RID_MATERIAL_BUFFER, MAX_MATERIALS * sizeof(MaterialData), - VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, STORAGE_BUFFER) .addBuffer(RID_MESH_METADATA_BUFFER, MAX_MESH_INSTANCES * sizeof(MeshMetadata), VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, STORAGE_BUFFER) .addTexture(RID_RAW_RENDERED_FRAME, gBufferW, gBufferH) diff --git a/src/context/editor/dock-spaces/viewport/ViewportPanel.cpp b/src/context/editor/dock-spaces/viewport/ViewportPanel.cpp index 41b09ad7..de05e660 100644 --- a/src/context/editor/dock-spaces/viewport/ViewportPanel.cpp +++ b/src/context/editor/dock-spaces/viewport/ViewportPanel.cpp @@ -6,18 +6,9 @@ #include "ViewportHeaderPanel.h" #include "EngineFramePanel.h" #include "../../../../context/ApplicationContext.h" -#include "../../../../service/descriptor/DescriptorInstance.h" -#include "../../../../service/framebuffer/FrameBufferInstance.h" #include "../../../../service/camera/Camera.h" #include "../../../../context/engine/frame-builder/EngineFrameBuilder.h" -#include "../../../../service/framebuffer/FrameBufferService.h" #include "../../../../enum/engine-definitions.h" -#include "../../../../dto/buffers/GlobalDataUBO.h" -#include "../../../../dto/buffers/TileInfoUBO.h" -#include "../../../../dto/buffers/LightData.h" -#include "../../../../dto/buffers/VolumeData.h" -#include "../../../../dto/buffers/MaterialData.h" - #include namespace Metal { diff --git a/src/context/editor/panel/FileImportModalPanel.cpp b/src/context/editor/panel/FileImportModalPanel.cpp index 170704ce..2e22bab1 100644 --- a/src/context/editor/panel/FileImportModalPanel.cpp +++ b/src/context/editor/panel/FileImportModalPanel.cpp @@ -13,14 +13,15 @@ namespace Metal { } void FileImportModalPanel::onSync() { - if (CTX.fileInspection.pendingImports.empty()) { + auto &editorRepository = CTX.editorRepository; + if (editorRepository.pendingImports.empty()) { isFirst = true; return; } if (isFirst) { formPanel->setInspection( - CTX.fileInspection.importSettingsMap.at(CTX.fileInspection.selectedFileForSettings).get()); + editorRepository.importSettingsMap.at(editorRepository.selectedFileForSettings).get()); isFirst = false; } @@ -32,7 +33,7 @@ namespace Metal { ImGui::SetNextWindowSizeConstraints(ImVec2(width, 400), ImVec2(width, maxHeight)); if (ImGui::Begin(("Import files?" + id + "importModal").c_str(), nullptr, - ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoDocking | ImGuiWindowFlags_NoMove)) { + ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoDocking | ImGuiWindowFlags_NoMove)) { if (ImGui::BeginTable((id + "ImportLayoutTable").c_str(), 2, ImGuiTableFlags_Resizable)) { ImGui::TableSetupColumn("FileList", ImGuiTableColumnFlags_WidthStretch, 0.4f); ImGui::TableSetupColumn("Settings", ImGuiTableColumnFlags_WidthStretch, 0.6f); @@ -49,16 +50,16 @@ namespace Metal { ImGui::TableSetupColumn("Size", ImGuiTableColumnFlags_WidthFixed, 80.0f); ImGui::TableHeadersRow(); - for (const auto &filePath: CTX.fileInspection.pendingImports) { + for (const auto &filePath: editorRepository.pendingImports) { std::filesystem::path p(filePath); ImGui::TableNextRow(); ImGui::TableNextColumn(); - bool isSelected = (CTX.fileInspection.selectedFileForSettings == filePath); + bool isSelected = (editorRepository.selectedFileForSettings == filePath); if (ImGui::Selectable(p.filename().string().c_str(), isSelected, ImGuiSelectableFlags_SpanAllColumns)) { - CTX.fileInspection.selectedFileForSettings = filePath; + editorRepository.selectedFileForSettings = filePath; formPanel->setInspection( - CTX.fileInspection.importSettingsMap.at(CTX.fileInspection.selectedFileForSettings). + editorRepository.importSettingsMap.at(editorRepository.selectedFileForSettings). get()); } ImGui::TableNextColumn(); @@ -75,7 +76,7 @@ namespace Metal { ImGui::TableNextColumn(); ImGui::Text("Settings: %s", - std::filesystem::path(CTX.fileInspection.selectedFileForSettings).filename().string(). + std::filesystem::path(editorRepository.selectedFileForSettings).filename().string(). c_str()); ImGui::BeginChild((id + "SettingsFormChild").c_str(), ImVec2(0, maxHeight - 180.0f), true); formPanel->onSync(); @@ -89,20 +90,20 @@ namespace Metal { ImGui::Spacing(); if (ImGui::Button(("Approve" + id + "approveImport").c_str(), ImVec2(120, 0))) { - for (const std::string &file: CTX.fileInspection.pendingImports) { - CTX.fileImporterService.importFile(CTX.fileInspection.targetImportDirectory->absolutePath, file, - CTX.fileInspection.importSettingsMap.at(file)); + for (const std::string &file: editorRepository.pendingImports) { + CTX.fileImporterService.importFile(editorRepository.targetImportDirectory->absolutePath, file, + editorRepository.importSettingsMap.at(file)); } CTX.notificationService.pushMessage("Importing files...", NotificationSeverities::WARNING); - FilesService::GetEntries(CTX.fileInspection.targetImportDirectory); - CTX.fileInspection.pendingImports.clear(); - CTX.fileInspection.importSettingsMap.clear(); + FilesService::GetEntries(editorRepository.targetImportDirectory); + editorRepository.pendingImports.clear(); + editorRepository.importSettingsMap.clear(); formPanel->resetForm(); } ImGui::SameLine(); if (ImGui::Button(("Cancel" + id + "cancel").c_str(), ImVec2(120, 0))) { - CTX.fileInspection.pendingImports.clear(); - CTX.fileInspection.importSettingsMap.clear(); + editorRepository.pendingImports.clear(); + editorRepository.importSettingsMap.clear(); formPanel->resetForm(); } } diff --git a/src/context/engine/EngineContext.cpp b/src/context/engine/EngineContext.cpp index 1f011c76..e34455aa 100644 --- a/src/context/engine/EngineContext.cpp +++ b/src/context/engine/EngineContext.cpp @@ -8,6 +8,9 @@ #include "../../service/camera/Camera.h" #include "../../service/framebuffer/FrameBufferInstance.h" #include "../../service/texture/TextureInstance.h" +#include "../../repository/world/components/AtmosphereComponent.h" +#include "../../repository/world/impl/EntityComponent.h" +#include "../../repository/world/components/TransformComponent.h" namespace Metal { void EngineContext::resetPathTracerAccumulationCount() const { @@ -18,33 +21,6 @@ namespace Metal { CTX.worldGridService.onSync(); } - void EngineContext::updateTileData() { - if (CTX.worldGridRepository.hasMainTileChanged) { - unsigned int i = 0; - std::vector bindings{}; - for (auto *tile: CTX.worldGridRepository.getLoadedTiles()) { - if (tile != nullptr) { - const auto *svo = CTX.streamingService.streamSVO(tile->id); - if (svo != nullptr) { - tileInfoUBO.tileCenterValid[i] = glm::vec4(tile->x, 0, - tile->z, 1); - tileInfoUBO.voxelBufferOffset[i] = svo->voxelBufferOffset; - i++; - } - } - } - - for (unsigned int j = i; j < 9; j++) { - tileInfoUBO.tileCenterValid[i].w = 0; - } - - if (i > 0) { - currentFrame->getResourceAs(RID_TILE_INFO)->update(tileInfoUBO.tileCenterValid.data()); - } - CTX.worldGridRepository.hasMainTileChanged = false; - } - } - void EngineContext::updateCurrentTime() { currentTime = Clock::now(); std::chrono::duration delta = currentTime - previousTime; @@ -77,7 +53,6 @@ namespace Metal { if (frame->getShouldRender()) { currentFrame = frame; - updateTileData(); if (updateLights || isFirstFrame) { CTX.lightService.onSync(); } @@ -112,7 +87,6 @@ namespace Metal { globalDataUBO.invProj = camera.invProjectionMatrix; globalDataUBO.invView = camera.invViewMatrix; globalDataUBO.cameraWorldPosition = camera.position; - globalDataUBO.volumeCount = CTX.volumeService.getCount(); globalDataUBO.lightsCount = CTX.lightService.getCount(); globalDataUBO.debugFlag = ShadingModes::IndexOfValue(CTX.editorRepository.shadingMode); CTX.engineRepository.pathTracerAccumulationCount++; @@ -122,14 +96,23 @@ namespace Metal { globalDataUBO.pathTracerMaxSamples = CTX.engineRepository.pathTracerMaxSamples; globalDataUBO.denoiserEnabled = CTX.engineRepository.denoiserEnabled && (globalDataUBO.debugFlag == LIT || globalDataUBO.debugFlag == LIGHTING_ONLY)? 1 : 0; - if (CTX.engineRepository.incrementTime) { - CTX.engineRepository.elapsedTime += .0005f * CTX.engineRepository.elapsedTimeSpeed; - setGISettingsUpdated(true); - updateLights = true; + entt::registry ® = CTX.worldRepository.registry; + auto view = reg.view(); + if (auto it = view.begin(); it != view.end()) { + auto &atmo = reg.get(*it); + atmosphereUBO.volumeScale = atmo.volumeScale; + atmosphereUBO.albedo = atmo.albedo; + atmosphereUBO.density = atmo.density; + atmosphereUBO.g = atmo.g; + atmosphereUBO.isAtmosphereEnabled = atmo.atmosphereEnabled ? 1 : 0; + atmosphereUBO.isVolumeEnabled = atmo.volumeEnabled ? 1 : 0; + atmosphereUBO.volumeShadowSteps = atmo.volumeShadowSteps; + atmosphereUBO.scatteringAlbedo = atmo.scatteringAlbedo; + atmosphereUBO.samples = atmo.samples; + atmosphereUBO.sunPosition = atmo.sunPosition; } - CTX.lightService.computeSunInfo(); - globalDataUBO.sunPosition = CTX.lightService.getSunPosition(); - globalDataUBO.sunColor = CTX.lightService.getSunColor(); + currentFrame->getResourceAs(RID_GLOBAL_DATA)->update(&globalDataUBO); + currentFrame->getResourceAs(RID_ATMOSPHERE_DATA)->update(&atmosphereUBO); } } diff --git a/src/context/engine/EngineContext.h b/src/context/engine/EngineContext.h index f9e63bcb..ecb2eaf9 100644 --- a/src/context/engine/EngineContext.h +++ b/src/context/engine/EngineContext.h @@ -6,6 +6,7 @@ #include #include "../../dto/buffers/GlobalDataUBO.h" +#include "../../dto/buffers/AtmosphereUBO.h" #include "../../common/AbstractRuntimeComponent.h" #include "../../dto/buffers/TileInfoUBO.h" @@ -15,7 +16,7 @@ using TimePoint = std::chrono::time_point; namespace Metal { class EngineContext final : public AbstractRuntimeComponent { GlobalDataUBO globalDataUBO{}; - TileInfoUBO tileInfoUBO{}; + AtmosphereUBO atmosphereUBO{}; long long start = -1; bool cameraUpdated = true; bool updateLights = true; @@ -62,8 +63,6 @@ namespace Metal { void onInitialize() override; - void updateTileData(); - void updateCurrentTime(); explicit EngineContext() : AbstractRuntimeComponent() { diff --git a/src/context/engine/compute-pass/impl/HWRayTracingPass.cpp b/src/context/engine/compute-pass/impl/HWRayTracingPass.cpp index 25055e11..739da1b7 100644 --- a/src/context/engine/compute-pass/impl/HWRayTracingPass.cpp +++ b/src/context/engine/compute-pass/impl/HWRayTracingPass.cpp @@ -7,6 +7,10 @@ #include "../../../../service/raytracing/RayTracingService.h" #include "../../../../enum/EngineResourceIDs.h" +#include "../../../../repository/world/components/PrimitiveComponent.h" +#include "../../../../repository/world/components/TransformComponent.h" +#include "../../../../repository/world/components/AtmosphereComponent.h" + namespace Metal { void HWRayTracingPass::onInitialize() { PipelineBuilder builder = PipelineBuilder::OfRayTracing( @@ -20,8 +24,7 @@ namespace Metal { .addStorageImageBinding(getScopedResourceId(RID_GBUFFER_POSITION_INDEX)) .addStorageImageBinding(getScopedResourceId(RID_GBUFFER_NORMAL)) .addBufferBinding(getScopedResourceId(RID_LIGHT_BUFFER)) - .addBufferBinding(getScopedResourceId(RID_VOLUMES_BUFFER)) - .addBufferBinding(getScopedResourceId(RID_MATERIAL_BUFFER)) + .addBufferBinding(getScopedResourceId(RID_ATMOSPHERE_DATA)) .addBufferBinding(getScopedResourceId(RID_MESH_METADATA_BUFFER)) .addCombinedImageSamplerBinding(CTX.vulkanContext.vkImageSampler, VK_NULL_HANDLE, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, 1000); @@ -30,9 +33,10 @@ namespace Metal { void HWRayTracingPass::onSync() { bool anyMeshes = false; - auto view = CTX.worldRepository.registry.view(); + entt::registry ® = CTX.worldRepository.registry; + auto view = reg.view(); for (auto entity: view) { - CTX.streamingService.streamMesh(view.get(entity).meshId); + CTX.streamingService.streamMesh(reg.get(entity).meshId); anyMeshes = true; } @@ -65,8 +69,6 @@ namespace Metal { // Trace rays pushConstant.pathTracerMultiplier = CTX.engineRepository.pathTracerMultiplier; - pushConstant.volumeShadowSteps = CTX.engineRepository.volumeShadowSteps; - pushConstant.isAtmosphereEnabled = CTX.engineRepository.atmosphereEnabled; pushConstant.multipleImportanceSampling = CTX.engineRepository.multipleImportanceSampling; pushConstant.pathTracerSamples = CTX.engineRepository.pathTracerSamples; diff --git a/src/context/engine/render-pass/impl/tools/SelectedDotPass.cpp b/src/context/engine/render-pass/impl/tools/SelectedDotPass.cpp index 267efdab..8451a465 100644 --- a/src/context/engine/render-pass/impl/tools/SelectedDotPass.cpp +++ b/src/context/engine/render-pass/impl/tools/SelectedDotPass.cpp @@ -34,11 +34,11 @@ namespace Metal { } const EntityID entityId = pair.first; const auto entity = static_cast(entityId); - if (!worldRepository.registry.all_of(entity) || !worldRepository.registry.all_of(entity)) { + if (!worldRepository.registry.all_of(entity) || !worldRepository.registry.all_of(entity)) { continue; } - const auto &mesh = worldRepository.registry.get(entity); + const auto &mesh = worldRepository.registry.get(entity); if (mesh.meshId.empty()) { continue; } diff --git a/src/dto/buffers/AtmosphereUBO.h b/src/dto/buffers/AtmosphereUBO.h new file mode 100644 index 00000000..76cba3a7 --- /dev/null +++ b/src/dto/buffers/AtmosphereUBO.h @@ -0,0 +1,21 @@ +#ifndef ATMOSPHEREUBO_H +#define ATMOSPHEREUBO_H + +#include + +namespace Metal { + struct AtmosphereUBO { + alignas(16) glm::vec3 albedo; + alignas(16) glm::vec3 volumeScale; + alignas(4) unsigned int isAtmosphereEnabled; + alignas(4) unsigned int isVolumeEnabled; + alignas(4) unsigned int volumeShadowSteps; + alignas(4) float density; + alignas(4) float g; + alignas(4) float scatteringAlbedo; + alignas(4) int samples; + alignas(16) glm::vec3 sunPosition{}; + }; +} + +#endif //ATMOSPHEREUBO_H diff --git a/src/dto/buffers/GlobalDataUBO.h b/src/dto/buffers/GlobalDataUBO.h index f56e6ca9..d79af7b3 100644 --- a/src/dto/buffers/GlobalDataUBO.h +++ b/src/dto/buffers/GlobalDataUBO.h @@ -9,19 +9,13 @@ namespace Metal { alignas(16) glm::mat4x4 projView{}; alignas(16) glm::mat4x4 invView{}; alignas(16) glm::mat4x4 invProj{}; - alignas(16) glm::mat4x4 previousProjView{}; alignas(16) glm::vec3 cameraWorldPosition{}; - alignas(16) glm::vec3 sunColor{}; - alignas(16) glm::vec3 sunPosition{}; alignas(8) glm::vec2 outputRes{}; - alignas(4) unsigned int volumeCount{}; alignas(4) unsigned int lightsCount{}; - alignas(4) unsigned int debugFlag; - alignas(4) unsigned int pathTracerAccumulationCount = 0; alignas(4) unsigned int globalFrameCount = 0; alignas(4) unsigned int pathTracerMaxSamples{}; diff --git a/src/dto/buffers/MaterialData.h b/src/dto/buffers/MaterialData.h deleted file mode 100644 index dc1c4769..00000000 --- a/src/dto/buffers/MaterialData.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef MATERIAL_DATA_H -#define MATERIAL_DATA_H -#include -#include -#include - -namespace Metal { - struct MaterialData final { - alignas(16) glm::vec3 albedo{}; - alignas(4) float roughness{}; - alignas(4) float metallic{}; - alignas(4) float transmission{}; - alignas(4) float thickness{}; - alignas(4) float ior{1.45f}; - alignas(4) unsigned int isEmissive{}; - - alignas(4) unsigned int useAlbedoTexture; - alignas(4) unsigned int useNormalTexture; - alignas(4) unsigned int useRoughnessTexture; - alignas(4) unsigned int useMetallicTexture; - - alignas(4) unsigned int albedoTextureId{}; - alignas(4) unsigned int normalTextureId{}; - alignas(4) unsigned int roughnessTextureId{}; - alignas(4) unsigned int metallicTextureId{}; - }; -} - -#endif //LIGHTDATA_H diff --git a/src/dto/buffers/MeshMetadata.h b/src/dto/buffers/MeshMetadata.h index dcbf9ddd..b2015c67 100644 --- a/src/dto/buffers/MeshMetadata.h +++ b/src/dto/buffers/MeshMetadata.h @@ -2,13 +2,31 @@ #define MESHMETADATA_H #include +#include namespace Metal { struct MeshMetadata { unsigned int renderIndex; - unsigned int materialIndex; uint64_t vertexBufferAddress; uint64_t indexBufferAddress; + + alignas(16) glm::vec3 albedo{}; + alignas(4) float roughness{}; + alignas(4) float metallic{}; + alignas(4) float transmission{}; + alignas(4) float thickness{}; + alignas(4) float ior{1.45f}; + alignas(4) unsigned int isEmissive{}; + + alignas(4) unsigned int useAlbedoTexture; + alignas(4) unsigned int useNormalTexture; + alignas(4) unsigned int useRoughnessTexture; + alignas(4) unsigned int useMetallicTexture; + + alignas(4) unsigned int albedoTextureId = 0; + alignas(4) unsigned int normalTextureId = 0; + alignas(4) unsigned int roughnessTextureId = 0; + alignas(4) unsigned int metallicTextureId = 0; }; } diff --git a/src/dto/push-constant/HWRayTracingPushConstant.h b/src/dto/push-constant/HWRayTracingPushConstant.h index 5cc92862..f7525d5d 100644 --- a/src/dto/push-constant/HWRayTracingPushConstant.h +++ b/src/dto/push-constant/HWRayTracingPushConstant.h @@ -4,8 +4,6 @@ namespace Metal { struct HWRayTracingPushConstant { alignas(4) float pathTracerMultiplier{}; - alignas(4) unsigned int volumeShadowSteps = 0; - alignas(4) unsigned int isAtmosphereEnabled{}; alignas(4) unsigned int multipleImportanceSampling{}; alignas(4) unsigned int pathTracerSamples{}; diff --git a/src/enum/ComponentType.h b/src/enum/ComponentType.h index d5b9850a..bfd794bd 100644 --- a/src/enum/ComponentType.h +++ b/src/enum/ComponentType.h @@ -4,18 +4,19 @@ namespace Metal::ComponentTypes { enum ComponentType { - MESH, + PRIMITIVE, TRANSFORM, SPHERE_LIGHT, PLANE_LIGHT, - VOLUME + VOLUME, + ATMOSPHERE }; - static constexpr const char *NAMES = "Add Entity\0Mesh\0Sphere Light\0Plane Light\0Volume\0"; + static constexpr const char *NAMES = "Add Entity\0Mesh\0Sphere Light\0Plane Light\0Volume\0Atmosphere\0"; static ComponentType ValueOfIndex(const int option) { if (option == 1) { - return MESH; + return PRIMITIVE; } if (option == 2) { return SPHERE_LIGHT; @@ -23,11 +24,14 @@ namespace Metal::ComponentTypes { if (option == 3) { return PLANE_LIGHT; } - return VOLUME; + if (option == 4) { + return VOLUME; + } + return ATMOSPHERE; } static const char *NameOf(const ComponentType mode) { - if (mode == MESH) + if (mode == PRIMITIVE) return "Mesh Component"; if (mode == TRANSFORM) return "Transformation Component"; @@ -37,11 +41,13 @@ namespace Metal::ComponentTypes { return "Plane Light Component"; if (mode == VOLUME) return "Volume Component"; + if (mode == ATMOSPHERE) + return "Atmosphere Component"; return nullptr; } static const char *IconOf(const ComponentType mode) { - if (mode == MESH) + if (mode == PRIMITIVE) return Icons::view_in_ar.c_str(); if (mode == TRANSFORM) return Icons::transform.c_str(); @@ -49,6 +55,8 @@ namespace Metal::ComponentTypes { return Icons::lightbulb.c_str(); if (mode == VOLUME) return Icons::blur_on.c_str(); + if (mode == ATMOSPHERE) + return Icons::cloud.c_str(); return nullptr; } } diff --git a/src/enum/EngineResourceIDs.h b/src/enum/EngineResourceIDs.h index ddfbacaa..e0a26f1e 100644 --- a/src/enum/EngineResourceIDs.h +++ b/src/enum/EngineResourceIDs.h @@ -3,10 +3,7 @@ namespace Metal { inline constexpr const char* RID_GLOBAL_DATA = "globalData"; - inline constexpr const char* RID_TILE_INFO = "tileInfo"; inline constexpr const char* RID_LIGHT_BUFFER = "lightBuffer"; - inline constexpr const char* RID_VOLUMES_BUFFER = "volumesBuffer"; - inline constexpr const char* RID_MATERIAL_BUFFER = "materialBuffer"; inline constexpr const char* RID_MESH_METADATA_BUFFER = "meshMetadataBuffer"; inline constexpr const char* RID_GBUFFER_POSITION_INDEX = "gBufferPositionIndex"; inline constexpr const char* RID_GBUFFER_NORMAL = "gBufferNormal"; @@ -21,6 +18,8 @@ namespace Metal { inline constexpr const char* RID_POST_PROCESSING_FBO = "postProcessingFBO"; inline constexpr const char* RID_COMPUTE_CB = "ComputeCB"; inline constexpr const char* RID_POST_PROCESSING_CB = "PostProcessingCB"; + inline constexpr const char* RID_ATMOSPHERE_DATA = "atmosphereData"; + inline constexpr const char* RID_VOLUMES_BUFFER = "volumesBuffer"; } #endif //ENGINE_RESOURCE_IDS_H diff --git a/src/enum/EntryType.h b/src/enum/EntryType.h index b1c63117..ea1790a7 100644 --- a/src/enum/EntryType.h +++ b/src/enum/EntryType.h @@ -8,11 +8,10 @@ namespace Metal::EntryType { TEXTURE, VOLUME, DIRECTORY, - MATERIAL, NONE }; - static const char *Names = "Scene\0Mesh\0Texture\0Volume\0Directory\0Material\0None\0"; + static const char *Names = "Scene\0Mesh\0Texture\0Volume\0Directory\0None\0"; static EntryType ValueOfIndex(const int option) { if (option == 0) { @@ -30,9 +29,6 @@ namespace Metal::EntryType { if (option == 4) { return EntryType::DIRECTORY; } - if (option == 5) { - return EntryType::MATERIAL; - } return EntryType::NONE; } @@ -52,9 +48,6 @@ namespace Metal::EntryType { if (mode == DIRECTORY) { return 4; } - if (mode == MATERIAL) { - return 5; - } if (mode == NONE) { return 6; } diff --git a/src/repository/editor/EditorRepository.h b/src/repository/editor/EditorRepository.h index 27c3a4bc..a11981f4 100644 --- a/src/repository/editor/EditorRepository.h +++ b/src/repository/editor/EditorRepository.h @@ -14,6 +14,8 @@ namespace Metal { struct TransformComponent; + struct FSEntry; + struct ImportSettingsDTO; struct EditorRepository final : Inspectable, Serializable { ImVec4 accent{}; @@ -50,6 +52,12 @@ namespace Metal { std::vector focusedShortcuts{}; ShadingMode shadingMode = LIT; + + std::vector pendingImports; + std::unordered_map > importSettingsMap; + std::string selectedFileForSettings; + FSEntry *targetImportDirectory = nullptr; + void registerFields() override; const char *getTitle() override; diff --git a/src/repository/engine/EngineRepository.cpp b/src/repository/engine/EngineRepository.cpp index c634beff..ec959140 100644 --- a/src/repository/engine/EngineRepository.cpp +++ b/src/repository/engine/EngineRepository.cpp @@ -7,7 +7,6 @@ #define PATH_TRACER "Path tracer" #define ATMOSPHERE "Atmosphere" #define SUN "Sun" -#define VOLUMES "Volumes" #define DEPTH_OF_FIELD "Depth of field" namespace Metal { @@ -18,7 +17,6 @@ namespace Metal { registerInt(numberOfTiles, "World", "Number of tiles", 2, 100); // registerInt(maxVideoFrames, "", "Max video frames", 1); - registerInt(volumeShadowSteps, VOLUMES, "Shadow steps", 1); registerFloat(pathTracerMultiplier, PATH_TRACER, "Strength"); registerBool(denoiserEnabled, PATH_TRACER, "Enable denoiser?"); @@ -29,28 +27,13 @@ namespace Metal { registerFloat(pathTracingEmissiveFactor, PATH_TRACER, "Emissive surface factor", 0); registerBool(dofEnabled, DEPTH_OF_FIELD, "Enable depth of field?"); - registerFloat(dofFocusDistance, DEPTH_OF_FIELD, "Focus distance"); - registerFloat(dofAperture, DEPTH_OF_FIELD, "Aperture"); - registerFloat(dofFocalLength, DEPTH_OF_FIELD, "Focal length"); - - registerBool(atmosphereEnabled, ATMOSPHERE, "Enable atmosphere?"); - registerFloat(elapsedTime, ATMOSPHERE, "Elapsed time"); - registerBool(incrementTime, ATMOSPHERE, "Increment time"); - registerFloat(elapsedTimeSpeed, ATMOSPHERE, "Time of day speed"); - registerFloat(sunDistance, ATMOSPHERE, "Sun distance"); - registerFloat(sunRadius, ATMOSPHERE, "Sun radius"); - registerFloat(sunLightIntensity, ATMOSPHERE, "Sun light intensity"); - registerColor(dawnColor, SUN, "Dawn color"); - registerColor(nightColor, SUN, "Night color"); - registerColor(middayColor, SUN, "Midday color"); } void EngineRepository::onUpdate(InspectableMember *member) { if (member != nullptr && member->name == LEVEL_OF_DETAIL) { CTX.worldGridRepository.hasMainTileChanged = true; } - if (member != nullptr && (member->group == PATH_TRACER || member->group == ATMOSPHERE || member->group - == SUN || member->group == DEPTH_OF_FIELD)) { + if (member != nullptr && (member->group == PATH_TRACER || member->group == DEPTH_OF_FIELD)) { CTX.engineContext.setGISettingsUpdated(true); CTX.engineContext.setUpdateLights(true); } @@ -62,22 +45,11 @@ namespace Metal { j["pathTracerSamples"] = pathTracerSamples; j["multipleImportanceSampling"] = multipleImportanceSampling; j["pathTracerBounces"] = pathTracerBounces; - j["atmosphereEnabled"] = atmosphereEnabled; - j["elapsedTime"] = elapsedTime; - j["incrementTime"] = incrementTime; - j["elapsedTimeSpeed"] = elapsedTimeSpeed; - j["sunRadius"] = sunRadius; - j["sunDistance"] = sunDistance; - j["sunLightIntensity"] = sunLightIntensity; - j["dawnColor"] = {dawnColor.x, dawnColor.y, dawnColor.z}; - j["nightColor"] = {nightColor.x, nightColor.y, nightColor.z}; - j["middayColor"] = {middayColor.x, middayColor.y, middayColor.z}; j["svoFilePaths"] = svoFilePaths; j["pathTracingEmissiveFactor"] = pathTracingEmissiveFactor; j["pathTracerMultiplier"] = pathTracerMultiplier; j["shadingResInvScale"] = shadingResInvScale; j["pathTracerMaxSamples"] = pathTracerMaxSamples; - j["volumeShadowSteps"] = volumeShadowSteps; j["denoiserEnabled"] = denoiserEnabled; j["dofEnabled"] = dofEnabled; j["dofFocusDistance"] = dofFocusDistance; @@ -91,23 +63,12 @@ namespace Metal { pathTracerSamples = j.at("pathTracerSamples").get(); multipleImportanceSampling = j.at("multipleImportanceSampling").get(); pathTracerBounces = j.at("pathTracerBounces").get(); - atmosphereEnabled = j.at("atmosphereEnabled").get(); - elapsedTime = j.at("elapsedTime").get(); - incrementTime = j.at("incrementTime").get(); - elapsedTimeSpeed = j.at("elapsedTimeSpeed").get(); - sunRadius = j.at("sunRadius").get(); - sunDistance = j.at("sunDistance").get(); - sunLightIntensity = j.at("sunLightIntensity").get(); - dawnColor = {j.at("dawnColor")[0], j.at("dawnColor")[1], j.at("dawnColor")[2]}; - nightColor = {j.at("nightColor")[0], j.at("nightColor")[1], j.at("nightColor")[2]}; - middayColor = {j.at("middayColor")[0], j.at("middayColor")[1], j.at("middayColor")[2]}; svoFilePaths = j.at("svoFilePaths").get >(); pathTracingEmissiveFactor = j.at("pathTracingEmissiveFactor").get(); pathTracerMultiplier = j.at("pathTracerMultiplier").get(); shadingResInvScale = j.at("shadingResInvScale").get(); pathTracerMaxSamples = j.at("pathTracerMaxSamples").get(); denoiserEnabled = j.at("denoiserEnabled").get(); - volumeShadowSteps = j.at("volumeShadowSteps").get(); dofEnabled = j.at("dofEnabled").get(); dofFocusDistance = j.at("dofFocusDistance").get(); dofAperture = j.at("dofAperture").get(); diff --git a/src/repository/engine/EngineRepository.h b/src/repository/engine/EngineRepository.h index e671bd1f..1bf56141 100644 --- a/src/repository/engine/EngineRepository.h +++ b/src/repository/engine/EngineRepository.h @@ -17,7 +17,6 @@ namespace Metal { bool multipleImportanceSampling = false; int maxVideoFrames = 100; - int volumeShadowSteps = 8; int shadingResInvScale = 2; int pathTracerMaxSamples = 200; float pathTracingEmissiveFactor = 2; @@ -26,16 +25,6 @@ namespace Metal { int pathTracerAccumulationCount = 0; float pathTracerMultiplier = 1; int numberOfTiles = 10; - float elapsedTime = .5f; - bool atmosphereEnabled = false; - bool incrementTime = false; - float elapsedTimeSpeed = 1; - float sunDistance = 10000; - float sunRadius = 3000; - float sunLightIntensity = 2; - glm::vec3 dawnColor{1, .39f, .19f}; - glm::vec3 nightColor{.1f, .1f, .1f}; - glm::vec3 middayColor{.9f, .9f, .9f}; std::vector svoFilePaths{}; void registerFields() override; diff --git a/src/repository/inspection/FilesRepository.cpp b/src/repository/inspection/FilesRepository.cpp deleted file mode 100644 index 8667cf4e..00000000 --- a/src/repository/inspection/FilesRepository.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include "FilesRepository.h" - -#include "../../common/interface/Icons.h" - -namespace Metal { - void FilesRepository::registerFields() { - registerResourceSelection(materialId, "", "Material", EntryType::MATERIAL, false); - } - - const char * FilesRepository::getIcon() { - return Icons::file_open.c_str(); - } - - const char * FilesRepository::getTitle() { - return "File Inspection"; - } -} // Metal diff --git a/src/repository/inspection/FilesRepository.h b/src/repository/inspection/FilesRepository.h deleted file mode 100644 index 49aa5e05..00000000 --- a/src/repository/inspection/FilesRepository.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef FILEINSPECTIONREPOSITORY_H -#define FILEINSPECTIONREPOSITORY_H -#include - -#include "../../common/inspection/Inspectable.h" - -namespace Metal { - struct FSEntry; - struct ImportSettingsDTO; - - struct FilesRepository final : Inspectable { - std::string materialId; - - std::vector pendingImports; - std::unordered_map > importSettingsMap; - std::string selectedFileForSettings; - FSEntry *targetImportDirectory = nullptr; - - void registerFields() override; - - const char *getIcon() override; - - const char *getTitle() override; - }; -} // Metal - -#endif //FILEINSPECTIONREPOSITORY_H diff --git a/src/repository/streaming/StreamingService.cpp b/src/repository/streaming/StreamingService.cpp index 4bab32e5..91208c74 100644 --- a/src/repository/streaming/StreamingService.cpp +++ b/src/repository/streaming/StreamingService.cpp @@ -4,9 +4,6 @@ #include "../../service/voxel/SVOInstance.h" #include "../../service/mesh/MeshInstance.h" #include "../../service/texture/TextureInstance.h" -#include -#include "../../repository/abstract/RuntimeResource.h" -#include "../../service/material/MaterialInstance.h" namespace Metal { static constexpr int MAX_TIMEOUT = 10000; @@ -41,10 +38,6 @@ namespace Metal { return nullptr; } - MaterialInstance *StreamingService::streamMaterial(const std::string &id) { - return stream(CTX.materialService, id, lastUse, tries); - } - SVOInstance *StreamingService::streamSVO(const std::string &id) { return stream(CTX.voxelService, id, lastUse, tries); } @@ -81,7 +74,6 @@ namespace Metal { disposeResources(CTX.meshService, lastUse); disposeResources(CTX.textureService, lastUse); disposeResources(CTX.voxelService, lastUse); - disposeResources(CTX.materialService, lastUse); } } } diff --git a/src/repository/streaming/StreamingService.h b/src/repository/streaming/StreamingService.h index f6636d64..e82f89b8 100644 --- a/src/repository/streaming/StreamingService.h +++ b/src/repository/streaming/StreamingService.h @@ -6,21 +6,15 @@ #include "../../service/abstract/AbstractResourceService.h" #include "../abstract/AbstractCoreRepository.h" -#include "../../service/abstract/IStreamable.h" #include "../abstract/RuntimeResource.h" - -namespace Metal { - struct SVOInstance; -} - using Clock = std::chrono::high_resolution_clock; using TimePoint = std::chrono::time_point; namespace Metal { struct MeshInstance; struct TextureInstance; - struct MaterialInstance; + struct SVOInstance; class StreamingService final : public AbstractRuntimeComponent { std::unordered_map tries{}; @@ -30,8 +24,6 @@ namespace Metal { public: MeshInstance *streamMesh(const std::string &id); - MaterialInstance *streamMaterial(const std::string &id); - SVOInstance *streamSVO(const std::string &id); TextureInstance *streamTexture(const std::string &id); diff --git a/src/repository/world/WorldRepository.cpp b/src/repository/world/WorldRepository.cpp index 4f915675..740600ea 100644 --- a/src/repository/world/WorldRepository.cpp +++ b/src/repository/world/WorldRepository.cpp @@ -58,27 +58,6 @@ namespace Metal { return nullptr; } - Inspectable *WorldRepository::getComponent(ComponentTypes::ComponentType comp, EntityID entityId) { - const auto entity = static_cast(entityId); - if (!registry.valid(entity)) return nullptr; - - switch (comp) { - case ComponentTypes::MESH: - return registry.all_of(entity) ? ®istry.get(entity) : nullptr; - case ComponentTypes::TRANSFORM: - return registry.all_of(entity) ? ®istry.get(entity) : nullptr; - case ComponentTypes::SPHERE_LIGHT: - case ComponentTypes::PLANE_LIGHT: - return registry.all_of>(entity) - ? registry.get>(entity).get() - : nullptr; - case ComponentTypes::VOLUME: - return registry.all_of(entity) ? ®istry.get(entity) : nullptr; - default: - return nullptr; - } - } - void WorldRepository::deleteRecursively(const std::vector &entities) { for (EntityID entityId: entities) { const auto entity = static_cast(entityId); @@ -148,8 +127,8 @@ namespace Metal { return; } switch (type) { - case ComponentTypes::MESH: { - auto &mesh = registry.emplace_or_replace(entity); + case ComponentTypes::PRIMITIVE: { + auto &mesh = registry.emplace_or_replace(entity); mesh.setEntityId(entityId); createComponent(entityId, ComponentTypes::TRANSFORM); CTX.rayTracingService.markDirty(); @@ -187,6 +166,12 @@ namespace Metal { } break; } + case ComponentTypes::ATMOSPHERE: { + auto &atmo = registry.emplace_or_replace(entity); + atmo.setEntityId(entityId); + CTX.engineContext.setGISettingsUpdated(true); + break; + } default: break; } @@ -208,8 +193,8 @@ namespace Metal { auto &h = registry.get(entity); ej["hierarchy"] = {{"parent", h.parent}, {"children", h.children}}; } - if (registry.all_of(entity)) { - ej["mesh"] = registry.get(entity).toJson(); + if (registry.all_of(entity)) { + ej["mesh"] = registry.get(entity).toJson(); } if (registry.all_of(entity)) { ej["transform"] = registry.get(entity).toJson(); @@ -220,6 +205,9 @@ namespace Metal { if (registry.all_of(entity)) { ej["volume"] = registry.get(entity).toJson(); } + if (registry.all_of(entity)) { + ej["atmosphere"] = registry.get(entity).toJson(); + } entitiesJson[std::to_string(id)] = ej; } j["registry"] = entitiesJson; @@ -245,7 +233,7 @@ namespace Metal { h.children = val.at("hierarchy").at("children").get>(); } if (val.contains("mesh")) { - registry.emplace(entity).fromJson(val.at("mesh")); + registry.emplace(entity).fromJson(val.at("mesh")); } if (val.contains("transform")) { registry.emplace(entity).fromJson(val.at("transform")); @@ -266,6 +254,9 @@ namespace Metal { if (val.contains("volume")) { registry.emplace(entity).fromJson(val.at("volume")); } + if (val.contains("atmosphere")) { + registry.emplace(entity).fromJson(val.at("atmosphere")); + } } } diff --git a/src/repository/world/WorldRepository.h b/src/repository/world/WorldRepository.h index 06ab9599..6ffffa3d 100644 --- a/src/repository/world/WorldRepository.h +++ b/src/repository/world/WorldRepository.h @@ -13,11 +13,12 @@ #include "impl/EntityComponent.h" #include "../../enum/ComponentType.h" #include "components/LightComponent.h" -#include "components/MeshComponent.h" +#include "components/PrimitiveComponent.h" #include "components/SphereLightComponent.h" #include "components/PlaneLightComponent.h" #include "components/TransformComponent.h" #include "components/VolumeComponent.h" +#include "components/AtmosphereComponent.h" namespace Metal { class Inspectable; @@ -40,9 +41,6 @@ namespace Metal { [[nodiscard]] EntityComponent *getEntity(EntityID node); - Inspectable *getComponent(ComponentTypes::ComponentType comp, EntityID entity); - - void deleteEntities(const std::vector &entities); void changeVisibility(EntityID entity, bool isVisible); diff --git a/src/repository/world/components/AtmosphereComponent.cpp b/src/repository/world/components/AtmosphereComponent.cpp new file mode 100644 index 00000000..6515ef03 --- /dev/null +++ b/src/repository/world/components/AtmosphereComponent.cpp @@ -0,0 +1,108 @@ +#include "AtmosphereComponent.h" +#include "../../../context/ApplicationContext.h" + +namespace Metal { + glm::vec3 BlendColors(glm::vec3 &c1, glm::vec3 &c2, float t) { + return { + (c1.x * (1 - t) + c2.x * t), + (c1.y * (1 - t) + c2.y * t), + (c1.z * (1 - t) + c2.z * t) + }; + } + + glm::vec3 CalculateSunColor(const float elevation, glm::vec3 &nightColor, glm::vec3 &dawnColor, + glm::vec3 &middayColor) { + if (elevation <= -0.1f) { + return nightColor; + } + if (elevation <= 0.0f) { + float t = (elevation + 0.1f) / 0.1f; + return BlendColors(nightColor, dawnColor, t); + } + if (elevation <= 0.5f) { + float t = elevation / 0.5f; + return BlendColors(dawnColor, middayColor, t); + } + return middayColor; + } + + + void AtmosphereComponent::registerFields() { + registerBool(volumeEnabled, "Volume", "Enable volume scattering?"); + registerColor(albedo, "Volume", "Albedo"); + registerFloat(density, "Volume", "Density", .1, 10); + registerFloat(g, "Volume", "Phase function asymmetry (0.0 for isotropic)", 0); + registerFloat(scatteringAlbedo, "Volume", "Scattering albedo", 0); + registerInt(samples, "Volume", "Samples", 1); + registerInt(volumeShadowSteps, "Volume", "Shadow steps", 1); + + registerBool(atmosphereEnabled, "Atmosphere", "Enable atmosphere?"); + registerFloat(elapsedTime, "Atmosphere", "Elapsed time"); + registerFloat(sunDistance, "Atmosphere", "Sun distance"); + registerFloat(sunRadius, "Atmosphere", "Sun radius"); + registerFloat(sunLightIntensity, "Atmosphere", "Sun light intensity"); + registerColor(dawnColor, "Sun", "Dawn color"); + registerColor(nightColor, "Sun", "Night color"); + registerColor(middayColor, "Sun", "Midday color"); + } + + ComponentTypes::ComponentType AtmosphereComponent::getType() { + return ComponentTypes::ATMOSPHERE; + } + + void AtmosphereComponent::onUpdate(InspectableMember *member) { + CTX.engineContext.setGISettingsUpdated(true); + CTX.engineContext.setUpdateLights(true); + CTX.engineContext.setUpdateVolumes(true); + + sunPosition = glm::vec3(0, + std::cos(elapsedTime), + std::sin(elapsedTime)) * sunDistance; + sunColor = CalculateSunColor( + sunPosition.y / sunDistance, + nightColor, dawnColor, + middayColor); + } + + nlohmann::json AtmosphereComponent::toJson() const { + nlohmann::json j; + j["entityId"] = entityId; + j["albedo"] = {albedo.x, albedo.y, albedo.z}; + j["density"] = density; + j["g"] = g; + j["scatteringAlbedo"] = scatteringAlbedo; + j["samples"] = samples; + j["sunDistance"] = sunDistance; + j["sunRadius"] = sunRadius; + j["sunLightIntensity"] = sunLightIntensity; + j["elapsedTime"] = elapsedTime; + j["atmosphereEnabled"] = atmosphereEnabled; + j["volumeShadowSteps"] = volumeShadowSteps; + j["volumeEnabled"] = volumeEnabled; + j["dawnColor"] = {dawnColor.x, dawnColor.y, dawnColor.z}; + j["nightColor"] = {nightColor.x, nightColor.y, nightColor.z}; + j["middayColor"] = {middayColor.x, middayColor.y, middayColor.z}; + j["volumeScale"] = {volumeScale.x, volumeScale.y, volumeScale.z}; + return j; + } + + void AtmosphereComponent::fromJson(const nlohmann::json &j) { + entityId = j.at("entityId").get(); + albedo = {j.at("albedo")[0], j.at("albedo")[1], j.at("albedo")[2]}; + density = j.at("density").get(); + g = j.at("g").get(); + scatteringAlbedo = j.at("scatteringAlbedo").get(); + samples = j.at("samples").get(); + volumeShadowSteps = j.at("volumeShadowSteps").get(); + sunDistance = j.at("sunDistance").get(); + sunRadius = j.at("sunRadius").get(); + sunLightIntensity = j.at("sunLightIntensity").get(); + elapsedTime = j.at("elapsedTime").get(); + atmosphereEnabled = j.at("atmosphereEnabled").get(); + volumeEnabled = j.at("volumeEnabled").get(); + dawnColor = {j.at("dawnColor")[0], j.at("dawnColor")[1], j.at("dawnColor")[2]}; + nightColor = {j.at("nightColor")[0], j.at("nightColor")[1], j.at("nightColor")[2]}; + middayColor = {j.at("middayColor")[0], j.at("middayColor")[1], j.at("middayColor")[2]}; + volumeScale = {j.at("volumeScale")[0], j.at("volumeScale")[1], j.at("volumeScale")[2]}; + } +} // Metal diff --git a/src/repository/world/components/AtmosphereComponent.h b/src/repository/world/components/AtmosphereComponent.h new file mode 100644 index 00000000..f5c58568 --- /dev/null +++ b/src/repository/world/components/AtmosphereComponent.h @@ -0,0 +1,45 @@ +#ifndef ATMOSPHERECOMPONENT_H +#define ATMOSPHERECOMPONENT_H + +#include "../impl/AbstractComponent.h" +#include "../../../util/Serializable.h" +#include + +namespace Metal { + struct AtmosphereComponent final : AbstractComponent, Serializable { + glm::vec3 albedo = glm::vec3(1.0f); + glm::vec3 volumeScale = glm::vec3(100.f); + float density = 1; + float g = 0; + float scatteringAlbedo = 5; + int samples = 64; + int volumeShadowSteps = 8; + + float sunDistance = 10000; + float sunRadius = 3000; + float sunLightIntensity = 2; + float elapsedTime = .5f; + bool atmosphereEnabled = false; + bool volumeEnabled = false; + + glm::vec3 dawnColor{1, .39f, .19f}; + glm::vec3 nightColor{.1f, .1f, .1f}; + glm::vec3 middayColor{.9f, .9f, .9f}; + + + glm::vec3 sunColor{}; + glm::vec3 sunPosition{}; + + void registerFields() override; + + ComponentTypes::ComponentType getType() override; + + void onUpdate(InspectableMember *member) override; + + nlohmann::json toJson() const override; + + void fromJson(const nlohmann::json& j) override; + }; +} // Metal + +#endif //ATMOSPHERECOMPONENT_H diff --git a/src/repository/world/components/MeshComponent.cpp b/src/repository/world/components/MeshComponent.cpp deleted file mode 100644 index ca6935e6..00000000 --- a/src/repository/world/components/MeshComponent.cpp +++ /dev/null @@ -1,43 +0,0 @@ -#include "MeshComponent.h" -#include "../../../context/ApplicationContext.h" -#include "../../../enum/EntryType.h" -#include "../../../service/mesh/MeshData.h" - -namespace Metal { - void MeshComponent::registerFields() { - registerResourceSelection(meshId, "", "Mesh", EntryType::MESH); - registerResourceSelection(materialId, "", "Material", EntryType::MATERIAL); - } - - void MeshComponent::onUpdate(InspectableMember *member) { - if (member != nullptr && member->name == "meshId") { - MeshData *data = CTX.meshService.stream(meshId); - if (data != nullptr) { - const auto e = static_cast(entityId); - if (CTX.worldRepository.registry.all_of(e)) { - CTX.worldRepository.registry.get(e).gizmoCenter = data->gizmoCenter; - } - delete data; - } - } - CTX.engineContext.setGISettingsUpdated(true); - } - - ComponentTypes::ComponentType MeshComponent::getType() { - return ComponentTypes::MESH; - } - - nlohmann::json MeshComponent::toJson() const { - nlohmann::json j; - j["entityId"] = entityId; - j["meshId"] = meshId; - j["materialId"] = materialId; - return j; - } - - void MeshComponent::fromJson(const nlohmann::json &j) { - entityId = j.at("entityId").get(); - meshId = j.at("meshId").get(); - materialId = j.at("materialId").get(); - } -} diff --git a/src/repository/world/components/MeshComponent.h b/src/repository/world/components/MeshComponent.h deleted file mode 100644 index 7e81347f..00000000 --- a/src/repository/world/components/MeshComponent.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef MESHCOMPONENT_H -#define MESHCOMPONENT_H - -#include "../impl/AbstractComponent.h" -#include "../../../util/Serializable.h" -#include - -namespace Metal { - struct MeshComponent final : AbstractComponent, Serializable { - std::string meshId; - std::string materialId; - - unsigned int renderIndex = 0; - - void registerFields() override; - - void onUpdate(InspectableMember *member) override; - - ComponentTypes::ComponentType getType() override; - - nlohmann::json toJson() const override; - - void fromJson(const nlohmann::json& j) override; - }; -} -#endif //MESHCOMPONENT_H diff --git a/src/repository/world/components/PrimitiveComponent.cpp b/src/repository/world/components/PrimitiveComponent.cpp new file mode 100644 index 00000000..066f31a4 --- /dev/null +++ b/src/repository/world/components/PrimitiveComponent.cpp @@ -0,0 +1,76 @@ +#include "PrimitiveComponent.h" +#include "../../../context/ApplicationContext.h" +#include "../../../enum/EntryType.h" +#include "../../../service/mesh/MeshData.h" + +namespace Metal { + void PrimitiveComponent::registerFields() { + registerResourceSelection(meshId, "", "Mesh", EntryType::MESH); + registerColor(albedoColor, "Material", "Albedo color"); + registerBool(isEmissive, "Material", "Is Emissive?"); + registerFloat(roughnessFactor, "Material", "Roughness factor", 0, 1); + registerFloat(metallicFactor, "Material", "Metallic factor", 0, 1); + registerFloat(transmissionFactor, "Material", "Transmission factor", 0, 1); + registerFloat(thicknessFactor, "Material", "Thickness factor", 0, 10); + registerFloat(ior, "Material", "IOR", 1, 3); + registerResourceSelection(albedo, "Material", "Albedo", EntryType::TEXTURE); + registerResourceSelection(normal, "Material", "Normal", EntryType::TEXTURE); + registerResourceSelection(roughness, "Material", "Roughness texture", EntryType::TEXTURE); + registerResourceSelection(metallic, "Material", "Metallic Texture", EntryType::TEXTURE); + } + + void PrimitiveComponent::onUpdate(InspectableMember *member) { + if (member != nullptr && member->name == "meshId") { + MeshData *data = CTX.meshService.stream(meshId); + if (data != nullptr) { + const auto e = static_cast(entityId); + if (CTX.worldRepository.registry.all_of(e)) { + CTX.worldRepository.registry.get(e).gizmoCenter = data->gizmoCenter; + } + delete data; + } + } + CTX.engineContext.setGISettingsUpdated(true); + CTX.rayTracingService.setNeedsMaterialUpdate(true); + } + + ComponentTypes::ComponentType PrimitiveComponent::getType() { + return ComponentTypes::PRIMITIVE; + } + + nlohmann::json PrimitiveComponent::toJson() const { + nlohmann::json j; + j["entityId"] = entityId; + j["meshId"] = meshId; + j["albedo"] = albedo; + j["normal"] = normal; + j["roughness"] = roughness; + j["metallic"] = metallic; + j["albedoColor"] = {albedoColor.x, albedoColor.y, albedoColor.z}; + j["roughnessFactor"] = roughnessFactor; + j["metallicFactor"] = metallicFactor; + j["transmissionFactor"] = transmissionFactor; + j["thicknessFactor"] = thicknessFactor; + j["ior"] = ior; + j["isEmissive"] = isEmissive; + return j; + } + + void PrimitiveComponent::fromJson(const nlohmann::json &j) { + entityId = j.at("entityId").get(); + meshId = j.at("meshId").get(); + + albedo = j.at("albedo").get(); + normal = j.at("normal").get(); + roughness = j.at("roughness").get(); + metallic = j.at("metallic").get(); + roughnessFactor = j.at("roughnessFactor").get(); + metallicFactor = j.at("metallicFactor").get(); + transmissionFactor = j.value("transmissionFactor", 0.0f); + thicknessFactor = j.value("thicknessFactor", 0.0f); + ior = j.value("ior", 1.45f); + isEmissive = j.at("isEmissive").get(); + + albedoColor = {j.at("albedoColor")[0], j.at("albedoColor")[1], j.at("albedoColor")[2]}; + } +} diff --git a/src/service/material/MaterialFileData.h b/src/repository/world/components/PrimitiveComponent.h similarity index 51% rename from src/service/material/MaterialFileData.h rename to src/repository/world/components/PrimitiveComponent.h index 9635b75c..9b37deff 100644 --- a/src/service/material/MaterialFileData.h +++ b/src/repository/world/components/PrimitiveComponent.h @@ -1,13 +1,14 @@ -#ifndef MATERIAL_FILE_DATA_H -#define MATERIAL_FILE_DATA_H -#include +#ifndef PRIMITIVE_COMPONENT_H +#define PRIMITIVE_COMPONENT_H -#include "../../common/inspection/Inspectable.h" -#include "../../util/Serializable.h" +#include "../impl/AbstractComponent.h" +#include "../../../util/Serializable.h" #include namespace Metal { - struct MaterialFileData final : Inspectable, Serializable { + struct PrimitiveComponent final : AbstractComponent, Serializable { + std::string meshId; + std::string albedo; std::string normal; std::string roughness; @@ -20,16 +21,17 @@ namespace Metal { float ior = 1.45; bool isEmissive = false; + unsigned int renderIndex = 0; + void registerFields() override; - const char *getIcon() override; + void onUpdate(InspectableMember *member) override; - const char *getTitle() override; + ComponentTypes::ComponentType getType() override; nlohmann::json toJson() const override; - void fromJson(const nlohmann::json &j) override; + void fromJson(const nlohmann::json& j) override; }; } - -#endif //MATERIALDATA_H +#endif //MESHCOMPONENT_H diff --git a/src/repository/world/components/VolumeComponent.cpp b/src/repository/world/components/VolumeComponent.cpp index ded620c7..4da49603 100644 --- a/src/repository/world/components/VolumeComponent.cpp +++ b/src/repository/world/components/VolumeComponent.cpp @@ -3,11 +3,6 @@ namespace Metal { void VolumeComponent::registerFields() { - registerColor(albedo, "", "Albedo"); - registerFloat(density, "", "Density", .1, 10); - registerFloat(g, "", "Phase function asymmetry (0.0 for isotropic)", 0); - registerFloat(scatteringAlbedo, "", "Scattering albedo", 0); - registerInt(samples, "", "Samples", 1); } ComponentTypes::ComponentType VolumeComponent::getType() { diff --git a/src/repository/world/components/VolumeComponent.h b/src/repository/world/components/VolumeComponent.h index 88696b55..b62839fd 100644 --- a/src/repository/world/components/VolumeComponent.h +++ b/src/repository/world/components/VolumeComponent.h @@ -6,12 +6,8 @@ #include namespace Metal { + // TODO - (VDB) SVO BASED VOLUMES struct VolumeComponent final : AbstractComponent, Serializable { - glm::vec3 albedo = glm::vec3(1.0f); - float density = 1; - float g = 0; - float scatteringAlbedo = 5; - int samples = 64; void registerFields() override; @@ -22,21 +18,11 @@ namespace Metal { nlohmann::json toJson() const override { nlohmann::json j; j["entityId"] = entityId; - j["albedo"] = {albedo.x, albedo.y, albedo.z}; - j["density"] = density; - j["g"] = g; - j["scatteringAlbedo"] = scatteringAlbedo; - j["samples"] = samples; return j; } void fromJson(const nlohmann::json& j) override { entityId = j.at("entityId").get(); - albedo = {j.at("albedo")[0], j.at("albedo")[1], j.at("albedo")[2]}; - density = j.at("density").get(); - g = j.at("g").get(); - scatteringAlbedo = j.at("scatteringAlbedo").get(); - samples = j.at("samples").get(); } }; } // Metal diff --git a/src/service/files/FilesService.cpp b/src/service/files/FilesService.cpp index 7cd0b086..9d6af371 100644 --- a/src/service/files/FilesService.cpp +++ b/src/service/files/FilesService.cpp @@ -81,10 +81,6 @@ namespace Metal { DELETE_S(FORMAT_FILE_SCENE) break; } - case EntryType::MATERIAL: { - DELETE_S(FORMAT_FILE_MATERIAL) - break; - } case EntryType::VOLUME: { DELETE_S(FORMAT_FILE_VOLUME) break; @@ -94,22 +90,6 @@ namespace Metal { } } - void FilesService::createMaterial(const std::string &targetDir, FSEntry *currentDirectory) const { - EntryMetadata materialMetadata{}; - materialMetadata.type = EntryType::MATERIAL; - int count = 0; - for (FSEntry *child: currentDirectory->children) { - if (child->type == EntryType::MATERIAL && child->name == "New Material (" + std::to_string(count) + ")") { - count++; - } - } - materialMetadata.name = "New Material (" + std::to_string(count+1) + ")"; - - DUMP_TEMPLATE(targetDir + '/' + FORMAT_FILE_METADATA(materialMetadata.getId()), materialMetadata) - MaterialFileData data{}; - DUMP_TEMPLATE(CTX.getAssetDirectory() + FORMAT_FILE_MATERIAL(materialMetadata.getId()), data) - } - void FilesService::CreateDirectory(FSEntry *currentDirectory) { int count = 0; for (FSEntry *child: currentDirectory->children) { diff --git a/src/service/files/FilesService.h b/src/service/files/FilesService.h index 06eb19e3..c2906941 100644 --- a/src/service/files/FilesService.h +++ b/src/service/files/FilesService.h @@ -27,8 +27,6 @@ namespace Metal { void deleteFiles(const std::unordered_map &files_context); - void createMaterial(const std::string &targetDir, FSEntry *currentDirectory) const; - void Move(FSEntry *toMove, FSEntry *targetDir); static void CreateDirectory(FSEntry *currentDirectory); diff --git a/src/service/lights/LightService.cpp b/src/service/lights/LightService.cpp index 56f6449b..8a26f964 100644 --- a/src/service/lights/LightService.cpp +++ b/src/service/lights/LightService.cpp @@ -5,6 +5,8 @@ #include "../buffer/BufferInstance.h" #include "../../enum/EngineResourceIDs.h" +#include "../../repository/world/components/AtmosphereComponent.h" + namespace Metal { void LightService::registerLights() { auto view = CTX.worldRepository.registry.view, TransformComponent>(); @@ -36,14 +38,18 @@ namespace Metal { } void LightService::registerSun() { - if (CTX.engineRepository.atmosphereEnabled) { - items.push_back(LightData( - glm::vec4(sunColor, CTX.engineRepository.sunLightIntensity), - sunPosition, - glm::vec3(0), - glm::vec3(CTX.engineRepository.sunRadius), - LightTypes::SPHERE - )); + auto view = CTX.worldRepository.registry.view(); + if (auto it = view.begin(); it != view.end()) { + auto &atmo = CTX.worldRepository.registry.get(*it); + if (atmo.atmosphereEnabled) { + items.push_back(LightData( + glm::vec4(atmo.sunColor, atmo.sunLightIntensity), + atmo.sunPosition, + glm::vec3(0), + glm::vec3(atmo.sunRadius), + LightTypes::SPHERE + )); + } } } @@ -57,40 +63,4 @@ namespace Metal { CTX.engineContext.currentFrame->getResourceAs(RID_LIGHT_BUFFER)->update(items.data()); } } - - - void LightService::computeSunInfo() { - sunPosition = glm::vec3(0, - std::cos(CTX.engineRepository.elapsedTime), - std::sin(CTX.engineRepository.elapsedTime)) * CTX.engineRepository - .sunDistance; - sunColor = LightService::CalculateSunColor( - sunPosition.y / CTX.engineRepository.sunDistance, - CTX.engineRepository.nightColor, CTX.engineRepository.dawnColor, - CTX.engineRepository.middayColor); - } - - glm::vec3 LightService::CalculateSunColor(const float elevation, glm::vec3 &nightColor, glm::vec3 &dawnColor, - glm::vec3 &middayColor) { - if (elevation <= -0.1f) { - return nightColor; - } - if (elevation <= 0.0f) { - float t = (elevation + 0.1f) / 0.1f; - return BlendColors(nightColor, dawnColor, t); - } - if (elevation <= 0.5f) { - float t = elevation / 0.5f; - return BlendColors(dawnColor, middayColor, t); - } - return middayColor; - } - - glm::vec3 LightService::BlendColors(glm::vec3 &c1, glm::vec3 &c2, float t) { - return { - (c1.x * (1 - t) + c2.x * t), - (c1.y * (1 - t) + c2.y * t), - (c1.z * (1 - t) + c2.z * t) - }; - } } // Metal diff --git a/src/service/lights/LightService.h b/src/service/lights/LightService.h index 2b806bd4..fb6de0d6 100644 --- a/src/service/lights/LightService.h +++ b/src/service/lights/LightService.h @@ -8,35 +8,14 @@ namespace Metal { class LightService final : public AbstractRuntimeComponent { std::vector items{}; - glm::vec3 sunColor{}; - glm::vec3 sunPosition{}; void registerLights(); void registerSun(); - static glm::vec3 CalculateSunColor(float elevation, glm::vec3 &nightColor, glm::vec3 &dawnColor, - glm::vec3 &middayColor); - - static glm::vec3 BlendColors(glm::vec3 &c1, glm::vec3 &c2, float t); - public: - explicit LightService() - : AbstractRuntimeComponent() { - } - void onSync() override; - void computeSunInfo(); - - [[nodiscard]] glm::vec3 getSunPosition() const { - return sunPosition; - } - - [[nodiscard]] glm::vec3 getSunColor() const { - return sunColor; - } - unsigned int getCount() const { return items.size(); } diff --git a/src/service/material/MaterialFileData.cpp b/src/service/material/MaterialFileData.cpp deleted file mode 100644 index 720e86d4..00000000 --- a/src/service/material/MaterialFileData.cpp +++ /dev/null @@ -1,59 +0,0 @@ -#include "MaterialFileData.h" - -#include "../../common/interface/Icons.h" - -namespace Metal { - void MaterialFileData::registerFields() { - registerColor(albedoColor, "", "Albedo color"); - registerBool(isEmissive, "", "Is Emissive"); - registerFloat(roughnessFactor, "", "Roughness factor", 0, 1); - registerFloat(metallicFactor, "", "Metallic factor", 0, 1); - registerFloat(transmissionFactor, "", "Transmission factor", 0, 1); - registerFloat(thicknessFactor, "", "Thickness factor", 0, 10); - registerFloat(ior, "", "IOR", 1, 3); - - registerResourceSelection(albedo, "", "Albedo", EntryType::TEXTURE); - registerResourceSelection(normal, "", "Normal", EntryType::TEXTURE); - registerResourceSelection(roughness, "", "Roughness texture", EntryType::TEXTURE); - registerResourceSelection(metallic, "", "Metallic Texture", EntryType::TEXTURE); - } - - const char *MaterialFileData::getIcon() { - return Icons::format_paint.c_str(); - } - - const char *MaterialFileData::getTitle() { - return "Material"; - } - - nlohmann::json MaterialFileData::toJson() const { - nlohmann::json j; - j["albedo"] = albedo; - j["normal"] = normal; - j["roughness"] = roughness; - j["metallic"] = metallic; - j["albedoColor"] = {albedoColor.x, albedoColor.y, albedoColor.z}; - j["roughnessFactor"] = roughnessFactor; - j["metallicFactor"] = metallicFactor; - j["transmissionFactor"] = transmissionFactor; - j["thicknessFactor"] = thicknessFactor; - j["ior"] = ior; - j["isEmissive"] = isEmissive; - return j; - } - - void MaterialFileData::fromJson(const nlohmann::json &j) { - albedo = j.at("albedo").get(); - normal = j.at("normal").get(); - roughness = j.at("roughness").get(); - metallic = j.at("metallic").get(); - roughnessFactor = j.at("roughnessFactor").get(); - metallicFactor = j.at("metallicFactor").get(); - transmissionFactor = j.value("transmissionFactor", 0.0f); - thicknessFactor = j.value("thicknessFactor", 0.0f); - ior = j.value("ior", 1.45f); - isEmissive = j.at("isEmissive").get(); - - albedoColor = {j.at("albedoColor")[0], j.at("albedoColor")[1], j.at("albedoColor")[2]}; - } -} diff --git a/src/service/material/MaterialImporterService.cpp b/src/service/material/MaterialImporterService.cpp index 90fd6d6f..82aeec99 100644 --- a/src/service/material/MaterialImporterService.cpp +++ b/src/service/material/MaterialImporterService.cpp @@ -1,17 +1,15 @@ #include "MaterialImporterService.h" #include "../../context/ApplicationContext.h" -#include "MaterialFileData.h" #include "../../dto/file/EntryMetadata.h" #include "../../enum/engine-definitions.h" #include "../../util/FilesUtil.h" #include - #include #include "../../util/serialization-definitions.h" namespace Metal { void MaterialImporterService::persistAllMaterials(const std::string &targetDir, const aiScene *scene, - std::unordered_map &materialMap, + std::unordered_map &materialMap, const std::string &rootDirectory, const std::stop_token &stopToken) const { namespace fs = std::filesystem; @@ -19,7 +17,7 @@ namespace Metal { for (unsigned int i = 0; i < scene->mNumMaterials; ++i) { if (stopToken.stop_requested()) return; const aiMaterial *material = scene->mMaterials[i]; - auto materialData = MaterialFileData{}; + auto materialData = MaterialData{}; const auto importAssimpTexture = [& ](const aiString &assimpPath, const std::string &nameHint) -> std::string { @@ -83,22 +81,9 @@ namespace Metal { continue; } - std::string materialId; - { - EntryMetadata materialMetadata{}; - materialMetadata.type = EntryType::MATERIAL; - materialMetadata.name = "Material " + std::to_string(i); - - std::string materialBlobPath = CTX.getAssetDirectory() + FORMAT_FILE_MATERIAL(materialMetadata.getId()); - DUMP_TEMPLATE(materialBlobPath, materialData) - materialMetadata.size = fs::file_size(materialBlobPath); - - DUMP_TEMPLATE(targetDir + '/' + FORMAT_FILE_METADATA(materialMetadata.getId()), materialMetadata) - materialId = materialMetadata.getId(); - } - materialMap.insert({i, materialId}); + materialMap.insert({i, materialData}); - LOG_INFO("Persisted material: " + materialId); + LOG_INFO("Processed material: " + std::to_string(i)); } } } diff --git a/src/service/material/MaterialImporterService.h b/src/service/material/MaterialImporterService.h index d2e4c7a3..d9e543d5 100644 --- a/src/service/material/MaterialImporterService.h +++ b/src/service/material/MaterialImporterService.h @@ -9,11 +9,18 @@ #include "../abstract/AbstractResourceService.h" namespace Metal { + struct MaterialData { + std::string albedo; + std::string normal; + std::string roughness; + std::string metallic; + }; + class MaterialImporterService final : public AbstractRuntimeComponent { public: void persistAllMaterials(const std::string &targetDir, const aiScene *scene, - std::unordered_map &materialMap, + std::unordered_map &materialMap, const std::string &rootDirectory, const std::stop_token &stopToken = {}) const; }; diff --git a/src/service/material/MaterialInstance.h b/src/service/material/MaterialInstance.h deleted file mode 100644 index c27318fd..00000000 --- a/src/service/material/MaterialInstance.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef MATERIALINSTANCE_H -#define MATERIALINSTANCE_H -#include -#include -#include - -#include "../../repository/abstract/RuntimeResource.h" -#include "../../service/descriptor/DescriptorInstance.h" - -namespace Metal { - struct MaterialInstance final : RuntimeResource { - explicit MaterialInstance(const std::string &id) : RuntimeResource(id) { - } - - std::vector textures{}; - unsigned int materialIndex = 0; - - std::vector &getDependencies() override { - return textures; - } - }; -} // Metal - -#endif //MATERIALINSTANCE_H diff --git a/src/service/material/MaterialService.cpp b/src/service/material/MaterialService.cpp index eb553e29..4099fbd8 100644 --- a/src/service/material/MaterialService.cpp +++ b/src/service/material/MaterialService.cpp @@ -1,111 +1,54 @@ #include "MaterialService.h" -#include "../../enum/engine-definitions.h" -#include "MaterialFileData.h" - -#include "../../context/vulkan/VulkanContext.h" -#include "../../util/FilesUtil.h" #include "../../util/serialization-definitions.h" +#include "../../dto/buffers/MeshMetadata.h" -#include -#include "../../dto/buffers/MaterialData.h" -#include "../buffer/BufferInstance.h" - -#include "MaterialInstance.h" #include "../../context/ApplicationContext.h" -#include "../../enum/EngineResourceIDs.h" namespace Metal { - MaterialInstance *MaterialService::create(const std::string &id) { - MaterialFileData *data = stream(id); - if (data == nullptr) { - return nullptr; - } - - auto *instance = createResourceInstance(id); - instance->materialIndex = nextMaterialIndex++; - MaterialData materialData{}; - materialData.albedo = data->albedoColor; - materialData.roughness = data->roughnessFactor; - materialData.metallic = data->metallicFactor; - materialData.transmission = data->transmissionFactor; - materialData.thickness = data->thicknessFactor; - materialData.ior = data->ior; - materialData.isEmissive = data->isEmissive ? 1 : 0; - - materialData.useAlbedoTexture = !data->albedo.empty(); - materialData.useNormalTexture = !data->normal.empty(); - materialData.useRoughnessTexture = !data->roughness.empty(); - materialData.useMetallicTexture = !data->metallic.empty(); + void MaterialService::load(MeshMetadata &materialData, PrimitiveComponent &data) { + materialData.albedo = data.albedoColor; + materialData.roughness = data.roughnessFactor; + materialData.metallic = data.metallicFactor; + materialData.transmission = data.transmissionFactor; + materialData.thickness = data.thicknessFactor; + materialData.ior = data.ior; + materialData.isEmissive = data.isEmissive ? 1 : 0; + + materialData.useAlbedoTexture = !data.albedo.empty(); + materialData.useNormalTexture = !data.normal.empty(); + materialData.useRoughnessTexture = !data.roughness.empty(); + materialData.useMetallicTexture = !data.metallic.empty(); materialData.albedoTextureId = 0; materialData.normalTextureId = 0; materialData.roughnessTextureId = 0; materialData.metallicTextureId = 0; - if (!data->albedo.empty()) { - auto *tex = CTX.textureService.create(data->albedo); + if (!data.albedo.empty()) { + auto *tex = CTX.textureService.create(data.albedo); if (tex != nullptr) { - materialData.albedoTextureId = CTX.textureService.getTextureIndex(data->albedo); + materialData.albedoTextureId = CTX.textureService.getTextureIndex(data.albedo); } } - if (!data->normal.empty()) { - auto *tex = CTX.textureService.create(data->normal); + if (!data.normal.empty()) { + auto *tex = CTX.textureService.create(data.normal); if (tex != nullptr) { - materialData.normalTextureId = CTX.textureService.getTextureIndex(data->normal); + materialData.normalTextureId = CTX.textureService.getTextureIndex(data.normal); } } - if (!data->roughness.empty()) { - auto *tex = CTX.textureService.create(data->roughness); + if (!data.roughness.empty()) { + auto *tex = CTX.textureService.create(data.roughness); if (tex != nullptr) { - materialData.roughnessTextureId = CTX.textureService.getTextureIndex(data->roughness); + materialData.roughnessTextureId = CTX.textureService.getTextureIndex(data.roughness); } } - if (!data->metallic.empty()) { - auto *tex = CTX.textureService.create(data->metallic); + if (!data.metallic.empty()) { + auto *tex = CTX.textureService.create(data.metallic); if (tex != nullptr) { - materialData.metallicTextureId = CTX.textureService.getTextureIndex(data->metallic); + materialData.metallicTextureId = CTX.textureService.getTextureIndex(data.metallic); } } - - materials[instance->materialIndex] = materialData; - - auto *materialBuffer = CTX.engineContext.currentFrame->getResourceAs(RID_MATERIAL_BUFFER); - materialBuffer->update(materials.data()); - - delete data; - - return instance; - } - - MaterialFileData *MaterialService::stream(const std::string &id) const { - auto pathToFile = CTX.getAssetDirectory() + FORMAT_FILE_MATERIAL(id); - if (std::filesystem::exists(pathToFile)) { - auto *data = new MaterialFileData; - PARSE_TEMPLATE(*data, pathToFile); - return data; - } - return nullptr; - } - - unsigned int MaterialService::getMaterialIndex(const std::string &id) { - if (id.empty()) { - return 0; - } - if (resources.contains(id)) { - return dynamic_cast(resources.at(id))->materialIndex; - } - auto *instance = create(id); - if (instance != nullptr) { - return instance->materialIndex; - } - return 0; - } - - void MaterialService::disposeResource(MaterialInstance *resource) { - // Materials are currently just entries in a global buffer, - // they don't hold many resources themselves, but they do have dependencies - // which are handled by StreamingService. } } // Metal diff --git a/src/service/material/MaterialService.h b/src/service/material/MaterialService.h index 98eaffa5..fce5458e 100644 --- a/src/service/material/MaterialService.h +++ b/src/service/material/MaterialService.h @@ -1,26 +1,13 @@ #ifndef MATERIALSERVICE_H #define MATERIALSERVICE_H -#include "MaterialFileData.h" -#include "MaterialInstance.h" -#include "../../service/abstract/AbstractResourceService.h" -#include "../../service/abstract/IStreamable.h" - -#include "../../enum/engine-definitions.h" -#include -#include "../../dto/buffers/MaterialData.h" namespace Metal { - class MaterialService final : public IStreamable { - unsigned int nextMaterialIndex = 1; - std::vector materials {MAX_MATERIALS}; - public: - MaterialInstance *create(const std::string &id) override; - - MaterialFileData *stream(const std::string &id) const; + struct PrimitiveComponent; + struct MeshMetadata; - unsigned int getMaterialIndex(const std::string &id); - - void disposeResource(MaterialInstance *resource) override; + class MaterialService final { + public: + void load(MeshMetadata &data, PrimitiveComponent &component); }; } // Metal diff --git a/src/service/mesh/EntityAssetData.h b/src/service/mesh/EntityAssetData.h index d3e64bde..b713a98a 100644 --- a/src/service/mesh/EntityAssetData.h +++ b/src/service/mesh/EntityAssetData.h @@ -3,22 +3,45 @@ #include #include "../../util/Serializable.h" +#include namespace Metal { struct EntityAssetData final : Serializable { std::string name{}; std::string meshId{}; - std::string materialId{}; int parentEntity = -1; int id; + std::string albedo; + std::string normal; + std::string roughness; + std::string metallic; + glm::vec3 albedoColor{1, 1, 1}; + float roughnessFactor = 1; + float metallicFactor = 0; + float transmissionFactor = 0; + float thicknessFactor = 0; + float ior = 1.45; + bool isEmissive = false; + nlohmann::json toJson() const override { nlohmann::json j; j["id"] = id; j["name"] = name; j["meshId"] = meshId; - j["materialId"] = materialId; j["parentEntity"] = parentEntity; + + j["albedo"] = albedo; + j["normal"] = normal; + j["roughness"] = roughness; + j["metallic"] = metallic; + j["albedoColor"] = {albedoColor.x, albedoColor.y, albedoColor.z}; + j["roughnessFactor"] = roughnessFactor; + j["metallicFactor"] = metallicFactor; + j["transmissionFactor"] = transmissionFactor; + j["thicknessFactor"] = thicknessFactor; + j["ior"] = ior; + j["isEmissive"] = isEmissive; return j; } @@ -26,8 +49,21 @@ namespace Metal { id = j.at("id").get(); name = j.at("name").get(); meshId = j.at("meshId").get(); - materialId = j.at("materialId").get(); parentEntity = j.at("parentEntity").get(); + + albedo = j.value("albedo", ""); + normal = j.value("normal", ""); + roughness = j.value("roughness", ""); + metallic = j.value("metallic", ""); + if (j.contains("albedoColor")) { + albedoColor = {j.at("albedoColor")[0], j.at("albedoColor")[1], j.at("albedoColor")[2]}; + } + roughnessFactor = j.value("roughnessFactor", 1.0f); + metallicFactor = j.value("metallicFactor", 0.0f); + transmissionFactor = j.value("transmissionFactor", 0.0f); + thicknessFactor = j.value("thicknessFactor", 0.0f); + ior = j.value("ior", 1.45f); + isEmissive = j.value("isEmissive", false); } }; } diff --git a/src/service/mesh/MeshService.cpp b/src/service/mesh/MeshService.cpp index 4a8117ab..ef92160e 100644 --- a/src/service/mesh/MeshService.cpp +++ b/src/service/mesh/MeshService.cpp @@ -12,7 +12,7 @@ #include #include "../../context/ApplicationContext.h" -#include "../../repository/world/components/MeshComponent.h" +#include "../../repository/world/components/PrimitiveComponent.h" #include "../../repository/world/components/TransformComponent.h" namespace Metal { @@ -29,14 +29,16 @@ namespace Metal { instance->dataBuffer = CTX.bufferService.createBuffer( id + "_data", sizeof(VertexData) * data->data.size(), - VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | VK_BUFFER_USAGE_ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY_BIT_KHR | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT, + VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | VK_BUFFER_USAGE_ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY_BIT_KHR | + VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT, data->data.data(), true); instance->indexBuffer = CTX.bufferService.createBuffer( id + "_indices", sizeof(unsigned int) * data->indices.size(), - VK_BUFFER_USAGE_INDEX_BUFFER_BIT | VK_BUFFER_USAGE_ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY_BIT_KHR | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT, + VK_BUFFER_USAGE_INDEX_BUFFER_BIT | VK_BUFFER_USAGE_ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY_BIT_KHR | + VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT, data->indices.data(), true); @@ -58,19 +60,32 @@ namespace Metal { } EntityID MeshService::createMeshEntity(const std::string &name, const std::string &meshId, - const std::string &materialId) const { + const EntityAssetData *data) const { const auto id = CTX.worldRepository.createEntity(); - CTX.worldRepository.createComponent(id, ComponentTypes::ComponentType::MESH); + CTX.worldRepository.createComponent(id, ComponentTypes::ComponentType::PRIMITIVE); const auto entity = static_cast(id); - auto &mesh = CTX.worldRepository.registry.get(entity); + auto &mesh = CTX.worldRepository.registry.get(entity); mesh.meshId = meshId; - mesh.materialId = materialId; - MeshData *data = stream(meshId); if (data != nullptr) { + mesh.albedo = data->albedo; + mesh.normal = data->normal; + mesh.roughness = data->roughness; + mesh.metallic = data->metallic; + mesh.albedoColor = data->albedoColor; + mesh.roughnessFactor = data->roughnessFactor; + mesh.metallicFactor = data->metallicFactor; + mesh.transmissionFactor = data->transmissionFactor; + mesh.thicknessFactor = data->thicknessFactor; + mesh.ior = data->ior; + mesh.isEmissive = data->isEmissive; + } + + MeshData *meshData = stream(meshId); + if (meshData != nullptr) { auto &transform = CTX.worldRepository.registry.get(entity); - transform.gizmoCenter = data->gizmoCenter; - delete data; + transform.gizmoCenter = meshData->gizmoCenter; + delete meshData; } CTX.worldRepository.getEntity(id)->name = name; @@ -79,15 +94,15 @@ namespace Metal { void MeshService::createSceneEntities(const std::string &id) const { auto &repo = CTX.worldRepository; - SceneData data; + SceneData sceneData; auto pathToFile = CTX.getAssetDirectory() + FORMAT_FILE_SCENE(id); - PARSE_TEMPLATE(data, pathToFile) + PARSE_TEMPLATE(sceneData, pathToFile) std::unordered_map entities; - for (auto &entity: data.entities) { + for (auto &entity: sceneData.entities) { if (!entity.meshId.empty()) { - entities.insert({entity.id, createMeshEntity(entity.name, entity.meshId, entity.materialId)}); + entities.insert({entity.id, createMeshEntity(entity.name, entity.meshId, &entity)}); } else { const auto entityId = repo.createEntity(); entities.insert({entity.id, entityId}); @@ -96,7 +111,7 @@ namespace Metal { } } - for (auto &entity: data.entities) { + for (auto &entity: sceneData.entities) { if (entity.parentEntity < 0 || !entities.contains(entity.parentEntity)) { continue; } diff --git a/src/service/mesh/MeshService.h b/src/service/mesh/MeshService.h index d5104ba1..d4b246fe 100644 --- a/src/service/mesh/MeshService.h +++ b/src/service/mesh/MeshService.h @@ -8,6 +8,7 @@ namespace Metal { struct MeshData; struct MeshInstance; + struct EntityAssetData; class MeshService final : public IStreamable { public: @@ -16,7 +17,7 @@ namespace Metal { MeshData *stream(const std::string &id) const; EntityID createMeshEntity(const std::string &name, const std::string &meshId, - const std::string &materialId) const; + const EntityAssetData *data) const; void createSceneEntities(const std::string &id) const; diff --git a/src/service/mesh/SceneImporterService.cpp b/src/service/mesh/SceneImporterService.cpp index 5aa9b819..848be621 100644 --- a/src/service/mesh/SceneImporterService.cpp +++ b/src/service/mesh/SceneImporterService.cpp @@ -4,6 +4,7 @@ #include "MeshData.h" #include "EntityAssetData.h" #include "SceneData.h" +#include "../material/MaterialImporterService.h" #include #include #include @@ -68,7 +69,7 @@ namespace Metal { throw std::runtime_error("Import cancelled"); } - std::unordered_map materialsMap{}; + std::unordered_map materialsMap{}; fs::path absolutePath = fs::absolute(pathToFile); fs::path directoryPath = absolutePath.parent_path(); @@ -95,7 +96,7 @@ namespace Metal { void SceneImporterService::ProcessNode(int &increment, SceneData &scene, const aiNode *node, int parentId, const std::unordered_map &meshMap, const std::unordered_map &meshMaterialMap, - const std::unordered_map &materialsMap, + const std::unordered_map &materialsMap, const std::stop_token &stopToken) { if (stopToken.stop_requested()) return; auto ¤tNode = scene.entities.emplace_back(); @@ -127,7 +128,11 @@ namespace Metal { if (meshMaterialMap.contains(childMeshNode.meshId)) { unsigned int matIndex = meshMaterialMap.at(childMeshNode.meshId); if (materialsMap.contains(matIndex)) { - childMeshNode.materialId = materialsMap.at(matIndex); + const auto &matData = materialsMap.at(matIndex); + childMeshNode.albedo = matData.albedo; + childMeshNode.normal = matData.normal; + childMeshNode.roughness = matData.roughness; + childMeshNode.metallic = matData.metallic; } } increment++; diff --git a/src/service/mesh/SceneImporterService.h b/src/service/mesh/SceneImporterService.h index cc05bcde..457bce92 100644 --- a/src/service/mesh/SceneImporterService.h +++ b/src/service/mesh/SceneImporterService.h @@ -8,7 +8,7 @@ #include namespace Metal { - struct MaterialFileData; + struct MaterialData; struct MeshData; struct SceneData; @@ -16,7 +16,7 @@ namespace Metal { static void ProcessNode(int &increment, SceneData &scene, const aiNode *node, int parentId, const std::unordered_map &meshMap, const std::unordered_map &meshMaterialMap, - const std::unordered_map &materialsMap, + const std::unordered_map &materialsMap, const std::stop_token &stopToken); public: diff --git a/src/service/picking/PickingService.cpp b/src/service/picking/PickingService.cpp index 879f29aa..225f5800 100644 --- a/src/service/picking/PickingService.cpp +++ b/src/service/picking/PickingService.cpp @@ -66,9 +66,9 @@ namespace Metal { const unsigned int renderIndex = static_cast(idValue + 0.5f) - 1; - auto view = CTX.worldRepository.registry.view(); + auto view = CTX.worldRepository.registry.view(); for (auto entity: view) { - auto &mesh = view.get(entity); + auto &mesh = view.get(entity); if (mesh.renderIndex == renderIndex) { return static_cast(entity); } diff --git a/src/service/raytracing/RayTracingService.cpp b/src/service/raytracing/RayTracingService.cpp index 51f7b451..0cc1376f 100644 --- a/src/service/raytracing/RayTracingService.cpp +++ b/src/service/raytracing/RayTracingService.cpp @@ -34,17 +34,20 @@ namespace Metal { } } void RayTracingService::onSync() { - if (!needsRebuild) { + if (needsMaterialUpdate) { updateMeshMaterials(); + needsMaterialUpdate = false; + } + if (!needsRebuild) { return; } // Check if any mesh is present and streamed bool hasMeshes = false; - auto view = CTX.worldRepository.registry.view(); + auto view = CTX.worldRepository.registry.view(); for (auto entity: view) { if (CTX.worldRepository.hiddenEntities.contains(static_cast(entity))) continue; - auto &meshComp = view.get(entity); + auto &meshComp = view.get(entity); if (meshComp.meshId.empty()) continue; auto *instance = CTX.streamingService.streamMesh(meshComp.meshId); if (instance != nullptr && instance->dataBuffer != nullptr && instance->indexBuffer != nullptr) { @@ -84,22 +87,19 @@ namespace Metal { } void RayTracingService::updateMeshMaterials() { - if (!accelerationStructureBuilt || meshMetadata.empty()) return; + if (!meshMetadata.empty()) return; bool changed = false; - auto view = CTX.worldRepository.registry.view(); + auto view = CTX.worldRepository.registry.view(); for (auto entity: view) { if (CTX.worldRepository.hiddenEntities.contains(static_cast(entity))) continue; - auto &meshComp = view.get(entity); + auto &meshComp = view.get(entity); if (meshComp.meshId.empty()) continue; if (meshComp.renderIndex < meshMetadata.size()) { - unsigned int materialIndex = CTX.materialService.getMaterialIndex(meshComp.materialId); - if (meshMetadata[meshComp.renderIndex].materialIndex != materialIndex) { - meshMetadata[meshComp.renderIndex].materialIndex = materialIndex; - changed = true; - } + CTX.materialService.load(meshMetadata[meshComp.renderIndex], meshComp); + changed = true; } } @@ -145,11 +145,11 @@ namespace Metal { std::unordered_map uniqueMeshes; - auto view = CTX.worldRepository.registry.view(); + auto view = CTX.worldRepository.registry.view(); for (auto entity: view) { if (CTX.worldRepository.hiddenEntities.contains(static_cast(entity))) continue; - auto &meshComp = view.get(entity); + auto &meshComp = view.get(entity); if (meshComp.meshId.empty()) continue; if (uniqueMeshes.contains(meshComp.meshId)) continue; auto *instance = CTX.streamingService.streamMesh(meshComp.meshId); @@ -268,7 +268,7 @@ namespace Metal { } std::vector instances; - auto view = CTX.worldRepository.registry.view(); + auto view = CTX.worldRepository.registry.view(); unsigned int currentInstanceIndex = 0; for (auto entity: view) { @@ -277,7 +277,7 @@ namespace Metal { break; } if (CTX.worldRepository.hiddenEntities.contains(static_cast(entity))) continue; - auto &meshComp = view.get(entity); + auto &meshComp = view.get(entity); if (meshComp.meshId.empty()) continue; auto it = blasEntries.find(meshComp.meshId); @@ -302,13 +302,11 @@ namespace Metal { } } - uint32_t materialIndex = CTX.materialService.getMaterialIndex(meshComp.materialId); - VkDeviceAddress vertexAddress = getDeviceAddress(vulkan, it->second.vertexData->vkBuffer); VkDeviceAddress indexAddress = getDeviceAddress(vulkan, it->second.indexData->vkBuffer); meshComp.renderIndex = currentInstanceIndex; - meshMetadata.push_back({meshComp.renderIndex, materialIndex, vertexAddress, indexAddress}); + meshMetadata.push_back({meshComp.renderIndex, vertexAddress, indexAddress}); VkAccelerationStructureInstanceKHR instance{}; instance.transform = transform; @@ -324,13 +322,8 @@ namespace Metal { if (instances.empty()) return; - if (CTX.engineContext.currentFrame != nullptr) { - auto *meshMetadataBuffer = CTX.engineContext.currentFrame->getResourceAs( - RID_MESH_METADATA_BUFFER); - if (meshMetadataBuffer != nullptr) { - meshMetadataBuffer->update(meshMetadata.data()); - } - } + + updateMeshMaterials(); instancesBuffer = CTX.bufferService.createBuffer( "tlas_instances", diff --git a/src/service/raytracing/RayTracingService.h b/src/service/raytracing/RayTracingService.h index e4949fcd..13c0bfc2 100644 --- a/src/service/raytracing/RayTracingService.h +++ b/src/service/raytracing/RayTracingService.h @@ -37,17 +37,23 @@ namespace Metal { bool accelerationStructureBuilt = false; bool needsRebuild = true; + bool needsMaterialUpdate = false; void updateDescriptorSets(VkAccelerationStructureKHR asHandle); void buildBLAS(); void buildTLAS(); - void updateMeshMaterials(); void destroyTLAS(); + void updateMeshMaterials(); + public: + void setNeedsMaterialUpdate(bool val) { + needsMaterialUpdate = val; + } + void destroyAccelerationStructures(); void onSync() override; diff --git a/src/service/transform/TransformService.cpp b/src/service/transform/TransformService.cpp index 9e670c1c..595ec535 100644 --- a/src/service/transform/TransformService.cpp +++ b/src/service/transform/TransformService.cpp @@ -57,7 +57,7 @@ namespace Metal { auto *newTile = CTX.worldGridRepository.getOrCreateTile(translation); CTX.worldGridRepository.moveBetweenTiles(st->getEntityId(), previousTile, newTile); - if (CTX.worldRepository.registry.all_of(static_cast::entity_type>(st->getEntityId()))) { + if (CTX.worldRepository.registry.all_of(static_cast::entity_type>(st->getEntityId()))) { CTX.rayTracingService.markDirty(); } } diff --git a/src/service/volumes/VolumeService.cpp b/src/service/volumes/VolumeService.cpp index c833ff38..a29eaa28 100644 --- a/src/service/volumes/VolumeService.cpp +++ b/src/service/volumes/VolumeService.cpp @@ -6,22 +6,6 @@ namespace Metal { void VolumeService::registerVolumes() { - auto view = CTX.worldRepository.registry.view(); - for (auto [entity, l, t]: view.each()) { - const auto entityId = static_cast(entity); - if (CTX.worldRepository.hiddenEntities.contains(entityId)) { - continue; - } - - auto &translation = t.translation; - - items.push_back(VolumeData( - glm::vec4(l.albedo, l.samples), - translation, - t.scale, - glm::vec3(l.density, l.scatteringAlbedo, l.g) - )); - } } void VolumeService::onSync() { diff --git a/src/service/voxel/impl/SparseVoxelOctreeBuilder.h b/src/service/voxel/impl/SparseVoxelOctreeBuilder.h index ddaafb2f..470fdd9f 100644 --- a/src/service/voxel/impl/SparseVoxelOctreeBuilder.h +++ b/src/service/voxel/impl/SparseVoxelOctreeBuilder.h @@ -9,7 +9,7 @@ namespace Metal { struct SnapshotWorldTile; struct VoxelData; struct OctreeNode; - struct MeshComponent; + struct PrimitiveComponent; class SparseVoxelOctreeBuilder { OctreeNode root{}; diff --git a/src/util/UIUtil.h b/src/util/UIUtil.h index 41305050..31f39f16 100644 --- a/src/util/UIUtil.h +++ b/src/util/UIUtil.h @@ -105,8 +105,6 @@ namespace Metal::UIUtil { return Icons::folder; case EntryType::SCENE: return Icons::inventory_2; - case EntryType::MATERIAL: - return Icons::format_paint; default: return ""; } } From 86b49f8fbe615ab58d9d7a0ff4fa43ceebb36ae9 Mon Sep 17 00:00:00 2001 From: facobackup Date: Wed, 4 Mar 2026 21:48:58 -0300 Subject: [PATCH 02/18] Removing grid Removing normal texture --- CMakeLists.txt | 7 - resources/shaders/MeshMetadata.glsl | 6 - resources/shaders/rt/HWRayTracing.rchit | 6 +- src/context/ApplicationContext.cpp | 2 - src/context/ApplicationContext.h | 6 - .../viewport/CameraPositionPanel.cpp | 5 - src/context/engine/EngineContext.cpp | 6 - src/context/engine/EngineContext.h | 9 -- .../compute-pass/impl/HWRayTracingPass.cpp | 4 +- src/dto/buffers/MeshMetadata.h | 6 - src/repository/engine/EngineRepository.cpp | 3 - src/repository/world/WorldRepository.cpp | 5 - .../world/components/AtmosphereComponent.cpp | 3 +- .../world/components/PrimitiveComponent.cpp | 3 - .../world/components/PrimitiveComponent.h | 1 - .../world/components/TransformComponent.cpp | 4 - .../world/components/VolumeComponent.cpp | 1 - src/repository/world/impl/EntityComponent.h | 3 - .../world/impl/WorldGridRepository.cpp | 123 ------------------ .../world/impl/WorldGridRepository.h | 82 ------------ src/repository/world/impl/WorldTile.h | 93 ------------- .../material/MaterialImporterService.cpp | 8 +- .../material/MaterialImporterService.h | 3 +- src/service/material/MaterialService.cpp | 12 -- src/service/mesh/EntityAssetData.h | 3 - src/service/mesh/MeshService.cpp | 7 +- src/service/mesh/SceneImporterService.cpp | 3 +- src/service/transform/TransformService.cpp | 6 - src/service/volumes/VolumeService.cpp | 20 --- src/service/volumes/VolumeService.h | 27 ---- src/service/voxel/VoxelImporterService.cpp | 3 +- src/service/world/WorldGridService.cpp | 62 --------- src/service/world/WorldGridService.h | 27 ---- src/util/ShaderUtil.cpp | 1 - 34 files changed, 12 insertions(+), 548 deletions(-) delete mode 100644 src/repository/world/impl/WorldGridRepository.cpp delete mode 100644 src/repository/world/impl/WorldGridRepository.h delete mode 100644 src/repository/world/impl/WorldTile.h delete mode 100644 src/service/volumes/VolumeService.cpp delete mode 100644 src/service/volumes/VolumeService.h delete mode 100644 src/service/world/WorldGridService.cpp delete mode 100644 src/service/world/WorldGridService.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 96862a67..fdd78ae6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -192,9 +192,6 @@ add_executable( src/context/editor/abstract/form/types/QuatField.h src/service/transform/TransformService.cpp src/service/transform/TransformService.h - src/repository/world/impl/WorldGridRepository.cpp - src/repository/world/impl/WorldGridRepository.h - src/repository/world/impl/WorldTile.h src/repository/world/impl/BoundingBox.h src/service/voxel/impl/SparseVoxelOctreeBuilder.cpp src/service/voxel/impl/SparseVoxelOctreeBuilder.h @@ -226,8 +223,6 @@ add_executable( src/service/picking/PickingService.cpp src/service/picking/PickingService.h src/service/voxel/SVOInstance.h - src/service/world/WorldGridService.cpp - src/service/world/WorldGridService.h src/dto/buffers/TileInfoUBO.h src/dto/buffers/LightData.h src/repository/world/components/LightComponent.cpp @@ -260,8 +255,6 @@ add_executable( src/service/voxel/VoxelImporterService.cpp src/service/voxel/VoxelImporterService.h src/dto/buffers/VolumeData.h - src/service/volumes/VolumeService.cpp - src/service/volumes/VolumeService.h src/service/voxel/VoxelService.cpp src/service/voxel/VoxelService.h src/util/Serializable.cpp diff --git a/resources/shaders/MeshMetadata.glsl b/resources/shaders/MeshMetadata.glsl index 2521a089..1867b4af 100644 --- a/resources/shaders/MeshMetadata.glsl +++ b/resources/shaders/MeshMetadata.glsl @@ -16,13 +16,7 @@ struct MeshMetadata { float ior; uint isEmissive; - uint useAlbedoTexture; - uint useNormalTexture; - uint useRoughnessTexture; - uint useMetallicTexture; - uint albedoTexture; - uint normalTexture; uint roughnessTexture; uint metallicTexture; }; diff --git a/resources/shaders/rt/HWRayTracing.rchit b/resources/shaders/rt/HWRayTracing.rchit index f1ee83d2..f89c4a2f 100644 --- a/resources/shaders/rt/HWRayTracing.rchit +++ b/resources/shaders/rt/HWRayTracing.rchit @@ -72,17 +72,17 @@ void main() { bool isEmissive = false; if (matIndex != 0u) { - if (metadata.useAlbedoTexture == 1u) { + if (metadata.albedoTexture != 0u) { baseColor = texture(textureArray[nonuniformEXT(metadata.albedoTexture)], uv).rgb; } else { baseColor = metadata.albedo; } - if (metadata.useRoughnessTexture == 1u) { + if (metadata.roughnessTexture != 0u) { roughness = texture(textureArray[nonuniformEXT(metadata.roughnessTexture)], uv).r; } else { roughness = metadata.roughness; } - if (metadata.useMetallicTexture == 1u) { + if (metadata.metallicTexture != 0u) { metallic = texture(textureArray[nonuniformEXT(metadata.metallicTexture)], uv).r; } else { metallic = metadata.metallic; diff --git a/src/context/ApplicationContext.cpp b/src/context/ApplicationContext.cpp index 75fa7640..f489b20b 100644 --- a/src/context/ApplicationContext.cpp +++ b/src/context/ApplicationContext.cpp @@ -42,7 +42,6 @@ namespace Metal { } PARSE_TEMPLATE(editorRepository, rootDirectory + "/" + HASH_OF_CLASS_NAME(EditorRepository) + ".json") PARSE_TEMPLATE(engineRepository, rootDirectory + "/" + HASH_OF_CLASS_NAME(EngineRepository) + ".json") - PARSE_TEMPLATE(worldGridRepository, rootDirectory + "/" + HASH_OF_CLASS_NAME(WorldGridRepository) + ".json") PARSE_TEMPLATE(worldRepository, rootDirectory + "/" + HASH_OF_CLASS_NAME(WorldRepository) + ".json") @@ -127,7 +126,6 @@ namespace Metal { try { DUMP_TEMPLATE(rootDirectory + "/" + HASH_OF_CLASS_NAME(EditorRepository) + ".json", editorRepository) DUMP_TEMPLATE(rootDirectory + "/" + HASH_OF_CLASS_NAME(EngineRepository) + ".json", engineRepository) - DUMP_TEMPLATE(rootDirectory + "/" + HASH_OF_CLASS_NAME(WorldGridRepository) + ".json", worldGridRepository) DUMP_TEMPLATE(rootDirectory + "/" + HASH_OF_CLASS_NAME(WorldRepository) + ".json", worldRepository) notificationService.pushMessage("Project saved", NotificationSeverities::SUCCESS); } catch (const std::exception &e) { diff --git a/src/context/ApplicationContext.h b/src/context/ApplicationContext.h index 09bc13a5..3cbde43c 100644 --- a/src/context/ApplicationContext.h +++ b/src/context/ApplicationContext.h @@ -8,7 +8,6 @@ #include "vulkan/VulkanContext.h" #include "../service/mesh/MeshService.h" -#include "../service/world/WorldGridService.h" #include "../service/texture/TextureService.h" #include "../service/framebuffer/FrameBufferService.h" #include "../service/pipeline/PipelineService.h" @@ -25,7 +24,6 @@ #include "../service/files/FileImporterService.h" #include "../service/camera/CameraService.h" -#include "../repository/world/impl/WorldGridRepository.h" #include "../repository/world/WorldRepository.h" #include "../repository/runtime/RuntimeRepository.h" #include "../repository/streaming/StreamingService.h" @@ -39,7 +37,6 @@ #include "../service/log/LogService.h" #include "../service/transform/TransformService.h" #include "../service/picking/PickingService.h" -#include "../service/volumes/VolumeService.h" #include "../service/voxel/VoxelImporterService.h" #include "../service/voxel/VoxelService.h" #include "../service/lights/LightService.h" @@ -88,10 +85,8 @@ namespace Metal { FileImporterService fileImporterService{}; CameraService cameraService{}; PickingService pickingService{}; - WorldGridService worldGridService{}; TransformService transformService{}; LightService lightService{}; - VolumeService volumeService{}; RayTracingService rayTracingService{}; CommandBufferRecorderService commandBufferRecorderService{}; VoxelImporterService voxelImporterService{}; @@ -99,7 +94,6 @@ namespace Metal { // ----------- Services // ----------- Repository - WorldGridRepository worldGridRepository{}; WorldRepository worldRepository{}; RuntimeRepository runtimeRepository{}; StreamingService streamingService{}; diff --git a/src/context/editor/dock-spaces/viewport/CameraPositionPanel.cpp b/src/context/editor/dock-spaces/viewport/CameraPositionPanel.cpp index 38857420..e84ed0b5 100644 --- a/src/context/editor/dock-spaces/viewport/CameraPositionPanel.cpp +++ b/src/context/editor/dock-spaces/viewport/CameraPositionPanel.cpp @@ -19,11 +19,6 @@ namespace Metal { if (ImGui::Begin(id.c_str(), &UIUtil::OPEN, ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoCollapse)) { const auto &positionCamera = CTX.worldRepository.camera.position; - ImGui::Text("Current tile: %i %i | N of tiles: %i", - CTX.worldGridRepository.getCurrentTile()->x, - CTX.worldGridRepository.getCurrentTile()->z, - CTX.worldGridRepository.getTiles().size()); - ImGui::SameLine(); ImGui::TextColored(RED, "X: %i", static_cast(positionCamera.x)); ImGui::SameLine(); ImGui::TextColored(GREEN, "Y: %i", static_cast(positionCamera.y)); diff --git a/src/context/engine/EngineContext.cpp b/src/context/engine/EngineContext.cpp index e34455aa..bdfbc5cc 100644 --- a/src/context/engine/EngineContext.cpp +++ b/src/context/engine/EngineContext.cpp @@ -18,7 +18,6 @@ namespace Metal { } void EngineContext::onInitialize() { - CTX.worldGridService.onSync(); } void EngineContext::updateCurrentTime() { @@ -45,7 +44,6 @@ namespace Metal { updateCurrentTime(); CTX.transformService.onSync(); - CTX.worldGridService.onSync(); CTX.streamingService.onSync(); CTX.cameraService.onSync(); @@ -57,10 +55,6 @@ namespace Metal { CTX.lightService.onSync(); } - if (updateVolumes || isFirstFrame) { - CTX.volumeService.onSync(); - } - isFirstFrame = false; updateGlobalData(); diff --git a/src/context/engine/EngineContext.h b/src/context/engine/EngineContext.h index ecb2eaf9..b47d4ddb 100644 --- a/src/context/engine/EngineContext.h +++ b/src/context/engine/EngineContext.h @@ -20,7 +20,6 @@ namespace Metal { long long start = -1; bool cameraUpdated = true; bool updateLights = true; - bool updateVolumes = true; bool giSettingsUpdated = true; bool isFirstFrame = true; @@ -35,14 +34,6 @@ namespace Metal { return updateLights; } - void setUpdateVolumes(const bool val) { - updateVolumes = val; - } - - [[nodiscard]] bool isUpdateVolumes() const { - return updateVolumes; - } - void setCameraUpdated(const bool val) { cameraUpdated = val; } diff --git a/src/context/engine/compute-pass/impl/HWRayTracingPass.cpp b/src/context/engine/compute-pass/impl/HWRayTracingPass.cpp index 739da1b7..def48539 100644 --- a/src/context/engine/compute-pass/impl/HWRayTracingPass.cpp +++ b/src/context/engine/compute-pass/impl/HWRayTracingPass.cpp @@ -48,10 +48,8 @@ namespace Metal { previousPositionIndex = frame->getResourceAs(RID_PREVIOUS_POSITION_INDEX); previousNormal = frame->getResourceAs(RID_PREVIOUS_NORMAL); - bool worldChanged = CTX.engineContext.isUpdateLights() || CTX.worldGridService.isNotFrozen(); if (isFirstRun || CTX.engineContext.isCameraUpdated() || CTX.engineContext.isGISettingsUpdated() || - worldChanged) { - CTX.worldGridService.freezeVersion(); + CTX.engineContext.isUpdateLights()) { clearTexture(rawRenderedFrame->vkImage); clearTexture(accumulatedFrame->vkImage); CTX.engineContext.resetPathTracerAccumulationCount(); diff --git a/src/dto/buffers/MeshMetadata.h b/src/dto/buffers/MeshMetadata.h index b2015c67..bfe11d8e 100644 --- a/src/dto/buffers/MeshMetadata.h +++ b/src/dto/buffers/MeshMetadata.h @@ -18,13 +18,7 @@ namespace Metal { alignas(4) float ior{1.45f}; alignas(4) unsigned int isEmissive{}; - alignas(4) unsigned int useAlbedoTexture; - alignas(4) unsigned int useNormalTexture; - alignas(4) unsigned int useRoughnessTexture; - alignas(4) unsigned int useMetallicTexture; - alignas(4) unsigned int albedoTextureId = 0; - alignas(4) unsigned int normalTextureId = 0; alignas(4) unsigned int roughnessTextureId = 0; alignas(4) unsigned int metallicTextureId = 0; }; diff --git a/src/repository/engine/EngineRepository.cpp b/src/repository/engine/EngineRepository.cpp index ec959140..9ddc5546 100644 --- a/src/repository/engine/EngineRepository.cpp +++ b/src/repository/engine/EngineRepository.cpp @@ -30,9 +30,6 @@ namespace Metal { } void EngineRepository::onUpdate(InspectableMember *member) { - if (member != nullptr && member->name == LEVEL_OF_DETAIL) { - CTX.worldGridRepository.hasMainTileChanged = true; - } if (member != nullptr && (member->group == PATH_TRACER || member->group == DEPTH_OF_FIELD)) { CTX.engineContext.setGISettingsUpdated(true); CTX.engineContext.setUpdateLights(true); diff --git a/src/repository/world/WorldRepository.cpp b/src/repository/world/WorldRepository.cpp index 740600ea..f2dc4e5a 100644 --- a/src/repository/world/WorldRepository.cpp +++ b/src/repository/world/WorldRepository.cpp @@ -94,7 +94,6 @@ namespace Metal { registerChange(); deleteRecursively(entities); CTX.engineContext.setUpdateLights(true); - CTX.engineContext.setUpdateVolumes(true); CTX.rayTracingService.markDirty(); } @@ -102,7 +101,6 @@ namespace Metal { registerChange(); changeVisibilityRecursively(entity, isVisible); CTX.engineContext.setUpdateLights(true); - CTX.engineContext.setUpdateVolumes(true); CTX.rayTracingService.markDirty(); } @@ -154,15 +152,12 @@ namespace Metal { auto &vol = registry.emplace_or_replace(entity); vol.setEntityId(entityId); createComponent(entityId, ComponentTypes::TRANSFORM); - CTX.engineContext.setUpdateVolumes(true); break; } case ComponentTypes::TRANSFORM: { if (!registry.all_of(entity)) { auto &trans = registry.emplace(entity); trans.setEntityId(entityId); - CTX.worldGridRepository.getCurrentTile()->entities.push_back(entityId); - registry.get(entity).onTile = CTX.worldGridRepository.getCurrentTile()->id; } break; } diff --git a/src/repository/world/components/AtmosphereComponent.cpp b/src/repository/world/components/AtmosphereComponent.cpp index 6515ef03..93a82abb 100644 --- a/src/repository/world/components/AtmosphereComponent.cpp +++ b/src/repository/world/components/AtmosphereComponent.cpp @@ -53,8 +53,7 @@ namespace Metal { void AtmosphereComponent::onUpdate(InspectableMember *member) { CTX.engineContext.setGISettingsUpdated(true); CTX.engineContext.setUpdateLights(true); - CTX.engineContext.setUpdateVolumes(true); - + sunPosition = glm::vec3(0, std::cos(elapsedTime), std::sin(elapsedTime)) * sunDistance; diff --git a/src/repository/world/components/PrimitiveComponent.cpp b/src/repository/world/components/PrimitiveComponent.cpp index 066f31a4..412889e4 100644 --- a/src/repository/world/components/PrimitiveComponent.cpp +++ b/src/repository/world/components/PrimitiveComponent.cpp @@ -14,7 +14,6 @@ namespace Metal { registerFloat(thicknessFactor, "Material", "Thickness factor", 0, 10); registerFloat(ior, "Material", "IOR", 1, 3); registerResourceSelection(albedo, "Material", "Albedo", EntryType::TEXTURE); - registerResourceSelection(normal, "Material", "Normal", EntryType::TEXTURE); registerResourceSelection(roughness, "Material", "Roughness texture", EntryType::TEXTURE); registerResourceSelection(metallic, "Material", "Metallic Texture", EntryType::TEXTURE); } @@ -43,7 +42,6 @@ namespace Metal { j["entityId"] = entityId; j["meshId"] = meshId; j["albedo"] = albedo; - j["normal"] = normal; j["roughness"] = roughness; j["metallic"] = metallic; j["albedoColor"] = {albedoColor.x, albedoColor.y, albedoColor.z}; @@ -61,7 +59,6 @@ namespace Metal { meshId = j.at("meshId").get(); albedo = j.at("albedo").get(); - normal = j.at("normal").get(); roughness = j.at("roughness").get(); metallic = j.at("metallic").get(); roughnessFactor = j.at("roughnessFactor").get(); diff --git a/src/repository/world/components/PrimitiveComponent.h b/src/repository/world/components/PrimitiveComponent.h index 9b37deff..a4392d85 100644 --- a/src/repository/world/components/PrimitiveComponent.h +++ b/src/repository/world/components/PrimitiveComponent.h @@ -10,7 +10,6 @@ namespace Metal { std::string meshId; std::string albedo; - std::string normal; std::string roughness; std::string metallic; glm::vec3 albedoColor{1, 1, 1}; diff --git a/src/repository/world/components/TransformComponent.cpp b/src/repository/world/components/TransformComponent.cpp index 119b5709..aa43ff86 100644 --- a/src/repository/world/components/TransformComponent.cpp +++ b/src/repository/world/components/TransformComponent.cpp @@ -20,14 +20,10 @@ namespace Metal { void TransformComponent::onUpdate(InspectableMember *member) { const auto e = static_cast(entityId); - bool isVolume = CTX.worldRepository.registry.all_of(e); bool isLight = CTX.worldRepository.registry.all_of >(e); if (isLight) { CTX.engineContext.setUpdateLights(true); } - if (isVolume) { - CTX.engineContext.setUpdateVolumes(true); - } if (member != nullptr && member->name == ROTATION) { rotation = normalize(glm::quat(rotationEuler * (glm::pi() / 180.f))); } diff --git a/src/repository/world/components/VolumeComponent.cpp b/src/repository/world/components/VolumeComponent.cpp index 4da49603..e961f161 100644 --- a/src/repository/world/components/VolumeComponent.cpp +++ b/src/repository/world/components/VolumeComponent.cpp @@ -10,6 +10,5 @@ namespace Metal { } void VolumeComponent::onUpdate(InspectableMember *member) { - CTX.engineContext.setUpdateVolumes(true); } } // Metal diff --git a/src/repository/world/impl/EntityComponent.h b/src/repository/world/impl/EntityComponent.h index ee998e69..8ed38696 100644 --- a/src/repository/world/impl/EntityComponent.h +++ b/src/repository/world/impl/EntityComponent.h @@ -10,14 +10,12 @@ namespace Metal { struct EntityComponent final : Inspectable, Serializable { - std::string onTile; std::string name = "New entity"; glm::vec3 color{}; bool isContainer = false; nlohmann::json toJson() const override { nlohmann::json j; - j["onTile"] = onTile; j["name"] = name; j["color"] = {color.x, color.y, color.z}; j["isContainer"] = isContainer; @@ -25,7 +23,6 @@ namespace Metal { } void fromJson(const nlohmann::json &j) override { - onTile = j.at("onTile").get(); name = j.at("name").get(); color.x = j.at("color")[0].get(); color.y = j.at("color")[1].get(); diff --git a/src/repository/world/impl/WorldGridRepository.cpp b/src/repository/world/impl/WorldGridRepository.cpp deleted file mode 100644 index 694d61cf..00000000 --- a/src/repository/world/impl/WorldGridRepository.cpp +++ /dev/null @@ -1,123 +0,0 @@ -#include "WorldGridRepository.h" - -#include "../../../context/ApplicationContext.h" - -namespace Metal { - bool WorldGridRepository::updateLoadedTiles() { - if (auto *center = getOrCreateTile(CTX.worldRepository.camera.position); - currentTile != center || prevSize != tiles.size()) { - hasMainTileChanged = true; - currentTile = center; - prevSize = tiles.size(); - loadedWorldTiles[0] = center; - for (int i = 0; i < 8; i++) { - if (!center->adjacentTiles[i].empty() && tiles.contains(center->adjacentTiles[i])) { - loadedWorldTiles[i + 1] = &tiles.at(center->adjacentTiles[i]); - } - } - return true; - } - return false; - } - - std::array &WorldGridRepository::getLoadedTiles() { - return loadedWorldTiles; - } - - WorldTile *WorldGridRepository::getOrCreateTile(const glm::vec3 &point) { - const int tileX = getTileLocation(point.x); - const int tileZ = getTileLocation(point.z); - const std::string id = TILE_ID(tileX, tileZ); - if (!tiles.contains(id)) { - addTile(point); - } - return &tiles.at(id); - } - - WorldTile *WorldGridRepository::getTile(const glm::vec3 &point) { - const int tileX = getTileLocation(point.x); - const int tileZ = getTileLocation(point.z); - const std::string id = TILE_ID(tileX, tileZ); - if (!tiles.contains(id)) { - return nullptr; - } - return &tiles.at(id); - } - - WorldTile *WorldGridRepository::getCurrentTile() const { - return currentTile; - } - - void WorldGridRepository::createIfAbsent(const int x, const int z) { - if (std::string id = TILE_ID(x, z); !tiles.contains(id)) { - LOG_INFO("Creating tile " + std::to_string(x) + " " + std::to_string(z) + " " + id); - tiles.insert({id, WorldTile(x, z, id)}); - } - } - - void WorldGridRepository::addTile(const glm::vec3 &point) { - const int x = getTileLocation(point.x); - const int z = getTileLocation(point.z); - std::string id = TILE_ID(x, z); - if (tiles.contains(id)) { - return; - } - tiles.insert({id, WorldTile(x, z, id)}); - - updateAdjacentTiles(&tiles.at(id)); - } - - void WorldGridRepository::updateAdjacentTiles(WorldTile *newTile) { - const int x = newTile->x; - const int z = newTile->z; - const std::array westTile{x, z - 1}; - const std::array eastTile{x, z + 1}; - const std::array northTile{x + 1, z}; - const std::array southTile{x - 1, z}; - const std::array northEastTile{x + 1, z + 1}; - const std::array northWestTile{x + 1, z - 1}; - const std::array southEastTile{x - 1, z + 1}; - const std::array southWestTile{x - 1, z - 1}; - - putAdjacentTile(westTile, newTile); - putAdjacentTile(eastTile, newTile); - putAdjacentTile(northTile, newTile); - putAdjacentTile(southTile, newTile); - putAdjacentTile(northEastTile, newTile); - putAdjacentTile(northWestTile, newTile); - putAdjacentTile(southEastTile, newTile); - putAdjacentTile(southWestTile, newTile); - } - - void WorldGridRepository::putAdjacentTile(const std::array &tileLocation, WorldTile *newTile) { - if (const std::string tileId = TILE_ID(tileLocation[0], tileLocation[1]); tiles.contains(tileId)) { - auto &tile = tiles.at(tileId); - tile.putAdjacentTile(newTile); - newTile->putAdjacentTile(&tile); - } - } - - void WorldGridRepository::removeTile(const std::string &id) { - const auto &tileToRemove = tiles.at(id); - tiles.erase(id); - for (auto &tile: tiles) { - tile.second.removeAdjacentTile(&tileToRemove); - } - } - - void WorldGridRepository::moveBetweenTiles(const EntityID entityId, WorldTile *previousWorldTile, - WorldTile *newWorldTile) const { - auto *entity = CTX.worldRepository.getEntity(entityId); - entity->registerChange(); - entity->freezeVersion(); - if (!entity->onTile.empty()) { - previousWorldTile->entities.erase( - std::ranges::remove(previousWorldTile->entities, entityId).begin(), - previousWorldTile->entities.end()); - newWorldTile->entities.push_back(entityId); - } else { - newWorldTile->entities.push_back(entityId); - } - entity->onTile = newWorldTile->id; - } -} // Metal diff --git a/src/repository/world/impl/WorldGridRepository.h b/src/repository/world/impl/WorldGridRepository.h deleted file mode 100644 index 96aabd4e..00000000 --- a/src/repository/world/impl/WorldGridRepository.h +++ /dev/null @@ -1,82 +0,0 @@ -#ifndef WORLDGRID_H -#define WORLDGRID_H -#include - -#include "WorldTile.h" -#include "../../../common/AbstractRuntimeComponent.h" -#include "../../../common/inspection/Inspectable.h" -#include "../../../enum/engine-definitions.h" -#include "../../../util/Serializable.h" - -namespace Metal { - class WorldGridRepository final : public AbstractRuntimeComponent, public Serializable { - std::unordered_map tiles{}; - std::array loadedWorldTiles{}; - WorldTile *currentTile = nullptr; - unsigned int prevSize = 0; - - public: - bool hasMainTileChanged = false; - - bool updateLoadedTiles(); - - explicit WorldGridRepository() - : AbstractRuntimeComponent() { - } - - static int getTileLocation(const float v) { - return static_cast(std::floor(v / TILE_SIZE) + 0.5); - } - - /** - * Returns current tile and its adjacent ones - * @return May contain null elements - */ - std::array &getLoadedTiles(); - - WorldTile *getOrCreateTile(const glm::vec3 &point); - - WorldTile *getCurrentTile() const; - - WorldTile *getTile(const glm::vec3 &point); - - void createIfAbsent(int x, int z); - - void addTile(const glm::vec3 &point); - - void updateAdjacentTiles(WorldTile *newTile); - - void putAdjacentTile(const std::array &tileLocation, WorldTile *newTile); - - void removeTile(const std::string &id); - - void moveBetweenTiles(EntityID entityId, WorldTile *previousWorldTile, WorldTile *newWorldTile) const; - - std::unordered_map &getTiles() { - return tiles; - } - - nlohmann::json toJson() const override { - nlohmann::json j; - nlohmann::json t; - for (auto const& [key, val] : tiles) { - t[key] = val.toJson(); - } - j["tiles"] = t; - return j; - } - - void fromJson(const nlohmann::json& j) override { - tiles.clear(); - if (j.contains("tiles")) { - for (auto const& [key, val] : j.at("tiles").items()) { - WorldTile tile; - tile.fromJson(val); - tiles.emplace(key, tile); - } - } - } - }; -} // Metal - -#endif //WORLDGRID_H diff --git a/src/repository/world/impl/WorldTile.h b/src/repository/world/impl/WorldTile.h deleted file mode 100644 index b8452ec4..00000000 --- a/src/repository/world/impl/WorldTile.h +++ /dev/null @@ -1,93 +0,0 @@ -#ifndef WORLDTILE_H -#define WORLDTILE_H -#include -#include -#include -#include - -#include "BoundingBox.h" -#include "../../../enum/engine-definitions.h" -#include "../../../service/voxel/impl/SparseVoxelOctreeBuilder.h" -#include "../../../util/Serializable.h" -#define TILE_SIZE 64 - -#define TILE_ID(x, z) (std::to_string(x) + "_" + std::to_string(z)) - -namespace Metal { - struct WorldTile final : Serializable { - std::array adjacentTiles{}; - int x; - int z; - std::string id; - bool loaded = false; - std::vector entities{}; - BoundingBox boundingBox{}; - int normalizedDistance = 0; - - void updateTiles(const WorldTile *adjacentWorldTile, const std::string &key) { - bool isWest = adjacentWorldTile->z < z && adjacentWorldTile->x == x; - bool isEast = adjacentWorldTile->z > z && adjacentWorldTile->x == x; - bool isNorth = adjacentWorldTile->x > x && adjacentWorldTile->z == z; - bool isSouth = adjacentWorldTile->x < x && adjacentWorldTile->z == z; - - bool isSouthEast = adjacentWorldTile->x < x && adjacentWorldTile->z > z; - bool isSouthWest = adjacentWorldTile->x < x && adjacentWorldTile->z < z; - bool isNorthEast = adjacentWorldTile->x > x && adjacentWorldTile->z > z; - bool isNorthWest = adjacentWorldTile->x > x && adjacentWorldTile->z < z; - - if (isWest) adjacentTiles[0] = key; - if (isNorth) adjacentTiles[1] = key; - if (isEast) adjacentTiles[2] = key; - if (isSouth) adjacentTiles[3] = key; - if (isSouthWest) adjacentTiles[4] = key; - if (isSouthEast) adjacentTiles[5] = key; - if (isNorthWest) adjacentTiles[6] = key; - if (isNorthEast) adjacentTiles[7] = key; - } - - explicit WorldTile(int x, int z, std::string id) - : x(x), z(z), id(std::move(id)) { - boundingBox.center.x = x * TILE_SIZE; - boundingBox.center.z = z * TILE_SIZE; - boundingBox.max = boundingBox.center + glm::vec3(TILE_SIZE / 2.0f, TILE_SIZE / 2.0f, TILE_SIZE / 2.0f); - boundingBox.min = boundingBox.center - glm::vec3(TILE_SIZE / 2.0f, TILE_SIZE / 2.0f, TILE_SIZE / 2.0f); - } - - explicit WorldTile(): x(0), z(0) { - } - - void putAdjacentTile(const WorldTile *adjacentWorldTile) { - updateTiles(adjacentWorldTile, adjacentWorldTile->id); - } - - void removeAdjacentTile(const WorldTile *adjacentWorldTile) { - updateTiles(adjacentWorldTile, ""); - } - - nlohmann::json toJson() const override { - nlohmann::json j; - j["adjacentTiles"] = adjacentTiles; - j["x"] = x; - j["z"] = z; - j["id"] = id; - j["loaded"] = loaded; - j["entities"] = entities; - j["boundingBox"] = boundingBox.toJson(); - j["normalizedDistance"] = normalizedDistance; - return j; - } - - void fromJson(const nlohmann::json& j) override { - adjacentTiles = j.at("adjacentTiles").get>(); - x = j.at("x").get(); - z = j.at("z").get(); - id = j.at("id").get(); - loaded = j.at("loaded").get(); - entities = j.at("entities").get>(); - boundingBox.fromJson(j.at("boundingBox")); - normalizedDistance = j.at("normalizedDistance").get(); - } - }; -} // Metal - -#endif //WORLDTILE_H diff --git a/src/service/material/MaterialImporterService.cpp b/src/service/material/MaterialImporterService.cpp index 82aeec99..a62e1794 100644 --- a/src/service/material/MaterialImporterService.cpp +++ b/src/service/material/MaterialImporterService.cpp @@ -8,7 +8,7 @@ #include "../../util/serialization-definitions.h" namespace Metal { - void MaterialImporterService::persistAllMaterials(const std::string &targetDir, const aiScene *scene, + void MaterialImporterService::collectMaterials(const std::string &targetDir, const aiScene *scene, std::unordered_map &materialMap, const std::string &rootDirectory, const std::stop_token &stopToken) const { @@ -65,17 +65,13 @@ namespace Metal { trySetFromType(materialData.albedo, aiTextureType_BASE_COLOR, "albedo"); trySetFromType(materialData.albedo, aiTextureType_DIFFUSE, "albedo"); - // Normal - trySetFromType(materialData.normal, aiTextureType_NORMALS, "normal"); - trySetFromType(materialData.normal, aiTextureType_NORMAL_CAMERA, "normal"); - // Metallic / Roughness trySetFromType(materialData.metallic, aiTextureType_METALNESS, "metallic"); trySetFromType(materialData.roughness, aiTextureType_DIFFUSE_ROUGHNESS, "roughness"); // If we didn't import any textures, don't create/persist a material at all. - if (materialData.albedo.empty() && materialData.normal.empty() && materialData.roughness.empty() && + if (materialData.albedo.empty() && materialData.roughness.empty() && materialData.metallic.empty()) { LOG_INFO("Skipping material " + std::to_string(i) + ": no textures associated"); continue; diff --git a/src/service/material/MaterialImporterService.h b/src/service/material/MaterialImporterService.h index d9e543d5..5bb7aff6 100644 --- a/src/service/material/MaterialImporterService.h +++ b/src/service/material/MaterialImporterService.h @@ -11,7 +11,6 @@ namespace Metal { struct MaterialData { std::string albedo; - std::string normal; std::string roughness; std::string metallic; }; @@ -19,7 +18,7 @@ namespace Metal { class MaterialImporterService final : public AbstractRuntimeComponent { public: - void persistAllMaterials(const std::string &targetDir, const aiScene *scene, + void collectMaterials(const std::string &targetDir, const aiScene *scene, std::unordered_map &materialMap, const std::string &rootDirectory, const std::stop_token &stopToken = {}) const; diff --git a/src/service/material/MaterialService.cpp b/src/service/material/MaterialService.cpp index 4099fbd8..0f4a6cf4 100644 --- a/src/service/material/MaterialService.cpp +++ b/src/service/material/MaterialService.cpp @@ -16,13 +16,7 @@ namespace Metal { materialData.ior = data.ior; materialData.isEmissive = data.isEmissive ? 1 : 0; - materialData.useAlbedoTexture = !data.albedo.empty(); - materialData.useNormalTexture = !data.normal.empty(); - materialData.useRoughnessTexture = !data.roughness.empty(); - materialData.useMetallicTexture = !data.metallic.empty(); - materialData.albedoTextureId = 0; - materialData.normalTextureId = 0; materialData.roughnessTextureId = 0; materialData.metallicTextureId = 0; @@ -32,12 +26,6 @@ namespace Metal { materialData.albedoTextureId = CTX.textureService.getTextureIndex(data.albedo); } } - if (!data.normal.empty()) { - auto *tex = CTX.textureService.create(data.normal); - if (tex != nullptr) { - materialData.normalTextureId = CTX.textureService.getTextureIndex(data.normal); - } - } if (!data.roughness.empty()) { auto *tex = CTX.textureService.create(data.roughness); if (tex != nullptr) { diff --git a/src/service/mesh/EntityAssetData.h b/src/service/mesh/EntityAssetData.h index b713a98a..2b4e1845 100644 --- a/src/service/mesh/EntityAssetData.h +++ b/src/service/mesh/EntityAssetData.h @@ -13,7 +13,6 @@ namespace Metal { int id; std::string albedo; - std::string normal; std::string roughness; std::string metallic; glm::vec3 albedoColor{1, 1, 1}; @@ -32,7 +31,6 @@ namespace Metal { j["parentEntity"] = parentEntity; j["albedo"] = albedo; - j["normal"] = normal; j["roughness"] = roughness; j["metallic"] = metallic; j["albedoColor"] = {albedoColor.x, albedoColor.y, albedoColor.z}; @@ -52,7 +50,6 @@ namespace Metal { parentEntity = j.at("parentEntity").get(); albedo = j.value("albedo", ""); - normal = j.value("normal", ""); roughness = j.value("roughness", ""); metallic = j.value("metallic", ""); if (j.contains("albedoColor")) { diff --git a/src/service/mesh/MeshService.cpp b/src/service/mesh/MeshService.cpp index ef92160e..79c448a7 100644 --- a/src/service/mesh/MeshService.cpp +++ b/src/service/mesh/MeshService.cpp @@ -29,16 +29,14 @@ namespace Metal { instance->dataBuffer = CTX.bufferService.createBuffer( id + "_data", sizeof(VertexData) * data->data.size(), - VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | VK_BUFFER_USAGE_ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY_BIT_KHR | - VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT, + VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | VK_BUFFER_USAGE_ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY_BIT_KHR | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT, data->data.data(), true); instance->indexBuffer = CTX.bufferService.createBuffer( id + "_indices", sizeof(unsigned int) * data->indices.size(), - VK_BUFFER_USAGE_INDEX_BUFFER_BIT | VK_BUFFER_USAGE_ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY_BIT_KHR | - VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT, + VK_BUFFER_USAGE_INDEX_BUFFER_BIT | VK_BUFFER_USAGE_ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY_BIT_KHR | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT, data->indices.data(), true); @@ -69,7 +67,6 @@ namespace Metal { if (data != nullptr) { mesh.albedo = data->albedo; - mesh.normal = data->normal; mesh.roughness = data->roughness; mesh.metallic = data->metallic; mesh.albedoColor = data->albedoColor; diff --git a/src/service/mesh/SceneImporterService.cpp b/src/service/mesh/SceneImporterService.cpp index 848be621..fa4db88f 100644 --- a/src/service/mesh/SceneImporterService.cpp +++ b/src/service/mesh/SceneImporterService.cpp @@ -73,7 +73,7 @@ namespace Metal { fs::path absolutePath = fs::absolute(pathToFile); fs::path directoryPath = absolutePath.parent_path(); - CTX.materialImporterService.persistAllMaterials(targetDir, scene, materialsMap, directoryPath.string(), + CTX.materialImporterService.collectMaterials(targetDir, scene, materialsMap, directoryPath.string(), stopToken); if (stopToken.stop_requested()) { @@ -130,7 +130,6 @@ namespace Metal { if (materialsMap.contains(matIndex)) { const auto &matData = materialsMap.at(matIndex); childMeshNode.albedo = matData.albedo; - childMeshNode.normal = matData.normal; childMeshNode.roughness = matData.roughness; childMeshNode.metallic = matData.metallic; } diff --git a/src/service/transform/TransformService.cpp b/src/service/transform/TransformService.cpp index 595ec535..06e02fc1 100644 --- a/src/service/transform/TransformService.cpp +++ b/src/service/transform/TransformService.cpp @@ -42,8 +42,6 @@ namespace Metal { LOG_WARN("Entity will not be transformed because it is set to static " + std::to_string(st->getEntityId())); return; } - translation = glm::vec3(st->model[3]); - auto *previousTile = CTX.worldGridRepository.getOrCreateTile(translation); auxMat42 = glm::identity(); auxMat42 = glm::translate(auxMat42, st->translation); // Translation @@ -53,10 +51,6 @@ namespace Metal { st->model = auxMat4 * auxMat42; st->freezeVersion(); - translation = glm::vec3(st->model[3]); - auto *newTile = CTX.worldGridRepository.getOrCreateTile(translation); - - CTX.worldGridRepository.moveBetweenTiles(st->getEntityId(), previousTile, newTile); if (CTX.worldRepository.registry.all_of(static_cast::entity_type>(st->getEntityId()))) { CTX.rayTracingService.markDirty(); } diff --git a/src/service/volumes/VolumeService.cpp b/src/service/volumes/VolumeService.cpp deleted file mode 100644 index a29eaa28..00000000 --- a/src/service/volumes/VolumeService.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include "VolumeService.h" -#include "../../context/ApplicationContext.h" -#include "../../repository/world/components/VolumeComponent.h" -#include "../buffer/BufferInstance.h" -#include "../../enum/EngineResourceIDs.h" - -namespace Metal { - void VolumeService::registerVolumes() { - } - - void VolumeService::onSync() { - items.clear(); - - registerVolumes(); - - if (!items.empty()) { - CTX.engineContext.currentFrame->getResourceAs(RID_VOLUMES_BUFFER)->update(items.data()); - } - } -} // Metal diff --git a/src/service/volumes/VolumeService.h b/src/service/volumes/VolumeService.h deleted file mode 100644 index 4ef7fb97..00000000 --- a/src/service/volumes/VolumeService.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef VOLUME_SERVICE_H -#define VOLUME_SERVICE_H -#include - -#include "../../common/AbstractRuntimeComponent.h" -#include "../../dto/buffers/VolumeData.h" - -namespace Metal { - - class VolumeService final : public AbstractRuntimeComponent { - std::vector items{}; - - void registerVolumes(); - public: - explicit VolumeService() - : AbstractRuntimeComponent() { - } - - void onSync() override; - - unsigned int getCount() const { - return items.size(); - } - }; -} // Metal - -#endif //LIGHTSSERVICE_H diff --git a/src/service/voxel/VoxelImporterService.cpp b/src/service/voxel/VoxelImporterService.cpp index 2c304ff5..3a89664a 100644 --- a/src/service/voxel/VoxelImporterService.cpp +++ b/src/service/voxel/VoxelImporterService.cpp @@ -51,9 +51,8 @@ namespace Metal { openvdb::initialize(); }); - auto *targetTile = CTX.worldGridRepository.getTile(glm::vec3(0, 0, 0)); int resolution = 12; - auto builder = SparseVoxelOctreeBuilder(targetTile->boundingBox, 32); + auto builder = SparseVoxelOctreeBuilder(BoundingBox{glm::vec3(-32, -32, -32), glm::vec3(32, 32, 32), glm::vec3(0, 0, 0)}, 32); try { openvdb::io::File file(sourcePath); diff --git a/src/service/world/WorldGridService.cpp b/src/service/world/WorldGridService.cpp deleted file mode 100644 index 951e2fb1..00000000 --- a/src/service/world/WorldGridService.cpp +++ /dev/null @@ -1,62 +0,0 @@ -#include "WorldGridService.h" - -#include "../../context/ApplicationContext.h" -#include "../log/LogService.h" - -namespace Metal { - void WorldGridService::addMissingTiles() { - const int numberOfTiles = CTX.engineRepository.numberOfTiles; - if (const int squared = numberOfTiles * numberOfTiles; - squared > CTX.worldGridRepository.getTiles().size()) { - LOG_INFO("Adding missing tiles " + std::to_string(squared) + " " + std::to_string(CTX.worldGridRepository.getTiles().size())); - const int half = numberOfTiles / 2; - for (int x = -half; x < half; x++) { - for (int z = -half; z < half; z++) { - CTX.worldGridRepository.createIfAbsent(x, z); - changed = true; - } - } - } - } - - bool WorldGridService::IsTileOutsideBounds(WorldTile *tile, int half, int min) { - return tile->z >= half || tile->z <= min || tile->x >= half || tile->x <= min; - } - - void WorldGridService::removeExtraTiles() { - const int numberOfTiles = CTX.engineRepository.numberOfTiles; - if (const int squared = numberOfTiles * numberOfTiles; - squared < CTX.worldGridRepository.getTiles().size()) { - LOG_INFO("Removing extra tiles " + std::to_string(CTX.worldGridRepository.getTiles().size()) + " " + std::to_string(squared)); - - const int min = -numberOfTiles; - for (auto it = CTX.worldGridRepository.getTiles().begin(); - it != CTX.worldGridRepository.getTiles().end();) { - auto &tile = it->second; - if (IsTileOutsideBounds(&tile, numberOfTiles / 2, min)) { - LOG_INFO("Removing tile " + tile.id); - // TODO - ADD DISPOSAL OF THINGS RATED TO THE TILE LIKE TERRAIN, FOLIAGE, MATERIALS AND VOXELS - it = CTX.worldGridRepository.getTiles().erase(it); - changed = true; - } else { - ++it; - } - } - } - } - - void WorldGridService::onSync() { - if (!CTX.worldGridRepository.updateLoadedTiles()) { - return; - } - prevTile = CTX.worldGridRepository.getCurrentTile(); - addMissingTiles(); - removeExtraTiles(); - if (changed) { - changed = false; - for (auto &tile: CTX.worldGridRepository.getTiles()) { - CTX.worldGridRepository.updateAdjacentTiles(&tile.second); - } - } - } -} // Metal diff --git a/src/service/world/WorldGridService.h b/src/service/world/WorldGridService.h deleted file mode 100644 index 5f2b5322..00000000 --- a/src/service/world/WorldGridService.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef WORLDGRIDSERVICE_H -#define WORLDGRIDSERVICE_H -#include "../../common/AbstractRuntimeComponent.h" - -namespace Metal { - struct WorldTile; - - class WorldGridService final : public AbstractRuntimeComponent { - WorldTile *prevTile = nullptr; - bool changed = false; - - public: - explicit WorldGridService() - : AbstractRuntimeComponent() { - } - - void addMissingTiles(); - - static bool IsTileOutsideBounds(WorldTile *tile, int half, int min); - - void removeExtraTiles(); - - void onSync() override; - }; -} // Metal - -#endif //WORLDGRIDSERVICE_H diff --git a/src/util/ShaderUtil.cpp b/src/util/ShaderUtil.cpp index 4ff976fc..e75c5148 100644 --- a/src/util/ShaderUtil.cpp +++ b/src/util/ShaderUtil.cpp @@ -173,7 +173,6 @@ namespace Metal { for (auto &entry: LightTypes::getEntries()) { source = "#define " + entry.first + " " + std::to_string(entry.second) + "\n" + source; } - source = "#define TILE_SIZE " + std::to_string(TILE_SIZE) + std::string("\n") + source; source = "#define PI_2 6.28318530718\n" + source; source = "#define PI 3.14159265\n" + source; From 130f499369bf3a82ba7cdde92227eb5cb2446368 Mon Sep 17 00:00:00 2001 From: facobackup Date: Wed, 4 Mar 2026 21:58:06 -0300 Subject: [PATCH 03/18] Fixed mesh buffer update IMproved path tracer --- resources/shaders/rt/HWRayTracing.rchit | 51 ++++---- resources/shaders/util/PixelShading.glsl | 125 ++++++++----------- src/service/raytracing/RayTracingService.cpp | 2 - src/service/voxel/VoxelImporterService.cpp | 79 ++++++------ 4 files changed, 116 insertions(+), 141 deletions(-) diff --git a/resources/shaders/rt/HWRayTracing.rchit b/resources/shaders/rt/HWRayTracing.rchit index f89c4a2f..9e5fd219 100644 --- a/resources/shaders/rt/HWRayTracing.rchit +++ b/resources/shaders/rt/HWRayTracing.rchit @@ -1,7 +1,7 @@ #extension GL_EXT_ray_tracing: require #extension GL_EXT_nonuniform_qualifier: enable -#extension GL_EXT_shader_explicit_arithmetic_types_int64 : require -#extension GL_EXT_buffer_reference2 : require +#extension GL_EXT_shader_explicit_arithmetic_types_int64: require +#extension GL_EXT_buffer_reference2: require #include "../util/HWRayTracingUtil.glsl" #define MESH_METADATA_SET 7 @@ -18,11 +18,11 @@ struct VertexData { float u, v; }; -layout(buffer_reference, std430) readonly buffer Vertices { +layout (buffer_reference, std430) readonly buffer Vertices { VertexData vertices[]; }; -layout(buffer_reference, std430) readonly buffer Indices { +layout (buffer_reference, std430) readonly buffer Indices { uint indices[]; }; @@ -42,11 +42,11 @@ void main() { VertexData v2 = vBuffer.vertices[i2]; const vec3 barycentrics = vec3(1.0 - attribs.x - attribs.y, attribs.x, attribs.y); - + vec3 n0 = vec3(v0.nx, v0.ny, v0.nz); vec3 n1 = vec3(v1.nx, v1.ny, v1.nz); vec3 n2 = vec3(v2.nx, v2.ny, v2.nz); - + vec2 uv0 = vec2(v0.u, v0.v); vec2 uv1 = vec2(v1.u, v1.v); vec2 uv2 = vec2(v2.u, v2.v); @@ -60,7 +60,6 @@ void main() { payload.hitNormal = normalize(vec3(gl_ObjectToWorldEXT * vec4(normal, 0.0))); payload.uv = uv; - uint matIndex = metadata.materialIndex; payload.renderIndex = metadata.renderIndex; vec3 baseColor = vec3(1.0); @@ -71,27 +70,25 @@ void main() { float ior = 1.45; bool isEmissive = false; - if (matIndex != 0u) { - if (metadata.albedoTexture != 0u) { - baseColor = texture(textureArray[nonuniformEXT(metadata.albedoTexture)], uv).rgb; - } else { - baseColor = metadata.albedo; - } - if (metadata.roughnessTexture != 0u) { - roughness = texture(textureArray[nonuniformEXT(metadata.roughnessTexture)], uv).r; - } else { - roughness = metadata.roughness; - } - if (metadata.metallicTexture != 0u) { - metallic = texture(textureArray[nonuniformEXT(metadata.metallicTexture)], uv).r; - } else { - metallic = metadata.metallic; - } - transmission = metadata.transmission; - thickness = metadata.thickness; - ior = metadata.ior; - isEmissive = metadata.isEmissive == 1u; + if (metadata.albedoTexture != 0u) { + baseColor = texture(textureArray[nonuniformEXT(metadata.albedoTexture)], uv).rgb; + } else { + baseColor = metadata.albedo; + } + if (metadata.roughnessTexture != 0u) { + roughness = texture(textureArray[nonuniformEXT(metadata.roughnessTexture)], uv).r; + } else { + roughness = metadata.roughness; + } + if (metadata.metallicTexture != 0u) { + metallic = texture(textureArray[nonuniformEXT(metadata.metallicTexture)], uv).r; + } else { + metallic = metadata.metallic; } + transmission = metadata.transmission; + thickness = metadata.thickness; + ior = metadata.ior; + isEmissive = metadata.isEmissive == 1u; payload.material.baseColor = baseColor; payload.material.roughness = max(roughness, 0.015); diff --git a/resources/shaders/util/PixelShading.glsl b/resources/shaders/util/PixelShading.glsl index 8514b173..7be5d306 100644 --- a/resources/shaders/util/PixelShading.glsl +++ b/resources/shaders/util/PixelShading.glsl @@ -3,26 +3,18 @@ #include "../CreateRay.glsl" -struct BounceInfo { +struct PathInfo { MaterialInfo material; SurfaceInteraction interaction; vec3 throughput; - vec3 indirectLight; + vec3 radiance; }; -void computeRadiance(inout BounceInfo bounceInfo) -{ - if (bounceInfo.material.isEmissive) - { - vec3 emission = bounceInfo.material.baseColor * pushConstants.pathTracingEmissiveFactor; - bounceInfo.indirectLight += bounceInfo.throughput * emission; - return; - } - - vec3 directRadiance = vec3(0); +void addDirectLighting(inout PathInfo pathInfo) { + vec3 wo = -pathInfo.interaction.incomingRayDir; + vec3 Ld = vec3(0); - for (int i = 0; i < int(globalData.lightsCount); ++i) - { + for (int i = 0; i < int(globalData.lightsCount); ++i) { Light l = lightBuffer.items[i]; l.color.rgb *= l.color.a; @@ -30,68 +22,80 @@ void computeRadiance(inout BounceInfo bounceInfo) vec3 f; float scatteringPdf; - directRadiance += calculateDirectLight(l, bounceInfo.interaction, bounceInfo.material, wi, f, scatteringPdf); + Ld += calculateDirectLight(l, pathInfo.interaction, pathInfo.material, wi, f, scatteringPdf); } - bounceInfo.indirectLight += bounceInfo.throughput * directRadiance; + pathInfo.radiance += pathInfo.throughput * Ld; } -vec3 calculateIndirectLighting(MaterialInfo material, SurfaceInteraction interaction) { - if (pushConstants.pathTracerBounces == 0) return vec3(0); - - BounceInfo bounceInfo; - bounceInfo.indirectLight = vec3(0); - bounceInfo.throughput = vec3(1); - bounceInfo.material = material; - bounceInfo.interaction = interaction; +vec3 tracePath(vec3 rayDirection, MaterialInfo material, SurfaceInteraction interaction) { + PathInfo pathInfo; + pathInfo.radiance = vec3(0); + pathInfo.throughput = vec3(1); + pathInfo.material = material; + pathInfo.interaction = interaction; + pathInfo.interaction.incomingRayDir = rayDirection; + + // First hit might be emissive + if (pathInfo.material.isEmissive) { + return pathInfo.material.baseColor * pushConstants.pathTracingEmissiveFactor; + } for (uint j = 0; j < pushConstants.pathTracerBounces; j++) { + // Direct Lighting + addDirectLighting(pathInfo); + + // Sample next direction vec3 wi; float pdf; vec3 X = vec3(0.), Y = vec3(0.); - directionOfAnisotropicity(bounceInfo.interaction.normal, X, Y); - bounceInfo.interaction.tangent = X; - bounceInfo.interaction.binormal = Y; + directionOfAnisotropicity(pathInfo.interaction.normal, X, Y); + pathInfo.interaction.tangent = X; + pathInfo.interaction.binormal = Y; - vec3 f = bsdfSample(wi, -bounceInfo.interaction.incomingRayDir, X, Y, pdf, bounceInfo.interaction, bounceInfo.material); - f *= abs(dot(wi, bounceInfo.interaction.normal)); + vec3 f = bsdfSample(wi, -pathInfo.interaction.incomingRayDir, X, Y, pdf, pathInfo.interaction, pathInfo.material); + f *= abs(dot(wi, pathInfo.interaction.normal)); if (pdf < EPSILON || dot(f, f) < EPSILON) break; - bounceInfo.throughput *= f / pdf; + pathInfo.throughput *= f / pdf; + + // Russian Roulette + if (j >= 3) { + float q = max(0.05, 1.0 - max(pathInfo.throughput.r, max(pathInfo.throughput.g, pathInfo.throughput.b))); + if (random() < q) break; + pathInfo.throughput /= (1.0 - q); + } float bias = 0.001; - vec3 rayOrigin = bounceInfo.interaction.point + (dot(wi, bounceInfo.interaction.normal) > 0.0 ? 1.0 : -1.0) * bounceInfo.interaction.normal * bias; + vec3 rayOrigin = pathInfo.interaction.point + (dot(wi, pathInfo.interaction.normal) > 0.0 ? 1.0 : -1.0) * pathInfo.interaction.normal * bias; - payload.hit = true; - traceRayEXT(topLevelAS, gl_RayFlagsOpaqueEXT, 0xFF, 0, 0, 0, rayOrigin, 0.001, wi, 1000.0, 0); + payload.hit = false; + traceRayEXT(topLevelAS, gl_RayFlagsOpaqueEXT, 0xFF, 0, 0, 0, rayOrigin, 0.001, wi, 10000.0, 0); if (!payload.hit) { if (atmosphereData.isAtmosphereEnabled != 0) { - bounceInfo.material.baseColor = calculate_sky_luminance_rgb(normalize(atmosphereData.sunPosition), wi, 2.0f) * 0.05f; - bounceInfo.material.isEmissive = true; - bounceInfo.interaction.point = rayOrigin + wi * 1000.0; // Placeholder point for atmosphere - computeRadiance(bounceInfo); + vec3 skyLuminance = calculate_sky_luminance_rgb(normalize(atmosphereData.sunPosition), wi, 2.0f) * 0.05f; + pathInfo.radiance += pathInfo.throughput * skyLuminance; } break; } - bounceInfo.material = payload.material; - bounceInfo.interaction.normal = payload.hitNormal; - bounceInfo.interaction.point = payload.hitPosition; - bounceInfo.interaction.incomingRayDir = wi; + pathInfo.material = payload.material; + pathInfo.interaction.normal = payload.hitNormal; + pathInfo.interaction.point = payload.hitPosition; + pathInfo.interaction.incomingRayDir = wi; - computeRadiance(bounceInfo); + if (pathInfo.material.isEmissive) { + pathInfo.radiance += pathInfo.throughput * pathInfo.material.baseColor * pushConstants.pathTracingEmissiveFactor; + break; // Stop at emissive for now, or continue if you want multiple emissive hits + } } - return bounceInfo.indirectLight; + return pathInfo.radiance; } vec3 calculatePixelColor(vec3 rayDirection, in vec2 texCoords, MaterialInfo material, SurfaceInteraction interaction) { vec3 L = vec3(0.); - vec3 beta = vec3(1.); - - vec3 wi; - interaction.incomingRayDir = rayDirection; material.subsurface = 0.; material.specular = 0.; @@ -102,33 +106,8 @@ vec3 calculatePixelColor(vec3 rayDirection, in vec2 texCoords, MaterialInfo mate material.sheen = 0.; material.sheenTint = 0.; - vec3 X = vec3(0.), Y = vec3(0.); - directionOfAnisotropicity(interaction.normal, X, Y); - interaction.tangent = X; - interaction.binormal = Y; - for (uint i = 0; i < pushConstants.pathTracerSamples; i++) { - vec3 f = vec3(0.); - float scatteringPdf = 0.; - vec3 Ld = vec3(0); - for (uint i = 0; i < globalData.lightsCount; i++) { - Light l = lightBuffer.items[i]; - l.color.rgb *= l.color.a; - Ld += beta * calculateDirectLight(l, interaction, material, wi, f, scatteringPdf) ; - } - - L += Ld; - - if (pushConstants.pathTracerBounces > 0 && pushConstants.pathTracerMultiplier > 0) { - L += beta * calculateIndirectLighting(material, interaction) * pushConstants.pathTracerMultiplier; - } - - if (scatteringPdf > EPSILON && dot(f, f) > EPSILON) { - beta *= f / scatteringPdf; - - float bias = 0.001; - interaction.point += (dot(wi, interaction.normal) > 0.0 ? 1.0 : -1.0) * interaction.normal * bias; - } + L += tracePath(rayDirection, material, interaction); } return L / pushConstants.pathTracerSamples; diff --git a/src/service/raytracing/RayTracingService.cpp b/src/service/raytracing/RayTracingService.cpp index 0cc1376f..065ba2f4 100644 --- a/src/service/raytracing/RayTracingService.cpp +++ b/src/service/raytracing/RayTracingService.cpp @@ -87,8 +87,6 @@ namespace Metal { } void RayTracingService::updateMeshMaterials() { - if (!meshMetadata.empty()) return; - bool changed = false; auto view = CTX.worldRepository.registry.view(); diff --git a/src/service/voxel/VoxelImporterService.cpp b/src/service/voxel/VoxelImporterService.cpp index 3a89664a..6923f58e 100644 --- a/src/service/voxel/VoxelImporterService.cpp +++ b/src/service/voxel/VoxelImporterService.cpp @@ -52,45 +52,46 @@ namespace Metal { }); int resolution = 12; - auto builder = SparseVoxelOctreeBuilder(BoundingBox{glm::vec3(-32, -32, -32), glm::vec3(32, 32, 32), glm::vec3(0, 0, 0)}, 32); - - try { - openvdb::io::File file(sourcePath); - file.open(); - openvdb::GridPtrVecPtr gridsPtr = file.getGrids(); - file.close(); - if (!gridsPtr) { - throw std::runtime_error("No grids found in VDB file."); - } - - if (stopToken.stop_requested()) { - return 0; - } - - for (const auto &gridPtr: *gridsPtr) { - if (auto floatGrid = openvdb::gridPtrCast(gridPtr)) { - for (auto iter = floatGrid->beginValueOn(); iter; ++iter) { - if (stopToken.stop_requested()) { - return 0; - } - const openvdb::Coord xyz = iter.getCoord(); - const openvdb::Vec3d worldPos = floatGrid->transform().indexToWorld(xyz); - const glm::vec3 volumePoint(worldPos.x(), worldPos.y(), worldPos.z()); - - const glm::vec3 albedo(0.5f); - const glm::vec3 normal(0.5f); - const VoxelData data{albedo, normal, true}; - - builder.insert(resolution, volumePoint, data); - } - break; - } - } - } catch (const std::exception &e) { - throw std::runtime_error("VDB conversion failed: " + std::string(e.what())); - } - - return serialize(builder, outPath); + // auto builder = SparseVoxelOctreeBuilder(BoundingBox{glm::vec3(-32, -32, -32), glm::vec3(32, 32, 32), glm::vec3(0, 0, 0)}, 32); + // + // try { + // openvdb::io::File file(sourcePath); + // file.open(); + // openvdb::GridPtrVecPtr gridsPtr = file.getGrids(); + // file.close(); + // if (!gridsPtr) { + // throw std::runtime_error("No grids found in VDB file."); + // } + // + // if (stopToken.stop_requested()) { + // return 0; + // } + // + // for (const auto &gridPtr: *gridsPtr) { + // if (auto floatGrid = openvdb::gridPtrCast(gridPtr)) { + // for (auto iter = floatGrid->beginValueOn(); iter; ++iter) { + // if (stopToken.stop_requested()) { + // return 0; + // } + // const openvdb::Coord xyz = iter.getCoord(); + // const openvdb::Vec3d worldPos = floatGrid->transform().indexToWorld(xyz); + // const glm::vec3 volumePoint(worldPos.x(), worldPos.y(), worldPos.z()); + // + // const glm::vec3 albedo(0.5f); + // const glm::vec3 normal(0.5f); + // const VoxelData data{albedo, normal, true}; + // + // builder.insert(resolution, volumePoint, data); + // } + // break; + // } + // } + // } catch (const std::exception &e) { + // throw std::runtime_error("VDB conversion failed: " + std::string(e.what())); + // } + + // return serialize(builder, outPath); + return 0; } void VoxelImporterService::FillStorage(SparseVoxelOctreeBuilder &builder, unsigned int &bufferIndex, From cb19417710848f26efcd71196b728e61c2a43b3c Mon Sep 17 00:00:00 2001 From: facobackup Date: Sat, 7 Mar 2026 17:16:10 -0300 Subject: [PATCH 04/18] Refactored and streamlined render passes: replaced SelectedDotPass with SelectionOutlinePass, introduced SelectionIDPass for improved entity selection handling. Removed unused AccumulationPass and tidied related resources. --- CMakeLists.txt | 8 ++-- resources/shaders/TemporalAccumulation.comp | 2 +- resources/shaders/rt/HWRayTracing.rgen | 9 ++++- resources/shaders/tools/SelectedDot.frag | 33 +++++------------ resources/shaders/tools/SelectionID.frag | 11 ++++++ .../{SelectedDot.vert => SelectionID.vert} | 0 .../editor/abstract/form/FormPanel.cpp | 8 ++-- .../dock-spaces/viewport/EngineFramePanel.cpp | 23 +++++------- src/context/engine/EngineContext.cpp | 10 ++++- .../compute-pass/impl/AccumulationPass.cpp | 23 ------------ .../compute-pass/impl/AccumulationPass.h | 17 --------- .../compute-pass/impl/HWRayTracingPass.cpp | 24 +++++------- .../compute-pass/impl/HWRayTracingPass.h | 7 ---- .../frame-builder/EngineFrameBuilder.cpp | 15 +++++--- .../engine/frame-builder/EngineFrameBuilder.h | 2 +- .../structures/FramebufferBuilder.cpp | 2 +- .../structures/FramebufferBuilder.h | 5 +-- .../frame-builder/structures/PassBuilder.cpp | 12 +++--- ...electedDotPass.cpp => SelectionIDPass.cpp} | 20 +++++----- .../render-pass/impl/tools/SelectionIDPass.h | 22 +++++++++++ .../impl/tools/SelectionOutlinePass.cpp | 37 +++++++++++++++++++ ...lectedDotPass.h => SelectionOutlinePass.h} | 4 +- src/enum/EngineResourceIDs.h | 4 +- src/enum/PassType.h | 5 ++- .../descriptor/DescriptorSetService.cpp | 6 +-- .../framebuffer/FrameBufferAttachment.h | 1 - .../framebuffer/FrameBufferService.cpp | 17 +++++---- src/service/framebuffer/FrameBufferService.h | 19 ++-------- 28 files changed, 174 insertions(+), 172 deletions(-) create mode 100644 resources/shaders/tools/SelectionID.frag rename resources/shaders/tools/{SelectedDot.vert => SelectionID.vert} (100%) delete mode 100644 src/context/engine/compute-pass/impl/AccumulationPass.cpp delete mode 100644 src/context/engine/compute-pass/impl/AccumulationPass.h rename src/context/engine/render-pass/impl/tools/{SelectedDotPass.cpp => SelectionIDPass.cpp} (83%) create mode 100644 src/context/engine/render-pass/impl/tools/SelectionIDPass.h create mode 100644 src/context/engine/render-pass/impl/tools/SelectionOutlinePass.cpp rename src/context/engine/render-pass/impl/tools/{SelectedDotPass.h => SelectionOutlinePass.h} (71%) diff --git a/CMakeLists.txt b/CMakeLists.txt index fdd78ae6..d4bd3f89 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -218,8 +218,8 @@ add_executable( src/dto/Notification.h src/enum/NotificationSeverity.h src/service/voxel/impl/SparseVoxelOctreeData.h - src/context/engine/render-pass/impl/tools/SelectedDotPass.cpp - src/context/engine/render-pass/impl/tools/SelectedDotPass.h + src/context/engine/render-pass/impl/tools/SelectionOutlinePass.cpp + src/context/engine/render-pass/impl/tools/SelectionOutlinePass.h src/service/picking/PickingService.cpp src/service/picking/PickingService.h src/service/voxel/SVOInstance.h @@ -232,6 +232,8 @@ add_executable( src/repository/world/components/PlaneLightComponent.h src/context/engine/render-pass/impl/tools/IconsPass.cpp src/context/engine/render-pass/impl/tools/IconsPass.h + src/context/engine/render-pass/impl/tools/SelectionIDPass.cpp + src/context/engine/render-pass/impl/tools/SelectionIDPass.h src/repository/editor/EditorRepository.cpp src/dto/push-constant/GridPushConstant.h src/context/engine/compute-pass/AbstractComputePass.cpp @@ -242,8 +244,6 @@ add_executable( src/service/material/MaterialService.cpp src/service/material/MaterialService.h src/enum/LightType.h - src/context/engine/compute-pass/impl/AccumulationPass.cpp - src/context/engine/compute-pass/impl/AccumulationPass.h src/service/lights/LightService.cpp src/service/lights/LightService.h src/repository/world/components/VolumeComponent.cpp diff --git a/resources/shaders/TemporalAccumulation.comp b/resources/shaders/TemporalAccumulation.comp index faaaf7e6..1eaeb052 100644 --- a/resources/shaders/TemporalAccumulation.comp +++ b/resources/shaders/TemporalAccumulation.comp @@ -49,7 +49,7 @@ void main() { prevNormal = imageLoad(previousNormalImage, prevCoord).rgb; vec4 prevDenoised = imageLoad(previousDenoisedImage, prevCoord); prevDenoisedColor = prevDenoised.rgb; - historyLen = prevDenoised.a; + historyLen = globalData.pathTracerAccumulationCount - 1; // Validation checks if (currentIdx != prevPositionIndex.a) valid = false; diff --git a/resources/shaders/rt/HWRayTracing.rgen b/resources/shaders/rt/HWRayTracing.rgen index ba7aeb59..fa4acdff 100644 --- a/resources/shaders/rt/HWRayTracing.rgen +++ b/resources/shaders/rt/HWRayTracing.rgen @@ -161,6 +161,11 @@ void main() { finalColor = volumetricColor.rgb * volumetricColor.a + finalColor * (1.0 - volumetricColor.a); } - finalColor = max(vec3(0), finalColor); - imageStore(outputImage, ivec2(gl_LaunchIDEXT.xy), vec4(finalColor, 1)); + vec4 prev = imageLoad(outputImage, ivec2(gl_LaunchIDEXT.xy)); + float count = min(float(globalData.pathTracerMaxSamples), max(globalData.pathTracerAccumulationCount, 1.0)); + vec3 color = prev.rgb * (1.0 - 1.0 / count) + finalColor.rgb * (1.0 / count); + + imageStore(outputImage, ivec2(gl_LaunchIDEXT.xy), vec4(color, 1)); + + } diff --git a/resources/shaders/tools/SelectedDot.frag b/resources/shaders/tools/SelectedDot.frag index 2a176237..22a5ce79 100644 --- a/resources/shaders/tools/SelectedDot.frag +++ b/resources/shaders/tools/SelectedDot.frag @@ -1,6 +1,6 @@ #include "../GlobalDataBuffer.glsl" -layout (set = 0, binding = 1, rgba32f) uniform readonly image2D gBufferPositionIndex; +layout (set = 0, binding = 1) uniform sampler2D selectionIdSampler; layout (location = 0) out vec4 outColor; @@ -11,8 +11,10 @@ layout (push_constant) uniform Push { } push; void main() { - uint currentIndex = uint(abs(imageLoad(gBufferPositionIndex, ivec2(gl_FragCoord.xy)).a)); - + uint currentIndex = uint(abs(texelFetch(selectionIdSampler, ivec2(gl_FragCoord.xy), 0).r)); + if (currentIndex == 0) { + discard; + } int thickness = int(push.selectionColor.a); bool isBoundary = false; @@ -32,9 +34,9 @@ void main() { break; } - uint neighborIndex = uint(abs(imageLoad(gBufferPositionIndex, neighborPixel).a)); + uint neighborIndex = uint(abs(texelFetch(selectionIdSampler, neighborPixel, 0).r)); - if (neighborIndex != push.renderIndex + 1) { + if (neighborIndex != currentIndex) { isBoundary = true; break; } @@ -42,25 +44,10 @@ void main() { if (isBoundary) break; } - bool isDiff = currentIndex != (push.renderIndex + 1); - if (isBoundary && !isDiff) { - outColor = vec4(push.selectionColor.rgb, 1.0); - } else { - int dotSpacing = 10; - int dotRadius = 2; - - vec2 gridIndex = floor(gl_FragCoord.xy / float(dotSpacing)); - vec2 gridCenter = (gridIndex + 0.5) * float(dotSpacing); - - float dist = distance(gl_FragCoord.xy, gridCenter); - if (dist >= dotRadius) { - discard; - } + if (isBoundary) { outColor = vec4(push.selectionColor.rgb, 1.0); - - if (isDiff) { - outColor.a = .5; - } + return; } + discard; } \ No newline at end of file diff --git a/resources/shaders/tools/SelectionID.frag b/resources/shaders/tools/SelectionID.frag new file mode 100644 index 00000000..a2b45ccf --- /dev/null +++ b/resources/shaders/tools/SelectionID.frag @@ -0,0 +1,11 @@ +layout (location = 0) out float outID; + +layout (push_constant) uniform Push { + mat4 model; + vec4 selectionColor; + uint renderIndex; +} push; + +void main() { + outID = float(push.renderIndex + 1); +} diff --git a/resources/shaders/tools/SelectedDot.vert b/resources/shaders/tools/SelectionID.vert similarity index 100% rename from resources/shaders/tools/SelectedDot.vert rename to resources/shaders/tools/SelectionID.vert diff --git a/src/context/editor/abstract/form/FormPanel.cpp b/src/context/editor/abstract/form/FormPanel.cpp index afa405a9..3a48ef77 100644 --- a/src/context/editor/abstract/form/FormPanel.cpp +++ b/src/context/editor/abstract/form/FormPanel.cpp @@ -17,19 +17,19 @@ namespace Metal { void FormPanel::processFields(Inspectable *inspection) { - std::unordered_map groups{}; - const auto rootPanel = new AccordionPanel(); + std::unordered_map groups{}; + const auto rootPanel = new ChildPanel(); rootPanel->setFilter(&searchFilter); appendChild(rootPanel); rootPanel->setTitle(std::string(inspection->getIcon()) + " " + inspection->getTitle()); for (const auto &field: inspection->getFields()) { if (!groups.contains(field->group)) { - const auto panel = new ChildPanel(); + const auto panel = new AccordionPanel(); panel->setFilter(&searchFilter); groups[field->group] = panel; rootPanel->appendChild(panel); } - ChildPanel *group = groups[field->group]; + AccordionPanel *group = groups[field->group]; group->setTitle(field->group); AbstractFormFieldPanel *fieldPanel = nullptr; switch (field->type) { diff --git a/src/context/editor/dock-spaces/viewport/EngineFramePanel.cpp b/src/context/editor/dock-spaces/viewport/EngineFramePanel.cpp index 31df28a7..34a88418 100644 --- a/src/context/editor/dock-spaces/viewport/EngineFramePanel.cpp +++ b/src/context/editor/dock-spaces/viewport/EngineFramePanel.cpp @@ -32,26 +32,28 @@ namespace Metal { VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, STORAGE_BUFFER) .addBuffer(RID_MESH_METADATA_BUFFER, MAX_MESH_INSTANCES * sizeof(MeshMetadata), VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, STORAGE_BUFFER) - .addTexture(RID_RAW_RENDERED_FRAME, gBufferW, gBufferH) .addTexture(RID_ACCUMULATED_FRAME, gBufferW, gBufferH) .addTexture(RID_GBUFFER_POSITION_INDEX, gBufferW, gBufferH, VK_FORMAT_R32G32B32A32_SFLOAT) .addTexture(RID_GBUFFER_NORMAL, gBufferW, gBufferH, VK_FORMAT_R16G16B16A16_SFLOAT) - .addTexture(RID_PREVIOUS_COLOR, gBufferW, gBufferH, VK_FORMAT_R16G16B16A16_SFLOAT) .addTexture(RID_PREVIOUS_POSITION_INDEX, gBufferW, gBufferH, VK_FORMAT_R32G32B32_SFLOAT) // I noticed current position is rgba32f, but let's check. .addTexture(RID_PREVIOUS_NORMAL, gBufferW, gBufferH, VK_FORMAT_R16G16B16A16_SFLOAT) .addTexture(RID_DENOISED_FRAME, gBufferW, gBufferH, VK_FORMAT_R16G16B16A16_SFLOAT) .addTexture(RID_TEMPORAL_OUTPUT, gBufferW, gBufferH, VK_FORMAT_R16G16B16A16_SFLOAT) .addTexture(RID_PREVIOUS_DENOISED_FRAME, gBufferW, gBufferH, VK_FORMAT_R16G16B16A16_SFLOAT) + .addFramebuffer(RID_SELECTION_FBO, gBufferW, gBufferH, glm::vec4(0, 0, 0, 0)) + .addColor(VK_FORMAT_R16_SFLOAT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) .addFramebuffer(RID_POST_PROCESSING_FBO, gBufferW, gBufferH, glm::vec4(0, 0, 0, 0)) - .addColor("Color", VK_FORMAT_R16G16B16A16_SFLOAT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) + .addColor(VK_FORMAT_R16G16B16A16_SFLOAT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) .addComputeCommandBuffer(RID_COMPUTE_CB) .addPass(RAY_TRACING, RID_COMPUTE_CB) .addPass(ACCUMULATION, RID_COMPUTE_CB) .addPass(TEMPORAL_ACCUMULATION, RID_COMPUTE_CB) .addPass(SPATIAL_FILTER, RID_COMPUTE_CB) + .addCommandBuffer(RID_SELECTION_CB, RID_SELECTION_FBO) + .addPass(SELECTION_ID, RID_SELECTION_CB) .addCommandBuffer(RID_POST_PROCESSING_CB, RID_POST_PROCESSING_FBO) .addPass(POST_PROCESSING, RID_POST_PROCESSING_CB) - .addPass(SELECTED_DOT, RID_POST_PROCESSING_CB) + .addPass(SELECTION_OUTLINE, RID_POST_PROCESSING_CB) .addPass(GRID, RID_POST_PROCESSING_CB) .addPass(ICONS, RID_POST_PROCESSING_CB) .build(); @@ -101,21 +103,16 @@ namespace Metal { return; } - auto *rawRenderedFrame = engineFrame->getResourceAs(RID_RAW_RENDERED_FRAME); - if (!rawRenderedFrame) { + auto *gBufferPositionIndex = engineFrame->getResourceAs(RID_GBUFFER_POSITION_INDEX); + if (!gBufferPositionIndex) { return; } - const auto width = rawRenderedFrame->width; - const auto height = rawRenderedFrame->height; + const auto width = gBufferPositionIndex->width; + const auto height = gBufferPositionIndex->height; const uint32_t pixelX = std::min(static_cast(u * static_cast(width)), width - 1); const uint32_t pixelY = std::min(static_cast(v * static_cast(height)), height - 1); - auto *gBufferPositionIndex = engineFrame->getResourceAs(RID_GBUFFER_POSITION_INDEX); - if (!gBufferPositionIndex) { - return; - } - const auto picked = CTX.pickingService.pickEntityFromGBuffer(gBufferPositionIndex, pixelX, pixelY); CTX.selectionService.clearSelection(); CTX.selectionService.addSelected(picked.value_or(EMPTY_ENTITY)); diff --git a/src/context/engine/EngineContext.cpp b/src/context/engine/EngineContext.cpp index bdfbc5cc..df30fc92 100644 --- a/src/context/engine/EngineContext.cpp +++ b/src/context/engine/EngineContext.cpp @@ -73,7 +73,7 @@ namespace Metal { void EngineContext::updateGlobalData() { auto &camera = CTX.worldRepository.camera; - auto *fbo = currentFrame->getResourceAs( RID_POST_PROCESSING_FBO); + auto *fbo = currentFrame->getResourceAs(RID_POST_PROCESSING_FBO); globalDataUBO.previousProjView = globalDataUBO.projView; globalDataUBO.viewMatrix = camera.viewMatrix; globalDataUBO.projectionMatrix = camera.projectionMatrix; @@ -88,7 +88,10 @@ namespace Metal { globalDataUBO.globalFrameCount++; globalDataUBO.outputRes = {fbo->bufferWidth, fbo->bufferHeight}; globalDataUBO.pathTracerMaxSamples = CTX.engineRepository.pathTracerMaxSamples; - globalDataUBO.denoiserEnabled = CTX.engineRepository.denoiserEnabled && (globalDataUBO.debugFlag == LIT || globalDataUBO.debugFlag == LIGHTING_ONLY)? 1 : 0; + globalDataUBO.denoiserEnabled = CTX.engineRepository.denoiserEnabled && ( + globalDataUBO.debugFlag == LIT || globalDataUBO.debugFlag == LIGHTING_ONLY) + ? 1 + : 0; entt::registry ® = CTX.worldRepository.registry; auto view = reg.view(); @@ -104,6 +107,9 @@ namespace Metal { atmosphereUBO.scatteringAlbedo = atmo.scatteringAlbedo; atmosphereUBO.samples = atmo.samples; atmosphereUBO.sunPosition = atmo.sunPosition; + } else { + atmosphereUBO.isVolumeEnabled = 0; + atmosphereUBO.isAtmosphereEnabled = 0; } currentFrame->getResourceAs(RID_GLOBAL_DATA)->update(&globalDataUBO); diff --git a/src/context/engine/compute-pass/impl/AccumulationPass.cpp b/src/context/engine/compute-pass/impl/AccumulationPass.cpp deleted file mode 100644 index 9effbae3..00000000 --- a/src/context/engine/compute-pass/impl/AccumulationPass.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#include "AccumulationPass.h" -#include "../../../ApplicationContext.h" -#include "../../../../service/pipeline/PipelineBuilder.h" -#include "../../../../service/texture/TextureInstance.h" -#include "../../../../enum/EngineResourceIDs.h" - -namespace Metal { - void AccumulationPass::onInitialize() { - PipelineBuilder builder = PipelineBuilder::Of("PathTracerAccumulation.comp") - .addBufferBinding(getScopedResourceId(RID_GLOBAL_DATA)) - .addStorageImageBinding(getScopedResourceId(RID_RAW_RENDERED_FRAME)) - .addStorageImageBinding(getScopedResourceId(RID_ACCUMULATED_FRAME)); - pipelineInstance = CTX.pipelineService.createPipeline(builder); - } - - void AccumulationPass::onSync() { - auto *accumulatedFrame = frame->getResourceAs(RID_ACCUMULATED_FRAME); - auto *rawRenderedFrame = frame->getResourceAs(RID_RAW_RENDERED_FRAME); - syncWriting(accumulatedFrame->vkImage); - recordImageDispatch(accumulatedFrame, 8, 8); - endWriting(rawRenderedFrame->vkImage); - } -} // Metal diff --git a/src/context/engine/compute-pass/impl/AccumulationPass.h b/src/context/engine/compute-pass/impl/AccumulationPass.h deleted file mode 100644 index e319ee7b..00000000 --- a/src/context/engine/compute-pass/impl/AccumulationPass.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef ACCUMULATIONPASS_H -#define ACCUMULATIONPASS_H -#include "../AbstractComputePass.h" - -namespace Metal { - class AccumulationPass final : public AbstractComputePass { - public: - explicit AccumulationPass(const std::string &id) : AbstractComputePass(id) {} - - void onSync() override; - - void onInitialize() override; - - }; -} // Metal - -#endif //ACCUMULATIONPASS_H diff --git a/src/context/engine/compute-pass/impl/HWRayTracingPass.cpp b/src/context/engine/compute-pass/impl/HWRayTracingPass.cpp index def48539..2d89d321 100644 --- a/src/context/engine/compute-pass/impl/HWRayTracingPass.cpp +++ b/src/context/engine/compute-pass/impl/HWRayTracingPass.cpp @@ -20,7 +20,7 @@ namespace Metal { .setPushConstantsSize(sizeof(HWRayTracingPushConstant)) .addBufferBinding(getScopedResourceId(RID_GLOBAL_DATA)) .addAccelerationStructureBinding(CTX.rayTracingService.getTLAS()) - .addStorageImageBinding(getScopedResourceId(RID_RAW_RENDERED_FRAME)) + .addStorageImageBinding(getScopedResourceId(RID_ACCUMULATED_FRAME)) .addStorageImageBinding(getScopedResourceId(RID_GBUFFER_POSITION_INDEX)) .addStorageImageBinding(getScopedResourceId(RID_GBUFFER_NORMAL)) .addBufferBinding(getScopedResourceId(RID_LIGHT_BUFFER)) @@ -40,28 +40,22 @@ namespace Metal { anyMeshes = true; } - rawRenderedFrame = frame->getResourceAs(RID_RAW_RENDERED_FRAME); - accumulatedFrame = frame->getResourceAs(RID_ACCUMULATED_FRAME); - gBufferPositionIndex = frame->getResourceAs(RID_GBUFFER_POSITION_INDEX); - gBufferNormal = frame->getResourceAs(RID_GBUFFER_NORMAL); - previousColor = frame->getResourceAs(RID_PREVIOUS_COLOR); - previousPositionIndex = frame->getResourceAs(RID_PREVIOUS_POSITION_INDEX); - previousNormal = frame->getResourceAs(RID_PREVIOUS_NORMAL); + auto *accumulatedFrame = frame->getResourceAs(RID_ACCUMULATED_FRAME); + auto *gBufferPositionIndex = frame->getResourceAs(RID_GBUFFER_POSITION_INDEX); + auto *gBufferNormal = frame->getResourceAs(RID_GBUFFER_NORMAL); + auto *previousPositionIndex = frame->getResourceAs(RID_PREVIOUS_POSITION_INDEX); + auto *previousNormal = frame->getResourceAs(RID_PREVIOUS_NORMAL); if (isFirstRun || CTX.engineContext.isCameraUpdated() || CTX.engineContext.isGISettingsUpdated() || CTX.engineContext.isUpdateLights()) { - clearTexture(rawRenderedFrame->vkImage); clearTexture(accumulatedFrame->vkImage); CTX.engineContext.resetPathTracerAccumulationCount(); isFirstRun = false; } - // Copy current to previous before writing new values - copyTexture(rawRenderedFrame, previousColor); copyTexture(gBufferPositionIndex, previousPositionIndex); copyTexture(gBufferNormal, previousNormal); - startWriting(rawRenderedFrame->vkImage); startWriting(gBufferPositionIndex->vkImage); startWriting(gBufferNormal->vkImage); @@ -87,11 +81,11 @@ namespace Metal { &pipelineInstance->missRegion, &pipelineInstance->hitRegion, &pipelineInstance->callableRegion, - rawRenderedFrame->width, - rawRenderedFrame->height, + accumulatedFrame->width, + accumulatedFrame->height, 1); - endWriting(rawRenderedFrame->vkImage); + endWriting(accumulatedFrame->vkImage); endWriting(gBufferPositionIndex->vkImage); endWriting(gBufferNormal->vkImage); } diff --git a/src/context/engine/compute-pass/impl/HWRayTracingPass.h b/src/context/engine/compute-pass/impl/HWRayTracingPass.h index 55e50e7a..bdd574e5 100644 --- a/src/context/engine/compute-pass/impl/HWRayTracingPass.h +++ b/src/context/engine/compute-pass/impl/HWRayTracingPass.h @@ -7,13 +7,6 @@ namespace Metal { class HWRayTracingPass final : public AbstractComputePass { bool isFirstRun = true; HWRayTracingPushConstant pushConstant{}; - TextureInstance *rawRenderedFrame = nullptr; - TextureInstance *accumulatedFrame = nullptr; - TextureInstance *gBufferPositionIndex = nullptr; - TextureInstance *gBufferNormal = nullptr; - TextureInstance *previousColor = nullptr; - TextureInstance *previousPositionIndex = nullptr; - TextureInstance *previousNormal = nullptr; public: explicit HWRayTracingPass(const std::string &id) : AbstractComputePass(id) { diff --git a/src/context/engine/frame-builder/EngineFrameBuilder.cpp b/src/context/engine/frame-builder/EngineFrameBuilder.cpp index 51a69988..9b870737 100644 --- a/src/context/engine/frame-builder/EngineFrameBuilder.cpp +++ b/src/context/engine/frame-builder/EngineFrameBuilder.cpp @@ -8,7 +8,7 @@ #include "EngineFrame.h" #include "../../ApplicationContext.h" #include "../passes/CommandBufferRecorder.h" -#include "../render-pass/impl/tools/SelectedDotPass.h" +#include "../render-pass/impl/tools/SelectionOutlinePass.h" namespace Metal { EngineFrameBuilder::EngineFrameBuilder(std::string frameId) : frameId(std::move(frameId)) { @@ -28,8 +28,8 @@ namespace Metal { return *this; } - EngineFrameBuilder &EngineFrameBuilder::addColor(std::string id, VkFormat format, VkImageUsageFlagBits usage) { - dynamic_cast(currentBuilder.get())->addColor(frameId + "_" + id, format, usage, nullptr); + EngineFrameBuilder &EngineFrameBuilder::addColor(VkFormat format, VkImageUsageFlagBits usage) { + dynamic_cast(currentBuilder.get())->addColor(format, usage, nullptr); return *this; } @@ -54,7 +54,9 @@ namespace Metal { EngineFrameBuilder &EngineFrameBuilder::addBuffer(const std::string &id, VkDeviceSize size, VkMemoryPropertyFlags properties, BufferType type) { currentBuilder = std::make_shared( - frameId + "_" + id, size, type == UNIFORM_BUFFER ? VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT : VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, + frameId + "_" + id, size, type == UNIFORM_BUFFER + ? VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT + : VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, properties, type); builders.push_back(currentBuilder); return *this; @@ -68,8 +70,9 @@ namespace Metal { } EngineFrameBuilder &EngineFrameBuilder::addCommandBuffer(const std::string &id, const std::string &framebufferId, - const bool clearBuffer) { - currentBuilder = std::make_shared(frameId + "_" + id, frameId + "_" + framebufferId, clearBuffer); + const bool clearBuffer) { + currentBuilder = std::make_shared( + frameId + "_" + id, frameId + "_" + framebufferId, clearBuffer); builders.push_back(currentBuilder); return *this; } diff --git a/src/context/engine/frame-builder/EngineFrameBuilder.h b/src/context/engine/frame-builder/EngineFrameBuilder.h index 58584b87..fd42fc69 100644 --- a/src/context/engine/frame-builder/EngineFrameBuilder.h +++ b/src/context/engine/frame-builder/EngineFrameBuilder.h @@ -29,7 +29,7 @@ namespace Metal { EngineFrameBuilder &addFramebuffer(const std::string &id); - EngineFrameBuilder &addColor(std::string id, VkFormat format, VkImageUsageFlagBits usage); + EngineFrameBuilder &addColor(VkFormat format, VkImageUsageFlagBits usage); EngineFrameBuilder &addDepth(); diff --git a/src/context/engine/frame-builder/structures/FramebufferBuilder.cpp b/src/context/engine/frame-builder/structures/FramebufferBuilder.cpp index 6073ff99..02d973f0 100644 --- a/src/context/engine/frame-builder/structures/FramebufferBuilder.cpp +++ b/src/context/engine/frame-builder/structures/FramebufferBuilder.cpp @@ -18,7 +18,7 @@ namespace Metal { fbo = framebufferService.createFrameBuffer(id, w, h, clearColor); for (const auto& attachment : attachments) { - framebufferService.createAttachment(attachment.id.c_str(), attachment.format, attachment.usage, fbo); + framebufferService.createAttachment(attachment.format, attachment.usage, fbo); } if (hasDepth) { diff --git a/src/context/engine/frame-builder/structures/FramebufferBuilder.h b/src/context/engine/frame-builder/structures/FramebufferBuilder.h index 80f7d3b0..f5ebead5 100644 --- a/src/context/engine/frame-builder/structures/FramebufferBuilder.h +++ b/src/context/engine/frame-builder/structures/FramebufferBuilder.h @@ -9,7 +9,6 @@ namespace Metal { struct FrameBufferInstance; struct FramebufferAttachmentBuilder { - std::string id; VkFormat format; VkImageUsageFlagBits usage; FrameBufferInstance *framebuffer; @@ -29,9 +28,9 @@ namespace Metal { ResourceType getType() override; - void addColor(std::string id, VkFormat format, VkImageUsageFlagBits usage, + void addColor( VkFormat format, VkImageUsageFlagBits usage, FrameBufferInstance *framebuffer) { - attachments.push_back({std::move(id), format, usage, framebuffer}); + attachments.push_back({ format, usage, framebuffer}); } void addDepth() { diff --git a/src/context/engine/frame-builder/structures/PassBuilder.cpp b/src/context/engine/frame-builder/structures/PassBuilder.cpp index e0db905b..56ce5f6a 100644 --- a/src/context/engine/frame-builder/structures/PassBuilder.cpp +++ b/src/context/engine/frame-builder/structures/PassBuilder.cpp @@ -1,12 +1,12 @@ #include "PassBuilder.h" #include "../../render-pass/impl/PostProcessingPass.h" #include "../../compute-pass/impl/HWRayTracingPass.h" -#include "../../compute-pass/impl/AccumulationPass.h" #include "../../compute-pass/impl/TemporalAccumulationPass.h" #include "../../compute-pass/impl/SpatialFilterPass.h" -#include "../../render-pass/impl/tools/SelectedDotPass.h" +#include "../../render-pass/impl/tools/SelectionOutlinePass.h" #include "../../render-pass/impl/tools/GridPass.h" #include "../../render-pass/impl/tools/IconsPass.h" +#include "../../render-pass/impl/tools/SelectionIDPass.h" namespace Metal { RuntimeResource* PassBuilder::build() { @@ -15,18 +15,18 @@ namespace Metal { return new PostProcessingPass(id); case RAY_TRACING: return new HWRayTracingPass(id); - case ACCUMULATION: - return new AccumulationPass(id); case TEMPORAL_ACCUMULATION: return new TemporalAccumulationPass(id); case SPATIAL_FILTER: return new SpatialFilterPass(id); - case SELECTED_DOT: - return new SelectedDotPass(id); + case SELECTION_OUTLINE: + return new SelectionOutlinePass(id); case GRID: return new GridPass(id); case ICONS: return new IconsPass(id); + case SELECTION_ID: + return new SelectionIDPass(id); default: return nullptr; } diff --git a/src/context/engine/render-pass/impl/tools/SelectedDotPass.cpp b/src/context/engine/render-pass/impl/tools/SelectionIDPass.cpp similarity index 83% rename from src/context/engine/render-pass/impl/tools/SelectedDotPass.cpp rename to src/context/engine/render-pass/impl/tools/SelectionIDPass.cpp index 8451a465..0390e04b 100644 --- a/src/context/engine/render-pass/impl/tools/SelectedDotPass.cpp +++ b/src/context/engine/render-pass/impl/tools/SelectionIDPass.cpp @@ -1,4 +1,4 @@ -#include "SelectedDotPass.h" +#include "SelectionIDPass.h" #include "../../../../../context/ApplicationContext.h" #include "../../../../../repository/world/components/TransformComponent.h" @@ -7,26 +7,24 @@ #include "../../../../../enum/EngineResourceIDs.h" namespace Metal { - void SelectedDotPass::onInitialize() { + void SelectionIDPass::onInitialize() { PipelineBuilder builder = PipelineBuilder::Of( - getScopedResourceId(RID_POST_PROCESSING_FBO), - "tools/SelectedDot.vert", - "tools/SelectedDot.frag" + getScopedResourceId(RID_SELECTION_FBO), + "tools/SelectionID.vert", + "tools/SelectionID.frag" ) - .setBlendEnabled() .setPrepareForMesh() - .setCullMode(VK_CULL_MODE_BACK_BIT) + .setCullMode(VK_CULL_MODE_NONE) .setPushConstantsSize(sizeof(SelectedDotPushConstant)) - .addBufferBinding(getScopedResourceId(RID_GLOBAL_DATA)) - .addStorageImageBinding(getScopedResourceId(RID_GBUFFER_POSITION_INDEX)); + .addBufferBinding(getScopedResourceId(RID_GLOBAL_DATA)); pipelineInstance = CTX.pipelineService.createPipeline(builder); } - bool SelectedDotPass::shouldRun() { + bool SelectionIDPass::shouldRun() { return !CTX.editorRepository.selected.empty(); } - void SelectedDotPass::onSync() { + void SelectionIDPass::onSync() { auto &worldRepository = CTX.worldRepository; for (const auto &pair: CTX.editorRepository.selected) { if (!pair.second) { diff --git a/src/context/engine/render-pass/impl/tools/SelectionIDPass.h b/src/context/engine/render-pass/impl/tools/SelectionIDPass.h new file mode 100644 index 00000000..31957bac --- /dev/null +++ b/src/context/engine/render-pass/impl/tools/SelectionIDPass.h @@ -0,0 +1,22 @@ +#ifndef SELECTIONIDPASS_H +#define SELECTIONIDPASS_H + +#include "../../AbstractRenderPass.h" +#include "../../../../../dto/push-constant/SelectedDotPushConstant.h" + +namespace Metal { + class SelectionIDPass final : public AbstractRenderPass { + SelectedDotPushConstant pushConstant{}; + + public: + explicit SelectionIDPass(const std::string &id) : AbstractRenderPass(id) {} + + void onInitialize() override; + + bool shouldRun() override; + + void onSync() override; + }; +} // Metal + +#endif // SELECTIONIDPASS_H diff --git a/src/context/engine/render-pass/impl/tools/SelectionOutlinePass.cpp b/src/context/engine/render-pass/impl/tools/SelectionOutlinePass.cpp new file mode 100644 index 00000000..6e1ca4a4 --- /dev/null +++ b/src/context/engine/render-pass/impl/tools/SelectionOutlinePass.cpp @@ -0,0 +1,37 @@ +#include "SelectionOutlinePass.h" + +#include "../../../../../context/ApplicationContext.h" +#include "../../../../../repository/world/components/TransformComponent.h" +#include "../../../../../dto/push-constant/SelectedDotPushConstant.h" +#include "../../../../../service/pipeline/PipelineBuilder.h" +#include "../../../../../enum/EngineResourceIDs.h" + +namespace Metal { + void SelectionOutlinePass::onInitialize() { + PipelineBuilder builder = PipelineBuilder::Of( + getScopedResourceId(RID_POST_PROCESSING_FBO), + "QUAD.vert", + "tools/SelectedDot.frag" + ) + .setBlendEnabled() + .setPushConstantsSize(sizeof(SelectedDotPushConstant)) + .addBufferBinding(getScopedResourceId(RID_GLOBAL_DATA)) + .addFboBinding(getScopedResourceId(RID_SELECTION_FBO), 0); + pipelineInstance = CTX.pipelineService.createPipeline(builder); + } + + bool SelectionOutlinePass::shouldRun() { + return !CTX.editorRepository.selected.empty(); + } + + void SelectionOutlinePass::onSync() { + + pushConstant.selectionColor.x = CTX.editorRepository.selectionColor.x; + pushConstant.selectionColor.y = CTX.editorRepository.selectionColor.y; + pushConstant.selectionColor.z = CTX.editorRepository.selectionColor.z; + pushConstant.selectionColor.w = CTX.editorRepository.selectionOutlineThickness; + + recordPushConstant(&pushConstant); + recordDrawSimpleInstanced(3, 1); + } +} // Metal diff --git a/src/context/engine/render-pass/impl/tools/SelectedDotPass.h b/src/context/engine/render-pass/impl/tools/SelectionOutlinePass.h similarity index 71% rename from src/context/engine/render-pass/impl/tools/SelectedDotPass.h rename to src/context/engine/render-pass/impl/tools/SelectionOutlinePass.h index f9a8ad0e..2e620341 100644 --- a/src/context/engine/render-pass/impl/tools/SelectedDotPass.h +++ b/src/context/engine/render-pass/impl/tools/SelectionOutlinePass.h @@ -5,11 +5,11 @@ #include "../../../../../dto/push-constant/SelectedDotPushConstant.h" namespace Metal { - class SelectedDotPass final : public AbstractRenderPass { + class SelectionOutlinePass final : public AbstractRenderPass { SelectedDotPushConstant pushConstant{}; public: - explicit SelectedDotPass(const std::string &id) : AbstractRenderPass(id) {} + explicit SelectionOutlinePass(const std::string &id) : AbstractRenderPass(id) {} void onInitialize() override; diff --git a/src/enum/EngineResourceIDs.h b/src/enum/EngineResourceIDs.h index e0a26f1e..17803b29 100644 --- a/src/enum/EngineResourceIDs.h +++ b/src/enum/EngineResourceIDs.h @@ -7,10 +7,8 @@ namespace Metal { inline constexpr const char* RID_MESH_METADATA_BUFFER = "meshMetadataBuffer"; inline constexpr const char* RID_GBUFFER_POSITION_INDEX = "gBufferPositionIndex"; inline constexpr const char* RID_GBUFFER_NORMAL = "gBufferNormal"; - inline constexpr const char* RID_PREVIOUS_COLOR = "previousColor"; inline constexpr const char* RID_PREVIOUS_POSITION_INDEX = "previousPositionIndex"; inline constexpr const char* RID_PREVIOUS_NORMAL = "previousNormal"; - inline constexpr const char* RID_RAW_RENDERED_FRAME = "rawRenderedFrame"; inline constexpr const char* RID_ACCUMULATED_FRAME = "accumulatedFrame"; inline constexpr const char* RID_DENOISED_FRAME = "denoisedFrame"; inline constexpr const char* RID_TEMPORAL_OUTPUT = "temporalOutput"; @@ -20,6 +18,8 @@ namespace Metal { inline constexpr const char* RID_POST_PROCESSING_CB = "PostProcessingCB"; inline constexpr const char* RID_ATMOSPHERE_DATA = "atmosphereData"; inline constexpr const char* RID_VOLUMES_BUFFER = "volumesBuffer"; + inline constexpr const char* RID_SELECTION_FBO = "selectionFBO"; + inline constexpr const char* RID_SELECTION_CB = "selectionCB"; } #endif //ENGINE_RESOURCE_IDS_H diff --git a/src/enum/PassType.h b/src/enum/PassType.h index 38d3cbb2..d0c67489 100644 --- a/src/enum/PassType.h +++ b/src/enum/PassType.h @@ -8,9 +8,10 @@ namespace Metal { TEMPORAL_ACCUMULATION, SPATIAL_FILTER, POST_PROCESSING, - SELECTED_DOT, + SELECTION_OUTLINE, GRID, - ICONS + ICONS, + SELECTION_ID }; } diff --git a/src/service/descriptor/DescriptorSetService.cpp b/src/service/descriptor/DescriptorSetService.cpp index cde1e917..81f7093a 100644 --- a/src/service/descriptor/DescriptorSetService.cpp +++ b/src/service/descriptor/DescriptorSetService.cpp @@ -11,7 +11,7 @@ namespace Metal { DescriptorInstance *DescriptorSetService::createDescriptor(const PipelineBuilder &pipelineBuilder, const std::string &id, VkShaderStageFlags stageFlags) { auto *descriptorInstance = createResourceInstance(id); - + for (auto &builder : pipelineBuilder.resourceBindings) { DescriptorBinding binding{}; binding.bindingPoint = builder.bindingPoint; @@ -70,7 +70,7 @@ namespace Metal { binding.stageFlags = static_cast(stageFlags); descriptorInstance->bindings.push_back(binding); } - + updateDescriptor(descriptorInstance); return descriptorInstance; } @@ -93,7 +93,7 @@ namespace Metal { unsigned int attachmentIndex) { auto attachment = framebuffer->attachments[attachmentIndex]; if (attachment->imageDescriptor == nullptr) { - attachment->imageDescriptor = createResourceInstance(std::string(attachment->name)); + attachment->imageDescriptor = createResourceInstance(framebuffer->getId() + std::to_string(attachmentIndex)); attachment->imageDescriptor->bindings.push_back(DescriptorBinding::Of(VK_SHADER_STAGE_FRAGMENT_BIT, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 0, CTX.vulkanContext.vkImageSampler, diff --git a/src/service/framebuffer/FrameBufferAttachment.h b/src/service/framebuffer/FrameBufferAttachment.h index 78784105..1c865e8f 100644 --- a/src/service/framebuffer/FrameBufferAttachment.h +++ b/src/service/framebuffer/FrameBufferAttachment.h @@ -10,7 +10,6 @@ namespace Metal { VkFormat format = VK_FORMAT_MAX_ENUM; DescriptorInstance *imageDescriptor = nullptr; bool depth = false; - const char *name = nullptr; void dispose() const; }; diff --git a/src/service/framebuffer/FrameBufferService.cpp b/src/service/framebuffer/FrameBufferService.cpp index 387394c1..73c8e478 100644 --- a/src/service/framebuffer/FrameBufferService.cpp +++ b/src/service/framebuffer/FrameBufferService.cpp @@ -10,7 +10,7 @@ #include "../../context/ApplicationContext.h" namespace Metal { - void FrameBufferService::createSampler(bool linear, VkSampler &vkImageSampler) { + void FrameBufferService::createSampler(bool linear, VkSampler &vkImageSampler) { VkSamplerCreateInfo samplerCreateInfo{}; samplerCreateInfo.magFilter = linear ? VK_FILTER_LINEAR : VK_FILTER_NEAREST; samplerCreateInfo.minFilter = linear ? VK_FILTER_LINEAR : VK_FILTER_NEAREST; @@ -30,7 +30,8 @@ namespace Metal { &vkImageSampler)); } - FrameBufferInstance *FrameBufferService::createFrameBuffer(const std::string &id, const unsigned w, const unsigned h, glm::vec4 clearColor) { + FrameBufferInstance *FrameBufferService::createFrameBuffer(const std::string &id, const unsigned w, + const unsigned h, glm::vec4 clearColor) { auto *framebuffer = createResourceInstance(id); framebuffer->bufferWidth = w; framebuffer->bufferHeight = h; @@ -41,25 +42,24 @@ namespace Metal { void FrameBufferService::createDepthAttachment(FrameBufferInstance *framebuffer) const { VkFormat depthFormat = VulkanUtils::GetValidDepthFormat(CTX.vulkanContext.physDevice.physical_device); - const auto att = createAttachmentInternal("Depth attachment", depthFormat, + const auto att = createAttachmentInternal(depthFormat, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, framebuffer); att->depth = true; } - void FrameBufferService::createAttachment(const char *name, VkFormat format, VkImageUsageFlagBits usage, + void FrameBufferService::createAttachment(VkFormat format, VkImageUsageFlagBits usage, FrameBufferInstance *framebuffer) const { - const auto att = createAttachmentInternal(name, format, + const auto att = createAttachmentInternal(format, usage, framebuffer); att->depth = false; } std::shared_ptr FrameBufferService::createAttachmentInternal( - const char *name, VkFormat format, + VkFormat format, VkImageUsageFlagBits usage, FrameBufferInstance *framebuffer) const { std::shared_ptr attachment = std::make_shared(); - attachment->name = name; framebuffer->attachments.push_back(attachment); attachment->format = format; @@ -90,7 +90,8 @@ namespace Metal { image.initialLayout = layout; image.sharingMode = VK_SHARING_MODE_EXCLUSIVE; - VulkanUtils::CheckVKResult(vkCreateImage(CTX.vulkanContext.device.device, &image, nullptr, &attachment->vkImage)); + VulkanUtils::CheckVKResult( + vkCreateImage(CTX.vulkanContext.device.device, &image, nullptr, &attachment->vkImage)); VkMemoryAllocateInfo memAlloc{}; VkMemoryRequirements memReqs; diff --git a/src/service/framebuffer/FrameBufferService.h b/src/service/framebuffer/FrameBufferService.h index 2e18e6cf..ffd6ecaf 100644 --- a/src/service/framebuffer/FrameBufferService.h +++ b/src/service/framebuffer/FrameBufferService.h @@ -12,35 +12,24 @@ namespace Metal { struct FrameBufferAttachment; struct FrameBufferInstance; - /** - * Responsible for creating: - * - Framebuffer attachments - * - Command buffers - * - Render passes - * - Framebuffers - */ class FrameBufferService final : public AbstractResourceService { - std::shared_ptr createAttachmentInternal(const char *name, VkFormat format, + std::shared_ptr createAttachmentInternal(VkFormat format, VkImageUsageFlagBits usage, FrameBufferInstance *framebuffer) const; void createVKFrameBuffer(FrameBufferInstance *framebuffer) const; public: - explicit FrameBufferService() - : AbstractResourceService() { - } - void createSampler(bool linear, VkSampler &vkImageSampler); - FrameBufferInstance *createFrameBuffer(const std::string &id, unsigned int w, unsigned int h, glm::vec4 clearColor = glm::vec4(0.0f)); + FrameBufferInstance *createFrameBuffer(const std::string &id, unsigned int w, unsigned int h, + glm::vec4 clearColor = glm::vec4(0.0f)); void createDepthAttachment(FrameBufferInstance *framebuffer) const; - void createAttachment(const char *name, VkFormat format, VkImageUsageFlagBits usage, + void createAttachment(VkFormat format, VkImageUsageFlagBits usage, FrameBufferInstance *framebuffer) const; - void createRenderPass(FrameBufferInstance *framebuffer) const; void disposeResource(FrameBufferInstance *resource) override; From ca78dd92310d607cd6ac0ef391c55059fb2dcf7a Mon Sep 17 00:00:00 2001 From: facobackup Date: Sat, 7 Mar 2026 20:11:36 -0300 Subject: [PATCH 05/18] Improved scene import; Unified ComponentType; Improved inspector; New repositories panel; Replacing EntityId with entt::entity; Removing broken hierarchy; Renamed HierarchyPanel to WorldPanel; Added action to add component; Added filter for component type on World panel --- CMakeLists.txt | 21 +- .../editor/abstract/form/types/QuatField.cpp | 4 +- .../editor/abstract/form/types/Vec2Field.cpp | 4 +- .../editor/abstract/form/types/Vec3Field.cpp | 4 +- .../editor/abstract/form/types/Vec4Field.cpp | 4 +- .../dock-spaces/files/FilePreviewPanel.cpp | 2 +- .../editor/dock-spaces/files/FilesPanel.cpp | 9 +- .../hierarchy/HierarchyHeaderPanel.cpp | 16 - .../dock-spaces/hierarchy/HierarchyPanel.cpp | 253 ---------------- .../dock-spaces/hierarchy/HierarchyPanel.h | 63 ---- .../dock-spaces/inspector/InspectorPanel.cpp | 63 ++-- .../dock-spaces/inspector/InspectorPanel.h | 3 +- .../repositories/RepositoriesPanel.cpp | 22 ++ .../repositories/RepositoriesPanel.h | 20 ++ .../viewport/GizmoSettingsPanel.cpp | 2 +- .../dock-spaces/viewport/GizmoSettingsPanel.h | 6 +- .../viewport/ViewportHeaderPanel.cpp | 10 +- .../dock-spaces/viewport/ViewportPanel.cpp | 9 +- .../dock-spaces/world/WorldHeaderPanel.cpp | 35 +++ .../WorldHeaderPanel.h} | 3 +- .../editor/dock-spaces/world/WorldPanel.cpp | 202 +++++++++++++ .../editor/dock-spaces/world/WorldPanel.h | 58 ++++ src/context/engine/EngineContext.cpp | 4 +- .../compute-pass/impl/HWRayTracingPass.cpp | 10 +- .../impl/tools/SelectionIDPass.cpp | 19 +- src/enum/ComponentType.cpp | 103 +++++++ src/enum/ComponentType.h | 73 ++--- src/enum/engine-definitions.h | 4 +- src/repository/dock/DockRepository.h | 2 +- src/repository/dock/DockSpace.cpp | 12 +- src/repository/dock/DockSpace.h | 3 +- src/repository/editor/EditorRepository.cpp | 28 +- src/repository/editor/EditorRepository.h | 6 +- src/repository/streaming/StreamingService.cpp | 61 ++-- src/repository/streaming/StreamingService.h | 7 - src/repository/world/WorldRepository.cpp | 280 ++++++------------ src/repository/world/WorldRepository.h | 29 +- .../world/components/AtmosphereComponent.cpp | 6 +- .../world/components/AtmosphereComponent.h | 2 +- .../world/components/LightComponent.h | 39 --- ...tComponent.cpp => PlaneLightComponent.cpp} | 7 +- .../world/components/PlaneLightComponent.h | 27 +- .../world/components/PrimitiveComponent.cpp | 13 +- .../world/components/PrimitiveComponent.h | 2 +- .../world/components/SphereLightComponent.cpp | 7 +- .../world/components/SphereLightComponent.h | 27 +- .../world/components/TransformComponent.cpp | 13 +- .../world/components/TransformComponent.h | 2 +- .../world/components/VolumeComponent.cpp | 4 +- .../world/components/VolumeComponent.h | 4 +- src/repository/world/impl/AbstractComponent.h | 13 +- src/repository/world/impl/EntityComponent.cpp | 23 -- .../world/impl/MetadataComponent.cpp | 14 + ...{EntityComponent.h => MetadataComponent.h} | 23 +- src/service/abstract/IStreamable.h | 19 -- src/service/lights/LightService.cpp | 37 ++- .../material/MaterialImporterService.cpp | 128 ++++---- .../material/MaterialImporterService.h | 14 +- src/service/material/MaterialService.cpp | 6 +- src/service/mesh/EntityAssetData.h | 67 ----- src/service/mesh/MeshImporterService.cpp | 6 +- src/service/mesh/MeshImporterService.h | 8 +- src/service/mesh/MeshService.cpp | 75 +---- src/service/mesh/MeshService.h | 12 +- src/service/mesh/SceneData.h | 18 +- src/service/mesh/SceneEntityData.h | 48 +++ src/service/mesh/SceneImporterService.cpp | 116 ++++---- src/service/mesh/SceneImporterService.h | 19 +- src/service/picking/PickingService.cpp | 4 +- src/service/picking/PickingService.h | 2 +- src/service/raytracing/RayTracingService.cpp | 21 +- src/service/raytracing/RayTracingService.h | 2 + src/service/selection/SelectionService.cpp | 17 +- src/service/selection/SelectionService.h | 4 +- src/service/texture/TextureService.cpp | 13 +- src/service/texture/TextureService.h | 10 +- src/service/transform/TransformService.cpp | 51 +--- src/service/transform/TransformService.h | 9 - src/service/voxel/VoxelService.h | 8 +- src/util/UIUtil.h | 83 ++++++ 80 files changed, 1206 insertions(+), 1271 deletions(-) delete mode 100644 src/context/editor/dock-spaces/hierarchy/HierarchyHeaderPanel.cpp delete mode 100644 src/context/editor/dock-spaces/hierarchy/HierarchyPanel.cpp delete mode 100644 src/context/editor/dock-spaces/hierarchy/HierarchyPanel.h create mode 100644 src/context/editor/dock-spaces/repositories/RepositoriesPanel.cpp create mode 100644 src/context/editor/dock-spaces/repositories/RepositoriesPanel.h create mode 100644 src/context/editor/dock-spaces/world/WorldHeaderPanel.cpp rename src/context/editor/dock-spaces/{hierarchy/HierarchyHeaderPanel.h => world/WorldHeaderPanel.h} (71%) create mode 100644 src/context/editor/dock-spaces/world/WorldPanel.cpp create mode 100644 src/context/editor/dock-spaces/world/WorldPanel.h create mode 100644 src/enum/ComponentType.cpp delete mode 100644 src/repository/world/components/LightComponent.h rename src/repository/world/components/{LightComponent.cpp => PlaneLightComponent.cpp} (61%) delete mode 100644 src/repository/world/impl/EntityComponent.cpp create mode 100644 src/repository/world/impl/MetadataComponent.cpp rename src/repository/world/impl/{EntityComponent.h => MetadataComponent.h} (61%) delete mode 100644 src/service/abstract/IStreamable.h delete mode 100644 src/service/mesh/EntityAssetData.h create mode 100644 src/service/mesh/SceneEntityData.h diff --git a/CMakeLists.txt b/CMakeLists.txt index d4bd3f89..ef9d468c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -85,8 +85,8 @@ add_executable( src/context/editor/dock-spaces/metrics/MetricsPanel.h src/service/log/LogService.cpp src/service/log/LogService.h - src/context/editor/dock-spaces/hierarchy/HierarchyPanel.cpp - src/context/editor/dock-spaces/hierarchy/HierarchyPanel.h + src/context/editor/dock-spaces/world/WorldPanel.cpp + src/context/editor/dock-spaces/world/WorldPanel.h src/repository/abstract/RuntimeResource.h src/util/ShaderUtil.cpp src/util/ShaderUtil.h @@ -152,17 +152,18 @@ add_executable( src/service/camera/Camera.cpp src/repository/world/WorldRepository.cpp src/repository/world/WorldRepository.h - src/repository/world/impl/EntityComponent.h + src/repository/world/impl/MetadataComponent.h + src/enum/ComponentType.cpp src/enum/ComponentType.h src/repository/world/impl/AbstractComponent.h src/repository/world/components/PrimitiveComponent.h src/repository/world/components/TransformComponent.h src/enum/ShadingMode.h - src/context/editor/dock-spaces/hierarchy/HierarchyHeaderPanel.cpp - src/context/editor/dock-spaces/hierarchy/HierarchyHeaderPanel.h + src/context/editor/dock-spaces/world/WorldHeaderPanel.cpp + src/context/editor/dock-spaces/world/WorldHeaderPanel.h src/service/selection/SelectionService.cpp src/service/selection/SelectionService.h - src/repository/world/impl/EntityComponent.cpp + src/repository/world/impl/MetadataComponent.cpp src/repository/world/components/TransformComponent.cpp src/repository/world/components/PrimitiveComponent.cpp src/context/editor/abstract/form/types/ResourceField.cpp @@ -199,7 +200,6 @@ add_executable( src/service/voxel/impl/OctreeNode.h src/service/voxel/impl/VoxelData.h src/service/mesh/SceneData.h - src/service/mesh/EntityAssetData.h src/context/engine/render-pass/impl/PostProcessingPass.cpp src/context/engine/render-pass/impl/PostProcessingPass.h src/context/engine/compute-pass/impl/HWRayTracingPass.cpp @@ -225,10 +225,9 @@ add_executable( src/service/voxel/SVOInstance.h src/dto/buffers/TileInfoUBO.h src/dto/buffers/LightData.h - src/repository/world/components/LightComponent.cpp - src/repository/world/components/LightComponent.h src/repository/world/components/SphereLightComponent.cpp src/repository/world/components/SphereLightComponent.h + src/repository/world/components/PlaneLightComponent.cpp src/repository/world/components/PlaneLightComponent.h src/context/engine/render-pass/impl/tools/IconsPass.cpp src/context/engine/render-pass/impl/tools/IconsPass.h @@ -286,6 +285,10 @@ add_executable( src/context/engine/compute-pass/impl/SpatialFilterPass.cpp src/context/engine/compute-pass/impl/SpatialFilterPass.h src/repository/world/components/AtmosphereComponent.cpp + src/enum/ComponentType.cpp + src/service/mesh/SceneEntityData.h + src/context/editor/dock-spaces/repositories/RepositoriesPanel.cpp + src/context/editor/dock-spaces/repositories/RepositoriesPanel.h ) diff --git a/src/context/editor/abstract/form/types/QuatField.cpp b/src/context/editor/abstract/form/types/QuatField.cpp index 2b09407c..24134b71 100644 --- a/src/context/editor/abstract/form/types/QuatField.cpp +++ b/src/context/editor/abstract/form/types/QuatField.cpp @@ -3,6 +3,7 @@ #include #include #include "../../../../../common/inspection/Inspectable.h" +#include "../../../../../util/UIUtil.h" namespace Metal { QuatField::QuatField(InspectedField &field) : field(field) { @@ -14,8 +15,7 @@ namespace Metal { values[1] = field.field->y; values[2] = field.field->z; values[3] = field.field->w; - ImGui::Text(field.name.c_str()); - if (ImGui::DragFloat4(field.id.c_str(), values, field.incrementF.value())) { + if (UIUtil::DrawQuatControl(field.name, field.id, values, field.incrementF.value())) { field.field->x = values[0]; field.field->y = values[1]; field.field->z = values[2]; diff --git a/src/context/editor/abstract/form/types/Vec2Field.cpp b/src/context/editor/abstract/form/types/Vec2Field.cpp index 8bc3cc7f..d45d650d 100644 --- a/src/context/editor/abstract/form/types/Vec2Field.cpp +++ b/src/context/editor/abstract/form/types/Vec2Field.cpp @@ -2,6 +2,7 @@ #include #include #include "../../../../../common/inspection/Inspectable.h" +#include "../../../../../util/UIUtil.h" namespace Metal { Vec2Field::Vec2Field(InspectedField &field) : field(field) { @@ -11,8 +12,7 @@ namespace Metal { if (!field.disabled) { values[0] = field.field->x; values[1] = field.field->y; - ImGui::Text(field.name.c_str()); - if (ImGui::DragFloat2(field.id.c_str(), values, field.incrementF.value())) { + if (UIUtil::DrawVec2Control(field.name, field.id, values, field.incrementF.value())) { field.field->x = values[0]; field.field->y = values[1]; field.instance->registerChange(); diff --git a/src/context/editor/abstract/form/types/Vec3Field.cpp b/src/context/editor/abstract/form/types/Vec3Field.cpp index 27de3d77..e518b42e 100644 --- a/src/context/editor/abstract/form/types/Vec3Field.cpp +++ b/src/context/editor/abstract/form/types/Vec3Field.cpp @@ -2,6 +2,7 @@ #include #include #include "../../../../../common/inspection/Inspectable.h" +#include "../../../../../util/UIUtil.h" namespace Metal { Vec3Field::Vec3Field(InspectedField &field) : field(field) { @@ -12,8 +13,7 @@ namespace Metal { values[0] = field.field->x; values[1] = field.field->y; values[2] = field.field->z; - ImGui::Text(field.name.c_str()); - if (ImGui::DragFloat3(field.id.c_str(), values, field.incrementF.value())) { + if (UIUtil::DrawVec3Control(field.name, field.id, values, field.incrementF.value())) { field.field->x = values[0]; field.field->y = values[1]; field.field->z = values[2]; diff --git a/src/context/editor/abstract/form/types/Vec4Field.cpp b/src/context/editor/abstract/form/types/Vec4Field.cpp index d760d068..07cc3dde 100644 --- a/src/context/editor/abstract/form/types/Vec4Field.cpp +++ b/src/context/editor/abstract/form/types/Vec4Field.cpp @@ -2,6 +2,7 @@ #include #include #include "../../../../../common/inspection/Inspectable.h" +#include "../../../../../util/UIUtil.h" namespace Metal { Vec4Field::Vec4Field(InspectedField &field) : field(field) { @@ -13,8 +14,7 @@ namespace Metal { values[1] = field.field->y; values[2] = field.field->z; values[3] = field.field->w; - ImGui::Text(field.name.c_str()); - if (ImGui::DragFloat4(field.id.c_str(), values, field.incrementF.value())) { + if (UIUtil::DrawVec4Control(field.name, field.id, values, field.incrementF.value())) { field.field->x = values[0]; field.field->y = values[1]; field.field->z = values[2]; diff --git a/src/context/editor/dock-spaces/files/FilePreviewPanel.cpp b/src/context/editor/dock-spaces/files/FilePreviewPanel.cpp index 7b0a2376..7c7c050b 100644 --- a/src/context/editor/dock-spaces/files/FilePreviewPanel.cpp +++ b/src/context/editor/dock-spaces/files/FilePreviewPanel.cpp @@ -21,7 +21,7 @@ namespace Metal { ImGui::Separator(); if (selected->type == EntryType::TEXTURE) { - auto *texture = CTX.streamingService.streamTexture(selected->getId()); + auto *texture = CTX.textureService.stream(selected->getId()); if (texture != nullptr) { float availWidth = ImGui::GetContentRegionAvail().x; float availHeight = ImGui::GetContentRegionAvail().y * 0.6f; // reserve space for table diff --git a/src/context/editor/dock-spaces/files/FilesPanel.cpp b/src/context/editor/dock-spaces/files/FilesPanel.cpp index a23068e7..32f0e537 100644 --- a/src/context/editor/dock-spaces/files/FilesPanel.cpp +++ b/src/context/editor/dock-spaces/files/FilesPanel.cpp @@ -123,15 +123,13 @@ namespace Metal { void FilesPanel::openResource(FSEntry *root) { switch (root->type) { - case EntryType::MESH: { - CTX.meshService.createMeshEntity(root->name, root->getId(), nullptr); - break; - } case EntryType::SCENE: { - CTX.meshService.createSceneEntities(root->getId()); + CTX.notificationService.pushMessage("Loading scene", NotificationSeverities::SUCCESS); + CTX.worldRepository.loadScene(root->getId()); break; } case EntryType::VOLUME: { + CTX.notificationService.pushMessage("Loading volume", NotificationSeverities::SUCCESS); CTX.voxelService.create(root->getId()); break; } @@ -142,6 +140,7 @@ namespace Metal { break; } default: + CTX.notificationService.pushMessage("Unsupported resource type", NotificationSeverities::ERROR); break; } } diff --git a/src/context/editor/dock-spaces/hierarchy/HierarchyHeaderPanel.cpp b/src/context/editor/dock-spaces/hierarchy/HierarchyHeaderPanel.cpp deleted file mode 100644 index 24a7eebe..00000000 --- a/src/context/editor/dock-spaces/hierarchy/HierarchyHeaderPanel.cpp +++ /dev/null @@ -1,16 +0,0 @@ -#include "HierarchyHeaderPanel.h" - -#include "../../../../context/ApplicationContext.h" -#include "../../../../util/UIUtil.h" - -namespace Metal { - void HierarchyHeaderPanel::onSync() { - ImGui::InputText(("##hierarchySearch" + id).c_str(), search, sizeof(search)); - ImGui::SameLine(); - if (UIUtil::ButtonSimple(Icons::inventory_2 + "##hierarchyAdd" + id, UIUtil::ONLY_ICON_BUTTON_SIZE, - UIUtil::ONLY_ICON_BUTTON_SIZE)) { - CTX.worldRepository.createEntity(); - } - UIUtil::RenderTooltip("Create folder"); - } -} // Metal diff --git a/src/context/editor/dock-spaces/hierarchy/HierarchyPanel.cpp b/src/context/editor/dock-spaces/hierarchy/HierarchyPanel.cpp deleted file mode 100644 index 24171b3b..00000000 --- a/src/context/editor/dock-spaces/hierarchy/HierarchyPanel.cpp +++ /dev/null @@ -1,253 +0,0 @@ -#include "HierarchyPanel.h" - -#include "HierarchyHeaderPanel.h" -#include "../../../../common/interface/Icons.h" -#include "../../../../util/UIUtil.h" -#include "../../../../context/ApplicationContext.h" -#include "../../../../repository/world/impl/EntityComponent.h" -#include "../../../../enum/ComponentType.h" - -namespace Metal { - void HierarchyPanel::onInitialize() { - appendChild(headerPanel = new HierarchyHeaderPanel()); - world = &CTX.worldRepository; - editorRepository = &CTX.editorRepository; - - shortcuts = { - ShortcutDTO("Delete", ImGuiKey_Delete, [this]() { - std::vector entities; - for (auto &entry: CTX.editorRepository.selected) { - entities.push_back(entry.first); - } - CTX.worldRepository.deleteEntities(entities); - CTX.selectionService.clearSelection(); - }), - ShortcutDTO("Select All", ImGuiMod_Ctrl | ImGuiKey_A, [this]() { - std::vector entities; - auto &storage = world->registry.storage(); - for (auto it = storage.begin(); it != storage.end(); ++it) { - auto entity = *it; - if (static_cast(entity) != WorldRepository::ROOT_ID && world->registry.all_of< - EntityComponent>(entity)) { - entities.push_back(static_cast(entity)); - } - } - CTX.selectionService.addAllSelected(entities); - }), - ShortcutDTO("Save", ImGuiMod_Ctrl | ImGuiKey_S, [] { - CTX.save(); - }), - }; - } - - void HierarchyPanel::contextMenu() const { - if (ImGui::BeginPopupContextItem((id + "contextMenu").c_str())) { - if (ImGui::MenuItem("Delete")) { - std::vector entities; - for (auto &entry: CTX.editorRepository.selected) { - entities.push_back(entry.first); - } - CTX.worldRepository.deleteEntities(entities); - CTX.selectionService.clearSelection(); - } - ImGui::EndPopup(); - } - - if (isSomethingHovered && ImGui::IsMouseClicked(ImGuiMouseButton_Right)) { - ImGui::OpenPopup((id + "contextMenu").c_str()); - } - } - - void HierarchyPanel::onSync() { - isOnSearch = strlen(headerPanel->search) > 0; - - isSomethingHovered = ImGui::IsItemHovered(); - - // hotKeys(); - onSyncChildren(); - ImGui::Separator(); - if (ImGui::BeginTable((id + "hierarchyTable").c_str(), 2, TABLE_FLAGS)) { - isSomethingHovered = isSomethingHovered || ImGui::IsItemHovered(); - ImGui::TableSetupColumn("Name", ImGuiTableColumnFlags_NoHide); - ImGui::TableSetupColumn(Icons::visibility.c_str(), ImGuiTableColumnFlags_WidthFixed, 20.f); - ImGui::TableHeadersRow(); - renderNode(WorldRepository::ROOT_ID); - ImGui::EndTable(); - } - if (!CTX.editorRepository.selected.empty()) { - contextMenu(); - } - } - - bool HierarchyPanel::renderNode(const EntityID entityId) { - EntityComponent *node = world->getEntity(entityId); - if (node == nullptr || (isOnSearch && - searchMatch.contains(entityId) && - searchMatchWith.contains(entityId) && - strcmp(searchMatchWith[entityId].c_str(), headerPanel->search) == 0)) { - return false; - } - - const bool isSearchMatch = matchSearch(entityId); - ImGui::TableNextRow(); - if (editorRepository->selected.contains(entityId)) { - ImGui::TableSetBgColor(ImGuiTableBgTarget_RowBg0, editorRepository->accentU32); - ImGui::TableSetBgColor(ImGuiTableBgTarget_RowBg1, editorRepository->accentU32); - } - ImGui::TableNextColumn(); - const int flags = getFlags(entityId); - bool open; - - if (world->culled.contains(entityId) || world->hiddenEntities.contains(entityId)) { - ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(node->color.x, node->color.y, node->color.z, .5)); - open = isOpen(entityId, flags); - ImGui::PopStyleColor(); - } else { - rowColor.x = node->color.x; - rowColor.y = node->color.y; - rowColor.z = node->color.z; - ImGui::PushStyleColor(ImGuiCol_Text, rowColor); - open = isOpen(entityId, flags); - ImGui::PopStyleColor(); - } - - handleDragDrop(entityId); - renderEntityColumns(entityId, false); - - if (open) { - opened.insert({entityId, ImGuiTreeNodeFlags_DefaultOpen}); - renderEntityChildren(entityId); - } else { - opened.insert({entityId, ImGuiTreeNodeFlags_None}); - } - - return isSearchMatch; - } - - bool HierarchyPanel::isOpen(const EntityID entityId, const int flags) const { - return ImGui::TreeNodeEx(getNodeLabel(entityId, true).c_str(), flags); - } - - const char *HierarchyPanel::GetIcon(const EntityID entityId) const { - const auto entity = static_cast(entityId); - if (world->registry.all_of(entity)) { - return ComponentTypes::IconOf(ComponentTypes::PRIMITIVE); - } - if (world->registry.all_of >(entity)) { - return ComponentTypes::IconOf(ComponentTypes::SPHERE_LIGHT); - } - if (world->registry.all_of(entity)) { - return ComponentTypes::IconOf(ComponentTypes::VOLUME); - } - return Icons::inventory_2.c_str(); - } - - std::string HierarchyPanel::getNodeLabel(const EntityID entityId, const bool addId) const { - const auto node = world->getEntity(entityId); - return std::format("{}{}##{}{}", - GetIcon(entityId), - node->name, - entityId, - addId ? id : ""); - } - - bool HierarchyPanel::matchSearch(const EntityID entityId) { - bool isSearchMatch = false; - const auto node = world->getEntity(entityId); - if (isOnSearch) { - isSearchMatch = node->name.find(headerPanel->search) != std::string::npos; - if (isSearchMatch) { - searchMatch.insert({entityId, true}); - } else { - searchMatch.erase(entityId); - } - searchMatchWith.insert({entityId, headerPanel->search}); - } else { - searchMatch.erase(entityId); - searchMatchWith.erase(entityId); - } - return isSearchMatch; - } - - void HierarchyPanel::renderEntityChildren(const EntityID entityId) { - const auto entity = static_cast(entityId); - if (!world->registry.all_of(entity)) { - ImGui::TreePop(); - return; - } - - const auto &hierarchy = world->registry.get(entity); - if (isOnSearch) { - for (const auto child: hierarchy.children) { - if (searchMatch.contains(entityId) || renderNode(child)) { - searchMatch.insert({entityId, true}); - } else { - searchMatch.erase(entityId); - } - } - } else { - for (const auto child: hierarchy.children) { - renderNode(child); - } - } - - ImGui::TreePop(); - } - - int HierarchyPanel::getFlags(const EntityID entityId) { - int flags = ImGuiTreeNodeFlags_SpanFullWidth; - if (isOnSearch) { - flags |= ImGuiTreeNodeFlags_DefaultOpen; - } - - if (opened.contains(entityId)) { - flags |= opened[entityId]; - } - return flags; - } - - void HierarchyPanel::renderEntityColumns(const EntityID entityId, const bool isPinned) const { - const auto idString = std::to_string(entityId); - handleClick(entityId); - ImGui::TableNextColumn(); - - ImGui::PushStyleColor(ImGuiCol_Button, TRANSPARENT); - ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, PADDING); - ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 0); - - bool isVisible = !world->hiddenEntities.contains(entityId); - if (UIUtil::ButtonSimple( - (isVisible ? Icons::visibility : Icons::visibility_off) + (isPinned ? "##vpinned" : "##v") + idString + - id, 20, 15)) { - CTX.worldRepository.changeVisibility(entityId, !isVisible); - } - ImGui::PopStyleColor(); - ImGui::PopStyleVar(2); - } - - void HierarchyPanel::handleClick(const EntityID entityId) const { - if (ImGui::IsItemClicked()) { - if (const bool isMultiSelect = ImGui::IsKeyDown(ImGuiKey_LeftCtrl); !isMultiSelect) { - CTX.selectionService.clearSelection(); - } - CTX.selectionService.addSelected(entityId); - } - } - - void HierarchyPanel::handleDragDrop(const EntityID entityId) { - const auto node = world->getEntity(entityId); - if (ImGui::BeginDragDropSource()) { - ImGui::SetDragDropPayload(id.c_str(), id.c_str(), sizeof(id.c_str())); - onDrag = entityId; - ImGui::Text("Dragging Node %s", node->getTitle()); - ImGui::EndDragDropSource(); - } - - if (ImGui::BeginDragDropTarget()) { - if (strcmp(static_cast(ImGui::AcceptDragDropPayload(id.c_str())->Data), id.c_str())) { - world->linkEntities(entityId, onDrag); - } - ImGui::EndDragDropTarget(); - } - } -} // Metal diff --git a/src/context/editor/dock-spaces/hierarchy/HierarchyPanel.h b/src/context/editor/dock-spaces/hierarchy/HierarchyPanel.h deleted file mode 100644 index 4a1a9c67..00000000 --- a/src/context/editor/dock-spaces/hierarchy/HierarchyPanel.h +++ /dev/null @@ -1,63 +0,0 @@ -#ifndef HIERARCHYPANEL_H -#define HIERARCHYPANEL_H -#include -#include - -#include "../../../../enum/engine-definitions.h" -#include "../../../../enum/ComponentType.h" -#include "../docks/AbstractDockPanel.h" - -namespace Metal { - struct EditorRepository; - struct WorldRepository; - struct AbstractComponent; - struct EntityComponent; - struct HierarchyComponent; - class HierarchyHeaderPanel; - - class HierarchyPanel final : public AbstractDockPanel { - static constexpr auto TRANSPARENT = ImVec4(0, 0, 0, 0); - static constexpr auto PADDING = ImVec2(0, 0); - static constexpr auto TABLE_FLAGS = ImGuiTableFlags_ScrollY | ImGuiTableFlags_Resizable | ImGuiTableFlags_RowBg - | ImGuiTableFlags_NoBordersInBody; - HierarchyHeaderPanel *headerPanel = nullptr; - ImVec4 rowColor = ImVec4(0, 0, 0, 1); - EntityID onDrag = EMPTY_ENTITY; - bool isOnSearch = false; - std::unordered_map searchMatchWith{}; - std::unordered_map searchMatch{}; - std::unordered_map opened{}; - WorldRepository *world = nullptr; - EditorRepository *editorRepository = nullptr; - bool isSomethingHovered = false; - - public: - void onInitialize() override; - - void contextMenu() const; - - void onSync() override; - - bool renderNode(EntityID entityId); - - bool isOpen(EntityID entityId, int flags) const; - - const char *GetIcon(EntityID entityId) const; - - std::string getNodeLabel(EntityID entityId, bool addId) const; - - bool matchSearch(EntityID entityId); - - void renderEntityChildren(EntityID entityId); - - int getFlags(EntityID entityId); - - void renderEntityColumns(EntityID entityId, bool isPinned) const; - - void handleClick(EntityID entityId) const; - - void handleDragDrop(EntityID entityId); - }; -} // Metal - -#endif //HIERARCHYPANEL_H diff --git a/src/context/editor/dock-spaces/inspector/InspectorPanel.cpp b/src/context/editor/dock-spaces/inspector/InspectorPanel.cpp index 3af42e36..fd785caf 100644 --- a/src/context/editor/dock-spaces/inspector/InspectorPanel.cpp +++ b/src/context/editor/dock-spaces/inspector/InspectorPanel.cpp @@ -4,34 +4,45 @@ #include "../../../../util/UIUtil.h" #include "../../../../common/inspection/Inspectable.h" #include "../../../../context/ApplicationContext.h" -#include "../../../../repository/world/impl/EntityComponent.h" +#include "../../../../repository/world/impl/MetadataComponent.h" #include "../../../../repository/world/components/VolumeComponent.h" -#include "../../../../repository/world/components/LightComponent.h" +#include "../../../../repository/world/components/SphereLightComponent.h" +#include "../../../../repository/world/components/PlaneLightComponent.h" +#include +#include #include "../../../../service/camera/Camera.h" namespace Metal { void InspectorPanel::onInitialize() { formPanel = new FormPanel(); appendChild(formPanel); - Inspectable *editorRepo = &CTX.editorRepository; - Inspectable *engineRepo = &CTX.engineRepository; - Inspectable *cameraRepo = &CTX.worldRepository.camera; - repositories.push_back(editorRepo); - repositories.push_back(engineRepo); - repositories.push_back(cameraRepo); } void InspectorPanel::onSync() { tick(); - { - for (auto *repo: repositories) { - formPanel->setInspection(repo); + formPanel->onSync(); + + if (selectedId != EMPTY_ENTITY) { + ImGui::Separator(); + if (ImGui::Button((Icons::add + " Add Component" + id + "addComp").c_str(), ImVec2(-1, 0))) { + ImGui::OpenPopup((id + "AddComponentPopup").c_str()); } - for (auto *component: additionalInspection) { - formPanel->setInspection(component); + + if (ImGui::BeginPopup((id + "AddComponentPopup").c_str())) { + for (const auto &compDef: ComponentTypes::getComponents()) { + bool hasComponent = compDef.getInspectable(CTX.worldRepository, selectedId) != nullptr; + if (!hasComponent) { + if (ImGui::MenuItem( + (compDef.icon + " " + compDef.name + id + "adCOmp" + compDef.name).c_str())) { + CTX.worldRepository.createComponent(selectedId, compDef.type); + selectedId = EMPTY_ENTITY; + tick(); + } + } + } + ImGui::EndPopup(); } } - formPanel->onSync(); } void InspectorPanel::tick() { @@ -42,32 +53,24 @@ namespace Metal { formPanel->resetForm(); if (selectedId != EMPTY_ENTITY) { auto &repo = CTX.worldRepository; - const auto entity = static_cast(selectedId); selectedEntity = repo.getEntity(selectedId); if (selectedEntity != nullptr) { additionalInspection.push_back(selectedEntity); - if (repo.registry.all_of(entity)) { - additionalInspection.push_back((Inspectable *) &repo.registry.get(entity)); - } - if (repo.registry.all_of(entity)) { - additionalInspection.push_back((Inspectable *) &repo.registry.get(entity)); - } - if (repo.registry.all_of >(entity)) { - additionalInspection.push_back( - (Inspectable *) repo.registry.get >(entity).get()); - } - if (repo.registry.all_of(entity)) { - additionalInspection.push_back((Inspectable *) &repo.registry.get(entity)); - } - if (repo.registry.all_of(entity)) { - additionalInspection.push_back((Inspectable *) &repo.registry.get(entity)); + for (const auto &compDef: ComponentTypes::getComponents()) { + if (Inspectable *inspectable = compDef.getInspectable(repo, selectedId)) { + additionalInspection.push_back(inspectable); + } } } } else { selectedEntity = nullptr; } } + + for (auto *component: additionalInspection) { + formPanel->setInspection(component); + } } } diff --git a/src/context/editor/dock-spaces/inspector/InspectorPanel.h b/src/context/editor/dock-spaces/inspector/InspectorPanel.h index e871d53e..5d024e96 100644 --- a/src/context/editor/dock-spaces/inspector/InspectorPanel.h +++ b/src/context/editor/dock-spaces/inspector/InspectorPanel.h @@ -9,12 +9,11 @@ namespace Metal { class Inspectable; class InspectorPanel final : public AbstractDockPanel { - std::vector repositories{}; std::vector additionalInspection{}; Inspectable *selectedEntity = nullptr; FormPanel *formPanel = nullptr; - EntityID selectedId = EMPTY_ENTITY; + entt::entity selectedId = EMPTY_ENTITY; public: void onInitialize() override; diff --git a/src/context/editor/dock-spaces/repositories/RepositoriesPanel.cpp b/src/context/editor/dock-spaces/repositories/RepositoriesPanel.cpp new file mode 100644 index 00000000..19af1c73 --- /dev/null +++ b/src/context/editor/dock-spaces/repositories/RepositoriesPanel.cpp @@ -0,0 +1,22 @@ +#include "RepositoriesPanel.h" +#include "../../abstract/form/FormPanel.h" +#include "../../../../context/ApplicationContext.h" +#include "../../../../common/inspection/Inspectable.h" + +namespace Metal { + void RepositoriesPanel::onInitialize() { + formPanel = new FormPanel(); + appendChild(formPanel); + + repositories.push_back(&CTX.editorRepository); + repositories.push_back(&CTX.engineRepository); + repositories.push_back(&CTX.worldRepository.camera); + } + + void RepositoriesPanel::onSync() { + for (auto *repo : repositories) { + formPanel->setInspection(repo); + } + formPanel->onSync(); + } +} diff --git a/src/context/editor/dock-spaces/repositories/RepositoriesPanel.h b/src/context/editor/dock-spaces/repositories/RepositoriesPanel.h new file mode 100644 index 00000000..b566b984 --- /dev/null +++ b/src/context/editor/dock-spaces/repositories/RepositoriesPanel.h @@ -0,0 +1,20 @@ +#ifndef REPOSITORIESPANEL_H +#define REPOSITORIESPANEL_H + +#include "../docks/AbstractDockPanel.h" + +namespace Metal { + class FormPanel; + class Inspectable; + + class RepositoriesPanel final : public AbstractDockPanel { + std::vector repositories{}; + FormPanel *formPanel = nullptr; + + public: + void onInitialize() override; + void onSync() override; + }; +} + +#endif diff --git a/src/context/editor/dock-spaces/viewport/GizmoSettingsPanel.cpp b/src/context/editor/dock-spaces/viewport/GizmoSettingsPanel.cpp index 0d209f37..3d2638d9 100644 --- a/src/context/editor/dock-spaces/viewport/GizmoSettingsPanel.cpp +++ b/src/context/editor/dock-spaces/viewport/GizmoSettingsPanel.cpp @@ -16,7 +16,7 @@ namespace Metal { gizmoGrid(); UIUtil::Spacing(); if (selectedEntityId != editorRepository->mainSelection && CTX.worldRepository.registry.all_of( - static_cast::entity_type>(editorRepository->mainSelection))) { + editorRepository->mainSelection)) { selectedEntity = CTX.worldRepository.getEntity(editorRepository->mainSelection); selectedEntityId = editorRepository->mainSelection; } diff --git a/src/context/editor/dock-spaces/viewport/GizmoSettingsPanel.h b/src/context/editor/dock-spaces/viewport/GizmoSettingsPanel.h index c9f89abd..aec3a185 100644 --- a/src/context/editor/dock-spaces/viewport/GizmoSettingsPanel.h +++ b/src/context/editor/dock-spaces/viewport/GizmoSettingsPanel.h @@ -7,7 +7,7 @@ #include "../../abstract/AbstractPanel.h" namespace Metal { - struct EntityComponent; + struct MetadataComponent; struct EditorRepository; class GizmoSettingsPanel final : public AbstractPanel { @@ -19,8 +19,8 @@ namespace Metal { static constexpr const char *SNAP_SCALE_OPTIONS = "0.5\0 1\0 2\0 5\0 10\0"; static constexpr std::array SNAP_SCALE_OPTIONS_A = {0.5, 1, 2, 5, 10}; EditorRepository *editorRepository = nullptr; - EntityComponent *selectedEntity = nullptr; - EntityID selectedEntityId = 0; + MetadataComponent *selectedEntity = nullptr; + entt::entity selectedEntityId = EMPTY_ENTITY; public: void onInitialize() override; diff --git a/src/context/editor/dock-spaces/viewport/ViewportHeaderPanel.cpp b/src/context/editor/dock-spaces/viewport/ViewportHeaderPanel.cpp index abc4a532..945b926e 100644 --- a/src/context/editor/dock-spaces/viewport/ViewportHeaderPanel.cpp +++ b/src/context/editor/dock-spaces/viewport/ViewportHeaderPanel.cpp @@ -16,15 +16,7 @@ namespace Metal { ImGui::SetCursorPos(ImVec2(ImGui::GetCursorPosX() + 2, ImGui::GetCursorPosY() + 4)); gizmo->onSync(); ImGui::SameLine(); - int option = 0; - UIUtil::DynamicSpacing(365); - ImGui::SetNextItemWidth(100); - if (ImGui::Combo((id + "##entities").c_str(), &option, ComponentTypes::NAMES)) { - auto id = CTX.worldRepository.createEntity(); - CTX.worldRepository.createComponent(id, ComponentTypes::ValueOfIndex(option)); - CTX.selectionService.clearSelection(); - CTX.selectionService.addSelected(id); - } + UIUtil::DynamicSpacing(270); ImGui::SameLine(); cameraMode(); diff --git a/src/context/editor/dock-spaces/viewport/ViewportPanel.cpp b/src/context/editor/dock-spaces/viewport/ViewportPanel.cpp index de05e660..93e31907 100644 --- a/src/context/editor/dock-spaces/viewport/ViewportPanel.cpp +++ b/src/context/editor/dock-spaces/viewport/ViewportPanel.cpp @@ -33,7 +33,7 @@ namespace Metal { CTX.editorRepository.gizmoType = ImGuizmo::OPERATION::ROTATE; }), ShortcutDTO("Delete", ImGuiKey_Delete, [this]() { - std::vector entities; + std::vector entities; for (auto &entry: CTX.editorRepository.selected) { entities.push_back(entry.first); } @@ -41,13 +41,12 @@ namespace Metal { CTX.selectionService.clearSelection(); }), ShortcutDTO("Select All", ImGuiMod_Ctrl | ImGuiKey_A, [this]() { - std::vector entities; + std::vector entities; auto &storage = CTX.worldRepository.registry.storage(); for (auto it = storage.begin(); it != storage.end(); ++it) { auto entity = *it; - if (static_cast(entity) != WorldRepository::ROOT_ID && CTX.worldRepository.registry.all_of - (entity)) { - entities.push_back(static_cast(entity)); + if (CTX.worldRepository.registry.all_of(entity)) { + entities.push_back(entity); } } CTX.selectionService.addAllSelected(entities); diff --git a/src/context/editor/dock-spaces/world/WorldHeaderPanel.cpp b/src/context/editor/dock-spaces/world/WorldHeaderPanel.cpp new file mode 100644 index 00000000..98b04ce1 --- /dev/null +++ b/src/context/editor/dock-spaces/world/WorldHeaderPanel.cpp @@ -0,0 +1,35 @@ +#include "WorldHeaderPanel.h" + +#include "../../../../context/ApplicationContext.h" +#include "../../../../util/UIUtil.h" +#include "../../../../enum/ComponentType.h" + +namespace Metal { + void WorldHeaderPanel::onSync() { + ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x - 120.f - UIUtil::ONLY_ICON_BUTTON_SIZE - 20.f); + ImGui::InputTextWithHint(("##hierarchySearch" + id).c_str(), "Search...", search, sizeof(search)); + ImGui::SameLine(); + ImGui::SetNextItemWidth(120.f); + if (ImGui::BeginCombo(("##hierarchyFilter" + id).c_str(), + selectedComponentType == -1 + ? "All" + : ComponentTypes::NameOf(static_cast(selectedComponentType)))) { + if (ImGui::Selectable("All", selectedComponentType == -1)) { + selectedComponentType = -1; + } + for (const auto &compDef: ComponentTypes::getComponents()) { + if (ImGui::Selectable((compDef.icon + compDef.name).c_str(), + selectedComponentType == static_cast(compDef.type))) { + selectedComponentType = static_cast(compDef.type); + } + } + ImGui::EndCombo(); + } + ImGui::SameLine(); + if (UIUtil::ButtonSimple(Icons::add + "##hierarchyAdd" + id, UIUtil::ONLY_ICON_BUTTON_SIZE, + UIUtil::ONLY_ICON_BUTTON_SIZE)) { + CTX.worldRepository.createEntity(); + } + UIUtil::RenderTooltip("Create entity"); + } +} // Metal diff --git a/src/context/editor/dock-spaces/hierarchy/HierarchyHeaderPanel.h b/src/context/editor/dock-spaces/world/WorldHeaderPanel.h similarity index 71% rename from src/context/editor/dock-spaces/hierarchy/HierarchyHeaderPanel.h rename to src/context/editor/dock-spaces/world/WorldHeaderPanel.h index e2078659..1e9f025a 100644 --- a/src/context/editor/dock-spaces/hierarchy/HierarchyHeaderPanel.h +++ b/src/context/editor/dock-spaces/world/WorldHeaderPanel.h @@ -3,11 +3,12 @@ #include "../../abstract/AbstractPanel.h" namespace Metal { - class HierarchyHeaderPanel final : public AbstractPanel { + class WorldHeaderPanel final : public AbstractPanel { public: void onSync() override; char search[512]; + int selectedComponentType = -1; }; } // Metal diff --git a/src/context/editor/dock-spaces/world/WorldPanel.cpp b/src/context/editor/dock-spaces/world/WorldPanel.cpp new file mode 100644 index 00000000..ecf595c5 --- /dev/null +++ b/src/context/editor/dock-spaces/world/WorldPanel.cpp @@ -0,0 +1,202 @@ +#include "WorldPanel.h" + +#include "WorldHeaderPanel.h" +#include "../../../../common/interface/Icons.h" +#include "../../../../util/UIUtil.h" +#include "../../../../context/ApplicationContext.h" +#include "../../../../repository/world/impl/MetadataComponent.h" +#include "../../../../repository/world/components/SphereLightComponent.h" +#include "../../../../repository/world/components/PlaneLightComponent.h" +#include "../../../../enum/ComponentType.h" + +namespace Metal { + void WorldPanel::onInitialize() { + appendChild(headerPanel = new WorldHeaderPanel()); + world = &CTX.worldRepository; + editorRepository = &CTX.editorRepository; + + shortcuts = { + ShortcutDTO("Delete", ImGuiKey_Delete, [this]() { + std::vector entities; + for (auto &entry: CTX.editorRepository.selected) { + entities.push_back(entry.first); + } + CTX.worldRepository.deleteEntities(entities); + CTX.selectionService.clearSelection(); + }), + ShortcutDTO("Select All", ImGuiMod_Ctrl | ImGuiKey_A, [this]() { + std::vector entities; + for (auto entity : world->registry.view()) { + if (isMatched(entity)) { + entities.push_back(entity); + } + } + CTX.selectionService.addAllSelected(entities); + }), + ShortcutDTO("Save", ImGuiMod_Ctrl | ImGuiKey_S, [] { + CTX.save(); + }), + }; + } + + void WorldPanel::contextMenu() const { + if (ImGui::BeginPopupContextItem((id + "contextMenu").c_str())) { + if (ImGui::MenuItem("Delete")) { + std::vector entities; + for (auto &entry: CTX.editorRepository.selected) { + entities.push_back(entry.first); + } + CTX.worldRepository.deleteEntities(entities); + CTX.selectionService.clearSelection(); + } + ImGui::EndPopup(); + } + + if (isSomethingHovered && ImGui::IsMouseClicked(ImGuiMouseButton_Right)) { + ImGui::OpenPopup((id + "contextMenu").c_str()); + } + } + + void WorldPanel::onSync() { + isOnSearch = strlen(headerPanel->search) > 0 || headerPanel->selectedComponentType != -1; + isSomethingHovered = ImGui::IsItemHovered(); + onSyncChildren(); + ImGui::Separator(); + if (ImGui::BeginTable((id + "hierarchyTable").c_str(), 2, TABLE_FLAGS)) { + isSomethingHovered = isSomethingHovered || ImGui::IsItemHovered(); + ImGui::TableSetupColumn("Name", ImGuiTableColumnFlags_NoHide); + ImGui::TableSetupColumn(Icons::visibility.c_str(), ImGuiTableColumnFlags_WidthFixed, 20.f); + ImGui::TableHeadersRow(); + + auto view = world->registry.view(); + for (const auto entity: view) { + renderNode(entity); + } + + ImGui::EndTable(); + } + if (!CTX.editorRepository.selected.empty()) { + contextMenu(); + } + } + + void WorldPanel::renderNode(const entt::entity entityId) { + MetadataComponent *node = world->getEntity(entityId); + if (node == nullptr || (isOnSearch && !isMatched(entityId))) { + return; + } + + applyRowStyle(entityId, node); + + if (processEntityNode(entityId, node)) { + renderEntityChildren(entityId); + ImGui::TreePop(); + } + } + + bool WorldPanel::processEntityNode(const entt::entity entityId, MetadataComponent *node) { + ImGui::TableNextRow(); + if (editorRepository->selected.contains(entityId)) { + ImGui::TableSetBgColor(ImGuiTableBgTarget_RowBg0, editorRepository->accentU32); + ImGui::TableSetBgColor(ImGuiTableBgTarget_RowBg1, editorRepository->accentU32); + } + + ImGui::TableNextColumn(); + const bool open = ImGui::TreeNodeEx(getNodeLabel(entityId).c_str(), getFlags(entityId)); + + handleDragDrop(entityId); + renderEntityColumns(entityId); + return open; + } + + void WorldPanel::applyRowStyle(const entt::entity entityId, MetadataComponent *node) const { + ImVec4 color = ImVec4(node->color.x, node->color.y, node->color.z, 1.0f); + if (world->culled.contains(entityId) || world->hiddenEntities.contains(entityId)) { + color.w = 0.5f; + } + ImGui::PushStyleColor(ImGuiCol_Text, color); + } + + std::string WorldPanel::getNodeLabel(const entt::entity entityId) const { + const auto node = world->getEntity(entityId); + return std::format("{} {}##{}{}", Icons::category, node->name, entt::to_integral(entityId), id); + } + + bool WorldPanel::isMatched(const entt::entity entityId) const { + const auto node = world->getEntity(entityId); + if (node == nullptr) return false; + bool matches = node->name.find(headerPanel->search) != std::string::npos; + if (headerPanel->selectedComponentType != -1) { + bool hasComponent = false; + for (const auto &compDef : ComponentTypes::getComponents()) { + if (static_cast(compDef.type) == headerPanel->selectedComponentType) { + hasComponent = compDef.getInspectable(*world, entityId) != nullptr; + break; + } + } + matches &= hasComponent; + } + return matches; + } + + void WorldPanel::renderEntityChildren(const entt::entity entityId) { + for (const auto &compDef: ComponentTypes::getComponents()) { + if (compDef.getInspectable(*world, entityId)) { + ImGui::TableNextRow(); + ImGui::TableNextColumn(); + + constexpr ImGuiTreeNodeFlags flags = ImGuiTreeNodeFlags_Leaf | ImGuiTreeNodeFlags_NoTreePushOnOpen | + ImGuiTreeNodeFlags_SpanFullWidth; + ImGui::TreeNodeEx((compDef.icon + " " + compDef.name + "##comp" + std::to_string(static_cast(entt::to_integral(entityId)))).c_str(), + flags); + + ImGui::TableNextColumn(); // Visibility column + } + } + } + + int WorldPanel::getFlags(const entt::entity entityId) const { + int flags = ImGuiTreeNodeFlags_SpanFullWidth; + if (isOnSearch) { + flags |= ImGuiTreeNodeFlags_DefaultOpen; + } + return flags; + } + + void WorldPanel::renderEntityColumns(const entt::entity entityId) const { + handleClick(entityId); + ImGui::TableNextColumn(); + + ImGui::PushStyleColor(ImGuiCol_Button, TRANSPARENT); + ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, PADDING); + ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 0); + + const bool isVisible = !world->hiddenEntities.contains(entityId); + if (UIUtil::ButtonSimple((isVisible ? Icons::visibility : Icons::visibility_off) + ("##v") + + std::to_string(static_cast(entt::to_integral(entityId))) + id, 20, 15)) { + CTX.worldRepository.changeVisibility(entityId, !isVisible); + } + ImGui::PopStyleColor(); + ImGui::PopStyleVar(2); + ImGui::PopStyleColor(); // Pop Row Style (from applyRowStyle) + } + + void WorldPanel::handleClick(const entt::entity entityId) const { + if (ImGui::IsItemClicked()) { + if (const bool isMultiSelect = ImGui::IsKeyDown(ImGuiKey_LeftCtrl); !isMultiSelect) { + CTX.selectionService.clearSelection(); + } + CTX.selectionService.addSelected(entityId); + } + } + + void WorldPanel::handleDragDrop(const entt::entity entityId) { + const auto node = world->getEntity(entityId); + if (ImGui::BeginDragDropSource()) { + ImGui::SetDragDropPayload(id.c_str(), id.c_str(), sizeof(id.c_str())); + onDrag = entityId; + ImGui::Text("Dragging Node %s", node->getTitle()); + ImGui::EndDragDropSource(); + } + } +} // Metal diff --git a/src/context/editor/dock-spaces/world/WorldPanel.h b/src/context/editor/dock-spaces/world/WorldPanel.h new file mode 100644 index 00000000..a6e87e81 --- /dev/null +++ b/src/context/editor/dock-spaces/world/WorldPanel.h @@ -0,0 +1,58 @@ +#ifndef HIERARCHYPANEL_H +#define HIERARCHYPANEL_H +#include +#include + +#include "../../../../enum/engine-definitions.h" +#include "../../../../enum/ComponentType.h" +#include "../docks/AbstractDockPanel.h" + +namespace Metal { + struct EditorRepository; + struct WorldRepository; + struct AbstractComponent; + struct MetadataComponent; + class WorldHeaderPanel; + + class WorldPanel final : public AbstractDockPanel { + static constexpr auto TRANSPARENT = ImVec4(0, 0, 0, 0); + static constexpr auto PADDING = ImVec2(0, 0); + static constexpr auto TABLE_FLAGS = ImGuiTableFlags_ScrollY | ImGuiTableFlags_Resizable | ImGuiTableFlags_RowBg + | ImGuiTableFlags_NoBordersInBody; + WorldHeaderPanel *headerPanel = nullptr; + entt::entity onDrag = EMPTY_ENTITY; + bool isOnSearch = false; + WorldRepository *world = nullptr; + EditorRepository *editorRepository = nullptr; + bool isSomethingHovered = false; + + public: + void onInitialize() override; + + void contextMenu() const; + + void onSync() override; + + void renderNode(entt::entity entityId); + + bool processEntityNode(entt::entity entityId, MetadataComponent *node); + + void applyRowStyle(entt::entity entityId, MetadataComponent *node) const; + + std::string getNodeLabel(entt::entity entityId) const; + + bool isMatched(entt::entity entityId) const; + + void renderEntityChildren(entt::entity entityId); + + int getFlags(entt::entity entityId) const; + + void renderEntityColumns(entt::entity entityId) const; + + void handleClick(entt::entity entityId) const; + + void handleDragDrop(entt::entity entityId); + }; +} // Metal + +#endif //HIERARCHYPANEL_H diff --git a/src/context/engine/EngineContext.cpp b/src/context/engine/EngineContext.cpp index df30fc92..abd2f473 100644 --- a/src/context/engine/EngineContext.cpp +++ b/src/context/engine/EngineContext.cpp @@ -9,7 +9,7 @@ #include "../../service/framebuffer/FrameBufferInstance.h" #include "../../service/texture/TextureInstance.h" #include "../../repository/world/components/AtmosphereComponent.h" -#include "../../repository/world/impl/EntityComponent.h" +#include "../../repository/world/impl/MetadataComponent.h" #include "../../repository/world/components/TransformComponent.h" namespace Metal { @@ -46,6 +46,7 @@ namespace Metal { CTX.transformService.onSync(); CTX.streamingService.onSync(); CTX.cameraService.onSync(); + CTX.rayTracingService.onSync(); for (auto *frame: registeredFrames) { if (frame->getShouldRender()) { @@ -64,7 +65,6 @@ namespace Metal { } } - CTX.rayTracingService.onSync(); setUpdateLights(false); setCameraUpdated(false); diff --git a/src/context/engine/compute-pass/impl/HWRayTracingPass.cpp b/src/context/engine/compute-pass/impl/HWRayTracingPass.cpp index 2d89d321..4c0d888c 100644 --- a/src/context/engine/compute-pass/impl/HWRayTracingPass.cpp +++ b/src/context/engine/compute-pass/impl/HWRayTracingPass.cpp @@ -32,14 +32,6 @@ namespace Metal { } void HWRayTracingPass::onSync() { - bool anyMeshes = false; - entt::registry ® = CTX.worldRepository.registry; - auto view = reg.view(); - for (auto entity: view) { - CTX.streamingService.streamMesh(reg.get(entity).meshId); - anyMeshes = true; - } - auto *accumulatedFrame = frame->getResourceAs(RID_ACCUMULATED_FRAME); auto *gBufferPositionIndex = frame->getResourceAs(RID_GBUFFER_POSITION_INDEX); auto *gBufferNormal = frame->getResourceAs(RID_GBUFFER_NORMAL); @@ -66,7 +58,7 @@ namespace Metal { pushConstant.pathTracerSamples = CTX.engineRepository.pathTracerSamples; pushConstant.pathTracerBounces = CTX.engineRepository.pathTracerBounces; pushConstant.pathTracingEmissiveFactor = CTX.engineRepository.pathTracingEmissiveFactor; - pushConstant.shouldTrace = CTX.rayTracingService.isReady() && anyMeshes ? 1 : 0; + pushConstant.shouldTrace = CTX.rayTracingService.isReady(); pushConstant.dofEnabled = CTX.engineRepository.dofEnabled; pushConstant.dofFocusDistance = CTX.engineRepository.dofFocusDistance; diff --git a/src/context/engine/render-pass/impl/tools/SelectionIDPass.cpp b/src/context/engine/render-pass/impl/tools/SelectionIDPass.cpp index 0390e04b..f34d9bee 100644 --- a/src/context/engine/render-pass/impl/tools/SelectionIDPass.cpp +++ b/src/context/engine/render-pass/impl/tools/SelectionIDPass.cpp @@ -26,17 +26,15 @@ namespace Metal { void SelectionIDPass::onSync() { auto &worldRepository = CTX.worldRepository; - for (const auto &pair: CTX.editorRepository.selected) { - if (!pair.second) { + for (auto const& [entityId, selected] : CTX.editorRepository.selected) { + if (!selected) { continue; } - const EntityID entityId = pair.first; - const auto entity = static_cast(entityId); - if (!worldRepository.registry.all_of(entity) || !worldRepository.registry.all_of(entity)) { + if (!worldRepository.registry.all_of(entityId) || !worldRepository.registry.all_of(entityId)) { continue; } - const auto &mesh = worldRepository.registry.get(entity); + const auto &mesh = worldRepository.registry.get(entityId); if (mesh.meshId.empty()) { continue; } @@ -44,16 +42,13 @@ namespace Metal { continue; } - const auto *meshInstance = CTX.streamingService.streamMesh(mesh.meshId); + const auto *meshInstance = CTX.meshService.stream(mesh.meshId); if (!meshInstance) { continue; } - pushConstant.model = worldRepository.registry.get(entity).model; - pushConstant.selectionColor.x = CTX.editorRepository.selectionColor.x; - pushConstant.selectionColor.y = CTX.editorRepository.selectionColor.y; - pushConstant.selectionColor.z = CTX.editorRepository.selectionColor.z; - pushConstant.selectionColor.w = CTX.editorRepository.selectionOutlineThickness; + pushConstant.model = worldRepository.registry.get(entityId).model; + pushConstant.selectionColor = glm::vec4(CTX.editorRepository.selectionColor, CTX.editorRepository.selectionOutlineThickness); pushConstant.renderIndex = mesh.renderIndex; recordPushConstant(&pushConstant); diff --git a/src/enum/ComponentType.cpp b/src/enum/ComponentType.cpp new file mode 100644 index 00000000..6cf50f48 --- /dev/null +++ b/src/enum/ComponentType.cpp @@ -0,0 +1,103 @@ +#include "ComponentType.h" +#include "../repository/world/WorldRepository.h" +#include "../context/ApplicationContext.h" + +#define DEFINE_COMPONENT(TYPE, NAME, JSON_KEY, ICON, DEPS, CLASS, CREATOR) \ +{ \ +TYPE, NAME, JSON_KEY, ICON, DEPS, \ +CREATOR, \ +[](WorldRepository &repo, entt::entity entityId) { \ +if (auto *comp = repo.registry.try_get(entityId)) { \ +return comp->toJson(); \ +} \ +return nlohmann::json(); \ +}, \ +[](WorldRepository &repo, entt::entity entityId, const nlohmann::json &j) { \ +repo.registry.get(entityId).fromJson(j); \ +}, \ +[](WorldRepository &repo, entt::entity entityId) -> Inspectable* { \ +if (auto *comp = repo.registry.try_get(entityId)) { \ +return static_cast(comp); \ +} \ +return nullptr; \ +} \ +} + +namespace Metal::ComponentTypes { + const std::vector &getComponents() { + static const std::vector COMPONENTS = { + DEFINE_COMPONENT( + PRIMITIVE, "Primitive", "mesh", Icons::view_in_ar, {TRANSFORM}, PrimitiveComponent, + [](WorldRepository &repo, entt::entity entityId) { + auto &mesh = repo.registry.emplace_or_replace(entityId); + mesh.setEntityId(entityId); + CTX.rayTracingService.markDirty(); + } + ), + DEFINE_COMPONENT( + TRANSFORM, "Transformation", "transform", Icons::transform, {}, TransformComponent, + [](WorldRepository &repo, entt::entity entityId) { + if (!repo.registry.all_of(entityId)) { + auto &trans = repo.registry.emplace(entityId); + trans.setEntityId(entityId); + } + } + ), + DEFINE_COMPONENT( + SPHERE_LIGHT, "Sphere Light", "sphere_light", Icons::lightbulb, {TRANSFORM}, + SphereLightComponent, + [](WorldRepository &repo, entt::entity entityId) { + auto &light = repo.registry.emplace_or_replace(entityId); + light.setEntityId(entityId); + CTX.engineContext.setUpdateLights(true); + } + ), + DEFINE_COMPONENT( + PLANE_LIGHT, "Plane Light", "plane_light", Icons::lightbulb, {TRANSFORM}, PlaneLightComponent, + [](WorldRepository &repo, entt::entity entityId) { + auto &light = repo.registry.emplace_or_replace(entityId); + light.setEntityId(entityId); + CTX.engineContext.setUpdateLights(true); + } + ), + DEFINE_COMPONENT( + VOLUME, "Volume Component", "volume", Icons::blur_on, {TRANSFORM}, VolumeComponent, + [](WorldRepository &repo, entt::entity entityId) { + auto &vol = repo.registry.emplace_or_replace(entityId); + vol.setEntityId(entityId); + } + ), + DEFINE_COMPONENT( + ATMOSPHERE, "Atmosphere", "atmosphere", Icons::cloud, {}, AtmosphereComponent, + [](WorldRepository &repo, entt::entity entityId) { + auto &atmo = repo.registry.emplace_or_replace(entityId); + atmo.setEntityId(entityId); + CTX.engineContext.setGISettingsUpdated(true); + } + ), + DEFINE_COMPONENT( + METADATA, "Metadata", "metadata", Icons::data_array, {}, MetadataComponent, + [](WorldRepository &repo, entt::entity entityId) { + auto &atmo = repo.registry.emplace_or_replace(entityId); + atmo.setEntityId(entityId); + CTX.engineContext.setGISettingsUpdated(true); + } + ) + }; + return COMPONENTS; + } + + const char *NameOf(ComponentType mode) { + for (const auto &comp: getComponents()) { + if (comp.type == mode) return comp.name.c_str(); + } + return nullptr; + } + + const char *IconOf(ComponentType mode) { + for (const auto &comp: getComponents()) { + if (comp.type == mode) return comp.icon.c_str(); + } + return nullptr; + } +} diff --git a/src/enum/ComponentType.h b/src/enum/ComponentType.h index bfd794bd..6a5433d3 100644 --- a/src/enum/ComponentType.h +++ b/src/enum/ComponentType.h @@ -1,63 +1,44 @@ #ifndef COMPONENTTYPE_H #define COMPONENTTYPE_H +#include +#include +#include +#include +#include #include "../common/interface/Icons.h" -namespace Metal::ComponentTypes { +namespace Metal { + class Inspectable; + struct WorldRepository; + enum ComponentType { PRIMITIVE, TRANSFORM, SPHERE_LIGHT, PLANE_LIGHT, VOLUME, - ATMOSPHERE + ATMOSPHERE, + METADATA }; +} - static constexpr const char *NAMES = "Add Entity\0Mesh\0Sphere Light\0Plane Light\0Volume\0Atmosphere\0"; +namespace Metal::ComponentTypes { + struct ComponentDefinition { + ComponentType type; + std::string name; + std::string jsonKey; + std::string icon; + std::vector dependencies; + std::function creator; + std::function toJson; + std::function fromJson; + std::function getInspectable; + }; - static ComponentType ValueOfIndex(const int option) { - if (option == 1) { - return PRIMITIVE; - } - if (option == 2) { - return SPHERE_LIGHT; - } - if (option == 3) { - return PLANE_LIGHT; - } - if (option == 4) { - return VOLUME; - } - return ATMOSPHERE; - } + const std::vector &getComponents(); - static const char *NameOf(const ComponentType mode) { - if (mode == PRIMITIVE) - return "Mesh Component"; - if (mode == TRANSFORM) - return "Transformation Component"; - if (mode == SPHERE_LIGHT) - return "Sphere Light Component"; - if (mode == PLANE_LIGHT) - return "Plane Light Component"; - if (mode == VOLUME) - return "Volume Component"; - if (mode == ATMOSPHERE) - return "Atmosphere Component"; - return nullptr; - } + const char *NameOf(ComponentType mode); - static const char *IconOf(const ComponentType mode) { - if (mode == PRIMITIVE) - return Icons::view_in_ar.c_str(); - if (mode == TRANSFORM) - return Icons::transform.c_str(); - if (mode == SPHERE_LIGHT || mode == PLANE_LIGHT) - return Icons::lightbulb.c_str(); - if (mode == VOLUME) - return Icons::blur_on.c_str(); - if (mode == ATMOSPHERE) - return Icons::cloud.c_str(); - return nullptr; - } + const char *IconOf(ComponentType mode); } #endif //COMPONENTTYPE_H diff --git a/src/enum/engine-definitions.h b/src/enum/engine-definitions.h index 4b026676..cb8984f8 100644 --- a/src/enum/engine-definitions.h +++ b/src/enum/engine-definitions.h @@ -1,12 +1,12 @@ #ifndef ENGINEID_H #define ENGINEID_H -typedef unsigned long long EntityID; +#include #define MAX_VOLUMES 300 #define MAX_LIGHTS 300 #define MAX_MATERIALS 100 #define MAX_MESH_INSTANCES 1000 -#define EMPTY_ENTITY 0 +#define EMPTY_ENTITY entt::null #define FILE_METADATA ".mjson" #define FILE_SCENE "-scene" #define FILE_MESH "-mesh" diff --git a/src/repository/dock/DockRepository.h b/src/repository/dock/DockRepository.h index 79d181fa..145cb3b3 100644 --- a/src/repository/dock/DockRepository.h +++ b/src/repository/dock/DockRepository.h @@ -8,7 +8,7 @@ namespace Metal { struct DockRepository final : AbstractRuntimeComponent { DockDTO top{&DockSpace::VIEWPORT, 0.17f}; DockDTO bottom{&DockSpace::FILES, .25f}; - DockDTO rightTop{&DockSpace::HIERARCHY, 0.6f}; + DockDTO rightTop{&DockSpace::WORLD, 0.6f}; DockDTO rightBottom{&DockSpace::INSPECTOR, 0.4f}; bool isInitialized = false; }; diff --git a/src/repository/dock/DockSpace.cpp b/src/repository/dock/DockSpace.cpp index 1f3e379b..4325a88e 100644 --- a/src/repository/dock/DockSpace.cpp +++ b/src/repository/dock/DockSpace.cpp @@ -3,20 +3,22 @@ #include "../../context/editor/dock-spaces/console/ConsolePanel.h" #include "../../context/editor/dock-spaces/files/FilesPanel.h" #include "../../context/editor/dock-spaces/metrics/MetricsPanel.h" +#include "../../context/editor/dock-spaces/repositories/RepositoriesPanel.h" #include "../../context/editor/dock-spaces/inspector/InspectorPanel.h" #include "../../context/editor/dock-spaces/viewport/ViewportPanel.h" -#include "../../context/editor/dock-spaces/hierarchy/HierarchyPanel.h" +#include "../../context/editor/dock-spaces/world/WorldPanel.h" #define CB(clazz) []() { return new clazz; } namespace Metal { DockSpace DockSpace::VIEWPORT{-1, "Viewport", Icons::ipublic, 0, 0,CB(ViewportPanel)}; DockSpace DockSpace::INSPECTOR{0, "Inspector", Icons::search, 4, 4,CB(InspectorPanel)}; - DockSpace DockSpace::HIERARCHY{1, "Hierarchy", Icons::account_tree, 4, 4, CB(HierarchyPanel)}; + DockSpace DockSpace::WORLD{1, "World", Icons::account_tree, 4, 4, CB(WorldPanel)}; DockSpace DockSpace::CONSOLE{2, "Console", Icons::terminal, 4, 4, CB(ConsolePanel)}; DockSpace DockSpace::FILES{3, "Files", Icons::folder_open, 4, 4, CB(FilesPanel)}; DockSpace DockSpace::METRICS{4, "Metrics", Icons::analytics, 4, 4, CB(MetricsPanel)}; - const char *DockSpace::OPTIONS = "Inspector\0Hierarchy\0Console\0Files\0Metrics"; + DockSpace DockSpace::REPOSITORIES{5, "Repositories", Icons::search, 4, 4, CB(RepositoriesPanel)}; + const char *DockSpace::OPTIONS = "Inspector\0World\0Console\0Files\0Metrics\0Repositories"; DockSpace *DockSpace::GetOption(const int selected) { @@ -24,13 +26,15 @@ namespace Metal { case 0: return &INSPECTOR; case 1: - return &HIERARCHY; + return &WORLD; case 2: return &CONSOLE; case 3: return &FILES; case 4: return &METRICS; + case 5: + return &REPOSITORIES; default: return nullptr; } diff --git a/src/repository/dock/DockSpace.h b/src/repository/dock/DockSpace.h index 46eb694b..25b2dcd8 100644 --- a/src/repository/dock/DockSpace.h +++ b/src/repository/dock/DockSpace.h @@ -10,10 +10,11 @@ namespace Metal { struct DockSpace { static DockSpace VIEWPORT; static DockSpace INSPECTOR; - static DockSpace HIERARCHY; + static DockSpace WORLD; static DockSpace CONSOLE; static DockSpace FILES; static DockSpace METRICS; + static DockSpace REPOSITORIES; static const char *OPTIONS; const int index; diff --git a/src/repository/editor/EditorRepository.cpp b/src/repository/editor/EditorRepository.cpp index 21c19f90..84c7cea2 100644 --- a/src/repository/editor/EditorRepository.cpp +++ b/src/repository/editor/EditorRepository.cpp @@ -35,9 +35,15 @@ namespace Metal { j["gizmoUseSnapRotate"] = gizmoUseSnapRotate; j["gizmoUseSnapScale"] = gizmoUseSnapScale; j["showOnlyEntitiesHierarchy"] = showOnlyEntitiesHierarchy; - j["mainSelection"] = mainSelection; - j["selected"] = selected; - j["copied"] = copied; + j["mainSelection"] = static_cast(entt::to_integral(mainSelection)); + j["selected"] = nlohmann::json::array(); + for (auto const& [key, val] : selected) { + j["selected"].push_back(static_cast(entt::to_integral(key))); + } + j["copied"] = nlohmann::json::array(); + for (auto const& entity : copied) { + j["copied"].push_back(static_cast(entt::to_integral(entity))); + } j["shadingMode"] = shadingMode; return j; } @@ -66,9 +72,19 @@ namespace Metal { gizmoUseSnapRotate = j.at("gizmoUseSnapRotate").get(); gizmoUseSnapScale = j.at("gizmoUseSnapScale").get(); showOnlyEntitiesHierarchy = j.at("showOnlyEntitiesHierarchy").get(); - mainSelection = j.at("mainSelection").get(); - selected = j.at("selected").get >(); - copied = j.at("copied").get >(); + mainSelection = static_cast(j.at("mainSelection").get()); + selected.clear(); + if (j.contains("selected") && j.at("selected").is_array()) { + for (auto const& item : j.at("selected")) { + selected[static_cast(item.get())] = true; + } + } + copied.clear(); + if (j.contains("copied") && j.at("copied").is_array()) { + for (auto const& item : j.at("copied")) { + copied.push_back(static_cast(item.get())); + } + } shadingMode = static_cast(j.at("shadingMode").get()); } diff --git a/src/repository/editor/EditorRepository.h b/src/repository/editor/EditorRepository.h index a11981f4..95ae4ac5 100644 --- a/src/repository/editor/EditorRepository.h +++ b/src/repository/editor/EditorRepository.h @@ -45,9 +45,9 @@ namespace Metal { bool gizmoUseSnapScale = false; bool showOnlyEntitiesHierarchy = false; TransformComponent *primitiveSelected = nullptr; - EntityID mainSelection = EMPTY_ENTITY; - std::unordered_map selected{}; - std::vector copied{}; + entt::entity mainSelection = EMPTY_ENTITY; + std::unordered_map selected{}; + std::vector copied{}; std::string focusedWindowName{}; std::vector focusedShortcuts{}; ShadingMode shadingMode = LIT; diff --git a/src/repository/streaming/StreamingService.cpp b/src/repository/streaming/StreamingService.cpp index 91208c74..a3c3667d 100644 --- a/src/repository/streaming/StreamingService.cpp +++ b/src/repository/streaming/StreamingService.cpp @@ -5,50 +5,10 @@ #include "../../service/mesh/MeshInstance.h" #include "../../service/texture/TextureInstance.h" +#include "../../repository/world/components/PrimitiveComponent.h" + namespace Metal { static constexpr int MAX_TIMEOUT = 10000; - static constexpr int MAX_TRIES = 5; - - template - T *stream(IStreamable &service, const std::string &id, - std::unordered_map &lastUse, - std::unordered_map &tries) { - if (!id.empty() && service.getResources().contains(id)) { - auto *e = service.getResource(id); - lastUse[e->getId()] = CTX.engineContext.currentTimeMs; - return e; - } - if (!tries.contains(id)) { - tries[id] = 0; - } - tries[id]++; - if (tries[id] < MAX_TRIES) { - LOG_DEBUG("Streaming " + id); - auto *instance = service.create(id); - if (instance != nullptr) { - tries[id] = 0; - for (auto &dep: instance->getDependencies()) { - if (lastUse.contains(dep)) { - lastUse[dep] = CTX.engineContext.currentTimeMs; - } - } - } - return instance; - } - return nullptr; - } - - SVOInstance *StreamingService::streamSVO(const std::string &id) { - return stream(CTX.voxelService, id, lastUse, tries); - } - - MeshInstance *StreamingService::streamMesh(const std::string &id) { - return stream(CTX.meshService, id, lastUse, tries); - } - - TextureInstance *StreamingService::streamTexture(const std::string &id) { - return stream(CTX.textureService, id, lastUse, tries); - } template void disposeResources(AbstractResourceService &service, std::unordered_map &lastUse) { @@ -69,6 +29,23 @@ namespace Metal { } void StreamingService::onSync() { + auto view = CTX.worldRepository.registry.view(); + for (auto entity: view) { + auto &meshComp = view.get(entity); + if (!meshComp.meshId.empty()) { + lastUse[meshComp.meshId] = CTX.engineContext.currentTimeMs; + } + if (!meshComp.albedo.empty()) { + lastUse[meshComp.albedo] = CTX.engineContext.currentTimeMs; + } + if (!meshComp.roughness.empty()) { + lastUse[meshComp.roughness] = CTX.engineContext.currentTimeMs; + } + if (!meshComp.metallic.empty()) { + lastUse[meshComp.metallic] = CTX.engineContext.currentTimeMs; + } + } + if ((CTX.engineContext.currentTime - sinceLastCleanup).count() >= MAX_TIMEOUT) { sinceLastCleanup = CTX.engineContext.currentTime; disposeResources(CTX.meshService, lastUse); diff --git a/src/repository/streaming/StreamingService.h b/src/repository/streaming/StreamingService.h index e82f89b8..2fcba091 100644 --- a/src/repository/streaming/StreamingService.h +++ b/src/repository/streaming/StreamingService.h @@ -17,17 +17,10 @@ namespace Metal { struct SVOInstance; class StreamingService final : public AbstractRuntimeComponent { - std::unordered_map tries{}; std::unordered_map lastUse{}; TimePoint sinceLastCleanup; public: - MeshInstance *streamMesh(const std::string &id); - - SVOInstance *streamSVO(const std::string &id); - - TextureInstance *streamTexture(const std::string &id); - void onSync() override; }; } // Metal diff --git a/src/repository/world/WorldRepository.cpp b/src/repository/world/WorldRepository.cpp index f2dc4e5a..897f8710 100644 --- a/src/repository/world/WorldRepository.cpp +++ b/src/repository/world/WorldRepository.cpp @@ -2,66 +2,29 @@ #include "../../context/ApplicationContext.h" #include "../../enum/ComponentType.h" +#include "../../service/mesh/SceneData.h" +#include "../../util/serialization-definitions.h" namespace Metal { - WorldRepository::WorldRepository(): AbstractRuntimeComponent() { - const auto root = registry.create(static_cast(ROOT_ID)); - auto &entity = registry.emplace(root); - entity.initialize(true); - entity.name = "Scene"; - registry.emplace(root); - } - - EntityID WorldRepository::createEntity(std::string name, const bool container) { + entt::entity WorldRepository::createEntity() { registerChange(); const auto entity = registry.create(); - auto &entityComp = registry.emplace(entity); - entityComp.initialize(container); - entityComp.name = std::move(name); - - registry.emplace(entity); - linkEntities(ROOT_ID, static_cast(entity)); - - return static_cast(entity); - } - - void WorldRepository::linkEntities(EntityID parentId, EntityID childId) { - registerChange(); - - const auto child = static_cast(childId); - auto &childHierarchy = registry.get(child); - - if (childHierarchy.parent != EMPTY_ENTITY) { - const auto oldParent = static_cast(childHierarchy.parent); - if (registry.valid(oldParent)) { - auto &oldParentHierarchy = registry.get(oldParent); - oldParentHierarchy.children.erase( - std::ranges::remove(oldParentHierarchy.children, childId).begin(), - oldParentHierarchy.children.end()); - } - } - - const auto newParent = static_cast(parentId); - if (registry.valid(newParent)) { - auto &newParentHierarchy = registry.get(newParent); - newParentHierarchy.children.push_back(childId); - childHierarchy.parent = parentId; - } + createComponent(entity, METADATA); + return entity; } - EntityComponent *WorldRepository::getEntity(const EntityID node) { - const auto entity = static_cast(node); - if (registry.valid(entity)) { - return ®istry.get(entity); + MetadataComponent *WorldRepository::getEntity(const entt::entity node) { + if (registry.valid(node)) { + return ®istry.get(node); } return nullptr; } - void WorldRepository::deleteRecursively(const std::vector &entities) { - for (EntityID entityId: entities) { - const auto entity = static_cast(entityId); - if (!registry.valid(entity)) continue; + void WorldRepository::deleteEntities(const std::vector &entities) { + registerChange(); + for (entt::entity entityId: entities) { + if (!registry.valid(entityId)) continue; if (hiddenEntities.contains(entityId)) { hiddenEntities.erase(entityId); @@ -70,105 +33,94 @@ namespace Metal { culled.erase(entityId); } - if (registry.all_of(entity)) { - auto &hierarchy = registry.get(entity); - if (!hierarchy.children.empty()) { - std::vector childrenToDelete = hierarchy.children; - deleteRecursively(childrenToDelete); - } - - auto parentId = hierarchy.parent; - const auto parent = static_cast(parentId); - if (registry.valid(parent) && registry.all_of(parent)) { - auto &parentHierarchy = registry.get(parent); - parentHierarchy.children.erase( - std::ranges::remove(parentHierarchy.children, entityId).begin(), - parentHierarchy.children.end()); - } - } - registry.destroy(entity); + registry.destroy(entityId); } - } - - void WorldRepository::deleteEntities(const std::vector &entities) { - registerChange(); - deleteRecursively(entities); CTX.engineContext.setUpdateLights(true); CTX.rayTracingService.markDirty(); } - void WorldRepository::changeVisibility(EntityID entity, bool isVisible) { + void WorldRepository::changeVisibility(entt::entity entity, bool isVisible) { registerChange(); - changeVisibilityRecursively(entity, isVisible); - CTX.engineContext.setUpdateLights(true); - CTX.rayTracingService.markDirty(); - } - - void WorldRepository::changeVisibilityRecursively(EntityID entity, const bool isVisible) { if (isVisible) { hiddenEntities.erase(entity); } else { hiddenEntities.insert({entity, true}); } + CTX.engineContext.setUpdateLights(true); + CTX.rayTracingService.markDirty(); + } - const auto e = static_cast(entity); - if (registry.valid(e) && registry.all_of(e)) { - for (const auto child: registry.get(e).children) { - changeVisibilityRecursively(child, isVisible); + void WorldRepository::loadScene(const std::string &sceneId) { + SceneData sceneData; + const auto pathToFile = CTX.getAssetDirectory() + FORMAT_FILE_SCENE(sceneId); + PARSE_TEMPLATE(sceneData, pathToFile) + + for (auto &entityData: sceneData.entities) { + const auto entityId = createEntity(); + + auto &entityComp = registry.get(entityId); + entityComp.name = entityData.entity.name; + + createComponent(entityId, TRANSFORM); + auto &transform = registry.get(entityId); + transform.translation = entityData.transform.translation; + transform.rotation = entityData.transform.rotation; + transform.rotationEuler = entityData.transform.rotationEuler; + transform.scale = entityData.transform.scale; + transform.gizmoCenter = entityData.transform.gizmoCenter; + transform.isStatic = entityData.transform.isStatic; + + if (entityData.primitive) { + + createComponent(entityId, PRIMITIVE); + auto &primitive = registry.get(entityId); + primitive.meshId = entityData.primitive->meshId; + primitive.albedo = entityData.primitive->albedo; + primitive.roughness = entityData.primitive->roughness; + primitive.metallic = entityData.primitive->metallic; + primitive.albedoColor = entityData.primitive->albedoColor; + primitive.roughnessFactor = entityData.primitive->roughnessFactor; + primitive.metallicFactor = entityData.primitive->metallicFactor; + primitive.transmissionFactor = entityData.primitive->transmissionFactor; + primitive.thicknessFactor = entityData.primitive->thicknessFactor; + primitive.ior = entityData.primitive->ior; + primitive.isEmissive = entityData.primitive->isEmissive; + } + + if (entityData.sphereLight) { + createComponent(entityId, SPHERE_LIGHT); + auto &sphereLight = registry.get(entityId); + sphereLight.color = entityData.sphereLight->color; + sphereLight.intensity = entityData.sphereLight->intensity; + sphereLight.radiusSize = entityData.sphereLight->radiusSize; + } + + if (entityData.planeLight) { + createComponent(entityId, PLANE_LIGHT); + auto &planeLight = registry.get(entityId); + planeLight.color = entityData.planeLight->color; + planeLight.intensity = entityData.planeLight->intensity; } } + + CTX.rayTracingService.markDirty(); } - void WorldRepository::createComponent(const EntityID entityId, ComponentTypes::ComponentType type) { - const auto entity = static_cast(entityId); - if (!registry.valid(entity)) { + void WorldRepository::createComponent(const entt::entity entityId, ComponentType type) { + if (!registry.valid(entityId)) { return; } - switch (type) { - case ComponentTypes::PRIMITIVE: { - auto &mesh = registry.emplace_or_replace(entity); - mesh.setEntityId(entityId); - createComponent(entityId, ComponentTypes::TRANSFORM); - CTX.rayTracingService.markDirty(); - break; - } - case ComponentTypes::SPHERE_LIGHT: { - auto light = std::make_unique(); - light->setEntityId(entityId); - registry.emplace_or_replace>(entity, std::move(light)); - createComponent(entityId, ComponentTypes::TRANSFORM); - CTX.engineContext.setUpdateLights(true); - break; - } - case ComponentTypes::PLANE_LIGHT: { - auto light = std::make_unique(); - light->setEntityId(entityId); - registry.emplace_or_replace>(entity, std::move(light)); - createComponent(entityId, ComponentTypes::TRANSFORM); - CTX.engineContext.setUpdateLights(true); - break; - } - case ComponentTypes::VOLUME: { - auto &vol = registry.emplace_or_replace(entity); - vol.setEntityId(entityId); - createComponent(entityId, ComponentTypes::TRANSFORM); - break; - } - case ComponentTypes::TRANSFORM: { - if (!registry.all_of(entity)) { - auto &trans = registry.emplace(entity); - trans.setEntityId(entityId); + + for (const auto &compDef: ComponentTypes::getComponents()) { + if (compDef.type == type) { + for (const auto &dep: compDef.dependencies) { + createComponent(entityId, dep); + } + if (compDef.creator) { + compDef.creator(*this, entityId); } break; } - case ComponentTypes::ATMOSPHERE: { - auto &atmo = registry.emplace_or_replace(entity); - atmo.setEntityId(entityId); - CTX.engineContext.setGISettingsUpdated(true); - break; - } - default: - break; } } @@ -177,33 +129,20 @@ namespace Metal { j["camera"] = camera.toJson(); nlohmann::json entitiesJson; - for (auto entity : registry.view()) { - const auto id = static_cast(entity); + for (auto entity: registry.view()) { nlohmann::json ej; - if (registry.all_of(entity)) { - ej["entity"] = registry.get(entity).toJson(); - } - if (registry.all_of(entity)) { - auto &h = registry.get(entity); - ej["hierarchy"] = {{"parent", h.parent}, {"children", h.children}}; - } - if (registry.all_of(entity)) { - ej["mesh"] = registry.get(entity).toJson(); - } - if (registry.all_of(entity)) { - ej["transform"] = registry.get(entity).toJson(); + if (registry.all_of(entity)) { + ej["entity"] = registry.get(entity).toJson(); } - if (registry.all_of>(entity)) { - ej["light"] = registry.get>(entity)->toJson(); - } - if (registry.all_of(entity)) { - ej["volume"] = registry.get(entity).toJson(); - } - if (registry.all_of(entity)) { - ej["atmosphere"] = registry.get(entity).toJson(); + + for (const auto &compDef: ComponentTypes::getComponents()) { + auto cj = compDef.toJson(const_cast(*this), entity); + if (!cj.is_null()) { + ej[compDef.jsonKey] = std::move(cj); + } } - entitiesJson[std::to_string(id)] = ej; + entitiesJson[std::to_string(entt::to_integral(entity))] = ej; } j["registry"] = entitiesJson; j["hiddenEntities"] = hiddenEntities; @@ -216,47 +155,24 @@ namespace Metal { registry.clear(); if (j.contains("registry")) { for (auto const &[key, val]: j.at("registry").items()) { - const auto id = static_cast(std::stoull(key)); - const auto entity = registry.create(static_cast(id)); + const auto id = static_cast(static_cast(std::stoul(key))); + const auto entity = registry.create(id); if (val.contains("entity")) { - registry.emplace(entity).fromJson(val.at("entity")); - } - if (val.contains("hierarchy")) { - auto &h = registry.emplace(entity); - h.parent = val.at("hierarchy").at("parent").get(); - h.children = val.at("hierarchy").at("children").get>(); - } - if (val.contains("mesh")) { - registry.emplace(entity).fromJson(val.at("mesh")); - } - if (val.contains("transform")) { - registry.emplace(entity).fromJson(val.at("transform")); + registry.emplace(entity).fromJson(val.at("entity")); } - if (val.contains("light")) { - auto &lj = val.at("light"); - std::string type = lj.at("lightType").get(); - if (type == "SPHERE") { - auto light = std::make_unique(); - light->fromJson(lj); - registry.emplace>(entity, std::move(light)); - } else if (type == "PLANE") { - auto light = std::make_unique(); - light->fromJson(lj); - registry.emplace>(entity, std::move(light)); + + for (const auto &compDef: ComponentTypes::getComponents()) { + if (val.contains(compDef.jsonKey)) { + compDef.creator(*this, id); + compDef.fromJson(*this, id, val.at(compDef.jsonKey)); } } - if (val.contains("volume")) { - registry.emplace(entity).fromJson(val.at("volume")); - } - if (val.contains("atmosphere")) { - registry.emplace(entity).fromJson(val.at("atmosphere")); - } } } if (j.contains("hiddenEntities")) { - hiddenEntities = j.at("hiddenEntities").get>(); + hiddenEntities = j.at("hiddenEntities").get >(); } } } // Metal diff --git a/src/repository/world/WorldRepository.h b/src/repository/world/WorldRepository.h index 6ffffa3d..2597e3ee 100644 --- a/src/repository/world/WorldRepository.h +++ b/src/repository/world/WorldRepository.h @@ -10,13 +10,12 @@ #include "../../util/Serializable.h" #include "../../enum/engine-definitions.h" #include "../../service/camera/Camera.h" -#include "impl/EntityComponent.h" +#include "impl/MetadataComponent.h" #include "../../enum/ComponentType.h" -#include "components/LightComponent.h" -#include "components/PrimitiveComponent.h" #include "components/SphereLightComponent.h" #include "components/PlaneLightComponent.h" #include "components/TransformComponent.h" +#include "components/PrimitiveComponent.h" #include "components/VolumeComponent.h" #include "components/AtmosphereComponent.h" @@ -24,35 +23,27 @@ namespace Metal { class Inspectable; struct WorldRepository final : AbstractRuntimeComponent, Serializable { - static constexpr EntityID ROOT_ID = 1; - - explicit WorldRepository(); - Camera camera{-(glm::pi() / 4), glm::pi() / 4, {10, 10, 10}}; entt::registry registry{}; - std::unordered_map culled{}; - std::unordered_map hiddenEntities{}; + std::unordered_map culled{}; + std::unordered_map hiddenEntities{}; - void createComponent(EntityID entity, ComponentTypes::ComponentType type); + void createComponent(entt::entity entity, ComponentType type); - EntityID createEntity(std::string name = "New Entity", bool container = false); + entt::entity createEntity(); - void linkEntities(EntityID parentId, EntityID childId); + [[nodiscard]] MetadataComponent *getEntity(entt::entity node); - [[nodiscard]] EntityComponent *getEntity(EntityID node); + void deleteEntities(const std::vector &entities); - void deleteEntities(const std::vector &entities); + void changeVisibility(entt::entity entity, bool isVisible); - void changeVisibility(EntityID entity, bool isVisible); + void loadScene(const std::string &sceneId); nlohmann::json toJson() const override; void fromJson(const nlohmann::json &j) override; - private: - void deleteRecursively(const std::vector &entities); - - void changeVisibilityRecursively(EntityID entity, bool isVisible); }; } // Metal diff --git a/src/repository/world/components/AtmosphereComponent.cpp b/src/repository/world/components/AtmosphereComponent.cpp index 93a82abb..652c3dab 100644 --- a/src/repository/world/components/AtmosphereComponent.cpp +++ b/src/repository/world/components/AtmosphereComponent.cpp @@ -46,8 +46,8 @@ namespace Metal { registerColor(middayColor, "Sun", "Midday color"); } - ComponentTypes::ComponentType AtmosphereComponent::getType() { - return ComponentTypes::ATMOSPHERE; + ComponentType AtmosphereComponent::getType() { + return ComponentType::ATMOSPHERE; } void AtmosphereComponent::onUpdate(InspectableMember *member) { @@ -86,7 +86,7 @@ namespace Metal { } void AtmosphereComponent::fromJson(const nlohmann::json &j) { - entityId = j.at("entityId").get(); + entityId = j.at("entityId").get(); albedo = {j.at("albedo")[0], j.at("albedo")[1], j.at("albedo")[2]}; density = j.at("density").get(); g = j.at("g").get(); diff --git a/src/repository/world/components/AtmosphereComponent.h b/src/repository/world/components/AtmosphereComponent.h index f5c58568..cdbb3cad 100644 --- a/src/repository/world/components/AtmosphereComponent.h +++ b/src/repository/world/components/AtmosphereComponent.h @@ -32,7 +32,7 @@ namespace Metal { void registerFields() override; - ComponentTypes::ComponentType getType() override; + ComponentType getType() override; void onUpdate(InspectableMember *member) override; diff --git a/src/repository/world/components/LightComponent.h b/src/repository/world/components/LightComponent.h deleted file mode 100644 index 59970491..00000000 --- a/src/repository/world/components/LightComponent.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef LIGHTCOMPONENT_H -#define LIGHTCOMPONENT_H - -#include "../impl/AbstractComponent.h" -#include "../../../util/Serializable.h" -#include - -#include "../../../enum/LightType.h" - -namespace Metal { - struct LightComponent : AbstractComponent, Serializable { - glm::vec3 color = glm::vec3(1.0f); - float intensity = 1.0f; - - virtual LightTypes::LightType getLightType() = 0; - - void registerFields() override; - - void onUpdate(InspectableMember *member) override; - - nlohmann::json toJson() const override { - nlohmann::json j; - j["entityId"] = entityId; - j["color"] = {color.x, color.y, color.z}; - j["intensity"] = intensity; - return j; - } - - void fromJson(const nlohmann::json& j) override { - entityId = j.at("entityId").get(); - color.x = j.at("color")[0].get(); - color.y = j.at("color")[1].get(); - color.z = j.at("color")[2].get(); - intensity = j.at("intensity").get(); - } - }; -} // Metal - -#endif //LIGHTCOMPONENT_H diff --git a/src/repository/world/components/LightComponent.cpp b/src/repository/world/components/PlaneLightComponent.cpp similarity index 61% rename from src/repository/world/components/LightComponent.cpp rename to src/repository/world/components/PlaneLightComponent.cpp index 3acc9ddb..a9bd7a44 100644 --- a/src/repository/world/components/LightComponent.cpp +++ b/src/repository/world/components/PlaneLightComponent.cpp @@ -1,14 +1,13 @@ -#include "LightComponent.h" - +#include "PlaneLightComponent.h" #include "../../../context/ApplicationContext.h" namespace Metal { - void LightComponent::registerFields() { + void PlaneLightComponent::registerFields() { registerColor(color, "", "Color"); registerFloat(intensity, "", "Intensity", .1, 100); } - void LightComponent::onUpdate(InspectableMember *member) { + void PlaneLightComponent::onUpdate(InspectableMember *member) { CTX.engineContext.setUpdateLights(true); } } // Metal diff --git a/src/repository/world/components/PlaneLightComponent.h b/src/repository/world/components/PlaneLightComponent.h index 8838a44e..8a7f1a16 100644 --- a/src/repository/world/components/PlaneLightComponent.h +++ b/src/repository/world/components/PlaneLightComponent.h @@ -1,25 +1,38 @@ #ifndef PLANELIGHTCOMPONENT_H #define PLANELIGHTCOMPONENT_H -#include "LightComponent.h" +#include "../impl/AbstractComponent.h" #include "../../../util/Serializable.h" +#include namespace Metal { - struct PlaneLightComponent final : LightComponent { - LightTypes::LightType getLightType() override { return LightTypes::PLANE; } + struct PlaneLightComponent final : AbstractComponent, Serializable { + glm::vec3 color = glm::vec3(1.0f); + float intensity = 1.0f; - ComponentTypes::ComponentType getType() override { - return ComponentTypes::PLANE_LIGHT; + void registerFields() override; + + ComponentType getType() override { + return ComponentType::PLANE_LIGHT; } + void onUpdate(InspectableMember *member) override; + nlohmann::json toJson() const override { - nlohmann::json j = LightComponent::toJson(); + nlohmann::json j; + j["entityId"] = entityId; + j["color"] = {color.x, color.y, color.z}; + j["intensity"] = intensity; j["lightType"] = "PLANE"; return j; } void fromJson(const nlohmann::json &j) override { - LightComponent::fromJson(j); + entityId = j.at("entityId").get(); + color.x = j.at("color")[0].get(); + color.y = j.at("color")[1].get(); + color.z = j.at("color")[2].get(); + intensity = j.at("intensity").get(); } }; } // Metal diff --git a/src/repository/world/components/PrimitiveComponent.cpp b/src/repository/world/components/PrimitiveComponent.cpp index 412889e4..26bf57c4 100644 --- a/src/repository/world/components/PrimitiveComponent.cpp +++ b/src/repository/world/components/PrimitiveComponent.cpp @@ -20,11 +20,10 @@ namespace Metal { void PrimitiveComponent::onUpdate(InspectableMember *member) { if (member != nullptr && member->name == "meshId") { - MeshData *data = CTX.meshService.stream(meshId); + MeshData *data = CTX.meshService.loadMeshData(meshId); if (data != nullptr) { - const auto e = static_cast(entityId); - if (CTX.worldRepository.registry.all_of(e)) { - CTX.worldRepository.registry.get(e).gizmoCenter = data->gizmoCenter; + if (CTX.worldRepository.registry.all_of(entityId)) { + CTX.worldRepository.registry.get(entityId).gizmoCenter = data->gizmoCenter; } delete data; } @@ -33,8 +32,8 @@ namespace Metal { CTX.rayTracingService.setNeedsMaterialUpdate(true); } - ComponentTypes::ComponentType PrimitiveComponent::getType() { - return ComponentTypes::PRIMITIVE; + ComponentType PrimitiveComponent::getType() { + return ComponentType::PRIMITIVE; } nlohmann::json PrimitiveComponent::toJson() const { @@ -55,7 +54,7 @@ namespace Metal { } void PrimitiveComponent::fromJson(const nlohmann::json &j) { - entityId = j.at("entityId").get(); + entityId = j.at("entityId").get(); meshId = j.at("meshId").get(); albedo = j.at("albedo").get(); diff --git a/src/repository/world/components/PrimitiveComponent.h b/src/repository/world/components/PrimitiveComponent.h index a4392d85..d5229ac4 100644 --- a/src/repository/world/components/PrimitiveComponent.h +++ b/src/repository/world/components/PrimitiveComponent.h @@ -26,7 +26,7 @@ namespace Metal { void onUpdate(InspectableMember *member) override; - ComponentTypes::ComponentType getType() override; + ComponentType getType() override; nlohmann::json toJson() const override; diff --git a/src/repository/world/components/SphereLightComponent.cpp b/src/repository/world/components/SphereLightComponent.cpp index a1f10ba9..8e8eed06 100644 --- a/src/repository/world/components/SphereLightComponent.cpp +++ b/src/repository/world/components/SphereLightComponent.cpp @@ -3,7 +3,12 @@ namespace Metal { void SphereLightComponent::registerFields() { - LightComponent::registerFields(); + registerColor(color, "", "Color"); + registerFloat(intensity, "", "Intensity", .1, 100); registerFloat(radiusSize, "", "Radius", .1, 10); } + + void SphereLightComponent::onUpdate(InspectableMember *member) { + CTX.engineContext.setUpdateLights(true); + } } // Metal diff --git a/src/repository/world/components/SphereLightComponent.h b/src/repository/world/components/SphereLightComponent.h index 45513378..9e5008c8 100644 --- a/src/repository/world/components/SphereLightComponent.h +++ b/src/repository/world/components/SphereLightComponent.h @@ -1,29 +1,40 @@ #ifndef SPHERELIGHTCOMPONENT_H #define SPHERELIGHTCOMPONENT_H -#include "LightComponent.h" +#include "../impl/AbstractComponent.h" +#include "../../../util/Serializable.h" +#include namespace Metal { - struct SphereLightComponent final : LightComponent { + struct SphereLightComponent final : AbstractComponent, Serializable { + glm::vec3 color = glm::vec3(1.0f); + float intensity = 1.0f; float radiusSize = 1; - LightTypes::LightType getLightType() override { return LightTypes::SPHERE; } - void registerFields() override; - ComponentTypes::ComponentType getType() override { - return ComponentTypes::SPHERE_LIGHT; + ComponentType getType() override { + return ComponentType::SPHERE_LIGHT; } + void onUpdate(InspectableMember *member) override; + nlohmann::json toJson() const override { - nlohmann::json j = LightComponent::toJson(); + nlohmann::json j; + j["entityId"] = entityId; + j["color"] = {color.x, color.y, color.z}; + j["intensity"] = intensity; j["radiusSize"] = radiusSize; j["lightType"] = "SPHERE"; return j; } void fromJson(const nlohmann::json& j) override { - LightComponent::fromJson(j); + entityId = j.at("entityId").get(); + color.x = j.at("color")[0].get(); + color.y = j.at("color")[1].get(); + color.z = j.at("color")[2].get(); + intensity = j.at("intensity").get(); radiusSize = j.at("radiusSize").get(); } }; diff --git a/src/repository/world/components/TransformComponent.cpp b/src/repository/world/components/TransformComponent.cpp index aa43ff86..9efa5cd7 100644 --- a/src/repository/world/components/TransformComponent.cpp +++ b/src/repository/world/components/TransformComponent.cpp @@ -1,6 +1,7 @@ #include "TransformComponent.h" #include "VolumeComponent.h" -#include "LightComponent.h" +#include "SphereLightComponent.h" +#include "PlaneLightComponent.h" #include "../../../common/interface/Icons.h" #include "../../../context/ApplicationContext.h" @@ -14,13 +15,13 @@ namespace Metal { registerBool(isStatic, "", "Static?"); } - ComponentTypes::ComponentType TransformComponent::getType() { - return ComponentTypes::TRANSFORM; + ComponentType TransformComponent::getType() { + return TRANSFORM; } void TransformComponent::onUpdate(InspectableMember *member) { - const auto e = static_cast(entityId); - bool isLight = CTX.worldRepository.registry.all_of >(e); + bool isLight = CTX.worldRepository.registry.all_of(entityId) || + CTX.worldRepository.registry.all_of(entityId); if (isLight) { CTX.engineContext.setUpdateLights(true); } @@ -48,7 +49,7 @@ namespace Metal { } void TransformComponent::fromJson(const nlohmann::json &j) { - entityId = j.at("entityId").get(); + entityId = j.at("entityId").get(); translation = {j.at("translation")[0], j.at("translation")[1], j.at("translation")[2]}; rotation = {j.at("rotation")[3], j.at("rotation")[0], j.at("rotation")[1], j.at("rotation")[2]}; rotationEuler = {j.at("rotationEuler")[0], j.at("rotationEuler")[1], j.at("rotationEuler")[2]}; diff --git a/src/repository/world/components/TransformComponent.h b/src/repository/world/components/TransformComponent.h index 6e627233..3315bcfd 100644 --- a/src/repository/world/components/TransformComponent.h +++ b/src/repository/world/components/TransformComponent.h @@ -22,7 +22,7 @@ namespace Metal { void registerFields() override; - ComponentTypes::ComponentType getType() override; + ComponentType getType() override; void onUpdate(InspectableMember *member) override; diff --git a/src/repository/world/components/VolumeComponent.cpp b/src/repository/world/components/VolumeComponent.cpp index e961f161..924594e5 100644 --- a/src/repository/world/components/VolumeComponent.cpp +++ b/src/repository/world/components/VolumeComponent.cpp @@ -5,8 +5,8 @@ namespace Metal { void VolumeComponent::registerFields() { } - ComponentTypes::ComponentType VolumeComponent::getType() { - return ComponentTypes::VOLUME; + ComponentType VolumeComponent::getType() { + return VOLUME; } void VolumeComponent::onUpdate(InspectableMember *member) { diff --git a/src/repository/world/components/VolumeComponent.h b/src/repository/world/components/VolumeComponent.h index b62839fd..fc30abd2 100644 --- a/src/repository/world/components/VolumeComponent.h +++ b/src/repository/world/components/VolumeComponent.h @@ -11,7 +11,7 @@ namespace Metal { void registerFields() override; - ComponentTypes::ComponentType getType() override; + ComponentType getType() override; void onUpdate(InspectableMember *member) override; @@ -22,7 +22,7 @@ namespace Metal { } void fromJson(const nlohmann::json& j) override { - entityId = j.at("entityId").get(); + entityId = j.at("entityId").get(); } }; } // Metal diff --git a/src/repository/world/impl/AbstractComponent.h b/src/repository/world/impl/AbstractComponent.h index 14bf540f..b9ab3ebb 100644 --- a/src/repository/world/impl/AbstractComponent.h +++ b/src/repository/world/impl/AbstractComponent.h @@ -1,35 +1,34 @@ #ifndef ABSTRACTCOMPONENT_H #define ABSTRACTCOMPONENT_H #include "../../../common/inspection/Inspectable.h" -#include "../../../enum/engine-definitions.h" #include "../../../enum/ComponentType.h" namespace Metal { struct AbstractComponent : Inspectable { AbstractComponent() = default; - [[nodiscard]] EntityID getEntityId() const { + [[nodiscard]] entt::entity getEntityId() const { return entityId; } - void setEntityId(const EntityID entityId) { + void setEntityId(const entt::entity entityId) { this->entityId = entityId; } const char *getIcon() override { - return ComponentTypes::IconOf(getType()); + return Metal::ComponentTypes::IconOf(getType()); } const char *getTitle() override { - return ComponentTypes::NameOf(getType()); + return Metal::ComponentTypes::NameOf(getType()); } - virtual ComponentTypes::ComponentType getType() { + virtual ComponentType getType() { throw std::runtime_error("Not implemented"); } protected: - EntityID entityId{}; + entt::entity entityId{}; }; } // Metal diff --git a/src/repository/world/impl/EntityComponent.cpp b/src/repository/world/impl/EntityComponent.cpp deleted file mode 100644 index 9a65f908..00000000 --- a/src/repository/world/impl/EntityComponent.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#include "EntityComponent.h" -#include "../../../common/interface/Icons.h" -#include "../../../util/UIUtil.h" - -namespace Metal { - void EntityComponent::initialize(bool container) { - this->isContainer = container; - if (container) { - color = glm::vec3(UIUtil::DIRECTORY_COLOR.x, UIUtil::DIRECTORY_COLOR.y, UIUtil::DIRECTORY_COLOR.z); - } else { - color = glm::vec3(1, 1, 1); - } - } - - void EntityComponent::registerFields() { - registerText(name, "", "Name"); - registerColor(color, "", "Hierarchy Color"); - } - - const char *EntityComponent::getIcon() { - return isContainer ? Icons::inventory_2.c_str() : Icons::category.c_str(); - } -} diff --git a/src/repository/world/impl/MetadataComponent.cpp b/src/repository/world/impl/MetadataComponent.cpp new file mode 100644 index 00000000..bd5dc915 --- /dev/null +++ b/src/repository/world/impl/MetadataComponent.cpp @@ -0,0 +1,14 @@ +#include "MetadataComponent.h" +#include "../../../common/interface/Icons.h" +#include "../../../util/UIUtil.h" + +namespace Metal { + void MetadataComponent::registerFields() { + registerText(name, "", "Name"); + registerColor(color, "", "Hierarchy Color"); + } + + ComponentType MetadataComponent::getType() { + return METADATA; + } +} diff --git a/src/repository/world/impl/EntityComponent.h b/src/repository/world/impl/MetadataComponent.h similarity index 61% rename from src/repository/world/impl/EntityComponent.h rename to src/repository/world/impl/MetadataComponent.h index 8ed38696..4923e86e 100644 --- a/src/repository/world/impl/EntityComponent.h +++ b/src/repository/world/impl/MetadataComponent.h @@ -3,22 +3,21 @@ #include #include +#include "AbstractComponent.h" #include "../../../enum/engine-definitions.h" #include "../../../enum/ComponentType.h" #include "../../../common/inspection/Inspectable.h" #include "../../../util/Serializable.h" namespace Metal { - struct EntityComponent final : Inspectable, Serializable { + struct MetadataComponent final : AbstractComponent, Serializable { std::string name = "New entity"; - glm::vec3 color{}; - bool isContainer = false; + glm::vec3 color{1,1,1}; nlohmann::json toJson() const override { nlohmann::json j; j["name"] = name; j["color"] = {color.x, color.y, color.z}; - j["isContainer"] = isContainer; return j; } @@ -27,25 +26,11 @@ namespace Metal { color.x = j.at("color")[0].get(); color.y = j.at("color")[1].get(); color.z = j.at("color")[2].get(); - isContainer = j.at("isContainer").get(); } - EntityComponent() = default; - - void initialize(bool container); - void registerFields() override; - const char *getIcon() override; - - const char *getTitle() override { - return name.c_str(); - } - }; - - struct HierarchyComponent { - EntityID parent = EMPTY_ENTITY; - std::vector children{}; + ComponentType getType() override; }; } // Metal diff --git a/src/service/abstract/IStreamable.h b/src/service/abstract/IStreamable.h deleted file mode 100644 index 26727f23..00000000 --- a/src/service/abstract/IStreamable.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef ISTREAMABLE_H -#define ISTREAMABLE_H - -#include -#include "AbstractResourceService.h" - -namespace Metal { - class RuntimeResource; - - template - class IStreamable : public AbstractResourceService { - public: - virtual ~IStreamable() = default; - - virtual T *create(const std::string &id) = 0; - }; -} - -#endif //ISTREAMABLE_H diff --git a/src/service/lights/LightService.cpp b/src/service/lights/LightService.cpp index 8a26f964..1cf11126 100644 --- a/src/service/lights/LightService.cpp +++ b/src/service/lights/LightService.cpp @@ -2,37 +2,52 @@ #include #include "../../context/ApplicationContext.h" #include "../../repository/world/components/SphereLightComponent.h" +#include "../../repository/world/components/PlaneLightComponent.h" #include "../buffer/BufferInstance.h" #include "../../enum/EngineResourceIDs.h" +#include "../../enum/LightType.h" #include "../../repository/world/components/AtmosphereComponent.h" namespace Metal { void LightService::registerLights() { - auto view = CTX.worldRepository.registry.view, TransformComponent>(); - for (auto [entity, l_ptr, t]: view.each()) { - const auto entityId = static_cast(entity); + auto sphereView = CTX.worldRepository.registry.view(); + for (auto [entityId, l, t]: sphereView.each()) { + if (CTX.worldRepository.hiddenEntities.contains(entityId)) { continue; } auto &translation = t.translation; - auto &l = *l_ptr; - const auto lightType = l.getLightType(); glm::vec3 normal(0.0f, 1.0f, 0.0f); glm::vec3 rotatedNormal = t.rotation * normal; - float radiusOrScale = 0; - if (lightType == LightTypes::SPHERE) { - radiusOrScale = static_cast(l).radiusSize; + items.push_back(LightData( + glm::vec4(l.color, l.intensity), + translation, + glm::normalize(rotatedNormal), + glm::vec3(l.radiusSize), + LightTypes::LightType::SPHERE + )); + } + + auto planeView = CTX.worldRepository.registry.view(); + for (auto [entityId, l, t]: planeView.each()) { + + if (CTX.worldRepository.hiddenEntities.contains(entityId)) { + continue; } + auto &translation = t.translation; + + glm::vec3 normal(0.0f, 1.0f, 0.0f); + glm::vec3 rotatedNormal = t.rotation * normal; items.push_back(LightData( glm::vec4(l.color, l.intensity), translation, glm::normalize(rotatedNormal), - lightType == LightTypes::SPHERE ? glm::vec3(radiusOrScale) : glm::vec3(t.scale), - lightType + glm::vec3(t.scale), + LightTypes::LightType::PLANE )); } } @@ -47,7 +62,7 @@ namespace Metal { atmo.sunPosition, glm::vec3(0), glm::vec3(atmo.sunRadius), - LightTypes::SPHERE + LightTypes::LightType::SPHERE )); } } diff --git a/src/service/material/MaterialImporterService.cpp b/src/service/material/MaterialImporterService.cpp index a62e1794..cc8def39 100644 --- a/src/service/material/MaterialImporterService.cpp +++ b/src/service/material/MaterialImporterService.cpp @@ -1,85 +1,91 @@ #include "MaterialImporterService.h" #include "../../context/ApplicationContext.h" -#include "../../dto/file/EntryMetadata.h" #include "../../enum/engine-definitions.h" -#include "../../util/FilesUtil.h" +#include "../../repository/world/components/PrimitiveComponent.h" #include #include -#include "../../util/serialization-definitions.h" namespace Metal { - void MaterialImporterService::collectMaterials(const std::string &targetDir, const aiScene *scene, - std::unordered_map &materialMap, - const std::string &rootDirectory, - const std::stop_token &stopToken) const { + void MaterialImporterService::importMaterial(const std::string &targetDir, const aiMaterial *material, + const aiScene *scene, const std::string &rootDirectory, + PrimitiveComponent &primitive, + const std::stop_token &stopToken) const { namespace fs = std::filesystem; - LOG_INFO("Processing materials for scene..."); - for (unsigned int i = 0; i < scene->mNumMaterials; ++i) { - if (stopToken.stop_requested()) return; - const aiMaterial *material = scene->mMaterials[i]; - auto materialData = MaterialData{}; - const auto importAssimpTexture = [& - ](const aiString &assimpPath, const std::string &nameHint) -> std::string { - if (assimpPath.length == 0) return ""; - const std::string p = assimpPath.C_Str(); + const auto importAssimpTexture = [&](const aiString &assimpPath, const std::string &nameHint) -> std::string { + if (assimpPath.length == 0) return ""; + const std::string p = assimpPath.C_Str(); - // Embedded textures are referenced as "*". - if (!p.empty() && p[0] == '*') { - try { - const unsigned int embeddedIndex = static_cast(std::stoul(p.substr(1))); - if (scene && embeddedIndex < scene->mNumTextures) { - return CTX.textureImporter.importEmbeddedTexture( - targetDir, scene->mTextures[embeddedIndex], nameHint); - } - } catch (std::exception &e) { - LOG_ERROR("Failed to import texture: " + std::string(e.what())); - return ""; - } - return ""; - } - - fs::path resolved = fs::path(p); - if (!resolved.is_absolute()) { - resolved = fs::path(rootDirectory) / resolved; - } - resolved = resolved.lexically_normal(); + // Embedded textures are referenced as "*". + if (!p.empty() && p[0] == '*') { try { - return CTX.textureImporter.importData(targetDir, resolved.string(), nullptr, stopToken); + const unsigned int embeddedIndex = static_cast(std::stoul(p.substr(1))); + if (scene && embeddedIndex < scene->mNumTextures) { + return CTX.textureImporter.importEmbeddedTexture( + targetDir, scene->mTextures[embeddedIndex], nameHint); + } } catch (std::exception &e) { - LOG_ERROR("Failed to import texture " + resolved.string() + ": " + e.what()); + LOG_ERROR("Failed to import texture: " + std::string(e.what())); return ""; } - }; + return ""; + } - const auto trySetFromType = [&](std::string &slot, aiTextureType type, const std::string &nameHint) { - if (!slot.empty()) return; - if (material->GetTextureCount(type) == 0) return; - aiString texturePath; - if (material->GetTexture(type, 0, &texturePath) == AI_SUCCESS) { - slot = importAssimpTexture(texturePath, nameHint); - } - }; + fs::path resolved = fs::path(p); + if (!resolved.is_absolute()) { + resolved = fs::path(rootDirectory) / resolved; + } + resolved = resolved.lexically_normal(); + try { + return CTX.textureImporter.importData(targetDir, resolved.string(), nullptr, stopToken); + } catch (std::exception &e) { + LOG_ERROR("Failed to import texture " + resolved.string() + ": " + e.what()); + return ""; + } + }; - // Albedo - trySetFromType(materialData.albedo, aiTextureType_BASE_COLOR, "albedo"); - trySetFromType(materialData.albedo, aiTextureType_DIFFUSE, "albedo"); + const auto trySetFromType = [&](std::string &slot, aiTextureType type, const std::string &nameHint) { + if (!slot.empty()) return; + if (material->GetTextureCount(type) == 0) return; + aiString texturePath; + if (material->GetTexture(type, 0, &texturePath) == AI_SUCCESS) { + slot = importAssimpTexture(texturePath, nameHint); + } + }; - // Metallic / Roughness - trySetFromType(materialData.metallic, aiTextureType_METALNESS, "metallic"); - trySetFromType(materialData.roughness, aiTextureType_DIFFUSE_ROUGHNESS, "roughness"); + // Albedo + trySetFromType(primitive.albedo, aiTextureType_BASE_COLOR, "albedo"); + trySetFromType(primitive.albedo, aiTextureType_DIFFUSE, "albedo"); + // Metallic / Roughness + trySetFromType(primitive.metallic, aiTextureType_METALNESS, "metallic"); + trySetFromType(primitive.roughness, aiTextureType_DIFFUSE_ROUGHNESS, "roughness"); - // If we didn't import any textures, don't create/persist a material at all. - if (materialData.albedo.empty() && materialData.roughness.empty() && - materialData.metallic.empty()) { - LOG_INFO("Skipping material " + std::to_string(i) + ": no textures associated"); - continue; - } + // Factors & Colors + aiColor4D color; + if (material->Get(AI_MATKEY_COLOR_DIFFUSE, color) == AI_SUCCESS) { + primitive.albedoColor = {color.r, color.g, color.b}; + } + + if (material->Get(AI_MATKEY_COLOR_EMISSIVE, color) == AI_SUCCESS) { + primitive.isEmissive = (color.r > 0 || color.g > 0 || color.b > 0); + } - materialMap.insert({i, materialData}); + float factor; + if (material->Get(AI_MATKEY_METALLIC_FACTOR, factor) == AI_SUCCESS) { + primitive.metallicFactor = factor; + } + + if (material->Get(AI_MATKEY_ROUGHNESS_FACTOR, factor) == AI_SUCCESS) { + primitive.roughnessFactor = factor; + } + + if (material->Get(AI_MATKEY_TRANSMISSION_FACTOR, factor) == AI_SUCCESS) { + primitive.transmissionFactor = factor; + } - LOG_INFO("Processed material: " + std::to_string(i)); + if (material->Get(AI_MATKEY_REFRACTI, factor) == AI_SUCCESS) { + primitive.ior = factor; } } } diff --git a/src/service/material/MaterialImporterService.h b/src/service/material/MaterialImporterService.h index 5bb7aff6..52c9aedd 100644 --- a/src/service/material/MaterialImporterService.h +++ b/src/service/material/MaterialImporterService.h @@ -9,19 +9,13 @@ #include "../abstract/AbstractResourceService.h" namespace Metal { - struct MaterialData { - std::string albedo; - std::string roughness; - std::string metallic; - }; + struct PrimitiveComponent; class MaterialImporterService final : public AbstractRuntimeComponent { public: - - void collectMaterials(const std::string &targetDir, const aiScene *scene, - std::unordered_map &materialMap, - const std::string &rootDirectory, - const std::stop_token &stopToken = {}) const; + void importMaterial(const std::string &targetDir, const aiMaterial *material, const aiScene *scene, + const std::string &rootDirectory, PrimitiveComponent &primitive, + const std::stop_token &stopToken = {}) const; }; } diff --git a/src/service/material/MaterialService.cpp b/src/service/material/MaterialService.cpp index 0f4a6cf4..80c72174 100644 --- a/src/service/material/MaterialService.cpp +++ b/src/service/material/MaterialService.cpp @@ -21,19 +21,19 @@ namespace Metal { materialData.metallicTextureId = 0; if (!data.albedo.empty()) { - auto *tex = CTX.textureService.create(data.albedo); + auto *tex = CTX.textureService.stream(data.albedo); if (tex != nullptr) { materialData.albedoTextureId = CTX.textureService.getTextureIndex(data.albedo); } } if (!data.roughness.empty()) { - auto *tex = CTX.textureService.create(data.roughness); + auto *tex = CTX.textureService.stream(data.roughness); if (tex != nullptr) { materialData.roughnessTextureId = CTX.textureService.getTextureIndex(data.roughness); } } if (!data.metallic.empty()) { - auto *tex = CTX.textureService.create(data.metallic); + auto *tex = CTX.textureService.stream(data.metallic); if (tex != nullptr) { materialData.metallicTextureId = CTX.textureService.getTextureIndex(data.metallic); } diff --git a/src/service/mesh/EntityAssetData.h b/src/service/mesh/EntityAssetData.h deleted file mode 100644 index 2b4e1845..00000000 --- a/src/service/mesh/EntityAssetData.h +++ /dev/null @@ -1,67 +0,0 @@ -#ifndef ENTITYASSETDATA_H -#define ENTITYASSETDATA_H -#include - -#include "../../util/Serializable.h" -#include - -namespace Metal { - struct EntityAssetData final : Serializable { - std::string name{}; - std::string meshId{}; - int parentEntity = -1; - int id; - - std::string albedo; - std::string roughness; - std::string metallic; - glm::vec3 albedoColor{1, 1, 1}; - float roughnessFactor = 1; - float metallicFactor = 0; - float transmissionFactor = 0; - float thicknessFactor = 0; - float ior = 1.45; - bool isEmissive = false; - - nlohmann::json toJson() const override { - nlohmann::json j; - j["id"] = id; - j["name"] = name; - j["meshId"] = meshId; - j["parentEntity"] = parentEntity; - - j["albedo"] = albedo; - j["roughness"] = roughness; - j["metallic"] = metallic; - j["albedoColor"] = {albedoColor.x, albedoColor.y, albedoColor.z}; - j["roughnessFactor"] = roughnessFactor; - j["metallicFactor"] = metallicFactor; - j["transmissionFactor"] = transmissionFactor; - j["thicknessFactor"] = thicknessFactor; - j["ior"] = ior; - j["isEmissive"] = isEmissive; - return j; - } - - void fromJson(const nlohmann::json& j) override { - id = j.at("id").get(); - name = j.at("name").get(); - meshId = j.at("meshId").get(); - parentEntity = j.at("parentEntity").get(); - - albedo = j.value("albedo", ""); - roughness = j.value("roughness", ""); - metallic = j.value("metallic", ""); - if (j.contains("albedoColor")) { - albedoColor = {j.at("albedoColor")[0], j.at("albedoColor")[1], j.at("albedoColor")[2]}; - } - roughnessFactor = j.value("roughnessFactor", 1.0f); - metallicFactor = j.value("metallicFactor", 0.0f); - transmissionFactor = j.value("transmissionFactor", 0.0f); - thicknessFactor = j.value("thicknessFactor", 0.0f); - ior = j.value("ior", 1.45f); - isEmissive = j.value("isEmissive", false); - } - }; -} -#endif //ENTITYASSETDATA_H diff --git a/src/service/mesh/MeshImporterService.cpp b/src/service/mesh/MeshImporterService.cpp index 509ed8ef..f8c2a980 100644 --- a/src/service/mesh/MeshImporterService.cpp +++ b/src/service/mesh/MeshImporterService.cpp @@ -31,8 +31,7 @@ namespace Metal { } void MeshImporterService::persistAllMeshes(const std::string &targetDir, const aiScene *scene, - std::unordered_map &meshMap, - std::unordered_map &meshMaterialMap, + std::unordered_map &meshMap, const std::stop_token &stopToken) const { LOG_INFO("Processing meshes for scene..."); for (unsigned int i = 0; i < scene->mNumMeshes; ++i) { @@ -78,8 +77,7 @@ namespace Metal { } } std::string id = persistMesh(targetDir, meshData); - meshMap.insert({i, id}); - meshMaterialMap.insert({id, assimpMesh->mMaterialIndex}); + meshMap.insert({i, {id, meshData.gizmoCenter}}); LOG_INFO("Persisted mesh: " + meshData.name + " (" + id + ")"); } } diff --git a/src/service/mesh/MeshImporterService.h b/src/service/mesh/MeshImporterService.h index 293f81e1..7e707e86 100644 --- a/src/service/mesh/MeshImporterService.h +++ b/src/service/mesh/MeshImporterService.h @@ -6,16 +6,20 @@ #include #include #include +#include namespace Metal { + struct MeshId { + std::string id; + glm::vec3 gizmoCenter; + }; struct MeshData; class MeshImporterService final : public AbstractRuntimeComponent { public: void persistAllMeshes(const std::string &targetDir, const aiScene *scene, - std::unordered_map &meshMap, - std::unordered_map &meshMaterialMap, + std::unordered_map &meshMap, const std::stop_token &stopToken = {}) const; private: diff --git a/src/service/mesh/MeshService.cpp b/src/service/mesh/MeshService.cpp index 79c448a7..cf7fbe17 100644 --- a/src/service/mesh/MeshService.cpp +++ b/src/service/mesh/MeshService.cpp @@ -2,7 +2,6 @@ #include "MeshInstance.h" #include "MeshData.h" #include "SceneData.h" -#include "EntityAssetData.h" #include "../../context/vulkan/VulkanContext.h" #include "../../util/FilesUtil.h" @@ -17,7 +16,7 @@ namespace Metal { MeshInstance *MeshService::create(const std::string &id) { - MeshData *data = stream(id); + MeshData *data = loadMeshData(id); if (data == nullptr) { return nullptr; } @@ -45,7 +44,18 @@ namespace Metal { return instance; } - MeshData *MeshService::stream(const std::string &id) const { + MeshInstance *MeshService::stream(const std::string &id) { + if (id.empty()) { + return nullptr; + } + auto *resource = getResource(id); + if (resource != nullptr) { + return resource; + } + return create(id); + } + + MeshData *MeshService::loadMeshData(const std::string &id) const { auto pathToFile = CTX.getAssetDirectory() + FORMAT_FILE_MESH(id); if (std::filesystem::exists(pathToFile)) { auto *data = new MeshData; @@ -57,65 +67,6 @@ namespace Metal { return nullptr; } - EntityID MeshService::createMeshEntity(const std::string &name, const std::string &meshId, - const EntityAssetData *data) const { - const auto id = CTX.worldRepository.createEntity(); - CTX.worldRepository.createComponent(id, ComponentTypes::ComponentType::PRIMITIVE); - const auto entity = static_cast(id); - auto &mesh = CTX.worldRepository.registry.get(entity); - mesh.meshId = meshId; - - if (data != nullptr) { - mesh.albedo = data->albedo; - mesh.roughness = data->roughness; - mesh.metallic = data->metallic; - mesh.albedoColor = data->albedoColor; - mesh.roughnessFactor = data->roughnessFactor; - mesh.metallicFactor = data->metallicFactor; - mesh.transmissionFactor = data->transmissionFactor; - mesh.thicknessFactor = data->thicknessFactor; - mesh.ior = data->ior; - mesh.isEmissive = data->isEmissive; - } - - MeshData *meshData = stream(meshId); - if (meshData != nullptr) { - auto &transform = CTX.worldRepository.registry.get(entity); - transform.gizmoCenter = meshData->gizmoCenter; - delete meshData; - } - - CTX.worldRepository.getEntity(id)->name = name; - return id; - } - - void MeshService::createSceneEntities(const std::string &id) const { - auto &repo = CTX.worldRepository; - SceneData sceneData; - auto pathToFile = CTX.getAssetDirectory() + FORMAT_FILE_SCENE(id); - PARSE_TEMPLATE(sceneData, pathToFile) - - std::unordered_map entities; - - for (auto &entity: sceneData.entities) { - if (!entity.meshId.empty()) { - entities.insert({entity.id, createMeshEntity(entity.name, entity.meshId, &entity)}); - } else { - const auto entityId = repo.createEntity(); - entities.insert({entity.id, entityId}); - repo.getEntity(entityId)->name = entity.name; - repo.getEntity(entityId)->initialize(true); - } - } - - for (auto &entity: sceneData.entities) { - if (entity.parentEntity < 0 || !entities.contains(entity.parentEntity)) { - continue; - } - repo.linkEntities(entities.at(entity.parentEntity), entities.at(entity.id)); - } - } - void MeshService::disposeResource(MeshInstance *resource) { LOG_INFO("Disposing of mesh instance"); CTX.rayTracingService.markDirty(); diff --git a/src/service/mesh/MeshService.h b/src/service/mesh/MeshService.h index d4b246fe..68535a20 100644 --- a/src/service/mesh/MeshService.h +++ b/src/service/mesh/MeshService.h @@ -1,7 +1,6 @@ #ifndef MESHSERVICE_H #define MESHSERVICE_H #include "../../service/abstract/AbstractResourceService.h" -#include "../../service/abstract/IStreamable.h" #include "MeshInstance.h" #include "../../enum/engine-definitions.h" @@ -10,16 +9,13 @@ namespace Metal { struct MeshInstance; struct EntityAssetData; - class MeshService final : public IStreamable { + class MeshService final : public AbstractResourceService { public: - MeshInstance *create(const std::string &id) override; + MeshInstance *create(const std::string &id); - MeshData *stream(const std::string &id) const; + MeshInstance *stream(const std::string &id); - EntityID createMeshEntity(const std::string &name, const std::string &meshId, - const EntityAssetData *data) const; - - void createSceneEntities(const std::string &id) const; + MeshData *loadMeshData(const std::string &id) const; void disposeResource(MeshInstance *resource) override; diff --git a/src/service/mesh/SceneData.h b/src/service/mesh/SceneData.h index 45c16af8..852bbd8f 100644 --- a/src/service/mesh/SceneData.h +++ b/src/service/mesh/SceneData.h @@ -1,32 +1,34 @@ #ifndef SCENEDESCRIPTION_H #define SCENEDESCRIPTION_H #include + +#include "SceneEntityData.h" #include "../../util/Serializable.h" -#include "EntityAssetData.h" namespace Metal { + struct SceneData final : Serializable { - std::vector entities; + std::vector entities; std::string name; nlohmann::json toJson() const override { nlohmann::json j; j["name"] = name; nlohmann::json e = nlohmann::json::array(); - for (const auto& ent : entities) { + for (const auto &ent: entities) { e.push_back(ent.toJson()); } j["entities"] = e; return j; } - void fromJson(const nlohmann::json& j) override { + void fromJson(const nlohmann::json &j) override { name = j.at("name").get(); entities.clear(); - for (const auto& ent : j.at("entities")) { - EntityAssetData ead; - ead.fromJson(ent); - entities.push_back(ead); + for (const auto &ent: j.at("entities")) { + SceneEntityData sed; + sed.fromJson(ent); + entities.push_back(sed); } } }; diff --git a/src/service/mesh/SceneEntityData.h b/src/service/mesh/SceneEntityData.h new file mode 100644 index 00000000..8c85068f --- /dev/null +++ b/src/service/mesh/SceneEntityData.h @@ -0,0 +1,48 @@ +#ifndef METAL_ENGINE_SCENEENTITYDATA_H +#define METAL_ENGINE_SCENEENTITYDATA_H +#include +#include "../../repository/world/components/PrimitiveComponent.h" +#include "../../repository/world/components/SphereLightComponent.h" +#include "../../repository/world/components/PlaneLightComponent.h" +#include "../../repository/world/components/TransformComponent.h" +#include "../../repository/world/impl/MetadataComponent.h" + +namespace Metal { + + struct SceneEntityData final : Serializable { + MetadataComponent entity; + TransformComponent transform; + std::optional primitive; + std::optional sphereLight; + std::optional planeLight; + + nlohmann::json toJson() const override { + nlohmann::json j; + j["entity"] = entity.toJson(); + j["transform"] = transform.toJson(); + if (primitive) j["primitive"] = primitive->toJson(); + if (sphereLight) j["sphereLight"] = sphereLight->toJson(); + if (planeLight) j["planeLight"] = planeLight->toJson(); + return j; + } + + void fromJson(const nlohmann::json &j) override { + entity.fromJson(j.at("entity")); + transform.fromJson(j.at("transform")); + if (j.contains("primitive")) { + primitive = PrimitiveComponent(); + primitive->fromJson(j.at("primitive")); + } + if (j.contains("sphereLight")) { + sphereLight = SphereLightComponent(); + sphereLight->fromJson(j.at("sphereLight")); + } + if (j.contains("planeLight")) { + planeLight = PlaneLightComponent(); + planeLight->fromJson(j.at("planeLight")); + } + } + }; +} + +#endif //METAL_ENGINE_SCENEENTITYDATA_H \ No newline at end of file diff --git a/src/service/mesh/SceneImporterService.cpp b/src/service/mesh/SceneImporterService.cpp index fa4db88f..cb265749 100644 --- a/src/service/mesh/SceneImporterService.cpp +++ b/src/service/mesh/SceneImporterService.cpp @@ -2,7 +2,6 @@ #include "../../dto/file/FSEntry.h" #include "MeshData.h" -#include "EntityAssetData.h" #include "SceneData.h" #include "../material/MaterialImporterService.h" #include @@ -15,13 +14,13 @@ #include "../../context/ApplicationContext.h" #include "../../util/serialization-definitions.h" #include "../../dto/file/SceneImportSettingsDTO.h" +#include "../../repository/world/components/SphereLightComponent.h" +#include "../../repository/world/components/PlaneLightComponent.h" namespace Metal { - std::string SceneImporterService::importData(const std::string &targetDir, const std::string &pathToFile, const std::shared_ptr &settings, const std::stop_token &stopToken) { - Assimp::Importer importer; unsigned int flags = aiProcess_GlobalScale | aiProcess_FindInstances | aiProcess_PreTransformVertices; @@ -39,7 +38,7 @@ namespace Metal { const aiScene *scene = importer.ReadFile(pathToFile, flags); if (stopToken.stop_requested()) { - throw std::runtime_error("Import cancelled"); + throw std::runtime_error("Import cancelled"); } if (!scene || !scene->HasMeshes()) { @@ -55,37 +54,36 @@ namespace Metal { std::string sceneBlobPath = CTX.getAssetDirectory() + FORMAT_FILE_SCENE(sceneMetadata.getId()); - - std::unordered_map meshMap{}; - std::unordered_map meshMaterialMap{}; + std::unordered_map meshMap{}; if (stopToken.stop_requested()) { throw std::runtime_error("Import cancelled"); } - CTX.meshImporterService.persistAllMeshes(targetDir, scene, meshMap, meshMaterialMap, stopToken); + CTX.meshImporterService.persistAllMeshes(targetDir, scene, meshMap, stopToken); if (stopToken.stop_requested()) { throw std::runtime_error("Import cancelled"); } - std::unordered_map materialsMap{}; fs::path absolutePath = fs::absolute(pathToFile); - fs::path directoryPath = absolutePath.parent_path(); + std::string directoryPath = absolutePath.parent_path().string(); - CTX.materialImporterService.collectMaterials(targetDir, scene, materialsMap, directoryPath.string(), - stopToken); + ProcessNode(sceneData, scene, scene->mRootNode, targetDir, directoryPath, meshMap, stopToken); + ProcessLights(sceneData, scene); if (stopToken.stop_requested()) { throw std::runtime_error("Import cancelled"); } - int increment = 0; - ProcessNode(increment, sceneData, scene->mRootNode, -1, meshMap, meshMaterialMap, materialsMap, stopToken); - - if (stopToken.stop_requested()) { - throw std::runtime_error("Import cancelled"); + std::vector entities{}; + for (SceneEntityData &entity: sceneData.entities) { + if (!entity.primitive && !entity.planeLight && !entity.sphereLight) { + continue; + } + entities.push_back(entity); } + sceneData.entities = entities; DUMP_TEMPLATE(sceneBlobPath, sceneData) sceneMetadata.size = fs::file_size(sceneBlobPath); DUMP_TEMPLATE(targetDir + '/' + FORMAT_FILE_METADATA(sceneMetadata.getId()), sceneMetadata) @@ -93,54 +91,70 @@ namespace Metal { return sceneMetadata.getId(); } - void SceneImporterService::ProcessNode(int &increment, SceneData &scene, const aiNode *node, int parentId, - const std::unordered_map &meshMap, - const std::unordered_map &meshMaterialMap, - const std::unordered_map &materialsMap, + void SceneImporterService::ProcessNode(SceneData &scene, const aiScene *aiScene, const aiNode *node, + const std::string &targetDir, const std::string &rootDirectory, + const std::unordered_map &meshMap, const std::stop_token &stopToken) { if (stopToken.stop_requested()) return; auto ¤tNode = scene.entities.emplace_back(); - currentNode.name = node->mName.data; - currentNode.id = increment; - increment++; - currentNode.parentEntity = parentId; + currentNode.entity.name = node->mName.data; - // IMPORTANT: `scene.entities` is a `std::vector`. Any further `emplace_back` may reallocate and - // invalidate references (including `currentNode`). Capture the needed values by copy. - const int currentNodeId = currentNode.id; - const std::string currentNodeName = currentNode.name; + // Extract transform + aiVector3D scaling, pos; + aiQuaternion rotation; + node->mTransformation.Decompose(scaling, rotation, pos); + currentNode.transform.translation = {pos.x, pos.y, pos.z}; + currentNode.transform.rotation = {rotation.w, rotation.x, rotation.y, rotation.z}; + currentNode.transform.scale = {scaling.x, scaling.y, scaling.z}; + ProcessMeshes(scene, aiScene, node, targetDir, rootDirectory, meshMap, stopToken); + + for (unsigned int i = 0; i < node->mNumChildren; ++i) { + ProcessNode(scene, aiScene, node->mChildren[i], targetDir, rootDirectory, meshMap, stopToken); + } + } + + void SceneImporterService::ProcessMeshes(SceneData &scene, const aiScene *aiScene, const aiNode *node, + const std::string &targetDir, const std::string &rootDirectory, + const std::unordered_map &meshMap, + const std::stop_token &stopToken) { for (unsigned int i = 0; i < node->mNumMeshes; ++i) { if (stopToken.stop_requested()) return; unsigned int meshIndex = node->mMeshes[i]; const auto it = meshMap.find(meshIndex); - if (it == meshMap.end()) { - // Mesh reference missing; skip linking to avoid terminating import. - continue; - } + if (it == meshMap.end()) continue; auto &childMeshNode = scene.entities.emplace_back(); - childMeshNode.meshId = it->second; - childMeshNode.name = currentNodeName + " (" + std::to_string(meshIndex) + ")"; - childMeshNode.parentEntity = currentNodeId; - childMeshNode.id = increment; - if (meshMaterialMap.contains(childMeshNode.meshId)) { - unsigned int matIndex = meshMaterialMap.at(childMeshNode.meshId); - if (materialsMap.contains(matIndex)) { - const auto &matData = materialsMap.at(matIndex); - childMeshNode.albedo = matData.albedo; - childMeshNode.roughness = matData.roughness; - childMeshNode.metallic = matData.metallic; - } - } - increment++; + childMeshNode.primitive = PrimitiveComponent(); + childMeshNode.primitive->meshId = it->second.id; + childMeshNode.transform.gizmoCenter = it->second.gizmoCenter; + + const aiMesh *assimpMesh = aiScene->mMeshes[meshIndex]; + childMeshNode.entity.name = assimpMesh->mName.length > 0 ? assimpMesh->mName.data : "Mesh"; + + const aiMaterial *material = aiScene->mMaterials[assimpMesh->mMaterialIndex]; + CTX.materialImporterService.importMaterial(targetDir, material, aiScene, rootDirectory, + *childMeshNode.primitive, stopToken); } + } - for (unsigned int i = 0; i < node->mNumChildren; ++i) { - if (stopToken.stop_requested()) return; - ProcessNode(increment, scene, node->mChildren[i], currentNodeId, meshMap, meshMaterialMap, materialsMap, - stopToken); + void SceneImporterService::ProcessLights(SceneData &scene, const aiScene *aiScene) { + for (unsigned int i = 0; i < aiScene->mNumLights; ++i) { + aiLight *light = aiScene->mLights[i]; + auto &lightNode = scene.entities.emplace_back(); + lightNode.entity.name = light->mName.data; + lightNode.transform.translation = {light->mPosition.x, light->mPosition.y, light->mPosition.z}; + + if (light->mType == aiLightSource_POINT) { + lightNode.sphereLight = SphereLightComponent(); + lightNode.sphereLight->color = {light->mColorDiffuse.r, light->mColorDiffuse.g, light->mColorDiffuse.b}; + lightNode.sphereLight->intensity = 1.0f; + } else if (light->mType == aiLightSource_DIRECTIONAL || light->mType == aiLightSource_AREA) { + lightNode.planeLight = PlaneLightComponent(); + lightNode.planeLight->color = {light->mColorDiffuse.r, light->mColorDiffuse.g, light->mColorDiffuse.b}; + lightNode.planeLight->intensity = 1.0f; + } } } diff --git a/src/service/mesh/SceneImporterService.h b/src/service/mesh/SceneImporterService.h index 457bce92..39b6d495 100644 --- a/src/service/mesh/SceneImporterService.h +++ b/src/service/mesh/SceneImporterService.h @@ -8,19 +8,28 @@ #include namespace Metal { + struct MeshId; struct MaterialData; struct MeshData; struct SceneData; class SceneImporterService final : public AbstractImporter { - static void ProcessNode(int &increment, SceneData &scene, const aiNode *node, int parentId, - const std::unordered_map &meshMap, - const std::unordered_map &meshMaterialMap, - const std::unordered_map &materialsMap, + static void ProcessNode(SceneData &scene, const aiScene *aiScene, const aiNode *node, + const std::string &targetDir, const std::string &rootDirectory, + const std::unordered_map &meshMap, const std::stop_token &stopToken); + static void ProcessMeshes(SceneData &scene, const aiScene *aiScene, const aiNode *node, + const std::string &targetDir, const std::string &rootDirectory, + const std::unordered_map &meshMap, + const std::stop_token &stopToken); + + static void ProcessLights(SceneData &scene, const aiScene *aiScene); + public: - std::string importData(const std::string &targetDir, const std::string &pathToFile, const std::shared_ptr &settings, const std::stop_token &stopToken) override; + std::string importData(const std::string &targetDir, const std::string &pathToFile, + const std::shared_ptr &settings, + const std::stop_token &stopToken) override; std::vector getSupportedTypes() override; }; diff --git a/src/service/picking/PickingService.cpp b/src/service/picking/PickingService.cpp index 225f5800..235ac849 100644 --- a/src/service/picking/PickingService.cpp +++ b/src/service/picking/PickingService.cpp @@ -5,7 +5,7 @@ #include "../../context/ApplicationContext.h" namespace Metal { - std::optional PickingService::pickEntityFromGBuffer(TextureInstance *attachment, const uint32_t pixelX, + std::optional PickingService::pickEntityFromGBuffer(TextureInstance *attachment, const uint32_t pixelX, const uint32_t pixelY) const { constexpr VkDeviceSize imageSize = 4 * sizeof(float); @@ -70,7 +70,7 @@ namespace Metal { for (auto entity: view) { auto &mesh = view.get(entity); if (mesh.renderIndex == renderIndex) { - return static_cast(entity); + return entity; } } diff --git a/src/service/picking/PickingService.h b/src/service/picking/PickingService.h index 66176460..d86177d0 100644 --- a/src/service/picking/PickingService.h +++ b/src/service/picking/PickingService.h @@ -9,7 +9,7 @@ namespace Metal { struct TextureInstance; class PickingService final : public AbstractRuntimeComponent { public: - [[nodiscard]] std::optional pickEntityFromGBuffer(TextureInstance *attachment, uint32_t pixelX, uint32_t pixelY) const; + [[nodiscard]] std::optional pickEntityFromGBuffer(TextureInstance *attachment, uint32_t pixelX, uint32_t pixelY) const; }; } // Metal diff --git a/src/service/raytracing/RayTracingService.cpp b/src/service/raytracing/RayTracingService.cpp index 065ba2f4..40ed64e7 100644 --- a/src/service/raytracing/RayTracingService.cpp +++ b/src/service/raytracing/RayTracingService.cpp @@ -41,22 +41,21 @@ namespace Metal { if (!needsRebuild) { return; } - + anyMeshes = false; // Check if any mesh is present and streamed - bool hasMeshes = false; auto view = CTX.worldRepository.registry.view(); for (auto entity: view) { - if (CTX.worldRepository.hiddenEntities.contains(static_cast(entity))) continue; + if (CTX.worldRepository.hiddenEntities.contains(entity)) continue; auto &meshComp = view.get(entity); if (meshComp.meshId.empty()) continue; - auto *instance = CTX.streamingService.streamMesh(meshComp.meshId); + auto *instance = CTX.meshService.stream(meshComp.meshId); if (instance != nullptr && instance->dataBuffer != nullptr && instance->indexBuffer != nullptr) { - hasMeshes = true; + anyMeshes = true; break; } } - if (!hasMeshes) { + if (!anyMeshes) { // No meshes – destroy all structures and set descriptor to null destroyAccelerationStructures(); // destroys BLAS and TLAS (waits for idle) updateDescriptorSets(VK_NULL_HANDLE); @@ -83,7 +82,7 @@ namespace Metal { } bool RayTracingService::isReady() const { - return accelerationStructureBuilt && tlas != VK_NULL_HANDLE; + return accelerationStructureBuilt && anyMeshes && tlas != VK_NULL_HANDLE; } void RayTracingService::updateMeshMaterials() { @@ -91,7 +90,7 @@ namespace Metal { auto view = CTX.worldRepository.registry.view(); for (auto entity: view) { - if (CTX.worldRepository.hiddenEntities.contains(static_cast(entity))) continue; + if (CTX.worldRepository.hiddenEntities.contains(entity)) continue; auto &meshComp = view.get(entity); if (meshComp.meshId.empty()) continue; @@ -146,11 +145,11 @@ namespace Metal { auto view = CTX.worldRepository.registry.view(); for (auto entity: view) { - if (CTX.worldRepository.hiddenEntities.contains(static_cast(entity))) continue; + if (CTX.worldRepository.hiddenEntities.contains(entity)) continue; auto &meshComp = view.get(entity); if (meshComp.meshId.empty()) continue; if (uniqueMeshes.contains(meshComp.meshId)) continue; - auto *instance = CTX.streamingService.streamMesh(meshComp.meshId); + auto *instance = CTX.meshService.stream(meshComp.meshId); if (instance == nullptr || instance->dataBuffer == nullptr || instance->indexBuffer == nullptr) { continue; } @@ -274,7 +273,7 @@ namespace Metal { LOG_ERROR("Max mesh instances reached for ray tracing: " + std::to_string(MAX_MESH_INSTANCES)); break; } - if (CTX.worldRepository.hiddenEntities.contains(static_cast(entity))) continue; + if (CTX.worldRepository.hiddenEntities.contains(entity)) continue; auto &meshComp = view.get(entity); if (meshComp.meshId.empty()) continue; diff --git a/src/service/raytracing/RayTracingService.h b/src/service/raytracing/RayTracingService.h index 13c0bfc2..bfa42ac6 100644 --- a/src/service/raytracing/RayTracingService.h +++ b/src/service/raytracing/RayTracingService.h @@ -21,6 +21,7 @@ namespace Metal { BufferInstance *vertexData = nullptr; BufferInstance *indexData = nullptr; }; + bool anyMeshes = false; // One BLAS per unique mesh ID std::unordered_map blasEntries; @@ -50,6 +51,7 @@ namespace Metal { void updateMeshMaterials(); public: + void setNeedsMaterialUpdate(bool val) { needsMaterialUpdate = val; } diff --git a/src/service/selection/SelectionService.cpp b/src/service/selection/SelectionService.cpp index 78c88251..23d4c8ff 100644 --- a/src/service/selection/SelectionService.cpp +++ b/src/service/selection/SelectionService.cpp @@ -4,13 +4,11 @@ #include "../../repository/world/components/TransformComponent.h" namespace Metal { - void SelectionService::addSelected(EntityID entity) const { + void SelectionService::addSelected(entt::entity entity) const { auto &editorRepository = CTX.editorRepository; if (editorRepository.selected.empty() || entity == EMPTY_ENTITY) { editorRepository.mainSelection = entity; - if (editorRepository.mainSelection == WorldRepository::ROOT_ID) { - editorRepository.mainSelection = EMPTY_ENTITY; - } else if (editorRepository.mainSelection != EMPTY_ENTITY) { + if (editorRepository.mainSelection != EMPTY_ENTITY) { updatePrimitiveSelected(); } } @@ -26,10 +24,10 @@ namespace Metal { editorRepository.primitiveSelected = nullptr; } - void SelectionService::addAllSelected(const std::vector &all) const { + void SelectionService::addAllSelected(const std::vector &all) const { auto &editorRepository = CTX.editorRepository; editorRepository.selected.clear(); - const EntityID first = all.size() > 0 ? all[0] : EMPTY_ENTITY; + const entt::entity first = all.size() > 0 ? all[0] : EMPTY_ENTITY; editorRepository.mainSelection = first; updatePrimitiveSelected(); for (auto a: all) { @@ -41,14 +39,13 @@ namespace Metal { auto &editorRepository = CTX.editorRepository; auto &repo = CTX.worldRepository; const auto entityId = editorRepository.mainSelection; - const auto entity = static_cast(entityId); - if (entityId == EMPTY_ENTITY || !repo.registry.valid(entity)) { + if (entityId == EMPTY_ENTITY || !repo.registry.valid(entityId)) { return; } - if (repo.registry.all_of(entity)) { - editorRepository.primitiveSelected = &repo.registry.get(entity); + if (repo.registry.all_of(entityId)) { + editorRepository.primitiveSelected = &repo.registry.get(entityId); } } diff --git a/src/service/selection/SelectionService.h b/src/service/selection/SelectionService.h index 2382345e..60cb3dd8 100644 --- a/src/service/selection/SelectionService.h +++ b/src/service/selection/SelectionService.h @@ -11,11 +11,11 @@ namespace Metal { class SelectionService final : public AbstractRuntimeComponent { public: - void addSelected(EntityID entity) const; + void addSelected(entt::entity entity) const; void clearSelection() const; - void addAllSelected(const std::vector &all) const; + void addAllSelected(const std::vector &all) const; void updatePrimitiveSelected() const; }; diff --git a/src/service/texture/TextureService.cpp b/src/service/texture/TextureService.cpp index 414c9f33..577d769b 100644 --- a/src/service/texture/TextureService.cpp +++ b/src/service/texture/TextureService.cpp @@ -124,7 +124,7 @@ namespace Metal { createImageWithInfo(imageInfo, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, image); } - TextureData *TextureService::stream(const std::string &id) const { + TextureData *TextureService::loadTextureData(const std::string &id) const { auto pathToFile = CTX.getAssetDirectory() + FORMAT_FILE_TEXTURE(id); if (std::filesystem::exists(pathToFile)) { int width, height, channels; @@ -137,6 +137,17 @@ namespace Metal { return nullptr; } + TextureInstance *TextureService::stream(const std::string &id) { + if (id.empty()) { + return nullptr; + } + auto *resource = getResource(id); + if (resource != nullptr) { + return resource; + } + return create(id); + } + TextureInstance *TextureService::loadTexture(const std::string &id, const std::string &pathToImage, bool generateMipMaps, VkFormat imageFormat) { diff --git a/src/service/texture/TextureService.h b/src/service/texture/TextureService.h index df076111..b949bb19 100644 --- a/src/service/texture/TextureService.h +++ b/src/service/texture/TextureService.h @@ -5,13 +5,13 @@ #include #include "TextureData.h" -#include "../abstract/IStreamable.h" +#include "../abstract/AbstractResourceService.h" #include "TextureInstance.h" namespace Metal { struct TextureInstance; - class TextureService final : public IStreamable { + class TextureService final : public AbstractResourceService { unsigned int nextTextureIndex = 1; std::unordered_map textureIndices{}; @@ -32,13 +32,15 @@ namespace Metal { void generateMipmaps(const TextureInstance *image) const; public: - [[nodiscard]] TextureData *stream(const std::string &id) const; + [[nodiscard]] TextureData *loadTextureData(const std::string &id) const; + + TextureInstance *stream(const std::string &id); TextureInstance *loadTexture(const std::string &id, const std::string &pathToImage, bool generateMipMaps = false, VkFormat imageFormat = VK_FORMAT_R8G8B8A8_SRGB); - TextureInstance *create(const std::string &id) override; + TextureInstance *create(const std::string &id); TextureInstance *createForCompute(const std::string &id, unsigned int width, unsigned int height, VkFormat format = VK_FORMAT_R16G16B16A16_SFLOAT); diff --git a/src/service/transform/TransformService.cpp b/src/service/transform/TransformService.cpp index 06e02fc1..e977dc2f 100644 --- a/src/service/transform/TransformService.cpp +++ b/src/service/transform/TransformService.cpp @@ -8,26 +8,11 @@ namespace Metal { void TransformService::onSync() { - traverse(WorldRepository::ROOT_ID, false); - } - - void TransformService::traverse(const EntityID entityId, bool parentHasChanged) { - const auto entity = static_cast(entityId); - TransformComponent *st = CTX.worldRepository.registry.all_of(entity) - ? &CTX.worldRepository.registry.get(entity) - : nullptr; - if (st != nullptr && (st->isNotFrozen() || parentHasChanged)) { - TransformComponent *parentTransform = findParent(st->getEntityId()); - transform(st, parentTransform); - st->freezeVersion(); - parentHasChanged = true; - } - - const auto e = static_cast(entityId); - if (CTX.worldRepository.registry.all_of(e)) { - const auto &hierarchy = CTX.worldRepository.registry.get(e); - for (auto child: hierarchy.children) { - traverse(child, parentHasChanged); + for (auto entity : CTX.worldRepository.registry.view()) { + TransformComponent &st = CTX.worldRepository.registry.get(entity); + if (st.isNotFrozen()) { + transform(&st, nullptr); + st.freezeVersion(); } } } @@ -39,7 +24,7 @@ namespace Metal { auxMat4 = glm::identity(); } if (!st->forceTransform && st->isStatic) { - LOG_WARN("Entity will not be transformed because it is set to static " + std::to_string(st->getEntityId())); + LOG_WARN("Entity will not be transformed because it is set to static " + std::to_string(entt::to_integral(st->getEntityId()))); return; } @@ -51,30 +36,8 @@ namespace Metal { st->model = auxMat4 * auxMat42; st->freezeVersion(); - if (CTX.worldRepository.registry.all_of(static_cast::entity_type>(st->getEntityId()))) { + if (CTX.worldRepository.registry.all_of(st->getEntityId())) { CTX.rayTracingService.markDirty(); } } - - TransformComponent *TransformService::findParent(EntityID id) const { - while (id != EMPTY_ENTITY && id != WorldRepository::ROOT_ID) { - const auto e = static_cast(id); - if (!CTX.worldRepository.registry.valid(e)) break; - const auto &hierarchy = CTX.worldRepository.registry.get(e); - id = hierarchy.parent; - const auto parent = static_cast(id); - TransformComponent *t = (CTX.worldRepository.registry.valid(parent) && CTX.worldRepository.registry.all_of(parent)) - ? &CTX.worldRepository.registry.get(parent) - : nullptr; - if (t != nullptr) { - return t; - } - } - return nullptr; - } - - float TransformService::getDistanceFromCamera(glm::vec3 &translation) { - distanceAux = CTX.worldRepository.camera.position; - return glm::length(distanceAux - translation); - } } // Metal diff --git a/src/service/transform/TransformService.h b/src/service/transform/TransformService.h index c77260c3..37ea9b5a 100644 --- a/src/service/transform/TransformService.h +++ b/src/service/transform/TransformService.h @@ -17,19 +17,10 @@ namespace Metal { glm::mat4x4 auxMat42{}; public: - explicit TransformService() - : AbstractRuntimeComponent() { - } void onSync() override; - void traverse(EntityID entityId, bool parentHasChanged); - void transform(TransformComponent *st, const TransformComponent *parentTransform); - - [[nodiscard]] TransformComponent *findParent(EntityID id) const; - - float getDistanceFromCamera(glm::vec3 &translation); }; } // Metal diff --git a/src/service/voxel/VoxelService.h b/src/service/voxel/VoxelService.h index 64880d14..cd5450dc 100644 --- a/src/service/voxel/VoxelService.h +++ b/src/service/voxel/VoxelService.h @@ -1,15 +1,17 @@ #ifndef METAL_ENGINE_VOXELSERVICE_H #define METAL_ENGINE_VOXELSERVICE_H -#include "../abstract/IStreamable.h" +#include "../abstract/AbstractResourceService.h" #include "SVOInstance.h" namespace Metal { struct SVOInstance; - class VoxelService final : public IStreamable { + class VoxelService final : public AbstractResourceService { public: - SVOInstance *create(const std::string &id) override; + SVOInstance *create(const std::string &id); + + SVOInstance *stream(const std::string &id); void disposeResource(SVOInstance *resource) override; }; diff --git a/src/util/UIUtil.h b/src/util/UIUtil.h index 31f39f16..48312985 100644 --- a/src/util/UIUtil.h +++ b/src/util/UIUtil.h @@ -77,6 +77,89 @@ namespace Metal::UIUtil { ImGui::SameLine(); } + static bool DragFloatWithLabel(const std::string &id, float *value, const std::string &label, const ImVec4 &color, + float speed = 0.1f) { + bool changed = false; + ImGui::PushID(id.c_str()); + + const float framePadding = ImGui::GetStyle().FramePadding.x; + const float labelWidth = ImGui::CalcTextSize(label.c_str()).x + framePadding * 2.0f; + + ImGui::PushStyleColor(ImGuiCol_Button, color); + ImGui::PushStyleColor(ImGuiCol_ButtonHovered, color); + ImGui::PushStyleColor(ImGuiCol_ButtonActive, color); + ImGui::Button(label.c_str(), ImVec2(labelWidth, 0)); + ImGui::PopStyleColor(3); + + ImGui::SameLine(0, 0); + ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); + changed = ImGui::DragFloat("##v", value, speed); + + ImGui::PopID(); + return changed; + } + + static bool DrawVec2Control(const std::string &name, const std::string &id, float *values, float speed = 0.1f) { + bool changed = false; + ImGui::Text(name.c_str()); + ImGui::PushID(id.c_str()); + + if (ImGui::BeginTable("##table", 2, ImGuiTableFlags_NoSavedSettings)) { + ImGui::TableNextColumn(); + if (DragFloatWithLabel("x", &values[0], "X", ImVec4{0.8f, 0.1f, 0.15f, 1.0f}, speed)) changed = true; + ImGui::TableNextColumn(); + if (DragFloatWithLabel("y", &values[1], "Y", ImVec4{0.2f, 0.7f, 0.2f, 1.0f}, speed)) changed = true; + ImGui::EndTable(); + } + + ImGui::PopID(); + return changed; + } + + static bool DrawVec3Control(const std::string &name, const std::string &id, float *values, float speed = 0.1f) { + bool changed = false; + ImGui::Text(name.c_str()); + ImGui::PushID(id.c_str()); + + if (ImGui::BeginTable("##table", 3, ImGuiTableFlags_NoSavedSettings)) { + ImGui::TableNextColumn(); + if (DragFloatWithLabel("x", &values[0], "X", ImVec4{0.8f, 0.1f, 0.15f, 1.0f}, speed)) changed = true; + ImGui::TableNextColumn(); + if (DragFloatWithLabel("y", &values[1], "Y", ImVec4{0.2f, 0.7f, 0.2f, 1.0f}, speed)) changed = true; + ImGui::TableNextColumn(); + if (DragFloatWithLabel("z", &values[2], "Z", ImVec4{0.1f, 0.25f, 0.8f, 1.0f}, speed)) changed = true; + ImGui::EndTable(); + } + + ImGui::PopID(); + return changed; + } + + static bool DrawVec4Control(const std::string &name, const std::string &id, float *values, float speed = 0.1f) { + bool changed = false; + ImGui::Text(name.c_str()); + ImGui::PushID(id.c_str()); + + if (ImGui::BeginTable("##table", 4, ImGuiTableFlags_NoSavedSettings)) { + ImGui::TableNextColumn(); + if (DragFloatWithLabel("x", &values[0], "X", ImVec4{0.8f, 0.1f, 0.15f, 1.0f}, speed)) changed = true; + ImGui::TableNextColumn(); + if (DragFloatWithLabel("y", &values[1], "Y", ImVec4{0.2f, 0.7f, 0.2f, 1.0f}, speed)) changed = true; + ImGui::TableNextColumn(); + if (DragFloatWithLabel("z", &values[2], "Z", ImVec4{0.1f, 0.25f, 0.8f, 1.0f}, speed)) changed = true; + ImGui::TableNextColumn(); + if (DragFloatWithLabel("w", &values[3], "W", ImVec4{0.5f, 0.5f, 0.5f, 1.0f}, speed)) changed = true; + ImGui::EndTable(); + } + + ImGui::PopID(); + return changed; + } + + static bool DrawQuatControl(const std::string &name, const std::string &id, float *values, float speed = 0.1f) { + return DrawVec4Control(name, id, values, speed); + } + static std::string GetKeyChordName(ImGuiKeyChord keyChord) { std::string result; if (keyChord & ImGuiMod_Ctrl) result += "Ctrl+"; From 8538a5342a82ea9d7db9e81771ae43baf02243b8 Mon Sep 17 00:00:00 2001 From: facobackup Date: Sun, 8 Mar 2026 21:12:29 -0300 Subject: [PATCH 06/18] Improved scoped resource ID handling, streamlined Vulkan texture sampler creation, enhanced light registration logic, and updated transparency implementation. Removed unused AO shading mode and simplified material factors extraction. --- resources/shaders/GlobalDataBuffer.glsl | 1 - resources/shaders/rt/HWRayTracing.rchit | 5 ++- resources/shaders/rt/HWRayTracing.rgen | 12 ++++++- resources/shaders/tools/SelectedDot.frag | 5 +-- resources/shaders/util/HWRayTracingUtil.glsl | 1 + .../dock-spaces/docks/DockSpacePanel.cpp | 2 +- src/context/engine/EngineContext.cpp | 16 +++------- .../engine/frame-builder/EngineFrame.cpp | 7 +++- .../engine/frame-builder/EngineFrame.h | 11 +++++-- src/context/engine/passes/AbstractPass.cpp | 5 +-- src/context/vulkan/VulkanContext.cpp | 7 ++-- src/context/vulkan/VulkanContext.h | 1 + src/dto/buffers/GlobalDataUBO.h | 1 - src/enum/ShadingMode.h | 2 -- .../framebuffer/FrameBufferService.cpp | 19 ----------- src/service/framebuffer/FrameBufferService.h | 2 -- src/service/lights/LightService.cpp | 32 ++++++++----------- .../material/MaterialImporterService.cpp | 32 +++++++++---------- src/service/texture/TextureService.cpp | 23 ++++++++++++- src/service/texture/TextureService.h | 2 ++ 20 files changed, 97 insertions(+), 89 deletions(-) diff --git a/resources/shaders/GlobalDataBuffer.glsl b/resources/shaders/GlobalDataBuffer.glsl index 4cf207c2..eb602dff 100644 --- a/resources/shaders/GlobalDataBuffer.glsl +++ b/resources/shaders/GlobalDataBuffer.glsl @@ -8,7 +8,6 @@ layout (set = 0, binding = 0) uniform GlobalDataBlock { mat4 invProj; mat4 previousProjView; vec3 cameraWorldPosition; - vec2 outputRes; uint lightsCount; uint debugFlag; diff --git a/resources/shaders/rt/HWRayTracing.rchit b/resources/shaders/rt/HWRayTracing.rchit index 9e5fd219..4a4be645 100644 --- a/resources/shaders/rt/HWRayTracing.rchit +++ b/resources/shaders/rt/HWRayTracing.rchit @@ -70,8 +70,11 @@ void main() { float ior = 1.45; bool isEmissive = false; + payload.alpha = 1.0; if (metadata.albedoTexture != 0u) { - baseColor = texture(textureArray[nonuniformEXT(metadata.albedoTexture)], uv).rgb; + vec4 alb = texture(textureArray[nonuniformEXT(metadata.albedoTexture)], uv); + payload.alpha = alb.a; + baseColor = alb.rgb; } else { baseColor = metadata.albedo; } diff --git a/resources/shaders/rt/HWRayTracing.rgen b/resources/shaders/rt/HWRayTracing.rgen index fa4acdff..31037684 100644 --- a/resources/shaders/rt/HWRayTracing.rgen +++ b/resources/shaders/rt/HWRayTracing.rgen @@ -93,9 +93,19 @@ void main() { payload.hit = false; payload.renderIndex = 0; + payload.alpha = 1.0; if (pushConstants.shouldTrace == 1) { - traceRayEXT(topLevelAS, gl_RayFlagsOpaqueEXT, 0xFF, 0, 0, 0, rayOrigin, 0.001, rayDirection, 10000.0, 0); + float tMin = 0.001; + vec3 origin = rayOrigin; + for (int i = 0; i < 8; i++) { + traceRayEXT(topLevelAS, gl_RayFlagsOpaqueEXT, 0xFF, 0, 0, 0, origin, tMin, rayDirection, 10000.0, 0); + if (!payload.hit || payload.alpha > 0.0) { + break; + } + origin = payload.hitPosition; + tMin = 0.001; + } } if (!payload.hit) { diff --git a/resources/shaders/tools/SelectedDot.frag b/resources/shaders/tools/SelectedDot.frag index 22a5ce79..0eea4f3f 100644 --- a/resources/shaders/tools/SelectedDot.frag +++ b/resources/shaders/tools/SelectedDot.frag @@ -19,6 +19,7 @@ void main() { bool isBoundary = false; ivec2 pixel = ivec2(gl_FragCoord.xy); + ivec2 texSize = textureSize(selectionIdSampler, 0); for (int y = -thickness; y <= thickness; ++y) { for (int x = -thickness; x <= thickness; ++x) { @@ -28,8 +29,8 @@ void main() { ivec2 neighborPixel = pixel + ivec2(x, y); - if (neighborPixel.x < 0 || neighborPixel.x >= int(globalData.outputRes.x) || - neighborPixel.y < 0 || neighborPixel.y >= int(globalData.outputRes.y)) { + if (neighborPixel.x < 0 || neighborPixel.x >= int(texSize.x) || + neighborPixel.y < 0 || neighborPixel.y >= int(texSize.y)) { isBoundary = true; break; } diff --git a/resources/shaders/util/HWRayTracingUtil.glsl b/resources/shaders/util/HWRayTracingUtil.glsl index c446a09f..05226bb4 100644 --- a/resources/shaders/util/HWRayTracingUtil.glsl +++ b/resources/shaders/util/HWRayTracingUtil.glsl @@ -33,6 +33,7 @@ struct RayPayload { vec3 hitNormal; vec2 uv; uint renderIndex; + float alpha; bool hit; float t; }; diff --git a/src/context/editor/dock-spaces/docks/DockSpacePanel.cpp b/src/context/editor/dock-spaces/docks/DockSpacePanel.cpp index ba1b2ca4..e07fe1ac 100644 --- a/src/context/editor/dock-spaces/docks/DockSpacePanel.cpp +++ b/src/context/editor/dock-spaces/docks/DockSpacePanel.cpp @@ -50,7 +50,7 @@ namespace Metal { void DockSpacePanel::handleShortcut() const { if (view != nullptr) { - const bool isHovered = ImGui::IsWindowFocused(ImGuiHoveredFlags_RootAndChildWindows); + const bool isHovered = ImGui::IsWindowHovered(ImGuiHoveredFlags_RootAndChildWindows); if (isHovered) { CTX.editorRepository.focusedShortcuts = view->getShortcuts(); CTX.editorRepository.focusedWindowName = view->dock->name; diff --git a/src/context/engine/EngineContext.cpp b/src/context/engine/EngineContext.cpp index abd2f473..8a10b208 100644 --- a/src/context/engine/EngineContext.cpp +++ b/src/context/engine/EngineContext.cpp @@ -45,19 +45,15 @@ namespace Metal { CTX.transformService.onSync(); CTX.streamingService.onSync(); - CTX.cameraService.onSync(); CTX.rayTracingService.onSync(); + CTX.cameraService.onSync(); + if (updateLights || isFirstFrame) { + CTX.lightService.onSync(); + } for (auto *frame: registeredFrames) { if (frame->getShouldRender()) { currentFrame = frame; - - if (updateLights || isFirstFrame) { - CTX.lightService.onSync(); - } - - isFirstFrame = false; - updateGlobalData(); currentFrame->onSync(); @@ -65,7 +61,7 @@ namespace Metal { } } - + isFirstFrame = false; setUpdateLights(false); setCameraUpdated(false); setGISettingsUpdated(false); @@ -73,7 +69,6 @@ namespace Metal { void EngineContext::updateGlobalData() { auto &camera = CTX.worldRepository.camera; - auto *fbo = currentFrame->getResourceAs(RID_POST_PROCESSING_FBO); globalDataUBO.previousProjView = globalDataUBO.projView; globalDataUBO.viewMatrix = camera.viewMatrix; globalDataUBO.projectionMatrix = camera.projectionMatrix; @@ -86,7 +81,6 @@ namespace Metal { CTX.engineRepository.pathTracerAccumulationCount++; globalDataUBO.pathTracerAccumulationCount = CTX.engineRepository.pathTracerAccumulationCount; globalDataUBO.globalFrameCount++; - globalDataUBO.outputRes = {fbo->bufferWidth, fbo->bufferHeight}; globalDataUBO.pathTracerMaxSamples = CTX.engineRepository.pathTracerMaxSamples; globalDataUBO.denoiserEnabled = CTX.engineRepository.denoiserEnabled && ( globalDataUBO.debugFlag == LIT || globalDataUBO.debugFlag == LIGHTING_ONLY) diff --git a/src/context/engine/frame-builder/EngineFrame.cpp b/src/context/engine/frame-builder/EngineFrame.cpp index 1953f907..6f714a1b 100644 --- a/src/context/engine/frame-builder/EngineFrame.cpp +++ b/src/context/engine/frame-builder/EngineFrame.cpp @@ -3,7 +3,8 @@ #include "../passes/AbstractPass.h" namespace Metal { - EngineFrame::EngineFrame(std::string id) : id(std::move(id)) {} + EngineFrame::EngineFrame(std::string id) : id(std::move(id)) { + } void EngineFrame::addResource(RuntimeResource *resource) { if (resource) { @@ -33,4 +34,8 @@ namespace Metal { } passes.clear(); } + + std::string EngineFrame::getScopedResourceId(const std::string &resourceId) const { + return id + "_" + resourceId; + } } diff --git a/src/context/engine/frame-builder/EngineFrame.h b/src/context/engine/frame-builder/EngineFrame.h index 4cf326e7..b86e3edc 100644 --- a/src/context/engine/frame-builder/EngineFrame.h +++ b/src/context/engine/frame-builder/EngineFrame.h @@ -11,6 +11,7 @@ namespace Metal { class CommandBufferRecorder; class AbstractPass; + class EngineFrame { std::string id; bool shouldRender = false; @@ -30,7 +31,7 @@ namespace Metal { template T *getResourceAs(const std::string &resourceId) { - auto it = resources.find(id + "_" +resourceId); + auto it = resources.find(getScopedResourceId(resourceId)); if (it != resources.end()) { return dynamic_cast(it->second); } @@ -39,7 +40,8 @@ namespace Metal { void addPass(CommandBufferRecorder *recorder, const std::vector &p); - [[nodiscard]] const std::vector > > &getPasses() const { + [[nodiscard]] const std::vector > > & + getPasses() const { return passes; } @@ -47,7 +49,10 @@ namespace Metal { void dispose(); - void destroy() {} + void destroy() { + } + + [[nodiscard]] std::string getScopedResourceId(const std::string &resourceId) const; }; } diff --git a/src/context/engine/passes/AbstractPass.cpp b/src/context/engine/passes/AbstractPass.cpp index 14d18725..31c60932 100644 --- a/src/context/engine/passes/AbstractPass.cpp +++ b/src/context/engine/passes/AbstractPass.cpp @@ -79,9 +79,6 @@ namespace Metal { } std::string AbstractPass::getScopedResourceId(const std::string &id) const { - if (frame != nullptr) { - return frame->getId() + "_" + id; - } - return id; + return frame->getScopedResourceId(id); } } diff --git a/src/context/vulkan/VulkanContext.cpp b/src/context/vulkan/VulkanContext.cpp index e5cb97b8..c2ef2593 100644 --- a/src/context/vulkan/VulkanContext.cpp +++ b/src/context/vulkan/VulkanContext.cpp @@ -281,11 +281,9 @@ namespace Metal { createMemoryAllocator(); createCommandPool(); createDescriptorPool(); - CTX.framebufferService.createSampler(false, vkImageSampler); + CTX.textureService.createSampler(false, vkImageSampler, VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER); + CTX.textureService.createSampler(true, vkTextureSampler, VK_SAMPLER_ADDRESS_MODE_REPEAT); // ------- CORE INITIALIZATION - - // ------- REPOSITORY INITIALIZATION - // ------- REPOSITORY INITIALIZATION } void VulkanContext::dispose() const { @@ -296,6 +294,7 @@ namespace Metal { CTX.rayTracingService.destroyAccelerationStructures(); vkDestroySampler(device.device, vkImageSampler, nullptr); + vkDestroySampler(device.device, vkTextureSampler, nullptr); vkDestroyDescriptorPool(CTX.vulkanContext.device.device, descriptorPool, nullptr); diff --git a/src/context/vulkan/VulkanContext.h b/src/context/vulkan/VulkanContext.h index 5084fcfd..2f74c8e4 100644 --- a/src/context/vulkan/VulkanContext.h +++ b/src/context/vulkan/VulkanContext.h @@ -69,6 +69,7 @@ namespace Metal { VkCommandPool commandPool = VK_NULL_HANDLE; VkPhysicalDeviceRayTracingPipelinePropertiesKHR rayTracingPipelineProperties{}; VkSampler vkImageSampler = VK_NULL_HANDLE; + VkSampler vkTextureSampler = VK_NULL_HANDLE; PFN_vkGetBufferDeviceAddressKHR vkGetBufferDeviceAddressKHR = nullptr; PFN_vkCreateAccelerationStructureKHR vkCreateAccelerationStructureKHR = nullptr; diff --git a/src/dto/buffers/GlobalDataUBO.h b/src/dto/buffers/GlobalDataUBO.h index d79af7b3..488bc859 100644 --- a/src/dto/buffers/GlobalDataUBO.h +++ b/src/dto/buffers/GlobalDataUBO.h @@ -12,7 +12,6 @@ namespace Metal { alignas(16) glm::mat4x4 previousProjView{}; alignas(16) glm::vec3 cameraWorldPosition{}; - alignas(8) glm::vec2 outputRes{}; alignas(4) unsigned int lightsCount{}; alignas(4) unsigned int debugFlag; diff --git a/src/enum/ShadingMode.h b/src/enum/ShadingMode.h index 236bb631..4a296079 100644 --- a/src/enum/ShadingMode.h +++ b/src/enum/ShadingMode.h @@ -13,7 +13,6 @@ namespace Metal { NORMAL, ROUGHNESS, METALLIC, - AO, RANDOM, DEPTH, UV, @@ -37,7 +36,6 @@ namespace Metal { {"NORMAL", "Normal", Icons::gradient, NORMAL}, {"ROUGHNESS", "Roughness", Icons::texture, ROUGHNESS}, {"METALLIC", "Metallic", Icons::blur_on, METALLIC}, - {"AO", "Occlusion", Icons::contrast, AO}, {"RANDOM", "Random", Icons::casino, RANDOM}, {"DEPTH", "Depth", Icons::layers, DEPTH}, {"UV", "UV", Icons::grid_on, UV}, diff --git a/src/service/framebuffer/FrameBufferService.cpp b/src/service/framebuffer/FrameBufferService.cpp index 73c8e478..3cb4a0ff 100644 --- a/src/service/framebuffer/FrameBufferService.cpp +++ b/src/service/framebuffer/FrameBufferService.cpp @@ -10,25 +10,6 @@ #include "../../context/ApplicationContext.h" namespace Metal { - void FrameBufferService::createSampler(bool linear, VkSampler &vkImageSampler) { - VkSamplerCreateInfo samplerCreateInfo{}; - samplerCreateInfo.magFilter = linear ? VK_FILTER_LINEAR : VK_FILTER_NEAREST; - samplerCreateInfo.minFilter = linear ? VK_FILTER_LINEAR : VK_FILTER_NEAREST; - samplerCreateInfo.mipmapMode = linear ? VK_SAMPLER_MIPMAP_MODE_LINEAR : VK_SAMPLER_MIPMAP_MODE_NEAREST; - samplerCreateInfo.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER; - samplerCreateInfo.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER; - samplerCreateInfo.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER; - samplerCreateInfo.mipLodBias = 0.0f; - samplerCreateInfo.compareOp = VK_COMPARE_OP_NEVER; - samplerCreateInfo.minLod = 0.0f; - samplerCreateInfo.maxLod = 1; - // TODO - ENABLE/DISABLE ANISOTROPY - samplerCreateInfo.maxAnisotropy = 8; - samplerCreateInfo.anisotropyEnable = VK_TRUE; - samplerCreateInfo.borderColor = VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK; - VulkanUtils::CheckVKResult(vkCreateSampler(CTX.vulkanContext.device.device, &samplerCreateInfo, nullptr, - &vkImageSampler)); - } FrameBufferInstance *FrameBufferService::createFrameBuffer(const std::string &id, const unsigned w, const unsigned h, glm::vec4 clearColor) { diff --git a/src/service/framebuffer/FrameBufferService.h b/src/service/framebuffer/FrameBufferService.h index ffd6ecaf..15fab167 100644 --- a/src/service/framebuffer/FrameBufferService.h +++ b/src/service/framebuffer/FrameBufferService.h @@ -20,8 +20,6 @@ namespace Metal { void createVKFrameBuffer(FrameBufferInstance *framebuffer) const; public: - void createSampler(bool linear, VkSampler &vkImageSampler); - FrameBufferInstance *createFrameBuffer(const std::string &id, unsigned int w, unsigned int h, glm::vec4 clearColor = glm::vec4(0.0f)); diff --git a/src/service/lights/LightService.cpp b/src/service/lights/LightService.cpp index 1cf11126..53c0e2bc 100644 --- a/src/service/lights/LightService.cpp +++ b/src/service/lights/LightService.cpp @@ -13,19 +13,13 @@ namespace Metal { void LightService::registerLights() { auto sphereView = CTX.worldRepository.registry.view(); for (auto [entityId, l, t]: sphereView.each()) { - if (CTX.worldRepository.hiddenEntities.contains(entityId)) { continue; } - auto &translation = t.translation; - - glm::vec3 normal(0.0f, 1.0f, 0.0f); - glm::vec3 rotatedNormal = t.rotation * normal; - items.push_back(LightData( glm::vec4(l.color, l.intensity), - translation, - glm::normalize(rotatedNormal), + t.translation, + glm::vec3(0), glm::vec3(l.radiusSize), LightTypes::LightType::SPHERE )); @@ -33,18 +27,15 @@ namespace Metal { auto planeView = CTX.worldRepository.registry.view(); for (auto [entityId, l, t]: planeView.each()) { - if (CTX.worldRepository.hiddenEntities.contains(entityId)) { continue; } - auto &translation = t.translation; - glm::vec3 normal(0.0f, 1.0f, 0.0f); glm::vec3 rotatedNormal = t.rotation * normal; items.push_back(LightData( glm::vec4(l.color, l.intensity), - translation, + t.translation, glm::normalize(rotatedNormal), glm::vec3(t.scale), LightTypes::LightType::PLANE @@ -58,11 +49,11 @@ namespace Metal { auto &atmo = CTX.worldRepository.registry.get(*it); if (atmo.atmosphereEnabled) { items.push_back(LightData( - glm::vec4(atmo.sunColor, atmo.sunLightIntensity), - atmo.sunPosition, - glm::vec3(0), - glm::vec3(atmo.sunRadius), - LightTypes::LightType::SPHERE + glm::vec4(atmo.sunColor, atmo.sunLightIntensity), + atmo.sunPosition, + glm::vec3(0), + glm::vec3(atmo.sunRadius), + LightTypes::LightType::SPHERE )); } } @@ -73,9 +64,12 @@ namespace Metal { registerSun(); registerLights(); + if (items.empty()) { + return; + } - if (!items.empty()) { - CTX.engineContext.currentFrame->getResourceAs(RID_LIGHT_BUFFER)->update(items.data()); + for (auto *frame: CTX.engineContext.registeredFrames) { + frame->getResourceAs(RID_LIGHT_BUFFER)->update(items.data()); } } } // Metal diff --git a/src/service/material/MaterialImporterService.cpp b/src/service/material/MaterialImporterService.cpp index cc8def39..35d659ff 100644 --- a/src/service/material/MaterialImporterService.cpp +++ b/src/service/material/MaterialImporterService.cpp @@ -71,21 +71,21 @@ namespace Metal { primitive.isEmissive = (color.r > 0 || color.g > 0 || color.b > 0); } - float factor; - if (material->Get(AI_MATKEY_METALLIC_FACTOR, factor) == AI_SUCCESS) { - primitive.metallicFactor = factor; - } - - if (material->Get(AI_MATKEY_ROUGHNESS_FACTOR, factor) == AI_SUCCESS) { - primitive.roughnessFactor = factor; - } - - if (material->Get(AI_MATKEY_TRANSMISSION_FACTOR, factor) == AI_SUCCESS) { - primitive.transmissionFactor = factor; - } - - if (material->Get(AI_MATKEY_REFRACTI, factor) == AI_SUCCESS) { - primitive.ior = factor; - } + // float factor; + // if (material->Get(AI_MATKEY_METALLIC_FACTOR, factor) == AI_SUCCESS) { + // primitive.metallicFactor = factor; + // } + // + // if (material->Get(AI_MATKEY_ROUGHNESS_FACTOR, factor) == AI_SUCCESS) { + // primitive.roughnessFactor = factor; + // } + // + // if (material->Get(AI_MATKEY_TRANSMISSION_FACTOR, factor) == AI_SUCCESS) { + // primitive.transmissionFactor = factor; + // } + // + // if (material->Get(AI_MATKEY_REFRACTI, factor) == AI_SUCCESS) { + // primitive.ior = factor; + // } } } diff --git a/src/service/texture/TextureService.cpp b/src/service/texture/TextureService.cpp index 577d769b..d5eacf08 100644 --- a/src/service/texture/TextureService.cpp +++ b/src/service/texture/TextureService.cpp @@ -376,7 +376,7 @@ namespace Metal { write.descriptorCount = 1; VkDescriptorImageInfo imageInfo{}; - imageInfo.sampler = CTX.vulkanContext.vkImageSampler; + imageInfo.sampler = CTX.vulkanContext.vkTextureSampler; imageInfo.imageView = texture->vkImageView; imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; write.pImageInfo = &imageInfo; @@ -401,4 +401,25 @@ namespace Metal { CTX.descriptorSetService.disposeResource(resource->imageDescriptor); } } + + void TextureService::createSampler(bool linear, VkSampler &vkImageSampler, VkSamplerAddressMode addressMode) { + VkSamplerCreateInfo samplerCreateInfo{}; + samplerCreateInfo.magFilter = linear ? VK_FILTER_LINEAR : VK_FILTER_NEAREST; + samplerCreateInfo.minFilter = linear ? VK_FILTER_LINEAR : VK_FILTER_NEAREST; + samplerCreateInfo.mipmapMode = linear ? VK_SAMPLER_MIPMAP_MODE_LINEAR : VK_SAMPLER_MIPMAP_MODE_NEAREST; + samplerCreateInfo.addressModeU = addressMode; + samplerCreateInfo.addressModeV = addressMode; + samplerCreateInfo.addressModeW = addressMode; + samplerCreateInfo.mipLodBias = 0.0f; + samplerCreateInfo.compareOp = VK_COMPARE_OP_NEVER; + samplerCreateInfo.minLod = 0.0f; + samplerCreateInfo.maxLod = 1; + // TODO - ENABLE/DISABLE ANISOTROPY + samplerCreateInfo.maxAnisotropy = 8; + samplerCreateInfo.anisotropyEnable = VK_TRUE; + samplerCreateInfo.borderColor = VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK; + VulkanUtils::CheckVKResult(vkCreateSampler(CTX.vulkanContext.device.device, &samplerCreateInfo, nullptr, + &vkImageSampler)); + } + } // Metal diff --git a/src/service/texture/TextureService.h b/src/service/texture/TextureService.h index b949bb19..40d00e1f 100644 --- a/src/service/texture/TextureService.h +++ b/src/service/texture/TextureService.h @@ -47,6 +47,8 @@ namespace Metal { unsigned int getTextureIndex(const std::string &id); void disposeResource(TextureInstance *resource) override; + + void createSampler(bool linear, VkSampler &vkImageSampler, VkSamplerAddressMode addressMode); }; } // Metal From d1b5a04a4999fba93d4f69466cafb698eb99b5c2 Mon Sep 17 00:00:00 2001 From: facobackup Date: Wed, 11 Mar 2026 22:16:44 -0300 Subject: [PATCH 07/18] - Rollback volume component and atmosphere - Removing light components - Removing flags from engine - Adding left side-bar dockspace --- CMakeLists.txt | 11 +- resources/shaders/GlobalDataBuffer.glsl | 18 +++ resources/shaders/VolumeBuffer.glsl | 13 +++ resources/shaders/rt/HWRayTracing.rgen | 36 +----- .../shaders/rt/HWRayTracingPushConstant.glsl | 2 + resources/shaders/util/LightVisibility.glsl | 27 +++-- resources/shaders/util/PixelShading.glsl | 4 +- resources/shaders/util/VolumeRayTracer.glsl | 49 ++++---- src/context/ApplicationContext.h | 2 + .../dock-spaces/inspector/InspectorPanel.cpp | 4 - .../dock-spaces/viewport/EngineFramePanel.cpp | 14 +-- .../dock-spaces/viewport/ViewportPanel.cpp | 6 +- .../editor/dock-spaces/world/WorldPanel.cpp | 2 - src/context/engine/EngineContext.cpp | 37 +----- src/context/engine/EngineContext.h | 15 --- .../compute-pass/impl/HWRayTracingPass.cpp | 11 +- src/dto/buffers/AtmosphereUBO.h | 21 ---- src/dto/buffers/GlobalDataUBO.h | 5 +- .../push-constant/HWRayTracingPushConstant.h | 2 + src/enum/ComponentType.cpp | 25 ---- src/enum/EngineResourceIDs.h | 1 - src/repository/dock/DockDTO.h | 2 +- src/repository/dock/DockPosition.h | 2 + src/repository/dock/DockRepository.cpp | 25 ++++ src/repository/dock/DockRepository.h | 12 +- src/repository/dock/DockSpace.cpp | 2 +- src/repository/engine/EngineRepository.cpp | 38 ++++++- src/repository/engine/EngineRepository.h | 12 +- src/repository/world/WorldRepository.cpp | 17 --- src/repository/world/WorldRepository.h | 3 - .../world/components/AtmosphereComponent.cpp | 107 ------------------ .../world/components/AtmosphereComponent.h | 45 -------- .../world/components/PlaneLightComponent.cpp | 13 --- .../world/components/PlaneLightComponent.h | 39 ------- .../world/components/SphereLightComponent.cpp | 14 --- .../world/components/SphereLightComponent.h | 43 ------- .../world/components/TransformComponent.cpp | 8 -- .../world/components/VolumeComponent.cpp | 8 +- .../world/components/VolumeComponent.h | 18 ++- src/service/camera/CameraService.cpp | 2 + src/service/dock/DockService.cpp | 82 ++++++++------ src/service/dock/DockService.h | 2 - src/service/lights/LightService.cpp | 93 ++++++--------- src/service/lights/LightService.h | 17 ++- src/service/mesh/SceneEntityData.h | 14 --- src/service/mesh/SceneImporterService.cpp | 17 +-- src/service/raytracing/RayTracingService.cpp | 2 + src/service/volumes/VolumeService.cpp | 36 ++++++ src/service/volumes/VolumeService.h | 24 ++++ 49 files changed, 373 insertions(+), 629 deletions(-) create mode 100644 resources/shaders/VolumeBuffer.glsl delete mode 100644 src/dto/buffers/AtmosphereUBO.h create mode 100644 src/repository/dock/DockRepository.cpp delete mode 100644 src/repository/world/components/AtmosphereComponent.cpp delete mode 100644 src/repository/world/components/AtmosphereComponent.h delete mode 100644 src/repository/world/components/PlaneLightComponent.cpp delete mode 100644 src/repository/world/components/PlaneLightComponent.h delete mode 100644 src/repository/world/components/SphereLightComponent.cpp delete mode 100644 src/repository/world/components/SphereLightComponent.h create mode 100644 src/service/volumes/VolumeService.cpp create mode 100644 src/service/volumes/VolumeService.h diff --git a/CMakeLists.txt b/CMakeLists.txt index ef9d468c..e81faae2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -112,7 +112,6 @@ add_executable( src/repository/runtime/RuntimeRepository.h src/service/buffer/BufferInstance.cpp src/service/buffer/BufferInstance.h - src/dto/buffers/AtmosphereUBO.h src/service/mesh/MeshService.cpp src/service/mesh/MeshService.h src/service/mesh/MeshData.h @@ -225,10 +224,6 @@ add_executable( src/service/voxel/SVOInstance.h src/dto/buffers/TileInfoUBO.h src/dto/buffers/LightData.h - src/repository/world/components/SphereLightComponent.cpp - src/repository/world/components/SphereLightComponent.h - src/repository/world/components/PlaneLightComponent.cpp - src/repository/world/components/PlaneLightComponent.h src/context/engine/render-pass/impl/tools/IconsPass.cpp src/context/engine/render-pass/impl/tools/IconsPass.h src/context/engine/render-pass/impl/tools/SelectionIDPass.cpp @@ -247,8 +242,6 @@ add_executable( src/service/lights/LightService.h src/repository/world/components/VolumeComponent.cpp src/repository/world/components/VolumeComponent.h - src/repository/world/components/AtmosphereComponent.cpp - src/repository/world/components/AtmosphereComponent.h src/service/descriptor/DescriptorBinding.h src/service/notification/AsyncTask.h src/service/voxel/VoxelImporterService.cpp @@ -284,11 +277,13 @@ add_executable( src/context/engine/compute-pass/impl/TemporalAccumulationPass.h src/context/engine/compute-pass/impl/SpatialFilterPass.cpp src/context/engine/compute-pass/impl/SpatialFilterPass.h - src/repository/world/components/AtmosphereComponent.cpp src/enum/ComponentType.cpp src/service/mesh/SceneEntityData.h src/context/editor/dock-spaces/repositories/RepositoriesPanel.cpp src/context/editor/dock-spaces/repositories/RepositoriesPanel.h + src/service/volumes/VolumeService.cpp + src/service/volumes/VolumeService.h + src/repository/dock/DockRepository.cpp ) diff --git a/resources/shaders/GlobalDataBuffer.glsl b/resources/shaders/GlobalDataBuffer.glsl index eb602dff..47cad588 100644 --- a/resources/shaders/GlobalDataBuffer.glsl +++ b/resources/shaders/GlobalDataBuffer.glsl @@ -8,7 +8,10 @@ layout (set = 0, binding = 0) uniform GlobalDataBlock { mat4 invProj; mat4 previousProjView; vec3 cameraWorldPosition; + vec3 sunColor; + vec3 sunPosition; + uint volumeCount; uint lightsCount; uint debugFlag; @@ -19,4 +22,19 @@ layout (set = 0, binding = 0) uniform GlobalDataBlock { } globalData; +bool intersectBox(vec3 ro, vec3 rd, vec3 dimensions, out float tEntry, out float tExit) { + vec3 boxMin = -dimensions * 0.5; + vec3 boxMax = dimensions * 0.5; + vec3 invRd = 1.0 / rd; + + vec3 t0s = (boxMin - ro) * invRd; + vec3 t1s = (boxMax - ro) * invRd; + vec3 tsmaller = min(t0s, t1s); + vec3 tbigger = max(t0s, t1s); + + tEntry = max(max(tsmaller.x, tsmaller.y), tsmaller.z); + tExit = min(min(tbigger.x, tbigger.y), tbigger.z); + + return (tExit >= max(tEntry, 0.0)); +} #endif \ No newline at end of file diff --git a/resources/shaders/VolumeBuffer.glsl b/resources/shaders/VolumeBuffer.glsl new file mode 100644 index 00000000..e8da13d6 --- /dev/null +++ b/resources/shaders/VolumeBuffer.glsl @@ -0,0 +1,13 @@ +#ifndef VOLUME_V +#define VOLUME_V +struct Volume { + vec4 color; + vec3 position; + vec3 dataA; + vec3 dataB; //For volumes: +}; + +layout(set = 0, binding = VOLUME_SET) readonly buffer Volumes { + Volume items[]; +} volumesBuffer; +#endif diff --git a/resources/shaders/rt/HWRayTracing.rgen b/resources/shaders/rt/HWRayTracing.rgen index 31037684..c09ac1bd 100644 --- a/resources/shaders/rt/HWRayTracing.rgen +++ b/resources/shaders/rt/HWRayTracing.rgen @@ -13,39 +13,11 @@ layout (set = 0, binding = 4, rgba16f) uniform image2D gBufferNormal; layout (location = 0) rayPayloadEXT RayPayload payload; -bool intersectBox(vec3 ro, vec3 rd, vec3 dimensions, out float tEntry, out float tExit) { - vec3 boxMin = -dimensions * 0.5; - vec3 boxMax = dimensions * 0.5; - vec3 invRd = 1.0 / rd; - - vec3 t0s = (boxMin - ro) * invRd; - vec3 t1s = (boxMax - ro) * invRd; - vec3 tsmaller = min(t0s, t1s); - vec3 tbigger = max(t0s, t1s); - - tEntry = max(max(tsmaller.x, tsmaller.y), tsmaller.z); - tExit = min(min(tbigger.x, tbigger.y), tbigger.z); - - return (tExit >= max(tEntry, 0.0)); -} - #define LIGHT_SET 5 #include "../LightBuffer.glsl" - -layout (set = 0, binding = 6) uniform AtmosphereDataBlock { - vec3 albedo; - vec3 volumeScale; - uint isAtmosphereEnabled; - uint isVolumeEnabled; - uint volumeShadowSteps; - float density; - float g; - float scatteringAlbedo; - int samples; - - vec3 sunPosition; -} atmosphereData; +#define VOLUME_SET 6 +#include "../VolumeBuffer.glsl" #define MESH_METADATA_SET 7 #include "../MeshMetadata.glsl" @@ -109,8 +81,8 @@ void main() { } if (!payload.hit) { - if (atmosphereData.isAtmosphereEnabled != 0) { - finalColor = calculate_sky_luminance_rgb(normalize(atmosphereData.sunPosition), rayDirection, 2.0f) * 0.05f; + if (pushConstants.isAtmosphereEnabled != 0) { + finalColor = calculate_sky_luminance_rgb(normalize(globalData.sunPosition), rayDirection, 2.0f) * 0.05f; } imageStore(gBufferPositionIndex, ivec2(gl_LaunchIDEXT.xy), vec4(0.0, 0.0, 0.0, 0.0)); imageStore(gBufferNormal, ivec2(gl_LaunchIDEXT.xy), vec4(0.0, 0.0, 0.0, 0.0)); diff --git a/resources/shaders/rt/HWRayTracingPushConstant.glsl b/resources/shaders/rt/HWRayTracingPushConstant.glsl index 01dd0e81..78d566ee 100644 --- a/resources/shaders/rt/HWRayTracingPushConstant.glsl +++ b/resources/shaders/rt/HWRayTracingPushConstant.glsl @@ -3,6 +3,8 @@ layout(push_constant) uniform PushConstants { float pathTracerMultiplier; + uint volumeShadowSteps; + uint isAtmosphereEnabled; uint multipleImportanceSampling; uint pathTracerSamples; diff --git a/resources/shaders/util/LightVisibility.glsl b/resources/shaders/util/LightVisibility.glsl index d3006d7a..92796b16 100644 --- a/resources/shaders/util/LightVisibility.glsl +++ b/resources/shaders/util/LightVisibility.glsl @@ -1,6 +1,6 @@ #ifndef V_T #define V_T -vec3 visibilityTest(const in Light light, in vec3 point, vec3 wi) { +vec3 visibilityTest(const in Light light, in vec3 point, vec3 wi) { float bias = max(.05, 1e-4 * length(point)); vec3 shadowsPosition = point + bias * wi;// Offset to avoid self-intersection @@ -20,20 +20,29 @@ vec3 visibilityTest(const in Light light, in vec3 point, vec3 wi) { float sigmaT = 0; vec3 vColor = vec3(1); bool anyHit = false; + for (uint i = 0; i < globalData.volumeCount; i++) { + Volume volume = volumesBuffer.items[i]; + + float tEntry, tExit; + vec3 roLocal = shadowsPosition - volume.position; + bool intersects = intersectBox(roLocal, wi, volume.dataA, tEntry, tExit); + if (!intersects) continue; + + if (tEntry > lightDistance){ + continue; + } - float tEntry, tExit; - vec3 roLocal = shadowsPosition; - bool intersects = intersectBox(roLocal, wi, atmosphereData.volumeScale, tEntry, tExit); - if (intersects && tEntry < lightDistance) { anyHit = true; - sigmaT = atmosphereData.density; + sigmaT = volume.dataB.x; distanceInVolume = tExit - tEntry; transmittance *= exp(-sigmaT * distanceInVolume); - vColor = atmosphereData.albedo; + vColor = volume.color.rgb; + if (transmittance < 1e-3) { + break; + } } - - return attenuation * vec3(transmittance * exp(-sigmaT * distanceInVolume) * vColor); + return attenuation * vec3(transmittance * exp(-sigmaT * distanceInVolume ) * vColor); } #endif \ No newline at end of file diff --git a/resources/shaders/util/PixelShading.glsl b/resources/shaders/util/PixelShading.glsl index 7be5d306..0fbea52a 100644 --- a/resources/shaders/util/PixelShading.glsl +++ b/resources/shaders/util/PixelShading.glsl @@ -74,8 +74,8 @@ vec3 tracePath(vec3 rayDirection, MaterialInfo material, SurfaceInteraction inte traceRayEXT(topLevelAS, gl_RayFlagsOpaqueEXT, 0xFF, 0, 0, 0, rayOrigin, 0.001, wi, 10000.0, 0); if (!payload.hit) { - if (atmosphereData.isAtmosphereEnabled != 0) { - vec3 skyLuminance = calculate_sky_luminance_rgb(normalize(atmosphereData.sunPosition), wi, 2.0f) * 0.05f; + if (pushConstants.isAtmosphereEnabled != 0) { + vec3 skyLuminance = calculate_sky_luminance_rgb(normalize(globalData.sunPosition), wi, 2.0f) * 0.05f; pathInfo.radiance += pathInfo.throughput * skyLuminance; } break; diff --git a/resources/shaders/util/VolumeRayTracer.glsl b/resources/shaders/util/VolumeRayTracer.glsl index d4d4e764..4d651a74 100644 --- a/resources/shaders/util/VolumeRayTracer.glsl +++ b/resources/shaders/util/VolumeRayTracer.glsl @@ -20,33 +20,33 @@ float hash(vec3 p) { } float densityVariation(vec3 p, float baseDensity) { - // float noise = hash(p * 0.5); +// float noise = hash(p * 0.5); return baseDensity; //* (0.5 + 0.5 * noise); } // Henyey–Greenstein phase function float phaseHenyeyGreenstein(vec3 wo, vec3 wi, float g) { float cosTheta = dot(wo, wi); - float denom = 1.0 + g * g - 2.0 * g * cosTheta; - return (1.0 - g * g) / (4.0 * 3.14159265359 * pow(denom, 1.5)); + float denom = 1.0 + g*g - 2.0 * g * cosTheta; + return (1.0 - g*g) / (4.0 * 3.14159265359 * pow(denom, 1.5)); } -vec4 integrateVolume(vec3 ro, vec3 rd, float sceneDepth) { - vec3 roLocal = ro; +vec4 integrateVolume(vec3 ro, vec3 rd, in Volume volume, float sceneDepth) { + vec3 roLocal = ro - volume.position; float tEntry, tExit; - bool intersects = intersectBox(roLocal, rd, atmosphereData.volumeScale, tEntry, tExit); + bool intersects = intersectBox(roLocal, rd, volume.dataA, tEntry, tExit); if (!intersects) { return vec4(0.0); } - if (tEntry > sceneDepth) { + if (tEntry > sceneDepth){ return vec4(0.0); } tEntry = max(tEntry, 0.0); - int steps = int(atmosphereData.samples); + int steps = int(volume.color.a); float dt = (tExit - tEntry) / float(steps); vec3 scattering = vec3(0.0); @@ -55,14 +55,14 @@ vec4 integrateVolume(vec3 ro, vec3 rd, float sceneDepth) { for (int i = 0; i < steps; i++) { float tCurrent = tEntry + dt * (float(i) + 0.5); vec3 pos = ro + rd * tCurrent; - vec3 localPos = pos ; + vec3 localPos = pos - volume.position; - float density = densityVariation(localPos, atmosphereData.density); + float density = densityVariation(localPos, volume.dataB.x); - float scatteringAlbedo = atmosphereData.scatteringAlbedo;// fraction of extinction that is scattering + float scatteringAlbedo = volume.dataB.y;// fraction of extinction that is scattering float scatteringCoefficient = density * scatteringAlbedo; - float absorptionCoefficient = density * (1.0 - scatteringAlbedo); - float extinctionCoefficient = scatteringCoefficient + absorptionCoefficient; + float absorptionCoefficient = density * (1.0 - scatteringAlbedo); + float extinctionCoefficient = scatteringCoefficient + absorptionCoefficient; vec3 inScattered = vec3(0.0); for (int li = 0; li < int(globalData.lightsCount); li++) { @@ -83,16 +83,16 @@ vec4 integrateVolume(vec3 ro, vec3 rd, float sceneDepth) { vec3 L = normalize(samplePos - pos); float lightDist = length(samplePos - pos); - float dtShadow = lightDist / float(atmosphereData.volumeShadowSteps); + float dtShadow = lightDist / float(pushConstants.volumeShadowSteps); float opticalDepth = 0.0; - for (int j = 0; j < int(atmosphereData.volumeShadowSteps); j++) { + for (int j = 0; j < int(pushConstants.volumeShadowSteps); j++) { float tShadow = float(j) * dtShadow; vec3 posShadow = pos + L * tShadow; - vec3 localShadow = posShadow; - opticalDepth += densityVariation(localShadow, atmosphereData.density) * dtShadow; + vec3 localShadow = posShadow - volume.position; + opticalDepth += densityVariation(localShadow, volume.dataB.x) * dtShadow; } float lightTransmittance = exp(-opticalDepth); - float g = atmosphereData.g;// phase function asymmetry parameter; 0.0 for isotropic + float g = volume.dataB.z;// phase function asymmetry parameter; 0.0 for isotropic float phase = phaseHenyeyGreenstein(rd, L, g); inScattered += light.color.rgb * light.color.a * lightTransmittance * phase; } @@ -100,16 +100,15 @@ vec4 integrateVolume(vec3 ro, vec3 rd, float sceneDepth) { viewTransmittance *= exp(-extinctionCoefficient * dt); } float volumeAlpha = 1.0 - viewTransmittance; - return vec4(scattering * atmosphereData.albedo, volumeAlpha); + return vec4(scattering * volume.color.rgb, volumeAlpha); } -void traceVolumes(inout vec4 finalColor, vec3 worldPosition, vec3 rayDirection) { - if (atmosphereData.isVolumeEnabled == 0) { - return; - } +void traceVolumes(inout vec4 finalColor, vec3 worldPosition, vec3 rayDirection){ vec3 rayOrigin = globalData.cameraWorldPosition; float sceneDepth = length(worldPosition.rgb - rayOrigin); - finalColor += integrateVolume(rayOrigin, rayDirection, sceneDepth); - + for (uint i = 0; i < globalData.volumeCount; i++) { + Volume volume = volumesBuffer.items[i]; + finalColor += integrateVolume(rayOrigin, rayDirection, volume, sceneDepth); + } } \ No newline at end of file diff --git a/src/context/ApplicationContext.h b/src/context/ApplicationContext.h index 3cbde43c..aad857a1 100644 --- a/src/context/ApplicationContext.h +++ b/src/context/ApplicationContext.h @@ -37,6 +37,7 @@ #include "../service/log/LogService.h" #include "../service/transform/TransformService.h" #include "../service/picking/PickingService.h" +#include "../service/volumes/VolumeService.h" #include "../service/voxel/VoxelImporterService.h" #include "../service/voxel/VoxelService.h" #include "../service/lights/LightService.h" @@ -87,6 +88,7 @@ namespace Metal { PickingService pickingService{}; TransformService transformService{}; LightService lightService{}; + VolumeService volumeService{}; RayTracingService rayTracingService{}; CommandBufferRecorderService commandBufferRecorderService{}; VoxelImporterService voxelImporterService{}; diff --git a/src/context/editor/dock-spaces/inspector/InspectorPanel.cpp b/src/context/editor/dock-spaces/inspector/InspectorPanel.cpp index fd785caf..9a09e624 100644 --- a/src/context/editor/dock-spaces/inspector/InspectorPanel.cpp +++ b/src/context/editor/dock-spaces/inspector/InspectorPanel.cpp @@ -5,12 +5,8 @@ #include "../../../../common/inspection/Inspectable.h" #include "../../../../context/ApplicationContext.h" #include "../../../../repository/world/impl/MetadataComponent.h" -#include "../../../../repository/world/components/VolumeComponent.h" -#include "../../../../repository/world/components/SphereLightComponent.h" -#include "../../../../repository/world/components/PlaneLightComponent.h" #include #include -#include "../../../../service/camera/Camera.h" namespace Metal { void InspectorPanel::onInitialize() { diff --git a/src/context/editor/dock-spaces/viewport/EngineFramePanel.cpp b/src/context/editor/dock-spaces/viewport/EngineFramePanel.cpp index 34a88418..d1bdc025 100644 --- a/src/context/editor/dock-spaces/viewport/EngineFramePanel.cpp +++ b/src/context/editor/dock-spaces/viewport/EngineFramePanel.cpp @@ -1,19 +1,16 @@ #include "EngineFramePanel.h" #include "../../../../context/ApplicationContext.h" -#include "ViewportPanel.h" #include "../../../../context/engine/frame-builder/EngineFrameBuilder.h" #include "../../../../context/engine/frame-builder/EngineFrame.h" -#include "../../../../service/framebuffer/FrameBufferService.h" #include "../../../../service/descriptor/DescriptorInstance.h" #include "../../../../service/framebuffer/FrameBufferInstance.h" #include "../../../../service/picking/PickingService.h" #include "../../../../enum/engine-definitions.h" #include "../../../../enum/EngineResourceIDs.h" #include "../../../../dto/buffers/GlobalDataUBO.h" -#include "../../../../dto/buffers/TileInfoUBO.h" #include "../../../../dto/buffers/LightData.h" +#include "../../../../dto/buffers/VolumeData.h" #include "../../../../dto/buffers/MeshMetadata.h" -#include "../../../../dto/buffers/AtmosphereUBO.h" #include "ViewportHeaderPanel.h" #include "ImGuizmo.h" #include @@ -26,10 +23,10 @@ namespace Metal { engineFrame = EngineFrameBuilder() .addBuffer(RID_GLOBAL_DATA, sizeof(GlobalDataUBO), VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, UNIFORM_BUFFER) - .addBuffer(RID_ATMOSPHERE_DATA, sizeof(AtmosphereUBO), - VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, UNIFORM_BUFFER) .addBuffer(RID_LIGHT_BUFFER, MAX_LIGHTS * sizeof(LightData), VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, STORAGE_BUFFER) + .addBuffer(RID_VOLUMES_BUFFER, MAX_VOLUMES * sizeof(VolumeData), + VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, STORAGE_BUFFER) .addBuffer(RID_MESH_METADATA_BUFFER, MAX_MESH_INSTANCES * sizeof(MeshMetadata), VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, STORAGE_BUFFER) .addTexture(RID_ACCUMULATED_FRAME, gBufferW, gBufferH) @@ -63,11 +60,6 @@ namespace Metal { void EngineFramePanel::onSync() { engineFrame->setShouldRender(true); - - const float tabHeight = ImGui::GetFrameHeightWithSpacing(); - // Assuming this panel is inside ViewportPanel, we need to get its size. - // But for now, let's use ImGui::GetContentRegionAvail() or similar if we can't access parent size easily. - // Actually, ViewportPanel sets its size in updateInputs. const ImVec2 viewportSize = ImGui::GetContentRegionAvail(); auto *framebuffer = engineFrame->getResourceAs(RID_POST_PROCESSING_FBO); diff --git a/src/context/editor/dock-spaces/viewport/ViewportPanel.cpp b/src/context/editor/dock-spaces/viewport/ViewportPanel.cpp index 93e31907..4d283a47 100644 --- a/src/context/editor/dock-spaces/viewport/ViewportPanel.cpp +++ b/src/context/editor/dock-spaces/viewport/ViewportPanel.cpp @@ -58,10 +58,8 @@ namespace Metal { } void ViewportPanel::onSync() { - if (!CTX.engineRepository.isBaking) { - updateCamera(); - updateInputs(); - } + updateCamera(); + updateInputs(); headerPanel->onSync(); engineFramePanel->onSync(); diff --git a/src/context/editor/dock-spaces/world/WorldPanel.cpp b/src/context/editor/dock-spaces/world/WorldPanel.cpp index ecf595c5..ac2265da 100644 --- a/src/context/editor/dock-spaces/world/WorldPanel.cpp +++ b/src/context/editor/dock-spaces/world/WorldPanel.cpp @@ -5,8 +5,6 @@ #include "../../../../util/UIUtil.h" #include "../../../../context/ApplicationContext.h" #include "../../../../repository/world/impl/MetadataComponent.h" -#include "../../../../repository/world/components/SphereLightComponent.h" -#include "../../../../repository/world/components/PlaneLightComponent.h" #include "../../../../enum/ComponentType.h" namespace Metal { diff --git a/src/context/engine/EngineContext.cpp b/src/context/engine/EngineContext.cpp index 8a10b208..4b8d6c85 100644 --- a/src/context/engine/EngineContext.cpp +++ b/src/context/engine/EngineContext.cpp @@ -3,13 +3,7 @@ #include "../../enum/EngineResourceIDs.h" #include "../../context/ApplicationContext.h" #include "../../service/buffer/BufferInstance.h" -#include "../../service/descriptor/DescriptorBinding.h" -#include "../../service/voxel/SVOInstance.h" #include "../../service/camera/Camera.h" -#include "../../service/framebuffer/FrameBufferInstance.h" -#include "../../service/texture/TextureInstance.h" -#include "../../repository/world/components/AtmosphereComponent.h" -#include "../../repository/world/impl/MetadataComponent.h" #include "../../repository/world/components/TransformComponent.h" namespace Metal { @@ -47,9 +41,8 @@ namespace Metal { CTX.streamingService.onSync(); CTX.rayTracingService.onSync(); CTX.cameraService.onSync(); - if (updateLights || isFirstFrame) { - CTX.lightService.onSync(); - } + CTX.lightService.onSync(); + CTX.volumeService.onSync(); for (auto *frame: registeredFrames) { if (frame->getShouldRender()) { @@ -61,8 +54,6 @@ namespace Metal { } } - isFirstFrame = false; - setUpdateLights(false); setCameraUpdated(false); setGISettingsUpdated(false); } @@ -76,6 +67,7 @@ namespace Metal { globalDataUBO.invProj = camera.invProjectionMatrix; globalDataUBO.invView = camera.invViewMatrix; globalDataUBO.cameraWorldPosition = camera.position; + globalDataUBO.volumeCount = CTX.volumeService.getCount(); globalDataUBO.lightsCount = CTX.lightService.getCount(); globalDataUBO.debugFlag = ShadingModes::IndexOfValue(CTX.editorRepository.shadingMode); CTX.engineRepository.pathTracerAccumulationCount++; @@ -87,26 +79,9 @@ namespace Metal { ? 1 : 0; - entt::registry ® = CTX.worldRepository.registry; - auto view = reg.view(); - if (auto it = view.begin(); it != view.end()) { - auto &atmo = reg.get(*it); - atmosphereUBO.volumeScale = atmo.volumeScale; - atmosphereUBO.albedo = atmo.albedo; - atmosphereUBO.density = atmo.density; - atmosphereUBO.g = atmo.g; - atmosphereUBO.isAtmosphereEnabled = atmo.atmosphereEnabled ? 1 : 0; - atmosphereUBO.isVolumeEnabled = atmo.volumeEnabled ? 1 : 0; - atmosphereUBO.volumeShadowSteps = atmo.volumeShadowSteps; - atmosphereUBO.scatteringAlbedo = atmo.scatteringAlbedo; - atmosphereUBO.samples = atmo.samples; - atmosphereUBO.sunPosition = atmo.sunPosition; - } else { - atmosphereUBO.isVolumeEnabled = 0; - atmosphereUBO.isAtmosphereEnabled = 0; - } - + CTX.lightService.computeSunInfo(); + globalDataUBO.sunPosition = CTX.lightService.getSunPosition(); + globalDataUBO.sunColor = CTX.lightService.getSunColor(); currentFrame->getResourceAs(RID_GLOBAL_DATA)->update(&globalDataUBO); - currentFrame->getResourceAs(RID_ATMOSPHERE_DATA)->update(&atmosphereUBO); } } diff --git a/src/context/engine/EngineContext.h b/src/context/engine/EngineContext.h index b47d4ddb..79e99f4b 100644 --- a/src/context/engine/EngineContext.h +++ b/src/context/engine/EngineContext.h @@ -6,7 +6,6 @@ #include #include "../../dto/buffers/GlobalDataUBO.h" -#include "../../dto/buffers/AtmosphereUBO.h" #include "../../common/AbstractRuntimeComponent.h" #include "../../dto/buffers/TileInfoUBO.h" @@ -16,24 +15,13 @@ using TimePoint = std::chrono::time_point; namespace Metal { class EngineContext final : public AbstractRuntimeComponent { GlobalDataUBO globalDataUBO{}; - AtmosphereUBO atmosphereUBO{}; long long start = -1; bool cameraUpdated = true; - bool updateLights = true; bool giSettingsUpdated = true; - bool isFirstFrame = true; public: GlobalDataUBO &getGlobalDataUBO() { return globalDataUBO; } - void setUpdateLights(const bool val) { - updateLights = val; - } - - [[nodiscard]] bool isUpdateLights() const { - return updateLights; - } - void setCameraUpdated(const bool val) { cameraUpdated = val; } @@ -56,9 +44,6 @@ namespace Metal { void updateCurrentTime(); - explicit EngineContext() : AbstractRuntimeComponent() { - } - long long currentTimeMs = 0; TimePoint currentTime; TimePoint previousTime = Clock::now(); diff --git a/src/context/engine/compute-pass/impl/HWRayTracingPass.cpp b/src/context/engine/compute-pass/impl/HWRayTracingPass.cpp index 4c0d888c..dcba2bfa 100644 --- a/src/context/engine/compute-pass/impl/HWRayTracingPass.cpp +++ b/src/context/engine/compute-pass/impl/HWRayTracingPass.cpp @@ -7,10 +7,6 @@ #include "../../../../service/raytracing/RayTracingService.h" #include "../../../../enum/EngineResourceIDs.h" -#include "../../../../repository/world/components/PrimitiveComponent.h" -#include "../../../../repository/world/components/TransformComponent.h" -#include "../../../../repository/world/components/AtmosphereComponent.h" - namespace Metal { void HWRayTracingPass::onInitialize() { PipelineBuilder builder = PipelineBuilder::OfRayTracing( @@ -24,7 +20,7 @@ namespace Metal { .addStorageImageBinding(getScopedResourceId(RID_GBUFFER_POSITION_INDEX)) .addStorageImageBinding(getScopedResourceId(RID_GBUFFER_NORMAL)) .addBufferBinding(getScopedResourceId(RID_LIGHT_BUFFER)) - .addBufferBinding(getScopedResourceId(RID_ATMOSPHERE_DATA)) + .addBufferBinding(getScopedResourceId(RID_VOLUMES_BUFFER)) .addBufferBinding(getScopedResourceId(RID_MESH_METADATA_BUFFER)) .addCombinedImageSamplerBinding(CTX.vulkanContext.vkImageSampler, VK_NULL_HANDLE, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, 1000); @@ -38,8 +34,7 @@ namespace Metal { auto *previousPositionIndex = frame->getResourceAs(RID_PREVIOUS_POSITION_INDEX); auto *previousNormal = frame->getResourceAs(RID_PREVIOUS_NORMAL); - if (isFirstRun || CTX.engineContext.isCameraUpdated() || CTX.engineContext.isGISettingsUpdated() || - CTX.engineContext.isUpdateLights()) { + if (isFirstRun || CTX.engineContext.isCameraUpdated() || CTX.engineContext.isGISettingsUpdated()) { clearTexture(accumulatedFrame->vkImage); CTX.engineContext.resetPathTracerAccumulationCount(); isFirstRun = false; @@ -53,6 +48,8 @@ namespace Metal { // Trace rays pushConstant.pathTracerMultiplier = CTX.engineRepository.pathTracerMultiplier; + pushConstant.volumeShadowSteps = CTX.engineRepository.volumeShadowSteps; + pushConstant.isAtmosphereEnabled = CTX.engineRepository.atmosphereEnabled; pushConstant.multipleImportanceSampling = CTX.engineRepository.multipleImportanceSampling; pushConstant.pathTracerSamples = CTX.engineRepository.pathTracerSamples; diff --git a/src/dto/buffers/AtmosphereUBO.h b/src/dto/buffers/AtmosphereUBO.h deleted file mode 100644 index 76cba3a7..00000000 --- a/src/dto/buffers/AtmosphereUBO.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef ATMOSPHEREUBO_H -#define ATMOSPHEREUBO_H - -#include - -namespace Metal { - struct AtmosphereUBO { - alignas(16) glm::vec3 albedo; - alignas(16) glm::vec3 volumeScale; - alignas(4) unsigned int isAtmosphereEnabled; - alignas(4) unsigned int isVolumeEnabled; - alignas(4) unsigned int volumeShadowSteps; - alignas(4) float density; - alignas(4) float g; - alignas(4) float scatteringAlbedo; - alignas(4) int samples; - alignas(16) glm::vec3 sunPosition{}; - }; -} - -#endif //ATMOSPHEREUBO_H diff --git a/src/dto/buffers/GlobalDataUBO.h b/src/dto/buffers/GlobalDataUBO.h index 488bc859..32440007 100644 --- a/src/dto/buffers/GlobalDataUBO.h +++ b/src/dto/buffers/GlobalDataUBO.h @@ -10,9 +10,10 @@ namespace Metal { alignas(16) glm::mat4x4 invView{}; alignas(16) glm::mat4x4 invProj{}; alignas(16) glm::mat4x4 previousProjView{}; - alignas(16) glm::vec3 cameraWorldPosition{}; - + alignas(16) glm::vec3 sunColor{}; + alignas(16) glm::vec3 sunPosition{}; + alignas(4) unsigned int volumeCount{}; alignas(4) unsigned int lightsCount{}; alignas(4) unsigned int debugFlag; alignas(4) unsigned int pathTracerAccumulationCount = 0; diff --git a/src/dto/push-constant/HWRayTracingPushConstant.h b/src/dto/push-constant/HWRayTracingPushConstant.h index f7525d5d..5cc92862 100644 --- a/src/dto/push-constant/HWRayTracingPushConstant.h +++ b/src/dto/push-constant/HWRayTracingPushConstant.h @@ -4,6 +4,8 @@ namespace Metal { struct HWRayTracingPushConstant { alignas(4) float pathTracerMultiplier{}; + alignas(4) unsigned int volumeShadowSteps = 0; + alignas(4) unsigned int isAtmosphereEnabled{}; alignas(4) unsigned int multipleImportanceSampling{}; alignas(4) unsigned int pathTracerSamples{}; diff --git a/src/enum/ComponentType.cpp b/src/enum/ComponentType.cpp index 6cf50f48..7dfbe93e 100644 --- a/src/enum/ComponentType.cpp +++ b/src/enum/ComponentType.cpp @@ -43,23 +43,6 @@ namespace Metal::ComponentTypes { } } ), - DEFINE_COMPONENT( - SPHERE_LIGHT, "Sphere Light", "sphere_light", Icons::lightbulb, {TRANSFORM}, - SphereLightComponent, - [](WorldRepository &repo, entt::entity entityId) { - auto &light = repo.registry.emplace_or_replace(entityId); - light.setEntityId(entityId); - CTX.engineContext.setUpdateLights(true); - } - ), - DEFINE_COMPONENT( - PLANE_LIGHT, "Plane Light", "plane_light", Icons::lightbulb, {TRANSFORM}, PlaneLightComponent, - [](WorldRepository &repo, entt::entity entityId) { - auto &light = repo.registry.emplace_or_replace(entityId); - light.setEntityId(entityId); - CTX.engineContext.setUpdateLights(true); - } - ), DEFINE_COMPONENT( VOLUME, "Volume Component", "volume", Icons::blur_on, {TRANSFORM}, VolumeComponent, [](WorldRepository &repo, entt::entity entityId) { @@ -67,14 +50,6 @@ namespace Metal::ComponentTypes { vol.setEntityId(entityId); } ), - DEFINE_COMPONENT( - ATMOSPHERE, "Atmosphere", "atmosphere", Icons::cloud, {}, AtmosphereComponent, - [](WorldRepository &repo, entt::entity entityId) { - auto &atmo = repo.registry.emplace_or_replace(entityId); - atmo.setEntityId(entityId); - CTX.engineContext.setGISettingsUpdated(true); - } - ), DEFINE_COMPONENT( METADATA, "Metadata", "metadata", Icons::data_array, {}, MetadataComponent, [](WorldRepository &repo, entt::entity entityId) { diff --git a/src/enum/EngineResourceIDs.h b/src/enum/EngineResourceIDs.h index 17803b29..8913ec70 100644 --- a/src/enum/EngineResourceIDs.h +++ b/src/enum/EngineResourceIDs.h @@ -16,7 +16,6 @@ namespace Metal { inline constexpr const char* RID_POST_PROCESSING_FBO = "postProcessingFBO"; inline constexpr const char* RID_COMPUTE_CB = "ComputeCB"; inline constexpr const char* RID_POST_PROCESSING_CB = "PostProcessingCB"; - inline constexpr const char* RID_ATMOSPHERE_DATA = "atmosphereData"; inline constexpr const char* RID_VOLUMES_BUFFER = "volumesBuffer"; inline constexpr const char* RID_SELECTION_FBO = "selectionFBO"; inline constexpr const char* RID_SELECTION_CB = "selectionCB"; diff --git a/src/repository/dock/DockDTO.h b/src/repository/dock/DockDTO.h index 4b539b1e..60a8109f 100644 --- a/src/repository/dock/DockDTO.h +++ b/src/repository/dock/DockDTO.h @@ -2,6 +2,7 @@ #define METAL_ENGINE_DOCKDTO_H #include +#include #include #include "DockSpace.h" #include "DockPosition.h" @@ -19,7 +20,6 @@ namespace Metal { float sizeRatioForNodeAtDir{}; DockDTO *outAtOppositeDir = nullptr; DockDTO *origin = nullptr; - DockPosition direction = RIGHT_TOP; std::vector dockSpaces{}; diff --git a/src/repository/dock/DockPosition.h b/src/repository/dock/DockPosition.h index a6e01522..b0b3ae35 100644 --- a/src/repository/dock/DockPosition.h +++ b/src/repository/dock/DockPosition.h @@ -6,6 +6,8 @@ namespace Metal { TOP, RIGHT_BOTTOM, RIGHT_TOP, + LEFT_TOP, + LEFT_BOTTOM, BOTTOM }; } diff --git a/src/repository/dock/DockRepository.cpp b/src/repository/dock/DockRepository.cpp new file mode 100644 index 00000000..560f31d7 --- /dev/null +++ b/src/repository/dock/DockRepository.cpp @@ -0,0 +1,25 @@ +#include "DockRepository.h" + +namespace Metal { + DockRepository::DockRepository() : AbstractRuntimeComponent() { + auto *rightT = new DockDTO{&DockSpace::WORLD}; + auto *leftTop = new DockDTO{&DockSpace::REPOSITORIES}; + auto *leftDown = new DockDTO{&DockSpace::INSPECTOR}; + auto *downLeft = new DockDTO{&DockSpace::CONSOLE}; + auto *downRight = new DockDTO{&DockSpace::FILES}; + + center.sizeRatioForNodeAtDir = 0.5f; + rightT->sizeRatioForNodeAtDir = 0.25f; + leftTop->sizeRatioForNodeAtDir = 0.2f; + leftDown->sizeRatioForNodeAtDir = 0.5f; + downLeft->sizeRatioForNodeAtDir = 0.25f; + downRight->sizeRatioForNodeAtDir = 0.5f; + + right.push_back(rightT); + left.push_back(leftTop); + left.push_back(leftDown); + + bottom.push_back(downLeft); + bottom.push_back(downRight); + } +} // Metal diff --git a/src/repository/dock/DockRepository.h b/src/repository/dock/DockRepository.h index 145cb3b3..dfbd6d79 100644 --- a/src/repository/dock/DockRepository.h +++ b/src/repository/dock/DockRepository.h @@ -1,16 +1,20 @@ #ifndef METAL_ENGINE_DOCKREPOSITORY_H #define METAL_ENGINE_DOCKREPOSITORY_H +#include #include "DockDTO.h" #include "../../common/AbstractRuntimeComponent.h" namespace Metal { struct DockRepository final : AbstractRuntimeComponent { - DockDTO top{&DockSpace::VIEWPORT, 0.17f}; - DockDTO bottom{&DockSpace::FILES, .25f}; - DockDTO rightTop{&DockSpace::WORLD, 0.6f}; - DockDTO rightBottom{&DockSpace::INSPECTOR, 0.4f}; + DockDTO center{&DockSpace::VIEWPORT}; + std::vector bottom; + std::vector left; + std::vector right; + bool isInitialized = false; + + explicit DockRepository(); }; } // Metal diff --git a/src/repository/dock/DockSpace.cpp b/src/repository/dock/DockSpace.cpp index 4325a88e..ce757cbc 100644 --- a/src/repository/dock/DockSpace.cpp +++ b/src/repository/dock/DockSpace.cpp @@ -18,7 +18,7 @@ namespace Metal { DockSpace DockSpace::FILES{3, "Files", Icons::folder_open, 4, 4, CB(FilesPanel)}; DockSpace DockSpace::METRICS{4, "Metrics", Icons::analytics, 4, 4, CB(MetricsPanel)}; DockSpace DockSpace::REPOSITORIES{5, "Repositories", Icons::search, 4, 4, CB(RepositoriesPanel)}; - const char *DockSpace::OPTIONS = "Inspector\0World\0Console\0Files\0Metrics\0Repositories"; + const char *DockSpace::OPTIONS = "Inspector\0World\0Console\0Files\0Metrics\0Repositories\0"; DockSpace *DockSpace::GetOption(const int selected) { diff --git a/src/repository/engine/EngineRepository.cpp b/src/repository/engine/EngineRepository.cpp index 9ddc5546..1add07b1 100644 --- a/src/repository/engine/EngineRepository.cpp +++ b/src/repository/engine/EngineRepository.cpp @@ -7,6 +7,7 @@ #define PATH_TRACER "Path tracer" #define ATMOSPHERE "Atmosphere" #define SUN "Sun" +#define VOLUMES "Volumes" #define DEPTH_OF_FIELD "Depth of field" namespace Metal { @@ -14,9 +15,8 @@ namespace Metal { registerInt(shadingResInvScale, "Display settings (Restart required)", "Shading inverted resolution scale", 1, 16); registerBool(vsync, "Display settings (Restart required)", "VSync?"); - registerInt(numberOfTiles, "World", "Number of tiles", 2, 100); - // registerInt(maxVideoFrames, "", "Max video frames", 1); + registerInt(volumeShadowSteps, VOLUMES, "Shadow steps", 1); registerFloat(pathTracerMultiplier, PATH_TRACER, "Strength"); registerBool(denoiserEnabled, PATH_TRACER, "Enable denoiser?"); @@ -27,12 +27,24 @@ namespace Metal { registerFloat(pathTracingEmissiveFactor, PATH_TRACER, "Emissive surface factor", 0); registerBool(dofEnabled, DEPTH_OF_FIELD, "Enable depth of field?"); + registerFloat(dofFocusDistance, DEPTH_OF_FIELD, "Focus distance"); + registerFloat(dofAperture, DEPTH_OF_FIELD, "Aperture"); + registerFloat(dofFocalLength, DEPTH_OF_FIELD, "Focal length"); + + registerBool(atmosphereEnabled, ATMOSPHERE, "Enable atmosphere?"); + registerFloat(elapsedTime, ATMOSPHERE, "Elapsed time"); + registerFloat(sunDistance, ATMOSPHERE, "Sun distance"); + registerFloat(sunRadius, ATMOSPHERE, "Sun radius"); + registerFloat(sunLightIntensity, ATMOSPHERE, "Sun light intensity"); + registerColor(dawnColor, SUN, "Dawn color"); + registerColor(nightColor, SUN, "Night color"); + registerColor(middayColor, SUN, "Midday color"); } void EngineRepository::onUpdate(InspectableMember *member) { - if (member != nullptr && (member->group == PATH_TRACER || member->group == DEPTH_OF_FIELD)) { + if (member != nullptr && (member->group == PATH_TRACER || member->group == ATMOSPHERE || member->group + == SUN || member->group == DEPTH_OF_FIELD)) { CTX.engineContext.setGISettingsUpdated(true); - CTX.engineContext.setUpdateLights(true); } } @@ -42,11 +54,20 @@ namespace Metal { j["pathTracerSamples"] = pathTracerSamples; j["multipleImportanceSampling"] = multipleImportanceSampling; j["pathTracerBounces"] = pathTracerBounces; + j["atmosphereEnabled"] = atmosphereEnabled; + j["elapsedTime"] = elapsedTime; + j["sunRadius"] = sunRadius; + j["sunDistance"] = sunDistance; + j["sunLightIntensity"] = sunLightIntensity; + j["dawnColor"] = {dawnColor.x, dawnColor.y, dawnColor.z}; + j["nightColor"] = {nightColor.x, nightColor.y, nightColor.z}; + j["middayColor"] = {middayColor.x, middayColor.y, middayColor.z}; j["svoFilePaths"] = svoFilePaths; j["pathTracingEmissiveFactor"] = pathTracingEmissiveFactor; j["pathTracerMultiplier"] = pathTracerMultiplier; j["shadingResInvScale"] = shadingResInvScale; j["pathTracerMaxSamples"] = pathTracerMaxSamples; + j["volumeShadowSteps"] = volumeShadowSteps; j["denoiserEnabled"] = denoiserEnabled; j["dofEnabled"] = dofEnabled; j["dofFocusDistance"] = dofFocusDistance; @@ -60,12 +81,21 @@ namespace Metal { pathTracerSamples = j.at("pathTracerSamples").get(); multipleImportanceSampling = j.at("multipleImportanceSampling").get(); pathTracerBounces = j.at("pathTracerBounces").get(); + atmosphereEnabled = j.at("atmosphereEnabled").get(); + elapsedTime = j.at("elapsedTime").get(); + sunRadius = j.at("sunRadius").get(); + sunDistance = j.at("sunDistance").get(); + sunLightIntensity = j.at("sunLightIntensity").get(); + dawnColor = {j.at("dawnColor")[0], j.at("dawnColor")[1], j.at("dawnColor")[2]}; + nightColor = {j.at("nightColor")[0], j.at("nightColor")[1], j.at("nightColor")[2]}; + middayColor = {j.at("middayColor")[0], j.at("middayColor")[1], j.at("middayColor")[2]}; svoFilePaths = j.at("svoFilePaths").get >(); pathTracingEmissiveFactor = j.at("pathTracingEmissiveFactor").get(); pathTracerMultiplier = j.at("pathTracerMultiplier").get(); shadingResInvScale = j.at("shadingResInvScale").get(); pathTracerMaxSamples = j.at("pathTracerMaxSamples").get(); denoiserEnabled = j.at("denoiserEnabled").get(); + volumeShadowSteps = j.at("volumeShadowSteps").get(); dofEnabled = j.at("dofEnabled").get(); dofFocusDistance = j.at("dofFocusDistance").get(); dofAperture = j.at("dofAperture").get(); diff --git a/src/repository/engine/EngineRepository.h b/src/repository/engine/EngineRepository.h index 1bf56141..de4db803 100644 --- a/src/repository/engine/EngineRepository.h +++ b/src/repository/engine/EngineRepository.h @@ -8,7 +8,6 @@ namespace Metal { struct EngineRepository final : Inspectable, Serializable { bool vsync = true; - bool isBaking = false; bool denoiserEnabled = false; bool dofEnabled = false; float dofFocusDistance = 10; @@ -16,7 +15,7 @@ namespace Metal { float dofFocalLength = 5; bool multipleImportanceSampling = false; - int maxVideoFrames = 100; + int volumeShadowSteps = 8; int shadingResInvScale = 2; int pathTracerMaxSamples = 200; float pathTracingEmissiveFactor = 2; @@ -24,7 +23,14 @@ namespace Metal { int pathTracerBounces = 1; int pathTracerAccumulationCount = 0; float pathTracerMultiplier = 1; - int numberOfTiles = 10; + float elapsedTime = .5f; + bool atmosphereEnabled = false; + float sunDistance = 10000; + float sunRadius = 3000; + float sunLightIntensity = 2; + glm::vec3 dawnColor{1, .39f, .19f}; + glm::vec3 nightColor{.1f, .1f, .1f}; + glm::vec3 middayColor{.9f, .9f, .9f}; std::vector svoFilePaths{}; void registerFields() override; diff --git a/src/repository/world/WorldRepository.cpp b/src/repository/world/WorldRepository.cpp index 897f8710..fd9a1cc9 100644 --- a/src/repository/world/WorldRepository.cpp +++ b/src/repository/world/WorldRepository.cpp @@ -35,7 +35,6 @@ namespace Metal { registry.destroy(entityId); } - CTX.engineContext.setUpdateLights(true); CTX.rayTracingService.markDirty(); } @@ -46,7 +45,6 @@ namespace Metal { } else { hiddenEntities.insert({entity, true}); } - CTX.engineContext.setUpdateLights(true); CTX.rayTracingService.markDirty(); } @@ -86,21 +84,6 @@ namespace Metal { primitive.ior = entityData.primitive->ior; primitive.isEmissive = entityData.primitive->isEmissive; } - - if (entityData.sphereLight) { - createComponent(entityId, SPHERE_LIGHT); - auto &sphereLight = registry.get(entityId); - sphereLight.color = entityData.sphereLight->color; - sphereLight.intensity = entityData.sphereLight->intensity; - sphereLight.radiusSize = entityData.sphereLight->radiusSize; - } - - if (entityData.planeLight) { - createComponent(entityId, PLANE_LIGHT); - auto &planeLight = registry.get(entityId); - planeLight.color = entityData.planeLight->color; - planeLight.intensity = entityData.planeLight->intensity; - } } CTX.rayTracingService.markDirty(); diff --git a/src/repository/world/WorldRepository.h b/src/repository/world/WorldRepository.h index 2597e3ee..2088eff3 100644 --- a/src/repository/world/WorldRepository.h +++ b/src/repository/world/WorldRepository.h @@ -12,12 +12,9 @@ #include "../../service/camera/Camera.h" #include "impl/MetadataComponent.h" #include "../../enum/ComponentType.h" -#include "components/SphereLightComponent.h" -#include "components/PlaneLightComponent.h" #include "components/TransformComponent.h" #include "components/PrimitiveComponent.h" #include "components/VolumeComponent.h" -#include "components/AtmosphereComponent.h" namespace Metal { class Inspectable; diff --git a/src/repository/world/components/AtmosphereComponent.cpp b/src/repository/world/components/AtmosphereComponent.cpp deleted file mode 100644 index 652c3dab..00000000 --- a/src/repository/world/components/AtmosphereComponent.cpp +++ /dev/null @@ -1,107 +0,0 @@ -#include "AtmosphereComponent.h" -#include "../../../context/ApplicationContext.h" - -namespace Metal { - glm::vec3 BlendColors(glm::vec3 &c1, glm::vec3 &c2, float t) { - return { - (c1.x * (1 - t) + c2.x * t), - (c1.y * (1 - t) + c2.y * t), - (c1.z * (1 - t) + c2.z * t) - }; - } - - glm::vec3 CalculateSunColor(const float elevation, glm::vec3 &nightColor, glm::vec3 &dawnColor, - glm::vec3 &middayColor) { - if (elevation <= -0.1f) { - return nightColor; - } - if (elevation <= 0.0f) { - float t = (elevation + 0.1f) / 0.1f; - return BlendColors(nightColor, dawnColor, t); - } - if (elevation <= 0.5f) { - float t = elevation / 0.5f; - return BlendColors(dawnColor, middayColor, t); - } - return middayColor; - } - - - void AtmosphereComponent::registerFields() { - registerBool(volumeEnabled, "Volume", "Enable volume scattering?"); - registerColor(albedo, "Volume", "Albedo"); - registerFloat(density, "Volume", "Density", .1, 10); - registerFloat(g, "Volume", "Phase function asymmetry (0.0 for isotropic)", 0); - registerFloat(scatteringAlbedo, "Volume", "Scattering albedo", 0); - registerInt(samples, "Volume", "Samples", 1); - registerInt(volumeShadowSteps, "Volume", "Shadow steps", 1); - - registerBool(atmosphereEnabled, "Atmosphere", "Enable atmosphere?"); - registerFloat(elapsedTime, "Atmosphere", "Elapsed time"); - registerFloat(sunDistance, "Atmosphere", "Sun distance"); - registerFloat(sunRadius, "Atmosphere", "Sun radius"); - registerFloat(sunLightIntensity, "Atmosphere", "Sun light intensity"); - registerColor(dawnColor, "Sun", "Dawn color"); - registerColor(nightColor, "Sun", "Night color"); - registerColor(middayColor, "Sun", "Midday color"); - } - - ComponentType AtmosphereComponent::getType() { - return ComponentType::ATMOSPHERE; - } - - void AtmosphereComponent::onUpdate(InspectableMember *member) { - CTX.engineContext.setGISettingsUpdated(true); - CTX.engineContext.setUpdateLights(true); - - sunPosition = glm::vec3(0, - std::cos(elapsedTime), - std::sin(elapsedTime)) * sunDistance; - sunColor = CalculateSunColor( - sunPosition.y / sunDistance, - nightColor, dawnColor, - middayColor); - } - - nlohmann::json AtmosphereComponent::toJson() const { - nlohmann::json j; - j["entityId"] = entityId; - j["albedo"] = {albedo.x, albedo.y, albedo.z}; - j["density"] = density; - j["g"] = g; - j["scatteringAlbedo"] = scatteringAlbedo; - j["samples"] = samples; - j["sunDistance"] = sunDistance; - j["sunRadius"] = sunRadius; - j["sunLightIntensity"] = sunLightIntensity; - j["elapsedTime"] = elapsedTime; - j["atmosphereEnabled"] = atmosphereEnabled; - j["volumeShadowSteps"] = volumeShadowSteps; - j["volumeEnabled"] = volumeEnabled; - j["dawnColor"] = {dawnColor.x, dawnColor.y, dawnColor.z}; - j["nightColor"] = {nightColor.x, nightColor.y, nightColor.z}; - j["middayColor"] = {middayColor.x, middayColor.y, middayColor.z}; - j["volumeScale"] = {volumeScale.x, volumeScale.y, volumeScale.z}; - return j; - } - - void AtmosphereComponent::fromJson(const nlohmann::json &j) { - entityId = j.at("entityId").get(); - albedo = {j.at("albedo")[0], j.at("albedo")[1], j.at("albedo")[2]}; - density = j.at("density").get(); - g = j.at("g").get(); - scatteringAlbedo = j.at("scatteringAlbedo").get(); - samples = j.at("samples").get(); - volumeShadowSteps = j.at("volumeShadowSteps").get(); - sunDistance = j.at("sunDistance").get(); - sunRadius = j.at("sunRadius").get(); - sunLightIntensity = j.at("sunLightIntensity").get(); - elapsedTime = j.at("elapsedTime").get(); - atmosphereEnabled = j.at("atmosphereEnabled").get(); - volumeEnabled = j.at("volumeEnabled").get(); - dawnColor = {j.at("dawnColor")[0], j.at("dawnColor")[1], j.at("dawnColor")[2]}; - nightColor = {j.at("nightColor")[0], j.at("nightColor")[1], j.at("nightColor")[2]}; - middayColor = {j.at("middayColor")[0], j.at("middayColor")[1], j.at("middayColor")[2]}; - volumeScale = {j.at("volumeScale")[0], j.at("volumeScale")[1], j.at("volumeScale")[2]}; - } -} // Metal diff --git a/src/repository/world/components/AtmosphereComponent.h b/src/repository/world/components/AtmosphereComponent.h deleted file mode 100644 index cdbb3cad..00000000 --- a/src/repository/world/components/AtmosphereComponent.h +++ /dev/null @@ -1,45 +0,0 @@ -#ifndef ATMOSPHERECOMPONENT_H -#define ATMOSPHERECOMPONENT_H - -#include "../impl/AbstractComponent.h" -#include "../../../util/Serializable.h" -#include - -namespace Metal { - struct AtmosphereComponent final : AbstractComponent, Serializable { - glm::vec3 albedo = glm::vec3(1.0f); - glm::vec3 volumeScale = glm::vec3(100.f); - float density = 1; - float g = 0; - float scatteringAlbedo = 5; - int samples = 64; - int volumeShadowSteps = 8; - - float sunDistance = 10000; - float sunRadius = 3000; - float sunLightIntensity = 2; - float elapsedTime = .5f; - bool atmosphereEnabled = false; - bool volumeEnabled = false; - - glm::vec3 dawnColor{1, .39f, .19f}; - glm::vec3 nightColor{.1f, .1f, .1f}; - glm::vec3 middayColor{.9f, .9f, .9f}; - - - glm::vec3 sunColor{}; - glm::vec3 sunPosition{}; - - void registerFields() override; - - ComponentType getType() override; - - void onUpdate(InspectableMember *member) override; - - nlohmann::json toJson() const override; - - void fromJson(const nlohmann::json& j) override; - }; -} // Metal - -#endif //ATMOSPHERECOMPONENT_H diff --git a/src/repository/world/components/PlaneLightComponent.cpp b/src/repository/world/components/PlaneLightComponent.cpp deleted file mode 100644 index a9bd7a44..00000000 --- a/src/repository/world/components/PlaneLightComponent.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include "PlaneLightComponent.h" -#include "../../../context/ApplicationContext.h" - -namespace Metal { - void PlaneLightComponent::registerFields() { - registerColor(color, "", "Color"); - registerFloat(intensity, "", "Intensity", .1, 100); - } - - void PlaneLightComponent::onUpdate(InspectableMember *member) { - CTX.engineContext.setUpdateLights(true); - } -} // Metal diff --git a/src/repository/world/components/PlaneLightComponent.h b/src/repository/world/components/PlaneLightComponent.h deleted file mode 100644 index 8a7f1a16..00000000 --- a/src/repository/world/components/PlaneLightComponent.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef PLANELIGHTCOMPONENT_H -#define PLANELIGHTCOMPONENT_H - -#include "../impl/AbstractComponent.h" -#include "../../../util/Serializable.h" -#include - -namespace Metal { - struct PlaneLightComponent final : AbstractComponent, Serializable { - glm::vec3 color = glm::vec3(1.0f); - float intensity = 1.0f; - - void registerFields() override; - - ComponentType getType() override { - return ComponentType::PLANE_LIGHT; - } - - void onUpdate(InspectableMember *member) override; - - nlohmann::json toJson() const override { - nlohmann::json j; - j["entityId"] = entityId; - j["color"] = {color.x, color.y, color.z}; - j["intensity"] = intensity; - j["lightType"] = "PLANE"; - return j; - } - - void fromJson(const nlohmann::json &j) override { - entityId = j.at("entityId").get(); - color.x = j.at("color")[0].get(); - color.y = j.at("color")[1].get(); - color.z = j.at("color")[2].get(); - intensity = j.at("intensity").get(); - } - }; -} // Metal -#endif //PLANELIGHTCOMPONENT_H diff --git a/src/repository/world/components/SphereLightComponent.cpp b/src/repository/world/components/SphereLightComponent.cpp deleted file mode 100644 index 8e8eed06..00000000 --- a/src/repository/world/components/SphereLightComponent.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include "SphereLightComponent.h" -#include "../../../context/ApplicationContext.h" - -namespace Metal { - void SphereLightComponent::registerFields() { - registerColor(color, "", "Color"); - registerFloat(intensity, "", "Intensity", .1, 100); - registerFloat(radiusSize, "", "Radius", .1, 10); - } - - void SphereLightComponent::onUpdate(InspectableMember *member) { - CTX.engineContext.setUpdateLights(true); - } -} // Metal diff --git a/src/repository/world/components/SphereLightComponent.h b/src/repository/world/components/SphereLightComponent.h deleted file mode 100644 index 9e5008c8..00000000 --- a/src/repository/world/components/SphereLightComponent.h +++ /dev/null @@ -1,43 +0,0 @@ -#ifndef SPHERELIGHTCOMPONENT_H -#define SPHERELIGHTCOMPONENT_H - -#include "../impl/AbstractComponent.h" -#include "../../../util/Serializable.h" -#include - -namespace Metal { - struct SphereLightComponent final : AbstractComponent, Serializable { - glm::vec3 color = glm::vec3(1.0f); - float intensity = 1.0f; - float radiusSize = 1; - - void registerFields() override; - - ComponentType getType() override { - return ComponentType::SPHERE_LIGHT; - } - - void onUpdate(InspectableMember *member) override; - - nlohmann::json toJson() const override { - nlohmann::json j; - j["entityId"] = entityId; - j["color"] = {color.x, color.y, color.z}; - j["intensity"] = intensity; - j["radiusSize"] = radiusSize; - j["lightType"] = "SPHERE"; - return j; - } - - void fromJson(const nlohmann::json& j) override { - entityId = j.at("entityId").get(); - color.x = j.at("color")[0].get(); - color.y = j.at("color")[1].get(); - color.z = j.at("color")[2].get(); - intensity = j.at("intensity").get(); - radiusSize = j.at("radiusSize").get(); - } - }; -} // Metal - -#endif //SPHERELIGHTCOMPONENT_H diff --git a/src/repository/world/components/TransformComponent.cpp b/src/repository/world/components/TransformComponent.cpp index 9efa5cd7..73104008 100644 --- a/src/repository/world/components/TransformComponent.cpp +++ b/src/repository/world/components/TransformComponent.cpp @@ -1,8 +1,5 @@ #include "TransformComponent.h" #include "VolumeComponent.h" -#include "SphereLightComponent.h" -#include "PlaneLightComponent.h" -#include "../../../common/interface/Icons.h" #include "../../../context/ApplicationContext.h" #define ROTATION "Rotation" @@ -20,11 +17,6 @@ namespace Metal { } void TransformComponent::onUpdate(InspectableMember *member) { - bool isLight = CTX.worldRepository.registry.all_of(entityId) || - CTX.worldRepository.registry.all_of(entityId); - if (isLight) { - CTX.engineContext.setUpdateLights(true); - } if (member != nullptr && member->name == ROTATION) { rotation = normalize(glm::quat(rotationEuler * (glm::pi() / 180.f))); } diff --git a/src/repository/world/components/VolumeComponent.cpp b/src/repository/world/components/VolumeComponent.cpp index 924594e5..e0f7b99d 100644 --- a/src/repository/world/components/VolumeComponent.cpp +++ b/src/repository/world/components/VolumeComponent.cpp @@ -3,12 +3,14 @@ namespace Metal { void VolumeComponent::registerFields() { + registerColor(albedo, "", "Albedo"); + registerFloat(density, "", "Density", .1, 10); + registerFloat(g, "", "Phase function asymmetry (0.0 for isotropic)", 0); + registerFloat(scatteringAlbedo, "", "Scattering albedo", 0); + registerInt(samples, "", "Samples", 1); } ComponentType VolumeComponent::getType() { return VOLUME; } - - void VolumeComponent::onUpdate(InspectableMember *member) { - } } // Metal diff --git a/src/repository/world/components/VolumeComponent.h b/src/repository/world/components/VolumeComponent.h index fc30abd2..4ea910c8 100644 --- a/src/repository/world/components/VolumeComponent.h +++ b/src/repository/world/components/VolumeComponent.h @@ -6,23 +6,35 @@ #include namespace Metal { - // TODO - (VDB) SVO BASED VOLUMES struct VolumeComponent final : AbstractComponent, Serializable { + glm::vec3 albedo = glm::vec3(1.0f); + float density = 1; + float g = 0; + float scatteringAlbedo = 5; + int samples = 64; void registerFields() override; ComponentType getType() override; - void onUpdate(InspectableMember *member) override; - nlohmann::json toJson() const override { nlohmann::json j; j["entityId"] = entityId; + j["albedo"] = {albedo.x, albedo.y, albedo.z}; + j["density"] = density; + j["g"] = g; + j["scatteringAlbedo"] = scatteringAlbedo; + j["samples"] = samples; return j; } void fromJson(const nlohmann::json& j) override { entityId = j.at("entityId").get(); + albedo = {j.at("albedo")[0], j.at("albedo")[1], j.at("albedo")[2]}; + density = j.at("density").get(); + g = j.at("g").get(); + scatteringAlbedo = j.at("scatteringAlbedo").get(); + samples = j.at("samples").get(); } }; } // Metal diff --git a/src/service/camera/CameraService.cpp b/src/service/camera/CameraService.cpp index 2783a948..723c06d6 100644 --- a/src/service/camera/CameraService.cpp +++ b/src/service/camera/CameraService.cpp @@ -4,6 +4,8 @@ #include "../../context/ApplicationContext.h" namespace Metal { + // Per frame + // TODO - EVENT SYSTEM void CameraService::onSync() { camera = &CTX.worldRepository.camera; if (camera != nullptr) { diff --git a/src/service/dock/DockService.cpp b/src/service/dock/DockService.cpp index c2a992b1..ee1ab8e4 100644 --- a/src/service/dock/DockService.cpp +++ b/src/service/dock/DockService.cpp @@ -8,9 +8,6 @@ #include "../../context/ApplicationContext.h" namespace Metal { - DockService::DockService() : AbstractRuntimeComponent() { - } - void DockService::buildViews(ImGuiID windowId, AbstractPanel *panel) const { if (ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_DockingEnable) { DockRepository &dockRepository = CTX.dockRepository; @@ -39,45 +36,62 @@ namespace Metal { ImGui::DockBuilderRemoveNode(windowId); ImGui::DockBuilderAddNode(windowId, ImGuiDockNodeFlags_NoTabBar); ImGui::DockBuilderSetNodeSize(windowId, ImGui::GetMainViewport()->Size); - { - dockRepository.top.direction = TOP; - dockRepository.top.origin = nullptr; - dockRepository.top.outAtOppositeDir = nullptr; - dockRepository.top.splitDir = ImGuiDir_Right; - createDockSpace(&dockRepository.top, &windowId); - addWindow(&dockRepository.top, panel); + const auto &left = dockRepository.left; + for (size_t i = 0; i < left.size(); i++) { + DockDTO *dockSpace = left[i]; + if (i == 0) { + dockSpace->origin = nullptr; + dockSpace->outAtOppositeDir = nullptr; + dockSpace->splitDir = ImGuiDir_Left; + } else { + DockDTO *previous = left[i - 1]; + dockSpace->origin = previous; + dockSpace->outAtOppositeDir = previous; + dockSpace->splitDir = ImGuiDir_Down; + } + createDockSpace(dockSpace, &windowId); + addWindow(dockSpace, panel); } - { - dockRepository.rightTop.origin = &dockRepository.top; - dockRepository.rightTop.outAtOppositeDir = &dockRepository.top; - dockRepository.rightTop.splitDir = ImGuiDir_Down; - dockRepository.rightTop.direction = RIGHT_TOP; - createDockSpace(&dockRepository.rightTop, &windowId); - addWindow(&dockRepository.rightTop, panel); + const auto &right = dockRepository.right; + for (size_t i = 0; i < right.size(); i++) { + DockDTO *dockSpace = right[i]; + if (i == 0) { + dockSpace->origin = nullptr; + dockSpace->outAtOppositeDir = nullptr; + dockSpace->splitDir = ImGuiDir_Right; + } else { + DockDTO *previous = right[i - 1]; + dockSpace->origin = previous; + dockSpace->outAtOppositeDir = previous; + dockSpace->splitDir = ImGuiDir_Down; + } + createDockSpace(dockSpace, &windowId); + addWindow(dockSpace, panel); } - { - dockRepository.rightBottom.origin = &dockRepository.rightTop; - dockRepository.rightBottom.outAtOppositeDir = &dockRepository.rightTop; - - dockRepository.rightBottom.splitDir = ImGuiDir_Down; - dockRepository.rightBottom.direction = RIGHT_BOTTOM; - createDockSpace(&dockRepository.rightBottom, &windowId); - addWindow(&dockRepository.rightBottom, panel); + const auto &bottom = dockRepository.bottom; + for (size_t i = 0, bottomSize = bottom.size(); i < bottomSize; i++) { + DockDTO *dockSpace = bottom[i]; + if (i == 0) { + dockSpace->origin = nullptr; + dockSpace->outAtOppositeDir = nullptr; + dockSpace->splitDir = ImGuiDir_Down; + } else { + DockDTO *previous = bottom[i - 1]; + dockSpace->origin = previous; + dockSpace->outAtOppositeDir = previous; + dockSpace->splitDir = ImGuiDir_Right; + } + createDockSpace(dockSpace, &windowId); + addWindow(dockSpace, panel); } - { - dockRepository.bottom.origin = nullptr; - dockRepository.bottom.outAtOppositeDir = nullptr; - dockRepository.bottom.splitDir = ImGuiDir_Down; + dockRepository.center.nodeId = windowId; + addWindow(&dockRepository.center, panel); - dockRepository.bottom.direction = BOTTOM; - createDockSpace(&dockRepository.bottom, &windowId); - addWindow(&dockRepository.bottom, panel); - } - ImGui::DockBuilderDockWindow(dockRepository.top.internalId.c_str(), windowId); + ImGui::DockBuilderDockWindow(dockRepository.center.internalId.c_str(), windowId); ImGui::DockBuilderFinish(windowId); } } diff --git a/src/service/dock/DockService.h b/src/service/dock/DockService.h index 7b97a22f..fe3c9cfd 100644 --- a/src/service/dock/DockService.h +++ b/src/service/dock/DockService.h @@ -16,8 +16,6 @@ namespace Metal { static void createDockSpace(DockDTO *dockSpace, ImGuiID *dockMainId); static void addWindow(DockDTO *d, AbstractPanel *panel); - - explicit DockService(); }; } // Metal diff --git a/src/service/lights/LightService.cpp b/src/service/lights/LightService.cpp index 53c0e2bc..2ce80c93 100644 --- a/src/service/lights/LightService.cpp +++ b/src/service/lights/LightService.cpp @@ -1,75 +1,56 @@ #include "LightService.h" -#include #include "../../context/ApplicationContext.h" -#include "../../repository/world/components/SphereLightComponent.h" -#include "../../repository/world/components/PlaneLightComponent.h" #include "../buffer/BufferInstance.h" #include "../../enum/EngineResourceIDs.h" -#include "../../enum/LightType.h" -#include "../../repository/world/components/AtmosphereComponent.h" - namespace Metal { void LightService::registerLights() { - auto sphereView = CTX.worldRepository.registry.view(); - for (auto [entityId, l, t]: sphereView.each()) { - if (CTX.worldRepository.hiddenEntities.contains(entityId)) { - continue; - } - items.push_back(LightData( - glm::vec4(l.color, l.intensity), - t.translation, - glm::vec3(0), - glm::vec3(l.radiusSize), - LightTypes::LightType::SPHERE - )); - } - - auto planeView = CTX.worldRepository.registry.view(); - for (auto [entityId, l, t]: planeView.each()) { - if (CTX.worldRepository.hiddenEntities.contains(entityId)) { - continue; - } - glm::vec3 normal(0.0f, 1.0f, 0.0f); - glm::vec3 rotatedNormal = t.rotation * normal; - - items.push_back(LightData( - glm::vec4(l.color, l.intensity), - t.translation, - glm::normalize(rotatedNormal), - glm::vec3(t.scale), - LightTypes::LightType::PLANE - )); - } - } - void LightService::registerSun() { - auto view = CTX.worldRepository.registry.view(); - if (auto it = view.begin(); it != view.end()) { - auto &atmo = CTX.worldRepository.registry.get(*it); - if (atmo.atmosphereEnabled) { - items.push_back(LightData( - glm::vec4(atmo.sunColor, atmo.sunLightIntensity), - atmo.sunPosition, - glm::vec3(0), - glm::vec3(atmo.sunRadius), - LightTypes::LightType::SPHERE - )); - } - } } + // TODO - ADD EVENT SYSTEM THAT TRIGGERS THIS UPDATE void LightService::onSync() { items.clear(); - registerSun(); registerLights(); - if (items.empty()) { - return; + + if (!items.empty()) { + CTX.engineContext.currentFrame->getResourceAs(RID_LIGHT_BUFFER)->update(items.data()); } + } + + void LightService::computeSunInfo() { + sunPosition = glm::vec3(0, + std::cos(CTX.engineRepository.elapsedTime), + std::sin(CTX.engineRepository.elapsedTime)) * CTX.engineRepository + .sunDistance; + sunColor = LightService::CalculateSunColor( + sunPosition.y / CTX.engineRepository.sunDistance, + CTX.engineRepository.nightColor, CTX.engineRepository.dawnColor, + CTX.engineRepository.middayColor); + } - for (auto *frame: CTX.engineContext.registeredFrames) { - frame->getResourceAs(RID_LIGHT_BUFFER)->update(items.data()); + glm::vec3 LightService::CalculateSunColor(const float elevation, glm::vec3 &nightColor, glm::vec3 &dawnColor, + glm::vec3 &middayColor) { + if (elevation <= -0.1f) { + return nightColor; + } + if (elevation <= 0.0f) { + float t = (elevation + 0.1f) / 0.1f; + return BlendColors(nightColor, dawnColor, t); } + if (elevation <= 0.5f) { + float t = elevation / 0.5f; + return BlendColors(dawnColor, middayColor, t); + } + return middayColor; + } + + glm::vec3 LightService::BlendColors(glm::vec3 &c1, glm::vec3 &c2, float t) { + return { + (c1.x * (1 - t) + c2.x * t), + (c1.y * (1 - t) + c2.y * t), + (c1.z * (1 - t) + c2.z * t) + }; } } // Metal diff --git a/src/service/lights/LightService.h b/src/service/lights/LightService.h index fb6de0d6..35a71ace 100644 --- a/src/service/lights/LightService.h +++ b/src/service/lights/LightService.h @@ -8,14 +8,29 @@ namespace Metal { class LightService final : public AbstractRuntimeComponent { std::vector items{}; + glm::vec3 sunColor{}; + glm::vec3 sunPosition{}; void registerLights(); - void registerSun(); + static glm::vec3 CalculateSunColor(float elevation, glm::vec3 &nightColor, glm::vec3 &dawnColor, + glm::vec3 &middayColor); + + static glm::vec3 BlendColors(glm::vec3 &c1, glm::vec3 &c2, float t); public: void onSync() override; + void computeSunInfo(); + + [[nodiscard]] glm::vec3 getSunPosition() const { + return sunPosition; + } + + [[nodiscard]] glm::vec3 getSunColor() const { + return sunColor; + } + unsigned int getCount() const { return items.size(); } diff --git a/src/service/mesh/SceneEntityData.h b/src/service/mesh/SceneEntityData.h index 8c85068f..0e60b9f8 100644 --- a/src/service/mesh/SceneEntityData.h +++ b/src/service/mesh/SceneEntityData.h @@ -2,8 +2,6 @@ #define METAL_ENGINE_SCENEENTITYDATA_H #include #include "../../repository/world/components/PrimitiveComponent.h" -#include "../../repository/world/components/SphereLightComponent.h" -#include "../../repository/world/components/PlaneLightComponent.h" #include "../../repository/world/components/TransformComponent.h" #include "../../repository/world/impl/MetadataComponent.h" @@ -13,16 +11,12 @@ namespace Metal { MetadataComponent entity; TransformComponent transform; std::optional primitive; - std::optional sphereLight; - std::optional planeLight; nlohmann::json toJson() const override { nlohmann::json j; j["entity"] = entity.toJson(); j["transform"] = transform.toJson(); if (primitive) j["primitive"] = primitive->toJson(); - if (sphereLight) j["sphereLight"] = sphereLight->toJson(); - if (planeLight) j["planeLight"] = planeLight->toJson(); return j; } @@ -33,14 +27,6 @@ namespace Metal { primitive = PrimitiveComponent(); primitive->fromJson(j.at("primitive")); } - if (j.contains("sphereLight")) { - sphereLight = SphereLightComponent(); - sphereLight->fromJson(j.at("sphereLight")); - } - if (j.contains("planeLight")) { - planeLight = PlaneLightComponent(); - planeLight->fromJson(j.at("planeLight")); - } } }; } diff --git a/src/service/mesh/SceneImporterService.cpp b/src/service/mesh/SceneImporterService.cpp index cb265749..08144c8a 100644 --- a/src/service/mesh/SceneImporterService.cpp +++ b/src/service/mesh/SceneImporterService.cpp @@ -14,8 +14,6 @@ #include "../../context/ApplicationContext.h" #include "../../util/serialization-definitions.h" #include "../../dto/file/SceneImportSettingsDTO.h" -#include "../../repository/world/components/SphereLightComponent.h" -#include "../../repository/world/components/PlaneLightComponent.h" namespace Metal { std::string SceneImporterService::importData(const std::string &targetDir, const std::string &pathToFile, @@ -24,8 +22,7 @@ namespace Metal { Assimp::Importer importer; unsigned int flags = aiProcess_GlobalScale | aiProcess_FindInstances | aiProcess_PreTransformVertices; - auto sceneSettings = std::dynamic_pointer_cast(settings); - if (sceneSettings) { + if (auto sceneSettings = std::dynamic_pointer_cast(settings)) { if (sceneSettings->triangulate) flags |= aiProcess_Triangulate; if (sceneSettings->flipUVs) flags |= aiProcess_FlipUVs; if (sceneSettings->genSmoothNormals) flags |= aiProcess_GenSmoothNormals; @@ -78,7 +75,7 @@ namespace Metal { std::vector entities{}; for (SceneEntityData &entity: sceneData.entities) { - if (!entity.primitive && !entity.planeLight && !entity.sphereLight) { + if (!entity.primitive) { continue; } entities.push_back(entity); @@ -145,16 +142,6 @@ namespace Metal { auto &lightNode = scene.entities.emplace_back(); lightNode.entity.name = light->mName.data; lightNode.transform.translation = {light->mPosition.x, light->mPosition.y, light->mPosition.z}; - - if (light->mType == aiLightSource_POINT) { - lightNode.sphereLight = SphereLightComponent(); - lightNode.sphereLight->color = {light->mColorDiffuse.r, light->mColorDiffuse.g, light->mColorDiffuse.b}; - lightNode.sphereLight->intensity = 1.0f; - } else if (light->mType == aiLightSource_DIRECTIONAL || light->mType == aiLightSource_AREA) { - lightNode.planeLight = PlaneLightComponent(); - lightNode.planeLight->color = {light->mColorDiffuse.r, light->mColorDiffuse.g, light->mColorDiffuse.b}; - lightNode.planeLight->intensity = 1.0f; - } } } diff --git a/src/service/raytracing/RayTracingService.cpp b/src/service/raytracing/RayTracingService.cpp index 40ed64e7..fd2b6de0 100644 --- a/src/service/raytracing/RayTracingService.cpp +++ b/src/service/raytracing/RayTracingService.cpp @@ -33,6 +33,8 @@ namespace Metal { } } } + + // TODO - EVENT SYSTEM BASED ON WORLD CHANGE AND ENTITY CHANGE void RayTracingService::onSync() { if (needsMaterialUpdate) { updateMeshMaterials(); diff --git a/src/service/volumes/VolumeService.cpp b/src/service/volumes/VolumeService.cpp new file mode 100644 index 00000000..5c03305b --- /dev/null +++ b/src/service/volumes/VolumeService.cpp @@ -0,0 +1,36 @@ +#include "VolumeService.h" +#include "../../context/ApplicationContext.h" +#include "../../repository/world/components/VolumeComponent.h" +#include "../buffer/BufferInstance.h" +#include "../../enum/EngineResourceIDs.h" + +namespace Metal { + void VolumeService::registerVolumes() { + auto view = CTX.worldRepository.registry.view(); + for (auto [entityId, l, t]: view.each()) { + if (CTX.worldRepository.hiddenEntities.contains(entityId)) { + continue; + } + + auto &translation = t.translation; + + items.push_back(VolumeData( + glm::vec4(l.albedo, l.samples), + translation, + t.scale, + glm::vec3(l.density, l.scatteringAlbedo, l.g) + )); + } + } + + // TODO - ADD EVENT SYSTEM THAT TRIGGERS THIS UPDATE + void VolumeService::onSync() { + items.clear(); + + registerVolumes(); + + if (!items.empty()) { + CTX.engineContext.currentFrame->getResourceAs(RID_VOLUMES_BUFFER)->update(items.data()); + } + } +} // Metal diff --git a/src/service/volumes/VolumeService.h b/src/service/volumes/VolumeService.h new file mode 100644 index 00000000..c2377b45 --- /dev/null +++ b/src/service/volumes/VolumeService.h @@ -0,0 +1,24 @@ +#ifndef VOLUME_SERVICE_H +#define VOLUME_SERVICE_H +#include + +#include "../../common/AbstractRuntimeComponent.h" +#include "../../dto/buffers/VolumeData.h" + +namespace Metal { + + class VolumeService final : public AbstractRuntimeComponent { + std::vector items{}; + + void registerVolumes(); + public: + + void onSync() override; + + unsigned int getCount() const { + return items.size(); + } + }; +} // Metal + +#endif //LIGHTSSERVICE_H From 1fcbd1f4452a48dd097e84d9004305d291f009f3 Mon Sep 17 00:00:00 2001 From: facobackup Date: Thu, 12 Mar 2026 21:12:41 -0300 Subject: [PATCH 08/18] Moving files around --- CMakeLists.txt | 550 +++++++++--------- src/{context => }/ApplicationContext.cpp | 10 +- src/{context => }/ApplicationContext.h | 66 +-- .../AbstractCoreRepository.h | 2 +- .../abstract => common}/AbstractImporter.h | 4 +- .../AbstractResourceService.h | 4 +- src/common/AbstractRuntimeComponent.h | 6 +- src/common/{interface => }/Changeable.h | 0 src/{enum => common}/FieldType.h | 0 src/common/{interface => }/Icons.h | 0 src/common/{interface => }/Initializable.h | 0 src/common/{inspection => }/Inspectable.cpp | 10 +- src/common/{inspection => }/Inspectable.h | 6 +- .../{inspection => }/InspectableMember.h | 2 +- src/common/{inspection => }/InspectedField.h | 2 +- src/common/{inspection => }/InspectedMethod.h | 0 src/{util => common}/Serializable.cpp | 6 +- src/{util => common}/Serializable.h | 0 src/common/{interface => }/Synchornizable.h | 0 src/{context => core}/glfw/GLFWContext.cpp | 2 +- src/{context => core}/glfw/GLFWContext.h | 0 src/{context => core}/gui/GuiContext.cpp | 6 +- src/{context => core}/gui/GuiContext.h | 0 .../vulkan/VulkanContext.cpp | 2 +- src/{context => core}/vulkan/VulkanContext.h | 0 src/{util => core/vulkan}/VulkanUtils.cpp | 8 +- src/{util => core/vulkan}/VulkanUtils.h | 0 src/{context => }/editor/EditorPanel.cpp | 4 +- src/{context => }/editor/EditorPanel.h | 0 .../editor/abstract/AbstractPanel.cpp | 2 +- .../editor/abstract/AbstractPanel.h | 0 src/{context => }/editor/abstract/IPanel.h | 4 +- .../abstract/form/AbstractFormFieldPanel.h | 0 .../editor/abstract/form/AccordionPanel.cpp | 0 .../editor/abstract/form/AccordionPanel.h | 0 .../editor/abstract/form/ChildPanel.cpp | 0 .../editor/abstract/form/ChildPanel.h | 0 .../editor/abstract/form/FormPanel.cpp | 4 +- .../editor/abstract/form/FormPanel.h | 0 .../abstract/form/types/BooleanField.cpp | 2 +- .../editor/abstract/form/types/BooleanField.h | 2 +- .../editor/abstract/form/types/ColorField.cpp | 2 +- .../editor/abstract/form/types/ColorField.h | 2 +- .../editor/abstract/form/types/FloatField.cpp | 2 +- .../editor/abstract/form/types/FloatField.h | 2 +- .../editor/abstract/form/types/IntField.cpp | 2 +- .../editor/abstract/form/types/IntField.h | 2 +- .../abstract/form/types/MethodField.cpp | 0 .../editor/abstract/form/types/MethodField.h | 2 +- .../editor/abstract/form/types/QuatField.cpp | 4 +- .../editor/abstract/form/types/QuatField.h | 2 +- .../abstract/form/types/ResourceField.cpp | 6 +- .../abstract/form/types/ResourceField.h | 2 +- .../form/types/ResourceFilesPanel.cpp | 6 +- .../abstract/form/types/ResourceFilesPanel.h | 0 .../abstract/form/types/StringField.cpp | 2 +- .../editor/abstract/form/types/StringField.h | 2 +- .../editor/abstract/form/types/Vec2Field.cpp | 4 +- .../editor/abstract/form/types/Vec2Field.h | 2 +- .../editor/abstract/form/types/Vec3Field.cpp | 4 +- .../editor/abstract/form/types/Vec3Field.h | 2 +- .../editor/abstract/form/types/Vec4Field.cpp | 4 +- .../editor/abstract/form/types/Vec4Field.h | 2 +- .../dock-spaces/console/ConsolePanel.cpp | 2 +- .../editor/dock-spaces/console/ConsolePanel.h | 2 +- .../dock-spaces/docks/AbstractDockPanel.h | 2 +- .../dock-spaces/docks/DockSpacePanel.cpp | 8 +- .../editor/dock-spaces/docks/DockSpacePanel.h | 0 .../dock-spaces/files/FilePreviewPanel.cpp | 6 +- .../dock-spaces/files/FilePreviewPanel.h | 0 .../editor/dock-spaces/files/FilesContext.cpp | 2 +- .../editor/dock-spaces/files/FilesContext.h | 2 +- .../dock-spaces/files/FilesHeaderPanel.cpp | 10 +- .../dock-spaces/files/FilesHeaderPanel.h | 0 .../dock-spaces/files/FilesListPanel.cpp | 6 +- .../editor/dock-spaces/files/FilesListPanel.h | 0 .../editor/dock-spaces/files/FilesPanel.cpp | 14 +- .../editor/dock-spaces/files/FilesPanel.h | 2 +- .../dock-spaces/header/AsyncTaskPanel.cpp | 2 +- .../dock-spaces/header/AsyncTaskPanel.h | 0 .../dock-spaces/header/EditorHeaderPanel.cpp | 2 +- .../dock-spaces/header/EditorHeaderPanel.h | 0 .../dock-spaces/inspector/InspectorPanel.cpp | 6 +- .../dock-spaces/inspector/InspectorPanel.h | 2 +- .../dock-spaces/metrics/MetricsPanel.cpp | 0 .../editor/dock-spaces/metrics/MetricsPanel.h | 0 .../repositories/RepositoriesPanel.cpp | 2 +- .../repositories/RepositoriesPanel.h | 0 .../viewport/CameraPositionPanel.cpp | 4 +- .../viewport/CameraPositionPanel.h | 0 .../dock-spaces/viewport/EngineFramePanel.cpp | 18 +- .../dock-spaces/viewport/EngineFramePanel.h | 0 .../dock-spaces/viewport/GizmoPanel.cpp | 4 +- .../editor/dock-spaces/viewport/GizmoPanel.h | 0 .../viewport/GizmoSettingsPanel.cpp | 2 +- .../dock-spaces/viewport/GizmoSettingsPanel.h | 2 +- .../viewport/ViewportHeaderPanel.cpp | 2 +- .../viewport/ViewportHeaderPanel.h | 0 .../dock-spaces/viewport/ViewportPanel.cpp | 4 +- .../dock-spaces/viewport/ViewportPanel.h | 0 .../dock-spaces/world/WorldHeaderPanel.cpp | 4 +- .../dock-spaces/world/WorldHeaderPanel.h | 0 .../editor/dock-spaces/world/WorldPanel.cpp | 8 +- .../editor/dock-spaces/world/WorldPanel.h | 4 +- .../notification => editor/dto}/AsyncTask.h | 0 src/{repository/dock => editor/dto}/DockDTO.h | 5 +- .../dock => editor/dto}/DockSpace.cpp | 18 +- .../dock => editor/dto}/DockSpace.h | 0 src/{dto/file => editor/dto}/EntryMetadata.h | 6 +- src/{dto/file => editor/dto}/FSEntry.h | 2 +- .../dto}/GridPushConstant.h | 0 .../file => editor/dto}/ImportSettingsDTO.h | 2 +- src/{ => editor}/dto/Notification.h | 0 .../voxel/impl => editor/dto}/OctreeNode.cpp | 2 +- .../voxel/impl => editor/dto}/OctreeNode.h | 2 +- src/{service/mesh => editor/dto}/SceneData.h | 2 +- .../mesh => editor/dto}/SceneEntityData.h | 6 +- .../dto}/SceneImportSettingsDTO.h | 0 .../dto}/SelectedDotPushConstant.h | 0 src/{ => editor}/dto/ShortcutDTO.h | 0 .../dto}/SparseVoxelOctreeBuilder.cpp | 2 +- .../dto}/SparseVoxelOctreeBuilder.h | 2 +- src/{ => editor}/enum/EngineResourceIDs.h | 0 src/{ => editor}/enum/EntryType.h | 0 src/{ => editor}/enum/NotificationSeverity.h | 2 +- src/{ => editor}/enum/ShadingMode.h | 2 +- src/{ => editor}/enum/engine-definitions.h | 2 +- .../editor/panel/FileImportModalPanel.cpp | 2 +- .../editor/panel/FileImportModalPanel.h | 0 .../editor/panel/NotificationsPanel.cpp | 4 +- .../editor/panel/NotificationsPanel.h | 0 .../impl/tools => editor/passes}/GridPass.cpp | 8 +- .../impl/tools => editor/passes}/GridPass.h | 4 +- .../tools => editor/passes}/IconsPass.cpp | 8 +- .../impl/tools => editor/passes}/IconsPass.h | 2 +- .../passes}/SelectionIDPass.cpp | 10 +- .../tools => editor/passes}/SelectionIDPass.h | 4 +- .../passes}/SelectionOutlinePass.cpp | 12 +- .../passes}/SelectionOutlinePass.h | 4 +- .../repository}/DockRepository.cpp | 2 +- .../repository}/DockRepository.h | 4 +- .../repository}/EditorRepository.cpp | 4 +- .../repository}/EditorRepository.h | 10 +- .../service}/AsyncTaskService.cpp | 6 +- .../service}/AsyncTaskService.h | 2 +- .../dock => editor/service}/DockService.cpp | 12 +- .../dock => editor/service}/DockService.h | 6 +- .../service}/FileImporterService.cpp | 6 +- .../service}/FileImporterService.h | 4 +- .../files => editor/service}/FilesService.cpp | 16 +- .../files => editor/service}/FilesService.h | 2 +- .../log => editor/service}/LogService.cpp | 2 +- .../log => editor/service}/LogService.h | 2 +- .../service}/MaterialImporterService.cpp | 6 +- .../service}/MaterialImporterService.h | 2 +- .../service}/MeshImporterService.cpp | 16 +- .../service}/MeshImporterService.h | 2 +- .../service}/NotificationService.cpp | 2 +- .../service}/NotificationService.h | 2 +- .../service}/PickingService.cpp | 8 +- .../service}/PickingService.h | 4 +- .../service}/SceneImporterService.cpp | 22 +- .../service}/SceneImporterService.h | 2 +- .../service}/SelectionService.cpp | 6 +- .../service}/SelectionService.h | 4 +- .../service}/TextureImporterService.cpp | 16 +- .../service}/TextureImporterService.h | 2 +- .../theme => editor/service}/ThemeService.cpp | 4 +- .../theme => editor/service}/ThemeService.h | 2 +- .../service}/VoxelImporterService.cpp | 16 +- .../service}/VoxelImporterService.h | 6 +- src/{ => editor}/util/FileDialogUtil.h | 4 +- src/{ => editor}/util/FilesUtil.h | 2 +- src/{ => editor}/util/UIUtil.h | 2 +- src/{ => editor}/util/Util.h | 0 .../util/serialization-definitions.h | 2 +- src/{context => }/engine/EngineContext.cpp | 8 +- src/{context => }/engine/EngineContext.h | 4 +- .../impl => engine/dto}/AbstractComponent.h | 4 +- .../dto}/AccumulationPushConstant.h | 0 .../world/impl => engine/dto}/BoundingBox.h | 2 +- src/{service/camera => engine/dto}/Camera.cpp | 4 +- src/{service/camera => engine/dto}/Camera.h | 4 +- .../dto}/DenoiserPushConstant.h | 0 .../dto}/DescriptorBinding.h | 0 .../dto}/DescriptorInstance.h | 4 +- .../buffers => engine/dto}/GlobalDataUBO.h | 0 .../dto}/HWRayTracingPushConstant.h | 0 src/{dto/buffers => engine/dto}/LightData.h | 0 src/{service/mesh => engine/dto}/MeshData.h | 2 +- .../buffers => engine/dto}/MeshMetadata.h | 0 .../impl => engine/dto}/MetadataComponent.cpp | 6 +- .../impl => engine/dto}/MetadataComponent.h | 8 +- .../dto}/PipelineBuilder.cpp | 4 +- .../pipeline => engine/dto}/PipelineBuilder.h | 2 +- .../dto}/PostProcessingPushConstant.h | 0 .../dto}/PrimitiveComponent.cpp | 8 +- .../dto}/PrimitiveComponent.h | 4 +- .../pipeline => engine/dto}/ShaderModule.cpp | 4 +- .../pipeline => engine/dto}/ShaderModule.h | 0 .../dto}/SparseVoxelOctreeData.h | 2 +- .../texture => engine/dto}/TextureData.h | 0 src/{dto/buffers => engine/dto}/TileInfoUBO.h | 0 .../dto}/TransformComponent.cpp | 6 +- .../dto}/TransformComponent.h | 4 +- src/{service/mesh => engine/dto}/VertexData.h | 2 +- .../dto}/VolumeComponent.cpp | 4 +- .../dto}/VolumeComponent.h | 4 +- src/{dto/buffers => engine/dto}/VolumeData.h | 0 .../voxel/impl => engine/dto}/VoxelData.h | 0 src/{ => engine}/enum/ComponentType.cpp | 6 +- src/{ => engine}/enum/ComponentType.h | 2 +- src/{ => engine}/enum/PassType.h | 0 src/{ => engine}/enum/ResourceType.h | 0 .../engine/frame-builder/EngineFrame.cpp | 0 .../engine/frame-builder/EngineFrame.h | 2 +- .../frame-builder/EngineFrameBuilder.cpp | 0 .../engine/frame-builder/EngineFrameBuilder.h | 4 +- .../structures/BufferBuilder.cpp | 4 +- .../frame-builder/structures/BufferBuilder.h | 2 +- .../CommandBufferRecorderBuilder.cpp | 0 .../structures/CommandBufferRecorderBuilder.h | 0 .../structures/FramebufferBuilder.cpp | 4 +- .../structures/FramebufferBuilder.h | 0 .../frame-builder/structures/PassBuilder.cpp | 6 +- .../frame-builder/structures/PassBuilder.h | 4 +- .../structures/ResourceBuilder.h | 2 +- .../structures/TextureBuilder.cpp | 2 +- .../frame-builder/structures/TextureBuilder.h | 0 .../passes}/AbstractComputePass.cpp | 10 +- .../passes}/AbstractComputePass.h | 2 +- .../engine/passes/AbstractPass.cpp | 2 +- .../engine/passes/AbstractPass.h | 2 +- .../passes}/AbstractRenderPass.cpp | 8 +- .../passes}/AbstractRenderPass.h | 2 +- .../engine/passes/CommandBufferRecorder.cpp | 8 +- .../engine/passes/CommandBufferRecorder.h | 6 +- .../passes}/impl/HWRayTracingPass.cpp | 14 +- .../passes}/impl/HWRayTracingPass.h | 2 +- .../passes}/impl/PostProcessingPass.cpp | 6 +- .../passes}/impl/PostProcessingPass.h | 2 +- .../passes}/impl/SpatialFilterPass.cpp | 8 +- .../passes}/impl/SpatialFilterPass.h | 0 .../passes}/impl/TemporalAccumulationPass.cpp | 8 +- .../passes}/impl/TemporalAccumulationPass.h | 0 .../repository}/EngineRepository.cpp | 6 +- .../repository}/EngineRepository.h | 4 +- .../repository}/ResourceRepository.h | 2 +- .../repository}/RuntimeRepository.h | 0 .../repository}/WorldRepository.cpp | 10 +- .../repository}/WorldRepository.h | 18 +- .../resource}/BufferInstance.cpp | 10 +- .../resource}/BufferInstance.h | 2 +- .../resource}/FrameBufferAttachment.cpp | 4 +- .../resource}/FrameBufferAttachment.h | 2 +- .../resource}/FrameBufferInstance.h | 2 +- .../mesh => engine/resource}/MeshInstance.h | 2 +- .../resource}/PipelineInstance.h | 4 +- .../resource}/RuntimeResource.h | 4 +- .../voxel => engine/resource}/SVOInstance.h | 4 +- .../resource}/TextureInstance.h | 6 +- .../service}/BufferService.cpp | 8 +- .../buffer => engine/service}/BufferService.h | 4 +- .../service}/CameraService.cpp | 6 +- .../camera => engine/service}/CameraService.h | 2 +- .../service}/CommandBufferRecorderService.h | 4 +- .../service}/DescriptorSetService.cpp | 18 +- .../service}/DescriptorSetService.h | 4 +- .../service}/FrameBufferService.cpp | 8 +- .../service}/FrameBufferService.h | 4 +- .../service}/LightService.cpp | 8 +- .../lights => engine/service}/LightService.h | 4 +- .../service}/MaterialService.cpp | 8 +- .../service}/MaterialService.h | 0 .../mesh => engine/service}/MeshService.cpp | 20 +- .../mesh => engine/service}/MeshService.h | 6 +- .../service}/PipelineService.cpp | 22 +- .../service}/PipelineService.h | 6 +- .../service}/RayTracingService.cpp | 18 +- .../service}/RayTracingService.h | 6 +- .../service}/StreamingService.cpp | 12 +- .../service}/StreamingService.h | 6 +- .../service}/TextureService.cpp | 12 +- .../service}/TextureService.h | 6 +- .../service}/TransformService.cpp | 6 +- .../service}/TransformService.h | 4 +- .../service}/VolumeService.cpp | 10 +- .../service}/VolumeService.h | 4 +- .../voxel => engine/service}/VoxelService.cpp | 4 +- .../voxel => engine/service}/VoxelService.h | 4 +- src/{ => engine}/util/ImageUtils.h | 0 src/{ => engine}/util/ShaderUtil.cpp | 20 +- src/{ => engine}/util/ShaderUtil.h | 2 +- src/enum/LightType.h | 19 - src/main.cpp | 2 +- src/repository/dock/DockPosition.h | 14 - 296 files changed, 867 insertions(+), 907 deletions(-) rename src/{context => }/ApplicationContext.cpp (96%) rename src/{context => }/ApplicationContext.h (69%) rename src/{repository/abstract => common}/AbstractCoreRepository.h (86%) rename src/{service/abstract => common}/AbstractImporter.h (91%) rename src/{service/abstract => common}/AbstractResourceService.h (94%) rename src/common/{interface => }/Changeable.h (100%) rename src/{enum => common}/FieldType.h (100%) rename src/common/{interface => }/Icons.h (100%) rename src/common/{interface => }/Initializable.h (100%) rename src/common/{inspection => }/Inspectable.cpp (95%) rename src/common/{inspection => }/Inspectable.h (97%) rename src/common/{inspection => }/InspectableMember.h (92%) rename src/common/{inspection => }/InspectedField.h (92%) rename src/common/{inspection => }/InspectedMethod.h (100%) rename src/{util => common}/Serializable.cpp (86%) rename src/{util => common}/Serializable.h (100%) rename src/common/{interface => }/Synchornizable.h (100%) rename src/{context => core}/glfw/GLFWContext.cpp (99%) rename src/{context => core}/glfw/GLFWContext.h (100%) rename src/{context => core}/gui/GuiContext.cpp (97%) rename src/{context => core}/gui/GuiContext.h (100%) rename src/{context => core}/vulkan/VulkanContext.cpp (99%) rename src/{context => core}/vulkan/VulkanContext.h (100%) rename src/{util => core/vulkan}/VulkanUtils.cpp (90%) rename src/{util => core/vulkan}/VulkanUtils.h (100%) rename src/{context => }/editor/EditorPanel.cpp (97%) rename src/{context => }/editor/EditorPanel.h (100%) rename src/{context => }/editor/abstract/AbstractPanel.cpp (95%) rename src/{context => }/editor/abstract/AbstractPanel.h (100%) rename src/{context => }/editor/abstract/IPanel.h (67%) rename src/{context => }/editor/abstract/form/AbstractFormFieldPanel.h (100%) rename src/{context => }/editor/abstract/form/AccordionPanel.cpp (100%) rename src/{context => }/editor/abstract/form/AccordionPanel.h (100%) rename src/{context => }/editor/abstract/form/ChildPanel.cpp (100%) rename src/{context => }/editor/abstract/form/ChildPanel.h (100%) rename src/{context => }/editor/abstract/form/FormPanel.cpp (97%) rename src/{context => }/editor/abstract/form/FormPanel.h (100%) rename src/{context => }/editor/abstract/form/types/BooleanField.cpp (93%) rename src/{context => }/editor/abstract/form/types/BooleanField.h (86%) rename src/{context => }/editor/abstract/form/types/ColorField.cpp (95%) rename src/{context => }/editor/abstract/form/types/ColorField.h (88%) rename src/{context => }/editor/abstract/form/types/FloatField.cpp (94%) rename src/{context => }/editor/abstract/form/types/FloatField.h (86%) rename src/{context => }/editor/abstract/form/types/IntField.cpp (94%) rename src/{context => }/editor/abstract/form/types/IntField.h (86%) rename src/{context => }/editor/abstract/form/types/MethodField.cpp (100%) rename src/{context => }/editor/abstract/form/types/MethodField.h (86%) rename src/{context => }/editor/abstract/form/types/QuatField.cpp (93%) rename src/{context => }/editor/abstract/form/types/QuatField.h (88%) rename src/{context => }/editor/abstract/form/types/ResourceField.cpp (96%) rename src/{context => }/editor/abstract/form/types/ResourceField.h (92%) rename src/{context => }/editor/abstract/form/types/ResourceFilesPanel.cpp (79%) rename src/{context => }/editor/abstract/form/types/ResourceFilesPanel.h (100%) rename src/{context => }/editor/abstract/form/types/StringField.cpp (94%) rename src/{context => }/editor/abstract/form/types/StringField.h (87%) rename src/{context => }/editor/abstract/form/types/Vec2Field.cpp (91%) rename src/{context => }/editor/abstract/form/types/Vec2Field.h (88%) rename src/{context => }/editor/abstract/form/types/Vec3Field.cpp (92%) rename src/{context => }/editor/abstract/form/types/Vec3Field.h (88%) rename src/{context => }/editor/abstract/form/types/Vec4Field.cpp (92%) rename src/{context => }/editor/abstract/form/types/Vec4Field.h (88%) rename src/{context => }/editor/dock-spaces/console/ConsolePanel.cpp (98%) rename src/{context => }/editor/dock-spaces/console/ConsolePanel.h (88%) rename src/{context => }/editor/dock-spaces/docks/AbstractDockPanel.h (93%) rename src/{context => }/editor/dock-spaces/docks/DockSpacePanel.cpp (97%) rename src/{context => }/editor/dock-spaces/docks/DockSpacePanel.h (100%) rename src/{context => }/editor/dock-spaces/files/FilePreviewPanel.cpp (96%) rename src/{context => }/editor/dock-spaces/files/FilePreviewPanel.h (100%) rename src/{context => }/editor/dock-spaces/files/FilesContext.cpp (91%) rename src/{context => }/editor/dock-spaces/files/FilesContext.h (94%) rename src/{context => }/editor/dock-spaces/files/FilesHeaderPanel.cpp (89%) rename src/{context => }/editor/dock-spaces/files/FilesHeaderPanel.h (100%) rename src/{context => }/editor/dock-spaces/files/FilesListPanel.cpp (98%) rename src/{context => }/editor/dock-spaces/files/FilesListPanel.h (100%) rename src/{context => }/editor/dock-spaces/files/FilesPanel.cpp (95%) rename src/{context => }/editor/dock-spaces/files/FilesPanel.h (95%) rename src/{context => }/editor/dock-spaces/header/AsyncTaskPanel.cpp (98%) rename src/{context => }/editor/dock-spaces/header/AsyncTaskPanel.h (100%) rename src/{context => }/editor/dock-spaces/header/EditorHeaderPanel.cpp (98%) rename src/{context => }/editor/dock-spaces/header/EditorHeaderPanel.h (100%) rename src/{context => }/editor/dock-spaces/inspector/InspectorPanel.cpp (94%) rename src/{context => }/editor/dock-spaces/inspector/InspectorPanel.h (91%) rename src/{context => }/editor/dock-spaces/metrics/MetricsPanel.cpp (100%) rename src/{context => }/editor/dock-spaces/metrics/MetricsPanel.h (100%) rename src/{context => }/editor/dock-spaces/repositories/RepositoriesPanel.cpp (91%) rename src/{context => }/editor/dock-spaces/repositories/RepositoriesPanel.h (100%) rename src/{context => }/editor/dock-spaces/viewport/CameraPositionPanel.cpp (94%) rename src/{context => }/editor/dock-spaces/viewport/CameraPositionPanel.h (100%) rename src/{context => }/editor/dock-spaces/viewport/EngineFramePanel.cpp (92%) rename src/{context => }/editor/dock-spaces/viewport/EngineFramePanel.h (100%) rename src/{context => }/editor/dock-spaces/viewport/GizmoPanel.cpp (97%) rename src/{context => }/editor/dock-spaces/viewport/GizmoPanel.h (100%) rename src/{context => }/editor/dock-spaces/viewport/GizmoSettingsPanel.cpp (99%) rename src/{context => }/editor/dock-spaces/viewport/GizmoSettingsPanel.h (96%) rename src/{context => }/editor/dock-spaces/viewport/ViewportHeaderPanel.cpp (98%) rename src/{context => }/editor/dock-spaces/viewport/ViewportHeaderPanel.h (100%) rename src/{context => }/editor/dock-spaces/viewport/ViewportPanel.cpp (98%) rename src/{context => }/editor/dock-spaces/viewport/ViewportPanel.h (100%) rename src/{context => }/editor/dock-spaces/world/WorldHeaderPanel.cpp (95%) rename src/{context => }/editor/dock-spaces/world/WorldHeaderPanel.h (100%) rename src/{context => }/editor/dock-spaces/world/WorldPanel.cpp (97%) rename src/{context => }/editor/dock-spaces/world/WorldPanel.h (94%) rename src/{service/notification => editor/dto}/AsyncTask.h (100%) rename src/{repository/dock => editor/dto}/DockDTO.h (93%) rename src/{repository/dock => editor/dto}/DockSpace.cpp (70%) rename src/{repository/dock => editor/dto}/DockSpace.h (100%) rename src/{dto/file => editor/dto}/EntryMetadata.h (90%) rename src/{dto/file => editor/dto}/FSEntry.h (95%) rename src/{dto/push-constant => editor/dto}/GridPushConstant.h (100%) rename src/{dto/file => editor/dto}/ImportSettingsDTO.h (86%) rename src/{ => editor}/dto/Notification.h (100%) rename src/{service/voxel/impl => editor/dto}/OctreeNode.cpp (94%) rename src/{service/voxel/impl => editor/dto}/OctreeNode.h (97%) rename src/{service/mesh => editor/dto}/SceneData.h (95%) rename src/{service/mesh => editor/dto}/SceneEntityData.h (83%) rename src/{dto/file => editor/dto}/SceneImportSettingsDTO.h (100%) rename src/{dto/push-constant => editor/dto}/SelectedDotPushConstant.h (100%) rename src/{ => editor}/dto/ShortcutDTO.h (100%) rename src/{service/voxel/impl => editor/dto}/SparseVoxelOctreeBuilder.cpp (97%) rename src/{service/voxel/impl => editor/dto}/SparseVoxelOctreeBuilder.h (95%) rename src/{ => editor}/enum/EngineResourceIDs.h (100%) rename src/{ => editor}/enum/EntryType.h (100%) rename src/{ => editor}/enum/NotificationSeverity.h (96%) rename src/{ => editor}/enum/ShadingMode.h (98%) rename src/{ => editor}/enum/engine-definitions.h (97%) rename src/{context => }/editor/panel/FileImportModalPanel.cpp (99%) rename src/{context => }/editor/panel/FileImportModalPanel.h (100%) rename src/{context => }/editor/panel/NotificationsPanel.cpp (95%) rename src/{context => }/editor/panel/NotificationsPanel.h (100%) rename src/{context/engine/render-pass/impl/tools => editor/passes}/GridPass.cpp (85%) rename src/{context/engine/render-pass/impl/tools => editor/passes}/GridPass.h (80%) rename src/{context/engine/render-pass/impl/tools => editor/passes}/IconsPass.cpp (79%) rename src/{context/engine/render-pass/impl/tools => editor/passes}/IconsPass.h (87%) rename src/{context/engine/render-pass/impl/tools => editor/passes}/SelectionIDPass.cpp (86%) rename src/{context/engine/render-pass/impl/tools => editor/passes}/SelectionIDPass.h (80%) rename src/{context/engine/render-pass/impl/tools => editor/passes}/SelectionOutlinePass.cpp (77%) rename src/{context/engine/render-pass/impl/tools => editor/passes}/SelectionOutlinePass.h (80%) rename src/{repository/dock => editor/repository}/DockRepository.cpp (94%) rename src/{repository/dock => editor/repository}/DockRepository.h (84%) rename src/{repository/editor => editor/repository}/EditorRepository.cpp (98%) rename src/{repository/editor => editor/repository}/EditorRepository.h (91%) rename src/{service/notification => editor/service}/AsyncTaskService.cpp (92%) rename src/{service/notification => editor/service}/AsyncTaskService.h (95%) rename src/{service/dock => editor/service}/DockService.cpp (94%) rename src/{service/dock => editor/service}/DockService.h (73%) rename src/{service/files => editor/service}/FileImporterService.cpp (96%) rename src/{service/files => editor/service}/FileImporterService.h (86%) rename src/{service/files => editor/service}/FilesService.cpp (95%) rename src/{service/files => editor/service}/FilesService.h (93%) rename src/{service/log => editor/service}/LogService.cpp (97%) rename src/{service/log => editor/service}/LogService.h (95%) rename src/{service/material => editor/service}/MaterialImporterService.cpp (96%) rename src/{service/material => editor/service}/MaterialImporterService.h (92%) rename src/{service/mesh => editor/service}/MeshImporterService.cpp (90%) rename src/{service/mesh => editor/service}/MeshImporterService.h (93%) rename src/{service/notification => editor/service}/NotificationService.cpp (95%) rename src/{service/notification => editor/service}/NotificationService.h (92%) rename src/{service/picking => editor/service}/PickingService.cpp (94%) rename src/{service/picking => editor/service}/PickingService.h (80%) rename src/{service/mesh => editor/service}/SceneImporterService.cpp (93%) rename src/{service/mesh => editor/service}/SceneImporterService.h (96%) rename src/{service/selection => editor/service}/SelectionService.cpp (92%) rename src/{service/selection => editor/service}/SelectionService.h (83%) rename src/{service/texture => editor/service}/TextureImporterService.cpp (93%) rename src/{service/texture => editor/service}/TextureImporterService.h (95%) rename src/{service/theme => editor/service}/ThemeService.cpp (98%) rename src/{service/theme => editor/service}/ThemeService.h (93%) rename src/{service/voxel => editor/service}/VoxelImporterService.cpp (94%) rename src/{service/voxel => editor/service}/VoxelImporterService.h (89%) rename src/{ => editor}/util/FileDialogUtil.h (93%) rename src/{ => editor}/util/FilesUtil.h (98%) rename src/{ => editor}/util/UIUtil.h (99%) rename src/{ => editor}/util/Util.h (100%) rename src/{ => editor}/util/serialization-definitions.h (97%) rename src/{context => }/engine/EngineContext.cpp (94%) rename src/{context => }/engine/EngineContext.h (95%) rename src/{repository/world/impl => engine/dto}/AbstractComponent.h (89%) rename src/{dto/push-constant => engine/dto}/AccumulationPushConstant.h (100%) rename src/{repository/world/impl => engine/dto}/BoundingBox.h (97%) rename src/{service/camera => engine/dto}/Camera.cpp (98%) rename src/{service/camera => engine/dto}/Camera.h (98%) rename src/{dto/push-constant => engine/dto}/DenoiserPushConstant.h (100%) rename src/{service/descriptor => engine/dto}/DescriptorBinding.h (100%) rename src/{service/descriptor => engine/dto}/DescriptorInstance.h (85%) rename src/{dto/buffers => engine/dto}/GlobalDataUBO.h (100%) rename src/{dto/push-constant => engine/dto}/HWRayTracingPushConstant.h (100%) rename src/{dto/buffers => engine/dto}/LightData.h (100%) rename src/{service/mesh => engine/dto}/MeshData.h (93%) rename src/{dto/buffers => engine/dto}/MeshMetadata.h (100%) rename src/{repository/world/impl => engine/dto}/MetadataComponent.cpp (64%) rename src/{repository/world/impl => engine/dto}/MetadataComponent.h (83%) rename src/{service/pipeline => engine/dto}/PipelineBuilder.cpp (97%) rename src/{service/pipeline => engine/dto}/PipelineBuilder.h (98%) rename src/{dto/push-constant => engine/dto}/PostProcessingPushConstant.h (100%) rename src/{repository/world/components => engine/dto}/PrimitiveComponent.cpp (94%) rename src/{repository/world/components => engine/dto}/PrimitiveComponent.h (91%) rename src/{service/pipeline => engine/dto}/ShaderModule.cpp (73%) rename src/{service/pipeline => engine/dto}/ShaderModule.h (100%) rename src/{service/voxel/impl => engine/dto}/SparseVoxelOctreeData.h (94%) rename src/{service/texture => engine/dto}/TextureData.h (100%) rename src/{dto/buffers => engine/dto}/TileInfoUBO.h (100%) rename src/{repository/world/components => engine/dto}/TransformComponent.cpp (92%) rename src/{repository/world/components => engine/dto}/TransformComponent.h (91%) rename src/{service/mesh => engine/dto}/VertexData.h (96%) rename src/{repository/world/components => engine/dto}/VolumeComponent.cpp (81%) rename src/{repository/world/components => engine/dto}/VolumeComponent.h (93%) rename src/{dto/buffers => engine/dto}/VolumeData.h (100%) rename src/{service/voxel/impl => engine/dto}/VoxelData.h (100%) rename src/{ => engine}/enum/ComponentType.cpp (95%) rename src/{ => engine}/enum/ComponentType.h (96%) rename src/{ => engine}/enum/PassType.h (100%) rename src/{ => engine}/enum/ResourceType.h (100%) rename src/{context => }/engine/frame-builder/EngineFrame.cpp (100%) rename src/{context => }/engine/frame-builder/EngineFrame.h (96%) rename src/{context => }/engine/frame-builder/EngineFrameBuilder.cpp (100%) rename src/{context => }/engine/frame-builder/EngineFrameBuilder.h (95%) rename src/{context => }/engine/frame-builder/structures/BufferBuilder.cpp (82%) rename src/{context => }/engine/frame-builder/structures/BufferBuilder.h (93%) rename src/{context => }/engine/frame-builder/structures/CommandBufferRecorderBuilder.cpp (100%) rename src/{context => }/engine/frame-builder/structures/CommandBufferRecorderBuilder.h (100%) rename src/{context => }/engine/frame-builder/structures/FramebufferBuilder.cpp (86%) rename src/{context => }/engine/frame-builder/structures/FramebufferBuilder.h (100%) rename src/{context => }/engine/frame-builder/structures/PassBuilder.cpp (86%) rename src/{context => }/engine/frame-builder/structures/PassBuilder.h (93%) rename src/{context => }/engine/frame-builder/structures/ResourceBuilder.h (92%) rename src/{context => }/engine/frame-builder/structures/TextureBuilder.cpp (89%) rename src/{context => }/engine/frame-builder/structures/TextureBuilder.h (100%) rename src/{context/engine/compute-pass => engine/passes}/AbstractComputePass.cpp (96%) rename src/{context/engine/compute-pass => engine/passes}/AbstractComputePass.h (96%) rename src/{context => }/engine/passes/AbstractPass.cpp (98%) rename src/{context => }/engine/passes/AbstractPass.h (96%) rename src/{context/engine/render-pass => engine/passes}/AbstractRenderPass.cpp (83%) rename src/{context/engine/render-pass => engine/passes}/AbstractRenderPass.h (93%) rename src/{context => }/engine/passes/CommandBufferRecorder.cpp (95%) rename src/{context => }/engine/passes/CommandBufferRecorder.h (88%) rename src/{context/engine/compute-pass => engine/passes}/impl/HWRayTracingPass.cpp (90%) rename src/{context/engine/compute-pass => engine/passes}/impl/HWRayTracingPass.h (87%) rename src/{context/engine/render-pass => engine/passes}/impl/PostProcessingPass.cpp (90%) rename src/{context/engine/render-pass => engine/passes}/impl/PostProcessingPass.h (86%) rename src/{context/engine/compute-pass => engine/passes}/impl/SpatialFilterPass.cpp (85%) rename src/{context/engine/compute-pass => engine/passes}/impl/SpatialFilterPass.h (100%) rename src/{context/engine/compute-pass => engine/passes}/impl/TemporalAccumulationPass.cpp (86%) rename src/{context/engine/compute-pass => engine/passes}/impl/TemporalAccumulationPass.h (100%) rename src/{repository/engine => engine/repository}/EngineRepository.cpp (97%) rename src/{repository/engine => engine/repository}/EngineRepository.h (94%) rename src/{repository/abstract => engine/repository}/ResourceRepository.h (83%) rename src/{repository/runtime => engine/repository}/RuntimeRepository.h (100%) rename src/{repository/world => engine/repository}/WorldRepository.cpp (96%) rename src/{repository/world => engine/repository}/WorldRepository.h (73%) rename src/{service/buffer => engine/resource}/BufferInstance.cpp (63%) rename src/{service/buffer => engine/resource}/BufferInstance.h (93%) rename src/{service/framebuffer => engine/resource}/FrameBufferAttachment.cpp (81%) rename src/{service/framebuffer => engine/resource}/FrameBufferAttachment.h (90%) rename src/{service/framebuffer => engine/resource}/FrameBufferInstance.h (92%) rename src/{service/mesh => engine/resource}/MeshInstance.h (88%) rename src/{service/pipeline => engine/resource}/PipelineInstance.h (92%) rename src/{repository/abstract => engine/resource}/RuntimeResource.h (93%) rename src/{service/voxel => engine/resource}/SVOInstance.h (80%) rename src/{service/texture => engine/resource}/TextureInstance.h (83%) rename src/{service/buffer => engine/service}/BufferService.cpp (97%) rename src/{service/buffer => engine/service}/BufferService.h (95%) rename src/{service/camera => engine/service}/CameraService.cpp (98%) rename src/{service/camera => engine/service}/CameraService.h (94%) rename src/{service/passes => engine/service}/CommandBufferRecorderService.h (85%) rename src/{service/descriptor => engine/service}/DescriptorSetService.cpp (96%) rename src/{service/descriptor => engine/service}/DescriptorSetService.h (91%) rename src/{service/framebuffer => engine/service}/FrameBufferService.cpp (98%) rename src/{service/framebuffer => engine/service}/FrameBufferService.h (93%) rename src/{service/lights => engine/service}/LightService.cpp (90%) rename src/{service/lights => engine/service}/LightService.h (91%) rename src/{service/material => engine/service}/MaterialService.cpp (88%) rename src/{service/material => engine/service}/MaterialService.h (100%) rename src/{service/mesh => engine/service}/MeshService.cpp (84%) rename src/{service/mesh => engine/service}/MeshService.h (78%) rename src/{service/pipeline => engine/service}/PipelineService.cpp (97%) rename src/{service/pipeline => engine/service}/PipelineService.h (90%) rename src/{service/raytracing => engine/service}/RayTracingService.cpp (97%) rename src/{service/raytracing => engine/service}/RayTracingService.h (92%) rename src/{repository/streaming => engine/service}/StreamingService.cpp (87%) rename src/{repository/streaming => engine/service}/StreamingService.h (78%) rename src/{service/texture => engine/service}/TextureService.cpp (98%) rename src/{service/texture => engine/service}/TextureService.h (94%) rename src/{service/transform => engine/service}/TransformService.cpp (90%) rename src/{service/transform => engine/service}/TransformService.h (83%) rename src/{service/volumes => engine/service}/VolumeService.cpp (81%) rename src/{service/volumes => engine/service}/VolumeService.h (81%) rename src/{service/voxel => engine/service}/VoxelService.cpp (93%) rename src/{service/voxel => engine/service}/VoxelService.h (82%) rename src/{ => engine}/util/ImageUtils.h (100%) rename src/{ => engine}/util/ShaderUtil.cpp (94%) rename src/{ => engine}/util/ShaderUtil.h (94%) delete mode 100644 src/enum/LightType.h delete mode 100644 src/repository/dock/DockPosition.h diff --git a/CMakeLists.txt b/CMakeLists.txt index e81faae2..1543f480 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,283 +7,281 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DVK_PROTOTYPES") add_executable( metal_engine src/main.cpp - src/context/editor/EditorPanel.cpp - src/context/editor/EditorPanel.h - src/context/editor/abstract/IPanel.h - src/context/engine/EngineContext.cpp - src/context/engine/EngineContext.h - src/util/VulkanUtils.cpp - src/util/VulkanUtils.h - src/context/vulkan/VulkanContext.cpp - src/context/vulkan/VulkanContext.h - src/context/glfw/GLFWContext.cpp - src/context/glfw/GLFWContext.h - src/context/gui/GuiContext.cpp - src/context/gui/GuiContext.h - src/context/editor/dock-spaces/viewport/ViewportPanel.cpp - src/context/editor/dock-spaces/viewport/ViewportPanel.h - src/context/editor/dock-spaces/viewport/EngineFramePanel.cpp - src/context/editor/dock-spaces/viewport/EngineFramePanel.h - src/context/editor/dock-spaces/docks/AbstractDockPanel.h - src/context/ApplicationContext.cpp - src/context/ApplicationContext.h - src/context/editor/abstract/AbstractPanel.h - src/context/editor/abstract/AbstractPanel.cpp - src/common/interface/Synchornizable.h - src/service/camera/CameraService.cpp - src/service/camera/CameraService.h - src/service/camera/Camera.h - src/util/Util.h - src/common/inspection/Inspectable.h - src/common/inspection/Inspectable.cpp - src/common/inspection/InspectedField.h - src/context/editor/dock-spaces/inspector/InspectorPanel.cpp - src/context/editor/dock-spaces/inspector/InspectorPanel.h - src/context/editor/abstract/form/FormPanel.cpp - src/context/editor/abstract/form/FormPanel.h - src/context/editor/abstract/form/AccordionPanel.cpp - src/context/editor/abstract/form/AccordionPanel.h - src/enum/FieldType.h - src/common/inspection/InspectableMember.h + src/editor/EditorPanel.cpp + src/editor/EditorPanel.h + src/editor/abstract/IPanel.h + src/engine/EngineContext.cpp + src/engine/EngineContext.h + src/core/vulkan/VulkanUtils.cpp + src/core/vulkan/VulkanUtils.h + src/core/vulkan/VulkanContext.cpp + src/core/vulkan/VulkanContext.h + src/core/glfw/GLFWContext.cpp + src/core/glfw/GLFWContext.h + src/core/gui/GuiContext.cpp + src/core/gui/GuiContext.h + src/editor/dock-spaces/viewport/ViewportPanel.cpp + src/editor/dock-spaces/viewport/ViewportPanel.h + src/editor/dock-spaces/viewport/EngineFramePanel.cpp + src/editor/dock-spaces/viewport/EngineFramePanel.h + src/editor/dock-spaces/docks/AbstractDockPanel.h + src/ApplicationContext.cpp + src/ApplicationContext.h + src/editor/abstract/AbstractPanel.h + src/editor/abstract/AbstractPanel.cpp + src/common/Synchornizable.h + src/engine/service/CameraService.cpp + src/engine/service/CameraService.h + src/engine/dto/Camera.h + src/editor/util/Util.h + src/common/Inspectable.h + src/common/Inspectable.cpp + src/common/InspectedField.h + src/editor/dock-spaces/inspector/InspectorPanel.cpp + src/editor/dock-spaces/inspector/InspectorPanel.h + src/editor/abstract/form/FormPanel.cpp + src/editor/abstract/form/FormPanel.h + src/editor/abstract/form/AccordionPanel.cpp + src/editor/abstract/form/AccordionPanel.h + src/common/FieldType.h + src/common/InspectableMember.h src/common/AbstractRuntimeComponent.h - src/context/editor/abstract/form/types/BooleanField.cpp - src/context/editor/abstract/form/types/BooleanField.h - src/context/editor/abstract/form/types/IntField.cpp - src/context/editor/abstract/form/types/IntField.h - src/context/editor/abstract/form/types/FloatField.cpp - src/context/editor/abstract/form/types/FloatField.h - src/context/editor/abstract/form/types/MethodField.cpp - src/context/editor/abstract/form/types/MethodField.h - src/util/UIUtil.h - src/context/editor/dock-spaces/header/EditorHeaderPanel.cpp - src/context/editor/dock-spaces/header/EditorHeaderPanel.h - src/context/editor/dock-spaces/header/AsyncTaskPanel.cpp - src/context/editor/dock-spaces/header/AsyncTaskPanel.h - src/common/interface/Icons.h - src/service/dock/DockService.cpp - src/service/dock/DockService.h - src/repository/dock/DockRepository.h - src/repository/dock/DockDTO.h - src/repository/dock/DockSpace.h - src/repository/dock/DockPosition.h - src/context/editor/dock-spaces/docks/DockSpacePanel.cpp - src/context/editor/dock-spaces/docks/DockSpacePanel.h - src/repository/dock/DockSpace.cpp - src/service/theme/ThemeService.cpp - src/service/theme/ThemeService.h - src/repository/editor/EditorRepository.h - src/enum/engine-definitions.h - src/context/editor/dock-spaces/files/FilesPanel.cpp - src/context/editor/dock-spaces/files/FilesPanel.h - src/context/editor/dock-spaces/files/FilesListPanel.cpp - src/context/editor/dock-spaces/files/FilesListPanel.h - src/context/editor/dock-spaces/files/FilePreviewPanel.cpp - src/context/editor/dock-spaces/files/FilePreviewPanel.h - src/context/editor/dock-spaces/console/ConsolePanel.cpp - src/context/editor/dock-spaces/console/ConsolePanel.h - src/context/editor/dock-spaces/metrics/MetricsPanel.cpp - src/context/editor/dock-spaces/metrics/MetricsPanel.h - src/service/log/LogService.cpp - src/service/log/LogService.h - src/context/editor/dock-spaces/world/WorldPanel.cpp - src/context/editor/dock-spaces/world/WorldPanel.h - src/repository/abstract/RuntimeResource.h - src/util/ShaderUtil.cpp - src/util/ShaderUtil.h - src/service/pipeline/ShaderModule.cpp - src/service/pipeline/ShaderModule.h - src/context/engine/render-pass/AbstractRenderPass.cpp - src/context/engine/render-pass/AbstractRenderPass.h - src/service/abstract/AbstractResourceService.h - src/service/framebuffer/FrameBufferAttachment.h - src/repository/abstract/AbstractCoreRepository.h - src/service/framebuffer/FrameBufferService.cpp - src/service/framebuffer/FrameBufferService.h - src/service/framebuffer/FrameBufferInstance.h - src/service/pipeline/PipelineService.cpp - src/service/pipeline/PipelineService.h - src/service/pipeline/PipelineInstance.h - src/service/buffer/BufferService.cpp - src/service/buffer/BufferService.h - src/service/descriptor/DescriptorSetService.cpp - src/service/descriptor/DescriptorSetService.h - src/service/descriptor/DescriptorInstance.h - src/dto/buffers/GlobalDataUBO.h - src/repository/runtime/RuntimeRepository.h - src/service/buffer/BufferInstance.cpp - src/service/buffer/BufferInstance.h - src/service/mesh/MeshService.cpp - src/service/mesh/MeshService.h - src/service/mesh/MeshData.h - src/service/mesh/MeshInstance.h - src/util/FilesUtil.h - src/dto/file/FSEntry.h - src/enum/EntryType.h - src/context/editor/dock-spaces/files/FilesContext.h - src/util/FileDialogUtil.h - src/context/editor/dock-spaces/files/FilesHeaderPanel.cpp - src/context/editor/dock-spaces/files/FilesHeaderPanel.h - src/service/material/MaterialImporterService.cpp - src/service/material/MaterialImporterService.h - src/service/mesh/MeshImporterService.cpp - src/service/mesh/MeshImporterService.h - src/service/mesh/SceneImporterService.cpp - src/service/mesh/SceneImporterService.h - src/service/abstract/AbstractImporter.h - src/service/texture/TextureImporterService.cpp - src/service/texture/TextureImporterService.h - src/dto/file/EntryMetadata.h - src/service/texture/TextureData.h - src/service/texture/TextureService.cpp - src/service/texture/TextureService.h - src/service/files/FilesService.cpp - src/service/files/FilesService.h - src/service/files/FileImporterService.cpp - src/service/files/FileImporterService.h - src/context/editor/dock-spaces/files/FilesContext.cpp - src/service/mesh/VertexData.h - src/context/editor/dock-spaces/viewport/CameraPositionPanel.cpp - src/context/editor/dock-spaces/viewport/CameraPositionPanel.h - src/context/engine/render-pass/impl/tools/GridPass.cpp - src/context/engine/render-pass/impl/tools/GridPass.h - src/context/engine/passes/CommandBufferRecorder.cpp - src/context/engine/passes/CommandBufferRecorder.h - src/service/camera/Camera.cpp - src/repository/world/WorldRepository.cpp - src/repository/world/WorldRepository.h - src/repository/world/impl/MetadataComponent.h - src/enum/ComponentType.cpp - src/enum/ComponentType.h - src/repository/world/impl/AbstractComponent.h - src/repository/world/components/PrimitiveComponent.h - src/repository/world/components/TransformComponent.h - src/enum/ShadingMode.h - src/context/editor/dock-spaces/world/WorldHeaderPanel.cpp - src/context/editor/dock-spaces/world/WorldHeaderPanel.h - src/service/selection/SelectionService.cpp - src/service/selection/SelectionService.h - src/repository/world/impl/MetadataComponent.cpp - src/repository/world/components/TransformComponent.cpp - src/repository/world/components/PrimitiveComponent.cpp - src/context/editor/abstract/form/types/ResourceField.cpp - src/context/editor/abstract/form/types/ResourceField.h - src/context/editor/abstract/form/types/ColorField.cpp - src/context/editor/abstract/form/types/ColorField.h - src/context/editor/abstract/form/types/Vec4Field.cpp - src/context/editor/abstract/form/types/Vec4Field.h - src/context/editor/abstract/form/types/Vec3Field.cpp - src/context/editor/abstract/form/types/Vec3Field.h - src/context/editor/abstract/form/types/Vec2Field.cpp - src/context/editor/abstract/form/types/Vec2Field.h - src/context/editor/abstract/form/types/StringField.cpp - src/context/editor/abstract/form/types/StringField.h - src/context/editor/abstract/form/types/ResourceFilesPanel.h - src/context/editor/abstract/form/types/ResourceFilesPanel.cpp - src/repository/streaming/StreamingService.cpp - src/repository/streaming/StreamingService.h - src/enum/ResourceType.h - src/context/editor/dock-spaces/viewport/GizmoPanel.cpp - src/context/editor/dock-spaces/viewport/GizmoPanel.h - src/context/editor/dock-spaces/viewport/ViewportHeaderPanel.cpp - src/context/editor/dock-spaces/viewport/ViewportHeaderPanel.h - src/context/editor/dock-spaces/viewport/GizmoSettingsPanel.cpp - src/context/editor/dock-spaces/viewport/GizmoSettingsPanel.h - src/context/editor/abstract/form/types/QuatField.cpp - src/context/editor/abstract/form/types/QuatField.h - src/service/transform/TransformService.cpp - src/service/transform/TransformService.h - src/repository/world/impl/BoundingBox.h - src/service/voxel/impl/SparseVoxelOctreeBuilder.cpp - src/service/voxel/impl/SparseVoxelOctreeBuilder.h - src/service/voxel/impl/OctreeNode.cpp - src/service/voxel/impl/OctreeNode.h - src/service/voxel/impl/VoxelData.h - src/service/mesh/SceneData.h - src/context/engine/render-pass/impl/PostProcessingPass.cpp - src/context/engine/render-pass/impl/PostProcessingPass.h - src/context/engine/compute-pass/impl/HWRayTracingPass.cpp - src/context/engine/compute-pass/impl/HWRayTracingPass.h - src/service/raytracing/RayTracingService.cpp - src/service/raytracing/RayTracingService.h - src/service/pipeline/PipelineBuilder.h - src/service/framebuffer/FrameBufferAttachment.cpp - src/repository/engine/EngineRepository.cpp - src/repository/engine/EngineRepository.h - src/util/serialization-definitions.h - src/service/notification/NotificationService.cpp - src/service/notification/NotificationService.h - src/service/notification/AsyncTaskService.cpp - src/service/notification/AsyncTaskService.h - src/dto/Notification.h - src/enum/NotificationSeverity.h - src/service/voxel/impl/SparseVoxelOctreeData.h - src/context/engine/render-pass/impl/tools/SelectionOutlinePass.cpp - src/context/engine/render-pass/impl/tools/SelectionOutlinePass.h - src/service/picking/PickingService.cpp - src/service/picking/PickingService.h - src/service/voxel/SVOInstance.h - src/dto/buffers/TileInfoUBO.h - src/dto/buffers/LightData.h - src/context/engine/render-pass/impl/tools/IconsPass.cpp - src/context/engine/render-pass/impl/tools/IconsPass.h - src/context/engine/render-pass/impl/tools/SelectionIDPass.cpp - src/context/engine/render-pass/impl/tools/SelectionIDPass.h - src/repository/editor/EditorRepository.cpp - src/dto/push-constant/GridPushConstant.h - src/context/engine/compute-pass/AbstractComputePass.cpp - src/context/engine/compute-pass/AbstractComputePass.h - src/context/engine/passes/AbstractPass.cpp - src/context/engine/passes/AbstractPass.h - src/util/ImageUtils.h - src/service/material/MaterialService.cpp - src/service/material/MaterialService.h - src/enum/LightType.h - src/service/lights/LightService.cpp - src/service/lights/LightService.h - src/repository/world/components/VolumeComponent.cpp - src/repository/world/components/VolumeComponent.h - src/service/descriptor/DescriptorBinding.h - src/service/notification/AsyncTask.h - src/service/voxel/VoxelImporterService.cpp - src/service/voxel/VoxelImporterService.h - src/dto/buffers/VolumeData.h - src/service/voxel/VoxelService.cpp - src/service/voxel/VoxelService.h - src/util/Serializable.cpp - src/context/editor/abstract/form/ChildPanel.cpp - src/context/editor/abstract/form/ChildPanel.h - src/dto/file/SceneImportSettingsDTO.h - src/context/editor/panel/NotificationsPanel.cpp - src/context/editor/panel/NotificationsPanel.h - src/context/editor/panel/FileImportModalPanel.cpp - src/context/editor/panel/FileImportModalPanel.h - src/context/engine/frame-builder/EngineFrameBuilder.cpp - src/context/engine/frame-builder/EngineFrameBuilder.h - src/context/engine/frame-builder/EngineFrame.cpp - src/context/engine/frame-builder/EngineFrame.h - src/context/engine/frame-builder/structures/FramebufferBuilder.cpp - src/context/engine/frame-builder/structures/FramebufferBuilder.h - src/context/engine/frame-builder/structures/TextureBuilder.cpp - src/context/engine/frame-builder/structures/TextureBuilder.h - src/context/engine/frame-builder/structures/BufferBuilder.cpp - src/context/engine/frame-builder/structures/BufferBuilder.h - src/context/engine/frame-builder/structures/ResourceBuilder.h - src/service/pipeline/PipelineBuilder.cpp - src/service/descriptor/DescriptorSetService.cpp - src/context/engine/frame-builder/structures/PassBuilder.cpp - src/context/engine/frame-builder/structures/CommandBufferRecorderBuilder.cpp - src/common/interface/Changeable.h - src/context/engine/compute-pass/impl/TemporalAccumulationPass.cpp - src/context/engine/compute-pass/impl/TemporalAccumulationPass.h - src/context/engine/compute-pass/impl/SpatialFilterPass.cpp - src/context/engine/compute-pass/impl/SpatialFilterPass.h - src/enum/ComponentType.cpp - src/service/mesh/SceneEntityData.h - src/context/editor/dock-spaces/repositories/RepositoriesPanel.cpp - src/context/editor/dock-spaces/repositories/RepositoriesPanel.h - src/service/volumes/VolumeService.cpp - src/service/volumes/VolumeService.h - src/repository/dock/DockRepository.cpp + src/editor/abstract/form/types/BooleanField.cpp + src/editor/abstract/form/types/BooleanField.h + src/editor/abstract/form/types/IntField.cpp + src/editor/abstract/form/types/IntField.h + src/editor/abstract/form/types/FloatField.cpp + src/editor/abstract/form/types/FloatField.h + src/editor/abstract/form/types/MethodField.cpp + src/editor/abstract/form/types/MethodField.h + src/editor/util/UIUtil.h + src/editor/dock-spaces/header/EditorHeaderPanel.cpp + src/editor/dock-spaces/header/EditorHeaderPanel.h + src/editor/dock-spaces/header/AsyncTaskPanel.cpp + src/editor/dock-spaces/header/AsyncTaskPanel.h + src/common/Icons.h + src/editor/service/DockService.cpp + src/editor/service/DockService.h + src/editor/repository/DockRepository.h + src/editor/dto/DockDTO.h + src/editor/dto/DockSpace.h + src/editor/dock-spaces/docks/DockSpacePanel.cpp + src/editor/dock-spaces/docks/DockSpacePanel.h + src/editor/dto/DockSpace.cpp + src/editor/service/ThemeService.cpp + src/editor/service/ThemeService.h + src/editor/repository/EditorRepository.h + src/editor/enum/engine-definitions.h + src/editor/dock-spaces/files/FilesPanel.cpp + src/editor/dock-spaces/files/FilesPanel.h + src/editor/dock-spaces/files/FilesListPanel.cpp + src/editor/dock-spaces/files/FilesListPanel.h + src/editor/dock-spaces/files/FilePreviewPanel.cpp + src/editor/dock-spaces/files/FilePreviewPanel.h + src/editor/dock-spaces/console/ConsolePanel.cpp + src/editor/dock-spaces/console/ConsolePanel.h + src/editor/dock-spaces/metrics/MetricsPanel.cpp + src/editor/dock-spaces/metrics/MetricsPanel.h + src/editor/service/LogService.cpp + src/editor/service/LogService.h + src/editor/dock-spaces/world/WorldPanel.cpp + src/editor/dock-spaces/world/WorldPanel.h + src/engine/resource/RuntimeResource.h + src/engine/util/ShaderUtil.cpp + src/engine/util/ShaderUtil.h + src/engine/dto/ShaderModule.cpp + src/engine/dto/ShaderModule.h + src/engine/passes/AbstractRenderPass.cpp + src/engine/passes/AbstractRenderPass.h + src/common/AbstractResourceService.h + src/engine/resource/FrameBufferAttachment.h + src/common/AbstractCoreRepository.h + src/engine/service/FrameBufferService.cpp + src/engine/service/FrameBufferService.h + src/engine/resource/FrameBufferInstance.h + src/engine/service/PipelineService.cpp + src/engine/service/PipelineService.h + src/engine/resource/PipelineInstance.h + src/engine/service/BufferService.cpp + src/engine/service/BufferService.h + src/engine/service/DescriptorSetService.cpp + src/engine/service/DescriptorSetService.h + src/engine/dto/DescriptorInstance.h + src/engine/dto/GlobalDataUBO.h + src/engine/repository/RuntimeRepository.h + src/engine/resource/BufferInstance.cpp + src/engine/resource/BufferInstance.h + src/engine/service/MeshService.cpp + src/engine/service/MeshService.h + src/engine/dto/MeshData.h + src/engine/resource/MeshInstance.h + src/editor/util/FilesUtil.h + src/editor/dto/FSEntry.h + src/editor/enum/EntryType.h + src/editor/dock-spaces/files/FilesContext.h + src/editor/util/FileDialogUtil.h + src/editor/dock-spaces/files/FilesHeaderPanel.cpp + src/editor/dock-spaces/files/FilesHeaderPanel.h + src/editor/service/MaterialImporterService.cpp + src/editor/service/MaterialImporterService.h + src/editor/service/MeshImporterService.cpp + src/editor/service/MeshImporterService.h + src/editor/service/SceneImporterService.cpp + src/editor/service/SceneImporterService.h + src/common/AbstractImporter.h + src/editor/service/TextureImporterService.cpp + src/editor/service/TextureImporterService.h + src/editor/dto/EntryMetadata.h + src/engine/dto/TextureData.h + src/engine/service/TextureService.cpp + src/engine/service/TextureService.h + src/editor/service/FilesService.cpp + src/editor/service/FilesService.h + src/editor/service/FileImporterService.cpp + src/editor/service/FileImporterService.h + src/editor/dock-spaces/files/FilesContext.cpp + src/engine/dto/VertexData.h + src/editor/dock-spaces/viewport/CameraPositionPanel.cpp + src/editor/dock-spaces/viewport/CameraPositionPanel.h + src/editor/passes/GridPass.cpp + src/editor/passes/GridPass.h + src/engine/passes/CommandBufferRecorder.cpp + src/engine/passes/CommandBufferRecorder.h + src/engine/dto/Camera.cpp + src/engine/repository/WorldRepository.cpp + src/engine/repository/WorldRepository.h + src/engine/dto/MetadataComponent.h + src/engine/enum/ComponentType.cpp + src/engine/enum/ComponentType.h + src/engine/dto/AbstractComponent.h + src/engine/dto/PrimitiveComponent.h + src/engine/dto/TransformComponent.h + src/editor/enum/ShadingMode.h + src/editor/dock-spaces/world/WorldHeaderPanel.cpp + src/editor/dock-spaces/world/WorldHeaderPanel.h + src/editor/service/SelectionService.cpp + src/editor/service/SelectionService.h + src/engine/dto/MetadataComponent.cpp + src/engine/dto/TransformComponent.cpp + src/engine/dto/PrimitiveComponent.cpp + src/editor/abstract/form/types/ResourceField.cpp + src/editor/abstract/form/types/ResourceField.h + src/editor/abstract/form/types/ColorField.cpp + src/editor/abstract/form/types/ColorField.h + src/editor/abstract/form/types/Vec4Field.cpp + src/editor/abstract/form/types/Vec4Field.h + src/editor/abstract/form/types/Vec3Field.cpp + src/editor/abstract/form/types/Vec3Field.h + src/editor/abstract/form/types/Vec2Field.cpp + src/editor/abstract/form/types/Vec2Field.h + src/editor/abstract/form/types/StringField.cpp + src/editor/abstract/form/types/StringField.h + src/editor/abstract/form/types/ResourceFilesPanel.h + src/editor/abstract/form/types/ResourceFilesPanel.cpp + src/engine/service/StreamingService.cpp + src/engine/service/StreamingService.h + src/engine/enum/ResourceType.h + src/editor/dock-spaces/viewport/GizmoPanel.cpp + src/editor/dock-spaces/viewport/GizmoPanel.h + src/editor/dock-spaces/viewport/ViewportHeaderPanel.cpp + src/editor/dock-spaces/viewport/ViewportHeaderPanel.h + src/editor/dock-spaces/viewport/GizmoSettingsPanel.cpp + src/editor/dock-spaces/viewport/GizmoSettingsPanel.h + src/editor/abstract/form/types/QuatField.cpp + src/editor/abstract/form/types/QuatField.h + src/engine/service/TransformService.cpp + src/engine/service/TransformService.h + src/engine/dto/BoundingBox.h + src/editor/dto/SparseVoxelOctreeBuilder.cpp + src/editor/dto/SparseVoxelOctreeBuilder.h + src/editor/dto/OctreeNode.cpp + src/editor/dto/OctreeNode.h + src/engine/dto/VoxelData.h + src/editor/dto/SceneData.h + src/engine/passes/impl/PostProcessingPass.cpp + src/engine/passes/impl/PostProcessingPass.h + src/engine/passes/impl/HWRayTracingPass.cpp + src/engine/passes/impl/HWRayTracingPass.h + src/engine/service/RayTracingService.cpp + src/engine/service/RayTracingService.h + src/engine/dto/PipelineBuilder.h + src/engine/resource/FrameBufferAttachment.cpp + src/engine/repository/EngineRepository.cpp + src/engine/repository/EngineRepository.h + src/editor/util/serialization-definitions.h + src/editor/service/NotificationService.cpp + src/editor/service/NotificationService.h + src/editor/service/AsyncTaskService.cpp + src/editor/service/AsyncTaskService.h + src/editor/dto/Notification.h + src/editor/enum/NotificationSeverity.h + src/engine/dto/SparseVoxelOctreeData.h + src/editor/passes/SelectionOutlinePass.cpp + src/editor/passes/SelectionOutlinePass.h + src/editor/service/PickingService.cpp + src/editor/service/PickingService.h + src/engine/resource/SVOInstance.h + src/engine/dto/TileInfoUBO.h + src/engine/dto/LightData.h + src/editor/passes/IconsPass.cpp + src/editor/passes/IconsPass.h + src/editor/passes/SelectionIDPass.cpp + src/editor/passes/SelectionIDPass.h + src/editor/repository/EditorRepository.cpp + src/editor/dto/GridPushConstant.h + src/engine/passes/AbstractComputePass.cpp + src/engine/passes/AbstractComputePass.h + src/engine/passes/AbstractPass.cpp + src/engine/passes/AbstractPass.h + src/engine/util/ImageUtils.h + src/engine/service/MaterialService.cpp + src/engine/service/MaterialService.h + src/engine/service/LightService.cpp + src/engine/service/LightService.h + src/engine/dto/VolumeComponent.cpp + src/engine/dto/VolumeComponent.h + src/engine/dto/DescriptorBinding.h + src/editor/dto/AsyncTask.h + src/editor/service/VoxelImporterService.cpp + src/editor/service/VoxelImporterService.h + src/engine/dto/VolumeData.h + src/engine/service/VoxelService.cpp + src/engine/service/VoxelService.h + src/common/Serializable.cpp + src/editor/abstract/form/ChildPanel.cpp + src/editor/abstract/form/ChildPanel.h + src/editor/dto/SceneImportSettingsDTO.h + src/editor/panel/NotificationsPanel.cpp + src/editor/panel/NotificationsPanel.h + src/editor/panel/FileImportModalPanel.cpp + src/editor/panel/FileImportModalPanel.h + src/engine/frame-builder/EngineFrameBuilder.cpp + src/engine/frame-builder/EngineFrameBuilder.h + src/engine/frame-builder/EngineFrame.cpp + src/engine/frame-builder/EngineFrame.h + src/engine/frame-builder/structures/FramebufferBuilder.cpp + src/engine/frame-builder/structures/FramebufferBuilder.h + src/engine/frame-builder/structures/TextureBuilder.cpp + src/engine/frame-builder/structures/TextureBuilder.h + src/engine/frame-builder/structures/BufferBuilder.cpp + src/engine/frame-builder/structures/BufferBuilder.h + src/engine/frame-builder/structures/ResourceBuilder.h + src/engine/dto/PipelineBuilder.cpp + src/engine/service/DescriptorSetService.cpp + src/engine/frame-builder/structures/PassBuilder.cpp + src/engine/frame-builder/structures/CommandBufferRecorderBuilder.cpp + src/common/Changeable.h + src/engine/passes/impl/TemporalAccumulationPass.cpp + src/engine/passes/impl/TemporalAccumulationPass.h + src/engine/passes/impl/SpatialFilterPass.cpp + src/engine/passes/impl/SpatialFilterPass.h + src/engine/enum/ComponentType.cpp + src/editor/dto/SceneEntityData.h + src/editor/dock-spaces/repositories/RepositoriesPanel.cpp + src/editor/dock-spaces/repositories/RepositoriesPanel.h + src/engine/service/VolumeService.cpp + src/engine/service/VolumeService.h + src/editor/repository/DockRepository.cpp ) diff --git a/src/context/ApplicationContext.cpp b/src/ApplicationContext.cpp similarity index 96% rename from src/context/ApplicationContext.cpp rename to src/ApplicationContext.cpp index f489b20b..fba64246 100644 --- a/src/context/ApplicationContext.cpp +++ b/src/ApplicationContext.cpp @@ -1,13 +1,13 @@ -#include "ApplicationContext.h" +#include "context/ApplicationContext.h" #include #include -#include "../util/FilesUtil.h" -#include "../util/VulkanUtils.h" -#include "../util/serialization-definitions.h" +#include "editor/util/FilesUtil.h" +#include "vulkan/VulkanUtils.h" +#include "editor/util/serialization-definitions.h" -#include "../util/FileDialogUtil.h" +#include "editor/util/FileDialogUtil.h" #include namespace Metal { diff --git a/src/context/ApplicationContext.h b/src/ApplicationContext.h similarity index 69% rename from src/context/ApplicationContext.h rename to src/ApplicationContext.h index aad857a1..08ace4d5 100644 --- a/src/context/ApplicationContext.h +++ b/src/ApplicationContext.h @@ -7,41 +7,41 @@ #include "glfw/GLFWContext.h" #include "vulkan/VulkanContext.h" -#include "../service/mesh/MeshService.h" -#include "../service/texture/TextureService.h" -#include "../service/framebuffer/FrameBufferService.h" -#include "../service/pipeline/PipelineService.h" -#include "../service/buffer/BufferService.h" -#include "../service/descriptor/DescriptorSetService.h" -#include "../service/theme/ThemeService.h" -#include "../service/dock/DockService.h" -#include "../service/selection/SelectionService.h" -#include "../service/mesh/SceneImporterService.h" -#include "../service/mesh/MeshImporterService.h" -#include "../service/material/MaterialImporterService.h" -#include "../service/texture/TextureImporterService.h" -#include "../service/files/FilesService.h" -#include "../service/files/FileImporterService.h" -#include "../service/camera/CameraService.h" - -#include "../repository/world/WorldRepository.h" -#include "../repository/runtime/RuntimeRepository.h" -#include "../repository/streaming/StreamingService.h" -#include "../repository/engine/EngineRepository.h" -#include "../repository/dock/DockRepository.h" -#include "../repository/editor/EditorRepository.h" -#include "../service/material/MaterialService.h" -#include "../service/passes/CommandBufferRecorderService.h" +#include "engine/service/MeshService.h" +#include "engine/service/TextureService.h" +#include "engine/service/FrameBufferService.h" +#include "engine/service/PipelineService.h" +#include "engine/service/BufferService.h" +#include "engine/service/DescriptorSetService.h" +#include "editor/service/ThemeService.h" +#include "editor/service/DockService.h" +#include "editor/service/SelectionService.h" +#include "editor/service/SceneImporterService.h" +#include "editor/service/MeshImporterService.h" +#include "editor/service/MaterialImporterService.h" +#include "editor/service/TextureImporterService.h" +#include "editor/service/FilesService.h" +#include "editor/service/FileImporterService.h" +#include "engine/service/CameraService.h" + +#include "engine/repository/WorldRepository.h" +#include "engine/repository/RuntimeRepository.h" +#include "engine/service/StreamingService.h" +#include "engine/repository/EngineRepository.h" +#include "editor/repository/DockRepository.h" +#include "editor/repository/EditorRepository.h" +#include "engine/service/MaterialService.h" +#include "engine/service/CommandBufferRecorderService.h" #include "../service/notification/NotificationService.h" -#include "../service/notification/AsyncTaskService.h" -#include "../service/log/LogService.h" -#include "../service/transform/TransformService.h" -#include "../service/picking/PickingService.h" -#include "../service/volumes/VolumeService.h" -#include "../service/voxel/VoxelImporterService.h" +#include "editor/service/AsyncTaskService.h" +#include "editor/service/LogService.h" +#include "engine/service/TransformService.h" +#include "editor/service/PickingService.h" +#include "engine/service/VolumeService.h" +#include "editor/service/VoxelImporterService.h" #include "../service/voxel/VoxelService.h" -#include "../service/lights/LightService.h" -#include "../service/raytracing/RayTracingService.h" +#include "engine/service/LightService.h" +#include "engine/service/RayTracingService.h" #include "editor/EditorPanel.h" #include "gui/GuiContext.h" diff --git a/src/repository/abstract/AbstractCoreRepository.h b/src/common/AbstractCoreRepository.h similarity index 86% rename from src/repository/abstract/AbstractCoreRepository.h rename to src/common/AbstractCoreRepository.h index 30369685..93631a01 100644 --- a/src/repository/abstract/AbstractCoreRepository.h +++ b/src/common/AbstractCoreRepository.h @@ -1,6 +1,6 @@ #ifndef ABSTRACTCOREREPOSITORY_H #define ABSTRACTCOREREPOSITORY_H -#include "../../common/AbstractRuntimeComponent.h" +#include "AbstractRuntimeComponent.h" namespace Metal { class VulkanContext; diff --git a/src/service/abstract/AbstractImporter.h b/src/common/AbstractImporter.h similarity index 91% rename from src/service/abstract/AbstractImporter.h rename to src/common/AbstractImporter.h index 4998a7a4..24e05029 100644 --- a/src/service/abstract/AbstractImporter.h +++ b/src/common/AbstractImporter.h @@ -4,8 +4,8 @@ #include #include -#include "../../dto/file/ImportSettingsDTO.h" -#include "../../common/AbstractRuntimeComponent.h" +#include "../context/editor/dto/ImportSettingsDTO.h" +#include "AbstractRuntimeComponent.h" namespace Metal { class AbstractImporter : public AbstractRuntimeComponent { diff --git a/src/service/abstract/AbstractResourceService.h b/src/common/AbstractResourceService.h similarity index 94% rename from src/service/abstract/AbstractResourceService.h rename to src/common/AbstractResourceService.h index 0d95c189..c94287d4 100644 --- a/src/service/abstract/AbstractResourceService.h +++ b/src/common/AbstractResourceService.h @@ -4,8 +4,8 @@ #include #include -#include "../../common/AbstractRuntimeComponent.h" -#include "../../repository/abstract/RuntimeResource.h" +#include "AbstractRuntimeComponent.h" +#include "../context/engine/resource/RuntimeResource.h" namespace Metal { class VulkanContext; diff --git a/src/common/AbstractRuntimeComponent.h b/src/common/AbstractRuntimeComponent.h index f8e18f3b..f2b753b1 100644 --- a/src/common/AbstractRuntimeComponent.h +++ b/src/common/AbstractRuntimeComponent.h @@ -1,9 +1,9 @@ #ifndef METAL_ENGINE_ABSTRACTRUNTIMECOMPONENT_H #define METAL_ENGINE_ABSTRACTRUNTIMECOMPONENT_H -#include "interface/Changeable.h" -#include "interface/Initializable.h" -#include "interface/Synchornizable.h" +#include "Changeable.h" +#include "Initializable.h" +#include "Synchornizable.h" #define ENGINE_NAME "Metal Engine" diff --git a/src/common/interface/Changeable.h b/src/common/Changeable.h similarity index 100% rename from src/common/interface/Changeable.h rename to src/common/Changeable.h diff --git a/src/enum/FieldType.h b/src/common/FieldType.h similarity index 100% rename from src/enum/FieldType.h rename to src/common/FieldType.h diff --git a/src/common/interface/Icons.h b/src/common/Icons.h similarity index 100% rename from src/common/interface/Icons.h rename to src/common/Icons.h diff --git a/src/common/interface/Initializable.h b/src/common/Initializable.h similarity index 100% rename from src/common/interface/Initializable.h rename to src/common/Initializable.h diff --git a/src/common/inspection/Inspectable.cpp b/src/common/Inspectable.cpp similarity index 95% rename from src/common/inspection/Inspectable.cpp rename to src/common/Inspectable.cpp index 0bc87b75..a0c0b207 100644 --- a/src/common/inspection/Inspectable.cpp +++ b/src/common/Inspectable.cpp @@ -1,14 +1,14 @@ -#include "Inspectable.h" +#include "inspection/Inspectable.h" #include #include #include #include -#include "InspectedField.h" -#include "InspectedMethod.h" -#include "../../util/Util.h" -#include "../../enum/EntryType.h" +#include "inspection/InspectedField.h" +#include "inspection/InspectedMethod.h" +#include "../context/editor/util/Util.h" +#include "../context/editor/enum/EntryType.h" #define DECLARATION(T, V) \ std::shared_ptr> field = std::make_shared>(&v);\ diff --git a/src/common/inspection/Inspectable.h b/src/common/Inspectable.h similarity index 97% rename from src/common/inspection/Inspectable.h rename to src/common/Inspectable.h index 990de344..1c3df071 100644 --- a/src/common/inspection/Inspectable.h +++ b/src/common/Inspectable.h @@ -7,9 +7,9 @@ #include #include "InspectableMember.h" -#include "../../util/Util.h" -#include "../../enum/EntryType.h" -#include "../interface/Changeable.h" +#include "../context/editor/util/Util.h" +#include "../context/editor/enum/EntryType.h" +#include "Changeable.h" namespace Metal { class Inspectable : public Changeable { diff --git a/src/common/inspection/InspectableMember.h b/src/common/InspectableMember.h similarity index 92% rename from src/common/inspection/InspectableMember.h rename to src/common/InspectableMember.h index dacc8336..08a7ed6e 100644 --- a/src/common/inspection/InspectableMember.h +++ b/src/common/InspectableMember.h @@ -1,7 +1,7 @@ #ifndef METAL_ENGINE_INSPECTABLEMEMBER_H #define METAL_ENGINE_INSPECTABLEMEMBER_H -#include "../../enum/FieldType.h" +#include "FieldType.h" namespace Metal { class Inspectable; diff --git a/src/common/inspection/InspectedField.h b/src/common/InspectedField.h similarity index 92% rename from src/common/inspection/InspectedField.h rename to src/common/InspectedField.h index 9c50c1ce..08b2b22e 100644 --- a/src/common/inspection/InspectedField.h +++ b/src/common/InspectedField.h @@ -4,7 +4,7 @@ #include #include "InspectableMember.h" -#include "../../enum/EntryType.h" +#include "../context/editor/enum/EntryType.h" namespace Metal { template diff --git a/src/common/inspection/InspectedMethod.h b/src/common/InspectedMethod.h similarity index 100% rename from src/common/inspection/InspectedMethod.h rename to src/common/InspectedMethod.h diff --git a/src/util/Serializable.cpp b/src/common/Serializable.cpp similarity index 86% rename from src/util/Serializable.cpp rename to src/common/Serializable.cpp index d7913ae7..98d46573 100644 --- a/src/util/Serializable.cpp +++ b/src/common/Serializable.cpp @@ -1,9 +1,9 @@ -#include "Serializable.h" -#include "../context/ApplicationContext.h" +#include "../util/Serializable.h" +#include "../ApplicationContext.h" #include #include #include -#include "../service/log/LogService.h" +#include "../context/editor/service/LogService.h" namespace Metal { void Serializable::saveToJson(const std::string &path) const { diff --git a/src/util/Serializable.h b/src/common/Serializable.h similarity index 100% rename from src/util/Serializable.h rename to src/common/Serializable.h diff --git a/src/common/interface/Synchornizable.h b/src/common/Synchornizable.h similarity index 100% rename from src/common/interface/Synchornizable.h rename to src/common/Synchornizable.h diff --git a/src/context/glfw/GLFWContext.cpp b/src/core/glfw/GLFWContext.cpp similarity index 99% rename from src/context/glfw/GLFWContext.cpp rename to src/core/glfw/GLFWContext.cpp index b819dc08..333ad510 100644 --- a/src/context/glfw/GLFWContext.cpp +++ b/src/core/glfw/GLFWContext.cpp @@ -1,7 +1,7 @@ #include #include "GLFWContext.h" #include "../ApplicationContext.h" -#include "../../util/VulkanUtils.h" +#include "../vulkan/VulkanUtils.h" namespace Metal { GLFWwindow *GLFWContext::getWindow() const { diff --git a/src/context/glfw/GLFWContext.h b/src/core/glfw/GLFWContext.h similarity index 100% rename from src/context/glfw/GLFWContext.h rename to src/core/glfw/GLFWContext.h diff --git a/src/context/gui/GuiContext.cpp b/src/core/gui/GuiContext.cpp similarity index 97% rename from src/context/gui/GuiContext.cpp rename to src/core/gui/GuiContext.cpp index f78080aa..c6ccbb2c 100644 --- a/src/context/gui/GuiContext.cpp +++ b/src/core/gui/GuiContext.cpp @@ -3,9 +3,9 @@ #include #include "imgui_freetype.h" #include "../ApplicationContext.h" -#include "../../util/VulkanUtils.h" -#include "../../service/descriptor/DescriptorInstance.h" -#include "../../service/texture/TextureInstance.h" +#include "../vulkan/VulkanUtils.h" +#include "../engine/dto/DescriptorInstance.h" +#include "../engine/resource/TextureInstance.h" namespace Metal { void GuiContext::endFrame() { diff --git a/src/context/gui/GuiContext.h b/src/core/gui/GuiContext.h similarity index 100% rename from src/context/gui/GuiContext.h rename to src/core/gui/GuiContext.h diff --git a/src/context/vulkan/VulkanContext.cpp b/src/core/vulkan/VulkanContext.cpp similarity index 99% rename from src/context/vulkan/VulkanContext.cpp rename to src/core/vulkan/VulkanContext.cpp index c2ef2593..0e5415b2 100644 --- a/src/context/vulkan/VulkanContext.cpp +++ b/src/core/vulkan/VulkanContext.cpp @@ -1,7 +1,7 @@ #include "VulkanContext.h" #include "VkBootstrap.h" -#include "../../util/VulkanUtils.h" +#include "VulkanUtils.h" #include "../ApplicationContext.h" namespace Metal { diff --git a/src/context/vulkan/VulkanContext.h b/src/core/vulkan/VulkanContext.h similarity index 100% rename from src/context/vulkan/VulkanContext.h rename to src/core/vulkan/VulkanContext.h diff --git a/src/util/VulkanUtils.cpp b/src/core/vulkan/VulkanUtils.cpp similarity index 90% rename from src/util/VulkanUtils.cpp rename to src/core/vulkan/VulkanUtils.cpp index 32bdd127..182dab58 100644 --- a/src/util/VulkanUtils.cpp +++ b/src/core/vulkan/VulkanUtils.cpp @@ -1,8 +1,8 @@ -#include "VulkanUtils.h" +#include "../../util/VulkanUtils.h" -#include "../../dependencies/vk-bootstrap/src/VkBootstrap.h" -#include "../context/ApplicationContext.h" -#include "../service/log/LogService.h" +#include "../../../dependencies/vk-bootstrap/src/VkBootstrap.h" +#include "../ApplicationContext.h" +#include "../editor/service/LogService.h" namespace Metal { void VulkanUtils::CheckVKResult(VkResult err) { diff --git a/src/util/VulkanUtils.h b/src/core/vulkan/VulkanUtils.h similarity index 100% rename from src/util/VulkanUtils.h rename to src/core/vulkan/VulkanUtils.h diff --git a/src/context/editor/EditorPanel.cpp b/src/editor/EditorPanel.cpp similarity index 97% rename from src/context/editor/EditorPanel.cpp rename to src/editor/EditorPanel.cpp index bbad6c87..2e70ba27 100644 --- a/src/context/editor/EditorPanel.cpp +++ b/src/editor/EditorPanel.cpp @@ -1,7 +1,7 @@ #include "EditorPanel.h" -#include "../../util/UIUtil.h" +#include "util/UIUtil.h" #include "../../context/ApplicationContext.h" -#include "../../dto/Notification.h" +#include "dto/Notification.h" #include "dock-spaces/header/EditorHeaderPanel.h" #include "panel/FileImportModalPanel.h" #include "panel/NotificationsPanel.h" diff --git a/src/context/editor/EditorPanel.h b/src/editor/EditorPanel.h similarity index 100% rename from src/context/editor/EditorPanel.h rename to src/editor/EditorPanel.h diff --git a/src/context/editor/abstract/AbstractPanel.cpp b/src/editor/abstract/AbstractPanel.cpp similarity index 95% rename from src/context/editor/abstract/AbstractPanel.cpp rename to src/editor/abstract/AbstractPanel.cpp index 93beda28..c4ab4cd6 100644 --- a/src/context/editor/abstract/AbstractPanel.cpp +++ b/src/editor/abstract/AbstractPanel.cpp @@ -1,5 +1,5 @@ #include "AbstractPanel.h" -#include "../../../util/Util.h" +#include "../util/Util.h" namespace Metal { void AbstractPanel::appendChild(AbstractPanel *panel) { diff --git a/src/context/editor/abstract/AbstractPanel.h b/src/editor/abstract/AbstractPanel.h similarity index 100% rename from src/context/editor/abstract/AbstractPanel.h rename to src/editor/abstract/AbstractPanel.h diff --git a/src/context/editor/abstract/IPanel.h b/src/editor/abstract/IPanel.h similarity index 67% rename from src/context/editor/abstract/IPanel.h rename to src/editor/abstract/IPanel.h index 3d024efa..8eba6fb6 100644 --- a/src/context/editor/abstract/IPanel.h +++ b/src/editor/abstract/IPanel.h @@ -1,8 +1,8 @@ #ifndef METAL_ENGINE_IPANEL_H #define METAL_ENGINE_IPANEL_H -#include "../../../common/interface/Synchornizable.h" -#include "../../../common/interface/Initializable.h" +#include "../../../common/Synchornizable.h" +#include "../../../common/Initializable.h" namespace Metal { class IPanel : public Syncronizable, public Initializable { diff --git a/src/context/editor/abstract/form/AbstractFormFieldPanel.h b/src/editor/abstract/form/AbstractFormFieldPanel.h similarity index 100% rename from src/context/editor/abstract/form/AbstractFormFieldPanel.h rename to src/editor/abstract/form/AbstractFormFieldPanel.h diff --git a/src/context/editor/abstract/form/AccordionPanel.cpp b/src/editor/abstract/form/AccordionPanel.cpp similarity index 100% rename from src/context/editor/abstract/form/AccordionPanel.cpp rename to src/editor/abstract/form/AccordionPanel.cpp diff --git a/src/context/editor/abstract/form/AccordionPanel.h b/src/editor/abstract/form/AccordionPanel.h similarity index 100% rename from src/context/editor/abstract/form/AccordionPanel.h rename to src/editor/abstract/form/AccordionPanel.h diff --git a/src/context/editor/abstract/form/ChildPanel.cpp b/src/editor/abstract/form/ChildPanel.cpp similarity index 100% rename from src/context/editor/abstract/form/ChildPanel.cpp rename to src/editor/abstract/form/ChildPanel.cpp diff --git a/src/context/editor/abstract/form/ChildPanel.h b/src/editor/abstract/form/ChildPanel.h similarity index 100% rename from src/context/editor/abstract/form/ChildPanel.h rename to src/editor/abstract/form/ChildPanel.h diff --git a/src/context/editor/abstract/form/FormPanel.cpp b/src/editor/abstract/form/FormPanel.cpp similarity index 97% rename from src/context/editor/abstract/form/FormPanel.cpp rename to src/editor/abstract/form/FormPanel.cpp index 3a48ef77..13aeb015 100644 --- a/src/context/editor/abstract/form/FormPanel.cpp +++ b/src/editor/abstract/form/FormPanel.cpp @@ -1,8 +1,8 @@ #include "FormPanel.h" #include "AccordionPanel.h" #include "ChildPanel.h" -#include "../../../../enum/FieldType.h" -#include "../../../../common/inspection/Inspectable.h" +#include "../../../../common/FieldType.h" +#include "../../../../common/Inspectable.h" #include "types/IntField.h" #include "types/FloatField.h" #include "types/BooleanField.h" diff --git a/src/context/editor/abstract/form/FormPanel.h b/src/editor/abstract/form/FormPanel.h similarity index 100% rename from src/context/editor/abstract/form/FormPanel.h rename to src/editor/abstract/form/FormPanel.h diff --git a/src/context/editor/abstract/form/types/BooleanField.cpp b/src/editor/abstract/form/types/BooleanField.cpp similarity index 93% rename from src/context/editor/abstract/form/types/BooleanField.cpp rename to src/editor/abstract/form/types/BooleanField.cpp index 38371db1..4f145c79 100644 --- a/src/context/editor/abstract/form/types/BooleanField.cpp +++ b/src/editor/abstract/form/types/BooleanField.cpp @@ -2,7 +2,7 @@ #include #include -#include "../../../../../common/inspection/Inspectable.h" +#include "../../../../../common/Inspectable.h" namespace Metal { BooleanField::BooleanField(InspectedField &field) : field(field) { diff --git a/src/context/editor/abstract/form/types/BooleanField.h b/src/editor/abstract/form/types/BooleanField.h similarity index 86% rename from src/context/editor/abstract/form/types/BooleanField.h rename to src/editor/abstract/form/types/BooleanField.h index 4cab6295..97c485d8 100644 --- a/src/context/editor/abstract/form/types/BooleanField.h +++ b/src/editor/abstract/form/types/BooleanField.h @@ -2,7 +2,7 @@ #define METAL_ENGINE_BOOLEANFIELD_H #include "../AbstractFormFieldPanel.h" -#include "../../../../../common/inspection/InspectedField.h" +#include "../../../../../common/InspectedField.h" namespace Metal { class BooleanField final : public AbstractFormFieldPanel { diff --git a/src/context/editor/abstract/form/types/ColorField.cpp b/src/editor/abstract/form/types/ColorField.cpp similarity index 95% rename from src/context/editor/abstract/form/types/ColorField.cpp rename to src/editor/abstract/form/types/ColorField.cpp index 0b8cd911..985efafc 100644 --- a/src/context/editor/abstract/form/types/ColorField.cpp +++ b/src/editor/abstract/form/types/ColorField.cpp @@ -1,7 +1,7 @@ #include "ColorField.h" #include #include -#include "../../../../../common/inspection/Inspectable.h" +#include "../../../../../common/Inspectable.h" namespace Metal { ColorField::ColorField(InspectedField &field) : field(field) { diff --git a/src/context/editor/abstract/form/types/ColorField.h b/src/editor/abstract/form/types/ColorField.h similarity index 88% rename from src/context/editor/abstract/form/types/ColorField.h rename to src/editor/abstract/form/types/ColorField.h index 87d9aaac..07ea8eef 100644 --- a/src/context/editor/abstract/form/types/ColorField.h +++ b/src/editor/abstract/form/types/ColorField.h @@ -3,7 +3,7 @@ #include #include "../AbstractFormFieldPanel.h" -#include "../../../../../common/inspection/InspectedField.h" +#include "../../../../../common/InspectedField.h" namespace Metal { class ColorField final : public AbstractFormFieldPanel { diff --git a/src/context/editor/abstract/form/types/FloatField.cpp b/src/editor/abstract/form/types/FloatField.cpp similarity index 94% rename from src/context/editor/abstract/form/types/FloatField.cpp rename to src/editor/abstract/form/types/FloatField.cpp index b431fae9..47252dc9 100644 --- a/src/context/editor/abstract/form/types/FloatField.cpp +++ b/src/editor/abstract/form/types/FloatField.cpp @@ -1,7 +1,7 @@ #include "FloatField.h" #include #include -#include "../../../../../common/inspection/Inspectable.h" +#include "../../../../../common/Inspectable.h" namespace Metal { void FloatField::onSync() { diff --git a/src/context/editor/abstract/form/types/FloatField.h b/src/editor/abstract/form/types/FloatField.h similarity index 86% rename from src/context/editor/abstract/form/types/FloatField.h rename to src/editor/abstract/form/types/FloatField.h index 41e7c8cd..509bfafa 100644 --- a/src/context/editor/abstract/form/types/FloatField.h +++ b/src/editor/abstract/form/types/FloatField.h @@ -2,7 +2,7 @@ #define METAL_ENGINE_FLOATFIELD_H #include "../AbstractFormFieldPanel.h" -#include "../../../../../common/inspection/InspectedField.h" +#include "../../../../../common/InspectedField.h" namespace Metal { diff --git a/src/context/editor/abstract/form/types/IntField.cpp b/src/editor/abstract/form/types/IntField.cpp similarity index 94% rename from src/context/editor/abstract/form/types/IntField.cpp rename to src/editor/abstract/form/types/IntField.cpp index e4187b21..7f2fc001 100644 --- a/src/context/editor/abstract/form/types/IntField.cpp +++ b/src/editor/abstract/form/types/IntField.cpp @@ -1,7 +1,7 @@ #include "IntField.h" #include #include -#include "../../../../../common/inspection/Inspectable.h" +#include "../../../../../common/Inspectable.h" namespace Metal { void IntField::onSync() { diff --git a/src/context/editor/abstract/form/types/IntField.h b/src/editor/abstract/form/types/IntField.h similarity index 86% rename from src/context/editor/abstract/form/types/IntField.h rename to src/editor/abstract/form/types/IntField.h index 6c414468..6d8a2c68 100644 --- a/src/context/editor/abstract/form/types/IntField.h +++ b/src/editor/abstract/form/types/IntField.h @@ -2,7 +2,7 @@ #define METAL_ENGINE_INTFIELD_H #include "../AbstractFormFieldPanel.h" -#include "../../../../../common/inspection/InspectedField.h" +#include "../../../../../common/InspectedField.h" namespace Metal { class IntField final : public AbstractFormFieldPanel { diff --git a/src/context/editor/abstract/form/types/MethodField.cpp b/src/editor/abstract/form/types/MethodField.cpp similarity index 100% rename from src/context/editor/abstract/form/types/MethodField.cpp rename to src/editor/abstract/form/types/MethodField.cpp diff --git a/src/context/editor/abstract/form/types/MethodField.h b/src/editor/abstract/form/types/MethodField.h similarity index 86% rename from src/context/editor/abstract/form/types/MethodField.h rename to src/editor/abstract/form/types/MethodField.h index 704a8b8c..145c8c6f 100644 --- a/src/context/editor/abstract/form/types/MethodField.h +++ b/src/editor/abstract/form/types/MethodField.h @@ -3,7 +3,7 @@ #define METAL_ENGINE_METHODFIELD_H #include "../AbstractFormFieldPanel.h" -#include "../../../../../common/inspection/InspectedMethod.h" +#include "../../../../../common/InspectedMethod.h" namespace Metal { diff --git a/src/context/editor/abstract/form/types/QuatField.cpp b/src/editor/abstract/form/types/QuatField.cpp similarity index 93% rename from src/context/editor/abstract/form/types/QuatField.cpp rename to src/editor/abstract/form/types/QuatField.cpp index 24134b71..512648bb 100644 --- a/src/context/editor/abstract/form/types/QuatField.cpp +++ b/src/editor/abstract/form/types/QuatField.cpp @@ -2,8 +2,8 @@ #include #include #include -#include "../../../../../common/inspection/Inspectable.h" -#include "../../../../../util/UIUtil.h" +#include "../../../../../common/Inspectable.h" +#include "../../../util/UIUtil.h" namespace Metal { QuatField::QuatField(InspectedField &field) : field(field) { diff --git a/src/context/editor/abstract/form/types/QuatField.h b/src/editor/abstract/form/types/QuatField.h similarity index 88% rename from src/context/editor/abstract/form/types/QuatField.h rename to src/editor/abstract/form/types/QuatField.h index c2def953..ed6cd528 100644 --- a/src/context/editor/abstract/form/types/QuatField.h +++ b/src/editor/abstract/form/types/QuatField.h @@ -2,7 +2,7 @@ #define QUATFIELD_H #include #include "../AbstractFormFieldPanel.h" -#include "../../../../../common/inspection/InspectedField.h" +#include "../../../../../common/InspectedField.h" namespace Metal { class QuatField final : public AbstractFormFieldPanel { diff --git a/src/context/editor/abstract/form/types/ResourceField.cpp b/src/editor/abstract/form/types/ResourceField.cpp similarity index 96% rename from src/context/editor/abstract/form/types/ResourceField.cpp rename to src/editor/abstract/form/types/ResourceField.cpp index 7bc9e88c..3c4fac3b 100644 --- a/src/context/editor/abstract/form/types/ResourceField.cpp +++ b/src/editor/abstract/form/types/ResourceField.cpp @@ -4,9 +4,9 @@ #include #include "ResourceFilesPanel.h" -#include "../../../../../common/interface/Icons.h" -#include "../../../../../util/UIUtil.h" -#include "../../../../../dto/file/FSEntry.h" +#include "../../../../../common/Icons.h" +#include "../../../util/UIUtil.h" +#include "../../../dto/FSEntry.h" #include "../../../../../context/ApplicationContext.h" #include "../../../../../common/inspection/Inspectable.h" diff --git a/src/context/editor/abstract/form/types/ResourceField.h b/src/editor/abstract/form/types/ResourceField.h similarity index 92% rename from src/context/editor/abstract/form/types/ResourceField.h rename to src/editor/abstract/form/types/ResourceField.h index 270b78db..308976da 100644 --- a/src/context/editor/abstract/form/types/ResourceField.h +++ b/src/editor/abstract/form/types/ResourceField.h @@ -4,7 +4,7 @@ #include #include "../AbstractFormFieldPanel.h" -#include "../../../../../common/inspection/InspectedField.h" +#include "../../../../../common/InspectedField.h" #include "imgui.h" namespace Metal { diff --git a/src/context/editor/abstract/form/types/ResourceFilesPanel.cpp b/src/editor/abstract/form/types/ResourceFilesPanel.cpp similarity index 79% rename from src/context/editor/abstract/form/types/ResourceFilesPanel.cpp rename to src/editor/abstract/form/types/ResourceFilesPanel.cpp index a74cf470..7cf50247 100644 --- a/src/context/editor/abstract/form/types/ResourceFilesPanel.cpp +++ b/src/editor/abstract/form/types/ResourceFilesPanel.cpp @@ -1,8 +1,8 @@ #include "ResourceFilesPanel.h" -#include "../../../../../common/interface/Icons.h" -#include "../../../../../dto/file/FSEntry.h" -#include "../../../../../service/files/FilesService.h" +#include "../../../../../common/Icons.h" +#include "../../../dto/FSEntry.h" +#include "../../../service/FilesService.h" namespace Metal { std::function ResourceFilesPanel::onAction() { diff --git a/src/context/editor/abstract/form/types/ResourceFilesPanel.h b/src/editor/abstract/form/types/ResourceFilesPanel.h similarity index 100% rename from src/context/editor/abstract/form/types/ResourceFilesPanel.h rename to src/editor/abstract/form/types/ResourceFilesPanel.h diff --git a/src/context/editor/abstract/form/types/StringField.cpp b/src/editor/abstract/form/types/StringField.cpp similarity index 94% rename from src/context/editor/abstract/form/types/StringField.cpp rename to src/editor/abstract/form/types/StringField.cpp index 082b6bbb..2b6ec53d 100644 --- a/src/context/editor/abstract/form/types/StringField.cpp +++ b/src/editor/abstract/form/types/StringField.cpp @@ -1,7 +1,7 @@ #include "StringField.h" #include #include -#include "../../../../../common/inspection/Inspectable.h" +#include "../../../../../common/Inspectable.h" namespace Metal { StringField::StringField(InspectedField &field) : field(field) { diff --git a/src/context/editor/abstract/form/types/StringField.h b/src/editor/abstract/form/types/StringField.h similarity index 87% rename from src/context/editor/abstract/form/types/StringField.h rename to src/editor/abstract/form/types/StringField.h index 2b786379..3e543281 100644 --- a/src/context/editor/abstract/form/types/StringField.h +++ b/src/editor/abstract/form/types/StringField.h @@ -2,7 +2,7 @@ #define STRINGFIELD_H #include "../AbstractFormFieldPanel.h" -#include "../../../../../common/inspection/InspectedField.h" +#include "../../../../../common/InspectedField.h" namespace Metal { diff --git a/src/context/editor/abstract/form/types/Vec2Field.cpp b/src/editor/abstract/form/types/Vec2Field.cpp similarity index 91% rename from src/context/editor/abstract/form/types/Vec2Field.cpp rename to src/editor/abstract/form/types/Vec2Field.cpp index d45d650d..d1d32756 100644 --- a/src/context/editor/abstract/form/types/Vec2Field.cpp +++ b/src/editor/abstract/form/types/Vec2Field.cpp @@ -1,8 +1,8 @@ #include "Vec2Field.h" #include #include -#include "../../../../../common/inspection/Inspectable.h" -#include "../../../../../util/UIUtil.h" +#include "../../../../../common/Inspectable.h" +#include "../../../util/UIUtil.h" namespace Metal { Vec2Field::Vec2Field(InspectedField &field) : field(field) { diff --git a/src/context/editor/abstract/form/types/Vec2Field.h b/src/editor/abstract/form/types/Vec2Field.h similarity index 88% rename from src/context/editor/abstract/form/types/Vec2Field.h rename to src/editor/abstract/form/types/Vec2Field.h index 11a57fc5..cbc6212e 100644 --- a/src/context/editor/abstract/form/types/Vec2Field.h +++ b/src/editor/abstract/form/types/Vec2Field.h @@ -4,7 +4,7 @@ #include #include "../AbstractFormFieldPanel.h" -#include "../../../../../common/inspection/InspectedField.h" +#include "../../../../../common/InspectedField.h" namespace Metal { class Vec2Field final : public AbstractFormFieldPanel { diff --git a/src/context/editor/abstract/form/types/Vec3Field.cpp b/src/editor/abstract/form/types/Vec3Field.cpp similarity index 92% rename from src/context/editor/abstract/form/types/Vec3Field.cpp rename to src/editor/abstract/form/types/Vec3Field.cpp index e518b42e..471f2410 100644 --- a/src/context/editor/abstract/form/types/Vec3Field.cpp +++ b/src/editor/abstract/form/types/Vec3Field.cpp @@ -1,8 +1,8 @@ #include "Vec3Field.h" #include #include -#include "../../../../../common/inspection/Inspectable.h" -#include "../../../../../util/UIUtil.h" +#include "../../../../../common/Inspectable.h" +#include "../../../util/UIUtil.h" namespace Metal { Vec3Field::Vec3Field(InspectedField &field) : field(field) { diff --git a/src/context/editor/abstract/form/types/Vec3Field.h b/src/editor/abstract/form/types/Vec3Field.h similarity index 88% rename from src/context/editor/abstract/form/types/Vec3Field.h rename to src/editor/abstract/form/types/Vec3Field.h index 0bb06e56..dbd36eab 100644 --- a/src/context/editor/abstract/form/types/Vec3Field.h +++ b/src/editor/abstract/form/types/Vec3Field.h @@ -4,7 +4,7 @@ #include #include "../AbstractFormFieldPanel.h" -#include "../../../../../common/inspection/InspectedField.h" +#include "../../../../../common/InspectedField.h" namespace Metal { diff --git a/src/context/editor/abstract/form/types/Vec4Field.cpp b/src/editor/abstract/form/types/Vec4Field.cpp similarity index 92% rename from src/context/editor/abstract/form/types/Vec4Field.cpp rename to src/editor/abstract/form/types/Vec4Field.cpp index 07cc3dde..8e5932f7 100644 --- a/src/context/editor/abstract/form/types/Vec4Field.cpp +++ b/src/editor/abstract/form/types/Vec4Field.cpp @@ -1,8 +1,8 @@ #include "Vec4Field.h" #include #include -#include "../../../../../common/inspection/Inspectable.h" -#include "../../../../../util/UIUtil.h" +#include "../../../../../common/Inspectable.h" +#include "../../../util/UIUtil.h" namespace Metal { Vec4Field::Vec4Field(InspectedField &field) : field(field) { diff --git a/src/context/editor/abstract/form/types/Vec4Field.h b/src/editor/abstract/form/types/Vec4Field.h similarity index 88% rename from src/context/editor/abstract/form/types/Vec4Field.h rename to src/editor/abstract/form/types/Vec4Field.h index 751c0efa..569fde21 100644 --- a/src/context/editor/abstract/form/types/Vec4Field.h +++ b/src/editor/abstract/form/types/Vec4Field.h @@ -3,7 +3,7 @@ #include #include "../AbstractFormFieldPanel.h" -#include "../../../../../common/inspection/InspectedField.h" +#include "../../../../../common/InspectedField.h" namespace Metal { class Vec4Field final : public AbstractFormFieldPanel { diff --git a/src/context/editor/dock-spaces/console/ConsolePanel.cpp b/src/editor/dock-spaces/console/ConsolePanel.cpp similarity index 98% rename from src/context/editor/dock-spaces/console/ConsolePanel.cpp rename to src/editor/dock-spaces/console/ConsolePanel.cpp index c358eaea..4b2e40fe 100644 --- a/src/context/editor/dock-spaces/console/ConsolePanel.cpp +++ b/src/editor/dock-spaces/console/ConsolePanel.cpp @@ -2,7 +2,7 @@ #include "imgui.h" #include "../../../ApplicationContext.h" -#include "../../../../common/interface/Icons.h" +#include "../../../../common/Icons.h" namespace Metal { ConsolePanel::ConsolePanel() { diff --git a/src/context/editor/dock-spaces/console/ConsolePanel.h b/src/editor/dock-spaces/console/ConsolePanel.h similarity index 88% rename from src/context/editor/dock-spaces/console/ConsolePanel.h rename to src/editor/dock-spaces/console/ConsolePanel.h index 8417cb14..5a6e3ae7 100644 --- a/src/context/editor/dock-spaces/console/ConsolePanel.h +++ b/src/editor/dock-spaces/console/ConsolePanel.h @@ -1,7 +1,7 @@ #ifndef CONSOLEPANEL_H #define CONSOLEPANEL_H #include "../docks/AbstractDockPanel.h" -#include "../../../../service/log/LogService.h" +#include "../../service/LogService.h" #include "imgui.h" namespace Metal { diff --git a/src/context/editor/dock-spaces/docks/AbstractDockPanel.h b/src/editor/dock-spaces/docks/AbstractDockPanel.h similarity index 93% rename from src/context/editor/dock-spaces/docks/AbstractDockPanel.h rename to src/editor/dock-spaces/docks/AbstractDockPanel.h index 3f144a8d..997ddd68 100644 --- a/src/context/editor/dock-spaces/docks/AbstractDockPanel.h +++ b/src/editor/dock-spaces/docks/AbstractDockPanel.h @@ -5,7 +5,7 @@ #include #include "../../abstract/AbstractPanel.h" -#include "../../../../dto/ShortcutDTO.h" +#include "../../dto/ShortcutDTO.h" struct ImVec2; diff --git a/src/context/editor/dock-spaces/docks/DockSpacePanel.cpp b/src/editor/dock-spaces/docks/DockSpacePanel.cpp similarity index 97% rename from src/context/editor/dock-spaces/docks/DockSpacePanel.cpp rename to src/editor/dock-spaces/docks/DockSpacePanel.cpp index e07fe1ac..6a938445 100644 --- a/src/context/editor/dock-spaces/docks/DockSpacePanel.cpp +++ b/src/editor/dock-spaces/docks/DockSpacePanel.cpp @@ -5,10 +5,10 @@ #include "AbstractDockPanel.h" #include "../../../../context/ApplicationContext.h" -#include "../../../../common/interface/Icons.h" -#include "../../../../repository/dock/DockDTO.h" -#include "../../../../util/UIUtil.h" -#include "../../../../service/log/LogService.h" +#include "../../../../common/Icons.h" +#include "../../dto/DockDTO.h" +#include "../../util/UIUtil.h" +#include "../../service/LogService.h" namespace Metal { const ImVec2 DockSpacePanel::DEFAULT{-1.f, -1.f}; diff --git a/src/context/editor/dock-spaces/docks/DockSpacePanel.h b/src/editor/dock-spaces/docks/DockSpacePanel.h similarity index 100% rename from src/context/editor/dock-spaces/docks/DockSpacePanel.h rename to src/editor/dock-spaces/docks/DockSpacePanel.h diff --git a/src/context/editor/dock-spaces/files/FilePreviewPanel.cpp b/src/editor/dock-spaces/files/FilePreviewPanel.cpp similarity index 96% rename from src/context/editor/dock-spaces/files/FilePreviewPanel.cpp rename to src/editor/dock-spaces/files/FilePreviewPanel.cpp index 7c7c050b..18365979 100644 --- a/src/context/editor/dock-spaces/files/FilePreviewPanel.cpp +++ b/src/editor/dock-spaces/files/FilePreviewPanel.cpp @@ -1,9 +1,9 @@ #include "FilePreviewPanel.h" #include -#include "../../../../util/UIUtil.h" -#include "../../../../dto/file/FSEntry.h" +#include "../../util/UIUtil.h" +#include "../../dto/FSEntry.h" #include "../../../../context/ApplicationContext.h" -#include "../../../../service/texture/TextureInstance.h" +#include "../../../engine/resource/TextureInstance.h" namespace Metal { FilePreviewPanel::FilePreviewPanel(FilesContext &filesContext) : filesContext(filesContext) { diff --git a/src/context/editor/dock-spaces/files/FilePreviewPanel.h b/src/editor/dock-spaces/files/FilePreviewPanel.h similarity index 100% rename from src/context/editor/dock-spaces/files/FilePreviewPanel.h rename to src/editor/dock-spaces/files/FilePreviewPanel.h diff --git a/src/context/editor/dock-spaces/files/FilesContext.cpp b/src/editor/dock-spaces/files/FilesContext.cpp similarity index 91% rename from src/context/editor/dock-spaces/files/FilesContext.cpp rename to src/editor/dock-spaces/files/FilesContext.cpp index bd74434c..a85c2ef5 100644 --- a/src/context/editor/dock-spaces/files/FilesContext.cpp +++ b/src/editor/dock-spaces/files/FilesContext.cpp @@ -1,6 +1,6 @@ #include "FilesContext.h" -#include "../../../../dto/file/FSEntry.h" +#include "../../dto/FSEntry.h" #include namespace Metal { diff --git a/src/context/editor/dock-spaces/files/FilesContext.h b/src/editor/dock-spaces/files/FilesContext.h similarity index 94% rename from src/context/editor/dock-spaces/files/FilesContext.h rename to src/editor/dock-spaces/files/FilesContext.h index d50da76a..f7d32d0e 100644 --- a/src/context/editor/dock-spaces/files/FilesContext.h +++ b/src/editor/dock-spaces/files/FilesContext.h @@ -3,7 +3,7 @@ #include #include -#include "../../../../enum/EntryType.h" +#include "../../enum/EntryType.h" namespace Metal { diff --git a/src/context/editor/dock-spaces/files/FilesHeaderPanel.cpp b/src/editor/dock-spaces/files/FilesHeaderPanel.cpp similarity index 89% rename from src/context/editor/dock-spaces/files/FilesHeaderPanel.cpp rename to src/editor/dock-spaces/files/FilesHeaderPanel.cpp index 3924fb73..8a0f737b 100644 --- a/src/context/editor/dock-spaces/files/FilesHeaderPanel.cpp +++ b/src/editor/dock-spaces/files/FilesHeaderPanel.cpp @@ -1,11 +1,11 @@ #include "FilesHeaderPanel.h" -#include "../../../../enum/EntryType.h" -#include "../../../../dto/file/FSEntry.h" -#include "../../../../common/interface/Icons.h" -#include "../../../../util/FilesUtil.h" +#include "../../enum/EntryType.h" +#include "../../dto/FSEntry.h" +#include "../../../../common/Icons.h" +#include "../../util/FilesUtil.h" #include "../../../../context/ApplicationContext.h" -#include "../../../../util/UIUtil.h" +#include "../../util/UIUtil.h" namespace Metal { void FilesHeaderPanel::onSync() { diff --git a/src/context/editor/dock-spaces/files/FilesHeaderPanel.h b/src/editor/dock-spaces/files/FilesHeaderPanel.h similarity index 100% rename from src/context/editor/dock-spaces/files/FilesHeaderPanel.h rename to src/editor/dock-spaces/files/FilesHeaderPanel.h diff --git a/src/context/editor/dock-spaces/files/FilesListPanel.cpp b/src/editor/dock-spaces/files/FilesListPanel.cpp similarity index 98% rename from src/context/editor/dock-spaces/files/FilesListPanel.cpp rename to src/editor/dock-spaces/files/FilesListPanel.cpp index 54f75cd0..62bb60c0 100644 --- a/src/context/editor/dock-spaces/files/FilesListPanel.cpp +++ b/src/editor/dock-spaces/files/FilesListPanel.cpp @@ -2,10 +2,10 @@ #include "FilesPanel.h" #include "FilesContext.h" -#include "../../../../util/UIUtil.h" +#include "../../util/UIUtil.h" #include "../../../../context/ApplicationContext.h" -#include "../../../../dto/file//FSEntry.h" -#include "../../../../service/files/FilesService.h" +#include "../../dto/FSEntry.h" +#include "../../service/FilesService.h" #include namespace Metal { diff --git a/src/context/editor/dock-spaces/files/FilesListPanel.h b/src/editor/dock-spaces/files/FilesListPanel.h similarity index 100% rename from src/context/editor/dock-spaces/files/FilesListPanel.h rename to src/editor/dock-spaces/files/FilesListPanel.h diff --git a/src/context/editor/dock-spaces/files/FilesPanel.cpp b/src/editor/dock-spaces/files/FilesPanel.cpp similarity index 95% rename from src/context/editor/dock-spaces/files/FilesPanel.cpp rename to src/editor/dock-spaces/files/FilesPanel.cpp index 32f0e537..ab444e51 100644 --- a/src/context/editor/dock-spaces/files/FilesPanel.cpp +++ b/src/editor/dock-spaces/files/FilesPanel.cpp @@ -3,20 +3,20 @@ #include "FilesHeaderPanel.h" #include "FilesListPanel.h" -#include "../../../../common/interface/Icons.h" +#include "../../../../common/Icons.h" #include "../../../../context/ApplicationContext.h" -#include "../../../../service/mesh/SceneData.h" -#include "../../../../util/UIUtil.h" -#include "../../../../dto/file/FSEntry.h" -#include "../../../../dto/file/SceneImportSettingsDTO.h" +#include "../../dto/SceneData.h" +#include "../../util/UIUtil.h" +#include "../../dto/FSEntry.h" +#include "../../dto/SceneImportSettingsDTO.h" #include "FilesContext.h" -#include "../../../../util/FileDialogUtil.h" +#include "../../util/FileDialogUtil.h" #include "FilePreviewPanel.h" #include "../../abstract/form/FormPanel.h" #include #include -#include "../../../../util/FilesUtil.h" +#include "../../util/FilesUtil.h" namespace Metal { std::string FilesPanel::getActionLabel() { diff --git a/src/context/editor/dock-spaces/files/FilesPanel.h b/src/editor/dock-spaces/files/FilesPanel.h similarity index 95% rename from src/context/editor/dock-spaces/files/FilesPanel.h rename to src/editor/dock-spaces/files/FilesPanel.h index 6643805e..ea127a9f 100644 --- a/src/context/editor/dock-spaces/files/FilesPanel.h +++ b/src/editor/dock-spaces/files/FilesPanel.h @@ -6,7 +6,7 @@ #include "FilesContext.h" #include "../docks/AbstractDockPanel.h" -#include "../../../../dto/file/ImportSettingsDTO.h" +#include "../../dto/ImportSettingsDTO.h" namespace Metal { struct FSEntry; diff --git a/src/context/editor/dock-spaces/header/AsyncTaskPanel.cpp b/src/editor/dock-spaces/header/AsyncTaskPanel.cpp similarity index 98% rename from src/context/editor/dock-spaces/header/AsyncTaskPanel.cpp rename to src/editor/dock-spaces/header/AsyncTaskPanel.cpp index 80db3d2c..ba3626bc 100644 --- a/src/context/editor/dock-spaces/header/AsyncTaskPanel.cpp +++ b/src/editor/dock-spaces/header/AsyncTaskPanel.cpp @@ -1,6 +1,6 @@ #include "AsyncTaskPanel.h" #include "../../../../context/ApplicationContext.h" -#include "../../../../util/UIUtil.h" +#include "../../util/UIUtil.h" #include namespace Metal { diff --git a/src/context/editor/dock-spaces/header/AsyncTaskPanel.h b/src/editor/dock-spaces/header/AsyncTaskPanel.h similarity index 100% rename from src/context/editor/dock-spaces/header/AsyncTaskPanel.h rename to src/editor/dock-spaces/header/AsyncTaskPanel.h diff --git a/src/context/editor/dock-spaces/header/EditorHeaderPanel.cpp b/src/editor/dock-spaces/header/EditorHeaderPanel.cpp similarity index 98% rename from src/context/editor/dock-spaces/header/EditorHeaderPanel.cpp rename to src/editor/dock-spaces/header/EditorHeaderPanel.cpp index 01591466..719902c8 100644 --- a/src/context/editor/dock-spaces/header/EditorHeaderPanel.cpp +++ b/src/editor/dock-spaces/header/EditorHeaderPanel.cpp @@ -1,6 +1,6 @@ #include "EditorHeaderPanel.h" #include "AsyncTaskPanel.h" -#include "../../../../util/UIUtil.h" +#include "../../util/UIUtil.h" #include "../../../../context/ApplicationContext.h" namespace Metal { diff --git a/src/context/editor/dock-spaces/header/EditorHeaderPanel.h b/src/editor/dock-spaces/header/EditorHeaderPanel.h similarity index 100% rename from src/context/editor/dock-spaces/header/EditorHeaderPanel.h rename to src/editor/dock-spaces/header/EditorHeaderPanel.h diff --git a/src/context/editor/dock-spaces/inspector/InspectorPanel.cpp b/src/editor/dock-spaces/inspector/InspectorPanel.cpp similarity index 94% rename from src/context/editor/dock-spaces/inspector/InspectorPanel.cpp rename to src/editor/dock-spaces/inspector/InspectorPanel.cpp index 9a09e624..bd827a58 100644 --- a/src/context/editor/dock-spaces/inspector/InspectorPanel.cpp +++ b/src/editor/dock-spaces/inspector/InspectorPanel.cpp @@ -1,10 +1,10 @@ #include "InspectorPanel.h" #include "../../abstract/form/FormPanel.h" -#include "../../../../util/UIUtil.h" -#include "../../../../common/inspection/Inspectable.h" +#include "../../util/UIUtil.h" +#include "../../../../common/Inspectable.h" #include "../../../../context/ApplicationContext.h" -#include "../../../../repository/world/impl/MetadataComponent.h" +#include "../../../engine/dto/MetadataComponent.h" #include #include diff --git a/src/context/editor/dock-spaces/inspector/InspectorPanel.h b/src/editor/dock-spaces/inspector/InspectorPanel.h similarity index 91% rename from src/context/editor/dock-spaces/inspector/InspectorPanel.h rename to src/editor/dock-spaces/inspector/InspectorPanel.h index 5d024e96..69a3c411 100644 --- a/src/context/editor/dock-spaces/inspector/InspectorPanel.h +++ b/src/editor/dock-spaces/inspector/InspectorPanel.h @@ -1,7 +1,7 @@ #ifndef INSPECTOR_H #define INSPECTOR_H -#include "../../../../enum/engine-definitions.h" +#include "../../enum/engine-definitions.h" #include "../docks/AbstractDockPanel.h" namespace Metal { diff --git a/src/context/editor/dock-spaces/metrics/MetricsPanel.cpp b/src/editor/dock-spaces/metrics/MetricsPanel.cpp similarity index 100% rename from src/context/editor/dock-spaces/metrics/MetricsPanel.cpp rename to src/editor/dock-spaces/metrics/MetricsPanel.cpp diff --git a/src/context/editor/dock-spaces/metrics/MetricsPanel.h b/src/editor/dock-spaces/metrics/MetricsPanel.h similarity index 100% rename from src/context/editor/dock-spaces/metrics/MetricsPanel.h rename to src/editor/dock-spaces/metrics/MetricsPanel.h diff --git a/src/context/editor/dock-spaces/repositories/RepositoriesPanel.cpp b/src/editor/dock-spaces/repositories/RepositoriesPanel.cpp similarity index 91% rename from src/context/editor/dock-spaces/repositories/RepositoriesPanel.cpp rename to src/editor/dock-spaces/repositories/RepositoriesPanel.cpp index 19af1c73..20ba7d80 100644 --- a/src/context/editor/dock-spaces/repositories/RepositoriesPanel.cpp +++ b/src/editor/dock-spaces/repositories/RepositoriesPanel.cpp @@ -1,7 +1,7 @@ #include "RepositoriesPanel.h" #include "../../abstract/form/FormPanel.h" #include "../../../../context/ApplicationContext.h" -#include "../../../../common/inspection/Inspectable.h" +#include "../../../../common/Inspectable.h" namespace Metal { void RepositoriesPanel::onInitialize() { diff --git a/src/context/editor/dock-spaces/repositories/RepositoriesPanel.h b/src/editor/dock-spaces/repositories/RepositoriesPanel.h similarity index 100% rename from src/context/editor/dock-spaces/repositories/RepositoriesPanel.h rename to src/editor/dock-spaces/repositories/RepositoriesPanel.h diff --git a/src/context/editor/dock-spaces/viewport/CameraPositionPanel.cpp b/src/editor/dock-spaces/viewport/CameraPositionPanel.cpp similarity index 94% rename from src/context/editor/dock-spaces/viewport/CameraPositionPanel.cpp rename to src/editor/dock-spaces/viewport/CameraPositionPanel.cpp index e84ed0b5..7ae495d5 100644 --- a/src/context/editor/dock-spaces/viewport/CameraPositionPanel.cpp +++ b/src/editor/dock-spaces/viewport/CameraPositionPanel.cpp @@ -1,8 +1,8 @@ #include "CameraPositionPanel.h" #include "../../../../context/ApplicationContext.h" -#include "../../../../util/UIUtil.h" -#include "../../../../service/camera/Camera.h" +#include "../../util/UIUtil.h" +#include "../../../engine/dto/Camera.h" namespace Metal { void CameraPositionPanel::onSync() { diff --git a/src/context/editor/dock-spaces/viewport/CameraPositionPanel.h b/src/editor/dock-spaces/viewport/CameraPositionPanel.h similarity index 100% rename from src/context/editor/dock-spaces/viewport/CameraPositionPanel.h rename to src/editor/dock-spaces/viewport/CameraPositionPanel.h diff --git a/src/context/editor/dock-spaces/viewport/EngineFramePanel.cpp b/src/editor/dock-spaces/viewport/EngineFramePanel.cpp similarity index 92% rename from src/context/editor/dock-spaces/viewport/EngineFramePanel.cpp rename to src/editor/dock-spaces/viewport/EngineFramePanel.cpp index d1bdc025..5bcd3602 100644 --- a/src/context/editor/dock-spaces/viewport/EngineFramePanel.cpp +++ b/src/editor/dock-spaces/viewport/EngineFramePanel.cpp @@ -2,15 +2,15 @@ #include "../../../../context/ApplicationContext.h" #include "../../../../context/engine/frame-builder/EngineFrameBuilder.h" #include "../../../../context/engine/frame-builder/EngineFrame.h" -#include "../../../../service/descriptor/DescriptorInstance.h" -#include "../../../../service/framebuffer/FrameBufferInstance.h" -#include "../../../../service/picking/PickingService.h" -#include "../../../../enum/engine-definitions.h" -#include "../../../../enum/EngineResourceIDs.h" -#include "../../../../dto/buffers/GlobalDataUBO.h" -#include "../../../../dto/buffers/LightData.h" -#include "../../../../dto/buffers/VolumeData.h" -#include "../../../../dto/buffers/MeshMetadata.h" +#include "../../../engine/dto/DescriptorInstance.h" +#include "../../../engine/resource/FrameBufferInstance.h" +#include "../../service/PickingService.h" +#include "../../enum/engine-definitions.h" +#include "../../enum/EngineResourceIDs.h" +#include "../../../engine/dto/GlobalDataUBO.h" +#include "../../../engine/dto/LightData.h" +#include "../../../engine/dto/VolumeData.h" +#include "../../../engine/dto/MeshMetadata.h" #include "ViewportHeaderPanel.h" #include "ImGuizmo.h" #include diff --git a/src/context/editor/dock-spaces/viewport/EngineFramePanel.h b/src/editor/dock-spaces/viewport/EngineFramePanel.h similarity index 100% rename from src/context/editor/dock-spaces/viewport/EngineFramePanel.h rename to src/editor/dock-spaces/viewport/EngineFramePanel.h diff --git a/src/context/editor/dock-spaces/viewport/GizmoPanel.cpp b/src/editor/dock-spaces/viewport/GizmoPanel.cpp similarity index 97% rename from src/context/editor/dock-spaces/viewport/GizmoPanel.cpp rename to src/editor/dock-spaces/viewport/GizmoPanel.cpp index b8585135..00106002 100644 --- a/src/context/editor/dock-spaces/viewport/GizmoPanel.cpp +++ b/src/editor/dock-spaces/viewport/GizmoPanel.cpp @@ -1,8 +1,8 @@ #include "GizmoPanel.h" #include "../../../../context/ApplicationContext.h" -#include "../../../../repository/world/components/TransformComponent.h" -#include "../../../../service/camera/Camera.h" +#include "../../../engine/dto/TransformComponent.h" +#include "../../../engine/dto/Camera.h" #include "ImGuizmo.h" #include #define GLM_ENABLE_EXPERIMENTAL diff --git a/src/context/editor/dock-spaces/viewport/GizmoPanel.h b/src/editor/dock-spaces/viewport/GizmoPanel.h similarity index 100% rename from src/context/editor/dock-spaces/viewport/GizmoPanel.h rename to src/editor/dock-spaces/viewport/GizmoPanel.h diff --git a/src/context/editor/dock-spaces/viewport/GizmoSettingsPanel.cpp b/src/editor/dock-spaces/viewport/GizmoSettingsPanel.cpp similarity index 99% rename from src/context/editor/dock-spaces/viewport/GizmoSettingsPanel.cpp rename to src/editor/dock-spaces/viewport/GizmoSettingsPanel.cpp index 3d2638d9..e8cc266b 100644 --- a/src/context/editor/dock-spaces/viewport/GizmoSettingsPanel.cpp +++ b/src/editor/dock-spaces/viewport/GizmoSettingsPanel.cpp @@ -1,5 +1,5 @@ #include "GizmoSettingsPanel.h" -#include "../../../../util/UIUtil.h" +#include "../../util/UIUtil.h" #include "../../../../context/ApplicationContext.h" #include "ImGuizmo.h" diff --git a/src/context/editor/dock-spaces/viewport/GizmoSettingsPanel.h b/src/editor/dock-spaces/viewport/GizmoSettingsPanel.h similarity index 96% rename from src/context/editor/dock-spaces/viewport/GizmoSettingsPanel.h rename to src/editor/dock-spaces/viewport/GizmoSettingsPanel.h index aec3a185..0c68b751 100644 --- a/src/context/editor/dock-spaces/viewport/GizmoSettingsPanel.h +++ b/src/editor/dock-spaces/viewport/GizmoSettingsPanel.h @@ -3,7 +3,7 @@ #include #include -#include "../../../../enum/engine-definitions.h" +#include "../../enum/engine-definitions.h" #include "../../abstract/AbstractPanel.h" namespace Metal { diff --git a/src/context/editor/dock-spaces/viewport/ViewportHeaderPanel.cpp b/src/editor/dock-spaces/viewport/ViewportHeaderPanel.cpp similarity index 98% rename from src/context/editor/dock-spaces/viewport/ViewportHeaderPanel.cpp rename to src/editor/dock-spaces/viewport/ViewportHeaderPanel.cpp index 945b926e..9345dea2 100644 --- a/src/context/editor/dock-spaces/viewport/ViewportHeaderPanel.cpp +++ b/src/editor/dock-spaces/viewport/ViewportHeaderPanel.cpp @@ -2,7 +2,7 @@ #include "GizmoSettingsPanel.h" #include "../../../../context/ApplicationContext.h" -#include "../../../../util/UIUtil.h" +#include "../../util/UIUtil.h" namespace Metal { void ViewportHeaderPanel::onInitialize() { diff --git a/src/context/editor/dock-spaces/viewport/ViewportHeaderPanel.h b/src/editor/dock-spaces/viewport/ViewportHeaderPanel.h similarity index 100% rename from src/context/editor/dock-spaces/viewport/ViewportHeaderPanel.h rename to src/editor/dock-spaces/viewport/ViewportHeaderPanel.h diff --git a/src/context/editor/dock-spaces/viewport/ViewportPanel.cpp b/src/editor/dock-spaces/viewport/ViewportPanel.cpp similarity index 98% rename from src/context/editor/dock-spaces/viewport/ViewportPanel.cpp rename to src/editor/dock-spaces/viewport/ViewportPanel.cpp index 4d283a47..e4e051a2 100644 --- a/src/context/editor/dock-spaces/viewport/ViewportPanel.cpp +++ b/src/editor/dock-spaces/viewport/ViewportPanel.cpp @@ -6,9 +6,9 @@ #include "ViewportHeaderPanel.h" #include "EngineFramePanel.h" #include "../../../../context/ApplicationContext.h" -#include "../../../../service/camera/Camera.h" +#include "../../../engine/dto/Camera.h" #include "../../../../context/engine/frame-builder/EngineFrameBuilder.h" -#include "../../../../enum/engine-definitions.h" +#include "../../enum/engine-definitions.h" #include namespace Metal { diff --git a/src/context/editor/dock-spaces/viewport/ViewportPanel.h b/src/editor/dock-spaces/viewport/ViewportPanel.h similarity index 100% rename from src/context/editor/dock-spaces/viewport/ViewportPanel.h rename to src/editor/dock-spaces/viewport/ViewportPanel.h diff --git a/src/context/editor/dock-spaces/world/WorldHeaderPanel.cpp b/src/editor/dock-spaces/world/WorldHeaderPanel.cpp similarity index 95% rename from src/context/editor/dock-spaces/world/WorldHeaderPanel.cpp rename to src/editor/dock-spaces/world/WorldHeaderPanel.cpp index 98b04ce1..13306c06 100644 --- a/src/context/editor/dock-spaces/world/WorldHeaderPanel.cpp +++ b/src/editor/dock-spaces/world/WorldHeaderPanel.cpp @@ -1,8 +1,8 @@ #include "WorldHeaderPanel.h" #include "../../../../context/ApplicationContext.h" -#include "../../../../util/UIUtil.h" -#include "../../../../enum/ComponentType.h" +#include "../../util/UIUtil.h" +#include "../../../engine/enum/ComponentType.h" namespace Metal { void WorldHeaderPanel::onSync() { diff --git a/src/context/editor/dock-spaces/world/WorldHeaderPanel.h b/src/editor/dock-spaces/world/WorldHeaderPanel.h similarity index 100% rename from src/context/editor/dock-spaces/world/WorldHeaderPanel.h rename to src/editor/dock-spaces/world/WorldHeaderPanel.h diff --git a/src/context/editor/dock-spaces/world/WorldPanel.cpp b/src/editor/dock-spaces/world/WorldPanel.cpp similarity index 97% rename from src/context/editor/dock-spaces/world/WorldPanel.cpp rename to src/editor/dock-spaces/world/WorldPanel.cpp index ac2265da..33a1c993 100644 --- a/src/context/editor/dock-spaces/world/WorldPanel.cpp +++ b/src/editor/dock-spaces/world/WorldPanel.cpp @@ -1,11 +1,11 @@ #include "WorldPanel.h" #include "WorldHeaderPanel.h" -#include "../../../../common/interface/Icons.h" -#include "../../../../util/UIUtil.h" +#include "../../../../common/Icons.h" +#include "../../util/UIUtil.h" #include "../../../../context/ApplicationContext.h" -#include "../../../../repository/world/impl/MetadataComponent.h" -#include "../../../../enum/ComponentType.h" +#include "../../../engine/dto/MetadataComponent.h" +#include "../../../engine/enum/ComponentType.h" namespace Metal { void WorldPanel::onInitialize() { diff --git a/src/context/editor/dock-spaces/world/WorldPanel.h b/src/editor/dock-spaces/world/WorldPanel.h similarity index 94% rename from src/context/editor/dock-spaces/world/WorldPanel.h rename to src/editor/dock-spaces/world/WorldPanel.h index a6e87e81..920c7f70 100644 --- a/src/context/editor/dock-spaces/world/WorldPanel.h +++ b/src/editor/dock-spaces/world/WorldPanel.h @@ -3,8 +3,8 @@ #include #include -#include "../../../../enum/engine-definitions.h" -#include "../../../../enum/ComponentType.h" +#include "../../enum/engine-definitions.h" +#include "../../../engine/enum/ComponentType.h" #include "../docks/AbstractDockPanel.h" namespace Metal { diff --git a/src/service/notification/AsyncTask.h b/src/editor/dto/AsyncTask.h similarity index 100% rename from src/service/notification/AsyncTask.h rename to src/editor/dto/AsyncTask.h diff --git a/src/repository/dock/DockDTO.h b/src/editor/dto/DockDTO.h similarity index 93% rename from src/repository/dock/DockDTO.h rename to src/editor/dto/DockDTO.h index 60a8109f..b80af738 100644 --- a/src/repository/dock/DockDTO.h +++ b/src/editor/dto/DockDTO.h @@ -4,9 +4,8 @@ #include #include #include -#include "DockSpace.h" -#include "DockPosition.h" -#include "../../util/Util.h" +#include "../../../repository/dock/DockSpace.h" +#include "../util/Util.h" namespace Metal { struct DockDTO { diff --git a/src/repository/dock/DockSpace.cpp b/src/editor/dto/DockSpace.cpp similarity index 70% rename from src/repository/dock/DockSpace.cpp rename to src/editor/dto/DockSpace.cpp index ce757cbc..810fc661 100644 --- a/src/repository/dock/DockSpace.cpp +++ b/src/editor/dto/DockSpace.cpp @@ -1,12 +1,12 @@ -#include "DockSpace.h" -#include "../../common/interface/Icons.h" -#include "../../context/editor/dock-spaces/console/ConsolePanel.h" -#include "../../context/editor/dock-spaces/files/FilesPanel.h" -#include "../../context/editor/dock-spaces/metrics/MetricsPanel.h" -#include "../../context/editor/dock-spaces/repositories/RepositoriesPanel.h" -#include "../../context/editor/dock-spaces/inspector/InspectorPanel.h" -#include "../../context/editor/dock-spaces/viewport/ViewportPanel.h" -#include "../../context/editor/dock-spaces/world/WorldPanel.h" +#include "../../../repository/dock/DockSpace.h" +#include "../../../common/Icons.h" +#include "../dock-spaces/console/ConsolePanel.h" +#include "../dock-spaces/files/FilesPanel.h" +#include "../dock-spaces/metrics/MetricsPanel.h" +#include "../dock-spaces/repositories/RepositoriesPanel.h" +#include "../dock-spaces/inspector/InspectorPanel.h" +#include "../dock-spaces/viewport/ViewportPanel.h" +#include "../dock-spaces/world/WorldPanel.h" #define CB(clazz) []() { return new clazz; } diff --git a/src/repository/dock/DockSpace.h b/src/editor/dto/DockSpace.h similarity index 100% rename from src/repository/dock/DockSpace.h rename to src/editor/dto/DockSpace.h diff --git a/src/dto/file/EntryMetadata.h b/src/editor/dto/EntryMetadata.h similarity index 90% rename from src/dto/file/EntryMetadata.h rename to src/editor/dto/EntryMetadata.h index e16e5628..4ab792f6 100644 --- a/src/dto/file/EntryMetadata.h +++ b/src/editor/dto/EntryMetadata.h @@ -2,9 +2,9 @@ #define FILEMETADATA_H #include -#include "../../util/Util.h" -#include "../../enum/EntryType.h" -#include "../../util/Serializable.h" +#include "../util/Util.h" +#include "../enum/EntryType.h" +#include "../../../common/Serializable.h" namespace Metal { struct EntryMetadata : Serializable { diff --git a/src/dto/file/FSEntry.h b/src/editor/dto/FSEntry.h similarity index 95% rename from src/dto/file/FSEntry.h rename to src/editor/dto/FSEntry.h index 099b3b1a..03cd72c4 100644 --- a/src/dto/file/FSEntry.h +++ b/src/editor/dto/FSEntry.h @@ -2,7 +2,7 @@ #define FILEENTRY_H #include -#include "../../util/Util.h" +#include "../util/Util.h" #include "EntryMetadata.h" namespace Metal { diff --git a/src/dto/push-constant/GridPushConstant.h b/src/editor/dto/GridPushConstant.h similarity index 100% rename from src/dto/push-constant/GridPushConstant.h rename to src/editor/dto/GridPushConstant.h diff --git a/src/dto/file/ImportSettingsDTO.h b/src/editor/dto/ImportSettingsDTO.h similarity index 86% rename from src/dto/file/ImportSettingsDTO.h rename to src/editor/dto/ImportSettingsDTO.h index 403ba57e..e6d48c90 100644 --- a/src/dto/file/ImportSettingsDTO.h +++ b/src/editor/dto/ImportSettingsDTO.h @@ -1,7 +1,7 @@ #ifndef IMPORTSETTINGSDTO_H #define IMPORTSETTINGSDTO_H -#include "../../common/inspection/Inspectable.h" +#include "../../../common/Inspectable.h" namespace Metal { diff --git a/src/dto/Notification.h b/src/editor/dto/Notification.h similarity index 100% rename from src/dto/Notification.h rename to src/editor/dto/Notification.h diff --git a/src/service/voxel/impl/OctreeNode.cpp b/src/editor/dto/OctreeNode.cpp similarity index 94% rename from src/service/voxel/impl/OctreeNode.cpp rename to src/editor/dto/OctreeNode.cpp index e57248ac..dce3c2ed 100644 --- a/src/service/voxel/impl/OctreeNode.cpp +++ b/src/editor/dto/OctreeNode.cpp @@ -1,4 +1,4 @@ -#include "OctreeNode.h" +#include "../../../service/voxel/impl/OctreeNode.h" namespace Metal { void OctreeNode::addChild(OctreeNode *child, int index) { diff --git a/src/service/voxel/impl/OctreeNode.h b/src/editor/dto/OctreeNode.h similarity index 97% rename from src/service/voxel/impl/OctreeNode.h rename to src/editor/dto/OctreeNode.h index 134d7bb5..6844a46f 100644 --- a/src/service/voxel/impl/OctreeNode.h +++ b/src/editor/dto/OctreeNode.h @@ -3,7 +3,7 @@ #include #include -#include "VoxelData.h" +#include "../../engine/dto/VoxelData.h" namespace Metal { struct OctreeNode final { diff --git a/src/service/mesh/SceneData.h b/src/editor/dto/SceneData.h similarity index 95% rename from src/service/mesh/SceneData.h rename to src/editor/dto/SceneData.h index 852bbd8f..6e52f84b 100644 --- a/src/service/mesh/SceneData.h +++ b/src/editor/dto/SceneData.h @@ -3,7 +3,7 @@ #include #include "SceneEntityData.h" -#include "../../util/Serializable.h" +#include "../../../common/Serializable.h" namespace Metal { diff --git a/src/service/mesh/SceneEntityData.h b/src/editor/dto/SceneEntityData.h similarity index 83% rename from src/service/mesh/SceneEntityData.h rename to src/editor/dto/SceneEntityData.h index 0e60b9f8..48dbf3e9 100644 --- a/src/service/mesh/SceneEntityData.h +++ b/src/editor/dto/SceneEntityData.h @@ -1,9 +1,9 @@ #ifndef METAL_ENGINE_SCENEENTITYDATA_H #define METAL_ENGINE_SCENEENTITYDATA_H #include -#include "../../repository/world/components/PrimitiveComponent.h" -#include "../../repository/world/components/TransformComponent.h" -#include "../../repository/world/impl/MetadataComponent.h" +#include "../../engine/dto/PrimitiveComponent.h" +#include "../../engine/dto/TransformComponent.h" +#include "../../engine/dto/MetadataComponent.h" namespace Metal { diff --git a/src/dto/file/SceneImportSettingsDTO.h b/src/editor/dto/SceneImportSettingsDTO.h similarity index 100% rename from src/dto/file/SceneImportSettingsDTO.h rename to src/editor/dto/SceneImportSettingsDTO.h diff --git a/src/dto/push-constant/SelectedDotPushConstant.h b/src/editor/dto/SelectedDotPushConstant.h similarity index 100% rename from src/dto/push-constant/SelectedDotPushConstant.h rename to src/editor/dto/SelectedDotPushConstant.h diff --git a/src/dto/ShortcutDTO.h b/src/editor/dto/ShortcutDTO.h similarity index 100% rename from src/dto/ShortcutDTO.h rename to src/editor/dto/ShortcutDTO.h diff --git a/src/service/voxel/impl/SparseVoxelOctreeBuilder.cpp b/src/editor/dto/SparseVoxelOctreeBuilder.cpp similarity index 97% rename from src/service/voxel/impl/SparseVoxelOctreeBuilder.cpp rename to src/editor/dto/SparseVoxelOctreeBuilder.cpp index 4bfb325f..8a6c70f4 100644 --- a/src/service/voxel/impl/SparseVoxelOctreeBuilder.cpp +++ b/src/editor/dto/SparseVoxelOctreeBuilder.cpp @@ -1,4 +1,4 @@ -#include "SparseVoxelOctreeBuilder.h" +#include "../../../service/voxel/impl/SparseVoxelOctreeBuilder.h" namespace Metal { void SparseVoxelOctreeBuilder::insert(int maxDepth, glm::vec3 point, VoxelData data) { diff --git a/src/service/voxel/impl/SparseVoxelOctreeBuilder.h b/src/editor/dto/SparseVoxelOctreeBuilder.h similarity index 95% rename from src/service/voxel/impl/SparseVoxelOctreeBuilder.h rename to src/editor/dto/SparseVoxelOctreeBuilder.h index 470fdd9f..d329476b 100644 --- a/src/service/voxel/impl/SparseVoxelOctreeBuilder.h +++ b/src/editor/dto/SparseVoxelOctreeBuilder.h @@ -2,7 +2,7 @@ #define SPARSEVOXELOCTREE_H #include "OctreeNode.h" -#include "../../../repository/world/impl/BoundingBox.h" +#include "../../engine/dto/BoundingBox.h" namespace Metal { class SparseVoxelOctreeBuilder; diff --git a/src/enum/EngineResourceIDs.h b/src/editor/enum/EngineResourceIDs.h similarity index 100% rename from src/enum/EngineResourceIDs.h rename to src/editor/enum/EngineResourceIDs.h diff --git a/src/enum/EntryType.h b/src/editor/enum/EntryType.h similarity index 100% rename from src/enum/EntryType.h rename to src/editor/enum/EntryType.h diff --git a/src/enum/NotificationSeverity.h b/src/editor/enum/NotificationSeverity.h similarity index 96% rename from src/enum/NotificationSeverity.h rename to src/editor/enum/NotificationSeverity.h index 53806f6d..9c0b303b 100644 --- a/src/enum/NotificationSeverity.h +++ b/src/editor/enum/NotificationSeverity.h @@ -2,7 +2,7 @@ #define NOTIFICATIONSEVERITY_H #include -#include "../common/interface/Icons.h" +#include "../../../common/Icons.h" namespace Metal::NotificationSeverities { enum NotificationSeverity { diff --git a/src/enum/ShadingMode.h b/src/editor/enum/ShadingMode.h similarity index 98% rename from src/enum/ShadingMode.h rename to src/editor/enum/ShadingMode.h index 4a296079..f3108cf1 100644 --- a/src/enum/ShadingMode.h +++ b/src/editor/enum/ShadingMode.h @@ -4,7 +4,7 @@ #include #include -#include "../common/interface/Icons.h" +#include "../../../common/Icons.h" namespace Metal { enum ShadingMode { diff --git a/src/enum/engine-definitions.h b/src/editor/enum/engine-definitions.h similarity index 97% rename from src/enum/engine-definitions.h rename to src/editor/enum/engine-definitions.h index cb8984f8..b3496556 100644 --- a/src/enum/engine-definitions.h +++ b/src/editor/enum/engine-definitions.h @@ -4,9 +4,9 @@ #include #define MAX_VOLUMES 300 #define MAX_LIGHTS 300 -#define MAX_MATERIALS 100 #define MAX_MESH_INSTANCES 1000 #define EMPTY_ENTITY entt::null + #define FILE_METADATA ".mjson" #define FILE_SCENE "-scene" #define FILE_MESH "-mesh" diff --git a/src/context/editor/panel/FileImportModalPanel.cpp b/src/editor/panel/FileImportModalPanel.cpp similarity index 99% rename from src/context/editor/panel/FileImportModalPanel.cpp rename to src/editor/panel/FileImportModalPanel.cpp index 2e22bab1..0f002400 100644 --- a/src/context/editor/panel/FileImportModalPanel.cpp +++ b/src/editor/panel/FileImportModalPanel.cpp @@ -3,7 +3,7 @@ #include #include #include "../../ApplicationContext.h" -#include "../../../util/FilesUtil.h" +#include "../util/FilesUtil.h" #include "../abstract/form/FormPanel.h" namespace Metal { diff --git a/src/context/editor/panel/FileImportModalPanel.h b/src/editor/panel/FileImportModalPanel.h similarity index 100% rename from src/context/editor/panel/FileImportModalPanel.h rename to src/editor/panel/FileImportModalPanel.h diff --git a/src/context/editor/panel/NotificationsPanel.cpp b/src/editor/panel/NotificationsPanel.cpp similarity index 95% rename from src/context/editor/panel/NotificationsPanel.cpp rename to src/editor/panel/NotificationsPanel.cpp index 51fc259d..873b0491 100644 --- a/src/context/editor/panel/NotificationsPanel.cpp +++ b/src/editor/panel/NotificationsPanel.cpp @@ -1,8 +1,8 @@ #include "NotificationsPanel.h" #include #include "../../ApplicationContext.h" -#include "../../../util/UIUtil.h" -#include "../../../dto/Notification.h" +#include "../util/UIUtil.h" +#include "../dto/Notification.h" namespace Metal { void NotificationsPanel::onSync() { diff --git a/src/context/editor/panel/NotificationsPanel.h b/src/editor/panel/NotificationsPanel.h similarity index 100% rename from src/context/editor/panel/NotificationsPanel.h rename to src/editor/panel/NotificationsPanel.h diff --git a/src/context/engine/render-pass/impl/tools/GridPass.cpp b/src/editor/passes/GridPass.cpp similarity index 85% rename from src/context/engine/render-pass/impl/tools/GridPass.cpp rename to src/editor/passes/GridPass.cpp index 77eabed2..65cd233f 100644 --- a/src/context/engine/render-pass/impl/tools/GridPass.cpp +++ b/src/editor/passes/GridPass.cpp @@ -1,8 +1,8 @@ -#include "GridPass.h" +#include "../../engine/passes/impl/tools/GridPass.h" -#include "../../../../../context/ApplicationContext.h" -#include "../../../../../service/pipeline/PipelineBuilder.h" -#include "../../../../../enum/EngineResourceIDs.h" +#include "../../ApplicationContext.h" +#include "../../engine/dto/PipelineBuilder.h" +#include "../enum/EngineResourceIDs.h" namespace Metal { void GridPass::onInitialize() { diff --git a/src/context/engine/render-pass/impl/tools/GridPass.h b/src/editor/passes/GridPass.h similarity index 80% rename from src/context/engine/render-pass/impl/tools/GridPass.h rename to src/editor/passes/GridPass.h index e45e24f4..86dc660d 100644 --- a/src/context/engine/render-pass/impl/tools/GridPass.h +++ b/src/editor/passes/GridPass.h @@ -1,7 +1,7 @@ #ifndef GRIDRENDERPASS_H #define GRIDRENDERPASS_H -#include "../../AbstractRenderPass.h" -#include "../../../../../dto/push-constant/GridPushConstant.h" +#include "../../engine/passes/AbstractRenderPass.h" +#include "../dto/GridPushConstant.h" namespace Metal { class GridPass final : public AbstractRenderPass { diff --git a/src/context/engine/render-pass/impl/tools/IconsPass.cpp b/src/editor/passes/IconsPass.cpp similarity index 79% rename from src/context/engine/render-pass/impl/tools/IconsPass.cpp rename to src/editor/passes/IconsPass.cpp index 8734921b..62ff2a18 100644 --- a/src/context/engine/render-pass/impl/tools/IconsPass.cpp +++ b/src/editor/passes/IconsPass.cpp @@ -1,8 +1,8 @@ -#include "IconsPass.h" +#include "../../engine/passes/impl/tools/IconsPass.h" -#include "../../../../../context/ApplicationContext.h" -#include "../../../../../service/pipeline/PipelineBuilder.h" -#include "../../../../../enum/EngineResourceIDs.h" +#include "../../ApplicationContext.h" +#include "../../engine/dto/PipelineBuilder.h" +#include "../enum/EngineResourceIDs.h" namespace Metal { void IconsPass::onInitialize() { diff --git a/src/context/engine/render-pass/impl/tools/IconsPass.h b/src/editor/passes/IconsPass.h similarity index 87% rename from src/context/engine/render-pass/impl/tools/IconsPass.h rename to src/editor/passes/IconsPass.h index 604f068e..cb46ae3c 100644 --- a/src/context/engine/render-pass/impl/tools/IconsPass.h +++ b/src/editor/passes/IconsPass.h @@ -1,6 +1,6 @@ #ifndef ICONRENDERPASS_H #define ICONRENDERPASS_H -#include "../../AbstractRenderPass.h" +#include "../../engine/passes/AbstractRenderPass.h" namespace Metal { class IconsPass final : public AbstractRenderPass { diff --git a/src/context/engine/render-pass/impl/tools/SelectionIDPass.cpp b/src/editor/passes/SelectionIDPass.cpp similarity index 86% rename from src/context/engine/render-pass/impl/tools/SelectionIDPass.cpp rename to src/editor/passes/SelectionIDPass.cpp index f34d9bee..939f0626 100644 --- a/src/context/engine/render-pass/impl/tools/SelectionIDPass.cpp +++ b/src/editor/passes/SelectionIDPass.cpp @@ -1,10 +1,10 @@ #include "SelectionIDPass.h" -#include "../../../../../context/ApplicationContext.h" -#include "../../../../../repository/world/components/TransformComponent.h" -#include "../../../../../dto/push-constant/SelectedDotPushConstant.h" -#include "../../../../../service/pipeline/PipelineBuilder.h" -#include "../../../../../enum/EngineResourceIDs.h" +#include "../../ApplicationContext.h" +#include "../../engine/dto/TransformComponent.h" +#include "../dto/SelectedDotPushConstant.h" +#include "../../engine/dto/PipelineBuilder.h" +#include "../enum/EngineResourceIDs.h" namespace Metal { void SelectionIDPass::onInitialize() { diff --git a/src/context/engine/render-pass/impl/tools/SelectionIDPass.h b/src/editor/passes/SelectionIDPass.h similarity index 80% rename from src/context/engine/render-pass/impl/tools/SelectionIDPass.h rename to src/editor/passes/SelectionIDPass.h index 31957bac..156892dd 100644 --- a/src/context/engine/render-pass/impl/tools/SelectionIDPass.h +++ b/src/editor/passes/SelectionIDPass.h @@ -1,8 +1,8 @@ #ifndef SELECTIONIDPASS_H #define SELECTIONIDPASS_H -#include "../../AbstractRenderPass.h" -#include "../../../../../dto/push-constant/SelectedDotPushConstant.h" +#include "../../engine/passes/AbstractRenderPass.h" +#include "../dto/SelectedDotPushConstant.h" namespace Metal { class SelectionIDPass final : public AbstractRenderPass { diff --git a/src/context/engine/render-pass/impl/tools/SelectionOutlinePass.cpp b/src/editor/passes/SelectionOutlinePass.cpp similarity index 77% rename from src/context/engine/render-pass/impl/tools/SelectionOutlinePass.cpp rename to src/editor/passes/SelectionOutlinePass.cpp index 6e1ca4a4..8be2221e 100644 --- a/src/context/engine/render-pass/impl/tools/SelectionOutlinePass.cpp +++ b/src/editor/passes/SelectionOutlinePass.cpp @@ -1,10 +1,10 @@ -#include "SelectionOutlinePass.h" +#include "../../engine/passes/impl/tools/SelectionOutlinePass.h" -#include "../../../../../context/ApplicationContext.h" -#include "../../../../../repository/world/components/TransformComponent.h" -#include "../../../../../dto/push-constant/SelectedDotPushConstant.h" -#include "../../../../../service/pipeline/PipelineBuilder.h" -#include "../../../../../enum/EngineResourceIDs.h" +#include "../../ApplicationContext.h" +#include "../../engine/dto/TransformComponent.h" +#include "../dto/SelectedDotPushConstant.h" +#include "../../engine/dto/PipelineBuilder.h" +#include "../enum/EngineResourceIDs.h" namespace Metal { void SelectionOutlinePass::onInitialize() { diff --git a/src/context/engine/render-pass/impl/tools/SelectionOutlinePass.h b/src/editor/passes/SelectionOutlinePass.h similarity index 80% rename from src/context/engine/render-pass/impl/tools/SelectionOutlinePass.h rename to src/editor/passes/SelectionOutlinePass.h index 2e620341..4d1b8d7b 100644 --- a/src/context/engine/render-pass/impl/tools/SelectionOutlinePass.h +++ b/src/editor/passes/SelectionOutlinePass.h @@ -1,8 +1,8 @@ #ifndef SELECTEDDOTPASS_H #define SELECTEDDOTPASS_H -#include "../../AbstractRenderPass.h" -#include "../../../../../dto/push-constant/SelectedDotPushConstant.h" +#include "../../engine/passes/AbstractRenderPass.h" +#include "../dto/SelectedDotPushConstant.h" namespace Metal { class SelectionOutlinePass final : public AbstractRenderPass { diff --git a/src/repository/dock/DockRepository.cpp b/src/editor/repository/DockRepository.cpp similarity index 94% rename from src/repository/dock/DockRepository.cpp rename to src/editor/repository/DockRepository.cpp index 560f31d7..507c17f8 100644 --- a/src/repository/dock/DockRepository.cpp +++ b/src/editor/repository/DockRepository.cpp @@ -1,4 +1,4 @@ -#include "DockRepository.h" +#include "../../../repository/dock/DockRepository.h" namespace Metal { DockRepository::DockRepository() : AbstractRuntimeComponent() { diff --git a/src/repository/dock/DockRepository.h b/src/editor/repository/DockRepository.h similarity index 84% rename from src/repository/dock/DockRepository.h rename to src/editor/repository/DockRepository.h index dfbd6d79..ab0648b5 100644 --- a/src/repository/dock/DockRepository.h +++ b/src/editor/repository/DockRepository.h @@ -2,8 +2,8 @@ #define METAL_ENGINE_DOCKREPOSITORY_H #include -#include "DockDTO.h" -#include "../../common/AbstractRuntimeComponent.h" +#include "../dto/DockDTO.h" +#include "../../../common/AbstractRuntimeComponent.h" namespace Metal { struct DockRepository final : AbstractRuntimeComponent { diff --git a/src/repository/editor/EditorRepository.cpp b/src/editor/repository/EditorRepository.cpp similarity index 98% rename from src/repository/editor/EditorRepository.cpp rename to src/editor/repository/EditorRepository.cpp index 84c7cea2..108cb4e1 100644 --- a/src/repository/editor/EditorRepository.cpp +++ b/src/editor/repository/EditorRepository.cpp @@ -1,5 +1,5 @@ -#include "EditorRepository.h" -#include "../../common/interface/Icons.h" +#include "../../../repository/editor/EditorRepository.h" +#include "../../../common/Icons.h" namespace Metal { const char *EditorRepository::getTitle() { diff --git a/src/repository/editor/EditorRepository.h b/src/editor/repository/EditorRepository.h similarity index 91% rename from src/repository/editor/EditorRepository.h rename to src/editor/repository/EditorRepository.h index 95ae4ac5..89d513d2 100644 --- a/src/repository/editor/EditorRepository.h +++ b/src/editor/repository/EditorRepository.h @@ -6,11 +6,11 @@ #include #include -#include "../../dto/ShortcutDTO.h" -#include "../../enum/engine-definitions.h" -#include "../../enum/ShadingMode.h" -#include "../../common/inspection/Inspectable.h" -#include "../../util/Serializable.h" +#include "../dto/ShortcutDTO.h" +#include "../enum/engine-definitions.h" +#include "../enum/ShadingMode.h" +#include "../../../common/Inspectable.h" +#include "../../../common/Serializable.h" namespace Metal { struct TransformComponent; diff --git a/src/service/notification/AsyncTaskService.cpp b/src/editor/service/AsyncTaskService.cpp similarity index 92% rename from src/service/notification/AsyncTaskService.cpp rename to src/editor/service/AsyncTaskService.cpp index 334b3c42..24833c25 100644 --- a/src/service/notification/AsyncTaskService.cpp +++ b/src/editor/service/AsyncTaskService.cpp @@ -1,8 +1,8 @@ -#include "AsyncTaskService.h" +#include "../../../service/notification/AsyncTaskService.h" #include #include -#include "../../util/Util.h" -#include "AsyncTask.h" +#include "../util/Util.h" +#include "../dto/AsyncTask.h" namespace Metal { std::string AsyncTaskService::registerTask(const std::string &name, std::function cancel) { diff --git a/src/service/notification/AsyncTaskService.h b/src/editor/service/AsyncTaskService.h similarity index 95% rename from src/service/notification/AsyncTaskService.h rename to src/editor/service/AsyncTaskService.h index f95581b0..41846f93 100644 --- a/src/service/notification/AsyncTaskService.h +++ b/src/editor/service/AsyncTaskService.h @@ -6,7 +6,7 @@ #include #include #include -#include "AsyncTask.h" +#include "../dto/AsyncTask.h" namespace Metal { class AsyncTaskService { diff --git a/src/service/dock/DockService.cpp b/src/editor/service/DockService.cpp similarity index 94% rename from src/service/dock/DockService.cpp rename to src/editor/service/DockService.cpp index ee1ab8e4..27eb553d 100644 --- a/src/service/dock/DockService.cpp +++ b/src/editor/service/DockService.cpp @@ -1,11 +1,11 @@ #include #include -#include "DockService.h" -#include "../../repository/dock/DockDTO.h" -#include "../../context/editor/abstract/AbstractPanel.h" -#include "../../context/editor/dock-spaces/docks/AbstractDockPanel.h" -#include "../../context/editor/dock-spaces/docks/DockSpacePanel.h" -#include "../../context/ApplicationContext.h" +#include "../../../service/dock/DockService.h" +#include "../dto/DockDTO.h" +#include "../abstract/AbstractPanel.h" +#include "../dock-spaces/docks/AbstractDockPanel.h" +#include "../dock-spaces/docks/DockSpacePanel.h" +#include "../../ApplicationContext.h" namespace Metal { void DockService::buildViews(ImGuiID windowId, AbstractPanel *panel) const { diff --git a/src/service/dock/DockService.h b/src/editor/service/DockService.h similarity index 73% rename from src/service/dock/DockService.h rename to src/editor/service/DockService.h index fe3c9cfd..f2e96c28 100644 --- a/src/service/dock/DockService.h +++ b/src/editor/service/DockService.h @@ -2,9 +2,9 @@ #define METAL_ENGINE_DOCKSERVICE_H #include "imgui.h" -#include "../../repository/dock/DockDTO.h" -#include "../../context/editor/dock-spaces/docks/DockSpacePanel.h" -#include "../../common/AbstractRuntimeComponent.h" +#include "../dto/DockDTO.h" +#include "../dock-spaces/docks/DockSpacePanel.h" +#include "../../../common/AbstractRuntimeComponent.h" namespace Metal { class AbstractPanel; diff --git a/src/service/files/FileImporterService.cpp b/src/editor/service/FileImporterService.cpp similarity index 96% rename from src/service/files/FileImporterService.cpp rename to src/editor/service/FileImporterService.cpp index 84244490..666b5f25 100644 --- a/src/service/files/FileImporterService.cpp +++ b/src/editor/service/FileImporterService.cpp @@ -1,7 +1,7 @@ -#include "FileImporterService.h" +#include "../../../service/files/FileImporterService.h" -#include "../../context/ApplicationContext.h" -#include "../log/LogService.h" +#include "../../ApplicationContext.h" +#include "LogService.h" #include #include diff --git a/src/service/files/FileImporterService.h b/src/editor/service/FileImporterService.h similarity index 86% rename from src/service/files/FileImporterService.h rename to src/editor/service/FileImporterService.h index 2df8abd7..231a3fbc 100644 --- a/src/service/files/FileImporterService.h +++ b/src/editor/service/FileImporterService.h @@ -5,8 +5,8 @@ #include #include -#include "../../dto/file/ImportSettingsDTO.h" -#include "../../common/AbstractRuntimeComponent.h" +#include "../dto/ImportSettingsDTO.h" +#include "../../../common/AbstractRuntimeComponent.h" namespace Metal { class FileImporterService final : public AbstractRuntimeComponent { diff --git a/src/service/files/FilesService.cpp b/src/editor/service/FilesService.cpp similarity index 95% rename from src/service/files/FilesService.cpp rename to src/editor/service/FilesService.cpp index 9d6af371..48f6dc06 100644 --- a/src/service/files/FilesService.cpp +++ b/src/editor/service/FilesService.cpp @@ -1,16 +1,16 @@ -#include "FilesService.h" -#include "../../dto/file/FSEntry.h" -#include "../../enum/EntryType.h" -#include "../../enum/engine-definitions.h" -#include "../../util/FilesUtil.h" -#include "../../context/ApplicationContext.h" -#include "../log/LogService.h" +#include "../../../service/files/FilesService.h" +#include "../dto/FSEntry.h" +#include "../enum/EntryType.h" +#include "../enum/engine-definitions.h" +#include "../util/FilesUtil.h" +#include "../../ApplicationContext.h" +#include "LogService.h" #include #include #include #include #include -#include "../../util/serialization-definitions.h" +#include "../util/serialization-definitions.h" namespace fs = std::filesystem; diff --git a/src/service/files/FilesService.h b/src/editor/service/FilesService.h similarity index 93% rename from src/service/files/FilesService.h rename to src/editor/service/FilesService.h index c2906941..299b1b8d 100644 --- a/src/service/files/FilesService.h +++ b/src/editor/service/FilesService.h @@ -4,7 +4,7 @@ #include #include -#include "../../common/AbstractRuntimeComponent.h" +#include "../../../common/AbstractRuntimeComponent.h" namespace Metal { struct FSEntry; diff --git a/src/service/log/LogService.cpp b/src/editor/service/LogService.cpp similarity index 97% rename from src/service/log/LogService.cpp rename to src/editor/service/LogService.cpp index 28cf54e1..4225a03b 100644 --- a/src/service/log/LogService.cpp +++ b/src/editor/service/LogService.cpp @@ -1,4 +1,4 @@ -#include "LogService.h" +#include "../../../service/log/LogService.h" #include #include #include diff --git a/src/service/log/LogService.h b/src/editor/service/LogService.h similarity index 95% rename from src/service/log/LogService.h rename to src/editor/service/LogService.h index 94254087..22e0487a 100644 --- a/src/service/log/LogService.h +++ b/src/editor/service/LogService.h @@ -4,7 +4,7 @@ #include #include #include -#include "../../common/AbstractRuntimeComponent.h" +#include "../../../common/AbstractRuntimeComponent.h" namespace Metal { diff --git a/src/service/material/MaterialImporterService.cpp b/src/editor/service/MaterialImporterService.cpp similarity index 96% rename from src/service/material/MaterialImporterService.cpp rename to src/editor/service/MaterialImporterService.cpp index 35d659ff..1270b7fd 100644 --- a/src/service/material/MaterialImporterService.cpp +++ b/src/editor/service/MaterialImporterService.cpp @@ -1,7 +1,7 @@ #include "MaterialImporterService.h" -#include "../../context/ApplicationContext.h" -#include "../../enum/engine-definitions.h" -#include "../../repository/world/components/PrimitiveComponent.h" +#include "../../ApplicationContext.h" +#include "../enum/engine-definitions.h" +#include "../../engine/dto/PrimitiveComponent.h" #include #include diff --git a/src/service/material/MaterialImporterService.h b/src/editor/service/MaterialImporterService.h similarity index 92% rename from src/service/material/MaterialImporterService.h rename to src/editor/service/MaterialImporterService.h index 52c9aedd..6f731505 100644 --- a/src/service/material/MaterialImporterService.h +++ b/src/editor/service/MaterialImporterService.h @@ -6,7 +6,7 @@ #include #include -#include "../abstract/AbstractResourceService.h" +#include "../../../common/AbstractResourceService.h" namespace Metal { struct PrimitiveComponent; diff --git a/src/service/mesh/MeshImporterService.cpp b/src/editor/service/MeshImporterService.cpp similarity index 90% rename from src/service/mesh/MeshImporterService.cpp rename to src/editor/service/MeshImporterService.cpp index f8c2a980..9943ad53 100644 --- a/src/service/mesh/MeshImporterService.cpp +++ b/src/editor/service/MeshImporterService.cpp @@ -1,13 +1,13 @@ -#include "MeshImporterService.h" -#include "MeshData.h" -#include "VertexData.h" -#include "../../dto/file/EntryMetadata.h" -#include "../../enum/engine-definitions.h" -#include "../../util/FilesUtil.h" -#include "../../context/ApplicationContext.h" +#include "../../../service/mesh/MeshImporterService.h" +#include "../../engine/dto/MeshData.h" +#include "../../context/editor/dto/VertexData.h" +#include "../dto/EntryMetadata.h" +#include "../enum/engine-definitions.h" +#include "../util/FilesUtil.h" +#include "../../ApplicationContext.h" #include #include -#include "../../util/serialization-definitions.h" +#include "../../../util/serialization-definitions.h" namespace Metal { std::string MeshImporterService::persistMesh(const std::string &targetDir, const MeshData &mesh) const { diff --git a/src/service/mesh/MeshImporterService.h b/src/editor/service/MeshImporterService.h similarity index 93% rename from src/service/mesh/MeshImporterService.h rename to src/editor/service/MeshImporterService.h index 7e707e86..250ea5ac 100644 --- a/src/service/mesh/MeshImporterService.h +++ b/src/editor/service/MeshImporterService.h @@ -1,7 +1,7 @@ #ifndef MESHIMPORTERSERVICE_H #define MESHIMPORTERSERVICE_H -#include "../abstract/AbstractResourceService.h" +#include "../../../common/AbstractResourceService.h" #include #include #include diff --git a/src/service/notification/NotificationService.cpp b/src/editor/service/NotificationService.cpp similarity index 95% rename from src/service/notification/NotificationService.cpp rename to src/editor/service/NotificationService.cpp index 92a21c0b..ed0b6a93 100644 --- a/src/service/notification/NotificationService.cpp +++ b/src/editor/service/NotificationService.cpp @@ -1,5 +1,5 @@ #include "NotificationService.h" -#include "../../dto/Notification.h" +#include "../dto/Notification.h" namespace Metal { void NotificationService::pushMessage(const std::string &message, NotificationSeverities::NotificationSeverity severity) { diff --git a/src/service/notification/NotificationService.h b/src/editor/service/NotificationService.h similarity index 92% rename from src/service/notification/NotificationService.h rename to src/editor/service/NotificationService.h index 32737dc5..050b4183 100644 --- a/src/service/notification/NotificationService.h +++ b/src/editor/service/NotificationService.h @@ -2,7 +2,7 @@ #define TOASTERSERVICE_H #include #include -#include "../../enum/NotificationSeverity.h" +#include "../enum/NotificationSeverity.h" #define MAX_notifications 4 #define MESSAGE_DURATION 3000 diff --git a/src/service/picking/PickingService.cpp b/src/editor/service/PickingService.cpp similarity index 94% rename from src/service/picking/PickingService.cpp rename to src/editor/service/PickingService.cpp index 235ac849..e1ee990e 100644 --- a/src/service/picking/PickingService.cpp +++ b/src/editor/service/PickingService.cpp @@ -1,8 +1,8 @@ -#include "PickingService.h" +#include "../../../service/picking/PickingService.h" -#include "../buffer/BufferInstance.h" -#include "../texture/TextureInstance.h" -#include "../../context/ApplicationContext.h" +#include "../../engine/resource/BufferInstance.h" +#include "../../engine/resource/TextureInstance.h" +#include "../../ApplicationContext.h" namespace Metal { std::optional PickingService::pickEntityFromGBuffer(TextureInstance *attachment, const uint32_t pixelX, diff --git a/src/service/picking/PickingService.h b/src/editor/service/PickingService.h similarity index 80% rename from src/service/picking/PickingService.h rename to src/editor/service/PickingService.h index d86177d0..923248e9 100644 --- a/src/service/picking/PickingService.h +++ b/src/editor/service/PickingService.h @@ -1,8 +1,8 @@ #ifndef PICKINGSERVICE_H #define PICKINGSERVICE_H -#include "../abstract/AbstractResourceService.h" -#include "../../enum/engine-definitions.h" +#include "../../../common/AbstractResourceService.h" +#include "../enum/engine-definitions.h" #include namespace Metal { diff --git a/src/service/mesh/SceneImporterService.cpp b/src/editor/service/SceneImporterService.cpp similarity index 93% rename from src/service/mesh/SceneImporterService.cpp rename to src/editor/service/SceneImporterService.cpp index 08144c8a..7196a0cc 100644 --- a/src/service/mesh/SceneImporterService.cpp +++ b/src/editor/service/SceneImporterService.cpp @@ -1,19 +1,19 @@ -#include "SceneImporterService.h" +#include "../../../service/mesh/SceneImporterService.h" -#include "../../dto/file/FSEntry.h" -#include "MeshData.h" -#include "SceneData.h" -#include "../material/MaterialImporterService.h" +#include "../../../dto/file/FSEntry.h" +#include "../../engine/dto/MeshData.h" +#include "../dto/SceneData.h" +#include "MaterialImporterService.h" #include #include #include #include -#include "../../util/FilesUtil.h" -#include "../../dto/file/EntryMetadata.h" -#include "../../enum/engine-definitions.h" -#include "../../context/ApplicationContext.h" -#include "../../util/serialization-definitions.h" -#include "../../dto/file/SceneImportSettingsDTO.h" +#include "../util/FilesUtil.h" +#include "../dto/EntryMetadata.h" +#include "../enum/engine-definitions.h" +#include "../../ApplicationContext.h" +#include "../util/serialization-definitions.h" +#include "../dto/SceneImportSettingsDTO.h" namespace Metal { std::string SceneImporterService::importData(const std::string &targetDir, const std::string &pathToFile, diff --git a/src/service/mesh/SceneImporterService.h b/src/editor/service/SceneImporterService.h similarity index 96% rename from src/service/mesh/SceneImporterService.h rename to src/editor/service/SceneImporterService.h index 39b6d495..29787d7b 100644 --- a/src/service/mesh/SceneImporterService.h +++ b/src/editor/service/SceneImporterService.h @@ -3,7 +3,7 @@ #include -#include "../abstract/AbstractImporter.h" +#include "../../../common/AbstractImporter.h" #include #include diff --git a/src/service/selection/SelectionService.cpp b/src/editor/service/SelectionService.cpp similarity index 92% rename from src/service/selection/SelectionService.cpp rename to src/editor/service/SelectionService.cpp index 23d4c8ff..d2ac6738 100644 --- a/src/service/selection/SelectionService.cpp +++ b/src/editor/service/SelectionService.cpp @@ -1,7 +1,7 @@ -#include "SelectionService.h" +#include "../../../service/selection/SelectionService.h" -#include "../../context/ApplicationContext.h" -#include "../../repository/world/components/TransformComponent.h" +#include "../../ApplicationContext.h" +#include "../../engine/dto/TransformComponent.h" namespace Metal { void SelectionService::addSelected(entt::entity entity) const { diff --git a/src/service/selection/SelectionService.h b/src/editor/service/SelectionService.h similarity index 83% rename from src/service/selection/SelectionService.h rename to src/editor/service/SelectionService.h index 60cb3dd8..1a878d56 100644 --- a/src/service/selection/SelectionService.h +++ b/src/editor/service/SelectionService.h @@ -2,8 +2,8 @@ #define SELECTIONSERVICE_H #include -#include "../../common/AbstractRuntimeComponent.h" -#include "../../enum/engine-definitions.h" +#include "../../../common/AbstractRuntimeComponent.h" +#include "../enum/engine-definitions.h" namespace Metal { struct WorldRepository; diff --git a/src/service/texture/TextureImporterService.cpp b/src/editor/service/TextureImporterService.cpp similarity index 93% rename from src/service/texture/TextureImporterService.cpp rename to src/editor/service/TextureImporterService.cpp index d5f3d5f5..43723b5d 100644 --- a/src/service/texture/TextureImporterService.cpp +++ b/src/editor/service/TextureImporterService.cpp @@ -1,16 +1,16 @@ #include "TextureImporterService.h" -#include "../../../dependencies/stb/stb_image.h" -#include "../../../dependencies/stb/stb_image_write.h" +#include "../../../../dependencies/stb/stb_image.h" +#include "../../../../dependencies/stb/stb_image_write.h" #include #include -#include "../../util/serialization-definitions.h" +#include "../util/serialization-definitions.h" -#include "../../dto/file/EntryMetadata.h" -#include "../../enum/EntryType.h" -#include "../../util/FilesUtil.h" -#include "../../context/ApplicationContext.h" -#include "TextureData.h" +#include "../dto/EntryMetadata.h" +#include "../enum/EntryType.h" +#include "../util/FilesUtil.h" +#include "../../ApplicationContext.h" +#include "../../engine/dto/TextureData.h" namespace fs = std::filesystem; diff --git a/src/service/texture/TextureImporterService.h b/src/editor/service/TextureImporterService.h similarity index 95% rename from src/service/texture/TextureImporterService.h rename to src/editor/service/TextureImporterService.h index 9cfa4085..244617ed 100644 --- a/src/service/texture/TextureImporterService.h +++ b/src/editor/service/TextureImporterService.h @@ -1,6 +1,6 @@ #ifndef TEXTUREIMPORTER_H #define TEXTUREIMPORTER_H -#include "../abstract/AbstractImporter.h" +#include "../../../common/AbstractImporter.h" struct aiTexture; diff --git a/src/service/theme/ThemeService.cpp b/src/editor/service/ThemeService.cpp similarity index 98% rename from src/service/theme/ThemeService.cpp rename to src/editor/service/ThemeService.cpp index c206b8a2..8e439ab7 100644 --- a/src/service/theme/ThemeService.cpp +++ b/src/editor/service/ThemeService.cpp @@ -1,6 +1,6 @@ -#include "ThemeService.h" +#include "../../../service/theme/ThemeService.h" -#include "../../context/ApplicationContext.h" +#include "../../ApplicationContext.h" namespace Metal { glm::vec3 ThemeService::BACKGROUND_COLOR = glm::vec3(0.f); diff --git a/src/service/theme/ThemeService.h b/src/editor/service/ThemeService.h similarity index 93% rename from src/service/theme/ThemeService.h rename to src/editor/service/ThemeService.h index e9d5f603..b8775037 100644 --- a/src/service/theme/ThemeService.h +++ b/src/editor/service/ThemeService.h @@ -2,7 +2,7 @@ #define THEMESERVICE_H #include #include -#include "../../common/AbstractRuntimeComponent.h" +#include "../../../common/AbstractRuntimeComponent.h" namespace Metal { diff --git a/src/service/voxel/VoxelImporterService.cpp b/src/editor/service/VoxelImporterService.cpp similarity index 94% rename from src/service/voxel/VoxelImporterService.cpp rename to src/editor/service/VoxelImporterService.cpp index 6923f58e..86142ef3 100644 --- a/src/service/voxel/VoxelImporterService.cpp +++ b/src/editor/service/VoxelImporterService.cpp @@ -1,20 +1,20 @@ -#include "VoxelImporterService.h" +#include "../../../service/voxel/VoxelImporterService.h" #include -#include "../../util/serialization-definitions.h" +#include "../util/serialization-definitions.h" -#include "../../context/ApplicationContext.h" -#include "../../dto/file/EntryMetadata.h" -#include "../../enum/EntryType.h" -#include "../../enum/engine-definitions.h" -#include "../../service/log/LogService.h" +#include "../../ApplicationContext.h" +#include "../dto/EntryMetadata.h" +#include "../enum/EntryType.h" +#include "../enum/engine-definitions.h" +#include "LogService.h" #include #include #include #include -#include "impl/SparseVoxelOctreeData.h" +#include "../../engine/dto/SparseVoxelOctreeData.h" namespace fs = std::filesystem; diff --git a/src/service/voxel/VoxelImporterService.h b/src/editor/service/VoxelImporterService.h similarity index 89% rename from src/service/voxel/VoxelImporterService.h rename to src/editor/service/VoxelImporterService.h index 57ed9bac..2e1dc578 100644 --- a/src/service/voxel/VoxelImporterService.h +++ b/src/editor/service/VoxelImporterService.h @@ -1,9 +1,9 @@ #ifndef METAL_ENGINE_VOLUMEIMPORTERSERVICE_H #define METAL_ENGINE_VOLUMEIMPORTERSERVICE_H -#include "../abstract/AbstractImporter.h" -#include "impl/SparseVoxelOctreeBuilder.h" -#include "impl/SparseVoxelOctreeData.h" +#include "../../../common/AbstractImporter.h" +#include "../dto/SparseVoxelOctreeBuilder.h" +#include "../../engine/dto/SparseVoxelOctreeData.h" namespace Metal { struct SVOInstance; diff --git a/src/util/FileDialogUtil.h b/src/editor/util/FileDialogUtil.h similarity index 93% rename from src/util/FileDialogUtil.h rename to src/editor/util/FileDialogUtil.h index 436d9966..39b4b9e3 100644 --- a/src/util/FileDialogUtil.h +++ b/src/editor/util/FileDialogUtil.h @@ -3,8 +3,8 @@ #include #include #include -#include "../service/log/LogService.h" -#include "../context/ApplicationContext.h" +#include "../service/LogService.h" +#include "../../ApplicationContext.h" namespace Metal:: FileDialogUtil { static std::vector PickFiles(std::vector filtersToApply) { diff --git a/src/util/FilesUtil.h b/src/editor/util/FilesUtil.h similarity index 98% rename from src/util/FilesUtil.h rename to src/editor/util/FilesUtil.h index 142aee2d..37aa80df 100644 --- a/src/util/FilesUtil.h +++ b/src/editor/util/FilesUtil.h @@ -2,7 +2,7 @@ #define FILESUTIL_H #include #include -#include "../dto/file/FSEntry.h" +#include "../dto/FSEntry.h" namespace fs = std::filesystem; diff --git a/src/util/UIUtil.h b/src/editor/util/UIUtil.h similarity index 99% rename from src/util/UIUtil.h rename to src/editor/util/UIUtil.h index 48312985..666482bc 100644 --- a/src/util/UIUtil.h +++ b/src/editor/util/UIUtil.h @@ -5,7 +5,7 @@ #include #include "../enum/EntryType.h" -#include "../common/interface/Icons.h" +#include "../../../common/Icons.h" namespace Metal::UIUtil { static constexpr ImVec4 DIRECTORY_COLOR{188 / 255.f, 128 / 255.f, 78 / 255.f, 1}; diff --git a/src/util/Util.h b/src/editor/util/Util.h similarity index 100% rename from src/util/Util.h rename to src/editor/util/Util.h diff --git a/src/util/serialization-definitions.h b/src/editor/util/serialization-definitions.h similarity index 97% rename from src/util/serialization-definitions.h rename to src/editor/util/serialization-definitions.h index eab3426b..ceef1d81 100644 --- a/src/util/serialization-definitions.h +++ b/src/editor/util/serialization-definitions.h @@ -3,7 +3,7 @@ #include #include -#include "Serializable.h" +#include "../../../common/Serializable.h" #include #include #include diff --git a/src/context/engine/EngineContext.cpp b/src/engine/EngineContext.cpp similarity index 94% rename from src/context/engine/EngineContext.cpp rename to src/engine/EngineContext.cpp index 4b8d6c85..ec840921 100644 --- a/src/context/engine/EngineContext.cpp +++ b/src/engine/EngineContext.cpp @@ -1,10 +1,10 @@ #include "EngineContext.h" -#include "../../enum/EngineResourceIDs.h" +#include "../editor/enum/EngineResourceIDs.h" #include "../../context/ApplicationContext.h" -#include "../../service/buffer/BufferInstance.h" -#include "../../service/camera/Camera.h" -#include "../../repository/world/components/TransformComponent.h" +#include "resource/BufferInstance.h" +#include "dto/Camera.h" +#include "dto/TransformComponent.h" namespace Metal { void EngineContext::resetPathTracerAccumulationCount() const { diff --git a/src/context/engine/EngineContext.h b/src/engine/EngineContext.h similarity index 95% rename from src/context/engine/EngineContext.h rename to src/engine/EngineContext.h index 79e99f4b..ad04b00c 100644 --- a/src/context/engine/EngineContext.h +++ b/src/engine/EngineContext.h @@ -5,9 +5,9 @@ #include #include -#include "../../dto/buffers/GlobalDataUBO.h" +#include "dto/GlobalDataUBO.h" #include "../../common/AbstractRuntimeComponent.h" -#include "../../dto/buffers/TileInfoUBO.h" +#include "dto/TileInfoUBO.h" using Clock = std::chrono::high_resolution_clock; using TimePoint = std::chrono::time_point; diff --git a/src/repository/world/impl/AbstractComponent.h b/src/engine/dto/AbstractComponent.h similarity index 89% rename from src/repository/world/impl/AbstractComponent.h rename to src/engine/dto/AbstractComponent.h index b9ab3ebb..a9fcfd67 100644 --- a/src/repository/world/impl/AbstractComponent.h +++ b/src/engine/dto/AbstractComponent.h @@ -1,7 +1,7 @@ #ifndef ABSTRACTCOMPONENT_H #define ABSTRACTCOMPONENT_H -#include "../../../common/inspection/Inspectable.h" -#include "../../../enum/ComponentType.h" +#include "../../../common/Inspectable.h" +#include "../enum/ComponentType.h" namespace Metal { struct AbstractComponent : Inspectable { diff --git a/src/dto/push-constant/AccumulationPushConstant.h b/src/engine/dto/AccumulationPushConstant.h similarity index 100% rename from src/dto/push-constant/AccumulationPushConstant.h rename to src/engine/dto/AccumulationPushConstant.h diff --git a/src/repository/world/impl/BoundingBox.h b/src/engine/dto/BoundingBox.h similarity index 97% rename from src/repository/world/impl/BoundingBox.h rename to src/engine/dto/BoundingBox.h index 94ea7dea..0d15dc8b 100644 --- a/src/repository/world/impl/BoundingBox.h +++ b/src/engine/dto/BoundingBox.h @@ -1,7 +1,7 @@ #ifndef BOUNDINGBOX_H #define BOUNDINGBOX_H #include -#include "../../../util/Serializable.h" +#include "../../../common/Serializable.h" namespace Metal { struct BoundingBox final : Serializable { diff --git a/src/service/camera/Camera.cpp b/src/engine/dto/Camera.cpp similarity index 98% rename from src/service/camera/Camera.cpp rename to src/engine/dto/Camera.cpp index 75fe8e20..b7112275 100644 --- a/src/service/camera/Camera.cpp +++ b/src/engine/dto/Camera.cpp @@ -1,6 +1,6 @@ -#include "Camera.h" +#include "../../../service/camera/Camera.h" -#include "../../common/interface/Icons.h" +#include "../../../common/Icons.h" namespace Metal { void Camera::extractFrustumPlanes(glm::mat4x4 m) { diff --git a/src/service/camera/Camera.h b/src/engine/dto/Camera.h similarity index 98% rename from src/service/camera/Camera.h rename to src/engine/dto/Camera.h index 6afad882..b6b0bf7c 100644 --- a/src/service/camera/Camera.h +++ b/src/engine/dto/Camera.h @@ -6,8 +6,8 @@ #include #include -#include "../../common/inspection/Inspectable.h" -#include "../../util/Serializable.h" +#include "../../../common/Inspectable.h" +#include "../../../common/Serializable.h" namespace Metal { diff --git a/src/dto/push-constant/DenoiserPushConstant.h b/src/engine/dto/DenoiserPushConstant.h similarity index 100% rename from src/dto/push-constant/DenoiserPushConstant.h rename to src/engine/dto/DenoiserPushConstant.h diff --git a/src/service/descriptor/DescriptorBinding.h b/src/engine/dto/DescriptorBinding.h similarity index 100% rename from src/service/descriptor/DescriptorBinding.h rename to src/engine/dto/DescriptorBinding.h diff --git a/src/service/descriptor/DescriptorInstance.h b/src/engine/dto/DescriptorInstance.h similarity index 85% rename from src/service/descriptor/DescriptorInstance.h rename to src/engine/dto/DescriptorInstance.h index f2069c62..ce0fc262 100644 --- a/src/service/descriptor/DescriptorInstance.h +++ b/src/engine/dto/DescriptorInstance.h @@ -2,8 +2,8 @@ #define DESCRIPTORINSTANCE_H #include -#include "../../repository/abstract/RuntimeResource.h" -#include "./DescriptorBinding.h" +#include "../resource/RuntimeResource.h" +#include "../../../service/descriptor/DescriptorBinding.h" namespace Metal { struct BufferInstance; diff --git a/src/dto/buffers/GlobalDataUBO.h b/src/engine/dto/GlobalDataUBO.h similarity index 100% rename from src/dto/buffers/GlobalDataUBO.h rename to src/engine/dto/GlobalDataUBO.h diff --git a/src/dto/push-constant/HWRayTracingPushConstant.h b/src/engine/dto/HWRayTracingPushConstant.h similarity index 100% rename from src/dto/push-constant/HWRayTracingPushConstant.h rename to src/engine/dto/HWRayTracingPushConstant.h diff --git a/src/dto/buffers/LightData.h b/src/engine/dto/LightData.h similarity index 100% rename from src/dto/buffers/LightData.h rename to src/engine/dto/LightData.h diff --git a/src/service/mesh/MeshData.h b/src/engine/dto/MeshData.h similarity index 93% rename from src/service/mesh/MeshData.h rename to src/engine/dto/MeshData.h index f5dfb639..43811394 100644 --- a/src/service/mesh/MeshData.h +++ b/src/engine/dto/MeshData.h @@ -3,7 +3,7 @@ #include #include #include "VertexData.h" -#include "../../util/serialization-definitions.h" +#include "../../editor/util/serialization-definitions.h" namespace Metal { struct MeshData final { diff --git a/src/dto/buffers/MeshMetadata.h b/src/engine/dto/MeshMetadata.h similarity index 100% rename from src/dto/buffers/MeshMetadata.h rename to src/engine/dto/MeshMetadata.h diff --git a/src/repository/world/impl/MetadataComponent.cpp b/src/engine/dto/MetadataComponent.cpp similarity index 64% rename from src/repository/world/impl/MetadataComponent.cpp rename to src/engine/dto/MetadataComponent.cpp index bd5dc915..14ea7662 100644 --- a/src/repository/world/impl/MetadataComponent.cpp +++ b/src/engine/dto/MetadataComponent.cpp @@ -1,6 +1,6 @@ -#include "MetadataComponent.h" -#include "../../../common/interface/Icons.h" -#include "../../../util/UIUtil.h" +#include "../../../repository/world/impl/MetadataComponent.h" +#include "../../../common/Icons.h" +#include "../../editor/util/UIUtil.h" namespace Metal { void MetadataComponent::registerFields() { diff --git a/src/repository/world/impl/MetadataComponent.h b/src/engine/dto/MetadataComponent.h similarity index 83% rename from src/repository/world/impl/MetadataComponent.h rename to src/engine/dto/MetadataComponent.h index 4923e86e..0cf4276d 100644 --- a/src/repository/world/impl/MetadataComponent.h +++ b/src/engine/dto/MetadataComponent.h @@ -4,10 +4,10 @@ #include #include "AbstractComponent.h" -#include "../../../enum/engine-definitions.h" -#include "../../../enum/ComponentType.h" -#include "../../../common/inspection/Inspectable.h" -#include "../../../util/Serializable.h" +#include "../../editor/enum/engine-definitions.h" +#include "../enum/ComponentType.h" +#include "../../../common/Inspectable.h" +#include "../../../common/Serializable.h" namespace Metal { struct MetadataComponent final : AbstractComponent, Serializable { diff --git a/src/service/pipeline/PipelineBuilder.cpp b/src/engine/dto/PipelineBuilder.cpp similarity index 97% rename from src/service/pipeline/PipelineBuilder.cpp rename to src/engine/dto/PipelineBuilder.cpp index 27f0f363..98ab72d5 100644 --- a/src/service/pipeline/PipelineBuilder.cpp +++ b/src/engine/dto/PipelineBuilder.cpp @@ -1,5 +1,5 @@ -#include "PipelineBuilder.h" -#include "../texture/TextureInstance.h" +#include "../../../service/pipeline/PipelineBuilder.h" +#include "../resource/TextureInstance.h" namespace Metal { PipelineBuilder PipelineBuilder::Of(std::string frameBufferId, const char *vertexShader, diff --git a/src/service/pipeline/PipelineBuilder.h b/src/engine/dto/PipelineBuilder.h similarity index 98% rename from src/service/pipeline/PipelineBuilder.h rename to src/engine/dto/PipelineBuilder.h index 14c8095c..cdb39b5e 100644 --- a/src/service/pipeline/PipelineBuilder.h +++ b/src/engine/dto/PipelineBuilder.h @@ -3,7 +3,7 @@ #include #include #include -#include "../descriptor/DescriptorBinding.h" +#include "DescriptorBinding.h" namespace Metal { struct DescriptorInstance; diff --git a/src/dto/push-constant/PostProcessingPushConstant.h b/src/engine/dto/PostProcessingPushConstant.h similarity index 100% rename from src/dto/push-constant/PostProcessingPushConstant.h rename to src/engine/dto/PostProcessingPushConstant.h diff --git a/src/repository/world/components/PrimitiveComponent.cpp b/src/engine/dto/PrimitiveComponent.cpp similarity index 94% rename from src/repository/world/components/PrimitiveComponent.cpp rename to src/engine/dto/PrimitiveComponent.cpp index 26bf57c4..35964482 100644 --- a/src/repository/world/components/PrimitiveComponent.cpp +++ b/src/engine/dto/PrimitiveComponent.cpp @@ -1,7 +1,7 @@ -#include "PrimitiveComponent.h" -#include "../../../context/ApplicationContext.h" -#include "../../../enum/EntryType.h" -#include "../../../service/mesh/MeshData.h" +#include "../../../repository/world/components/PrimitiveComponent.h" +#include "../../ApplicationContext.h" +#include "../../editor/enum/EntryType.h" +#include "MeshData.h" namespace Metal { void PrimitiveComponent::registerFields() { diff --git a/src/repository/world/components/PrimitiveComponent.h b/src/engine/dto/PrimitiveComponent.h similarity index 91% rename from src/repository/world/components/PrimitiveComponent.h rename to src/engine/dto/PrimitiveComponent.h index d5229ac4..d49c8afc 100644 --- a/src/repository/world/components/PrimitiveComponent.h +++ b/src/engine/dto/PrimitiveComponent.h @@ -1,8 +1,8 @@ #ifndef PRIMITIVE_COMPONENT_H #define PRIMITIVE_COMPONENT_H -#include "../impl/AbstractComponent.h" -#include "../../../util/Serializable.h" +#include "AbstractComponent.h" +#include "../../../common/Serializable.h" #include namespace Metal { diff --git a/src/service/pipeline/ShaderModule.cpp b/src/engine/dto/ShaderModule.cpp similarity index 73% rename from src/service/pipeline/ShaderModule.cpp rename to src/engine/dto/ShaderModule.cpp index bbcdfe88..a11e2fb8 100644 --- a/src/service/pipeline/ShaderModule.cpp +++ b/src/engine/dto/ShaderModule.cpp @@ -1,6 +1,6 @@ -#include "ShaderModule.h" +#include "../../../service/pipeline/ShaderModule.h" -#include "../../context/vulkan/VulkanContext.h" +#include "../../vulkan/VulkanContext.h" namespace Metal { void ShaderModule::initialize(glslang_program_t *program) { diff --git a/src/service/pipeline/ShaderModule.h b/src/engine/dto/ShaderModule.h similarity index 100% rename from src/service/pipeline/ShaderModule.h rename to src/engine/dto/ShaderModule.h diff --git a/src/service/voxel/impl/SparseVoxelOctreeData.h b/src/engine/dto/SparseVoxelOctreeData.h similarity index 94% rename from src/service/voxel/impl/SparseVoxelOctreeData.h rename to src/engine/dto/SparseVoxelOctreeData.h index dac7a84b..87987780 100644 --- a/src/service/voxel/impl/SparseVoxelOctreeData.h +++ b/src/engine/dto/SparseVoxelOctreeData.h @@ -4,7 +4,7 @@ #include #include -#include "../../../util/Serializable.h" +#include "../../../common/Serializable.h" namespace Metal { struct SparseVoxelOctreeData final : Serializable { diff --git a/src/service/texture/TextureData.h b/src/engine/dto/TextureData.h similarity index 100% rename from src/service/texture/TextureData.h rename to src/engine/dto/TextureData.h diff --git a/src/dto/buffers/TileInfoUBO.h b/src/engine/dto/TileInfoUBO.h similarity index 100% rename from src/dto/buffers/TileInfoUBO.h rename to src/engine/dto/TileInfoUBO.h diff --git a/src/repository/world/components/TransformComponent.cpp b/src/engine/dto/TransformComponent.cpp similarity index 92% rename from src/repository/world/components/TransformComponent.cpp rename to src/engine/dto/TransformComponent.cpp index 73104008..da3e63b1 100644 --- a/src/repository/world/components/TransformComponent.cpp +++ b/src/engine/dto/TransformComponent.cpp @@ -1,6 +1,6 @@ -#include "TransformComponent.h" -#include "VolumeComponent.h" -#include "../../../context/ApplicationContext.h" +#include "../../../repository/world/components/TransformComponent.h" +#include "../../../repository/world/components/VolumeComponent.h" +#include "../../ApplicationContext.h" #define ROTATION "Rotation" diff --git a/src/repository/world/components/TransformComponent.h b/src/engine/dto/TransformComponent.h similarity index 91% rename from src/repository/world/components/TransformComponent.h rename to src/engine/dto/TransformComponent.h index 3315bcfd..1857e1eb 100644 --- a/src/repository/world/components/TransformComponent.h +++ b/src/engine/dto/TransformComponent.h @@ -5,8 +5,8 @@ #include #include -#include "../impl/AbstractComponent.h" -#include "../../../util/Serializable.h" +#include "AbstractComponent.h" +#include "../../../common/Serializable.h" namespace Metal { diff --git a/src/service/mesh/VertexData.h b/src/engine/dto/VertexData.h similarity index 96% rename from src/service/mesh/VertexData.h rename to src/engine/dto/VertexData.h index 5c366199..677c9fc2 100644 --- a/src/service/mesh/VertexData.h +++ b/src/engine/dto/VertexData.h @@ -4,7 +4,7 @@ #include #include -#include "../../util/serialization-definitions.h" +#include "../../editor/util/serialization-definitions.h" namespace Metal { struct VertexData final { diff --git a/src/repository/world/components/VolumeComponent.cpp b/src/engine/dto/VolumeComponent.cpp similarity index 81% rename from src/repository/world/components/VolumeComponent.cpp rename to src/engine/dto/VolumeComponent.cpp index e0f7b99d..0d9455cc 100644 --- a/src/repository/world/components/VolumeComponent.cpp +++ b/src/engine/dto/VolumeComponent.cpp @@ -1,5 +1,5 @@ -#include "VolumeComponent.h" -#include "../../../context/ApplicationContext.h" +#include "../../../repository/world/components/VolumeComponent.h" +#include "../../ApplicationContext.h" namespace Metal { void VolumeComponent::registerFields() { diff --git a/src/repository/world/components/VolumeComponent.h b/src/engine/dto/VolumeComponent.h similarity index 93% rename from src/repository/world/components/VolumeComponent.h rename to src/engine/dto/VolumeComponent.h index 4ea910c8..57a77cf2 100644 --- a/src/repository/world/components/VolumeComponent.h +++ b/src/engine/dto/VolumeComponent.h @@ -1,8 +1,8 @@ #ifndef VOLUMECOMPONENT_H #define VOLUMECOMPONENT_H -#include "../impl/AbstractComponent.h" -#include "../../../util/Serializable.h" +#include "AbstractComponent.h" +#include "../../../common/Serializable.h" #include namespace Metal { diff --git a/src/dto/buffers/VolumeData.h b/src/engine/dto/VolumeData.h similarity index 100% rename from src/dto/buffers/VolumeData.h rename to src/engine/dto/VolumeData.h diff --git a/src/service/voxel/impl/VoxelData.h b/src/engine/dto/VoxelData.h similarity index 100% rename from src/service/voxel/impl/VoxelData.h rename to src/engine/dto/VoxelData.h diff --git a/src/enum/ComponentType.cpp b/src/engine/enum/ComponentType.cpp similarity index 95% rename from src/enum/ComponentType.cpp rename to src/engine/enum/ComponentType.cpp index 7dfbe93e..8ffb8a23 100644 --- a/src/enum/ComponentType.cpp +++ b/src/engine/enum/ComponentType.cpp @@ -1,6 +1,6 @@ -#include "ComponentType.h" -#include "../repository/world/WorldRepository.h" -#include "../context/ApplicationContext.h" +#include "../../../enum/ComponentType.h" +#include "../repository/WorldRepository.h" +#include "../../ApplicationContext.h" #define DEFINE_COMPONENT(TYPE, NAME, JSON_KEY, ICON, DEPS, CLASS, CREATOR) \ { \ diff --git a/src/enum/ComponentType.h b/src/engine/enum/ComponentType.h similarity index 96% rename from src/enum/ComponentType.h rename to src/engine/enum/ComponentType.h index 6a5433d3..90bddb09 100644 --- a/src/enum/ComponentType.h +++ b/src/engine/enum/ComponentType.h @@ -5,7 +5,7 @@ #include #include #include -#include "../common/interface/Icons.h" +#include "../../../common/Icons.h" namespace Metal { class Inspectable; diff --git a/src/enum/PassType.h b/src/engine/enum/PassType.h similarity index 100% rename from src/enum/PassType.h rename to src/engine/enum/PassType.h diff --git a/src/enum/ResourceType.h b/src/engine/enum/ResourceType.h similarity index 100% rename from src/enum/ResourceType.h rename to src/engine/enum/ResourceType.h diff --git a/src/context/engine/frame-builder/EngineFrame.cpp b/src/engine/frame-builder/EngineFrame.cpp similarity index 100% rename from src/context/engine/frame-builder/EngineFrame.cpp rename to src/engine/frame-builder/EngineFrame.cpp diff --git a/src/context/engine/frame-builder/EngineFrame.h b/src/engine/frame-builder/EngineFrame.h similarity index 96% rename from src/context/engine/frame-builder/EngineFrame.h rename to src/engine/frame-builder/EngineFrame.h index b86e3edc..66c8446d 100644 --- a/src/context/engine/frame-builder/EngineFrame.h +++ b/src/engine/frame-builder/EngineFrame.h @@ -4,7 +4,7 @@ #include #include #include -#include "../../../repository/abstract/RuntimeResource.h" +#include "../resource/RuntimeResource.h" #include "../passes/CommandBufferRecorder.h" #include "../passes/AbstractPass.h" diff --git a/src/context/engine/frame-builder/EngineFrameBuilder.cpp b/src/engine/frame-builder/EngineFrameBuilder.cpp similarity index 100% rename from src/context/engine/frame-builder/EngineFrameBuilder.cpp rename to src/engine/frame-builder/EngineFrameBuilder.cpp diff --git a/src/context/engine/frame-builder/EngineFrameBuilder.h b/src/engine/frame-builder/EngineFrameBuilder.h similarity index 95% rename from src/context/engine/frame-builder/EngineFrameBuilder.h rename to src/engine/frame-builder/EngineFrameBuilder.h index fd42fc69..0462a415 100644 --- a/src/context/engine/frame-builder/EngineFrameBuilder.h +++ b/src/engine/frame-builder/EngineFrameBuilder.h @@ -8,8 +8,8 @@ #include #include "structures/ResourceBuilder.h" -#include "../../../enum/PassType.h" -#include "../../../service/buffer/BufferInstance.h" +#include "../enum/PassType.h" +#include "../resource/BufferInstance.h" namespace Metal { class CommandBufferRecorder; diff --git a/src/context/engine/frame-builder/structures/BufferBuilder.cpp b/src/engine/frame-builder/structures/BufferBuilder.cpp similarity index 82% rename from src/context/engine/frame-builder/structures/BufferBuilder.cpp rename to src/engine/frame-builder/structures/BufferBuilder.cpp index fd2ff11a..2dce9a2c 100644 --- a/src/context/engine/frame-builder/structures/BufferBuilder.cpp +++ b/src/engine/frame-builder/structures/BufferBuilder.cpp @@ -1,7 +1,7 @@ #include "BufferBuilder.h" #include "../../../ApplicationContext.h" -#include "../../../../service/buffer/BufferInstance.h" -#include "../../../../service/buffer/BufferService.h" +#include "../../resource/BufferInstance.h" +#include "../../service/BufferService.h" namespace Metal { ResourceType BufferBuilder::getType() { diff --git a/src/context/engine/frame-builder/structures/BufferBuilder.h b/src/engine/frame-builder/structures/BufferBuilder.h similarity index 93% rename from src/context/engine/frame-builder/structures/BufferBuilder.h rename to src/engine/frame-builder/structures/BufferBuilder.h index 2620383c..740c9e69 100644 --- a/src/context/engine/frame-builder/structures/BufferBuilder.h +++ b/src/engine/frame-builder/structures/BufferBuilder.h @@ -4,7 +4,7 @@ #include "ResourceBuilder.h" #include -#include "../../../../service/buffer/BufferInstance.h" +#include "../../resource/BufferInstance.h" namespace Metal { class BufferBuilder final : public ResourceBuilder { diff --git a/src/context/engine/frame-builder/structures/CommandBufferRecorderBuilder.cpp b/src/engine/frame-builder/structures/CommandBufferRecorderBuilder.cpp similarity index 100% rename from src/context/engine/frame-builder/structures/CommandBufferRecorderBuilder.cpp rename to src/engine/frame-builder/structures/CommandBufferRecorderBuilder.cpp diff --git a/src/context/engine/frame-builder/structures/CommandBufferRecorderBuilder.h b/src/engine/frame-builder/structures/CommandBufferRecorderBuilder.h similarity index 100% rename from src/context/engine/frame-builder/structures/CommandBufferRecorderBuilder.h rename to src/engine/frame-builder/structures/CommandBufferRecorderBuilder.h diff --git a/src/context/engine/frame-builder/structures/FramebufferBuilder.cpp b/src/engine/frame-builder/structures/FramebufferBuilder.cpp similarity index 86% rename from src/context/engine/frame-builder/structures/FramebufferBuilder.cpp rename to src/engine/frame-builder/structures/FramebufferBuilder.cpp index 02d973f0..0978ee74 100644 --- a/src/context/engine/frame-builder/structures/FramebufferBuilder.cpp +++ b/src/engine/frame-builder/structures/FramebufferBuilder.cpp @@ -1,7 +1,7 @@ #include "FramebufferBuilder.h" #include "../../../ApplicationContext.h" -#include "../../../../service/framebuffer/FrameBufferService.h" -#include "../../../../service/framebuffer/FrameBufferInstance.h" +#include "../../service/FrameBufferService.h" +#include "../../resource/FrameBufferInstance.h" namespace Metal { ResourceType FramebufferBuilder::getType() { diff --git a/src/context/engine/frame-builder/structures/FramebufferBuilder.h b/src/engine/frame-builder/structures/FramebufferBuilder.h similarity index 100% rename from src/context/engine/frame-builder/structures/FramebufferBuilder.h rename to src/engine/frame-builder/structures/FramebufferBuilder.h diff --git a/src/context/engine/frame-builder/structures/PassBuilder.cpp b/src/engine/frame-builder/structures/PassBuilder.cpp similarity index 86% rename from src/context/engine/frame-builder/structures/PassBuilder.cpp rename to src/engine/frame-builder/structures/PassBuilder.cpp index 56ce5f6a..ee326176 100644 --- a/src/context/engine/frame-builder/structures/PassBuilder.cpp +++ b/src/engine/frame-builder/structures/PassBuilder.cpp @@ -1,8 +1,8 @@ #include "PassBuilder.h" #include "../../render-pass/impl/PostProcessingPass.h" -#include "../../compute-pass/impl/HWRayTracingPass.h" -#include "../../compute-pass/impl/TemporalAccumulationPass.h" -#include "../../compute-pass/impl/SpatialFilterPass.h" +#include "../../passes/impl/HWRayTracingPass.h" +#include "../../passes/impl/TemporalAccumulationPass.h" +#include "../../passes/impl/SpatialFilterPass.h" #include "../../render-pass/impl/tools/SelectionOutlinePass.h" #include "../../render-pass/impl/tools/GridPass.h" #include "../../render-pass/impl/tools/IconsPass.h" diff --git a/src/context/engine/frame-builder/structures/PassBuilder.h b/src/engine/frame-builder/structures/PassBuilder.h similarity index 93% rename from src/context/engine/frame-builder/structures/PassBuilder.h rename to src/engine/frame-builder/structures/PassBuilder.h index abba7912..e92c1cfd 100644 --- a/src/context/engine/frame-builder/structures/PassBuilder.h +++ b/src/engine/frame-builder/structures/PassBuilder.h @@ -2,8 +2,8 @@ #define METAL_ENGINE_PASSBUILDER_H #include "ResourceBuilder.h" -#include "../../../../enum/PassType.h" -#include "../../../../enum/ResourceType.h" +#include "../../enum/PassType.h" +#include "../../enum/ResourceType.h" namespace Metal { class PassBuilder final : public ResourceBuilder { diff --git a/src/context/engine/frame-builder/structures/ResourceBuilder.h b/src/engine/frame-builder/structures/ResourceBuilder.h similarity index 92% rename from src/context/engine/frame-builder/structures/ResourceBuilder.h rename to src/engine/frame-builder/structures/ResourceBuilder.h index ee26de66..c0bd11d5 100644 --- a/src/context/engine/frame-builder/structures/ResourceBuilder.h +++ b/src/engine/frame-builder/structures/ResourceBuilder.h @@ -1,7 +1,7 @@ #ifndef METAL_ENGINE_RESOURCEBUILDER_H #define METAL_ENGINE_RESOURCEBUILDER_H #include -#include "../../../../enum/ResourceType.h" +#include "../../enum/ResourceType.h" namespace Metal { class RuntimeResource; diff --git a/src/context/engine/frame-builder/structures/TextureBuilder.cpp b/src/engine/frame-builder/structures/TextureBuilder.cpp similarity index 89% rename from src/context/engine/frame-builder/structures/TextureBuilder.cpp rename to src/engine/frame-builder/structures/TextureBuilder.cpp index 72d776a6..91e17622 100644 --- a/src/context/engine/frame-builder/structures/TextureBuilder.cpp +++ b/src/engine/frame-builder/structures/TextureBuilder.cpp @@ -1,6 +1,6 @@ #include "TextureBuilder.h" #include "../../../ApplicationContext.h" -#include "../../../../service/texture/TextureInstance.h" +#include "../../resource/TextureInstance.h" namespace Metal { ResourceType TextureBuilder::getType() { diff --git a/src/context/engine/frame-builder/structures/TextureBuilder.h b/src/engine/frame-builder/structures/TextureBuilder.h similarity index 100% rename from src/context/engine/frame-builder/structures/TextureBuilder.h rename to src/engine/frame-builder/structures/TextureBuilder.h diff --git a/src/context/engine/compute-pass/AbstractComputePass.cpp b/src/engine/passes/AbstractComputePass.cpp similarity index 96% rename from src/context/engine/compute-pass/AbstractComputePass.cpp rename to src/engine/passes/AbstractComputePass.cpp index 1bc48f6d..b847add8 100644 --- a/src/context/engine/compute-pass/AbstractComputePass.cpp +++ b/src/engine/passes/AbstractComputePass.cpp @@ -1,8 +1,8 @@ -#include "AbstractComputePass.h" -#include "../../../context/ApplicationContext.h" -#include "../../../service/pipeline/PipelineInstance.h" -#include "../../../service/texture/TextureInstance.h" -#include "../../../util/ImageUtils.h" +#include "../compute-pass/AbstractComputePass.h" +#include "../../ApplicationContext.h" +#include "../resource/PipelineInstance.h" +#include "../resource/TextureInstance.h" +#include "../util/ImageUtils.h" namespace Metal { AbstractComputePass::AbstractComputePass(const std::string &id) : AbstractPass(id, true) { diff --git a/src/context/engine/compute-pass/AbstractComputePass.h b/src/engine/passes/AbstractComputePass.h similarity index 96% rename from src/context/engine/compute-pass/AbstractComputePass.h rename to src/engine/passes/AbstractComputePass.h index 8075789c..321e0989 100644 --- a/src/context/engine/compute-pass/AbstractComputePass.h +++ b/src/engine/passes/AbstractComputePass.h @@ -2,7 +2,7 @@ #define ABSTRACTCOMPUTEPASS_H #include -#include "../passes/AbstractPass.h" +#include "AbstractPass.h" namespace Metal { struct WorldRepository; diff --git a/src/context/engine/passes/AbstractPass.cpp b/src/engine/passes/AbstractPass.cpp similarity index 98% rename from src/context/engine/passes/AbstractPass.cpp rename to src/engine/passes/AbstractPass.cpp index 31c60932..2000f968 100644 --- a/src/context/engine/passes/AbstractPass.cpp +++ b/src/engine/passes/AbstractPass.cpp @@ -1,7 +1,7 @@ #include "AbstractPass.h" #include "../frame-builder/EngineFrame.h" #include "../../../context/ApplicationContext.h" -#include "../../../service/pipeline/PipelineInstance.h" +#include "../resource/PipelineInstance.h" namespace Metal { AbstractPass::AbstractPass(const std::string &id, bool isComputePass) : RuntimeResource(id), diff --git a/src/context/engine/passes/AbstractPass.h b/src/engine/passes/AbstractPass.h similarity index 96% rename from src/context/engine/passes/AbstractPass.h rename to src/engine/passes/AbstractPass.h index 549a49f5..f95e11fd 100644 --- a/src/context/engine/passes/AbstractPass.h +++ b/src/engine/passes/AbstractPass.h @@ -4,7 +4,7 @@ #include #include #include "../../../common/AbstractRuntimeComponent.h" -#include "../../../repository/abstract/RuntimeResource.h" +#include "../resource/RuntimeResource.h" namespace Metal { class EngineFrame; diff --git a/src/context/engine/render-pass/AbstractRenderPass.cpp b/src/engine/passes/AbstractRenderPass.cpp similarity index 83% rename from src/context/engine/render-pass/AbstractRenderPass.cpp rename to src/engine/passes/AbstractRenderPass.cpp index 48d82395..16cd6eb6 100644 --- a/src/context/engine/render-pass/AbstractRenderPass.cpp +++ b/src/engine/passes/AbstractRenderPass.cpp @@ -1,8 +1,8 @@ -#include "AbstractRenderPass.h" +#include "render-pass/AbstractRenderPass.h" #include "../../../context/ApplicationContext.h" -#include "../../../service/pipeline/PipelineInstance.h" -#include "../../../service/mesh/MeshInstance.h" -#include "../../../service/buffer/BufferInstance.h" +#include "../resource/PipelineInstance.h" +#include "../resource/MeshInstance.h" +#include "../resource/BufferInstance.h" namespace Metal { AbstractRenderPass::AbstractRenderPass(const std::string &id) : AbstractPass(id, false) { diff --git a/src/context/engine/render-pass/AbstractRenderPass.h b/src/engine/passes/AbstractRenderPass.h similarity index 93% rename from src/context/engine/render-pass/AbstractRenderPass.h rename to src/engine/passes/AbstractRenderPass.h index 39b4203c..a08bb11b 100644 --- a/src/context/engine/render-pass/AbstractRenderPass.h +++ b/src/engine/passes/AbstractRenderPass.h @@ -1,7 +1,7 @@ #ifndef ABSTRACTRENDERPASS_H #define ABSTRACTRENDERPASS_H -#include "../passes/AbstractPass.h" +#include "AbstractPass.h" #include "vulkan/vulkan.h" namespace Metal { diff --git a/src/context/engine/passes/CommandBufferRecorder.cpp b/src/engine/passes/CommandBufferRecorder.cpp similarity index 95% rename from src/context/engine/passes/CommandBufferRecorder.cpp rename to src/engine/passes/CommandBufferRecorder.cpp index 90bc3f73..f7019f61 100644 --- a/src/context/engine/passes/CommandBufferRecorder.cpp +++ b/src/engine/passes/CommandBufferRecorder.cpp @@ -3,12 +3,12 @@ #include -#include "../../../service/descriptor/DescriptorInstance.h" -#include "../../../service/framebuffer/FrameBufferInstance.h" -#include "../../../service/pipeline/PipelineInstance.h" +#include "../dto/DescriptorInstance.h" +#include "../resource/FrameBufferInstance.h" +#include "../resource/PipelineInstance.h" #include "../../ApplicationContext.h" #include "../render-pass/AbstractRenderPass.h" -#include "../../../util/VulkanUtils.h" +#include "../../vulkan/VulkanUtils.h" namespace Metal { void CommandBufferRecorder::createCommandBuffer() { diff --git a/src/context/engine/passes/CommandBufferRecorder.h b/src/engine/passes/CommandBufferRecorder.h similarity index 88% rename from src/context/engine/passes/CommandBufferRecorder.h rename to src/engine/passes/CommandBufferRecorder.h index ad428c13..7897160d 100644 --- a/src/context/engine/passes/CommandBufferRecorder.h +++ b/src/engine/passes/CommandBufferRecorder.h @@ -1,10 +1,10 @@ #ifndef RENDERPASS_H #define RENDERPASS_H -#include "../../../repository/abstract/RuntimeResource.h" +#include "../resource/RuntimeResource.h" #include #include -#include "../../../service/pipeline/PipelineInstance.h" -#include "../../../util/VulkanUtils.h" +#include "../resource/PipelineInstance.h" +#include "../../vulkan/VulkanUtils.h" namespace Metal { class AbstractPass; diff --git a/src/context/engine/compute-pass/impl/HWRayTracingPass.cpp b/src/engine/passes/impl/HWRayTracingPass.cpp similarity index 90% rename from src/context/engine/compute-pass/impl/HWRayTracingPass.cpp rename to src/engine/passes/impl/HWRayTracingPass.cpp index dcba2bfa..5a9dbeca 100644 --- a/src/context/engine/compute-pass/impl/HWRayTracingPass.cpp +++ b/src/engine/passes/impl/HWRayTracingPass.cpp @@ -1,11 +1,11 @@ -#include "./HWRayTracingPass.h" +#include "../../compute-pass/impl/HWRayTracingPass.h" #include "../../../ApplicationContext.h" -#include "../../../../service/framebuffer/FrameBufferInstance.h" -#include "../../../../service/pipeline/PipelineBuilder.h" -#include "../../../../service/pipeline/PipelineInstance.h" -#include "../../../../service/texture/TextureInstance.h" -#include "../../../../service/raytracing/RayTracingService.h" -#include "../../../../enum/EngineResourceIDs.h" +#include "../../resource/FrameBufferInstance.h" +#include "../../dto/PipelineBuilder.h" +#include "../../resource/PipelineInstance.h" +#include "../../resource/TextureInstance.h" +#include "../../service/RayTracingService.h" +#include "../../../editor/enum/EngineResourceIDs.h" namespace Metal { void HWRayTracingPass::onInitialize() { diff --git a/src/context/engine/compute-pass/impl/HWRayTracingPass.h b/src/engine/passes/impl/HWRayTracingPass.h similarity index 87% rename from src/context/engine/compute-pass/impl/HWRayTracingPass.h rename to src/engine/passes/impl/HWRayTracingPass.h index bdd574e5..860a2424 100644 --- a/src/context/engine/compute-pass/impl/HWRayTracingPass.h +++ b/src/engine/passes/impl/HWRayTracingPass.h @@ -1,7 +1,7 @@ #ifndef HWRAYTRACINGPASS_H #define HWRAYTRACINGPASS_H #include "../AbstractComputePass.h" -#include "../../../../dto/push-constant/HWRayTracingPushConstant.h" +#include "../../dto/HWRayTracingPushConstant.h" namespace Metal { class HWRayTracingPass final : public AbstractComputePass { diff --git a/src/context/engine/render-pass/impl/PostProcessingPass.cpp b/src/engine/passes/impl/PostProcessingPass.cpp similarity index 90% rename from src/context/engine/render-pass/impl/PostProcessingPass.cpp rename to src/engine/passes/impl/PostProcessingPass.cpp index db325602..543fe4aa 100644 --- a/src/context/engine/render-pass/impl/PostProcessingPass.cpp +++ b/src/engine/passes/impl/PostProcessingPass.cpp @@ -1,9 +1,9 @@ -#include "PostProcessingPass.h" +#include "../render-pass/impl/PostProcessingPass.h" #include "../../../../context/ApplicationContext.h" -#include "../../../../service/pipeline/PipelineBuilder.h" -#include "../../../../enum/EngineResourceIDs.h" +#include "../../dto/PipelineBuilder.h" +#include "../../../editor/enum/EngineResourceIDs.h" namespace Metal { diff --git a/src/context/engine/render-pass/impl/PostProcessingPass.h b/src/engine/passes/impl/PostProcessingPass.h similarity index 86% rename from src/context/engine/render-pass/impl/PostProcessingPass.h rename to src/engine/passes/impl/PostProcessingPass.h index b6bb3c4b..98dbcbc9 100644 --- a/src/context/engine/render-pass/impl/PostProcessingPass.h +++ b/src/engine/passes/impl/PostProcessingPass.h @@ -1,7 +1,7 @@ #ifndef POSTPROCESSINGPASS_H #define POSTPROCESSINGPASS_H #include "../AbstractRenderPass.h" -#include "../../../../dto/push-constant/PostProcessingPushConstant.h" +#include "../../dto/PostProcessingPushConstant.h" namespace Metal { class PostProcessingPass final : public AbstractRenderPass { diff --git a/src/context/engine/compute-pass/impl/SpatialFilterPass.cpp b/src/engine/passes/impl/SpatialFilterPass.cpp similarity index 85% rename from src/context/engine/compute-pass/impl/SpatialFilterPass.cpp rename to src/engine/passes/impl/SpatialFilterPass.cpp index f59bc568..3a3aa6ff 100644 --- a/src/context/engine/compute-pass/impl/SpatialFilterPass.cpp +++ b/src/engine/passes/impl/SpatialFilterPass.cpp @@ -1,8 +1,8 @@ -#include "SpatialFilterPass.h" +#include "../../compute-pass/impl/SpatialFilterPass.h" #include "../../../ApplicationContext.h" -#include "../../../../service/pipeline/PipelineBuilder.h" -#include "../../../../service/texture/TextureInstance.h" -#include "../../../../enum/EngineResourceIDs.h" +#include "../../dto/PipelineBuilder.h" +#include "../../resource/TextureInstance.h" +#include "../../../editor/enum/EngineResourceIDs.h" namespace Metal { void SpatialFilterPass::onInitialize() { diff --git a/src/context/engine/compute-pass/impl/SpatialFilterPass.h b/src/engine/passes/impl/SpatialFilterPass.h similarity index 100% rename from src/context/engine/compute-pass/impl/SpatialFilterPass.h rename to src/engine/passes/impl/SpatialFilterPass.h diff --git a/src/context/engine/compute-pass/impl/TemporalAccumulationPass.cpp b/src/engine/passes/impl/TemporalAccumulationPass.cpp similarity index 86% rename from src/context/engine/compute-pass/impl/TemporalAccumulationPass.cpp rename to src/engine/passes/impl/TemporalAccumulationPass.cpp index 3a885a0a..d7108241 100644 --- a/src/context/engine/compute-pass/impl/TemporalAccumulationPass.cpp +++ b/src/engine/passes/impl/TemporalAccumulationPass.cpp @@ -1,8 +1,8 @@ -#include "TemporalAccumulationPass.h" +#include "../../compute-pass/impl/TemporalAccumulationPass.h" #include "../../../ApplicationContext.h" -#include "../../../../service/pipeline/PipelineBuilder.h" -#include "../../../../service/texture/TextureInstance.h" -#include "../../../../enum/EngineResourceIDs.h" +#include "../../dto/PipelineBuilder.h" +#include "../../resource/TextureInstance.h" +#include "../../../editor/enum/EngineResourceIDs.h" namespace Metal { void TemporalAccumulationPass::onInitialize() { diff --git a/src/context/engine/compute-pass/impl/TemporalAccumulationPass.h b/src/engine/passes/impl/TemporalAccumulationPass.h similarity index 100% rename from src/context/engine/compute-pass/impl/TemporalAccumulationPass.h rename to src/engine/passes/impl/TemporalAccumulationPass.h diff --git a/src/repository/engine/EngineRepository.cpp b/src/engine/repository/EngineRepository.cpp similarity index 97% rename from src/repository/engine/EngineRepository.cpp rename to src/engine/repository/EngineRepository.cpp index 1add07b1..f5ac4024 100644 --- a/src/repository/engine/EngineRepository.cpp +++ b/src/engine/repository/EngineRepository.cpp @@ -1,7 +1,7 @@ -#include "EngineRepository.h" +#include "../../../repository/engine/EngineRepository.h" -#include "../../common/interface/Icons.h" -#include "../../context/ApplicationContext.h" +#include "../../../common/Icons.h" +#include "../../ApplicationContext.h" #define LEVEL_OF_DETAIL "Level of detail" #define PATH_TRACER "Path tracer" diff --git a/src/repository/engine/EngineRepository.h b/src/engine/repository/EngineRepository.h similarity index 94% rename from src/repository/engine/EngineRepository.h rename to src/engine/repository/EngineRepository.h index de4db803..0870e1b0 100644 --- a/src/repository/engine/EngineRepository.h +++ b/src/engine/repository/EngineRepository.h @@ -1,8 +1,8 @@ #ifndef ENGINEREPO_H #define ENGINEREPO_H -#include "../../common/inspection/Inspectable.h" +#include "../../../common/Inspectable.h" #include -#include "../../util/Serializable.h" +#include "../../../common/Serializable.h" namespace Metal { struct EngineRepository final : Inspectable, Serializable { diff --git a/src/repository/abstract/ResourceRepository.h b/src/engine/repository/ResourceRepository.h similarity index 83% rename from src/repository/abstract/ResourceRepository.h rename to src/engine/repository/ResourceRepository.h index bebf7cfb..20ec9f5d 100644 --- a/src/repository/abstract/ResourceRepository.h +++ b/src/engine/repository/ResourceRepository.h @@ -2,7 +2,7 @@ #define RESOURCEREPOSITORY_H #include -#include "RuntimeResource.h" +#include "../repository/abstract/RuntimeResource.h" namespace Metal { struct ResourceRepository final { diff --git a/src/repository/runtime/RuntimeRepository.h b/src/engine/repository/RuntimeRepository.h similarity index 100% rename from src/repository/runtime/RuntimeRepository.h rename to src/engine/repository/RuntimeRepository.h diff --git a/src/repository/world/WorldRepository.cpp b/src/engine/repository/WorldRepository.cpp similarity index 96% rename from src/repository/world/WorldRepository.cpp rename to src/engine/repository/WorldRepository.cpp index fd9a1cc9..aa0da49b 100644 --- a/src/repository/world/WorldRepository.cpp +++ b/src/engine/repository/WorldRepository.cpp @@ -1,9 +1,9 @@ -#include "WorldRepository.h" +#include "../../../repository/world/WorldRepository.h" -#include "../../context/ApplicationContext.h" -#include "../../enum/ComponentType.h" -#include "../../service/mesh/SceneData.h" -#include "../../util/serialization-definitions.h" +#include "../../ApplicationContext.h" +#include "../enum/ComponentType.h" +#include "../../editor/dto/SceneData.h" +#include "../../editor/util/serialization-definitions.h" namespace Metal { entt::entity WorldRepository::createEntity() { diff --git a/src/repository/world/WorldRepository.h b/src/engine/repository/WorldRepository.h similarity index 73% rename from src/repository/world/WorldRepository.h rename to src/engine/repository/WorldRepository.h index 2088eff3..86d0f415 100644 --- a/src/repository/world/WorldRepository.h +++ b/src/engine/repository/WorldRepository.h @@ -6,15 +6,15 @@ #include #include -#include "../../common/AbstractRuntimeComponent.h" -#include "../../util/Serializable.h" -#include "../../enum/engine-definitions.h" -#include "../../service/camera/Camera.h" -#include "impl/MetadataComponent.h" -#include "../../enum/ComponentType.h" -#include "components/TransformComponent.h" -#include "components/PrimitiveComponent.h" -#include "components/VolumeComponent.h" +#include "../../../common/AbstractRuntimeComponent.h" +#include "../../../common/Serializable.h" +#include "../../editor/enum/engine-definitions.h" +#include "../dto/Camera.h" +#include "../dto/MetadataComponent.h" +#include "../enum/ComponentType.h" +#include "../dto/TransformComponent.h" +#include "../dto/PrimitiveComponent.h" +#include "../dto/VolumeComponent.h" namespace Metal { class Inspectable; diff --git a/src/service/buffer/BufferInstance.cpp b/src/engine/resource/BufferInstance.cpp similarity index 63% rename from src/service/buffer/BufferInstance.cpp rename to src/engine/resource/BufferInstance.cpp index 53e2b27f..a8698cb0 100644 --- a/src/service/buffer/BufferInstance.cpp +++ b/src/engine/resource/BufferInstance.cpp @@ -1,10 +1,10 @@ -#include "BufferInstance.h" +#include "../../../service/buffer/BufferInstance.h" #include -#include "../../service/log/LogService.h" -#include "../../context/ApplicationContext.h" -#include "../../context/vulkan/VulkanContext.h" -#include "../../util/VulkanUtils.h" +#include "../../editor/service/LogService.h" +#include "../../ApplicationContext.h" +#include "../../vulkan/VulkanContext.h" +#include "../../vulkan/VulkanUtils.h" namespace Metal { BufferType BufferInstance::getBufferType() { diff --git a/src/service/buffer/BufferInstance.h b/src/engine/resource/BufferInstance.h similarity index 93% rename from src/service/buffer/BufferInstance.h rename to src/engine/resource/BufferInstance.h index 1cd66932..175a1cbd 100644 --- a/src/service/buffer/BufferInstance.h +++ b/src/engine/resource/BufferInstance.h @@ -3,7 +3,7 @@ #include -#include "../../repository/abstract/RuntimeResource.h" +#include "RuntimeResource.h" namespace Metal { enum BufferType { diff --git a/src/service/framebuffer/FrameBufferAttachment.cpp b/src/engine/resource/FrameBufferAttachment.cpp similarity index 81% rename from src/service/framebuffer/FrameBufferAttachment.cpp rename to src/engine/resource/FrameBufferAttachment.cpp index e04d3983..cf4a0c4c 100644 --- a/src/service/framebuffer/FrameBufferAttachment.cpp +++ b/src/engine/resource/FrameBufferAttachment.cpp @@ -1,7 +1,7 @@ -#include "FrameBufferAttachment.h" +#include "../../../service/framebuffer/FrameBufferAttachment.h" -#include "../../context/ApplicationContext.h" +#include "../../ApplicationContext.h" namespace Metal { void FrameBufferAttachment::dispose() const { diff --git a/src/service/framebuffer/FrameBufferAttachment.h b/src/engine/resource/FrameBufferAttachment.h similarity index 90% rename from src/service/framebuffer/FrameBufferAttachment.h rename to src/engine/resource/FrameBufferAttachment.h index 1c865e8f..6e559c13 100644 --- a/src/service/framebuffer/FrameBufferAttachment.h +++ b/src/engine/resource/FrameBufferAttachment.h @@ -1,6 +1,6 @@ #ifndef FRAMEBUFFERATTACHMENT_H #define FRAMEBUFFERATTACHMENT_H -#include "../descriptor/DescriptorInstance.h" +#include "../dto/DescriptorInstance.h" namespace Metal { struct FrameBufferAttachment final { diff --git a/src/service/framebuffer/FrameBufferInstance.h b/src/engine/resource/FrameBufferInstance.h similarity index 92% rename from src/service/framebuffer/FrameBufferInstance.h rename to src/engine/resource/FrameBufferInstance.h index 9de1a0e7..3587924e 100644 --- a/src/service/framebuffer/FrameBufferInstance.h +++ b/src/engine/resource/FrameBufferInstance.h @@ -1,7 +1,7 @@ #ifndef FRAMEBUFFER_INSTANCE_H #define FRAMEBUFFER_INSTANCE_H -#include "../../repository/abstract/RuntimeResource.h" +#include "RuntimeResource.h" #include #include #include "FrameBufferAttachment.h" diff --git a/src/service/mesh/MeshInstance.h b/src/engine/resource/MeshInstance.h similarity index 88% rename from src/service/mesh/MeshInstance.h rename to src/engine/resource/MeshInstance.h index d869a3bd..6321e421 100644 --- a/src/service/mesh/MeshInstance.h +++ b/src/engine/resource/MeshInstance.h @@ -1,6 +1,6 @@ #ifndef MESHINSTANCE_H #define MESHINSTANCE_H -#include "../../repository/abstract/RuntimeResource.h" +#include "RuntimeResource.h" namespace Metal { struct BufferInstance; diff --git a/src/service/pipeline/PipelineInstance.h b/src/engine/resource/PipelineInstance.h similarity index 92% rename from src/service/pipeline/PipelineInstance.h rename to src/engine/resource/PipelineInstance.h index b9361236..321f10c9 100644 --- a/src/service/pipeline/PipelineInstance.h +++ b/src/engine/resource/PipelineInstance.h @@ -2,8 +2,8 @@ #define PIPELINEINSTANCE_H #include -#include "../../repository/abstract/RuntimeResource.h" -#include "../descriptor/DescriptorInstance.h" +#include "RuntimeResource.h" +#include "../dto/DescriptorInstance.h" #include namespace Metal { diff --git a/src/repository/abstract/RuntimeResource.h b/src/engine/resource/RuntimeResource.h similarity index 93% rename from src/repository/abstract/RuntimeResource.h rename to src/engine/resource/RuntimeResource.h index 045a102f..a99d4632 100644 --- a/src/repository/abstract/RuntimeResource.h +++ b/src/engine/resource/RuntimeResource.h @@ -1,7 +1,7 @@ #ifndef IGPURESOURCE_H #define IGPURESOURCE_H -#include "../../enum/ResourceType.h" -#include "../../util/Util.h" +#include "../enum/ResourceType.h" +#include "../../editor/util/Util.h" #include using Clock = std::chrono::high_resolution_clock; diff --git a/src/service/voxel/SVOInstance.h b/src/engine/resource/SVOInstance.h similarity index 80% rename from src/service/voxel/SVOInstance.h rename to src/engine/resource/SVOInstance.h index 954d3296..6c13542f 100644 --- a/src/service/voxel/SVOInstance.h +++ b/src/engine/resource/SVOInstance.h @@ -1,7 +1,7 @@ #ifndef SVOINSTANCE_H #define SVOINSTANCE_H -#include "../../repository/abstract/RuntimeResource.h" -#include "../../service/buffer/BufferInstance.h" +#include "RuntimeResource.h" +#include "BufferInstance.h" namespace Metal { struct DescriptorInstance; diff --git a/src/service/texture/TextureInstance.h b/src/engine/resource/TextureInstance.h similarity index 83% rename from src/service/texture/TextureInstance.h rename to src/engine/resource/TextureInstance.h index 31bdd44a..0f78471e 100644 --- a/src/service/texture/TextureInstance.h +++ b/src/engine/resource/TextureInstance.h @@ -2,9 +2,9 @@ #define TEXTUREINSTANCE_H #include -#include "../descriptor/DescriptorInstance.h" -#include "../../repository/abstract/RuntimeResource.h" -#include "../../context/vulkan/VulkanContext.h" +#include "../dto/DescriptorInstance.h" +#include "../../../common/RuntimeResource.h" +#include "../../vulkan/VulkanContext.h" namespace Metal { struct TextureInstance final : RuntimeResource { diff --git a/src/service/buffer/BufferService.cpp b/src/engine/service/BufferService.cpp similarity index 97% rename from src/service/buffer/BufferService.cpp rename to src/engine/service/BufferService.cpp index fa569bfd..0b6beec3 100644 --- a/src/service/buffer/BufferService.cpp +++ b/src/engine/service/BufferService.cpp @@ -1,8 +1,8 @@ -#include "BufferService.h" +#include "../../../service/buffer/BufferService.h" -#include "../../context/ApplicationContext.h" -#include "../../util/VulkanUtils.h" -#include "BufferInstance.h" +#include "../../ApplicationContext.h" +#include "../../vulkan/VulkanUtils.h" +#include "../resource/BufferInstance.h" namespace Metal { BufferInstance *BufferService::createBuffer(const std::string &id, VkDeviceSize bufferSize, diff --git a/src/service/buffer/BufferService.h b/src/engine/service/BufferService.h similarity index 95% rename from src/service/buffer/BufferService.h rename to src/engine/service/BufferService.h index 54c920cf..91de4573 100644 --- a/src/service/buffer/BufferService.h +++ b/src/engine/service/BufferService.h @@ -3,8 +3,8 @@ #include #include -#include "../abstract/AbstractResourceService.h" -#include "BufferInstance.h" +#include "../../../common/AbstractResourceService.h" +#include "../resource/BufferInstance.h" #include "vulkan/vulkan.h" namespace Metal { diff --git a/src/service/camera/CameraService.cpp b/src/engine/service/CameraService.cpp similarity index 98% rename from src/service/camera/CameraService.cpp rename to src/engine/service/CameraService.cpp index 723c06d6..9058a3f1 100644 --- a/src/service/camera/CameraService.cpp +++ b/src/engine/service/CameraService.cpp @@ -1,7 +1,7 @@ -#include "CameraService.h" +#include "../../../service/camera/CameraService.h" -#include "Camera.h" -#include "../../context/ApplicationContext.h" +#include "../dto/Camera.h" +#include "../../ApplicationContext.h" namespace Metal { // Per frame diff --git a/src/service/camera/CameraService.h b/src/engine/service/CameraService.h similarity index 94% rename from src/service/camera/CameraService.h rename to src/engine/service/CameraService.h index 967f3a1c..98efd602 100644 --- a/src/service/camera/CameraService.h +++ b/src/engine/service/CameraService.h @@ -1,7 +1,7 @@ #ifndef CAMERASYSTEM_H #define CAMERASYSTEM_H -#include "../../common/AbstractRuntimeComponent.h" +#include "../../../common/AbstractRuntimeComponent.h" #include #include diff --git a/src/service/passes/CommandBufferRecorderService.h b/src/engine/service/CommandBufferRecorderService.h similarity index 85% rename from src/service/passes/CommandBufferRecorderService.h rename to src/engine/service/CommandBufferRecorderService.h index c05d1d50..d4ce7c7c 100644 --- a/src/service/passes/CommandBufferRecorderService.h +++ b/src/engine/service/CommandBufferRecorderService.h @@ -1,8 +1,8 @@ #ifndef COMMANDBUFFERRECORDERSERVICE_H #define COMMANDBUFFERRECORDERSERVICE_H -#include "../abstract/AbstractResourceService.h" -#include "../../context/engine/passes/CommandBufferRecorder.h" +#include "../../../common/AbstractResourceService.h" +#include "../passes/CommandBufferRecorder.h" namespace Metal { class CommandBufferRecorderService final : public AbstractResourceService { diff --git a/src/service/descriptor/DescriptorSetService.cpp b/src/engine/service/DescriptorSetService.cpp similarity index 96% rename from src/service/descriptor/DescriptorSetService.cpp rename to src/engine/service/DescriptorSetService.cpp index 81f7093a..3ee642d5 100644 --- a/src/service/descriptor/DescriptorSetService.cpp +++ b/src/engine/service/DescriptorSetService.cpp @@ -1,12 +1,12 @@ -#include "DescriptorSetService.h" -#include "../../service/pipeline/PipelineBuilder.h" -#include "../../service/buffer/BufferInstance.h" -#include "../../service/log/LogService.h" -#include "../../context/ApplicationContext.h" -#include "../framebuffer/FrameBufferAttachment.h" -#include "../framebuffer/FrameBufferInstance.h" -#include "../texture/TextureInstance.h" -#include "../../util/VulkanUtils.h" +#include "../../../service/descriptor/DescriptorSetService.h" +#include "../dto/PipelineBuilder.h" +#include "../resource/BufferInstance.h" +#include "../../editor/service/LogService.h" +#include "../../ApplicationContext.h" +#include "../resource/FrameBufferAttachment.h" +#include "../../../service/framebuffer/FrameBufferInstance.h" +#include "../resource/TextureInstance.h" +#include "../../vulkan/VulkanUtils.h" namespace Metal { DescriptorInstance *DescriptorSetService::createDescriptor(const PipelineBuilder &pipelineBuilder, const std::string &id, VkShaderStageFlags stageFlags) { diff --git a/src/service/descriptor/DescriptorSetService.h b/src/engine/service/DescriptorSetService.h similarity index 91% rename from src/service/descriptor/DescriptorSetService.h rename to src/engine/service/DescriptorSetService.h index c11de27e..3777cf71 100644 --- a/src/service/descriptor/DescriptorSetService.h +++ b/src/engine/service/DescriptorSetService.h @@ -1,8 +1,8 @@ #ifndef DESCRIPTORSETSERVICE_H #define DESCRIPTORSETSERVICE_H -#include "../abstract/AbstractResourceService.h" -#include "DescriptorInstance.h" +#include "../../../common/AbstractResourceService.h" +#include "../dto/DescriptorInstance.h" namespace Metal { struct PipelineBuilder; diff --git a/src/service/framebuffer/FrameBufferService.cpp b/src/engine/service/FrameBufferService.cpp similarity index 98% rename from src/service/framebuffer/FrameBufferService.cpp rename to src/engine/service/FrameBufferService.cpp index 3cb4a0ff..5188c427 100644 --- a/src/service/framebuffer/FrameBufferService.cpp +++ b/src/engine/service/FrameBufferService.cpp @@ -1,13 +1,13 @@ -#include "FrameBufferService.h" +#include "../../../service/framebuffer/FrameBufferService.h" #include #include #include #include "FrameBufferInstance.h" -#include "../../util/VulkanUtils.h" -#include "FrameBufferAttachment.h" -#include "../../context/ApplicationContext.h" +#include "../../vulkan/VulkanUtils.h" +#include "../resource/FrameBufferAttachment.h" +#include "../../ApplicationContext.h" namespace Metal { diff --git a/src/service/framebuffer/FrameBufferService.h b/src/engine/service/FrameBufferService.h similarity index 93% rename from src/service/framebuffer/FrameBufferService.h rename to src/engine/service/FrameBufferService.h index 15fab167..985f3ab4 100644 --- a/src/service/framebuffer/FrameBufferService.h +++ b/src/engine/service/FrameBufferService.h @@ -5,8 +5,8 @@ #include #include -#include "../abstract/AbstractResourceService.h" -#include "FrameBufferInstance.h" +#include "../../../common/AbstractResourceService.h" +#include "../resource/FrameBufferInstance.h" namespace Metal { struct FrameBufferAttachment; diff --git a/src/service/lights/LightService.cpp b/src/engine/service/LightService.cpp similarity index 90% rename from src/service/lights/LightService.cpp rename to src/engine/service/LightService.cpp index 2ce80c93..e120c769 100644 --- a/src/service/lights/LightService.cpp +++ b/src/engine/service/LightService.cpp @@ -1,7 +1,7 @@ -#include "LightService.h" -#include "../../context/ApplicationContext.h" -#include "../buffer/BufferInstance.h" -#include "../../enum/EngineResourceIDs.h" +#include "../../../service/lights/LightService.h" +#include "../../ApplicationContext.h" +#include "../resource/BufferInstance.h" +#include "../../editor/enum/EngineResourceIDs.h" namespace Metal { void LightService::registerLights() { diff --git a/src/service/lights/LightService.h b/src/engine/service/LightService.h similarity index 91% rename from src/service/lights/LightService.h rename to src/engine/service/LightService.h index 35a71ace..c7046f2a 100644 --- a/src/service/lights/LightService.h +++ b/src/engine/service/LightService.h @@ -2,8 +2,8 @@ #define LIGHTSSERVICE_H #include -#include "../../common/AbstractRuntimeComponent.h" -#include "../../dto/buffers/LightData.h" +#include "../../../common/AbstractRuntimeComponent.h" +#include "../dto/LightData.h" namespace Metal { class LightService final : public AbstractRuntimeComponent { diff --git a/src/service/material/MaterialService.cpp b/src/engine/service/MaterialService.cpp similarity index 88% rename from src/service/material/MaterialService.cpp rename to src/engine/service/MaterialService.cpp index 80c72174..ce5ef1cf 100644 --- a/src/service/material/MaterialService.cpp +++ b/src/engine/service/MaterialService.cpp @@ -1,9 +1,9 @@ -#include "MaterialService.h" +#include "../../../service/material/MaterialService.h" -#include "../../util/serialization-definitions.h" -#include "../../dto/buffers/MeshMetadata.h" +#include "../../editor/util/serialization-definitions.h" +#include "../dto/MeshMetadata.h" -#include "../../context/ApplicationContext.h" +#include "../../ApplicationContext.h" namespace Metal { diff --git a/src/service/material/MaterialService.h b/src/engine/service/MaterialService.h similarity index 100% rename from src/service/material/MaterialService.h rename to src/engine/service/MaterialService.h diff --git a/src/service/mesh/MeshService.cpp b/src/engine/service/MeshService.cpp similarity index 84% rename from src/service/mesh/MeshService.cpp rename to src/engine/service/MeshService.cpp index cf7fbe17..a642e127 100644 --- a/src/service/mesh/MeshService.cpp +++ b/src/engine/service/MeshService.cpp @@ -1,18 +1,18 @@ -#include "MeshService.h" -#include "MeshInstance.h" -#include "MeshData.h" -#include "SceneData.h" +#include "../../../service/mesh/MeshService.h" +#include "../resource/MeshInstance.h" +#include "../dto/MeshData.h" +#include "../../editor/dto/SceneData.h" -#include "../../context/vulkan/VulkanContext.h" -#include "../../util/FilesUtil.h" -#include "../../util/serialization-definitions.h" +#include "../../vulkan/VulkanContext.h" +#include "../../editor/util/FilesUtil.h" +#include "../../editor/util/serialization-definitions.h" #include #include -#include "../../context/ApplicationContext.h" -#include "../../repository/world/components/PrimitiveComponent.h" -#include "../../repository/world/components/TransformComponent.h" +#include "../../ApplicationContext.h" +#include "../dto/PrimitiveComponent.h" +#include "../dto/TransformComponent.h" namespace Metal { MeshInstance *MeshService::create(const std::string &id) { diff --git a/src/service/mesh/MeshService.h b/src/engine/service/MeshService.h similarity index 78% rename from src/service/mesh/MeshService.h rename to src/engine/service/MeshService.h index 68535a20..396af5d1 100644 --- a/src/service/mesh/MeshService.h +++ b/src/engine/service/MeshService.h @@ -1,8 +1,8 @@ #ifndef MESHSERVICE_H #define MESHSERVICE_H -#include "../../service/abstract/AbstractResourceService.h" -#include "MeshInstance.h" -#include "../../enum/engine-definitions.h" +#include "../../../common/AbstractResourceService.h" +#include "../resource/MeshInstance.h" +#include "../../editor/enum/engine-definitions.h" namespace Metal { struct MeshData; diff --git a/src/service/pipeline/PipelineService.cpp b/src/engine/service/PipelineService.cpp similarity index 97% rename from src/service/pipeline/PipelineService.cpp rename to src/engine/service/PipelineService.cpp index beff6a04..56884e6d 100644 --- a/src/service/pipeline/PipelineService.cpp +++ b/src/engine/service/PipelineService.cpp @@ -1,16 +1,16 @@ -#include "PipelineService.h" +#include "../../../service/pipeline/PipelineService.h" -#include "PipelineBuilder.h" -#include "../../util/ShaderUtil.h" -#include "../../context/ApplicationContext.h" -#include "../../util/VulkanUtils.h" +#include "../dto/PipelineBuilder.h" +#include "../util/ShaderUtil.h" +#include "../../ApplicationContext.h" +#include "../../vulkan/VulkanUtils.h" #include "../framebuffer/FrameBufferInstance.h" -#include "../pipeline/PipelineInstance.h" -#include "../mesh/MeshData.h" -#include "../mesh/VertexData.h" -#include "../descriptor/DescriptorInstance.h" -#include "../framebuffer/FrameBufferAttachment.h" -#include "../buffer/BufferInstance.h" +#include "../resource/PipelineInstance.h" +#include "../dto/MeshData.h" +#include "../../context/editor/dto/VertexData.h" +#include "../dto/DescriptorInstance.h" +#include "../resource/FrameBufferAttachment.h" +#include "../resource/BufferInstance.h" namespace Metal { void PipelineService::createPipelineLayout( diff --git a/src/service/pipeline/PipelineService.h b/src/engine/service/PipelineService.h similarity index 90% rename from src/service/pipeline/PipelineService.h rename to src/engine/service/PipelineService.h index 9ac16eaa..d43d8ce1 100644 --- a/src/service/pipeline/PipelineService.h +++ b/src/engine/service/PipelineService.h @@ -2,9 +2,9 @@ #define PIPELINESERVICE_H #include -#include "../abstract/AbstractResourceService.h" -#include "../descriptor/DescriptorSetService.h" -#include "PipelineInstance.h" +#include "../../../common/AbstractResourceService.h" +#include "DescriptorSetService.h" +#include "../resource/PipelineInstance.h" namespace Metal { struct PipelineBuilder; diff --git a/src/service/raytracing/RayTracingService.cpp b/src/engine/service/RayTracingService.cpp similarity index 97% rename from src/service/raytracing/RayTracingService.cpp rename to src/engine/service/RayTracingService.cpp index fd2b6de0..1210906e 100644 --- a/src/service/raytracing/RayTracingService.cpp +++ b/src/engine/service/RayTracingService.cpp @@ -1,12 +1,12 @@ -#include "RayTracingService.h" -#include "../../context/ApplicationContext.h" -#include "../buffer/BufferInstance.h" -#include "../descriptor/DescriptorInstance.h" -#include "../descriptor/DescriptorBinding.h" -#include "../mesh/MeshInstance.h" -#include "../mesh/VertexData.h" -#include "../../util/VulkanUtils.h" -#include "../../enum/EngineResourceIDs.h" +#include "../../../service/raytracing/RayTracingService.h" +#include "../../ApplicationContext.h" +#include "../resource/BufferInstance.h" +#include "../dto/DescriptorInstance.h" +#include "../../../service/descriptor/DescriptorBinding.h" +#include "../resource/MeshInstance.h" +#include "../dto/VertexData.h" +#include "../../vulkan/VulkanUtils.h" +#include "../../editor/enum/EngineResourceIDs.h" #include namespace Metal { diff --git a/src/service/raytracing/RayTracingService.h b/src/engine/service/RayTracingService.h similarity index 92% rename from src/service/raytracing/RayTracingService.h rename to src/engine/service/RayTracingService.h index bfa42ac6..a646b23c 100644 --- a/src/service/raytracing/RayTracingService.h +++ b/src/engine/service/RayTracingService.h @@ -1,14 +1,14 @@ #ifndef RAYTRACINGSERVICE_H #define RAYTRACINGSERVICE_H -#include "../../dto/buffers/MeshMetadata.h" -#include "../../enum/engine-definitions.h" +#include "../dto/MeshMetadata.h" +#include "../../editor/enum/engine-definitions.h" #include #include #include #include #include -#include "../../common/AbstractRuntimeComponent.h" +#include "../../../common/AbstractRuntimeComponent.h" namespace Metal { struct BufferInstance; diff --git a/src/repository/streaming/StreamingService.cpp b/src/engine/service/StreamingService.cpp similarity index 87% rename from src/repository/streaming/StreamingService.cpp rename to src/engine/service/StreamingService.cpp index a3c3667d..6ddb487a 100644 --- a/src/repository/streaming/StreamingService.cpp +++ b/src/engine/service/StreamingService.cpp @@ -1,11 +1,11 @@ -#include "StreamingService.h" +#include "../../../repository/streaming/StreamingService.h" -#include "../../context/ApplicationContext.h" -#include "../../service/voxel/SVOInstance.h" -#include "../../service/mesh/MeshInstance.h" -#include "../../service/texture/TextureInstance.h" +#include "../../ApplicationContext.h" +#include "../resource/SVOInstance.h" +#include "../resource/MeshInstance.h" +#include "../resource/TextureInstance.h" -#include "../../repository/world/components/PrimitiveComponent.h" +#include "../dto/PrimitiveComponent.h" namespace Metal { static constexpr int MAX_TIMEOUT = 10000; diff --git a/src/repository/streaming/StreamingService.h b/src/engine/service/StreamingService.h similarity index 78% rename from src/repository/streaming/StreamingService.h rename to src/engine/service/StreamingService.h index 2fcba091..f2b6a1d8 100644 --- a/src/repository/streaming/StreamingService.h +++ b/src/engine/service/StreamingService.h @@ -4,9 +4,9 @@ #include #include -#include "../../service/abstract/AbstractResourceService.h" -#include "../abstract/AbstractCoreRepository.h" -#include "../abstract/RuntimeResource.h" +#include "../../../common/AbstractResourceService.h" +#include "../../../common/AbstractCoreRepository.h" +#include "../../../repository/abstract/RuntimeResource.h" using Clock = std::chrono::high_resolution_clock; using TimePoint = std::chrono::time_point; diff --git a/src/service/texture/TextureService.cpp b/src/engine/service/TextureService.cpp similarity index 98% rename from src/service/texture/TextureService.cpp rename to src/engine/service/TextureService.cpp index d5eacf08..4e71cd3f 100644 --- a/src/service/texture/TextureService.cpp +++ b/src/engine/service/TextureService.cpp @@ -1,16 +1,16 @@ -#include "TextureService.h" +#include "../../../service/texture/TextureService.h" #include -#include "../../util/ImageUtils.h" +#include "../util/ImageUtils.h" #include #include -#include "TextureData.h" -#include "../../context/ApplicationContext.h" -#include "../../service/texture/TextureInstance.h" -#include "../../service/buffer/BufferInstance.h" +#include "../dto/TextureData.h" +#include "../../ApplicationContext.h" +#include "../resource/TextureInstance.h" +#include "../resource/BufferInstance.h" namespace Metal { void TextureService::copyBufferToImage(const VkBuffer &vkBuffer, const TextureInstance *image, diff --git a/src/service/texture/TextureService.h b/src/engine/service/TextureService.h similarity index 94% rename from src/service/texture/TextureService.h rename to src/engine/service/TextureService.h index 40d00e1f..4184817f 100644 --- a/src/service/texture/TextureService.h +++ b/src/engine/service/TextureService.h @@ -4,9 +4,9 @@ #include #include -#include "TextureData.h" -#include "../abstract/AbstractResourceService.h" -#include "TextureInstance.h" +#include "../dto/TextureData.h" +#include "../../../common/AbstractResourceService.h" +#include "../resource/TextureInstance.h" namespace Metal { struct TextureInstance; diff --git a/src/service/transform/TransformService.cpp b/src/engine/service/TransformService.cpp similarity index 90% rename from src/service/transform/TransformService.cpp rename to src/engine/service/TransformService.cpp index e977dc2f..8a7a0a4f 100644 --- a/src/service/transform/TransformService.cpp +++ b/src/engine/service/TransformService.cpp @@ -1,10 +1,10 @@ -#include "TransformService.h" +#include "../../../service/transform/TransformService.h" #include #include #include -#include "../../context/ApplicationContext.h" -#include "../../repository/world/components/TransformComponent.h" +#include "../../ApplicationContext.h" +#include "../dto/TransformComponent.h" namespace Metal { void TransformService::onSync() { diff --git a/src/service/transform/TransformService.h b/src/engine/service/TransformService.h similarity index 83% rename from src/service/transform/TransformService.h rename to src/engine/service/TransformService.h index 37ea9b5a..1d5d88d8 100644 --- a/src/service/transform/TransformService.h +++ b/src/engine/service/TransformService.h @@ -4,8 +4,8 @@ #include #include -#include "../../enum/engine-definitions.h" -#include "../../common/AbstractRuntimeComponent.h" +#include "../../editor/enum/engine-definitions.h" +#include "../../../common/AbstractRuntimeComponent.h" namespace Metal { struct TransformComponent; diff --git a/src/service/volumes/VolumeService.cpp b/src/engine/service/VolumeService.cpp similarity index 81% rename from src/service/volumes/VolumeService.cpp rename to src/engine/service/VolumeService.cpp index 5c03305b..2e19ef20 100644 --- a/src/service/volumes/VolumeService.cpp +++ b/src/engine/service/VolumeService.cpp @@ -1,8 +1,8 @@ -#include "VolumeService.h" -#include "../../context/ApplicationContext.h" -#include "../../repository/world/components/VolumeComponent.h" -#include "../buffer/BufferInstance.h" -#include "../../enum/EngineResourceIDs.h" +#include "../../../service/volumes/VolumeService.h" +#include "../../ApplicationContext.h" +#include "../dto/VolumeComponent.h" +#include "../resource/BufferInstance.h" +#include "../../editor/enum/EngineResourceIDs.h" namespace Metal { void VolumeService::registerVolumes() { diff --git a/src/service/volumes/VolumeService.h b/src/engine/service/VolumeService.h similarity index 81% rename from src/service/volumes/VolumeService.h rename to src/engine/service/VolumeService.h index c2377b45..3df0d4e7 100644 --- a/src/service/volumes/VolumeService.h +++ b/src/engine/service/VolumeService.h @@ -2,8 +2,8 @@ #define VOLUME_SERVICE_H #include -#include "../../common/AbstractRuntimeComponent.h" -#include "../../dto/buffers/VolumeData.h" +#include "../../../common/AbstractRuntimeComponent.h" +#include "../dto/VolumeData.h" namespace Metal { diff --git a/src/service/voxel/VoxelService.cpp b/src/engine/service/VoxelService.cpp similarity index 93% rename from src/service/voxel/VoxelService.cpp rename to src/engine/service/VoxelService.cpp index 8991b5b9..ab70ff5e 100644 --- a/src/service/voxel/VoxelService.cpp +++ b/src/engine/service/VoxelService.cpp @@ -2,9 +2,9 @@ // Created by russi on 2/18/2026. // -#include "VoxelService.h" +#include "../../../service/voxel/VoxelService.h" -#include "SVOInstance.h" +#include "../resource/SVOInstance.h" namespace Metal { diff --git a/src/service/voxel/VoxelService.h b/src/engine/service/VoxelService.h similarity index 82% rename from src/service/voxel/VoxelService.h rename to src/engine/service/VoxelService.h index cd5450dc..e5c6939a 100644 --- a/src/service/voxel/VoxelService.h +++ b/src/engine/service/VoxelService.h @@ -1,8 +1,8 @@ #ifndef METAL_ENGINE_VOXELSERVICE_H #define METAL_ENGINE_VOXELSERVICE_H -#include "../abstract/AbstractResourceService.h" -#include "SVOInstance.h" +#include "../../../common/AbstractResourceService.h" +#include "../resource/SVOInstance.h" namespace Metal { struct SVOInstance; diff --git a/src/util/ImageUtils.h b/src/engine/util/ImageUtils.h similarity index 100% rename from src/util/ImageUtils.h rename to src/engine/util/ImageUtils.h diff --git a/src/util/ShaderUtil.cpp b/src/engine/util/ShaderUtil.cpp similarity index 94% rename from src/util/ShaderUtil.cpp rename to src/engine/util/ShaderUtil.cpp index e75c5148..1924663c 100644 --- a/src/util/ShaderUtil.cpp +++ b/src/engine/util/ShaderUtil.cpp @@ -1,16 +1,15 @@ -#include "ShaderUtil.h" +#include "../../../util/ShaderUtil.h" #include #include -#include "../service/pipeline/ShaderModule.h" -#include "../util/VulkanUtils.h" -#include "../util/Util.h" -#include "../context/ApplicationContext.h" -#include "FilesUtil.h" -#include "../service/log/LogService.h" -#include "../enum/LightType.h" -#include "../enum/ShadingMode.h" +#include "../dto/ShaderModule.h" +#include "../../vulkan/VulkanUtils.h" +#include "../../editor/util/Util.h" +#include "../../ApplicationContext.h" +#include "../../editor/util/FilesUtil.h" +#include "../../editor/service/LogService.h" +#include "../../editor/enum/ShadingMode.h" #include "glslang/Include/glslang_c_interface.h" #include "glslang/Public/resource_limits_c.h" #define BASE_PATH "../resources/shaders/" @@ -170,9 +169,6 @@ namespace Metal { for (auto &entry: ShadingModes::getShaderEntries()) { source = "#define " + entry.first + " " + std::to_string(entry.second) + "\n" + source; } - for (auto &entry: LightTypes::getEntries()) { - source = "#define " + entry.first + " " + std::to_string(entry.second) + "\n" + source; - } source = "#define PI_2 6.28318530718\n" + source; source = "#define PI 3.14159265\n" + source; diff --git a/src/util/ShaderUtil.h b/src/engine/util/ShaderUtil.h similarity index 94% rename from src/util/ShaderUtil.h rename to src/engine/util/ShaderUtil.h index ad777b65..13f07699 100644 --- a/src/util/ShaderUtil.h +++ b/src/engine/util/ShaderUtil.h @@ -4,7 +4,7 @@ #include #include -#include "../service/pipeline/ShaderModule.h" +#include "../dto/ShaderModule.h" namespace Metal { class ShaderUtil final { diff --git a/src/enum/LightType.h b/src/enum/LightType.h deleted file mode 100644 index 4333562b..00000000 --- a/src/enum/LightType.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef LIGHTTYPE_H -#define LIGHTTYPE_H -#include -#include - -namespace Metal::LightTypes{ - enum LightType { - SPHERE, - PLANE - }; - - inline std::unordered_map getEntries() { - std::unordered_map entries; - entries["ITEM_TYPE_SPHERE"] = SPHERE; - entries["ITEM_TYPE_PLANE"] = PLANE; - return entries; - } -} -#endif //LIGHTTYPE_H diff --git a/src/main.cpp b/src/main.cpp index 6ba7dc50..2e02e7af 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5,7 +5,7 @@ #define VMA_IMPLEMENTATION #define GLM_FORCE_RADIANS #define GLM_FORCE_DEPTH_ZERO_TO_ONE -#include "context/ApplicationContext.h" +#include "ApplicationContext.h" int main(int, char **) { Metal::ApplicationContext::Init(true); diff --git a/src/repository/dock/DockPosition.h b/src/repository/dock/DockPosition.h deleted file mode 100644 index b0b3ae35..00000000 --- a/src/repository/dock/DockPosition.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef METAL_ENGINE_DOCKPOSITION_H -#define METAL_ENGINE_DOCKPOSITION_H - -namespace Metal { - enum DockPosition { - TOP, - RIGHT_BOTTOM, - RIGHT_TOP, - LEFT_TOP, - LEFT_BOTTOM, - BOTTOM - }; -} -#endif //METAL_ENGINE_DOCKPOSITION_H From 54411f0923f9c6b164e6543c0438ed40ff65ee33 Mon Sep 17 00:00:00 2001 From: facobackup Date: Thu, 12 Mar 2026 21:48:35 -0300 Subject: [PATCH 09/18] Fixing includes --- CMakeLists.txt | 2 +- src/ApplicationContext.cpp | 6 +++--- src/ApplicationContext.h | 10 +++++----- src/common/AbstractImporter.h | 2 +- src/common/AbstractResourceService.h | 2 +- src/common/Inspectable.cpp | 10 +++++----- src/common/Inspectable.h | 4 ++-- src/common/InspectedField.h | 2 +- src/common/Serializable.cpp | 4 ++-- .../util => common}/serialization-definitions.h | 2 +- src/core/glfw/GLFWContext.cpp | 2 +- src/core/gui/GuiContext.cpp | 6 +++--- src/core/vulkan/VulkanContext.cpp | 2 +- src/core/vulkan/VulkanUtils.cpp | 6 +++--- src/editor/EditorPanel.cpp | 3 +-- src/editor/abstract/IPanel.h | 4 ++-- src/editor/abstract/form/FormPanel.cpp | 4 ++-- src/editor/abstract/form/types/BooleanField.cpp | 2 +- src/editor/abstract/form/types/BooleanField.h | 2 +- src/editor/abstract/form/types/ColorField.cpp | 2 +- src/editor/abstract/form/types/ColorField.h | 2 +- src/editor/abstract/form/types/FloatField.cpp | 2 +- src/editor/abstract/form/types/FloatField.h | 2 +- src/editor/abstract/form/types/IntField.cpp | 2 +- src/editor/abstract/form/types/IntField.h | 2 +- src/editor/abstract/form/types/MethodField.h | 2 +- src/editor/abstract/form/types/QuatField.cpp | 2 +- src/editor/abstract/form/types/QuatField.h | 2 +- src/editor/abstract/form/types/ResourceField.cpp | 6 +++--- src/editor/abstract/form/types/ResourceField.h | 2 +- src/editor/abstract/form/types/ResourceFilesPanel.cpp | 2 +- src/editor/abstract/form/types/StringField.cpp | 2 +- src/editor/abstract/form/types/StringField.h | 2 +- src/editor/abstract/form/types/Vec2Field.cpp | 2 +- src/editor/abstract/form/types/Vec2Field.h | 2 +- src/editor/abstract/form/types/Vec3Field.cpp | 2 +- src/editor/abstract/form/types/Vec3Field.h | 2 +- src/editor/abstract/form/types/Vec4Field.cpp | 2 +- src/editor/abstract/form/types/Vec4Field.h | 2 +- src/editor/dock-spaces/console/ConsolePanel.cpp | 2 +- src/editor/dock-spaces/docks/DockSpacePanel.cpp | 4 ++-- src/editor/dock-spaces/files/FilePreviewPanel.cpp | 2 +- src/editor/dock-spaces/files/FilesHeaderPanel.cpp | 5 ++--- src/editor/dock-spaces/files/FilesListPanel.cpp | 2 +- src/editor/dock-spaces/files/FilesPanel.cpp | 4 ++-- src/editor/dock-spaces/header/AsyncTaskPanel.cpp | 2 +- src/editor/dock-spaces/header/EditorHeaderPanel.cpp | 2 +- src/editor/dock-spaces/inspector/InspectorPanel.cpp | 4 ++-- .../dock-spaces/repositories/RepositoriesPanel.cpp | 4 ++-- .../dock-spaces/viewport/CameraPositionPanel.cpp | 2 +- src/editor/dock-spaces/viewport/EngineFramePanel.cpp | 6 +++--- src/editor/dock-spaces/viewport/GizmoPanel.cpp | 2 +- src/editor/dock-spaces/viewport/GizmoSettingsPanel.cpp | 2 +- .../dock-spaces/viewport/ViewportHeaderPanel.cpp | 2 +- src/editor/dock-spaces/viewport/ViewportPanel.cpp | 5 ++--- src/editor/dock-spaces/world/WorldHeaderPanel.cpp | 2 +- src/editor/dock-spaces/world/WorldPanel.cpp | 4 ++-- src/editor/dto/DockDTO.h | 2 +- src/editor/dto/DockSpace.cpp | 4 ++-- src/editor/dto/EntryMetadata.h | 2 +- src/editor/dto/ImportSettingsDTO.h | 2 +- src/editor/dto/OctreeNode.cpp | 2 +- src/editor/dto/SceneData.h | 2 +- src/editor/dto/SparseVoxelOctreeBuilder.cpp | 2 +- src/editor/enum/NotificationSeverity.h | 2 +- src/editor/enum/ShadingMode.h | 2 +- src/editor/passes/GridPass.cpp | 2 +- src/editor/passes/IconsPass.cpp | 2 +- src/editor/passes/SelectionOutlinePass.cpp | 2 +- src/editor/repository/DockRepository.cpp | 2 +- src/editor/repository/DockRepository.h | 2 +- src/editor/repository/EditorRepository.cpp | 4 ++-- src/editor/repository/EditorRepository.h | 4 ++-- src/editor/service/AsyncTaskService.cpp | 2 +- src/editor/service/AsyncTaskService.h | 1 - src/editor/service/DockService.cpp | 2 +- src/editor/service/DockService.h | 2 +- src/editor/service/FileImporterService.cpp | 2 +- src/editor/service/FileImporterService.h | 2 +- src/editor/service/FilesService.cpp | 4 ++-- src/editor/service/FilesService.h | 2 +- src/editor/service/LogService.cpp | 2 +- src/editor/service/LogService.h | 2 +- src/editor/service/MaterialImporterService.h | 2 +- src/editor/service/MeshImporterService.cpp | 7 +++---- src/editor/service/MeshImporterService.h | 2 +- src/editor/service/PickingService.cpp | 2 +- src/editor/service/PickingService.h | 2 +- src/editor/service/SceneImporterService.cpp | 6 +++--- src/editor/service/SceneImporterService.h | 2 +- src/editor/service/SelectionService.cpp | 2 +- src/editor/service/SelectionService.h | 2 +- src/editor/service/TextureImporterService.cpp | 2 +- src/editor/service/TextureImporterService.h | 2 +- src/editor/service/ThemeService.cpp | 2 +- src/editor/service/ThemeService.h | 2 +- src/editor/service/VoxelImporterService.cpp | 4 ++-- src/editor/service/VoxelImporterService.h | 2 +- src/editor/util/UIUtil.h | 2 +- src/engine/EngineContext.cpp | 3 +-- src/engine/EngineContext.h | 2 +- src/engine/dto/AbstractComponent.h | 2 +- src/engine/dto/BoundingBox.h | 2 +- src/engine/dto/Camera.cpp | 4 ++-- src/engine/dto/Camera.h | 4 ++-- src/engine/dto/DescriptorInstance.h | 2 +- src/engine/dto/MeshData.h | 2 +- src/engine/dto/MetadataComponent.cpp | 4 +--- src/engine/dto/MetadataComponent.h | 4 ++-- src/engine/dto/PipelineBuilder.cpp | 2 +- src/engine/dto/PrimitiveComponent.cpp | 2 +- src/engine/dto/PrimitiveComponent.h | 2 +- src/engine/dto/ShaderModule.cpp | 4 ++-- src/engine/dto/SparseVoxelOctreeData.h | 2 +- src/engine/dto/TransformComponent.cpp | 4 ++-- src/engine/dto/TransformComponent.h | 2 +- src/engine/dto/VertexData.h | 2 +- src/engine/dto/VolumeComponent.cpp | 2 +- src/engine/dto/VolumeComponent.h | 2 +- src/engine/enum/ComponentType.cpp | 2 +- src/engine/enum/ComponentType.h | 1 - src/engine/frame-builder/EngineFrameBuilder.cpp | 1 - src/engine/frame-builder/structures/PassBuilder.cpp | 10 +++++----- src/engine/passes/AbstractComputePass.cpp | 2 +- src/engine/passes/AbstractPass.cpp | 2 +- src/engine/passes/AbstractPass.h | 2 +- src/engine/passes/AbstractRenderPass.cpp | 5 ++--- src/engine/passes/CommandBufferRecorder.cpp | 6 ++---- src/engine/passes/CommandBufferRecorder.h | 2 +- src/engine/passes/impl/HWRayTracingPass.cpp | 3 +-- src/engine/passes/impl/PostProcessingPass.cpp | 4 ++-- src/engine/passes/impl/SpatialFilterPass.cpp | 2 +- src/engine/passes/impl/TemporalAccumulationPass.cpp | 2 +- src/engine/repository/EngineRepository.cpp | 5 ++--- src/engine/repository/EngineRepository.h | 4 ++-- src/engine/repository/WorldRepository.cpp | 4 ++-- src/engine/repository/WorldRepository.h | 4 ++-- src/engine/resource/BufferInstance.cpp | 8 +------- src/engine/resource/FrameBufferAttachment.cpp | 2 +- src/engine/resource/TextureInstance.h | 4 +--- src/engine/service/BufferService.cpp | 4 ++-- src/engine/service/BufferService.h | 2 +- src/engine/service/CameraService.cpp | 2 +- src/engine/service/CameraService.h | 2 +- src/engine/service/CommandBufferRecorderService.h | 2 +- src/engine/service/DescriptorSetService.cpp | 6 +++--- src/engine/service/DescriptorSetService.h | 2 +- src/engine/service/FrameBufferService.cpp | 6 +++--- src/engine/service/FrameBufferService.h | 2 +- src/engine/service/LightService.cpp | 2 +- src/engine/service/LightService.h | 2 +- src/engine/service/MaterialService.cpp | 4 ++-- src/engine/service/MeshService.cpp | 7 ++----- src/engine/service/MeshService.h | 2 +- src/engine/service/PipelineService.cpp | 9 ++++----- src/engine/service/PipelineService.h | 2 +- src/engine/service/RayTracingService.cpp | 6 +++--- src/engine/service/RayTracingService.h | 2 +- src/engine/service/StreamingService.cpp | 2 +- src/engine/service/StreamingService.h | 5 ++--- src/engine/service/TextureService.cpp | 2 +- src/engine/service/TextureService.h | 2 +- src/engine/service/TransformService.cpp | 2 +- src/engine/service/TransformService.h | 2 +- src/engine/service/VolumeService.cpp | 2 +- src/engine/service/VolumeService.h | 2 +- src/engine/service/VoxelService.cpp | 6 +----- src/engine/service/VoxelService.h | 2 +- src/engine/util/ShaderUtil.cpp | 4 ++-- 169 files changed, 234 insertions(+), 266 deletions(-) rename src/{editor/util => common}/serialization-definitions.h (97%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1543f480..391ca93b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -208,7 +208,7 @@ add_executable( src/engine/resource/FrameBufferAttachment.cpp src/engine/repository/EngineRepository.cpp src/engine/repository/EngineRepository.h - src/editor/util/serialization-definitions.h + src/common/serialization-definitions.h src/editor/service/NotificationService.cpp src/editor/service/NotificationService.h src/editor/service/AsyncTaskService.cpp diff --git a/src/ApplicationContext.cpp b/src/ApplicationContext.cpp index fba64246..d47dd628 100644 --- a/src/ApplicationContext.cpp +++ b/src/ApplicationContext.cpp @@ -1,11 +1,11 @@ -#include "context/ApplicationContext.h" +#include "ApplicationContext.h" #include #include #include "editor/util/FilesUtil.h" -#include "vulkan/VulkanUtils.h" -#include "editor/util/serialization-definitions.h" +#include "core/vulkan/VulkanUtils.h" +#include "common/serialization-definitions.h" #include "editor/util/FileDialogUtil.h" #include diff --git a/src/ApplicationContext.h b/src/ApplicationContext.h index 08ace4d5..e1c88cfb 100644 --- a/src/ApplicationContext.h +++ b/src/ApplicationContext.h @@ -4,8 +4,8 @@ #include #include "engine/EngineContext.h" -#include "glfw/GLFWContext.h" -#include "vulkan/VulkanContext.h" +#include "core/glfw/GLFWContext.h" +#include "core/vulkan/VulkanContext.h" #include "engine/service/MeshService.h" #include "engine/service/TextureService.h" @@ -32,18 +32,18 @@ #include "editor/repository/EditorRepository.h" #include "engine/service/MaterialService.h" #include "engine/service/CommandBufferRecorderService.h" -#include "../service/notification/NotificationService.h" +#include "editor/service/NotificationService.h" #include "editor/service/AsyncTaskService.h" #include "editor/service/LogService.h" #include "engine/service/TransformService.h" #include "editor/service/PickingService.h" #include "engine/service/VolumeService.h" #include "editor/service/VoxelImporterService.h" -#include "../service/voxel/VoxelService.h" +#include "engine/service/VoxelService.h" #include "engine/service/LightService.h" #include "engine/service/RayTracingService.h" #include "editor/EditorPanel.h" -#include "gui/GuiContext.h" +#include "core/gui/GuiContext.h" #define CTX Metal::ApplicationContext::Get() diff --git a/src/common/AbstractImporter.h b/src/common/AbstractImporter.h index 24e05029..3507b6b9 100644 --- a/src/common/AbstractImporter.h +++ b/src/common/AbstractImporter.h @@ -4,7 +4,7 @@ #include #include -#include "../context/editor/dto/ImportSettingsDTO.h" +#include "../editor/dto/ImportSettingsDTO.h" #include "AbstractRuntimeComponent.h" namespace Metal { diff --git a/src/common/AbstractResourceService.h b/src/common/AbstractResourceService.h index c94287d4..25ad1072 100644 --- a/src/common/AbstractResourceService.h +++ b/src/common/AbstractResourceService.h @@ -5,7 +5,7 @@ #include #include "AbstractRuntimeComponent.h" -#include "../context/engine/resource/RuntimeResource.h" +#include "../engine/resource/RuntimeResource.h" namespace Metal { class VulkanContext; diff --git a/src/common/Inspectable.cpp b/src/common/Inspectable.cpp index a0c0b207..e2b4a1ee 100644 --- a/src/common/Inspectable.cpp +++ b/src/common/Inspectable.cpp @@ -1,14 +1,14 @@ -#include "inspection/Inspectable.h" +#include "Inspectable.h" #include #include #include #include -#include "inspection/InspectedField.h" -#include "inspection/InspectedMethod.h" -#include "../context/editor/util/Util.h" -#include "../context/editor/enum/EntryType.h" +#include "InspectedField.h" +#include "InspectedMethod.h" +#include "../editor/util/Util.h" +#include "../editor/enum/EntryType.h" #define DECLARATION(T, V) \ std::shared_ptr> field = std::make_shared>(&v);\ diff --git a/src/common/Inspectable.h b/src/common/Inspectable.h index 1c3df071..3c300946 100644 --- a/src/common/Inspectable.h +++ b/src/common/Inspectable.h @@ -7,8 +7,8 @@ #include #include "InspectableMember.h" -#include "../context/editor/util/Util.h" -#include "../context/editor/enum/EntryType.h" +#include "../editor/util/Util.h" +#include "../editor/enum/EntryType.h" #include "Changeable.h" namespace Metal { diff --git a/src/common/InspectedField.h b/src/common/InspectedField.h index 08b2b22e..fdcd9155 100644 --- a/src/common/InspectedField.h +++ b/src/common/InspectedField.h @@ -4,7 +4,7 @@ #include #include "InspectableMember.h" -#include "../context/editor/enum/EntryType.h" +#include "../editor/enum/EntryType.h" namespace Metal { template diff --git a/src/common/Serializable.cpp b/src/common/Serializable.cpp index 98d46573..c9a08f3d 100644 --- a/src/common/Serializable.cpp +++ b/src/common/Serializable.cpp @@ -1,9 +1,9 @@ -#include "../util/Serializable.h" +#include "Serializable.h" #include "../ApplicationContext.h" #include #include #include -#include "../context/editor/service/LogService.h" +#include "../editor/service/LogService.h" namespace Metal { void Serializable::saveToJson(const std::string &path) const { diff --git a/src/editor/util/serialization-definitions.h b/src/common/serialization-definitions.h similarity index 97% rename from src/editor/util/serialization-definitions.h rename to src/common/serialization-definitions.h index ceef1d81..eab3426b 100644 --- a/src/editor/util/serialization-definitions.h +++ b/src/common/serialization-definitions.h @@ -3,7 +3,7 @@ #include #include -#include "../../../common/Serializable.h" +#include "Serializable.h" #include #include #include diff --git a/src/core/glfw/GLFWContext.cpp b/src/core/glfw/GLFWContext.cpp index 333ad510..8014aea8 100644 --- a/src/core/glfw/GLFWContext.cpp +++ b/src/core/glfw/GLFWContext.cpp @@ -1,6 +1,6 @@ #include #include "GLFWContext.h" -#include "../ApplicationContext.h" +#include "../../ApplicationContext.h" #include "../vulkan/VulkanUtils.h" namespace Metal { diff --git a/src/core/gui/GuiContext.cpp b/src/core/gui/GuiContext.cpp index c6ccbb2c..6874f866 100644 --- a/src/core/gui/GuiContext.cpp +++ b/src/core/gui/GuiContext.cpp @@ -2,10 +2,10 @@ #include #include "imgui_freetype.h" -#include "../ApplicationContext.h" +#include "../../ApplicationContext.h" #include "../vulkan/VulkanUtils.h" -#include "../engine/dto/DescriptorInstance.h" -#include "../engine/resource/TextureInstance.h" +#include "../../engine/dto/DescriptorInstance.h" +#include "../../engine/resource/TextureInstance.h" namespace Metal { void GuiContext::endFrame() { diff --git a/src/core/vulkan/VulkanContext.cpp b/src/core/vulkan/VulkanContext.cpp index 0e5415b2..040e475d 100644 --- a/src/core/vulkan/VulkanContext.cpp +++ b/src/core/vulkan/VulkanContext.cpp @@ -2,7 +2,7 @@ #include "VkBootstrap.h" #include "VulkanUtils.h" -#include "../ApplicationContext.h" +#include "../../ApplicationContext.h" namespace Metal { VulkanContext::VulkanContext(bool debugMode) : AbstractRuntimeComponent(), diff --git a/src/core/vulkan/VulkanUtils.cpp b/src/core/vulkan/VulkanUtils.cpp index 182dab58..9a133c92 100644 --- a/src/core/vulkan/VulkanUtils.cpp +++ b/src/core/vulkan/VulkanUtils.cpp @@ -1,8 +1,8 @@ -#include "../../util/VulkanUtils.h" +#include "VulkanUtils.h" #include "../../../dependencies/vk-bootstrap/src/VkBootstrap.h" -#include "../ApplicationContext.h" -#include "../editor/service/LogService.h" +#include "../../ApplicationContext.h" +#include "../../editor/service/LogService.h" namespace Metal { void VulkanUtils::CheckVKResult(VkResult err) { diff --git a/src/editor/EditorPanel.cpp b/src/editor/EditorPanel.cpp index 2e70ba27..0f07986a 100644 --- a/src/editor/EditorPanel.cpp +++ b/src/editor/EditorPanel.cpp @@ -1,7 +1,6 @@ #include "EditorPanel.h" #include "util/UIUtil.h" -#include "../../context/ApplicationContext.h" -#include "dto/Notification.h" +#include "../ApplicationContext.h" #include "dock-spaces/header/EditorHeaderPanel.h" #include "panel/FileImportModalPanel.h" #include "panel/NotificationsPanel.h" diff --git a/src/editor/abstract/IPanel.h b/src/editor/abstract/IPanel.h index 8eba6fb6..126139fe 100644 --- a/src/editor/abstract/IPanel.h +++ b/src/editor/abstract/IPanel.h @@ -1,8 +1,8 @@ #ifndef METAL_ENGINE_IPANEL_H #define METAL_ENGINE_IPANEL_H -#include "../../../common/Synchornizable.h" -#include "../../../common/Initializable.h" +#include "../../common/Synchornizable.h" +#include "../../common/Initializable.h" namespace Metal { class IPanel : public Syncronizable, public Initializable { diff --git a/src/editor/abstract/form/FormPanel.cpp b/src/editor/abstract/form/FormPanel.cpp index 13aeb015..5c683c15 100644 --- a/src/editor/abstract/form/FormPanel.cpp +++ b/src/editor/abstract/form/FormPanel.cpp @@ -1,8 +1,8 @@ #include "FormPanel.h" #include "AccordionPanel.h" #include "ChildPanel.h" -#include "../../../../common/FieldType.h" -#include "../../../../common/Inspectable.h" +#include "../../../common/FieldType.h" +#include "../../../common/Inspectable.h" #include "types/IntField.h" #include "types/FloatField.h" #include "types/BooleanField.h" diff --git a/src/editor/abstract/form/types/BooleanField.cpp b/src/editor/abstract/form/types/BooleanField.cpp index 4f145c79..11963c65 100644 --- a/src/editor/abstract/form/types/BooleanField.cpp +++ b/src/editor/abstract/form/types/BooleanField.cpp @@ -2,7 +2,7 @@ #include #include -#include "../../../../../common/Inspectable.h" +#include "../../../../common/Inspectable.h" namespace Metal { BooleanField::BooleanField(InspectedField &field) : field(field) { diff --git a/src/editor/abstract/form/types/BooleanField.h b/src/editor/abstract/form/types/BooleanField.h index 97c485d8..b7e683f9 100644 --- a/src/editor/abstract/form/types/BooleanField.h +++ b/src/editor/abstract/form/types/BooleanField.h @@ -2,7 +2,7 @@ #define METAL_ENGINE_BOOLEANFIELD_H #include "../AbstractFormFieldPanel.h" -#include "../../../../../common/InspectedField.h" +#include "../../../../common/InspectedField.h" namespace Metal { class BooleanField final : public AbstractFormFieldPanel { diff --git a/src/editor/abstract/form/types/ColorField.cpp b/src/editor/abstract/form/types/ColorField.cpp index 985efafc..b63c5967 100644 --- a/src/editor/abstract/form/types/ColorField.cpp +++ b/src/editor/abstract/form/types/ColorField.cpp @@ -1,7 +1,7 @@ #include "ColorField.h" #include #include -#include "../../../../../common/Inspectable.h" +#include "../../../../common/Inspectable.h" namespace Metal { ColorField::ColorField(InspectedField &field) : field(field) { diff --git a/src/editor/abstract/form/types/ColorField.h b/src/editor/abstract/form/types/ColorField.h index 07ea8eef..5d4af9b2 100644 --- a/src/editor/abstract/form/types/ColorField.h +++ b/src/editor/abstract/form/types/ColorField.h @@ -3,7 +3,7 @@ #include #include "../AbstractFormFieldPanel.h" -#include "../../../../../common/InspectedField.h" +#include "../../../../common/InspectedField.h" namespace Metal { class ColorField final : public AbstractFormFieldPanel { diff --git a/src/editor/abstract/form/types/FloatField.cpp b/src/editor/abstract/form/types/FloatField.cpp index 47252dc9..c888e6d8 100644 --- a/src/editor/abstract/form/types/FloatField.cpp +++ b/src/editor/abstract/form/types/FloatField.cpp @@ -1,7 +1,7 @@ #include "FloatField.h" #include #include -#include "../../../../../common/Inspectable.h" +#include "../../../../common/Inspectable.h" namespace Metal { void FloatField::onSync() { diff --git a/src/editor/abstract/form/types/FloatField.h b/src/editor/abstract/form/types/FloatField.h index 509bfafa..80443303 100644 --- a/src/editor/abstract/form/types/FloatField.h +++ b/src/editor/abstract/form/types/FloatField.h @@ -2,7 +2,7 @@ #define METAL_ENGINE_FLOATFIELD_H #include "../AbstractFormFieldPanel.h" -#include "../../../../../common/InspectedField.h" +#include "../../../../common/InspectedField.h" namespace Metal { diff --git a/src/editor/abstract/form/types/IntField.cpp b/src/editor/abstract/form/types/IntField.cpp index 7f2fc001..a8af0903 100644 --- a/src/editor/abstract/form/types/IntField.cpp +++ b/src/editor/abstract/form/types/IntField.cpp @@ -1,7 +1,7 @@ #include "IntField.h" #include #include -#include "../../../../../common/Inspectable.h" +#include "../../../../common/Inspectable.h" namespace Metal { void IntField::onSync() { diff --git a/src/editor/abstract/form/types/IntField.h b/src/editor/abstract/form/types/IntField.h index 6d8a2c68..ffae0f01 100644 --- a/src/editor/abstract/form/types/IntField.h +++ b/src/editor/abstract/form/types/IntField.h @@ -2,7 +2,7 @@ #define METAL_ENGINE_INTFIELD_H #include "../AbstractFormFieldPanel.h" -#include "../../../../../common/InspectedField.h" +#include "../../../../common/InspectedField.h" namespace Metal { class IntField final : public AbstractFormFieldPanel { diff --git a/src/editor/abstract/form/types/MethodField.h b/src/editor/abstract/form/types/MethodField.h index 145c8c6f..9ef1e055 100644 --- a/src/editor/abstract/form/types/MethodField.h +++ b/src/editor/abstract/form/types/MethodField.h @@ -3,7 +3,7 @@ #define METAL_ENGINE_METHODFIELD_H #include "../AbstractFormFieldPanel.h" -#include "../../../../../common/InspectedMethod.h" +#include "../../../../common/InspectedMethod.h" namespace Metal { diff --git a/src/editor/abstract/form/types/QuatField.cpp b/src/editor/abstract/form/types/QuatField.cpp index 512648bb..880f0f82 100644 --- a/src/editor/abstract/form/types/QuatField.cpp +++ b/src/editor/abstract/form/types/QuatField.cpp @@ -2,7 +2,7 @@ #include #include #include -#include "../../../../../common/Inspectable.h" +#include "../../../../common/Inspectable.h" #include "../../../util/UIUtil.h" namespace Metal { diff --git a/src/editor/abstract/form/types/QuatField.h b/src/editor/abstract/form/types/QuatField.h index ed6cd528..833cf1cd 100644 --- a/src/editor/abstract/form/types/QuatField.h +++ b/src/editor/abstract/form/types/QuatField.h @@ -2,7 +2,7 @@ #define QUATFIELD_H #include #include "../AbstractFormFieldPanel.h" -#include "../../../../../common/InspectedField.h" +#include "../../../../common/InspectedField.h" namespace Metal { class QuatField final : public AbstractFormFieldPanel { diff --git a/src/editor/abstract/form/types/ResourceField.cpp b/src/editor/abstract/form/types/ResourceField.cpp index 3c4fac3b..668ec209 100644 --- a/src/editor/abstract/form/types/ResourceField.cpp +++ b/src/editor/abstract/form/types/ResourceField.cpp @@ -4,11 +4,11 @@ #include #include "ResourceFilesPanel.h" -#include "../../../../../common/Icons.h" +#include "../../../../common/Icons.h" #include "../../../util/UIUtil.h" #include "../../../dto/FSEntry.h" -#include "../../../../../context/ApplicationContext.h" -#include "../../../../../common/inspection/Inspectable.h" +#include "../../../../ApplicationContext.h" +#include "../../../../common/Inspectable.h" namespace Metal { constexpr ImGuiWindowFlags flags = ImGuiWindowFlags_NoDocking | diff --git a/src/editor/abstract/form/types/ResourceField.h b/src/editor/abstract/form/types/ResourceField.h index 308976da..8126a42e 100644 --- a/src/editor/abstract/form/types/ResourceField.h +++ b/src/editor/abstract/form/types/ResourceField.h @@ -4,7 +4,7 @@ #include #include "../AbstractFormFieldPanel.h" -#include "../../../../../common/InspectedField.h" +#include "../../../../common/InspectedField.h" #include "imgui.h" namespace Metal { diff --git a/src/editor/abstract/form/types/ResourceFilesPanel.cpp b/src/editor/abstract/form/types/ResourceFilesPanel.cpp index 7cf50247..cf3e6196 100644 --- a/src/editor/abstract/form/types/ResourceFilesPanel.cpp +++ b/src/editor/abstract/form/types/ResourceFilesPanel.cpp @@ -1,6 +1,6 @@ #include "ResourceFilesPanel.h" -#include "../../../../../common/Icons.h" +#include "../../../../common/Icons.h" #include "../../../dto/FSEntry.h" #include "../../../service/FilesService.h" diff --git a/src/editor/abstract/form/types/StringField.cpp b/src/editor/abstract/form/types/StringField.cpp index 2b6ec53d..9f07b8b2 100644 --- a/src/editor/abstract/form/types/StringField.cpp +++ b/src/editor/abstract/form/types/StringField.cpp @@ -1,7 +1,7 @@ #include "StringField.h" #include #include -#include "../../../../../common/Inspectable.h" +#include "../../../../common/Inspectable.h" namespace Metal { StringField::StringField(InspectedField &field) : field(field) { diff --git a/src/editor/abstract/form/types/StringField.h b/src/editor/abstract/form/types/StringField.h index 3e543281..f712b6c5 100644 --- a/src/editor/abstract/form/types/StringField.h +++ b/src/editor/abstract/form/types/StringField.h @@ -2,7 +2,7 @@ #define STRINGFIELD_H #include "../AbstractFormFieldPanel.h" -#include "../../../../../common/InspectedField.h" +#include "../../../../common/InspectedField.h" namespace Metal { diff --git a/src/editor/abstract/form/types/Vec2Field.cpp b/src/editor/abstract/form/types/Vec2Field.cpp index d1d32756..99a88f7f 100644 --- a/src/editor/abstract/form/types/Vec2Field.cpp +++ b/src/editor/abstract/form/types/Vec2Field.cpp @@ -1,7 +1,7 @@ #include "Vec2Field.h" #include #include -#include "../../../../../common/Inspectable.h" +#include "../../../../common/Inspectable.h" #include "../../../util/UIUtil.h" namespace Metal { diff --git a/src/editor/abstract/form/types/Vec2Field.h b/src/editor/abstract/form/types/Vec2Field.h index cbc6212e..fe8d944c 100644 --- a/src/editor/abstract/form/types/Vec2Field.h +++ b/src/editor/abstract/form/types/Vec2Field.h @@ -4,7 +4,7 @@ #include #include "../AbstractFormFieldPanel.h" -#include "../../../../../common/InspectedField.h" +#include "../../../../common/InspectedField.h" namespace Metal { class Vec2Field final : public AbstractFormFieldPanel { diff --git a/src/editor/abstract/form/types/Vec3Field.cpp b/src/editor/abstract/form/types/Vec3Field.cpp index 471f2410..de0ea9b6 100644 --- a/src/editor/abstract/form/types/Vec3Field.cpp +++ b/src/editor/abstract/form/types/Vec3Field.cpp @@ -1,7 +1,7 @@ #include "Vec3Field.h" #include #include -#include "../../../../../common/Inspectable.h" +#include "../../../../common/Inspectable.h" #include "../../../util/UIUtil.h" namespace Metal { diff --git a/src/editor/abstract/form/types/Vec3Field.h b/src/editor/abstract/form/types/Vec3Field.h index dbd36eab..d005b64d 100644 --- a/src/editor/abstract/form/types/Vec3Field.h +++ b/src/editor/abstract/form/types/Vec3Field.h @@ -4,7 +4,7 @@ #include #include "../AbstractFormFieldPanel.h" -#include "../../../../../common/InspectedField.h" +#include "../../../../common/InspectedField.h" namespace Metal { diff --git a/src/editor/abstract/form/types/Vec4Field.cpp b/src/editor/abstract/form/types/Vec4Field.cpp index 8e5932f7..e39247fc 100644 --- a/src/editor/abstract/form/types/Vec4Field.cpp +++ b/src/editor/abstract/form/types/Vec4Field.cpp @@ -1,7 +1,7 @@ #include "Vec4Field.h" #include #include -#include "../../../../../common/Inspectable.h" +#include "../../../../common/Inspectable.h" #include "../../../util/UIUtil.h" namespace Metal { diff --git a/src/editor/abstract/form/types/Vec4Field.h b/src/editor/abstract/form/types/Vec4Field.h index 569fde21..0ce2cae9 100644 --- a/src/editor/abstract/form/types/Vec4Field.h +++ b/src/editor/abstract/form/types/Vec4Field.h @@ -3,7 +3,7 @@ #include #include "../AbstractFormFieldPanel.h" -#include "../../../../../common/InspectedField.h" +#include "../../../../common/InspectedField.h" namespace Metal { class Vec4Field final : public AbstractFormFieldPanel { diff --git a/src/editor/dock-spaces/console/ConsolePanel.cpp b/src/editor/dock-spaces/console/ConsolePanel.cpp index 4b2e40fe..67e17115 100644 --- a/src/editor/dock-spaces/console/ConsolePanel.cpp +++ b/src/editor/dock-spaces/console/ConsolePanel.cpp @@ -2,7 +2,7 @@ #include "imgui.h" #include "../../../ApplicationContext.h" -#include "../../../../common/Icons.h" +#include "../../../common/Icons.h" namespace Metal { ConsolePanel::ConsolePanel() { diff --git a/src/editor/dock-spaces/docks/DockSpacePanel.cpp b/src/editor/dock-spaces/docks/DockSpacePanel.cpp index 6a938445..16098bbc 100644 --- a/src/editor/dock-spaces/docks/DockSpacePanel.cpp +++ b/src/editor/dock-spaces/docks/DockSpacePanel.cpp @@ -4,8 +4,8 @@ #include #include "AbstractDockPanel.h" -#include "../../../../context/ApplicationContext.h" -#include "../../../../common/Icons.h" +#include "../../../ApplicationContext.h" +#include "../../../common/Icons.h" #include "../../dto/DockDTO.h" #include "../../util/UIUtil.h" #include "../../service/LogService.h" diff --git a/src/editor/dock-spaces/files/FilePreviewPanel.cpp b/src/editor/dock-spaces/files/FilePreviewPanel.cpp index 18365979..87a6ca4a 100644 --- a/src/editor/dock-spaces/files/FilePreviewPanel.cpp +++ b/src/editor/dock-spaces/files/FilePreviewPanel.cpp @@ -2,7 +2,7 @@ #include #include "../../util/UIUtil.h" #include "../../dto/FSEntry.h" -#include "../../../../context/ApplicationContext.h" +#include "../../../ApplicationContext.h" #include "../../../engine/resource/TextureInstance.h" namespace Metal { diff --git a/src/editor/dock-spaces/files/FilesHeaderPanel.cpp b/src/editor/dock-spaces/files/FilesHeaderPanel.cpp index 8a0f737b..7b317138 100644 --- a/src/editor/dock-spaces/files/FilesHeaderPanel.cpp +++ b/src/editor/dock-spaces/files/FilesHeaderPanel.cpp @@ -2,9 +2,8 @@ #include "../../enum/EntryType.h" #include "../../dto/FSEntry.h" -#include "../../../../common/Icons.h" -#include "../../util/FilesUtil.h" -#include "../../../../context/ApplicationContext.h" +#include "../../../common/Icons.h" +#include "../../../ApplicationContext.h" #include "../../util/UIUtil.h" namespace Metal { diff --git a/src/editor/dock-spaces/files/FilesListPanel.cpp b/src/editor/dock-spaces/files/FilesListPanel.cpp index 62bb60c0..05b2fa59 100644 --- a/src/editor/dock-spaces/files/FilesListPanel.cpp +++ b/src/editor/dock-spaces/files/FilesListPanel.cpp @@ -3,7 +3,7 @@ #include "FilesPanel.h" #include "FilesContext.h" #include "../../util/UIUtil.h" -#include "../../../../context/ApplicationContext.h" +#include "../../../ApplicationContext.h" #include "../../dto/FSEntry.h" #include "../../service/FilesService.h" #include diff --git a/src/editor/dock-spaces/files/FilesPanel.cpp b/src/editor/dock-spaces/files/FilesPanel.cpp index ab444e51..c09b0515 100644 --- a/src/editor/dock-spaces/files/FilesPanel.cpp +++ b/src/editor/dock-spaces/files/FilesPanel.cpp @@ -3,8 +3,8 @@ #include "FilesHeaderPanel.h" #include "FilesListPanel.h" -#include "../../../../common/Icons.h" -#include "../../../../context/ApplicationContext.h" +#include "../../../common/Icons.h" +#include "../../../ApplicationContext.h" #include "../../dto/SceneData.h" #include "../../util/UIUtil.h" #include "../../dto/FSEntry.h" diff --git a/src/editor/dock-spaces/header/AsyncTaskPanel.cpp b/src/editor/dock-spaces/header/AsyncTaskPanel.cpp index ba3626bc..2cc626c5 100644 --- a/src/editor/dock-spaces/header/AsyncTaskPanel.cpp +++ b/src/editor/dock-spaces/header/AsyncTaskPanel.cpp @@ -1,5 +1,5 @@ #include "AsyncTaskPanel.h" -#include "../../../../context/ApplicationContext.h" +#include "../../../ApplicationContext.h" #include "../../util/UIUtil.h" #include diff --git a/src/editor/dock-spaces/header/EditorHeaderPanel.cpp b/src/editor/dock-spaces/header/EditorHeaderPanel.cpp index 719902c8..b2b577a5 100644 --- a/src/editor/dock-spaces/header/EditorHeaderPanel.cpp +++ b/src/editor/dock-spaces/header/EditorHeaderPanel.cpp @@ -1,7 +1,7 @@ #include "EditorHeaderPanel.h" #include "AsyncTaskPanel.h" #include "../../util/UIUtil.h" -#include "../../../../context/ApplicationContext.h" +#include "../../../ApplicationContext.h" namespace Metal { void EditorHeaderPanel::onSync() { diff --git a/src/editor/dock-spaces/inspector/InspectorPanel.cpp b/src/editor/dock-spaces/inspector/InspectorPanel.cpp index bd827a58..a3c02608 100644 --- a/src/editor/dock-spaces/inspector/InspectorPanel.cpp +++ b/src/editor/dock-spaces/inspector/InspectorPanel.cpp @@ -2,8 +2,8 @@ #include "../../abstract/form/FormPanel.h" #include "../../util/UIUtil.h" -#include "../../../../common/Inspectable.h" -#include "../../../../context/ApplicationContext.h" +#include "../../../common/Inspectable.h" +#include "../../../ApplicationContext.h" #include "../../../engine/dto/MetadataComponent.h" #include #include diff --git a/src/editor/dock-spaces/repositories/RepositoriesPanel.cpp b/src/editor/dock-spaces/repositories/RepositoriesPanel.cpp index 20ba7d80..70957667 100644 --- a/src/editor/dock-spaces/repositories/RepositoriesPanel.cpp +++ b/src/editor/dock-spaces/repositories/RepositoriesPanel.cpp @@ -1,7 +1,7 @@ #include "RepositoriesPanel.h" #include "../../abstract/form/FormPanel.h" -#include "../../../../context/ApplicationContext.h" -#include "../../../../common/Inspectable.h" +#include "../../../ApplicationContext.h" +#include "../../../common/Inspectable.h" namespace Metal { void RepositoriesPanel::onInitialize() { diff --git a/src/editor/dock-spaces/viewport/CameraPositionPanel.cpp b/src/editor/dock-spaces/viewport/CameraPositionPanel.cpp index 7ae495d5..425d60cd 100644 --- a/src/editor/dock-spaces/viewport/CameraPositionPanel.cpp +++ b/src/editor/dock-spaces/viewport/CameraPositionPanel.cpp @@ -1,6 +1,6 @@ #include "CameraPositionPanel.h" -#include "../../../../context/ApplicationContext.h" +#include "../../../ApplicationContext.h" #include "../../util/UIUtil.h" #include "../../../engine/dto/Camera.h" diff --git a/src/editor/dock-spaces/viewport/EngineFramePanel.cpp b/src/editor/dock-spaces/viewport/EngineFramePanel.cpp index 5bcd3602..5ba17e43 100644 --- a/src/editor/dock-spaces/viewport/EngineFramePanel.cpp +++ b/src/editor/dock-spaces/viewport/EngineFramePanel.cpp @@ -1,7 +1,7 @@ #include "EngineFramePanel.h" -#include "../../../../context/ApplicationContext.h" -#include "../../../../context/engine/frame-builder/EngineFrameBuilder.h" -#include "../../../../context/engine/frame-builder/EngineFrame.h" +#include "../../../ApplicationContext.h" +#include "../../../engine/frame-builder/EngineFrameBuilder.h" +#include "../../../engine/frame-builder/EngineFrame.h" #include "../../../engine/dto/DescriptorInstance.h" #include "../../../engine/resource/FrameBufferInstance.h" #include "../../service/PickingService.h" diff --git a/src/editor/dock-spaces/viewport/GizmoPanel.cpp b/src/editor/dock-spaces/viewport/GizmoPanel.cpp index 00106002..501340c3 100644 --- a/src/editor/dock-spaces/viewport/GizmoPanel.cpp +++ b/src/editor/dock-spaces/viewport/GizmoPanel.cpp @@ -1,6 +1,6 @@ #include "GizmoPanel.h" -#include "../../../../context/ApplicationContext.h" +#include "../../../ApplicationContext.h" #include "../../../engine/dto/TransformComponent.h" #include "../../../engine/dto/Camera.h" #include "ImGuizmo.h" diff --git a/src/editor/dock-spaces/viewport/GizmoSettingsPanel.cpp b/src/editor/dock-spaces/viewport/GizmoSettingsPanel.cpp index e8cc266b..75632216 100644 --- a/src/editor/dock-spaces/viewport/GizmoSettingsPanel.cpp +++ b/src/editor/dock-spaces/viewport/GizmoSettingsPanel.cpp @@ -1,6 +1,6 @@ #include "GizmoSettingsPanel.h" #include "../../util/UIUtil.h" -#include "../../../../context/ApplicationContext.h" +#include "../../../ApplicationContext.h" #include "ImGuizmo.h" namespace Metal { diff --git a/src/editor/dock-spaces/viewport/ViewportHeaderPanel.cpp b/src/editor/dock-spaces/viewport/ViewportHeaderPanel.cpp index 9345dea2..d4dbbafe 100644 --- a/src/editor/dock-spaces/viewport/ViewportHeaderPanel.cpp +++ b/src/editor/dock-spaces/viewport/ViewportHeaderPanel.cpp @@ -1,7 +1,7 @@ #include "ViewportHeaderPanel.h" #include "GizmoSettingsPanel.h" -#include "../../../../context/ApplicationContext.h" +#include "../../../ApplicationContext.h" #include "../../util/UIUtil.h" namespace Metal { diff --git a/src/editor/dock-spaces/viewport/ViewportPanel.cpp b/src/editor/dock-spaces/viewport/ViewportPanel.cpp index e4e051a2..d923b9ae 100644 --- a/src/editor/dock-spaces/viewport/ViewportPanel.cpp +++ b/src/editor/dock-spaces/viewport/ViewportPanel.cpp @@ -5,10 +5,9 @@ #include "ImGuizmo.h" #include "ViewportHeaderPanel.h" #include "EngineFramePanel.h" -#include "../../../../context/ApplicationContext.h" +#include "../../../ApplicationContext.h" #include "../../../engine/dto/Camera.h" -#include "../../../../context/engine/frame-builder/EngineFrameBuilder.h" -#include "../../enum/engine-definitions.h" +#include "../../../engine/frame-builder/EngineFrameBuilder.h" #include namespace Metal { diff --git a/src/editor/dock-spaces/world/WorldHeaderPanel.cpp b/src/editor/dock-spaces/world/WorldHeaderPanel.cpp index 13306c06..8aea7de6 100644 --- a/src/editor/dock-spaces/world/WorldHeaderPanel.cpp +++ b/src/editor/dock-spaces/world/WorldHeaderPanel.cpp @@ -1,6 +1,6 @@ #include "WorldHeaderPanel.h" -#include "../../../../context/ApplicationContext.h" +#include "../../../ApplicationContext.h" #include "../../util/UIUtil.h" #include "../../../engine/enum/ComponentType.h" diff --git a/src/editor/dock-spaces/world/WorldPanel.cpp b/src/editor/dock-spaces/world/WorldPanel.cpp index 33a1c993..c7cd1842 100644 --- a/src/editor/dock-spaces/world/WorldPanel.cpp +++ b/src/editor/dock-spaces/world/WorldPanel.cpp @@ -1,9 +1,9 @@ #include "WorldPanel.h" #include "WorldHeaderPanel.h" -#include "../../../../common/Icons.h" +#include "../../../common/Icons.h" #include "../../util/UIUtil.h" -#include "../../../../context/ApplicationContext.h" +#include "../../../ApplicationContext.h" #include "../../../engine/dto/MetadataComponent.h" #include "../../../engine/enum/ComponentType.h" diff --git a/src/editor/dto/DockDTO.h b/src/editor/dto/DockDTO.h index b80af738..1d3b84f3 100644 --- a/src/editor/dto/DockDTO.h +++ b/src/editor/dto/DockDTO.h @@ -4,7 +4,7 @@ #include #include #include -#include "../../../repository/dock/DockSpace.h" +#include "DockSpace.h" #include "../util/Util.h" namespace Metal { diff --git a/src/editor/dto/DockSpace.cpp b/src/editor/dto/DockSpace.cpp index 810fc661..186a612a 100644 --- a/src/editor/dto/DockSpace.cpp +++ b/src/editor/dto/DockSpace.cpp @@ -1,5 +1,5 @@ -#include "../../../repository/dock/DockSpace.h" -#include "../../../common/Icons.h" +#include "DockSpace.h" +#include "../../common/Icons.h" #include "../dock-spaces/console/ConsolePanel.h" #include "../dock-spaces/files/FilesPanel.h" #include "../dock-spaces/metrics/MetricsPanel.h" diff --git a/src/editor/dto/EntryMetadata.h b/src/editor/dto/EntryMetadata.h index 4ab792f6..bfb9a00c 100644 --- a/src/editor/dto/EntryMetadata.h +++ b/src/editor/dto/EntryMetadata.h @@ -4,7 +4,7 @@ #include #include "../util/Util.h" #include "../enum/EntryType.h" -#include "../../../common/Serializable.h" +#include "../../common//Serializable.h" namespace Metal { struct EntryMetadata : Serializable { diff --git a/src/editor/dto/ImportSettingsDTO.h b/src/editor/dto/ImportSettingsDTO.h index e6d48c90..061b3a4f 100644 --- a/src/editor/dto/ImportSettingsDTO.h +++ b/src/editor/dto/ImportSettingsDTO.h @@ -1,7 +1,7 @@ #ifndef IMPORTSETTINGSDTO_H #define IMPORTSETTINGSDTO_H -#include "../../../common/Inspectable.h" +#include "../../common//Inspectable.h" namespace Metal { diff --git a/src/editor/dto/OctreeNode.cpp b/src/editor/dto/OctreeNode.cpp index dce3c2ed..e57248ac 100644 --- a/src/editor/dto/OctreeNode.cpp +++ b/src/editor/dto/OctreeNode.cpp @@ -1,4 +1,4 @@ -#include "../../../service/voxel/impl/OctreeNode.h" +#include "OctreeNode.h" namespace Metal { void OctreeNode::addChild(OctreeNode *child, int index) { diff --git a/src/editor/dto/SceneData.h b/src/editor/dto/SceneData.h index 6e52f84b..ef40380e 100644 --- a/src/editor/dto/SceneData.h +++ b/src/editor/dto/SceneData.h @@ -3,7 +3,7 @@ #include #include "SceneEntityData.h" -#include "../../../common/Serializable.h" +#include "../../common//Serializable.h" namespace Metal { diff --git a/src/editor/dto/SparseVoxelOctreeBuilder.cpp b/src/editor/dto/SparseVoxelOctreeBuilder.cpp index 8a6c70f4..4bfb325f 100644 --- a/src/editor/dto/SparseVoxelOctreeBuilder.cpp +++ b/src/editor/dto/SparseVoxelOctreeBuilder.cpp @@ -1,4 +1,4 @@ -#include "../../../service/voxel/impl/SparseVoxelOctreeBuilder.h" +#include "SparseVoxelOctreeBuilder.h" namespace Metal { void SparseVoxelOctreeBuilder::insert(int maxDepth, glm::vec3 point, VoxelData data) { diff --git a/src/editor/enum/NotificationSeverity.h b/src/editor/enum/NotificationSeverity.h index 9c0b303b..e15d107e 100644 --- a/src/editor/enum/NotificationSeverity.h +++ b/src/editor/enum/NotificationSeverity.h @@ -2,7 +2,7 @@ #define NOTIFICATIONSEVERITY_H #include -#include "../../../common/Icons.h" +#include "../../common/Icons.h" namespace Metal::NotificationSeverities { enum NotificationSeverity { diff --git a/src/editor/enum/ShadingMode.h b/src/editor/enum/ShadingMode.h index f3108cf1..3a949993 100644 --- a/src/editor/enum/ShadingMode.h +++ b/src/editor/enum/ShadingMode.h @@ -4,7 +4,7 @@ #include #include -#include "../../../common/Icons.h" +#include "../../common/Icons.h" namespace Metal { enum ShadingMode { diff --git a/src/editor/passes/GridPass.cpp b/src/editor/passes/GridPass.cpp index 65cd233f..365aaef8 100644 --- a/src/editor/passes/GridPass.cpp +++ b/src/editor/passes/GridPass.cpp @@ -1,4 +1,4 @@ -#include "../../engine/passes/impl/tools/GridPass.h" +#include "GridPass.h" #include "../../ApplicationContext.h" #include "../../engine/dto/PipelineBuilder.h" diff --git a/src/editor/passes/IconsPass.cpp b/src/editor/passes/IconsPass.cpp index 62ff2a18..73e0126b 100644 --- a/src/editor/passes/IconsPass.cpp +++ b/src/editor/passes/IconsPass.cpp @@ -1,4 +1,4 @@ -#include "../../engine/passes/impl/tools/IconsPass.h" +#include "IconsPass.h" #include "../../ApplicationContext.h" #include "../../engine/dto/PipelineBuilder.h" diff --git a/src/editor/passes/SelectionOutlinePass.cpp b/src/editor/passes/SelectionOutlinePass.cpp index 8be2221e..d3e542ca 100644 --- a/src/editor/passes/SelectionOutlinePass.cpp +++ b/src/editor/passes/SelectionOutlinePass.cpp @@ -1,4 +1,4 @@ -#include "../../engine/passes/impl/tools/SelectionOutlinePass.h" +#include "SelectionOutlinePass.h" #include "../../ApplicationContext.h" #include "../../engine/dto/TransformComponent.h" diff --git a/src/editor/repository/DockRepository.cpp b/src/editor/repository/DockRepository.cpp index 507c17f8..560f31d7 100644 --- a/src/editor/repository/DockRepository.cpp +++ b/src/editor/repository/DockRepository.cpp @@ -1,4 +1,4 @@ -#include "../../../repository/dock/DockRepository.h" +#include "DockRepository.h" namespace Metal { DockRepository::DockRepository() : AbstractRuntimeComponent() { diff --git a/src/editor/repository/DockRepository.h b/src/editor/repository/DockRepository.h index ab0648b5..9fe872bd 100644 --- a/src/editor/repository/DockRepository.h +++ b/src/editor/repository/DockRepository.h @@ -3,7 +3,7 @@ #include #include "../dto/DockDTO.h" -#include "../../../common/AbstractRuntimeComponent.h" +#include "../../common/AbstractRuntimeComponent.h" namespace Metal { struct DockRepository final : AbstractRuntimeComponent { diff --git a/src/editor/repository/EditorRepository.cpp b/src/editor/repository/EditorRepository.cpp index 108cb4e1..b4cb5b1b 100644 --- a/src/editor/repository/EditorRepository.cpp +++ b/src/editor/repository/EditorRepository.cpp @@ -1,5 +1,5 @@ -#include "../../../repository/editor/EditorRepository.h" -#include "../../../common/Icons.h" +#include "EditorRepository.h" +#include "../../common/Icons.h" namespace Metal { const char *EditorRepository::getTitle() { diff --git a/src/editor/repository/EditorRepository.h b/src/editor/repository/EditorRepository.h index 89d513d2..ea30d277 100644 --- a/src/editor/repository/EditorRepository.h +++ b/src/editor/repository/EditorRepository.h @@ -9,8 +9,8 @@ #include "../dto/ShortcutDTO.h" #include "../enum/engine-definitions.h" #include "../enum/ShadingMode.h" -#include "../../../common/Inspectable.h" -#include "../../../common/Serializable.h" +#include "../../common/Inspectable.h" +#include "../../common/Serializable.h" namespace Metal { struct TransformComponent; diff --git a/src/editor/service/AsyncTaskService.cpp b/src/editor/service/AsyncTaskService.cpp index 24833c25..d2200a0d 100644 --- a/src/editor/service/AsyncTaskService.cpp +++ b/src/editor/service/AsyncTaskService.cpp @@ -1,4 +1,4 @@ -#include "../../../service/notification/AsyncTaskService.h" +#include "AsyncTaskService.h" #include #include #include "../util/Util.h" diff --git a/src/editor/service/AsyncTaskService.h b/src/editor/service/AsyncTaskService.h index 41846f93..71a16e40 100644 --- a/src/editor/service/AsyncTaskService.h +++ b/src/editor/service/AsyncTaskService.h @@ -4,7 +4,6 @@ #include #include #include -#include #include #include "../dto/AsyncTask.h" diff --git a/src/editor/service/DockService.cpp b/src/editor/service/DockService.cpp index 27eb553d..5bbffb0a 100644 --- a/src/editor/service/DockService.cpp +++ b/src/editor/service/DockService.cpp @@ -1,6 +1,6 @@ #include #include -#include "../../../service/dock/DockService.h" +#include "DockService.h" #include "../dto/DockDTO.h" #include "../abstract/AbstractPanel.h" #include "../dock-spaces/docks/AbstractDockPanel.h" diff --git a/src/editor/service/DockService.h b/src/editor/service/DockService.h index f2e96c28..6d00ee6e 100644 --- a/src/editor/service/DockService.h +++ b/src/editor/service/DockService.h @@ -4,7 +4,7 @@ #include "imgui.h" #include "../dto/DockDTO.h" #include "../dock-spaces/docks/DockSpacePanel.h" -#include "../../../common/AbstractRuntimeComponent.h" +#include "../../common/AbstractRuntimeComponent.h" namespace Metal { class AbstractPanel; diff --git a/src/editor/service/FileImporterService.cpp b/src/editor/service/FileImporterService.cpp index 666b5f25..09e8f104 100644 --- a/src/editor/service/FileImporterService.cpp +++ b/src/editor/service/FileImporterService.cpp @@ -1,4 +1,4 @@ -#include "../../../service/files/FileImporterService.h" +#include "FileImporterService.h" #include "../../ApplicationContext.h" #include "LogService.h" diff --git a/src/editor/service/FileImporterService.h b/src/editor/service/FileImporterService.h index 231a3fbc..ee69dcb4 100644 --- a/src/editor/service/FileImporterService.h +++ b/src/editor/service/FileImporterService.h @@ -6,7 +6,7 @@ #include #include "../dto/ImportSettingsDTO.h" -#include "../../../common/AbstractRuntimeComponent.h" +#include "../../common/AbstractRuntimeComponent.h" namespace Metal { class FileImporterService final : public AbstractRuntimeComponent { diff --git a/src/editor/service/FilesService.cpp b/src/editor/service/FilesService.cpp index 48f6dc06..fd0bf822 100644 --- a/src/editor/service/FilesService.cpp +++ b/src/editor/service/FilesService.cpp @@ -1,4 +1,4 @@ -#include "../../../service/files/FilesService.h" +#include "FilesService.h" #include "../dto/FSEntry.h" #include "../enum/EntryType.h" #include "../enum/engine-definitions.h" @@ -10,7 +10,7 @@ #include #include #include -#include "../util/serialization-definitions.h" +#include "../../common/serialization-definitions.h" namespace fs = std::filesystem; diff --git a/src/editor/service/FilesService.h b/src/editor/service/FilesService.h index 299b1b8d..c2906941 100644 --- a/src/editor/service/FilesService.h +++ b/src/editor/service/FilesService.h @@ -4,7 +4,7 @@ #include #include -#include "../../../common/AbstractRuntimeComponent.h" +#include "../../common/AbstractRuntimeComponent.h" namespace Metal { struct FSEntry; diff --git a/src/editor/service/LogService.cpp b/src/editor/service/LogService.cpp index 4225a03b..28cf54e1 100644 --- a/src/editor/service/LogService.cpp +++ b/src/editor/service/LogService.cpp @@ -1,4 +1,4 @@ -#include "../../../service/log/LogService.h" +#include "LogService.h" #include #include #include diff --git a/src/editor/service/LogService.h b/src/editor/service/LogService.h index 22e0487a..94254087 100644 --- a/src/editor/service/LogService.h +++ b/src/editor/service/LogService.h @@ -4,7 +4,7 @@ #include #include #include -#include "../../../common/AbstractRuntimeComponent.h" +#include "../../common/AbstractRuntimeComponent.h" namespace Metal { diff --git a/src/editor/service/MaterialImporterService.h b/src/editor/service/MaterialImporterService.h index 6f731505..5eb416e5 100644 --- a/src/editor/service/MaterialImporterService.h +++ b/src/editor/service/MaterialImporterService.h @@ -6,7 +6,7 @@ #include #include -#include "../../../common/AbstractResourceService.h" +#include "../../common/AbstractResourceService.h" namespace Metal { struct PrimitiveComponent; diff --git a/src/editor/service/MeshImporterService.cpp b/src/editor/service/MeshImporterService.cpp index 9943ad53..4dabe766 100644 --- a/src/editor/service/MeshImporterService.cpp +++ b/src/editor/service/MeshImporterService.cpp @@ -1,13 +1,12 @@ -#include "../../../service/mesh/MeshImporterService.h" +#include "MeshImporterService.h" #include "../../engine/dto/MeshData.h" -#include "../../context/editor/dto/VertexData.h" +#include "../../engine/dto/VertexData.h" #include "../dto/EntryMetadata.h" #include "../enum/engine-definitions.h" #include "../util/FilesUtil.h" #include "../../ApplicationContext.h" #include -#include -#include "../../../util/serialization-definitions.h" +#include "../../common/serialization-definitions.h" namespace Metal { std::string MeshImporterService::persistMesh(const std::string &targetDir, const MeshData &mesh) const { diff --git a/src/editor/service/MeshImporterService.h b/src/editor/service/MeshImporterService.h index 250ea5ac..5d522770 100644 --- a/src/editor/service/MeshImporterService.h +++ b/src/editor/service/MeshImporterService.h @@ -1,7 +1,7 @@ #ifndef MESHIMPORTERSERVICE_H #define MESHIMPORTERSERVICE_H -#include "../../../common/AbstractResourceService.h" +#include "../../common/AbstractResourceService.h" #include #include #include diff --git a/src/editor/service/PickingService.cpp b/src/editor/service/PickingService.cpp index e1ee990e..45c76e19 100644 --- a/src/editor/service/PickingService.cpp +++ b/src/editor/service/PickingService.cpp @@ -1,4 +1,4 @@ -#include "../../../service/picking/PickingService.h" +#include "PickingService.h" #include "../../engine/resource/BufferInstance.h" #include "../../engine/resource/TextureInstance.h" diff --git a/src/editor/service/PickingService.h b/src/editor/service/PickingService.h index 923248e9..36ff15c0 100644 --- a/src/editor/service/PickingService.h +++ b/src/editor/service/PickingService.h @@ -1,7 +1,7 @@ #ifndef PICKINGSERVICE_H #define PICKINGSERVICE_H -#include "../../../common/AbstractResourceService.h" +#include "../../common/AbstractResourceService.h" #include "../enum/engine-definitions.h" #include diff --git a/src/editor/service/SceneImporterService.cpp b/src/editor/service/SceneImporterService.cpp index 7196a0cc..d63b859c 100644 --- a/src/editor/service/SceneImporterService.cpp +++ b/src/editor/service/SceneImporterService.cpp @@ -1,6 +1,6 @@ -#include "../../../service/mesh/SceneImporterService.h" +#include "SceneImporterService.h" -#include "../../../dto/file/FSEntry.h" +#include "../dto/FSEntry.h" #include "../../engine/dto/MeshData.h" #include "../dto/SceneData.h" #include "MaterialImporterService.h" @@ -12,7 +12,7 @@ #include "../dto/EntryMetadata.h" #include "../enum/engine-definitions.h" #include "../../ApplicationContext.h" -#include "../util/serialization-definitions.h" +#include "../../common/serialization-definitions.h" #include "../dto/SceneImportSettingsDTO.h" namespace Metal { diff --git a/src/editor/service/SceneImporterService.h b/src/editor/service/SceneImporterService.h index 29787d7b..6cec5ce0 100644 --- a/src/editor/service/SceneImporterService.h +++ b/src/editor/service/SceneImporterService.h @@ -3,7 +3,7 @@ #include -#include "../../../common/AbstractImporter.h" +#include "../../common/AbstractImporter.h" #include #include diff --git a/src/editor/service/SelectionService.cpp b/src/editor/service/SelectionService.cpp index d2ac6738..245a54ed 100644 --- a/src/editor/service/SelectionService.cpp +++ b/src/editor/service/SelectionService.cpp @@ -1,4 +1,4 @@ -#include "../../../service/selection/SelectionService.h" +#include "SelectionService.h" #include "../../ApplicationContext.h" #include "../../engine/dto/TransformComponent.h" diff --git a/src/editor/service/SelectionService.h b/src/editor/service/SelectionService.h index 1a878d56..f86db212 100644 --- a/src/editor/service/SelectionService.h +++ b/src/editor/service/SelectionService.h @@ -2,7 +2,7 @@ #define SELECTIONSERVICE_H #include -#include "../../../common/AbstractRuntimeComponent.h" +#include "../../common/AbstractRuntimeComponent.h" #include "../enum/engine-definitions.h" namespace Metal { diff --git a/src/editor/service/TextureImporterService.cpp b/src/editor/service/TextureImporterService.cpp index 43723b5d..61697ff1 100644 --- a/src/editor/service/TextureImporterService.cpp +++ b/src/editor/service/TextureImporterService.cpp @@ -4,7 +4,7 @@ #include "../../../../dependencies/stb/stb_image_write.h" #include #include -#include "../util/serialization-definitions.h" +#include "../../common/serialization-definitions.h" #include "../dto/EntryMetadata.h" #include "../enum/EntryType.h" diff --git a/src/editor/service/TextureImporterService.h b/src/editor/service/TextureImporterService.h index 244617ed..7357eeac 100644 --- a/src/editor/service/TextureImporterService.h +++ b/src/editor/service/TextureImporterService.h @@ -1,6 +1,6 @@ #ifndef TEXTUREIMPORTER_H #define TEXTUREIMPORTER_H -#include "../../../common/AbstractImporter.h" +#include "../../common/AbstractImporter.h" struct aiTexture; diff --git a/src/editor/service/ThemeService.cpp b/src/editor/service/ThemeService.cpp index 8e439ab7..4eee2551 100644 --- a/src/editor/service/ThemeService.cpp +++ b/src/editor/service/ThemeService.cpp @@ -1,4 +1,4 @@ -#include "../../../service/theme/ThemeService.h" +#include "ThemeService.h" #include "../../ApplicationContext.h" diff --git a/src/editor/service/ThemeService.h b/src/editor/service/ThemeService.h index b8775037..e9d5f603 100644 --- a/src/editor/service/ThemeService.h +++ b/src/editor/service/ThemeService.h @@ -2,7 +2,7 @@ #define THEMESERVICE_H #include #include -#include "../../../common/AbstractRuntimeComponent.h" +#include "../../common/AbstractRuntimeComponent.h" namespace Metal { diff --git a/src/editor/service/VoxelImporterService.cpp b/src/editor/service/VoxelImporterService.cpp index 86142ef3..101fa675 100644 --- a/src/editor/service/VoxelImporterService.cpp +++ b/src/editor/service/VoxelImporterService.cpp @@ -1,7 +1,7 @@ -#include "../../../service/voxel/VoxelImporterService.h" +#include "VoxelImporterService.h" #include -#include "../util/serialization-definitions.h" +#include "../../common/serialization-definitions.h" #include "../../ApplicationContext.h" #include "../dto/EntryMetadata.h" diff --git a/src/editor/service/VoxelImporterService.h b/src/editor/service/VoxelImporterService.h index 2e1dc578..4cee1f71 100644 --- a/src/editor/service/VoxelImporterService.h +++ b/src/editor/service/VoxelImporterService.h @@ -1,7 +1,7 @@ #ifndef METAL_ENGINE_VOLUMEIMPORTERSERVICE_H #define METAL_ENGINE_VOLUMEIMPORTERSERVICE_H -#include "../../../common/AbstractImporter.h" +#include "../../common/AbstractImporter.h" #include "../dto/SparseVoxelOctreeBuilder.h" #include "../../engine/dto/SparseVoxelOctreeData.h" diff --git a/src/editor/util/UIUtil.h b/src/editor/util/UIUtil.h index 666482bc..dc10a0a2 100644 --- a/src/editor/util/UIUtil.h +++ b/src/editor/util/UIUtil.h @@ -5,7 +5,7 @@ #include #include "../enum/EntryType.h" -#include "../../../common/Icons.h" +#include "../../common/Icons.h" namespace Metal::UIUtil { static constexpr ImVec4 DIRECTORY_COLOR{188 / 255.f, 128 / 255.f, 78 / 255.f, 1}; diff --git a/src/engine/EngineContext.cpp b/src/engine/EngineContext.cpp index ec840921..744ca3ab 100644 --- a/src/engine/EngineContext.cpp +++ b/src/engine/EngineContext.cpp @@ -1,9 +1,8 @@ #include "EngineContext.h" #include "../editor/enum/EngineResourceIDs.h" -#include "../../context/ApplicationContext.h" +#include "../ApplicationContext.h" #include "resource/BufferInstance.h" -#include "dto/Camera.h" #include "dto/TransformComponent.h" namespace Metal { diff --git a/src/engine/EngineContext.h b/src/engine/EngineContext.h index ad04b00c..6c07088d 100644 --- a/src/engine/EngineContext.h +++ b/src/engine/EngineContext.h @@ -6,7 +6,7 @@ #include #include "dto/GlobalDataUBO.h" -#include "../../common/AbstractRuntimeComponent.h" +#include "../common/AbstractRuntimeComponent.h" #include "dto/TileInfoUBO.h" using Clock = std::chrono::high_resolution_clock; diff --git a/src/engine/dto/AbstractComponent.h b/src/engine/dto/AbstractComponent.h index a9fcfd67..5f8db038 100644 --- a/src/engine/dto/AbstractComponent.h +++ b/src/engine/dto/AbstractComponent.h @@ -1,6 +1,6 @@ #ifndef ABSTRACTCOMPONENT_H #define ABSTRACTCOMPONENT_H -#include "../../../common/Inspectable.h" +#include "../../common/Inspectable.h" #include "../enum/ComponentType.h" namespace Metal { diff --git a/src/engine/dto/BoundingBox.h b/src/engine/dto/BoundingBox.h index 0d15dc8b..ec6de8bb 100644 --- a/src/engine/dto/BoundingBox.h +++ b/src/engine/dto/BoundingBox.h @@ -1,7 +1,7 @@ #ifndef BOUNDINGBOX_H #define BOUNDINGBOX_H #include -#include "../../../common/Serializable.h" +#include "../../common/Serializable.h" namespace Metal { struct BoundingBox final : Serializable { diff --git a/src/engine/dto/Camera.cpp b/src/engine/dto/Camera.cpp index b7112275..91260a28 100644 --- a/src/engine/dto/Camera.cpp +++ b/src/engine/dto/Camera.cpp @@ -1,6 +1,6 @@ -#include "../../../service/camera/Camera.h" +#include "Camera.h" -#include "../../../common/Icons.h" +#include "../../common/Icons.h" namespace Metal { void Camera::extractFrustumPlanes(glm::mat4x4 m) { diff --git a/src/engine/dto/Camera.h b/src/engine/dto/Camera.h index b6b0bf7c..70928a1c 100644 --- a/src/engine/dto/Camera.h +++ b/src/engine/dto/Camera.h @@ -6,8 +6,8 @@ #include #include -#include "../../../common/Inspectable.h" -#include "../../../common/Serializable.h" +#include "../../common/Inspectable.h" +#include "../../common/Serializable.h" namespace Metal { diff --git a/src/engine/dto/DescriptorInstance.h b/src/engine/dto/DescriptorInstance.h index ce0fc262..c924f7e5 100644 --- a/src/engine/dto/DescriptorInstance.h +++ b/src/engine/dto/DescriptorInstance.h @@ -3,7 +3,7 @@ #include #include "../resource/RuntimeResource.h" -#include "../../../service/descriptor/DescriptorBinding.h" +#include "DescriptorBinding.h" namespace Metal { struct BufferInstance; diff --git a/src/engine/dto/MeshData.h b/src/engine/dto/MeshData.h index 43811394..2a24bd4c 100644 --- a/src/engine/dto/MeshData.h +++ b/src/engine/dto/MeshData.h @@ -3,7 +3,7 @@ #include #include #include "VertexData.h" -#include "../../editor/util/serialization-definitions.h" +#include "../../common/serialization-definitions.h" namespace Metal { struct MeshData final { diff --git a/src/engine/dto/MetadataComponent.cpp b/src/engine/dto/MetadataComponent.cpp index 14ea7662..7726da77 100644 --- a/src/engine/dto/MetadataComponent.cpp +++ b/src/engine/dto/MetadataComponent.cpp @@ -1,6 +1,4 @@ -#include "../../../repository/world/impl/MetadataComponent.h" -#include "../../../common/Icons.h" -#include "../../editor/util/UIUtil.h" +#include "MetadataComponent.h" namespace Metal { void MetadataComponent::registerFields() { diff --git a/src/engine/dto/MetadataComponent.h b/src/engine/dto/MetadataComponent.h index 0cf4276d..59928072 100644 --- a/src/engine/dto/MetadataComponent.h +++ b/src/engine/dto/MetadataComponent.h @@ -6,8 +6,8 @@ #include "AbstractComponent.h" #include "../../editor/enum/engine-definitions.h" #include "../enum/ComponentType.h" -#include "../../../common/Inspectable.h" -#include "../../../common/Serializable.h" +#include "../../common/Inspectable.h" +#include "../../common/Serializable.h" namespace Metal { struct MetadataComponent final : AbstractComponent, Serializable { diff --git a/src/engine/dto/PipelineBuilder.cpp b/src/engine/dto/PipelineBuilder.cpp index 98ab72d5..5bd8a621 100644 --- a/src/engine/dto/PipelineBuilder.cpp +++ b/src/engine/dto/PipelineBuilder.cpp @@ -1,4 +1,4 @@ -#include "../../../service/pipeline/PipelineBuilder.h" +#include "PipelineBuilder.h" #include "../resource/TextureInstance.h" namespace Metal { diff --git a/src/engine/dto/PrimitiveComponent.cpp b/src/engine/dto/PrimitiveComponent.cpp index 35964482..7018d702 100644 --- a/src/engine/dto/PrimitiveComponent.cpp +++ b/src/engine/dto/PrimitiveComponent.cpp @@ -1,4 +1,4 @@ -#include "../../../repository/world/components/PrimitiveComponent.h" +#include "PrimitiveComponent.h" #include "../../ApplicationContext.h" #include "../../editor/enum/EntryType.h" #include "MeshData.h" diff --git a/src/engine/dto/PrimitiveComponent.h b/src/engine/dto/PrimitiveComponent.h index d49c8afc..5b112d5c 100644 --- a/src/engine/dto/PrimitiveComponent.h +++ b/src/engine/dto/PrimitiveComponent.h @@ -2,7 +2,7 @@ #define PRIMITIVE_COMPONENT_H #include "AbstractComponent.h" -#include "../../../common/Serializable.h" +#include "../../common/Serializable.h" #include namespace Metal { diff --git a/src/engine/dto/ShaderModule.cpp b/src/engine/dto/ShaderModule.cpp index a11e2fb8..2149f95a 100644 --- a/src/engine/dto/ShaderModule.cpp +++ b/src/engine/dto/ShaderModule.cpp @@ -1,6 +1,6 @@ -#include "../../../service/pipeline/ShaderModule.h" +#include "ShaderModule.h" -#include "../../vulkan/VulkanContext.h" +#include "../../core/vulkan/VulkanContext.h" namespace Metal { void ShaderModule::initialize(glslang_program_t *program) { diff --git a/src/engine/dto/SparseVoxelOctreeData.h b/src/engine/dto/SparseVoxelOctreeData.h index 87987780..0c4f3be5 100644 --- a/src/engine/dto/SparseVoxelOctreeData.h +++ b/src/engine/dto/SparseVoxelOctreeData.h @@ -4,7 +4,7 @@ #include #include -#include "../../../common/Serializable.h" +#include "../../common/Serializable.h" namespace Metal { struct SparseVoxelOctreeData final : Serializable { diff --git a/src/engine/dto/TransformComponent.cpp b/src/engine/dto/TransformComponent.cpp index da3e63b1..a929c214 100644 --- a/src/engine/dto/TransformComponent.cpp +++ b/src/engine/dto/TransformComponent.cpp @@ -1,5 +1,5 @@ -#include "../../../repository/world/components/TransformComponent.h" -#include "../../../repository/world/components/VolumeComponent.h" +#include "TransformComponent.h" +#include "VolumeComponent.h" #include "../../ApplicationContext.h" #define ROTATION "Rotation" diff --git a/src/engine/dto/TransformComponent.h b/src/engine/dto/TransformComponent.h index 1857e1eb..78974590 100644 --- a/src/engine/dto/TransformComponent.h +++ b/src/engine/dto/TransformComponent.h @@ -6,7 +6,7 @@ #include #include "AbstractComponent.h" -#include "../../../common/Serializable.h" +#include "../../common/Serializable.h" namespace Metal { diff --git a/src/engine/dto/VertexData.h b/src/engine/dto/VertexData.h index 677c9fc2..b9468cfb 100644 --- a/src/engine/dto/VertexData.h +++ b/src/engine/dto/VertexData.h @@ -4,7 +4,7 @@ #include #include -#include "../../editor/util/serialization-definitions.h" +#include "../../common/serialization-definitions.h" namespace Metal { struct VertexData final { diff --git a/src/engine/dto/VolumeComponent.cpp b/src/engine/dto/VolumeComponent.cpp index 0d9455cc..56829e59 100644 --- a/src/engine/dto/VolumeComponent.cpp +++ b/src/engine/dto/VolumeComponent.cpp @@ -1,4 +1,4 @@ -#include "../../../repository/world/components/VolumeComponent.h" +#include "VolumeComponent.h" #include "../../ApplicationContext.h" namespace Metal { diff --git a/src/engine/dto/VolumeComponent.h b/src/engine/dto/VolumeComponent.h index 57a77cf2..c886278b 100644 --- a/src/engine/dto/VolumeComponent.h +++ b/src/engine/dto/VolumeComponent.h @@ -2,7 +2,7 @@ #define VOLUMECOMPONENT_H #include "AbstractComponent.h" -#include "../../../common/Serializable.h" +#include "../../common/Serializable.h" #include namespace Metal { diff --git a/src/engine/enum/ComponentType.cpp b/src/engine/enum/ComponentType.cpp index 8ffb8a23..74fa1e67 100644 --- a/src/engine/enum/ComponentType.cpp +++ b/src/engine/enum/ComponentType.cpp @@ -1,4 +1,4 @@ -#include "../../../enum/ComponentType.h" +#include "ComponentType.h" #include "../repository/WorldRepository.h" #include "../../ApplicationContext.h" diff --git a/src/engine/enum/ComponentType.h b/src/engine/enum/ComponentType.h index 90bddb09..5cfc8fad 100644 --- a/src/engine/enum/ComponentType.h +++ b/src/engine/enum/ComponentType.h @@ -5,7 +5,6 @@ #include #include #include -#include "../../../common/Icons.h" namespace Metal { class Inspectable; diff --git a/src/engine/frame-builder/EngineFrameBuilder.cpp b/src/engine/frame-builder/EngineFrameBuilder.cpp index 9b870737..82804505 100644 --- a/src/engine/frame-builder/EngineFrameBuilder.cpp +++ b/src/engine/frame-builder/EngineFrameBuilder.cpp @@ -8,7 +8,6 @@ #include "EngineFrame.h" #include "../../ApplicationContext.h" #include "../passes/CommandBufferRecorder.h" -#include "../render-pass/impl/tools/SelectionOutlinePass.h" namespace Metal { EngineFrameBuilder::EngineFrameBuilder(std::string frameId) : frameId(std::move(frameId)) { diff --git a/src/engine/frame-builder/structures/PassBuilder.cpp b/src/engine/frame-builder/structures/PassBuilder.cpp index ee326176..8d9d8278 100644 --- a/src/engine/frame-builder/structures/PassBuilder.cpp +++ b/src/engine/frame-builder/structures/PassBuilder.cpp @@ -1,12 +1,12 @@ #include "PassBuilder.h" -#include "../../render-pass/impl/PostProcessingPass.h" +#include "../../passes/impl/PostProcessingPass.h" #include "../../passes/impl/HWRayTracingPass.h" #include "../../passes/impl/TemporalAccumulationPass.h" #include "../../passes/impl/SpatialFilterPass.h" -#include "../../render-pass/impl/tools/SelectionOutlinePass.h" -#include "../../render-pass/impl/tools/GridPass.h" -#include "../../render-pass/impl/tools/IconsPass.h" -#include "../../render-pass/impl/tools/SelectionIDPass.h" +#include "../../../editor/passes/SelectionOutlinePass.h" +#include "../../../editor/passes/GridPass.h" +#include "../../../editor/passes/IconsPass.h" +#include "../../../editor/passes/SelectionIDPass.h" namespace Metal { RuntimeResource* PassBuilder::build() { diff --git a/src/engine/passes/AbstractComputePass.cpp b/src/engine/passes/AbstractComputePass.cpp index b847add8..cd34e278 100644 --- a/src/engine/passes/AbstractComputePass.cpp +++ b/src/engine/passes/AbstractComputePass.cpp @@ -1,4 +1,4 @@ -#include "../compute-pass/AbstractComputePass.h" +#include "AbstractComputePass.h" #include "../../ApplicationContext.h" #include "../resource/PipelineInstance.h" #include "../resource/TextureInstance.h" diff --git a/src/engine/passes/AbstractPass.cpp b/src/engine/passes/AbstractPass.cpp index 2000f968..a0dbd400 100644 --- a/src/engine/passes/AbstractPass.cpp +++ b/src/engine/passes/AbstractPass.cpp @@ -1,6 +1,6 @@ #include "AbstractPass.h" #include "../frame-builder/EngineFrame.h" -#include "../../../context/ApplicationContext.h" +#include "../../ApplicationContext.h" #include "../resource/PipelineInstance.h" namespace Metal { diff --git a/src/engine/passes/AbstractPass.h b/src/engine/passes/AbstractPass.h index f95e11fd..d5fffc8f 100644 --- a/src/engine/passes/AbstractPass.h +++ b/src/engine/passes/AbstractPass.h @@ -3,7 +3,7 @@ #include #include #include -#include "../../../common/AbstractRuntimeComponent.h" +#include "../../common/AbstractRuntimeComponent.h" #include "../resource/RuntimeResource.h" namespace Metal { diff --git a/src/engine/passes/AbstractRenderPass.cpp b/src/engine/passes/AbstractRenderPass.cpp index 16cd6eb6..c8b1084f 100644 --- a/src/engine/passes/AbstractRenderPass.cpp +++ b/src/engine/passes/AbstractRenderPass.cpp @@ -1,6 +1,5 @@ -#include "render-pass/AbstractRenderPass.h" -#include "../../../context/ApplicationContext.h" -#include "../resource/PipelineInstance.h" +#include "AbstractRenderPass.h" +#include "../../ApplicationContext.h" #include "../resource/MeshInstance.h" #include "../resource/BufferInstance.h" diff --git a/src/engine/passes/CommandBufferRecorder.cpp b/src/engine/passes/CommandBufferRecorder.cpp index f7019f61..785eb2f6 100644 --- a/src/engine/passes/CommandBufferRecorder.cpp +++ b/src/engine/passes/CommandBufferRecorder.cpp @@ -1,14 +1,12 @@ #include "CommandBufferRecorder.h" #include -#include -#include "../dto/DescriptorInstance.h" #include "../resource/FrameBufferInstance.h" #include "../resource/PipelineInstance.h" #include "../../ApplicationContext.h" -#include "../render-pass/AbstractRenderPass.h" -#include "../../vulkan/VulkanUtils.h" +#include "AbstractRenderPass.h" +#include "../../core/vulkan/VulkanUtils.h" namespace Metal { void CommandBufferRecorder::createCommandBuffer() { diff --git a/src/engine/passes/CommandBufferRecorder.h b/src/engine/passes/CommandBufferRecorder.h index 7897160d..f7b367c9 100644 --- a/src/engine/passes/CommandBufferRecorder.h +++ b/src/engine/passes/CommandBufferRecorder.h @@ -4,7 +4,7 @@ #include #include #include "../resource/PipelineInstance.h" -#include "../../vulkan/VulkanUtils.h" +#include "../../core/vulkan/VulkanUtils.h" namespace Metal { class AbstractPass; diff --git a/src/engine/passes/impl/HWRayTracingPass.cpp b/src/engine/passes/impl/HWRayTracingPass.cpp index 5a9dbeca..cc537f3e 100644 --- a/src/engine/passes/impl/HWRayTracingPass.cpp +++ b/src/engine/passes/impl/HWRayTracingPass.cpp @@ -1,6 +1,5 @@ -#include "../../compute-pass/impl/HWRayTracingPass.h" +#include "HWRayTracingPass.h" #include "../../../ApplicationContext.h" -#include "../../resource/FrameBufferInstance.h" #include "../../dto/PipelineBuilder.h" #include "../../resource/PipelineInstance.h" #include "../../resource/TextureInstance.h" diff --git a/src/engine/passes/impl/PostProcessingPass.cpp b/src/engine/passes/impl/PostProcessingPass.cpp index 543fe4aa..67aab25f 100644 --- a/src/engine/passes/impl/PostProcessingPass.cpp +++ b/src/engine/passes/impl/PostProcessingPass.cpp @@ -1,6 +1,6 @@ -#include "../render-pass/impl/PostProcessingPass.h" +#include "PostProcessingPass.h" -#include "../../../../context/ApplicationContext.h" +#include "../../../ApplicationContext.h" #include "../../dto/PipelineBuilder.h" #include "../../../editor/enum/EngineResourceIDs.h" diff --git a/src/engine/passes/impl/SpatialFilterPass.cpp b/src/engine/passes/impl/SpatialFilterPass.cpp index 3a3aa6ff..291d7b5f 100644 --- a/src/engine/passes/impl/SpatialFilterPass.cpp +++ b/src/engine/passes/impl/SpatialFilterPass.cpp @@ -1,4 +1,4 @@ -#include "../../compute-pass/impl/SpatialFilterPass.h" +#include "SpatialFilterPass.h" #include "../../../ApplicationContext.h" #include "../../dto/PipelineBuilder.h" #include "../../resource/TextureInstance.h" diff --git a/src/engine/passes/impl/TemporalAccumulationPass.cpp b/src/engine/passes/impl/TemporalAccumulationPass.cpp index d7108241..e1d1029d 100644 --- a/src/engine/passes/impl/TemporalAccumulationPass.cpp +++ b/src/engine/passes/impl/TemporalAccumulationPass.cpp @@ -1,4 +1,4 @@ -#include "../../compute-pass/impl/TemporalAccumulationPass.h" +#include "TemporalAccumulationPass.h" #include "../../../ApplicationContext.h" #include "../../dto/PipelineBuilder.h" #include "../../resource/TextureInstance.h" diff --git a/src/engine/repository/EngineRepository.cpp b/src/engine/repository/EngineRepository.cpp index f5ac4024..30489fef 100644 --- a/src/engine/repository/EngineRepository.cpp +++ b/src/engine/repository/EngineRepository.cpp @@ -1,9 +1,8 @@ -#include "../../../repository/engine/EngineRepository.h" +#include "EngineRepository.h" -#include "../../../common/Icons.h" +#include "../../common/Icons.h" #include "../../ApplicationContext.h" -#define LEVEL_OF_DETAIL "Level of detail" #define PATH_TRACER "Path tracer" #define ATMOSPHERE "Atmosphere" #define SUN "Sun" diff --git a/src/engine/repository/EngineRepository.h b/src/engine/repository/EngineRepository.h index 0870e1b0..fe2b81dc 100644 --- a/src/engine/repository/EngineRepository.h +++ b/src/engine/repository/EngineRepository.h @@ -1,8 +1,8 @@ #ifndef ENGINEREPO_H #define ENGINEREPO_H -#include "../../../common/Inspectable.h" +#include "../../common/Inspectable.h" #include -#include "../../../common/Serializable.h" +#include "../../common/Serializable.h" namespace Metal { struct EngineRepository final : Inspectable, Serializable { diff --git a/src/engine/repository/WorldRepository.cpp b/src/engine/repository/WorldRepository.cpp index aa0da49b..812ccace 100644 --- a/src/engine/repository/WorldRepository.cpp +++ b/src/engine/repository/WorldRepository.cpp @@ -1,9 +1,9 @@ -#include "../../../repository/world/WorldRepository.h" +#include "WorldRepository.h" #include "../../ApplicationContext.h" #include "../enum/ComponentType.h" #include "../../editor/dto/SceneData.h" -#include "../../editor/util/serialization-definitions.h" +#include "../../common/serialization-definitions.h" namespace Metal { entt::entity WorldRepository::createEntity() { diff --git a/src/engine/repository/WorldRepository.h b/src/engine/repository/WorldRepository.h index 86d0f415..1a42b233 100644 --- a/src/engine/repository/WorldRepository.h +++ b/src/engine/repository/WorldRepository.h @@ -6,8 +6,8 @@ #include #include -#include "../../../common/AbstractRuntimeComponent.h" -#include "../../../common/Serializable.h" +#include "../../common/AbstractRuntimeComponent.h" +#include "../../common/Serializable.h" #include "../../editor/enum/engine-definitions.h" #include "../dto/Camera.h" #include "../dto/MetadataComponent.h" diff --git a/src/engine/resource/BufferInstance.cpp b/src/engine/resource/BufferInstance.cpp index a8698cb0..e2144325 100644 --- a/src/engine/resource/BufferInstance.cpp +++ b/src/engine/resource/BufferInstance.cpp @@ -1,10 +1,4 @@ -#include "../../../service/buffer/BufferInstance.h" - -#include -#include "../../editor/service/LogService.h" -#include "../../ApplicationContext.h" -#include "../../vulkan/VulkanContext.h" -#include "../../vulkan/VulkanUtils.h" +#include "BufferInstance.h" namespace Metal { BufferType BufferInstance::getBufferType() { diff --git a/src/engine/resource/FrameBufferAttachment.cpp b/src/engine/resource/FrameBufferAttachment.cpp index cf4a0c4c..3e830173 100644 --- a/src/engine/resource/FrameBufferAttachment.cpp +++ b/src/engine/resource/FrameBufferAttachment.cpp @@ -1,4 +1,4 @@ -#include "../../../service/framebuffer/FrameBufferAttachment.h" +#include "FrameBufferAttachment.h" #include "../../ApplicationContext.h" diff --git a/src/engine/resource/TextureInstance.h b/src/engine/resource/TextureInstance.h index 0f78471e..e77fbafd 100644 --- a/src/engine/resource/TextureInstance.h +++ b/src/engine/resource/TextureInstance.h @@ -1,10 +1,8 @@ #ifndef TEXTUREINSTANCE_H #define TEXTUREINSTANCE_H -#include #include "../dto/DescriptorInstance.h" -#include "../../../common/RuntimeResource.h" -#include "../../vulkan/VulkanContext.h" +#include "RuntimeResource.h" namespace Metal { struct TextureInstance final : RuntimeResource { diff --git a/src/engine/service/BufferService.cpp b/src/engine/service/BufferService.cpp index 0b6beec3..27161788 100644 --- a/src/engine/service/BufferService.cpp +++ b/src/engine/service/BufferService.cpp @@ -1,7 +1,7 @@ -#include "../../../service/buffer/BufferService.h" +#include "BufferService.h" #include "../../ApplicationContext.h" -#include "../../vulkan/VulkanUtils.h" +#include "../../core/vulkan/VulkanUtils.h" #include "../resource/BufferInstance.h" namespace Metal { diff --git a/src/engine/service/BufferService.h b/src/engine/service/BufferService.h index 91de4573..a171a084 100644 --- a/src/engine/service/BufferService.h +++ b/src/engine/service/BufferService.h @@ -3,7 +3,7 @@ #include #include -#include "../../../common/AbstractResourceService.h" +#include "../../common/AbstractResourceService.h" #include "../resource/BufferInstance.h" #include "vulkan/vulkan.h" diff --git a/src/engine/service/CameraService.cpp b/src/engine/service/CameraService.cpp index 9058a3f1..3f58a727 100644 --- a/src/engine/service/CameraService.cpp +++ b/src/engine/service/CameraService.cpp @@ -1,4 +1,4 @@ -#include "../../../service/camera/CameraService.h" +#include "CameraService.h" #include "../dto/Camera.h" #include "../../ApplicationContext.h" diff --git a/src/engine/service/CameraService.h b/src/engine/service/CameraService.h index 98efd602..967f3a1c 100644 --- a/src/engine/service/CameraService.h +++ b/src/engine/service/CameraService.h @@ -1,7 +1,7 @@ #ifndef CAMERASYSTEM_H #define CAMERASYSTEM_H -#include "../../../common/AbstractRuntimeComponent.h" +#include "../../common/AbstractRuntimeComponent.h" #include #include diff --git a/src/engine/service/CommandBufferRecorderService.h b/src/engine/service/CommandBufferRecorderService.h index d4ce7c7c..c741b512 100644 --- a/src/engine/service/CommandBufferRecorderService.h +++ b/src/engine/service/CommandBufferRecorderService.h @@ -1,7 +1,7 @@ #ifndef COMMANDBUFFERRECORDERSERVICE_H #define COMMANDBUFFERRECORDERSERVICE_H -#include "../../../common/AbstractResourceService.h" +#include "../../common/AbstractResourceService.h" #include "../passes/CommandBufferRecorder.h" namespace Metal { diff --git a/src/engine/service/DescriptorSetService.cpp b/src/engine/service/DescriptorSetService.cpp index 3ee642d5..901a1f0a 100644 --- a/src/engine/service/DescriptorSetService.cpp +++ b/src/engine/service/DescriptorSetService.cpp @@ -1,12 +1,12 @@ -#include "../../../service/descriptor/DescriptorSetService.h" +#include "DescriptorSetService.h" #include "../dto/PipelineBuilder.h" #include "../resource/BufferInstance.h" #include "../../editor/service/LogService.h" #include "../../ApplicationContext.h" #include "../resource/FrameBufferAttachment.h" -#include "../../../service/framebuffer/FrameBufferInstance.h" +#include "../resource/FrameBufferInstance.h" #include "../resource/TextureInstance.h" -#include "../../vulkan/VulkanUtils.h" +#include "../../core/vulkan/VulkanUtils.h" namespace Metal { DescriptorInstance *DescriptorSetService::createDescriptor(const PipelineBuilder &pipelineBuilder, const std::string &id, VkShaderStageFlags stageFlags) { diff --git a/src/engine/service/DescriptorSetService.h b/src/engine/service/DescriptorSetService.h index 3777cf71..fd5d7833 100644 --- a/src/engine/service/DescriptorSetService.h +++ b/src/engine/service/DescriptorSetService.h @@ -1,7 +1,7 @@ #ifndef DESCRIPTORSETSERVICE_H #define DESCRIPTORSETSERVICE_H -#include "../../../common/AbstractResourceService.h" +#include "../../common/AbstractResourceService.h" #include "../dto/DescriptorInstance.h" namespace Metal { diff --git a/src/engine/service/FrameBufferService.cpp b/src/engine/service/FrameBufferService.cpp index 5188c427..1f90f6c5 100644 --- a/src/engine/service/FrameBufferService.cpp +++ b/src/engine/service/FrameBufferService.cpp @@ -1,11 +1,11 @@ -#include "../../../service/framebuffer/FrameBufferService.h" +#include "FrameBufferService.h" #include #include #include -#include "FrameBufferInstance.h" -#include "../../vulkan/VulkanUtils.h" +#include "../resource/FrameBufferInstance.h" +#include "../../core/vulkan/VulkanUtils.h" #include "../resource/FrameBufferAttachment.h" #include "../../ApplicationContext.h" diff --git a/src/engine/service/FrameBufferService.h b/src/engine/service/FrameBufferService.h index 985f3ab4..5cc4c221 100644 --- a/src/engine/service/FrameBufferService.h +++ b/src/engine/service/FrameBufferService.h @@ -5,7 +5,7 @@ #include #include -#include "../../../common/AbstractResourceService.h" +#include "../../common/AbstractResourceService.h" #include "../resource/FrameBufferInstance.h" namespace Metal { diff --git a/src/engine/service/LightService.cpp b/src/engine/service/LightService.cpp index e120c769..3d759aa0 100644 --- a/src/engine/service/LightService.cpp +++ b/src/engine/service/LightService.cpp @@ -1,4 +1,4 @@ -#include "../../../service/lights/LightService.h" +#include "LightService.h" #include "../../ApplicationContext.h" #include "../resource/BufferInstance.h" #include "../../editor/enum/EngineResourceIDs.h" diff --git a/src/engine/service/LightService.h b/src/engine/service/LightService.h index c7046f2a..655781c9 100644 --- a/src/engine/service/LightService.h +++ b/src/engine/service/LightService.h @@ -2,7 +2,7 @@ #define LIGHTSSERVICE_H #include -#include "../../../common/AbstractRuntimeComponent.h" +#include "../../common/AbstractRuntimeComponent.h" #include "../dto/LightData.h" namespace Metal { diff --git a/src/engine/service/MaterialService.cpp b/src/engine/service/MaterialService.cpp index ce5ef1cf..a42e5b3b 100644 --- a/src/engine/service/MaterialService.cpp +++ b/src/engine/service/MaterialService.cpp @@ -1,6 +1,6 @@ -#include "../../../service/material/MaterialService.h" +#include "MaterialService.h" -#include "../../editor/util/serialization-definitions.h" +#include "../../common/serialization-definitions.h" #include "../dto/MeshMetadata.h" #include "../../ApplicationContext.h" diff --git a/src/engine/service/MeshService.cpp b/src/engine/service/MeshService.cpp index a642e127..d3838b01 100644 --- a/src/engine/service/MeshService.cpp +++ b/src/engine/service/MeshService.cpp @@ -1,18 +1,15 @@ -#include "../../../service/mesh/MeshService.h" +#include "MeshService.h" #include "../resource/MeshInstance.h" #include "../dto/MeshData.h" #include "../../editor/dto/SceneData.h" -#include "../../vulkan/VulkanContext.h" +#include "../../core/vulkan/VulkanContext.h" #include "../../editor/util/FilesUtil.h" -#include "../../editor/util/serialization-definitions.h" #include #include #include "../../ApplicationContext.h" -#include "../dto/PrimitiveComponent.h" -#include "../dto/TransformComponent.h" namespace Metal { MeshInstance *MeshService::create(const std::string &id) { diff --git a/src/engine/service/MeshService.h b/src/engine/service/MeshService.h index 396af5d1..671c7baf 100644 --- a/src/engine/service/MeshService.h +++ b/src/engine/service/MeshService.h @@ -1,6 +1,6 @@ #ifndef MESHSERVICE_H #define MESHSERVICE_H -#include "../../../common/AbstractResourceService.h" +#include "../../common/AbstractResourceService.h" #include "../resource/MeshInstance.h" #include "../../editor/enum/engine-definitions.h" diff --git a/src/engine/service/PipelineService.cpp b/src/engine/service/PipelineService.cpp index 56884e6d..30df93ea 100644 --- a/src/engine/service/PipelineService.cpp +++ b/src/engine/service/PipelineService.cpp @@ -1,13 +1,12 @@ -#include "../../../service/pipeline/PipelineService.h" - +#include "PipelineService.h" #include "../dto/PipelineBuilder.h" #include "../util/ShaderUtil.h" #include "../../ApplicationContext.h" -#include "../../vulkan/VulkanUtils.h" -#include "../framebuffer/FrameBufferInstance.h" +#include "../../core/vulkan/VulkanUtils.h" +#include "../resource/FrameBufferInstance.h" #include "../resource/PipelineInstance.h" #include "../dto/MeshData.h" -#include "../../context/editor/dto/VertexData.h" +#include "../dto/VertexData.h" #include "../dto/DescriptorInstance.h" #include "../resource/FrameBufferAttachment.h" #include "../resource/BufferInstance.h" diff --git a/src/engine/service/PipelineService.h b/src/engine/service/PipelineService.h index d43d8ce1..6d97a544 100644 --- a/src/engine/service/PipelineService.h +++ b/src/engine/service/PipelineService.h @@ -2,7 +2,7 @@ #define PIPELINESERVICE_H #include -#include "../../../common/AbstractResourceService.h" +#include "../../common/AbstractResourceService.h" #include "DescriptorSetService.h" #include "../resource/PipelineInstance.h" diff --git a/src/engine/service/RayTracingService.cpp b/src/engine/service/RayTracingService.cpp index 1210906e..d46be68a 100644 --- a/src/engine/service/RayTracingService.cpp +++ b/src/engine/service/RayTracingService.cpp @@ -1,11 +1,11 @@ -#include "../../../service/raytracing/RayTracingService.h" +#include "RayTracingService.h" #include "../../ApplicationContext.h" #include "../resource/BufferInstance.h" #include "../dto/DescriptorInstance.h" -#include "../../../service/descriptor/DescriptorBinding.h" +#include "../dto/DescriptorBinding.h" #include "../resource/MeshInstance.h" #include "../dto/VertexData.h" -#include "../../vulkan/VulkanUtils.h" +#include "../../core/vulkan/VulkanUtils.h" #include "../../editor/enum/EngineResourceIDs.h" #include diff --git a/src/engine/service/RayTracingService.h b/src/engine/service/RayTracingService.h index a646b23c..e4b35fa7 100644 --- a/src/engine/service/RayTracingService.h +++ b/src/engine/service/RayTracingService.h @@ -8,7 +8,7 @@ #include #include #include -#include "../../../common/AbstractRuntimeComponent.h" +#include "../../common/AbstractRuntimeComponent.h" namespace Metal { struct BufferInstance; diff --git a/src/engine/service/StreamingService.cpp b/src/engine/service/StreamingService.cpp index 6ddb487a..48895cb4 100644 --- a/src/engine/service/StreamingService.cpp +++ b/src/engine/service/StreamingService.cpp @@ -1,4 +1,4 @@ -#include "../../../repository/streaming/StreamingService.h" +#include "StreamingService.h" #include "../../ApplicationContext.h" #include "../resource/SVOInstance.h" diff --git a/src/engine/service/StreamingService.h b/src/engine/service/StreamingService.h index f2b6a1d8..ccd7e5af 100644 --- a/src/engine/service/StreamingService.h +++ b/src/engine/service/StreamingService.h @@ -4,9 +4,8 @@ #include #include -#include "../../../common/AbstractResourceService.h" -#include "../../../common/AbstractCoreRepository.h" -#include "../../../repository/abstract/RuntimeResource.h" +#include "../../common/AbstractResourceService.h" +#include "../../common/AbstractCoreRepository.h" using Clock = std::chrono::high_resolution_clock; using TimePoint = std::chrono::time_point; diff --git a/src/engine/service/TextureService.cpp b/src/engine/service/TextureService.cpp index 4e71cd3f..8f20419f 100644 --- a/src/engine/service/TextureService.cpp +++ b/src/engine/service/TextureService.cpp @@ -1,4 +1,4 @@ -#include "../../../service/texture/TextureService.h" +#include "TextureService.h" #include diff --git a/src/engine/service/TextureService.h b/src/engine/service/TextureService.h index 4184817f..e1eff442 100644 --- a/src/engine/service/TextureService.h +++ b/src/engine/service/TextureService.h @@ -5,7 +5,7 @@ #include #include "../dto/TextureData.h" -#include "../../../common/AbstractResourceService.h" +#include "../../common/AbstractResourceService.h" #include "../resource/TextureInstance.h" namespace Metal { diff --git a/src/engine/service/TransformService.cpp b/src/engine/service/TransformService.cpp index 8a7a0a4f..5dfdc638 100644 --- a/src/engine/service/TransformService.cpp +++ b/src/engine/service/TransformService.cpp @@ -1,4 +1,4 @@ -#include "../../../service/transform/TransformService.h" +#include "TransformService.h" #include #include #include diff --git a/src/engine/service/TransformService.h b/src/engine/service/TransformService.h index 1d5d88d8..ff399b3e 100644 --- a/src/engine/service/TransformService.h +++ b/src/engine/service/TransformService.h @@ -5,7 +5,7 @@ #include #include "../../editor/enum/engine-definitions.h" -#include "../../../common/AbstractRuntimeComponent.h" +#include "../../common/AbstractRuntimeComponent.h" namespace Metal { struct TransformComponent; diff --git a/src/engine/service/VolumeService.cpp b/src/engine/service/VolumeService.cpp index 2e19ef20..2f5cde9f 100644 --- a/src/engine/service/VolumeService.cpp +++ b/src/engine/service/VolumeService.cpp @@ -1,4 +1,4 @@ -#include "../../../service/volumes/VolumeService.h" +#include "VolumeService.h" #include "../../ApplicationContext.h" #include "../dto/VolumeComponent.h" #include "../resource/BufferInstance.h" diff --git a/src/engine/service/VolumeService.h b/src/engine/service/VolumeService.h index 3df0d4e7..2feafe3e 100644 --- a/src/engine/service/VolumeService.h +++ b/src/engine/service/VolumeService.h @@ -2,7 +2,7 @@ #define VOLUME_SERVICE_H #include -#include "../../../common/AbstractRuntimeComponent.h" +#include "../../common/AbstractRuntimeComponent.h" #include "../dto/VolumeData.h" namespace Metal { diff --git a/src/engine/service/VoxelService.cpp b/src/engine/service/VoxelService.cpp index ab70ff5e..d1db5046 100644 --- a/src/engine/service/VoxelService.cpp +++ b/src/engine/service/VoxelService.cpp @@ -1,8 +1,4 @@ -// -// Created by russi on 2/18/2026. -// - -#include "../../../service/voxel/VoxelService.h" +#include "VoxelService.h" #include "../resource/SVOInstance.h" diff --git a/src/engine/service/VoxelService.h b/src/engine/service/VoxelService.h index e5c6939a..aab1bf57 100644 --- a/src/engine/service/VoxelService.h +++ b/src/engine/service/VoxelService.h @@ -1,7 +1,7 @@ #ifndef METAL_ENGINE_VOXELSERVICE_H #define METAL_ENGINE_VOXELSERVICE_H -#include "../../../common/AbstractResourceService.h" +#include "../../common/AbstractResourceService.h" #include "../resource/SVOInstance.h" namespace Metal { diff --git a/src/engine/util/ShaderUtil.cpp b/src/engine/util/ShaderUtil.cpp index 1924663c..b0544a2e 100644 --- a/src/engine/util/ShaderUtil.cpp +++ b/src/engine/util/ShaderUtil.cpp @@ -1,10 +1,10 @@ -#include "../../../util/ShaderUtil.h" +#include "ShaderUtil.h" #include #include #include "../dto/ShaderModule.h" -#include "../../vulkan/VulkanUtils.h" +#include "../../core/vulkan/VulkanUtils.h" #include "../../editor/util/Util.h" #include "../../ApplicationContext.h" #include "../../editor/util/FilesUtil.h" From cf8ae69c8478393f5ddc1560820e3e11963a116a Mon Sep 17 00:00:00 2001 From: facobackup Date: Thu, 12 Mar 2026 22:37:26 -0300 Subject: [PATCH 10/18] Constructor references Rollback panel removing applicationContext pointer Added imgui rendered window frame and footer --- CMakeLists.txt | 2 + src/ApplicationContext.cpp | 1 + src/ApplicationContext.h | 30 +++--- src/core/glfw/GLFWContext.cpp | 1 + src/editor/EditorPanel.cpp | 40 +++++--- src/editor/EditorPanel.h | 5 + src/editor/abstract/AbstractPanel.cpp | 1 + src/editor/abstract/AbstractPanel.h | 3 +- src/editor/abstract/form/AccordionPanel.cpp | 2 +- src/editor/abstract/form/ChildPanel.cpp | 2 +- .../abstract/form/types/ResourceField.cpp | 2 +- .../dock-spaces/console/ConsolePanel.cpp | 8 +- .../dock-spaces/docks/DockSpacePanel.cpp | 8 +- .../dock-spaces/files/FilePreviewPanel.cpp | 4 +- .../dock-spaces/files/FilesListPanel.cpp | 4 +- src/editor/dock-spaces/files/FilesListPanel.h | 4 +- src/editor/dock-spaces/files/FilesPanel.cpp | 32 +++---- .../dock-spaces/footer/EditorFooterPanel.cpp | 59 ++++++++++++ .../dock-spaces/footer/EditorFooterPanel.h | 16 ++++ .../dock-spaces/header/AsyncTaskPanel.cpp | 4 +- .../dock-spaces/header/EditorHeaderPanel.cpp | 94 ++++++++----------- .../dock-spaces/header/EditorHeaderPanel.h | 4 +- .../dock-spaces/inspector/InspectorPanel.cpp | 8 +- .../dock-spaces/metrics/MetricsPanel.cpp | 12 +-- .../repositories/RepositoriesPanel.cpp | 6 +- .../viewport/CameraPositionPanel.cpp | 6 +- .../dock-spaces/viewport/EngineFramePanel.cpp | 14 +-- .../dock-spaces/viewport/GizmoPanel.cpp | 10 +- .../viewport/GizmoSettingsPanel.cpp | 6 +- .../viewport/ViewportHeaderPanel.cpp | 10 +- .../dock-spaces/viewport/ViewportPanel.cpp | 42 ++++----- .../dock-spaces/world/WorldHeaderPanel.cpp | 2 +- src/editor/dock-spaces/world/WorldPanel.cpp | 30 +++--- src/editor/panel/FileImportModalPanel.cpp | 6 +- src/editor/panel/NotificationsPanel.cpp | 10 +- src/editor/service/FileImporterService.cpp | 35 +++---- src/editor/service/FileImporterService.h | 23 +++++ src/editor/service/FilesService.cpp | 22 ++--- src/editor/service/FilesService.h | 8 +- src/editor/service/LogService.cpp | 16 ++-- src/editor/service/LogService.h | 31 +++--- .../service/MaterialImporterService.cpp | 7 +- src/editor/service/MaterialImporterService.h | 9 ++ src/editor/service/MeshImporterService.cpp | 4 +- src/editor/service/MeshImporterService.h | 5 + src/editor/service/PickingService.cpp | 21 +++-- src/editor/service/PickingService.h | 12 +++ src/editor/service/SceneImporterService.cpp | 25 ++--- src/editor/service/SceneImporterService.h | 37 +++++--- src/editor/service/SelectionService.cpp | 15 +-- src/editor/service/SelectionService.h | 7 ++ src/editor/service/TextureImporterService.cpp | 4 +- src/editor/service/TextureImporterService.h | 6 +- src/editor/service/VoxelImporterService.cpp | 3 +- src/editor/service/VoxelImporterService.h | 4 + src/engine/EngineContext.cpp | 46 +++++---- src/engine/EngineContext.h | 39 ++++++++ src/engine/repository/EngineRepository.cpp | 9 +- src/engine/repository/WorldRepository.cpp | 10 +- src/engine/repository/WorldRepository.h | 8 ++ src/engine/service/BufferService.cpp | 44 +++++---- src/engine/service/BufferService.h | 5 + src/engine/service/CameraService.cpp | 17 ++-- src/engine/service/CameraService.h | 11 ++- src/engine/service/DescriptorSetService.cpp | 33 ++++--- src/engine/service/DescriptorSetService.h | 15 ++- src/engine/service/FrameBufferService.cpp | 23 ++--- src/engine/service/FrameBufferService.h | 7 ++ src/engine/service/LightService.cpp | 14 +-- src/engine/service/LightService.h | 10 ++ src/engine/service/MaterialService.cpp | 17 ++-- src/engine/service/MaterialService.h | 5 + src/engine/service/MeshService.cpp | 15 +-- src/engine/service/MeshService.h | 11 +++ src/engine/service/PipelineService.cpp | 45 ++++----- src/engine/service/PipelineService.h | 15 ++- src/engine/service/RayTracingService.cpp | 71 +++++++------- src/engine/service/RayTracingService.h | 20 +++- src/engine/service/StreamingService.cpp | 32 ++++--- src/engine/service/StreamingService.h | 14 +++ src/engine/service/TextureService.cpp | 62 ++++++------ src/engine/service/TextureService.h | 13 +++ src/engine/service/TransformService.cpp | 10 +- src/engine/service/TransformService.h | 10 ++ src/engine/service/VolumeService.cpp | 8 +- src/engine/service/VolumeService.h | 9 ++ 86 files changed, 906 insertions(+), 524 deletions(-) create mode 100644 src/editor/dock-spaces/footer/EditorFooterPanel.cpp create mode 100644 src/editor/dock-spaces/footer/EditorFooterPanel.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 391ca93b..9fa89d53 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -59,6 +59,8 @@ add_executable( src/editor/dock-spaces/header/EditorHeaderPanel.h src/editor/dock-spaces/header/AsyncTaskPanel.cpp src/editor/dock-spaces/header/AsyncTaskPanel.h + src/editor/dock-spaces/footer/EditorFooterPanel.cpp + src/editor/dock-spaces/footer/EditorFooterPanel.h src/common/Icons.h src/editor/service/DockService.cpp src/editor/service/DockService.h diff --git a/src/ApplicationContext.cpp b/src/ApplicationContext.cpp index d47dd628..9aff2362 100644 --- a/src/ApplicationContext.cpp +++ b/src/ApplicationContext.cpp @@ -80,6 +80,7 @@ namespace Metal { vulkanContext.onInitialize(); guiContext.onInitialize(); filesService.onInitialize(); + editorPanel.applicationContext = this; editorPanel.onInitialize(); engineContext.onInitialize(); diff --git a/src/ApplicationContext.h b/src/ApplicationContext.h index e1c88cfb..3e0f075e 100644 --- a/src/ApplicationContext.h +++ b/src/ApplicationContext.h @@ -34,7 +34,6 @@ #include "engine/service/CommandBufferRecorderService.h" #include "editor/service/NotificationService.h" #include "editor/service/AsyncTaskService.h" -#include "editor/service/LogService.h" #include "engine/service/TransformService.h" #include "editor/service/PickingService.h" #include "engine/service/VolumeService.h" @@ -67,14 +66,13 @@ namespace Metal { // ----------- Services NotificationService notificationService; AsyncTaskService asyncTaskService; - LogService logService{}; - MeshService meshService{}; - MaterialService materialService{}; - TextureService textureService{}; - FrameBufferService framebufferService{}; - DescriptorSetService descriptorSetService{}; - PipelineService pipelineService{descriptorSetService}; - BufferService bufferService{}; + MeshService meshService{bufferService, rayTracingService, rootDirectory}; + MaterialService materialService{textureService}; + TextureService textureService{vulkanContext, bufferService, pipelineService, descriptorSetService, rootDirectory}; + FrameBufferService framebufferService{vulkanContext}; + DescriptorSetService descriptorSetService{vulkanContext, framebufferService, bufferService, textureService}; + PipelineService pipelineService{vulkanContext, framebufferService, bufferService, descriptorSetService}; + BufferService bufferService{vulkanContext}; ThemeService themeService{}; DockService dockService{}; SelectionService selectionService{}; @@ -84,21 +82,21 @@ namespace Metal { TextureImporterService textureImporter{}; FilesService filesService{}; FileImporterService fileImporterService{}; - CameraService cameraService{}; + CameraService cameraService{engineContext, worldRepository, runtimeRepository}; PickingService pickingService{}; - TransformService transformService{}; - LightService lightService{}; - VolumeService volumeService{}; - RayTracingService rayTracingService{}; + TransformService transformService{worldRepository, rayTracingService}; + LightService lightService{engineContext, engineRepository}; + VolumeService volumeService{worldRepository, engineContext}; + RayTracingService rayTracingService{vulkanContext, pipelineService, worldRepository, meshService, materialService, bufferService, engineContext}; CommandBufferRecorderService commandBufferRecorderService{}; - VoxelImporterService voxelImporterService{}; + VoxelImporterService voxelImporterService{rootDirectory}; VoxelService voxelService{}; // ----------- Services // ----------- Repository WorldRepository worldRepository{}; RuntimeRepository runtimeRepository{}; - StreamingService streamingService{}; + StreamingService streamingService{engineContext, worldRepository, meshService, textureService, voxelService}; EngineRepository engineRepository{}; DockRepository dockRepository{}; EditorRepository editorRepository{}; diff --git a/src/core/glfw/GLFWContext.cpp b/src/core/glfw/GLFWContext.cpp index 8014aea8..9ebba466 100644 --- a/src/core/glfw/GLFWContext.cpp +++ b/src/core/glfw/GLFWContext.cpp @@ -85,6 +85,7 @@ namespace Metal { if (validContext) { glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); + glfwWindowHint(GLFW_DECORATED, GLFW_FALSE); window = glfwCreateWindow(1280, 720, ENGINE_NAME, nullptr, nullptr); if (!glfwVulkanSupported()) { diff --git a/src/editor/EditorPanel.cpp b/src/editor/EditorPanel.cpp index 0f07986a..399fa50e 100644 --- a/src/editor/EditorPanel.cpp +++ b/src/editor/EditorPanel.cpp @@ -2,6 +2,7 @@ #include "util/UIUtil.h" #include "../ApplicationContext.h" #include "dock-spaces/header/EditorHeaderPanel.h" +#include "dock-spaces/footer/EditorFooterPanel.h" #include "panel/FileImportModalPanel.h" #include "panel/NotificationsPanel.h" @@ -15,13 +16,16 @@ namespace Metal { ImGuiWindowFlags_NoNavFocus; const char *EditorPanel::NAME = "##main_window"; const char *EditorPanel::NAME_HEADER = "##header_window"; + const char *EditorPanel::NAME_FOOTER = "##footer_window"; ImVec2 EditorPanel::CENTER(0.0f, 0.0f); float EditorPanel::HEADER_HEIGHT = 25; + float EditorPanel::FOOTER_HEIGHT = 30; void EditorPanel::renderDockSpaces() { const ImGuiViewport *viewport = ImGui::GetMainViewport(); renderHeader(viewport); + renderFooter(viewport); // Begin window { @@ -30,7 +34,7 @@ namespace Metal { ImGui::SetNextWindowPos(UIUtil::AUX_VEC2); UIUtil::AUX_VEC2.x = viewport->Size.x; - UIUtil::AUX_VEC2.y = viewport->Size.y - HEADER_HEIGHT; + UIUtil::AUX_VEC2.y = viewport->Size.y - HEADER_HEIGHT - FOOTER_HEIGHT; ImGui::SetNextWindowSize(UIUtil::AUX_VEC2); ImGui::SetNextWindowViewport(viewport->ID); @@ -42,7 +46,7 @@ namespace Metal { ImGui::PopStyleVar(3); - CTX.dockService.buildViews(windowId, this); + applicationContext->dockService.buildViews(windowId, this); ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 0.0f); ImGui::DockSpace(windowId, CENTER, ImGuiDockNodeFlags_PassthruCentralNode); @@ -54,7 +58,7 @@ namespace Metal { void EditorPanel::renderHeader(const ImGuiViewport *viewport) { UIUtil::AUX_VEC2.x = viewport->Pos.x; - UIUtil::AUX_VEC2.y = 0; + UIUtil::AUX_VEC2.y = viewport->Pos.y; ImGui::SetNextWindowPos(UIUtil::AUX_VEC2); UIUtil::AUX_VEC2.x = viewport->Size.x; @@ -69,6 +73,23 @@ namespace Metal { ImGui::End(); } + void EditorPanel::renderFooter(const ImGuiViewport *viewport) { + UIUtil::AUX_VEC2.x = viewport->Pos.x; + UIUtil::AUX_VEC2.y = viewport->Pos.y + viewport->Size.y - FOOTER_HEIGHT; + ImGui::SetNextWindowPos(UIUtil::AUX_VEC2); + + UIUtil::AUX_VEC2.x = viewport->Size.x; + UIUtil::AUX_VEC2.y = FOOTER_HEIGHT; + ImGui::SetNextWindowSize(UIUtil::AUX_VEC2); + + SetWindowStyle(); + ImGui::Begin(NAME_FOOTER, &UIUtil::OPEN, FLAGS | ImGuiWindowFlags_NoScrollbar); + ImGui::PopStyleVar(3); + + footerPanel->onSync(); + ImGui::End(); + } + void EditorPanel::SetWindowStyle() { ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f); ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f); @@ -76,19 +97,16 @@ namespace Metal { } void EditorPanel::onSync() { - CTX.themeService.onSync(); + applicationContext->themeService.onSync(); renderDockSpaces(); notificationsPanel->onSync(); fileImportModalPanel->onSync(); } void EditorPanel::onInitialize() { - headerPanel = new EditorHeaderPanel(); - headerPanel->onInitialize(); - notificationsPanel = new NotificationsPanel(); - notificationsPanel->onInitialize(); - - fileImportModalPanel = new FileImportModalPanel(); - fileImportModalPanel->onInitialize(); + appendChild(headerPanel = new EditorHeaderPanel()); + appendChild(footerPanel = new EditorFooterPanel()); + appendChild(notificationsPanel = new NotificationsPanel()); + appendChild(fileImportModalPanel = new FileImportModalPanel()); } } diff --git a/src/editor/EditorPanel.h b/src/editor/EditorPanel.h index 0a1983e7..32a9cf0a 100644 --- a/src/editor/EditorPanel.h +++ b/src/editor/EditorPanel.h @@ -9,10 +9,13 @@ namespace Metal { static int FLAGS; static const char *NAME; static const char *NAME_HEADER; + static const char *NAME_FOOTER; static ImVec2 CENTER; static float HEADER_HEIGHT; + static float FOOTER_HEIGHT; ImGuiID windowId = 0; AbstractPanel *headerPanel = nullptr; + AbstractPanel *footerPanel = nullptr; AbstractPanel *notificationsPanel = nullptr; AbstractPanel *fileImportModalPanel = nullptr; @@ -22,6 +25,8 @@ namespace Metal { void renderHeader(const ImGuiViewport *viewport); + void renderFooter(const ImGuiViewport *viewport); + public: void onInitialize() override; diff --git a/src/editor/abstract/AbstractPanel.cpp b/src/editor/abstract/AbstractPanel.cpp index c4ab4cd6..3db1de52 100644 --- a/src/editor/abstract/AbstractPanel.cpp +++ b/src/editor/abstract/AbstractPanel.cpp @@ -3,6 +3,7 @@ namespace Metal { void AbstractPanel::appendChild(AbstractPanel *panel) { + panel->applicationContext = applicationContext; panel->onInitialize(); children.emplace_back(panel); } diff --git a/src/editor/abstract/AbstractPanel.h b/src/editor/abstract/AbstractPanel.h index 61ac76b6..d2f52f23 100644 --- a/src/editor/abstract/AbstractPanel.h +++ b/src/editor/abstract/AbstractPanel.h @@ -8,8 +8,9 @@ namespace Metal { class ApplicationContext; - class AbstractPanel : public IPanel { + public: + ApplicationContext *applicationContext{}; protected: std::vector children; const std::string id; diff --git a/src/editor/abstract/form/AccordionPanel.cpp b/src/editor/abstract/form/AccordionPanel.cpp index bf310e4b..0efd891e 100644 --- a/src/editor/abstract/form/AccordionPanel.cpp +++ b/src/editor/abstract/form/AccordionPanel.cpp @@ -14,7 +14,7 @@ namespace Metal { return; } - ImGui::PushStyleColor(ImGuiCol_Header, CTX.themeService.neutralPalette); + ImGui::PushStyleColor(ImGuiCol_Header, applicationContext->themeService.neutralPalette); bool open = ImGui::CollapsingHeader(fixedId.c_str(), ImGuiTreeNodeFlags_None); ImGui::PopStyleColor(); diff --git a/src/editor/abstract/form/ChildPanel.cpp b/src/editor/abstract/form/ChildPanel.cpp index 85f7c309..aaf611b5 100644 --- a/src/editor/abstract/form/ChildPanel.cpp +++ b/src/editor/abstract/form/ChildPanel.cpp @@ -9,7 +9,7 @@ namespace Metal { } void ChildPanel::onSync() { - ImGui::PushStyleColor(ImGuiCol_ChildBg, CTX.themeService.palette0); + ImGui::PushStyleColor(ImGuiCol_ChildBg, applicationContext->themeService.palette0); if (!title.empty()) { ImGui::Spacing(); ImGui::Text(title.c_str()); diff --git a/src/editor/abstract/form/types/ResourceField.cpp b/src/editor/abstract/form/types/ResourceField.cpp index 668ec209..3b06c714 100644 --- a/src/editor/abstract/form/types/ResourceField.cpp +++ b/src/editor/abstract/form/types/ResourceField.cpp @@ -79,7 +79,7 @@ namespace Metal { void ResourceField::onSync() { if (field.field->size() > 0 && (entry == nullptr || entry->getId() != *field.field)) { - entry = CTX.filesService.getResource(*field.field); + entry = applicationContext->filesService.getResource(*field.field); } if (!field.disabled) { renderButton(); diff --git a/src/editor/dock-spaces/console/ConsolePanel.cpp b/src/editor/dock-spaces/console/ConsolePanel.cpp index 67e17115..9f2093af 100644 --- a/src/editor/dock-spaces/console/ConsolePanel.cpp +++ b/src/editor/dock-spaces/console/ConsolePanel.cpp @@ -11,17 +11,15 @@ namespace Metal { } shortcuts = { ShortcutDTO("Clear Logs", ImGuiMod_Ctrl | ImGuiKey_L, [this]() { - CTX.logService.clear(); + LogService::clear(); }) }; } void ConsolePanel::onSync() { - LogService& logService = CTX.logService; - // Header if (ImGui::Button("Clear")) { - logService.clear(); + LogService::clear(); } ImGui::SameLine(); bool copyToClipboard = ImGui::Button("Copy"); @@ -48,7 +46,7 @@ namespace Metal { ImGui::LogToClipboard(); } - const auto entries = logService.getEntriesSnapshot(); + const auto entries = LogService::getEntriesSnapshot(); for (const auto& entry : entries) { if (!levelFilter[(int)entry.level]) continue; if (!filter.PassFilter(entry.message.c_str())) continue; diff --git a/src/editor/dock-spaces/docks/DockSpacePanel.cpp b/src/editor/dock-spaces/docks/DockSpacePanel.cpp index 16098bbc..c6f0826a 100644 --- a/src/editor/dock-spaces/docks/DockSpacePanel.cpp +++ b/src/editor/dock-spaces/docks/DockSpacePanel.cpp @@ -52,13 +52,13 @@ namespace Metal { if (view != nullptr) { const bool isHovered = ImGui::IsWindowHovered(ImGuiHoveredFlags_RootAndChildWindows); if (isHovered) { - CTX.editorRepository.focusedShortcuts = view->getShortcuts(); - CTX.editorRepository.focusedWindowName = view->dock->name; + applicationContext->editorRepository.focusedShortcuts = view->getShortcuts(); + applicationContext->editorRepository.focusedWindowName = view->dock->name; } view->isWindowFocused = isHovered; if (view->isWindowFocused) { - for (const auto &shortcut: CTX.editorRepository.focusedShortcuts) { + for (const auto &shortcut: applicationContext->editorRepository.focusedShortcuts) { if (ImGui::IsKeyChordPressed(shortcut.keyChord)) { LOG_INFO("Action called: " + shortcut.name); shortcut.callback(); @@ -116,7 +116,7 @@ namespace Metal { ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, headerPadding); const bool isFocused = ImGui::IsWindowFocused(ImGuiFocusedFlags_RootAndChildWindows); ImGui::PushStyleColor(ImGuiCol_TabActive, - isFocused ? CTX.editorRepository.accent : CTX.themeService.palette0); + isFocused ? applicationContext->editorRepository.accent : applicationContext->themeService.palette0); if (ImGui::BeginTabBar((id + "dockTabs").c_str(), ImGuiTabBarFlags_AutoSelectNewTabs)) { for (auto *space: dock->dockSpaces) { diff --git a/src/editor/dock-spaces/files/FilePreviewPanel.cpp b/src/editor/dock-spaces/files/FilePreviewPanel.cpp index 87a6ca4a..143aa77a 100644 --- a/src/editor/dock-spaces/files/FilePreviewPanel.cpp +++ b/src/editor/dock-spaces/files/FilePreviewPanel.cpp @@ -21,7 +21,7 @@ namespace Metal { ImGui::Separator(); if (selected->type == EntryType::TEXTURE) { - auto *texture = CTX.textureService.stream(selected->getId()); + auto *texture = applicationContext->textureService.stream(selected->getId()); if (texture != nullptr) { float availWidth = ImGui::GetContentRegionAvail().x; float availHeight = ImGui::GetContentRegionAvail().y * 0.6f; // reserve space for table @@ -41,7 +41,7 @@ namespace Metal { float offsetX = (availWidth - renderWidth) * 0.5f; if (offsetX > 0) ImGui::SetCursorPosX(ImGui::GetCursorPosX() + offsetX); - CTX.guiContext.renderImage(texture, renderWidth, renderHeight); + applicationContext->guiContext.renderImage(texture, renderWidth, renderHeight); ImGui::Separator(); } } diff --git a/src/editor/dock-spaces/files/FilesListPanel.cpp b/src/editor/dock-spaces/files/FilesListPanel.cpp index 05b2fa59..56229939 100644 --- a/src/editor/dock-spaces/files/FilesListPanel.cpp +++ b/src/editor/dock-spaces/files/FilesListPanel.cpp @@ -89,7 +89,7 @@ namespace Metal { if (!ImGui::IsMouseDown(ImGuiMouseButton_Left) && onDrag != nullptr && fileEntry->type == EntryType::DIRECTORY) { - CTX.filesService.Move(onDrag, fileEntry); + applicationContext->filesService.Move(onDrag, fileEntry); onDrag = nullptr; } } @@ -280,7 +280,7 @@ namespace Metal { FilesService::GetEntries(filesContext.currentDirectory); } if (ImGui::MenuItem("Delete")) { - CTX.filesService.deleteFiles(filesContext.selected); + applicationContext->filesService.deleteFiles(filesContext.selected); FilesService::GetEntries(filesContext.currentDirectory); } ImGui::Separator(); diff --git a/src/editor/dock-spaces/files/FilesListPanel.h b/src/editor/dock-spaces/files/FilesListPanel.h index 9eda2ba8..1bf8dd21 100644 --- a/src/editor/dock-spaces/files/FilesListPanel.h +++ b/src/editor/dock-spaces/files/FilesListPanel.h @@ -45,9 +45,9 @@ namespace Metal { void renderTreeItem(FSEntry *entry); public: - explicit FilesListPanel(FilesContext &ctx, std::function onDoubleClick, + explicit FilesListPanel(FilesContext &applicationContext-> std::function onDoubleClick, EntryType::EntryType typeFilter) - : filesContext(ctx), typeFilter(typeFilter), onDoubleClick(std::move(onDoubleClick)) { + : filesContext(applicationContext->, typeFilter(typeFilter), onDoubleClick(std::move(onDoubleClick)) { } void onSync() override; diff --git a/src/editor/dock-spaces/files/FilesPanel.cpp b/src/editor/dock-spaces/files/FilesPanel.cpp index c09b0515..898b0afa 100644 --- a/src/editor/dock-spaces/files/FilesPanel.cpp +++ b/src/editor/dock-spaces/files/FilesPanel.cpp @@ -28,27 +28,27 @@ namespace Metal { auto files = FileDialogUtil::PickFiles({ { "Files", - CTX.fileImporterService.collectCompatibleFiles().c_str(), + applicationContext->fileImporterService.collectCompatibleFiles().c_str(), } }); if (!files.empty()) { - CTX.editorRepository.pendingImports = files; - CTX.editorRepository.importSettingsMap.clear(); - for (const auto& file : CTX.editorRepository.pendingImports) { - if (CTX.sceneImporterService.isCompatible(file)) { - CTX.editorRepository.importSettingsMap.emplace(file, std::make_shared()); + applicationContext->editorRepository.pendingImports = files; + applicationContext->editorRepository.importSettingsMap.clear(); + for (const auto& file : applicationContext->editorRepository.pendingImports) { + if (applicationContext->sceneImporterService.isCompatible(file)) { + applicationContext->editorRepository.importSettingsMap.emplace(file, std::make_shared()); } else { - CTX.editorRepository.importSettingsMap.emplace(file, std::make_shared()); + applicationContext->editorRepository.importSettingsMap.emplace(file, std::make_shared()); } } - CTX.editorRepository.selectedFileForSettings = CTX.editorRepository.pendingImports[0]; - CTX.editorRepository.targetImportDirectory = filesContext.currentDirectory; + applicationContext->editorRepository.selectedFileForSettings = applicationContext->editorRepository.pendingImports[0]; + applicationContext->editorRepository.targetImportDirectory = filesContext.currentDirectory; } }; } void FilesPanel::onInitialize() { - filesContext.setCurrentDirectory(CTX.filesService.getRoot()); + filesContext.setCurrentDirectory(applicationContext->filesService.getRoot()); appendChild(filesHeader = new FilesHeaderPanel(filesContext, getActionLabel(), onAction())); filesListPanel = new FilesListPanel( filesContext, [ @@ -124,13 +124,13 @@ namespace Metal { void FilesPanel::openResource(FSEntry *root) { switch (root->type) { case EntryType::SCENE: { - CTX.notificationService.pushMessage("Loading scene", NotificationSeverities::SUCCESS); - CTX.worldRepository.loadScene(root->getId()); + applicationContext->notificationService.pushMessage("Loading scene", NotificationSeverities::SUCCESS); + applicationContext->worldRepository.loadScene(root->getId()); break; } case EntryType::VOLUME: { - CTX.notificationService.pushMessage("Loading volume", NotificationSeverities::SUCCESS); - CTX.voxelService.create(root->getId()); + applicationContext->notificationService.pushMessage("Loading volume", NotificationSeverities::SUCCESS); + applicationContext->voxelService.create(root->getId()); break; } case EntryType::DIRECTORY: { @@ -140,7 +140,7 @@ namespace Metal { break; } default: - CTX.notificationService.pushMessage("Unsupported resource type", NotificationSeverities::ERROR); + applicationContext->notificationService.pushMessage("Unsupported resource type", NotificationSeverities::ERROR); break; } } @@ -174,7 +174,7 @@ namespace Metal { } void FilesPanel::deleteSelected() const { - CTX.filesService.deleteFiles(filesContext.selected); + applicationContext->filesService.deleteFiles(filesContext.selected); FilesService::GetEntries(filesContext.currentDirectory); } } diff --git a/src/editor/dock-spaces/footer/EditorFooterPanel.cpp b/src/editor/dock-spaces/footer/EditorFooterPanel.cpp new file mode 100644 index 00000000..c754ab52 --- /dev/null +++ b/src/editor/dock-spaces/footer/EditorFooterPanel.cpp @@ -0,0 +1,59 @@ +#include "EditorFooterPanel.h" +#include "../../util/UIUtil.h" +#include "../../../ApplicationContext.h" + +namespace Metal { + void EditorFooterPanel::onSync() { + renderShortcuts(); + framerate(); + } + + void EditorFooterPanel::framerate() { + const int framerate = static_cast(round(ImGui::GetIO().Framerate)); + if (framerate > 0) { + ImGui::SameLine(ImGui::GetWindowWidth() - 100); + ImGui::Text("%i ms | %i fps", 1000 / framerate, framerate); + } + } + + void EditorFooterPanel::renderShortcuts() { + auto &shortcuts = applicationContext->editorRepository.focusedShortcuts; + if (shortcuts.empty()) return; + + ImGui::SetCursorPosY(ImGui::GetCursorPosY() + 5); // Some padding + ImGui::Text(applicationContext->editorRepository.focusedWindowName.c_str()); + ImGui::SameLine(); + std::string label; + for (size_t i = 0; i < std::min(shortcuts.size(), size_t(3)); ++i) { + if (i > 0) label += " | "; + label += UIUtil::GetKeyChordName(shortcuts[i].keyChord); + } + + if (ImGui::Button(label.c_str())) { + ImGui::OpenPopup("AllShortcutsPopupFooter"); + } + + if (ImGui::BeginPopup("AllShortcutsPopupFooter")) { + if (ImGui::BeginTable("ShortcutsTableFooter", 2, + ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg | + ImGuiTableFlags_SizingStretchProp)) { + ImGui::TableSetupColumn("Key"); + ImGui::TableSetupColumn("Action"); + ImGui::TableHeadersRow(); + + for (const auto &shortcut: shortcuts) { + ImGui::TableNextRow(); + ImGui::TableNextColumn(); + ImGui::TextUnformatted(UIUtil::GetKeyChordName(shortcut.keyChord).c_str()); + ImGui::TableNextColumn(); + if (ImGui::Selectable(shortcut.name.c_str(), false, ImGuiSelectableFlags_SpanAllColumns)) { + shortcut.callback(); + ImGui::CloseCurrentPopup(); + } + } + ImGui::EndTable(); + } + ImGui::EndPopup(); + } + } +} diff --git a/src/editor/dock-spaces/footer/EditorFooterPanel.h b/src/editor/dock-spaces/footer/EditorFooterPanel.h new file mode 100644 index 00000000..257b12bd --- /dev/null +++ b/src/editor/dock-spaces/footer/EditorFooterPanel.h @@ -0,0 +1,16 @@ +#ifndef METAL_ENGINE_EDITORFOOTERPANEL_H +#define METAL_ENGINE_EDITORFOOTERPANEL_H + +#include "../../abstract/AbstractPanel.h" + +namespace Metal { + class EditorFooterPanel final : public AbstractPanel { + void renderShortcuts(); + static void framerate(); + + public: + void onSync() override; + }; +} + +#endif diff --git a/src/editor/dock-spaces/header/AsyncTaskPanel.cpp b/src/editor/dock-spaces/header/AsyncTaskPanel.cpp index 2cc626c5..fba2a231 100644 --- a/src/editor/dock-spaces/header/AsyncTaskPanel.cpp +++ b/src/editor/dock-spaces/header/AsyncTaskPanel.cpp @@ -5,7 +5,7 @@ namespace Metal { void AsyncTaskPanel::onSync() { - auto tasks = CTX.asyncTaskService.getActiveTasks(); + auto tasks = applicationContext->asyncTaskService.getActiveTasks(); if (tasks.empty()) { UIUtil::DynamicSpacing(90); return; @@ -56,7 +56,7 @@ namespace Metal { ImGui::SameLine(); if (ImGui::Button((Icons::close + "##" + task->id).c_str(), ImVec2(UIUtil::ONLY_ICON_BUTTON_SIZE, UIUtil::ONLY_ICON_BUTTON_SIZE))) { - CTX.asyncTaskService.endTask(task->id, true); + applicationContext->asyncTaskService.endTask(task->id, true); } ImGui::EndGroup(); } diff --git a/src/editor/dock-spaces/header/EditorHeaderPanel.cpp b/src/editor/dock-spaces/header/EditorHeaderPanel.cpp index b2b577a5..5c5fac77 100644 --- a/src/editor/dock-spaces/header/EditorHeaderPanel.cpp +++ b/src/editor/dock-spaces/header/EditorHeaderPanel.cpp @@ -9,25 +9,55 @@ namespace Metal { ImGui::Dummy(ImVec2(0, UIUtil::ONLY_ICON_BUTTON_SIZE)); ImGui::Dummy(ImVec2(2, 0)); ImGui::Separator(); + + // Window dragging logic + if (ImGui::IsWindowHovered() && ImGui::IsMouseDragging(ImGuiMouseButton_Left)) { + ImVec2 delta = ImGui::GetIO().MouseDelta; + GLFWwindow* window = applicationContext->glfwContext.getWindow(); + int x, y; + glfwGetWindowPos(window, &x, &y); + glfwSetWindowPos(window, x + (int)delta.x, y + (int)delta.y); + } } - void EditorHeaderPanel::onInitialize() { - appendChild(asyncTask = new AsyncTaskPanel()); + void EditorHeaderPanel::renderWindowControls() { + ImGui::SameLine(ImGui::GetWindowWidth() - (UIUtil::ONLY_ICON_BUTTON_SIZE * 3 + 10)); + + GLFWwindow* window = applicationContext->glfwContext.getWindow(); + + if (UIUtil::ButtonSimple(Icons::minimize, UIUtil::ONLY_ICON_BUTTON_SIZE, UIUtil::ONLY_ICON_BUTTON_SIZE)) { + glfwIconifyWindow(window); + } + ImGui::SameLine(); + + bool isMaximized = glfwGetWindowAttrib(window, GLFW_MAXIMIZED); + if (UIUtil::ButtonSimple(isMaximized ? Icons::filter_none : Icons::crop_square, UIUtil::ONLY_ICON_BUTTON_SIZE, UIUtil::ONLY_ICON_BUTTON_SIZE)) { + if (isMaximized) { + glfwRestoreWindow(window); + } else { + glfwMaximizeWindow(window); + } + } + ImGui::SameLine(); + + if (UIUtil::ButtonSimple(Icons::close, UIUtil::ONLY_ICON_BUTTON_SIZE, UIUtil::ONLY_ICON_BUTTON_SIZE)) { + glfwSetWindowShouldClose(window, GLFW_TRUE); + } } void EditorHeaderPanel::renderFileTab() { if (ImGui::BeginMainMenuBar()) { if (UIUtil::ButtonSimple(Icons::save, UIUtil::ONLY_ICON_BUTTON_SIZE, UIUtil::ONLY_ICON_BUTTON_SIZE)) { - CTX.save(); + applicationContext->save(); } ImGui::SameLine(); if (ImGui::BeginMenu("File")) { if (ImGui::MenuItem("Open", "Ctrl+O")) { - CTX.engineContext.dispose(); - CTX.updateRootPath(true); + applicationContext->engineContext.dispose(); + applicationContext->updateRootPath(true); } if (ImGui::MenuItem("Save", "Ctrl+S")) { - CTX.save(); + applicationContext->save(); } ImGui::Separator(); if (ImGui::MenuItem("Exit")) { @@ -39,67 +69,23 @@ namespace Metal { // Create an "Edit" menu if (ImGui::BeginMenu("Edit")) { if (ImGui::MenuItem("Compile shaders")) { - CTX.engineContext.dispose(); + applicationContext->engineContext.dispose(); // TODO - CREATE NEW FRAME } ImGui::EndMenu(); } UIUtil::LargeSpacing(); - renderShortcuts(); - UIUtil::Spacing(); asyncTask->onSync(); - framerate(); + renderWindowControls(); ImGui::EndMainMenuBar(); } } - void EditorHeaderPanel::framerate() { - const int framerate = static_cast(round(ImGui::GetIO().Framerate)); - if (framerate > 0) { - ImGui::Text("%i ms | %i fps", 1000 / framerate, framerate); - } - } - - void EditorHeaderPanel::renderShortcuts() { - auto &shortcuts = CTX.editorRepository.focusedShortcuts; - if (shortcuts.empty()) return; - ImGui::Text(CTX.editorRepository.focusedWindowName.c_str()); - ImGui::SameLine(); - std::string label; - for (size_t i = 0; i < std::min(shortcuts.size(), size_t(3)); ++i) { - if (i > 0) label += " | "; - label += UIUtil::GetKeyChordName(shortcuts[i].keyChord); - } - - if (ImGui::Button(label.c_str())) { - ImGui::OpenPopup("AllShortcutsPopup"); - } - - if (ImGui::BeginPopup("AllShortcutsPopup")) { - if (ImGui::BeginTable("ShortcutsTable", 2, - ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg | - ImGuiTableFlags_SizingStretchProp)) { - ImGui::TableSetupColumn("Key"); - ImGui::TableSetupColumn("Action"); - ImGui::TableHeadersRow(); - - for (const auto &shortcut: shortcuts) { - ImGui::TableNextRow(); - ImGui::TableNextColumn(); - ImGui::TextUnformatted(UIUtil::GetKeyChordName(shortcut.keyChord).c_str()); - ImGui::TableNextColumn(); - if (ImGui::Selectable(shortcut.name.c_str(), false, ImGuiSelectableFlags_SpanAllColumns)) { - shortcut.callback(); - ImGui::CloseCurrentPopup(); - } - } - ImGui::EndTable(); - } - ImGui::EndPopup(); - } + void EditorHeaderPanel::onInitialize() { + appendChild(asyncTask = new AsyncTaskPanel()); } } diff --git a/src/editor/dock-spaces/header/EditorHeaderPanel.h b/src/editor/dock-spaces/header/EditorHeaderPanel.h index 897cae94..75f2f184 100644 --- a/src/editor/dock-spaces/header/EditorHeaderPanel.h +++ b/src/editor/dock-spaces/header/EditorHeaderPanel.h @@ -9,9 +9,7 @@ namespace Metal { void renderFileTab(); - void renderShortcuts(); - - static void framerate(); + void renderWindowControls(); public: void onInitialize() override; diff --git a/src/editor/dock-spaces/inspector/InspectorPanel.cpp b/src/editor/dock-spaces/inspector/InspectorPanel.cpp index a3c02608..bee24e34 100644 --- a/src/editor/dock-spaces/inspector/InspectorPanel.cpp +++ b/src/editor/dock-spaces/inspector/InspectorPanel.cpp @@ -26,11 +26,11 @@ namespace Metal { if (ImGui::BeginPopup((id + "AddComponentPopup").c_str())) { for (const auto &compDef: ComponentTypes::getComponents()) { - bool hasComponent = compDef.getInspectable(CTX.worldRepository, selectedId) != nullptr; + bool hasComponent = compDef.getInspectable(applicationContext->worldRepository, selectedId) != nullptr; if (!hasComponent) { if (ImGui::MenuItem( (compDef.icon + " " + compDef.name + id + "adCOmp" + compDef.name).c_str())) { - CTX.worldRepository.createComponent(selectedId, compDef.type); + applicationContext->worldRepository.createComponent(selectedId, compDef.type); selectedId = EMPTY_ENTITY; tick(); } @@ -42,13 +42,13 @@ namespace Metal { } void InspectorPanel::tick() { - if (auto &editorRepository = CTX.editorRepository; + if (auto &editorRepository = applicationContext->editorRepository; editorRepository.mainSelection != selectedId) { additionalInspection.clear(); selectedId = editorRepository.mainSelection; formPanel->resetForm(); if (selectedId != EMPTY_ENTITY) { - auto &repo = CTX.worldRepository; + auto &repo = applicationContext->worldRepository; selectedEntity = repo.getEntity(selectedId); if (selectedEntity != nullptr) { diff --git a/src/editor/dock-spaces/metrics/MetricsPanel.cpp b/src/editor/dock-spaces/metrics/MetricsPanel.cpp index fc27f0e2..f478554a 100644 --- a/src/editor/dock-spaces/metrics/MetricsPanel.cpp +++ b/src/editor/dock-spaces/metrics/MetricsPanel.cpp @@ -22,11 +22,11 @@ namespace Metal { } void MetricsPanel::onSync() { - drawResourceList("Meshes", CTX.meshService, id); - drawResourceList("Voxels", CTX.voxelService, id); - drawResourceList("Framebuffers", CTX.framebufferService, id); - drawResourceList("Textures", CTX.textureService, id); - drawResourceList("Pipelines", CTX.pipelineService, id); - drawResourceList("Buffers", CTX.bufferService, id); + drawResourceList("Meshes", applicationContext->meshService, id); + drawResourceList("Voxels", applicationContext->voxelService, id); + drawResourceList("Framebuffers", applicationContext->framebufferService, id); + drawResourceList("Textures", applicationContext->textureService, id); + drawResourceList("Pipelines", applicationContext->pipelineService, id); + drawResourceList("Buffers", applicationContext->bufferService, id); } } diff --git a/src/editor/dock-spaces/repositories/RepositoriesPanel.cpp b/src/editor/dock-spaces/repositories/RepositoriesPanel.cpp index 70957667..fff6ec87 100644 --- a/src/editor/dock-spaces/repositories/RepositoriesPanel.cpp +++ b/src/editor/dock-spaces/repositories/RepositoriesPanel.cpp @@ -8,9 +8,9 @@ namespace Metal { formPanel = new FormPanel(); appendChild(formPanel); - repositories.push_back(&CTX.editorRepository); - repositories.push_back(&CTX.engineRepository); - repositories.push_back(&CTX.worldRepository.camera); + repositories.push_back(&applicationContext->editorRepository); + repositories.push_back(&applicationContext->engineRepository); + repositories.push_back(&applicationContext->worldRepository.camera); } void RepositoriesPanel::onSync() { diff --git a/src/editor/dock-spaces/viewport/CameraPositionPanel.cpp b/src/editor/dock-spaces/viewport/CameraPositionPanel.cpp index 425d60cd..9af7929e 100644 --- a/src/editor/dock-spaces/viewport/CameraPositionPanel.cpp +++ b/src/editor/dock-spaces/viewport/CameraPositionPanel.cpp @@ -18,7 +18,7 @@ namespace Metal { ImGui::SetNextWindowBgAlpha(.4f); if (ImGui::Begin(id.c_str(), &UIUtil::OPEN, ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoCollapse)) { - const auto &positionCamera = CTX.worldRepository.camera.position; + const auto &positionCamera = applicationContext->worldRepository.camera.position; ImGui::TextColored(RED, "X: %i", static_cast(positionCamera.x)); ImGui::SameLine(); ImGui::TextColored(GREEN, "Y: %i", static_cast(positionCamera.y)); @@ -27,10 +27,10 @@ namespace Metal { ImGui::SameLine(); ImGui::Text( - "Yaw: %i", static_cast(CTX.worldRepository.camera.yaw * TO_DEG)); + "Yaw: %i", static_cast(applicationContext->worldRepository.camera.yaw * TO_DEG)); ImGui::SameLine(); ImGui::Text("Pitch: %i", - static_cast(CTX.worldRepository.camera.pitch * TO_DEG)); + static_cast(applicationContext->worldRepository.camera.pitch * TO_DEG)); } ImGui::PopStyleVar(); ImGui::End(); diff --git a/src/editor/dock-spaces/viewport/EngineFramePanel.cpp b/src/editor/dock-spaces/viewport/EngineFramePanel.cpp index 5ba17e43..bae6fdde 100644 --- a/src/editor/dock-spaces/viewport/EngineFramePanel.cpp +++ b/src/editor/dock-spaces/viewport/EngineFramePanel.cpp @@ -17,8 +17,8 @@ namespace Metal { void EngineFramePanel::onInitialize() { - const auto gBufferW = CTX.vulkanContext.getWindowWidth() / CTX.engineRepository.shadingResInvScale; - const auto gBufferH = CTX.vulkanContext.getWindowHeight() / CTX.engineRepository.shadingResInvScale; + const auto gBufferW = applicationContext->vulkanContext.getWindowWidth() / applicationContext->engineRepository.shadingResInvScale; + const auto gBufferH = applicationContext->vulkanContext.getWindowHeight() / applicationContext->engineRepository.shadingResInvScale; engineFrame = EngineFrameBuilder() .addBuffer(RID_GLOBAL_DATA, sizeof(GlobalDataUBO), @@ -55,7 +55,7 @@ namespace Metal { .addPass(ICONS, RID_POST_PROCESSING_CB) .build(); - CTX.engineContext.registerFrame(engineFrame.get()); + applicationContext->engineContext.registerFrame(engineFrame.get()); } void EngineFramePanel::onSync() { @@ -64,7 +64,7 @@ namespace Metal { auto *framebuffer = engineFrame->getResourceAs(RID_POST_PROCESSING_FBO); if (framebuffer) { - CTX.descriptorSetService.setImageDescriptor(framebuffer, 0); + applicationContext->descriptorSetService.setImageDescriptor(framebuffer, 0); ImGui::Image(reinterpret_cast(framebuffer->attachments[0]->imageDescriptor->vkDescriptorSet), viewportSize); @@ -105,8 +105,8 @@ namespace Metal { const uint32_t pixelX = std::min(static_cast(u * static_cast(width)), width - 1); const uint32_t pixelY = std::min(static_cast(v * static_cast(height)), height - 1); - const auto picked = CTX.pickingService.pickEntityFromGBuffer(gBufferPositionIndex, pixelX, pixelY); - CTX.selectionService.clearSelection(); - CTX.selectionService.addSelected(picked.value_or(EMPTY_ENTITY)); + const auto picked = applicationContext->pickingService.pickEntityFromGBuffer(gBufferPositionIndex, pixelX, pixelY); + applicationContext->selectionService.clearSelection(); + applicationContext->selectionService.addSelected(picked.value_or(EMPTY_ENTITY)); } } // Metal diff --git a/src/editor/dock-spaces/viewport/GizmoPanel.cpp b/src/editor/dock-spaces/viewport/GizmoPanel.cpp index 501340c3..aed80e22 100644 --- a/src/editor/dock-spaces/viewport/GizmoPanel.cpp +++ b/src/editor/dock-spaces/viewport/GizmoPanel.cpp @@ -13,7 +13,7 @@ namespace Metal { } void GizmoPanel::onInitialize() { - editorRepository = &CTX.editorRepository; + editorRepository = &applicationContext->editorRepository; } void GizmoPanel::onSync() { @@ -22,7 +22,7 @@ namespace Metal { localSelected = nullptr; localChangeId = 0; if (editorRepository->mainSelection != EMPTY_ENTITY) { - CTX.selectionService.updatePrimitiveSelected(); + applicationContext->selectionService.updatePrimitiveSelected(); } return; } @@ -40,7 +40,7 @@ namespace Metal { } recomposeMatrix(); - ImGuizmo::SetOrthographic(CTX.worldRepository.camera.isOrthographic); + ImGuizmo::SetOrthographic(applicationContext->worldRepository.camera.isOrthographic); ImGuizmo::SetDrawlist(); ImVec2 viewportMin = ImGui::GetItemRectMin(); ImVec2 viewportSize = ImGui::GetItemRectSize(); @@ -113,8 +113,8 @@ namespace Metal { } void GizmoPanel::recomposeMatrix() { - viewMatrixCache = glm::value_ptr(CTX.worldRepository.camera.viewMatrix); - cacheProjection = CTX.worldRepository.camera.projectionMatrix; + viewMatrixCache = glm::value_ptr(applicationContext->worldRepository.camera.viewMatrix); + cacheProjection = applicationContext->worldRepository.camera.projectionMatrix; cacheProjection[1][1] *= -1; diff --git a/src/editor/dock-spaces/viewport/GizmoSettingsPanel.cpp b/src/editor/dock-spaces/viewport/GizmoSettingsPanel.cpp index 75632216..1a3e1c07 100644 --- a/src/editor/dock-spaces/viewport/GizmoSettingsPanel.cpp +++ b/src/editor/dock-spaces/viewport/GizmoSettingsPanel.cpp @@ -5,7 +5,7 @@ namespace Metal { void GizmoSettingsPanel::onInitialize() { - editorRepository = &CTX.editorRepository; + editorRepository = &applicationContext->editorRepository; } void GizmoSettingsPanel::onSync() { @@ -15,9 +15,9 @@ namespace Metal { ImGui::SameLine(); gizmoGrid(); UIUtil::Spacing(); - if (selectedEntityId != editorRepository->mainSelection && CTX.worldRepository.registry.all_of( + if (selectedEntityId != editorRepository->mainSelection && applicationContext->worldRepository.registry.all_of( editorRepository->mainSelection)) { - selectedEntity = CTX.worldRepository.getEntity(editorRepository->mainSelection); + selectedEntity = applicationContext->worldRepository.getEntity(editorRepository->mainSelection); selectedEntityId = editorRepository->mainSelection; } if (selectedEntity != nullptr) { diff --git a/src/editor/dock-spaces/viewport/ViewportHeaderPanel.cpp b/src/editor/dock-spaces/viewport/ViewportHeaderPanel.cpp index d4dbbafe..5c4d99f9 100644 --- a/src/editor/dock-spaces/viewport/ViewportHeaderPanel.cpp +++ b/src/editor/dock-spaces/viewport/ViewportHeaderPanel.cpp @@ -33,8 +33,8 @@ namespace Metal { if (UIUtil::ButtonSimple(Icons::center_focus_strong + id + "centerCamera", UIUtil::ONLY_ICON_BUTTON_SIZE, UIUtil::ONLY_ICON_BUTTON_SIZE)) { - CTX.worldRepository.camera.position = {0, 0, 0}; - CTX.worldRepository.camera.registerChange(); + applicationContext->worldRepository.camera.position = {0, 0, 0}; + applicationContext->worldRepository.camera.registerChange(); } UIUtil::RenderTooltip("Center camera?"); @@ -44,19 +44,19 @@ namespace Metal { static float speedValues[] = {0.1f, 0.5f, 1.0f, 2.0f, 5.0f, 10.0f}; int currentSpeedIndex = 2; for (int i = 0; i < 6; i++) { - if (CTX.worldRepository.camera.movementSensitivity == speedValues[i]) { + if (applicationContext->worldRepository.camera.movementSensitivity == speedValues[i]) { currentSpeedIndex = i; break; } } if (ImGui::Combo((id + "speedCamera").c_str(), ¤tSpeedIndex, speeds, IM_ARRAYSIZE(speeds))) { - CTX.worldRepository.camera.movementSensitivity = speedValues[currentSpeedIndex]; + applicationContext->worldRepository.camera.movementSensitivity = speedValues[currentSpeedIndex]; } UIUtil::RenderTooltip("Camera speed"); } void ViewportHeaderPanel::shadingMode() { - auto &editorRepository = CTX.editorRepository; + auto &editorRepository = applicationContext->editorRepository; ImGui::SetNextItemWidth(150); shadingModelOption = ShadingModes::IndexOfValue(editorRepository.shadingMode); diff --git a/src/editor/dock-spaces/viewport/ViewportPanel.cpp b/src/editor/dock-spaces/viewport/ViewportPanel.cpp index d923b9ae..8d7e4807 100644 --- a/src/editor/dock-spaces/viewport/ViewportPanel.cpp +++ b/src/editor/dock-spaces/viewport/ViewportPanel.cpp @@ -18,40 +18,40 @@ namespace Metal { appendChild(cameraPanel = new CameraPositionPanel()); shortcuts = { - ShortcutDTO("Change shading mode", ImGuiKey_Q, []() { - CTX.editorRepository.shadingMode = ShadingModes::ValueOfIndex( - ShadingModes::IndexOfValue(CTX.editorRepository.shadingMode) + 1); + ShortcutDTO("Change shading mode", ImGuiKey_Q, [this]() { + applicationContext->editorRepository.shadingMode = ShadingModes::ValueOfIndex( + ShadingModes::IndexOfValue(applicationContext->editorRepository.shadingMode) + 1); }), - ShortcutDTO("Translate", ImGuiKey_1, []() { - CTX.editorRepository.gizmoType = ImGuizmo::OPERATION::TRANSLATE; + ShortcutDTO("Translate", ImGuiKey_1, [this]() { + applicationContext->editorRepository.gizmoType = ImGuizmo::OPERATION::TRANSLATE; }), - ShortcutDTO("Scale", ImGuiKey_2, []() { - CTX.editorRepository.gizmoType = ImGuizmo::OPERATION::SCALE; + ShortcutDTO("Scale", ImGuiKey_2, [this]() { + applicationContext->editorRepository.gizmoType = ImGuizmo::OPERATION::SCALE; }), - ShortcutDTO("Rotate", ImGuiKey_3, []() { - CTX.editorRepository.gizmoType = ImGuizmo::OPERATION::ROTATE; + ShortcutDTO("Rotate", ImGuiKey_3, [this]() { + applicationContext->editorRepository.gizmoType = ImGuizmo::OPERATION::ROTATE; }), ShortcutDTO("Delete", ImGuiKey_Delete, [this]() { std::vector entities; - for (auto &entry: CTX.editorRepository.selected) { + for (auto &entry: applicationContext->editorRepository.selected) { entities.push_back(entry.first); } - CTX.worldRepository.deleteEntities(entities); - CTX.selectionService.clearSelection(); + applicationContext->worldRepository.deleteEntities(entities); + applicationContext->selectionService.clearSelection(); }), ShortcutDTO("Select All", ImGuiMod_Ctrl | ImGuiKey_A, [this]() { std::vector entities; - auto &storage = CTX.worldRepository.registry.storage(); + auto &storage = applicationContext->worldRepository.registry.storage(); for (auto it = storage.begin(); it != storage.end(); ++it) { auto entity = *it; - if (CTX.worldRepository.registry.all_of(entity)) { + if (applicationContext->worldRepository.registry.all_of(entity)) { entities.push_back(entity); } } - CTX.selectionService.addAllSelected(entities); + applicationContext->selectionService.addAllSelected(entities); }), - ShortcutDTO("Save", ImGuiMod_Ctrl | ImGuiKey_S, [] { - CTX.save(); + ShortcutDTO("Save", ImGuiMod_Ctrl | ImGuiKey_S, [this] { + applicationContext->save(); }) }; } @@ -68,13 +68,13 @@ namespace Metal { } void ViewportPanel::updateCamera() { - auto &worldRepository = CTX.worldRepository; - const auto &cameraService = CTX.cameraService; + auto &worldRepository = applicationContext->worldRepository; + const auto &cameraService = applicationContext->cameraService; if (ImGui::IsWindowHovered() && !ImGuizmo::IsUsing() && ImGui::IsMouseDown(ImGuiMouseButton_Right)) { cameraService.handleInput(isFirstMovement); if (const auto &io = ImGui::GetIO(); io.MouseWheel != 0) { - worldRepository.camera.movementSensitivity += io.MouseWheel * 100 * CTX. + worldRepository.camera.movementSensitivity += io.MouseWheel * 100 * applicationContext-> engineContext.deltaTime; worldRepository.camera.movementSensitivity = std::max(.1f, worldRepository.camera.movementSensitivity); @@ -86,7 +86,7 @@ namespace Metal { } void ViewportPanel::updateInputs() const { - auto &repo = CTX.runtimeRepository; + auto &repo = applicationContext->runtimeRepository; const ImVec2 windowSize = ImGui::GetWindowSize(); size->x = windowSize.x; size->y = windowSize.y; diff --git a/src/editor/dock-spaces/world/WorldHeaderPanel.cpp b/src/editor/dock-spaces/world/WorldHeaderPanel.cpp index 8aea7de6..f263fb2c 100644 --- a/src/editor/dock-spaces/world/WorldHeaderPanel.cpp +++ b/src/editor/dock-spaces/world/WorldHeaderPanel.cpp @@ -28,7 +28,7 @@ namespace Metal { ImGui::SameLine(); if (UIUtil::ButtonSimple(Icons::add + "##hierarchyAdd" + id, UIUtil::ONLY_ICON_BUTTON_SIZE, UIUtil::ONLY_ICON_BUTTON_SIZE)) { - CTX.worldRepository.createEntity(); + applicationContext->worldRepository.createEntity(); } UIUtil::RenderTooltip("Create entity"); } diff --git a/src/editor/dock-spaces/world/WorldPanel.cpp b/src/editor/dock-spaces/world/WorldPanel.cpp index c7cd1842..dfa7c336 100644 --- a/src/editor/dock-spaces/world/WorldPanel.cpp +++ b/src/editor/dock-spaces/world/WorldPanel.cpp @@ -10,17 +10,17 @@ namespace Metal { void WorldPanel::onInitialize() { appendChild(headerPanel = new WorldHeaderPanel()); - world = &CTX.worldRepository; - editorRepository = &CTX.editorRepository; + world = &applicationContext->worldRepository; + editorRepository = &applicationContext->editorRepository; shortcuts = { ShortcutDTO("Delete", ImGuiKey_Delete, [this]() { std::vector entities; - for (auto &entry: CTX.editorRepository.selected) { + for (auto &entry: applicationContext->editorRepository.selected) { entities.push_back(entry.first); } - CTX.worldRepository.deleteEntities(entities); - CTX.selectionService.clearSelection(); + applicationContext->worldRepository.deleteEntities(entities); + applicationContext->selectionService.clearSelection(); }), ShortcutDTO("Select All", ImGuiMod_Ctrl | ImGuiKey_A, [this]() { std::vector entities; @@ -29,10 +29,10 @@ namespace Metal { entities.push_back(entity); } } - CTX.selectionService.addAllSelected(entities); + applicationContext->selectionService.addAllSelected(entities); }), - ShortcutDTO("Save", ImGuiMod_Ctrl | ImGuiKey_S, [] { - CTX.save(); + ShortcutDTO("Save", ImGuiMod_Ctrl | ImGuiKey_S, [this] { + applicationContext->save(); }), }; } @@ -41,11 +41,11 @@ namespace Metal { if (ImGui::BeginPopupContextItem((id + "contextMenu").c_str())) { if (ImGui::MenuItem("Delete")) { std::vector entities; - for (auto &entry: CTX.editorRepository.selected) { + for (auto &entry: applicationContext->editorRepository.selected) { entities.push_back(entry.first); } - CTX.worldRepository.deleteEntities(entities); - CTX.selectionService.clearSelection(); + applicationContext->worldRepository.deleteEntities(entities); + applicationContext->selectionService.clearSelection(); } ImGui::EndPopup(); } @@ -73,7 +73,7 @@ namespace Metal { ImGui::EndTable(); } - if (!CTX.editorRepository.selected.empty()) { + if (!applicationContext->editorRepository.selected.empty()) { contextMenu(); } } @@ -172,7 +172,7 @@ namespace Metal { const bool isVisible = !world->hiddenEntities.contains(entityId); if (UIUtil::ButtonSimple((isVisible ? Icons::visibility : Icons::visibility_off) + ("##v") + std::to_string(static_cast(entt::to_integral(entityId))) + id, 20, 15)) { - CTX.worldRepository.changeVisibility(entityId, !isVisible); + applicationContext->worldRepository.changeVisibility(entityId, !isVisible); } ImGui::PopStyleColor(); ImGui::PopStyleVar(2); @@ -182,9 +182,9 @@ namespace Metal { void WorldPanel::handleClick(const entt::entity entityId) const { if (ImGui::IsItemClicked()) { if (const bool isMultiSelect = ImGui::IsKeyDown(ImGuiKey_LeftCtrl); !isMultiSelect) { - CTX.selectionService.clearSelection(); + applicationContext->selectionService.clearSelection(); } - CTX.selectionService.addSelected(entityId); + applicationContext->selectionService.addSelected(entityId); } } diff --git a/src/editor/panel/FileImportModalPanel.cpp b/src/editor/panel/FileImportModalPanel.cpp index 0f002400..46941806 100644 --- a/src/editor/panel/FileImportModalPanel.cpp +++ b/src/editor/panel/FileImportModalPanel.cpp @@ -13,7 +13,7 @@ namespace Metal { } void FileImportModalPanel::onSync() { - auto &editorRepository = CTX.editorRepository; + auto &editorRepository = applicationContext->editorRepository; if (editorRepository.pendingImports.empty()) { isFirst = true; return; @@ -91,10 +91,10 @@ namespace Metal { if (ImGui::Button(("Approve" + id + "approveImport").c_str(), ImVec2(120, 0))) { for (const std::string &file: editorRepository.pendingImports) { - CTX.fileImporterService.importFile(editorRepository.targetImportDirectory->absolutePath, file, + applicationContext->fileImporterService.importFile(editorRepository.targetImportDirectory->absolutePath, file, editorRepository.importSettingsMap.at(file)); } - CTX.notificationService.pushMessage("Importing files...", NotificationSeverities::WARNING); + applicationContext->notificationService.pushMessage("Importing files...", NotificationSeverities::WARNING); FilesService::GetEntries(editorRepository.targetImportDirectory); editorRepository.pendingImports.clear(); editorRepository.importSettingsMap.clear(); diff --git a/src/editor/panel/NotificationsPanel.cpp b/src/editor/panel/NotificationsPanel.cpp index 873b0491..6b5c8dc0 100644 --- a/src/editor/panel/NotificationsPanel.cpp +++ b/src/editor/panel/NotificationsPanel.cpp @@ -7,17 +7,17 @@ namespace Metal { void NotificationsPanel::onSync() { int usedIndices = 0; - for (int i = 0; i < CTX.notificationService.getNotifications().size(); i++) { - auto *notification = CTX.notificationService.getNotifications()[i]; + for (int i = 0; i < applicationContext->notificationService.getNotifications().size(); i++) { + auto *notification = applicationContext->notificationService.getNotifications()[i]; if (notification == nullptr) { continue; } if (notification->displayTime < 0) { - notification->displayTime = CTX.engineContext.currentTimeMs; + notification->displayTime = applicationContext->engineContext.currentTimeMs; } - if (CTX.engineContext.currentTimeMs - notification->displayTime > MESSAGE_DURATION) { + if (applicationContext->engineContext.currentTimeMs - notification->displayTime > MESSAGE_DURATION) { delete notification; - CTX.notificationService.getNotifications()[i] = nullptr; + applicationContext->notificationService.getNotifications()[i] = nullptr; continue; } ImGui::SetNextWindowPos(ImVec2(5, ImGui::GetMainViewport()->Size.y - 40 * (usedIndices + 1))); diff --git a/src/editor/service/FileImporterService.cpp b/src/editor/service/FileImporterService.cpp index 09e8f104..2131cd1f 100644 --- a/src/editor/service/FileImporterService.cpp +++ b/src/editor/service/FileImporterService.cpp @@ -1,6 +1,9 @@ #include "FileImporterService.h" - -#include "../../ApplicationContext.h" +#include "SceneImporterService.h" +#include "TextureImporterService.h" +#include "VoxelImporterService.h" +#include "NotificationService.h" +#include "AsyncTaskService.h" #include "LogService.h" #include @@ -11,30 +14,30 @@ namespace Metal { const std::shared_ptr &settings) { std::string fileName = file.substr(file.find_last_of(std::filesystem::path::preferred_separator) + 1); runAsync("Import file: " + fileName, - [targetDir, file, fileName, settings](const std::stop_token &token) { + [this, targetDir, file, fileName, settings](const std::stop_token &token) { try { LOG_INFO("Starting file processing: " + fileName); - if (CTX.sceneImporterService.isCompatible(file)) { - CTX.sceneImporterService.importData(targetDir, + if (sceneImporterService.isCompatible(file)) { + sceneImporterService.importData(targetDir, file, settings, token); - } else if (CTX.textureImporter.isCompatible(file)) { - CTX.textureImporter.importData(targetDir, file, settings, token); - } else if (CTX.voxelImporterService.isCompatible(file)) { - CTX.voxelImporterService.importData(targetDir, file, settings, token); + } else if (textureImporterService.isCompatible(file)) { + textureImporterService.importData(targetDir, file, settings, token); + } else if (voxelImporterService.isCompatible(file)) { + voxelImporterService.importData(targetDir, file, settings, token); } LOG_INFO("Successfully imported file: " + fileName); - CTX.notificationService.pushMessage("Successfully imported file: " + fileName, + notificationService.pushMessage("Successfully imported file: " + fileName, NotificationSeverities::SUCCESS); } catch (std::exception &e) { - CTX.notificationService.pushMessage(e.what(), NotificationSeverities::ERROR); + notificationService.pushMessage(e.what(), NotificationSeverities::ERROR); } }); } std::string FileImporterService::runAsync(const std::string &taskName, const LoadingTask &task) const { std::stop_source stopSource; - std::string taskId = CTX.asyncTaskService.registerTask(taskName, [stopSource]() mutable { + std::string taskId = asyncTaskService.registerTask(taskName, [stopSource]() mutable { stopSource.request_stop(); }); @@ -46,7 +49,7 @@ namespace Metal { } catch (...) { LOG_ERROR("Loading task failed with unknown error."); } - CTX.asyncTaskService.endTask(taskId, stopToken.stop_requested()); + asyncTaskService.endTask(taskId, stopToken.stop_requested()); }).detach(); return taskId; @@ -54,13 +57,13 @@ namespace Metal { std::string FileImporterService::collectCompatibleFiles() const { std::string outStr = ""; - for (std::string type: CTX.sceneImporterService.getSupportedTypes()) { + for (std::string type: sceneImporterService.getSupportedTypes()) { outStr += type + ","; }; - for (std::string type: CTX.textureImporter.getSupportedTypes()) { + for (std::string type: textureImporterService.getSupportedTypes()) { outStr += type + ","; }; - for (std::string type: CTX.voxelImporterService.getSupportedTypes()) { + for (std::string type: voxelImporterService.getSupportedTypes()) { outStr += type + ","; }; return outStr; diff --git a/src/editor/service/FileImporterService.h b/src/editor/service/FileImporterService.h index ee69dcb4..86b1227b 100644 --- a/src/editor/service/FileImporterService.h +++ b/src/editor/service/FileImporterService.h @@ -9,8 +9,31 @@ #include "../../common/AbstractRuntimeComponent.h" namespace Metal { + class SceneImporterService; + class TextureImporterService; + class VoxelImporterService; + class NotificationService; + class AsyncTaskService; + class FileImporterService final : public AbstractRuntimeComponent { + SceneImporterService &sceneImporterService; + TextureImporterService &textureImporterService; + VoxelImporterService &voxelImporterService; + NotificationService ¬ificationService; + AsyncTaskService &asyncTaskService; + public: + FileImporterService(SceneImporterService &sceneImporterService, + TextureImporterService &textureImporterService, + VoxelImporterService &voxelImporterService, + NotificationService ¬ificationService, + AsyncTaskService &asyncTaskService) + : sceneImporterService(sceneImporterService), + textureImporterService(textureImporterService), + voxelImporterService(voxelImporterService), + notificationService(notificationService), + asyncTaskService(asyncTaskService) { + } using LoadingTask = std::function; diff --git a/src/editor/service/FilesService.cpp b/src/editor/service/FilesService.cpp index fd0bf822..90e59a05 100644 --- a/src/editor/service/FilesService.cpp +++ b/src/editor/service/FilesService.cpp @@ -1,9 +1,9 @@ #include "FilesService.h" +#include "NotificationService.h" #include "../dto/FSEntry.h" #include "../enum/EntryType.h" #include "../enum/engine-definitions.h" #include "../util/FilesUtil.h" -#include "../../ApplicationContext.h" #include "LogService.h" #include #include @@ -14,20 +14,20 @@ namespace fs = std::filesystem; -#define DELETE_F(F)\ +#define DELETE_F(F, rootDir)\ std::filesystem::remove_all(entry.second->absolutePath);\ -std::filesystem::remove_all(CTX.getAssetDirectory() + F(entry.second->getId())); +std::filesystem::remove_all(rootDir + "/assets/" + F(entry.second->getId())); -#define DELETE_S(F)\ +#define DELETE_S(F, rootDir)\ std::filesystem::remove_all(entry.second->absolutePath);\ -std::filesystem::remove_all(CTX.getAssetDirectory() + F(entry.second->getId())); +std::filesystem::remove_all(rootDir + "/assets/" + F(entry.second->getId())); #define DATA \ std::filesystem::file_time_type ftime = last_write_time(entry); namespace Metal { void FilesService::onInitialize() { - root = new FSEntry(nullptr, CTX.getAssetRefDirectory(), ""); + root = new FSEntry(nullptr, rootDirectory + "/assets-ref/", ""); root->type = EntryType::DIRECTORY; root->name = "Files"; GetEntries(root); @@ -70,19 +70,19 @@ namespace Metal { break; } case EntryType::MESH: { - DELETE_F(FORMAT_FILE_MESH) + DELETE_F(FORMAT_FILE_MESH, rootDirectory) break; } case EntryType::TEXTURE: { - DELETE_F(FORMAT_FILE_TEXTURE) + DELETE_F(FORMAT_FILE_TEXTURE, rootDirectory) break; } case EntryType::SCENE: { - DELETE_S(FORMAT_FILE_SCENE) + DELETE_S(FORMAT_FILE_SCENE, rootDirectory) break; } case EntryType::VOLUME: { - DELETE_S(FORMAT_FILE_VOLUME) + DELETE_S(FORMAT_FILE_VOLUME, rootDirectory) break; } default: break;; @@ -116,7 +116,7 @@ namespace Metal { fs::rename(sourcePath, targetPath); } catch (const fs::filesystem_error &e) { LOG_ERROR("Could not move file"); - CTX.notificationService.pushMessage("Could not move entry", NotificationSeverities::ERROR); + notificationService.pushMessage("Could not move entry", NotificationSeverities::ERROR); return; } diff --git a/src/editor/service/FilesService.h b/src/editor/service/FilesService.h index c2906941..62fe176d 100644 --- a/src/editor/service/FilesService.h +++ b/src/editor/service/FilesService.h @@ -9,12 +9,16 @@ namespace Metal { struct FSEntry; + class NotificationService; + class FilesService final : public AbstractRuntimeComponent { FSEntry *root = nullptr; + std::string &rootDirectory; + NotificationService ¬ificationService; public: - explicit FilesService() - : AbstractRuntimeComponent() { + explicit FilesService(std::string &rootDirectory, NotificationService ¬ificationService) + : AbstractRuntimeComponent(), rootDirectory(rootDirectory), notificationService(notificationService) { } FSEntry *getRoot() { diff --git a/src/editor/service/LogService.cpp b/src/editor/service/LogService.cpp index 28cf54e1..c0d5cb41 100644 --- a/src/editor/service/LogService.cpp +++ b/src/editor/service/LogService.cpp @@ -4,12 +4,12 @@ #include #include -namespace Metal { +namespace Metal::LogService { - LogService::LogService() : AbstractRuntimeComponent() { - } + static std::vector entries; + static std::mutex logMutex; - void LogService::log(LogLevel level, const std::string &message) const { + void log(LogLevel level, const std::string &message) { auto now = std::chrono::system_clock::now(); auto in_time_t = std::chrono::system_clock::to_time_t(now); @@ -25,17 +25,17 @@ namespace Metal { std::cout << "[" << timestamp << "] [" << getLevelName(level) << "] " << message << std::endl; } - std::vector LogService::getEntriesSnapshot() const { + std::vector getEntriesSnapshot() { std::lock_guard lock(logMutex); return entries; } - void LogService::clear() { + void clear() { std::lock_guard lock(logMutex); entries.clear(); } - const char* LogService::getLevelName(LogLevel level) { + const char* getLevelName(LogLevel level) { switch (level) { case LogLevel::Trace: return "TRACE"; case LogLevel::Debug: return "DEBUG"; @@ -47,7 +47,7 @@ namespace Metal { } } - uint32_t LogService::getLevelColor(LogLevel level) { + uint32_t getLevelColor(LogLevel level) { switch (level) { case LogLevel::Trace: return 0xFF888888; // Grey case LogLevel::Debug: return 0xFFAAAAAA; // Light Grey diff --git a/src/editor/service/LogService.h b/src/editor/service/LogService.h index 94254087..756e30c4 100644 --- a/src/editor/service/LogService.h +++ b/src/editor/service/LogService.h @@ -23,30 +23,23 @@ namespace Metal { std::string timestamp; }; - class LogService : public AbstractRuntimeComponent { - public: - explicit LogService(); + namespace LogService { + void log(LogLevel level, const std::string &message); - void log(LogLevel level, const std::string &message) const; - - [[nodiscard]] std::vector getEntriesSnapshot() const; + [[nodiscard]] std::vector getEntriesSnapshot(); void clear(); - static const char* getLevelName(LogLevel level); - static uint32_t getLevelColor(LogLevel level); - - private: - mutable std::vector entries; - mutable std::mutex logMutex; - }; + const char* getLevelName(LogLevel level); + uint32_t getLevelColor(LogLevel level); + } } -#define LOG_TRACE(msg) CTX.logService.log(Metal::LogLevel::Trace, msg) -#define LOG_DEBUG(msg) CTX.logService.log(Metal::LogLevel::Debug, msg) -#define LOG_INFO(msg) CTX.logService.log(Metal::LogLevel::Info, msg) -#define LOG_WARN(msg) CTX.logService.log(Metal::LogLevel::Warn, msg) -#define LOG_ERROR(msg) CTX.logService.log(Metal::LogLevel::Error, msg) -#define LOG_FATAL(msg) CTX.logService.log(Metal::LogLevel::Fatal, msg) +#define LOG_TRACE(msg) Metal::LogService::log(Metal::LogLevel::Trace, msg) +#define LOG_DEBUG(msg) Metal::LogService::log(Metal::LogLevel::Debug, msg) +#define LOG_INFO(msg) Metal::LogService::log(Metal::LogLevel::Info, msg) +#define LOG_WARN(msg) Metal::LogService::log(Metal::LogLevel::Warn, msg) +#define LOG_ERROR(msg) Metal::LogService::log(Metal::LogLevel::Error, msg) +#define LOG_FATAL(msg) Metal::LogService::log(Metal::LogLevel::Fatal, msg) #endif diff --git a/src/editor/service/MaterialImporterService.cpp b/src/editor/service/MaterialImporterService.cpp index 1270b7fd..dbe18d97 100644 --- a/src/editor/service/MaterialImporterService.cpp +++ b/src/editor/service/MaterialImporterService.cpp @@ -1,5 +1,6 @@ #include "MaterialImporterService.h" -#include "../../ApplicationContext.h" +#include "TextureImporterService.h" +#include "LogService.h" #include "../enum/engine-definitions.h" #include "../../engine/dto/PrimitiveComponent.h" #include @@ -21,7 +22,7 @@ namespace Metal { try { const unsigned int embeddedIndex = static_cast(std::stoul(p.substr(1))); if (scene && embeddedIndex < scene->mNumTextures) { - return CTX.textureImporter.importEmbeddedTexture( + return textureImporterService.importEmbeddedTexture( targetDir, scene->mTextures[embeddedIndex], nameHint); } } catch (std::exception &e) { @@ -37,7 +38,7 @@ namespace Metal { } resolved = resolved.lexically_normal(); try { - return CTX.textureImporter.importData(targetDir, resolved.string(), nullptr, stopToken); + return textureImporterService.importData(targetDir, resolved.string(), nullptr, stopToken); } catch (std::exception &e) { LOG_ERROR("Failed to import texture " + resolved.string() + ": " + e.what()); return ""; diff --git a/src/editor/service/MaterialImporterService.h b/src/editor/service/MaterialImporterService.h index 5eb416e5..21f5a876 100644 --- a/src/editor/service/MaterialImporterService.h +++ b/src/editor/service/MaterialImporterService.h @@ -11,8 +11,17 @@ namespace Metal { struct PrimitiveComponent; + class TextureImporterService; + class MaterialImporterService final : public AbstractRuntimeComponent { + TextureImporterService &textureImporterService; + std::string &rootDirectory; + public: + MaterialImporterService(TextureImporterService &textureImporterService, std::string &rootDirectory) + : textureImporterService(textureImporterService), rootDirectory(rootDirectory) { + } + void importMaterial(const std::string &targetDir, const aiMaterial *material, const aiScene *scene, const std::string &rootDirectory, PrimitiveComponent &primitive, const std::stop_token &stopToken = {}) const; diff --git a/src/editor/service/MeshImporterService.cpp b/src/editor/service/MeshImporterService.cpp index 4dabe766..6035b5a9 100644 --- a/src/editor/service/MeshImporterService.cpp +++ b/src/editor/service/MeshImporterService.cpp @@ -1,10 +1,10 @@ #include "MeshImporterService.h" +#include "LogService.h" #include "../../engine/dto/MeshData.h" #include "../../engine/dto/VertexData.h" #include "../dto/EntryMetadata.h" #include "../enum/engine-definitions.h" #include "../util/FilesUtil.h" -#include "../../ApplicationContext.h" #include #include "../../common/serialization-definitions.h" @@ -17,7 +17,7 @@ namespace Metal { metadata.name = metadata.name.substr(0, metadata.name.find_last_of('.')); } - std::string lod0Path = CTX.getAssetDirectory() + FORMAT_FILE_MESH(metadata.getId()); + std::string lod0Path = rootDirectory + "/assets/" + FORMAT_FILE_MESH(metadata.getId()); { std::ofstream output(lod0Path, std::ios::binary); cereal::BinaryOutputArchive archive(output); diff --git a/src/editor/service/MeshImporterService.h b/src/editor/service/MeshImporterService.h index 5d522770..82bea5e6 100644 --- a/src/editor/service/MeshImporterService.h +++ b/src/editor/service/MeshImporterService.h @@ -16,7 +16,12 @@ namespace Metal { struct MeshData; class MeshImporterService final : public AbstractRuntimeComponent { + std::string &rootDirectory; + public: + explicit MeshImporterService(std::string &rootDirectory) + : rootDirectory(rootDirectory) { + } void persistAllMeshes(const std::string &targetDir, const aiScene *scene, std::unordered_map &meshMap, diff --git a/src/editor/service/PickingService.cpp b/src/editor/service/PickingService.cpp index 45c76e19..34c7c4ee 100644 --- a/src/editor/service/PickingService.cpp +++ b/src/editor/service/PickingService.cpp @@ -3,17 +3,20 @@ #include "../../engine/resource/BufferInstance.h" #include "../../engine/resource/TextureInstance.h" #include "../../ApplicationContext.h" +#include "../../core/vulkan/VulkanContext.h" +#include "../../engine/service/BufferService.h" +#include "../../engine/repository/WorldRepository.h" namespace Metal { std::optional PickingService::pickEntityFromGBuffer(TextureInstance *attachment, const uint32_t pixelX, const uint32_t pixelY) const { constexpr VkDeviceSize imageSize = 4 * sizeof(float); - auto stagingBuffer = CTX.bufferService.createBuffer("stagingBuffer", imageSize, VK_BUFFER_USAGE_TRANSFER_DST_BIT, + auto stagingBuffer = bufferService.createBuffer("stagingBuffer", imageSize, VK_BUFFER_USAGE_TRANSFER_DST_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT); - VkCommandBuffer commandBuffer = CTX.vulkanContext.beginSingleTimeCommands(); + VkCommandBuffer commandBuffer = vulkanContext.beginSingleTimeCommands(); VkImageMemoryBarrier barrier = {}; barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; @@ -35,8 +38,8 @@ namespace Metal { region.bufferImageHeight = 0; region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; region.imageSubresource.mipLevel = 0; - region.imageSubresource.baseArrayLayer = 0; - region.imageSubresource.layerCount = 1; + region.baseArrayLayer = 0; + region.layerCount = 1; region.imageOffset = {static_cast(pixelX), static_cast(pixelY), 0}; region.imageExtent = {1, 1, 1}; @@ -51,14 +54,14 @@ namespace Metal { vkCmdPipelineBarrier(commandBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 1, &barrier); - CTX.vulkanContext.endSingleTimeCommands(commandBuffer); + vulkanContext.endSingleTimeCommands(commandBuffer); void *data = nullptr; - vkMapMemory(CTX.vulkanContext.device.device, stagingBuffer->vkDeviceMemory, 0, imageSize, 0, &data); + vkMapMemory(vulkanContext.device.device, stagingBuffer->vkDeviceMemory, 0, imageSize, 0, &data); const auto *pixel = static_cast(data); const float idValue = pixel[3]; // Render index is in the A channel (index 3) - vkUnmapMemory(CTX.vulkanContext.device.device, stagingBuffer->vkDeviceMemory); - CTX.bufferService.dispose("stagingBuffer"); + vkUnmapMemory(vulkanContext.device.device, stagingBuffer->vkDeviceMemory); + bufferService.dispose("stagingBuffer"); if (idValue <= 0.0f) { return std::nullopt; @@ -66,7 +69,7 @@ namespace Metal { const unsigned int renderIndex = static_cast(idValue + 0.5f) - 1; - auto view = CTX.worldRepository.registry.view(); + auto view = worldRepository.registry.view(); for (auto entity: view) { auto &mesh = view.get(entity); if (mesh.renderIndex == renderIndex) { diff --git a/src/editor/service/PickingService.h b/src/editor/service/PickingService.h index 36ff15c0..88127897 100644 --- a/src/editor/service/PickingService.h +++ b/src/editor/service/PickingService.h @@ -7,8 +7,20 @@ namespace Metal { struct TextureInstance; + class VulkanContext; + class BufferService; + struct WorldRepository; + class PickingService final : public AbstractRuntimeComponent { + VulkanContext &vulkanContext; + BufferService &bufferService; + WorldRepository &worldRepository; + public: + PickingService(VulkanContext &vulkanContext, BufferService &bufferService, WorldRepository &worldRepository) + : vulkanContext(vulkanContext), bufferService(bufferService), worldRepository(worldRepository) {} + PickingService() = delete; + [[nodiscard]] std::optional pickEntityFromGBuffer(TextureInstance *attachment, uint32_t pixelX, uint32_t pixelY) const; }; } // Metal diff --git a/src/editor/service/SceneImporterService.cpp b/src/editor/service/SceneImporterService.cpp index d63b859c..70ef75a7 100644 --- a/src/editor/service/SceneImporterService.cpp +++ b/src/editor/service/SceneImporterService.cpp @@ -1,5 +1,7 @@ #include "SceneImporterService.h" - +#include "MeshImporterService.h" +#include "MaterialImporterService.h" +#include "LogService.h" #include "../dto/FSEntry.h" #include "../../engine/dto/MeshData.h" #include "../dto/SceneData.h" @@ -11,7 +13,6 @@ #include "../util/FilesUtil.h" #include "../dto/EntryMetadata.h" #include "../enum/engine-definitions.h" -#include "../../ApplicationContext.h" #include "../../common/serialization-definitions.h" #include "../dto/SceneImportSettingsDTO.h" @@ -49,7 +50,7 @@ namespace Metal { sceneMetadata.name = sceneData.name = scene->mName.length > 0 ? scene->mName.data : scene->mRootNode->mName.data; - std::string sceneBlobPath = CTX.getAssetDirectory() + FORMAT_FILE_SCENE(sceneMetadata.getId()); + std::string sceneBlobPath = rootDirectory + "/assets/" + FORMAT_FILE_SCENE(sceneMetadata.getId()); std::unordered_map meshMap{}; @@ -57,7 +58,7 @@ namespace Metal { throw std::runtime_error("Import cancelled"); } - CTX.meshImporterService.persistAllMeshes(targetDir, scene, meshMap, stopToken); + meshImporterService.persistAllMeshes(targetDir, scene, meshMap, stopToken); if (stopToken.stop_requested()) { throw std::runtime_error("Import cancelled"); @@ -66,7 +67,7 @@ namespace Metal { fs::path absolutePath = fs::absolute(pathToFile); std::string directoryPath = absolutePath.parent_path().string(); - ProcessNode(sceneData, scene, scene->mRootNode, targetDir, directoryPath, meshMap, stopToken); + processNode(sceneData, scene, scene->mRootNode, targetDir, directoryPath, meshMap, stopToken); ProcessLights(sceneData, scene); if (stopToken.stop_requested()) { @@ -88,10 +89,10 @@ namespace Metal { return sceneMetadata.getId(); } - void SceneImporterService::ProcessNode(SceneData &scene, const aiScene *aiScene, const aiNode *node, + void SceneImporterService::processNode(SceneData &scene, const aiScene *aiScene, const aiNode *node, const std::string &targetDir, const std::string &rootDirectory, const std::unordered_map &meshMap, - const std::stop_token &stopToken) { + const std::stop_token &stopToken) const { if (stopToken.stop_requested()) return; auto ¤tNode = scene.entities.emplace_back(); @@ -105,17 +106,17 @@ namespace Metal { currentNode.transform.rotation = {rotation.w, rotation.x, rotation.y, rotation.z}; currentNode.transform.scale = {scaling.x, scaling.y, scaling.z}; - ProcessMeshes(scene, aiScene, node, targetDir, rootDirectory, meshMap, stopToken); + processMeshes(scene, aiScene, node, targetDir, rootDirectory, meshMap, stopToken); for (unsigned int i = 0; i < node->mNumChildren; ++i) { - ProcessNode(scene, aiScene, node->mChildren[i], targetDir, rootDirectory, meshMap, stopToken); + processNode(scene, aiScene, node->mChildren[i], targetDir, rootDirectory, meshMap, stopToken); } } - void SceneImporterService::ProcessMeshes(SceneData &scene, const aiScene *aiScene, const aiNode *node, + void SceneImporterService::processMeshes(SceneData &scene, const aiScene *aiScene, const aiNode *node, const std::string &targetDir, const std::string &rootDirectory, const std::unordered_map &meshMap, - const std::stop_token &stopToken) { + const std::stop_token &stopToken) const { for (unsigned int i = 0; i < node->mNumMeshes; ++i) { if (stopToken.stop_requested()) return; unsigned int meshIndex = node->mMeshes[i]; @@ -131,7 +132,7 @@ namespace Metal { childMeshNode.entity.name = assimpMesh->mName.length > 0 ? assimpMesh->mName.data : "Mesh"; const aiMaterial *material = aiScene->mMaterials[assimpMesh->mMaterialIndex]; - CTX.materialImporterService.importMaterial(targetDir, material, aiScene, rootDirectory, + materialImporterService.importMaterial(targetDir, material, aiScene, rootDirectory, *childMeshNode.primitive, stopToken); } } diff --git a/src/editor/service/SceneImporterService.h b/src/editor/service/SceneImporterService.h index 6cec5ce0..d70496e7 100644 --- a/src/editor/service/SceneImporterService.h +++ b/src/editor/service/SceneImporterService.h @@ -13,24 +13,39 @@ namespace Metal { struct MeshData; struct SceneData; - class SceneImporterService final : public AbstractImporter { - static void ProcessNode(SceneData &scene, const aiScene *aiScene, const aiNode *node, - const std::string &targetDir, const std::string &rootDirectory, - const std::unordered_map &meshMap, - const std::stop_token &stopToken); - - static void ProcessMeshes(SceneData &scene, const aiScene *aiScene, const aiNode *node, - const std::string &targetDir, const std::string &rootDirectory, - const std::unordered_map &meshMap, - const std::stop_token &stopToken); + class MeshImporterService; + class MaterialImporterService; - static void ProcessLights(SceneData &scene, const aiScene *aiScene); + class SceneImporterService final : public AbstractImporter { + MeshImporterService &meshImporterService; + MaterialImporterService &materialImporterService; + std::string &rootDirectory; public: + SceneImporterService(MeshImporterService &meshImporterService, + MaterialImporterService &materialImporterService, + std::string &rootDirectory) + : meshImporterService(meshImporterService), + materialImporterService(materialImporterService), + rootDirectory(rootDirectory) { + } + std::string importData(const std::string &targetDir, const std::string &pathToFile, const std::shared_ptr &settings, const std::stop_token &stopToken) override; + void processNode(SceneData &scene, const aiScene *aiScene, const aiNode *node, + const std::string &targetDir, const std::string &rootDirectory, + const std::unordered_map &meshMap, + const std::stop_token &stopToken) const; + + void processMeshes(SceneData &scene, const aiScene *aiScene, const aiNode *node, + const std::string &targetDir, const std::string &rootDirectory, + const std::unordered_map &meshMap, + const std::stop_token &stopToken) const; + + static void ProcessLights(SceneData &scene, const aiScene *aiScene); + std::vector getSupportedTypes() override; }; } // Metal diff --git a/src/editor/service/SelectionService.cpp b/src/editor/service/SelectionService.cpp index 245a54ed..0105d673 100644 --- a/src/editor/service/SelectionService.cpp +++ b/src/editor/service/SelectionService.cpp @@ -1,11 +1,10 @@ #include "SelectionService.h" - -#include "../../ApplicationContext.h" +#include "../../editor/repository/EditorRepository.h" +#include "../../engine/repository/WorldRepository.h" #include "../../engine/dto/TransformComponent.h" namespace Metal { void SelectionService::addSelected(entt::entity entity) const { - auto &editorRepository = CTX.editorRepository; if (editorRepository.selected.empty() || entity == EMPTY_ENTITY) { editorRepository.mainSelection = entity; if (editorRepository.mainSelection != EMPTY_ENTITY) { @@ -18,14 +17,12 @@ namespace Metal { } void SelectionService::clearSelection() const { - auto &editorRepository = CTX.editorRepository; editorRepository.selected.clear(); editorRepository.mainSelection = EMPTY_ENTITY; editorRepository.primitiveSelected = nullptr; } void SelectionService::addAllSelected(const std::vector &all) const { - auto &editorRepository = CTX.editorRepository; editorRepository.selected.clear(); const entt::entity first = all.size() > 0 ? all[0] : EMPTY_ENTITY; editorRepository.mainSelection = first; @@ -36,16 +33,14 @@ namespace Metal { } void SelectionService::updatePrimitiveSelected() const { - auto &editorRepository = CTX.editorRepository; - auto &repo = CTX.worldRepository; const auto entityId = editorRepository.mainSelection; - if (entityId == EMPTY_ENTITY || !repo.registry.valid(entityId)) { + if (entityId == EMPTY_ENTITY || !worldRepository.registry.valid(entityId)) { return; } - if (repo.registry.all_of(entityId)) { - editorRepository.primitiveSelected = &repo.registry.get(entityId); + if (worldRepository.registry.all_of(entityId)) { + editorRepository.primitiveSelected = &worldRepository.registry.get(entityId); } } diff --git a/src/editor/service/SelectionService.h b/src/editor/service/SelectionService.h index f86db212..8916fa72 100644 --- a/src/editor/service/SelectionService.h +++ b/src/editor/service/SelectionService.h @@ -10,7 +10,14 @@ namespace Metal { struct EditorRepository; class SelectionService final : public AbstractRuntimeComponent { + EditorRepository &editorRepository; + WorldRepository &worldRepository; + public: + SelectionService(EditorRepository &editorRepository, WorldRepository &worldRepository) + : editorRepository(editorRepository), worldRepository(worldRepository) { + } + void addSelected(entt::entity entity) const; void clearSelection() const; diff --git a/src/editor/service/TextureImporterService.cpp b/src/editor/service/TextureImporterService.cpp index 61697ff1..2b5cb11d 100644 --- a/src/editor/service/TextureImporterService.cpp +++ b/src/editor/service/TextureImporterService.cpp @@ -1,4 +1,5 @@ #include "TextureImporterService.h" +#include "LogService.h" #include "../../../../dependencies/stb/stb_image.h" #include "../../../../dependencies/stb/stb_image_write.h" @@ -9,7 +10,6 @@ #include "../dto/EntryMetadata.h" #include "../enum/EntryType.h" #include "../util/FilesUtil.h" -#include "../../ApplicationContext.h" #include "../../engine/dto/TextureData.h" namespace fs = std::filesystem; @@ -103,7 +103,7 @@ namespace Metal { size_t TextureImporterService::saveImage(const std::string &fileId, const TextureData &textureData) const { - std::string texturePath = CTX.getAssetDirectory() + FORMAT_FILE_TEXTURE(fileId); + std::string texturePath = rootDirectory + "/assets/" + FORMAT_FILE_TEXTURE(fileId); if (!stbi_write_png(texturePath.c_str(), textureData.width, textureData.height, textureData.channels, textureData.data, textureData.width * textureData.channels)) { diff --git a/src/editor/service/TextureImporterService.h b/src/editor/service/TextureImporterService.h index 7357eeac..d00446b9 100644 --- a/src/editor/service/TextureImporterService.h +++ b/src/editor/service/TextureImporterService.h @@ -8,9 +8,11 @@ namespace Metal { struct TextureData; class TextureImporterService final : public AbstractImporter { + std::string &rootDirectory; + public: - explicit TextureImporterService() - : AbstractImporter() { + explicit TextureImporterService(std::string &rootDirectory) + : AbstractImporter(), rootDirectory(rootDirectory) { } std::vector getSupportedTypes() override { diff --git a/src/editor/service/VoxelImporterService.cpp b/src/editor/service/VoxelImporterService.cpp index 101fa675..7d0563db 100644 --- a/src/editor/service/VoxelImporterService.cpp +++ b/src/editor/service/VoxelImporterService.cpp @@ -3,7 +3,6 @@ #include #include "../../common/serialization-definitions.h" -#include "../../ApplicationContext.h" #include "../dto/EntryMetadata.h" #include "../enum/EntryType.h" #include "../enum/engine-definitions.h" @@ -29,7 +28,7 @@ namespace Metal { metadata.name = metadata.name.substr(0, metadata.name.find_last_of('.')); - std::string outPath = CTX.getAssetDirectory() + FORMAT_FILE_VOLUME(metadata.getId()); + std::string outPath = rootDirectory + "/assets/" + FORMAT_FILE_VOLUME(metadata.getId()); metadata.size = convertToSVO(pathToFile, outPath, stopToken); DUMP_TEMPLATE(targetDir + '/' + FORMAT_FILE_METADATA(metadata.getId()), metadata) diff --git a/src/editor/service/VoxelImporterService.h b/src/editor/service/VoxelImporterService.h index 4cee1f71..fed4a639 100644 --- a/src/editor/service/VoxelImporterService.h +++ b/src/editor/service/VoxelImporterService.h @@ -9,7 +9,11 @@ namespace Metal { struct SVOInstance; class VoxelImporterService final : public AbstractImporter { + const std::string &rootDirectory; public: + explicit VoxelImporterService(const std::string &rootDirectory) : rootDirectory(rootDirectory) {} + VoxelImporterService() = delete; + std::vector getSupportedTypes() override; size_t convertToSVO(const std::string &sourcePath, const std::string &outPath, diff --git a/src/engine/EngineContext.cpp b/src/engine/EngineContext.cpp index 744ca3ab..e97a104e 100644 --- a/src/engine/EngineContext.cpp +++ b/src/engine/EngineContext.cpp @@ -1,13 +1,21 @@ #include "EngineContext.h" +#include "service/TransformService.h" +#include "service/StreamingService.h" +#include "service/RayTracingService.h" +#include "service/CameraService.h" +#include "service/LightService.h" +#include "service/VolumeService.h" +#include "repository/WorldRepository.h" +#include "repository/EngineRepository.h" +#include "../editor/repository/EditorRepository.h" #include "../editor/enum/EngineResourceIDs.h" -#include "../ApplicationContext.h" #include "resource/BufferInstance.h" #include "dto/TransformComponent.h" namespace Metal { void EngineContext::resetPathTracerAccumulationCount() const { - CTX.engineRepository.pathTracerAccumulationCount = 0; + engineRepository.pathTracerAccumulationCount = 0; } void EngineContext::onInitialize() { @@ -36,12 +44,12 @@ namespace Metal { void EngineContext::onSync() { updateCurrentTime(); - CTX.transformService.onSync(); - CTX.streamingService.onSync(); - CTX.rayTracingService.onSync(); - CTX.cameraService.onSync(); - CTX.lightService.onSync(); - CTX.volumeService.onSync(); + transformService.onSync(); + streamingService.onSync(); + rayTracingService.onSync(); + cameraService.onSync(); + lightService.onSync(); + volumeService.onSync(); for (auto *frame: registeredFrames) { if (frame->getShouldRender()) { @@ -58,7 +66,7 @@ namespace Metal { } void EngineContext::updateGlobalData() { - auto &camera = CTX.worldRepository.camera; + auto &camera = worldRepository.camera; globalDataUBO.previousProjView = globalDataUBO.projView; globalDataUBO.viewMatrix = camera.viewMatrix; globalDataUBO.projectionMatrix = camera.projectionMatrix; @@ -66,21 +74,21 @@ namespace Metal { globalDataUBO.invProj = camera.invProjectionMatrix; globalDataUBO.invView = camera.invViewMatrix; globalDataUBO.cameraWorldPosition = camera.position; - globalDataUBO.volumeCount = CTX.volumeService.getCount(); - globalDataUBO.lightsCount = CTX.lightService.getCount(); - globalDataUBO.debugFlag = ShadingModes::IndexOfValue(CTX.editorRepository.shadingMode); - CTX.engineRepository.pathTracerAccumulationCount++; - globalDataUBO.pathTracerAccumulationCount = CTX.engineRepository.pathTracerAccumulationCount; + globalDataUBO.volumeCount = volumeService.getCount(); + globalDataUBO.lightsCount = lightService.getCount(); + globalDataUBO.debugFlag = ShadingModes::IndexOfValue(editorRepository.shadingMode); + engineRepository.pathTracerAccumulationCount++; + globalDataUBO.pathTracerAccumulationCount = engineRepository.pathTracerAccumulationCount; globalDataUBO.globalFrameCount++; - globalDataUBO.pathTracerMaxSamples = CTX.engineRepository.pathTracerMaxSamples; - globalDataUBO.denoiserEnabled = CTX.engineRepository.denoiserEnabled && ( + globalDataUBO.pathTracerMaxSamples = engineRepository.pathTracerMaxSamples; + globalDataUBO.denoiserEnabled = engineRepository.denoiserEnabled && ( globalDataUBO.debugFlag == LIT || globalDataUBO.debugFlag == LIGHTING_ONLY) ? 1 : 0; - CTX.lightService.computeSunInfo(); - globalDataUBO.sunPosition = CTX.lightService.getSunPosition(); - globalDataUBO.sunColor = CTX.lightService.getSunColor(); + lightService.computeSunInfo(); + globalDataUBO.sunPosition = lightService.getSunPosition(); + globalDataUBO.sunColor = lightService.getSunColor(); currentFrame->getResourceAs(RID_GLOBAL_DATA)->update(&globalDataUBO); } } diff --git a/src/engine/EngineContext.h b/src/engine/EngineContext.h index 6c07088d..5f73f823 100644 --- a/src/engine/EngineContext.h +++ b/src/engine/EngineContext.h @@ -13,13 +13,52 @@ using Clock = std::chrono::high_resolution_clock; using TimePoint = std::chrono::time_point; namespace Metal { + class TransformService; + class StreamingService; + class RayTracingService; + class CameraService; + class LightService; + class VolumeService; + struct WorldRepository; + struct EditorRepository; + struct EngineRepository; + class EngineContext final : public AbstractRuntimeComponent { + TransformService &transformService; + StreamingService &streamingService; + RayTracingService &rayTracingService; + CameraService &cameraService; + LightService &lightService; + VolumeService &volumeService; + WorldRepository &worldRepository; + EditorRepository &editorRepository; + EngineRepository &engineRepository; + GlobalDataUBO globalDataUBO{}; long long start = -1; bool cameraUpdated = true; bool giSettingsUpdated = true; public: + EngineContext(TransformService &transformService, + StreamingService &streamingService, + RayTracingService &rayTracingService, + CameraService &cameraService, + LightService &lightService, + VolumeService &volumeService, + WorldRepository &worldRepository, + EditorRepository &editorRepository, + EngineRepository &engineRepository) + : transformService(transformService), + streamingService(streamingService), + rayTracingService(rayTracingService), + cameraService(cameraService), + lightService(lightService), + volumeService(volumeService), + worldRepository(worldRepository), + editorRepository(editorRepository), + engineRepository(engineRepository) { + } GlobalDataUBO &getGlobalDataUBO() { return globalDataUBO; } void setCameraUpdated(const bool val) { diff --git a/src/engine/repository/EngineRepository.cpp b/src/engine/repository/EngineRepository.cpp index 30489fef..6d4aa4d2 100644 --- a/src/engine/repository/EngineRepository.cpp +++ b/src/engine/repository/EngineRepository.cpp @@ -41,10 +41,11 @@ namespace Metal { } void EngineRepository::onUpdate(InspectableMember *member) { - if (member != nullptr && (member->group == PATH_TRACER || member->group == ATMOSPHERE || member->group - == SUN || member->group == DEPTH_OF_FIELD)) { - CTX.engineContext.setGISettingsUpdated(true); - } + // TODO - EVENT + // if (member != nullptr && (member->group == PATH_TRACER || member->group == ATMOSPHERE || member->group + // == SUN || member->group == DEPTH_OF_FIELD)) { + // engineContext.setGISettingsUpdated(true); + // } } nlohmann::json EngineRepository::toJson() const { diff --git a/src/engine/repository/WorldRepository.cpp b/src/engine/repository/WorldRepository.cpp index 812ccace..519cb1a5 100644 --- a/src/engine/repository/WorldRepository.cpp +++ b/src/engine/repository/WorldRepository.cpp @@ -1,6 +1,6 @@ #include "WorldRepository.h" +#include "../service/RayTracingService.h" -#include "../../ApplicationContext.h" #include "../enum/ComponentType.h" #include "../../editor/dto/SceneData.h" #include "../../common/serialization-definitions.h" @@ -35,7 +35,7 @@ namespace Metal { registry.destroy(entityId); } - CTX.rayTracingService.markDirty(); + rayTracingService.markDirty(); } void WorldRepository::changeVisibility(entt::entity entity, bool isVisible) { @@ -45,12 +45,12 @@ namespace Metal { } else { hiddenEntities.insert({entity, true}); } - CTX.rayTracingService.markDirty(); + rayTracingService.markDirty(); } void WorldRepository::loadScene(const std::string &sceneId) { SceneData sceneData; - const auto pathToFile = CTX.getAssetDirectory() + FORMAT_FILE_SCENE(sceneId); + const auto pathToFile = rootDirectory + "/assets/" + FORMAT_FILE_SCENE(sceneId); PARSE_TEMPLATE(sceneData, pathToFile) for (auto &entityData: sceneData.entities) { @@ -86,7 +86,7 @@ namespace Metal { } } - CTX.rayTracingService.markDirty(); + rayTracingService.markDirty(); } void WorldRepository::createComponent(const entt::entity entityId, ComponentType type) { diff --git a/src/engine/repository/WorldRepository.h b/src/engine/repository/WorldRepository.h index 1a42b233..0e261522 100644 --- a/src/engine/repository/WorldRepository.h +++ b/src/engine/repository/WorldRepository.h @@ -18,8 +18,16 @@ namespace Metal { class Inspectable; + class RayTracingService; struct WorldRepository final : AbstractRuntimeComponent, Serializable { + RayTracingService &rayTracingService; + std::string &rootDirectory; + + WorldRepository(RayTracingService &rayTracingService, std::string &rootDirectory) + : rayTracingService(rayTracingService), rootDirectory(rootDirectory) { + } + Camera camera{-(glm::pi() / 4), glm::pi() / 4, {10, 10, 10}}; entt::registry registry{}; std::unordered_map culled{}; diff --git a/src/engine/service/BufferService.cpp b/src/engine/service/BufferService.cpp index 27161788..c0931b71 100644 --- a/src/engine/service/BufferService.cpp +++ b/src/engine/service/BufferService.cpp @@ -1,6 +1,6 @@ #include "BufferService.h" -#include "../../ApplicationContext.h" +#include "../../core/vulkan/VulkanContext.h" #include "../../core/vulkan/VulkanUtils.h" #include "../resource/BufferInstance.h" @@ -10,7 +10,7 @@ namespace Metal { VkMemoryPropertyFlags memoryPropertyFlags, BufferType type) { BufferInstance *buffer = createResourceInstance(id, bufferSize, type); createVkBuffer(usageFlags, memoryPropertyFlags, buffer); - vkMapMemory(CTX.vulkanContext.device.device, buffer->vkDeviceMemory, 0, bufferSize, 0, &buffer->mapped); + vkMapMemory(vulkanContext.device.device, buffer->vkDeviceMemory, 0, bufferSize, 0, &buffer->mapped); return buffer; } @@ -23,10 +23,10 @@ namespace Metal { createVkBuffer(VK_BUFFER_USAGE_TRANSFER_SRC_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, stagingBuffer); - vkMapMemory(CTX.vulkanContext.device.device, stagingBuffer->vkDeviceMemory, 0, dataSize, 0, + vkMapMemory(vulkanContext.device.device, stagingBuffer->vkDeviceMemory, 0, dataSize, 0, &stagingBuffer->mapped); memcpy(stagingBuffer->mapped, bufferData, dataSize); - vkUnmapMemory(CTX.vulkanContext.device.device, stagingBuffer->vkDeviceMemory); + vkUnmapMemory(vulkanContext.device.device, stagingBuffer->vkDeviceMemory); createVkBuffer(VK_BUFFER_USAGE_TRANSFER_DST_BIT | usageFlags, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, finalBuffer); @@ -38,8 +38,8 @@ namespace Metal { } unsigned int BufferService::findMemoryType(unsigned int typeFilter, VkMemoryPropertyFlags properties) const { - for (unsigned int i = 0; i < CTX.vulkanContext.physicalDeviceMemoryProperties.memoryTypeCount; i++) { - if ((typeFilter & (1 << i)) && (CTX.vulkanContext.physicalDeviceMemoryProperties.memoryTypes[i]. + for (unsigned int i = 0; i < vulkanContext.physicalDeviceMemoryProperties.memoryTypeCount; i++) { + if ((typeFilter & (1 << i)) && (vulkanContext.physicalDeviceMemoryProperties.memoryTypes[i]. propertyFlags & properties) == properties) { return i; @@ -57,31 +57,31 @@ namespace Metal { bufferInfo.usage = usage; bufferInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE; - VulkanUtils::CheckVKResult(vkCreateBuffer(CTX.vulkanContext.device.device, &bufferInfo, nullptr, + VulkanUtils::CheckVKResult(vkCreateBuffer(vulkanContext.device.device, &bufferInfo, nullptr, &buffer->vkBuffer)); VkMemoryRequirements memRequirements; - vkGetBufferMemoryRequirements(CTX.vulkanContext.device.device, buffer->vkBuffer, &memRequirements); + vkGetBufferMemoryRequirements(vulkanContext.device.device, buffer->vkBuffer, &memRequirements); VkMemoryAllocateInfo allocInfo{}; allocInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; allocInfo.allocationSize = memRequirements.size; allocInfo.memoryTypeIndex = findMemoryType(memRequirements.memoryTypeBits, properties); - VulkanUtils::CheckVKResult(vkAllocateMemory(CTX.vulkanContext.device.device, &allocInfo, nullptr, + VulkanUtils::CheckVKResult(vkAllocateMemory(vulkanContext.device.device, &allocInfo, nullptr, &buffer->vkDeviceMemory)); - vkBindBufferMemory(CTX.vulkanContext.device.device, buffer->vkBuffer, buffer->vkDeviceMemory, 0); + vkBindBufferMemory(vulkanContext.device.device, buffer->vkBuffer, buffer->vkDeviceMemory, 0); } void BufferService::copyBuffer(const BufferInstance *srcBuffer, const BufferInstance *dstBuffer) const { - VkCommandBuffer commandBuffer = CTX.vulkanContext.beginSingleTimeCommands(); + VkCommandBuffer commandBuffer = vulkanContext.beginSingleTimeCommands(); VkBufferCopy copyRegion{}; copyRegion.size = dstBuffer->dataSize; vkCmdCopyBuffer(commandBuffer, srcBuffer->vkBuffer, dstBuffer->vkBuffer, 1, ©Region); - CTX.vulkanContext.endSingleTimeCommands(commandBuffer); + vulkanContext.endSingleTimeCommands(commandBuffer); } BufferInstance *BufferService::createBuffer(const std::string &id, VkDeviceSize bufferSize, @@ -99,11 +99,11 @@ namespace Metal { } bufferInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE; - VulkanUtils::CheckVKResult(vkCreateBuffer(CTX.vulkanContext.device.device, &bufferInfo, nullptr, + VulkanUtils::CheckVKResult(vkCreateBuffer(vulkanContext.device.device, &bufferInfo, nullptr, &buffer->vkBuffer)); VkMemoryRequirements memRequirements; - vkGetBufferMemoryRequirements(CTX.vulkanContext.device.device, buffer->vkBuffer, &memRequirements); + vkGetBufferMemoryRequirements(vulkanContext.device.device, buffer->vkBuffer, &memRequirements); VkMemoryAllocateInfo allocInfo{}; allocInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; @@ -117,12 +117,12 @@ namespace Metal { allocInfo.pNext = &allocFlagsInfo; } - VulkanUtils::CheckVKResult(vkAllocateMemory(CTX.vulkanContext.device.device, &allocInfo, nullptr, + VulkanUtils::CheckVKResult(vkAllocateMemory(vulkanContext.device.device, &allocInfo, nullptr, &buffer->vkDeviceMemory)); - vkBindBufferMemory(CTX.vulkanContext.device.device, buffer->vkBuffer, buffer->vkDeviceMemory, 0); + vkBindBufferMemory(vulkanContext.device.device, buffer->vkBuffer, buffer->vkDeviceMemory, 0); if (memoryPropertyFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) { - vkMapMemory(CTX.vulkanContext.device.device, buffer->vkDeviceMemory, 0, bufferSize, 0, &buffer->mapped); + vkMapMemory(vulkanContext.device.device, buffer->vkDeviceMemory, 0, bufferSize, 0, &buffer->mapped); } return buffer; @@ -137,10 +137,10 @@ namespace Metal { createVkBuffer(VK_BUFFER_USAGE_TRANSFER_SRC_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, stagingBuffer); - vkMapMemory(CTX.vulkanContext.device.device, stagingBuffer->vkDeviceMemory, 0, dataSize, 0, + vkMapMemory(vulkanContext.device.device, stagingBuffer->vkDeviceMemory, 0, dataSize, 0, &stagingBuffer->mapped); memcpy(stagingBuffer->mapped, bufferData, dataSize); - vkUnmapMemory(CTX.vulkanContext.device.device, stagingBuffer->vkDeviceMemory); + vkUnmapMemory(vulkanContext.device.device, stagingBuffer->vkDeviceMemory); auto *finalBuffer = createBuffer(id, dataSize, VK_BUFFER_USAGE_TRANSFER_DST_BIT | usageFlags, @@ -153,9 +153,7 @@ namespace Metal { } void BufferService::disposeResource(BufferInstance *resource) { - LOG_INFO("Disposing of buffer instance " + resource->getId()); - - vkDestroyBuffer(CTX.vulkanContext.device.device, resource->vkBuffer, nullptr); - vkFreeMemory(CTX.vulkanContext.device.device, resource->vkDeviceMemory, nullptr); + vkDestroyBuffer(vulkanContext.device.device, resource->vkBuffer, nullptr); + vkFreeMemory(vulkanContext.device.device, resource->vkDeviceMemory, nullptr); } } // Metal diff --git a/src/engine/service/BufferService.h b/src/engine/service/BufferService.h index a171a084..8b6b3632 100644 --- a/src/engine/service/BufferService.h +++ b/src/engine/service/BufferService.h @@ -12,6 +12,8 @@ namespace Metal { class VulkanContext; class BufferService final : public AbstractResourceService { + VulkanContext &vulkanContext; + void copyBuffer(const BufferInstance *srcBuffer, const BufferInstance *dstBuffer) const; @@ -19,6 +21,9 @@ namespace Metal { BufferInstance *buffer) const; public: + explicit BufferService(VulkanContext &vulkanContext) : vulkanContext(vulkanContext) {} + BufferService() = delete; + [[nodiscard]] unsigned int findMemoryType(unsigned int typeFilter, VkMemoryPropertyFlags properties) const; BufferInstance *createBuffer(const std::string &id, VkDeviceSize bufferSize, diff --git a/src/engine/service/CameraService.cpp b/src/engine/service/CameraService.cpp index 3f58a727..9391b3d7 100644 --- a/src/engine/service/CameraService.cpp +++ b/src/engine/service/CameraService.cpp @@ -2,25 +2,26 @@ #include "../dto/Camera.h" #include "../../ApplicationContext.h" +#include "../EngineContext.h" +#include "../repository/WorldRepository.h" +#include "../repository/RuntimeRepository.h" namespace Metal { // Per frame // TODO - EVENT SYSTEM void CameraService::onSync() { - camera = &CTX.worldRepository.camera; + camera = &worldRepository.camera; if (camera != nullptr) { updateAspectRatio(); if (camera->isNotFrozen()) { updateMatrices(); - CTX.engineContext.setCameraUpdated(true); + engineContext.setCameraUpdated(true); camera->freezeVersion(); } } } void CameraService::updateAspectRatio() const { - const auto &runtimeRepository = CTX.runtimeRepository; - const float prevAspect = camera->aspectRatio; camera->aspectRatio = runtimeRepository.viewportW / runtimeRepository.viewportH; if (prevAspect != camera->aspectRatio) { @@ -56,12 +57,11 @@ namespace Metal { camera->invProjectionMatrix = glm::inverse(camera->projectionMatrix); } - CameraService::CameraService() : AbstractRuntimeComponent() { + CameraService::CameraService(EngineContext &engineContext, WorldRepository &worldRepository, RuntimeRepository &runtimeRepository) + : engineContext(engineContext), worldRepository(worldRepository), runtimeRepository(runtimeRepository) { } void CameraService::handleInputInternal() const { - const auto &runtimeRepository = CTX.runtimeRepository; - glm::vec3 forward( -std::sin(camera->yaw) * std::cos(camera->pitch), std::sin(camera->pitch), @@ -76,7 +76,7 @@ namespace Metal { right = glm::normalize(right); const float multiplier = 10 * camera->movementSensitivity * - CTX.engineContext.deltaTime; + engineContext.deltaTime; if (runtimeRepository.leftPressed) { camera->position += right * multiplier; camera->registerChange(); @@ -118,7 +118,6 @@ namespace Metal { } void CameraService::updateDelta(const bool isFirstMovement) const { - const auto &runtimeRepository = CTX.runtimeRepository; const float mouseX = runtimeRepository.mouseX; const float mouseY = runtimeRepository.mouseY; diff --git a/src/engine/service/CameraService.h b/src/engine/service/CameraService.h index 967f3a1c..3109c51d 100644 --- a/src/engine/service/CameraService.h +++ b/src/engine/service/CameraService.h @@ -13,7 +13,16 @@ namespace Metal { class ApplicationContext; struct Camera; + class EngineContext; + struct WorldRepository; + struct RuntimeRepository; + struct Camera; + class CameraService final : public AbstractRuntimeComponent { + EngineContext &engineContext; + WorldRepository &worldRepository; + RuntimeRepository &runtimeRepository; + Camera *camera = nullptr; glm::vec3 xAxis{0.0f}; glm::vec3 yAxis{0.0f}; @@ -38,7 +47,7 @@ namespace Metal { public: void handleInput(bool isFirstMovement) const; - explicit CameraService(); + explicit CameraService(EngineContext &engineContext, WorldRepository &worldRepository, RuntimeRepository &runtimeRepository); void onSync() override; }; diff --git a/src/engine/service/DescriptorSetService.cpp b/src/engine/service/DescriptorSetService.cpp index 901a1f0a..3032fec6 100644 --- a/src/engine/service/DescriptorSetService.cpp +++ b/src/engine/service/DescriptorSetService.cpp @@ -2,7 +2,10 @@ #include "../dto/PipelineBuilder.h" #include "../resource/BufferInstance.h" #include "../../editor/service/LogService.h" -#include "../../ApplicationContext.h" +#include "../../core/vulkan/VulkanContext.h" +#include "FrameBufferService.h" +#include "BufferService.h" +#include "TextureService.h" #include "../resource/FrameBufferAttachment.h" #include "../resource/FrameBufferInstance.h" #include "../resource/TextureInstance.h" @@ -27,13 +30,13 @@ namespace Metal { binding.attachmentIndex = builder.attachmentIndex; if (builder.type == DescriptorBindingType::FBO_ATTACHMENT) { - auto *fbo = CTX.framebufferService.getResource(binding.frameBufferId); + auto *fbo = framebufferService.getResource(binding.frameBufferId); if (fbo == nullptr) { throw std::runtime_error("Framebuffer not found: " + binding.frameBufferId); } binding.view = fbo->attachments[binding.attachmentIndex]->vkImageView; if (binding.sampler == VK_NULL_HANDLE) { - binding.sampler = CTX.vulkanContext.vkImageSampler; + binding.sampler = vulkanContext.vkImageSampler; } } @@ -42,7 +45,7 @@ namespace Metal { binding.descriptorType = VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR; break; case DescriptorBindingType::BUFFER: { - BufferInstance *buffer = CTX.bufferService.getResource(binding.bufferId); + BufferInstance *buffer = bufferService.getResource(binding.bufferId); if (buffer != nullptr) { binding.descriptorType = buffer->getBufferType() == BufferType::UNIFORM_BUFFER @@ -58,7 +61,7 @@ namespace Metal { binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; break; case DescriptorBindingType::STORAGE_IMAGE: { - auto *texture = CTX.textureService.getResource(binding.storageImageId); + auto *texture = textureService.getResource(binding.storageImageId); if (texture == nullptr) { throw std::runtime_error("Storage image texture not found: " + binding.storageImageId); } @@ -77,7 +80,7 @@ namespace Metal { void DescriptorSetService::disposeResource(DescriptorInstance *resource) { LOG_INFO("Disposing of descriptor set resource"); - vkDestroyDescriptorSetLayout(CTX.vulkanContext.device.device, resource->vkDescriptorSetLayout, nullptr); + vkDestroyDescriptorSetLayout(vulkanContext.device.device, resource->vkDescriptorSetLayout, nullptr); } std::vector DescriptorSetService::getAllDescriptors() const { @@ -96,7 +99,7 @@ namespace Metal { attachment->imageDescriptor = createResourceInstance(framebuffer->getId() + std::to_string(attachmentIndex)); attachment->imageDescriptor->bindings.push_back(DescriptorBinding::Of(VK_SHADER_STAGE_FRAGMENT_BIT, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 0, - CTX.vulkanContext.vkImageSampler, + vulkanContext.vkImageSampler, attachment->vkImageView)); updateDescriptor(attachment->imageDescriptor); } @@ -150,27 +153,27 @@ namespace Metal { layoutInfo.flags = VK_DESCRIPTOR_SET_LAYOUT_CREATE_UPDATE_AFTER_BIND_POOL_BIT_EXT; layoutInfo.pNext = &flagsInfo; - VulkanUtils::CheckVKResult(vkCreateDescriptorSetLayout(CTX.vulkanContext.device.device, &layoutInfo, + VulkanUtils::CheckVKResult(vkCreateDescriptorSetLayout(vulkanContext.device.device, &layoutInfo, nullptr, &descriptor->vkDescriptorSetLayout)); VkDescriptorSetAllocateInfo allocInfo = {}; allocInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; - allocInfo.descriptorPool = CTX.vulkanContext.descriptorPool; // Created during setup + allocInfo.descriptorPool = vulkanContext.descriptorPool; // Created during setup allocInfo.descriptorSetCount = 1; allocInfo.pSetLayouts = &descriptor->vkDescriptorSetLayout; - VulkanUtils::CheckVKResult(vkAllocateDescriptorSets(CTX.vulkanContext.device.device, &allocInfo, &descriptor->vkDescriptorSet)); + VulkanUtils::CheckVKResult(vkAllocateDescriptorSets(vulkanContext.device.device, &allocInfo, &descriptor->vkDescriptorSet)); // WRITE - Write(descriptor->vkDescriptorSet, descriptor->bindings); + Write(vulkanContext, bufferService, descriptor->vkDescriptorSet, descriptor->bindings); } void DescriptorSetService::write(DescriptorInstance *descriptor) { - Write(descriptor->vkDescriptorSet, descriptor->bindings); + Write(vulkanContext, bufferService, descriptor->vkDescriptorSet, descriptor->bindings); } - void DescriptorSetService::Write(const VkDescriptorSet &vkDescriptorSet, + void DescriptorSetService::Write(VulkanContext &vulkanContext, BufferService &bufferService, const VkDescriptorSet &vkDescriptorSet, const std::vector &bindings) { std::vector writeDescriptorSets; std::vector bufferInfos; @@ -204,7 +207,7 @@ namespace Metal { writeDescriptorSets.push_back(descriptorWrite); } } else if (!binding.bufferId.empty()) { - BufferInstance *buffer = CTX.bufferService.getResource(binding.bufferId); + BufferInstance *buffer = bufferService.getResource(binding.bufferId); if (buffer == nullptr) { LOG_ERROR("DescriptorSetService Buffer not found: " + binding.bufferId); @@ -258,7 +261,7 @@ namespace Metal { if (writeDescriptorSets.empty()) return; - vkUpdateDescriptorSets(CTX.vulkanContext.device.device, + vkUpdateDescriptorSets(vulkanContext.device.device, static_cast(writeDescriptorSets.size()), writeDescriptorSets.data(), 0, diff --git a/src/engine/service/DescriptorSetService.h b/src/engine/service/DescriptorSetService.h index fd5d7833..f5ebde4e 100644 --- a/src/engine/service/DescriptorSetService.h +++ b/src/engine/service/DescriptorSetService.h @@ -8,9 +8,22 @@ namespace Metal { struct PipelineBuilder; struct TextureInstance; struct FrameBufferInstance; + class VulkanContext; + class FrameBufferService; + class BufferService; + class TextureService; class DescriptorSetService final : public AbstractResourceService { + VulkanContext &vulkanContext; + FrameBufferService &framebufferService; + BufferService &bufferService; + TextureService &textureService; + public: + DescriptorSetService(VulkanContext &vulkanContext, FrameBufferService &framebufferService, BufferService &bufferService, TextureService &textureService) + : vulkanContext(vulkanContext), framebufferService(framebufferService), bufferService(bufferService), textureService(textureService) {} + DescriptorSetService() = delete; + DescriptorInstance *createDescriptor(const PipelineBuilder &pipelineBuilder, const std::string &id, VkShaderStageFlags stageFlags); void disposeResource(DescriptorInstance *resource) override; @@ -25,7 +38,7 @@ namespace Metal { void write(DescriptorInstance *descriptor); - static void Write(const VkDescriptorSet &vkDescriptorSet, const std::vector &bindings); + static void Write(VulkanContext &vulkanContext, BufferService &bufferService, const VkDescriptorSet &vkDescriptorSet, const std::vector &bindings); }; } diff --git a/src/engine/service/FrameBufferService.cpp b/src/engine/service/FrameBufferService.cpp index 1f90f6c5..b1bedf37 100644 --- a/src/engine/service/FrameBufferService.cpp +++ b/src/engine/service/FrameBufferService.cpp @@ -5,6 +5,7 @@ #include #include "../resource/FrameBufferInstance.h" +#include "../../core/vulkan/VulkanContext.h" #include "../../core/vulkan/VulkanUtils.h" #include "../resource/FrameBufferAttachment.h" #include "../../ApplicationContext.h" @@ -22,7 +23,7 @@ namespace Metal { } void FrameBufferService::createDepthAttachment(FrameBufferInstance *framebuffer) const { - VkFormat depthFormat = VulkanUtils::GetValidDepthFormat(CTX.vulkanContext.physDevice.physical_device); + VkFormat depthFormat = VulkanUtils::GetValidDepthFormat(vulkanContext.physDevice.physical_device); const auto att = createAttachmentInternal(depthFormat, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, framebuffer); att->depth = true; @@ -72,20 +73,20 @@ namespace Metal { image.sharingMode = VK_SHARING_MODE_EXCLUSIVE; VulkanUtils::CheckVKResult( - vkCreateImage(CTX.vulkanContext.device.device, &image, nullptr, &attachment->vkImage)); + vkCreateImage(vulkanContext.device.device, &image, nullptr, &attachment->vkImage)); VkMemoryAllocateInfo memAlloc{}; VkMemoryRequirements memReqs; - vkGetImageMemoryRequirements(CTX.vulkanContext.device.device, attachment->vkImage, &memReqs); + vkGetImageMemoryRequirements(vulkanContext.device.device, attachment->vkImage, &memReqs); memAlloc.allocationSize = memReqs.size; - memAlloc.memoryTypeIndex = VulkanUtils::GetMemTypeIndex(CTX.vulkanContext.physicalDeviceMemoryProperties, + memAlloc.memoryTypeIndex = VulkanUtils::GetMemTypeIndex(vulkanContext.physicalDeviceMemoryProperties, memReqs.memoryTypeBits, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT); - VulkanUtils::CheckVKResult(vkAllocateMemory(CTX.vulkanContext.device.device, &memAlloc, nullptr, + VulkanUtils::CheckVKResult(vkAllocateMemory(vulkanContext.device.device, &memAlloc, nullptr, &attachment->vkImageMemory)); VulkanUtils::CheckVKResult( - vkBindImageMemory(CTX.vulkanContext.device.device, attachment->vkImage, attachment->vkImageMemory, 0)); + vkBindImageMemory(vulkanContext.device.device, attachment->vkImage, attachment->vkImageMemory, 0)); VkImageViewCreateInfo imageView{}; imageView.viewType = VK_IMAGE_VIEW_TYPE_2D; @@ -97,7 +98,7 @@ namespace Metal { imageView.subresourceRange.baseArrayLayer = 0; imageView.subresourceRange.layerCount = 1; imageView.image = attachment->vkImage; - VulkanUtils::CheckVKResult(vkCreateImageView(CTX.vulkanContext.device.device, &imageView, nullptr, + VulkanUtils::CheckVKResult(vkCreateImageView(vulkanContext.device.device, &imageView, nullptr, &attachment->vkImageView)); return attachment; } @@ -166,7 +167,7 @@ namespace Metal { renderPassInfo.dependencyCount = dependencies.size(); renderPassInfo.pDependencies = dependencies.data(); - VulkanUtils::CheckVKResult(vkCreateRenderPass(CTX.vulkanContext.device.device, + VulkanUtils::CheckVKResult(vkCreateRenderPass(vulkanContext.device.device, &renderPassInfo, nullptr, &framebuffer->vkRenderPass)); @@ -195,14 +196,14 @@ namespace Metal { framebufferInfo.height = framebuffer->bufferHeight; framebufferInfo.layers = 1; - vkCreateFramebuffer(CTX.vulkanContext.device.device, &framebufferInfo, nullptr, + vkCreateFramebuffer(vulkanContext.device.device, &framebufferInfo, nullptr, &framebuffer->vkFramebuffer); } void FrameBufferService::disposeResource(FrameBufferInstance *resource) { LOG_INFO("Disposing framebuffer instance"); - vkDestroyFramebuffer(CTX.vulkanContext.device.device, resource->vkFramebuffer, nullptr); - vkDestroyRenderPass(CTX.vulkanContext.device.device, resource->vkRenderPass, nullptr); + vkDestroyFramebuffer(vulkanContext.device.device, resource->vkFramebuffer, nullptr); + vkDestroyRenderPass(vulkanContext.device.device, resource->vkRenderPass, nullptr); for (int i = 0; i < resource->attachments.size(); i++) { LOG_INFO("Disposing of attachment instance " + std::to_string(i)); diff --git a/src/engine/service/FrameBufferService.h b/src/engine/service/FrameBufferService.h index 5cc4c221..33694124 100644 --- a/src/engine/service/FrameBufferService.h +++ b/src/engine/service/FrameBufferService.h @@ -12,7 +12,11 @@ namespace Metal { struct FrameBufferAttachment; struct FrameBufferInstance; + class VulkanContext; + class FrameBufferService final : public AbstractResourceService { + VulkanContext &vulkanContext; + std::shared_ptr createAttachmentInternal(VkFormat format, VkImageUsageFlagBits usage, FrameBufferInstance *framebuffer) const; @@ -20,6 +24,9 @@ namespace Metal { void createVKFrameBuffer(FrameBufferInstance *framebuffer) const; public: + explicit FrameBufferService(VulkanContext &vulkanContext) : vulkanContext(vulkanContext) {} + FrameBufferService() = delete; + FrameBufferInstance *createFrameBuffer(const std::string &id, unsigned int w, unsigned int h, glm::vec4 clearColor = glm::vec4(0.0f)); diff --git a/src/engine/service/LightService.cpp b/src/engine/service/LightService.cpp index 3d759aa0..3f4ca266 100644 --- a/src/engine/service/LightService.cpp +++ b/src/engine/service/LightService.cpp @@ -2,6 +2,8 @@ #include "../../ApplicationContext.h" #include "../resource/BufferInstance.h" #include "../../editor/enum/EngineResourceIDs.h" +#include "../EngineContext.h" +#include "../repository/EngineRepository.h" namespace Metal { void LightService::registerLights() { @@ -15,19 +17,19 @@ namespace Metal { registerLights(); if (!items.empty()) { - CTX.engineContext.currentFrame->getResourceAs(RID_LIGHT_BUFFER)->update(items.data()); + engineContext.currentFrame->getResourceAs(RID_LIGHT_BUFFER)->update(items.data()); } } void LightService::computeSunInfo() { sunPosition = glm::vec3(0, - std::cos(CTX.engineRepository.elapsedTime), - std::sin(CTX.engineRepository.elapsedTime)) * CTX.engineRepository + std::cos(engineRepository.elapsedTime), + std::sin(engineRepository.elapsedTime)) * engineRepository .sunDistance; sunColor = LightService::CalculateSunColor( - sunPosition.y / CTX.engineRepository.sunDistance, - CTX.engineRepository.nightColor, CTX.engineRepository.dawnColor, - CTX.engineRepository.middayColor); + sunPosition.y / engineRepository.sunDistance, + engineRepository.nightColor, engineRepository.dawnColor, + engineRepository.middayColor); } glm::vec3 LightService::CalculateSunColor(const float elevation, glm::vec3 &nightColor, glm::vec3 &dawnColor, diff --git a/src/engine/service/LightService.h b/src/engine/service/LightService.h index 655781c9..905b53e0 100644 --- a/src/engine/service/LightService.h +++ b/src/engine/service/LightService.h @@ -6,7 +6,13 @@ #include "../dto/LightData.h" namespace Metal { + class EngineContext; + struct EngineRepository; + class LightService final : public AbstractRuntimeComponent { + EngineContext &engineContext; + EngineRepository &engineRepository; + std::vector items{}; glm::vec3 sunColor{}; glm::vec3 sunPosition{}; @@ -19,6 +25,10 @@ namespace Metal { static glm::vec3 BlendColors(glm::vec3 &c1, glm::vec3 &c2, float t); public: + explicit LightService(EngineContext &engineContext, EngineRepository &engineRepository) + : engineContext(engineContext), engineRepository(engineRepository) {} + LightService() = delete; + void onSync() override; void computeSunInfo(); diff --git a/src/engine/service/MaterialService.cpp b/src/engine/service/MaterialService.cpp index a42e5b3b..4c41d172 100644 --- a/src/engine/service/MaterialService.cpp +++ b/src/engine/service/MaterialService.cpp @@ -2,9 +2,8 @@ #include "../../common/serialization-definitions.h" #include "../dto/MeshMetadata.h" - -#include "../../ApplicationContext.h" - +#include "TextureService.h" +#include "../dto/PrimitiveComponent.h" namespace Metal { void MaterialService::load(MeshMetadata &materialData, PrimitiveComponent &data) { @@ -21,21 +20,21 @@ namespace Metal { materialData.metallicTextureId = 0; if (!data.albedo.empty()) { - auto *tex = CTX.textureService.stream(data.albedo); + auto *tex = textureService.stream(data.albedo); if (tex != nullptr) { - materialData.albedoTextureId = CTX.textureService.getTextureIndex(data.albedo); + materialData.albedoTextureId = textureService.getTextureIndex(data.albedo); } } if (!data.roughness.empty()) { - auto *tex = CTX.textureService.stream(data.roughness); + auto *tex = textureService.stream(data.roughness); if (tex != nullptr) { - materialData.roughnessTextureId = CTX.textureService.getTextureIndex(data.roughness); + materialData.roughnessTextureId = textureService.getTextureIndex(data.roughness); } } if (!data.metallic.empty()) { - auto *tex = CTX.textureService.stream(data.metallic); + auto *tex = textureService.stream(data.metallic); if (tex != nullptr) { - materialData.metallicTextureId = CTX.textureService.getTextureIndex(data.metallic); + materialData.metallicTextureId = textureService.getTextureIndex(data.metallic); } } } diff --git a/src/engine/service/MaterialService.h b/src/engine/service/MaterialService.h index fce5458e..9c1668bc 100644 --- a/src/engine/service/MaterialService.h +++ b/src/engine/service/MaterialService.h @@ -4,9 +4,14 @@ namespace Metal { struct PrimitiveComponent; struct MeshMetadata; + class TextureService; class MaterialService final { + TextureService &textureService; public: + explicit MaterialService(TextureService &textureService) : textureService(textureService) {} + MaterialService() = delete; + void load(MeshMetadata &data, PrimitiveComponent &component); }; } // Metal diff --git a/src/engine/service/MeshService.cpp b/src/engine/service/MeshService.cpp index d3838b01..2b9488ea 100644 --- a/src/engine/service/MeshService.cpp +++ b/src/engine/service/MeshService.cpp @@ -8,8 +8,11 @@ #include #include +#include #include "../../ApplicationContext.h" +#include "BufferService.h" +#include "RayTracingService.h" namespace Metal { MeshInstance *MeshService::create(const std::string &id) { @@ -22,14 +25,14 @@ namespace Metal { instance->indexCount = data->indices.size(); instance->vertexCount = data->data.size(); - instance->dataBuffer = CTX.bufferService.createBuffer( + instance->dataBuffer = bufferService.createBuffer( id + "_data", sizeof(VertexData) * data->data.size(), VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | VK_BUFFER_USAGE_ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY_BIT_KHR | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT, data->data.data(), true); - instance->indexBuffer = CTX.bufferService.createBuffer( + instance->indexBuffer = bufferService.createBuffer( id + "_indices", sizeof(unsigned int) * data->indices.size(), VK_BUFFER_USAGE_INDEX_BUFFER_BIT | VK_BUFFER_USAGE_ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY_BIT_KHR | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT, @@ -53,7 +56,7 @@ namespace Metal { } MeshData *MeshService::loadMeshData(const std::string &id) const { - auto pathToFile = CTX.getAssetDirectory() + FORMAT_FILE_MESH(id); + auto pathToFile = rootDirectory + "/assets/" + FORMAT_FILE_MESH(id); if (std::filesystem::exists(pathToFile)) { auto *data = new MeshData; std::ifstream input(pathToFile, std::ios::binary); @@ -66,8 +69,8 @@ namespace Metal { void MeshService::disposeResource(MeshInstance *resource) { LOG_INFO("Disposing of mesh instance"); - CTX.rayTracingService.markDirty(); - CTX.bufferService.dispose(resource->indexBuffer->getId()); - CTX.bufferService.dispose(resource->dataBuffer->getId()); + rayTracingService.markDirty(); + bufferService.dispose(resource->indexBuffer->getId()); + bufferService.dispose(resource->dataBuffer->getId()); } } // Metal diff --git a/src/engine/service/MeshService.h b/src/engine/service/MeshService.h index 671c7baf..40ba1270 100644 --- a/src/engine/service/MeshService.h +++ b/src/engine/service/MeshService.h @@ -9,8 +9,19 @@ namespace Metal { struct MeshInstance; struct EntityAssetData; + class BufferService; + class RayTracingService; + class MeshService final : public AbstractResourceService { + BufferService &bufferService; + RayTracingService &rayTracingService; + const std::string &rootDirectory; + public: + MeshService(BufferService &bufferService, RayTracingService &rayTracingService, const std::string &rootDirectory) + : bufferService(bufferService), rayTracingService(rayTracingService), rootDirectory(rootDirectory) {} + MeshService() = delete; + MeshInstance *create(const std::string &id); MeshInstance *stream(const std::string &id); diff --git a/src/engine/service/PipelineService.cpp b/src/engine/service/PipelineService.cpp index 30df93ea..d8feef1b 100644 --- a/src/engine/service/PipelineService.cpp +++ b/src/engine/service/PipelineService.cpp @@ -1,8 +1,10 @@ #include "PipelineService.h" #include "../dto/PipelineBuilder.h" #include "../util/ShaderUtil.h" -#include "../../ApplicationContext.h" +#include "../../core/vulkan/VulkanContext.h" #include "../../core/vulkan/VulkanUtils.h" +#include "FrameBufferService.h" +#include "BufferService.h" #include "../resource/FrameBufferInstance.h" #include "../resource/PipelineInstance.h" #include "../dto/MeshData.h" @@ -10,6 +12,7 @@ #include "../dto/DescriptorInstance.h" #include "../resource/FrameBufferAttachment.h" #include "../resource/BufferInstance.h" +#include "../../ApplicationContext.h" namespace Metal { void PipelineService::createPipelineLayout( @@ -34,7 +37,7 @@ namespace Metal { layoutInfo.pPushConstantRanges = &pushConstantRange; } - VulkanUtils::CheckVKResult(vkCreatePipelineLayout(CTX.vulkanContext.device.device, &layoutInfo, nullptr, + VulkanUtils::CheckVKResult(vkCreatePipelineLayout(vulkanContext.device.device, &layoutInfo, nullptr, &pipeline->vkPipelineLayout)); } @@ -84,12 +87,12 @@ namespace Metal { pipelineInfo.layout = pipeline->vkPipelineLayout; pipelineInfo.stage = computeShaderStageInfo; - if (vkCreateComputePipelines(CTX.vulkanContext.device.device, VK_NULL_HANDLE, 1, &pipelineInfo, nullptr, + if (vkCreateComputePipelines(vulkanContext.device.device, VK_NULL_HANDLE, 1, &pipelineInfo, nullptr, &pipeline->vkPipeline) != VK_SUCCESS) { throw std::runtime_error("failed to create compute pipeline!"); } - vkDestroyShaderModule(CTX.vulkanContext.device.device, computeShaderModule, nullptr); + vkDestroyShaderModule(vulkanContext.device.device, computeShaderModule, nullptr); return pipeline; } @@ -154,7 +157,7 @@ namespace Metal { multisampling.sampleShadingEnable = VK_FALSE; multisampling.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT; - auto *frameBuffer = CTX.framebufferService.getResource(pipelineBuilder.frameBufferId); + auto *frameBuffer = framebufferService.getResource(pipelineBuilder.frameBufferId); if (!frameBuffer) { throw std::runtime_error("Framebuffer not found: " + pipelineBuilder.frameBufferId); } @@ -225,13 +228,13 @@ namespace Metal { pipelineInfo.subpass = 0; pipelineInfo.basePipelineHandle = VK_NULL_HANDLE; - VulkanUtils::CheckVKResult(vkCreateGraphicsPipelines(CTX.vulkanContext.device.device, VK_NULL_HANDLE, 1, + VulkanUtils::CheckVKResult(vkCreateGraphicsPipelines(vulkanContext.device.device, VK_NULL_HANDLE, 1, &pipelineInfo, nullptr, &pipeline->vkPipeline)); - vkDestroyShaderModule(CTX.vulkanContext.device.device, fragmentShaderModule, nullptr); - vkDestroyShaderModule(CTX.vulkanContext.device.device, vertexShaderModule, nullptr); + vkDestroyShaderModule(vulkanContext.device.device, fragmentShaderModule, nullptr); + vkDestroyShaderModule(vulkanContext.device.device, vertexShaderModule, nullptr); return pipeline; } @@ -308,12 +311,12 @@ namespace Metal { rtPipelineInfo.layout = pipeline->vkPipelineLayout; VulkanUtils::CheckVKResult( - CTX.vulkanContext.vkCreateRayTracingPipelinesKHR( - CTX.vulkanContext.device.device, VK_NULL_HANDLE, VK_NULL_HANDLE, + vulkanContext.vkCreateRayTracingPipelinesKHR( + vulkanContext.device.device, VK_NULL_HANDLE, VK_NULL_HANDLE, 1, &rtPipelineInfo, nullptr, &pipeline->vkPipeline)); // Build Shader Binding Table - const auto &rtProps = CTX.vulkanContext.rayTracingPipelineProperties; + const auto &rtProps = vulkanContext.rayTracingPipelineProperties; const uint32_t handleSize = rtProps.shaderGroupHandleSize; const uint32_t handleAlignment = rtProps.shaderGroupHandleAlignment; const uint32_t baseAlignment = rtProps.shaderGroupBaseAlignment; @@ -323,14 +326,14 @@ namespace Metal { const uint32_t sbtSize = groupCount * handleSizeAligned; std::vector shaderHandleStorage(sbtSize); VulkanUtils::CheckVKResult( - CTX.vulkanContext.vkGetRayTracingShaderGroupHandlesKHR( - CTX.vulkanContext.device.device, pipeline->vkPipeline, + vulkanContext.vkGetRayTracingShaderGroupHandlesKHR( + vulkanContext.device.device, pipeline->vkPipeline, 0, groupCount, sbtSize, shaderHandleStorage.data())); // Create SBT buffers - each needs baseAlignment auto createSBTBuffer = [&](uint32_t groupIndex, const std::string &sbtType) -> BufferInstance * { const uint32_t sbtBufferSize = (handleSizeAligned + baseAlignment - 1) & ~(baseAlignment - 1); - auto *buf = CTX.bufferService.createBuffer( + auto *buf = bufferService.createBuffer( pipeline->getId() + "_sbt_" + sbtType, sbtBufferSize, VK_BUFFER_USAGE_SHADER_BINDING_TABLE_BIT_KHR | VK_BUFFER_USAGE_TRANSFER_DST_BIT, @@ -345,8 +348,8 @@ namespace Metal { pipeline->hitSBT = createSBTBuffer(2, "hit"); auto getAddr = [&](const BufferInstance *buf) { - return getBufferDeviceAddress(CTX.vulkanContext.device.device, buf->vkBuffer, - CTX.vulkanContext.vkGetBufferDeviceAddressKHR); + return getBufferDeviceAddress(vulkanContext.device.device, buf->vkBuffer, + vulkanContext.vkGetBufferDeviceAddressKHR); }; pipeline->raygenRegion.deviceAddress = getAddr(pipeline->raygenSBT); @@ -363,9 +366,9 @@ namespace Metal { pipeline->callableRegion = {}; // unused - vkDestroyShaderModule(CTX.vulkanContext.device.device, rayGenModule, nullptr); - vkDestroyShaderModule(CTX.vulkanContext.device.device, missModule, nullptr); - vkDestroyShaderModule(CTX.vulkanContext.device.device, closestHitModule, nullptr); + vkDestroyShaderModule(vulkanContext.device.device, rayGenModule, nullptr); + vkDestroyShaderModule(vulkanContext.device.device, missModule, nullptr); + vkDestroyShaderModule(vulkanContext.device.device, closestHitModule, nullptr); return pipeline; } @@ -377,8 +380,8 @@ namespace Metal { descriptorSetService.dispose(resource->getId()); } - vkDestroyPipelineLayout(CTX.vulkanContext.device.device, resource->vkPipelineLayout, nullptr); - vkDestroyPipeline(CTX.vulkanContext.device.device, resource->vkPipeline, nullptr); + vkDestroyPipelineLayout(vulkanContext.device.device, resource->vkPipelineLayout, nullptr); + vkDestroyPipeline(vulkanContext.device.device, resource->vkPipeline, nullptr); } std::vector PipelineService::getAllDescriptors() const { diff --git a/src/engine/service/PipelineService.h b/src/engine/service/PipelineService.h index 6d97a544..e3095178 100644 --- a/src/engine/service/PipelineService.h +++ b/src/engine/service/PipelineService.h @@ -12,9 +12,20 @@ namespace Metal { struct PipelineInstance; struct DescriptorInstance; + class VulkanContext; + class FrameBufferService; + class BufferService; + class PipelineService final : public AbstractResourceService { + VulkanContext &vulkanContext; + FrameBufferService &framebufferService; + BufferService &bufferService; + DescriptorSetService &descriptorSetService; + public: - explicit PipelineService(DescriptorSetService &descriptorSetService) : descriptorSetService(descriptorSetService) {} + explicit PipelineService(VulkanContext &vulkanContext, FrameBufferService &framebufferService, BufferService &bufferService, DescriptorSetService &descriptorSetService) + : vulkanContext(vulkanContext), framebufferService(framebufferService), bufferService(bufferService), descriptorSetService(descriptorSetService) {} + PipelineService() = delete; PipelineInstance *createPipeline(PipelineBuilder &pipelineBuilder); @@ -23,8 +34,6 @@ namespace Metal { std::vector getAllDescriptors() const; private: - DescriptorSetService &descriptorSetService; - PipelineInstance *createComputePipeline(const PipelineBuilder &pipelineBuilder, PipelineInstance *pipeline); PipelineInstance *createRenderingPipeline(PipelineBuilder &pipelineBuilder, PipelineInstance *pipeline); diff --git a/src/engine/service/RayTracingService.cpp b/src/engine/service/RayTracingService.cpp index d46be68a..26c09a41 100644 --- a/src/engine/service/RayTracingService.cpp +++ b/src/engine/service/RayTracingService.cpp @@ -7,6 +7,13 @@ #include "../dto/VertexData.h" #include "../../core/vulkan/VulkanUtils.h" #include "../../editor/enum/EngineResourceIDs.h" +#include "../../core/vulkan/VulkanContext.h" +#include "PipelineService.h" +#include "../repository/WorldRepository.h" +#include "MeshService.h" +#include "MaterialService.h" +#include "BufferService.h" +#include "../EngineContext.h" #include namespace Metal { @@ -18,7 +25,7 @@ namespace Metal { } void RayTracingService::updateDescriptorSets(VkAccelerationStructureKHR asHandle) { - auto descriptors = CTX.pipelineService.getAllDescriptors(); + auto descriptors = pipelineService.getAllDescriptors(); for (auto *descriptor: descriptors) { bool needsUpdate = false; for (auto &binding: descriptor->bindings) { @@ -29,7 +36,7 @@ namespace Metal { } if (needsUpdate) { - DescriptorSetService::Write(descriptor->vkDescriptorSet, descriptor->bindings); + DescriptorSetService::Write(vulkanContext, bufferService, descriptor->vkDescriptorSet, descriptor->bindings); } } } @@ -45,12 +52,12 @@ namespace Metal { } anyMeshes = false; // Check if any mesh is present and streamed - auto view = CTX.worldRepository.registry.view(); + auto view = worldRepository.registry.view(); for (auto entity: view) { - if (CTX.worldRepository.hiddenEntities.contains(entity)) continue; + if (worldRepository.hiddenEntities.contains(entity)) continue; auto &meshComp = view.get(entity); if (meshComp.meshId.empty()) continue; - auto *instance = CTX.meshService.stream(meshComp.meshId); + auto *instance = meshService.stream(meshComp.meshId); if (instance != nullptr && instance->dataBuffer != nullptr && instance->indexBuffer != nullptr) { anyMeshes = true; break; @@ -89,21 +96,21 @@ namespace Metal { void RayTracingService::updateMeshMaterials() { bool changed = false; - auto view = CTX.worldRepository.registry.view(); + auto view = worldRepository.registry.view(); for (auto entity: view) { - if (CTX.worldRepository.hiddenEntities.contains(entity)) continue; + if (worldRepository.hiddenEntities.contains(entity)) continue; auto &meshComp = view.get(entity); if (meshComp.meshId.empty()) continue; if (meshComp.renderIndex < meshMetadata.size()) { - CTX.materialService.load(meshMetadata[meshComp.renderIndex], meshComp); + materialService.load(meshMetadata[meshComp.renderIndex], meshComp); changed = true; } } if (changed) { - for (auto *frame : CTX.engineContext.registeredFrames) { + for (auto *frame : engineContext.registeredFrames) { auto *meshMetadataBuffer = frame->getResourceAs(RID_MESH_METADATA_BUFFER); if (meshMetadataBuffer != nullptr) { meshMetadataBuffer->update(meshMetadata.data()); @@ -113,7 +120,7 @@ namespace Metal { } void RayTracingService::destroyTLAS() { - auto &vulkan = CTX.vulkanContext; + auto &vulkan = vulkanContext; if (vulkan.device.device != VK_NULL_HANDLE) { vkDeviceWaitIdle(vulkan.device.device); } @@ -124,15 +131,15 @@ namespace Metal { } if (tlasBuffer) { - CTX.bufferService.dispose("tlas_buffer"); + bufferService.dispose("tlas_buffer"); tlasBuffer = nullptr; } if (instancesBuffer) { - CTX.bufferService.dispose("tlas_instances"); + bufferService.dispose("tlas_instances"); instancesBuffer = nullptr; } if (tlasScratchBuffer) { - CTX.bufferService.dispose("tlas_scratch"); + bufferService.dispose("tlas_scratch"); tlasScratchBuffer = nullptr; } @@ -140,18 +147,18 @@ namespace Metal { } void RayTracingService::buildBLAS() { - auto &vulkan = CTX.vulkanContext; + auto &vulkan = vulkanContext; std::unordered_map uniqueMeshes; - auto view = CTX.worldRepository.registry.view(); + auto view = worldRepository.registry.view(); for (auto entity: view) { - if (CTX.worldRepository.hiddenEntities.contains(entity)) continue; + if (worldRepository.hiddenEntities.contains(entity)) continue; auto &meshComp = view.get(entity); if (meshComp.meshId.empty()) continue; if (uniqueMeshes.contains(meshComp.meshId)) continue; - auto *instance = CTX.meshService.stream(meshComp.meshId); + auto *instance = meshService.stream(meshComp.meshId); if (instance == nullptr || instance->dataBuffer == nullptr || instance->indexBuffer == nullptr) { continue; } @@ -173,9 +180,9 @@ namespace Metal { nullptr); } if (existing.buffer) - CTX.bufferService.dispose("blas_" + meshId); + bufferService.dispose("blas_" + meshId); if (existing.scratchBuffer) - CTX.bufferService.dispose("blas_scratch_" + meshId); + bufferService.dispose("blas_scratch_" + meshId); blasEntries.erase(meshId); } VkDeviceAddress vertexAddress = getDeviceAddress(vulkan, instance->dataBuffer->vkBuffer); @@ -214,14 +221,14 @@ namespace Metal { &sizeInfo); BLASEntry entry; - entry.buffer = CTX.bufferService.createBuffer( + entry.buffer = bufferService.createBuffer( "blas_" + meshId, sizeInfo.accelerationStructureSize, VK_BUFFER_USAGE_ACCELERATION_STRUCTURE_STORAGE_BIT_KHR, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, true); - entry.scratchBuffer = CTX.bufferService.createBuffer( + entry.scratchBuffer = bufferService.createBuffer( "blas_scratch_" + meshId, sizeInfo.buildScratchSize, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, @@ -258,7 +265,7 @@ namespace Metal { } void RayTracingService::buildTLAS() { - auto &vulkan = CTX.vulkanContext; + auto &vulkan = vulkanContext; meshMetadata.clear(); if (blasEntries.empty()) return; @@ -267,7 +274,7 @@ namespace Metal { } std::vector instances; - auto view = CTX.worldRepository.registry.view(); + auto view = worldRepository.registry.view(); unsigned int currentInstanceIndex = 0; for (auto entity: view) { @@ -275,7 +282,7 @@ namespace Metal { LOG_ERROR("Max mesh instances reached for ray tracing: " + std::to_string(MAX_MESH_INSTANCES)); break; } - if (CTX.worldRepository.hiddenEntities.contains(entity)) continue; + if (worldRepository.hiddenEntities.contains(entity)) continue; auto &meshComp = view.get(entity); if (meshComp.meshId.empty()) continue; @@ -290,8 +297,8 @@ namespace Metal { vulkan.device.device, &addressInfo); glm::mat4 model = glm::mat4(1.0f); - if (CTX.worldRepository.registry.all_of(entity)) { - model = CTX.worldRepository.registry.get(entity).model; + if (worldRepository.registry.all_of(entity)) { + model = worldRepository.registry.get(entity).model; } VkTransformMatrixKHR transform{}; @@ -324,7 +331,7 @@ namespace Metal { updateMeshMaterials(); - instancesBuffer = CTX.bufferService.createBuffer( + instancesBuffer = bufferService.createBuffer( "tlas_instances", sizeof(VkAccelerationStructureInstanceKHR) * instances.size(), VK_BUFFER_USAGE_ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY_BIT_KHR, @@ -360,7 +367,7 @@ namespace Metal { &instanceCount, &sizeInfo); - tlasBuffer = CTX.bufferService.createBuffer( + tlasBuffer = bufferService.createBuffer( "tlas_buffer", sizeInfo.accelerationStructureSize, VK_BUFFER_USAGE_ACCELERATION_STRUCTURE_STORAGE_BIT_KHR, @@ -375,7 +382,7 @@ namespace Metal { VulkanUtils::CheckVKResult( vulkan.vkCreateAccelerationStructureKHR(vulkan.device.device, &createInfo, nullptr, &tlas)); - tlasScratchBuffer = CTX.bufferService.createBuffer( + tlasScratchBuffer = bufferService.createBuffer( "tlas_scratch", sizeInfo.buildScratchSize, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, @@ -396,7 +403,7 @@ namespace Metal { void RayTracingService::destroyAccelerationStructures() { LOG_INFO("Destroying acceleration structures"); - auto &vulkan = CTX.vulkanContext; + auto &vulkan = vulkanContext; if (vulkan.device.device != VK_NULL_HANDLE) { vkDeviceWaitIdle(vulkan.device.device); @@ -412,9 +419,9 @@ namespace Metal { entry.accelerationStructure = VK_NULL_HANDLE; } if (entry.buffer) - CTX.bufferService.dispose("blas_" + meshId); + bufferService.dispose("blas_" + meshId); if (entry.scratchBuffer) - CTX.bufferService.dispose("blas_scratch_" + meshId); + bufferService.dispose("blas_scratch_" + meshId); } blasEntries.clear(); diff --git a/src/engine/service/RayTracingService.h b/src/engine/service/RayTracingService.h index e4b35fa7..7d90afd3 100644 --- a/src/engine/service/RayTracingService.h +++ b/src/engine/service/RayTracingService.h @@ -11,9 +11,24 @@ #include "../../common/AbstractRuntimeComponent.h" namespace Metal { - struct BufferInstance; + class BufferInstance; + class VulkanContext; + class PipelineService; + struct WorldRepository; + class MeshService; + class MaterialService; + class BufferService; + class EngineContext; class RayTracingService final : public AbstractRuntimeComponent { + VulkanContext &vulkanContext; + PipelineService &pipelineService; + WorldRepository &worldRepository; + MeshService &meshService; + MaterialService &materialService; + BufferService &bufferService; + EngineContext &engineContext; + struct BLASEntry { VkAccelerationStructureKHR accelerationStructure = VK_NULL_HANDLE; BufferInstance *buffer = nullptr; @@ -51,6 +66,9 @@ namespace Metal { void updateMeshMaterials(); public: + RayTracingService(VulkanContext &vulkanContext, PipelineService &pipelineService, WorldRepository &worldRepository, MeshService &meshService, MaterialService &materialService, BufferService &bufferService, EngineContext &engineContext) + : vulkanContext(vulkanContext), pipelineService(pipelineService), worldRepository(worldRepository), meshService(meshService), materialService(materialService), bufferService(bufferService), engineContext(engineContext) {} + RayTracingService() = delete; void setNeedsMaterialUpdate(bool val) { needsMaterialUpdate = val; diff --git a/src/engine/service/StreamingService.cpp b/src/engine/service/StreamingService.cpp index 48895cb4..e5a04f37 100644 --- a/src/engine/service/StreamingService.cpp +++ b/src/engine/service/StreamingService.cpp @@ -1,6 +1,12 @@ #include "StreamingService.h" +#include "../EngineContext.h" +#include "../repository/WorldRepository.h" +#include "MeshService.h" +#include "TextureService.h" +#include "VoxelService.h" #include "../../ApplicationContext.h" + #include "../resource/SVOInstance.h" #include "../resource/MeshInstance.h" #include "../resource/TextureInstance.h" @@ -11,13 +17,13 @@ namespace Metal { static constexpr int MAX_TIMEOUT = 10000; template - void disposeResources(AbstractResourceService &service, std::unordered_map &lastUse) { + void disposeResources(AbstractResourceService &service, std::unordered_map &lastUse, EngineContext &engineContext) { auto &resources = service.getResources(); for (auto it = resources.begin(); it != resources.end();) { if (lastUse.contains(it->second->getId()) && !it->second->isNoDisposal() && ( - CTX.engineContext.currentTimeMs - lastUse.at(it->second->getId())) >= MAX_TIMEOUT) { + engineContext.currentTimeMs - lastUse.at(it->second->getId())) >= MAX_TIMEOUT) { LOG_DEBUG( - "Disposing of " + it->first + " Since last use: " + std::to_string(CTX.engineContext.currentTimeMs - + "Disposing of " + it->first + " Since last use: " + std::to_string(engineContext.currentTimeMs - lastUse.at(it->second->getId()))); std::string id = it->first; ++it; @@ -29,28 +35,28 @@ namespace Metal { } void StreamingService::onSync() { - auto view = CTX.worldRepository.registry.view(); + auto view = worldRepository.registry.view(); for (auto entity: view) { auto &meshComp = view.get(entity); if (!meshComp.meshId.empty()) { - lastUse[meshComp.meshId] = CTX.engineContext.currentTimeMs; + lastUse[meshComp.meshId] = engineContext.currentTimeMs; } if (!meshComp.albedo.empty()) { - lastUse[meshComp.albedo] = CTX.engineContext.currentTimeMs; + lastUse[meshComp.albedo] = engineContext.currentTimeMs; } if (!meshComp.roughness.empty()) { - lastUse[meshComp.roughness] = CTX.engineContext.currentTimeMs; + lastUse[meshComp.roughness] = engineContext.currentTimeMs; } if (!meshComp.metallic.empty()) { - lastUse[meshComp.metallic] = CTX.engineContext.currentTimeMs; + lastUse[meshComp.metallic] = engineContext.currentTimeMs; } } - if ((CTX.engineContext.currentTime - sinceLastCleanup).count() >= MAX_TIMEOUT) { - sinceLastCleanup = CTX.engineContext.currentTime; - disposeResources(CTX.meshService, lastUse); - disposeResources(CTX.textureService, lastUse); - disposeResources(CTX.voxelService, lastUse); + if ((engineContext.currentTime - sinceLastCleanup).count() >= MAX_TIMEOUT) { + sinceLastCleanup = engineContext.currentTime; + disposeResources(meshService, lastUse, engineContext); + disposeResources(textureService, lastUse, engineContext); + disposeResources(voxelService, lastUse, engineContext); } } } diff --git a/src/engine/service/StreamingService.h b/src/engine/service/StreamingService.h index ccd7e5af..d93c7568 100644 --- a/src/engine/service/StreamingService.h +++ b/src/engine/service/StreamingService.h @@ -14,12 +14,26 @@ namespace Metal { struct MeshInstance; struct TextureInstance; struct SVOInstance; + class EngineContext; + struct WorldRepository; + class MeshService; + class TextureService; + class VoxelService; class StreamingService final : public AbstractRuntimeComponent { std::unordered_map lastUse{}; TimePoint sinceLastCleanup; + EngineContext &engineContext; + WorldRepository &worldRepository; + MeshService &meshService; + TextureService &textureService; + VoxelService &voxelService; + public: + StreamingService(EngineContext &engineContext, WorldRepository &worldRepository, MeshService &meshService, TextureService &textureService, VoxelService &voxelService) + : engineContext(engineContext), worldRepository(worldRepository), meshService(meshService), textureService(textureService), voxelService(voxelService) {} + void onSync() override; }; } // Metal diff --git a/src/engine/service/TextureService.cpp b/src/engine/service/TextureService.cpp index 8f20419f..1e045dec 100644 --- a/src/engine/service/TextureService.cpp +++ b/src/engine/service/TextureService.cpp @@ -1,21 +1,29 @@ #include "TextureService.h" #include +#include #include "../util/ImageUtils.h" +#include "../../editor/enum/engine-definitions.h" +#include "../../ApplicationContext.h" #include #include #include "../dto/TextureData.h" -#include "../../ApplicationContext.h" +#include "../../core/vulkan/VulkanContext.h" +#include "../../core/vulkan/VulkanUtils.h" #include "../resource/TextureInstance.h" #include "../resource/BufferInstance.h" +#include "BufferService.h" +#include "PipelineService.h" +#include "DescriptorSetService.h" +#include "../dto/DescriptorInstance.h" namespace Metal { void TextureService::copyBufferToImage(const VkBuffer &vkBuffer, const TextureInstance *image, const int layerCount) const { - VkCommandBuffer commandBuffer = CTX.vulkanContext.beginSingleTimeCommands(); + VkCommandBuffer commandBuffer = vulkanContext.beginSingleTimeCommands(); VkBufferImageCopy region{}; region.bufferOffset = 0; @@ -37,31 +45,31 @@ namespace Metal { VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, ®ion); - CTX.vulkanContext.endSingleTimeCommands(commandBuffer); + vulkanContext.endSingleTimeCommands(commandBuffer); } void TextureService::createImageWithInfo(const VkImageCreateInfo &imageInfo, VkMemoryPropertyFlagBits vkMemoryProperties, TextureInstance *image) const { - if (vkCreateImage(CTX.vulkanContext.device.device, &imageInfo, nullptr, &image->vkImage) != VK_SUCCESS) { + if (vkCreateImage(vulkanContext.device.device, &imageInfo, nullptr, &image->vkImage) != VK_SUCCESS) { throw std::runtime_error("failed to create image!"); } VkMemoryRequirements memRequirements; - vkGetImageMemoryRequirements(CTX.vulkanContext.device.device, image->vkImage, &memRequirements); + vkGetImageMemoryRequirements(vulkanContext.device.device, image->vkImage, &memRequirements); VkMemoryAllocateInfo allocInfo{}; allocInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; allocInfo.allocationSize = memRequirements.size; - allocInfo.memoryTypeIndex = CTX.bufferService.findMemoryType( + allocInfo.memoryTypeIndex = bufferService.findMemoryType( memRequirements.memoryTypeBits, vkMemoryProperties); - if (vkAllocateMemory(CTX.vulkanContext.device.device, &allocInfo, nullptr, &image->vkImageMemory) != + if (vkAllocateMemory(vulkanContext.device.device, &allocInfo, nullptr, &image->vkImageMemory) != VK_SUCCESS) { throw std::runtime_error("failed to allocate image memory!"); } - if (vkBindImageMemory(CTX.vulkanContext.device.device, image->vkImage, image->vkImageMemory, 0) != + if (vkBindImageMemory(vulkanContext.device.device, image->vkImage, image->vkImageMemory, 0) != VK_SUCCESS) { throw std::runtime_error("failed to bind image memory!"); } @@ -84,7 +92,7 @@ namespace Metal { samplerInfo.anisotropyEnable = VK_TRUE; samplerInfo.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; - vkCreateSampler(CTX.vulkanContext.device.device, &samplerInfo, nullptr, &image->vkSampler); + vkCreateSampler(vulkanContext.device.device, &samplerInfo, nullptr, &image->vkSampler); } void TextureService::createImageView(VkFormat imageFormat, TextureInstance *image) const { @@ -102,7 +110,7 @@ namespace Metal { imageViewInfo.subresourceRange.levelCount = image->mipLevels; imageViewInfo.image = image->vkImage; - vkCreateImageView(CTX.vulkanContext.device.device, &imageViewInfo, nullptr, &image->vkImageView); + vkCreateImageView(vulkanContext.device.device, &imageViewInfo, nullptr, &image->vkImageView); } void TextureService::createImage(VkFormat imageFormat, TextureInstance *image, const int width, @@ -125,7 +133,7 @@ namespace Metal { } TextureData *TextureService::loadTextureData(const std::string &id) const { - auto pathToFile = CTX.getAssetDirectory() + FORMAT_FILE_TEXTURE(id); + auto pathToFile = rootDirectory + "/assets/" + FORMAT_FILE_TEXTURE(id); if (std::filesystem::exists(pathToFile)) { int width, height, channels; unsigned char *data = stbi_load(pathToFile.c_str(), &width, &height, &channels, 0); @@ -163,7 +171,7 @@ namespace Metal { image->vkFormat = imageFormat; LOG_INFO("Loading texture " + id + " from " + pathToImage); LOG_INFO("Texture data: Width " + std::to_string(image->width) + " Height " + std::to_string(image->height)); - BufferInstance *stagingBuffer = CTX.bufferService.createBuffer( + BufferInstance *stagingBuffer = bufferService.createBuffer( id + "_staging", image->width * image->height * 4, VK_BUFFER_USAGE_TRANSFER_SRC_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT); @@ -184,7 +192,7 @@ namespace Metal { void TextureService::transitionImageLayout(const TextureInstance *image, VkImageLayout oldLayout, VkImageLayout newLayout) const { - VkCommandBuffer commandBuffer = CTX.vulkanContext.beginSingleTimeCommands(); + VkCommandBuffer commandBuffer = vulkanContext.beginSingleTimeCommands(); VkImageMemoryBarrier barrier{}; barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; barrier.oldLayout = oldLayout; @@ -235,19 +243,19 @@ namespace Metal { 0, nullptr, 1, &barrier); - CTX.vulkanContext.endSingleTimeCommands(commandBuffer); + vulkanContext.endSingleTimeCommands(commandBuffer); } void TextureService::generateMipmaps(const TextureInstance *image) const { VkFormatProperties formatProperties; - vkGetPhysicalDeviceFormatProperties(CTX.vulkanContext.physDevice.physical_device, image->vkFormat, + vkGetPhysicalDeviceFormatProperties(vulkanContext.physDevice.physical_device, image->vkFormat, &formatProperties); if (!(formatProperties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT)) { throw std::runtime_error("texture image format does not support linear blitting!"); } - VkCommandBuffer commandBuffer = CTX.vulkanContext.beginSingleTimeCommands(); + VkCommandBuffer commandBuffer = vulkanContext.beginSingleTimeCommands(); VkImageMemoryBarrier barrier{}; barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; @@ -310,11 +318,11 @@ namespace Metal { vkCmdPipelineBarrier(commandBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 1, &barrier); - CTX.vulkanContext.endSingleTimeCommands(commandBuffer); + vulkanContext.endSingleTimeCommands(commandBuffer); } TextureInstance *TextureService::create(const std::string &id) { - auto pathToFile = CTX.getAssetDirectory() + FORMAT_FILE_TEXTURE(id); + auto pathToFile = rootDirectory + "/assets/" + FORMAT_FILE_TEXTURE(id); if (std::filesystem::exists(pathToFile)) { auto *instance = loadTexture(id, pathToFile, true, VK_FORMAT_R8G8B8A8_UNORM); if (instance != nullptr) { @@ -363,7 +371,7 @@ namespace Metal { textureIndices[id] = index; // Update all descriptors that contain a texture array - auto descriptors = CTX.pipelineService.getAllDescriptors(); + auto descriptors = pipelineService.getAllDescriptors(); for (auto *descriptor: descriptors) { for (auto &binding: descriptor->bindings) { if (binding.descriptorType == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER && binding.descriptorCount > 1) { @@ -376,12 +384,12 @@ namespace Metal { write.descriptorCount = 1; VkDescriptorImageInfo imageInfo{}; - imageInfo.sampler = CTX.vulkanContext.vkTextureSampler; + imageInfo.sampler = vulkanContext.vkTextureSampler; imageInfo.imageView = texture->vkImageView; imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; write.pImageInfo = &imageInfo; - vkUpdateDescriptorSets(CTX.vulkanContext.device.device, 1, &write, 0, nullptr); + vkUpdateDescriptorSets(vulkanContext.device.device, 1, &write, 0, nullptr); } } } @@ -392,13 +400,13 @@ namespace Metal { } void TextureService::disposeResource(TextureInstance *resource) { - vkDestroyImage(CTX.vulkanContext.device.device, resource->vkImage, nullptr); - vkFreeMemory(CTX.vulkanContext.device.device, resource->vkImageMemory, nullptr); - vkDestroyImageView(CTX.vulkanContext.device.device, resource->vkImageView, nullptr); - vkDestroySampler(CTX.vulkanContext.device.device, resource->vkSampler, nullptr); + vkDestroyImage(vulkanContext.device.device, resource->vkImage, nullptr); + vkFreeMemory(vulkanContext.device.device, resource->vkImageMemory, nullptr); + vkDestroyImageView(vulkanContext.device.device, resource->vkImageView, nullptr); + vkDestroySampler(vulkanContext.device.device, resource->vkSampler, nullptr); if (resource->imageDescriptor != nullptr) { - CTX.descriptorSetService.disposeResource(resource->imageDescriptor); + descriptorSetService.disposeResource(resource->imageDescriptor); } } @@ -418,7 +426,7 @@ namespace Metal { samplerCreateInfo.maxAnisotropy = 8; samplerCreateInfo.anisotropyEnable = VK_TRUE; samplerCreateInfo.borderColor = VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK; - VulkanUtils::CheckVKResult(vkCreateSampler(CTX.vulkanContext.device.device, &samplerCreateInfo, nullptr, + VulkanUtils::CheckVKResult(vkCreateSampler(vulkanContext.device.device, &samplerCreateInfo, nullptr, &vkImageSampler)); } diff --git a/src/engine/service/TextureService.h b/src/engine/service/TextureService.h index e1eff442..891f847d 100644 --- a/src/engine/service/TextureService.h +++ b/src/engine/service/TextureService.h @@ -10,8 +10,17 @@ namespace Metal { struct TextureInstance; + class BufferService; + class PipelineService; + class DescriptorSetService; class TextureService final : public AbstractResourceService { + VulkanContext &vulkanContext; + BufferService &bufferService; + PipelineService &pipelineService; + DescriptorSetService &descriptorSetService; + const std::string &rootDirectory; + unsigned int nextTextureIndex = 1; std::unordered_map textureIndices{}; @@ -32,6 +41,10 @@ namespace Metal { void generateMipmaps(const TextureInstance *image) const; public: + TextureService(VulkanContext &vulkanContext, BufferService &bufferService, PipelineService &pipelineService, DescriptorSetService &descriptorSetService, const std::string &rootDirectory) + : vulkanContext(vulkanContext), bufferService(bufferService), pipelineService(pipelineService), descriptorSetService(descriptorSetService), rootDirectory(rootDirectory) {} + TextureService() = delete; + [[nodiscard]] TextureData *loadTextureData(const std::string &id) const; TextureInstance *stream(const std::string &id); diff --git a/src/engine/service/TransformService.cpp b/src/engine/service/TransformService.cpp index 5dfdc638..4e201f84 100644 --- a/src/engine/service/TransformService.cpp +++ b/src/engine/service/TransformService.cpp @@ -5,11 +5,13 @@ #include "../../ApplicationContext.h" #include "../dto/TransformComponent.h" +#include "../repository/WorldRepository.h" +#include "RayTracingService.h" namespace Metal { void TransformService::onSync() { - for (auto entity : CTX.worldRepository.registry.view()) { - TransformComponent &st = CTX.worldRepository.registry.get(entity); + for (auto entity : worldRepository.registry.view()) { + TransformComponent &st = worldRepository.registry.get(entity); if (st.isNotFrozen()) { transform(&st, nullptr); st.freezeVersion(); @@ -36,8 +38,8 @@ namespace Metal { st->model = auxMat4 * auxMat42; st->freezeVersion(); - if (CTX.worldRepository.registry.all_of(st->getEntityId())) { - CTX.rayTracingService.markDirty(); + if (worldRepository.registry.all_of(st->getEntityId())) { + rayTracingService.markDirty(); } } } // Metal diff --git a/src/engine/service/TransformService.h b/src/engine/service/TransformService.h index ff399b3e..3149e81c 100644 --- a/src/engine/service/TransformService.h +++ b/src/engine/service/TransformService.h @@ -10,13 +10,23 @@ namespace Metal { struct TransformComponent; + struct TransformComponent; + struct WorldRepository; + class RayTracingService; + class TransformService final : AbstractRuntimeComponent { + WorldRepository &worldRepository; + RayTracingService &rayTracingService; + glm::vec3 distanceAux{}; glm::mat4x4 auxMat4{}; glm::vec3 translation{}; glm::mat4x4 auxMat42{}; public: + explicit TransformService(WorldRepository &worldRepository, RayTracingService &rayTracingService) + : worldRepository(worldRepository), rayTracingService(rayTracingService) {} + TransformService() = delete; void onSync() override; diff --git a/src/engine/service/VolumeService.cpp b/src/engine/service/VolumeService.cpp index 2f5cde9f..d04c4454 100644 --- a/src/engine/service/VolumeService.cpp +++ b/src/engine/service/VolumeService.cpp @@ -3,12 +3,14 @@ #include "../dto/VolumeComponent.h" #include "../resource/BufferInstance.h" #include "../../editor/enum/EngineResourceIDs.h" +#include "../repository/WorldRepository.h" +#include "../EngineContext.h" namespace Metal { void VolumeService::registerVolumes() { - auto view = CTX.worldRepository.registry.view(); + auto view = worldRepository.registry.view(); for (auto [entityId, l, t]: view.each()) { - if (CTX.worldRepository.hiddenEntities.contains(entityId)) { + if (worldRepository.hiddenEntities.contains(entityId)) { continue; } @@ -30,7 +32,7 @@ namespace Metal { registerVolumes(); if (!items.empty()) { - CTX.engineContext.currentFrame->getResourceAs(RID_VOLUMES_BUFFER)->update(items.data()); + engineContext.currentFrame->getResourceAs(RID_VOLUMES_BUFFER)->update(items.data()); } } } // Metal diff --git a/src/engine/service/VolumeService.h b/src/engine/service/VolumeService.h index 2feafe3e..60d32fed 100644 --- a/src/engine/service/VolumeService.h +++ b/src/engine/service/VolumeService.h @@ -7,11 +7,20 @@ namespace Metal { + struct WorldRepository; + class EngineContext; + class VolumeService final : public AbstractRuntimeComponent { + WorldRepository &worldRepository; + EngineContext &engineContext; + std::vector items{}; void registerVolumes(); public: + explicit VolumeService(WorldRepository &worldRepository, EngineContext &engineContext) + : worldRepository(worldRepository), engineContext(engineContext) {} + VolumeService() = delete; void onSync() override; From c919b2a2ac500be22d3f6df8074ddec4d5aa8bc9 Mon Sep 17 00:00:00 2001 From: facobackup Date: Sat, 14 Mar 2026 10:06:11 -0300 Subject: [PATCH 11/18] Refactoring frame builder Continuing refactoring of ApplicationContext --- CMakeLists.txt | 7 +- src/ApplicationContext.cpp | 12 --- src/ApplicationContext.h | 96 ++++++++++--------- src/core/glfw/GLFWContext.cpp | 23 ++--- src/core/glfw/GLFWContext.h | 7 ++ src/core/gui/GuiContext.cpp | 40 +++++--- src/core/gui/GuiContext.h | 11 ++- src/core/vulkan/VulkanContext.cpp | 57 +++++++---- src/core/vulkan/VulkanContext.h | 27 +++++- .../dock-spaces/docks/DockSpacePanel.cpp | 6 +- .../dock-spaces/files/FilesHeaderPanel.cpp | 16 +++- .../dock-spaces/files/FilesHeaderPanel.h | 1 - .../dock-spaces/viewport/EngineFramePanel.cpp | 39 +++++--- src/editor/dto/DockSpace.cpp | 29 +++--- src/editor/dto/DockSpace.h | 4 +- src/editor/enum/EntryType.h | 61 +++++------- src/editor/passes/GridPass.h | 2 - src/editor/passes/IconsPass.cpp | 27 ------ src/editor/passes/IconsPass.h | 18 ---- src/editor/passes/SelectionIDPass.h | 1 - src/editor/passes/SelectionOutlinePass.h | 2 - src/editor/repository/EditorRepository.cpp | 6 +- src/editor/service/DockService.cpp | 1 - src/editor/service/DockService.h | 5 + src/editor/service/ThemeService.cpp | 1 - src/editor/service/ThemeService.h | 5 +- src/engine/dto/PrimitiveComponent.cpp | 23 ++--- src/engine/enum/PassType.h | 18 ---- src/engine/enum/ResourceType.h | 3 +- src/engine/frame-builder/EngineFrame.cpp | 13 +-- src/engine/frame-builder/EngineFrame.h | 14 +-- .../frame-builder/EngineFrameBuilder.cpp | 31 +++--- src/engine/frame-builder/EngineFrameBuilder.h | 9 +- .../structures/BufferBuilder.cpp | 2 +- .../frame-builder/structures/PassBuilder.cpp | 34 ------- .../frame-builder/structures/PassBuilder.h | 35 ------- src/engine/passes/AbstractComputePass.cpp | 2 +- src/engine/passes/AbstractComputePass.h | 2 +- src/engine/passes/AbstractPass.cpp | 9 +- src/engine/passes/AbstractPass.h | 12 +-- src/engine/passes/AbstractRenderPass.cpp | 2 +- src/engine/passes/AbstractRenderPass.h | 2 +- src/engine/passes/CommandBufferRecorder.cpp | 4 +- src/engine/passes/CommandBufferRecorder.h | 4 +- src/engine/passes/impl/HWRayTracingPass.h | 3 - src/engine/passes/impl/PostProcessingPass.h | 2 - src/engine/passes/impl/SpatialFilterPass.h | 3 - .../passes/impl/TemporalAccumulationPass.h | 2 - src/engine/service/PipelineService.cpp | 14 +-- src/engine/service/PipelineService.h | 11 ++- .../ShaderService.cpp} | 30 +++--- src/engine/service/ShaderService.h | 34 +++++++ src/engine/service/StreamingService.h | 3 +- src/engine/util/ShaderUtil.h | 27 ------ 54 files changed, 375 insertions(+), 477 deletions(-) delete mode 100644 src/editor/passes/IconsPass.cpp delete mode 100644 src/editor/passes/IconsPass.h delete mode 100644 src/engine/enum/PassType.h delete mode 100644 src/engine/frame-builder/structures/PassBuilder.cpp delete mode 100644 src/engine/frame-builder/structures/PassBuilder.h rename src/engine/{util/ShaderUtil.cpp => service/ShaderService.cpp} (88%) create mode 100644 src/engine/service/ShaderService.h delete mode 100644 src/engine/util/ShaderUtil.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 9fa89d53..50fc7887 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -89,8 +89,8 @@ add_executable( src/editor/dock-spaces/world/WorldPanel.cpp src/editor/dock-spaces/world/WorldPanel.h src/engine/resource/RuntimeResource.h - src/engine/util/ShaderUtil.cpp - src/engine/util/ShaderUtil.h + src/engine/service/ShaderService.cpp + src/engine/service/ShaderService.h src/engine/dto/ShaderModule.cpp src/engine/dto/ShaderModule.h src/engine/passes/AbstractRenderPass.cpp @@ -225,8 +225,6 @@ add_executable( src/engine/resource/SVOInstance.h src/engine/dto/TileInfoUBO.h src/engine/dto/LightData.h - src/editor/passes/IconsPass.cpp - src/editor/passes/IconsPass.h src/editor/passes/SelectionIDPass.cpp src/editor/passes/SelectionIDPass.h src/editor/repository/EditorRepository.cpp @@ -270,7 +268,6 @@ add_executable( src/engine/frame-builder/structures/ResourceBuilder.h src/engine/dto/PipelineBuilder.cpp src/engine/service/DescriptorSetService.cpp - src/engine/frame-builder/structures/PassBuilder.cpp src/engine/frame-builder/structures/CommandBufferRecorderBuilder.cpp src/common/Changeable.h src/engine/passes/impl/TemporalAccumulationPass.cpp diff --git a/src/ApplicationContext.cpp b/src/ApplicationContext.cpp index 9aff2362..8c794998 100644 --- a/src/ApplicationContext.cpp +++ b/src/ApplicationContext.cpp @@ -11,18 +11,6 @@ #include namespace Metal { - std::unique_ptr ApplicationContext::CONTEXT = nullptr; - - ApplicationContext &ApplicationContext::Get() { - if (CONTEXT == nullptr) { - throw std::runtime_error("Context not initialized"); - } - return *CONTEXT; - } - - void ApplicationContext::Init(bool debugMode) { - CONTEXT = std::make_unique(debugMode); - } void ApplicationContext::updateRootPath(bool forceSelection) { std::string cachedPath; diff --git a/src/ApplicationContext.h b/src/ApplicationContext.h index 3e0f075e..78774aa7 100644 --- a/src/ApplicationContext.h +++ b/src/ApplicationContext.h @@ -44,70 +44,80 @@ #include "editor/EditorPanel.h" #include "core/gui/GuiContext.h" -#define CTX Metal::ApplicationContext::Get() - +#define CTX ApplicationContext::CONTEXT namespace Metal { - class ApplicationContext { - static std::unique_ptr CONTEXT; - bool debugMode; + class ApplicationContext : public Initializable{ EditorPanel editorPanel; std::string rootDirectory; public: - explicit ApplicationContext(bool debug_mode) - : debugMode(debug_mode) { - } - - EngineContext engineContext{}; - VulkanContext vulkanContext{ debugMode}; - GuiContext guiContext{}; + static ApplicationContext CONTEXT; + + VulkanContext vulkanContext{ + true, + glfwContext, + engineRepository, + meshService, + textureService, + framebufferService, + pipelineService, + rayTracingService + }; + GuiContext guiContext{vulkanContext, glfwContext, descriptorSetService}; GLFWContext glfwContext{}; + EngineContext engineContext{ + transformService, + streamingService, + rayTracingService, + cameraService, + lightService, + volumeService, + worldRepository, + editorRepository, + engineRepository + }; + + // ----------- Repository + WorldRepository worldRepository{rayTracingService, rootDirectory}; + RuntimeRepository runtimeRepository{}; + EngineRepository engineRepository{}; + DockRepository dockRepository{}; + EditorRepository editorRepository{}; + // ----------- Services NotificationService notificationService; AsyncTaskService asyncTaskService; - MeshService meshService{bufferService, rayTracingService, rootDirectory}; - MaterialService materialService{textureService}; - TextureService textureService{vulkanContext, bufferService, pipelineService, descriptorSetService, rootDirectory}; + BufferService bufferService{vulkanContext}; FrameBufferService framebufferService{vulkanContext}; + ThemeService themeService{editorRepository}; + DockService dockService{dockRepository}; DescriptorSetService descriptorSetService{vulkanContext, framebufferService, bufferService, textureService}; - PipelineService pipelineService{vulkanContext, framebufferService, bufferService, descriptorSetService}; - BufferService bufferService{vulkanContext}; - ThemeService themeService{}; - DockService dockService{}; - SelectionService selectionService{}; - SceneImporterService sceneImporterService{}; - MeshImporterService meshImporterService{}; - MaterialImporterService materialImporterService{}; - TextureImporterService textureImporter{}; - FilesService filesService{}; - FileImporterService fileImporterService{}; + SelectionService selectionService{editorRepository, worldRepository}; + VoxelImporterService voxelImporterService{rootDirectory}; + MeshImporterService meshImporterService{rootDirectory}; + TextureImporterService textureImporter{rootDirectory}; + MaterialImporterService materialImporterService{textureImporter, rootDirectory}; + SceneImporterService sceneImporterService{meshImporterService, materialImporterService, rootDirectory}; + FilesService filesService{rootDirectory, notificationService}; + FileImporterService fileImporterService{ + sceneImporterService, textureImporter, voxelImporterService, notificationService, asyncTaskService + }; CameraService cameraService{engineContext, worldRepository, runtimeRepository}; - PickingService pickingService{}; + PickingService pickingService{vulkanContext, bufferService, worldRepository}; TransformService transformService{worldRepository, rayTracingService}; LightService lightService{engineContext, engineRepository}; VolumeService volumeService{worldRepository, engineContext}; - RayTracingService rayTracingService{vulkanContext, pipelineService, worldRepository, meshService, materialService, bufferService, engineContext}; + RayTracingService rayTracingService{ + vulkanContext, pipelineService, worldRepository, meshService, materialService, bufferService, engineContext + }; CommandBufferRecorderService commandBufferRecorderService{}; - VoxelImporterService voxelImporterService{rootDirectory}; VoxelService voxelService{}; - // ----------- Services - - // ----------- Repository - WorldRepository worldRepository{}; - RuntimeRepository runtimeRepository{}; StreamingService streamingService{engineContext, worldRepository, meshService, textureService, voxelService}; - EngineRepository engineRepository{}; - DockRepository dockRepository{}; - EditorRepository editorRepository{}; + // ----------- Services // ----------- Repository - - static ApplicationContext &Get(); - - static void Init(bool debugMode); - - [[nodiscard]] bool isDebugMode() const { return debugMode; } + [[nodiscard]] bool isDebugMode() const { return true; } void updateRootPath(bool forceSelection); diff --git a/src/core/glfw/GLFWContext.cpp b/src/core/glfw/GLFWContext.cpp index 9ebba466..4c489631 100644 --- a/src/core/glfw/GLFWContext.cpp +++ b/src/core/glfw/GLFWContext.cpp @@ -2,6 +2,7 @@ #include "GLFWContext.h" #include "../../ApplicationContext.h" #include "../vulkan/VulkanUtils.h" +#include "../vulkan/VulkanContext.h" namespace Metal { GLFWwindow *GLFWContext::getWindow() const { @@ -19,19 +20,19 @@ namespace Metal { int fb_width, fb_height; glfwGetFramebufferSize(window, &fb_width, &fb_height); if (fb_width > 0 && fb_height > 0 && - (swapChainRebuild || CTX.vulkanContext.imguiVulkanWindow.Width != + (swapChainRebuild || vulkanContext->imguiVulkanWindow.Width != fb_width || - CTX.vulkanContext.imguiVulkanWindow.Height != fb_height)) { + vulkanContext->imguiVulkanWindow.Height != fb_height)) { ImGui_ImplVulkan_SetMinImageCount(MAX_FRAMES_IN_FLIGHT); - ImGui_ImplVulkanH_CreateOrResizeWindow(CTX.vulkanContext.instance.instance, - CTX.vulkanContext.physDevice.physical_device, - CTX.vulkanContext.device.device, - &CTX.vulkanContext.imguiVulkanWindow, - CTX.vulkanContext.queueFamily, + ImGui_ImplVulkanH_CreateOrResizeWindow(vulkanContext->instance.instance, + vulkanContext->physDevice.physical_device, + vulkanContext->device.device, + &vulkanContext->imguiVulkanWindow, + vulkanContext->queueFamily, nullptr, fb_width, fb_height, MAX_FRAMES_IN_FLIGHT); - CTX.vulkanContext.imguiVulkanWindow.FrameIndex = 0; + vulkanContext->imguiVulkanWindow.FrameIndex = 0; swapChainRebuild = false; } if (glfwGetWindowAttrib(window, GLFW_ICONIFIED) != 0) { @@ -47,7 +48,7 @@ namespace Metal { } ImGui_ImplVulkanH_Window &GLFWContext::getGUIWindow() const { - return CTX.vulkanContext.imguiVulkanWindow; + return vulkanContext->imguiVulkanWindow; } void GLFWContext::setSwapChainRebuild(const bool val) { @@ -58,7 +59,7 @@ namespace Metal { if (swapChainRebuild) { return; } - auto &wd = CTX.vulkanContext.imguiVulkanWindow; + auto &wd = vulkanContext->imguiVulkanWindow; VkSemaphore semaphore = wd.FrameSemaphores[wd.SemaphoreIndex].RenderCompleteSemaphore; VkPresentInfoKHR info = {}; info.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR; @@ -67,7 +68,7 @@ namespace Metal { info.swapchainCount = 1; info.pSwapchains = &wd.Swapchain; info.pImageIndices = &wd.FrameIndex; - VkResult err = vkQueuePresentKHR(CTX.vulkanContext.graphicsQueue, &info); + VkResult err = vkQueuePresentKHR(vulkanContext->graphicsQueue, &info); if (err == VK_ERROR_OUT_OF_DATE_KHR || err == VK_SUBOPTIMAL_KHR) { swapChainRebuild = true; return; diff --git a/src/core/glfw/GLFWContext.h b/src/core/glfw/GLFWContext.h index a2df6e3e..01ac63cb 100644 --- a/src/core/glfw/GLFWContext.h +++ b/src/core/glfw/GLFWContext.h @@ -14,7 +14,10 @@ struct ImGui_ImplVulkanH_Window; namespace Metal { class ApplicationContext; + class VulkanContext; + class GLFWContext final : public Initializable { + VulkanContext *vulkanContext = nullptr; GLFWwindow *window = nullptr; bool validContext = true; ; @@ -41,6 +44,10 @@ namespace Metal { void dispose() const; [[nodiscard]] ImGui_ImplVulkanH_Window &getGUIWindow() const; + + void setVulkanContext(VulkanContext *vulkanContext) { + this->vulkanContext = vulkanContext; + } }; } diff --git a/src/core/gui/GuiContext.cpp b/src/core/gui/GuiContext.cpp index 6874f866..b92bfff5 100644 --- a/src/core/gui/GuiContext.cpp +++ b/src/core/gui/GuiContext.cpp @@ -8,12 +8,16 @@ #include "../../engine/resource/TextureInstance.h" namespace Metal { + #include "../vulkan/VulkanContext.h" + #include "../glfw/GLFWContext.h" + #include "../../engine/service/DescriptorSetService.h" + void GuiContext::endFrame() { } void GuiContext::renderImage(TextureInstance *texture, const float sizeX, const float sizeY) const { - CTX.descriptorSetService.setImageDescriptor(texture); + descriptorSetService.setImageDescriptor(texture); ImGui::Image(reinterpret_cast(texture->imageDescriptor->vkDescriptorSet), ImVec2{sizeX, sizeY}); } @@ -61,19 +65,19 @@ namespace Metal { io.ConfigWindowsResizeFromEdges = true; // Setup Platform/Renderer backends - ImGui_ImplGlfw_InitForVulkan(CTX.glfwContext.getWindow(), true); + ImGui_ImplGlfw_InitForVulkan(glfwContext.getWindow(), true); ImGui_ImplVulkan_InitInfo init_info = {}; - init_info.Instance = CTX.vulkanContext.instance.instance; - init_info.PhysicalDevice = CTX.vulkanContext.physDevice.physical_device; - init_info.Device = CTX.vulkanContext.device.device; - init_info.QueueFamily = CTX.vulkanContext.queueFamily; - init_info.Queue = CTX.vulkanContext.graphicsQueue; - init_info.PipelineCache = CTX.vulkanContext.pipelineCache; - init_info.DescriptorPool = CTX.vulkanContext.descriptorPool; - init_info.RenderPass = CTX.vulkanContext.imguiVulkanWindow.RenderPass; + init_info.Instance = vulkanContext.instance.instance; + init_info.PhysicalDevice = vulkanContext.physDevice.physical_device; + init_info.Device = vulkanContext.device.device; + init_info.QueueFamily = vulkanContext.queueFamily; + init_info.Queue = vulkanContext.graphicsQueue; + init_info.PipelineCache = vulkanContext.pipelineCache; + init_info.DescriptorPool = vulkanContext.descriptorPool; + init_info.RenderPass = vulkanContext.imguiVulkanWindow.RenderPass; init_info.Subpass = 0; init_info.MinImageCount = MAX_FRAMES_IN_FLIGHT; - init_info.ImageCount = CTX.vulkanContext.imguiVulkanWindow.ImageCount; + init_info.ImageCount = vulkanContext.imguiVulkanWindow.ImageCount; init_info.MSAASamples = VK_SAMPLE_COUNT_1_BIT; init_info.Allocator = nullptr; init_info.CheckVkResultFn = VulkanUtils::CheckVKResult; @@ -137,16 +141,22 @@ namespace Metal { } void GuiContext::dispose() const { - const VkResult err = vkDeviceWaitIdle(CTX.vulkanContext.device.device); + const VkResult err = vkDeviceWaitIdle(vulkanContext.device.device); VulkanUtils::CheckVKResult(err); ImGui_ImplVulkan_Shutdown(); ImGui_ImplGlfw_Shutdown(); ImGui::DestroyContext(); - ImGui_ImplVulkanH_DestroyWindow(CTX.vulkanContext.instance, CTX.vulkanContext.device.device, - &CTX.glfwContext.getGUIWindow(), + ImGui_ImplVulkanH_DestroyWindow(vulkanContext.instance, vulkanContext.device.device, + &glfwContext.getGUIWindow(), nullptr); } - GuiContext::GuiContext() : AbstractRuntimeComponent() { + GuiContext::GuiContext(VulkanContext &vulkanContext, + GLFWContext &glfwContext, + DescriptorSetService &descriptorSetService) + : AbstractRuntimeComponent(), + vulkanContext(vulkanContext), + glfwContext(glfwContext), + descriptorSetService(descriptorSetService) { } } diff --git a/src/core/gui/GuiContext.h b/src/core/gui/GuiContext.h index e360874b..5324f944 100644 --- a/src/core/gui/GuiContext.h +++ b/src/core/gui/GuiContext.h @@ -10,7 +10,14 @@ namespace Metal { struct FrameBufferAttachment; struct TextureInstance; + class VulkanContext; + class DescriptorSetService; + class GuiContext final : public AbstractRuntimeComponent { + VulkanContext &vulkanContext; + GLFWContext &glfwContext; + DescriptorSetService &descriptorSetService; + static void applySpacing(); void applyFonts(); @@ -19,7 +26,9 @@ namespace Metal { ImFont *largeIconsFont = nullptr; public: - explicit GuiContext(); + explicit GuiContext(VulkanContext &vulkanContext, + GLFWContext &glfwContext, + DescriptorSetService &descriptorSetService); [[ nodiscard]] ImFont *getLargeIconsFont() const { return largeIconsFont; diff --git a/src/core/vulkan/VulkanContext.cpp b/src/core/vulkan/VulkanContext.cpp index 040e475d..9480dbda 100644 --- a/src/core/vulkan/VulkanContext.cpp +++ b/src/core/vulkan/VulkanContext.cpp @@ -1,12 +1,27 @@ #include "VulkanContext.h" - #include "VkBootstrap.h" #include "VulkanUtils.h" #include "../../ApplicationContext.h" +#include "../../editor/service/LogService.h" namespace Metal { - VulkanContext::VulkanContext(bool debugMode) : AbstractRuntimeComponent(), - debugMode(debugMode) { + VulkanContext::VulkanContext(bool debugMode, + GLFWContext &glfwContext, + EngineRepository &engineRepository, + MeshService &meshService, + TextureService &textureService, + FrameBufferService &framebufferService, + PipelineService &pipelineService, + RayTracingService &rayTracingService) + : AbstractRuntimeComponent(), + glfwContext(glfwContext), + engineRepository(engineRepository), + meshService(meshService), + textureService(textureService), + framebufferService(framebufferService), + pipelineService(pipelineService), + rayTracingService(rayTracingService), + debugMode(debugMode) { } void VulkanContext::createSwapChain() { @@ -162,7 +177,7 @@ namespace Metal { } void VulkanContext::createPresentMode() { - VkPresentModeKHR presentModes = !CTX.engineRepository.vsync + VkPresentModeKHR presentModes = !engineRepository.vsync ? VK_PRESENT_MODE_IMMEDIATE_KHR : VK_PRESENT_MODE_FIFO_KHR; imguiVulkanWindow.PresentMode = ImGui_ImplVulkanH_SelectPresentMode( @@ -254,12 +269,12 @@ namespace Metal { imguiVulkanWindow.ClearValue.color.float32[2] = 0; imguiVulkanWindow.ClearValue.color.float32[3] = 1; - this->window = CTX.glfwContext.getWindow(); + this->window = glfwContext.getWindow(); vkb::InstanceBuilder instanceBuilder; // ------- CORE INITIALIZATION // ----- INSTANCE AND EXTENSIONS - addExtensions(instanceBuilder, CTX.glfwContext.getInstanceExtensions()); + addExtensions(instanceBuilder, glfwContext.getInstanceExtensions()); auto vkbResult = instanceBuilder .set_app_name(ENGINE_NAME) .set_engine_name(ENGINE_NAME) @@ -281,24 +296,24 @@ namespace Metal { createMemoryAllocator(); createCommandPool(); createDescriptorPool(); - CTX.textureService.createSampler(false, vkImageSampler, VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER); - CTX.textureService.createSampler(true, vkTextureSampler, VK_SAMPLER_ADDRESS_MODE_REPEAT); + textureService.createSampler(false, vkImageSampler, VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER); + textureService.createSampler(true, vkTextureSampler, VK_SAMPLER_ADDRESS_MODE_REPEAT); // ------- CORE INITIALIZATION } void VulkanContext::dispose() const { - CTX.pipelineService.disposeAll(); - CTX.textureService.disposeAll(); - CTX.meshService.disposeAll(); - CTX.framebufferService.disposeAll(); - CTX.rayTracingService.destroyAccelerationStructures(); + pipelineService.disposeAll(); + textureService.disposeAll(); + meshService.disposeAll(); + framebufferService.disposeAll(); + rayTracingService.destroyAccelerationStructures(); vkDestroySampler(device.device, vkImageSampler, nullptr); vkDestroySampler(device.device, vkTextureSampler, nullptr); - vkDestroyDescriptorPool(CTX.vulkanContext.device.device, descriptorPool, + vkDestroyDescriptorPool(device.device, descriptorPool, nullptr); - vkDestroyCommandPool(CTX.vulkanContext.device.device, commandPool, + vkDestroyCommandPool(device.device, commandPool, nullptr); vkDestroyDevice(device.device, nullptr); @@ -323,7 +338,7 @@ namespace Metal { poolInfo.maxSets = 500; VulkanUtils::CheckVKResult(vkCreateDescriptorPool(device.device, &poolInfo, - nullptr, &CTX.vulkanContext.descriptorPool)); + nullptr, &descriptorPool)); } VkCommandBuffer VulkanContext::beginSingleTimeCommands() const { @@ -360,19 +375,19 @@ namespace Metal { void VulkanContext::submitFrame(VkSemaphore image_acquired_semaphore, VkSemaphore render_complete_semaphore, - ImGui_ImplVulkanH_Frame *fd) const { + ImGui_ImplVulkanH_Frame *fd) { VkPipelineStageFlags wait_stage = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT; VkSubmitInfo info = {}; - CTX.vulkanContext.pushCommandBuffer(fd->CommandBuffer); + pushCommandBuffer(fd->CommandBuffer); info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; info.waitSemaphoreCount = 1; info.pWaitSemaphores = &image_acquired_semaphore; info.pWaitDstStageMask = &wait_stage; - info.commandBufferCount = CTX.vulkanContext.getCommandBuffers().size(); - info.pCommandBuffers = CTX.vulkanContext.getCommandBuffers().data(); + info.commandBufferCount = getCommandBuffers().size(); + info.pCommandBuffers = getCommandBuffers().data(); info.signalSemaphoreCount = 1; info.pSignalSemaphores = &render_complete_semaphore; VulkanUtils::CheckVKResult(vkEndCommandBuffer(fd->CommandBuffer)); - VulkanUtils::CheckVKResult(vkQueueSubmit(CTX.vulkanContext.graphicsQueue, 1, &info, fd->Fence)); + VulkanUtils::CheckVKResult(vkQueueSubmit(graphicsQueue, 1, &info, fd->Fence)); } } diff --git a/src/core/vulkan/VulkanContext.h b/src/core/vulkan/VulkanContext.h index 2f74c8e4..0da550f5 100644 --- a/src/core/vulkan/VulkanContext.h +++ b/src/core/vulkan/VulkanContext.h @@ -12,7 +12,23 @@ #define VK_KHR_PORTABILITY_SUBSET_EXTENSION_NAME "VK_KHR_portability_subset" namespace Metal { + class GLFWContext; + struct EngineRepository; + class MeshService; + class TextureService; + class FrameBufferService; + class PipelineService; + class RayTracingService; + class VulkanContext final : public AbstractRuntimeComponent { + GLFWContext &glfwContext; + EngineRepository &engineRepository; + MeshService &meshService; + TextureService &textureService; + FrameBufferService &framebufferService; + PipelineService &pipelineService; + RayTracingService &rayTracingService; + static VkBool32 DebugCallback(VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity, VkDebugUtilsMessageTypeFlagsEXT messageType, const VkDebugUtilsMessengerCallbackDataEXT *pCallbackData, @@ -51,7 +67,14 @@ namespace Metal { std::vector &getCommandBuffers() { return commandBuffers; } - explicit VulkanContext(bool debugMode); + explicit VulkanContext(bool debugMode, + GLFWContext &glfwContext, + EngineRepository &engineRepository, + MeshService &meshService, + TextureService &textureService, + FrameBufferService &framebufferService, + PipelineService &pipelineService, + RayTracingService &rayTracingService); VkPhysicalDeviceProperties physicalDeviceProperties{}; VkPhysicalDeviceMemoryProperties physicalDeviceMemoryProperties{}; @@ -98,7 +121,7 @@ namespace Metal { void endSingleTimeCommands(VkCommandBuffer commandBuffer) const; void submitFrame(VkSemaphore image_acquired_semaphore, VkSemaphore render_complete_semaphore, - ImGui_ImplVulkanH_Frame *fd) const; + ImGui_ImplVulkanH_Frame *fd); }; } // Metal diff --git a/src/editor/dock-spaces/docks/DockSpacePanel.cpp b/src/editor/dock-spaces/docks/DockSpacePanel.cpp index c6f0826a..8e998f1e 100644 --- a/src/editor/dock-spaces/docks/DockSpacePanel.cpp +++ b/src/editor/dock-spaces/docks/DockSpacePanel.cpp @@ -143,11 +143,7 @@ namespace Metal { if (ImGui::BeginPopup((id + "NewTabDropdown").c_str())) { ImGui::Text("New Tab"); ImGui::Separator(); - for (int i = 0; i <= 4; i++) { - DockSpace *option = DockSpace::GetOption(i); - if (option == nullptr) { - continue; - } + for (auto *option: DockSpace::OPTIONS_LIST) { const bool exists = hasDockSpace(option->index); const std::string label = option->icon + " " + option->name; if (ImGui::MenuItem(label.c_str(), nullptr, false, !exists)) { diff --git a/src/editor/dock-spaces/files/FilesHeaderPanel.cpp b/src/editor/dock-spaces/files/FilesHeaderPanel.cpp index 7b317138..a81e2751 100644 --- a/src/editor/dock-spaces/files/FilesHeaderPanel.cpp +++ b/src/editor/dock-spaces/files/FilesHeaderPanel.cpp @@ -22,7 +22,6 @@ namespace Metal { filesContext.setCurrentDirectory(filesContext.currentDirectory->parent); } UIUtil::RenderTooltip("Go to parent folder"); - } ImGui::SameLine(); @@ -37,9 +36,18 @@ namespace Metal { UIUtil::DynamicSpacing(200); ImGui::SetNextItemWidth(100); - editorMode = IndexOfValue(filesContext.filterType); - if (ImGui::Combo((id + "filter").c_str(), &editorMode, EntryType::Names)) { - filesContext.filterType = EntryType::ValueOfIndex(editorMode); + const auto ¤tDTO = EntryType::GetDTO(filesContext.filterType); + std::string filterLabel = currentDTO.icon + " " + currentDTO.name; + if (ImGui::Button((filterLabel + id + "filter").c_str(), ImVec2(100, 0))) { + ImGui::OpenPopup((id + "FilterPopup").c_str()); + } + if (ImGui::BeginPopup((id + "FilterPopup").c_str())) { + for (const auto &dto: EntryType::ENTRIES) { + if (ImGui::MenuItem((dto.icon + " " + dto.name).c_str())) { + filesContext.filterType = dto.type; + } + } + ImGui::EndPopup(); } ImGui::SameLine(); if (UIUtil::ButtonSimple(actionLabel + id, 100, diff --git a/src/editor/dock-spaces/files/FilesHeaderPanel.h b/src/editor/dock-spaces/files/FilesHeaderPanel.h index c2df144c..ecc11c54 100644 --- a/src/editor/dock-spaces/files/FilesHeaderPanel.h +++ b/src/editor/dock-spaces/files/FilesHeaderPanel.h @@ -10,7 +10,6 @@ namespace Metal { FilesContext &filesContext; std::string actionLabel; std::function action; - int editorMode = 0; public: explicit FilesHeaderPanel(FilesContext &files_context, const std::string &actionLabel, std::function action) diff --git a/src/editor/dock-spaces/viewport/EngineFramePanel.cpp b/src/editor/dock-spaces/viewport/EngineFramePanel.cpp index bae6fdde..b38e5df5 100644 --- a/src/editor/dock-spaces/viewport/EngineFramePanel.cpp +++ b/src/editor/dock-spaces/viewport/EngineFramePanel.cpp @@ -15,24 +15,34 @@ #include "ImGuizmo.h" #include +#include "../../../engine/passes/impl/HWRayTracingPass.h" +#include "../../../engine/passes/impl/PostProcessingPass.h" +#include "../../../engine/passes/impl/SpatialFilterPass.h" +#include "../../../engine/passes/impl/TemporalAccumulationPass.h" +#include "../../passes/GridPass.h" +#include "../../passes/SelectionIDPass.h" +#include "../../passes/SelectionOutlinePass.h" + namespace Metal { void EngineFramePanel::onInitialize() { - const auto gBufferW = applicationContext->vulkanContext.getWindowWidth() / applicationContext->engineRepository.shadingResInvScale; - const auto gBufferH = applicationContext->vulkanContext.getWindowHeight() / applicationContext->engineRepository.shadingResInvScale; + const auto gBufferW = applicationContext->vulkanContext.getWindowWidth() / applicationContext->engineRepository. + shadingResInvScale; + const auto gBufferH = applicationContext->vulkanContext.getWindowHeight() / applicationContext->engineRepository + .shadingResInvScale; engineFrame = EngineFrameBuilder() .addBuffer(RID_GLOBAL_DATA, sizeof(GlobalDataUBO), VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, UNIFORM_BUFFER) .addBuffer(RID_LIGHT_BUFFER, MAX_LIGHTS * sizeof(LightData), VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, STORAGE_BUFFER) - .addBuffer(RID_VOLUMES_BUFFER, MAX_VOLUMES * sizeof(VolumeData), - VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, STORAGE_BUFFER) + .addBuffer(RID_VOLUMES_BUFFER, MAX_VOLUMES * sizeof(VolumeData), + VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, STORAGE_BUFFER) .addBuffer(RID_MESH_METADATA_BUFFER, MAX_MESH_INSTANCES * sizeof(MeshMetadata), VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, STORAGE_BUFFER) .addTexture(RID_ACCUMULATED_FRAME, gBufferW, gBufferH) .addTexture(RID_GBUFFER_POSITION_INDEX, gBufferW, gBufferH, VK_FORMAT_R32G32B32A32_SFLOAT) .addTexture(RID_GBUFFER_NORMAL, gBufferW, gBufferH, VK_FORMAT_R16G16B16A16_SFLOAT) - .addTexture(RID_PREVIOUS_POSITION_INDEX, gBufferW, gBufferH, VK_FORMAT_R32G32B32_SFLOAT) // I noticed current position is rgba32f, but let's check. + .addTexture(RID_PREVIOUS_POSITION_INDEX, gBufferW, gBufferH, VK_FORMAT_R32G32B32A32_SFLOAT) .addTexture(RID_PREVIOUS_NORMAL, gBufferW, gBufferH, VK_FORMAT_R16G16B16A16_SFLOAT) .addTexture(RID_DENOISED_FRAME, gBufferW, gBufferH, VK_FORMAT_R16G16B16A16_SFLOAT) .addTexture(RID_TEMPORAL_OUTPUT, gBufferW, gBufferH, VK_FORMAT_R16G16B16A16_SFLOAT) @@ -42,17 +52,15 @@ namespace Metal { .addFramebuffer(RID_POST_PROCESSING_FBO, gBufferW, gBufferH, glm::vec4(0, 0, 0, 0)) .addColor(VK_FORMAT_R16G16B16A16_SFLOAT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) .addComputeCommandBuffer(RID_COMPUTE_CB) - .addPass(RAY_TRACING, RID_COMPUTE_CB) - .addPass(ACCUMULATION, RID_COMPUTE_CB) - .addPass(TEMPORAL_ACCUMULATION, RID_COMPUTE_CB) - .addPass(SPATIAL_FILTER, RID_COMPUTE_CB) + .addPass(std::make_unique(), RID_COMPUTE_CB) + .addPass(std::make_unique(), RID_COMPUTE_CB) + .addPass(std::make_unique(), RID_COMPUTE_CB) .addCommandBuffer(RID_SELECTION_CB, RID_SELECTION_FBO) - .addPass(SELECTION_ID, RID_SELECTION_CB) + .addPass(std::make_unique(), RID_SELECTION_CB) .addCommandBuffer(RID_POST_PROCESSING_CB, RID_POST_PROCESSING_FBO) - .addPass(POST_PROCESSING, RID_POST_PROCESSING_CB) - .addPass(SELECTION_OUTLINE, RID_POST_PROCESSING_CB) - .addPass(GRID, RID_POST_PROCESSING_CB) - .addPass(ICONS, RID_POST_PROCESSING_CB) + .addPass(std::make_unique(), RID_POST_PROCESSING_CB) + .addPass(std::make_unique(), RID_POST_PROCESSING_CB) + .addPass(std::make_unique(), RID_POST_PROCESSING_CB) .build(); applicationContext->engineContext.registerFrame(engineFrame.get()); @@ -105,7 +113,8 @@ namespace Metal { const uint32_t pixelX = std::min(static_cast(u * static_cast(width)), width - 1); const uint32_t pixelY = std::min(static_cast(v * static_cast(height)), height - 1); - const auto picked = applicationContext->pickingService.pickEntityFromGBuffer(gBufferPositionIndex, pixelX, pixelY); + const auto picked = applicationContext->pickingService.pickEntityFromGBuffer( + gBufferPositionIndex, pixelX, pixelY); applicationContext->selectionService.clearSelection(); applicationContext->selectionService.addSelected(picked.value_or(EMPTY_ENTITY)); } diff --git a/src/editor/dto/DockSpace.cpp b/src/editor/dto/DockSpace.cpp index 186a612a..52ce8b7e 100644 --- a/src/editor/dto/DockSpace.cpp +++ b/src/editor/dto/DockSpace.cpp @@ -18,25 +18,22 @@ namespace Metal { DockSpace DockSpace::FILES{3, "Files", Icons::folder_open, 4, 4, CB(FilesPanel)}; DockSpace DockSpace::METRICS{4, "Metrics", Icons::analytics, 4, 4, CB(MetricsPanel)}; DockSpace DockSpace::REPOSITORIES{5, "Repositories", Icons::search, 4, 4, CB(RepositoriesPanel)}; - const char *DockSpace::OPTIONS = "Inspector\0World\0Console\0Files\0Metrics\0Repositories\0"; + const std::vector DockSpace::OPTIONS_LIST = { + &INSPECTOR, + &WORLD, + &CONSOLE, + &FILES, + &METRICS, + &REPOSITORIES + }; DockSpace *DockSpace::GetOption(const int selected) { - switch (selected) { - case 0: - return &INSPECTOR; - case 1: - return &WORLD; - case 2: - return &CONSOLE; - case 3: - return &FILES; - case 4: - return &METRICS; - case 5: - return &REPOSITORIES; - default: - return nullptr; + for (auto *option: OPTIONS_LIST) { + if (option->index == selected) { + return option; + } } + return nullptr; } } diff --git a/src/editor/dto/DockSpace.h b/src/editor/dto/DockSpace.h index 25b2dcd8..98fedeb0 100644 --- a/src/editor/dto/DockSpace.h +++ b/src/editor/dto/DockSpace.h @@ -1,6 +1,7 @@ #ifndef METAL_ENGINE_DOCKSPACE_H #define METAL_ENGINE_DOCKSPACE_H +#include #include #include @@ -15,7 +16,8 @@ namespace Metal { static DockSpace FILES; static DockSpace METRICS; static DockSpace REPOSITORIES; - static const char *OPTIONS; + + static const std::vector OPTIONS_LIST; const int index; const std::string name; diff --git a/src/editor/enum/EntryType.h b/src/editor/enum/EntryType.h index ea1790a7..e291a601 100644 --- a/src/editor/enum/EntryType.h +++ b/src/editor/enum/EntryType.h @@ -1,6 +1,10 @@ #ifndef FILETYPE_H #define FILETYPE_H +#include +#include +#include "../../../common/Icons.h" + namespace Metal::EntryType { enum EntryType { SCENE, @@ -11,47 +15,28 @@ namespace Metal::EntryType { NONE }; - static const char *Names = "Scene\0Mesh\0Texture\0Volume\0Directory\0None\0"; + struct EntryTypeDTO { + EntryType type; + std::string name; + std::string icon; + }; - static EntryType ValueOfIndex(const int option) { - if (option == 0) { - return EntryType::SCENE; - } - if (option == 1) { - return EntryType::MESH; - } - if (option == 2) { - return EntryType::TEXTURE; - } - if (option == 3) { - return EntryType::VOLUME; - } - if (option == 4) { - return EntryType::DIRECTORY; - } - return EntryType::NONE; - } + static const std::vector ENTRIES = { + {SCENE, "Scene", Icons::image}, + {MESH, "Mesh", Icons::view_in_ar}, + {TEXTURE, "Texture", Icons::texture}, + {VOLUME, "Volume", Icons::view_agenda}, + {DIRECTORY, "Directory", Icons::folder}, + {NONE, "None", Icons::close} + }; - static int IndexOfValue(const EntryType mode) { - if (mode == SCENE) { - return 0; - } - if (mode == MESH) { - return 1; - } - if (mode == TEXTURE) { - return 2; - } - if (mode == VOLUME) { - return 3; - } - if (mode == DIRECTORY) { - return 4; - } - if (mode == NONE) { - return 6; + static const EntryTypeDTO& GetDTO(EntryType type) { + for (const auto& dto : ENTRIES) { + if (dto.type == type) { + return dto; + } } - return 6; + return ENTRIES.back(); // Return NONE } } #endif diff --git a/src/editor/passes/GridPass.h b/src/editor/passes/GridPass.h index 86dc660d..ff77ef29 100644 --- a/src/editor/passes/GridPass.h +++ b/src/editor/passes/GridPass.h @@ -8,8 +8,6 @@ namespace Metal { GridPushConstant pushConstant{}; public: - explicit GridPass(const std::string &id) : AbstractRenderPass(id) {} - void onInitialize() override; bool shouldRun() override; diff --git a/src/editor/passes/IconsPass.cpp b/src/editor/passes/IconsPass.cpp deleted file mode 100644 index 73e0126b..00000000 --- a/src/editor/passes/IconsPass.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include "IconsPass.h" - -#include "../../ApplicationContext.h" -#include "../../engine/dto/PipelineBuilder.h" -#include "../enum/EngineResourceIDs.h" - -namespace Metal { - void IconsPass::onInitialize() { - PipelineBuilder iconPipelineBuilder = PipelineBuilder::Of( - getScopedResourceId(RID_POST_PROCESSING_FBO), - "QUAD.vert", - "tools/Icon.frag" - ) - .addBufferBinding(getScopedResourceId(RID_GLOBAL_DATA)) - .addBufferBinding(getScopedResourceId(RID_LIGHT_BUFFER)) - .setBlendEnabled(); - pipelineInstance = CTX.pipelineService.createPipeline(iconPipelineBuilder); - } - - bool IconsPass::shouldRun() { - return CTX.isDebugMode() && CTX.editorRepository.showIcons; - } - - void IconsPass::onSync() { - recordDrawSimpleInstanced(3, 1); - } -} // Metal diff --git a/src/editor/passes/IconsPass.h b/src/editor/passes/IconsPass.h deleted file mode 100644 index cb46ae3c..00000000 --- a/src/editor/passes/IconsPass.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef ICONRENDERPASS_H -#define ICONRENDERPASS_H -#include "../../engine/passes/AbstractRenderPass.h" - -namespace Metal { - class IconsPass final : public AbstractRenderPass { - public: - explicit IconsPass(const std::string &id) : AbstractRenderPass(id) {} - - void onInitialize() override; - - bool shouldRun() override; - - void onSync() override; - }; -} // Metal - -#endif //ICONRENDERPASS_H diff --git a/src/editor/passes/SelectionIDPass.h b/src/editor/passes/SelectionIDPass.h index 156892dd..fe0aac3a 100644 --- a/src/editor/passes/SelectionIDPass.h +++ b/src/editor/passes/SelectionIDPass.h @@ -9,7 +9,6 @@ namespace Metal { SelectedDotPushConstant pushConstant{}; public: - explicit SelectionIDPass(const std::string &id) : AbstractRenderPass(id) {} void onInitialize() override; diff --git a/src/editor/passes/SelectionOutlinePass.h b/src/editor/passes/SelectionOutlinePass.h index 4d1b8d7b..60860a7a 100644 --- a/src/editor/passes/SelectionOutlinePass.h +++ b/src/editor/passes/SelectionOutlinePass.h @@ -9,8 +9,6 @@ namespace Metal { SelectedDotPushConstant pushConstant{}; public: - explicit SelectionOutlinePass(const std::string &id) : AbstractRenderPass(id) {} - void onInitialize() override; bool shouldRun() override; diff --git a/src/editor/repository/EditorRepository.cpp b/src/editor/repository/EditorRepository.cpp index b4cb5b1b..aff132b3 100644 --- a/src/editor/repository/EditorRepository.cpp +++ b/src/editor/repository/EditorRepository.cpp @@ -35,14 +35,14 @@ namespace Metal { j["gizmoUseSnapRotate"] = gizmoUseSnapRotate; j["gizmoUseSnapScale"] = gizmoUseSnapScale; j["showOnlyEntitiesHierarchy"] = showOnlyEntitiesHierarchy; - j["mainSelection"] = static_cast(entt::to_integral(mainSelection)); + j["mainSelection"] = entt::to_integral(mainSelection); j["selected"] = nlohmann::json::array(); for (auto const& [key, val] : selected) { - j["selected"].push_back(static_cast(entt::to_integral(key))); + j["selected"].push_back(entt::to_integral(key)); } j["copied"] = nlohmann::json::array(); for (auto const& entity : copied) { - j["copied"].push_back(static_cast(entt::to_integral(entity))); + j["copied"].push_back(entt::to_integral(entity)); } j["shadingMode"] = shadingMode; return j; diff --git a/src/editor/service/DockService.cpp b/src/editor/service/DockService.cpp index 5bbffb0a..c231964f 100644 --- a/src/editor/service/DockService.cpp +++ b/src/editor/service/DockService.cpp @@ -10,7 +10,6 @@ namespace Metal { void DockService::buildViews(ImGuiID windowId, AbstractPanel *panel) const { if (ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_DockingEnable) { - DockRepository &dockRepository = CTX.dockRepository; if (dockRepository.isInitialized) { return; } diff --git a/src/editor/service/DockService.h b/src/editor/service/DockService.h index 6d00ee6e..2c5fbf40 100644 --- a/src/editor/service/DockService.h +++ b/src/editor/service/DockService.h @@ -10,7 +10,12 @@ namespace Metal { class AbstractPanel; class DockService final : public AbstractRuntimeComponent { + DockRepository &dockRepository; public: + explicit DockService(DockRepository &dockRepository) + : AbstractRuntimeComponent(), dockRepository(dockRepository) { + } + void buildViews(ImGuiID windowId, AbstractPanel *panel) const; static void createDockSpace(DockDTO *dockSpace, ImGuiID *dockMainId); diff --git a/src/editor/service/ThemeService.cpp b/src/editor/service/ThemeService.cpp index 4eee2551..993a6c9c 100644 --- a/src/editor/service/ThemeService.cpp +++ b/src/editor/service/ThemeService.cpp @@ -6,7 +6,6 @@ namespace Metal { glm::vec3 ThemeService::BACKGROUND_COLOR = glm::vec3(0.f); void ThemeService::onSync() { - EditorRepository &editorRepository = CTX.editorRepository; if (previousTheme == editorRepository.isDarkMode && glm::length(editorRepository.accentColor) == prevLength) { return; } diff --git a/src/editor/service/ThemeService.h b/src/editor/service/ThemeService.h index e9d5f603..94310fbe 100644 --- a/src/editor/service/ThemeService.h +++ b/src/editor/service/ThemeService.h @@ -6,7 +6,9 @@ namespace Metal { + struct EditorRepository; class ThemeService final : public AbstractRuntimeComponent { + EditorRepository &editorRepository; public: ImVec4 neutralPalette{}; ImVec4 palette0{}; @@ -21,7 +23,8 @@ namespace Metal { bool previousTheme = false; float prevLength = 0.0f; - explicit ThemeService() : AbstractRuntimeComponent() { + explicit ThemeService(EditorRepository &editorRepository) + : AbstractRuntimeComponent(), editorRepository(editorRepository) { } void setDarkMode(); diff --git a/src/engine/dto/PrimitiveComponent.cpp b/src/engine/dto/PrimitiveComponent.cpp index 7018d702..519167ca 100644 --- a/src/engine/dto/PrimitiveComponent.cpp +++ b/src/engine/dto/PrimitiveComponent.cpp @@ -19,17 +19,18 @@ namespace Metal { } void PrimitiveComponent::onUpdate(InspectableMember *member) { - if (member != nullptr && member->name == "meshId") { - MeshData *data = CTX.meshService.loadMeshData(meshId); - if (data != nullptr) { - if (CTX.worldRepository.registry.all_of(entityId)) { - CTX.worldRepository.registry.get(entityId).gizmoCenter = data->gizmoCenter; - } - delete data; - } - } - CTX.engineContext.setGISettingsUpdated(true); - CTX.rayTracingService.setNeedsMaterialUpdate(true); + // TODO - EVENT SYSTEM + // if (member != nullptr && member->name == "meshId") { + // MeshData *data = CTX.meshService.loadMeshData(meshId); + // if (data != nullptr) { + // if (CTX.worldRepository.registry.all_of(entityId)) { + // CTX.worldRepository.registry.get(entityId).gizmoCenter = data->gizmoCenter; + // } + // delete data; + // } + // } + // CTX.engineContext.setGISettingsUpdated(true); + // CTX.rayTracingService.setNeedsMaterialUpdate(true); } ComponentType PrimitiveComponent::getType() { diff --git a/src/engine/enum/PassType.h b/src/engine/enum/PassType.h deleted file mode 100644 index d0c67489..00000000 --- a/src/engine/enum/PassType.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef PASS_TYPE_H -#define PASS_TYPE_H - -namespace Metal { - enum PassType { - RAY_TRACING, - ACCUMULATION, - TEMPORAL_ACCUMULATION, - SPATIAL_FILTER, - POST_PROCESSING, - SELECTION_OUTLINE, - GRID, - ICONS, - SELECTION_ID - }; -} - -#endif //PASS_TYPE_H diff --git a/src/engine/enum/ResourceType.h b/src/engine/enum/ResourceType.h index a2ebd28c..c29f3423 100644 --- a/src/engine/enum/ResourceType.h +++ b/src/engine/enum/ResourceType.h @@ -8,8 +8,7 @@ namespace Metal { PIPELINE, BUFFER, DESCRIPTOR_SET, - COMMAND_BUFFER_RECORDER, - PASS + COMMAND_BUFFER_RECORDER }; } diff --git a/src/engine/frame-builder/EngineFrame.cpp b/src/engine/frame-builder/EngineFrame.cpp index 6f714a1b..49d71f48 100644 --- a/src/engine/frame-builder/EngineFrame.cpp +++ b/src/engine/frame-builder/EngineFrame.cpp @@ -12,8 +12,7 @@ namespace Metal { } } - - void EngineFrame::addPass(CommandBufferRecorder *recorder, const std::vector &p) { + void EngineFrame::addPass(CommandBufferRecorder *recorder, const std::vector> &p) { if (recorder) { passes.emplace_back(recorder, p); } @@ -25,16 +24,6 @@ namespace Metal { } } - void EngineFrame::dispose() { - for (auto &pair: passes) { - delete pair.first; - for (auto *pass: pair.second) { - delete pass; - } - } - passes.clear(); - } - std::string EngineFrame::getScopedResourceId(const std::string &resourceId) const { return id + "_" + resourceId; } diff --git a/src/engine/frame-builder/EngineFrame.h b/src/engine/frame-builder/EngineFrame.h index 66c8446d..9ea82210 100644 --- a/src/engine/frame-builder/EngineFrame.h +++ b/src/engine/frame-builder/EngineFrame.h @@ -16,7 +16,7 @@ namespace Metal { std::string id; bool shouldRender = false; std::unordered_map resources; - std::vector > > passes; + std::vector > > > passes; public: explicit EngineFrame(std::string id); @@ -38,20 +38,10 @@ namespace Metal { return nullptr; } - void addPass(CommandBufferRecorder *recorder, const std::vector &p); - - [[nodiscard]] const std::vector > > & - getPasses() const { - return passes; - } + void addPass(CommandBufferRecorder *recorder, const std::vector> &p); void onSync(); - void dispose(); - - void destroy() { - } - [[nodiscard]] std::string getScopedResourceId(const std::string &resourceId) const; }; } diff --git a/src/engine/frame-builder/EngineFrameBuilder.cpp b/src/engine/frame-builder/EngineFrameBuilder.cpp index 82804505..4d8796db 100644 --- a/src/engine/frame-builder/EngineFrameBuilder.cpp +++ b/src/engine/frame-builder/EngineFrameBuilder.cpp @@ -82,9 +82,9 @@ namespace Metal { return *this; } - EngineFrameBuilder &EngineFrameBuilder::addPass(PassType type, const std::string &commandBufferId) { - currentBuilder = std::make_shared(Util::uuidV4(), type, frameId + "_" + commandBufferId); - builders.push_back(currentBuilder); + EngineFrameBuilder &EngineFrameBuilder::addPass(std::unique_ptr pass, + const std::string &commandBufferId) { + passes.emplace_back(std::move(pass), frameId + "_" + commandBufferId); return *this; } @@ -103,37 +103,32 @@ namespace Metal { std::unordered_map builtResources; for (const auto &builder: builders) { - auto *resource = builder->build(); - if (resource) { + if (auto *resource = builder->build()) { frame->addResource(resource); builtResources[builder->getId()] = resource; } } - std::unordered_map > recorderToPasses; + std::unordered_map> > recorderToPasses; std::vector recorderOrder; for (const auto &builder: builders) { if (auto *passBuilder = dynamic_cast(builder.get())) { const auto cbId = passBuilder->getCommandBufferId(); - if (std::find(recorderOrder.begin(), recorderOrder.end(), cbId) == recorderOrder.end()) { + if (std::ranges::find(recorderOrder, cbId) == recorderOrder.end()) { recorderOrder.push_back(cbId); } - - if (builtResources.contains(builder->getId())) { - auto *pass = dynamic_cast(builtResources.at(builder->getId())); - if (pass) { - pass->frame = frame.get(); - pass->onInitialize(); - recorderToPasses[cbId].push_back(pass); - } - } } } + for (auto &pass: passes) { + pass.pass->frame = frame.get(); + pass.pass->onInitialize(); + recorderToPasses[pass.commandBufferId].push_back(std::move(pass.pass)); + } + for (const auto &cbId: recorderOrder) { - auto *recorder = CTX.commandBufferRecorderService.getResource(cbId); - if (recorder) { + if (auto *recorder = dynamic_cast(builtResources.at(cbId))) { frame->addPass(recorder, recorderToPasses[cbId]); } } diff --git a/src/engine/frame-builder/EngineFrameBuilder.h b/src/engine/frame-builder/EngineFrameBuilder.h index 0462a415..63c58cf2 100644 --- a/src/engine/frame-builder/EngineFrameBuilder.h +++ b/src/engine/frame-builder/EngineFrameBuilder.h @@ -12,15 +12,22 @@ #include "../resource/BufferInstance.h" namespace Metal { + class AbstractPass; class CommandBufferRecorder; struct FrameBufferInstance; struct DescriptorBinding; class ResourceBuilder; class EngineFrame; + struct PassData { + std::unique_ptr pass; + std::string commandBufferId; + }; + class EngineFrameBuilder final { std::string frameId; std::vector > builders{}; + std::vector passes{}; std::shared_ptr currentBuilder{}; public: @@ -46,7 +53,7 @@ namespace Metal { EngineFrameBuilder &addComputeCommandBuffer(const std::string &id); - EngineFrameBuilder &addPass(PassType type, const std::string &commandBufferId); + EngineFrameBuilder &addPass(std::unique_ptr pass, const std::string &commandBufferId); bool tryMatch(const std::string &id, ResourceType type); diff --git a/src/engine/frame-builder/structures/BufferBuilder.cpp b/src/engine/frame-builder/structures/BufferBuilder.cpp index 2dce9a2c..ce876357 100644 --- a/src/engine/frame-builder/structures/BufferBuilder.cpp +++ b/src/engine/frame-builder/structures/BufferBuilder.cpp @@ -5,7 +5,7 @@ namespace Metal { ResourceType BufferBuilder::getType() { - return ResourceType::BUFFER; + return BUFFER; } RuntimeResource *BufferBuilder::build() { diff --git a/src/engine/frame-builder/structures/PassBuilder.cpp b/src/engine/frame-builder/structures/PassBuilder.cpp deleted file mode 100644 index 8d9d8278..00000000 --- a/src/engine/frame-builder/structures/PassBuilder.cpp +++ /dev/null @@ -1,34 +0,0 @@ -#include "PassBuilder.h" -#include "../../passes/impl/PostProcessingPass.h" -#include "../../passes/impl/HWRayTracingPass.h" -#include "../../passes/impl/TemporalAccumulationPass.h" -#include "../../passes/impl/SpatialFilterPass.h" -#include "../../../editor/passes/SelectionOutlinePass.h" -#include "../../../editor/passes/GridPass.h" -#include "../../../editor/passes/IconsPass.h" -#include "../../../editor/passes/SelectionIDPass.h" - -namespace Metal { - RuntimeResource* PassBuilder::build() { - switch (passType) { - case POST_PROCESSING: - return new PostProcessingPass(id); - case RAY_TRACING: - return new HWRayTracingPass(id); - case TEMPORAL_ACCUMULATION: - return new TemporalAccumulationPass(id); - case SPATIAL_FILTER: - return new SpatialFilterPass(id); - case SELECTION_OUTLINE: - return new SelectionOutlinePass(id); - case GRID: - return new GridPass(id); - case ICONS: - return new IconsPass(id); - case SELECTION_ID: - return new SelectionIDPass(id); - default: - return nullptr; - } - } -} diff --git a/src/engine/frame-builder/structures/PassBuilder.h b/src/engine/frame-builder/structures/PassBuilder.h deleted file mode 100644 index e92c1cfd..00000000 --- a/src/engine/frame-builder/structures/PassBuilder.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef METAL_ENGINE_PASSBUILDER_H -#define METAL_ENGINE_PASSBUILDER_H - -#include "ResourceBuilder.h" -#include "../../enum/PassType.h" -#include "../../enum/ResourceType.h" - -namespace Metal { - class PassBuilder final : public ResourceBuilder { - PassType passType; - std::string commandBufferId; - std::string framebufferId; - bool clearBuffer; - - public: - explicit PassBuilder(const std::string &id, PassType type, std::string commandBufferId, - std::string framebufferId = "", bool clearBuffer = true) - : ResourceBuilder(id), passType(type), commandBufferId(std::move(commandBufferId)), - framebufferId(std::move(framebufferId)), clearBuffer(clearBuffer) { - } - - ResourceType getType() override { - return PASS; - } - - RuntimeResource *build() override; - - [[nodiscard]] PassType getPassType() const { return passType; } - const std::string &getCommandBufferId() const { return commandBufferId; } - const std::string &getFramebufferId() const { return framebufferId; } - bool shouldClearBuffer() const { return clearBuffer; } - }; -} - -#endif diff --git a/src/engine/passes/AbstractComputePass.cpp b/src/engine/passes/AbstractComputePass.cpp index cd34e278..bed92677 100644 --- a/src/engine/passes/AbstractComputePass.cpp +++ b/src/engine/passes/AbstractComputePass.cpp @@ -5,7 +5,7 @@ #include "../util/ImageUtils.h" namespace Metal { - AbstractComputePass::AbstractComputePass(const std::string &id) : AbstractPass(id, true) { + AbstractComputePass::AbstractComputePass() : AbstractPass(true) { } void AbstractComputePass::recordDispatch(const unsigned int groupX, const unsigned int groupY, diff --git a/src/engine/passes/AbstractComputePass.h b/src/engine/passes/AbstractComputePass.h index 321e0989..20cd53c2 100644 --- a/src/engine/passes/AbstractComputePass.h +++ b/src/engine/passes/AbstractComputePass.h @@ -13,7 +13,7 @@ namespace Metal { class AbstractComputePass : public AbstractPass { public: - explicit AbstractComputePass(const std::string &id); + explicit AbstractComputePass(); void recordDispatch(unsigned int groupX, unsigned int groupY, unsigned int groupZ) const; diff --git a/src/engine/passes/AbstractPass.cpp b/src/engine/passes/AbstractPass.cpp index a0dbd400..367c8fad 100644 --- a/src/engine/passes/AbstractPass.cpp +++ b/src/engine/passes/AbstractPass.cpp @@ -4,14 +4,7 @@ #include "../resource/PipelineInstance.h" namespace Metal { - AbstractPass::AbstractPass(const std::string &id, bool isComputePass) : RuntimeResource(id), - isComputePass(isComputePass) { - } - - AbstractPass::~AbstractPass() { - if (pipelineInstance != nullptr) { - CTX.pipelineService.dispose(pipelineInstance->getId()); - } + AbstractPass::AbstractPass(bool isComputePass) : isComputePass(isComputePass) { } void AbstractPass::recordPushConstant(const void *data) { diff --git a/src/engine/passes/AbstractPass.h b/src/engine/passes/AbstractPass.h index d5fffc8f..8be0960e 100644 --- a/src/engine/passes/AbstractPass.h +++ b/src/engine/passes/AbstractPass.h @@ -13,7 +13,7 @@ namespace Metal { class StreamingService; struct PipelineInstance; - class AbstractPass : public AbstractRuntimeComponent, public RuntimeResource { + class AbstractPass : public AbstractRuntimeComponent { bool isComputePass; public: @@ -21,13 +21,7 @@ namespace Metal { VkCommandBuffer vkCommandBuffer = VK_NULL_HANDLE; PipelineInstance *pipelineInstance = nullptr; - explicit AbstractPass(const std::string &id, bool isComputePass); - - virtual ~AbstractPass() override; - - ResourceType resourceType() override { - return PASS; - } + explicit AbstractPass( bool isComputePass); void recordPushConstant(const void *data); @@ -39,7 +33,7 @@ namespace Metal { this->vkCommandBuffer = vkCommandBuffer; } - PipelineInstance *getPipeline() { + PipelineInstance *getPipeline() const { return pipelineInstance; } diff --git a/src/engine/passes/AbstractRenderPass.cpp b/src/engine/passes/AbstractRenderPass.cpp index c8b1084f..15708631 100644 --- a/src/engine/passes/AbstractRenderPass.cpp +++ b/src/engine/passes/AbstractRenderPass.cpp @@ -4,7 +4,7 @@ #include "../resource/BufferInstance.h" namespace Metal { - AbstractRenderPass::AbstractRenderPass(const std::string &id) : AbstractPass(id, false) { + AbstractRenderPass::AbstractRenderPass() : AbstractPass(false) { } void AbstractRenderPass::recordDrawSimpleInstanced(const unsigned int vertexCount, const unsigned int instanceCount) const { diff --git a/src/engine/passes/AbstractRenderPass.h b/src/engine/passes/AbstractRenderPass.h index a08bb11b..e751c57c 100644 --- a/src/engine/passes/AbstractRenderPass.h +++ b/src/engine/passes/AbstractRenderPass.h @@ -12,7 +12,7 @@ namespace Metal { class AbstractRenderPass : public AbstractPass { public: - explicit AbstractRenderPass(const std::string &id); + explicit AbstractRenderPass(); void recordDrawSimpleInstanced(unsigned int vertexCount, unsigned int instanceCount) const; diff --git a/src/engine/passes/CommandBufferRecorder.cpp b/src/engine/passes/CommandBufferRecorder.cpp index 785eb2f6..03f9b60c 100644 --- a/src/engine/passes/CommandBufferRecorder.cpp +++ b/src/engine/passes/CommandBufferRecorder.cpp @@ -70,7 +70,7 @@ namespace Metal { } void CommandBufferRecorder::recordCommands( - const std::vector &passes) const { + const std::vector> &passes) const { auto vkCommandBuffer = _commandBuffers[CTX.getFrameIndex()]; VkCommandBufferBeginInfo beginInfo{}; beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; @@ -91,7 +91,7 @@ namespace Metal { } void CommandBufferRecorder::RecordCommandsInternal( - const std::vector &passes, + const std::vector> &passes, VkCommandBuffer vkCommandBuffer) { for (auto &pass: passes) { pass->setCommandBuffer(vkCommandBuffer); diff --git a/src/engine/passes/CommandBufferRecorder.h b/src/engine/passes/CommandBufferRecorder.h index f7b367c9..a188280f 100644 --- a/src/engine/passes/CommandBufferRecorder.h +++ b/src/engine/passes/CommandBufferRecorder.h @@ -20,7 +20,7 @@ namespace Metal { bool computePassMode; static void RecordCommandsInternal( - const std::vector &passes, + const std::vector> &passes, VkCommandBuffer vkCommandBuffer); void createRenderPassInfo(const FrameBufferInstance *frameBuffer, bool clearBuffer); @@ -36,7 +36,7 @@ namespace Metal { void createCommandBuffer(); - void recordCommands(const std::vector &passes) const; + void recordCommands(const std::vector> &passes) const; }; } // Metal diff --git a/src/engine/passes/impl/HWRayTracingPass.h b/src/engine/passes/impl/HWRayTracingPass.h index 860a2424..de0d0f70 100644 --- a/src/engine/passes/impl/HWRayTracingPass.h +++ b/src/engine/passes/impl/HWRayTracingPass.h @@ -9,9 +9,6 @@ namespace Metal { HWRayTracingPushConstant pushConstant{}; public: - explicit HWRayTracingPass(const std::string &id) : AbstractComputePass(id) { - } - void onSync() override; void onInitialize() override; diff --git a/src/engine/passes/impl/PostProcessingPass.h b/src/engine/passes/impl/PostProcessingPass.h index 98dbcbc9..08e60b2c 100644 --- a/src/engine/passes/impl/PostProcessingPass.h +++ b/src/engine/passes/impl/PostProcessingPass.h @@ -7,8 +7,6 @@ namespace Metal { class PostProcessingPass final : public AbstractRenderPass { PostProcessingPushConstant pushConstant{}; public: - explicit PostProcessingPass(const std::string &id) : AbstractRenderPass(id) {} - void onInitialize() override; void onSync() override; diff --git a/src/engine/passes/impl/SpatialFilterPass.h b/src/engine/passes/impl/SpatialFilterPass.h index ef66e4b3..838a353f 100644 --- a/src/engine/passes/impl/SpatialFilterPass.h +++ b/src/engine/passes/impl/SpatialFilterPass.h @@ -5,9 +5,6 @@ namespace Metal { class SpatialFilterPass final : public AbstractComputePass { public: - explicit SpatialFilterPass(const std::string &id) : AbstractComputePass(id) { - } - void onSync() override; void onInitialize() override; diff --git a/src/engine/passes/impl/TemporalAccumulationPass.h b/src/engine/passes/impl/TemporalAccumulationPass.h index e9d61531..a95b2c3f 100644 --- a/src/engine/passes/impl/TemporalAccumulationPass.h +++ b/src/engine/passes/impl/TemporalAccumulationPass.h @@ -5,8 +5,6 @@ namespace Metal { class TemporalAccumulationPass final : public AbstractComputePass { public: - explicit TemporalAccumulationPass(const std::string &id) : AbstractComputePass(id) { - } void onSync() override; diff --git a/src/engine/service/PipelineService.cpp b/src/engine/service/PipelineService.cpp index d8feef1b..83e84709 100644 --- a/src/engine/service/PipelineService.cpp +++ b/src/engine/service/PipelineService.cpp @@ -1,6 +1,6 @@ #include "PipelineService.h" #include "../dto/PipelineBuilder.h" -#include "../util/ShaderUtil.h" +#include "ShaderService.h" #include "../../core/vulkan/VulkanContext.h" #include "../../core/vulkan/VulkanUtils.h" #include "FrameBufferService.h" @@ -73,7 +73,7 @@ namespace Metal { PipelineInstance *pipeline) { pipeline->isCompute = true; pipeline->pushConstantsSize = pipelineBuilder.pushConstantsSize; - VkShaderModule computeShaderModule = ShaderUtil::CreateShaderModule(pipelineBuilder.computeShader); + VkShaderModule computeShaderModule = shaderService.createShaderModule(pipelineBuilder.computeShader); VkPipelineShaderStageCreateInfo computeShaderStageInfo{}; computeShaderStageInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; computeShaderStageInfo.stage = VK_SHADER_STAGE_COMPUTE_BIT; @@ -101,8 +101,8 @@ namespace Metal { auto meshDescriptions = VertexData::GetAttributeDescriptions(); pipeline->pushConstantsSize = pipelineBuilder.pushConstantsSize; - auto fragmentShaderModule = ShaderUtil::CreateShaderModule(pipelineBuilder.fragmentShader); - auto vertexShaderModule = ShaderUtil::CreateShaderModule(pipelineBuilder.vertexShader); + auto fragmentShaderModule = shaderService.createShaderModule(pipelineBuilder.fragmentShader); + auto vertexShaderModule = shaderService.createShaderModule(pipelineBuilder.vertexShader); createPipelineLayout(pipelineBuilder.pushConstantsSize, pipeline); std::array shaderStages{}; @@ -252,9 +252,9 @@ namespace Metal { pipeline->pushConstantsSize = pipelineBuilder.pushConstantsSize; // Create shader modules - auto rayGenModule = ShaderUtil::CreateShaderModule(pipelineBuilder.rayGenShader); - auto missModule = ShaderUtil::CreateShaderModule(pipelineBuilder.missShader); - auto closestHitModule = ShaderUtil::CreateShaderModule(pipelineBuilder.closestHitShader); + auto rayGenModule = shaderService.createShaderModule(pipelineBuilder.rayGenShader); + auto missModule = shaderService.createShaderModule(pipelineBuilder.missShader); + auto closestHitModule = shaderService.createShaderModule(pipelineBuilder.closestHitShader); // Shader stages: 0=raygen, 1=miss, 2=closesthit std::array shaderStages{}; diff --git a/src/engine/service/PipelineService.h b/src/engine/service/PipelineService.h index e3095178..55d4852f 100644 --- a/src/engine/service/PipelineService.h +++ b/src/engine/service/PipelineService.h @@ -7,6 +7,7 @@ #include "../resource/PipelineInstance.h" namespace Metal { + class ShaderService; struct PipelineBuilder; struct FrameBufferInstance; struct PipelineInstance; @@ -21,10 +22,16 @@ namespace Metal { FrameBufferService &framebufferService; BufferService &bufferService; DescriptorSetService &descriptorSetService; + ShaderService &shaderService; public: - explicit PipelineService(VulkanContext &vulkanContext, FrameBufferService &framebufferService, BufferService &bufferService, DescriptorSetService &descriptorSetService) - : vulkanContext(vulkanContext), framebufferService(framebufferService), bufferService(bufferService), descriptorSetService(descriptorSetService) {} + explicit PipelineService(ShaderService &shaderService, VulkanContext &vulkanContext, + FrameBufferService &framebufferService, BufferService &bufferService, + DescriptorSetService &descriptorSetService) + : shaderService(shaderService), vulkanContext(vulkanContext), framebufferService(framebufferService), + bufferService(bufferService), descriptorSetService(descriptorSetService) { + } + PipelineService() = delete; PipelineInstance *createPipeline(PipelineBuilder &pipelineBuilder); diff --git a/src/engine/util/ShaderUtil.cpp b/src/engine/service/ShaderService.cpp similarity index 88% rename from src/engine/util/ShaderUtil.cpp rename to src/engine/service/ShaderService.cpp index b0544a2e..8e062433 100644 --- a/src/engine/util/ShaderUtil.cpp +++ b/src/engine/service/ShaderService.cpp @@ -1,7 +1,10 @@ -#include "ShaderUtil.h" +#include "ShaderService.h" #include #include +#include +#include +#include #include "../dto/ShaderModule.h" #include "../../core/vulkan/VulkanUtils.h" @@ -15,7 +18,7 @@ #define BASE_PATH "../resources/shaders/" namespace Metal { - void ShaderUtil::CheckShaderCompilation(glslang_shader_t *shader) { + void ShaderService::CheckShaderCompilation(glslang_shader_t *shader) { const char *infoLog = glslang_shader_get_info_log(shader); const char *debugLog = glslang_shader_get_info_debug_log(shader); const char *shaderCode = glslang_shader_get_preprocessed_code(shader); @@ -28,8 +31,8 @@ namespace Metal { } } - bool ShaderUtil::CompileShader(glslang_stage_t stage, const char *pShaderCode, - ShaderModule *shaderModule) { + bool ShaderService::CompileShader(glslang_stage_t stage, const char *pShaderCode, + ShaderModule *shaderModule) const { const glslang_input_t input = { .language = GLSLANG_SOURCE_GLSL, .stage = stage, @@ -78,7 +81,7 @@ namespace Metal { shaderCreateInfo.codeSize = shaderModule->SPIRV.size() * sizeof(unsigned int); shaderCreateInfo.pCode = static_cast(shaderModule->SPIRV.data()); - VulkanUtils::CheckVKResult(vkCreateShaderModule(CTX.vulkanContext.device.device, &shaderCreateInfo, + VulkanUtils::CheckVKResult(vkCreateShaderModule(vulkanContext.device.device, &shaderCreateInfo, nullptr, &shaderModule->vkShaderModule)); glslang_program_delete(program); @@ -87,7 +90,7 @@ namespace Metal { return !shaderModule->SPIRV.empty(); } - glslang_stage_t ShaderUtil::ShaderStageFromFilename(const char *pFilename) { + glslang_stage_t ShaderService::ShaderStageFromFilename(const char *pFilename) { const std::string s(pFilename); if (s.ends_with(".vert")) { @@ -128,7 +131,7 @@ namespace Metal { throw std::runtime_error("Unknown shader stage in file"); } - std::string ShaderUtil::ProcessIncludes(const std::string &input) { + std::string ShaderService::ProcessIncludes(const std::string &input) { std::string result = input; std::regex includePattern(R"(#include\s+"(.+))"); std::smatch match; @@ -154,16 +157,15 @@ namespace Metal { return result; } - std::string ShaderUtil::ProcessShader(const std::string &file) { + std::string ShaderService::ProcessShader(const std::string &file) { std::string source; FilesUtil::ReadFile(file.c_str(), source); return ProcessIncludes(source); } - VkShaderModule ShaderUtil::CreateShaderModule(const std::string &pFilename) { - const std::string basePath = CTX.getShadersDirectory(); + VkShaderModule ShaderService::createShaderModule(const std::string &pFilename) { std::string source = ProcessShader(BASE_PATH + pFilename); - if (CTX.isDebugMode()) { + if (isDebugMode) { source = "#define DEBUG\n" + source; } for (auto &entry: ShadingModes::getShaderEntries()) { @@ -175,8 +177,8 @@ namespace Metal { const size_t sourceHash = std::hash{}(source); const std::string part(BASE_PATH + pFilename); const std::string shaderName = part.substr(part.find_last_of('/') + 1, part.size()); - const std::string binaryFilename = basePath + shaderName + ".spv"; - const std::string hashFilename = basePath + shaderName + ".hash"; + const std::string binaryFilename = shadersDirectory + shaderName + ".spv"; + const std::string hashFilename = shadersDirectory + shaderName + ".hash"; ShaderModule shader{}; @@ -193,7 +195,7 @@ namespace Metal { shaderCreateInfo.codeSize = shader.SPIRV.size() * sizeof(unsigned int); shaderCreateInfo.pCode = static_cast(shader.SPIRV.data()); - if (vkCreateShaderModule(CTX.vulkanContext.device.device, &shaderCreateInfo, + if (vkCreateShaderModule(vulkanContext.device.device, &shaderCreateInfo, nullptr, &shader.vkShaderModule) == VK_SUCCESS) { needsCompilation = false; LOG_INFO("Loaded cached shader: " + shaderName); diff --git a/src/engine/service/ShaderService.h b/src/engine/service/ShaderService.h new file mode 100644 index 00000000..43a2dd06 --- /dev/null +++ b/src/engine/service/ShaderService.h @@ -0,0 +1,34 @@ +#ifndef SHADERSERVICE_H +#define SHADERSERVICE_H +#include +#include "../dto/ShaderModule.h" +#include "../../common/AbstractRuntimeComponent.h" + +namespace Metal { + class VulkanContext; + + class ShaderService final : public AbstractRuntimeComponent { + bool isDebugMode; + std::string shadersDirectory; + VulkanContext &vulkanContext; + + static void CheckShaderCompilation(glslang_shader_t *shader); + + bool CompileShader(glslang_stage_t stage, const char *pShaderCode, + ShaderModule *shaderModule) const; + + static glslang_stage_t ShaderStageFromFilename(const char *pFilename); + + static std::string ProcessIncludes(const std::string &input); + + static std::string ProcessShader(const std::string &file); + + public: + explicit ShaderService(const std::string &shadersDirectory, bool isDebugMode, VulkanContext &vulkanContext) : shadersDirectory( + shadersDirectory), isDebugMode(isDebugMode), vulkanContext(vulkanContext){} + + VkShaderModule createShaderModule(const std::string &pFilename); + }; +} // Metal + +#endif diff --git a/src/engine/service/StreamingService.h b/src/engine/service/StreamingService.h index d93c7568..649e650a 100644 --- a/src/engine/service/StreamingService.h +++ b/src/engine/service/StreamingService.h @@ -4,8 +4,7 @@ #include #include -#include "../../common/AbstractResourceService.h" -#include "../../common/AbstractCoreRepository.h" +#include "../../common/AbstractRuntimeComponent.h" using Clock = std::chrono::high_resolution_clock; using TimePoint = std::chrono::time_point; diff --git a/src/engine/util/ShaderUtil.h b/src/engine/util/ShaderUtil.h deleted file mode 100644 index 13f07699..00000000 --- a/src/engine/util/ShaderUtil.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef SHADERSERVICE_H -#define SHADERSERVICE_H -#include -#include -#include - -#include "../dto/ShaderModule.h" - -namespace Metal { - class ShaderUtil final { - static void CheckShaderCompilation(glslang_shader_t *shader); - - static bool CompileShader(glslang_stage_t stage, const char *pShaderCode, - ShaderModule *shaderModule); - - static glslang_stage_t ShaderStageFromFilename(const char *pFilename); - - static std::string ProcessIncludes(const std::string &input); - - static std::string ProcessShader(const std::string &file); - - public: - static VkShaderModule CreateShaderModule(const std::string &pFilename); - }; -} // Metal - -#endif From eaf331e0ce1ce29869f0aee7cbe609a4321213cd Mon Sep 17 00:00:00 2001 From: facobackup Date: Sat, 14 Mar 2026 12:20:52 -0300 Subject: [PATCH 12/18] Dependency injection --- CMakeLists.txt | 27 +-- src/ApplicationContext.cpp | 129 +++---------- src/ApplicationContext.h | 176 +++++------------- src/common/AbstractCoreRepository.h | 17 -- src/common/AbstractImporter.h | 8 +- src/common/AbstractResourceService.h | 4 +- src/common/AbstractRuntimeComponent.h | 17 -- src/common/Changeable.h | 28 --- src/{editor/util => common}/FileDialogUtil.h | 4 +- src/{editor/util => common}/FilesUtil.h | 2 +- src/common/IContextMember.cpp | 10 + src/common/IContextMember.h | 32 ++++ src/common/IDisposable.h | 10 + src/common/{Initializable.h => IInit.h} | 4 +- src/common/IRepository.h | 13 ++ .../{Serializable.cpp => ISerialize.cpp} | 8 +- src/common/{Serializable.h => ISerialize.h} | 4 +- src/common/IService.h | 11 ++ src/common/{Synchornizable.h => ISync.h} | 4 +- src/common/Inspectable.h | 21 ++- .../LogService.cpp => common/LoggerUtil.cpp} | 2 +- .../LogService.h => common/LoggerUtil.h} | 1 - src/common/serialization-definitions.h | 2 +- src/core/DirectoryService.cpp | 59 ++++++ src/core/DirectoryService.h | 54 ++++++ src/core/FrameService.cpp | 70 +++++++ src/core/FrameService.h | 43 +++++ src/core/glfw/GLFWContext.cpp | 2 +- src/core/glfw/GLFWContext.h | 21 +-- src/core/gui/GuiContext.cpp | 51 +++-- src/core/gui/GuiContext.h | 27 ++- src/core/vulkan/VulkanContext.cpp | 64 +++---- src/core/vulkan/VulkanContext.h | 42 +++-- src/core/vulkan/VulkanUtils.cpp | 2 +- src/editor/abstract/IPanel.h | 6 +- src/editor/dock-spaces/console/ConsolePanel.h | 2 +- .../dock-spaces/docks/DockSpacePanel.cpp | 2 +- src/editor/dock-spaces/files/FilesPanel.cpp | 4 +- src/editor/dto/EntryMetadata.h | 4 +- src/editor/dto/SceneData.h | 4 +- src/editor/dto/SceneEntityData.h | 2 +- src/editor/enum/EntryType.h | 2 +- src/editor/panel/FileImportModalPanel.cpp | 2 +- src/editor/repository/DockRepository.cpp | 25 --- src/editor/repository/DockRepository.h | 21 --- src/editor/repository/EditorRepository.h | 5 +- src/editor/service/AsyncTaskService.cpp | 2 +- src/editor/service/AsyncTaskService.h | 7 +- src/editor/service/DockService.cpp | 22 +++ src/editor/service/DockService.h | 16 +- src/editor/service/FileImporterService.cpp | 28 +-- src/editor/service/FileImporterService.h | 32 ++-- src/editor/service/FilesService.cpp | 5 +- src/editor/service/FilesService.h | 16 +- .../service/MaterialImporterService.cpp | 6 +- src/editor/service/MaterialImporterService.h | 14 +- src/editor/service/MeshImporterService.cpp | 7 +- src/editor/service/MeshImporterService.h | 12 +- src/editor/service/NotificationService.h | 3 +- src/editor/service/PickingService.cpp | 23 ++- src/editor/service/PickingService.h | 20 +- src/editor/service/SceneImporterService.cpp | 7 +- src/editor/service/SceneImporterService.h | 19 +- src/editor/service/SelectionService.cpp | 28 +-- src/editor/service/SelectionService.h | 15 +- src/editor/service/TextureImporterService.cpp | 8 +- src/editor/service/TextureImporterService.h | 9 +- src/editor/service/ThemeService.h | 15 +- src/editor/service/VoxelImporterService.cpp | 5 +- src/editor/service/VoxelImporterService.h | 10 +- src/engine/EngineContext.cpp | 42 ++--- src/engine/EngineContext.h | 61 +++--- src/engine/dto/BoundingBox.h | 4 +- src/engine/dto/Camera.h | 4 +- src/engine/dto/MetadataComponent.h | 4 +- src/engine/dto/PrimitiveComponent.h | 4 +- src/engine/dto/SparseVoxelOctreeData.h | 4 +- src/engine/dto/TileInfoUBO.h | 13 -- src/engine/dto/TransformComponent.h | 4 +- src/engine/dto/VolumeComponent.h | 4 +- .../frame-builder/EngineFrameBuilder.cpp | 12 +- src/engine/frame-builder/EngineFrameBuilder.h | 1 - src/engine/passes/AbstractPass.h | 5 +- src/engine/repository/EngineRepository.h | 6 +- src/engine/repository/RuntimeRepository.h | 3 +- src/engine/repository/WorldRepository.cpp | 9 +- src/engine/repository/WorldRepository.h | 30 ++- src/engine/service/BufferService.h | 7 +- src/engine/service/CameraService.cpp | 24 +-- src/engine/service/CameraService.h | 20 +- src/engine/service/DescriptorSetService.cpp | 53 +++--- src/engine/service/DescriptorSetService.h | 26 ++- src/engine/service/FrameBufferService.h | 7 +- src/engine/service/LightService.cpp | 13 +- src/engine/service/LightService.h | 18 +- src/engine/service/MaterialService.cpp | 13 +- src/engine/service/MaterialService.h | 13 +- src/engine/service/MeshService.cpp | 16 +- src/engine/service/MeshService.h | 20 +- src/engine/service/PipelineService.h | 21 +-- src/engine/service/RayTracingService.cpp | 9 +- src/engine/service/RayTracingService.h | 46 +++-- src/engine/service/ShaderService.cpp | 27 +-- src/engine/service/ShaderService.h | 25 ++- src/engine/service/StreamingService.cpp | 25 +-- src/engine/service/StreamingService.h | 26 ++- src/engine/service/TextureService.cpp | 2 +- src/engine/service/TextureService.h | 24 ++- src/engine/service/TransformService.cpp | 11 +- src/engine/service/TransformService.h | 20 +- src/engine/service/VolumeService.cpp | 16 +- src/engine/service/VolumeService.h | 18 +- src/main.cpp | 102 +++++++++- 113 files changed, 1214 insertions(+), 975 deletions(-) delete mode 100644 src/common/AbstractCoreRepository.h delete mode 100644 src/common/AbstractRuntimeComponent.h delete mode 100644 src/common/Changeable.h rename src/{editor/util => common}/FileDialogUtil.h (94%) rename src/{editor/util => common}/FilesUtil.h (98%) create mode 100644 src/common/IContextMember.cpp create mode 100644 src/common/IContextMember.h create mode 100644 src/common/IDisposable.h rename src/common/{Initializable.h => IInit.h} (69%) create mode 100644 src/common/IRepository.h rename src/common/{Serializable.cpp => ISerialize.cpp} (77%) rename src/common/{Serializable.h => ISerialize.h} (84%) create mode 100644 src/common/IService.h rename src/common/{Synchornizable.h => ISync.h} (69%) rename src/{editor/service/LogService.cpp => common/LoggerUtil.cpp} (98%) rename src/{editor/service/LogService.h => common/LoggerUtil.h} (95%) create mode 100644 src/core/DirectoryService.cpp create mode 100644 src/core/DirectoryService.h create mode 100644 src/core/FrameService.cpp create mode 100644 src/core/FrameService.h delete mode 100644 src/editor/repository/DockRepository.cpp delete mode 100644 src/editor/repository/DockRepository.h delete mode 100644 src/engine/dto/TileInfoUBO.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 50fc7887..3b165cea 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,7 +29,7 @@ add_executable( src/ApplicationContext.h src/editor/abstract/AbstractPanel.h src/editor/abstract/AbstractPanel.cpp - src/common/Synchornizable.h + src/common/ISync.h src/engine/service/CameraService.cpp src/engine/service/CameraService.h src/engine/dto/Camera.h @@ -45,7 +45,6 @@ add_executable( src/editor/abstract/form/AccordionPanel.h src/common/FieldType.h src/common/InspectableMember.h - src/common/AbstractRuntimeComponent.h src/editor/abstract/form/types/BooleanField.cpp src/editor/abstract/form/types/BooleanField.h src/editor/abstract/form/types/IntField.cpp @@ -64,7 +63,6 @@ add_executable( src/common/Icons.h src/editor/service/DockService.cpp src/editor/service/DockService.h - src/editor/repository/DockRepository.h src/editor/dto/DockDTO.h src/editor/dto/DockSpace.h src/editor/dock-spaces/docks/DockSpacePanel.cpp @@ -84,8 +82,8 @@ add_executable( src/editor/dock-spaces/console/ConsolePanel.h src/editor/dock-spaces/metrics/MetricsPanel.cpp src/editor/dock-spaces/metrics/MetricsPanel.h - src/editor/service/LogService.cpp - src/editor/service/LogService.h + src/common/LoggerUtil.cpp + src/common/LoggerUtil.h src/editor/dock-spaces/world/WorldPanel.cpp src/editor/dock-spaces/world/WorldPanel.h src/engine/resource/RuntimeResource.h @@ -97,7 +95,6 @@ add_executable( src/engine/passes/AbstractRenderPass.h src/common/AbstractResourceService.h src/engine/resource/FrameBufferAttachment.h - src/common/AbstractCoreRepository.h src/engine/service/FrameBufferService.cpp src/engine/service/FrameBufferService.h src/engine/resource/FrameBufferInstance.h @@ -117,11 +114,11 @@ add_executable( src/engine/service/MeshService.h src/engine/dto/MeshData.h src/engine/resource/MeshInstance.h - src/editor/util/FilesUtil.h + src/common/FilesUtil.h src/editor/dto/FSEntry.h src/editor/enum/EntryType.h src/editor/dock-spaces/files/FilesContext.h - src/editor/util/FileDialogUtil.h + src/common/FileDialogUtil.h src/editor/dock-spaces/files/FilesHeaderPanel.cpp src/editor/dock-spaces/files/FilesHeaderPanel.h src/editor/service/MaterialImporterService.cpp @@ -223,7 +220,6 @@ add_executable( src/editor/service/PickingService.cpp src/editor/service/PickingService.h src/engine/resource/SVOInstance.h - src/engine/dto/TileInfoUBO.h src/engine/dto/LightData.h src/editor/passes/SelectionIDPass.cpp src/editor/passes/SelectionIDPass.h @@ -247,7 +243,7 @@ add_executable( src/engine/dto/VolumeData.h src/engine/service/VoxelService.cpp src/engine/service/VoxelService.h - src/common/Serializable.cpp + src/common/ISerialize.cpp src/editor/abstract/form/ChildPanel.cpp src/editor/abstract/form/ChildPanel.h src/editor/dto/SceneImportSettingsDTO.h @@ -269,7 +265,6 @@ add_executable( src/engine/dto/PipelineBuilder.cpp src/engine/service/DescriptorSetService.cpp src/engine/frame-builder/structures/CommandBufferRecorderBuilder.cpp - src/common/Changeable.h src/engine/passes/impl/TemporalAccumulationPass.cpp src/engine/passes/impl/TemporalAccumulationPass.h src/engine/passes/impl/SpatialFilterPass.cpp @@ -280,7 +275,15 @@ add_executable( src/editor/dock-spaces/repositories/RepositoriesPanel.h src/engine/service/VolumeService.cpp src/engine/service/VolumeService.h - src/editor/repository/DockRepository.cpp + src/common/IContextMember.h + src/common/IService.h + src/common/IRepository.h + src/common/IContextMember.cpp + src/core/DirectoryService.cpp + src/core/DirectoryService.h + src/common/IDisposable.h + src/core/FrameService.cpp + src/core/FrameService.h ) diff --git a/src/ApplicationContext.cpp b/src/ApplicationContext.cpp index 8c794998..a0cb05d3 100644 --- a/src/ApplicationContext.cpp +++ b/src/ApplicationContext.cpp @@ -1,125 +1,46 @@ #include "ApplicationContext.h" -#include -#include - -#include "editor/util/FilesUtil.h" -#include "core/vulkan/VulkanUtils.h" #include "common/serialization-definitions.h" +#include "common/LoggerUtil.h" -#include "editor/util/FileDialogUtil.h" -#include +#include "engine/EngineContext.h" +#include "core/glfw/GLFWContext.h" namespace Metal { + ApplicationContext *ApplicationContext::CONTEXT = nullptr; - void ApplicationContext::updateRootPath(bool forceSelection) { - std::string cachedPath; - std::string cachePathFile = std::filesystem::current_path().string() + CACHED_PATH; - FilesUtil::ReadFile(cachePathFile.c_str(), cachedPath); - cachedPath.erase(std::ranges::remove(cachedPath, '\n').begin(), cachedPath.cend()); - if (cachedPath.empty() || forceSelection || !fs::exists(cachedPath)) { - rootDirectory = FileDialogUtil::SelectDirectory(); - rootDirectory.erase(std::ranges::remove(rootDirectory, '\n').begin(), rootDirectory.cend()); - if (rootDirectory.empty()) { - throw std::runtime_error("No directory selected."); - } - save(); - FilesUtil::WriteFile(cachePathFile.c_str(), rootDirectory.c_str()); - } else { - rootDirectory = cachedPath; - } - PARSE_TEMPLATE(editorRepository, rootDirectory + "/" + HASH_OF_CLASS_NAME(EditorRepository) + ".json") - PARSE_TEMPLATE(engineRepository, rootDirectory + "/" + HASH_OF_CLASS_NAME(EngineRepository) + ".json") - PARSE_TEMPLATE(worldRepository, rootDirectory + "/" + HASH_OF_CLASS_NAME(WorldRepository) + ".json") + ApplicationContext::ApplicationContext(bool debugMode) : debugMode(debugMode) { + CONTEXT = this; + } + void ApplicationContext::onInitialize() { + for (auto &instance : instances) { + instance->setDependencies(*this); + } - FilesUtil::CreateDirectory(getShadersDirectory()); - FilesUtil::CreateDirectory(getAssetRefDirectory()); - FilesUtil::CreateDirectory(getAssetDirectory()); + for (auto &instance : instances) { + auto *init = dynamic_cast(instance.get()); + if (init) { + init->onInitialize(); + } + } } - unsigned int ApplicationContext::getFrameIndex() const { - return vulkanContext.imguiVulkanWindow.FrameIndex; + bool ApplicationContext::isDebugMode() const { + return debugMode; } void ApplicationContext::dispose() { - NFD_Quit(); try { - rayTracingService.destroyAccelerationStructures(); - asyncTaskService.endAll(); - engineContext.dispose(); - guiContext.dispose(); - vulkanContext.dispose(); - glfwContext.dispose(); - } catch (std::exception &e) { - std::cerr << e.what() << std::endl; - } - } - - void ApplicationContext::start() { - NFD_Init(); - - updateRootPath(false); - - glfwContext.onInitialize(); - if (!glfwContext.isValidContext()) { - throw std::runtime_error("Could not create window"); - } - vulkanContext.onInitialize(); - guiContext.onInitialize(); - filesService.onInitialize(); - editorPanel.applicationContext = this; - editorPanel.onInitialize(); - engineContext.onInitialize(); - - GLFWwindow *window = glfwContext.getWindow(); - while (!glfwWindowShouldClose(window)) { - if (glfwContext.beginFrame()) { - GuiContext::BeginFrame(); - editorPanel.onSync(); - ImGui::Render(); - auto *drawData = ImGui::GetDrawData(); - const bool main_is_minimized = (drawData->DisplaySize.x <= 0.0f || drawData->DisplaySize.y <= 0.0f); - if (!main_is_minimized) { - vulkanContext.getCommandBuffers().clear(); - auto &wd = vulkanContext.imguiVulkanWindow; - VkSemaphore imageAcquiredSemaphore = wd.FrameSemaphores[wd.SemaphoreIndex].ImageAcquiredSemaphore; - VkResult err = vkAcquireNextImageKHR(vulkanContext.device.device, wd.Swapchain, UINT64_MAX, - imageAcquiredSemaphore, VK_NULL_HANDLE, - &wd.FrameIndex); - if (err == VK_ERROR_OUT_OF_DATE_KHR || err == VK_SUBOPTIMAL_KHR) { - glfwContext.setSwapChainRebuild(true); - return; - } - - VulkanUtils::CheckVKResult(err); - ImGui_ImplVulkanH_Frame *fd = &wd.Frames[getFrameIndex()]; - VulkanUtils::CheckVKResult(vkWaitForFences(vulkanContext.device.device, 1, &fd->Fence, VK_TRUE, - UINT64_MAX)); - VulkanUtils::CheckVKResult(vkResetFences(vulkanContext.device.device, 1, &fd->Fence)); - VulkanUtils::CheckVKResult(vkResetCommandPool(vulkanContext.device.device, fd->CommandPool, - VK_COMMAND_POOL_RESET_RELEASE_RESOURCES_BIT)); - engineContext.onSync(); - GuiContext::RecordImguiCommandBuffer(drawData, err, wd, fd); - vulkanContext.submitFrame(imageAcquiredSemaphore, wd.FrameSemaphores[wd.SemaphoreIndex]. - RenderCompleteSemaphore, fd); + for (auto it = instances.rbegin(); it != instances.rend(); ++it) { + auto *disposable = dynamic_cast(it->get()); + if (disposable) { + disposable->dispose(); } - if (!main_is_minimized) - glfwContext.presentFrame(); + delete it->release(); } - } - dispose(); - } - - void ApplicationContext::save() { - try { - DUMP_TEMPLATE(rootDirectory + "/" + HASH_OF_CLASS_NAME(EditorRepository) + ".json", editorRepository) - DUMP_TEMPLATE(rootDirectory + "/" + HASH_OF_CLASS_NAME(EngineRepository) + ".json", engineRepository) - DUMP_TEMPLATE(rootDirectory + "/" + HASH_OF_CLASS_NAME(WorldRepository) + ".json", worldRepository) - notificationService.pushMessage("Project saved", NotificationSeverities::SUCCESS); - } catch (const std::exception &e) { + } catch (std::exception &e) { LOG_ERROR(e.what()); - notificationService.pushMessage("Could not save project", NotificationSeverities::ERROR); } } } diff --git a/src/ApplicationContext.h b/src/ApplicationContext.h index 78774aa7..0afd22a2 100644 --- a/src/ApplicationContext.h +++ b/src/ApplicationContext.h @@ -1,157 +1,65 @@ #ifndef METAL_ENGINE_APPLICATIONCONTEXT_H #define METAL_ENGINE_APPLICATIONCONTEXT_H -#define CACHED_PATH "/metal-engine-cached.txt" #include +#include +#include +#include +#include +#include +#include -#include "engine/EngineContext.h" -#include "core/glfw/GLFWContext.h" -#include "core/vulkan/VulkanContext.h" - -#include "engine/service/MeshService.h" -#include "engine/service/TextureService.h" -#include "engine/service/FrameBufferService.h" -#include "engine/service/PipelineService.h" -#include "engine/service/BufferService.h" -#include "engine/service/DescriptorSetService.h" -#include "editor/service/ThemeService.h" -#include "editor/service/DockService.h" -#include "editor/service/SelectionService.h" -#include "editor/service/SceneImporterService.h" -#include "editor/service/MeshImporterService.h" -#include "editor/service/MaterialImporterService.h" -#include "editor/service/TextureImporterService.h" -#include "editor/service/FilesService.h" -#include "editor/service/FileImporterService.h" -#include "engine/service/CameraService.h" - -#include "engine/repository/WorldRepository.h" -#include "engine/repository/RuntimeRepository.h" -#include "engine/service/StreamingService.h" -#include "engine/repository/EngineRepository.h" -#include "editor/repository/DockRepository.h" -#include "editor/repository/EditorRepository.h" -#include "engine/service/MaterialService.h" -#include "engine/service/CommandBufferRecorderService.h" -#include "editor/service/NotificationService.h" -#include "editor/service/AsyncTaskService.h" -#include "engine/service/TransformService.h" -#include "editor/service/PickingService.h" -#include "engine/service/VolumeService.h" -#include "editor/service/VoxelImporterService.h" -#include "engine/service/VoxelService.h" -#include "engine/service/LightService.h" -#include "engine/service/RayTracingService.h" -#include "editor/EditorPanel.h" -#include "core/gui/GuiContext.h" +#include "common/IInit.h" +#include "common/IContextMember.h" +#include "common/IDisposable.h" #define CTX ApplicationContext::CONTEXT +#define ENGINE_NAME "Metal Engine" + namespace Metal { - class ApplicationContext : public Initializable{ - EditorPanel editorPanel; - std::string rootDirectory; + namespace fs = std::filesystem; + class ApplicationContext : public IInit, public IDisposable { public: - static ApplicationContext CONTEXT; - - VulkanContext vulkanContext{ - true, - glfwContext, - engineRepository, - meshService, - textureService, - framebufferService, - pipelineService, - rayTracingService - }; - GuiContext guiContext{vulkanContext, glfwContext, descriptorSetService}; - GLFWContext glfwContext{}; - - EngineContext engineContext{ - transformService, - streamingService, - rayTracingService, - cameraService, - lightService, - volumeService, - worldRepository, - editorRepository, - engineRepository - }; - - // ----------- Repository - WorldRepository worldRepository{rayTracingService, rootDirectory}; - RuntimeRepository runtimeRepository{}; - EngineRepository engineRepository{}; - DockRepository dockRepository{}; - EditorRepository editorRepository{}; - - // ----------- Services - NotificationService notificationService; - AsyncTaskService asyncTaskService; - BufferService bufferService{vulkanContext}; - FrameBufferService framebufferService{vulkanContext}; - ThemeService themeService{editorRepository}; - DockService dockService{dockRepository}; - DescriptorSetService descriptorSetService{vulkanContext, framebufferService, bufferService, textureService}; - SelectionService selectionService{editorRepository, worldRepository}; - VoxelImporterService voxelImporterService{rootDirectory}; - MeshImporterService meshImporterService{rootDirectory}; - TextureImporterService textureImporter{rootDirectory}; - MaterialImporterService materialImporterService{textureImporter, rootDirectory}; - SceneImporterService sceneImporterService{meshImporterService, materialImporterService, rootDirectory}; - FilesService filesService{rootDirectory, notificationService}; - FileImporterService fileImporterService{ - sceneImporterService, textureImporter, voxelImporterService, notificationService, asyncTaskService - }; - CameraService cameraService{engineContext, worldRepository, runtimeRepository}; - PickingService pickingService{vulkanContext, bufferService, worldRepository}; - TransformService transformService{worldRepository, rayTracingService}; - LightService lightService{engineContext, engineRepository}; - VolumeService volumeService{worldRepository, engineContext}; - RayTracingService rayTracingService{ - vulkanContext, pipelineService, worldRepository, meshService, materialService, bufferService, engineContext - }; - CommandBufferRecorderService commandBufferRecorderService{}; - VoxelService voxelService{}; - StreamingService streamingService{engineContext, worldRepository, meshService, textureService, voxelService}; - // ----------- Services - // ----------- Repository - - [[nodiscard]] bool isDebugMode() const { return true; } + static ApplicationContext *CONTEXT; - void updateRootPath(bool forceSelection); + private: + std::unordered_map singletons; + std::vector > instances; + bool debugMode; - [[nodiscard]] bool isValidContext() const { - return glfwContext.isValidContext(); - } + public: + explicit ApplicationContext(bool debugMode); - [[nodiscard]] const std::string &getRootDirectory() const { - return rootDirectory; - } + void onInitialize() override; - [[nodiscard]] std::string getAssetRefDirectory() const { - return rootDirectory + "/assets-ref/"; + template + void registerSingleton(std::unique_ptr instance) { + static_assert(std::is_base_of_v, "T must derive from IContextMember"); + T *ptr = instance.get(); + singletons[typeid(T).name()] = static_cast(ptr); + instances.push_back(std::move(instance)); } - [[nodiscard]] std::string getShadersDirectory() const { - return rootDirectory + "/shaders/"; + template + T &getSingleton() { + auto it = singletons.find(typeid(T).name()); + if (it == singletons.end()) { + throw std::runtime_error(std::string("Singleton not registered: ") + typeid(T).name()); + } + return *static_cast(it->second); } - [[nodiscard]] std::string getAssetDirectory() const { - return rootDirectory + "/assets/"; + void *getSingletonByName(const std::string &name) { + auto it = singletons.find(name); + if (it == singletons.end()) { + throw std::runtime_error(std::string("Singleton not registered: ") + name); + } + return it->second; } - [[nodiscard]] std::string getVideoOutputPath() const { - return rootDirectory + "/output.mp4"; - } - - [[nodiscard]] unsigned int getFrameIndex() const; - - void dispose(); - - void start(); + [[nodiscard]] bool isDebugMode() const; - void save(); + void dispose() override; }; } diff --git a/src/common/AbstractCoreRepository.h b/src/common/AbstractCoreRepository.h deleted file mode 100644 index 93631a01..00000000 --- a/src/common/AbstractCoreRepository.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef ABSTRACTCOREREPOSITORY_H -#define ABSTRACTCOREREPOSITORY_H -#include "AbstractRuntimeComponent.h" - -namespace Metal { - class VulkanContext; - class FrameBufferService; - class BufferService; - class PipelineService; - - class AbstractCoreRepository : public AbstractRuntimeComponent { - }; - - -} // Metal - -#endif //ABSTRACTCOREREPOSITORY_H diff --git a/src/common/AbstractImporter.h b/src/common/AbstractImporter.h index 3507b6b9..ca3dbde0 100644 --- a/src/common/AbstractImporter.h +++ b/src/common/AbstractImporter.h @@ -5,19 +5,15 @@ #include #include "../editor/dto/ImportSettingsDTO.h" -#include "AbstractRuntimeComponent.h" +#include "IService.h" namespace Metal { - class AbstractImporter : public AbstractRuntimeComponent { + class AbstractImporter : public IService { public: virtual std::vector getSupportedTypes() { return {}; } - explicit AbstractImporter() - : AbstractRuntimeComponent() { - } - virtual std::string importData(const std::string &targetDir, const std::string &pathToFile, const std::shared_ptr &settings, const std::stop_token &stopToken) { diff --git a/src/common/AbstractResourceService.h b/src/common/AbstractResourceService.h index 25ad1072..a2e05ce3 100644 --- a/src/common/AbstractResourceService.h +++ b/src/common/AbstractResourceService.h @@ -4,14 +4,14 @@ #include #include -#include "AbstractRuntimeComponent.h" +#include "IService.h" #include "../engine/resource/RuntimeResource.h" namespace Metal { class VulkanContext; template - class AbstractResourceService : public AbstractRuntimeComponent { + class AbstractResourceService : public IService { static_assert(std::is_base_of_v, "T must be a subclass of RuntimeResource"); protected: diff --git a/src/common/AbstractRuntimeComponent.h b/src/common/AbstractRuntimeComponent.h deleted file mode 100644 index f2b753b1..00000000 --- a/src/common/AbstractRuntimeComponent.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef METAL_ENGINE_ABSTRACTRUNTIMECOMPONENT_H -#define METAL_ENGINE_ABSTRACTRUNTIMECOMPONENT_H - -#include "Changeable.h" -#include "Initializable.h" -#include "Synchornizable.h" - -#define ENGINE_NAME "Metal Engine" - -namespace Metal { - class AbstractRuntimeComponent : public Changeable, public Syncronizable, public Initializable { - public: - explicit AbstractRuntimeComponent() = default; - }; -} - -#endif diff --git a/src/common/Changeable.h b/src/common/Changeable.h deleted file mode 100644 index 8ce78c2b..00000000 --- a/src/common/Changeable.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef CHANGEABLE_H -#define CHANGEABLE_H - -namespace Metal { - class Changeable { - protected: - unsigned long changes = 0; - unsigned long frozenVersion = 99999; - - public: - [[nodiscard]] unsigned long getChangeId() const { - return changes; - } - - void registerChange() { - changes++; - } - - [[nodiscard]] bool isNotFrozen() const { - return frozenVersion != getChangeId(); - } - - void freezeVersion() { - frozenVersion = getChangeId(); - } - }; -} -#endif diff --git a/src/editor/util/FileDialogUtil.h b/src/common/FileDialogUtil.h similarity index 94% rename from src/editor/util/FileDialogUtil.h rename to src/common/FileDialogUtil.h index 39b4b9e3..205c261a 100644 --- a/src/editor/util/FileDialogUtil.h +++ b/src/common/FileDialogUtil.h @@ -3,8 +3,8 @@ #include #include #include -#include "../service/LogService.h" -#include "../../ApplicationContext.h" +#include "LoggerUtil.h" +#include "../ApplicationContext.h" namespace Metal:: FileDialogUtil { static std::vector PickFiles(std::vector filtersToApply) { diff --git a/src/editor/util/FilesUtil.h b/src/common/FilesUtil.h similarity index 98% rename from src/editor/util/FilesUtil.h rename to src/common/FilesUtil.h index 37aa80df..811fcf54 100644 --- a/src/editor/util/FilesUtil.h +++ b/src/common/FilesUtil.h @@ -2,7 +2,7 @@ #define FILESUTIL_H #include #include -#include "../dto/FSEntry.h" +#include "../editor/dto/FSEntry.h" namespace fs = std::filesystem; diff --git a/src/common/IContextMember.cpp b/src/common/IContextMember.cpp new file mode 100644 index 00000000..f42b28ce --- /dev/null +++ b/src/common/IContextMember.cpp @@ -0,0 +1,10 @@ +#include "IContextMember.h" +#include "../ApplicationContext.h" + +namespace Metal { + void IContextMember::setDependencies(ApplicationContext &ctx) { + for (auto &dep : getDependencies()) { + dep.ptr = ctx.getSingletonByName(dep.name); + } + } +} diff --git a/src/common/IContextMember.h b/src/common/IContextMember.h new file mode 100644 index 00000000..1226a4fc --- /dev/null +++ b/src/common/IContextMember.h @@ -0,0 +1,32 @@ +#ifndef METAL_ENGINE_CONTEXTMEMBER_H +#define METAL_ENGINE_CONTEXTMEMBER_H +#include +#include + +namespace Metal { + class ApplicationContext; + + struct Dependency { + std::string name; + void *ptr; + }; + + class IContextMember { + public: + virtual ~IContextMember() = default; + + /** + * Dependency injection. Called after all the context is created and + * will be the data used to initialize the pointers + */ + virtual std::vector getDependencies() { + return {}; + } + + /** + * Will call getDependencies and set the pointers based on the singletons returned + */ + void setDependencies(ApplicationContext &ctx); + }; +} +#endif //METAL_ENGINE_CONTEXTMEMBER_H diff --git a/src/common/IDisposable.h b/src/common/IDisposable.h new file mode 100644 index 00000000..e68d55ea --- /dev/null +++ b/src/common/IDisposable.h @@ -0,0 +1,10 @@ +#ifndef METAL_ENGINE_IDISPOSABLE_H +#define METAL_ENGINE_IDISPOSABLE_H +namespace Metal { + class IDisposable { + public: + virtual ~IDisposable() = default; + virtual void dispose() = 0; + }; +} +#endif \ No newline at end of file diff --git a/src/common/Initializable.h b/src/common/IInit.h similarity index 69% rename from src/common/Initializable.h rename to src/common/IInit.h index 3a3c44bb..93b6bfbd 100644 --- a/src/common/Initializable.h +++ b/src/common/IInit.h @@ -2,9 +2,9 @@ #define METAL_ENGINE_INITIALIZABLE_H namespace Metal { - class Initializable { + class IInit { public: - virtual ~Initializable() = default; + virtual ~IInit() = default; virtual void onInitialize() {} }; diff --git a/src/common/IRepository.h b/src/common/IRepository.h new file mode 100644 index 00000000..88576aad --- /dev/null +++ b/src/common/IRepository.h @@ -0,0 +1,13 @@ +#ifndef METAL_ENGINE_IREPOSITORY_H +#define METAL_ENGINE_IREPOSITORY_H +#include "IContextMember.h" +#include "Inspectable.h" +#include "ISerialize.h" + +namespace Metal { + class IRepository : public IContextMember, public Inspectable, public ISerialize { + public: + virtual ~IRepository() = default; + }; +} +#endif //METAL_ENGINE_IREPOSITORY_H diff --git a/src/common/Serializable.cpp b/src/common/ISerialize.cpp similarity index 77% rename from src/common/Serializable.cpp rename to src/common/ISerialize.cpp index c9a08f3d..192b3bfb 100644 --- a/src/common/Serializable.cpp +++ b/src/common/ISerialize.cpp @@ -1,19 +1,19 @@ -#include "Serializable.h" +#include "ISerialize.h" #include "../ApplicationContext.h" #include #include #include -#include "../editor/service/LogService.h" +#include "LoggerUtil.h" namespace Metal { - void Serializable::saveToJson(const std::string &path) const { + void ISerialize::saveToJson(const std::string &path) const { std::ofstream os(path); if (os.is_open()) { os << toJson().dump(4); } } - void Serializable::loadFromJson(const std::string &path) { + void ISerialize::loadFromJson(const std::string &path) { if (std::filesystem::exists(path)) { std::ifstream is(path); if (is.is_open()) { diff --git a/src/common/Serializable.h b/src/common/ISerialize.h similarity index 84% rename from src/common/Serializable.h rename to src/common/ISerialize.h index b98f673f..d40b4922 100644 --- a/src/common/Serializable.h +++ b/src/common/ISerialize.h @@ -4,9 +4,9 @@ #include namespace Metal { - class Serializable { + class ISerialize { public: - virtual ~Serializable() = default; + virtual ~ISerialize() = default; virtual nlohmann::json toJson() const = 0; diff --git a/src/common/IService.h b/src/common/IService.h new file mode 100644 index 00000000..c880c173 --- /dev/null +++ b/src/common/IService.h @@ -0,0 +1,11 @@ +#ifndef METAL_ENGINE_ISERVICE_H +#define METAL_ENGINE_ISERVICE_H +#include "IContextMember.h" + +namespace Metal { + class IService : public IContextMember { + public: + virtual ~IService() = default; + }; +} +#endif //METAL_ENGINE_ISERVICE_H diff --git a/src/common/Synchornizable.h b/src/common/ISync.h similarity index 69% rename from src/common/Synchornizable.h rename to src/common/ISync.h index d5640524..9cd8af3f 100644 --- a/src/common/Synchornizable.h +++ b/src/common/ISync.h @@ -2,9 +2,9 @@ #define METAL_ENGINE_SYNCHORNIZABLE_H namespace Metal { - class Syncronizable { + class ISync { public: - virtual ~Syncronizable() = default; + virtual ~ISync() = default; virtual void onSync() {} }; diff --git a/src/common/Inspectable.h b/src/common/Inspectable.h index 3c300946..e5990746 100644 --- a/src/common/Inspectable.h +++ b/src/common/Inspectable.h @@ -9,13 +9,14 @@ #include "InspectableMember.h" #include "../editor/util/Util.h" #include "../editor/enum/EntryType.h" -#include "Changeable.h" namespace Metal { - class Inspectable : public Changeable { + class Inspectable { std::string uniqueIdentifier = Util::uuidV4(); std::vector > fields{}; bool fieldsRegistered = false; + unsigned long changes = 0; + unsigned long frozenVersion = 99999; public: Inspectable &operator=(const Inspectable &other) { @@ -87,6 +88,22 @@ namespace Metal { std::string group, std::string name, bool disabled = false); public: + [[nodiscard]] unsigned long getChangeId() const { + return changes; + } + + void registerChange() { + changes++; + } + + [[nodiscard]] bool isNotFrozen() const { + return frozenVersion != getChangeId(); + } + + void freezeVersion() { + frozenVersion = getChangeId(); + } + std::vector > &getFields(); Inspectable() = default; diff --git a/src/editor/service/LogService.cpp b/src/common/LoggerUtil.cpp similarity index 98% rename from src/editor/service/LogService.cpp rename to src/common/LoggerUtil.cpp index c0d5cb41..9f8871cb 100644 --- a/src/editor/service/LogService.cpp +++ b/src/common/LoggerUtil.cpp @@ -1,4 +1,4 @@ -#include "LogService.h" +#include "LoggerUtil.h" #include #include #include diff --git a/src/editor/service/LogService.h b/src/common/LoggerUtil.h similarity index 95% rename from src/editor/service/LogService.h rename to src/common/LoggerUtil.h index 756e30c4..be198cc3 100644 --- a/src/editor/service/LogService.h +++ b/src/common/LoggerUtil.h @@ -4,7 +4,6 @@ #include #include #include -#include "../../common/AbstractRuntimeComponent.h" namespace Metal { diff --git a/src/common/serialization-definitions.h b/src/common/serialization-definitions.h index eab3426b..1a70f527 100644 --- a/src/common/serialization-definitions.h +++ b/src/common/serialization-definitions.h @@ -3,7 +3,7 @@ #include #include -#include "Serializable.h" +#include "ISerialize.h" #include #include #include diff --git a/src/core/DirectoryService.cpp b/src/core/DirectoryService.cpp new file mode 100644 index 00000000..785e1d45 --- /dev/null +++ b/src/core/DirectoryService.cpp @@ -0,0 +1,59 @@ +#include "DirectoryService.h" +#include "../common/FileDialogUtil.h" +#include "../common/FilesUtil.h" +#include "../common/serialization-definitions.h" + +#include +#define CACHED_PATH "/metal-engine-cached.txt" +#include "../editor/repository/EditorRepository.h" +#include "../editor/service/NotificationService.h" +#include "../engine/repository/EngineRepository.h" +#include "../engine/repository/WorldRepository.h" + +namespace Metal { + void DirectoryService::updateRootPath(bool forceSelection) { + std::string cachedPath; + std::string cachePathFile = std::filesystem::current_path().string() + CACHED_PATH; + FilesUtil::ReadFile(cachePathFile.c_str(), cachedPath); + cachedPath.erase(std::ranges::remove(cachedPath, '\n').begin(), cachedPath.cend()); + if (cachedPath.empty() || forceSelection || !fs::exists(cachedPath)) { + rootDirectory = FileDialogUtil::SelectDirectory(); + rootDirectory.erase(std::ranges::remove(rootDirectory, '\n').begin(), rootDirectory.cend()); + if (rootDirectory.empty()) { + throw std::runtime_error("No directory selected."); + } + save(); + FilesUtil::WriteFile(cachePathFile.c_str(), rootDirectory.c_str()); + } else { + rootDirectory = cachedPath; + } + + // TODO - LOOP REPOSITORY SINGLETONS AND CALL + PARSE_TEMPLATE(*editorRepository, rootDirectory + "/" + HASH_OF_CLASS_NAME(EditorRepository) + ".json") + PARSE_TEMPLATE(*engineRepository, rootDirectory + "/" + HASH_OF_CLASS_NAME(EngineRepository) + ".json") + PARSE_TEMPLATE(*worldRepository, rootDirectory + "/" + HASH_OF_CLASS_NAME(WorldRepository) + ".json") + + + FilesUtil::CreateDirectory(getShadersDirectory()); + FilesUtil::CreateDirectory(getAssetRefDirectory()); + FilesUtil::CreateDirectory(getAssetDirectory()); + } + + + void DirectoryService::save() { + try { + // TODO - LOOP REPOSITORY SINGLETONS AND CALL + + DUMP_TEMPLATE(rootDirectory + "/" + HASH_OF_CLASS_NAME(EditorRepository) + ".json", + *editorRepository) + DUMP_TEMPLATE(rootDirectory + "/" + HASH_OF_CLASS_NAME(EngineRepository) + ".json", + *engineRepository) + DUMP_TEMPLATE(rootDirectory + "/" + HASH_OF_CLASS_NAME(WorldRepository) + ".json", + *worldRepository) + notificationService->pushMessage("Project saved", NotificationSeverities::SUCCESS); + } catch (const std::exception &e) { + LOG_ERROR(e.what()); + notificationService->pushMessage("Could not save project", NotificationSeverities::ERROR); + } + } +} // Metal diff --git a/src/core/DirectoryService.h b/src/core/DirectoryService.h new file mode 100644 index 00000000..a02b1339 --- /dev/null +++ b/src/core/DirectoryService.h @@ -0,0 +1,54 @@ +#ifndef METAL_ENGINE_DIRECTORYSERVICE_H +#define METAL_ENGINE_DIRECTORYSERVICE_H +#include "../common/IService.h" + +namespace Metal { + struct EditorRepository; + struct EngineRepository; + struct WorldRepository; + class NotificationService; + + struct DirectoryService final : IService { + EditorRepository *editorRepository = nullptr; + EngineRepository *engineRepository = nullptr; + WorldRepository *worldRepository = nullptr; + NotificationService *notificationService = nullptr; + + std::string rootDirectory; + + std::vector getDependencies() override { + return { + {"EditorRepository", editorRepository}, + {"EngineRepository", engineRepository}, + {"WorldRepository", worldRepository}, + {"NotificationService", notificationService} + }; + } + + void updateRootPath(bool forceSelection); + + void save(); + + [[nodiscard]] const std::string &getRootDirectory() const { + return rootDirectory; + } + + [[nodiscard]] std::string getAssetRefDirectory() const { + return rootDirectory + "/assets-ref/"; + } + + [[nodiscard]] std::string getShadersDirectory() const { + return rootDirectory + "/shaders/"; + } + + [[nodiscard]] std::string getAssetDirectory() const { + return rootDirectory + "/assets/"; + } + + [[nodiscard]] std::string getVideoOutputPath() const { + return rootDirectory + "/output.mp4"; + } + }; +} // Metal + +#endif //METAL_ENGINE_DIRECTORYSERVICE_H diff --git a/src/core/FrameService.cpp b/src/core/FrameService.cpp new file mode 100644 index 00000000..48b35d6d --- /dev/null +++ b/src/core/FrameService.cpp @@ -0,0 +1,70 @@ +#include "FrameService.h" + +#include +#include + +#include "gui/GuiContext.h" +#include "vulkan/VulkanContext.h" +#include "glfw/GLFWContext.h" +#include "../editor/abstract/AbstractPanel.h" +#include "../engine/EngineContext.h" +#include "vulkan/VulkanUtils.h" + +namespace Metal { + unsigned int FrameService::getFrameIndex() const { + return vulkanContext->imguiVulkanWindow.FrameIndex; + } + + void FrameService::dispose() { + NFD_Quit(); + } + + bool FrameService::isValidContext() const { + return glfwContext->isValidContext(); + } + + void FrameService::setPanel(AbstractPanel *panel) { + this->panel = panel; + } + + void FrameService::onInitialize() { + NFD_Init(); + + GLFWwindow *window = glfwContext->getWindow(); + while (!glfwWindowShouldClose(window)) { + if (glfwContext->beginFrame()) { + GuiContext::BeginFrame(); + panel->onSync(); + ImGui::Render(); + auto *drawData = ImGui::GetDrawData(); + const bool main_is_minimized = (drawData->DisplaySize.x <= 0.0f || drawData->DisplaySize.y <= 0.0f); + if (!main_is_minimized) { + vulkanContext->getCommandBuffers().clear(); + auto &wd = vulkanContext->imguiVulkanWindow; + VkSemaphore imageAcquiredSemaphore = wd.FrameSemaphores[wd.SemaphoreIndex].ImageAcquiredSemaphore; + VkResult err = vkAcquireNextImageKHR(vulkanContext->device.device, wd.Swapchain, UINT64_MAX, + imageAcquiredSemaphore, VK_NULL_HANDLE, + &wd.FrameIndex); + if (err == VK_ERROR_OUT_OF_DATE_KHR || err == VK_SUBOPTIMAL_KHR) { + glfwContext->setSwapChainRebuild(true); + return; + } + + VulkanUtils::CheckVKResult(err); + ImGui_ImplVulkanH_Frame *fd = &wd.Frames[getFrameIndex()]; + VulkanUtils::CheckVKResult(vkWaitForFences(vulkanContext->device.device, 1, &fd->Fence, VK_TRUE, + UINT64_MAX)); + VulkanUtils::CheckVKResult(vkResetFences(vulkanContext->device.device, 1, &fd->Fence)); + VulkanUtils::CheckVKResult(vkResetCommandPool(vulkanContext->device.device, fd->CommandPool, + VK_COMMAND_POOL_RESET_RELEASE_RESOURCES_BIT)); + engineContext->onSync(); + GuiContext::RecordImguiCommandBuffer(drawData, err, wd, fd); + vulkanContext->submitFrame(imageAcquiredSemaphore, wd.FrameSemaphores[wd.SemaphoreIndex]. + RenderCompleteSemaphore, fd); + } + if (!main_is_minimized) + glfwContext->presentFrame(); + } + } + } +} // Metal diff --git a/src/core/FrameService.h b/src/core/FrameService.h new file mode 100644 index 00000000..d00287f1 --- /dev/null +++ b/src/core/FrameService.h @@ -0,0 +1,43 @@ +#ifndef METAL_ENGINE_FRAMESERVICE_H +#define METAL_ENGINE_FRAMESERVICE_H +#include "../common/IDisposable.h" +#include "../common/IInit.h" +#include "../common/IService.h" + +namespace Metal { + class EngineContext; + class VulkanContext; + class GLFWContext; + class GuiContext; + class AbstractPanel; + + class FrameService final : public IService, public IInit, public IDisposable { + GLFWContext *glfwContext = nullptr; + VulkanContext *vulkanContext = nullptr; + EngineContext *engineContext = nullptr; + GuiContext *guiContext = nullptr; + AbstractPanel *panel = nullptr; + + public: + std::vector getDependencies() override { + return { + {"GLFWContext", glfwContext}, + {"VulkanContext", vulkanContext}, + {"GuiContext", guiContext}, + {"EngineContext", engineContext} + }; + } + + void setPanel(AbstractPanel *panel); + + void onInitialize() override; + + [[nodiscard]] bool isValidContext() const; + + [[nodiscard]] unsigned int getFrameIndex() const; + + void dispose() override; + }; +} // Metal + +#endif //METAL_ENGINE_FRAMESERVICE_H diff --git a/src/core/glfw/GLFWContext.cpp b/src/core/glfw/GLFWContext.cpp index 4c489631..ae539bb5 100644 --- a/src/core/glfw/GLFWContext.cpp +++ b/src/core/glfw/GLFWContext.cpp @@ -42,7 +42,7 @@ namespace Metal { return true; } - void GLFWContext::dispose() const { + void GLFWContext::dispose() { glfwDestroyWindow(window); glfwTerminate(); } diff --git a/src/core/glfw/GLFWContext.h b/src/core/glfw/GLFWContext.h index 01ac63cb..0f4b06d4 100644 --- a/src/core/glfw/GLFWContext.h +++ b/src/core/glfw/GLFWContext.h @@ -6,31 +6,34 @@ #include #include -#include "../../common/AbstractRuntimeComponent.h" + +#include "../../common/IContextMember.h" +#include "../../common/IDisposable.h" +#include "../../common/IInit.h" struct ImGui_ImplVulkanH_Window; namespace Metal { class ApplicationContext; - class VulkanContext; - class GLFWContext final : public Initializable { + class GLFWContext final : public IContextMember, public IInit, public IDisposable { VulkanContext *vulkanContext = nullptr; GLFWwindow *window = nullptr; bool validContext = true; - ; bool swapChainRebuild = false; ImVector instance_extensions{}; public: + std::vector getDependencies() override { + return {{"VulkanContext", vulkanContext}}; + } + void setSwapChainRebuild(bool val); void presentFrame(); - explicit GLFWContext() = default; - [[nodiscard]] const ImVector &getInstanceExtensions() const; void onInitialize() override; @@ -41,13 +44,9 @@ namespace Metal { bool beginFrame(); - void dispose() const; + void dispose() override; [[nodiscard]] ImGui_ImplVulkanH_Window &getGUIWindow() const; - - void setVulkanContext(VulkanContext *vulkanContext) { - this->vulkanContext = vulkanContext; - } }; } diff --git a/src/core/gui/GuiContext.cpp b/src/core/gui/GuiContext.cpp index b92bfff5..ab84174b 100644 --- a/src/core/gui/GuiContext.cpp +++ b/src/core/gui/GuiContext.cpp @@ -7,17 +7,16 @@ #include "../../engine/dto/DescriptorInstance.h" #include "../../engine/resource/TextureInstance.h" -namespace Metal { - #include "../vulkan/VulkanContext.h" - #include "../glfw/GLFWContext.h" - #include "../../engine/service/DescriptorSetService.h" +#include "../vulkan/VulkanContext.h" +#include "../glfw/GLFWContext.h" +#include "../../engine/service/DescriptorSetService.h" +namespace Metal { void GuiContext::endFrame() { - } void GuiContext::renderImage(TextureInstance *texture, const float sizeX, const float sizeY) const { - descriptorSetService.setImageDescriptor(texture); + descriptorSetService->setImageDescriptor(texture); ImGui::Image(reinterpret_cast(texture->imageDescriptor->vkDescriptorSet), ImVec2{sizeX, sizeY}); } @@ -33,7 +32,8 @@ namespace Metal { info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; info.flags |= VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; err = vkBeginCommandBuffer(fd->CommandBuffer, &info); - VulkanUtils::CheckVKResult(err); { + VulkanUtils::CheckVKResult(err); + { VkRenderPassBeginInfo info = {}; info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; info.renderPass = wd.RenderPass; @@ -65,19 +65,19 @@ namespace Metal { io.ConfigWindowsResizeFromEdges = true; // Setup Platform/Renderer backends - ImGui_ImplGlfw_InitForVulkan(glfwContext.getWindow(), true); + ImGui_ImplGlfw_InitForVulkan(glfwContext->getWindow(), true); ImGui_ImplVulkan_InitInfo init_info = {}; - init_info.Instance = vulkanContext.instance.instance; - init_info.PhysicalDevice = vulkanContext.physDevice.physical_device; - init_info.Device = vulkanContext.device.device; - init_info.QueueFamily = vulkanContext.queueFamily; - init_info.Queue = vulkanContext.graphicsQueue; - init_info.PipelineCache = vulkanContext.pipelineCache; - init_info.DescriptorPool = vulkanContext.descriptorPool; - init_info.RenderPass = vulkanContext.imguiVulkanWindow.RenderPass; + init_info.Instance = vulkanContext->instance.instance; + init_info.PhysicalDevice = vulkanContext->physDevice.physical_device; + init_info.Device = vulkanContext->device.device; + init_info.QueueFamily = vulkanContext->queueFamily; + init_info.Queue = vulkanContext->graphicsQueue; + init_info.PipelineCache = vulkanContext->pipelineCache; + init_info.DescriptorPool = vulkanContext->descriptorPool; + init_info.RenderPass = vulkanContext->imguiVulkanWindow.RenderPass; init_info.Subpass = 0; init_info.MinImageCount = MAX_FRAMES_IN_FLIGHT; - init_info.ImageCount = vulkanContext.imguiVulkanWindow.ImageCount; + init_info.ImageCount = vulkanContext->imguiVulkanWindow.ImageCount; init_info.MSAASamples = VK_SAMPLE_COUNT_1_BIT; init_info.Allocator = nullptr; init_info.CheckVkResultFn = VulkanUtils::CheckVKResult; @@ -140,23 +140,14 @@ namespace Metal { delete fontConfig; } - void GuiContext::dispose() const { - const VkResult err = vkDeviceWaitIdle(vulkanContext.device.device); + void GuiContext::dispose() { + const VkResult err = vkDeviceWaitIdle(vulkanContext->device.device); VulkanUtils::CheckVKResult(err); ImGui_ImplVulkan_Shutdown(); ImGui_ImplGlfw_Shutdown(); ImGui::DestroyContext(); - ImGui_ImplVulkanH_DestroyWindow(vulkanContext.instance, vulkanContext.device.device, - &glfwContext.getGUIWindow(), + ImGui_ImplVulkanH_DestroyWindow(vulkanContext->instance.instance, vulkanContext->device.device, + &glfwContext->getGUIWindow(), nullptr); } - - GuiContext::GuiContext(VulkanContext &vulkanContext, - GLFWContext &glfwContext, - DescriptorSetService &descriptorSetService) - : AbstractRuntimeComponent(), - vulkanContext(vulkanContext), - glfwContext(glfwContext), - descriptorSetService(descriptorSetService) { - } } diff --git a/src/core/gui/GuiContext.h b/src/core/gui/GuiContext.h index 5324f944..5c117b02 100644 --- a/src/core/gui/GuiContext.h +++ b/src/core/gui/GuiContext.h @@ -4,19 +4,22 @@ #define LARGE_FONT_SIZE 38 #include #include -#include "../../common/AbstractRuntimeComponent.h" +#include "../../common/IService.h" +#include "../../common/IDisposable.h" +#include "../../common/IInit.h" namespace Metal { + class GLFWContext; struct FrameBufferAttachment; struct TextureInstance; class VulkanContext; class DescriptorSetService; - class GuiContext final : public AbstractRuntimeComponent { - VulkanContext &vulkanContext; - GLFWContext &glfwContext; - DescriptorSetService &descriptorSetService; + class GuiContext final : public IService, public IDisposable, public IInit { + VulkanContext *vulkanContext = nullptr; + GLFWContext *glfwContext = nullptr; + DescriptorSetService *descriptorSetService = nullptr; static void applySpacing(); @@ -26,15 +29,21 @@ namespace Metal { ImFont *largeIconsFont = nullptr; public: - explicit GuiContext(VulkanContext &vulkanContext, - GLFWContext &glfwContext, - DescriptorSetService &descriptorSetService); + GuiContext() = default; + + std::vector getDependencies() override { + return { + {"VulkanContext", vulkanContext}, + {"GLFWContext", glfwContext}, + {"DescriptorSetService", descriptorSetService} + }; + } [[ nodiscard]] ImFont *getLargeIconsFont() const { return largeIconsFont; } - void dispose() const; + void dispose() override; void onInitialize() override; diff --git a/src/core/vulkan/VulkanContext.cpp b/src/core/vulkan/VulkanContext.cpp index 9480dbda..4c38039e 100644 --- a/src/core/vulkan/VulkanContext.cpp +++ b/src/core/vulkan/VulkanContext.cpp @@ -2,27 +2,17 @@ #include "VkBootstrap.h" #include "VulkanUtils.h" #include "../../ApplicationContext.h" -#include "../../editor/service/LogService.h" +#include "../../common/LoggerUtil.h" + +#include "../glfw/GLFWContext.h" +#include "../../engine/repository/EngineRepository.h" +#include "../../engine/service/MeshService.h" +#include "../../engine/service/TextureService.h" +#include "../../engine/service/FrameBufferService.h" +#include "../../engine/service/PipelineService.h" +#include "../../engine/service/RayTracingService.h" namespace Metal { - VulkanContext::VulkanContext(bool debugMode, - GLFWContext &glfwContext, - EngineRepository &engineRepository, - MeshService &meshService, - TextureService &textureService, - FrameBufferService &framebufferService, - PipelineService &pipelineService, - RayTracingService &rayTracingService) - : AbstractRuntimeComponent(), - glfwContext(glfwContext), - engineRepository(engineRepository), - meshService(meshService), - textureService(textureService), - framebufferService(framebufferService), - pipelineService(pipelineService), - rayTracingService(rayTracingService), - debugMode(debugMode) { - } void VulkanContext::createSwapChain() { int w{}, h{}; @@ -177,7 +167,7 @@ namespace Metal { } void VulkanContext::createPresentMode() { - VkPresentModeKHR presentModes = !engineRepository.vsync + VkPresentModeKHR presentModes = !engineRepository->vsync ? VK_PRESENT_MODE_IMMEDIATE_KHR : VK_PRESENT_MODE_FIFO_KHR; imguiVulkanWindow.PresentMode = ImGui_ImplVulkanH_SelectPresentMode( @@ -264,17 +254,18 @@ namespace Metal { } void VulkanContext::onInitialize() { + this->debugMode = CTX->isDebugMode(); + this->window = glfwContext->getWindow(); + imguiVulkanWindow.ClearValue.color.float32[0] = 0; imguiVulkanWindow.ClearValue.color.float32[1] = 0; imguiVulkanWindow.ClearValue.color.float32[2] = 0; imguiVulkanWindow.ClearValue.color.float32[3] = 1; - - this->window = glfwContext.getWindow(); vkb::InstanceBuilder instanceBuilder; // ------- CORE INITIALIZATION // ----- INSTANCE AND EXTENSIONS - addExtensions(instanceBuilder, glfwContext.getInstanceExtensions()); + addExtensions(instanceBuilder, glfwContext->getInstanceExtensions()); auto vkbResult = instanceBuilder .set_app_name(ENGINE_NAME) .set_engine_name(ENGINE_NAME) @@ -296,17 +287,17 @@ namespace Metal { createMemoryAllocator(); createCommandPool(); createDescriptorPool(); - textureService.createSampler(false, vkImageSampler, VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER); - textureService.createSampler(true, vkTextureSampler, VK_SAMPLER_ADDRESS_MODE_REPEAT); + textureService->createSampler(false, vkImageSampler, VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER); + textureService->createSampler(true, vkTextureSampler, VK_SAMPLER_ADDRESS_MODE_REPEAT); // ------- CORE INITIALIZATION } - void VulkanContext::dispose() const { - pipelineService.disposeAll(); - textureService.disposeAll(); - meshService.disposeAll(); - framebufferService.disposeAll(); - rayTracingService.destroyAccelerationStructures(); + void VulkanContext::dispose() { + pipelineService->disposeAll(); + textureService->disposeAll(); + meshService->disposeAll(); + framebufferService->disposeAll(); + rayTracingService->dispose(); vkDestroySampler(device.device, vkImageSampler, nullptr); vkDestroySampler(device.device, vkTextureSampler, nullptr); @@ -322,7 +313,7 @@ namespace Metal { } void VulkanContext::createDescriptorPool() const { - const std::array sizes{ + const std::array sizes{ VkDescriptorPoolSize{VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 100}, // 1 for imgui VkDescriptorPoolSize{VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 100}, VkDescriptorPoolSize{VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 100}, @@ -332,13 +323,14 @@ namespace Metal { VkDescriptorPoolCreateInfo poolInfo{}; poolInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; - poolInfo.poolSizeCount = sizes.size(); + poolInfo.poolSizeCount = static_cast(sizes.size()); poolInfo.pPoolSizes = sizes.data(); - poolInfo.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT | VK_DESCRIPTOR_POOL_CREATE_UPDATE_AFTER_BIND_BIT; + poolInfo.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT | + VK_DESCRIPTOR_POOL_CREATE_UPDATE_AFTER_BIND_BIT; poolInfo.maxSets = 500; VulkanUtils::CheckVKResult(vkCreateDescriptorPool(device.device, &poolInfo, - nullptr, &descriptorPool)); + nullptr, const_cast(&descriptorPool))); } VkCommandBuffer VulkanContext::beginSingleTimeCommands() const { @@ -375,7 +367,7 @@ namespace Metal { void VulkanContext::submitFrame(VkSemaphore image_acquired_semaphore, VkSemaphore render_complete_semaphore, - ImGui_ImplVulkanH_Frame *fd) { + ImGui_ImplVulkanH_Frame *fd) { VkPipelineStageFlags wait_stage = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT; VkSubmitInfo info = {}; pushCommandBuffer(fd->CommandBuffer); diff --git a/src/core/vulkan/VulkanContext.h b/src/core/vulkan/VulkanContext.h index 0da550f5..deed4b7a 100644 --- a/src/core/vulkan/VulkanContext.h +++ b/src/core/vulkan/VulkanContext.h @@ -2,12 +2,13 @@ #define METAL_ENGINE_VULKANCONTEXT_H #include "vk_mem_alloc.h" -#include #include "imgui_impl_vulkan.h" #include #include "VkBootstrap.h" -#include "../../common/AbstractRuntimeComponent.h" +#include "../../common/IInit.h" +#include "../../common/IService.h" +#include "../../common/IDisposable.h" #define VK_KHR_PORTABILITY_SUBSET_EXTENSION_NAME "VK_KHR_portability_subset" @@ -20,14 +21,14 @@ namespace Metal { class PipelineService; class RayTracingService; - class VulkanContext final : public AbstractRuntimeComponent { - GLFWContext &glfwContext; - EngineRepository &engineRepository; - MeshService &meshService; - TextureService &textureService; - FrameBufferService &framebufferService; - PipelineService &pipelineService; - RayTracingService &rayTracingService; + class VulkanContext final : public IService, public IDisposable, public IInit { + GLFWContext *glfwContext = nullptr; + EngineRepository *engineRepository = nullptr; + MeshService *meshService = nullptr; + TextureService *textureService = nullptr; + FrameBufferService *framebufferService = nullptr; + PipelineService *pipelineService = nullptr; + RayTracingService *rayTracingService = nullptr; static VkBool32 DebugCallback(VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity, VkDebugUtilsMessageTypeFlagsEXT messageType, @@ -67,14 +68,17 @@ namespace Metal { std::vector &getCommandBuffers() { return commandBuffers; } - explicit VulkanContext(bool debugMode, - GLFWContext &glfwContext, - EngineRepository &engineRepository, - MeshService &meshService, - TextureService &textureService, - FrameBufferService &framebufferService, - PipelineService &pipelineService, - RayTracingService &rayTracingService); + std::vector getDependencies() override { + return { + {"GLFWContext", glfwContext}, + {"EngineRepository", engineRepository}, + {"MeshService", meshService}, + {"TextureService", textureService}, + {"FrameBufferService", framebufferService}, + {"PipelineService", pipelineService}, + {"RayTracingService", rayTracingService} + }; + } VkPhysicalDeviceProperties physicalDeviceProperties{}; VkPhysicalDeviceMemoryProperties physicalDeviceMemoryProperties{}; @@ -104,7 +108,7 @@ namespace Metal { PFN_vkGetRayTracingShaderGroupHandlesKHR vkGetRayTracingShaderGroupHandlesKHR = nullptr; PFN_vkCmdTraceRaysKHR vkCmdTraceRaysKHR = nullptr; - void dispose() const; + void dispose() override; void onInitialize() override; diff --git a/src/core/vulkan/VulkanUtils.cpp b/src/core/vulkan/VulkanUtils.cpp index 9a133c92..9890c96a 100644 --- a/src/core/vulkan/VulkanUtils.cpp +++ b/src/core/vulkan/VulkanUtils.cpp @@ -2,7 +2,7 @@ #include "../../../dependencies/vk-bootstrap/src/VkBootstrap.h" #include "../../ApplicationContext.h" -#include "../../editor/service/LogService.h" +#include "../../common/LoggerUtil.h" namespace Metal { void VulkanUtils::CheckVKResult(VkResult err) { diff --git a/src/editor/abstract/IPanel.h b/src/editor/abstract/IPanel.h index 126139fe..48dfc868 100644 --- a/src/editor/abstract/IPanel.h +++ b/src/editor/abstract/IPanel.h @@ -1,11 +1,11 @@ #ifndef METAL_ENGINE_IPANEL_H #define METAL_ENGINE_IPANEL_H -#include "../../common/Synchornizable.h" -#include "../../common/Initializable.h" +#include "../../common/ISync.h" +#include "../../common/IInit.h" namespace Metal { - class IPanel : public Syncronizable, public Initializable { + class IPanel : public ISync, public IInit { public: virtual void removeAllChildren() { } diff --git a/src/editor/dock-spaces/console/ConsolePanel.h b/src/editor/dock-spaces/console/ConsolePanel.h index 5a6e3ae7..b6897524 100644 --- a/src/editor/dock-spaces/console/ConsolePanel.h +++ b/src/editor/dock-spaces/console/ConsolePanel.h @@ -1,7 +1,7 @@ #ifndef CONSOLEPANEL_H #define CONSOLEPANEL_H #include "../docks/AbstractDockPanel.h" -#include "../../service/LogService.h" +#include "../../../common/LoggerUtil.h" #include "imgui.h" namespace Metal { diff --git a/src/editor/dock-spaces/docks/DockSpacePanel.cpp b/src/editor/dock-spaces/docks/DockSpacePanel.cpp index 8e998f1e..3c0b6cd2 100644 --- a/src/editor/dock-spaces/docks/DockSpacePanel.cpp +++ b/src/editor/dock-spaces/docks/DockSpacePanel.cpp @@ -8,7 +8,7 @@ #include "../../../common/Icons.h" #include "../../dto/DockDTO.h" #include "../../util/UIUtil.h" -#include "../../service/LogService.h" +#include "../../../common/LoggerUtil.h" namespace Metal { const ImVec2 DockSpacePanel::DEFAULT{-1.f, -1.f}; diff --git a/src/editor/dock-spaces/files/FilesPanel.cpp b/src/editor/dock-spaces/files/FilesPanel.cpp index 898b0afa..7f772d6c 100644 --- a/src/editor/dock-spaces/files/FilesPanel.cpp +++ b/src/editor/dock-spaces/files/FilesPanel.cpp @@ -10,13 +10,13 @@ #include "../../dto/FSEntry.h" #include "../../dto/SceneImportSettingsDTO.h" #include "FilesContext.h" -#include "../../util/FileDialogUtil.h" +#include "../../../common/FileDialogUtil.h" #include "FilePreviewPanel.h" #include "../../abstract/form/FormPanel.h" #include #include -#include "../../util/FilesUtil.h" +#include "../../../common/FilesUtil.h" namespace Metal { std::string FilesPanel::getActionLabel() { diff --git a/src/editor/dto/EntryMetadata.h b/src/editor/dto/EntryMetadata.h index bfb9a00c..72b99a55 100644 --- a/src/editor/dto/EntryMetadata.h +++ b/src/editor/dto/EntryMetadata.h @@ -4,10 +4,10 @@ #include #include "../util/Util.h" #include "../enum/EntryType.h" -#include "../../common//Serializable.h" +#include "../../common//ISerialize.h" namespace Metal { - struct EntryMetadata : Serializable { + struct EntryMetadata : ISerialize { protected: std::string id = Util::uuidV4(); diff --git a/src/editor/dto/SceneData.h b/src/editor/dto/SceneData.h index ef40380e..894b3f80 100644 --- a/src/editor/dto/SceneData.h +++ b/src/editor/dto/SceneData.h @@ -3,11 +3,11 @@ #include #include "SceneEntityData.h" -#include "../../common//Serializable.h" +#include "../../common//ISerialize.h" namespace Metal { - struct SceneData final : Serializable { + struct SceneData final : ISerialize { std::vector entities; std::string name; diff --git a/src/editor/dto/SceneEntityData.h b/src/editor/dto/SceneEntityData.h index 48dbf3e9..0fbda6e6 100644 --- a/src/editor/dto/SceneEntityData.h +++ b/src/editor/dto/SceneEntityData.h @@ -7,7 +7,7 @@ namespace Metal { - struct SceneEntityData final : Serializable { + struct SceneEntityData final : ISerialize { MetadataComponent entity; TransformComponent transform; std::optional primitive; diff --git a/src/editor/enum/EntryType.h b/src/editor/enum/EntryType.h index e291a601..ed82b7ea 100644 --- a/src/editor/enum/EntryType.h +++ b/src/editor/enum/EntryType.h @@ -3,7 +3,7 @@ #include #include -#include "../../../common/Icons.h" +#include "../../common/Icons.h" namespace Metal::EntryType { enum EntryType { diff --git a/src/editor/panel/FileImportModalPanel.cpp b/src/editor/panel/FileImportModalPanel.cpp index 46941806..15b233df 100644 --- a/src/editor/panel/FileImportModalPanel.cpp +++ b/src/editor/panel/FileImportModalPanel.cpp @@ -3,7 +3,7 @@ #include #include #include "../../ApplicationContext.h" -#include "../util/FilesUtil.h" +#include "../../common/FilesUtil.h" #include "../abstract/form/FormPanel.h" namespace Metal { diff --git a/src/editor/repository/DockRepository.cpp b/src/editor/repository/DockRepository.cpp deleted file mode 100644 index 560f31d7..00000000 --- a/src/editor/repository/DockRepository.cpp +++ /dev/null @@ -1,25 +0,0 @@ -#include "DockRepository.h" - -namespace Metal { - DockRepository::DockRepository() : AbstractRuntimeComponent() { - auto *rightT = new DockDTO{&DockSpace::WORLD}; - auto *leftTop = new DockDTO{&DockSpace::REPOSITORIES}; - auto *leftDown = new DockDTO{&DockSpace::INSPECTOR}; - auto *downLeft = new DockDTO{&DockSpace::CONSOLE}; - auto *downRight = new DockDTO{&DockSpace::FILES}; - - center.sizeRatioForNodeAtDir = 0.5f; - rightT->sizeRatioForNodeAtDir = 0.25f; - leftTop->sizeRatioForNodeAtDir = 0.2f; - leftDown->sizeRatioForNodeAtDir = 0.5f; - downLeft->sizeRatioForNodeAtDir = 0.25f; - downRight->sizeRatioForNodeAtDir = 0.5f; - - right.push_back(rightT); - left.push_back(leftTop); - left.push_back(leftDown); - - bottom.push_back(downLeft); - bottom.push_back(downRight); - } -} // Metal diff --git a/src/editor/repository/DockRepository.h b/src/editor/repository/DockRepository.h deleted file mode 100644 index 9fe872bd..00000000 --- a/src/editor/repository/DockRepository.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef METAL_ENGINE_DOCKREPOSITORY_H -#define METAL_ENGINE_DOCKREPOSITORY_H - -#include -#include "../dto/DockDTO.h" -#include "../../common/AbstractRuntimeComponent.h" - -namespace Metal { - struct DockRepository final : AbstractRuntimeComponent { - DockDTO center{&DockSpace::VIEWPORT}; - std::vector bottom; - std::vector left; - std::vector right; - - bool isInitialized = false; - - explicit DockRepository(); - }; -} // Metal - -#endif diff --git a/src/editor/repository/EditorRepository.h b/src/editor/repository/EditorRepository.h index ea30d277..f3133dac 100644 --- a/src/editor/repository/EditorRepository.h +++ b/src/editor/repository/EditorRepository.h @@ -9,15 +9,14 @@ #include "../dto/ShortcutDTO.h" #include "../enum/engine-definitions.h" #include "../enum/ShadingMode.h" -#include "../../common/Inspectable.h" -#include "../../common/Serializable.h" +#include "../../common/IRepository.h" namespace Metal { struct TransformComponent; struct FSEntry; struct ImportSettingsDTO; - struct EditorRepository final : Inspectable, Serializable { + struct EditorRepository final : IRepository { ImVec4 accent{}; ImU32 accentU32 = 0; diff --git a/src/editor/service/AsyncTaskService.cpp b/src/editor/service/AsyncTaskService.cpp index d2200a0d..eb03ec42 100644 --- a/src/editor/service/AsyncTaskService.cpp +++ b/src/editor/service/AsyncTaskService.cpp @@ -40,7 +40,7 @@ namespace Metal { return !tasks.empty(); } - void AsyncTaskService::endAll() { + void AsyncTaskService::dispose() { for (std::shared_ptr &task: tasksArray) { endTask(task->id, true); } diff --git a/src/editor/service/AsyncTaskService.h b/src/editor/service/AsyncTaskService.h index 71a16e40..5ca1a64d 100644 --- a/src/editor/service/AsyncTaskService.h +++ b/src/editor/service/AsyncTaskService.h @@ -5,10 +5,13 @@ #include #include #include + +#include "../../common/IDisposable.h" +#include "../../common/IService.h" #include "../dto/AsyncTask.h" namespace Metal { - class AsyncTaskService { + class AsyncTaskService final : public IService, IDisposable{ std::unordered_map > tasks; std::vector > tasksArray; mutable std::mutex tasksMutex; @@ -22,7 +25,7 @@ namespace Metal { bool hasActiveTasks(); - void endAll(); + void dispose() override; }; } diff --git a/src/editor/service/DockService.cpp b/src/editor/service/DockService.cpp index c231964f..2a5b821f 100644 --- a/src/editor/service/DockService.cpp +++ b/src/editor/service/DockService.cpp @@ -8,6 +8,28 @@ #include "../../ApplicationContext.h" namespace Metal { + DockService::DockService() { + auto *rightT = new DockDTO{&DockSpace::WORLD}; + auto *leftTop = new DockDTO{&DockSpace::REPOSITORIES}; + auto *leftDown = new DockDTO{&DockSpace::INSPECTOR}; + auto *downLeft = new DockDTO{&DockSpace::CONSOLE}; + auto *downRight = new DockDTO{&DockSpace::FILES}; + + center.sizeRatioForNodeAtDir = 0.5f; + rightT->sizeRatioForNodeAtDir = 0.25f; + leftTop->sizeRatioForNodeAtDir = 0.2f; + leftDown->sizeRatioForNodeAtDir = 0.5f; + downLeft->sizeRatioForNodeAtDir = 0.25f; + downRight->sizeRatioForNodeAtDir = 0.5f; + + right.push_back(rightT); + left.push_back(leftTop); + left.push_back(leftDown); + + bottom.push_back(downLeft); + bottom.push_back(downRight); + } + void DockService::buildViews(ImGuiID windowId, AbstractPanel *panel) const { if (ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_DockingEnable) { if (dockRepository.isInitialized) { diff --git a/src/editor/service/DockService.h b/src/editor/service/DockService.h index 2c5fbf40..8fca6f13 100644 --- a/src/editor/service/DockService.h +++ b/src/editor/service/DockService.h @@ -4,17 +4,21 @@ #include "imgui.h" #include "../dto/DockDTO.h" #include "../dock-spaces/docks/DockSpacePanel.h" -#include "../../common/AbstractRuntimeComponent.h" +#include "../../common/IService.h" namespace Metal { class AbstractPanel; - class DockService final : public AbstractRuntimeComponent { - DockRepository &dockRepository; + class DockService final : public IService { + DockDTO center{&DockSpace::VIEWPORT}; + std::vector bottom; + std::vector left; + std::vector right; + + + bool isInitialized = false; public: - explicit DockService(DockRepository &dockRepository) - : AbstractRuntimeComponent(), dockRepository(dockRepository) { - } + explicit DockService(); void buildViews(ImGuiID windowId, AbstractPanel *panel) const; diff --git a/src/editor/service/FileImporterService.cpp b/src/editor/service/FileImporterService.cpp index 2131cd1f..55c3d6cd 100644 --- a/src/editor/service/FileImporterService.cpp +++ b/src/editor/service/FileImporterService.cpp @@ -4,7 +4,7 @@ #include "VoxelImporterService.h" #include "NotificationService.h" #include "AsyncTaskService.h" -#include "LogService.h" +#include "../../common/LoggerUtil.h" #include #include @@ -17,27 +17,27 @@ namespace Metal { [this, targetDir, file, fileName, settings](const std::stop_token &token) { try { LOG_INFO("Starting file processing: " + fileName); - if (sceneImporterService.isCompatible(file)) { - sceneImporterService.importData(targetDir, + if (sceneImporterService->isCompatible(file)) { + sceneImporterService->importData(targetDir, file, settings, token); - } else if (textureImporterService.isCompatible(file)) { - textureImporterService.importData(targetDir, file, settings, token); - } else if (voxelImporterService.isCompatible(file)) { - voxelImporterService.importData(targetDir, file, settings, token); + } else if (textureImporterService->isCompatible(file)) { + textureImporterService->importData(targetDir, file, settings, token); + } else if (voxelImporterService->isCompatible(file)) { + voxelImporterService->importData(targetDir, file, settings, token); } LOG_INFO("Successfully imported file: " + fileName); - notificationService.pushMessage("Successfully imported file: " + fileName, + notificationService->pushMessage("Successfully imported file: " + fileName, NotificationSeverities::SUCCESS); } catch (std::exception &e) { - notificationService.pushMessage(e.what(), NotificationSeverities::ERROR); + notificationService->pushMessage(e.what(), NotificationSeverities::ERROR); } }); } std::string FileImporterService::runAsync(const std::string &taskName, const LoadingTask &task) const { std::stop_source stopSource; - std::string taskId = asyncTaskService.registerTask(taskName, [stopSource]() mutable { + std::string taskId = asyncTaskService->registerTask(taskName, [stopSource]() mutable { stopSource.request_stop(); }); @@ -49,7 +49,7 @@ namespace Metal { } catch (...) { LOG_ERROR("Loading task failed with unknown error."); } - asyncTaskService.endTask(taskId, stopToken.stop_requested()); + asyncTaskService->endTask(taskId, stopToken.stop_requested()); }).detach(); return taskId; @@ -57,13 +57,13 @@ namespace Metal { std::string FileImporterService::collectCompatibleFiles() const { std::string outStr = ""; - for (std::string type: sceneImporterService.getSupportedTypes()) { + for (std::string type: sceneImporterService->getSupportedTypes()) { outStr += type + ","; }; - for (std::string type: textureImporterService.getSupportedTypes()) { + for (std::string type: textureImporterService->getSupportedTypes()) { outStr += type + ","; }; - for (std::string type: voxelImporterService.getSupportedTypes()) { + for (std::string type: voxelImporterService->getSupportedTypes()) { outStr += type + ","; }; return outStr; diff --git a/src/editor/service/FileImporterService.h b/src/editor/service/FileImporterService.h index 86b1227b..411c617a 100644 --- a/src/editor/service/FileImporterService.h +++ b/src/editor/service/FileImporterService.h @@ -6,7 +6,7 @@ #include #include "../dto/ImportSettingsDTO.h" -#include "../../common/AbstractRuntimeComponent.h" +#include "../../common/IService.h" namespace Metal { class SceneImporterService; @@ -15,24 +15,22 @@ namespace Metal { class NotificationService; class AsyncTaskService; - class FileImporterService final : public AbstractRuntimeComponent { - SceneImporterService &sceneImporterService; - TextureImporterService &textureImporterService; - VoxelImporterService &voxelImporterService; - NotificationService ¬ificationService; - AsyncTaskService &asyncTaskService; + class FileImporterService final : public IService { + SceneImporterService *sceneImporterService = nullptr; + TextureImporterService *textureImporterService = nullptr; + VoxelImporterService *voxelImporterService = nullptr; + NotificationService *notificationService = nullptr; + AsyncTaskService *asyncTaskService = nullptr; public: - FileImporterService(SceneImporterService &sceneImporterService, - TextureImporterService &textureImporterService, - VoxelImporterService &voxelImporterService, - NotificationService ¬ificationService, - AsyncTaskService &asyncTaskService) - : sceneImporterService(sceneImporterService), - textureImporterService(textureImporterService), - voxelImporterService(voxelImporterService), - notificationService(notificationService), - asyncTaskService(asyncTaskService) { + std::vector getDependencies() override { + return { + {"SceneImporterService", sceneImporterService}, + {"TextureImporterService", textureImporterService}, + {"VoxelImporterService", voxelImporterService}, + {"NotificationService", notificationService}, + {"AsyncTaskService", asyncTaskService} + }; } using LoadingTask = std::function; diff --git a/src/editor/service/FilesService.cpp b/src/editor/service/FilesService.cpp index 90e59a05..78bc1b36 100644 --- a/src/editor/service/FilesService.cpp +++ b/src/editor/service/FilesService.cpp @@ -3,8 +3,8 @@ #include "../dto/FSEntry.h" #include "../enum/EntryType.h" #include "../enum/engine-definitions.h" -#include "../util/FilesUtil.h" -#include "LogService.h" +#include "../../common/FilesUtil.h" +#include "../../common/LoggerUtil.h" #include #include #include @@ -162,4 +162,5 @@ namespace Metal { } } } + } // Metal diff --git a/src/editor/service/FilesService.h b/src/editor/service/FilesService.h index 62fe176d..3ecca1a4 100644 --- a/src/editor/service/FilesService.h +++ b/src/editor/service/FilesService.h @@ -4,24 +4,26 @@ #include #include -#include "../../common/AbstractRuntimeComponent.h" +#include "../../common/IInit.h" +#include "../../common/IService.h" namespace Metal { + struct DirectoryService; struct FSEntry; class NotificationService; - class FilesService final : public AbstractRuntimeComponent { + class FilesService final : public IService, public IInit { FSEntry *root = nullptr; - std::string &rootDirectory; - NotificationService ¬ificationService; + DirectoryService *directoryService = nullptr; + NotificationService *notificationService = nullptr; public: - explicit FilesService(std::string &rootDirectory, NotificationService ¬ificationService) - : AbstractRuntimeComponent(), rootDirectory(rootDirectory), notificationService(notificationService) { + std::vector getDependencies() override { + return {{"DirectoryService", directoryService}, {"NotificationService", notificationService}}; } - FSEntry *getRoot() { + FSEntry *getRoot() const { return root; } diff --git a/src/editor/service/MaterialImporterService.cpp b/src/editor/service/MaterialImporterService.cpp index dbe18d97..6aa6009c 100644 --- a/src/editor/service/MaterialImporterService.cpp +++ b/src/editor/service/MaterialImporterService.cpp @@ -1,6 +1,6 @@ #include "MaterialImporterService.h" #include "TextureImporterService.h" -#include "LogService.h" +#include "../../common/LoggerUtil.h" #include "../enum/engine-definitions.h" #include "../../engine/dto/PrimitiveComponent.h" #include @@ -22,7 +22,7 @@ namespace Metal { try { const unsigned int embeddedIndex = static_cast(std::stoul(p.substr(1))); if (scene && embeddedIndex < scene->mNumTextures) { - return textureImporterService.importEmbeddedTexture( + return textureImporterService->importEmbeddedTexture( targetDir, scene->mTextures[embeddedIndex], nameHint); } } catch (std::exception &e) { @@ -38,7 +38,7 @@ namespace Metal { } resolved = resolved.lexically_normal(); try { - return textureImporterService.importData(targetDir, resolved.string(), nullptr, stopToken); + return textureImporterService->importData(targetDir, resolved.string(), nullptr, stopToken); } catch (std::exception &e) { LOG_ERROR("Failed to import texture " + resolved.string() + ": " + e.what()); return ""; diff --git a/src/editor/service/MaterialImporterService.h b/src/editor/service/MaterialImporterService.h index 21f5a876..cbe42008 100644 --- a/src/editor/service/MaterialImporterService.h +++ b/src/editor/service/MaterialImporterService.h @@ -2,24 +2,24 @@ #define MATERIALIMPORTERSERVICE_H #include -#include #include #include -#include "../../common/AbstractResourceService.h" +#include "../../common/IService.h" namespace Metal { struct PrimitiveComponent; class TextureImporterService; - class MaterialImporterService final : public AbstractRuntimeComponent { - TextureImporterService &textureImporterService; - std::string &rootDirectory; + class MaterialImporterService final : public IService { + TextureImporterService *textureImporterService = nullptr; public: - MaterialImporterService(TextureImporterService &textureImporterService, std::string &rootDirectory) - : textureImporterService(textureImporterService), rootDirectory(rootDirectory) { + std::vector getDependencies() override { + return { + {"TextureImporterService", textureImporterService} + }; } void importMaterial(const std::string &targetDir, const aiMaterial *material, const aiScene *scene, diff --git a/src/editor/service/MeshImporterService.cpp b/src/editor/service/MeshImporterService.cpp index 6035b5a9..4a500d42 100644 --- a/src/editor/service/MeshImporterService.cpp +++ b/src/editor/service/MeshImporterService.cpp @@ -1,10 +1,11 @@ #include "MeshImporterService.h" -#include "LogService.h" +#include "../../core/DirectoryService.h" +#include "../../common/LoggerUtil.h" #include "../../engine/dto/MeshData.h" #include "../../engine/dto/VertexData.h" #include "../dto/EntryMetadata.h" #include "../enum/engine-definitions.h" -#include "../util/FilesUtil.h" +#include "../../common/FilesUtil.h" #include #include "../../common/serialization-definitions.h" @@ -17,7 +18,7 @@ namespace Metal { metadata.name = metadata.name.substr(0, metadata.name.find_last_of('.')); } - std::string lod0Path = rootDirectory + "/assets/" + FORMAT_FILE_MESH(metadata.getId()); + std::string lod0Path = directoryService->getAssetDirectory() + FORMAT_FILE_MESH(metadata.getId()); { std::ofstream output(lod0Path, std::ios::binary); cereal::BinaryOutputArchive archive(output); diff --git a/src/editor/service/MeshImporterService.h b/src/editor/service/MeshImporterService.h index 82bea5e6..360be3a5 100644 --- a/src/editor/service/MeshImporterService.h +++ b/src/editor/service/MeshImporterService.h @@ -1,7 +1,7 @@ #ifndef MESHIMPORTERSERVICE_H #define MESHIMPORTERSERVICE_H -#include "../../common/AbstractResourceService.h" +#include "../../common/IService.h" #include #include #include @@ -15,12 +15,14 @@ namespace Metal { }; struct MeshData; - class MeshImporterService final : public AbstractRuntimeComponent { - std::string &rootDirectory; + class MeshImporterService final : public IService { + DirectoryService *directoryService = nullptr; public: - explicit MeshImporterService(std::string &rootDirectory) - : rootDirectory(rootDirectory) { + std::vector getDependencies() override { + return { + {"DirectoryService", directoryService} + }; } void persistAllMeshes(const std::string &targetDir, const aiScene *scene, diff --git a/src/editor/service/NotificationService.h b/src/editor/service/NotificationService.h index 050b4183..f76ebba9 100644 --- a/src/editor/service/NotificationService.h +++ b/src/editor/service/NotificationService.h @@ -3,6 +3,7 @@ #include #include #include "../enum/NotificationSeverity.h" +#include "../../common/IService.h" #define MAX_notifications 4 #define MESSAGE_DURATION 3000 @@ -10,7 +11,7 @@ namespace Metal { struct Notification; - class NotificationService { + class NotificationService : public IService { std::array notifications{}; public: diff --git a/src/editor/service/PickingService.cpp b/src/editor/service/PickingService.cpp index 34c7c4ee..1d1495df 100644 --- a/src/editor/service/PickingService.cpp +++ b/src/editor/service/PickingService.cpp @@ -6,17 +6,19 @@ #include "../../core/vulkan/VulkanContext.h" #include "../../engine/service/BufferService.h" #include "../../engine/repository/WorldRepository.h" +#include "../../engine/dto/PrimitiveComponent.h" +#include "../../engine/dto/TransformComponent.h" namespace Metal { std::optional PickingService::pickEntityFromGBuffer(TextureInstance *attachment, const uint32_t pixelX, const uint32_t pixelY) const { constexpr VkDeviceSize imageSize = 4 * sizeof(float); - auto stagingBuffer = bufferService.createBuffer("stagingBuffer", imageSize, VK_BUFFER_USAGE_TRANSFER_DST_BIT, + auto stagingBuffer = bufferService->createBuffer("stagingBuffer", imageSize, VK_BUFFER_USAGE_TRANSFER_DST_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT); - VkCommandBuffer commandBuffer = vulkanContext.beginSingleTimeCommands(); + VkCommandBuffer commandBuffer = vulkanContext->beginSingleTimeCommands(); VkImageMemoryBarrier barrier = {}; barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; @@ -38,8 +40,8 @@ namespace Metal { region.bufferImageHeight = 0; region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; region.imageSubresource.mipLevel = 0; - region.baseArrayLayer = 0; - region.layerCount = 1; + region.imageSubresource.baseArrayLayer = 0; + region.imageSubresource.layerCount = 1; region.imageOffset = {static_cast(pixelX), static_cast(pixelY), 0}; region.imageExtent = {1, 1, 1}; @@ -54,14 +56,14 @@ namespace Metal { vkCmdPipelineBarrier(commandBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 1, &barrier); - vulkanContext.endSingleTimeCommands(commandBuffer); + vulkanContext->endSingleTimeCommands(commandBuffer); void *data = nullptr; - vkMapMemory(vulkanContext.device.device, stagingBuffer->vkDeviceMemory, 0, imageSize, 0, &data); + vkMapMemory(vulkanContext->device.device, stagingBuffer->vkDeviceMemory, 0, imageSize, 0, &data); const auto *pixel = static_cast(data); const float idValue = pixel[3]; // Render index is in the A channel (index 3) - vkUnmapMemory(vulkanContext.device.device, stagingBuffer->vkDeviceMemory); - bufferService.dispose("stagingBuffer"); + vkUnmapMemory(vulkanContext->device.device, stagingBuffer->vkDeviceMemory); + bufferService->dispose("stagingBuffer"); if (idValue <= 0.0f) { return std::nullopt; @@ -69,9 +71,10 @@ namespace Metal { const unsigned int renderIndex = static_cast(idValue + 0.5f) - 1; - auto view = worldRepository.registry.view(); + auto ®istry = worldRepository->registry; + auto view = registry.view(); for (auto entity: view) { - auto &mesh = view.get(entity); + auto &mesh = registry.get(entity); if (mesh.renderIndex == renderIndex) { return entity; } diff --git a/src/editor/service/PickingService.h b/src/editor/service/PickingService.h index 88127897..a51b8167 100644 --- a/src/editor/service/PickingService.h +++ b/src/editor/service/PickingService.h @@ -1,7 +1,7 @@ #ifndef PICKINGSERVICE_H #define PICKINGSERVICE_H -#include "../../common/AbstractResourceService.h" +#include "../../common/IService.h" #include "../enum/engine-definitions.h" #include @@ -11,15 +11,19 @@ namespace Metal { class BufferService; struct WorldRepository; - class PickingService final : public AbstractRuntimeComponent { - VulkanContext &vulkanContext; - BufferService &bufferService; - WorldRepository &worldRepository; + class PickingService final : public IService { + VulkanContext *vulkanContext = nullptr; + BufferService *bufferService = nullptr; + WorldRepository *worldRepository = nullptr; public: - PickingService(VulkanContext &vulkanContext, BufferService &bufferService, WorldRepository &worldRepository) - : vulkanContext(vulkanContext), bufferService(bufferService), worldRepository(worldRepository) {} - PickingService() = delete; + std::vector getDependencies() override { + return { + {"VulkanContext", vulkanContext}, + {"BufferService", bufferService}, + {"WorldRepository", worldRepository} + }; + } [[nodiscard]] std::optional pickEntityFromGBuffer(TextureInstance *attachment, uint32_t pixelX, uint32_t pixelY) const; }; diff --git a/src/editor/service/SceneImporterService.cpp b/src/editor/service/SceneImporterService.cpp index 70ef75a7..86ac3a29 100644 --- a/src/editor/service/SceneImporterService.cpp +++ b/src/editor/service/SceneImporterService.cpp @@ -1,7 +1,7 @@ #include "SceneImporterService.h" #include "MeshImporterService.h" #include "MaterialImporterService.h" -#include "LogService.h" +#include "../../common/LoggerUtil.h" #include "../dto/FSEntry.h" #include "../../engine/dto/MeshData.h" #include "../dto/SceneData.h" @@ -10,10 +10,11 @@ #include #include #include -#include "../util/FilesUtil.h" +#include "../../common/FilesUtil.h" #include "../dto/EntryMetadata.h" #include "../enum/engine-definitions.h" #include "../../common/serialization-definitions.h" +#include "../../core/DirectoryService.h" #include "../dto/SceneImportSettingsDTO.h" namespace Metal { @@ -50,7 +51,7 @@ namespace Metal { sceneMetadata.name = sceneData.name = scene->mName.length > 0 ? scene->mName.data : scene->mRootNode->mName.data; - std::string sceneBlobPath = rootDirectory + "/assets/" + FORMAT_FILE_SCENE(sceneMetadata.getId()); + std::string sceneBlobPath = directoryService->getAssetDirectory() + FORMAT_FILE_SCENE(sceneMetadata.getId()); std::unordered_map meshMap{}; diff --git a/src/editor/service/SceneImporterService.h b/src/editor/service/SceneImporterService.h index d70496e7..997d76bc 100644 --- a/src/editor/service/SceneImporterService.h +++ b/src/editor/service/SceneImporterService.h @@ -8,6 +8,7 @@ #include namespace Metal { + struct DirectoryService; struct MeshId; struct MaterialData; struct MeshData; @@ -17,17 +18,17 @@ namespace Metal { class MaterialImporterService; class SceneImporterService final : public AbstractImporter { - MeshImporterService &meshImporterService; - MaterialImporterService &materialImporterService; - std::string &rootDirectory; + MeshImporterService *meshImporterService = nullptr; + MaterialImporterService *materialImporterService = nullptr; + DirectoryService *directoryService = nullptr; public: - SceneImporterService(MeshImporterService &meshImporterService, - MaterialImporterService &materialImporterService, - std::string &rootDirectory) - : meshImporterService(meshImporterService), - materialImporterService(materialImporterService), - rootDirectory(rootDirectory) { + std::vector getDependencies() override { + return { + {"MeshImporterService", meshImporterService}, + {"MaterialImporterService", materialImporterService}, + {"DirectoryService", directoryService} + }; } std::string importData(const std::string &targetDir, const std::string &pathToFile, diff --git a/src/editor/service/SelectionService.cpp b/src/editor/service/SelectionService.cpp index 0105d673..de66ed82 100644 --- a/src/editor/service/SelectionService.cpp +++ b/src/editor/service/SelectionService.cpp @@ -5,42 +5,42 @@ namespace Metal { void SelectionService::addSelected(entt::entity entity) const { - if (editorRepository.selected.empty() || entity == EMPTY_ENTITY) { - editorRepository.mainSelection = entity; - if (editorRepository.mainSelection != EMPTY_ENTITY) { + if (editorRepository->selected.empty() || entity == EMPTY_ENTITY) { + editorRepository->mainSelection = entity; + if (editorRepository->mainSelection != EMPTY_ENTITY) { updatePrimitiveSelected(); } } if (entity != EMPTY_ENTITY) { - editorRepository.selected.insert({entity, true}); + editorRepository->selected.insert({entity, true}); } } void SelectionService::clearSelection() const { - editorRepository.selected.clear(); - editorRepository.mainSelection = EMPTY_ENTITY; - editorRepository.primitiveSelected = nullptr; + editorRepository->selected.clear(); + editorRepository->mainSelection = EMPTY_ENTITY; + editorRepository->primitiveSelected = nullptr; } void SelectionService::addAllSelected(const std::vector &all) const { - editorRepository.selected.clear(); + editorRepository->selected.clear(); const entt::entity first = all.size() > 0 ? all[0] : EMPTY_ENTITY; - editorRepository.mainSelection = first; + editorRepository->mainSelection = first; updatePrimitiveSelected(); for (auto a: all) { - editorRepository.selected.insert({a, true}); + editorRepository->selected.insert({a, true}); } } void SelectionService::updatePrimitiveSelected() const { - const auto entityId = editorRepository.mainSelection; + const auto entityId = editorRepository->mainSelection; - if (entityId == EMPTY_ENTITY || !worldRepository.registry.valid(entityId)) { + if (entityId == EMPTY_ENTITY || !worldRepository->registry.valid(entityId)) { return; } - if (worldRepository.registry.all_of(entityId)) { - editorRepository.primitiveSelected = &worldRepository.registry.get(entityId); + if (worldRepository->registry.all_of(entityId)) { + editorRepository->primitiveSelected = &worldRepository->registry.get(entityId); } } diff --git a/src/editor/service/SelectionService.h b/src/editor/service/SelectionService.h index 8916fa72..27562703 100644 --- a/src/editor/service/SelectionService.h +++ b/src/editor/service/SelectionService.h @@ -2,20 +2,23 @@ #define SELECTIONSERVICE_H #include -#include "../../common/AbstractRuntimeComponent.h" +#include "../../common/IService.h" #include "../enum/engine-definitions.h" namespace Metal { struct WorldRepository; struct EditorRepository; - class SelectionService final : public AbstractRuntimeComponent { - EditorRepository &editorRepository; - WorldRepository &worldRepository; + class SelectionService final : public IService { + EditorRepository *editorRepository = nullptr; + WorldRepository *worldRepository = nullptr; public: - SelectionService(EditorRepository &editorRepository, WorldRepository &worldRepository) - : editorRepository(editorRepository), worldRepository(worldRepository) { + std::vector getDependencies() override { + return { + {"EditorRepository", editorRepository}, + {"WorldRepository", worldRepository} + }; } void addSelected(entt::entity entity) const; diff --git a/src/editor/service/TextureImporterService.cpp b/src/editor/service/TextureImporterService.cpp index 2b5cb11d..0c6b7009 100644 --- a/src/editor/service/TextureImporterService.cpp +++ b/src/editor/service/TextureImporterService.cpp @@ -1,5 +1,7 @@ #include "TextureImporterService.h" -#include "LogService.h" +#include "../../core/DirectoryService.h" +#include "../../common/LoggerUtil.h" +#include "../enum/engine-definitions.h" #include "../../../../dependencies/stb/stb_image.h" #include "../../../../dependencies/stb/stb_image_write.h" @@ -9,7 +11,7 @@ #include "../dto/EntryMetadata.h" #include "../enum/EntryType.h" -#include "../util/FilesUtil.h" +#include "../../common/FilesUtil.h" #include "../../engine/dto/TextureData.h" namespace fs = std::filesystem; @@ -103,7 +105,7 @@ namespace Metal { size_t TextureImporterService::saveImage(const std::string &fileId, const TextureData &textureData) const { - std::string texturePath = rootDirectory + "/assets/" + FORMAT_FILE_TEXTURE(fileId); + std::string texturePath = directoryService->getAssetDirectory() + FORMAT_FILE_TEXTURE(fileId); if (!stbi_write_png(texturePath.c_str(), textureData.width, textureData.height, textureData.channels, textureData.data, textureData.width * textureData.channels)) { diff --git a/src/editor/service/TextureImporterService.h b/src/editor/service/TextureImporterService.h index d00446b9..59b56317 100644 --- a/src/editor/service/TextureImporterService.h +++ b/src/editor/service/TextureImporterService.h @@ -5,14 +5,17 @@ struct aiTexture; namespace Metal { + class DirectoryService; struct TextureData; class TextureImporterService final : public AbstractImporter { - std::string &rootDirectory; + DirectoryService *directoryService = nullptr; public: - explicit TextureImporterService(std::string &rootDirectory) - : AbstractImporter(), rootDirectory(rootDirectory) { + std::vector getDependencies() override { + return { + {"DirectoryService", directoryService} + }; } std::vector getSupportedTypes() override { diff --git a/src/editor/service/ThemeService.h b/src/editor/service/ThemeService.h index 94310fbe..4cc321d7 100644 --- a/src/editor/service/ThemeService.h +++ b/src/editor/service/ThemeService.h @@ -2,13 +2,14 @@ #define THEMESERVICE_H #include #include -#include "../../common/AbstractRuntimeComponent.h" +#include "../../common/IService.h" +#include "../../common/ISync.h" namespace Metal { struct EditorRepository; - class ThemeService final : public AbstractRuntimeComponent { - EditorRepository &editorRepository; + class ThemeService final : public IService, public ISync { + EditorRepository *editorRepository = nullptr; public: ImVec4 neutralPalette{}; ImVec4 palette0{}; @@ -23,15 +24,15 @@ namespace Metal { bool previousTheme = false; float prevLength = 0.0f; - explicit ThemeService(EditorRepository &editorRepository) - : AbstractRuntimeComponent(), editorRepository(editorRepository) { - } - void setDarkMode(); void setLightMode(); void onSync() override; + + std::vector getDependencies() override { + return {{"EditorRepository", editorRepository}}; + } }; } // Metal diff --git a/src/editor/service/VoxelImporterService.cpp b/src/editor/service/VoxelImporterService.cpp index 7d0563db..65d7546a 100644 --- a/src/editor/service/VoxelImporterService.cpp +++ b/src/editor/service/VoxelImporterService.cpp @@ -1,4 +1,5 @@ #include "VoxelImporterService.h" +#include "../../core/DirectoryService.h" #include #include "../../common/serialization-definitions.h" @@ -6,7 +7,7 @@ #include "../dto/EntryMetadata.h" #include "../enum/EntryType.h" #include "../enum/engine-definitions.h" -#include "LogService.h" +#include "../../common/LoggerUtil.h" #include #include #include @@ -28,7 +29,7 @@ namespace Metal { metadata.name = metadata.name.substr(0, metadata.name.find_last_of('.')); - std::string outPath = rootDirectory + "/assets/" + FORMAT_FILE_VOLUME(metadata.getId()); + std::string outPath = directoryService->getAssetDirectory() + FORMAT_FILE_VOLUME(metadata.getId()); metadata.size = convertToSVO(pathToFile, outPath, stopToken); DUMP_TEMPLATE(targetDir + '/' + FORMAT_FILE_METADATA(metadata.getId()), metadata) diff --git a/src/editor/service/VoxelImporterService.h b/src/editor/service/VoxelImporterService.h index fed4a639..781283b0 100644 --- a/src/editor/service/VoxelImporterService.h +++ b/src/editor/service/VoxelImporterService.h @@ -6,13 +6,17 @@ #include "../../engine/dto/SparseVoxelOctreeData.h" namespace Metal { + class DirectoryService; struct SVOInstance; class VoxelImporterService final : public AbstractImporter { - const std::string &rootDirectory; + DirectoryService *directoryService = nullptr; public: - explicit VoxelImporterService(const std::string &rootDirectory) : rootDirectory(rootDirectory) {} - VoxelImporterService() = delete; + std::vector getDependencies() override { + return { + {"DirectoryService", directoryService} + }; + } std::vector getSupportedTypes() override; diff --git a/src/engine/EngineContext.cpp b/src/engine/EngineContext.cpp index e97a104e..23dcd9d2 100644 --- a/src/engine/EngineContext.cpp +++ b/src/engine/EngineContext.cpp @@ -15,10 +15,7 @@ namespace Metal { void EngineContext::resetPathTracerAccumulationCount() const { - engineRepository.pathTracerAccumulationCount = 0; - } - - void EngineContext::onInitialize() { + engineRepository->pathTracerAccumulationCount = 0; } void EngineContext::updateCurrentTime() { @@ -36,20 +33,17 @@ namespace Metal { } void EngineContext::dispose() { - if (currentFrame != nullptr) { - currentFrame->dispose(); - } } void EngineContext::onSync() { updateCurrentTime(); - transformService.onSync(); - streamingService.onSync(); - rayTracingService.onSync(); - cameraService.onSync(); - lightService.onSync(); - volumeService.onSync(); + transformService->onSync(); + streamingService->onSync(); + rayTracingService->onSync(); + cameraService->onSync(); + lightService->onSync(); + volumeService->onSync(); for (auto *frame: registeredFrames) { if (frame->getShouldRender()) { @@ -66,7 +60,7 @@ namespace Metal { } void EngineContext::updateGlobalData() { - auto &camera = worldRepository.camera; + auto &camera = worldRepository->camera; globalDataUBO.previousProjView = globalDataUBO.projView; globalDataUBO.viewMatrix = camera.viewMatrix; globalDataUBO.projectionMatrix = camera.projectionMatrix; @@ -74,21 +68,21 @@ namespace Metal { globalDataUBO.invProj = camera.invProjectionMatrix; globalDataUBO.invView = camera.invViewMatrix; globalDataUBO.cameraWorldPosition = camera.position; - globalDataUBO.volumeCount = volumeService.getCount(); - globalDataUBO.lightsCount = lightService.getCount(); - globalDataUBO.debugFlag = ShadingModes::IndexOfValue(editorRepository.shadingMode); - engineRepository.pathTracerAccumulationCount++; - globalDataUBO.pathTracerAccumulationCount = engineRepository.pathTracerAccumulationCount; + globalDataUBO.volumeCount = volumeService->getCount(); + globalDataUBO.lightsCount = lightService->getCount(); + globalDataUBO.debugFlag = ShadingModes::IndexOfValue(editorRepository->shadingMode); + engineRepository->pathTracerAccumulationCount++; + globalDataUBO.pathTracerAccumulationCount = engineRepository->pathTracerAccumulationCount; globalDataUBO.globalFrameCount++; - globalDataUBO.pathTracerMaxSamples = engineRepository.pathTracerMaxSamples; - globalDataUBO.denoiserEnabled = engineRepository.denoiserEnabled && ( + globalDataUBO.pathTracerMaxSamples = engineRepository->pathTracerMaxSamples; + globalDataUBO.denoiserEnabled = engineRepository->denoiserEnabled && ( globalDataUBO.debugFlag == LIT || globalDataUBO.debugFlag == LIGHTING_ONLY) ? 1 : 0; - lightService.computeSunInfo(); - globalDataUBO.sunPosition = lightService.getSunPosition(); - globalDataUBO.sunColor = lightService.getSunColor(); + lightService->computeSunInfo(); + globalDataUBO.sunPosition = lightService->getSunPosition(); + globalDataUBO.sunColor = lightService->getSunColor(); currentFrame->getResourceAs(RID_GLOBAL_DATA)->update(&globalDataUBO); } } diff --git a/src/engine/EngineContext.h b/src/engine/EngineContext.h index 5f73f823..127953c8 100644 --- a/src/engine/EngineContext.h +++ b/src/engine/EngineContext.h @@ -6,8 +6,9 @@ #include #include "dto/GlobalDataUBO.h" -#include "../common/AbstractRuntimeComponent.h" -#include "dto/TileInfoUBO.h" +#include "../common/IService.h" +#include "../common/IDisposable.h" +#include "../common/ISync.h" using Clock = std::chrono::high_resolution_clock; using TimePoint = std::chrono::time_point; @@ -23,16 +24,16 @@ namespace Metal { struct EditorRepository; struct EngineRepository; - class EngineContext final : public AbstractRuntimeComponent { - TransformService &transformService; - StreamingService &streamingService; - RayTracingService &rayTracingService; - CameraService &cameraService; - LightService &lightService; - VolumeService &volumeService; - WorldRepository &worldRepository; - EditorRepository &editorRepository; - EngineRepository &engineRepository; + class EngineContext final : public IService, public ISync, public IDisposable { + TransformService *transformService = nullptr; + StreamingService *streamingService = nullptr; + RayTracingService *rayTracingService = nullptr; + CameraService *cameraService = nullptr; + LightService *lightService = nullptr; + VolumeService *volumeService = nullptr; + WorldRepository *worldRepository = nullptr; + EditorRepository *editorRepository = nullptr; + EngineRepository *engineRepository = nullptr; GlobalDataUBO globalDataUBO{}; long long start = -1; @@ -40,25 +41,20 @@ namespace Metal { bool giSettingsUpdated = true; public: - EngineContext(TransformService &transformService, - StreamingService &streamingService, - RayTracingService &rayTracingService, - CameraService &cameraService, - LightService &lightService, - VolumeService &volumeService, - WorldRepository &worldRepository, - EditorRepository &editorRepository, - EngineRepository &engineRepository) - : transformService(transformService), - streamingService(streamingService), - rayTracingService(rayTracingService), - cameraService(cameraService), - lightService(lightService), - volumeService(volumeService), - worldRepository(worldRepository), - editorRepository(editorRepository), - engineRepository(engineRepository) { + std::vector getDependencies() override { + return { + {"TransformService", transformService}, + {"StreamingService", streamingService}, + {"RayTracingService", rayTracingService}, + {"CameraService", cameraService}, + {"LightService", lightService}, + {"VolumeService", volumeService}, + {"WorldRepository", worldRepository}, + {"EditorRepository", editorRepository}, + {"EngineRepository", engineRepository} + }; } + GlobalDataUBO &getGlobalDataUBO() { return globalDataUBO; } void setCameraUpdated(const bool val) { @@ -79,8 +75,6 @@ namespace Metal { return giSettingsUpdated; } - void onInitialize() override; - void updateCurrentTime(); long long currentTimeMs = 0; @@ -90,6 +84,7 @@ namespace Metal { std::vector registeredFrames; EngineFrame *currentFrame = nullptr; + void updateGlobalData(); void registerFrame(EngineFrame *frame) { @@ -102,7 +97,7 @@ namespace Metal { void onSync() override; - void dispose(); + void dispose() override; }; } #endif diff --git a/src/engine/dto/BoundingBox.h b/src/engine/dto/BoundingBox.h index ec6de8bb..74fdbb0a 100644 --- a/src/engine/dto/BoundingBox.h +++ b/src/engine/dto/BoundingBox.h @@ -1,10 +1,10 @@ #ifndef BOUNDINGBOX_H #define BOUNDINGBOX_H #include -#include "../../common/Serializable.h" +#include "../../common/ISerialize.h" namespace Metal { - struct BoundingBox final : Serializable { + struct BoundingBox final : ISerialize { glm::vec3 min = glm::vec3(std::numeric_limits::max()); glm::vec3 max = glm::vec3(std::numeric_limits::lowest()); glm::vec3 center = glm::vec3(0.0f); diff --git a/src/engine/dto/Camera.h b/src/engine/dto/Camera.h index 70928a1c..ac38f427 100644 --- a/src/engine/dto/Camera.h +++ b/src/engine/dto/Camera.h @@ -7,11 +7,11 @@ #include #include "../../common/Inspectable.h" -#include "../../common/Serializable.h" +#include "../../common/ISerialize.h" namespace Metal { - struct Camera final : Inspectable, Serializable { + struct Camera final : Inspectable, ISerialize { float rotationSensitivity = 1; float movementSensitivity = 1.0f; float zoomSensitivity = 1.0f; diff --git a/src/engine/dto/MetadataComponent.h b/src/engine/dto/MetadataComponent.h index 59928072..14848c28 100644 --- a/src/engine/dto/MetadataComponent.h +++ b/src/engine/dto/MetadataComponent.h @@ -7,10 +7,10 @@ #include "../../editor/enum/engine-definitions.h" #include "../enum/ComponentType.h" #include "../../common/Inspectable.h" -#include "../../common/Serializable.h" +#include "../../common/ISerialize.h" namespace Metal { - struct MetadataComponent final : AbstractComponent, Serializable { + struct MetadataComponent final : AbstractComponent, ISerialize { std::string name = "New entity"; glm::vec3 color{1,1,1}; diff --git a/src/engine/dto/PrimitiveComponent.h b/src/engine/dto/PrimitiveComponent.h index 5b112d5c..3f6e80ef 100644 --- a/src/engine/dto/PrimitiveComponent.h +++ b/src/engine/dto/PrimitiveComponent.h @@ -2,11 +2,11 @@ #define PRIMITIVE_COMPONENT_H #include "AbstractComponent.h" -#include "../../common/Serializable.h" +#include "../../common/ISerialize.h" #include namespace Metal { - struct PrimitiveComponent final : AbstractComponent, Serializable { + struct PrimitiveComponent final : AbstractComponent, ISerialize { std::string meshId; std::string albedo; diff --git a/src/engine/dto/SparseVoxelOctreeData.h b/src/engine/dto/SparseVoxelOctreeData.h index 0c4f3be5..8799a44e 100644 --- a/src/engine/dto/SparseVoxelOctreeData.h +++ b/src/engine/dto/SparseVoxelOctreeData.h @@ -4,10 +4,10 @@ #include #include -#include "../../common/Serializable.h" +#include "../../common/ISerialize.h" namespace Metal { - struct SparseVoxelOctreeData final : Serializable { + struct SparseVoxelOctreeData final : ISerialize { std::vector data{}; unsigned int voxelBufferOffset; diff --git a/src/engine/dto/TileInfoUBO.h b/src/engine/dto/TileInfoUBO.h deleted file mode 100644 index f2dd1a80..00000000 --- a/src/engine/dto/TileInfoUBO.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef TILEINFOUBO_H -#define TILEINFOUBO_H -#include -#include - -namespace Metal { - struct TileInfoUBO final { - std::array tileCenterValid{}; - std::array voxelBufferOffset{}; - }; -} - -#endif //TILEINFOUBO_H diff --git a/src/engine/dto/TransformComponent.h b/src/engine/dto/TransformComponent.h index 78974590..b6b4ab0b 100644 --- a/src/engine/dto/TransformComponent.h +++ b/src/engine/dto/TransformComponent.h @@ -6,11 +6,11 @@ #include #include "AbstractComponent.h" -#include "../../common/Serializable.h" +#include "../../common/ISerialize.h" namespace Metal { - struct TransformComponent final : AbstractComponent, Serializable { + struct TransformComponent final : AbstractComponent, ISerialize { glm::mat4x4 model = glm::identity(); glm::vec3 translation{}; glm::vec3 rotationEuler = {0, 0, 0}; diff --git a/src/engine/dto/VolumeComponent.h b/src/engine/dto/VolumeComponent.h index c886278b..f77d5742 100644 --- a/src/engine/dto/VolumeComponent.h +++ b/src/engine/dto/VolumeComponent.h @@ -2,11 +2,11 @@ #define VOLUMECOMPONENT_H #include "AbstractComponent.h" -#include "../../common/Serializable.h" +#include "../../common/ISerialize.h" #include namespace Metal { - struct VolumeComponent final : AbstractComponent, Serializable { + struct VolumeComponent final : AbstractComponent, ISerialize { glm::vec3 albedo = glm::vec3(1.0f); float density = 1; float g = 0; diff --git a/src/engine/frame-builder/EngineFrameBuilder.cpp b/src/engine/frame-builder/EngineFrameBuilder.cpp index 4d8796db..e9295641 100644 --- a/src/engine/frame-builder/EngineFrameBuilder.cpp +++ b/src/engine/frame-builder/EngineFrameBuilder.cpp @@ -3,7 +3,6 @@ #include "structures/FramebufferBuilder.h" #include "structures/TextureBuilder.h" #include "structures/BufferBuilder.h" -#include "structures/PassBuilder.h" #include "structures/CommandBufferRecorderBuilder.h" #include "EngineFrame.h" #include "../../ApplicationContext.h" @@ -112,16 +111,9 @@ namespace Metal { std::unordered_map> > recorderToPasses; std::vector recorderOrder; - for (const auto &builder: builders) { - if (auto *passBuilder = dynamic_cast(builder.get())) { - const auto cbId = passBuilder->getCommandBufferId(); - if (std::ranges::find(recorderOrder, cbId) == recorderOrder.end()) { - recorderOrder.push_back(cbId); - } - } - } - for (auto &pass: passes) { + recorderOrder.push_back(pass.commandBufferId); + pass.pass->frame = frame.get(); pass.pass->onInitialize(); recorderToPasses[pass.commandBufferId].push_back(std::move(pass.pass)); diff --git a/src/engine/frame-builder/EngineFrameBuilder.h b/src/engine/frame-builder/EngineFrameBuilder.h index 63c58cf2..71ff3a60 100644 --- a/src/engine/frame-builder/EngineFrameBuilder.h +++ b/src/engine/frame-builder/EngineFrameBuilder.h @@ -8,7 +8,6 @@ #include #include "structures/ResourceBuilder.h" -#include "../enum/PassType.h" #include "../resource/BufferInstance.h" namespace Metal { diff --git a/src/engine/passes/AbstractPass.h b/src/engine/passes/AbstractPass.h index 8be0960e..be268269 100644 --- a/src/engine/passes/AbstractPass.h +++ b/src/engine/passes/AbstractPass.h @@ -3,7 +3,8 @@ #include #include #include -#include "../../common/AbstractRuntimeComponent.h" +#include "../../common/ISync.h" +#include "../../common/IInit.h" #include "../resource/RuntimeResource.h" namespace Metal { @@ -13,7 +14,7 @@ namespace Metal { class StreamingService; struct PipelineInstance; - class AbstractPass : public AbstractRuntimeComponent { + class AbstractPass : public ISync, public IInit { bool isComputePass; public: diff --git a/src/engine/repository/EngineRepository.h b/src/engine/repository/EngineRepository.h index fe2b81dc..77f3cab7 100644 --- a/src/engine/repository/EngineRepository.h +++ b/src/engine/repository/EngineRepository.h @@ -1,11 +1,11 @@ #ifndef ENGINEREPO_H #define ENGINEREPO_H -#include "../../common/Inspectable.h" #include -#include "../../common/Serializable.h" + +#include "../../common/IRepository.h" namespace Metal { - struct EngineRepository final : Inspectable, Serializable { + struct EngineRepository final : IRepository { bool vsync = true; bool denoiserEnabled = false; diff --git a/src/engine/repository/RuntimeRepository.h b/src/engine/repository/RuntimeRepository.h index 37215d86..f7c87003 100644 --- a/src/engine/repository/RuntimeRepository.h +++ b/src/engine/repository/RuntimeRepository.h @@ -3,8 +3,7 @@ #include namespace Metal { - struct RuntimeRepository { - + struct RuntimeRepository : IContextMember { bool isFocused; int displayW; int displayH; diff --git a/src/engine/repository/WorldRepository.cpp b/src/engine/repository/WorldRepository.cpp index 519cb1a5..eb2457d6 100644 --- a/src/engine/repository/WorldRepository.cpp +++ b/src/engine/repository/WorldRepository.cpp @@ -4,6 +4,7 @@ #include "../enum/ComponentType.h" #include "../../editor/dto/SceneData.h" #include "../../common/serialization-definitions.h" +#include "../../core/DirectoryService.h" namespace Metal { entt::entity WorldRepository::createEntity() { @@ -35,7 +36,7 @@ namespace Metal { registry.destroy(entityId); } - rayTracingService.markDirty(); + rayTracingService->markDirty(); } void WorldRepository::changeVisibility(entt::entity entity, bool isVisible) { @@ -45,12 +46,12 @@ namespace Metal { } else { hiddenEntities.insert({entity, true}); } - rayTracingService.markDirty(); + rayTracingService->markDirty(); } void WorldRepository::loadScene(const std::string &sceneId) { SceneData sceneData; - const auto pathToFile = rootDirectory + "/assets/" + FORMAT_FILE_SCENE(sceneId); + const auto pathToFile = directoryService->getAssetDirectory() + FORMAT_FILE_SCENE(sceneId); PARSE_TEMPLATE(sceneData, pathToFile) for (auto &entityData: sceneData.entities) { @@ -86,7 +87,7 @@ namespace Metal { } } - rayTracingService.markDirty(); + rayTracingService->markDirty(); } void WorldRepository::createComponent(const entt::entity entityId, ComponentType type) { diff --git a/src/engine/repository/WorldRepository.h b/src/engine/repository/WorldRepository.h index 0e261522..737df3dd 100644 --- a/src/engine/repository/WorldRepository.h +++ b/src/engine/repository/WorldRepository.h @@ -1,38 +1,35 @@ #ifndef WORLDREPOSITORY_H #define WORLDREPOSITORY_H -#include #include #include -#include -#include "../../common/AbstractRuntimeComponent.h" -#include "../../common/Serializable.h" -#include "../../editor/enum/engine-definitions.h" +#include "../../common/IRepository.h" #include "../dto/Camera.h" -#include "../dto/MetadataComponent.h" #include "../enum/ComponentType.h" -#include "../dto/TransformComponent.h" -#include "../dto/PrimitiveComponent.h" -#include "../dto/VolumeComponent.h" namespace Metal { + struct MetadataComponent; class Inspectable; class RayTracingService; + class DirectoryService; - struct WorldRepository final : AbstractRuntimeComponent, Serializable { - RayTracingService &rayTracingService; - std::string &rootDirectory; - - WorldRepository(RayTracingService &rayTracingService, std::string &rootDirectory) - : rayTracingService(rayTracingService), rootDirectory(rootDirectory) { - } + struct WorldRepository final : IRepository { + RayTracingService *rayTracingService; + DirectoryService *directoryService; Camera camera{-(glm::pi() / 4), glm::pi() / 4, {10, 10, 10}}; entt::registry registry{}; std::unordered_map culled{}; std::unordered_map hiddenEntities{}; + std::vector getDependencies() override { + return { + {"RayTracingService", rayTracingService}, + {"DirectoryService", directoryService} + }; + } + void createComponent(entt::entity entity, ComponentType type); entt::entity createEntity(); @@ -48,7 +45,6 @@ namespace Metal { nlohmann::json toJson() const override; void fromJson(const nlohmann::json &j) override; - }; } // Metal diff --git a/src/engine/service/BufferService.h b/src/engine/service/BufferService.h index 8b6b3632..4c77aa73 100644 --- a/src/engine/service/BufferService.h +++ b/src/engine/service/BufferService.h @@ -12,7 +12,7 @@ namespace Metal { class VulkanContext; class BufferService final : public AbstractResourceService { - VulkanContext &vulkanContext; + VulkanContext *vulkanContext = nullptr; void copyBuffer(const BufferInstance *srcBuffer, const BufferInstance *dstBuffer) const; @@ -21,8 +21,9 @@ namespace Metal { BufferInstance *buffer) const; public: - explicit BufferService(VulkanContext &vulkanContext) : vulkanContext(vulkanContext) {} - BufferService() = delete; + BufferService() = default; + + std::vector getDependencies() override; [[nodiscard]] unsigned int findMemoryType(unsigned int typeFilter, VkMemoryPropertyFlags properties) const; diff --git a/src/engine/service/CameraService.cpp b/src/engine/service/CameraService.cpp index 9391b3d7..37dff1aa 100644 --- a/src/engine/service/CameraService.cpp +++ b/src/engine/service/CameraService.cpp @@ -10,12 +10,12 @@ namespace Metal { // Per frame // TODO - EVENT SYSTEM void CameraService::onSync() { - camera = &worldRepository.camera; + camera = &worldRepository->camera; if (camera != nullptr) { updateAspectRatio(); if (camera->isNotFrozen()) { updateMatrices(); - engineContext.setCameraUpdated(true); + engineContext->setCameraUpdated(true); camera->freezeVersion(); } } @@ -23,7 +23,7 @@ namespace Metal { void CameraService::updateAspectRatio() const { const float prevAspect = camera->aspectRatio; - camera->aspectRatio = runtimeRepository.viewportW / runtimeRepository.viewportH; + camera->aspectRatio = runtimeRepository->viewportW / runtimeRepository->viewportH; if (prevAspect != camera->aspectRatio) { camera->registerChange(); } @@ -57,10 +57,6 @@ namespace Metal { camera->invProjectionMatrix = glm::inverse(camera->projectionMatrix); } - CameraService::CameraService(EngineContext &engineContext, WorldRepository &worldRepository, RuntimeRepository &runtimeRepository) - : engineContext(engineContext), worldRepository(worldRepository), runtimeRepository(runtimeRepository) { - } - void CameraService::handleInputInternal() const { glm::vec3 forward( -std::sin(camera->yaw) * std::cos(camera->pitch), @@ -76,16 +72,16 @@ namespace Metal { right = glm::normalize(right); const float multiplier = 10 * camera->movementSensitivity * - engineContext.deltaTime; - if (runtimeRepository.leftPressed) { + engineContext->deltaTime; + if (runtimeRepository->leftPressed) { camera->position += right * multiplier; camera->registerChange(); } - if (runtimeRepository.rightPressed) { + if (runtimeRepository->rightPressed) { camera->position -= right * multiplier; camera->registerChange(); } - if (runtimeRepository.backwardPressed) { + if (runtimeRepository->backwardPressed) { if (camera->isOrthographic) { camera->orthographicProjectionSize += multiplier; } else { @@ -93,7 +89,7 @@ namespace Metal { } camera->registerChange(); } - if (runtimeRepository.forwardPressed) { + if (runtimeRepository->forwardPressed) { if (camera->isOrthographic) { camera->orthographicProjectionSize -= multiplier; } else { @@ -118,8 +114,8 @@ namespace Metal { } void CameraService::updateDelta(const bool isFirstMovement) const { - const float mouseX = runtimeRepository.mouseX; - const float mouseY = runtimeRepository.mouseY; + const float mouseX = runtimeRepository->mouseX; + const float mouseY = runtimeRepository->mouseY; if (isFirstMovement) { camera->lastMouseX = mouseX; diff --git a/src/engine/service/CameraService.h b/src/engine/service/CameraService.h index 3109c51d..7e2fe9cb 100644 --- a/src/engine/service/CameraService.h +++ b/src/engine/service/CameraService.h @@ -1,10 +1,12 @@ #ifndef CAMERASYSTEM_H #define CAMERASYSTEM_H -#include "../../common/AbstractRuntimeComponent.h" +#include "../../common/ISync.h" #include #include +#include "../../common/IService.h" + constexpr float PI_OVER_2 = glm::pi() / 2.0f; constexpr float PI_2 = glm::pi() * 2.0f; constexpr float MIN_MAX_PITCH = glm::radians(89.0f); @@ -18,10 +20,10 @@ namespace Metal { struct RuntimeRepository; struct Camera; - class CameraService final : public AbstractRuntimeComponent { - EngineContext &engineContext; - WorldRepository &worldRepository; - RuntimeRepository &runtimeRepository; + class CameraService final : public IService, public ISync { + EngineContext *engineContext = nullptr; + WorldRepository *worldRepository = nullptr; + RuntimeRepository *runtimeRepository = nullptr; Camera *camera = nullptr; glm::vec3 xAxis{0.0f}; @@ -47,7 +49,13 @@ namespace Metal { public: void handleInput(bool isFirstMovement) const; - explicit CameraService(EngineContext &engineContext, WorldRepository &worldRepository, RuntimeRepository &runtimeRepository); + std::vector getDependencies() override { + return { + {"EngineContext", engineContext}, + {"WorldRepository", worldRepository}, + {"RuntimeRepository", runtimeRepository} + }; + } void onSync() override; }; diff --git a/src/engine/service/DescriptorSetService.cpp b/src/engine/service/DescriptorSetService.cpp index 3032fec6..71a8a55d 100644 --- a/src/engine/service/DescriptorSetService.cpp +++ b/src/engine/service/DescriptorSetService.cpp @@ -1,7 +1,7 @@ #include "DescriptorSetService.h" #include "../dto/PipelineBuilder.h" #include "../resource/BufferInstance.h" -#include "../../editor/service/LogService.h" +#include "../../common/LoggerUtil.h" #include "../../core/vulkan/VulkanContext.h" #include "FrameBufferService.h" #include "BufferService.h" @@ -12,10 +12,11 @@ #include "../../core/vulkan/VulkanUtils.h" namespace Metal { - DescriptorInstance *DescriptorSetService::createDescriptor(const PipelineBuilder &pipelineBuilder, const std::string &id, VkShaderStageFlags stageFlags) { + DescriptorInstance *DescriptorSetService::createDescriptor(const PipelineBuilder &pipelineBuilder, + const std::string &id, VkShaderStageFlags stageFlags) { auto *descriptorInstance = createResourceInstance(id); - for (auto &builder : pipelineBuilder.resourceBindings) { + for (auto &builder: pipelineBuilder.resourceBindings) { DescriptorBinding binding{}; binding.bindingPoint = builder.bindingPoint; binding.descriptorCount = builder.descriptorCount; @@ -36,7 +37,7 @@ namespace Metal { } binding.view = fbo->attachments[binding.attachmentIndex]->vkImageView; if (binding.sampler == VK_NULL_HANDLE) { - binding.sampler = vulkanContext.vkImageSampler; + binding.sampler = vulkanContext->vkImageSampler; } } @@ -45,7 +46,7 @@ namespace Metal { binding.descriptorType = VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR; break; case DescriptorBindingType::BUFFER: { - BufferInstance *buffer = bufferService.getResource(binding.bufferId); + BufferInstance *buffer = bufferService->getResource(binding.bufferId); if (buffer != nullptr) { binding.descriptorType = buffer->getBufferType() == BufferType::UNIFORM_BUFFER @@ -80,26 +81,27 @@ namespace Metal { void DescriptorSetService::disposeResource(DescriptorInstance *resource) { LOG_INFO("Disposing of descriptor set resource"); - vkDestroyDescriptorSetLayout(vulkanContext.device.device, resource->vkDescriptorSetLayout, nullptr); + vkDestroyDescriptorSetLayout(vulkanContext->device.device, resource->vkDescriptorSetLayout, nullptr); } std::vector DescriptorSetService::getAllDescriptors() const { std::vector descriptors; std::lock_guard lock(resourceMutex); - for (auto const& [id, descriptor] : resources) { + for (auto const &[id, descriptor]: resources) { descriptors.emplace_back(descriptor); } return descriptors; } void DescriptorSetService::setImageDescriptor(const FrameBufferInstance *framebuffer, - unsigned int attachmentIndex) { + unsigned int attachmentIndex) { auto attachment = framebuffer->attachments[attachmentIndex]; if (attachment->imageDescriptor == nullptr) { - attachment->imageDescriptor = createResourceInstance(framebuffer->getId() + std::to_string(attachmentIndex)); + attachment->imageDescriptor = + createResourceInstance(framebuffer->getId() + std::to_string(attachmentIndex)); attachment->imageDescriptor->bindings.push_back(DescriptorBinding::Of(VK_SHADER_STAGE_FRAGMENT_BIT, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 0, - vulkanContext.vkImageSampler, + vulkanContext->vkImageSampler, attachment->vkImageView)); updateDescriptor(attachment->imageDescriptor); } @@ -109,14 +111,15 @@ namespace Metal { if (texture->imageDescriptor == nullptr) { texture->imageDescriptor = createResourceInstance(texture->getId() + "_descriptor"); texture->imageDescriptor->bindings.push_back(DescriptorBinding::Of(VK_SHADER_STAGE_FRAGMENT_BIT, - VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, - 0, - texture->vkSampler, - texture->vkImageView + VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, + 0, + texture->vkSampler, + texture->vkImageView )); updateDescriptor(texture->imageDescriptor); } } + void DescriptorSetService::updateDescriptor(DescriptorInstance *descriptor) { if (descriptor->bindings.empty()) { throw std::runtime_error("No descriptor layout sets were created"); @@ -134,7 +137,8 @@ namespace Metal { samplerLayoutBinding.pImmutableSamplers = nullptr; if (binding.descriptorCount > 1) { - bindingFlags.push_back(VK_DESCRIPTOR_BINDING_PARTIALLY_BOUND_BIT | VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT); + bindingFlags.push_back( + VK_DESCRIPTOR_BINDING_PARTIALLY_BOUND_BIT | VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT); } else { bindingFlags.push_back(0); } @@ -153,31 +157,32 @@ namespace Metal { layoutInfo.flags = VK_DESCRIPTOR_SET_LAYOUT_CREATE_UPDATE_AFTER_BIND_POOL_BIT_EXT; layoutInfo.pNext = &flagsInfo; - VulkanUtils::CheckVKResult(vkCreateDescriptorSetLayout(vulkanContext.device.device, &layoutInfo, + VulkanUtils::CheckVKResult(vkCreateDescriptorSetLayout(vulkanContext->device.device, &layoutInfo, nullptr, &descriptor->vkDescriptorSetLayout)); VkDescriptorSetAllocateInfo allocInfo = {}; allocInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; - allocInfo.descriptorPool = vulkanContext.descriptorPool; // Created during setup + allocInfo.descriptorPool = vulkanContext->descriptorPool; // Created during setup allocInfo.descriptorSetCount = 1; allocInfo.pSetLayouts = &descriptor->vkDescriptorSetLayout; - VulkanUtils::CheckVKResult(vkAllocateDescriptorSets(vulkanContext.device.device, &allocInfo, &descriptor->vkDescriptorSet)); + VulkanUtils::CheckVKResult( + vkAllocateDescriptorSets(vulkanContext->device.device, &allocInfo, &descriptor->vkDescriptorSet)); // WRITE - Write(vulkanContext, bufferService, descriptor->vkDescriptorSet, descriptor->bindings); + Write(descriptor->vkDescriptorSet, descriptor->bindings); } void DescriptorSetService::write(DescriptorInstance *descriptor) { - Write(vulkanContext, bufferService, descriptor->vkDescriptorSet, descriptor->bindings); + Write(descriptor->vkDescriptorSet, descriptor->bindings); } - void DescriptorSetService::Write(VulkanContext &vulkanContext, BufferService &bufferService, const VkDescriptorSet &vkDescriptorSet, + void DescriptorSetService::Write(const VkDescriptorSet &vkDescriptorSet, const std::vector &bindings) { std::vector writeDescriptorSets; std::vector bufferInfos; - std::vector> imageInfosPool; + std::vector > imageInfosPool; std::vector asInfos; bufferInfos.reserve(bindings.size()); @@ -207,7 +212,7 @@ namespace Metal { writeDescriptorSets.push_back(descriptorWrite); } } else if (!binding.bufferId.empty()) { - BufferInstance *buffer = bufferService.getResource(binding.bufferId); + BufferInstance *buffer = bufferService->getResource(binding.bufferId); if (buffer == nullptr) { LOG_ERROR("DescriptorSetService Buffer not found: " + binding.bufferId); @@ -261,7 +266,7 @@ namespace Metal { if (writeDescriptorSets.empty()) return; - vkUpdateDescriptorSets(vulkanContext.device.device, + vkUpdateDescriptorSets(vulkanContext->device.device, static_cast(writeDescriptorSets.size()), writeDescriptorSets.data(), 0, diff --git a/src/engine/service/DescriptorSetService.h b/src/engine/service/DescriptorSetService.h index f5ebde4e..52e420fe 100644 --- a/src/engine/service/DescriptorSetService.h +++ b/src/engine/service/DescriptorSetService.h @@ -14,17 +14,23 @@ namespace Metal { class TextureService; class DescriptorSetService final : public AbstractResourceService { - VulkanContext &vulkanContext; - FrameBufferService &framebufferService; - BufferService &bufferService; - TextureService &textureService; + VulkanContext *vulkanContext = nullptr; + FrameBufferService *framebufferService = nullptr; + BufferService *bufferService = nullptr; + TextureService *textureService = nullptr; public: - DescriptorSetService(VulkanContext &vulkanContext, FrameBufferService &framebufferService, BufferService &bufferService, TextureService &textureService) - : vulkanContext(vulkanContext), framebufferService(framebufferService), bufferService(bufferService), textureService(textureService) {} - DescriptorSetService() = delete; - - DescriptorInstance *createDescriptor(const PipelineBuilder &pipelineBuilder, const std::string &id, VkShaderStageFlags stageFlags); + std::vector getDependencies() override { + return { + {"VulkanContext", vulkanContext}, + {"FrameBufferService", framebufferService}, + {"BufferService", bufferService}, + {"TextureService", textureService} + }; + } + + DescriptorInstance *createDescriptor(const PipelineBuilder &pipelineBuilder, const std::string &id, + VkShaderStageFlags stageFlags); void disposeResource(DescriptorInstance *resource) override; @@ -38,7 +44,7 @@ namespace Metal { void write(DescriptorInstance *descriptor); - static void Write(VulkanContext &vulkanContext, BufferService &bufferService, const VkDescriptorSet &vkDescriptorSet, const std::vector &bindings); + void Write(const VkDescriptorSet &vkDescriptorSet, const std::vector &bindings); }; } diff --git a/src/engine/service/FrameBufferService.h b/src/engine/service/FrameBufferService.h index 33694124..76676188 100644 --- a/src/engine/service/FrameBufferService.h +++ b/src/engine/service/FrameBufferService.h @@ -15,7 +15,7 @@ namespace Metal { class VulkanContext; class FrameBufferService final : public AbstractResourceService { - VulkanContext &vulkanContext; + VulkanContext *vulkanContext = nullptr; std::shared_ptr createAttachmentInternal(VkFormat format, VkImageUsageFlagBits usage, @@ -24,8 +24,9 @@ namespace Metal { void createVKFrameBuffer(FrameBufferInstance *framebuffer) const; public: - explicit FrameBufferService(VulkanContext &vulkanContext) : vulkanContext(vulkanContext) {} - FrameBufferService() = delete; + std::vector getDependencies() override { + return {{"VulkanContext", vulkanContext}}; + } FrameBufferInstance *createFrameBuffer(const std::string &id, unsigned int w, unsigned int h, glm::vec4 clearColor = glm::vec4(0.0f)); diff --git a/src/engine/service/LightService.cpp b/src/engine/service/LightService.cpp index 3f4ca266..de69de89 100644 --- a/src/engine/service/LightService.cpp +++ b/src/engine/service/LightService.cpp @@ -17,19 +17,18 @@ namespace Metal { registerLights(); if (!items.empty()) { - engineContext.currentFrame->getResourceAs(RID_LIGHT_BUFFER)->update(items.data()); + engineContext->currentFrame->getResourceAs(RID_LIGHT_BUFFER)->update(items.data()); } } void LightService::computeSunInfo() { sunPosition = glm::vec3(0, - std::cos(engineRepository.elapsedTime), - std::sin(engineRepository.elapsedTime)) * engineRepository - .sunDistance; + std::cos(engineRepository->elapsedTime), + std::sin(engineRepository->elapsedTime)) * engineRepository->sunDistance; sunColor = LightService::CalculateSunColor( - sunPosition.y / engineRepository.sunDistance, - engineRepository.nightColor, engineRepository.dawnColor, - engineRepository.middayColor); + sunPosition.y / engineRepository->sunDistance, + engineRepository->nightColor, engineRepository->dawnColor, + engineRepository->middayColor); } glm::vec3 LightService::CalculateSunColor(const float elevation, glm::vec3 &nightColor, glm::vec3 &dawnColor, diff --git a/src/engine/service/LightService.h b/src/engine/service/LightService.h index 905b53e0..3a5c7575 100644 --- a/src/engine/service/LightService.h +++ b/src/engine/service/LightService.h @@ -2,16 +2,17 @@ #define LIGHTSSERVICE_H #include -#include "../../common/AbstractRuntimeComponent.h" +#include "../../common/IService.h" +#include "../../common/ISync.h" #include "../dto/LightData.h" namespace Metal { class EngineContext; struct EngineRepository; - class LightService final : public AbstractRuntimeComponent { - EngineContext &engineContext; - EngineRepository &engineRepository; + class LightService final : public IService, public ISync{ + EngineContext *engineContext = nullptr; + EngineRepository *engineRepository = nullptr; std::vector items{}; glm::vec3 sunColor{}; @@ -25,9 +26,12 @@ namespace Metal { static glm::vec3 BlendColors(glm::vec3 &c1, glm::vec3 &c2, float t); public: - explicit LightService(EngineContext &engineContext, EngineRepository &engineRepository) - : engineContext(engineContext), engineRepository(engineRepository) {} - LightService() = delete; + std::vector getDependencies() override { + return { + {"EngineContext", engineContext}, + {"EngineRepository", engineRepository} + }; + } void onSync() override; diff --git a/src/engine/service/MaterialService.cpp b/src/engine/service/MaterialService.cpp index 4c41d172..ef66308c 100644 --- a/src/engine/service/MaterialService.cpp +++ b/src/engine/service/MaterialService.cpp @@ -6,6 +6,7 @@ #include "../dto/PrimitiveComponent.h" namespace Metal { + void MaterialService::load(MeshMetadata &materialData, PrimitiveComponent &data) { materialData.albedo = data.albedoColor; materialData.roughness = data.roughnessFactor; @@ -20,21 +21,21 @@ namespace Metal { materialData.metallicTextureId = 0; if (!data.albedo.empty()) { - auto *tex = textureService.stream(data.albedo); + auto *tex = textureService->stream(data.albedo); if (tex != nullptr) { - materialData.albedoTextureId = textureService.getTextureIndex(data.albedo); + materialData.albedoTextureId = textureService->getTextureIndex(data.albedo); } } if (!data.roughness.empty()) { - auto *tex = textureService.stream(data.roughness); + auto *tex = textureService->stream(data.roughness); if (tex != nullptr) { - materialData.roughnessTextureId = textureService.getTextureIndex(data.roughness); + materialData.roughnessTextureId = textureService->getTextureIndex(data.roughness); } } if (!data.metallic.empty()) { - auto *tex = textureService.stream(data.metallic); + auto *tex = textureService->stream(data.metallic); if (tex != nullptr) { - materialData.metallicTextureId = textureService.getTextureIndex(data.metallic); + materialData.metallicTextureId = textureService->getTextureIndex(data.metallic); } } } diff --git a/src/engine/service/MaterialService.h b/src/engine/service/MaterialService.h index 9c1668bc..660c48b8 100644 --- a/src/engine/service/MaterialService.h +++ b/src/engine/service/MaterialService.h @@ -1,16 +1,21 @@ #ifndef MATERIALSERVICE_H #define MATERIALSERVICE_H +#include "../../common/IService.h" namespace Metal { struct PrimitiveComponent; struct MeshMetadata; class TextureService; - class MaterialService final { - TextureService &textureService; + class MaterialService final : public IService { + TextureService *textureService = nullptr; + public: - explicit MaterialService(TextureService &textureService) : textureService(textureService) {} - MaterialService() = delete; + std::vector getDependencies() override { + return { + {"TextureService", textureService} + }; + } void load(MeshMetadata &data, PrimitiveComponent &component); }; diff --git a/src/engine/service/MeshService.cpp b/src/engine/service/MeshService.cpp index 2b9488ea..417887bf 100644 --- a/src/engine/service/MeshService.cpp +++ b/src/engine/service/MeshService.cpp @@ -4,7 +4,8 @@ #include "../../editor/dto/SceneData.h" #include "../../core/vulkan/VulkanContext.h" -#include "../../editor/util/FilesUtil.h" +#include "../../common/FilesUtil.h" +#include "../../core/DirectoryService.h" #include #include @@ -15,6 +16,7 @@ #include "RayTracingService.h" namespace Metal { + MeshInstance *MeshService::create(const std::string &id) { MeshData *data = loadMeshData(id); if (data == nullptr) { @@ -25,14 +27,14 @@ namespace Metal { instance->indexCount = data->indices.size(); instance->vertexCount = data->data.size(); - instance->dataBuffer = bufferService.createBuffer( + instance->dataBuffer = bufferService->createBuffer( id + "_data", sizeof(VertexData) * data->data.size(), VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | VK_BUFFER_USAGE_ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY_BIT_KHR | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT, data->data.data(), true); - instance->indexBuffer = bufferService.createBuffer( + instance->indexBuffer = bufferService->createBuffer( id + "_indices", sizeof(unsigned int) * data->indices.size(), VK_BUFFER_USAGE_INDEX_BUFFER_BIT | VK_BUFFER_USAGE_ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY_BIT_KHR | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT, @@ -56,7 +58,7 @@ namespace Metal { } MeshData *MeshService::loadMeshData(const std::string &id) const { - auto pathToFile = rootDirectory + "/assets/" + FORMAT_FILE_MESH(id); + auto pathToFile = directoryService->getRootDirectory() + "/assets/" + FORMAT_FILE_MESH(id); if (std::filesystem::exists(pathToFile)) { auto *data = new MeshData; std::ifstream input(pathToFile, std::ios::binary); @@ -69,8 +71,8 @@ namespace Metal { void MeshService::disposeResource(MeshInstance *resource) { LOG_INFO("Disposing of mesh instance"); - rayTracingService.markDirty(); - bufferService.dispose(resource->indexBuffer->getId()); - bufferService.dispose(resource->dataBuffer->getId()); + rayTracingService->markDirty(); + bufferService->dispose(resource->indexBuffer->getId()); + bufferService->dispose(resource->dataBuffer->getId()); } } // Metal diff --git a/src/engine/service/MeshService.h b/src/engine/service/MeshService.h index 40ba1270..b7984f35 100644 --- a/src/engine/service/MeshService.h +++ b/src/engine/service/MeshService.h @@ -11,16 +11,23 @@ namespace Metal { class BufferService; class RayTracingService; + class DirectoryService; class MeshService final : public AbstractResourceService { - BufferService &bufferService; - RayTracingService &rayTracingService; - const std::string &rootDirectory; + BufferService *bufferService = nullptr; + RayTracingService *rayTracingService = nullptr; + DirectoryService *directoryService = nullptr; public: - MeshService(BufferService &bufferService, RayTracingService &rayTracingService, const std::string &rootDirectory) - : bufferService(bufferService), rayTracingService(rayTracingService), rootDirectory(rootDirectory) {} - MeshService() = delete; + MeshService() = default; + + std::vector getDependencies() override { + return { + {"BufferService", bufferService}, + {"RayTracingService", rayTracingService}, + {"DirectoryService", directoryService} + }; + } MeshInstance *create(const std::string &id); @@ -29,7 +36,6 @@ namespace Metal { MeshData *loadMeshData(const std::string &id) const; void disposeResource(MeshInstance *resource) override; - }; } // Metal diff --git a/src/engine/service/PipelineService.h b/src/engine/service/PipelineService.h index 55d4852f..a80bbe1f 100644 --- a/src/engine/service/PipelineService.h +++ b/src/engine/service/PipelineService.h @@ -18,21 +18,16 @@ namespace Metal { class BufferService; class PipelineService final : public AbstractResourceService { - VulkanContext &vulkanContext; - FrameBufferService &framebufferService; - BufferService &bufferService; - DescriptorSetService &descriptorSetService; - ShaderService &shaderService; + VulkanContext *vulkanContext = nullptr; + FrameBufferService *framebufferService = nullptr; + BufferService *bufferService = nullptr; + DescriptorSetService *descriptorSetService = nullptr; + ShaderService *shaderService = nullptr; public: - explicit PipelineService(ShaderService &shaderService, VulkanContext &vulkanContext, - FrameBufferService &framebufferService, BufferService &bufferService, - DescriptorSetService &descriptorSetService) - : shaderService(shaderService), vulkanContext(vulkanContext), framebufferService(framebufferService), - bufferService(bufferService), descriptorSetService(descriptorSetService) { - } - - PipelineService() = delete; + PipelineService() = default; + + std::vector getDependencies() override; PipelineInstance *createPipeline(PipelineBuilder &pipelineBuilder); diff --git a/src/engine/service/RayTracingService.cpp b/src/engine/service/RayTracingService.cpp index 26c09a41..902a8641 100644 --- a/src/engine/service/RayTracingService.cpp +++ b/src/engine/service/RayTracingService.cpp @@ -12,6 +12,7 @@ #include "../repository/WorldRepository.h" #include "MeshService.h" #include "MaterialService.h" +#include "DescriptorSetService.h" #include "BufferService.h" #include "../EngineContext.h" #include @@ -25,7 +26,7 @@ namespace Metal { } void RayTracingService::updateDescriptorSets(VkAccelerationStructureKHR asHandle) { - auto descriptors = pipelineService.getAllDescriptors(); + auto descriptors = pipelineService->getAllDescriptors(); for (auto *descriptor: descriptors) { bool needsUpdate = false; for (auto &binding: descriptor->bindings) { @@ -36,7 +37,7 @@ namespace Metal { } if (needsUpdate) { - DescriptorSetService::Write(vulkanContext, bufferService, descriptor->vkDescriptorSet, descriptor->bindings); + descriptorService->Write(vulkanContext, bufferService, descriptor->vkDescriptorSet, descriptor->bindings); } } } @@ -66,7 +67,7 @@ namespace Metal { if (!anyMeshes) { // No meshes – destroy all structures and set descriptor to null - destroyAccelerationStructures(); // destroys BLAS and TLAS (waits for idle) + dispose(); // destroys BLAS and TLAS (waits for idle) updateDescriptorSets(VK_NULL_HANDLE); accelerationStructureBuilt = false; needsRebuild = false; @@ -401,7 +402,7 @@ namespace Metal { vulkan.endSingleTimeCommands(cmd); } - void RayTracingService::destroyAccelerationStructures() { + void RayTracingService::dispose() { LOG_INFO("Destroying acceleration structures"); auto &vulkan = vulkanContext; diff --git a/src/engine/service/RayTracingService.h b/src/engine/service/RayTracingService.h index 7d90afd3..4ecc20b2 100644 --- a/src/engine/service/RayTracingService.h +++ b/src/engine/service/RayTracingService.h @@ -2,13 +2,13 @@ #define RAYTRACINGSERVICE_H #include "../dto/MeshMetadata.h" -#include "../../editor/enum/engine-definitions.h" -#include #include #include #include #include -#include "../../common/AbstractRuntimeComponent.h" +#include "../../common/IService.h" +#include "../../common/ISync.h" +#include "../../common/IDisposable.h" namespace Metal { class BufferInstance; @@ -19,15 +19,17 @@ namespace Metal { class MaterialService; class BufferService; class EngineContext; - - class RayTracingService final : public AbstractRuntimeComponent { - VulkanContext &vulkanContext; - PipelineService &pipelineService; - WorldRepository &worldRepository; - MeshService &meshService; - MaterialService &materialService; - BufferService &bufferService; - EngineContext &engineContext; + class DescriptorService; + + class RayTracingService final : public IService, public ISync, public IDisposable { + VulkanContext *vulkanContext = nullptr; + PipelineService *pipelineService = nullptr; + WorldRepository *worldRepository = nullptr; + MeshService *meshService = nullptr; + MaterialService *materialService = nullptr; + BufferService *bufferService = nullptr; + EngineContext *engineContext = nullptr; + DescriptorService *descriptorService = nullptr; struct BLASEntry { VkAccelerationStructureKHR accelerationStructure = VK_NULL_HANDLE; @@ -36,6 +38,7 @@ namespace Metal { BufferInstance *vertexData = nullptr; BufferInstance *indexData = nullptr; }; + bool anyMeshes = false; // One BLAS per unique mesh ID @@ -66,15 +69,26 @@ namespace Metal { void updateMeshMaterials(); public: - RayTracingService(VulkanContext &vulkanContext, PipelineService &pipelineService, WorldRepository &worldRepository, MeshService &meshService, MaterialService &materialService, BufferService &bufferService, EngineContext &engineContext) - : vulkanContext(vulkanContext), pipelineService(pipelineService), worldRepository(worldRepository), meshService(meshService), materialService(materialService), bufferService(bufferService), engineContext(engineContext) {} - RayTracingService() = delete; + RayTracingService() = default; + + std::vector getDependencies() override { + return { + {"VulkanContext", vulkanContext}, + {"PipelineService", pipelineService}, + {"WorldRepository", worldRepository}, + {"MeshService", meshService}, + {"MaterialService", materialService}, + {"BufferService", bufferService}, + {"EngineContext", engineContext}, + {"DescriptorService", descriptorService} + }; + } void setNeedsMaterialUpdate(bool val) { needsMaterialUpdate = val; } - void destroyAccelerationStructures(); + void dispose() override; void onSync() override; diff --git a/src/engine/service/ShaderService.cpp b/src/engine/service/ShaderService.cpp index 8e062433..acb0ec4e 100644 --- a/src/engine/service/ShaderService.cpp +++ b/src/engine/service/ShaderService.cpp @@ -10,12 +10,15 @@ #include "../../core/vulkan/VulkanUtils.h" #include "../../editor/util/Util.h" #include "../../ApplicationContext.h" -#include "../../editor/util/FilesUtil.h" -#include "../../editor/service/LogService.h" +#include "../../common/FilesUtil.h" +#include "../../common/LoggerUtil.h" #include "../../editor/enum/ShadingMode.h" #include "glslang/Include/glslang_c_interface.h" #include "glslang/Public/resource_limits_c.h" -#define BASE_PATH "../resources/shaders/" +#define BASE_PATH directoryService->getShadersDirectory() + +#include "../../core/DirectoryService.h" +#include "../../core/vulkan/VulkanContext.h" namespace Metal { void ShaderService::CheckShaderCompilation(glslang_shader_t *shader) { @@ -81,7 +84,7 @@ namespace Metal { shaderCreateInfo.codeSize = shaderModule->SPIRV.size() * sizeof(unsigned int); shaderCreateInfo.pCode = static_cast(shaderModule->SPIRV.data()); - VulkanUtils::CheckVKResult(vkCreateShaderModule(vulkanContext.device.device, &shaderCreateInfo, + VulkanUtils::CheckVKResult(vkCreateShaderModule(vulkanContext->device.device, &shaderCreateInfo, nullptr, &shaderModule->vkShaderModule)); glslang_program_delete(program); @@ -131,7 +134,7 @@ namespace Metal { throw std::runtime_error("Unknown shader stage in file"); } - std::string ShaderService::ProcessIncludes(const std::string &input) { + std::string ShaderService::ProcessIncludes(const std::string &input, const std::string &basePath) { std::string result = input; std::regex includePattern(R"(#include\s+"(.+))"); std::smatch match; @@ -144,7 +147,7 @@ namespace Metal { } try { std::string source; - FilesUtil::ReadFile((BASE_PATH + includeFile).c_str(), source); + FilesUtil::ReadFile((basePath + includeFile).c_str(), source); result.replace(match.position(0), match.length(0), source); } catch (const std::exception &e) { LOG_ERROR("Error loading included shader: " + std::string(e.what())); @@ -152,19 +155,20 @@ namespace Metal { } } if (result.find("#include") != std::string::npos) { - result = ProcessIncludes(result); + result = ProcessIncludes(result, basePath); } return result; } - std::string ShaderService::ProcessShader(const std::string &file) { + std::string ShaderService::ProcessShader(const std::string &file, const std::string &basePath) { std::string source; FilesUtil::ReadFile(file.c_str(), source); - return ProcessIncludes(source); + return ProcessIncludes(source, basePath); } VkShaderModule ShaderService::createShaderModule(const std::string &pFilename) { - std::string source = ProcessShader(BASE_PATH + pFilename); + this->isDebugMode = CTX->isDebugMode(); + std::string source = ProcessShader(BASE_PATH + pFilename, BASE_PATH); if (isDebugMode) { source = "#define DEBUG\n" + source; } @@ -177,6 +181,7 @@ namespace Metal { const size_t sourceHash = std::hash{}(source); const std::string part(BASE_PATH + pFilename); const std::string shaderName = part.substr(part.find_last_of('/') + 1, part.size()); + const std::string shadersDirectory = directoryService->getShadersDirectory(); const std::string binaryFilename = shadersDirectory + shaderName + ".spv"; const std::string hashFilename = shadersDirectory + shaderName + ".hash"; @@ -195,7 +200,7 @@ namespace Metal { shaderCreateInfo.codeSize = shader.SPIRV.size() * sizeof(unsigned int); shaderCreateInfo.pCode = static_cast(shader.SPIRV.data()); - if (vkCreateShaderModule(vulkanContext.device.device, &shaderCreateInfo, + if (vkCreateShaderModule(vulkanContext->device.device, &shaderCreateInfo, nullptr, &shader.vkShaderModule) == VK_SUCCESS) { needsCompilation = false; LOG_INFO("Loaded cached shader: " + shaderName); diff --git a/src/engine/service/ShaderService.h b/src/engine/service/ShaderService.h index 43a2dd06..19199570 100644 --- a/src/engine/service/ShaderService.h +++ b/src/engine/service/ShaderService.h @@ -2,15 +2,16 @@ #define SHADERSERVICE_H #include #include "../dto/ShaderModule.h" -#include "../../common/AbstractRuntimeComponent.h" +#include "../../common/IService.h" namespace Metal { class VulkanContext; - class ShaderService final : public AbstractRuntimeComponent { - bool isDebugMode; - std::string shadersDirectory; - VulkanContext &vulkanContext; + class DirectoryService; + class ShaderService final : public IService { + bool isDebugMode = false; + VulkanContext *vulkanContext = nullptr; + DirectoryService *directoryService = nullptr; static void CheckShaderCompilation(glslang_shader_t *shader); @@ -19,13 +20,19 @@ namespace Metal { static glslang_stage_t ShaderStageFromFilename(const char *pFilename); - static std::string ProcessIncludes(const std::string &input); + static std::string ProcessIncludes(const std::string &input, const std::string &basePath); - static std::string ProcessShader(const std::string &file); + static std::string ProcessShader(const std::string &file, const std::string &basePath); public: - explicit ShaderService(const std::string &shadersDirectory, bool isDebugMode, VulkanContext &vulkanContext) : shadersDirectory( - shadersDirectory), isDebugMode(isDebugMode), vulkanContext(vulkanContext){} + ShaderService() = default; + + std::vector getDependencies() override { + return { + {"VulkanContext", vulkanContext}, + {"DirectoryService", directoryService} + }; + } VkShaderModule createShaderModule(const std::string &pFilename); }; diff --git a/src/engine/service/StreamingService.cpp b/src/engine/service/StreamingService.cpp index e5a04f37..1b1cabb8 100644 --- a/src/engine/service/StreamingService.cpp +++ b/src/engine/service/StreamingService.cpp @@ -10,6 +10,7 @@ #include "../resource/SVOInstance.h" #include "../resource/MeshInstance.h" #include "../resource/TextureInstance.h" +#include "../../common/LoggerUtil.h" #include "../dto/PrimitiveComponent.h" @@ -17,17 +18,17 @@ namespace Metal { static constexpr int MAX_TIMEOUT = 10000; template - void disposeResources(AbstractResourceService &service, std::unordered_map &lastUse, EngineContext &engineContext) { - auto &resources = service.getResources(); + void disposeResources(AbstractResourceService *service, std::unordered_map &lastUse, EngineContext *engineContext) { + auto &resources = service->getResources(); for (auto it = resources.begin(); it != resources.end();) { if (lastUse.contains(it->second->getId()) && !it->second->isNoDisposal() && ( - engineContext.currentTimeMs - lastUse.at(it->second->getId())) >= MAX_TIMEOUT) { + engineContext->currentTimeMs - lastUse.at(it->second->getId())) >= MAX_TIMEOUT) { LOG_DEBUG( - "Disposing of " + it->first + " Since last use: " + std::to_string(engineContext.currentTimeMs - + "Disposing of " + it->first + " Since last use: " + std::to_string(engineContext->currentTimeMs - lastUse.at(it->second->getId()))); std::string id = it->first; ++it; - service.dispose(id); + service->dispose(id); } else { ++it; } @@ -35,25 +36,25 @@ namespace Metal { } void StreamingService::onSync() { - auto view = worldRepository.registry.view(); + auto view = worldRepository->registry.view(); for (auto entity: view) { auto &meshComp = view.get(entity); if (!meshComp.meshId.empty()) { - lastUse[meshComp.meshId] = engineContext.currentTimeMs; + lastUse[meshComp.meshId] = engineContext->currentTimeMs; } if (!meshComp.albedo.empty()) { - lastUse[meshComp.albedo] = engineContext.currentTimeMs; + lastUse[meshComp.albedo] = engineContext->currentTimeMs; } if (!meshComp.roughness.empty()) { - lastUse[meshComp.roughness] = engineContext.currentTimeMs; + lastUse[meshComp.roughness] = engineContext->currentTimeMs; } if (!meshComp.metallic.empty()) { - lastUse[meshComp.metallic] = engineContext.currentTimeMs; + lastUse[meshComp.metallic] = engineContext->currentTimeMs; } } - if ((engineContext.currentTime - sinceLastCleanup).count() >= MAX_TIMEOUT) { - sinceLastCleanup = engineContext.currentTime; + if ((engineContext->currentTime - sinceLastCleanup).count() >= MAX_TIMEOUT) { + sinceLastCleanup = engineContext->currentTime; disposeResources(meshService, lastUse, engineContext); disposeResources(textureService, lastUse, engineContext); disposeResources(voxelService, lastUse, engineContext); diff --git a/src/engine/service/StreamingService.h b/src/engine/service/StreamingService.h index 649e650a..44201422 100644 --- a/src/engine/service/StreamingService.h +++ b/src/engine/service/StreamingService.h @@ -4,7 +4,8 @@ #include #include -#include "../../common/AbstractRuntimeComponent.h" +#include "../../common/IService.h" +#include "../../common/ISync.h" using Clock = std::chrono::high_resolution_clock; using TimePoint = std::chrono::time_point; @@ -19,19 +20,26 @@ namespace Metal { class TextureService; class VoxelService; - class StreamingService final : public AbstractRuntimeComponent { + class StreamingService final : public IService, public ISync { std::unordered_map lastUse{}; TimePoint sinceLastCleanup; - EngineContext &engineContext; - WorldRepository &worldRepository; - MeshService &meshService; - TextureService &textureService; - VoxelService &voxelService; + EngineContext *engineContext = nullptr; + WorldRepository *worldRepository = nullptr; + MeshService *meshService = nullptr; + TextureService *textureService = nullptr; + VoxelService *voxelService = nullptr; public: - StreamingService(EngineContext &engineContext, WorldRepository &worldRepository, MeshService &meshService, TextureService &textureService, VoxelService &voxelService) - : engineContext(engineContext), worldRepository(worldRepository), meshService(meshService), textureService(textureService), voxelService(voxelService) {} + std::vector getDependencies() override { + return { + {"EngineContext", engineContext}, + {"WorldRepository", worldRepository}, + {"MeshService", meshService}, + {"TextureService", textureService}, + {"VoxelService", voxelService} + }; + } void onSync() override; }; diff --git a/src/engine/service/TextureService.cpp b/src/engine/service/TextureService.cpp index 1e045dec..8505d17f 100644 --- a/src/engine/service/TextureService.cpp +++ b/src/engine/service/TextureService.cpp @@ -18,9 +18,9 @@ #include "BufferService.h" #include "PipelineService.h" #include "DescriptorSetService.h" -#include "../dto/DescriptorInstance.h" namespace Metal { + void TextureService::copyBufferToImage(const VkBuffer &vkBuffer, const TextureInstance *image, const int layerCount) const { VkCommandBuffer commandBuffer = vulkanContext.beginSingleTimeCommands(); diff --git a/src/engine/service/TextureService.h b/src/engine/service/TextureService.h index 891f847d..047561e7 100644 --- a/src/engine/service/TextureService.h +++ b/src/engine/service/TextureService.h @@ -10,16 +10,18 @@ namespace Metal { struct TextureInstance; + class VulkanContext; class BufferService; class PipelineService; class DescriptorSetService; + class DirectoryService; class TextureService final : public AbstractResourceService { - VulkanContext &vulkanContext; - BufferService &bufferService; - PipelineService &pipelineService; - DescriptorSetService &descriptorSetService; - const std::string &rootDirectory; + VulkanContext *vulkanContext = nullptr; + BufferService *bufferService = nullptr; + PipelineService *pipelineService = nullptr; + DescriptorSetService *descriptorSetService = nullptr; + DirectoryService *directoryService = nullptr; unsigned int nextTextureIndex = 1; std::unordered_map textureIndices{}; @@ -41,9 +43,15 @@ namespace Metal { void generateMipmaps(const TextureInstance *image) const; public: - TextureService(VulkanContext &vulkanContext, BufferService &bufferService, PipelineService &pipelineService, DescriptorSetService &descriptorSetService, const std::string &rootDirectory) - : vulkanContext(vulkanContext), bufferService(bufferService), pipelineService(pipelineService), descriptorSetService(descriptorSetService), rootDirectory(rootDirectory) {} - TextureService() = delete; + std::vector getDependencies() override { + return { + {"VulkanContext", vulkanContext}, + {"BufferService", bufferService}, + {"PipelineService", pipelineService}, + {"DescriptorSetService", descriptorSetService}, + {"DirectoryService", directoryService} + }; + } [[nodiscard]] TextureData *loadTextureData(const std::string &id) const; diff --git a/src/engine/service/TransformService.cpp b/src/engine/service/TransformService.cpp index 4e201f84..bc08a257 100644 --- a/src/engine/service/TransformService.cpp +++ b/src/engine/service/TransformService.cpp @@ -2,16 +2,19 @@ #include #include #include +#include "../../common/LoggerUtil.h" #include "../../ApplicationContext.h" #include "../dto/TransformComponent.h" #include "../repository/WorldRepository.h" +#include "../dto/TransformComponent.h" +#include "../dto/PrimitiveComponent.h" #include "RayTracingService.h" namespace Metal { void TransformService::onSync() { - for (auto entity : worldRepository.registry.view()) { - TransformComponent &st = worldRepository.registry.get(entity); + for (auto entity : worldRepository->registry.view()) { + TransformComponent &st = worldRepository->registry.get(entity); if (st.isNotFrozen()) { transform(&st, nullptr); st.freezeVersion(); @@ -38,8 +41,8 @@ namespace Metal { st->model = auxMat4 * auxMat42; st->freezeVersion(); - if (worldRepository.registry.all_of(st->getEntityId())) { - rayTracingService.markDirty(); + if (worldRepository->registry.all_of(st->getEntityId())) { + rayTracingService->markDirty(); } } } // Metal diff --git a/src/engine/service/TransformService.h b/src/engine/service/TransformService.h index 3149e81c..f221dde7 100644 --- a/src/engine/service/TransformService.h +++ b/src/engine/service/TransformService.h @@ -4,19 +4,18 @@ #include #include -#include "../../editor/enum/engine-definitions.h" -#include "../../common/AbstractRuntimeComponent.h" +#include "../../common/ISync.h" +#include "../../common/IService.h" namespace Metal { struct TransformComponent; - struct TransformComponent; struct WorldRepository; class RayTracingService; - class TransformService final : AbstractRuntimeComponent { - WorldRepository &worldRepository; - RayTracingService &rayTracingService; + class TransformService final : public IService, public ISync { + WorldRepository *worldRepository = nullptr; + RayTracingService *rayTracingService = nullptr; glm::vec3 distanceAux{}; glm::mat4x4 auxMat4{}; @@ -24,9 +23,12 @@ namespace Metal { glm::mat4x4 auxMat42{}; public: - explicit TransformService(WorldRepository &worldRepository, RayTracingService &rayTracingService) - : worldRepository(worldRepository), rayTracingService(rayTracingService) {} - TransformService() = delete; + std::vector getDependencies() override { + return { + {"WorldRepository", worldRepository}, + {"RayTracingService", rayTracingService} + }; + } void onSync() override; diff --git a/src/engine/service/VolumeService.cpp b/src/engine/service/VolumeService.cpp index d04c4454..52d3b3b8 100644 --- a/src/engine/service/VolumeService.cpp +++ b/src/engine/service/VolumeService.cpp @@ -4,13 +4,21 @@ #include "../resource/BufferInstance.h" #include "../../editor/enum/EngineResourceIDs.h" #include "../repository/WorldRepository.h" +#include "../dto/TransformComponent.h" +#include "../dto/VolumeComponent.h" #include "../EngineContext.h" namespace Metal { void VolumeService::registerVolumes() { - auto view = worldRepository.registry.view(); - for (auto [entityId, l, t]: view.each()) { - if (worldRepository.hiddenEntities.contains(entityId)) { + auto ®istry = worldRepository->registry; + auto view = registry.view(); + for (auto entityId: view) { + if (!registry.all_of(entityId)) { + continue; + } + auto &l = registry.get(entityId); + auto &t = registry.get(entityId); + if (worldRepository->hiddenEntities.contains(entityId)) { continue; } @@ -32,7 +40,7 @@ namespace Metal { registerVolumes(); if (!items.empty()) { - engineContext.currentFrame->getResourceAs(RID_VOLUMES_BUFFER)->update(items.data()); + engineContext->currentFrame->getResourceAs(RID_VOLUMES_BUFFER)->update(items.data()); } } } // Metal diff --git a/src/engine/service/VolumeService.h b/src/engine/service/VolumeService.h index 60d32fed..eada2e3d 100644 --- a/src/engine/service/VolumeService.h +++ b/src/engine/service/VolumeService.h @@ -2,7 +2,8 @@ #define VOLUME_SERVICE_H #include -#include "../../common/AbstractRuntimeComponent.h" +#include "../../common/IService.h" +#include "../../common/ISync.h" #include "../dto/VolumeData.h" namespace Metal { @@ -10,17 +11,20 @@ namespace Metal { struct WorldRepository; class EngineContext; - class VolumeService final : public AbstractRuntimeComponent { - WorldRepository &worldRepository; - EngineContext &engineContext; + class VolumeService final : public IService, public ISync { + WorldRepository *worldRepository = nullptr; + EngineContext *engineContext = nullptr; std::vector items{}; void registerVolumes(); public: - explicit VolumeService(WorldRepository &worldRepository, EngineContext &engineContext) - : worldRepository(worldRepository), engineContext(engineContext) {} - VolumeService() = delete; + std::vector getDependencies() override { + return { + {"WorldRepository", worldRepository}, + {"EngineContext", engineContext} + }; + } void onSync() override; diff --git a/src/main.cpp b/src/main.cpp index 2e02e7af..a851954a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6,14 +6,110 @@ #define GLM_FORCE_RADIANS #define GLM_FORCE_DEPTH_ZERO_TO_ONE #include "ApplicationContext.h" +#include "core/DirectoryService.h" +#include "core/FrameService.h" +#include "core/glfw/GLFWContext.h" +#include "core/gui/GuiContext.h" +#include "core/vulkan/VulkanContext.h" +#include "editor/EditorPanel.h" +#include "editor/service/AsyncTaskService.h" +#include "editor/service/DockService.h" +#include "editor/service/FileImporterService.h" +#include "editor/service/FilesService.h" +#include "editor/service/MaterialImporterService.h" +#include "editor/service/MeshImporterService.h" +#include "editor/service/NotificationService.h" +#include "editor/service/PickingService.h" +#include "editor/service/SceneImporterService.h" +#include "editor/service/SelectionService.h" +#include "editor/service/TextureImporterService.h" +#include "editor/service/ThemeService.h" +#include "editor/service/VoxelImporterService.h" +#include "editor/repository/EditorRepository.h" + +#include "engine/repository/EngineRepository.h" +#include "engine/repository/RuntimeRepository.h" +#include "engine/repository/WorldRepository.h" + +#include "engine/service/BufferService.h" +#include "engine/service/CameraService.h" +#include "engine/service/CommandBufferRecorderService.h" +#include "engine/service/DescriptorSetService.h" +#include "engine/service/FrameBufferService.h" +#include "engine/service/LightService.h" +#include "engine/service/MaterialService.h" +#include "engine/service/MeshService.h" +#include "engine/service/PipelineService.h" +#include "engine/service/RayTracingService.h" +#include "engine/service/ShaderService.h" +#include "engine/service/StreamingService.h" +#include "engine/service/TextureService.h" +#include "engine/service/TransformService.h" +#include "engine/service/VolumeService.h" +#include "engine/service/VoxelService.h" +#include "engine/EngineContext.h" int main(int, char **) { - Metal::ApplicationContext::Init(true); + Metal::ApplicationContext context{true}; + + // --- ORDER MATTERS + context.registerSingleton(std::make_unique()); + context.registerSingleton(std::make_unique()); + context.registerSingleton(std::make_unique()); + context.registerSingleton(std::make_unique()); + // --- ORDER MATTERS + + context.registerSingleton(std::make_unique()); + context.registerSingleton(std::make_unique()); + context.registerSingleton(std::make_unique()); + context.registerSingleton(std::make_unique()); + context.registerSingleton(std::make_unique()); + context.registerSingleton(std::make_unique()); + context.registerSingleton(std::make_unique()); + context.registerSingleton(std::make_unique()); + context.registerSingleton(std::make_unique()); + context.registerSingleton(std::make_unique()); + context.registerSingleton(std::make_unique()); + context.registerSingleton(std::make_unique()); + context.registerSingleton(std::make_unique()); + context.registerSingleton(std::make_unique()); + context.registerSingleton(std::make_unique()); + context.registerSingleton(std::make_unique()); + context.registerSingleton(std::make_unique()); + context.registerSingleton(std::make_unique()); + context.registerSingleton(std::make_unique()); + + context.registerSingleton(std::make_unique()); + context.registerSingleton(std::make_unique()); + context.registerSingleton(std::make_unique()); + context.registerSingleton(std::make_unique()); + context.registerSingleton(std::make_unique()); + context.registerSingleton(std::make_unique()); + context.registerSingleton(std::make_unique()); + context.registerSingleton(std::make_unique()); + context.registerSingleton(std::make_unique()); + context.registerSingleton(std::make_unique()); + context.registerSingleton(std::make_unique()); + context.registerSingleton(std::make_unique()); + + context.registerSingleton(std::make_unique()); + context.registerSingleton(std::make_unique()); + context.registerSingleton(std::make_unique()); + context.registerSingleton(std::make_unique()); + context.registerSingleton(std::make_unique()); + + context.onInitialize(); + auto &frameService = context.getSingleton(); + auto &directoryService = context.getSingleton(); + directoryService.updateRootPath(false); + auto &editor = context.getSingleton(); - if (!CTX.isValidContext()) { + frameService.setPanel(&editor); + if (!frameService.isValidContext()) { printf("GLFW: Vulkan Not Supported\n"); return 1; } - CTX.start(); + frameService.onInitialize(); + context.dispose(); return 0; } From e7210c802d5cc743dd4987f334092658c325a186 Mon Sep 17 00:00:00 2001 From: facobackup Date: Sat, 14 Mar 2026 17:13:09 -0300 Subject: [PATCH 13/18] Dependency injection for panels and other runtime objects --- CMakeLists.txt | 1 - src/ApplicationContext.cpp | 4 - src/ApplicationContext.h | 17 ++- src/common/IContextMember.cpp | 1 + src/common/IContextMember.h | 2 + src/core/gui/GuiContext.cpp | 1 + src/core/gui/GuiContext.h | 1 - src/core/vulkan/VulkanContext.cpp | 2 +- src/editor/EditorPanel.cpp | 6 +- src/editor/EditorPanel.h | 13 ++ src/editor/abstract/AbstractPanel.cpp | 7 +- src/editor/abstract/AbstractPanel.h | 14 +- src/editor/abstract/IPanel.h | 14 -- .../abstract/form/AbstractFormFieldPanel.h | 10 ++ src/editor/abstract/form/AccordionPanel.cpp | 3 +- src/editor/abstract/form/AccordionPanel.h | 3 +- src/editor/abstract/form/ChildPanel.cpp | 3 +- .../abstract/form/types/ResourceField.cpp | 3 +- .../abstract/form/types/ResourceField.h | 6 + .../form/types/ResourceFilesPanel.cpp | 2 +- .../abstract/form/types/StringField.cpp | 2 +- .../dock-spaces/docks/DockSpacePanel.cpp | 10 +- src/editor/dock-spaces/docks/DockSpacePanel.h | 12 ++ .../dock-spaces/files/FilePreviewPanel.cpp | 6 +- .../dock-spaces/files/FilePreviewPanel.h | 13 ++ .../dock-spaces/files/FilesHeaderPanel.cpp | 7 +- .../dock-spaces/files/FilesHeaderPanel.h | 10 +- .../dock-spaces/files/FilesListPanel.cpp | 10 +- src/editor/dock-spaces/files/FilesListPanel.h | 13 +- src/editor/dock-spaces/files/FilesPanel.cpp | 53 +++---- src/editor/dock-spaces/files/FilesPanel.h | 27 ++++ .../dock-spaces/footer/EditorFooterPanel.cpp | 5 +- .../dock-spaces/footer/EditorFooterPanel.h | 10 ++ .../dock-spaces/header/AsyncTaskPanel.cpp | 6 +- .../dock-spaces/header/AsyncTaskPanel.h | 10 ++ .../dock-spaces/header/EditorHeaderPanel.cpp | 17 ++- .../dock-spaces/header/EditorHeaderPanel.h | 16 ++ .../dock-spaces/inspector/InspectorPanel.cpp | 18 +-- .../dock-spaces/inspector/InspectorPanel.h | 12 ++ .../dock-spaces/metrics/MetricsPanel.cpp | 18 ++- src/editor/dock-spaces/metrics/MetricsPanel.h | 25 ++++ .../repositories/RepositoriesPanel.cpp | 10 +- .../repositories/RepositoriesPanel.h | 15 ++ .../viewport/CameraPositionPanel.cpp | 8 +- .../viewport/CameraPositionPanel.h | 10 ++ .../dock-spaces/viewport/EngineFramePanel.cpp | 31 ++-- .../dock-spaces/viewport/EngineFramePanel.h | 24 ++- .../dock-spaces/viewport/GizmoPanel.cpp | 14 +- src/editor/dock-spaces/viewport/GizmoPanel.h | 14 ++ .../viewport/GizmoSettingsPanel.cpp | 10 +- .../dock-spaces/viewport/GizmoSettingsPanel.h | 9 ++ .../viewport/ViewportHeaderPanel.cpp | 16 +- .../viewport/ViewportHeaderPanel.h | 13 ++ .../dock-spaces/viewport/ViewportPanel.cpp | 82 +++++------ .../dock-spaces/viewport/ViewportPanel.h | 28 ++++ .../dock-spaces/world/WorldHeaderPanel.cpp | 4 +- .../dock-spaces/world/WorldHeaderPanel.h | 10 ++ src/editor/dock-spaces/world/WorldPanel.cpp | 31 ++-- src/editor/dock-spaces/world/WorldPanel.h | 14 ++ src/editor/enum/engine-definitions.h | 1 + src/editor/panel/FileImportModalPanel.cpp | 39 ++--- src/editor/panel/FileImportModalPanel.h | 15 ++ src/editor/panel/NotificationsPanel.cpp | 12 +- src/editor/panel/NotificationsPanel.h | 13 ++ src/editor/passes/GridPass.cpp | 15 +- src/editor/passes/GridPass.h | 16 ++ src/editor/passes/SelectionIDPass.cpp | 26 ++-- src/editor/passes/SelectionIDPass.h | 18 +++ src/editor/passes/SelectionOutlinePass.cpp | 15 +- src/editor/passes/SelectionOutlinePass.h | 13 ++ src/editor/service/DockService.cpp | 19 +-- src/editor/service/DockService.h | 7 +- src/editor/service/FilesService.cpp | 27 ++-- src/editor/service/FilesService.h | 4 +- src/editor/service/ThemeService.cpp | 44 +++--- src/engine/EngineContext.cpp | 18 +++ src/engine/EngineContext.h | 9 +- src/engine/enum/ComponentType.cpp | 11 +- src/engine/enum/ComponentType.h | 1 + .../frame-builder/EngineFrameBuilder.cpp | 29 ++-- src/engine/frame-builder/EngineFrameBuilder.h | 21 ++- .../structures/BufferBuilder.cpp | 4 +- .../frame-builder/structures/BufferBuilder.h | 7 + .../CommandBufferRecorderBuilder.cpp | 9 +- .../structures/CommandBufferRecorderBuilder.h | 19 ++- .../structures/FramebufferBuilder.cpp | 19 ++- .../structures/FramebufferBuilder.h | 7 +- .../structures/ResourceBuilder.h | 7 +- .../structures/TextureBuilder.cpp | 8 +- .../frame-builder/structures/TextureBuilder.h | 8 +- src/engine/passes/AbstractPass.h | 4 +- src/engine/passes/CommandBufferRecorder.cpp | 10 +- src/engine/passes/CommandBufferRecorder.h | 10 +- src/engine/passes/impl/HWRayTracingPass.cpp | 41 +++--- src/engine/passes/impl/HWRayTracingPass.h | 22 +++ src/engine/passes/impl/PostProcessingPass.cpp | 14 +- src/engine/passes/impl/PostProcessingPass.h | 17 +++ src/engine/passes/impl/SpatialFilterPass.cpp | 5 +- src/engine/passes/impl/SpatialFilterPass.h | 10 ++ .../passes/impl/TemporalAccumulationPass.cpp | 5 +- .../passes/impl/TemporalAccumulationPass.h | 9 ++ src/engine/repository/WorldRepository.h | 8 +- src/engine/resource/FrameBufferAttachment.cpp | 13 +- src/engine/resource/FrameBufferAttachment.h | 8 +- src/engine/resource/RuntimeResource.h | 19 ++- src/engine/service/BufferService.cpp | 40 ++--- src/engine/service/DescriptorSetService.cpp | 4 +- src/engine/service/FrameBufferService.cpp | 25 ++-- src/engine/service/PipelineService.cpp | 59 ++++---- src/engine/service/RayTracingService.cpp | 139 +++++++++--------- src/engine/service/RayTracingService.h | 8 +- src/engine/service/ShaderService.cpp | 2 +- src/engine/service/TextureService.cpp | 54 +++---- src/main.cpp | 93 ++++++------ 114 files changed, 1212 insertions(+), 624 deletions(-) delete mode 100644 src/editor/abstract/IPanel.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 3b165cea..9d6aebeb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,6 @@ add_executable( src/main.cpp src/editor/EditorPanel.cpp src/editor/EditorPanel.h - src/editor/abstract/IPanel.h src/engine/EngineContext.cpp src/engine/EngineContext.h src/core/vulkan/VulkanUtils.cpp diff --git a/src/ApplicationContext.cpp b/src/ApplicationContext.cpp index a0cb05d3..b14ca0d3 100644 --- a/src/ApplicationContext.cpp +++ b/src/ApplicationContext.cpp @@ -7,10 +7,7 @@ #include "core/glfw/GLFWContext.h" namespace Metal { - ApplicationContext *ApplicationContext::CONTEXT = nullptr; - ApplicationContext::ApplicationContext(bool debugMode) : debugMode(debugMode) { - CONTEXT = this; } void ApplicationContext::onInitialize() { @@ -37,7 +34,6 @@ namespace Metal { if (disposable) { disposable->dispose(); } - delete it->release(); } } catch (std::exception &e) { LOG_ERROR(e.what()); diff --git a/src/ApplicationContext.h b/src/ApplicationContext.h index 0afd22a2..54ba00fd 100644 --- a/src/ApplicationContext.h +++ b/src/ApplicationContext.h @@ -6,25 +6,21 @@ #include #include #include +#include #include #include "common/IInit.h" #include "common/IContextMember.h" #include "common/IDisposable.h" -#define CTX ApplicationContext::CONTEXT #define ENGINE_NAME "Metal Engine" namespace Metal { namespace fs = std::filesystem; - class ApplicationContext : public IInit, public IDisposable { - public: - static ApplicationContext *CONTEXT; - - private: + class ApplicationContext : public IContextMember, public IInit, public IDisposable { std::unordered_map singletons; - std::vector > instances; + std::vector > instances; bool debugMode; public: @@ -33,7 +29,7 @@ namespace Metal { void onInitialize() override; template - void registerSingleton(std::unique_ptr instance) { + void registerSingleton(std::shared_ptr instance) { static_assert(std::is_base_of_v, "T must derive from IContextMember"); T *ptr = instance.get(); singletons[typeid(T).name()] = static_cast(ptr); @@ -57,6 +53,11 @@ namespace Metal { return it->second; } + void injectDependencies(IContextMember *member) { + std::cout << "Injecting dependencies for: " << typeid(*member).name() << std::endl; + member->setDependencies(*this); + } + [[nodiscard]] bool isDebugMode() const; void dispose() override; diff --git a/src/common/IContextMember.cpp b/src/common/IContextMember.cpp index f42b28ce..8daeee72 100644 --- a/src/common/IContextMember.cpp +++ b/src/common/IContextMember.cpp @@ -3,6 +3,7 @@ namespace Metal { void IContextMember::setDependencies(ApplicationContext &ctx) { + this->ctx = &ctx; for (auto &dep : getDependencies()) { dep.ptr = ctx.getSingletonByName(dep.name); } diff --git a/src/common/IContextMember.h b/src/common/IContextMember.h index 1226a4fc..6a80f326 100644 --- a/src/common/IContextMember.h +++ b/src/common/IContextMember.h @@ -12,6 +12,8 @@ namespace Metal { }; class IContextMember { + public: + ApplicationContext *ctx = nullptr; public: virtual ~IContextMember() = default; diff --git a/src/core/gui/GuiContext.cpp b/src/core/gui/GuiContext.cpp index ab84174b..15fb1226 100644 --- a/src/core/gui/GuiContext.cpp +++ b/src/core/gui/GuiContext.cpp @@ -10,6 +10,7 @@ #include "../vulkan/VulkanContext.h" #include "../glfw/GLFWContext.h" #include "../../engine/service/DescriptorSetService.h" +#include "../../editor/enum/engine-definitions.h" namespace Metal { void GuiContext::endFrame() { diff --git a/src/core/gui/GuiContext.h b/src/core/gui/GuiContext.h index 5c117b02..2ee14541 100644 --- a/src/core/gui/GuiContext.h +++ b/src/core/gui/GuiContext.h @@ -1,7 +1,6 @@ #ifndef METAL_ENGINE_GUICONTEXT_H #define METAL_ENGINE_GUICONTEXT_H -#define LARGE_FONT_SIZE 38 #include #include #include "../../common/IService.h" diff --git a/src/core/vulkan/VulkanContext.cpp b/src/core/vulkan/VulkanContext.cpp index 4c38039e..35f7930d 100644 --- a/src/core/vulkan/VulkanContext.cpp +++ b/src/core/vulkan/VulkanContext.cpp @@ -254,7 +254,7 @@ namespace Metal { } void VulkanContext::onInitialize() { - this->debugMode = CTX->isDebugMode(); + this->debugMode = ctx->isDebugMode(); this->window = glfwContext->getWindow(); imguiVulkanWindow.ClearValue.color.float32[0] = 0; diff --git a/src/editor/EditorPanel.cpp b/src/editor/EditorPanel.cpp index 399fa50e..89efab59 100644 --- a/src/editor/EditorPanel.cpp +++ b/src/editor/EditorPanel.cpp @@ -1,6 +1,8 @@ #include "EditorPanel.h" #include "util/UIUtil.h" #include "../ApplicationContext.h" +#include "service/DockService.h" +#include "service/ThemeService.h" #include "dock-spaces/header/EditorHeaderPanel.h" #include "dock-spaces/footer/EditorFooterPanel.h" #include "panel/FileImportModalPanel.h" @@ -46,7 +48,7 @@ namespace Metal { ImGui::PopStyleVar(3); - applicationContext->dockService.buildViews(windowId, this); + dockService->buildViews(windowId, this); ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 0.0f); ImGui::DockSpace(windowId, CENTER, ImGuiDockNodeFlags_PassthruCentralNode); @@ -97,7 +99,7 @@ namespace Metal { } void EditorPanel::onSync() { - applicationContext->themeService.onSync(); + themeService->onSync(); renderDockSpaces(); notificationsPanel->onSync(); fileImportModalPanel->onSync(); diff --git a/src/editor/EditorPanel.h b/src/editor/EditorPanel.h index 32a9cf0a..80d47127 100644 --- a/src/editor/EditorPanel.h +++ b/src/editor/EditorPanel.h @@ -5,6 +5,9 @@ #include "abstract/AbstractPanel.h" namespace Metal { + class DockService; + class ThemeService; + class EditorPanel final : public AbstractPanel { static int FLAGS; static const char *NAME; @@ -19,6 +22,9 @@ namespace Metal { AbstractPanel *notificationsPanel = nullptr; AbstractPanel *fileImportModalPanel = nullptr; + DockService *dockService = nullptr; + ThemeService *themeService = nullptr; + static void SetWindowStyle(); void renderDockSpaces(); @@ -28,6 +34,13 @@ namespace Metal { void renderFooter(const ImGuiViewport *viewport); public: + std::vector getDependencies() override { + return { + {"DockService", dockService}, + {"ThemeService", themeService} + }; + } + void onInitialize() override; void onSync() override; diff --git a/src/editor/abstract/AbstractPanel.cpp b/src/editor/abstract/AbstractPanel.cpp index 3db1de52..441d5537 100644 --- a/src/editor/abstract/AbstractPanel.cpp +++ b/src/editor/abstract/AbstractPanel.cpp @@ -1,11 +1,12 @@ #include "AbstractPanel.h" #include "../util/Util.h" +#include "../../ApplicationContext.h" namespace Metal { void AbstractPanel::appendChild(AbstractPanel *panel) { - panel->applicationContext = applicationContext; + ctx->injectDependencies(panel); panel->onInitialize(); - children.emplace_back(panel); + children.push_back(panel); } void AbstractPanel::onSyncChildren() const { @@ -25,7 +26,7 @@ namespace Metal { children.clear(); } - std::vector &AbstractPanel::getChildren() { + std::vector &AbstractPanel::getChildren() { return children; } } diff --git a/src/editor/abstract/AbstractPanel.h b/src/editor/abstract/AbstractPanel.h index d2f52f23..b86431df 100644 --- a/src/editor/abstract/AbstractPanel.h +++ b/src/editor/abstract/AbstractPanel.h @@ -4,15 +4,15 @@ #include #include -#include "IPanel.h" +#include "../../common/IContextMember.h" +#include "../../common/ISync.h" +#include "../../common/IInit.h" namespace Metal { class ApplicationContext; - class AbstractPanel : public IPanel { - public: - ApplicationContext *applicationContext{}; + class AbstractPanel : public IContextMember, public ISync, public IInit { protected: - std::vector children; + std::vector children; const std::string id; virtual void onSyncChildren() const; @@ -20,11 +20,11 @@ namespace Metal { public: explicit AbstractPanel(); - std::vector &getChildren(); + std::vector &getChildren(); void appendChild(AbstractPanel *panel); - void removeAllChildren() override; + void removeAllChildren(); virtual void onRemove() { } diff --git a/src/editor/abstract/IPanel.h b/src/editor/abstract/IPanel.h deleted file mode 100644 index 48dfc868..00000000 --- a/src/editor/abstract/IPanel.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef METAL_ENGINE_IPANEL_H -#define METAL_ENGINE_IPANEL_H - -#include "../../common/ISync.h" -#include "../../common/IInit.h" - -namespace Metal { - class IPanel : public ISync, public IInit { - public: - virtual void removeAllChildren() { - } - }; -} -#endif diff --git a/src/editor/abstract/form/AbstractFormFieldPanel.h b/src/editor/abstract/form/AbstractFormFieldPanel.h index 4ab21a41..bfdb7f1f 100644 --- a/src/editor/abstract/form/AbstractFormFieldPanel.h +++ b/src/editor/abstract/form/AbstractFormFieldPanel.h @@ -6,10 +6,20 @@ #include "../AbstractPanel.h" namespace Metal { + class ThemeService; + class AbstractFormFieldPanel : public AbstractPanel { protected: const std::string* filter = nullptr; + + ThemeService *themeService = nullptr; public: + + std::vector getDependencies() override { + return { + {"ThemeService", themeService} + }; + } [[nodiscard]] virtual bool isVisible() const = 0; void onSyncChildren() const override { diff --git a/src/editor/abstract/form/AccordionPanel.cpp b/src/editor/abstract/form/AccordionPanel.cpp index 0efd891e..bb3789a2 100644 --- a/src/editor/abstract/form/AccordionPanel.cpp +++ b/src/editor/abstract/form/AccordionPanel.cpp @@ -1,6 +1,7 @@ #include "AccordionPanel.h" #include "imgui.h" #include "../../../ApplicationContext.h" +#include "../../service/ThemeService.h" namespace Metal { void AccordionPanel::setTitle(const std::string &t) { @@ -14,7 +15,7 @@ namespace Metal { return; } - ImGui::PushStyleColor(ImGuiCol_Header, applicationContext->themeService.neutralPalette); + ImGui::PushStyleColor(ImGuiCol_Header, themeService->neutralPalette); bool open = ImGui::CollapsingHeader(fixedId.c_str(), ImGuiTreeNodeFlags_None); ImGui::PopStyleColor(); diff --git a/src/editor/abstract/form/AccordionPanel.h b/src/editor/abstract/form/AccordionPanel.h index b161a2a4..65a787e4 100644 --- a/src/editor/abstract/form/AccordionPanel.h +++ b/src/editor/abstract/form/AccordionPanel.h @@ -4,12 +4,13 @@ #include "AbstractFormFieldPanel.h" namespace Metal { + class ThemeService; + class AccordionPanel final : public AbstractFormFieldPanel { std::string fixedId = id; std::string title; public: - void setTitle(const std::string &title); void onSync() override; diff --git a/src/editor/abstract/form/ChildPanel.cpp b/src/editor/abstract/form/ChildPanel.cpp index aaf611b5..498c3971 100644 --- a/src/editor/abstract/form/ChildPanel.cpp +++ b/src/editor/abstract/form/ChildPanel.cpp @@ -1,6 +1,7 @@ #include "ChildPanel.h" #include "imgui.h" #include "../../../ApplicationContext.h" +#include "../../service/ThemeService.h" namespace Metal { void ChildPanel::setTitle(const std::string &t) { @@ -9,7 +10,7 @@ namespace Metal { } void ChildPanel::onSync() { - ImGui::PushStyleColor(ImGuiCol_ChildBg, applicationContext->themeService.palette0); + ImGui::PushStyleColor(ImGuiCol_ChildBg, themeService->palette0); if (!title.empty()) { ImGui::Spacing(); ImGui::Text(title.c_str()); diff --git a/src/editor/abstract/form/types/ResourceField.cpp b/src/editor/abstract/form/types/ResourceField.cpp index 3b06c714..ba761c59 100644 --- a/src/editor/abstract/form/types/ResourceField.cpp +++ b/src/editor/abstract/form/types/ResourceField.cpp @@ -9,6 +9,7 @@ #include "../../../dto/FSEntry.h" #include "../../../../ApplicationContext.h" #include "../../../../common/Inspectable.h" +#include "../../../service/FilesService.h" namespace Metal { constexpr ImGuiWindowFlags flags = ImGuiWindowFlags_NoDocking | @@ -79,7 +80,7 @@ namespace Metal { void ResourceField::onSync() { if (field.field->size() > 0 && (entry == nullptr || entry->getId() != *field.field)) { - entry = applicationContext->filesService.getResource(*field.field); + entry = filesService->getResource(*field.field); } if (!field.disabled) { renderButton(); diff --git a/src/editor/abstract/form/types/ResourceField.h b/src/editor/abstract/form/types/ResourceField.h index 8126a42e..92b8a23b 100644 --- a/src/editor/abstract/form/types/ResourceField.h +++ b/src/editor/abstract/form/types/ResourceField.h @@ -8,14 +8,20 @@ #include "imgui.h" namespace Metal { + class FilesService; struct FSEntry; class ResourceField final : public AbstractFormFieldPanel { InspectedField &field; std::unique_ptr entry = nullptr; mutable bool open = false; + FilesService *filesService = nullptr; public: + std::vector getDependencies() override { + return {{"FilesService", filesService}}; + } + void onInitialize() override; void renderButton(); diff --git a/src/editor/abstract/form/types/ResourceFilesPanel.cpp b/src/editor/abstract/form/types/ResourceFilesPanel.cpp index cf3e6196..b32d295c 100644 --- a/src/editor/abstract/form/types/ResourceFilesPanel.cpp +++ b/src/editor/abstract/form/types/ResourceFilesPanel.cpp @@ -18,7 +18,7 @@ namespace Metal { void ResourceFilesPanel::openResource(FSEntry *root) { if (root->type == EntryType::DIRECTORY) { filesContext.setCurrentDirectory(root); - FilesService::GetEntries(root); + filesService->GetEntries(root); filesContext.selected.clear(); } else { callback(root); diff --git a/src/editor/abstract/form/types/StringField.cpp b/src/editor/abstract/form/types/StringField.cpp index 9f07b8b2..0a24e84a 100644 --- a/src/editor/abstract/form/types/StringField.cpp +++ b/src/editor/abstract/form/types/StringField.cpp @@ -9,7 +9,7 @@ namespace Metal { void StringField::onSync() { if (!field.disabled) { - strcpy(buffer, field.field->c_str()); + strcpy_s(buffer, sizeof(buffer), field.field->c_str()); ImGui::Text(field.name.c_str()); if (ImGui::InputText(field.id.c_str(), buffer, sizeof(buffer))) { *field.field = buffer; diff --git a/src/editor/dock-spaces/docks/DockSpacePanel.cpp b/src/editor/dock-spaces/docks/DockSpacePanel.cpp index 3c0b6cd2..c77db728 100644 --- a/src/editor/dock-spaces/docks/DockSpacePanel.cpp +++ b/src/editor/dock-spaces/docks/DockSpacePanel.cpp @@ -9,6 +9,8 @@ #include "../../dto/DockDTO.h" #include "../../util/UIUtil.h" #include "../../../common/LoggerUtil.h" +#include "../../repository/EditorRepository.h" +#include "../../service/ThemeService.h" namespace Metal { const ImVec2 DockSpacePanel::DEFAULT{-1.f, -1.f}; @@ -52,13 +54,13 @@ namespace Metal { if (view != nullptr) { const bool isHovered = ImGui::IsWindowHovered(ImGuiHoveredFlags_RootAndChildWindows); if (isHovered) { - applicationContext->editorRepository.focusedShortcuts = view->getShortcuts(); - applicationContext->editorRepository.focusedWindowName = view->dock->name; + editorRepository->focusedShortcuts = view->getShortcuts(); + editorRepository->focusedWindowName = view->dock->name; } view->isWindowFocused = isHovered; if (view->isWindowFocused) { - for (const auto &shortcut: applicationContext->editorRepository.focusedShortcuts) { + for (const auto &shortcut: editorRepository->focusedShortcuts) { if (ImGui::IsKeyChordPressed(shortcut.keyChord)) { LOG_INFO("Action called: " + shortcut.name); shortcut.callback(); @@ -116,7 +118,7 @@ namespace Metal { ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, headerPadding); const bool isFocused = ImGui::IsWindowFocused(ImGuiFocusedFlags_RootAndChildWindows); ImGui::PushStyleColor(ImGuiCol_TabActive, - isFocused ? applicationContext->editorRepository.accent : applicationContext->themeService.palette0); + isFocused ? editorRepository->accent : themeService->palette0); if (ImGui::BeginTabBar((id + "dockTabs").c_str(), ImGuiTabBarFlags_AutoSelectNewTabs)) { for (auto *space: dock->dockSpaces) { diff --git a/src/editor/dock-spaces/docks/DockSpacePanel.h b/src/editor/dock-spaces/docks/DockSpacePanel.h index 56658704..bc89e743 100644 --- a/src/editor/dock-spaces/docks/DockSpacePanel.h +++ b/src/editor/dock-spaces/docks/DockSpacePanel.h @@ -11,6 +11,8 @@ namespace Metal { struct DockDTO; struct DockSpace; class AbstractDockPanel; + struct EditorRepository; + class ThemeService; class DockSpacePanel final : public AbstractPanel { ImVec2 padding{DEFAULT.x, DEFAULT.y}; @@ -26,11 +28,21 @@ namespace Metal { std::unordered_map views{}; ImVec2 headerPadding{0, 3}; + EditorRepository *editorRepository = nullptr; + ThemeService *themeService = nullptr; + DockSpace *getSelectedDockSpace() const; bool hasDockSpace(int index) const; public: + std::vector getDependencies() override { + return { + {"EditorRepository", editorRepository}, + {"ThemeService", themeService} + }; + } + static constexpr int FLAGS = ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_MenuBar; static const ImVec2 DEFAULT; static const ImVec2 MAX_SIZE; diff --git a/src/editor/dock-spaces/files/FilePreviewPanel.cpp b/src/editor/dock-spaces/files/FilePreviewPanel.cpp index 143aa77a..f94c1c71 100644 --- a/src/editor/dock-spaces/files/FilePreviewPanel.cpp +++ b/src/editor/dock-spaces/files/FilePreviewPanel.cpp @@ -4,6 +4,8 @@ #include "../../dto/FSEntry.h" #include "../../../ApplicationContext.h" #include "../../../engine/resource/TextureInstance.h" +#include "../../../engine/service/TextureService.h" +#include "../../../core/gui/GuiContext.h" namespace Metal { FilePreviewPanel::FilePreviewPanel(FilesContext &filesContext) : filesContext(filesContext) { @@ -21,7 +23,7 @@ namespace Metal { ImGui::Separator(); if (selected->type == EntryType::TEXTURE) { - auto *texture = applicationContext->textureService.stream(selected->getId()); + auto *texture = textureService->stream(selected->getId()); if (texture != nullptr) { float availWidth = ImGui::GetContentRegionAvail().x; float availHeight = ImGui::GetContentRegionAvail().y * 0.6f; // reserve space for table @@ -41,7 +43,7 @@ namespace Metal { float offsetX = (availWidth - renderWidth) * 0.5f; if (offsetX > 0) ImGui::SetCursorPosX(ImGui::GetCursorPosX() + offsetX); - applicationContext->guiContext.renderImage(texture, renderWidth, renderHeight); + guiContext->renderImage(texture, renderWidth, renderHeight); ImGui::Separator(); } } diff --git a/src/editor/dock-spaces/files/FilePreviewPanel.h b/src/editor/dock-spaces/files/FilePreviewPanel.h index 689ac058..b539a00a 100644 --- a/src/editor/dock-spaces/files/FilePreviewPanel.h +++ b/src/editor/dock-spaces/files/FilePreviewPanel.h @@ -5,10 +5,23 @@ #include "FilesContext.h" namespace Metal { + class TextureService; + class GuiContext; + class FilePreviewPanel final : public AbstractPanel { FilesContext &filesContext; + TextureService *textureService = nullptr; + GuiContext *guiContext = nullptr; + public: + std::vector getDependencies() override { + return { + {"TextureService", textureService}, + {"GuiContext", guiContext} + }; + } + explicit FilePreviewPanel(FilesContext &filesContext); void onSync() override; diff --git a/src/editor/dock-spaces/files/FilesHeaderPanel.cpp b/src/editor/dock-spaces/files/FilesHeaderPanel.cpp index a81e2751..d687da19 100644 --- a/src/editor/dock-spaces/files/FilesHeaderPanel.cpp +++ b/src/editor/dock-spaces/files/FilesHeaderPanel.cpp @@ -4,14 +4,15 @@ #include "../../dto/FSEntry.h" #include "../../../common/Icons.h" #include "../../../ApplicationContext.h" +#include "../../service/FilesService.h" #include "../../util/UIUtil.h" namespace Metal { void FilesHeaderPanel::onSync() { if (UIUtil::ButtonSimple(Icons::create_new_folder + id, UIUtil::ONLY_ICON_BUTTON_SIZE, UIUtil::ONLY_ICON_BUTTON_SIZE)) { - FilesService::CreateDirectory(filesContext.currentDirectory); - FilesService::GetEntries(filesContext.currentDirectory); + filesService->CreateDirectory(filesContext.currentDirectory); + filesService->GetEntries(filesContext.currentDirectory); } UIUtil::RenderTooltip("Create folder"); ImGui::SameLine(); @@ -26,7 +27,7 @@ namespace Metal { ImGui::SameLine(); if (UIUtil::ButtonSimple(Icons::refresh, UIUtil::ONLY_ICON_BUTTON_SIZE, UIUtil::ONLY_ICON_BUTTON_SIZE)) { - FilesService::GetEntries(filesContext.currentDirectory); + filesService->GetEntries(filesContext.currentDirectory); } UIUtil::RenderTooltip("Refresh"); diff --git a/src/editor/dock-spaces/files/FilesHeaderPanel.h b/src/editor/dock-spaces/files/FilesHeaderPanel.h index ecc11c54..479e7235 100644 --- a/src/editor/dock-spaces/files/FilesHeaderPanel.h +++ b/src/editor/dock-spaces/files/FilesHeaderPanel.h @@ -6,13 +6,21 @@ #include "../../abstract/AbstractPanel.h" namespace Metal { + class FilesService; + class FilesHeaderPanel final : public AbstractPanel { FilesContext &filesContext; std::string actionLabel; std::function action; + FilesService *filesService = nullptr; + public: + std::vector getDependencies() override { + return {{"FilesService", filesService}}; + } + explicit FilesHeaderPanel(FilesContext &files_context, const std::string &actionLabel, - std::function action) + std::function action) : filesContext(files_context), actionLabel(actionLabel), action(std::move(action)) { } diff --git a/src/editor/dock-spaces/files/FilesListPanel.cpp b/src/editor/dock-spaces/files/FilesListPanel.cpp index 56229939..068b328f 100644 --- a/src/editor/dock-spaces/files/FilesListPanel.cpp +++ b/src/editor/dock-spaces/files/FilesListPanel.cpp @@ -89,7 +89,7 @@ namespace Metal { if (!ImGui::IsMouseDown(ImGuiMouseButton_Left) && onDrag != nullptr && fileEntry->type == EntryType::DIRECTORY) { - applicationContext->filesService.Move(onDrag, fileEntry); + filesService->Move(onDrag, fileEntry); onDrag = nullptr; } } @@ -211,7 +211,7 @@ namespace Metal { if (isDirectory && open) { if (!loadedDirectoryPaths.contains(entry->absolutePath)) { - FilesService::GetEntries(entry); + filesService->GetEntries(entry); loadedDirectoryPaths.insert(entry->absolutePath); } // After loading, children may change; keep original iteration order to avoid infinite recursion here. @@ -277,11 +277,11 @@ namespace Metal { } if (ImGui::MenuItem("Paste")) { filesContext.toCut.clear(); - FilesService::GetEntries(filesContext.currentDirectory); + filesService->GetEntries(filesContext.currentDirectory); } if (ImGui::MenuItem("Delete")) { - applicationContext->filesService.deleteFiles(filesContext.selected); - FilesService::GetEntries(filesContext.currentDirectory); + filesService->deleteFiles(filesContext.selected); + filesService->GetEntries(filesContext.currentDirectory); } ImGui::Separator(); if (ImGui::MenuItem("Select all")) { diff --git a/src/editor/dock-spaces/files/FilesListPanel.h b/src/editor/dock-spaces/files/FilesListPanel.h index 1bf8dd21..9ebd6e44 100644 --- a/src/editor/dock-spaces/files/FilesListPanel.h +++ b/src/editor/dock-spaces/files/FilesListPanel.h @@ -10,6 +10,7 @@ namespace Metal { struct FSEntry; + class FilesService; class FilesListPanel final : public AbstractPanel { FilesContext &filesContext; @@ -27,6 +28,8 @@ namespace Metal { std::function onDoubleClick; + FilesService *filesService = nullptr; + void ensureCache(); void applySort(); @@ -45,9 +48,15 @@ namespace Metal { void renderTreeItem(FSEntry *entry); public: - explicit FilesListPanel(FilesContext &applicationContext-> std::function onDoubleClick, + std::vector getDependencies() override { + return { + {"FilesService", filesService} + }; + } + + explicit FilesListPanel(FilesContext &filesContext, std::function onDoubleClick, EntryType::EntryType typeFilter) - : filesContext(applicationContext->, typeFilter(typeFilter), onDoubleClick(std::move(onDoubleClick)) { + : filesContext(filesContext), typeFilter(typeFilter), onDoubleClick(std::move(onDoubleClick)) { } void onSync() override; diff --git a/src/editor/dock-spaces/files/FilesPanel.cpp b/src/editor/dock-spaces/files/FilesPanel.cpp index 7f772d6c..91316c83 100644 --- a/src/editor/dock-spaces/files/FilesPanel.cpp +++ b/src/editor/dock-spaces/files/FilesPanel.cpp @@ -1,22 +1,23 @@ #include "FilesPanel.h" - - #include "FilesHeaderPanel.h" #include "FilesListPanel.h" #include "../../../common/Icons.h" -#include "../../../ApplicationContext.h" -#include "../../dto/SceneData.h" #include "../../util/UIUtil.h" #include "../../dto/FSEntry.h" #include "../../dto/SceneImportSettingsDTO.h" #include "FilesContext.h" #include "../../../common/FileDialogUtil.h" - #include "FilePreviewPanel.h" -#include "../../abstract/form/FormPanel.h" #include #include #include "../../../common/FilesUtil.h" +#include "../../service/FileImporterService.h" +#include "../../repository/EditorRepository.h" +#include "../../service/SceneImporterService.h" +#include "../../service/FilesService.h" +#include "../../service/NotificationService.h" +#include "../../../engine/repository/WorldRepository.h" +#include "../../../engine/service/VoxelService.h" namespace Metal { std::string FilesPanel::getActionLabel() { @@ -28,27 +29,27 @@ namespace Metal { auto files = FileDialogUtil::PickFiles({ { "Files", - applicationContext->fileImporterService.collectCompatibleFiles().c_str(), + fileImporterService->collectCompatibleFiles().c_str(), } }); if (!files.empty()) { - applicationContext->editorRepository.pendingImports = files; - applicationContext->editorRepository.importSettingsMap.clear(); - for (const auto& file : applicationContext->editorRepository.pendingImports) { - if (applicationContext->sceneImporterService.isCompatible(file)) { - applicationContext->editorRepository.importSettingsMap.emplace(file, std::make_shared()); + editorRepository->pendingImports = files; + editorRepository->importSettingsMap.clear(); + for (const auto& file : editorRepository->pendingImports) { + if (sceneImporterService->isCompatible(file)) { + editorRepository->importSettingsMap.emplace(file, std::make_shared()); } else { - applicationContext->editorRepository.importSettingsMap.emplace(file, std::make_shared()); + editorRepository->importSettingsMap.emplace(file, std::make_shared()); } } - applicationContext->editorRepository.selectedFileForSettings = applicationContext->editorRepository.pendingImports[0]; - applicationContext->editorRepository.targetImportDirectory = filesContext.currentDirectory; + editorRepository->selectedFileForSettings = editorRepository->pendingImports[0]; + editorRepository->targetImportDirectory = filesContext.currentDirectory; } }; } void FilesPanel::onInitialize() { - filesContext.setCurrentDirectory(applicationContext->filesService.getRoot()); + filesContext.setCurrentDirectory(filesService->getRoot()); appendChild(filesHeader = new FilesHeaderPanel(filesContext, getActionLabel(), onAction())); filesListPanel = new FilesListPanel( filesContext, [ @@ -124,23 +125,23 @@ namespace Metal { void FilesPanel::openResource(FSEntry *root) { switch (root->type) { case EntryType::SCENE: { - applicationContext->notificationService.pushMessage("Loading scene", NotificationSeverities::SUCCESS); - applicationContext->worldRepository.loadScene(root->getId()); + notificationService->pushMessage("Loading scene", NotificationSeverities::SUCCESS); + worldRepository->loadScene(root->getId()); break; } case EntryType::VOLUME: { - applicationContext->notificationService.pushMessage("Loading volume", NotificationSeverities::SUCCESS); - applicationContext->voxelService.create(root->getId()); + notificationService->pushMessage("Loading volume", NotificationSeverities::SUCCESS); + voxelService->create(root->getId()); break; } case EntryType::DIRECTORY: { filesContext.setCurrentDirectory(root); - FilesService::GetEntries(root); + filesService->GetEntries(root); filesContext.selected.clear(); break; } default: - applicationContext->notificationService.pushMessage("Unsupported resource type", NotificationSeverities::ERROR); + notificationService->pushMessage("Unsupported resource type", NotificationSeverities::ERROR); break; } } @@ -150,7 +151,7 @@ namespace Metal { // } filesContext.toCut.clear(); - FilesService::GetEntries(filesContext.currentDirectory); + filesService->GetEntries(filesContext.currentDirectory); } void FilesPanel::openSelected() { @@ -162,7 +163,7 @@ namespace Metal { void FilesPanel::cutSelected() { filesContext.toCut.clear(); filesContext.toCut = filesContext.selected; - FilesService::GetEntries(filesContext.currentDirectory); + filesService->GetEntries(filesContext.currentDirectory); } void FilesPanel::selectAll() { @@ -174,7 +175,7 @@ namespace Metal { } void FilesPanel::deleteSelected() const { - applicationContext->filesService.deleteFiles(filesContext.selected); - FilesService::GetEntries(filesContext.currentDirectory); + filesService->deleteFiles(filesContext.selected); + filesService->GetEntries(filesContext.currentDirectory); } } diff --git a/src/editor/dock-spaces/files/FilesPanel.h b/src/editor/dock-spaces/files/FilesPanel.h index ea127a9f..2c90c3a1 100644 --- a/src/editor/dock-spaces/files/FilesPanel.h +++ b/src/editor/dock-spaces/files/FilesPanel.h @@ -12,6 +12,13 @@ namespace Metal { struct FSEntry; class FilePreviewPanel; class FormPanel; + class FileImporterService; + struct EditorRepository; + class SceneImporterService; + class FilesService; + class NotificationService; + struct WorldRepository; + class VoxelService; class FilesPanel : public AbstractDockPanel { protected: @@ -21,7 +28,27 @@ namespace Metal { AbstractPanel *filesListPanel = nullptr; float previewWidth = 200.0f; + FileImporterService *fileImporterService = nullptr; + EditorRepository *editorRepository = nullptr; + SceneImporterService *sceneImporterService = nullptr; + FilesService *filesService = nullptr; + NotificationService *notificationService = nullptr; + WorldRepository *worldRepository = nullptr; + VoxelService *voxelService = nullptr; + public: + std::vector getDependencies() override { + return { + {"FileImporterService", fileImporterService}, + {"EditorRepository", editorRepository}, + {"SceneImporterService", sceneImporterService}, + {"FilesService", filesService}, + {"NotificationService", notificationService}, + {"WorldRepository", worldRepository}, + {"VoxelService", voxelService} + }; + } + virtual bool renderPreview() { return true; } diff --git a/src/editor/dock-spaces/footer/EditorFooterPanel.cpp b/src/editor/dock-spaces/footer/EditorFooterPanel.cpp index c754ab52..d8336424 100644 --- a/src/editor/dock-spaces/footer/EditorFooterPanel.cpp +++ b/src/editor/dock-spaces/footer/EditorFooterPanel.cpp @@ -1,6 +1,7 @@ #include "EditorFooterPanel.h" #include "../../util/UIUtil.h" #include "../../../ApplicationContext.h" +#include "../../repository/EditorRepository.h" namespace Metal { void EditorFooterPanel::onSync() { @@ -17,11 +18,11 @@ namespace Metal { } void EditorFooterPanel::renderShortcuts() { - auto &shortcuts = applicationContext->editorRepository.focusedShortcuts; + auto &shortcuts = editorRepository->focusedShortcuts; if (shortcuts.empty()) return; ImGui::SetCursorPosY(ImGui::GetCursorPosY() + 5); // Some padding - ImGui::Text(applicationContext->editorRepository.focusedWindowName.c_str()); + ImGui::Text(editorRepository->focusedWindowName.c_str()); ImGui::SameLine(); std::string label; for (size_t i = 0; i < std::min(shortcuts.size(), size_t(3)); ++i) { diff --git a/src/editor/dock-spaces/footer/EditorFooterPanel.h b/src/editor/dock-spaces/footer/EditorFooterPanel.h index 257b12bd..372c6119 100644 --- a/src/editor/dock-spaces/footer/EditorFooterPanel.h +++ b/src/editor/dock-spaces/footer/EditorFooterPanel.h @@ -4,11 +4,21 @@ #include "../../abstract/AbstractPanel.h" namespace Metal { + struct EditorRepository; + class EditorFooterPanel final : public AbstractPanel { + EditorRepository *editorRepository = nullptr; + void renderShortcuts(); static void framerate(); public: + std::vector getDependencies() override { + return { + {"EditorRepository", editorRepository} + }; + } + void onSync() override; }; } diff --git a/src/editor/dock-spaces/header/AsyncTaskPanel.cpp b/src/editor/dock-spaces/header/AsyncTaskPanel.cpp index fba2a231..616fc37b 100644 --- a/src/editor/dock-spaces/header/AsyncTaskPanel.cpp +++ b/src/editor/dock-spaces/header/AsyncTaskPanel.cpp @@ -2,10 +2,12 @@ #include "../../../ApplicationContext.h" #include "../../util/UIUtil.h" #include +#include "../../service/AsyncTaskService.h" +#include "../../dto/AsyncTask.h" namespace Metal { void AsyncTaskPanel::onSync() { - auto tasks = applicationContext->asyncTaskService.getActiveTasks(); + auto tasks = asyncTaskService->getActiveTasks(); if (tasks.empty()) { UIUtil::DynamicSpacing(90); return; @@ -56,7 +58,7 @@ namespace Metal { ImGui::SameLine(); if (ImGui::Button((Icons::close + "##" + task->id).c_str(), ImVec2(UIUtil::ONLY_ICON_BUTTON_SIZE, UIUtil::ONLY_ICON_BUTTON_SIZE))) { - applicationContext->asyncTaskService.endTask(task->id, true); + asyncTaskService->endTask(task->id, true); } ImGui::EndGroup(); } diff --git a/src/editor/dock-spaces/header/AsyncTaskPanel.h b/src/editor/dock-spaces/header/AsyncTaskPanel.h index c1e09daf..640dee30 100644 --- a/src/editor/dock-spaces/header/AsyncTaskPanel.h +++ b/src/editor/dock-spaces/header/AsyncTaskPanel.h @@ -4,8 +4,18 @@ #include "../../abstract/AbstractPanel.h" namespace Metal { + class AsyncTaskService; + class AsyncTaskPanel final : public AbstractPanel { + AsyncTaskService *asyncTaskService = nullptr; + public: + std::vector getDependencies() override { + return { + {"AsyncTaskService", asyncTaskService} + }; + } + void onSync() override; }; } diff --git a/src/editor/dock-spaces/header/EditorHeaderPanel.cpp b/src/editor/dock-spaces/header/EditorHeaderPanel.cpp index 5c5fac77..1bca0433 100644 --- a/src/editor/dock-spaces/header/EditorHeaderPanel.cpp +++ b/src/editor/dock-spaces/header/EditorHeaderPanel.cpp @@ -2,6 +2,9 @@ #include "AsyncTaskPanel.h" #include "../../util/UIUtil.h" #include "../../../ApplicationContext.h" +#include "../../../core/DirectoryService.h" +#include "../../../core/glfw/GLFWContext.h" +#include "../../../engine/EngineContext.h" namespace Metal { void EditorHeaderPanel::onSync() { @@ -13,7 +16,7 @@ namespace Metal { // Window dragging logic if (ImGui::IsWindowHovered() && ImGui::IsMouseDragging(ImGuiMouseButton_Left)) { ImVec2 delta = ImGui::GetIO().MouseDelta; - GLFWwindow* window = applicationContext->glfwContext.getWindow(); + GLFWwindow* window = glfwContext->getWindow(); int x, y; glfwGetWindowPos(window, &x, &y); glfwSetWindowPos(window, x + (int)delta.x, y + (int)delta.y); @@ -23,7 +26,7 @@ namespace Metal { void EditorHeaderPanel::renderWindowControls() { ImGui::SameLine(ImGui::GetWindowWidth() - (UIUtil::ONLY_ICON_BUTTON_SIZE * 3 + 10)); - GLFWwindow* window = applicationContext->glfwContext.getWindow(); + GLFWwindow* window = glfwContext->getWindow(); if (UIUtil::ButtonSimple(Icons::minimize, UIUtil::ONLY_ICON_BUTTON_SIZE, UIUtil::ONLY_ICON_BUTTON_SIZE)) { glfwIconifyWindow(window); @@ -48,16 +51,16 @@ namespace Metal { void EditorHeaderPanel::renderFileTab() { if (ImGui::BeginMainMenuBar()) { if (UIUtil::ButtonSimple(Icons::save, UIUtil::ONLY_ICON_BUTTON_SIZE, UIUtil::ONLY_ICON_BUTTON_SIZE)) { - applicationContext->save(); + directoryService->save(); } ImGui::SameLine(); if (ImGui::BeginMenu("File")) { if (ImGui::MenuItem("Open", "Ctrl+O")) { - applicationContext->engineContext.dispose(); - applicationContext->updateRootPath(true); + engineContext->dispose(); + directoryService->updateRootPath(true); } if (ImGui::MenuItem("Save", "Ctrl+S")) { - applicationContext->save(); + directoryService->save(); } ImGui::Separator(); if (ImGui::MenuItem("Exit")) { @@ -69,7 +72,7 @@ namespace Metal { // Create an "Edit" menu if (ImGui::BeginMenu("Edit")) { if (ImGui::MenuItem("Compile shaders")) { - applicationContext->engineContext.dispose(); + engineContext->dispose(); // TODO - CREATE NEW FRAME } ImGui::EndMenu(); diff --git a/src/editor/dock-spaces/header/EditorHeaderPanel.h b/src/editor/dock-spaces/header/EditorHeaderPanel.h index 75f2f184..412ae9a6 100644 --- a/src/editor/dock-spaces/header/EditorHeaderPanel.h +++ b/src/editor/dock-spaces/header/EditorHeaderPanel.h @@ -4,14 +4,30 @@ #include "../../abstract/AbstractPanel.h" namespace Metal { + class GLFWContext; + class EngineContext; + struct DirectoryService; + class EditorHeaderPanel final : public AbstractPanel { AbstractPanel *asyncTask = nullptr; + GLFWContext *glfwContext = nullptr; + EngineContext *engineContext = nullptr; + DirectoryService *directoryService = nullptr; + void renderFileTab(); void renderWindowControls(); public: + std::vector getDependencies() override { + return { + {"GLFWContext", glfwContext}, + {"EngineContext", engineContext}, + {"DirectoryService", directoryService} + }; + } + void onInitialize() override; void onSync() override; diff --git a/src/editor/dock-spaces/inspector/InspectorPanel.cpp b/src/editor/dock-spaces/inspector/InspectorPanel.cpp index bee24e34..adef54bd 100644 --- a/src/editor/dock-spaces/inspector/InspectorPanel.cpp +++ b/src/editor/dock-spaces/inspector/InspectorPanel.cpp @@ -1,5 +1,4 @@ #include "InspectorPanel.h" - #include "../../abstract/form/FormPanel.h" #include "../../util/UIUtil.h" #include "../../../common/Inspectable.h" @@ -7,6 +6,8 @@ #include "../../../engine/dto/MetadataComponent.h" #include #include +#include "../../repository/EditorRepository.h" +#include "../../../engine/repository/WorldRepository.h" namespace Metal { void InspectorPanel::onInitialize() { @@ -26,11 +27,11 @@ namespace Metal { if (ImGui::BeginPopup((id + "AddComponentPopup").c_str())) { for (const auto &compDef: ComponentTypes::getComponents()) { - bool hasComponent = compDef.getInspectable(applicationContext->worldRepository, selectedId) != nullptr; + bool hasComponent = compDef.getInspectable(*worldRepository, selectedId) != nullptr; if (!hasComponent) { if (ImGui::MenuItem( (compDef.icon + " " + compDef.name + id + "adCOmp" + compDef.name).c_str())) { - applicationContext->worldRepository.createComponent(selectedId, compDef.type); + worldRepository->createComponent(selectedId, compDef.type); selectedId = EMPTY_ENTITY; tick(); } @@ -42,20 +43,17 @@ namespace Metal { } void InspectorPanel::tick() { - if (auto &editorRepository = applicationContext->editorRepository; - editorRepository.mainSelection != selectedId) { + if (editorRepository->mainSelection != selectedId) { additionalInspection.clear(); - selectedId = editorRepository.mainSelection; + selectedId = editorRepository->mainSelection; formPanel->resetForm(); if (selectedId != EMPTY_ENTITY) { - auto &repo = applicationContext->worldRepository; - - selectedEntity = repo.getEntity(selectedId); + selectedEntity = worldRepository->getEntity(selectedId); if (selectedEntity != nullptr) { additionalInspection.push_back(selectedEntity); for (const auto &compDef: ComponentTypes::getComponents()) { - if (Inspectable *inspectable = compDef.getInspectable(repo, selectedId)) { + if (Inspectable *inspectable = compDef.getInspectable(*worldRepository, selectedId)) { additionalInspection.push_back(inspectable); } } diff --git a/src/editor/dock-spaces/inspector/InspectorPanel.h b/src/editor/dock-spaces/inspector/InspectorPanel.h index 69a3c411..cf8a1bf6 100644 --- a/src/editor/dock-spaces/inspector/InspectorPanel.h +++ b/src/editor/dock-spaces/inspector/InspectorPanel.h @@ -7,6 +7,8 @@ namespace Metal { class FormPanel; class Inspectable; + struct EditorRepository; + struct WorldRepository; class InspectorPanel final : public AbstractDockPanel { std::vector additionalInspection{}; @@ -15,7 +17,17 @@ namespace Metal { FormPanel *formPanel = nullptr; entt::entity selectedId = EMPTY_ENTITY; + EditorRepository *editorRepository = nullptr; + WorldRepository *worldRepository = nullptr; + public: + std::vector getDependencies() override { + return { + {"EditorRepository", editorRepository}, + {"WorldRepository", worldRepository} + }; + } + void onInitialize() override; void onSync() override; diff --git a/src/editor/dock-spaces/metrics/MetricsPanel.cpp b/src/editor/dock-spaces/metrics/MetricsPanel.cpp index f478554a..7e8bd984 100644 --- a/src/editor/dock-spaces/metrics/MetricsPanel.cpp +++ b/src/editor/dock-spaces/metrics/MetricsPanel.cpp @@ -1,6 +1,12 @@ #include "MetricsPanel.h" #include "../../../ApplicationContext.h" #include "imgui.h" +#include "../../../engine/service/MeshService.h" +#include "../../../engine/service/VoxelService.h" +#include "../../../engine/service/FrameBufferService.h" +#include "../../../engine/service/TextureService.h" +#include "../../../engine/service/PipelineService.h" +#include "../../../engine/service/BufferService.h" namespace Metal { template @@ -22,11 +28,11 @@ namespace Metal { } void MetricsPanel::onSync() { - drawResourceList("Meshes", applicationContext->meshService, id); - drawResourceList("Voxels", applicationContext->voxelService, id); - drawResourceList("Framebuffers", applicationContext->framebufferService, id); - drawResourceList("Textures", applicationContext->textureService, id); - drawResourceList("Pipelines", applicationContext->pipelineService, id); - drawResourceList("Buffers", applicationContext->bufferService, id); + if (meshService) drawResourceList("Meshes", *meshService, id); + if (voxelService) drawResourceList("Voxels", *voxelService, id); + if (framebufferService) drawResourceList("Framebuffers", *framebufferService, id); + if (textureService) drawResourceList("Textures", *textureService, id); + if (pipelineService) drawResourceList("Pipelines", *pipelineService, id); + if (bufferService) drawResourceList("Buffers", *bufferService, id); } } diff --git a/src/editor/dock-spaces/metrics/MetricsPanel.h b/src/editor/dock-spaces/metrics/MetricsPanel.h index 0f133b5a..e81e1e6c 100644 --- a/src/editor/dock-spaces/metrics/MetricsPanel.h +++ b/src/editor/dock-spaces/metrics/MetricsPanel.h @@ -5,8 +5,33 @@ #include "imgui.h" namespace Metal { + class MeshService; + class VoxelService; + class FrameBufferService; + class TextureService; + class PipelineService; + class BufferService; + class MetricsPanel final : public AbstractDockPanel { + MeshService *meshService = nullptr; + VoxelService *voxelService = nullptr; + FrameBufferService *framebufferService = nullptr; + TextureService *textureService = nullptr; + PipelineService *pipelineService = nullptr; + BufferService *bufferService = nullptr; + public: + std::vector getDependencies() override { + return { + {"MeshService", meshService}, + {"VoxelService", voxelService}, + {"FrameBufferService", framebufferService}, + {"TextureService", textureService}, + {"PipelineService", pipelineService}, + {"BufferService", bufferService} + }; + } + void onSync() override; }; } diff --git a/src/editor/dock-spaces/repositories/RepositoriesPanel.cpp b/src/editor/dock-spaces/repositories/RepositoriesPanel.cpp index fff6ec87..4c6bc533 100644 --- a/src/editor/dock-spaces/repositories/RepositoriesPanel.cpp +++ b/src/editor/dock-spaces/repositories/RepositoriesPanel.cpp @@ -2,15 +2,19 @@ #include "../../abstract/form/FormPanel.h" #include "../../../ApplicationContext.h" #include "../../../common/Inspectable.h" +#include "../../repository/EditorRepository.h" +#include "../../../engine/repository/EngineRepository.h" +#include "../../../engine/repository/WorldRepository.h" +#include "../../../engine/dto/Camera.h" namespace Metal { void RepositoriesPanel::onInitialize() { formPanel = new FormPanel(); appendChild(formPanel); - repositories.push_back(&applicationContext->editorRepository); - repositories.push_back(&applicationContext->engineRepository); - repositories.push_back(&applicationContext->worldRepository.camera); + repositories.push_back(editorRepository); + repositories.push_back(engineRepository); + repositories.push_back(&worldRepository->camera); } void RepositoriesPanel::onSync() { diff --git a/src/editor/dock-spaces/repositories/RepositoriesPanel.h b/src/editor/dock-spaces/repositories/RepositoriesPanel.h index b566b984..6121111c 100644 --- a/src/editor/dock-spaces/repositories/RepositoriesPanel.h +++ b/src/editor/dock-spaces/repositories/RepositoriesPanel.h @@ -6,12 +6,27 @@ namespace Metal { class FormPanel; class Inspectable; + struct EditorRepository; + struct EngineRepository; + struct WorldRepository; class RepositoriesPanel final : public AbstractDockPanel { std::vector repositories{}; FormPanel *formPanel = nullptr; + EditorRepository *editorRepository = nullptr; + EngineRepository *engineRepository = nullptr; + WorldRepository *worldRepository = nullptr; + public: + std::vector getDependencies() override { + return { + {"EditorRepository", editorRepository}, + {"EngineRepository", engineRepository}, + {"WorldRepository", worldRepository} + }; + } + void onInitialize() override; void onSync() override; }; diff --git a/src/editor/dock-spaces/viewport/CameraPositionPanel.cpp b/src/editor/dock-spaces/viewport/CameraPositionPanel.cpp index 9af7929e..9ce03f4d 100644 --- a/src/editor/dock-spaces/viewport/CameraPositionPanel.cpp +++ b/src/editor/dock-spaces/viewport/CameraPositionPanel.cpp @@ -1,8 +1,8 @@ #include "CameraPositionPanel.h" - #include "../../../ApplicationContext.h" #include "../../util/UIUtil.h" #include "../../../engine/dto/Camera.h" +#include "../../../engine/repository/WorldRepository.h" namespace Metal { void CameraPositionPanel::onSync() { @@ -18,7 +18,7 @@ namespace Metal { ImGui::SetNextWindowBgAlpha(.4f); if (ImGui::Begin(id.c_str(), &UIUtil::OPEN, ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoCollapse)) { - const auto &positionCamera = applicationContext->worldRepository.camera.position; + const auto &positionCamera = worldRepository->camera.position; ImGui::TextColored(RED, "X: %i", static_cast(positionCamera.x)); ImGui::SameLine(); ImGui::TextColored(GREEN, "Y: %i", static_cast(positionCamera.y)); @@ -27,10 +27,10 @@ namespace Metal { ImGui::SameLine(); ImGui::Text( - "Yaw: %i", static_cast(applicationContext->worldRepository.camera.yaw * TO_DEG)); + "Yaw: %i", static_cast(worldRepository->camera.yaw * TO_DEG)); ImGui::SameLine(); ImGui::Text("Pitch: %i", - static_cast(applicationContext->worldRepository.camera.pitch * TO_DEG)); + static_cast(worldRepository->camera.pitch * TO_DEG)); } ImGui::PopStyleVar(); ImGui::End(); diff --git a/src/editor/dock-spaces/viewport/CameraPositionPanel.h b/src/editor/dock-spaces/viewport/CameraPositionPanel.h index eabc4a4a..1dd71422 100644 --- a/src/editor/dock-spaces/viewport/CameraPositionPanel.h +++ b/src/editor/dock-spaces/viewport/CameraPositionPanel.h @@ -6,13 +6,23 @@ #include "../../abstract/AbstractPanel.h" namespace Metal { + struct WorldRepository; + class CameraPositionPanel final : public AbstractPanel { ImVec4 RED = ImVec4(1, 0, 0, 1); ImVec4 GREEN = ImVec4(0, 1, 0, 1); ImVec4 BLUE = ImVec4(0, .5f, 1, 1); float TO_DEG = 180.f / glm::pi(); + WorldRepository *worldRepository = nullptr; + public: + std::vector getDependencies() override { + return { + {"WorldRepository", worldRepository} + }; + } + void onSync() override; }; } // Metal diff --git a/src/editor/dock-spaces/viewport/EngineFramePanel.cpp b/src/editor/dock-spaces/viewport/EngineFramePanel.cpp index b38e5df5..12f6587c 100644 --- a/src/editor/dock-spaces/viewport/EngineFramePanel.cpp +++ b/src/editor/dock-spaces/viewport/EngineFramePanel.cpp @@ -14,7 +14,6 @@ #include "ViewportHeaderPanel.h" #include "ImGuizmo.h" #include - #include "../../../engine/passes/impl/HWRayTracingPass.h" #include "../../../engine/passes/impl/PostProcessingPass.h" #include "../../../engine/passes/impl/SpatialFilterPass.h" @@ -22,15 +21,21 @@ #include "../../passes/GridPass.h" #include "../../passes/SelectionIDPass.h" #include "../../passes/SelectionOutlinePass.h" +#include "../../../core/vulkan/VulkanContext.h" +#include "../../../engine/repository/EngineRepository.h" +#include "../../../engine/EngineContext.h" +#include "../../../engine/service/DescriptorSetService.h" +#include "../../service/SelectionService.h" +#include "../../../engine/resource/TextureInstance.h" namespace Metal { void EngineFramePanel::onInitialize() { - const auto gBufferW = applicationContext->vulkanContext.getWindowWidth() / applicationContext->engineRepository. + const auto gBufferW = vulkanContext->getWindowWidth() / engineRepository-> shadingResInvScale; - const auto gBufferH = applicationContext->vulkanContext.getWindowHeight() / applicationContext->engineRepository - .shadingResInvScale; + const auto gBufferH = vulkanContext->getWindowHeight() / engineRepository + ->shadingResInvScale; - engineFrame = EngineFrameBuilder() + engineContext->createFrame(id) .addBuffer(RID_GLOBAL_DATA, sizeof(GlobalDataUBO), VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, UNIFORM_BUFFER) .addBuffer(RID_LIGHT_BUFFER, MAX_LIGHTS * sizeof(LightData), @@ -62,17 +67,15 @@ namespace Metal { .addPass(std::make_unique(), RID_POST_PROCESSING_CB) .addPass(std::make_unique(), RID_POST_PROCESSING_CB) .build(); - - applicationContext->engineContext.registerFrame(engineFrame.get()); } void EngineFramePanel::onSync() { - engineFrame->setShouldRender(true); + engineContext->setCurrentFrame(id); const ImVec2 viewportSize = ImGui::GetContentRegionAvail(); - auto *framebuffer = engineFrame->getResourceAs(RID_POST_PROCESSING_FBO); + auto *framebuffer = engineContext->currentFrame->getResourceAs(RID_POST_PROCESSING_FBO); if (framebuffer) { - applicationContext->descriptorSetService.setImageDescriptor(framebuffer, 0); + descriptorSetService->setImageDescriptor(framebuffer, 0); ImGui::Image(reinterpret_cast(framebuffer->attachments[0]->imageDescriptor->vkDescriptorSet), viewportSize); @@ -103,7 +106,7 @@ namespace Metal { return; } - auto *gBufferPositionIndex = engineFrame->getResourceAs(RID_GBUFFER_POSITION_INDEX); + auto *gBufferPositionIndex = engineContext->currentFrame->getResourceAs(RID_GBUFFER_POSITION_INDEX); if (!gBufferPositionIndex) { return; } @@ -113,9 +116,9 @@ namespace Metal { const uint32_t pixelX = std::min(static_cast(u * static_cast(width)), width - 1); const uint32_t pixelY = std::min(static_cast(v * static_cast(height)), height - 1); - const auto picked = applicationContext->pickingService.pickEntityFromGBuffer( + const auto picked = pickingService->pickEntityFromGBuffer( gBufferPositionIndex, pixelX, pixelY); - applicationContext->selectionService.clearSelection(); - applicationContext->selectionService.addSelected(picked.value_or(EMPTY_ENTITY)); + selectionService->clearSelection(); + selectionService->addSelected(picked.value_or(EMPTY_ENTITY)); } } // Metal diff --git a/src/editor/dock-spaces/viewport/EngineFramePanel.h b/src/editor/dock-spaces/viewport/EngineFramePanel.h index cc7670bb..bee6aba7 100644 --- a/src/editor/dock-spaces/viewport/EngineFramePanel.h +++ b/src/editor/dock-spaces/viewport/EngineFramePanel.h @@ -7,11 +7,33 @@ namespace Metal { class EngineFrame; + class VulkanContext; + struct EngineRepository; + class EngineContext; + class DescriptorSetService; + class PickingService; + class SelectionService; class EngineFramePanel final : public AbstractPanel { - std::unique_ptr engineFrame; + VulkanContext *vulkanContext = nullptr; + EngineRepository *engineRepository = nullptr; + EngineContext *engineContext = nullptr; + DescriptorSetService *descriptorSetService = nullptr; + PickingService *pickingService = nullptr; + SelectionService *selectionService = nullptr; public: + std::vector getDependencies() override { + return { + {"VulkanContext", vulkanContext}, + {"EngineRepository", engineRepository}, + {"EngineContext", engineContext}, + {"DescriptorSetService", descriptorSetService}, + {"PickingService", pickingService}, + {"SelectionService", selectionService} + }; + } + void onInitialize() override; void onSync() override; diff --git a/src/editor/dock-spaces/viewport/GizmoPanel.cpp b/src/editor/dock-spaces/viewport/GizmoPanel.cpp index aed80e22..30f4163d 100644 --- a/src/editor/dock-spaces/viewport/GizmoPanel.cpp +++ b/src/editor/dock-spaces/viewport/GizmoPanel.cpp @@ -1,19 +1,19 @@ #include "GizmoPanel.h" - #include "../../../ApplicationContext.h" #include "../../../engine/dto/TransformComponent.h" #include "../../../engine/dto/Camera.h" #include "ImGuizmo.h" #include -#define GLM_ENABLE_EXPERIMENTAL #include +#include "../../repository/EditorRepository.h" +#include "../../../engine/repository/WorldRepository.h" +#include "../../service/SelectionService.h" namespace Metal { GizmoPanel::GizmoPanel(ImVec2 *position, glm::vec2 *size): size(size), position(position) { } void GizmoPanel::onInitialize() { - editorRepository = &applicationContext->editorRepository; } void GizmoPanel::onSync() { @@ -22,7 +22,7 @@ namespace Metal { localSelected = nullptr; localChangeId = 0; if (editorRepository->mainSelection != EMPTY_ENTITY) { - applicationContext->selectionService.updatePrimitiveSelected(); + selectionService->updatePrimitiveSelected(); } return; } @@ -40,7 +40,7 @@ namespace Metal { } recomposeMatrix(); - ImGuizmo::SetOrthographic(applicationContext->worldRepository.camera.isOrthographic); + ImGuizmo::SetOrthographic(worldRepository->camera.isOrthographic); ImGuizmo::SetDrawlist(); ImVec2 viewportMin = ImGui::GetItemRectMin(); ImVec2 viewportSize = ImGui::GetItemRectSize(); @@ -113,8 +113,8 @@ namespace Metal { } void GizmoPanel::recomposeMatrix() { - viewMatrixCache = glm::value_ptr(applicationContext->worldRepository.camera.viewMatrix); - cacheProjection = applicationContext->worldRepository.camera.projectionMatrix; + viewMatrixCache = glm::value_ptr(worldRepository->camera.viewMatrix); + cacheProjection = worldRepository->camera.projectionMatrix; cacheProjection[1][1] *= -1; diff --git a/src/editor/dock-spaces/viewport/GizmoPanel.h b/src/editor/dock-spaces/viewport/GizmoPanel.h index 36b6ee20..b68c74fc 100644 --- a/src/editor/dock-spaces/viewport/GizmoPanel.h +++ b/src/editor/dock-spaces/viewport/GizmoPanel.h @@ -2,6 +2,7 @@ #define GIZMOPANEL_H #include #include +#define GLM_ENABLE_EXPERIMENTAL #include #include @@ -9,6 +10,8 @@ namespace Metal { struct EditorRepository; + struct WorldRepository; + class SelectionService; } namespace Metal { @@ -31,9 +34,20 @@ namespace Metal { TransformComponent *localSelected = nullptr; int localChangeId{}; bool isGizmoOver = false; + EditorRepository *editorRepository = nullptr; + WorldRepository *worldRepository = nullptr; + SelectionService *selectionService = nullptr; public: + std::vector getDependencies() override { + return { + {"EditorRepository", editorRepository}, + {"WorldRepository", worldRepository}, + {"SelectionService", selectionService} + }; + } + explicit GizmoPanel(ImVec2 *position, glm::vec2 *size); void onInitialize() override; diff --git a/src/editor/dock-spaces/viewport/GizmoSettingsPanel.cpp b/src/editor/dock-spaces/viewport/GizmoSettingsPanel.cpp index 1a3e1c07..9094ce19 100644 --- a/src/editor/dock-spaces/viewport/GizmoSettingsPanel.cpp +++ b/src/editor/dock-spaces/viewport/GizmoSettingsPanel.cpp @@ -2,10 +2,12 @@ #include "../../util/UIUtil.h" #include "../../../ApplicationContext.h" #include "ImGuizmo.h" +#include "../../repository/EditorRepository.h" +#include "../../../engine/repository/WorldRepository.h" +#include "../../../engine/dto/MetadataComponent.h" namespace Metal { void GizmoSettingsPanel::onInitialize() { - editorRepository = &applicationContext->editorRepository; } void GizmoSettingsPanel::onSync() { @@ -15,9 +17,9 @@ namespace Metal { ImGui::SameLine(); gizmoGrid(); UIUtil::Spacing(); - if (selectedEntityId != editorRepository->mainSelection && applicationContext->worldRepository.registry.all_of( + if (selectedEntityId != editorRepository->mainSelection && worldRepository->registry.valid( editorRepository->mainSelection)) { - selectedEntity = applicationContext->worldRepository.getEntity(editorRepository->mainSelection); + selectedEntity = worldRepository->getEntity(editorRepository->mainSelection); selectedEntityId = editorRepository->mainSelection; } if (selectedEntity != nullptr) { @@ -119,7 +121,7 @@ namespace Metal { ImGui::SetNextItemWidth(50); if (ImGui::Combo((id + "scaleSnapAngle").c_str(), &editorRepository->gizmoSnapScaleOption, SNAP_SCALE_OPTIONS, ImGuiComboFlags_NoArrowButton)) { - editorRepository->gizmoSnapScale = SNAP_SCALE_OPTIONS[editorRepository->gizmoSnapScaleOption]; + editorRepository->gizmoSnapScale = SNAP_SCALE_OPTIONS_A[editorRepository->gizmoSnapScaleOption]; } } } // Metal diff --git a/src/editor/dock-spaces/viewport/GizmoSettingsPanel.h b/src/editor/dock-spaces/viewport/GizmoSettingsPanel.h index 0c68b751..998ac529 100644 --- a/src/editor/dock-spaces/viewport/GizmoSettingsPanel.h +++ b/src/editor/dock-spaces/viewport/GizmoSettingsPanel.h @@ -9,6 +9,7 @@ namespace Metal { struct MetadataComponent; struct EditorRepository; + struct WorldRepository; class GizmoSettingsPanel final : public AbstractPanel { static constexpr ImVec2 SPACING = ImVec2(0, 0); @@ -19,10 +20,18 @@ namespace Metal { static constexpr const char *SNAP_SCALE_OPTIONS = "0.5\0 1\0 2\0 5\0 10\0"; static constexpr std::array SNAP_SCALE_OPTIONS_A = {0.5, 1, 2, 5, 10}; EditorRepository *editorRepository = nullptr; + WorldRepository *worldRepository = nullptr; MetadataComponent *selectedEntity = nullptr; entt::entity selectedEntityId = EMPTY_ENTITY; public: + std::vector getDependencies() override { + return { + {"EditorRepository", editorRepository}, + {"WorldRepository", worldRepository} + }; + } + void onInitialize() override; void gizmoGrid() const; diff --git a/src/editor/dock-spaces/viewport/ViewportHeaderPanel.cpp b/src/editor/dock-spaces/viewport/ViewportHeaderPanel.cpp index 5c4d99f9..c6a7dd27 100644 --- a/src/editor/dock-spaces/viewport/ViewportHeaderPanel.cpp +++ b/src/editor/dock-spaces/viewport/ViewportHeaderPanel.cpp @@ -1,8 +1,9 @@ #include "ViewportHeaderPanel.h" - #include "GizmoSettingsPanel.h" #include "../../../ApplicationContext.h" #include "../../util/UIUtil.h" +#include "../../repository/EditorRepository.h" +#include "../../../engine/repository/WorldRepository.h" namespace Metal { void ViewportHeaderPanel::onInitialize() { @@ -33,8 +34,8 @@ namespace Metal { if (UIUtil::ButtonSimple(Icons::center_focus_strong + id + "centerCamera", UIUtil::ONLY_ICON_BUTTON_SIZE, UIUtil::ONLY_ICON_BUTTON_SIZE)) { - applicationContext->worldRepository.camera.position = {0, 0, 0}; - applicationContext->worldRepository.camera.registerChange(); + worldRepository->camera.position = {0, 0, 0}; + worldRepository->camera.registerChange(); } UIUtil::RenderTooltip("Center camera?"); @@ -44,21 +45,20 @@ namespace Metal { static float speedValues[] = {0.1f, 0.5f, 1.0f, 2.0f, 5.0f, 10.0f}; int currentSpeedIndex = 2; for (int i = 0; i < 6; i++) { - if (applicationContext->worldRepository.camera.movementSensitivity == speedValues[i]) { + if (worldRepository->camera.movementSensitivity == speedValues[i]) { currentSpeedIndex = i; break; } } if (ImGui::Combo((id + "speedCamera").c_str(), ¤tSpeedIndex, speeds, IM_ARRAYSIZE(speeds))) { - applicationContext->worldRepository.camera.movementSensitivity = speedValues[currentSpeedIndex]; + worldRepository->camera.movementSensitivity = speedValues[currentSpeedIndex]; } UIUtil::RenderTooltip("Camera speed"); } void ViewportHeaderPanel::shadingMode() { - auto &editorRepository = applicationContext->editorRepository; ImGui::SetNextItemWidth(150); - shadingModelOption = ShadingModes::IndexOfValue(editorRepository.shadingMode); + shadingModelOption = ShadingModes::IndexOfValue(editorRepository->shadingMode); auto currentEntry = ShadingModes::entries[shadingModelOption]; if (ImGui::BeginCombo((id + "shadingMode").c_str(), (currentEntry.icon + " " + currentEntry.label).c_str())) { @@ -67,7 +67,7 @@ namespace Metal { auto entry = ShadingModes::entries[i]; if (ImGui::Selectable((entry.icon + " " + entry.label).c_str(), is_selected)) { shadingModelOption = i; - editorRepository.shadingMode = ShadingModes::ValueOfIndex(shadingModelOption); + editorRepository->shadingMode = ShadingModes::ValueOfIndex(shadingModelOption); } if (is_selected) { ImGui::SetItemDefaultFocus(); diff --git a/src/editor/dock-spaces/viewport/ViewportHeaderPanel.h b/src/editor/dock-spaces/viewport/ViewportHeaderPanel.h index ed2e51c1..a5712887 100644 --- a/src/editor/dock-spaces/viewport/ViewportHeaderPanel.h +++ b/src/editor/dock-spaces/viewport/ViewportHeaderPanel.h @@ -5,13 +5,26 @@ #include "../../abstract/AbstractPanel.h" namespace Metal { + struct EditorRepository; + struct WorldRepository; + class ViewportHeaderPanel final : public AbstractPanel { static constexpr int FLAGS = ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoBackground | ImGuiWindowFlags_NoCollapse; AbstractPanel *gizmo = nullptr; int shadingModelOption = 0; + EditorRepository *editorRepository = nullptr; + WorldRepository *worldRepository = nullptr; + public: + std::vector getDependencies() override { + return { + {"EditorRepository", editorRepository}, + {"WorldRepository", worldRepository} + }; + } + static constexpr float HEIGHT = 28; void onInitialize() override; diff --git a/src/editor/dock-spaces/viewport/ViewportPanel.cpp b/src/editor/dock-spaces/viewport/ViewportPanel.cpp index 8d7e4807..8114ee67 100644 --- a/src/editor/dock-spaces/viewport/ViewportPanel.cpp +++ b/src/editor/dock-spaces/viewport/ViewportPanel.cpp @@ -1,5 +1,4 @@ #include "ViewportPanel.h" - #include "CameraPositionPanel.h" #include "GizmoPanel.h" #include "ImGuizmo.h" @@ -9,6 +8,14 @@ #include "../../../engine/dto/Camera.h" #include "../../../engine/frame-builder/EngineFrameBuilder.h" #include +#include "../../repository/EditorRepository.h" +#include "../../../engine/repository/WorldRepository.h" +#include "../../service/SelectionService.h" +#include "../../../engine/service/CameraService.h" +#include "../../../engine/repository/RuntimeRepository.h" +#include "../../../engine/EngineContext.h" +#include "../../../core/DirectoryService.h" +#include "../../../engine/dto/MetadataComponent.h" namespace Metal { void ViewportPanel::onInitialize() { @@ -19,39 +26,39 @@ namespace Metal { shortcuts = { ShortcutDTO("Change shading mode", ImGuiKey_Q, [this]() { - applicationContext->editorRepository.shadingMode = ShadingModes::ValueOfIndex( - ShadingModes::IndexOfValue(applicationContext->editorRepository.shadingMode) + 1); + editorRepository->shadingMode = ShadingModes::ValueOfIndex( + ShadingModes::IndexOfValue(editorRepository->shadingMode) + 1); }), ShortcutDTO("Translate", ImGuiKey_1, [this]() { - applicationContext->editorRepository.gizmoType = ImGuizmo::OPERATION::TRANSLATE; + editorRepository->gizmoType = ImGuizmo::OPERATION::TRANSLATE; }), ShortcutDTO("Scale", ImGuiKey_2, [this]() { - applicationContext->editorRepository.gizmoType = ImGuizmo::OPERATION::SCALE; + editorRepository->gizmoType = ImGuizmo::OPERATION::SCALE; }), ShortcutDTO("Rotate", ImGuiKey_3, [this]() { - applicationContext->editorRepository.gizmoType = ImGuizmo::OPERATION::ROTATE; + editorRepository->gizmoType = ImGuizmo::OPERATION::ROTATE; }), ShortcutDTO("Delete", ImGuiKey_Delete, [this]() { std::vector entities; - for (auto &entry: applicationContext->editorRepository.selected) { + for (auto &entry: editorRepository->selected) { entities.push_back(entry.first); } - applicationContext->worldRepository.deleteEntities(entities); - applicationContext->selectionService.clearSelection(); + worldRepository->deleteEntities(entities); + selectionService->clearSelection(); }), ShortcutDTO("Select All", ImGuiMod_Ctrl | ImGuiKey_A, [this]() { std::vector entities; - auto &storage = applicationContext->worldRepository.registry.storage(); + auto &storage = worldRepository->registry.storage(); for (auto it = storage.begin(); it != storage.end(); ++it) { auto entity = *it; - if (applicationContext->worldRepository.registry.all_of(entity)) { + if (worldRepository->registry.all_of(entity)) { entities.push_back(entity); } } - applicationContext->selectionService.addAllSelected(entities); + selectionService->addAllSelected(entities); }), ShortcutDTO("Save", ImGuiMod_Ctrl | ImGuiKey_S, [this] { - applicationContext->save(); + directoryService->save(); }) }; } @@ -68,16 +75,12 @@ namespace Metal { } void ViewportPanel::updateCamera() { - auto &worldRepository = applicationContext->worldRepository; - const auto &cameraService = applicationContext->cameraService; - if (ImGui::IsWindowHovered() && !ImGuizmo::IsUsing() && ImGui::IsMouseDown(ImGuiMouseButton_Right)) { - cameraService.handleInput(isFirstMovement); + cameraService->handleInput(isFirstMovement); if (const auto &io = ImGui::GetIO(); io.MouseWheel != 0) { - worldRepository.camera.movementSensitivity += io.MouseWheel * 100 * applicationContext-> - engineContext.deltaTime; - worldRepository.camera.movementSensitivity = - std::max(.1f, worldRepository.camera.movementSensitivity); + worldRepository->camera.movementSensitivity += io.MouseWheel * 100 * engineContext->deltaTime; + worldRepository->camera.movementSensitivity = + std::max(.1f, worldRepository->camera.movementSensitivity); } isFirstMovement = false; } else { @@ -86,33 +89,28 @@ namespace Metal { } void ViewportPanel::updateInputs() const { - auto &repo = applicationContext->runtimeRepository; - const ImVec2 windowSize = ImGui::GetWindowSize(); - size->x = windowSize.x; - size->y = windowSize.y; - - repo.viewportH = size->y; - repo.viewportW = size->x; + runtimeRepository->viewportH = size->y; + runtimeRepository->viewportW = size->x; const ImVec2 windowPos = ImGui::GetWindowPos(); - repo.viewportX = windowPos.x; - repo.viewportY = windowPos.y; + runtimeRepository->viewportX = windowPos.x; + runtimeRepository->viewportY = windowPos.y; - repo.isFocused = ImGui::IsWindowHovered(); - repo.forwardPressed = ImGui::IsKeyDown(ImGuiKey_W); - repo.backwardPressed = ImGui::IsKeyDown(ImGuiKey_S); - repo.leftPressed = ImGui::IsKeyDown(ImGuiKey_A); - repo.rightPressed = ImGui::IsKeyDown(ImGuiKey_D); - repo.upPressed = ImGui::IsKeyDown(ImGuiKey_Space); - repo.downPressed = ImGui::IsKeyDown(ImGuiKey_LeftCtrl); - repo.mousePressed = ImGui::IsWindowFocused() && ImGui::IsWindowHovered() && ImGui::IsMouseDown( + runtimeRepository->isFocused = ImGui::IsWindowHovered(); + runtimeRepository->forwardPressed = ImGui::IsKeyDown(ImGuiKey_W); + runtimeRepository->backwardPressed = ImGui::IsKeyDown(ImGuiKey_S); + runtimeRepository->leftPressed = ImGui::IsKeyDown(ImGuiKey_A); + runtimeRepository->rightPressed = ImGui::IsKeyDown(ImGuiKey_D); + runtimeRepository->upPressed = ImGui::IsKeyDown(ImGuiKey_Space); + runtimeRepository->downPressed = ImGui::IsKeyDown(ImGuiKey_LeftCtrl); + runtimeRepository->mousePressed = ImGui::IsWindowFocused() && ImGui::IsWindowHovered() && ImGui::IsMouseDown( ImGuiMouseButton_Left); const ImVec2 mousePos = ImGui::GetMousePos(); - repo.mouseX = mousePos.x; - repo.mouseY = mousePos.y; + runtimeRepository->mouseX = mousePos.x; + runtimeRepository->mouseY = mousePos.y; - repo.normalizedMouseX = (repo.mouseX + repo.viewportX) / repo.viewportW; - repo.normalizedMouseY = (repo.viewportH - repo.mouseY + repo.viewportY) / repo.viewportH; + runtimeRepository->normalizedMouseX = (runtimeRepository->mouseX + runtimeRepository->viewportX) / runtimeRepository->viewportW; + runtimeRepository->normalizedMouseY = (runtimeRepository->viewportH - runtimeRepository->mouseY + runtimeRepository->viewportY) / runtimeRepository->viewportH; } } diff --git a/src/editor/dock-spaces/viewport/ViewportPanel.h b/src/editor/dock-spaces/viewport/ViewportPanel.h index 0cc24af5..343cded0 100644 --- a/src/editor/dock-spaces/viewport/ViewportPanel.h +++ b/src/editor/dock-spaces/viewport/ViewportPanel.h @@ -4,6 +4,14 @@ #include "../docks/AbstractDockPanel.h" namespace Metal { + class CameraService; + class SelectionService; + struct EditorRepository; + struct WorldRepository; + struct RuntimeRepository; + class EngineContext; + struct DirectoryService; + class ViewportPanel final : public AbstractDockPanel { bool isFirstMovement = false; AbstractPanel *headerPanel = nullptr; @@ -11,7 +19,27 @@ namespace Metal { AbstractPanel *cameraPanel = nullptr; AbstractPanel *engineFramePanel = nullptr; + CameraService *cameraService = nullptr; + SelectionService *selectionService = nullptr; + EditorRepository *editorRepository = nullptr; + WorldRepository *worldRepository = nullptr; + RuntimeRepository *runtimeRepository = nullptr; + EngineContext *engineContext = nullptr; + DirectoryService *directoryService = nullptr; + public: + std::vector getDependencies() override { + return { + {"CameraService", cameraService}, + {"SelectionService", selectionService}, + {"EditorRepository", editorRepository}, + {"WorldRepository", worldRepository}, + {"RuntimeRepository", runtimeRepository}, + {"EngineContext", engineContext}, + {"DirectoryService", directoryService} + }; + } + void onInitialize() override; void onSync() override; diff --git a/src/editor/dock-spaces/world/WorldHeaderPanel.cpp b/src/editor/dock-spaces/world/WorldHeaderPanel.cpp index f263fb2c..fba2b9f4 100644 --- a/src/editor/dock-spaces/world/WorldHeaderPanel.cpp +++ b/src/editor/dock-spaces/world/WorldHeaderPanel.cpp @@ -1,8 +1,8 @@ #include "WorldHeaderPanel.h" - #include "../../../ApplicationContext.h" #include "../../util/UIUtil.h" #include "../../../engine/enum/ComponentType.h" +#include "../../../engine/repository/WorldRepository.h" namespace Metal { void WorldHeaderPanel::onSync() { @@ -28,7 +28,7 @@ namespace Metal { ImGui::SameLine(); if (UIUtil::ButtonSimple(Icons::add + "##hierarchyAdd" + id, UIUtil::ONLY_ICON_BUTTON_SIZE, UIUtil::ONLY_ICON_BUTTON_SIZE)) { - applicationContext->worldRepository.createEntity(); + worldRepository->createEntity(); } UIUtil::RenderTooltip("Create entity"); } diff --git a/src/editor/dock-spaces/world/WorldHeaderPanel.h b/src/editor/dock-spaces/world/WorldHeaderPanel.h index 1e9f025a..c89b5e4d 100644 --- a/src/editor/dock-spaces/world/WorldHeaderPanel.h +++ b/src/editor/dock-spaces/world/WorldHeaderPanel.h @@ -3,8 +3,18 @@ #include "../../abstract/AbstractPanel.h" namespace Metal { + struct WorldRepository; + class WorldHeaderPanel final : public AbstractPanel { + WorldRepository *worldRepository = nullptr; + public: + std::vector getDependencies() override { + return { + {"WorldRepository", worldRepository} + }; + } + void onSync() override; char search[512]; diff --git a/src/editor/dock-spaces/world/WorldPanel.cpp b/src/editor/dock-spaces/world/WorldPanel.cpp index dfa7c336..ab177ffd 100644 --- a/src/editor/dock-spaces/world/WorldPanel.cpp +++ b/src/editor/dock-spaces/world/WorldPanel.cpp @@ -1,26 +1,27 @@ #include "WorldPanel.h" - #include "WorldHeaderPanel.h" #include "../../../common/Icons.h" #include "../../util/UIUtil.h" #include "../../../ApplicationContext.h" #include "../../../engine/dto/MetadataComponent.h" #include "../../../engine/enum/ComponentType.h" +#include "../../../engine/repository/WorldRepository.h" +#include "../../repository/EditorRepository.h" +#include "../../service/SelectionService.h" +#include "../../../core/DirectoryService.h" namespace Metal { void WorldPanel::onInitialize() { appendChild(headerPanel = new WorldHeaderPanel()); - world = &applicationContext->worldRepository; - editorRepository = &applicationContext->editorRepository; shortcuts = { ShortcutDTO("Delete", ImGuiKey_Delete, [this]() { std::vector entities; - for (auto &entry: applicationContext->editorRepository.selected) { + for (auto &entry: editorRepository->selected) { entities.push_back(entry.first); } - applicationContext->worldRepository.deleteEntities(entities); - applicationContext->selectionService.clearSelection(); + world->deleteEntities(entities); + selectionService->clearSelection(); }), ShortcutDTO("Select All", ImGuiMod_Ctrl | ImGuiKey_A, [this]() { std::vector entities; @@ -29,10 +30,10 @@ namespace Metal { entities.push_back(entity); } } - applicationContext->selectionService.addAllSelected(entities); + selectionService->addAllSelected(entities); }), ShortcutDTO("Save", ImGuiMod_Ctrl | ImGuiKey_S, [this] { - applicationContext->save(); + directoryService->save(); }), }; } @@ -41,11 +42,11 @@ namespace Metal { if (ImGui::BeginPopupContextItem((id + "contextMenu").c_str())) { if (ImGui::MenuItem("Delete")) { std::vector entities; - for (auto &entry: applicationContext->editorRepository.selected) { + for (auto &entry: editorRepository->selected) { entities.push_back(entry.first); } - applicationContext->worldRepository.deleteEntities(entities); - applicationContext->selectionService.clearSelection(); + world->deleteEntities(entities); + selectionService->clearSelection(); } ImGui::EndPopup(); } @@ -73,7 +74,7 @@ namespace Metal { ImGui::EndTable(); } - if (!applicationContext->editorRepository.selected.empty()) { + if (!editorRepository->selected.empty()) { contextMenu(); } } @@ -172,7 +173,7 @@ namespace Metal { const bool isVisible = !world->hiddenEntities.contains(entityId); if (UIUtil::ButtonSimple((isVisible ? Icons::visibility : Icons::visibility_off) + ("##v") + std::to_string(static_cast(entt::to_integral(entityId))) + id, 20, 15)) { - applicationContext->worldRepository.changeVisibility(entityId, !isVisible); + world->changeVisibility(entityId, !isVisible); } ImGui::PopStyleColor(); ImGui::PopStyleVar(2); @@ -182,9 +183,9 @@ namespace Metal { void WorldPanel::handleClick(const entt::entity entityId) const { if (ImGui::IsItemClicked()) { if (const bool isMultiSelect = ImGui::IsKeyDown(ImGuiKey_LeftCtrl); !isMultiSelect) { - applicationContext->selectionService.clearSelection(); + selectionService->clearSelection(); } - applicationContext->selectionService.addSelected(entityId); + selectionService->addSelected(entityId); } } diff --git a/src/editor/dock-spaces/world/WorldPanel.h b/src/editor/dock-spaces/world/WorldPanel.h index 920c7f70..dabf837e 100644 --- a/src/editor/dock-spaces/world/WorldPanel.h +++ b/src/editor/dock-spaces/world/WorldPanel.h @@ -13,6 +13,8 @@ namespace Metal { struct AbstractComponent; struct MetadataComponent; class WorldHeaderPanel; + class SelectionService; + struct DirectoryService; class WorldPanel final : public AbstractDockPanel { static constexpr auto TRANSPARENT = ImVec4(0, 0, 0, 0); @@ -26,7 +28,19 @@ namespace Metal { EditorRepository *editorRepository = nullptr; bool isSomethingHovered = false; + SelectionService *selectionService = nullptr; + DirectoryService *directoryService = nullptr; + public: + std::vector getDependencies() override { + return { + {"WorldRepository", world}, + {"EditorRepository", editorRepository}, + {"SelectionService", selectionService}, + {"DirectoryService", directoryService} + }; + } + void onInitialize() override; void contextMenu() const; diff --git a/src/editor/enum/engine-definitions.h b/src/editor/enum/engine-definitions.h index b3496556..a92a1a39 100644 --- a/src/editor/enum/engine-definitions.h +++ b/src/editor/enum/engine-definitions.h @@ -6,6 +6,7 @@ #define MAX_LIGHTS 300 #define MAX_MESH_INSTANCES 1000 #define EMPTY_ENTITY entt::null +#define LARGE_FONT_SIZE 38 #define FILE_METADATA ".mjson" #define FILE_SCENE "-scene" diff --git a/src/editor/panel/FileImportModalPanel.cpp b/src/editor/panel/FileImportModalPanel.cpp index 15b233df..e52c06ca 100644 --- a/src/editor/panel/FileImportModalPanel.cpp +++ b/src/editor/panel/FileImportModalPanel.cpp @@ -1,10 +1,14 @@ #include "FileImportModalPanel.h" - #include #include #include "../../ApplicationContext.h" #include "../../common/FilesUtil.h" #include "../abstract/form/FormPanel.h" +#include "../repository/EditorRepository.h" +#include "../service/FileImporterService.h" +#include "../service/NotificationService.h" +#include "../service/FilesService.h" +#include "../dto/FSEntry.h" namespace Metal { void FileImportModalPanel::onInitialize() { @@ -13,15 +17,14 @@ namespace Metal { } void FileImportModalPanel::onSync() { - auto &editorRepository = applicationContext->editorRepository; - if (editorRepository.pendingImports.empty()) { + if (editorRepository->pendingImports.empty()) { isFirst = true; return; } if (isFirst) { formPanel->setInspection( - editorRepository.importSettingsMap.at(editorRepository.selectedFileForSettings).get()); + editorRepository->importSettingsMap.at(editorRepository->selectedFileForSettings).get()); isFirst = false; } @@ -50,16 +53,16 @@ namespace Metal { ImGui::TableSetupColumn("Size", ImGuiTableColumnFlags_WidthFixed, 80.0f); ImGui::TableHeadersRow(); - for (const auto &filePath: editorRepository.pendingImports) { + for (const auto &filePath: editorRepository->pendingImports) { std::filesystem::path p(filePath); ImGui::TableNextRow(); ImGui::TableNextColumn(); - bool isSelected = (editorRepository.selectedFileForSettings == filePath); + bool isSelected = (editorRepository->selectedFileForSettings == filePath); if (ImGui::Selectable(p.filename().string().c_str(), isSelected, ImGuiSelectableFlags_SpanAllColumns)) { - editorRepository.selectedFileForSettings = filePath; + editorRepository->selectedFileForSettings = filePath; formPanel->setInspection( - editorRepository.importSettingsMap.at(editorRepository.selectedFileForSettings). + editorRepository->importSettingsMap.at(editorRepository->selectedFileForSettings). get()); } ImGui::TableNextColumn(); @@ -76,7 +79,7 @@ namespace Metal { ImGui::TableNextColumn(); ImGui::Text("Settings: %s", - std::filesystem::path(editorRepository.selectedFileForSettings).filename().string(). + std::filesystem::path(editorRepository->selectedFileForSettings).filename().string(). c_str()); ImGui::BeginChild((id + "SettingsFormChild").c_str(), ImVec2(0, maxHeight - 180.0f), true); formPanel->onSync(); @@ -90,20 +93,20 @@ namespace Metal { ImGui::Spacing(); if (ImGui::Button(("Approve" + id + "approveImport").c_str(), ImVec2(120, 0))) { - for (const std::string &file: editorRepository.pendingImports) { - applicationContext->fileImporterService.importFile(editorRepository.targetImportDirectory->absolutePath, file, - editorRepository.importSettingsMap.at(file)); + for (const std::string &file: editorRepository->pendingImports) { + fileImporterService->importFile(editorRepository->targetImportDirectory->absolutePath, file, + editorRepository->importSettingsMap.at(file)); } - applicationContext->notificationService.pushMessage("Importing files...", NotificationSeverities::WARNING); - FilesService::GetEntries(editorRepository.targetImportDirectory); - editorRepository.pendingImports.clear(); - editorRepository.importSettingsMap.clear(); + notificationService->pushMessage("Importing files...", NotificationSeverities::WARNING); + filesService->GetEntries(editorRepository->targetImportDirectory); + editorRepository->pendingImports.clear(); + editorRepository->importSettingsMap.clear(); formPanel->resetForm(); } ImGui::SameLine(); if (ImGui::Button(("Cancel" + id + "cancel").c_str(), ImVec2(120, 0))) { - editorRepository.pendingImports.clear(); - editorRepository.importSettingsMap.clear(); + editorRepository->pendingImports.clear(); + editorRepository->importSettingsMap.clear(); formPanel->resetForm(); } } diff --git a/src/editor/panel/FileImportModalPanel.h b/src/editor/panel/FileImportModalPanel.h index 03f26316..89c0849b 100644 --- a/src/editor/panel/FileImportModalPanel.h +++ b/src/editor/panel/FileImportModalPanel.h @@ -4,12 +4,27 @@ namespace Metal { class FormPanel; + struct EditorRepository; + class FileImporterService; + class NotificationService; class FileImportModalPanel final : public AbstractPanel { FormPanel *formPanel = nullptr; bool isFirst = false; + EditorRepository *editorRepository = nullptr; + FileImporterService *fileImporterService = nullptr; + NotificationService *notificationService = nullptr; + public: + std::vector getDependencies() override { + return { + {"EditorRepository", editorRepository}, + {"FileImporterService", fileImporterService}, + {"NotificationService", notificationService} + }; + } + void onInitialize() override; void onSync() override; diff --git a/src/editor/panel/NotificationsPanel.cpp b/src/editor/panel/NotificationsPanel.cpp index 6b5c8dc0..8e954514 100644 --- a/src/editor/panel/NotificationsPanel.cpp +++ b/src/editor/panel/NotificationsPanel.cpp @@ -3,21 +3,23 @@ #include "../../ApplicationContext.h" #include "../util/UIUtil.h" #include "../dto/Notification.h" +#include "../service/NotificationService.h" +#include "../../engine/EngineContext.h" namespace Metal { void NotificationsPanel::onSync() { int usedIndices = 0; - for (int i = 0; i < applicationContext->notificationService.getNotifications().size(); i++) { - auto *notification = applicationContext->notificationService.getNotifications()[i]; + for (int i = 0; i < notificationService->getNotifications().size(); i++) { + auto *notification = notificationService->getNotifications()[i]; if (notification == nullptr) { continue; } if (notification->displayTime < 0) { - notification->displayTime = applicationContext->engineContext.currentTimeMs; + notification->displayTime = engineContext->currentTimeMs; } - if (applicationContext->engineContext.currentTimeMs - notification->displayTime > MESSAGE_DURATION) { + if (engineContext->currentTimeMs - notification->displayTime > MESSAGE_DURATION) { delete notification; - applicationContext->notificationService.getNotifications()[i] = nullptr; + notificationService->getNotifications()[i] = nullptr; continue; } ImGui::SetNextWindowPos(ImVec2(5, ImGui::GetMainViewport()->Size.y - 40 * (usedIndices + 1))); diff --git a/src/editor/panel/NotificationsPanel.h b/src/editor/panel/NotificationsPanel.h index 2018f3c0..eae1b8e7 100644 --- a/src/editor/panel/NotificationsPanel.h +++ b/src/editor/panel/NotificationsPanel.h @@ -3,8 +3,21 @@ #include "../abstract/AbstractPanel.h" namespace Metal { + class NotificationService; + class EngineContext; + class NotificationsPanel final : public AbstractPanel { + NotificationService *notificationService = nullptr; + EngineContext *engineContext = nullptr; + public: + std::vector getDependencies() override { + return { + {"NotificationService", notificationService}, + {"EngineContext", engineContext} + }; + } + void onSync() override; }; } // Metal diff --git a/src/editor/passes/GridPass.cpp b/src/editor/passes/GridPass.cpp index 365aaef8..3dfcc2a9 100644 --- a/src/editor/passes/GridPass.cpp +++ b/src/editor/passes/GridPass.cpp @@ -1,7 +1,8 @@ #include "GridPass.h" - #include "../../ApplicationContext.h" #include "../../engine/dto/PipelineBuilder.h" +#include "../../engine/service/PipelineService.h" +#include "../repository/EditorRepository.h" #include "../enum/EngineResourceIDs.h" namespace Metal { @@ -15,18 +16,18 @@ namespace Metal { .setPushConstantsSize(sizeof(GridPushConstant)) .addBufferBinding(getScopedResourceId(RID_GLOBAL_DATA)) .addStorageImageBinding(getScopedResourceId(RID_GBUFFER_POSITION_INDEX)); - pipelineInstance = CTX.pipelineService.createPipeline(gridPipelineBuilder); + pipelineInstance = pipelineService->createPipeline(gridPipelineBuilder); } bool GridPass::shouldRun() { - return CTX.isDebugMode() && CTX.editorRepository.showGrid; + return applicationContext->isDebugMode() && editorRepository->showGrid; } void GridPass::onSync() { - pushConstant.scale = CTX.editorRepository.gridScale; - pushConstant.overlayObjects = CTX.editorRepository.gridOverlayObjects; - pushConstant.threshold = CTX.editorRepository.gridThreshold; - pushConstant.thickness = CTX.editorRepository.gridThickness; + pushConstant.scale = editorRepository->gridScale; + pushConstant.overlayObjects = editorRepository->gridOverlayObjects; + pushConstant.threshold = editorRepository->gridThreshold; + pushConstant.thickness = editorRepository->gridThickness; recordPushConstant(&pushConstant); recordDrawSimpleInstanced(3, 1); } diff --git a/src/editor/passes/GridPass.h b/src/editor/passes/GridPass.h index ff77ef29..93342511 100644 --- a/src/editor/passes/GridPass.h +++ b/src/editor/passes/GridPass.h @@ -4,10 +4,26 @@ #include "../dto/GridPushConstant.h" namespace Metal { + class PipelineService; + class ApplicationContext; + struct EditorRepository; + class GridPass final : public AbstractRenderPass { GridPushConstant pushConstant{}; + PipelineService *pipelineService = nullptr; + ApplicationContext *applicationContext = nullptr; + EditorRepository *editorRepository = nullptr; + public: + std::vector getDependencies() override { + return { + {"PipelineService", pipelineService}, + {"ApplicationContext", applicationContext}, + {"EditorRepository", editorRepository} + }; + } + void onInitialize() override; bool shouldRun() override; diff --git a/src/editor/passes/SelectionIDPass.cpp b/src/editor/passes/SelectionIDPass.cpp index 939f0626..9a917ae0 100644 --- a/src/editor/passes/SelectionIDPass.cpp +++ b/src/editor/passes/SelectionIDPass.cpp @@ -1,9 +1,12 @@ #include "SelectionIDPass.h" - -#include "../../ApplicationContext.h" #include "../../engine/dto/TransformComponent.h" +#include "../../engine/dto/PrimitiveComponent.h" #include "../dto/SelectedDotPushConstant.h" #include "../../engine/dto/PipelineBuilder.h" +#include "../../engine/service/PipelineService.h" +#include "../repository/EditorRepository.h" +#include "../../engine/repository/WorldRepository.h" +#include "../../engine/service/MeshService.h" #include "../enum/EngineResourceIDs.h" namespace Metal { @@ -17,38 +20,37 @@ namespace Metal { .setCullMode(VK_CULL_MODE_NONE) .setPushConstantsSize(sizeof(SelectedDotPushConstant)) .addBufferBinding(getScopedResourceId(RID_GLOBAL_DATA)); - pipelineInstance = CTX.pipelineService.createPipeline(builder); + pipelineInstance = pipelineService->createPipeline(builder); } bool SelectionIDPass::shouldRun() { - return !CTX.editorRepository.selected.empty(); + return !editorRepository->selected.empty(); } void SelectionIDPass::onSync() { - auto &worldRepository = CTX.worldRepository; - for (auto const& [entityId, selected] : CTX.editorRepository.selected) { + for (auto const& [entityId, selected] : editorRepository->selected) { if (!selected) { continue; } - if (!worldRepository.registry.all_of(entityId) || !worldRepository.registry.all_of(entityId)) { + if (!worldRepository->registry.all_of(entityId) || !worldRepository->registry.all_of(entityId)) { continue; } - const auto &mesh = worldRepository.registry.get(entityId); + const auto &mesh = worldRepository->registry.get(entityId); if (mesh.meshId.empty()) { continue; } - if (worldRepository.hiddenEntities.contains(entityId)) { + if (worldRepository->hiddenEntities.contains(entityId)) { continue; } - const auto *meshInstance = CTX.meshService.stream(mesh.meshId); + const auto *meshInstance = meshService->stream(mesh.meshId); if (!meshInstance) { continue; } - pushConstant.model = worldRepository.registry.get(entityId).model; - pushConstant.selectionColor = glm::vec4(CTX.editorRepository.selectionColor, CTX.editorRepository.selectionOutlineThickness); + pushConstant.model = worldRepository->registry.get(entityId).model; + pushConstant.selectionColor = glm::vec4(editorRepository->selectionColor, editorRepository->selectionOutlineThickness); pushConstant.renderIndex = mesh.renderIndex; recordPushConstant(&pushConstant); diff --git a/src/editor/passes/SelectionIDPass.h b/src/editor/passes/SelectionIDPass.h index fe0aac3a..9a972cd2 100644 --- a/src/editor/passes/SelectionIDPass.h +++ b/src/editor/passes/SelectionIDPass.h @@ -5,10 +5,28 @@ #include "../dto/SelectedDotPushConstant.h" namespace Metal { + class PipelineService; + struct EditorRepository; + struct WorldRepository; + class MeshService; + class SelectionIDPass final : public AbstractRenderPass { SelectedDotPushConstant pushConstant{}; + PipelineService *pipelineService = nullptr; + EditorRepository *editorRepository = nullptr; + WorldRepository *worldRepository = nullptr; + MeshService *meshService = nullptr; + public: + std::vector getDependencies() override { + return { + {"PipelineService", pipelineService}, + {"EditorRepository", editorRepository}, + {"WorldRepository", worldRepository}, + {"MeshService", meshService} + }; + } void onInitialize() override; diff --git a/src/editor/passes/SelectionOutlinePass.cpp b/src/editor/passes/SelectionOutlinePass.cpp index d3e542ca..f44c9289 100644 --- a/src/editor/passes/SelectionOutlinePass.cpp +++ b/src/editor/passes/SelectionOutlinePass.cpp @@ -1,9 +1,10 @@ #include "SelectionOutlinePass.h" - #include "../../ApplicationContext.h" #include "../../engine/dto/TransformComponent.h" #include "../dto/SelectedDotPushConstant.h" #include "../../engine/dto/PipelineBuilder.h" +#include "../../engine/service/PipelineService.h" +#include "../repository/EditorRepository.h" #include "../enum/EngineResourceIDs.h" namespace Metal { @@ -17,19 +18,19 @@ namespace Metal { .setPushConstantsSize(sizeof(SelectedDotPushConstant)) .addBufferBinding(getScopedResourceId(RID_GLOBAL_DATA)) .addFboBinding(getScopedResourceId(RID_SELECTION_FBO), 0); - pipelineInstance = CTX.pipelineService.createPipeline(builder); + pipelineInstance = pipelineService->createPipeline(builder); } bool SelectionOutlinePass::shouldRun() { - return !CTX.editorRepository.selected.empty(); + return !editorRepository->selected.empty(); } void SelectionOutlinePass::onSync() { - pushConstant.selectionColor.x = CTX.editorRepository.selectionColor.x; - pushConstant.selectionColor.y = CTX.editorRepository.selectionColor.y; - pushConstant.selectionColor.z = CTX.editorRepository.selectionColor.z; - pushConstant.selectionColor.w = CTX.editorRepository.selectionOutlineThickness; + pushConstant.selectionColor.x = editorRepository->selectionColor.x; + pushConstant.selectionColor.y = editorRepository->selectionColor.y; + pushConstant.selectionColor.z = editorRepository->selectionColor.z; + pushConstant.selectionColor.w = editorRepository->selectionOutlineThickness; recordPushConstant(&pushConstant); recordDrawSimpleInstanced(3, 1); diff --git a/src/editor/passes/SelectionOutlinePass.h b/src/editor/passes/SelectionOutlinePass.h index 60860a7a..3d036e68 100644 --- a/src/editor/passes/SelectionOutlinePass.h +++ b/src/editor/passes/SelectionOutlinePass.h @@ -5,10 +5,23 @@ #include "../dto/SelectedDotPushConstant.h" namespace Metal { + class PipelineService; + struct EditorRepository; + class SelectionOutlinePass final : public AbstractRenderPass { SelectedDotPushConstant pushConstant{}; + PipelineService *pipelineService = nullptr; + EditorRepository *editorRepository = nullptr; + public: + std::vector getDependencies() override { + return { + {"PipelineService", pipelineService}, + {"EditorRepository", editorRepository} + }; + } + void onInitialize() override; bool shouldRun() override; diff --git a/src/editor/service/DockService.cpp b/src/editor/service/DockService.cpp index 2a5b821f..6113369e 100644 --- a/src/editor/service/DockService.cpp +++ b/src/editor/service/DockService.cpp @@ -8,7 +8,7 @@ #include "../../ApplicationContext.h" namespace Metal { - DockService::DockService() { + void DockService::onInitialize() { auto *rightT = new DockDTO{&DockSpace::WORLD}; auto *leftTop = new DockDTO{&DockSpace::REPOSITORIES}; auto *leftDown = new DockDTO{&DockSpace::INSPECTOR}; @@ -30,14 +30,14 @@ namespace Metal { bottom.push_back(downRight); } - void DockService::buildViews(ImGuiID windowId, AbstractPanel *panel) const { + void DockService::buildViews(ImGuiID windowId, AbstractPanel *panel) { if (ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_DockingEnable) { - if (dockRepository.isInitialized) { + if (isInitialized) { return; } - dockRepository.isInitialized = true; + isInitialized = true; - std::vector toKeep{}; + std::vector toKeep{}; for (auto *child: panel->getChildren()) { auto *p = dynamic_cast(child); if (p == nullptr) { @@ -58,7 +58,6 @@ namespace Metal { ImGui::DockBuilderAddNode(windowId, ImGuiDockNodeFlags_NoTabBar); ImGui::DockBuilderSetNodeSize(windowId, ImGui::GetMainViewport()->Size); - const auto &left = dockRepository.left; for (size_t i = 0; i < left.size(); i++) { DockDTO *dockSpace = left[i]; if (i == 0) { @@ -75,7 +74,6 @@ namespace Metal { addWindow(dockSpace, panel); } - const auto &right = dockRepository.right; for (size_t i = 0; i < right.size(); i++) { DockDTO *dockSpace = right[i]; if (i == 0) { @@ -92,7 +90,6 @@ namespace Metal { addWindow(dockSpace, panel); } - const auto &bottom = dockRepository.bottom; for (size_t i = 0, bottomSize = bottom.size(); i < bottomSize; i++) { DockDTO *dockSpace = bottom[i]; if (i == 0) { @@ -109,10 +106,10 @@ namespace Metal { addWindow(dockSpace, panel); } - dockRepository.center.nodeId = windowId; - addWindow(&dockRepository.center, panel); + center.nodeId = windowId; + addWindow(¢er, panel); - ImGui::DockBuilderDockWindow(dockRepository.center.internalId.c_str(), windowId); + ImGui::DockBuilderDockWindow(center.internalId.c_str(), windowId); ImGui::DockBuilderFinish(windowId); } } diff --git a/src/editor/service/DockService.h b/src/editor/service/DockService.h index 8fca6f13..c8b8de89 100644 --- a/src/editor/service/DockService.h +++ b/src/editor/service/DockService.h @@ -9,7 +9,7 @@ namespace Metal { class AbstractPanel; - class DockService final : public IService { + class DockService final : public IService, public IInit { DockDTO center{&DockSpace::VIEWPORT}; std::vector bottom; std::vector left; @@ -17,10 +17,11 @@ namespace Metal { bool isInitialized = false; + public: - explicit DockService(); + void onInitialize() override; - void buildViews(ImGuiID windowId, AbstractPanel *panel) const; + void buildViews(ImGuiID windowId, AbstractPanel *panel); static void createDockSpace(DockDTO *dockSpace, ImGuiID *dockMainId); diff --git a/src/editor/service/FilesService.cpp b/src/editor/service/FilesService.cpp index 78bc1b36..5b59131f 100644 --- a/src/editor/service/FilesService.cpp +++ b/src/editor/service/FilesService.cpp @@ -11,6 +11,7 @@ #include #include #include "../../common/serialization-definitions.h" +#include "../../core/DirectoryService.h" namespace fs = std::filesystem; @@ -26,14 +27,14 @@ std::filesystem::remove_all(rootDir + "/assets/" + F(entry.second->getId())); std::filesystem::file_time_type ftime = last_write_time(entry); namespace Metal { - void FilesService::onInitialize() { - root = new FSEntry(nullptr, rootDirectory + "/assets-ref/", ""); + void filesService->onInitialize() { + root = new FSEntry(nullptr, directoryService->getAssetRefDirectory(), ""); root->type = EntryType::DIRECTORY; root->name = "Files"; GetEntries(root); } - std::unique_ptr FilesService::getResource(const std::string &id) { + std::unique_ptr filesService->getResource(const std::string &id) { try { for (const auto &entry: fs::recursive_directory_iterator(root->absolutePath)) { if (entry.is_regular_file() && @@ -56,11 +57,11 @@ namespace Metal { return nullptr; } - void FilesService::deleteFiles(const std::unordered_map &selected) { + void filesService->deleteFiles(const std::unordered_map &selected) { for (auto &entry: selected) { switch (entry.second->type) { case EntryType::DIRECTORY: { - FilesService::GetEntries(entry.second); + GetEntries(entry.second); std::unordered_map files; for (auto *f: entry.second->children) { files.insert({f->getId(), f}); @@ -70,19 +71,19 @@ namespace Metal { break; } case EntryType::MESH: { - DELETE_F(FORMAT_FILE_MESH, rootDirectory) + DELETE_F(FORMAT_FILE_MESH, directoryService->getRootDirectory()) break; } case EntryType::TEXTURE: { - DELETE_F(FORMAT_FILE_TEXTURE, rootDirectory) + DELETE_F(FORMAT_FILE_TEXTURE, directoryService->getRootDirectory()) break; } case EntryType::SCENE: { - DELETE_S(FORMAT_FILE_SCENE, rootDirectory) + DELETE_S(FORMAT_FILE_SCENE, directoryService->getRootDirectory()) break; } case EntryType::VOLUME: { - DELETE_S(FORMAT_FILE_VOLUME, rootDirectory) + DELETE_S(FORMAT_FILE_VOLUME, directoryService->getRootDirectory()) break; } default: break;; @@ -90,7 +91,7 @@ namespace Metal { } } - void FilesService::CreateDirectory(FSEntry *currentDirectory) { + void filesService->CreateDirectory(FSEntry *currentDirectory) { int count = 0; for (FSEntry *child: currentDirectory->children) { if (child->type == EntryType::DIRECTORY && child->name == "New Directory (" + std::to_string(count) + ")") { @@ -104,7 +105,7 @@ namespace Metal { std::filesystem::create_directory(pathToDir); } - void FilesService::Move(FSEntry *toMove, FSEntry *targetDir) { + void filesService->Move(FSEntry *toMove, FSEntry *targetDir) { if (!targetDir || targetDir->type != EntryType::DIRECTORY) { return; } @@ -116,7 +117,7 @@ namespace Metal { fs::rename(sourcePath, targetPath); } catch (const fs::filesystem_error &e) { LOG_ERROR("Could not move file"); - notificationService.pushMessage("Could not move entry", NotificationSeverities::ERROR); + notificationService->pushMessage("Could not move entry", NotificationSeverities::ERROR); return; } @@ -132,7 +133,7 @@ namespace Metal { targetDir->children.push_back(toMove); } - void FilesService::GetEntries(FSEntry *root) { + void filesService->GetEntries(FSEntry *root) { if (root->type != EntryType::DIRECTORY) { return; } diff --git a/src/editor/service/FilesService.h b/src/editor/service/FilesService.h index 3ecca1a4..cdefef5a 100644 --- a/src/editor/service/FilesService.h +++ b/src/editor/service/FilesService.h @@ -35,9 +35,9 @@ namespace Metal { void Move(FSEntry *toMove, FSEntry *targetDir); - static void CreateDirectory(FSEntry *currentDirectory); + void CreateDirectory(FSEntry *currentDirectory); - static void GetEntries(FSEntry *root); + void GetEntries(FSEntry *root); }; } // Metal diff --git a/src/editor/service/ThemeService.cpp b/src/editor/service/ThemeService.cpp index 993a6c9c..d508d959 100644 --- a/src/editor/service/ThemeService.cpp +++ b/src/editor/service/ThemeService.cpp @@ -1,21 +1,23 @@ #include "ThemeService.h" -#include "../../ApplicationContext.h" +#include + +#include "../repository/EditorRepository.h" namespace Metal { glm::vec3 ThemeService::BACKGROUND_COLOR = glm::vec3(0.f); void ThemeService::onSync() { - if (previousTheme == editorRepository.isDarkMode && glm::length(editorRepository.accentColor) == prevLength) { + if (previousTheme == editorRepository->isDarkMode && glm::length(editorRepository->accentColor) == prevLength) { return; } - prevLength = glm::length(editorRepository.accentColor); - previousTheme = editorRepository.isDarkMode; + prevLength = glm::length(editorRepository->accentColor); + previousTheme = editorRepository->isDarkMode; ImGuiStyle &style = ImGui::GetStyle(); auto &colors = style.Colors; - if (!editorRepository.isDarkMode) { + if (!editorRepository->isDarkMode) { ImGui::StyleColorsLight(); setLightMode(); } else { @@ -60,24 +62,24 @@ namespace Metal { colors[ImGuiCol_NavWindowingDimBg] = palette2; colors[ImGuiCol_ModalWindowDimBg] = palette2; - editorRepository.accent.y = editorRepository.accentColor.y; - editorRepository.accent.z = editorRepository.accentColor.z; - editorRepository.accent.x = editorRepository.accentColor.x; - editorRepository.accent.w = 1; - editorRepository.accentU32 = ImGui::GetColorU32(editorRepository.accent); + editorRepository->accent.y = editorRepository->accentColor.y; + editorRepository->accent.z = editorRepository->accentColor.z; + editorRepository->accent.x = editorRepository->accentColor.x; + editorRepository->accent.w = 1; + editorRepository->accentU32 = ImGui::GetColorU32(editorRepository->accent); - colors[ImGuiCol_FrameBgHovered] = editorRepository.accent; - colors[ImGuiCol_FrameBgActive] = editorRepository.accent; - colors[ImGuiCol_CheckMark] = editorRepository.accent; - colors[ImGuiCol_SliderGrabActive] = editorRepository.accent; + colors[ImGuiCol_FrameBgHovered] = editorRepository->accent; + colors[ImGuiCol_FrameBgActive] = editorRepository->accent; + colors[ImGuiCol_CheckMark] = editorRepository->accent; + colors[ImGuiCol_SliderGrabActive] = editorRepository->accent; colors[ImGuiCol_Button] = palette3; - colors[ImGuiCol_ButtonHovered] = editorRepository.accent; - colors[ImGuiCol_Header] = editorRepository.accent; - colors[ImGuiCol_HeaderHovered] = editorRepository.accent; - colors[ImGuiCol_HeaderActive] = editorRepository.accent; - colors[ImGuiCol_ResizeGripHovered] = editorRepository.accent; - colors[ImGuiCol_ResizeGripActive] = editorRepository.accent; - colors[ImGuiCol_TextSelectedBg] = editorRepository.accent; + colors[ImGuiCol_ButtonHovered] = editorRepository->accent; + colors[ImGuiCol_Header] = editorRepository->accent; + colors[ImGuiCol_HeaderHovered] = editorRepository->accent; + colors[ImGuiCol_HeaderActive] = editorRepository->accent; + colors[ImGuiCol_ResizeGripHovered] = editorRepository->accent; + colors[ImGuiCol_ResizeGripActive] = editorRepository->accent; + colors[ImGuiCol_TextSelectedBg] = editorRepository->accent; BACKGROUND_COLOR[0] = colors[ImGuiCol_WindowBg].x; BACKGROUND_COLOR[1] = colors[ImGuiCol_WindowBg].y; diff --git a/src/engine/EngineContext.cpp b/src/engine/EngineContext.cpp index 23dcd9d2..ffdb7651 100644 --- a/src/engine/EngineContext.cpp +++ b/src/engine/EngineContext.cpp @@ -1,4 +1,6 @@ #include "EngineContext.h" + +#include "../ApplicationContext.h" #include "service/TransformService.h" #include "service/StreamingService.h" #include "service/RayTracingService.h" @@ -32,6 +34,22 @@ namespace Metal { } } + EngineFrameBuilder EngineContext::createFrame(const std::string &id) { + EngineFrameBuilder frameBuilder(id); + ctx->injectDependencies(&frameBuilder); + return frameBuilder; + } + + void EngineContext::setCurrentFrame(const std::string &id) { + for (auto *frame : registeredFrames) { + if (frame->getId() == id) { + currentFrame = frame; + return; + } + } + throw std::runtime_error("Frame not found"); + } + void EngineContext::dispose() { } diff --git a/src/engine/EngineContext.h b/src/engine/EngineContext.h index 127953c8..2e09a24e 100644 --- a/src/engine/EngineContext.h +++ b/src/engine/EngineContext.h @@ -1,7 +1,6 @@ #ifndef METAL_ENGINE_ENGINECONTEXT_H #define METAL_ENGINE_ENGINECONTEXT_H -#include "frame-builder/EngineFrame.h" #include #include @@ -9,6 +8,8 @@ #include "../common/IService.h" #include "../common/IDisposable.h" #include "../common/ISync.h" +#include "frame-builder/EngineFrame.h" +#include "frame-builder/EngineFrameBuilder.h" using Clock = std::chrono::high_resolution_clock; using TimePoint = std::chrono::time_point; @@ -23,6 +24,8 @@ namespace Metal { struct WorldRepository; struct EditorRepository; struct EngineRepository; + class EngineFrame; + class EngineFrameBuilder; class EngineContext final : public IService, public ISync, public IDisposable { TransformService *transformService = nullptr; @@ -77,6 +80,10 @@ namespace Metal { void updateCurrentTime(); + EngineFrameBuilder createFrame(const std::string &id); + + void setCurrentFrame(const std::string & id); + long long currentTimeMs = 0; TimePoint currentTime; TimePoint previousTime = Clock::now(); diff --git a/src/engine/enum/ComponentType.cpp b/src/engine/enum/ComponentType.cpp index 74fa1e67..14bed4bc 100644 --- a/src/engine/enum/ComponentType.cpp +++ b/src/engine/enum/ComponentType.cpp @@ -1,6 +1,13 @@ #include "ComponentType.h" + +#include "../EngineContext.h" #include "../repository/WorldRepository.h" +#include "../service/RayTracingService.h" #include "../../ApplicationContext.h" +#include "../dto/TransformComponent.h" +#include "../dto/PrimitiveComponent.h" +#include "../dto/VolumeComponent.h" +#include "../dto/MetadataComponent.h" #define DEFINE_COMPONENT(TYPE, NAME, JSON_KEY, ICON, DEPS, CLASS, CREATOR) \ { \ @@ -31,7 +38,7 @@ namespace Metal::ComponentTypes { [](WorldRepository &repo, entt::entity entityId) { auto &mesh = repo.registry.emplace_or_replace(entityId); mesh.setEntityId(entityId); - CTX.rayTracingService.markDirty(); + repo.rayTracingService->markDirty(); } ), DEFINE_COMPONENT( @@ -55,7 +62,7 @@ namespace Metal::ComponentTypes { [](WorldRepository &repo, entt::entity entityId) { auto &atmo = repo.registry.emplace_or_replace(entityId); atmo.setEntityId(entityId); - CTX.engineContext.setGISettingsUpdated(true); + repo.ctx->getSingleton().setGISettingsUpdated(true); } ) }; diff --git a/src/engine/enum/ComponentType.h b/src/engine/enum/ComponentType.h index 5cfc8fad..1b1350ad 100644 --- a/src/engine/enum/ComponentType.h +++ b/src/engine/enum/ComponentType.h @@ -7,6 +7,7 @@ #include namespace Metal { + class ApplicationContext; class Inspectable; struct WorldRepository; diff --git a/src/engine/frame-builder/EngineFrameBuilder.cpp b/src/engine/frame-builder/EngineFrameBuilder.cpp index e9295641..8d3359a8 100644 --- a/src/engine/frame-builder/EngineFrameBuilder.cpp +++ b/src/engine/frame-builder/EngineFrameBuilder.cpp @@ -7,6 +7,7 @@ #include "EngineFrame.h" #include "../../ApplicationContext.h" #include "../passes/CommandBufferRecorder.h" +#include "../EngineContext.h" namespace Metal { EngineFrameBuilder::EngineFrameBuilder(std::string frameId) : frameId(std::move(frameId)) { @@ -15,7 +16,7 @@ namespace Metal { EngineFrameBuilder &EngineFrameBuilder::addFramebuffer(std::string id, const unsigned w, const unsigned h, glm::vec4 clearColor) { currentBuilder = std::make_shared(frameId + "_" + id, w, h, clearColor); - builders.push_back(currentBuilder); + storeBuilder(); return *this; } @@ -38,7 +39,7 @@ namespace Metal { EngineFrameBuilder &EngineFrameBuilder::addTexture(const std::string &id, unsigned w, unsigned h, VkFormat format) { currentBuilder = std::make_shared(frameId + "_" + id, w, h, format); - builders.push_back(currentBuilder); + storeBuilder(); return *this; } @@ -56,7 +57,7 @@ namespace Metal { ? VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT : VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, properties, type); - builders.push_back(currentBuilder); + storeBuilder(); return *this; } @@ -71,13 +72,18 @@ namespace Metal { const bool clearBuffer) { currentBuilder = std::make_shared( frameId + "_" + id, frameId + "_" + framebufferId, clearBuffer); - builders.push_back(currentBuilder); + storeBuilder(); return *this; } + void EngineFrameBuilder::storeBuilder() { + ctx->injectDependencies(currentBuilder.get()); + builders.push_back(currentBuilder); + } + EngineFrameBuilder &EngineFrameBuilder::addComputeCommandBuffer(const std::string &id) { currentBuilder = std::make_shared(frameId + "_" + id); - builders.push_back(currentBuilder); + storeBuilder(); return *this; } @@ -97,8 +103,9 @@ namespace Metal { return false; } - std::unique_ptr EngineFrameBuilder::build() { - auto frame = std::make_unique(frameId); + void EngineFrameBuilder::build() { + auto *frame = new EngineFrame(frameId); + engineContext->registerFrame(frame); std::unordered_map builtResources; for (const auto &builder: builders) { @@ -108,23 +115,23 @@ namespace Metal { } } - std::unordered_map> > recorderToPasses; + std::unordered_map > > recorderToPasses; std::vector recorderOrder; for (auto &pass: passes) { recorderOrder.push_back(pass.commandBufferId); - pass.pass->frame = frame.get(); + pass.pass->frame = frame; + ctx->injectDependencies(pass.pass.get()); pass.pass->onInitialize(); recorderToPasses[pass.commandBufferId].push_back(std::move(pass.pass)); } for (const auto &cbId: recorderOrder) { - if (auto *recorder = dynamic_cast(builtResources.at(cbId))) { + if (auto *recorder = dynamic_cast(builtResources.at(cbId))) { frame->addPass(recorder, recorderToPasses[cbId]); } } - return frame; } } // Metal diff --git a/src/engine/frame-builder/EngineFrameBuilder.h b/src/engine/frame-builder/EngineFrameBuilder.h index 71ff3a60..e4b90114 100644 --- a/src/engine/frame-builder/EngineFrameBuilder.h +++ b/src/engine/frame-builder/EngineFrameBuilder.h @@ -1,16 +1,17 @@ #ifndef METAL_ENGINE_ENGINEFRAMEBUILDER_H #define METAL_ENGINE_ENGINEFRAMEBUILDER_H -#include #include #include #include #include #include +#include "../../common/IContextMember.h" #include "structures/ResourceBuilder.h" #include "../resource/BufferInstance.h" namespace Metal { + class EngineContext; class AbstractPass; class CommandBufferRecorder; struct FrameBufferInstance; @@ -23,14 +24,20 @@ namespace Metal { std::string commandBufferId; }; - class EngineFrameBuilder final { + class EngineFrameBuilder final : public IContextMember { std::string frameId; std::vector > builders{}; std::vector passes{}; std::shared_ptr currentBuilder{}; + EngineContext *engineContext = nullptr; public: + std::vector getDependencies() override { + return {{"EngineContext", engineContext}}; + } + explicit EngineFrameBuilder(std::string frameId = Util::uuidV4()); + EngineFrameBuilder &addFramebuffer(std::string id, unsigned w, unsigned h, glm::vec4 clearColor); EngineFrameBuilder &addFramebuffer(const std::string &id); @@ -39,7 +46,8 @@ namespace Metal { EngineFrameBuilder &addDepth(); - EngineFrameBuilder &addTexture(const std::string &id, unsigned w, unsigned h, VkFormat format = VK_FORMAT_R16G16B16A16_SFLOAT); + EngineFrameBuilder &addTexture(const std::string &id, unsigned w, unsigned h, + VkFormat format = VK_FORMAT_R16G16B16A16_SFLOAT); EngineFrameBuilder &addTexture(const std::string &id); @@ -48,7 +56,10 @@ namespace Metal { EngineFrameBuilder &addBuffer(const std::string &id); - EngineFrameBuilder &addCommandBuffer(const std::string &id, const std::string &framebufferId, bool clearBuffer = true); + EngineFrameBuilder &addCommandBuffer(const std::string &id, const std::string &framebufferId, + bool clearBuffer = true); + + void storeBuilder(); EngineFrameBuilder &addComputeCommandBuffer(const std::string &id); @@ -56,7 +67,7 @@ namespace Metal { bool tryMatch(const std::string &id, ResourceType type); - std::unique_ptr build(); + void build(); }; } // Metal diff --git a/src/engine/frame-builder/structures/BufferBuilder.cpp b/src/engine/frame-builder/structures/BufferBuilder.cpp index ce876357..950d8ee9 100644 --- a/src/engine/frame-builder/structures/BufferBuilder.cpp +++ b/src/engine/frame-builder/structures/BufferBuilder.cpp @@ -9,12 +9,12 @@ namespace Metal { } RuntimeResource *BufferBuilder::build() { - auto *buffer = CTX.bufferService.getResource(id); + auto *buffer = bufferService->getResource(id); if (buffer != nullptr) { return buffer; } - buffer = CTX.bufferService.createBuffer(id, size, usage, properties, type); + buffer = bufferService->createBuffer(id, size, usage, properties, type); buffer->setAsNoDisposal(); return buffer; diff --git a/src/engine/frame-builder/structures/BufferBuilder.h b/src/engine/frame-builder/structures/BufferBuilder.h index 740c9e69..60d18771 100644 --- a/src/engine/frame-builder/structures/BufferBuilder.h +++ b/src/engine/frame-builder/structures/BufferBuilder.h @@ -7,13 +7,20 @@ #include "../../resource/BufferInstance.h" namespace Metal { + class BufferService; + class BufferBuilder final : public ResourceBuilder { VkDeviceSize size; VkBufferUsageFlags usage; VkMemoryPropertyFlags properties; BufferType type; + BufferService *bufferService = nullptr; public: + std::vector getDependencies() override { + return {{"BufferService", bufferService}}; + } + explicit BufferBuilder(const std::string &id, VkDeviceSize size, VkBufferUsageFlags usage, VkMemoryPropertyFlags properties, BufferType type) : ResourceBuilder(id), size(size), usage(usage), properties(properties), type(type) { diff --git a/src/engine/frame-builder/structures/CommandBufferRecorderBuilder.cpp b/src/engine/frame-builder/structures/CommandBufferRecorderBuilder.cpp index abb3db0f..ea77203c 100644 --- a/src/engine/frame-builder/structures/CommandBufferRecorderBuilder.cpp +++ b/src/engine/frame-builder/structures/CommandBufferRecorderBuilder.cpp @@ -1,12 +1,13 @@ #include "CommandBufferRecorderBuilder.h" -#include "../../../ApplicationContext.h" +#include "../../service/CommandBufferRecorderService.h" +#include "../../service/FrameBufferService.h" namespace Metal { RuntimeResource *CommandBufferRecorderBuilder::build() { if (computeMode) { - return CTX.commandBufferRecorderService.createCompute(id); + return commandBufferRecorderService->createCompute(id); } - auto *fbo = CTX.framebufferService.getResource(framebufferId); - return CTX.commandBufferRecorderService.create(id, fbo, clearBuffer); + auto *fbo = framebufferService->getResource(framebufferId); + return commandBufferRecorderService->create(id, fbo, clearBuffer); } } diff --git a/src/engine/frame-builder/structures/CommandBufferRecorderBuilder.h b/src/engine/frame-builder/structures/CommandBufferRecorderBuilder.h index 22c7af72..e5a52121 100644 --- a/src/engine/frame-builder/structures/CommandBufferRecorderBuilder.h +++ b/src/engine/frame-builder/structures/CommandBufferRecorderBuilder.h @@ -4,14 +4,27 @@ #include "ResourceBuilder.h" namespace Metal { + class CommandBufferRecorderService; + class FrameBufferService; + class CommandBufferRecorderBuilder final : public ResourceBuilder { std::string framebufferId; bool clearBuffer; bool computeMode; + FrameBufferService *framebufferService = nullptr; + CommandBufferRecorderService *commandBufferRecorderService = nullptr; public: + std::vector getDependencies() override { + return { + {"FrameBufferService", framebufferService}, + {"CommandBufferRecorderService", commandBufferRecorderService} + }; + } + explicit CommandBufferRecorderBuilder(const std::string &id, std::string framebufferId, bool clearBuffer = true) - : ResourceBuilder(id), framebufferId(std::move(framebufferId)), clearBuffer(clearBuffer), computeMode(false) { + : ResourceBuilder(id), framebufferId(std::move(framebufferId)), clearBuffer(clearBuffer), + computeMode(false) { } explicit CommandBufferRecorderBuilder(const std::string &id) @@ -23,9 +36,9 @@ namespace Metal { } RuntimeResource *build() override; - + bool isComputeMode() const { return computeMode; } - const std::string& getFramebufferId() const { return framebufferId; } + const std::string &getFramebufferId() const { return framebufferId; } bool shouldClearBuffer() const { return clearBuffer; } }; } diff --git a/src/engine/frame-builder/structures/FramebufferBuilder.cpp b/src/engine/frame-builder/structures/FramebufferBuilder.cpp index 0978ee74..63adbdf7 100644 --- a/src/engine/frame-builder/structures/FramebufferBuilder.cpp +++ b/src/engine/frame-builder/structures/FramebufferBuilder.cpp @@ -5,28 +5,27 @@ namespace Metal { ResourceType FramebufferBuilder::getType() { - return ResourceType::FRAMEBUFFER; + return FRAMEBUFFER; } - RuntimeResource* FramebufferBuilder::build() { - auto &framebufferService = CTX.framebufferService; - FrameBufferInstance* fbo = framebufferService.getResource(id); + RuntimeResource *FramebufferBuilder::build() { + FrameBufferInstance *fbo = frameBufferService->getResource(id); if (fbo != nullptr) { return fbo; } - fbo = framebufferService.createFrameBuffer(id, w, h, clearColor); + fbo = frameBufferService->createFrameBuffer(id, w, h, clearColor); - for (const auto& attachment : attachments) { - framebufferService.createAttachment(attachment.format, attachment.usage, fbo); + for (const auto &attachment: attachments) { + frameBufferService->createAttachment(attachment.format, attachment.usage, fbo); } if (hasDepth) { - framebufferService.createDepthAttachment(fbo); + frameBufferService->createDepthAttachment(fbo); } - framebufferService.createRenderPass(fbo); + frameBufferService->createRenderPass(fbo); return fbo; } -} // Metal \ No newline at end of file +} // Metal diff --git a/src/engine/frame-builder/structures/FramebufferBuilder.h b/src/engine/frame-builder/structures/FramebufferBuilder.h index f5ebead5..b439cffa 100644 --- a/src/engine/frame-builder/structures/FramebufferBuilder.h +++ b/src/engine/frame-builder/structures/FramebufferBuilder.h @@ -6,6 +6,7 @@ #include "ResourceBuilder.h" namespace Metal { + class FrameBufferService; struct FrameBufferInstance; struct FramebufferAttachmentBuilder { @@ -20,8 +21,12 @@ namespace Metal { glm::vec4 clearColor; std::vector attachments; bool hasDepth = false; - + FrameBufferService *frameBufferService = nullptr; public: + std::vector getDependencies() override { + return {{"FrameBufferService", frameBufferService}}; + } + explicit FramebufferBuilder(const std::string &id, const unsigned w, const unsigned h, glm::vec4 clearColor) : ResourceBuilder(id), clearColor(clearColor), w(w), h(h) { } diff --git a/src/engine/frame-builder/structures/ResourceBuilder.h b/src/engine/frame-builder/structures/ResourceBuilder.h index c0bd11d5..1a5c8ba0 100644 --- a/src/engine/frame-builder/structures/ResourceBuilder.h +++ b/src/engine/frame-builder/structures/ResourceBuilder.h @@ -2,10 +2,12 @@ #define METAL_ENGINE_RESOURCEBUILDER_H #include #include "../../enum/ResourceType.h" +#include "../../../common/IContextMember.h" namespace Metal { class RuntimeResource; - class ResourceBuilder { + + class ResourceBuilder : public IContextMember { protected: std::string id; @@ -16,9 +18,10 @@ namespace Metal { [[nodiscard]] std::string getId() const { return id; } + virtual ~ResourceBuilder() = default; - virtual RuntimeResource* build() = 0; + virtual RuntimeResource *build() = 0; virtual ResourceType getType() = 0; }; diff --git a/src/engine/frame-builder/structures/TextureBuilder.cpp b/src/engine/frame-builder/structures/TextureBuilder.cpp index 91e17622..7b03b40e 100644 --- a/src/engine/frame-builder/structures/TextureBuilder.cpp +++ b/src/engine/frame-builder/structures/TextureBuilder.cpp @@ -1,19 +1,19 @@ #include "TextureBuilder.h" -#include "../../../ApplicationContext.h" #include "../../resource/TextureInstance.h" +#include "../../service/TextureService.h" namespace Metal { ResourceType TextureBuilder::getType() { - return ResourceType::TEXTURE; + return TEXTURE; } RuntimeResource *TextureBuilder::build() { - auto *texture = CTX.textureService.getResource(id); + auto *texture = textureService->getResource(id); if (texture != nullptr) { return texture; } - texture = CTX.textureService.createForCompute(id, w, h, format); + texture = textureService->createForCompute(id, w, h, format); texture->setAsNoDisposal(); return texture; diff --git a/src/engine/frame-builder/structures/TextureBuilder.h b/src/engine/frame-builder/structures/TextureBuilder.h index 1015fdae..3294e0e9 100644 --- a/src/engine/frame-builder/structures/TextureBuilder.h +++ b/src/engine/frame-builder/structures/TextureBuilder.h @@ -5,12 +5,18 @@ #include "ResourceBuilder.h" namespace Metal { + class TextureService; + class TextureBuilder final : public ResourceBuilder { unsigned w; unsigned h; VkFormat format; - + TextureService *textureService = nullptr; public: + std::vector getDependencies() override { + return {{"TextureService", textureService}}; + } + explicit TextureBuilder(const std::string &id, unsigned w, unsigned h, VkFormat format = VK_FORMAT_R16G16B16A16_SFLOAT) : ResourceBuilder(id), w(w), h(h), format(format) { } diff --git a/src/engine/passes/AbstractPass.h b/src/engine/passes/AbstractPass.h index be268269..2cd69f9f 100644 --- a/src/engine/passes/AbstractPass.h +++ b/src/engine/passes/AbstractPass.h @@ -3,6 +3,8 @@ #include #include #include + +#include "../../common/IContextMember.h" #include "../../common/ISync.h" #include "../../common/IInit.h" #include "../resource/RuntimeResource.h" @@ -14,7 +16,7 @@ namespace Metal { class StreamingService; struct PipelineInstance; - class AbstractPass : public ISync, public IInit { + class AbstractPass : public IContextMember, public ISync, public IInit { bool isComputePass; public: diff --git a/src/engine/passes/CommandBufferRecorder.cpp b/src/engine/passes/CommandBufferRecorder.cpp index 03f9b60c..e523f940 100644 --- a/src/engine/passes/CommandBufferRecorder.cpp +++ b/src/engine/passes/CommandBufferRecorder.cpp @@ -7,16 +7,18 @@ #include "../../ApplicationContext.h" #include "AbstractRenderPass.h" #include "../../core/vulkan/VulkanUtils.h" +#include "../../core/vulkan/VulkanContext.h" +#include "../../core/FrameService.h" namespace Metal { void CommandBufferRecorder::createCommandBuffer() { VkCommandBufferAllocateInfo allocInfo{}; allocInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; - allocInfo.commandPool = CTX.vulkanContext.commandPool; + allocInfo.commandPool = vulkanContext->commandPool; allocInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; allocInfo.commandBufferCount = MAX_FRAMES_IN_FLIGHT; VulkanUtils::CheckVKResult( - vkAllocateCommandBuffers(CTX.vulkanContext.device.device, &allocInfo, + vkAllocateCommandBuffers(vulkanContext->device.device, &allocInfo, _commandBuffers.data())); } @@ -71,7 +73,7 @@ namespace Metal { void CommandBufferRecorder::recordCommands( const std::vector> &passes) const { - auto vkCommandBuffer = _commandBuffers[CTX.getFrameIndex()]; + auto vkCommandBuffer = _commandBuffers[frameService->getFrameIndex()]; VkCommandBufferBeginInfo beginInfo{}; beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; vkBeginCommandBuffer(vkCommandBuffer, &beginInfo); @@ -87,7 +89,7 @@ namespace Metal { } vkEndCommandBuffer(vkCommandBuffer); - CTX.vulkanContext.pushCommandBuffer(vkCommandBuffer); + vulkanContext->pushCommandBuffer(vkCommandBuffer); } void CommandBufferRecorder::RecordCommandsInternal( diff --git a/src/engine/passes/CommandBufferRecorder.h b/src/engine/passes/CommandBufferRecorder.h index a188280f..e5348c57 100644 --- a/src/engine/passes/CommandBufferRecorder.h +++ b/src/engine/passes/CommandBufferRecorder.h @@ -7,6 +7,7 @@ #include "../../core/vulkan/VulkanUtils.h" namespace Metal { + class FrameService; class AbstractPass; class ApplicationContext; struct FrameBufferInstance; @@ -18,14 +19,19 @@ namespace Metal { VkRenderPassBeginInfo renderPassInfo{}; std::vector clearColors{}; bool computePassMode; + FrameService *frameService = nullptr; static void RecordCommandsInternal( - const std::vector> &passes, + const std::vector > &passes, VkCommandBuffer vkCommandBuffer); void createRenderPassInfo(const FrameBufferInstance *frameBuffer, bool clearBuffer); public: + std::vector getDependencies() override { + return {{"FrameService", frameService}, {"VulkanContext", vulkanContext}}; + } + explicit CommandBufferRecorder(std::string id, FrameBufferInstance *frameBuffer, bool clearBuffer = true); explicit CommandBufferRecorder(std::string id); @@ -36,7 +42,7 @@ namespace Metal { void createCommandBuffer(); - void recordCommands(const std::vector> &passes) const; + void recordCommands(const std::vector > &passes) const; }; } // Metal diff --git a/src/engine/passes/impl/HWRayTracingPass.cpp b/src/engine/passes/impl/HWRayTracingPass.cpp index cc537f3e..af2574ea 100644 --- a/src/engine/passes/impl/HWRayTracingPass.cpp +++ b/src/engine/passes/impl/HWRayTracingPass.cpp @@ -1,9 +1,12 @@ #include "HWRayTracingPass.h" -#include "../../../ApplicationContext.h" #include "../../dto/PipelineBuilder.h" #include "../../resource/PipelineInstance.h" #include "../../resource/TextureInstance.h" #include "../../service/RayTracingService.h" +#include "../../service/PipelineService.h" +#include "../../../core/vulkan/VulkanContext.h" +#include "../../../engine/EngineContext.h" +#include "../../../engine/repository/EngineRepository.h" #include "../../../editor/enum/EngineResourceIDs.h" namespace Metal { @@ -14,16 +17,16 @@ namespace Metal { "rt/HWRayTracing.rchit") .setPushConstantsSize(sizeof(HWRayTracingPushConstant)) .addBufferBinding(getScopedResourceId(RID_GLOBAL_DATA)) - .addAccelerationStructureBinding(CTX.rayTracingService.getTLAS()) + .addAccelerationStructureBinding(rayTracingService->getTLAS()) .addStorageImageBinding(getScopedResourceId(RID_ACCUMULATED_FRAME)) .addStorageImageBinding(getScopedResourceId(RID_GBUFFER_POSITION_INDEX)) .addStorageImageBinding(getScopedResourceId(RID_GBUFFER_NORMAL)) .addBufferBinding(getScopedResourceId(RID_LIGHT_BUFFER)) .addBufferBinding(getScopedResourceId(RID_VOLUMES_BUFFER)) .addBufferBinding(getScopedResourceId(RID_MESH_METADATA_BUFFER)) - .addCombinedImageSamplerBinding(CTX.vulkanContext.vkImageSampler, VK_NULL_HANDLE, + .addCombinedImageSamplerBinding(vulkanContext->vkImageSampler, VK_NULL_HANDLE, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, 1000); - pipelineInstance = CTX.pipelineService.createPipeline(builder); + pipelineInstance = pipelineService->createPipeline(builder); } void HWRayTracingPass::onSync() { @@ -33,9 +36,9 @@ namespace Metal { auto *previousPositionIndex = frame->getResourceAs(RID_PREVIOUS_POSITION_INDEX); auto *previousNormal = frame->getResourceAs(RID_PREVIOUS_NORMAL); - if (isFirstRun || CTX.engineContext.isCameraUpdated() || CTX.engineContext.isGISettingsUpdated()) { + if (isFirstRun || engineContext->isCameraUpdated() || engineContext->isGISettingsUpdated()) { clearTexture(accumulatedFrame->vkImage); - CTX.engineContext.resetPathTracerAccumulationCount(); + engineContext->resetPathTracerAccumulationCount(); isFirstRun = false; } @@ -46,24 +49,24 @@ namespace Metal { startWriting(gBufferNormal->vkImage); // Trace rays - pushConstant.pathTracerMultiplier = CTX.engineRepository.pathTracerMultiplier; - pushConstant.volumeShadowSteps = CTX.engineRepository.volumeShadowSteps; - pushConstant.isAtmosphereEnabled = CTX.engineRepository.atmosphereEnabled; + pushConstant.pathTracerMultiplier = engineRepository->pathTracerMultiplier; + pushConstant.volumeShadowSteps = engineRepository->volumeShadowSteps; + pushConstant.isAtmosphereEnabled = engineRepository->atmosphereEnabled; - pushConstant.multipleImportanceSampling = CTX.engineRepository.multipleImportanceSampling; - pushConstant.pathTracerSamples = CTX.engineRepository.pathTracerSamples; - pushConstant.pathTracerBounces = CTX.engineRepository.pathTracerBounces; - pushConstant.pathTracingEmissiveFactor = CTX.engineRepository.pathTracingEmissiveFactor; - pushConstant.shouldTrace = CTX.rayTracingService.isReady(); + pushConstant.multipleImportanceSampling = engineRepository->multipleImportanceSampling; + pushConstant.pathTracerSamples = engineRepository->pathTracerSamples; + pushConstant.pathTracerBounces = engineRepository->pathTracerBounces; + pushConstant.pathTracingEmissiveFactor = engineRepository->pathTracingEmissiveFactor; + pushConstant.shouldTrace = rayTracingService->isReady(); - pushConstant.dofEnabled = CTX.engineRepository.dofEnabled; - pushConstant.dofFocusDistance = CTX.engineRepository.dofFocusDistance; - pushConstant.dofAperture = CTX.engineRepository.dofAperture; - pushConstant.dofFocalLength = CTX.engineRepository.dofFocalLength; + pushConstant.dofEnabled = engineRepository->dofEnabled; + pushConstant.dofFocusDistance = engineRepository->dofFocusDistance; + pushConstant.dofAperture = engineRepository->dofAperture; + pushConstant.dofFocalLength = engineRepository->dofFocalLength; recordPushConstant(&pushConstant); - CTX.vulkanContext.vkCmdTraceRaysKHR( + vulkanContext->vkCmdTraceRaysKHR( vkCommandBuffer, &pipelineInstance->raygenRegion, &pipelineInstance->missRegion, diff --git a/src/engine/passes/impl/HWRayTracingPass.h b/src/engine/passes/impl/HWRayTracingPass.h index de0d0f70..c8e9601a 100644 --- a/src/engine/passes/impl/HWRayTracingPass.h +++ b/src/engine/passes/impl/HWRayTracingPass.h @@ -4,11 +4,33 @@ #include "../../dto/HWRayTracingPushConstant.h" namespace Metal { + class RayTracingService; + class PipelineService; + class VulkanContext; + class EngineContext; + struct EngineRepository; + class HWRayTracingPass final : public AbstractComputePass { bool isFirstRun = true; HWRayTracingPushConstant pushConstant{}; + RayTracingService *rayTracingService = nullptr; + PipelineService *pipelineService = nullptr; + VulkanContext *vulkanContext = nullptr; + EngineContext *engineContext = nullptr; + EngineRepository *engineRepository = nullptr; + public: + std::vector getDependencies() override { + return { + {"RayTracingService", rayTracingService}, + {"PipelineService", pipelineService}, + {"VulkanContext", vulkanContext}, + {"EngineContext", engineContext}, + {"EngineRepository", engineRepository} + }; + } + void onSync() override; void onInitialize() override; diff --git a/src/engine/passes/impl/PostProcessingPass.cpp b/src/engine/passes/impl/PostProcessingPass.cpp index 67aab25f..f16d3d5d 100644 --- a/src/engine/passes/impl/PostProcessingPass.cpp +++ b/src/engine/passes/impl/PostProcessingPass.cpp @@ -1,9 +1,11 @@ #include "PostProcessingPass.h" - -#include "../../../ApplicationContext.h" - #include "../../dto/PipelineBuilder.h" +#include "../../service/PipelineService.h" +#include "../../../core/vulkan/VulkanContext.h" +#include "../../../engine/repository/WorldRepository.h" #include "../../../editor/enum/EngineResourceIDs.h" +#include "../../frame-builder/EngineFrame.h" +#include "../../resource/TextureInstance.h" namespace Metal { @@ -14,12 +16,12 @@ namespace Metal { "PostProcessing.frag" ) .setPushConstantsSize(sizeof(PostProcessingPushConstant)) - .addCombinedImageSamplerBinding(CTX.vulkanContext.vkImageSampler, frame->getResourceAs(RID_DENOISED_FRAME)->vkImageView); - pipelineInstance = CTX.pipelineService.createPipeline(ppPipelineBuilder); + .addCombinedImageSamplerBinding(vulkanContext->vkImageSampler, frame->getResourceAs(RID_DENOISED_FRAME)->vkImageView); + pipelineInstance = pipelineService->createPipeline(ppPipelineBuilder); } void PostProcessingPass::onSync() { - auto &camera = CTX.worldRepository.camera; + auto &camera = worldRepository->camera; pushConstant.distortionIntensity = camera.distortionIntensity; pushConstant.chromaticAberrationIntensity = camera.chromaticAberrationIntensity; pushConstant.distortionEnabled = camera.distortionEnabled; diff --git a/src/engine/passes/impl/PostProcessingPass.h b/src/engine/passes/impl/PostProcessingPass.h index 08e60b2c..9cf49ab9 100644 --- a/src/engine/passes/impl/PostProcessingPass.h +++ b/src/engine/passes/impl/PostProcessingPass.h @@ -4,9 +4,26 @@ #include "../../dto/PostProcessingPushConstant.h" namespace Metal { + class VulkanContext; + class PipelineService; + struct WorldRepository; + class PostProcessingPass final : public AbstractRenderPass { PostProcessingPushConstant pushConstant{}; + + VulkanContext *vulkanContext = nullptr; + PipelineService *pipelineService = nullptr; + WorldRepository *worldRepository = nullptr; + public: + std::vector getDependencies() override { + return { + {"VulkanContext", vulkanContext}, + {"PipelineService", pipelineService}, + {"WorldRepository", worldRepository} + }; + } + void onInitialize() override; void onSync() override; diff --git a/src/engine/passes/impl/SpatialFilterPass.cpp b/src/engine/passes/impl/SpatialFilterPass.cpp index 291d7b5f..ee34a76f 100644 --- a/src/engine/passes/impl/SpatialFilterPass.cpp +++ b/src/engine/passes/impl/SpatialFilterPass.cpp @@ -1,7 +1,8 @@ #include "SpatialFilterPass.h" -#include "../../../ApplicationContext.h" #include "../../dto/PipelineBuilder.h" #include "../../resource/TextureInstance.h" +#include "../../service/PipelineService.h" +#include "../../frame-builder/EngineFrame.h" #include "../../../editor/enum/EngineResourceIDs.h" namespace Metal { @@ -12,7 +13,7 @@ namespace Metal { .addStorageImageBinding(getScopedResourceId(RID_DENOISED_FRAME)) .addStorageImageBinding(getScopedResourceId(RID_GBUFFER_POSITION_INDEX)) .addStorageImageBinding(getScopedResourceId(RID_GBUFFER_NORMAL)); - pipelineInstance = CTX.pipelineService.createPipeline(spatialBuilder); + pipelineInstance = pipelineService->createPipeline(spatialBuilder); } void SpatialFilterPass::onSync() { diff --git a/src/engine/passes/impl/SpatialFilterPass.h b/src/engine/passes/impl/SpatialFilterPass.h index 838a353f..9edd07ca 100644 --- a/src/engine/passes/impl/SpatialFilterPass.h +++ b/src/engine/passes/impl/SpatialFilterPass.h @@ -3,8 +3,18 @@ #include "../AbstractComputePass.h" namespace Metal { + class PipelineService; + class SpatialFilterPass final : public AbstractComputePass { + PipelineService *pipelineService = nullptr; + public: + std::vector getDependencies() override { + return { + {"PipelineService", pipelineService} + }; + } + void onSync() override; void onInitialize() override; diff --git a/src/engine/passes/impl/TemporalAccumulationPass.cpp b/src/engine/passes/impl/TemporalAccumulationPass.cpp index e1d1029d..68c751aa 100644 --- a/src/engine/passes/impl/TemporalAccumulationPass.cpp +++ b/src/engine/passes/impl/TemporalAccumulationPass.cpp @@ -1,7 +1,8 @@ #include "TemporalAccumulationPass.h" -#include "../../../ApplicationContext.h" #include "../../dto/PipelineBuilder.h" #include "../../resource/TextureInstance.h" +#include "../../service/PipelineService.h" +#include "../../frame-builder/EngineFrame.h" #include "../../../editor/enum/EngineResourceIDs.h" namespace Metal { @@ -15,7 +16,7 @@ namespace Metal { .addStorageImageBinding(getScopedResourceId(RID_PREVIOUS_POSITION_INDEX)) .addStorageImageBinding(getScopedResourceId(RID_GBUFFER_NORMAL)) .addStorageImageBinding(getScopedResourceId(RID_PREVIOUS_NORMAL)); - pipelineInstance = CTX.pipelineService.createPipeline(temporalBuilder); + pipelineInstance = pipelineService->createPipeline(temporalBuilder); } void TemporalAccumulationPass::onSync() { diff --git a/src/engine/passes/impl/TemporalAccumulationPass.h b/src/engine/passes/impl/TemporalAccumulationPass.h index a95b2c3f..ff7c467c 100644 --- a/src/engine/passes/impl/TemporalAccumulationPass.h +++ b/src/engine/passes/impl/TemporalAccumulationPass.h @@ -3,8 +3,17 @@ #include "../AbstractComputePass.h" namespace Metal { + class PipelineService; + class TemporalAccumulationPass final : public AbstractComputePass { + PipelineService *pipelineService = nullptr; + public: + std::vector getDependencies() override { + return { + {"PipelineService", pipelineService} + }; + } void onSync() override; diff --git a/src/engine/repository/WorldRepository.h b/src/engine/repository/WorldRepository.h index 737df3dd..8ed4ee40 100644 --- a/src/engine/repository/WorldRepository.h +++ b/src/engine/repository/WorldRepository.h @@ -15,8 +15,8 @@ namespace Metal { class DirectoryService; struct WorldRepository final : IRepository { - RayTracingService *rayTracingService; - DirectoryService *directoryService; + RayTracingService *rayTracingService = nullptr; + DirectoryService *directoryService = nullptr; Camera camera{-(glm::pi() / 4), glm::pi() / 4, {10, 10, 10}}; entt::registry registry{}; @@ -25,8 +25,8 @@ namespace Metal { std::vector getDependencies() override { return { - {"RayTracingService", rayTracingService}, - {"DirectoryService", directoryService} + {"RayTracingService", rayTracingService}, + {"DirectoryService", directoryService} }; } diff --git a/src/engine/resource/FrameBufferAttachment.cpp b/src/engine/resource/FrameBufferAttachment.cpp index 3e830173..00bbfe33 100644 --- a/src/engine/resource/FrameBufferAttachment.cpp +++ b/src/engine/resource/FrameBufferAttachment.cpp @@ -1,16 +1,15 @@ #include "FrameBufferAttachment.h" - - -#include "../../ApplicationContext.h" +#include "../service/DescriptorSetService.h" +#include "../../core/vulkan/VulkanContext.h" namespace Metal { void FrameBufferAttachment::dispose() const { - vkDestroyImage(CTX.vulkanContext.device.device, vkImage, nullptr); - vkDestroyImageView(CTX.vulkanContext.device.device, vkImageView, nullptr); - vkFreeMemory(CTX.vulkanContext.device.device, vkImageMemory, nullptr); + vkDestroyImage(vulkanContext->device.device, vkImage, nullptr); + vkDestroyImageView(vulkanContext->device.device, vkImageView, nullptr); + vkFreeMemory(vulkanContext->device.device, vkImageMemory, nullptr); if (imageDescriptor != nullptr) { - CTX.descriptorSetService.disposeResource(imageDescriptor); + descriptorSetService->disposeResource(imageDescriptor); } } } diff --git a/src/engine/resource/FrameBufferAttachment.h b/src/engine/resource/FrameBufferAttachment.h index 6e559c13..6a1b102c 100644 --- a/src/engine/resource/FrameBufferAttachment.h +++ b/src/engine/resource/FrameBufferAttachment.h @@ -3,7 +3,9 @@ #include "../dto/DescriptorInstance.h" namespace Metal { - struct FrameBufferAttachment final { + class DescriptorSetService; + + struct FrameBufferAttachment final : IContextMember { VkImage vkImage = VK_NULL_HANDLE; VkDeviceMemory vkImageMemory = VK_NULL_HANDLE; VkImageView vkImageView = VK_NULL_HANDLE; @@ -12,6 +14,10 @@ namespace Metal { bool depth = false; void dispose() const; + + private: + VulkanContext *vulkanContext = nullptr; + DescriptorSetService *descriptorSetService = nullptr; }; } diff --git a/src/engine/resource/RuntimeResource.h b/src/engine/resource/RuntimeResource.h index a99d4632..e3952bcc 100644 --- a/src/engine/resource/RuntimeResource.h +++ b/src/engine/resource/RuntimeResource.h @@ -4,20 +4,29 @@ #include "../../editor/util/Util.h" #include +#include "../../common/IContextMember.h" + using Clock = std::chrono::high_resolution_clock; using TimePoint = std::chrono::time_point; namespace Metal { class VulkanContext; - class RuntimeResource { + class RuntimeResource : public IContextMember { const std::string id; bool noDisposal = false; - std::vector empty{}; + + protected: + VulkanContext *vulkanContext = nullptr; + public: + std::vector getDependencies() override { + return {{"VulkanContext", vulkanContext}}; + } + virtual ~RuntimeResource() = default; - explicit RuntimeResource(const std::string &id = Util::uuidV4()): id(std::move(id)) { + explicit RuntimeResource(const std::string &id = Util::uuidV4()) : id(id) { } [[nodiscard]] std::string getId() const { @@ -35,10 +44,6 @@ namespace Metal { virtual ResourceType resourceType() { throw std::runtime_error("Not implemented"); } - - virtual std::vector &getDependencies() { - return empty; - } }; } #endif diff --git a/src/engine/service/BufferService.cpp b/src/engine/service/BufferService.cpp index c0931b71..d6523bf1 100644 --- a/src/engine/service/BufferService.cpp +++ b/src/engine/service/BufferService.cpp @@ -10,7 +10,7 @@ namespace Metal { VkMemoryPropertyFlags memoryPropertyFlags, BufferType type) { BufferInstance *buffer = createResourceInstance(id, bufferSize, type); createVkBuffer(usageFlags, memoryPropertyFlags, buffer); - vkMapMemory(vulkanContext.device.device, buffer->vkDeviceMemory, 0, bufferSize, 0, &buffer->mapped); + vkMapMemory(vulkanContext->device.device, buffer->vkDeviceMemory, 0, bufferSize, 0, &buffer->mapped); return buffer; } @@ -23,10 +23,10 @@ namespace Metal { createVkBuffer(VK_BUFFER_USAGE_TRANSFER_SRC_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, stagingBuffer); - vkMapMemory(vulkanContext.device.device, stagingBuffer->vkDeviceMemory, 0, dataSize, 0, + vkMapMemory(vulkanContext->device.device, stagingBuffer->vkDeviceMemory, 0, dataSize, 0, &stagingBuffer->mapped); memcpy(stagingBuffer->mapped, bufferData, dataSize); - vkUnmapMemory(vulkanContext.device.device, stagingBuffer->vkDeviceMemory); + vkUnmapMemory(vulkanContext->device.device, stagingBuffer->vkDeviceMemory); createVkBuffer(VK_BUFFER_USAGE_TRANSFER_DST_BIT | usageFlags, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, finalBuffer); @@ -38,8 +38,8 @@ namespace Metal { } unsigned int BufferService::findMemoryType(unsigned int typeFilter, VkMemoryPropertyFlags properties) const { - for (unsigned int i = 0; i < vulkanContext.physicalDeviceMemoryProperties.memoryTypeCount; i++) { - if ((typeFilter & (1 << i)) && (vulkanContext.physicalDeviceMemoryProperties.memoryTypes[i]. + for (unsigned int i = 0; i < vulkanContext->physicalDeviceMemoryProperties.memoryTypeCount; i++) { + if ((typeFilter & (1 << i)) && (vulkanContext->physicalDeviceMemoryProperties.memoryTypes[i]. propertyFlags & properties) == properties) { return i; @@ -57,31 +57,31 @@ namespace Metal { bufferInfo.usage = usage; bufferInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE; - VulkanUtils::CheckVKResult(vkCreateBuffer(vulkanContext.device.device, &bufferInfo, nullptr, + VulkanUtils::CheckVKResult(vkCreateBuffer(vulkanContext->device.device, &bufferInfo, nullptr, &buffer->vkBuffer)); VkMemoryRequirements memRequirements; - vkGetBufferMemoryRequirements(vulkanContext.device.device, buffer->vkBuffer, &memRequirements); + vkGetBufferMemoryRequirements(vulkanContext->device.device, buffer->vkBuffer, &memRequirements); VkMemoryAllocateInfo allocInfo{}; allocInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; allocInfo.allocationSize = memRequirements.size; allocInfo.memoryTypeIndex = findMemoryType(memRequirements.memoryTypeBits, properties); - VulkanUtils::CheckVKResult(vkAllocateMemory(vulkanContext.device.device, &allocInfo, nullptr, + VulkanUtils::CheckVKResult(vkAllocateMemory(vulkanContext->device.device, &allocInfo, nullptr, &buffer->vkDeviceMemory)); - vkBindBufferMemory(vulkanContext.device.device, buffer->vkBuffer, buffer->vkDeviceMemory, 0); + vkBindBufferMemory(vulkanContext->device.device, buffer->vkBuffer, buffer->vkDeviceMemory, 0); } void BufferService::copyBuffer(const BufferInstance *srcBuffer, const BufferInstance *dstBuffer) const { - VkCommandBuffer commandBuffer = vulkanContext.beginSingleTimeCommands(); + VkCommandBuffer commandBuffer = vulkanContext->beginSingleTimeCommands(); VkBufferCopy copyRegion{}; copyRegion.size = dstBuffer->dataSize; vkCmdCopyBuffer(commandBuffer, srcBuffer->vkBuffer, dstBuffer->vkBuffer, 1, ©Region); - vulkanContext.endSingleTimeCommands(commandBuffer); + vulkanContext->endSingleTimeCommands(commandBuffer); } BufferInstance *BufferService::createBuffer(const std::string &id, VkDeviceSize bufferSize, @@ -99,11 +99,11 @@ namespace Metal { } bufferInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE; - VulkanUtils::CheckVKResult(vkCreateBuffer(vulkanContext.device.device, &bufferInfo, nullptr, + VulkanUtils::CheckVKResult(vkCreateBuffer(vulkanContext->device.device, &bufferInfo, nullptr, &buffer->vkBuffer)); VkMemoryRequirements memRequirements; - vkGetBufferMemoryRequirements(vulkanContext.device.device, buffer->vkBuffer, &memRequirements); + vkGetBufferMemoryRequirements(vulkanContext->device.device, buffer->vkBuffer, &memRequirements); VkMemoryAllocateInfo allocInfo{}; allocInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; @@ -117,12 +117,12 @@ namespace Metal { allocInfo.pNext = &allocFlagsInfo; } - VulkanUtils::CheckVKResult(vkAllocateMemory(vulkanContext.device.device, &allocInfo, nullptr, + VulkanUtils::CheckVKResult(vkAllocateMemory(vulkanContext->device.device, &allocInfo, nullptr, &buffer->vkDeviceMemory)); - vkBindBufferMemory(vulkanContext.device.device, buffer->vkBuffer, buffer->vkDeviceMemory, 0); + vkBindBufferMemory(vulkanContext->device.device, buffer->vkBuffer, buffer->vkDeviceMemory, 0); if (memoryPropertyFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) { - vkMapMemory(vulkanContext.device.device, buffer->vkDeviceMemory, 0, bufferSize, 0, &buffer->mapped); + vkMapMemory(vulkanContext->device.device, buffer->vkDeviceMemory, 0, bufferSize, 0, &buffer->mapped); } return buffer; @@ -137,10 +137,10 @@ namespace Metal { createVkBuffer(VK_BUFFER_USAGE_TRANSFER_SRC_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, stagingBuffer); - vkMapMemory(vulkanContext.device.device, stagingBuffer->vkDeviceMemory, 0, dataSize, 0, + vkMapMemory(vulkanContext->device.device, stagingBuffer->vkDeviceMemory, 0, dataSize, 0, &stagingBuffer->mapped); memcpy(stagingBuffer->mapped, bufferData, dataSize); - vkUnmapMemory(vulkanContext.device.device, stagingBuffer->vkDeviceMemory); + vkUnmapMemory(vulkanContext->device.device, stagingBuffer->vkDeviceMemory); auto *finalBuffer = createBuffer(id, dataSize, VK_BUFFER_USAGE_TRANSFER_DST_BIT | usageFlags, @@ -153,7 +153,7 @@ namespace Metal { } void BufferService::disposeResource(BufferInstance *resource) { - vkDestroyBuffer(vulkanContext.device.device, resource->vkBuffer, nullptr); - vkFreeMemory(vulkanContext.device.device, resource->vkDeviceMemory, nullptr); + vkDestroyBuffer(vulkanContext->device.device, resource->vkBuffer, nullptr); + vkFreeMemory(vulkanContext->device.device, resource->vkDeviceMemory, nullptr); } } // Metal diff --git a/src/engine/service/DescriptorSetService.cpp b/src/engine/service/DescriptorSetService.cpp index 71a8a55d..e1ea7d22 100644 --- a/src/engine/service/DescriptorSetService.cpp +++ b/src/engine/service/DescriptorSetService.cpp @@ -31,7 +31,7 @@ namespace Metal { binding.attachmentIndex = builder.attachmentIndex; if (builder.type == DescriptorBindingType::FBO_ATTACHMENT) { - auto *fbo = framebufferService.getResource(binding.frameBufferId); + auto *fbo = framebufferService->getResource(binding.frameBufferId); if (fbo == nullptr) { throw std::runtime_error("Framebuffer not found: " + binding.frameBufferId); } @@ -62,7 +62,7 @@ namespace Metal { binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; break; case DescriptorBindingType::STORAGE_IMAGE: { - auto *texture = textureService.getResource(binding.storageImageId); + auto *texture = textureService->getResource(binding.storageImageId); if (texture == nullptr) { throw std::runtime_error("Storage image texture not found: " + binding.storageImageId); } diff --git a/src/engine/service/FrameBufferService.cpp b/src/engine/service/FrameBufferService.cpp index b1bedf37..0292ea33 100644 --- a/src/engine/service/FrameBufferService.cpp +++ b/src/engine/service/FrameBufferService.cpp @@ -1,7 +1,6 @@ #include "FrameBufferService.h" #include -#include #include #include "../resource/FrameBufferInstance.h" @@ -9,6 +8,7 @@ #include "../../core/vulkan/VulkanUtils.h" #include "../resource/FrameBufferAttachment.h" #include "../../ApplicationContext.h" +#include "../../common/LoggerUtil.h" namespace Metal { @@ -23,7 +23,7 @@ namespace Metal { } void FrameBufferService::createDepthAttachment(FrameBufferInstance *framebuffer) const { - VkFormat depthFormat = VulkanUtils::GetValidDepthFormat(vulkanContext.physDevice.physical_device); + VkFormat depthFormat = VulkanUtils::GetValidDepthFormat(vulkanContext->physDevice.physical_device); const auto att = createAttachmentInternal(depthFormat, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, framebuffer); att->depth = true; @@ -42,6 +42,7 @@ namespace Metal { VkImageUsageFlagBits usage, FrameBufferInstance *framebuffer) const { std::shared_ptr attachment = std::make_shared(); + ctx->injectDependencies(attachment.get()); framebuffer->attachments.push_back(attachment); attachment->format = format; @@ -73,20 +74,20 @@ namespace Metal { image.sharingMode = VK_SHARING_MODE_EXCLUSIVE; VulkanUtils::CheckVKResult( - vkCreateImage(vulkanContext.device.device, &image, nullptr, &attachment->vkImage)); + vkCreateImage(vulkanContext->device.device, &image, nullptr, &attachment->vkImage)); VkMemoryAllocateInfo memAlloc{}; VkMemoryRequirements memReqs; - vkGetImageMemoryRequirements(vulkanContext.device.device, attachment->vkImage, &memReqs); + vkGetImageMemoryRequirements(vulkanContext->device.device, attachment->vkImage, &memReqs); memAlloc.allocationSize = memReqs.size; - memAlloc.memoryTypeIndex = VulkanUtils::GetMemTypeIndex(vulkanContext.physicalDeviceMemoryProperties, + memAlloc.memoryTypeIndex = VulkanUtils::GetMemTypeIndex(vulkanContext->physicalDeviceMemoryProperties, memReqs.memoryTypeBits, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT); - VulkanUtils::CheckVKResult(vkAllocateMemory(vulkanContext.device.device, &memAlloc, nullptr, + VulkanUtils::CheckVKResult(vkAllocateMemory(vulkanContext->device.device, &memAlloc, nullptr, &attachment->vkImageMemory)); VulkanUtils::CheckVKResult( - vkBindImageMemory(vulkanContext.device.device, attachment->vkImage, attachment->vkImageMemory, 0)); + vkBindImageMemory(vulkanContext->device.device, attachment->vkImage, attachment->vkImageMemory, 0)); VkImageViewCreateInfo imageView{}; imageView.viewType = VK_IMAGE_VIEW_TYPE_2D; @@ -98,7 +99,7 @@ namespace Metal { imageView.subresourceRange.baseArrayLayer = 0; imageView.subresourceRange.layerCount = 1; imageView.image = attachment->vkImage; - VulkanUtils::CheckVKResult(vkCreateImageView(vulkanContext.device.device, &imageView, nullptr, + VulkanUtils::CheckVKResult(vkCreateImageView(vulkanContext->device.device, &imageView, nullptr, &attachment->vkImageView)); return attachment; } @@ -167,7 +168,7 @@ namespace Metal { renderPassInfo.dependencyCount = dependencies.size(); renderPassInfo.pDependencies = dependencies.data(); - VulkanUtils::CheckVKResult(vkCreateRenderPass(vulkanContext.device.device, + VulkanUtils::CheckVKResult(vkCreateRenderPass(vulkanContext->device.device, &renderPassInfo, nullptr, &framebuffer->vkRenderPass)); @@ -196,14 +197,14 @@ namespace Metal { framebufferInfo.height = framebuffer->bufferHeight; framebufferInfo.layers = 1; - vkCreateFramebuffer(vulkanContext.device.device, &framebufferInfo, nullptr, + vkCreateFramebuffer(vulkanContext->device.device, &framebufferInfo, nullptr, &framebuffer->vkFramebuffer); } void FrameBufferService::disposeResource(FrameBufferInstance *resource) { LOG_INFO("Disposing framebuffer instance"); - vkDestroyFramebuffer(vulkanContext.device.device, resource->vkFramebuffer, nullptr); - vkDestroyRenderPass(vulkanContext.device.device, resource->vkRenderPass, nullptr); + vkDestroyFramebuffer(vulkanContext->device.device, resource->vkFramebuffer, nullptr); + vkDestroyRenderPass(vulkanContext->device.device, resource->vkRenderPass, nullptr); for (int i = 0; i < resource->attachments.size(); i++) { LOG_INFO("Disposing of attachment instance " + std::to_string(i)); diff --git a/src/engine/service/PipelineService.cpp b/src/engine/service/PipelineService.cpp index 83e84709..0697bf19 100644 --- a/src/engine/service/PipelineService.cpp +++ b/src/engine/service/PipelineService.cpp @@ -13,6 +13,7 @@ #include "../resource/FrameBufferAttachment.h" #include "../resource/BufferInstance.h" #include "../../ApplicationContext.h" +#include "../../common/LoggerUtil.h" namespace Metal { void PipelineService::createPipelineLayout( @@ -37,7 +38,7 @@ namespace Metal { layoutInfo.pPushConstantRanges = &pushConstantRange; } - VulkanUtils::CheckVKResult(vkCreatePipelineLayout(vulkanContext.device.device, &layoutInfo, nullptr, + VulkanUtils::CheckVKResult(vkCreatePipelineLayout(vulkanContext->device.device, &layoutInfo, nullptr, &pipeline->vkPipelineLayout)); } @@ -57,7 +58,7 @@ namespace Metal { stageFlags = VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT; } - pipeline->descriptor = descriptorSetService.createDescriptor(pipelineBuilder, id + "_descriptor", stageFlags); + pipeline->descriptor = descriptorSetService->createDescriptor(pipelineBuilder, id + "_descriptor", stageFlags); } if (pipelineBuilder.isRayTracing) { @@ -73,7 +74,7 @@ namespace Metal { PipelineInstance *pipeline) { pipeline->isCompute = true; pipeline->pushConstantsSize = pipelineBuilder.pushConstantsSize; - VkShaderModule computeShaderModule = shaderService.createShaderModule(pipelineBuilder.computeShader); + VkShaderModule computeShaderModule = shaderService->createShaderModule(pipelineBuilder.computeShader); VkPipelineShaderStageCreateInfo computeShaderStageInfo{}; computeShaderStageInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; computeShaderStageInfo.stage = VK_SHADER_STAGE_COMPUTE_BIT; @@ -87,12 +88,12 @@ namespace Metal { pipelineInfo.layout = pipeline->vkPipelineLayout; pipelineInfo.stage = computeShaderStageInfo; - if (vkCreateComputePipelines(vulkanContext.device.device, VK_NULL_HANDLE, 1, &pipelineInfo, nullptr, + if (vkCreateComputePipelines(vulkanContext->device.device, VK_NULL_HANDLE, 1, &pipelineInfo, nullptr, &pipeline->vkPipeline) != VK_SUCCESS) { throw std::runtime_error("failed to create compute pipeline!"); } - vkDestroyShaderModule(vulkanContext.device.device, computeShaderModule, nullptr); + vkDestroyShaderModule(vulkanContext->device.device, computeShaderModule, nullptr); return pipeline; } @@ -101,8 +102,8 @@ namespace Metal { auto meshDescriptions = VertexData::GetAttributeDescriptions(); pipeline->pushConstantsSize = pipelineBuilder.pushConstantsSize; - auto fragmentShaderModule = shaderService.createShaderModule(pipelineBuilder.fragmentShader); - auto vertexShaderModule = shaderService.createShaderModule(pipelineBuilder.vertexShader); + auto fragmentShaderModule = shaderService->createShaderModule(pipelineBuilder.fragmentShader); + auto vertexShaderModule = shaderService->createShaderModule(pipelineBuilder.vertexShader); createPipelineLayout(pipelineBuilder.pushConstantsSize, pipeline); std::array shaderStages{}; @@ -157,7 +158,7 @@ namespace Metal { multisampling.sampleShadingEnable = VK_FALSE; multisampling.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT; - auto *frameBuffer = framebufferService.getResource(pipelineBuilder.frameBufferId); + auto *frameBuffer = framebufferService->getResource(pipelineBuilder.frameBufferId); if (!frameBuffer) { throw std::runtime_error("Framebuffer not found: " + pipelineBuilder.frameBufferId); } @@ -228,13 +229,13 @@ namespace Metal { pipelineInfo.subpass = 0; pipelineInfo.basePipelineHandle = VK_NULL_HANDLE; - VulkanUtils::CheckVKResult(vkCreateGraphicsPipelines(vulkanContext.device.device, VK_NULL_HANDLE, 1, + VulkanUtils::CheckVKResult(vkCreateGraphicsPipelines(vulkanContext->device.device, VK_NULL_HANDLE, 1, &pipelineInfo, nullptr, &pipeline->vkPipeline)); - vkDestroyShaderModule(vulkanContext.device.device, fragmentShaderModule, nullptr); - vkDestroyShaderModule(vulkanContext.device.device, vertexShaderModule, nullptr); + vkDestroyShaderModule(vulkanContext->device.device, fragmentShaderModule, nullptr); + vkDestroyShaderModule(vulkanContext->device.device, vertexShaderModule, nullptr); return pipeline; } @@ -252,9 +253,9 @@ namespace Metal { pipeline->pushConstantsSize = pipelineBuilder.pushConstantsSize; // Create shader modules - auto rayGenModule = shaderService.createShaderModule(pipelineBuilder.rayGenShader); - auto missModule = shaderService.createShaderModule(pipelineBuilder.missShader); - auto closestHitModule = shaderService.createShaderModule(pipelineBuilder.closestHitShader); + auto rayGenModule = shaderService->createShaderModule(pipelineBuilder.rayGenShader); + auto missModule = shaderService->createShaderModule(pipelineBuilder.missShader); + auto closestHitModule = shaderService->createShaderModule(pipelineBuilder.closestHitShader); // Shader stages: 0=raygen, 1=miss, 2=closesthit std::array shaderStages{}; @@ -311,12 +312,12 @@ namespace Metal { rtPipelineInfo.layout = pipeline->vkPipelineLayout; VulkanUtils::CheckVKResult( - vulkanContext.vkCreateRayTracingPipelinesKHR( - vulkanContext.device.device, VK_NULL_HANDLE, VK_NULL_HANDLE, + vulkanContext->vkCreateRayTracingPipelinesKHR( + vulkanContext->device.device, VK_NULL_HANDLE, VK_NULL_HANDLE, 1, &rtPipelineInfo, nullptr, &pipeline->vkPipeline)); // Build Shader Binding Table - const auto &rtProps = vulkanContext.rayTracingPipelineProperties; + const auto &rtProps = vulkanContext->rayTracingPipelineProperties; const uint32_t handleSize = rtProps.shaderGroupHandleSize; const uint32_t handleAlignment = rtProps.shaderGroupHandleAlignment; const uint32_t baseAlignment = rtProps.shaderGroupBaseAlignment; @@ -326,14 +327,14 @@ namespace Metal { const uint32_t sbtSize = groupCount * handleSizeAligned; std::vector shaderHandleStorage(sbtSize); VulkanUtils::CheckVKResult( - vulkanContext.vkGetRayTracingShaderGroupHandlesKHR( - vulkanContext.device.device, pipeline->vkPipeline, + vulkanContext->vkGetRayTracingShaderGroupHandlesKHR( + vulkanContext->device.device, pipeline->vkPipeline, 0, groupCount, sbtSize, shaderHandleStorage.data())); // Create SBT buffers - each needs baseAlignment auto createSBTBuffer = [&](uint32_t groupIndex, const std::string &sbtType) -> BufferInstance * { const uint32_t sbtBufferSize = (handleSizeAligned + baseAlignment - 1) & ~(baseAlignment - 1); - auto *buf = bufferService.createBuffer( + auto *buf = bufferService->createBuffer( pipeline->getId() + "_sbt_" + sbtType, sbtBufferSize, VK_BUFFER_USAGE_SHADER_BINDING_TABLE_BIT_KHR | VK_BUFFER_USAGE_TRANSFER_DST_BIT, @@ -348,8 +349,8 @@ namespace Metal { pipeline->hitSBT = createSBTBuffer(2, "hit"); auto getAddr = [&](const BufferInstance *buf) { - return getBufferDeviceAddress(vulkanContext.device.device, buf->vkBuffer, - vulkanContext.vkGetBufferDeviceAddressKHR); + return getBufferDeviceAddress(vulkanContext->device.device, buf->vkBuffer, + vulkanContext->vkGetBufferDeviceAddressKHR); }; pipeline->raygenRegion.deviceAddress = getAddr(pipeline->raygenSBT); @@ -366,9 +367,9 @@ namespace Metal { pipeline->callableRegion = {}; // unused - vkDestroyShaderModule(vulkanContext.device.device, rayGenModule, nullptr); - vkDestroyShaderModule(vulkanContext.device.device, missModule, nullptr); - vkDestroyShaderModule(vulkanContext.device.device, closestHitModule, nullptr); + vkDestroyShaderModule(vulkanContext->device.device, rayGenModule, nullptr); + vkDestroyShaderModule(vulkanContext->device.device, missModule, nullptr); + vkDestroyShaderModule(vulkanContext->device.device, closestHitModule, nullptr); return pipeline; } @@ -377,14 +378,14 @@ namespace Metal { LOG_INFO("Disposing of pipeline instance"); if (resource->descriptor != nullptr) { - descriptorSetService.dispose(resource->getId()); + descriptorSetService->dispose(resource->getId()); } - vkDestroyPipelineLayout(vulkanContext.device.device, resource->vkPipelineLayout, nullptr); - vkDestroyPipeline(vulkanContext.device.device, resource->vkPipeline, nullptr); + vkDestroyPipelineLayout(vulkanContext->device.device, resource->vkPipelineLayout, nullptr); + vkDestroyPipeline(vulkanContext->device.device, resource->vkPipeline, nullptr); } std::vector PipelineService::getAllDescriptors() const { - return descriptorSetService.getAllDescriptors(); + return descriptorSetService->getAllDescriptors(); } } // Metal diff --git a/src/engine/service/RayTracingService.cpp b/src/engine/service/RayTracingService.cpp index 902a8641..af1fac86 100644 --- a/src/engine/service/RayTracingService.cpp +++ b/src/engine/service/RayTracingService.cpp @@ -8,6 +8,9 @@ #include "../../core/vulkan/VulkanUtils.h" #include "../../editor/enum/EngineResourceIDs.h" #include "../../core/vulkan/VulkanContext.h" +#include "../../common/LoggerUtil.h" +#include "../dto/TransformComponent.h" +#include "../dto/PrimitiveComponent.h" #include "PipelineService.h" #include "../repository/WorldRepository.h" #include "MeshService.h" @@ -18,11 +21,11 @@ #include namespace Metal { - static VkDeviceAddress getDeviceAddress(const VulkanContext &ctx, VkBuffer buffer) { + VkDeviceAddress RayTracingService::getDeviceAddress(VkBuffer buffer) { VkBufferDeviceAddressInfo info{}; info.sType = VK_STRUCTURE_TYPE_BUFFER_DEVICE_ADDRESS_INFO; info.buffer = buffer; - return ctx.vkGetBufferDeviceAddressKHR(ctx.device.device, &info); + return vulkanContext->vkGetBufferDeviceAddressKHR(vulkanContext->device.device, &info); } void RayTracingService::updateDescriptorSets(VkAccelerationStructureKHR asHandle) { @@ -37,7 +40,7 @@ namespace Metal { } if (needsUpdate) { - descriptorService->Write(vulkanContext, bufferService, descriptor->vkDescriptorSet, descriptor->bindings); + descriptorSetService->Write(descriptor->vkDescriptorSet, descriptor->bindings); } } } @@ -53,12 +56,12 @@ namespace Metal { } anyMeshes = false; // Check if any mesh is present and streamed - auto view = worldRepository.registry.view(); + auto view = worldRepository->registry.view(); for (auto entity: view) { - if (worldRepository.hiddenEntities.contains(entity)) continue; + if (worldRepository->hiddenEntities.contains(entity)) continue; auto &meshComp = view.get(entity); if (meshComp.meshId.empty()) continue; - auto *instance = meshService.stream(meshComp.meshId); + auto *instance = meshService->stream(meshComp.meshId); if (instance != nullptr && instance->dataBuffer != nullptr && instance->indexBuffer != nullptr) { anyMeshes = true; break; @@ -67,7 +70,7 @@ namespace Metal { if (!anyMeshes) { // No meshes – destroy all structures and set descriptor to null - dispose(); // destroys BLAS and TLAS (waits for idle) + dispose(); // destroys BLAS and TLAS (waits for idle) updateDescriptorSets(VK_NULL_HANDLE); accelerationStructureBuilt = false; needsRebuild = false; @@ -75,9 +78,9 @@ namespace Metal { } // At least one mesh exists: rebuild acceleration structures safely - destroyTLAS(); // Destroy old TLAS (waits for idle) before modifying BLAS - buildBLAS(); // Rebuild BLAS (incremental, safe because TLAS is gone) - buildTLAS(); // Build new TLAS + destroyTLAS(); // Destroy old TLAS (waits for idle) before modifying BLAS + buildBLAS(); // Rebuild BLAS (incremental, safe because TLAS is gone) + buildTLAS(); // Build new TLAS if (tlas != VK_NULL_HANDLE) { LOG_INFO("Updating acceleration structures"); @@ -97,21 +100,21 @@ namespace Metal { void RayTracingService::updateMeshMaterials() { bool changed = false; - auto view = worldRepository.registry.view(); + auto view = worldRepository->registry.view(); for (auto entity: view) { - if (worldRepository.hiddenEntities.contains(entity)) continue; + if (worldRepository->hiddenEntities.contains(entity)) continue; auto &meshComp = view.get(entity); if (meshComp.meshId.empty()) continue; if (meshComp.renderIndex < meshMetadata.size()) { - materialService.load(meshMetadata[meshComp.renderIndex], meshComp); + materialService->load(meshMetadata[meshComp.renderIndex], meshComp); changed = true; } } if (changed) { - for (auto *frame : engineContext.registeredFrames) { + for (auto *frame: engineContext->registeredFrames) { auto *meshMetadataBuffer = frame->getResourceAs(RID_MESH_METADATA_BUFFER); if (meshMetadataBuffer != nullptr) { meshMetadataBuffer->update(meshMetadata.data()); @@ -121,26 +124,25 @@ namespace Metal { } void RayTracingService::destroyTLAS() { - auto &vulkan = vulkanContext; - if (vulkan.device.device != VK_NULL_HANDLE) { - vkDeviceWaitIdle(vulkan.device.device); + if (vulkanContext->device.device != VK_NULL_HANDLE) { + vkDeviceWaitIdle(vulkanContext->device.device); } if (tlas != VK_NULL_HANDLE) { - vulkan.vkDestroyAccelerationStructureKHR(vulkan.device.device, tlas, nullptr); + vulkanContext->vkDestroyAccelerationStructureKHR(vulkanContext->device.device, tlas, nullptr); tlas = VK_NULL_HANDLE; } if (tlasBuffer) { - bufferService.dispose("tlas_buffer"); + bufferService->dispose("tlas_buffer"); tlasBuffer = nullptr; } if (instancesBuffer) { - bufferService.dispose("tlas_instances"); + bufferService->dispose("tlas_instances"); instancesBuffer = nullptr; } if (tlasScratchBuffer) { - bufferService.dispose("tlas_scratch"); + bufferService->dispose("tlas_scratch"); tlasScratchBuffer = nullptr; } @@ -152,14 +154,14 @@ namespace Metal { std::unordered_map uniqueMeshes; - auto view = worldRepository.registry.view(); + auto view = worldRepository->registry.view(); for (auto entity: view) { - if (worldRepository.hiddenEntities.contains(entity)) continue; + if (worldRepository->hiddenEntities.contains(entity)) continue; auto &meshComp = view.get(entity); if (meshComp.meshId.empty()) continue; if (uniqueMeshes.contains(meshComp.meshId)) continue; - auto *instance = meshService.stream(meshComp.meshId); + auto *instance = meshService->stream(meshComp.meshId); if (instance == nullptr || instance->dataBuffer == nullptr || instance->indexBuffer == nullptr) { continue; } @@ -176,18 +178,19 @@ namespace Metal { } // If mesh buffers changed, we need to rebuild this BLAS // For now, let's just destroy and re-create below by removing it - if (vulkan.device.device != VK_NULL_HANDLE) { - vulkan.vkDestroyAccelerationStructureKHR(vulkan.device.device, existing.accelerationStructure, - nullptr); + if (vulkanContext->device.device != VK_NULL_HANDLE) { + vulkanContext->vkDestroyAccelerationStructureKHR(vulkanContext->device.device, + existing.accelerationStructure, + nullptr); } if (existing.buffer) - bufferService.dispose("blas_" + meshId); + bufferService->dispose("blas_" + meshId); if (existing.scratchBuffer) - bufferService.dispose("blas_scratch_" + meshId); + bufferService->dispose("blas_scratch_" + meshId); blasEntries.erase(meshId); } - VkDeviceAddress vertexAddress = getDeviceAddress(vulkan, instance->dataBuffer->vkBuffer); - VkDeviceAddress indexAddress = getDeviceAddress(vulkan, instance->indexBuffer->vkBuffer); + VkDeviceAddress vertexAddress = getDeviceAddress(instance->dataBuffer->vkBuffer); + VkDeviceAddress indexAddress = getDeviceAddress(instance->indexBuffer->vkBuffer); VkAccelerationStructureGeometryKHR geometry{}; geometry.sType = VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_GEOMETRY_KHR; @@ -214,22 +217,22 @@ namespace Metal { VkAccelerationStructureBuildSizesInfoKHR sizeInfo{}; sizeInfo.sType = VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_BUILD_SIZES_INFO_KHR; - vulkan.vkGetAccelerationStructureBuildSizesKHR( - vulkan.device.device, + vulkanContext->vkGetAccelerationStructureBuildSizesKHR( + vulkanContext->device.device, VK_ACCELERATION_STRUCTURE_BUILD_TYPE_DEVICE_KHR, &buildInfo, &primitiveCount, &sizeInfo); BLASEntry entry; - entry.buffer = bufferService.createBuffer( + entry.buffer = bufferService->createBuffer( "blas_" + meshId, sizeInfo.accelerationStructureSize, VK_BUFFER_USAGE_ACCELERATION_STRUCTURE_STORAGE_BIT_KHR, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, true); - entry.scratchBuffer = bufferService.createBuffer( + entry.scratchBuffer = bufferService->createBuffer( "blas_scratch_" + meshId, sizeInfo.buildScratchSize, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, @@ -242,11 +245,11 @@ namespace Metal { createInfo.size = sizeInfo.accelerationStructureSize; createInfo.type = VK_ACCELERATION_STRUCTURE_TYPE_BOTTOM_LEVEL_KHR; VulkanUtils::CheckVKResult( - vulkan.vkCreateAccelerationStructureKHR(vulkan.device.device, &createInfo, nullptr, - &entry.accelerationStructure)); + vulkanContext->vkCreateAccelerationStructureKHR(vulkanContext->device.device, &createInfo, nullptr, + &entry.accelerationStructure)); buildInfo.dstAccelerationStructure = entry.accelerationStructure; - buildInfo.scratchData.deviceAddress = getDeviceAddress(vulkan, entry.scratchBuffer->vkBuffer); + buildInfo.scratchData.deviceAddress = getDeviceAddress(entry.scratchBuffer->vkBuffer); VkAccelerationStructureBuildRangeInfoKHR rangeInfo{}; rangeInfo.primitiveCount = primitiveCount; @@ -255,9 +258,9 @@ namespace Metal { rangeInfo.transformOffset = 0; const VkAccelerationStructureBuildRangeInfoKHR *pRangeInfo = &rangeInfo; - VkCommandBuffer cmd = vulkan.beginSingleTimeCommands(); - vulkan.vkCmdBuildAccelerationStructuresKHR(cmd, 1, &buildInfo, &pRangeInfo); - vulkan.endSingleTimeCommands(cmd); + VkCommandBuffer cmd = vulkanContext->beginSingleTimeCommands(); + vulkanContext->vkCmdBuildAccelerationStructuresKHR(cmd, 1, &buildInfo, &pRangeInfo); + vulkanContext->endSingleTimeCommands(cmd); entry.vertexData = instance->dataBuffer; entry.indexData = instance->indexBuffer; @@ -266,16 +269,15 @@ namespace Metal { } void RayTracingService::buildTLAS() { - auto &vulkan = vulkanContext; meshMetadata.clear(); if (blasEntries.empty()) return; - if (vulkan.device.device != VK_NULL_HANDLE) { - vkDeviceWaitIdle(vulkan.device.device); + if (vulkanContext->device.device != VK_NULL_HANDLE) { + vkDeviceWaitIdle(vulkanContext->device.device); } std::vector instances; - auto view = worldRepository.registry.view(); + auto view = worldRepository->registry.view(); unsigned int currentInstanceIndex = 0; for (auto entity: view) { @@ -283,7 +285,7 @@ namespace Metal { LOG_ERROR("Max mesh instances reached for ray tracing: " + std::to_string(MAX_MESH_INSTANCES)); break; } - if (worldRepository.hiddenEntities.contains(entity)) continue; + if (worldRepository->hiddenEntities.contains(entity)) continue; auto &meshComp = view.get(entity); if (meshComp.meshId.empty()) continue; @@ -294,12 +296,12 @@ namespace Metal { VkAccelerationStructureDeviceAddressInfoKHR addressInfo{}; addressInfo.sType = VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_DEVICE_ADDRESS_INFO_KHR; addressInfo.accelerationStructure = it->second.accelerationStructure; - VkDeviceAddress blasAddress = vulkan.vkGetAccelerationStructureDeviceAddressKHR( - vulkan.device.device, &addressInfo); + VkDeviceAddress blasAddress = vulkanContext->vkGetAccelerationStructureDeviceAddressKHR( + vulkanContext->device.device, &addressInfo); glm::mat4 model = glm::mat4(1.0f); - if (worldRepository.registry.all_of(entity)) { - model = worldRepository.registry.get(entity).model; + if (worldRepository->registry.all_of(entity)) { + model = worldRepository->registry.get(entity).model; } VkTransformMatrixKHR transform{}; @@ -309,8 +311,8 @@ namespace Metal { } } - VkDeviceAddress vertexAddress = getDeviceAddress(vulkan, it->second.vertexData->vkBuffer); - VkDeviceAddress indexAddress = getDeviceAddress(vulkan, it->second.indexData->vkBuffer); + VkDeviceAddress vertexAddress = getDeviceAddress(it->second.vertexData->vkBuffer); + VkDeviceAddress indexAddress = getDeviceAddress(it->second.indexData->vkBuffer); meshComp.renderIndex = currentInstanceIndex; meshMetadata.push_back({meshComp.renderIndex, vertexAddress, indexAddress}); @@ -332,14 +334,14 @@ namespace Metal { updateMeshMaterials(); - instancesBuffer = bufferService.createBuffer( + instancesBuffer = bufferService->createBuffer( "tlas_instances", sizeof(VkAccelerationStructureInstanceKHR) * instances.size(), VK_BUFFER_USAGE_ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY_BIT_KHR, instances.data(), true); - VkDeviceAddress instancesAddress = getDeviceAddress(vulkan, instancesBuffer->vkBuffer); + VkDeviceAddress instancesAddress = getDeviceAddress(instancesBuffer->vkBuffer); VkAccelerationStructureGeometryKHR tlasGeometry{}; tlasGeometry.sType = VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_GEOMETRY_KHR; @@ -361,14 +363,14 @@ namespace Metal { VkAccelerationStructureBuildSizesInfoKHR sizeInfo{}; sizeInfo.sType = VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_BUILD_SIZES_INFO_KHR; - vulkan.vkGetAccelerationStructureBuildSizesKHR( - vulkan.device.device, + vulkanContext->vkGetAccelerationStructureBuildSizesKHR( + vulkanContext->device.device, VK_ACCELERATION_STRUCTURE_BUILD_TYPE_DEVICE_KHR, &buildInfo, &instanceCount, &sizeInfo); - tlasBuffer = bufferService.createBuffer( + tlasBuffer = bufferService->createBuffer( "tlas_buffer", sizeInfo.accelerationStructureSize, VK_BUFFER_USAGE_ACCELERATION_STRUCTURE_STORAGE_BIT_KHR, @@ -381,9 +383,9 @@ namespace Metal { createInfo.size = sizeInfo.accelerationStructureSize; createInfo.type = VK_ACCELERATION_STRUCTURE_TYPE_TOP_LEVEL_KHR; VulkanUtils::CheckVKResult( - vulkan.vkCreateAccelerationStructureKHR(vulkan.device.device, &createInfo, nullptr, &tlas)); + vulkanContext->vkCreateAccelerationStructureKHR(vulkanContext->device.device, &createInfo, nullptr, &tlas)); - tlasScratchBuffer = bufferService.createBuffer( + tlasScratchBuffer = bufferService->createBuffer( "tlas_scratch", sizeInfo.buildScratchSize, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, @@ -391,23 +393,23 @@ namespace Metal { true); buildInfo.dstAccelerationStructure = tlas; - buildInfo.scratchData.deviceAddress = getDeviceAddress(vulkan, tlasScratchBuffer->vkBuffer); + buildInfo.scratchData.deviceAddress = getDeviceAddress(tlasScratchBuffer->vkBuffer); VkAccelerationStructureBuildRangeInfoKHR rangeInfo{}; rangeInfo.primitiveCount = instanceCount; const VkAccelerationStructureBuildRangeInfoKHR *pRangeInfo = &rangeInfo; - VkCommandBuffer cmd = vulkan.beginSingleTimeCommands(); - vulkan.vkCmdBuildAccelerationStructuresKHR(cmd, 1, &buildInfo, &pRangeInfo); - vulkan.endSingleTimeCommands(cmd); + VkCommandBuffer cmd = vulkanContext->beginSingleTimeCommands(); + vulkanContext->vkCmdBuildAccelerationStructuresKHR(cmd, 1, &buildInfo, &pRangeInfo); + vulkanContext->endSingleTimeCommands(cmd); } void RayTracingService::dispose() { LOG_INFO("Destroying acceleration structures"); auto &vulkan = vulkanContext; - if (vulkan.device.device != VK_NULL_HANDLE) { - vkDeviceWaitIdle(vulkan.device.device); + if (vulkanContext->device.device != VK_NULL_HANDLE) { + vkDeviceWaitIdle(vulkanContext->device.device); } // Destroy TLAS and its buffers @@ -416,13 +418,14 @@ namespace Metal { // Destroy all BLAS entries for (auto &[meshId, entry]: blasEntries) { if (entry.accelerationStructure != VK_NULL_HANDLE) { - vulkan.vkDestroyAccelerationStructureKHR(vulkan.device.device, entry.accelerationStructure, nullptr); + vulkanContext->vkDestroyAccelerationStructureKHR(vulkanContext->device.device, + entry.accelerationStructure, nullptr); entry.accelerationStructure = VK_NULL_HANDLE; } if (entry.buffer) - bufferService.dispose("blas_" + meshId); + bufferService->dispose("blas_" + meshId); if (entry.scratchBuffer) - bufferService.dispose("blas_scratch_" + meshId); + bufferService->dispose("blas_scratch_" + meshId); } blasEntries.clear(); diff --git a/src/engine/service/RayTracingService.h b/src/engine/service/RayTracingService.h index 4ecc20b2..c4325efe 100644 --- a/src/engine/service/RayTracingService.h +++ b/src/engine/service/RayTracingService.h @@ -11,6 +11,7 @@ #include "../../common/IDisposable.h" namespace Metal { + class DescriptorSetService; class BufferInstance; class VulkanContext; class PipelineService; @@ -19,7 +20,6 @@ namespace Metal { class MaterialService; class BufferService; class EngineContext; - class DescriptorService; class RayTracingService final : public IService, public ISync, public IDisposable { VulkanContext *vulkanContext = nullptr; @@ -29,7 +29,7 @@ namespace Metal { MaterialService *materialService = nullptr; BufferService *bufferService = nullptr; EngineContext *engineContext = nullptr; - DescriptorService *descriptorService = nullptr; + DescriptorSetService *descriptorSetService = nullptr; struct BLASEntry { VkAccelerationStructureKHR accelerationStructure = VK_NULL_HANDLE; @@ -58,6 +58,8 @@ namespace Metal { bool needsRebuild = true; bool needsMaterialUpdate = false; + VkDeviceAddress getDeviceAddress(VkBuffer buffer); + void updateDescriptorSets(VkAccelerationStructureKHR asHandle); void buildBLAS(); @@ -80,7 +82,7 @@ namespace Metal { {"MaterialService", materialService}, {"BufferService", bufferService}, {"EngineContext", engineContext}, - {"DescriptorService", descriptorService} + {"DescriptorSetService", descriptorSetService} }; } diff --git a/src/engine/service/ShaderService.cpp b/src/engine/service/ShaderService.cpp index acb0ec4e..30d8b467 100644 --- a/src/engine/service/ShaderService.cpp +++ b/src/engine/service/ShaderService.cpp @@ -167,7 +167,7 @@ namespace Metal { } VkShaderModule ShaderService::createShaderModule(const std::string &pFilename) { - this->isDebugMode = CTX->isDebugMode(); + this->isDebugMode = ctx->isDebugMode(); std::string source = ProcessShader(BASE_PATH + pFilename, BASE_PATH); if (isDebugMode) { source = "#define DEBUG\n" + source; diff --git a/src/engine/service/TextureService.cpp b/src/engine/service/TextureService.cpp index 8505d17f..707322dc 100644 --- a/src/engine/service/TextureService.cpp +++ b/src/engine/service/TextureService.cpp @@ -18,12 +18,14 @@ #include "BufferService.h" #include "PipelineService.h" #include "DescriptorSetService.h" +#include "../../core/DirectoryService.h" +#include "../../common/LoggerUtil.h" namespace Metal { void TextureService::copyBufferToImage(const VkBuffer &vkBuffer, const TextureInstance *image, const int layerCount) const { - VkCommandBuffer commandBuffer = vulkanContext.beginSingleTimeCommands(); + VkCommandBuffer commandBuffer = vulkanContext->beginSingleTimeCommands(); VkBufferImageCopy region{}; region.bufferOffset = 0; @@ -45,31 +47,31 @@ namespace Metal { VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, ®ion); - vulkanContext.endSingleTimeCommands(commandBuffer); + vulkanContext->endSingleTimeCommands(commandBuffer); } void TextureService::createImageWithInfo(const VkImageCreateInfo &imageInfo, VkMemoryPropertyFlagBits vkMemoryProperties, TextureInstance *image) const { - if (vkCreateImage(vulkanContext.device.device, &imageInfo, nullptr, &image->vkImage) != VK_SUCCESS) { + if (vkCreateImage(vulkanContext->device.device, &imageInfo, nullptr, &image->vkImage) != VK_SUCCESS) { throw std::runtime_error("failed to create image!"); } VkMemoryRequirements memRequirements; - vkGetImageMemoryRequirements(vulkanContext.device.device, image->vkImage, &memRequirements); + vkGetImageMemoryRequirements(vulkanContext->device.device, image->vkImage, &memRequirements); VkMemoryAllocateInfo allocInfo{}; allocInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; allocInfo.allocationSize = memRequirements.size; - allocInfo.memoryTypeIndex = bufferService.findMemoryType( + allocInfo.memoryTypeIndex = bufferService->findMemoryType( memRequirements.memoryTypeBits, vkMemoryProperties); - if (vkAllocateMemory(vulkanContext.device.device, &allocInfo, nullptr, &image->vkImageMemory) != + if (vkAllocateMemory(vulkanContext->device.device, &allocInfo, nullptr, &image->vkImageMemory) != VK_SUCCESS) { throw std::runtime_error("failed to allocate image memory!"); } - if (vkBindImageMemory(vulkanContext.device.device, image->vkImage, image->vkImageMemory, 0) != + if (vkBindImageMemory(vulkanContext->device.device, image->vkImage, image->vkImageMemory, 0) != VK_SUCCESS) { throw std::runtime_error("failed to bind image memory!"); } @@ -92,7 +94,7 @@ namespace Metal { samplerInfo.anisotropyEnable = VK_TRUE; samplerInfo.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; - vkCreateSampler(vulkanContext.device.device, &samplerInfo, nullptr, &image->vkSampler); + vkCreateSampler(vulkanContext->device.device, &samplerInfo, nullptr, &image->vkSampler); } void TextureService::createImageView(VkFormat imageFormat, TextureInstance *image) const { @@ -110,7 +112,7 @@ namespace Metal { imageViewInfo.subresourceRange.levelCount = image->mipLevels; imageViewInfo.image = image->vkImage; - vkCreateImageView(vulkanContext.device.device, &imageViewInfo, nullptr, &image->vkImageView); + vkCreateImageView(vulkanContext->device.device, &imageViewInfo, nullptr, &image->vkImageView); } void TextureService::createImage(VkFormat imageFormat, TextureInstance *image, const int width, @@ -133,7 +135,7 @@ namespace Metal { } TextureData *TextureService::loadTextureData(const std::string &id) const { - auto pathToFile = rootDirectory + "/assets/" + FORMAT_FILE_TEXTURE(id); + auto pathToFile = directoryService->getAssetDirectory() + FORMAT_FILE_TEXTURE(id); if (std::filesystem::exists(pathToFile)) { int width, height, channels; unsigned char *data = stbi_load(pathToFile.c_str(), &width, &height, &channels, 0); @@ -171,7 +173,7 @@ namespace Metal { image->vkFormat = imageFormat; LOG_INFO("Loading texture " + id + " from " + pathToImage); LOG_INFO("Texture data: Width " + std::to_string(image->width) + " Height " + std::to_string(image->height)); - BufferInstance *stagingBuffer = bufferService.createBuffer( + BufferInstance *stagingBuffer = bufferService->createBuffer( id + "_staging", image->width * image->height * 4, VK_BUFFER_USAGE_TRANSFER_SRC_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT); @@ -192,7 +194,7 @@ namespace Metal { void TextureService::transitionImageLayout(const TextureInstance *image, VkImageLayout oldLayout, VkImageLayout newLayout) const { - VkCommandBuffer commandBuffer = vulkanContext.beginSingleTimeCommands(); + VkCommandBuffer commandBuffer = vulkanContext->beginSingleTimeCommands(); VkImageMemoryBarrier barrier{}; barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; barrier.oldLayout = oldLayout; @@ -243,19 +245,19 @@ namespace Metal { 0, nullptr, 1, &barrier); - vulkanContext.endSingleTimeCommands(commandBuffer); + vulkanContext->endSingleTimeCommands(commandBuffer); } void TextureService::generateMipmaps(const TextureInstance *image) const { VkFormatProperties formatProperties; - vkGetPhysicalDeviceFormatProperties(vulkanContext.physDevice.physical_device, image->vkFormat, + vkGetPhysicalDeviceFormatProperties(vulkanContext->physDevice.physical_device, image->vkFormat, &formatProperties); if (!(formatProperties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT)) { throw std::runtime_error("texture image format does not support linear blitting!"); } - VkCommandBuffer commandBuffer = vulkanContext.beginSingleTimeCommands(); + VkCommandBuffer commandBuffer = vulkanContext->beginSingleTimeCommands(); VkImageMemoryBarrier barrier{}; barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; @@ -318,11 +320,11 @@ namespace Metal { vkCmdPipelineBarrier(commandBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 1, &barrier); - vulkanContext.endSingleTimeCommands(commandBuffer); + vulkanContext->endSingleTimeCommands(commandBuffer); } TextureInstance *TextureService::create(const std::string &id) { - auto pathToFile = rootDirectory + "/assets/" + FORMAT_FILE_TEXTURE(id); + auto pathToFile = directoryService->getAssetDirectory() + FORMAT_FILE_TEXTURE(id); if (std::filesystem::exists(pathToFile)) { auto *instance = loadTexture(id, pathToFile, true, VK_FORMAT_R8G8B8A8_UNORM); if (instance != nullptr) { @@ -371,7 +373,7 @@ namespace Metal { textureIndices[id] = index; // Update all descriptors that contain a texture array - auto descriptors = pipelineService.getAllDescriptors(); + auto descriptors = pipelineService->getAllDescriptors(); for (auto *descriptor: descriptors) { for (auto &binding: descriptor->bindings) { if (binding.descriptorType == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER && binding.descriptorCount > 1) { @@ -384,12 +386,12 @@ namespace Metal { write.descriptorCount = 1; VkDescriptorImageInfo imageInfo{}; - imageInfo.sampler = vulkanContext.vkTextureSampler; + imageInfo.sampler = vulkanContext->vkTextureSampler; imageInfo.imageView = texture->vkImageView; imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; write.pImageInfo = &imageInfo; - vkUpdateDescriptorSets(vulkanContext.device.device, 1, &write, 0, nullptr); + vkUpdateDescriptorSets(vulkanContext->device.device, 1, &write, 0, nullptr); } } } @@ -400,13 +402,13 @@ namespace Metal { } void TextureService::disposeResource(TextureInstance *resource) { - vkDestroyImage(vulkanContext.device.device, resource->vkImage, nullptr); - vkFreeMemory(vulkanContext.device.device, resource->vkImageMemory, nullptr); - vkDestroyImageView(vulkanContext.device.device, resource->vkImageView, nullptr); - vkDestroySampler(vulkanContext.device.device, resource->vkSampler, nullptr); + vkDestroyImage(vulkanContext->device.device, resource->vkImage, nullptr); + vkFreeMemory(vulkanContext->device.device, resource->vkImageMemory, nullptr); + vkDestroyImageView(vulkanContext->device.device, resource->vkImageView, nullptr); + vkDestroySampler(vulkanContext->device.device, resource->vkSampler, nullptr); if (resource->imageDescriptor != nullptr) { - descriptorSetService.disposeResource(resource->imageDescriptor); + descriptorSetService->disposeResource(resource->imageDescriptor); } } @@ -426,7 +428,7 @@ namespace Metal { samplerCreateInfo.maxAnisotropy = 8; samplerCreateInfo.anisotropyEnable = VK_TRUE; samplerCreateInfo.borderColor = VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK; - VulkanUtils::CheckVKResult(vkCreateSampler(vulkanContext.device.device, &samplerCreateInfo, nullptr, + VulkanUtils::CheckVKResult(vkCreateSampler(vulkanContext->device.device, &samplerCreateInfo, nullptr, &vkImageSampler)); } diff --git a/src/main.cpp b/src/main.cpp index a851954a..bb6fe456 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -50,59 +50,60 @@ #include "engine/EngineContext.h" int main(int, char **) { - Metal::ApplicationContext context{true}; + std::shared_ptr context{}; // --- ORDER MATTERS - context.registerSingleton(std::make_unique()); - context.registerSingleton(std::make_unique()); - context.registerSingleton(std::make_unique()); - context.registerSingleton(std::make_unique()); + context->registerSingleton(context); + context->registerSingleton(std::make_shared()); + context->registerSingleton(std::make_shared()); + context->registerSingleton(std::make_shared()); + context->registerSingleton(std::make_shared()); // --- ORDER MATTERS - context.registerSingleton(std::make_unique()); - context.registerSingleton(std::make_unique()); - context.registerSingleton(std::make_unique()); - context.registerSingleton(std::make_unique()); - context.registerSingleton(std::make_unique()); - context.registerSingleton(std::make_unique()); - context.registerSingleton(std::make_unique()); - context.registerSingleton(std::make_unique()); - context.registerSingleton(std::make_unique()); - context.registerSingleton(std::make_unique()); - context.registerSingleton(std::make_unique()); - context.registerSingleton(std::make_unique()); - context.registerSingleton(std::make_unique()); - context.registerSingleton(std::make_unique()); - context.registerSingleton(std::make_unique()); - context.registerSingleton(std::make_unique()); - context.registerSingleton(std::make_unique()); - context.registerSingleton(std::make_unique()); - context.registerSingleton(std::make_unique()); + context->registerSingleton(std::make_shared()); + context->registerSingleton(std::make_shared()); + context->registerSingleton(std::make_shared()); + context->registerSingleton(std::make_shared()); + context->registerSingleton(std::make_shared()); + context->registerSingleton(std::make_shared()); + context->registerSingleton(std::make_shared()); + context->registerSingleton(std::make_shared()); + context->registerSingleton(std::make_shared()); + context->registerSingleton(std::make_shared()); + context->registerSingleton(std::make_shared()); + context->registerSingleton(std::make_shared()); + context->registerSingleton(std::make_shared()); + context->registerSingleton(std::make_shared()); + context->registerSingleton(std::make_shared()); + context->registerSingleton(std::make_shared()); + context->registerSingleton(std::make_shared()); + context->registerSingleton(std::make_shared()); + context->registerSingleton(std::make_shared()); - context.registerSingleton(std::make_unique()); - context.registerSingleton(std::make_unique()); - context.registerSingleton(std::make_unique()); - context.registerSingleton(std::make_unique()); - context.registerSingleton(std::make_unique()); - context.registerSingleton(std::make_unique()); - context.registerSingleton(std::make_unique()); - context.registerSingleton(std::make_unique()); - context.registerSingleton(std::make_unique()); - context.registerSingleton(std::make_unique()); - context.registerSingleton(std::make_unique()); - context.registerSingleton(std::make_unique()); + context->registerSingleton(std::make_shared()); + context->registerSingleton(std::make_shared()); + context->registerSingleton(std::make_shared()); + context->registerSingleton(std::make_shared()); + context->registerSingleton(std::make_shared()); + context->registerSingleton(std::make_shared()); + context->registerSingleton(std::make_shared()); + context->registerSingleton(std::make_shared()); + context->registerSingleton(std::make_shared()); + context->registerSingleton(std::make_shared()); + context->registerSingleton(std::make_shared()); + context->registerSingleton(std::make_shared()); - context.registerSingleton(std::make_unique()); - context.registerSingleton(std::make_unique()); - context.registerSingleton(std::make_unique()); - context.registerSingleton(std::make_unique()); - context.registerSingleton(std::make_unique()); + context->registerSingleton(std::make_shared()); + context->registerSingleton(std::make_shared()); + context->registerSingleton(std::make_shared()); + context->registerSingleton(std::make_shared()); - context.onInitialize(); - auto &frameService = context.getSingleton(); - auto &directoryService = context.getSingleton(); + context->onInitialize(); + auto &frameService = context->getSingleton(); + auto &directoryService = context->getSingleton(); directoryService.updateRootPath(false); - auto &editor = context.getSingleton(); + Metal::EditorPanel editor{}; + context->injectDependencies(&editor); frameService.setPanel(&editor); if (!frameService.isValidContext()) { @@ -110,6 +111,6 @@ int main(int, char **) { return 1; } frameService.onInitialize(); - context.dispose(); + context->dispose(); return 0; } From a9bd9454eb756a30f3399c3cfd27b164fb3a2255 Mon Sep 17 00:00:00 2001 From: facobackup Date: Sat, 14 Mar 2026 17:27:22 -0300 Subject: [PATCH 14/18] Fixes --- .output.txt | 303 ++++++++++++++++++ src/ApplicationContext.h | 32 +- src/editor/panel/FileImportModalPanel.h | 5 +- src/editor/service/FilesService.cpp | 12 +- src/editor/service/MeshImporterService.h | 2 + src/editor/service/SceneImporterService.cpp | 4 +- src/engine/frame-builder/EngineFrame.cpp | 4 +- src/engine/frame-builder/EngineFrame.h | 2 +- .../frame-builder/EngineFrameBuilder.cpp | 5 +- src/engine/service/BufferService.cpp | 2 + src/engine/service/BufferService.h | 8 +- src/engine/service/MeshService.cpp | 1 + src/engine/service/PipelineService.h | 10 +- src/main.cpp | 2 +- 14 files changed, 369 insertions(+), 23 deletions(-) create mode 100644 .output.txt diff --git a/.output.txt b/.output.txt new file mode 100644 index 00000000..7bda7820 --- /dev/null +++ b/.output.txt @@ -0,0 +1,303 @@ +[23/44] Building CXX object CMakeFiles\metal_engine.dir\src\engine\passes\AbstractPass.cpp.obj +C:\Users\russi\CLionProjects\metal-engine\src\engine\passes\AbstractPass.h(35): warning C4458: declaration of 'vkCommandBuffer' hides class member +C:\Users\russi\CLionProjects\metal-engine\src\engine\passes\AbstractPass.h(24): note: see declaration of 'Metal::AbstractPass::vkCommandBuffer' +C:\Users\russi\CLionProjects\metal-engine\src\engine\passes\AbstractPass.cpp(57): warning C4267: 'argument': conversion from 'size_t' to 'uint32_t', possible loss of data +[24/44] Building CXX object CMakeFiles\metal_engine...editor\dock-spaces\header\EditorHeaderPanel.cpp.obj +C:\Users\russi\CLionProjects\metal-engine\src\editor\dock-spaces\header\../../util/UIUtil.h(48): warning C4244: 'initializing': conversion from 'int' to 'float', possible loss of data +C:\Users\russi\CLionProjects\metal-engine\src\editor\dock-spaces\header\../../util/UIUtil.h(48): warning C4244: 'initializing': conversion from 'int' to 'const float', possible loss of data +C:\Users\russi\CLionProjects\metal-engine\src\engine\dto/GlobalDataUBO.h(14): warning C4324: 'Metal::GlobalDataUBO': structure was padded due to alignment specifier +C:\Users\russi\CLionProjects\metal-engine\src\engine\dto/GlobalDataUBO.h(15): warning C4324: 'Metal::GlobalDataUBO': structure was padded due to alignment specifier +C:\Users\russi\CLionProjects\metal-engine\src\engine\frame-builder\../passes/AbstractPass.h(35): warning C4458: declaration of 'vkCommandBuffer' hides class member +C:\Users\russi\CLionProjects\metal-engine\src\engine\frame-builder\../passes/AbstractPass.h(24): note: see declaration of 'Metal::AbstractPass::vkCommandBuffer' +C:\Users\russi\CLionProjects\metal-engine\src\editor\util\../enum/EntryType.h(33): warning C4505: 'Metal::EntryType::GetDTO': unreferenced function with internal linkage has been removed +C:\Users\russi\CLionProjects\metal-engine\src\editor\dock-spaces\header\../../util/UIUtil.h(46): warning C4505: 'Metal::UIUtil::RenderOption': unreferenced function with internal linkage has been removed +C:\Users\russi\CLionProjects\metal-engine\src\editor\dock-spaces\header\../../util/UIUtil.h(52): warning C4505: 'Metal::UIUtil::RenderTooltip': unreferenced function with internal linkage has been removed +C:\Users\russi\CLionProjects\metal-engine\src\editor\dock-spaces\header\../../util/UIUtil.h(66): warning C4505: 'Metal::UIUtil::Spacing': unreferenced function with internal linkage has been removed +C:\Users\russi\CLionProjects\metal-engine\src\editor\dock-spaces\header\../../util/UIUtil.h(72): warning C4505: 'Metal::UIUtil::DynamicSpacing': unreferenced function with internal linkage has been removed +C:\Users\russi\CLionProjects\metal-engine\src\editor\dock-spaces\header\../../util/UIUtil.h(102): warning C4505: 'Metal::UIUtil::DrawVec2Control': unreferenced function with internal linkage has been removed +C:\Users\russi\CLionProjects\metal-engine\src\editor\dock-spaces\header\../../util/UIUtil.h(119): warning C4505: 'Metal::UIUtil::DrawVec3Control': unreferenced function with internal linkage has been removed +C:\Users\russi\CLionProjects\metal-engine\src\editor\dock-spaces\header\../../util/UIUtil.h(159): warning C4505: 'Metal::UIUtil::DrawQuatControl': unreferenced function with internal linkage has been removed +C:\Users\russi\CLionProjects\metal-engine\src\editor\dock-spaces\header\../../util/UIUtil.h(163): warning C4505: 'Metal::UIUtil::GetKeyChordName': unreferenced function with internal linkage has been removed +C:\Users\russi\CLionProjects\metal-engine\src\editor\dock-spaces\header\../../util/UIUtil.h(179): warning C4505: 'Metal::UIUtil::GetEntryIcon': unreferenced function with internal linkage has been removed +[25/44] Building CXX object CMakeFiles\metal_engine.dir\src\ApplicationContext.cpp.obj +C:\Users\russi\CLionProjects\metal-engine\src\engine\dto/GlobalDataUBO.h(14): warning C4324: 'Metal::GlobalDataUBO': structure was padded due to alignment specifier +C:\Users\russi\CLionProjects\metal-engine\src\engine\dto/GlobalDataUBO.h(15): warning C4324: 'Metal::GlobalDataUBO': structure was padded due to alignment specifier +C:\Users\russi\CLionProjects\metal-engine\src\engine\frame-builder\../passes/AbstractPass.h(35): warning C4458: declaration of 'vkCommandBuffer' hides class member +C:\Users\russi\CLionProjects\metal-engine\src\engine\frame-builder\../passes/AbstractPass.h(24): note: see declaration of 'Metal::AbstractPass::vkCommandBuffer' +[26/44] Building CXX object CMakeFiles\metal_engine.dir\src\engine\passes\impl\HWRayTracingPass.cpp.obj +C:\Users\russi\CLionProjects\metal-engine\src\engine\passes\AbstractPass.h(35): warning C4458: declaration of 'vkCommandBuffer' hides class member +C:\Users\russi\CLionProjects\metal-engine\src\engine\passes\AbstractPass.h(24): note: see declaration of 'Metal::AbstractPass::vkCommandBuffer' +C:\Users\russi\CLionProjects\metal-engine\src\engine\service\../dto/MeshMetadata.h(13): warning C4324: 'Metal::MeshMetadata': structure was padded due to alignment specifier +C:\Users\russi\CLionProjects\metal-engine\src\engine\passes\impl\../../service/RayTracingService.h(15): warning C4099: 'Metal::BufferInstance': type name first seen using 'struct' now seen using 'class' +C:\Users\russi\CLionProjects\metal-engine\src\engine\dto\DescriptorBinding.h(8): note: see declaration of 'Metal::BufferInstance' +C:\Users\russi\CLionProjects\metal-engine\src\engine\dto/GlobalDataUBO.h(14): warning C4324: 'Metal::GlobalDataUBO': structure was padded due to alignment specifier +C:\Users\russi\CLionProjects\metal-engine\src\engine\dto/GlobalDataUBO.h(15): warning C4324: 'Metal::GlobalDataUBO': structure was padded due to alignment specifier +C:\Users\russi\CLionProjects\metal-engine\src\common\Inspectable.h(125): warning C4100: 'member': unreferenced parameter +C:\Users\russi\CLionProjects\metal-engine\src\common\../editor/enum/EntryType.h(33): warning C4505: 'Metal::EntryType::GetDTO': unreferenced function with internal linkage has been removed +[27/44] Building CXX object CMakeFiles\metal_engine.dir\src\engine\service\LightService.cpp.obj +C:\Users\russi\CLionProjects\metal-engine\src\engine\service\../dto/LightData.h(11): warning C4324: 'Metal::LightData': structure was padded due to alignment specifier +C:\Users\russi\CLionProjects\metal-engine\src\engine\service\../dto/LightData.h(12): warning C4324: 'Metal::LightData': structure was padded due to alignment specifier +C:\Users\russi\CLionProjects\metal-engine\src\engine\service\LightService.h(49): warning C4267: 'return': conversion from 'size_t' to 'unsigned int', possible loss of data +C:\Users\russi\CLionProjects\metal-engine\src\engine\dto/GlobalDataUBO.h(14): warning C4324: 'Metal::GlobalDataUBO': structure was padded due to alignment specifier +C:\Users\russi\CLionProjects\metal-engine\src\engine\dto/GlobalDataUBO.h(15): warning C4324: 'Metal::GlobalDataUBO': structure was padded due to alignment specifier +C:\Users\russi\CLionProjects\metal-engine\src\engine\frame-builder\../passes/AbstractPass.h(35): warning C4458: declaration of 'vkCommandBuffer' hides class member +C:\Users\russi\CLionProjects\metal-engine\src\engine\frame-builder\../passes/AbstractPass.h(24): note: see declaration of 'Metal::AbstractPass::vkCommandBuffer' +C:\Users\russi\CLionProjects\metal-engine\src\common\Inspectable.h(125): warning C4100: 'member': unreferenced parameter +C:\Users\russi\CLionProjects\metal-engine\src\common\../editor/enum/EntryType.h(33): warning C4505: 'Metal::EntryType::GetDTO': unreferenced function with internal linkage has been removed +[28/44] Building CXX object CMakeFiles\metal_engine...c\editor\dock-spaces\viewport\ViewportPanel.cpp.obj +C:\Users\russi\CLionProjects\metal-engine\src\engine\dto\../../common/Inspectable.h(125): warning C4100: 'member': unreferenced parameter +C:\Users\russi\CLionProjects\metal-engine\src\editor\dock-spaces\viewport\../../repository/EditorRepository.h(33): warning C4305: 'initializing': truncation from 'double' to 'float' +C:\Users\russi\CLionProjects\metal-engine\src\editor\dock-spaces\viewport\../../../engine/repository/WorldRepository.h(15): warning C4099: 'Metal::DirectoryService': type name first seen using 'struct' now seen using 'class' +C:\Users\russi\CLionProjects\metal-engine\src\editor\dock-spaces\viewport\ViewportPanel.h(13): note: see declaration of 'Metal::DirectoryService' +C:\Users\russi\CLionProjects\metal-engine\src\engine\dto/GlobalDataUBO.h(14): warning C4324: 'Metal::GlobalDataUBO': structure was padded due to alignment specifier +C:\Users\russi\CLionProjects\metal-engine\src\engine\dto/GlobalDataUBO.h(15): warning C4324: 'Metal::GlobalDataUBO': structure was padded due to alignment specifier +C:\Users\russi\CLionProjects\metal-engine\src\engine\frame-builder\../passes/AbstractPass.h(35): warning C4458: declaration of 'vkCommandBuffer' hides class member +C:\Users\russi\CLionProjects\metal-engine\src\engine\frame-builder\../passes/AbstractPass.h(24): note: see declaration of 'Metal::AbstractPass::vkCommandBuffer' +C:\Users\russi\CLionProjects\metal-engine\src\engine\dto\AbstractComponent.h(14): warning C4458: declaration of 'entityId' hides class member +C:\Users\russi\CLionProjects\metal-engine\src\engine\dto\AbstractComponent.h(31): note: see declaration of 'Metal::AbstractComponent::entityId' +C:\Users\russi\CLionProjects\metal-engine\src\common\../editor/enum/EntryType.h(33): warning C4505: 'Metal::EntryType::GetDTO': unreferenced function with internal linkage has been removed +[29/44] Building CXX object CMakeFiles\metal_engine.dir\src\editor\panel\NotificationsPanel.cpp.obj +C:\Users\russi\CLionProjects\metal-engine\src\editor\panel\../util/UIUtil.h(48): warning C4244: 'initializing': conversion from 'int' to 'float', possible loss of data +C:\Users\russi\CLionProjects\metal-engine\src\editor\panel\../util/UIUtil.h(48): warning C4244: 'initializing': conversion from 'int' to 'const float', possible loss of data +C:\Users\russi\CLionProjects\metal-engine\src\engine\dto/GlobalDataUBO.h(14): warning C4324: 'Metal::GlobalDataUBO': structure was padded due to alignment specifier +C:\Users\russi\CLionProjects\metal-engine\src\engine\dto/GlobalDataUBO.h(15): warning C4324: 'Metal::GlobalDataUBO': structure was padded due to alignment specifier +C:\Users\russi\CLionProjects\metal-engine\src\engine\frame-builder\../passes/AbstractPass.h(35): warning C4458: declaration of 'vkCommandBuffer' hides class member +C:\Users\russi\CLionProjects\metal-engine\src\engine\frame-builder\../passes/AbstractPass.h(24): note: see declaration of 'Metal::AbstractPass::vkCommandBuffer' +C:\Users\russi\CLionProjects\metal-engine\src\editor\util\../enum/EntryType.h(33): warning C4505: 'Metal::EntryType::GetDTO': unreferenced function with internal linkage has been removed +C:\Users\russi\CLionProjects\metal-engine\src\editor\panel\../util/UIUtil.h(40): warning C4505: 'Metal::UIUtil::ButtonSimple': unreferenced function with internal linkage has been removed +C:\Users\russi\CLionProjects\metal-engine\src\editor\panel\../util/UIUtil.h(46): warning C4505: 'Metal::UIUtil::RenderOption': unreferenced function with internal linkage has been removed +C:\Users\russi\CLionProjects\metal-engine\src\editor\panel\../util/UIUtil.h(52): warning C4505: 'Metal::UIUtil::RenderTooltip': unreferenced function with internal linkage has been removed +C:\Users\russi\CLionProjects\metal-engine\src\editor\panel\../util/UIUtil.h(60): warning C4505: 'Metal::UIUtil::LargeSpacing': unreferenced function with internal linkage has been removed +C:\Users\russi\CLionProjects\metal-engine\src\editor\panel\../util/UIUtil.h(66): warning C4505: 'Metal::UIUtil::Spacing': unreferenced function with internal linkage has been removed +C:\Users\russi\CLionProjects\metal-engine\src\editor\panel\../util/UIUtil.h(72): warning C4505: 'Metal::UIUtil::DynamicSpacing': unreferenced function with internal linkage has been removed +C:\Users\russi\CLionProjects\metal-engine\src\editor\panel\../util/UIUtil.h(102): warning C4505: 'Metal::UIUtil::DrawVec2Control': unreferenced function with internal linkage has been removed +C:\Users\russi\CLionProjects\metal-engine\src\editor\panel\../util/UIUtil.h(119): warning C4505: 'Metal::UIUtil::DrawVec3Control': unreferenced function with internal linkage has been removed +C:\Users\russi\CLionProjects\metal-engine\src\editor\panel\../util/UIUtil.h(159): warning C4505: 'Metal::UIUtil::DrawQuatControl': unreferenced function with internal linkage has been removed +C:\Users\russi\CLionProjects\metal-engine\src\editor\panel\../util/UIUtil.h(163): warning C4505: 'Metal::UIUtil::GetKeyChordName': unreferenced function with internal linkage has been removed +C:\Users\russi\CLionProjects\metal-engine\src\editor\panel\../util/UIUtil.h(179): warning C4505: 'Metal::UIUtil::GetEntryIcon': unreferenced function with internal linkage has been removed +[30/44] Building CXX object CMakeFiles\metal_engine...ditor\dock-spaces\viewport\EngineFramePanel.cpp.obj +C:\Users\russi\CLionProjects\metal-engine\src\engine\frame-builder\../passes/AbstractPass.h(35): warning C4458: declaration of 'vkCommandBuffer' hides class member +C:\Users\russi\CLionProjects\metal-engine\src\engine\frame-builder\../passes/AbstractPass.h(24): note: see declaration of 'Metal::AbstractPass::vkCommandBuffer' +C:\Users\russi\CLionProjects\metal-engine\src\editor\dock-spaces\viewport\../../../engine/dto/GlobalDataUBO.h(14): warning C4324: 'Metal::GlobalDataUBO': structure was padded due to alignment specifier +C:\Users\russi\CLionProjects\metal-engine\src\editor\dock-spaces\viewport\../../../engine/dto/GlobalDataUBO.h(15): warning C4324: 'Metal::GlobalDataUBO': structure was padded due to alignment specifier +C:\Users\russi\CLionProjects\metal-engine\src\editor\dock-spaces\viewport\../../../engine/dto/LightData.h(11): warning C4324: 'Metal::LightData': structure was padded due to alignment specifier +C:\Users\russi\CLionProjects\metal-engine\src\editor\dock-spaces\viewport\../../../engine/dto/LightData.h(12): warning C4324: 'Metal::LightData': structure was padded due to alignment specifier +C:\Users\russi\CLionProjects\metal-engine\src\editor\dock-spaces\viewport\../../../engine/dto/VolumeData.h(11): warning C4324: 'Metal::VolumeData': structure was padded due to alignment specifier +C:\Users\russi\CLionProjects\metal-engine\src\editor\dock-spaces\viewport\../../../engine/dto/VolumeData.h(12): warning C4324: 'Metal::VolumeData': structure was padded due to alignment specifier +C:\Users\russi\CLionProjects\metal-engine\src\editor\dock-spaces\viewport\../../../engine/dto/MeshMetadata.h(13): warning C4324: 'Metal::MeshMetadata': structure was padded due to alignment specifier +C:\Users\russi\CLionProjects\metal-engine\src\engine\passes\impl\../../dto/PostProcessingPushConstant.h(9): warning C4324: 'Metal::PostProcessingPushConstant': structure was padded due to alignment specifier +C:\Users\russi\CLionProjects\metal-engine\src\engine\passes\impl\../../dto/PostProcessingPushConstant.h(10): warning C4324: 'Metal::PostProcessingPushConstant': structure was padded due to alignment specifier +C:\Users\russi\CLionProjects\metal-engine\src\common\Inspectable.h(125): warning C4100: 'member': unreferenced parameter +C:\Users\russi\CLionProjects\metal-engine\src\common\../editor/enum/EntryType.h(33): warning C4505: 'Metal::EntryType::GetDTO': unreferenced function with internal linkage has been removed +[31/44] Building CXX object CMakeFiles\metal_engine.dir\src\engine\service\StreamingService.cpp.obj +C:\Users\russi\CLionProjects\metal-engine\src\engine\dto/GlobalDataUBO.h(14): warning C4324: 'Metal::GlobalDataUBO': structure was padded due to alignment specifier +C:\Users\russi\CLionProjects\metal-engine\src\engine\dto/GlobalDataUBO.h(15): warning C4324: 'Metal::GlobalDataUBO': structure was padded due to alignment specifier +C:\Users\russi\CLionProjects\metal-engine\src\engine\frame-builder\../passes/AbstractPass.h(35): warning C4458: declaration of 'vkCommandBuffer' hides class member +C:\Users\russi\CLionProjects\metal-engine\src\engine\frame-builder\../passes/AbstractPass.h(24): note: see declaration of 'Metal::AbstractPass::vkCommandBuffer' +C:\Users\russi\CLionProjects\metal-engine\src\common\Inspectable.h(125): warning C4100: 'member': unreferenced parameter +C:\Users\russi\CLionProjects\metal-engine\src\engine\service\../dto/TextureData.h(16): warning C4244: 'initializing': conversion from 'T' to 'int', possible loss of data + with + [ + T=float + ] +C:\Users\russi\CLionProjects\metal-engine\src\engine\service\../dto/TextureData.h(16): warning C4244: 'initializing': conversion from 'T' to 'const int', possible loss of data + with + [ + T=float + ] +C:\Users\russi\CLionProjects\metal-engine\src\engine\service\../dto/TextureData.h(17): warning C4244: 'initializing': conversion from 'T' to 'int', possible loss of data + with + [ + T=float + ] +C:\Users\russi\CLionProjects\metal-engine\src\engine\service\../dto/TextureData.h(17): warning C4244: 'initializing': conversion from 'T' to 'const int', possible loss of data + with + [ + T=float + ] +C:\Users\russi\CLionProjects\metal-engine\src\engine\dto\AbstractComponent.h(14): warning C4458: declaration of 'entityId' hides class member +C:\Users\russi\CLionProjects\metal-engine\src\engine\dto\AbstractComponent.h(31): note: see declaration of 'Metal::AbstractComponent::entityId' +C:\Users\russi\CLionProjects\metal-engine\src\engine\service\../dto/PrimitiveComponent.h(20): warning C4305: 'initializing': truncation from 'double' to 'float' +C:\Users\russi\CLionProjects\metal-engine\src\common\../editor/enum/EntryType.h(33): warning C4505: 'Metal::EntryType::GetDTO': unreferenced function with internal linkage has been removed +[32/44] Building CXX object CMakeFiles\metal_engine.dir\src\engine\service\CameraService.cpp.obj +C:\Users\russi\CLionProjects\metal-engine\src\engine\dto\../../common/Inspectable.h(125): warning C4100: 'member': unreferenced parameter +C:\Users\russi\CLionProjects\metal-engine\src\engine\dto/GlobalDataUBO.h(14): warning C4324: 'Metal::GlobalDataUBO': structure was padded due to alignment specifier +C:\Users\russi\CLionProjects\metal-engine\src\engine\dto/GlobalDataUBO.h(15): warning C4324: 'Metal::GlobalDataUBO': structure was padded due to alignment specifier +C:\Users\russi\CLionProjects\metal-engine\src\engine\frame-builder\../passes/AbstractPass.h(35): warning C4458: declaration of 'vkCommandBuffer' hides class member +C:\Users\russi\CLionProjects\metal-engine\src\engine\frame-builder\../passes/AbstractPass.h(24): note: see declaration of 'Metal::AbstractPass::vkCommandBuffer' +C:\Users\russi\CLionProjects\metal-engine\src\common\../editor/enum/EntryType.h(33): warning C4505: 'Metal::EntryType::GetDTO': unreferenced function with internal linkage has been removed +[33/44] Building CXX object CMakeFiles\metal_engine.dir\src\engine\EngineContext.cpp.obj +C:\Users\russi\CLionProjects\metal-engine\src\engine\dto/GlobalDataUBO.h(14): warning C4324: 'Metal::GlobalDataUBO': structure was padded due to alignment specifier +C:\Users\russi\CLionProjects\metal-engine\src\engine\dto/GlobalDataUBO.h(15): warning C4324: 'Metal::GlobalDataUBO': structure was padded due to alignment specifier +C:\Users\russi\CLionProjects\metal-engine\src\engine\frame-builder\../passes/AbstractPass.h(35): warning C4458: declaration of 'vkCommandBuffer' hides class member +C:\Users\russi\CLionProjects\metal-engine\src\engine\frame-builder\../passes/AbstractPass.h(24): note: see declaration of 'Metal::AbstractPass::vkCommandBuffer' +C:\Users\russi\CLionProjects\metal-engine\src\engine\service\../dto/MeshMetadata.h(13): warning C4324: 'Metal::MeshMetadata': structure was padded due to alignment specifier +C:\Users\russi\CLionProjects\metal-engine\src\engine\service/RayTracingService.h(15): warning C4099: 'Metal::BufferInstance': type name first seen using 'struct' now seen using 'class' +C:\Users\russi\CLionProjects\metal-engine\src\engine\frame-builder\../resource/BufferInstance.h(14): note: see declaration of 'Metal::BufferInstance' +C:\Users\russi\CLionProjects\metal-engine\src\engine\service\../dto/LightData.h(11): warning C4324: 'Metal::LightData': structure was padded due to alignment specifier +C:\Users\russi\CLionProjects\metal-engine\src\engine\service\../dto/LightData.h(12): warning C4324: 'Metal::LightData': structure was padded due to alignment specifier +C:\Users\russi\CLionProjects\metal-engine\src\engine\service/LightService.h(49): warning C4267: 'return': conversion from 'size_t' to 'unsigned int', possible loss of data +C:\Users\russi\CLionProjects\metal-engine\src\engine\service\../dto/VolumeData.h(11): warning C4324: 'Metal::VolumeData': structure was padded due to alignment specifier +C:\Users\russi\CLionProjects\metal-engine\src\engine\service\../dto/VolumeData.h(12): warning C4324: 'Metal::VolumeData': structure was padded due to alignment specifier +C:\Users\russi\CLionProjects\metal-engine\src\engine\service/VolumeService.h(32): warning C4267: 'return': conversion from 'size_t' to 'unsigned int', possible loss of data +C:\Users\russi\CLionProjects\metal-engine\src\common\Inspectable.h(125): warning C4100: 'member': unreferenced parameter +C:\Users\russi\CLionProjects\metal-engine\src\engine\../editor/repository/EditorRepository.h(33): warning C4305: 'initializing': truncation from 'double' to 'float' +C:\Users\russi\CLionProjects\metal-engine\src\engine\dto\AbstractComponent.h(14): warning C4458: declaration of 'entityId' hides class member +C:\Users\russi\CLionProjects\metal-engine\src\engine\dto\AbstractComponent.h(31): note: see declaration of 'Metal::AbstractComponent::entityId' +C:\Users\russi\CLionProjects\metal-engine\src\common\../editor/enum/EntryType.h(33): warning C4505: 'Metal::EntryType::GetDTO': unreferenced function with internal linkage has been removed +[34/44] Building CXX object CMakeFiles\metal_engine.dir\src\engine\passes\impl\PostProcessingPass.cpp.obj +C:\Users\russi\CLionProjects\metal-engine\src\engine\passes\AbstractPass.h(35): warning C4458: declaration of 'vkCommandBuffer' hides class member +C:\Users\russi\CLionProjects\metal-engine\src\engine\passes\AbstractPass.h(24): note: see declaration of 'Metal::AbstractPass::vkCommandBuffer' +C:\Users\russi\CLionProjects\metal-engine\src\engine\passes\impl\../../dto/PostProcessingPushConstant.h(9): warning C4324: 'Metal::PostProcessingPushConstant': structure was padded due to alignment specifier +C:\Users\russi\CLionProjects\metal-engine\src\engine\passes\impl\../../dto/PostProcessingPushConstant.h(10): warning C4324: 'Metal::PostProcessingPushConstant': structure was padded due to alignment specifier +C:\Users\russi\CLionProjects\metal-engine\src\common\Inspectable.h(125): warning C4100: 'member': unreferenced parameter +C:\Users\russi\CLionProjects\metal-engine\src\common\../editor/enum/EntryType.h(33): warning C4505: 'Metal::EntryType::GetDTO': unreferenced function with internal linkage has been removed +[35/44] Building CXX object CMakeFiles\metal_engine.dir\src\engine\frame-builder\EngineFrame.cpp.obj +C:\Users\russi\CLionProjects\metal-engine\src\engine\frame-builder\../passes/AbstractPass.h(35): warning C4458: declaration of 'vkCommandBuffer' hides class member +C:\Users\russi\CLionProjects\metal-engine\src\engine\frame-builder\../passes/AbstractPass.h(24): note: see declaration of 'Metal::AbstractPass::vkCommandBuffer' +[36/44] Building CXX object CMakeFiles\metal_engine...src\engine\frame-builder\EngineFrameBuilder.cpp.obj +FAILED: CMakeFiles/metal_engine.dir/src/engine/frame-builder/EngineFrameBuilder.cpp.obj +C:\PROGRA~1\MICROS~2\18\COMMUN~1\VC\Tools\MSVC\1450~1.357\bin\Hostx64\x64\cl.exe /nologo /TP -DBOOST_IOSTREAMS_DYN_LINK -DBOOST_IOSTREAMS_NO_LIB -DBOOST_RANDOM_DYN_LINK -DBOOST_RANDOM_NO_LIB -DFMT_SHARED -DGLFW_DLL -DIMATH_DLL -DIMGUI_ENABLE_FREETYPE -DMESHOPTIMIZER_API=__declspec(dllimport) -DNFD_SHARED -DNOMINMAX -DOPENVDB_ABI_VERSION_NUMBER=12 -DOPENVDB_DLL -DOPENVDB_USE_DELAYED_LOADING -DSPDLOG_COMPILED_LIB -DSPDLOG_FMT_EXTERNAL -DSPDLOG_SHARED_LIB -DTBB_USE_DEBUG -D_WIN32 -IC:\Users\russi\CLionProjects\metal-engine\dependencies\vk-bootstrap\src -external:IC:\Users\russi\CLionProjects\metal-engine\cmake-build-debug-visual-studio\vcpkg_installed\x64-windows\include -external:IC:\Users\russi\CLionProjects\metal-engine\cmake-build-debug-visual-studio\vcpkg_installed\x64-windows\include\vma -external:IC:\Users\russi\CLionProjects\metal-engine\cmake-build-debug-visual-studio\vcpkg_installed\x64-windows\include\Imath -external:W0 /DWIN32 /D_WINDOWS /EHsc -DVK_PROTOTYPES /Ob0 /Od /RTC1 -std:c++20 -MDd -Zi /W4 /wd4251 /wd4275 /utf-8 /EHsc /showIncludes @CMakeFiles\metal_engine.dir\src\engine\frame-builder\EngineFrameBuilder.cpp.obj.modmap /FoCMakeFiles\metal_engine.dir\src\engine\frame-builder\EngineFrameBuilder.cpp.obj /FdCMakeFiles\metal_engine.dir\ /FS -c C:\Users\russi\CLionProjects\metal-engine\src\engine\frame-builder\EngineFrameBuilder.cpp +C:\Users\russi\CLionProjects\metal-engine\src\engine\frame-builder\../passes/AbstractPass.h(35): warning C4458: declaration of 'vkCommandBuffer' hides class member +C:\Users\russi\CLionProjects\metal-engine\src\engine\frame-builder\../passes/AbstractPass.h(24): note: see declaration of 'Metal::AbstractPass::vkCommandBuffer' +C:\Users\russi\CLionProjects\metal-engine\src\engine\dto/GlobalDataUBO.h(14): warning C4324: 'Metal::GlobalDataUBO': structure was padded due to alignment specifier +C:\Users\russi\CLionProjects\metal-engine\src\engine\dto/GlobalDataUBO.h(15): warning C4324: 'Metal::GlobalDataUBO': structure was padded due to alignment specifier +C:\Program Files\Microsoft Visual Studio\18\Community\VC\Tools\MSVC\14.50.35717\include\xmemory(734): error C2672: 'std::construct_at': no matching overloaded function found +C:\Program Files\Microsoft Visual Studio\18\Community\VC\Tools\MSVC\14.50.35717\include\xutility(507): note: could be '_Ty *std::construct_at(_Ty *const ,_Types ...) noexcept()' +C:\Program Files\Microsoft Visual Studio\18\Community\VC\Tools\MSVC\14.50.35717\include\xmemory(734): note: the associated constraints are not satisfied +C:\Program Files\Microsoft Visual Studio\18\Community\VC\Tools\MSVC\14.50.35717\include\xutility(505): note: 'std::unique_ptr>::unique_ptr(const std::unique_ptr> &)': attempting to reference a deleted function +C:\Program Files\Microsoft Visual Studio\18\Community\VC\Tools\MSVC\14.50.35717\include\memory(3504): note: see declaration of 'std::unique_ptr>::unique_ptr' +C:\Program Files\Microsoft Visual Studio\18\Community\VC\Tools\MSVC\14.50.35717\include\memory(3504): note: 'std::unique_ptr>::unique_ptr(const std::unique_ptr> &)': function was explicitly deleted +C:\Program Files\Microsoft Visual Studio\18\Community\VC\Tools\MSVC\14.50.35717\include\xutility(505): note: 'std::unique_ptr>::unique_ptr(const std::unique_ptr> &)': attempting to reference a deleted function +C:\Program Files\Microsoft Visual Studio\18\Community\VC\Tools\MSVC\14.50.35717\include\memory(3504): note: see declaration of 'std::unique_ptr>::unique_ptr' +C:\Program Files\Microsoft Visual Studio\18\Community\VC\Tools\MSVC\14.50.35717\include\memory(3504): note: 'std::unique_ptr>::unique_ptr(const std::unique_ptr> &)': function was explicitly deleted +C:\Program Files\Microsoft Visual Studio\18\Community\VC\Tools\MSVC\14.50.35717\include\xmemory(734): note: the template instantiation context (the oldest one first) is +C:\Users\russi\CLionProjects\metal-engine\src\engine\frame-builder\EngineFrameBuilder.cpp(127): note: see reference to class template instantiation 'std::vector>,std::allocator>>>' being compiled +C:\Program Files\Microsoft Visual Studio\18\Community\VC\Tools\MSVC\14.50.35717\include\vector(745): note: while compiling class template member function 'std::vector>,std::allocator>>>::vector(const std::vector>,std::allocator>>> &)' +C:\Users\russi\CLionProjects\metal-engine\src\engine\frame-builder\EngineFrameBuilder.cpp(132): note: see the first reference to 'std::vector>,std::allocator>>>::vector' in 'Metal::EngineFrameBuilder::build' +C:\Program Files\Microsoft Visual Studio\18\Community\VC\Tools\MSVC\14.50.35717\include\vector(749): note: see reference to function template instantiation 'void std::vector>,std::allocator>>>::_Construct_n>*const &,std::unique_ptr>*const &>(const unsigned __int64,std::unique_ptr> *const &,std::unique_ptr> *const &)' being compiled +C:\Program Files\Microsoft Visual Studio\18\Community\VC\Tools\MSVC\14.50.35717\include\vector(2120): note: see reference to function template instantiation 'std::unique_ptr> *std::_Uninitialized_copy>*,std::unique_ptr>*,std::allocator>>>(_InIt,_Se,std::unique_ptr> *,_Alloc &)' being compiled + with + [ + _InIt=std::unique_ptr> *, + _Se=std::unique_ptr> *, + _Alloc=std::allocator>> + ] +C:\Program Files\Microsoft Visual Studio\18\Community\VC\Tools\MSVC\14.50.35717\include\xmemory(1922): note: see reference to function template instantiation 'void std::_Uninitialized_backout_al>>>::_Emplace_back>&>(std::unique_ptr> &)' being compiled +C:\Program Files\Microsoft Visual Studio\18\Community\VC\Tools\MSVC\14.50.35717\include\xmemory(1864): note: see reference to function template instantiation 'void std::_Default_allocator_traits<_Alloc>::construct<_Ty,std::unique_ptr>&>(_Alloc &,_Objty *const ,std::unique_ptr> &)' being compiled + with + [ + _Alloc=std::allocator>>, + _Ty=std::unique_ptr>, + _Objty=std::unique_ptr> + ] +[37/44] Building CXX object CMakeFiles\metal_engine.dir\src\engine\enum\ComponentType.cpp.obj +C:\Users\russi\CLionProjects\metal-engine\src\engine\dto/GlobalDataUBO.h(14): warning C4324: 'Metal::GlobalDataUBO': structure was padded due to alignment specifier +C:\Users\russi\CLionProjects\metal-engine\src\engine\dto/GlobalDataUBO.h(15): warning C4324: 'Metal::GlobalDataUBO': structure was padded due to alignment specifier +C:\Users\russi\CLionProjects\metal-engine\src\engine\frame-builder\../passes/AbstractPass.h(35): warning C4458: declaration of 'vkCommandBuffer' hides class member +C:\Users\russi\CLionProjects\metal-engine\src\engine\frame-builder\../passes/AbstractPass.h(24): note: see declaration of 'Metal::AbstractPass::vkCommandBuffer' +C:\Users\russi\CLionProjects\metal-engine\src\common\Inspectable.h(125): warning C4100: 'member': unreferenced parameter +C:\Users\russi\CLionProjects\metal-engine\src\engine\service\../dto/MeshMetadata.h(13): warning C4324: 'Metal::MeshMetadata': structure was padded due to alignment specifier +C:\Users\russi\CLionProjects\metal-engine\src\engine\enum\../service/RayTracingService.h(15): warning C4099: 'Metal::BufferInstance': type name first seen using 'struct' now seen using 'class' +C:\Users\russi\CLionProjects\metal-engine\src\engine\frame-builder\../resource/BufferInstance.h(14): note: see declaration of 'Metal::BufferInstance' +C:\Users\russi\CLionProjects\metal-engine\src\engine\dto\AbstractComponent.h(14): warning C4458: declaration of 'entityId' hides class member +C:\Users\russi\CLionProjects\metal-engine\src\engine\dto\AbstractComponent.h(31): note: see declaration of 'Metal::AbstractComponent::entityId' +C:\Users\russi\CLionProjects\metal-engine\src\engine\enum\../dto/PrimitiveComponent.h(20): warning C4305: 'initializing': truncation from 'double' to 'float' +C:\Users\russi\CLionProjects\metal-engine\src\common\../editor/enum/EntryType.h(33): warning C4505: 'Metal::EntryType::GetDTO': unreferenced function with internal linkage has been removed +[38/44] Building CXX object CMakeFiles\metal_engine...engine\passes\impl\TemporalAccumulationPass.cpp.obj +C:\Users\russi\CLionProjects\metal-engine\src\engine\passes\AbstractPass.h(35): warning C4458: declaration of 'vkCommandBuffer' hides class member +C:\Users\russi\CLionProjects\metal-engine\src\engine\passes\AbstractPass.h(24): note: see declaration of 'Metal::AbstractPass::vkCommandBuffer' +[39/44] Building CXX object CMakeFiles\metal_engine.dir\src\main.cpp.obj +C:\Users\russi\CLionProjects\metal-engine\src\editor\dto\../../common//Inspectable.h(125): warning C4100: 'member': unreferenced parameter +C:\Users\russi\CLionProjects\metal-engine\src\editor\service\../../common/AbstractImporter.h(19): warning C4100: 'stopToken': unreferenced parameter +C:\Users\russi\CLionProjects\metal-engine\src\editor\service\../../common/AbstractImporter.h(18): warning C4100: 'settings': unreferenced parameter +C:\Users\russi\CLionProjects\metal-engine\src\editor\service\../../common/AbstractImporter.h(17): warning C4100: 'pathToFile': unreferenced parameter +C:\Users\russi\CLionProjects\metal-engine\src\editor\service\../../common/AbstractImporter.h(17): warning C4100: 'targetDir': unreferenced parameter +C:\Users\russi\CLionProjects\metal-engine\src\editor/service/TextureImporterService.h(8): warning C4099: 'Metal::DirectoryService': type name first seen using 'struct' now seen using 'class' +C:\Users\russi\CLionProjects\metal-engine\src\core/DirectoryService.h(11): note: see declaration of 'Metal::DirectoryService' +C:\Users\russi\CLionProjects\metal-engine\src\editor/service/VoxelImporterService.h(9): warning C4099: 'Metal::DirectoryService': type name first seen using 'struct' now seen using 'class' +C:\Users\russi\CLionProjects\metal-engine\src\core/DirectoryService.h(11): note: see declaration of 'Metal::DirectoryService' +C:\Users\russi\CLionProjects\metal-engine\src\editor/repository/EditorRepository.h(33): warning C4305: 'initializing': truncation from 'double' to 'float' +C:\Users\russi\CLionProjects\metal-engine\src\engine/repository/WorldRepository.h(15): warning C4099: 'Metal::DirectoryService': type name first seen using 'struct' now seen using 'class' +C:\Users\russi\CLionProjects\metal-engine\src\core/DirectoryService.h(11): note: see declaration of 'Metal::DirectoryService' +C:\Users\russi\CLionProjects\metal-engine\src\engine/service/CommandBufferRecorderService.h(10): warning C4100: 'resource': unreferenced parameter +C:\Users\russi\CLionProjects\metal-engine\src\engine\service\../dto/LightData.h(11): warning C4324: 'Metal::LightData': structure was padded due to alignment specifier +C:\Users\russi\CLionProjects\metal-engine\src\engine\service\../dto/LightData.h(12): warning C4324: 'Metal::LightData': structure was padded due to alignment specifier +C:\Users\russi\CLionProjects\metal-engine\src\engine/service/LightService.h(49): warning C4267: 'return': conversion from 'size_t' to 'unsigned int', possible loss of data +C:\Users\russi\CLionProjects\metal-engine\src\engine/service/MeshService.h(14): warning C4099: 'Metal::DirectoryService': type name first seen using 'struct' now seen using 'class' +C:\Users\russi\CLionProjects\metal-engine\src\core/DirectoryService.h(11): note: see declaration of 'Metal::DirectoryService' +C:\Users\russi\CLionProjects\metal-engine\src\engine\service\../dto/MeshMetadata.h(13): warning C4324: 'Metal::MeshMetadata': structure was padded due to alignment specifier +C:\Users\russi\CLionProjects\metal-engine\src\engine/service/RayTracingService.h(15): warning C4099: 'Metal::BufferInstance': type name first seen using 'struct' now seen using 'class' +C:\Users\russi\CLionProjects\metal-engine\src\engine\service\../resource/BufferInstance.h(14): note: see declaration of 'Metal::BufferInstance' +C:\Users\russi\CLionProjects\metal-engine\src\engine/service/ShaderService.h(10): warning C4099: 'Metal::DirectoryService': type name first seen using 'struct' now seen using 'class' +C:\Users\russi\CLionProjects\metal-engine\src\core/DirectoryService.h(11): note: see declaration of 'Metal::DirectoryService' +C:\Users\russi\CLionProjects\metal-engine\src\engine\service\../dto/TextureData.h(16): warning C4244: 'initializing': conversion from 'T' to 'int', possible loss of data + with + [ + T=float + ] +C:\Users\russi\CLionProjects\metal-engine\src\engine\service\../dto/TextureData.h(16): warning C4244: 'initializing': conversion from 'T' to 'const int', possible loss of data + with + [ + T=float + ] +C:\Users\russi\CLionProjects\metal-engine\src\engine\service\../dto/TextureData.h(17): warning C4244: 'initializing': conversion from 'T' to 'int', possible loss of data + with + [ + T=float + ] +C:\Users\russi\CLionProjects\metal-engine\src\engine\service\../dto/TextureData.h(17): warning C4244: 'initializing': conversion from 'T' to 'const int', possible loss of data + with + [ + T=float + ] +C:\Users\russi\CLionProjects\metal-engine\src\engine/service/TextureService.h(17): warning C4099: 'Metal::DirectoryService': type name first seen using 'struct' now seen using 'class' +C:\Users\russi\CLionProjects\metal-engine\src\core/DirectoryService.h(11): note: see declaration of 'Metal::DirectoryService' +C:\Users\russi\CLionProjects\metal-engine\src\engine\service\../dto/VolumeData.h(11): warning C4324: 'Metal::VolumeData': structure was padded due to alignment specifier +C:\Users\russi\CLionProjects\metal-engine\src\engine\service\../dto/VolumeData.h(12): warning C4324: 'Metal::VolumeData': structure was padded due to alignment specifier +C:\Users\russi\CLionProjects\metal-engine\src\engine/service/VolumeService.h(32): warning C4267: 'return': conversion from 'size_t' to 'unsigned int', possible loss of data +C:\Users\russi\CLionProjects\metal-engine\src\engine\dto/GlobalDataUBO.h(14): warning C4324: 'Metal::GlobalDataUBO': structure was padded due to alignment specifier +C:\Users\russi\CLionProjects\metal-engine\src\engine\dto/GlobalDataUBO.h(15): warning C4324: 'Metal::GlobalDataUBO': structure was padded due to alignment specifier +C:\Users\russi\CLionProjects\metal-engine\src\engine\frame-builder\../passes/AbstractPass.h(35): warning C4458: declaration of 'vkCommandBuffer' hides class member +C:\Users\russi\CLionProjects\metal-engine\src\engine\frame-builder\../passes/AbstractPass.h(24): note: see declaration of 'Metal::AbstractPass::vkCommandBuffer' +C:\Users\russi\CLionProjects\metal-engine\src\common\../editor/enum/EntryType.h(33): warning C4505: 'Metal::EntryType::GetDTO': unreferenced function with internal linkage has been removed +C:\Users\russi\CLionProjects\metal-engine\src\editor\service\../enum/NotificationSeverity.h(14): warning C4505: 'Metal::NotificationSeverities::GetIcon': unreferenced function with internal linkage has been removed +C:\Users\russi\CLionProjects\metal-engine\src\editor\service\../enum/NotificationSeverity.h(26): warning C4505: 'Metal::NotificationSeverities::GetColor': unreferenced function with internal linkage has been removed +[40/44] Building CXX object CMakeFiles\metal_engine.dir\src\engine\passes\impl\SpatialFilterPass.cpp.obj +C:\Users\russi\CLionProjects\metal-engine\src\engine\passes\AbstractPass.h(35): warning C4458: declaration of 'vkCommandBuffer' hides class member +C:\Users\russi\CLionProjects\metal-engine\src\engine\passes\AbstractPass.h(24): note: see declaration of 'Metal::AbstractPass::vkCommandBuffer' +[41/44] Building CXX object CMakeFiles\metal_engine.dir\src\engine\service\RayTracingService.cpp.obj +C:\Users\russi\CLionProjects\metal-engine\src\engine\service\../dto/MeshMetadata.h(13): warning C4324: 'Metal::MeshMetadata': structure was padded due to alignment specifier +C:\Users\russi\CLionProjects\metal-engine\src\engine\service\../resource/BufferInstance.h(14): warning C4099: 'Metal::BufferInstance': type name first seen using 'class' now seen using 'struct' +C:\Users\russi\CLionProjects\metal-engine\src\engine\service\../resource/BufferInstance.h(14): note: see declaration of 'Metal::BufferInstance' +C:\Users\russi\CLionProjects\metal-engine\src\engine\dto\../../common/Inspectable.h(125): warning C4100: 'member': unreferenced parameter +C:\Users\russi\CLionProjects\metal-engine\src\engine\dto\AbstractComponent.h(14): warning C4458: declaration of 'entityId' hides class member +C:\Users\russi\CLionProjects\metal-engine\src\engine\dto\AbstractComponent.h(31): note: see declaration of 'Metal::AbstractComponent::entityId' +C:\Users\russi\CLionProjects\metal-engine\src\engine\service\../dto/PrimitiveComponent.h(20): warning C4305: 'initializing': truncation from 'double' to 'float' +C:\Users\russi\CLionProjects\metal-engine\src\engine\dto/GlobalDataUBO.h(14): warning C4324: 'Metal::GlobalDataUBO': structure was padded due to alignment specifier +C:\Users\russi\CLionProjects\metal-engine\src\engine\dto/GlobalDataUBO.h(15): warning C4324: 'Metal::GlobalDataUBO': structure was padded due to alignment specifier +C:\Users\russi\CLionProjects\metal-engine\src\engine\frame-builder\../passes/AbstractPass.h(35): warning C4458: declaration of 'vkCommandBuffer' hides class member +C:\Users\russi\CLionProjects\metal-engine\src\engine\frame-builder\../passes/AbstractPass.h(24): note: see declaration of 'Metal::AbstractPass::vkCommandBuffer' +C:\Users\russi\CLionProjects\metal-engine\src\engine\service\RayTracingService.cpp(153): warning C4189: 'vulkan': local variable is initialized but not referenced +C:\Users\russi\CLionProjects\metal-engine\src\engine\service\RayTracingService.cpp(409): warning C4189: 'vulkan': local variable is initialized but not referenced +C:\Users\russi\CLionProjects\metal-engine\src\common\../editor/enum/EntryType.h(33): warning C4505: 'Metal::EntryType::GetDTO': unreferenced function with internal linkage has been removed +[42/44] Building CXX object CMakeFiles\metal_engine.dir\src\core\FrameService.cpp.obj +C:\Users\russi\CLionProjects\metal-engine\src\engine\dto/GlobalDataUBO.h(14): warning C4324: 'Metal::GlobalDataUBO': structure was padded due to alignment specifier +C:\Users\russi\CLionProjects\metal-engine\src\engine\dto/GlobalDataUBO.h(15): warning C4324: 'Metal::GlobalDataUBO': structure was padded due to alignment specifier +C:\Users\russi\CLionProjects\metal-engine\src\engine\frame-builder\../passes/AbstractPass.h(35): warning C4458: declaration of 'vkCommandBuffer' hides class member +C:\Users\russi\CLionProjects\metal-engine\src\engine\frame-builder\../passes/AbstractPass.h(24): note: see declaration of 'Metal::AbstractPass::vkCommandBuffer' +C:\Users\russi\CLionProjects\metal-engine\src\core\FrameService.cpp(26): warning C4458: declaration of 'panel' hides class member +C:\Users\russi\CLionProjects\metal-engine\src\core\FrameService.h(19): note: see declaration of 'Metal::FrameService::panel' +[43/44] Building CXX object CMakeFiles\metal_engine.dir\src\engine\service\VolumeService.cpp.obj +C:\Users\russi\CLionProjects\metal-engine\src\engine\service\../dto/VolumeData.h(11): warning C4324: 'Metal::VolumeData': structure was padded due to alignment specifier +C:\Users\russi\CLionProjects\metal-engine\src\engine\service\../dto/VolumeData.h(12): warning C4324: 'Metal::VolumeData': structure was padded due to alignment specifier +C:\Users\russi\CLionProjects\metal-engine\src\engine\service\VolumeService.h(32): warning C4267: 'return': conversion from 'size_t' to 'unsigned int', possible loss of data +C:\Users\russi\CLionProjects\metal-engine\src\engine\dto\../../common/Inspectable.h(125): warning C4100: 'member': unreferenced parameter +C:\Users\russi\CLionProjects\metal-engine\src\engine\dto\AbstractComponent.h(14): warning C4458: declaration of 'entityId' hides class member +C:\Users\russi\CLionProjects\metal-engine\src\engine\dto\AbstractComponent.h(31): note: see declaration of 'Metal::AbstractComponent::entityId' +C:\Users\russi\CLionProjects\metal-engine\src\engine\dto/GlobalDataUBO.h(14): warning C4324: 'Metal::GlobalDataUBO': structure was padded due to alignment specifier +C:\Users\russi\CLionProjects\metal-engine\src\engine\dto/GlobalDataUBO.h(15): warning C4324: 'Metal::GlobalDataUBO': structure was padded due to alignment specifier +C:\Users\russi\CLionProjects\metal-engine\src\engine\frame-builder\../passes/AbstractPass.h(35): warning C4458: declaration of 'vkCommandBuffer' hides class member +C:\Users\russi\CLionProjects\metal-engine\src\engine\frame-builder\../passes/AbstractPass.h(24): note: see declaration of 'Metal::AbstractPass::vkCommandBuffer' +C:\Users\russi\CLionProjects\metal-engine\src\common\../editor/enum/EntryType.h(33): warning C4505: 'Metal::EntryType::GetDTO': unreferenced function with internal linkage has been removed +ninja: build stopped: subcommand failed. \ No newline at end of file diff --git a/src/ApplicationContext.h b/src/ApplicationContext.h index 54ba00fd..46c9dc6b 100644 --- a/src/ApplicationContext.h +++ b/src/ApplicationContext.h @@ -8,6 +8,8 @@ #include #include #include +#include +#include #include "common/IInit.h" #include "common/IContextMember.h" @@ -23,6 +25,22 @@ namespace Metal { std::vector > instances; bool debugMode; + template + static std::string getTypeName() { + std::string name = typeid(T).name(); + size_t lastSpace = name.find_last_of(' '); + if (lastSpace != std::string::npos) { + name = name.substr(lastSpace + 1); + } + size_t lastColon = name.find_last_of(':'); + if (lastColon != std::string::npos) { + name = name.substr(lastColon + 1); + } + std::transform(name.begin(), name.end(), name.begin(), + [](unsigned char c) { return std::tolower(c); }); + return name; + } + public: explicit ApplicationContext(bool debugMode); @@ -32,23 +50,27 @@ namespace Metal { void registerSingleton(std::shared_ptr instance) { static_assert(std::is_base_of_v, "T must derive from IContextMember"); T *ptr = instance.get(); - singletons[typeid(T).name()] = static_cast(ptr); + singletons[getTypeName()] = static_cast(ptr); instances.push_back(std::move(instance)); } template T &getSingleton() { - auto it = singletons.find(typeid(T).name()); + auto name = getTypeName(); + auto it = singletons.find(name); if (it == singletons.end()) { - throw std::runtime_error(std::string("Singleton not registered: ") + typeid(T).name()); + throw std::runtime_error(std::string("Singleton not registered: ") + name); } return *static_cast(it->second); } void *getSingletonByName(const std::string &name) { - auto it = singletons.find(name); + std::string lowerName = name; + std::transform(lowerName.begin(), lowerName.end(), lowerName.begin(), + [](unsigned char c) { return std::tolower(c); }); + auto it = singletons.find(lowerName); if (it == singletons.end()) { - throw std::runtime_error(std::string("Singleton not registered: ") + name); + throw std::runtime_error(std::string("Singleton not registered: ") + lowerName); } return it->second; } diff --git a/src/editor/panel/FileImportModalPanel.h b/src/editor/panel/FileImportModalPanel.h index 89c0849b..f3f5f713 100644 --- a/src/editor/panel/FileImportModalPanel.h +++ b/src/editor/panel/FileImportModalPanel.h @@ -3,6 +3,7 @@ #include "../abstract/AbstractPanel.h" namespace Metal { + class FilesService; class FormPanel; struct EditorRepository; class FileImporterService; @@ -15,13 +16,15 @@ namespace Metal { EditorRepository *editorRepository = nullptr; FileImporterService *fileImporterService = nullptr; NotificationService *notificationService = nullptr; + FilesService *filesService = nullptr; public: std::vector getDependencies() override { return { {"EditorRepository", editorRepository}, {"FileImporterService", fileImporterService}, - {"NotificationService", notificationService} + {"NotificationService", notificationService}, + {"FilesService", filesService} }; } diff --git a/src/editor/service/FilesService.cpp b/src/editor/service/FilesService.cpp index 5b59131f..8813ccaf 100644 --- a/src/editor/service/FilesService.cpp +++ b/src/editor/service/FilesService.cpp @@ -27,14 +27,14 @@ std::filesystem::remove_all(rootDir + "/assets/" + F(entry.second->getId())); std::filesystem::file_time_type ftime = last_write_time(entry); namespace Metal { - void filesService->onInitialize() { + void FilesService::onInitialize() { root = new FSEntry(nullptr, directoryService->getAssetRefDirectory(), ""); root->type = EntryType::DIRECTORY; root->name = "Files"; GetEntries(root); } - std::unique_ptr filesService->getResource(const std::string &id) { + std::unique_ptr FilesService::getResource(const std::string &id) { try { for (const auto &entry: fs::recursive_directory_iterator(root->absolutePath)) { if (entry.is_regular_file() && @@ -57,7 +57,7 @@ namespace Metal { return nullptr; } - void filesService->deleteFiles(const std::unordered_map &selected) { + void FilesService::deleteFiles(const std::unordered_map &selected) { for (auto &entry: selected) { switch (entry.second->type) { case EntryType::DIRECTORY: { @@ -91,7 +91,7 @@ namespace Metal { } } - void filesService->CreateDirectory(FSEntry *currentDirectory) { + void FilesService::CreateDirectory(FSEntry *currentDirectory) { int count = 0; for (FSEntry *child: currentDirectory->children) { if (child->type == EntryType::DIRECTORY && child->name == "New Directory (" + std::to_string(count) + ")") { @@ -105,7 +105,7 @@ namespace Metal { std::filesystem::create_directory(pathToDir); } - void filesService->Move(FSEntry *toMove, FSEntry *targetDir) { + void FilesService::Move(FSEntry *toMove, FSEntry *targetDir) { if (!targetDir || targetDir->type != EntryType::DIRECTORY) { return; } @@ -133,7 +133,7 @@ namespace Metal { targetDir->children.push_back(toMove); } - void filesService->GetEntries(FSEntry *root) { + void FilesService::GetEntries(FSEntry *root) { if (root->type != EntryType::DIRECTORY) { return; } diff --git a/src/editor/service/MeshImporterService.h b/src/editor/service/MeshImporterService.h index 360be3a5..aa9c33fe 100644 --- a/src/editor/service/MeshImporterService.h +++ b/src/editor/service/MeshImporterService.h @@ -9,6 +9,8 @@ #include namespace Metal { + struct DirectoryService; + struct MeshId { std::string id; glm::vec3 gizmoCenter; diff --git a/src/editor/service/SceneImporterService.cpp b/src/editor/service/SceneImporterService.cpp index 86ac3a29..ce925d01 100644 --- a/src/editor/service/SceneImporterService.cpp +++ b/src/editor/service/SceneImporterService.cpp @@ -59,7 +59,7 @@ namespace Metal { throw std::runtime_error("Import cancelled"); } - meshImporterService.persistAllMeshes(targetDir, scene, meshMap, stopToken); + meshImporterService->persistAllMeshes(targetDir, scene, meshMap, stopToken); if (stopToken.stop_requested()) { throw std::runtime_error("Import cancelled"); @@ -133,7 +133,7 @@ namespace Metal { childMeshNode.entity.name = assimpMesh->mName.length > 0 ? assimpMesh->mName.data : "Mesh"; const aiMaterial *material = aiScene->mMaterials[assimpMesh->mMaterialIndex]; - materialImporterService.importMaterial(targetDir, material, aiScene, rootDirectory, + materialImporterService->importMaterial(targetDir, material, aiScene, rootDirectory, *childMeshNode.primitive, stopToken); } } diff --git a/src/engine/frame-builder/EngineFrame.cpp b/src/engine/frame-builder/EngineFrame.cpp index 49d71f48..66e5bb4a 100644 --- a/src/engine/frame-builder/EngineFrame.cpp +++ b/src/engine/frame-builder/EngineFrame.cpp @@ -12,9 +12,9 @@ namespace Metal { } } - void EngineFrame::addPass(CommandBufferRecorder *recorder, const std::vector> &p) { + void EngineFrame::addPass(CommandBufferRecorder *recorder, std::vector> p) { if (recorder) { - passes.emplace_back(recorder, p); + passes.emplace_back(recorder, std::move(p)); } } diff --git a/src/engine/frame-builder/EngineFrame.h b/src/engine/frame-builder/EngineFrame.h index 9ea82210..992c611a 100644 --- a/src/engine/frame-builder/EngineFrame.h +++ b/src/engine/frame-builder/EngineFrame.h @@ -38,7 +38,7 @@ namespace Metal { return nullptr; } - void addPass(CommandBufferRecorder *recorder, const std::vector> &p); + void addPass(CommandBufferRecorder *recorder, std::vector> p); void onSync(); diff --git a/src/engine/frame-builder/EngineFrameBuilder.cpp b/src/engine/frame-builder/EngineFrameBuilder.cpp index 8d3359a8..7693f009 100644 --- a/src/engine/frame-builder/EngineFrameBuilder.cpp +++ b/src/engine/frame-builder/EngineFrameBuilder.cpp @@ -129,7 +129,10 @@ namespace Metal { for (const auto &cbId: recorderOrder) { if (auto *recorder = dynamic_cast(builtResources.at(cbId))) { - frame->addPass(recorder, recorderToPasses[cbId]); + auto it = recorderToPasses.find(cbId); + if (it != recorderToPasses.end() && !it->second.empty()) { + frame->addPass(recorder, std::move(it->second)); + } } } diff --git a/src/engine/service/BufferService.cpp b/src/engine/service/BufferService.cpp index d6523bf1..3078cd54 100644 --- a/src/engine/service/BufferService.cpp +++ b/src/engine/service/BufferService.cpp @@ -5,6 +5,8 @@ #include "../resource/BufferInstance.h" namespace Metal { + + BufferInstance *BufferService::createBuffer(const std::string &id, VkDeviceSize bufferSize, VkBufferUsageFlags usageFlags, VkMemoryPropertyFlags memoryPropertyFlags, BufferType type) { diff --git a/src/engine/service/BufferService.h b/src/engine/service/BufferService.h index 4c77aa73..4fac84e6 100644 --- a/src/engine/service/BufferService.h +++ b/src/engine/service/BufferService.h @@ -21,9 +21,11 @@ namespace Metal { BufferInstance *buffer) const; public: - BufferService() = default; - - std::vector getDependencies() override; + std::vector getDependencies() override { + return { + {"VulkanContext", &vulkanContext} + }; + } [[nodiscard]] unsigned int findMemoryType(unsigned int typeFilter, VkMemoryPropertyFlags properties) const; diff --git a/src/engine/service/MeshService.cpp b/src/engine/service/MeshService.cpp index 417887bf..4394c482 100644 --- a/src/engine/service/MeshService.cpp +++ b/src/engine/service/MeshService.cpp @@ -5,6 +5,7 @@ #include "../../core/vulkan/VulkanContext.h" #include "../../common/FilesUtil.h" +#include "../../common/LoggerUtil.h" #include "../../core/DirectoryService.h" #include diff --git a/src/engine/service/PipelineService.h b/src/engine/service/PipelineService.h index a80bbe1f..2c134925 100644 --- a/src/engine/service/PipelineService.h +++ b/src/engine/service/PipelineService.h @@ -27,7 +27,15 @@ namespace Metal { public: PipelineService() = default; - std::vector getDependencies() override; + std::vector getDependencies() override { + return { + {"VulkanContext", &vulkanContext}, + {"FramebufferService", &framebufferService}, + {"BufferService", &bufferService}, + {"DescriptorSetService", &descriptorSetService}, + {"ShaderService", &shaderService} + }; + } PipelineInstance *createPipeline(PipelineBuilder &pipelineBuilder); diff --git a/src/main.cpp b/src/main.cpp index bb6fe456..8c08e1ab 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -50,7 +50,7 @@ #include "engine/EngineContext.h" int main(int, char **) { - std::shared_ptr context{}; + std::shared_ptr context = std::make_shared(false); // --- ORDER MATTERS context->registerSingleton(context); From e10d7fb732f13f66b8e2a9ebf249a14c1da0f332 Mon Sep 17 00:00:00 2001 From: facobackup Date: Sat, 14 Mar 2026 18:29:57 -0300 Subject: [PATCH 15/18] Fixes --- resources/shaders/rt/HWRayTracing.rgen | 2 + resources/shaders/tools/Icon.frag | 90 ------------------- src/ApplicationContext.cpp | 19 ++-- src/common/AbstractResourceService.h | 9 +- src/common/IContextMember.cpp | 5 +- src/common/IContextMember.h | 2 +- src/core/DirectoryService.cpp | 9 ++ src/core/DirectoryService.h | 16 ++-- src/core/FrameService.cpp | 8 +- src/core/FrameService.h | 14 ++- src/core/glfw/GLFWContext.cpp | 2 +- src/core/glfw/GLFWContext.h | 6 +- src/core/gui/GuiContext.cpp | 2 +- src/core/gui/GuiContext.h | 10 +-- src/core/vulkan/VulkanContext.cpp | 12 +-- src/core/vulkan/VulkanContext.h | 18 ++-- src/editor/EditorPanel.cpp | 8 +- src/editor/EditorPanel.h | 4 +- src/editor/abstract/AbstractPanel.cpp | 7 +- src/editor/abstract/AbstractPanel.h | 2 +- .../abstract/form/AbstractFormFieldPanel.h | 2 +- src/editor/abstract/form/FormPanel.cpp | 6 +- .../abstract/form/types/ResourceField.cpp | 2 +- .../abstract/form/types/ResourceField.h | 2 +- .../dock-spaces/docks/DockSpacePanel.cpp | 2 +- src/editor/dock-spaces/docks/DockSpacePanel.h | 4 +- .../dock-spaces/files/FilePreviewPanel.h | 4 +- .../dock-spaces/files/FilesHeaderPanel.h | 2 +- src/editor/dock-spaces/files/FilesListPanel.h | 2 +- src/editor/dock-spaces/files/FilesPanel.cpp | 6 +- src/editor/dock-spaces/files/FilesPanel.h | 14 +-- .../dock-spaces/footer/EditorFooterPanel.cpp | 5 +- .../dock-spaces/footer/EditorFooterPanel.h | 2 +- .../dock-spaces/header/AsyncTaskPanel.h | 2 +- .../dock-spaces/header/EditorHeaderPanel.cpp | 19 ++-- .../dock-spaces/header/EditorHeaderPanel.h | 6 +- .../dock-spaces/inspector/InspectorPanel.cpp | 2 +- .../dock-spaces/inspector/InspectorPanel.h | 4 +- src/editor/dock-spaces/metrics/MetricsPanel.h | 12 +-- .../repositories/RepositoriesPanel.cpp | 2 +- .../repositories/RepositoriesPanel.h | 7 +- .../viewport/CameraPositionPanel.h | 2 +- .../dock-spaces/viewport/EngineFramePanel.h | 12 +-- src/editor/dock-spaces/viewport/GizmoPanel.h | 6 +- .../dock-spaces/viewport/GizmoSettingsPanel.h | 4 +- .../viewport/ViewportHeaderPanel.cpp | 2 +- .../viewport/ViewportHeaderPanel.h | 4 +- .../dock-spaces/viewport/ViewportPanel.cpp | 8 +- .../dock-spaces/viewport/ViewportPanel.h | 14 +-- .../dock-spaces/world/WorldHeaderPanel.h | 2 +- src/editor/dock-spaces/world/WorldPanel.cpp | 2 +- src/editor/dock-spaces/world/WorldPanel.h | 8 +- src/editor/panel/FileImportModalPanel.cpp | 2 +- src/editor/panel/FileImportModalPanel.h | 8 +- src/editor/panel/NotificationsPanel.h | 4 +- src/editor/passes/GridPass.h | 6 +- src/editor/passes/SelectionIDPass.h | 8 +- src/editor/passes/SelectionOutlinePass.h | 4 +- src/editor/service/DockService.cpp | 4 +- src/editor/service/FileImporterService.h | 10 +-- src/editor/service/FilesService.h | 4 +- src/editor/service/MaterialImporterService.h | 2 +- src/editor/service/MeshImporterService.h | 2 +- src/editor/service/PickingService.h | 6 +- src/editor/service/SceneImporterService.h | 6 +- src/editor/service/SelectionService.h | 4 +- src/editor/service/TextureImporterService.h | 2 +- src/editor/service/ThemeService.h | 2 +- src/editor/service/VoxelImporterService.h | 2 +- src/engine/EngineContext.cpp | 3 +- src/engine/EngineContext.h | 18 ++-- src/engine/frame-builder/EngineFrameBuilder.h | 2 +- .../frame-builder/structures/BufferBuilder.h | 2 +- .../structures/CommandBufferRecorderBuilder.h | 4 +- .../structures/FramebufferBuilder.h | 2 +- .../frame-builder/structures/TextureBuilder.h | 2 +- src/engine/passes/CommandBufferRecorder.cpp | 6 +- src/engine/passes/CommandBufferRecorder.h | 10 ++- src/engine/passes/impl/HWRayTracingPass.h | 10 +-- src/engine/passes/impl/PostProcessingPass.h | 6 +- src/engine/passes/impl/SpatialFilterPass.h | 2 +- .../passes/impl/TemporalAccumulationPass.h | 2 +- src/engine/repository/WorldRepository.h | 4 +- src/engine/resource/FrameBufferAttachment.cpp | 4 - src/engine/resource/FrameBufferAttachment.h | 7 ++ src/engine/resource/RuntimeResource.h | 2 +- src/engine/service/CameraService.h | 6 +- src/engine/service/DescriptorSetService.h | 8 +- src/engine/service/FrameBufferService.cpp | 1 + src/engine/service/FrameBufferService.h | 2 +- src/engine/service/LightService.h | 4 +- src/engine/service/MaterialService.h | 2 +- src/engine/service/MeshService.h | 6 +- src/engine/service/RayTracingService.cpp | 3 - src/engine/service/RayTracingService.h | 16 ++-- src/engine/service/ShaderService.cpp | 23 +++-- src/engine/service/ShaderService.h | 14 +-- src/engine/service/StreamingService.h | 10 +-- src/engine/service/TextureService.h | 10 +-- src/engine/service/TransformService.h | 4 +- src/engine/service/VolumeService.h | 4 +- src/main.cpp | 7 +- 102 files changed, 320 insertions(+), 378 deletions(-) delete mode 100644 resources/shaders/tools/Icon.frag diff --git a/resources/shaders/rt/HWRayTracing.rgen b/resources/shaders/rt/HWRayTracing.rgen index c09ac1bd..69e273fc 100644 --- a/resources/shaders/rt/HWRayTracing.rgen +++ b/resources/shaders/rt/HWRayTracing.rgen @@ -1,4 +1,6 @@ #extension GL_EXT_ray_tracing: require +#define ITEM_TYPE_SPHERE 0 +#define ITEM_TYPE_PLANE 1 #include "../GlobalDataBuffer.glsl" #include "../rt/HWRayTracingPushConstant.glsl" diff --git a/resources/shaders/tools/Icon.frag b/resources/shaders/tools/Icon.frag deleted file mode 100644 index 4a281c2a..00000000 --- a/resources/shaders/tools/Icon.frag +++ /dev/null @@ -1,90 +0,0 @@ -#include "../GlobalDataBuffer.glsl" -#include "../CreateRay.glsl" - -#define LIGHT_SET 1 -#include "../LightBuffer.glsl" - -layout (location = 0) in vec2 texCoords; -layout (location = 0) out vec4 finalColor; - -float sdSphere(vec3 p, float s, in vec3 translation){ - return length(p - translation)-s; -} -float dot2(vec3 v) { - return dot(v, v); -} -float udQuad(vec3 p, vec3 a, vec3 b, vec3 c, vec3 d) -{ - vec3 ba = b - a; vec3 pa = p - a; - vec3 cb = c - b; vec3 pb = p - b; - vec3 dc = d - c; vec3 pc = p - c; - vec3 ad = a - d; vec3 pd = p - d; - vec3 nor = cross(ba, ad); - - return sqrt( - (sign(dot(cross(ba, nor), pa)) + - sign(dot(cross(cb, nor), pb)) + - sign(dot(cross(dc, nor), pc)) + - sign(dot(cross(ad, nor), pd))<3.0) - ? - min(min(min( - dot2(ba*clamp(dot(ba, pa)/dot2(ba), 0.0, 1.0)-pa), - dot2(cb*clamp(dot(cb, pb)/dot2(cb), 0.0, 1.0)-pb)), - dot2(dc*clamp(dot(dc, pc)/dot2(dc), 0.0, 1.0)-pc)), - dot2(ad*clamp(dot(ad, pd)/dot2(ad), 0.0, 1.0)-pd)) - : - dot(nor, pa)*dot(nor, pa)/dot2(nor)); -} - -bool rayMarch(vec3 ro, vec3 rd, in Light l) { - float t = 0.0; - for (int i = 0; i < 256; i++) { - vec3 p = ro + t * rd; - float d; - - switch (l.itemType){ - case ITEM_TYPE_SPHERE:{ - d = sdSphere(p, l.dataB.x, l.position); - break; - } - case ITEM_TYPE_PLANE:{ - vec3 reference = abs(l.dataA.y) > 0.999 ? vec3(1.0, 0.0, 0.0) : vec3(0.0, 1.0, 0.0); - vec3 right = normalize(cross(l.dataA, reference)); - vec3 up = normalize(cross(right, l.dataA)); - - // Use correct plane dimensions - vec3 halfRight = right * (l.dataB.z * 0.5); - vec3 halfUp = up * (l.dataB.x * 0.5); - - vec3 a = l.position - halfRight - halfUp; - vec3 b = l.position + halfRight - halfUp; - vec3 c = l.position + halfRight + halfUp; - vec3 dl = l.position - halfRight + halfUp; - d = udQuad(p, a, b, c, dl); - break; - } - default :{ - return false; - } - } - if (d < 0.001) return true; - if (t > 100.0) break; - t += d; - } - return false; -} - -void main(){ - if (globalData.lightsCount == 0){ - discard; - } - vec3 dir = createRay(texCoords, globalData.invProj, globalData.invView); - for (uint i = 0; i < globalData.lightsCount; i++){ - Light l = lightBuffer.items[i]; - if (rayMarch(globalData.cameraWorldPosition.xyz, dir, l)){ - finalColor = vec4(l.color.rgb * l.color.a, 1); - return; - } - } - discard; -} \ No newline at end of file diff --git a/src/ApplicationContext.cpp b/src/ApplicationContext.cpp index b14ca0d3..84de4494 100644 --- a/src/ApplicationContext.cpp +++ b/src/ApplicationContext.cpp @@ -11,14 +11,18 @@ namespace Metal { } void ApplicationContext::onInitialize() { - for (auto &instance : instances) { - instance->setDependencies(*this); + for (auto &instance: instances) { + if (instance.get() != this) { + instance->setDependencies(*this); + } } - for (auto &instance : instances) { - auto *init = dynamic_cast(instance.get()); - if (init) { - init->onInitialize(); + for (auto &instance: instances) { + if (instance.get() != this) { + auto *init = dynamic_cast(instance.get()); + if (init) { + init->onInitialize(); + } } } } @@ -30,6 +34,9 @@ namespace Metal { void ApplicationContext::dispose() { try { for (auto it = instances.rbegin(); it != instances.rend(); ++it) { + if (it->get() == this) { + continue; + } auto *disposable = dynamic_cast(it->get()); if (disposable) { disposable->dispose(); diff --git a/src/common/AbstractResourceService.h b/src/common/AbstractResourceService.h index a2e05ce3..870b12f5 100644 --- a/src/common/AbstractResourceService.h +++ b/src/common/AbstractResourceService.h @@ -5,13 +5,14 @@ #include #include "IService.h" +#include "../ApplicationContext.h" #include "../engine/resource/RuntimeResource.h" namespace Metal { class VulkanContext; template - class AbstractResourceService : public IService { + class AbstractResourceService : public IService, public IDisposable { static_assert(std::is_base_of_v, "T must be a subclass of RuntimeResource"); protected: @@ -23,6 +24,10 @@ namespace Metal { std::lock_guard lock(resourceMutex); auto *resource = new T(id, std::forward(args)...); resources[id] = resource; + ctx->injectDependencies(resource); + if (auto *initializable = dynamic_cast(resource)) { + initializable->onInitialize(); + } return resource; } @@ -52,7 +57,7 @@ namespace Metal { } } - void disposeAll() { + void dispose() override { std::lock_guard lock(resourceMutex); for (auto it = resources.begin(); it != resources.end();) { auto *r = it->second; diff --git a/src/common/IContextMember.cpp b/src/common/IContextMember.cpp index 8daeee72..28dae77e 100644 --- a/src/common/IContextMember.cpp +++ b/src/common/IContextMember.cpp @@ -5,7 +5,10 @@ namespace Metal { void IContextMember::setDependencies(ApplicationContext &ctx) { this->ctx = &ctx; for (auto &dep : getDependencies()) { - dep.ptr = ctx.getSingletonByName(dep.name); + void* singleton = ctx.getSingletonByName(dep.name); + if (dep.ptr != nullptr) { + *static_cast(dep.ptr) = singleton; + } } } } diff --git a/src/common/IContextMember.h b/src/common/IContextMember.h index 6a80f326..26b9c2eb 100644 --- a/src/common/IContextMember.h +++ b/src/common/IContextMember.h @@ -14,7 +14,7 @@ namespace Metal { class IContextMember { public: ApplicationContext *ctx = nullptr; - public: + virtual ~IContextMember() = default; /** diff --git a/src/core/DirectoryService.cpp b/src/core/DirectoryService.cpp index 785e1d45..4a3bfd18 100644 --- a/src/core/DirectoryService.cpp +++ b/src/core/DirectoryService.cpp @@ -11,6 +11,15 @@ #include "../engine/repository/WorldRepository.h" namespace Metal { + void DirectoryService::onInitialize() { + NFD_Init(); + updateRootPath(false); + } + + void DirectoryService::dispose() { + NFD_Quit(); + } + void DirectoryService::updateRootPath(bool forceSelection) { std::string cachedPath; std::string cachePathFile = std::filesystem::current_path().string() + CACHED_PATH; diff --git a/src/core/DirectoryService.h b/src/core/DirectoryService.h index a02b1339..1b7c46a0 100644 --- a/src/core/DirectoryService.h +++ b/src/core/DirectoryService.h @@ -1,5 +1,7 @@ #ifndef METAL_ENGINE_DIRECTORYSERVICE_H #define METAL_ENGINE_DIRECTORYSERVICE_H +#include "../common/IDisposable.h" +#include "../common/IInit.h" #include "../common/IService.h" namespace Metal { @@ -8,7 +10,7 @@ namespace Metal { struct WorldRepository; class NotificationService; - struct DirectoryService final : IService { + struct DirectoryService final : IService, IInit, IDisposable{ EditorRepository *editorRepository = nullptr; EngineRepository *engineRepository = nullptr; WorldRepository *worldRepository = nullptr; @@ -18,13 +20,17 @@ namespace Metal { std::vector getDependencies() override { return { - {"EditorRepository", editorRepository}, - {"EngineRepository", engineRepository}, - {"WorldRepository", worldRepository}, - {"NotificationService", notificationService} + {"EditorRepository", &editorRepository}, + {"EngineRepository", &engineRepository}, + {"WorldRepository", &worldRepository}, + {"NotificationService", ¬ificationService} }; } + void onInitialize() override; + + void dispose() override; + void updateRootPath(bool forceSelection); void save(); diff --git a/src/core/FrameService.cpp b/src/core/FrameService.cpp index 48b35d6d..d7a96f9e 100644 --- a/src/core/FrameService.cpp +++ b/src/core/FrameService.cpp @@ -15,10 +15,6 @@ namespace Metal { return vulkanContext->imguiVulkanWindow.FrameIndex; } - void FrameService::dispose() { - NFD_Quit(); - } - bool FrameService::isValidContext() const { return glfwContext->isValidContext(); } @@ -27,9 +23,7 @@ namespace Metal { this->panel = panel; } - void FrameService::onInitialize() { - NFD_Init(); - + void FrameService::start() const { GLFWwindow *window = glfwContext->getWindow(); while (!glfwWindowShouldClose(window)) { if (glfwContext->beginFrame()) { diff --git a/src/core/FrameService.h b/src/core/FrameService.h index d00287f1..2ed29d06 100644 --- a/src/core/FrameService.h +++ b/src/core/FrameService.h @@ -11,7 +11,7 @@ namespace Metal { class GuiContext; class AbstractPanel; - class FrameService final : public IService, public IInit, public IDisposable { + class FrameService final : public IService { GLFWContext *glfwContext = nullptr; VulkanContext *vulkanContext = nullptr; EngineContext *engineContext = nullptr; @@ -21,22 +21,20 @@ namespace Metal { public: std::vector getDependencies() override { return { - {"GLFWContext", glfwContext}, - {"VulkanContext", vulkanContext}, - {"GuiContext", guiContext}, - {"EngineContext", engineContext} + {"GLFWContext", &glfwContext}, + {"VulkanContext", &vulkanContext}, + {"GuiContext", &guiContext}, + {"EngineContext", &engineContext} }; } void setPanel(AbstractPanel *panel); - void onInitialize() override; + void start() const; [[nodiscard]] bool isValidContext() const; [[nodiscard]] unsigned int getFrameIndex() const; - - void dispose() override; }; } // Metal diff --git a/src/core/glfw/GLFWContext.cpp b/src/core/glfw/GLFWContext.cpp index ae539bb5..7a3a6e26 100644 --- a/src/core/glfw/GLFWContext.cpp +++ b/src/core/glfw/GLFWContext.cpp @@ -42,7 +42,7 @@ namespace Metal { return true; } - void GLFWContext::dispose() { + void GLFWContext::disposeManually() { glfwDestroyWindow(window); glfwTerminate(); } diff --git a/src/core/glfw/GLFWContext.h b/src/core/glfw/GLFWContext.h index 0f4b06d4..33ad1dc3 100644 --- a/src/core/glfw/GLFWContext.h +++ b/src/core/glfw/GLFWContext.h @@ -18,7 +18,7 @@ namespace Metal { class ApplicationContext; class VulkanContext; - class GLFWContext final : public IContextMember, public IInit, public IDisposable { + class GLFWContext final : public IContextMember, public IInit { VulkanContext *vulkanContext = nullptr; GLFWwindow *window = nullptr; bool validContext = true; @@ -27,7 +27,7 @@ namespace Metal { public: std::vector getDependencies() override { - return {{"VulkanContext", vulkanContext}}; + return {{"VulkanContext", &vulkanContext}}; } void setSwapChainRebuild(bool val); @@ -44,7 +44,7 @@ namespace Metal { bool beginFrame(); - void dispose() override; + void disposeManually(); [[nodiscard]] ImGui_ImplVulkanH_Window &getGUIWindow() const; }; diff --git a/src/core/gui/GuiContext.cpp b/src/core/gui/GuiContext.cpp index 15fb1226..97c06c7c 100644 --- a/src/core/gui/GuiContext.cpp +++ b/src/core/gui/GuiContext.cpp @@ -141,7 +141,7 @@ namespace Metal { delete fontConfig; } - void GuiContext::dispose() { + void GuiContext::disposeManually() { const VkResult err = vkDeviceWaitIdle(vulkanContext->device.device); VulkanUtils::CheckVKResult(err); ImGui_ImplVulkan_Shutdown(); diff --git a/src/core/gui/GuiContext.h b/src/core/gui/GuiContext.h index 2ee14541..7a27eb6a 100644 --- a/src/core/gui/GuiContext.h +++ b/src/core/gui/GuiContext.h @@ -15,7 +15,7 @@ namespace Metal { class VulkanContext; class DescriptorSetService; - class GuiContext final : public IService, public IDisposable, public IInit { + class GuiContext final : public IService, public IInit { VulkanContext *vulkanContext = nullptr; GLFWContext *glfwContext = nullptr; DescriptorSetService *descriptorSetService = nullptr; @@ -32,9 +32,9 @@ namespace Metal { std::vector getDependencies() override { return { - {"VulkanContext", vulkanContext}, - {"GLFWContext", glfwContext}, - {"DescriptorSetService", descriptorSetService} + {"VulkanContext", &vulkanContext}, + {"GLFWContext", &glfwContext}, + {"DescriptorSetService", &descriptorSetService} }; } @@ -42,7 +42,7 @@ namespace Metal { return largeIconsFont; } - void dispose() override; + void disposeManually(); void onInitialize() override; diff --git a/src/core/vulkan/VulkanContext.cpp b/src/core/vulkan/VulkanContext.cpp index 35f7930d..1fb88ca9 100644 --- a/src/core/vulkan/VulkanContext.cpp +++ b/src/core/vulkan/VulkanContext.cpp @@ -9,8 +9,6 @@ #include "../../engine/service/MeshService.h" #include "../../engine/service/TextureService.h" #include "../../engine/service/FrameBufferService.h" -#include "../../engine/service/PipelineService.h" -#include "../../engine/service/RayTracingService.h" namespace Metal { @@ -292,12 +290,7 @@ namespace Metal { // ------- CORE INITIALIZATION } - void VulkanContext::dispose() { - pipelineService->disposeAll(); - textureService->disposeAll(); - meshService->disposeAll(); - framebufferService->disposeAll(); - rayTracingService->dispose(); + void VulkanContext::disposeManually() { vkDestroySampler(device.device, vkImageSampler, nullptr); vkDestroySampler(device.device, vkTextureSampler, nullptr); @@ -308,12 +301,11 @@ namespace Metal { nullptr); vkDestroyDevice(device.device, nullptr); - vkDestroySurfaceKHR(instance.instance, surface, nullptr); vkb::destroy_instance(instance); } void VulkanContext::createDescriptorPool() const { - const std::array sizes{ + const std::array sizes{ VkDescriptorPoolSize{VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 100}, // 1 for imgui VkDescriptorPoolSize{VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 100}, VkDescriptorPoolSize{VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 100}, diff --git a/src/core/vulkan/VulkanContext.h b/src/core/vulkan/VulkanContext.h index deed4b7a..cee39ddd 100644 --- a/src/core/vulkan/VulkanContext.h +++ b/src/core/vulkan/VulkanContext.h @@ -21,7 +21,7 @@ namespace Metal { class PipelineService; class RayTracingService; - class VulkanContext final : public IService, public IDisposable, public IInit { + class VulkanContext final : public IService, public IInit { GLFWContext *glfwContext = nullptr; EngineRepository *engineRepository = nullptr; MeshService *meshService = nullptr; @@ -70,13 +70,13 @@ namespace Metal { std::vector getDependencies() override { return { - {"GLFWContext", glfwContext}, - {"EngineRepository", engineRepository}, - {"MeshService", meshService}, - {"TextureService", textureService}, - {"FrameBufferService", framebufferService}, - {"PipelineService", pipelineService}, - {"RayTracingService", rayTracingService} + {"GLFWContext", &glfwContext}, + {"EngineRepository", &engineRepository}, + {"MeshService", &meshService}, + {"TextureService", &textureService}, + {"FrameBufferService", &framebufferService}, + {"PipelineService", &pipelineService}, + {"RayTracingService", &rayTracingService} }; } @@ -108,7 +108,7 @@ namespace Metal { PFN_vkGetRayTracingShaderGroupHandlesKHR vkGetRayTracingShaderGroupHandlesKHR = nullptr; PFN_vkCmdTraceRaysKHR vkCmdTraceRaysKHR = nullptr; - void dispose() override; + void disposeManually(); void onInitialize() override; diff --git a/src/editor/EditorPanel.cpp b/src/editor/EditorPanel.cpp index 89efab59..ba38367e 100644 --- a/src/editor/EditorPanel.cpp +++ b/src/editor/EditorPanel.cpp @@ -106,9 +106,9 @@ namespace Metal { } void EditorPanel::onInitialize() { - appendChild(headerPanel = new EditorHeaderPanel()); - appendChild(footerPanel = new EditorFooterPanel()); - appendChild(notificationsPanel = new NotificationsPanel()); - appendChild(fileImportModalPanel = new FileImportModalPanel()); + initializePanel(headerPanel = new EditorHeaderPanel(), false); + initializePanel(footerPanel = new EditorFooterPanel(), false); + initializePanel(notificationsPanel = new NotificationsPanel(), false); + initializePanel(fileImportModalPanel = new FileImportModalPanel(), false); } } diff --git a/src/editor/EditorPanel.h b/src/editor/EditorPanel.h index 80d47127..d007ff7a 100644 --- a/src/editor/EditorPanel.h +++ b/src/editor/EditorPanel.h @@ -36,8 +36,8 @@ namespace Metal { public: std::vector getDependencies() override { return { - {"DockService", dockService}, - {"ThemeService", themeService} + {"DockService", &dockService}, + {"ThemeService", &themeService} }; } diff --git a/src/editor/abstract/AbstractPanel.cpp b/src/editor/abstract/AbstractPanel.cpp index 441d5537..d3e1f1a6 100644 --- a/src/editor/abstract/AbstractPanel.cpp +++ b/src/editor/abstract/AbstractPanel.cpp @@ -3,10 +3,13 @@ #include "../../ApplicationContext.h" namespace Metal { - void AbstractPanel::appendChild(AbstractPanel *panel) { + void AbstractPanel::initializePanel(AbstractPanel *panel, bool addToChildList) { + panel->ctx = ctx; ctx->injectDependencies(panel); panel->onInitialize(); - children.push_back(panel); + if (addToChildList) { + children.push_back(panel); + } } void AbstractPanel::onSyncChildren() const { diff --git a/src/editor/abstract/AbstractPanel.h b/src/editor/abstract/AbstractPanel.h index b86431df..651f9d6b 100644 --- a/src/editor/abstract/AbstractPanel.h +++ b/src/editor/abstract/AbstractPanel.h @@ -22,7 +22,7 @@ namespace Metal { std::vector &getChildren(); - void appendChild(AbstractPanel *panel); + void initializePanel(AbstractPanel *panel, bool addToChildList = true); void removeAllChildren(); diff --git a/src/editor/abstract/form/AbstractFormFieldPanel.h b/src/editor/abstract/form/AbstractFormFieldPanel.h index bfdb7f1f..f3381221 100644 --- a/src/editor/abstract/form/AbstractFormFieldPanel.h +++ b/src/editor/abstract/form/AbstractFormFieldPanel.h @@ -17,7 +17,7 @@ namespace Metal { std::vector getDependencies() override { return { - {"ThemeService", themeService} + {"ThemeService", &themeService} }; } [[nodiscard]] virtual bool isVisible() const = 0; diff --git a/src/editor/abstract/form/FormPanel.cpp b/src/editor/abstract/form/FormPanel.cpp index 5c683c15..3600d088 100644 --- a/src/editor/abstract/form/FormPanel.cpp +++ b/src/editor/abstract/form/FormPanel.cpp @@ -20,14 +20,14 @@ namespace Metal { std::unordered_map groups{}; const auto rootPanel = new ChildPanel(); rootPanel->setFilter(&searchFilter); - appendChild(rootPanel); + initializePanel(rootPanel); rootPanel->setTitle(std::string(inspection->getIcon()) + " " + inspection->getTitle()); for (const auto &field: inspection->getFields()) { if (!groups.contains(field->group)) { const auto panel = new AccordionPanel(); panel->setFilter(&searchFilter); groups[field->group] = panel; - rootPanel->appendChild(panel); + rootPanel->initializePanel(panel); } AccordionPanel *group = groups[field->group]; group->setTitle(field->group); @@ -71,7 +71,7 @@ namespace Metal { } if (fieldPanel) { fieldPanel->setFilter(&searchFilter); - group->appendChild(fieldPanel); + group->initializePanel(fieldPanel); } } } diff --git a/src/editor/abstract/form/types/ResourceField.cpp b/src/editor/abstract/form/types/ResourceField.cpp index ba761c59..884eceb9 100644 --- a/src/editor/abstract/form/types/ResourceField.cpp +++ b/src/editor/abstract/form/types/ResourceField.cpp @@ -19,7 +19,7 @@ namespace Metal { } void ResourceField::onInitialize() { - appendChild(new ResourceFilesPanel([this](FSEntry *file) { + initializePanel(new ResourceFilesPanel([this](FSEntry *file) { if (file == nullptr) { open = false; return; diff --git a/src/editor/abstract/form/types/ResourceField.h b/src/editor/abstract/form/types/ResourceField.h index 92b8a23b..5c970922 100644 --- a/src/editor/abstract/form/types/ResourceField.h +++ b/src/editor/abstract/form/types/ResourceField.h @@ -19,7 +19,7 @@ namespace Metal { public: std::vector getDependencies() override { - return {{"FilesService", filesService}}; + return {{"FilesService", &filesService}}; } void onInitialize() override; diff --git a/src/editor/dock-spaces/docks/DockSpacePanel.cpp b/src/editor/dock-spaces/docks/DockSpacePanel.cpp index c77db728..60f9c479 100644 --- a/src/editor/dock-spaces/docks/DockSpacePanel.cpp +++ b/src/editor/dock-spaces/docks/DockSpacePanel.cpp @@ -36,7 +36,7 @@ namespace Metal { newView->size = &size; newView->dock = selectedSpace; newView->position = &position; - appendChild(newView); + initializePanel(newView); views.emplace(selectedSpace->index, newView); view = newView; } else { diff --git a/src/editor/dock-spaces/docks/DockSpacePanel.h b/src/editor/dock-spaces/docks/DockSpacePanel.h index bc89e743..911e94bc 100644 --- a/src/editor/dock-spaces/docks/DockSpacePanel.h +++ b/src/editor/dock-spaces/docks/DockSpacePanel.h @@ -38,8 +38,8 @@ namespace Metal { public: std::vector getDependencies() override { return { - {"EditorRepository", editorRepository}, - {"ThemeService", themeService} + {"EditorRepository", &editorRepository}, + {"ThemeService", &themeService} }; } diff --git a/src/editor/dock-spaces/files/FilePreviewPanel.h b/src/editor/dock-spaces/files/FilePreviewPanel.h index b539a00a..7486746d 100644 --- a/src/editor/dock-spaces/files/FilePreviewPanel.h +++ b/src/editor/dock-spaces/files/FilePreviewPanel.h @@ -17,8 +17,8 @@ namespace Metal { public: std::vector getDependencies() override { return { - {"TextureService", textureService}, - {"GuiContext", guiContext} + {"TextureService", &textureService}, + {"GuiContext", &guiContext} }; } diff --git a/src/editor/dock-spaces/files/FilesHeaderPanel.h b/src/editor/dock-spaces/files/FilesHeaderPanel.h index 479e7235..2dd46591 100644 --- a/src/editor/dock-spaces/files/FilesHeaderPanel.h +++ b/src/editor/dock-spaces/files/FilesHeaderPanel.h @@ -16,7 +16,7 @@ namespace Metal { public: std::vector getDependencies() override { - return {{"FilesService", filesService}}; + return {{"FilesService", &filesService}}; } explicit FilesHeaderPanel(FilesContext &files_context, const std::string &actionLabel, diff --git a/src/editor/dock-spaces/files/FilesListPanel.h b/src/editor/dock-spaces/files/FilesListPanel.h index 9ebd6e44..b87f2121 100644 --- a/src/editor/dock-spaces/files/FilesListPanel.h +++ b/src/editor/dock-spaces/files/FilesListPanel.h @@ -50,7 +50,7 @@ namespace Metal { public: std::vector getDependencies() override { return { - {"FilesService", filesService} + {"FilesService", &filesService} }; } diff --git a/src/editor/dock-spaces/files/FilesPanel.cpp b/src/editor/dock-spaces/files/FilesPanel.cpp index 91316c83..2823793a 100644 --- a/src/editor/dock-spaces/files/FilesPanel.cpp +++ b/src/editor/dock-spaces/files/FilesPanel.cpp @@ -50,16 +50,16 @@ namespace Metal { void FilesPanel::onInitialize() { filesContext.setCurrentDirectory(filesService->getRoot()); - appendChild(filesHeader = new FilesHeaderPanel(filesContext, getActionLabel(), onAction())); + initializePanel(filesHeader = new FilesHeaderPanel(filesContext, getActionLabel(), onAction())); filesListPanel = new FilesListPanel( filesContext, [ this](FSEntry *entry) { openResource(entry); }, getTypeFilter()); - appendChild(filesListPanel); + initializePanel(filesListPanel); previewPanel = new FilePreviewPanel(filesContext); - appendChild(previewPanel); + initializePanel(previewPanel); shortcuts = { ShortcutDTO("Cut", ImGuiMod_Ctrl | ImGuiKey_X, [this]() { diff --git a/src/editor/dock-spaces/files/FilesPanel.h b/src/editor/dock-spaces/files/FilesPanel.h index 2c90c3a1..cec10119 100644 --- a/src/editor/dock-spaces/files/FilesPanel.h +++ b/src/editor/dock-spaces/files/FilesPanel.h @@ -39,13 +39,13 @@ namespace Metal { public: std::vector getDependencies() override { return { - {"FileImporterService", fileImporterService}, - {"EditorRepository", editorRepository}, - {"SceneImporterService", sceneImporterService}, - {"FilesService", filesService}, - {"NotificationService", notificationService}, - {"WorldRepository", worldRepository}, - {"VoxelService", voxelService} + {"FileImporterService", &fileImporterService}, + {"EditorRepository", &editorRepository}, + {"SceneImporterService", &sceneImporterService}, + {"FilesService", &filesService}, + {"NotificationService", ¬ificationService}, + {"WorldRepository", &worldRepository}, + {"VoxelService", &voxelService} }; } diff --git a/src/editor/dock-spaces/footer/EditorFooterPanel.cpp b/src/editor/dock-spaces/footer/EditorFooterPanel.cpp index d8336424..280a194c 100644 --- a/src/editor/dock-spaces/footer/EditorFooterPanel.cpp +++ b/src/editor/dock-spaces/footer/EditorFooterPanel.cpp @@ -20,14 +20,15 @@ namespace Metal { void EditorFooterPanel::renderShortcuts() { auto &shortcuts = editorRepository->focusedShortcuts; if (shortcuts.empty()) return; - + ImGui::SetCursorPosY(ImGui::GetCursorPosY() + 5); // Some padding + ImGui::Text(editorRepository->focusedWindowName.c_str()); ImGui::SameLine(); std::string label; for (size_t i = 0; i < std::min(shortcuts.size(), size_t(3)); ++i) { if (i > 0) label += " | "; - label += UIUtil::GetKeyChordName(shortcuts[i].keyChord); + label += UIUtil::GetKeyChordName(shortcuts[i].keyChord) + " " + shortcuts[i].name; } if (ImGui::Button(label.c_str())) { diff --git a/src/editor/dock-spaces/footer/EditorFooterPanel.h b/src/editor/dock-spaces/footer/EditorFooterPanel.h index 372c6119..4dee9bb0 100644 --- a/src/editor/dock-spaces/footer/EditorFooterPanel.h +++ b/src/editor/dock-spaces/footer/EditorFooterPanel.h @@ -15,7 +15,7 @@ namespace Metal { public: std::vector getDependencies() override { return { - {"EditorRepository", editorRepository} + {"EditorRepository", &editorRepository} }; } diff --git a/src/editor/dock-spaces/header/AsyncTaskPanel.h b/src/editor/dock-spaces/header/AsyncTaskPanel.h index 640dee30..d834c713 100644 --- a/src/editor/dock-spaces/header/AsyncTaskPanel.h +++ b/src/editor/dock-spaces/header/AsyncTaskPanel.h @@ -12,7 +12,7 @@ namespace Metal { public: std::vector getDependencies() override { return { - {"AsyncTaskService", asyncTaskService} + {"AsyncTaskService", &asyncTaskService} }; } diff --git a/src/editor/dock-spaces/header/EditorHeaderPanel.cpp b/src/editor/dock-spaces/header/EditorHeaderPanel.cpp index 1bca0433..6f7be23b 100644 --- a/src/editor/dock-spaces/header/EditorHeaderPanel.cpp +++ b/src/editor/dock-spaces/header/EditorHeaderPanel.cpp @@ -16,25 +16,27 @@ namespace Metal { // Window dragging logic if (ImGui::IsWindowHovered() && ImGui::IsMouseDragging(ImGuiMouseButton_Left)) { ImVec2 delta = ImGui::GetIO().MouseDelta; - GLFWwindow* window = glfwContext->getWindow(); + GLFWwindow *window = glfwContext->getWindow(); int x, y; glfwGetWindowPos(window, &x, &y); - glfwSetWindowPos(window, x + (int)delta.x, y + (int)delta.y); + glfwSetWindowPos(window, x + (int) delta.x, y + (int) delta.y); } } void EditorHeaderPanel::renderWindowControls() { ImGui::SameLine(ImGui::GetWindowWidth() - (UIUtil::ONLY_ICON_BUTTON_SIZE * 3 + 10)); - - GLFWwindow* window = glfwContext->getWindow(); - if (UIUtil::ButtonSimple(Icons::minimize, UIUtil::ONLY_ICON_BUTTON_SIZE, UIUtil::ONLY_ICON_BUTTON_SIZE)) { + GLFWwindow *window = glfwContext->getWindow(); + + if (UIUtil::ButtonSimple((Icons::minimize + id + "min"), UIUtil::ONLY_ICON_BUTTON_SIZE, + UIUtil::ONLY_ICON_BUTTON_SIZE)) { glfwIconifyWindow(window); } ImGui::SameLine(); bool isMaximized = glfwGetWindowAttrib(window, GLFW_MAXIMIZED); - if (UIUtil::ButtonSimple(isMaximized ? Icons::filter_none : Icons::crop_square, UIUtil::ONLY_ICON_BUTTON_SIZE, UIUtil::ONLY_ICON_BUTTON_SIZE)) { + if (UIUtil::ButtonSimple((isMaximized ? Icons::filter_none : Icons::crop_square) + id + "max", + UIUtil::ONLY_ICON_BUTTON_SIZE, UIUtil::ONLY_ICON_BUTTON_SIZE)) { if (isMaximized) { glfwRestoreWindow(window); } else { @@ -43,7 +45,8 @@ namespace Metal { } ImGui::SameLine(); - if (UIUtil::ButtonSimple(Icons::close, UIUtil::ONLY_ICON_BUTTON_SIZE, UIUtil::ONLY_ICON_BUTTON_SIZE)) { + if (UIUtil::ButtonSimple(Icons::close + id + "close", UIUtil::ONLY_ICON_BUTTON_SIZE, + UIUtil::ONLY_ICON_BUTTON_SIZE)) { glfwSetWindowShouldClose(window, GLFW_TRUE); } } @@ -89,6 +92,6 @@ namespace Metal { } void EditorHeaderPanel::onInitialize() { - appendChild(asyncTask = new AsyncTaskPanel()); + initializePanel(asyncTask = new AsyncTaskPanel()); } } diff --git a/src/editor/dock-spaces/header/EditorHeaderPanel.h b/src/editor/dock-spaces/header/EditorHeaderPanel.h index 412ae9a6..230591f9 100644 --- a/src/editor/dock-spaces/header/EditorHeaderPanel.h +++ b/src/editor/dock-spaces/header/EditorHeaderPanel.h @@ -22,9 +22,9 @@ namespace Metal { public: std::vector getDependencies() override { return { - {"GLFWContext", glfwContext}, - {"EngineContext", engineContext}, - {"DirectoryService", directoryService} + {"GLFWContext", &glfwContext}, + {"EngineContext", &engineContext}, + {"DirectoryService", &directoryService} }; } diff --git a/src/editor/dock-spaces/inspector/InspectorPanel.cpp b/src/editor/dock-spaces/inspector/InspectorPanel.cpp index adef54bd..c6ed3c38 100644 --- a/src/editor/dock-spaces/inspector/InspectorPanel.cpp +++ b/src/editor/dock-spaces/inspector/InspectorPanel.cpp @@ -12,7 +12,7 @@ namespace Metal { void InspectorPanel::onInitialize() { formPanel = new FormPanel(); - appendChild(formPanel); + initializePanel(formPanel); } void InspectorPanel::onSync() { diff --git a/src/editor/dock-spaces/inspector/InspectorPanel.h b/src/editor/dock-spaces/inspector/InspectorPanel.h index cf8a1bf6..cfb45e4b 100644 --- a/src/editor/dock-spaces/inspector/InspectorPanel.h +++ b/src/editor/dock-spaces/inspector/InspectorPanel.h @@ -23,8 +23,8 @@ namespace Metal { public: std::vector getDependencies() override { return { - {"EditorRepository", editorRepository}, - {"WorldRepository", worldRepository} + {"EditorRepository", &editorRepository}, + {"WorldRepository", &worldRepository} }; } diff --git a/src/editor/dock-spaces/metrics/MetricsPanel.h b/src/editor/dock-spaces/metrics/MetricsPanel.h index e81e1e6c..5a945ebb 100644 --- a/src/editor/dock-spaces/metrics/MetricsPanel.h +++ b/src/editor/dock-spaces/metrics/MetricsPanel.h @@ -23,12 +23,12 @@ namespace Metal { public: std::vector getDependencies() override { return { - {"MeshService", meshService}, - {"VoxelService", voxelService}, - {"FrameBufferService", framebufferService}, - {"TextureService", textureService}, - {"PipelineService", pipelineService}, - {"BufferService", bufferService} + {"MeshService", &meshService}, + {"VoxelService", &voxelService}, + {"FrameBufferService", &framebufferService}, + {"TextureService", &textureService}, + {"PipelineService", &pipelineService}, + {"BufferService", &bufferService} }; } diff --git a/src/editor/dock-spaces/repositories/RepositoriesPanel.cpp b/src/editor/dock-spaces/repositories/RepositoriesPanel.cpp index 4c6bc533..74279177 100644 --- a/src/editor/dock-spaces/repositories/RepositoriesPanel.cpp +++ b/src/editor/dock-spaces/repositories/RepositoriesPanel.cpp @@ -10,7 +10,7 @@ namespace Metal { void RepositoriesPanel::onInitialize() { formPanel = new FormPanel(); - appendChild(formPanel); + initializePanel(formPanel); repositories.push_back(editorRepository); repositories.push_back(engineRepository); diff --git a/src/editor/dock-spaces/repositories/RepositoriesPanel.h b/src/editor/dock-spaces/repositories/RepositoriesPanel.h index 6121111c..7d446362 100644 --- a/src/editor/dock-spaces/repositories/RepositoriesPanel.h +++ b/src/editor/dock-spaces/repositories/RepositoriesPanel.h @@ -21,13 +21,14 @@ namespace Metal { public: std::vector getDependencies() override { return { - {"EditorRepository", editorRepository}, - {"EngineRepository", engineRepository}, - {"WorldRepository", worldRepository} + {"EditorRepository", &editorRepository}, + {"EngineRepository", &engineRepository}, + {"WorldRepository", &worldRepository} }; } void onInitialize() override; + void onSync() override; }; } diff --git a/src/editor/dock-spaces/viewport/CameraPositionPanel.h b/src/editor/dock-spaces/viewport/CameraPositionPanel.h index 1dd71422..4a2b4367 100644 --- a/src/editor/dock-spaces/viewport/CameraPositionPanel.h +++ b/src/editor/dock-spaces/viewport/CameraPositionPanel.h @@ -19,7 +19,7 @@ namespace Metal { public: std::vector getDependencies() override { return { - {"WorldRepository", worldRepository} + {"WorldRepository", &worldRepository} }; } diff --git a/src/editor/dock-spaces/viewport/EngineFramePanel.h b/src/editor/dock-spaces/viewport/EngineFramePanel.h index bee6aba7..0b7f9cba 100644 --- a/src/editor/dock-spaces/viewport/EngineFramePanel.h +++ b/src/editor/dock-spaces/viewport/EngineFramePanel.h @@ -25,12 +25,12 @@ namespace Metal { public: std::vector getDependencies() override { return { - {"VulkanContext", vulkanContext}, - {"EngineRepository", engineRepository}, - {"EngineContext", engineContext}, - {"DescriptorSetService", descriptorSetService}, - {"PickingService", pickingService}, - {"SelectionService", selectionService} + {"VulkanContext", &vulkanContext}, + {"EngineRepository", &engineRepository}, + {"EngineContext", &engineContext}, + {"DescriptorSetService", &descriptorSetService}, + {"PickingService", &pickingService}, + {"SelectionService", &selectionService} }; } diff --git a/src/editor/dock-spaces/viewport/GizmoPanel.h b/src/editor/dock-spaces/viewport/GizmoPanel.h index b68c74fc..12da02fc 100644 --- a/src/editor/dock-spaces/viewport/GizmoPanel.h +++ b/src/editor/dock-spaces/viewport/GizmoPanel.h @@ -42,9 +42,9 @@ namespace Metal { public: std::vector getDependencies() override { return { - {"EditorRepository", editorRepository}, - {"WorldRepository", worldRepository}, - {"SelectionService", selectionService} + {"EditorRepository", &editorRepository}, + {"WorldRepository", &worldRepository}, + {"SelectionService", &selectionService} }; } diff --git a/src/editor/dock-spaces/viewport/GizmoSettingsPanel.h b/src/editor/dock-spaces/viewport/GizmoSettingsPanel.h index 998ac529..7f5b13d0 100644 --- a/src/editor/dock-spaces/viewport/GizmoSettingsPanel.h +++ b/src/editor/dock-spaces/viewport/GizmoSettingsPanel.h @@ -27,8 +27,8 @@ namespace Metal { public: std::vector getDependencies() override { return { - {"EditorRepository", editorRepository}, - {"WorldRepository", worldRepository} + {"EditorRepository", &editorRepository}, + {"WorldRepository", &worldRepository} }; } diff --git a/src/editor/dock-spaces/viewport/ViewportHeaderPanel.cpp b/src/editor/dock-spaces/viewport/ViewportHeaderPanel.cpp index c6a7dd27..3d4cd54f 100644 --- a/src/editor/dock-spaces/viewport/ViewportHeaderPanel.cpp +++ b/src/editor/dock-spaces/viewport/ViewportHeaderPanel.cpp @@ -7,7 +7,7 @@ namespace Metal { void ViewportHeaderPanel::onInitialize() { - appendChild(gizmo = new GizmoSettingsPanel()); + initializePanel(gizmo = new GizmoSettingsPanel()); } void ViewportHeaderPanel::onSync() { diff --git a/src/editor/dock-spaces/viewport/ViewportHeaderPanel.h b/src/editor/dock-spaces/viewport/ViewportHeaderPanel.h index a5712887..eb5cf60b 100644 --- a/src/editor/dock-spaces/viewport/ViewportHeaderPanel.h +++ b/src/editor/dock-spaces/viewport/ViewportHeaderPanel.h @@ -20,8 +20,8 @@ namespace Metal { public: std::vector getDependencies() override { return { - {"EditorRepository", editorRepository}, - {"WorldRepository", worldRepository} + {"EditorRepository", &editorRepository}, + {"WorldRepository", &worldRepository} }; } diff --git a/src/editor/dock-spaces/viewport/ViewportPanel.cpp b/src/editor/dock-spaces/viewport/ViewportPanel.cpp index 8114ee67..05f00fa8 100644 --- a/src/editor/dock-spaces/viewport/ViewportPanel.cpp +++ b/src/editor/dock-spaces/viewport/ViewportPanel.cpp @@ -19,10 +19,10 @@ namespace Metal { void ViewportPanel::onInitialize() { - appendChild(headerPanel = new ViewportHeaderPanel()); - appendChild(engineFramePanel = new EngineFramePanel()); - appendChild(gizmoPanel = new GizmoPanel(position, size)); - appendChild(cameraPanel = new CameraPositionPanel()); + initializePanel(headerPanel = new ViewportHeaderPanel()); + initializePanel(engineFramePanel = new EngineFramePanel()); + initializePanel(gizmoPanel = new GizmoPanel(position, size)); + initializePanel(cameraPanel = new CameraPositionPanel()); shortcuts = { ShortcutDTO("Change shading mode", ImGuiKey_Q, [this]() { diff --git a/src/editor/dock-spaces/viewport/ViewportPanel.h b/src/editor/dock-spaces/viewport/ViewportPanel.h index 343cded0..5703d6fa 100644 --- a/src/editor/dock-spaces/viewport/ViewportPanel.h +++ b/src/editor/dock-spaces/viewport/ViewportPanel.h @@ -30,13 +30,13 @@ namespace Metal { public: std::vector getDependencies() override { return { - {"CameraService", cameraService}, - {"SelectionService", selectionService}, - {"EditorRepository", editorRepository}, - {"WorldRepository", worldRepository}, - {"RuntimeRepository", runtimeRepository}, - {"EngineContext", engineContext}, - {"DirectoryService", directoryService} + {"CameraService", &cameraService}, + {"SelectionService", &selectionService}, + {"EditorRepository", &editorRepository}, + {"WorldRepository", &worldRepository}, + {"RuntimeRepository", &runtimeRepository}, + {"EngineContext", &engineContext}, + {"DirectoryService", &directoryService} }; } diff --git a/src/editor/dock-spaces/world/WorldHeaderPanel.h b/src/editor/dock-spaces/world/WorldHeaderPanel.h index c89b5e4d..5a7134a6 100644 --- a/src/editor/dock-spaces/world/WorldHeaderPanel.h +++ b/src/editor/dock-spaces/world/WorldHeaderPanel.h @@ -11,7 +11,7 @@ namespace Metal { public: std::vector getDependencies() override { return { - {"WorldRepository", worldRepository} + {"WorldRepository", &worldRepository} }; } diff --git a/src/editor/dock-spaces/world/WorldPanel.cpp b/src/editor/dock-spaces/world/WorldPanel.cpp index ab177ffd..1b555094 100644 --- a/src/editor/dock-spaces/world/WorldPanel.cpp +++ b/src/editor/dock-spaces/world/WorldPanel.cpp @@ -12,7 +12,7 @@ namespace Metal { void WorldPanel::onInitialize() { - appendChild(headerPanel = new WorldHeaderPanel()); + initializePanel(headerPanel = new WorldHeaderPanel()); shortcuts = { ShortcutDTO("Delete", ImGuiKey_Delete, [this]() { diff --git a/src/editor/dock-spaces/world/WorldPanel.h b/src/editor/dock-spaces/world/WorldPanel.h index dabf837e..37a33934 100644 --- a/src/editor/dock-spaces/world/WorldPanel.h +++ b/src/editor/dock-spaces/world/WorldPanel.h @@ -34,10 +34,10 @@ namespace Metal { public: std::vector getDependencies() override { return { - {"WorldRepository", world}, - {"EditorRepository", editorRepository}, - {"SelectionService", selectionService}, - {"DirectoryService", directoryService} + {"WorldRepository", &world}, + {"EditorRepository", &editorRepository}, + {"SelectionService", &selectionService}, + {"DirectoryService", &directoryService} }; } diff --git a/src/editor/panel/FileImportModalPanel.cpp b/src/editor/panel/FileImportModalPanel.cpp index e52c06ca..832b4828 100644 --- a/src/editor/panel/FileImportModalPanel.cpp +++ b/src/editor/panel/FileImportModalPanel.cpp @@ -13,7 +13,7 @@ namespace Metal { void FileImportModalPanel::onInitialize() { formPanel = new FormPanel(); - appendChild(formPanel); + initializePanel(formPanel); } void FileImportModalPanel::onSync() { diff --git a/src/editor/panel/FileImportModalPanel.h b/src/editor/panel/FileImportModalPanel.h index f3f5f713..fa9a75e5 100644 --- a/src/editor/panel/FileImportModalPanel.h +++ b/src/editor/panel/FileImportModalPanel.h @@ -21,10 +21,10 @@ namespace Metal { public: std::vector getDependencies() override { return { - {"EditorRepository", editorRepository}, - {"FileImporterService", fileImporterService}, - {"NotificationService", notificationService}, - {"FilesService", filesService} + {"EditorRepository", &editorRepository}, + {"FileImporterService", &fileImporterService}, + {"NotificationService", ¬ificationService}, + {"FilesService", &filesService} }; } diff --git a/src/editor/panel/NotificationsPanel.h b/src/editor/panel/NotificationsPanel.h index eae1b8e7..afdf6091 100644 --- a/src/editor/panel/NotificationsPanel.h +++ b/src/editor/panel/NotificationsPanel.h @@ -13,8 +13,8 @@ namespace Metal { public: std::vector getDependencies() override { return { - {"NotificationService", notificationService}, - {"EngineContext", engineContext} + {"NotificationService", ¬ificationService}, + {"EngineContext", &engineContext} }; } diff --git a/src/editor/passes/GridPass.h b/src/editor/passes/GridPass.h index 93342511..f9f2a635 100644 --- a/src/editor/passes/GridPass.h +++ b/src/editor/passes/GridPass.h @@ -18,9 +18,9 @@ namespace Metal { public: std::vector getDependencies() override { return { - {"PipelineService", pipelineService}, - {"ApplicationContext", applicationContext}, - {"EditorRepository", editorRepository} + {"PipelineService", &pipelineService}, + {"ApplicationContext", &applicationContext}, + {"EditorRepository", &editorRepository} }; } diff --git a/src/editor/passes/SelectionIDPass.h b/src/editor/passes/SelectionIDPass.h index 9a972cd2..0bf55bf6 100644 --- a/src/editor/passes/SelectionIDPass.h +++ b/src/editor/passes/SelectionIDPass.h @@ -21,10 +21,10 @@ namespace Metal { public: std::vector getDependencies() override { return { - {"PipelineService", pipelineService}, - {"EditorRepository", editorRepository}, - {"WorldRepository", worldRepository}, - {"MeshService", meshService} + {"PipelineService", &pipelineService}, + {"EditorRepository", &editorRepository}, + {"WorldRepository", &worldRepository}, + {"MeshService", &meshService} }; } diff --git a/src/editor/passes/SelectionOutlinePass.h b/src/editor/passes/SelectionOutlinePass.h index 3d036e68..8a9ccac5 100644 --- a/src/editor/passes/SelectionOutlinePass.h +++ b/src/editor/passes/SelectionOutlinePass.h @@ -17,8 +17,8 @@ namespace Metal { public: std::vector getDependencies() override { return { - {"PipelineService", pipelineService}, - {"EditorRepository", editorRepository} + {"PipelineService", &pipelineService}, + {"EditorRepository", &editorRepository} }; } diff --git a/src/editor/service/DockService.cpp b/src/editor/service/DockService.cpp index 6113369e..cf2f9182 100644 --- a/src/editor/service/DockService.cpp +++ b/src/editor/service/DockService.cpp @@ -135,10 +135,10 @@ namespace Metal { ImGui::DockBuilderDockWindow(d->internalId.c_str(), d->nodeId); for (auto *l: panel->getChildren()) { if (dynamic_cast(l)) { - panel->appendChild(new DockSpacePanel(dynamic_cast(l), d)); + panel->initializePanel(new DockSpacePanel(dynamic_cast(l), d)); return; } } - panel->appendChild(new DockSpacePanel(nullptr, d)); + panel->initializePanel(new DockSpacePanel(nullptr, d)); } } diff --git a/src/editor/service/FileImporterService.h b/src/editor/service/FileImporterService.h index 411c617a..4df01d4a 100644 --- a/src/editor/service/FileImporterService.h +++ b/src/editor/service/FileImporterService.h @@ -25,11 +25,11 @@ namespace Metal { public: std::vector getDependencies() override { return { - {"SceneImporterService", sceneImporterService}, - {"TextureImporterService", textureImporterService}, - {"VoxelImporterService", voxelImporterService}, - {"NotificationService", notificationService}, - {"AsyncTaskService", asyncTaskService} + {"SceneImporterService", &sceneImporterService}, + {"TextureImporterService", &textureImporterService}, + {"VoxelImporterService", &voxelImporterService}, + {"NotificationService", ¬ificationService}, + {"AsyncTaskService", &asyncTaskService} }; } diff --git a/src/editor/service/FilesService.h b/src/editor/service/FilesService.h index cdefef5a..c0228b93 100644 --- a/src/editor/service/FilesService.h +++ b/src/editor/service/FilesService.h @@ -20,7 +20,9 @@ namespace Metal { public: std::vector getDependencies() override { - return {{"DirectoryService", directoryService}, {"NotificationService", notificationService}}; + return { + {"DirectoryService", &directoryService}, + {"NotificationService", ¬ificationService}}; } FSEntry *getRoot() const { diff --git a/src/editor/service/MaterialImporterService.h b/src/editor/service/MaterialImporterService.h index cbe42008..ae2596cc 100644 --- a/src/editor/service/MaterialImporterService.h +++ b/src/editor/service/MaterialImporterService.h @@ -18,7 +18,7 @@ namespace Metal { public: std::vector getDependencies() override { return { - {"TextureImporterService", textureImporterService} + {"TextureImporterService", &textureImporterService} }; } diff --git a/src/editor/service/MeshImporterService.h b/src/editor/service/MeshImporterService.h index aa9c33fe..364c8764 100644 --- a/src/editor/service/MeshImporterService.h +++ b/src/editor/service/MeshImporterService.h @@ -23,7 +23,7 @@ namespace Metal { public: std::vector getDependencies() override { return { - {"DirectoryService", directoryService} + {"DirectoryService", &directoryService} }; } diff --git a/src/editor/service/PickingService.h b/src/editor/service/PickingService.h index a51b8167..d7e2e842 100644 --- a/src/editor/service/PickingService.h +++ b/src/editor/service/PickingService.h @@ -19,9 +19,9 @@ namespace Metal { public: std::vector getDependencies() override { return { - {"VulkanContext", vulkanContext}, - {"BufferService", bufferService}, - {"WorldRepository", worldRepository} + {"VulkanContext", &vulkanContext}, + {"BufferService", &bufferService}, + {"WorldRepository", &worldRepository} }; } diff --git a/src/editor/service/SceneImporterService.h b/src/editor/service/SceneImporterService.h index 997d76bc..daea86d0 100644 --- a/src/editor/service/SceneImporterService.h +++ b/src/editor/service/SceneImporterService.h @@ -25,9 +25,9 @@ namespace Metal { public: std::vector getDependencies() override { return { - {"MeshImporterService", meshImporterService}, - {"MaterialImporterService", materialImporterService}, - {"DirectoryService", directoryService} + {"MeshImporterService", &meshImporterService}, + {"MaterialImporterService", &materialImporterService}, + {"DirectoryService", &directoryService} }; } diff --git a/src/editor/service/SelectionService.h b/src/editor/service/SelectionService.h index 27562703..f3d7a7d0 100644 --- a/src/editor/service/SelectionService.h +++ b/src/editor/service/SelectionService.h @@ -16,8 +16,8 @@ namespace Metal { public: std::vector getDependencies() override { return { - {"EditorRepository", editorRepository}, - {"WorldRepository", worldRepository} + {"EditorRepository", &editorRepository}, + {"WorldRepository", &worldRepository} }; } diff --git a/src/editor/service/TextureImporterService.h b/src/editor/service/TextureImporterService.h index 59b56317..6daa7cc9 100644 --- a/src/editor/service/TextureImporterService.h +++ b/src/editor/service/TextureImporterService.h @@ -14,7 +14,7 @@ namespace Metal { public: std::vector getDependencies() override { return { - {"DirectoryService", directoryService} + {"DirectoryService", &directoryService} }; } diff --git a/src/editor/service/ThemeService.h b/src/editor/service/ThemeService.h index 4cc321d7..4ccf93a6 100644 --- a/src/editor/service/ThemeService.h +++ b/src/editor/service/ThemeService.h @@ -31,7 +31,7 @@ namespace Metal { void onSync() override; std::vector getDependencies() override { - return {{"EditorRepository", editorRepository}}; + return {{"EditorRepository", &editorRepository}}; } }; } // Metal diff --git a/src/editor/service/VoxelImporterService.h b/src/editor/service/VoxelImporterService.h index 781283b0..4221e448 100644 --- a/src/editor/service/VoxelImporterService.h +++ b/src/editor/service/VoxelImporterService.h @@ -14,7 +14,7 @@ namespace Metal { public: std::vector getDependencies() override { return { - {"DirectoryService", directoryService} + {"DirectoryService", &directoryService} }; } diff --git a/src/engine/EngineContext.cpp b/src/engine/EngineContext.cpp index ffdb7651..057569a9 100644 --- a/src/engine/EngineContext.cpp +++ b/src/engine/EngineContext.cpp @@ -41,9 +41,10 @@ namespace Metal { } void EngineContext::setCurrentFrame(const std::string &id) { - for (auto *frame : registeredFrames) { + for (auto *frame: registeredFrames) { if (frame->getId() == id) { currentFrame = frame; + currentFrame->setShouldRender(true); return; } } diff --git a/src/engine/EngineContext.h b/src/engine/EngineContext.h index 2e09a24e..a630a405 100644 --- a/src/engine/EngineContext.h +++ b/src/engine/EngineContext.h @@ -46,15 +46,15 @@ namespace Metal { public: std::vector getDependencies() override { return { - {"TransformService", transformService}, - {"StreamingService", streamingService}, - {"RayTracingService", rayTracingService}, - {"CameraService", cameraService}, - {"LightService", lightService}, - {"VolumeService", volumeService}, - {"WorldRepository", worldRepository}, - {"EditorRepository", editorRepository}, - {"EngineRepository", engineRepository} + {"TransformService", &transformService}, + {"StreamingService", &streamingService}, + {"RayTracingService", &rayTracingService}, + {"CameraService", &cameraService}, + {"LightService", &lightService}, + {"VolumeService", &volumeService}, + {"WorldRepository", &worldRepository}, + {"EditorRepository", &editorRepository}, + {"EngineRepository", &engineRepository} }; } diff --git a/src/engine/frame-builder/EngineFrameBuilder.h b/src/engine/frame-builder/EngineFrameBuilder.h index e4b90114..fa72b744 100644 --- a/src/engine/frame-builder/EngineFrameBuilder.h +++ b/src/engine/frame-builder/EngineFrameBuilder.h @@ -33,7 +33,7 @@ namespace Metal { public: std::vector getDependencies() override { - return {{"EngineContext", engineContext}}; + return {{"EngineContext", &engineContext}}; } explicit EngineFrameBuilder(std::string frameId = Util::uuidV4()); diff --git a/src/engine/frame-builder/structures/BufferBuilder.h b/src/engine/frame-builder/structures/BufferBuilder.h index 60d18771..acb66359 100644 --- a/src/engine/frame-builder/structures/BufferBuilder.h +++ b/src/engine/frame-builder/structures/BufferBuilder.h @@ -18,7 +18,7 @@ namespace Metal { public: std::vector getDependencies() override { - return {{"BufferService", bufferService}}; + return {{"BufferService", &bufferService}}; } explicit BufferBuilder(const std::string &id, VkDeviceSize size, VkBufferUsageFlags usage, diff --git a/src/engine/frame-builder/structures/CommandBufferRecorderBuilder.h b/src/engine/frame-builder/structures/CommandBufferRecorderBuilder.h index e5a52121..19a3b56c 100644 --- a/src/engine/frame-builder/structures/CommandBufferRecorderBuilder.h +++ b/src/engine/frame-builder/structures/CommandBufferRecorderBuilder.h @@ -17,8 +17,8 @@ namespace Metal { public: std::vector getDependencies() override { return { - {"FrameBufferService", framebufferService}, - {"CommandBufferRecorderService", commandBufferRecorderService} + {"FrameBufferService", &framebufferService}, + {"CommandBufferRecorderService", &commandBufferRecorderService} }; } diff --git a/src/engine/frame-builder/structures/FramebufferBuilder.h b/src/engine/frame-builder/structures/FramebufferBuilder.h index b439cffa..d1b4807d 100644 --- a/src/engine/frame-builder/structures/FramebufferBuilder.h +++ b/src/engine/frame-builder/structures/FramebufferBuilder.h @@ -24,7 +24,7 @@ namespace Metal { FrameBufferService *frameBufferService = nullptr; public: std::vector getDependencies() override { - return {{"FrameBufferService", frameBufferService}}; + return {{"FrameBufferService", &frameBufferService}}; } explicit FramebufferBuilder(const std::string &id, const unsigned w, const unsigned h, glm::vec4 clearColor) diff --git a/src/engine/frame-builder/structures/TextureBuilder.h b/src/engine/frame-builder/structures/TextureBuilder.h index 3294e0e9..09618bf9 100644 --- a/src/engine/frame-builder/structures/TextureBuilder.h +++ b/src/engine/frame-builder/structures/TextureBuilder.h @@ -14,7 +14,7 @@ namespace Metal { TextureService *textureService = nullptr; public: std::vector getDependencies() override { - return {{"TextureService", textureService}}; + return {{"TextureService", &textureService}}; } explicit TextureBuilder(const std::string &id, unsigned w, unsigned h, VkFormat format = VK_FORMAT_R16G16B16A16_SFLOAT) diff --git a/src/engine/passes/CommandBufferRecorder.cpp b/src/engine/passes/CommandBufferRecorder.cpp index e523f940..326f9765 100644 --- a/src/engine/passes/CommandBufferRecorder.cpp +++ b/src/engine/passes/CommandBufferRecorder.cpp @@ -11,7 +11,7 @@ #include "../../core/FrameService.h" namespace Metal { - void CommandBufferRecorder::createCommandBuffer() { + void CommandBufferRecorder::onInitialize() { VkCommandBufferAllocateInfo allocInfo{}; allocInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; allocInfo.commandPool = vulkanContext->commandPool; @@ -36,12 +36,10 @@ namespace Metal { scissor.extent.width = frameBuffer->bufferWidth; scissor.extent.height = frameBuffer->bufferHeight; - createCommandBuffer(); computePassMode = false; } - CommandBufferRecorder::CommandBufferRecorder(std::string id) : RuntimeResource(std::move(id)) { - createCommandBuffer(); + CommandBufferRecorder::CommandBufferRecorder(const std::string &id) : RuntimeResource(id) { computePassMode = true; } diff --git a/src/engine/passes/CommandBufferRecorder.h b/src/engine/passes/CommandBufferRecorder.h index e5348c57..95a3733d 100644 --- a/src/engine/passes/CommandBufferRecorder.h +++ b/src/engine/passes/CommandBufferRecorder.h @@ -3,6 +3,8 @@ #include "../resource/RuntimeResource.h" #include #include + +#include "../../common/IInit.h" #include "../resource/PipelineInstance.h" #include "../../core/vulkan/VulkanUtils.h" @@ -12,7 +14,7 @@ namespace Metal { class ApplicationContext; struct FrameBufferInstance; - class CommandBufferRecorder final : public RuntimeResource { + class CommandBufferRecorder final : public RuntimeResource, public IInit { std::array _commandBuffers{}; VkViewport viewport{}; VkRect2D scissor{}; @@ -29,12 +31,14 @@ namespace Metal { public: std::vector getDependencies() override { - return {{"FrameService", frameService}, {"VulkanContext", vulkanContext}}; + return {{"FrameService", &frameService}, {"VulkanContext", &vulkanContext}}; } + void onInitialize() override; + explicit CommandBufferRecorder(std::string id, FrameBufferInstance *frameBuffer, bool clearBuffer = true); - explicit CommandBufferRecorder(std::string id); + explicit CommandBufferRecorder(const std::string &id); ResourceType resourceType() override { return COMMAND_BUFFER_RECORDER; diff --git a/src/engine/passes/impl/HWRayTracingPass.h b/src/engine/passes/impl/HWRayTracingPass.h index c8e9601a..9774c65d 100644 --- a/src/engine/passes/impl/HWRayTracingPass.h +++ b/src/engine/passes/impl/HWRayTracingPass.h @@ -23,11 +23,11 @@ namespace Metal { public: std::vector getDependencies() override { return { - {"RayTracingService", rayTracingService}, - {"PipelineService", pipelineService}, - {"VulkanContext", vulkanContext}, - {"EngineContext", engineContext}, - {"EngineRepository", engineRepository} + {"RayTracingService", &rayTracingService}, + {"PipelineService", &pipelineService}, + {"VulkanContext", &vulkanContext}, + {"EngineContext", &engineContext}, + {"EngineRepository", &engineRepository} }; } diff --git a/src/engine/passes/impl/PostProcessingPass.h b/src/engine/passes/impl/PostProcessingPass.h index 9cf49ab9..15b31a27 100644 --- a/src/engine/passes/impl/PostProcessingPass.h +++ b/src/engine/passes/impl/PostProcessingPass.h @@ -18,9 +18,9 @@ namespace Metal { public: std::vector getDependencies() override { return { - {"VulkanContext", vulkanContext}, - {"PipelineService", pipelineService}, - {"WorldRepository", worldRepository} + {"VulkanContext", &vulkanContext}, + {"PipelineService", &pipelineService}, + {"WorldRepository", &worldRepository} }; } diff --git a/src/engine/passes/impl/SpatialFilterPass.h b/src/engine/passes/impl/SpatialFilterPass.h index 9edd07ca..515cca51 100644 --- a/src/engine/passes/impl/SpatialFilterPass.h +++ b/src/engine/passes/impl/SpatialFilterPass.h @@ -11,7 +11,7 @@ namespace Metal { public: std::vector getDependencies() override { return { - {"PipelineService", pipelineService} + {"PipelineService", &pipelineService} }; } diff --git a/src/engine/passes/impl/TemporalAccumulationPass.h b/src/engine/passes/impl/TemporalAccumulationPass.h index ff7c467c..f2ed2798 100644 --- a/src/engine/passes/impl/TemporalAccumulationPass.h +++ b/src/engine/passes/impl/TemporalAccumulationPass.h @@ -11,7 +11,7 @@ namespace Metal { public: std::vector getDependencies() override { return { - {"PipelineService", pipelineService} + {"PipelineService", &pipelineService} }; } diff --git a/src/engine/repository/WorldRepository.h b/src/engine/repository/WorldRepository.h index 8ed4ee40..8f62fa62 100644 --- a/src/engine/repository/WorldRepository.h +++ b/src/engine/repository/WorldRepository.h @@ -25,8 +25,8 @@ namespace Metal { std::vector getDependencies() override { return { - {"RayTracingService", rayTracingService}, - {"DirectoryService", directoryService} + {"RayTracingService", &rayTracingService}, + {"DirectoryService", &directoryService} }; } diff --git a/src/engine/resource/FrameBufferAttachment.cpp b/src/engine/resource/FrameBufferAttachment.cpp index 00bbfe33..c580b7b8 100644 --- a/src/engine/resource/FrameBufferAttachment.cpp +++ b/src/engine/resource/FrameBufferAttachment.cpp @@ -7,9 +7,5 @@ namespace Metal { vkDestroyImage(vulkanContext->device.device, vkImage, nullptr); vkDestroyImageView(vulkanContext->device.device, vkImageView, nullptr); vkFreeMemory(vulkanContext->device.device, vkImageMemory, nullptr); - - if (imageDescriptor != nullptr) { - descriptorSetService->disposeResource(imageDescriptor); - } } } diff --git a/src/engine/resource/FrameBufferAttachment.h b/src/engine/resource/FrameBufferAttachment.h index 6a1b102c..9f33e11e 100644 --- a/src/engine/resource/FrameBufferAttachment.h +++ b/src/engine/resource/FrameBufferAttachment.h @@ -15,6 +15,13 @@ namespace Metal { void dispose() const; + std::vector getDependencies() override { + return { + {"VulkanContext", &vulkanContext}, + {"DescriptorSetService", &descriptorSetService} + }; + } + private: VulkanContext *vulkanContext = nullptr; DescriptorSetService *descriptorSetService = nullptr; diff --git a/src/engine/resource/RuntimeResource.h b/src/engine/resource/RuntimeResource.h index e3952bcc..16c485f2 100644 --- a/src/engine/resource/RuntimeResource.h +++ b/src/engine/resource/RuntimeResource.h @@ -21,7 +21,7 @@ namespace Metal { public: std::vector getDependencies() override { - return {{"VulkanContext", vulkanContext}}; + return {{"VulkanContext", &vulkanContext}}; } virtual ~RuntimeResource() = default; diff --git a/src/engine/service/CameraService.h b/src/engine/service/CameraService.h index 7e2fe9cb..c4552745 100644 --- a/src/engine/service/CameraService.h +++ b/src/engine/service/CameraService.h @@ -51,9 +51,9 @@ namespace Metal { std::vector getDependencies() override { return { - {"EngineContext", engineContext}, - {"WorldRepository", worldRepository}, - {"RuntimeRepository", runtimeRepository} + {"EngineContext", &engineContext}, + {"WorldRepository", &worldRepository}, + {"RuntimeRepository", &runtimeRepository} }; } diff --git a/src/engine/service/DescriptorSetService.h b/src/engine/service/DescriptorSetService.h index 52e420fe..d0ff4df0 100644 --- a/src/engine/service/DescriptorSetService.h +++ b/src/engine/service/DescriptorSetService.h @@ -22,10 +22,10 @@ namespace Metal { public: std::vector getDependencies() override { return { - {"VulkanContext", vulkanContext}, - {"FrameBufferService", framebufferService}, - {"BufferService", bufferService}, - {"TextureService", textureService} + {"VulkanContext", &vulkanContext}, + {"FrameBufferService", &framebufferService}, + {"BufferService", &bufferService}, + {"TextureService", &textureService} }; } diff --git a/src/engine/service/FrameBufferService.cpp b/src/engine/service/FrameBufferService.cpp index 0292ea33..a47cb814 100644 --- a/src/engine/service/FrameBufferService.cpp +++ b/src/engine/service/FrameBufferService.cpp @@ -111,6 +111,7 @@ namespace Metal { for (unsigned int i = 0; i < framebuffer->attachments.size(); i++) { VkAttachmentDescription &attachmentDescription = attachmentDescriptions.emplace_back(); const std::shared_ptr fbAttachment = framebuffer->attachments[i]; + ctx->injectDependencies(fbAttachment.get()); attachmentDescription.samples = VK_SAMPLE_COUNT_1_BIT; attachmentDescription.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; attachmentDescription.storeOp = VK_ATTACHMENT_STORE_OP_STORE; diff --git a/src/engine/service/FrameBufferService.h b/src/engine/service/FrameBufferService.h index 76676188..5c077a77 100644 --- a/src/engine/service/FrameBufferService.h +++ b/src/engine/service/FrameBufferService.h @@ -25,7 +25,7 @@ namespace Metal { public: std::vector getDependencies() override { - return {{"VulkanContext", vulkanContext}}; + return {{"VulkanContext", &vulkanContext}}; } FrameBufferInstance *createFrameBuffer(const std::string &id, unsigned int w, unsigned int h, diff --git a/src/engine/service/LightService.h b/src/engine/service/LightService.h index 3a5c7575..9764b680 100644 --- a/src/engine/service/LightService.h +++ b/src/engine/service/LightService.h @@ -28,8 +28,8 @@ namespace Metal { public: std::vector getDependencies() override { return { - {"EngineContext", engineContext}, - {"EngineRepository", engineRepository} + {"EngineContext", &engineContext}, + {"EngineRepository", &engineRepository} }; } diff --git a/src/engine/service/MaterialService.h b/src/engine/service/MaterialService.h index 660c48b8..1656406f 100644 --- a/src/engine/service/MaterialService.h +++ b/src/engine/service/MaterialService.h @@ -13,7 +13,7 @@ namespace Metal { public: std::vector getDependencies() override { return { - {"TextureService", textureService} + {"TextureService", &textureService} }; } diff --git a/src/engine/service/MeshService.h b/src/engine/service/MeshService.h index b7984f35..0fa3241b 100644 --- a/src/engine/service/MeshService.h +++ b/src/engine/service/MeshService.h @@ -23,9 +23,9 @@ namespace Metal { std::vector getDependencies() override { return { - {"BufferService", bufferService}, - {"RayTracingService", rayTracingService}, - {"DirectoryService", directoryService} + {"BufferService", &bufferService}, + {"RayTracingService", &rayTracingService}, + {"DirectoryService", &directoryService} }; } diff --git a/src/engine/service/RayTracingService.cpp b/src/engine/service/RayTracingService.cpp index af1fac86..a0c103f6 100644 --- a/src/engine/service/RayTracingService.cpp +++ b/src/engine/service/RayTracingService.cpp @@ -405,9 +405,6 @@ namespace Metal { } void RayTracingService::dispose() { - LOG_INFO("Destroying acceleration structures"); - auto &vulkan = vulkanContext; - if (vulkanContext->device.device != VK_NULL_HANDLE) { vkDeviceWaitIdle(vulkanContext->device.device); } diff --git a/src/engine/service/RayTracingService.h b/src/engine/service/RayTracingService.h index c4325efe..cec2bca4 100644 --- a/src/engine/service/RayTracingService.h +++ b/src/engine/service/RayTracingService.h @@ -75,14 +75,14 @@ namespace Metal { std::vector getDependencies() override { return { - {"VulkanContext", vulkanContext}, - {"PipelineService", pipelineService}, - {"WorldRepository", worldRepository}, - {"MeshService", meshService}, - {"MaterialService", materialService}, - {"BufferService", bufferService}, - {"EngineContext", engineContext}, - {"DescriptorSetService", descriptorSetService} + {"VulkanContext", &vulkanContext}, + {"PipelineService", &pipelineService}, + {"WorldRepository", &worldRepository}, + {"MeshService", &meshService}, + {"MaterialService", &materialService}, + {"BufferService", &bufferService}, + {"EngineContext", &engineContext}, + {"DescriptorSetService", &descriptorSetService} }; } diff --git a/src/engine/service/ShaderService.cpp b/src/engine/service/ShaderService.cpp index 30d8b467..8fc26d80 100644 --- a/src/engine/service/ShaderService.cpp +++ b/src/engine/service/ShaderService.cpp @@ -15,10 +15,9 @@ #include "../../editor/enum/ShadingMode.h" #include "glslang/Include/glslang_c_interface.h" #include "glslang/Public/resource_limits_c.h" -#define BASE_PATH directoryService->getShadersDirectory() - #include "../../core/DirectoryService.h" #include "../../core/vulkan/VulkanContext.h" +#define BASE_PATH "../resources/shaders/" namespace Metal { void ShaderService::CheckShaderCompilation(glslang_shader_t *shader) { @@ -134,7 +133,7 @@ namespace Metal { throw std::runtime_error("Unknown shader stage in file"); } - std::string ShaderService::ProcessIncludes(const std::string &input, const std::string &basePath) { + std::string ShaderService::ProcessIncludes(const std::string &input) { std::string result = input; std::regex includePattern(R"(#include\s+"(.+))"); std::smatch match; @@ -147,7 +146,7 @@ namespace Metal { } try { std::string source; - FilesUtil::ReadFile((basePath + includeFile).c_str(), source); + FilesUtil::ReadFile((BASE_PATH + includeFile).c_str(), source); result.replace(match.position(0), match.length(0), source); } catch (const std::exception &e) { LOG_ERROR("Error loading included shader: " + std::string(e.what())); @@ -155,21 +154,20 @@ namespace Metal { } } if (result.find("#include") != std::string::npos) { - result = ProcessIncludes(result, basePath); + result = ProcessIncludes(result); } return result; } - std::string ShaderService::ProcessShader(const std::string &file, const std::string &basePath) { + std::string ShaderService::ProcessShader(const std::string &file) { std::string source; FilesUtil::ReadFile(file.c_str(), source); - return ProcessIncludes(source, basePath); + return ProcessIncludes(source); } VkShaderModule ShaderService::createShaderModule(const std::string &pFilename) { - this->isDebugMode = ctx->isDebugMode(); - std::string source = ProcessShader(BASE_PATH + pFilename, BASE_PATH); - if (isDebugMode) { + std::string source = ProcessShader(BASE_PATH + pFilename); + if (ctx->isDebugMode()) { source = "#define DEBUG\n" + source; } for (auto &entry: ShadingModes::getShaderEntries()) { @@ -181,9 +179,8 @@ namespace Metal { const size_t sourceHash = std::hash{}(source); const std::string part(BASE_PATH + pFilename); const std::string shaderName = part.substr(part.find_last_of('/') + 1, part.size()); - const std::string shadersDirectory = directoryService->getShadersDirectory(); - const std::string binaryFilename = shadersDirectory + shaderName + ".spv"; - const std::string hashFilename = shadersDirectory + shaderName + ".hash"; + const std::string binaryFilename = directoryService->getShadersDirectory() + shaderName + ".spv"; + const std::string hashFilename = directoryService->getShadersDirectory() + shaderName + ".hash"; ShaderModule shader{}; diff --git a/src/engine/service/ShaderService.h b/src/engine/service/ShaderService.h index 19199570..98f5b929 100644 --- a/src/engine/service/ShaderService.h +++ b/src/engine/service/ShaderService.h @@ -8,29 +8,29 @@ namespace Metal { class VulkanContext; class DirectoryService; + class ShaderService final : public IService { - bool isDebugMode = false; VulkanContext *vulkanContext = nullptr; DirectoryService *directoryService = nullptr; static void CheckShaderCompilation(glslang_shader_t *shader); - bool CompileShader(glslang_stage_t stage, const char *pShaderCode, - ShaderModule *shaderModule) const; + bool CompileShader(glslang_stage_t stage, const char *pShaderCode, + ShaderModule *shaderModule) const; static glslang_stage_t ShaderStageFromFilename(const char *pFilename); - static std::string ProcessIncludes(const std::string &input, const std::string &basePath); + std::string ProcessIncludes(const std::string &input); - static std::string ProcessShader(const std::string &file, const std::string &basePath); + std::string ProcessShader(const std::string &file); public: ShaderService() = default; std::vector getDependencies() override { return { - {"VulkanContext", vulkanContext}, - {"DirectoryService", directoryService} + {"VulkanContext", &vulkanContext}, + {"DirectoryService", &directoryService} }; } diff --git a/src/engine/service/StreamingService.h b/src/engine/service/StreamingService.h index 44201422..2eecf222 100644 --- a/src/engine/service/StreamingService.h +++ b/src/engine/service/StreamingService.h @@ -33,11 +33,11 @@ namespace Metal { public: std::vector getDependencies() override { return { - {"EngineContext", engineContext}, - {"WorldRepository", worldRepository}, - {"MeshService", meshService}, - {"TextureService", textureService}, - {"VoxelService", voxelService} + {"EngineContext", &engineContext}, + {"WorldRepository", &worldRepository}, + {"MeshService", &meshService}, + {"TextureService", &textureService}, + {"VoxelService", &voxelService} }; } diff --git a/src/engine/service/TextureService.h b/src/engine/service/TextureService.h index 047561e7..abc1bd26 100644 --- a/src/engine/service/TextureService.h +++ b/src/engine/service/TextureService.h @@ -45,11 +45,11 @@ namespace Metal { public: std::vector getDependencies() override { return { - {"VulkanContext", vulkanContext}, - {"BufferService", bufferService}, - {"PipelineService", pipelineService}, - {"DescriptorSetService", descriptorSetService}, - {"DirectoryService", directoryService} + {"VulkanContext", &vulkanContext}, + {"BufferService", &bufferService}, + {"PipelineService", &pipelineService}, + {"DescriptorSetService", &descriptorSetService}, + {"DirectoryService", &directoryService} }; } diff --git a/src/engine/service/TransformService.h b/src/engine/service/TransformService.h index f221dde7..bab96925 100644 --- a/src/engine/service/TransformService.h +++ b/src/engine/service/TransformService.h @@ -25,8 +25,8 @@ namespace Metal { public: std::vector getDependencies() override { return { - {"WorldRepository", worldRepository}, - {"RayTracingService", rayTracingService} + {"WorldRepository", &worldRepository}, + {"RayTracingService", &rayTracingService} }; } diff --git a/src/engine/service/VolumeService.h b/src/engine/service/VolumeService.h index eada2e3d..70ff3a1e 100644 --- a/src/engine/service/VolumeService.h +++ b/src/engine/service/VolumeService.h @@ -21,8 +21,8 @@ namespace Metal { public: std::vector getDependencies() override { return { - {"WorldRepository", worldRepository}, - {"EngineContext", engineContext} + {"WorldRepository", &worldRepository}, + {"EngineContext", &engineContext} }; } diff --git a/src/main.cpp b/src/main.cpp index 8c08e1ab..3fd38ca0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -104,13 +104,18 @@ int main(int, char **) { directoryService.updateRootPath(false); Metal::EditorPanel editor{}; context->injectDependencies(&editor); + editor.onInitialize(); frameService.setPanel(&editor); if (!frameService.isValidContext()) { printf("GLFW: Vulkan Not Supported\n"); return 1; } - frameService.onInitialize(); + frameService.start(); context->dispose(); + context->getSingleton().disposeManually(); + context->getSingleton().disposeManually(); + context->getSingleton().disposeManually(); + return 0; } From 7d8f838202b34513cb28f5caaf42f26c08944e5a Mon Sep 17 00:00:00 2001 From: facobackup Date: Sat, 14 Mar 2026 20:21:07 -0300 Subject: [PATCH 16/18] Tests Adjusting layout --- .output.txt | 303 ----------------- CMakeLists.txt | 306 ++---------------- ...SelectedDot.frag => SelectionOutline.frag} | 0 src/ApplicationContext.cpp | 7 + src/ApplicationContext.h | 3 + src/CMakeLists.txt | 296 +++++++++++++++++ src/core/vulkan/VulkanContext.cpp | 3 +- src/core/vulkan/VulkanContext.h | 1 - src/editor/EditorPanel.cpp | 86 +++-- src/editor/EditorPanel.h | 4 - .../dock-spaces/footer/EditorFooterPanel.cpp | 12 +- .../dock-spaces/footer/EditorFooterPanel.h | 5 + .../dock-spaces/header/AsyncTaskPanel.cpp | 44 ++- .../dock-spaces/header/EditorHeaderPanel.cpp | 63 ++-- .../dock-spaces/header/EditorHeaderPanel.h | 17 +- src/editor/passes/GridPass.cpp | 3 +- src/editor/passes/GridPass.h | 3 - src/editor/passes/SelectionOutlinePass.cpp | 2 +- src/main.cpp | 7 - tests/ApplicationContextTest.cpp | 39 +++ tests/CMakeLists.txt | 21 ++ tests/WorldRepositoryTest.cpp | 64 ++++ vcpkg.json | 8 +- 23 files changed, 587 insertions(+), 710 deletions(-) delete mode 100644 .output.txt rename resources/shaders/tools/{SelectedDot.frag => SelectionOutline.frag} (100%) create mode 100644 src/CMakeLists.txt create mode 100644 tests/ApplicationContextTest.cpp create mode 100644 tests/CMakeLists.txt create mode 100644 tests/WorldRepositoryTest.cpp diff --git a/.output.txt b/.output.txt deleted file mode 100644 index 7bda7820..00000000 --- a/.output.txt +++ /dev/null @@ -1,303 +0,0 @@ -[23/44] Building CXX object CMakeFiles\metal_engine.dir\src\engine\passes\AbstractPass.cpp.obj -C:\Users\russi\CLionProjects\metal-engine\src\engine\passes\AbstractPass.h(35): warning C4458: declaration of 'vkCommandBuffer' hides class member -C:\Users\russi\CLionProjects\metal-engine\src\engine\passes\AbstractPass.h(24): note: see declaration of 'Metal::AbstractPass::vkCommandBuffer' -C:\Users\russi\CLionProjects\metal-engine\src\engine\passes\AbstractPass.cpp(57): warning C4267: 'argument': conversion from 'size_t' to 'uint32_t', possible loss of data -[24/44] Building CXX object CMakeFiles\metal_engine...editor\dock-spaces\header\EditorHeaderPanel.cpp.obj -C:\Users\russi\CLionProjects\metal-engine\src\editor\dock-spaces\header\../../util/UIUtil.h(48): warning C4244: 'initializing': conversion from 'int' to 'float', possible loss of data -C:\Users\russi\CLionProjects\metal-engine\src\editor\dock-spaces\header\../../util/UIUtil.h(48): warning C4244: 'initializing': conversion from 'int' to 'const float', possible loss of data -C:\Users\russi\CLionProjects\metal-engine\src\engine\dto/GlobalDataUBO.h(14): warning C4324: 'Metal::GlobalDataUBO': structure was padded due to alignment specifier -C:\Users\russi\CLionProjects\metal-engine\src\engine\dto/GlobalDataUBO.h(15): warning C4324: 'Metal::GlobalDataUBO': structure was padded due to alignment specifier -C:\Users\russi\CLionProjects\metal-engine\src\engine\frame-builder\../passes/AbstractPass.h(35): warning C4458: declaration of 'vkCommandBuffer' hides class member -C:\Users\russi\CLionProjects\metal-engine\src\engine\frame-builder\../passes/AbstractPass.h(24): note: see declaration of 'Metal::AbstractPass::vkCommandBuffer' -C:\Users\russi\CLionProjects\metal-engine\src\editor\util\../enum/EntryType.h(33): warning C4505: 'Metal::EntryType::GetDTO': unreferenced function with internal linkage has been removed -C:\Users\russi\CLionProjects\metal-engine\src\editor\dock-spaces\header\../../util/UIUtil.h(46): warning C4505: 'Metal::UIUtil::RenderOption': unreferenced function with internal linkage has been removed -C:\Users\russi\CLionProjects\metal-engine\src\editor\dock-spaces\header\../../util/UIUtil.h(52): warning C4505: 'Metal::UIUtil::RenderTooltip': unreferenced function with internal linkage has been removed -C:\Users\russi\CLionProjects\metal-engine\src\editor\dock-spaces\header\../../util/UIUtil.h(66): warning C4505: 'Metal::UIUtil::Spacing': unreferenced function with internal linkage has been removed -C:\Users\russi\CLionProjects\metal-engine\src\editor\dock-spaces\header\../../util/UIUtil.h(72): warning C4505: 'Metal::UIUtil::DynamicSpacing': unreferenced function with internal linkage has been removed -C:\Users\russi\CLionProjects\metal-engine\src\editor\dock-spaces\header\../../util/UIUtil.h(102): warning C4505: 'Metal::UIUtil::DrawVec2Control': unreferenced function with internal linkage has been removed -C:\Users\russi\CLionProjects\metal-engine\src\editor\dock-spaces\header\../../util/UIUtil.h(119): warning C4505: 'Metal::UIUtil::DrawVec3Control': unreferenced function with internal linkage has been removed -C:\Users\russi\CLionProjects\metal-engine\src\editor\dock-spaces\header\../../util/UIUtil.h(159): warning C4505: 'Metal::UIUtil::DrawQuatControl': unreferenced function with internal linkage has been removed -C:\Users\russi\CLionProjects\metal-engine\src\editor\dock-spaces\header\../../util/UIUtil.h(163): warning C4505: 'Metal::UIUtil::GetKeyChordName': unreferenced function with internal linkage has been removed -C:\Users\russi\CLionProjects\metal-engine\src\editor\dock-spaces\header\../../util/UIUtil.h(179): warning C4505: 'Metal::UIUtil::GetEntryIcon': unreferenced function with internal linkage has been removed -[25/44] Building CXX object CMakeFiles\metal_engine.dir\src\ApplicationContext.cpp.obj -C:\Users\russi\CLionProjects\metal-engine\src\engine\dto/GlobalDataUBO.h(14): warning C4324: 'Metal::GlobalDataUBO': structure was padded due to alignment specifier -C:\Users\russi\CLionProjects\metal-engine\src\engine\dto/GlobalDataUBO.h(15): warning C4324: 'Metal::GlobalDataUBO': structure was padded due to alignment specifier -C:\Users\russi\CLionProjects\metal-engine\src\engine\frame-builder\../passes/AbstractPass.h(35): warning C4458: declaration of 'vkCommandBuffer' hides class member -C:\Users\russi\CLionProjects\metal-engine\src\engine\frame-builder\../passes/AbstractPass.h(24): note: see declaration of 'Metal::AbstractPass::vkCommandBuffer' -[26/44] Building CXX object CMakeFiles\metal_engine.dir\src\engine\passes\impl\HWRayTracingPass.cpp.obj -C:\Users\russi\CLionProjects\metal-engine\src\engine\passes\AbstractPass.h(35): warning C4458: declaration of 'vkCommandBuffer' hides class member -C:\Users\russi\CLionProjects\metal-engine\src\engine\passes\AbstractPass.h(24): note: see declaration of 'Metal::AbstractPass::vkCommandBuffer' -C:\Users\russi\CLionProjects\metal-engine\src\engine\service\../dto/MeshMetadata.h(13): warning C4324: 'Metal::MeshMetadata': structure was padded due to alignment specifier -C:\Users\russi\CLionProjects\metal-engine\src\engine\passes\impl\../../service/RayTracingService.h(15): warning C4099: 'Metal::BufferInstance': type name first seen using 'struct' now seen using 'class' -C:\Users\russi\CLionProjects\metal-engine\src\engine\dto\DescriptorBinding.h(8): note: see declaration of 'Metal::BufferInstance' -C:\Users\russi\CLionProjects\metal-engine\src\engine\dto/GlobalDataUBO.h(14): warning C4324: 'Metal::GlobalDataUBO': structure was padded due to alignment specifier -C:\Users\russi\CLionProjects\metal-engine\src\engine\dto/GlobalDataUBO.h(15): warning C4324: 'Metal::GlobalDataUBO': structure was padded due to alignment specifier -C:\Users\russi\CLionProjects\metal-engine\src\common\Inspectable.h(125): warning C4100: 'member': unreferenced parameter -C:\Users\russi\CLionProjects\metal-engine\src\common\../editor/enum/EntryType.h(33): warning C4505: 'Metal::EntryType::GetDTO': unreferenced function with internal linkage has been removed -[27/44] Building CXX object CMakeFiles\metal_engine.dir\src\engine\service\LightService.cpp.obj -C:\Users\russi\CLionProjects\metal-engine\src\engine\service\../dto/LightData.h(11): warning C4324: 'Metal::LightData': structure was padded due to alignment specifier -C:\Users\russi\CLionProjects\metal-engine\src\engine\service\../dto/LightData.h(12): warning C4324: 'Metal::LightData': structure was padded due to alignment specifier -C:\Users\russi\CLionProjects\metal-engine\src\engine\service\LightService.h(49): warning C4267: 'return': conversion from 'size_t' to 'unsigned int', possible loss of data -C:\Users\russi\CLionProjects\metal-engine\src\engine\dto/GlobalDataUBO.h(14): warning C4324: 'Metal::GlobalDataUBO': structure was padded due to alignment specifier -C:\Users\russi\CLionProjects\metal-engine\src\engine\dto/GlobalDataUBO.h(15): warning C4324: 'Metal::GlobalDataUBO': structure was padded due to alignment specifier -C:\Users\russi\CLionProjects\metal-engine\src\engine\frame-builder\../passes/AbstractPass.h(35): warning C4458: declaration of 'vkCommandBuffer' hides class member -C:\Users\russi\CLionProjects\metal-engine\src\engine\frame-builder\../passes/AbstractPass.h(24): note: see declaration of 'Metal::AbstractPass::vkCommandBuffer' -C:\Users\russi\CLionProjects\metal-engine\src\common\Inspectable.h(125): warning C4100: 'member': unreferenced parameter -C:\Users\russi\CLionProjects\metal-engine\src\common\../editor/enum/EntryType.h(33): warning C4505: 'Metal::EntryType::GetDTO': unreferenced function with internal linkage has been removed -[28/44] Building CXX object CMakeFiles\metal_engine...c\editor\dock-spaces\viewport\ViewportPanel.cpp.obj -C:\Users\russi\CLionProjects\metal-engine\src\engine\dto\../../common/Inspectable.h(125): warning C4100: 'member': unreferenced parameter -C:\Users\russi\CLionProjects\metal-engine\src\editor\dock-spaces\viewport\../../repository/EditorRepository.h(33): warning C4305: 'initializing': truncation from 'double' to 'float' -C:\Users\russi\CLionProjects\metal-engine\src\editor\dock-spaces\viewport\../../../engine/repository/WorldRepository.h(15): warning C4099: 'Metal::DirectoryService': type name first seen using 'struct' now seen using 'class' -C:\Users\russi\CLionProjects\metal-engine\src\editor\dock-spaces\viewport\ViewportPanel.h(13): note: see declaration of 'Metal::DirectoryService' -C:\Users\russi\CLionProjects\metal-engine\src\engine\dto/GlobalDataUBO.h(14): warning C4324: 'Metal::GlobalDataUBO': structure was padded due to alignment specifier -C:\Users\russi\CLionProjects\metal-engine\src\engine\dto/GlobalDataUBO.h(15): warning C4324: 'Metal::GlobalDataUBO': structure was padded due to alignment specifier -C:\Users\russi\CLionProjects\metal-engine\src\engine\frame-builder\../passes/AbstractPass.h(35): warning C4458: declaration of 'vkCommandBuffer' hides class member -C:\Users\russi\CLionProjects\metal-engine\src\engine\frame-builder\../passes/AbstractPass.h(24): note: see declaration of 'Metal::AbstractPass::vkCommandBuffer' -C:\Users\russi\CLionProjects\metal-engine\src\engine\dto\AbstractComponent.h(14): warning C4458: declaration of 'entityId' hides class member -C:\Users\russi\CLionProjects\metal-engine\src\engine\dto\AbstractComponent.h(31): note: see declaration of 'Metal::AbstractComponent::entityId' -C:\Users\russi\CLionProjects\metal-engine\src\common\../editor/enum/EntryType.h(33): warning C4505: 'Metal::EntryType::GetDTO': unreferenced function with internal linkage has been removed -[29/44] Building CXX object CMakeFiles\metal_engine.dir\src\editor\panel\NotificationsPanel.cpp.obj -C:\Users\russi\CLionProjects\metal-engine\src\editor\panel\../util/UIUtil.h(48): warning C4244: 'initializing': conversion from 'int' to 'float', possible loss of data -C:\Users\russi\CLionProjects\metal-engine\src\editor\panel\../util/UIUtil.h(48): warning C4244: 'initializing': conversion from 'int' to 'const float', possible loss of data -C:\Users\russi\CLionProjects\metal-engine\src\engine\dto/GlobalDataUBO.h(14): warning C4324: 'Metal::GlobalDataUBO': structure was padded due to alignment specifier -C:\Users\russi\CLionProjects\metal-engine\src\engine\dto/GlobalDataUBO.h(15): warning C4324: 'Metal::GlobalDataUBO': structure was padded due to alignment specifier -C:\Users\russi\CLionProjects\metal-engine\src\engine\frame-builder\../passes/AbstractPass.h(35): warning C4458: declaration of 'vkCommandBuffer' hides class member -C:\Users\russi\CLionProjects\metal-engine\src\engine\frame-builder\../passes/AbstractPass.h(24): note: see declaration of 'Metal::AbstractPass::vkCommandBuffer' -C:\Users\russi\CLionProjects\metal-engine\src\editor\util\../enum/EntryType.h(33): warning C4505: 'Metal::EntryType::GetDTO': unreferenced function with internal linkage has been removed -C:\Users\russi\CLionProjects\metal-engine\src\editor\panel\../util/UIUtil.h(40): warning C4505: 'Metal::UIUtil::ButtonSimple': unreferenced function with internal linkage has been removed -C:\Users\russi\CLionProjects\metal-engine\src\editor\panel\../util/UIUtil.h(46): warning C4505: 'Metal::UIUtil::RenderOption': unreferenced function with internal linkage has been removed -C:\Users\russi\CLionProjects\metal-engine\src\editor\panel\../util/UIUtil.h(52): warning C4505: 'Metal::UIUtil::RenderTooltip': unreferenced function with internal linkage has been removed -C:\Users\russi\CLionProjects\metal-engine\src\editor\panel\../util/UIUtil.h(60): warning C4505: 'Metal::UIUtil::LargeSpacing': unreferenced function with internal linkage has been removed -C:\Users\russi\CLionProjects\metal-engine\src\editor\panel\../util/UIUtil.h(66): warning C4505: 'Metal::UIUtil::Spacing': unreferenced function with internal linkage has been removed -C:\Users\russi\CLionProjects\metal-engine\src\editor\panel\../util/UIUtil.h(72): warning C4505: 'Metal::UIUtil::DynamicSpacing': unreferenced function with internal linkage has been removed -C:\Users\russi\CLionProjects\metal-engine\src\editor\panel\../util/UIUtil.h(102): warning C4505: 'Metal::UIUtil::DrawVec2Control': unreferenced function with internal linkage has been removed -C:\Users\russi\CLionProjects\metal-engine\src\editor\panel\../util/UIUtil.h(119): warning C4505: 'Metal::UIUtil::DrawVec3Control': unreferenced function with internal linkage has been removed -C:\Users\russi\CLionProjects\metal-engine\src\editor\panel\../util/UIUtil.h(159): warning C4505: 'Metal::UIUtil::DrawQuatControl': unreferenced function with internal linkage has been removed -C:\Users\russi\CLionProjects\metal-engine\src\editor\panel\../util/UIUtil.h(163): warning C4505: 'Metal::UIUtil::GetKeyChordName': unreferenced function with internal linkage has been removed -C:\Users\russi\CLionProjects\metal-engine\src\editor\panel\../util/UIUtil.h(179): warning C4505: 'Metal::UIUtil::GetEntryIcon': unreferenced function with internal linkage has been removed -[30/44] Building CXX object CMakeFiles\metal_engine...ditor\dock-spaces\viewport\EngineFramePanel.cpp.obj -C:\Users\russi\CLionProjects\metal-engine\src\engine\frame-builder\../passes/AbstractPass.h(35): warning C4458: declaration of 'vkCommandBuffer' hides class member -C:\Users\russi\CLionProjects\metal-engine\src\engine\frame-builder\../passes/AbstractPass.h(24): note: see declaration of 'Metal::AbstractPass::vkCommandBuffer' -C:\Users\russi\CLionProjects\metal-engine\src\editor\dock-spaces\viewport\../../../engine/dto/GlobalDataUBO.h(14): warning C4324: 'Metal::GlobalDataUBO': structure was padded due to alignment specifier -C:\Users\russi\CLionProjects\metal-engine\src\editor\dock-spaces\viewport\../../../engine/dto/GlobalDataUBO.h(15): warning C4324: 'Metal::GlobalDataUBO': structure was padded due to alignment specifier -C:\Users\russi\CLionProjects\metal-engine\src\editor\dock-spaces\viewport\../../../engine/dto/LightData.h(11): warning C4324: 'Metal::LightData': structure was padded due to alignment specifier -C:\Users\russi\CLionProjects\metal-engine\src\editor\dock-spaces\viewport\../../../engine/dto/LightData.h(12): warning C4324: 'Metal::LightData': structure was padded due to alignment specifier -C:\Users\russi\CLionProjects\metal-engine\src\editor\dock-spaces\viewport\../../../engine/dto/VolumeData.h(11): warning C4324: 'Metal::VolumeData': structure was padded due to alignment specifier -C:\Users\russi\CLionProjects\metal-engine\src\editor\dock-spaces\viewport\../../../engine/dto/VolumeData.h(12): warning C4324: 'Metal::VolumeData': structure was padded due to alignment specifier -C:\Users\russi\CLionProjects\metal-engine\src\editor\dock-spaces\viewport\../../../engine/dto/MeshMetadata.h(13): warning C4324: 'Metal::MeshMetadata': structure was padded due to alignment specifier -C:\Users\russi\CLionProjects\metal-engine\src\engine\passes\impl\../../dto/PostProcessingPushConstant.h(9): warning C4324: 'Metal::PostProcessingPushConstant': structure was padded due to alignment specifier -C:\Users\russi\CLionProjects\metal-engine\src\engine\passes\impl\../../dto/PostProcessingPushConstant.h(10): warning C4324: 'Metal::PostProcessingPushConstant': structure was padded due to alignment specifier -C:\Users\russi\CLionProjects\metal-engine\src\common\Inspectable.h(125): warning C4100: 'member': unreferenced parameter -C:\Users\russi\CLionProjects\metal-engine\src\common\../editor/enum/EntryType.h(33): warning C4505: 'Metal::EntryType::GetDTO': unreferenced function with internal linkage has been removed -[31/44] Building CXX object CMakeFiles\metal_engine.dir\src\engine\service\StreamingService.cpp.obj -C:\Users\russi\CLionProjects\metal-engine\src\engine\dto/GlobalDataUBO.h(14): warning C4324: 'Metal::GlobalDataUBO': structure was padded due to alignment specifier -C:\Users\russi\CLionProjects\metal-engine\src\engine\dto/GlobalDataUBO.h(15): warning C4324: 'Metal::GlobalDataUBO': structure was padded due to alignment specifier -C:\Users\russi\CLionProjects\metal-engine\src\engine\frame-builder\../passes/AbstractPass.h(35): warning C4458: declaration of 'vkCommandBuffer' hides class member -C:\Users\russi\CLionProjects\metal-engine\src\engine\frame-builder\../passes/AbstractPass.h(24): note: see declaration of 'Metal::AbstractPass::vkCommandBuffer' -C:\Users\russi\CLionProjects\metal-engine\src\common\Inspectable.h(125): warning C4100: 'member': unreferenced parameter -C:\Users\russi\CLionProjects\metal-engine\src\engine\service\../dto/TextureData.h(16): warning C4244: 'initializing': conversion from 'T' to 'int', possible loss of data - with - [ - T=float - ] -C:\Users\russi\CLionProjects\metal-engine\src\engine\service\../dto/TextureData.h(16): warning C4244: 'initializing': conversion from 'T' to 'const int', possible loss of data - with - [ - T=float - ] -C:\Users\russi\CLionProjects\metal-engine\src\engine\service\../dto/TextureData.h(17): warning C4244: 'initializing': conversion from 'T' to 'int', possible loss of data - with - [ - T=float - ] -C:\Users\russi\CLionProjects\metal-engine\src\engine\service\../dto/TextureData.h(17): warning C4244: 'initializing': conversion from 'T' to 'const int', possible loss of data - with - [ - T=float - ] -C:\Users\russi\CLionProjects\metal-engine\src\engine\dto\AbstractComponent.h(14): warning C4458: declaration of 'entityId' hides class member -C:\Users\russi\CLionProjects\metal-engine\src\engine\dto\AbstractComponent.h(31): note: see declaration of 'Metal::AbstractComponent::entityId' -C:\Users\russi\CLionProjects\metal-engine\src\engine\service\../dto/PrimitiveComponent.h(20): warning C4305: 'initializing': truncation from 'double' to 'float' -C:\Users\russi\CLionProjects\metal-engine\src\common\../editor/enum/EntryType.h(33): warning C4505: 'Metal::EntryType::GetDTO': unreferenced function with internal linkage has been removed -[32/44] Building CXX object CMakeFiles\metal_engine.dir\src\engine\service\CameraService.cpp.obj -C:\Users\russi\CLionProjects\metal-engine\src\engine\dto\../../common/Inspectable.h(125): warning C4100: 'member': unreferenced parameter -C:\Users\russi\CLionProjects\metal-engine\src\engine\dto/GlobalDataUBO.h(14): warning C4324: 'Metal::GlobalDataUBO': structure was padded due to alignment specifier -C:\Users\russi\CLionProjects\metal-engine\src\engine\dto/GlobalDataUBO.h(15): warning C4324: 'Metal::GlobalDataUBO': structure was padded due to alignment specifier -C:\Users\russi\CLionProjects\metal-engine\src\engine\frame-builder\../passes/AbstractPass.h(35): warning C4458: declaration of 'vkCommandBuffer' hides class member -C:\Users\russi\CLionProjects\metal-engine\src\engine\frame-builder\../passes/AbstractPass.h(24): note: see declaration of 'Metal::AbstractPass::vkCommandBuffer' -C:\Users\russi\CLionProjects\metal-engine\src\common\../editor/enum/EntryType.h(33): warning C4505: 'Metal::EntryType::GetDTO': unreferenced function with internal linkage has been removed -[33/44] Building CXX object CMakeFiles\metal_engine.dir\src\engine\EngineContext.cpp.obj -C:\Users\russi\CLionProjects\metal-engine\src\engine\dto/GlobalDataUBO.h(14): warning C4324: 'Metal::GlobalDataUBO': structure was padded due to alignment specifier -C:\Users\russi\CLionProjects\metal-engine\src\engine\dto/GlobalDataUBO.h(15): warning C4324: 'Metal::GlobalDataUBO': structure was padded due to alignment specifier -C:\Users\russi\CLionProjects\metal-engine\src\engine\frame-builder\../passes/AbstractPass.h(35): warning C4458: declaration of 'vkCommandBuffer' hides class member -C:\Users\russi\CLionProjects\metal-engine\src\engine\frame-builder\../passes/AbstractPass.h(24): note: see declaration of 'Metal::AbstractPass::vkCommandBuffer' -C:\Users\russi\CLionProjects\metal-engine\src\engine\service\../dto/MeshMetadata.h(13): warning C4324: 'Metal::MeshMetadata': structure was padded due to alignment specifier -C:\Users\russi\CLionProjects\metal-engine\src\engine\service/RayTracingService.h(15): warning C4099: 'Metal::BufferInstance': type name first seen using 'struct' now seen using 'class' -C:\Users\russi\CLionProjects\metal-engine\src\engine\frame-builder\../resource/BufferInstance.h(14): note: see declaration of 'Metal::BufferInstance' -C:\Users\russi\CLionProjects\metal-engine\src\engine\service\../dto/LightData.h(11): warning C4324: 'Metal::LightData': structure was padded due to alignment specifier -C:\Users\russi\CLionProjects\metal-engine\src\engine\service\../dto/LightData.h(12): warning C4324: 'Metal::LightData': structure was padded due to alignment specifier -C:\Users\russi\CLionProjects\metal-engine\src\engine\service/LightService.h(49): warning C4267: 'return': conversion from 'size_t' to 'unsigned int', possible loss of data -C:\Users\russi\CLionProjects\metal-engine\src\engine\service\../dto/VolumeData.h(11): warning C4324: 'Metal::VolumeData': structure was padded due to alignment specifier -C:\Users\russi\CLionProjects\metal-engine\src\engine\service\../dto/VolumeData.h(12): warning C4324: 'Metal::VolumeData': structure was padded due to alignment specifier -C:\Users\russi\CLionProjects\metal-engine\src\engine\service/VolumeService.h(32): warning C4267: 'return': conversion from 'size_t' to 'unsigned int', possible loss of data -C:\Users\russi\CLionProjects\metal-engine\src\common\Inspectable.h(125): warning C4100: 'member': unreferenced parameter -C:\Users\russi\CLionProjects\metal-engine\src\engine\../editor/repository/EditorRepository.h(33): warning C4305: 'initializing': truncation from 'double' to 'float' -C:\Users\russi\CLionProjects\metal-engine\src\engine\dto\AbstractComponent.h(14): warning C4458: declaration of 'entityId' hides class member -C:\Users\russi\CLionProjects\metal-engine\src\engine\dto\AbstractComponent.h(31): note: see declaration of 'Metal::AbstractComponent::entityId' -C:\Users\russi\CLionProjects\metal-engine\src\common\../editor/enum/EntryType.h(33): warning C4505: 'Metal::EntryType::GetDTO': unreferenced function with internal linkage has been removed -[34/44] Building CXX object CMakeFiles\metal_engine.dir\src\engine\passes\impl\PostProcessingPass.cpp.obj -C:\Users\russi\CLionProjects\metal-engine\src\engine\passes\AbstractPass.h(35): warning C4458: declaration of 'vkCommandBuffer' hides class member -C:\Users\russi\CLionProjects\metal-engine\src\engine\passes\AbstractPass.h(24): note: see declaration of 'Metal::AbstractPass::vkCommandBuffer' -C:\Users\russi\CLionProjects\metal-engine\src\engine\passes\impl\../../dto/PostProcessingPushConstant.h(9): warning C4324: 'Metal::PostProcessingPushConstant': structure was padded due to alignment specifier -C:\Users\russi\CLionProjects\metal-engine\src\engine\passes\impl\../../dto/PostProcessingPushConstant.h(10): warning C4324: 'Metal::PostProcessingPushConstant': structure was padded due to alignment specifier -C:\Users\russi\CLionProjects\metal-engine\src\common\Inspectable.h(125): warning C4100: 'member': unreferenced parameter -C:\Users\russi\CLionProjects\metal-engine\src\common\../editor/enum/EntryType.h(33): warning C4505: 'Metal::EntryType::GetDTO': unreferenced function with internal linkage has been removed -[35/44] Building CXX object CMakeFiles\metal_engine.dir\src\engine\frame-builder\EngineFrame.cpp.obj -C:\Users\russi\CLionProjects\metal-engine\src\engine\frame-builder\../passes/AbstractPass.h(35): warning C4458: declaration of 'vkCommandBuffer' hides class member -C:\Users\russi\CLionProjects\metal-engine\src\engine\frame-builder\../passes/AbstractPass.h(24): note: see declaration of 'Metal::AbstractPass::vkCommandBuffer' -[36/44] Building CXX object CMakeFiles\metal_engine...src\engine\frame-builder\EngineFrameBuilder.cpp.obj -FAILED: CMakeFiles/metal_engine.dir/src/engine/frame-builder/EngineFrameBuilder.cpp.obj -C:\PROGRA~1\MICROS~2\18\COMMUN~1\VC\Tools\MSVC\1450~1.357\bin\Hostx64\x64\cl.exe /nologo /TP -DBOOST_IOSTREAMS_DYN_LINK -DBOOST_IOSTREAMS_NO_LIB -DBOOST_RANDOM_DYN_LINK -DBOOST_RANDOM_NO_LIB -DFMT_SHARED -DGLFW_DLL -DIMATH_DLL -DIMGUI_ENABLE_FREETYPE -DMESHOPTIMIZER_API=__declspec(dllimport) -DNFD_SHARED -DNOMINMAX -DOPENVDB_ABI_VERSION_NUMBER=12 -DOPENVDB_DLL -DOPENVDB_USE_DELAYED_LOADING -DSPDLOG_COMPILED_LIB -DSPDLOG_FMT_EXTERNAL -DSPDLOG_SHARED_LIB -DTBB_USE_DEBUG -D_WIN32 -IC:\Users\russi\CLionProjects\metal-engine\dependencies\vk-bootstrap\src -external:IC:\Users\russi\CLionProjects\metal-engine\cmake-build-debug-visual-studio\vcpkg_installed\x64-windows\include -external:IC:\Users\russi\CLionProjects\metal-engine\cmake-build-debug-visual-studio\vcpkg_installed\x64-windows\include\vma -external:IC:\Users\russi\CLionProjects\metal-engine\cmake-build-debug-visual-studio\vcpkg_installed\x64-windows\include\Imath -external:W0 /DWIN32 /D_WINDOWS /EHsc -DVK_PROTOTYPES /Ob0 /Od /RTC1 -std:c++20 -MDd -Zi /W4 /wd4251 /wd4275 /utf-8 /EHsc /showIncludes @CMakeFiles\metal_engine.dir\src\engine\frame-builder\EngineFrameBuilder.cpp.obj.modmap /FoCMakeFiles\metal_engine.dir\src\engine\frame-builder\EngineFrameBuilder.cpp.obj /FdCMakeFiles\metal_engine.dir\ /FS -c C:\Users\russi\CLionProjects\metal-engine\src\engine\frame-builder\EngineFrameBuilder.cpp -C:\Users\russi\CLionProjects\metal-engine\src\engine\frame-builder\../passes/AbstractPass.h(35): warning C4458: declaration of 'vkCommandBuffer' hides class member -C:\Users\russi\CLionProjects\metal-engine\src\engine\frame-builder\../passes/AbstractPass.h(24): note: see declaration of 'Metal::AbstractPass::vkCommandBuffer' -C:\Users\russi\CLionProjects\metal-engine\src\engine\dto/GlobalDataUBO.h(14): warning C4324: 'Metal::GlobalDataUBO': structure was padded due to alignment specifier -C:\Users\russi\CLionProjects\metal-engine\src\engine\dto/GlobalDataUBO.h(15): warning C4324: 'Metal::GlobalDataUBO': structure was padded due to alignment specifier -C:\Program Files\Microsoft Visual Studio\18\Community\VC\Tools\MSVC\14.50.35717\include\xmemory(734): error C2672: 'std::construct_at': no matching overloaded function found -C:\Program Files\Microsoft Visual Studio\18\Community\VC\Tools\MSVC\14.50.35717\include\xutility(507): note: could be '_Ty *std::construct_at(_Ty *const ,_Types ...) noexcept()' -C:\Program Files\Microsoft Visual Studio\18\Community\VC\Tools\MSVC\14.50.35717\include\xmemory(734): note: the associated constraints are not satisfied -C:\Program Files\Microsoft Visual Studio\18\Community\VC\Tools\MSVC\14.50.35717\include\xutility(505): note: 'std::unique_ptr>::unique_ptr(const std::unique_ptr> &)': attempting to reference a deleted function -C:\Program Files\Microsoft Visual Studio\18\Community\VC\Tools\MSVC\14.50.35717\include\memory(3504): note: see declaration of 'std::unique_ptr>::unique_ptr' -C:\Program Files\Microsoft Visual Studio\18\Community\VC\Tools\MSVC\14.50.35717\include\memory(3504): note: 'std::unique_ptr>::unique_ptr(const std::unique_ptr> &)': function was explicitly deleted -C:\Program Files\Microsoft Visual Studio\18\Community\VC\Tools\MSVC\14.50.35717\include\xutility(505): note: 'std::unique_ptr>::unique_ptr(const std::unique_ptr> &)': attempting to reference a deleted function -C:\Program Files\Microsoft Visual Studio\18\Community\VC\Tools\MSVC\14.50.35717\include\memory(3504): note: see declaration of 'std::unique_ptr>::unique_ptr' -C:\Program Files\Microsoft Visual Studio\18\Community\VC\Tools\MSVC\14.50.35717\include\memory(3504): note: 'std::unique_ptr>::unique_ptr(const std::unique_ptr> &)': function was explicitly deleted -C:\Program Files\Microsoft Visual Studio\18\Community\VC\Tools\MSVC\14.50.35717\include\xmemory(734): note: the template instantiation context (the oldest one first) is -C:\Users\russi\CLionProjects\metal-engine\src\engine\frame-builder\EngineFrameBuilder.cpp(127): note: see reference to class template instantiation 'std::vector>,std::allocator>>>' being compiled -C:\Program Files\Microsoft Visual Studio\18\Community\VC\Tools\MSVC\14.50.35717\include\vector(745): note: while compiling class template member function 'std::vector>,std::allocator>>>::vector(const std::vector>,std::allocator>>> &)' -C:\Users\russi\CLionProjects\metal-engine\src\engine\frame-builder\EngineFrameBuilder.cpp(132): note: see the first reference to 'std::vector>,std::allocator>>>::vector' in 'Metal::EngineFrameBuilder::build' -C:\Program Files\Microsoft Visual Studio\18\Community\VC\Tools\MSVC\14.50.35717\include\vector(749): note: see reference to function template instantiation 'void std::vector>,std::allocator>>>::_Construct_n>*const &,std::unique_ptr>*const &>(const unsigned __int64,std::unique_ptr> *const &,std::unique_ptr> *const &)' being compiled -C:\Program Files\Microsoft Visual Studio\18\Community\VC\Tools\MSVC\14.50.35717\include\vector(2120): note: see reference to function template instantiation 'std::unique_ptr> *std::_Uninitialized_copy>*,std::unique_ptr>*,std::allocator>>>(_InIt,_Se,std::unique_ptr> *,_Alloc &)' being compiled - with - [ - _InIt=std::unique_ptr> *, - _Se=std::unique_ptr> *, - _Alloc=std::allocator>> - ] -C:\Program Files\Microsoft Visual Studio\18\Community\VC\Tools\MSVC\14.50.35717\include\xmemory(1922): note: see reference to function template instantiation 'void std::_Uninitialized_backout_al>>>::_Emplace_back>&>(std::unique_ptr> &)' being compiled -C:\Program Files\Microsoft Visual Studio\18\Community\VC\Tools\MSVC\14.50.35717\include\xmemory(1864): note: see reference to function template instantiation 'void std::_Default_allocator_traits<_Alloc>::construct<_Ty,std::unique_ptr>&>(_Alloc &,_Objty *const ,std::unique_ptr> &)' being compiled - with - [ - _Alloc=std::allocator>>, - _Ty=std::unique_ptr>, - _Objty=std::unique_ptr> - ] -[37/44] Building CXX object CMakeFiles\metal_engine.dir\src\engine\enum\ComponentType.cpp.obj -C:\Users\russi\CLionProjects\metal-engine\src\engine\dto/GlobalDataUBO.h(14): warning C4324: 'Metal::GlobalDataUBO': structure was padded due to alignment specifier -C:\Users\russi\CLionProjects\metal-engine\src\engine\dto/GlobalDataUBO.h(15): warning C4324: 'Metal::GlobalDataUBO': structure was padded due to alignment specifier -C:\Users\russi\CLionProjects\metal-engine\src\engine\frame-builder\../passes/AbstractPass.h(35): warning C4458: declaration of 'vkCommandBuffer' hides class member -C:\Users\russi\CLionProjects\metal-engine\src\engine\frame-builder\../passes/AbstractPass.h(24): note: see declaration of 'Metal::AbstractPass::vkCommandBuffer' -C:\Users\russi\CLionProjects\metal-engine\src\common\Inspectable.h(125): warning C4100: 'member': unreferenced parameter -C:\Users\russi\CLionProjects\metal-engine\src\engine\service\../dto/MeshMetadata.h(13): warning C4324: 'Metal::MeshMetadata': structure was padded due to alignment specifier -C:\Users\russi\CLionProjects\metal-engine\src\engine\enum\../service/RayTracingService.h(15): warning C4099: 'Metal::BufferInstance': type name first seen using 'struct' now seen using 'class' -C:\Users\russi\CLionProjects\metal-engine\src\engine\frame-builder\../resource/BufferInstance.h(14): note: see declaration of 'Metal::BufferInstance' -C:\Users\russi\CLionProjects\metal-engine\src\engine\dto\AbstractComponent.h(14): warning C4458: declaration of 'entityId' hides class member -C:\Users\russi\CLionProjects\metal-engine\src\engine\dto\AbstractComponent.h(31): note: see declaration of 'Metal::AbstractComponent::entityId' -C:\Users\russi\CLionProjects\metal-engine\src\engine\enum\../dto/PrimitiveComponent.h(20): warning C4305: 'initializing': truncation from 'double' to 'float' -C:\Users\russi\CLionProjects\metal-engine\src\common\../editor/enum/EntryType.h(33): warning C4505: 'Metal::EntryType::GetDTO': unreferenced function with internal linkage has been removed -[38/44] Building CXX object CMakeFiles\metal_engine...engine\passes\impl\TemporalAccumulationPass.cpp.obj -C:\Users\russi\CLionProjects\metal-engine\src\engine\passes\AbstractPass.h(35): warning C4458: declaration of 'vkCommandBuffer' hides class member -C:\Users\russi\CLionProjects\metal-engine\src\engine\passes\AbstractPass.h(24): note: see declaration of 'Metal::AbstractPass::vkCommandBuffer' -[39/44] Building CXX object CMakeFiles\metal_engine.dir\src\main.cpp.obj -C:\Users\russi\CLionProjects\metal-engine\src\editor\dto\../../common//Inspectable.h(125): warning C4100: 'member': unreferenced parameter -C:\Users\russi\CLionProjects\metal-engine\src\editor\service\../../common/AbstractImporter.h(19): warning C4100: 'stopToken': unreferenced parameter -C:\Users\russi\CLionProjects\metal-engine\src\editor\service\../../common/AbstractImporter.h(18): warning C4100: 'settings': unreferenced parameter -C:\Users\russi\CLionProjects\metal-engine\src\editor\service\../../common/AbstractImporter.h(17): warning C4100: 'pathToFile': unreferenced parameter -C:\Users\russi\CLionProjects\metal-engine\src\editor\service\../../common/AbstractImporter.h(17): warning C4100: 'targetDir': unreferenced parameter -C:\Users\russi\CLionProjects\metal-engine\src\editor/service/TextureImporterService.h(8): warning C4099: 'Metal::DirectoryService': type name first seen using 'struct' now seen using 'class' -C:\Users\russi\CLionProjects\metal-engine\src\core/DirectoryService.h(11): note: see declaration of 'Metal::DirectoryService' -C:\Users\russi\CLionProjects\metal-engine\src\editor/service/VoxelImporterService.h(9): warning C4099: 'Metal::DirectoryService': type name first seen using 'struct' now seen using 'class' -C:\Users\russi\CLionProjects\metal-engine\src\core/DirectoryService.h(11): note: see declaration of 'Metal::DirectoryService' -C:\Users\russi\CLionProjects\metal-engine\src\editor/repository/EditorRepository.h(33): warning C4305: 'initializing': truncation from 'double' to 'float' -C:\Users\russi\CLionProjects\metal-engine\src\engine/repository/WorldRepository.h(15): warning C4099: 'Metal::DirectoryService': type name first seen using 'struct' now seen using 'class' -C:\Users\russi\CLionProjects\metal-engine\src\core/DirectoryService.h(11): note: see declaration of 'Metal::DirectoryService' -C:\Users\russi\CLionProjects\metal-engine\src\engine/service/CommandBufferRecorderService.h(10): warning C4100: 'resource': unreferenced parameter -C:\Users\russi\CLionProjects\metal-engine\src\engine\service\../dto/LightData.h(11): warning C4324: 'Metal::LightData': structure was padded due to alignment specifier -C:\Users\russi\CLionProjects\metal-engine\src\engine\service\../dto/LightData.h(12): warning C4324: 'Metal::LightData': structure was padded due to alignment specifier -C:\Users\russi\CLionProjects\metal-engine\src\engine/service/LightService.h(49): warning C4267: 'return': conversion from 'size_t' to 'unsigned int', possible loss of data -C:\Users\russi\CLionProjects\metal-engine\src\engine/service/MeshService.h(14): warning C4099: 'Metal::DirectoryService': type name first seen using 'struct' now seen using 'class' -C:\Users\russi\CLionProjects\metal-engine\src\core/DirectoryService.h(11): note: see declaration of 'Metal::DirectoryService' -C:\Users\russi\CLionProjects\metal-engine\src\engine\service\../dto/MeshMetadata.h(13): warning C4324: 'Metal::MeshMetadata': structure was padded due to alignment specifier -C:\Users\russi\CLionProjects\metal-engine\src\engine/service/RayTracingService.h(15): warning C4099: 'Metal::BufferInstance': type name first seen using 'struct' now seen using 'class' -C:\Users\russi\CLionProjects\metal-engine\src\engine\service\../resource/BufferInstance.h(14): note: see declaration of 'Metal::BufferInstance' -C:\Users\russi\CLionProjects\metal-engine\src\engine/service/ShaderService.h(10): warning C4099: 'Metal::DirectoryService': type name first seen using 'struct' now seen using 'class' -C:\Users\russi\CLionProjects\metal-engine\src\core/DirectoryService.h(11): note: see declaration of 'Metal::DirectoryService' -C:\Users\russi\CLionProjects\metal-engine\src\engine\service\../dto/TextureData.h(16): warning C4244: 'initializing': conversion from 'T' to 'int', possible loss of data - with - [ - T=float - ] -C:\Users\russi\CLionProjects\metal-engine\src\engine\service\../dto/TextureData.h(16): warning C4244: 'initializing': conversion from 'T' to 'const int', possible loss of data - with - [ - T=float - ] -C:\Users\russi\CLionProjects\metal-engine\src\engine\service\../dto/TextureData.h(17): warning C4244: 'initializing': conversion from 'T' to 'int', possible loss of data - with - [ - T=float - ] -C:\Users\russi\CLionProjects\metal-engine\src\engine\service\../dto/TextureData.h(17): warning C4244: 'initializing': conversion from 'T' to 'const int', possible loss of data - with - [ - T=float - ] -C:\Users\russi\CLionProjects\metal-engine\src\engine/service/TextureService.h(17): warning C4099: 'Metal::DirectoryService': type name first seen using 'struct' now seen using 'class' -C:\Users\russi\CLionProjects\metal-engine\src\core/DirectoryService.h(11): note: see declaration of 'Metal::DirectoryService' -C:\Users\russi\CLionProjects\metal-engine\src\engine\service\../dto/VolumeData.h(11): warning C4324: 'Metal::VolumeData': structure was padded due to alignment specifier -C:\Users\russi\CLionProjects\metal-engine\src\engine\service\../dto/VolumeData.h(12): warning C4324: 'Metal::VolumeData': structure was padded due to alignment specifier -C:\Users\russi\CLionProjects\metal-engine\src\engine/service/VolumeService.h(32): warning C4267: 'return': conversion from 'size_t' to 'unsigned int', possible loss of data -C:\Users\russi\CLionProjects\metal-engine\src\engine\dto/GlobalDataUBO.h(14): warning C4324: 'Metal::GlobalDataUBO': structure was padded due to alignment specifier -C:\Users\russi\CLionProjects\metal-engine\src\engine\dto/GlobalDataUBO.h(15): warning C4324: 'Metal::GlobalDataUBO': structure was padded due to alignment specifier -C:\Users\russi\CLionProjects\metal-engine\src\engine\frame-builder\../passes/AbstractPass.h(35): warning C4458: declaration of 'vkCommandBuffer' hides class member -C:\Users\russi\CLionProjects\metal-engine\src\engine\frame-builder\../passes/AbstractPass.h(24): note: see declaration of 'Metal::AbstractPass::vkCommandBuffer' -C:\Users\russi\CLionProjects\metal-engine\src\common\../editor/enum/EntryType.h(33): warning C4505: 'Metal::EntryType::GetDTO': unreferenced function with internal linkage has been removed -C:\Users\russi\CLionProjects\metal-engine\src\editor\service\../enum/NotificationSeverity.h(14): warning C4505: 'Metal::NotificationSeverities::GetIcon': unreferenced function with internal linkage has been removed -C:\Users\russi\CLionProjects\metal-engine\src\editor\service\../enum/NotificationSeverity.h(26): warning C4505: 'Metal::NotificationSeverities::GetColor': unreferenced function with internal linkage has been removed -[40/44] Building CXX object CMakeFiles\metal_engine.dir\src\engine\passes\impl\SpatialFilterPass.cpp.obj -C:\Users\russi\CLionProjects\metal-engine\src\engine\passes\AbstractPass.h(35): warning C4458: declaration of 'vkCommandBuffer' hides class member -C:\Users\russi\CLionProjects\metal-engine\src\engine\passes\AbstractPass.h(24): note: see declaration of 'Metal::AbstractPass::vkCommandBuffer' -[41/44] Building CXX object CMakeFiles\metal_engine.dir\src\engine\service\RayTracingService.cpp.obj -C:\Users\russi\CLionProjects\metal-engine\src\engine\service\../dto/MeshMetadata.h(13): warning C4324: 'Metal::MeshMetadata': structure was padded due to alignment specifier -C:\Users\russi\CLionProjects\metal-engine\src\engine\service\../resource/BufferInstance.h(14): warning C4099: 'Metal::BufferInstance': type name first seen using 'class' now seen using 'struct' -C:\Users\russi\CLionProjects\metal-engine\src\engine\service\../resource/BufferInstance.h(14): note: see declaration of 'Metal::BufferInstance' -C:\Users\russi\CLionProjects\metal-engine\src\engine\dto\../../common/Inspectable.h(125): warning C4100: 'member': unreferenced parameter -C:\Users\russi\CLionProjects\metal-engine\src\engine\dto\AbstractComponent.h(14): warning C4458: declaration of 'entityId' hides class member -C:\Users\russi\CLionProjects\metal-engine\src\engine\dto\AbstractComponent.h(31): note: see declaration of 'Metal::AbstractComponent::entityId' -C:\Users\russi\CLionProjects\metal-engine\src\engine\service\../dto/PrimitiveComponent.h(20): warning C4305: 'initializing': truncation from 'double' to 'float' -C:\Users\russi\CLionProjects\metal-engine\src\engine\dto/GlobalDataUBO.h(14): warning C4324: 'Metal::GlobalDataUBO': structure was padded due to alignment specifier -C:\Users\russi\CLionProjects\metal-engine\src\engine\dto/GlobalDataUBO.h(15): warning C4324: 'Metal::GlobalDataUBO': structure was padded due to alignment specifier -C:\Users\russi\CLionProjects\metal-engine\src\engine\frame-builder\../passes/AbstractPass.h(35): warning C4458: declaration of 'vkCommandBuffer' hides class member -C:\Users\russi\CLionProjects\metal-engine\src\engine\frame-builder\../passes/AbstractPass.h(24): note: see declaration of 'Metal::AbstractPass::vkCommandBuffer' -C:\Users\russi\CLionProjects\metal-engine\src\engine\service\RayTracingService.cpp(153): warning C4189: 'vulkan': local variable is initialized but not referenced -C:\Users\russi\CLionProjects\metal-engine\src\engine\service\RayTracingService.cpp(409): warning C4189: 'vulkan': local variable is initialized but not referenced -C:\Users\russi\CLionProjects\metal-engine\src\common\../editor/enum/EntryType.h(33): warning C4505: 'Metal::EntryType::GetDTO': unreferenced function with internal linkage has been removed -[42/44] Building CXX object CMakeFiles\metal_engine.dir\src\core\FrameService.cpp.obj -C:\Users\russi\CLionProjects\metal-engine\src\engine\dto/GlobalDataUBO.h(14): warning C4324: 'Metal::GlobalDataUBO': structure was padded due to alignment specifier -C:\Users\russi\CLionProjects\metal-engine\src\engine\dto/GlobalDataUBO.h(15): warning C4324: 'Metal::GlobalDataUBO': structure was padded due to alignment specifier -C:\Users\russi\CLionProjects\metal-engine\src\engine\frame-builder\../passes/AbstractPass.h(35): warning C4458: declaration of 'vkCommandBuffer' hides class member -C:\Users\russi\CLionProjects\metal-engine\src\engine\frame-builder\../passes/AbstractPass.h(24): note: see declaration of 'Metal::AbstractPass::vkCommandBuffer' -C:\Users\russi\CLionProjects\metal-engine\src\core\FrameService.cpp(26): warning C4458: declaration of 'panel' hides class member -C:\Users\russi\CLionProjects\metal-engine\src\core\FrameService.h(19): note: see declaration of 'Metal::FrameService::panel' -[43/44] Building CXX object CMakeFiles\metal_engine.dir\src\engine\service\VolumeService.cpp.obj -C:\Users\russi\CLionProjects\metal-engine\src\engine\service\../dto/VolumeData.h(11): warning C4324: 'Metal::VolumeData': structure was padded due to alignment specifier -C:\Users\russi\CLionProjects\metal-engine\src\engine\service\../dto/VolumeData.h(12): warning C4324: 'Metal::VolumeData': structure was padded due to alignment specifier -C:\Users\russi\CLionProjects\metal-engine\src\engine\service\VolumeService.h(32): warning C4267: 'return': conversion from 'size_t' to 'unsigned int', possible loss of data -C:\Users\russi\CLionProjects\metal-engine\src\engine\dto\../../common/Inspectable.h(125): warning C4100: 'member': unreferenced parameter -C:\Users\russi\CLionProjects\metal-engine\src\engine\dto\AbstractComponent.h(14): warning C4458: declaration of 'entityId' hides class member -C:\Users\russi\CLionProjects\metal-engine\src\engine\dto\AbstractComponent.h(31): note: see declaration of 'Metal::AbstractComponent::entityId' -C:\Users\russi\CLionProjects\metal-engine\src\engine\dto/GlobalDataUBO.h(14): warning C4324: 'Metal::GlobalDataUBO': structure was padded due to alignment specifier -C:\Users\russi\CLionProjects\metal-engine\src\engine\dto/GlobalDataUBO.h(15): warning C4324: 'Metal::GlobalDataUBO': structure was padded due to alignment specifier -C:\Users\russi\CLionProjects\metal-engine\src\engine\frame-builder\../passes/AbstractPass.h(35): warning C4458: declaration of 'vkCommandBuffer' hides class member -C:\Users\russi\CLionProjects\metal-engine\src\engine\frame-builder\../passes/AbstractPass.h(24): note: see declaration of 'Metal::AbstractPass::vkCommandBuffer' -C:\Users\russi\CLionProjects\metal-engine\src\common\../editor/enum/EntryType.h(33): warning C4505: 'Metal::EntryType::GetDTO': unreferenced function with internal linkage has been removed -ninja: build stopped: subcommand failed. \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 9d6aebeb..82d1aa80 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,293 +4,14 @@ project(metal_engine CXX) set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DVK_PROTOTYPES") -add_executable( - metal_engine - src/main.cpp - src/editor/EditorPanel.cpp - src/editor/EditorPanel.h - src/engine/EngineContext.cpp - src/engine/EngineContext.h - src/core/vulkan/VulkanUtils.cpp - src/core/vulkan/VulkanUtils.h - src/core/vulkan/VulkanContext.cpp - src/core/vulkan/VulkanContext.h - src/core/glfw/GLFWContext.cpp - src/core/glfw/GLFWContext.h - src/core/gui/GuiContext.cpp - src/core/gui/GuiContext.h - src/editor/dock-spaces/viewport/ViewportPanel.cpp - src/editor/dock-spaces/viewport/ViewportPanel.h - src/editor/dock-spaces/viewport/EngineFramePanel.cpp - src/editor/dock-spaces/viewport/EngineFramePanel.h - src/editor/dock-spaces/docks/AbstractDockPanel.h - src/ApplicationContext.cpp - src/ApplicationContext.h - src/editor/abstract/AbstractPanel.h - src/editor/abstract/AbstractPanel.cpp - src/common/ISync.h - src/engine/service/CameraService.cpp - src/engine/service/CameraService.h - src/engine/dto/Camera.h - src/editor/util/Util.h - src/common/Inspectable.h - src/common/Inspectable.cpp - src/common/InspectedField.h - src/editor/dock-spaces/inspector/InspectorPanel.cpp - src/editor/dock-spaces/inspector/InspectorPanel.h - src/editor/abstract/form/FormPanel.cpp - src/editor/abstract/form/FormPanel.h - src/editor/abstract/form/AccordionPanel.cpp - src/editor/abstract/form/AccordionPanel.h - src/common/FieldType.h - src/common/InspectableMember.h - src/editor/abstract/form/types/BooleanField.cpp - src/editor/abstract/form/types/BooleanField.h - src/editor/abstract/form/types/IntField.cpp - src/editor/abstract/form/types/IntField.h - src/editor/abstract/form/types/FloatField.cpp - src/editor/abstract/form/types/FloatField.h - src/editor/abstract/form/types/MethodField.cpp - src/editor/abstract/form/types/MethodField.h - src/editor/util/UIUtil.h - src/editor/dock-spaces/header/EditorHeaderPanel.cpp - src/editor/dock-spaces/header/EditorHeaderPanel.h - src/editor/dock-spaces/header/AsyncTaskPanel.cpp - src/editor/dock-spaces/header/AsyncTaskPanel.h - src/editor/dock-spaces/footer/EditorFooterPanel.cpp - src/editor/dock-spaces/footer/EditorFooterPanel.h - src/common/Icons.h - src/editor/service/DockService.cpp - src/editor/service/DockService.h - src/editor/dto/DockDTO.h - src/editor/dto/DockSpace.h - src/editor/dock-spaces/docks/DockSpacePanel.cpp - src/editor/dock-spaces/docks/DockSpacePanel.h - src/editor/dto/DockSpace.cpp - src/editor/service/ThemeService.cpp - src/editor/service/ThemeService.h - src/editor/repository/EditorRepository.h - src/editor/enum/engine-definitions.h - src/editor/dock-spaces/files/FilesPanel.cpp - src/editor/dock-spaces/files/FilesPanel.h - src/editor/dock-spaces/files/FilesListPanel.cpp - src/editor/dock-spaces/files/FilesListPanel.h - src/editor/dock-spaces/files/FilePreviewPanel.cpp - src/editor/dock-spaces/files/FilePreviewPanel.h - src/editor/dock-spaces/console/ConsolePanel.cpp - src/editor/dock-spaces/console/ConsolePanel.h - src/editor/dock-spaces/metrics/MetricsPanel.cpp - src/editor/dock-spaces/metrics/MetricsPanel.h - src/common/LoggerUtil.cpp - src/common/LoggerUtil.h - src/editor/dock-spaces/world/WorldPanel.cpp - src/editor/dock-spaces/world/WorldPanel.h - src/engine/resource/RuntimeResource.h - src/engine/service/ShaderService.cpp - src/engine/service/ShaderService.h - src/engine/dto/ShaderModule.cpp - src/engine/dto/ShaderModule.h - src/engine/passes/AbstractRenderPass.cpp - src/engine/passes/AbstractRenderPass.h - src/common/AbstractResourceService.h - src/engine/resource/FrameBufferAttachment.h - src/engine/service/FrameBufferService.cpp - src/engine/service/FrameBufferService.h - src/engine/resource/FrameBufferInstance.h - src/engine/service/PipelineService.cpp - src/engine/service/PipelineService.h - src/engine/resource/PipelineInstance.h - src/engine/service/BufferService.cpp - src/engine/service/BufferService.h - src/engine/service/DescriptorSetService.cpp - src/engine/service/DescriptorSetService.h - src/engine/dto/DescriptorInstance.h - src/engine/dto/GlobalDataUBO.h - src/engine/repository/RuntimeRepository.h - src/engine/resource/BufferInstance.cpp - src/engine/resource/BufferInstance.h - src/engine/service/MeshService.cpp - src/engine/service/MeshService.h - src/engine/dto/MeshData.h - src/engine/resource/MeshInstance.h - src/common/FilesUtil.h - src/editor/dto/FSEntry.h - src/editor/enum/EntryType.h - src/editor/dock-spaces/files/FilesContext.h - src/common/FileDialogUtil.h - src/editor/dock-spaces/files/FilesHeaderPanel.cpp - src/editor/dock-spaces/files/FilesHeaderPanel.h - src/editor/service/MaterialImporterService.cpp - src/editor/service/MaterialImporterService.h - src/editor/service/MeshImporterService.cpp - src/editor/service/MeshImporterService.h - src/editor/service/SceneImporterService.cpp - src/editor/service/SceneImporterService.h - src/common/AbstractImporter.h - src/editor/service/TextureImporterService.cpp - src/editor/service/TextureImporterService.h - src/editor/dto/EntryMetadata.h - src/engine/dto/TextureData.h - src/engine/service/TextureService.cpp - src/engine/service/TextureService.h - src/editor/service/FilesService.cpp - src/editor/service/FilesService.h - src/editor/service/FileImporterService.cpp - src/editor/service/FileImporterService.h - src/editor/dock-spaces/files/FilesContext.cpp - src/engine/dto/VertexData.h - src/editor/dock-spaces/viewport/CameraPositionPanel.cpp - src/editor/dock-spaces/viewport/CameraPositionPanel.h - src/editor/passes/GridPass.cpp - src/editor/passes/GridPass.h - src/engine/passes/CommandBufferRecorder.cpp - src/engine/passes/CommandBufferRecorder.h - src/engine/dto/Camera.cpp - src/engine/repository/WorldRepository.cpp - src/engine/repository/WorldRepository.h - src/engine/dto/MetadataComponent.h - src/engine/enum/ComponentType.cpp - src/engine/enum/ComponentType.h - src/engine/dto/AbstractComponent.h - src/engine/dto/PrimitiveComponent.h - src/engine/dto/TransformComponent.h - src/editor/enum/ShadingMode.h - src/editor/dock-spaces/world/WorldHeaderPanel.cpp - src/editor/dock-spaces/world/WorldHeaderPanel.h - src/editor/service/SelectionService.cpp - src/editor/service/SelectionService.h - src/engine/dto/MetadataComponent.cpp - src/engine/dto/TransformComponent.cpp - src/engine/dto/PrimitiveComponent.cpp - src/editor/abstract/form/types/ResourceField.cpp - src/editor/abstract/form/types/ResourceField.h - src/editor/abstract/form/types/ColorField.cpp - src/editor/abstract/form/types/ColorField.h - src/editor/abstract/form/types/Vec4Field.cpp - src/editor/abstract/form/types/Vec4Field.h - src/editor/abstract/form/types/Vec3Field.cpp - src/editor/abstract/form/types/Vec3Field.h - src/editor/abstract/form/types/Vec2Field.cpp - src/editor/abstract/form/types/Vec2Field.h - src/editor/abstract/form/types/StringField.cpp - src/editor/abstract/form/types/StringField.h - src/editor/abstract/form/types/ResourceFilesPanel.h - src/editor/abstract/form/types/ResourceFilesPanel.cpp - src/engine/service/StreamingService.cpp - src/engine/service/StreamingService.h - src/engine/enum/ResourceType.h - src/editor/dock-spaces/viewport/GizmoPanel.cpp - src/editor/dock-spaces/viewport/GizmoPanel.h - src/editor/dock-spaces/viewport/ViewportHeaderPanel.cpp - src/editor/dock-spaces/viewport/ViewportHeaderPanel.h - src/editor/dock-spaces/viewport/GizmoSettingsPanel.cpp - src/editor/dock-spaces/viewport/GizmoSettingsPanel.h - src/editor/abstract/form/types/QuatField.cpp - src/editor/abstract/form/types/QuatField.h - src/engine/service/TransformService.cpp - src/engine/service/TransformService.h - src/engine/dto/BoundingBox.h - src/editor/dto/SparseVoxelOctreeBuilder.cpp - src/editor/dto/SparseVoxelOctreeBuilder.h - src/editor/dto/OctreeNode.cpp - src/editor/dto/OctreeNode.h - src/engine/dto/VoxelData.h - src/editor/dto/SceneData.h - src/engine/passes/impl/PostProcessingPass.cpp - src/engine/passes/impl/PostProcessingPass.h - src/engine/passes/impl/HWRayTracingPass.cpp - src/engine/passes/impl/HWRayTracingPass.h - src/engine/service/RayTracingService.cpp - src/engine/service/RayTracingService.h - src/engine/dto/PipelineBuilder.h - src/engine/resource/FrameBufferAttachment.cpp - src/engine/repository/EngineRepository.cpp - src/engine/repository/EngineRepository.h - src/common/serialization-definitions.h - src/editor/service/NotificationService.cpp - src/editor/service/NotificationService.h - src/editor/service/AsyncTaskService.cpp - src/editor/service/AsyncTaskService.h - src/editor/dto/Notification.h - src/editor/enum/NotificationSeverity.h - src/engine/dto/SparseVoxelOctreeData.h - src/editor/passes/SelectionOutlinePass.cpp - src/editor/passes/SelectionOutlinePass.h - src/editor/service/PickingService.cpp - src/editor/service/PickingService.h - src/engine/resource/SVOInstance.h - src/engine/dto/LightData.h - src/editor/passes/SelectionIDPass.cpp - src/editor/passes/SelectionIDPass.h - src/editor/repository/EditorRepository.cpp - src/editor/dto/GridPushConstant.h - src/engine/passes/AbstractComputePass.cpp - src/engine/passes/AbstractComputePass.h - src/engine/passes/AbstractPass.cpp - src/engine/passes/AbstractPass.h - src/engine/util/ImageUtils.h - src/engine/service/MaterialService.cpp - src/engine/service/MaterialService.h - src/engine/service/LightService.cpp - src/engine/service/LightService.h - src/engine/dto/VolumeComponent.cpp - src/engine/dto/VolumeComponent.h - src/engine/dto/DescriptorBinding.h - src/editor/dto/AsyncTask.h - src/editor/service/VoxelImporterService.cpp - src/editor/service/VoxelImporterService.h - src/engine/dto/VolumeData.h - src/engine/service/VoxelService.cpp - src/engine/service/VoxelService.h - src/common/ISerialize.cpp - src/editor/abstract/form/ChildPanel.cpp - src/editor/abstract/form/ChildPanel.h - src/editor/dto/SceneImportSettingsDTO.h - src/editor/panel/NotificationsPanel.cpp - src/editor/panel/NotificationsPanel.h - src/editor/panel/FileImportModalPanel.cpp - src/editor/panel/FileImportModalPanel.h - src/engine/frame-builder/EngineFrameBuilder.cpp - src/engine/frame-builder/EngineFrameBuilder.h - src/engine/frame-builder/EngineFrame.cpp - src/engine/frame-builder/EngineFrame.h - src/engine/frame-builder/structures/FramebufferBuilder.cpp - src/engine/frame-builder/structures/FramebufferBuilder.h - src/engine/frame-builder/structures/TextureBuilder.cpp - src/engine/frame-builder/structures/TextureBuilder.h - src/engine/frame-builder/structures/BufferBuilder.cpp - src/engine/frame-builder/structures/BufferBuilder.h - src/engine/frame-builder/structures/ResourceBuilder.h - src/engine/dto/PipelineBuilder.cpp - src/engine/service/DescriptorSetService.cpp - src/engine/frame-builder/structures/CommandBufferRecorderBuilder.cpp - src/engine/passes/impl/TemporalAccumulationPass.cpp - src/engine/passes/impl/TemporalAccumulationPass.h - src/engine/passes/impl/SpatialFilterPass.cpp - src/engine/passes/impl/SpatialFilterPass.h - src/engine/enum/ComponentType.cpp - src/editor/dto/SceneEntityData.h - src/editor/dock-spaces/repositories/RepositoriesPanel.cpp - src/editor/dock-spaces/repositories/RepositoriesPanel.h - src/engine/service/VolumeService.cpp - src/engine/service/VolumeService.h - src/common/IContextMember.h - src/common/IService.h - src/common/IRepository.h - src/common/IContextMember.cpp - src/core/DirectoryService.cpp - src/core/DirectoryService.h - src/common/IDisposable.h - src/core/FrameService.cpp - src/core/FrameService.h -) - +if (MSVC) + add_compile_options(/utf-8) +endif() # ------ LIBS find_package(glfw3 REQUIRED) find_package(glm REQUIRED) find_package(imgui REQUIRED) -find_package(spdlog CONFIG REQUIRED) find_package(nlohmann_json CONFIG REQUIRED) find_package(Vulkan) find_package(VulkanMemoryAllocator CONFIG REQUIRED) @@ -301,6 +22,7 @@ find_package(assimp CONFIG REQUIRED) find_package(meshoptimizer CONFIG REQUIRED) find_package(cereal CONFIG REQUIRED) find_package(OpenVDB CONFIG REQUIRED) +find_package(EnTT CONFIG REQUIRED) set(COMMON_LIBRARIES glfw @@ -315,24 +37,34 @@ set(COMMON_LIBRARIES glm::glm imgui::imgui imguizmo::imguizmo - spdlog::spdlog nlohmann_json::nlohmann_json + EnTT::EnTT glslang::glslang glslang::glslang-default-resource-limits glslang::SPVRemapper OpenVDB::openvdb ) -target_link_libraries(metal_engine PRIVATE ${COMMON_LIBRARIES}) + add_subdirectory(dependencies/vk-bootstrap) # ------ LIBS + +add_subdirectory(src) +enable_testing() +add_subdirectory(tests) + # ------ STATIC RESOURCES -file(COPY "${CMAKE_SOURCE_DIR}/resources" DESTINATION "${CMAKE_BINARY_DIR}/") +file(GLOB_RECURSE RESOURCE_FILES "resources/*") +add_custom_target(copy_resources ALL + COMMAND ${CMAKE_COMMAND} -E copy_directory + "${CMAKE_SOURCE_DIR}/resources" + "${CMAKE_BINARY_DIR}/resources" + DEPENDS ${RESOURCE_FILES} + COMMENT "Copying resources to build directory" +) # ------ STATIC RESOURCES # ------ VCPKG - -#set(CMAKE_TOOLCHAIN_FILE "Users/cafe/.vcpkg-clion/vcpkg/scripts/buildsystems/vcpkg.cmake") set(VCPKG_JSON_PATH "${CMAKE_CURRENT_SOURCE_DIR}/vcpkg.json") # Include vcpkg toolchain diff --git a/resources/shaders/tools/SelectedDot.frag b/resources/shaders/tools/SelectionOutline.frag similarity index 100% rename from resources/shaders/tools/SelectedDot.frag rename to resources/shaders/tools/SelectionOutline.frag diff --git a/src/ApplicationContext.cpp b/src/ApplicationContext.cpp index 84de4494..df32e882 100644 --- a/src/ApplicationContext.cpp +++ b/src/ApplicationContext.cpp @@ -1,5 +1,12 @@ #include "ApplicationContext.h" +#define STB_IMAGE_IMPLEMENTATION +#include "stb_image.h" +#define STB_IMAGE_WRITE_IMPLEMENTATION +#include "stb_image_write.h" +#define VMA_IMPLEMENTATION +#include + #include "common/serialization-definitions.h" #include "common/LoggerUtil.h" diff --git a/src/ApplicationContext.h b/src/ApplicationContext.h index 46c9dc6b..c4de96c2 100644 --- a/src/ApplicationContext.h +++ b/src/ApplicationContext.h @@ -1,5 +1,8 @@ #ifndef METAL_ENGINE_APPLICATIONCONTEXT_H #define METAL_ENGINE_APPLICATIONCONTEXT_H +#define GLM_FORCE_RADIANS +#define GLM_FORCE_DEPTH_ZERO_TO_ONE + #include #include #include diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 00000000..e2b3bc36 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,296 @@ +set(ENGINE_SOURCES + main.cpp + editor/EditorPanel.cpp + editor/EditorPanel.h + engine/EngineContext.cpp + engine/EngineContext.h + core/vulkan/VulkanUtils.cpp + core/vulkan/VulkanUtils.h + core/vulkan/VulkanContext.cpp + core/vulkan/VulkanContext.h + core/glfw/GLFWContext.cpp + core/glfw/GLFWContext.h + core/gui/GuiContext.cpp + core/gui/GuiContext.h + editor/dock-spaces/viewport/ViewportPanel.cpp + editor/dock-spaces/viewport/ViewportPanel.h + editor/dock-spaces/viewport/EngineFramePanel.cpp + editor/dock-spaces/viewport/EngineFramePanel.h + editor/dock-spaces/docks/AbstractDockPanel.h + ApplicationContext.cpp + ApplicationContext.h + editor/abstract/AbstractPanel.h + editor/abstract/AbstractPanel.cpp + common/ISync.h + engine/service/CameraService.cpp + engine/service/CameraService.h + engine/dto/Camera.h + editor/util/Util.h + common/Inspectable.h + common/Inspectable.cpp + common/InspectedField.h + editor/dock-spaces/inspector/InspectorPanel.cpp + editor/dock-spaces/inspector/InspectorPanel.h + editor/abstract/form/FormPanel.cpp + editor/abstract/form/FormPanel.h + editor/abstract/form/AccordionPanel.cpp + editor/abstract/form/AccordionPanel.h + common/FieldType.h + common/InspectableMember.h + editor/abstract/form/types/BooleanField.cpp + editor/abstract/form/types/BooleanField.h + editor/abstract/form/types/IntField.cpp + editor/abstract/form/types/IntField.h + editor/abstract/form/types/FloatField.cpp + editor/abstract/form/types/FloatField.h + editor/abstract/form/types/MethodField.cpp + editor/abstract/form/types/MethodField.h + editor/util/UIUtil.h + editor/dock-spaces/header/EditorHeaderPanel.cpp + editor/dock-spaces/header/EditorHeaderPanel.h + editor/dock-spaces/header/AsyncTaskPanel.cpp + editor/dock-spaces/header/AsyncTaskPanel.h + editor/dock-spaces/footer/EditorFooterPanel.cpp + editor/dock-spaces/footer/EditorFooterPanel.h + common/Icons.h + editor/service/DockService.cpp + editor/service/DockService.h + editor/dto/DockDTO.h + editor/dto/DockSpace.h + editor/dock-spaces/docks/DockSpacePanel.cpp + editor/dock-spaces/docks/DockSpacePanel.h + editor/dto/DockSpace.cpp + editor/service/ThemeService.cpp + editor/service/ThemeService.h + editor/repository/EditorRepository.h + editor/enum/engine-definitions.h + editor/dock-spaces/files/FilesPanel.cpp + editor/dock-spaces/files/FilesPanel.h + editor/dock-spaces/files/FilesListPanel.cpp + editor/dock-spaces/files/FilesListPanel.h + editor/dock-spaces/files/FilePreviewPanel.cpp + editor/dock-spaces/files/FilePreviewPanel.h + editor/dock-spaces/console/ConsolePanel.cpp + editor/dock-spaces/console/ConsolePanel.h + editor/dock-spaces/metrics/MetricsPanel.cpp + editor/dock-spaces/metrics/MetricsPanel.h + common/LoggerUtil.cpp + common/LoggerUtil.h + editor/dock-spaces/world/WorldPanel.cpp + editor/dock-spaces/world/WorldPanel.h + engine/resource/RuntimeResource.h + engine/service/ShaderService.cpp + engine/service/ShaderService.h + engine/dto/ShaderModule.cpp + engine/dto/ShaderModule.h + engine/passes/AbstractRenderPass.cpp + engine/passes/AbstractRenderPass.h + common/AbstractResourceService.h + engine/resource/FrameBufferAttachment.h + engine/service/FrameBufferService.cpp + engine/service/FrameBufferService.h + engine/resource/FrameBufferInstance.h + engine/service/PipelineService.cpp + engine/service/PipelineService.h + engine/resource/PipelineInstance.h + engine/service/BufferService.cpp + engine/service/BufferService.h + engine/service/DescriptorSetService.cpp + engine/service/DescriptorSetService.h + engine/dto/DescriptorInstance.h + engine/dto/GlobalDataUBO.h + engine/repository/RuntimeRepository.h + engine/resource/BufferInstance.cpp + engine/resource/BufferInstance.h + engine/service/MeshService.cpp + engine/service/MeshService.h + engine/dto/MeshData.h + engine/resource/MeshInstance.h + common/FilesUtil.h + editor/dto/FSEntry.h + editor/enum/EntryType.h + editor/dock-spaces/files/FilesContext.h + common/FileDialogUtil.h + editor/dock-spaces/files/FilesHeaderPanel.cpp + editor/dock-spaces/files/FilesHeaderPanel.h + editor/service/MaterialImporterService.cpp + editor/service/MaterialImporterService.h + editor/service/MeshImporterService.cpp + editor/service/MeshImporterService.h + editor/service/SceneImporterService.cpp + editor/service/SceneImporterService.h + common/AbstractImporter.h + editor/service/TextureImporterService.cpp + editor/service/TextureImporterService.h + editor/dto/EntryMetadata.h + engine/dto/TextureData.h + engine/service/TextureService.cpp + engine/service/TextureService.h + editor/service/FilesService.cpp + editor/service/FilesService.h + editor/service/FileImporterService.cpp + editor/service/FileImporterService.h + editor/dock-spaces/files/FilesContext.cpp + engine/dto/VertexData.h + editor/dock-spaces/viewport/CameraPositionPanel.cpp + editor/dock-spaces/viewport/CameraPositionPanel.h + editor/passes/GridPass.cpp + editor/passes/GridPass.h + engine/passes/CommandBufferRecorder.cpp + engine/passes/CommandBufferRecorder.h + engine/dto/Camera.cpp + engine/repository/WorldRepository.cpp + engine/repository/WorldRepository.h + engine/dto/MetadataComponent.h + engine/enum/ComponentType.cpp + engine/enum/ComponentType.h + engine/dto/AbstractComponent.h + engine/dto/PrimitiveComponent.h + engine/dto/TransformComponent.h + editor/enum/ShadingMode.h + editor/dock-spaces/world/WorldHeaderPanel.cpp + editor/dock-spaces/world/WorldHeaderPanel.h + editor/service/SelectionService.cpp + editor/service/SelectionService.h + engine/dto/MetadataComponent.cpp + engine/dto/TransformComponent.cpp + engine/dto/PrimitiveComponent.cpp + editor/abstract/form/types/ResourceField.cpp + editor/abstract/form/types/ResourceField.h + editor/abstract/form/types/ColorField.cpp + editor/abstract/form/types/ColorField.h + editor/abstract/form/types/Vec4Field.cpp + editor/abstract/form/types/Vec4Field.h + editor/abstract/form/types/Vec3Field.cpp + editor/abstract/form/types/Vec3Field.h + editor/abstract/form/types/Vec2Field.cpp + editor/abstract/form/types/Vec2Field.h + editor/abstract/form/types/StringField.cpp + editor/abstract/form/types/StringField.h + editor/abstract/form/types/ResourceFilesPanel.h + editor/abstract/form/types/ResourceFilesPanel.cpp + engine/service/StreamingService.cpp + engine/service/StreamingService.h + engine/enum/ResourceType.h + editor/dock-spaces/viewport/GizmoPanel.cpp + editor/dock-spaces/viewport/GizmoPanel.h + editor/dock-spaces/viewport/ViewportHeaderPanel.cpp + editor/dock-spaces/viewport/ViewportHeaderPanel.h + editor/dock-spaces/viewport/GizmoSettingsPanel.cpp + editor/dock-spaces/viewport/GizmoSettingsPanel.h + editor/abstract/form/types/QuatField.cpp + editor/abstract/form/types/QuatField.h + engine/service/TransformService.cpp + engine/service/TransformService.h + engine/dto/BoundingBox.h + editor/dto/SparseVoxelOctreeBuilder.cpp + editor/dto/SparseVoxelOctreeBuilder.h + editor/dto/OctreeNode.cpp + editor/dto/OctreeNode.h + engine/dto/VoxelData.h + editor/dto/SceneData.h + engine/passes/impl/PostProcessingPass.cpp + engine/passes/impl/PostProcessingPass.h + engine/passes/impl/HWRayTracingPass.cpp + engine/passes/impl/HWRayTracingPass.h + engine/service/RayTracingService.cpp + engine/service/RayTracingService.h + engine/dto/PipelineBuilder.h + engine/resource/FrameBufferAttachment.cpp + engine/repository/EngineRepository.cpp + engine/repository/EngineRepository.h + common/serialization-definitions.h + editor/service/NotificationService.cpp + editor/service/NotificationService.h + editor/service/AsyncTaskService.cpp + editor/service/AsyncTaskService.h + editor/dto/Notification.h + editor/enum/NotificationSeverity.h + engine/dto/SparseVoxelOctreeData.h + editor/passes/SelectionOutlinePass.cpp + editor/passes/SelectionOutlinePass.h + editor/service/PickingService.cpp + editor/service/PickingService.h + engine/resource/SVOInstance.h + engine/dto/LightData.h + editor/passes/SelectionIDPass.cpp + editor/passes/SelectionIDPass.h + editor/repository/EditorRepository.cpp + editor/dto/GridPushConstant.h + engine/passes/AbstractComputePass.cpp + engine/passes/AbstractComputePass.h + engine/passes/AbstractPass.cpp + engine/passes/AbstractPass.h + engine/util/ImageUtils.h + engine/service/MaterialService.cpp + engine/service/MaterialService.h + engine/service/LightService.cpp + engine/service/LightService.h + engine/dto/VolumeComponent.cpp + engine/dto/VolumeComponent.h + engine/dto/DescriptorBinding.h + editor/dto/AsyncTask.h + editor/service/VoxelImporterService.cpp + editor/service/VoxelImporterService.h + engine/dto/VolumeData.h + engine/service/VoxelService.cpp + engine/service/VoxelService.h + common/ISerialize.cpp + editor/abstract/form/ChildPanel.cpp + editor/abstract/form/ChildPanel.h + editor/dto/SceneImportSettingsDTO.h + editor/panel/NotificationsPanel.cpp + editor/panel/NotificationsPanel.h + editor/panel/FileImportModalPanel.cpp + editor/panel/FileImportModalPanel.h + engine/frame-builder/EngineFrameBuilder.cpp + engine/frame-builder/EngineFrameBuilder.h + engine/frame-builder/EngineFrame.cpp + engine/frame-builder/EngineFrame.h + engine/frame-builder/structures/FramebufferBuilder.cpp + engine/frame-builder/structures/FramebufferBuilder.h + engine/frame-builder/structures/TextureBuilder.cpp + engine/frame-builder/structures/TextureBuilder.h + engine/frame-builder/structures/BufferBuilder.cpp + engine/frame-builder/structures/BufferBuilder.h + engine/frame-builder/structures/ResourceBuilder.h + engine/dto/PipelineBuilder.cpp + engine/service/DescriptorSetService.cpp + engine/frame-builder/structures/CommandBufferRecorderBuilder.cpp + engine/passes/impl/TemporalAccumulationPass.cpp + engine/passes/impl/TemporalAccumulationPass.h + engine/passes/impl/SpatialFilterPass.cpp + engine/passes/impl/SpatialFilterPass.h + engine/enum/ComponentType.cpp + editor/dto/SceneEntityData.h + editor/dock-spaces/repositories/RepositoriesPanel.cpp + editor/dock-spaces/repositories/RepositoriesPanel.h + engine/service/VolumeService.cpp + engine/service/VolumeService.h + common/IContextMember.h + common/IService.h + common/IRepository.h + common/IContextMember.cpp + core/DirectoryService.cpp + core/DirectoryService.h + common/IDisposable.h + core/FrameService.cpp + core/FrameService.h +) + +# Extract non-main sources for testing +set(ENGINE_LIB_SOURCES ${ENGINE_SOURCES}) +list(REMOVE_ITEM ENGINE_LIB_SOURCES main.cpp) + +add_library(metal_engine_lib STATIC ${ENGINE_LIB_SOURCES}) +target_include_directories(metal_engine_lib PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) +target_link_libraries(metal_engine_lib PUBLIC ${COMMON_LIBRARIES}) + +add_executable(metal_engine main.cpp) +target_link_libraries(metal_engine PRIVATE metal_engine_lib) +add_dependencies(metal_engine copy_resources) + +add_custom_command(TARGET metal_engine POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_directory + "${CMAKE_BINARY_DIR}/resources" + "$/resources") diff --git a/src/core/vulkan/VulkanContext.cpp b/src/core/vulkan/VulkanContext.cpp index 1fb88ca9..68520c7d 100644 --- a/src/core/vulkan/VulkanContext.cpp +++ b/src/core/vulkan/VulkanContext.cpp @@ -211,7 +211,7 @@ namespace Metal { const ImVector &instanceExtensions) const { if (auto sysInfoResult = vkb::SystemInfo::get_system_info(); sysInfoResult) { const auto &sysInfo = sysInfoResult.value(); - if (sysInfo.validation_layers_available && debugMode) { + if (sysInfo.validation_layers_available && ctx->isDebugMode()) { if (sysInfo.is_layer_available("VK_LAYER_LUNARG_api_dump")) { // instanceBuilder.enable_layer("VK_LAYER_LUNARG_api_dump"); } @@ -252,7 +252,6 @@ namespace Metal { } void VulkanContext::onInitialize() { - this->debugMode = ctx->isDebugMode(); this->window = glfwContext->getWindow(); imguiVulkanWindow.ClearValue.color.float32[0] = 0; diff --git a/src/core/vulkan/VulkanContext.h b/src/core/vulkan/VulkanContext.h index cee39ddd..2fe36230 100644 --- a/src/core/vulkan/VulkanContext.h +++ b/src/core/vulkan/VulkanContext.h @@ -58,7 +58,6 @@ namespace Metal { unsigned int w{}, h{}; GLFWwindow *window = nullptr; - bool debugMode = false; std::vector commandBuffers{}; public: diff --git a/src/editor/EditorPanel.cpp b/src/editor/EditorPanel.cpp index ba38367e..8626f437 100644 --- a/src/editor/EditorPanel.cpp +++ b/src/editor/EditorPanel.cpp @@ -26,70 +26,68 @@ namespace Metal { void EditorPanel::renderDockSpaces() { const ImGuiViewport *viewport = ImGui::GetMainViewport(); - renderHeader(viewport); - renderFooter(viewport); - // Begin window + // Header { UIUtil::AUX_VEC2.x = viewport->Pos.x; - UIUtil::AUX_VEC2.y = viewport->Pos.y + HEADER_HEIGHT; + UIUtil::AUX_VEC2.y = viewport->Pos.y; ImGui::SetNextWindowPos(UIUtil::AUX_VEC2); UIUtil::AUX_VEC2.x = viewport->Size.x; - UIUtil::AUX_VEC2.y = viewport->Size.y - HEADER_HEIGHT - FOOTER_HEIGHT; + UIUtil::AUX_VEC2.y = HEADER_HEIGHT; ImGui::SetNextWindowSize(UIUtil::AUX_VEC2); - ImGui::SetNextWindowViewport(viewport->ID); SetWindowStyle(); - } + ImGui::Begin(NAME_HEADER, &UIUtil::OPEN, FLAGS | ImGuiWindowFlags_NoScrollbar); + ImGui::PopStyleVar(3); - ImGui::Begin(NAME, &UIUtil::OPEN, FLAGS); - windowId = ImGui::GetID(NAME); - - ImGui::PopStyleVar(3); - - dockService->buildViews(windowId, this); + headerPanel->onSync(); + ImGui::End(); + } - ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 0.0f); - ImGui::DockSpace(windowId, CENTER, ImGuiDockNodeFlags_PassthruCentralNode); - ImGui::PopStyleVar(1); + // Main Window (DockSpace) + { + UIUtil::AUX_VEC2.x = viewport->Pos.x; + UIUtil::AUX_VEC2.y = viewport->Pos.y + HEADER_HEIGHT; + ImGui::SetNextWindowPos(UIUtil::AUX_VEC2); - onSyncChildren(); - ImGui::End(); - } + UIUtil::AUX_VEC2.x = viewport->Size.x; + UIUtil::AUX_VEC2.y = viewport->Size.y - HEADER_HEIGHT - FOOTER_HEIGHT; + ImGui::SetNextWindowSize(UIUtil::AUX_VEC2); + ImGui::SetNextWindowViewport(viewport->ID); - void EditorPanel::renderHeader(const ImGuiViewport *viewport) { - UIUtil::AUX_VEC2.x = viewport->Pos.x; - UIUtil::AUX_VEC2.y = viewport->Pos.y; - ImGui::SetNextWindowPos(UIUtil::AUX_VEC2); + SetWindowStyle(); + ImGui::Begin(NAME, &UIUtil::OPEN, FLAGS); + windowId = ImGui::GetID(NAME); + ImGui::PopStyleVar(3); - UIUtil::AUX_VEC2.x = viewport->Size.x; - UIUtil::AUX_VEC2.y = HEADER_HEIGHT; - ImGui::SetNextWindowSize(UIUtil::AUX_VEC2); + dockService->buildViews(windowId, this); - SetWindowStyle(); - ImGui::Begin(NAME_HEADER, &UIUtil::OPEN, FLAGS | ImGuiWindowFlags_NoScrollbar); - ImGui::PopStyleVar(3); + ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 0.0f); + ImGui::DockSpace(windowId, CENTER, ImGuiDockNodeFlags_PassthruCentralNode); + ImGui::PopStyleVar(1); - headerPanel->onSync(); - ImGui::End(); - } + onSyncChildren(); + ImGui::End(); + } - void EditorPanel::renderFooter(const ImGuiViewport *viewport) { - UIUtil::AUX_VEC2.x = viewport->Pos.x; - UIUtil::AUX_VEC2.y = viewport->Pos.y + viewport->Size.y - FOOTER_HEIGHT; - ImGui::SetNextWindowPos(UIUtil::AUX_VEC2); + // Footer + { + UIUtil::AUX_VEC2.x = viewport->Pos.x; + UIUtil::AUX_VEC2.y = viewport->Pos.y + viewport->Size.y - FOOTER_HEIGHT; + ImGui::SetNextWindowPos(UIUtil::AUX_VEC2); - UIUtil::AUX_VEC2.x = viewport->Size.x; - UIUtil::AUX_VEC2.y = FOOTER_HEIGHT; - ImGui::SetNextWindowSize(UIUtil::AUX_VEC2); + UIUtil::AUX_VEC2.x = viewport->Size.x; + UIUtil::AUX_VEC2.y = FOOTER_HEIGHT; + ImGui::SetNextWindowSize(UIUtil::AUX_VEC2); - SetWindowStyle(); - ImGui::Begin(NAME_FOOTER, &UIUtil::OPEN, FLAGS | ImGuiWindowFlags_NoScrollbar); - ImGui::PopStyleVar(3); + SetWindowStyle(); + ImGui::Begin(NAME_FOOTER, &UIUtil::OPEN, FLAGS | ImGuiWindowFlags_NoScrollbar); + ImGui::PopStyleVar(3); - footerPanel->onSync(); - ImGui::End(); + footerPanel->onSync(); + ImGui::End(); + } } void EditorPanel::SetWindowStyle() { diff --git a/src/editor/EditorPanel.h b/src/editor/EditorPanel.h index d007ff7a..f3a97a12 100644 --- a/src/editor/EditorPanel.h +++ b/src/editor/EditorPanel.h @@ -29,10 +29,6 @@ namespace Metal { void renderDockSpaces(); - void renderHeader(const ImGuiViewport *viewport); - - void renderFooter(const ImGuiViewport *viewport); - public: std::vector getDependencies() override { return { diff --git a/src/editor/dock-spaces/footer/EditorFooterPanel.cpp b/src/editor/dock-spaces/footer/EditorFooterPanel.cpp index 280a194c..0a427db7 100644 --- a/src/editor/dock-spaces/footer/EditorFooterPanel.cpp +++ b/src/editor/dock-spaces/footer/EditorFooterPanel.cpp @@ -1,14 +1,22 @@ #include "EditorFooterPanel.h" +#include "../header/AsyncTaskPanel.h" #include "../../util/UIUtil.h" #include "../../../ApplicationContext.h" #include "../../repository/EditorRepository.h" namespace Metal { void EditorFooterPanel::onSync() { + ImGui::Separator(); + asyncTaskPanel->onSync(); + ImGui::SameLine(); renderShortcuts(); framerate(); } + void EditorFooterPanel::onInitialize() { + initializePanel(asyncTaskPanel = new AsyncTaskPanel(), false); + } + void EditorFooterPanel::framerate() { const int framerate = static_cast(round(ImGui::GetIO().Framerate)); if (framerate > 0) { @@ -21,10 +29,8 @@ namespace Metal { auto &shortcuts = editorRepository->focusedShortcuts; if (shortcuts.empty()) return; - ImGui::SetCursorPosY(ImGui::GetCursorPosY() + 5); // Some padding + ImGui::SetCursorPosY(ImGui::GetCursorPosY() + 2); // Some padding - ImGui::Text(editorRepository->focusedWindowName.c_str()); - ImGui::SameLine(); std::string label; for (size_t i = 0; i < std::min(shortcuts.size(), size_t(3)); ++i) { if (i > 0) label += " | "; diff --git a/src/editor/dock-spaces/footer/EditorFooterPanel.h b/src/editor/dock-spaces/footer/EditorFooterPanel.h index 4dee9bb0..9f4ec717 100644 --- a/src/editor/dock-spaces/footer/EditorFooterPanel.h +++ b/src/editor/dock-spaces/footer/EditorFooterPanel.h @@ -6,8 +6,11 @@ namespace Metal { struct EditorRepository; + class AsyncTaskPanel; + class EditorFooterPanel final : public AbstractPanel { EditorRepository *editorRepository = nullptr; + AsyncTaskPanel *asyncTaskPanel = nullptr; void renderShortcuts(); static void framerate(); @@ -19,6 +22,8 @@ namespace Metal { }; } + void onInitialize() override; + void onSync() override; }; } diff --git a/src/editor/dock-spaces/header/AsyncTaskPanel.cpp b/src/editor/dock-spaces/header/AsyncTaskPanel.cpp index 616fc37b..108824e7 100644 --- a/src/editor/dock-spaces/header/AsyncTaskPanel.cpp +++ b/src/editor/dock-spaces/header/AsyncTaskPanel.cpp @@ -8,37 +8,28 @@ namespace Metal { void AsyncTaskPanel::onSync() { auto tasks = asyncTaskService->getActiveTasks(); - if (tasks.empty()) { - UIUtil::DynamicSpacing(90); - return; - } - UIUtil::DynamicSpacing(250); - ImGui::SameLine(); - - float time = (float)ImGui::GetTime(); - float t = 0.5f + 0.5f * std::sin(time * 3.0f); // 0.0 to 1.0 - - ImVec4 color = ImVec4( - 0.0f + t * 0.4f, - 0.2f + t * 0.5f, - 0.6f + t * 0.4f, - 1.0f - ); + bool hasTasks = !tasks.empty(); + ImGui::BeginGroup(); ImVec2 pos = ImGui::GetCursorScreenPos(); - float width = 150.0f; - float height = 10.0f; + float size = (float)UIUtil::ONLY_ICON_BUTTON_SIZE; - pos.y += (UIUtil::ONLY_ICON_BUTTON_SIZE - height) / 2.0f; + if (ImGui::InvisibleButton("##AsyncTaskIcon", ImVec2(size, size))) { + ImGui::OpenPopup("AsyncTasksPopup"); + } - ImGui::GetWindowDrawList()->AddRectFilled(pos, ImVec2(pos.x + width, pos.y + height), ImGui::ColorConvertFloat4ToU32(color), 5.0f); + ImU32 iconColor = ImGui::GetColorU32(ImGuiCol_Text); + ImGui::GetWindowDrawList()->AddText(ImGui::GetFont(), ImGui::GetFontSize(), + ImVec2(pos.x + (size - ImGui::CalcTextSize(Icons::sync.c_str()).x) / 2, + pos.y + (size - ImGui::GetFontSize()) / 2), + iconColor, Icons::sync.c_str()); - ImGui::SetCursorScreenPos(pos); - if (ImGui::InvisibleButton("##AsyncTaskLine", ImVec2(width, height))) { - ImGui::OpenPopup("AsyncTasksPopup"); + if (hasTasks) { + float circleRadius = 3.0f; + ImVec2 circlePos = ImVec2(pos.x + size / 2.0f, pos.y + size - circleRadius - 2.0f); + ImGui::GetWindowDrawList()->AddCircleFilled(circlePos, circleRadius, IM_COL32(0, 200, 255, 255)); } - ImGui::SameLine(); - ImGui::Dummy(ImVec2(0, UIUtil::ONLY_ICON_BUTTON_SIZE)); + ImGui::EndGroup(); UIUtil::RenderTooltip(Icons::sync + " " + std::to_string(tasks.size()) + " processes running..."); @@ -52,8 +43,9 @@ namespace Metal { ImGui::Text("%s", task->name.c_str()); ImVec2 p = ImGui::GetCursorScreenPos(); + float height = 10.0f; float w = ImGui::GetContentRegionAvail().x - UIUtil::ONLY_ICON_BUTTON_SIZE - ImGui::GetStyle().ItemSpacing.x; - ImGui::GetWindowDrawList()->AddRectFilled(p, ImVec2(p.x + w, p.y + height), ImGui::ColorConvertFloat4ToU32(color), 5.0f); + ImGui::GetWindowDrawList()->AddRectFilled(p, ImVec2(p.x + w, p.y + height), IM_COL32(50, 150, 255, 255), 5.0f); ImGui::Dummy(ImVec2(w, height)); ImGui::SameLine(); diff --git a/src/editor/dock-spaces/header/EditorHeaderPanel.cpp b/src/editor/dock-spaces/header/EditorHeaderPanel.cpp index 6f7be23b..c1f57417 100644 --- a/src/editor/dock-spaces/header/EditorHeaderPanel.cpp +++ b/src/editor/dock-spaces/header/EditorHeaderPanel.cpp @@ -1,5 +1,4 @@ #include "EditorHeaderPanel.h" -#include "AsyncTaskPanel.h" #include "../../util/UIUtil.h" #include "../../../ApplicationContext.h" #include "../../../core/DirectoryService.h" @@ -12,19 +11,10 @@ namespace Metal { ImGui::Dummy(ImVec2(0, UIUtil::ONLY_ICON_BUTTON_SIZE)); ImGui::Dummy(ImVec2(2, 0)); ImGui::Separator(); - - // Window dragging logic - if (ImGui::IsWindowHovered() && ImGui::IsMouseDragging(ImGuiMouseButton_Left)) { - ImVec2 delta = ImGui::GetIO().MouseDelta; - GLFWwindow *window = glfwContext->getWindow(); - int x, y; - glfwGetWindowPos(window, &x, &y); - glfwSetWindowPos(window, x + (int) delta.x, y + (int) delta.y); - } } void EditorHeaderPanel::renderWindowControls() { - ImGui::SameLine(ImGui::GetWindowWidth() - (UIUtil::ONLY_ICON_BUTTON_SIZE * 3 + 10)); + ImGui::SameLine(ImGui::GetWindowWidth() - (UIUtil::ONLY_ICON_BUTTON_SIZE * 3 + 20)); GLFWwindow *window = glfwContext->getWindow(); @@ -72,26 +62,61 @@ namespace Metal { ImGui::EndMenu(); } - // Create an "Edit" menu + // Edit menu if (ImGui::BeginMenu("Edit")) { if (ImGui::MenuItem("Compile shaders")) { engineContext->dispose(); - // TODO - CREATE NEW FRAME } ImGui::EndMenu(); } - UIUtil::LargeSpacing(); + // --- Drag handle area --- + // Use remaining width (minus the space reserved for window controls) + float controlsWidth = UIUtil::ONLY_ICON_BUTTON_SIZE * 3 + 20; // approximate width of minimize/maximize/close + float dragHandleWidth = ImGui::GetContentRegionAvail().x - controlsWidth; + if (dragHandleWidth > 0) { + ImGui::SameLine(); + dragHandleScreenPos = ImGui::GetCursorScreenPos(); + ImGui::InvisibleButton("##header_drag_handle", ImVec2(dragHandleWidth, ImGui::GetFrameHeight())); + + GLFWwindow *window = glfwContext->getWindow(); + if (ImGui::IsItemHovered() && ImGui::IsMouseClicked(ImGuiMouseButton_Left)) { + if (!glfwGetWindowAttrib(window, GLFW_MAXIMIZED)) { + isDragging = true; + dragStartMousePos = ImGui::GetIO().MousePos; + glfwGetWindowPos(window, &dragStartWindowX, &dragStartWindowY); + lastWindowX = dragStartWindowX; + lastWindowY = dragStartWindowY; + } + } + + if (isDragging) { + if (ImGui::IsMouseDown(ImGuiMouseButton_Left)) { + ImVec2 currentMousePos = ImGui::GetIO().MousePos; + + // Calculate how much the mouse has moved relative to the drag handle's CURRENT screen position + // This compensates for the window's own movement + float deltaX = currentMousePos.x - dragStartMousePos.x; + float deltaY = currentMousePos.y - dragStartMousePos.y; - asyncTask->onSync(); + int newWindowX = lastWindowX + (int)deltaX; + int newWindowY = lastWindowY + (int)deltaY; + if (newWindowX != lastWindowX || newWindowY != lastWindowY) { + glfwSetWindowPos(window, newWindowX, newWindowY); + lastWindowX = newWindowX; + lastWindowY = newWindowY; + } + } else { + isDragging = false; + } + } + } + + // Window controls (minimize, maximize, close) renderWindowControls(); ImGui::EndMainMenuBar(); } } - - void EditorHeaderPanel::onInitialize() { - initializePanel(asyncTask = new AsyncTaskPanel()); - } } diff --git a/src/editor/dock-spaces/header/EditorHeaderPanel.h b/src/editor/dock-spaces/header/EditorHeaderPanel.h index 230591f9..3e385bee 100644 --- a/src/editor/dock-spaces/header/EditorHeaderPanel.h +++ b/src/editor/dock-spaces/header/EditorHeaderPanel.h @@ -2,6 +2,7 @@ #define METAL_ENGINE_EDITORHEADERPANEL_H #include "../../abstract/AbstractPanel.h" +#include namespace Metal { class GLFWContext; @@ -9,12 +10,22 @@ namespace Metal { struct DirectoryService; class EditorHeaderPanel final : public AbstractPanel { - AbstractPanel *asyncTask = nullptr; - GLFWContext *glfwContext = nullptr; EngineContext *engineContext = nullptr; DirectoryService *directoryService = nullptr; + ImVec2 dragStartMousePos; + int dragStartWindowX = 0; + int dragStartWindowY = 0; + bool isDragging = false; + + double dragStartGlobalMouseX = 0; + double dragStartGlobalMouseY = 0; + int lastWindowX = 0; + int lastWindowY = 0; + + ImVec2 dragHandleScreenPos; + void renderFileTab(); void renderWindowControls(); @@ -28,8 +39,6 @@ namespace Metal { }; } - void onInitialize() override; - void onSync() override; }; } // Metal diff --git a/src/editor/passes/GridPass.cpp b/src/editor/passes/GridPass.cpp index 3dfcc2a9..4a919feb 100644 --- a/src/editor/passes/GridPass.cpp +++ b/src/editor/passes/GridPass.cpp @@ -1,5 +1,4 @@ #include "GridPass.h" -#include "../../ApplicationContext.h" #include "../../engine/dto/PipelineBuilder.h" #include "../../engine/service/PipelineService.h" #include "../repository/EditorRepository.h" @@ -20,7 +19,7 @@ namespace Metal { } bool GridPass::shouldRun() { - return applicationContext->isDebugMode() && editorRepository->showGrid; + return editorRepository->showGrid; } void GridPass::onSync() { diff --git a/src/editor/passes/GridPass.h b/src/editor/passes/GridPass.h index f9f2a635..4be4e4c5 100644 --- a/src/editor/passes/GridPass.h +++ b/src/editor/passes/GridPass.h @@ -5,21 +5,18 @@ namespace Metal { class PipelineService; - class ApplicationContext; struct EditorRepository; class GridPass final : public AbstractRenderPass { GridPushConstant pushConstant{}; PipelineService *pipelineService = nullptr; - ApplicationContext *applicationContext = nullptr; EditorRepository *editorRepository = nullptr; public: std::vector getDependencies() override { return { {"PipelineService", &pipelineService}, - {"ApplicationContext", &applicationContext}, {"EditorRepository", &editorRepository} }; } diff --git a/src/editor/passes/SelectionOutlinePass.cpp b/src/editor/passes/SelectionOutlinePass.cpp index f44c9289..7726eb9e 100644 --- a/src/editor/passes/SelectionOutlinePass.cpp +++ b/src/editor/passes/SelectionOutlinePass.cpp @@ -12,7 +12,7 @@ namespace Metal { PipelineBuilder builder = PipelineBuilder::Of( getScopedResourceId(RID_POST_PROCESSING_FBO), "QUAD.vert", - "tools/SelectedDot.frag" + "tools/SelectionOutline.frag" ) .setBlendEnabled() .setPushConstantsSize(sizeof(SelectedDotPushConstant)) diff --git a/src/main.cpp b/src/main.cpp index 3fd38ca0..8e452fdc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,10 +1,3 @@ -#define STB_IMAGE_IMPLEMENTATION -#include "stb_image.h" -#define STB_IMAGE_WRITE_IMPLEMENTATION -#include "stb_image_write.h" -#define VMA_IMPLEMENTATION -#define GLM_FORCE_RADIANS -#define GLM_FORCE_DEPTH_ZERO_TO_ONE #include "ApplicationContext.h" #include "core/DirectoryService.h" #include "core/FrameService.h" diff --git a/tests/ApplicationContextTest.cpp b/tests/ApplicationContextTest.cpp new file mode 100644 index 00000000..699f0f04 --- /dev/null +++ b/tests/ApplicationContextTest.cpp @@ -0,0 +1,39 @@ +#include +#include +#include "../src/ApplicationContext.h" +#include "../src/common/IContextMember.h" +#include + +using namespace Metal; + +class MockContextMember : public IContextMember { +public: + int value = 0; +}; + +TEST(ApplicationContextTest, RegisterAndGetSingleton) { + ApplicationContext ctx(true); + auto member = std::make_shared(); + member->value = 42; + + ctx.registerSingleton(member); + + MockContextMember& retrieved = ctx.getSingleton(); + EXPECT_EQ(retrieved.value, 42); +} + +TEST(ApplicationContextTest, GetSingletonByName) { + ApplicationContext ctx(true); + auto member = std::make_shared(); + + ctx.registerSingleton(member); + + void* ptr = ctx.getSingletonByName("MockContextMember"); + EXPECT_NE(ptr, nullptr); + EXPECT_EQ(static_cast(ptr), member.get()); +} + +TEST(ApplicationContextTest, ThrowsWhenSingletonNotFound) { + ApplicationContext ctx(true); + EXPECT_THROW(ctx.getSingleton(), std::runtime_error); +} diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 00000000..a80f315c --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,21 @@ +find_package(GTest REQUIRED) + +add_executable(metal_engine_tests + ApplicationContextTest.cpp + WorldRepositoryTest.cpp +) + +target_link_libraries(metal_engine_tests + PRIVATE + metal_engine_lib + GTest::gtest_main +) +add_dependencies(metal_engine_tests copy_resources) + +add_custom_command(TARGET metal_engine_tests POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_directory + "${CMAKE_BINARY_DIR}/resources" + "$/resources") + +include(GoogleTest) +gtest_discover_tests(metal_engine_tests) diff --git a/tests/WorldRepositoryTest.cpp b/tests/WorldRepositoryTest.cpp new file mode 100644 index 00000000..efc8a4b9 --- /dev/null +++ b/tests/WorldRepositoryTest.cpp @@ -0,0 +1,64 @@ +#include +#include +#include "../src/ApplicationContext.h" +#include "../src/engine/repository/WorldRepository.h" +#include "../src/engine/dto/MetadataComponent.h" +#include "../src/engine/service/RayTracingService.h" +#include "../src/core/DirectoryService.h" +#include "../src/engine/EngineContext.h" +#include + +using namespace Metal; + +class WorldRepositoryTest : public ::testing::Test { +protected: + std::unique_ptr context; + WorldRepository* repo; + + void SetUp() override { + context = std::make_unique(true); + + auto worldRepo = std::make_shared(); + auto rayTracingService = std::make_shared(); + auto directoryService = std::make_shared(); + auto engineContext = std::make_shared(); + + context->registerSingleton(worldRepo); + context->registerSingleton(rayTracingService); + context->registerSingleton(directoryService); + context->registerSingleton(engineContext); + + context->injectDependencies(worldRepo.get()); + + repo = worldRepo.get(); + } +}; + +TEST_F(WorldRepositoryTest, CreateEntity) { + entt::entity entity = repo->createEntity(); + EXPECT_NE(entity, static_cast(entt::null)); + EXPECT_TRUE(repo->registry.valid(entity)); +} + +TEST_F(WorldRepositoryTest, GetEntityMetadata) { + entt::entity entity = repo->createEntity(); + MetadataComponent* metadata = repo->getEntity(entity); + EXPECT_NE(metadata, nullptr); +} + +TEST_F(WorldRepositoryTest, DeleteEntity) { + entt::entity entity = repo->createEntity(); + repo->deleteEntities({entity}); + EXPECT_FALSE(repo->registry.valid(entity)); +} + +TEST_F(WorldRepositoryTest, ChangeVisibility) { + entt::entity entity = repo->createEntity(); + + repo->changeVisibility(entity, false); + EXPECT_EQ(repo->hiddenEntities.count(entity), 1); + EXPECT_TRUE(repo->hiddenEntities.at(entity)); + + repo->changeVisibility(entity, true); + EXPECT_EQ(repo->hiddenEntities.count(entity), 0); +} diff --git a/vcpkg.json b/vcpkg.json index e5abb844..5b0cea8f 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -18,9 +18,6 @@ }, { "name" : "glm", "version>=" : "1.0.1#3" - }, { - "name" : "spdlog", - "version>=" : "1.15.0#1" }, { "name" : "spirv-tools", "version>=" : "1.3.296.0" @@ -51,5 +48,8 @@ }, { "name" : "entt", "version>=" : "3.16.0" - } ] + }, { + "name" : "gtest", + "version>=" : "1.15.2" + }] } \ No newline at end of file From 4a1f7971154b92dda308883b45e4e826f6ca2468 Mon Sep 17 00:00:00 2001 From: facobackup Date: Sat, 14 Mar 2026 20:24:20 -0300 Subject: [PATCH 17/18] Drag --- .../dock-spaces/header/EditorHeaderPanel.cpp | 42 ------------------- .../dock-spaces/header/EditorHeaderPanel.h | 12 ------ 2 files changed, 54 deletions(-) diff --git a/src/editor/dock-spaces/header/EditorHeaderPanel.cpp b/src/editor/dock-spaces/header/EditorHeaderPanel.cpp index c1f57417..ae5ee5f4 100644 --- a/src/editor/dock-spaces/header/EditorHeaderPanel.cpp +++ b/src/editor/dock-spaces/header/EditorHeaderPanel.cpp @@ -70,48 +70,6 @@ namespace Metal { ImGui::EndMenu(); } - // --- Drag handle area --- - // Use remaining width (minus the space reserved for window controls) - float controlsWidth = UIUtil::ONLY_ICON_BUTTON_SIZE * 3 + 20; // approximate width of minimize/maximize/close - float dragHandleWidth = ImGui::GetContentRegionAvail().x - controlsWidth; - if (dragHandleWidth > 0) { - ImGui::SameLine(); - dragHandleScreenPos = ImGui::GetCursorScreenPos(); - ImGui::InvisibleButton("##header_drag_handle", ImVec2(dragHandleWidth, ImGui::GetFrameHeight())); - - GLFWwindow *window = glfwContext->getWindow(); - if (ImGui::IsItemHovered() && ImGui::IsMouseClicked(ImGuiMouseButton_Left)) { - if (!glfwGetWindowAttrib(window, GLFW_MAXIMIZED)) { - isDragging = true; - dragStartMousePos = ImGui::GetIO().MousePos; - glfwGetWindowPos(window, &dragStartWindowX, &dragStartWindowY); - lastWindowX = dragStartWindowX; - lastWindowY = dragStartWindowY; - } - } - - if (isDragging) { - if (ImGui::IsMouseDown(ImGuiMouseButton_Left)) { - ImVec2 currentMousePos = ImGui::GetIO().MousePos; - - // Calculate how much the mouse has moved relative to the drag handle's CURRENT screen position - // This compensates for the window's own movement - float deltaX = currentMousePos.x - dragStartMousePos.x; - float deltaY = currentMousePos.y - dragStartMousePos.y; - - int newWindowX = lastWindowX + (int)deltaX; - int newWindowY = lastWindowY + (int)deltaY; - - if (newWindowX != lastWindowX || newWindowY != lastWindowY) { - glfwSetWindowPos(window, newWindowX, newWindowY); - lastWindowX = newWindowX; - lastWindowY = newWindowY; - } - } else { - isDragging = false; - } - } - } // Window controls (minimize, maximize, close) renderWindowControls(); diff --git a/src/editor/dock-spaces/header/EditorHeaderPanel.h b/src/editor/dock-spaces/header/EditorHeaderPanel.h index 3e385bee..032e7ab5 100644 --- a/src/editor/dock-spaces/header/EditorHeaderPanel.h +++ b/src/editor/dock-spaces/header/EditorHeaderPanel.h @@ -14,18 +14,6 @@ namespace Metal { EngineContext *engineContext = nullptr; DirectoryService *directoryService = nullptr; - ImVec2 dragStartMousePos; - int dragStartWindowX = 0; - int dragStartWindowY = 0; - bool isDragging = false; - - double dragStartGlobalMouseX = 0; - double dragStartGlobalMouseY = 0; - int lastWindowX = 0; - int lastWindowY = 0; - - ImVec2 dragHandleScreenPos; - void renderFileTab(); void renderWindowControls(); From 3c20e57c0249ea0229ec2e8a47c7b1da58290d71 Mon Sep 17 00:00:00 2001 From: facobackup Date: Sat, 14 Mar 2026 22:09:25 -0300 Subject: [PATCH 18/18] New UI layout Theme json configuration file Fixing window dragging and border --- resources/theme.json | 22 ++ src/CMakeLists.txt | 3 + src/core/glfw/GLFWContext.cpp | 308 ++++++++++++++++++ src/core/glfw/GLFWContext.h | 86 +++++ src/editor/EditorPanel.cpp | 14 +- src/editor/EditorPanel.h | 2 +- .../dock-spaces/docks/DockSpacePanel.cpp | 158 ++++++--- src/editor/dock-spaces/docks/DockSpacePanel.h | 6 +- .../dock-spaces/footer/EditorFooterPanel.cpp | 9 +- .../dock-spaces/footer/EditorFooterPanel.h | 8 +- .../dock-spaces/header/EditorHeaderPanel.cpp | 118 ++++--- .../dock-spaces/header/EditorHeaderPanel.h | 11 +- .../dock-spaces/viewport/EngineFramePanel.cpp | 14 +- src/editor/dto/DockDTO.h | 1 + src/editor/service/DockService.cpp | 26 +- src/editor/service/DockService.h | 1 - src/editor/service/ThemeService.cpp | 90 +++-- src/editor/service/ThemeService.h | 12 +- src/main.cpp | 2 +- 19 files changed, 752 insertions(+), 139 deletions(-) create mode 100644 resources/theme.json diff --git a/resources/theme.json b/resources/theme.json new file mode 100644 index 00000000..0beeb31b --- /dev/null +++ b/resources/theme.json @@ -0,0 +1,22 @@ +{ + "dark": { + "palette0": "#18191b", + "palette1": "#08080a", + "palette2": "#161616", + "palette3": "#232323", + "palette4": "#414141", + "palette5": "#777777", + "palette6": "#E0E0E0", + "neutralPalette": "#161616" + }, + "light": { + "palette0": "#EBEBEB", + "palette1": "#F5F5F5", + "palette2": "#E1E1E1", + "palette3": "#C8C8C8", + "palette4": "#A0A0A0", + "palette5": "#787878", + "palette6": "#0A0A0A", + "neutralPalette": "#E1E1E1" + } +} diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e2b3bc36..d1998475 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -288,6 +288,9 @@ target_link_libraries(metal_engine_lib PUBLIC ${COMMON_LIBRARIES}) add_executable(metal_engine main.cpp) target_link_libraries(metal_engine PRIVATE metal_engine_lib) +if (WIN32) + target_link_libraries(metal_engine PRIVATE dwmapi) +endif() add_dependencies(metal_engine copy_resources) add_custom_command(TARGET metal_engine POST_BUILD diff --git a/src/core/glfw/GLFWContext.cpp b/src/core/glfw/GLFWContext.cpp index 7a3a6e26..4c2509de 100644 --- a/src/core/glfw/GLFWContext.cpp +++ b/src/core/glfw/GLFWContext.cpp @@ -1,4 +1,8 @@ #include +#define GLFW_EXPOSE_NATIVE_WIN32 +#include +#include +#include #include "GLFWContext.h" #include "../../ApplicationContext.h" #include "../vulkan/VulkanUtils.h" @@ -43,6 +47,7 @@ namespace Metal { } void GLFWContext::disposeManually() { + disposeCursors(); glfwDestroyWindow(window); glfwTerminate(); } @@ -97,8 +102,311 @@ namespace Metal { const char **glfw_extensions = glfwGetRequiredInstanceExtensions(&extensions_count); for (unsigned int i = 0; i < extensions_count; i++) instance_extensions.push_back(glfw_extensions[i]); + + glfwSetWindowUserPointer(window, this); + glfwSetMouseButtonCallback(window, [](GLFWwindow *win, int button, int action, int mods) { + auto *ctx = static_cast(glfwGetWindowUserPointer(win)); + ctx->handleWindowManagement(button, action, mods); + for (auto &callback: ctx->getMouseButtonCallbacks()) { + callback(button, action, mods); + } + }); + glfwSetCursorPosCallback(window, [](GLFWwindow *win, double xpos, double ypos) { + auto *ctx = static_cast(glfwGetWindowUserPointer(win)); + ctx->handleCursorPos(xpos, ypos); + ctx->updateCursorShape(xpos, ypos); + for (auto &callback: ctx->getCursorPosCallbacks()) { + callback(xpos, ypos); + } + }); + + hResizeCursor = glfwCreateStandardCursor(GLFW_HRESIZE_CURSOR); + vResizeCursor = glfwCreateStandardCursor(GLFW_VRESIZE_CURSOR); + nwseResizeCursor = glfwCreateStandardCursor(GLFW_RESIZE_NWSE_CURSOR); + neswResizeCursor = glfwCreateStandardCursor(GLFW_RESIZE_NESW_CURSOR); + + // Enable Windows 11 rounded corners + HWND hwnd = glfwGetWin32Window(window); + if (hwnd) { + DWM_WINDOW_CORNER_PREFERENCE preference = DWMWCP_ROUND; + DwmSetWindowAttribute(hwnd, DWMWA_WINDOW_CORNER_PREFERENCE, &preference, sizeof(preference)); + } + } + } + } + + void GLFWContext::handleWindowManagement(int button, int action, int mods) { + if (button != GLFW_MOUSE_BUTTON_LEFT) return; + + double xpos, ypos; + glfwGetCursorPos(window, &xpos, &ypos); + + if (action == GLFW_PRESS) { + resizeRegion = getResizeRegion(xpos, ypos); + if (resizeRegion != ResizeRegion::None) { + isDragging = false; + glfwGetWindowPos(window, &dragStartWindowX, &dragStartWindowY); + glfwGetWindowSize(window, &dragStartWindowWidth, &dragStartWindowHeight); + dragStartCursorX = xpos; + dragStartCursorY = ypos; + return; + } + + bool isInTitleBar = ypos >= 0 && ypos < static_cast(windowManagerInfo.menuBarHeight); + + auto isInRect = [](const ImRect &rect, double x, double y) { + return x >= rect.Min.x && x <= rect.Max.x && y >= rect.Min.y && y <= rect.Max.y; + }; + + bool isOverButton = isInRect(windowManagerInfo.minimizeBtnRect, xpos, ypos) || + isInRect(windowManagerInfo.maximizeBtnRect, xpos, ypos) || + isInRect(windowManagerInfo.closeBtnRect, xpos, ypos); + + if (isInTitleBar && !isOverButton) { + double currentTime = glfwGetTime(); + if (currentTime - lastClickTime < 0.3) { + if (glfwGetWindowAttrib(window, GLFW_MAXIMIZED)) { + glfwRestoreWindow(window); + } else { + glfwMaximizeWindow(window); + } + isDragging = false; + lastClickTime = 0; + return; + } + lastClickTime = currentTime; + + isDragging = true; + dragStartCursorX = xpos; + dragStartCursorY = ypos; + glfwGetWindowPos(window, &dragStartWindowX, &dragStartWindowY); + + if (glfwGetWindowAttrib(window, GLFW_MAXIMIZED)) { + int windowWidth, windowHeight; + glfwGetWindowSize(window, &windowWidth, &windowHeight); + glfwRestoreWindow(window); + int restoredWidth, restoredHeight; + glfwGetWindowSize(window, &restoredWidth, &restoredHeight); + + double relativeX = dragStartCursorX / static_cast(windowWidth); + dragStartCursorX = relativeX * restoredWidth; + dragStartWindowX = static_cast(xpos - dragStartCursorX); + dragStartWindowY = static_cast(ypos - dragStartCursorY); + glfwSetWindowPos(window, dragStartWindowX, dragStartWindowY); + } + } + } else if (action == GLFW_RELEASE) { + if (isDragging && currentSnapTarget.active) { + applySnap(currentSnapTarget); + } + isDragging = false; + resizeRegion = ResizeRegion::None; + currentSnapTarget.active = false; + } + } + + void GLFWContext::handleCursorPos(double xpos, double ypos) { + if (isDragging) { + int wx, wy; + glfwGetWindowPos(window, &wx, &wy); + int newX = wx + static_cast(xpos - dragStartCursorX); + int newY = wy + static_cast(ypos - dragStartCursorY); + glfwSetWindowPos(window, newX, newY); + currentSnapTarget = calculateSnapTarget(xpos, ypos); + } else if (resizeRegion != ResizeRegion::None) { + int dx = static_cast(xpos - dragStartCursorX); + int dy = static_cast(ypos - dragStartCursorY); + + int newX = dragStartWindowX; + int newY = dragStartWindowY; + int newW = dragStartWindowWidth; + int newH = dragStartWindowHeight; + + const int minW = 400; + const int minH = 300; + + switch (resizeRegion) { + case ResizeRegion::Left: + newX += dx; + newW -= dx; + break; + case ResizeRegion::Right: + newW += dx; + break; + case ResizeRegion::Top: + newY += dy; + newH -= dy; + break; + case ResizeRegion::Bottom: + newH += dy; + break; + case ResizeRegion::TopLeft: + newX += dx; + newW -= dx; + newY += dy; + newH -= dy; + break; + case ResizeRegion::TopRight: + newW += dx; + newY += dy; + newH -= dy; + break; + case ResizeRegion::BottomLeft: + newX += dx; + newW -= dx; + newH += dy; + break; + case ResizeRegion::BottomRight: + newW += dx; + newH += dy; + break; + default: + break; + } + + if (newW < minW) { + if (resizeRegion == ResizeRegion::Left || resizeRegion == ResizeRegion::TopLeft || resizeRegion == ResizeRegion::BottomLeft) { + newX = dragStartWindowX + (dragStartWindowWidth - minW); + } + newW = minW; + } + if (newH < minH) { + if (resizeRegion == ResizeRegion::Top || resizeRegion == ResizeRegion::TopLeft || resizeRegion == ResizeRegion::TopRight) { + newY = dragStartWindowY + (dragStartWindowHeight - minH); + } + newH = minH; + } + + int curX, curY, curW, curH; + glfwGetWindowPos(window, &curX, &curY); + glfwGetWindowSize(window, &curW, &curH); + + if (newX != curX || newY != curY) glfwSetWindowPos(window, newX, newY); + if (newW != curW || newH != curH) glfwSetWindowSize(window, newW, newH); + } + } + + void GLFWContext::updateCursorShape(double xpos, double ypos) { + if (isDragging) return; + + ResizeRegion region = (resizeRegion != ResizeRegion::None) ? resizeRegion : getResizeRegion(xpos, ypos); + GLFWcursor *cursor = nullptr; + + switch (region) { + case ResizeRegion::Left: + case ResizeRegion::Right: + cursor = hResizeCursor; + break; + case ResizeRegion::Top: + case ResizeRegion::Bottom: + cursor = vResizeCursor; + break; + case ResizeRegion::TopLeft: + case ResizeRegion::BottomRight: + cursor = nwseResizeCursor; + break; + case ResizeRegion::TopRight: + case ResizeRegion::BottomLeft: + cursor = neswResizeCursor; + break; + default: + break; + } + + glfwSetCursor(window, cursor); + } + + ResizeRegion GLFWContext::getResizeRegion(double xpos, double ypos) { + if (glfwGetWindowAttrib(window, GLFW_MAXIMIZED)) return ResizeRegion::None; + + int w, h; + glfwGetWindowSize(window, &w, &h); + const double thickness = 8.0; + + bool left = xpos < thickness; + bool right = xpos > w - thickness; + bool top = ypos < thickness; + bool bottom = ypos > h - thickness; + + if (left && top) return ResizeRegion::TopLeft; + if (right && top) return ResizeRegion::TopRight; + if (left && bottom) return ResizeRegion::BottomLeft; + if (right && bottom) return ResizeRegion::BottomRight; + if (left) return ResizeRegion::Left; + if (right) return ResizeRegion::Right; + if (top) return ResizeRegion::Top; + if (bottom) return ResizeRegion::Bottom; + + return ResizeRegion::None; + } + + void GLFWContext::applySnap(const SnapTarget &target) { + if (target.isMaximized) { + glfwMaximizeWindow(window); + } else { + glfwRestoreWindow(window); + glfwSetWindowPos(window, target.x, target.y); + glfwSetWindowSize(window, target.width, target.height); + } + } + + SnapTarget GLFWContext::calculateSnapTarget(double xpos, double ypos) { + SnapTarget target; + int wx, wy; + glfwGetWindowPos(window, &wx, &wy); + double screenX = wx + xpos; + double screenY = wy + ypos; + + int screenW = windowManagerInfo.screenWidth; + int screenH = windowManagerInfo.screenHeight; + + const int threshold = 10; + + if (screenY < threshold) { + target.active = true; + target.isMaximized = true; + return target; + } + + if (screenX < threshold) { + target.active = true; + target.x = 0; + target.y = 0; + target.width = screenW / 2; + target.height = screenH; + if (screenY < threshold * 5) { + target.height = screenH / 2; + } else if (screenY > screenH - threshold * 5) { + target.y = screenH / 2; + target.height = screenH / 2; + } + return target; + } + + if (screenX > screenW - threshold) { + target.active = true; + target.x = screenW / 2; + target.y = 0; + target.width = screenW / 2; + target.height = screenH; + if (screenY < threshold * 5) { + target.height = screenH / 2; + } else if (screenY > screenH - threshold * 5) { + target.y = screenH / 2; + target.height = screenH / 2; } + return target; } + + return target; + } + + void GLFWContext::disposeCursors() { + if (hResizeCursor) glfwDestroyCursor(hResizeCursor); + if (vResizeCursor) glfwDestroyCursor(vResizeCursor); + if (nwseResizeCursor) glfwDestroyCursor(nwseResizeCursor); + if (neswResizeCursor) glfwDestroyCursor(neswResizeCursor); + hResizeCursor = vResizeCursor = nwseResizeCursor = neswResizeCursor = nullptr; } const ImVector &GLFWContext::getInstanceExtensions() const { diff --git a/src/core/glfw/GLFWContext.h b/src/core/glfw/GLFWContext.h index 33ad1dc3..faae8ae7 100644 --- a/src/core/glfw/GLFWContext.h +++ b/src/core/glfw/GLFWContext.h @@ -6,18 +6,51 @@ #include #include +#include #include "../../common/IContextMember.h" #include "../../common/IDisposable.h" #include "../../common/IInit.h" +#include +#include + struct ImGui_ImplVulkanH_Window; namespace Metal { class ApplicationContext; class VulkanContext; + enum class ResizeRegion { + None, + Left, + Right, + Top, + Bottom, + TopLeft, + TopRight, + BottomLeft, + BottomRight + }; + + struct SnapTarget { + int x, y, width, height; + bool active = false; + bool isMaximized = false; + }; + + struct WindowManagerInfo { + float menuBarHeight = 0; + ImRect minimizeBtnRect; + ImRect maximizeBtnRect; + ImRect closeBtnRect; + int windowWidth = 0; + int windowHeight = 0; + int screenWidth = 0; + int screenHeight = 0; + }; + class GLFWContext final : public IContextMember, public IInit { VulkanContext *vulkanContext = nullptr; GLFWwindow *window = nullptr; @@ -25,11 +58,46 @@ namespace Metal { bool swapChainRebuild = false; ImVector instance_extensions{}; + std::vector> mouseButtonCallbacks; + std::vector> cursorPosCallbacks; + + // Window management state + WindowManagerInfo windowManagerInfo; + bool isDragging = false; + ResizeRegion resizeRegion = ResizeRegion::None; + double dragStartCursorX = 0; + double dragStartCursorY = 0; + int dragStartWindowX = 0; + int dragStartWindowY = 0; + int dragStartWindowWidth = 0; + int dragStartWindowHeight = 0; + double lastClickTime = 0; + + // Snapping state + SnapTarget currentSnapTarget; + + // Cursor shapes + GLFWcursor *hResizeCursor = nullptr; + GLFWcursor *vResizeCursor = nullptr; + GLFWcursor *nwseResizeCursor = nullptr; + GLFWcursor *neswResizeCursor = nullptr; + + void handleWindowManagement(int button, int action, int mods); + void handleCursorPos(double xpos, double ypos); + void updateCursorShape(double xpos, double ypos); + ResizeRegion getResizeRegion(double xpos, double ypos); + void applySnap(const SnapTarget& target); + SnapTarget calculateSnapTarget(double xpos, double ypos); + public: std::vector getDependencies() override { return {{"VulkanContext", &vulkanContext}}; } + void updateWindowManagerInfo(const WindowManagerInfo& info) { + windowManagerInfo = info; + } + void setSwapChainRebuild(bool val); void presentFrame(); @@ -47,6 +115,24 @@ namespace Metal { void disposeManually(); [[nodiscard]] ImGui_ImplVulkanH_Window &getGUIWindow() const; + + void addMouseButtonCallback(std::function callback) { + mouseButtonCallbacks.push_back(std::move(callback)); + } + + void addCursorPosCallback(std::function callback) { + cursorPosCallbacks.push_back(std::move(callback)); + } + + const std::vector> &getMouseButtonCallbacks() const { + return mouseButtonCallbacks; + } + + const std::vector> &getCursorPosCallbacks() const { + return cursorPosCallbacks; + } + + void disposeCursors(); }; } diff --git a/src/editor/EditorPanel.cpp b/src/editor/EditorPanel.cpp index 8626f437..714361f6 100644 --- a/src/editor/EditorPanel.cpp +++ b/src/editor/EditorPanel.cpp @@ -20,7 +20,7 @@ namespace Metal { const char *EditorPanel::NAME_HEADER = "##header_window"; const char *EditorPanel::NAME_FOOTER = "##footer_window"; ImVec2 EditorPanel::CENTER(0.0f, 0.0f); - float EditorPanel::HEADER_HEIGHT = 25; + float EditorPanel::HEADER_HEIGHT = 35; float EditorPanel::FOOTER_HEIGHT = 30; @@ -37,7 +37,7 @@ namespace Metal { UIUtil::AUX_VEC2.y = HEADER_HEIGHT; ImGui::SetNextWindowSize(UIUtil::AUX_VEC2); - SetWindowStyle(); + SetWindowStyle(UIUtil::VEC2_ZERO); ImGui::Begin(NAME_HEADER, &UIUtil::OPEN, FLAGS | ImGuiWindowFlags_NoScrollbar); ImGui::PopStyleVar(3); @@ -56,7 +56,9 @@ namespace Metal { ImGui::SetNextWindowSize(UIUtil::AUX_VEC2); ImGui::SetNextWindowViewport(viewport->ID); - SetWindowStyle(); + UIUtil::AUX_VEC2.x = 4.0f; + UIUtil::AUX_VEC2.y = .0f; + SetWindowStyle(UIUtil::AUX_VEC2); ImGui::Begin(NAME, &UIUtil::OPEN, FLAGS); windowId = ImGui::GetID(NAME); ImGui::PopStyleVar(3); @@ -81,7 +83,7 @@ namespace Metal { UIUtil::AUX_VEC2.y = FOOTER_HEIGHT; ImGui::SetNextWindowSize(UIUtil::AUX_VEC2); - SetWindowStyle(); + SetWindowStyle(UIUtil::VEC2_ZERO); ImGui::Begin(NAME_FOOTER, &UIUtil::OPEN, FLAGS | ImGuiWindowFlags_NoScrollbar); ImGui::PopStyleVar(3); @@ -90,10 +92,10 @@ namespace Metal { } } - void EditorPanel::SetWindowStyle() { + void EditorPanel::SetWindowStyle(const ImVec2 &padding) { ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f); ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f); - ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, UIUtil::VEC2_ZERO); + ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, padding); } void EditorPanel::onSync() { diff --git a/src/editor/EditorPanel.h b/src/editor/EditorPanel.h index f3a97a12..63d4a653 100644 --- a/src/editor/EditorPanel.h +++ b/src/editor/EditorPanel.h @@ -25,7 +25,7 @@ namespace Metal { DockService *dockService = nullptr; ThemeService *themeService = nullptr; - static void SetWindowStyle(); + static void SetWindowStyle(const ImVec2 &padding); void renderDockSpaces(); diff --git a/src/editor/dock-spaces/docks/DockSpacePanel.cpp b/src/editor/dock-spaces/docks/DockSpacePanel.cpp index 60f9c479..4962e07f 100644 --- a/src/editor/dock-spaces/docks/DockSpacePanel.cpp +++ b/src/editor/dock-spaces/docks/DockSpacePanel.cpp @@ -11,6 +11,9 @@ #include "../../../common/LoggerUtil.h" #include "../../repository/EditorRepository.h" #include "../../service/ThemeService.h" +#define BORDER_RADIUS 8.0f +#define OUTSIDE_PADDING 2.0f +#define INSIDE_PADDING 8.0f namespace Metal { const ImVec2 DockSpacePanel::DEFAULT{-1.f, -1.f}; @@ -75,18 +78,22 @@ namespace Metal { initializeView(); } ImGui::SetNextWindowSizeConstraints(MIN_SIZE, MAX_SIZE); - if (padding.x != DEFAULT.x || padding.y != DEFAULT.y) { - ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, padding); - stylePushCount++; - } if (!sizeInitialized && dock->sizeX > 0 && dock->sizeY > 0) { UIUtil::AUX_VEC2.x = dock->sizeX; UIUtil::AUX_VEC2.y = dock->sizeY; ImGui::SetNextWindowSize(UIUtil::AUX_VEC2); sizeInitialized = true; } + ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0)); + ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, BORDER_RADIUS); + ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(0, 0, 0, 0)); + ImGui::PushStyleColor(ImGuiCol_Border, themeService->palette3); + ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f); + stylePushCount = 3; + styleColorPushCount = 2; beforeWindow(); - if (ImGui::Begin(dock->internalId.c_str(), &UIUtil::OPEN, FLAGS)) { + if (ImGui::Begin(dock->internalId.c_str(), &UIUtil::OPEN, + (FLAGS & ~ImGuiWindowFlags_MenuBar) | ImGuiWindowFlags_NoBackground | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse)) { handleShortcut(); sizeInternal = ImGui::GetWindowSize(); size.x = sizeInternal.x; @@ -96,73 +103,130 @@ namespace Metal { dock->sizeY = size.y; position = ImGui::GetWindowPos(); - renderHeader(); - if (view != nullptr) { - view->onSync(); + + ImGui::SetCursorPos(ImVec2(OUTSIDE_PADDING, OUTSIDE_PADDING)); + ImGui::PushStyleVar(ImGuiStyleVar_ChildRounding, BORDER_RADIUS); + ImGui::PushStyleColor(ImGuiCol_ChildBg, themeService->palette0); + ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(INSIDE_PADDING, INSIDE_PADDING)); + if (ImGui::BeginChild((dock->internalId + "island").c_str(), ImVec2(size.x - OUTSIDE_PADDING * 2, size.y - OUTSIDE_PADDING * 2), + ImGuiChildFlags_None, ImGuiWindowFlags_None)) { + if (!dock->isCenter) { + renderCustomHeader(); + } + + ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, padding.x != DEFAULT.x ? padding : ImVec2(INSIDE_PADDING, INSIDE_PADDING)); + if (ImGui::BeginChild((dock->internalId + "content").c_str(), ImVec2(0, 0), ImGuiChildFlags_None, + ImGuiWindowFlags_None)) { + if (view != nullptr) { + view->onSync(); + } + } + ImGui::EndChild(); + ImGui::PopStyleVar(); } + ImGui::EndChild(); + ImGui::PopStyleColor(); + ImGui::PopStyleVar(2); } ImGui::End(); + ImGui::PopStyleColor(styleColorPushCount); ImGui::PopStyleVar(stylePushCount); stylePushCount = 0; + styleColorPushCount = 0; } AbstractDockPanel *DockSpacePanel::getView() const { return view; } - void DockSpacePanel::renderHeader() { - headerPadding.x = ImGui::GetStyle().FramePadding.x; + void DockSpacePanel::renderCustomHeader() { + const float buttonWidth = 23.0f; + const float headerPaddingY = (headerHeight - ImGui::GetFrameHeight()) * 0.5f; - if (ImGui::BeginMenuBar()) { - ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, headerPadding); + ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(ImGui::GetStyle().FramePadding.x, headerPaddingY)); + + // Tab Bar Area + ImGui::BeginGroup(); + + const float availableWidth = ImGui::GetContentRegionAvail().x - buttonWidth - ImGui::GetStyle().ItemSpacing.x; + + if (ImGui::BeginChild((id + "tabs_scroll").c_str(), ImVec2(availableWidth, headerHeight), ImGuiChildFlags_None, + ImGuiWindowFlags_HorizontalScrollbar | ImGuiWindowFlags_NoBackground)) { const bool isFocused = ImGui::IsWindowFocused(ImGuiFocusedFlags_RootAndChildWindows); - ImGui::PushStyleColor(ImGuiCol_TabActive, - isFocused ? editorRepository->accent : themeService->palette0); - if (ImGui::BeginTabBar((id + "dockTabs").c_str(), ImGuiTabBarFlags_AutoSelectNewTabs)) { - for (auto *space: dock->dockSpaces) { - if (space == nullptr) { - continue; - } - const std::string label = space->icon + " " + space->name + id + - std::to_string(space->index); + for (auto *space: dock->dockSpaces) { + if (space == nullptr) continue; - if (ImGui::BeginTabItem(label.c_str(), nullptr)) { - if (dock->selectedOption != space->index) { - dock->selectedOption = space->index; - initializeView(); - } - ImGui::EndTabItem(); - } + const std::string label = space->icon + " " + space->name + "##" + std::to_string(space->index); + const bool isSelected = (dock->selectedOption == space->index); + + if (isSelected) { + ImGui::PushStyleColor(ImGuiCol_Button, + isFocused ? editorRepository->accent : themeService->palette3); + } else { + ImGui::PushStyleColor(ImGuiCol_Button, themeService->palette3); } - ImGui::SetNextItemWidth(23); - if (ImGui::TabItemButton((Icons::add.c_str() + id + "addTab").c_str(), - ImGuiTabItemFlags_Trailing | ImGuiTabItemFlags_NoReorder)) { - ImGui::OpenPopup((id + "NewTabDropdown").c_str()); + + if (ImGui::Button(label.c_str(), ImVec2(0, headerHeight))) { + dock->selectedOption = space->index; + initializeView(); } - if (ImGui::BeginPopup((id + "NewTabDropdown").c_str())) { - ImGui::Text("New Tab"); - ImGui::Separator(); - for (auto *option: DockSpace::OPTIONS_LIST) { - const bool exists = hasDockSpace(option->index); - const std::string label = option->icon + " " + option->name; - if (ImGui::MenuItem(label.c_str(), nullptr, false, !exists)) { - dock->dockSpaces.emplace_back(option); - dock->selectedOption = option->index; - initializeView(); + if (dock->dockSpaces.size() > 1) { + ImGui::SameLine(0, 0); + ImGui::PushStyleColor(ImGuiCol_Button, isSelected ? (isFocused ? editorRepository->accent : themeService->palette3) : themeService->palette3); + if (ImGui::Button((Icons::close + "##close" + std::to_string(space->index) + id).c_str(), ImVec2(0, headerHeight))) { + int indexToRemove = -1; + for (int i = 0; i < dock->dockSpaces.size(); i++) { + if (dock->dockSpaces[i]->index == space->index) { + indexToRemove = i; + break; + } + } + if (indexToRemove != -1) { + dock->dockSpaces.erase(dock->dockSpaces.begin() + indexToRemove); + if (isSelected && !dock->dockSpaces.empty()) { + dock->selectedOption = dock->dockSpaces.front()->index; + initializeView(); + } } } - ImGui::EndPopup(); + ImGui::PopStyleColor(); } - ImGui::EndTabBar(); + ImGui::PopStyleColor(); + ImGui::SameLine(); } - ImGui::PopStyleColor(); - ImGui::PopStyleVar(); - ImGui::EndMenuBar(); } + ImGui::EndChild(); + + ImGui::SameLine(); + + // Add Tab Button + if (UIUtil::ButtonSimple(Icons::add + "##addTab" + id, buttonWidth, headerHeight)) { + ImGui::OpenPopup((id + "NewTabDropdown").c_str()); + } + + if (ImGui::BeginPopup((id + "NewTabDropdown").c_str())) { + ImGui::Text("New Tab"); + ImGui::Separator(); + for (auto *option: DockSpace::OPTIONS_LIST) { + const bool exists = hasDockSpace(option->index); + const std::string label = option->icon + " " + option->name; + if (ImGui::MenuItem(label.c_str(), nullptr, false, !exists)) { + dock->dockSpaces.emplace_back(option); + dock->selectedOption = option->index; + initializeView(); + } + } + ImGui::EndPopup(); + } + + ImGui::EndGroup(); + ImGui::PopStyleVar(); + + ImGui::Separator(); } DockSpace *DockSpacePanel::getSelectedDockSpace() const { diff --git a/src/editor/dock-spaces/docks/DockSpacePanel.h b/src/editor/dock-spaces/docks/DockSpacePanel.h index 911e94bc..cd5f4616 100644 --- a/src/editor/dock-spaces/docks/DockSpacePanel.h +++ b/src/editor/dock-spaces/docks/DockSpacePanel.h @@ -22,11 +22,13 @@ namespace Metal { bool isDownDirection = false; bool sizeInitialized = false; int stylePushCount = 0; + int styleColorPushCount = 0; DockSpacePanel *mainWindow = nullptr; DockDTO *dock = nullptr; AbstractDockPanel *view = nullptr; std::unordered_map views{}; ImVec2 headerPadding{0, 3}; + float headerHeight = 25.0f; EditorRepository *editorRepository = nullptr; ThemeService *themeService = nullptr; @@ -35,6 +37,8 @@ namespace Metal { bool hasDockSpace(int index) const; + void renderCustomHeader(); + public: std::vector getDependencies() override { return { @@ -67,8 +71,6 @@ namespace Metal { [[nodiscard]] AbstractDockPanel *getView() const; - void renderHeader(); - void beforeWindow() const; ImVec2 &getPosition(); diff --git a/src/editor/dock-spaces/footer/EditorFooterPanel.cpp b/src/editor/dock-spaces/footer/EditorFooterPanel.cpp index 0a427db7..adae38ea 100644 --- a/src/editor/dock-spaces/footer/EditorFooterPanel.cpp +++ b/src/editor/dock-spaces/footer/EditorFooterPanel.cpp @@ -3,10 +3,10 @@ #include "../../util/UIUtil.h" #include "../../../ApplicationContext.h" #include "../../repository/EditorRepository.h" +#include "../../service/ThemeService.h" namespace Metal { void EditorFooterPanel::onSync() { - ImGui::Separator(); asyncTaskPanel->onSync(); ImGui::SameLine(); renderShortcuts(); @@ -20,8 +20,13 @@ namespace Metal { void EditorFooterPanel::framerate() { const int framerate = static_cast(round(ImGui::GetIO().Framerate)); if (framerate > 0) { - ImGui::SameLine(ImGui::GetWindowWidth() - 100); + ImGui::SameLine(ImGui::GetWindowWidth() - 130); ImGui::Text("%i ms | %i fps", 1000 / framerate, framerate); + ImGui::SameLine(); + if (UIUtil::ButtonSimple((editorRepository->isDarkMode ? Icons::light_mode : Icons::dark_mode) + id + "theme", + UIUtil::ONLY_ICON_BUTTON_SIZE, UIUtil::ONLY_ICON_BUTTON_SIZE)) { + editorRepository->isDarkMode = !editorRepository->isDarkMode; + } } } diff --git a/src/editor/dock-spaces/footer/EditorFooterPanel.h b/src/editor/dock-spaces/footer/EditorFooterPanel.h index 9f4ec717..2e12a08a 100644 --- a/src/editor/dock-spaces/footer/EditorFooterPanel.h +++ b/src/editor/dock-spaces/footer/EditorFooterPanel.h @@ -5,20 +5,22 @@ namespace Metal { struct EditorRepository; - + class ThemeService; class AsyncTaskPanel; class EditorFooterPanel final : public AbstractPanel { EditorRepository *editorRepository = nullptr; + ThemeService *themeService = nullptr; AsyncTaskPanel *asyncTaskPanel = nullptr; void renderShortcuts(); - static void framerate(); + void framerate(); public: std::vector getDependencies() override { return { - {"EditorRepository", &editorRepository} + {"EditorRepository", &editorRepository}, + {"ThemeService", &themeService} }; } diff --git a/src/editor/dock-spaces/header/EditorHeaderPanel.cpp b/src/editor/dock-spaces/header/EditorHeaderPanel.cpp index ae5ee5f4..6aba4425 100644 --- a/src/editor/dock-spaces/header/EditorHeaderPanel.cpp +++ b/src/editor/dock-spaces/header/EditorHeaderPanel.cpp @@ -4,77 +4,121 @@ #include "../../../core/DirectoryService.h" #include "../../../core/glfw/GLFWContext.h" #include "../../../engine/EngineContext.h" +#include "editor/service/ThemeService.h" +#define HEIGHT 35.0f namespace Metal { void EditorHeaderPanel::onSync() { + ImGui::SetCursorPosX(5); + ImGui::SetCursorPosY(0); renderFileTab(); - ImGui::Dummy(ImVec2(0, UIUtil::ONLY_ICON_BUTTON_SIZE)); - ImGui::Dummy(ImVec2(2, 0)); - ImGui::Separator(); + renderWindowControls(); } void EditorHeaderPanel::renderWindowControls() { - ImGui::SameLine(ImGui::GetWindowWidth() - (UIUtil::ONLY_ICON_BUTTON_SIZE * 3 + 20)); + ImGui::SameLine(ImGui::GetWindowWidth() - (HEIGHT * 3)); + ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0, 0)); + ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 0)); + ImGui::PushStyleColor(ImGuiCol_Border, themeService->palette1); + ImGui::PushStyleColor(ImGuiCol_Button, themeService->palette1); GLFWwindow *window = glfwContext->getWindow(); - if (UIUtil::ButtonSimple((Icons::minimize + id + "min"), UIUtil::ONLY_ICON_BUTTON_SIZE, - UIUtil::ONLY_ICON_BUTTON_SIZE)) { + WindowManagerInfo info; + info.menuBarHeight = HEIGHT; + ImGui::PushStyleColor(ImGuiCol_ButtonHovered, themeService->palette3); + + if (UIUtil::ButtonSimple((Icons::minimize + id + "min"), HEIGHT, HEIGHT)) { glfwIconifyWindow(window); } + info.minimizeBtnRect = ImRect(ImGui::GetItemRectMin(), ImGui::GetItemRectMax()); ImGui::SameLine(); bool isMaximized = glfwGetWindowAttrib(window, GLFW_MAXIMIZED); if (UIUtil::ButtonSimple((isMaximized ? Icons::filter_none : Icons::crop_square) + id + "max", - UIUtil::ONLY_ICON_BUTTON_SIZE, UIUtil::ONLY_ICON_BUTTON_SIZE)) { + HEIGHT, HEIGHT)) { if (isMaximized) { glfwRestoreWindow(window); } else { glfwMaximizeWindow(window); } } + ImGui::PopStyleColor(); + + info.maximizeBtnRect = ImRect(ImGui::GetItemRectMin(), ImGui::GetItemRectMax()); ImGui::SameLine(); - if (UIUtil::ButtonSimple(Icons::close + id + "close", UIUtil::ONLY_ICON_BUTTON_SIZE, - UIUtil::ONLY_ICON_BUTTON_SIZE)) { + ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0.9f, 0.1f, 0.1f, 1.0f)); + if (UIUtil::ButtonSimple(Icons::close + id + "close", HEIGHT, HEIGHT)) { glfwSetWindowShouldClose(window, GLFW_TRUE); } + info.closeBtnRect = ImRect(ImGui::GetItemRectMin(), ImGui::GetItemRectMax()); + ImGui::PopStyleColor(); + + ImGui::PopStyleColor(2); + ImGui::PopStyleVar(2); + + int w, h; + glfwGetWindowSize(window, &w, &h); + info.windowWidth = w; + info.windowHeight = h; + + GLFWmonitor *monitor = glfwGetPrimaryMonitor(); + const GLFWvidmode *mode = glfwGetVideoMode(monitor); + if (mode) { + info.screenWidth = mode->width; + info.screenHeight = mode->height; + } + + glfwContext->updateWindowManagerInfo(info); + } + + void EditorHeaderPanel::renderMenu(const char *label, std::function itemsFunc) { + if (ImGui::Button(label, ImVec2(0, HEIGHT))) { + ImGui::OpenPopup(label); + } + if (ImGui::BeginPopup(label)) { + itemsFunc(); + ImGui::EndPopup(); + } } void EditorHeaderPanel::renderFileTab() { - if (ImGui::BeginMainMenuBar()) { - if (UIUtil::ButtonSimple(Icons::save, UIUtil::ONLY_ICON_BUTTON_SIZE, UIUtil::ONLY_ICON_BUTTON_SIZE)) { - directoryService->save(); + ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(10, 10)); + ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(10, 0)); + ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0, 0, 0, 0)); + + if (UIUtil::ButtonSimple(Icons::save, HEIGHT, HEIGHT)) { + directoryService->save(); + } + ImGui::SameLine(); + + ImGui::SetCursorPosY(0); + + + renderMenu("File", [this] { + if (ImGui::MenuItem("Open", "Ctrl+O")) { + engineContext->dispose(); + directoryService->updateRootPath(true); } - ImGui::SameLine(); - if (ImGui::BeginMenu("File")) { - if (ImGui::MenuItem("Open", "Ctrl+O")) { - engineContext->dispose(); - directoryService->updateRootPath(true); - } - if (ImGui::MenuItem("Save", "Ctrl+S")) { - directoryService->save(); - } - ImGui::Separator(); - if (ImGui::MenuItem("Exit")) { - exit(0); - } - ImGui::EndMenu(); + if (ImGui::MenuItem("Save", "Ctrl+S")) { + directoryService->save(); } - - // Edit menu - if (ImGui::BeginMenu("Edit")) { - if (ImGui::MenuItem("Compile shaders")) { - engineContext->dispose(); - } - ImGui::EndMenu(); + ImGui::Separator(); + if (ImGui::MenuItem("Exit")) { + exit(0); } + }); + ImGui::SameLine(); - // Window controls (minimize, maximize, close) - renderWindowControls(); + renderMenu("Edit", [this] { + if (ImGui::MenuItem("Compile shaders")) { + engineContext->dispose(); + } + }); - ImGui::EndMainMenuBar(); - } + ImGui::PopStyleColor(); + ImGui::PopStyleVar(2); } } diff --git a/src/editor/dock-spaces/header/EditorHeaderPanel.h b/src/editor/dock-spaces/header/EditorHeaderPanel.h index 032e7ab5..7973077c 100644 --- a/src/editor/dock-spaces/header/EditorHeaderPanel.h +++ b/src/editor/dock-spaces/header/EditorHeaderPanel.h @@ -1,10 +1,13 @@ #ifndef METAL_ENGINE_EDITORHEADERPANEL_H #define METAL_ENGINE_EDITORHEADERPANEL_H +#include + #include "../../abstract/AbstractPanel.h" #include namespace Metal { + class ThemeService; class GLFWContext; class EngineContext; struct DirectoryService; @@ -13,17 +16,23 @@ namespace Metal { GLFWContext *glfwContext = nullptr; EngineContext *engineContext = nullptr; DirectoryService *directoryService = nullptr; + ThemeService *themeService = nullptr; + + float menuBarHeight = 0; void renderFileTab(); void renderWindowControls(); + void renderMenu(const char *label, std::function itemsFunc); + public: std::vector getDependencies() override { return { {"GLFWContext", &glfwContext}, {"EngineContext", &engineContext}, - {"DirectoryService", &directoryService} + {"DirectoryService", &directoryService}, + {"ThemeService", &themeService} }; } diff --git a/src/editor/dock-spaces/viewport/EngineFramePanel.cpp b/src/editor/dock-spaces/viewport/EngineFramePanel.cpp index 12f6587c..acb2ebbb 100644 --- a/src/editor/dock-spaces/viewport/EngineFramePanel.cpp +++ b/src/editor/dock-spaces/viewport/EngineFramePanel.cpp @@ -76,11 +76,17 @@ namespace Metal { auto *framebuffer = engineContext->currentFrame->getResourceAs(RID_POST_PROCESSING_FBO); if (framebuffer) { descriptorSetService->setImageDescriptor(framebuffer, 0); - ImGui::Image(reinterpret_cast(framebuffer->attachments[0]->imageDescriptor->vkDescriptorSet), - viewportSize); + + const ImVec2 pos = ImGui::GetCursorScreenPos(); + const auto textureId = reinterpret_cast(framebuffer->attachments[0]->imageDescriptor->vkDescriptorSet); + + ImGui::GetWindowDrawList()->AddImageRounded(textureId, pos, ImVec2(pos.x + viewportSize.x, pos.y + viewportSize.y), + ImVec2(0, 0), ImVec2(1, 1), IM_COL32_WHITE, 8.0f); + + ImGui::Dummy(viewportSize); - const ImVec2 imageMin = ImGui::GetItemRectMin(); - const ImVec2 imageMax = ImGui::GetItemRectMax(); + const ImVec2 imageMin = pos; + const ImVec2 imageMax = ImVec2(pos.x + viewportSize.x, pos.y + viewportSize.y); handleViewportPicking(imageMin, imageMax); } } diff --git a/src/editor/dto/DockDTO.h b/src/editor/dto/DockDTO.h index 1d3b84f3..92edec34 100644 --- a/src/editor/dto/DockDTO.h +++ b/src/editor/dto/DockDTO.h @@ -9,6 +9,7 @@ namespace Metal { struct DockDTO { + bool isCenter = false; const std::string id = Util::uuidV4(); ImGuiID nodeId{}; int selectedOption; diff --git a/src/editor/service/DockService.cpp b/src/editor/service/DockService.cpp index cf2f9182..b259d216 100644 --- a/src/editor/service/DockService.cpp +++ b/src/editor/service/DockService.cpp @@ -10,24 +10,26 @@ namespace Metal { void DockService::onInitialize() { auto *rightT = new DockDTO{&DockSpace::WORLD}; - auto *leftTop = new DockDTO{&DockSpace::REPOSITORIES}; - auto *leftDown = new DockDTO{&DockSpace::INSPECTOR}; - auto *downLeft = new DockDTO{&DockSpace::CONSOLE}; - auto *downRight = new DockDTO{&DockSpace::FILES}; + auto *leftT = new DockDTO{&DockSpace::REPOSITORIES}; + auto *leftB = new DockDTO{&DockSpace::INSPECTOR}; + auto *rightB = new DockDTO{&DockSpace::CONSOLE}; + auto *b = new DockDTO{&DockSpace::FILES}; + center.isCenter = true; center.sizeRatioForNodeAtDir = 0.5f; rightT->sizeRatioForNodeAtDir = 0.25f; - leftTop->sizeRatioForNodeAtDir = 0.2f; - leftDown->sizeRatioForNodeAtDir = 0.5f; - downLeft->sizeRatioForNodeAtDir = 0.25f; - downRight->sizeRatioForNodeAtDir = 0.5f; + leftT->sizeRatioForNodeAtDir = 0.2f; + leftB->sizeRatioForNodeAtDir = 0.5f; + rightB->sizeRatioForNodeAtDir = 0.25f; + b->sizeRatioForNodeAtDir = 0.25f; right.push_back(rightT); - left.push_back(leftTop); - left.push_back(leftDown); + right.push_back(rightB); - bottom.push_back(downLeft); - bottom.push_back(downRight); + left.push_back(leftT); + left.push_back(leftB); + + bottom.push_back(b); } void DockService::buildViews(ImGuiID windowId, AbstractPanel *panel) { diff --git a/src/editor/service/DockService.h b/src/editor/service/DockService.h index c8b8de89..23d585dc 100644 --- a/src/editor/service/DockService.h +++ b/src/editor/service/DockService.h @@ -15,7 +15,6 @@ namespace Metal { std::vector left; std::vector right; - bool isInitialized = false; public: diff --git a/src/editor/service/ThemeService.cpp b/src/editor/service/ThemeService.cpp index d508d959..fc1bb51b 100644 --- a/src/editor/service/ThemeService.cpp +++ b/src/editor/service/ThemeService.cpp @@ -1,13 +1,57 @@ #include "ThemeService.h" #include +#include +#include +#include #include "../repository/EditorRepository.h" namespace Metal { glm::vec3 ThemeService::BACKGROUND_COLOR = glm::vec3(0.f); + void ThemeService::loadTheme() { + if (themeLoaded) return; + + std::string filename = "theme.json"; + if (!std::filesystem::exists(filename)) { + filename = "resources/theme.json"; + } + + if (std::filesystem::exists(filename)) { + try { + std::ifstream f(filename); + themeData = nlohmann::json::parse(f); + themeLoaded = true; + } catch (const std::exception& e) { + std::cerr << "Failed to parse theme.json: " << e.what() << std::endl; + } + } else { + std::cerr << "theme.json not found in root or resources directory." << std::endl; + } + } + + ImVec4 ThemeService::hexToRGBA(const std::string& hex) { + std::string h = hex; + if (h[0] == '#') h = h.substr(1); + + if (h.length() == 6) { + int r = std::stoi(h.substr(0, 2), nullptr, 16); + int g = std::stoi(h.substr(2, 2), nullptr, 16); + int b = std::stoi(h.substr(4, 2), nullptr, 16); + return ImVec4(r / 255.0f, g / 255.0f, b / 255.0f, 1.0f); + } else if (h.length() == 8) { + int r = std::stoi(h.substr(0, 2), nullptr, 16); + int g = std::stoi(h.substr(2, 2), nullptr, 16); + int b = std::stoi(h.substr(4, 2), nullptr, 16); + int a = std::stoi(h.substr(6, 2), nullptr, 16); + return ImVec4(r / 255.0f, g / 255.0f, b / 255.0f, a / 255.0f); + } + return ImVec4(1.0f, 1.0f, 1.0f, 1.0f); // Default white + } + void ThemeService::onSync() { + loadTheme(); if (previousTheme == editorRepository->isDarkMode && glm::length(editorRepository->accentColor) == prevLength) { return; } @@ -31,7 +75,7 @@ namespace Metal { colors[ImGuiCol_WindowBg] = palette1; colors[ImGuiCol_ChildBg] = palette1; colors[ImGuiCol_PopupBg] = palette1; - colors[ImGuiCol_Border] = palette3; + colors[ImGuiCol_Border] = palette1; colors[ImGuiCol_BorderShadow] = ImVec4(0.f, 0.f, 0.f, 0.f); colors[ImGuiCol_FrameBg] = palette2; colors[ImGuiCol_TitleBg] = palette1; @@ -44,10 +88,8 @@ namespace Metal { colors[ImGuiCol_ScrollbarGrabActive] = palette2; colors[ImGuiCol_SliderGrab] = palette4; colors[ImGuiCol_ButtonActive] = palette2; - colors[ImGuiCol_Separator] = palette5; - colors[ImGuiCol_SeparatorHovered] = palette6; - colors[ImGuiCol_SeparatorActive] = palette6; - colors[ImGuiCol_ResizeGrip] = palette4; + colors[ImGuiCol_Separator] = palette1; + colors[ImGuiCol_ResizeGrip] = palette1; colors[ImGuiCol_Tab] = palette2; colors[ImGuiCol_TabHovered] = palette3; colors[ImGuiCol_DockingPreview] = palette4; @@ -87,24 +129,30 @@ namespace Metal { } void ThemeService::setDarkMode() { - palette0 = ImVec4(10.0f / 255.0f, 10.0f / 255.0f, 10.0f / 255.0f, 1.0f); - palette1 = ImVec4(18.0f / 255.0f, 18.0f / 255.0f, 18.0f / 255.0f, 1.0f); - palette2 = ImVec4(22.0f / 255.0f, 22.0f / 255.0f, 22.0f / 255.0f, 1.0f); - neutralPalette = palette2; - palette3 = ImVec4(35.0f / 255.0f, 35.0f / 255.0f, 35.0f / 255.0f, 1.0f); - palette4 = ImVec4(65.0f / 255.0f, 65.0f / 255.0f, 65.0f / 255.0f, 1.0f); - palette5 = ImVec4(119.0f / 255.0f, 119.0f / 255.0f, 119.0f / 255.0f, 1.0f); - palette6 = ImVec4(224.0f / 255.0f, 224.0f / 255.0f, 224.0f / 255.0f, 1.0f); + if (themeLoaded && themeData.contains("dark")) { + auto& dark = themeData["dark"]; + palette0 = hexToRGBA(dark.value("palette0", "#121212")); + palette1 = hexToRGBA(dark.value("palette1", "#0A0A0A")); + palette2 = hexToRGBA(dark.value("palette2", "#161616")); + palette3 = hexToRGBA(dark.value("palette3", "#232323")); + palette4 = hexToRGBA(dark.value("palette4", "#414141")); + palette5 = hexToRGBA(dark.value("palette5", "#777777")); + palette6 = hexToRGBA(dark.value("palette6", "#E0E0E0")); + neutralPalette = hexToRGBA(dark.value("neutralPalette", "#161616")); + } } void ThemeService::setLightMode() { - palette0 = ImVec4(245.0f / 255.0f, 245.0f / 255.0f, 245.0f / 255.0f, 1.0f); // light gray - palette1 = ImVec4(235.0f / 255.0f, 235.0f / 255.0f, 235.0f / 255.0f, 1.0f); // slightly darker gray - palette2 = ImVec4(225.0f / 255.0f, 225.0f / 255.0f, 225.0f / 255.0f, 1.0f); // medium gray - neutralPalette = palette2; - palette3 = ImVec4(200.0f / 255.0f, 200.0f / 255.0f, 200.0f / 255.0f, 1.0f); // darker gray - palette4 = ImVec4(160.0f / 255.0f, 160.0f / 255.0f, 160.0f / 255.0f, 1.0f); // even darker gray - palette5 = ImVec4(120.0f / 255.0f, 120.0f / 255.0f, 120.0f / 255.0f, 1.0f); // dark gray - palette6 = ImVec4(10.0f / 255.0f, 10.0f / 255.0f, 10.0f / 255.0f, 1.0f); // very dark gray + if (themeLoaded && themeData.contains("light")) { + auto& light = themeData["light"]; + palette0 = hexToRGBA(light.value("palette0", "#EBEBEB")); + palette1 = hexToRGBA(light.value("palette1", "#F5F5F5")); + palette2 = hexToRGBA(light.value("palette2", "#E1E1E1")); + palette3 = hexToRGBA(light.value("palette3", "#C8C8C8")); + palette4 = hexToRGBA(light.value("palette4", "#A0A0A0")); + palette5 = hexToRGBA(light.value("palette5", "#787878")); + palette6 = hexToRGBA(light.value("palette6", "#0A0A0A")); + neutralPalette = hexToRGBA(light.value("neutralPalette", "#E1E1E1")); + } } } // Metal diff --git a/src/editor/service/ThemeService.h b/src/editor/service/ThemeService.h index 4ccf93a6..52953edc 100644 --- a/src/editor/service/ThemeService.h +++ b/src/editor/service/ThemeService.h @@ -2,14 +2,24 @@ #define THEMESERVICE_H #include #include +#include +#include + #include "../../common/IService.h" #include "../../common/ISync.h" - namespace Metal { struct EditorRepository; + class ThemeService final : public IService, public ISync { EditorRepository *editorRepository = nullptr; + nlohmann::json themeData; + bool themeLoaded = false; + + void loadTheme(); + + static ImVec4 hexToRGBA(const std::string &hex); + public: ImVec4 neutralPalette{}; ImVec4 palette0{}; diff --git a/src/main.cpp b/src/main.cpp index 8e452fdc..9202828c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -43,7 +43,7 @@ #include "engine/EngineContext.h" int main(int, char **) { - std::shared_ptr context = std::make_shared(false); + std::shared_ptr context = std::make_shared(true); // --- ORDER MATTERS context->registerSingleton(context);