//! Various implementations of [`crate::ShipBehavior`] mod null; mod point; use null::*; use point::PointShipController; use std::fmt::Debug; use super::ShipControls; use crate::phys::{PhysImage, PhysSimShipHandle, PhysStepResources}; /// Represents a ship controller #[derive(Debug, Clone)] pub enum ShipController { /// Null controller Null(NullShipController), /// Point controller Point(PointShipController), } impl ShipController { /// Make a new null controller pub fn new_null() -> Self { Self::Null(NullShipController::new()) } /// Make a new point controller pub fn new_point() -> Self { Self::Point(PointShipController::new()) } /// Compute new ship controls from world state pub fn update_controls( &mut self, res: &PhysStepResources, img: &PhysImage, this_ship: PhysSimShipHandle, ) -> Option { match self { Self::Null(n) => n.update_controls(res, img, this_ship), Self::Point(p) => p.update_controls(res, img, this_ship), } } } trait ShipControllerStruct where Self: Debug + Clone, { /// Update a ship's controls based on system state. /// This method returns the ship's new control values, /// or None if no change is to be made. fn update_controls( &mut self, res: &PhysStepResources, img: &PhysImage, this_ship: PhysSimShipHandle, ) -> Option; }