Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Hacksaar
rinx
Commits
834190fc
Commit
834190fc
authored
Mar 06, 2016
by
Ralf
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rename State -> Situation
parent
656752a8
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
21 deletions
+22
-21
src/brain/environment.rs
src/brain/environment.rs
+2
-0
src/brain/mod.rs
src/brain/mod.rs
+3
-3
src/brain/situations.rs
src/brain/situations.rs
+17
-18
No files found.
src/brain/environment.rs
View file @
834190fc
//! This module implements the [Environment] type, which manages the state
//! that is available to Situations.
use
std
::
time
::
Duration
;
use
std
::
thread
;
...
...
src/brain/mod.rs
View file @
834190fc
...
...
@@ -3,7 +3,7 @@ use actors::{Actor, LockAction};
#[macro_use]
mod
environment
;
mod
handlers
;
mod
s
tate
s
;
mod
s
ituation
s
;
pub
struct
Actors
{
...
...
@@ -12,6 +12,6 @@ pub struct Actors {
buzz
:
Box
<
Actor
<
bool
>>
,
}
pub
trait
S
tate
{
fn
run
(
&
mut
self
,
Actors
,
&
mut
environment
::
Environment
)
->
Option
<
Box
<
S
tate
>>
;
pub
trait
S
ituation
{
fn
run
(
&
mut
self
,
Actors
,
&
mut
environment
::
Environment
)
->
(
Actors
,
Option
<
Box
<
S
ituation
>>
)
;
}
src/brain/s
tate
s.rs
→
src/brain/s
ituation
s.rs
View file @
834190fc
...
...
@@ -5,21 +5,21 @@ use input::Event;
use
util
::
wakeable
::
Wakeable
;
use
brain
::
environment
::
*
;
use
brain
::
handlers
;
use
brain
::{
Actors
,
S
tate
};
use
brain
::{
Actors
,
S
ituation
};
#[derive(Debug)]
pub
struct
UnLocking
State
{
pub
struct
UnLocking
{
locking
:
bool
,
}
impl
UnLocking
State
{
pub
fn
new
(
locking
:
bool
)
->
UnLocking
State
{
UnLocking
State
{
locking
:
locking
}
impl
UnLocking
{
pub
fn
new
(
locking
:
bool
)
->
UnLocking
{
UnLocking
{
locking
:
locking
}
}
}
impl
S
tate
for
UnLocking
State
{
fn
run
(
&
mut
self
,
mut
actors
:
Actors
,
env
:
&
mut
Environment
)
->
Option
<
Box
<
S
tate
>>
{
impl
S
ituation
for
UnLocking
{
fn
run
(
&
mut
self
,
mut
actors
:
Actors
,
env
:
&
mut
Environment
)
->
(
Actors
,
Option
<
Box
<
S
ituation
>>
)
{
// 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
S
tate
for
OpenState
{
fn
run
(
&
mut
self
,
mut
actors
:
Actors
,
env
:
&
mut
Environment
)
->
Option
<
Box
<
S
tate
>>
{
impl
S
ituation
for
SpaceOpen
{
fn
run
(
&
mut
self
,
mut
actors
:
Actors
,
env
:
&
mut
Environment
)
->
(
Actors
,
Option
<
Box
<
S
ituation
>>
)
{
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 */
})
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment