[Enhancement] Implement Digital Speedometer (#431)

* Fix crash

* Poorly document camera

* Fix harder cpu items

* Fix item

* Prevent Rare Infinite Loop

* Impl Digital Speedometer

* Update PortMenu.cpp

---------

Co-authored-by: MegaMech <7255464+MegaMech@users.noreply.github.com>
This commit is contained in:
MegaMech
2025-07-06 18:06:24 -06:00
committed by GitHub
parent a0b202cca4
commit ffbb9d5438
6 changed files with 78 additions and 4 deletions
+4 -1
View File
@@ -951,7 +951,10 @@ void func_80058F78(void) {
draw_simplified_lap_count(PLAYER_ONE);
func_8004EB38(0);
if (D_801657E6 != false) {
func_8004ED40(0);
if (CVarGetInteger("gEnableDigitalSpeedometer", false) == true) {
render_digital_speedometer(PLAYER_ONE);
}
render_speedometer(PLAYER_ONE);
}
}
}
+53
View File
@@ -2285,6 +2285,55 @@ void print_text2(s32 column, s32 row, char* text, s32 tracking, f32 scaleX, f32
FrameInterpolation_ShouldInterpolateFrame(true);
}
void print_text2_wide(s32 column, s32 row, char* text, s32 tracking, f32 scaleX, f32 scaleY, s32 arg6) {
MenuTexture* glyphTexture;
s32 characterWidth;
s32 glyphIndex;
if (text == NULL) {
// @port if invalid text is loaded it will skip rendering it.
return;
}
// @port Skip Interpolation, if interpolated later remove this tag
FrameInterpolation_ShouldInterpolateFrame(false);
gSPDisplayList(gDisplayListHead++, D_020077A8);
if (*text != 0) {
do {
glyphIndex = char_to_glyph_index(text);
if (glyphIndex >= 0) {
glyphTexture = (MenuTexture*) segmented_to_virtual_dupe((const void*) gGlyphTextureLUT[glyphIndex]);
load_menu_img(glyphTexture);
gDisplayListHead =
print_letter_wide_right(gDisplayListHead, glyphTexture, column - (gGlyphDisplayWidth[glyphIndex] / 2), row,
arg6, scaleX, scaleY);
if ((glyphIndex >= 0xD5) && (glyphIndex < 0xE0)) {
characterWidth = 0x20;
} else {
characterWidth = 0xC;
}
column = column + (s32) ((characterWidth + tracking) * scaleX);
} else if ((glyphIndex != -2) && (glyphIndex == -1)) {
column = column + (s32) ((tracking + 7) * scaleX);
} else {
gSPDisplayList(gDisplayListHead++, D_020077D8);
return;
}
if (glyphIndex >= 0x30) {
text += 2;
} else {
text += 1;
}
} while (*text != 0);
}
gSPDisplayList(gDisplayListHead++, D_020077D8);
// @port Resume Interpolation, if interpolated later remove this tag
FrameInterpolation_ShouldInterpolateFrame(true);
}
void func_800939C8(s32 column, s32 row, char* text, s32 tracking, f32 scaleX, f32 scaleY) {
print_text2(column, row, text, tracking, scaleX, scaleY, 1);
}
@@ -2293,6 +2342,10 @@ void text_draw(s32 column, s32 row, char* text, s32 tracking, f32 scaleX, f32 sc
print_text2(column, row, text, tracking, scaleX, scaleY, 2);
}
void text_draw_wide(s32 column, s32 row, char* text, s32 tracking, f32 scaleX, f32 scaleY) {
print_text2_wide(column, row, text, tracking, scaleX, scaleY, 2);
}
void func_80093A30(s32 arg0) {
func_8009E2A8(D_800F0B1C[arg0]);
}
+2
View File
@@ -377,8 +377,10 @@ void print_text1_center_mode_1(s32, s32, char*, s32, f32, f32);
void print_text1_right(s32, s32, char*, s32, f32, f32);
void print_text1_center_mode_2(s32, s32, char*, s32, f32, f32);
void print_text2(s32, s32, char*, s32, f32, f32, s32);
void print_text2_wide(s32, s32, char*, s32, f32, f32, s32);
void func_800939C8(s32, s32, char*, s32, f32, f32);
void text_draw(s32, s32, char*, s32, f32, f32);
void text_draw_wide(s32, s32, char*, s32, f32, f32);
void func_80093A30(s32);
void func_80093A5C(u32);
void func_80093B70(u32);
+4
View File
@@ -367,6 +367,10 @@ void PortMenu::AddEnhancements() {
.PreFunc([](WidgetInfo& info) { info.isHidden = !CVarGetInteger("gEnableCustomCC", 0); })
.Options(FloatSliderOptions().Min(0.0f).Max(1000.0f).DefaultValue(150.0f).Step(10.0f));
AddWidget(path, "Enable Digital Speedometer", WIDGET_CVAR_CHECKBOX)
.CVar("gEnableDigitalSpeedometer")
.Options(CheckboxOptions().Tooltip("Welcome to the modern era"));
AddWidget(path, "Harder CPU", WIDGET_CVAR_CHECKBOX).CVar("gHarderCPU");
path = { "Enhancements", "Cheats", SECTION_COLUMN_1 };
+13 -2
View File
@@ -2698,13 +2698,24 @@ void func_8004EB38(s32 playerId) {
}
}
void render_digital_speedometer(s32 playerIdx) {
char str[16];
f32 speed = (gPlayers[playerIdx].speed / 18.0f) * 216.0f;
set_text_color(TEXT_YELLOW);
sprintf(str, "%.2f", speed);
text_draw_wide(270, 224, str, 0, 0.5f, 0.5f);
}
// render the speedometer for the player
void func_8004ED40(s32 arg0) {
void render_speedometer(s32 playerIdx) {
gSPClearGeometryMode(gDisplayListHead++, G_ZBUFFER);
func_8004A2F4(playerHUD[arg0].speedometerX, playerHUD[arg0].speedometerY, 0U, 1.0f,
func_8004A2F4(playerHUD[playerIdx].speedometerX, playerHUD[playerIdx].speedometerY, 0U, 1.0f,
// RGBA
CM_GetProps()->Minimap.Colour.r, CM_GetProps()->Minimap.Colour.g, CM_GetProps()->Minimap.Colour.b,
0xFF, LOAD_ASSET(common_texture_speedometer), LOAD_ASSET(D_0D0064B0), 64, 96, 64, 48);
// x, y, needle rot
func_8004A258(D_8018CFEC, D_8018CFF4, D_8016579E, 1.0f, common_texture_speedometer_needle, D_0D005FF0, 0x40, 0x20,
0x40, 0x20);
}
+2 -1
View File
@@ -292,7 +292,8 @@ void func_8004E800(s32);
void func_8004E998(s32);
void func_8004EB30(s32);
void func_8004EB38(s32);
void func_8004ED40(s32);
void render_digital_speedometer(s32 playerIdx);
void render_speedometer(s32);
void func_8004EE54(s32);
void func_8004EF9C(s32);