Move controller-poll info from Injection to Controllers panel
The per-slot XInput poll rates and the "game reading controller" summary describe the controller, not the injection mechanism, so move them to the Controllers panel (renamed from debug_overlay -> ControllersPanel, now a class that owns the poll-rate sampling). The panel now shows both directions: the guest pads the host receives from RPT, and what the injected game reads back. The Injection panel keeps the hook attach state, focus spoof, focus-API counts, and input-path diagnostics, and points to the Controllers panel for poll rates. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
157
host/src/controllers_panel.cpp
Normal file
157
host/src/controllers_panel.cpp
Normal file
@@ -0,0 +1,157 @@
|
||||
#include "controllers_panel.hpp"
|
||||
|
||||
#include <imgui.h>
|
||||
|
||||
namespace coop
|
||||
{
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
const ImVec4 kGreen(0.4f, 1.0f, 0.4f, 1.0f);
|
||||
const ImVec4 kGrey(0.7f, 0.7f, 0.7f, 1.0f);
|
||||
|
||||
struct ButtonBit
|
||||
{
|
||||
std::uint16_t mask;
|
||||
const char* label;
|
||||
};
|
||||
|
||||
// XINPUT_GAMEPAD_* bit values (kept local so this file needn't include Xinput.h).
|
||||
constexpr ButtonBit kButtons[] = {
|
||||
{0x0001, "Up"}, {0x0002, "Down"}, {0x0004, "Left"}, {0x0008, "Right"}, {0x0010, "Start"},
|
||||
{0x0020, "Back"}, {0x0040, "LS"}, {0x0080, "RS"}, {0x0100, "LB"}, {0x0200, "RB"},
|
||||
{0x1000, "A"}, {0x2000, "B"}, {0x4000, "X"}, {0x8000, "Y"},
|
||||
};
|
||||
|
||||
void draw_pad(int index, const PadInfo& pad, bool debug_details)
|
||||
{
|
||||
ImGui::PushID(index);
|
||||
if (!pad.connected)
|
||||
{
|
||||
ImGui::TextDisabled("Slot %d: disconnected", index);
|
||||
ImGui::PopID();
|
||||
return;
|
||||
}
|
||||
|
||||
ImGui::TextColored(kGreen, "Slot %d [%s]", index, pad.source.c_str());
|
||||
|
||||
bool first = true;
|
||||
ImGui::TextUnformatted("Buttons: ");
|
||||
for (const ButtonBit& b : kButtons)
|
||||
{
|
||||
if ((pad.state.buttons & b.mask) != 0)
|
||||
{
|
||||
ImGui::SameLine();
|
||||
ImGui::TextColored(kGreen, "%s%s", first ? "" : ", ", b.label);
|
||||
first = false;
|
||||
}
|
||||
}
|
||||
if (first)
|
||||
{
|
||||
ImGui::SameLine();
|
||||
ImGui::TextDisabled("(none)");
|
||||
}
|
||||
|
||||
if (debug_details)
|
||||
{
|
||||
ImGui::Text("LT %3u RT %3u", pad.state.left_trigger, pad.state.right_trigger);
|
||||
ImGui::Text("L (%6d, %6d) R (%6d, %6d)", pad.state.thumb_lx, pad.state.thumb_ly,
|
||||
pad.state.thumb_rx, pad.state.thumb_ry);
|
||||
}
|
||||
ImGui::Separator();
|
||||
ImGui::PopID();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void ControllersPanel::draw(const InputSource& input, const HookStatusView& status, bool debug_details)
|
||||
{
|
||||
ImGui::SetNextWindowPos(ImVec2(24, 40), ImGuiCond_FirstUseEver);
|
||||
ImGui::SetNextWindowSize(ImVec2(420, 0), ImGuiCond_FirstUseEver);
|
||||
ImGui::Begin("Controllers");
|
||||
|
||||
ImGui::Text("Input backend: %s", input.name());
|
||||
ImGui::TextDisabled("This window is what Remote Play Together captures.");
|
||||
ImGui::TextDisabled("F1: hide overlay (clean mirror) Esc: quit");
|
||||
|
||||
// --- Guest pads the host receives from RPT -----------------------------
|
||||
ImGui::SeparatorText("Incoming (host receives)");
|
||||
const auto& pads = input.pads();
|
||||
for (int i = 0; i < static_cast<int>(pads.size()); ++i)
|
||||
{
|
||||
draw_pad(i, pads[i], debug_details);
|
||||
}
|
||||
|
||||
// --- What the injected game reads back via the XInput hook --------------
|
||||
ImGui::SeparatorText("Game polling (hook reports)");
|
||||
if (!status.attached)
|
||||
{
|
||||
ImGui::TextDisabled("Not injected (no XInput hook).");
|
||||
ImGui::End();
|
||||
return;
|
||||
}
|
||||
|
||||
// Convert the cumulative per-slot counters into rates every half second.
|
||||
const double now = ImGui::GetTime();
|
||||
if (now - last_sample_time_ >= 0.5)
|
||||
{
|
||||
const double dt = now - last_sample_time_;
|
||||
for (int i = 0; i < static_cast<int>(kMaxPads); ++i)
|
||||
{
|
||||
const unsigned long long delta =
|
||||
status.get_state[i] >= last_state_count_[i] ? status.get_state[i] - last_state_count_[i] : 0;
|
||||
state_rate_[i] = dt > 0.0 ? static_cast<double>(delta) / dt : 0.0;
|
||||
last_state_count_[i] = status.get_state[i];
|
||||
}
|
||||
last_sample_time_ = now;
|
||||
}
|
||||
|
||||
double total_rate = 0.0;
|
||||
for (int i = 0; i < static_cast<int>(kMaxPads); ++i)
|
||||
{
|
||||
total_rate += state_rate_[i];
|
||||
}
|
||||
if (total_rate > 0.0)
|
||||
{
|
||||
ImGui::TextColored(kGreen, "Game reading controller: %.0f polls/s", total_rate);
|
||||
}
|
||||
else
|
||||
{
|
||||
ImGui::TextColored(kGrey, "Game reading controller: idle");
|
||||
}
|
||||
|
||||
if (debug_details &&
|
||||
ImGui::BeginTable("slots", 4, ImGuiTableFlags_Borders | ImGuiTableFlags_SizingStretchProp))
|
||||
{
|
||||
ImGui::TableSetupColumn("Slot");
|
||||
ImGui::TableSetupColumn("GetState/s");
|
||||
ImGui::TableSetupColumn("GetState total");
|
||||
ImGui::TableSetupColumn("GetCaps total");
|
||||
ImGui::TableHeadersRow();
|
||||
for (int i = 0; i < static_cast<int>(kMaxPads); ++i)
|
||||
{
|
||||
ImGui::TableNextRow();
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("%d", i);
|
||||
ImGui::TableNextColumn();
|
||||
if (state_rate_[i] > 0.0)
|
||||
{
|
||||
ImGui::TextColored(kGreen, "%.0f", state_rate_[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
ImGui::TextDisabled("0");
|
||||
}
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("%llu", static_cast<unsigned long long>(status.get_state[i]));
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("%llu", static_cast<unsigned long long>(status.get_caps[i]));
|
||||
}
|
||||
ImGui::EndTable();
|
||||
}
|
||||
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
} // namespace coop
|
||||
Reference in New Issue
Block a user