0

Merge branch 'direct-to-tiles' into dtt-c-render

This commit is contained in:
Aaron Griffith
2011-03-17 22:29:24 -04:00
2 changed files with 129 additions and 6 deletions

94
contrib/clearOldCache.py Normal file
View File

@@ -0,0 +1,94 @@
#!/usr/bin/python
usage = "python contrib/%prog [OPTIONS] <World # / Name / Path to World>"
description = """
This script will delete files from the old chunk-based cache, a lot
like the old `gmap.py -d World/` command. You should only use this if
you're updating from an older version of Overviewer, and you want to
clean up your world folder.
"""
from optparse import OptionParser
import sys
import re
import os.path
# sys.path wrangling, so we can access Overviewer code
overviewer_dir = os.path.split(os.path.split(os.path.abspath(__file__))[0])[0]
sys.path.insert(0, overviewer_dir)
import world
from gmap import list_worlds
def main():
parser = OptionParser(usage=usage, description=description)
parser.add_option("-d", "--dry-run", dest="dry", action="store_true",
help="Don't actually delete anything. Best used with -v.")
parser.add_option("-k", "--keep-dirs", dest="keep", action="store_true",
help="Keep the world directories intact, even if they are empty.")
parser.add_option("-v", "--verbose", dest="verbose", action="store_true",
help="Log each and every file that is deleted.")
opt, args = parser.parse_args()
if not len(args) == 1:
parser.print_help()
sys.exit(1)
worlddir = args[0]
if not os.path.exists(worlddir):
# world given is either world number, or name
worlds = world.get_worlds()
# if there are no worlds found at all, exit now
if not worlds:
parser.print_help()
print "\nInvalid world path"
sys.exit(1)
try:
worldnum = int(worlddir)
worlddir = worlds[worldnum]['path']
except ValueError:
# it wasn't a number or path, try using it as a name
try:
worlddir = worlds[worlddir]['path']
except KeyError:
# it's not a number, name, or path
parser.print_help()
print "Invalid world name or path"
sys.exit(1)
except KeyError:
# it was an invalid number
parser.print_help()
print "Invalid world number"
sys.exit(1)
files_deleted = 0
dirs_deleted = 0
imgre = re.compile(r'img\.[^.]+\.[^.]+\.nocave\.\w+\.png$')
for dirpath, dirnames, filenames in os.walk(worlddir, topdown=False):
for f in filenames:
if imgre.match(f):
filepath = os.path.join(dirpath, f)
if opt.verbose:
print "Deleting %s" % (filepath,)
if not opt.dry:
os.unlink(filepath)
files_deleted += 1
if not opt.keep:
if len(os.listdir(dirpath)) == 0:
if opt.verbose:
print "Deleting %s" % (dirpath,)
if not opt.dry:
os.rmdir(dirpath)
dirs_deleted += 1
print "%i files and %i directories deleted." % (files_deleted, dirs_deleted)
if __name__ == "__main__":
main()

View File

@@ -279,7 +279,7 @@ def _build_blockimages():
# 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 # 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
34, -1, 52, 48, 49,160,144, -1,176, 74, -1, -1, -1, -1, -1, -1, # Cloths are left out, sandstone (it has top, side, and bottom wich is ignored here), note block 34, -1, 52, 48, 49,160,144, -1,176, 74, -1, -1, -1, -1, -1, -1, # Cloths are left out, sandstone (it has top, side, and bottom wich is ignored here), note block
# 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 # 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
-1, -1, -1, -1, -1, 13, 12, 29, 28, 23, 22, 6, 6, 7, 8, 35, # Gold/iron blocks? Doublestep? TNT from above? -1, -1, -1, -1, -1, 13, 12, 29, 28, 23, 22, -1, -1, 7, 8, 35, # Gold/iron blocks? Doublestep? TNT from above?
# 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 # 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
36, 37, 80, -1, 65, 4, 25, -1, 98, 24, 43, -1, 86, -1, -1, -1, # Torch from above? leaving out fire. Redstone wire? Crops/furnaces handled elsewhere. sign post 36, 37, 80, -1, 65, 4, 25, -1, 98, 24, 43, -1, 86, -1, -1, -1, # Torch from above? leaving out fire. Redstone wire? Crops/furnaces handled elsewhere. sign post
# 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 # 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
@@ -296,7 +296,7 @@ def _build_blockimages():
# 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 # 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
34, -1, 52, 48, 49,160,144, -1,192, 74, -1, -1,- 1, -1, -1, -1, 34, -1, 52, 48, 49,160,144, -1,192, 74, -1, -1,- 1, -1, -1, -1,
# 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 # 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
-1, -1, -1, -1, -1, 13, 12, 29, 28, 23, 22, 5, 5, 7, 8, 35, -1, -1, -1, -1, -1, 13, 12, 29, 28, 23, 22, -1, -1, 7, 8, 35,
# 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 # 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
36, 37, 80, -1, 65, 4, 25,101, 98, 24, 43, -1, 86, -1, -1, -1, 36, 37, 80, -1, 65, 4, 25,101, 98, 24, 43, -1, 86, -1, -1, -1,
# 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 # 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
@@ -777,6 +777,30 @@ def generate_special_texture(blockID, data):
return (img.convert("RGB"),img.split()[3]) return (img.convert("RGB"),img.split()[3])
if blockID in (43,44): # slab and double-slab
if data == 0: # stone slab
top = terrain_images[6]
side = terrain_images[5]
img = _build_block(top, side, blockID)
return (img.convert("RGB"), img.split()[3])
if data == 1: # stone slab
top = terrain_images[176]
side = terrain_images[192]
img = _build_block(top, side, blockID)
return (img.convert("RGB"), img.split()[3])
if data == 2: # wooden slab
top = side = terrain_images[4]
img = _build_block(top, side, blockID)
return (img.convert("RGB"), img.split()[3])
if data == 3: # cobblestone slab
top = side = terrain_images[16]
img = _build_block(top, side, blockID)
return (img.convert("RGB"), img.split()[3])
return None return None
def tintTexture(im, c): def tintTexture(im, c):
@@ -854,21 +878,24 @@ def getBiomeData(worlddir, chunkX, chunkY):
if biomeFile == currentBiomeFile: if biomeFile == currentBiomeFile:
return currentBiomeData return currentBiomeData
currentBiomeFile = biomeFile
f = open(os.path.join(worlddir, "biomes", biomeFile), "rb") f = open(os.path.join(worlddir, "biomes", biomeFile), "rb")
rawdata = f.read() rawdata = f.read()
f.close() f.close()
# make sure the file size is correct
if not len(rawdata) == 512 * 512 * 2:
raise Exception("Biome file %s is not valid." % (biomeFile,))
data = numpy.frombuffer(rawdata, dtype=numpy.dtype(">u2")) data = numpy.frombuffer(rawdata, dtype=numpy.dtype(">u2"))
currentBiomeFile = biomeFile
currentBiomeData = data currentBiomeData = data
return data return data
# This set holds block ids that require special pre-computing. These are typically # This set holds block ids that require special pre-computing. These are typically
# things that require ancillary data to render properly (i.e. ladder plus orientation) # things that require ancillary data to render properly (i.e. ladder plus orientation)
special_blocks = set([66,59,61,62, 65,64,71,91,86,2,18,85,17,23,35,51]) special_blocks = set([66,59,61,62, 65,64,71,91,86,2,18,85,17,23,35,51,43,44])
# this is a map of special blockIDs to a list of all # this is a map of special blockIDs to a list of all
# possible values for ancillary data that it might have. # possible values for ancillary data that it might have.
@@ -887,6 +914,8 @@ special_map[17] = range(4) # wood: normal, birch and pine
special_map[23] = range(6) # dispensers special_map[23] = range(6) # dispensers
special_map[35] = range(16) # wool, colored and white special_map[35] = range(16) # wool, colored and white
special_map[51] = range(16) # fire special_map[51] = range(16) # fire
special_map[43] = range(4) # stone, sandstone, wooden and cobblestone double-slab
special_map[44] = range(4) # stone, sandstone, wooden and cobblestone slab
# apparently pumpkins and jack-o-lanterns have ancillary data, but it's unknown # apparently pumpkins and jack-o-lanterns have ancillary data, but it's unknown
# what that data represents. For now, assume that the range for data is 0 to 5 # what that data represents. For now, assume that the range for data is 0 to 5