res refactor progress
This commit is contained in:
parent
db9d3677d5
commit
a8fb832bcb
@ -10,7 +10,7 @@ String InitializeAppWriteDirectory(Arena *arena, String write_dir)
|
|||||||
/* Create write path */
|
/* Create write path */
|
||||||
String base_write_dir = P_GetWritePath(scratch.arena);
|
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_fmt = base_write_dir.len > 0 ? Lit("%F/%F/") : Lit("%F%F/");
|
||||||
String write_path = StringFormat(
|
String write_path = FormatString(
|
||||||
arena,
|
arena,
|
||||||
write_path_fmt,
|
write_path_fmt,
|
||||||
FmtString(base_write_dir),
|
FmtString(base_write_dir),
|
||||||
@ -231,14 +231,12 @@ void Startup(void)
|
|||||||
if (error.len > 0)
|
if (error.len > 0)
|
||||||
{
|
{
|
||||||
P_LogInfoF("Failed to load settings file with error - %F", FmtString(error));
|
P_LogInfoF("Failed to load settings file with error - %F", FmtString(error));
|
||||||
String msg = StringFormat(temp.arena,
|
String msg = StringF(temp.arena,
|
||||||
Lit(
|
|
||||||
"Failed to loading settings file \"%F\":\n"
|
"Failed to loading settings file \"%F\":\n"
|
||||||
"------------\n"
|
"------------\n"
|
||||||
"%F\n"
|
"%F\n"
|
||||||
"------------\n"
|
"------------\n"
|
||||||
"To stop this error from appearing, either fix the issue above or delete the file from the system."
|
"To stop this error from appearing, either fix the issue above or delete the file from the system.",
|
||||||
),
|
|
||||||
FmtString(settings_path),
|
FmtString(settings_path),
|
||||||
FmtString(error));
|
FmtString(error));
|
||||||
Panic(msg);
|
Panic(msg);
|
||||||
|
|||||||
@ -502,8 +502,8 @@ ASE_DecodedImage ASE_DecodeImage(Arena *arena, String encoded)
|
|||||||
|
|
||||||
if (ase_header.color_depth != 32)
|
if (ase_header.color_depth != 32)
|
||||||
{
|
{
|
||||||
String msg = StringFormat(scratch.arena,
|
String msg = StringF(scratch.arena,
|
||||||
Lit("Only 32 bit rgba color mode is supported (got %F)"),
|
"Only 32 bit rgba color mode is supported (got %F)",
|
||||||
FmtUint(ase_header.color_depth));
|
FmtUint(ase_header.color_depth));
|
||||||
ASE_PushError(arena, &result.errors, msg);
|
ASE_PushError(arena, &result.errors, msg);
|
||||||
goto abort;
|
goto abort;
|
||||||
|
|||||||
@ -37,12 +37,6 @@
|
|||||||
# error Missing compile time definition for 'TestsAreEnabled'
|
# error Missing compile time definition for 'TestsAreEnabled'
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef IncbinRawDir
|
|
||||||
# error Missing compile time definition for 'IncbinRawDir'
|
|
||||||
#else
|
|
||||||
# define IncbinDir Stringize(IncbinRawDir)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ Machine context
|
//~ Machine context
|
||||||
|
|
||||||
|
|||||||
@ -207,7 +207,7 @@ Inline ArenaCtx *ArenaCtxFromFiberId(i16 fiber_id)
|
|||||||
* scope that could potentially be a scratch arena from another scope. */
|
* scope that could potentially be a scratch arena from another scope. */
|
||||||
Inline TempArena BeginScratch(Arena *potential_conflict)
|
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);
|
StaticAssert(ScratchArenasPerCtx == 2);
|
||||||
|
|
||||||
/* Use `BeginScratchNoConflict` if no conflicts are present */
|
/* Use `BeginScratchNoConflict` if no conflicts are present */
|
||||||
@ -215,7 +215,7 @@ Inline TempArena BeginScratch(Arena *potential_conflict)
|
|||||||
|
|
||||||
ArenaCtx *ctx = ArenaCtxFromFiberId(FiberId);
|
ArenaCtx *ctx = ArenaCtxFromFiberId(FiberId);
|
||||||
Arena *scratch_arena = ctx->scratch_arenas[0];
|
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];
|
scratch_arena = ctx->scratch_arenas[1];
|
||||||
}
|
}
|
||||||
|
|||||||
@ -33,9 +33,9 @@ Enum(JobPriority)
|
|||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ @hookdecl Startup
|
//~ @hookdecl Init
|
||||||
|
|
||||||
void StartupBaseJobs(void);
|
void InitJobWorkers(void);
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ @hookdecl Futex
|
//~ @hookdecl Futex
|
||||||
|
|||||||
@ -293,12 +293,12 @@ f32 LnF32(f32 x)
|
|||||||
if ((x_int & 0x7fffffff) == 0)
|
if ((x_int & 0x7fffffff) == 0)
|
||||||
{
|
{
|
||||||
/* Return -inf if x is 0 */
|
/* Return -inf if x is 0 */
|
||||||
return -two_p25 / 0;
|
return -F32Infinity;
|
||||||
}
|
}
|
||||||
else if (x_int < 0)
|
else if (x_int < 0)
|
||||||
{
|
{
|
||||||
/* Return NaN if x is negative */
|
/* Return NaN if x is negative */
|
||||||
return (x - x) / 0;
|
return F32Nan;
|
||||||
}
|
}
|
||||||
k -= 25;
|
k -= 25;
|
||||||
x *= two_p25;
|
x *= two_p25;
|
||||||
|
|||||||
@ -493,10 +493,10 @@ String Trim(String s, String pattern)
|
|||||||
* included in the arguments (instead of w/ the specifier like in printf).
|
* included in the arguments (instead of w/ the specifier like in printf).
|
||||||
*
|
*
|
||||||
* Example:
|
* 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
|
* 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:
|
* Format arguments:
|
||||||
* FmtChar: Format a single u8 character
|
* FmtChar: Format a single u8 character
|
||||||
@ -515,7 +515,7 @@ String Trim(String s, String pattern)
|
|||||||
* %e/%E equivalent? (scientific notation of floats)
|
* %e/%E equivalent? (scientific notation of floats)
|
||||||
* %o equivalent? (octal representation)
|
* %o equivalent? (octal representation)
|
||||||
*/
|
*/
|
||||||
String StringFormatV(Arena *arena, String fmt, va_list args)
|
String FormatStringV(Arena *arena, String fmt, va_list args)
|
||||||
{
|
{
|
||||||
__prof;
|
__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_list args;
|
||||||
va_start(args, fmt);
|
va_start(args, fmt);
|
||||||
String new_str = StringFormatV(arena, fmt, args);
|
String new_str = FormatStringV(arena, fmt, args);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
return new_str;
|
return new_str;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -112,10 +112,10 @@ String StringFromList(Arena *arena, StringList l, String separator);
|
|||||||
#define FmtEnd (FmtArg) {.kind = FmtKind_End}
|
#define FmtEnd (FmtArg) {.kind = FmtKind_End}
|
||||||
|
|
||||||
//- Format functions
|
//- Format functions
|
||||||
#define StringF(arena, lit, ...) StringFormat_((arena), Lit(lit), __VA_ARGS__, FmtEnd)
|
#define StringF(arena, lit, ...) FormatString_((arena), Lit(lit), __VA_ARGS__, FmtEnd)
|
||||||
#define StringFormat(arena, fmt, ...) StringFormat_((arena), (fmt), __VA_ARGS__, FmtEnd)
|
#define FormatString(arena, fmt, ...) FormatString_((arena), (fmt), __VA_ARGS__, FmtEnd)
|
||||||
String StringFormat_(Arena *arena, String fmt, ...);
|
String FormatString_(Arena *arena, String fmt, ...);
|
||||||
String StringFormatV(Arena *arena, String fmt, va_list args);
|
String FormatStringV(Arena *arena, String fmt, va_list args);
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ Unicode operations
|
//~ Unicode operations
|
||||||
|
|||||||
@ -18,7 +18,10 @@ b32 Panic(String msg)
|
|||||||
MessageBoxExA(0, msg_cstr, "Fatal error", mb_flags, 0);
|
MessageBoxExA(0, msg_cstr, "Fatal error", mb_flags, 0);
|
||||||
}
|
}
|
||||||
HANDLE console_handle = GetStdHandle(STD_ERROR_HANDLE);
|
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())
|
if (IsRunningInDebugger())
|
||||||
{
|
{
|
||||||
Assert(0);
|
Assert(0);
|
||||||
@ -184,8 +187,8 @@ i32 W32_Main(void)
|
|||||||
/* Query system info */
|
/* Query system info */
|
||||||
GetSystemInfo(&g->info);
|
GetSystemInfo(&g->info);
|
||||||
|
|
||||||
//- Startup jobs
|
//- Startup workers
|
||||||
StartupBaseJobs();
|
InitJobWorkers();
|
||||||
|
|
||||||
/* Startup layers */
|
/* Startup layers */
|
||||||
if (!Atomic32Fetch(&g->panicking))
|
if (!Atomic32Fetch(&g->panicking))
|
||||||
|
|||||||
@ -3,7 +3,7 @@ W32_SharedJobCtx W32_shared_job_ctx = ZI;
|
|||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ @hookdef Startup
|
//~ @hookdef Startup
|
||||||
|
|
||||||
void StartupBaseJobs(void)
|
void InitJobWorkers(void)
|
||||||
{
|
{
|
||||||
W32_SharedJobCtx *g = &W32_shared_job_ctx;
|
W32_SharedJobCtx *g = &W32_shared_job_ctx;
|
||||||
|
|
||||||
@ -114,7 +114,7 @@ void StartupBaseJobs(void)
|
|||||||
W32_WorkerCtx *ctx = &pool->worker_contexts[i];
|
W32_WorkerCtx *ctx = &pool->worker_contexts[i];
|
||||||
ctx->pool_kind = pool_kind;
|
ctx->pool_kind = pool_kind;
|
||||||
ctx->id = i;
|
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);
|
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)
|
for (W32_Thread *t = g->first_thread; t; t = t->next)
|
||||||
{
|
{
|
||||||
String name = StringFromCstr(t->thread_name_cstr, countof(t->thread_name_cstr));
|
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;
|
++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);
|
//Panic(threads_msg);
|
||||||
EndScratch(scratch);
|
EndScratch(scratch);
|
||||||
}
|
}
|
||||||
@ -1056,7 +1056,7 @@ W32_ThreadDef(W32_JobWorkerEntryFunc, worker_ctx_arg)
|
|||||||
{
|
{
|
||||||
/* Invalid yield kind */
|
/* Invalid yield kind */
|
||||||
TempArena scratch = BeginScratchNoConflict();
|
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);
|
EndScratch(scratch);
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
|
|||||||
@ -41,8 +41,8 @@ JobDef(F_LoadJob, sig, _)
|
|||||||
if (resource_data.len == 0)
|
if (resource_data.len == 0)
|
||||||
{
|
{
|
||||||
/* FIME: Load baked font instead of panicking */
|
/* FIME: Load baked font instead of panicking */
|
||||||
Panic(StringFormat(scratch.arena,
|
Panic(StringF(scratch.arena,
|
||||||
Lit("Font \"%F\" not found"),
|
"Font \"%F\" not found",
|
||||||
FmtString(name)));
|
FmtString(name)));
|
||||||
}
|
}
|
||||||
TTF_Result result = TTF_Decode(scratch.arena, resource_data, point_size, font_codes, countof(font_codes));
|
TTF_Result result = TTF_Decode(scratch.arena, resource_data, point_size, font_codes, countof(font_codes));
|
||||||
@ -78,8 +78,8 @@ JobDef(F_LoadJob, sig, _)
|
|||||||
/* FIXME: Load baked font instead of panicking */
|
/* FIXME: Load baked font instead of panicking */
|
||||||
if (font->glyphs_count <= 0)
|
if (font->glyphs_count <= 0)
|
||||||
{
|
{
|
||||||
Panic(StringFormat(scratch.arena,
|
Panic(StringF(scratch.arena,
|
||||||
Lit("Parsed 0 glyphs from font \"%F\"!"),
|
"Parsed 0 glyphs from font \"%F\"!",
|
||||||
FmtString(name)));
|
FmtString(name)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,8 +111,8 @@ AC_Asset *F_LoadAsset(R_Tag resource, f32 point_size, b32 wait)
|
|||||||
String name = R_NameFromTag(resource);
|
String name = R_NameFromTag(resource);
|
||||||
|
|
||||||
/* Concatenate point_size to name for key */
|
/* Concatenate point_size to name for key */
|
||||||
String key = StringFormat(scratch.arena,
|
String key = StringF(scratch.arena,
|
||||||
Lit("%F%F_font"),
|
"%F%F_font",
|
||||||
FmtString(name),
|
FmtString(name),
|
||||||
FmtFloatP((f64)point_size, 1));
|
FmtFloatP((f64)point_size, 1));
|
||||||
u64 hash = AC_HashFromKey(key);
|
u64 hash = AC_HashFromKey(key);
|
||||||
|
|||||||
@ -293,7 +293,10 @@ Vec2I32 GPU_GetTextureSize(GPU_Resource *resource);
|
|||||||
GPU_CommandList *GPU_BeginCommandList(void);
|
GPU_CommandList *GPU_BeginCommandList(void);
|
||||||
GPU_Fence GPU_EndCommandList(GPU_CommandList *cl);
|
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
|
//~ 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_TransitionToSrv(GPU_CommandList *cl, GPU_Resource *resource);
|
||||||
void GPU_TransitionToUav(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_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
|
//~ Dispatch operations
|
||||||
|
|||||||
@ -70,10 +70,13 @@ GPU_Fence GPU_EndCommandList(GPU_CommandList *cl)
|
|||||||
return (GPU_Fence) ZI;
|
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 cl;
|
||||||
LAX zone_name;
|
LAX name;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
@ -97,7 +100,7 @@ void GPU_TransitionToRtv(GPU_CommandList *cl, GPU_Resource *resource)
|
|||||||
LAX resource;
|
LAX resource;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GPU_Flush(GPU_CommandList *cl, GPU_Resource *resource)
|
void GPU_FlushUav(GPU_CommandList *cl, GPU_Resource *resource)
|
||||||
{
|
{
|
||||||
LAX cl;
|
LAX cl;
|
||||||
LAX resource;
|
LAX resource;
|
||||||
|
|||||||
@ -45,10 +45,6 @@
|
|||||||
# define TestsAreEnabled 0
|
# define TestsAreEnabled 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef IncbinRawDir
|
|
||||||
# define IncbinRawDir
|
|
||||||
#endif
|
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ Includes
|
//~ Includes
|
||||||
|
|
||||||
@ -60,17 +56,14 @@
|
|||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ Util
|
//~ Util
|
||||||
|
|
||||||
/* TODO: Remove printf */
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
void Echo(String msg)
|
void Echo(String msg)
|
||||||
{
|
{
|
||||||
TempArena scratch = BeginScratchNoConflict();
|
HANDLE console_handle = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||||
char *msg_cstr = CstrFromString(scratch.arena, msg);
|
if (console_handle != INVALID_HANDLE_VALUE)
|
||||||
printf(msg_cstr);
|
{
|
||||||
printf("\n");
|
WriteFile(console_handle, msg.text, msg.len, 0, 0);
|
||||||
fflush(stdout);
|
WriteFile(console_handle, "\n", 1, 0, 0);
|
||||||
EndScratch(scratch);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Struct(LineCol)
|
Struct(LineCol)
|
||||||
@ -584,11 +577,16 @@ L_Topo L_TopoFromLayerName(Arena *arena, StringList starting_layer_names, String
|
|||||||
}
|
}
|
||||||
if (cycle_names_list.count > 1)
|
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
|
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
|
else
|
||||||
@ -814,6 +812,7 @@ void StartupMeta(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//- Generate C
|
//- Generate C
|
||||||
|
String c_out_file = F_GetFull(arena, Lit("pp_gen.c"));
|
||||||
if (errors.count <= 0)
|
if (errors.count <= 0)
|
||||||
{
|
{
|
||||||
StringList c_out_lines = ZI;
|
StringList c_out_lines = ZI;
|
||||||
@ -863,7 +862,7 @@ void StartupMeta(void)
|
|||||||
}
|
}
|
||||||
/* Write to file */
|
/* Write to file */
|
||||||
String c_out = StringFromList(arena, c_out_lines, Lit("\n"));
|
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
|
//- Echo meta errors
|
||||||
@ -905,13 +904,12 @@ void StartupMeta(void)
|
|||||||
PushStringToList(arena, &shared_compiler_flags, Lit("-DProfilingIsEnabled=0"));
|
PushStringToList(arena, &shared_compiler_flags, Lit("-DProfilingIsEnabled=0"));
|
||||||
PushStringToList(arena, &shared_compiler_flags, Lit("-DUnoptimizedIsEnabled=1"));
|
PushStringToList(arena, &shared_compiler_flags, Lit("-DUnoptimizedIsEnabled=1"));
|
||||||
PushStringToList(arena, &shared_compiler_flags, Lit("-DTestsAreEnabled=0"));
|
PushStringToList(arena, &shared_compiler_flags, Lit("-DTestsAreEnabled=0"));
|
||||||
PushStringToList(arena, &shared_compiler_flags, Lit("-DIncbinRawDir=\"bla/\""));
|
|
||||||
|
|
||||||
//- Msvc
|
//- Msvc
|
||||||
{
|
{
|
||||||
PushStringToList(arena, &msvc_compiler_flags, Lit("-Z7"));
|
PushStringToList(arena, &msvc_compiler_flags, Lit("-Z7"));
|
||||||
PushStringToList(arena, &msvc_compiler_flags, Lit("-DEBUG:FULL"));
|
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("-Fe:pp.exe"));
|
||||||
PushStringToList(arena, &msvc_compiler_flags, Lit("-nologo"));
|
PushStringToList(arena, &msvc_compiler_flags, Lit("-nologo"));
|
||||||
PushStringToList(arena, &msvc_compiler_flags, Lit("-diagnostics:column"));
|
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("-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("-wd4324")); /* structure was padded due to alignment specifier */
|
||||||
PushStringToList(arena, &msvc_compiler_flags, Lit("-wd4100")); /* unreferenced parameter */
|
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("-wd4189")); /* local variable is initialized but not referenced */
|
||||||
PushStringToList(arena, &msvc_compiler_flags, Lit("-wd4200")); /* nonstandard extension used: zero-sized array in struct/union */
|
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"));
|
PushStringToList(arena, &clang_compiler_flags, Lit("-msse4.2"));
|
||||||
/* Enable warnings */
|
/* Enable warnings */
|
||||||
PushStringToList(arena, &clang_compiler_flags, Lit("-Wall"));
|
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("-Wframe-larger-than=65536"));
|
||||||
PushStringToList(arena, &clang_compiler_flags, Lit("-Wmissing-prototypes"));
|
PushStringToList(arena, &clang_compiler_flags, Lit("-Wmissing-prototypes"));
|
||||||
PushStringToList(arena, &clang_compiler_flags, Lit("-Wunused-variable"));
|
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, shared_compiler_flags, Lit(" "))),
|
||||||
FmtString(StringFromList(arena, msvc_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 */
|
/* Clang */
|
||||||
{
|
{
|
||||||
@ -966,10 +966,11 @@ void StartupMeta(void)
|
|||||||
FmtString(StringFromList(arena, shared_compiler_flags, Lit(" "))),
|
FmtString(StringFromList(arena, shared_compiler_flags, Lit(" "))),
|
||||||
FmtString(StringFromList(arena, clang_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
|
//- Compile C
|
||||||
|
Echo(Lit("Compiling..."));
|
||||||
i32 ret = errors.count > 0;
|
i32 ret = errors.count > 0;
|
||||||
if (ret == 0) {
|
if (ret == 0) {
|
||||||
String cmd_str = msvc_cmd_str;
|
String cmd_str = msvc_cmd_str;
|
||||||
@ -980,9 +981,14 @@ void StartupMeta(void)
|
|||||||
output = Trim(output, Lit("\n"));
|
output = Trim(output, Lit("\n"));
|
||||||
output = Trim(output, Lit("\r"));
|
output = Trim(output, Lit("\r"));
|
||||||
output = Trim(output, Lit("\n"));
|
output = Trim(output, Lit("\n"));
|
||||||
if (result.code != 0)
|
|
||||||
{
|
|
||||||
Echo(output);
|
Echo(output);
|
||||||
|
if (result.code == 0)
|
||||||
|
{
|
||||||
|
Echo(Lit("Compilation succeeded"));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Echo(Lit("Compilation failed"));
|
||||||
}
|
}
|
||||||
ret = result.code;
|
ret = result.code;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -102,9 +102,9 @@ String OS_GetFullPath(Arena *arena, String path)
|
|||||||
{
|
{
|
||||||
TempArena scratch = BeginScratch(arena);
|
TempArena scratch = BeginScratch(arena);
|
||||||
wchar_t *rel_path_wstr = WstrFromString(scratch.arena, path);
|
wchar_t *rel_path_wstr = WstrFromString(scratch.arena, path);
|
||||||
wchar_t buff[4096];
|
wchar_t full_path_wstr_buff[4096];
|
||||||
wchar_t *full_path_wstr = _wfullpath(buff, rel_path_wstr, countof(buff));
|
GetFullPathNameW(rel_path_wstr, countof(full_path_wstr_buff), full_path_wstr_buff, 0);
|
||||||
String res = StringFromWstrNoLimit(arena, full_path_wstr);
|
String res = StringFromWstr(arena, full_path_wstr_buff, countof(full_path_wstr_buff));
|
||||||
EndScratch(scratch);
|
EndScratch(scratch);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
@ -186,8 +186,6 @@ OS_CommandResult OS_RunCommand(Arena *arena, String cmd)
|
|||||||
TempArena scratch = BeginScratch(arena);
|
TempArena scratch = BeginScratch(arena);
|
||||||
OS_CommandResult result = ZI;
|
OS_CommandResult result = ZI;
|
||||||
|
|
||||||
i32 res = -1;
|
|
||||||
|
|
||||||
wchar_t *cmd_wstr = WstrFromString(scratch.arena, cmd);
|
wchar_t *cmd_wstr = WstrFromString(scratch.arena, cmd);
|
||||||
|
|
||||||
SECURITY_ATTRIBUTES sa = ZI;
|
SECURITY_ATTRIBUTES sa = ZI;
|
||||||
@ -195,11 +193,8 @@ OS_CommandResult OS_RunCommand(Arena *arena, String cmd)
|
|||||||
sa.bInheritHandle = 1;
|
sa.bInheritHandle = 1;
|
||||||
|
|
||||||
HANDLE pipe_read, pipe_write;
|
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;
|
STARTUPINFO si = ZI;
|
||||||
@ -214,8 +209,26 @@ OS_CommandResult OS_RunCommand(Arena *arena, String cmd)
|
|||||||
result.output.text = PushDry(arena, u8);
|
result.output.text = PushDry(arena, u8);
|
||||||
if (!CreateProcessW(0, cmd_wstr, 0, 0, 1, 0, 0, 0, &si, &pi))
|
if (!CreateProcessW(0, cmd_wstr, 0, 0, 1, 0, 0, 0, &si, &pi))
|
||||||
{
|
{
|
||||||
/* TODO: error handling */
|
DWORD err = GetLastError();
|
||||||
Assert(0);
|
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)
|
||||||
|
{
|
||||||
|
result.output = PushString(arena, StringFromCstr(msg_cstr, len));
|
||||||
|
LocalFree(msg_cstr);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
result.output = Lit("Failed to create process");
|
||||||
|
}
|
||||||
|
result.code = -1;
|
||||||
} else {
|
} else {
|
||||||
CloseHandle(pipe_write);
|
CloseHandle(pipe_write);
|
||||||
b32 exit_code_valid = 0;
|
b32 exit_code_valid = 0;
|
||||||
@ -251,6 +264,13 @@ OS_CommandResult OS_RunCommand(Arena *arena, String cmd)
|
|||||||
}
|
}
|
||||||
|
|
||||||
CloseHandle(pipe_read);
|
CloseHandle(pipe_read);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
result.output = Lit("Failed to create pipe");
|
||||||
|
result.code = -1;
|
||||||
|
}
|
||||||
|
|
||||||
EndScratch(scratch);
|
EndScratch(scratch);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,3 @@
|
|||||||
#include <stdlib.h> /* _wfullpath */
|
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ Win32 libs
|
//~ Win32 libs
|
||||||
|
|
||||||
|
|||||||
@ -100,7 +100,7 @@ void P_LogFV_(i32 level, String fmt, va_list args)
|
|||||||
P_SharedLogState *ctx = &P_shared_log_state;
|
P_SharedLogState *ctx = &P_shared_log_state;
|
||||||
if (!Atomic32Fetch(&ctx->initialized)) { return; }
|
if (!Atomic32Fetch(&ctx->initialized)) { return; }
|
||||||
TempArena scratch = BeginScratchNoConflict();
|
TempArena scratch = BeginScratchNoConflict();
|
||||||
String msg = StringFormatV(scratch.arena, fmt, args);
|
String msg = FormatStringV(scratch.arena, fmt, args);
|
||||||
#if P_IncludeLogSourceLocation
|
#if P_IncludeLogSourceLocation
|
||||||
P_Log_(level, file, line, msg);
|
P_Log_(level, file, line, msg);
|
||||||
#else
|
#else
|
||||||
@ -150,7 +150,6 @@ void P_Log_(i32 level, String msg)
|
|||||||
Panic(Lit("Invalid log level"));
|
Panic(Lit("Invalid log level"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* FIXME: Log actual thread & fiber id */
|
/* FIXME: Log actual thread & fiber id */
|
||||||
// u32 tid = ThreadId();
|
// u32 tid = ThreadId();
|
||||||
u32 tid = 0;
|
u32 tid = 0;
|
||||||
@ -161,9 +160,9 @@ void P_Log_(i32 level, String msg)
|
|||||||
String shorthand = settings.shorthand;
|
String shorthand = settings.shorthand;
|
||||||
|
|
||||||
#if P_IncludeLogSourceLocation
|
#if P_IncludeLogSourceLocation
|
||||||
String msg_formatted = StringFormat(
|
String msg_formatted = StringF(
|
||||||
scratch.arena,
|
scratch.arena,
|
||||||
Lit("[%F:%F:%F.%F] |%F| [%F] <%F:%F> %F"),
|
"[%F:%F:%F.%F] |%F| [%F] <%F:%F> %F",
|
||||||
|
|
||||||
/* Time */
|
/* Time */
|
||||||
FmtUintZ(datetime.hour, 2),
|
FmtUintZ(datetime.hour, 2),
|
||||||
@ -185,7 +184,7 @@ void P_Log_(i32 level, String msg)
|
|||||||
FmtString(msg)
|
FmtString(msg)
|
||||||
);
|
);
|
||||||
#else
|
#else
|
||||||
String msg_formatted = StringFormat(
|
String msg_formatted = FormatString(
|
||||||
scratch.arena,
|
scratch.arena,
|
||||||
Lit("[%F:%F:%F.%F] |%F| [%F] %F"),
|
Lit("[%F:%F:%F.%F] |%F| [%F] %F"),
|
||||||
|
|
||||||
|
|||||||
@ -1,11 +1,11 @@
|
|||||||
P_W32_SharedCtx P_W32_shared_ctx = ZI;
|
P_W32_SharedState P_W32_shared_state = ZI;
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ @hookdef Startup
|
//~ @hookdef Startup
|
||||||
|
|
||||||
void P_Startup(void)
|
void P_Startup(void)
|
||||||
{
|
{
|
||||||
P_W32_SharedCtx *g = &P_W32_shared_ctx;
|
P_W32_SharedState *g = &P_W32_shared_state;
|
||||||
|
|
||||||
//- Initialize btn table
|
//- 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_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;
|
P_W32_Window *window = 0;
|
||||||
{
|
{
|
||||||
Lock lock = LockE(&g->windows_mutex);
|
Lock lock = LockE(&g->windows_mutex);
|
||||||
@ -191,7 +191,7 @@ void P_W32_ReleaseWindow(P_W32_Window *window)
|
|||||||
{
|
{
|
||||||
/* Stop window threads */
|
/* Stop window threads */
|
||||||
Atomic32FetchSet(&window->shutdown, 1);
|
Atomic32FetchSet(&window->shutdown, 1);
|
||||||
P_W32_SharedCtx *g = &P_W32_shared_ctx;
|
P_W32_SharedState *g = &P_W32_shared_state;
|
||||||
P_W32_WakeWindow(window);
|
P_W32_WakeWindow(window);
|
||||||
W32_WaitReleaseThread(window->window_thread);
|
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)
|
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):
|
* 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)
|
LRESULT CALLBACK P_W32_Win32WindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
|
||||||
{
|
{
|
||||||
__prof;
|
__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);
|
P_W32_Window *window = (P_W32_Window *)GetWindowLongPtrW(hwnd, GWLP_USERDATA);
|
||||||
|
|
||||||
if (!window)
|
if (!window)
|
||||||
@ -947,8 +947,8 @@ void P_MkDir(String path)
|
|||||||
}
|
}
|
||||||
if (err.len > 0)
|
if (err.len > 0)
|
||||||
{
|
{
|
||||||
String msg = StringFormat(scratch.arena,
|
String msg = StringF(scratch.arena,
|
||||||
Lit("Failed to create directory \"%F\": %F"),
|
"Failed to create directory \"%F\": %F",
|
||||||
FmtString(path),
|
FmtString(path),
|
||||||
FmtString(err));
|
FmtString(err));
|
||||||
Panic(msg);
|
Panic(msg);
|
||||||
@ -1105,8 +1105,8 @@ void P_WriteFile(P_File file, String data)
|
|||||||
if (data.len >= 0x7FFF)
|
if (data.len >= 0x7FFF)
|
||||||
{
|
{
|
||||||
TempArena scratch = BeginScratchNoConflict();
|
TempArena scratch = BeginScratchNoConflict();
|
||||||
Panic(StringFormat(scratch.arena,
|
Panic(StringF(scratch.arena,
|
||||||
Lit("Tried to write too many bytes to disk (%F)"),
|
"Tried to write too many bytes to disk (%F)",
|
||||||
FmtUint(data.len)));
|
FmtUint(data.len)));
|
||||||
EndScratch(scratch);
|
EndScratch(scratch);
|
||||||
}
|
}
|
||||||
@ -1569,7 +1569,7 @@ String P_StringFromAddress(Arena *arena, P_Address address)
|
|||||||
ip[i] = ntohs(address.ipnb[i]);
|
ip[i] = ntohs(address.ipnb[i]);
|
||||||
}
|
}
|
||||||
u16 port = ntohs(address.portnb);
|
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;
|
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_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;
|
P_W32_Sock *ws = 0;
|
||||||
{
|
{
|
||||||
Lock lock = LockE(&g->socks_mutex);
|
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)
|
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;
|
P_W32_Sock *ws = (P_W32_Sock *)sock;
|
||||||
closesocket(ws->sock);
|
closesocket(ws->sock);
|
||||||
Lock lock = LockE(&g->socks_mutex);
|
Lock lock = LockE(&g->socks_mutex);
|
||||||
|
|||||||
@ -114,7 +114,7 @@ Struct(P_W32_Sock)
|
|||||||
|
|
||||||
#define P_W32_WindowClassName L"power_play_window_class"
|
#define P_W32_WindowClassName L"power_play_window_class"
|
||||||
|
|
||||||
Struct(P_W32_SharedCtx)
|
Struct(P_W32_SharedState)
|
||||||
{
|
{
|
||||||
//- Key lookup table
|
//- Key lookup table
|
||||||
P_Btn vk_btn_table[256];
|
P_Btn vk_btn_table[256];
|
||||||
@ -137,7 +137,7 @@ Struct(P_W32_SharedCtx)
|
|||||||
P_W32_Sock *first_free_sock;
|
P_W32_Sock *first_free_sock;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern P_W32_SharedCtx P_W32_shared_ctx;
|
extern P_W32_SharedState P_W32_shared_state;
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ Time operations
|
//~ Time operations
|
||||||
|
|||||||
229
src/pp/pp.c
229
src/pp/pp.c
@ -146,35 +146,35 @@ String DebugStringFromEntity(Arena *arena, Entity *ent)
|
|||||||
String result = ZI;
|
String result = ZI;
|
||||||
result.text = PushDry(arena, u8);
|
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 transmitting = HasProp(ent, Prop_SyncSrc);
|
||||||
b32 receiving = HasProp(ent, Prop_SyncDst);
|
b32 receiving = HasProp(ent, Prop_SyncDst);
|
||||||
if (transmitting & receiving)
|
if (transmitting & receiving)
|
||||||
{
|
{
|
||||||
result.len += PushString(arena, Lit(" networked (sending & receiving)")).len;
|
result.len += StringF(arena, " networked (sending & receiving)").len;
|
||||||
}
|
}
|
||||||
else if (transmitting)
|
else if (transmitting)
|
||||||
{
|
{
|
||||||
result.len += PushString(arena, Lit(" networked (sending)")).len;
|
result.len += StringF(arena, " networked (sending)").len;
|
||||||
}
|
}
|
||||||
else if (receiving)
|
else if (receiving)
|
||||||
{
|
{
|
||||||
result.len += PushString(arena, Lit(" networked (receiving)")).len;
|
result.len += StringF(arena, " networked (receiving)").len;
|
||||||
}
|
}
|
||||||
else
|
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;)
|
for (u64 chunk_index = countof(ent->props); chunk_index-- > 0;)
|
||||||
{
|
{
|
||||||
u64 chunk = ent->props[chunk_index];
|
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))
|
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))
|
if (!IsNilId(ent->next) || !IsNilId(ent->prev))
|
||||||
{
|
{
|
||||||
result.len += StringFormat(arena, Lit("prev: [%F]\n"), FmtUid(ent->prev.uid)).len;
|
result.len += StringF(arena, "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, "next: [%F]\n", FmtUid(ent->next.uid)).len;
|
||||||
}
|
}
|
||||||
|
|
||||||
result.len += PushString(arena, Lit("\n")).len;
|
result.len += StringF(arena, "\n").len;
|
||||||
|
|
||||||
/* Pos */
|
/* Pos */
|
||||||
Xform xf = XformFromEntity(ent);
|
Xform xf = XformFromEntity(ent);
|
||||||
Vec2 linear_velocity = ent->linear_velocity;
|
Vec2 linear_velocity = ent->linear_velocity;
|
||||||
f32 angular_velocity = ent->angular_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 += StringF(arena, "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 += StringF(arena, "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, "angular velocity: %F\n", FmtFloat(angular_velocity)).len;
|
||||||
|
|
||||||
/* Test */
|
/* 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 */
|
/* Children */
|
||||||
if (!IsNilId(ent->first) || !IsNilId(ent->last))
|
if (!IsNilId(ent->first) || !IsNilId(ent->last))
|
||||||
@ -222,13 +222,13 @@ String DebugStringFromEntity(Arena *arena, Entity *ent)
|
|||||||
Entity *child = EntityFromId(ss, ent->first);
|
Entity *child = EntityFromId(ss, ent->first);
|
||||||
if (!EqId(ent->first, ent->last) || !child->valid)
|
if (!EqId(ent->first, ent->last) || !child->valid)
|
||||||
{
|
{
|
||||||
result.len += StringFormat(arena, Lit("first child: [%F]\n"), FmtUid(ent->first.uid)).len;
|
result.len += StringF(arena, "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, "last child: [%F]\n", FmtUid(ent->last.uid)).len;
|
||||||
}
|
}
|
||||||
while (child->valid)
|
while (child->valid)
|
||||||
{
|
{
|
||||||
result.len += PushString(arena, Lit("\n---------------------------------\n")).len;
|
result.len += StringF(arena, "\n---------------------------------\n").len;
|
||||||
result.len += PushString(arena, Lit("CHILD\n")).len;
|
result.len += StringF(arena, "CHILD\n").len;
|
||||||
String child_text = DebugStringFromEntity(scratch.arena, child);
|
String child_text = DebugStringFromEntity(scratch.arena, child);
|
||||||
result.len += IndentString(arena, child_text, 4).len;
|
result.len += IndentString(arena, child_text, 4).len;
|
||||||
child = EntityFromId(ss, child->next);
|
child = EntityFromId(ss, child->next);
|
||||||
@ -340,9 +340,9 @@ void DrawDebugConsole(i32 level, b32 minimized)
|
|||||||
if (!minimized)
|
if (!minimized)
|
||||||
{
|
{
|
||||||
P_DateTime datetime = log->datetime;
|
P_DateTime datetime = log->datetime;
|
||||||
text = StringFormat(
|
text = StringF(
|
||||||
scratch.arena,
|
scratch.arena,
|
||||||
Lit("[%F:%F:%F.%F] %F"),
|
"[%F:%F:%F.%F] %F",
|
||||||
FmtUintZ(datetime.hour, 2),
|
FmtUintZ(datetime.hour, 2),
|
||||||
FmtUintZ(datetime.minute, 2),
|
FmtUintZ(datetime.minute, 2),
|
||||||
FmtUintZ(datetime.second, 2),
|
FmtUintZ(datetime.second, 2),
|
||||||
@ -457,8 +457,8 @@ MergesortCompareFuncDef(EntitySortCmp, arg_a, arg_b, _)
|
|||||||
if (result == 0)
|
if (result == 0)
|
||||||
{
|
{
|
||||||
/* Sort by sprite */
|
/* Sort by sprite */
|
||||||
u64 a_cmp = a->sprite.hash;
|
u64 a_cmp = a->sprite.r.hash;
|
||||||
u64 b_cmp = b->sprite.hash;
|
u64 b_cmp = b->sprite.r.hash;
|
||||||
result = (a_cmp < b_cmp) - (a_cmp > b_cmp);
|
result = (a_cmp < b_cmp) - (a_cmp > b_cmp);
|
||||||
}
|
}
|
||||||
if (result == 0)
|
if (result == 0)
|
||||||
@ -485,7 +485,6 @@ void UpdateUser(P_Window *window)
|
|||||||
g->real_dt_ns = TimeNs() - g->real_time_ns;
|
g->real_dt_ns = TimeNs() - g->real_time_ns;
|
||||||
g->real_time_ns += g->real_dt_ns;
|
g->real_time_ns += g->real_dt_ns;
|
||||||
g->screen_size = P_GetWindowSize(window);
|
g->screen_size = P_GetWindowSize(window);
|
||||||
S_Scope *sprite_frame_scope = S_BeginScope();
|
|
||||||
|
|
||||||
//- Pull latest local sim snapshot
|
//- Pull latest local sim snapshot
|
||||||
|
|
||||||
@ -1217,8 +1216,8 @@ void UpdateUser(P_Window *window)
|
|||||||
/* Draw sprite */
|
/* Draw sprite */
|
||||||
if (!S_IsTagNil(sprite))
|
if (!S_IsTagNil(sprite))
|
||||||
{
|
{
|
||||||
S_Sheet *sheet = S_SheetFromTagAsync(sprite_frame_scope, sprite);
|
S_Sheet *sheet = S_SheetFromTagAsync(sprite);
|
||||||
S_Texture *texture = S_TextureFromTagAsync(sprite_frame_scope, sprite);
|
S_Texture *texture = S_TextureFromTagAsync(sprite);
|
||||||
|
|
||||||
/* TODO: Fade in placeholder if texture isn't loaded */
|
/* TODO: Fade in placeholder if texture isn't loaded */
|
||||||
if (sheet->loaded && texture->loaded)
|
if (sheet->loaded && texture->loaded)
|
||||||
@ -1245,8 +1244,8 @@ void UpdateUser(P_Window *window)
|
|||||||
if (HasProp(ent, Prop_TileChunk))
|
if (HasProp(ent, Prop_TileChunk))
|
||||||
{
|
{
|
||||||
Vec2I32 chunk_index = ent->tile_chunk_index;
|
Vec2I32 chunk_index = ent->tile_chunk_index;
|
||||||
S_Tag tile_sprite = S_TagFromPath(Lit("sprite/tile.ase"));
|
S_Tag tile_sprite = S_TagFromName(Lit("sprite/tile.ase"));
|
||||||
S_Texture *tile_texture = S_TextureFromTagAsync(sprite_frame_scope, tile_sprite);
|
S_Texture *tile_texture = S_TextureFromTagAsync(tile_sprite);
|
||||||
if (tile_texture->loaded)
|
if (tile_texture->loaded)
|
||||||
{
|
{
|
||||||
f32 tile_size = 1.f / SIM_TILES_PER_UNIT_SQRT;
|
f32 tile_size = 1.f / SIM_TILES_PER_UNIT_SQRT;
|
||||||
@ -1312,7 +1311,7 @@ void UpdateUser(P_Window *window)
|
|||||||
/* Draw focus arrow */
|
/* Draw focus arrow */
|
||||||
if (ent == local_control || EqId(ent->id, g->debug_following))
|
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);
|
S_Slice slice = S_SliceFromNameIndex(sheet, Lit("attach.wep"), ent->animation_frame);
|
||||||
Vec2 start = MulXformV2(sprite_xform, slice.center);
|
Vec2 start = MulXformV2(sprite_xform, slice.center);
|
||||||
start = MulXformV2(g->world_to_ui_xf, start);
|
start = MulXformV2(g->world_to_ui_xf, start);
|
||||||
@ -1326,7 +1325,7 @@ void UpdateUser(P_Window *window)
|
|||||||
/* Draw slices */
|
/* Draw slices */
|
||||||
if (!S_IsTagNil(ent->sprite))
|
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 quad_color = Rgba32F(1, 0, 0.5, 1);
|
||||||
u32 point_color = Rgba32F(1, 0, 0, 1);
|
u32 point_color = Rgba32F(1, 0, 0, 1);
|
||||||
@ -1495,7 +1494,7 @@ void UpdateUser(P_Window *window)
|
|||||||
"normal: (%F, %F)\n"
|
"normal: (%F, %F)\n"
|
||||||
"num contacts: %F"
|
"num contacts: %F"
|
||||||
);
|
);
|
||||||
String text = StringFormat(temp.arena, fmt,
|
String text = StringF(temp.arena, fmt,
|
||||||
FmtUint(e0->handle.idx),
|
FmtUint(e0->handle.idx),
|
||||||
FmtUint(e1->handle.idx),
|
FmtUint(e1->handle.idx),
|
||||||
FmtHex(point.id),
|
FmtHex(point.id),
|
||||||
@ -1505,7 +1504,6 @@ void UpdateUser(P_Window *window)
|
|||||||
FmtFloatP(data->normal.x, 6), FmtFloatP(data->normal.y, 6),
|
FmtFloatP(data->normal.x, 6), FmtFloatP(data->normal.y, 6),
|
||||||
FmtUint(data->num_points));
|
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);
|
draw_text(g->render_sig, disp_font, AddVec2(RoundVec2(MulXformV2(g->world_to_ui_xf, dbg_pt)), VEC2(0, offset_px)), text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1613,13 +1611,12 @@ void UpdateUser(P_Window *window)
|
|||||||
"e1 pos: (%F, %F)\n"
|
"e1 pos: (%F, %F)\n"
|
||||||
"e1 rot: %F\n"
|
"e1 rot: %F\n"
|
||||||
);
|
);
|
||||||
String text = StringFormat(temp.arena, fmt,
|
String text = StringF(temp.arena, fmt,
|
||||||
FmtFloatP(e0_xf.og.x, 24), FmtFloatP(e0_xf.og.y, 24),
|
FmtFloatP(e0_xf.og.x, 24), FmtFloatP(e0_xf.og.y, 24),
|
||||||
FmtFloatP(RotationFromXform(e0_xf), 24),
|
FmtFloatP(RotationFromXform(e0_xf), 24),
|
||||||
FmtFloatP(e1_xf.og.x, 24), FmtFloatP(e1_xf.og.y, 24),
|
FmtFloatP(e1_xf.og.x, 24), FmtFloatP(e1_xf.og.y, 24),
|
||||||
FmtFloatP(RotationFromXform(e1_xf), 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);
|
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");
|
__profn("Draw crosshair");
|
||||||
Vec2 crosshair_pos = g->ui_cursor;
|
Vec2 crosshair_pos = g->ui_cursor;
|
||||||
S_Tag crosshair = S_TagFromPath(Lit("sprite/crosshair.ase"));
|
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);
|
Vec2 size = VEC2(t->width, t->height);
|
||||||
Xform xf = XformFromTrs(TRS(.t = crosshair_pos, .s = size));
|
Xform xf = XformFromTrs(TRS(.t = crosshair_pos, .s = size));
|
||||||
D_DrawUiRect(g->render_sig, D_UIRECTPARAMS(.xf = xf, .texture = t->gpu_resource));
|
D_DrawUiRect(g->render_sig, D_UIRECTPARAMS(.xf = xf, .texture = t->gpu_resource));
|
||||||
@ -1776,7 +1773,7 @@ void UpdateUser(P_Window *window)
|
|||||||
}
|
}
|
||||||
else
|
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);
|
Vec2 size = VEC2(t->width, t->height);
|
||||||
Rect cursor_clip = RectFromVec2(g->ui_screen_offset, g->ui_size);
|
Rect cursor_clip = RectFromVec2(g->ui_screen_offset, g->ui_size);
|
||||||
cursor_clip.pos = AddVec2(cursor_clip.pos, MulVec2(size, 0.5f));
|
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);
|
text.text = PushDry(temp.arena, u8);
|
||||||
|
|
||||||
#if BITBUFF_DEBUG
|
#if BITBUFF_DEBUG
|
||||||
text.len += PushString(temp.arena, Lit("(bitbuff debug enabled)")).len;
|
text.len += StringF(temp.arena, "(bitbuff debug enabled)").len;
|
||||||
text.len += PushString(temp.arena, Lit("\n")).len;
|
text.len += StringF(temp.arena, "\n").len;
|
||||||
#endif
|
#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 += 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 += PushString(temp.arena, Lit("\n")).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 += StringF(temp.arena, "blended world tick: %F", FmtUint(g->ss_blended->tick)).len;
|
||||||
text.len += PushString(temp.arena, Lit("\n")).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 += StringF(temp.arena, "blended world time: %F", FmtFloat(SecondsFromNs(g->ss_blended->sim_time_ns))).len;
|
||||||
text.len += PushString(temp.arena, Lit("\n")).len;
|
text.len += StringF(temp.arena, "\n").len;
|
||||||
text.len += PushString(temp.arena, Lit("\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 += StringF(temp.arena, "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, "\n").len;
|
||||||
|
|
||||||
text.len += StringFormat(temp.arena, Lit("local sim last known tick: %F"), FmtUint(g->local_sim_last_known_tick)).len;
|
text.len += StringF(temp.arena, "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, "\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 += StringF(temp.arena, "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, "\n").len;
|
||||||
|
|
||||||
text.len += StringFormat(temp.arena, Lit("local sim predicted time: %F"), FmtFloat(SecondsFromNs(g->local_sim_predicted_time_ns))).len;
|
text.len += StringF(temp.arena, "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, "\n").len;
|
||||||
|
|
||||||
text.len += StringFormat(temp.arena, Lit("render time target: %F"), FmtFloat(SecondsFromNs(g->render_time_target_ns))).len;
|
text.len += StringF(temp.arena, "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, "\n").len;
|
||||||
|
|
||||||
text.len += StringFormat(temp.arena, Lit("render time: %F"), FmtFloat(SecondsFromNs(g->render_time_ns))).len;
|
text.len += StringF(temp.arena, "render time: %F", FmtFloat(SecondsFromNs(g->render_time_ns))).len;
|
||||||
text.len += PushString(temp.arena, Lit("\n")).len;
|
text.len += StringF(temp.arena, "\n").len;
|
||||||
text.len += PushString(temp.arena, Lit("\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 += StringF(temp.arena, "local player: [%F]", FmtUid(local_player->id.uid)).len;
|
||||||
text.len += PushString(temp.arena, Lit("\n")).len;
|
text.len += StringF(temp.arena, "\n").len;
|
||||||
text.len += PushString(temp.arena, Lit("\n")).len;
|
text.len += StringF(temp.arena, "\n").len;
|
||||||
|
|
||||||
Vec2 world_cursor = g->world_cursor;
|
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 += StringF(temp.arena, "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, "\n").len;
|
||||||
|
|
||||||
Vec2I32 world_tile_cursor = WorldTileIndexFromPos(world_cursor);
|
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 += StringF(temp.arena, "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, "\n").len;
|
||||||
|
|
||||||
Vec2I32 local_tile_cursor = LocalTileIndexFromWorldTileIndex(world_tile_cursor);
|
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 += StringF(temp.arena, "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, "\n").len;
|
||||||
|
|
||||||
Vec2I32 tile_chunk_cursor = TileChunkIndexFromWorldTileIndex(world_tile_cursor);
|
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 += StringF(temp.arena, "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 += StringF(temp.arena, "\n").len;
|
||||||
text.len += PushString(temp.arena, Lit("\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 += StringF(temp.arena, "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, "\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 += StringF(temp.arena, "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, "\n").len;
|
||||||
|
|
||||||
text.len += StringFormat(temp.arena, Lit("Ping (real): %F ms"), FmtFloat(SecondsFromNs(local_player->player_last_rtt_ns) * 1000)).len;
|
text.len += StringF(temp.arena, "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, "\n").len;
|
||||||
|
|
||||||
text.len += StringFormat(temp.arena, Lit("Ping (average): %F ms"), FmtFloat(local_player->player_average_rtt_seconds * 1000)).len;
|
text.len += StringF(temp.arena, "Ping (average): %F ms", FmtFloat(local_player->player_average_rtt_seconds * 1000)).len;
|
||||||
text.len += PushString(temp.arena, Lit("\n")).len;
|
text.len += StringF(temp.arena, "\n").len;
|
||||||
text.len += PushString(temp.arena, Lit("\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 += StringF(temp.arena, "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, "\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 += StringF(temp.arena, "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, "\n").len;
|
||||||
|
|
||||||
text.len += StringFormat(temp.arena, Lit("Arenas allocated: %F"), FmtUint(GetGstat(GSTAT_NUM_ARENAS))).len;
|
text.len += StringF(temp.arena, "Arenas allocated: %F", FmtUint(GetGstat(GSTAT_NUM_ARENAS))).len;
|
||||||
text.len += PushString(temp.arena, Lit("\n")).len;
|
text.len += StringF(temp.arena, "\n").len;
|
||||||
text.len += PushString(temp.arena, Lit("\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 += StringF(temp.arena, "Video memory (GPU): %F MiB", FmtFloat((f64)vram.local_used / 1024 / 1024)).len;
|
||||||
text.len += PushString(temp.arena, Lit("\n")).len;
|
text.len += StringF(temp.arena, "\n").len;
|
||||||
text.len += StringFormat(temp.arena, Lit("Video memory (shared): %F MiB"), FmtFloat((f64)vram.non_local_used / 1024 / 1024)).len;
|
text.len += StringF(temp.arena, "Video memory (shared): %F MiB", FmtFloat((f64)vram.non_local_used / 1024 / 1024)).len;
|
||||||
//text.len += PushString(temp.arena, Lit("\n")).len;
|
//text.len += StringF(temp.arena, \n")).len;
|
||||||
//text.len += PushString(temp.arena, Lit("\n")).len;
|
//text.len += StringF(temp.arena, \n")).len;
|
||||||
|
|
||||||
#if RtcIsEnabled
|
#if RtcIsEnabled
|
||||||
text.len += PushString(temp.arena, Lit("\n")).len;
|
text.len += StringF(temp.arena, "\n").len;
|
||||||
text.len += PushString(temp.arena, Lit("\n")).len;
|
text.len += StringF(temp.arena, "\n").len;
|
||||||
text.len += StringFormat(temp.arena, Lit("Debug steps: %F"), FmtUint(GetGstat(GSTAT_DEBUG_STEPS))).len;
|
text.len += StringF(temp.arena, "Debug steps: %F", FmtUint(GetGstat(GSTAT_DEBUG_STEPS))).len;
|
||||||
//text.len += PushString(temp.arena, Lit("\n")).len;
|
//text.len += StringF(temp.arena, \n")).len;
|
||||||
|
|
||||||
#endif
|
#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);
|
//draw_text(g->render_sig, font, pos, text);
|
||||||
|
|
||||||
Vec2 pos = VEC2(10, g->ui_size.y);
|
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_Resource *grids_buffer = AcquireTransferBufferFromArena(g->grids_count, g->grids_arena);
|
||||||
|
|
||||||
GPU_CommandList *cl = GPU_BeginCommandList();
|
GPU_CommandList *cl = GPU_BeginCommandList();
|
||||||
GPU_ProfileDF(cl, Lit("Run render"));
|
|
||||||
{
|
{
|
||||||
__profn("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 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 ui_vp_matrix = ProjectMat4x4View(XformIdentity, ui_viewport.width, ui_viewport.height);
|
||||||
Mat4x4 blit_vp_matrix = ZI;
|
Mat4x4 blit_vp_matrix = ZI;
|
||||||
@ -2207,9 +2204,9 @@ void UpdateUser(P_Window *window)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//- Prep material pass
|
//- Prep material pass
|
||||||
GPU_ProfileDF(cl, Lit("Clear gbuffers"));
|
|
||||||
{
|
{
|
||||||
__profn("Clear gbuffers");
|
__profn("Clear gbuffers");
|
||||||
|
GPU_ProfN(cl, Lit("Clear gbuffers"));
|
||||||
GPU_TransitionToRtv(cl, g->albedo);
|
GPU_TransitionToRtv(cl, g->albedo);
|
||||||
GPU_TransitionToRtv(cl, g->emittance);
|
GPU_TransitionToRtv(cl, g->emittance);
|
||||||
GPU_DispatchClear(cl, g->albedo);
|
GPU_DispatchClear(cl, g->albedo);
|
||||||
@ -2217,9 +2214,9 @@ void UpdateUser(P_Window *window)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//- Material pass
|
//- Material pass
|
||||||
GPU_ProfileDF(cl, Lit("Material pass"));
|
|
||||||
{
|
{
|
||||||
__profn("Material pass");
|
__profn("Material pass");
|
||||||
|
GPU_ProfN(cl, Lit("Material pass"));
|
||||||
|
|
||||||
GPU_Resource *rts[] = {
|
GPU_Resource *rts[] = {
|
||||||
g->albedo,
|
g->albedo,
|
||||||
@ -2252,9 +2249,9 @@ void UpdateUser(P_Window *window)
|
|||||||
|
|
||||||
//- Flood pass
|
//- Flood pass
|
||||||
if (!effects_disabled)
|
if (!effects_disabled)
|
||||||
GPU_ProfileDF(cl, Lit("Flood pass"));
|
|
||||||
{
|
{
|
||||||
__profn("Flood pass");
|
__profn("Flood pass");
|
||||||
|
GPU_ProfN(cl, Lit("Flood pass"));
|
||||||
|
|
||||||
i32 step_length = -1;
|
i32 step_length = -1;
|
||||||
|
|
||||||
@ -2262,11 +2259,11 @@ void UpdateUser(P_Window *window)
|
|||||||
u64 max_steps = GetGstat(GSTAT_DEBUG_STEPS);
|
u64 max_steps = GetGstat(GSTAT_DEBUG_STEPS);
|
||||||
u64 step = 0;
|
u64 step = 0;
|
||||||
while (step_length != 0 && step < max_steps)
|
while (step_length != 0 && step < max_steps)
|
||||||
GPU_ProfileDF(cl, Lit("Flood step"));
|
|
||||||
{
|
{
|
||||||
__profn("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;
|
FloodSig sig = ZI;
|
||||||
sig.step_len = step_length;
|
sig.step_len = step_length;
|
||||||
@ -2296,21 +2293,21 @@ void UpdateUser(P_Window *window)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//- Prep shade pass
|
//- Prep shade pass
|
||||||
GPU_ProfileDF(cl, Lit("Clear shade target"));
|
|
||||||
{
|
{
|
||||||
__profn("Clear shade target");
|
__profn("Clear shade target");
|
||||||
|
GPU_ProfN(cl, Lit("Clear shade target"));
|
||||||
GPU_TransitionToSrv(cl, g->albedo);
|
GPU_TransitionToSrv(cl, g->albedo);
|
||||||
GPU_TransitionToSrv(cl, g->emittance);
|
GPU_TransitionToSrv(cl, g->emittance);
|
||||||
GPU_TransitionToUav(cl, g->shade_target);
|
GPU_TransitionToUav(cl, g->shade_target);
|
||||||
GPU_Flush(cl, g->emittance_flood_read);
|
GPU_FlushUav(cl, g->emittance_flood_read);
|
||||||
GPU_Flush(cl, g->shade_read);
|
GPU_FlushUav(cl, g->shade_read);
|
||||||
GPU_DispatchClear(cl, g->shade_target);
|
GPU_DispatchClear(cl, g->shade_target);
|
||||||
}
|
}
|
||||||
|
|
||||||
//- Shade pass
|
//- Shade pass
|
||||||
GPU_ProfileDF(cl, Lit("Shade pass"));
|
|
||||||
{
|
{
|
||||||
__profn("Shade pass");
|
__profn("Shade pass");
|
||||||
|
GPU_ProfN(cl, Lit("Shade pass"));
|
||||||
|
|
||||||
u32 shade_flags = K_SHADE_FLAG_NONE;
|
u32 shade_flags = K_SHADE_FLAG_NONE;
|
||||||
if (effects_disabled)
|
if (effects_disabled)
|
||||||
@ -2341,18 +2338,18 @@ void UpdateUser(P_Window *window)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//- Prep ui pass
|
//- Prep ui pass
|
||||||
GPU_ProfileDF(cl, Lit("Clear ui target"));
|
|
||||||
{
|
{
|
||||||
__profn("Clear ui target");
|
__profn("Clear ui target");
|
||||||
|
GPU_ProfN(cl, Lit("Clear ui target"));
|
||||||
GPU_TransitionToRtv(cl, g->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);
|
GPU_DispatchClear(cl, g->ui_target);
|
||||||
}
|
}
|
||||||
|
|
||||||
//- Ui blit pass
|
//- Ui blit pass
|
||||||
GPU_ProfileDF(cl, Lit("UI blit pass"));
|
|
||||||
{
|
{
|
||||||
__profn("UI blit pass");
|
__profn("UI blit pass");
|
||||||
|
GPU_ProfN(cl, Lit("UI blit pass"));
|
||||||
|
|
||||||
GPU_Viewport viewport = GPU_ViewportFromRect(ui_viewport);
|
GPU_Viewport viewport = GPU_ViewportFromRect(ui_viewport);
|
||||||
GPU_Scissor scissor = GPU_ScissorFromRect(ui_viewport);
|
GPU_Scissor scissor = GPU_ScissorFromRect(ui_viewport);
|
||||||
@ -2375,9 +2372,9 @@ void UpdateUser(P_Window *window)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//- Ui rect pass
|
//- Ui rect pass
|
||||||
GPU_ProfileDF(cl, Lit("UI rect pass"));
|
|
||||||
{
|
{
|
||||||
__profn("UI rect pass");
|
__profn("UI rect pass");
|
||||||
|
GPU_ProfN(cl, Lit("UI rect pass"));
|
||||||
|
|
||||||
GPU_Viewport viewport = GPU_ViewportFromRect(ui_viewport);
|
GPU_Viewport viewport = GPU_ViewportFromRect(ui_viewport);
|
||||||
GPU_Scissor scissor = GPU_ScissorFromRect(ui_viewport);
|
GPU_Scissor scissor = GPU_ScissorFromRect(ui_viewport);
|
||||||
@ -2397,9 +2394,9 @@ void UpdateUser(P_Window *window)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//- Ui shape pass
|
//- Ui shape pass
|
||||||
GPU_ProfileDF(cl, Lit("UI shape pass"));
|
|
||||||
{
|
{
|
||||||
__profn("UI shape pass");
|
__profn("UI shape pass");
|
||||||
|
GPU_ProfN(cl, Lit("UI shape pass"));
|
||||||
|
|
||||||
GPU_Viewport viewport = GPU_ViewportFromRect(ui_viewport);
|
GPU_Viewport viewport = GPU_ViewportFromRect(ui_viewport);
|
||||||
GPU_Scissor scissor = GPU_ScissorFromRect(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);
|
EndScratch(scratch);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -36,7 +36,7 @@ void ResetSimAccel(Snapshot *ss, SimAccel *accel)
|
|||||||
Entity *SpawnTestSmg(Entity *parent)
|
Entity *SpawnTestSmg(Entity *parent)
|
||||||
{
|
{
|
||||||
Entity *e = AcquireSyncSrc(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);
|
EnableProp(e, Prop_Attached);
|
||||||
e->attach_slice = Lit("attach.wep");
|
e->attach_slice = Lit("attach.wep");
|
||||||
@ -52,7 +52,7 @@ Entity *SpawnTestSmg(Entity *parent)
|
|||||||
Entity *SpawnTestLauncher(Entity *parent)
|
Entity *SpawnTestLauncher(Entity *parent)
|
||||||
{
|
{
|
||||||
Entity *e = AcquireSyncSrc(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);
|
EnableProp(e, Prop_Attached);
|
||||||
e->attach_slice = Lit("attach.wep");
|
e->attach_slice = Lit("attach.wep");
|
||||||
@ -68,7 +68,7 @@ Entity *SpawnTestLauncher(Entity *parent)
|
|||||||
Entity *SpawnTestChucker(Entity *parent)
|
Entity *SpawnTestChucker(Entity *parent)
|
||||||
{
|
{
|
||||||
Entity *chucker = AcquireSyncSrc(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);
|
EnableProp(chucker, Prop_Attached);
|
||||||
chucker->attach_slice = Lit("attach.wep");
|
chucker->attach_slice = Lit("attach.wep");
|
||||||
@ -119,12 +119,12 @@ Entity *SpawnTestEmployee(Entity *parent)
|
|||||||
|
|
||||||
{
|
{
|
||||||
EnableProp(e, Prop_Test);
|
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->mass_unscaled = 10;
|
||||||
e->inertia_unscaled = 5;
|
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.unarmed");
|
||||||
//e->sprite_span_name = Lit("idle.one_handed");
|
//e->sprite_span_name = Lit("idle.one_handed");
|
||||||
e->sprite_span_name = Lit("idle.two_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));
|
Xform xf = XformFromTrs(TRS(.t = pos, .r = rot, .s = size));
|
||||||
SetXform(e, xf);
|
SetXform(e, xf);
|
||||||
|
|
||||||
e->sprite = S_TagFromPath(Lit("sprite/tile.ase"));
|
e->sprite = S_TagFromName(Lit("sprite/tile.ase"));
|
||||||
e->layer = Layer_Shoulders;
|
e->layer = Layer_Shoulders;
|
||||||
|
|
||||||
//e->sprite_tint = Alpha32F(ColorBlue, 0.75);
|
//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);
|
Xform xf = XformFromTrs(.t = pos, .r = r, .s = size);
|
||||||
SetXform(e, xf);
|
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->sprite_collider_slice = Lit("shape");
|
||||||
e->layer = Layer_Shoulders;
|
e->layer = Layer_Shoulders;
|
||||||
|
|
||||||
@ -327,7 +327,7 @@ void SpawnTestEntities3(Entity *parent, Vec2 pos)
|
|||||||
Xform xf = XformFromTrs(TRS(.t = pos, .r = r, .s = size));
|
Xform xf = XformFromTrs(TRS(.t = pos, .r = r, .s = size));
|
||||||
SetXform(e, xf);
|
SetXform(e, xf);
|
||||||
|
|
||||||
e->sprite = S_TagFromPath(Lit("sprite/box.ase"));
|
e->sprite = S_TagFromName(Lit("sprite/box.ase"));
|
||||||
e->layer = Layer_Shoulders;
|
e->layer = Layer_Shoulders;
|
||||||
|
|
||||||
e->sprite_tint = ColorRed;
|
e->sprite_tint = ColorRed;
|
||||||
@ -350,8 +350,8 @@ void SpawnTestEntities4(Entity *parent, Vec2 pos)
|
|||||||
Xform xf = XformFromTrs(TRS(.t = pos, .r = r, .s = size));
|
Xform xf = XformFromTrs(TRS(.t = pos, .r = r, .s = size));
|
||||||
SetXform(e, xf);
|
SetXform(e, xf);
|
||||||
|
|
||||||
//e->sprite = S_TagFromPath(Lit("sprite/box.ase"));
|
//e->sprite = S_TagFromName(Lit("sprite/box.ase"));
|
||||||
e->sprite = S_TagFromPath(Lit("sprite/tile.ase"));
|
e->sprite = S_TagFromName(Lit("sprite/tile.ase"));
|
||||||
e->layer = Layer_Shoulders;
|
e->layer = Layer_Shoulders;
|
||||||
|
|
||||||
EnableProp(e, Prop_LightTest);
|
EnableProp(e, Prop_LightTest);
|
||||||
@ -380,15 +380,11 @@ void SpawnTestTile(Snapshot *world, Vec2 world_pos)
|
|||||||
SetXform(e, xf);
|
SetXform(e, xf);
|
||||||
|
|
||||||
e->layer = Layer_Walls;
|
e->layer = Layer_Walls;
|
||||||
e->sprite = S_TagFromPath(Lit("sprite/tile.ase"));
|
e->sprite = S_TagFromName(Lit("sprite/tile.ase"));
|
||||||
e->sprite_tint = ColorRed;
|
e->sprite_tint = ColorRed;
|
||||||
|
|
||||||
{
|
S_Sheet *sheet = S_SheetFromTagAwait(e->sprite);
|
||||||
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));
|
e->sprite_local_xform = XformFromTrs(.s = DivVec2(sheet->frame_size, PIXELS_PER_UNIT));
|
||||||
S_EndScope(scope);
|
|
||||||
}
|
|
||||||
|
|
||||||
EnableProp(e, Prop_Solid);
|
EnableProp(e, Prop_Solid);
|
||||||
Quad collider_quad = QuadFromRect(RectFromScalar(-tile_size.x / 2, -tile_size.y / 2, tile_size.y, tile_size.y));
|
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)));
|
Xform xf = XformFromTrs(TRS(.t = point, .r = RandF64FromState(&step_ctx->rand, 0, Tau)));
|
||||||
Entity *decal = AcquireSyncSrc(root);
|
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->sprite_tint = Rgba32F(1, 1, 1, 0.25f);
|
||||||
decal->layer = Layer_FloorDecals;
|
decal->layer = Layer_FloorDecals;
|
||||||
SetXform(decal, xf);
|
SetXform(decal, xf);
|
||||||
@ -901,8 +897,6 @@ void StepSim(SimStepCtx *ctx)
|
|||||||
world->sim_time_ns += world->sim_dt_ns;
|
world->sim_time_ns += world->sim_dt_ns;
|
||||||
f32 sim_dt = SecondsFromNs(world->sim_dt_ns);
|
f32 sim_dt = SecondsFromNs(world->sim_dt_ns);
|
||||||
|
|
||||||
S_Scope *sprite_frame_scope = S_BeginScope();
|
|
||||||
|
|
||||||
Entity *root = EntityFromId(world, RootEntityId);
|
Entity *root = EntityFromId(world, RootEntityId);
|
||||||
root->owner = world->client->player_id;
|
root->owner = world->client->player_id;
|
||||||
|
|
||||||
@ -1257,7 +1251,7 @@ void StepSim(SimStepCtx *ctx)
|
|||||||
if (!ShouldSimulate(ent)) continue;
|
if (!ShouldSimulate(ent)) continue;
|
||||||
if (S_IsTagNil(ent->sprite)) 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 */
|
/* Update animation */
|
||||||
{
|
{
|
||||||
@ -1297,16 +1291,16 @@ void StepSim(SimStepCtx *ctx)
|
|||||||
#if 0
|
#if 0
|
||||||
/* Update sprite local xform */
|
/* 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 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;
|
f32 rot = AngleFromVec2(dir) + Pi / 2;
|
||||||
|
|
||||||
Xform xf = XformIdentity;
|
Xform xf = XformIdentity;
|
||||||
xf = RotateXform(xf, -rot);
|
xf = RotateXform(xf, -rot);
|
||||||
xf = ScaleXform(xf, sprite_size);
|
xf = ScaleXform(xf, sprite_size);
|
||||||
xf = TranslateXform(xf, NegVec2(slice.center));
|
xf = TranslateXform(xf, NegVec2(pivot_slice.center));
|
||||||
ent->sprite_local_xform = xf;
|
ent->sprite_local_xform = xf;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -1315,8 +1309,7 @@ void StepSim(SimStepCtx *ctx)
|
|||||||
if (ent->sprite_collider_slice.len > 0)
|
if (ent->sprite_collider_slice.len > 0)
|
||||||
{
|
{
|
||||||
Xform cxf = ent->sprite_local_xform;
|
Xform cxf = ent->sprite_local_xform;
|
||||||
|
S_Slice slice = S_SliceFromName(sheet, ent->sprite_collider_slice, ent->animation_frame);
|
||||||
S_Slice slice = S_SliceFromNameIndex(sheet, ent->sprite_collider_slice, ent->animation_frame);
|
|
||||||
ent->local_collider = CLD_ShapeFromQuad(MulXformQuad(cxf, QuadFromRect(slice.rect)));
|
ent->local_collider = CLD_ShapeFromQuad(MulXformQuad(cxf, QuadFromRect(slice.rect)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1367,11 +1360,11 @@ void StepSim(SimStepCtx *ctx)
|
|||||||
|
|
||||||
Entity *parent = EntityFromId(world, ent->parent);
|
Entity *parent = EntityFromId(world, ent->parent);
|
||||||
S_Tag parent_sprite = parent->sprite;
|
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;
|
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_pos = MulXformV2(parent_sprite_xf, attach_slice.center);
|
||||||
Vec2 attach_dir = MulXformBasisV2(parent_sprite_xf, attach_slice.dir);
|
Vec2 attach_dir = MulXformBasisV2(parent_sprite_xf, attach_slice.dir);
|
||||||
|
|
||||||
@ -1459,9 +1452,9 @@ void StepSim(SimStepCtx *ctx)
|
|||||||
{
|
{
|
||||||
S_Tag sprite = ent->sprite;
|
S_Tag sprite = ent->sprite;
|
||||||
u32 animation_frame = ent->animation_frame;
|
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;
|
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_pos = MulXformV2(sprite_local_xform, out_slice.center);
|
||||||
Vec2 rel_dir = MulXformBasisV2(sprite_local_xform, out_slice.dir);
|
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.points[0] = VEC2(0, 0);
|
||||||
bullet->local_collider.count = 1;
|
bullet->local_collider.count = 1;
|
||||||
#else
|
#else
|
||||||
bullet->sprite = S_TagFromPath(Lit("sprite/bullet.ase"));
|
bullet->sprite = S_TagFromName(Lit("sprite/bullet.ase"));
|
||||||
bullet->sprite_collider_slice = Lit("shape");
|
bullet->sprite_collider_slice = Lit("shape");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -1508,9 +1501,9 @@ void StepSim(SimStepCtx *ctx)
|
|||||||
{
|
{
|
||||||
S_Tag sprite = ent->sprite;
|
S_Tag sprite = ent->sprite;
|
||||||
u32 animation_frame = ent->animation_frame;
|
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;
|
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_pos = MulXformV2(sprite_local_xform, out_slice.center);
|
||||||
Vec2 rel_dir = MulXformBasisV2(sprite_local_xform, out_slice.dir);
|
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_pos;
|
||||||
Vec2 sprite_hold_dir;
|
Vec2 sprite_hold_dir;
|
||||||
{
|
{
|
||||||
S_Sheet *sheet = S_SheetFromTagAwait(sprite_frame_scope, ent->sprite);
|
S_Sheet *sheet = S_SheetFromTagAwait(ent->sprite);
|
||||||
S_Slice slice = S_SliceFromNameIndex(sheet, Lit("attach.wep"), ent->animation_frame);
|
S_Slice slice = S_SliceFromName(sheet, Lit("attach.wep"), ent->animation_frame);
|
||||||
sprite_hold_pos = slice.center;
|
sprite_hold_pos = slice.center;
|
||||||
sprite_hold_dir = slice.dir;
|
sprite_hold_dir = slice.dir;
|
||||||
}
|
}
|
||||||
@ -2073,9 +2066,5 @@ void StepSim(SimStepCtx *ctx)
|
|||||||
pub_world->local_player = world->local_player;
|
pub_world->local_player = world->local_player;
|
||||||
}
|
}
|
||||||
|
|
||||||
//- End frame
|
|
||||||
|
|
||||||
S_EndScope(sprite_frame_scope);
|
|
||||||
|
|
||||||
EndScratch(scratch);
|
EndScratch(scratch);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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;
|
||||||
|
}
|
||||||
@ -9,5 +9,10 @@ Struct(R_Tag)
|
|||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ Tag helpers
|
//~ Tag helpers
|
||||||
|
|
||||||
|
R_Tag R_TagFromName(String name);
|
||||||
|
|
||||||
|
////////////////////////////////
|
||||||
|
//~ Resource operations
|
||||||
|
|
||||||
String R_DataFromTag(R_Tag tag);
|
String R_DataFromTag(R_Tag tag);
|
||||||
String R_NameFromTag(R_Tag tag);
|
String R_NameFromTag(R_Tag tag);
|
||||||
|
|||||||
@ -27,7 +27,7 @@ String SETTINGS_StringFromWindowSettings(Arena *arena, const P_WindowSettings *s
|
|||||||
"}\n"
|
"}\n"
|
||||||
);
|
);
|
||||||
|
|
||||||
String formatted = StringFormat(arena,
|
String formatted = FormatString(arena,
|
||||||
fmt,
|
fmt,
|
||||||
FmtString(minimized),
|
FmtString(minimized),
|
||||||
FmtString(maximized),
|
FmtString(maximized),
|
||||||
@ -165,7 +165,7 @@ abort:
|
|||||||
{
|
{
|
||||||
if (json_error.msg.len > 0)
|
if (json_error.msg.len > 0)
|
||||||
{
|
{
|
||||||
*error_out = StringFormat(arena,
|
*error_out = StringF(arena,
|
||||||
Lit("%F\n(%F:%F)"),
|
Lit("%F\n(%F:%F)"),
|
||||||
FmtString(json_error.msg),
|
FmtString(json_error.msg),
|
||||||
FmtUint(json_error.start),
|
FmtUint(json_error.start),
|
||||||
|
|||||||
@ -87,8 +87,8 @@ AC_Asset *SND_LoadAsset(R_Tag resource, SND_SoundFlag flags, b32 wait)
|
|||||||
|
|
||||||
/* Generate and append sound flags to name key */
|
/* Generate and append sound flags to name key */
|
||||||
String name = R_NameFromTag(resource);
|
String name = R_NameFromTag(resource);
|
||||||
String key = StringFormat(scratch.arena,
|
String key = StringF(scratch.arena,
|
||||||
Lit("%F%F_sound"),
|
"%F%F_sound",
|
||||||
FmtString(name),
|
FmtString(name),
|
||||||
FmtUint((u64)flags));
|
FmtUint((u64)flags));
|
||||||
u64 hash = AC_HashFromKey(key);
|
u64 hash = AC_HashFromKey(key);
|
||||||
|
|||||||
1199
src/sprite/sprite.c
1199
src/sprite/sprite.c
File diff suppressed because it is too large
Load Diff
@ -1,14 +1,13 @@
|
|||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ Tag
|
//~ Tag types
|
||||||
|
|
||||||
Struct(S_Tag)
|
Struct(S_Tag)
|
||||||
{
|
{
|
||||||
u64 hash;
|
R_Tag r;
|
||||||
String path;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ Texture
|
//~ Texture types
|
||||||
|
|
||||||
Struct(S_Texture)
|
Struct(S_Texture)
|
||||||
{
|
{
|
||||||
@ -90,160 +89,12 @@ Struct(S_Sheet)
|
|||||||
Dict *slice_groups_dict;
|
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
|
//~ Shared state
|
||||||
|
|
||||||
Struct(S_SharedState)
|
Struct(S_SharedState)
|
||||||
{
|
{
|
||||||
Arena *perm_arena;
|
i32 _;
|
||||||
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;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
extern S_SharedState S_shared_state;
|
extern S_SharedState S_shared_state;
|
||||||
@ -254,85 +105,24 @@ extern S_SharedState S_shared_state;
|
|||||||
void S_Startup(void);
|
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_IsTagNil(S_Tag tag);
|
||||||
b32 S_EqTag(S_Tag t1, S_Tag t2);
|
S_Tag S_TagFromName(String name);
|
||||||
S_Hash S_CacheEntryFromTagHash(u64 tag_hash, S_CacheEntryKind kind);
|
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);
|
S_Sheet *S_SheetFromTagAwait(S_Tag tag);
|
||||||
JobDecl(S_LoadSpriteJob, { S_Scope *scope; S_CacheEntryRef ref; 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_Span S_SpanFromName(S_Sheet *sheet, String name);
|
||||||
S_Slice S_SliceFromNameIndex(S_Sheet *sheet, String name, u32 frame_index);
|
S_Frame S_FrameFromIndex(S_Sheet *sheet, u64 index);
|
||||||
S_SliceArray S_SlicesFromNameIndex(S_Sheet *sheet, String name, u32 frame_index);
|
S_Slice S_SliceFromName(S_Sheet *sheet, String name, u64 frame_index);
|
||||||
|
|
||||||
////////////////////////////////
|
|
||||||
//~ Evictor job
|
|
||||||
|
|
||||||
MergesortCompareFuncDef(S_EvictorSortCmp, arg_a, arg_b, udata);
|
|
||||||
JobDecl(S_EvictorJob, EmptySig);
|
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
@Layer sprite
|
@Layer sprite
|
||||||
|
|
||||||
//- Dependencies
|
//- Dependencies
|
||||||
@Dep platform
|
|
||||||
@Dep gpu
|
@Dep gpu
|
||||||
@Dep ase
|
@Dep ase
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user