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)
|
moredirs, dir2 = os.path.split(destdir)
|
||||||
_, dir1 = os.path.split(moredirs)
|
_, dir1 = os.path.split(moredirs)
|
||||||
self.cachedir = os.path.join(cachedir, dir1, dir2)
|
self.cachedir = os.path.join(cachedir, dir1, dir2)
|
||||||
|
self.dirbits = (dir1, dir2)
|
||||||
|
|
||||||
|
|
||||||
if self.world.useBiomeData:
|
if self.world.useBiomeData:
|
||||||
@@ -301,16 +302,12 @@ class ChunkRenderer(object):
|
|||||||
return self._digest
|
return self._digest
|
||||||
|
|
||||||
def find_oldimage(self, cave):
|
def find_oldimage(self, cave):
|
||||||
# Get the name of the existing image. No way to do this but to look at
|
# Get the name of the existing image.
|
||||||
# all the files
|
|
||||||
oldimg = oldimg_path = None
|
oldimg = oldimg_path = None
|
||||||
for filename in os.listdir(self.cachedir):
|
key = ".".join((dirbits[0], dirbits[1], self.blockid, "cave" if cave else "nocave"))
|
||||||
if filename.startswith("img.{0}.{1}.".format(self.blockid,
|
if key in self.world.cached:
|
||||||
"cave" if cave else "nocave")) and \
|
oldimg_path = self.world.cached[key]
|
||||||
filename.endswith(".png"):
|
_, oldimg = os.path.split(oldimg_path)
|
||||||
oldimg = filename
|
|
||||||
oldimg_path = os.path.join(self.cachedir, oldimg)
|
|
||||||
break
|
|
||||||
return oldimg, oldimg_path
|
return oldimg, oldimg_path
|
||||||
|
|
||||||
def render_and_save(self, cave=False):
|
def render_and_save(self, cave=False):
|
||||||
|
|||||||
15
world.py
15
world.py
@@ -21,6 +21,7 @@ import Queue
|
|||||||
import sys
|
import sys
|
||||||
import logging
|
import logging
|
||||||
import cPickle
|
import cPickle
|
||||||
|
import collections
|
||||||
|
|
||||||
import numpy
|
import numpy
|
||||||
|
|
||||||
@@ -107,6 +108,20 @@ class WorldRenderer(object):
|
|||||||
textures.prepareBiomeData(worlddir)
|
textures.prepareBiomeData(worlddir)
|
||||||
|
|
||||||
self.chunklist = chunklist
|
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
|
# stores Points Of Interest to be mapped with markers
|
||||||
# a list of dictionaries, see below for an example
|
# a list of dictionaries, see below for an example
|
||||||
|
|||||||
Reference in New Issue
Block a user