54 lines
1.8 KiB
Python
54 lines
1.8 KiB
Python
"""Tests for the headless raycaster: honest frames from real world state."""
|
|
|
|
from testbed.room.render import Raycaster
|
|
from testbed.room.world import Room
|
|
|
|
|
|
def test_spawn_view_shows_crate_and_occludes_beacon():
|
|
"""From spawn the beacon is behind crate_red, so the frame center is the
|
|
crate's color, not a cyan glow."""
|
|
room = Room()
|
|
img, grid = Raycaster().render(room)
|
|
px = img.load()
|
|
r, g, b = px[80, 60]
|
|
assert r > 120 and g < 100 and b < 90 # reddish crate, distance-fogged
|
|
assert len(grid) == 30 and len(grid[0]) == 40
|
|
# The crate is ~5m away: center depth block must be well below 10.
|
|
assert 2.0 < grid[17][20] < 8.0
|
|
|
|
|
|
def test_wall_nearby_is_bright_gray():
|
|
room = Room()
|
|
room.capsule.yaw_deg = 180.0 # face north wall 1.5m away
|
|
px = Raycaster().render(room)[0].load()
|
|
r, g, _b = px[80, 60]
|
|
assert abs(r - g) < 8 and r > 80 # gray wall, little fog at 1.5m
|
|
|
|
|
|
def test_beacon_glow_visible_when_facing_it():
|
|
room = Room()
|
|
room.capsule.x, room.capsule.z, room.capsule.yaw_deg = 11.0, 11.0, 45.0
|
|
img, _ = Raycaster().render(room)
|
|
px = img.load()
|
|
r, _, b = px[80, 60]
|
|
assert b > r # inactive beacon glows cyan
|
|
room.beacon.active = True
|
|
px = Raycaster().render(room)[0].load()
|
|
r, _, b = px[80, 60]
|
|
assert r > b # active beacon glows warm yellow
|
|
|
|
|
|
def test_beacon_occluded_by_crate():
|
|
room = Room()
|
|
# Beacon behind crate_red from spawn: center pixel must not be cyan.
|
|
px = Raycaster().render(room)[0].load()
|
|
_r, _g, b = px[80, 60]
|
|
assert b < 90
|
|
|
|
|
|
def test_depth_grid_aligned_and_bounded():
|
|
room = Room()
|
|
_, grid = Raycaster().render(room, max_depth=10.0)
|
|
assert all(0.0 <= v <= 10.0 for row in grid for v in row)
|
|
assert any(v > 0 for row in grid for v in row)
|