Working on supporting multiple users during edition. For now prepare a way to write a .ini file with user and its id.
This commit is contained in:
1 parent
c70cce463b
commit
9e8bbad5d4
15 files changed
+240
-30
No files matched your search
+1
-1
@@ -233,7 +233,7 @@ void RenderWorldEditorUI(World& world)
|
||||
if (ImGui::Begin("World Editor"))
|
||||
{
|
||||
TempArena temp = scratch_begin(nullptr, 0);
|
||||
static char worldFilePath[256] = "../world.bin";
|
||||
static char worldFilePath[256] = "/world.bin";
|
||||
ImGui::InputText("World File", worldFilePath, sizeof(worldFilePath));
|
||||
|
||||
String path = GetAssetPath(temp.Arena, AssetType::JAsset, ConstString(worldFilePath));
|
||||
|
||||
@@ -5,16 +5,19 @@
|
||||
enum class AssetType
|
||||
{
|
||||
JAsset,
|
||||
Shader
|
||||
Shader,
|
||||
Config,
|
||||
};
|
||||
|
||||
// Returns the path to the application directory
|
||||
extern JULIET_API String GetBasePath();
|
||||
JULIET_API String GetBasePath();
|
||||
|
||||
// Path to the /Assets/ folder
|
||||
extern JULIET_API String GetAssetBasePath();
|
||||
JULIET_API String GetAssetBasePath();
|
||||
|
||||
// Builds a full path to an asset file given its filename (e.g. "Triangle.vert.dxil").
|
||||
extern JULIET_API String GetAssetPath(NonNullPtr<Arena> arena, AssetType type, String filename);
|
||||
JULIET_API String GetAssetPath(NonNullPtr<Arena> arena, AssetType type, String filename);
|
||||
|
||||
extern JULIET_API bool IsAbsolutePath(String path);
|
||||
JULIET_API bool IsAbsolutePath(String path);
|
||||
|
||||
JULIET_API String CleanPath(NonNullPtr<Arena> arena, String path);
|
||||
@@ -1,5 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <Core/Common/NonNullPtr.h>
|
||||
#include <Core/Common/String.h>
|
||||
#include <Core/Memory/MemoryArena.h>
|
||||
|
||||
namespace Memory
|
||||
{
|
||||
Byte* OS_Reserve(size_t size);
|
||||
@@ -39,5 +43,10 @@ namespace Debug
|
||||
JULIET_API bool IsDebuggerPresent();
|
||||
} // namespace Debug
|
||||
|
||||
String os_get_env_var(NonNullPtr<Arena> arena, const String& name);
|
||||
void os_set_env_var(const String& name, const String& value);
|
||||
|
||||
String os_get_username(NonNullPtr<Arena> arena);
|
||||
|
||||
using EntryPointFunc = int (*)(int, wchar_t**);
|
||||
JULIET_API int Bootstrap(EntryPointFunc entryPointFunc, int argc, wchar_t** argv);
|
||||
@@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
using UserID = uint8;
|
||||
|
||||
void initialize_user_system();
|
||||
void shutdown_user_system();
|
||||
|
||||
uint8 get_local_user_id();
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <Core/Logging/LogManager.h>
|
||||
#include <Core/Logging/LogTypes.h>
|
||||
#include <Core/Memory/Allocator.h>
|
||||
#include <Core/Thread/ThreadContext.h>
|
||||
|
||||
namespace
|
||||
{
|
||||
@@ -36,13 +37,14 @@ String GetAssetBasePath()
|
||||
|
||||
String GetAssetPath(NonNullPtr<Arena> arena, AssetType type, String filename)
|
||||
{
|
||||
Assert(IsValid(filename));
|
||||
|
||||
String asset_path = {};
|
||||
switch (type)
|
||||
{
|
||||
case AssetType::Shader:
|
||||
{
|
||||
Assert(IsValid(CachedShaderBasePath));
|
||||
Assert(IsValid(filename));
|
||||
|
||||
size_t totalSize = CachedShaderBasePath.Size + filename.Size + 1;
|
||||
char* buffer = ArenaPushArray<char>(arena, totalSize);
|
||||
@@ -52,9 +54,31 @@ String GetAssetPath(NonNullPtr<Arena> arena, AssetType type, String filename)
|
||||
asset_path = { buffer, totalSize - 1 };
|
||||
}
|
||||
break;
|
||||
case AssetType::Config:
|
||||
{
|
||||
Assert(IsValid(CachedAssetBasePath));
|
||||
|
||||
constexpr const char* kConfig_str = "config/";
|
||||
constexpr size_t kConfig_size = sizeof(kConfig_str) - 1;
|
||||
|
||||
size_t totalSize = CachedAssetBasePath.Size + kConfig_size + filename.Size + 1;
|
||||
char* buffer = ArenaPushArray<char>(arena, totalSize);
|
||||
Assert(buffer);
|
||||
|
||||
juliet_snprintf(buffer, totalSize, "%s%s%s", CStr(CachedAssetBasePath), kConfig_str, CStr(filename));
|
||||
asset_path = { buffer, totalSize - 1 };
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
asset_path = GetAssetBasePath();
|
||||
Assert(IsValid(CachedAssetBasePath));
|
||||
|
||||
size_t totalSize = CachedAssetBasePath.Size + filename.Size + 1;
|
||||
char* buffer = ArenaPushArray<char>(arena, totalSize);
|
||||
Assert(buffer);
|
||||
|
||||
juliet_snprintf(buffer, totalSize, "%s%s", CStr(CachedAssetBasePath), CStr(filename));
|
||||
asset_path = { buffer, totalSize - 1 };
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -71,6 +95,11 @@ bool IsAbsolutePath(String path)
|
||||
return Platform::IsAbsolutePath(path);
|
||||
}
|
||||
|
||||
String CleanPath(NonNullPtr<Arena> arena, String path)
|
||||
{
|
||||
return Platform::CleanPath(arena, path);
|
||||
}
|
||||
|
||||
void InitFilesystem(NonNullPtr<Arena> arena)
|
||||
{
|
||||
CachedBasePath = Platform::GetBasePath(arena);
|
||||
@@ -90,13 +119,10 @@ void InitFilesystem(NonNullPtr<Arena> arena)
|
||||
|
||||
if (DirectoryExists(probePath))
|
||||
{
|
||||
size_t len = strlen(probePath);
|
||||
if (char* buffer = ArenaPushArray<char>(arena, len + 1 JULIET_DEBUG_PARAM("CachedAssetBasePath")))
|
||||
{
|
||||
juliet_snprintf(buffer, len + 1, "%s", probePath);
|
||||
CachedAssetBasePath = { buffer, len };
|
||||
Log(LogLevel::Message, LogCategory::Core, "Asset base path: %s", buffer);
|
||||
}
|
||||
// Clean the path first to remove any relative parts
|
||||
String abs_path = CleanPath(arena, WrapString(probePath));
|
||||
CachedAssetBasePath = abs_path;
|
||||
Log(LogLevel::Message, LogCategory::Core, "Asset base path: %s", CStr(abs_path));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -113,18 +139,13 @@ void InitFilesystem(NonNullPtr<Arena> arena)
|
||||
|
||||
if (DirectoryExists(probePath))
|
||||
{
|
||||
size_t len = strlen(probePath);
|
||||
if (char* buffer = ArenaPushArray<char>(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;
|
||||
// Clean the path first to remove any relative parts
|
||||
String abs_path = CleanPath(arena, WrapString(probePath));
|
||||
CachedShaderBasePath = abs_path;
|
||||
Log(LogLevel::Message, LogCategory::Core, "Asset base path: %s", CStr(abs_path));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Log(LogLevel::Error, LogCategory::Core, "Filesystem: Could not find Assets/compiled/ directory!");
|
||||
}
|
||||
|
||||
void ShutdownFilesystem()
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Platform
|
||||
{
|
||||
extern String GetBasePath(NonNullPtr<Arena> arena);
|
||||
extern bool IsAbsolutePath(String path);
|
||||
String GetBasePath(NonNullPtr<Arena> arena);
|
||||
bool IsAbsolutePath(String path);
|
||||
String CleanPath(NonNullPtr<Arena> arena, String path);
|
||||
} // namespace Platform
|
||||
@@ -91,4 +91,17 @@ namespace Platform
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
String CleanPath(NonNullPtr<Arena> arena, String path)
|
||||
{
|
||||
char clean_path_buffer[MAX_PATH];
|
||||
LPSTR file_part = nullptr;
|
||||
DWORD result = GetFullPathNameA(CStr(path), MAX_PATH, clean_path_buffer, &file_part);
|
||||
if (result == 0)
|
||||
{
|
||||
LogError(LogCategory::Core, "Failed to resolve path. Error: %lu\n", GetLastError());
|
||||
}
|
||||
|
||||
return StringCopy(arena, WrapString(clean_path_buffer));
|
||||
}
|
||||
} // namespace Platform
|
||||
@@ -1,6 +1,8 @@
|
||||
#include <Core/HAL/OS/OS.h>
|
||||
#include <Core/HAL/OS/OS_Private.h>
|
||||
#include <Core/Memory/MemoryArena.h>
|
||||
#include <Core/Thread/Thread.h>
|
||||
#include <Graphics/D3D12/D3D12Includes.h>
|
||||
|
||||
namespace Memory
|
||||
{
|
||||
@@ -58,9 +60,24 @@ namespace Debug
|
||||
}
|
||||
} // namespace Debug
|
||||
|
||||
String os_get_env_var(NonNullPtr<Arena> arena, const String& name)
|
||||
{
|
||||
String result = Internal::os_get_env_var(arena, name);
|
||||
return result;
|
||||
}
|
||||
|
||||
void os_set_env_var(const String& name, const String& value)
|
||||
{
|
||||
Internal::os_set_env_var(name, value);
|
||||
}
|
||||
|
||||
String os_get_username(NonNullPtr<Arena> arena)
|
||||
{
|
||||
return Internal::os_get_username(arena);
|
||||
}
|
||||
|
||||
int Bootstrap(EntryPointFunc entryPointFunc, int argc, wchar_t** argv)
|
||||
{
|
||||
|
||||
int result = Internal::OS_Main(argc, argv);
|
||||
if (result == 0)
|
||||
{
|
||||
@@ -73,4 +90,3 @@ int Bootstrap(EntryPointFunc entryPointFunc, int argc, wchar_t** argv)
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -20,6 +20,11 @@ namespace Time::Internal
|
||||
|
||||
namespace Internal
|
||||
{
|
||||
String os_get_env_var(NonNullPtr<Arena> arena, const String& name);
|
||||
void os_set_env_var(const String& name, const String& value);
|
||||
|
||||
String os_get_username(NonNullPtr<Arena> arena);
|
||||
|
||||
int OS_Main(int argc, wchar_t** argv);
|
||||
void OS_Main_Exit();
|
||||
} // namespace Internal
|
||||
@@ -100,6 +100,36 @@ namespace Internal
|
||||
{
|
||||
thread_local thread_context* mainThread = nullptr;
|
||||
|
||||
String os_get_env_var(NonNullPtr<Arena> arena, const String& name)
|
||||
{
|
||||
char buffer[256];
|
||||
String result = {};
|
||||
|
||||
if (GetEnvironmentVariableA(CStr(name), buffer, sizeof(buffer)) != 0)
|
||||
{
|
||||
result = StringCopy(arena, WrapString(buffer));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void os_set_env_var(const String& name, const String& value)
|
||||
{
|
||||
SetEnvironmentVariableA(CStr(name), CStr(value));
|
||||
}
|
||||
|
||||
String os_get_username(NonNullPtr<Arena> arena)
|
||||
{
|
||||
char username[256];
|
||||
DWORD usernameLength = sizeof(username);
|
||||
String result = {};
|
||||
if (GetUserNameA(username, &usernameLength) && usernameLength > 1)
|
||||
{
|
||||
result = StringCopy(arena, { username, usernameLength });
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int OS_Main([[maybe_unused]] int argc, [[maybe_unused]] wchar_t** argv)
|
||||
{
|
||||
SetUnhandledExceptionFilter(&ExceptionFilter);
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <Core/JulietInit.h>
|
||||
#include <Core/Logging/LogManager.h>
|
||||
#include <Core/Memory/MemoryArena.h>
|
||||
#include <Engine/user.h>
|
||||
#include <Graphics/DebugDisplay.h>
|
||||
#include <Graphics/Graphics.h>
|
||||
#include <Graphics/MeshRenderer.h>
|
||||
@@ -159,6 +160,8 @@ void InitializeEngine(JulietInit_Flags flags)
|
||||
|
||||
InitFilesystem(EngineInstance.PlatformArena);
|
||||
|
||||
initialize_user_system();
|
||||
|
||||
JulietInit(flags);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
#include <Engine/user.h>
|
||||
|
||||
#include <Core/Common/CRC32.h>
|
||||
#include <Core/Common/serialization.h>
|
||||
#include <Core/HAL/Filesystem/Filesystem.h>
|
||||
#include <Core/HAL/IO/IOStream.h>
|
||||
#include <Core/HAL/OS/OS.h>
|
||||
#include <Core/Thread/ThreadContext.h>
|
||||
#include <Engine/Engine.h>
|
||||
|
||||
void initialize_user_system()
|
||||
{
|
||||
// Project needs a user.ini file with all users
|
||||
// When starting if none exists -> create it
|
||||
// User name is basically found in a env variable, if not, the local windows user will be used.
|
||||
TempArena temp = scratch_begin(nullptr, 0);
|
||||
|
||||
String user_system_path = GetAssetPath(temp.Arena, AssetType::Config, ConstString("users.ini"));
|
||||
ByteBuffer user_file = LoadFile(temp.Arena, user_system_path);
|
||||
|
||||
String username = os_get_username(temp.Arena);
|
||||
|
||||
if (user_file.Size == 0)
|
||||
{
|
||||
IOStream* stream = IOFromFile(temp.Arena, user_system_path, ConstString("w+"));
|
||||
Archive ar = { .arena = temp.Arena, .loading = false, .stream = stream };
|
||||
|
||||
uint8 id = 1;
|
||||
serialize(ar, username, crc32(username), id);
|
||||
|
||||
IOClose(stream);
|
||||
}
|
||||
else
|
||||
{
|
||||
ParsedArchive parsed_archive = tokenize_archive(temp.Arena, user_file);
|
||||
|
||||
Archive ar = { .arena = temp.Arena, .loading = true, .base = parsed_archive };
|
||||
}
|
||||
|
||||
scratch_end(temp);
|
||||
}
|
||||
|
||||
void shutdown_user_system() {}
|
||||
|
||||
uint8 get_local_user_id()
|
||||
{
|
||||
return 0u;
|
||||
}
|
||||
@@ -11,11 +11,13 @@ namespace UnitTest
|
||||
void VectorUnitTest();
|
||||
void TestMemoryArena();
|
||||
void SerializationUnitTest();
|
||||
void os_unit_test();
|
||||
|
||||
void RunUnitTests()
|
||||
{
|
||||
LogMessage(LogCategory::Core, "Starting Unit Tests...");
|
||||
|
||||
os_unit_test();
|
||||
TestMemoryArena();
|
||||
VectorUnitTest();
|
||||
SerializationUnitTest();
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
#if JULIET_DEBUG
|
||||
|
||||
#include <Core/HAL/OS/OS.h>
|
||||
#include <Core/Logging/LogManager.h>
|
||||
#include <Core/Logging/LogTypes.h>
|
||||
#include <Core/Thread/ThreadContext.h>
|
||||
|
||||
namespace UnitTest
|
||||
{
|
||||
void os_unit_test()
|
||||
{
|
||||
LogMessage(LogCategory::Core, "=== Running OS Unit Tests (Juliet) ===");
|
||||
|
||||
TempArena scratch = scratch_begin(nullptr, 0);
|
||||
String username = os_get_username(scratch.Arena);
|
||||
|
||||
Assert(IsValid(username));
|
||||
|
||||
String env = os_get_env_var(scratch.Arena, ConstString("JULIET_UNIT_TEST"));
|
||||
|
||||
os_set_env_var(ConstString("JULIET_UNIT_TEST"), username);
|
||||
|
||||
String env2 = os_get_env_var(scratch.Arena, ConstString("JULIET_UNIT_TEST"));
|
||||
|
||||
os_set_env_var(ConstString("JULIET_UNIT_TEST"), env);
|
||||
|
||||
Assert(StringCompare(env, env2) != 0);
|
||||
|
||||
// String os_get_env_var(NonNullPtr<Arena> arena, const String& name)
|
||||
// {
|
||||
// String result = Internal::os_get_env_var(arena, name);
|
||||
// return result;
|
||||
// }
|
||||
//
|
||||
// void os_set_env_var(const String& name, const String& value)
|
||||
// {
|
||||
// Internal::os_set_env_var(name, value);
|
||||
// }
|
||||
//
|
||||
// String os_get_username(NonNullPtr<Arena> arena)
|
||||
// {
|
||||
// Internal::os_get_username(arena);
|
||||
// }
|
||||
//
|
||||
|
||||
scratch_end(scratch);
|
||||
LogMessage(LogCategory::Core, "=== All OS Unit Tests Passed Successfully ===");
|
||||
}
|
||||
} // namespace UnitTest
|
||||
|
||||
#endif
|
||||
+1
-1
@@ -175,7 +175,7 @@ if /i "!CFG!"=="Debug" (
|
||||
set IMGUI_UNITY_SRCS=
|
||||
)
|
||||
|
||||
set COMMON_LIBS=kernel32.lib user32.lib gdi32.lib dxguid.lib Ws2_32.lib dxgi.lib imm32.lib dwmapi.lib d3dcompiler.lib dxcompiler.lib shell32.lib winhttp.lib delayimp.lib
|
||||
set COMMON_LIBS=kernel32.lib user32.lib Advapi32.lib gdi32.lib dxguid.lib Ws2_32.lib dxgi.lib imm32.lib dwmapi.lib d3dcompiler.lib dxcompiler.lib shell32.lib winhttp.lib delayimp.lib
|
||||
|
||||
if defined IMGUI_UNITY_SRCS (
|
||||
echo STEP Compiling ImGui Shared Objs [!CFG!]>>"!PLAN_FILE!"
|
||||
|
||||
Reference in new issue
Block a user