nmarshall commited on
Commit
cfbe978
·
1 Parent(s): c1edef6

gameplay: resolve linked location visibility

Browse files
Cargo.lock CHANGED
@@ -9,6 +9,9 @@ version = "0.1.0"
9
  [[package]]
10
  name = "urt-gameplay"
11
  version = "0.1.0"
 
 
 
12
 
13
  [[package]]
14
  name = "xtask"
 
9
  [[package]]
10
  name = "urt-gameplay"
11
  version = "0.1.0"
12
+ dependencies = [
13
+ "urt-assets",
14
+ ]
15
 
16
  [[package]]
17
  name = "xtask"
crates/urt-assets/src/bsp.rs CHANGED
@@ -24,6 +24,7 @@ pub struct BspVisibility<'a> {
24
  nodes: &'a [u8],
25
  leaves: &'a [u8],
26
  visibility: Option<Visibility<'a>>,
 
27
  }
28
 
29
  fn lump(data: &[u8], index: usize) -> Result<&[u8]> {
@@ -92,25 +93,40 @@ impl<'a> BspVisibility<'a> {
92
  }
93
  }
94
  }
 
95
  for leaf in leaves.chunks_exact(LEAF_STRIDE) {
96
  let cluster = int(leaf, 0)?;
 
97
  if cluster < -1
98
- || int(leaf, 4)? < -1
 
99
  || visibility
100
  .as_ref()
101
  .is_some_and(|v| cluster >= 0 && cluster as usize >= v.clusters)
102
  {
103
  return Err(Error("invalid BSP leaf cluster or area"));
104
  }
 
 
 
105
  }
106
  Ok(Self {
107
  planes,
108
  nodes,
109
  leaves,
110
  visibility,
 
111
  })
112
  }
113
 
 
 
 
 
 
 
 
 
114
  /// Walk child zero for a nonnegative plane distance; otherwise child one.
115
  /// The oblique subtraction order follows the paired native point walk.
116
  pub fn point_leaf(&self, point: [f32; 3]) -> Result<Leaf> {
 
24
  nodes: &'a [u8],
25
  leaves: &'a [u8],
26
  visibility: Option<Visibility<'a>>,
27
+ area_count: usize,
28
  }
29
 
30
  fn lump(data: &[u8], index: usize) -> Result<&[u8]> {
 
93
  }
94
  }
95
  }
96
+ let mut area_count = 0;
97
  for leaf in leaves.chunks_exact(LEAF_STRIDE) {
98
  let cluster = int(leaf, 0)?;
99
+ let area = int(leaf, 4)?;
100
  if cluster < -1
101
+ || area < -1
102
+ || usize::try_from(area).is_ok_and(|a| a >= leaves.len() / LEAF_STRIDE)
103
  || visibility
104
  .as_ref()
105
  .is_some_and(|v| cluster >= 0 && cluster as usize >= v.clusters)
106
  {
107
  return Err(Error("invalid BSP leaf cluster or area"));
108
  }
109
+ if area >= 0 {
110
+ area_count = area_count.max(area as usize + 1);
111
+ }
112
  }
113
  Ok(Self {
114
  planes,
115
  nodes,
116
  leaves,
117
  visibility,
118
+ area_count,
119
  })
120
  }
121
 
122
+ pub fn area_count(&self) -> usize {
123
+ self.area_count
124
+ }
125
+
126
+ pub fn has_visibility(&self) -> bool {
127
+ self.visibility.is_some()
128
+ }
129
+
130
  /// Walk child zero for a nonnegative plane distance; otherwise child one.
131
  /// The oblique subtraction order follows the paired native point walk.
132
  pub fn point_leaf(&self, point: [f32; 3]) -> Result<Leaf> {
crates/urt-gameplay/Cargo.toml CHANGED
@@ -3,3 +3,6 @@ name = "urt-gameplay"
3
  version = "0.1.0"
4
  edition = "2024"
5
  publish = false
 
 
 
 
3
  version = "0.1.0"
4
  edition = "2024"
5
  publish = false
6
+
7
+ [dependencies]
8
+ urt-assets = { path = "../urt-assets" }
crates/urt-gameplay/src/bin/urt-world-visibility.rs ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ use std::{env, fs, io::Read};
2
+ use urt_assets::bsp::BspVisibility;
3
+ use urt_gameplay::area_portals::AreaPortals;
4
+ use urt_gameplay::location_feedback::{LocationEntry, LocationLookup};
5
+ use urt_gameplay::spatial_index::{Bounds, SpatialIndex};
6
+ use urt_gameplay::world_visibility::WorldVisibility;
7
+
8
+ fn main() {
9
+ let mut args = env::args().skip(1);
10
+ let path = args.next().unwrap();
11
+ let data = if path == "-" {
12
+ let mut bytes = Vec::new();
13
+ std::io::stdin().read_to_end(&mut bytes).unwrap();
14
+ bytes
15
+ } else {
16
+ fs::read(path).unwrap()
17
+ };
18
+ let points = args
19
+ .map(|arg| arg.parse::<f32>().unwrap())
20
+ .collect::<Vec<_>>();
21
+ let [from, to]: [[f32; 3]; 2] = [
22
+ points[..3].try_into().unwrap(),
23
+ points[3..].try_into().unwrap(),
24
+ ];
25
+ let bsp = BspVisibility::parse(&data).unwrap();
26
+ let mut portals = AreaPortals::new(bsp.area_count());
27
+ let index = SpatialIndex::new(Bounds::new([-128.; 3], [128.; 3]).unwrap(), 1).unwrap();
28
+ let entries = [Some(LocationEntry {
29
+ point: to.map(f32::to_bits),
30
+ trigger: false,
31
+ visible: false,
32
+ })];
33
+ let lookup = LocationLookup {
34
+ actor: from.map(f32::to_bits),
35
+ cache: None,
36
+ expiry: 0,
37
+ tick: 0,
38
+ order: &[0],
39
+ };
40
+ let sample = |portals: &AreaPortals, ignore_areas| {
41
+ let world = WorldVisibility {
42
+ bsp: &bsp,
43
+ portals,
44
+ ignore_areas,
45
+ };
46
+ let visible = world.visible(from, to).unwrap();
47
+ let selected = world
48
+ .nearest_location(&index, &entries, lookup)
49
+ .unwrap()
50
+ .selected
51
+ .is_some();
52
+ let cached = world
53
+ .nearest_location(
54
+ &index,
55
+ &entries,
56
+ LocationLookup {
57
+ cache: Some(0),
58
+ expiry: 1,
59
+ ..lookup
60
+ },
61
+ )
62
+ .unwrap()
63
+ .selected
64
+ .is_some();
65
+ format!(r#"{{"visible":{visible},"selected":{selected},"cached":{cached}}}"#)
66
+ };
67
+
68
+ let closed = sample(&portals, false);
69
+ let bypass = sample(&portals, true);
70
+ let opening = |point| {
71
+ bsp.point_leaf(point)
72
+ .unwrap()
73
+ .area
74
+ .map(|area| area as usize)
75
+ };
76
+ portals.adjust(opening(from), opening(to), true).unwrap();
77
+ let open = sample(&portals, false);
78
+ println!(
79
+ r#"{{"area_count":{},"closed":{closed},"open":{open},"bypass":{bypass}}}"#,
80
+ bsp.area_count()
81
+ );
82
+ }
crates/urt-gameplay/src/lib.rs CHANGED
@@ -207,3 +207,5 @@ pub mod location_feedback;
207
  pub mod spatial_index;
208
 
209
  pub mod area_portals;
 
 
 
207
  pub mod spatial_index;
208
 
209
  pub mod area_portals;
210
+
211
+ pub mod world_visibility;
crates/urt-gameplay/src/location_feedback.rs CHANGED
@@ -32,6 +32,7 @@ pub fn nearest_location(
32
  |slot| entries.get(slot).copied(),
33
  LocationLookup::from(input),
34
  LocationCandidates::Supplied(&input.query),
 
35
  )
36
  }
37
 
@@ -63,11 +64,21 @@ pub fn nearest_linked_location(
63
  index: &crate::spatial_index::SpatialIndex,
64
  entries: &[Option<LocationEntry>],
65
  input: LocationLookup<'_>,
 
 
 
 
 
 
 
 
 
66
  ) -> Result<LocationSelection, Error> {
67
  nearest_from(
68
  |slot| entries.get(slot).copied().flatten(),
69
  input,
70
  LocationCandidates::Linked(index),
 
71
  )
72
  }
73
 
@@ -80,6 +91,7 @@ fn nearest_from(
80
  entry: impl Fn(usize) -> Option<LocationEntry>,
81
  input: LocationLookup<'_>,
82
  candidates: LocationCandidates<'_>,
 
83
  ) -> Result<LocationSelection, Error> {
84
  use std::borrow::Cow;
85
 
@@ -148,7 +160,7 @@ fn nearest_from(
148
  }
149
  if square <= best {
150
  out.pvs.push(index);
151
- if e.visible {
152
  best = square;
153
  out.selected = Some(index);
154
  }
 
32
  |slot| entries.get(slot).copied(),
33
  LocationLookup::from(input),
34
  LocationCandidates::Supplied(&input.query),
35
+ |e| Ok(e.visible),
36
  )
37
  }
38
 
 
64
  index: &crate::spatial_index::SpatialIndex,
65
  entries: &[Option<LocationEntry>],
66
  input: LocationLookup<'_>,
67
+ ) -> Result<LocationSelection, Error> {
68
+ nearest_linked_with_visibility(index, entries, input, |e| Ok(e.visible))
69
+ }
70
+
71
+ pub(crate) fn nearest_linked_with_visibility(
72
+ index: &crate::spatial_index::SpatialIndex,
73
+ entries: &[Option<LocationEntry>],
74
+ input: LocationLookup<'_>,
75
+ visible: impl FnMut(LocationEntry) -> Result<bool, Error>,
76
  ) -> Result<LocationSelection, Error> {
77
  nearest_from(
78
  |slot| entries.get(slot).copied().flatten(),
79
  input,
80
  LocationCandidates::Linked(index),
81
+ visible,
82
  )
83
  }
84
 
 
91
  entry: impl Fn(usize) -> Option<LocationEntry>,
92
  input: LocationLookup<'_>,
93
  candidates: LocationCandidates<'_>,
94
+ mut visible: impl FnMut(LocationEntry) -> Result<bool, Error>,
95
  ) -> Result<LocationSelection, Error> {
96
  use std::borrow::Cow;
97
 
 
160
  }
161
  if square <= best {
162
  out.pvs.push(index);
163
+ if visible(e)? {
164
  best = square;
165
  out.selected = Some(index);
166
  }
crates/urt-gameplay/src/world_visibility.rs ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //! Point visibility from a loaded BSP and current area portal state.
2
+ use crate::area_portals::AreaPortals;
3
+ use crate::location_feedback::{
4
+ LocationEntry, LocationLookup, LocationSelection, nearest_linked_with_visibility,
5
+ };
6
+ use crate::native_policy::Error;
7
+ use crate::spatial_index::SpatialIndex;
8
+ use urt_assets::bsp::BspVisibility;
9
+
10
+ pub struct WorldVisibility<'a, 'map> {
11
+ pub bsp: &'a BspVisibility<'map>,
12
+ pub portals: &'a AreaPortals,
13
+ pub ignore_areas: bool,
14
+ }
15
+
16
+ impl WorldVisibility<'_, '_> {
17
+ /// A clear cluster bit rejects visibility before checking area connectivity.
18
+ pub fn visible(&self, source: [f32; 3], target: [f32; 3]) -> Result<bool, Error> {
19
+ let source = self
20
+ .bsp
21
+ .point_leaf(source)
22
+ .map_err(|_| Error::InvalidInput)?;
23
+ let target = self
24
+ .bsp
25
+ .point_leaf(target)
26
+ .map_err(|_| Error::InvalidInput)?;
27
+ if self.bsp.has_visibility() {
28
+ // The native source-cluster fallback points at the start of the table.
29
+ // A target outside the clustered space has no valid table bit.
30
+ let Some(target_cluster) = target.cluster else {
31
+ return Ok(false);
32
+ };
33
+ if self
34
+ .bsp
35
+ .cluster_visible(source.cluster.unwrap_or(0), target_cluster)
36
+ .map_err(|_| Error::InvalidInput)?
37
+ == Some(false)
38
+ {
39
+ return Ok(false);
40
+ }
41
+ }
42
+ if self.ignore_areas {
43
+ return Ok(true);
44
+ }
45
+ let Some((a, b)) = source.area.zip(target.area) else {
46
+ return Ok(false);
47
+ };
48
+ self.portals.connected(a as usize, b as usize)
49
+ }
50
+
51
+ /// The cache and trigger paths bypass point visibility. On the fallback
52
+ /// path use current map and portal state in place of a supplied mask.
53
+ pub fn nearest_location(
54
+ &self,
55
+ index: &SpatialIndex,
56
+ entries: &[Option<LocationEntry>],
57
+ input: LocationLookup<'_>,
58
+ ) -> Result<LocationSelection, Error> {
59
+ nearest_linked_with_visibility(index, entries, input, |entry| {
60
+ self.visible(
61
+ input.actor.map(f32::from_bits),
62
+ entry.point.map(f32::from_bits),
63
+ )
64
+ })
65
+ }
66
+ }
docs/FINDINGS.md CHANGED
@@ -2071,3 +2071,5 @@ RE-1034–1043 batch validation passed:2,018 Python tests,339 Rust tests,146 det
2071
  - The Rust BSP reader supplies map-derived leaves and packed cluster visibility, with absent areas and clusters retained from on-disk sentinels. [BSP visibility parity](research/RUST_BSP_VISIBILITY.md).
2072
 
2073
  - The Rust area graph retains connectivity until the last portal reference is closed. [Area portal parity](research/RUST_AREA_PORTALS.md).
 
 
 
2071
  - The Rust BSP reader supplies map-derived leaves and packed cluster visibility, with absent areas and clusters retained from on-disk sentinels. [BSP visibility parity](research/RUST_BSP_VISIBILITY.md).
2072
 
2073
  - The Rust area graph retains connectivity until the last portal reference is closed. [Area portal parity](research/RUST_AREA_PORTALS.md).
2074
+
2075
+ - Linked location fallback can use map-derived cluster masks and live area portal connectivity to select a visible location. [World visibility composition](research/RUST_WORLD_VISIBILITY.md).
docs/PROVISIONAL_TODO.md CHANGED
@@ -2133,3 +2133,5 @@ RE-974–983 completed routing, command rewrite, inactivity, movement-parameter
2133
  - [x] RE-1062 Decode IBSP point leaves and cluster visibility for Rust spatial queries ([evidence](research/RUST_BSP_VISIBILITY.md)).
2134
 
2135
  - [x] RE-1063 Port linked area connectivity and balanced portal reference updates ([evidence](research/RUST_AREA_PORTALS.md)).
 
 
 
2133
  - [x] RE-1062 Decode IBSP point leaves and cluster visibility for Rust spatial queries ([evidence](research/RUST_BSP_VISIBILITY.md)).
2134
 
2135
  - [x] RE-1063 Port linked area connectivity and balanced portal reference updates ([evidence](research/RUST_AREA_PORTALS.md)).
2136
+
2137
+ - [x] RE-1064 Connect loaded BSP cluster bits and current area portals to linked location fallback ([evidence](research/RUST_WORLD_VISIBILITY.md)).
docs/RESEARCH_LEDGER.md CHANGED
@@ -2927,3 +2927,7 @@ The Rust asset reader consumes the collision tree and visibility row data from t
2927
  ## 2026-11-25 — RE-1063 Port linked area connectivity and balanced portal reference updates
2928
 
2929
  Rust matches all 18 traced portal updates, including repeated opens, self-pairs and removal of the last connecting edge. See [area portal parity](research/RUST_AREA_PORTALS.md).
 
 
 
 
 
2927
  ## 2026-11-25 — RE-1063 Port linked area connectivity and balanced portal reference updates
2928
 
2929
  Rust matches all 18 traced portal updates, including repeated opens, self-pairs and removal of the last connecting edge. See [area portal parity](research/RUST_AREA_PORTALS.md).
2930
+
2931
+ ## 2026-11-25 — RE-1064 Connect loaded BSP cluster bits and current area portals to linked location fallback
2932
+
2933
+ The Rust visibility service applies map cluster visibility followed by the live area graph. Controlled and real map cases verify both gates and the existing location cache bypass. See [world visibility composition](research/RUST_WORLD_VISIBILITY.md).
docs/research/README.md CHANGED
@@ -1699,3 +1699,5 @@ The extension collector adds five focused tests for native tail calls, command-r
1699
  - [IBSP point leaves and cluster visibility in Rust](RUST_BSP_VISIBILITY.md)
1700
 
1701
  - [Rust area portal connectivity](RUST_AREA_PORTALS.md)
 
 
 
1699
  - [IBSP point leaves and cluster visibility in Rust](RUST_BSP_VISIBILITY.md)
1700
 
1701
  - [Rust area portal connectivity](RUST_AREA_PORTALS.md)
1702
+
1703
+ - [World visibility for linked location queries](RUST_WORLD_VISIBILITY.md)
docs/research/RUST_WORLD_VISIBILITY.md ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ # World visibility for linked location queries
2
+
3
+ `WorldVisibility` combines the loaded BSP's directed cluster bit with current area portal connectivity. A clear bit rejects a candidate even after its portal opens. The area bypass skips connectivity after the cluster test. A map with no visibility lump has no cluster restriction. The paired Linux routine returns the start of the loaded table for an unclustered source. Rust uses that row and treats an unclustered target as invisible when a table is present, since it has no valid target bit.
4
+
5
+ Linked location fallback uses this service for each candidate that reaches the distance test. Cached and trigger hits continue to bypass PVS. Seven controlled maps and six pairs from extracted maps cover cluster and area gates, portal updates and cache hits. See [the parity report](rust-world-visibility.json). Portal open and close calls still come from the caller. Native bounds/state ownership and full callback integration remain open.
docs/research/rust-world-visibility.json ADDED
@@ -0,0 +1,586 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "controlled": [
3
+ {
4
+ "case": "open-positive",
5
+ "expected": {
6
+ "area_count": 2,
7
+ "bypass": {
8
+ "cached": true,
9
+ "selected": true,
10
+ "visible": true
11
+ },
12
+ "closed": {
13
+ "cached": true,
14
+ "selected": false,
15
+ "visible": false
16
+ },
17
+ "open": {
18
+ "cached": true,
19
+ "selected": true,
20
+ "visible": true
21
+ }
22
+ },
23
+ "rust": {
24
+ "area_count": 2,
25
+ "bypass": {
26
+ "cached": true,
27
+ "selected": true,
28
+ "visible": true
29
+ },
30
+ "closed": {
31
+ "cached": true,
32
+ "selected": false,
33
+ "visible": false
34
+ },
35
+ "open": {
36
+ "cached": true,
37
+ "selected": true,
38
+ "visible": true
39
+ }
40
+ }
41
+ },
42
+ {
43
+ "case": "clear-bit-despite-open",
44
+ "expected": {
45
+ "area_count": 2,
46
+ "bypass": {
47
+ "cached": true,
48
+ "selected": false,
49
+ "visible": false
50
+ },
51
+ "closed": {
52
+ "cached": true,
53
+ "selected": false,
54
+ "visible": false
55
+ },
56
+ "open": {
57
+ "cached": true,
58
+ "selected": false,
59
+ "visible": false
60
+ }
61
+ },
62
+ "rust": {
63
+ "area_count": 2,
64
+ "bypass": {
65
+ "cached": true,
66
+ "selected": false,
67
+ "visible": false
68
+ },
69
+ "closed": {
70
+ "cached": true,
71
+ "selected": false,
72
+ "visible": false
73
+ },
74
+ "open": {
75
+ "cached": true,
76
+ "selected": false,
77
+ "visible": false
78
+ }
79
+ }
80
+ },
81
+ {
82
+ "case": "no-table",
83
+ "expected": {
84
+ "area_count": 2,
85
+ "bypass": {
86
+ "cached": true,
87
+ "selected": true,
88
+ "visible": true
89
+ },
90
+ "closed": {
91
+ "cached": true,
92
+ "selected": false,
93
+ "visible": false
94
+ },
95
+ "open": {
96
+ "cached": true,
97
+ "selected": true,
98
+ "visible": true
99
+ }
100
+ },
101
+ "rust": {
102
+ "area_count": 2,
103
+ "bypass": {
104
+ "cached": true,
105
+ "selected": true,
106
+ "visible": true
107
+ },
108
+ "closed": {
109
+ "cached": true,
110
+ "selected": false,
111
+ "visible": false
112
+ },
113
+ "open": {
114
+ "cached": true,
115
+ "selected": true,
116
+ "visible": true
117
+ }
118
+ }
119
+ },
120
+ {
121
+ "case": "unclustered-source",
122
+ "expected": {
123
+ "area_count": 2,
124
+ "bypass": {
125
+ "cached": true,
126
+ "selected": true,
127
+ "visible": true
128
+ },
129
+ "closed": {
130
+ "cached": true,
131
+ "selected": false,
132
+ "visible": false
133
+ },
134
+ "open": {
135
+ "cached": true,
136
+ "selected": true,
137
+ "visible": true
138
+ }
139
+ },
140
+ "rust": {
141
+ "area_count": 2,
142
+ "bypass": {
143
+ "cached": true,
144
+ "selected": true,
145
+ "visible": true
146
+ },
147
+ "closed": {
148
+ "cached": true,
149
+ "selected": false,
150
+ "visible": false
151
+ },
152
+ "open": {
153
+ "cached": true,
154
+ "selected": true,
155
+ "visible": true
156
+ }
157
+ }
158
+ },
159
+ {
160
+ "case": "unclustered-target",
161
+ "expected": {
162
+ "area_count": 2,
163
+ "bypass": {
164
+ "cached": true,
165
+ "selected": false,
166
+ "visible": false
167
+ },
168
+ "closed": {
169
+ "cached": true,
170
+ "selected": false,
171
+ "visible": false
172
+ },
173
+ "open": {
174
+ "cached": true,
175
+ "selected": false,
176
+ "visible": false
177
+ }
178
+ },
179
+ "rust": {
180
+ "area_count": 2,
181
+ "bypass": {
182
+ "cached": true,
183
+ "selected": false,
184
+ "visible": false
185
+ },
186
+ "closed": {
187
+ "cached": true,
188
+ "selected": false,
189
+ "visible": false
190
+ },
191
+ "open": {
192
+ "cached": true,
193
+ "selected": false,
194
+ "visible": false
195
+ }
196
+ }
197
+ },
198
+ {
199
+ "case": "absent-area",
200
+ "expected": {
201
+ "area_count": 1,
202
+ "bypass": {
203
+ "cached": true,
204
+ "selected": true,
205
+ "visible": true
206
+ },
207
+ "closed": {
208
+ "cached": true,
209
+ "selected": false,
210
+ "visible": false
211
+ },
212
+ "open": {
213
+ "cached": true,
214
+ "selected": false,
215
+ "visible": false
216
+ }
217
+ },
218
+ "rust": {
219
+ "area_count": 1,
220
+ "bypass": {
221
+ "cached": true,
222
+ "selected": true,
223
+ "visible": true
224
+ },
225
+ "closed": {
226
+ "cached": true,
227
+ "selected": false,
228
+ "visible": false
229
+ },
230
+ "open": {
231
+ "cached": true,
232
+ "selected": false,
233
+ "visible": false
234
+ }
235
+ }
236
+ },
237
+ {
238
+ "case": "same-area",
239
+ "expected": {
240
+ "area_count": 1,
241
+ "bypass": {
242
+ "cached": true,
243
+ "selected": true,
244
+ "visible": true
245
+ },
246
+ "closed": {
247
+ "cached": true,
248
+ "selected": true,
249
+ "visible": true
250
+ },
251
+ "open": {
252
+ "cached": true,
253
+ "selected": true,
254
+ "visible": true
255
+ }
256
+ },
257
+ "rust": {
258
+ "area_count": 1,
259
+ "bypass": {
260
+ "cached": true,
261
+ "selected": true,
262
+ "visible": true
263
+ },
264
+ "closed": {
265
+ "cached": true,
266
+ "selected": true,
267
+ "visible": true
268
+ },
269
+ "open": {
270
+ "cached": true,
271
+ "selected": true,
272
+ "visible": true
273
+ }
274
+ }
275
+ }
276
+ ],
277
+ "limits": "Cluster-bit and area-portal composition. Map samples use independent BSP reads. Unclustered target outcomes use the bounded Rust policy.",
278
+ "maps": [
279
+ {
280
+ "expected": {
281
+ "area_count": 7,
282
+ "bypass": {
283
+ "cached": true,
284
+ "selected": false,
285
+ "visible": false
286
+ },
287
+ "closed": {
288
+ "cached": true,
289
+ "selected": false,
290
+ "visible": false
291
+ },
292
+ "open": {
293
+ "cached": true,
294
+ "selected": false,
295
+ "visible": false
296
+ }
297
+ },
298
+ "path": "assets/extracted/zUrT43_004.pk3/members/000006/maps/ut4_tombs.bsp",
299
+ "points": [
300
+ [
301
+ 2166.5,
302
+ 1636.5,
303
+ 806.0
304
+ ],
305
+ [
306
+ 2166.5,
307
+ 520.5,
308
+ 806.0
309
+ ]
310
+ ],
311
+ "rust": {
312
+ "area_count": 7,
313
+ "bypass": {
314
+ "cached": true,
315
+ "selected": false,
316
+ "visible": false
317
+ },
318
+ "closed": {
319
+ "cached": true,
320
+ "selected": false,
321
+ "visible": false
322
+ },
323
+ "open": {
324
+ "cached": true,
325
+ "selected": false,
326
+ "visible": false
327
+ }
328
+ }
329
+ },
330
+ {
331
+ "expected": {
332
+ "area_count": 7,
333
+ "bypass": {
334
+ "cached": true,
335
+ "selected": true,
336
+ "visible": true
337
+ },
338
+ "closed": {
339
+ "cached": true,
340
+ "selected": true,
341
+ "visible": true
342
+ },
343
+ "open": {
344
+ "cached": true,
345
+ "selected": true,
346
+ "visible": true
347
+ }
348
+ },
349
+ "path": "assets/extracted/zUrT43_004.pk3/members/000006/maps/ut4_tombs.bsp",
350
+ "points": [
351
+ [
352
+ 2166.5,
353
+ 1636.5,
354
+ 806.0
355
+ ],
356
+ [
357
+ 2166.5,
358
+ 1636.5,
359
+ 806.0
360
+ ]
361
+ ],
362
+ "rust": {
363
+ "area_count": 7,
364
+ "bypass": {
365
+ "cached": true,
366
+ "selected": true,
367
+ "visible": true
368
+ },
369
+ "closed": {
370
+ "cached": true,
371
+ "selected": true,
372
+ "visible": true
373
+ },
374
+ "open": {
375
+ "cached": true,
376
+ "selected": true,
377
+ "visible": true
378
+ }
379
+ }
380
+ },
381
+ {
382
+ "expected": {
383
+ "area_count": 5,
384
+ "bypass": {
385
+ "cached": true,
386
+ "selected": false,
387
+ "visible": false
388
+ },
389
+ "closed": {
390
+ "cached": true,
391
+ "selected": false,
392
+ "visible": false
393
+ },
394
+ "open": {
395
+ "cached": true,
396
+ "selected": false,
397
+ "visible": false
398
+ }
399
+ },
400
+ "path": "assets/extracted/zUrT43_004.pk3/members/000016/maps/ut4_uptown.bsp",
401
+ "points": [
402
+ [
403
+ 1000000.0,
404
+ 1000000.0,
405
+ 1000000.0
406
+ ],
407
+ [
408
+ 2078.0,
409
+ -448.0,
410
+ 672.0
411
+ ]
412
+ ],
413
+ "rust": {
414
+ "area_count": 5,
415
+ "bypass": {
416
+ "cached": true,
417
+ "selected": false,
418
+ "visible": false
419
+ },
420
+ "closed": {
421
+ "cached": true,
422
+ "selected": false,
423
+ "visible": false
424
+ },
425
+ "open": {
426
+ "cached": true,
427
+ "selected": false,
428
+ "visible": false
429
+ }
430
+ }
431
+ },
432
+ {
433
+ "expected": {
434
+ "area_count": 5,
435
+ "bypass": {
436
+ "cached": true,
437
+ "selected": true,
438
+ "visible": true
439
+ },
440
+ "closed": {
441
+ "cached": true,
442
+ "selected": true,
443
+ "visible": true
444
+ },
445
+ "open": {
446
+ "cached": true,
447
+ "selected": true,
448
+ "visible": true
449
+ }
450
+ },
451
+ "path": "assets/extracted/zUrT43_004.pk3/members/000016/maps/ut4_uptown.bsp",
452
+ "points": [
453
+ [
454
+ 1000000.0,
455
+ 1000000.0,
456
+ 1000000.0
457
+ ],
458
+ [
459
+ 1000000.0,
460
+ 1000000.0,
461
+ 1000000.0
462
+ ]
463
+ ],
464
+ "rust": {
465
+ "area_count": 5,
466
+ "bypass": {
467
+ "cached": true,
468
+ "selected": true,
469
+ "visible": true
470
+ },
471
+ "closed": {
472
+ "cached": true,
473
+ "selected": true,
474
+ "visible": true
475
+ },
476
+ "open": {
477
+ "cached": true,
478
+ "selected": true,
479
+ "visible": true
480
+ }
481
+ }
482
+ },
483
+ {
484
+ "expected": {
485
+ "area_count": 7,
486
+ "bypass": {
487
+ "cached": true,
488
+ "selected": false,
489
+ "visible": false
490
+ },
491
+ "closed": {
492
+ "cached": true,
493
+ "selected": false,
494
+ "visible": false
495
+ },
496
+ "open": {
497
+ "cached": true,
498
+ "selected": false,
499
+ "visible": false
500
+ }
501
+ },
502
+ "path": "assets/extracted/zUrT43_021.pk3/members/000002/maps/ut4_paris.bsp",
503
+ "points": [
504
+ [
505
+ 0.0,
506
+ 0.0,
507
+ 0.0
508
+ ],
509
+ [
510
+ 1396.0,
511
+ 1376.0,
512
+ 916.0
513
+ ]
514
+ ],
515
+ "rust": {
516
+ "area_count": 7,
517
+ "bypass": {
518
+ "cached": true,
519
+ "selected": false,
520
+ "visible": false
521
+ },
522
+ "closed": {
523
+ "cached": true,
524
+ "selected": false,
525
+ "visible": false
526
+ },
527
+ "open": {
528
+ "cached": true,
529
+ "selected": false,
530
+ "visible": false
531
+ }
532
+ }
533
+ },
534
+ {
535
+ "expected": {
536
+ "area_count": 7,
537
+ "bypass": {
538
+ "cached": true,
539
+ "selected": true,
540
+ "visible": true
541
+ },
542
+ "closed": {
543
+ "cached": true,
544
+ "selected": true,
545
+ "visible": true
546
+ },
547
+ "open": {
548
+ "cached": true,
549
+ "selected": true,
550
+ "visible": true
551
+ }
552
+ },
553
+ "path": "assets/extracted/zUrT43_021.pk3/members/000002/maps/ut4_paris.bsp",
554
+ "points": [
555
+ [
556
+ 0.0,
557
+ 0.0,
558
+ 0.0
559
+ ],
560
+ [
561
+ 0.0,
562
+ 0.0,
563
+ 0.0
564
+ ]
565
+ ],
566
+ "rust": {
567
+ "area_count": 7,
568
+ "bypass": {
569
+ "cached": true,
570
+ "selected": true,
571
+ "visible": true
572
+ },
573
+ "closed": {
574
+ "cached": true,
575
+ "selected": true,
576
+ "visible": true
577
+ },
578
+ "open": {
579
+ "cached": true,
580
+ "selected": true,
581
+ "visible": true
582
+ }
583
+ }
584
+ }
585
+ ]
586
+ }
scripts/analyze_rust_world_visibility.py ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Exercise visibility composition with controlled and extracted BSP points."""
2
+ import json
3
+ import os
4
+ import struct
5
+ import subprocess
6
+ from pathlib import Path
7
+
8
+ from analyze_qvm import write_json
9
+
10
+
11
+ def fixture(row, areas=(0, 1), clusters=(0, 1)):
12
+ chunks = {
13
+ 2: struct.pack('<4f', 1., 0., 0., 0.),
14
+ 3: struct.pack('<9i', 0, -1, -2, *([0] * 6)),
15
+ 4: b''.join(struct.pack('<12i', c, a, *([0] * 10)) for c, a in zip(clusters, areas)),
16
+ }
17
+ if row is not None:
18
+ chunks[16] = struct.pack('<iiBB', 2, 1, row, 2)
19
+ data = bytearray(b'IBSP' + struct.pack('<i', 46) + bytes(17 * 8))
20
+ for lump, contents in chunks.items():
21
+ struct.pack_into('<ii', data, 8 + 8 * lump, len(data), len(contents))
22
+ data.extend(contents)
23
+ return bytes(data)
24
+
25
+
26
+ def sample(visible, selected=None):
27
+ return dict(visible=visible, selected=visible if selected is None else selected, cached=True)
28
+
29
+
30
+ def expected(areas, closed, opened, bypass):
31
+ return dict(area_count=areas, closed=sample(closed), open=sample(opened), bypass=sample(bypass))
32
+
33
+
34
+ def run(binary, source, points, data=None):
35
+ args = [str(binary), source, *(str(x) for point in points for x in point)]
36
+ return json.loads(subprocess.run(args, input=data, capture_output=True, check=True).stdout)
37
+
38
+
39
+ def main():
40
+ subprocess.run(['cargo', 'build', '--offline', '-p', 'urt-gameplay', '--bin',
41
+ 'urt-world-visibility'], check=True)
42
+ binary = Path(os.environ.get('CARGO_TARGET_DIR', 'target')) / 'debug' / 'urt-world-visibility'
43
+ controlled = []
44
+ for label, data, want in (
45
+ ('open-positive', fixture(3), expected(2, False, True, True)),
46
+ ('clear-bit-despite-open', fixture(1), expected(2, False, False, False)),
47
+ ('no-table', fixture(None), expected(2, False, True, True)),
48
+ ('unclustered-source', fixture(3, clusters=(-1, 1)), expected(2, False, True, True)),
49
+ ('unclustered-target', fixture(3, clusters=(0, -1)), expected(2, False, False, False)),
50
+ ('absent-area', fixture(3, areas=(0, -1)), expected(1, False, False, True)),
51
+ ('same-area', fixture(3, areas=(0, 0)), expected(1, True, True, True)),
52
+ ):
53
+ got = run(binary, '-', [[5., 0., 0.], [-5., 0., 0.]], data)
54
+ controlled.append(dict(case=label, expected=want, rust=got))
55
+ maps = []
56
+ baseline = json.loads(Path('docs/research/rust-bsp-visibility.json').read_text())
57
+ for original in baseline['maps']:
58
+ path = original['path']
59
+ data = Path(path).read_bytes()
60
+ start, size = struct.unpack_from('<ii', data, 40)
61
+ area_count = max(struct.unpack_from('<i', data, i + 4)[0] for i in range(start, start + size, 48)) + 1
62
+ points = original['points']
63
+ leaves = original['expected']['leaves']
64
+ masks = original['expected']['visibility']
65
+ for should_see in (False, True):
66
+ i, j = next((i, j) for i in range(len(points)) for j in range(len(points))
67
+ if leaves[i][1] is not None and leaves[j][1] is not None
68
+ and masks[i * len(points) + j] is should_see)
69
+ a, b = points[i], points[j]
70
+ # A point beyond the location distance cap skips fallback PVS entirely.
71
+ within = sum((x - y) ** 2 for x, y in zip(a, b)) <= 201326592
72
+ same_area = leaves[i][1] == leaves[j][1]
73
+ want = expected(area_count, should_see and same_area, should_see, should_see)
74
+ for key in ('closed', 'open', 'bypass'):
75
+ want[key]['selected'] &= within
76
+ maps.append(dict(path=path, points=[a, b], expected=want,
77
+ rust=run(binary, path, [a, b])))
78
+ write_json(Path('docs/research/rust-world-visibility.json'), {
79
+ 'controlled': controlled, 'maps': maps,
80
+ 'limits': 'Cluster-bit and area-portal composition. Map samples use independent BSP reads. Unclustered target outcomes use the bounded Rust policy.',
81
+ })
82
+
83
+
84
+ if __name__ == '__main__':
85
+ main()
scripts/test_rust_world_visibility.py ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import unittest
3
+ from pathlib import Path
4
+
5
+
6
+ class WorldVisibilityTests(unittest.TestCase):
7
+ def test_controlled_and_real_map_points(self):
8
+ report = json.loads(Path('docs/research/rust-world-visibility.json').read_text())
9
+ self.assertEqual(len(report['controlled']), 7)
10
+ self.assertEqual(len(report['maps']), 6)
11
+ for row in report['controlled'] + report['maps']:
12
+ with self.subTest(case=row.get('case', row.get('path'))):
13
+ self.assertEqual(row['rust'], row['expected'])
14
+
15
+
16
+ if __name__ == '__main__':
17
+ unittest.main()
xtask/checks.tsv CHANGED
@@ -4919,3 +4919,17 @@ group gameplay scripts/analyze_rust_area_portals.py
4919
  edge crates/urt-gameplay/src/area_portals.rs scripts/analyze_rust_area_portals.py
4920
  edge crates/urt-gameplay/src/bin/urt-area-portals.rs scripts/analyze_rust_area_portals.py
4921
  edge crates/urt-gameplay/src/area_portals.rs scripts/analyze_rust_health_impulse.py
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4919
  edge crates/urt-gameplay/src/area_portals.rs scripts/analyze_rust_area_portals.py
4920
  edge crates/urt-gameplay/src/bin/urt-area-portals.rs scripts/analyze_rust_area_portals.py
4921
  edge crates/urt-gameplay/src/area_portals.rs scripts/analyze_rust_health_impulse.py
4922
+ report scripts/analyze_rust_world_visibility.py docs/research/rust-world-visibility.json
4923
+ edge docs/research/rust-world-visibility.json scripts/test_rust_world_visibility.py
4924
+ group rust-world-visibility scripts/analyze_rust_world_visibility.py
4925
+ group rust-world-visibility scripts/analyze_rust_bsp_visibility.py
4926
+ group rust-world-visibility scripts/analyze_rust_linked_location.py
4927
+ group gameplay scripts/analyze_rust_world_visibility.py
4928
+ edge docs/research/rust-bsp-visibility.json scripts/analyze_rust_world_visibility.py
4929
+ edge crates/urt-assets/src/bsp.rs scripts/analyze_rust_world_visibility.py
4930
+ edge crates/urt-gameplay/src/area_portals.rs scripts/analyze_rust_world_visibility.py
4931
+ edge crates/urt-gameplay/src/spatial_index.rs scripts/analyze_rust_world_visibility.py
4932
+ edge crates/urt-gameplay/src/location_feedback.rs scripts/analyze_rust_world_visibility.py
4933
+ edge crates/urt-gameplay/src/world_visibility.rs scripts/analyze_rust_world_visibility.py
4934
+ edge crates/urt-gameplay/src/bin/urt-world-visibility.rs scripts/analyze_rust_world_visibility.py
4935
+ edge crates/urt-gameplay/src/world_visibility.rs scripts/analyze_rust_health_impulse.py