res refactor progress

This commit is contained in:
jacob 2025-08-25 23:57:12 -05:00
parent db9d3677d5
commit a8fb832bcb
28 changed files with 409 additions and 1734 deletions

View File

@ -10,7 +10,7 @@ String InitializeAppWriteDirectory(Arena *arena, String write_dir)
/* Create write path */
String base_write_dir = P_GetWritePath(scratch.arena);
String write_path_fmt = base_write_dir.len > 0 ? Lit("%F/%F/") : Lit("%F%F/");
String write_path = StringFormat(
String write_path = FormatString(
arena,
write_path_fmt,
FmtString(base_write_dir),
@ -231,16 +231,14 @@ void Startup(void)
if (error.len > 0)
{
P_LogInfoF("Failed to load settings file with error - %F", FmtString(error));
String msg = StringFormat(temp.arena,
Lit(
"Failed to loading settings file \"%F\":\n"
"------------\n"
"%F\n"
"------------\n"
"To stop this error from appearing, either fix the issue above or delete the file from the system."
),
FmtString(settings_path),
FmtString(error));
String msg = StringF(temp.arena,
"Failed to loading settings file \"%F\":\n"
"------------\n"
"%F\n"
"------------\n"
"To stop this error from appearing, either fix the issue above or delete the file from the system.",
FmtString(settings_path),
FmtString(error));
Panic(msg);
}
P_LogInfoF("Settings file loaded successfully");

View File

@ -502,9 +502,9 @@ ASE_DecodedImage ASE_DecodeImage(Arena *arena, String encoded)
if (ase_header.color_depth != 32)
{
String msg = StringFormat(scratch.arena,
Lit("Only 32 bit rgba color mode is supported (got %F)"),
FmtUint(ase_header.color_depth));
String msg = StringF(scratch.arena,
"Only 32 bit rgba color mode is supported (got %F)",
FmtUint(ase_header.color_depth));
ASE_PushError(arena, &result.errors, msg);
goto abort;
}

View File

@ -37,12 +37,6 @@
# error Missing compile time definition for 'TestsAreEnabled'
#endif
#ifndef IncbinRawDir
# error Missing compile time definition for 'IncbinRawDir'
#else
# define IncbinDir Stringize(IncbinRawDir)
#endif
////////////////////////////////
//~ Machine context

View File

@ -207,7 +207,7 @@ Inline ArenaCtx *ArenaCtxFromFiberId(i16 fiber_id)
* scope that could potentially be a scratch arena from another scope. */
Inline TempArena BeginScratch(Arena *potential_conflict)
{
/* This function is currently hard-coded to support 2 scratch arenas */
/* This function is currently hard-coded to search through 2 scratch arenas */
StaticAssert(ScratchArenasPerCtx == 2);
/* Use `BeginScratchNoConflict` if no conflicts are present */
@ -215,7 +215,7 @@ Inline TempArena BeginScratch(Arena *potential_conflict)
ArenaCtx *ctx = ArenaCtxFromFiberId(FiberId);
Arena *scratch_arena = ctx->scratch_arenas[0];
if (potential_conflict && scratch_arena == potential_conflict)
if (scratch_arena == potential_conflict)
{
scratch_arena = ctx->scratch_arenas[1];
}

View File

@ -33,9 +33,9 @@ Enum(JobPriority)
};
////////////////////////////////
//~ @hookdecl Startup
//~ @hookdecl Init
void StartupBaseJobs(void);
void InitJobWorkers(void);
////////////////////////////////
//~ @hookdecl Futex

View File

@ -293,12 +293,12 @@ f32 LnF32(f32 x)
if ((x_int & 0x7fffffff) == 0)
{
/* Return -inf if x is 0 */
return -two_p25 / 0;
return -F32Infinity;
}
else if (x_int < 0)
{
/* Return NaN if x is negative */
return (x - x) / 0;
return F32Nan;
}
k -= 25;
x *= two_p25;

View File

@ -493,10 +493,10 @@ String Trim(String s, String pattern)
* included in the arguments (instead of w/ the specifier like in printf).
*
* Example:
* StringFormat(arena, Lit("Hello there %F"), FmtString(Lit("George")))
* FormatString(arena, Lit("Hello there %F"), FmtString(Lit("George")))
*
* NOTE: FmtEnd must be passed as the last arg in the va_list (This is
* done automatically by the `StringFormat` macro).
* done automatically by the `FormatString` macro).
*
* Format arguments:
* FmtChar: Format a single u8 character
@ -515,7 +515,7 @@ String Trim(String s, String pattern)
* %e/%E equivalent? (scientific notation of floats)
* %o equivalent? (octal representation)
*/
String StringFormatV(Arena *arena, String fmt, va_list args)
String FormatStringV(Arena *arena, String fmt, va_list args)
{
__prof;
@ -633,11 +633,11 @@ String StringFormatV(Arena *arena, String fmt, va_list args)
};
}
String StringFormat_(Arena *arena, String fmt, ...)
String FormatString_(Arena *arena, String fmt, ...)
{
va_list args;
va_start(args, fmt);
String new_str = StringFormatV(arena, fmt, args);
String new_str = FormatStringV(arena, fmt, args);
va_end(args);
return new_str;
}

View File

@ -112,10 +112,10 @@ String StringFromList(Arena *arena, StringList l, String separator);
#define FmtEnd (FmtArg) {.kind = FmtKind_End}
//- Format functions
#define StringF(arena, lit, ...) StringFormat_((arena), Lit(lit), __VA_ARGS__, FmtEnd)
#define StringFormat(arena, fmt, ...) StringFormat_((arena), (fmt), __VA_ARGS__, FmtEnd)
String StringFormat_(Arena *arena, String fmt, ...);
String StringFormatV(Arena *arena, String fmt, va_list args);
#define StringF(arena, lit, ...) FormatString_((arena), Lit(lit), __VA_ARGS__, FmtEnd)
#define FormatString(arena, fmt, ...) FormatString_((arena), (fmt), __VA_ARGS__, FmtEnd)
String FormatString_(Arena *arena, String fmt, ...);
String FormatStringV(Arena *arena, String fmt, va_list args);
////////////////////////////////
//~ Unicode operations

View File

@ -18,7 +18,10 @@ b32 Panic(String msg)
MessageBoxExA(0, msg_cstr, "Fatal error", mb_flags, 0);
}
HANDLE console_handle = GetStdHandle(STD_ERROR_HANDLE);
WriteConsoleA(console_handle, msg.text, msg.len, 0, 0);
if (console_handle != INVALID_HANDLE_VALUE)
{
WriteFile(console_handle, msg.text, msg.len, 0, 0);
}
if (IsRunningInDebugger())
{
Assert(0);
@ -184,8 +187,8 @@ i32 W32_Main(void)
/* Query system info */
GetSystemInfo(&g->info);
//- Startup jobs
StartupBaseJobs();
//- Startup workers
InitJobWorkers();
/* Startup layers */
if (!Atomic32Fetch(&g->panicking))

View File

@ -3,7 +3,7 @@ W32_SharedJobCtx W32_shared_job_ctx = ZI;
////////////////////////////////
//~ @hookdef Startup
void StartupBaseJobs(void)
void InitJobWorkers(void)
{
W32_SharedJobCtx *g = &W32_shared_job_ctx;
@ -114,7 +114,7 @@ void StartupBaseJobs(void)
W32_WorkerCtx *ctx = &pool->worker_contexts[i];
ctx->pool_kind = pool_kind;
ctx->id = i;
String name = StringFormat(pool->worker_threads_arena, name_fmt, FmtSint(i));
String name = FormatString(pool->worker_threads_arena, name_fmt, FmtSint(i));
pool->worker_threads[i] = W32_AcquireThread(W32_JobWorkerEntryFunc, ctx, name, prof_group + i);
}
}
@ -179,10 +179,10 @@ void ShutdownJobs(void)
for (W32_Thread *t = g->first_thread; t; t = t->next)
{
String name = StringFromCstr(t->thread_name_cstr, countof(t->thread_name_cstr));
threads_msg.len += StringFormat(scratch.arena, Lit(" \"%F\"\n"), FmtString(name)).len;
threads_msg.len += StringF(scratch.arena, " \"%F\"\n", FmtString(name)).len;
++num_dangling_threads;
}
threads_msg = StringFormat(scratch.arena, Lit("%F dangling thread(s):\n%F"), FmtUint(num_dangling_threads), FmtString(threads_msg));
threads_msg = FormatString(scratch.arena, Lit("%F dangling thread(s):\n%F"), FmtUint(num_dangling_threads), FmtString(threads_msg));
//Panic(threads_msg);
EndScratch(scratch);
}
@ -1056,7 +1056,7 @@ W32_ThreadDef(W32_JobWorkerEntryFunc, worker_ctx_arg)
{
/* Invalid yield kind */
TempArena scratch = BeginScratchNoConflict();
//Panic(StringFormat(scratch.arena, Lit("Invalid fiber yield kind \"%F\""), FmtSint(yield.kind)));
//Panic(FormatString(scratch.arena, Lit("Invalid fiber yield kind \"%F\""), FmtSint(yield.kind)));
EndScratch(scratch);
} break;

View File

@ -41,9 +41,9 @@ JobDef(F_LoadJob, sig, _)
if (resource_data.len == 0)
{
/* FIME: Load baked font instead of panicking */
Panic(StringFormat(scratch.arena,
Lit("Font \"%F\" not found"),
FmtString(name)));
Panic(StringF(scratch.arena,
"Font \"%F\" not found",
FmtString(name)));
}
TTF_Result result = TTF_Decode(scratch.arena, resource_data, point_size, font_codes, countof(font_codes));
@ -78,9 +78,9 @@ JobDef(F_LoadJob, sig, _)
/* FIXME: Load baked font instead of panicking */
if (font->glyphs_count <= 0)
{
Panic(StringFormat(scratch.arena,
Lit("Parsed 0 glyphs from font \"%F\"!"),
FmtString(name)));
Panic(StringF(scratch.arena,
"Parsed 0 glyphs from font \"%F\"!",
FmtString(name)));
}
/* Copy glyphs from decode result */
@ -111,10 +111,10 @@ AC_Asset *F_LoadAsset(R_Tag resource, f32 point_size, b32 wait)
String name = R_NameFromTag(resource);
/* Concatenate point_size to name for key */
String key = StringFormat(scratch.arena,
Lit("%F%F_font"),
FmtString(name),
FmtFloatP((f64)point_size, 1));
String key = StringF(scratch.arena,
"%F%F_font",
FmtString(name),
FmtFloatP((f64)point_size, 1));
u64 hash = AC_HashFromKey(key);
b32 is_first_touch;
AC_Asset *asset = AC_TouchCache(key, hash, &is_first_touch);

View File

@ -293,7 +293,10 @@ Vec2I32 GPU_GetTextureSize(GPU_Resource *resource);
GPU_CommandList *GPU_BeginCommandList(void);
GPU_Fence GPU_EndCommandList(GPU_CommandList *cl);
void GPU_ProfileDF(GPU_CommandList *cl, String zone_name);
////////////////////////////////
//~ Profiling helpers
void GPU_ProfN(GPU_CommandList *cl, String name);
////////////////////////////////
//~ Resource transition operations
@ -301,7 +304,7 @@ void GPU_ProfileDF(GPU_CommandList *cl, String zone_name);
void GPU_TransitionToSrv(GPU_CommandList *cl, GPU_Resource *resource);
void GPU_TransitionToUav(GPU_CommandList *cl, GPU_Resource *resource);
void GPU_TransitionToRtv(GPU_CommandList *cl, GPU_Resource *resource);
void GPU_Flush(GPU_CommandList *cl, GPU_Resource *resource);
void GPU_FlushUav(GPU_CommandList *cl, GPU_Resource *resource);
////////////////////////////////
//~ Dispatch operations

View File

@ -70,10 +70,13 @@ GPU_Fence GPU_EndCommandList(GPU_CommandList *cl)
return (GPU_Fence) ZI;
}
void GPU_ProfileDF(GPU_CommandList *cl, String zone_name)
////////////////////////////////
//~ @hookdef Profiling helpers
void GPU_ProfN(GPU_CommandList *cl, String name)
{
LAX cl;
LAX zone_name;
LAX name;
}
////////////////////////////////
@ -97,7 +100,7 @@ void GPU_TransitionToRtv(GPU_CommandList *cl, GPU_Resource *resource)
LAX resource;
}
void GPU_Flush(GPU_CommandList *cl, GPU_Resource *resource)
void GPU_FlushUav(GPU_CommandList *cl, GPU_Resource *resource)
{
LAX cl;
LAX resource;

View File

@ -45,10 +45,6 @@
# define TestsAreEnabled 0
#endif
#ifndef IncbinRawDir
# define IncbinRawDir
#endif
////////////////////////////////
//~ Includes
@ -60,17 +56,14 @@
////////////////////////////////
//~ Util
/* TODO: Remove printf */
#include <stdio.h>
void Echo(String msg)
{
TempArena scratch = BeginScratchNoConflict();
char *msg_cstr = CstrFromString(scratch.arena, msg);
printf(msg_cstr);
printf("\n");
fflush(stdout);
EndScratch(scratch);
HANDLE console_handle = GetStdHandle(STD_OUTPUT_HANDLE);
if (console_handle != INVALID_HANDLE_VALUE)
{
WriteFile(console_handle, msg.text, msg.len, 0, 0);
WriteFile(console_handle, "\n", 1, 0, 0);
}
}
Struct(LineCol)
@ -584,11 +577,16 @@ L_Topo L_TopoFromLayerName(Arena *arena, StringList starting_layer_names, String
}
if (cycle_names_list.count > 1)
{
L_PushTopoItem(arena, &result.errors, token_file, token_pos, StringF(arena, "Cyclic dependency detected while processing dependencies for layer '%F' (%F)", FmtString(name), FmtString(cycle_names_str)));
L_PushTopoItem(arena, &result.errors, token_file, token_pos, StringF(arena,
"Cyclic dependency detected while processing dependencies for layer '%F' (%F)",
FmtString(name),
FmtString(cycle_names_str)));
}
else
{
L_PushTopoItem(arena, &result.errors, token_file, token_pos, StringF(arena, "Cyclic dependency detected while processing dependencies for layer '%F'", FmtString(name)));
L_PushTopoItem(arena, &result.errors, token_file, token_pos, StringF(arena,
"Cyclic dependency detected while processing dependencies for layer '%F'",
FmtString(name)));
}
}
else
@ -814,6 +812,7 @@ void StartupMeta(void)
}
//- Generate C
String c_out_file = F_GetFull(arena, Lit("pp_gen.c"));
if (errors.count <= 0)
{
StringList c_out_lines = ZI;
@ -863,7 +862,7 @@ void StartupMeta(void)
}
/* Write to file */
String c_out = StringFromList(arena, c_out_lines, Lit("\n"));
F_ClearWrite(Lit("pp_gen.c"), c_out);
F_ClearWrite(c_out_file, c_out);
}
//- Echo meta errors
@ -905,13 +904,12 @@ void StartupMeta(void)
PushStringToList(arena, &shared_compiler_flags, Lit("-DProfilingIsEnabled=0"));
PushStringToList(arena, &shared_compiler_flags, Lit("-DUnoptimizedIsEnabled=1"));
PushStringToList(arena, &shared_compiler_flags, Lit("-DTestsAreEnabled=0"));
PushStringToList(arena, &shared_compiler_flags, Lit("-DIncbinRawDir=\"bla/\""));
//- Msvc
{
PushStringToList(arena, &msvc_compiler_flags, Lit("-Z7"));
PushStringToList(arena, &msvc_compiler_flags, Lit("-DEBUG:FULL"));
PushStringToList(arena, &msvc_compiler_flags, Lit("-Fo:pp_pp_gen.obj"));
PushStringToList(arena, &msvc_compiler_flags, Lit("-Fo:pp_gen.obj"));
PushStringToList(arena, &msvc_compiler_flags, Lit("-Fe:pp.exe"));
PushStringToList(arena, &msvc_compiler_flags, Lit("-nologo"));
PushStringToList(arena, &msvc_compiler_flags, Lit("-diagnostics:column"));
@ -923,6 +921,7 @@ void StartupMeta(void)
PushStringToList(arena, &msvc_compiler_flags, Lit("-wd4201")); /* nonstandard extension used: nameless struct/union */
PushStringToList(arena, &msvc_compiler_flags, Lit("-wd4324")); /* structure was padded due to alignment specifier */
PushStringToList(arena, &msvc_compiler_flags, Lit("-wd4100")); /* unreferenced parameter */
PushStringToList(arena, &msvc_compiler_flags, Lit("-wd4101")); /* unreferenced local variable */
PushStringToList(arena, &msvc_compiler_flags, Lit("-wd4189")); /* local variable is initialized but not referenced */
PushStringToList(arena, &msvc_compiler_flags, Lit("-wd4200")); /* nonstandard extension used: zero-sized array in struct/union */
}
@ -936,6 +935,7 @@ void StartupMeta(void)
PushStringToList(arena, &clang_compiler_flags, Lit("-msse4.2"));
/* Enable warnings */
PushStringToList(arena, &clang_compiler_flags, Lit("-Wall"));
PushStringToList(arena, &clang_compiler_flags, Lit("-Werror"));
PushStringToList(arena, &clang_compiler_flags, Lit("-Wframe-larger-than=65536"));
PushStringToList(arena, &clang_compiler_flags, Lit("-Wmissing-prototypes"));
PushStringToList(arena, &clang_compiler_flags, Lit("-Wunused-variable"));
@ -957,7 +957,7 @@ void StartupMeta(void)
FmtString(StringFromList(arena, shared_compiler_flags, Lit(" "))),
FmtString(StringFromList(arena, msvc_compiler_flags, Lit(" ")))
);
msvc_cmd_str = StringF(arena, "\"cl\" pp_gen.c %F", FmtString(flags_str));
msvc_cmd_str = StringF(arena, "\"cl\" %F %F", FmtString(c_out_file), FmtString(flags_str));
}
/* Clang */
{
@ -966,10 +966,11 @@ void StartupMeta(void)
FmtString(StringFromList(arena, shared_compiler_flags, Lit(" "))),
FmtString(StringFromList(arena, clang_compiler_flags, Lit(" ")))
);
clang_cmd_str = StringF(arena, "\"clang\" pp_gen.c %F", FmtString(flags_str));
clang_cmd_str = StringF(arena, "\"clang\" %F %F", FmtString(c_out_file), FmtString(flags_str));
}
//- Compile C
Echo(Lit("Compiling..."));
i32 ret = errors.count > 0;
if (ret == 0) {
String cmd_str = msvc_cmd_str;
@ -980,9 +981,14 @@ void StartupMeta(void)
output = Trim(output, Lit("\n"));
output = Trim(output, Lit("\r"));
output = Trim(output, Lit("\n"));
if (result.code != 0)
Echo(output);
if (result.code == 0)
{
Echo(output);
Echo(Lit("Compilation succeeded"));
}
else
{
Echo(Lit("Compilation failed"));
}
ret = result.code;
}

View File

@ -102,9 +102,9 @@ String OS_GetFullPath(Arena *arena, String path)
{
TempArena scratch = BeginScratch(arena);
wchar_t *rel_path_wstr = WstrFromString(scratch.arena, path);
wchar_t buff[4096];
wchar_t *full_path_wstr = _wfullpath(buff, rel_path_wstr, countof(buff));
String res = StringFromWstrNoLimit(arena, full_path_wstr);
wchar_t full_path_wstr_buff[4096];
GetFullPathNameW(rel_path_wstr, countof(full_path_wstr_buff), full_path_wstr_buff, 0);
String res = StringFromWstr(arena, full_path_wstr_buff, countof(full_path_wstr_buff));
EndScratch(scratch);
return res;
}
@ -186,8 +186,6 @@ OS_CommandResult OS_RunCommand(Arena *arena, String cmd)
TempArena scratch = BeginScratch(arena);
OS_CommandResult result = ZI;
i32 res = -1;
wchar_t *cmd_wstr = WstrFromString(scratch.arena, cmd);
SECURITY_ATTRIBUTES sa = ZI;
@ -195,62 +193,84 @@ OS_CommandResult OS_RunCommand(Arena *arena, String cmd)
sa.bInheritHandle = 1;
HANDLE pipe_read, pipe_write;
if (!CreatePipe(&pipe_read, &pipe_write, &sa, 0))
if (CreatePipe(&pipe_read, &pipe_write, &sa, 0))
{
/* TODO: error handling */
Assert(0);
}
SetHandleInformation(pipe_read, HANDLE_FLAG_INHERIT, 0);
SetHandleInformation(pipe_read, HANDLE_FLAG_INHERIT, 0);
STARTUPINFO si = ZI;
si.cb = sizeof(si);
si.dwFlags = STARTF_USESTDHANDLES;
si.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
si.hStdOutput = pipe_write;
si.hStdError = pipe_write;
STARTUPINFO si = ZI;
si.cb = sizeof(si);
si.dwFlags = STARTF_USESTDHANDLES;
si.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
si.hStdOutput = pipe_write;
si.hStdError = pipe_write;
PROCESS_INFORMATION pi = ZI;
PROCESS_INFORMATION pi = ZI;
result.output.text = PushDry(arena, u8);
if (!CreateProcessW(0, cmd_wstr, 0, 0, 1, 0, 0, 0, &si, &pi))
{
/* TODO: error handling */
Assert(0);
} else {
CloseHandle(pipe_write);
b32 exit_code_valid = 0;
i32 exit_code = 0;
b32 stdout_finished = 0;
while (!stdout_finished)
result.output.text = PushDry(arena, u8);
if (!CreateProcessW(0, cmd_wstr, 0, 0, 1, 0, 0, 0, &si, &pi))
{
u8 buff[4096] = ZI;
DWORD bytes_read = 0;
if (!ReadFile(pipe_read, buff, countof(buff), &bytes_read, 0))
DWORD err = GetLastError();
char *msg_cstr = 0;
i64 len = FormatMessageA(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
0,
err,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPSTR)&msg_cstr,
0,
0);
if (len > 0)
{
if (GetLastError() == ERROR_BROKEN_PIPE)
{
GetExitCodeProcess(pi.hProcess, &exit_code);
exit_code_valid = 1;
}
stdout_finished = 1;
result.output = PushString(arena, StringFromCstr(msg_cstr, len));
LocalFree(msg_cstr);
}
else
{
result.output = Lit("Failed to create process");
}
PushStructsNoZero(arena, u8, bytes_read);
CopyBytes(result.output.text + result.output.len, buff, bytes_read);
result.output.len += bytes_read;
}
CloseHandle(pi.hThread);
CloseHandle(pi.hProcess);
if (exit_code_valid)
{
result.code = exit_code;
} else {
result.code = -1;
} else {
CloseHandle(pipe_write);
b32 exit_code_valid = 0;
i32 exit_code = 0;
b32 stdout_finished = 0;
while (!stdout_finished)
{
u8 buff[4096] = ZI;
DWORD bytes_read = 0;
if (!ReadFile(pipe_read, buff, countof(buff), &bytes_read, 0))
{
if (GetLastError() == ERROR_BROKEN_PIPE)
{
GetExitCodeProcess(pi.hProcess, &exit_code);
exit_code_valid = 1;
}
stdout_finished = 1;
}
PushStructsNoZero(arena, u8, bytes_read);
CopyBytes(result.output.text + result.output.len, buff, bytes_read);
result.output.len += bytes_read;
}
CloseHandle(pi.hThread);
CloseHandle(pi.hProcess);
if (exit_code_valid)
{
result.code = exit_code;
} else {
result.code = -1;
}
}
CloseHandle(pipe_read);
}
else
{
result.output = Lit("Failed to create pipe");
result.code = -1;
}
CloseHandle(pipe_read);
EndScratch(scratch);
return result;
}

View File

@ -1,5 +1,3 @@
#include <stdlib.h> /* _wfullpath */
////////////////////////////////
//~ Win32 libs

View File

@ -100,7 +100,7 @@ void P_LogFV_(i32 level, String fmt, va_list args)
P_SharedLogState *ctx = &P_shared_log_state;
if (!Atomic32Fetch(&ctx->initialized)) { return; }
TempArena scratch = BeginScratchNoConflict();
String msg = StringFormatV(scratch.arena, fmt, args);
String msg = FormatStringV(scratch.arena, fmt, args);
#if P_IncludeLogSourceLocation
P_Log_(level, file, line, msg);
#else
@ -150,7 +150,6 @@ void P_Log_(i32 level, String msg)
Panic(Lit("Invalid log level"));
}
/* FIXME: Log actual thread & fiber id */
// u32 tid = ThreadId();
u32 tid = 0;
@ -161,9 +160,9 @@ void P_Log_(i32 level, String msg)
String shorthand = settings.shorthand;
#if P_IncludeLogSourceLocation
String msg_formatted = StringFormat(
String msg_formatted = StringF(
scratch.arena,
Lit("[%F:%F:%F.%F] |%F| [%F] <%F:%F> %F"),
"[%F:%F:%F.%F] |%F| [%F] <%F:%F> %F",
/* Time */
FmtUintZ(datetime.hour, 2),
@ -185,7 +184,7 @@ void P_Log_(i32 level, String msg)
FmtString(msg)
);
#else
String msg_formatted = StringFormat(
String msg_formatted = FormatString(
scratch.arena,
Lit("[%F:%F:%F.%F] |%F| [%F] %F"),

View File

@ -1,11 +1,11 @@
P_W32_SharedCtx P_W32_shared_ctx = ZI;
P_W32_SharedState P_W32_shared_state = ZI;
////////////////////////////////
//~ @hookdef Startup
void P_Startup(void)
{
P_W32_SharedCtx *g = &P_W32_shared_ctx;
P_W32_SharedState *g = &P_W32_shared_state;
//- Initialize btn table
{
@ -156,7 +156,7 @@ String P_W32_StringFromWin32Path(Arena *arena, wchar_t *src)
P_W32_Window *P_W32_AcquireWindow(void)
{
P_W32_SharedCtx *g = &P_W32_shared_ctx;
P_W32_SharedState *g = &P_W32_shared_state;
P_W32_Window *window = 0;
{
Lock lock = LockE(&g->windows_mutex);
@ -191,7 +191,7 @@ void P_W32_ReleaseWindow(P_W32_Window *window)
{
/* Stop window threads */
Atomic32FetchSet(&window->shutdown, 1);
P_W32_SharedCtx *g = &P_W32_shared_ctx;
P_W32_SharedState *g = &P_W32_shared_state;
P_W32_WakeWindow(window);
W32_WaitReleaseThread(window->window_thread);
@ -205,7 +205,7 @@ void P_W32_ReleaseWindow(P_W32_Window *window)
HWND P_W32_InitWindow(P_W32_Window *window)
{
struct P_W32_SharedCtx *g = &P_W32_shared_ctx;
struct P_W32_SharedState *g = &P_W32_shared_state;
/*
* From martins (https://gist.github.com/mmozeiko/5e727f845db182d468a34d524508ad5f#file-win32_d3d11-c-L66-L70):
@ -438,7 +438,7 @@ void P_W32_WakeWindow(P_W32_Window *window)
LRESULT CALLBACK P_W32_Win32WindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
__prof;
P_W32_SharedCtx *g = &P_W32_shared_ctx;
P_W32_SharedState *g = &P_W32_shared_state;
P_W32_Window *window = (P_W32_Window *)GetWindowLongPtrW(hwnd, GWLP_USERDATA);
if (!window)
@ -947,10 +947,10 @@ void P_MkDir(String path)
}
if (err.len > 0)
{
String msg = StringFormat(scratch.arena,
Lit("Failed to create directory \"%F\": %F"),
FmtString(path),
FmtString(err));
String msg = StringF(scratch.arena,
"Failed to create directory \"%F\": %F",
FmtString(path),
FmtString(err));
Panic(msg);
}
EndScratch(scratch);
@ -1105,9 +1105,9 @@ void P_WriteFile(P_File file, String data)
if (data.len >= 0x7FFF)
{
TempArena scratch = BeginScratchNoConflict();
Panic(StringFormat(scratch.arena,
Lit("Tried to write too many bytes to disk (%F)"),
FmtUint(data.len)));
Panic(StringF(scratch.arena,
"Tried to write too many bytes to disk (%F)",
FmtUint(data.len)));
EndScratch(scratch);
}
@ -1569,7 +1569,7 @@ String P_StringFromAddress(Arena *arena, P_Address address)
ip[i] = ntohs(address.ipnb[i]);
}
u16 port = ntohs(address.portnb);
result = StringFormat(arena, Lit("%F.%F.%F.%F:%F"), FmtUint(ip[0]), FmtUint(ip[1]), FmtUint(ip[2]), FmtUint(ip[3]), FmtUint(port));
result = StringF(arena, "%F.%F.%F.%F:%F", FmtUint(ip[0]), FmtUint(ip[1]), FmtUint(ip[2]), FmtUint(ip[3]), FmtUint(port));
}
return result;
@ -1585,7 +1585,7 @@ b32 P_AddressIsEqual(P_Address a, P_Address b)
P_Sock *P_AcquireSock(u16 listen_port, u64 sndbuf_size, u64 rcvbuf_size)
{
P_W32_SharedCtx *g = &P_W32_shared_ctx;
P_W32_SharedState *g = &P_W32_shared_state;
P_W32_Sock *ws = 0;
{
Lock lock = LockE(&g->socks_mutex);
@ -1620,7 +1620,7 @@ P_Sock *P_AcquireSock(u16 listen_port, u64 sndbuf_size, u64 rcvbuf_size)
void P_ReleaseSock(P_Sock *sock)
{
P_W32_SharedCtx *g = &P_W32_shared_ctx;
P_W32_SharedState *g = &P_W32_shared_state;
P_W32_Sock *ws = (P_W32_Sock *)sock;
closesocket(ws->sock);
Lock lock = LockE(&g->socks_mutex);

View File

@ -114,7 +114,7 @@ Struct(P_W32_Sock)
#define P_W32_WindowClassName L"power_play_window_class"
Struct(P_W32_SharedCtx)
Struct(P_W32_SharedState)
{
//- Key lookup table
P_Btn vk_btn_table[256];
@ -137,7 +137,7 @@ Struct(P_W32_SharedCtx)
P_W32_Sock *first_free_sock;
};
extern P_W32_SharedCtx P_W32_shared_ctx;
extern P_W32_SharedState P_W32_shared_state;
////////////////////////////////
//~ Time operations

View File

@ -146,35 +146,35 @@ String DebugStringFromEntity(Arena *arena, Entity *ent)
String result = ZI;
result.text = PushDry(arena, u8);
//result.len += StringFormat(arena, Lit("[%F]"), FmtUid(ent->id.uid)).len;
//result.len += StringF(arena, "[%F]", FmtUid(ent->id.uid)).len;
{
b32 transmitting = HasProp(ent, Prop_SyncSrc);
b32 receiving = HasProp(ent, Prop_SyncDst);
if (transmitting & receiving)
{
result.len += PushString(arena, Lit(" networked (sending & receiving)")).len;
result.len += StringF(arena, " networked (sending & receiving)").len;
}
else if (transmitting)
{
result.len += PushString(arena, Lit(" networked (sending)")).len;
result.len += StringF(arena, " networked (sending)").len;
}
else if (receiving)
{
result.len += PushString(arena, Lit(" networked (receiving)")).len;
result.len += StringF(arena, " networked (receiving)").len;
}
else
{
result.len += PushString(arena, Lit(" local")).len;
result.len += StringF(arena, " local").len;
}
}
result.len += PushString(arena, Lit("\n")).len;
result.len += StringF(arena, "\n").len;
result.len += StringFormat(arena, Lit("owner: [%F]\n"), FmtUid(ent->owner.uid)).len;
result.len += StringF(arena, "owner: [%F]\n", FmtUid(ent->owner.uid)).len;
result.len += PushString(arena, Lit("\n")).len;
result.len += StringF(arena, "\n").len;
{
result.len += PushString(arena, Lit("props: 0x")).len;
result.len += StringF(arena, "props: 0x").len;
for (u64 chunk_index = countof(ent->props); chunk_index-- > 0;)
{
u64 chunk = ent->props[chunk_index];
@ -189,32 +189,32 @@ String DebugStringFromEntity(Arena *arena, Entity *ent)
}
}
}
result.len += PushString(arena, Lit("\n")).len;
result.len += StringF(arena, "\n").len;
}
if (!EqId(ent->parent, RootEntityId))
{
result.len += StringFormat(arena, Lit("parent: [%F]\n"), FmtUid(ent->parent.uid)).len;
result.len += StringF(arena, "parent: [%F]\n", FmtUid(ent->parent.uid)).len;
}
if (!IsNilId(ent->next) || !IsNilId(ent->prev))
{
result.len += StringFormat(arena, Lit("prev: [%F]\n"), FmtUid(ent->prev.uid)).len;
result.len += StringFormat(arena, Lit("next: [%F]\n"), FmtUid(ent->next.uid)).len;
result.len += StringF(arena, "prev: [%F]\n", FmtUid(ent->prev.uid)).len;
result.len += StringF(arena, "next: [%F]\n", FmtUid(ent->next.uid)).len;
}
result.len += PushString(arena, Lit("\n")).len;
result.len += StringF(arena, "\n").len;
/* Pos */
Xform xf = XformFromEntity(ent);
Vec2 linear_velocity = ent->linear_velocity;
f32 angular_velocity = ent->angular_velocity;
result.len += StringFormat(arena, Lit("pos: (%F, %F)\n"), FmtFloat(xf.og.x), FmtFloat(xf.og.y)).len;
result.len += StringFormat(arena, Lit("linear velocity: (%F, %F)\n"), FmtFloat(linear_velocity.x), FmtFloat(linear_velocity.y)).len;
result.len += StringFormat(arena, Lit("angular velocity: %F\n"), FmtFloat(angular_velocity)).len;
result.len += StringF(arena, "pos: (%F, %F)\n", FmtFloat(xf.og.x), FmtFloat(xf.og.y)).len;
result.len += StringF(arena, "linear velocity: (%F, %F)\n", FmtFloat(linear_velocity.x), FmtFloat(linear_velocity.y)).len;
result.len += StringF(arena, "angular velocity: %F\n", FmtFloat(angular_velocity)).len;
/* Test */
result.len += StringFormat(arena, Lit("collision dir: (%F, %F)\n"), FmtFloat(ent->collision_dir.x), FmtFloat(ent->collision_dir.y)).len;
result.len += StringF(arena, "collision dir: (%F, %F)\n", FmtFloat(ent->collision_dir.x), FmtFloat(ent->collision_dir.y)).len;
/* Children */
if (!IsNilId(ent->first) || !IsNilId(ent->last))
@ -222,13 +222,13 @@ String DebugStringFromEntity(Arena *arena, Entity *ent)
Entity *child = EntityFromId(ss, ent->first);
if (!EqId(ent->first, ent->last) || !child->valid)
{
result.len += StringFormat(arena, Lit("first child: [%F]\n"), FmtUid(ent->first.uid)).len;
result.len += StringFormat(arena, Lit("last child: [%F]\n"), FmtUid(ent->last.uid)).len;
result.len += StringF(arena, "first child: [%F]\n", FmtUid(ent->first.uid)).len;
result.len += StringF(arena, "last child: [%F]\n", FmtUid(ent->last.uid)).len;
}
while (child->valid)
{
result.len += PushString(arena, Lit("\n---------------------------------\n")).len;
result.len += PushString(arena, Lit("CHILD\n")).len;
result.len += StringF(arena, "\n---------------------------------\n").len;
result.len += StringF(arena, "CHILD\n").len;
String child_text = DebugStringFromEntity(scratch.arena, child);
result.len += IndentString(arena, child_text, 4).len;
child = EntityFromId(ss, child->next);
@ -340,9 +340,9 @@ void DrawDebugConsole(i32 level, b32 minimized)
if (!minimized)
{
P_DateTime datetime = log->datetime;
text = StringFormat(
text = StringF(
scratch.arena,
Lit("[%F:%F:%F.%F] %F"),
"[%F:%F:%F.%F] %F",
FmtUintZ(datetime.hour, 2),
FmtUintZ(datetime.minute, 2),
FmtUintZ(datetime.second, 2),
@ -457,8 +457,8 @@ MergesortCompareFuncDef(EntitySortCmp, arg_a, arg_b, _)
if (result == 0)
{
/* Sort by sprite */
u64 a_cmp = a->sprite.hash;
u64 b_cmp = b->sprite.hash;
u64 a_cmp = a->sprite.r.hash;
u64 b_cmp = b->sprite.r.hash;
result = (a_cmp < b_cmp) - (a_cmp > b_cmp);
}
if (result == 0)
@ -485,7 +485,6 @@ void UpdateUser(P_Window *window)
g->real_dt_ns = TimeNs() - g->real_time_ns;
g->real_time_ns += g->real_dt_ns;
g->screen_size = P_GetWindowSize(window);
S_Scope *sprite_frame_scope = S_BeginScope();
//- Pull latest local sim snapshot
@ -1217,8 +1216,8 @@ void UpdateUser(P_Window *window)
/* Draw sprite */
if (!S_IsTagNil(sprite))
{
S_Sheet *sheet = S_SheetFromTagAsync(sprite_frame_scope, sprite);
S_Texture *texture = S_TextureFromTagAsync(sprite_frame_scope, sprite);
S_Sheet *sheet = S_SheetFromTagAsync(sprite);
S_Texture *texture = S_TextureFromTagAsync(sprite);
/* TODO: Fade in placeholder if texture isn't loaded */
if (sheet->loaded && texture->loaded)
@ -1245,8 +1244,8 @@ void UpdateUser(P_Window *window)
if (HasProp(ent, Prop_TileChunk))
{
Vec2I32 chunk_index = ent->tile_chunk_index;
S_Tag tile_sprite = S_TagFromPath(Lit("sprite/tile.ase"));
S_Texture *tile_texture = S_TextureFromTagAsync(sprite_frame_scope, tile_sprite);
S_Tag tile_sprite = S_TagFromName(Lit("sprite/tile.ase"));
S_Texture *tile_texture = S_TextureFromTagAsync(tile_sprite);
if (tile_texture->loaded)
{
f32 tile_size = 1.f / SIM_TILES_PER_UNIT_SQRT;
@ -1312,7 +1311,7 @@ void UpdateUser(P_Window *window)
/* Draw focus arrow */
if (ent == local_control || EqId(ent->id, g->debug_following))
{
S_Sheet *sheet = S_SheetFromTagAsync(sprite_frame_scope, ent->sprite);
S_Sheet *sheet = S_SheetFromTagAsync(ent->sprite);
S_Slice slice = S_SliceFromNameIndex(sheet, Lit("attach.wep"), ent->animation_frame);
Vec2 start = MulXformV2(sprite_xform, slice.center);
start = MulXformV2(g->world_to_ui_xf, start);
@ -1326,7 +1325,7 @@ void UpdateUser(P_Window *window)
/* Draw slices */
if (!S_IsTagNil(ent->sprite))
{
S_Sheet *sheet = S_SheetFromTagAsync(sprite_frame_scope, sprite);
S_Sheet *sheet = S_SheetFromTagAsync(sprite);
u32 quad_color = Rgba32F(1, 0, 0.5, 1);
u32 point_color = Rgba32F(1, 0, 0, 1);
@ -1495,16 +1494,15 @@ void UpdateUser(P_Window *window)
"normal: (%F, %F)\n"
"num contacts: %F"
);
String text = StringFormat(temp.arena, fmt,
FmtUint(e0->handle.idx),
FmtUint(e1->handle.idx),
FmtHex(point.id),
FmtFloat(point.normal_impulse),
FmtFloat(point.tangent_impulse),
FmtFloatP(point.starting_separation, 6),
FmtFloatP(data->normal.x, 6), FmtFloatP(data->normal.y, 6),
FmtUint(data->num_points));
String text = StringF(temp.arena, fmt,
FmtUint(e0->handle.idx),
FmtUint(e1->handle.idx),
FmtHex(point.id),
FmtFloat(point.normal_impulse),
FmtFloat(point.tangent_impulse),
FmtFloatP(point.starting_separation, 6),
FmtFloatP(data->normal.x, 6), FmtFloatP(data->normal.y, 6),
FmtUint(data->num_points));
draw_text(g->render_sig, disp_font, AddVec2(RoundVec2(MulXformV2(g->world_to_ui_xf, dbg_pt)), VEC2(0, offset_px)), text);
}
@ -1613,12 +1611,11 @@ void UpdateUser(P_Window *window)
"e1 pos: (%F, %F)\n"
"e1 rot: %F\n"
);
String text = StringFormat(temp.arena, fmt,
FmtFloatP(e0_xf.og.x, 24), FmtFloatP(e0_xf.og.y, 24),
FmtFloatP(RotationFromXform(e0_xf), 24),
FmtFloatP(e1_xf.og.x, 24), FmtFloatP(e1_xf.og.y, 24),
FmtFloatP(RotationFromXform(e1_xf), 24));
String text = StringF(temp.arena, fmt,
FmtFloatP(e0_xf.og.x, 24), FmtFloatP(e0_xf.og.y, 24),
FmtFloatP(RotationFromXform(e0_xf), 24),
FmtFloatP(e1_xf.og.x, 24), FmtFloatP(e1_xf.og.y, 24),
FmtFloatP(RotationFromXform(e1_xf), 24));
draw_text(g->render_sig, disp_font, AddVec2(RoundVec2(MulXformV2(g->world_to_ui_xf, VEC2(0, 0))), VEC2(0, offset_px)), text);
}
@ -1758,7 +1755,7 @@ void UpdateUser(P_Window *window)
__profn("Draw crosshair");
Vec2 crosshair_pos = g->ui_cursor;
S_Tag crosshair = S_TagFromPath(Lit("sprite/crosshair.ase"));
S_Texture *t = S_TextureFromTagAsync(sprite_frame_scope, crosshair);
S_Texture *t = S_TextureFromTagAsync(crosshair);
Vec2 size = VEC2(t->width, t->height);
Xform xf = XformFromTrs(TRS(.t = crosshair_pos, .s = size));
D_DrawUiRect(g->render_sig, D_UIRECTPARAMS(.xf = xf, .texture = t->gpu_resource));
@ -1776,7 +1773,7 @@ void UpdateUser(P_Window *window)
}
else
{
S_Texture *t = S_TextureFromTagAsync(sprite_frame_scope, S_TagFromPath(Lit("sprite/crosshair.ase")));
S_Texture *t = S_TextureFromTagAsync(S_TagFromPath(Lit("sprite/crosshair.ase")));
Vec2 size = VEC2(t->width, t->height);
Rect cursor_clip = RectFromVec2(g->ui_screen_offset, g->ui_size);
cursor_clip.pos = AddVec2(cursor_clip.pos, MulVec2(size, 0.5f));
@ -2025,97 +2022,97 @@ void UpdateUser(P_Window *window)
text.text = PushDry(temp.arena, u8);
#if BITBUFF_DEBUG
text.len += PushString(temp.arena, Lit("(bitbuff debug enabled)")).len;
text.len += PushString(temp.arena, Lit("\n")).len;
text.len += StringF(temp.arena, "(bitbuff debug enabled)").len;
text.len += StringF(temp.arena, "\n").len;
#endif
text.len += StringFormat(temp.arena, Lit("blended world entities: %F/%F"), FmtUint(g->ss_blended->num_ents_allocated), FmtUint(g->ss_blended->num_ents_reserved)).len;
text.len += PushString(temp.arena, Lit("\n")).len;
text.len += StringF(temp.arena, "blended world entities: %F/%F", FmtUint(g->ss_blended->num_ents_allocated), FmtUint(g->ss_blended->num_ents_reserved)).len;
text.len += StringF(temp.arena, "\n").len;
text.len += StringFormat(temp.arena, Lit("blended world tick: %F"), FmtUint(g->ss_blended->tick)).len;
text.len += PushString(temp.arena, Lit("\n")).len;
text.len += StringF(temp.arena, "blended world tick: %F", FmtUint(g->ss_blended->tick)).len;
text.len += StringF(temp.arena, "\n").len;
text.len += StringFormat(temp.arena, Lit("blended world time: %F"), FmtFloat(SecondsFromNs(g->ss_blended->sim_time_ns))).len;
text.len += PushString(temp.arena, Lit("\n")).len;
text.len += PushString(temp.arena, Lit("\n")).len;
text.len += StringF(temp.arena, "blended world time: %F", FmtFloat(SecondsFromNs(g->ss_blended->sim_time_ns))).len;
text.len += StringF(temp.arena, "\n").len;
text.len += StringF(temp.arena, "\n").len;
text.len += StringFormat(temp.arena, Lit("average local sim publish dt: %F"), FmtFloat(SecondsFromNs(g->average_local_to_user_snapshot_publish_dt_ns))).len;
text.len += PushString(temp.arena, Lit("\n")).len;
text.len += StringF(temp.arena, "average local sim publish dt: %F", FmtFloat(SecondsFromNs(g->average_local_to_user_snapshot_publish_dt_ns))).len;
text.len += StringF(temp.arena, "\n").len;
text.len += StringFormat(temp.arena, Lit("local sim last known tick: %F"), FmtUint(g->local_sim_last_known_tick)).len;
text.len += PushString(temp.arena, Lit("\n")).len;
text.len += StringF(temp.arena, "local sim last known tick: %F", FmtUint(g->local_sim_last_known_tick)).len;
text.len += StringF(temp.arena, "\n").len;
text.len += StringFormat(temp.arena, Lit("local sim last known time: %F"), FmtFloat(SecondsFromNs(g->local_sim_last_known_time_ns))).len;
text.len += PushString(temp.arena, Lit("\n")).len;
text.len += StringF(temp.arena, "local sim last known time: %F", FmtFloat(SecondsFromNs(g->local_sim_last_known_time_ns))).len;
text.len += StringF(temp.arena, "\n").len;
text.len += StringFormat(temp.arena, Lit("local sim predicted time: %F"), FmtFloat(SecondsFromNs(g->local_sim_predicted_time_ns))).len;
text.len += PushString(temp.arena, Lit("\n")).len;
text.len += StringF(temp.arena, "local sim predicted time: %F", FmtFloat(SecondsFromNs(g->local_sim_predicted_time_ns))).len;
text.len += StringF(temp.arena, "\n").len;
text.len += StringFormat(temp.arena, Lit("render time target: %F"), FmtFloat(SecondsFromNs(g->render_time_target_ns))).len;
text.len += PushString(temp.arena, Lit("\n")).len;
text.len += StringF(temp.arena, "render time target: %F", FmtFloat(SecondsFromNs(g->render_time_target_ns))).len;
text.len += StringF(temp.arena, "\n").len;
text.len += StringFormat(temp.arena, Lit("render time: %F"), FmtFloat(SecondsFromNs(g->render_time_ns))).len;
text.len += PushString(temp.arena, Lit("\n")).len;
text.len += PushString(temp.arena, Lit("\n")).len;
text.len += StringF(temp.arena, "render time: %F", FmtFloat(SecondsFromNs(g->render_time_ns))).len;
text.len += StringF(temp.arena, "\n").len;
text.len += StringF(temp.arena, "\n").len;
text.len += StringFormat(temp.arena, Lit("local player: [%F]"), FmtUid(local_player->id.uid)).len;
text.len += PushString(temp.arena, Lit("\n")).len;
text.len += PushString(temp.arena, Lit("\n")).len;
text.len += StringF(temp.arena, "local player: [%F]", FmtUid(local_player->id.uid)).len;
text.len += StringF(temp.arena, "\n").len;
text.len += StringF(temp.arena, "\n").len;
Vec2 world_cursor = g->world_cursor;
text.len += StringFormat(temp.arena, Lit("cursor world: %F, %F"), FmtFloat(world_cursor.x), FmtFloat(world_cursor.y)).len;
text.len += PushString(temp.arena, Lit("\n")).len;
text.len += StringF(temp.arena, "cursor world: %F, %F", FmtFloat(world_cursor.x), FmtFloat(world_cursor.y)).len;
text.len += StringF(temp.arena, "\n").len;
Vec2I32 world_tile_cursor = WorldTileIndexFromPos(world_cursor);
text.len += StringFormat(temp.arena, Lit("cursor world tile: %F, %F"), FmtSint(world_tile_cursor.x), FmtSint(world_tile_cursor.y)).len;
text.len += PushString(temp.arena, Lit("\n")).len;
text.len += StringF(temp.arena, "cursor world tile: %F, %F", FmtSint(world_tile_cursor.x), FmtSint(world_tile_cursor.y)).len;
text.len += StringF(temp.arena, "\n").len;
Vec2I32 local_tile_cursor = LocalTileIndexFromWorldTileIndex(world_tile_cursor);
text.len += StringFormat(temp.arena, Lit("cursor local tile: %F, %F"), FmtSint(local_tile_cursor.x), FmtSint(local_tile_cursor.y)).len;
text.len += PushString(temp.arena, Lit("\n")).len;
text.len += StringF(temp.arena, "cursor local tile: %F, %F", FmtSint(local_tile_cursor.x), FmtSint(local_tile_cursor.y)).len;
text.len += StringF(temp.arena, "\n").len;
Vec2I32 tile_chunk_cursor = TileChunkIndexFromWorldTileIndex(world_tile_cursor);
text.len += StringFormat(temp.arena, Lit("cursor tile chunk: %F, %F"), FmtSint(tile_chunk_cursor.x), FmtSint(tile_chunk_cursor.y)).len;
text.len += PushString(temp.arena, Lit("\n")).len;
text.len += PushString(temp.arena, Lit("\n")).len;
text.len += StringF(temp.arena, "cursor tile chunk: %F, %F", FmtSint(tile_chunk_cursor.x), FmtSint(tile_chunk_cursor.y)).len;
text.len += StringF(temp.arena, "\n").len;
text.len += StringF(temp.arena, "\n").len;
text.len += StringFormat(temp.arena, Lit("Network read: %F mbit/s"), FmtFloat((f64)g->net_bytes_read.last_second * 8 / 1000 / 1000)).len;
text.len += PushString(temp.arena, Lit("\n")).len;
text.len += StringF(temp.arena, "Network read: %F mbit/s", FmtFloat((f64)g->net_bytes_read.last_second * 8 / 1000 / 1000)).len;
text.len += StringF(temp.arena, "\n").len;
text.len += StringFormat(temp.arena, Lit("Network write: %F mbit/s"), FmtFloat((f64)g->net_bytes_sent.last_second * 8 / 1000 / 1000)).len;
text.len += PushString(temp.arena, Lit("\n")).len;
text.len += StringF(temp.arena, "Network write: %F mbit/s", FmtFloat((f64)g->net_bytes_sent.last_second * 8 / 1000 / 1000)).len;
text.len += StringF(temp.arena, "\n").len;
text.len += StringFormat(temp.arena, Lit("Ping (real): %F ms"), FmtFloat(SecondsFromNs(local_player->player_last_rtt_ns) * 1000)).len;
text.len += PushString(temp.arena, Lit("\n")).len;
text.len += StringF(temp.arena, "Ping (real): %F ms", FmtFloat(SecondsFromNs(local_player->player_last_rtt_ns) * 1000)).len;
text.len += StringF(temp.arena, "\n").len;
text.len += StringFormat(temp.arena, Lit("Ping (average): %F ms"), FmtFloat(local_player->player_average_rtt_seconds * 1000)).len;
text.len += PushString(temp.arena, Lit("\n")).len;
text.len += PushString(temp.arena, Lit("\n")).len;
text.len += StringF(temp.arena, "Ping (average): %F ms", FmtFloat(local_player->player_average_rtt_seconds * 1000)).len;
text.len += StringF(temp.arena, "\n").len;
text.len += StringF(temp.arena, "\n").len;
text.len += StringFormat(temp.arena, Lit("Memory committed: %F MiB"), FmtFloat((f64)GetGstat(GSTAT_MEMORY_COMMITTED) / 1024 / 1024)).len;
text.len += PushString(temp.arena, Lit("\n")).len;
text.len += StringF(temp.arena, "Memory committed: %F MiB", FmtFloat((f64)GetGstat(GSTAT_MEMORY_COMMITTED) / 1024 / 1024)).len;
text.len += StringF(temp.arena, "\n").len;
text.len += StringFormat(temp.arena, Lit("Virtual memory reserved: %F TiB"), FmtFloat((f64)GetGstat(GSTAT_MEMORY_RESERVED) / 1024 / 1024 / 1024 / 1024)).len;
text.len += PushString(temp.arena, Lit("\n")).len;
text.len += StringF(temp.arena, "Virtual memory reserved: %F TiB", FmtFloat((f64)GetGstat(GSTAT_MEMORY_RESERVED) / 1024 / 1024 / 1024 / 1024)).len;
text.len += StringF(temp.arena, "\n").len;
text.len += StringFormat(temp.arena, Lit("Arenas allocated: %F"), FmtUint(GetGstat(GSTAT_NUM_ARENAS))).len;
text.len += PushString(temp.arena, Lit("\n")).len;
text.len += PushString(temp.arena, Lit("\n")).len;
text.len += StringF(temp.arena, "Arenas allocated: %F", FmtUint(GetGstat(GSTAT_NUM_ARENAS))).len;
text.len += StringF(temp.arena, "\n").len;
text.len += StringF(temp.arena, "\n").len;
text.len += StringFormat(temp.arena, Lit("Video memory (GPU): %F MiB"), FmtFloat((f64)vram.local_used / 1024 / 1024)).len;
text.len += PushString(temp.arena, Lit("\n")).len;
text.len += StringFormat(temp.arena, Lit("Video memory (shared): %F MiB"), FmtFloat((f64)vram.non_local_used / 1024 / 1024)).len;
//text.len += PushString(temp.arena, Lit("\n")).len;
//text.len += PushString(temp.arena, Lit("\n")).len;
text.len += StringF(temp.arena, "Video memory (GPU): %F MiB", FmtFloat((f64)vram.local_used / 1024 / 1024)).len;
text.len += StringF(temp.arena, "\n").len;
text.len += StringF(temp.arena, "Video memory (shared): %F MiB", FmtFloat((f64)vram.non_local_used / 1024 / 1024)).len;
//text.len += StringF(temp.arena, \n")).len;
//text.len += StringF(temp.arena, \n")).len;
#if RtcIsEnabled
text.len += PushString(temp.arena, Lit("\n")).len;
text.len += PushString(temp.arena, Lit("\n")).len;
text.len += StringFormat(temp.arena, Lit("Debug steps: %F"), FmtUint(GetGstat(GSTAT_DEBUG_STEPS))).len;
//text.len += PushString(temp.arena, Lit("\n")).len;
text.len += StringF(temp.arena, "\n").len;
text.len += StringF(temp.arena, "\n").len;
text.len += StringF(temp.arena, "Debug steps: %F", FmtUint(GetGstat(GSTAT_DEBUG_STEPS))).len;
//text.len += StringF(temp.arena, \n")).len;
#endif
//draw_text(g->render_sig, font, pos, StringFormat(temp.arena, Lit("blended world entities: %F/%F"), FmtUint(g->ss_blended->num_ents_allocated), FmtUint(g->ss_blended->num_ents_reserved)));
//draw_text(g->render_sig, font, pos, StringF(temp.arena, "blended world entities: %F/%F", FmtUint(g->ss_blended->num_ents_allocated), FmtUint(g->ss_blended->num_ents_reserved)));
//draw_text(g->render_sig, font, pos, text);
Vec2 pos = VEC2(10, g->ui_size.y);
@ -2193,9 +2190,9 @@ void UpdateUser(P_Window *window)
GPU_Resource *grids_buffer = AcquireTransferBufferFromArena(g->grids_count, g->grids_arena);
GPU_CommandList *cl = GPU_BeginCommandList();
GPU_ProfileDF(cl, Lit("Run render"));
{
__profn("Run render");
GPU_ProfN(cl, Lit("Run render"));
Mat4x4 world_to_render_vp_matrix = ProjectMat4x4View(g->world_to_render_xf, render_viewport.width, render_viewport.height);
Mat4x4 ui_vp_matrix = ProjectMat4x4View(XformIdentity, ui_viewport.width, ui_viewport.height);
Mat4x4 blit_vp_matrix = ZI;
@ -2207,9 +2204,9 @@ void UpdateUser(P_Window *window)
}
//- Prep material pass
GPU_ProfileDF(cl, Lit("Clear gbuffers"));
{
__profn("Clear gbuffers");
GPU_ProfN(cl, Lit("Clear gbuffers"));
GPU_TransitionToRtv(cl, g->albedo);
GPU_TransitionToRtv(cl, g->emittance);
GPU_DispatchClear(cl, g->albedo);
@ -2217,9 +2214,9 @@ void UpdateUser(P_Window *window)
}
//- Material pass
GPU_ProfileDF(cl, Lit("Material pass"));
{
__profn("Material pass");
GPU_ProfN(cl, Lit("Material pass"));
GPU_Resource *rts[] = {
g->albedo,
@ -2252,9 +2249,9 @@ void UpdateUser(P_Window *window)
//- Flood pass
if (!effects_disabled)
GPU_ProfileDF(cl, Lit("Flood pass"));
{
__profn("Flood pass");
GPU_ProfN(cl, Lit("Flood pass"));
i32 step_length = -1;
@ -2262,11 +2259,11 @@ void UpdateUser(P_Window *window)
u64 max_steps = GetGstat(GSTAT_DEBUG_STEPS);
u64 step = 0;
while (step_length != 0 && step < max_steps)
GPU_ProfileDF(cl, Lit("Flood step"));
{
__profn("Flood step");
GPU_ProfN(cl, Lit("Flood step"));
GPU_Flush(cl, g->emittance_flood_read);
GPU_FlushUav(cl, g->emittance_flood_read);
FloodSig sig = ZI;
sig.step_len = step_length;
@ -2296,21 +2293,21 @@ void UpdateUser(P_Window *window)
}
//- Prep shade pass
GPU_ProfileDF(cl, Lit("Clear shade target"));
{
__profn("Clear shade target");
GPU_ProfN(cl, Lit("Clear shade target"));
GPU_TransitionToSrv(cl, g->albedo);
GPU_TransitionToSrv(cl, g->emittance);
GPU_TransitionToUav(cl, g->shade_target);
GPU_Flush(cl, g->emittance_flood_read);
GPU_Flush(cl, g->shade_read);
GPU_FlushUav(cl, g->emittance_flood_read);
GPU_FlushUav(cl, g->shade_read);
GPU_DispatchClear(cl, g->shade_target);
}
//- Shade pass
GPU_ProfileDF(cl, Lit("Shade pass"));
{
__profn("Shade pass");
GPU_ProfN(cl, Lit("Shade pass"));
u32 shade_flags = K_SHADE_FLAG_NONE;
if (effects_disabled)
@ -2341,18 +2338,18 @@ void UpdateUser(P_Window *window)
}
//- Prep ui pass
GPU_ProfileDF(cl, Lit("Clear ui target"));
{
__profn("Clear ui target");
GPU_ProfN(cl, Lit("Clear ui target"));
GPU_TransitionToRtv(cl, g->ui_target);
GPU_Flush(cl, g->shade_read);
GPU_FlushUav(cl, g->shade_read);
GPU_DispatchClear(cl, g->ui_target);
}
//- Ui blit pass
GPU_ProfileDF(cl, Lit("UI blit pass"));
{
__profn("UI blit pass");
GPU_ProfN(cl, Lit("UI blit pass"));
GPU_Viewport viewport = GPU_ViewportFromRect(ui_viewport);
GPU_Scissor scissor = GPU_ScissorFromRect(ui_viewport);
@ -2375,9 +2372,9 @@ void UpdateUser(P_Window *window)
}
//- Ui rect pass
GPU_ProfileDF(cl, Lit("UI rect pass"));
{
__profn("UI rect pass");
GPU_ProfN(cl, Lit("UI rect pass"));
GPU_Viewport viewport = GPU_ViewportFromRect(ui_viewport);
GPU_Scissor scissor = GPU_ScissorFromRect(ui_viewport);
@ -2397,9 +2394,9 @@ void UpdateUser(P_Window *window)
}
//- Ui shape pass
GPU_ProfileDF(cl, Lit("UI shape pass"));
{
__profn("UI shape pass");
GPU_ProfN(cl, Lit("UI shape pass"));
GPU_Viewport viewport = GPU_ViewportFromRect(ui_viewport);
GPU_Scissor scissor = GPU_ScissorFromRect(ui_viewport);
@ -2441,10 +2438,6 @@ void UpdateUser(P_Window *window)
}
}
//- End frame cache scopes
S_EndScope(sprite_frame_scope);
EndScratch(scratch);
}

View File

@ -36,7 +36,7 @@ void ResetSimAccel(Snapshot *ss, SimAccel *accel)
Entity *SpawnTestSmg(Entity *parent)
{
Entity *e = AcquireSyncSrc(parent);
e->sprite = S_TagFromPath(Lit("sprite/gun.ase"));
e->sprite = S_TagFromName(Lit("sprite/gun.ase"));
EnableProp(e, Prop_Attached);
e->attach_slice = Lit("attach.wep");
@ -52,7 +52,7 @@ Entity *SpawnTestSmg(Entity *parent)
Entity *SpawnTestLauncher(Entity *parent)
{
Entity *e = AcquireSyncSrc(parent);
e->sprite = S_TagFromPath(Lit("sprite/gun.ase"));
e->sprite = S_TagFromName(Lit("sprite/gun.ase"));
EnableProp(e, Prop_Attached);
e->attach_slice = Lit("attach.wep");
@ -68,7 +68,7 @@ Entity *SpawnTestLauncher(Entity *parent)
Entity *SpawnTestChucker(Entity *parent)
{
Entity *chucker = AcquireSyncSrc(parent);
chucker->sprite = S_TagFromPath(Lit("sprite/gun.ase"));
chucker->sprite = S_TagFromName(Lit("sprite/gun.ase"));
EnableProp(chucker, Prop_Attached);
chucker->attach_slice = Lit("attach.wep");
@ -119,12 +119,12 @@ Entity *SpawnTestEmployee(Entity *parent)
{
EnableProp(e, Prop_Test);
e->sprite = S_TagFromPath(Lit("sprite/tim.ase"));
e->sprite = S_TagFromName(Lit("sprite/tim.ase"));
e->mass_unscaled = 10;
e->inertia_unscaled = 5;
}
//e->sprite = S_TagFromPath(Lit("sprite/box_rounded.ase"));
//e->sprite = S_TagFromName(Lit("sprite/box_rounded.ase"));
//e->sprite_span_name = Lit("idle.unarmed");
//e->sprite_span_name = Lit("idle.one_handed");
e->sprite_span_name = Lit("idle.two_handed");
@ -257,7 +257,7 @@ void SpawnTestEntities2(Entity *parent, Vec2 pos)
Xform xf = XformFromTrs(TRS(.t = pos, .r = rot, .s = size));
SetXform(e, xf);
e->sprite = S_TagFromPath(Lit("sprite/tile.ase"));
e->sprite = S_TagFromName(Lit("sprite/tile.ase"));
e->layer = Layer_Shoulders;
//e->sprite_tint = Alpha32F(ColorBlue, 0.75);
@ -299,7 +299,7 @@ void SpawnTestEntities2(Entity *parent, Vec2 pos)
Xform xf = XformFromTrs(.t = pos, .r = r, .s = size);
SetXform(e, xf);
e->sprite = S_TagFromPath(Lit("sprite/bullet.ase"));
e->sprite = S_TagFromName(Lit("sprite/bullet.ase"));
e->sprite_collider_slice = Lit("shape");
e->layer = Layer_Shoulders;
@ -327,7 +327,7 @@ void SpawnTestEntities3(Entity *parent, Vec2 pos)
Xform xf = XformFromTrs(TRS(.t = pos, .r = r, .s = size));
SetXform(e, xf);
e->sprite = S_TagFromPath(Lit("sprite/box.ase"));
e->sprite = S_TagFromName(Lit("sprite/box.ase"));
e->layer = Layer_Shoulders;
e->sprite_tint = ColorRed;
@ -350,8 +350,8 @@ void SpawnTestEntities4(Entity *parent, Vec2 pos)
Xform xf = XformFromTrs(TRS(.t = pos, .r = r, .s = size));
SetXform(e, xf);
//e->sprite = S_TagFromPath(Lit("sprite/box.ase"));
e->sprite = S_TagFromPath(Lit("sprite/tile.ase"));
//e->sprite = S_TagFromName(Lit("sprite/box.ase"));
e->sprite = S_TagFromName(Lit("sprite/tile.ase"));
e->layer = Layer_Shoulders;
EnableProp(e, Prop_LightTest);
@ -380,15 +380,11 @@ void SpawnTestTile(Snapshot *world, Vec2 world_pos)
SetXform(e, xf);
e->layer = Layer_Walls;
e->sprite = S_TagFromPath(Lit("sprite/tile.ase"));
e->sprite = S_TagFromName(Lit("sprite/tile.ase"));
e->sprite_tint = ColorRed;
{
S_Scope *scope = S_BeginScope();
S_Sheet *sheet = S_SheetFromTagAwait(scope, e->sprite);
e->sprite_local_xform = XformFromTrs(.s = DivVec2(sheet->frame_size, PIXELS_PER_UNIT));
S_EndScope(scope);
}
S_Sheet *sheet = S_SheetFromTagAwait(e->sprite);
e->sprite_local_xform = XformFromTrs(.s = DivVec2(sheet->frame_size, PIXELS_PER_UNIT));
EnableProp(e, Prop_Solid);
Quad collider_quad = QuadFromRect(RectFromScalar(-tile_size.x / 2, -tile_size.y / 2, tile_size.y, tile_size.y));
@ -787,7 +783,7 @@ CollisionCallbackFuncDef(OnEntityCollision, data, step_ctx)
{
Xform xf = XformFromTrs(TRS(.t = point, .r = RandF64FromState(&step_ctx->rand, 0, Tau)));
Entity *decal = AcquireSyncSrc(root);
decal->sprite = S_TagFromPath(Lit("sprite/blood.ase"));
decal->sprite = S_TagFromName(Lit("sprite/blood.ase"));
decal->sprite_tint = Rgba32F(1, 1, 1, 0.25f);
decal->layer = Layer_FloorDecals;
SetXform(decal, xf);
@ -901,8 +897,6 @@ void StepSim(SimStepCtx *ctx)
world->sim_time_ns += world->sim_dt_ns;
f32 sim_dt = SecondsFromNs(world->sim_dt_ns);
S_Scope *sprite_frame_scope = S_BeginScope();
Entity *root = EntityFromId(world, RootEntityId);
root->owner = world->client->player_id;
@ -1257,7 +1251,7 @@ void StepSim(SimStepCtx *ctx)
if (!ShouldSimulate(ent)) continue;
if (S_IsTagNil(ent->sprite)) continue;
S_Sheet *sheet = S_SheetFromTagAwait(sprite_frame_scope, ent->sprite);
S_Sheet *sheet = S_SheetFromTagAwait(ent->sprite);
/* Update animation */
{
@ -1297,16 +1291,16 @@ void StepSim(SimStepCtx *ctx)
#if 0
/* Update sprite local xform */
{
S_Slice slice = S_SliceFromNameIndex(sheet, Lit("pivot"), ent->animation_frame);
S_Slice pivot_slice = S_SliceFromName(sheet, Lit("pivot"), ent->animation_frame);
Vec2 sprite_size = DivVec2(sheet->frame_size, (f32)PIXELS_PER_UNIT);
Vec2 dir = MulVec2Vec2(sprite_size, slice.dir);
Vec2 dir = MulVec2Vec2(sprite_size, pivot_slice.dir);
f32 rot = AngleFromVec2(dir) + Pi / 2;
Xform xf = XformIdentity;
xf = RotateXform(xf, -rot);
xf = ScaleXform(xf, sprite_size);
xf = TranslateXform(xf, NegVec2(slice.center));
xf = TranslateXform(xf, NegVec2(pivot_slice.center));
ent->sprite_local_xform = xf;
}
#endif
@ -1315,8 +1309,7 @@ void StepSim(SimStepCtx *ctx)
if (ent->sprite_collider_slice.len > 0)
{
Xform cxf = ent->sprite_local_xform;
S_Slice slice = S_SliceFromNameIndex(sheet, ent->sprite_collider_slice, ent->animation_frame);
S_Slice slice = S_SliceFromName(sheet, ent->sprite_collider_slice, ent->animation_frame);
ent->local_collider = CLD_ShapeFromQuad(MulXformQuad(cxf, QuadFromRect(slice.rect)));
}
@ -1367,11 +1360,11 @@ void StepSim(SimStepCtx *ctx)
Entity *parent = EntityFromId(world, ent->parent);
S_Tag parent_sprite = parent->sprite;
S_Sheet *parent_sheet = S_SheetFromTagAwait(sprite_frame_scope, parent_sprite);
S_Sheet *parent_sheet = S_SheetFromTagAwait(parent_sprite);
Xform parent_sprite_xf = parent->sprite_local_xform;
S_Slice attach_slice = S_SliceFromNameIndex(parent_sheet, ent->attach_slice, parent->animation_frame);
S_Slice attach_slice = S_SliceFromName(parent_sheet, ent->attach_slice, parent->animation_frame);
Vec2 attach_pos = MulXformV2(parent_sprite_xf, attach_slice.center);
Vec2 attach_dir = MulXformBasisV2(parent_sprite_xf, attach_slice.dir);
@ -1459,9 +1452,9 @@ void StepSim(SimStepCtx *ctx)
{
S_Tag sprite = ent->sprite;
u32 animation_frame = ent->animation_frame;
S_Sheet *sheet = S_SheetFromTagAwait(sprite_frame_scope, sprite);
S_Sheet *sheet = S_SheetFromTagAwait(sprite);
Xform sprite_local_xform = ent->sprite_local_xform;
S_Slice out_slice = S_SliceFromNameIndex(sheet, Lit("out"), animation_frame);
S_Slice out_slice = S_SliceFromName(sheet, Lit("out"), animation_frame);
Vec2 rel_pos = MulXformV2(sprite_local_xform, out_slice.center);
Vec2 rel_dir = MulXformBasisV2(sprite_local_xform, out_slice.dir);
@ -1484,7 +1477,7 @@ void StepSim(SimStepCtx *ctx)
bullet->local_collider.points[0] = VEC2(0, 0);
bullet->local_collider.count = 1;
#else
bullet->sprite = S_TagFromPath(Lit("sprite/bullet.ase"));
bullet->sprite = S_TagFromName(Lit("sprite/bullet.ase"));
bullet->sprite_collider_slice = Lit("shape");
#endif
}
@ -1508,9 +1501,9 @@ void StepSim(SimStepCtx *ctx)
{
S_Tag sprite = ent->sprite;
u32 animation_frame = ent->animation_frame;
S_Sheet *sheet = S_SheetFromTagAwait(sprite_frame_scope, sprite);
S_Sheet *sheet = S_SheetFromTagAwait(sprite);
Xform sprite_local_xform = ent->sprite_local_xform;
S_Slice out_slice = S_SliceFromNameIndex(sheet, Lit("out"), animation_frame);
S_Slice out_slice = S_SliceFromName(sheet, Lit("out"), animation_frame);
Vec2 rel_pos = MulXformV2(sprite_local_xform, out_slice.center);
Vec2 rel_dir = MulXformBasisV2(sprite_local_xform, out_slice.dir);
@ -1680,8 +1673,8 @@ void StepSim(SimStepCtx *ctx)
Vec2 sprite_hold_pos;
Vec2 sprite_hold_dir;
{
S_Sheet *sheet = S_SheetFromTagAwait(sprite_frame_scope, ent->sprite);
S_Slice slice = S_SliceFromNameIndex(sheet, Lit("attach.wep"), ent->animation_frame);
S_Sheet *sheet = S_SheetFromTagAwait(ent->sprite);
S_Slice slice = S_SliceFromName(sheet, Lit("attach.wep"), ent->animation_frame);
sprite_hold_pos = slice.center;
sprite_hold_dir = slice.dir;
}
@ -2073,9 +2066,5 @@ void StepSim(SimStepCtx *ctx)
pub_world->local_player = world->local_player;
}
//- End frame
S_EndScope(sprite_frame_scope);
EndScratch(scratch);
}

View File

@ -0,0 +1,24 @@
////////////////////////////////
//~ Tag helpers
R_Tag R_TagFromName(String name)
{
R_Tag result = ZI;
return result;
}
////////////////////////////////
//~ Resource operations
String R_DataFromTag(R_Tag tag)
{
String result = ZI;
return result;
}
String R_NameFromTag(R_Tag tag)
{
String result = ZI;
return result;
}

View File

@ -9,5 +9,10 @@ Struct(R_Tag)
////////////////////////////////
//~ Tag helpers
R_Tag R_TagFromName(String name);
////////////////////////////////
//~ Resource operations
String R_DataFromTag(R_Tag tag);
String R_NameFromTag(R_Tag tag);

View File

@ -27,7 +27,7 @@ String SETTINGS_StringFromWindowSettings(Arena *arena, const P_WindowSettings *s
"}\n"
);
String formatted = StringFormat(arena,
String formatted = FormatString(arena,
fmt,
FmtString(minimized),
FmtString(maximized),
@ -165,11 +165,11 @@ abort:
{
if (json_error.msg.len > 0)
{
*error_out = StringFormat(arena,
Lit("%F\n(%F:%F)"),
FmtString(json_error.msg),
FmtUint(json_error.start),
FmtUint(json_error.end));
*error_out = StringF(arena,
Lit("%F\n(%F:%F)"),
FmtString(json_error.msg),
FmtUint(json_error.start),
FmtUint(json_error.end));
}
else
{

View File

@ -87,10 +87,10 @@ AC_Asset *SND_LoadAsset(R_Tag resource, SND_SoundFlag flags, b32 wait)
/* Generate and append sound flags to name key */
String name = R_NameFromTag(resource);
String key = StringFormat(scratch.arena,
Lit("%F%F_sound"),
FmtString(name),
FmtUint((u64)flags));
String key = StringF(scratch.arena,
"%F%F_sound",
FmtString(name),
FmtUint((u64)flags));
u64 hash = AC_HashFromKey(key);
b32 is_first_touch;
AC_Asset *asset = AC_TouchCache(key, hash, &is_first_touch);

File diff suppressed because it is too large Load Diff

View File

@ -1,14 +1,13 @@
////////////////////////////////
//~ Tag
//~ Tag types
Struct(S_Tag)
{
u64 hash;
String path;
R_Tag r;
};
////////////////////////////////
//~ Texture
//~ Texture types
Struct(S_Texture)
{
@ -90,160 +89,12 @@ Struct(S_Sheet)
Dict *slice_groups_dict;
};
////////////////////////////////
//~ Cache types
Enum(S_CacheEntryKind)
{
S_CacheEntryKind_Texture,
S_CacheEntryKind_Sheet,
S_CacheEntryKind_Count
};
Enum(S_CacheEntryState)
{
S_CacheEntryState_None,
S_CacheEntryState_Queued,
S_CacheEntryState_Working,
S_CacheEntryState_Loaded
};
Struct(S_Refcount)
{
i32 count; /* Number of scopes currently holding a reference to this entry */
i32 last_ref_cycle; /* Last evictor cycle that the refcount was modified */
};
StaticAssert(sizeof(S_Refcount) == 8); /* Must fit into 64 bit atomic */
Struct(S_Hash)
{
u64 v;
};
Struct(S_CacheEntry)
{
S_CacheEntryKind kind;
S_Hash hash;
Atomic32 state;
Atomic64Padded refcount_struct; /* Cast fetched result to `cache_refcount` */
/* Acquired data */
/* NOTE: This data is finalized once entry state = loaded */
i64 load_time_ns;
u64 memory_usage;
Arena *arena;
S_Texture *texture;
S_Sheet *sheet;
/* Hash list */
S_CacheEntry *next_in_bin;
S_CacheEntry *prev_in_bin;
/* Free list */
S_CacheEntry *next_free;
};
Struct(S_CacheEntryBin)
{
Mutex mutex;
S_CacheEntry *first;
S_CacheEntry *last;
};
Struct(S_Cache)
{
Atomic64Padded memory_usage;
Arena *arena;
S_CacheEntryBin *bins;
Mutex entry_pool_mutex;
S_CacheEntry *entry_pool_first_free;
};
/* Represents a reference that can be used to safely access cache entry without it becoming evicted during the reference's lifetime */
Struct(S_CacheEntryRef)
{
S_CacheEntry *e;
};
////////////////////////////////
//~ Scope types
/* A cache reference whose lifetime is bound to the scope it was retrieved from */
Struct(S_ScopeCacheEntryRef)
{
S_CacheEntryRef ref;
S_ScopeCacheEntryRef *next_in_bin;
};
Struct(S_Scope)
{
S_ScopeCacheEntryRef **ref_node_bins;
S_ScopeCacheEntryRef *ref_node_pool;
u64 num_references;
S_Scope *next_free;
};
////////////////////////////////
//~ Evictor types
Struct(S_EvictorNode)
{
i32 last_ref_cycle;
S_CacheEntry *cache_entry;
S_CacheEntryBin *cache_bin;
S_EvictorNode *next_evicted;
};
////////////////////////////////
//~ Cache constants
/* Texture arena only used to store texture struct at the moment. Actual image data is allocated on GPU. */
#define S_TextureArenaReserve Mebi(1)
#define S_CacheBinsCount 1024
#define S_MaxScopeReferences 1024
#define S_SheetArenaReserve Mebi(64)
#define S_SheetSpanLookupTableBinRatio 2.0
#define S_SliceLookupTableBinRatio 2.0
/* How long between evictor cycles */
#define S_EvictorCycleIntervalNs NsFromSeconds(0.500)
/* How many cycles a cache entry spends unused until it's considered evictable */
#define S_EvictorGracePeriodCycles (NsFromSeconds(10.000) / S_EvictorCycleIntervalNs)
/* The evictor will begin evicting once cache usage is > threshold.
* It will entries until the budget has shrunk < target. */
#define S_CacheMemoryBudgetThreshold (Mebi(256))
#define S_CacheMemoryBudgetTarget (Mebi(128))
StaticAssert(S_CacheMemoryBudgetThreshold >= S_CacheMemoryBudgetTarget);
////////////////////////////////
//~ Shared state
Struct(S_SharedState)
{
Arena *perm_arena;
S_Texture *nil_texture;
S_Texture *loading_texture;
S_Sheet *nil_sheet;
S_Sheet *loading_sheet;
/* Cache */
S_Cache cache;
/* Scopes */
Mutex scopes_mutex;
Arena *scopes_arena;
S_Scope *first_free_scope;
/* Evictor */
Atomic32Padded evictor_cycle;
Counter shutdown_counter;
b32 evictor_scheduler_shutdown;
Mutex evictor_scheduler_mutex;
Cv evictor_scheduler_shutdown_cv;
i32 _;
};
extern S_SharedState S_shared_state;
@ -254,85 +105,24 @@ extern S_SharedState S_shared_state;
void S_Startup(void);
////////////////////////////////
//~ Shutdown
//~ Tag helpers
ExitFuncDef(S_Shutdown);
////////////////////////////////
//~ Purple-black image
u32 *S_GeneratePurpleBlackImage(Arena *arena, u32 width, u32 height);
////////////////////////////////
//~ Tag operations
S_Tag S_TagFromPath(String path);
b32 S_IsTagNil(S_Tag tag);
b32 S_EqTag(S_Tag t1, S_Tag t2);
S_Hash S_CacheEntryFromTagHash(u64 tag_hash, S_CacheEntryKind kind);
S_Tag S_TagFromName(String name);
S_Tag S_TagFromResource(R_Tag resource);
////////////////////////////////
//~ Sheet init
//~ Texture operations
S_Sheet S_SheetFromAseResult(Arena *arena, ASE_DecodedSheet ase);
S_Texture *S_TextureFromTagAwait(S_Tag tag);
S_Texture *S_TextureFromTagAsync(S_Tag tag);
////////////////////////////////
//~ Load job
//~ Sheet operations
void S_PushLoadJob(S_CacheEntryRef ref, S_Tag tag);
JobDecl(S_LoadSpriteJob, { S_Scope *scope; S_CacheEntryRef ref; S_Tag tag; });
S_Sheet *S_SheetFromTagAwait(S_Tag tag);
S_Sheet *S_SheetFromTagAsync(S_Tag tag);
////////////////////////////////
//~ Cache load operations
void S_LoadCacheEntryTexture(S_CacheEntryRef ref, S_Tag tag);
void S_LoadCacheEntrySheet(S_CacheEntryRef ref, S_Tag tag);
////////////////////////////////
//~ Ref operations
void S_AddRef(S_CacheEntry *e, i32 amount);
S_ScopeCacheEntryRef *S_EnsureRefUnsafely(S_Scope *scope, S_CacheEntry *e);
S_ScopeCacheEntryRef *S_EnsureRefFromEntryLocked(S_Scope *scope, S_CacheEntry *e, Lock *bin_lock);
S_ScopeCacheEntryRef *S_EnsureRefFromRef(S_Scope *scope, S_CacheEntryRef ref);
////////////////////////////////
//~ Scope operations
S_Scope *S_BeginScope(void);
void S_EndScope(S_Scope *scope);
////////////////////////////////
//~ Cache lookup operations
S_ScopeCacheEntryRef *S_EntryFromHashLocked(S_Scope *scope, S_Hash hash, Lock *bin_lock);
S_ScopeCacheEntryRef *S_EntryFromTag(S_Scope *scope, S_Tag tag, S_CacheEntryKind kind, b32 force_new);
void *S_DataFromTag(S_Scope *scope, S_Tag tag, S_CacheEntryKind kind, b32 await);
////////////////////////////////
//~ Texture retrieval operations
S_Texture *S_TextureFromTagAwait(S_Scope *scope, S_Tag tag);
S_Texture *S_TextureFromTagAsync(S_Scope *scope, S_Tag tag);
void S_PrefetchTextureFromTag(S_Scope *scope, S_Tag tag);
////////////////////////////////
//~ Sheet retrieval operations
S_Sheet *S_SheetFromTagAwait(S_Scope *scope, S_Tag tag);
S_Sheet *S_SheetFromTagAsync(S_Scope *scope, S_Tag tag);
void S_PrefetchSheetFromTag(S_Scope *scope, S_Tag tag);
////////////////////////////////
//~ Sheet data operations
S_Frame S_FrameFromIndex(S_Sheet *sheet, u32 index);
S_Span S_SpanFromName(S_Sheet *sheet, String name);
S_Slice S_SliceFromNameIndex(S_Sheet *sheet, String name, u32 frame_index);
S_SliceArray S_SlicesFromNameIndex(S_Sheet *sheet, String name, u32 frame_index);
////////////////////////////////
//~ Evictor job
MergesortCompareFuncDef(S_EvictorSortCmp, arg_a, arg_b, udata);
JobDecl(S_EvictorJob, EmptySig);
S_Frame S_FrameFromIndex(S_Sheet *sheet, u64 index);
S_Slice S_SliceFromName(S_Sheet *sheet, String name, u64 frame_index);

View File

@ -1,7 +1,6 @@
@Layer sprite
//- Dependencies
@Dep platform
@Dep gpu
@Dep ase