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

The Great Debuggening #632

Merged
merged 7 commits into from
Oct 8, 2020
Merged
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
2 changes: 1 addition & 1 deletion crates/bevy_app/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,5 @@ impl App {
}

/// An event that indicates the app should exit. This will fully exit the app process.
#[derive(Clone)]
#[derive(Debug, Clone)]
pub struct AppExit;
1 change: 0 additions & 1 deletion crates/bevy_app/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ fn map_instance_event<T>(event_instance: &EventInstance<T>) -> &T {
}

/// Reads events of type `T` in order and tracks which events have already been read.
#[derive(Debug)]
pub struct EventReader<T> {
last_event_count: usize,
_marker: PhantomData<T>,
Expand Down
2 changes: 2 additions & 0 deletions crates/bevy_asset/src/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ use bevy_type_registry::RegisterType;
use bevy_utils::HashMap;

/// Events that happen on assets of type `T`
#[derive(Debug)]
pub enum AssetEvent<T: Resource> {
Created { handle: Handle<T> },
Modified { handle: Handle<T> },
Removed { handle: Handle<T> },
}

/// Stores Assets of a given type and tracks changes to them.
#[derive(Debug)]
pub struct Assets<T: Resource> {
assets: HashMap<Handle<T>, T>,
events: Events<AssetEvent<T>>,
Expand Down
2 changes: 2 additions & 0 deletions crates/bevy_asset/src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ pub trait AssetLoader<T>: Send + Sync + 'static {
}

/// The result of loading an asset of type `T`
#[derive(Debug)]
pub struct AssetResult<T: 'static> {
pub result: Result<T, AssetLoadError>,
pub handle: Handle<T>,
Expand All @@ -41,6 +42,7 @@ pub struct AssetResult<T: 'static> {
}

/// A channel to send and receive [AssetResult]s
#[derive(Debug)]
pub struct AssetChannel<T: 'static> {
pub sender: Sender<AssetResult<T>>,
pub receiver: Receiver<AssetResult<T>>,
Expand Down
13 changes: 12 additions & 1 deletion crates/bevy_audio/src/audio_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use bevy_asset::{Assets, Handle};
use bevy_ecs::Res;
use parking_lot::RwLock;
use rodio::{Device, Sink};
use std::collections::VecDeque;
use std::{collections::VecDeque, fmt};

/// Used to play audio on the current "audio device"
pub struct AudioOutput<P = AudioSource>
Expand All @@ -14,6 +14,17 @@ where
queue: RwLock<VecDeque<Handle<P>>>,
}

impl<P> fmt::Debug for AudioOutput<P>
where
P: Decodable,
{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("AudioOutput")
.field("queue", &self.queue)
.finish()
}
}

impl<P> Default for AudioOutput<P>
where
P: Decodable,
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_audio/src/audio_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use bevy_asset::AssetLoader;
use std::{io::Cursor, path::Path, sync::Arc};

/// A source of audio data
#[derive(Clone)]
#[derive(Debug, Clone)]
pub struct AudioSource {
pub bytes: Arc<[u8]>,
}
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_core/src/label.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl Labels {
}

/// Maintains a mapping from [Entity](bevy_ecs::prelude::Entity) ids to entity labels and entity labels to [Entities](bevy_ecs::prelude::Entity).
#[derive(Default)]
#[derive(Debug, Default)]
pub struct EntityLabels {
label_entities: HashMap<Cow<'static, str>, Vec<Entity>>,
entity_labels: HashMap<Entity, HashSet<Cow<'static, str>>>,
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_diagnostic/src/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl Diagnostic {
}

/// A collection of [Diagnostic]s
#[derive(Default)]
#[derive(Debug, Default)]
pub struct Diagnostics {
diagnostics: HashMap<DiagnosticId, Diagnostic>,
}
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_diagnostic/src/system_profiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ struct SystemRunInfo {
stop: Instant,
}

#[derive(Default)]
#[derive(Debug, Default)]
struct SystemProfiles {
diagnostic_id: DiagnosticId,
history: Vec<SystemRunInfo>,
current_start: Option<Instant>,
}

/// Profiles systems by recording their run duration as diagnostics.
#[derive(Default)]
#[derive(Debug, Default)]
pub struct SystemProfiler {
system_profiles: Arc<RwLock<HashMap<Cow<'static, str>, SystemProfiles>>>,
}
Expand Down
1 change: 1 addition & 0 deletions crates/bevy_ecs/hecs/src/entities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ impl Entities {
}

/// Reserves entities in a way that is usable in multi-threaded contexts.
#[derive(Debug)]
pub struct EntityReserver {
entities: &'static Entities,
}
Expand Down
7 changes: 7 additions & 0 deletions crates/bevy_ecs/src/resource/resource_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use std::marker::PhantomData;

/// A shared borrow of a Resource
/// that will only return in a query if the Resource has been changed
#[derive(Debug)]
pub struct ChangedRes<'a, T: Resource> {
value: &'a T,
}
Expand Down Expand Up @@ -200,6 +201,7 @@ impl<'a, T: Resource> ResourceQuery for Res<'a, T> {
}

/// Fetches a shared resource reference
#[derive(Debug)]
pub struct FetchResourceRead<T>(NonNull<T>);

impl<'a, T: Resource> FetchResource<'a> for FetchResourceRead<T> {
Expand Down Expand Up @@ -229,6 +231,7 @@ impl<'a, T: Resource> ResourceQuery for ChangedRes<'a, T> {
}

/// Fetches a shared resource reference
#[derive(Debug)]
pub struct FetchResourceChanged<T>(NonNull<T>);

impl<'a, T: Resource> FetchResource<'a> for FetchResourceChanged<T> {
Expand Down Expand Up @@ -263,6 +266,7 @@ impl<'a, T: Resource> ResourceQuery for ResMut<'a, T> {
}

/// Fetches a unique resource reference
#[derive(Debug)]
pub struct FetchResourceWrite<T>(NonNull<T>);

impl<'a, T: Resource> FetchResource<'a> for FetchResourceWrite<T> {
Expand Down Expand Up @@ -300,6 +304,7 @@ impl<'a, T: Resource + FromResources> ResourceQuery for Local<'a, T> {
}

/// Fetches a `Local<T>` resource reference
#[derive(Debug)]
pub struct FetchResourceLocalMut<T>(NonNull<T>);

impl<'a, T: Resource + FromResources> FetchResource<'a> for FetchResourceLocalMut<T> {
Expand Down Expand Up @@ -385,8 +390,10 @@ macro_rules! tuple_impl {

smaller_tuples_too!(tuple_impl, O, N, M, L, K, J, I, H, G, F, E, D, C, B, A);

#[derive(Debug)]
pub struct OrRes<T>(T);

#[derive(Debug)]
pub struct FetchResourceOr<T>(NonNull<T>);

macro_rules! tuple_impl_or {
Expand Down
4 changes: 3 additions & 1 deletion crates/bevy_ecs/src/resource/resources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,21 @@ use std::ptr::NonNull;
pub trait Resource: Send + Sync + 'static {}
impl<T: Send + Sync + 'static> Resource for T {}

#[derive(Debug)]
pub(crate) struct ResourceData {
archetype: Archetype,
default_index: Option<usize>,
system_id_to_archetype_index: HashMap<usize, usize>,
}

#[derive(Debug)]
pub enum ResourceIndex {
Global,
System(SystemId),
}

/// A collection of resource instances identified by their type.
#[derive(Default)]
#[derive(Debug, Default)]
pub struct Resources {
pub(crate) resource_data: HashMap<TypeId, ResourceData>,
}
Expand Down
23 changes: 22 additions & 1 deletion crates/bevy_ecs/src/schedule/schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
};
use bevy_hecs::World;
use bevy_utils::{HashMap, HashSet};
use std::borrow::Cow;
use std::{borrow::Cow, fmt};

/// An ordered collection of stages, which each contain an ordered list of [System]s.
/// Schedules are essentially the "execution plan" for an App's systems.
Expand All @@ -18,6 +18,27 @@ pub struct Schedule {
last_initialize_generation: usize,
}

impl fmt::Debug for Schedule {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
writeln!(f, "Schedule {{")?;

let stages = self
.stage_order
.iter()
.map(|s| (s, self.stages[s].iter().map(|s| (s.name(), s.id()))));

for (stage, syss) in stages {
writeln!(f, " Stage \"{}\"", stage)?;

for (name, id) in syss {
writeln!(f, " System {{ name: \"{}\", id: {:?} }}", name, id)?;
}
}

writeln!(f, "}}")
}
}

impl Schedule {
pub fn add_stage(&mut self, stage: impl Into<Cow<'static, str>>) {
let stage: Cow<str> = stage.into();
Expand Down
27 changes: 24 additions & 3 deletions crates/bevy_ecs/src/system/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,35 @@ use super::SystemId;
use crate::resource::{Resource, Resources};
use bevy_hecs::{Bundle, Component, DynamicBundle, Entity, EntityReserver, World};
use parking_lot::Mutex;
use std::{marker::PhantomData, sync::Arc};
use std::{fmt, marker::PhantomData, sync::Arc};

/// A queued command to mutate the current [World] or [Resources]
pub enum Command {
WriteWorld(Box<dyn WorldWriter>),
WriteResources(Box<dyn ResourcesWriter>),
}

impl fmt::Debug for Command {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Command::WriteWorld(x) => f
.debug_tuple("WriteWorld")
.field(&(x.as_ref() as *const dyn WorldWriter))
.finish(),
Command::WriteResources(x) => f
.debug_tuple("WriteResources")
.field(&(x.as_ref() as *const dyn ResourcesWriter))
.finish(),
}
}
}

/// A [World] mutation
pub trait WorldWriter: Send + Sync {
fn write(self: Box<Self>, world: &mut World);
}

#[derive(Debug)]
pub(crate) struct Spawn<T>
where
T: DynamicBundle + Send + Sync + 'static,
Expand Down Expand Up @@ -49,6 +65,7 @@ where
}
}

#[derive(Debug)]
pub(crate) struct Despawn {
entity: Entity,
}
Expand Down Expand Up @@ -76,6 +93,7 @@ where
}
}

#[derive(Debug)]
pub(crate) struct InsertOne<T>
where
T: Component,
Expand All @@ -93,6 +111,7 @@ where
}
}

#[derive(Debug)]
pub(crate) struct RemoveOne<T>
where
T: Component,
Expand All @@ -112,6 +131,7 @@ where
}
}

#[derive(Debug)]
pub(crate) struct Remove<T>
where
T: Bundle + Send + Sync + 'static,
Expand Down Expand Up @@ -143,6 +163,7 @@ impl<T: Resource> ResourcesWriter for InsertResource<T> {
}
}

#[derive(Debug)]
pub(crate) struct InsertLocalResource<T: Resource> {
resource: T,
system_id: SystemId,
Expand All @@ -154,7 +175,7 @@ impl<T: Resource> ResourcesWriter for InsertLocalResource<T> {
}
}

#[derive(Default)]
#[derive(Debug, Default)]
pub struct CommandsInternal {
pub commands: Vec<Command>,
pub current_entity: Option<Entity>,
Expand Down Expand Up @@ -212,7 +233,7 @@ impl CommandsInternal {
}

/// A queue of [Command]s to run on the current [World] and [Resources]
#[derive(Default, Clone)]
#[derive(Debug, Default, Clone)]
pub struct Commands {
pub commands: Arc<Mutex<CommandsInternal>>,
}
Expand Down
1 change: 1 addition & 0 deletions crates/bevy_ecs/src/system/into_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::{
use bevy_hecs::{Fetch, Query as HecsQuery, World};
use std::borrow::Cow;

#[derive(Debug)]
pub(crate) struct SystemFn<State, F, ThreadLocalF, Init, SetArchetypeAccess>
where
F: FnMut(&World, &Resources, &ArchetypeAccess, &mut State) + Send + Sync,
Expand Down
Loading