use bevy_ecs::system::Resource;
use crate::api::alloc::SmartAlloc;
use crate::api::stats::AllocStats;
#[derive(Resource, Clone)]
pub struct AllocResource(pub SmartAlloc);
impl AllocResource {
pub fn new(alloc: SmartAlloc) -> Self {
Self(alloc)
}
pub fn frame_alloc<T>(&self) -> *mut T {
self.0.frame_alloc::<T>()
}
pub fn pool_alloc<T>(&self) -> *mut T {
self.0.pool_alloc::<T>()
}
pub unsafe fn pool_free<T>(&self, ptr: *mut T) {
self.0.pool_free(ptr);
}
pub fn heap_alloc<T>(&self) -> *mut T {
self.0.heap_alloc::<T>()
}
pub unsafe fn heap_free<T>(&self, ptr: *mut T) {
self.0.heap_free(ptr);
}
pub fn stats(&self) -> AllocStats {
self.0.stats()
}
}
impl std::ops::Deref for AllocResource {
type Target = SmartAlloc;
fn deref(&self) -> &Self::Target {
&self.0
}
}