forked from jakobhellermann/bevy_mod_debugdump
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_docs.rs
163 lines (140 loc) · 6.23 KB
/
generate_docs.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
use std::{any::TypeId, path::PathBuf};
use bevy::{prelude::*, render::RenderApp};
use bevy_ecs::schedule::ScheduleLabel;
use bevy_mod_debugdump::schedule_graph::{settings::Style, Settings};
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash)]
struct ScheduleDebugGroup;
fn main() -> Result<(), std::io::Error> {
let docs_path = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("docs");
let schedule_path = docs_path.join("schedule");
let render_path = docs_path.join("render");
std::fs::create_dir_all(schedule_path.join("light"))?;
std::fs::create_dir_all(schedule_path.join("dark"))?;
std::fs::create_dir_all(render_path.join("light"))?;
std::fs::create_dir_all(render_path.join("dark"))?;
let mut app = App::new();
app.add_plugins(DefaultPlugins);
let style_light = Style::light();
let style_dark = Style::dark_github();
app.world_mut()
.resource_scope::<Schedules, _>(|world, mut schedules| {
initialize_schedules(&mut schedules, world)?;
let settings_light = Settings {
style: style_light.clone(),
..Settings::default()
};
let settings_dark = Settings {
style: style_dark.clone(),
..Settings::default()
};
for (label, schedule) in schedules.iter() {
let dot_light = bevy_mod_debugdump::schedule_graph::schedule_graph_dot(
schedule,
&world,
&settings_light,
);
let dot_dark = bevy_mod_debugdump::schedule_graph::schedule_graph_dot(
schedule,
&world,
&settings_dark,
);
let filename = format!("schedule_{label:?}.dot");
std::fs::write(schedule_path.join("light").join(&filename), dot_light)?;
std::fs::write(schedule_path.join("dark").join(&filename), dot_dark)?;
}
Ok::<_, std::io::Error>(())
})?;
with_main_world_in_render_app(&mut app, |render_app| {
render_app
.world_mut()
.resource_scope::<Schedules, _>(|world, mut schedules| {
let ignored_ambiguities = schedules.ignored_scheduling_ambiguities.clone();
for (label, schedule) in schedules.iter_mut() {
// for access info
schedule.graph_mut().initialize(world);
// for `conflicting_systems`
schedule
.graph_mut()
.build_schedule(
world.components(),
ScheduleDebugGroup.intern(),
&ignored_ambiguities,
)
.unwrap();
let ignore_ambiguities = &[TypeId::of::<bevy_render::texture::TextureCache>()];
let settings_light = Settings {
style: style_light.clone(),
..Default::default()
}
.without_single_ambiguities_on_one_of(ignore_ambiguities);
let settings_dark = Settings {
style: style_dark.clone(),
..Default::default()
}
.without_single_ambiguities_on_one_of(ignore_ambiguities);
let dot_light = bevy_mod_debugdump::schedule_graph::schedule_graph_dot(
schedule,
&world,
&settings_light,
);
let dot_dark = bevy_mod_debugdump::schedule_graph::schedule_graph_dot(
schedule,
&world,
&settings_dark,
);
let filename = format!("render_schedule_{label:?}.dot");
std::fs::write(schedule_path.join("light").join(&filename), dot_light)?;
std::fs::write(schedule_path.join("dark").join(&filename), dot_dark)?;
}
Ok::<(), std::io::Error>(())
})
})?;
let settings_render_light = bevy_mod_debugdump::render_graph::Settings {
style: bevy_mod_debugdump::render_graph::settings::Style::light(),
};
let settings_render_dark = bevy_mod_debugdump::render_graph::Settings {
style: bevy_mod_debugdump::render_graph::settings::Style::dark_github(),
};
let dot_light = bevy_mod_debugdump::render_graph_dot(&app, &settings_render_light);
let dot_dark = bevy_mod_debugdump::render_graph_dot(&app, &settings_render_dark);
let filename = "render_graph.dot";
std::fs::write(render_path.join("light").join(filename), dot_light)?;
std::fs::write(render_path.join("dark").join(filename), dot_dark)?;
Ok(())
}
fn initialize_schedules(
schedules: &mut Mut<Schedules>,
world: &mut World,
) -> Result<(), std::io::Error> {
let ignored_ambiguities = schedules.ignored_scheduling_ambiguities.clone();
Ok(for (_, schedule) in schedules.iter_mut() {
// for access info
schedule.graph_mut().initialize(world);
// for `conflicting_systems`
schedule
.graph_mut()
.build_schedule(
world.components(),
ScheduleDebugGroup.intern(),
&ignored_ambiguities,
)
.unwrap();
})
}
fn with_main_world_in_render_app<T>(app: &mut App, f: impl Fn(&mut SubApp) -> T) -> T {
// temporarily add the app world to the render world as a resource
let inserted_world = std::mem::take(app.world_mut());
let mut render_main_world = bevy_render::MainWorld::default();
*render_main_world = inserted_world;
let render_app = app.sub_app_mut(RenderApp);
render_app.world().insert_resource(render_main_world);
let ret = f(render_app);
// move the app world back, as if nothing happened.
let mut inserted_world = render_app
.world()
.remove_resource::<bevy_render::MainWorld>()
.unwrap();
// FIXME: bevy 0.14 does not expose world anymore, so this pattern is not possible to my knowledge.
app.world = std::mem::take(&mut *inserted_world);
ret
}