revert to non-benchmark
This commit is contained in:
+10
-151
@@ -1,9 +1,4 @@
|
||||
use std::fs::File;
|
||||
|
||||
use bevy::prelude::*;
|
||||
use bevy::window::WindowMode;
|
||||
use std::io::Write;
|
||||
use tile::CameraMoved;
|
||||
|
||||
mod camera;
|
||||
mod citizen;
|
||||
@@ -29,7 +24,6 @@ fn main() {
|
||||
.set(WindowPlugin {
|
||||
primary_window: Some(Window {
|
||||
title: String::from("Dorf"),
|
||||
// mode: WindowMode::BorderlessFullscreen(MonitorSelection::Primary),
|
||||
..Default::default()
|
||||
}),
|
||||
..Default::default()
|
||||
@@ -39,7 +33,7 @@ fn main() {
|
||||
.add_plugins(FrameTimeDiagnosticsPlugin::default())
|
||||
.insert_resource(ClearColor(Color::srgb(0.0, 0.0, 0.0)))
|
||||
.add_plugins(tilemap::TilemapPlugin)
|
||||
.add_plugins(PathfindingPlugin)
|
||||
.add_plugins(citizen::PathfindingPlugin)
|
||||
.add_systems(
|
||||
Startup,
|
||||
(
|
||||
@@ -51,154 +45,19 @@ fn main() {
|
||||
.add_systems(
|
||||
FixedUpdate,
|
||||
(
|
||||
// camera::camera_movement,
|
||||
camera::camera_movement,
|
||||
cursor::move_cursor,
|
||||
tiles::build_world_sprites,
|
||||
tile::update_tile_visibility.run_if(|cwss: Res<tiles::CurrentWorldSpriteState>| {
|
||||
cwss.state == tiles::WorldSpriteState::RenderReady
|
||||
}),
|
||||
),
|
||||
)
|
||||
.init_resource::<tile::CameraMoved>()
|
||||
// .add_systems(
|
||||
// Update,
|
||||
// (
|
||||
// tile::camera_z_movement,
|
||||
// tile::update_tile_visibility
|
||||
// .run_if(|camera_moved: Res<tile::CameraMoved>| camera_moved.0),
|
||||
// log_fps_system,
|
||||
// ),
|
||||
// )
|
||||
.init_resource::<DiagnosticsRecorder>()
|
||||
.add_systems(Update, (start_recording_system, record_diagnostics_system))
|
||||
.add_systems(
|
||||
Update,
|
||||
(
|
||||
tile::camera_z_movement,
|
||||
tile::update_tile_visibility
|
||||
.run_if(|camera_moved: Res<tile::CameraMoved>| camera_moved.0),
|
||||
),
|
||||
)
|
||||
.run();
|
||||
}
|
||||
|
||||
use bevy::diagnostic::DiagnosticsStore;
|
||||
use citizen::PathfindingPlugin;
|
||||
|
||||
fn log_fps_system(diagnostics: Res<DiagnosticsStore>) {
|
||||
if let Some(fps) = diagnostics
|
||||
.get(&FrameTimeDiagnosticsPlugin::FPS)
|
||||
.and_then(|fps_diagnostic| fps_diagnostic.average())
|
||||
{
|
||||
println!("Average FPS: {:?}", fps);
|
||||
}
|
||||
if let Some(instantaneous_fps) = diagnostics
|
||||
.get(&FrameTimeDiagnosticsPlugin::FPS)
|
||||
.and_then(|fps_diagnostic| fps_diagnostic.value())
|
||||
{
|
||||
println!("Instantaneous FPS: {:?}", instantaneous_fps);
|
||||
}
|
||||
if let Some(ft) = diagnostics
|
||||
.get(&FrameTimeDiagnosticsPlugin::FRAME_TIME)
|
||||
.and_then(|fps_diagnostic| fps_diagnostic.average())
|
||||
{
|
||||
println!("Average FT: {:?}", ft);
|
||||
}
|
||||
if let Some(instantaneous_ft) = diagnostics
|
||||
.get(&FrameTimeDiagnosticsPlugin::FRAME_TIME)
|
||||
.and_then(|fps_diagnostic| fps_diagnostic.value())
|
||||
{
|
||||
println!("Instantaneous FT: {:?}", instantaneous_ft);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Resource)]
|
||||
struct DiagnosticsRecorder {
|
||||
start_time: Option<f64>,
|
||||
data: Vec<(f64, f64, f64, f64, f64)>, // (time, avg_fps, instantaneous_fps, avg_frame_time, instantaneous_frame_time)
|
||||
}
|
||||
|
||||
fn start_recording_system(time: Res<Time>, mut recorder: ResMut<DiagnosticsRecorder>) {
|
||||
if recorder.start_time.is_none() {
|
||||
recorder.start_time = Some(time.elapsed_secs_f64());
|
||||
}
|
||||
}
|
||||
|
||||
fn record_diagnostics_system(
|
||||
time: Res<Time>,
|
||||
diagnostics: Res<DiagnosticsStore>,
|
||||
mut recorder: ResMut<DiagnosticsRecorder>,
|
||||
mut z_index: ResMut<game::ZIndex>,
|
||||
mut camera_moved: ResMut<CameraMoved>,
|
||||
) {
|
||||
if let Some(start_time) = recorder.start_time {
|
||||
let elapsed = time.elapsed_secs_f64() - start_time;
|
||||
camera_moved.0 = false;
|
||||
|
||||
// Set z_index to -3 at the start
|
||||
if elapsed < 10.0 {
|
||||
z_index.0 = -3.0;
|
||||
camera_moved.0 = true;
|
||||
}
|
||||
|
||||
// Increase z_index by +1 every 10 seconds
|
||||
if elapsed >= 10.0 && elapsed % 10.0 < time.delta_secs_f64() {
|
||||
z_index.0 += 1.0;
|
||||
camera_moved.0 = true;
|
||||
}
|
||||
|
||||
if elapsed >= 10.0 && elapsed <= 70.0 {
|
||||
let avg_fps = diagnostics
|
||||
.get(&FrameTimeDiagnosticsPlugin::FPS)
|
||||
.and_then(|fps_diagnostic| fps_diagnostic.average())
|
||||
.unwrap_or(0.0);
|
||||
|
||||
let instantaneous_fps = diagnostics
|
||||
.get(&FrameTimeDiagnosticsPlugin::FPS)
|
||||
.and_then(|fps_diagnostic| fps_diagnostic.value())
|
||||
.unwrap_or(0.0);
|
||||
|
||||
let avg_frame_time = diagnostics
|
||||
.get(&FrameTimeDiagnosticsPlugin::FRAME_TIME)
|
||||
.and_then(|ft_diagnostic| ft_diagnostic.average())
|
||||
.unwrap_or(0.0);
|
||||
|
||||
let instantaneous_frame_time = diagnostics
|
||||
.get(&FrameTimeDiagnosticsPlugin::FRAME_TIME)
|
||||
.and_then(|ft_diagnostic| ft_diagnostic.value())
|
||||
.unwrap_or(0.0);
|
||||
|
||||
recorder.data.push((
|
||||
elapsed,
|
||||
avg_fps,
|
||||
instantaneous_fps,
|
||||
avg_frame_time,
|
||||
instantaneous_frame_time,
|
||||
));
|
||||
} else if elapsed > 70.0 {
|
||||
save_to_csv(&recorder.data);
|
||||
std::process::exit(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn save_to_csv(data: &[(f64, f64, f64, f64, f64)]) {
|
||||
if let Ok(mut file) = File::create("diagnostics.csv") {
|
||||
writeln!(
|
||||
file,
|
||||
"Time,Avg FPS,Instantaneous FPS,Avg Frame Time,Instantaneous Frame Time"
|
||||
)
|
||||
.unwrap();
|
||||
for (time, avg_fps, instantaneous_fps, avg_frame_time, instantaneous_frame_time) in data {
|
||||
writeln!(
|
||||
file,
|
||||
"{},{},{},{},{}",
|
||||
time, avg_fps, instantaneous_fps, avg_frame_time, instantaneous_frame_time
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
} else {
|
||||
eprintln!("Failed to create diagnostics.csv");
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for DiagnosticsRecorder {
|
||||
fn default() -> Self {
|
||||
DiagnosticsRecorder {
|
||||
start_time: None,
|
||||
data: Vec::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user