#include #include "imgui.h" #include "engine/simulation.h" #include "gui/gui.h" int main() { Gui gui; if (!gui.init()) return 1; Simulation sim; const double SIM_DT = 1.0 / 360.0; double accumulator = 0.0; auto last_time = std::chrono::steady_clock::now(); while (gui.begin_frame()) { // 'r' resets the engine (rpm -> 0). false = don't auto-repeat while held. if (ImGui::IsKeyPressed(ImGuiKey_R, false)) { sim.engine().reset(); } auto now = std::chrono::steady_clock::now(); double frame_time = std::chrono::duration(now - last_time).count(); last_time = now; if (frame_time > 0.25) frame_time = 0.25; // clamp huge stalls (e.g. breakpoint) accumulator += frame_time; while (accumulator >= SIM_DT) { sim.step(SIM_DT); accumulator -= SIM_DT; } // Build this frame's display data. Only rpm is real right now; // the rest are placeholders until those models exist. EngineStats stats; stats.rpm = sim.engine().rpm(); stats.fuel_consumption_lph = 0.0; // TODO: derive from fuel model stats.crank_power_kw = 0.0; // TODO: torque_nm * rpm -> kW stats.output_heat_j = 0.0; // TODO: energy balance / exhaust heat model stats.extra_stats.push_back({"Oil Temp", 0.0, "C"}); stats.extra_stats.push_back({"Coolant Temp", 0.0, "C"}); gui.render(stats); gui.end_frame(); } gui.shutdown(); return 0; }