Skip to content

Commit bb25076

Browse files
bors[bot]azriel91
andauthored
1882: Maintenance/update amethyst test r=distransient,jojolepro a=azriel91 ## Description Updated `amethyst_test::AmethystApplication` to take both `System` and `SystemDesc` (currently sits on top of amethyst#1881 so that CI succeeds). ## Additions * `AmethystApplication` takes in `SystemDesc`s through `with_system_desc`. * `AmethystApplication::with_thread_local_desc` takes in `RunNowDesc`. ## Modifications * `AmethystApplication` takes in a `System` instead of a closure for `with_system`. * `AmethystApplication::with_thread_local` constraint relaxed to `RunNow` (previously `System`). ## PR Checklist By placing an x in the boxes I certify that I have: - [x] Updated the content of the book if this PR would make the book outdated. - [x] Added a changelog entry if this will impact users, or modified more than 5 lines of Rust that wasn't a doc comment. - **n/a** Added unit tests for new code added in this PR. - [x] Acknowledged that by making this pull request I release this code under an MIT/Apache 2.0 dual licensing scheme. If this modified or created any rs files: - [x] Ran `cargo +stable fmt --all` - [x] Ran `cargo clippy --all --features "empty"` - [x] Ran `cargo test --all --features "empty"` Co-authored-by: Azriel Hoh <[email protected]>
2 parents 5e5e588 + 15d4b5a commit bb25076

File tree

33 files changed

+449
-324
lines changed

33 files changed

+449
-324
lines changed

amethyst_controls/src/systems.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -230,13 +230,6 @@ impl<'a, 'b> SystemDesc<'a, 'b, CursorHideSystem> for CursorHideSystemDesc {
230230
fn build(self, world: &mut World) -> CursorHideSystem {
231231
<CursorHideSystem as System<'_>>::SystemData::setup(world);
232232

233-
let win = world.fetch::<Window>();
234-
235-
if let Err(err) = win.grab_cursor(true) {
236-
log::error!("Unable to grab the cursor. Error: {:?}", err);
237-
}
238-
win.hide_cursor(true);
239-
240233
CursorHideSystem::new()
241234
}
242235
}

amethyst_derive/tests/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ mod tests {
108108
macro_rules! assert_prefab {
109109
($prefab_type:ident, $prefab:expr, $assertion:expr) => {
110110
assert!(AmethystApplication::blank()
111-
.with_system(
111+
.with_system_desc(
112112
PrefabLoaderSystemDesc::<$prefab_type>::default(),
113113
"test_loader",
114114
&[]

amethyst_gltf/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ amethyst_rendy = { path = "../amethyst_rendy", version = "0.2.0" }
2323
err-derive = "0.1"
2424
base64 = "0.10"
2525
fnv = "1"
26-
gltf = "0.12"
26+
gltf = "0.13"
2727
gfx = "0.17"
2828
hibitset = { version = "0.5.1", features = ["parallel"] }
2929
itertools = "0.7"

amethyst_test/src/amethyst_application.rs

Lines changed: 69 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::{any::Any, marker::PhantomData, panic, path::PathBuf, sync::Mutex};
22

33
use amethyst::{
44
self,
5-
core::{transform::TransformBundle, EventReader, SystemBundle, SystemDesc},
5+
core::{transform::TransformBundle, EventReader, RunNowDesc, SystemBundle, SystemDesc},
66
ecs::prelude::*,
77
error::Error,
88
input::{BindingTypes, InputBundle},
@@ -17,8 +17,8 @@ use derivative::Derivative;
1717
use lazy_static::lazy_static;
1818

1919
use crate::{
20-
CustomDispatcherStateBuilder, FunctionState, GameUpdate, SequencerState, SystemInjectionBundle,
21-
ThreadLocalInjectionBundle,
20+
CustomDispatcherStateBuilder, FunctionState, GameUpdate, SequencerState,
21+
SystemDescInjectionBundle, SystemInjectionBundle, ThreadLocalInjectionBundle,
2222
};
2323

2424
type BundleAddFn = Box<
@@ -366,8 +366,8 @@ where
366366
self.resource_add_fns
367367
.push(Box::new(move |world: &mut World| {
368368
let resource = resource_opt.take();
369-
if resource.is_some() {
370-
world.insert(resource.unwrap());
369+
if let Some(resource) = resource {
370+
world.insert(resource);
371371
}
372372
}));
373373
self
@@ -389,41 +389,82 @@ where
389389
self
390390
}
391391

392+
/// Registers a `System` into this application's `GameData`.
393+
///
394+
/// # Parameters
395+
///
396+
/// * `system`: `System` to run.
397+
/// * `name`: Name to register the system with, used for dependency ordering.
398+
/// * `deps`: Names of systems that must run before this system.
399+
pub fn with_system<S>(
400+
self,
401+
system: S,
402+
name: &'static str,
403+
deps: &'static [&'static str],
404+
) -> Self
405+
where
406+
S: for<'sys_local> System<'sys_local> + Send + 'static,
407+
{
408+
self.with_bundle_fn(move || SystemInjectionBundle::new(system, name, deps))
409+
}
410+
392411
/// Registers a `System` into this application's `GameData`.
393412
///
394413
/// # Parameters
395414
///
396415
/// * `system_desc`: Descriptor to instantiate the `System`.
397416
/// * `name`: Name to register the system with, used for dependency ordering.
398417
/// * `deps`: Names of systems that must run before this system.
399-
pub fn with_system<N, SD, S>(self, system_desc: SD, name: N, deps: &[N]) -> Self
418+
pub fn with_system_desc<SD, S>(
419+
self,
420+
system_desc: SD,
421+
name: &'static str,
422+
deps: &'static [&'static str],
423+
) -> Self
400424
where
401-
N: Into<String> + Clone,
402425
SD: SystemDesc<'static, 'static, S> + Send + Sync + 'static,
403426
S: for<'sys_local> System<'sys_local> + Send + 'static,
404427
{
405-
let name = name.into();
406-
let deps = deps
407-
.iter()
408-
.map(|dep| dep.clone().into())
409-
.collect::<Vec<String>>();
410-
self.with_bundle_fn(move || SystemInjectionBundle::new(system_desc, name, deps))
428+
self.with_bundle_fn(move || SystemDescInjectionBundle::new(system_desc, name, deps))
411429
}
412430

413431
/// Registers a thread local `System` into this application's `GameData`.
414432
///
415433
/// # Parameters
416434
///
417-
/// * `system_desc`: Descriptor to instantiate the thread local system.
418-
pub fn with_thread_local<SD, S>(self, system_desc: SD) -> Self
435+
/// * `run_now_desc`: Descriptor to instantiate the thread local system.
436+
pub fn with_thread_local<RNDesc, RN>(self, run_now_desc: RNDesc) -> Self
419437
where
420-
SD: SystemDesc<'static, 'static, S> + Send + Sync + 'static,
421-
S: for<'sys_local> System<'sys_local> + Send + 'static,
422-
// Ideally we can use the following lesser bound, but this would cause a duplication of
423-
// traits and types which may not be worth it at this point in time.
424-
// S: for<'sys_local> RunNow<'sys_local> + Send + 'static,
438+
RNDesc: RunNowDesc<'static, 'static, RN> + Send + Sync + 'static,
439+
RN: for<'sys_local> RunNow<'sys_local> + Send + 'static,
425440
{
426-
self.with_bundle_fn(move || ThreadLocalInjectionBundle::new(system_desc))
441+
self.with_bundle_fn(move || ThreadLocalInjectionBundle::new(run_now_desc))
442+
}
443+
444+
/// Registers a `System` to run in a `CustomDispatcherState`.
445+
///
446+
/// This will run the system once in a dedicated `State`, allowing you to inspect the effects of
447+
/// the system after setting up the world to a desired state.
448+
///
449+
/// # Parameters
450+
///
451+
/// * `system`: `System` to run.
452+
/// * `name`: Name to register the system with, used for dependency ordering.
453+
/// * `deps`: Names of systems that must run before this system.
454+
pub fn with_system_single<S>(
455+
self,
456+
system: S,
457+
name: &'static str,
458+
deps: &'static [&'static str],
459+
) -> Self
460+
where
461+
S: for<'sys_local> System<'sys_local> + Send + Sync + 'static,
462+
{
463+
self.with_state(move || {
464+
CustomDispatcherStateBuilder::new()
465+
.with_system(system, name, deps)
466+
.build()
467+
})
427468
}
428469

429470
/// Registers a `System` to run in a `CustomDispatcherState`.
@@ -436,20 +477,19 @@ where
436477
/// * `system_desc`: Descriptor to instantiate the `System`.
437478
/// * `name`: Name to register the system with, used for dependency ordering.
438479
/// * `deps`: Names of systems that must run before this system.
439-
pub fn with_system_single<N, SD, S>(self, system_desc: SD, name: N, deps: &[N]) -> Self
480+
pub fn with_system_desc_single<SD, S>(
481+
self,
482+
system_desc: SD,
483+
name: &'static str,
484+
deps: &'static [&'static str],
485+
) -> Self
440486
where
441-
N: Into<String> + Clone,
442487
SD: SystemDesc<'static, 'static, S> + Send + Sync + 'static,
443488
S: for<'sys_local> System<'sys_local> + Send + Sync + 'static,
444489
{
445-
let name = name.into();
446-
let deps = deps
447-
.iter()
448-
.map(|dep| dep.clone().into())
449-
.collect::<Vec<String>>();
450490
self.with_state(move || {
451491
CustomDispatcherStateBuilder::new()
452-
.with(system_desc, name, deps)
492+
.with_system_desc(system_desc, name, deps)
453493
.build()
454494
})
455495
}

amethyst_test/src/lib.rs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,12 @@
117117
//!
118118
//! ```rust,no_run
119119
//! # use amethyst::{
120-
//! # core::{bundle::SystemBundle, SystemDesc},
121-
//! # derive::SystemDesc,
120+
//! # core::bundle::SystemBundle,
122121
//! # ecs::prelude::*,
123122
//! # prelude::*,
124123
//! # };
125124
//! #
126-
//! # #[derive(Debug, SystemDesc)]
125+
//! # #[derive(Debug)]
127126
//! # struct MySystem;
128127
//! #
129128
//! # impl<'s> System<'s> for MySystem {
@@ -174,17 +173,15 @@
174173
//! ```rust
175174
//! # use amethyst_test::prelude::*;
176175
//! # use amethyst::{
177-
//! # core::{bundle::SystemBundle, SystemDesc},
178-
//! # derive::SystemDesc,
176+
//! # core::bundle::SystemBundle,
179177
//! # ecs::prelude::*,
180178
//! # prelude::*,
181179
//! # };
182180
//! #
183181
//! # #[derive(Debug)]
184182
//! # struct ApplicationResource;
185183
//! #
186-
//! # #[derive(Debug, SystemDesc)]
187-
//! # #[system_desc(insert(ApplicationResource))]
184+
//! # #[derive(Debug)]
188185
//! # struct MySystem;
189186
//! #
190187
//! # impl<'s> System<'s> for MySystem {
@@ -198,7 +195,8 @@
198195
//! # impl<'a, 'b> SystemBundle<'a, 'b> for MyBundle {
199196
//! # fn build(self, world: &mut World, builder: &mut DispatcherBuilder<'a, 'b>)
200197
//! # -> amethyst::Result<()> {
201-
//! # builder.add(MySystem.build(world), "my_system", &[]);
198+
//! # world.insert(ApplicationResource);
199+
//! # builder.add(MySystem, "my_system", &[]);
202200
//! # Ok(())
203201
//! # }
204202
//! # }
@@ -224,8 +222,6 @@
224222
//! ```rust
225223
//! # use amethyst_test::prelude::*;
226224
//! # use amethyst::{
227-
//! # core::SystemDesc,
228-
//! # derive::SystemDesc,
229225
//! # ecs::prelude::*,
230226
//! # prelude::*,
231227
//! # };
@@ -236,7 +232,7 @@
236232
//! # type Storage = DenseVecStorage<Self>;
237233
//! # }
238234
//! #
239-
//! # #[derive(Debug, SystemDesc)]
235+
//! # #[derive(Debug)]
240236
//! # struct MySystem;
241237
//! #
242238
//! # impl<'s> System<'s> for MySystem {
@@ -285,16 +281,14 @@
285281
//! ```rust
286282
//! # use amethyst_test::prelude::*;
287283
//! # use amethyst::{
288-
//! # core::SystemDesc,
289-
//! # derive::SystemDesc,
290284
//! # ecs::prelude::*,
291285
//! # prelude::*,
292286
//! # };
293287
//! #
294288
//! # // !Default
295289
//! # struct MyResource(pub i32);
296290
//! #
297-
//! # #[derive(Debug, SystemDesc)]
291+
//! # #[derive(Debug)]
298292
//! # struct MySystem;
299293
//! #
300294
//! # impl<'s> System<'s> for MySystem {
@@ -340,6 +334,7 @@ pub use crate::{
340334
},
341335
};
342336
pub(crate) use crate::{
337+
system_desc_injection_bundle::SystemDescInjectionBundle,
343338
system_injection_bundle::SystemInjectionBundle,
344339
thread_local_injection_bundle::ThreadLocalInjectionBundle,
345340
};
@@ -350,5 +345,6 @@ mod fixture;
350345
mod game_update;
351346
pub mod prelude;
352347
mod state;
348+
mod system_desc_injection_bundle;
353349
mod system_injection_bundle;
354350
mod thread_local_injection_bundle;

0 commit comments

Comments
 (0)