From 346c42d64bf76f79d789c63c536d08beba719f23 Mon Sep 17 00:00:00 2001 From: Xon Date: Tue, 29 Mar 2011 09:56:00 +0800 Subject: [PATCH] Fixed chunk caching to correctly count empty chunk responses. Tweaked upper bound on number of chunks to cache. --- world.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/world.py b/world.py index 4f1b4cf..665619d 100644 --- a/world.py +++ b/world.py @@ -84,9 +84,10 @@ class World(object): self.regionfiles = regionfiles # set the number of region file handles we will permit open at any time before we start closing them # self.regionlimit = 1000 - # the max number of chunks we will keep before removing them - self.chunklimit = 1024*6 # this should be a multipule of the max chunks per region or things could get wonky ??? + # the max number of chunks we will keep before removing them (includes emptry chunks) + self.chunklimit = 1024 self.chunkcount = 0 + self.empty_chunk = [None,None] logging.debug("Done scanning regions") # figure out chunk format is in use @@ -116,7 +117,8 @@ class World(object): else: # some defaults self.persistentData = dict(POI=[]) - + + def get_region_path(self, chunkX, chunkY): """Returns the path to the region that contains chunk (chunkX, chunkY) """ @@ -131,16 +133,18 @@ class World(object): chunks = regioninfo[2] chunk_data = chunks.get((x,y)) if chunk_data is None: - nbt = self.load_region(filename).load_chunk(x, y) - if nbt is None: - chunks[(x,y)] = [None,None] - return None ## return none. I think this is who we should indicate missing chunks - #raise IOError("No such chunk in region: (%i, %i)" % (x, y)) #prune the cache if required if self.chunkcount > self.chunklimit: #todo: make the emptying the chunk cache slightly less crazy [self.reload_region(regionfile) for regionfile in self.regions if regionfile <> filename] + self.chunkcount = 0 self.chunkcount += 1 + nbt = self.load_region(filename).load_chunk(x, y) + if nbt is None: + chunks[(x,y)] = self.empty_chunk + return None ## return none. I think this is who we should indicate missing chunks + #raise IOError("No such chunk in region: (%i, %i)" % (x, y)) + #we cache the transformed data, not it's raw form data = nbt.read_all() level = data[1]['Level']