diff options
| -rw-r--r-- | pixel-client/src/game.rs | 6 | ||||
| -rw-r--r-- | pixel-client/src/main.rs | 8 | ||||
| -rw-r--r-- | pixel-client/src/menu.rs | 10 | ||||
| -rw-r--r-- | pixel-client/src/render/mod.rs | 2 | ||||
| -rw-r--r-- | pixel-client/src/render/sprite.rs | 2 | ||||
| -rw-r--r-- | pixel-client/src/tilemap.rs | 2 | ||||
| -rw-r--r-- | pixel-client/tools/src/bin/bunnymark.rs | 2 | ||||
| -rw-r--r-- | server/protocol/src/movement.rs | 9 | ||||
| -rw-r--r-- | server/replaytool/src/main.rs | 2 | ||||
| -rw-r--r-- | server/src/entity/conveyor.rs | 6 | ||||
| -rw-r--r-- | server/src/entity/customers/demands.rs | 8 | ||||
| -rw-r--r-- | server/src/entity/customers/mod.rs | 4 | ||||
| -rw-r--r-- | server/src/entity/customers/pathfinding.rs | 6 | ||||
| -rw-r--r-- | server/src/entity/mod.rs | 2 | ||||
| -rw-r--r-- | server/src/game.rs | 16 | ||||
| -rw-r--r-- | server/src/interaction.rs | 30 | 
16 files changed, 54 insertions, 61 deletions
diff --git a/pixel-client/src/game.rs b/pixel-client/src/game.rs index 57f419e2..aefafd6e 100644 --- a/pixel-client/src/game.rs +++ b/pixel-client/src/game.rs @@ -169,13 +169,13 @@ impl Game {              self.camera_center.exp_to(player.movement.position, dt * 5.);          } -        for (_pid, player) in &mut self.players { +        for player in self.players.values_mut() {              if let Some(item) = &mut player.item {                  item.parent_position = player.movement.position;                  item.tick(1., dt);              }          } -        for (_pos, tile) in &mut self.tiles { +        for tile in self.tiles.values_mut() {              if let Some(item) = &mut tile.item {                  item.tick(1., dt)              } @@ -359,8 +359,6 @@ impl Game {          self.tilemap.draw(ctx); -         -          if let Some(me) = self.players.get(&self.my_id) {              let t = me.movement.get_interact_target();              ctx.draw_world( diff --git a/pixel-client/src/main.rs b/pixel-client/src/main.rs index 7501aba2..65de7b15 100644 --- a/pixel-client/src/main.rs +++ b/pixel-client/src/main.rs @@ -52,7 +52,7 @@ pub enum Action {  }  enum State { -    Ingame(Game), +    Ingame(Box<Game>),      Menu(Menu),  } @@ -89,10 +89,10 @@ fn main() {      let mut state = match args.action.unwrap_or_default() {          Action::Menu => State::Menu(Menu::new()), -        Action::Join { server_address } => State::Ingame(Game::new( +        Action::Join { server_address } => State::Ingame(Box::new(Game::new(              Network::connect(&server_address).unwrap(), -            &renderer.atlas_layout(), -        )), +            renderer.atlas_layout(), +        ))),      };      let mut events = sdl_context.event_pump().unwrap(); diff --git a/pixel-client/src/menu.rs b/pixel-client/src/menu.rs index 0a05e84c..a3242edb 100644 --- a/pixel-client/src/menu.rs +++ b/pixel-client/src/menu.rs @@ -3,10 +3,16 @@ use sdl2::keyboard::KeyboardState;  pub struct Menu {} +impl Default for Menu { +    fn default() -> Self { +        Self::new() +    } +} +  impl Menu {      pub fn new() -> Self {          Self {}      } -    pub fn tick(&mut self, dt: f32, keyboard: &KeyboardState, layout: &AtlasLayout) {} -    pub fn draw(&self, ctx: &mut SpriteRenderer) {} +    pub fn tick(&mut self, _dt: f32, _keyboard: &KeyboardState, _layout: &AtlasLayout) {} +    pub fn draw(&self, _ctx: &mut SpriteRenderer) {}  } diff --git a/pixel-client/src/render/mod.rs b/pixel-client/src/render/mod.rs index f18d96ad..4eea439a 100644 --- a/pixel-client/src/render/mod.rs +++ b/pixel-client/src/render/mod.rs @@ -71,7 +71,7 @@ impl<'a> SpriteRenderer<'a> {              }              for (x, char) in line.chars().enumerate() {                  let color = palette.get(&char).unwrap(); -                texels[(y * 1024 + x) * 4 + 0] = color[3]; +                texels[(y * 1024 + x) * 4] = color[3];                  texels[(y * 1024 + x) * 4 + 1] = color[2];                  texels[(y * 1024 + x) * 4 + 2] = color[1];                  texels[(y * 1024 + x) * 4 + 3] = color[0]; diff --git a/pixel-client/src/render/sprite.rs b/pixel-client/src/render/sprite.rs index 4210b58d..084e277e 100644 --- a/pixel-client/src/render/sprite.rs +++ b/pixel-client/src/render/sprite.rs @@ -92,7 +92,7 @@ impl Ord for SpriteDraw {  }  impl PartialOrd for SpriteDraw {      fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> { -        Some(self.cmp(&other)) +        Some(self.cmp(other))      }  }  impl Eq for SpriteDraw {} diff --git a/pixel-client/src/tilemap.rs b/pixel-client/src/tilemap.rs index 768f79ba..05f33b4b 100644 --- a/pixel-client/src/tilemap.rs +++ b/pixel-client/src/tilemap.rs @@ -99,7 +99,7 @@ impl Tilemap {          if let Some(gid) = self.connect_group_by_tile[tile.0] {              let cgroup = &self.connect_members_by_group[gid];              idx |= 0b0100 * (cgroup.contains(&neighbors[0])) as usize; -            idx |= 0b0001 * (cgroup.contains(&neighbors[1])) as usize; +            idx |= (cgroup.contains(&neighbors[1])) as usize;              idx |= 0b1000 * (cgroup.contains(&neighbors[2])) as usize;              idx |= 0b0010 * (cgroup.contains(&neighbors[3])) as usize;          } diff --git a/pixel-client/tools/src/bin/bunnymark.rs b/pixel-client/tools/src/bin/bunnymark.rs index f59fecff..b9e4b0ae 100644 --- a/pixel-client/tools/src/bin/bunnymark.rs +++ b/pixel-client/tools/src/bin/bunnymark.rs @@ -28,7 +28,7 @@ const WIDTH: i32 = 1920;  const HEIGHT: i32 = 1080;  pub fn main() { -    let amount = std::env::args().skip(1).next().unwrap().parse().unwrap(); +    let amount = std::env::args().nth(1).unwrap().parse().unwrap();      let sdl_context = sdl2::init().unwrap();      let video_subsystem = sdl_context.video().unwrap(); diff --git a/server/protocol/src/movement.rs b/server/protocol/src/movement.rs index ab4eb818..76a243e2 100644 --- a/server/protocol/src/movement.rs +++ b/server/protocol/src/movement.rs @@ -67,11 +67,11 @@ impl MovementBase {          } else {              dt / BOOST_RESTORE          }; -        self.stamina = self.stamina.max(0.).min(1.); +        self.stamina = self.stamina.clamp(0., 1.);          let speed = PLAYER_SPEED * if self.boosting { BOOST_FACTOR } else { 1. };          self.velocity += direction * dt * speed;          self.position += self.velocity * dt; -        self.velocity = self.velocity * (-dt * PLAYER_FRICTION).exp(); +        self.velocity *= (-dt * PLAYER_FRICTION).exp();          collide_player_tiles(self, map);          PacketS::Movement { @@ -84,7 +84,10 @@ impl MovementBase {      pub fn collide(&mut self, other: &mut Self, dt: f32) {          let diff = self.position - other.position;          let d = diff.length(); -        if d < 0.01 || d > PLAYER_SIZE * 2. { +        if d < 0.01 { +            return; +        } +        if d > PLAYER_SIZE * 2. {              return;          }          let norm = diff.normalize(); diff --git a/server/replaytool/src/main.rs b/server/replaytool/src/main.rs index 40466b82..a6ad70fd 100644 --- a/server/replaytool/src/main.rs +++ b/server/replaytool/src/main.rs @@ -193,7 +193,7 @@ pub async fn do_record(output: &Path, url: &str) -> anyhow::Result<()> {                          "{}\n",                          serde_json::to_string(&Event {                              ts: start.elapsed().as_secs_f64(), -                            packet: packet +                            packet                          })                          .unwrap()                      ) diff --git a/server/src/entity/conveyor.rs b/server/src/entity/conveyor.rs index d1594ce7..6067c679 100644 --- a/server/src/entity/conveyor.rs +++ b/server/src/entity/conveyor.rs @@ -44,11 +44,7 @@ impl EntityT for Conveyor {                      .get(t)                      .ok_or(anyhow!("conveyor filter missing"))?;                  filter_tile.item.as_ref().map(|e| e.kind) -            } else if let Some(i) = &self.filter_item { -                Some(*i) -            } else { -                None -            }; +            } else { self.filter_item.as_ref().map(|i| *i) };              if let Some(filter) = filter {                  if from_item.kind != filter { diff --git a/server/src/entity/customers/demands.rs b/server/src/entity/customers/demands.rs index fa7e0dbf..4f15f86f 100644 --- a/server/src/entity/customers/demands.rs +++ b/server/src/entity/customers/demands.rs @@ -41,7 +41,7 @@ pub fn generate_demands(          let prod_count = producable.len();          for r in &recipes { -            let output_count = r.outputs().iter().filter(|o| !items.contains(&o)).count(); +            let output_count = r.outputs().iter().filter(|o| !items.contains(o)).count();              let Some(ingred_cost) = r                  .inputs()                  .iter() @@ -79,16 +79,12 @@ pub fn generate_demands(      raw_demands          .iter()          .filter_map(|(i, o, d)| { -            if let Some(cost) = producable.get(i) { -                Some(Demand { +            producable.get(i).map(|cost| Demand {                      from: *i,                      to: *o,                      duration: *d,                      points: *cost as i64,                  }) -            } else { -                None -            }          })          .collect()  } diff --git a/server/src/entity/customers/mod.rs b/server/src/entity/customers/mod.rs index 7f0b0c22..806a25f9 100644 --- a/server/src/entity/customers/mod.rs +++ b/server/src/entity/customers/mod.rs @@ -150,7 +150,7 @@ impl EntityT for Customers {                              game.data.customer_spawn.as_ivec2(),                          )                          .expect("no path to exit"); -                        *self.chairs.get_mut(&chair).unwrap() = true; +                        *self.chairs.get_mut(chair).unwrap() = true;                          game.demands_failed += 1;                          game.points -= 1;                          game.score_changed = true; @@ -231,7 +231,7 @@ impl EntityT for Customers {                              game.data.customer_spawn.as_ivec2(),                          )                          .ok_or(anyhow!("no path to exit"))?; -                        *self.chairs.get_mut(&chair).unwrap() = true; +                        *self.chairs.get_mut(chair).unwrap() = true;                          game.demands_completed += 1;                          game.points += demand.points;                          game.score_changed = true; diff --git a/server/src/entity/customers/pathfinding.rs b/server/src/entity/customers/pathfinding.rs index 97bd8328..87ccf391 100644 --- a/server/src/entity/customers/pathfinding.rs +++ b/server/src/entity/customers/pathfinding.rs @@ -47,7 +47,7 @@ pub fn find_path(walkable: &HashSet<IVec2>, from: IVec2, to: IVec2) -> Option<Pa      struct Open(i32, IVec2, IVec2, i32);      impl PartialOrd for Open {          fn partial_cmp(&self, other: &Self) -> Option<Ordering> { -            self.0.partial_cmp(&other.0) +            Some(self.0.cmp(&other.0))          }      }      impl Ord for Open { @@ -61,9 +61,7 @@ pub fn find_path(walkable: &HashSet<IVec2>, from: IVec2, to: IVec2) -> Option<Pa      open.push(Open(1, from, from, 0));      loop { -        let Some(Open(_, pos, f, distance)) = open.pop() else { -            return None; -        }; +        let Open(_, pos, f, distance) = open.pop()?;          if visited.contains_key(&pos) {              continue;          } diff --git a/server/src/entity/mod.rs b/server/src/entity/mod.rs index beee9309..c471a6d4 100644 --- a/server/src/entity/mod.rs +++ b/server/src/entity/mod.rs @@ -101,7 +101,7 @@ pub fn construct_entity(              })          }          EntityDecl::Customers {} => { -            let demands = generate_demands(tiles_used, items_used, &raw_demands, &recipes); +            let demands = generate_demands(tiles_used, items_used, raw_demands, recipes);              let chair = reg.register_tile("chair".to_string());              let chairs = initial_map                  .iter() diff --git a/server/src/game.rs b/server/src/game.rs index 370c2e8f..f5670277 100644 --- a/server/src/game.rs +++ b/server/src/game.rs @@ -83,6 +83,12 @@ pub struct Game {      pub demands_completed: usize,  } +impl Default for Game { +    fn default() -> Self { +        Self::new() +    } +} +  impl Game {      pub fn new() -> Self {          Self { @@ -239,7 +245,7 @@ impl Game {                      self.tiles.get(&(tile + IVec2::Y)).map(|e| e.kind),                      self.tiles.get(&(tile + IVec2::X)).map(|e| e.kind),                  ], -                kind: Some(tdata.kind.clone()), +                kind: Some(tdata.kind),              });              if let Some(item) = &tdata.item {                  out.push(PacketC::SetItem { @@ -574,13 +580,11 @@ impl Game {              }          } -        return self.end.map(|t| t < Instant::now()).unwrap_or_default(); +        self.end.map(|t| t < Instant::now()).unwrap_or_default()      }      pub fn count_chefs(&self) -> usize { -        self.players -            .iter() -            .map(|(_, p)| if p.character >= 0 { 1 } else { 0 }) +        self.players.values().map(|p| if p.character >= 0 { 1 } else { 0 })              .sum()      }  } @@ -606,7 +610,7 @@ pub fn interact_effect(      let this_had_item = this.is_some();      let other_had_item = other.is_some(); -    if let Some(effect) = interact(&data, edge, this_tile_kind, this, other, points, automated) { +    if let Some(effect) = interact(data, edge, this_tile_kind, this, other, points, automated) {          match effect {              InteractEffect::Put => {                  info!("put {this_loc} <- {other_loc}"); diff --git a/server/src/interaction.rs b/server/src/interaction.rs index b3f6af8c..2f6c940a 100644 --- a/server/src/interaction.rs +++ b/server/src/interaction.rs @@ -80,20 +80,14 @@ impl Recipe {          match self {              Recipe::Passive { input, .. } => vec![*input],              Recipe::Active { input, .. } => vec![*input], -            Recipe::Instant { inputs, .. } => { -                inputs.into_iter().flat_map(|e| e.to_owned()).collect() -            } +            Recipe::Instant { inputs, .. } => inputs.iter().flat_map(|e| e.to_owned()).collect(),          }      }      pub fn outputs(&self) -> Vec<ItemIndex> {          match self { -            Recipe::Passive { output, .. } => output.to_owned().into_iter().collect(), -            Recipe::Active { outputs, .. } => { -                outputs.into_iter().flat_map(|e| e.to_owned()).collect() -            } -            Recipe::Instant { outputs, .. } => { -                outputs.into_iter().flat_map(|e| e.to_owned()).collect() -            } +            Recipe::Passive { output, .. } => output.iter().copied().collect(), +            Recipe::Active { outputs, .. } => outputs.iter().flat_map(|e| e.to_owned()).collect(), +            Recipe::Instant { outputs, .. } => outputs.iter().flat_map(|e| e.to_owned()).collect(),          }      }      pub fn supports_tile(&self, tile: Option<TileIndex>) -> bool { @@ -161,15 +155,13 @@ pub fn interact(                  Recipe::Active { input, .. } => {                      if other.is_none() {                          if let Some(item) = this { -                            if item.kind == *input { -                                if item.active.is_none() { -                                    info!("start active recipe {ri:?}"); -                                    item.active = Some(Involvement { -                                        recipe: ri, -                                        working: 1, -                                        progress: 0., -                                    }); -                                } +                            if item.kind == *input && item.active.is_none() { +                                info!("start active recipe {ri:?}"); +                                item.active = Some(Involvement { +                                    recipe: ri, +                                    working: 1, +                                    progress: 0., +                                });                              }                          }                      }  |