fix(input): preserve Win16 flipper key latches
Normal ball-end handling keeps the original flipper key bytes and geometry unless the current player has finished. Rust instead reset both flippers on every drain, skipped the normal WAVE 2021 release edge, and treated a key still held after Tilt as a fresh press once Tilt cleared. Preserve flipper state across ordinary drains. Tilt and a player's final ball now clear only the key flags, let the timer epilogue lower raised geometry, and latch each physical key until key-up before accepting another press. This matches the original WM_KEYDOWN/WM_KEYUP lifetime while retaining modern per-frame input sampling. Test Plan: - `cargo test --workspace --all-targets --all-features` -- 119 passed - `cargo clippy --workspace --all-targets --all-features -- -D warnings` -- passed - `rumdl check --flavor commonmark RECONSTRUCTION.md CHANGELOG.md` -- passed - `git diff --cached --check` -- passed
This commit is contained in:
@@ -147,6 +147,10 @@ and this project adheres to
|
||||
Left-Shift, keypad-3, and Space formulas using scalar 15, the shared Borland
|
||||
random stream, 32-bit velocity wrapping, and the decaying 16-bit `+25` tilt
|
||||
counter with its randomized `30..39` threshold.
|
||||
- Preserve held flipper keys and raised geometry across ordinary drains. Tilt
|
||||
and a player's final ball now clear the key latch, release a raised flipper
|
||||
through its normal WAVE 2021 timer edge, and require physical key-up before
|
||||
the same key can raise it again.
|
||||
- Replace the Xorshift gameplay RNG with the original Borland linear stream and
|
||||
unbiased `Random(n)` high-word mapping. Launcher variation, effect selection,
|
||||
claw terminals, and magnetic-field impulses now share the recovered sequence.
|
||||
|
||||
@@ -23,7 +23,7 @@ implementation.
|
||||
| Audio | Exact samples and recovered dispatch | All 16 mono PCM WAV resources are embedded unchanged. Playback is emitted at the reconstructed call sites, including multi-sound bank completions and nudge-then-tilt ordering. Like Win16 `SndPlaySound(SND_ASYNC|SND_NODEFAULT)`, each new resource stops the previous one and plays at the host mixer level without an application-side attenuation. WAV 2022 is loaded by the original generic resource loop but has no playback call and is therefore never played by Rust. |
|
||||
| Help and languages | Exact | Original resource images 1001-1005 are displayed directly. |
|
||||
| Playfield collision layout | Recovered | All 109 active type-2 line objects and 40 static active type-1 circles are transcribed from the original 175-object registration table. The registration routine converts its sideways inputs with `screen = (y, x - 20)` and accumulates explicitly relative objects. Every static record retains its `+0x49` layer mask; the scanner selects layer 1 below the old Y value 250,000 and layer 2 at or above it, while mask 3 records remain shared. Before detection, the raw `1000:9b69` predicted position must lie in the record bounds derived with the registered five-pixel ball margin. Type-2 records retain every recovered Real48 normal/tangent response pair and registered one-sided orientation. Type-1 records retain their swept-circle radius, radial rebound, tangent coupling, and bumper kick. Detection retains unresolved normal/material candidates so later scan-time motion changes can participate in the selected response. Raw stack slot `SS:...d8a2` makes the first detected record ID win; later nearer candidates are stored but never applied, and both C/Rust have two-candidate regression coverage for this quirk. Each flipper uses its exact two line records plus moving tip circle in both positions. Moving-flipper contact ports `1000:7ed9` rather than fitting live samples: delta-specific pivots/edges, integer cross gates, radial/penetration calculations, response-record gain, and position/velocity publication are tested against all four C harness directions and the raised release geometry. Object 174 is overwritten with the live first ball and Rust handles its ball-to-ball role directly. |
|
||||
| Ball launcher and nudge input | Recovered | The initial 32-bit fixed-point coordinates decode to `(325, 413)` in the right shooter lane. Each Down keydown subtracts `15*50 = 750` millipixels, release subtracts another `15*100 = 1500`, and the result follows the recovered randomized `-3800` lower and `-2280` weak upper clamp branches. The ten decoration frames use the same strict 750-millipixel thresholds. Left Shift and keypad 3 apply their directional `(50-Random(20))*15` impulses; Space uses the recovered Real48 horizontal factor and `(60-Random(20))*15` vertical impulse. With two balls, the key path still consumes those active-window draws, then applies its separately recovered fixed/shared random slot impulse to both saved velocities. Each nudge adds 25 to the wrapping 16-bit tilt counter, compares it with `30+Random(10)`, and the detail timer decrements a nonzero counter once per callback. |
|
||||
| Ball launcher and nudge input | Recovered | The initial 32-bit fixed-point coordinates decode to `(325, 413)` in the right shooter lane. Each Down keydown subtracts `15*50 = 750` millipixels, release subtracts another `15*100 = 1500`, and the result follows the recovered randomized `-3800` lower and `-2280` weak upper clamp branches. The ten decoration frames use the same strict 750-millipixel thresholds. Left Shift and keypad 3 apply their directional `(50-Random(20))*15` impulses; Space uses the recovered Real48 horizontal factor and `(60-Random(20))*15` vertical impulse. With two balls, the key path still consumes those active-window draws, then applies its separately recovered fixed/shared random slot impulse to both saved velocities. Each nudge adds 25 to the wrapping 16-bit tilt counter, compares it with `30+Random(10)`, and the detail timer decrements a nonzero counter once per callback. Flipper key flags and raised geometry survive ordinary drains; Tilt and a player's final ball clear the flags, lower raised flippers through the normal WAVE-2021 timer edge, and require a physical key release before another press. |
|
||||
| Physics arithmetic | Recovered Real48 core | Production movement uses the original 10 ms millipixel substep, `+15` vertical acceleration, Real48 `3800/speed` clamp, four-sided pre-scan prediction bounds `(0,340000] x (0,460000]`, type-2 distance/cross gates, type-1 midpoint normal, first-detected candidate selection, persistent Real48 spin, and the common impulse response. The scan follows record chunks 1-5, 6, 7-88, 89, 90-128, 129-133, 134-139, 140-152, 153-154, 155-173, and dynamic 174/175 while carrying prediction separately from mutable motion. Negative auxiliary thresholds and kick coefficients are retained for bumpers 51-53 and lines 55/74/107, including weak-hit score behavior, unscored-rail WAVE 2019, and tilt suppression. Type-3 reads the pre-movement coordinate for pull/hold, obeys its prediction broadphase, and contributes its recovered radial rim candidate when a nonzero contact is outside the deep zone. Type-4 randomization mutates motion before the selected candidate is resolved and before position publication; only rectangular magnetic records rewrite prediction. Detail callbacks freeze their starting ball count, run all 5/4/3/2/1 substeps for slot 1 before slot 2, stop a slot after its first collision/reset/removal, and apply effect-seven spawn requests after the current batch. Dynamic records 174/175 use their 21-pixel prediction bounds and transfer normal impulse only when the other slot's capture age is nonpositive; successful transfer then applies `normal_velocity-1000`, while a held slot remains unchanged and leaves the moving normal velocity intact. Effect seven spawns record/slot 2 from record 148 coordinates `(17000,23000)` with exact `(0,3040)` velocity. Both slots traverse the same type-3/type-4 dispatcher. Capture age is saved per slot, contact words retain ball ownership, a completed multiball capture removes exactly that slot and promotes the survivor when needed, and effect seven's argument-2 guard prevents a third ball. The original Borland seed update, high-word `Random(n)`, and normalized Real48 random register result drive launcher variation, effects, claw terminals, magnetic fields, and trigger response. Type-4 triggers retain a shared transient entry flag; type-3 captures retain per-player 16-bit contact words, deep-inside pull/hold progression to age 300, first-contact sound, and `99`/`2` completion sentinels. Zero-spin C harnesses and retained-spin Wine probes are tested separately rather than conflated. |
|
||||
| Rules | Recovered gameplay paths | Player count, controls, the five three-line bumper-value groups, four three-line TDK-diamond groups, five doubling-value lock holes, wheel-reset target, seven-way effect selector/consumer including multiball, ball-scoped double scoring, and four exact media/extra-ball thresholds follow original help/code paths, globals, and object flags. The ninth diamond pays the original 24,464 completion value, then immediately enables double scoring and all three magnetic fields before that collision's static 1,500-point award. Further completed banks during that ball add 100,000 to the per-player secondary score. A normal ball end clears double scoring, so the first later completion re-enables it without adding 100,000; effect seven's special respawn preserves it because it bypasses `normal_ball_end`. Bumpers 51-53 and targets 140-147/150-152 use the original 5/20/10 active-callback countdowns and exact overlay-A render rectangles. Record 121 runs the six-active-callback DAT600 target rotation with exact 91x90 frames/target points and rotates the five contact/item values at state 6; it pauses while a ball waits in the launcher and survives a normal drain. Completing all five lock holes suspends physics for the full 281-callback panel animation, clears contact/item state at the recovered boundaries, and uses the exact WAVE 2013/2012/stop sequence. Effect seven retains required state through active multiball; when the last ball is lost, `1000:ae6e` grants one uncharged special respawn at `(17000,23000)/(0,3040)`, clears required state, and suppresses record 148 until a broadphase-active type-4 record clears `0x0875`. Turn changes mirror the original save/load of all 175 collision active/contact states plus wheel/top targets and selected effect. Claw contact and all initially active type-4 targets use recovered records. The top three targets score 500 each and independently enable the left, center, or right magnetic field record. Each rectangular field requires the previous position inside, applies its Real48/random pull, and deactivates when raw `1000:9b69` finds the resulting `07db/07df` prediction outside any edge. The claw state machine and release table have live differential coverage for all four random terminals. |
|
||||
| Numeric scoring | Recovered gameplay values | Static scores come from the initialized 175-object ledger. Dynamic bumper progression, target-bank completion, diamond awards, 10k-160k lock bonuses, 310k transfer, six effect values, multiball mode, and all four media thresholds are transcribed from `1000:b476`, `1000:c4e1`, `1000:bc36`, and live state probes. The central helper suppresses all mutation during Tilt, applies a 2x active-multiball factor, and then independently applies the active ball's 2x factor, allowing the original 4x stack. Lock and effect awards share the original per-player secondary score and display multiplier; the fifth hole transfers and clears it, increments the multiplier, and grants the recovered ball award. Score mutation uses the original 32-bit wrapping behavior; media markers use the binary's signed-high/unsigned-low comparison, and each add operation can advance at most one threshold. Type-4 WAVE 2004 and bumper WAVE 2006 dispatch before their score mutations, leaving a crossed marker's WAVE 2007 as the audible asynchronous sample. Rendering separately follows `1008:0996`'s eight-place 130x40 fields/right edge X=606 and `1008:0b9e`'s strict signed status thresholds; configured-player rows and 5x5 remaining-ball markers retain their exact dimensions and current/noncurrent counts. |
|
||||
|
||||
+68
-6
@@ -347,6 +347,7 @@ pub struct Game {
|
||||
player_entry: PlayerEntry,
|
||||
random: BorlandRandom,
|
||||
pending_flipper_edges: [i8; 2],
|
||||
flipper_release_latch: [bool; 2],
|
||||
record_contacts: [u16; 176],
|
||||
trigger_flags: [bool; 176],
|
||||
object_active: [bool; 176],
|
||||
@@ -390,6 +391,7 @@ impl Game {
|
||||
player_entry: PlayerEntry::Open,
|
||||
random: BorlandRandom::new(seed),
|
||||
pending_flipper_edges: [0; 2],
|
||||
flipper_release_latch: [false; 2],
|
||||
record_contacts: [0; 176],
|
||||
trigger_flags: [false; 176],
|
||||
object_active: initial_object_activity(),
|
||||
@@ -478,8 +480,22 @@ impl Game {
|
||||
self.last_collision_id = None;
|
||||
self.claw_frame_seconds = DETAIL_TIMER_SECONDS[usize::from(detail.clamp(1, 5) - 1)];
|
||||
let mut events = Vec::new();
|
||||
self.flipper_inputs.left_raised = controls.left_flipper && !self.tilted;
|
||||
self.flipper_inputs.right_raised = controls.right_flipper && !self.tilted;
|
||||
if !controls.left_flipper {
|
||||
self.flipper_release_latch[0] = false;
|
||||
} else if self.tilted {
|
||||
self.flipper_release_latch[0] = true;
|
||||
}
|
||||
if !controls.right_flipper {
|
||||
self.flipper_release_latch[1] = false;
|
||||
} else if self.tilted {
|
||||
self.flipper_release_latch[1] = true;
|
||||
}
|
||||
self.flipper_inputs.left_raised = controls.left_flipper
|
||||
&& !self.tilted
|
||||
&& !self.flipper_release_latch[0];
|
||||
self.flipper_inputs.right_raised = controls.right_flipper
|
||||
&& !self.tilted
|
||||
&& !self.flipper_release_latch[1];
|
||||
|
||||
if self.ball.in_launcher && !self.tilted {
|
||||
if controls.launch_down {
|
||||
@@ -716,6 +732,8 @@ impl Game {
|
||||
let threshold = self.random.below(10) + 30;
|
||||
if threshold < self.tilt_counter {
|
||||
self.tilted = true;
|
||||
self.flipper_release_latch[0] |= self.flipper_inputs.left_raised;
|
||||
self.flipper_release_latch[1] |= self.flipper_inputs.right_raised;
|
||||
self.flipper_inputs = Flippers::default();
|
||||
self.pending_flipper_edges.fill(0);
|
||||
events.push(Event::Tilt);
|
||||
@@ -2073,12 +2091,12 @@ impl Game {
|
||||
events.push(Event::Sound(2008));
|
||||
if let Some(score) = high_score_candidate {
|
||||
events.push(Event::HighScoreCandidate(score));
|
||||
self.flipper_release_latch[0] |= self.flipper_inputs.left_raised;
|
||||
self.flipper_release_latch[1] |= self.flipper_inputs.right_raised;
|
||||
self.flipper_inputs = Flippers::default();
|
||||
}
|
||||
self.tilted = false;
|
||||
self.tilt_counter = 0;
|
||||
self.flipper_inputs = Flippers::default();
|
||||
self.flippers = Flippers::default();
|
||||
self.pending_flipper_edges.fill(0);
|
||||
self.secondary_ball = None;
|
||||
self.score_mode = ScoreMode::Normal;
|
||||
self.launcher_charge = 0.0;
|
||||
@@ -4176,10 +4194,54 @@ mod tests {
|
||||
game.ball.position = vec2(157.0, 454.0);
|
||||
game.ball.velocity = vec2(0.0, 200.0);
|
||||
|
||||
game.update(0.030, 3, Controls::default());
|
||||
let held = Controls {
|
||||
left_flipper: true,
|
||||
..Controls::default()
|
||||
};
|
||||
game.update(0.030, 3, held);
|
||||
|
||||
assert!(!game.tilted);
|
||||
assert!(game.ball.in_launcher);
|
||||
assert!(game.flipper_release_latch[0]);
|
||||
game.update(0.0, 3, held);
|
||||
assert!(!game.flipper_inputs.left_raised);
|
||||
game.update(0.0, 3, Controls::default());
|
||||
game.update(0.0, 3, held);
|
||||
assert!(game.flipper_inputs.left_raised);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ball_end_preserves_or_releases_flippers_like_key_message_latches() {
|
||||
let mut live_player = Game::new(1);
|
||||
live_player.flipper_inputs.left_raised = true;
|
||||
live_player.flippers.left_raised = true;
|
||||
live_player.drain(&mut Vec::new());
|
||||
assert!(live_player.flipper_inputs.left_raised);
|
||||
assert!(live_player.flippers.left_raised);
|
||||
|
||||
let mut finished_player = Game::new(2);
|
||||
finished_player.players[0].balls = 1;
|
||||
finished_player.flipper_inputs.left_raised = true;
|
||||
finished_player.flippers.left_raised = true;
|
||||
finished_player.drain(&mut Vec::new());
|
||||
assert!(!finished_player.flipper_inputs.left_raised);
|
||||
assert!(finished_player.flippers.left_raised);
|
||||
assert!(finished_player.flipper_release_latch[0]);
|
||||
|
||||
let mut events = Vec::new();
|
||||
finished_player.timer_tick(0.030, 0, &mut events);
|
||||
assert!(!finished_player.flippers.left_raised);
|
||||
assert_eq!(events, [Event::FlipperMove, Event::Sound(2021)]);
|
||||
|
||||
let held = Controls {
|
||||
left_flipper: true,
|
||||
..Controls::default()
|
||||
};
|
||||
finished_player.update(0.0, 3, held);
|
||||
assert!(!finished_player.flipper_inputs.left_raised);
|
||||
finished_player.update(0.0, 3, Controls::default());
|
||||
finished_player.update(0.0, 3, held);
|
||||
assert!(finished_player.flipper_inputs.left_raised);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user