Skip to content

Commit

Permalink
Update players during redpiler compile
Browse files Browse the repository at this point in the history
  • Loading branch information
StackDoubleFlow committed Jan 4, 2024
1 parent e2c1176 commit ac1b366
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions crates/core/src/plot/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -518,16 +518,41 @@ impl Plot {

fn start_redpiler(&mut self, options: CompilerOptions) {
debug!("Starting redpiler");
let ticks = self.world.to_be_ticked.drain(..).collect();
self.scoreboard
.set_redpiler_state(&self.players, RedpilerState::Compiling);
self.scoreboard
.set_redpiler_options(&self.players, &options);

let bounds = self.world.get_corners();
// TODO: move redpiler compile to new thread and use monitor
// TODO: use monitor
let monitor = Default::default();
self.redpiler
.compile(&mut self.world, bounds, options, ticks, monitor);
let ticks = self.world.to_be_ticked.drain(..).collect();

let mut players_need_updates = HashSet::new();
thread::scope(|s| {
let handle = s.spawn(|| {
self.redpiler
.compile(&mut self.world, bounds, options, ticks, monitor)
});
while !handle.is_finished() {
// We'll update the players so that they don't time out.
for player_idx in 0..self.players.len() {
if self.players[player_idx].update() {
// Unforunately we can't update a players view position
// since we don't have access to the world, but we can
// save the players that need updating for later.
players_need_updates.insert(player_idx);
}
}
thread::sleep(Duration::from_millis(20));
}
});

// Now that we have ownership of the world again, we can update player view positions
for player_idx in players_need_updates {
self.update_view_pos_for_player(player_idx, false);
}

self.scoreboard
.set_redpiler_state(&self.players, RedpilerState::Running);

Expand Down

0 comments on commit ac1b366

Please sign in to comment.