Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
big-brain
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Louis
big-brain
Commits
35a3156a
Unverified
Commit
35a3156a
authored
4 years ago
by
Kat Marchán
Browse files
Options
Downloads
Patches
Plain Diff
example: Add an idler action to thirst example
parent
7f8ed12b
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
examples/thirst.rs
+39
-1
39 additions, 1 deletion
examples/thirst.rs
src/thinker.rs
+0
-3
0 additions, 3 deletions
src/thinker.rs
with
39 additions
and
4 deletions
examples/thirst.rs
+
39
−
1
View file @
35a3156a
...
...
@@ -98,6 +98,42 @@ fn drink_action_system(
}
}
#[derive(Debug,
Clone)]
struct
Idle
;
impl
Idle
{
fn
build
()
->
IdleBuilder
{
IdleBuilder
}
}
#[derive(Debug,
Clone)]
struct
IdleBuilder
;
impl
ActionBuilder
for
IdleBuilder
{
fn
build
(
&
self
,
cmd
:
&
mut
Commands
,
action
:
Entity
,
_actor
:
Entity
)
{
cmd
.entity
(
action
)
.insert
(
Idle
);
}
}
fn
idle_system
(
mut
query
:
Query
<&
mut
ActionState
,
With
<
Idle
>>
)
{
for
mut
state
in
query
.iter_mut
()
{
match
*
state
{
ActionState
::
Requested
=>
{
println!
(
"Idling..."
);
*
state
=
ActionState
::
Executing
;
}
ActionState
::
Cancelled
=>
{
println!
(
"Idling cancelled"
);
*
state
=
ActionState
::
Success
;
}
ActionState
::
Executing
=>
{
println!
(
"Idled"
);
}
_
=>
{}
}
}
}
// Then, we have something called "Scorers". These are special components that
// run in the background, calculating a "Score" value, which is what Big Brain
// will use to pick which actions to execute.
...
...
@@ -156,7 +192,8 @@ pub fn init_entities(mut cmd: Commands) {
Thinker
::
build
()
.picker
(
FirstToScore
{
threshold
:
80.0
})
// Note that what we pass in are _builders_, not components!
.when
(
Thirsty
::
build
(),
Drink
::
build
()),
.when
(
Thirsty
::
build
(),
Drink
::
build
())
.otherwise
(
Idle
::
build
()),
);
}
...
...
@@ -169,5 +206,6 @@ fn main() {
.add_system
(
thirst_system
.system
())
.add_system
(
drink_action_system
.system
())
.add_system
(
thirsty_scorer_system
.system
())
.add_system
(
idle_system
.system
())
.run
();
}
This diff is collapsed.
Click to expand it.
src/thinker.rs
+
0
−
3
View file @
35a3156a
...
...
@@ -243,7 +243,6 @@ pub fn thinker_system(
// ...and then execute it (details below).
exec_picked_action
(
&
mut
cmd
,
thinker_ent
,
*
actor
,
&
mut
thinker
,
&
choice
.action
,
...
...
@@ -254,7 +253,6 @@ pub fn thinker_system(
let
default_action_ent
=
default_action_ent
.clone
();
exec_picked_action
(
&
mut
cmd
,
thinker_ent
,
*
actor
,
&
mut
thinker
,
&
default_action_ent
,
...
...
@@ -289,7 +287,6 @@ pub fn thinker_system(
fn
exec_picked_action
(
cmd
:
&
mut
Commands
,
thinker_ent
:
Entity
,
actor
:
Entity
,
thinker
:
&
mut
Mut
<
Thinker
>
,
picked_action
:
&
ActionBuilderWrapper
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment