use xplane_sys::{XPLMDestroyInstance, XPLMDrawInfo_t, XPLMInstanceRef, XPLMInstanceSetPosition};
use crate::NoSendSync;
#[derive(Debug, Clone, Copy)]
pub struct Position {
pub x: f32,
pub y: f32,
pub z: f32,
pub pitch: f32,
pub hdg: f32,
pub roll: f32,
}
pub struct Instance<const NUM_DATAREFS: usize> {
pub(crate) handle: XPLMInstanceRef,
pub(crate) _phantom: NoSendSync,
}
impl<const NUM_DATAREFS: usize> Instance<NUM_DATAREFS> {
#[allow(clippy::cast_possible_truncation, clippy::cast_possible_wrap)]
pub fn set_position(&mut self, pos: Position, datarefs: &[f32; NUM_DATAREFS]) {
let draw_info = XPLMDrawInfo_t {
structSize: std::mem::size_of::<XPLMDrawInfo_t>() as i32,
x: pos.x,
y: pos.y,
z: pos.z,
pitch: pos.pitch,
heading: pos.hdg,
roll: pos.roll,
};
let datarefs: *const [f32] = datarefs;
let datarefs: *const f32 = (datarefs).cast::<f32>();
unsafe {
XPLMInstanceSetPosition(self.handle, &draw_info, datarefs);
}
}
}
impl<const NUM_DATAREFS: usize> Drop for Instance<NUM_DATAREFS> {
fn drop(&mut self) {
unsafe {
XPLMDestroyInstance(self.handle);
}
}
}