Branch data Line data Source code
1 : : #include "GuiLayer.h"
2 : : #include "Version.h"
3 : : #include "Config.h"
4 : : #include "Tooltips.h"
5 : : #include "DirectInputFFB.h"
6 : : #include "GameConnector.h"
7 : : #include "GuiWidgets.h"
8 : : #include "AsyncLogger.h"
9 : : #include <iostream>
10 : : #include <vector>
11 : : #include <cmath>
12 : : #include <algorithm>
13 : : #include <cstring>
14 : : #include <mutex>
15 : : #include <chrono>
16 : : #include <ctime>
17 : :
18 : : #ifdef ENABLE_IMGUI
19 : : #include "imgui.h"
20 : :
21 : 310 : static void DisplayRate(const char* label, double rate, double target) {
22 [ + - ]: 310 : ImGui::Text("%s", label);
23 : :
24 : : // Status colors for performance metrics
25 : : static const ImVec4 COLOR_RED(1.0F, 0.4F, 0.4F, 1.0F);
26 : : static const ImVec4 COLOR_GREEN(0.4F, 1.0F, 0.4F, 1.0F);
27 : : static const ImVec4 COLOR_YELLOW(1.0F, 1.0F, 0.4F, 1.0F);
28 : :
29 : 310 : ImVec4 color = COLOR_RED;
30 [ + + ]: 310 : if (rate >= target * 0.95) {
31 : 7 : color = COLOR_GREEN;
32 [ + + ]: 303 : } else if (rate >= target * 0.75) {
33 : 7 : color = COLOR_YELLOW;
34 : : }
35 : :
36 [ + - ]: 310 : ImGui::TextColored(color, "%.1f Hz", rate);
37 : 310 : }
38 : :
39 : :
40 : : // External linkage to FFB loop status
41 : : extern std::atomic<bool> g_running;
42 : : extern std::recursive_mutex g_engine_mutex;
43 : :
44 : : static const float CONFIG_PANEL_WIDTH = 500.0f;
45 : : static const int LATENCY_WARNING_THRESHOLD_MS = 15;
46 : :
47 : : // Professional "Flat Dark" Theme
48 : 1 : void GuiLayer::SetupGUIStyle() {
49 [ + - ]: 1 : ImGuiStyle& style = ImGui::GetStyle();
50 : :
51 : 1 : style.WindowRounding = 5.0f;
52 : 1 : style.FrameRounding = 4.0f;
53 : 1 : style.GrabRounding = 4.0f;
54 : 1 : style.FramePadding = ImVec2(8, 4);
55 : 1 : style.ItemSpacing = ImVec2(8, 6);
56 : :
57 : 1 : ImVec4* colors = style.Colors;
58 : :
59 : 1 : colors[ImGuiCol_WindowBg] = ImVec4(0.12f, 0.12f, 0.12f, 1.00f);
60 : 1 : colors[ImGuiCol_ChildBg] = ImVec4(0.15f, 0.15f, 0.15f, 1.00f);
61 : 1 : colors[ImGuiCol_PopupBg] = ImVec4(0.15f, 0.15f, 0.15f, 0.98f);
62 : :
63 : 1 : colors[ImGuiCol_Header] = ImVec4(0.20f, 0.20f, 0.20f, 0.00f);
64 : 1 : colors[ImGuiCol_HeaderHovered] = ImVec4(0.25f, 0.25f, 0.25f, 0.50f);
65 : 1 : colors[ImGuiCol_HeaderActive] = ImVec4(0.30f, 0.30f, 0.30f, 0.50f);
66 : :
67 : 1 : colors[ImGuiCol_FrameBg] = ImVec4(0.20f, 0.20f, 0.20f, 1.00f);
68 : 1 : colors[ImGuiCol_FrameBgHovered] = ImVec4(0.25f, 0.25f, 0.25f, 1.00f);
69 : 1 : colors[ImGuiCol_FrameBgActive] = ImVec4(0.30f, 0.30f, 0.30f, 1.00f);
70 : :
71 : 1 : ImVec4 accent = ImVec4(0.00f, 0.60f, 0.85f, 1.00f);
72 : 1 : colors[ImGuiCol_SliderGrab] = accent;
73 : 1 : colors[ImGuiCol_SliderGrabActive] = ImVec4(0.00f, 0.70f, 0.95f, 1.00f);
74 : 1 : colors[ImGuiCol_Button] = ImVec4(0.25f, 0.25f, 0.25f, 1.00f);
75 : 1 : colors[ImGuiCol_ButtonHovered] = accent;
76 : 1 : colors[ImGuiCol_ButtonActive] = ImVec4(0.00f, 0.50f, 0.75f, 1.00f);
77 : 1 : colors[ImGuiCol_CheckMark] = accent;
78 : :
79 : 1 : colors[ImGuiCol_Text] = ImVec4(0.90f, 0.90f, 0.90f, 1.00f);
80 : 1 : colors[ImGuiCol_TextDisabled] = ImVec4(0.50f, 0.50f, 0.50f, 1.00f);
81 : 1 : }
82 : :
83 : :
84 : : static constexpr std::chrono::seconds CONNECT_ATTEMPT_INTERVAL(2);
85 : :
86 : 377 : void GuiLayer::DrawTuningWindow(FFBEngine& engine) {
87 [ + - ]: 377 : std::lock_guard<std::recursive_mutex> lock(g_engine_mutex);
88 : :
89 [ + - ]: 377 : ImGuiViewport* viewport = ImGui::GetMainViewport();
90 [ + + ]: 377 : float current_width = Config::show_graphs ? CONFIG_PANEL_WIDTH : viewport->Size.x;
91 : :
92 [ + - ]: 377 : ImGui::SetNextWindowPos(viewport->Pos);
93 [ + - ]: 377 : ImGui::SetNextWindowSize(ImVec2(current_width, viewport->Size.y));
94 : :
95 : 377 : ImGuiWindowFlags flags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize;
96 [ + - ]: 377 : ImGui::Begin("MainUI", nullptr, flags);
97 : :
98 [ + - ]: 377 : ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(0.00f, 0.60f, 0.85f, 1.00f));
99 [ + - ]: 377 : ImGui::Text("lmuFFB");
100 [ + - ]: 377 : ImGui::PopStyleColor();
101 [ + - ]: 377 : ImGui::SameLine();
102 [ + - ]: 377 : ImGui::TextDisabled("v%s", LMUFFB_VERSION);
103 [ + - ]: 377 : ImGui::Separator();
104 : :
105 [ + + + - ]: 377 : static std::chrono::steady_clock::time_point last_check_time = std::chrono::steady_clock::now();
106 : :
107 [ + - + - : 377 : if (!GameConnector::Get().IsConnected()) {
+ + ]
108 [ + - ]: 208 : ImGui::TextColored(ImVec4(1, 1, 0, 1), "Connecting to LMU...");
109 [ + - + - : 208 : if (std::chrono::steady_clock::now() - last_check_time > CONNECT_ATTEMPT_INTERVAL) {
- + ]
110 : 0 : last_check_time = std::chrono::steady_clock::now();
111 [ # # # # ]: 0 : GameConnector::Get().TryConnect();
112 : : }
113 : : } else {
114 [ + - ]: 169 : ImGui::TextColored(ImVec4(0, 1, 0, 1), "Connected to LMU");
115 [ + - ]: 169 : ImGui::SameLine();
116 [ + - ]: 169 : ImGui::TextColored(ImVec4(0.7f, 0.7f, 0.7f, 1.0f), "| FFB: %.0fHz | Tel: %.0fHz", engine.m_ffb_rate, engine.m_telemetry_rate);
117 : : }
118 : :
119 [ + + + - ]: 377 : static std::vector<DeviceInfo> devices;
120 : : static int selected_device_idx = -1;
121 : :
122 [ + + ]: 377 : if (devices.empty()) {
123 [ + - + - ]: 1 : devices = DirectInputFFB::Get().EnumerateDevices();
124 [ + - + - : 1 : if (selected_device_idx == -1 && !Config::m_last_device_guid.empty()) {
+ - ]
125 [ + - ]: 1 : GUID target = DirectInputFFB::StringToGuid(Config::m_last_device_guid);
126 [ + + ]: 3 : for (int i = 0; i < (int)devices.size(); i++) {
127 [ - + ]: 2 : if (memcmp(&devices[i].guid, &target, sizeof(GUID)) == 0) {
128 : 0 : selected_device_idx = i;
129 [ # # # # ]: 0 : DirectInputFFB::Get().SelectDevice(devices[i].guid);
130 : 0 : break;
131 : : }
132 : : }
133 : : }
134 : : }
135 : :
136 [ + - + - ]: 377 : ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x * 0.4f);
137 [ - + + - : 377 : if (ImGui::BeginCombo("FFB Device", selected_device_idx >= 0 ? devices[selected_device_idx].name.c_str() : "Select Device...")) {
- + ]
138 [ # # ]: 0 : for (int i = 0; i < (int)devices.size(); i++) {
139 : 0 : bool is_selected = (selected_device_idx == i);
140 [ # # ]: 0 : ImGui::PushID(i);
141 [ # # # # ]: 0 : if (ImGui::Selectable(devices[i].name.c_str(), is_selected)) {
142 : 0 : selected_device_idx = i;
143 [ # # # # ]: 0 : DirectInputFFB::Get().SelectDevice(devices[i].guid);
144 [ # # ]: 0 : Config::m_last_device_guid = DirectInputFFB::GuidToString(devices[i].guid);
145 [ # # # # ]: 0 : Config::Save(engine);
146 : : }
147 [ # # # # ]: 0 : if (is_selected) ImGui::SetItemDefaultFocus();
148 [ # # ]: 0 : ImGui::PopID();
149 : : }
150 [ # # ]: 0 : ImGui::EndCombo();
151 : : }
152 [ + - + + : 377 : if (ImGui::IsItemHovered()) ImGui::SetTooltip("%s", Tooltips::DEVICE_SELECT);
+ - ]
153 : :
154 [ + - ]: 377 : ImGui::SameLine();
155 [ + - - + ]: 377 : if (ImGui::Button("Rescan")) {
156 [ # # # # ]: 0 : devices = DirectInputFFB::Get().EnumerateDevices();
157 : 0 : selected_device_idx = -1;
158 : : }
159 [ + - + + : 377 : if (ImGui::IsItemHovered()) ImGui::SetTooltip("%s", Tooltips::DEVICE_RESCAN);
+ - ]
160 [ + - ]: 377 : ImGui::SameLine();
161 [ + - - + ]: 377 : if (ImGui::Button("Unbind")) {
162 [ # # # # ]: 0 : DirectInputFFB::Get().ReleaseDevice();
163 : 0 : selected_device_idx = -1;
164 : : }
165 [ + - - + : 377 : if (ImGui::IsItemHovered()) ImGui::SetTooltip("%s", Tooltips::DEVICE_UNBIND);
- - ]
166 : :
167 [ + - - + ]: 377 : if (DirectInputFFB::Get().IsActive()) {
168 [ # # # # ]: 0 : if (DirectInputFFB::Get().IsExclusive()) {
169 [ # # ]: 0 : ImGui::TextColored(ImVec4(0.4f, 1.0f, 0.4f, 1.0f), "Mode: EXCLUSIVE (Game FFB Blocked)");
170 [ # # # # : 0 : if (ImGui::IsItemHovered()) ImGui::SetTooltip("%s", Tooltips::MODE_EXCLUSIVE);
# # ]
171 : : } else {
172 [ # # ]: 0 : ImGui::TextColored(ImVec4(1.0f, 1.0f, 0.4f, 1.0f), "Mode: SHARED (Potential Conflict)");
173 [ # # # # : 0 : if (ImGui::IsItemHovered()) ImGui::SetTooltip("%s", Tooltips::MODE_SHARED);
# # ]
174 : : }
175 : : } else {
176 [ + - ]: 377 : ImGui::TextColored(ImVec4(1.0f, 0.4f, 0.4f, 1.0f), "No device selected.");
177 [ + - + + : 377 : if (ImGui::IsItemHovered()) ImGui::SetTooltip("%s", Tooltips::NO_DEVICE);
+ - ]
178 : : }
179 : :
180 [ + - - + ]: 377 : if (ImGui::Checkbox("Always on Top", &Config::m_always_on_top)) {
181 [ # # ]: 0 : SetWindowAlwaysOnTopPlatform(Config::m_always_on_top);
182 [ # # # # ]: 0 : Config::Save(engine);
183 : : }
184 [ + - + + : 377 : if (ImGui::IsItemHovered()) ImGui::SetTooltip("%s", Tooltips::ALWAYS_ON_TOP);
+ - ]
185 [ + - ]: 377 : ImGui::SameLine();
186 : :
187 : 377 : bool toggled = Config::show_graphs;
188 [ + - - + ]: 377 : if (ImGui::Checkbox("Graphs", &toggled)) {
189 [ # # ]: 0 : SaveCurrentWindowGeometryPlatform(Config::show_graphs);
190 : 0 : Config::show_graphs = toggled;
191 [ # # ]: 0 : int target_w = Config::show_graphs ? Config::win_w_large : Config::win_w_small;
192 [ # # ]: 0 : int target_h = Config::show_graphs ? Config::win_h_large : Config::win_h_small;
193 [ # # ]: 0 : ResizeWindowPlatform(Config::win_pos_x, Config::win_pos_y, target_w, target_h);
194 [ # # # # ]: 0 : Config::Save(engine);
195 : : }
196 [ + - - + : 377 : if (ImGui::IsItemHovered()) ImGui::SetTooltip("%s", Tooltips::SHOW_GRAPHS);
- - ]
197 : :
198 [ + - ]: 377 : ImGui::Separator();
199 [ + - ]: 377 : bool is_logging = AsyncLogger::Get().IsLogging();
200 [ + + ]: 377 : if (is_logging) {
201 [ + - - + ]: 3 : if (ImGui::Button("STOP LOG", ImVec2(80, 0))) {
202 [ # # ]: 0 : AsyncLogger::Get().Stop();
203 : : }
204 [ + - - + : 3 : if (ImGui::IsItemHovered()) ImGui::SetTooltip("%s", Tooltips::LOG_STOP);
- - ]
205 [ + - ]: 3 : ImGui::SameLine();
206 [ + - ]: 3 : float time = (float)ImGui::GetTime();
207 : 3 : bool blink = (fmod(time, 1.0f) < 0.5f);
208 [ + + + - ]: 3 : ImGui::TextColored(blink ? ImVec4(1,0,0,1) : ImVec4(0.6f,0,0,1), "REC");
209 [ + - - + : 3 : if (ImGui::IsItemHovered()) ImGui::SetTooltip("%s", Tooltips::LOG_REC);
- - ]
210 : :
211 [ + - ]: 3 : ImGui::SameLine();
212 [ + - ]: 3 : size_t bytes = AsyncLogger::Get().GetFileSizeBytes();
213 [ + - ]: 3 : if (bytes < 1024ULL * 1024ULL)
214 [ + - + - ]: 3 : ImGui::Text("%zu f (%.0f KB)", AsyncLogger::Get().GetFrameCount(), (float)bytes / 1024.0f);
215 : : else
216 [ # # # # ]: 0 : ImGui::Text("%zu f (%.1f MB)", AsyncLogger::Get().GetFrameCount(), (float)bytes / (1024.0f * 1024.0f));
217 : :
218 [ + - ]: 3 : ImGui::SameLine();
219 [ + - - + ]: 3 : if (ImGui::Button("MARKER")) {
220 [ # # ]: 0 : AsyncLogger::Get().SetMarker();
221 : : }
222 [ + - - + : 3 : if (ImGui::IsItemHovered()) ImGui::SetTooltip("%s", Tooltips::LOG_MARKER);
- - ]
223 : : } else {
224 [ + - - + ]: 374 : if (ImGui::Button("START LOGGING", ImVec2(120, 0))) {
225 : 0 : SessionInfo info;
226 [ # # ]: 0 : info.app_version = LMUFFB_VERSION;
227 [ # # # # ]: 0 : if (engine.m_vehicle_name[0] != '\0') info.vehicle_name = engine.m_vehicle_name;
228 [ # # ]: 0 : else info.vehicle_name = "UnknownCar";
229 : :
230 [ # # # # ]: 0 : if (engine.m_track_name[0] != '\0') info.track_name = engine.m_track_name;
231 [ # # ]: 0 : else info.track_name = "UnknownTrack";
232 : :
233 [ # # ]: 0 : info.driver_name = "Auto";
234 : :
235 : 0 : info.gain = engine.m_gain;
236 : 0 : info.understeer_effect = engine.m_understeer_effect;
237 : 0 : info.sop_effect = engine.m_sop_effect;
238 : 0 : info.slope_enabled = engine.m_slope_detection_enabled;
239 : 0 : info.slope_sensitivity = engine.m_slope_sensitivity;
240 : 0 : info.slope_threshold = (float)engine.m_slope_min_threshold;
241 : 0 : info.slope_alpha_threshold = engine.m_slope_alpha_threshold;
242 : 0 : info.slope_decay_rate = engine.m_slope_decay_rate;
243 : 0 : info.torque_passthrough = engine.m_torque_passthrough;
244 : :
245 [ # # # # ]: 0 : AsyncLogger::Get().Start(info, Config::m_log_path);
246 : 0 : }
247 [ + - + + : 374 : if (ImGui::IsItemHovered()) ImGui::SetTooltip("%s", Tooltips::LOG_START);
+ - ]
248 [ + - ]: 374 : ImGui::SameLine();
249 [ + - ]: 374 : ImGui::TextDisabled("(Diagnostics)");
250 : : }
251 : :
252 : :
253 [ + - ]: 377 : ImGui::Separator();
254 : :
255 : : static int selected_preset = 0;
256 : :
257 : 3363 : auto FormatDecoupled = [&](float val, float base_nm) {
258 : 3363 : float estimated_nm = val * base_nm;
259 : : static char buf[64];
260 : 3363 : snprintf(buf, 64, "%.1f%%%% (~%.1f Nm)", val * 100.0f, estimated_nm);
261 : 3363 : return (const char*)buf;
262 : : };
263 : :
264 : 2262 : auto FormatPct = [&](float val) {
265 : : static char buf[32];
266 : 2262 : snprintf(buf, 32, "%.1f%%%%", val * 100.0f);
267 : 2262 : return (const char*)buf;
268 : : };
269 : :
270 : 18664 : auto FloatSetting = [&](const char* label, float* v, float min, float max, const char* fmt = "%.2f", const char* tooltip = nullptr, std::function<void()> decorator = nullptr) {
271 [ + - + - ]: 18664 : GuiWidgets::Result res = GuiWidgets::Float(label, v, min, max, fmt, tooltip, decorator);
272 [ - + ]: 18664 : if (res.deactivated) {
273 [ # # # # ]: 0 : Config::Save(engine);
274 : : }
275 : 18664 : };
276 : :
277 : 3770 : auto BoolSetting = [&](const char* label, bool* v, const char* tooltip = nullptr) {
278 [ + - ]: 3770 : GuiWidgets::Result res = GuiWidgets::Checkbox(label, v, tooltip);
279 [ - + ]: 3770 : if (res.deactivated) {
280 [ # # # # ]: 0 : Config::Save(engine);
281 : : }
282 : 3770 : };
283 : :
284 : 754 : auto IntSetting = [&](const char* label, int* v, const char* const items[], int items_count, const char* tooltip = nullptr) {
285 [ + - ]: 754 : GuiWidgets::Result res = GuiWidgets::Combo(label, v, items, items_count, tooltip);
286 [ - + ]: 754 : if (res.changed) {
287 [ # # ]: 0 : std::lock_guard<std::recursive_mutex> lock(g_engine_mutex);
288 : : // v is already updated by ImGui, but we lock to ensure visibility and consistency
289 [ # # # # ]: 0 : Config::Save(engine);
290 : 0 : }
291 : 754 : };
292 : :
293 [ + - + - ]: 377 : if (ImGui::TreeNodeEx("Presets and Configuration", ImGuiTreeNodeFlags_DefaultOpen | ImGuiTreeNodeFlags_Framed)) {
294 [ - + - - ]: 377 : if (Config::presets.empty()) Config::LoadPresets();
295 : :
296 : : static bool first_run = true;
297 [ + + + - : 377 : if (first_run && !Config::presets.empty()) {
+ + ]
298 [ + - ]: 1 : for (int i = 0; i < (int)Config::presets.size(); i++) {
299 [ + - ]: 1 : if (Config::presets[i].name == Config::m_last_preset_name) {
300 : 1 : selected_preset = i;
301 : 1 : break;
302 : : }
303 : : }
304 : 1 : first_run = false;
305 : : }
306 : :
307 [ + + + - ]: 377 : static std::string preview_buf;
308 : 377 : const char* preview_value = "Custom";
309 [ + - + - : 377 : if (selected_preset >= 0 && selected_preset < (int)Config::presets.size()) {
+ - ]
310 [ + - ]: 377 : preview_buf = Config::presets[selected_preset].name;
311 [ + - + + ]: 377 : if (Config::IsEngineDirtyRelativeToPreset(selected_preset, engine)) {
312 [ + - ]: 370 : preview_buf += "*";
313 : : }
314 : 377 : preview_value = preview_buf.c_str();
315 : : }
316 : :
317 [ + - + - ]: 377 : ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x * 0.6f);
318 [ + - - + ]: 377 : if (ImGui::BeginCombo("Load Preset", preview_value)) {
319 [ # # ]: 0 : for (int i = 0; i < (int)Config::presets.size(); i++) {
320 : 0 : bool is_selected = (selected_preset == i);
321 [ # # ]: 0 : ImGui::PushID(i);
322 [ # # # # ]: 0 : if (ImGui::Selectable(Config::presets[i].name.c_str(), is_selected)) {
323 : 0 : selected_preset = i;
324 [ # # ]: 0 : Config::ApplyPreset(i, engine);
325 : : }
326 [ # # # # ]: 0 : if (is_selected) ImGui::SetItemDefaultFocus();
327 [ # # ]: 0 : ImGui::PopID();
328 : : }
329 [ # # ]: 0 : ImGui::EndCombo();
330 : : }
331 : :
332 : : static char new_preset_name[64] = "";
333 [ + - + - ]: 377 : ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x * 0.4f);
334 [ + - ]: 377 : ImGui::InputText("##NewPresetName", new_preset_name, 64);
335 [ + - + + : 377 : if (ImGui::IsItemHovered()) ImGui::SetTooltip("%s", Tooltips::PRESET_NAME);
+ - ]
336 [ + - ]: 377 : ImGui::SameLine();
337 [ + - - + ]: 377 : if (ImGui::Button("Save New")) {
338 [ # # ]: 0 : if (strlen(new_preset_name) > 0) {
339 [ # # # # ]: 0 : Config::AddUserPreset(std::string(new_preset_name), engine);
340 [ # # ]: 0 : for (int i = 0; i < (int)Config::presets.size(); i++) {
341 [ # # # # ]: 0 : if (Config::presets[i].name == std::string(new_preset_name)) {
342 : 0 : selected_preset = i;
343 : 0 : break;
344 : : }
345 : : }
346 : 0 : new_preset_name[0] = '\0';
347 : : }
348 : : }
349 [ + - - + : 377 : if (ImGui::IsItemHovered()) ImGui::SetTooltip("%s", Tooltips::PRESET_SAVE_NEW);
- - ]
350 : :
351 [ + - - + ]: 377 : if (ImGui::Button("Save Current Config")) {
352 [ # # # # : 0 : if (selected_preset >= 0 && selected_preset < (int)Config::presets.size() && !Config::presets[selected_preset].is_builtin) {
# # # # ]
353 [ # # ]: 0 : Config::AddUserPreset(Config::presets[selected_preset].name, engine);
354 : : } else {
355 [ # # # # ]: 0 : Config::Save(engine);
356 : : }
357 : : }
358 [ + - + + : 377 : if (ImGui::IsItemHovered()) ImGui::SetTooltip("%s", Tooltips::PRESET_SAVE_CURRENT);
+ - ]
359 [ + - ]: 377 : ImGui::SameLine();
360 [ + - - + ]: 377 : if (ImGui::Button("Reset Defaults")) {
361 [ # # ]: 0 : Config::ApplyPreset(0, engine);
362 : 0 : selected_preset = 0;
363 : : }
364 [ + - - + : 377 : if (ImGui::IsItemHovered()) ImGui::SetTooltip("%s", Tooltips::PRESET_RESET);
- - ]
365 [ + - ]: 377 : ImGui::SameLine();
366 [ + - - + ]: 377 : if (ImGui::Button("Duplicate")) {
367 [ # # ]: 0 : if (selected_preset >= 0) {
368 [ # # ]: 0 : Config::DuplicatePreset(selected_preset, engine);
369 [ # # ]: 0 : for (int i = 0; i < (int)Config::presets.size(); i++) {
370 [ # # ]: 0 : if (Config::presets[i].name == Config::m_last_preset_name) {
371 : 0 : selected_preset = i;
372 : 0 : break;
373 : : }
374 : : }
375 : : }
376 : : }
377 [ + - + + : 377 : if (ImGui::IsItemHovered()) ImGui::SetTooltip("%s", Tooltips::PRESET_DUPLICATE);
+ - ]
378 [ + - ]: 377 : ImGui::SameLine();
379 [ + - + - : 377 : bool can_delete = (selected_preset >= 0 && selected_preset < (int)Config::presets.size() && !Config::presets[selected_preset].is_builtin);
+ - ]
380 [ - + - - ]: 377 : if (!can_delete) ImGui::BeginDisabled();
381 [ + - - + ]: 377 : if (ImGui::Button("Delete")) {
382 [ # # ]: 0 : Config::DeletePreset(selected_preset, engine);
383 : 0 : selected_preset = 0;
384 [ # # ]: 0 : Config::ApplyPreset(0, engine);
385 : : }
386 [ + - - + : 377 : if (ImGui::IsItemHovered()) ImGui::SetTooltip("%s", Tooltips::PRESET_DELETE);
- - ]
387 [ - + - - ]: 377 : if (!can_delete) ImGui::EndDisabled();
388 : :
389 [ + - ]: 377 : ImGui::Separator();
390 [ + - - + ]: 377 : if (ImGui::Button("Import Preset...")) {
391 : 0 : std::string path;
392 [ # # # # ]: 0 : if (OpenPresetFileDialogPlatform(path)) {
393 [ # # # # ]: 0 : if (Config::ImportPreset(path, engine)) {
394 : 0 : selected_preset = (int)Config::presets.size() - 1;
395 : : }
396 : : }
397 : 0 : }
398 [ + - + + : 377 : if (ImGui::IsItemHovered()) ImGui::SetTooltip("%s", Tooltips::PRESET_IMPORT);
+ - ]
399 [ + - ]: 377 : ImGui::SameLine();
400 [ + - - + ]: 377 : if (ImGui::Button("Export Selected...")) {
401 [ # # # # : 0 : if (selected_preset >= 0 && selected_preset < (int)Config::presets.size()) {
# # ]
402 : 0 : std::string path;
403 [ # # ]: 0 : std::string defaultName = Config::presets[selected_preset].name + ".ini";
404 [ # # # # ]: 0 : if (SavePresetFileDialogPlatform(path, defaultName)) {
405 [ # # ]: 0 : Config::ExportPreset(selected_preset, path);
406 : : }
407 : 0 : }
408 : : }
409 [ + - - + : 377 : if (ImGui::IsItemHovered()) ImGui::SetTooltip("%s", Tooltips::PRESET_EXPORT);
- - ]
410 : :
411 [ + - ]: 377 : ImGui::TreePop();
412 : : }
413 : :
414 [ + - ]: 377 : ImGui::Spacing();
415 : :
416 [ + - ]: 377 : ImGui::Columns(2, "SettingsGrid", false);
417 [ + - + - ]: 377 : ImGui::SetColumnWidth(0, ImGui::GetWindowWidth() * 0.45f);
418 : :
419 [ + - + - ]: 377 : if (ImGui::TreeNodeEx("General FFB", ImGuiTreeNodeFlags_DefaultOpen | ImGuiTreeNodeFlags_Framed)) {
420 [ + - + - ]: 377 : ImGui::NextColumn(); ImGui::NextColumn();
421 : :
422 [ + - ]: 377 : ImGui::Spacing();
423 : 377 : bool use_in_game_ffb = (engine.m_torque_source == 1);
424 [ + - - + ]: 377 : if (GuiWidgets::Checkbox("Use In-Game FFB (400Hz Native)", &use_in_game_ffb, Tooltips::USE_INGAME_FFB).changed) {
425 [ # # ]: 0 : std::lock_guard<std::recursive_mutex> lock(g_engine_mutex);
426 [ # # ]: 0 : engine.m_torque_source = use_in_game_ffb ? 1 : 0;
427 [ # # # # ]: 0 : Config::Save(engine);
428 : 0 : }
429 : :
430 [ + - ]: 377 : BoolSetting("Invert FFB Signal", &engine.m_invert_force, Tooltips::INVERT_FFB);
431 : :
432 : 377 : bool prev_structural = engine.m_dynamic_normalization_enabled;
433 [ + - - + ]: 377 : if (GuiWidgets::Checkbox("Enable Dynamic Normalization (Session Peak)", &engine.m_dynamic_normalization_enabled, Tooltips::DYNAMIC_NORMALIZATION_ENABLE).changed) {
434 [ # # # # ]: 0 : if (prev_structural && !engine.m_dynamic_normalization_enabled) {
435 [ # # ]: 0 : engine.ResetNormalization();
436 : : }
437 [ # # # # ]: 0 : Config::Save(engine);
438 : : }
439 [ + - ]: 377 : FloatSetting("Master Gain", &engine.m_gain, 0.0f, 2.0f, FormatPct(engine.m_gain), Tooltips::MASTER_GAIN);
440 [ + - ]: 377 : FloatSetting("Wheelbase Max Torque", &engine.m_wheelbase_max_nm, 1.0f, 50.0f, "%.1f Nm", Tooltips::WHEELBASE_MAX_TORQUE);
441 [ + - ]: 377 : FloatSetting("Target Rim Torque", &engine.m_target_rim_nm, 1.0f, 50.0f, "%.1f Nm", Tooltips::TARGET_RIM_TORQUE);
442 [ + - ]: 377 : FloatSetting("Min Force", &engine.m_min_force, 0.0f, 0.20f, "%.3f", Tooltips::MIN_FORCE);
443 : :
444 [ + - + - ]: 377 : if (ImGui::TreeNodeEx("Soft Lock", ImGuiTreeNodeFlags_DefaultOpen)) {
445 [ + - + - ]: 377 : ImGui::NextColumn(); ImGui::NextColumn();
446 [ + - ]: 377 : BoolSetting("Enable Soft Lock", &engine.m_soft_lock_enabled, Tooltips::SOFT_LOCK_ENABLE);
447 [ + - ]: 377 : if (engine.m_soft_lock_enabled) {
448 [ + - ]: 377 : FloatSetting(" Stiffness", &engine.m_soft_lock_stiffness, 0.0f, 100.0f, "%.1f", Tooltips::SOFT_LOCK_STIFFNESS);
449 [ + - ]: 377 : FloatSetting(" Damping", &engine.m_soft_lock_damping, 0.0f, 5.0f, "%.2f", Tooltips::SOFT_LOCK_DAMPING);
450 : : }
451 [ + - ]: 377 : ImGui::TreePop();
452 [ + - ]: 377 : ImGui::Separator();
453 : : }
454 : :
455 [ + - ]: 377 : ImGui::TreePop();
456 : : } else {
457 [ # # # # ]: 0 : ImGui::NextColumn(); ImGui::NextColumn();
458 : : }
459 : :
460 [ + - + - ]: 377 : if (ImGui::TreeNodeEx("Front Axle (Understeer)", ImGuiTreeNodeFlags_DefaultOpen | ImGuiTreeNodeFlags_Framed)) {
461 [ + - + - ]: 377 : ImGui::NextColumn(); ImGui::NextColumn();
462 : :
463 [ + + ]: 377 : if (engine.m_torque_source == 1) {
464 [ + - ]: 166 : FloatSetting("In-Game FFB Gain", &engine.m_ingame_ffb_gain, 0.0f, 2.0f, FormatPct(engine.m_ingame_ffb_gain), Tooltips::INGAME_FFB_GAIN);
465 : : } else {
466 [ + - ]: 211 : FloatSetting("Steering Shaft Gain", &engine.m_steering_shaft_gain, 0.0f, 2.0f, FormatPct(engine.m_steering_shaft_gain), Tooltips::STEERING_SHAFT_GAIN);
467 : : }
468 : :
469 [ + - ]: 377 : FloatSetting("Steering Shaft Smoothing", &engine.m_steering_shaft_smoothing, 0.000f, 0.100f, "%.3f s",
470 : : Tooltips::STEERING_SHAFT_SMOOTHING,
471 : 377 : [&]() {
472 : 377 : int ms = (int)std::lround(engine.m_steering_shaft_smoothing * 1000.0f);
473 [ + - ]: 377 : ImVec4 color = (ms < LATENCY_WARNING_THRESHOLD_MS) ? ImVec4(0,1,0,1) : ImVec4(1,0,0,1);
474 [ + - + - ]: 377 : ImGui::TextColored(color, "Latency: %d ms - %s", ms, (ms < LATENCY_WARNING_THRESHOLD_MS) ? "OK" : "High");
475 : 377 : });
476 : :
477 [ + - ]: 377 : FloatSetting("Understeer Effect", &engine.m_understeer_effect, 0.0f, 2.0f, FormatPct(engine.m_understeer_effect),
478 : : Tooltips::UNDERSTEER_EFFECT);
479 : :
480 [ + - ]: 377 : FloatSetting("Dynamic Weight", &engine.m_dynamic_weight_gain, 0.0f, 2.0f, FormatPct(engine.m_dynamic_weight_gain),
481 : : Tooltips::DYNAMIC_WEIGHT);
482 : :
483 [ + - ]: 377 : FloatSetting(" Weight Smoothing", &engine.m_dynamic_weight_smoothing, 0.000f, 0.500f, "%.3f s",
484 : : Tooltips::WEIGHT_SMOOTHING);
485 : :
486 : 377 : const char* torque_sources[] = { "Shaft Torque (100Hz Legacy)", "In-Game FFB (400Hz LMU 1.2+)" };
487 [ + - ]: 377 : IntSetting("Torque Source", &engine.m_torque_source, torque_sources, sizeof(torque_sources)/sizeof(torque_sources[0]),
488 : : Tooltips::TORQUE_SOURCE);
489 : :
490 [ + - ]: 377 : BoolSetting("Pure Passthrough", &engine.m_torque_passthrough, Tooltips::PURE_PASSTHROUGH);
491 : :
492 [ + - + - ]: 377 : if (ImGui::TreeNodeEx("Signal Filtering", ImGuiTreeNodeFlags_DefaultOpen)) {
493 [ + - + - ]: 377 : ImGui::NextColumn(); ImGui::NextColumn();
494 : :
495 [ + - ]: 377 : BoolSetting(" Flatspot Suppression", &engine.m_flatspot_suppression, Tooltips::FLATSPOT_SUPPRESSION);
496 [ + + ]: 377 : if (engine.m_flatspot_suppression) {
497 [ + - ]: 364 : FloatSetting(" Filter Width (Q)", &engine.m_notch_q, 0.5f, 10.0f, "Q: %.2f", Tooltips::NOTCH_Q);
498 [ + - ]: 364 : FloatSetting(" Suppression Strength", &engine.m_flatspot_strength, 0.0f, 1.0f, "%.2f", Tooltips::SUPPRESSION_STRENGTH);
499 [ + - ]: 364 : ImGui::Text(" Est. / Theory Freq");
500 [ + - ]: 364 : ImGui::NextColumn();
501 [ + - ]: 364 : ImGui::TextDisabled("%.1f Hz / %.1f Hz", engine.m_debug_freq, engine.m_theoretical_freq);
502 [ + - ]: 364 : ImGui::NextColumn();
503 : : }
504 : :
505 [ + - ]: 377 : BoolSetting(" Static Noise Filter", &engine.m_static_notch_enabled, Tooltips::STATIC_NOISE_FILTER);
506 [ + + ]: 377 : if (engine.m_static_notch_enabled) {
507 [ + - ]: 363 : FloatSetting(" Target Frequency", &engine.m_static_notch_freq, 10.0f, 100.0f, "%.1f Hz", Tooltips::STATIC_NOTCH_FREQ);
508 [ + - ]: 363 : FloatSetting(" Filter Width", &engine.m_static_notch_width, 0.1f, 10.0f, "%.1f Hz", Tooltips::STATIC_NOTCH_WIDTH);
509 : : }
510 : :
511 [ + - ]: 377 : ImGui::TreePop();
512 : : } else {
513 [ # # # # ]: 0 : ImGui::NextColumn(); ImGui::NextColumn();
514 : : }
515 : :
516 [ + - ]: 377 : ImGui::TreePop();
517 : : } else {
518 [ # # # # ]: 0 : ImGui::NextColumn(); ImGui::NextColumn();
519 : : }
520 : :
521 [ + - + - ]: 377 : if (ImGui::TreeNodeEx("Rear Axle (Oversteer)", ImGuiTreeNodeFlags_DefaultOpen | ImGuiTreeNodeFlags_Framed)) {
522 [ + - + - ]: 377 : ImGui::NextColumn(); ImGui::NextColumn();
523 : :
524 [ + - ]: 377 : FloatSetting("Lateral G Boost (Slide)", &engine.m_oversteer_boost, 0.0f, 4.0f, FormatPct(engine.m_oversteer_boost),
525 : : Tooltips::OVERSTEER_BOOST);
526 [ + - ]: 377 : FloatSetting("Lateral G", &engine.m_sop_effect, 0.0f, 2.0f, FormatDecoupled(engine.m_sop_effect, FFBEngine::BASE_NM_SOP_LATERAL), Tooltips::LATERAL_G);
527 [ + - ]: 377 : FloatSetting("SoP Self-Aligning Torque", &engine.m_rear_align_effect, 0.0f, 2.0f, FormatDecoupled(engine.m_rear_align_effect, FFBEngine::BASE_NM_REAR_ALIGN),
528 : : Tooltips::REAR_ALIGN_TORQUE);
529 [ + - ]: 377 : FloatSetting("Yaw Kick", &engine.m_sop_yaw_gain, 0.0f, 1.0f, FormatDecoupled(engine.m_sop_yaw_gain, FFBEngine::BASE_NM_YAW_KICK),
530 : : Tooltips::YAW_KICK);
531 [ + - ]: 377 : FloatSetting(" Activation Threshold", &engine.m_yaw_kick_threshold, 0.0f, 10.0f, "%.2f rad/s²", Tooltips::YAW_KICK_THRESHOLD);
532 : :
533 [ + - ]: 377 : FloatSetting(" Kick Response", &engine.m_yaw_accel_smoothing, 0.000f, 0.050f, "%.3f s",
534 : : Tooltips::YAW_KICK_RESPONSE,
535 : 377 : [&]() {
536 : 377 : int ms = (int)std::lround(engine.m_yaw_accel_smoothing * 1000.0f);
537 [ + - ]: 377 : ImVec4 color = (ms <= 15) ? ImVec4(0,1,0,1) : ImVec4(1,0,0,1);
538 [ + - ]: 377 : ImGui::TextColored(color, "Latency: %d ms", ms);
539 : 377 : });
540 : :
541 [ + - ]: 377 : FloatSetting("Gyro Damping", &engine.m_gyro_gain, 0.0f, 1.0f, FormatDecoupled(engine.m_gyro_gain, FFBEngine::BASE_NM_GYRO_DAMPING), Tooltips::GYRO_DAMPING);
542 : :
543 [ + - ]: 377 : FloatSetting(" Gyro Smooth", &engine.m_gyro_smoothing, 0.000f, 0.050f, "%.3f s",
544 : : Tooltips::GYRO_SMOOTH,
545 : 377 : [&]() {
546 : 377 : int ms = (int)std::lround(engine.m_gyro_smoothing * 1000.0f);
547 [ + - ]: 377 : ImVec4 color = (ms <= 20) ? ImVec4(0,1,0,1) : ImVec4(1,0,0,1);
548 [ + - ]: 377 : ImGui::TextColored(color, "Latency: %d ms", ms);
549 : 377 : });
550 : :
551 [ + - ]: 377 : ImGui::TextColored(ImVec4(0.0f, 0.6f, 0.85f, 1.0f), "Advanced SoP");
552 [ + - + - ]: 377 : ImGui::NextColumn(); ImGui::NextColumn();
553 : :
554 [ + - ]: 377 : FloatSetting("SoP Smoothing", &engine.m_sop_smoothing_factor, 0.0f, 1.0f, "%.2f",
555 : : Tooltips::SOP_SMOOTHING,
556 : 377 : [&]() {
557 : 377 : int ms = (int)std::lround((1.0f - engine.m_sop_smoothing_factor) * 100.0f);
558 [ + - ]: 377 : ImVec4 color = (ms < LATENCY_WARNING_THRESHOLD_MS) ? ImVec4(0,1,0,1) : ImVec4(1,0,0,1);
559 [ + - + - ]: 377 : ImGui::TextColored(color, "Latency: %d ms - %s", ms, (ms < LATENCY_WARNING_THRESHOLD_MS) ? "OK" : "High");
560 : 377 : });
561 : :
562 [ + - ]: 377 : FloatSetting("Grip Smoothing", &engine.m_grip_smoothing_steady, 0.000f, 0.100f, "%.3f s",
563 : : Tooltips::GRIP_SMOOTHING);
564 : :
565 [ + - ]: 377 : FloatSetting(" SoP Scale", &engine.m_sop_scale, 0.0f, 20.0f, "%.2f", Tooltips::SOP_SCALE);
566 : :
567 [ + - ]: 377 : ImGui::TreePop();
568 : : } else {
569 [ # # # # ]: 0 : ImGui::NextColumn(); ImGui::NextColumn();
570 : : }
571 : :
572 [ + - + - ]: 377 : if (ImGui::TreeNodeEx("Grip & Slip Angle Estimation", ImGuiTreeNodeFlags_DefaultOpen | ImGuiTreeNodeFlags_Framed)) {
573 [ + - + - ]: 377 : ImGui::NextColumn(); ImGui::NextColumn();
574 : :
575 [ + - ]: 377 : FloatSetting("Slip Angle Smoothing", &engine.m_slip_angle_smoothing, 0.000f, 0.100f, "%.3f s",
576 : : Tooltips::SLIP_ANGLE_SMOOTHING,
577 : 377 : [&]() {
578 : 377 : int ms = (int)std::lround(engine.m_slip_angle_smoothing * 1000.0f);
579 [ + - ]: 377 : ImVec4 color = (ms < LATENCY_WARNING_THRESHOLD_MS) ? ImVec4(0,1,0,1) : ImVec4(1,0,0,1);
580 [ + - + - ]: 377 : ImGui::TextColored(color, "Latency: %d ms - %s", ms, (ms < LATENCY_WARNING_THRESHOLD_MS) ? "OK" : "High");
581 : 377 : });
582 : :
583 [ + - ]: 377 : FloatSetting("Chassis Inertia (Load)", &engine.m_chassis_inertia_smoothing, 0.000f, 0.100f, "%.3f s",
584 : : Tooltips::CHASSIS_INERTIA,
585 : 377 : [&]() {
586 : 377 : int ms = (int)std::lround(engine.m_chassis_inertia_smoothing * 1000.0f);
587 [ + - ]: 377 : ImGui::TextColored(ImVec4(0.5f, 0.5f, 1.0f, 1.0f), "Simulation: %d ms", ms);
588 : 377 : });
589 : :
590 [ + - ]: 377 : FloatSetting("Optimal Slip Angle", &engine.m_optimal_slip_angle, 0.05f, 0.20f, "%.2f rad",
591 : : Tooltips::OPTIMAL_SLIP_ANGLE);
592 [ + - ]: 377 : FloatSetting("Optimal Slip Ratio", &engine.m_optimal_slip_ratio, 0.05f, 0.20f, "%.2f",
593 : : Tooltips::OPTIMAL_SLIP_RATIO);
594 : :
595 [ + - ]: 377 : ImGui::Separator();
596 [ + - ]: 377 : ImGui::TextColored(ImVec4(1.0f, 0.8f, 0.0f, 1.0f), "Slope Detection (Experimental)");
597 [ + - + - ]: 377 : ImGui::NextColumn(); ImGui::NextColumn();
598 : :
599 : 377 : bool prev_slope_enabled = engine.m_slope_detection_enabled;
600 [ + - ]: 377 : GuiWidgets::Result slope_res = GuiWidgets::Checkbox("Enable Slope Detection", &engine.m_slope_detection_enabled,
601 : : Tooltips::SLOPE_DETECTION_ENABLE);
602 : :
603 [ - + ]: 377 : if (slope_res.changed) {
604 [ # # # # ]: 0 : if (!prev_slope_enabled && engine.m_slope_detection_enabled) {
605 : 0 : engine.m_slope_buffer_count = 0;
606 : 0 : engine.m_slope_buffer_index = 0;
607 : 0 : engine.m_slope_smoothed_output = 1.0;
608 : : }
609 : : }
610 [ - + ]: 377 : if (slope_res.deactivated) {
611 [ # # # # ]: 0 : Config::Save(engine);
612 : : }
613 : :
614 [ + + + + ]: 377 : if (engine.m_slope_detection_enabled && engine.m_oversteer_boost > 0.01f) {
615 [ + - ]: 362 : ImGui::TextColored(ImVec4(1.0f, 0.5f, 0.0f, 1.0f),
616 : : "Note: Lateral G Boost (Slide) is auto-disabled when Slope Detection is ON.");
617 [ + - + - ]: 362 : ImGui::NextColumn(); ImGui::NextColumn();
618 : : }
619 : :
620 [ + + ]: 377 : if (engine.m_slope_detection_enabled) {
621 : 363 : int window = engine.m_slope_sg_window;
622 [ + - - + ]: 363 : if (ImGui::SliderInt(" Filter Window", &window, 5, 41)) {
623 [ # # ]: 0 : if (window % 2 == 0) window++;
624 : 0 : engine.m_slope_sg_window = window;
625 : : }
626 [ + - - + ]: 363 : if (ImGui::IsItemHovered()) {
627 [ # # ]: 0 : ImGui::SetTooltip("%s", Tooltips::SLOPE_FILTER_WINDOW);
628 : : }
629 [ + - - + : 363 : if (ImGui::IsItemDeactivatedAfterEdit()) Config::Save(engine);
- - - - ]
630 : :
631 [ + - ]: 363 : ImGui::SameLine();
632 : 363 : float latency_ms = (static_cast<float>(engine.m_slope_sg_window) / 2.0f) * 2.5f;
633 [ + - ]: 363 : ImVec4 color = (latency_ms < 25.0f) ? ImVec4(0,1,0,1) : ImVec4(1,0.5f,0,1);
634 [ + - ]: 363 : ImGui::TextColored(color, "~%.0f ms latency", latency_ms);
635 [ + - + - ]: 363 : ImGui::NextColumn(); ImGui::NextColumn();
636 : :
637 [ + - ]: 363 : FloatSetting(" Sensitivity", &engine.m_slope_sensitivity, 0.1f, 5.0f, "%.1fx",
638 : : Tooltips::SLOPE_SENSITIVITY);
639 : :
640 [ + - - + ]: 363 : if (ImGui::TreeNode("Advanced Slope Settings")) {
641 [ # # # # ]: 0 : ImGui::NextColumn(); ImGui::NextColumn();
642 [ # # ]: 0 : FloatSetting(" Slope Threshold", &engine.m_slope_min_threshold, -1.0f, 0.0f, "%.2f", Tooltips::SLOPE_THRESHOLD);
643 [ # # ]: 0 : FloatSetting(" Output Smoothing", &engine.m_slope_smoothing_tau, 0.005f, 0.100f, "%.3f s", Tooltips::SLOPE_OUTPUT_SMOOTHING);
644 : :
645 [ # # ]: 0 : ImGui::Separator();
646 [ # # ]: 0 : ImGui::Text("Stability Fixes (v0.7.3)");
647 [ # # # # ]: 0 : ImGui::NextColumn(); ImGui::NextColumn();
648 [ # # ]: 0 : FloatSetting(" Alpha Threshold", &engine.m_slope_alpha_threshold, 0.001f, 0.100f, "%.3f", Tooltips::SLOPE_ALPHA_THRESHOLD);
649 [ # # ]: 0 : FloatSetting(" Decay Rate", &engine.m_slope_decay_rate, 0.5f, 20.0f, "%.1f", Tooltips::SLOPE_DECAY_RATE);
650 [ # # ]: 0 : BoolSetting(" Confidence Gate", &engine.m_slope_confidence_enabled, Tooltips::SLOPE_CONFIDENCE_GATE);
651 : :
652 [ # # ]: 0 : ImGui::TreePop();
653 : : } else {
654 [ + - + - ]: 363 : ImGui::NextColumn(); ImGui::NextColumn();
655 : : }
656 : :
657 : 363 : ImGui::Text(" Live Slope: %.3f | Grip: %.0f%%",
658 : : engine.m_slope_current,
659 [ + - ]: 363 : engine.m_slope_smoothed_output * 100.0f);
660 [ + - + - ]: 363 : ImGui::NextColumn(); ImGui::NextColumn();
661 : : }
662 : :
663 [ + - ]: 377 : ImGui::TreePop();
664 : : } else {
665 [ # # # # ]: 0 : ImGui::NextColumn(); ImGui::NextColumn();
666 : : }
667 : :
668 [ + - + - ]: 377 : if (ImGui::TreeNodeEx("Braking & Lockup", ImGuiTreeNodeFlags_DefaultOpen | ImGuiTreeNodeFlags_Framed)) {
669 [ + - + - ]: 377 : ImGui::NextColumn(); ImGui::NextColumn();
670 : :
671 [ + - ]: 377 : BoolSetting("Lockup Vibration", &engine.m_lockup_enabled, Tooltips::LOCKUP_VIBRATION);
672 [ + + ]: 377 : if (engine.m_lockup_enabled) {
673 [ + - ]: 373 : FloatSetting(" Lockup Strength", &engine.m_lockup_gain, 0.0f, 3.0f, FormatDecoupled(engine.m_lockup_gain, FFBEngine::BASE_NM_LOCKUP_VIBRATION), Tooltips::LOCKUP_STRENGTH);
674 [ + - ]: 373 : FloatSetting(" Brake Load Cap", &engine.m_brake_load_cap, 1.0f, 10.0f, "%.2fx", Tooltips::BRAKE_LOAD_CAP);
675 [ + - ]: 373 : FloatSetting(" Vibration Pitch", &engine.m_lockup_freq_scale, 0.5f, 2.0f, "%.2fx", Tooltips::VIBRATION_PITCH);
676 : :
677 [ + - ]: 373 : ImGui::Separator();
678 [ + - ]: 373 : ImGui::Text("Response Curve");
679 [ + - + - ]: 373 : ImGui::NextColumn(); ImGui::NextColumn();
680 : :
681 [ + - ]: 373 : FloatSetting(" Gamma", &engine.m_lockup_gamma, 0.1f, 3.0f, "%.1f", Tooltips::LOCKUP_GAMMA);
682 [ + - ]: 373 : FloatSetting(" Start Slip %", &engine.m_lockup_start_pct, 1.0f, 10.0f, "%.1f%%", Tooltips::LOCKUP_START_PCT);
683 [ + - ]: 373 : FloatSetting(" Full Slip %", &engine.m_lockup_full_pct, 5.0f, 25.0f, "%.1f%%", Tooltips::LOCKUP_FULL_PCT);
684 : :
685 [ + - ]: 373 : ImGui::Separator();
686 [ + - ]: 373 : ImGui::Text("Prediction (Advanced)");
687 [ + - + - ]: 373 : ImGui::NextColumn(); ImGui::NextColumn();
688 : :
689 [ + - ]: 373 : FloatSetting(" Sensitivity", &engine.m_lockup_prediction_sens, 10.0f, 100.0f, "%.0f", Tooltips::LOCKUP_PREDICTION_SENS);
690 [ + - ]: 373 : FloatSetting(" Bump Rejection", &engine.m_lockup_bump_reject, 0.1f, 5.0f, "%.1f m/s", Tooltips::LOCKUP_BUMP_REJECT);
691 [ + - ]: 373 : FloatSetting(" Rear Boost", &engine.m_lockup_rear_boost, 1.0f, 10.0f, "%.2fx", Tooltips::LOCKUP_REAR_BOOST);
692 : : }
693 : :
694 [ + - ]: 377 : ImGui::Separator();
695 [ + - ]: 377 : ImGui::Text("ABS & Hardware");
696 [ + - + - ]: 377 : ImGui::NextColumn(); ImGui::NextColumn();
697 : :
698 [ + - ]: 377 : BoolSetting("ABS Pulse", &engine.m_abs_pulse_enabled, Tooltips::ABS_PULSE);
699 [ + + ]: 377 : if (engine.m_abs_pulse_enabled) {
700 [ + - ]: 360 : FloatSetting(" Pulse Gain", &engine.m_abs_gain, 0.0f, 10.0f, "%.2f", Tooltips::ABS_PULSE_GAIN);
701 [ + - ]: 360 : FloatSetting(" Pulse Frequency", &engine.m_abs_freq_hz, 10.0f, 50.0f, "%.1f Hz", Tooltips::ABS_PULSE_FREQ);
702 : : }
703 : :
704 [ + - ]: 377 : ImGui::TreePop();
705 : : } else {
706 [ # # # # ]: 0 : ImGui::NextColumn(); ImGui::NextColumn();
707 : : }
708 : :
709 [ + - + - ]: 377 : if (ImGui::TreeNodeEx("Tactile Textures", ImGuiTreeNodeFlags_DefaultOpen | ImGuiTreeNodeFlags_Framed)) {
710 [ + - + - ]: 377 : ImGui::NextColumn(); ImGui::NextColumn();
711 : :
712 : 377 : bool prev_tactile = engine.m_auto_load_normalization_enabled;
713 [ + - - + ]: 377 : if (GuiWidgets::Checkbox("Enable Dynamic Load Normalization", &engine.m_auto_load_normalization_enabled, Tooltips::DYNAMIC_LOAD_NORMALIZATION_ENABLE).changed) {
714 [ # # # # ]: 0 : if (prev_tactile && !engine.m_auto_load_normalization_enabled) {
715 [ # # ]: 0 : engine.ResetNormalization();
716 : : }
717 [ # # # # ]: 0 : Config::Save(engine);
718 : : }
719 : :
720 [ + - ]: 377 : FloatSetting("Texture Load Cap", &engine.m_texture_load_cap, 1.0f, 3.0f, "%.2fx", Tooltips::TEXTURE_LOAD_CAP);
721 [ + - ]: 377 : FloatSetting("Tactile Strength", &engine.m_tactile_gain, 0.0f, 2.0f, FormatPct(engine.m_tactile_gain), Tooltips::TACTILE_GAIN);
722 : :
723 [ + - ]: 377 : BoolSetting("Slide Rumble", &engine.m_slide_texture_enabled, Tooltips::SLIDE_RUMBLE);
724 [ + + ]: 377 : if (engine.m_slide_texture_enabled) {
725 [ + - ]: 359 : FloatSetting(" Slide Gain", &engine.m_slide_texture_gain, 0.0f, 2.0f, FormatDecoupled(engine.m_slide_texture_gain, FFBEngine::BASE_NM_SLIDE_TEXTURE), Tooltips::SLIDE_GAIN);
726 [ + - ]: 359 : FloatSetting(" Slide Pitch", &engine.m_slide_freq_scale, 0.5f, 5.0f, "%.2fx", Tooltips::SLIDE_PITCH);
727 : : }
728 : :
729 [ + - ]: 377 : BoolSetting("Road Details", &engine.m_road_texture_enabled, Tooltips::ROAD_DETAILS);
730 [ + + ]: 377 : if (engine.m_road_texture_enabled) {
731 [ + - ]: 373 : FloatSetting(" Road Gain", &engine.m_road_texture_gain, 0.0f, 2.0f, FormatDecoupled(engine.m_road_texture_gain, FFBEngine::BASE_NM_ROAD_TEXTURE), Tooltips::ROAD_GAIN);
732 : : }
733 : :
734 [ + - ]: 377 : BoolSetting("Spin Vibration", &engine.m_spin_enabled, Tooltips::SPIN_VIBRATION);
735 [ + + ]: 377 : if (engine.m_spin_enabled) {
736 [ + - ]: 373 : FloatSetting(" Spin Strength", &engine.m_spin_gain, 0.0f, 2.0f, FormatDecoupled(engine.m_spin_gain, FFBEngine::BASE_NM_SPIN_VIBRATION), Tooltips::SPIN_STRENGTH);
737 [ + - ]: 373 : FloatSetting(" Spin Pitch", &engine.m_spin_freq_scale, 0.5f, 2.0f, "%.2fx", Tooltips::SPIN_PITCH);
738 : : }
739 : :
740 [ + - ]: 377 : FloatSetting("Scrub Drag", &engine.m_scrub_drag_gain, 0.0f, 1.0f, FormatDecoupled(engine.m_scrub_drag_gain, FFBEngine::BASE_NM_SCRUB_DRAG), Tooltips::SCRUB_DRAG);
741 : :
742 : 377 : const char* bottoming_modes[] = { "Method A: Scraping", "Method B: Susp. Spike" };
743 [ + - ]: 377 : IntSetting("Bottoming Logic", &engine.m_bottoming_method, bottoming_modes, sizeof(bottoming_modes)/sizeof(bottoming_modes[0]), Tooltips::BOTTOMING_LOGIC);
744 : :
745 [ + - ]: 377 : ImGui::TreePop();
746 : : } else {
747 [ # # # # ]: 0 : ImGui::NextColumn(); ImGui::NextColumn();
748 : : }
749 : :
750 [ + - - + ]: 377 : if (ImGui::CollapsingHeader("Advanced Settings")) {
751 [ # # ]: 0 : ImGui::Indent();
752 : :
753 [ # # # # ]: 0 : if (ImGui::TreeNode("Stationary Vibration Gate")) {
754 : 0 : float lower_kmh = engine.m_speed_gate_lower * 3.6f;
755 [ # # # # ]: 0 : if (ImGui::SliderFloat("Mute Below", &lower_kmh, 0.0f, 20.0f, "%.1f km/h")) {
756 : 0 : engine.m_speed_gate_lower = lower_kmh / 3.6f;
757 [ # # ]: 0 : if (engine.m_speed_gate_upper <= engine.m_speed_gate_lower + 0.1f)
758 : 0 : engine.m_speed_gate_upper = engine.m_speed_gate_lower + 0.5f;
759 : : }
760 [ # # # # : 0 : if (ImGui::IsItemHovered()) ImGui::SetTooltip("%s", Tooltips::MUTE_BELOW);
# # ]
761 [ # # # # : 0 : if (ImGui::IsItemDeactivatedAfterEdit()) Config::Save(engine);
# # # # ]
762 : :
763 : 0 : float upper_kmh = engine.m_speed_gate_upper * 3.6f;
764 [ # # # # ]: 0 : if (ImGui::SliderFloat("Full Above", &upper_kmh, 1.0f, 50.0f, "%.1f km/h")) {
765 : 0 : engine.m_speed_gate_upper = upper_kmh / 3.6f;
766 [ # # ]: 0 : if (engine.m_speed_gate_upper <= engine.m_speed_gate_lower + 0.1f)
767 : 0 : engine.m_speed_gate_upper = engine.m_speed_gate_lower + 0.5f;
768 : : }
769 [ # # # # : 0 : if (ImGui::IsItemHovered()) ImGui::SetTooltip("%s", Tooltips::FULL_ABOVE);
# # ]
770 [ # # # # : 0 : if (ImGui::IsItemDeactivatedAfterEdit()) Config::Save(engine);
# # # # ]
771 : :
772 [ # # ]: 0 : ImGui::TreePop();
773 : : }
774 : :
775 [ # # # # ]: 0 : if (ImGui::TreeNode("Telemetry Logger")) {
776 [ # # # # ]: 0 : if (ImGui::Checkbox("Auto-Start on Session", &Config::m_auto_start_logging)) {
777 [ # # # # ]: 0 : Config::Save(engine);
778 : : }
779 [ # # # # : 0 : if (ImGui::IsItemHovered()) ImGui::SetTooltip("%s", Tooltips::AUTO_START_LOGGING);
# # ]
780 : :
781 : : char log_path_buf[256];
782 : : #ifdef _WIN32
783 : : strncpy_s(log_path_buf, sizeof(log_path_buf), Config::m_log_path.c_str(), _TRUNCATE);
784 : : #else
785 : 0 : strncpy(log_path_buf, Config::m_log_path.c_str(), 255);
786 : : #endif
787 : 0 : log_path_buf[255] = '\0';
788 [ # # # # ]: 0 : if (ImGui::InputText("Log Path", log_path_buf, 255)) {
789 [ # # ]: 0 : Config::m_log_path = log_path_buf;
790 : : }
791 [ # # # # : 0 : if (ImGui::IsItemHovered()) ImGui::SetTooltip("%s", Tooltips::LOG_PATH);
# # ]
792 [ # # # # : 0 : if (ImGui::IsItemDeactivatedAfterEdit()) Config::Save(engine);
# # # # ]
793 : :
794 [ # # # # ]: 0 : if (AsyncLogger::Get().IsLogging()) {
795 [ # # # # : 0 : ImGui::BulletText("Filename: %s", AsyncLogger::Get().GetFilename().c_str());
# # ]
796 : : }
797 : :
798 [ # # ]: 0 : ImGui::TreePop();
799 : : }
800 [ # # ]: 0 : ImGui::Unindent();
801 : : }
802 : :
803 [ + - ]: 377 : ImGui::Columns(1);
804 [ + - ]: 377 : ImGui::End();
805 : 377 : }
806 : :
807 : : const float PLOT_HISTORY_SEC = 10.0f;
808 : : const int PHYSICS_RATE_HZ = 400;
809 : : const int PLOT_BUFFER_SIZE = (int)(PLOT_HISTORY_SEC * PHYSICS_RATE_HZ);
810 : :
811 : : struct RollingBuffer {
812 : : std::vector<float> data;
813 : : int offset = 0;
814 : :
815 : 46 : RollingBuffer() {
816 [ + - ]: 46 : data.resize(PLOT_BUFFER_SIZE, 0.0f);
817 : 46 : }
818 : :
819 : 46 : void Add(float val) {
820 : 46 : data[offset] = val;
821 : 46 : offset = (offset + 1) % (int)data.size();
822 : 46 : }
823 : :
824 : 992 : float GetCurrent() const {
825 [ - + ]: 992 : if (data.empty()) return 0.0f;
826 : 992 : size_t idx = (offset - 1 + (int)data.size()) % (int)data.size();
827 : 992 : return data[idx];
828 : : }
829 : :
830 : 992 : float GetMin() const {
831 [ - + ]: 992 : if (data.empty()) return 0.0f;
832 [ + - ]: 992 : return *std::min_element(data.begin(), data.end());
833 : : }
834 : :
835 : 992 : float GetMax() const {
836 [ - + ]: 992 : if (data.empty()) return 0.0f;
837 [ + - ]: 992 : return *std::max_element(data.begin(), data.end());
838 : : }
839 : : };
840 : :
841 : 992 : inline void PlotWithStats(const char* label, const RollingBuffer& buffer,
842 : : float scale_min, float scale_max,
843 : : const ImVec2& size = ImVec2(0, 40),
844 : : const char* tooltip = nullptr) {
845 [ + - ]: 992 : ImGui::Text("%s", label);
846 : : char hidden_label[256];
847 : 992 : snprintf(hidden_label, sizeof(hidden_label), "##%s", label);
848 [ + - ]: 992 : ImGui::PlotLines(hidden_label, buffer.data.data(), (int)buffer.data.size(),
849 : 992 : buffer.offset, NULL, scale_min, scale_max, size);
850 [ - + - - : 992 : if (tooltip && ImGui::IsItemHovered()) ImGui::SetTooltip("%s", tooltip);
- - - + -
- ]
851 : :
852 : 992 : float current = buffer.GetCurrent();
853 [ + - ]: 992 : float min_val = buffer.GetMin();
854 [ + - ]: 992 : float max_val = buffer.GetMax();
855 : : char stats_overlay[128];
856 : 992 : snprintf(stats_overlay, sizeof(stats_overlay), "Cur:%.4f Min:%.3f Max:%.3f", current, min_val, max_val);
857 : :
858 [ + - ]: 992 : ImVec2 p_min = ImGui::GetItemRectMin();
859 [ + - ]: 992 : ImVec2 p_max = ImGui::GetItemRectMax();
860 : 992 : float plot_width = p_max.x - p_min.x;
861 : 992 : p_min.x += 2; p_min.y += 2;
862 : :
863 [ + - ]: 992 : ImDrawList* draw_list = ImGui::GetWindowDrawList();
864 [ + - ]: 992 : ImFont* font = ImGui::GetFont();
865 [ + - ]: 992 : float font_size = ImGui::GetFontSize();
866 [ + - ]: 992 : ImVec2 text_size = font->CalcTextSizeA(font_size, FLT_MAX, 0.0f, stats_overlay);
867 : :
868 [ - + ]: 992 : if (text_size.x > plot_width - 4) {
869 : 0 : snprintf(stats_overlay, sizeof(stats_overlay), "%.4f [%.3f, %.3f]", current, min_val, max_val);
870 [ # # ]: 0 : text_size = font->CalcTextSizeA(font_size, FLT_MAX, 0.0f, stats_overlay);
871 [ # # ]: 0 : if (text_size.x > plot_width - 4) {
872 : 0 : snprintf(stats_overlay, sizeof(stats_overlay), "Val: %.4f", current);
873 [ # # ]: 0 : text_size = font->CalcTextSizeA(font_size, FLT_MAX, 0.0f, stats_overlay);
874 : : }
875 : : }
876 [ + - ]: 992 : draw_list->AddRectFilled(ImVec2(p_min.x - 1, p_min.y), ImVec2(p_min.x + text_size.x + 2, p_min.y + text_size.y), IM_COL32(0, 0, 0, 90));
877 [ + - ]: 992 : draw_list->AddText(font, font_size, p_min, IM_COL32(255, 255, 255, 255), stats_overlay);
878 : 992 : }
879 : :
880 : : // Global Buffers
881 : : static RollingBuffer plot_total, plot_base, plot_sop, plot_yaw_kick, plot_rear_torque, plot_gyro_damping, plot_scrub_drag, plot_soft_lock, plot_oversteer, plot_understeer, plot_clipping, plot_road, plot_slide, plot_lockup, plot_spin, plot_bottoming;
882 : : static RollingBuffer plot_calc_front_load, plot_calc_rear_load, plot_calc_front_grip, plot_calc_rear_grip, plot_calc_slip_ratio, plot_calc_slip_angle_smoothed, plot_calc_rear_slip_angle_smoothed, plot_slope_current, plot_calc_rear_lat_force;
883 : : static RollingBuffer plot_raw_steer, plot_raw_shaft_torque, plot_raw_gen_torque, plot_raw_input_steering, plot_raw_throttle, plot_raw_brake, plot_input_accel, plot_raw_car_speed, plot_raw_load, plot_raw_grip, plot_raw_rear_grip, plot_raw_front_slip_ratio, plot_raw_susp_force, plot_raw_ride_height, plot_raw_front_lat_patch_vel, plot_raw_front_long_patch_vel, plot_raw_rear_lat_patch_vel, plot_raw_rear_long_patch_vel, plot_raw_slip_angle, plot_raw_rear_slip_angle, plot_raw_front_deflection;
884 : :
885 : : static bool g_warn_dt = false;
886 : :
887 : 63 : void GuiLayer::DrawDebugWindow(FFBEngine& engine) {
888 [ + + ]: 63 : if (!Config::show_graphs) return;
889 : :
890 [ + - ]: 62 : ImGuiViewport* viewport = ImGui::GetMainViewport();
891 [ + - ]: 62 : ImGui::SetNextWindowPos(ImVec2(viewport->Pos.x + CONFIG_PANEL_WIDTH, viewport->Pos.y));
892 [ + - ]: 62 : ImGui::SetNextWindowSize(ImVec2(viewport->Size.x - CONFIG_PANEL_WIDTH, viewport->Size.y));
893 : :
894 : 62 : ImGuiWindowFlags flags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize;
895 [ + - ]: 62 : ImGui::Begin("FFB Analysis", nullptr, flags);
896 : :
897 : : // System Health Diagnostics (Moved from Tuning window - Issue #149)
898 [ + - + - ]: 62 : if (ImGui::CollapsingHeader("System Health (Hz)", ImGuiTreeNodeFlags_DefaultOpen)) {
899 [ + - ]: 62 : ImGui::Columns(5, "RateCols", false);
900 [ + - ]: 62 : DisplayRate("FFB Loop", engine.m_ffb_rate, 400.0);
901 [ + - ]: 62 : ImGui::NextColumn();
902 [ + - ]: 62 : DisplayRate("Telemetry", engine.m_telemetry_rate, 400.0);
903 [ + - ]: 62 : ImGui::NextColumn();
904 [ + - ]: 62 : DisplayRate("Hardware", engine.m_hw_rate, 400.0);
905 [ + - ]: 62 : ImGui::NextColumn();
906 [ + - ]: 62 : DisplayRate("S.Torque", engine.m_torque_rate, 400.0);
907 [ + - ]: 62 : ImGui::NextColumn();
908 [ + - ]: 62 : DisplayRate("G.Torque", engine.m_gen_torque_rate, 400.0);
909 [ + - ]: 62 : ImGui::Columns(1);
910 [ - + - - : 62 : if ((engine.m_telemetry_rate < 380.0 || engine.m_torque_rate < 380.0) && engine.m_telemetry_rate > 1.0 && GameConnector::Get().IsConnected()) {
+ + + - +
- + - +
+ ]
911 [ + - ]: 6 : ImGui::TextColored(ImVec4(1, 1, 0, 1), "Warning: Low telemetry/torque rate. Check game FFB settings.");
912 : : }
913 [ + - ]: 62 : ImGui::Separator();
914 : : }
915 : :
916 [ + - ]: 62 : auto snapshots = engine.GetDebugBatch();
917 [ + + ]: 63 : for (const auto& snap : snapshots) {
918 : 1 : plot_total.Add(snap.total_output);
919 : 1 : plot_base.Add(snap.base_force);
920 : 1 : plot_sop.Add(snap.sop_force);
921 : 1 : plot_yaw_kick.Add(snap.ffb_yaw_kick);
922 : 1 : plot_rear_torque.Add(snap.ffb_rear_torque);
923 : 1 : plot_gyro_damping.Add(snap.ffb_gyro_damping);
924 : 1 : plot_scrub_drag.Add(snap.ffb_scrub_drag);
925 : 1 : plot_soft_lock.Add(snap.ffb_soft_lock);
926 : 1 : plot_oversteer.Add(snap.oversteer_boost);
927 : 1 : plot_understeer.Add(snap.understeer_drop);
928 : 1 : plot_clipping.Add(snap.clipping);
929 : 1 : plot_road.Add(snap.texture_road);
930 : 1 : plot_slide.Add(snap.texture_slide);
931 : 1 : plot_lockup.Add(snap.texture_lockup);
932 : 1 : plot_spin.Add(snap.texture_spin);
933 : 1 : plot_bottoming.Add(snap.texture_bottoming);
934 : 1 : plot_calc_front_load.Add(snap.calc_front_load);
935 : 1 : plot_calc_rear_load.Add(snap.calc_rear_load);
936 : 1 : plot_calc_front_grip.Add(snap.calc_front_grip);
937 : 1 : plot_calc_rear_grip.Add(snap.calc_rear_grip);
938 : 1 : plot_calc_slip_ratio.Add(snap.calc_front_slip_ratio);
939 : 1 : plot_calc_slip_angle_smoothed.Add(snap.calc_front_slip_angle_smoothed);
940 : 1 : plot_calc_rear_slip_angle_smoothed.Add(snap.calc_rear_slip_angle_smoothed);
941 : 1 : plot_calc_rear_lat_force.Add(snap.calc_rear_lat_force);
942 : 1 : plot_slope_current.Add(snap.slope_current);
943 : 1 : plot_raw_steer.Add(snap.steer_force);
944 : 1 : plot_raw_shaft_torque.Add(snap.raw_shaft_torque);
945 : 1 : plot_raw_gen_torque.Add(snap.raw_gen_torque);
946 : 1 : plot_raw_input_steering.Add(snap.raw_input_steering);
947 : 1 : plot_raw_throttle.Add(snap.raw_input_throttle);
948 : 1 : plot_raw_brake.Add(snap.raw_input_brake);
949 : 1 : plot_input_accel.Add(snap.accel_x);
950 : 1 : plot_raw_car_speed.Add(snap.raw_car_speed);
951 : 1 : plot_raw_load.Add(snap.raw_front_tire_load);
952 : 1 : plot_raw_grip.Add(snap.raw_front_grip_fract);
953 : 1 : plot_raw_rear_grip.Add(snap.raw_rear_grip);
954 : 1 : plot_raw_front_slip_ratio.Add(snap.raw_front_slip_ratio);
955 : 1 : plot_raw_susp_force.Add(snap.raw_front_susp_force);
956 : 1 : plot_raw_ride_height.Add(snap.raw_front_ride_height);
957 : 1 : plot_raw_front_lat_patch_vel.Add(snap.raw_front_lat_patch_vel);
958 : 1 : plot_raw_front_long_patch_vel.Add(snap.raw_front_long_patch_vel);
959 : 1 : plot_raw_rear_lat_patch_vel.Add(snap.raw_rear_lat_patch_vel);
960 : 1 : plot_raw_rear_long_patch_vel.Add(snap.raw_rear_long_patch_vel);
961 : 1 : plot_raw_slip_angle.Add(snap.raw_front_slip_angle);
962 : 1 : plot_raw_rear_slip_angle.Add(snap.raw_rear_slip_angle);
963 : 1 : plot_raw_front_deflection.Add(snap.raw_front_deflection);
964 : 1 : g_warn_dt = snap.warn_dt;
965 : : }
966 : :
967 [ + + ]: 62 : if (g_warn_dt) {
968 [ + - ]: 50 : ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1.0f, 0.0f, 0.0f, 1.0f));
969 [ + - ]: 50 : ImGui::Text("TELEMETRY WARNINGS: - Invalid DeltaTime");
970 [ + - ]: 50 : ImGui::PopStyleColor();
971 [ + - ]: 50 : ImGui::Separator();
972 : : }
973 : :
974 [ + - + - ]: 62 : if (ImGui::CollapsingHeader("A. FFB Components (Output)", ImGuiTreeNodeFlags_DefaultOpen)) {
975 [ + - ]: 62 : PlotWithStats("Total Output", plot_total, -1.0f, 1.0f, ImVec2(0, 60));
976 [ + - ]: 62 : ImGui::Separator();
977 [ + - ]: 62 : ImGui::Columns(3, "FFBMain", false);
978 [ + - ]: 62 : ImGui::TextColored(ImVec4(0.7f, 0.7f, 1.0f, 1.0f), "[Main Forces]");
979 [ + - ]: 62 : PlotWithStats("Base Torque (Nm)", plot_base, -30.0f, 30.0f);
980 [ + - ]: 62 : PlotWithStats("SoP (Chassis G)", plot_sop, -20.0f, 20.0f);
981 [ + - ]: 62 : PlotWithStats("Yaw Kick", plot_yaw_kick, -20.0f, 20.0f);
982 [ + - ]: 62 : PlotWithStats("Rear Align", plot_rear_torque, -20.0f, 20.0f);
983 [ + - ]: 62 : PlotWithStats("Gyro Damping", plot_gyro_damping, -20.0f, 20.0f);
984 [ + - ]: 62 : PlotWithStats("Scrub Drag", plot_scrub_drag, -20.0f, 20.0f);
985 [ + - ]: 62 : PlotWithStats("Soft Lock", plot_soft_lock, -50.0f, 50.0f);
986 [ + - ]: 62 : ImGui::NextColumn();
987 [ + - ]: 62 : ImGui::TextColored(ImVec4(1.0f, 0.7f, 0.7f, 1.0f), "[Modifiers]");
988 [ + - ]: 62 : PlotWithStats("Lateral G Boost", plot_oversteer, -20.0f, 20.0f);
989 [ + - ]: 62 : PlotWithStats("Understeer Cut", plot_understeer, -20.0f, 20.0f);
990 [ + - ]: 62 : PlotWithStats("Clipping", plot_clipping, 0.0f, 1.1f);
991 [ + - ]: 62 : ImGui::NextColumn();
992 [ + - ]: 62 : ImGui::TextColored(ImVec4(0.7f, 1.0f, 0.7f, 1.0f), "[Textures]");
993 [ + - ]: 62 : PlotWithStats("Road Texture", plot_road, -10.0f, 10.0f);
994 [ + - ]: 62 : PlotWithStats("Slide Texture", plot_slide, -10.0f, 10.0f);
995 [ + - ]: 62 : PlotWithStats("Lockup Vib", plot_lockup, -10.0f, 10.0f);
996 [ + - ]: 62 : PlotWithStats("Spin Vib", plot_spin, -10.0f, 10.0f);
997 [ + - ]: 62 : PlotWithStats("Bottoming", plot_bottoming, -10.0f, 10.0f);
998 [ + - ]: 62 : ImGui::Columns(1);
999 : : }
1000 : :
1001 [ + - - + ]: 62 : if (ImGui::CollapsingHeader("B. Internal Physics (Brain)", ImGuiTreeNodeFlags_None)) {
1002 [ # # ]: 0 : ImGui::Columns(3, "PhysCols", false);
1003 [ # # ]: 0 : ImGui::TextColored(ImVec4(1.0f, 1.0f, 0.0f, 1.0f), "[Loads]");
1004 [ # # ]: 0 : ImGui::Text("Front: %.0f N | Rear: %.0f N", plot_calc_front_load.GetCurrent(), plot_calc_rear_load.GetCurrent());
1005 [ # # ]: 0 : ImGui::PushStyleColor(ImGuiCol_PlotLines, ImVec4(0.0f, 1.0f, 1.0f, 1.0f));
1006 [ # # ]: 0 : ImGui::PlotLines("##CLoadF", plot_calc_front_load.data.data(), (int)plot_calc_front_load.data.size(), plot_calc_front_load.offset, NULL, 0.0f, 10000.0f, ImVec2(0, 40));
1007 [ # # ]: 0 : ImGui::PopStyleColor();
1008 [ # # ]: 0 : ImVec2 pos_load = ImGui::GetItemRectMin();
1009 [ # # ]: 0 : ImGui::SetCursorScreenPos(pos_load);
1010 [ # # ]: 0 : ImGui::PushStyleColor(ImGuiCol_FrameBg, ImVec4(0,0,0,0));
1011 [ # # ]: 0 : ImGui::PushStyleColor(ImGuiCol_PlotLines, ImVec4(1.0f, 0.0f, 1.0f, 1.0f));
1012 [ # # ]: 0 : ImGui::PlotLines("##CLoadR", plot_calc_rear_load.data.data(), (int)plot_calc_rear_load.data.size(), plot_calc_rear_load.offset, NULL, 0.0f, 10000.0f, ImVec2(0, 40));
1013 [ # # ]: 0 : ImGui::PopStyleColor(2);
1014 [ # # ]: 0 : ImGui::NextColumn();
1015 [ # # ]: 0 : ImGui::TextColored(ImVec4(1.0f, 1.0f, 0.0f, 1.0f), "[Grip/Slip]");
1016 [ # # ]: 0 : PlotWithStats("Calc Front Grip", plot_calc_front_grip, 0.0f, 1.2f);
1017 [ # # ]: 0 : PlotWithStats("Calc Rear Grip", plot_calc_rear_grip, 0.0f, 1.2f);
1018 [ # # ]: 0 : PlotWithStats("Front Slip Ratio", plot_calc_slip_ratio, -1.0f, 1.0f);
1019 [ # # ]: 0 : PlotWithStats("Front Slip Angle", plot_calc_slip_angle_smoothed, 0.0f, 1.0f);
1020 [ # # ]: 0 : PlotWithStats("Rear Slip Angle", plot_calc_rear_slip_angle_smoothed, 0.0f, 1.0f);
1021 [ # # # # ]: 0 : if (engine.m_slope_detection_enabled) PlotWithStats("Slope", plot_slope_current, -5.0f, 5.0f);
1022 [ # # ]: 0 : ImGui::NextColumn();
1023 [ # # ]: 0 : ImGui::TextColored(ImVec4(1.0f, 1.0f, 0.0f, 1.0f), "[Forces]");
1024 [ # # ]: 0 : PlotWithStats("Calc Rear Lat Force", plot_calc_rear_lat_force, -5000.0f, 5000.0f);
1025 [ # # ]: 0 : ImGui::Columns(1);
1026 : : }
1027 : :
1028 [ + - - + ]: 62 : if (ImGui::CollapsingHeader("C. Raw Game Telemetry (Input)", ImGuiTreeNodeFlags_None)) {
1029 [ # # ]: 0 : ImGui::Columns(4, "TelCols", false);
1030 [ # # ]: 0 : ImGui::TextColored(ImVec4(0.0f, 1.0f, 1.0f, 1.0f), "[Driver Input]");
1031 [ # # ]: 0 : PlotWithStats("Selected Torque", plot_raw_steer, -30.0f, 30.0f, ImVec2(0, 40), Tooltips::PLOT_SELECTED_TORQUE);
1032 [ # # ]: 0 : PlotWithStats("Shaft Torque (100Hz)", plot_raw_shaft_torque, -30.0f, 30.0f, ImVec2(0, 40), Tooltips::PLOT_SHAFT_TORQUE);
1033 [ # # ]: 0 : PlotWithStats("In-Game FFB (400Hz)", plot_raw_gen_torque, -30.0f, 30.0f, ImVec2(0, 40), Tooltips::PLOT_INGAME_FFB);
1034 [ # # ]: 0 : PlotWithStats("Steering Input", plot_raw_input_steering, -1.0f, 1.0f);
1035 [ # # ]: 0 : ImGui::Text("Combined Input");
1036 [ # # ]: 0 : ImVec2 pos = ImGui::GetCursorScreenPos();
1037 [ # # ]: 0 : ImGui::PushStyleColor(ImGuiCol_PlotLines, ImVec4(1.0f, 0.0f, 0.0f, 1.0f));
1038 [ # # ]: 0 : ImGui::PlotLines("##BrkComb", plot_raw_brake.data.data(), (int)plot_raw_brake.data.size(), plot_raw_brake.offset, NULL, 0.0f, 1.0f, ImVec2(0, 40));
1039 [ # # ]: 0 : ImGui::PopStyleColor();
1040 [ # # ]: 0 : ImGui::SetCursorScreenPos(pos);
1041 [ # # ]: 0 : ImGui::PushStyleColor(ImGuiCol_PlotLines, ImVec4(0.0f, 1.0f, 0.0f, 1.0f));
1042 [ # # ]: 0 : ImGui::PushStyleColor(ImGuiCol_FrameBg, ImVec4(0.0f, 0.0f, 0.0f, 0.0f));
1043 [ # # ]: 0 : ImGui::PlotLines("##ThrComb", plot_raw_throttle.data.data(), (int)plot_raw_throttle.data.size(), plot_raw_throttle.offset, NULL, 0.0f, 1.0f, ImVec2(0, 40));
1044 [ # # ]: 0 : ImGui::PopStyleColor(2);
1045 [ # # ]: 0 : ImGui::NextColumn();
1046 [ # # ]: 0 : ImGui::TextColored(ImVec4(0.0f, 1.0f, 1.0f, 1.0f), "[Vehicle State]");
1047 [ # # ]: 0 : PlotWithStats("Lat Accel", plot_input_accel, -20.0f, 20.0f);
1048 [ # # ]: 0 : PlotWithStats("Speed (m/s)", plot_raw_car_speed, 0.0f, 100.0f);
1049 [ # # ]: 0 : ImGui::NextColumn();
1050 [ # # ]: 0 : ImGui::TextColored(ImVec4(0.0f, 1.0f, 1.0f, 1.0f), "[Raw Tire Data]");
1051 [ # # ]: 0 : PlotWithStats("Raw Front Load", plot_raw_load, 0.0f, 10000.0f);
1052 [ # # ]: 0 : PlotWithStats("Raw Front Grip", plot_raw_grip, 0.0f, 1.2f);
1053 [ # # ]: 0 : PlotWithStats("Raw Rear Grip", plot_raw_rear_grip, 0.0f, 1.2f);
1054 [ # # ]: 0 : ImGui::NextColumn();
1055 [ # # ]: 0 : ImGui::TextColored(ImVec4(0.0f, 1.0f, 1.0f, 1.0f), "[Patch Velocities]");
1056 [ # # ]: 0 : PlotWithStats("F-Lat PatchVel", plot_raw_front_lat_patch_vel, 0.0f, 20.0f);
1057 [ # # ]: 0 : PlotWithStats("R-Lat PatchVel", plot_raw_rear_lat_patch_vel, 0.0f, 20.0f);
1058 [ # # ]: 0 : PlotWithStats("F-Long PatchVel", plot_raw_front_long_patch_vel, -20.0f, 20.0f);
1059 [ # # ]: 0 : PlotWithStats("R-Long PatchVel", plot_raw_rear_long_patch_vel, -20.0f, 20.0f);
1060 [ # # ]: 0 : ImGui::Columns(1);
1061 : : }
1062 : :
1063 [ + - ]: 62 : ImGui::End();
1064 : 62 : }
1065 : : #endif
|