spring_ai_rs/ai_interface/callback/
trace.rs1use std::error::Error;
2
3use spring_ai_sys::COMMAND_TO_ID_ENGINE;
4
5use crate::ai_interface::{
6 callback::{
7 command::{
8 command_data::{
9 trace::{FeatureTraceRayCommandData, TraceRayCommandData},
10 CommandData,
11 },
12 command_topic::CommandTopic,
13 },
14 engine::handle_command,
15 feature::Feature,
16 unit::Unit,
17 },
18 AIInterface,
19};
20
21pub struct Trace {
22 ai_id: i32,
23}
24
25impl AIInterface {
26 fn trace(&self) -> Trace {
27 Trace { ai_id: self.ai_id }
28 }
29}
30
31impl Trace {
32 pub fn ray(
33 &self,
34 position: [f32; 3],
35 direction: [f32; 3],
36 length: f32,
37 source_unit_id: i32,
38 flags: i32,
39 ) -> Result<Unit, Box<dyn Error>> {
40 let mut command_c_data = TraceRayCommandData {
41 ray_position: position,
42 ray_direction: direction,
43 ray_length: length,
44 source_unit_id,
45 flags,
46 }
47 .c_data();
48
49 handle_command(
50 self.ai_id,
51 COMMAND_TO_ID_ENGINE,
52 -1,
53 CommandTopic::TraceRay.into(),
54 &mut command_c_data,
55 )?;
56
57 Ok(Unit {
58 ai_id: self.ai_id,
59 unit_id: command_c_data.ret_hitUnitId,
60 })
61 }
62
63 pub fn feature_ray(
64 &self,
65 position: [f32; 3],
66 direction: [f32; 3],
67 length: f32,
68 source_unit_id: i32,
69 flags: i32,
70 ) -> Result<Feature, Box<dyn Error>> {
71 let mut command_c_data = FeatureTraceRayCommandData {
72 ray_position: position,
73 ray_direction: direction,
74 ray_length: length,
75 source_unit_id,
76 flags,
77 }
78 .c_data();
79
80 handle_command(
81 self.ai_id,
82 COMMAND_TO_ID_ENGINE,
83 -1,
84 CommandTopic::TraceRayFeature.into(),
85 &mut command_c_data,
86 )?;
87
88 Ok(Feature {
89 ai_id: self.ai_id,
90 feature_id: command_c_data.ret_hitFeatureId,
91 })
92 }
93}