Skip to content

Commit

Permalink
Merge pull request #26 from forbjok/fix-tile-entities-leaking-on-map-…
Browse files Browse the repository at this point in the history
…despawn

Fixed tile entities leaking when map entity is despawned recursively
  • Loading branch information
StarArawn authored May 14, 2021
2 parents 43f05d2 + b714184 commit eb299da
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ impl Clone for MapSettings {
pub struct Map {
/// The map information for the tilemap entity.
pub settings: MapSettings,
map_entity: Option<Entity>,
chunks: Vec<Option<Entity>>,
tiles: Vec<Option<Entity>>,
events: VecDeque<SetTileEvent>,
Expand All @@ -114,6 +115,7 @@ impl Default for Map {
cull: true,
mesher: Box::new(SquareChunkMesher),
},
map_entity: None,
chunks: Vec::new(),
tiles: Vec::new(),
events: VecDeque::new(),
Expand Down Expand Up @@ -147,6 +149,7 @@ impl Map {
let tile_count = tile_size_x * tile_size_y;
Self {
settings,
map_entity: None,
chunks: vec![None; map_size],
tiles: vec![None; tile_count],
events: VecDeque::new(),
Expand Down Expand Up @@ -205,6 +208,7 @@ impl Map {
} else {
let mut tile_commands = commands.spawn();
tile_commands
.insert(Parent(self.map_entity.unwrap()))
.insert(Tile {
chunk: chunk,
..tile
Expand Down Expand Up @@ -348,6 +352,8 @@ impl Map {
map_entity: Entity,
populate_chunks: bool,
) {
self.map_entity = Some(map_entity);

for x in 0..self.settings.map_size.x {
for y in 0..self.settings.map_size.y {
let mut chunk_entity = None;
Expand Down

0 comments on commit eb299da

Please sign in to comment.