61 lines
3.1 KiB
Python
61 lines
3.1 KiB
Python
"""Shared-eye source anchors and phase-specific DEFAULT/follow boundaries."""
|
|
from pathlib import Path
|
|
import struct
|
|
import sys
|
|
import unittest
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
sys.path.insert(0, str(ROOT / 'tools/binary'))
|
|
from camera_handoff import CameraProjection, collect, default_handoff, normal_follow
|
|
|
|
|
|
class CameraHandoffTests(unittest.TestCase):
|
|
@classmethod
|
|
def setUpClass(cls):
|
|
cls.report = collect(ROOT.parent / 'Original')
|
|
|
|
def test_original_shared_storage_and_callback_targets(self):
|
|
sites = {s['name']: s for s in self.report['sites']}
|
|
self.assertEqual(sites['walking_previous_x']['bytes'], 'd94044d99d14070000')
|
|
self.assertEqual(sites['airborne_previous_x']['bytes'], 'd94044d95c243c')
|
|
self.assertEqual(self.report['threshold']['value'], 1000)
|
|
targets = {t['name']: t['target'] for t in self.report['tables']}
|
|
self.assertEqual(targets['Jimmy walking input/follow'], '0x438bc0')
|
|
self.assertEqual(targets['Jimmy airborne input/follow'], '0x439900')
|
|
|
|
def test_default_below_equal_above_and_already_owned(self):
|
|
threshold_bits, = struct.unpack('<I', struct.pack('<f', 1000))
|
|
for offset, snapped in ((-1, False), (0, False), (1, True)):
|
|
distance, = struct.unpack('<f', struct.pack('<I', threshold_bits+offset))
|
|
view = CameraProjection((distance, 0, 0), (1, 2, 3))
|
|
result = default_handoff(view, (0, 0, 0), False)
|
|
self.assertEqual(result.eye, (0, 0, 0) if snapped else view.eye)
|
|
self.assertEqual(result.direction, view.direction, 'DEFAULT changes no orientation in this block')
|
|
owned = CameraProjection((5000, 0, 0), (1, 0, 0))
|
|
self.assertEqual(default_handoff(owned, (0, 0, 0), True), owned)
|
|
|
|
def test_first_resumed_follow_uses_scripted_shared_eye(self):
|
|
scripted = CameraProjection((600, 200, -200), (-600, -100, 200))
|
|
restored = default_handoff(scripted, (0, 500, -500), False)
|
|
self.assertEqual(restored, scripted, 'Within threshold retains scripted shared eye')
|
|
followed = normal_follow(restored, (0, 180, -350), (0, 99, 0), 1/60)
|
|
self.assertAlmostEqual(followed.eye[0], 584)
|
|
self.assertAlmostEqual(followed.eye[1], 199.6)
|
|
self.assertAlmostEqual(followed.eye[2], -204)
|
|
self.assertEqual(followed.direction, (-600, -101, 200), 'Aim derives from pre-update shared eye')
|
|
stale = CameraProjection((0, 180, -350), (0, 0, 1))
|
|
self.assertNotEqual(normal_follow(stale, (0, 180, -350), (0, 99, 0), 1/60).eye, followed.eye)
|
|
|
|
def test_snap_then_follow_preserves_phase_boundary(self):
|
|
scripted = CameraProjection((5000, 500, -500), (-1, 0, 0))
|
|
snapped = default_handoff(scripted, (0, 500, -500), False)
|
|
self.assertEqual(snapped.eye, (0, 500, -500))
|
|
self.assertEqual(snapped.direction, scripted.direction)
|
|
followed = normal_follow(snapped, (0, 180, -350), (0, 99, 0), 1/60, 1.5)
|
|
self.assertAlmostEqual(followed.eye[1], 490.4)
|
|
self.assertEqual(followed.direction, (0, -401, 500))
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|