f68a3439d3455e57c1f80aff84473e3098914b7c
3
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
6f58d9ab68 |
MDX: Decoupled Input Polling Rate From Game Refresh Rate (P4IO Timing Fix) (#446)
## Context In the real implementation of `ac_io_mdxf_update_control_status_buffer`, it doesn't actually add entries to the pad state ring buffers (it only marks the head entry as the "last consumed" entry), and `arkmdxp4.dll` expects the ring buffers to be updated at regular intervals inside `libacio2.dll` at ~250Hz per player. Instead, in the emulated version, the updates happen in this function and that regular interval is established internally using the game's refresh rate (60Hz, 120Hz, 144Hz, etc.). This effectively locks the polling rate of pad input to that refresh rate, which is quite low for pad input. ## Description of change The polling rate lock was circumvented by calling `ac_io_mdxf_update_control_status_buffer` as soon as the game receives controller input in `rawinput.cpp`. A simple wrapper function `mdxf_poll` was exposed so press and release events could be added to the ring buffers in real time as they happen. After each controller event in `rawinput.cpp`, `mdxf_poll` calls `ac_io_mdxf_update_control_status_buffer` for each player, checking the pad's current state and adding it to the ring buffer if it's changed since the last call. This results in the 0 -> 1 (press) and 1 -> 0 (release) state transitions used for gameplay to be based only on the real-time events inserted from `rawinput.cpp`, while leaving the rest of the entries generated from the main `arkmdxp4.dll` thread as "padding" the game expects (I actually tried reducing the ring buffers to *only* write entries on state transitions, but it broke gameplay, which means the game still depends regular reporting of the pad state). Here's an example of how a ring buffer would look if an arrow was pressed at some time 32ms (assume 165Hz game refresh rate, ~6ms updates): ``` Old (only frame updates): 1 | 36ms 0 | 30ms 0 | 24ms 0 | 18ms 0 | 12ms 0 | 6ms 0 | 0ms ``` The game only sees the press event at time 36ms on frame update, so time 36ms is assigned to the press time of that arrow (4ms later than the real press time). ``` New (frame updates + event updates from rawinput.cpp): 1 | 36ms 1 | 32ms <- from rawinput.cpp 0 | 30ms 0 | 24ms 0 | 18ms 0 | 12ms 0 | 6ms ``` The game sees the real press time 32ms on frame update, so the correct press time 32ms is assigned. ## Testing - Played on various refresh rates and verified the controller input remains highly responsive. - Inspected the ring buffers with a debugger and verified entries for press and release events from `rawinput.cpp` were correctly being added for their respective players. |
||
|
|
dc7d8515d3 |
MDX: Fixed Ring Buffer Traversal Direction (P4IO Timing Fix) (#441)
## Description of change In the real `libacio2.dll` implementation, `ac_io_mdxf_get_control_status_buffer` returns the ring buffer entry at `(head - index) mod size` but this function was using `(head + index) mod size` instead. Basically, `index` is supposed to indicate how many entries back, not forward. This was causing the polling history of each player to be returned backwards. A few other things were updated to bring the function's behavior closer to the real implementation: 1. Number of ring buffer entries per player were increased to 16 (this is the size of them in the real implementation) 2. `ac_io_mdxf_get_control_status_buffer` now returns the current head of the ring buffer (instead of a success/failure boolean), which is what `arkmdxp4.dll` expects. ## Testing I played a few songs to make sure nothing was broken. I also attached a debugger and verified the ring buffer entries are *actually* now being returned in reverse chronological order as intended. |
||
|
|
e5808257ca |
MDX: Fixed Status Control Buffer Emulators (P4IO Timing Fix) (#439)
## Description of change In its current state, the emulated `libacio2.dll` functions `ac_io_mdxf_get_control_status_buffer` and `ac_io_mdxf_update_control_status_buffer` only operate using a single head pointer (`COUNTER`) for the ring buffers of `[panel_state,timestamp]` (simplified for brevity here) polls for both players, when they should be maintaining a separate head pointer for each ring buffer. On every frame, `arkmdxp4.dll` makes calls to `ac_io_mdxf_update_control_status_buffer`, which [in this emulated version] advances the head pointer, creates a new entry for the latest panel state info along with the current time, and stores it at the head of the ring buffer. This function is called for each player: After the call for 1P, the head pointer is advanced by 1, so by the time it's called for 2P, the head pointer had already been advanced by 1, meaning the new entry for 2P's panel state ring buffer is written two entries ahead of where the last entry for 2P was written. This is an example of how the entries were written for each ring buffer: ``` Frame 1: 1P[0] = t0 2P[1] = t0 Frame 2: 1P[2] = t1 2P[3] = t1 Frame 3: 1P[4] = t2 2P[5] = t2 Frame 4: 1P[6] = t3 2P[0] = t3 ... Frame 7: 1P[5] = t6 2P[6] = t6 Frame 8: 1P[0] = t7 2P[1] = t7 ``` This is an issue because `arkmdxp4.dll` calls `ac_io_mdxf_get_control_status_buffer` on every frame to load the last 7 polls for each player, which depends on the ring buffer entries being in reverse chronological order to properly determine when an arrow is pressed and when it was released, but this is what it sees from the ring buffers after 8 frames: ``` 1P: t7 -> t3 -> t6 -> t2 -> t5 -> t1 -> t4 2P: t7 -> t3 -> t6 -> t2 -> t5 -> t1 -> t4 ``` In this case, `arkmdxp4.dll` assigns step times based on polls that are out of order, resulting in unpredictable timestamp assignment to each step, with the issue compounding at lower framerates since the timestamp deltas between each poll will be greater (see side note). After implementing two separate head pointers for each ring buffer, those same two arrays become: ``` 1P: t7 -> t6 -> t5 -> t4 -> t3 -> t2 -> t1 2P: t7 -> t6 -> t5 -> t4 -> t3 -> t2 -> t1 ``` This is how `arkmdxp4.dll` expects this data to be structured, so timing should become more consistent after this change. Side note: in this particular p4io implementation, the only place the polls are updated is once per frame on the calls to `ac_io_mdxf_update_control_status_buffer`, meaning the polling rate of the controller used is locked to the framerate of the game. There should be another thread not tied to the main one that listens to input from the OS and updates these ring buffers on a much faster cadence. ## Testing I played a few songs to make sure nothing was broken. I also attached a debugger and verified the ring buffer entries are now being returned in reverse chronological order as intended. |