Skip to content
Snippets Groups Projects
Commit a76dcbb6 authored by Kat Marchán's avatar Kat Marchán
Browse files

fix(choice): return &Choice instead of cloning

parent 372c13e2
No related branches found
No related tags found
No related merge requests found
...@@ -12,7 +12,7 @@ Required trait for Pickers. A Picker is given a slice of choices and a query tha ...@@ -12,7 +12,7 @@ Required trait for Pickers. A Picker is given a slice of choices and a query tha
Implementations of `pick` must return `Some(Choice)` for the `Choice` that was picked, or `None`. Implementations of `pick` must return `Some(Choice)` for the `Choice` that was picked, or `None`.
*/ */
pub trait Picker: std::fmt::Debug + Sync + Send { pub trait Picker: std::fmt::Debug + Sync + Send {
fn pick(&self, _choices: &[Choice], _utilities: &Query<&Score>) -> Option<Choice>; fn pick<'a>(&self, choices: &'a [Choice], scores: &Query<&Score>) -> Option<&'a Choice>;
} }
/** /**
...@@ -38,11 +38,11 @@ impl FirstToScore { ...@@ -38,11 +38,11 @@ impl FirstToScore {
} }
impl Picker for FirstToScore { impl Picker for FirstToScore {
fn pick(&self, choices: &[Choice], scores: &Query<&Score>) -> Option<Choice> { fn pick<'a>(&self, choices: &'a [Choice], scores: &Query<&Score>) -> Option<&'a Choice> {
for choice in choices { for choice in choices {
let value = choice.calculate(scores); let value = choice.calculate(scores);
if value >= self.threshold { if value >= self.threshold {
return Some(choice.clone()); return Some(choice);
} }
} }
None None
......
...@@ -241,13 +241,8 @@ pub fn thinker_system( ...@@ -241,13 +241,8 @@ pub fn thinker_system(
// Think about what action we're supposed to be taking. We do this // Think about what action we're supposed to be taking. We do this
// every tick, because we might change our mind. // every tick, because we might change our mind.
// ...and then execute it (details below). // ...and then execute it (details below).
exec_picked_action( let action = choice.action.clone();
&mut cmd, exec_picked_action(&mut cmd, *actor, &mut thinker, &action, &mut action_states);
*actor,
&mut thinker,
&choice.action,
&mut action_states,
);
} else if let Some(default_action_ent) = &thinker.otherwise { } else if let Some(default_action_ent) = &thinker.otherwise {
// Otherwise, let's just execute the default one! (if it's there) // Otherwise, let's just execute the default one! (if it's there)
let default_action_ent = default_action_ent.clone(); let default_action_ent = default_action_ent.clone();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment