Skip to content
This repository has been archived by the owner on Apr 18, 2022. It is now read-only.

Commit

Permalink
Merge #1198
Browse files Browse the repository at this point in the history
1198: Remove lifetime from `SimpleState` and `SimpleTrans` r=torkleyy a=torkleyy

Fixes #1178 

Related: #1152 

Co-authored-by: Thomas Schaller <torkleyy@gmail.com>
  • Loading branch information
bors[bot] and torkleyy committed Dec 4, 2018
2 parents 2c7dc58 + e4f711b commit ac6b2b8
Show file tree
Hide file tree
Showing 47 changed files with 86 additions and 96 deletions.
2 changes: 1 addition & 1 deletion amethyst_core/src/frame_limiter.rs
Expand Up @@ -25,7 +25,7 @@
//! use amethyst::core::frame_limiter::FrameRateLimitStrategy;
//!
//! # struct GameState;
//! # impl<'a, 'b> SimpleState<'a, 'b> for GameState {}
//! # impl SimpleState for GameState {}
//! # fn main() -> amethyst::Result<()> {
//! let mut game = Application::build("./", GameState)?
//! .with_frame_limit(
Expand Down
4 changes: 2 additions & 2 deletions book/src/concepts/state.md
Expand Up @@ -102,7 +102,7 @@ struct GameplayState {
player_count: u8,
}
impl<'a,'b> SimpleState<'a,'b> for GameplayState {
impl SimpleState for GameplayState {
fn on_start(&mut self, _data: StateData<GameData>) {
println!("Number of players: {}", self.player_count);
}
Expand All @@ -116,7 +116,7 @@ We first declare the `State`'s struct `GameplayState`.
In this case, we give it some data: `player_count`, a byte.

Then, we implement the `SimpleState` trait for our `GameplayState`.
`SimpleState` is a shorthand for `State<GameData<'a, 'b>, ()>` where `GameData` is the internal shared data between states.
`SimpleState` is a shorthand for `State<GameData<'static, 'static>, ()>` where `GameData` is the internal shared data between states.

### Switching State

Expand Down
8 changes: 4 additions & 4 deletions book/src/concepts/system.md
Expand Up @@ -357,8 +357,8 @@ impl Default for Game {
struct GameplayState;
impl<'a, 'b> SimpleState<'a, 'b> for GameplayState {
fn update(&mut self, data: &mut StateData<GameData>) -> SimpleTrans<'a, 'b> {
impl SimpleState for GameplayState {
fn update(&mut self, data: &mut StateData<GameData>) -> SimpleTrans {
// If the `Game` resource has been set up to go back to the menu, pop
// the state so that we go back.
Expand All @@ -379,8 +379,8 @@ impl<'a, 'b> SimpleState<'a, 'b> for GameplayState {
struct GameMenuState;
impl<'a, 'b> SimpleState<'a, 'b> for GameMenuState {
fn update(&mut self, data: &mut StateData<GameData>) -> SimpleTrans<'a, 'b> {
impl SimpleState for GameMenuState {
fn update(&mut self, data: &mut StateData<GameData>) -> SimpleTrans {
let mut game = data.world.write_resource::<Game>();
match game.user_action.take() {
Expand Down
4 changes: 2 additions & 2 deletions book/src/pong-tutorial/pong-tutorial-01.md
Expand Up @@ -44,7 +44,7 @@ just implement two methods:
# use amethyst::renderer::{DisplayConfig, DrawFlat, Pipeline,
# PosTex, RenderBundle, Stage};
# struct Pong;
impl<'a, 'b> SimpleState<'a, 'b> for Pong {
impl SimpleState for Pong {
}
```

Expand Down Expand Up @@ -166,7 +166,7 @@ Now let's pack everything up and run it:
# let path = "./resources/display_config.ron";
# let config = DisplayConfig::load(&path);
# struct Pong;
# impl<'a, 'b> SimpleState<'a,'b> for Pong { }
# impl SimpleState for Pong { }
let pipe = Pipeline::build()
.with_stage(
# Stage::with_backbuffer()
Expand Down
10 changes: 5 additions & 5 deletions book/src/pong-tutorial/pong-tutorial-02.md
Expand Up @@ -56,7 +56,7 @@ We will leave it empty for now, but it will become useful later down the line.
# extern crate amethyst;
# use amethyst::prelude::*;
# struct MyState;
# impl<'a, 'b> SimpleState<'a, 'b> for MyState {
# impl SimpleState for MyState {
fn on_start(&mut self, data: StateData<GameData>) {
}
Expand Down Expand Up @@ -141,7 +141,7 @@ our State's `on_start` method:
# use amethyst::ecs::World;
# fn initialise_camera(world: &mut World) { }
# struct MyState;
# impl<'a, 'b> SimpleState<'a, 'b> for MyState {
# impl SimpleState for MyState {
fn on_start(&mut self, data: StateData<GameData>) {
let world = data.world;
Expand Down Expand Up @@ -289,7 +289,7 @@ compiles. Update the `on_start` method to the following:
# fn initialise_paddles(world: &mut World) { }
# fn initialise_camera(world: &mut World) { }
# struct MyState;
# impl<'a, 'b> SimpleState<'a, 'b> for MyState {
# impl SimpleState for MyState {
fn on_start(&mut self, data: StateData<GameData>) {
let world = data.world;
Expand Down Expand Up @@ -383,7 +383,7 @@ fn main() -> amethyst::Result<()> {
# .with_pass(DrawFlat2D::new()),
# );
# struct Pong;
# impl<'a, 'b> SimpleState<'a, 'b> for Pong { }
# impl SimpleState for Pong { }
let game_data = GameDataBuilder::default()
.with_bundle(
RenderBundle::new(pipe, Some(config))
Expand Down Expand Up @@ -602,7 +602,7 @@ all together in the `on_start()` method:
# fn initialise_camera(world: &mut World) { }
# fn load_sprite_sheet(world: &mut World) -> SpriteSheetHandle { unimplemented!() }
# struct MyState;
# impl<'a, 'b> SimpleState<'a, 'b> for MyState {
# impl SimpleState for MyState {
fn on_start(&mut self, data: StateData<GameData>) {
let world = data.world;
Expand Down
4 changes: 2 additions & 2 deletions book/src/pong-tutorial/pong-tutorial-03.md
Expand Up @@ -76,7 +76,7 @@ let input_bundle = InputBundle::<String, String>::new()
# .with_pass(DrawFlat::<PosTex>::new()),
# );
# struct Pong;
# impl<'a, 'b> SimpleState<'a, 'b> for Pong { }
# impl SimpleState for Pong { }
let game_data = GameDataBuilder::default()
.with_bundle(RenderBundle::new(pipe, Some(config)).with_sprite_sheet_processor())?
.with_bundle(TransformBundle::new())?
Expand Down Expand Up @@ -370,7 +370,7 @@ will take care of that for us, as well as set up the storage.
# fn initialise_camera(world: &mut World) { }
# fn load_sprite_sheet(world: &mut World) -> SpriteSheetHandle { unimplemented!() }
# struct MyState;
# impl<'a, 'b> SimpleState<'a, 'b> for MyState {
# impl SimpleState for MyState {
fn on_start(&mut self, data: StateData<GameData>) {
let world = data.world;
Expand Down
2 changes: 1 addition & 1 deletion book/src/pong-tutorial/pong-tutorial-04.md
Expand Up @@ -113,7 +113,7 @@ Finally, let's make sure the code is working as intended by updating the `on_sta
# fn initialise_camera(world: &mut World) { }
# fn load_sprite_sheet(world: &mut World) -> SpriteSheetHandle { unimplemented!() }
# struct MyState;
# impl<'a, 'b> SimpleState<'a, 'b> for MyState {
# impl SimpleState for MyState {
fn on_start(&mut self, data: StateData<GameData>) {
let world = data.world;
Expand Down
4 changes: 2 additions & 2 deletions book/src/pong-tutorial/pong-tutorial-05.md
Expand Up @@ -286,7 +286,7 @@ use amethyst::{
#
# pub struct Pong;
#
# impl<'a, 'b> SimpleState<'a, 'b> for Pong {
# impl SimpleState for Pong {
# fn on_start(&mut self, data: StateData<GameData>) {
# let world = data.world;
#
Expand Down Expand Up @@ -487,7 +487,7 @@ use amethyst::{
#
# pub struct Pong;
#
impl<'a, 'b> SimpleState<'a, 'b> for Pong {
impl SimpleState for Pong {
fn on_start(&mut self, data: StateData<GameData>) {
# let world = data.world;
#
Expand Down
2 changes: 1 addition & 1 deletion book/src/sprites/display_the_texture.md
Expand Up @@ -44,7 +44,7 @@ fn init_image(world: &mut World, texture_handle: &TextureHandle) {
#[derive(Debug)]
struct ExampleState;
impl<'a, 'b> SimpleState<'a, 'b> for ExampleState {
impl SimpleState for ExampleState {
fn on_start(&mut self, data: StateData<GameData>) {
let world = data.world;
let texture_handle = load_texture("texture/sprite_sheet.png", world);
Expand Down
2 changes: 1 addition & 1 deletion book/src/sprites/load_the_texture.md
Expand Up @@ -27,7 +27,7 @@ where
#[derive(Debug)]
struct ExampleState;
impl<'a, 'b> SimpleState<'a, 'b> for ExampleState {
impl SimpleState for ExampleState {
fn on_start(&mut self, data: StateData<GameData>) {
let texture_handle = load_texture("texture/sprite_sheet.png", &data.world);
}
Expand Down
2 changes: 1 addition & 1 deletion book/src/sprites/orthographic_camera.md
Expand Up @@ -16,7 +16,7 @@ use amethyst::renderer::{
#[derive(Debug)]
struct ExampleState;
impl<'a, 'b> SimpleState<'a, 'b> for ExampleState {
impl SimpleState for ExampleState {
fn on_start(&mut self, mut data: StateData<GameData>) {
// ...
Expand Down
2 changes: 1 addition & 1 deletion book/src/sprites/set_up_the_render_pass.md
Expand Up @@ -20,7 +20,7 @@ use amethyst::renderer::{
# #[derive(Debug, Default)]
# struct ExampleState;
#
# impl<'a, 'b> SimpleState<'a, 'b> for ExampleState {}
# impl SimpleState for ExampleState {}
fn main() -> amethyst::Result<()> {
# amethyst::start_logger(Default::default());
Expand Down
4 changes: 2 additions & 2 deletions book/src/sprites/sprite_render_component.md
Expand Up @@ -37,7 +37,7 @@ use amethyst::renderer::{
#[derive(Debug)]
struct ExampleState;
impl<'a, 'b> SimpleState<'a, 'b> for ExampleState {
impl SimpleState for ExampleState {
fn on_start(&mut self, mut data: StateData<GameData>) {
# let texture_handle = load_texture("texture/sprite_sheet.png", &data.world);
// ...
Expand Down Expand Up @@ -82,7 +82,7 @@ use amethyst::renderer::{
#[derive(Debug)]
struct ExampleState;
impl<'a, 'b> SimpleState<'a, 'b> for ExampleState {
impl SimpleState for ExampleState {
fn on_start(&mut self, mut data: StateData<GameData>) {
# let texture_handle = load_texture("texture/sprite_sheet.png", &data.world);
#
Expand Down
3 changes: 3 additions & 0 deletions docs/CHANGELOG.md
Expand Up @@ -43,6 +43,7 @@ The format is based on [Keep a Changelog][kc], and this project adheres to
* Renamed the `DrawSprite` pass to `DrawFlat2D` as it now handles both sprites and images without spritesheets. ([#1153])
* `BasicScenePrefab` deserialization now returns an error on invalid fields. ([#1164])
* Reordered arguments for `Transform::set_rotation_euler` to match nalgebra's Euler angles. ([#1052])
* Remove lifetimes from `SimpleState` ([#1198])

### Removed

Expand Down Expand Up @@ -85,6 +86,7 @@ The format is based on [Keep a Changelog][kc], and this project adheres to
[#1184]: https://github.com/amethyst/amethyst/pull/1184
[#1187]: https://github.com/amethyst/amethyst/pull/1187
[#1188]: https://github.com/amethyst/amethyst/pull/1188
[#1198]: https://github.com/amethyst/amethyst/pull/1198
[winit_018]: https://github.com/tomaka/winit/blob/v0.18.0/CHANGELOG.md#version-0180-2018-11-07
[glutin_019]: https://github.com/tomaka/glutin/blob/master/CHANGELOG.md#version-0190-2018-11-09

Expand Down Expand Up @@ -703,3 +705,4 @@ The format is based on [Keep a Changelog][kc], and this project adheres to
[0.4.1]: https://github.com/amethyst/amethyst/compare/v0.4...v0.4.1
[0.4.0]: https://github.com/amethyst/amethyst/compare/v0.3.1...v0.4
[0.3.1]: https://github.com/amethyst/amethyst/compare/v0.3...v0.3.1

8 changes: 2 additions & 6 deletions examples/animation/main.rs
Expand Up @@ -46,7 +46,7 @@ impl Default for Example {
}
}

impl<'a, 'b> SimpleState<'a, 'b> for Example {
impl SimpleState for Example {
fn on_start(&mut self, data: StateData<GameData>) {
let StateData { world, .. } = data;
// Initialise the scene with an object, a light and a camera.
Expand All @@ -56,11 +56,7 @@ impl<'a, 'b> SimpleState<'a, 'b> for Example {
self.sphere = Some(world.create_entity().with(prefab_handle).build());
}

fn handle_event(
&mut self,
data: StateData<GameData>,
event: StateEvent,
) -> SimpleTrans<'a, 'b> {
fn handle_event(&mut self, data: StateData<GameData>, event: StateEvent) -> SimpleTrans {
let StateData { world, .. } = data;
if let StateEvent::Window(event) = &event {
if is_close_requested(&event) || is_key_down(&event, VirtualKeyCode::Escape) {
Expand Down
2 changes: 1 addition & 1 deletion examples/appendix_a/pong.rs
Expand Up @@ -19,7 +19,7 @@ use crate::{

pub struct Pong;

impl<'a, 'b> SimpleState<'a, 'b> for Pong {
impl SimpleState for Pong {
fn on_start(&mut self, data: StateData<GameData>) {
let StateData { world, .. } = data;
use crate::audio::initialise_audio;
Expand Down
2 changes: 1 addition & 1 deletion examples/arc_ball_camera/main.rs
Expand Up @@ -22,7 +22,7 @@ type MyPrefabData = BasicScenePrefab<Vec<PosNormTex>>;

struct ExampleState;

impl<'a, 'b> SimpleState<'a, 'b> for ExampleState {
impl SimpleState for ExampleState {
fn on_start(&mut self, data: StateData<GameData>) {
let prefab_handle = data.world.exec(|loader: PrefabLoader<MyPrefabData>| {
loader.load("prefab/arc_ball_camera.ron", RonFormat, (), ())
Expand Down
2 changes: 1 addition & 1 deletion examples/asset_loading/main.rs
Expand Up @@ -63,7 +63,7 @@ impl SimpleFormat<Mesh> for Custom {

struct AssetsExample;

impl<'a, 'b> SimpleState<'a, 'b> for AssetsExample {
impl SimpleState for AssetsExample {
fn on_start(&mut self, data: StateData<GameData>) {
let StateData { world, .. } = data;
world.add_resource(0usize);
Expand Down
2 changes: 1 addition & 1 deletion examples/custom_ui/main.rs
Expand Up @@ -75,7 +75,7 @@ impl ToNativeWidget for CustomUi {

struct Example;

impl<'a, 'b> SimpleState<'a, 'b> for Example {
impl SimpleState for Example {
fn on_start(&mut self, data: StateData<GameData>) {
let StateData { world, .. } = data;
// Initialise the scene with an object, a light and a camera.
Expand Down
2 changes: 1 addition & 1 deletion examples/debug_lines/main.rs
Expand Up @@ -44,7 +44,7 @@ impl<'s> System<'s> for ExampleLinesSystem {
}

struct ExampleState;
impl<'a, 'b> SimpleState<'a, 'b> for ExampleState {
impl SimpleState for ExampleState {
fn on_start(&mut self, data: StateData<GameData>) {
// Setup debug lines as a resource
data.world
Expand Down
2 changes: 1 addition & 1 deletion examples/fly_camera/main.rs
Expand Up @@ -17,7 +17,7 @@ type MyPrefabData = BasicScenePrefab<Vec<PosNormTex>>;

struct ExampleState;

impl<'a, 'b> SimpleState<'a, 'b> for ExampleState {
impl SimpleState for ExampleState {
fn on_start(&mut self, data: StateData<GameData>) {
let prefab_handle = data.world.exec(|loader: PrefabLoader<MyPrefabData>| {
loader.load("prefab/fly_camera.ron", RonFormat, (), ())
Expand Down
10 changes: 3 additions & 7 deletions examples/gltf/main.rs
Expand Up @@ -51,7 +51,7 @@ struct ScenePrefabData {
fly_tag: Option<ControlTagPrefab>,
}

impl<'a, 'b> SimpleState<'a, 'b> for Example {
impl SimpleState for Example {
fn on_start(&mut self, data: StateData<GameData>) {
let StateData { world, .. } = data;

Expand All @@ -69,11 +69,7 @@ impl<'a, 'b> SimpleState<'a, 'b> for Example {
);
}

fn handle_event(
&mut self,
data: StateData<GameData>,
event: StateEvent,
) -> SimpleTrans<'a, 'b> {
fn handle_event(&mut self, data: StateData<GameData>, event: StateEvent) -> SimpleTrans {
let StateData { world, .. } = data;
if let StateEvent::Window(event) = &event {
if is_close_requested(&event) || is_key_down(&event, VirtualKeyCode::Escape) {
Expand All @@ -94,7 +90,7 @@ impl<'a, 'b> SimpleState<'a, 'b> for Example {
}
}

fn update(&mut self, data: &mut StateData<GameData>) -> SimpleTrans<'a, 'b> {
fn update(&mut self, data: &mut StateData<GameData>) -> SimpleTrans {
if !self.initialised {
let remove = match self.progress.as_ref().map(|p| p.complete()) {
None | Some(Completion::Loading) => false,
Expand Down
4 changes: 2 additions & 2 deletions examples/locale/main.rs
Expand Up @@ -27,7 +27,7 @@ impl Example {
}
}

impl<'a, 'b> SimpleState<'a, 'b> for Example {
impl SimpleState for Example {
fn on_start(&mut self, data: StateData<GameData>) {
data.world.add_resource(AssetStorage::<Locale>::new());
let mut progress_counter = ProgressCounter::default();
Expand Down Expand Up @@ -56,7 +56,7 @@ impl<'a, 'b> SimpleState<'a, 'b> for Example {
self.progress_counter = Some(progress_counter);
}

fn update(&mut self, data: &mut StateData<GameData>) -> SimpleTrans<'a, 'b> {
fn update(&mut self, data: &mut StateData<GameData>) -> SimpleTrans {
// Check if the locale has been loaded.
if self.progress_counter.as_ref().unwrap().is_complete() {
let store = data.world.read_resource::<AssetStorage<Locale>>();
Expand Down
2 changes: 1 addition & 1 deletion examples/material/main.rs
Expand Up @@ -13,7 +13,7 @@ use amethyst::{

struct Example;

impl<'a, 'b> SimpleState<'a, 'b> for Example {
impl SimpleState for Example {
fn on_start(&mut self, data: StateData<GameData>) {
let StateData { world, .. } = data;
let mat_defaults = world.read_resource::<MaterialDefaults>().0.clone();
Expand Down
2 changes: 1 addition & 1 deletion examples/net_client/main.rs
Expand Up @@ -31,7 +31,7 @@ fn main() -> Result<()> {

/// Default empty state
pub struct State1;
impl<'a, 'b> SimpleState<'a, 'b> for State1 {
impl SimpleState for State1 {
fn on_start(&mut self, data: StateData<GameData>) {
data.world
.create_entity()
Expand Down
2 changes: 1 addition & 1 deletion examples/net_server/main.rs
Expand Up @@ -30,7 +30,7 @@ fn main() -> Result<()> {

/// Default empty state
pub struct State1;
impl<'a, 'b> SimpleState<'a, 'b> for State1 {
impl SimpleState for State1 {
fn on_start(&mut self, data: StateData<GameData>) {
data.world
.create_entity()
Expand Down
2 changes: 1 addition & 1 deletion examples/pong/pong.rs
Expand Up @@ -13,7 +13,7 @@ use crate::{systems::ScoreText, Ball, Paddle, Side, ARENA_HEIGHT, ARENA_WIDTH};

pub struct Pong;

impl<'a, 'b> SimpleState<'a, 'b> for Pong {
impl SimpleState for Pong {
fn on_start(&mut self, data: StateData<GameData>) {
let StateData { world, .. } = data;
use crate::audio::initialise_audio;
Expand Down

0 comments on commit ac6b2b8

Please sign in to comment.