Ejemplo n.º 1
0
    def __init__(self, chunkcoords, cachedir, worldobj, oldimg, queue):
        """Make a new chunk renderer for the given chunk coordinates.
        chunkcoors should be a tuple: (chunkX, chunkY)
        
        cachedir is a directory to save the resulting chunk images to
        """
        self.queue = queue
        # derive based on worlddir and chunkcoords
        self.regionfile = os.path.join(worldobj.worlddir, "region",
                "r.%d.%d.mcr" % (chunkcoords[0] // 32, chunkcoords[1]//32))
    
        if not os.path.exists(self.regionfile):
            raise ValueError("Could not find regionfile: %s" % self.regionfile)

        ## TODO TODO all of this class

        #destdir, filename = os.path.split(self.chunkfile)
        #filename_split = filename.split(".")
        #chunkcoords = filename_split[1:3]
        
        #self.coords = map(world.base36decode, chunkcoords)
        self.blockid = "%d.%d" % chunkcoords

        # chunk coordinates (useful to converting local block coords to 
        # global block coords)
        self.chunkX = chunkcoords[0]
        self.chunkY = chunkcoords[1]



        self.world = worldobj


        # Cachedir here is the base directory of the caches. We need to go 2
        # levels deeper according to the chunk file. Get the last 2 components
        # of destdir and use that
        ##moredirs, dir2 = os.path.split(destdir)
        ##_, dir1 = os.path.split(moredirs)
        self.cachedir = os.path.join(cachedir, 
                world.base36encode(self.chunkX%64), 
                world.base36encode(self.chunkY%64))

        #logging.debug("cache location for this chunk: %s", self.cachedir)
        self.oldimg, self.oldimg_path = oldimg


        if self.world.useBiomeData:
            # make sure we've at least *tried* to load the color arrays in this process...
            textures.prepareBiomeData(self.world.worlddir)
            if not textures.grasscolor or not textures.foliagecolor:
                raise Exception("Can't find grasscolor.png or foliagecolor.png")


        if not os.path.exists(self.cachedir):
            try:
                os.makedirs(self.cachedir)
            except OSError, e:
                import errno
                if e.errno != errno.EEXIST:
                    raise
Ejemplo n.º 2
0
    def __init__(self, chunkcoords, cachedir, worldobj, oldimg, queue):
        """Make a new chunk renderer for the given chunk coordinates.
        chunkcoors should be a tuple: (chunkX, chunkY)
        
        cachedir is a directory to save the resulting chunk images to
        """
        self.queue = queue
        # derive based on worlddir and chunkcoords
        self.regionfile = os.path.join(
            worldobj.worlddir, "region",
            "r.%d.%d.mcr" % (chunkcoords[0] // 32, chunkcoords[1] // 32))

        if not os.path.exists(self.regionfile):
            raise ValueError("Could not find regionfile: %s" % self.regionfile)

        ## TODO TODO all of this class

        #destdir, filename = os.path.split(self.chunkfile)
        #filename_split = filename.split(".")
        #chunkcoords = filename_split[1:3]

        #self.coords = map(world.base36decode, chunkcoords)
        self.blockid = "%d.%d" % chunkcoords

        # chunk coordinates (useful to converting local block coords to
        # global block coords)
        self.chunkX = chunkcoords[0]
        self.chunkY = chunkcoords[1]

        self.world = worldobj

        # Cachedir here is the base directory of the caches. We need to go 2
        # levels deeper according to the chunk file. Get the last 2 components
        # of destdir and use that
        ##moredirs, dir2 = os.path.split(destdir)
        ##_, dir1 = os.path.split(moredirs)
        self.cachedir = os.path.join(cachedir,
                                     world.base36encode(self.chunkX % 64),
                                     world.base36encode(self.chunkY % 64))

        #logging.debug("cache location for this chunk: %s", self.cachedir)
        self.oldimg, self.oldimg_path = oldimg

        if self.world.useBiomeData:
            # make sure we've at least *tried* to load the color arrays in this process...
            textures.prepareBiomeData(self.world.worlddir)
            if not textures.grasscolor or not textures.foliagecolor:
                raise Exception(
                    "Can't find grasscolor.png or foliagecolor.png")

        if not os.path.exists(self.cachedir):
            try:
                os.makedirs(self.cachedir)
            except OSError, e:
                import errno
                if e.errno != errno.EEXIST:
                    raise
Ejemplo n.º 3
0
def find_oldimage(chunkXY, cached, cave):
    blockid = "%d.%d" % chunkXY

    # Get the name of the existing image.
    dir1 = world.base36encode(chunkXY[0]%64)
    dir2 = world.base36encode(chunkXY[1]%64)
    cachename = '/'.join((dir1, dir2))

    oldimg = oldimg_path = None
    key = ".".join((blockid, "cave" if cave else "nocave"))
    if key in cached[cachename]:
         oldimg_path = cached[cachename][key]
         _, oldimg = os.path.split(oldimg_path)
         #logging.debug("Found cached image {0}".format(oldimg))
    return oldimg, oldimg_path
Ejemplo n.º 4
0
def find_oldimage(chunkXY, cached, cave):
    blockid = "%d.%d" % chunkXY

    # Get the name of the existing image.
    dir1 = world.base36encode(chunkXY[0] % 64)
    dir2 = world.base36encode(chunkXY[1] % 64)
    cachename = '/'.join((dir1, dir2))

    oldimg = oldimg_path = None
    key = ".".join((blockid, "cave" if cave else "nocave"))
    if key in cached[cachename]:
        oldimg_path = cached[cachename][key]
        _, oldimg = os.path.split(oldimg_path)
        #logging.debug("Found cached image {0}".format(oldimg))
    return oldimg, oldimg_path