Skip to content

Commit

Permalink
Merge pull request #390 from AnthonyTornetta/389-system-ordering-has-…
Browse files Browse the repository at this point in the history
…errors

Fixed system ordering issue + adding some extra logging
  • Loading branch information
AnthonyTornetta authored Dec 23, 2024
2 parents 9f7e1c8 + d524bad commit b56c3a0
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 9 deletions.
2 changes: 1 addition & 1 deletion cosmos_server/src/entities/player/persistence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ fn save_player_link(
q_serialized_data: Query<(&SerializedData, &EntityId, Option<&LoadingDistance>)>,
) {
for (entity, e_id, player, loc) in q_player_needs_saved.iter() {
info!("Saving player {player:?} @ {loc}");
info!("Saving player {player:?} ({entity:?}) @ {loc}");
let _ = fs::create_dir_all(PLAYER_LINK_PATH);

let sfi = calculate_sfi(entity, &q_parent, &q_entity_id, &q_serialized_data).expect("Missing save file identifier for player!");
Expand Down
10 changes: 8 additions & 2 deletions cosmos_server/src/persistence/saving.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ use bevy::{
core::Name,
ecs::schedule::{IntoSystemSetConfigs, SystemSet},
hierarchy::Parent,
log::{error, warn},
log::{error, info, warn},
prelude::{App, Commands, Component, Entity, First, IntoSystemConfigs, Or, Query, ResMut, Transform, With, Without},
reflect::Reflect,
};
use bevy_rapier3d::prelude::Velocity;
use cosmos_core::{
ecs::{despawn_needed, NeedsDespawned},
entities::player::Player,
netty::cosmos_encoder,
persistence::LoadingDistance,
physics::location::Location,
Expand Down Expand Up @@ -158,6 +159,7 @@ fn done_saving(
&EntityId,
Option<&LoadingDistance>,
Option<&SaveFileIdentifier>,
Option<&Player>,
),
With<NeedsSaved>,
>,
Expand All @@ -179,7 +181,7 @@ fn done_saving(
}
}

for (entity, name, sd, entity_id, loading_distance, mut save_file_identifier) in q_needs_saved.iter() {
for (entity, name, sd, entity_id, loading_distance, mut save_file_identifier, player) in q_needs_saved.iter() {
commands.entity(entity).remove::<NeedsSaved>().remove::<SerializedData>();

if !sd.should_save() {
Expand Down Expand Up @@ -235,6 +237,10 @@ fn done_saving(
error!("Unable to save {entity:?}\n{e}");
}

if let Some(player) = player {
info!("Saving player data for {player:?} to disk.")
}

if matches!(&save_file_identifier.identifier_type, SaveFileIdentifierType::Base(_, _, _)) {
if let Some(loc) = sd.location {
sectors_cache.insert(loc.sector(), entity_id.clone(), loading_distance.map(|ld| ld.load_distance()));
Expand Down
6 changes: 4 additions & 2 deletions cosmos_server/src/universe/asteroid_spawner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,11 @@ fn generate_asteroids(mut commands: Commands, q_players: Query<&Location, With<P
pub(super) fn register(app: &mut App) {
app.add_systems(
Update,
(spawn_asteroids.in_set(SystemGenerationSet::Asteroid), generate_asteroids)
(
spawn_asteroids.in_set(SystemGenerationSet::Asteroid),
generate_asteroids.in_set(NetworkingSystemsSet::Between),
)
.chain()
.in_set(NetworkingSystemsSet::Between)
.run_if(in_state(GameState::Playing)),
)
.insert_resource(CachedSectors::default());
Expand Down
6 changes: 4 additions & 2 deletions cosmos_server/src/universe/planet_spawner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,11 @@ fn spawn_planets(
pub(super) fn register(app: &mut App) {
app.add_systems(
Update,
(spawn_planets.in_set(SystemGenerationSet::Planet), monitor_planets_to_spawn)
(
spawn_planets.in_set(SystemGenerationSet::Planet),
monitor_planets_to_spawn.in_set(NetworkingSystemsSet::Between),
)
.chain()
.in_set(NetworkingSystemsSet::Between)
.run_if(in_state(GameState::Playing)),
)
.insert_resource(CachedSectors::default());
Expand Down
6 changes: 4 additions & 2 deletions cosmos_server/src/universe/star.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,11 @@ fn generate_stars(
pub(super) fn register(app: &mut App) {
app.add_systems(
Update,
(generate_stars.in_set(SystemGenerationSet::Star), load_stars_in_universe)
(
generate_stars.in_set(SystemGenerationSet::Star),
load_stars_in_universe.in_set(NetworkingSystemsSet::Between),
)
.chain()
.in_set(NetworkingSystemsSet::Between)
.run_if(in_state(GameState::Playing)),
)
.add_systems(
Expand Down

0 comments on commit b56c3a0

Please sign in to comment.