Use a more efficient checker for cached images
This commit is contained in:
15
chunk.py
15
chunk.py
@@ -169,6 +169,7 @@ class ChunkRenderer(object):
|
||||
moredirs, dir2 = os.path.split(destdir)
|
||||
_, dir1 = os.path.split(moredirs)
|
||||
self.cachedir = os.path.join(cachedir, dir1, dir2)
|
||||
self.dirbits = (dir1, dir2)
|
||||
|
||||
|
||||
if self.world.useBiomeData:
|
||||
@@ -301,16 +302,12 @@ class ChunkRenderer(object):
|
||||
return self._digest
|
||||
|
||||
def find_oldimage(self, cave):
|
||||
# Get the name of the existing image. No way to do this but to look at
|
||||
# all the files
|
||||
# Get the name of the existing image.
|
||||
oldimg = oldimg_path = None
|
||||
for filename in os.listdir(self.cachedir):
|
||||
if filename.startswith("img.{0}.{1}.".format(self.blockid,
|
||||
"cave" if cave else "nocave")) and \
|
||||
filename.endswith(".png"):
|
||||
oldimg = filename
|
||||
oldimg_path = os.path.join(self.cachedir, oldimg)
|
||||
break
|
||||
key = ".".join((dirbits[0], dirbits[1], self.blockid, "cave" if cave else "nocave"))
|
||||
if key in self.world.cached:
|
||||
oldimg_path = self.world.cached[key]
|
||||
_, oldimg = os.path.split(oldimg_path)
|
||||
return oldimg, oldimg_path
|
||||
|
||||
def render_and_save(self, cave=False):
|
||||
|
||||
15
world.py
15
world.py
@@ -21,6 +21,7 @@ import Queue
|
||||
import sys
|
||||
import logging
|
||||
import cPickle
|
||||
import collections
|
||||
|
||||
import numpy
|
||||
|
||||
@@ -107,6 +108,20 @@ class WorldRenderer(object):
|
||||
textures.prepareBiomeData(worlddir)
|
||||
|
||||
self.chunklist = chunklist
|
||||
self.cached = collections.defaultdict(dict)
|
||||
|
||||
# In order to avoid having to look up the cache file names in
|
||||
# ChunkRenderer, get them all and store them here
|
||||
for root, dirnames, filenames in os.walk('.'):
|
||||
for filename in filenames:
|
||||
if not filename.endswith('.png'):
|
||||
continue
|
||||
dirname, dir_b = os.path.split(root)
|
||||
_, dir_a = os.path.split(dirname)
|
||||
_, x, z, cave, _ = filename.split('.', 4)
|
||||
bits = '.'.join((dir_a, dir_b, x, z, cave))
|
||||
self.cached[bits] = os.path.join(root, filename)
|
||||
|
||||
|
||||
# stores Points Of Interest to be mapped with markers
|
||||
# a list of dictionaries, see below for an example
|
||||
|
||||
Reference in New Issue
Block a user