use win_shared_memory::{SharedMemoryError, SharedMemoryLink};
use crate::{
bindings::root::ks::{SPageFileGraphicEvo, SPageFilePhysics, SPageFileStaticEvo},
views::{GraphicsView, PhysicsView, StaticView},
};
const STATIC_FILE: &str = "Local\\acevo_pmf_static";
const PHYSICS_FILE: &str = "Local\\acevo_pmf_physics";
const GRAPHICS_FILE: &str = "Local\\acevo_pmf_graphics";
#[derive(Debug)]
pub struct Mapper {
physics_memory: SharedMemoryLink<SPageFilePhysics>,
graphics_memory: SharedMemoryLink<SPageFileGraphicEvo>,
static_memory: SharedMemoryLink<SPageFileStaticEvo>,
}
impl Mapper {
pub fn open() -> Result<Self, SharedMemoryError> {
let output = Self {
static_memory: SharedMemoryLink::open(STATIC_FILE)?,
physics_memory: SharedMemoryLink::open(PHYSICS_FILE)?,
graphics_memory: SharedMemoryLink::open(GRAPHICS_FILE)?,
};
Ok(output)
}
pub fn physics(&self) -> PhysicsView<'_> {
let raw = self.physics_raw();
PhysicsView::borrowed(raw)
}
pub fn graphics(&self) -> GraphicsView<'_> {
let raw = self.graphics_raw();
GraphicsView::borrowed(raw)
}
pub fn static_data(&self) -> StaticView<'_> {
let raw = self.static_data_raw();
StaticView::borrowed(raw)
}
pub fn physics_raw(&self) -> &SPageFilePhysics {
unsafe { self.physics_memory.get() }
}
pub fn graphics_raw(&self) -> &SPageFileGraphicEvo {
unsafe { self.graphics_memory.get() }
}
pub fn static_data_raw(&self) -> &SPageFileStaticEvo {
unsafe { self.static_memory.get() }
}
}