rename 'extra' -> 'common'

This commit is contained in:
jacob 2025-10-23 23:54:47 -05:00
parent 26e2875126
commit 0f31e27d96
13 changed files with 66 additions and 65 deletions

View File

@ -4,11 +4,11 @@
@Dep platform
//- Api
@IncludeC gpu.h
@IncludeC gpu_extra.h
@IncludeC gpu_core.h
@IncludeC gpu_common.h
//- Impl
@IncludeC gpu_extra.c
@IncludeC gpu_common.c
//- Dx12 impl
@DefaultWindowsImpl gpu_dx12

View File

@ -68,7 +68,7 @@ void PushGameUiStyle(void)
// UI_Push(FontSize, 24);
UI_Push(FontSize, 12);
UI_Push(Rounding, 0.3f);
UI_Push(Rounding, 0.5f);
UI_Push(TextPadding, 4);
UI_Push(Border, 3);
@ -2025,92 +2025,63 @@ void UpdateUser(P_Window *window)
UI_PushCheckpoint();
{
UI_Push(Parent, dbg_box);
UI_Push(Width, UI_TextSize(0));
UI_Push(Height, UI_TextSize(0));
// UI_Push(BackgroundColor, Rgba32F(0.3, 0.6, 0.3, 0.5));
UI_Push(BackgroundColor, 0);
UI_Push(BorderColor, 0);
UI_Push(TextPadding, 0);
UI_BuildLabelF("blended world entities: %F/%F", FmtUint(g->ss_blended->num_ents_allocated), FmtUint(g->ss_blended->num_ents_reserved));
UI_BuildDivider();
UI_BuildLabelF("blended world tick: %F", FmtUint(g->ss_blended->tick));
UI_BuildDivider();
UI_BuildLabelF("blended world time: %F", FmtFloat(SecondsFromNs(g->ss_blended->sim_time_ns)));
UI_BuildDivider();
UI_BuildDivider();
UI_BuildSpacer(UI_PixelSize(20, 0));
UI_BuildLabelF("average local sim publish dt: %F", FmtFloat(SecondsFromNs(g->average_local_to_user_snapshot_publish_dt_ns)));
UI_BuildDivider();
UI_BuildLabelF("local sim last known tick: %F", FmtUint(g->local_sim_last_known_tick));
UI_BuildDivider();
UI_BuildLabelF("local sim last known time: %F", FmtFloat(SecondsFromNs(g->local_sim_last_known_time_ns)));
UI_BuildDivider();
UI_BuildLabelF("local sim predicted time: %F", FmtFloat(SecondsFromNs(g->local_sim_predicted_time_ns)));
UI_BuildDivider();
UI_BuildLabelF("render time target: %F", FmtFloat(SecondsFromNs(g->render_time_target_ns)));
UI_BuildDivider();
UI_BuildLabelF("render time: %F", FmtFloat(SecondsFromNs(g->render_time_ns)));
UI_BuildDivider();
UI_BuildDivider();
UI_BuildLabelF("local player: [%F]", FmtUid(local_player->id.uid));
UI_BuildDivider();
UI_BuildDivider();
UI_BuildSpacer(UI_PixelSize(20, 0));
Vec2 world_cursor = g->world_cursor;
UI_BuildLabelF("cursor world: %F, %F", FmtFloat(world_cursor.x), FmtFloat(world_cursor.y));
UI_BuildDivider();
Vec2I32 world_tile_cursor = WorldTileIndexFromPos(world_cursor);
UI_BuildLabelF("cursor world tile: %F, %F", FmtSint(world_tile_cursor.x), FmtSint(world_tile_cursor.y));
UI_BuildDivider();
Vec2I32 local_tile_cursor = LocalTileIndexFromWorldTileIndex(world_tile_cursor);
UI_BuildLabelF("cursor local tile: %F, %F", FmtSint(local_tile_cursor.x), FmtSint(local_tile_cursor.y));
UI_BuildDivider();
Vec2I32 tile_chunk_cursor = TileChunkIndexFromWorldTileIndex(world_tile_cursor);
UI_BuildLabelF("cursor tile chunk: %F, %F", FmtSint(tile_chunk_cursor.x), FmtSint(tile_chunk_cursor.y));
UI_BuildDivider();
UI_BuildDivider();
UI_BuildSpacer(UI_PixelSize(20, 0));
UI_BuildLabelF("Network read: %F mbit/s", FmtFloat((f64)g->net_bytes_read.last_second * 8 / 1000 / 1000));
UI_BuildDivider();
UI_BuildLabelF("Network write: %F mbit/s", FmtFloat((f64)g->net_bytes_sent.last_second * 8 / 1000 / 1000));
UI_BuildDivider();
UI_BuildLabelF("Ping (real): %F ms", FmtFloat(SecondsFromNs(local_player->player_last_rtt_ns) * 1000));
UI_BuildDivider();
UI_BuildLabelF("Ping (average): %F ms", FmtFloat(local_player->player_average_rtt_seconds * 1000));
UI_BuildDivider();
UI_BuildDivider();
UI_BuildSpacer(UI_PixelSize(20, 0));
UI_BuildLabelF("Memory committed: %F MiB", FmtFloat((f64)GetGstat(GSTAT_MEMORY_COMMITTED) / 1024 / 1024));
UI_BuildDivider();
UI_BuildLabelF("Virtual memory reserved: %F TiB", FmtFloat((f64)GetGstat(GSTAT_MEMORY_RESERVED) / 1024 / 1024 / 1024 / 1024));
UI_BuildDivider();
UI_BuildLabelF("Arenas allocated: %F", FmtUint(GetGstat(GSTAT_NUM_ARENAS)));
UI_BuildDivider();
UI_BuildDivider();
UI_BuildSpacer(UI_PixelSize(20, 0));
UI_BuildLabelF("Video memory (GPU): %F MiB", FmtFloat((f64)vram.local_used / 1024 / 1024));
UI_BuildDivider();
UI_BuildLabelF("Video memory (shared): %F MiB", FmtFloat((f64)vram.non_local_used / 1024 / 1024));
//UI_BuildLabelF(\n"));
//UI_BuildLabelF(\n"));
#if RtcIsEnabled
UI_BuildDivider();
UI_BuildDivider();
UI_BuildSpacer(UI_PixelSize(20, 0));
UI_BuildLabelF("Debug steps: %F", FmtUint(GetGstat(GSTAT_DEBUG_STEPS)));
//UI_BuildLabelF(\n"));
@ -2461,12 +2432,12 @@ void UpdateUser(P_Window *window)
/* Set root background texture to game texture */
{
pp_root_box->background_texture = g->shade_read;
Xform ui_to_render_xf = InvertXform(g->render_to_ui_xf);
Vec2 p0 = MulXformV2(ui_to_render_xf, VEC2(0, 0));
Vec2 p1 = MulXformV2(ui_to_render_xf, Vec2FromFields(g->ui_size));
pp_root_box->background_texture_uv0 = DivVec2Vec2(p0, Vec2FromFields(g->render_size));
pp_root_box->background_texture_uv1 = DivVec2Vec2(p1, Vec2FromFields(g->render_size));
Vec2 uv0 = DivVec2Vec2(p0, Vec2FromFields(g->render_size));
Vec2 uv1 = DivVec2Vec2(p1, Vec2FromFields(g->render_size));
UI_SetBackgroundTexture(pp_root_box, g->shade_read, uv0, uv1);
}
/* Render UI */

View File

@ -5,14 +5,14 @@
@Dep font
//- Api
@IncludeC ui.h
@IncludeC ui_extra.h
@IncludeC ui_core.h
@IncludeC ui_common.h
@IncludeC ui_draw.h
@IncludeGpu ui_draw.h
//- Impl
@IncludeC ui.c
@IncludeC ui_extra.c
@IncludeC ui_core.c
@IncludeC ui_common.c
@IncludeGpu ui_draw.gpu
//- Shaders

View File

@ -4,6 +4,8 @@
UI_Box *UI_BuildLabel(String text)
{
UI_Key key = UI_KeyFromString(0, text);
UI_SetNext(Width, UI_TextSize(0));
UI_SetNext(Height, UI_TextSize(0));
UI_Box *box = UI_BuildBox(UI_BoxFlag_DrawText, UI_NilKey);
UI_SetDisplayText(box, text);
return box;
@ -25,10 +27,14 @@ UI_Box *UI_BuildLabelF_(char *fmt_cstr, ...)
}
////////////////////////////////////////////////////////////
//~ Divider widget
//~ Spacing widgets
UI_Box *UI_BuildDivider(void)
UI_Box *UI_BuildSpacer(UI_Size size)
{
UI_SetNext(Tint, 0);
/* FIXME: Only set size in parent layout direction */
UI_SetNext(Width, size);
UI_SetNext(Height, size);
UI_Box *box = UI_BuildBox(0, UI_NilKey);
return box;
}

View File

@ -6,6 +6,6 @@ UI_Box *UI_BuildLabel(String text);
UI_Box *UI_BuildLabelF_(char *fmt_cstr, ...);
////////////////////////////////////////////////////////////
//~ Divider widget
//~ Spacing widgets
UI_Box *UI_BuildDivider(void);
UI_Box *UI_BuildSpacer(UI_Size size);

View File

@ -197,6 +197,8 @@ UI_Box *UI_BuildBox(UI_BoxFlag flags, UI_Key key)
box->layout_axis = UI_UseTop(LayoutAxis);
box->background_color = UI_UseTop(BackgroundColor);
box->border_color = UI_UseTop(BorderColor);
box->text_color = UI_UseTop(TextColor);
box->tint = UI_UseTop(Tint);
box->border = UI_UseTop(Border);
box->font_resource = UI_UseTop(Font);
box->font_size = UI_UseTop(FontSize);
@ -222,6 +224,13 @@ void UI_SetDisplayText(UI_Box *box, String str)
box->display_text = text;
}
void UI_SetBackgroundTexture(UI_Box *box, GPU_Resource *texture, Vec2 uv0, Vec2 uv1)
{
box->background_texture = texture;
box->background_texture_uv0 = uv0;
box->background_texture_uv1 = uv1;
}
////////////////////////////////////////////////////////////
//~ Begin build
@ -277,6 +286,7 @@ void UI_BeginBuild(void)
g->style_tops[UI_StyleKind_Height]->style.Height = UI_RatioSize(1, 0);
g->style_tops[UI_StyleKind_Font]->style.Font = UI_GetDefaultFontResource();
g->style_tops[UI_StyleKind_FontSize]->style.FontSize = 12.0f;
g->style_tops[UI_StyleKind_Tint]->style.Tint = 0xFFFFFFFF;
}
if (!g->back_build_arena)
@ -493,6 +503,7 @@ GPU_Resource *UI_EndBuild(Rect render_viewport)
rect->tex_uv1 = VEC2(1, 1);
rect->background_srgb = box->background_color;
rect->border_srgb = box->border_color;
rect->tint_srgb = box->tint;
rect->border = box->border;
rect->rounding = box->rounding;
if (box->background_texture != 0)
@ -530,6 +541,7 @@ GPU_Resource *UI_EndBuild(Rect render_viewport)
rect->flags |= UI_RectFlag_DrawTexture;
rect->p0 = AddVec2(baseline, rr.baseline_start_offset);
rect->p1 = AddVec2(rect->p0, glyph_size);
rect->tint_srgb = box->tint;
rect->tex_uv0 = MulVec2Vec2(atlas_p0, inv_font_image_size);
rect->tex_uv1 = MulVec2Vec2(atlas_p1, inv_font_image_size);

View File

@ -36,8 +36,11 @@ Struct(UI_Size)
x(LayoutAxis, Axis) \
x(Width, UI_Size) \
x(Height, UI_Size) \
x(Size, UI_Size) \
x(BackgroundColor, u32) \
x(BorderColor, u32) \
x(TextColor, u32) \
x(Tint, u32) \
x(Border, f32) \
x(Font, Resource) \
x(FontSize, u32) \
@ -116,6 +119,8 @@ Struct(UI_Box)
UI_Size pref_size[Axis_CountXY];
u32 background_color;
u32 border_color;
u32 text_color;
u32 tint;
f32 border;
f32 text_padding;
f32 rounding;
@ -207,7 +212,7 @@ void UI_PushCheckpoint(void);
void UI_PopCheckpoint(void);
////////////////////////////////////////////////////////////
//~ Style stack helpers
//~ Style helpers
UI_StyleNode *UI_PushStyleNode(UI_StyleKind kind, b32 pop_when_used, UI_Style desc);
UI_Style UI_PopStyleNode(UI_StyleKind kind);
@ -234,6 +239,7 @@ UI_Style UI_StyleFromTopNode(UI_StyleKind kind, b32 use);
UI_Box *UI_BuildBox(UI_BoxFlag flags, UI_Key key);
void UI_SetDisplayText(UI_Box *box, String str);
void UI_SetBackgroundTexture(UI_Box *box, GPU_Resource *texture, Vec2 uv0, Vec2 uv1);
////////////////////////////////////////////////////////////
//~ Begin build

View File

@ -11,6 +11,7 @@ Struct(UI_RectPS_Input)
Semantic(nointerpolation u32, rect_idx);
Semantic(Vec4, background_lin);
Semantic(Vec4, border_lin);
Semantic(Vec4, tint_lin);
Semantic(Vec2, rect_uv);
Semantic(Vec2, tex_uv);
};
@ -36,6 +37,7 @@ UI_RectPS_Input VSDef(UI_RectVS, Semantic(u32, sv_instanceid), Semantic(u32, sv_
result.sv_position = Vec4(NdcFromViewport(sig.viewport_size, screen_vert).xy, 0, 1);
result.background_lin = LinearFromSrgbU32(rect.background_srgb);
result.border_lin = LinearFromSrgbU32(rect.border_srgb);
result.tint_lin = LinearFromSrgbU32(rect.tint_srgb);
result.rect_idx = sv_instanceid;
result.rect_uv = rect_uv;
result.tex_uv = tex_uv;
@ -114,6 +116,9 @@ UI_RectPS_Output PSDef(UI_RectPS, UI_RectPS_Input input)
result = input.border_lin;
}
/* Tint */
result *= input.tint_lin;
UI_RectPS_Output output;
output.sv_target0 = result;
return output;

View File

@ -22,6 +22,7 @@ Struct(UI_RectInstance)
UI_RectFlag flags;
Vec2 p0;
Vec2 p1;
u32 tint_srgb;
u32 background_srgb;
u32 border_srgb;
f32 border;

View File