Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tickn method to redpiler JITBackend trait #170

Merged
merged 2 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -130,6 +130,10 @@ impl TimingsMonitor {
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 @@ -204,6 +204,10 @@ impl Compiler {
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
Loading