Fix clear_terrain not changing Changes

Former-commit-id: da7b02939d6d0bc7dbef7d923fb880081f6e08aa
This commit is contained in:
timokoesters 2019-05-25 14:23:56 +02:00
parent 525af4c201
commit f4434013db
6 changed files with 20 additions and 9 deletions

View File

@ -133,8 +133,8 @@ impl Client {
/// Remove all cached terrain
#[allow(dead_code)]
pub fn reset_terrain(&mut self) {
self.state.terrain_mut().clear();
pub fn clear_terrain(&mut self) {
self.state.clear_terrain();
self.pending_chunks.clear();
}

View File

@ -190,6 +190,18 @@ impl State {
self.ecs.write_resource::<TerrainMap>()
}
/// Removes every chunk of the terrain.
pub fn clear_terrain(&mut self) {
let keys = self.terrain_mut()
.drain()
.map(|(key, _)| key)
.collect::<Vec<_>>();
for key in keys {
self.remove_chunk(key);
}
}
/// Insert the provided chunk into this state's terrain.
pub fn insert_chunk(&mut self, key: Vec2<i32>, chunk: TerrainChunk) {
if self

View File

@ -6,7 +6,7 @@ use crate::{
dyna::{Dyna, DynaErr},
},
};
use std::{collections::HashMap, marker::PhantomData, sync::Arc};
use std::{collections::{hash_map, HashMap}, marker::PhantomData, sync::Arc};
use vek::*;
#[derive(Debug)]
@ -149,6 +149,10 @@ impl<V: BaseVol, S: VolSize> VolMap2d<V, S> {
self.chunks.clear();
}
pub fn drain(&mut self) -> hash_map::Drain<Vec2<i32>, Arc<V>> {
self.chunks.drain()
}
pub fn remove(&mut self, key: Vec2<i32>) -> Option<Arc<V>> {
self.chunks.remove(&key)
}

View File

@ -45,7 +45,6 @@ impl PlayState for CharSelectionState {
fn play(&mut self, _: Direction, global_state: &mut GlobalState) -> PlayStateResult {
// Set up an fps clock.
let mut clock = Clock::new();
self.client.borrow_mut().reset_terrain();
let mut current_client_state = self.client.borrow().get_client_state();
while let ClientState::Pending | ClientState::Registered = current_client_state {

View File

@ -205,8 +205,4 @@ impl Terrain {
renderer.render_terrain_chunk(&chunk.model, globals, &chunk.locals);
}
}
pub fn clear(&mut self) {
self.chunks.clear();
}
}

View File

@ -115,7 +115,7 @@ impl PlayState for SessionState {
// Set up an fps clock.
let mut clock = Clock::new();
self.client.borrow_mut().reset_terrain();
self.client.borrow_mut().clear_terrain();
// Game loop
let mut current_client_state = self.client.borrow().get_client_state();