aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEightFactorial <29801334+EightFactorial@users.noreply.github.com>2025-03-24 21:30:33 -0700
committerGitHub <noreply@github.com>2025-03-24 23:30:33 -0500
commitb25474ad66d6d95c46d5f7e695b7d84a34f2c582 (patch)
treeb116b3bad74a470be597d17229a943ff192b9b83
parent656162d2186444f70512af7012f87bfbf9da916a (diff)
downloadazalea-drasl-b25474ad66d6d95c46d5f7e695b7d84a34f2c582.tar.xz
Wait for plugins to load before starting the ECS (#212)
* Wait for plugins to load before starting the ECS Also runs `App:finish()` after plugins finish loading. * Forgot to run `App::cleanup()` Oops haha * copy a check from bevy and don't busywait --------- Co-authored-by: mat <git@matdoes.dev>
-rw-r--r--azalea-client/src/client.rs20
1 files changed, 18 insertions, 2 deletions
diff --git a/azalea-client/src/client.rs b/azalea-client/src/client.rs
index 4b57c270..0d36fe56 100644
--- a/azalea-client/src/client.rs
+++ b/azalea-client/src/client.rs
@@ -4,6 +4,7 @@ use std::{
io,
net::SocketAddr,
sync::Arc,
+ thread,
time::{Duration, Instant},
};
@@ -39,7 +40,7 @@ use azalea_protocol::{
resolver,
};
use azalea_world::{Instance, InstanceContainer, InstanceName, PartialInstance};
-use bevy_app::{App, Plugin, PluginGroup, PluginGroupBuilder, Update};
+use bevy_app::{App, Plugin, PluginGroup, PluginGroupBuilder, PluginsState, Update};
use bevy_ecs::{
bundle::Bundle,
component::Component,
@@ -60,7 +61,7 @@ use tokio::{
},
time,
};
-use tracing::{debug, error};
+use tracing::{debug, error, info};
use uuid::Uuid;
use crate::{
@@ -880,6 +881,21 @@ pub fn start_ecs_runner(
run_schedule_receiver: mpsc::Receiver<()>,
run_schedule_sender: mpsc::Sender<()>,
) -> Arc<Mutex<World>> {
+ // this block is based on Bevy's default runner:
+ // https://github.com/bevyengine/bevy/blob/390877cdae7a17095a75c8f9f1b4241fe5047e83/crates/bevy_app/src/schedule_runner.rs#L77-L85
+ if app.plugins_state() != PluginsState::Cleaned {
+ // Wait for plugins to load
+ if app.plugins_state() == PluginsState::Adding {
+ info!("Waiting for plugins to load ...");
+ while app.plugins_state() == PluginsState::Adding {
+ thread::yield_now();
+ }
+ }
+ // Finish adding plugins and cleanup
+ app.finish();
+ app.cleanup();
+ }
+
// all resources should have been added by now so we can take the ecs from the
// app
let ecs = Arc::new(Mutex::new(std::mem::take(app.world_mut())));