Skip to content

Commit

Permalink
Refactor Transform in the book
Browse files Browse the repository at this point in the history
  • Loading branch information
CBenoit committed Apr 18, 2019
1 parent 39b0202 commit a65703b
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 36 deletions.
2 changes: 1 addition & 1 deletion book/src/assets/how_to_use_assets.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ This guide covers the basic usage of assets into Amethyst for existing supported
let game_data = GameDataBuilder::default()
.with_bundle(UiBundle::<String, String>::new())?
.with_bundle(
RenderBundle::new(pipeline, Some(display_config))
RenderBundle::<'_, _, _, f32>::new(pipeline, Some(display_config))
.with_sprite_sheet_processor()
)?;
Expand Down
10 changes: 5 additions & 5 deletions book/src/concepts/system.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ struct WalkPlayerUp {
}
impl<'a> System<'a> for WalkPlayerUp {
type SystemData = WriteStorage<'a, Transform>;
type SystemData = WriteStorage<'a, Transform<f32>>;
fn run(&mut self, mut transforms: Self::SystemData) {
transforms.get_mut(self.player).unwrap().translate_y(0.1);
Expand Down Expand Up @@ -116,7 +116,7 @@ struct MakeObjectsFall;
impl<'a> System<'a> for MakeObjectsFall {
type SystemData = (
WriteStorage<'a, Transform>,
WriteStorage<'a, Transform<f32>>,
ReadStorage<'a, FallingObject>,
);
Expand Down Expand Up @@ -154,7 +154,7 @@ struct NotFallingObjects;
impl<'a> System<'a> for NotFallingObjects {
type SystemData = (
WriteStorage<'a, Transform>,
WriteStorage<'a, Transform<f32>>,
ReadStorage<'a, FallingObject>,
);
Expand Down Expand Up @@ -191,7 +191,7 @@ struct SpawnEnemies {
impl<'a> System<'a> for SpawnEnemies {
type SystemData = (
WriteStorage<'a, Transform>,
WriteStorage<'a, Transform<f32>>,
WriteStorage<'a, Enemy>,
Entities<'a>,
);
Expand Down Expand Up @@ -244,7 +244,7 @@ struct MakeObjectsFall;
impl<'a> System<'a> for MakeObjectsFall {
type SystemData = (
Entities<'a>,
WriteStorage<'a, Transform>,
WriteStorage<'a, Transform<f32>>,
ReadStorage<'a, FallingObject>,
);
Expand Down
6 changes: 3 additions & 3 deletions book/src/pong-tutorial/pong-tutorial-01.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ let pipe = Pipeline::build()
.with_stage(
Stage::with_backbuffer()
.clear_target([0.0, 0.0, 0.0, 1.0], 1.0)
.with_pass(DrawFlat2D::new()),
.with_pass(DrawFlat2D::<f32>::new()),
);
# }
```
Expand All @@ -172,13 +172,13 @@ let pipe = Pipeline::build()
.with_stage(
# Stage::with_backbuffer()
# .clear_target([0.0, 0.0, 0.0, 1.0], 1.0)
# .with_pass(DrawFlat2D::new()),
# .with_pass(DrawFlat2D::<f32>::new()),
// --snip--
);
let game_data = GameDataBuilder::default()
.with_bundle(
RenderBundle::new(pipe, Some(config))
RenderBundle::<'_, _, _, f32>::new(pipe, Some(config))
.with_sprite_sheet_processor()
)?;
Expand Down
6 changes: 4 additions & 2 deletions book/src/pong-tutorial/pong-tutorial-02.md
Original file line number Diff line number Diff line change
Expand Up @@ -378,16 +378,18 @@ fn main() -> amethyst::Result<()> {
# let config = DisplayConfig::load(&path);
# let pipe = Pipeline::build().with_stage(Stage::with_backbuffer()
# .clear_target([0.0, 0.0, 0.0, 1.0], 1.0)
# .with_pass(DrawFlat2D::new()),
# .with_pass(DrawFlat2D::<f32>::new()),
# );
# struct Pong;
# impl SimpleState for Pong { }
let game_data = GameDataBuilder::default()
.with_bundle(
RenderBundle::new(pipe, Some(config))
RenderBundle::<'_, _, _, f32>::new(pipe, Some(config))
.with_sprite_sheet_processor()
)?
.with_bundle(TransformBundle::new())?;
# let assets_dir = "/";
# let mut game = Application::new(assets_dir, Pong, game_data)?;
# Ok(())
}
```
Expand Down
18 changes: 11 additions & 7 deletions book/src/pong-tutorial/pong-tutorial-03.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ let input_bundle = InputBundle::<String, String>::new()
# let config = DisplayConfig::load(&path);
# let pipe = Pipeline::build().with_stage(Stage::with_backbuffer()
# .clear_target([0.0, 0.0, 0.0, 1.0], 1.0)
# .with_pass(DrawFlat::<PosTex>::new()),
# .with_pass(DrawFlat::<PosTex, f32>::new()),
# );
# struct Pong;
# impl SimpleState for Pong { }
let game_data = GameDataBuilder::default()
.with_bundle(RenderBundle::new(pipe, Some(config)).with_sprite_sheet_processor())?
.with_bundle(RenderBundle::<'_, _, _, f32>::new(pipe, Some(config)).with_sprite_sheet_processor())?
.with_bundle(TransformBundle::new())?
.with_bundle(input_bundle)?;
let mut game = Application::new("./", Pong, game_data)?;
Expand Down Expand Up @@ -134,7 +134,7 @@ pub struct PaddleSystem;
impl<'s> System<'s> for PaddleSystem {
type SystemData = (
WriteStorage<'s, Transform>,
WriteStorage<'s, Transform<f32>>,
ReadStorage<'s, Paddle>,
Read<'s, InputHandler<String, String>>,
);
Expand Down Expand Up @@ -210,7 +210,7 @@ fn main() -> amethyst::Result<()> {
# let config = DisplayConfig::load(&path);
# let pipe = Pipeline::build().with_stage(Stage::with_backbuffer()
# .clear_target([0.0, 0.0, 0.0, 1.0], 1.0)
# .with_pass(DrawFlat::<PosTex>::new()),
# .with_pass(DrawFlat::<PosTex, f32>::new()),
# );
# mod systems {
# use amethyst;
Expand All @@ -222,10 +222,14 @@ fn main() -> amethyst::Result<()> {
# }
# let input_bundle = amethyst::input::InputBundle::<String, String>::new();
let game_data = GameDataBuilder::default()
.with_bundle(RenderBundle::new(pipe, Some(config)).with_sprite_sheet_processor())?
.with_bundle(RenderBundle::<'_, _, _, f32>::new(pipe, Some(config)).with_sprite_sheet_processor())?
.with_bundle(TransformBundle::new())?
.with_bundle(input_bundle)?
.with(systems::PaddleSystem, "paddle_system", &["input_system"]); // Add this line
# let assets_dir = "/";
# struct Pong;
# impl SimpleState for Pong { }
# let mut game = Application::new(assets_dir, Pong, game_data)?;
# Ok(())
}
```
Expand Down Expand Up @@ -261,7 +265,7 @@ component of the transform's translation.
# pub struct PaddleSystem;
# impl<'s> System<'s> for PaddleSystem {
# type SystemData = (
# WriteStorage<'s, Transform>,
# WriteStorage<'s, Transform<f32>>,
# ReadStorage<'s, Paddle>,
# Read<'s, InputHandler<String, String>>,
# );
Expand Down Expand Up @@ -321,7 +325,7 @@ Our run function should now look something like this:
# pub struct PaddleSystem;
# impl<'s> System<'s> for PaddleSystem {
# type SystemData = (
# WriteStorage<'s, Transform>,
# WriteStorage<'s, Transform<f32>>,
# ReadStorage<'s, Paddle>,
# Read<'s, InputHandler<String, String>>,
# );
Expand Down
12 changes: 8 additions & 4 deletions book/src/pong-tutorial/pong-tutorial-04.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ pub struct MoveBallsSystem;
impl<'s> System<'s> for MoveBallsSystem {
type SystemData = (
ReadStorage<'s, Ball>,
WriteStorage<'s, Transform>,
WriteStorage<'s, Transform<f32>>,
Read<'s, Time>,
);
Expand Down Expand Up @@ -249,7 +249,7 @@ impl<'s> System<'s> for BounceSystem {
type SystemData = (
WriteStorage<'s, Ball>,
ReadStorage<'s, Paddle>,
ReadStorage<'s, Transform>,
ReadStorage<'s, Transform<f32>>,
);
fn run(&mut self, (mut balls, paddles, transforms): Self::SystemData) {
Expand Down Expand Up @@ -324,7 +324,7 @@ as well as adding our new systems to the game data:
# let config = DisplayConfig::load(&path);
# let pipe = Pipeline::build().with_stage(Stage::with_backbuffer()
# .clear_target([0.0, 0.0, 0.0, 1.0], 1.0)
# .with_pass(DrawFlat::<PosTex>::new()),
# .with_pass(DrawFlat::<PosTex, f32>::new()),
# );
# mod systems {
# use amethyst;
Expand All @@ -346,7 +346,7 @@ as well as adding our new systems to the game data:
# }
# let input_bundle = amethyst::input::InputBundle::<String, String>::new();
let game_data = GameDataBuilder::default()
# .with_bundle(RenderBundle::new(pipe, Some(config)).with_sprite_sheet_processor())?
# .with_bundle(RenderBundle::<'_, _, _, f32>::new(pipe, Some(config)).with_sprite_sheet_processor())?
# .with_bundle(TransformBundle::new())?
# .with_bundle(input_bundle)?
# .with(systems::PaddleSystem, "paddle_system", &["input_system"])
Expand All @@ -357,6 +357,10 @@ let game_data = GameDataBuilder::default()
"collision_system",
&["paddle_system", "ball_system"],
);
# let assets_dir = "/";
# struct Pong;
# impl SimpleState for Pong { }
# let mut game = Application::new(assets_dir, Pong, game_data)?;
# Ok(())
# }
```
Expand Down
24 changes: 16 additions & 8 deletions book/src/pong-tutorial/pong-tutorial-05.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub struct WinnerSystem;
impl<'s> System<'s> for WinnerSystem {
type SystemData = (
WriteStorage<'s, Ball>,
WriteStorage<'s, Transform>,
WriteStorage<'s, Transform<f32>>,
);
fn run(&mut self, (mut balls, mut locals): Self::SystemData) {
Expand Down Expand Up @@ -136,12 +136,12 @@ keep playing after someone scores and log who got the point.
# let config = DisplayConfig::load(&path);
# let pipe = Pipeline::build().with_stage(Stage::with_backbuffer()
# .clear_target([0.0, 0.0, 0.0, 1.0], 1.0)
# .with_pass(DrawFlat2D::new()),
# .with_pass(DrawFlat2D::<f32>::new()),
# );
# let input_bundle = amethyst::input::InputBundle::<String, String>::new();
#
let game_data = GameDataBuilder::default()
# .with_bundle(RenderBundle::new(pipe, Some(config)).with_sprite_sheet_processor())?
# .with_bundle(RenderBundle::<'_, _, _, f32>::new(pipe, Some(config)).with_sprite_sheet_processor())?
# .with_bundle(TransformBundle::new())?
# .with_bundle(input_bundle)?
# .with(systems::PaddleSystem, "paddle_system", &["input_system"])
Expand All @@ -154,6 +154,10 @@ let game_data = GameDataBuilder::default()
// --snip--
.with(systems::WinnerSystem, "winner_system", &["ball_system"]);
#
# let assets_dir = "/";
# struct Pong;
# impl SimpleState for Pong { }
# let mut game = Application::new(assets_dir, Pong, game_data)?;
# Ok(())
# }
```
Expand Down Expand Up @@ -218,13 +222,13 @@ fn main() -> amethyst::Result<()> {
# let config = DisplayConfig::load(&path);
let pipe = Pipeline::build().with_stage(Stage::with_backbuffer()
.clear_target([0.0, 0.0, 0.0, 1.0], 1.0)
.with_pass(DrawFlat2D::new())
.with_pass(DrawFlat2D::<f32>::new())
.with_pass(DrawUi::new()), // <-- Add me
);
# let input_bundle = amethyst::input::InputBundle::<String, String>::new();
#
let game_data = GameDataBuilder::default()
.with_bundle(RenderBundle::new(pipe, Some(config))
.with_bundle(RenderBundle::<'_, _, _, f32>::new(pipe, Some(config))
.with_sprite_sheet_processor())?
.with_bundle(TransformBundle::new())?
.with_bundle(input_bundle)?
Expand All @@ -239,8 +243,12 @@ fn main() -> amethyst::Result<()> {
# &["paddle_system", "ball_system"],
# )
# .with(systems::WinnerSystem, "winner_system", &["ball_system"]);
#
# Ok(())
#
# let assets_dir = "/";
# struct Pong;
# impl SimpleState for Pong { }
# let mut game = Application::new(assets_dir, Pong, game_data)?;
# Ok(())
}
```

Expand Down Expand Up @@ -777,7 +785,7 @@ pub struct WinnerSystem;
impl<'s> System<'s> for WinnerSystem {
type SystemData = (
WriteStorage<'s, Ball>,
WriteStorage<'s, Transform>,
WriteStorage<'s, Transform<f32>>,
WriteStorage<'s, UiText>,
Write<'s, ScoreBoard>,
ReadExpect<'s, ScoreText>,
Expand Down
2 changes: 1 addition & 1 deletion book/src/prefabs/how_to_define_prefabs_prelude.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Component | Serialized representation | Example(s) |
# use specs_derive::Component;
#
# #[derive(Component, Debug, Deserialize, Serialize /* .. */)]
# pub struct Position(pub f32, pub f32, pub f32);
# pub struct Position{pub x: f32, pub y: f32, pub z:f32};
#
impl From<(i32, i32, i32)> for Position {
fn from((x, y, z): (i32, i32, i32)) -> Position {
Expand Down
4 changes: 2 additions & 2 deletions book/src/prefabs/prefabs_technical_explanation.md
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ Lets look at an example of an aggregate struct:
#[derive(PrefabData)]
pub struct MyScenePrefab {
mesh: AssetPrefab<Mesh, ObjFormat>,
transform: Transform,
transform: Transform<f32>,
}
```

Expand All @@ -275,7 +275,7 @@ One last example that also adds a custom pure data `Component` into the aggregat
#[derive(PrefabData)]
pub struct MyScenePrefab {
mesh: AssetPrefab<Mesh, ObjFormat>,
transform: Transform,
transform: Transform<f32>,
#[prefab(Component)]
some: SomeComponent,
Expand Down
6 changes: 3 additions & 3 deletions book/src/sprites/set_up_the_render_pass.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ fn main() -> amethyst::Result<()> {
Stage::with_backbuffer()
.clear_target([0., 0., 0., 1.], 1.)
.with_pass(
DrawFlat2D::new()
.with_transparency(ColorMask::all(), ALPHA, None)),
DrawFlat2D::<f32>::new()
.with_transparency_settings(ColorMask::all(), ALPHA, None)),
);
let game_data = GameDataBuilder::default()
# .with_bundle(TransformBundle::new())?
.with_bundle(
RenderBundle::new(pipe, Some(display_config))
RenderBundle::<'_, _, _, f32>::new(pipe, Some(display_config))
.with_sprite_sheet_processor())?
# .with_bundle(InputBundle::<String, String>::new())?
Expand Down

0 comments on commit a65703b

Please sign in to comment.