Skip to content

Commit

Permalink
port examples
Browse files Browse the repository at this point in the history
  • Loading branch information
AnneKitsune committed Jul 5, 2019
1 parent e51b464 commit db8283b
Show file tree
Hide file tree
Showing 40 changed files with 260 additions and 184 deletions.
11 changes: 4 additions & 7 deletions examples/arc_ball_camera/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ struct CameraDistanceSystem {
}

impl CameraDistanceSystem {
pub fn new() -> Self {
Self::SystemData::setup(res);
pub fn new(world: &mut World) -> Self {
<Self as System<'_>>::SystemData::setup(&mut world.res);
let event_reader = world.res.fetch_mut::<EventChannel<InputEvent<String>>>()
.register_reader();

Expand Down Expand Up @@ -103,9 +103,6 @@ impl<'a> System<'a> for CameraDistanceSystem {
}
}
}

fn setup(&mut self, res: &mut Resources) {
}
}

fn main() -> Result<(), Error> {
Expand All @@ -131,14 +128,14 @@ fn main() -> Result<(), Error> {
)?
.with_bundle(&mut world, ArcBallControlBundle::<StringBindings>::new())?
.with(
CameraDistanceSystem::new(),
CameraDistanceSystem::new(&mut world),
"camera_distance_system",
&["input_system"],
)
.with_thread_local(RenderingSystem::<DefaultBackend, _>::new(
ExampleGraph::default(),
));
let mut game = Application::build(resources_directory, ExampleState)?.build(game_data, world)?;
let mut game = Application::build(resources_directory, ExampleState, world)?.build(game_data)?;
game.run();
Ok(())
}
Expand Down
5 changes: 4 additions & 1 deletion examples/asset_custom/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use amethyst::{
Asset, AssetStorage, Format, Handle, Loader, ProcessingState, Processor, ProgressCounter,
Source,
},
ecs::VecStorage,
ecs::{VecStorage, World},
error::{format_err, Error, ResultExt},
prelude::*,
utils::application_root_dir,
Expand Down Expand Up @@ -124,6 +124,8 @@ fn main() -> amethyst::Result<()> {
let app_root = application_root_dir()?;
let assets_dir = app_root.join("assets");

let world = World::new();

let game_data = GameDataBuilder::default().with(Processor::<EnergyBlast>::new(), "", &[]);
let mut game = Application::new(
assets_dir,
Expand All @@ -132,6 +134,7 @@ fn main() -> amethyst::Result<()> {
energy_blast_handle: None,
},
game_data,
world,
)?;

game.run();
Expand Down
12 changes: 7 additions & 5 deletions examples/asset_loading/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use amethyst::{
assets::{Format as AssetFormat, Handle, Loader},
core::{math::Vector3, Transform, TransformBundle},
ecs::{ReadExpect, Resources, SystemData},
ecs::{ReadExpect, Resources, SystemData, World},
error::Error,
input::{InputBundle, StringBindings},
prelude::*,
Expand Down Expand Up @@ -130,14 +130,16 @@ fn main() -> Result<(), Error> {
let display_config_path =
app_root.join("{}/examples/asset_loading/resources/display_config.ron");

let mut world = World::new();

let game_data = GameDataBuilder::default()
.with_bundle(WindowBundle::from_config_path(display_config_path))?
.with_bundle(InputBundle::<StringBindings>::new())?
.with_bundle(TransformBundle::new())?
.with_bundle(&mut world, WindowBundle::from_config_path(display_config_path))?
.with_bundle(&mut world, InputBundle::<StringBindings>::new())?
.with_bundle(&mut world, TransformBundle::new())?
.with_thread_local(RenderingSystem::<DefaultBackend, _>::new(
ExampleGraph::default(),
));
let mut game = Application::new(resources_directory, AssetsExample, game_data)?;
let mut game = Application::new(resources_directory, AssetsExample, game_data, world)?;
game.run();
Ok(())
}
Expand Down
16 changes: 9 additions & 7 deletions examples/auto_fov/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use amethyst::{
},
core::{Transform, TransformBundle},
derive::PrefabData,
ecs::{Entity, ReadExpect, ReadStorage, Resources, System, WriteStorage},
ecs::{Entity, ReadExpect, ReadStorage, Resources, System, WriteStorage, World},
input::{is_close_requested, is_key_down, InputBundle, StringBindings},
prelude::{
Application, Builder, GameData, GameDataBuilder, SimpleState, SimpleTrans, StateData,
Expand Down Expand Up @@ -54,19 +54,21 @@ fn main() -> Result<(), Error> {
let display_config_path = app_dir.join("auto_fov/resources/display.ron");
let assets = app_dir.join("assets");

let mut world = World::new();

let game_data = GameDataBuilder::new()
.with_bundle(WindowBundle::from_config_path(display_config_path))?
.with(PrefabLoaderSystem::<ScenePrefab>::default(), "prefab", &[])
.with_bundle(&mut world, WindowBundle::from_config_path(display_config_path))?
.with(PrefabLoaderSystem::<ScenePrefab>::new(&mut world), "prefab", &[])
.with(AutoFovSystem::default(), "auto_fov", &["prefab"]) // This makes the system adjust the camera right after it has been loaded (in the same frame), preventing any flickering
.with(ShowFovSystem, "show_fov", &["auto_fov"])
.with_bundle(TransformBundle::new())?
.with_bundle(InputBundle::<StringBindings>::new())?
.with_bundle(UiBundle::<DefaultBackend, StringBindings>::new())?
.with_bundle(&mut world, TransformBundle::new())?
.with_bundle(&mut world, InputBundle::<StringBindings>::new())?
.with_bundle(&mut world, UiBundle::<DefaultBackend, StringBindings>::new())?
.with_thread_local(RenderingSystem::<DefaultBackend, _>::new(
ExampleGraph::default(),
));

let mut game = Application::build(assets, Loading::new())?.build(game_data)?;
let mut game = Application::build(assets, Loading::new(), world)?.build(game_data)?;
game.run();

Ok(())
Expand Down
4 changes: 2 additions & 2 deletions examples/custom_game_data/game_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ impl<'a, 'b> CustomGameDataBuilder<'a, 'b> {
self
}

pub fn with_base_bundle<B>(mut self, bundle: B) -> Result<Self, Error>
pub fn with_base_bundle<B>(mut self, world: &mut World, bundle: B) -> Result<Self, Error>
where
B: SystemBundle<'a, 'b>,
{
bundle.build(&mut self.base)?;
bundle.build(world, &mut self.base)?;
Ok(self)
}
pub fn with_thread_local<S>(mut self, system: S) -> Self
Expand Down
18 changes: 10 additions & 8 deletions examples/custom_game_data/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use amethyst::{
core::transform::TransformBundle,
ecs::{
prelude::{Component, Entity, ReadExpect, Resources, SystemData},
NullStorage,
NullStorage, World,
},
input::{is_close_requested, is_key_down, InputBundle, StringBindings},
prelude::*,
Expand Down Expand Up @@ -212,25 +212,27 @@ fn main() -> Result<(), Error> {
let display_config_path =
app_root.join("examples/custom_game_data/resources/display_config.ron");

let mut world = World::new();

// let pipeline_builder = Pipeline::build().with_stage(
// Stage::with_backbuffer()
// .clear_target([0.0, 0.0, 0.0, 1.0], 1.0)
// .with_pass(DrawShaded::<PosNormTex>::new())
// .with_pass(DrawUi::new()),
// );
let game_data = CustomGameDataBuilder::default()
.with_base(PrefabLoaderSystem::<MyPrefabData>::default(), "", &[])
.with_base(PrefabLoaderSystem::<MyPrefabData>::new(&mut world), "", &[])
.with_running::<ExampleSystem>(ExampleSystem::default(), "example_system", &[])
.with_base_bundle(TransformBundle::new())?
.with_base_bundle(UiBundle::<DefaultBackend, StringBindings>::new())?
.with_base_bundle(FpsCounterBundle::default())?
.with_base_bundle(InputBundle::<StringBindings>::new())?
.with_base_bundle(WindowBundle::from_config_path(display_config_path))?
.with_base_bundle(&mut world, TransformBundle::new())?
.with_base_bundle(&mut world, UiBundle::<DefaultBackend, StringBindings>::new())?
.with_base_bundle(&mut world, FpsCounterBundle::default())?
.with_base_bundle(&mut world, InputBundle::<StringBindings>::new())?
.with_base_bundle(&mut world, WindowBundle::from_config_path(display_config_path))?
.with_thread_local(RenderingSystem::<DefaultBackend, _>::new(
ExampleGraph::default(),
));

let mut game = Application::build(asset_dir, Loading::default())?.build(game_data)?;
let mut game = Application::build(asset_dir, Loading::default(), world)?.build(game_data)?;
game.run();

Ok(())
Expand Down
14 changes: 8 additions & 6 deletions examples/custom_ui/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use amethyst::{
assets::{PrefabLoader, PrefabLoaderSystem, RonFormat},
core::transform::TransformBundle,
ecs::prelude::{ReadExpect, Resources, SystemData},
ecs::prelude::{ReadExpect, Resources, SystemData, World},
input::StringBindings,
prelude::*,
renderer::{
Expand Down Expand Up @@ -105,15 +105,17 @@ fn main() -> amethyst::Result<()> {
let display_config_path = app_root.join("examples/custom_ui/resources/display.ron");
let resources = app_root.join("examples/assets");

let mut world = World::new();

let game_data = GameDataBuilder::default()
.with_bundle(WindowBundle::from_config_path(display_config_path))?
.with(PrefabLoaderSystem::<MyPrefabData>::default(), "", &[])
.with_bundle(TransformBundle::new())?
.with_bundle(UiBundle::<DefaultBackend, StringBindings, CustomUi>::new())?
.with_bundle(&mut world, WindowBundle::from_config_path(display_config_path))?
.with(PrefabLoaderSystem::<MyPrefabData>::new(&mut world), "", &[])
.with_bundle(&mut world, TransformBundle::new())?
.with_bundle(&mut world, UiBundle::<DefaultBackend, StringBindings, CustomUi>::new())?
.with_thread_local(RenderingSystem::<DefaultBackend, _>::new(
ExampleGraph::default(),
));
let mut game = Application::new(resources, Example, game_data)?;
let mut game = Application::new(resources, Example, game_data, world)?;
game.run();
Ok(())
}
Expand Down
13 changes: 8 additions & 5 deletions examples/debug_lines/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use amethyst::{
transform::{Transform, TransformBundle},
Time,
},
ecs::{Read, ReadExpect, Resources, System, SystemData, Write},
ecs::{Read, ReadExpect, Resources, System, SystemData, Write, World},
input::{is_close_requested, is_key_down, InputBundle, StringBindings},
prelude::*,
renderer::{
Expand Down Expand Up @@ -192,19 +192,22 @@ fn main() -> amethyst::Result<()> {
)
.with_sensitivity(0.1, 0.1);

let mut world = World::new();

let game_data = GameDataBuilder::default()
.with_bundle(WindowBundle::from_config_path(display_config_path))?
.with_bundle(&mut world, WindowBundle::from_config_path(display_config_path))?
.with_bundle(
&mut world,
InputBundle::<StringBindings>::new().with_bindings_from_file(&key_bindings_path)?,
)?
.with(ExampleLinesSystem, "example_lines_system", &[])
.with_bundle(fly_control_bundle)?
.with_bundle(TransformBundle::new().with_dep(&["fly_movement"]))?
.with_bundle(&mut world, fly_control_bundle)?
.with_bundle(&mut world, TransformBundle::new().with_dep(&["fly_movement"]))?
.with_thread_local(RenderingSystem::<DefaultBackend, _>::new(
ExampleGraph::default(),
));

let mut game = Application::new(resources, ExampleState, game_data)?;
let mut game = Application::new(resources, ExampleState, game_data, world)?;
game.run();
Ok(())
}
Expand Down
10 changes: 6 additions & 4 deletions examples/debug_lines_ortho/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use amethyst::{
transform::{Transform, TransformBundle},
Time,
},
ecs::{Read, ReadExpect, Resources, System, SystemData, Write},
ecs::{Read, ReadExpect, Resources, System, SystemData, Write, World},
prelude::*,
renderer::{
camera::Camera,
Expand Down Expand Up @@ -111,15 +111,17 @@ fn main() -> amethyst::Result<()> {
let display_config_path = app_root.join("examples/debug_lines_ortho/resources/display.ron");
let resources = app_root.join("examples/assets/");

let mut world = World::new();

let game_data = GameDataBuilder::default()
.with_bundle(WindowBundle::from_config_path(display_config_path))?
.with_bundle(TransformBundle::new())?
.with_bundle(&mut world, WindowBundle::from_config_path(display_config_path))?
.with_bundle(&mut world, TransformBundle::new())?
.with(ExampleLinesSystem, "example_lines_system", &["window"])
.with_thread_local(RenderingSystem::<DefaultBackend, _>::new(
ExampleGraph::default(),
));

let mut game = Application::new(resources, ExampleState, game_data)?;
let mut game = Application::new(resources, ExampleState, game_data, world)?;
game.run();
Ok(())
}
Expand Down
18 changes: 8 additions & 10 deletions examples/events/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use amethyst::{
frame_limiter::FrameRateLimitStrategy,
shrev::{EventChannel, ReaderId},
},
ecs::{DispatcherBuilder, Read, Resources, System, SystemData, World, Write},
ecs::{DispatcherBuilder, Read, System, SystemData, World, Write},
prelude::*,
};

Expand All @@ -17,12 +17,10 @@ use core::result::Result;
struct MyBundle;

impl<'a, 'b> SystemBundle<'a, 'b> for MyBundle {
fn build(self, builder: &mut DispatcherBuilder<'a, 'b>) -> Result<(), Error> {
fn build(self, world: &mut World, builder: &mut DispatcherBuilder<'a, 'b>) -> Result<(), Error> {
builder.add(SpammingSystem, "spamming_system", &[]);
builder.add(
ReceivingSystem {
reader: Option::None,
},
ReceivingSystem::new(world),
"receiving_system",
&[],
);
Expand Down Expand Up @@ -64,8 +62,8 @@ struct ReceivingSystem {
}

impl ReceivingSystem {
pub fn new(world: &mut World) {
Self::SystemData::setup(world.res);
pub fn new(world: &mut World) -> Self {
<Self as System<'_>>::SystemData::setup(&mut world.res);
let reader = world.res.fetch_mut::<EventChannel<MyEvent>>().register_reader();
ReceivingSystem {
reader
Expand All @@ -77,7 +75,7 @@ impl<'a> System<'a> for ReceivingSystem {
type SystemData = Read<'a, EventChannel<MyEvent>>;

fn run(&mut self, my_event_channel: Self::SystemData) {
for event in my_event_channel.read(self.reader) {
for event in my_event_channel.read(&mut self.reader) {
println!("Received an event: {:?}", event);
}
}
Expand All @@ -91,9 +89,9 @@ fn main() -> amethyst::Result<()> {
let mut world = World::new();
world.add_resource(EventChannel::<MyEvent>::new());

let game_data = GameDataBuilder::default().with_bundle(MyBundle)?;
let game_data = GameDataBuilder::default().with_bundle(&mut world, MyBundle)?;

let mut game = Application::build("./", GameplayState)?
let mut game = Application::build("./", GameplayState, world)?
.with_frame_limit(FrameRateLimitStrategy::Sleep, 1)
.build(game_data)?;

Expand Down
16 changes: 9 additions & 7 deletions examples/fly_camera/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use amethyst::{
assets::{PrefabLoader, PrefabLoaderSystem, RonFormat},
controls::{FlyControlBundle, HideCursor},
core::transform::TransformBundle,
ecs::{ReadExpect, Resources, SystemData},
ecs::{ReadExpect, Resources, SystemData, World},
input::{is_key_down, is_mouse_button_down, InputBundle, StringBindings},
prelude::*,
renderer::{
Expand Down Expand Up @@ -68,30 +68,32 @@ fn main() -> Result<(), Error> {
let app_root = application_root_dir()?;

let resources_directory = app_root.join("examples/assets");

let display_config_path = app_root.join("examples/fly_camera/resources/display_config.ron");

let key_bindings_path = app_root.join("examples/fly_camera/resources/input.ron");

let mut world = World::new();

let game_data = GameDataBuilder::default()
.with_bundle(WindowBundle::from_config_path(display_config_path))?
.with(PrefabLoaderSystem::<MyPrefabData>::default(), "", &[])
.with_bundle(&mut world, WindowBundle::from_config_path(display_config_path))?
.with(PrefabLoaderSystem::<MyPrefabData>::new(&mut world), "", &[])
.with_bundle(
&mut world,
FlyControlBundle::<StringBindings>::new(
Some(String::from("move_x")),
Some(String::from("move_y")),
Some(String::from("move_z")),
)
.with_sensitivity(0.1, 0.1),
)?
.with_bundle(TransformBundle::new().with_dep(&["fly_movement"]))?
.with_bundle(&mut world, TransformBundle::new().with_dep(&["fly_movement"]))?
.with_bundle(
&mut world,
InputBundle::<StringBindings>::new().with_bindings_from_file(&key_bindings_path)?,
)?
.with_thread_local(RenderingSystem::<DefaultBackend, _>::new(
ExampleGraph::default(),
));
let mut game = Application::build(resources_directory, ExampleState)?.build(game_data)?;
let mut game = Application::build(resources_directory, ExampleState, world)?.build(game_data)?;
game.run();
Ok(())
}
Expand Down
Loading

0 comments on commit db8283b

Please sign in to comment.