From 3271f97470734f0311154a611bc04a5736c7eac4 Mon Sep 17 00:00:00 2001 From: Ken Hoover Date: Tue, 8 Oct 2024 22:09:39 -0700 Subject: [PATCH] refactor: use `RoomCoordinate` indexing for `LocalRoomTerrain` Removes unsafe block that directly converted to linear coordinates. --- src/local/terrain.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/local/terrain.rs b/src/local/terrain.rs index 8b8b8e14..9f5b918d 100644 --- a/src/local/terrain.rs +++ b/src/local/terrain.rs @@ -7,7 +7,7 @@ use crate::{ objects::RoomTerrain, }; -use super::{xy_to_terrain_index, RoomXY}; +use super::RoomXY; #[derive(Debug, Clone)] pub struct LocalRoomTerrain { @@ -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