mirror of
https://github.com/Xevion/Pac-Man.git
synced 2025-12-17 14:12:40 -06:00
chore: use NodeId explicitly in collision.rs types
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
use smallvec::SmallVec;
|
use smallvec::SmallVec;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use crate::entity::traversal::Position;
|
use crate::entity::{graph::NodeId, traversal::Position};
|
||||||
|
|
||||||
/// Trait for entities that can participate in collision detection.
|
/// Trait for entities that can participate in collision detection.
|
||||||
pub trait Collidable {
|
pub trait Collidable {
|
||||||
@@ -19,7 +19,7 @@ pub trait Collidable {
|
|||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct CollisionSystem {
|
pub struct CollisionSystem {
|
||||||
/// Maps node IDs to lists of entity IDs that are at that node
|
/// Maps node IDs to lists of entity IDs that are at that node
|
||||||
node_entities: HashMap<usize, Vec<EntityId>>,
|
node_entities: HashMap<NodeId, Vec<EntityId>>,
|
||||||
/// Maps entity IDs to their current positions
|
/// Maps entity IDs to their current positions
|
||||||
entity_positions: HashMap<EntityId, Position>,
|
entity_positions: HashMap<EntityId, Position>,
|
||||||
/// Next available entity ID
|
/// Next available entity ID
|
||||||
@@ -62,7 +62,7 @@ impl CollisionSystem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Gets all entity IDs at a specific node
|
/// Gets all entity IDs at a specific node
|
||||||
pub fn entities_at_node(&self, node: usize) -> &[EntityId] {
|
pub fn entities_at_node(&self, node: NodeId) -> &[EntityId] {
|
||||||
self.node_entities.get(&node).map(|v| v.as_slice()).unwrap_or(&[])
|
self.node_entities.get(&node).map(|v| v.as_slice()).unwrap_or(&[])
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,7 +115,7 @@ fn positions_overlap(a: &Position, b: &Position) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Gets all nodes that an entity is currently at or between.
|
/// Gets all nodes that an entity is currently at or between.
|
||||||
fn get_nodes(pos: &Position) -> SmallVec<[usize; 2]> {
|
fn get_nodes(pos: &Position) -> SmallVec<[NodeId; 2]> {
|
||||||
let mut nodes = SmallVec::new();
|
let mut nodes = SmallVec::new();
|
||||||
match pos {
|
match pos {
|
||||||
Position::AtNode(node) => nodes.push(*node),
|
Position::AtNode(node) => nodes.push(*node),
|
||||||
|
|||||||
Reference in New Issue
Block a user