use bevy_app::{App, First, Last, Plugin};
use crate::api::config::AllocConfig;
use crate::api::alloc::SmartAlloc;
use crate::bevy::resource::AllocResource;
use crate::bevy::systems::{begin_frame_system, end_frame_system};
pub struct SmartAllocPlugin {
config: AllocConfig,
}
impl SmartAllocPlugin {
pub fn new(config: AllocConfig) -> Self {
Self { config }
}
pub fn high_performance() -> Self {
Self {
config: AllocConfig::high_performance(),
}
}
pub fn minimal() -> Self {
Self {
config: AllocConfig::minimal(),
}
}
}
impl Default for SmartAllocPlugin {
fn default() -> Self {
Self {
config: AllocConfig::default(),
}
}
}
impl Plugin for SmartAllocPlugin {
fn build(&self, app: &mut App) {
let alloc = SmartAlloc::new(self.config.clone());
app.insert_resource(AllocResource(alloc))
.add_systems(First, begin_frame_system)
.add_systems(Last, end_frame_system);
}
}