@@ -16,17 +16,12 @@ pub struct Map {
1616 pub height : i32 ,
1717 pub revealed_tiles : Vec < bool > ,
1818 pub visible_tiles : Vec < bool > ,
19- pub blocked : Vec < bool > ,
2019 pub depth : i32 ,
2120 pub bloodstains : HashSet < usize > ,
2221 pub view_blocked : HashSet < usize > ,
2322 pub name : String ,
2423 pub outdoors : bool ,
2524 pub light : Vec < rltk:: RGB > ,
26-
27- #[ serde( skip_serializing) ]
28- #[ serde( skip_deserializing) ]
29- pub tile_content : Vec < Vec < Entity > >
3025}
3126
3227impl Map {
@@ -37,32 +32,30 @@ impl Map {
3732 fn is_exit_valid ( & self , x : i32 , y : i32 ) -> bool {
3833 if x < 1 || x > self . width -1 || y < 1 || y > self . height -1 { return false ; }
3934 let idx = self . xy_idx ( x, y) ;
40- !self . blocked [ idx]
35+ !crate :: spatial :: is_blocked ( idx)
4136 }
4237
4338 pub fn populate_blocked ( & mut self ) {
44- for ( i, tile) in self . tiles . iter_mut ( ) . enumerate ( ) {
45- self . blocked [ i] = !tile_walkable ( * tile) ;
46- }
39+ crate :: spatial:: populate_blocked_from_map ( self ) ;
4740 }
4841
4942 pub fn populate_blocked_multi ( & mut self , width : i32 , height : i32 ) {
5043 self . populate_blocked ( ) ;
5144 for y in 1 .. self . height -1 {
5245 for x in 1 .. self . width - 1 {
5346 let idx = self . xy_idx ( x, y) ;
54- if !self . blocked [ idx] {
47+ if !crate :: spatial :: is_blocked ( idx) {
5548 for cy in 0 ..height {
5649 for cx in 0 ..width {
5750 let tx = x + cx;
5851 let ty = y + cy;
5952 if tx < self . width -1 && ty < self . height -1 {
6053 let tidx = self . xy_idx ( tx, ty) ;
61- if self . blocked [ tidx] {
62- self . blocked [ idx] = true ;
54+ if crate :: spatial :: is_blocked ( tidx) {
55+ crate :: spatial :: set_blocked ( idx, true ) ;
6356 }
6457 } else {
65- self . blocked [ idx] = true ;
58+ crate :: spatial :: set_blocked ( idx, true ) ;
6659 }
6760 }
6861 }
@@ -72,22 +65,19 @@ impl Map {
7265 }
7366
7467 pub fn clear_content_index ( & mut self ) {
75- for content in self . tile_content . iter_mut ( ) {
76- content. clear ( ) ;
77- }
68+ crate :: spatial:: clear ( ) ;
7869 }
7970
8071 /// Generates an empty map, consisting entirely of solid walls
8172 pub fn new < S : ToString > ( new_depth : i32 , width : i32 , height : i32 , name : S ) -> Map {
8273 let map_tile_count = ( width* height) as usize ;
74+ crate :: spatial:: set_size ( map_tile_count) ;
8375 Map {
8476 tiles : vec ! [ TileType :: Wall ; map_tile_count] ,
8577 width,
8678 height,
8779 revealed_tiles : vec ! [ false ; map_tile_count] ,
8880 visible_tiles : vec ! [ false ; map_tile_count] ,
89- blocked : vec ! [ false ; map_tile_count] ,
90- tile_content : vec ! [ Vec :: new( ) ; map_tile_count] ,
9181 depth : new_depth,
9282 bloodstains : HashSet :: new ( ) ,
9383 view_blocked : HashSet :: new ( ) ,
0 commit comments