perf: ⚡ fish counter following performance improved
This commit is contained in:
parent
de29059c13
commit
79f115c6ef
2 changed files with 16 additions and 9 deletions
|
@ -1,8 +1,9 @@
|
||||||
use bevy::{
|
use bevy::{
|
||||||
app::{App, PluginGroup, Startup, Update},
|
app::{App, PluginGroup, Startup, Update},
|
||||||
diagnostic::FrameTimeDiagnosticsPlugin,
|
diagnostic::FrameTimeDiagnosticsPlugin,
|
||||||
|
prelude::IntoSystemConfigs,
|
||||||
utils::default,
|
utils::default,
|
||||||
window::{PresentMode, Window, WindowPlugin, WindowTheme},
|
window::{Window, WindowPlugin, WindowTheme},
|
||||||
DefaultPlugins,
|
DefaultPlugins,
|
||||||
};
|
};
|
||||||
use camera::UserCamera;
|
use camera::UserCamera;
|
||||||
|
@ -15,7 +16,7 @@ mod player;
|
||||||
mod ui;
|
mod ui;
|
||||||
mod water;
|
mod water;
|
||||||
|
|
||||||
pub const CHARACTER_SPEED: f32 = 300.0;
|
pub const CHARACTER_SPEED: f32 = 1000.0;
|
||||||
pub const CAMERA_DECAY_RATE: f32 = 3.0;
|
pub const CAMERA_DECAY_RATE: f32 = 3.0;
|
||||||
pub const FISHING_AREA_RADIUS: f32 = 100.0;
|
pub const FISHING_AREA_RADIUS: f32 = 100.0;
|
||||||
|
|
||||||
|
@ -24,7 +25,7 @@ pub fn start_game() {
|
||||||
.add_plugins(DefaultPlugins.set(WindowPlugin {
|
.add_plugins(DefaultPlugins.set(WindowPlugin {
|
||||||
primary_window: Some(Window {
|
primary_window: Some(Window {
|
||||||
title: "Fisher ~Tahinli".to_owned(),
|
title: "Fisher ~Tahinli".to_owned(),
|
||||||
present_mode: PresentMode::AutoVsync,
|
// present_mode: PresentMode::Immediate, //Vsync off
|
||||||
window_theme: Some(WindowTheme::Dark),
|
window_theme: Some(WindowTheme::Dark),
|
||||||
..default()
|
..default()
|
||||||
}),
|
}),
|
||||||
|
@ -47,7 +48,7 @@ pub fn start_game() {
|
||||||
(
|
(
|
||||||
FPSText::update,
|
FPSText::update,
|
||||||
UserCamera::update,
|
UserCamera::update,
|
||||||
Player::r#move,
|
Player::r#move.before(FishCounterText::update),
|
||||||
Water::fishing,
|
Water::fishing,
|
||||||
FishCounterText::update,
|
FishCounterText::update,
|
||||||
),
|
),
|
||||||
|
|
16
src/ui.rs
16
src/ui.rs
|
@ -1,3 +1,5 @@
|
||||||
|
use std::sync::{Arc, LazyLock, RwLock};
|
||||||
|
|
||||||
use bevy::{
|
use bevy::{
|
||||||
diagnostic::{DiagnosticsStore, FrameTimeDiagnosticsPlugin},
|
diagnostic::{DiagnosticsStore, FrameTimeDiagnosticsPlugin},
|
||||||
prelude::*,
|
prelude::*,
|
||||||
|
@ -5,6 +7,9 @@ use bevy::{
|
||||||
|
|
||||||
use crate::player::Player;
|
use crate::player::Player;
|
||||||
|
|
||||||
|
const FISH_COUNTER_OFFSET: Vec3 = Vec3::new(50.0, 50.0, 1.0);
|
||||||
|
static FISH_COUNT: LazyLock<Arc<RwLock<usize>>> = LazyLock::new(|| Arc::new(RwLock::new(0)));
|
||||||
|
|
||||||
#[derive(Debug, Component)]
|
#[derive(Debug, Component)]
|
||||||
pub struct FPSText;
|
pub struct FPSText;
|
||||||
|
|
||||||
|
@ -63,12 +68,13 @@ impl FishCounterText {
|
||||||
let player = player_query.get_single().unwrap();
|
let player = player_query.get_single().unwrap();
|
||||||
|
|
||||||
let player_position = player_transform_query.get_single().unwrap();
|
let player_position = player_transform_query.get_single().unwrap();
|
||||||
let mut new_fish_counter_text_position = player_position.translation.truncate().extend(1.0);
|
let mut new_fish_counter_text_position = player_position.translation.truncate().extend(0.0);
|
||||||
new_fish_counter_text_position.x += 50.0;
|
new_fish_counter_text_position += FISH_COUNTER_OFFSET;
|
||||||
new_fish_counter_text_position.y += 50.0;
|
|
||||||
|
|
||||||
fish_counter_text_transform.translation = new_fish_counter_text_position;
|
fish_counter_text_transform.translation = new_fish_counter_text_position;
|
||||||
*fish_counter_text = format!("Fish Count = {}", player.fish_count).into();
|
if *FISH_COUNT.read().unwrap() != player.fish_count {
|
||||||
|
*FISH_COUNT.write().unwrap() = player.fish_count;
|
||||||
|
*fish_counter_text = format!("Fish Count = {}", player.fish_count).into();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue