Recover and verify static collision traversal and body contracts
This commit is contained in:
1 parent
7c0d1a4b0c
commit
df0263b26e
34 files changed
+1962
-17
No files matched your search
@@ -0,0 +1,110 @@
|
||||
"""Bounded contact/friction source signatures and state boundary fixtures."""
|
||||
from pathlib import Path
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
sys.path.insert(0, str(ROOT / 'tools/binary'))
|
||||
from collision_contact_callbacks import (
|
||||
collect, normal_callback, NORMAL_Y_THRESHOLD, ceiling_projection,
|
||||
player_material_actions, jimmy_contact_actions, friction_projection, landing_phases,
|
||||
)
|
||||
|
||||
|
||||
class CollisionContactCallbacksTests(unittest.TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
cls.report = collect(ROOT.parent / 'Original')
|
||||
|
||||
def test_exact_source_identity_targets_and_complete_callbacks(self):
|
||||
self.assertEqual(len(self.report['sites']), 50)
|
||||
self.assertEqual(len(self.report['tables']), 20)
|
||||
self.assertEqual(len(self.report['bodies']), 6)
|
||||
self.assertFalse(any(b['raw_control_reference'] for b in self.report['bodies']))
|
||||
targets = {(t['owner'], t['slot']): t['target'] for t in self.report['tables']}
|
||||
self.assertEqual(targets['Jimmy', '0x374'], '0x42a660')
|
||||
self.assertEqual(targets['Object', '0x374'], '0x458890')
|
||||
self.assertEqual(targets['Jimmy', '0x37c'], '0x472970')
|
||||
|
||||
def test_ceiling_callback_dispatch_has_strict_threshold(self):
|
||||
self.assertEqual(normal_callback(NORMAL_Y_THRESHOLD), 0x370)
|
||||
self.assertEqual(normal_callback(NORMAL_Y_THRESHOLD-.00001), 0x370)
|
||||
self.assertEqual(normal_callback(NORMAL_Y_THRESHOLD+.00001), 0x374)
|
||||
|
||||
def test_ceiling_changes_only_independently_positive_y(self):
|
||||
self.assertEqual(ceiling_projection((1, 5, 3, 7), (4, -2, 6, 8)),
|
||||
((1, 0, 3, 7), (4, -2, 6, 8)))
|
||||
self.assertEqual(ceiling_projection((1, -5, 3, 7), (4, 2, 6, 8)),
|
||||
((1, -5, 3, 7), (4, 0, 6, 8)))
|
||||
self.assertEqual(ceiling_projection((1, 0, 3, 7), (4, 0, 6, 8)),
|
||||
((1, 0, 3, 7), (4, 0, 6, 8)))
|
||||
|
||||
def test_ordinary_material_is_not_generic_velocity_projection(self):
|
||||
for elapsed in (0, 3, 4):
|
||||
self.assertEqual(player_material_actions(17, elapsed, 0), ())
|
||||
self.assertEqual(player_material_actions(120, 3, 0), ())
|
||||
self.assertEqual(player_material_actions(120, 3.01, 1), ('complete160',))
|
||||
self.assertEqual(player_material_actions(119, 4, 1), ('complete164',))
|
||||
self.assertEqual(player_material_actions(60, 4, 0), ('fence_query',))
|
||||
self.assertEqual(player_material_actions(69, 4, 1), ())
|
||||
self.assertEqual(player_material_actions(180, 4, 0), ('ladder_query',))
|
||||
for material in (-1, 59, 70, 109, 130, 179, 181):
|
||||
self.assertEqual(player_material_actions(material, 4, 0), ())
|
||||
|
||||
def test_friction_is_gated_by_support_published_speed_and_linear_motion(self):
|
||||
velocity, angular = (10, -5, 20, 7), (2, -4, 6, 8)
|
||||
self.assertEqual(friction_projection(velocity, angular, .8, .25),
|
||||
((8, -5, 16, 7), (1.6, -3.2, 4.8, 8)))
|
||||
for options in ({'support': False}, {'published_speed': 2}, {'published_speed': -2}):
|
||||
self.assertEqual(friction_projection(velocity, angular, .8, .25, **options),
|
||||
(velocity, angular))
|
||||
# No planar motion still damps angular velocity when vertical motion exists.
|
||||
self.assertEqual(friction_projection((0, 5, 0), (2, 4, 6), .8, .25),
|
||||
((0, 5, 0), (1.6, 3.2, 4.8)))
|
||||
self.assertEqual(friction_projection((0, 0, 0), angular, .8, .25),
|
||||
((0, 0, 0), angular))
|
||||
# The source multiplier is not clamped to prevent reversal.
|
||||
self.assertEqual(friction_projection((10, 5, 20), (2, 4, 6), 2, 1),
|
||||
((-10, 5, -20), (-2, -4, -6)))
|
||||
|
||||
def test_no_selection_and_jetpack_bypass_extra_gadget_effects(self):
|
||||
for selected in (-1, 3):
|
||||
for mode in (0, 1):
|
||||
self.assertEqual(jimmy_contact_actions(selected, 17, 4, mode), ())
|
||||
self.assertEqual(jimmy_contact_actions(selected, 17, 4, mode,
|
||||
gadget7_active=True), ())
|
||||
self.assertEqual(jimmy_contact_actions(7, 17, 4, 0), ())
|
||||
self.assertEqual(jimmy_contact_actions(7, 17, 4, 0, gadget7_active=True),
|
||||
('gadget7_unresolved',))
|
||||
|
||||
def test_material_discriminator_is_linked_chunk_id_and_route_has_specials(self):
|
||||
identity = self.report['material_identity']
|
||||
self.assertEqual(len(identity['dll_sites']), 11)
|
||||
expected = {
|
||||
'level1b.omt': {61: 20, 62: 24, 63: 4, 120: 4, 121: 20, 122: 3, 180: 6},
|
||||
'VR04.omt': {},
|
||||
'level1.omt': {60: 62, 61: 38, 62: 26, 180: 20},
|
||||
}
|
||||
for archive in identity['archives']:
|
||||
# Every used material payload has the same trailing value; the
|
||||
# distinct source callback policy comes from its linked chunk ID.
|
||||
self.assertEqual({m['payload_trailing'] for m in archive['materials']}, {3})
|
||||
counts = {}
|
||||
for polygon in archive['special_polygons']:
|
||||
if polygon['potential374_wall']:
|
||||
mid = polygon['material_id']
|
||||
counts[mid] = counts.get(mid, 0) + 1
|
||||
self.assertEqual(counts, expected[archive['name']])
|
||||
material = next(m for m in archive['materials'] if m['id'] == 0)
|
||||
self.assertNotEqual(material['table_id_offset'], material['payload_offset'])
|
||||
|
||||
def test_landing_callback_observes_old_velocity_and_support(self):
|
||||
phases = landing_phases(False)
|
||||
self.assertEqual(phases, ['root318', 'acceleration278_Y0',
|
||||
'landing37C_noop_for_Jimmy', 'velocity2C4_Y0',
|
||||
'support21C_true', 'shape34C', 'polygon33C'])
|
||||
self.assertNotIn('landing37C_noop_for_Jimmy', landing_phases(True))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user