forked from amethyst/amethyst
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changed lifetime requirements for TransQueue. Added state_dispatcher …
…example.
- Loading branch information
1 parent
c03e7ea
commit 853afe8
Showing
6 changed files
with
67 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
//! An example showing how to create a dispatcher inside of a State. | ||
extern crate amethyst; | ||
|
||
use amethyst::Error; | ||
use amethyst::ecs::{Dispatcher, DispatcherBuilder}; | ||
use amethyst::prelude::*; | ||
|
||
struct StateA; | ||
|
||
impl SimpleState<'static, 'static> for StateA { | ||
fn update(&mut self, data: &mut StateData<GameData>) -> SimpleTrans<'static, 'static> { | ||
println!("StateA::update()"); | ||
// Shows how to push a `Trans` through the event queue. | ||
data.world.write_resource::<TransQueue<GameData<'static, 'static>, StateEvent>>().push_back(Box::new(|| Trans::Push(Box::new(StateB::<'static, 'static>::default())))); | ||
Trans::None | ||
} | ||
} | ||
|
||
/// StateB isn't Send + Sync | ||
struct StateB<'a, 'b> { | ||
dispatcher: Dispatcher<'a, 'b>, | ||
} | ||
|
||
impl<'a, 'b> Default for StateB<'a, 'b> { | ||
fn default() -> Self { | ||
StateB { | ||
dispatcher: DispatcherBuilder::new().build(), | ||
} | ||
} | ||
} | ||
|
||
impl<'a, 'b> SimpleState<'a, 'b> for StateB<'a, 'b> { | ||
fn update(&mut self, data: &mut StateData<GameData>) -> SimpleTrans<'a, 'b> { | ||
println!("StateB::update()"); | ||
self.dispatcher.dispatch(&mut data.world.res); | ||
Trans::Quit | ||
} | ||
} | ||
|
||
fn main() -> Result<(), Error> { | ||
amethyst::start_logger(Default::default()); | ||
let mut game = Application::build("./", StateA)?.build(GameDataBuilder::default())?; | ||
game.run(); | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters