def pool_initializer(rendernode): logging.debug("Child process {0}".format(os.getpid())) #stash the quadtree objects in a global variable after fork() for windows compat. global child_rendernode child_rendernode = rendernode # make sure textures are generated for this process # and initialize c_overviewer textures.generate(path=rendernode.options.get('textures_path', None), north_direction=rendernode.options.get('north_direction', None)) c_overviewer.init_chunk_render() # setup c_overviewer rendermode customs / options for mode in rendernode.options.custom_rendermodes: c_overviewer.add_custom_render_mode(mode, rendernode.options.custom_rendermodes[mode]) for mode in rendernode.options.rendermode_options: c_overviewer.set_render_mode_options(mode, rendernode.options.rendermode_options[mode]) # load biome data in each process, if needed for quadtree in rendernode.quadtrees: if quadtree.world.useBiomeData: # make sure we've at least *tried* to load the color arrays in this process... textures.prepareBiomeData(quadtree.world.worlddir) if not textures.grasscolor or not textures.foliagecolor: raise Exception("Can't find grasscolor.png or foliagecolor.png") # only load biome data once break
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
def __init__(self, worlddir, cachedir, chunklist=None, lighting=False, night=False, spawn=False, useBiomeData=False): self.worlddir = worlddir self.caves = False self.lighting = lighting or night or spawn self.night = night or spawn self.spawn = spawn self.cachedir = cachedir self.useBiomeData = useBiomeData if self.useBiomeData: textures.prepareBiomeData(worlddir) self.chunklist = chunklist # stores Points Of Interest to be mapped with markers # a list of dictionaries, see below for an example self.POI = [] # if it exists, open overviewer.dat, and read in the data structure # info self.persistentData. This dictionary can hold any information # that may be needed between runs. # Currently only holds into about POIs (more more details, see quadtree) self.pickleFile = os.path.join(self.cachedir,"overviewer.dat") if os.path.exists(self.pickleFile): with open(self.pickleFile,"rb") as p: self.persistentData = cPickle.load(p) else: # some defaults self.persistentData = dict(POI=[])
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
def __init__(self, worlddir, cachedir, chunklist=None, lighting=False, night=False, spawn=False, useBiomeData=False): self.worlddir = worlddir self.caves = False self.lighting = lighting or night or spawn self.night = night or spawn self.spawn = spawn self.cachedir = cachedir self.useBiomeData = useBiomeData # figure out chunk format is in use # if mcregion, error out early until we can add support data = nbt.load(os.path.join(self.worlddir, "level.dat"))[1]['Data'] #print data if not ('version' in data and data['version'] == 19132): logging.error("Sorry, This version of Minecraft-Overviewer only works with the new McRegion chunk format") sys.exit(1) if self.useBiomeData: textures.prepareBiomeData(worlddir) self.chunklist = chunklist # In order to avoid having to look up the cache file names in # ChunkRenderer, get them all and store them here # TODO change how caching works for root, dirnames, filenames in os.walk(cachedir): for filename in filenames: if not filename.endswith('.png') or not filename.startswith("img."): continue dirname, dir_b = os.path.split(root) _, dir_a = os.path.split(dirname) _, x, z, cave, _ = filename.split('.', 4) dir = '/'.join((dir_a, dir_b)) bits = '.'.join((x, z, cave)) cached[dir][bits] = os.path.join(root, filename) # stores Points Of Interest to be mapped with markers # a list of dictionaries, see below for an example self.POI = [] # if it exists, open overviewer.dat, and read in the data structure # info self.persistentData. This dictionary can hold any information # that may be needed between runs. # Currently only holds into about POIs (more more details, see quadtree) self.pickleFile = os.path.join(self.cachedir,"overviewer.dat") if os.path.exists(self.pickleFile): with open(self.pickleFile,"rb") as p: self.persistentData = cPickle.load(p) else: # some defaults self.persistentData = dict(POI=[])
def __init__(self, worlddir, useBiomeData=False,regionlist=None): self.worlddir = worlddir self.useBiomeData = useBiomeData #find region files, or load the region list #this also caches all the region file header info logging.info("Scanning regions") regionfiles = {} self.regions = {} self.regionlist = regionlist # a list of paths for x, y, regionfile in self._iterate_regionfiles(): mcr = self.reload_region(regionfile) mcr.get_chunk_info() regionfiles[(x,y)] = (x,y,regionfile,mcr) self.regionfiles = regionfiles # set the number of region file handles we will permit open at any time before we start closing them # self.regionlimit = 1000 # the max number of chunks we will keep before removing them (includes emptry chunks) self.chunklimit = 1024 self.chunkcount = 0 self.empty_chunk = [None,None] logging.debug("Done scanning regions") # figure out chunk format is in use # if not mcregion, error out early data = nbt.load(os.path.join(self.worlddir, "level.dat"))[1]['Data'] #print data if not ('version' in data and data['version'] == 19132): logging.error("Sorry, This version of Minecraft-Overviewer only works with the new McRegion chunk format") sys.exit(1) if self.useBiomeData: textures.prepareBiomeData(worlddir) # stores Points Of Interest to be mapped with markers # a list of dictionaries, see below for an example self.POI = [] # if it exists, open overviewer.dat, and read in the data structure # info self.persistentData. This dictionary can hold any information # that may be needed between runs. # Currently only holds into about POIs (more more details, see quadtree) # TODO maybe store this with the tiles, not with the world? self.pickleFile = os.path.join(self.worlddir, "overviewer.dat") if os.path.exists(self.pickleFile): with open(self.pickleFile,"rb") as p: self.persistentData = cPickle.load(p) else: # some defaults self.persistentData = dict(POI=[])
def __init__(self, chunkfile, cachedir, worldobj, oldimg, queue): """Make a new chunk renderer for the given chunkfile. chunkfile should be a full path to the .dat file to process cachedir is a directory to save the resulting chunk images to """ self.queue = queue if not os.path.exists(chunkfile): raise ValueError("Could not find chunkfile") self.chunkfile = chunkfile destdir, filename = os.path.split(self.chunkfile) filename_split = filename.split(".") chunkcoords = filename_split[1:3] self.coords = map(world.base36decode, chunkcoords) self.blockid = ".".join(chunkcoords) # chunk coordinates (useful to converting local block coords to # global block coords) self.chunkX = int(filename_split[1], base=36) self.chunkY = int(filename_split[2], base=36) 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, dir1, dir2) 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
def __init__( self, worlddir, cachedir, chunklist=None, lighting=False, night=False, spawn=False, useBiomeData=False ): self.worlddir = worlddir self.caves = False self.lighting = lighting or night or spawn self.night = night or spawn self.spawn = spawn self.cachedir = cachedir self.useBiomeData = useBiomeData if self.useBiomeData: textures.prepareBiomeData(worlddir) self.chunklist = chunklist # 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(cachedir): for filename in filenames: if not filename.endswith(".png") or not filename.startswith("img."): continue dirname, dir_b = os.path.split(root) _, dir_a = os.path.split(dirname) _, x, z, cave, _ = filename.split(".", 4) dir = "/".join((dir_a, dir_b)) bits = ".".join((x, z, cave)) cached[dir][bits] = os.path.join(root, filename) # stores Points Of Interest to be mapped with markers # a list of dictionaries, see below for an example self.POI = [] # if it exists, open overviewer.dat, and read in the data structure # info self.persistentData. This dictionary can hold any information # that may be needed between runs. # Currently only holds into about POIs (more more details, see quadtree) self.pickleFile = os.path.join(self.cachedir, "overviewer.dat") if os.path.exists(self.pickleFile): with open(self.pickleFile, "rb") as p: self.persistentData = cPickle.load(p) else: # some defaults self.persistentData = dict(POI=[])
def __init__(self, worlddir, cachedir, chunklist=None, lighting=False, night=False, spawn=False, useBiomeData=False): self.worlddir = worlddir self.caves = False self.lighting = lighting or night or spawn self.night = night or spawn self.spawn = spawn self.cachedir = cachedir self.useBiomeData = useBiomeData # figure out chunk format is in use # if mcregion, error out early until we can add support data = nbt.load(os.path.join(self.worlddir, "level.dat"))[1]['Data'] #print data if not ('version' in data and data['version'] == 19132): logging.error( "Sorry, This version of Minecraft-Overviewer only works with the new McRegion chunk format" ) sys.exit(1) if self.useBiomeData: textures.prepareBiomeData(worlddir) self.chunklist = chunklist # In order to avoid having to look up the cache file names in # ChunkRenderer, get them all and store them here # TODO change how caching works for root, dirnames, filenames in os.walk(cachedir): for filename in filenames: if not filename.endswith('.png') or not filename.startswith( "img."): continue dirname, dir_b = os.path.split(root) _, dir_a = os.path.split(dirname) _, x, z, cave, _ = filename.split('.', 4) dir = '/'.join((dir_a, dir_b)) bits = '.'.join((x, z, cave)) cached[dir][bits] = os.path.join(root, filename) # stores Points Of Interest to be mapped with markers # a list of dictionaries, see below for an example self.POI = [] # if it exists, open overviewer.dat, and read in the data structure # info self.persistentData. This dictionary can hold any information # that may be needed between runs. # Currently only holds into about POIs (more more details, see quadtree) self.pickleFile = os.path.join(self.cachedir, "overviewer.dat") if os.path.exists(self.pickleFile): with open(self.pickleFile, "rb") as p: self.persistentData = cPickle.load(p) else: # some defaults self.persistentData = dict(POI=[])