Files
spice2x.github.io/src/spice2x/games/rb/rb.cpp
T
bicarus d7c144646f rawinput: deal with high poll rate devices, use 3x3 for default for rb touch emu (#796)
## Link to GitHub Issue or related Pull Request, if one exists
n/a

## Description of change
Two changes:

1. Handle all HID events in `WM_INPUT` and not just the first one. This
only really affects 4000Hz / 8000Hz HID devices.
2. Go back to `3x3` as the default for rb IR touch emulation and remove
`1x1` as an option as it does not perform as well as I expected.

## Testing
2026-07-12 10:32:29 -07:00

71 lines
1.7 KiB
C++

#include "rb.h"
#include "avs/game.h"
#include "hooks/devicehook.h"
#include "hooks/audio/backends/dsound/dsound_backend.h"
#include "util/detour.h"
#include "util/precise_timer.h"
#include "util/logging.h"
#include "cfg/configurator.h"
#include "touch.h"
namespace games::rb {
uint16_t TOUCH_POLL_RATE = 0;
}
static decltype(SleepEx) *SleepEx_orig;
static DWORD WINAPI SleepEx_hook(DWORD dwMilliseconds, BOOL bAlertable) {
// increase touch poll rate
if (dwMilliseconds == 8) {
dwMilliseconds = 1000 / games::rb::TOUCH_POLL_RATE;
}
// most calls from rb are actually non-alertable
if (!bAlertable) {
static thread_local timeutils::PreciseSleepTimer timer;
timer.sleep(dwMilliseconds);
return 0;
}
// call original
return SleepEx_orig(dwMilliseconds, bAlertable);
}
games::rb::RBGame::RBGame() : Game("Reflec Beat") {
}
void games::rb::RBGame::attach() {
Game::attach();
if (1000 < games::rb::TOUCH_POLL_RATE) {
log_fatal("rb", "-rbtouchhz is set too high; cannot exceed 1000");
}
// init stuff
devicehook_init();
// add touch device
devicehook_add(new ReflecBeatTouchDeviceHandle(false));
if (avs::game::is_model({"KBR", "LBR"})) {
// dsound.dll hook
audio_dsound_init();
}
// hooks
if (0 < TOUCH_POLL_RATE) {
log_info("rb", "force increasing touch poll rate by hooking SleepEx ({}Hz)", TOUCH_POLL_RATE);
SleepEx_orig = detour::iat_try("SleepEx", SleepEx_hook, avs::game::DLL_INSTANCE);
} else {
log_info("rb", "not changing touch poll rate (~125Hz by default)");
}
}
void games::rb::RBGame::detach() {
Game::detach();
devicehook_dispose();
}