@@ -17,17 +17,12 @@ pub struct Map {
1717 pub height : i32 ,
1818 pub revealed_tiles : Vec < bool > ,
1919 pub visible_tiles : Vec < bool > ,
20- pub blocked : Vec < bool > ,
2120 pub depth : i32 ,
2221 pub bloodstains : HashSet < usize > ,
2322 pub view_blocked : HashSet < usize > ,
2423 pub name : String ,
2524 pub outdoors : bool ,
2625 pub light : Vec < rltk:: RGB > ,
27-
28- #[ serde( skip_serializing) ]
29- #[ serde( skip_deserializing) ]
30- pub tile_content : Vec < Vec < Entity > >
3126}
3227
3328impl Map {
@@ -38,32 +33,30 @@ impl Map {
3833 fn is_exit_valid ( & self , x : i32 , y : i32 ) -> bool {
3934 if x < 1 || x > self . width -1 || y < 1 || y > self . height -1 { return false ; }
4035 let idx = self . xy_idx ( x, y) ;
41- !self . blocked [ idx]
36+ !crate :: spatial :: is_blocked ( idx)
4237 }
4338
4439 pub fn populate_blocked ( & mut self ) {
45- for ( i, tile) in self . tiles . iter_mut ( ) . enumerate ( ) {
46- self . blocked [ i] = !tile_walkable ( * tile) ;
47- }
40+ crate :: spatial:: populate_blocked_from_map ( self ) ;
4841 }
4942
5043 pub fn populate_blocked_multi ( & mut self , width : i32 , height : i32 ) {
5144 self . populate_blocked ( ) ;
5245 for y in 1 .. self . height -1 {
5346 for x in 1 .. self . width - 1 {
5447 let idx = self . xy_idx ( x, y) ;
55- if !self . blocked [ idx] {
48+ if !crate :: spatial :: is_blocked ( idx) {
5649 for cy in 0 ..height {
5750 for cx in 0 ..width {
5851 let tx = x + cx;
5952 let ty = y + cy;
6053 if tx < self . width -1 && ty < self . height -1 {
6154 let tidx = self . xy_idx ( tx, ty) ;
62- if self . blocked [ tidx] {
63- self . blocked [ idx] = true ;
55+ if crate :: spatial :: is_blocked ( tidx) {
56+ crate :: spatial :: set_blocked ( idx, true ) ;
6457 }
6558 } else {
66- self . blocked [ idx] = true ;
59+ crate :: spatial :: set_blocked ( idx, true ) ;
6760 }
6861 }
6962 }
@@ -73,22 +66,19 @@ impl Map {
7366 }
7467
7568 pub fn clear_content_index ( & mut self ) {
76- for content in self . tile_content . iter_mut ( ) {
77- content. clear ( ) ;
78- }
69+ crate :: spatial:: clear ( ) ;
7970 }
8071
8172 /// Generates an empty map, consisting entirely of solid walls
8273 pub fn new < S : ToString > ( new_depth : i32 , width : i32 , height : i32 , name : S ) -> Map {
8374 let map_tile_count = ( width* height) as usize ;
75+ crate :: spatial:: set_size ( map_tile_count) ;
8476 Map {
8577 tiles : vec ! [ TileType :: Wall ; map_tile_count] ,
8678 width,
8779 height,
8880 revealed_tiles : vec ! [ false ; map_tile_count] ,
8981 visible_tiles : vec ! [ false ; map_tile_count] ,
90- blocked : vec ! [ false ; map_tile_count] ,
91- tile_content : vec ! [ Vec :: new( ) ; map_tile_count] ,
9282 depth : new_depth,
9383 bloodstains : HashSet :: new ( ) ,
9484 view_blocked : HashSet :: new ( ) ,
0 commit comments