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::{
|
||||
app::{App, PluginGroup, Startup, Update},
|
||||
diagnostic::FrameTimeDiagnosticsPlugin,
|
||||
prelude::IntoSystemConfigs,
|
||||
utils::default,
|
||||
window::{PresentMode, Window, WindowPlugin, WindowTheme},
|
||||
window::{Window, WindowPlugin, WindowTheme},
|
||||
DefaultPlugins,
|
||||
};
|
||||
use camera::UserCamera;
|
||||
|
@ -15,7 +16,7 @@ mod player;
|
|||
mod ui;
|
||||
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 FISHING_AREA_RADIUS: f32 = 100.0;
|
||||
|
||||
|
@ -24,7 +25,7 @@ pub fn start_game() {
|
|||
.add_plugins(DefaultPlugins.set(WindowPlugin {
|
||||
primary_window: Some(Window {
|
||||
title: "Fisher ~Tahinli".to_owned(),
|
||||
present_mode: PresentMode::AutoVsync,
|
||||
// present_mode: PresentMode::Immediate, //Vsync off
|
||||
window_theme: Some(WindowTheme::Dark),
|
||||
..default()
|
||||
}),
|
||||
|
@ -47,7 +48,7 @@ pub fn start_game() {
|
|||
(
|
||||
FPSText::update,
|
||||
UserCamera::update,
|
||||
Player::r#move,
|
||||
Player::r#move.before(FishCounterText::update),
|
||||
Water::fishing,
|
||||
FishCounterText::update,
|
||||
),
|
||||
|
|
16
src/ui.rs
16
src/ui.rs
|
@ -1,3 +1,5 @@
|
|||
use std::sync::{Arc, LazyLock, RwLock};
|
||||
|
||||
use bevy::{
|
||||
diagnostic::{DiagnosticsStore, FrameTimeDiagnosticsPlugin},
|
||||
prelude::*,
|
||||
|
@ -5,6 +7,9 @@ use bevy::{
|
|||
|
||||
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)]
|
||||
pub struct FPSText;
|
||||
|
||||
|
@ -63,12 +68,13 @@ impl FishCounterText {
|
|||
let player = player_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);
|
||||
new_fish_counter_text_position.x += 50.0;
|
||||
new_fish_counter_text_position.y += 50.0;
|
||||
|
||||
let mut new_fish_counter_text_position = player_position.translation.truncate().extend(0.0);
|
||||
new_fish_counter_text_position += FISH_COUNTER_OFFSET;
|
||||
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