Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to latest shipyard #6

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use crate::{
use shipyard::*;
use tracing::trace_span;

#[allow(clippy::needless_doctest_main)]
/// Containers of app logic and data
pub struct App {
pub world: World,
Expand All @@ -32,15 +31,15 @@ impl App {
#[track_caller]
pub fn add_plugin_workload<P>(&mut self, plugin: P) -> AppWorkload
where
P: Plugin + 'static,
P: Plugin,
{
self.add_plugin_workload_with_info(plugin).0
}

#[track_caller]
pub fn add_plugin_workload_with_info<P>(&mut self, plugin: P) -> (AppWorkload, AppWorkloadInfo)
where
P: Plugin + 'static,
P: Plugin,
{
let workload_name = type_name::<P>();
let workload_type_id = TypeId::of::<P>();
Expand Down
16 changes: 7 additions & 9 deletions src/app_add_cycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ impl App {
cumulative_update_packed.associate(
up_type,
CycleWorkloadAssociations {
plugins: assoc,
plugins: assoc.to_vec(),
workload_plugin_id: plugin_id,
workload: name.clone(),
},
Expand All @@ -99,7 +99,7 @@ impl App {
cumulative_tracked_uniques.associate(
tracked_type,
CycleWorkloadAssociations {
plugins: assoc,
plugins: assoc.to_vec(),
workload: name.clone(),
workload_plugin_id: plugin_id,
},
Expand All @@ -108,7 +108,7 @@ impl App {
}
}

names_checked.push(name.clone());
names_checked.push(name);
}

let mut errs = Vec::<CycleCheckError>::new();
Expand All @@ -117,12 +117,11 @@ impl App {
errs.extend(
cumulative_update_packed
.entries()
.into_iter()
.filter(|((_, _), workloads_dependent)| workloads_dependent.len() > 1)
.filter(|(_, workloads_dependent)| workloads_dependent.len() > 1)
.map(|((_, update_pack_storage_name), workloads_dependent)| {
CycleCheckError::UpdatePackResetInMultipleWorkloads {
update_pack: update_pack_storage_name,
conflicts: workloads_dependent,
conflicts: workloads_dependent.to_vec(),
}
}),
);
Expand All @@ -131,12 +130,11 @@ impl App {
errs.extend(
cumulative_tracked_uniques
.entries()
.into_iter()
.filter(|((_, _), workloads_dependent)| workloads_dependent.len() > 1)
.filter(|(_, workloads_dependent)| workloads_dependent.len() > 1)
.map(|((_, tracked_unique_storage_name), workloads_dependent)| {
CycleCheckError::TrackedUniqueResetInMultipleWorkloads {
tracked_unique: tracked_unique_storage_name,
conflicts: workloads_dependent,
conflicts: workloads_dependent.to_vec(),
}
}),
);
Expand Down
47 changes: 20 additions & 27 deletions src/app_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,12 @@ pub(crate) struct TypeIdBuckets<T> {
pub(crate) type_plugins_lookup: HashMap<TypeId, Vec<T>>,
}

impl<T: std::fmt::Debug + Clone> std::fmt::Debug for TypeIdBuckets<T> {
impl<T: std::fmt::Debug> std::fmt::Debug for TypeIdBuckets<T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_map()
.entry(&"association", &self.name)
.entries(
self.entries()
.into_iter()
.map(|((_, name), associated)| (name, associated)),
)
.finish()
Expand All @@ -68,18 +67,17 @@ impl<T> TypeIdBuckets<T> {
}
}

impl<T: Clone + std::fmt::Debug> TypeIdBuckets<T> {
pub(crate) fn entries(&self) -> Vec<((TypeId, &'static str), Vec<T>)> {
self.type_plugins_lookup
.iter()
.map(|(id, associations)| -> ((TypeId, &'static str), Vec<T>) {
impl<T: std::fmt::Debug> TypeIdBuckets<T> {
pub(crate) fn entries(&self) -> impl Iterator<Item = ((TypeId, &'static str), &[T])> + '_ {
self.type_plugins_lookup.iter().map(
move |(id, associations)| -> ((TypeId, &'static str), &[T]) {
let name = self
.track_type_names
.lookup_name(&id)
.expect("all type ids with associations have a name saved");
((*id, name), associations.to_vec())
})
.collect()
((*id, name), associations)
},
)
}

pub(crate) fn associate_type<U: 'static>(&mut self, assoc: T) -> AssociateResult {
Expand Down Expand Up @@ -219,9 +217,9 @@ pub struct AppWorkloadInfo {
}

#[derive(Clone)]
pub(crate) struct Blind<T: Clone + 'static>(pub T);
pub(crate) struct Blind<T>(pub T);

impl<T: Clone + 'static> std::fmt::Debug for Blind<T> {
impl<T> std::fmt::Debug for Blind<T> {
fn fmt(&self, mut f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(&mut f, "Blind<{}>", type_name::<T>())
}
Expand All @@ -234,7 +232,7 @@ impl AppWorkload {
for workload_name in self.names.iter() {
let span = trace_span!("AppWorkload::run", ?workload_name);
let _span = span.enter();
app.world.run_workload(&workload_name).unwrap();
app.world.run_workload(workload_name).unwrap();
}
}
}
Expand Down Expand Up @@ -282,17 +280,10 @@ impl<'a> AppBuilder<'a> {
signature,
} = self;

let mut update_workload = systems.into_iter().fold(
WorkloadBuilder::new(update_stage.clone()),
|mut acc: WorkloadBuilder, system: WorkloadSystem| {
acc.with_system(system);
acc
},
);
let mut update_workload = WorkloadBuilder::new(update_stage.clone());

for reset_system in resets {
update_workload.with_system(reset_system);
}
update_workload.extend(systems);
update_workload.extend(resets);

let info = update_workload.add_to_world_with_info(&app.world).unwrap();
(
Expand Down Expand Up @@ -325,7 +316,8 @@ impl<'a> AppBuilder<'a> {
.is_first()
{
self.app.world.borrow::<ViewMut<T>>().unwrap().update_pack();
self.resets.push(system!(reset_update_pack::<T>));
self.resets
.push(reset_update_pack::<T>.into_workload_system().unwrap());
}

self
Expand All @@ -340,7 +332,8 @@ impl<'a> AppBuilder<'a> {
.associate_plugin::<T>(&self.track_current_plugin, reason)
.is_first()
{
self.resets.push(system!(reset_tracked_unique::<T>));
self.resets
.push(reset_tracked_unique::<T>.into_workload_system().unwrap());
}

self
Expand Down Expand Up @@ -443,8 +436,8 @@ impl<'a> AppBuilder<'a> {
}

#[track_caller]
pub fn add_system(&mut self, system: WorkloadSystem) -> &mut Self {
self.systems.push(system);
pub fn add_system<B, R, S: IntoWorkloadSystem<B, R>>(&mut self, system: S) -> &mut Self {
self.systems.push(system.into_workload_system().unwrap());

self
}
Expand Down
Loading