Skip to content

Commit

Permalink
stringcrc as map key
Browse files Browse the repository at this point in the history
  • Loading branch information
T-rvw committed Nov 10, 2023
1 parent 35aafaf commit 63e05e1
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 56 deletions.
10 changes: 5 additions & 5 deletions Engine/Source/Editor/Resources/ResourceBuilder.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include "ResourceBuilder.h"

#include "Base/Template.h"
#include "Log/Log.h"
#include "Path/Path.h"
#include "Time/Clock.h"
#include "Log/Log.h"

#include <cassert>

Expand All @@ -13,7 +13,7 @@ namespace editor
ResourceBuilder::ResourceBuilder()
{
std::string modifyCachePath = GetModifyCacheFilePath();
if (std::filesystem::exists(cd::MoveTemp(modifyCachePath)))
if (engine::Path::FileExists(modifyCachePath.c_str()))
{
ReadModifyCacheFile();
}
Expand Down Expand Up @@ -61,7 +61,7 @@ void ResourceBuilder::WriteModifyCacheFile()

std::string modifyCachePath = GetModifyCacheFilePath();

if (!std::filesystem::exists(modifyCachePath))
if (!engine::Path::FileExists(modifyCachePath.c_str()))
{
CD_INFO("Creating modify cache file at : {0}", modifyCachePath);
std::filesystem::create_directories(std::filesystem::path(modifyCachePath).parent_path());
Expand Down Expand Up @@ -111,7 +111,7 @@ ProcessStatus ResourceBuilder::CheckFileStatus(const char* pInputFilePath, const

const char* key = pOutputFilePath;

if (!std::filesystem::exists(pInputFilePath))
if (!engine::Path::FileExists(pInputFilePath))
{
CD_ERROR("Input file path {0} does not exist!", pInputFilePath);
return ProcessStatus::InputNotExist;
Expand All @@ -133,7 +133,7 @@ ProcessStatus ResourceBuilder::CheckFileStatus(const char* pInputFilePath, const
return ProcessStatus::InputModified;
}

if (!std::filesystem::exists(pOutputFilePath))
if (!engine::Path::FileExists(pOutputFilePath))
{
CD_INFO("Output file path {0} dose not exist.", pOutputFilePath);
return ProcessStatus::OutputNotExist;
Expand Down
16 changes: 16 additions & 0 deletions Engine/Source/Runtime/Core/StringCrc.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class TStringCrc final
~TStringCrc() = default;

constexpr T Value() const { return m_hashValue; }
bool operator<(const TStringCrc& other) const { return m_hashValue < other.m_hashValue; }
bool operator>(const TStringCrc& other) const { return m_hashValue > other.m_hashValue; }
bool operator==(const TStringCrc& other) const { return m_hashValue == other.m_hashValue; }
bool operator!=(const TStringCrc& other) const { return m_hashValue != other.m_hashValue; }

Expand All @@ -28,4 +30,18 @@ class TStringCrc final

using StringCrc = TStringCrc<uint32_t>;

}

namespace std
{

template<>
struct hash<engine::StringCrc>
{
uint64_t operator()(const engine::StringCrc& key) const
{
return static_cast<uint32_t>(key.Value());
}
};

}
20 changes: 20 additions & 0 deletions Engine/Source/Runtime/Path/Path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,24 @@ std::string Path::GetTerrainTextureOutputFilePath(const char* pInputFilePath, co
return ((GetEngineResourcesPath() / "Textures" / "Terrain" / std::filesystem::path(pInputFilePath).stem()).replace_extension(extension)).generic_string();
}

bool Path::FileExists(const char* pFilePath)
{
return std::filesystem::exists(pFilePath);
}

bool Path::DirectoryExists(const char* pDirectoryPath)
{
return std::filesystem::is_directory(pDirectoryPath);
}

std::string Path::GetFileName(const char* pFilePath)
{
return std::filesystem::path(pFilePath).filename().string();
}

std::string Path::GetFileNameWithoutExtension(const char* pFilePath)
{
return std::filesystem::path(pFilePath).stem().string();
}

}
5 changes: 5 additions & 0 deletions Engine/Source/Runtime/Path/Path.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ class Path
static std::string GetTextureOutputFilePath(const char* pInputFilePath, const char* extension);
static std::string GetTerrainTextureOutputFilePath(const char* pInputFilePath, const char* extension);

static bool FileExists(const char* pFilePath);
static bool DirectoryExists(const char* pDirectoryPath);
static std::string GetFileName(const char* pFilePath);
static std::string GetFileNameWithoutExtension(const char* pFilePath);

private:
static std::filesystem::path GetEngineBuiltinShaderPath();
static std::filesystem::path GetEngineResourcesPath();
Expand Down
Loading

0 comments on commit 63e05e1

Please sign in to comment.