forked from Mirrorlandia_minetest/minetest
minetestmapper speed tweaks (kahrl & JacobF)
This commit is contained in:
parent
3ca847b4e1
commit
08ac3454cc
42
util/minetestmapper.py
Executable file → Normal file
42
util/minetestmapper.py
Executable file → Normal file
@ -56,6 +56,25 @@ TRANSLATION_TABLE = {
|
|||||||
28: 0x813, # CONTENT_PAPYRUS
|
28: 0x813, # CONTENT_PAPYRUS
|
||||||
29: 0x814} # CONTENT_BOOKSHELF
|
29: 0x814} # CONTENT_BOOKSHELF
|
||||||
|
|
||||||
|
class Bytestream:
|
||||||
|
def __init__(self, stream):
|
||||||
|
self.stream = stream
|
||||||
|
self.pos = 0
|
||||||
|
|
||||||
|
# So you can use files also
|
||||||
|
if hasattr(self.stream, 'read'):
|
||||||
|
self.read = self.stream.read
|
||||||
|
|
||||||
|
def __len__(self):
|
||||||
|
return len(self.stream)
|
||||||
|
|
||||||
|
def read(self, length = None):
|
||||||
|
if length is None:
|
||||||
|
length = len(self)
|
||||||
|
self.pos += length
|
||||||
|
return self.stream[self.pos - length:self.pos]
|
||||||
|
|
||||||
|
def close(self): pass
|
||||||
|
|
||||||
def hex_to_int(h):
|
def hex_to_int(h):
|
||||||
i = int(h, 16)
|
i = int(h, 16)
|
||||||
@ -200,7 +219,7 @@ if os.path.exists(path + "map.sqlite"):
|
|||||||
if not r:
|
if not r:
|
||||||
break
|
break
|
||||||
|
|
||||||
x, y, z = getIntegerAsBlock (r[0])
|
x, y, z = getIntegerAsBlock(r[0])
|
||||||
|
|
||||||
if x < sector_xmin or x > sector_xmax:
|
if x < sector_xmin or x > sector_xmax:
|
||||||
continue
|
continue
|
||||||
@ -233,6 +252,9 @@ if os.path.exists(path + "sectors"):
|
|||||||
xlist.append(x)
|
xlist.append(x)
|
||||||
zlist.append(z)
|
zlist.append(z)
|
||||||
|
|
||||||
|
# Get rid of doubles
|
||||||
|
xlist, zlist = zip(*sorted(set(zip(xlist, zlist))))
|
||||||
|
|
||||||
minx = min(xlist)
|
minx = min(xlist)
|
||||||
minz = min(zlist)
|
minz = min(zlist)
|
||||||
maxx = max(xlist)
|
maxx = max(xlist)
|
||||||
@ -382,7 +404,8 @@ for n in range(len(xlist)):
|
|||||||
if sectortype == "":
|
if sectortype == "":
|
||||||
continue
|
continue
|
||||||
|
|
||||||
ylist.sort()
|
#ylist.sort()
|
||||||
|
ylist = sorted(set(ylist))
|
||||||
|
|
||||||
# Make a list of pixels of the sector that are to be looked for.
|
# Make a list of pixels of the sector that are to be looked for.
|
||||||
pixellist = []
|
pixellist = []
|
||||||
@ -405,10 +428,7 @@ for n in range(len(xlist)):
|
|||||||
r = cur.fetchone()
|
r = cur.fetchone()
|
||||||
if not r:
|
if not r:
|
||||||
continue
|
continue
|
||||||
filename = "mtm_tmp"
|
f = Bytestream(r[0])
|
||||||
f = file(filename, 'wb')
|
|
||||||
f.write(r[0])
|
|
||||||
f.close()
|
|
||||||
else:
|
else:
|
||||||
if sectortype == "old":
|
if sectortype == "old":
|
||||||
filename = path + "sectors/" + sector1 + "/" + yhex.lower()
|
filename = path + "sectors/" + sector1 + "/" + yhex.lower()
|
||||||
@ -441,12 +461,7 @@ for n in range(len(xlist)):
|
|||||||
r = cur.fetchone()
|
r = cur.fetchone()
|
||||||
if not r:
|
if not r:
|
||||||
continue
|
continue
|
||||||
filename = "mtm_tmp"
|
f = Bytestream(r[0])
|
||||||
f = file(filename, 'wb')
|
|
||||||
f.write(r[0])
|
|
||||||
f.close()
|
|
||||||
|
|
||||||
f = file(filename, "rb")
|
|
||||||
|
|
||||||
version = ord(f.read(1))
|
version = ord(f.read(1))
|
||||||
flags = f.read(1)
|
flags = f.read(1)
|
||||||
@ -567,8 +582,5 @@ if drawplayers:
|
|||||||
except OSError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if os.path.isfile("mtm_tmp"):
|
|
||||||
os.remove("mtm_tmp")
|
|
||||||
|
|
||||||
print "Saving"
|
print "Saving"
|
||||||
im.save(output)
|
im.save(output)
|
||||||
|
Loading…
Reference in New Issue
Block a user