Skip to content

Commit

Permalink
Add tickn method to redpiler JITBackend trait
Browse files Browse the repository at this point in the history
  • Loading branch information
BramOtte authored and StackDoubleFlow committed Jan 7, 2025
1 parent 12fc9c8 commit c98bc6d
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 6 deletions.
5 changes: 2 additions & 3 deletions crates/core/src/plot/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,9 +321,8 @@ impl Plot {
return false;
};
let start_time = Instant::now();
for _ in 0..ticks {
self.tick();
}
self.tickn(ticks as u64);

if self.redpiler.is_active() {
self.redpiler.flush(&mut self.world);
}
Expand Down
16 changes: 13 additions & 3 deletions crates/core/src/plot/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,18 @@ impl World for PlotWorld {
}

impl Plot {
fn tickn(&mut self, ticks: u64) {
if self.redpiler.is_active() {
self.timings.tickn(ticks);
self.redpiler.tickn(ticks);
return;
}

for _ in 0..ticks {
self.tick();
}
}

fn tick(&mut self) {
self.timings.tick();
if self.redpiler.is_active() {
Expand Down Expand Up @@ -1012,9 +1024,7 @@ impl Plot {
let batch_size = batch_size.min(50_000) as u32;
let mut ticks_completed = batch_size;
if self.redpiler.is_active() {
for _ in 0..batch_size {
self.tick();
}
self.tickn(batch_size as u64);
self.redpiler.flush(&mut self.world);
} else {
for i in 0..batch_size {
Expand Down
4 changes: 4 additions & 0 deletions crates/core/src/plot/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ impl TimingsMonitor {
pub fn tick(&self) {
self.data.ticks_passed.fetch_add(1, Ordering::Relaxed);
}

pub fn tickn(&self, ticks: u64) {
self.data.ticks_passed.fetch_add(ticks, Ordering::Relaxed);
}

pub fn is_running_behind(&self) -> bool {
self.data.too_slow.load(Ordering::Relaxed)
Expand Down
7 changes: 7 additions & 0 deletions crates/redpiler/src/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ pub trait JITBackend {
monitor: Arc<TaskMonitor>,
);
fn tick(&mut self);

fn tickn(&mut self, ticks: u64) {
for _ in 0..ticks {
self.tick();
}
}

fn on_use_block(&mut self, pos: BlockPos);
fn set_pressure_plate(&mut self, pos: BlockPos, powered: bool);
fn flush<W: World>(&mut self, world: &mut W, io_only: bool);
Expand Down
4 changes: 4 additions & 0 deletions crates/redpiler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,10 @@ impl Compiler {
pub fn tick(&mut self) {
self.backend().tick();
}

pub fn tickn(&mut self, ticks: u64) {
self.backend().tickn(ticks);
}

pub fn on_use_block(&mut self, pos: BlockPos) {
self.backend().on_use_block(pos);
Expand Down

0 comments on commit c98bc6d

Please sign in to comment.