0

Fixed chunk caching to correctly count empty chunk responses.

Tweaked upper bound on number of chunks to cache.
This commit is contained in:
Xon
2011-03-29 09:56:00 +08:00
parent 2a234e0659
commit 346c42d64b

View File

@@ -84,9 +84,10 @@ class World(object):
self.regionfiles = regionfiles self.regionfiles = regionfiles
# set the number of region file handles we will permit open at any time before we start closing them # set the number of region file handles we will permit open at any time before we start closing them
# self.regionlimit = 1000 # self.regionlimit = 1000
# the max number of chunks we will keep before removing them # the max number of chunks we will keep before removing them (includes emptry chunks)
self.chunklimit = 1024*6 # this should be a multipule of the max chunks per region or things could get wonky ??? self.chunklimit = 1024
self.chunkcount = 0 self.chunkcount = 0
self.empty_chunk = [None,None]
logging.debug("Done scanning regions") logging.debug("Done scanning regions")
# figure out chunk format is in use # figure out chunk format is in use
@@ -116,7 +117,8 @@ class World(object):
else: else:
# some defaults # some defaults
self.persistentData = dict(POI=[]) self.persistentData = dict(POI=[])
def get_region_path(self, chunkX, chunkY): def get_region_path(self, chunkX, chunkY):
"""Returns the path to the region that contains chunk (chunkX, chunkY) """Returns the path to the region that contains chunk (chunkX, chunkY)
""" """
@@ -131,16 +133,18 @@ class World(object):
chunks = regioninfo[2] chunks = regioninfo[2]
chunk_data = chunks.get((x,y)) chunk_data = chunks.get((x,y))
if chunk_data is None: 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 #prune the cache if required
if self.chunkcount > self.chunklimit: #todo: make the emptying the chunk cache slightly less crazy 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.reload_region(regionfile) for regionfile in self.regions if regionfile <> filename]
self.chunkcount = 0
self.chunkcount += 1 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 #we cache the transformed data, not it's raw form
data = nbt.read_all() data = nbt.read_all()
level = data[1]['Level'] level = data[1]['Level']