nmarshall commited on
Commit
a4cee4d
·
1 Parent(s): b9199be

gameplay: produce absolute entity link bounds

Browse files
crates/urt-gameplay/src/bin/urt-spatial-index.rs CHANGED
@@ -1,4 +1,4 @@
1
- use urt_gameplay::spatial_index::{Bounds, SpatialIndex};
2
 
3
  fn bounds(words: &[u32]) -> Bounds {
4
  let values = <[u32; 6]>::try_from(words).unwrap().map(f32::from_bits);
@@ -13,6 +13,33 @@ fn main() {
13
  let mut args = std::env::args().skip(1);
14
  let mode = args.next().unwrap();
15
  let words = args.map(|arg| arg.parse().unwrap()).collect::<Vec<u32>>();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  let mut index = SpatialIndex::new(bounds(&words[..6]), 1024).unwrap();
17
  match mode.as_str() {
18
  "tree" => {
 
1
+ use urt_gameplay::spatial_index::{Bounds, SpatialIndex, linked_bounds};
2
 
3
  fn bounds(words: &[u32]) -> Bounds {
4
  let values = <[u32; 6]>::try_from(words).unwrap().map(f32::from_bits);
 
13
  let mut args = std::env::args().skip(1);
14
  let mode = args.next().unwrap();
15
  let words = args.map(|arg| arg.parse().unwrap()).collect::<Vec<u32>>();
16
+ if mode == "bounds" {
17
+ print!("[");
18
+ for (i, row) in words.chunks_exact(13).enumerate() {
19
+ if i != 0 {
20
+ print!(",");
21
+ }
22
+ let vector = |words: &[u32]| <[u32; 3]>::try_from(words).unwrap().map(f32::from_bits);
23
+ let out = linked_bounds(
24
+ bounds(&row[..6]),
25
+ vector(&row[6..9]),
26
+ row[9] != 0,
27
+ vector(&row[10..]),
28
+ )
29
+ .unwrap();
30
+ let endpoints = out
31
+ .absolute
32
+ .endpoints()
33
+ .map(|point| point.map(f32::to_bits));
34
+ let radius = out
35
+ .radius
36
+ .map(|v| v.to_bits().to_string())
37
+ .unwrap_or("null".into());
38
+ print!(r#"{{"bounds":{endpoints:?},"radius":{radius}}}"#);
39
+ }
40
+ println!("]");
41
+ return;
42
+ }
43
  let mut index = SpatialIndex::new(bounds(&words[..6]), 1024).unwrap();
44
  match mode.as_str() {
45
  "tree" => {
crates/urt-gameplay/src/spatial_index.rs CHANGED
@@ -21,11 +21,51 @@ impl Bounds {
21
  Ok(Self { min, max })
22
  }
23
 
 
 
 
 
24
  fn overlaps(self, other: Self) -> bool {
25
  (0..3).all(|axis| self.min[axis] <= other.max[axis] && self.max[axis] >= other.min[axis])
26
  }
27
  }
28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  #[derive(Clone, Copy, Debug, PartialEq)]
30
  pub struct Split {
31
  pub axis: usize,
@@ -124,6 +164,18 @@ impl SpatialIndex {
124
  Ok(sector)
125
  }
126
 
 
 
 
 
 
 
 
 
 
 
 
 
127
  pub fn unlink(&mut self, slot: usize) -> Result<bool, Error> {
128
  let link = self.links.get_mut(slot).ok_or(Error::InvalidIndex)?.take();
129
  if let Some(link) = link {
 
21
  Ok(Self { min, max })
22
  }
23
 
24
+ pub fn endpoints(self) -> [[f32; 3]; 2] {
25
+ [self.min, self.max]
26
+ }
27
+
28
  fn overlaps(self, other: Self) -> bool {
29
  (0..3).all(|axis| self.min[axis] <= other.max[axis] && self.max[axis] >= other.min[axis])
30
  }
31
  }
32
 
33
+ #[derive(Clone, Copy, Debug, PartialEq)]
34
+ pub struct LinkedBounds {
35
+ pub absolute: Bounds,
36
+ pub radius: Option<f32>,
37
+ }
38
+
39
+ /// Prepare the finite broad-phase bounds used by entity linking. Rotated brush
40
+ /// models use the local bounding radius; all paths expand absolute bounds by
41
+ /// one unit after translating.
42
+ pub fn linked_bounds(
43
+ local: Bounds,
44
+ origin: [f32; 3],
45
+ brush_model: bool,
46
+ angles: [f32; 3],
47
+ ) -> Result<LinkedBounds, Error> {
48
+ if origin.iter().any(|v| !v.is_finite())
49
+ || (brush_model && angles.iter().any(|v| !v.is_finite()))
50
+ {
51
+ return Err(Error::NonFinite);
52
+ }
53
+ let radius = (brush_model && angles.iter().any(|&v| v != 0.)).then(|| {
54
+ let [x, y, z] =
55
+ std::array::from_fn(|axis| local.min[axis].abs().max(local.max[axis].abs()));
56
+ ((x * x + y * y) + z * z).sqrt()
57
+ });
58
+ let (mins, maxs) = match radius {
59
+ Some(radius) => ([-radius; 3], [radius; 3]),
60
+ None => (local.min, local.max),
61
+ };
62
+ let absolute = Bounds::new(
63
+ std::array::from_fn(|axis| (origin[axis] + mins[axis]) - 1.),
64
+ std::array::from_fn(|axis| (origin[axis] + maxs[axis]) + 1.),
65
+ )?;
66
+ Ok(LinkedBounds { absolute, radius })
67
+ }
68
+
69
  #[derive(Clone, Copy, Debug, PartialEq)]
70
  pub struct Split {
71
  pub axis: usize,
 
164
  Ok(sector)
165
  }
166
 
167
+ pub fn link_entity(
168
+ &mut self,
169
+ slot: usize,
170
+ local: Bounds,
171
+ origin: [f32; 3],
172
+ brush_model: bool,
173
+ angles: [f32; 3],
174
+ ) -> Result<usize, Error> {
175
+ let bounds = linked_bounds(local, origin, brush_model, angles)?;
176
+ self.link(slot, bounds.absolute)
177
+ }
178
+
179
  pub fn unlink(&mut self, slot: usize) -> Result<bool, Error> {
180
  let link = self.links.get_mut(slot).ok_or(Error::InvalidIndex)?.take();
181
  if let Some(link) = link {
docs/FINDINGS.md CHANGED
@@ -2075,3 +2075,5 @@ RE-1034–1043 batch validation passed:2,018 Python tests,339 Rust tests,146 det
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).
2076
 
2077
  - Defuse radio can resolve location text through the linked-slot index and BSP portal visibility service. [World-backed defuse radio](research/RUST_DEFUSE_WORLD_RADIO.md).
 
 
 
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).
2076
 
2077
  - Defuse radio can resolve location text through the linked-slot index and BSP portal visibility service. [World-backed defuse radio](research/RUST_DEFUSE_WORLD_RADIO.md).
2078
+
2079
+ - Rust links can derive their absolute bounds from entity origin, brush-model state and local bounds. [Link bounds parity](research/RUST_LINK_BOUNDS.md).
docs/PROVISIONAL_TODO.md CHANGED
@@ -2137,3 +2137,5 @@ RE-974–983 completed routing, command rewrite, inactivity, movement-parameter
2137
  - [x] RE-1064 Connect loaded BSP cluster bits and current area portals to linked location fallback ([evidence](research/RUST_WORLD_VISIBILITY.md)).
2138
 
2139
  - [x] RE-1065 Connect allocated defuse radio to live spatial queries and map visibility ([evidence](research/RUST_DEFUSE_WORLD_RADIO.md)).
 
 
 
2137
  - [x] RE-1064 Connect loaded BSP cluster bits and current area portals to linked location fallback ([evidence](research/RUST_WORLD_VISIBILITY.md)).
2138
 
2139
  - [x] RE-1065 Connect allocated defuse radio to live spatial queries and map visibility ([evidence](research/RUST_DEFUSE_WORLD_RADIO.md)).
2140
+
2141
+ - [x] RE-1066 Port absolute entity bounds for linked-slot queries ([evidence](research/RUST_LINK_BOUNDS.md)).
docs/RESEARCH_LEDGER.md CHANGED
@@ -2935,3 +2935,7 @@ The Rust visibility service applies map cluster visibility followed by the live
2935
  ## 2026-11-25 — RE-1065 Connect allocated defuse radio to live spatial queries and map visibility
2936
 
2937
  The allocated callback consumes current linked locations, BSP masks and portal connectivity for radio. The 16-case comparison includes the effect-free waiting and cancellation feedback gates. See [world-backed radio](research/RUST_DEFUSE_WORLD_RADIO.md).
 
 
 
 
 
2935
  ## 2026-11-25 — RE-1065 Connect allocated defuse radio to live spatial queries and map visibility
2936
 
2937
  The allocated callback consumes current linked locations, BSP masks and portal connectivity for radio. The 16-case comparison includes the effect-free waiting and cancellation feedback gates. See [world-backed radio](research/RUST_DEFUSE_WORLD_RADIO.md).
2938
+
2939
+ ## 2026-11-25 — RE-1066 Port absolute entity bounds for linked-slot queries
2940
+
2941
+ The Rust link producer matches 180 native slices across rotated and unrotated bounds, signed zero and padding. See [absolute bounds parity](research/RUST_LINK_BOUNDS.md).
docs/research/README.md CHANGED
@@ -1703,3 +1703,5 @@ The extension collector adds five focused tests for native tail calls, command-r
1703
  - [World visibility for linked location queries](RUST_WORLD_VISIBILITY.md)
1704
 
1705
  - [World-backed defuse radio](RUST_DEFUSE_WORLD_RADIO.md)
 
 
 
1703
  - [World visibility for linked location queries](RUST_WORLD_VISIBILITY.md)
1704
 
1705
  - [World-backed defuse radio](RUST_DEFUSE_WORLD_RADIO.md)
1706
+
1707
+ - [Absolute bounds for Rust entity linking](RUST_LINK_BOUNDS.md)
docs/research/RUST_LINK_BOUNDS.md ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ # Absolute bounds for Rust entity linking
2
+
3
+ `linked_bounds` translates local bounds by the entity origin. A nonzero brush-model state with a nonzero angle instead computes the bounding radius and uses the cube around that origin. Both paths expand their absolute bounds by one unit after translation. The Rust sector index can link directly from those inputs and validates the new bounds before replacing old membership.
4
+
5
+ [The parity report](rust-link-bounds.json) compares the exact endpoint and radius words across 180 paired native cases. These cover ordinary bounds, nonzero brush-model values, signed zero angles and all three rotation axes. The port covers the broad-phase bound producer. BSP link metadata, rotated narrow-phase geometry and frame scheduling remain separate.
docs/research/rust-link-bounds.json ADDED
The diff for this file is too large to render. See raw diff
 
scripts/analyze_rust_link_bounds.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Compare finite Rust entity bounds with the native linking slices."""
2
+ import hashlib
3
+ import json
4
+ import os
5
+ import subprocess
6
+ from pathlib import Path
7
+
8
+ from analyze_qvm import write_json
9
+ from qvm_move_callbacks_oracle import word
10
+ from rust_lifecycle_support import result
11
+
12
+
13
+ def main():
14
+ subprocess.run(['cargo', 'build', '--offline', '-p', 'urt-gameplay', '--bin',
15
+ 'urt-spatial-index'], check=True)
16
+ binary = Path(os.environ.get('CARGO_TARGET_DIR', 'target')) / 'debug' / 'urt-spatial-index'
17
+ path = Path('docs/research/link-bounds.json')
18
+ data = path.read_bytes()
19
+ probes = []
20
+ for name, native in json.loads(data)['native'].items():
21
+ args, expected = [], []
22
+ for row in native['bounds_compositions']:
23
+ args.extend([*map(word, row['local_min']), *map(word, row['local_max']),
24
+ *map(word, row['origin']), row['model_word'], *map(word, row['angles'])])
25
+ expected.append(dict(bounds=[list(map(word, row['absolute_min'])),
26
+ list(map(word, row['absolute_max']))],
27
+ radius=word(row['radius']) if row['radius_path'] else None))
28
+ probes.append(dict(engine=name, source=expected, rust=result(binary, 'bounds', args)))
29
+ write_json(Path('docs/research/rust-link-bounds.json'), {
30
+ 'source_report': str(path), 'source_report_sha256': hashlib.sha256(data).hexdigest(),
31
+ 'probes': probes, 'limits': 'Finite absolute broad-phase bounds. Leaf metadata and physics remain separate.',
32
+ })
33
+
34
+
35
+ if __name__ == '__main__':
36
+ main()
scripts/test_rust_link_bounds.py ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import hashlib
2
+ import json
3
+ import unittest
4
+ from pathlib import Path
5
+
6
+
7
+ class RustLinkBoundsTests(unittest.TestCase):
8
+ def test_native_bounds(self):
9
+ report = json.loads(Path('docs/research/rust-link-bounds.json').read_text())
10
+ self.assertEqual(report['source_report_sha256'],
11
+ hashlib.sha256(Path(report['source_report']).read_bytes()).hexdigest())
12
+ self.assertEqual(len(report['probes']), 2)
13
+ for row in report['probes']:
14
+ with self.subTest(engine=row['engine']):
15
+ self.assertEqual(len(row['source']), 90)
16
+ self.assertEqual(row['rust'], row['source'])
17
+
18
+
19
+ if __name__ == '__main__':
20
+ unittest.main()
xtask/checks.tsv CHANGED
@@ -4945,3 +4945,12 @@ edge crates/urt-gameplay/src/world_visibility.rs scripts/analyze_rust_defuse_wor
4945
  edge crates/urt-gameplay/src/spatial_index.rs scripts/analyze_rust_defuse_world_radio.py
4946
  edge crates/urt-gameplay/src/defuse.rs scripts/analyze_rust_defuse_world_radio.py
4947
  edge crates/urt-gameplay/src/bin/urt-defuse.rs scripts/analyze_rust_defuse_world_radio.py
 
 
 
 
 
 
 
 
 
 
4945
  edge crates/urt-gameplay/src/spatial_index.rs scripts/analyze_rust_defuse_world_radio.py
4946
  edge crates/urt-gameplay/src/defuse.rs scripts/analyze_rust_defuse_world_radio.py
4947
  edge crates/urt-gameplay/src/bin/urt-defuse.rs scripts/analyze_rust_defuse_world_radio.py
4948
+ report scripts/analyze_rust_link_bounds.py docs/research/rust-link-bounds.json
4949
+ edge docs/research/rust-link-bounds.json scripts/test_rust_link_bounds.py
4950
+ edge docs/research/link-bounds.json scripts/analyze_rust_link_bounds.py
4951
+ group rust-link-bounds scripts/analyze_rust_link_bounds.py
4952
+ group rust-link-bounds scripts/test_link_bounds.py
4953
+ group rust-link-bounds scripts/analyze_rust_spatial_index.py
4954
+ group gameplay scripts/analyze_rust_link_bounds.py
4955
+ edge crates/urt-gameplay/src/spatial_index.rs scripts/analyze_rust_link_bounds.py
4956
+ edge crates/urt-gameplay/src/bin/urt-spatial-index.rs scripts/analyze_rust_link_bounds.py