nmarshall commited on
Commit
8e9a5d3
·
1 Parent(s): c92bd49

gameplay: resolve located defuse radio

Browse files
crates/urt-gameplay/src/bin/support/located_radio.rs ADDED
@@ -0,0 +1,149 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ use urt_gameplay::effect_feedback::{RadioClient, RadioInput};
2
+ use urt_gameplay::location_feedback::{
3
+ DefuseRadioState, LocatedRadioOutput, LocationEntry, LocationInput,
4
+ };
5
+
6
+ pub struct RadioFixture {
7
+ pub entries: Vec<LocationEntry>,
8
+ pub location: LocationInput,
9
+ pub clients: Vec<RadioClient>,
10
+ pub texts: Vec<Vec<u8>>,
11
+ pub state: DefuseRadioState,
12
+ pub input: RadioInput,
13
+ }
14
+
15
+ fn list(v: &[u32]) -> String {
16
+ format!(
17
+ "[{}]",
18
+ v.iter()
19
+ .map(|v| v.to_string())
20
+ .collect::<Vec<_>>()
21
+ .join(",")
22
+ )
23
+ }
24
+ fn hex(v: &[u8]) -> String {
25
+ v.iter().map(|v| format!("{v:02x}")).collect()
26
+ }
27
+ fn optional(v: Option<usize>) -> String {
28
+ v.map(|v| v.to_string()).unwrap_or("null".into())
29
+ }
30
+ fn decode_location(w: &[u32]) -> (Vec<LocationEntry>, LocationInput) {
31
+ assert!(w.len() >= 19);
32
+ let mut pos = 3;
33
+ let mut e = vec![];
34
+ for _ in 0..3 {
35
+ e.push(LocationEntry {
36
+ point: w[pos..pos + 3].try_into().unwrap(),
37
+ trigger: w[pos + 3] != 0,
38
+ visible: w[pos + 4] != 0,
39
+ });
40
+ pos += 5;
41
+ }
42
+ let q = w[pos] as usize;
43
+ pos += 1;
44
+ let query = w[pos..pos + q].iter().map(|v| *v as usize).collect();
45
+ pos += q;
46
+ let n = w[pos] as usize;
47
+ pos += 1;
48
+ let order = w[pos..pos + n].iter().map(|v| *v as usize).collect();
49
+ pos += n;
50
+ assert_eq!(pos, w.len());
51
+ let cache = if w[0] == u32::MAX {
52
+ None
53
+ } else {
54
+ Some(w[0] as usize)
55
+ };
56
+ (
57
+ e,
58
+ LocationInput {
59
+ actor: [0; 3],
60
+ cache,
61
+ expiry: w[1],
62
+ tick: w[2],
63
+ query,
64
+ order,
65
+ },
66
+ )
67
+ }
68
+
69
+ fn commands(v: &[(usize, Vec<u8>)]) -> String {
70
+ v.iter()
71
+ .map(|(slot, text)| format!(r#"{{"slot":{},"text":"{}"}}"#, slot, hex(text)))
72
+ .collect::<Vec<_>>()
73
+ .join(",")
74
+ }
75
+ pub fn decode_radio(w: &[u32]) -> RadioFixture {
76
+ let n = w[0] as usize;
77
+ let (e, l) = decode_location(&w[1..1 + n]);
78
+ let r = &w[1 + n..];
79
+ let payload_len = r[9] as usize;
80
+ assert_eq!(r.len(), 10 + payload_len + 2 * (r[4] as usize).max(3));
81
+ let payload = r[10..10 + payload_len]
82
+ .iter()
83
+ .map(|v| *v as u8)
84
+ .collect::<Vec<_>>();
85
+ let clients = r[10 + payload_len..]
86
+ .chunks_exact(2)
87
+ .map(|c| urt_gameplay::effect_feedback::RadioClient {
88
+ connection: c[0],
89
+ team: c[1],
90
+ })
91
+ .collect::<Vec<_>>();
92
+ let marker = if r[7] != 0 {
93
+ Some(urt_gameplay::effect_feedback::RadioMarker {
94
+ deadline: 17,
95
+ active: 18,
96
+ })
97
+ } else {
98
+ None
99
+ };
100
+ let state = DefuseRadioState { marker, ring: r[8] };
101
+ let input = urt_gameplay::effect_feedback::RadioInput {
102
+ mode: r[0],
103
+ follow: r[1],
104
+ health: r[2],
105
+ team: r[3],
106
+ count: r[4] as usize,
107
+ tick: r[5],
108
+ code: r[6],
109
+ slot: 2,
110
+ success: false,
111
+ payload: vec![],
112
+ };
113
+ RadioFixture {
114
+ entries: e,
115
+ location: l,
116
+ clients,
117
+ texts: vec![payload; 3],
118
+ state,
119
+ input,
120
+ }
121
+ }
122
+
123
+ pub fn radio_fields(out: LocatedRadioOutput, state: &DefuseRadioState) -> String {
124
+ let (selected, bounds, pvs) = if let Some(l) = out.location {
125
+ (l.selected, l.queries, l.pvs)
126
+ } else {
127
+ (None, vec![], vec![])
128
+ };
129
+ let bounds = bounds
130
+ .iter()
131
+ .map(|b| format!("[{},{}]", list(&b[0]), list(&b[1])))
132
+ .collect::<Vec<_>>()
133
+ .join(",");
134
+ let m = state
135
+ .marker
136
+ .map(|m| [m.deadline, m.active])
137
+ .unwrap_or([17, 18]);
138
+ format!(
139
+ r#"{{"commands":[{}],"getter_calls":{},"marker":{},"ring":{},"location_result":{},"location_queries":[{}],"location_pvs":{},"warnings":{}}}"#,
140
+ commands(&out.radio.commands),
141
+ out.radio.getter_calls,
142
+ list(&m),
143
+ state.ring,
144
+ optional(selected),
145
+ bounds,
146
+ list(&pvs.iter().map(|v| *v as u32).collect::<Vec<_>>()),
147
+ out.warnings
148
+ )
149
+ }
crates/urt-gameplay/src/bin/urt-defuse.rs CHANGED
@@ -1,9 +1,15 @@
1
  #[path = "support/entity_pool.rs"]
2
  mod entity_pool;
3
 
 
 
 
4
  use entity_pool::{allocation_fields, decode_pool, record};
5
  use urt_gameplay::defuse::*;
6
- use urt_gameplay::location_feedback::process_allocated_defuse;
 
 
 
7
  fn list(v: &[u32]) -> String {
8
  format!(
9
  "[{}]",
@@ -94,6 +100,7 @@ fn main() {
94
  }
95
  "full" => println!("{}", full(&w)),
96
  "allocated-full" => println!("{}", allocated_full(&w)),
 
97
  "sequence" => println!("{}", sequence(&w)),
98
  _ => panic!("unknown policy"),
99
  }
@@ -233,12 +240,71 @@ fn allocated_full(w: &[u32]) -> String {
233
  for index in [64, 65, 66] {
234
  pool.slots[index].words[424 / 4] = w[31];
235
  }
236
- let (mut routing, allocated) =
237
  process_allocated_defuse(&mut world, &mut pool, input, start).unwrap();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
238
  let Some(allocated) = allocated else {
239
  return format!(
240
  r#"{{{},"allocation":null,"record":null,"links":[]}}"#,
241
- full_fields(world.state, &routing, FIXTURE_GUARDS)
242
  );
243
  };
244
  let link = allocated.link.unwrap();
@@ -258,8 +324,8 @@ fn allocated_full(w: &[u32]) -> String {
258
  pool.slots[slot] = allocated.initialized.unwrap();
259
  format!(
260
  r#"{{{},"allocation":{{{}}},"record":{},"links":[{{"slot":{},"payload":{},"flags":{}}}]}}"#,
261
- full_fields(world.state, &routing, guards),
262
- allocation_fields(&pool, &allocated.allocation),
263
  final_fields,
264
  slot,
265
  link.record.words[184 / 4],
 
1
  #[path = "support/entity_pool.rs"]
2
  mod entity_pool;
3
 
4
+ #[path = "support/located_radio.rs"]
5
+ mod radio_fixture;
6
+
7
  use entity_pool::{allocation_fields, decode_pool, record};
8
  use urt_gameplay::defuse::*;
9
+ use urt_gameplay::location_feedback::{
10
+ DefuseAllocation, DefuseRadioContext, EntityPool, process_allocated_defuse,
11
+ process_located_defuse,
12
+ };
13
  fn list(v: &[u32]) -> String {
14
  format!(
15
  "[{}]",
 
100
  }
101
  "full" => println!("{}", full(&w)),
102
  "allocated-full" => println!("{}", allocated_full(&w)),
103
+ "located-full" => println!("{}", located_full(&w)),
104
  "sequence" => println!("{}", sequence(&w)),
105
  _ => panic!("unknown policy"),
106
  }
 
240
  for index in [64, 65, 66] {
241
  pool.slots[index].words[424 / 4] = w[31];
242
  }
243
+ let (routing, allocated) =
244
  process_allocated_defuse(&mut world, &mut pool, input, start).unwrap();
245
+ allocated_fields(world.state, routing, allocated, &mut pool)
246
+ }
247
+
248
+ fn located_full(w: &[u32]) -> String {
249
+ let (mut world, input) = decode_full(&w[..31]);
250
+ let pool_len = w[32] as usize;
251
+ let (mut pool, _, start) = decode_pool(&w[33..33 + pool_len]);
252
+ for index in [64, 65, 66] {
253
+ pool.slots[index].words[424 / 4] = w[31];
254
+ }
255
+ let mut fixture = radio_fixture::decode_radio(&w[33 + pool_len..]);
256
+ let mut outcome = process_located_defuse(
257
+ &mut world,
258
+ &mut pool,
259
+ input,
260
+ start,
261
+ &mut fixture.state,
262
+ DefuseRadioContext {
263
+ mode: fixture.input.mode,
264
+ clients: &fixture.clients,
265
+ entries: &fixture.entries,
266
+ location: &fixture.location,
267
+ texts: &fixture.texts,
268
+ },
269
+ )
270
+ .unwrap();
271
+ let radio = outcome
272
+ .radio
273
+ .map(|plan| {
274
+ let allocation = outcome.allocation.as_mut().expect("radio follows an event");
275
+ assert!(allocation.after_allocation.is_empty());
276
+ allocation.after_allocation.push(DefuseEffect::Sound {
277
+ slot: plan.slot,
278
+ sound: plan.code,
279
+ });
280
+ radio_fixture::radio_fields(plan.output, &fixture.state)
281
+ })
282
+ .unwrap_or_default();
283
+ let marker = fixture
284
+ .state
285
+ .marker
286
+ .map(|m| [m.deadline, m.active])
287
+ .unwrap_or([17, 18]);
288
+ let base = allocated_fields(world.state, outcome.routing, outcome.allocation, &mut pool);
289
+ format!(
290
+ r#"{},"radio":[{}],"ring":{},"marker":{}}}"#,
291
+ base.strip_suffix('}').unwrap(),
292
+ radio,
293
+ fixture.state.ring,
294
+ list(&marker)
295
+ )
296
+ }
297
+
298
+ fn allocated_fields(
299
+ state: DefuseState,
300
+ mut routing: DefuseOutcome,
301
+ allocated: Option<DefuseAllocation>,
302
+ pool: &mut EntityPool,
303
+ ) -> String {
304
  let Some(allocated) = allocated else {
305
  return format!(
306
  r#"{{{},"allocation":null,"record":null,"links":[]}}"#,
307
+ full_fields(state, &routing, FIXTURE_GUARDS)
308
  );
309
  };
310
  let link = allocated.link.unwrap();
 
324
  pool.slots[slot] = allocated.initialized.unwrap();
325
  format!(
326
  r#"{{{},"allocation":{{{}}},"record":{},"links":[{{"slot":{},"payload":{},"flags":{}}}]}}"#,
327
+ full_fields(state, &routing, guards),
328
+ allocation_fields(pool, &allocated.allocation),
329
  final_fields,
330
  slot,
331
  link.record.words[184 / 4],
crates/urt-gameplay/src/bin/urt-location-feedback.rs CHANGED
@@ -1,5 +1,7 @@
1
  #[path = "support/entity_pool.rs"]
2
  mod entity_pool;
 
 
3
  use entity_pool::{allocation_fields, decode_pool, record};
4
  use urt_gameplay::location_feedback::*;
5
  fn list(v: &[u32]) -> String {
@@ -108,121 +110,19 @@ fn text(w: &[u32]) -> String {
108
  )
109
  }
110
 
111
- fn decode_location(w: &[u32]) -> (Vec<LocationEntry>, LocationInput) {
112
- assert!(w.len() >= 19);
113
- let mut pos = 3;
114
- let mut e = vec![];
115
- for _ in 0..3 {
116
- e.push(LocationEntry {
117
- point: w[pos..pos + 3].try_into().unwrap(),
118
- trigger: w[pos + 3] != 0,
119
- visible: w[pos + 4] != 0,
120
- });
121
- pos += 5;
122
- }
123
- let q = w[pos] as usize;
124
- pos += 1;
125
- let query = w[pos..pos + q].iter().map(|v| *v as usize).collect();
126
- pos += q;
127
- let n = w[pos] as usize;
128
- pos += 1;
129
- let order = w[pos..pos + n].iter().map(|v| *v as usize).collect();
130
- pos += n;
131
- assert_eq!(pos, w.len());
132
- let cache = if w[0] == u32::MAX {
133
- None
134
- } else {
135
- Some(w[0] as usize)
136
- };
137
- (
138
- e,
139
- LocationInput {
140
- actor: [0; 3],
141
- cache,
142
- expiry: w[1],
143
- tick: w[2],
144
- query,
145
- order,
146
- },
147
- )
148
- }
149
-
150
- fn commands(v: &[(usize, Vec<u8>)]) -> String {
151
- v.iter()
152
- .map(|(slot, text)| format!(r#"{{"slot":{},"text":"{}"}}"#, slot, hex(text)))
153
- .collect::<Vec<_>>()
154
- .join(",")
155
- }
156
  fn radio(w: &[u32]) -> String {
157
- let n = w[0] as usize;
158
- let (e, l) = decode_location(&w[1..1 + n]);
159
- let r = &w[1 + n..];
160
- let payload_len = r[9] as usize;
161
- assert_eq!(r.len(), 10 + payload_len + 2 * (r[4] as usize).max(3));
162
- let payload = r[10..10 + payload_len]
163
- .iter()
164
- .map(|v| *v as u8)
165
- .collect::<Vec<_>>();
166
- let clients = r[10 + payload_len..]
167
- .chunks_exact(2)
168
- .map(|c| urt_gameplay::effect_feedback::RadioClient {
169
- connection: c[0],
170
- team: c[1],
171
- })
172
- .collect::<Vec<_>>();
173
- let mut marker = if r[7] != 0 {
174
- Some(urt_gameplay::effect_feedback::RadioMarker {
175
- deadline: 17,
176
- active: 18,
177
- })
178
- } else {
179
- None
180
- };
181
- let mut ring = r[8];
182
- let input = urt_gameplay::effect_feedback::RadioInput {
183
- mode: r[0],
184
- follow: r[1],
185
- health: r[2],
186
- team: r[3],
187
- count: r[4] as usize,
188
- tick: r[5],
189
- code: r[6],
190
- slot: 2,
191
- success: false,
192
- payload: vec![],
193
- };
194
  let out = located_radio(
195
- &mut marker,
196
- &mut ring,
197
- &clients,
198
- &input,
199
- &e,
200
- &l,
201
- &vec![payload; 3],
202
  )
203
  .unwrap();
204
- let (selected, bounds, pvs) = if let Some(l) = out.location {
205
- (l.selected, l.queries, l.pvs)
206
- } else {
207
- (None, vec![], vec![])
208
- };
209
- let bounds = bounds
210
- .iter()
211
- .map(|b| format!("[{},{}]", list(&b[0]), list(&b[1])))
212
- .collect::<Vec<_>>()
213
- .join(",");
214
- let m = marker.map(|m| [m.deadline, m.active]).unwrap_or([17, 18]);
215
- format!(
216
- r#"{{"commands":[{}],"getter_calls":{},"marker":{},"ring":{},"location_result":{},"location_queries":[{}],"location_pvs":{},"warnings":{}}}"#,
217
- commands(&out.radio.commands),
218
- out.radio.getter_calls,
219
- list(&m),
220
- ring,
221
- optional(selected),
222
- bounds,
223
- list(&pvs.iter().map(|v| *v as u32).collect::<Vec<_>>()),
224
- out.warnings
225
- )
226
  }
227
  fn allocation(w: &[u32]) -> String {
228
  let (mut pool, tick, start) = decode_pool(w);
 
1
  #[path = "support/entity_pool.rs"]
2
  mod entity_pool;
3
+ #[path = "support/located_radio.rs"]
4
+ mod radio_fixture;
5
  use entity_pool::{allocation_fields, decode_pool, record};
6
  use urt_gameplay::location_feedback::*;
7
  fn list(v: &[u32]) -> String {
 
110
  )
111
  }
112
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
113
  fn radio(w: &[u32]) -> String {
114
+ let mut fixture = radio_fixture::decode_radio(w);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115
  let out = located_radio(
116
+ &mut fixture.state.marker,
117
+ &mut fixture.state.ring,
118
+ &fixture.clients,
119
+ &fixture.input,
120
+ &fixture.entries,
121
+ &fixture.location,
122
+ &fixture.texts,
123
  )
124
  .unwrap();
125
+ radio_fixture::radio_fields(out, &fixture.state)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
126
  }
127
  fn allocation(w: &[u32]) -> String {
128
  let (mut pool, tick, start) = decode_pool(w);
crates/urt-gameplay/src/location_feedback.rs CHANGED
@@ -601,6 +601,122 @@ pub fn process_allocated_defuse(
601
  })
602
  }
603
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
604
  /// Resolve event allocation for a reached defuse branch. Pending diagnostic
605
  /// and fatal outcomes commit the observed caller and allocator prefix. Typed
606
  /// errors leave the supplied state untouched. Native effects remain plans.
@@ -612,6 +728,20 @@ pub fn allocate_defuse_branch(
612
  start: u32,
613
  origin: [u32; 3],
614
  ) -> Result<Option<DefuseAllocation>, Error> {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
615
  use crate::defuse::{DefuseEffect, begin_defuse, cancel_defuse, finish_defuse};
616
 
617
  let mut caller = *state;
@@ -653,16 +783,17 @@ pub fn allocate_defuse_branch(
653
  after_allocation.clear();
654
  (None, None)
655
  };
656
- *state = caller;
657
- *pool = next_pool;
658
- Ok(Some(DefuseAllocation {
659
  event_kind,
660
  allocation,
661
  initialized,
662
  link,
663
  before_allocation: effects,
664
  after_allocation,
665
- }))
 
 
 
666
  }
667
 
668
  fn construct_event(
 
601
  })
602
  }
603
 
604
+ /// Mutable state shared by located radio calls within a level.
605
+ #[derive(Clone, Copy, Debug, PartialEq, Eq)]
606
+ pub struct DefuseRadioState {
607
+ pub marker: Option<crate::effect_feedback::RadioMarker>,
608
+ pub ring: u32,
609
+ }
610
+
611
+ /// Native recipient and spatial observations supplied to a defuse radio call.
612
+ pub struct DefuseRadioContext<'a> {
613
+ pub mode: u32,
614
+ pub clients: &'a [crate::effect_feedback::RadioClient],
615
+ pub entries: &'a [LocationEntry],
616
+ pub location: &'a LocationInput,
617
+ pub texts: &'a [Vec<u8>],
618
+ }
619
+
620
+ #[derive(Clone, Debug, PartialEq, Eq)]
621
+ pub struct DefuseRadioPlan {
622
+ pub slot: i32,
623
+ pub code: u32,
624
+ pub output: LocatedRadioOutput,
625
+ }
626
+
627
+ #[derive(Clone, Debug, Default, PartialEq, Eq)]
628
+ pub struct LocatedDefuseOutcome {
629
+ pub routing: crate::defuse::DefuseOutcome,
630
+ pub allocation: Option<DefuseAllocation>,
631
+ pub radio: Option<DefuseRadioPlan>,
632
+ }
633
+
634
+ /// Resolve the radio effect after successful event construction. The returned
635
+ /// allocation keeps only the effects still needing dispatch. Invalid typed
636
+ /// input leaves the caller, pool, and radio state untouched.
637
+ pub fn process_located_defuse(
638
+ world: &mut crate::defuse::DefuseWorld,
639
+ pool: &mut EntityPool,
640
+ input: crate::defuse::FullDefuseInput,
641
+ level_start: u32,
642
+ radio_state: &mut DefuseRadioState,
643
+ context: DefuseRadioContext<'_>,
644
+ ) -> Result<LocatedDefuseOutcome, Error> {
645
+ use crate::defuse::DefuseEffect;
646
+ use crate::effect_feedback::RadioInput;
647
+
648
+ let actor = world.clients.get(input.base.slot as usize).copied();
649
+ let actor_point = world.actor_point;
650
+ let mut feedback = *radio_state;
651
+ let (routing, result) =
652
+ crate::defuse::process_defuse_with(world, input, |state, base, cancel, origin| {
653
+ let branch = if cancel {
654
+ DefuseBranch::Cancel
655
+ } else {
656
+ DefuseBranch::Finish
657
+ };
658
+ allocate_defuse_with(
659
+ state,
660
+ pool,
661
+ base,
662
+ branch,
663
+ level_start,
664
+ origin,
665
+ |mut outcome| {
666
+ let radio = if let [DefuseEffect::Sound { slot, sound }] =
667
+ outcome.after_allocation.as_slice()
668
+ {
669
+ let actor = actor.ok_or(Error::InvalidIndex)?;
670
+ let mut location = context.location.clone();
671
+ location.actor = actor_point;
672
+ location.tick = base.tick;
673
+ let input = RadioInput {
674
+ follow: actor.follow,
675
+ health: actor.health,
676
+ team: actor.team,
677
+ slot: *slot,
678
+ mode: context.mode,
679
+ count: input.count,
680
+ tick: base.tick,
681
+ code: *sound,
682
+ success: false,
683
+ payload: Vec::new(),
684
+ };
685
+ let output = located_radio(
686
+ &mut feedback.marker,
687
+ &mut feedback.ring,
688
+ context.clients,
689
+ &input,
690
+ context.entries,
691
+ &location,
692
+ context.texts,
693
+ )?;
694
+ let plan = DefuseRadioPlan {
695
+ slot: *slot,
696
+ code: *sound,
697
+ output,
698
+ };
699
+ outcome.after_allocation.clear();
700
+ Some(plan)
701
+ } else {
702
+ None
703
+ };
704
+ Ok((outcome, radio))
705
+ },
706
+ )
707
+ })?;
708
+ let (allocation, radio) = match result {
709
+ Some((allocation, radio)) => (Some(allocation), radio),
710
+ None => (None, None),
711
+ };
712
+ *radio_state = feedback;
713
+ Ok(LocatedDefuseOutcome {
714
+ routing,
715
+ allocation,
716
+ radio,
717
+ })
718
+ }
719
+
720
  /// Resolve event allocation for a reached defuse branch. Pending diagnostic
721
  /// and fatal outcomes commit the observed caller and allocator prefix. Typed
722
  /// errors leave the supplied state untouched. Native effects remain plans.
 
728
  start: u32,
729
  origin: [u32; 3],
730
  ) -> Result<Option<DefuseAllocation>, Error> {
731
+ allocate_defuse_with(state, pool, input, branch, start, origin, |outcome| {
732
+ Ok(outcome)
733
+ })
734
+ }
735
+
736
+ fn allocate_defuse_with<T>(
737
+ state: &mut crate::defuse::DefuseState,
738
+ pool: &mut EntityPool,
739
+ input: crate::defuse::DefuseInput,
740
+ branch: DefuseBranch,
741
+ start: u32,
742
+ origin: [u32; 3],
743
+ resolve: impl FnOnce(DefuseAllocation) -> Result<T, Error>,
744
+ ) -> Result<Option<T>, Error> {
745
  use crate::defuse::{DefuseEffect, begin_defuse, cancel_defuse, finish_defuse};
746
 
747
  let mut caller = *state;
 
783
  after_allocation.clear();
784
  (None, None)
785
  };
786
+ let result = resolve(DefuseAllocation {
 
 
787
  event_kind,
788
  allocation,
789
  initialized,
790
  link,
791
  before_allocation: effects,
792
  after_allocation,
793
+ })?;
794
+ *state = caller;
795
+ *pool = next_pool;
796
+ Ok(Some(result))
797
  }
798
 
799
  fn construct_event(
docs/FINDINGS.md CHANGED
@@ -2041,3 +2041,5 @@ RE-1034–1043 batch validation passed:2,018 Python tests,339 Rust tests,146 det
2041
  - The Rust callback exposes a link-time record snapshot and retains the final event in the pool. [Allocated defuse parity](research/RUST_DEFUSE_ALLOCATED_CALLBACK.md).
2042
 
2043
  - Allocated defuse starts run located radio after event construction. Other tested callback branches preserve marker and formatter ring state. [Located callback trace](research/QVM_DEFUSE_LOCATED_CALLBACK.md).
 
 
 
2041
  - The Rust callback exposes a link-time record snapshot and retains the final event in the pool. [Allocated defuse parity](research/RUST_DEFUSE_ALLOCATED_CALLBACK.md).
2042
 
2043
  - Allocated defuse starts run located radio after event construction. Other tested callback branches preserve marker and formatter ring state. [Located callback trace](research/QVM_DEFUSE_LOCATED_CALLBACK.md).
2044
+
2045
+ - The Rust allocated callback resolves its radio effect into ordered commands, marker updates and formatter ring state. [Rust located callback parity](research/RUST_DEFUSE_LOCATED_CALLBACK.md).
docs/PROVISIONAL_TODO.md CHANGED
@@ -2103,3 +2103,5 @@ RE-974–983 completed routing, command rewrite, inactivity, movement-parameter
2103
  - [x] RE-1047 Port the full allocated defuse callback and its link-time snapshot ([evidence](research/RUST_DEFUSE_ALLOCATED_CALLBACK.md)).
2104
 
2105
  - [x] RE-1048 Trace located radio within the allocated defuse callback ([evidence](research/QVM_DEFUSE_LOCATED_CALLBACK.md)).
 
 
 
2103
  - [x] RE-1047 Port the full allocated defuse callback and its link-time snapshot ([evidence](research/RUST_DEFUSE_ALLOCATED_CALLBACK.md)).
2104
 
2105
  - [x] RE-1048 Trace located radio within the allocated defuse callback ([evidence](research/QVM_DEFUSE_LOCATED_CALLBACK.md)).
2106
+
2107
+ - [x] RE-1049 Compose allocated defuse and located radio in Rust ([evidence](research/RUST_DEFUSE_LOCATED_CALLBACK.md)).
docs/RESEARCH_LEDGER.md CHANGED
@@ -2867,3 +2867,7 @@ Rust shares existing callback routing and matches all 39 source cases with actua
2867
  ## 2026-11-25 — RE-1048 Trace located radio within the allocated defuse callback
2868
 
2869
  Forty-eight cases compose successful defuse allocation with location selection and radio formatting. Sixteen starts execute radio. Cached, expired, trigger and missing locations cover warning, command, formatter ring and marker observations. See [located callback findings](research/QVM_DEFUSE_LOCATED_CALLBACK.md).
 
 
 
 
 
2867
  ## 2026-11-25 — RE-1048 Trace located radio within the allocated defuse callback
2868
 
2869
  Forty-eight cases compose successful defuse allocation with location selection and radio formatting. Sixteen starts execute radio. Cached, expired, trigger and missing locations cover warning, command, formatter ring and marker observations. See [located callback findings](research/QVM_DEFUSE_LOCATED_CALLBACK.md).
2870
+
2871
+ ## 2026-11-25 — RE-1049 Compose allocated defuse and located radio in Rust
2872
+
2873
+ The Rust callback resolves the returned event's radio plan using actor state and supplied engine observations. It matches all 48 source cases, including unaffected radio state outside successful starts. See [the parity notes](research/RUST_DEFUSE_LOCATED_CALLBACK.md).
docs/research/QVM_LOCATION_ALLOCATION_BATCH.md CHANGED
@@ -77,3 +77,5 @@ RE-1046 combines successful allocation and event construction with [the full sou
77
  RE-1047 matches the 39 source fixtures in [the full Rust callback](RUST_DEFUSE_ALLOCATED_CALLBACK.md). Native link adapters can now consume the record snapshot separately from the final pool contents.
78
 
79
  RE-1048 follows [located radio within the allocated callback](QVM_DEFUSE_LOCATED_CALLBACK.md) with separate bomb and location identities. The source verifies formatting and marker state alongside the existing pool and event results.
 
 
 
77
  RE-1047 matches the 39 source fixtures in [the full Rust callback](RUST_DEFUSE_ALLOCATED_CALLBACK.md). Native link adapters can now consume the record snapshot separately from the final pool contents.
78
 
79
  RE-1048 follows [located radio within the allocated callback](QVM_DEFUSE_LOCATED_CALLBACK.md) with separate bomb and location identities. The source verifies formatting and marker state alongside the existing pool and event results.
80
+
81
+ RE-1049 matches all 48 source fixtures in [the Rust located callback](RUST_DEFUSE_LOCATED_CALLBACK.md), preserving the link snapshot and resolving the start's radio before returning its command plan.
docs/research/README.md CHANGED
@@ -1669,3 +1669,5 @@ The extension collector adds five focused tests for native tail calls, command-r
1669
  - [Allocated defuse callback in Rust](RUST_DEFUSE_ALLOCATED_CALLBACK.md)
1670
 
1671
  - [Located radio in the full defuse callback](QVM_DEFUSE_LOCATED_CALLBACK.md)
 
 
 
1669
  - [Allocated defuse callback in Rust](RUST_DEFUSE_ALLOCATED_CALLBACK.md)
1670
 
1671
  - [Located radio in the full defuse callback](QVM_DEFUSE_LOCATED_CALLBACK.md)
1672
+
1673
+ - [Located radio in the Rust defuse callback](RUST_DEFUSE_LOCATED_CALLBACK.md)
docs/research/RUST_DEFUSE_LOCATED_CALLBACK.md ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ # Located radio in the Rust defuse callback
2
+
3
+ `process_located_defuse` resolves the start's radio effect after a successful event allocation. It uses the actor's health, team, position and tick from the defuse world. The caller supplies the recipient table and observations for box queries and PVS. The resolved radio plan carries native send requests and location observations. The allocator result excludes the radio effect that the adapter already resolved.
4
+
5
+ The [parity report](rust-defuse-located-callback.json) matches all 48 source cases across event construction, link snapshots, clipping, command bytes, markers and ring counters. A terminal allocation yields no radio plan. Typed radio errors leave the supplied state and pool untouched. Diagnostic and fatal execution, registration, linking and sending remain engine boundaries.
docs/research/rust-defuse-located-callback.json ADDED
The diff for this file is too large to render. See raw diff
 
scripts/analyze_rust_defuse_located_callback.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Compare the allocated Rust defuse callback with its full source traces."""
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 analyze_rust_defuse_complete import encode as encode_callback
10
+ from analyze_rust_location_allocation import encode as encode_pool
11
+ from analyze_rust_location_radio import encode as encode_radio
12
+ from rust_lifecycle_support import result
13
+
14
+
15
+ def main():
16
+ subprocess.run(['cargo', 'build', '--offline', '--package', 'urt-gameplay',
17
+ '--bin', 'urt-defuse'], check=True)
18
+ binary = Path(os.environ.get('CARGO_TARGET_DIR', 'target')) / 'debug' / 'urt-defuse'
19
+ path = Path('docs/research/qvm-defuse-located-callback.json')
20
+ data = path.read_bytes()
21
+ probes = []
22
+ for row in json.loads(data)['probes']:
23
+ a = row['input']
24
+ expected = {key: value for key, value in row.items() if key not in ('input', 'execution')}
25
+ pool = encode_pool(a['allocation'])
26
+ args = [*encode_callback(a), a['event_flags'], len(pool), *pool, *encode_radio(a['radio'])]
27
+ probes.append(dict(input=a, source=expected, rust=result(binary, 'located-full', args)))
28
+ write_json(Path('docs/research/rust-defuse-located-callback.json'), {
29
+ 'source_report': str(path), 'source_report_sha256': hashlib.sha256(data).hexdigest(),
30
+ 'probes': probes, 'limits': 'Fixed-pool callback and located radio parity. Native effects remain plans.',
31
+ })
32
+
33
+
34
+ if __name__ == '__main__':
35
+ main()
scripts/test_rust_defuse_located_callback.py ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import hashlib
2
+ import json
3
+ import unittest
4
+ from pathlib import Path
5
+
6
+
7
+ class DefuseLocatedCallbackParity(unittest.TestCase):
8
+ def test_located_callback(self):
9
+ report = json.loads(Path('docs/research/rust-defuse-located-callback.json').read_text())
10
+ digest = hashlib.sha256(Path(report['source_report']).read_bytes()).hexdigest()
11
+ self.assertEqual(report['source_report_sha256'], digest)
12
+ self.assertEqual(len(report['probes']), 48)
13
+ for row in report['probes']:
14
+ with self.subTest(input=row['input']):
15
+ self.assertEqual(row['source'], row['rust'])
16
+
17
+
18
+ if __name__ == '__main__':
19
+ unittest.main()
xtask/checks.tsv CHANGED
@@ -4785,3 +4785,20 @@ edge docs/research/qvm-defuse-allocated-callback.json scripts/test_qvm_defuse_lo
4785
  group qvm-defuse-located-callback scripts/analyze_qvm_defuse_located_callback.py
4786
  group qvm-defuse-located-callback scripts/analyze_qvm_location_radio.py
4787
  edge scripts/analyze_qvm_defuse_located_callback.py scripts/analyze_qvm_resumer_audit.py
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4785
  group qvm-defuse-located-callback scripts/analyze_qvm_defuse_located_callback.py
4786
  group qvm-defuse-located-callback scripts/analyze_qvm_location_radio.py
4787
  edge scripts/analyze_qvm_defuse_located_callback.py scripts/analyze_qvm_resumer_audit.py
4788
+ report scripts/analyze_rust_defuse_located_callback.py docs/research/rust-defuse-located-callback.json
4789
+ edge docs/research/rust-defuse-located-callback.json scripts/test_rust_defuse_located_callback.py
4790
+ group rust-defuse-located-callback scripts/analyze_rust_defuse_located_callback.py
4791
+ group rust-defuse-located-callback scripts/analyze_rust_defuse_allocated_callback.py
4792
+ group rust-defuse-located-callback scripts/analyze_rust_location_radio.py
4793
+ group gameplay scripts/analyze_rust_defuse_located_callback.py
4794
+ edge docs/research/qvm-defuse-located-callback.json scripts/analyze_rust_defuse_located_callback.py
4795
+ edge crates/urt-gameplay/src/defuse.rs scripts/analyze_rust_defuse_located_callback.py
4796
+ edge crates/urt-gameplay/src/location_feedback.rs scripts/analyze_rust_defuse_located_callback.py
4797
+ edge crates/urt-gameplay/src/move_callbacks.rs scripts/analyze_rust_defuse_located_callback.py
4798
+ edge crates/urt-gameplay/src/transition.rs scripts/analyze_rust_defuse_located_callback.py
4799
+ edge crates/urt-gameplay/src/effect_feedback.rs scripts/analyze_rust_defuse_located_callback.py
4800
+ edge crates/urt-gameplay/src/qvm_format.rs scripts/analyze_rust_defuse_located_callback.py
4801
+ edge crates/urt-gameplay/src/bin/urt-defuse.rs scripts/analyze_rust_defuse_located_callback.py
4802
+ edge crates/urt-gameplay/src/bin/support/entity_pool.rs scripts/analyze_rust_defuse_located_callback.py
4803
+ edge crates/urt-gameplay/src/bin/support/located_radio.rs scripts/analyze_rust_defuse_located_callback.py
4804
+ edge crates/urt-gameplay/src/bin/support/located_radio.rs scripts/analyze_rust_location_radio.py