pub use super::allocator::Allocator;
use crate::AIndexSet;
pub struct Atlas {
pub allocator: Allocator,
pub allocated: AIndexSet<usize>,
pub migrating: bool,
}
impl Atlas {
pub fn new(size: u32) -> Self {
Self {
allocator: Allocator::new(size),
allocated: AIndexSet::default(),
migrating: false,
}
}
pub fn allocate(
&mut self,
width: u32,
height: u32,
) -> Option<guillotiere::Allocation> {
self.allocator.allocate(width, height)
}
pub fn insert_index(&mut self, index: usize) {
self.allocated.insert(index);
}
pub fn clear(&mut self) {
self.allocator.clear();
self.allocated.clear();
self.migrating = false;
}
pub fn deallocate(
&mut self,
index: usize,
allocation: guillotiere::Allocation,
) {
self.allocated.swap_remove(&index);
self.allocator.deallocate(allocation);
}
pub fn deallocations(&self) -> usize {
self.allocator.deallocations()
}
pub fn start_migration(&mut self) {
self.migrating = true;
}
}