Fix leaderboard opponent times and authentic pitstop recharging

This commit is contained in:
Luxferre committed 2026-12-01 08:33:48 +02:00
1 parent b9353f552c
commit 3a377b0534
8 files changed
+592 -79

No files matched your search

+86 -27
View File
@@ -16,7 +16,7 @@ namespace {
std::string format_time(float sec) {
if (sec <= 0.0f) return "--:--.--";
int total_cs = static_cast<int>(sec * 100.0f);
int total_cs = std::clamp(static_cast<int>(std::lround(sec * 100.0f)), 1, 599999);
int mins = total_cs / 6000;
int secs = (total_cs / 100) % 60;
int cs = total_cs % 100;
@@ -518,7 +518,12 @@ void GameApp::update_racing_step(float dt) {
post_race_record_flags_ = hiscores_.submit_race(selected_track_, race_sim_.crafts());
if (selected_mode_ == sim::GameMode::CloneRace && !race_sim_.crafts().empty() &&
race_sim_.crafts()[0].finished) {
save_clone_recording(vfs_.pref_dir(), race_sim_.current_recording());
bool beat_clone = !race_sim_.has_clone_ghost() ||
race_sim_.playback_clone().best_race_time >= 1e8f ||
race_sim_.crafts()[0].race_time <= race_sim_.playback_clone().best_race_time;
if (beat_clone) {
save_clone_recording(vfs_.pref_dir(), race_sim_.current_recording());
}
}
if (selected_mode_ == sim::GameMode::Championship) {
champ_.record_race_results(race_sim_.crafts());
@@ -1298,18 +1303,29 @@ void GameApp::render_hud_viewport(const sim::CraftState& craft, const render::Re
ui_ren_.draw_rect(pad, hud_y, hud_w, hud_h, Vec4(0.02f, 0.04f, 0.1f, 0.72f));
ui_ren_.draw_rect_outline(pad, hud_y, hud_w, hud_h, 2.0f, Vec4(0.25f, 0.65f, 1.0f, 0.8f));
auto draw_bar = [&](float bx, float by, const char* lbl, float val, float maxv, const Vec4& col) {
ui_ren_.draw_text_fit(bx, by, 72.0f * s, 1.45f * s, lbl, Vec4(0.85f, 0.9f, 1.0f, 1));
auto draw_bar = [&](float bx, float by, const char* lbl, float val, float maxv, const Vec4& col,
bool charging) {
Vec4 lbl_col = charging
? ((static_cast<int>(craft.race_time * 10.0f) & 1) ? Vec4(1.0f, 1.0f, 1.0f, 1.0f)
: Vec4(0.45f, 1.0f, 0.55f, 1.0f))
: Vec4(0.85f, 0.9f, 1.0f, 1);
ui_ren_.draw_text_fit(bx, by, 72.0f * s, 1.45f * s, lbl, lbl_col);
float bar_x = bx + 78.0f * s;
float bar_w = 215.0f * s;
float bar_h = 12.0f * s;
ui_ren_.draw_rect(bar_x, by, bar_w, bar_h, Vec4(0.12f, 0.12f, 0.18f, 0.9f));
if (charging) {
ui_ren_.draw_rect_outline(bar_x, by, bar_w, bar_h, 1.0f, Vec4(0.45f, 1.0f, 0.55f, 0.9f));
}
float frac = std::clamp(val / std::max(maxv, 1.0f), 0.0f, 1.0f);
ui_ren_.draw_rect(bar_x + 1, by + 1, (bar_w - 2) * frac, bar_h - 2, col);
};
draw_bar(pad + 10.0f * s, hud_y + 10.0f * s, "SHLD", craft.shield, craft.max_shield, Vec4(0.2f, 0.75f, 1.0f, 1));
draw_bar(pad + 10.0f * s, hud_y + 30.0f * s, "FUEL", craft.fuel, craft.max_fuel, Vec4(1.0f, 0.65f, 0.15f, 1));
draw_bar(pad + 10.0f * s, hud_y + 50.0f * s, "AMMO", craft.ammo, craft.max_ammo, Vec4(0.95f, 0.9f, 0.25f, 1));
draw_bar(pad + 10.0f * s, hud_y + 10.0f * s, "SHLD", craft.shield, craft.max_shield,
Vec4(0.2f, 0.75f, 1.0f, 1), (craft.active_recharge_mask & 1u) != 0);
draw_bar(pad + 10.0f * s, hud_y + 30.0f * s, "FUEL", craft.fuel, craft.max_fuel,
Vec4(1.0f, 0.65f, 0.15f, 1), (craft.active_recharge_mask & 2u) != 0);
draw_bar(pad + 10.0f * s, hud_y + 50.0f * s, "AMMO", craft.ammo, craft.max_ammo,
Vec4(0.95f, 0.9f, 0.25f, 1), (craft.active_recharge_mask & 4u) != 0);
int kmh = static_cast<int>(craft.speed_horizontal() * 14.5f);
char spd_buf[64];
@@ -1776,25 +1792,68 @@ void GameApp::render_menus() {
float c0 = cx - tbl_w * 0.5f;
float c1 = c0 + tbl_w * 0.09f;
float c2 = c0 + tbl_w * 0.31f;
float c3 = c0 + tbl_w * 0.55f;
float c4 = c0 + tbl_w * 0.73f;
float c5 = c0 + tbl_w * 0.91f;
ui_ren_.draw_text_fit(c0, 162.0f, tbl_w * 0.08f, 1.65f, str.position, Vec4(0.4f, 0.85f, 1, 1));
ui_ren_.draw_text_fit(c1, 162.0f, tbl_w * 0.21f, 1.65f, str.driver, Vec4(0.4f, 0.85f, 1, 1));
ui_ren_.draw_text_fit(c2, 162.0f, tbl_w * 0.23f, 1.65f, "TEAM", Vec4(0.4f, 0.85f, 1, 1));
ui_ren_.draw_text_fit(c3, 162.0f, tbl_w * 0.17f, 1.65f, str.time_hdr, Vec4(0.4f, 0.85f, 1, 1));
ui_ren_.draw_text_fit(c4, 162.0f, tbl_w * 0.17f, 1.65f, str.best_lap, Vec4(0.4f, 0.85f, 1, 1));
ui_ren_.draw_text_fit(c5, 162.0f, tbl_w * 0.09f, 1.65f, "KILLS", Vec4(0.4f, 0.85f, 1, 1));
for (size_t i = 0; i < sorted.size(); ++i) {
const auto& c = sorted[i];
float ry = 198.0f + static_cast<float>(i) * 32.0f;
Vec4 col = c.is_human ? Vec4(1, 0.95f, 0.25f, 1) : Vec4(0.85f, 0.9f, 1, 1);
ui_ren_.draw_text_fit(c0, ry, tbl_w * 0.08f, 1.65f, std::to_string(c.placement) + ".", col);
ui_ren_.draw_text_fit(c1, ry, tbl_w * 0.21f, 1.65f, c.pilot_name, col);
ui_ren_.draw_text_fit(c2, ry, tbl_w * 0.23f, 1.65f, sim::kTeamNames[c.team_idx], col);
ui_ren_.draw_text_fit(c3, ry, tbl_w * 0.17f, 1.65f, format_time(c.race_time), col);
ui_ren_.draw_text_fit(c4, ry, tbl_w * 0.17f, 1.65f, format_time(c.best_lap_time), col);
ui_ren_.draw_text_fit(c5, ry, tbl_w * 0.09f, 1.65f, std::to_string(c.kills), col);
if (selected_mode_ == sim::GameMode::DeathMatch) {
float c3 = c0 + tbl_w * 0.55f;
float c4 = c0 + tbl_w * 0.74f;
float c5 = c0 + tbl_w * 0.87f;
ui_ren_.draw_text_fit(c0, 162.0f, tbl_w * 0.08f, 1.65f, str.position, Vec4(0.4f, 0.85f, 1, 1));
ui_ren_.draw_text_fit(c1, 162.0f, tbl_w * 0.21f, 1.65f, str.driver, Vec4(0.4f, 0.85f, 1, 1));
ui_ren_.draw_text_fit(c2, 162.0f, tbl_w * 0.23f, 1.65f, "TEAM", Vec4(0.4f, 0.85f, 1, 1));
ui_ren_.draw_text_fit(c3, 162.0f, tbl_w * 0.18f, 1.65f, str.best_lap, Vec4(0.4f, 0.85f, 1, 1));
ui_ren_.draw_text_fit(c4, 162.0f, tbl_w * 0.12f, 1.65f, "KILLS", Vec4(0.4f, 0.85f, 1, 1));
ui_ren_.draw_text_fit(c5, 162.0f, tbl_w * 0.13f, 1.65f, "DEATHS", Vec4(0.4f, 0.85f, 1, 1));
for (size_t i = 0; i < sorted.size(); ++i) {
const auto& c = sorted[i];
float ry = 198.0f + static_cast<float>(i) * 32.0f;
Vec4 col = c.is_human ? Vec4(1, 0.95f, 0.25f, 1) : Vec4(0.85f, 0.9f, 1, 1);
int tidx = std::clamp(c.team_idx, 0, 7);
ui_ren_.draw_text_fit(c0, ry, tbl_w * 0.08f, 1.65f, std::to_string(c.placement) + ".", col);
ui_ren_.draw_text_fit(c1, ry, tbl_w * 0.21f, 1.65f, c.pilot_name, col);
ui_ren_.draw_text_fit(c2, ry, tbl_w * 0.23f, 1.65f, sim::kTeamNames[tidx], col);
ui_ren_.draw_text_fit(c3, ry, tbl_w * 0.18f, 1.65f, format_time(c.best_lap_time), col);
ui_ren_.draw_text_fit(c4, ry, tbl_w * 0.12f, 1.65f, std::to_string(c.kills), col);
ui_ren_.draw_text_fit(c5, ry, tbl_w * 0.13f, 1.65f, std::to_string(c.deaths), col);
}
} else {
if (selected_mode_ == sim::GameMode::CloneRace && race_sim_.has_clone_ghost() &&
race_sim_.playback_clone().best_race_time < 1e8f) {
sim::CraftState ghost;
ghost.is_human = false;
ghost.pilot_name = "CLONE GHOST";
ghost.team_idx = std::clamp(race_sim_.playback_clone().team_idx, 0, 7);
ghost.race_time = race_sim_.playback_clone().best_race_time;
ghost.best_lap_time = (race_sim_.setup().total_laps <= 1) ? ghost.race_time : 0.0f;
ghost.kills = 0;
ghost.finished = true;
sorted.push_back(std::move(ghost));
std::sort(sorted.begin(), sorted.end(), [](const auto& a, const auto& b) {
return a.race_time < b.race_time;
});
for (size_t i = 0; i < sorted.size(); ++i) {
sorted[i].placement = static_cast<int>(i + 1);
}
}
float c3 = c0 + tbl_w * 0.55f;
float c4 = c0 + tbl_w * 0.73f;
float c5 = c0 + tbl_w * 0.91f;
ui_ren_.draw_text_fit(c0, 162.0f, tbl_w * 0.08f, 1.65f, str.position, Vec4(0.4f, 0.85f, 1, 1));
ui_ren_.draw_text_fit(c1, 162.0f, tbl_w * 0.21f, 1.65f, str.driver, Vec4(0.4f, 0.85f, 1, 1));
ui_ren_.draw_text_fit(c2, 162.0f, tbl_w * 0.23f, 1.65f, "TEAM", Vec4(0.4f, 0.85f, 1, 1));
ui_ren_.draw_text_fit(c3, 162.0f, tbl_w * 0.17f, 1.65f, str.time_hdr, Vec4(0.4f, 0.85f, 1, 1));
ui_ren_.draw_text_fit(c4, 162.0f, tbl_w * 0.17f, 1.65f, str.best_lap, Vec4(0.4f, 0.85f, 1, 1));
ui_ren_.draw_text_fit(c5, 162.0f, tbl_w * 0.09f, 1.65f, "KILLS", Vec4(0.4f, 0.85f, 1, 1));
for (size_t i = 0; i < sorted.size(); ++i) {
const auto& c = sorted[i];
float ry = 198.0f + static_cast<float>(i) * 32.0f;
Vec4 col = c.is_human ? Vec4(1, 0.95f, 0.25f, 1) : Vec4(0.85f, 0.9f, 1, 1);
int tidx = std::clamp(c.team_idx, 0, 7);
ui_ren_.draw_text_fit(c0, ry, tbl_w * 0.08f, 1.65f, std::to_string(c.placement) + ".", col);
ui_ren_.draw_text_fit(c1, ry, tbl_w * 0.21f, 1.65f, c.pilot_name, col);
ui_ren_.draw_text_fit(c2, ry, tbl_w * 0.23f, 1.65f, sim::kTeamNames[tidx], col);
ui_ren_.draw_text_fit(c3, ry, tbl_w * 0.17f, 1.65f, format_time(c.race_time), col);
ui_ren_.draw_text_fit(c4, ry, tbl_w * 0.17f, 1.65f, format_time(c.best_lap_time), col);
ui_ren_.draw_text_fit(c5, ry, tbl_w * 0.09f, 1.65f, std::to_string(c.kills), col);
}
}
} else if (post_race_page_ == 1 && !race_sim_.crafts().empty()) {
const auto& p1 = race_sim_.crafts()[0];
@@ -1819,7 +1878,7 @@ void GameApp::render_menus() {
float c4 = c0 + tbl_w * 0.84f;
for (size_t i = 0; i < ds.size(); ++i) {
float ry = 210.0f + static_cast<float>(i) * 32.0f;
Vec4 col = (i == 0 && ds[i].name == cfg_.player_name)
Vec4 col = (ds[i].name == cfg_.player_name)
? Vec4(1, 0.95f, 0.25f, 1)
: Vec4(0.9f, 0.95f, 1, 1);
ui_ren_.draw_text_fit(c0, ry, tbl_w * 0.09f, 1.7f, std::to_string(i + 1) + ".", col);