Skip to content

Commit

Permalink
Store system name and dependencies as Strings in `DispatcherOperati…
Browse files Browse the repository at this point in the history
…on`.
  • Loading branch information
azriel91 committed Aug 19, 2019
1 parent e1ba938 commit c895a0d
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 54 deletions.
22 changes: 16 additions & 6 deletions amethyst_core/src/deferred_dispatcher_operation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ pub struct AddSystem<S> {
#[derivative(Debug = "ignore")]
pub system: S,
/// System name
pub name: &'static str,
pub name: String,
/// System dependencies list
pub dependencies: &'static [&'static str],
pub dependencies: Vec<String>,
}

impl<'a, 'b, S> DispatcherOperation<'a, 'b> for AddSystem<S>
Expand All @@ -58,7 +58,12 @@ where
_world: &mut World,
dispatcher_builder: &mut DispatcherBuilder<'a, 'b>,
) -> Result<(), Error> {
dispatcher_builder.add(self.system, self.name, self.dependencies);
let dependencies = self
.dependencies
.iter()
.map(String::as_str)
.collect::<Vec<&str>>();
dispatcher_builder.add(self.system, &self.name, &dependencies);
Ok(())
}
}
Expand All @@ -71,9 +76,9 @@ pub struct AddSystemDesc<SD, S> {
#[derivative(Debug = "ignore")]
pub system_desc: SD,
/// System name
pub name: &'static str,
pub name: String,
/// System dependencies
pub dependencies: &'static [&'static str],
pub dependencies: Vec<String>,
/// Generic type holder
pub marker: PhantomData<S>,
}
Expand All @@ -89,7 +94,12 @@ where
dispatcher_builder: &mut DispatcherBuilder<'a, 'b>,
) -> Result<(), Error> {
let system = self.system_desc.build(world);
dispatcher_builder.add(system, self.name, self.dependencies);
let dependencies = self
.dependencies
.iter()
.map(String::as_str)
.collect::<Vec<&str>>();
dispatcher_builder.add(system, &self.name, &dependencies);
Ok(())
}
}
Expand Down
56 changes: 32 additions & 24 deletions amethyst_test/src/amethyst_application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,15 +396,17 @@ where
/// * `system`: `System` to run.
/// * `name`: Name to register the system with, used for dependency ordering.
/// * `deps`: Names of systems that must run before this system.
pub fn with_system<S>(
self,
system: S,
name: &'static str,
deps: &'static [&'static str],
) -> Self
pub fn with_system<S, N>(self, system: S, name: N, deps: &[N]) -> Self
where
S: for<'sys_local> System<'sys_local> + Send + 'static,
N: Into<String> + Clone,
{
let name = Into::<String>::into(name);
let deps = deps
.iter()
.map(Clone::clone)
.map(Into::<String>::into)
.collect::<Vec<String>>();
self.with_bundle_fn(move || SystemInjectionBundle::new(system, name, deps))
}

Expand All @@ -415,16 +417,18 @@ where
/// * `system_desc`: Descriptor to instantiate the `System`.
/// * `name`: Name to register the system with, used for dependency ordering.
/// * `deps`: Names of systems that must run before this system.
pub fn with_system_desc<SD, S>(
self,
system_desc: SD,
name: &'static str,
deps: &'static [&'static str],
) -> Self
pub fn with_system_desc<SD, S, N>(self, system_desc: SD, name: N, deps: &[N]) -> Self
where
SD: SystemDesc<'static, 'static, S> + Send + Sync + 'static,
S: for<'sys_local> System<'sys_local> + Send + 'static,
N: Into<String> + Clone,
{
let name = Into::<String>::into(name);
let deps = deps
.iter()
.map(Clone::clone)
.map(Into::<String>::into)
.collect::<Vec<String>>();
self.with_bundle_fn(move || SystemDescInjectionBundle::new(system_desc, name, deps))
}

Expand All @@ -451,15 +455,17 @@ where
/// * `system`: `System` to run.
/// * `name`: Name to register the system with, used for dependency ordering.
/// * `deps`: Names of systems that must run before this system.
pub fn with_system_single<S>(
self,
system: S,
name: &'static str,
deps: &'static [&'static str],
) -> Self
pub fn with_system_single<S, N>(self, system: S, name: N, deps: &[N]) -> Self
where
S: for<'sys_local> System<'sys_local> + Send + Sync + 'static,
N: Into<String> + Clone,
{
let name = Into::<String>::into(name);
let deps = deps
.iter()
.map(Clone::clone)
.map(Into::<String>::into)
.collect::<Vec<String>>();
self.with_state(move || {
CustomDispatcherStateBuilder::new()
.with_system(system, name, deps)
Expand All @@ -477,16 +483,18 @@ where
/// * `system_desc`: Descriptor to instantiate the `System`.
/// * `name`: Name to register the system with, used for dependency ordering.
/// * `deps`: Names of systems that must run before this system.
pub fn with_system_desc_single<SD, S>(
self,
system_desc: SD,
name: &'static str,
deps: &'static [&'static str],
) -> Self
pub fn with_system_desc_single<SD, S, N>(self, system_desc: SD, name: N, deps: &[N]) -> Self
where
SD: SystemDesc<'static, 'static, S> + Send + Sync + 'static,
S: for<'sys_local> System<'sys_local> + Send + Sync + 'static,
N: Into<String> + Clone,
{
let name = Into::<String>::into(name);
let deps = deps
.iter()
.map(Clone::clone)
.map(Into::<String>::into)
.collect::<Vec<String>>();
self.with_state(move || {
CustomDispatcherStateBuilder::new()
.with_system_desc(system_desc, name, deps)
Expand Down
11 changes: 3 additions & 8 deletions amethyst_test/src/state/custom_dispatcher_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,7 @@ impl<'a, 'b: 'a> CustomDispatcherStateBuilder<'a, 'b> {
/// * `system`: Function to instantiate the `System`.
/// * `name`: Name to register the system with, used for dependency ordering.
/// * `deps`: Names of systems that must run before this system.
pub fn with_system<S>(
mut self,
system: S,
name: &'static str,
dependencies: &'static [&'static str],
) -> Self
pub fn with_system<S>(mut self, system: S, name: String, dependencies: Vec<String>) -> Self
where
S: for<'c> System<'c> + 'static + Send,
{
Expand All @@ -138,8 +133,8 @@ impl<'a, 'b: 'a> CustomDispatcherStateBuilder<'a, 'b> {
pub fn with_system_desc<SD, S>(
mut self,
system_desc: SD,
name: &'static str,
dependencies: &'static [&'static str],
name: String,
dependencies: Vec<String>,
) -> Self
where
SD: SystemDesc<'a, 'b, S> + 'a,
Expand Down
13 changes: 9 additions & 4 deletions amethyst_test/src/system_desc_injection_bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ where
/// Function to instantiate `System` to add to the dispatcher.
system_desc: SD,
/// Name to register the system with.
system_name: &'static str,
system_name: String,
/// Names of the system dependencies.
system_dependencies: &'static [&'static str],
system_dependencies: Vec<String>,
/// Marker.
system_marker: PhantomData<(&'a SD, &'b S)>,
}
Expand All @@ -35,10 +35,15 @@ where
world: &mut World,
builder: &mut DispatcherBuilder<'a, 'b>,
) -> Result<(), Error> {
let system_dependencies = self
.system_dependencies
.iter()
.map(String::as_str)
.collect::<Vec<&str>>();
builder.add(
self.system_desc.build(world),
self.system_name,
self.system_dependencies,
&self.system_name,
&system_dependencies,
);
Ok(())
}
Expand Down
11 changes: 8 additions & 3 deletions amethyst_test/src/system_injection_bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ where
/// Function to instantiate `System` to add to the dispatcher.
system: S,
/// Name to register the system with.
system_name: &'static str,
system_name: String,
/// Names of the system dependencies.
system_dependencies: &'static [&'static str],
system_dependencies: Vec<String>,
}

impl<'a, 'b, S> SystemBundle<'a, 'b> for SystemInjectionBundle<S>
Expand All @@ -25,7 +25,12 @@ where
_world: &mut World,
builder: &mut DispatcherBuilder<'a, 'b>,
) -> Result<(), Error> {
builder.add(self.system, self.system_name, self.system_dependencies);
let system_dependencies = self
.system_dependencies
.iter()
.map(String::as_str)
.collect::<Vec<&str>>();
builder.add(self.system, &self.system_name, &system_dependencies);
Ok(())
}
}
27 changes: 18 additions & 9 deletions src/game_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,17 @@ impl<'a, 'b> GameDataBuilder<'a, 'b> {
/// // It is legal to register a system with an empty name
/// .with(NopSystem, "", &[]);
/// ~~~
pub fn with<S>(
mut self,
system: S,
name: &'static str,
dependencies: &'static [&'static str],
) -> Self
pub fn with<S, N>(mut self, system: S, name: N, dependencies: &[N]) -> Self
where
S: for<'c> System<'c> + 'static + Send,
N: Into<String> + Clone,
{
let name = Into::<String>::into(name);
let dependencies = dependencies
.iter()
.map(Clone::clone)
.map(Into::<String>::into)
.collect::<Vec<String>>();
let dispatcher_operation = Box::new(AddSystem {
system,
name,
Expand Down Expand Up @@ -259,16 +261,23 @@ impl<'a, 'b> GameDataBuilder<'a, 'b> {
/// // It is legal to register a system with an empty name
/// .with_system_desc(NopSystem, "", &[]);
/// ~~~
pub fn with_system_desc<SD, S>(
pub fn with_system_desc<SD, S, N>(
mut self,
system_desc: SD,
name: &'static str,
dependencies: &'static [&'static str],
name: N,
dependencies: &[N],
) -> Self
where
SD: SystemDesc<'a, 'b, S> + 'static,
S: for<'c> System<'c> + 'static + Send,
N: Into<String> + Clone,
{
let name = Into::<String>::into(name);
let dependencies = dependencies
.iter()
.map(Clone::clone)
.map(Into::<String>::into)
.collect::<Vec<String>>();
let dispatcher_operation = Box::new(AddSystemDesc {
system_desc,
name,
Expand Down

0 comments on commit c895a0d

Please sign in to comment.