2026-11-30 22:31:51 +02:00
|
|
|
#include "game/game_app.hpp"
|
|
|
|
|
#include "core/log.hpp"
|
|
|
|
|
#include "game/localization.hpp"
|
|
|
|
|
#include "sim/combat.hpp"
|
|
|
|
|
#include "sim/vehicle_defs.hpp"
|
|
|
|
|
|
|
|
|
|
#include <algorithm>
|
2026-11-30 23:57:29 +02:00
|
|
|
#include <cctype>
|
2026-11-30 22:31:51 +02:00
|
|
|
#include <cmath>
|
|
|
|
|
#include <cstdio>
|
2026-11-30 23:57:29 +02:00
|
|
|
#include <filesystem>
|
2026-11-30 22:31:51 +02:00
|
|
|
|
|
|
|
|
namespace top_octane::game {
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
std::string format_time(float sec) {
|
|
|
|
|
if (sec <= 0.0f) return "--:--.--";
|
2026-12-01 08:33:48 +02:00
|
|
|
int total_cs = std::clamp(static_cast<int>(std::lround(sec * 100.0f)), 1, 599999);
|
2026-11-30 22:31:51 +02:00
|
|
|
int mins = total_cs / 6000;
|
|
|
|
|
int secs = (total_cs / 100) % 60;
|
|
|
|
|
int cs = total_cs % 100;
|
|
|
|
|
char buf[32];
|
|
|
|
|
std::snprintf(buf, sizeof(buf), "%02d:%02d.%02d", mins, secs, cs);
|
|
|
|
|
return buf;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool project_world_to_screen(const Vec3& wp, const Mat4& vp, int vx, int vy, int vw, int vh,
|
|
|
|
|
int full_h, float& out_sx, float& out_sy) {
|
|
|
|
|
float cx = vp.m[0] * wp.x + vp.m[4] * wp.y + vp.m[8] * wp.z + vp.m[12];
|
|
|
|
|
float cy = vp.m[1] * wp.x + vp.m[5] * wp.y + vp.m[9] * wp.z + vp.m[13];
|
|
|
|
|
float cw = vp.m[3] * wp.x + vp.m[7] * wp.y + vp.m[11] * wp.z + vp.m[15];
|
|
|
|
|
if (cw <= 0.1f) return false;
|
|
|
|
|
float ndcx = cx / cw;
|
|
|
|
|
float ndcy = cy / cw;
|
|
|
|
|
if (ndcx < -1.1f || ndcx > 1.1f || ndcy < -1.1f || ndcy > 1.1f) return false;
|
|
|
|
|
out_sx = static_cast<float>(vx) + (ndcx * 0.5f + 0.5f) * static_cast<float>(vw);
|
|
|
|
|
// Convert GL bottom-up vy into top-down UI Y
|
|
|
|
|
float gl_y = static_cast<float>(vy) + (ndcy * 0.5f + 0.5f) * static_cast<float>(vh);
|
|
|
|
|
out_sy = static_cast<float>(full_h) - gl_y;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char* diff_label(int d) {
|
|
|
|
|
if (d == 0) return "EASY";
|
|
|
|
|
if (d == 2) return "HARD";
|
|
|
|
|
return "MEDIUM";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char* backend_label(MusicBackend b) {
|
|
|
|
|
switch (b) {
|
|
|
|
|
case MusicBackend::Opl3: return "OPL3 FM (SAMPLE.OPL)";
|
|
|
|
|
case MusicBackend::SoundFont: return "SOUNDFONT (BULLFROG.SBK)";
|
|
|
|
|
case MusicBackend::Custom: return "CUSTOM WAV";
|
|
|
|
|
}
|
|
|
|
|
return "OPL3 FM";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char* lang_label(Language l) {
|
|
|
|
|
switch (l) {
|
|
|
|
|
case Language::German: return "DEUTSCH";
|
|
|
|
|
case Language::Spanish: return "ESPANOL";
|
|
|
|
|
case Language::French: return "FRANCAIS";
|
|
|
|
|
default: return "ENGLISH";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-30 23:57:29 +02:00
|
|
|
const char* camera_label(int cam) {
|
|
|
|
|
if (cam == 1) return "CLOSE CHASE";
|
|
|
|
|
if (cam == 2) return "COCKPIT";
|
|
|
|
|
return "CHASE";
|
|
|
|
|
}
|
|
|
|
|
|
2026-12-01 09:19:20 +02:00
|
|
|
void append_charger_lights(const assets::LevelData& level, double time_s,
|
|
|
|
|
std::vector<render::DynamicLight>& out) {
|
|
|
|
|
float pulse = 0.88f + 0.12f * std::sin(static_cast<float>(time_s) * 3.8f);
|
|
|
|
|
for (const auto& pad : level.pads) {
|
|
|
|
|
Vec3 col(0.22f, 0.70f, 1.00f); // Fuel blue
|
|
|
|
|
if (pad.type == assets::ChargerType::Shield) col = Vec3(0.15f, 1.00f, 0.48f);
|
|
|
|
|
else if (pad.type == assets::ChargerType::Ammo) col = Vec3(1.00f, 0.82f, 0.20f);
|
|
|
|
|
float y = level.sample_height_world(pad.cx, pad.cz) + 0.90f;
|
|
|
|
|
float rad = std::max(pad.half_x, pad.half_z) + 3.4f;
|
|
|
|
|
out.push_back({Vec3(pad.cx, y, pad.cz), rad, col, 0.72f * pulse});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::vector<render::DynamicLight> select_viewport_lights(
|
|
|
|
|
const std::vector<render::DynamicLight>& candidates, const Vec3& focus, float max_dist) {
|
|
|
|
|
struct Scored {
|
|
|
|
|
float score = 0.0f;
|
|
|
|
|
size_t idx = 0;
|
|
|
|
|
};
|
|
|
|
|
std::vector<Scored> ranked;
|
|
|
|
|
ranked.reserve(candidates.size());
|
|
|
|
|
for (size_t i = 0; i < candidates.size(); ++i) {
|
|
|
|
|
const auto& l = candidates[i];
|
|
|
|
|
float d2 = (l.pos - focus).len_sq();
|
|
|
|
|
float lim = max_dist + l.radius;
|
|
|
|
|
if (d2 > lim * lim) continue;
|
|
|
|
|
ranked.push_back({l.intensity / (1.0f + 0.018f * d2), i});
|
|
|
|
|
}
|
|
|
|
|
constexpr size_t kMaxLights = 12;
|
|
|
|
|
if (ranked.size() > kMaxLights) {
|
|
|
|
|
std::partial_sort(ranked.begin(), ranked.begin() + kMaxLights, ranked.end(),
|
|
|
|
|
[](const Scored& a, const Scored& b) { return a.score > b.score; });
|
|
|
|
|
ranked.resize(kMaxLights);
|
|
|
|
|
}
|
|
|
|
|
std::vector<render::DynamicLight> out;
|
|
|
|
|
out.reserve(ranked.size());
|
|
|
|
|
for (const auto& s : ranked) {
|
|
|
|
|
out.push_back(candidates[s.idx]);
|
|
|
|
|
}
|
|
|
|
|
return out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool write_backbuffer_ppm(const std::string& path, int w, int h) {
|
|
|
|
|
if (w <= 0 || h <= 0 || path.empty()) return false;
|
|
|
|
|
std::vector<uint8_t> rgb(static_cast<size_t>(w) * static_cast<size_t>(h) * 3u);
|
|
|
|
|
glPixelStorei(GL_PACK_ALIGNMENT, 1);
|
|
|
|
|
glReadPixels(0, 0, w, h, GL_RGB, GL_UNSIGNED_BYTE, rgb.data());
|
|
|
|
|
std::FILE* f = std::fopen(path.c_str(), "wb");
|
|
|
|
|
if (!f) return false;
|
|
|
|
|
std::fprintf(f, "P6\n%d %d\n255\n", w, h);
|
|
|
|
|
const size_t row_bytes = static_cast<size_t>(w) * 3u;
|
|
|
|
|
for (int y = h - 1; y >= 0; --y) {
|
|
|
|
|
std::fwrite(rgb.data() + static_cast<size_t>(y) * row_bytes, 1, row_bytes, f);
|
|
|
|
|
}
|
|
|
|
|
std::fclose(f);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2026-12-01 09:38:10 +02:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-30 22:31:51 +02:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
bool GameApp::init(const LaunchOptions& opts) {
|
|
|
|
|
opts_ = opts;
|
|
|
|
|
if (!vfs_.init(opts.data_dir)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cfg_.load(vfs_.pref_dir() / "config.ini");
|
|
|
|
|
if (opts.force_classic) cfg_.classic_mode = true;
|
2026-12-01 09:19:20 +02:00
|
|
|
if (opts.force_modern) cfg_.classic_mode = false;
|
2026-11-30 22:31:51 +02:00
|
|
|
if (opts.force_fullscreen) cfg_.fullscreen = true;
|
|
|
|
|
if (opts.force_backend >= 0 && opts.force_backend <= 2) {
|
|
|
|
|
cfg_.music_backend = static_cast<MusicBackend>(opts.force_backend);
|
|
|
|
|
}
|
|
|
|
|
p1_veh_ = cfg_.preferred_vehicle;
|
|
|
|
|
p1_team_ = cfg_.preferred_team;
|
|
|
|
|
selected_laps_ = cfg_.default_laps;
|
|
|
|
|
selected_difficulty_ = cfg_.difficulty;
|
2026-11-30 23:57:29 +02:00
|
|
|
cam_mode_ = cfg_.default_camera;
|
|
|
|
|
hud_visible_ = cfg_.show_hud;
|
|
|
|
|
|
|
|
|
|
// Discover optional external SoundFont (.sf2/.sbk) files under pref_dir
|
|
|
|
|
available_soundfonts_.clear();
|
|
|
|
|
available_soundfonts_.push_back("");
|
|
|
|
|
auto scan_sf_dir = [&](const std::filesystem::path& dir) {
|
|
|
|
|
std::error_code ec;
|
|
|
|
|
if (!std::filesystem::exists(dir, ec) || !std::filesystem::is_directory(dir, ec)) return;
|
|
|
|
|
for (const auto& ent : std::filesystem::directory_iterator(dir, ec)) {
|
|
|
|
|
if (!ent.is_regular_file(ec)) continue;
|
|
|
|
|
std::string ext = ent.path().extension().string();
|
|
|
|
|
for (char& ch : ext) ch = static_cast<char>(std::tolower(static_cast<unsigned char>(ch)));
|
|
|
|
|
if (ext == ".sf2" || ext == ".sbk") {
|
|
|
|
|
std::string p = ent.path().string();
|
|
|
|
|
if (std::find(available_soundfonts_.begin(), available_soundfonts_.end(), p) ==
|
|
|
|
|
available_soundfonts_.end()) {
|
|
|
|
|
available_soundfonts_.push_back(p);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
scan_sf_dir(vfs_.pref_dir() / "soundfonts");
|
|
|
|
|
scan_sf_dir(vfs_.pref_dir());
|
|
|
|
|
if (!cfg_.custom_soundfont_path.empty() &&
|
|
|
|
|
std::find(available_soundfonts_.begin(), available_soundfonts_.end(),
|
|
|
|
|
cfg_.custom_soundfont_path) == available_soundfonts_.end()) {
|
|
|
|
|
available_soundfonts_.push_back(cfg_.custom_soundfont_path);
|
|
|
|
|
}
|
2026-11-30 22:31:51 +02:00
|
|
|
|
|
|
|
|
hiscores_.load(vfs_.pref_dir() / "hiscores.dat");
|
|
|
|
|
|
|
|
|
|
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) != 0) {
|
|
|
|
|
LOG_ERROR("SDL_Init failed: %s", SDL_GetError());
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
|
|
|
|
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
|
|
|
|
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
|
|
|
|
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG);
|
|
|
|
|
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
|
|
|
|
|
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
|
|
|
|
|
if (cfg_.msaa_samples >= 2) {
|
|
|
|
|
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
|
|
|
|
|
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, cfg_.msaa_samples);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint32_t win_flags = SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI;
|
|
|
|
|
if (cfg_.fullscreen) win_flags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
|
|
|
|
|
|
|
|
|
|
window_ = SDL_CreateWindow("Top-Octane", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
|
|
|
|
|
cfg_.window_width, cfg_.window_height, win_flags);
|
|
|
|
|
if (!window_ && cfg_.msaa_samples > 0) {
|
|
|
|
|
// Retry without MSAA if driver rejects requested sample count
|
|
|
|
|
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 0);
|
|
|
|
|
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 0);
|
|
|
|
|
window_ = SDL_CreateWindow("Top-Octane", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
|
|
|
|
|
cfg_.window_width, cfg_.window_height, win_flags);
|
|
|
|
|
}
|
|
|
|
|
if (!window_) {
|
|
|
|
|
LOG_ERROR("SDL_CreateWindow failed: %s", SDL_GetError());
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gl_ctx_ = SDL_GL_CreateContext(window_);
|
|
|
|
|
if (!gl_ctx_) {
|
|
|
|
|
LOG_ERROR("SDL_GL_CreateContext(3.3 Core) failed: %s", SDL_GetError());
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
SDL_GL_MakeCurrent(window_, gl_ctx_);
|
|
|
|
|
SDL_GL_SetSwapInterval(cfg_.vsync ? 1 : 0);
|
|
|
|
|
|
|
|
|
|
if (!gl::init()) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
SDL_GL_GetDrawableSize(window_, &win_w_, &win_h_);
|
|
|
|
|
|
|
|
|
|
if (!palette_.load(vfs_) || !world_ren_.init(vfs_, palette_) || !ui_ren_.init(vfs_, palette_)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
input_.init();
|
|
|
|
|
audio_.init(vfs_, cfg_, /*open_device=*/true);
|
|
|
|
|
|
|
|
|
|
// Preload vehicle & prop 3D models cleanly
|
|
|
|
|
for (int v = 0; v < 6; ++v) {
|
|
|
|
|
for (int t = 0; t < 8; ++t) {
|
|
|
|
|
world_ren_.ensure_model(vfs_, sim::model_key_for(v, t), palette_);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
const char* extra_models[] = {"BAREL0-0", "CONE0-0", "SIGN0-0", "MARSH0-0", "RECOV0-0"};
|
|
|
|
|
for (const char* em : extra_models) {
|
|
|
|
|
world_ren_.ensure_model(vfs_, em, palette_);
|
|
|
|
|
}
|
|
|
|
|
|
2026-12-01 09:38:10 +02:00
|
|
|
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) {
|
2026-11-30 22:31:51 +02:00
|
|
|
enter_track_viewer(opts.start_track);
|
|
|
|
|
} else if (opts.start_track >= 1 && opts.start_track <= 6) {
|
|
|
|
|
selected_track_ = opts.start_track;
|
|
|
|
|
start_race_session();
|
|
|
|
|
} else if (opts.smoke_test_frames > 0) {
|
|
|
|
|
selected_track_ = 1;
|
|
|
|
|
start_race_session();
|
|
|
|
|
} else if (opts.skip_intro || cfg_.skip_intro || !vfs_.exists("DATA/INTRO.DAT") || !flic_.open(vfs_)) {
|
|
|
|
|
enter_state(ScreenState::Title);
|
|
|
|
|
} else {
|
|
|
|
|
enter_state(ScreenState::Intro);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
clock_.reset(SDL_GetPerformanceCounter(), SDL_GetPerformanceFrequency());
|
|
|
|
|
running_ = true;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GameApp::shutdown() {
|
2026-11-30 23:41:37 +02:00
|
|
|
cancel_name_edit();
|
2026-12-01 09:19:20 +02:00
|
|
|
if (opts_.smoke_test_frames == 0) {
|
|
|
|
|
save_all_user_data();
|
|
|
|
|
}
|
2026-11-30 22:31:51 +02:00
|
|
|
audio_.shutdown();
|
|
|
|
|
input_.shutdown();
|
|
|
|
|
ui_ren_.shutdown();
|
|
|
|
|
world_ren_.shutdown();
|
|
|
|
|
if (gl_ctx_) {
|
|
|
|
|
SDL_GL_DeleteContext(gl_ctx_);
|
|
|
|
|
gl_ctx_ = nullptr;
|
|
|
|
|
}
|
|
|
|
|
if (window_) {
|
|
|
|
|
SDL_DestroyWindow(window_);
|
|
|
|
|
window_ = nullptr;
|
|
|
|
|
}
|
|
|
|
|
SDL_Quit();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GameApp::save_all_user_data() {
|
|
|
|
|
cfg_.preferred_vehicle = p1_veh_;
|
|
|
|
|
cfg_.preferred_team = p1_team_;
|
|
|
|
|
cfg_.default_laps = selected_laps_;
|
|
|
|
|
cfg_.difficulty = selected_difficulty_;
|
|
|
|
|
cfg_.save(vfs_.pref_dir() / "config.ini");
|
|
|
|
|
hiscores_.save(vfs_.pref_dir() / "hiscores.dat");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GameApp::apply_video_settings() {
|
|
|
|
|
if (!window_) return;
|
|
|
|
|
SDL_SetWindowFullscreen(window_, cfg_.fullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0);
|
|
|
|
|
if (!cfg_.fullscreen) {
|
|
|
|
|
SDL_SetWindowSize(window_, cfg_.window_width, cfg_.window_height);
|
|
|
|
|
}
|
|
|
|
|
SDL_GL_SetSwapInterval(cfg_.vsync ? 1 : 0);
|
|
|
|
|
SDL_GL_GetDrawableSize(window_, &win_w_, &win_h_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GameApp::toggle_fullscreen() {
|
|
|
|
|
cfg_.fullscreen = !cfg_.fullscreen;
|
|
|
|
|
apply_video_settings();
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-30 23:41:37 +02:00
|
|
|
void GameApp::ensure_music(audio::MusicTrackId track, bool loop, bool force_restart) {
|
|
|
|
|
int tid = static_cast<int>(track);
|
|
|
|
|
if (force_restart || active_music_track_ != tid) {
|
|
|
|
|
active_music_track_ = tid;
|
|
|
|
|
audio_.play_music(track, loop);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-30 23:57:29 +02:00
|
|
|
void GameApp::begin_name_edit(int target) {
|
|
|
|
|
editing_name_target_ = (target == 2) ? 2 : 1;
|
|
|
|
|
name_edit_buf_ = (editing_name_target_ == 2) ? cfg_.player2_name : cfg_.player_name;
|
2026-11-30 23:41:37 +02:00
|
|
|
input_.start_text_input();
|
|
|
|
|
audio_.play_sfx("SELECT.WAV", 0.38f);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GameApp::cancel_name_edit() {
|
2026-11-30 23:57:29 +02:00
|
|
|
if (editing_name_target_ != 0) {
|
|
|
|
|
editing_name_target_ = 0;
|
2026-11-30 23:41:37 +02:00
|
|
|
input_.stop_text_input();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GameApp::update_name_edit() {
|
|
|
|
|
for (char ch : input_.text_input_chars()) {
|
|
|
|
|
if (name_edit_buf_.size() < 12) {
|
|
|
|
|
name_edit_buf_.push_back(ch);
|
|
|
|
|
audio_.play_sfx("CHANGE.WAV", 0.22f);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (input_.text_backspace_pressed() && !name_edit_buf_.empty()) {
|
|
|
|
|
name_edit_buf_.pop_back();
|
|
|
|
|
audio_.play_sfx("CHANGE.WAV", 0.22f);
|
|
|
|
|
}
|
|
|
|
|
if (input_.text_confirm_pressed()) {
|
|
|
|
|
size_t a = 0;
|
|
|
|
|
while (a < name_edit_buf_.size() && name_edit_buf_[a] == ' ') ++a;
|
|
|
|
|
size_t b = name_edit_buf_.size();
|
|
|
|
|
while (b > a && name_edit_buf_[b - 1] == ' ') --b;
|
|
|
|
|
std::string cleaned = name_edit_buf_.substr(a, b - a);
|
2026-11-30 23:57:29 +02:00
|
|
|
std::string& dst = (editing_name_target_ == 2) ? cfg_.player2_name : cfg_.player_name;
|
|
|
|
|
const char* fallback = (editing_name_target_ == 2) ? "PLAYER 2" : "PLAYER";
|
2026-11-30 23:41:37 +02:00
|
|
|
if (!cleaned.empty()) {
|
2026-11-30 23:57:29 +02:00
|
|
|
dst = cleaned;
|
|
|
|
|
} else if (dst.empty()) {
|
|
|
|
|
dst = fallback;
|
2026-11-30 23:41:37 +02:00
|
|
|
}
|
2026-11-30 23:57:29 +02:00
|
|
|
if (editing_name_target_ == 1 && champ_.active && !champ_.drivers.empty()) {
|
2026-11-30 23:41:37 +02:00
|
|
|
champ_.player_name = cfg_.player_name;
|
|
|
|
|
champ_.drivers[0].name = cfg_.player_name;
|
|
|
|
|
}
|
|
|
|
|
cfg_.save(vfs_.pref_dir() / "config.ini");
|
2026-11-30 23:57:29 +02:00
|
|
|
status_toast_ = std::string(editing_name_target_ == 2 ? "P2 NAME: " : "PILOT NAME: ") + dst;
|
|
|
|
|
status_toast_timer_ = 2.0f;
|
2026-11-30 23:41:37 +02:00
|
|
|
cancel_name_edit();
|
|
|
|
|
audio_.play_sfx("SELECT.WAV", 0.38f);
|
|
|
|
|
} else if (input_.text_cancel_pressed()) {
|
|
|
|
|
cancel_name_edit();
|
|
|
|
|
audio_.play_sfx("CHANGE.WAV", 0.32f);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-30 22:31:51 +02:00
|
|
|
void GameApp::enter_state(ScreenState s) {
|
2026-11-30 23:41:37 +02:00
|
|
|
cancel_name_edit();
|
2026-11-30 22:31:51 +02:00
|
|
|
state_ = s;
|
2026-11-30 23:41:37 +02:00
|
|
|
menu_cursor_ = (s == ScreenState::VehicleSelect) ? 1 : 0;
|
2026-11-30 22:31:51 +02:00
|
|
|
rebind_slot_ = -1;
|
|
|
|
|
input_.cancel_rebind();
|
|
|
|
|
|
|
|
|
|
if (s == ScreenState::Intro) {
|
2026-11-30 23:41:37 +02:00
|
|
|
in_race_session_ = false;
|
2026-11-30 22:31:51 +02:00
|
|
|
flic_.reset();
|
|
|
|
|
intro_accum_ = 0.0;
|
|
|
|
|
intro_turbo_played_ = false;
|
|
|
|
|
intro_explode_played_ = false;
|
|
|
|
|
audio_.set_engine_state(false, 0.0f, false, 0.0f);
|
2026-12-01 09:19:20 +02:00
|
|
|
audio_.set_pitstop_state(false, false, 1.0f);
|
2026-11-30 23:41:37 +02:00
|
|
|
ensure_music(audio::MusicTrackId::TitleIntro, true, true);
|
|
|
|
|
} else if (s == ScreenState::Title || s == ScreenState::MainMenu ||
|
|
|
|
|
s == ScreenState::ChampionshipMenu || s == ScreenState::TrackSelect ||
|
|
|
|
|
s == ScreenState::VehicleSelect || s == ScreenState::Highscores) {
|
|
|
|
|
in_race_session_ = false;
|
2026-11-30 22:31:51 +02:00
|
|
|
audio_.set_engine_state(false, 0.0f, false, 0.0f);
|
2026-12-01 09:19:20 +02:00
|
|
|
audio_.set_pitstop_state(false, false, 1.0f);
|
2026-11-30 23:41:37 +02:00
|
|
|
if (active_music_track_ != static_cast<int>(audio::MusicTrackId::TitleIntro)) {
|
|
|
|
|
ensure_music(audio::MusicTrackId::Menu, true, false);
|
|
|
|
|
}
|
|
|
|
|
} else if (s == ScreenState::Options) {
|
|
|
|
|
if (!in_race_session_) {
|
|
|
|
|
audio_.set_engine_state(false, 0.0f, false, 0.0f);
|
2026-12-01 09:19:20 +02:00
|
|
|
audio_.set_pitstop_state(false, false, 1.0f);
|
2026-11-30 23:41:37 +02:00
|
|
|
if (active_music_track_ != static_cast<int>(audio::MusicTrackId::TitleIntro)) {
|
|
|
|
|
ensure_music(audio::MusicTrackId::Menu, true, false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else if (s == ScreenState::PostRace) {
|
|
|
|
|
in_race_session_ = false;
|
2026-11-30 22:31:51 +02:00
|
|
|
audio_.set_engine_state(false, 0.0f, false, 0.0f);
|
2026-12-01 09:19:20 +02:00
|
|
|
audio_.set_pitstop_state(false, false, 1.0f);
|
2026-11-30 23:41:37 +02:00
|
|
|
ensure_music(audio::MusicTrackId::Menu, true, false);
|
2026-11-30 22:31:51 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GameApp::enter_track_viewer(int track_num) {
|
2026-11-30 23:41:37 +02:00
|
|
|
in_race_session_ = false;
|
|
|
|
|
cancel_name_edit();
|
2026-11-30 22:31:51 +02:00
|
|
|
selected_track_ = std::clamp(track_num, 1, 6);
|
|
|
|
|
if (!viewer_level_.load(vfs_, selected_track_)) return;
|
|
|
|
|
world_ren_.load_level(vfs_, viewer_level_, palette_);
|
|
|
|
|
if (!viewer_level_.checkpoints.empty()) {
|
|
|
|
|
const auto& cp = viewer_level_.checkpoints[0];
|
|
|
|
|
viewer_pos_ = Vec3(cp.cx, viewer_level_.sample_height_world(cp.cx, cp.cz) + 3.5f, cp.cz + 6.0f);
|
|
|
|
|
} else {
|
|
|
|
|
viewer_pos_ = Vec3(20.0f, 5.0f, 20.0f);
|
|
|
|
|
}
|
|
|
|
|
viewer_yaw_ = kPi;
|
|
|
|
|
viewer_pitch_ = -0.25f;
|
|
|
|
|
state_ = ScreenState::TrackViewer;
|
2026-11-30 23:41:37 +02:00
|
|
|
ensure_music(static_cast<audio::MusicTrackId>(1 + (selected_track_ - 1) % 4), true, true);
|
2026-11-30 22:31:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GameApp::start_race_session() {
|
2026-11-30 23:41:37 +02:00
|
|
|
cancel_name_edit();
|
2026-11-30 22:31:51 +02:00
|
|
|
assets::LevelData lvl;
|
|
|
|
|
if (!lvl.load(vfs_, selected_track_)) {
|
|
|
|
|
LOG_ERROR("Failed to load level %d", selected_track_);
|
|
|
|
|
enter_state(ScreenState::MainMenu);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
world_ren_.load_level(vfs_, lvl, palette_);
|
|
|
|
|
|
|
|
|
|
sim::RaceSetup setup;
|
|
|
|
|
setup.mode = selected_mode_;
|
|
|
|
|
setup.track_number = selected_track_;
|
|
|
|
|
setup.total_laps = (selected_mode_ == sim::GameMode::Championship) ? 3 : selected_laps_;
|
2026-11-30 23:57:29 +02:00
|
|
|
setup.difficulty = (selected_mode_ == sim::GameMode::Championship) ? champ_.difficulty : selected_difficulty_;
|
2026-11-30 22:31:51 +02:00
|
|
|
setup.num_ai = selected_opponents_;
|
|
|
|
|
setup.p1_vehicle = (selected_mode_ == sim::GameMode::Championship) ? champ_.player_vehicle : p1_veh_;
|
|
|
|
|
setup.p1_team = (selected_mode_ == sim::GameMode::Championship) ? champ_.player_team : p1_team_;
|
|
|
|
|
setup.p1_name = cfg_.player_name;
|
|
|
|
|
setup.p2_vehicle = p2_veh_;
|
|
|
|
|
setup.p2_team = p2_team_;
|
2026-11-30 23:57:29 +02:00
|
|
|
setup.p2_name = cfg_.player2_name;
|
|
|
|
|
setup.deathmatch_kill_limit = cfg_.deathmatch_kill_limit;
|
|
|
|
|
setup.fuel_enabled = cfg_.fuel_enabled;
|
|
|
|
|
setup.damage_enabled = cfg_.damage_enabled;
|
|
|
|
|
setup.weapons_enabled = cfg_.weapons_enabled;
|
|
|
|
|
setup.pickups_enabled = cfg_.pickups_enabled;
|
|
|
|
|
setup.track_morphing_enabled = cfg_.track_morphing_enabled;
|
|
|
|
|
|
|
|
|
|
cam_mode_ = cfg_.default_camera;
|
|
|
|
|
hud_visible_ = cfg_.show_hud;
|
2026-11-30 22:31:51 +02:00
|
|
|
|
|
|
|
|
sim::CloneRecording existing_clone;
|
|
|
|
|
const sim::CloneRecording* clone_ptr = nullptr;
|
|
|
|
|
if (selected_mode_ == sim::GameMode::CloneRace &&
|
|
|
|
|
load_clone_recording(vfs_.pref_dir(), selected_track_, existing_clone)) {
|
|
|
|
|
clone_ptr = &existing_clone;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
race_sim_.start_race(lvl, setup, clone_ptr);
|
|
|
|
|
hud_banner_ = {"", ""};
|
|
|
|
|
hud_banner_timer_ = {0.0f, 0.0f};
|
|
|
|
|
post_race_page_ = 0;
|
|
|
|
|
post_race_record_flags_ = 0;
|
2026-11-30 23:41:37 +02:00
|
|
|
in_race_session_ = true;
|
2026-11-30 22:31:51 +02:00
|
|
|
state_ = ScreenState::Racing;
|
2026-12-01 09:19:20 +02:00
|
|
|
audio_.set_pitstop_state(false, false, 1.0f);
|
2026-11-30 22:31:51 +02:00
|
|
|
|
2026-11-30 23:41:37 +02:00
|
|
|
ensure_music(static_cast<audio::MusicTrackId>(1 + (selected_track_ - 1) % 4), true, true);
|
2026-11-30 22:31:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GameApp::handle_sim_events() {
|
|
|
|
|
const auto& crafts = race_sim_.crafts();
|
|
|
|
|
Vec3 listener_pos = crafts.empty() ? Vec3(0, 0, 0) : crafts[0].curr_pose.pos;
|
|
|
|
|
Vec3 listener_right = Vec3(1, 0, 0);
|
|
|
|
|
if (!crafts.empty()) {
|
|
|
|
|
Vec3 fwd = crafts[0].forward_dir();
|
|
|
|
|
listener_right = Vec3(-fwd.z, 0.0f, fwd.x);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (const auto& ev : race_sim_.events()) {
|
|
|
|
|
if (!ev.banner_text.empty()) {
|
|
|
|
|
if (ev.target_player == -1 || ev.target_player == 0) {
|
|
|
|
|
hud_banner_[0] = ev.banner_text;
|
|
|
|
|
hud_banner_timer_[0] = 2.0f;
|
|
|
|
|
}
|
|
|
|
|
if (ev.target_player == -1 || ev.target_player == 1) {
|
|
|
|
|
hud_banner_[1] = ev.banner_text;
|
|
|
|
|
hud_banner_timer_[1] = 2.0f;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (ev.rumble_intensity > 0.05f && ev.target_player >= 0) {
|
|
|
|
|
input_.trigger_rumble(ev.target_player, ev.rumble_intensity,
|
|
|
|
|
ev.rumble_intensity * 0.7f, 160, cfg_);
|
|
|
|
|
}
|
|
|
|
|
const char* wav = nullptr;
|
|
|
|
|
float base_gain = 0.45f;
|
2026-12-01 09:19:20 +02:00
|
|
|
float pitch = 1.0f;
|
2026-11-30 22:31:51 +02:00
|
|
|
float cd_sec = 0.08f;
|
|
|
|
|
switch (ev.sound) {
|
|
|
|
|
case sim::SimSoundCue::StartBeep: wav = "START1.WAV"; base_gain = 0.50f; cd_sec = 0.15f; break;
|
|
|
|
|
case sim::SimSoundCue::StartGo: wav = "START2.WAV"; base_gain = 0.50f; cd_sec = 0.15f; break;
|
|
|
|
|
case sim::SimSoundCue::MinigunShot: {
|
|
|
|
|
wav = "MINISHOT.WAV";
|
|
|
|
|
bool is_player = (ev.target_player >= 0);
|
|
|
|
|
base_gain = is_player ? 0.30f : 0.18f;
|
|
|
|
|
cd_sec = is_player ? 0.08f : 0.11f;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case sim::SimSoundCue::MissileLaunch: wav = "MISSILE.WAV"; base_gain = 0.48f; cd_sec = 0.18f; break;
|
|
|
|
|
case sim::SimSoundCue::Explosion: wav = "EXPLODE.WAV"; base_gain = 0.60f; cd_sec = 0.10f; break;
|
|
|
|
|
case sim::SimSoundCue::Impact: wav = "HELEHIT.WAV"; base_gain = 0.42f; cd_sec = 0.14f; break;
|
|
|
|
|
case sim::SimSoundCue::Scrape: wav = "RICCO1.WAV"; base_gain = 0.24f; cd_sec = 0.16f; break;
|
|
|
|
|
case sim::SimSoundCue::Boost: wav = "BOOST.WAV"; base_gain = 0.44f; cd_sec = 0.45f; break;
|
|
|
|
|
case sim::SimSoundCue::Pickup: wav = "PICKUP.WAV"; base_gain = 0.44f; cd_sec = 0.12f; break;
|
|
|
|
|
case sim::SimSoundCue::Powerup: wav = "POWERUP.WAV"; base_gain = 0.52f; cd_sec = 0.15f; break;
|
2026-12-01 09:19:20 +02:00
|
|
|
case sim::SimSoundCue::Refuel: wav = "REFUEL.WAV"; base_gain = 0.42f; cd_sec = 0.35f; break;
|
2026-11-30 22:31:51 +02:00
|
|
|
case sim::SimSoundCue::LockOn: wav = "LOCKON4.WAV"; base_gain = 0.38f; cd_sec = 0.35f; break;
|
|
|
|
|
case sim::SimSoundCue::Warning: wav = "WARNING.WAV"; base_gain = 0.40f; cd_sec = 0.50f; break;
|
|
|
|
|
case sim::SimSoundCue::Stunt180: wav = "STUNT180.WAV"; base_gain = 0.52f; cd_sec = 0.30f; break;
|
|
|
|
|
case sim::SimSoundCue::Stunt360: wav = "STUNT360.WAV"; base_gain = 0.52f; cd_sec = 0.30f; break;
|
|
|
|
|
case sim::SimSoundCue::Stunt720: wav = "STUNT720.WAV"; base_gain = 0.52f; cd_sec = 0.30f; break;
|
|
|
|
|
case sim::SimSoundCue::SwitchTrigger: wav = "SWITCH.WAV"; base_gain = 0.45f; cd_sec = 0.30f; break;
|
2026-12-01 09:19:20 +02:00
|
|
|
case sim::SimSoundCue::PitComplete: wav = "POWERUP.WAV"; base_gain = 0.46f; pitch = 1.15f; cd_sec = 0.25f; break;
|
2026-11-30 22:31:51 +02:00
|
|
|
default: break;
|
|
|
|
|
}
|
|
|
|
|
if (wav) {
|
|
|
|
|
if (ev.pos.len_sq() < 0.01f) {
|
2026-12-01 09:19:20 +02:00
|
|
|
audio_.play_sfx(wav, base_gain, pitch, 0.0f, false, cd_sec);
|
2026-11-30 22:31:51 +02:00
|
|
|
} else {
|
2026-12-01 09:19:20 +02:00
|
|
|
audio_.play_sfx_3d(wav, ev.pos, listener_pos, listener_right, base_gain, pitch, cd_sec);
|
2026-11-30 22:31:51 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
race_sim_.clear_events();
|
|
|
|
|
|
2026-12-01 08:05:04 +02:00
|
|
|
std::vector<sim::DirtyRect> dirty_rects;
|
|
|
|
|
bool columns_dirty = false;
|
|
|
|
|
if (race_sim_.consume_world_dirty(dirty_rects, columns_dirty)) {
|
|
|
|
|
for (const auto& r : dirty_rects) {
|
|
|
|
|
world_ren_.update_terrain_region(race_sim_.level(), r.x0, r.z0, r.x1, r.z1);
|
|
|
|
|
}
|
|
|
|
|
if (columns_dirty) {
|
|
|
|
|
world_ren_.rebuild_columns(race_sim_.level());
|
|
|
|
|
}
|
2026-11-30 22:31:51 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GameApp::update_racing_step(float dt) {
|
|
|
|
|
CraftInput p1 = input_.craft_input(0, cfg_, selected_mode_ != sim::GameMode::SplitScreen);
|
|
|
|
|
CraftInput p2 = input_.craft_input(1, cfg_, false);
|
|
|
|
|
if (p1.cycle_camera_pressed) {
|
|
|
|
|
cam_mode_ = (cam_mode_ + 1) % 3;
|
|
|
|
|
}
|
2026-11-30 23:57:29 +02:00
|
|
|
if (p1.toggle_hud_pressed) {
|
|
|
|
|
hud_visible_ = !hud_visible_;
|
|
|
|
|
}
|
2026-11-30 22:31:51 +02:00
|
|
|
|
|
|
|
|
race_sim_.step(p1, p2, dt);
|
|
|
|
|
handle_sim_events();
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < 2; ++i) {
|
|
|
|
|
if (hud_banner_timer_[i] > 0.0f) {
|
|
|
|
|
hud_banner_timer_[i] = std::max(0.0f, hud_banner_timer_[i] - dt);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!race_sim_.crafts().empty()) {
|
|
|
|
|
const auto& c0 = race_sim_.crafts()[0];
|
|
|
|
|
const auto& sp = sim::kVehicleSpecs[std::clamp(c0.vehicle_idx, 0, 5)];
|
|
|
|
|
float spd_ratio = c0.speed_horizontal() / sp.top_speed;
|
|
|
|
|
audio_.set_engine_state(c0.recovery_state == sim::RecoveryState::Active,
|
|
|
|
|
spd_ratio, c0.boost_timer > 0.05f, c0.scrape_intensity);
|
|
|
|
|
}
|
2026-12-01 09:19:20 +02:00
|
|
|
bool any_pit = false;
|
|
|
|
|
bool any_charging = false;
|
|
|
|
|
float fill_ratio = 1.0f;
|
|
|
|
|
for (const auto& c : race_sim_.crafts()) {
|
|
|
|
|
if (!c.is_human || c.recovery_state != sim::RecoveryState::Active) continue;
|
|
|
|
|
if (c.on_pit_mask != 0) {
|
|
|
|
|
any_pit = true;
|
|
|
|
|
}
|
|
|
|
|
if (c.active_recharge_mask != 0) {
|
|
|
|
|
any_charging = true;
|
|
|
|
|
fill_ratio = std::min(fill_ratio, c.pit_fill_ratio);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
audio_.set_pitstop_state(any_pit, any_charging, fill_ratio);
|
2026-11-30 22:31:51 +02:00
|
|
|
|
|
|
|
|
if (race_sim_.race_finished()) {
|
|
|
|
|
audio_.set_engine_state(false, 0.0f, false, 0.0f);
|
2026-12-01 09:19:20 +02:00
|
|
|
audio_.set_pitstop_state(false, false, 1.0f);
|
2026-11-30 22:31:51 +02:00
|
|
|
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) {
|
2026-12-01 08:33:48 +02:00
|
|
|
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());
|
|
|
|
|
}
|
2026-11-30 22:31:51 +02:00
|
|
|
}
|
|
|
|
|
if (selected_mode_ == sim::GameMode::Championship) {
|
|
|
|
|
champ_.record_race_results(race_sim_.crafts());
|
|
|
|
|
}
|
|
|
|
|
save_all_user_data();
|
|
|
|
|
enter_state(ScreenState::PostRace);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GameApp::update_track_viewer(float dt) {
|
|
|
|
|
const uint8_t* ks = SDL_GetKeyboardState(nullptr);
|
|
|
|
|
float spd = (ks[SDL_SCANCODE_LSHIFT] ? 32.0f : 14.0f) * dt;
|
|
|
|
|
if (ks[SDL_SCANCODE_LEFT]) viewer_yaw_ += 1.8f * dt;
|
|
|
|
|
if (ks[SDL_SCANCODE_RIGHT]) viewer_yaw_ -= 1.8f * dt;
|
|
|
|
|
if (ks[SDL_SCANCODE_UP]) viewer_pitch_ = std::min(1.1f, viewer_pitch_ + 1.2f * dt);
|
|
|
|
|
if (ks[SDL_SCANCODE_DOWN]) viewer_pitch_ = std::max(-1.1f, viewer_pitch_ - 1.2f * dt);
|
|
|
|
|
|
|
|
|
|
Vec3 fwd(std::sin(viewer_yaw_), 0.0f, std::cos(viewer_yaw_));
|
|
|
|
|
Vec3 right(-fwd.z, 0.0f, fwd.x);
|
|
|
|
|
if (ks[SDL_SCANCODE_W]) viewer_pos_ += fwd * spd;
|
|
|
|
|
if (ks[SDL_SCANCODE_S]) viewer_pos_ -= fwd * spd;
|
|
|
|
|
if (ks[SDL_SCANCODE_A]) viewer_pos_ -= right * spd;
|
|
|
|
|
if (ks[SDL_SCANCODE_D]) viewer_pos_ += right * spd;
|
|
|
|
|
if (ks[SDL_SCANCODE_SPACE] || ks[SDL_SCANCODE_E]) viewer_pos_.y += spd;
|
|
|
|
|
if (ks[SDL_SCANCODE_C] || ks[SDL_SCANCODE_Q]) viewer_pos_.y -= spd;
|
|
|
|
|
|
|
|
|
|
viewer_pos_.x = std::clamp(viewer_pos_.x, 1.0f, static_cast<float>(assets::kMapWidth - 2));
|
|
|
|
|
viewer_pos_.z = std::clamp(viewer_pos_.z, 1.0f, static_cast<float>(assets::kMapHeight - 2));
|
|
|
|
|
viewer_pos_.y = std::clamp(viewer_pos_.y, -3.0f, 35.0f);
|
|
|
|
|
|
|
|
|
|
if (input_.menu_input().back) {
|
|
|
|
|
enter_state(ScreenState::MainMenu);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GameApp::update_menu(float dt) {
|
|
|
|
|
ui_time_ += dt;
|
|
|
|
|
if (status_toast_timer_ > 0.0f) {
|
|
|
|
|
status_toast_timer_ = std::max(0.0f, status_toast_timer_ - dt);
|
|
|
|
|
}
|
|
|
|
|
const MenuInput& m = input_.menu_input();
|
|
|
|
|
|
|
|
|
|
if (state_ == ScreenState::Intro) {
|
|
|
|
|
intro_accum_ += dt * flic_.fps();
|
|
|
|
|
while (intro_accum_ >= 1.0) {
|
|
|
|
|
intro_accum_ -= 1.0;
|
|
|
|
|
if (!flic_.step_frame()) {
|
|
|
|
|
enter_state(ScreenState::Title);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
ui_ren_.update_stream_rgba(flic_.width(), flic_.height(), flic_.rgba().data());
|
|
|
|
|
if (!intro_turbo_played_ && flic_.current_frame() >= 60) {
|
|
|
|
|
intro_turbo_played_ = true;
|
|
|
|
|
audio_.play_sfx("TURBO.WAV", 0.55f, 1.0f, 0.0f, true);
|
|
|
|
|
}
|
|
|
|
|
if (!intro_explode_played_ && flic_.current_frame() >= 250) {
|
|
|
|
|
intro_explode_played_ = true;
|
|
|
|
|
audio_.play_sfx("EXPLODE.WAV", 0.55f, 1.0f, 0.0f, true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (m.any_pressed) {
|
|
|
|
|
audio_.play_sfx("SELECT.WAV", 0.38f);
|
|
|
|
|
enter_state(ScreenState::Title);
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (state_ == ScreenState::Title) {
|
|
|
|
|
if (m.confirm || m.any_pressed) {
|
|
|
|
|
audio_.play_sfx("SELECT.WAV", 0.38f);
|
|
|
|
|
enter_state(ScreenState::MainMenu);
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (state_ == ScreenState::MainMenu) {
|
|
|
|
|
constexpr int kItems = 9;
|
|
|
|
|
if (m.up) { menu_cursor_ = (menu_cursor_ + kItems - 1) % kItems; audio_.play_sfx("CHANGE.WAV", 0.32f); }
|
|
|
|
|
if (m.down) { menu_cursor_ = (menu_cursor_ + 1) % kItems; audio_.play_sfx("CHANGE.WAV", 0.32f); }
|
|
|
|
|
if (m.confirm) {
|
|
|
|
|
audio_.play_sfx("SELECT.WAV", 0.38f);
|
|
|
|
|
switch (menu_cursor_) {
|
|
|
|
|
case 0: selected_mode_ = sim::GameMode::SingleRace; enter_state(ScreenState::TrackSelect); break;
|
|
|
|
|
case 1: selected_mode_ = sim::GameMode::DeathMatch; enter_state(ScreenState::TrackSelect); break;
|
|
|
|
|
case 2: selected_mode_ = sim::GameMode::CloneRace; enter_state(ScreenState::TrackSelect); break;
|
|
|
|
|
case 3: selected_mode_ = sim::GameMode::Championship; enter_state(ScreenState::ChampionshipMenu); break;
|
|
|
|
|
case 4: selected_mode_ = sim::GameMode::SplitScreen; enter_state(ScreenState::TrackSelect); break;
|
|
|
|
|
case 5: enter_track_viewer(selected_track_); break;
|
|
|
|
|
case 6: enter_state(ScreenState::Highscores); break;
|
|
|
|
|
case 7: opt_tab_ = OptionsTab::Video; enter_state(ScreenState::Options); break;
|
|
|
|
|
case 8: running_ = false; break;
|
|
|
|
|
}
|
|
|
|
|
} else if (m.back) {
|
|
|
|
|
enter_state(ScreenState::Title);
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (state_ == ScreenState::ChampionshipMenu) {
|
2026-11-30 23:57:29 +02:00
|
|
|
constexpr int kItems = 6;
|
2026-11-30 22:31:51 +02:00
|
|
|
if (m.up) { menu_cursor_ = (menu_cursor_ + kItems - 1) % kItems; audio_.play_sfx("CHANGE.WAV", 0.32f); }
|
|
|
|
|
if (m.down) { menu_cursor_ = (menu_cursor_ + 1) % kItems; audio_.play_sfx("CHANGE.WAV", 0.32f); }
|
2026-11-30 23:57:29 +02:00
|
|
|
if (menu_cursor_ == 1 && (m.left || m.right)) {
|
|
|
|
|
int dir = m.right ? 1 : -1;
|
|
|
|
|
selected_difficulty_ = (selected_difficulty_ + dir + 3) % 3;
|
|
|
|
|
cfg_.difficulty = selected_difficulty_;
|
|
|
|
|
audio_.play_sfx("CHANGE.WAV", 0.32f);
|
|
|
|
|
} else if (menu_cursor_ == 3 || menu_cursor_ == 4) {
|
2026-11-30 22:31:51 +02:00
|
|
|
if (m.left) { champ_slot_cursor_ = (champ_slot_cursor_ + 3) % 4; audio_.play_sfx("CHANGE.WAV", 0.32f); }
|
|
|
|
|
if (m.right) { champ_slot_cursor_ = (champ_slot_cursor_ + 1) % 4; audio_.play_sfx("CHANGE.WAV", 0.32f); }
|
|
|
|
|
}
|
|
|
|
|
if (m.confirm) {
|
|
|
|
|
audio_.play_sfx("SELECT.WAV", 0.38f);
|
|
|
|
|
if (menu_cursor_ == 0) {
|
|
|
|
|
champ_.start_new(cfg_.player_name, p1_veh_, p1_team_, selected_difficulty_);
|
|
|
|
|
selected_track_ = 1;
|
|
|
|
|
enter_state(ScreenState::VehicleSelect);
|
2026-11-30 23:57:29 +02:00
|
|
|
} else if (menu_cursor_ == 2) {
|
2026-11-30 22:31:51 +02:00
|
|
|
if (!champ_.active || champ_.is_complete()) {
|
|
|
|
|
champ_.start_new(cfg_.player_name, p1_veh_, p1_team_, selected_difficulty_);
|
|
|
|
|
}
|
|
|
|
|
selected_track_ = std::clamp(champ_.current_track, 1, 6);
|
|
|
|
|
start_race_session();
|
2026-11-30 23:57:29 +02:00
|
|
|
} else if (menu_cursor_ == 3) {
|
2026-11-30 22:31:51 +02:00
|
|
|
if (champ_.load_slot(vfs_.pref_dir(), champ_slot_cursor_)) {
|
|
|
|
|
selected_track_ = std::clamp(champ_.current_track, 1, 6);
|
2026-11-30 23:57:29 +02:00
|
|
|
selected_difficulty_ = std::clamp(champ_.difficulty, 0, 2);
|
|
|
|
|
cfg_.difficulty = selected_difficulty_;
|
2026-11-30 22:31:51 +02:00
|
|
|
status_toast_ = "LOADED SLOT " + std::to_string(champ_slot_cursor_ + 1);
|
|
|
|
|
status_toast_timer_ = 2.0f;
|
|
|
|
|
}
|
2026-11-30 23:57:29 +02:00
|
|
|
} else if (menu_cursor_ == 4) {
|
2026-11-30 22:31:51 +02:00
|
|
|
if (champ_.save_slot(vfs_.pref_dir(), champ_slot_cursor_)) {
|
|
|
|
|
status_toast_ = "SAVED SLOT " + std::to_string(champ_slot_cursor_ + 1);
|
|
|
|
|
status_toast_timer_ = 2.0f;
|
|
|
|
|
}
|
2026-11-30 23:57:29 +02:00
|
|
|
} else if (menu_cursor_ == 5) {
|
2026-11-30 22:31:51 +02:00
|
|
|
enter_state(ScreenState::MainMenu);
|
|
|
|
|
}
|
|
|
|
|
} else if (m.back) {
|
|
|
|
|
enter_state(ScreenState::MainMenu);
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (state_ == ScreenState::TrackSelect) {
|
2026-11-30 23:57:29 +02:00
|
|
|
constexpr int kRows = 5; // Track, Laps/Kill Limit, Difficulty, Opponents, Proceed
|
2026-11-30 22:31:51 +02:00
|
|
|
if (m.up) { menu_cursor_ = (menu_cursor_ + kRows - 1) % kRows; audio_.play_sfx("CHANGE.WAV", 0.32f); }
|
|
|
|
|
if (m.down) { menu_cursor_ = (menu_cursor_ + 1) % kRows; audio_.play_sfx("CHANGE.WAV", 0.32f); }
|
|
|
|
|
int dir = m.right ? 1 : (m.left ? -1 : 0);
|
|
|
|
|
if (dir != 0) {
|
|
|
|
|
audio_.play_sfx("CHANGE.WAV", 0.32f);
|
2026-11-30 23:57:29 +02:00
|
|
|
if (menu_cursor_ == 0) {
|
|
|
|
|
selected_track_ = ((selected_track_ - 1 + dir + 6) % 6) + 1;
|
|
|
|
|
} else if (menu_cursor_ == 1) {
|
|
|
|
|
if (selected_mode_ == sim::GameMode::DeathMatch) {
|
|
|
|
|
cfg_.deathmatch_kill_limit = std::clamp(cfg_.deathmatch_kill_limit + dir, 3, 20);
|
|
|
|
|
} else {
|
|
|
|
|
selected_laps_ = std::clamp(selected_laps_ + dir, 1, 20);
|
|
|
|
|
cfg_.default_laps = selected_laps_;
|
|
|
|
|
}
|
|
|
|
|
} else if (menu_cursor_ == 2) {
|
|
|
|
|
selected_difficulty_ = (selected_difficulty_ + dir + 3) % 3;
|
|
|
|
|
cfg_.difficulty = selected_difficulty_;
|
|
|
|
|
} else if (menu_cursor_ == 3 && selected_mode_ != sim::GameMode::CloneRace) {
|
|
|
|
|
selected_opponents_ = std::clamp(selected_opponents_ + dir, 0, 7);
|
|
|
|
|
}
|
2026-11-30 22:31:51 +02:00
|
|
|
}
|
|
|
|
|
if (m.confirm && (menu_cursor_ == 4 || menu_cursor_ == 0)) {
|
|
|
|
|
audio_.play_sfx("SELECT.WAV", 0.38f);
|
|
|
|
|
enter_state(ScreenState::VehicleSelect);
|
|
|
|
|
} else if (m.back) {
|
|
|
|
|
enter_state(ScreenState::MainMenu);
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (state_ == ScreenState::VehicleSelect) {
|
2026-11-30 23:57:29 +02:00
|
|
|
if (editing_name_target_ != 0) {
|
2026-11-30 23:41:37 +02:00
|
|
|
update_name_edit();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2026-11-30 23:57:29 +02:00
|
|
|
bool is_split = (selected_mode_ == sim::GameMode::SplitScreen);
|
|
|
|
|
int max_rows = is_split ? 7 : 4;
|
2026-11-30 22:31:51 +02:00
|
|
|
if (m.up) { menu_cursor_ = (menu_cursor_ + max_rows - 1) % max_rows; audio_.play_sfx("CHANGE.WAV", 0.32f); }
|
|
|
|
|
if (m.down) { menu_cursor_ = (menu_cursor_ + 1) % max_rows; audio_.play_sfx("CHANGE.WAV", 0.32f); }
|
|
|
|
|
int dir = m.right ? 1 : (m.left ? -1 : 0);
|
|
|
|
|
if (dir != 0) {
|
|
|
|
|
audio_.play_sfx("CHANGE.WAV", 0.32f);
|
2026-11-30 23:41:37 +02:00
|
|
|
if (menu_cursor_ == 1) p1_veh_ = (p1_veh_ + dir + 6) % 6;
|
|
|
|
|
else if (menu_cursor_ == 2) p1_team_ = (p1_team_ + dir + 8) % 8;
|
2026-11-30 23:57:29 +02:00
|
|
|
else if (is_split && menu_cursor_ == 4) p2_veh_ = (p2_veh_ + dir + 6) % 6;
|
|
|
|
|
else if (is_split && menu_cursor_ == 5) p2_team_ = (p2_team_ + dir + 8) % 8;
|
2026-11-30 22:31:51 +02:00
|
|
|
}
|
2026-11-30 23:41:37 +02:00
|
|
|
if (menu_cursor_ == 0 && m.confirm) {
|
2026-11-30 23:57:29 +02:00
|
|
|
begin_name_edit(1);
|
|
|
|
|
} else if (is_split && menu_cursor_ == 3 && m.confirm) {
|
|
|
|
|
begin_name_edit(2);
|
2026-11-30 23:41:37 +02:00
|
|
|
} else if (m.confirm && (menu_cursor_ == max_rows - 1 || menu_cursor_ == 1)) {
|
2026-11-30 22:31:51 +02:00
|
|
|
audio_.play_sfx("SELECT.WAV", 0.38f);
|
|
|
|
|
if (selected_mode_ == sim::GameMode::Championship) {
|
2026-11-30 23:41:37 +02:00
|
|
|
champ_.player_name = cfg_.player_name;
|
2026-11-30 22:31:51 +02:00
|
|
|
champ_.player_vehicle = p1_veh_;
|
|
|
|
|
champ_.player_team = p1_team_;
|
2026-11-30 23:41:37 +02:00
|
|
|
champ_.drivers[0].name = cfg_.player_name;
|
2026-11-30 22:31:51 +02:00
|
|
|
champ_.drivers[0].vehicle_idx = p1_veh_;
|
|
|
|
|
champ_.drivers[0].team_idx = p1_team_;
|
|
|
|
|
}
|
|
|
|
|
start_race_session();
|
|
|
|
|
} else if (m.back) {
|
|
|
|
|
enter_state(selected_mode_ == sim::GameMode::Championship
|
|
|
|
|
? ScreenState::ChampionshipMenu
|
|
|
|
|
: ScreenState::TrackSelect);
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (state_ == ScreenState::Highscores) {
|
|
|
|
|
if (m.confirm) {
|
|
|
|
|
hiscores_.clear();
|
|
|
|
|
hiscores_.save(vfs_.pref_dir() / "hiscores.dat");
|
|
|
|
|
audio_.play_sfx("SELECT.WAV", 0.38f);
|
|
|
|
|
status_toast_ = "HISCORES CLEARED";
|
|
|
|
|
status_toast_timer_ = 2.0f;
|
|
|
|
|
} else if (m.back) {
|
|
|
|
|
enter_state(ScreenState::MainMenu);
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (state_ == ScreenState::Options) {
|
2026-11-30 23:57:29 +02:00
|
|
|
if (editing_name_target_ != 0) {
|
2026-11-30 23:41:37 +02:00
|
|
|
update_name_edit();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2026-11-30 22:31:51 +02:00
|
|
|
if (rebind_slot_ >= 0) {
|
|
|
|
|
int new_sc = 0;
|
|
|
|
|
if (input_.consume_rebound_scancode(new_sc)) {
|
2026-11-30 23:57:29 +02:00
|
|
|
int* targets[17] = {
|
2026-11-30 22:31:51 +02:00
|
|
|
&cfg_.keys.steer_left, &cfg_.keys.steer_right, &cfg_.keys.accelerate,
|
|
|
|
|
&cfg_.keys.brake, &cfg_.keys.boost, &cfg_.keys.fire_minigun,
|
2026-11-30 23:57:29 +02:00
|
|
|
&cfg_.keys.fire_missile, &cfg_.keys.autopilot, &cfg_.keys.camera_view,
|
|
|
|
|
&cfg_.keys.hud_toggle,
|
|
|
|
|
&cfg_.keys.p2_steer_left, &cfg_.keys.p2_steer_right, &cfg_.keys.p2_accelerate,
|
|
|
|
|
&cfg_.keys.p2_brake, &cfg_.keys.p2_boost, &cfg_.keys.p2_fire_minigun,
|
|
|
|
|
&cfg_.keys.p2_fire_missile
|
2026-11-30 22:31:51 +02:00
|
|
|
};
|
2026-11-30 23:57:29 +02:00
|
|
|
if (rebind_slot_ < 17) *targets[rebind_slot_] = new_sc;
|
2026-11-30 22:31:51 +02:00
|
|
|
rebind_slot_ = -1;
|
|
|
|
|
audio_.play_sfx("SELECT.WAV", 0.38f);
|
|
|
|
|
cfg_.save(vfs_.pref_dir() / "config.ini");
|
|
|
|
|
} else if (!input_.is_rebinding()) {
|
|
|
|
|
rebind_slot_ = -1;
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-30 23:57:29 +02:00
|
|
|
constexpr int kNumTabs = 7;
|
|
|
|
|
const int row_counts[kNumTabs] = {10, 7, 11, 8, 8, 8, 9};
|
2026-11-30 22:31:51 +02:00
|
|
|
int rows = row_counts[static_cast<int>(opt_tab_)];
|
|
|
|
|
if (m.up) { menu_cursor_ = (menu_cursor_ + rows - 1) % rows; audio_.play_sfx("CHANGE.WAV", 0.32f); }
|
|
|
|
|
if (m.down) { menu_cursor_ = (menu_cursor_ + 1) % rows; audio_.play_sfx("CHANGE.WAV", 0.32f); }
|
|
|
|
|
|
|
|
|
|
int dir = m.right ? 1 : (m.left ? -1 : 0);
|
|
|
|
|
if (menu_cursor_ == 0 && dir != 0) {
|
2026-11-30 23:57:29 +02:00
|
|
|
opt_tab_ = static_cast<OptionsTab>((static_cast<int>(opt_tab_) + dir + kNumTabs) % kNumTabs);
|
2026-11-30 22:31:51 +02:00
|
|
|
audio_.play_sfx("CHANGE.WAV", 0.32f);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (opt_tab_ == OptionsTab::Video && (dir != 0 || m.confirm)) {
|
|
|
|
|
audio_.play_sfx("CHANGE.WAV", 0.32f);
|
|
|
|
|
if (menu_cursor_ == 1) {
|
|
|
|
|
static constexpr int kRes[4][2] = {{1280, 720}, {1600, 900}, {1920, 1080}, {800, 600}};
|
|
|
|
|
int cur = 0;
|
|
|
|
|
for (int i = 0; i < 4; ++i) {
|
|
|
|
|
if (cfg_.window_width == kRes[i][0]) cur = i;
|
|
|
|
|
}
|
|
|
|
|
cur = (cur + (dir != 0 ? dir : 1) + 4) % 4;
|
|
|
|
|
cfg_.window_width = kRes[cur][0];
|
|
|
|
|
cfg_.window_height = kRes[cur][1];
|
|
|
|
|
apply_video_settings();
|
|
|
|
|
} else if (menu_cursor_ == 2) {
|
|
|
|
|
cfg_.fullscreen = !cfg_.fullscreen;
|
|
|
|
|
apply_video_settings();
|
|
|
|
|
} else if (menu_cursor_ == 3) {
|
|
|
|
|
cfg_.vsync = !cfg_.vsync;
|
|
|
|
|
apply_video_settings();
|
2026-11-30 23:57:29 +02:00
|
|
|
} else if (menu_cursor_ == 4) {
|
|
|
|
|
static constexpr int kMsaa[4] = {0, 2, 4, 8};
|
|
|
|
|
int cur = 2;
|
|
|
|
|
for (int i = 0; i < 4; ++i) {
|
|
|
|
|
if (cfg_.msaa_samples == kMsaa[i]) cur = i;
|
|
|
|
|
}
|
|
|
|
|
cur = (cur + (dir != 0 ? dir : 1) + 4) % 4;
|
|
|
|
|
cfg_.msaa_samples = kMsaa[cur];
|
|
|
|
|
status_toast_ = "MSAA APPLIES ON NEXT LAUNCH";
|
|
|
|
|
status_toast_timer_ = 2.0f;
|
|
|
|
|
} else if (menu_cursor_ == 5 && dir != 0) {
|
|
|
|
|
cfg_.fov_deg = std::clamp(cfg_.fov_deg + dir * 5.0f, 50.0f, 105.0f);
|
|
|
|
|
} else if (menu_cursor_ == 6 && dir != 0) {
|
2026-11-30 22:31:51 +02:00
|
|
|
cfg_.draw_distance = std::clamp(cfg_.draw_distance + dir * 10.0f, 30.0f, 150.0f);
|
2026-11-30 23:57:29 +02:00
|
|
|
} else if (menu_cursor_ == 7) {
|
2026-11-30 22:31:51 +02:00
|
|
|
cfg_.texture_filter = (cfg_.texture_filter == TextureFilterMode::Linear)
|
|
|
|
|
? TextureFilterMode::Nearest
|
|
|
|
|
: TextureFilterMode::Linear;
|
2026-11-30 23:57:29 +02:00
|
|
|
} else if (menu_cursor_ == 8) {
|
2026-11-30 22:31:51 +02:00
|
|
|
if (!cfg_.classic_mode) { cfg_.classic_mode = true; cfg_.classic_hires = false; }
|
|
|
|
|
else if (!cfg_.classic_hires) { cfg_.classic_hires = true; }
|
|
|
|
|
else { cfg_.classic_mode = false; }
|
2026-11-30 23:57:29 +02:00
|
|
|
} else if (menu_cursor_ == 9) {
|
|
|
|
|
cfg_.classic_scanlines = !cfg_.classic_scanlines;
|
2026-11-30 22:31:51 +02:00
|
|
|
}
|
|
|
|
|
} else if (opt_tab_ == OptionsTab::Audio && (dir != 0 || m.confirm)) {
|
|
|
|
|
audio_.play_sfx("CHANGE.WAV", 0.32f);
|
|
|
|
|
if (menu_cursor_ == 1) {
|
|
|
|
|
int b = (static_cast<int>(cfg_.music_backend) + (dir != 0 ? dir : 1) + 3) % 3;
|
|
|
|
|
cfg_.music_backend = static_cast<MusicBackend>(b);
|
|
|
|
|
} else if (menu_cursor_ == 2 && dir != 0) {
|
|
|
|
|
cfg_.master_volume = std::clamp(cfg_.master_volume + dir * 0.1f, 0.0f, 1.0f);
|
|
|
|
|
} else if (menu_cursor_ == 3 && dir != 0) {
|
|
|
|
|
cfg_.sfx_volume = std::clamp(cfg_.sfx_volume + dir * 0.1f, 0.0f, 1.0f);
|
|
|
|
|
} else if (menu_cursor_ == 4 && dir != 0) {
|
|
|
|
|
cfg_.music_volume = std::clamp(cfg_.music_volume + dir * 0.1f, 0.0f, 1.0f);
|
2026-11-30 23:57:29 +02:00
|
|
|
} else if (menu_cursor_ == 5) {
|
|
|
|
|
cfg_.mute_on_focus_loss = !cfg_.mute_on_focus_loss;
|
|
|
|
|
} else if (menu_cursor_ == 6 && available_soundfonts_.size() > 1) {
|
|
|
|
|
auto it = std::find(available_soundfonts_.begin(), available_soundfonts_.end(),
|
|
|
|
|
cfg_.custom_soundfont_path);
|
|
|
|
|
int idx = (it == available_soundfonts_.end())
|
|
|
|
|
? 0
|
|
|
|
|
: static_cast<int>(it - available_soundfonts_.begin());
|
|
|
|
|
int n = static_cast<int>(available_soundfonts_.size());
|
|
|
|
|
idx = (idx + (dir != 0 ? dir : 1) + n) % n;
|
|
|
|
|
cfg_.custom_soundfont_path = available_soundfonts_[idx];
|
2026-11-30 22:31:51 +02:00
|
|
|
}
|
|
|
|
|
audio_.apply_config(cfg_, window_focused_);
|
2026-11-30 23:57:29 +02:00
|
|
|
} else if (opt_tab_ == OptionsTab::ControlsP1) {
|
|
|
|
|
if (menu_cursor_ >= 1 && menu_cursor_ <= 10 && m.confirm) {
|
2026-11-30 22:31:51 +02:00
|
|
|
rebind_slot_ = menu_cursor_ - 1;
|
|
|
|
|
input_.start_rebind();
|
|
|
|
|
audio_.play_sfx("SELECT.WAV", 0.38f);
|
2026-11-30 23:57:29 +02:00
|
|
|
}
|
|
|
|
|
} else if (opt_tab_ == OptionsTab::ControlsP2) {
|
|
|
|
|
if (menu_cursor_ >= 1 && menu_cursor_ <= 7 && m.confirm) {
|
|
|
|
|
rebind_slot_ = 10 + (menu_cursor_ - 1);
|
|
|
|
|
input_.start_rebind();
|
|
|
|
|
audio_.play_sfx("SELECT.WAV", 0.38f);
|
|
|
|
|
}
|
|
|
|
|
} else if (opt_tab_ == OptionsTab::InputPad && (dir != 0 || m.confirm)) {
|
|
|
|
|
audio_.play_sfx("CHANGE.WAV", 0.32f);
|
|
|
|
|
if (menu_cursor_ == 1) {
|
|
|
|
|
int step = (dir != 0) ? dir : 1;
|
|
|
|
|
cfg_.p1_gamepad_index = ((cfg_.p1_gamepad_index + 1 + step + 5) % 5) - 1;
|
|
|
|
|
} else if (menu_cursor_ == 2) {
|
|
|
|
|
int step = (dir != 0) ? dir : 1;
|
|
|
|
|
cfg_.p2_gamepad_index = ((cfg_.p2_gamepad_index + 1 + step + 5) % 5) - 1;
|
|
|
|
|
} else if (menu_cursor_ == 3 && dir != 0) {
|
2026-11-30 22:31:51 +02:00
|
|
|
cfg_.gamepad_deadzone = std::clamp(cfg_.gamepad_deadzone + dir * 0.02f, 0.0f, 0.4f);
|
2026-11-30 23:57:29 +02:00
|
|
|
} else if (menu_cursor_ == 4 && dir != 0) {
|
|
|
|
|
cfg_.steering_sensitivity = std::clamp(cfg_.steering_sensitivity + dir * 0.1f, 0.25f, 3.0f);
|
|
|
|
|
} else if (menu_cursor_ == 5 && dir != 0) {
|
|
|
|
|
cfg_.steering_curve = std::clamp(cfg_.steering_curve + dir * 0.1f, 0.5f, 3.0f);
|
|
|
|
|
} else if (menu_cursor_ == 6) {
|
2026-11-30 22:31:51 +02:00
|
|
|
cfg_.rumble_enabled = !cfg_.rumble_enabled;
|
2026-11-30 23:57:29 +02:00
|
|
|
} else if (menu_cursor_ == 7) {
|
2026-11-30 22:31:51 +02:00
|
|
|
cfg_.mouse_steering = !cfg_.mouse_steering;
|
|
|
|
|
}
|
2026-11-30 23:41:37 +02:00
|
|
|
} else if (opt_tab_ == OptionsTab::Game) {
|
|
|
|
|
if (menu_cursor_ == 1 && m.confirm) {
|
2026-11-30 23:57:29 +02:00
|
|
|
begin_name_edit(1);
|
|
|
|
|
return;
|
|
|
|
|
} else if (menu_cursor_ == 2 && m.confirm) {
|
|
|
|
|
begin_name_edit(2);
|
2026-11-30 23:41:37 +02:00
|
|
|
return;
|
|
|
|
|
} else if (dir != 0 || m.confirm) {
|
|
|
|
|
audio_.play_sfx("CHANGE.WAV", 0.32f);
|
2026-11-30 23:57:29 +02:00
|
|
|
if (menu_cursor_ == 3) {
|
2026-11-30 23:41:37 +02:00
|
|
|
int l = (static_cast<int>(cfg_.language) + (dir != 0 ? dir : 1) + 4) % 4;
|
|
|
|
|
cfg_.language = static_cast<Language>(l);
|
|
|
|
|
} else if (menu_cursor_ == 4) {
|
2026-11-30 23:57:29 +02:00
|
|
|
cfg_.default_camera = (cfg_.default_camera + (dir != 0 ? dir : 1) + 3) % 3;
|
|
|
|
|
cam_mode_ = cfg_.default_camera;
|
|
|
|
|
} else if (menu_cursor_ == 5) {
|
|
|
|
|
cfg_.show_hud = !cfg_.show_hud;
|
|
|
|
|
hud_visible_ = cfg_.show_hud;
|
|
|
|
|
} else if (menu_cursor_ == 6) {
|
|
|
|
|
cfg_.show_minimap = !cfg_.show_minimap;
|
|
|
|
|
} else if (menu_cursor_ == 7) {
|
|
|
|
|
cfg_.skip_intro = !cfg_.skip_intro;
|
2026-11-30 23:41:37 +02:00
|
|
|
}
|
2026-11-30 22:31:51 +02:00
|
|
|
}
|
2026-11-30 23:57:29 +02:00
|
|
|
} else if (opt_tab_ == OptionsTab::Rules && (dir != 0 || m.confirm)) {
|
|
|
|
|
audio_.play_sfx("CHANGE.WAV", 0.32f);
|
|
|
|
|
if (menu_cursor_ == 1) {
|
|
|
|
|
cfg_.difficulty = (cfg_.difficulty + (dir != 0 ? dir : 1) + 3) % 3;
|
|
|
|
|
selected_difficulty_ = cfg_.difficulty;
|
|
|
|
|
} else if (menu_cursor_ == 2 && dir != 0) {
|
|
|
|
|
cfg_.default_laps = std::clamp(cfg_.default_laps + dir, 1, 20);
|
|
|
|
|
selected_laps_ = cfg_.default_laps;
|
|
|
|
|
} else if (menu_cursor_ == 3 && dir != 0) {
|
|
|
|
|
cfg_.deathmatch_kill_limit = std::clamp(cfg_.deathmatch_kill_limit + dir, 3, 20);
|
|
|
|
|
} else if (menu_cursor_ == 4) {
|
|
|
|
|
cfg_.fuel_enabled = !cfg_.fuel_enabled;
|
|
|
|
|
} else if (menu_cursor_ == 5) {
|
|
|
|
|
cfg_.damage_enabled = !cfg_.damage_enabled;
|
|
|
|
|
} else if (menu_cursor_ == 6) {
|
|
|
|
|
cfg_.weapons_enabled = !cfg_.weapons_enabled;
|
|
|
|
|
} else if (menu_cursor_ == 7) {
|
|
|
|
|
cfg_.pickups_enabled = !cfg_.pickups_enabled;
|
|
|
|
|
} else if (menu_cursor_ == 8) {
|
|
|
|
|
cfg_.track_morphing_enabled = !cfg_.track_morphing_enabled;
|
|
|
|
|
}
|
2026-11-30 22:31:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (m.back) {
|
|
|
|
|
cfg_.save(vfs_.pref_dir() / "config.ini");
|
|
|
|
|
audio_.play_sfx("SELECT.WAV", 0.38f);
|
2026-11-30 23:41:37 +02:00
|
|
|
enter_state(in_race_session_ ? ScreenState::Paused : ScreenState::MainMenu);
|
2026-11-30 22:31:51 +02:00
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (state_ == ScreenState::Paused) {
|
|
|
|
|
constexpr int kItems = 4;
|
|
|
|
|
if (m.up) { menu_cursor_ = (menu_cursor_ + kItems - 1) % kItems; audio_.play_sfx("CHANGE.WAV", 0.32f); }
|
|
|
|
|
if (m.down) { menu_cursor_ = (menu_cursor_ + 1) % kItems; audio_.play_sfx("CHANGE.WAV", 0.32f); }
|
|
|
|
|
if (m.pause || m.back) {
|
|
|
|
|
state_ = ScreenState::Racing;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (m.confirm) {
|
|
|
|
|
audio_.play_sfx("SELECT.WAV", 0.38f);
|
|
|
|
|
if (menu_cursor_ == 0) state_ = ScreenState::Racing;
|
|
|
|
|
else if (menu_cursor_ == 1) start_race_session();
|
|
|
|
|
else if (menu_cursor_ == 2) { opt_tab_ = OptionsTab::Video; enter_state(ScreenState::Options); }
|
|
|
|
|
else enter_state(ScreenState::MainMenu);
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (state_ == ScreenState::PostRace) {
|
|
|
|
|
if (m.left || m.right) {
|
|
|
|
|
post_race_page_ = (post_race_page_ + 1) % (selected_mode_ == sim::GameMode::Championship ? 3 : 2);
|
|
|
|
|
audio_.play_sfx("CHANGE.WAV", 0.32f);
|
|
|
|
|
}
|
|
|
|
|
if (m.confirm || m.back) {
|
|
|
|
|
audio_.play_sfx("SELECT.WAV", 0.38f);
|
|
|
|
|
if (selected_mode_ == sim::GameMode::Championship && !champ_.is_complete()) {
|
|
|
|
|
selected_track_ = champ_.current_track;
|
|
|
|
|
start_race_session();
|
|
|
|
|
} else {
|
|
|
|
|
enter_state(ScreenState::MainMenu);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int GameApp::run() {
|
|
|
|
|
int smoke_left = opts_.smoke_test_frames;
|
|
|
|
|
while (running_) {
|
|
|
|
|
input_.begin_frame();
|
|
|
|
|
SDL_Event ev;
|
|
|
|
|
bool want_quit = false;
|
|
|
|
|
bool want_fs = false;
|
|
|
|
|
while (SDL_PollEvent(&ev)) {
|
|
|
|
|
if (ev.type == SDL_WINDOWEVENT) {
|
|
|
|
|
if (ev.window.event == SDL_WINDOWEVENT_SIZE_CHANGED ||
|
|
|
|
|
ev.window.event == SDL_WINDOWEVENT_RESIZED) {
|
|
|
|
|
SDL_GL_GetDrawableSize(window_, &win_w_, &win_h_);
|
|
|
|
|
} else if (ev.window.event == SDL_WINDOWEVENT_FOCUS_LOST) {
|
|
|
|
|
window_focused_ = false;
|
|
|
|
|
audio_.apply_config(cfg_, false);
|
|
|
|
|
} else if (ev.window.event == SDL_WINDOWEVENT_FOCUS_GAINED) {
|
|
|
|
|
window_focused_ = true;
|
|
|
|
|
audio_.apply_config(cfg_, true);
|
|
|
|
|
}
|
2026-11-30 23:41:37 +02:00
|
|
|
} else if (ev.type == SDL_KEYDOWN && !ev.key.repeat &&
|
|
|
|
|
!input_.is_rebinding() && !input_.is_text_input_active()) {
|
2026-11-30 22:31:51 +02:00
|
|
|
if (ev.key.keysym.scancode == SDL_SCANCODE_F2) {
|
|
|
|
|
cfg_.classic_mode = !cfg_.classic_mode;
|
|
|
|
|
} else if (ev.key.keysym.scancode == SDL_SCANCODE_F4) {
|
|
|
|
|
int b = (static_cast<int>(cfg_.music_backend) + 1) % 2;
|
|
|
|
|
cfg_.music_backend = static_cast<MusicBackend>(b);
|
|
|
|
|
audio_.apply_config(cfg_, window_focused_);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
input_.handle_event(ev, cfg_, want_quit, want_fs);
|
|
|
|
|
}
|
|
|
|
|
input_.end_frame(cfg_);
|
|
|
|
|
|
|
|
|
|
if (want_quit) { running_ = false; break; }
|
|
|
|
|
if (want_fs) toggle_fullscreen();
|
|
|
|
|
|
|
|
|
|
int steps = clock_.advance(SDL_GetPerformanceCounter());
|
|
|
|
|
if (state_ == ScreenState::Racing) {
|
|
|
|
|
if (input_.menu_input().pause) {
|
|
|
|
|
audio_.set_engine_state(false, 0.0f, false, 0.0f);
|
2026-12-01 09:19:20 +02:00
|
|
|
audio_.set_pitstop_state(false, false, 1.0f);
|
2026-11-30 22:31:51 +02:00
|
|
|
enter_state(ScreenState::Paused);
|
|
|
|
|
} else {
|
|
|
|
|
for (int s = 0; s < steps; ++s) {
|
|
|
|
|
update_racing_step(static_cast<float>(FixedStepClock::kFixedDt));
|
|
|
|
|
if (state_ != ScreenState::Racing) break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else if (state_ == ScreenState::TrackViewer) {
|
|
|
|
|
update_track_viewer(static_cast<float>(steps) * static_cast<float>(FixedStepClock::kFixedDt));
|
|
|
|
|
} else {
|
|
|
|
|
update_menu(std::max(1, steps) * static_cast<float>(FixedStepClock::kFixedDt));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
render_frame(static_cast<float>(clock_.alpha()));
|
2026-12-01 09:19:20 +02:00
|
|
|
if (!opts_.screenshot_path.empty() && smoke_left == 1) {
|
|
|
|
|
if (write_backbuffer_ppm(opts_.screenshot_path, win_w_, win_h_)) {
|
|
|
|
|
LOG_INFO("Saved screenshot to %s (%dx%d)", opts_.screenshot_path.c_str(), win_w_, win_h_);
|
|
|
|
|
} else {
|
|
|
|
|
LOG_WARN("Failed to write screenshot: %s", opts_.screenshot_path.c_str());
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-11-30 22:31:51 +02:00
|
|
|
SDL_GL_SwapWindow(window_);
|
|
|
|
|
|
|
|
|
|
if (smoke_left > 0) {
|
|
|
|
|
GLenum gl_err = glGetError();
|
|
|
|
|
if (gl_err != GL_NO_ERROR) {
|
|
|
|
|
LOG_ERROR("GL error during smoke test: 0x%x", gl_err);
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
// Exercise both Modern & Classic modes during automated smoke test
|
2026-12-01 09:19:20 +02:00
|
|
|
if (opts_.screenshot_path.empty() && smoke_left == opts_.smoke_test_frames / 2) {
|
2026-11-30 22:31:51 +02:00
|
|
|
cfg_.classic_mode = !cfg_.classic_mode;
|
|
|
|
|
}
|
|
|
|
|
if (--smoke_left == 0) {
|
|
|
|
|
running_ = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!cfg_.vsync) {
|
|
|
|
|
SDL_Delay(1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GameApp::render_frame(float alpha) {
|
|
|
|
|
world_ren_.begin_frame(win_w_, win_h_, cfg_);
|
|
|
|
|
|
|
|
|
|
if (state_ == ScreenState::TrackViewer) {
|
|
|
|
|
render::RenderCamera cam;
|
|
|
|
|
cam.eye = viewer_pos_;
|
|
|
|
|
Vec3 look(std::sin(viewer_yaw_) * std::cos(viewer_pitch_),
|
|
|
|
|
std::sin(viewer_pitch_),
|
|
|
|
|
std::cos(viewer_yaw_) * std::cos(viewer_pitch_));
|
|
|
|
|
cam.target = cam.eye + look;
|
2026-12-01 09:19:20 +02:00
|
|
|
std::vector<render::DynamicLight> tv_all;
|
|
|
|
|
append_charger_lights(viewer_level_, ui_time_, tv_all);
|
|
|
|
|
auto tv_lights = select_viewport_lights(tv_all, cam.eye, cfg_.draw_distance);
|
|
|
|
|
world_ren_.render_world_view(cam, {}, {}, 0, 1, cfg_, tv_lights, {});
|
2026-11-30 22:31:51 +02:00
|
|
|
world_ren_.end_classic_world_pass(win_w_, win_h_, cfg_);
|
|
|
|
|
|
2026-12-01 09:38:10 +02:00
|
|
|
MenuLayout ml = compute_menu_layout(win_w_, win_h_);
|
|
|
|
|
ui_ren_.begin(win_w_, win_h_, ml.vw, ml.vh);
|
2026-11-30 22:31:51 +02:00
|
|
|
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, 44, 1.5f, "WASD MOVE ARROWS LOOK SPACE/C UP/DOWN F2 CLASSIC ESC BACK",
|
|
|
|
|
Vec4(0.85f, 0.9f, 1.0f, 1));
|
|
|
|
|
ui_ren_.end();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (state_ == ScreenState::Racing || state_ == ScreenState::Paused) {
|
|
|
|
|
std::vector<render::ModelInstance> models;
|
|
|
|
|
models.reserve(race_sim_.crafts().size() + race_sim_.pickups().size() +
|
|
|
|
|
race_sim_.props().size() + race_sim_.projectiles().size() + 4);
|
2026-12-01 09:19:20 +02:00
|
|
|
std::vector<render::CraftShadow> craft_shadows;
|
|
|
|
|
craft_shadows.reserve(race_sim_.crafts().size());
|
|
|
|
|
std::vector<render::DynamicLight> all_lights;
|
|
|
|
|
all_lights.reserve(race_sim_.level().pads.size() + race_sim_.crafts().size() + 16);
|
2026-11-30 22:31:51 +02:00
|
|
|
|
|
|
|
|
for (const auto& c : race_sim_.crafts()) {
|
|
|
|
|
sim::CraftPose p = sim::interpolate_pose(c, alpha);
|
|
|
|
|
Vec4 tint(1, 1, 1, 1);
|
|
|
|
|
if (c.damage_flash > 0.0f) tint = Vec4(1.8f, 0.45f, 0.45f, 1.0f);
|
|
|
|
|
float vscale = sim::kVehicleSpecs[std::clamp(c.vehicle_idx, 0, 5)].visual_scale;
|
|
|
|
|
models.push_back({sim::model_key_for(c.vehicle_idx, c.team_idx), p.pos,
|
|
|
|
|
p.yaw, p.pitch, p.roll, vscale, tint});
|
2026-12-01 09:19:20 +02:00
|
|
|
if (c.recovery_state == sim::RecoveryState::Active ||
|
|
|
|
|
c.recovery_state == sim::RecoveryState::Repairing ||
|
|
|
|
|
c.recovery_state == sim::RecoveryState::Destroyed) {
|
|
|
|
|
craft_shadows.push_back({p.pos, 0.82f + 0.35f * vscale});
|
|
|
|
|
}
|
|
|
|
|
if (c.recovery_state == sim::RecoveryState::Active) {
|
|
|
|
|
Vec3 fwd(std::sin(p.yaw), 0.0f, std::cos(p.yaw));
|
|
|
|
|
Vec3 jet_pos = p.pos - fwd * 0.55f + Vec3(0.0f, 0.14f, 0.0f);
|
|
|
|
|
if (c.boost_timer > 0.0f) {
|
|
|
|
|
all_lights.push_back({jet_pos, 6.5f, Vec3(0.40f, 0.88f, 1.00f), 1.35f});
|
|
|
|
|
} else if (c.speed_horizontal() > 2.5f) {
|
|
|
|
|
all_lights.push_back({jet_pos, 3.8f, Vec3(0.28f, 0.68f, 1.00f), 0.45f});
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-11-30 22:31:51 +02:00
|
|
|
}
|
|
|
|
|
if (race_sim_.has_clone_ghost()) {
|
|
|
|
|
sim::CraftPose gp = race_sim_.interpolated_clone_pose(alpha);
|
|
|
|
|
const auto& rec = race_sim_.current_recording();
|
|
|
|
|
float gscale = sim::kVehicleSpecs[std::clamp(rec.vehicle_idx, 0, 5)].visual_scale;
|
|
|
|
|
models.push_back({sim::model_key_for(rec.vehicle_idx, rec.team_idx), gp.pos,
|
|
|
|
|
gp.yaw, gp.pitch, gp.roll, gscale, Vec4(0.45f, 0.85f, 1.0f, 0.45f)});
|
|
|
|
|
}
|
|
|
|
|
for (const auto& rv : sim::get_recovery_visuals(race_sim_.crafts())) {
|
|
|
|
|
models.push_back({"RECOV0-0", rv.pos, rv.yaw, 0.0f, 0.0f, 0.55f, Vec4(1, 1, 1, 1)});
|
|
|
|
|
}
|
|
|
|
|
for (const auto& pr : race_sim_.props()) {
|
|
|
|
|
if (!pr.alive) continue;
|
|
|
|
|
float pscale = (pr.model_key.rfind("BAREL", 0) == 0) ? 0.42f : 0.68f;
|
|
|
|
|
models.push_back({pr.model_key, pr.pos, pr.yaw, 0.0f, 0.0f, pscale, Vec4(1, 1, 1, 1)});
|
|
|
|
|
}
|
|
|
|
|
for (const auto& pk : race_sim_.pickups()) {
|
|
|
|
|
if (!pk.active) continue;
|
|
|
|
|
float bob = std::sin(static_cast<float>(ui_time_) * 3.5f + pk.pos.x) * 0.12f;
|
|
|
|
|
float rot = static_cast<float>(ui_time_) * 2.2f;
|
|
|
|
|
Vec4 pcol(0.3f, 1.0f, 0.4f, 1.0f);
|
|
|
|
|
if (pk.subtype <= 2) pcol = Vec4(1.0f, 0.65f, 0.2f, 1.0f); // fuel
|
|
|
|
|
else if (pk.subtype <= 5) pcol = Vec4(0.3f, 0.7f, 1.0f, 1.0f); // shield
|
|
|
|
|
else if (pk.subtype <= 9) pcol = Vec4(1.0f, 0.9f, 0.2f, 1.0f); // ammo
|
|
|
|
|
else pcol = Vec4(1.0f, 0.35f, 0.9f, 1.0f); // weapon/booster upgrade
|
2026-12-01 09:19:20 +02:00
|
|
|
Vec3 ppos = pk.pos + Vec3(0, bob, 0);
|
|
|
|
|
models.push_back({"CONE0-0", ppos, rot, 0.0f, 0.0f, 0.65f, pcol});
|
|
|
|
|
all_lights.push_back({ppos + Vec3(0.0f, 0.25f, 0.0f), 3.4f, Vec3(pcol.x, pcol.y, pcol.z), 0.46f});
|
2026-11-30 22:31:51 +02:00
|
|
|
}
|
|
|
|
|
for (const auto& pj : race_sim_.projectiles()) {
|
2026-12-01 09:19:20 +02:00
|
|
|
if (!pj.active) continue;
|
|
|
|
|
if (pj.is_missile) {
|
|
|
|
|
models.push_back({"CONE0-1", pj.pos, pj.yaw, -kHalfPi, 0.0f, 0.5f, Vec4(1.0f, 0.3f, 0.2f, 1)});
|
|
|
|
|
all_lights.push_back({pj.pos, 5.8f, Vec3(1.0f, 0.44f, 0.14f), 1.15f});
|
|
|
|
|
} else {
|
|
|
|
|
all_lights.push_back({pj.pos, 2.8f, Vec3(1.0f, 0.85f, 0.32f), 0.55f});
|
|
|
|
|
}
|
2026-11-30 22:31:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::vector<render::ParticleQuad> parts;
|
2026-12-01 09:19:20 +02:00
|
|
|
parts.reserve(race_sim_.particles().size() + race_sim_.projectiles().size());
|
|
|
|
|
std::vector<Vec3> fire_clusters;
|
2026-11-30 22:31:51 +02:00
|
|
|
for (const auto& pb : race_sim_.particles()) {
|
2026-12-01 09:19:20 +02:00
|
|
|
bool additive = (pb.kind == sim::ParticleKind::AdditiveGlow ||
|
|
|
|
|
pb.kind == sim::ParticleKind::Fireball);
|
|
|
|
|
parts.push_back({pb.pos, pb.size, pb.color, static_cast<float>(pb.kind), pb.seed, additive});
|
|
|
|
|
if (pb.kind == sim::ParticleKind::Fireball && pb.color.w > 0.15f) {
|
|
|
|
|
bool merged = false;
|
|
|
|
|
for (const auto& fp : fire_clusters) {
|
|
|
|
|
if ((pb.pos - fp).len_sq() < 4.84f) {
|
|
|
|
|
merged = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!merged) {
|
|
|
|
|
fire_clusters.push_back(pb.pos);
|
|
|
|
|
all_lights.push_back({pb.pos, 10.5f, Vec3(1.0f, 0.54f, 0.14f),
|
|
|
|
|
1.65f * std::clamp(pb.color.w, 0.25f, 1.0f)});
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-11-30 22:31:51 +02:00
|
|
|
}
|
|
|
|
|
for (const auto& pj : race_sim_.projectiles()) {
|
|
|
|
|
if (!pj.active || pj.is_missile) continue;
|
2026-12-01 09:19:20 +02:00
|
|
|
parts.push_back({pj.pos, 0.28f, Vec4(1.0f, 0.9f, 0.35f, 1.0f), 0.0f, 0.0f, true});
|
2026-11-30 22:31:51 +02:00
|
|
|
}
|
2026-12-01 09:19:20 +02:00
|
|
|
append_charger_lights(race_sim_.level(), ui_time_, all_lights);
|
2026-11-30 22:31:51 +02:00
|
|
|
|
2026-12-01 09:19:20 +02:00
|
|
|
float draw_dist = cfg_.classic_mode ? 38.0f : cfg_.draw_distance;
|
2026-11-30 22:31:51 +02:00
|
|
|
int split_count = (selected_mode_ == sim::GameMode::SplitScreen && race_sim_.crafts().size() >= 2) ? 2 : 1;
|
|
|
|
|
std::array<render::RenderCamera, 2> cams{};
|
|
|
|
|
for (int vp = 0; vp < split_count; ++vp) {
|
|
|
|
|
const auto& craft = race_sim_.crafts()[vp];
|
|
|
|
|
sim::CraftPose pose = sim::interpolate_pose(craft, alpha);
|
|
|
|
|
Vec3 fwd(std::sin(pose.yaw), 0.0f, std::cos(pose.yaw));
|
|
|
|
|
if (cam_mode_ == 0) {
|
|
|
|
|
cams[vp].eye = pose.pos - fwd * 3.1f + Vec3(0.0f, 1.35f, 0.0f);
|
|
|
|
|
cams[vp].target = pose.pos + fwd * 2.5f + Vec3(0.0f, 0.2f, 0.0f);
|
|
|
|
|
} else if (cam_mode_ == 1) {
|
|
|
|
|
cams[vp].eye = pose.pos - fwd * 2.1f + Vec3(0.0f, 0.95f, 0.0f);
|
|
|
|
|
cams[vp].target = pose.pos + fwd * 3.2f + Vec3(0.0f, 0.15f, 0.0f);
|
|
|
|
|
} else {
|
|
|
|
|
cams[vp].eye = pose.pos + fwd * 0.45f + Vec3(0.0f, 0.42f, 0.0f);
|
|
|
|
|
cams[vp].target = pose.pos + fwd * 6.0f + Vec3(0.0f, 0.2f, 0.0f);
|
|
|
|
|
}
|
2026-12-01 08:05:04 +02:00
|
|
|
if (cam_mode_ == 0 || cam_mode_ == 1) {
|
|
|
|
|
float cam_floor_y = 0.0f;
|
|
|
|
|
float cam_ceil_y = 1e6f;
|
|
|
|
|
race_sim_.level().sample_surface_and_ceiling(cams[vp].eye.x, cams[vp].eye.z,
|
|
|
|
|
pose.pos.y, cam_floor_y, cam_ceil_y);
|
|
|
|
|
if (cams[vp].eye.y < cam_floor_y + 0.35f) {
|
|
|
|
|
cams[vp].eye.y = cam_floor_y + 0.35f;
|
|
|
|
|
}
|
|
|
|
|
if (cam_ceil_y < 1e5f) {
|
|
|
|
|
float max_cam_y = std::max(pose.pos.y + 0.15f, cam_ceil_y - 0.18f);
|
|
|
|
|
if (cams[vp].eye.y > max_cam_y) {
|
|
|
|
|
cams[vp].eye.y = max_cam_y;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Vec3 anchor = pose.pos + Vec3(0.0f, 0.35f, 0.0f);
|
|
|
|
|
Vec3 prev_clear = anchor;
|
|
|
|
|
constexpr int kCamSteps = 10;
|
|
|
|
|
for (int k = 1; k <= kCamSteps; ++k) {
|
|
|
|
|
float t = static_cast<float>(k) / static_cast<float>(kCamSteps);
|
|
|
|
|
Vec3 p = lerp(anchor, cams[vp].eye, t);
|
|
|
|
|
int ix = static_cast<int>(std::floor(p.x));
|
|
|
|
|
int iz = static_cast<int>(std::floor(p.z));
|
|
|
|
|
if (race_sim_.level().is_cell_solid_at_point(ix, iz, p.x, p.z, p.y, 0.15f)) {
|
|
|
|
|
cams[vp].eye = prev_clear;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
prev_clear = p;
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-11-30 22:31:51 +02:00
|
|
|
float min_cam_y = race_sim_.level().sample_height_world(cams[vp].eye.x, cams[vp].eye.z) + 0.4f;
|
|
|
|
|
if (cams[vp].eye.y < min_cam_y) cams[vp].eye.y = min_cam_y;
|
2026-12-01 09:19:20 +02:00
|
|
|
auto vp_lights = select_viewport_lights(all_lights, cams[vp].target, draw_dist);
|
|
|
|
|
world_ren_.render_world_view(cams[vp], models, parts, vp, split_count, cfg_, vp_lights, craft_shadows);
|
2026-11-30 22:31:51 +02:00
|
|
|
}
|
|
|
|
|
world_ren_.end_classic_world_pass(win_w_, win_h_, cfg_);
|
|
|
|
|
|
2026-12-01 09:19:20 +02:00
|
|
|
// Compute screen-space 2D HUD viewport bounds (respects Classic 4:3 pillarbox!)
|
|
|
|
|
int frame_x = 0, frame_y_gl = 0, frame_w = win_w_, frame_h = win_h_;
|
|
|
|
|
if (cfg_.classic_mode) {
|
|
|
|
|
float win_aspect = static_cast<float>(win_w_) / static_cast<float>(std::max(win_h_, 1));
|
|
|
|
|
constexpr float kTargetAspect = 4.0f / 3.0f;
|
|
|
|
|
if (win_aspect > kTargetAspect) {
|
|
|
|
|
frame_w = static_cast<int>(static_cast<float>(win_h_) * kTargetAspect);
|
|
|
|
|
frame_x = (win_w_ - frame_w) / 2;
|
|
|
|
|
} else {
|
|
|
|
|
frame_h = static_cast<int>(static_cast<float>(win_w_) / kTargetAspect);
|
|
|
|
|
frame_y_gl = (win_h_ - frame_h) / 2;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-30 22:31:51 +02:00
|
|
|
ui_ren_.begin(win_w_, win_h_);
|
|
|
|
|
for (int vp = 0; vp < split_count; ++vp) {
|
2026-12-01 09:19:20 +02:00
|
|
|
int vh = (split_count == 2) ? (frame_h / 2) : frame_h;
|
|
|
|
|
int gl_vy = (split_count == 2)
|
|
|
|
|
? ((vp == 0) ? (frame_y_gl + frame_h - vh) : frame_y_gl)
|
|
|
|
|
: frame_y_gl;
|
2026-11-30 23:57:29 +02:00
|
|
|
if (hud_visible_) {
|
2026-12-01 09:19:20 +02:00
|
|
|
render_hud_viewport(race_sim_.crafts()[vp], cams[vp], frame_x, gl_vy, frame_w, vh,
|
2026-11-30 23:57:29 +02:00
|
|
|
vp == 0 && cfg_.show_minimap);
|
2026-12-01 09:19:20 +02:00
|
|
|
} else if (race_sim_.countdown_active() || race_sim_.crafts()[vp].race_time < 0.85f) {
|
|
|
|
|
float hs = std::clamp(static_cast<float>(vh) / 480.0f, 0.55f, 1.8f);
|
2026-11-30 23:57:29 +02:00
|
|
|
int top_y = win_h_ - (gl_vy + vh);
|
2026-12-01 09:19:20 +02:00
|
|
|
float cx = static_cast<float>(frame_x) + static_cast<float>(frame_w) * 0.5f;
|
|
|
|
|
render_countdown_lights(cx, static_cast<float>(top_y) + 126.0f * hs, hs);
|
2026-11-30 23:57:29 +02:00
|
|
|
}
|
2026-11-30 22:31:51 +02:00
|
|
|
if (split_count == 2 && vp == 0) {
|
2026-12-01 09:19:20 +02:00
|
|
|
int div_y = win_h_ - (frame_y_gl + vh);
|
|
|
|
|
ui_ren_.draw_rect(static_cast<float>(frame_x), static_cast<float>(div_y - 2),
|
|
|
|
|
static_cast<float>(frame_w), 4.0f, Vec4(0.1f, 0.1f, 0.15f, 1.0f));
|
2026-11-30 22:31:51 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ui_ren_.end();
|
2026-12-01 09:38:10 +02:00
|
|
|
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();
|
|
|
|
|
}
|
2026-11-30 22:31:51 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Menu / Intro / Title / PostRace
|
|
|
|
|
gl::BindFramebuffer(GL_FRAMEBUFFER, 0);
|
|
|
|
|
glViewport(0, 0, win_w_, win_h_);
|
|
|
|
|
glClearColor(0.02f, 0.02f, 0.05f, 1.0f);
|
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
|
|
|
|
2026-12-01 09:38:10 +02:00
|
|
|
MenuLayout ml = compute_menu_layout(win_w_, win_h_);
|
|
|
|
|
ui_ren_.begin(win_w_, win_h_, ml.vw, ml.vh);
|
2026-11-30 22:31:51 +02:00
|
|
|
render_menus();
|
|
|
|
|
ui_ren_.end();
|
|
|
|
|
|
|
|
|
|
if (state_ == ScreenState::VehicleSelect) {
|
2026-12-01 09:38:10 +02:00
|
|
|
// Draw live rotating 3D craft model inside scaled virtual showroom box
|
|
|
|
|
float bx = 0.0f, by = 0.0f, bw = 0.0f, bh = 0.0f;
|
|
|
|
|
vehicle_preview_rect_virt(ml, bx, by, bw, bh);
|
|
|
|
|
int pv_x = static_cast<int>(std::lround(bx * ml.scale));
|
|
|
|
|
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));
|
2026-11-30 23:57:29 +02:00
|
|
|
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_;
|
2026-11-30 22:31:51 +02:00
|
|
|
float pv_scale = sim::kVehicleSpecs[std::clamp(veh, 0, 5)].visual_scale * 1.45f;
|
|
|
|
|
world_ren_.render_model_preview(sim::model_key_for(veh, team),
|
|
|
|
|
static_cast<float>(ui_time_) * 0.9f,
|
|
|
|
|
pv_x, pv_y, pv_w, pv_h, pv_scale);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GameApp::render_hud_viewport(const sim::CraftState& craft, const render::RenderCamera& cam,
|
|
|
|
|
int vx, int vy, int vw, int vh, bool show_minimap) {
|
|
|
|
|
const auto& str = get_strings(cfg_.language);
|
|
|
|
|
int top_y = win_h_ - (vy + vh);
|
2026-12-01 09:19:20 +02:00
|
|
|
bool split_view = (selected_mode_ == sim::GameMode::SplitScreen && race_sim_.crafts().size() >= 2);
|
|
|
|
|
float hs = std::min(static_cast<float>(vw) / 640.0f,
|
|
|
|
|
static_cast<float>(vh) / (split_view ? 410.0f : 475.0f));
|
|
|
|
|
hs = std::clamp(hs, 0.55f, 2.4f);
|
|
|
|
|
float s = std::clamp(static_cast<float>(vh) / 720.0f, 0.55f, 1.6f);
|
2026-11-30 22:31:51 +02:00
|
|
|
|
2026-12-01 09:19:20 +02:00
|
|
|
float ox = static_cast<float>(vx) + (static_cast<float>(vw) - 640.0f * hs) * 0.5f;
|
|
|
|
|
float oy = static_cast<float>(top_y) + 2.0f * hs;
|
|
|
|
|
|
|
|
|
|
auto draw_panel = [&](int spr, float x640, float y480, const Vec4& tint = Vec4(1, 1, 1, 1)) {
|
|
|
|
|
ui_ren_.draw_bank_sprite("panel", spr, ox + x640 * hs, oy + y480 * hs, hs, tint);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 1. Missile Lock-On Target Reticle (#258..#267)
|
2026-11-30 22:31:51 +02:00
|
|
|
if (craft.lock_target_id >= 0 && craft.lock_target_id < static_cast<int>(race_sim_.crafts().size())) {
|
|
|
|
|
const auto& tgt = race_sim_.crafts()[craft.lock_target_id];
|
|
|
|
|
if (tgt.recovery_state == sim::RecoveryState::Active) {
|
|
|
|
|
float aspect = static_cast<float>(vw) / static_cast<float>(std::max(vh, 1));
|
2026-12-01 09:19:20 +02:00
|
|
|
if (split_view) aspect = std::max(aspect, 1.0f);
|
2026-11-30 22:31:51 +02:00
|
|
|
float fov = cfg_.classic_mode ? 62.0f : cfg_.fov_deg;
|
|
|
|
|
Mat4 vp_mat = Mat4::perspective(deg_to_rad(fov), aspect, cam.z_near, cam.z_far) *
|
|
|
|
|
Mat4::look_at(cam.eye, cam.target, cam.up);
|
2026-12-01 09:19:20 +02:00
|
|
|
float sx = 0.0f, sy = 0.0f;
|
2026-11-30 22:31:51 +02:00
|
|
|
if (project_world_to_screen(tgt.curr_pose.pos, vp_mat, vx, vy, vw, vh, win_h_, sx, sy)) {
|
2026-12-01 09:19:20 +02:00
|
|
|
bool locked = (craft.lock_progress >= 1.0f);
|
|
|
|
|
float pulse = locked ? (0.75f + 0.25f * std::sin(static_cast<float>(ui_time_) * 16.0f)) : 0.92f;
|
|
|
|
|
Vec4 tint(1.0f, 1.0f, 1.0f, pulse);
|
|
|
|
|
float rs = std::max(1.25f, hs * 1.15f);
|
|
|
|
|
int box_spr = locked ? 259 : 258;
|
|
|
|
|
ui_ren_.draw_bank_sprite("panel", box_spr, sx - 10.5f * rs, sy - 9.5f * rs, rs, tint);
|
|
|
|
|
|
|
|
|
|
float spread = (1.0f - craft.lock_progress) * 26.0f * rs + 11.5f * rs;
|
|
|
|
|
ui_ren_.draw_bank_sprite("panel", locked ? 261 : 260, sx - 10.5f * rs, sy - spread - 4.0f * rs, rs, tint);
|
|
|
|
|
ui_ren_.draw_bank_sprite("panel", locked ? 263 : 262, sx - 10.5f * rs, sy + spread, rs, tint);
|
|
|
|
|
ui_ren_.draw_bank_sprite("panel", locked ? 265 : 264, sx - spread - 4.0f * rs, sy - 9.5f * rs, rs, tint);
|
|
|
|
|
ui_ren_.draw_bank_sprite("panel", locked ? 267 : 266, sx + spread, sy - 9.5f * rs, rs, tint);
|
|
|
|
|
|
|
|
|
|
if (locked) {
|
|
|
|
|
ui_ren_.draw_text_centered(sx, sy - spread - 20.0f * s, 1.15f * s, "LOCK",
|
|
|
|
|
Vec4(1.0f, 0.25f, 0.18f, pulse), true, render::UiFont::Panel);
|
2026-11-30 22:31:51 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-12-01 09:19:20 +02:00
|
|
|
// 2. Authentic Top Visor Curved Segmented Gauges (HIOCTANE.EXE PANEL0-1 tables)
|
|
|
|
|
struct SegSpec {
|
|
|
|
|
int16_t x;
|
|
|
|
|
int16_t y;
|
|
|
|
|
int16_t spr;
|
|
|
|
|
int thr;
|
|
|
|
|
};
|
|
|
|
|
auto draw_arc = [&](const SegSpec* segs, int count, int val_10000,
|
|
|
|
|
const Vec4& lit_tint, float back_alpha) {
|
|
|
|
|
Vec4 dim_tint(0.14f, 0.17f, 0.24f, back_alpha);
|
|
|
|
|
for (int i = 0; i < count; ++i) {
|
|
|
|
|
draw_panel(segs[i].spr, static_cast<float>(segs[i].x), static_cast<float>(segs[i].y), dim_tint);
|
2026-12-01 08:33:48 +02:00
|
|
|
}
|
2026-12-01 09:19:20 +02:00
|
|
|
for (int i = 0; i < count; ++i) {
|
|
|
|
|
if (val_10000 > segs[i].thr) {
|
|
|
|
|
draw_panel(segs[i].spr, static_cast<float>(segs[i].x), static_cast<float>(segs[i].y), lit_tint);
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-11-30 22:31:51 +02:00
|
|
|
};
|
|
|
|
|
|
2026-12-01 09:19:20 +02:00
|
|
|
static constexpr SegSpec kFuelArc[17] = {
|
|
|
|
|
{514, 4, 17, 0}, {488, 4, 16, 384}, {464, 4, 15, 768}, {440, 4, 14, 1152},
|
|
|
|
|
{414, 4, 13, 1536}, {390, 4, 12, 1920}, {366, 4, 11, 2304}, {342, 4, 10, 2688},
|
|
|
|
|
{324, 4, 9, 3072}, {306, 4, 8, 3456}, {286, 4, 7, 3840}, {264, 4, 6, 4224},
|
|
|
|
|
{240, 4, 5, 4608}, {216, 4, 4, 5376}, {182, 4, 3, 6528}, {136, 4, 2, 7680},
|
|
|
|
|
{82, 4, 1, 8832},
|
|
|
|
|
};
|
|
|
|
|
static constexpr SegSpec kSpeedWaveDim[19] = {
|
|
|
|
|
{120, 16, 18, 0}, {142, 16, 19, 526}, {162, 16, 20, 1052}, {186, 16, 21, 1578},
|
|
|
|
|
{206, 16, 22, 2104}, {228, 16, 23, 2630}, {246, 16, 24, 3156}, {268, 16, 25, 3682},
|
|
|
|
|
{288, 16, 26, 4208}, {306, 16, 27, 4734}, {324, 16, 28, 5260}, {342, 16, 29, 5786},
|
|
|
|
|
{364, 16, 30, 6312}, {388, 16, 31, 6838}, {414, 16, 32, 7364}, {438, 16, 33, 7890},
|
|
|
|
|
{462, 16, 34, 8416}, {484, 16, 35, 8942}, {508, 16, 36, 9468},
|
|
|
|
|
};
|
|
|
|
|
static constexpr SegSpec kSpeedWaveLit[19] = {
|
|
|
|
|
{120, 16, 37, 0}, {142, 16, 38, 526}, {162, 16, 39, 1052}, {186, 16, 40, 1578},
|
|
|
|
|
{206, 16, 41, 2104}, {228, 16, 42, 2630}, {246, 16, 43, 3156}, {268, 16, 44, 3682},
|
|
|
|
|
{288, 16, 45, 4208}, {306, 16, 46, 4734}, {324, 16, 47, 5260}, {342, 16, 48, 5786},
|
|
|
|
|
{364, 16, 49, 6312}, {388, 16, 50, 6838}, {414, 16, 51, 7364}, {438, 16, 52, 7890},
|
|
|
|
|
{462, 16, 53, 8416}, {484, 16, 54, 8942}, {508, 16, 55, 9468},
|
|
|
|
|
};
|
|
|
|
|
static constexpr SegSpec kSpeedBar[16] = {
|
|
|
|
|
{128, 26, 56, 0}, {148, 26, 57, 384}, {168, 26, 58, 768}, {188, 26, 59, 1152},
|
|
|
|
|
{208, 26, 60, 1536}, {230, 26, 61, 1920}, {248, 26, 62, 2304}, {268, 26, 63, 2688},
|
|
|
|
|
{288, 26, 64, 3072}, {306, 26, 65, 3456}, {324, 26, 66, 3840}, {342, 26, 67, 4608},
|
|
|
|
|
{360, 26, 68, 5376}, {380, 26, 69, 6528}, {418, 26, 70, 7680}, {454, 26, 71, 8832},
|
|
|
|
|
};
|
|
|
|
|
static constexpr SegSpec kShieldArc[6] = {
|
|
|
|
|
{4, 4, 72, 0}, {42, 4, 73, 1666}, {68, 4, 74, 3332},
|
|
|
|
|
{76, 4, 75, 4998}, {96, 4, 76, 6664}, {114, 4, 77, 8330},
|
|
|
|
|
};
|
|
|
|
|
static constexpr SegSpec kAmmoArc[6] = {
|
|
|
|
|
{596, 4, 91, 0}, {554, 4, 90, 1666}, {526, 4, 89, 3332},
|
|
|
|
|
{506, 4, 88, 4998},{488, 4, 87, 6664}, {460, 4, 86, 8330},
|
|
|
|
|
};
|
|
|
|
|
static constexpr SegSpec kRightWingRed[16] = {
|
|
|
|
|
{502, 28, 92, 0}, {518, 28, 93, 625}, {524, 28, 94, 1250}, {530, 28, 95, 1875},
|
|
|
|
|
{536, 28, 96, 2500}, {542, 28, 97, 3125}, {548, 28, 98, 3750}, {554, 28, 99, 4375},
|
|
|
|
|
{566, 28, 100, 5000},{578, 28, 101, 5625},{586, 28, 102, 6250}, {594, 28, 103, 6875},
|
|
|
|
|
{602, 28, 104, 7500},{610, 28, 105, 8125},{618, 28, 106, 8750}, {626, 28, 107, 9375},
|
|
|
|
|
};
|
2026-11-30 22:31:51 +02:00
|
|
|
|
2026-12-01 09:19:20 +02:00
|
|
|
float shield_frac = cfg_.damage_enabled ? std::clamp(craft.shield / std::max(craft.max_shield, 1.0f), 0.0f, 1.0f) : 1.0f;
|
|
|
|
|
float fuel_frac = cfg_.fuel_enabled ? std::clamp(craft.fuel / std::max(craft.max_fuel, 1.0f), 0.0f, 1.0f) : 1.0f;
|
|
|
|
|
float ammo_frac = cfg_.weapons_enabled ? std::clamp(craft.ammo / std::max(craft.max_ammo, 1.0f), 0.0f, 1.0f) : 1.0f;
|
|
|
|
|
|
|
|
|
|
auto status_tint = [&](float frac, uint8_t bit_mask) -> Vec4 {
|
|
|
|
|
if ((craft.active_recharge_mask & bit_mask) != 0) {
|
|
|
|
|
float p = 0.80f + 0.20f * std::sin(static_cast<float>(ui_time_) * 12.0f);
|
|
|
|
|
return Vec4(1.25f * p, 1.35f * p, 1.25f * p, 1.0f);
|
|
|
|
|
}
|
|
|
|
|
if (frac < 0.20f && frac > 0.0f) {
|
|
|
|
|
float blink = 0.55f + 0.45f * std::sin(static_cast<float>(ui_time_) * 10.0f);
|
|
|
|
|
return Vec4(1.0f, 0.72f, 0.72f, blink);
|
|
|
|
|
}
|
|
|
|
|
return Vec4(1.0f, 1.0f, 1.0f, 1.0f);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Draw Speed Wave + Fuel + Shield + Ammo + Speedometer + Right Boost/Lock Wing
|
|
|
|
|
const auto& spec = sim::kVehicleSpecs[std::clamp(craft.vehicle_idx, 0, 5)];
|
|
|
|
|
float boost_mult = 1.0f + 0.14f * static_cast<float>(craft.booster_level - 1);
|
|
|
|
|
float max_ref_spd = spec.top_speed + spec.boost_bonus * boost_mult;
|
|
|
|
|
float spd_frac = std::clamp(craft.speed_horizontal() / std::max(max_ref_spd, 1.0f), 0.0f, 1.0f);
|
|
|
|
|
|
|
|
|
|
draw_arc(kFuelArc, 17, static_cast<int>(fuel_frac * 10000.0f), status_tint(fuel_frac, 2u), 0.26f);
|
|
|
|
|
draw_arc(kSpeedWaveDim, 19, static_cast<int>(spd_frac * 10000.0f), Vec4(1.0f, 1.0f, 1.0f, 0.95f), 0.22f);
|
|
|
|
|
if (craft.boost_timer > 0.0f) {
|
|
|
|
|
int wave_val = static_cast<int>(std::clamp(spd_frac + 0.25f, 0.35f, 1.0f) * 10000.0f);
|
|
|
|
|
for (int i = 0; i < 19; ++i) {
|
|
|
|
|
if (wave_val > kSpeedWaveLit[i].thr) {
|
|
|
|
|
draw_panel(kSpeedWaveLit[i].spr, static_cast<float>(kSpeedWaveLit[i].x),
|
|
|
|
|
static_cast<float>(kSpeedWaveLit[i].y), Vec4(1.0f, 1.0f, 1.0f, 0.98f));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
draw_arc(kSpeedBar, 16, static_cast<int>(spd_frac * 10000.0f), Vec4(1.0f, 1.0f, 1.0f, 1.0f), 0.25f);
|
|
|
|
|
draw_arc(kShieldArc, 6, static_cast<int>(shield_frac * 10000.0f), status_tint(shield_frac, 1u), 0.30f);
|
|
|
|
|
draw_arc(kAmmoArc, 6, static_cast<int>(ammo_frac * 10000.0f), status_tint(ammo_frac, 4u), 0.30f);
|
|
|
|
|
|
|
|
|
|
// Right wing orange/red bar shows Missile Lock Charge (when locking) or Booster overdrive charge
|
|
|
|
|
float right_frac = (craft.lock_target_id >= 0 && craft.lock_progress > 0.02f)
|
|
|
|
|
? craft.lock_progress
|
|
|
|
|
: (craft.boost_timer > 0.0f ? std::clamp(craft.boost_timer / 2.5f, 0.0f, 1.0f)
|
|
|
|
|
: spd_frac * 0.7f);
|
|
|
|
|
Vec4 right_tint = (craft.lock_progress >= 1.0f)
|
|
|
|
|
? Vec4(1.3f, 0.9f, 0.9f, 0.7f + 0.3f * std::sin(static_cast<float>(ui_time_) * 16.0f))
|
|
|
|
|
: Vec4(1.0f, 1.0f, 1.0f, 1.0f);
|
|
|
|
|
draw_arc(kRightWingRed, 16, static_cast<int>(right_frac * 10000.0f), right_tint, 0.25f);
|
|
|
|
|
|
|
|
|
|
// 3. Giant Metallic Position Counter (#108..#117, #138 '/', #128..#137)
|
|
|
|
|
int place = std::clamp(craft.placement, 0, 9);
|
|
|
|
|
int total_c = std::clamp(static_cast<int>(race_sim_.crafts().size()), 1, 9);
|
|
|
|
|
draw_panel(108 + place, 4.0f, 32.0f);
|
|
|
|
|
draw_panel(138, 56.0f, 76.0f);
|
|
|
|
|
draw_panel(128 + total_c, 86.0f, 76.0f);
|
|
|
|
|
|
|
|
|
|
// 4. Weapon & Booster Upgrade Bars (#268..#276)
|
|
|
|
|
draw_panel(268, 148.0f, 70.0f);
|
|
|
|
|
draw_panel(271, 264.0f, 70.0f);
|
|
|
|
|
draw_panel(274, 362.0f, 70.0f);
|
|
|
|
|
for (int p = 0; p < 3; ++p) {
|
|
|
|
|
Vec4 gun_t = (craft.minigun_level > p) ? Vec4(1, 1, 1, 1) : Vec4(0.25f, 0.25f, 0.30f, 0.45f);
|
|
|
|
|
Vec4 msl_t = (craft.missile_level > p) ? Vec4(1, 1, 1, 1) : Vec4(0.25f, 0.25f, 0.30f, 0.45f);
|
|
|
|
|
Vec4 bst_t = (craft.booster_level > p) ? Vec4(1, 1, 1, 1) : Vec4(0.25f, 0.25f, 0.30f, 0.45f);
|
|
|
|
|
draw_panel(270, 218.0f + p * 14.0f, 70.0f, gun_t);
|
|
|
|
|
draw_panel(273, 316.0f + p * 14.0f, 70.0f, msl_t);
|
|
|
|
|
draw_panel((p == 2) ? 276 : 275, 412.0f + p * 14.0f, 70.0f, bst_t);
|
2026-11-30 22:31:51 +02:00
|
|
|
}
|
|
|
|
|
|
2026-12-01 09:19:20 +02:00
|
|
|
// 5. Lap Counter (or DeathMatch Kill Limit) under Left Wing (#227 + small red digits #139..#150)
|
|
|
|
|
int cur_a = (selected_mode_ == sim::GameMode::DeathMatch)
|
|
|
|
|
? std::clamp(craft.kills, 0, 99)
|
|
|
|
|
: std::clamp(std::min(craft.lap, race_sim_.setup().total_laps), 1, 99);
|
|
|
|
|
int max_b = (selected_mode_ == sim::GameMode::DeathMatch)
|
|
|
|
|
? std::clamp(race_sim_.setup().deathmatch_kill_limit, 1, 99)
|
|
|
|
|
: std::clamp(race_sim_.setup().total_laps, 1, 99);
|
|
|
|
|
draw_panel(227, 128.0f, 94.0f);
|
|
|
|
|
draw_panel(139 + (cur_a / 10) % 10, 178.0f, 96.0f);
|
|
|
|
|
draw_panel(139 + (cur_a % 10), 192.0f, 96.0f);
|
|
|
|
|
draw_panel(150, 204.0f, 96.0f);
|
|
|
|
|
draw_panel(139 + (max_b / 10) % 10, 218.0f, 96.0f);
|
|
|
|
|
draw_panel(139 + (max_b % 10), 232.0f, 96.0f);
|
|
|
|
|
|
|
|
|
|
// 6. Top-Right Red Skull & Kills Counter (#228 + medium red digits #118..#127)
|
|
|
|
|
int kills_clamped = std::clamp(craft.kills, 0, 99);
|
|
|
|
|
draw_panel(228, 554.0f, 68.0f);
|
|
|
|
|
draw_panel(118 + (kills_clamped / 10) % 10, 586.0f, 68.0f);
|
|
|
|
|
draw_panel(118 + (kills_clamped % 10), 612.0f, 68.0f);
|
|
|
|
|
|
|
|
|
|
// 7. Recharging Hazard Banner (#198/#199) or Low-Resource Alert below upgrade bars
|
|
|
|
|
if (craft.active_recharge_mask != 0) {
|
|
|
|
|
int stripe_spr = (static_cast<int>(ui_time_ * 6.0) & 1) ? 198 : 199;
|
|
|
|
|
draw_panel(stripe_spr, 260.0f, 98.0f);
|
|
|
|
|
draw_panel(stripe_spr == 198 ? 199 : 198, 492.0f, 98.0f);
|
|
|
|
|
const char* rmsg = "RECHARGING";
|
|
|
|
|
Vec4 rcol(0.35f, 1.0f, 0.55f, 1.0f);
|
|
|
|
|
if (craft.active_recharge_mask & 1u) {
|
|
|
|
|
rmsg = "SHIELD CHARGING";
|
|
|
|
|
rcol = Vec4(0.35f, 1.0f, 0.55f, 1.0f);
|
|
|
|
|
} else if (craft.active_recharge_mask & 2u) {
|
|
|
|
|
rmsg = "FUEL CHARGING";
|
|
|
|
|
rcol = Vec4(0.42f, 0.85f, 1.0f, 1.0f);
|
|
|
|
|
} else if (craft.active_recharge_mask & 4u) {
|
|
|
|
|
rmsg = "AMMO CHARGING";
|
|
|
|
|
rcol = Vec4(1.0f, 0.90f, 0.25f, 1.0f);
|
|
|
|
|
}
|
|
|
|
|
ui_ren_.draw_text_centered_fit(ox + 401.0f * hs, oy + 99.0f * hs, 174.0f * hs, 1.15f * hs,
|
|
|
|
|
rmsg, rcol, true, render::UiFont::Panel);
|
|
|
|
|
} else if (cfg_.damage_enabled && shield_frac < 0.20f) {
|
|
|
|
|
if ((static_cast<int>(ui_time_ * 6.0) & 1) == 0) {
|
|
|
|
|
ui_ren_.draw_text_centered_fit(ox + 398.0f * hs, oy + 99.0f * hs, 220.0f * hs, 1.2f * hs,
|
|
|
|
|
"SHIELD LOW", Vec4(1.0f, 0.28f, 0.25f, 1.0f), true, render::UiFont::Panel);
|
|
|
|
|
}
|
|
|
|
|
} else if (cfg_.fuel_enabled && fuel_frac < 0.18f) {
|
|
|
|
|
if ((static_cast<int>(ui_time_ * 6.0) & 1) == 0) {
|
|
|
|
|
ui_ren_.draw_text_centered_fit(ox + 398.0f * hs, oy + 99.0f * hs, 220.0f * hs, 1.2f * hs,
|
|
|
|
|
"FUEL LOW", Vec4(1.0f, 0.65f, 0.2f, 1.0f), true, render::UiFont::Panel);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 8. Bottom-Left Compact Telemetry Card (Speed KPH using #151..#160 silver digits + TIME / BEST)
|
|
|
|
|
float pad = 14.0f * s;
|
|
|
|
|
float card_w = (split_view ? 206.0f : 232.0f) * s;
|
|
|
|
|
float card_h = (craft.best_lap_time > 0.0f) ? (80.0f * s) : (58.0f * s);
|
|
|
|
|
float card_x = static_cast<float>(vx) + pad;
|
|
|
|
|
float card_y = static_cast<float>(top_y + vh) - card_h - pad;
|
|
|
|
|
ui_ren_.draw_rect(card_x, card_y, card_w, card_h, Vec4(0.02f, 0.04f, 0.10f, 0.64f));
|
|
|
|
|
ui_ren_.draw_rect_outline(card_x, card_y, card_w, card_h, 2.0f, Vec4(0.28f, 0.68f, 1.0f, 0.78f));
|
|
|
|
|
|
|
|
|
|
int kmh = std::clamp(static_cast<int>(craft.speed_horizontal() * 14.5f), 0, 999);
|
|
|
|
|
float ds = (split_view ? 0.85f : 1.0f) * s;
|
|
|
|
|
ui_ren_.draw_bank_sprite("panel", 151 + (kmh / 100) % 10, card_x + 10.0f * s, card_y + 7.0f * s, ds);
|
|
|
|
|
ui_ren_.draw_bank_sprite("panel", 151 + (kmh / 10) % 10, card_x + 25.0f * s, card_y + 7.0f * s, ds);
|
|
|
|
|
ui_ren_.draw_bank_sprite("panel", 151 + (kmh % 10), card_x + 40.0f * s, card_y + 7.0f * s, ds);
|
|
|
|
|
ui_ren_.draw_text_fit(card_x + 60.0f * s, card_y + 9.0f * s, card_w - 68.0f * s, 1.65f * s,
|
|
|
|
|
"KPH", Vec4(0.75f, 0.90f, 1.0f, 1.0f), true, render::UiFont::MenuSmall);
|
|
|
|
|
std::string time_str = (craft.race_time > 0.0f) ? format_time(craft.race_time) : "00:00.00";
|
|
|
|
|
ui_ren_.draw_text_fit(card_x + 10.0f * s, card_y + 34.0f * s, card_w - 20.0f * s, 1.60f * s,
|
|
|
|
|
"TIME " + time_str, Vec4(0.92f, 0.97f, 1.0f, 1.0f),
|
|
|
|
|
true, render::UiFont::MenuSmall);
|
|
|
|
|
if (craft.best_lap_time > 0.0f) {
|
|
|
|
|
ui_ren_.draw_text_fit(card_x + 10.0f * s, card_y + 55.0f * s, card_w - 20.0f * s, 1.40f * s,
|
|
|
|
|
"BEST " + format_time(craft.best_lap_time), Vec4(0.42f, 1.0f, 0.65f, 1.0f),
|
|
|
|
|
true, render::UiFont::MenuSmall);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 9. Bottom-Right Minimap (kept completely clear of top visor gauges!)
|
|
|
|
|
if (show_minimap) {
|
|
|
|
|
float mm_size = (split_view ? 110.0f : 152.0f) * s;
|
|
|
|
|
render_minimap(craft, static_cast<float>(vx + vw) - mm_size - pad,
|
|
|
|
|
static_cast<float>(top_y + vh) - mm_size - pad, mm_size);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 10. Center Start Traffic Lights (#281..#286), Wrong-Way Warning & Banners
|
|
|
|
|
float cx = static_cast<float>(vx) + static_cast<float>(vw) * 0.5f;
|
|
|
|
|
float cy = oy + 126.0f * hs;
|
|
|
|
|
if (race_sim_.countdown_active() || (!race_sim_.countdown_active() && craft.race_time < 0.85f)) {
|
|
|
|
|
render_countdown_lights(cx, cy, hs);
|
2026-11-30 22:31:51 +02:00
|
|
|
} else if (craft.wrong_way) {
|
2026-12-01 09:19:20 +02:00
|
|
|
ui_ren_.draw_text_centered_fit(cx, cy + 28.0f * s, static_cast<float>(vw) * 0.75f, 2.6f * s,
|
|
|
|
|
str.wrong_way, Vec4(1.0f, 0.22f, 0.20f, 1.0f), true, render::UiFont::MenuLarge);
|
2026-11-30 22:31:51 +02:00
|
|
|
} else {
|
|
|
|
|
int pi = (craft.player_index == 1) ? 1 : 0;
|
|
|
|
|
if (hud_banner_timer_[pi] > 0.0f && !hud_banner_[pi].empty()) {
|
2026-12-01 09:19:20 +02:00
|
|
|
ui_ren_.draw_text_centered_fit(cx, cy + 26.0f * s, static_cast<float>(vw) * 0.75f, 2.4f * s,
|
|
|
|
|
hud_banner_[pi], Vec4(1.0f, 0.92f, 0.25f, 1.0f),
|
|
|
|
|
true, render::UiFont::MenuLarge);
|
2026-11-30 22:31:51 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-12-01 09:19:20 +02:00
|
|
|
void GameApp::render_countdown_lights(float cx, float ly, float hs) {
|
|
|
|
|
float ct = race_sim_.countdown_timer();
|
|
|
|
|
bool counting = race_sim_.countdown_active();
|
|
|
|
|
ui_ren_.draw_bank_sprite("panel", (counting && ct > 1.0f) ? 282 : 281, cx - 102.0f * hs, ly, hs);
|
|
|
|
|
ui_ren_.draw_bank_sprite("panel", (counting && ct <= 2.0f) ? 284 : 283, cx - 32.0f * hs, ly, hs);
|
|
|
|
|
ui_ren_.draw_bank_sprite("panel", (!counting) ? 286 : 285, cx + 38.0f * hs, ly, hs);
|
|
|
|
|
if (counting) {
|
|
|
|
|
int c = std::clamp(static_cast<int>(std::ceil(ct)), 1, 9);
|
|
|
|
|
ui_ren_.draw_bank_sprite("panel", 108 + c, cx - 25.0f * hs, ly + 36.0f * hs, hs);
|
|
|
|
|
} else {
|
|
|
|
|
ui_ren_.draw_text_centered(cx, ly + 42.0f * hs, 2.8f * hs, "GO!",
|
|
|
|
|
Vec4(0.35f, 1.0f, 0.45f, 1.0f), true, render::UiFont::MenuLarge);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-30 22:31:51 +02:00
|
|
|
void GameApp::render_minimap(const sim::CraftState& focus, float mx, float my, float size) {
|
2026-12-01 09:19:20 +02:00
|
|
|
ui_ren_.draw_rect(mx, my, size, size, Vec4(0.02f, 0.04f, 0.09f, 0.70f));
|
|
|
|
|
ui_ren_.draw_rect_outline(mx, my, size, size, 2.0f, Vec4(0.28f, 0.68f, 1.0f, 0.82f));
|
2026-11-30 22:31:51 +02:00
|
|
|
|
|
|
|
|
const auto& lvl = race_sim_.level();
|
|
|
|
|
const auto& wps = lvl.main_waypoints;
|
|
|
|
|
if (wps.size() < 2) return;
|
|
|
|
|
|
|
|
|
|
float min_x = 1e9f, max_x = -1e9f, min_z = 1e9f, max_z = -1e9f;
|
|
|
|
|
for (const auto& w : wps) {
|
|
|
|
|
min_x = std::min(min_x, w.x); max_x = std::max(max_x, w.x);
|
|
|
|
|
min_z = std::min(min_z, w.z); max_z = std::max(max_z, w.z);
|
|
|
|
|
}
|
|
|
|
|
float span = std::max({max_x - min_x, max_z - min_z, 10.0f});
|
2026-12-01 09:19:20 +02:00
|
|
|
float pad = size * 0.10f;
|
2026-11-30 22:31:51 +02:00
|
|
|
float scale = (size - 2.0f * pad) / span;
|
|
|
|
|
float ox = mx + (size - (max_x - min_x) * scale) * 0.5f;
|
|
|
|
|
float oy = my + (size - (max_z - min_z) * scale) * 0.5f;
|
|
|
|
|
|
|
|
|
|
auto to_mm = [&](float wx, float wz) -> Vec2 {
|
|
|
|
|
return Vec2(ox + (wx - min_x) * scale, oy + (wz - min_z) * scale);
|
|
|
|
|
};
|
|
|
|
|
|
2026-12-01 09:19:20 +02:00
|
|
|
// Dark outer casing + bright slate track ribbon
|
2026-11-30 22:31:51 +02:00
|
|
|
for (size_t i = 0; i < wps.size(); ++i) {
|
|
|
|
|
Vec2 p0 = to_mm(wps[i].x, wps[i].z);
|
|
|
|
|
Vec2 p1 = to_mm(wps[(i + 1) % wps.size()].x, wps[(i + 1) % wps.size()].z);
|
2026-12-01 09:19:20 +02:00
|
|
|
ui_ren_.draw_line(p0.x, p0.y, p1.x, p1.y, 4.5f, Vec4(0.08f, 0.14f, 0.22f, 0.95f));
|
|
|
|
|
}
|
|
|
|
|
for (size_t i = 0; i < wps.size(); ++i) {
|
|
|
|
|
Vec2 p0 = to_mm(wps[i].x, wps[i].z);
|
|
|
|
|
Vec2 p1 = to_mm(wps[(i + 1) % wps.size()].x, wps[(i + 1) % wps.size()].z);
|
|
|
|
|
ui_ren_.draw_line(p0.x, p0.y, p1.x, p1.y, 2.2f, Vec4(0.50f, 0.70f, 0.88f, 0.95f));
|
2026-11-30 22:31:51 +02:00
|
|
|
}
|
|
|
|
|
|
2026-12-01 09:19:20 +02:00
|
|
|
// Start/finish orthogonal tick
|
|
|
|
|
Vec2 sf0 = to_mm(wps[0].x, wps[0].z);
|
|
|
|
|
Vec2 sf1 = to_mm(wps[1].x, wps[1].z);
|
|
|
|
|
Vec2 td = (sf1 - sf0).normalized();
|
|
|
|
|
Vec2 perp(-td.y, td.x);
|
|
|
|
|
ui_ren_.draw_line(sf0.x - perp.x * 5.0f, sf0.y - perp.y * 5.0f,
|
|
|
|
|
sf0.x + perp.x * 5.0f, sf0.y + perp.y * 5.0f, 2.5f, Vec4(1.0f, 1.0f, 1.0f, 1.0f));
|
|
|
|
|
|
|
|
|
|
// Pitstop bay markers (Shield emerald, Fuel cyan, Ammo gold)
|
|
|
|
|
for (const auto& cp : lvl.pads) {
|
|
|
|
|
Vec2 mp = to_mm(cp.cx, cp.cz);
|
|
|
|
|
Vec4 pc(0.25f, 0.72f, 1.0f, 0.95f);
|
|
|
|
|
if (cp.type == assets::ChargerType::Shield) pc = Vec4(0.20f, 1.0f, 0.45f, 0.95f);
|
|
|
|
|
else if (cp.type == assets::ChargerType::Ammo) pc = Vec4(1.0f, 0.85f, 0.22f, 0.95f);
|
|
|
|
|
ui_ren_.draw_rect(mp.x - 2.5f, mp.y - 2.5f, 5.0f, 5.0f, pc);
|
2026-11-30 22:31:51 +02:00
|
|
|
}
|
2026-12-01 09:19:20 +02:00
|
|
|
|
|
|
|
|
// Opponent craft markers
|
|
|
|
|
for (const auto& c : race_sim_.crafts()) {
|
|
|
|
|
if (c.id == focus.id) continue;
|
|
|
|
|
Vec2 p = to_mm(c.curr_pose.pos.x, c.curr_pose.pos.z);
|
|
|
|
|
Vec4 dot_col = c.is_human ? Vec4(0.2f, 1.0f, 0.4f, 1.0f) : Vec4(1.0f, 0.3f, 0.28f, 1.0f);
|
|
|
|
|
ui_ren_.draw_rect(p.x - 2.5f, p.y - 2.5f, 5.0f, 5.0f, dot_col);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Focus craft directional heading chevron
|
|
|
|
|
Vec2 fp = to_mm(focus.curr_pose.pos.x, focus.curr_pose.pos.z);
|
|
|
|
|
Vec2 fwd(std::sin(focus.curr_pose.yaw), std::cos(focus.curr_pose.yaw));
|
|
|
|
|
Vec2 side(-fwd.y, fwd.x);
|
|
|
|
|
Vec2 tip = fp + fwd * 5.5f;
|
|
|
|
|
Vec2 bl = fp - fwd * 3.5f + side * 4.0f;
|
|
|
|
|
Vec2 br = fp - fwd * 3.5f - side * 4.0f;
|
|
|
|
|
ui_ren_.draw_line(tip.x, tip.y, bl.x, bl.y, 2.2f, Vec4(1.0f, 0.92f, 0.15f, 1.0f));
|
|
|
|
|
ui_ren_.draw_line(tip.x, tip.y, br.x, br.y, 2.2f, Vec4(1.0f, 0.92f, 0.15f, 1.0f));
|
|
|
|
|
ui_ren_.draw_line(bl.x, bl.y, br.x, br.y, 2.0f, Vec4(1.0f, 0.72f, 0.10f, 1.0f));
|
2026-11-30 22:31:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GameApp::render_menus() {
|
|
|
|
|
const auto& str = get_strings(cfg_.language);
|
2026-12-01 09:38:10 +02:00
|
|
|
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;
|
2026-11-30 22:31:51 +02:00
|
|
|
|
|
|
|
|
if (state_ == ScreenState::Intro) {
|
|
|
|
|
ui_ren_.draw_stream_4_3();
|
2026-12-01 09:38:10 +02:00
|
|
|
ui_ren_.draw_text_centered(cx, vh - 28.0f, 1.85f,
|
2026-11-30 22:31:51 +02:00
|
|
|
"PRESS ANY KEY TO SKIP", Vec4(0.75f, 0.8f, 0.9f, 0.8f));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (state_ == ScreenState::Title) {
|
|
|
|
|
ui_ren_.draw_screen_4_3("title");
|
|
|
|
|
float pulse = 0.65f + 0.35f * std::sin(static_cast<float>(ui_time_) * 4.5f);
|
2026-12-01 09:38:10 +02:00
|
|
|
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,
|
2026-11-30 22:31:51 +02:00
|
|
|
str.press_fire, Vec4(1.0f, 0.9f, 0.25f, pulse));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Backdrop for menus
|
|
|
|
|
ui_ren_.draw_screen_cover("oscr", 0.38f);
|
2026-12-01 09:38:10 +02:00
|
|
|
ui_ren_.draw_rect(0, 0, vw, vh, Vec4(0.03f, 0.05f, 0.11f, 0.55f));
|
2026-11-30 22:31:51 +02:00
|
|
|
|
|
|
|
|
if (state_ == ScreenState::Paused) {
|
2026-12-01 09:38:10 +02:00
|
|
|
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 - 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, oy + 168.0f, 3.1f, "PAUSED", Vec4(1.0f, 0.85f, 0.2f, 1));
|
2026-11-30 22:31:51 +02:00
|
|
|
const char* pitems[] = {str.continue_game, "RESTART RACE", str.options, str.abort_game};
|
|
|
|
|
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);
|
2026-12-01 09:38:10 +02:00
|
|
|
ui_ren_.draw_text_centered(cx, oy + 232.0f + i * 44.0f, 2.25f, pitems[i], col);
|
2026-11-30 22:31:51 +02:00
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-30 23:41:37 +02:00
|
|
|
// Header Title in authentic Bullfrog neon-green bevel font (PFONT0-1)
|
2026-12-01 09:38:10 +02:00
|
|
|
ui_ren_.draw_text_centered_fit(cx, oy + 18.0f, vw - 48.0f, 4.6f,
|
2026-11-30 23:41:37 +02:00
|
|
|
"TOP-OCTANE", Vec4(1.0f, 1.0f, 1.0f, 1.0f), true,
|
|
|
|
|
render::UiFont::Panel);
|
|
|
|
|
|
|
|
|
|
bool blink_cursor = std::fmod(ui_time_ * 2.5, 1.0) < 0.55;
|
|
|
|
|
std::string edit_display = name_edit_buf_ + (blink_cursor ? "_" : " ");
|
2026-11-30 22:31:51 +02:00
|
|
|
|
|
|
|
|
if (state_ == ScreenState::MainMenu) {
|
2026-12-01 09:38:10 +02:00
|
|
|
ui_ren_.draw_text_centered(cx, oy + 72.0f, 1.9f, "PILOT: " + cfg_.player_name,
|
2026-11-30 23:41:37 +02:00
|
|
|
Vec4(0.45f, 0.95f, 0.65f, 1.0f));
|
2026-11-30 22:31:51 +02:00
|
|
|
const char* items[] = {
|
|
|
|
|
str.single_race, str.death_match, str.clone_race,
|
|
|
|
|
str.championship, str.split_screen, str.track_viewer,
|
|
|
|
|
str.highscores, str.options, str.quit
|
|
|
|
|
};
|
2026-12-01 09:38:10 +02:00
|
|
|
float start_y = oy + 114.0f;
|
2026-11-30 22:31:51 +02:00
|
|
|
for (int i = 0; i < 9; ++i) {
|
|
|
|
|
bool sel = (i == menu_cursor_);
|
|
|
|
|
if (sel) {
|
2026-12-01 09:38:10 +02:00
|
|
|
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 - 280.0f, start_y + i * 44.0f - 7.0f, 560.0f, 34.0f, 2.0f, Vec4(1, 0.85f, 0.2f, 1));
|
2026-11-30 22:31:51 +02:00
|
|
|
}
|
2026-12-01 09:38:10 +02:00
|
|
|
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.84f, 0.92f, 1, 1));
|
2026-11-30 22:31:51 +02:00
|
|
|
}
|
2026-12-01 09:38:10 +02:00
|
|
|
ui_ren_.draw_text_centered_fit(cx, vh - 30.0f,
|
|
|
|
|
vw - 40.0f, 1.5f,
|
2026-11-30 23:41:37 +02:00
|
|
|
"ARROWS/DPAD NAVIGATE ENTER/A SELECT F2 CLASSIC MODE F11 FULLSCREEN",
|
2026-12-01 09:38:10 +02:00
|
|
|
Vec4(0.65f, 0.76f, 0.92f, 1));
|
2026-11-30 22:31:51 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (state_ == ScreenState::ChampionshipMenu) {
|
2026-12-01 09:38:10 +02:00
|
|
|
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, oy + 112.0f, 1.8f, "PILOT: " + cfg_.player_name,
|
2026-11-30 23:41:37 +02:00
|
|
|
Vec4(0.45f, 0.95f, 0.65f, 1.0f));
|
2026-11-30 23:57:29 +02:00
|
|
|
std::string items[6] = {
|
2026-11-30 22:31:51 +02:00
|
|
|
"NEW CHAMPIONSHIP",
|
2026-11-30 23:57:29 +02:00
|
|
|
std::string(str.difficulty) + ": < " + diff_label(selected_difficulty_) + " >",
|
2026-11-30 22:31:51 +02:00
|
|
|
champ_.active && !champ_.is_complete()
|
|
|
|
|
? ("CONTINUE CHAMPIONSHIP (TRACK " + std::to_string(champ_.current_track) + "/6)")
|
|
|
|
|
: "CONTINUE CHAMPIONSHIP (NONE)",
|
|
|
|
|
"LOAD SLOT " + std::to_string(champ_slot_cursor_ + 1) +
|
|
|
|
|
(ChampionshipState::slot_exists(vfs_.pref_dir(), champ_slot_cursor_) ? " [SAVED]" : " [EMPTY]"),
|
|
|
|
|
"SAVE SLOT " + std::to_string(champ_slot_cursor_ + 1),
|
|
|
|
|
"BACK TO MAIN MENU"
|
|
|
|
|
};
|
2026-11-30 23:57:29 +02:00
|
|
|
for (int i = 0; i < 6; ++i) {
|
2026-11-30 22:31:51 +02:00
|
|
|
bool sel = (i == menu_cursor_);
|
2026-12-01 09:38:10 +02:00
|
|
|
ui_ren_.draw_text_centered_fit(cx, oy + 162.0f + i * 46.0f, vw - 80.0f,
|
|
|
|
|
2.15f, items[i],
|
2026-11-30 23:41:37 +02:00
|
|
|
sel ? Vec4(1, 0.9f, 0.2f, 1) : Vec4(0.85f, 0.9f, 1, 1));
|
2026-11-30 22:31:51 +02:00
|
|
|
}
|
|
|
|
|
if (status_toast_timer_ > 0.0f) {
|
2026-12-01 09:38:10 +02:00
|
|
|
ui_ren_.draw_text_centered(cx, oy + 470.0f, 2.0f, status_toast_, Vec4(0.3f, 1.0f, 0.5f, 1));
|
2026-11-30 22:31:51 +02:00
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (state_ == ScreenState::TrackSelect) {
|
2026-12-01 09:38:10 +02:00
|
|
|
ui_ren_.draw_text_centered(cx, oy + 76.0f, 2.55f, str.select_track, Vec4(0.4f, 0.85f, 1, 1));
|
2026-11-30 22:31:51 +02:00
|
|
|
// 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};
|
|
|
|
|
int preview_idx = kTrackPreviewSprites[std::clamp(selected_track_ - 1, 0, 5)];
|
2026-12-01 09:38:10 +02:00
|
|
|
const float box_x = cx + 100.0f;
|
|
|
|
|
const float box_y = oy + 148.0f;
|
|
|
|
|
const float box_w = std::clamp(vw - box_x - 28.0f, 180.0f, 340.0f);
|
|
|
|
|
const float box_h = 264.0f;
|
2026-11-30 22:31:51 +02:00
|
|
|
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));
|
|
|
|
|
int sw = 0, sh = 0;
|
|
|
|
|
if (ui_ren_.get_bank_sprite_size("track", preview_idx, sw, sh)) {
|
|
|
|
|
constexpr float kPad = 16.0f;
|
|
|
|
|
float sc = std::min((box_w - 2.0f * kPad) / std::max(sw, 1),
|
|
|
|
|
(box_h - 2.0f * kPad) / std::max(sh, 1));
|
|
|
|
|
float draw_w = static_cast<float>(sw) * sc;
|
|
|
|
|
float draw_h = static_cast<float>(sh) * sc;
|
|
|
|
|
float sx = box_x + (box_w - draw_w) * 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));
|
|
|
|
|
}
|
2026-12-01 09:38:10 +02:00
|
|
|
const float left_x = std::max(36.0f, cx - 460.0f);
|
|
|
|
|
const float max_w = std::max(220.0f, box_x - left_x - 24.0f);
|
2026-11-30 22:31:51 +02:00
|
|
|
const char* tnames[6] = {
|
|
|
|
|
"1. AMAZON DELTA TURNPIKE", "2. TRANS-ASIA INTERSTATE", "3. SHANGHAI DRAGON",
|
|
|
|
|
"4. NEW CHERNOBYL CENTRAL", "5. SLAM CANYON", "6. THRAK CITY"
|
|
|
|
|
};
|
2026-11-30 23:57:29 +02:00
|
|
|
std::string row1 = (selected_mode_ == sim::GameMode::DeathMatch)
|
|
|
|
|
? ("KILL LIMIT: < " + std::to_string(cfg_.deathmatch_kill_limit) + " >")
|
|
|
|
|
: (std::string(str.laps) + ": < " + std::to_string(selected_laps_) + " >");
|
|
|
|
|
std::string row3 = (selected_mode_ == sim::GameMode::CloneRace)
|
|
|
|
|
? (std::string(str.opponents) + ": CLONE GHOST")
|
|
|
|
|
: (std::string(str.opponents) + ": < " + std::to_string(selected_opponents_) + " >");
|
2026-11-30 22:31:51 +02:00
|
|
|
std::string rows[5] = {
|
|
|
|
|
std::string("TRACK: ") + tnames[selected_track_ - 1],
|
2026-11-30 23:57:29 +02:00
|
|
|
row1,
|
|
|
|
|
std::string(str.difficulty) + ": < " + diff_label(selected_difficulty_) + " >",
|
|
|
|
|
row3,
|
2026-11-30 22:31:51 +02:00
|
|
|
"NEXT: SELECT VEHICLE >>"
|
|
|
|
|
};
|
|
|
|
|
for (int i = 0; i < 5; ++i) {
|
|
|
|
|
bool sel = (i == menu_cursor_);
|
2026-12-01 09:38:10 +02:00
|
|
|
ui_ren_.draw_text_fit(left_x, oy + 166.0f + i * 48.0f, max_w, 2.0f, rows[i],
|
2026-11-30 23:41:37 +02:00
|
|
|
sel ? Vec4(1, 0.92f, 0.2f, 1) : Vec4(0.85f, 0.9f, 1, 1));
|
2026-11-30 22:31:51 +02:00
|
|
|
}
|
|
|
|
|
const auto& rec = hiscores_.tracks[selected_track_ - 1];
|
2026-12-01 09:38:10 +02:00
|
|
|
ui_ren_.draw_text_fit(left_x, oy + 448.0f, vw - left_x - 32.0f, 1.8f,
|
2026-11-30 23:41:37 +02:00
|
|
|
"BEST LAP: " + format_time(rec.best_lap) + " (" + rec.best_lap_driver + ")",
|
|
|
|
|
Vec4(0.4f, 1, 0.65f, 1));
|
2026-12-01 09:38:10 +02:00
|
|
|
ui_ren_.draw_text_fit(left_x, oy + 482.0f, vw - left_x - 32.0f, 1.8f,
|
2026-11-30 23:41:37 +02:00
|
|
|
"BEST RACE: " + format_time(rec.best_race) + " (" + rec.best_race_driver + ")",
|
|
|
|
|
Vec4(0.4f, 1, 0.65f, 1));
|
2026-11-30 22:31:51 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (state_ == ScreenState::VehicleSelect) {
|
2026-12-01 09:38:10 +02:00
|
|
|
ui_ren_.draw_text_centered(cx, oy + 76.0f, 2.55f, str.select_car, Vec4(0.4f, 0.85f, 1, 1));
|
|
|
|
|
float bx = 0.0f, by = 0.0f, bw = 0.0f, bh = 0.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);
|
2026-11-30 23:57:29 +02:00
|
|
|
bool is_split = (selected_mode_ == sim::GameMode::SplitScreen);
|
2026-11-30 23:41:37 +02:00
|
|
|
|
2026-11-30 23:57:29 +02:00
|
|
|
auto draw_pilot_row = [&](float ry, const char* prefix, const std::string& cur_val,
|
|
|
|
|
int target_id, bool sel) {
|
|
|
|
|
if (editing_name_target_ == target_id) {
|
|
|
|
|
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,
|
|
|
|
|
Vec4(1.0f, 0.88f, 0.2f, 1.0f));
|
2026-12-01 09:38:10 +02:00
|
|
|
ui_ren_.draw_text_fit(left_x, ry, max_w, 1.85f, std::string(prefix) + edit_display,
|
2026-11-30 23:57:29 +02:00
|
|
|
Vec4(1.0f, 0.96f, 0.3f, 1.0f));
|
|
|
|
|
} else {
|
|
|
|
|
std::string pline = std::string(prefix) + cur_val + (sel ? " [ENTER EDIT]" : "");
|
2026-12-01 09:38:10 +02:00
|
|
|
ui_ren_.draw_text_fit(left_x, ry, max_w, 1.85f, pline,
|
2026-11-30 23:57:29 +02:00
|
|
|
sel ? Vec4(1, 0.92f, 0.2f, 1) : Vec4(0.45f, 0.95f, 0.65f, 1));
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2026-12-01 09:38:10 +02:00
|
|
|
draw_pilot_row(oy + 136.0f, is_split ? "P1 NAME: " : "PILOT NAME: ", cfg_.player_name, 1, menu_cursor_ == 0);
|
2026-11-30 23:41:37 +02:00
|
|
|
|
2026-11-30 22:31:51 +02:00
|
|
|
const auto& sp = sim::kVehicleSpecs[p1_veh_];
|
2026-12-01 09:38:10 +02:00
|
|
|
ui_ren_.draw_text_fit(left_x, oy + 174.0f, max_w, 1.95f,
|
2026-11-30 23:41:37 +02:00
|
|
|
std::string("P1 VEHICLE: < ") + sp.name + " >",
|
|
|
|
|
menu_cursor_ == 1 ? Vec4(1, 0.92f, 0.2f, 1) : Vec4(0.85f, 0.9f, 1, 1));
|
2026-12-01 09:38:10 +02:00
|
|
|
ui_ren_.draw_text_fit(left_x, oy + 208.0f, max_w, 1.85f,
|
2026-11-30 23:41:37 +02:00
|
|
|
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));
|
2026-11-30 22:31:51 +02:00
|
|
|
|
|
|
|
|
auto draw_stat = [&](float y, const char* lbl, int val) {
|
2026-12-01 09:38:10 +02:00
|
|
|
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));
|
2026-11-30 22:31:51 +02:00
|
|
|
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);
|
2026-12-01 09:38:10 +02:00
|
|
|
ui_ren_.draw_rect(bar_x0 + b * cell_step, y, cell_step - 4.0f, 13.0f, col);
|
2026-11-30 22:31:51 +02:00
|
|
|
}
|
|
|
|
|
};
|
2026-12-01 09:38:10 +02:00
|
|
|
draw_stat(oy + 248.0f, str.weight, sp.stat_weight);
|
|
|
|
|
draw_stat(oy + 272.0f, str.armour, sp.stat_armour);
|
|
|
|
|
draw_stat(oy + 296.0f, str.speed, sp.stat_speed);
|
|
|
|
|
draw_stat(oy + 320.0f, str.firepower, sp.stat_firepower);
|
2026-11-30 22:31:51 +02:00
|
|
|
|
2026-11-30 23:41:37 +02:00
|
|
|
int start_row = 3;
|
2026-11-30 23:57:29 +02:00
|
|
|
if (is_split) {
|
2026-11-30 22:31:51 +02:00
|
|
|
const auto& sp2 = sim::kVehicleSpecs[p2_veh_];
|
2026-12-01 09:38:10 +02:00
|
|
|
draw_pilot_row(oy + 358.0f, "P2 NAME: ", cfg_.player2_name, 2, menu_cursor_ == 3);
|
|
|
|
|
ui_ren_.draw_text_fit(left_x, oy + 392.0f, max_w, 1.85f,
|
2026-11-30 23:41:37 +02:00
|
|
|
std::string("P2 VEHICLE: < ") + sp2.name + " >",
|
|
|
|
|
menu_cursor_ == 4 ? Vec4(1, 0.92f, 0.2f, 1) : Vec4(0.85f, 0.9f, 1, 1));
|
2026-12-01 09:38:10 +02:00
|
|
|
ui_ren_.draw_text_fit(left_x, oy + 426.0f, max_w, 1.85f,
|
2026-11-30 23:57:29 +02:00
|
|
|
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));
|
|
|
|
|
start_row = 6;
|
2026-11-30 23:41:37 +02:00
|
|
|
}
|
2026-12-01 09:38:10 +02:00
|
|
|
ui_ren_.draw_text_fit(left_x, oy + 482.0f, max_w, 2.3f, "START RACE >>",
|
2026-11-30 23:41:37 +02:00
|
|
|
menu_cursor_ == start_row ? Vec4(0.3f, 1.0f, 0.45f, 1) : Vec4(0.8f, 0.9f, 1, 1));
|
|
|
|
|
|
2026-11-30 23:57:29 +02:00
|
|
|
if (editing_name_target_ != 0) {
|
2026-12-01 09:38:10 +02:00
|
|
|
ui_ren_.draw_text_centered_fit(cx, vh - 30.0f,
|
|
|
|
|
vw - 40.0f, 1.5f,
|
2026-11-30 23:41:37 +02:00
|
|
|
"TYPE PILOT NAME BACKSPACE DELETE ENTER SAVE ESC CANCEL",
|
|
|
|
|
Vec4(1.0f, 0.9f, 0.35f, 1.0f));
|
|
|
|
|
} else if (status_toast_timer_ > 0.0f) {
|
2026-12-01 09:38:10 +02:00
|
|
|
ui_ren_.draw_text_centered(cx, vh - 36.0f, 1.85f, status_toast_,
|
2026-11-30 23:41:37 +02:00
|
|
|
Vec4(0.3f, 1.0f, 0.5f, 1));
|
2026-11-30 22:31:51 +02:00
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (state_ == ScreenState::Highscores) {
|
2026-12-01 09:38:10 +02:00
|
|
|
ui_ren_.draw_text_centered(cx, oy + 76.0f, 2.55f, str.highscores, Vec4(0.4f, 0.85f, 1, 1));
|
2026-11-30 22:31:51 +02:00
|
|
|
const char* tnames[6] = {"AMAZON DELTA", "TRANS-ASIA", "SHANGHAI DRAGON", "NEW CHERNOBYL", "SLAM CANYON", "THRAK CITY"};
|
2026-12-01 09:38:10 +02:00
|
|
|
float tbl_w = std::min(900.0f, vw - 48.0f);
|
2026-11-30 23:41:37 +02:00
|
|
|
float c_trk = cx - tbl_w * 0.5f;
|
|
|
|
|
float c_lap = c_trk + tbl_w * 0.30f;
|
|
|
|
|
float c_rac = c_trk + tbl_w * 0.65f;
|
2026-12-01 09:38:10 +02:00
|
|
|
float hdr_y = oy + 140.0f;
|
|
|
|
|
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.75f, "BEST LAP", 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));
|
2026-11-30 23:41:37 +02:00
|
|
|
|
2026-11-30 22:31:51 +02:00
|
|
|
for (int i = 0; i < 6; ++i) {
|
|
|
|
|
const auto& r = hiscores_.tracks[i];
|
2026-12-01 09:38:10 +02:00
|
|
|
float ry = oy + 178.0f + i * 44.0f;
|
2026-11-30 23:41:37 +02:00
|
|
|
std::string col0 = std::to_string(i + 1) + ". " + tnames[i];
|
|
|
|
|
std::string col1 = format_time(r.best_lap) + " (" + r.best_lap_driver + ")";
|
|
|
|
|
std::string col2 = format_time(r.best_race) + " (" + r.best_race_driver + ")";
|
2026-12-01 09:38:10 +02:00
|
|
|
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.7f, col1, 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));
|
2026-11-30 22:31:51 +02:00
|
|
|
}
|
2026-12-01 09:38:10 +02:00
|
|
|
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));
|
2026-11-30 22:31:51 +02:00
|
|
|
if (status_toast_timer_ > 0.0f) {
|
2026-12-01 09:38:10 +02:00
|
|
|
ui_ren_.draw_text_centered(cx, oy + 520.0f, 2.0f, status_toast_, Vec4(0.3f, 1, 0.5f, 1));
|
2026-11-30 22:31:51 +02:00
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (state_ == ScreenState::Options) {
|
2026-12-01 09:38:10 +02:00
|
|
|
ui_ren_.draw_text_centered(cx, oy + 76.0f, 2.55f, str.options, Vec4(0.4f, 0.85f, 1, 1));
|
2026-11-30 23:57:29 +02:00
|
|
|
const char* tabs[7] = {"VIDEO", "AUDIO", "CONTROLS P1", "CONTROLS P2", "INPUT / PAD", "GAME", "RULES"};
|
2026-11-30 22:31:51 +02:00
|
|
|
std::string tab_str = std::string("CATEGORY: < ") + tabs[static_cast<int>(opt_tab_)] + " >";
|
2026-12-01 09:38:10 +02:00
|
|
|
ui_ren_.draw_text_centered(cx, oy + 130.0f, 2.1f, tab_str,
|
2026-11-30 22:31:51 +02:00
|
|
|
menu_cursor_ == 0 ? Vec4(1, 0.92f, 0.2f, 1) : Vec4(0.5f, 0.85f, 1, 1));
|
|
|
|
|
|
2026-11-30 23:57:29 +02:00
|
|
|
auto on_off = [](bool b) -> const char* { return b ? "ON" : "OFF"; };
|
2026-11-30 22:31:51 +02:00
|
|
|
std::vector<std::string> rows;
|
2026-11-30 23:57:29 +02:00
|
|
|
int edit_row_idx = -1;
|
|
|
|
|
|
2026-11-30 22:31:51 +02:00
|
|
|
if (opt_tab_ == OptionsTab::Video) {
|
|
|
|
|
rows.push_back("RESOLUTION: " + std::to_string(cfg_.window_width) + "X" + std::to_string(cfg_.window_height));
|
2026-11-30 23:57:29 +02:00
|
|
|
rows.push_back(std::string("FULLSCREEN: ") + on_off(cfg_.fullscreen));
|
|
|
|
|
rows.push_back(std::string("VSYNC: ") + on_off(cfg_.vsync));
|
|
|
|
|
rows.push_back(std::string("MSAA: ") + (cfg_.msaa_samples >= 2 ? (std::to_string(cfg_.msaa_samples) + "X") : "OFF"));
|
|
|
|
|
rows.push_back("FIELD OF VIEW: " + std::to_string(static_cast<int>(cfg_.fov_deg)) + " DEG");
|
2026-11-30 22:31:51 +02:00
|
|
|
rows.push_back("DRAW DISTANCE: " + std::to_string(static_cast<int>(cfg_.draw_distance)) + " TILES");
|
|
|
|
|
rows.push_back(std::string("TEXTURE FILTER: ") + (cfg_.texture_filter == TextureFilterMode::Linear ? "LINEAR" : "NEAREST"));
|
|
|
|
|
std::string cm = !cfg_.classic_mode ? "MODERN OPENGL" : (cfg_.classic_hires ? "CLASSIC 640X480" : "CLASSIC 320X200");
|
|
|
|
|
rows.push_back("RENDER MODE: " + cm);
|
2026-11-30 23:57:29 +02:00
|
|
|
rows.push_back(std::string("CLASSIC SCANLINES: ") + on_off(cfg_.classic_scanlines));
|
2026-11-30 22:31:51 +02:00
|
|
|
} else if (opt_tab_ == OptionsTab::Audio) {
|
|
|
|
|
rows.push_back(std::string("MUSIC BACKEND: ") + backend_label(cfg_.music_backend));
|
2026-11-30 23:57:29 +02:00
|
|
|
rows.push_back("MASTER VOLUME: " + std::to_string(static_cast<int>(std::round(cfg_.master_volume * 100.0f))) + "%");
|
|
|
|
|
rows.push_back("SFX VOLUME: " + std::to_string(static_cast<int>(std::round(cfg_.sfx_volume * 100.0f))) + "%");
|
|
|
|
|
rows.push_back("MUSIC VOLUME: " + std::to_string(static_cast<int>(std::round(cfg_.music_volume * 100.0f))) + "%");
|
|
|
|
|
rows.push_back(std::string("MUTE ON FOCUS LOSS: ") + on_off(cfg_.mute_on_focus_loss));
|
|
|
|
|
std::string sf_lbl = cfg_.custom_soundfont_path.empty()
|
|
|
|
|
? "BUILT-IN (BULLFROG.SBK)"
|
|
|
|
|
: std::filesystem::path(cfg_.custom_soundfont_path).filename().string();
|
|
|
|
|
rows.push_back("SOUNDFONT: " + sf_lbl);
|
|
|
|
|
} else if (opt_tab_ == OptionsTab::ControlsP1) {
|
|
|
|
|
const char* klabels[10] = {"STEER LEFT", "STEER RIGHT", "ACCELERATE", "BRAKE", "BOOST",
|
|
|
|
|
"FIRE MINIGUN", "FIRE MISSILE", "AUTO PILOT", "CAMERA VIEW", "HUD TOGGLE"};
|
|
|
|
|
int kvals[10] = {cfg_.keys.steer_left, cfg_.keys.steer_right, cfg_.keys.accelerate,
|
|
|
|
|
cfg_.keys.brake, cfg_.keys.boost, cfg_.keys.fire_minigun,
|
|
|
|
|
cfg_.keys.fire_missile, cfg_.keys.autopilot, cfg_.keys.camera_view,
|
|
|
|
|
cfg_.keys.hud_toggle};
|
|
|
|
|
for (int i = 0; i < 10; ++i) {
|
2026-11-30 22:31:51 +02:00
|
|
|
std::string kname = (rebind_slot_ == i) ? "[PRESS KEY...]" : InputManager::scancode_name(kvals[i]);
|
|
|
|
|
rows.push_back(std::string(klabels[i]) + ": " + kname);
|
|
|
|
|
}
|
2026-11-30 23:57:29 +02:00
|
|
|
} else if (opt_tab_ == OptionsTab::ControlsP2) {
|
|
|
|
|
const char* klabels[7] = {"P2 STEER LEFT", "P2 STEER RIGHT", "P2 ACCELERATE", "P2 BRAKE",
|
|
|
|
|
"P2 BOOST", "P2 FIRE MINIGUN", "P2 FIRE MISSILE"};
|
|
|
|
|
int kvals[7] = {cfg_.keys.p2_steer_left, cfg_.keys.p2_steer_right, cfg_.keys.p2_accelerate,
|
|
|
|
|
cfg_.keys.p2_brake, cfg_.keys.p2_boost, cfg_.keys.p2_fire_minigun,
|
|
|
|
|
cfg_.keys.p2_fire_missile};
|
|
|
|
|
for (int i = 0; i < 7; ++i) {
|
|
|
|
|
std::string kname = (rebind_slot_ == 10 + i) ? "[PRESS KEY...]" : InputManager::scancode_name(kvals[i]);
|
|
|
|
|
rows.push_back(std::string(klabels[i]) + ": " + kname);
|
|
|
|
|
}
|
|
|
|
|
} else if (opt_tab_ == OptionsTab::InputPad) {
|
|
|
|
|
auto pad_desc = [&](int slot) -> std::string {
|
|
|
|
|
if (slot < 0) return "KEYBOARD ONLY";
|
|
|
|
|
std::string gn = input_.gamepad_name(slot);
|
|
|
|
|
if (gn == "None") return "SLOT " + std::to_string(slot + 1) + " [EMPTY]";
|
|
|
|
|
if (gn.size() > 16) gn = gn.substr(0, 16);
|
|
|
|
|
return "SLOT " + std::to_string(slot + 1) + " [" + gn + "]";
|
|
|
|
|
};
|
|
|
|
|
rows.push_back("P1 GAMEPAD: " + pad_desc(cfg_.p1_gamepad_index));
|
|
|
|
|
rows.push_back("P2 GAMEPAD: " + pad_desc(cfg_.p2_gamepad_index));
|
|
|
|
|
rows.push_back("GAMEPAD DEADZONE: " + std::to_string(static_cast<int>(std::round(cfg_.gamepad_deadzone * 100.0f))) + "%");
|
|
|
|
|
rows.push_back("STEER SENSITIVITY: " + std::to_string(static_cast<int>(std::round(cfg_.steering_sensitivity * 100.0f))) + "%");
|
|
|
|
|
char curve_buf[24];
|
|
|
|
|
std::snprintf(curve_buf, sizeof(curve_buf), "%.2f", cfg_.steering_curve);
|
|
|
|
|
rows.push_back(std::string("STEER CURVE: ") + curve_buf);
|
|
|
|
|
rows.push_back(std::string("RUMBLE HAPTICS: ") + on_off(cfg_.rumble_enabled));
|
|
|
|
|
rows.push_back(std::string("MOUSE STEERING: ") + on_off(cfg_.mouse_steering));
|
|
|
|
|
} else if (opt_tab_ == OptionsTab::Game) {
|
|
|
|
|
if (editing_name_target_ == 1) {
|
|
|
|
|
rows.push_back("PLAYER 1 NAME: " + edit_display);
|
|
|
|
|
edit_row_idx = 0;
|
2026-11-30 23:41:37 +02:00
|
|
|
} else {
|
2026-11-30 23:57:29 +02:00
|
|
|
rows.push_back("PLAYER 1 NAME: " + cfg_.player_name + " [ENTER EDIT]");
|
|
|
|
|
}
|
|
|
|
|
if (editing_name_target_ == 2) {
|
|
|
|
|
rows.push_back("PLAYER 2 NAME: " + edit_display);
|
|
|
|
|
edit_row_idx = 1;
|
|
|
|
|
} else {
|
|
|
|
|
rows.push_back("PLAYER 2 NAME: " + cfg_.player2_name + " [ENTER EDIT]");
|
2026-11-30 23:41:37 +02:00
|
|
|
}
|
2026-11-30 22:31:51 +02:00
|
|
|
rows.push_back(std::string("LANGUAGE: ") + lang_label(cfg_.language));
|
2026-11-30 23:57:29 +02:00
|
|
|
rows.push_back(std::string("DEFAULT CAMERA: ") + camera_label(cfg_.default_camera));
|
|
|
|
|
rows.push_back(std::string("SHOW HUD: ") + on_off(cfg_.show_hud));
|
|
|
|
|
rows.push_back(std::string("SHOW MINIMAP: ") + on_off(cfg_.show_minimap));
|
|
|
|
|
rows.push_back(std::string("SKIP INTRO: ") + on_off(cfg_.skip_intro));
|
|
|
|
|
} else {
|
|
|
|
|
rows.push_back(std::string("DIFFICULTY: < ") + diff_label(cfg_.difficulty) + " >");
|
|
|
|
|
rows.push_back("DEFAULT LAPS: " + std::to_string(cfg_.default_laps));
|
|
|
|
|
rows.push_back("DEATHMATCH KILLS: " + std::to_string(cfg_.deathmatch_kill_limit));
|
|
|
|
|
rows.push_back(std::string("FUEL CONSUMPTION: ") + on_off(cfg_.fuel_enabled));
|
|
|
|
|
rows.push_back(std::string("SHIELD DAMAGE: ") + on_off(cfg_.damage_enabled));
|
|
|
|
|
rows.push_back(std::string("WEAPONS / COMBAT: ") + on_off(cfg_.weapons_enabled));
|
|
|
|
|
rows.push_back(std::string("TRACK PICKUPS: ") + on_off(cfg_.pickups_enabled));
|
|
|
|
|
rows.push_back(std::string("TRACK MORPHING: ") + on_off(cfg_.track_morphing_enabled));
|
2026-11-30 22:31:51 +02:00
|
|
|
}
|
|
|
|
|
|
2026-12-01 09:38:10 +02:00
|
|
|
const float ry_start = oy + 178.0f;
|
|
|
|
|
const float avail_h = std::max(240.0f, oy + 520.0f - ry_start);
|
|
|
|
|
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.7f : 1.9f;
|
|
|
|
|
const float opt_max_w = vw - 64.0f;
|
2026-11-30 22:31:51 +02:00
|
|
|
for (size_t i = 0; i < rows.size(); ++i) {
|
2026-11-30 23:57:29 +02:00
|
|
|
float ry = ry_start + static_cast<float>(i) * step_y;
|
2026-11-30 22:31:51 +02:00
|
|
|
bool sel = (static_cast<int>(i) + 1 == menu_cursor_);
|
2026-11-30 23:57:29 +02:00
|
|
|
if (static_cast<int>(i) == edit_row_idx) {
|
2026-11-30 23:41:37 +02:00
|
|
|
float bw = std::min(500.0f, opt_max_w);
|
|
|
|
|
ui_ren_.draw_rect(cx - bw * 0.5f, ry - 6.0f, bw, 28.0f, Vec4(0.16f, 0.34f, 0.68f, 0.85f));
|
|
|
|
|
ui_ren_.draw_rect_outline(cx - bw * 0.5f, ry - 6.0f, bw, 28.0f, 2.0f,
|
|
|
|
|
Vec4(1.0f, 0.88f, 0.2f, 1.0f));
|
|
|
|
|
}
|
2026-11-30 23:57:29 +02:00
|
|
|
ui_ren_.draw_text_centered_fit(cx, ry, opt_max_w, font_sz, rows[i],
|
2026-11-30 23:41:37 +02:00
|
|
|
sel ? Vec4(1, 0.92f, 0.2f, 1) : Vec4(0.85f, 0.9f, 1, 1));
|
2026-11-30 22:31:51 +02:00
|
|
|
}
|
2026-11-30 23:57:29 +02:00
|
|
|
if (status_toast_timer_ > 0.0f && editing_name_target_ == 0) {
|
2026-12-01 09:38:10 +02:00
|
|
|
ui_ren_.draw_text_centered(cx, vh - 64.0f, 1.85f,
|
2026-11-30 23:41:37 +02:00
|
|
|
status_toast_, Vec4(0.3f, 1.0f, 0.5f, 1.0f));
|
|
|
|
|
}
|
2026-11-30 23:57:29 +02:00
|
|
|
const char* footer = (editing_name_target_ != 0)
|
2026-11-30 23:41:37 +02:00
|
|
|
? "TYPE PLAYER NAME BACKSPACE DELETE ENTER SAVE ESC CANCEL"
|
|
|
|
|
: "LEFT/RIGHT ADJUST ENTER EDIT/TOGGLE ESC SAVE & BACK";
|
2026-12-01 09:38:10 +02:00
|
|
|
ui_ren_.draw_text_centered_fit(cx, vh - 30.0f,
|
|
|
|
|
vw - 40.0f, 1.5f, footer,
|
2026-11-30 23:57:29 +02:00
|
|
|
(editing_name_target_ != 0) ? Vec4(1.0f, 0.9f, 0.35f, 1.0f)
|
2026-12-01 09:38:10 +02:00
|
|
|
: Vec4(0.65f, 0.76f, 0.92f, 1));
|
2026-11-30 22:31:51 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (state_ == ScreenState::PostRace) {
|
2026-12-01 09:38:10 +02:00
|
|
|
ui_ren_.draw_text_centered(cx, oy + 76.0f, 2.65f, str.race_over, Vec4(0.35f, 1.0f, 0.55f, 1));
|
2026-11-30 22:31:51 +02:00
|
|
|
if (post_race_record_flags_ & 1) {
|
2026-12-01 09:38:10 +02:00
|
|
|
ui_ren_.draw_text_centered(cx, oy + 114.0f, 1.9f, "NEW FASTEST LAP!", Vec4(1, 0.9f, 0.2f, 1));
|
2026-11-30 22:31:51 +02:00
|
|
|
}
|
|
|
|
|
if (post_race_page_ == 0) {
|
|
|
|
|
auto sorted = race_sim_.crafts();
|
|
|
|
|
std::sort(sorted.begin(), sorted.end(), [](const auto& a, const auto& b) {
|
|
|
|
|
return a.placement < b.placement;
|
|
|
|
|
});
|
2026-12-01 09:38:10 +02:00
|
|
|
float tbl_w = std::min(900.0f, vw - 48.0f);
|
2026-11-30 23:41:37 +02:00
|
|
|
float c0 = cx - tbl_w * 0.5f;
|
|
|
|
|
float c1 = c0 + tbl_w * 0.09f;
|
|
|
|
|
float c2 = c0 + tbl_w * 0.31f;
|
2026-12-01 08:33:48 +02:00
|
|
|
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;
|
2026-12-01 09:38:10 +02:00
|
|
|
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, oy + 150.0f, tbl_w * 0.21f, 1.7f, str.driver, 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, 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, oy + 150.0f, tbl_w * 0.12f, 1.7f, "KILLS", 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));
|
2026-12-01 08:33:48 +02:00
|
|
|
for (size_t i = 0; i < sorted.size(); ++i) {
|
|
|
|
|
const auto& c = sorted[i];
|
2026-12-01 09:38:10 +02:00
|
|
|
float ry = oy + 186.0f + static_cast<float>(i) * 32.0f;
|
2026-12-01 08:33:48 +02:00
|
|
|
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);
|
2026-12-01 09:38:10 +02:00
|
|
|
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.7f, c.pilot_name, 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.7f, format_time(c.best_lap_time), 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.7f, std::to_string(c.deaths), col);
|
2026-12-01 08:33:48 +02:00
|
|
|
}
|
|
|
|
|
} 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;
|
2026-12-01 09:38:10 +02:00
|
|
|
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, oy + 150.0f, tbl_w * 0.21f, 1.7f, str.driver, 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, 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, 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, oy + 150.0f, tbl_w * 0.09f, 1.7f, "KILLS", Vec4(0.4f, 0.85f, 1, 1));
|
2026-12-01 08:33:48 +02:00
|
|
|
for (size_t i = 0; i < sorted.size(); ++i) {
|
|
|
|
|
const auto& c = sorted[i];
|
2026-12-01 09:38:10 +02:00
|
|
|
float ry = oy + 186.0f + static_cast<float>(i) * 32.0f;
|
2026-12-01 08:33:48 +02:00
|
|
|
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);
|
2026-12-01 09:38:10 +02:00
|
|
|
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.7f, c.pilot_name, 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.7f, format_time(c.race_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.7f, std::to_string(c.kills), col);
|
2026-12-01 08:33:48 +02:00
|
|
|
}
|
2026-11-30 22:31:51 +02:00
|
|
|
}
|
|
|
|
|
} else if (post_race_page_ == 1 && !race_sim_.crafts().empty()) {
|
|
|
|
|
const auto& p1 = race_sim_.crafts()[0];
|
2026-12-01 09:38:10 +02:00
|
|
|
ui_ren_.draw_text_centered(cx, oy + 152.0f, 2.25f, str.statistics, Vec4(0.4f, 0.85f, 1, 1));
|
2026-11-30 22:31:51 +02:00
|
|
|
int acc = (p1.shots_fired > 0) ? (p1.shots_hit * 100 / p1.shots_fired) : 0;
|
2026-12-01 09:38:10 +02:00
|
|
|
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.0f, oy + 250.0f, 2.0f, "HIT ACCURACY: " + std::to_string(acc) + "%");
|
|
|
|
|
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.0f, oy + 330.0f, 2.0f, "ARMOUR USED: " + std::to_string(static_cast<int>(p1.armour_used)));
|
2026-11-30 22:31:51 +02:00
|
|
|
if (selected_mode_ == sim::GameMode::Championship) {
|
2026-12-01 09:38:10 +02:00
|
|
|
ui_ren_.draw_text(cx - 240.0f, oy + 370.0f, 2.0f, "RATING: " + champ_.player_rating_title(), Vec4(1, 0.9f, 0.2f, 1));
|
2026-11-30 22:31:51 +02:00
|
|
|
}
|
|
|
|
|
} else if (selected_mode_ == sim::GameMode::Championship) {
|
2026-12-01 09:38:10 +02:00
|
|
|
ui_ren_.draw_text_centered(cx, oy + 152.0f, 2.25f, "CHAMPIONSHIP TABLE", Vec4(0.4f, 0.85f, 1, 1));
|
2026-11-30 22:31:51 +02:00
|
|
|
auto ds = champ_.drivers;
|
|
|
|
|
std::sort(ds.begin(), ds.end(), [](const auto& a, const auto& b) { return a.points > b.points; });
|
2026-12-01 09:38:10 +02:00
|
|
|
float tbl_w = std::min(720.0f, vw - 48.0f);
|
2026-11-30 23:41:37 +02:00
|
|
|
float c0 = cx - tbl_w * 0.5f;
|
|
|
|
|
float c1 = c0 + tbl_w * 0.10f;
|
|
|
|
|
float c2 = c0 + tbl_w * 0.40f;
|
|
|
|
|
float c3 = c0 + tbl_w * 0.70f;
|
|
|
|
|
float c4 = c0 + tbl_w * 0.84f;
|
2026-11-30 22:31:51 +02:00
|
|
|
for (size_t i = 0; i < ds.size(); ++i) {
|
2026-12-01 09:38:10 +02:00
|
|
|
float ry = oy + 200.0f + static_cast<float>(i) * 32.0f;
|
2026-12-01 08:33:48 +02:00
|
|
|
Vec4 col = (ds[i].name == cfg_.player_name)
|
2026-11-30 23:41:37 +02:00
|
|
|
? Vec4(1, 0.95f, 0.25f, 1)
|
|
|
|
|
: Vec4(0.9f, 0.95f, 1, 1);
|
2026-12-01 09:38:10 +02:00
|
|
|
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.75f, ds[i].name, 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.75f, std::to_string(ds[i].points) + " PTS", col);
|
|
|
|
|
ui_ren_.draw_text_fit(c4, ry, tbl_w * 0.16f, 1.75f, std::to_string(ds[i].wins) + " W", col);
|
2026-11-30 22:31:51 +02:00
|
|
|
}
|
|
|
|
|
}
|
2026-12-01 09:38:10 +02:00
|
|
|
ui_ren_.draw_text_centered_fit(cx, oy + 505.0f, vw - 48.0f, 1.9f,
|
2026-11-30 23:41:37 +02:00
|
|
|
"LEFT/RIGHT STATS PAGE ENTER CONTINUE", Vec4(1, 0.85f, 0.2f, 1));
|
2026-11-30 22:31:51 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace top_octane::game
|