increase max speed and step counter digits, show microseconds per step, massive simulation optimisation for large worlds (5-100x faster)

This commit is contained in:
Crispy 2024-12-07 16:19:59 +01:00
parent 140a462add
commit c1094980a6
2 changed files with 27 additions and 14 deletions

View file

@ -1,3 +1,5 @@
use std::hint::unreachable_unchecked;
use raylib::prelude::*;
pub mod board;
@ -13,6 +15,7 @@ use crate::{draw_usize_small, Textures};
pub struct Machine {
board: Board,
marbles: Vec<Pos>,
powered: Vec<Pos>,
input: Vec<u8>,
input_index: usize,
@ -25,6 +28,7 @@ impl Machine {
Self {
board: Board::new_empty(width, width),
marbles: Vec::new(),
powered: Vec::new(),
input,
input_index: 0,
output: Vec::new(),
@ -97,13 +101,13 @@ impl Machine {
pub fn step(&mut self) {
self.steps += 1;
// reset wires
for y in 0..self.board.height() {
for x in 0..self.board.width() {
if let Some(Tile::Powerable(_, state)) = self.board.get_mut((x, y).into()) {
*state = false;
}
}
for &p in &self.powered {
let Some(Tile::Powerable(_, state)) = self.board.get_mut(p) else {
unsafe { unreachable_unchecked() }
};
*state = false;
}
self.powered.clear();
if self.marbles.is_empty() {
return;
@ -302,6 +306,7 @@ impl Machine {
}
let was_powered = *state;
*state = true;
self.powered.push(pos);
match tile {
PTile::Wire(wiretype) => {
if was_powered {