added fuel limit
This commit is contained in:
parent
5e9a99e030
commit
598fdf4df6
2 changed files with 26 additions and 18 deletions
|
|
@ -60,7 +60,7 @@ impl LiveState {
|
|||
let mut turtles = Vec::new();
|
||||
for turtle in save.turtles.into_iter() {
|
||||
let (tx, rx) = mpsc::channel(1);
|
||||
turtles.push(Turtle::with_channel(turtle.name.to_num(), turtle.position, turtle.fuel, tx, rx));
|
||||
turtles.push(Turtle::with_channel(turtle.name.to_num(), turtle.position, turtle.fuel, turtle.fuel_limit, tx, rx));
|
||||
};
|
||||
Self { turtles: turtles.into_iter().map(|t| Arc::new(RwLock::new(t))).collect(), tasks: Vec::new(), world: World::from_tree(save.world) }
|
||||
}
|
||||
|
|
@ -139,7 +139,7 @@ async fn create_turtle(
|
|||
let (send, receive) = mpsc::channel(1);
|
||||
state.turtles.push(
|
||||
Arc::new(RwLock::new(
|
||||
turtle::Turtle::with_channel(id, Position::new(req.position, req.facing), req.fuel, send,receive)
|
||||
turtle::Turtle::with_channel(id, Position::new(req.position, req.facing), req.fuel, req.fuellimit, send,receive)
|
||||
)));
|
||||
state.tasks.push(VecDeque::new());
|
||||
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@ const IDLE_TIME: u32 = 3;
|
|||
pub(crate) struct Turtle {
|
||||
pub(crate) name: Name,
|
||||
pub(crate) fuel: usize,
|
||||
pub(crate) fuel_limit: usize,
|
||||
/// movement vector of last given command
|
||||
pub(crate) queued_movement: Vec3,
|
||||
pub(crate) position: Position,
|
||||
|
|
@ -85,6 +86,7 @@ impl Default for Turtle {
|
|||
Self {
|
||||
name: Name::from_num(0),
|
||||
fuel: Default::default(),
|
||||
fuel_limit: Default::default(),
|
||||
queued_movement: Default::default(),
|
||||
position: Position::new(Vec3::zeros(), Direction::North),
|
||||
goal: None,
|
||||
|
|
@ -121,10 +123,11 @@ impl Turtle {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn with_channel(id: u32, position: Position, fuel: usize, sender: Sender, receiver: Receiver) -> Self {
|
||||
pub fn with_channel(id: u32, position: Position, fuel: usize, fuel_limit: usize, sender: Sender, receiver: Receiver) -> Self {
|
||||
Self {
|
||||
name: Name::from_num(id),
|
||||
fuel,
|
||||
fuel_limit,
|
||||
queued_movement: Vec3::new(0, 0, 0),
|
||||
position,
|
||||
pending_update: true,
|
||||
|
|
@ -169,6 +172,10 @@ impl TurtleCommander {
|
|||
self.turtle.read().await.fuel
|
||||
}
|
||||
|
||||
pub async fn fuel_limit(&self) -> usize {
|
||||
self.turtle.read().await.fuel_limit
|
||||
}
|
||||
|
||||
pub async fn world(&self) -> World {
|
||||
self.world.clone()
|
||||
}
|
||||
|
|
@ -392,6 +399,7 @@ pub(crate) struct TurtleUpdate {
|
|||
#[derive(Serialize, Deserialize)]
|
||||
pub(crate) struct TurtleRegister {
|
||||
pub(crate) fuel: usize,
|
||||
pub(crate) fuellimit: usize,
|
||||
pub(crate) position: Vec3,
|
||||
pub(crate) facing: Direction,
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue