diff --git a/Game/Data/World.cpp b/Game/Data/World.cpp index 1d19b54..689a333 100644 --- a/Game/Data/World.cpp +++ b/Game/Data/World.cpp @@ -236,7 +236,7 @@ void RenderWorldEditorUI(World& world) static char worldFilePath[256] = "../world.bin"; ImGui::InputText("World File", worldFilePath, sizeof(worldFilePath)); - String path = GetAssetPath(temp.Arena, WrapString(worldFilePath)); + String path = GetAssetPath(temp.Arena, AssetType::JAsset, ConstString(worldFilePath)); if (ImGui::Button("Save World")) { diff --git a/Juliet/include/Core/HAL/Filesystem/Filesystem.h b/Juliet/include/Core/HAL/Filesystem/Filesystem.h index 0bfbad9..c71f33b 100644 --- a/Juliet/include/Core/HAL/Filesystem/Filesystem.h +++ b/Juliet/include/Core/HAL/Filesystem/Filesystem.h @@ -2,16 +2,19 @@ #include -// Returns the path to the application directory -[[nodiscard]] extern JULIET_API String GetBasePath(); +enum class AssetType +{ + JAsset, + Shader +}; -// Returns the resolved base path to the compiled shaders directory. -// In dev, this resolves to ../../Assets/compiled/ relative to the exe. -// In shipping, this resolves to Assets/Shaders/ next to the exe. -[[nodiscard]] extern JULIET_API String GetAssetBasePath(); +// Returns the path to the application directory +extern JULIET_API String GetBasePath(); + +// Path to the /Assets/ folder +extern JULIET_API String GetAssetBasePath(); // Builds a full path to an asset file given its filename (e.g. "Triangle.vert.dxil"). -// The caller owns the returned buffer and must free it. -[[nodiscard]] extern JULIET_API String GetAssetPath(NonNullPtr arena, String filename); +extern JULIET_API String GetAssetPath(NonNullPtr arena, AssetType type, String filename); -[[nodiscard]] extern JULIET_API bool IsAbsolutePath(String path); +extern JULIET_API bool IsAbsolutePath(String path); diff --git a/Juliet/src/Core/HAL/Filesystem/Filesystem.cpp b/Juliet/src/Core/HAL/Filesystem/Filesystem.cpp index f1f3a6e..c84f216 100644 --- a/Juliet/src/Core/HAL/Filesystem/Filesystem.cpp +++ b/Juliet/src/Core/HAL/Filesystem/Filesystem.cpp @@ -10,8 +10,9 @@ namespace { - String CachedBasePath = {}; - String CachedAssetBasePath = {}; + String CachedBasePath = {}; + String CachedAssetBasePath = {}; + String CachedShaderBasePath = {}; bool DirectoryExists(const char* path) { @@ -33,18 +34,32 @@ String GetAssetBasePath() return CachedAssetBasePath; } -[[nodiscard]] String GetAssetPath(NonNullPtr arena, String filename) +String GetAssetPath(NonNullPtr arena, AssetType type, String filename) { - // TODO: Path is Assets/Compiled, we need to fix that one day - Assert(IsValid(CachedAssetBasePath)); - Assert(IsValid(filename)); + String asset_path = {}; + switch (type) + { + case AssetType::Shader: + { + Assert(IsValid(CachedShaderBasePath)); + Assert(IsValid(filename)); - size_t totalSize = CachedAssetBasePath.Size + filename.Size + 1; - char* buffer = ArenaPushArray(arena, totalSize); - Assert(buffer); + size_t totalSize = CachedShaderBasePath.Size + filename.Size + 1; + char* buffer = ArenaPushArray(arena, totalSize); + Assert(buffer); - juliet_snprintf(buffer, totalSize, "%s%s", CStr(CachedAssetBasePath), CStr(filename)); - return { buffer, totalSize - 1 }; + juliet_snprintf(buffer, totalSize, "%s%s", CStr(CachedShaderBasePath), CStr(filename)); + asset_path = { buffer, totalSize - 1 }; + } + break; + default: + { + asset_path = GetAssetBasePath(); + } + break; + } + + return asset_path; } bool IsAbsolutePath(String path) @@ -63,10 +78,10 @@ void InitFilesystem(NonNullPtr arena) String basePath = GetBasePath(); Assert(IsValid(basePath)); - // Probe candidate paths for compiled shader directory - // 1. Shipping layout: Assets/Shaders/ next to the exe - // 2. Dev layout: ../../Assets/compiled/ (exe is in bin/x64Clang-/) - constexpr const char* kCandidates[] = { "Assets/Shaders/", "../../Assets/compiled/" }; + // Probe candidate paths base asset folder + // 1. Shipping layout: Assets/ next to the exe + // 2. Dev layout: ../../Assets/ (exe is in bin/x64Clang-/) + constexpr const char* kCandidates[] = { "Assets/", "../../Assets/" }; for (const char* candidate : kCandidates) { @@ -82,6 +97,29 @@ void InitFilesystem(NonNullPtr arena) CachedAssetBasePath = { buffer, len }; Log(LogLevel::Message, LogCategory::Core, "Asset base path: %s", buffer); } + break; + } + } + + // Probe candidate paths for compiled shader directory + // 1. Shipping layout: Assets/Shaders/ + // 2. Dev layout: Assets/compiled/ + constexpr const char* kCandidatesShader[] = { "Shaders/", "compiled/" }; + + for (const char* candidate : kCandidatesShader) + { + char probePath[512]; + juliet_snprintf(probePath, sizeof(probePath), "%s%s", CStr(CachedAssetBasePath), candidate); + + if (DirectoryExists(probePath)) + { + size_t len = strlen(probePath); + if (char* buffer = ArenaPushArray(arena, len + 1 JULIET_DEBUG_PARAM("CachedShaderBasePath"))) + { + juliet_snprintf(buffer, len + 1, "%s", probePath); + CachedShaderBasePath = { buffer, len }; + Log(LogLevel::Message, LogCategory::Core, "Shader base path: %s", buffer); + } return; } } @@ -91,8 +129,10 @@ void InitFilesystem(NonNullPtr arena) void ShutdownFilesystem() { - CachedBasePath.Size = 0; - CachedBasePath.Str = nullptr; - CachedAssetBasePath.Size = 0; - CachedAssetBasePath.Str = nullptr; + CachedBasePath.Size = 0; + CachedBasePath.Str = nullptr; + CachedAssetBasePath.Size = 0; + CachedAssetBasePath.Str = nullptr; + CachedShaderBasePath.Size = 0; + CachedShaderBasePath.Str = nullptr; } diff --git a/Juliet/src/Graphics/DebugDisplayRenderer.cpp b/Juliet/src/Graphics/DebugDisplayRenderer.cpp index f957e4d..baac7dc 100644 --- a/Juliet/src/Graphics/DebugDisplayRenderer.cpp +++ b/Juliet/src/Graphics/DebugDisplayRenderer.cpp @@ -86,11 +86,11 @@ namespace TempArena path = scratch_begin(0, 0); - String vertPath = GetAssetPath(path.Arena, WrapString("Debug.vert.dxil")); + String vertPath = GetAssetPath(path.Arena, AssetType::Shader, ConstString("Debug.vert.dxil")); shaderCI.Stage = ShaderStage::Vertex; Shader* vertexShader = CreateShader(device, vertPath, shaderCI); - String fragPath = GetAssetPath(path.Arena, WrapString("Debug.frag.dxil")); + String fragPath = GetAssetPath(path.Arena, AssetType::Shader, ConstString("Debug.frag.dxil")); shaderCI.Stage = ShaderStage::Fragment; Shader* fragmentShader = CreateShader(device, fragPath, shaderCI); diff --git a/Juliet/src/Graphics/ImGuiRenderer.cpp b/Juliet/src/Graphics/ImGuiRenderer.cpp index 6c18100..7ab1a87 100644 --- a/Juliet/src/Graphics/ImGuiRenderer.cpp +++ b/Juliet/src/Graphics/ImGuiRenderer.cpp @@ -131,11 +131,11 @@ bool ImGuiRenderer_Initialize(GraphicsDevice* device) TempArena path = scratch_begin(0, 0); - String vertPath = GetAssetPath(path.Arena, WrapString("ImGui.vert.dxil")); + String vertPath = GetAssetPath(path.Arena, AssetType::Shader, ConstString("ImGui.vert.dxil")); shaderCI.Stage = ShaderStage::Vertex; g_ImGuiState.VertexShader = CreateShader(device, vertPath, shaderCI); - String fragPath = GetAssetPath(path.Arena, WrapString("ImGui.frag.dxil")); + String fragPath = GetAssetPath(path.Arena, AssetType::Shader, ConstString("ImGui.frag.dxil")); shaderCI.Stage = ShaderStage::Fragment; g_ImGuiState.FragmentShader = CreateShader(device, fragPath, shaderCI); @@ -401,10 +401,10 @@ void ImGuiRenderer_Render(CommandList* cmdList, RenderPass* renderPass) // Set scissor rect (clipping rectangle) struct Rectangle scissorRect = {}; - scissorRect.X = static_cast(clip_min.x); - scissorRect.Y = static_cast(clip_min.y); - scissorRect.Width = static_cast(clip_max.x - clip_min.x); - scissorRect.Height = static_cast(clip_max.y - clip_min.y); + scissorRect.X = static_cast(clip_min.x); + scissorRect.Y = static_cast(clip_min.y); + scissorRect.Width = static_cast(clip_max.x - clip_min.x); + scissorRect.Height = static_cast(clip_max.y - clip_min.y); SetScissorRect(renderPass, scissorRect); // Bind Texture diff --git a/Juliet/src/Graphics/MeshRenderer.cpp b/Juliet/src/Graphics/MeshRenderer.cpp index e4ed512..a9e0984 100644 --- a/Juliet/src/Graphics/MeshRenderer.cpp +++ b/Juliet/src/Graphics/MeshRenderer.cpp @@ -81,11 +81,11 @@ bool InitializeMeshRendererGraphics(NonNullPtr device, NonNullPt TempArena path = scratch_begin(0, 0); - String shaderPath = GetAssetPath(path.Arena, WrapString("Triangle.vert.dxil")); + String shaderPath = GetAssetPath(path.Arena, AssetType::Shader, ConstString("Triangle.vert.dxil")); shaderCI.Stage = ShaderStage::Vertex; Shader* vertexShader = CreateShader(graphicsDevice, shaderPath, shaderCI); - shaderPath = GetAssetPath(path.Arena, WrapString("SolidColor.frag.dxil")); + shaderPath = GetAssetPath(path.Arena, AssetType::Shader, ConstString("SolidColor.frag.dxil")); shaderCI.Stage = ShaderStage::Fragment; Shader* fragmentShader = CreateShader(graphicsDevice, shaderPath, shaderCI); @@ -149,8 +149,7 @@ bool InitializeMeshRendererGraphics(NonNullPtr device, NonNullPt transformsBufferCI.IsDynamic = true; g_MeshRenderer.TransformsBuffer = CreateGraphicsBuffer(graphicsDevice, transformsBufferCI); Assert(g_MeshRenderer.TransformsBuffer != nullptr); - g_MeshRenderer.MappedTransforms = - static_cast(MapGraphicsBuffer(graphicsDevice, g_MeshRenderer.TransformsBuffer)); + g_MeshRenderer.MappedTransforms = static_cast(MapGraphicsBuffer(graphicsDevice, g_MeshRenderer.TransformsBuffer)); Assert(g_MeshRenderer.MappedTransforms != nullptr); // Sync existing lights that might have been added before graphics initialization @@ -551,11 +550,11 @@ void ReloadMeshRendererShaders() String entryPoint = WrapString("main"); ShaderCreateInfo shaderCI = {}; shaderCI.EntryPoint = entryPoint; - String shaderPath = GetAssetPath(path.Arena, WrapString("Triangle.vert.dxil")); + String shaderPath = GetAssetPath(path.Arena, AssetType::Shader, ConstString("Triangle.vert.dxil")); shaderCI.Stage = ShaderStage::Vertex; Shader* vertexShader = CreateShader(device, shaderPath, shaderCI); - shaderPath = GetAssetPath(path.Arena, WrapString("SolidColor.frag.dxil")); + shaderPath = GetAssetPath(path.Arena, AssetType::Shader, ConstString("SolidColor.frag.dxil")); shaderCI.Stage = ShaderStage::Fragment; Shader* fragmentShader = CreateShader(device, shaderPath, shaderCI); diff --git a/Juliet/src/Graphics/SkyboxRenderer.cpp b/Juliet/src/Graphics/SkyboxRenderer.cpp index c1e920c..36c8f75 100644 --- a/Juliet/src/Graphics/SkyboxRenderer.cpp +++ b/Juliet/src/Graphics/SkyboxRenderer.cpp @@ -24,14 +24,14 @@ bool InitializeSkyboxRenderer(NonNullPtr device, NonNullPtr