Trackball: poll every iteration, count all pulses, accelerate
The crosshair crawled one 14px segment per tick because the ball pins were sampled only once per game frame (33 ms) and just compared to the previous level: a fast roll completed whole pulse cycles between reads, so most edges were dropped and at most one step per frame was applied. Now pollTrackball() runs in the loop() hot path (~1 ms apart) and counts every edge into per-direction accumulators; applyTrackball() consumes them once per frame, moving the cross steps * CROSS_STEP and capping at CROSS_MAX_STEP (48 px/frame) — slow roll = fine steps, hard flick = the cursor flies across the screen, arcade-style. Accumulation is disabled outside PLAYING/BANNER and the first read is primed so the power-up pin levels don't count as steps. Emulator: mouse wheel now simulates ball pulses (6 edges per notch, drained one toggle per iteration) for desktop testing.
This commit is contained in:
+22
-1
@@ -3,6 +3,7 @@
|
||||
*
|
||||
* Input mapping:
|
||||
* Arrow keys trackball roll (hold to keep rolling)
|
||||
* Mouse wheel trackball roll (each notch = a ball pulse burst)
|
||||
* Enter / right-click trackball press (fire)
|
||||
* Left-click screen tap (aim + fire)
|
||||
* A S D fire from left / center / right battery
|
||||
@@ -93,6 +94,8 @@ int main(int argc, char **argv)
|
||||
|
||||
const uint8_t dirPin[4] = { BOARD_TBOX_G02, BOARD_TBOX_G01, BOARD_TBOX_G04, BOARD_TBOX_G03 };
|
||||
bool held[4] = { false, false, false, false };
|
||||
// mouse wheel -> simulated ball pulses: pending pin toggles per direction
|
||||
int wheelPulse[4] = { 0, 0, 0, 0 };
|
||||
uint32_t frame = 0;
|
||||
|
||||
bool running = true;
|
||||
@@ -149,6 +152,17 @@ int main(int argc, char **argv)
|
||||
break;
|
||||
}
|
||||
|
||||
case SDL_MOUSEWHEEL: {
|
||||
// Each wheel notch = a burst of ball edges on the matching
|
||||
// direction pin (emitted over the next few iterations).
|
||||
const int perNotch = 6;
|
||||
if (e.wheel.y > 0) wheelPulse[1] += perNotch * e.wheel.y; // up
|
||||
if (e.wheel.y < 0) wheelPulse[3] += perNotch * -e.wheel.y; // down
|
||||
if (e.wheel.x > 0) wheelPulse[0] += perNotch * e.wheel.x; // right
|
||||
if (e.wheel.x < 0) wheelPulse[2] += perNotch * -e.wheel.x; // left
|
||||
break;
|
||||
}
|
||||
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
case SDL_MOUSEBUTTONUP: {
|
||||
int ww, wh;
|
||||
@@ -175,7 +189,14 @@ int main(int argc, char **argv)
|
||||
}
|
||||
|
||||
// Simulate a rolling trackball: toggle the held quadrant pin so the
|
||||
// game keeps seeing edges while the arrow key is down.
|
||||
// game keeps seeing edges while the arrow key is down, and drain the
|
||||
// mouse-wheel pulse queues (one toggle per iteration = one ball edge).
|
||||
for (int d = 0; d < 4; d++) {
|
||||
if (wheelPulse[d] > 0) {
|
||||
emu::pinLevels[dirPin[d]] ^= 1;
|
||||
wheelPulse[d]--;
|
||||
}
|
||||
}
|
||||
if (++frame % 3 == 0) {
|
||||
for (int d = 0; d < 4; d++) {
|
||||
if (held[d]) emu::pinLevels[dirPin[d]] ^= 1;
|
||||
|
||||
Reference in New Issue
Block a user