pub mod objects;
pub mod actions;
pub mod traits;
pub mod systems;
pub mod error;
pub use objects::Object;
pub use actions::{Action, ActionContext, ActionResult};
pub use traits::{Trait, TraitData};
pub use systems::{System, SystemManager, Priority};
pub use error::OatsError;
pub type Result<T> = std::result::Result<T, OatsError>;
#[derive(Default)]
pub struct OatsSystem {
objects: Vec<Object>,
actions: Vec<Box<dyn Action>>,
systems: Vec<Box<dyn System>>,
}
impl OatsSystem {
#[inline]
pub fn new() -> Self {
Self::default()
}
pub fn with_capacity(objects: usize, actions: usize, systems: usize) -> Self {
Self {
objects: Vec::with_capacity(objects),
actions: Vec::with_capacity(actions),
systems: Vec::with_capacity(systems),
}
}
#[inline]
pub fn add_object(&mut self, object: Object) {
self.objects.push(object);
}
pub fn add_objects(&mut self, objects: impl IntoIterator<Item = Object>) {
self.objects.extend(objects);
}
#[inline]
pub fn add_action(&mut self, action: Box<dyn Action>) {
self.actions.push(action);
}
#[inline]
pub fn add_system(&mut self, system: Box<dyn System>) {
self.systems.push(system);
}
#[inline]
pub fn objects(&self) -> &[Object] {
&self.objects
}
#[inline]
pub fn actions(&self) -> &[Box<dyn Action>] {
&self.actions
}
#[inline]
pub fn systems(&self) -> &[Box<dyn System>] {
&self.systems
}
#[inline]
pub fn object_count(&self) -> usize {
self.objects.len()
}
#[inline]
pub fn action_count(&self) -> usize {
self.actions.len()
}
#[inline]
pub fn system_count(&self) -> usize {
self.systems.len()
}
#[inline]
pub fn clear_objects(&mut self) {
self.objects.clear();
}
#[inline]
pub fn clear_actions(&mut self) {
self.actions.clear();
}
#[inline]
pub fn clear_systems(&mut self) {
self.systems.clear();
}
#[inline]
pub fn reserve_objects(&mut self, additional: usize) {
self.objects.reserve(additional);
}
#[inline]
pub fn reserve_actions(&mut self, additional: usize) {
self.actions.reserve(additional);
}
#[inline]
pub fn reserve_systems(&mut self, additional: usize) {
self.systems.reserve(additional);
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_oats_system_creation() {
let system = OatsSystem::new();
assert_eq!(system.object_count(), 0);
assert_eq!(system.action_count(), 0);
assert_eq!(system.system_count(), 0);
}
#[test]
fn test_oats_system_with_capacity() {
let system = OatsSystem::with_capacity(100, 10, 5);
assert_eq!(system.object_count(), 0);
assert_eq!(system.action_count(), 0);
assert_eq!(system.system_count(), 0);
}
#[test]
fn test_oats_system_operations() {
let mut system = OatsSystem::new();
let obj = Object::new("test", "type");
system.add_object(obj);
assert_eq!(system.object_count(), 1);
let objects = vec![
Object::new("obj1", "type"),
Object::new("obj2", "type"),
];
system.add_objects(objects);
assert_eq!(system.object_count(), 3);
system.reserve_objects(100);
assert!(system.objects.capacity() >= 103);
}
}