Skip to content

Commit

Permalink
refactor: use RoomCoordinate indexing for LocalRoomTerrain
Browse files Browse the repository at this point in the history
Removes unsafe block that directly converted to linear coordinates.
  • Loading branch information
khoover committed Oct 9, 2024
1 parent e7cad72 commit 3271f97
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/local/terrain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{
objects::RoomTerrain,
};

use super::{xy_to_terrain_index, RoomXY};
use super::RoomXY;

#[derive(Debug, Clone)]
pub struct LocalRoomTerrain {
Expand All @@ -20,8 +20,7 @@ pub struct LocalRoomTerrain {
impl LocalRoomTerrain {
/// Gets the terrain at the specified position in this room.
pub fn get_xy(&self, xy: RoomXY) -> Terrain {
// SAFETY: RoomXY is always a valid coordinate.
let byte = unsafe { self.bits.get_unchecked(xy_to_terrain_index(xy)) };
let byte = self.bits[xy.y][xy.x];
// not using Terrain::from_u8() because `0b11` value, wall+swamp, happens
// in commonly used server environments (notably the private server default
// map), and is special-cased in the engine code; we special-case it here
Expand Down

0 comments on commit 3271f97

Please sign in to comment.