Skip to content

Commit

Permalink
Merge pull request #7 from vultix/main
Browse files Browse the repository at this point in the history
Cleaned up CallbackSystem::run method
  • Loading branch information
aevyrie authored Oct 30, 2023
2 parents 299ae64 + b8fc2ac commit 4ff7482
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions crates/bevy_eventlistener_core/src/callbacks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,18 @@ pub enum CallbackSystem {
}

impl CallbackSystem {
pub(crate) fn is_initialized(&self) -> bool {
matches!(self, CallbackSystem::Initialized(_))
}

pub(crate) fn run(&mut self, world: &mut World) {
if !self.is_initialized() {
let mut temp = CallbackSystem::Empty;
std::mem::swap(self, &mut temp);
if let CallbackSystem::New(mut system) = temp {
let mut system = match std::mem::take(self) {
CallbackSystem::Empty => return,
CallbackSystem::New(mut system) => {
system.initialize(world);
*self = CallbackSystem::Initialized(system);
system
}
}
if let CallbackSystem::Initialized(system) = self {
system.run((), world);
system.apply_deferred(world);
}
CallbackSystem::Initialized(system) => system,
};
system.run((), world);
system.apply_deferred(world);
*self = CallbackSystem::Initialized(system);
}
}

Expand Down

0 comments on commit 4ff7482

Please sign in to comment.