From 7ce2e689c48f8d808c42eb7af1d1e935ec1b6195 Mon Sep 17 00:00:00 2001 From: CrispyPin Date: Sat, 14 Dec 2024 17:50:09 +0100 Subject: [PATCH 1/3] redraw io tile --- assets/tiles/io_tile_off.png | Bin 187 -> 292 bytes assets/tiles/io_tile_on.png | Bin 189 -> 342 bytes 2 files changed, 0 insertions(+), 0 deletions(-) diff --git a/assets/tiles/io_tile_off.png b/assets/tiles/io_tile_off.png index afe0ffd25f29807390c408361be53351c04a6991..88872bd385c1535b9d1b2ac82c05df8f229ab005 100644 GIT binary patch delta 276 zcmV+v0qg#|0i*(u8Gi-<001BJ|6u?C0P9IaK~y-6#gefK0x=AR{}bI@Iyt!n-{8;( z5xP1aIJw^LQt$!XT?@WRz=v=z4o(hnkd*e?LvS%r2x1QChmlV1Q`*TsBV zYp~Wzt?s>VhP7BoMa=wlat5&0N-7E=Q~}1A2x4Y<@0&)&V}GI)>YOVth)9evqX$57 zoO1#|h)5bDlCkN-dToO$AcTO~_MFvT*L?=+`yNDu;tihb0{}qgi(=Yw^C&j}%3rvz zc3G3cmbVjt{1>Lc#~_(`_)<&)fVOR8uBIxSr5i;Sb0${GVRN_f1gDyv+5ek=*oA+F z+141|y!r6FvYFoXQ@nYswY@H3v%a#KvEvzV3&2izDY<-!ihlvFkK+T>*6ziV-x~~T zi~EOB$bI_Usu=(g@r%JZU4Rf&mL<+PV?@L+zD^(+0sIPyI`C6`e>tyD$w&cRt2|U^ zd{kK*5V~kWx*cqR#6apmM0}At{sOr>dTl#^`W1@QX|cbYDnRXaVA^P!>u0000 Date: Sat, 14 Dec 2024 23:42:17 +0100 Subject: [PATCH 2/3] prevent marbles from bouncing during the same step that they are created --- src/marble_engine.rs | 46 ++++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/src/marble_engine.rs b/src/marble_engine.rs index f99ddd2..422301e 100644 --- a/src/marble_engine.rs +++ b/src/marble_engine.rs @@ -179,25 +179,6 @@ impl Machine { }; } - for &(pos, _val, _dir) in &new_marbles { - let Some(Tile::Open(OpenTile::Blank, claim)) = self.board.get_mut(pos) else { - unreachable!() - }; - *claim = match claim { - Claim::Free => Claim::Claimed, - Claim::Claimed | Claim::Blocked => Claim::Blocked, - _ => unreachable!(), - } - } - // new marbles are past old_marbles index, so will not move this step - for (pos, value, dir) in new_marbles { - let Some(Tile::Open(OpenTile::Blank, Claim::Claimed)) = self.board.get_mut(pos) else { - continue; - }; - self.board.set(pos, Tile::Marble { value, dir }); - self.marbles.push(pos); - } - // old wires have to be reset after machine processing, // so they can figure out which directions they are powered from for &p in &self.powered { @@ -220,7 +201,7 @@ impl Machine { Multiple, } - // find all direct bounces + // #### find all direct bounces #### let mut will_reverse_direction = vec![false; self.marbles.len()]; // todo store in tile to remove search through self.marbles let mut influenced_direction = vec![DirInfluence::None; self.marbles.len()]; @@ -261,7 +242,7 @@ impl Machine { _ => (), } } - // apply all direct bounces + // #### apply all direct bounces #### for (i, &pos) in self.marbles.iter().enumerate() { let Some(Tile::Marble { value: _, dir }) = self.board.get_mut(pos) else { unreachable!() @@ -273,6 +254,29 @@ impl Machine { } } + // #### new marbles #### + // prepare creating the new marbles + for &(pos, _val, _dir) in &new_marbles { + let Some(Tile::Open(OpenTile::Blank, claim)) = self.board.get_mut(pos) else { + unreachable!() + }; + *claim = match claim { + Claim::Free => Claim::Claimed, + Claim::Claimed | Claim::Blocked => Claim::Blocked, + _ => unreachable!(), + } + } + // create new marbles + // new marbles are past old_marbles index, so will not move this step + for (pos, value, dir) in new_marbles { + let Some(Tile::Open(OpenTile::Blank, Claim::Claimed)) = self.board.get_mut(pos) else { + continue; + }; + self.board.set(pos, Tile::Marble { value, dir }); + self.marbles.push(pos); + } + + // #### movement #### let mut claim_positions = Vec::new(); // mark claims to figure out what spaces can be moved to for &pos in &self.marbles[..old_marbles] { From 1061ae6ce0379823c0705b519014f72429b9a864 Mon Sep 17 00:00:00 2001 From: CrispyPin Date: Sat, 14 Dec 2024 23:51:48 +0100 Subject: [PATCH 3/3] replace raylibs grid rendering and decrease grid contrast --- src/editor.rs | 25 +++++++++++-------------- src/theme.rs | 3 +++ 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/editor.rs b/src/editor.rs index e1877b3..8fbbd59 100644 --- a/src/editor.rs +++ b/src/editor.rs @@ -444,23 +444,20 @@ impl Editor { } pub fn draw(&mut self, d: &mut RaylibDrawHandle, textures: &Textures) { - d.clear_background(gray(48)); + d.clear_background(BG_WORLD); - if self.draw_overlay && self.zoom >= 1. { - let tile_size = (TILE_TEXTURE_SIZE * self.zoom) as f32; + if self.draw_overlay && self.zoom >= 0.5 { + let tile_size = TILE_TEXTURE_SIZE * self.zoom; let grid_spill_x = (self.view_offset.x).rem(tile_size) - tile_size; let grid_spill_y = (self.view_offset.y).rem(tile_size) - tile_size; - d.gui_grid( - Rectangle::new( - grid_spill_x, - grid_spill_y, - d.get_screen_width() as f32 * 2., - d.get_screen_height() as f32 * 2., - ), - None, - tile_size, - 1, - ); + for y in 0..=(d.get_screen_height() / tile_size as i32) { + let y = y * tile_size as i32 + grid_spill_y as i32; + d.draw_line(0, y, d.get_screen_width(), y, FG_GRID); + } + for x in 0..=(d.get_screen_width() / tile_size as i32) { + let x = x * tile_size as i32 + grid_spill_x as i32; + d.draw_line(x, 0, x, d.get_screen_height(), FG_GRID); + } } self.draw_board(d, textures); diff --git a/src/theme.rs b/src/theme.rs index 6d9cdc8..fd2875c 100644 --- a/src/theme.rs +++ b/src/theme.rs @@ -1,5 +1,8 @@ use raylib::prelude::*; +pub const BG_WORLD: Color = gray(48); +pub const FG_GRID: Color = gray(64); + pub const BG_DARK: Color = gray(32); pub const BG_MEDIUM: Color = gray(48); pub const BG_LIGHT: Color = gray(64);