Skip to content

Commit

Permalink
Merge amethyst#346
Browse files Browse the repository at this point in the history
346: Upgrade shred r=torkleyy a=torkleyy



<!-- Reviewable:start -->
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/slide-rs/specs/346)
<!-- Reviewable:end -->
  • Loading branch information
bors[bot] committed Feb 17, 2018
2 parents 489a1ca + a6cdf97 commit dd81261
Show file tree
Hide file tree
Showing 20 changed files with 89 additions and 246 deletions.
7 changes: 3 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Specs is an Entity-Component System library written in Rust.
"""
documentation = "https://docs.rs/specs/"
repository = "https://github.com/slide-rs/specs"
homepage = "https://slide-rs.github.io/specs-website/"
homepage = "https://slide-rs.github.io/"
readme = "README.md"
keywords = ["gamedev"]
categories = ["concurrency"]
Expand All @@ -23,9 +23,9 @@ derivative = "1"
fnv = "1.0"
hibitset = { version = "0.4.1", features = ["parallel"] }
mopa = "0.2"
shred = "0.5.0"
shred = "0.6.0"
shrev = "0.8.0"
shred-derive = "0.3"
shred-derive = "0.4"
tuple_utils = "0.2"
rayon = "0.8.2"

Expand All @@ -47,7 +47,6 @@ cgmath = { version = "0.14", features = ["eders"] }
ron = "0.1.3"
rand = "0.3"
serde_json = "1.0"
#specs-derive = "0.1"
specs-derive = { path = "specs-derive", version = "0.2.0" }

[[example]]
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ fn main() {
// logical dependencies on other systems.
// Since we only have one, we don't depend on anything.
// See the `full` example for dependencies.
let mut dispatcher = DispatcherBuilder::new().add(SysA, "sys_a", &[]).build();
let mut dispatcher = DispatcherBuilder::new().with(SysA, "sys_a", &[]).build();

// This dispatches all the systems in parallel (but blocking).
dispatcher.dispatch(&mut world.res);
Expand Down
8 changes: 4 additions & 4 deletions benches/parallel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,10 +337,10 @@ fn bench_parallel(b: &mut Bencher) {
}

let mut d = DispatcherBuilder::new()
.add(RequestSpawns, "req_spawns", &[])
.add(GenCollisions, "gen_collisions", &[])
.add(Spawn, "spawn", &[])
.add(Integrate, "integrate", &[])
.with(RequestSpawns, "req_spawns", &[])
.with(GenCollisions, "gen_collisions", &[])
.with(Spawn, "spawn", &[])
.with(Integrate, "integrate", &[])
.build();

b.iter(|| {
Expand Down
8 changes: 4 additions & 4 deletions book/src/03_dispatcher.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ First of all, we have to build such a dispatcher.
use specs::DispatcherBuilder;
let mut dispatcher = DispatcherBuilder::new()
.add(hello_world, "hello_world", &[])
.with(hello_world, "hello_world", &[])
.build();
```

Expand Down Expand Up @@ -85,7 +85,7 @@ same for every entity). The solution to this are `Resource`s, see
Okay, now you can add another system *after* the `HelloWorld` system:

```rust,ignore
.add(UpdatePos, "update_pos", &["hello_world"])
.with(UpdatePos, "update_pos", &["hello_world"])
```

The `UpdatePos` system now depends on the `HelloWorld` system and will only
Expand Down Expand Up @@ -169,8 +169,8 @@ fn main() {
.build();
let mut dispatcher = DispatcherBuilder::new()
.add(HelloWorld, "hello_world", &[])
.add(UpdatePos, "update_pos", &["hello_world"])
.with(HelloWorld, "hello_world", &[])
.with(UpdatePos, "update_pos", &["hello_world"])
.build();
dispatcher.dispatch(&mut world.res);
Expand Down
2 changes: 1 addition & 1 deletion book/src/09_rendering.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Adding one is a simple line added to the builder code:

```rust,ignore
DispatcherBuilder::new()
.add_thread_local(RenderSys);
.with_thread_local(RenderSys);
```

## Amethyst
Expand Down
2 changes: 1 addition & 1 deletion examples/async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ fn main() {
// Since we only have one, we don't depend on anything.
// See the `full` example for dependencies.
let mut dispatcher = DispatcherBuilder::new()
.add(SysA, "sys_a", &[])
.with(SysA, "sys_a", &[])
.build_async(world);

// This dispatches all the systems in parallel and async.
Expand Down
2 changes: 1 addition & 1 deletion examples/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ fn main() {
// logical dependencies on other systems.
// Since we only have one, we don't depend on anything.
// See the `full` example for dependencies.
let mut dispatcher = DispatcherBuilder::new().add(SysA, "sys_a", &[]).build();
let mut dispatcher = DispatcherBuilder::new().with(SysA, "sys_a", &[]).build();

// This dispatches all the systems in parallel (but blocking).
dispatcher.dispatch(&world.res);
Expand Down
6 changes: 3 additions & 3 deletions examples/cluster_bomb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ fn main() {
.build();

let mut dispatcher = DispatcherBuilder::new()
.add(PhysicsSystem, "physics", &[])
.add(ClusterBombSystem, "cluster_bombs", &[])
.add(ShrapnelSystem, "shrapnels", &[])
.with(PhysicsSystem, "physics", &[])
.with(ClusterBombSystem, "cluster_bombs", &[])
.with(ShrapnelSystem, "shrapnels", &[])
.build();

let mut step = 0;
Expand Down
2 changes: 1 addition & 1 deletion examples/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ fn main() {
world.create_entity().with(future_sqrt(25.0)).build();

let mut dispatcher = DispatcherBuilder::new()
.add(Merge::<MyFuture>::new(), "merge_my_float", &[])
.with(Merge::<MyFuture>::new(), "merge_my_float", &[])
.build();

dispatcher.dispatch(&world.res);
Expand Down
12 changes: 6 additions & 6 deletions examples/full.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,12 +210,12 @@ fn main() {
// because we want to print the components before executing
// `SysCheckPositive`.
let mut dispatcher = DispatcherBuilder::new()
.add(SysPrintBool, "print_bool", &[])
.add(SysCheckPositive, "check_positive", &["print_bool"])
.add(SysStoreMax::new(), "store_max", &["check_positive"])
.add(SysSpawn::new(), "spawn", &[])
.add(SysPrintBool, "print_bool2", &["check_positive"])
.add(JoinParallel, "join_par", &[])
.with(SysPrintBool, "print_bool", &[])
.with(SysCheckPositive, "check_positive", &["print_bool"])
.with(SysStoreMax::new(), "store_max", &["check_positive"])
.with(SysSpawn::new(), "spawn", &[])
.with(SysPrintBool, "print_bool2", &["check_positive"])
.with(JoinParallel, "join_par", &[])
.build();

dispatcher.dispatch(&w.res);
Expand Down
2 changes: 1 addition & 1 deletion examples/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ fn main() {
.build();

let mut dispatcher = DispatcherBuilder::new()
.add(SerializeSystem, "ser", &[])
.with(SerializeSystem, "ser", &[])
.build();

dispatcher.dispatch(&mut world.res);
Expand Down
4 changes: 2 additions & 2 deletions examples/track.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ fn main() {
}

let mut dispatcher = DispatcherBuilder::new()
.add(sysa, "sys_a", &[])
.add(SysB::default(), "sys_b", &[])
.with(sysa, "sys_a", &[])
.with(SysB::default(), "sys_b", &[])
.build();

dispatcher.dispatch(&mut world.res);
Expand Down
4 changes: 2 additions & 2 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ where
);

fn run(&mut self, (entities, errors, mut futures, mut pers): Self::SystemData) {
for (e, _) in (&*entities, &futures.check()).join() {
for (e, _) in (&*entities, &futures.mask().clone()).join() {
self.spawns.push((e, spawn(futures.remove(e).unwrap())));
}

Expand Down Expand Up @@ -324,7 +324,7 @@ mod test {

let system: Merge<TestFuture> = Merge::new();

let mut dispatcher = DispatcherBuilder::new().add(system, "merge", &[]).build();
let mut dispatcher = DispatcherBuilder::new().with(system, "merge", &[]).build();

// Sequential dispatch used in order to avoid missing panics due to them happening in
// another thread.
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
//! // logical dependencies on other systems.
//! // Since we only have one, we don't depend on anything.
//! // See the `full` example for dependencies.
//! let mut dispatcher = DispatcherBuilder::new().add(SysA, "sys_a", &[]).build();
//! let mut dispatcher = DispatcherBuilder::new().with(SysA, "sys_a", &[]).build();
//!
//! // This dispatches all the systems in parallel (but blocking).
//! dispatcher.dispatch(&mut world.res);
Expand Down
20 changes: 10 additions & 10 deletions src/storage/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,18 +114,18 @@ impl<'a, T> SystemData<'a> for ReadStorage<'a, T>
where
T: Component,
{
fn fetch(res: &'a Resources, id: usize) -> Self {
Storage::new(res.fetch(0), res.fetch(id))
fn fetch(res: &'a Resources) -> Self {
Storage::new(res.fetch(), res.fetch())
}

fn reads(id: usize) -> Vec<ResourceId> {
fn reads() -> Vec<ResourceId> {
vec![
ResourceId::new::<EntitiesRes>(),
ResourceId::new_with_id::<MaskedStorage<T>>(id),
ResourceId::new::<MaskedStorage<T>>(),
]
}

fn writes(_: usize) -> Vec<ResourceId> {
fn writes() -> Vec<ResourceId> {
vec![]
}
}
Expand Down Expand Up @@ -197,15 +197,15 @@ impl<'a, T> SystemData<'a> for WriteStorage<'a, T>
where
T: Component,
{
fn fetch(res: &'a Resources, id: usize) -> Self {
Storage::new(res.fetch(0), res.fetch_mut(id))
fn fetch(res: &'a Resources) -> Self {
Storage::new(res.fetch(), res.fetch_mut())
}

fn reads(_: usize) -> Vec<ResourceId> {
fn reads() -> Vec<ResourceId> {
vec![ResourceId::new::<EntitiesRes>()]
}

fn writes(id: usize) -> Vec<ResourceId> {
vec![ResourceId::new_with_id::<MaskedStorage<T>>(id)]
fn writes() -> Vec<ResourceId> {
vec![ResourceId::new::<MaskedStorage<T>>()]
}
}
3 changes: 2 additions & 1 deletion src/storage/flagged.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use world::Index;
///
/// # Examples
///
/// ```rust
/// ```
/// extern crate specs;
///
/// use specs::prelude::*;
Expand Down Expand Up @@ -123,6 +123,7 @@ use world::Index;
/// };
/// }
/// ```
///
pub struct FlaggedStorage<C, T = DenseVecStorage<C>> {
trackers: TrackChannels,
storage: T,
Expand Down
24 changes: 12 additions & 12 deletions src/storage/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -669,12 +669,12 @@ mod test {
#[should_panic]
fn wrong_storage() {
use join::Join;
let mut w = World::new();
w.register_with_id::<Cvec>(1);
w.register_with_id::<Cvec>(2);
let mut s1: Storage<Cvec, _> = w.write_with_id(1);
// Possibility if the world uses dynamic components.
let mut s2: Storage<Cvec, _> = w.write_with_id(2);
let mut w0 = World::new();
let mut w1 = World::new();
w0.register::<Cvec>();
w1.register::<Cvec>();
let mut s1: Storage<Cvec, _> = w0.write();
let mut s2: Storage<Cvec, _> = w1.write();

for i in 0..50 {
s1.insert(Entity::new(i, Generation::new(1)), (i + 10).into());
Expand All @@ -694,12 +694,12 @@ mod test {
use join::ParJoin;
use rayon::iter::ParallelIterator;

let mut w = World::new();
w.register_with_id::<Cvec>(1);
w.register_with_id::<Cvec>(2);
let mut s1: Storage<Cvec, _> = w.write_with_id(1);
// Possibility if the world uses dynamic components.
let mut s2: Storage<Cvec, _> = w.write_with_id(2);
let mut w0 = World::new();
let mut w1 = World::new();
w0.register::<Cvec>();
w1.register::<Cvec>();
let mut s1: Storage<Cvec, _> = w0.write();
let mut s2: Storage<Cvec, _> = w1.write();

for i in 0..50 {
s1.insert(Entity::new(i, Generation::new(1)), (i + 10).into());
Expand Down
13 changes: 1 addition & 12 deletions src/world/lazy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,12 @@ pub struct LazyBuilder<'a> {
impl<'a> LazyBuilder<'a> {
/// Inserts a component using `LazyUpdate`.
pub fn with<C>(self, component: C) -> Self
where
C: Component + Send + Sync,
{
self.with_id(component, 0)
}

/// Inserts a component using `LazyUpdate`.
/// The `id` is the component id which is in most cases `0`,
/// because it's only used for scripting where you want multiple
/// storages for the same Rust type.
pub fn with_id<C>(self, component: C, id: usize) -> Self
where
C: Component + Send + Sync,
{
let entity = self.entity;
self.lazy.execute(move |world| {
world.write_with_id::<C>(id).insert(entity, component);
world.write::<C>().insert(entity, component);
});

self
Expand Down
Loading

0 comments on commit dd81261

Please sign in to comment.