mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 14:26:04 +00:00
Rename TicksAlive to TicksConnected
* Move component to plugins/tick_counter.rs and add doc comment
This commit is contained in:
parent
9e1952de7a
commit
80a1071077
6 changed files with 17 additions and 17 deletions
|
@ -705,8 +705,6 @@ async fn run_schedule_loop(ecs: Arc<Mutex<World>>, outer_schedule_label: Interne
|
|||
"GameTick is more than 10 ticks behind, skipping ticks so we don't have to burst too much"
|
||||
);
|
||||
*last_tick = now;
|
||||
|
||||
// TODO: do we increment TickComponent here?
|
||||
}
|
||||
} else {
|
||||
last_tick = Some(now);
|
||||
|
|
|
@ -128,9 +128,6 @@ impl Default for Hunger {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Component, Clone, Debug, Default)]
|
||||
pub struct TicksAlive(pub u64);
|
||||
|
||||
impl InstanceHolder {
|
||||
/// Create a new `InstanceHolder` for the given entity.
|
||||
///
|
||||
|
|
|
@ -11,7 +11,7 @@ use tracing::info;
|
|||
use super::login::IsAuthenticated;
|
||||
use crate::{
|
||||
chat_signing, client::JoinedClientBundle, connection::RawConnection, loading::HasClientLoaded,
|
||||
local_player::{InstanceHolder, TicksAlive},
|
||||
local_player::InstanceHolder, tick_counter::TicksConnected,
|
||||
};
|
||||
|
||||
pub struct DisconnectPlugin;
|
||||
|
@ -73,7 +73,7 @@ pub struct RemoveOnDisconnectBundle {
|
|||
// send ServerboundPlayerLoaded next time we join.
|
||||
pub has_client_loaded: HasClientLoaded,
|
||||
// TickCounter is reset on reconnect
|
||||
pub ticks_alive: TicksAlive,
|
||||
pub ticks_alive: TicksConnected,
|
||||
}
|
||||
|
||||
/// A system that removes the several components from our clients when they get
|
||||
|
|
|
@ -24,7 +24,7 @@ use tracing::{debug, error, trace, warn};
|
|||
use crate::{
|
||||
block_update::QueuedServerBlockUpdates, chat::{ChatPacket, ChatReceivedEvent}, chunks, connection::RawConnection, declare_packet_handlers, disconnect::DisconnectEvent, interact::BlockStatePredictionHandler, inventory::{
|
||||
ClientSideCloseContainerEvent, Inventory, MenuOpenedEvent, SetContainerContentEvent,
|
||||
}, loading::HasClientLoaded, local_player::{Hunger, InstanceHolder, LocalGameMode, PlayerAbilities, TabList, TicksAlive}, movement::{KnockbackEvent, KnockbackType}, packet::as_system, player::{GameProfileComponent, PlayerInfo}, ClientInformation
|
||||
}, loading::HasClientLoaded, local_player::{Hunger, InstanceHolder, LocalGameMode, PlayerAbilities, TabList}, movement::{KnockbackEvent, KnockbackType}, packet::as_system, player::{GameProfileComponent, PlayerInfo}, tick_counter::TicksConnected, ClientInformation
|
||||
};
|
||||
|
||||
pub fn process_packet(ecs: &mut World, player: Entity, packet: &ClientboundGamePacket) {
|
||||
|
@ -286,7 +286,7 @@ impl GamePacketHandler<'_> {
|
|||
previous: p.common.previous_game_type.into(),
|
||||
},
|
||||
entity_bundle,
|
||||
TicksAlive(0),
|
||||
TicksConnected(0),
|
||||
));
|
||||
|
||||
azalea_entity::indexing::add_entity_to_indexes(
|
||||
|
|
|
@ -5,7 +5,12 @@ use azalea_world::InstanceName;
|
|||
use bevy_app::{App, Plugin};
|
||||
use bevy_ecs::prelude::*;
|
||||
|
||||
use crate::{local_player::TicksAlive, mining::MiningSet, movement::send_position, tick_broadcast::send_tick_broadcast};
|
||||
use crate::{mining::MiningSet, movement::send_position, tick_broadcast::send_tick_broadcast};
|
||||
|
||||
/// Counts the number of game ticks elapsed on the **local client** since the
|
||||
/// `login` packet was received.
|
||||
#[derive(Component, Clone, Debug, Default)]
|
||||
pub struct TicksConnected(pub u64);
|
||||
|
||||
/// Inserts the counter-increment system into the `GameTick` schedule **before**
|
||||
/// physics, mining and movement.
|
||||
|
@ -25,7 +30,7 @@ impl Plugin for TickCounterPlugin {
|
|||
}
|
||||
|
||||
/// Increment the [`GameTickCounter`] on every entity that lives in an instance.
|
||||
fn increment_counter(mut query: Query<&mut TicksAlive, With<InstanceName>>) {
|
||||
fn increment_counter(mut query: Query<&mut TicksConnected, With<InstanceName>>) {
|
||||
for mut counter in &mut query {
|
||||
counter.0 += 1;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use azalea_client::{local_player::TicksAlive, test_utils::prelude::*};
|
||||
use azalea_client::{test_utils::prelude::*, tick_counter::TicksConnected};
|
||||
use azalea_core::resource_location::ResourceLocation;
|
||||
use azalea_protocol::packets::{config::{ClientboundFinishConfiguration, ClientboundRegistryData}, ConnectionProtocol};
|
||||
use azalea_registry::{DataRegistry, DimensionType};
|
||||
|
@ -29,7 +29,7 @@ fn counter_increments_and_resets_on_disconnect() {
|
|||
// we need a second tick to handle the state switch properly
|
||||
simulation.tick();
|
||||
|
||||
assert!(!simulation.has_component::<TicksAlive>());
|
||||
assert!(!simulation.has_component::<TicksConnected>());
|
||||
|
||||
simulation.receive_packet(make_basic_login_packet(
|
||||
DimensionType::new_raw(0), // overworld
|
||||
|
@ -37,13 +37,13 @@ fn counter_increments_and_resets_on_disconnect() {
|
|||
));
|
||||
simulation.tick();
|
||||
|
||||
assert!(simulation.has_component::<TicksAlive>());
|
||||
assert_eq!(simulation.component::<TicksAlive>().0, 1);
|
||||
assert!(simulation.has_component::<TicksConnected>());
|
||||
assert_eq!(simulation.component::<TicksConnected>().0, 1);
|
||||
|
||||
// Tick three times; counter should read 2, 3, 4.
|
||||
for expected in 2..=4 {
|
||||
simulation.tick();
|
||||
let counter = simulation.component::<TicksAlive>();
|
||||
let counter = simulation.component::<TicksConnected>();
|
||||
assert_eq!(
|
||||
counter.0, expected,
|
||||
"after {expected} tick(s) counter should be {expected}"
|
||||
|
@ -53,5 +53,5 @@ fn counter_increments_and_resets_on_disconnect() {
|
|||
simulation.disconnect();
|
||||
simulation.tick();
|
||||
|
||||
assert!(!simulation.has_component::<TicksAlive>());
|
||||
assert!(!simulation.has_component::<TicksConnected>());
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue