Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/amethyst/amethyst into ma…
Browse files Browse the repository at this point in the history
…inqueue
  • Loading branch information
AnneKitsune committed Nov 13, 2018
2 parents 55fcd68 + 8240933 commit d0f9639
Show file tree
Hide file tree
Showing 39 changed files with 621 additions and 362 deletions.
8 changes: 8 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,17 @@ path = "examples/prefab/main.rs"
name = "debug_lines"
path = "examples/debug_lines/main.rs"

[[example]]
name = "state_dispatcher"
path = "examples/state_dispatcher/main.rs"

[[example]]
name = "spotlights"
path = "examples/spotlights/main.rs"

[[example]]
name = "sprite_camera_follow"
path = "examples/sprite_camera_follow/main.rs"

[workspace]
members = ["amethyst_gltf", "tests/amethyst_test"]
31 changes: 12 additions & 19 deletions amethyst_animation/src/skinning/systems.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use amethyst_core::{
specs::prelude::{
BitSet, InsertedFlag, Join, ModifiedFlag, ReadStorage, ReaderId, Resources, System,
WriteStorage,
BitSet, ComponentEvent, Join, ReadStorage, ReaderId, Resources, System, WriteStorage,
},
GlobalTransform,
};
Expand All @@ -17,8 +16,7 @@ pub struct VertexSkinningSystem {
updated: BitSet,
updated_skins: BitSet,
/// Used for tracking modifications to global transforms
updated_id: Option<ReaderId<ModifiedFlag>>,
inserted_id: Option<ReaderId<InsertedFlag>>,
updated_id: Option<ReaderId<ComponentEvent>>,
}

impl VertexSkinningSystem {
Expand All @@ -27,7 +25,6 @@ impl VertexSkinningSystem {
Self {
updated: BitSet::new(),
updated_skins: BitSet::new(),
inserted_id: None,
updated_id: None,
}
}
Expand All @@ -44,19 +41,16 @@ impl<'a> System<'a> for VertexSkinningSystem {
fn run(&mut self, (joints, global_transforms, mut skins, mut matrices): Self::SystemData) {
self.updated.clear();

global_transforms.populate_modified(
&mut self.updated_id.as_mut().expect(
global_transforms
.channel()
.read(self.updated_id.as_mut().expect(
"`VertexSkinningSystem::setup` was not called before `VertexSkinningSystem::run`",
),
&mut self.updated,
);

global_transforms.populate_inserted(
&mut self.inserted_id.as_mut().expect(
"`VertexSkinningSystem::setup` was not called before `VertexSkinningSystem::run`",
),
&mut self.updated,
);
)).for_each(|event| match event {
ComponentEvent::Inserted(id) | ComponentEvent::Modified(id) => {
self.updated.add(*id);
}
ComponentEvent::Removed(_id) => {}
});

self.updated_skins.clear();

Expand Down Expand Up @@ -129,7 +123,6 @@ impl<'a> System<'a> for VertexSkinningSystem {
use amethyst_core::specs::prelude::SystemData;
Self::SystemData::setup(res);
let mut transform = WriteStorage::<GlobalTransform>::fetch(res);
self.updated_id = Some(transform.track_modified());
self.inserted_id = Some(transform.track_inserted());
self.updated_id = Some(transform.register_reader());
}
}
21 changes: 12 additions & 9 deletions amethyst_assets/src/prefab/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use std::{marker::PhantomData, ops::Deref};

use amethyst_core::{
specs::{
BitSet, Entities, Entity, InsertedFlag, Join, Read, ReadExpect, ReadStorage, ReaderId,
Resources, System, Write, WriteStorage,
storage::ComponentEvent, BitSet, Entities, Entity, Join, Read, ReadExpect, ReadStorage,
ReaderId, Resources, System, Write, WriteStorage,
},
ArcThreadPool, Parent, Time,
};
Expand All @@ -22,7 +22,7 @@ pub struct PrefabLoaderSystem<T> {
entities: Vec<Entity>,
finished: Vec<Entity>,
to_process: BitSet,
insert_reader: Option<ReaderId<InsertedFlag>>,
insert_reader: Option<ReaderId<ComponentEvent>>,
next_tag: u64,
}

Expand Down Expand Up @@ -93,12 +93,15 @@ where
&**pool,
strategy,
);
prefab_handles.populate_inserted(
self.insert_reader.as_mut().expect(
prefab_handles
.channel()
.read(self.insert_reader.as_mut().expect(
"`PrefabLoaderSystem::setup` was not called before `PrefabLoaderSystem::run`",
),
&mut self.to_process,
);
)).for_each(|event| {
if let ComponentEvent::Inserted(id) = event {
self.to_process.add(*id);
}
});
self.finished.clear();
for (root_entity, handle, _) in (&*entities, &prefab_handles, &self.to_process).join() {
if let Some(prefab) = prefab_storage.get(handle) {
Expand Down Expand Up @@ -149,6 +152,6 @@ where
fn setup(&mut self, res: &mut Resources) {
use amethyst_core::specs::prelude::SystemData;
Self::SystemData::setup(res);
self.insert_reader = Some(WriteStorage::<Handle<Prefab<T>>>::fetch(&res).track_inserted());
self.insert_reader = Some(WriteStorage::<Handle<Prefab<T>>>::fetch(&res).register_reader());
}
}
4 changes: 2 additions & 2 deletions amethyst_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ log = "0.4"
rayon = "1.0.2"
serde = { version = "1", features = ["serde_derive"] }
shred = { version = "0.7" }
specs = { version = "0.12.3", features = ["common"] }
specs-hierarchy = { version = "0.2" }
specs = { version = "0.14", features = ["common"] }
specs-hierarchy = { version = "0.3" }
shrev = "1.0"

thread_profiler = { version = "0.3" , optional = true }
Expand Down
37 changes: 17 additions & 20 deletions amethyst_core/src/transform/systems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
use hibitset::BitSet;
use specs::prelude::{
Entities, Entity, InsertedFlag, Join, ModifiedFlag, ReadExpect, ReadStorage, ReaderId,
Resources, System, WriteStorage,
ComponentEvent, Entities, Entity, Join, ReadExpect, ReadStorage, ReaderId, Resources, System,
WriteStorage,
};

use transform::{GlobalTransform, HierarchyEvent, Parent, ParentHierarchy, Transform};
Expand All @@ -14,8 +14,7 @@ pub struct TransformSystem {
local_modified: BitSet,
global_modified: BitSet,

inserted_local_id: Option<ReaderId<InsertedFlag>>,
modified_local_id: Option<ReaderId<ModifiedFlag>>,
locals_events_id: Option<ReaderId<ComponentEvent>>,

parent_events_id: Option<ReaderId<HierarchyEvent>>,

Expand All @@ -26,8 +25,7 @@ impl TransformSystem {
/// Creates a new transform processor.
pub fn new() -> TransformSystem {
TransformSystem {
inserted_local_id: None,
modified_local_id: None,
locals_events_id: None,
parent_events_id: None,
local_modified: BitSet::default(),
global_modified: BitSet::default(),
Expand Down Expand Up @@ -60,18 +58,18 @@ impl<'a> System<'a> for TransformSystem {
self.local_modified.clear();
self.global_modified.clear();

locals.populate_inserted(
self.inserted_local_id
.as_mut()
.expect("`TransformSystem::setup` was not called before `TransformSystem::run`"),
&mut self.local_modified,
);
locals.populate_modified(
self.modified_local_id
.as_mut()
.expect("`TransformSystem::setup` was not called before `TransformSystem::run`"),
&mut self.local_modified,
);
locals
.channel()
.read(
self.locals_events_id.as_mut().expect(
"`TransformSystem::setup` was not called before `TransformSystem::run`",
),
).for_each(|event| match event {
ComponentEvent::Inserted(id) | ComponentEvent::Modified(id) => {
self.local_modified.add(*id);
}
ComponentEvent::Removed(_id) => {}
});

for event in hierarchy.changed().read(
self.parent_events_id
Expand Down Expand Up @@ -137,8 +135,7 @@ impl<'a> System<'a> for TransformSystem {
let mut hierarchy = res.fetch_mut::<ParentHierarchy>();
let mut locals = WriteStorage::<Transform>::fetch(res);
self.parent_events_id = Some(hierarchy.track());
self.inserted_local_id = Some(locals.track_inserted());
self.modified_local_id = Some(locals.track_modified());
self.locals_events_id = Some(locals.register_reader());
}
}

Expand Down
46 changes: 28 additions & 18 deletions amethyst_renderer/src/hide_system.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use amethyst_core::{
specs::prelude::{
BitSet, InsertedFlag, ReadExpect, ReadStorage, ReaderId, RemovedFlag, Resources, System,
WriteStorage,
BitSet, ComponentEvent, ReadExpect, ReadStorage, ReaderId, Resources, System, WriteStorage,
},
transform::components::{HierarchyEvent, Parent, ParentHierarchy},
};
Expand All @@ -16,8 +15,7 @@ use HiddenPropagate;
pub struct HideHierarchySystem {
marked_as_modified: BitSet,

inserted_hidden_id: Option<ReaderId<InsertedFlag>>,
removed_hidden_id: Option<ReaderId<RemovedFlag>>,
hidden_events_id: Option<ReaderId<ComponentEvent>>,

parent_events_id: Option<ReaderId<HierarchyEvent>>,
}
Expand All @@ -34,15 +32,21 @@ impl<'a> System<'a> for HideHierarchySystem {

self.marked_as_modified.clear();

let self_inserted_hidden_id = &mut self.inserted_hidden_id.as_mut().expect(
"`HideHierarchySystem::setup` was not called before `HideHierarchySystem::run`",
);
let self_removed_hidden_id = &mut self.removed_hidden_id.as_mut().expect(
// Borrow multiple parts of self as mutable
let self_hidden_events_id = &mut self.hidden_events_id.as_mut().expect(
"`HideHierarchySystem::setup` was not called before `HideHierarchySystem::run`",
);
let self_marked_as_modified = &mut self.marked_as_modified;

hidden.populate_inserted(self_inserted_hidden_id, &mut self.marked_as_modified);
hidden.populate_removed(self_removed_hidden_id, &mut self.marked_as_modified);
hidden
.channel()
.read(self_hidden_events_id)
.for_each(|event| match event {
ComponentEvent::Inserted(id) | ComponentEvent::Removed(id) => {
self_marked_as_modified.add(*id);
}
ComponentEvent::Modified(_id) => {}
});

for event in hierarchy
.changed()
Expand All @@ -51,22 +55,22 @@ impl<'a> System<'a> for HideHierarchySystem {
)) {
match *event {
HierarchyEvent::Removed(entity) => {
self.marked_as_modified.add(entity.id());
self_marked_as_modified.add(entity.id());
}
HierarchyEvent::Modified(entity) => {
// HierarchyEvent::Modified includes insertion of new components to the storage.
self.marked_as_modified.add(entity.id());
self_marked_as_modified.add(entity.id());
}
}
}

// Compute hide status with parents.
for entity in hierarchy.all() {
{
let self_dirty = self.marked_as_modified.contains(entity.id());
let self_dirty = self_marked_as_modified.contains(entity.id());

let parent_entity = parents.get(*entity).expect("Unreachable: All entities in `ParentHierarchy` should also be in `Parents`").entity;
let parent_dirty = self.marked_as_modified.contains(parent_entity.id());
let parent_dirty = self_marked_as_modified.contains(parent_entity.id());
if parent_dirty {
if hidden.contains(parent_entity) {
for child in hierarchy.all_children_iter(parent_entity) {
Expand Down Expand Up @@ -98,8 +102,15 @@ impl<'a> System<'a> for HideHierarchySystem {
// Populate the modifications we just did.
// Happens inside the for-loop, so that the changes are picked up in the next iteration already,
// instead of on the next `system.run()`
hidden.populate_inserted(self_inserted_hidden_id, &mut self.marked_as_modified);
hidden.populate_removed(self_removed_hidden_id, &mut self.marked_as_modified);
hidden
.channel()
.read(self_hidden_events_id)
.for_each(|event| match event {
ComponentEvent::Inserted(id) | ComponentEvent::Removed(id) => {
self_marked_as_modified.add(*id);
}
ComponentEvent::Modified(_id) => {}
});
}
}

Expand All @@ -109,7 +120,6 @@ impl<'a> System<'a> for HideHierarchySystem {
// This fetch_mut panics if `ParentHierarchy` is not set up yet, hence the dependency on "parent_hierarchy_system"
self.parent_events_id = Some(res.fetch_mut::<ParentHierarchy>().track());
let mut hidden = WriteStorage::<HiddenPropagate>::fetch(res);
self.inserted_hidden_id = Some(hidden.track_inserted());
self.removed_hidden_id = Some(hidden.track_removed());
self.hidden_events_id = Some(hidden.register_reader());
}
}
2 changes: 1 addition & 1 deletion amethyst_renderer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ pub use {
},
light::{DirectionalLight, Light, LightPrefab, PointLight, SpotLight, SunLight},
mesh::{vertex_data, Mesh, MeshBuilder, MeshHandle, VertexBuffer},
mtl::{Material, MaterialDefaults, MaterialTextureSet, TextureOffset},
mtl::{Material, MaterialDefaults, TextureOffset},
pass::{
get_camera, set_vertex_args, DebugLinesParams, DrawDebugLines, DrawFlat, DrawFlatSeparate,
DrawPbm, DrawPbmSeparate, DrawShaded, DrawShadedSeparate, DrawSkybox, DrawSprite,
Expand Down
56 changes: 1 addition & 55 deletions amethyst_renderer/src/mtl.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
//! Physically-based material.
use fnv::FnvHashMap;

use amethyst_assets::Handle;
use amethyst_core::specs::prelude::{Component, DenseVecStorage};

use tex::{Texture, TextureHandle};
use tex::TextureHandle;

/// Material reference this part of the texture
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
Expand Down Expand Up @@ -71,54 +68,3 @@ impl Component for Material {
/// `Material` you don't want to specify.
#[derive(Clone)]
pub struct MaterialDefaults(pub Material);

/// Textures used by texture animations
#[derive(Debug, Default)]
pub struct MaterialTextureSet {
textures: FnvHashMap<u64, Handle<Texture>>,
texture_inverse: FnvHashMap<Handle<Texture>, u64>,
}

impl MaterialTextureSet {
/// Create new texture set
pub fn new() -> Self {
MaterialTextureSet {
textures: FnvHashMap::default(),
texture_inverse: FnvHashMap::default(),
}
}

/// Retrieve the handle for a given index
pub fn handle(&self, id: u64) -> Option<Handle<Texture>> {
self.textures.get(&id).cloned()
}

/// Retrieve the index for a given handle
pub fn id(&self, handle: &Handle<Texture>) -> Option<u64> {
self.texture_inverse.get(handle).cloned()
}

/// Insert a texture handle at the given index
pub fn insert(&mut self, id: u64, handle: Handle<Texture>) {
self.textures.insert(id, handle.clone());
self.texture_inverse.insert(handle, id);
}

/// Remove the given index
pub fn remove(&mut self, id: u64) {
if let Some(handle) = self.textures.remove(&id) {
self.texture_inverse.remove(&handle);
}
}

/// Get number of textures in the set
pub fn len(&self) -> usize {
self.textures.len()
}

/// Remove all texture handles in the set
pub fn clear(&mut self) {
self.textures.clear();
self.texture_inverse.clear();
}
}
Loading

0 comments on commit d0f9639

Please sign in to comment.