From 6f1bb4ef8d420e7cc8a51ec5f793fa18bc760cbc Mon Sep 17 00:00:00 2001 From: Xon Date: Fri, 1 Apr 2011 16:09:34 +0800 Subject: [PATCH] Tweaked get_chunks_in_range to only look up the region object if it has changed in the inner-loop --- quadtree.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/quadtree.py b/quadtree.py index 2437b33..ac1c26c 100644 --- a/quadtree.py +++ b/quadtree.py @@ -222,6 +222,10 @@ class QuadtreeGen(object): unconvert_coords = self.world.unconvert_coords #get_region_path = self.world.get_region_path get_region = self.world.regionfiles.get + regionx = None + regiony = None + c = None + mcr = None for row in xrange(rowstart-16, rowend+1): for col in xrange(colstart, colend+1): # due to how chunks are arranged, we can only allow @@ -230,12 +234,18 @@ class QuadtreeGen(object): if row % 2 != col % 2: continue - # return (col, row, chunkx, chunky, regionpath) chunkx, chunky = unconvert_coords(col, row) - #c = get_region_path(chunkx, chunky) - _, _, c, mcr = get_region((chunkx//32, chunky//32),(None,None,None,None)); + + regionx_ = chunkx//32 + regiony_ = chunky//32 + if regionx_ != regionx or regiony_ != regiony: + regionx = regionx_ + regiony = regiony_ + _, _, c, mcr = get_region((regionx, regiony),(None,None,None,None)) + if c is not None and mcr.chunkExists(chunkx,chunky): chunklist.append((col, row, chunkx, chunky, c)) + return chunklist def get_worldtiles(self):