From f2b34dff7adfe8cc83ca8f671c55ddf1713340e7 Mon Sep 17 00:00:00 2001 From: Andrew Chin Date: Sun, 24 Oct 2010 00:19:27 -0400 Subject: [PATCH] Improved handling of signposts --- chunk.py | 50 ++++++++++++++++++++++++-------------------------- quadtree.py | 10 +--------- world.py | 9 +++++++-- 3 files changed, 32 insertions(+), 37 deletions(-) diff --git a/chunk.py b/chunk.py index 270679b..4ca0d19 100644 --- a/chunk.py +++ b/chunk.py @@ -520,32 +520,6 @@ class ChunkRenderer(object): else: t = textures.blockmap[blockid] - - # see if we want to do anything else with this chunk - if blockid in (63, 68): # signs - # find the sign text from the TileEntities list - print "Found a sign!" - for entity in tileEntities: - if entity['id'] == 'Sign': - print "adding to POI list" - # TODO assert that the x,y,z of this entity matches - # the x,y,z of this block - - # convert the blockID coordinates from local chunk - # coordinates to global world coordinates - newPOI = dict(type="sign", - x= x+(self.chunkX*16), - y= z, - z= y+(self.chunkY*16), - msg="%s\n%s\n%s\n%s" % - (entity['Text1'], entity['Text2'], entity['Text3'], entity['Text4']), - chunk= (self.chunkX, self.chunkY), - ) - print "new POI: %s" % newPOI - self.queue.put(["newpoi", newPOI]) - break - - if not t: continue @@ -644,6 +618,30 @@ class ChunkRenderer(object): if y != 0 and blocks[x,y-1,z] == 0: draw.line(((imgx,imgy+6+increment), (imgx+12,imgy+increment)), fill=(0,0,0), width=1) + + for entity in tileEntities: + if entity['id'] == 'Sign': + + # convert the blockID coordinates from local chunk + # coordinates to global world coordinates + newPOI = dict(type="sign", + x= entity['x'], + y= entity['z'], + z= entity['y'], + msg="%s\n%s\n%s\n%s" % + (entity['Text1'], entity['Text2'], entity['Text3'], entity['Text4']), + chunk= (self.chunkX, self.chunkY), + ) + self.queue.put(["newpoi", newPOI]) + + + # check to see if there are any signs in the persistentData list that are from this chunk. + # if so, remove them from the persistentData list (since they're have been added to the world.POI + # list above. + self.queue.put(['removePOI', (self.chunkX, self.chunkY)]) + + + return img # Render 3 blending masks for lighting diff --git a/quadtree.py b/quadtree.py index 56811a0..c013c62 100644 --- a/quadtree.py +++ b/quadtree.py @@ -153,15 +153,7 @@ class QuadtreeGen(object): # in self.world.POI. To make sure we don't remove these from markers.js # we need to merge self.world.POI with the persistant data in world.PersistentData - # - modifiedChunks = map(lambda x: x['chunk'], filter(lambda x: x['type'] != 'spawn', self.world.POI)) - - for item in self.world.persistentData['POI']: - # if this previously discovered POI isn't in a modified chunk, keep it - if item['chunk'] not in modifiedChunks and item['type'] != 'spawn': - self.world.POI.append(item) - # else discard it, because self.world.POI will contain it (or not if it - # was deleted) + self.world.POI += filter(lambda x: x['type'] != 'spawn', self.world.persistentData['POI']) # write out the default marker table with open(os.path.join(self.destdir, "markers.js"), 'w') as output: diff --git a/world.py b/world.py index 09ed516..925feb0 100644 --- a/world.py +++ b/world.py @@ -17,6 +17,7 @@ import functools import os import os.path import multiprocessing +import Queue import sys import logging import cPickle @@ -280,7 +281,9 @@ class WorldRenderer(object): item = q.get(block=False) if item[0] == "newpoi": self.POI.append(item[1]) - except: + elif item[0] == "removePOI": + self.persistentData['POI'] = filter(lambda x: x['chunk'] != item[1], self.persistentData['POI']) + except Queue.Empty: pass if 1000 % i == 0 or i % 1000 == 0: logging.info("{0}/{1} chunks rendered".format(i, len(chunks))) @@ -310,8 +313,10 @@ class WorldRenderer(object): item = q.get(block=False) if item[0] == "newpoi": self.POI.append(item[1]) + elif item[0] == "removePOI": + self.persistentData['POI'] = filter(lambda x: x['chunk'] != item[1], self.persistentData['POI']) - except: + except Queue.Empty: pass if i > 0: if 1000 % i == 0 or i % 1000 == 0: