Skip to content

Commit

Permalink
Merge pull request #383 from AnthonyTornetta/375-server-sometimes-doe…
Browse files Browse the repository at this point in the history
…snt-properly-despawn-chunk-physics-parts-sometimes-when-client-disconnects

375 server sometimes doesnt properly despawn chunk physics parts sometimes when client disconnects
  • Loading branch information
AnthonyTornetta authored Dec 21, 2024
2 parents fff9d25 + 5249f3c commit c042415
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
11 changes: 10 additions & 1 deletion cosmos_core/src/structure/shared/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use serde::{Deserialize, Serialize};
use crate::{
ecs::NeedsDespawned,
netty::sync::{IdentifiableComponent, SyncableComponent},
physics::structure_physics::ChunkPhysicsPart,
structure::{chunk::ChunkEntity, systems::StructureSystem},
};

Expand Down Expand Up @@ -42,7 +43,15 @@ pub struct DespawnWithStructure;
/// any of the things docked to it (like the player walking on it)
fn save_the_kids(
query: Query<&Children, (With<NeedsDespawned>, With<Structure>)>,
is_this_structure: Query<(), Or<(With<ChunkEntity>, With<StructureSystem>, With<DespawnWithStructure>)>>,
is_this_structure: Query<
(),
Or<(
With<ChunkEntity>,
With<ChunkPhysicsPart>,
With<StructureSystem>,
With<DespawnWithStructure>,
)>,
>,
mut commands: Commands,
) {
for children in query.iter() {
Expand Down
8 changes: 5 additions & 3 deletions cosmos_server/src/ai/pirate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,14 +215,16 @@ fn add_pirate_ai(mut commands: Commands, q_needs_ai: Query<Entity, (With<Pirate>

fn on_melt_down(
q_is_pirate: Query<(), With<PiratePilot>>,
q_melting_down: Query<(Entity, &Pilot), (With<MeltingDown>, With<PirateAi>, With<AiControlled>)>,
q_melting_down: Query<(Entity, Option<&Pilot>), (With<MeltingDown>, With<PirateAi>, With<AiControlled>)>,
mut commands: Commands,
) {
for (ent, pilot) in &q_melting_down {
commands.entity(ent).remove::<(PirateAi, AiControlled, Pirate, Pilot)>();

if q_is_pirate.contains(pilot.entity) {
commands.entity(pilot.entity).insert(NeedsDespawned);
if let Some(pilot) = pilot {
if q_is_pirate.contains(pilot.entity) {
commands.entity(pilot.entity).insert(NeedsDespawned);
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion cosmos_server/src/persistence/backup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,6 @@ pub fn zip_directory(src_dir: &Path, dest_file: &Path) -> io::Result<()> {

pub(super) fn register(app: &mut App) {
app.add_systems(First, backup_world.before(SavingSystemSet::BeginSaving))
.add_systems(Update, cleanup_backups.run_if(on_timer(std::time::Duration::from_secs(10))))
.add_systems(Update, cleanup_backups.run_if(on_timer(std::time::Duration::from_mins(20))))
.add_event::<CreateWorldBackup>();
}

0 comments on commit c042415

Please sign in to comment.