0

Better cache checking, now uses chunk timestamps

and possibly fixed a bug in check_cache?
This commit is contained in:
Andrew Chin
2011-02-28 22:10:36 -05:00
parent caa1ef1f45
commit 5f2f098d40
2 changed files with 12 additions and 7 deletions

View File

@@ -150,10 +150,15 @@ def check_cache(world, chunkXY, oldimg):
# TODO currently, just use the mtime on the region file # TODO currently, just use the mtime on the region file
# TODO (which will cause a single chunk update to invalidate everything in the region # TODO (which will cause a single chunk update to invalidate everything in the region
chunkfile = os.path.join(world.worlddir, "region", "r.%d.%d.mcr" % (chunkXY[0]%64, chunkXY[1]%64)) if not oldimg[1]: return False
#logging.debug("checking cache %s against %s", chunkfile, oldimg[1]) chunkfile = os.path.join(world.worlddir, "region", "r.%d.%d.mcr" % (chunkXY[0]//64, chunkXY[1]//64))
with open(chunkfile, "rb") as f:
region = nbt.MCRFileReader(f)
mtime = region.get_chunk_timestamp(chunkXY[0], chunkXY[1])
#logging.debug("checking cache %s against %s %d", chunkfile, oldimg[1], mtime)
try: try:
if oldimg[1] and os.path.getmtime(chunkfile) <= os.path.getmtime(oldimg[1]): if mtime <= os.path.getmtime(oldimg[1]):
return True return True
return False return False
except OSError: except OSError:
@@ -500,7 +505,6 @@ class ChunkRenderer(object):
except NoSuchChunk, e: except NoSuchChunk, e:
return None return None
dest_path = os.path.join(self.cachedir, dest_filename) dest_path = os.path.join(self.cachedir, dest_filename)
#logging.debug("cache filename: %s", dest_path) #logging.debug("cache filename: %s", dest_path)
@@ -510,9 +514,9 @@ class ChunkRenderer(object):
# hashes match. # hashes match.
# Before we return it, update its mtime so the next round # Before we return it, update its mtime so the next round
# doesn't have to check the hash # doesn't have to check the hash
# TODO fix up hash checking # TODO confirm hash checking is correct (it should be)
os.utime(dest_path, None) os.utime(dest_path, None)
logging.debug("Using cached image") logging.debug("Using cached image, and updating utime")
return dest_path return dest_path
else: else:
# Remove old image for this chunk. Anything already existing is # Remove old image for this chunk. Anything already existing is
@@ -520,6 +524,7 @@ class ChunkRenderer(object):
os.unlink(self.oldimg_path) os.unlink(self.oldimg_path)
logging.debug("doing a real real render")
# Render the chunk # Render the chunk
img = self.chunk_render(cave=cave) img = self.chunk_render(cave=cave)
# Save it # Save it

View File

@@ -344,7 +344,7 @@ class WorldRenderer(object):
if chunk.check_cache(self, chunkXY, oldimg): if chunk.check_cache(self, chunkXY, oldimg):
result = oldimg[1] result = oldimg[1]
else: else:
#logging.debug("check cache failed, need to render") #logging.debug("check cache failed, need to render (could be ghost chunk)")
result = chunk.render_and_save(chunkXY, self.cachedir, self, oldimg, queue=q) result = chunk.render_and_save(chunkXY, self.cachedir, self, oldimg, queue=q)
if result: if result: