use crate::components::Velocity;
use crate::dispatch::ElevatorGroup;
use crate::entity::EntityId;
use crate::error::SimError;
use crate::events::Event;
use crate::ids::GroupId;
use crate::metrics::Metrics;
use crate::stop::{StopId, StopRef};
use crate::time::TimeAdapter;
use crate::world::World;
impl super::Simulation {
#[must_use]
#[allow(clippy::missing_const_for_fn)]
pub fn world(&self) -> &World {
&self.world
}
#[allow(clippy::missing_const_for_fn)]
pub fn world_mut(&mut self) -> &mut World {
&mut self.world
}
#[must_use]
pub const fn current_tick(&self) -> u64 {
self.tick
}
#[must_use]
pub const fn dt(&self) -> f64 {
self.dt
}
#[must_use]
pub fn position_at(&self, id: EntityId, alpha: f64) -> Option<f64> {
let current = self.world.position(id)?.value;
let alpha = if alpha.is_nan() {
0.0
} else {
alpha.clamp(0.0, 1.0)
};
let prev = self.world.prev_position(id).map_or(current, |p| p.value);
Some((current - prev).mul_add(alpha, prev))
}
#[must_use]
pub fn velocity(&self, id: EntityId) -> Option<f64> {
self.world.velocity(id).map(Velocity::value)
}
#[must_use]
pub const fn metrics(&self) -> &Metrics {
&self.metrics
}
#[must_use]
pub const fn time(&self) -> &TimeAdapter {
&self.time
}
#[must_use]
pub fn groups(&self) -> &[ElevatorGroup] {
&self.groups
}
pub fn groups_mut(&mut self) -> &mut [ElevatorGroup] {
&mut self.groups
}
#[must_use]
pub fn stop_entity(&self, id: StopId) -> Option<EntityId> {
self.stop_lookup.get(&id).copied()
}
pub(super) fn resolve_stop(&self, stop: StopRef) -> Result<EntityId, SimError> {
match stop {
StopRef::ByEntity(id) => Ok(id),
StopRef::ById(sid) => self.stop_entity(sid).ok_or(SimError::StopNotFound(sid)),
}
}
#[must_use]
pub fn strategy_id(&self, group: GroupId) -> Option<&crate::dispatch::BuiltinStrategy> {
self.strategy_ids.get(&group)
}
pub fn stop_lookup_iter(&self) -> impl Iterator<Item = (&StopId, &EntityId)> {
self.stop_lookup.iter()
}
pub fn pending_events(&mut self) -> &[Event] {
self.pending_output.extend(self.events.drain());
&self.pending_output
}
}