1
2
Fork 0
mirror of https://github.com/mat-1/azalea.git synced 2025-08-02 06:16:04 +00:00

make sure Startup system runs before any bots join

This commit is contained in:
mat 2023-12-02 16:06:42 -06:00
parent 34a4027010
commit f052882123
3 changed files with 24 additions and 3 deletions

View file

@ -54,7 +54,9 @@ use azalea_protocol::{
resolver, ServerAddress,
};
use azalea_world::{Instance, InstanceContainer, InstanceName, PartialInstance};
use bevy_app::{App, FixedUpdate, Plugin, PluginGroup, PluginGroupBuilder, Update};
use bevy_app::{
App, FixedUpdate, Plugin, PluginGroup, PluginGroupBuilder, PreStartup, Startup, Update,
};
use bevy_ecs::{
bundle::Bundle,
component::Component,
@ -653,7 +655,7 @@ impl Plugin for AzaleaPlugin {
/// [`DefaultPlugins`].
#[doc(hidden)]
pub fn start_ecs_runner(
app: App,
mut app: App,
run_schedule_receiver: mpsc::UnboundedReceiver<()>,
run_schedule_sender: mpsc::UnboundedSender<()>,
) -> Arc<Mutex<World>> {

View file

@ -193,9 +193,18 @@ where
// An event that causes the schedule to run. This is only used internally.
let (run_schedule_sender, run_schedule_receiver) = mpsc::unbounded_channel();
let main_schedule_label = self.app.main_schedule_label;
let ecs_lock =
start_ecs_runner(self.app, run_schedule_receiver, run_schedule_sender.clone());
// run the main schedule so the startup systems run
{
let mut ecs = ecs_lock.lock();
ecs.run_schedule(main_schedule_label);
ecs.clear_trackers();
}
let (bot, mut rx) = Client::start_client(
ecs_lock,
&account,

View file

@ -320,6 +320,9 @@ where
let (swarm_tx, mut swarm_rx) = mpsc::unbounded_channel();
let (run_schedule_sender, run_schedule_receiver) = mpsc::unbounded_channel();
let main_schedule_label = self.app.main_schedule_label;
let ecs_lock =
start_ecs_runner(self.app, run_schedule_receiver, run_schedule_sender.clone());
@ -337,7 +340,14 @@ where
run_schedule_sender,
};
ecs_lock.lock().insert_resource(swarm.clone());
// run the main schedule so the startup systems run
{
let mut ecs = ecs_lock.lock();
ecs.insert_resource(swarm.clone());
ecs.run_schedule(main_schedule_label);
ecs.clear_trackers();
}
// SwarmBuilder (self) isn't Send so we have to take all the things we need out
// of it