fix(physics): process sensors before collision response
Evaluate type-three captures from the pre-movement position, retain their missing radial rim candidates, and run type-four motion randomization before candidate resolution and position publication. Sensor groups now execute in binary ID order without Hold or Complete prematurely aborting later records. Test Plan: - cargo test --all-targets - cargo clippy --all-targets --all-features -- -D warnings - rumdl check CHANGELOG.md RECONSTRUCTION.md README.md - git diff --check
This commit is contained in:
@@ -10,6 +10,10 @@ and this project adheres to
|
||||
|
||||
### Fixed
|
||||
|
||||
- Run type-3/type-4 processing before response and position publication:
|
||||
captures now test the old position, contacted type-3 rims contribute radial
|
||||
candidates, triggers mutate the live motion first, and sensor IDs execute in
|
||||
binary order without Hold/Complete prematurely ending the record scan.
|
||||
- Apply the collision table's predicted-position broadphase bounds before
|
||||
type-1/type-2 detection, including the registered five-pixel ball margin,
|
||||
and retain unresolved candidates until the selected response phase.
|
||||
|
||||
@@ -24,7 +24,7 @@ implementation.
|
||||
| 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. 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. |
|
||||
| Physics arithmetic | Recovered Real48 core | Production movement uses the original 10 ms millipixel substep, `+15` vertical acceleration, Real48 `3800/speed` clamp, type-2 distance/cross gates, type-1 midpoint normal, surface-distance candidate ordering, persistent Real48 spin, and the common impulse response. 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. 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 transfer normal impulse to the other ball before applying `normal_velocity-1000` to the moving ball; 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. |
|
||||
| Physics arithmetic | Recovered Real48 core | Production movement uses the original 10 ms millipixel substep, `+15` vertical acceleration, Real48 `3800/speed` clamp, type-2 distance/cross gates, type-1 midpoint normal, surface-distance candidate ordering, persistent Real48 spin, and the common impulse response. 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 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; sensor groups execute in record order 89, 129-133, 140-152 without Hold/Complete aborting later records. 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 transfer normal impulse to the other ball before applying `normal_velocity-1000` to the moving ball; 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, permanent 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; the following completed bank enables double scoring, and later completions add 100,000 to the per-player secondary score. 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-callback DAT600 target rotation with exact 91x90 frames/target points and rotates the five contact/item values at state 6. 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. Turn changes mirror the original save/load of all 175 collision record states: wheel/top targets, active/contact slots, selected effect, and multiball readiness remain attached to their player. 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. 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, and each add operation can advance at most one media threshold. |
|
||||
| High scores | Recovered visible flow; portable storage | The original 276-byte table is decoded as ten `IWIK`-XOR-obfuscated little-endian scores plus ten 22-byte names. Each player is checked immediately when their own last ball is lost; qualifying scores use the original signed-high/unsigned-low comparison and a `TDK Pinball Player`-prefilled name screen before the table is shown and play resumes. Persisted updates use portable JSON rather than rewriting the Win16 file. |
|
||||
|
||||
+265
-71
@@ -5,8 +5,8 @@ use crate::{
|
||||
original_physics::{
|
||||
CollisionMaterial, CollisionResponse, GRAVITY_MILLI_PER_STEP,
|
||||
MAXIMUM_SPEED_MILLI_PER_STEP, MilliVec, STEP_SECONDS, StaticCollisionCandidate,
|
||||
ball_collision_response, circle_collision_candidate, line_collision_candidate,
|
||||
milli_distance, path_intersects_circle,
|
||||
ball_collision_response, capture_collision_candidate, circle_collision_candidate,
|
||||
line_collision_candidate, milli_distance, path_intersects_circle,
|
||||
},
|
||||
real48::Real48,
|
||||
table::{
|
||||
@@ -222,6 +222,12 @@ enum BallAction {
|
||||
Remove,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
struct SensorScanResult {
|
||||
action: BallAction,
|
||||
capture_candidate: Option<(u8, StaticCollisionCandidate)>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
struct RuleState {
|
||||
wheel_holes: [bool; 5],
|
||||
@@ -667,22 +673,40 @@ impl Game {
|
||||
}
|
||||
|
||||
let old_position = MilliVec::from_position(self.ball.position);
|
||||
let mut velocity = MilliVec::from_velocity_per_second(self.ball.velocity);
|
||||
let initial_secondary = self.secondary_ball;
|
||||
let ball_count = if initial_secondary.is_some() { 2 } else { 1 };
|
||||
let mut ball = self.ball;
|
||||
let mut velocity = MilliVec::from_velocity_per_second(ball.velocity);
|
||||
velocity.y += GRAVITY_MILLI_PER_STEP;
|
||||
velocity.clamp_speed(MAXIMUM_SPEED_MILLI_PER_STEP);
|
||||
self.apply_magnetic_fields(old_position, &mut velocity);
|
||||
let movement_velocity = velocity;
|
||||
let mut position = old_position.add(velocity);
|
||||
let best_static = self.find_static_collision_candidate(old_position, velocity);
|
||||
let mut best_collision = best_static.map(|(id, is_wall, candidate)| {
|
||||
(id, is_wall, candidate.resolve(velocity, self.ball.spin))
|
||||
});
|
||||
let mut best_static = self.find_static_collision_candidate(old_position, velocity);
|
||||
ball.velocity = velocity.to_velocity_per_second();
|
||||
let scan = self.check_sensor_objects_for_ball(
|
||||
&mut ball,
|
||||
1,
|
||||
ball_count,
|
||||
old_position,
|
||||
movement_velocity,
|
||||
events,
|
||||
);
|
||||
if let Some((id, candidate)) = scan.capture_candidate
|
||||
&& best_static.is_none_or(|(_, _, closest)| {
|
||||
candidate.surface_distance <= closest.surface_distance
|
||||
})
|
||||
{
|
||||
best_static = Some((id, false, candidate));
|
||||
}
|
||||
velocity = MilliVec::from_velocity_per_second(ball.velocity);
|
||||
let mut best_collision = best_static
|
||||
.map(|(id, is_wall, candidate)| (id, is_wall, candidate.resolve(velocity, ball.spin)));
|
||||
let mut transferred_secondary_velocity = None;
|
||||
if let Some(secondary) = self.secondary_ball {
|
||||
if let Some(secondary) = initial_secondary {
|
||||
let response = ball_collision_response(
|
||||
old_position,
|
||||
velocity,
|
||||
self.ball.spin,
|
||||
ball.spin,
|
||||
MilliVec::from_position(secondary.position),
|
||||
MilliVec::from_velocity_per_second(secondary.velocity),
|
||||
);
|
||||
@@ -708,10 +732,9 @@ impl Game {
|
||||
let mut auxiliary_fired = false;
|
||||
let (hit_wall, hit_circle) = if let Some((object_id, is_wall, response)) = best_collision {
|
||||
velocity = response.velocity;
|
||||
self.ball.spin = response.spin;
|
||||
ball.spin = response.spin;
|
||||
auxiliary_fired = response.auxiliary_fired;
|
||||
velocity.clamp_speed(MAXIMUM_SPEED_MILLI_PER_STEP);
|
||||
position = old_position.add(velocity);
|
||||
self.last_collision_id = Some(object_id);
|
||||
if object_id == 175
|
||||
&& let (Some(secondary), Some(transferred)) =
|
||||
@@ -727,8 +750,10 @@ impl Game {
|
||||
} else {
|
||||
(None, None)
|
||||
};
|
||||
self.ball.position = position.to_position();
|
||||
self.ball.velocity = velocity.to_velocity_per_second();
|
||||
velocity.clamp_speed(MAXIMUM_SPEED_MILLI_PER_STEP);
|
||||
ball.position = old_position.add(velocity).to_position();
|
||||
ball.velocity = velocity.to_velocity_per_second();
|
||||
self.ball = ball;
|
||||
|
||||
if let Some(wall_id) = hit_wall {
|
||||
if wall_id == 2 {
|
||||
@@ -765,8 +790,20 @@ impl Game {
|
||||
events.push(Event::Sound(2006));
|
||||
}
|
||||
|
||||
if self.check_sensor_objects(old_position, movement_velocity, events) != BallAction::Keep {
|
||||
return true;
|
||||
match scan.action {
|
||||
BallAction::Keep => {}
|
||||
BallAction::Suspend => return true,
|
||||
BallAction::Reset => {
|
||||
self.reset_ball_to_launcher();
|
||||
return true;
|
||||
}
|
||||
BallAction::Remove => {
|
||||
self.ball = self
|
||||
.secondary_ball
|
||||
.take()
|
||||
.expect("a multiball capture must leave the other slot active");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if self.ball.position.y > 470.0 {
|
||||
@@ -877,6 +914,7 @@ impl Game {
|
||||
self.advance_secondary_ball_slot(events, true)
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_lines)]
|
||||
fn advance_secondary_ball_slot(
|
||||
&mut self,
|
||||
events: &mut Vec<Event>,
|
||||
@@ -885,16 +923,34 @@ impl Game {
|
||||
let Some(mut ball) = self.secondary_ball.take() else {
|
||||
return true;
|
||||
};
|
||||
let primary_position = self.ball.position;
|
||||
let primary_velocity = self.ball.velocity;
|
||||
let old_position = MilliVec::from_position(ball.position);
|
||||
let mut velocity = MilliVec::from_velocity_per_second(ball.velocity);
|
||||
velocity.y += GRAVITY_MILLI_PER_STEP;
|
||||
velocity.clamp_speed(MAXIMUM_SPEED_MILLI_PER_STEP);
|
||||
self.apply_magnetic_fields(old_position, &mut velocity);
|
||||
let movement_velocity = velocity;
|
||||
let best_static = self.find_static_collision_candidate(old_position, velocity);
|
||||
let mut best_collision = best_static.map(|(id, is_wall, candidate)| {
|
||||
(id, is_wall, candidate.resolve(velocity, ball.spin))
|
||||
});
|
||||
let mut best_static = self.find_static_collision_candidate(old_position, velocity);
|
||||
ball.velocity = velocity.to_velocity_per_second();
|
||||
let scan = self.check_sensor_objects_for_ball(
|
||||
&mut ball,
|
||||
2,
|
||||
2,
|
||||
old_position,
|
||||
movement_velocity,
|
||||
events,
|
||||
);
|
||||
if let Some((id, candidate)) = scan.capture_candidate
|
||||
&& best_static.is_none_or(|(_, _, closest)| {
|
||||
candidate.surface_distance <= closest.surface_distance
|
||||
})
|
||||
{
|
||||
best_static = Some((id, false, candidate));
|
||||
}
|
||||
velocity = MilliVec::from_velocity_per_second(ball.velocity);
|
||||
let mut best_collision = best_static
|
||||
.map(|(id, is_wall, candidate)| (id, is_wall, candidate.resolve(velocity, ball.spin)));
|
||||
|
||||
let mut transferred_primary_velocity = None;
|
||||
if primary_slot_active
|
||||
@@ -902,8 +958,8 @@ impl Game {
|
||||
old_position,
|
||||
velocity,
|
||||
ball.spin,
|
||||
MilliVec::from_position(self.ball.position),
|
||||
MilliVec::from_velocity_per_second(self.ball.velocity),
|
||||
MilliVec::from_position(primary_position),
|
||||
MilliVec::from_velocity_per_second(primary_velocity),
|
||||
)
|
||||
&& best_collision.is_none_or(|(_, _, closest)| {
|
||||
response.surface_distance <= closest.surface_distance
|
||||
@@ -936,6 +992,7 @@ impl Game {
|
||||
self.ball.velocity = transferred.to_velocity_per_second();
|
||||
}
|
||||
}
|
||||
velocity.clamp_speed(MAXIMUM_SPEED_MILLI_PER_STEP);
|
||||
ball.position = old_position.add(velocity).to_position();
|
||||
ball.velocity = velocity.to_velocity_per_second();
|
||||
if hit == Some((2, true)) || ball.position.y > 470.0 {
|
||||
@@ -962,19 +1019,11 @@ impl Game {
|
||||
events.push(Event::Bumper);
|
||||
events.push(Event::Sound(2006));
|
||||
}
|
||||
let action = self.check_sensor_objects_for_ball(
|
||||
&mut ball,
|
||||
2,
|
||||
2,
|
||||
old_position,
|
||||
movement_velocity,
|
||||
events,
|
||||
);
|
||||
match action {
|
||||
match scan.action {
|
||||
BallAction::Keep | BallAction::Suspend => self.secondary_ball = Some(ball),
|
||||
BallAction::Reset | BallAction::Remove => return true,
|
||||
}
|
||||
collided || action == BallAction::Suspend
|
||||
collided || scan.action == BallAction::Suspend
|
||||
}
|
||||
|
||||
fn apply_wall_rule(&mut self, object_id: u8, events: &mut Vec<Event>) {
|
||||
@@ -1074,6 +1123,7 @@ impl Game {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
fn check_sensor_objects(
|
||||
&mut self,
|
||||
old_position: MilliVec,
|
||||
@@ -1082,7 +1132,7 @@ impl Game {
|
||||
) -> BallAction {
|
||||
let ball_count = if self.secondary_ball.is_some() { 2 } else { 1 };
|
||||
let mut ball = self.ball;
|
||||
let action = self.check_sensor_objects_for_ball(
|
||||
let scan = self.check_sensor_objects_for_ball(
|
||||
&mut ball,
|
||||
1,
|
||||
ball_count,
|
||||
@@ -1090,7 +1140,7 @@ impl Game {
|
||||
movement_velocity,
|
||||
events,
|
||||
);
|
||||
match action {
|
||||
match scan.action {
|
||||
BallAction::Keep | BallAction::Suspend => self.ball = ball,
|
||||
BallAction::Reset => self.reset_ball_to_launcher(),
|
||||
BallAction::Remove => {
|
||||
@@ -1100,7 +1150,7 @@ impl Game {
|
||||
.expect("a multiball capture must leave the other slot active");
|
||||
}
|
||||
}
|
||||
action
|
||||
scan.action
|
||||
}
|
||||
|
||||
fn check_sensor_objects_for_ball(
|
||||
@@ -1111,9 +1161,14 @@ impl Game {
|
||||
old_position: MilliVec,
|
||||
movement_velocity: MilliVec,
|
||||
events: &mut Vec<Event>,
|
||||
) -> BallAction {
|
||||
) -> SensorScanResult {
|
||||
let mut capture_candidate = None;
|
||||
let mut action = BallAction::Keep;
|
||||
if old_position.y >= 250_000 {
|
||||
return BallAction::Keep;
|
||||
return SensorScanResult {
|
||||
action: BallAction::Keep,
|
||||
capture_candidate,
|
||||
};
|
||||
}
|
||||
if !self.claw.active {
|
||||
match self.capture_record_step(
|
||||
@@ -1124,30 +1179,52 @@ impl Game {
|
||||
CLAW_TRIGGER_CENTER,
|
||||
CLAW_TRIGGER_RADIUS,
|
||||
old_position,
|
||||
&mut capture_candidate,
|
||||
events,
|
||||
) {
|
||||
CaptureStep::Holding => return BallAction::Keep,
|
||||
CaptureStep::Holding | CaptureStep::Outside => {}
|
||||
CaptureStep::Complete => {
|
||||
if ball_count == 1 {
|
||||
let terminal_frame = self.next_claw_terminal_frame();
|
||||
self.begin_claw_capture_after_hold(ball, terminal_frame, events);
|
||||
return BallAction::Suspend;
|
||||
action = BallAction::Suspend;
|
||||
} else {
|
||||
action = BallAction::Remove;
|
||||
}
|
||||
return BallAction::Remove;
|
||||
}
|
||||
CaptureStep::Outside => {}
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(action) =
|
||||
self.check_lock_holes(ball, ball_number, ball_count, old_position, events)
|
||||
if let Some(completed_action) =
|
||||
self.check_lock_holes(
|
||||
ball,
|
||||
ball_number,
|
||||
ball_count,
|
||||
old_position,
|
||||
&mut capture_candidate,
|
||||
events,
|
||||
)
|
||||
{
|
||||
return action;
|
||||
action = completed_action;
|
||||
}
|
||||
if let Some(action) =
|
||||
self.check_wheel_reset(ball, ball_number, ball_count, old_position, events)
|
||||
self.check_target_sensors(
|
||||
ball,
|
||||
old_position,
|
||||
movement_velocity,
|
||||
140..=147,
|
||||
events,
|
||||
);
|
||||
if let Some(completed_action) =
|
||||
self.check_wheel_reset(
|
||||
ball,
|
||||
ball_number,
|
||||
ball_count,
|
||||
old_position,
|
||||
&mut capture_candidate,
|
||||
events,
|
||||
)
|
||||
{
|
||||
return action;
|
||||
action = completed_action;
|
||||
}
|
||||
self.check_effect_sensor(
|
||||
ball,
|
||||
@@ -1156,8 +1233,17 @@ impl Game {
|
||||
movement_velocity,
|
||||
events,
|
||||
);
|
||||
self.check_target_sensors(ball, old_position, movement_velocity, events);
|
||||
BallAction::Keep
|
||||
self.check_target_sensors(
|
||||
ball,
|
||||
old_position,
|
||||
movement_velocity,
|
||||
150..=152,
|
||||
events,
|
||||
);
|
||||
SensorScanResult {
|
||||
action,
|
||||
capture_candidate,
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::cast_possible_truncation, clippy::too_many_arguments)]
|
||||
@@ -1170,11 +1256,14 @@ impl Game {
|
||||
center: Vec2,
|
||||
radius: f32,
|
||||
previous_position: MilliVec,
|
||||
best_capture: &mut Option<(u8, StaticCollisionCandidate)>,
|
||||
events: &mut Vec<Event>,
|
||||
) -> CaptureStep {
|
||||
let current_position = MilliVec::from_position(ball.position);
|
||||
let center = MilliVec::from_position(center);
|
||||
let radius = (radius * 1_000.0).round() as i32;
|
||||
let center_view = center;
|
||||
let center = MilliVec::from_position(center_view);
|
||||
let radius_view = radius;
|
||||
let radius = (radius_view * 1_000.0).round() as i32;
|
||||
let dx = center.x.wrapping_sub(current_position.x);
|
||||
let dy = center
|
||||
.y
|
||||
@@ -1240,6 +1329,23 @@ impl Game {
|
||||
self.record_contacts[contact_index] = 0;
|
||||
ball.capture_age = 0;
|
||||
}
|
||||
let velocity = MilliVec::from_velocity_per_second(ball.velocity);
|
||||
if surface_distance <= milli_distance(velocity)
|
||||
&& surface_distance >= -11_000
|
||||
&& contact != 0
|
||||
&& let Some(candidate) = capture_collision_candidate(
|
||||
current_position,
|
||||
velocity,
|
||||
center_view,
|
||||
radius_view,
|
||||
CollisionMaterial::line(0.6, 0.0),
|
||||
)
|
||||
&& best_capture.is_none_or(|(_, closest)| {
|
||||
candidate.surface_distance <= closest.surface_distance
|
||||
})
|
||||
{
|
||||
*best_capture = Some((record_id, candidate));
|
||||
}
|
||||
CaptureStep::Outside
|
||||
}
|
||||
|
||||
@@ -1249,6 +1355,7 @@ impl Game {
|
||||
ball_number: u16,
|
||||
ball_count: u16,
|
||||
old_position: MilliVec,
|
||||
best_capture: &mut Option<(u8, StaticCollisionCandidate)>,
|
||||
events: &mut Vec<Event>,
|
||||
) -> Option<BallAction> {
|
||||
for (index, sensor) in LOCK_HOLES.into_iter().enumerate() {
|
||||
@@ -1260,10 +1367,10 @@ impl Game {
|
||||
sensor.center,
|
||||
sensor.radius,
|
||||
old_position,
|
||||
best_capture,
|
||||
events,
|
||||
) {
|
||||
CaptureStep::Outside => continue,
|
||||
CaptureStep::Holding => return Some(BallAction::Keep),
|
||||
CaptureStep::Outside | CaptureStep::Holding => continue,
|
||||
CaptureStep::Complete => {}
|
||||
}
|
||||
let filled_before = self.wheel_holes.iter().filter(|filled| **filled).count();
|
||||
@@ -1296,6 +1403,7 @@ impl Game {
|
||||
ball_number: u16,
|
||||
ball_count: u16,
|
||||
old_position: MilliVec,
|
||||
best_capture: &mut Option<(u8, StaticCollisionCandidate)>,
|
||||
events: &mut Vec<Event>,
|
||||
) -> Option<BallAction> {
|
||||
match self.capture_record_step(
|
||||
@@ -1306,10 +1414,10 @@ impl Game {
|
||||
WHEEL_RESET_SENSOR.center,
|
||||
WHEEL_RESET_SENSOR.radius,
|
||||
old_position,
|
||||
best_capture,
|
||||
events,
|
||||
) {
|
||||
CaptureStep::Outside => return None,
|
||||
CaptureStep::Holding => return Some(BallAction::Keep),
|
||||
CaptureStep::Outside | CaptureStep::Holding => return None,
|
||||
CaptureStep::Complete => {}
|
||||
}
|
||||
self.wheel_holes.fill(false);
|
||||
@@ -1333,7 +1441,6 @@ impl Game {
|
||||
if self.tilted {
|
||||
return;
|
||||
}
|
||||
let current_position = MilliVec::from_position(ball.position);
|
||||
let effect_index = usize::from(EFFECT_SENSOR.id);
|
||||
if self.object_active[effect_index] {
|
||||
let touched = path_intersects_circle(
|
||||
@@ -1343,12 +1450,7 @@ impl Game {
|
||||
EFFECT_SENSOR.radius,
|
||||
);
|
||||
let entered = touched && !self.trigger_flags[effect_index];
|
||||
self.trigger_flags[effect_index] = path_intersects_circle(
|
||||
current_position,
|
||||
MilliVec::default(),
|
||||
EFFECT_SENSOR.center,
|
||||
EFFECT_SENSOR.radius,
|
||||
);
|
||||
self.trigger_flags[effect_index] = touched;
|
||||
if entered {
|
||||
self.add_score(EFFECT_SENSOR.score, events);
|
||||
match self.target_effect {
|
||||
@@ -1389,13 +1491,16 @@ impl Game {
|
||||
ball: &mut Ball,
|
||||
old_position: MilliVec,
|
||||
movement_velocity: MilliVec,
|
||||
record_ids: std::ops::RangeInclusive<u8>,
|
||||
events: &mut Vec<Event>,
|
||||
) {
|
||||
if self.tilted {
|
||||
return;
|
||||
}
|
||||
let current_position = MilliVec::from_position(ball.position);
|
||||
for sensor in TARGET_SENSORS {
|
||||
if !record_ids.contains(&sensor.id) {
|
||||
continue;
|
||||
}
|
||||
let touched = path_intersects_circle(
|
||||
old_position,
|
||||
movement_velocity,
|
||||
@@ -1404,12 +1509,7 @@ impl Game {
|
||||
);
|
||||
let contact_index = usize::from(sensor.id);
|
||||
let entered = touched && !self.trigger_flags[contact_index];
|
||||
self.trigger_flags[contact_index] = path_intersects_circle(
|
||||
current_position,
|
||||
MilliVec::default(),
|
||||
sensor.center,
|
||||
sensor.radius,
|
||||
);
|
||||
self.trigger_flags[contact_index] = touched;
|
||||
if !entered {
|
||||
continue;
|
||||
}
|
||||
@@ -1781,6 +1881,7 @@ mod tests {
|
||||
events: &mut Vec<Event>,
|
||||
) -> CaptureStep {
|
||||
let mut ball = game.ball;
|
||||
let mut capture_candidate = None;
|
||||
let result = game.capture_record_step(
|
||||
&mut ball,
|
||||
1,
|
||||
@@ -1789,6 +1890,7 @@ mod tests {
|
||||
center,
|
||||
radius,
|
||||
previous_position,
|
||||
&mut capture_candidate,
|
||||
events,
|
||||
);
|
||||
game.ball = ball;
|
||||
@@ -2215,7 +2317,8 @@ mod tests {
|
||||
old_position,
|
||||
movement,
|
||||
&mut events,
|
||||
),
|
||||
)
|
||||
.action,
|
||||
BallAction::Keep
|
||||
);
|
||||
|
||||
@@ -2249,7 +2352,8 @@ mod tests {
|
||||
MilliVec::from_position(EFFECT_SENSOR.center),
|
||||
MilliVec::default(),
|
||||
&mut events,
|
||||
),
|
||||
)
|
||||
.action,
|
||||
BallAction::Keep
|
||||
);
|
||||
|
||||
@@ -3108,6 +3212,96 @@ mod tests {
|
||||
assert_eq!(game.ball.capture_age, 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn production_type_three_pull_tests_the_pre_movement_position() {
|
||||
let sensor = LOCK_HOLES[0];
|
||||
let mut game = Game::new(1);
|
||||
game.object_active.fill(false);
|
||||
game.object_active[usize::from(sensor.id)] = true;
|
||||
game.ball.in_launcher = false;
|
||||
game.ball.position = sensor.center + vec2(7.5, 0.0);
|
||||
game.ball.velocity = MilliVec { x: 3_800, y: 0 }.to_velocity_per_second();
|
||||
let old_position = MilliVec::from_position(game.ball.position);
|
||||
let mut expected_velocity = MilliVec { x: 3_800, y: 15 };
|
||||
expected_velocity.clamp_speed(MAXIMUM_SPEED_MILLI_PER_STEP);
|
||||
let damping = Real48::from_bytes([0x80, 0x66, 0x66, 0x66, 0x66, 0x66]);
|
||||
expected_velocity.x = Real48::from_i32(expected_velocity.x)
|
||||
.multiply(damping)
|
||||
.round_i32()
|
||||
.wrapping_sub(150);
|
||||
expected_velocity.y = Real48::from_i32(expected_velocity.y)
|
||||
.multiply(damping)
|
||||
.round_i32()
|
||||
.wrapping_sub(150);
|
||||
|
||||
assert!(!game.fixed_update(STEP_SECONDS, &mut Vec::new()));
|
||||
|
||||
assert_eq!(
|
||||
MilliVec::from_velocity_per_second(game.ball.velocity),
|
||||
expected_velocity
|
||||
);
|
||||
assert_eq!(
|
||||
MilliVec::from_position(game.ball.position),
|
||||
old_position.add(expected_velocity)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn production_type_three_contacted_rim_participates_in_candidate_ordering() {
|
||||
let sensor = LOCK_HOLES[0];
|
||||
let mut game = Game::new(1);
|
||||
game.object_active.fill(false);
|
||||
game.object_active[usize::from(sensor.id)] = true;
|
||||
game.record_contacts[usize::from(sensor.id)] = 99;
|
||||
game.ball.in_launcher = false;
|
||||
game.ball.position = sensor.center + vec2(17.0, 0.0);
|
||||
game.ball.velocity = MilliVec { x: -3_000, y: 0 }.to_velocity_per_second();
|
||||
let old_position = MilliVec::from_position(game.ball.position);
|
||||
|
||||
assert!(game.fixed_update(STEP_SECONDS, &mut Vec::new()));
|
||||
|
||||
let velocity = MilliVec::from_velocity_per_second(game.ball.velocity);
|
||||
assert!(velocity.x > 0, "the type-three rim must reflect the ball");
|
||||
assert_eq!(game.last_collision_id, Some(sensor.id));
|
||||
assert_eq!(
|
||||
MilliVec::from_position(game.ball.position),
|
||||
old_position.add(velocity)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn production_type_four_randomizes_motion_before_position_publication() {
|
||||
let sensor = TARGET_SENSORS
|
||||
.into_iter()
|
||||
.find(|sensor| sensor.id == 150)
|
||||
.expect("record 150 must be present");
|
||||
let mut game = Game::new_with_seed(1, 7);
|
||||
game.object_active.fill(false);
|
||||
game.object_active[usize::from(sensor.id)] = true;
|
||||
game.ball.in_launcher = false;
|
||||
game.ball.position = vec2(205.0, 58.0);
|
||||
game.ball.velocity = MilliVec { x: 0, y: -2_000 }.to_velocity_per_second();
|
||||
let old_position = MilliVec::from_position(game.ball.position);
|
||||
let mut expected_game = game.clone();
|
||||
let mut expected_ball = game.ball;
|
||||
expected_ball.velocity = MilliVec { x: 0, y: -1_985 }.to_velocity_per_second();
|
||||
expected_game.randomize_trigger_velocity(&mut expected_ball);
|
||||
let expected_velocity = MilliVec::from_velocity_per_second(expected_ball.velocity);
|
||||
|
||||
game.fixed_update(STEP_SECONDS, &mut Vec::new());
|
||||
|
||||
assert_eq!(game.player().score, 500);
|
||||
assert_eq!(
|
||||
MilliVec::from_velocity_per_second(game.ball.velocity),
|
||||
expected_velocity
|
||||
);
|
||||
assert_eq!(
|
||||
MilliVec::from_position(game.ball.position),
|
||||
old_position.add(expected_velocity)
|
||||
);
|
||||
assert_eq!(game.random.seed(), expected_game.random.seed());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn panel_completion_uses_all_281_frames_and_original_sound_boundaries() {
|
||||
let mut game = Game::new(1);
|
||||
|
||||
@@ -452,6 +452,48 @@ pub fn circle_collision_candidate(
|
||||
})
|
||||
}
|
||||
|
||||
/// Detect the non-capture boundary response of a type-3 record.
|
||||
pub fn capture_collision_candidate(
|
||||
old_position: MilliVec,
|
||||
velocity: MilliVec,
|
||||
center: Vec2,
|
||||
radius: f32,
|
||||
material: CollisionMaterial,
|
||||
) -> Option<StaticCollisionCandidate> {
|
||||
let center = MilliVec::from_position(center);
|
||||
let radius_milli = (radius * 1_000.0).round() as i32;
|
||||
let delta = MilliVec {
|
||||
x: center.x.wrapping_sub(old_position.x),
|
||||
y: center
|
||||
.y
|
||||
.wrapping_sub(old_position.y)
|
||||
.wrapping_sub(2_000),
|
||||
};
|
||||
let surface_distance = milli_distance(delta).wrapping_sub(radius_milli);
|
||||
let normal_x = Real48::from_i32(center.y.wrapping_sub(old_position.y));
|
||||
let normal_y = Real48::from_i32(old_position.x.wrapping_sub(center.x));
|
||||
let length = milli_distance(MilliVec {
|
||||
x: normal_x.round_i32(),
|
||||
y: normal_y.round_i32(),
|
||||
});
|
||||
if length == 0 {
|
||||
return None;
|
||||
}
|
||||
let normal_velocity = normal_velocity(velocity, normal_x, normal_y, length);
|
||||
if normal_velocity >= 0
|
||||
|| normal_velocity.wrapping_abs() < surface_distance.wrapping_abs()
|
||||
{
|
||||
return None;
|
||||
}
|
||||
Some(StaticCollisionCandidate {
|
||||
surface_distance,
|
||||
normal_x,
|
||||
normal_y,
|
||||
normal_velocity,
|
||||
material,
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub fn circle_collision_response(
|
||||
old_position: MilliVec,
|
||||
@@ -622,6 +664,27 @@ mod tests {
|
||||
assert_eq!(response.surface_distance, 2_000);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn type_three_boundary_builds_the_recovered_radial_candidate() {
|
||||
let candidate = capture_collision_candidate(
|
||||
MilliVec {
|
||||
x: 100_000,
|
||||
y: 100_000,
|
||||
},
|
||||
MilliVec { x: 1_000, y: 0 },
|
||||
vec2(103.0, 102.0),
|
||||
3.8,
|
||||
CollisionMaterial::line(0.6, 0.0),
|
||||
)
|
||||
.expect("the contacted type-three rim must retain a candidate");
|
||||
|
||||
assert_eq!(candidate.surface_distance, -800);
|
||||
assert_ne!(
|
||||
candidate.resolve(MilliVec { x: 1_000, y: 0 }, Real48::ZERO).velocity,
|
||||
MilliVec { x: 1_000, y: 0 }
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn auxiliary_kick_uses_the_recovered_negative_speed_threshold() {
|
||||
let material = CollisionMaterial::line_with_kick(0.5, 0.1, -0.4, 0.4);
|
||||
|
||||
Reference in New Issue
Block a user