diff --git a/src/pickers.rs b/src/pickers.rs index a83e160309a62b7627018de6f85c89ff835a5534..abb0b024eeb4b6268bd594477cd02051e275d152 100644 --- a/src/pickers.rs +++ b/src/pickers.rs @@ -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`. */ 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 { } 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 { let value = choice.calculate(scores); if value >= self.threshold { - return Some(choice.clone()); + return Some(choice); } } None diff --git a/src/thinker.rs b/src/thinker.rs index bc01bd066af32c09a1859327ab9bad7716b91000..45aa7c8d01469f73dabc56db97d1d2f856baf1b2 100644 --- a/src/thinker.rs +++ b/src/thinker.rs @@ -241,13 +241,8 @@ pub fn thinker_system( // Think about what action we're supposed to be taking. We do this // every tick, because we might change our mind. // ...and then execute it (details below). - exec_picked_action( - &mut cmd, - *actor, - &mut thinker, - &choice.action, - &mut action_states, - ); + let action = choice.action.clone(); + exec_picked_action(&mut cmd, *actor, &mut thinker, &action, &mut action_states); } else if let Some(default_action_ent) = &thinker.otherwise { // Otherwise, let's just execute the default one! (if it's there) let default_action_ent = default_action_ent.clone();