conversion to arena of filesystem
This commit is contained in:
@@ -26,15 +26,13 @@ namespace Juliet
|
||||
|
||||
String GetBasePath()
|
||||
{
|
||||
if (!IsValid(CachedBasePath))
|
||||
{
|
||||
CachedBasePath = Platform::GetBasePath();
|
||||
}
|
||||
Assert(IsValid(CachedBasePath));
|
||||
return CachedBasePath;
|
||||
}
|
||||
|
||||
String GetAssetBasePath()
|
||||
{
|
||||
Assert(IsValid(CachedAssetBasePath));
|
||||
return CachedAssetBasePath;
|
||||
}
|
||||
|
||||
@@ -50,7 +48,7 @@ namespace Juliet
|
||||
return {};
|
||||
}
|
||||
|
||||
snprintf(buffer, totalSize, "%s%s", CStr(CachedAssetBasePath), CStr(filename));
|
||||
juliet_snprintf(buffer, totalSize, "%s%s", CStr(CachedAssetBasePath), CStr(filename));
|
||||
return { buffer, totalSize - 1 };
|
||||
}
|
||||
|
||||
@@ -63,8 +61,10 @@ namespace Juliet
|
||||
return Platform::IsAbsolutePath(path);
|
||||
}
|
||||
|
||||
void InitFilesystem()
|
||||
void InitFilesystem(NonNullPtr<Arena> arena)
|
||||
{
|
||||
CachedBasePath = Platform::GetBasePath(arena);
|
||||
|
||||
String basePath = GetBasePath();
|
||||
Assert(IsValid(basePath));
|
||||
|
||||
@@ -76,15 +76,14 @@ namespace Juliet
|
||||
for (const char* candidate : kCandidates)
|
||||
{
|
||||
char probePath[512];
|
||||
snprintf(probePath, sizeof(probePath), "%s%s", CStr(basePath), candidate);
|
||||
juliet_snprintf(probePath, sizeof(probePath), "%s%s", CStr(basePath), candidate);
|
||||
|
||||
if (DirectoryExists(probePath))
|
||||
{
|
||||
size_t len = strlen(probePath);
|
||||
auto* buffer = static_cast<char*>(Calloc(len + 1, sizeof(char)));
|
||||
if (buffer)
|
||||
if (char* buffer = ArenaPushArray<char>(arena, len + 1 JULIET_DEBUG_PARAM("CachedAssetBasePath")))
|
||||
{
|
||||
snprintf(buffer, len + 1, "%s", probePath);
|
||||
juliet_snprintf(buffer, len + 1, "%s", probePath);
|
||||
CachedAssetBasePath = { buffer, len };
|
||||
Log(LogLevel::Message, LogCategory::Core, "Asset base path: %s", buffer);
|
||||
}
|
||||
@@ -96,16 +95,10 @@ namespace Juliet
|
||||
}
|
||||
|
||||
void ShutdownFilesystem()
|
||||
{
|
||||
if (IsValid(CachedBasePath))
|
||||
{
|
||||
CachedBasePath.Size = 0;
|
||||
SafeFree(CachedBasePath.Str);
|
||||
}
|
||||
if (IsValid(CachedAssetBasePath))
|
||||
{
|
||||
CachedBasePath.Str = nullptr;
|
||||
CachedAssetBasePath.Size = 0;
|
||||
SafeFree(CachedAssetBasePath.Str);
|
||||
}
|
||||
CachedAssetBasePath.Str = nullptr;
|
||||
}
|
||||
} // namespace Juliet
|
||||
|
||||
@@ -2,6 +2,6 @@
|
||||
|
||||
namespace Juliet::Platform
|
||||
{
|
||||
extern String GetBasePath();
|
||||
extern String GetBasePath(NonNullPtr<Arena> arena);
|
||||
extern bool IsAbsolutePath(String path);
|
||||
} // namespace Juliet::Platform
|
||||
|
||||
@@ -2,6 +2,6 @@
|
||||
|
||||
namespace Juliet
|
||||
{
|
||||
extern void InitFilesystem();
|
||||
extern void InitFilesystem(NonNullPtr<Arena> arena);
|
||||
extern void ShutdownFilesystem();
|
||||
} // namespace Juliet
|
||||
|
||||
@@ -7,12 +7,12 @@
|
||||
|
||||
namespace Juliet::Platform
|
||||
{
|
||||
String GetBasePath()
|
||||
String GetBasePath(NonNullPtr<Arena> arena)
|
||||
{
|
||||
// Allocate a buffer that could fit the module size.
|
||||
// Max Path is a good start but could be bigger if the path include long path prefix
|
||||
size_t bufferSize = MAX_PATH;
|
||||
auto buffer = static_cast<char*>(Calloc(MAX_PATH, sizeof(char)));
|
||||
auto buffer = ArenaPushArray<char>(arena, MAX_PATH JULIET_DEBUG_PARAM("BasePath buffer"));
|
||||
if (buffer == nullptr)
|
||||
{
|
||||
return {};
|
||||
@@ -26,8 +26,9 @@ namespace Juliet::Platform
|
||||
// If the module filename length is bigger than the buffer size, we need to reallocate a bigger buffer
|
||||
if (moduleFilenameLength >= bufferSize - 1)
|
||||
{
|
||||
char* addedBuffer = ArenaPushArray<char>(arena, bufferSize JULIET_DEBUG_PARAM("BasePath buffer"));
|
||||
Assert(addedBuffer != nullptr);
|
||||
bufferSize *= 2;
|
||||
buffer = static_cast<char*>(Realloc(buffer, bufferSize * sizeof(char)));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -37,7 +38,6 @@ namespace Juliet::Platform
|
||||
|
||||
if (moduleFilenameLength == 0)
|
||||
{
|
||||
SafeFree(buffer);
|
||||
Log(LogLevel::Error, LogCategory::Core, "Filesystem: Cannot locate executable path");
|
||||
}
|
||||
|
||||
|
||||
@@ -160,7 +160,7 @@ namespace Juliet
|
||||
UnitTest::RunUnitTests();
|
||||
#endif
|
||||
|
||||
InitFilesystem();
|
||||
InitFilesystem(EngineInstance.PlatformArena);
|
||||
|
||||
JulietInit(flags);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user