Skip to content

Commit 354d71c

Browse files
authored
The Great Debuggening (#632)
The Great Debuggening
1 parent a92790c commit 354d71c

File tree

79 files changed

+339
-71
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+339
-71
lines changed

crates/bevy_app/src/app.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,5 +80,5 @@ impl App {
8080
}
8181

8282
/// An event that indicates the app should exit. This will fully exit the app process.
83-
#[derive(Clone)]
83+
#[derive(Debug, Clone)]
8484
pub struct AppExit;

crates/bevy_app/src/event.rs

-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ fn map_instance_event<T>(event_instance: &EventInstance<T>) -> &T {
8383
}
8484

8585
/// Reads events of type `T` in order and tracks which events have already been read.
86-
#[derive(Debug)]
8786
pub struct EventReader<T> {
8887
last_event_count: usize,
8988
_marker: PhantomData<T>,

crates/bevy_asset/src/assets.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ use bevy_type_registry::RegisterType;
88
use bevy_utils::HashMap;
99

1010
/// Events that happen on assets of type `T`
11+
#[derive(Debug)]
1112
pub enum AssetEvent<T: Resource> {
1213
Created { handle: Handle<T> },
1314
Modified { handle: Handle<T> },
1415
Removed { handle: Handle<T> },
1516
}
1617

1718
/// Stores Assets of a given type and tracks changes to them.
19+
#[derive(Debug)]
1820
pub struct Assets<T: Resource> {
1921
assets: HashMap<Handle<T>, T>,
2022
events: Events<AssetEvent<T>>,

crates/bevy_asset/src/loader.rs

+2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ pub trait AssetLoader<T>: Send + Sync + 'static {
3333
}
3434

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

4344
/// A channel to send and receive [AssetResult]s
45+
#[derive(Debug)]
4446
pub struct AssetChannel<T: 'static> {
4547
pub sender: Sender<AssetResult<T>>,
4648
pub receiver: Receiver<AssetResult<T>>,

crates/bevy_audio/src/audio_output.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use bevy_asset::{Assets, Handle};
33
use bevy_ecs::Res;
44
use parking_lot::RwLock;
55
use rodio::{Device, Sink};
6-
use std::collections::VecDeque;
6+
use std::{collections::VecDeque, fmt};
77

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

17+
impl<P> fmt::Debug for AudioOutput<P>
18+
where
19+
P: Decodable,
20+
{
21+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
22+
f.debug_struct("AudioOutput")
23+
.field("queue", &self.queue)
24+
.finish()
25+
}
26+
}
27+
1728
impl<P> Default for AudioOutput<P>
1829
where
1930
P: Decodable,

crates/bevy_audio/src/audio_source.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use bevy_asset::AssetLoader;
33
use std::{io::Cursor, path::Path, sync::Arc};
44

55
/// A source of audio data
6-
#[derive(Clone)]
6+
#[derive(Debug, Clone)]
77
pub struct AudioSource {
88
pub bytes: Arc<[u8]>,
99
}

crates/bevy_core/src/label.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl Labels {
5252
}
5353

5454
/// Maintains a mapping from [Entity](bevy_ecs::prelude::Entity) ids to entity labels and entity labels to [Entities](bevy_ecs::prelude::Entity).
55-
#[derive(Default)]
55+
#[derive(Debug, Default)]
5656
pub struct EntityLabels {
5757
label_entities: HashMap<Cow<'static, str>, Vec<Entity>>,
5858
entity_labels: HashMap<Entity, HashSet<Cow<'static, str>>>,

crates/bevy_diagnostic/src/diagnostic.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ impl Diagnostic {
103103
}
104104

105105
/// A collection of [Diagnostic]s
106-
#[derive(Default)]
106+
#[derive(Debug, Default)]
107107
pub struct Diagnostics {
108108
diagnostics: HashMap<DiagnosticId, Diagnostic>,
109109
}

crates/bevy_diagnostic/src/system_profiler.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ struct SystemRunInfo {
1515
stop: Instant,
1616
}
1717

18-
#[derive(Default)]
18+
#[derive(Debug, Default)]
1919
struct SystemProfiles {
2020
diagnostic_id: DiagnosticId,
2121
history: Vec<SystemRunInfo>,
2222
current_start: Option<Instant>,
2323
}
2424

2525
/// Profiles systems by recording their run duration as diagnostics.
26-
#[derive(Default)]
26+
#[derive(Debug, Default)]
2727
pub struct SystemProfiler {
2828
system_profiles: Arc<RwLock<HashMap<Cow<'static, str>, SystemProfiles>>>,
2929
}

crates/bevy_ecs/hecs/src/entities.rs

+1
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ impl Entities {
322322
}
323323

324324
/// Reserves entities in a way that is usable in multi-threaded contexts.
325+
#[derive(Debug)]
325326
pub struct EntityReserver {
326327
entities: &'static Entities,
327328
}

crates/bevy_ecs/src/resource/resource_query.rs

+7
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use std::marker::PhantomData;
1313

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

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

205207
impl<'a, T: Resource> FetchResource<'a> for FetchResourceRead<T> {
@@ -229,6 +231,7 @@ impl<'a, T: Resource> ResourceQuery for ChangedRes<'a, T> {
229231
}
230232

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

234237
impl<'a, T: Resource> FetchResource<'a> for FetchResourceChanged<T> {
@@ -263,6 +266,7 @@ impl<'a, T: Resource> ResourceQuery for ResMut<'a, T> {
263266
}
264267

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

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

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

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

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

393+
#[derive(Debug)]
388394
pub struct OrRes<T>(T);
389395

396+
#[derive(Debug)]
390397
pub struct FetchResourceOr<T>(NonNull<T>);
391398

392399
macro_rules! tuple_impl_or {

crates/bevy_ecs/src/resource/resources.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,21 @@ use std::ptr::NonNull;
99
pub trait Resource: Send + Sync + 'static {}
1010
impl<T: Send + Sync + 'static> Resource for T {}
1111

12+
#[derive(Debug)]
1213
pub(crate) struct ResourceData {
1314
archetype: Archetype,
1415
default_index: Option<usize>,
1516
system_id_to_archetype_index: HashMap<usize, usize>,
1617
}
1718

19+
#[derive(Debug)]
1820
pub enum ResourceIndex {
1921
Global,
2022
System(SystemId),
2123
}
2224

2325
/// A collection of resource instances identified by their type.
24-
#[derive(Default)]
26+
#[derive(Debug, Default)]
2527
pub struct Resources {
2628
pub(crate) resource_data: HashMap<TypeId, ResourceData>,
2729
}

crates/bevy_ecs/src/schedule/schedule.rs

+22-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::{
44
};
55
use bevy_hecs::World;
66
use bevy_utils::{HashMap, HashSet};
7-
use std::borrow::Cow;
7+
use std::{borrow::Cow, fmt};
88

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

21+
impl fmt::Debug for Schedule {
22+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
23+
writeln!(f, "Schedule {{")?;
24+
25+
let stages = self
26+
.stage_order
27+
.iter()
28+
.map(|s| (s, self.stages[s].iter().map(|s| (s.name(), s.id()))));
29+
30+
for (stage, syss) in stages {
31+
writeln!(f, " Stage \"{}\"", stage)?;
32+
33+
for (name, id) in syss {
34+
writeln!(f, " System {{ name: \"{}\", id: {:?} }}", name, id)?;
35+
}
36+
}
37+
38+
writeln!(f, "}}")
39+
}
40+
}
41+
2142
impl Schedule {
2243
pub fn add_stage(&mut self, stage: impl Into<Cow<'static, str>>) {
2344
let stage: Cow<str> = stage.into();

crates/bevy_ecs/src/system/commands.rs

+24-3
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,35 @@ use super::SystemId;
22
use crate::resource::{Resource, Resources};
33
use bevy_hecs::{Bundle, Component, DynamicBundle, Entity, EntityReserver, World};
44
use parking_lot::Mutex;
5-
use std::{marker::PhantomData, sync::Arc};
5+
use std::{fmt, marker::PhantomData, sync::Arc};
66

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

13+
impl fmt::Debug for Command {
14+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
15+
match self {
16+
Command::WriteWorld(x) => f
17+
.debug_tuple("WriteWorld")
18+
.field(&(x.as_ref() as *const dyn WorldWriter))
19+
.finish(),
20+
Command::WriteResources(x) => f
21+
.debug_tuple("WriteResources")
22+
.field(&(x.as_ref() as *const dyn ResourcesWriter))
23+
.finish(),
24+
}
25+
}
26+
}
27+
1328
/// A [World] mutation
1429
pub trait WorldWriter: Send + Sync {
1530
fn write(self: Box<Self>, world: &mut World);
1631
}
1732

33+
#[derive(Debug)]
1834
pub(crate) struct Spawn<T>
1935
where
2036
T: DynamicBundle + Send + Sync + 'static,
@@ -49,6 +65,7 @@ where
4965
}
5066
}
5167

68+
#[derive(Debug)]
5269
pub(crate) struct Despawn {
5370
entity: Entity,
5471
}
@@ -76,6 +93,7 @@ where
7693
}
7794
}
7895

96+
#[derive(Debug)]
7997
pub(crate) struct InsertOne<T>
8098
where
8199
T: Component,
@@ -93,6 +111,7 @@ where
93111
}
94112
}
95113

114+
#[derive(Debug)]
96115
pub(crate) struct RemoveOne<T>
97116
where
98117
T: Component,
@@ -112,6 +131,7 @@ where
112131
}
113132
}
114133

134+
#[derive(Debug)]
115135
pub(crate) struct Remove<T>
116136
where
117137
T: Bundle + Send + Sync + 'static,
@@ -143,6 +163,7 @@ impl<T: Resource> ResourcesWriter for InsertResource<T> {
143163
}
144164
}
145165

166+
#[derive(Debug)]
146167
pub(crate) struct InsertLocalResource<T: Resource> {
147168
resource: T,
148169
system_id: SystemId,
@@ -154,7 +175,7 @@ impl<T: Resource> ResourcesWriter for InsertLocalResource<T> {
154175
}
155176
}
156177

157-
#[derive(Default)]
178+
#[derive(Debug, Default)]
158179
pub struct CommandsInternal {
159180
pub commands: Vec<Command>,
160181
pub current_entity: Option<Entity>,
@@ -212,7 +233,7 @@ impl CommandsInternal {
212233
}
213234

214235
/// A queue of [Command]s to run on the current [World] and [Resources]
215-
#[derive(Default, Clone)]
236+
#[derive(Debug, Default, Clone)]
216237
pub struct Commands {
217238
pub commands: Arc<Mutex<CommandsInternal>>,
218239
}

crates/bevy_ecs/src/system/into_system.rs

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use crate::{
77
use bevy_hecs::{Fetch, Query as HecsQuery, World};
88
use std::borrow::Cow;
99

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

0 commit comments

Comments
 (0)