Autoscale menus and 3D vehicle preview to screen size

This commit is contained in:
Luxferre committed 2026-12-01 09:38:10 +02:00
1 parent 197bfbc973
commit 554958db9a
5 files changed
+217 -150

No files matched your search

+187 -132
View File
@@ -129,6 +129,33 @@ bool write_backbuffer_ppm(const std::string& path, int w, int h) {
return true; return true;
} }
struct MenuLayout {
float scale = 1.0f;
float vw = 1000.0f;
float vh = 580.0f;
float oy = 0.0f;
};
MenuLayout compute_menu_layout(int win_w, int win_h) {
constexpr float kDesignW = 1000.0f;
constexpr float kDesignH = 580.0f;
MenuLayout ml;
float fw = static_cast<float>(std::max(win_w, 1));
float fh = static_cast<float>(std::max(win_h, 1));
ml.scale = std::max(0.45f, std::min(fw / kDesignW, fh / kDesignH));
ml.vw = fw / ml.scale;
ml.vh = fh / ml.scale;
ml.oy = std::max(0.0f, (ml.vh - kDesignH) * 0.5f);
return ml;
}
void vehicle_preview_rect_virt(const MenuLayout& ml, float& x, float& y, float& w, float& h) {
x = ml.vw * 0.5f + 16.0f;
y = ml.oy + 132.0f;
w = std::clamp(ml.vw - x - 28.0f, 180.0f, 440.0f);
h = 360.0f;
}
} // namespace } // namespace
bool GameApp::init(const LaunchOptions& opts) { bool GameApp::init(const LaunchOptions& opts) {
@@ -243,7 +270,15 @@ bool GameApp::init(const LaunchOptions& opts) {
world_ren_.ensure_model(vfs_, em, palette_); world_ren_.ensure_model(vfs_, em, palette_);
} }
if (opts.track_viewer && opts.start_track >= 1 && opts.start_track <= 6) { if (!opts.smoke_menu.empty()) {
selected_track_ = 1;
if (opts.smoke_menu == "main") enter_state(ScreenState::MainMenu);
else if (opts.smoke_menu == "track") enter_state(ScreenState::TrackSelect);
else if (opts.smoke_menu == "vehicle") enter_state(ScreenState::VehicleSelect);
else if (opts.smoke_menu == "options") enter_state(ScreenState::Options);
else if (opts.smoke_menu == "highscores") enter_state(ScreenState::Highscores);
else enter_state(ScreenState::MainMenu);
} else if (opts.track_viewer && opts.start_track >= 1 && opts.start_track <= 6) {
enter_track_viewer(opts.start_track); enter_track_viewer(opts.start_track);
} else if (opts.start_track >= 1 && opts.start_track <= 6) { } else if (opts.start_track >= 1 && opts.start_track <= 6) {
selected_track_ = opts.start_track; selected_track_ = opts.start_track;
@@ -1166,7 +1201,8 @@ void GameApp::render_frame(float alpha) {
world_ren_.render_world_view(cam, {}, {}, 0, 1, cfg_, tv_lights, {}); world_ren_.render_world_view(cam, {}, {}, 0, 1, cfg_, tv_lights, {});
world_ren_.end_classic_world_pass(win_w_, win_h_, cfg_); world_ren_.end_classic_world_pass(win_w_, win_h_, cfg_);
ui_ren_.begin(win_w_, win_h_); MenuLayout ml = compute_menu_layout(win_w_, win_h_);
ui_ren_.begin(win_w_, win_h_, ml.vw, ml.vh);
ui_ren_.draw_rect(12, 12, 520, 56, Vec4(0, 0, 0, 0.65f)); ui_ren_.draw_rect(12, 12, 520, 56, Vec4(0, 0, 0, 0.65f));
ui_ren_.draw_text(24, 22, 2.0f, viewer_level_.name, Vec4(1, 0.85f, 0.2f, 1)); ui_ren_.draw_text(24, 22, 2.0f, viewer_level_.name, Vec4(1, 0.85f, 0.2f, 1));
ui_ren_.draw_text(24, 44, 1.5f, "WASD MOVE ARROWS LOOK SPACE/C UP/DOWN F2 CLASSIC ESC BACK", ui_ren_.draw_text(24, 44, 1.5f, "WASD MOVE ARROWS LOOK SPACE/C UP/DOWN F2 CLASSIC ESC BACK",
@@ -1360,10 +1396,13 @@ void GameApp::render_frame(float alpha) {
static_cast<float>(frame_w), 4.0f, Vec4(0.1f, 0.1f, 0.15f, 1.0f)); static_cast<float>(frame_w), 4.0f, Vec4(0.1f, 0.1f, 0.15f, 1.0f));
} }
} }
if (state_ == ScreenState::Paused) {
render_menus();
}
ui_ren_.end(); ui_ren_.end();
if (state_ == ScreenState::Paused) {
MenuLayout ml = compute_menu_layout(win_w_, win_h_);
ui_ren_.begin(win_w_, win_h_, ml.vw, ml.vh);
render_menus();
ui_ren_.end();
}
return; return;
} }
@@ -1373,16 +1412,19 @@ void GameApp::render_frame(float alpha) {
glClearColor(0.02f, 0.02f, 0.05f, 1.0f); glClearColor(0.02f, 0.02f, 0.05f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
ui_ren_.begin(win_w_, win_h_); MenuLayout ml = compute_menu_layout(win_w_, win_h_);
ui_ren_.begin(win_w_, win_h_, ml.vw, ml.vh);
render_menus(); render_menus();
ui_ren_.end(); ui_ren_.end();
if (state_ == ScreenState::VehicleSelect) { if (state_ == ScreenState::VehicleSelect) {
// Draw live rotating 3D craft model over Vehicle Select screen! // Draw live rotating 3D craft model inside scaled virtual showroom box
int pv_w = win_w_ * 42 / 100; float bx = 0.0f, by = 0.0f, bw = 0.0f, bh = 0.0f;
int pv_h = win_h_ * 46 / 100; vehicle_preview_rect_virt(ml, bx, by, bw, bh);
int pv_x = win_w_ * 52 / 100; int pv_x = static_cast<int>(std::lround(bx * ml.scale));
int pv_y = win_h_ * 26 / 100; int pv_w = static_cast<int>(std::lround(bw * ml.scale));
int pv_h = static_cast<int>(std::lround(bh * ml.scale));
int pv_y = win_h_ - static_cast<int>(std::lround((by + bh) * ml.scale));
int veh = (selected_mode_ == sim::GameMode::SplitScreen && menu_cursor_ >= 3 && menu_cursor_ <= 5) ? p2_veh_ : p1_veh_; int veh = (selected_mode_ == sim::GameMode::SplitScreen && menu_cursor_ >= 3 && menu_cursor_ <= 5) ? p2_veh_ : p1_veh_;
int team = (selected_mode_ == sim::GameMode::SplitScreen && menu_cursor_ >= 3 && menu_cursor_ <= 5) ? p2_team_ : p1_team_; int team = (selected_mode_ == sim::GameMode::SplitScreen && menu_cursor_ >= 3 && menu_cursor_ <= 5) ? p2_team_ : p1_team_;
float pv_scale = sim::kVehicleSpecs[std::clamp(veh, 0, 5)].visual_scale * 1.45f; float pv_scale = sim::kVehicleSpecs[std::clamp(veh, 0, 5)].visual_scale * 1.45f;
@@ -1761,11 +1803,15 @@ void GameApp::render_minimap(const sim::CraftState& focus, float mx, float my, f
void GameApp::render_menus() { void GameApp::render_menus() {
const auto& str = get_strings(cfg_.language); const auto& str = get_strings(cfg_.language);
float cx = static_cast<float>(win_w_) * 0.5f; MenuLayout ml = compute_menu_layout(win_w_, win_h_);
const float vw = ml.vw;
const float vh = ml.vh;
const float oy = ml.oy;
const float cx = vw * 0.5f;
if (state_ == ScreenState::Intro) { if (state_ == ScreenState::Intro) {
ui_ren_.draw_stream_4_3(); ui_ren_.draw_stream_4_3();
ui_ren_.draw_text_centered(cx, static_cast<float>(win_h_) - 28.0f, 1.8f, ui_ren_.draw_text_centered(cx, vh - 28.0f, 1.85f,
"PRESS ANY KEY TO SKIP", Vec4(0.75f, 0.8f, 0.9f, 0.8f)); "PRESS ANY KEY TO SKIP", Vec4(0.75f, 0.8f, 0.9f, 0.8f));
return; return;
} }
@@ -1773,29 +1819,31 @@ void GameApp::render_menus() {
if (state_ == ScreenState::Title) { if (state_ == ScreenState::Title) {
ui_ren_.draw_screen_4_3("title"); ui_ren_.draw_screen_4_3("title");
float pulse = 0.65f + 0.35f * std::sin(static_cast<float>(ui_time_) * 4.5f); float pulse = 0.65f + 0.35f * std::sin(static_cast<float>(ui_time_) * 4.5f);
ui_ren_.draw_text_centered(cx, static_cast<float>(win_h_) * 0.84f, 2.4f, float img_h = std::min(vh, vw * 0.75f);
float prompt_y = (vh + img_h) * 0.5f - img_h * 0.14f;
ui_ren_.draw_text_centered(cx, prompt_y, 2.5f,
str.press_fire, Vec4(1.0f, 0.9f, 0.25f, pulse)); str.press_fire, Vec4(1.0f, 0.9f, 0.25f, pulse));
return; return;
} }
// Backdrop for menus // Backdrop for menus
ui_ren_.draw_screen_cover("oscr", 0.38f); ui_ren_.draw_screen_cover("oscr", 0.38f);
ui_ren_.draw_rect(0, 0, static_cast<float>(win_w_), static_cast<float>(win_h_), Vec4(0.03f, 0.05f, 0.11f, 0.55f)); ui_ren_.draw_rect(0, 0, vw, vh, Vec4(0.03f, 0.05f, 0.11f, 0.55f));
if (state_ == ScreenState::Paused) { if (state_ == ScreenState::Paused) {
ui_ren_.draw_rect(cx - 220, 180, 440, 270, Vec4(0.03f, 0.05f, 0.12f, 0.9f)); ui_ren_.draw_rect(cx - 230.0f, oy + 145.0f, 460.0f, 290.0f, Vec4(0.03f, 0.05f, 0.12f, 0.92f));
ui_ren_.draw_rect_outline(cx - 220, 180, 440, 270, 2.0f, Vec4(0.3f, 0.7f, 1.0f, 1)); ui_ren_.draw_rect_outline(cx - 230.0f, oy + 145.0f, 460.0f, 290.0f, 2.0f, Vec4(0.3f, 0.7f, 1.0f, 1));
ui_ren_.draw_text_centered(cx, 200, 3.0f, "PAUSED", Vec4(1.0f, 0.85f, 0.2f, 1)); ui_ren_.draw_text_centered(cx, oy + 168.0f, 3.1f, "PAUSED", Vec4(1.0f, 0.85f, 0.2f, 1));
const char* pitems[] = {str.continue_game, "RESTART RACE", str.options, str.abort_game}; const char* pitems[] = {str.continue_game, "RESTART RACE", str.options, str.abort_game};
for (int i = 0; i < 4; ++i) { for (int i = 0; i < 4; ++i) {
Vec4 col = (i == menu_cursor_) ? Vec4(1, 0.95f, 0.2f, 1) : Vec4(0.8f, 0.88f, 1, 1); Vec4 col = (i == menu_cursor_) ? Vec4(1, 0.95f, 0.2f, 1) : Vec4(0.8f, 0.88f, 1, 1);
ui_ren_.draw_text_centered(cx, 260 + i * 42.0f, 2.2f, pitems[i], col); ui_ren_.draw_text_centered(cx, oy + 232.0f + i * 44.0f, 2.25f, pitems[i], col);
} }
return; return;
} }
// Header Title in authentic Bullfrog neon-green bevel font (PFONT0-1) // Header Title in authentic Bullfrog neon-green bevel font (PFONT0-1)
ui_ren_.draw_text_centered_fit(cx, 20.0f, static_cast<float>(win_w_) - 48.0f, 4.6f, ui_ren_.draw_text_centered_fit(cx, oy + 18.0f, vw - 48.0f, 4.6f,
"TOP-OCTANE", Vec4(1.0f, 1.0f, 1.0f, 1.0f), true, "TOP-OCTANE", Vec4(1.0f, 1.0f, 1.0f, 1.0f), true,
render::UiFont::Panel); render::UiFont::Panel);
@@ -1803,33 +1851,33 @@ void GameApp::render_menus() {
std::string edit_display = name_edit_buf_ + (blink_cursor ? "_" : " "); std::string edit_display = name_edit_buf_ + (blink_cursor ? "_" : " ");
if (state_ == ScreenState::MainMenu) { if (state_ == ScreenState::MainMenu) {
ui_ren_.draw_text_centered(cx, 74.0f, 1.8f, "PILOT: " + cfg_.player_name, ui_ren_.draw_text_centered(cx, oy + 72.0f, 1.9f, "PILOT: " + cfg_.player_name,
Vec4(0.45f, 0.95f, 0.65f, 1.0f)); Vec4(0.45f, 0.95f, 0.65f, 1.0f));
const char* items[] = { const char* items[] = {
str.single_race, str.death_match, str.clone_race, str.single_race, str.death_match, str.clone_race,
str.championship, str.split_screen, str.track_viewer, str.championship, str.split_screen, str.track_viewer,
str.highscores, str.options, str.quit str.highscores, str.options, str.quit
}; };
float start_y = 122.0f; float start_y = oy + 114.0f;
for (int i = 0; i < 9; ++i) { for (int i = 0; i < 9; ++i) {
bool sel = (i == menu_cursor_); bool sel = (i == menu_cursor_);
if (sel) { if (sel) {
ui_ren_.draw_rect(cx - 270, start_y + i * 46 - 7, 540, 34, Vec4(0.15f, 0.45f, 0.85f, 0.6f)); ui_ren_.draw_rect(cx - 280.0f, start_y + i * 44.0f - 7.0f, 560.0f, 34.0f, Vec4(0.15f, 0.45f, 0.85f, 0.62f));
ui_ren_.draw_rect_outline(cx - 270, start_y + i * 46 - 7, 540, 34, 2.0f, Vec4(1, 0.85f, 0.2f, 1)); ui_ren_.draw_rect_outline(cx - 280.0f, start_y + i * 44.0f - 7.0f, 560.0f, 34.0f, 2.0f, Vec4(1, 0.85f, 0.2f, 1));
} }
ui_ren_.draw_text_centered_fit(cx, start_y + i * 46, 510.0f, 2.2f, items[i], ui_ren_.draw_text_centered_fit(cx, start_y + i * 44.0f, 520.0f, 2.25f, items[i],
sel ? Vec4(1, 0.95f, 0.25f, 1) : Vec4(0.82f, 0.9f, 1, 1)); sel ? Vec4(1, 0.95f, 0.25f, 1) : Vec4(0.84f, 0.92f, 1, 1));
} }
ui_ren_.draw_text_centered_fit(cx, static_cast<float>(win_h_) - 32.0f, ui_ren_.draw_text_centered_fit(cx, vh - 30.0f,
static_cast<float>(win_w_) - 40.0f, 1.45f, vw - 40.0f, 1.5f,
"ARROWS/DPAD NAVIGATE ENTER/A SELECT F2 CLASSIC MODE F11 FULLSCREEN", "ARROWS/DPAD NAVIGATE ENTER/A SELECT F2 CLASSIC MODE F11 FULLSCREEN",
Vec4(0.6f, 0.72f, 0.88f, 1)); Vec4(0.65f, 0.76f, 0.92f, 1));
return; return;
} }
if (state_ == ScreenState::ChampionshipMenu) { if (state_ == ScreenState::ChampionshipMenu) {
ui_ren_.draw_text_centered(cx, 78.0f, 2.4f, str.championship, Vec4(0.4f, 0.85f, 1, 1)); ui_ren_.draw_text_centered(cx, oy + 76.0f, 2.45f, str.championship, Vec4(0.4f, 0.85f, 1, 1));
ui_ren_.draw_text_centered(cx, 114.0f, 1.75f, "PILOT: " + cfg_.player_name, ui_ren_.draw_text_centered(cx, oy + 112.0f, 1.8f, "PILOT: " + cfg_.player_name,
Vec4(0.45f, 0.95f, 0.65f, 1.0f)); Vec4(0.45f, 0.95f, 0.65f, 1.0f));
std::string items[6] = { std::string items[6] = {
"NEW CHAMPIONSHIP", "NEW CHAMPIONSHIP",
@@ -1844,25 +1892,25 @@ void GameApp::render_menus() {
}; };
for (int i = 0; i < 6; ++i) { for (int i = 0; i < 6; ++i) {
bool sel = (i == menu_cursor_); bool sel = (i == menu_cursor_);
ui_ren_.draw_text_centered_fit(cx, 165.0f + i * 44.0f, static_cast<float>(win_w_) - 80.0f, ui_ren_.draw_text_centered_fit(cx, oy + 162.0f + i * 46.0f, vw - 80.0f,
2.1f, items[i], 2.15f, items[i],
sel ? Vec4(1, 0.9f, 0.2f, 1) : Vec4(0.85f, 0.9f, 1, 1)); sel ? Vec4(1, 0.9f, 0.2f, 1) : Vec4(0.85f, 0.9f, 1, 1));
} }
if (status_toast_timer_ > 0.0f) { if (status_toast_timer_ > 0.0f) {
ui_ren_.draw_text_centered(cx, 465, 2.0f, status_toast_, Vec4(0.3f, 1.0f, 0.5f, 1)); ui_ren_.draw_text_centered(cx, oy + 470.0f, 2.0f, status_toast_, Vec4(0.3f, 1.0f, 0.5f, 1));
} }
return; return;
} }
if (state_ == ScreenState::TrackSelect) { if (state_ == ScreenState::TrackSelect) {
ui_ren_.draw_text_centered(cx, 82.0f, 2.5f, str.select_track, Vec4(0.4f, 0.85f, 1, 1)); ui_ren_.draw_text_centered(cx, oy + 76.0f, 2.55f, str.select_track, Vec4(0.4f, 0.85f, 1, 1));
// Track map preview sprite from TRACK0-1 (full track silhouettes sit at indices 1, 3, 6, 7, 9, 11) // Track map preview sprite from TRACK0-1 (full track silhouettes sit at indices 1, 3, 6, 7, 9, 11)
static constexpr int kTrackPreviewSprites[6] = {1, 3, 6, 7, 9, 11}; static constexpr int kTrackPreviewSprites[6] = {1, 3, 6, 7, 9, 11};
int preview_idx = kTrackPreviewSprites[std::clamp(selected_track_ - 1, 0, 5)]; int preview_idx = kTrackPreviewSprites[std::clamp(selected_track_ - 1, 0, 5)];
const float box_x = cx + 115.0f; const float box_x = cx + 100.0f;
const float box_y = 158.0f; const float box_y = oy + 148.0f;
const float box_w = std::max(140.0f, std::min(280.0f, static_cast<float>(win_w_) - box_x - 24.0f)); const float box_w = std::clamp(vw - box_x - 28.0f, 180.0f, 340.0f);
const float box_h = 250.0f; const float box_h = 264.0f;
ui_ren_.draw_rect(box_x, box_y, box_w, box_h, Vec4(0.03f, 0.06f, 0.14f, 0.78f)); ui_ren_.draw_rect(box_x, box_y, box_w, box_h, Vec4(0.03f, 0.06f, 0.14f, 0.78f));
ui_ren_.draw_rect_outline(box_x, box_y, box_w, box_h, 2.0f, Vec4(0.3f, 0.8f, 1.0f, 0.85f)); ui_ren_.draw_rect_outline(box_x, box_y, box_w, box_h, 2.0f, Vec4(0.3f, 0.8f, 1.0f, 0.85f));
int sw = 0, sh = 0; int sw = 0, sh = 0;
@@ -1876,8 +1924,8 @@ void GameApp::render_menus() {
float sy = box_y + (box_h - draw_h) * 0.5f; float sy = box_y + (box_h - draw_h) * 0.5f;
ui_ren_.draw_bank_sprite("track", preview_idx, sx, sy, sc, Vec4(0.85f, 1.0f, 1.0f, 1.0f)); ui_ren_.draw_bank_sprite("track", preview_idx, sx, sy, sc, Vec4(0.85f, 1.0f, 1.0f, 1.0f));
} }
const float left_x = std::max(36.0f, cx - 480.0f); const float left_x = std::max(36.0f, cx - 460.0f);
const float max_w = std::max(180.0f, box_x - left_x - 24.0f); const float max_w = std::max(220.0f, box_x - left_x - 24.0f);
const char* tnames[6] = { const char* tnames[6] = {
"1. AMAZON DELTA TURNPIKE", "2. TRANS-ASIA INTERSTATE", "3. SHANGHAI DRAGON", "1. AMAZON DELTA TURNPIKE", "2. TRANS-ASIA INTERSTATE", "3. SHANGHAI DRAGON",
"4. NEW CHERNOBYL CENTRAL", "5. SLAM CANYON", "6. THRAK CITY" "4. NEW CHERNOBYL CENTRAL", "5. SLAM CANYON", "6. THRAK CITY"
@@ -1897,23 +1945,28 @@ void GameApp::render_menus() {
}; };
for (int i = 0; i < 5; ++i) { for (int i = 0; i < 5; ++i) {
bool sel = (i == menu_cursor_); bool sel = (i == menu_cursor_);
ui_ren_.draw_text_fit(left_x, 175.0f + i * 48.0f, max_w, 1.95f, rows[i], ui_ren_.draw_text_fit(left_x, oy + 166.0f + i * 48.0f, max_w, 2.0f, rows[i],
sel ? Vec4(1, 0.92f, 0.2f, 1) : Vec4(0.85f, 0.9f, 1, 1)); sel ? Vec4(1, 0.92f, 0.2f, 1) : Vec4(0.85f, 0.9f, 1, 1));
} }
const auto& rec = hiscores_.tracks[selected_track_ - 1]; const auto& rec = hiscores_.tracks[selected_track_ - 1];
ui_ren_.draw_text_fit(left_x, 450.0f, max_w + 180.0f, 1.75f, ui_ren_.draw_text_fit(left_x, oy + 448.0f, vw - left_x - 32.0f, 1.8f,
"BEST LAP: " + format_time(rec.best_lap) + " (" + rec.best_lap_driver + ")", "BEST LAP: " + format_time(rec.best_lap) + " (" + rec.best_lap_driver + ")",
Vec4(0.4f, 1, 0.65f, 1)); Vec4(0.4f, 1, 0.65f, 1));
ui_ren_.draw_text_fit(left_x, 482.0f, max_w + 180.0f, 1.75f, ui_ren_.draw_text_fit(left_x, oy + 482.0f, vw - left_x - 32.0f, 1.8f,
"BEST RACE: " + format_time(rec.best_race) + " (" + rec.best_race_driver + ")", "BEST RACE: " + format_time(rec.best_race) + " (" + rec.best_race_driver + ")",
Vec4(0.4f, 1, 0.65f, 1)); Vec4(0.4f, 1, 0.65f, 1));
return; return;
} }
if (state_ == ScreenState::VehicleSelect) { if (state_ == ScreenState::VehicleSelect) {
ui_ren_.draw_text_centered(cx, 82.0f, 2.5f, str.select_car, Vec4(0.4f, 0.85f, 1, 1)); ui_ren_.draw_text_centered(cx, oy + 76.0f, 2.55f, str.select_car, Vec4(0.4f, 0.85f, 1, 1));
const float left_x = std::max(36.0f, cx - 480.0f); float bx = 0.0f, by = 0.0f, bw = 0.0f, bh = 0.0f;
const float max_w = std::max(220.0f, static_cast<float>(win_w_) * 0.50f - left_x - 16.0f); vehicle_preview_rect_virt(ml, bx, by, bw, bh);
ui_ren_.draw_rect(bx, by, bw, bh, Vec4(0.03f, 0.06f, 0.14f, 0.72f));
ui_ren_.draw_rect_outline(bx, by, bw, bh, 2.0f, Vec4(0.3f, 0.8f, 1.0f, 0.85f));
const float left_x = std::max(36.0f, cx - 460.0f);
const float max_w = std::max(240.0f, bx - left_x - 20.0f);
bool is_split = (selected_mode_ == sim::GameMode::SplitScreen); bool is_split = (selected_mode_ == sim::GameMode::SplitScreen);
auto draw_pilot_row = [&](float ry, const char* prefix, const std::string& cur_val, auto draw_pilot_row = [&](float ry, const char* prefix, const std::string& cur_val,
@@ -1922,98 +1975,100 @@ void GameApp::render_menus() {
ui_ren_.draw_rect(left_x - 6.0f, ry - 6.0f, max_w + 12.0f, 28.0f, Vec4(0.16f, 0.34f, 0.68f, 0.85f)); ui_ren_.draw_rect(left_x - 6.0f, ry - 6.0f, max_w + 12.0f, 28.0f, Vec4(0.16f, 0.34f, 0.68f, 0.85f));
ui_ren_.draw_rect_outline(left_x - 6.0f, ry - 6.0f, max_w + 12.0f, 28.0f, 2.0f, ui_ren_.draw_rect_outline(left_x - 6.0f, ry - 6.0f, max_w + 12.0f, 28.0f, 2.0f,
Vec4(1.0f, 0.88f, 0.2f, 1.0f)); Vec4(1.0f, 0.88f, 0.2f, 1.0f));
ui_ren_.draw_text_fit(left_x, ry, max_w, 1.8f, std::string(prefix) + edit_display, ui_ren_.draw_text_fit(left_x, ry, max_w, 1.85f, std::string(prefix) + edit_display,
Vec4(1.0f, 0.96f, 0.3f, 1.0f)); Vec4(1.0f, 0.96f, 0.3f, 1.0f));
} else { } else {
std::string pline = std::string(prefix) + cur_val + (sel ? " [ENTER EDIT]" : ""); std::string pline = std::string(prefix) + cur_val + (sel ? " [ENTER EDIT]" : "");
ui_ren_.draw_text_fit(left_x, ry, max_w, 1.8f, pline, ui_ren_.draw_text_fit(left_x, ry, max_w, 1.85f, pline,
sel ? Vec4(1, 0.92f, 0.2f, 1) : Vec4(0.45f, 0.95f, 0.65f, 1)); sel ? Vec4(1, 0.92f, 0.2f, 1) : Vec4(0.45f, 0.95f, 0.65f, 1));
} }
}; };
draw_pilot_row(142.0f, is_split ? "P1 NAME: " : "PILOT NAME: ", cfg_.player_name, 1, menu_cursor_ == 0); draw_pilot_row(oy + 136.0f, is_split ? "P1 NAME: " : "PILOT NAME: ", cfg_.player_name, 1, menu_cursor_ == 0);
const auto& sp = sim::kVehicleSpecs[p1_veh_]; const auto& sp = sim::kVehicleSpecs[p1_veh_];
ui_ren_.draw_text_fit(left_x, 180.0f, max_w, 1.95f, ui_ren_.draw_text_fit(left_x, oy + 174.0f, max_w, 1.95f,
std::string("P1 VEHICLE: < ") + sp.name + " >", std::string("P1 VEHICLE: < ") + sp.name + " >",
menu_cursor_ == 1 ? Vec4(1, 0.92f, 0.2f, 1) : Vec4(0.85f, 0.9f, 1, 1)); menu_cursor_ == 1 ? Vec4(1, 0.92f, 0.2f, 1) : Vec4(0.85f, 0.9f, 1, 1));
ui_ren_.draw_text_fit(left_x, 214.0f, max_w, 1.85f, ui_ren_.draw_text_fit(left_x, oy + 208.0f, max_w, 1.85f,
std::string("P1 TEAM: < ") + sim::kTeamNames[p1_team_] + " >", std::string("P1 TEAM: < ") + sim::kTeamNames[p1_team_] + " >",
menu_cursor_ == 2 ? Vec4(1, 0.92f, 0.2f, 1) : Vec4(0.85f, 0.9f, 1, 1)); menu_cursor_ == 2 ? Vec4(1, 0.92f, 0.2f, 1) : Vec4(0.85f, 0.9f, 1, 1));
auto draw_stat = [&](float y, const char* lbl, int val) { auto draw_stat = [&](float y, const char* lbl, int val) {
ui_ren_.draw_text_fit(left_x, y, 180.0f, 1.65f, lbl, Vec4(0.8f, 0.9f, 1, 1)); ui_ren_.draw_text_fit(left_x, y, 168.0f, 1.65f, lbl, Vec4(0.8f, 0.9f, 1, 1));
float bar_x0 = left_x + 178.0f;
float cell_step = std::min(22.0f, std::max(10.0f, (max_w - 178.0f) / 10.0f));
for (int b = 0; b < 10; ++b) { for (int b = 0; b < 10; ++b) {
Vec4 col = (b < val) ? Vec4(0.25f, 0.9f, 1.0f, 1.0f) : Vec4(0.15f, 0.2f, 0.3f, 0.8f); Vec4 col = (b < val) ? Vec4(0.25f, 0.9f, 1.0f, 1.0f) : Vec4(0.15f, 0.2f, 0.3f, 0.8f);
ui_ren_.draw_rect(left_x + 190.0f + b * 22.0f, y, 18.0f, 13.0f, col); ui_ren_.draw_rect(bar_x0 + b * cell_step, y, cell_step - 4.0f, 13.0f, col);
} }
}; };
draw_stat(254, str.weight, sp.stat_weight); draw_stat(oy + 248.0f, str.weight, sp.stat_weight);
draw_stat(278, str.armour, sp.stat_armour); draw_stat(oy + 272.0f, str.armour, sp.stat_armour);
draw_stat(302, str.speed, sp.stat_speed); draw_stat(oy + 296.0f, str.speed, sp.stat_speed);
draw_stat(326, str.firepower, sp.stat_firepower); draw_stat(oy + 320.0f, str.firepower, sp.stat_firepower);
int start_row = 3; int start_row = 3;
if (is_split) { if (is_split) {
const auto& sp2 = sim::kVehicleSpecs[p2_veh_]; const auto& sp2 = sim::kVehicleSpecs[p2_veh_];
draw_pilot_row(364.0f, "P2 NAME: ", cfg_.player2_name, 2, menu_cursor_ == 3); draw_pilot_row(oy + 358.0f, "P2 NAME: ", cfg_.player2_name, 2, menu_cursor_ == 3);
ui_ren_.draw_text_fit(left_x, 398.0f, max_w, 1.85f, ui_ren_.draw_text_fit(left_x, oy + 392.0f, max_w, 1.85f,
std::string("P2 VEHICLE: < ") + sp2.name + " >", std::string("P2 VEHICLE: < ") + sp2.name + " >",
menu_cursor_ == 4 ? Vec4(1, 0.92f, 0.2f, 1) : Vec4(0.85f, 0.9f, 1, 1)); menu_cursor_ == 4 ? Vec4(1, 0.92f, 0.2f, 1) : Vec4(0.85f, 0.9f, 1, 1));
ui_ren_.draw_text_fit(left_x, 432.0f, max_w, 1.85f, ui_ren_.draw_text_fit(left_x, oy + 426.0f, max_w, 1.85f,
std::string("P2 TEAM: < ") + sim::kTeamNames[p2_team_] + " >", std::string("P2 TEAM: < ") + sim::kTeamNames[p2_team_] + " >",
menu_cursor_ == 5 ? Vec4(1, 0.92f, 0.2f, 1) : Vec4(0.85f, 0.9f, 1, 1)); menu_cursor_ == 5 ? Vec4(1, 0.92f, 0.2f, 1) : Vec4(0.85f, 0.9f, 1, 1));
start_row = 6; start_row = 6;
} }
ui_ren_.draw_text_fit(left_x, 488.0f, max_w, 2.25f, "START RACE >>", ui_ren_.draw_text_fit(left_x, oy + 482.0f, max_w, 2.3f, "START RACE >>",
menu_cursor_ == start_row ? Vec4(0.3f, 1.0f, 0.45f, 1) : Vec4(0.8f, 0.9f, 1, 1)); menu_cursor_ == start_row ? Vec4(0.3f, 1.0f, 0.45f, 1) : Vec4(0.8f, 0.9f, 1, 1));
if (editing_name_target_ != 0) { if (editing_name_target_ != 0) {
ui_ren_.draw_text_centered_fit(cx, static_cast<float>(win_h_) - 32.0f, ui_ren_.draw_text_centered_fit(cx, vh - 30.0f,
static_cast<float>(win_w_) - 40.0f, 1.45f, vw - 40.0f, 1.5f,
"TYPE PILOT NAME BACKSPACE DELETE ENTER SAVE ESC CANCEL", "TYPE PILOT NAME BACKSPACE DELETE ENTER SAVE ESC CANCEL",
Vec4(1.0f, 0.9f, 0.35f, 1.0f)); Vec4(1.0f, 0.9f, 0.35f, 1.0f));
} else if (status_toast_timer_ > 0.0f) { } else if (status_toast_timer_ > 0.0f) {
ui_ren_.draw_text_centered(cx, static_cast<float>(win_h_) - 36.0f, 1.8f, status_toast_, ui_ren_.draw_text_centered(cx, vh - 36.0f, 1.85f, status_toast_,
Vec4(0.3f, 1.0f, 0.5f, 1)); Vec4(0.3f, 1.0f, 0.5f, 1));
} }
return; return;
} }
if (state_ == ScreenState::Highscores) { if (state_ == ScreenState::Highscores) {
ui_ren_.draw_text_centered(cx, 82.0f, 2.5f, str.highscores, Vec4(0.4f, 0.85f, 1, 1)); ui_ren_.draw_text_centered(cx, oy + 76.0f, 2.55f, str.highscores, Vec4(0.4f, 0.85f, 1, 1));
const char* tnames[6] = {"AMAZON DELTA", "TRANS-ASIA", "SHANGHAI DRAGON", "NEW CHERNOBYL", "SLAM CANYON", "THRAK CITY"}; const char* tnames[6] = {"AMAZON DELTA", "TRANS-ASIA", "SHANGHAI DRAGON", "NEW CHERNOBYL", "SLAM CANYON", "THRAK CITY"};
float tbl_w = std::min(900.0f, static_cast<float>(win_w_) - 48.0f); float tbl_w = std::min(900.0f, vw - 48.0f);
float c_trk = cx - tbl_w * 0.5f; float c_trk = cx - tbl_w * 0.5f;
float c_lap = c_trk + tbl_w * 0.30f; float c_lap = c_trk + tbl_w * 0.30f;
float c_rac = c_trk + tbl_w * 0.65f; float c_rac = c_trk + tbl_w * 0.65f;
float hdr_y = 148.0f; float hdr_y = oy + 140.0f;
ui_ren_.draw_text_fit(c_trk, hdr_y, tbl_w * 0.28f, 1.7f, "TRACK", Vec4(0.4f, 0.85f, 1, 1)); ui_ren_.draw_text_fit(c_trk, hdr_y, tbl_w * 0.28f, 1.75f, "TRACK", Vec4(0.4f, 0.85f, 1, 1));
ui_ren_.draw_text_fit(c_lap, hdr_y, tbl_w * 0.33f, 1.7f, "BEST LAP", Vec4(0.4f, 0.85f, 1, 1)); ui_ren_.draw_text_fit(c_lap, hdr_y, tbl_w * 0.33f, 1.75f, "BEST LAP", Vec4(0.4f, 0.85f, 1, 1));
ui_ren_.draw_text_fit(c_rac, hdr_y, tbl_w * 0.35f, 1.7f, "BEST RACE", Vec4(0.4f, 0.85f, 1, 1)); ui_ren_.draw_text_fit(c_rac, hdr_y, tbl_w * 0.35f, 1.75f, "BEST RACE", Vec4(0.4f, 0.85f, 1, 1));
for (int i = 0; i < 6; ++i) { for (int i = 0; i < 6; ++i) {
const auto& r = hiscores_.tracks[i]; const auto& r = hiscores_.tracks[i];
float ry = 186.0f + i * 44.0f; float ry = oy + 178.0f + i * 44.0f;
std::string col0 = std::to_string(i + 1) + ". " + tnames[i]; std::string col0 = std::to_string(i + 1) + ". " + tnames[i];
std::string col1 = format_time(r.best_lap) + " (" + r.best_lap_driver + ")"; std::string col1 = format_time(r.best_lap) + " (" + r.best_lap_driver + ")";
std::string col2 = format_time(r.best_race) + " (" + r.best_race_driver + ")"; std::string col2 = format_time(r.best_race) + " (" + r.best_race_driver + ")";
ui_ren_.draw_text_fit(c_trk, ry, tbl_w * 0.28f, 1.65f, col0, Vec4(0.9f, 0.95f, 1, 1)); ui_ren_.draw_text_fit(c_trk, ry, tbl_w * 0.28f, 1.7f, col0, Vec4(0.9f, 0.95f, 1, 1));
ui_ren_.draw_text_fit(c_lap, ry, tbl_w * 0.33f, 1.65f, col1, Vec4(0.85f, 0.95f, 0.9f, 1)); ui_ren_.draw_text_fit(c_lap, ry, tbl_w * 0.33f, 1.7f, col1, Vec4(0.85f, 0.95f, 0.9f, 1));
ui_ren_.draw_text_fit(c_rac, ry, tbl_w * 0.35f, 1.65f, col2, Vec4(0.85f, 0.95f, 0.9f, 1)); ui_ren_.draw_text_fit(c_rac, ry, tbl_w * 0.35f, 1.7f, col2, Vec4(0.85f, 0.95f, 0.9f, 1));
} }
ui_ren_.draw_text_centered_fit(cx, 500, tbl_w, 1.85f, "ENTER CLEAR HISCORES ESC BACK", Vec4(1, 0.85f, 0.2f, 1)); ui_ren_.draw_text_centered_fit(cx, oy + 480.0f, tbl_w, 1.85f, "ENTER CLEAR HISCORES ESC BACK", Vec4(1, 0.85f, 0.2f, 1));
if (status_toast_timer_ > 0.0f) { if (status_toast_timer_ > 0.0f) {
ui_ren_.draw_text_centered(cx, 540, 2.0f, status_toast_, Vec4(0.3f, 1, 0.5f, 1)); ui_ren_.draw_text_centered(cx, oy + 520.0f, 2.0f, status_toast_, Vec4(0.3f, 1, 0.5f, 1));
} }
return; return;
} }
if (state_ == ScreenState::Options) { if (state_ == ScreenState::Options) {
ui_ren_.draw_text_centered(cx, 82.0f, 2.5f, str.options, Vec4(0.4f, 0.85f, 1, 1)); ui_ren_.draw_text_centered(cx, oy + 76.0f, 2.55f, str.options, Vec4(0.4f, 0.85f, 1, 1));
const char* tabs[7] = {"VIDEO", "AUDIO", "CONTROLS P1", "CONTROLS P2", "INPUT / PAD", "GAME", "RULES"}; const char* tabs[7] = {"VIDEO", "AUDIO", "CONTROLS P1", "CONTROLS P2", "INPUT / PAD", "GAME", "RULES"};
std::string tab_str = std::string("CATEGORY: < ") + tabs[static_cast<int>(opt_tab_)] + " >"; std::string tab_str = std::string("CATEGORY: < ") + tabs[static_cast<int>(opt_tab_)] + " >";
ui_ren_.draw_text_centered(cx, 138.0f, 2.05f, tab_str, ui_ren_.draw_text_centered(cx, oy + 130.0f, 2.1f, tab_str,
menu_cursor_ == 0 ? Vec4(1, 0.92f, 0.2f, 1) : Vec4(0.5f, 0.85f, 1, 1)); menu_cursor_ == 0 ? Vec4(1, 0.92f, 0.2f, 1) : Vec4(0.5f, 0.85f, 1, 1));
auto on_off = [](bool b) -> const char* { return b ? "ON" : "OFF"; }; auto on_off = [](bool b) -> const char* { return b ? "ON" : "OFF"; };
@@ -2108,11 +2163,11 @@ void GameApp::render_menus() {
rows.push_back(std::string("TRACK MORPHING: ") + on_off(cfg_.track_morphing_enabled)); rows.push_back(std::string("TRACK MORPHING: ") + on_off(cfg_.track_morphing_enabled));
} }
const float ry_start = 186.0f; const float ry_start = oy + 178.0f;
const float avail_h = std::max(220.0f, static_cast<float>(win_h_) - 72.0f - ry_start); const float avail_h = std::max(240.0f, oy + 520.0f - ry_start);
const float step_y = std::min(44.0f, avail_h / static_cast<float>(std::max<size_t>(rows.size(), 1))); const float step_y = std::min(42.0f, avail_h / static_cast<float>(std::max<size_t>(rows.size(), 1)));
const float font_sz = (step_y < 32.0f) ? 1.65f : 1.85f; const float font_sz = (step_y < 32.0f) ? 1.7f : 1.9f;
const float opt_max_w = static_cast<float>(win_w_) - 64.0f; const float opt_max_w = vw - 64.0f;
for (size_t i = 0; i < rows.size(); ++i) { for (size_t i = 0; i < rows.size(); ++i) {
float ry = ry_start + static_cast<float>(i) * step_y; float ry = ry_start + static_cast<float>(i) * step_y;
bool sel = (static_cast<int>(i) + 1 == menu_cursor_); bool sel = (static_cast<int>(i) + 1 == menu_cursor_);
@@ -2126,30 +2181,30 @@ void GameApp::render_menus() {
sel ? Vec4(1, 0.92f, 0.2f, 1) : Vec4(0.85f, 0.9f, 1, 1)); sel ? Vec4(1, 0.92f, 0.2f, 1) : Vec4(0.85f, 0.9f, 1, 1));
} }
if (status_toast_timer_ > 0.0f && editing_name_target_ == 0) { if (status_toast_timer_ > 0.0f && editing_name_target_ == 0) {
ui_ren_.draw_text_centered(cx, static_cast<float>(win_h_) - 64.0f, 1.8f, ui_ren_.draw_text_centered(cx, vh - 64.0f, 1.85f,
status_toast_, Vec4(0.3f, 1.0f, 0.5f, 1.0f)); status_toast_, Vec4(0.3f, 1.0f, 0.5f, 1.0f));
} }
const char* footer = (editing_name_target_ != 0) const char* footer = (editing_name_target_ != 0)
? "TYPE PLAYER NAME BACKSPACE DELETE ENTER SAVE ESC CANCEL" ? "TYPE PLAYER NAME BACKSPACE DELETE ENTER SAVE ESC CANCEL"
: "LEFT/RIGHT ADJUST ENTER EDIT/TOGGLE ESC SAVE & BACK"; : "LEFT/RIGHT ADJUST ENTER EDIT/TOGGLE ESC SAVE & BACK";
ui_ren_.draw_text_centered_fit(cx, static_cast<float>(win_h_) - 32.0f, ui_ren_.draw_text_centered_fit(cx, vh - 30.0f,
static_cast<float>(win_w_) - 40.0f, 1.45f, footer, vw - 40.0f, 1.5f, footer,
(editing_name_target_ != 0) ? Vec4(1.0f, 0.9f, 0.35f, 1.0f) (editing_name_target_ != 0) ? Vec4(1.0f, 0.9f, 0.35f, 1.0f)
: Vec4(0.6f, 0.72f, 0.88f, 1)); : Vec4(0.65f, 0.76f, 0.92f, 1));
return; return;
} }
if (state_ == ScreenState::PostRace) { if (state_ == ScreenState::PostRace) {
ui_ren_.draw_text_centered(cx, 82.0f, 2.6f, str.race_over, Vec4(0.35f, 1.0f, 0.55f, 1)); ui_ren_.draw_text_centered(cx, oy + 76.0f, 2.65f, str.race_over, Vec4(0.35f, 1.0f, 0.55f, 1));
if (post_race_record_flags_ & 1) { if (post_race_record_flags_ & 1) {
ui_ren_.draw_text_centered(cx, 122.0f, 1.85f, "NEW FASTEST LAP!", Vec4(1, 0.9f, 0.2f, 1)); ui_ren_.draw_text_centered(cx, oy + 114.0f, 1.9f, "NEW FASTEST LAP!", Vec4(1, 0.9f, 0.2f, 1));
} }
if (post_race_page_ == 0) { if (post_race_page_ == 0) {
auto sorted = race_sim_.crafts(); auto sorted = race_sim_.crafts();
std::sort(sorted.begin(), sorted.end(), [](const auto& a, const auto& b) { std::sort(sorted.begin(), sorted.end(), [](const auto& a, const auto& b) {
return a.placement < b.placement; return a.placement < b.placement;
}); });
float tbl_w = std::min(880.0f, static_cast<float>(win_w_) - 48.0f); float tbl_w = std::min(900.0f, vw - 48.0f);
float c0 = cx - tbl_w * 0.5f; float c0 = cx - tbl_w * 0.5f;
float c1 = c0 + tbl_w * 0.09f; float c1 = c0 + tbl_w * 0.09f;
float c2 = c0 + tbl_w * 0.31f; float c2 = c0 + tbl_w * 0.31f;
@@ -2157,23 +2212,23 @@ void GameApp::render_menus() {
float c3 = c0 + tbl_w * 0.55f; float c3 = c0 + tbl_w * 0.55f;
float c4 = c0 + tbl_w * 0.74f; float c4 = c0 + tbl_w * 0.74f;
float c5 = c0 + tbl_w * 0.87f; 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(c0, oy + 150.0f, tbl_w * 0.08f, 1.7f, 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(c1, oy + 150.0f, tbl_w * 0.21f, 1.7f, 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(c2, oy + 150.0f, tbl_w * 0.23f, 1.7f, "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(c3, oy + 150.0f, tbl_w * 0.18f, 1.7f, 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(c4, oy + 150.0f, tbl_w * 0.12f, 1.7f, "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)); ui_ren_.draw_text_fit(c5, oy + 150.0f, tbl_w * 0.13f, 1.7f, "DEATHS", Vec4(0.4f, 0.85f, 1, 1));
for (size_t i = 0; i < sorted.size(); ++i) { for (size_t i = 0; i < sorted.size(); ++i) {
const auto& c = sorted[i]; const auto& c = sorted[i];
float ry = 198.0f + static_cast<float>(i) * 32.0f; float ry = oy + 186.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); 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); 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(c0, ry, tbl_w * 0.08f, 1.7f, 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(c1, ry, tbl_w * 0.21f, 1.7f, 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(c2, ry, tbl_w * 0.23f, 1.7f, 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(c3, ry, tbl_w * 0.18f, 1.7f, 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(c4, ry, tbl_w * 0.12f, 1.7f, 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); ui_ren_.draw_text_fit(c5, ry, tbl_w * 0.13f, 1.7f, std::to_string(c.deaths), col);
} }
} else { } else {
if (selected_mode_ == sim::GameMode::CloneRace && race_sim_.has_clone_ghost() && if (selected_mode_ == sim::GameMode::CloneRace && race_sim_.has_clone_ghost() &&
@@ -2197,59 +2252,59 @@ void GameApp::render_menus() {
float c3 = c0 + tbl_w * 0.55f; float c3 = c0 + tbl_w * 0.55f;
float c4 = c0 + tbl_w * 0.73f; float c4 = c0 + tbl_w * 0.73f;
float c5 = c0 + tbl_w * 0.91f; 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(c0, oy + 150.0f, tbl_w * 0.08f, 1.7f, 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(c1, oy + 150.0f, tbl_w * 0.21f, 1.7f, 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(c2, oy + 150.0f, tbl_w * 0.23f, 1.7f, "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(c3, oy + 150.0f, tbl_w * 0.17f, 1.7f, 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(c4, oy + 150.0f, tbl_w * 0.17f, 1.7f, 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)); ui_ren_.draw_text_fit(c5, oy + 150.0f, tbl_w * 0.09f, 1.7f, "KILLS", Vec4(0.4f, 0.85f, 1, 1));
for (size_t i = 0; i < sorted.size(); ++i) { for (size_t i = 0; i < sorted.size(); ++i) {
const auto& c = sorted[i]; const auto& c = sorted[i];
float ry = 198.0f + static_cast<float>(i) * 32.0f; float ry = oy + 186.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); 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); 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(c0, ry, tbl_w * 0.08f, 1.7f, 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(c1, ry, tbl_w * 0.21f, 1.7f, 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(c2, ry, tbl_w * 0.23f, 1.7f, 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(c3, ry, tbl_w * 0.17f, 1.7f, 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(c4, ry, tbl_w * 0.17f, 1.7f, 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); ui_ren_.draw_text_fit(c5, ry, tbl_w * 0.09f, 1.7f, std::to_string(c.kills), col);
} }
} }
} else if (post_race_page_ == 1 && !race_sim_.crafts().empty()) { } else if (post_race_page_ == 1 && !race_sim_.crafts().empty()) {
const auto& p1 = race_sim_.crafts()[0]; const auto& p1 = race_sim_.crafts()[0];
ui_ren_.draw_text_centered(cx, 162.0f, 2.2f, str.statistics, Vec4(0.4f, 0.85f, 1, 1)); ui_ren_.draw_text_centered(cx, oy + 152.0f, 2.25f, str.statistics, Vec4(0.4f, 0.85f, 1, 1));
int acc = (p1.shots_fired > 0) ? (p1.shots_hit * 100 / p1.shots_fired) : 0; int acc = (p1.shots_fired > 0) ? (p1.shots_hit * 100 / p1.shots_fired) : 0;
ui_ren_.draw_text(cx - 240, 220, 1.95f, "KILLS / DEATHS: " + std::to_string(p1.kills) + " / " + std::to_string(p1.deaths)); ui_ren_.draw_text(cx - 240.0f, oy + 210.0f, 2.0f, "KILLS / DEATHS: " + std::to_string(p1.kills) + " / " + std::to_string(p1.deaths));
ui_ren_.draw_text(cx - 240, 260, 1.95f, "HIT ACCURACY: " + std::to_string(acc) + "%"); ui_ren_.draw_text(cx - 240.0f, oy + 250.0f, 2.0f, "HIT ACCURACY: " + std::to_string(acc) + "%");
ui_ren_.draw_text(cx - 240, 300, 1.95f, "FUEL USED: " + std::to_string(static_cast<int>(p1.fuel_used))); ui_ren_.draw_text(cx - 240.0f, oy + 290.0f, 2.0f, "FUEL USED: " + std::to_string(static_cast<int>(p1.fuel_used)));
ui_ren_.draw_text(cx - 240, 340, 1.95f, "ARMOUR USED: " + std::to_string(static_cast<int>(p1.armour_used))); ui_ren_.draw_text(cx - 240.0f, oy + 330.0f, 2.0f, "ARMOUR USED: " + std::to_string(static_cast<int>(p1.armour_used)));
if (selected_mode_ == sim::GameMode::Championship) { if (selected_mode_ == sim::GameMode::Championship) {
ui_ren_.draw_text(cx - 240, 380, 1.95f, "RATING: " + champ_.player_rating_title(), Vec4(1, 0.9f, 0.2f, 1)); ui_ren_.draw_text(cx - 240.0f, oy + 370.0f, 2.0f, "RATING: " + champ_.player_rating_title(), Vec4(1, 0.9f, 0.2f, 1));
} }
} else if (selected_mode_ == sim::GameMode::Championship) { } else if (selected_mode_ == sim::GameMode::Championship) {
ui_ren_.draw_text_centered(cx, 162.0f, 2.2f, "CHAMPIONSHIP TABLE", Vec4(0.4f, 0.85f, 1, 1)); ui_ren_.draw_text_centered(cx, oy + 152.0f, 2.25f, "CHAMPIONSHIP TABLE", Vec4(0.4f, 0.85f, 1, 1));
auto ds = champ_.drivers; auto ds = champ_.drivers;
std::sort(ds.begin(), ds.end(), [](const auto& a, const auto& b) { return a.points > b.points; }); std::sort(ds.begin(), ds.end(), [](const auto& a, const auto& b) { return a.points > b.points; });
float tbl_w = std::min(700.0f, static_cast<float>(win_w_) - 48.0f); float tbl_w = std::min(720.0f, vw - 48.0f);
float c0 = cx - tbl_w * 0.5f; float c0 = cx - tbl_w * 0.5f;
float c1 = c0 + tbl_w * 0.10f; float c1 = c0 + tbl_w * 0.10f;
float c2 = c0 + tbl_w * 0.40f; float c2 = c0 + tbl_w * 0.40f;
float c3 = c0 + tbl_w * 0.70f; float c3 = c0 + tbl_w * 0.70f;
float c4 = c0 + tbl_w * 0.84f; float c4 = c0 + tbl_w * 0.84f;
for (size_t i = 0; i < ds.size(); ++i) { for (size_t i = 0; i < ds.size(); ++i) {
float ry = 210.0f + static_cast<float>(i) * 32.0f; float ry = oy + 200.0f + static_cast<float>(i) * 32.0f;
Vec4 col = (ds[i].name == cfg_.player_name) Vec4 col = (ds[i].name == cfg_.player_name)
? Vec4(1, 0.95f, 0.25f, 1) ? Vec4(1, 0.95f, 0.25f, 1)
: Vec4(0.9f, 0.95f, 1, 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); ui_ren_.draw_text_fit(c0, ry, tbl_w * 0.09f, 1.75f, std::to_string(i + 1) + ".", col);
ui_ren_.draw_text_fit(c1, ry, tbl_w * 0.29f, 1.7f, ds[i].name, col); ui_ren_.draw_text_fit(c1, ry, tbl_w * 0.29f, 1.75f, ds[i].name, col);
ui_ren_.draw_text_fit(c2, ry, tbl_w * 0.29f, 1.7f, sim::kTeamNames[ds[i].team_idx], col); ui_ren_.draw_text_fit(c2, ry, tbl_w * 0.29f, 1.75f, sim::kTeamNames[ds[i].team_idx], col);
ui_ren_.draw_text_fit(c3, ry, tbl_w * 0.13f, 1.7f, std::to_string(ds[i].points) + " PTS", col); ui_ren_.draw_text_fit(c3, ry, tbl_w * 0.13f, 1.75f, std::to_string(ds[i].points) + " PTS", col);
ui_ren_.draw_text_fit(c4, ry, tbl_w * 0.16f, 1.7f, std::to_string(ds[i].wins) + " W", col); ui_ren_.draw_text_fit(c4, ry, tbl_w * 0.16f, 1.75f, std::to_string(ds[i].wins) + " W", col);
} }
} }
ui_ren_.draw_text_centered_fit(cx, 520.0f, static_cast<float>(win_w_) - 48.0f, 1.85f, ui_ren_.draw_text_centered_fit(cx, oy + 505.0f, vw - 48.0f, 1.9f,
"LEFT/RIGHT STATS PAGE ENTER CONTINUE", Vec4(1, 0.85f, 0.2f, 1)); "LEFT/RIGHT STATS PAGE ENTER CONTINUE", Vec4(1, 0.85f, 0.2f, 1));
} }
} }
+1
View File
@@ -30,6 +30,7 @@ struct LaunchOptions {
bool skip_intro = false; bool skip_intro = false;
int smoke_test_frames = 0; // >0: run N real frames and exit cleanly int smoke_test_frames = 0; // >0: run N real frames and exit cleanly
std::string screenshot_path; // optional PPM output on final smoke frame std::string screenshot_path; // optional PPM output on final smoke frame
std::string smoke_menu; // optional menu screen for visual inspection
}; };
class GameApp { class GameApp {
+3
View File
@@ -22,6 +22,7 @@ void print_usage(const char* argv0) {
<< " --skip-intro Skip INTRO.DAT movie\n" << " --skip-intro Skip INTRO.DAT movie\n"
<< " --smoke-test <frames> Render N frames and exit cleanly\n" << " --smoke-test <frames> Render N frames and exit cleanly\n"
<< " --screenshot <path.ppm> Save final smoke frame as RGB PPM\n" << " --screenshot <path.ppm> Save final smoke frame as RGB PPM\n"
<< " --menu <main|track|vehicle|options> Open specific menu screen on launch\n"
<< " --help Show this help\n"; << " --help Show this help\n";
} }
@@ -57,6 +58,8 @@ int main(int argc, char** argv) {
opts.smoke_test_frames = std::atoi(argv[++i]); opts.smoke_test_frames = std::atoi(argv[++i]);
} else if (std::strcmp(argv[i], "--screenshot") == 0 && i + 1 < argc) { } else if (std::strcmp(argv[i], "--screenshot") == 0 && i + 1 < argc) {
opts.screenshot_path = argv[++i]; opts.screenshot_path = argv[++i];
} else if (std::strcmp(argv[i], "--menu") == 0 && i + 1 < argc) {
opts.smoke_menu = argv[++i];
} else { } else {
LOG_WARN("Unknown argument: %s", argv[i]); LOG_WARN("Unknown argument: %s", argv[i]);
} }
+21 -16
View File
@@ -327,8 +327,14 @@ void UiRenderer::shutdown() {
} }
void UiRenderer::begin(int screen_w, int screen_h) { void UiRenderer::begin(int screen_w, int screen_h) {
screen_w_ = std::max(screen_w, 1); begin(screen_w, screen_h, static_cast<float>(screen_w), static_cast<float>(screen_h));
screen_h_ = std::max(screen_h, 1); }
void UiRenderer::begin(int viewport_w, int viewport_h, float virtual_w, float virtual_h) {
viewport_w_ = std::max(viewport_w, 1);
viewport_h_ = std::max(viewport_h, 1);
virt_w_ = std::max(virtual_w, 1.0f);
virt_h_ = std::max(virtual_h, 1.0f);
verts_.clear(); verts_.clear();
batches_.clear(); batches_.clear();
} }
@@ -353,14 +359,13 @@ void UiRenderer::push_quad(GLuint tex, float x0, float y0, float x1, float y1,
void UiRenderer::end() { void UiRenderer::end() {
if (verts_.empty()) return; if (verts_.empty()) return;
glViewport(0, 0, screen_w_, screen_h_); glViewport(0, 0, viewport_w_, viewport_h_);
glDisable(GL_DEPTH_TEST); glDisable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE); glDisable(GL_CULL_FACE);
glEnable(GL_BLEND); glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
Mat4 ortho = Mat4::ortho(0.0f, static_cast<float>(screen_w_), Mat4 ortho = Mat4::ortho(0.0f, virt_w_, virt_h_, 0.0f, -1.0f, 1.0f);
static_cast<float>(screen_h_), 0.0f, -1.0f, 1.0f);
ui_shader_.use(); ui_shader_.use();
ui_shader_.set_mat4("uOrtho", ortho); ui_shader_.set_mat4("uOrtho", ortho);
ui_shader_.set_int("uTex", 0); ui_shader_.set_int("uTex", 0);
@@ -559,7 +564,7 @@ void UiRenderer::draw_text_centered_fit(float cx, float y, float max_w, float sc
void UiRenderer::draw_screen_cover(const std::string& screen_key, float alpha) { void UiRenderer::draw_screen_cover(const std::string& screen_key, float alpha) {
auto it = screens_.find(screen_key); auto it = screens_.find(screen_key);
if (it == screens_.end() || !it->second.tex) return; if (it == screens_.end() || !it->second.tex) return;
push_quad(it->second.tex, 0, 0, static_cast<float>(screen_w_), static_cast<float>(screen_h_), push_quad(it->second.tex, 0, 0, virt_w_, virt_h_,
0, 0, 1, 1, Vec4(1, 1, 1, alpha)); 0, 0, 1, 1, Vec4(1, 1, 1, alpha));
} }
@@ -567,16 +572,16 @@ void UiRenderer::draw_screen_4_3(const std::string& screen_key, float alpha) {
auto it = screens_.find(screen_key); auto it = screens_.find(screen_key);
if (it == screens_.end() || !it->second.tex) return; if (it == screens_.end() || !it->second.tex) return;
float target_aspect = 4.0f / 3.0f; float target_aspect = 4.0f / 3.0f;
float win_aspect = static_cast<float>(screen_w_) / static_cast<float>(screen_h_); float win_aspect = virt_w_ / virt_h_;
float w = static_cast<float>(screen_w_); float w = virt_w_;
float h = static_cast<float>(screen_h_); float h = virt_h_;
float x = 0.0f, y = 0.0f; float x = 0.0f, y = 0.0f;
if (win_aspect > target_aspect) { if (win_aspect > target_aspect) {
w = h * target_aspect; w = h * target_aspect;
x = (static_cast<float>(screen_w_) - w) * 0.5f; x = (virt_w_ - w) * 0.5f;
} else { } else {
h = w / target_aspect; h = w / target_aspect;
y = (static_cast<float>(screen_h_) - h) * 0.5f; y = (virt_h_ - h) * 0.5f;
} }
push_quad(it->second.tex, x, y, x + w, y + h, 0, 0, 1, 1, Vec4(1, 1, 1, alpha)); push_quad(it->second.tex, x, y, x + w, y + h, 0, 0, 1, 1, Vec4(1, 1, 1, alpha));
} }
@@ -616,16 +621,16 @@ void UiRenderer::update_stream_rgba(int w, int h, const uint8_t* rgba) {
void UiRenderer::draw_stream_4_3() { void UiRenderer::draw_stream_4_3() {
if (!stream_tex_) return; if (!stream_tex_) return;
float target_aspect = 4.0f / 3.0f; float target_aspect = 4.0f / 3.0f;
float win_aspect = static_cast<float>(screen_w_) / static_cast<float>(screen_h_); float win_aspect = virt_w_ / virt_h_;
float w = static_cast<float>(screen_w_); float w = virt_w_;
float h = static_cast<float>(screen_h_); float h = virt_h_;
float x = 0.0f, y = 0.0f; float x = 0.0f, y = 0.0f;
if (win_aspect > target_aspect) { if (win_aspect > target_aspect) {
w = h * target_aspect; w = h * target_aspect;
x = (static_cast<float>(screen_w_) - w) * 0.5f; x = (virt_w_ - w) * 0.5f;
} else { } else {
h = w / target_aspect; h = w / target_aspect;
y = (static_cast<float>(screen_h_) - h) * 0.5f; y = (virt_h_ - h) * 0.5f;
} }
push_quad(stream_tex_, x, y, x + w, y + h, 0, 0, 1, 1, Vec4(1, 1, 1, 1)); push_quad(stream_tex_, x, y, x + w, y + h, 0, 0, 1, 1, Vec4(1, 1, 1, 1));
} }
+5 -2
View File
@@ -40,6 +40,7 @@ public:
void shutdown(); void shutdown();
void begin(int screen_w, int screen_h); void begin(int screen_w, int screen_h);
void begin(int viewport_w, int viewport_h, float virtual_w, float virtual_h);
void end(); void end();
// Primitives // Primitives
@@ -120,8 +121,10 @@ private:
GLuint stream_tex_ = 0; GLuint stream_tex_ = 0;
int stream_w_ = 0, stream_h_ = 0; int stream_w_ = 0, stream_h_ = 0;
int screen_w_ = 1280; int viewport_w_ = 1280;
int screen_h_ = 720; int viewport_h_ = 720;
float virt_w_ = 1280.0f;
float virt_h_ = 720.0f;
FontAtlas font_large_{}; FontAtlas font_large_{};
FontAtlas font_small_{}; FontAtlas font_small_{};