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

Convert to specs v0.9 #250

Merged
merged 7 commits into from Jun 30, 2017
Merged

Convert to specs v0.9 #250

merged 7 commits into from Jun 30, 2017

Conversation

zakarumych
Copy link
Member

Convert to specs v0.9.1

@zakarumych zakarumych changed the title Developer Convert to specs v0.9 Jun 30, 2017
Copy link
Member

@torkleyy torkleyy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thanks for the PR! I added some comments, and I'd ask you to also do some formatting and import reordering.

@@ -7,7 +7,7 @@ extern crate cgmath;
use amethyst::{Application, ElementState, Event, State, Trans, VirtualKeyCode, WindowEvent};
use amethyst::asset_manager::{AssetManager, DirectoryStore};
use amethyst::project::Config;
use amethyst::ecs::{Join, System, RunArg, World};
use amethyst::ecs::{Join, System, World, WriteStorage, Fetch, FetchMut};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please order imports alphabetically.


type SystemData = (WriteStorage<'a, Ball>, WriteStorage<'a, Plank>, WriteStorage<'a, LocalTransform>, Fetch<'a, Camera>, Fetch<'a, Time>, Fetch<'a, InputHandler>, FetchMut<'a, Score>);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind adding a line break here?

use wavefront_obj::obj::{ObjSet, parse, Primitive};

use ecs::{Allocator, Component, Entity, GatedStorage, MaskedStorage, Storage, VecStorage, World};
use ecs::{Component, Entity, VecStorage, World, ReadStorage};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, please move ReadStorage before VecStorage.

//! fn main() {
//! use amethyst::ecs::Gate;
//!
//! fn main() {//!
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the //! is necessary here.

use ticketed_lock::ReadTicket;

use ecs::{World, Component, EntityBuilder, GatedStorage, Allocator, MaskedStorage, Join};
use ecs::{World, Component, EntityBuilder, Join, ReadStorage};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We didn't have it before, but it would be nice to sort these imports, too.

self.world.entities().join().collect::<Vec<_>>()
};
for entity in entities {
self.world.delete_entity(entity);
}
self.world.maintain();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this call is necessary, dunno why it is there.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I should move it to the end of Application::advance_frame

@@ -64,10 +65,11 @@ impl Application {
assets.add_loader::<gfx_types::Factory>(factory);

let trans_sys = TransformSystem::new();
planner.add_system::<TransformSystem>(trans_sys, "transform_system", 0);

let dispatcher_builder = dispatcher_builder.add_barrier();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed on Gitter, it would be preferable to give the responsibility of adding "default" systems to the user.

pub fn new(initial_state: T, cfg: DisplayConfig) -> ApplicationBuilder<T> {
let pool = Arc::new(ThreadPool::new(num_cpus::get()));
pub fn new(initial_state: T, cfg: DisplayConfig) -> ApplicationBuilder<'a, T> {
let pool = Arc::new(ThreadPool::new( ::rayon::Configuration::new().num_threads(num_cpus::get())).unwrap());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you format the code in some way? Seems there is unnecessary whitespace. And please add an import statement inside the function.

Additionally, consider using expect over unwrap.

{
self.planner.add_system::<S>(sys, name, pri);
self.dispatcher_builder = self.dispatcher_builder.add(sys, name, dep);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if we should just wrap the functionality. Could we just let the user pass in the dispatcher with all systems already added?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same way we could just let the user to pass world with all Components added.
But there is interesting feature in @ebkalderons fork. SystemExtwhich can be used to add all related components. We could use it inApplicationBuilder`'s wrapping functions

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not integrate it into Specs? I didn't know about that, but it would be helpful, yeah.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh well, it seems it isn't 100% compatible with our existing builders...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there should be two possibilities for user now
Use ApplicationBuilder and add Systems and register Components through it.
Create Application instance directly passing Dispatcher with all Systems and World with all Components added.

Copy link
Member

@torkleyy torkleyy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for addressing my comments! I added some more comments.

@@ -3,8 +3,10 @@ extern crate amethyst;
use amethyst::{Application, Event, State, Trans, VirtualKeyCode, WindowEvent};
use amethyst::asset_manager::AssetManager;
use amethyst::project::Config;
use amethyst::ecs::{World, Join, VecStorage, Component, RunArg, System};
use amethyst::ecs::{World, Join, VecStorage, Component, System, WriteStorage, Fetch, FetchMut};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs reordering.

if plank.position + plank.dimensions[1] / 2. < 1. {
plank.position += plank.velocity * delta_time;
}
}
// If `S` is pressed and plank is in screen boundaries then move down
if input.key_down(VirtualKeyCode::S) {
if input.key_is_pressed(VirtualKeyCode::S) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need a rebase here.

pub fn with<S>(mut self, sys: S, name: &str, pri: Priority) -> ApplicationBuilder<T>
where S: System<()> + 'static
/// Adds a given thread-local system `sys`
/// All thread-local systems executed sequentially after all non-thread-local systems
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add an "are" in here?

src/lib.rs Outdated
@@ -84,7 +84,7 @@ extern crate genmesh;
extern crate imagefmt;
extern crate num_cpus;
extern crate specs;
extern crate threadpool;
extern crate rayon;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, have to nitpick here again - please move the rayon line up by one.

@@ -3,7 +3,7 @@
use cgmath::Matrix4;
use fnv::{FnvHashMap as HashMap, FnvHashSet as HashSet};

use ecs::{Join, Entity, RunArg, System};
use ecs::{Entity, Join, WriteStorage, ReadStorage, Entities, System};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs reordering.

@@ -214,6 +213,8 @@ fn main() {
let path = format!("{}/examples/05_assets/resources/config.yml",
env!("CARGO_MANIFEST_DIR"));
let cfg = DisplayConfig::load(path);
let mut game = Application::build(Example, cfg).done();
let mut game = Application::build(Example, cfg)
.with_thread_local::<TransformSystem>(TransformSystem::new())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure TransformSystem is thread-local?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well. After you mention that I think it is not :)

@@ -342,7 +335,8 @@ fn main() {
let mut game = Application::build(Pong, cfg)
.register::<Ball>()
.register::<Plank>()
.with::<PongSystem>(PongSystem, "pong_system", 1)
.with::<PongSystem>(PongSystem, "pong_system", &[])
.with_thread_local::<TransformSystem>(TransformSystem::new())
Copy link
Member

@torkleyy torkleyy Jun 30, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here (see one of the comments below).

@@ -292,7 +285,8 @@ fn main() {
env!("CARGO_MANIFEST_DIR"));
let cfg = DisplayConfig::load(path);
let mut game = Application::build(Example, cfg)
.with::<ExampleSystem>(ExampleSystem, "example_system", 1)
.with::<ExampleSystem>(ExampleSystem, "example_system", &[])
.with_thread_local::<TransformSystem>(TransformSystem::new())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

Copy link
Member

@ebkalderon ebkalderon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@omni-viral Since you submitted ebkalderon#2, won't this PR conflict when I merge into develop again? I think we should accept this PR into the mainline and then I'll rebase on my end.

@zakarumych
Copy link
Member Author

zakarumych commented Jun 30, 2017

@ebkalderon There might be conflicts. You may rebase and reject ebkalderon/amethyst#2

@ebkalderon
Copy link
Member

@omni-viral Sweet, I reverted it successfully. I will rebase on top of this PR once it's ready for merge!

@torkleyy
Copy link
Member

@ebkalderon I'd like to review once more, if that's okay?

@ebkalderon
Copy link
Member

Of course, go right ahead.

Copy link
Member

@torkleyy torkleyy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks @omni-viral!

Copy link
Member

@Xaeroxe Xaeroxe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Thanks for your work!

@zakarumych
Copy link
Member Author

Thank you all for your feedback!
I'm glad I can help :)


ApplicationBuilder {
config: cfg,
initial_state: initial_state,
planner: Planner::from_pool(World::new(), pool),
dispatcher_builder: DispatcherBuilder::new().with_pool(pool),
world: World::new(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hold on, shouldn't we give the user the chance to access the World before starting the game? Not exactly sure about it.

Copy link
Member

@Xaeroxe Xaeroxe Jun 30, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think so. There is a space between when the Application is built and when we call .run() on it, so all it would take is adding a .world_mut() function to the Application.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or passing in World instead of creating it inside the ApplicationBuilder.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either or. Both are functionally the same I think.

Copy link
Member

@Xaeroxe Xaeroxe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@omni-viral I know this didn't exist prior to your pull request, but could you add a way for users to initialize the game world prior to executing .run() for the application? @torkleyy and I have both suggested some ways to do this, either is fine.

Copy link
Member

@Xaeroxe Xaeroxe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect, thank you!

@ebkalderon
Copy link
Member

ebkalderon commented Jun 30, 2017

@torkleyy Heads up! It's possible that this pull request might break your ongoing asset management work on #244. Please make sure to rebase against the latest develop if any breakage occurs.

@torkleyy
Copy link
Member

@ebkalderon How is that? I don't even depend on amethyst crate so far, so I don't think I will have any problems rebasing.

Copy link
Member

@torkleyy torkleyy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can merge now, thanks again @omni-viral!

@ebkalderon ebkalderon merged commit 4e3d397 into amethyst:develop Jun 30, 2017
@zakarumych zakarumych deleted the developer branch July 1, 2017 06:52
@nchashch nchashch mentioned this pull request Jul 3, 2017
13 tasks
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants