Advertisement
Guest User

DOD Problem

a guest
Jan 7th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 0.79 KB | None | 0 0
  1. // I'm using specs for ECS.
  2.  
  3. #[derive(Component, Debug, Clone)]
  4. #[storage(DenseVecStorage)]
  5. pub struct Navigator {
  6.     destination: Destination,
  7.     path: PathState
  8. }
  9.  
  10. impl Navigator {
  11.     // Is `navigate` the correct thing to write?
  12.     // It borrows itself mutably to assign the destination and path.
  13.     // This will only be called from systems.
  14.     // But the problem is I do not want the destination to be mutated from
  15.     // outside without setting `path` to `PathState::Finding`.
  16.     pub fn navigate(&mut self, destination: Destination) {
  17.         self.destination = destination;
  18.         self.path = PathState::Finding;
  19.     }
  20.     pub fn destination(&self) -> Destination {
  21.         self.destination
  22.     }
  23.     pub fn arrived(&self) -> bool {
  24.         self.path == PathState::Arrived
  25.     }
  26.     // ...
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement