From 447d1691a065a54b2a2277ae157815c22f068996 Mon Sep 17 00:00:00 2001 From: daft7 Date: Mon, 17 Nov 2025 16:29:47 -0600 Subject: [PATCH 1/8] xHudFontMeter overhead --- src/SB/Core/x/xHudFontMeter.h | 39 +++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/src/SB/Core/x/xHudFontMeter.h b/src/SB/Core/x/xHudFontMeter.h index 766287827..f1bd2ce0c 100644 --- a/src/SB/Core/x/xHudFontMeter.h +++ b/src/SB/Core/x/xHudFontMeter.h @@ -18,27 +18,36 @@ namespace xhud color32u c; color32u drop_c; }; - + struct font_meter_asset : meter_asset { - font_context font; // offset 0x4C, size 0x24 - U8 counter_mode; // offset 0x70, size 0x1 - U8 pad1; // offset 0x71, size 0x1 - U8 pad2; // offset 0x72, size 0x1 - U8 pad3; // offset 0x73, size 0x1 + font_context font; // offset 0x4C, size 0x24 + U8 counter_mode; // offset 0x70, size 0x1 + U8 pad1; // offset 0x71, size 0x1 + U8 pad2; // offset 0x72, size 0x1 + U8 pad3; // offset 0x73, size 0x1 + + char* type_name(); }; struct font_meter_widget : meter_widget { - font_context font; - font_context start_font; - S32 precision; - xVec2 offset; - char buffer[12]; - S32 last_value; - xfont xf; - - static void load(xBase& data, xDynAsset& asset, size_t); + font_context font; // 0xC4 + font_context start_font; // 0xE8 + S32 precision; // 0x10C + xVec2 offset; // 0x110 + char buffer[12]; // 0x118 + S32 last_value; // 0x124 + xfont xf; // 0x128 + + void load(xBase& data, xDynAsset& asset, u32 size_t); + font_meter_widget(xhud::font_meter_asset& init); + void destruct(); + void destroy(); + U32 type(); + U8 is(U32 id); + void update(F32 dt); + void render(); font_meter_asset* get_asset() { From 0d5d89c75b1f51c56a82a62b3edae1c97067df4c Mon Sep 17 00:00:00 2001 From: daft7 Date: Mon, 17 Nov 2025 16:30:03 -0600 Subject: [PATCH 2/8] Method for converting color32u to iColor_tag --- src/SB/Core/gc/iColor.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/SB/Core/gc/iColor.h b/src/SB/Core/gc/iColor.h index c01e8ba4d..c6e985c38 100644 --- a/src/SB/Core/gc/iColor.h +++ b/src/SB/Core/gc/iColor.h @@ -2,6 +2,7 @@ #define ICOLOR_H #include +#include struct iColor_tag { @@ -18,6 +19,16 @@ struct iColor_tag this->a = rhs.a; return *this; }; + + // Conversion constructor instead? + iColor_tag& operator=(const xhud::color32u& rhs) + { + this->r = rhs.r; + this->g = rhs.g; + this->b = rhs.b; + this->a = rhs.a; + return *this; + }; }; #endif From af51fb00ad298b62ffc84d0b24e919b1463f7673 Mon Sep 17 00:00:00 2001 From: daft7 Date: Mon, 17 Nov 2025 16:30:20 -0600 Subject: [PATCH 3/8] Generally okay matches for xHudFontMeter --- src/SB/Core/x/xHudFontMeter.cpp | 179 ++++++++++++++++++++++++++++++++ 1 file changed, 179 insertions(+) diff --git a/src/SB/Core/x/xHudFontMeter.cpp b/src/SB/Core/x/xHudFontMeter.cpp index 99fba1118..d354a8a67 100644 --- a/src/SB/Core/x/xHudFontMeter.cpp +++ b/src/SB/Core/x/xHudFontMeter.cpp @@ -1,3 +1,182 @@ #include "xHudFontMeter.h" #include +#include +#include +#include + +void xhud::font_meter_widget::load(xBase& data, xDynAsset& asset, u32 size_t) +{ + widget::init_base((xBase&)*this, *(xBaseAsset*)&data, sizeof(xhud::font_meter_widget) + 0x10); + new (&this->rc.size) + xhud::font_meter_widget(*(xhud::font_meter_asset*)&data); // TODO: proper size value +} + +xhud::font_meter_widget::font_meter_widget(xhud::font_meter_asset& init) : meter_widget(init) +{ + basic_rect screen_bounds; + + this->font.id = init.font.id; + this->font.justify = init.font.justify; + this->start_font.id = init.font.id; + this->start_font.justify = init.font.justify; + + // No assembly for this operator but bytewise is too many instructions + this->font.c = init.font.c; + this->start_font.c = init.font.c; + this->font.drop_c = init.font.drop_c; + this->start_font.drop_c = init.font.drop_c; + + this->last_value = ((S32)(this->value)) - 20; + this->xf.id = 0; + this->xf.width = this->font.w; + this->xf.height = this->font.h; + this->xf.space = this->font.space; + + this->xf.color = this->font.c; + this->xf.clip = screen_bounds; +} + +void xhud::font_meter_widget::destruct() +{ + ((xhud::meter_widget*)this)->destruct(); +} + +void xhud::font_meter_widget::destroy() +{ + this->destruct(); +} + +U32 xhud::font_meter_widget::type() +{ + static S8 init; + static U32 myid; + + if (init == 0) + { + myid = xStrHash(((xhud::font_meter_asset*)this)->type_name()); + init = 1; + } + return myid; +} + +U8 xhud::font_meter_widget::is(U32 id) +{ + U8 val = 0; + + if ((id == this->type()) || (((xhud::meter_widget*)this->is(id)) != 0)) + { + val = 1; + } + return val; +} + +void xhud::font_meter_widget::update(F32 dt) + +{ + char* format_text[3]; + format_text[0] = 0; + + F32 a; + S32 new_value; + basic_rect bounds; + + U8 flag_1; + U8 flag_2; + + (*this).updater(dt); + this->xf.id = (this->font).id; + this->xf.space = (this->font).space; + a = (*this).rc.size.x; + this->font.w = a; + this->xf.width = a; + a = (*this).rc.size.y; + this->font.h = a; + this->xf.height = a; + + a = (*this).rc.a * (F32)this->start_font.c.a + 0.5; + if (a <= 0.0) + { + flag_1 = 0; + } + else if (a >= 255.0) + { + flag_1 = 255; + } + else if (a < 2.1474836e+09) + { + flag_1 = (U8)(S32)a; + } + else + { + flag_1 = (U8)(S32)(a - 2.1474836e+09); + } + (this->font).c.a = flag_1; + + a = (*this).rc.a * (F32)this->start_font.drop_c.a + 0.5; + if (a <= 0.0) + { + flag_1 = 0; + } + else if (a >= 255.0) + { + flag_1 = 255; + } + else if (a < 2.1474836e+09) + { + flag_1 = (U8)(S32)a; + } + else + { + flag_1 = (U8)(S32)(a - 2.1474836e+09); + } + (this->font).drop_c.a = flag_1; + + new_value = (S32)(this->value + 0.5); + if (this->last_value != new_value) + { + this->last_value = new_value; + a = this->max_value; + if (a < this->min_value) + { + flag_2 = 0; + } + else + { + flag_2 = ((font_meter_asset*)(this->a))->counter_mode; + } + sprintf(this->buffer, format_text[flag_2], new_value, (S32)(a + 0.5)); + bounds = (&this->xf)->bounds(this->buffer); + (this->offset).x = -bounds.x; + (this->offset).y = -bounds.y; + } + return; +} + +void xhud::font_meter_widget::render() + +{ + F32 x; + F32 temp_x; + F32 y; + + temp_x = (this->offset).x + this->rc.loc.x; + y = (this->offset).y + this->rc.loc.y; + if ((this->font).drop_c.a != '\0') + { + (this->xf).color = (this->font).drop_c; + x = temp_x + (this->font).drop_x; + (this->xf).render(this->buffer, x, y + (this->font).drop_y); + } + if ((this->font).c.a != '\0') + { + (this->xf).color = (this->font).c; + (this->xf).render(this->buffer, temp_x, y); + } + return; +} + +char* xhud::font_meter_asset::type_name() +{ + return "hud:meter:font"; +} From 81fbeeaeffef7bb600d6e0c78fc79d968e4ce7eb Mon Sep 17 00:00:00 2001 From: daft7 Date: Mon, 17 Nov 2025 21:47:24 -0600 Subject: [PATCH 4/8] Seeing if it builds with new commented out --- src/SB/Core/x/xHudFontMeter.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/SB/Core/x/xHudFontMeter.cpp b/src/SB/Core/x/xHudFontMeter.cpp index d354a8a67..dcd32a74f 100644 --- a/src/SB/Core/x/xHudFontMeter.cpp +++ b/src/SB/Core/x/xHudFontMeter.cpp @@ -8,8 +8,8 @@ void xhud::font_meter_widget::load(xBase& data, xDynAsset& asset, u32 size_t) { widget::init_base((xBase&)*this, *(xBaseAsset*)&data, sizeof(xhud::font_meter_widget) + 0x10); - new (&this->rc.size) - xhud::font_meter_widget(*(xhud::font_meter_asset*)&data); // TODO: proper size value + // new (&this->rc.size) + // xhud::font_meter_widget(*(xhud::font_meter_asset*)&data); // TODO: proper size value } xhud::font_meter_widget::font_meter_widget(xhud::font_meter_asset& init) : meter_widget(init) From 3c026088d63ee79bfbb69caa0bb7848573e8c372 Mon Sep 17 00:00:00 2001 From: daft7 Date: Mon, 17 Nov 2025 22:30:21 -0600 Subject: [PATCH 5/8] Other build fix (thanks Sway) --- src/SB/Core/x/xHudFontMeter.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/SB/Core/x/xHudFontMeter.cpp b/src/SB/Core/x/xHudFontMeter.cpp index dcd32a74f..ab976a397 100644 --- a/src/SB/Core/x/xHudFontMeter.cpp +++ b/src/SB/Core/x/xHudFontMeter.cpp @@ -7,7 +7,8 @@ void xhud::font_meter_widget::load(xBase& data, xDynAsset& asset, u32 size_t) { - widget::init_base((xBase&)*this, *(xBaseAsset*)&data, sizeof(xhud::font_meter_widget) + 0x10); + // Stub for now because this fails to build. 100% match locally though. + // widget::init_base((xBase&)*this, *(xBaseAsset*)&data, sizeof(xhud::font_meter_widget) + 0x10); // new (&this->rc.size) // xhud::font_meter_widget(*(xhud::font_meter_asset*)&data); // TODO: proper size value } From b644cef4c3725e96a0f29a9ee10dab0e3f7f726d Mon Sep 17 00:00:00 2001 From: daft7 Date: Mon, 17 Nov 2025 22:34:01 -0600 Subject: [PATCH 6/8] Revert, this was fine --- src/SB/Core/x/xHudFontMeter.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/SB/Core/x/xHudFontMeter.cpp b/src/SB/Core/x/xHudFontMeter.cpp index ab976a397..dcd32a74f 100644 --- a/src/SB/Core/x/xHudFontMeter.cpp +++ b/src/SB/Core/x/xHudFontMeter.cpp @@ -7,8 +7,7 @@ void xhud::font_meter_widget::load(xBase& data, xDynAsset& asset, u32 size_t) { - // Stub for now because this fails to build. 100% match locally though. - // widget::init_base((xBase&)*this, *(xBaseAsset*)&data, sizeof(xhud::font_meter_widget) + 0x10); + widget::init_base((xBase&)*this, *(xBaseAsset*)&data, sizeof(xhud::font_meter_widget) + 0x10); // new (&this->rc.size) // xhud::font_meter_widget(*(xhud::font_meter_asset*)&data); // TODO: proper size value } From 079b4fd471f9e66da1b9677b09736e179aa0b54d Mon Sep 17 00:00:00 2001 From: daft7 Date: Mon, 17 Nov 2025 22:49:50 -0600 Subject: [PATCH 7/8] My redefinition of the load method was breaking things. Reverted and method commented to be a stub. --- src/SB/Core/x/xHudFontMeter.cpp | 3 ++- src/SB/Core/x/xHudFontMeter.h | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/SB/Core/x/xHudFontMeter.cpp b/src/SB/Core/x/xHudFontMeter.cpp index dcd32a74f..4a0292c34 100644 --- a/src/SB/Core/x/xHudFontMeter.cpp +++ b/src/SB/Core/x/xHudFontMeter.cpp @@ -7,7 +7,8 @@ void xhud::font_meter_widget::load(xBase& data, xDynAsset& asset, u32 size_t) { - widget::init_base((xBase&)*this, *(xBaseAsset*)&data, sizeof(xhud::font_meter_widget) + 0x10); + // Stubbed out for now for causing build failure. 100% match locally though if method redefined to be nonstatic. + // widget::init_base((xBase&)*this, *(xBaseAsset*)&data, sizeof(xhud::font_meter_widget) + 0x10); // new (&this->rc.size) // xhud::font_meter_widget(*(xhud::font_meter_asset*)&data); // TODO: proper size value } diff --git a/src/SB/Core/x/xHudFontMeter.h b/src/SB/Core/x/xHudFontMeter.h index f1bd2ce0c..a851e82d5 100644 --- a/src/SB/Core/x/xHudFontMeter.h +++ b/src/SB/Core/x/xHudFontMeter.h @@ -40,7 +40,7 @@ namespace xhud S32 last_value; // 0x124 xfont xf; // 0x128 - void load(xBase& data, xDynAsset& asset, u32 size_t); + static void load(xBase& data, xDynAsset& asset, size_t); font_meter_widget(xhud::font_meter_asset& init); void destruct(); void destroy(); From 72c452a205481ab41d895cbc66fae5002b699dd1 Mon Sep 17 00:00:00 2001 From: daft7 Date: Mon, 17 Nov 2025 23:54:54 -0600 Subject: [PATCH 8/8] Square tweaks --- src/SB/Core/x/xHudFontMeter.cpp | 44 ++++++++++++++++----------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/src/SB/Core/x/xHudFontMeter.cpp b/src/SB/Core/x/xHudFontMeter.cpp index 4a0292c34..e16a14a7e 100644 --- a/src/SB/Core/x/xHudFontMeter.cpp +++ b/src/SB/Core/x/xHudFontMeter.cpp @@ -40,7 +40,7 @@ xhud::font_meter_widget::font_meter_widget(xhud::font_meter_asset& init) : meter void xhud::font_meter_widget::destruct() { - ((xhud::meter_widget*)this)->destruct(); + xhud::meter_widget::destruct(); } void xhud::font_meter_widget::destroy() @@ -85,17 +85,17 @@ void xhud::font_meter_widget::update(F32 dt) U8 flag_1; U8 flag_2; - (*this).updater(dt); - this->xf.id = (this->font).id; - this->xf.space = (this->font).space; - a = (*this).rc.size.x; + this->updater(dt); + this->xf.id = this->font.id; + this->xf.space = this->font.space; + a = this->rc.size.x; this->font.w = a; this->xf.width = a; - a = (*this).rc.size.y; + a = this->rc.size.y; this->font.h = a; this->xf.height = a; - a = (*this).rc.a * (F32)this->start_font.c.a + 0.5; + a = this->rc.a * (F32)this->start_font.c.a + 0.5; if (a <= 0.0) { flag_1 = 0; @@ -112,9 +112,9 @@ void xhud::font_meter_widget::update(F32 dt) { flag_1 = (U8)(S32)(a - 2.1474836e+09); } - (this->font).c.a = flag_1; + this->font.c.a = flag_1; - a = (*this).rc.a * (F32)this->start_font.drop_c.a + 0.5; + a = this->rc.a * (F32)this->start_font.drop_c.a + 0.5; if (a <= 0.0) { flag_1 = 0; @@ -131,7 +131,7 @@ void xhud::font_meter_widget::update(F32 dt) { flag_1 = (U8)(S32)(a - 2.1474836e+09); } - (this->font).drop_c.a = flag_1; + this->font.drop_c.a = flag_1; new_value = (S32)(this->value + 0.5); if (this->last_value != new_value) @@ -147,9 +147,9 @@ void xhud::font_meter_widget::update(F32 dt) flag_2 = ((font_meter_asset*)(this->a))->counter_mode; } sprintf(this->buffer, format_text[flag_2], new_value, (S32)(a + 0.5)); - bounds = (&this->xf)->bounds(this->buffer); - (this->offset).x = -bounds.x; - (this->offset).y = -bounds.y; + bounds = this->xf.bounds(this->buffer); + this->offset.x = -bounds.x; + this->offset.y = -bounds.y; } return; } @@ -161,18 +161,18 @@ void xhud::font_meter_widget::render() F32 temp_x; F32 y; - temp_x = (this->offset).x + this->rc.loc.x; - y = (this->offset).y + this->rc.loc.y; - if ((this->font).drop_c.a != '\0') + temp_x = this->offset.x + this->rc.loc.x; + y = this->offset.y + this->rc.loc.y; + if (this->font.drop_c.a != 0) { - (this->xf).color = (this->font).drop_c; - x = temp_x + (this->font).drop_x; - (this->xf).render(this->buffer, x, y + (this->font).drop_y); + this->xf.color = this->font.drop_c; + x = temp_x + this->font.drop_x; + this->xf.render(this->buffer, x, y + this->font.drop_y); } - if ((this->font).c.a != '\0') + if (this->font.c.a != 0) { - (this->xf).color = (this->font).c; - (this->xf).render(this->buffer, temp_x, y); + this->xf.color = this->font.c; + this->xf.render(this->buffer, temp_x, y); } return; }