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"
|
"GameTick is more than 10 ticks behind, skipping ticks so we don't have to burst too much"
|
||||||
);
|
);
|
||||||
*last_tick = now;
|
*last_tick = now;
|
||||||
|
|
||||||
// TODO: do we increment TickComponent here?
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
last_tick = Some(now);
|
last_tick = Some(now);
|
||||||
|
|
|
@ -128,9 +128,6 @@ impl Default for Hunger {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Component, Clone, Debug, Default)]
|
|
||||||
pub struct TicksAlive(pub u64);
|
|
||||||
|
|
||||||
impl InstanceHolder {
|
impl InstanceHolder {
|
||||||
/// Create a new `InstanceHolder` for the given entity.
|
/// Create a new `InstanceHolder` for the given entity.
|
||||||
///
|
///
|
||||||
|
|
|
@ -11,7 +11,7 @@ use tracing::info;
|
||||||
use super::login::IsAuthenticated;
|
use super::login::IsAuthenticated;
|
||||||
use crate::{
|
use crate::{
|
||||||
chat_signing, client::JoinedClientBundle, connection::RawConnection, loading::HasClientLoaded,
|
chat_signing, client::JoinedClientBundle, connection::RawConnection, loading::HasClientLoaded,
|
||||||
local_player::{InstanceHolder, TicksAlive},
|
local_player::InstanceHolder, tick_counter::TicksConnected,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct DisconnectPlugin;
|
pub struct DisconnectPlugin;
|
||||||
|
@ -73,7 +73,7 @@ pub struct RemoveOnDisconnectBundle {
|
||||||
// send ServerboundPlayerLoaded next time we join.
|
// send ServerboundPlayerLoaded next time we join.
|
||||||
pub has_client_loaded: HasClientLoaded,
|
pub has_client_loaded: HasClientLoaded,
|
||||||
// TickCounter is reset on reconnect
|
// 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
|
/// 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::{
|
use crate::{
|
||||||
block_update::QueuedServerBlockUpdates, chat::{ChatPacket, ChatReceivedEvent}, chunks, connection::RawConnection, declare_packet_handlers, disconnect::DisconnectEvent, interact::BlockStatePredictionHandler, inventory::{
|
block_update::QueuedServerBlockUpdates, chat::{ChatPacket, ChatReceivedEvent}, chunks, connection::RawConnection, declare_packet_handlers, disconnect::DisconnectEvent, interact::BlockStatePredictionHandler, inventory::{
|
||||||
ClientSideCloseContainerEvent, Inventory, MenuOpenedEvent, SetContainerContentEvent,
|
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) {
|
pub fn process_packet(ecs: &mut World, player: Entity, packet: &ClientboundGamePacket) {
|
||||||
|
@ -286,7 +286,7 @@ impl GamePacketHandler<'_> {
|
||||||
previous: p.common.previous_game_type.into(),
|
previous: p.common.previous_game_type.into(),
|
||||||
},
|
},
|
||||||
entity_bundle,
|
entity_bundle,
|
||||||
TicksAlive(0),
|
TicksConnected(0),
|
||||||
));
|
));
|
||||||
|
|
||||||
azalea_entity::indexing::add_entity_to_indexes(
|
azalea_entity::indexing::add_entity_to_indexes(
|
||||||
|
|
|
@ -5,7 +5,12 @@ use azalea_world::InstanceName;
|
||||||
use bevy_app::{App, Plugin};
|
use bevy_app::{App, Plugin};
|
||||||
use bevy_ecs::prelude::*;
|
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**
|
/// Inserts the counter-increment system into the `GameTick` schedule **before**
|
||||||
/// physics, mining and movement.
|
/// physics, mining and movement.
|
||||||
|
@ -25,7 +30,7 @@ impl Plugin for TickCounterPlugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Increment the [`GameTickCounter`] on every entity that lives in an instance.
|
/// 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 {
|
for mut counter in &mut query {
|
||||||
counter.0 += 1;
|
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_core::resource_location::ResourceLocation;
|
||||||
use azalea_protocol::packets::{config::{ClientboundFinishConfiguration, ClientboundRegistryData}, ConnectionProtocol};
|
use azalea_protocol::packets::{config::{ClientboundFinishConfiguration, ClientboundRegistryData}, ConnectionProtocol};
|
||||||
use azalea_registry::{DataRegistry, DimensionType};
|
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
|
// we need a second tick to handle the state switch properly
|
||||||
simulation.tick();
|
simulation.tick();
|
||||||
|
|
||||||
assert!(!simulation.has_component::<TicksAlive>());
|
assert!(!simulation.has_component::<TicksConnected>());
|
||||||
|
|
||||||
simulation.receive_packet(make_basic_login_packet(
|
simulation.receive_packet(make_basic_login_packet(
|
||||||
DimensionType::new_raw(0), // overworld
|
DimensionType::new_raw(0), // overworld
|
||||||
|
@ -37,13 +37,13 @@ fn counter_increments_and_resets_on_disconnect() {
|
||||||
));
|
));
|
||||||
simulation.tick();
|
simulation.tick();
|
||||||
|
|
||||||
assert!(simulation.has_component::<TicksAlive>());
|
assert!(simulation.has_component::<TicksConnected>());
|
||||||
assert_eq!(simulation.component::<TicksAlive>().0, 1);
|
assert_eq!(simulation.component::<TicksConnected>().0, 1);
|
||||||
|
|
||||||
// Tick three times; counter should read 2, 3, 4.
|
// Tick three times; counter should read 2, 3, 4.
|
||||||
for expected in 2..=4 {
|
for expected in 2..=4 {
|
||||||
simulation.tick();
|
simulation.tick();
|
||||||
let counter = simulation.component::<TicksAlive>();
|
let counter = simulation.component::<TicksConnected>();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
counter.0, expected,
|
counter.0, expected,
|
||||||
"after {expected} tick(s) counter should be {expected}"
|
"after {expected} tick(s) counter should be {expected}"
|
||||||
|
@ -53,5 +53,5 @@ fn counter_increments_and_resets_on_disconnect() {
|
||||||
simulation.disconnect();
|
simulation.disconnect();
|
||||||
simulation.tick();
|
simulation.tick();
|
||||||
|
|
||||||
assert!(!simulation.has_component::<TicksAlive>());
|
assert!(!simulation.has_component::<TicksConnected>());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue