Commit 834190fc authored by Ralf's avatar Ralf

rename State -> Situation

parent 656752a8
//! This module implements the [Environment] type, which manages the state
//! that is available to Situations.
use std::time::Duration;
use std::thread;
......
......@@ -3,7 +3,7 @@ use actors::{Actor, LockAction};
#[macro_use]
mod environment;
mod handlers;
mod states;
mod situations;
pub struct Actors {
......@@ -12,6 +12,6 @@ pub struct Actors {
buzz: Box<Actor<bool>>,
}
pub trait State {
fn run(&mut self, Actors, &mut environment::Environment) -> Option<Box<State>>;
pub trait Situation {
fn run(&mut self, Actors, &mut environment::Environment) -> (Actors, Option<Box<Situation>>);
}
......@@ -5,21 +5,21 @@ use input::Event;
use util::wakeable::Wakeable;
use brain::environment::*;
use brain::handlers;
use brain::{Actors, State};
use brain::{Actors, Situation};
#[derive(Debug)]
pub struct UnLockingState {
pub struct UnLocking {
locking: bool,
}
impl UnLockingState {
pub fn new(locking: bool) -> UnLockingState {
UnLockingState { locking: locking }
impl UnLocking {
pub fn new(locking: bool) -> UnLocking {
UnLocking { locking: locking }
}
}
impl State for UnLockingState {
fn run(&mut self, mut actors: Actors, env: &mut Environment) -> Option<Box<State>> {
impl Situation for UnLocking {
fn run(&mut self, mut actors: Actors, env: &mut Environment) -> (Actors, Option<Box<Situation>>) {
// TODO: abort if already locked
let locking = self.locking;
for _ in 0..3 {
......@@ -50,21 +50,21 @@ impl State for UnLockingState {
break; // the retries
}
}
None // FIXME
(actors, None) // FIXME
}
}
#[derive(Debug)]
pub struct OpenState;
pub struct SpaceOpen;
impl OpenState {
pub fn new() -> OpenState {
OpenState
impl SpaceOpen {
pub fn new() -> SpaceOpen {
SpaceOpen
}
}
impl State for OpenState {
fn run(&mut self, mut actors: Actors, env: &mut Environment) -> Option<Box<State>> {
impl Situation for SpaceOpen {
fn run(&mut self, mut actors: Actors, env: &mut Environment) -> (Actors, Option<Box<Situation>>) {
let mut buzzer = Wakeable::new(actors.buzz, move |t, mut buzz_actor, d| {
buzz_actor.act(true);
t.sleep(d);
......@@ -78,9 +78,8 @@ impl State for OpenState {
}
}));
actors.buzz = buzzer.terminate();
if r == EventsResult::ShuttingDown {
return None;
}
None // FIXME
// hand over to next state
(actors, if r == EventsResult::ShuttingDown { None }
else { None /* FIXME */ })
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment