revert to non-benchmark
This commit is contained in:
+1
-1
@@ -268,7 +268,7 @@ fn calculate_path(tilemap: &TileMap, start: IVec3, goal: IVec3) -> Vec<Vec3> {
|
||||
let current = current_node.position;
|
||||
|
||||
if current == goal {
|
||||
println!("path found");
|
||||
// println!("path found");
|
||||
return reconstruct_path(came_from, current);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
pub const PIXEL_RATIO: f32 = 2.0;
|
||||
pub const TILE_SIZE: f32 = 16.0 * PIXEL_RATIO;
|
||||
pub const ITILE_SIZE: i32 = TILE_SIZE as i32;
|
||||
pub const UTILE_SIZE: u32 = TILE_SIZE as u32;
|
||||
|
||||
+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(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+7
-34
@@ -1,5 +1,4 @@
|
||||
use crate::{game, tiles};
|
||||
use bevy::ecs::system::ParamSet;
|
||||
use bevy::prelude::*;
|
||||
use std::collections::HashMap;
|
||||
|
||||
@@ -77,40 +76,14 @@ pub struct TileMap {
|
||||
|
||||
//TODO, redo
|
||||
pub fn update_tile_visibility(
|
||||
z_index: ResMut<game::ZIndex>,
|
||||
mut query_set: ParamSet<(
|
||||
Query<(&FloorTile, &mut Visibility), Without<NeedsOccluded>>,
|
||||
Query<(&FixtureTile, &mut Visibility), Without<NeedsOccluded>>,
|
||||
)>,
|
||||
// z_index: ResMut<game::ZIndex>,
|
||||
mut cwss: ResMut<tiles::CurrentWorldSpriteState>,
|
||||
) {
|
||||
let z_index = (z_index.0 as i32 + 150) as usize;
|
||||
|
||||
// Update floor visibility
|
||||
query_set
|
||||
.p0()
|
||||
.par_iter_mut()
|
||||
.for_each(|(tile, mut visibility)| {
|
||||
let is_visible = (tile.visible_range[z_index / 32] & (1 << (z_index % 32) as u32)) != 0;
|
||||
*visibility = if is_visible {
|
||||
Visibility::Visible
|
||||
} else {
|
||||
Visibility::Hidden
|
||||
};
|
||||
});
|
||||
|
||||
// Update fixture visibility
|
||||
query_set
|
||||
.p1()
|
||||
.par_iter_mut()
|
||||
.for_each(|(fixture, mut visibility)| {
|
||||
let is_visible =
|
||||
(fixture.visible_range[z_index / 32] & (1 << (z_index % 32) as u32)) != 0;
|
||||
*visibility = if is_visible {
|
||||
Visibility::Visible
|
||||
} else {
|
||||
Visibility::Hidden
|
||||
};
|
||||
});
|
||||
println!("update_tile_visibility, cwss.state = {:?}", cwss.state);
|
||||
cwss.state = tiles::WorldSpriteState::WaitingForRender;
|
||||
println!("update_tile_visibility, cwss.state = {:?}", cwss.state);
|
||||
println!("");
|
||||
// let z_index = (z_index.0 as i32 + 150) as usize;
|
||||
}
|
||||
|
||||
#[derive(Component)]
|
||||
|
||||
@@ -2,7 +2,6 @@ use crate::constants::{ITILE_SIZE, TILE_SIZE};
|
||||
use crate::tile::{self, FixtureTile, FloorTile, NeedsOccluded, TileMap};
|
||||
use crate::tiles::{self, FixtureTilePrefab, FloorTilePrefab, Textures};
|
||||
use bevy::prelude::*;
|
||||
use bevy::text::cosmic_text::ttf_parser::gpos::PositioningSubtable;
|
||||
use noise::{NoiseFn, Perlin};
|
||||
use std::collections::HashMap;
|
||||
|
||||
|
||||
+16
-11
@@ -1,7 +1,7 @@
|
||||
use std::process::exit;
|
||||
|
||||
use crate::constants::*;
|
||||
use crate::tile::{FixtureTile, FloorTile, NeedsOccluded, TileState};
|
||||
use crate::{constants::*, game};
|
||||
use bevy::utils::HashMap;
|
||||
use bevy::{prelude::*, transform};
|
||||
|
||||
@@ -98,6 +98,7 @@ pub fn build_world_sprites(
|
||||
mut cwss: ResMut<CurrentWorldSpriteState>,
|
||||
textures: Res<Textures>,
|
||||
texture_ids: Res<TextureIDs>,
|
||||
z_index: ResMut<game::ZIndex>,
|
||||
) {
|
||||
if cwss.state != WorldSpriteState::WaitingForRender {
|
||||
return;
|
||||
@@ -105,24 +106,28 @@ pub fn build_world_sprites(
|
||||
let now = Instant::now();
|
||||
if cwss.state == WorldSpriteState::WaitingForRender {
|
||||
cwss.state = WorldSpriteState::InProgress;
|
||||
// async/thread this so we don't block the main thread
|
||||
let z_index = (z_index.0 as i32 + 150) as usize;
|
||||
println!("z_index = {}", z_index);
|
||||
|
||||
for (floortile, transform) in query.iter_mut() {
|
||||
let id = floortile.id;
|
||||
let texture_id = texture_ids.refs.get(&id).unwrap();
|
||||
let texture = textures.handles.get(texture_id).unwrap();
|
||||
let sprite = Sprite {
|
||||
image: texture.clone(),
|
||||
..Default::default()
|
||||
};
|
||||
commands.spawn((sprite, *transform));
|
||||
let is_visible =
|
||||
(floortile.visible_range[z_index / 32] & (1 << (z_index % 32) as u32)) != 0;
|
||||
if is_visible {
|
||||
let id = floortile.id;
|
||||
let texture_id = texture_ids.refs.get(&id).unwrap();
|
||||
let texture = textures.handles.get(texture_id).unwrap();
|
||||
let sprite = Sprite {
|
||||
image: texture.clone(),
|
||||
..Default::default()
|
||||
};
|
||||
commands.spawn((sprite, *transform));
|
||||
}
|
||||
}
|
||||
cwss.state = WorldSpriteState::RenderReady;
|
||||
}
|
||||
println!("{:?}", cwss.state);
|
||||
let elapsed = now.elapsed();
|
||||
println!("Elapsed: {:.2?}", elapsed);
|
||||
// exit(0);
|
||||
}
|
||||
|
||||
#[derive(Bundle)]
|
||||
|
||||
Reference in New Issue
Block a user