mirror of
https://github.com/spice2x/spice2x.github.io.git
synced 2026-08-02 06:40:42 -07:00
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
This commit is contained in:
@@ -41,7 +41,7 @@ void games::rb::RBGame::attach() {
|
||||
Game::attach();
|
||||
|
||||
if (1000 < games::rb::TOUCH_POLL_RATE) {
|
||||
log_fatal("rb", "-rbtouchsize is set too high; cannot exceed 1000");
|
||||
log_fatal("rb", "-rbtouchhz is set too high; cannot exceed 1000");
|
||||
}
|
||||
|
||||
// init stuff
|
||||
@@ -60,7 +60,7 @@ void games::rb::RBGame::attach() {
|
||||
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 (120Hz by default)");
|
||||
log_info("rb", "not changing touch poll rate (~125Hz by default)");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
namespace games::rb {
|
||||
|
||||
extern uint16_t TOUCH_SCALING;
|
||||
extern uint8_t TOUCH_SIZE;
|
||||
extern uint16_t TOUCH_POLL_RATE;
|
||||
|
||||
class RBGame : public games::Game {
|
||||
|
||||
@@ -14,7 +14,6 @@ static std::string WINDOW_TITLE = "REFLEC BEAT";
|
||||
|
||||
namespace games::rb {
|
||||
uint16_t TOUCH_SCALING = 1000;
|
||||
uint8_t TOUCH_SIZE = 1;
|
||||
}
|
||||
|
||||
games::rb::ReflecBeatTouchDeviceHandle::ReflecBeatTouchDeviceHandle(bool log_fps) {
|
||||
@@ -50,6 +49,9 @@ bool games::rb::ReflecBeatTouchDeviceHandle::open(LPCWSTR lpFileName) {
|
||||
|
||||
if (wnd != nullptr) {
|
||||
|
||||
// cache the game window so read() can size against it regardless of focus
|
||||
this->game_hwnd = wnd;
|
||||
|
||||
// reset window process to make the game not crash
|
||||
SetWindowLongPtr(wnd, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(DefWindowProc));
|
||||
|
||||
@@ -106,8 +108,9 @@ int games::rb::ReflecBeatTouchDeviceHandle::read(LPVOID lpBuffer, DWORD nNumberO
|
||||
return 0;
|
||||
}
|
||||
|
||||
// get window
|
||||
HWND window = GetForegroundWindow();
|
||||
// size against the game window cached in open() (not GetForegroundWindow), so
|
||||
// touch stays correctly scaled and keeps working when the game loses focus
|
||||
HWND window = this->game_hwnd;
|
||||
if (window == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
@@ -166,20 +169,20 @@ int games::rb::ReflecBeatTouchDeviceHandle::read(LPVOID lpBuffer, DWORD nNumberO
|
||||
const auto point_x = (int) ((x - window_width / 2.0) * 48.0 / 54.0 + window_width / 2.0);
|
||||
const auto point_y = (int) (y - window_height / 76);
|
||||
|
||||
// center
|
||||
grid_insert(data, point_x, point_y);
|
||||
|
||||
// surrounding points
|
||||
if (games::rb::TOUCH_SIZE == 3) {
|
||||
grid_insert(data, point_x - offset_x, point_y); // west
|
||||
grid_insert(data, point_x - offset_x, point_y - offset_y); // northwest
|
||||
grid_insert(data, point_x - offset_x, point_y + offset_y); // southwest
|
||||
grid_insert(data, point_x + offset_x, point_y); // east
|
||||
grid_insert(data, point_x + offset_x, point_y + offset_y); // southeast
|
||||
grid_insert(data, point_x + offset_x, point_y - offset_y); // northeast
|
||||
grid_insert(data, point_x, point_y - offset_y); // north
|
||||
grid_insert(data, point_x, point_y + offset_y); // south
|
||||
}
|
||||
// model a finger as a 3x3 block of IR sensors around the touch point
|
||||
// this gives better accuracy (than just 1x1) since the logic below
|
||||
// can toggle anywhere from 1x1 to 2x2, and the game engine calculates
|
||||
// the center point, which means by inserting up to 8 extra blocks
|
||||
// we are emulating a sub-"pixel" resolution
|
||||
grid_insert(data, point_x, point_y); // center
|
||||
grid_insert(data, point_x - offset_x, point_y); // west
|
||||
grid_insert(data, point_x - offset_x, point_y - offset_y); // northwest
|
||||
grid_insert(data, point_x - offset_x, point_y + offset_y); // southwest
|
||||
grid_insert(data, point_x + offset_x, point_y); // east
|
||||
grid_insert(data, point_x + offset_x, point_y + offset_y); // southeast
|
||||
grid_insert(data, point_x + offset_x, point_y - offset_y); // northeast
|
||||
grid_insert(data, point_x, point_y - offset_y); // north
|
||||
grid_insert(data, point_x, point_y + offset_y); // south
|
||||
}
|
||||
|
||||
// copy data to buffer
|
||||
|
||||
@@ -12,6 +12,12 @@ namespace games::rb {
|
||||
int window_width = 1080;
|
||||
int window_height = 1920;
|
||||
|
||||
// game window resolved in open(); read() sizes against this instead of the
|
||||
// foreground window so touch stays correctly scaled and keeps working when
|
||||
// the game is not the foreground window (rawinput delivers touch regardless
|
||||
// of focus)
|
||||
HWND game_hwnd = nullptr;
|
||||
|
||||
// logging
|
||||
bool log_fps = false;
|
||||
uint64_t log_time = 0;
|
||||
|
||||
Reference in New Issue
Block a user