mirror of
https://github.com/minetest/minetest.git
synced 2024-11-24 08:33:46 +01:00
* tabs to spaces
This commit is contained in:
parent
33264d0fb6
commit
de8996ac3b
@ -22,35 +22,35 @@ import string
|
|||||||
import time
|
import time
|
||||||
|
|
||||||
def hex_to_int(h):
|
def hex_to_int(h):
|
||||||
i = int(h,16)
|
i = int(h,16)
|
||||||
if(i > 2047):
|
if(i > 2047):
|
||||||
i-=4096
|
i-=4096
|
||||||
return i
|
return i
|
||||||
|
|
||||||
def hex4_to_int(h):
|
def hex4_to_int(h):
|
||||||
i = int(h,16)
|
i = int(h,16)
|
||||||
if(i > 32767):
|
if(i > 32767):
|
||||||
i-=65536
|
i-=65536
|
||||||
return i
|
return i
|
||||||
|
|
||||||
def int_to_hex3(i):
|
def int_to_hex3(i):
|
||||||
if(i < 0):
|
if(i < 0):
|
||||||
return "%03X" % (i + 4096)
|
return "%03X" % (i + 4096)
|
||||||
else:
|
else:
|
||||||
return "%03X" % i
|
return "%03X" % i
|
||||||
|
|
||||||
def int_to_hex4(i):
|
def int_to_hex4(i):
|
||||||
if(i < 0):
|
if(i < 0):
|
||||||
return "%04X" % (i + 65536)
|
return "%04X" % (i + 65536)
|
||||||
else:
|
else:
|
||||||
return "%04X" % i
|
return "%04X" % i
|
||||||
|
|
||||||
def limit(i,l,h):
|
def limit(i,l,h):
|
||||||
if(i>h):
|
if(i>h):
|
||||||
i=h
|
i=h
|
||||||
if(i<l):
|
if(i<l):
|
||||||
i=l
|
i=l
|
||||||
return i
|
return i
|
||||||
|
|
||||||
# Fix these!
|
# Fix these!
|
||||||
path="../map/"
|
path="../map/"
|
||||||
@ -65,8 +65,8 @@ sector_zmax = 1000/16
|
|||||||
colors = {}
|
colors = {}
|
||||||
f = file("colors.txt")
|
f = file("colors.txt")
|
||||||
for line in f:
|
for line in f:
|
||||||
values = string.split(line)
|
values = string.split(line)
|
||||||
colors[int(values[0])] = (int(values[1]), int(values[2]), int(values[3]))
|
colors[int(values[0])] = (int(values[1]), int(values[2]), int(values[3]))
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
xlist = []
|
xlist = []
|
||||||
@ -74,24 +74,24 @@ zlist = []
|
|||||||
|
|
||||||
# List all sectors to memory and calculate the width and heigth of the resulting picture.
|
# List all sectors to memory and calculate the width and heigth of the resulting picture.
|
||||||
for filename in os.listdir(path + "sectors2"):
|
for filename in os.listdir(path + "sectors2"):
|
||||||
for filename2 in os.listdir(path + "sectors2/" + filename):
|
for filename2 in os.listdir(path + "sectors2/" + filename):
|
||||||
x = hex_to_int(filename)
|
x = hex_to_int(filename)
|
||||||
z = hex_to_int(filename2)
|
z = hex_to_int(filename2)
|
||||||
if x < sector_xmin or x > sector_xmax:
|
if x < sector_xmin or x > sector_xmax:
|
||||||
continue
|
continue
|
||||||
if z < sector_zmin or z > sector_zmax:
|
if z < sector_zmin or z > sector_zmax:
|
||||||
continue
|
continue
|
||||||
xlist.append(x)
|
xlist.append(x)
|
||||||
zlist.append(z)
|
zlist.append(z)
|
||||||
for filename in os.listdir(path + "sectors"):
|
for filename in os.listdir(path + "sectors"):
|
||||||
x = hex4_to_int(filename[:4])
|
x = hex4_to_int(filename[:4])
|
||||||
z = hex4_to_int(filename[-4:])
|
z = hex4_to_int(filename[-4:])
|
||||||
if x < sector_xmin or x > sector_xmax:
|
if x < sector_xmin or x > sector_xmax:
|
||||||
continue
|
continue
|
||||||
if z < sector_zmin or z > sector_zmax:
|
if z < sector_zmin or z > sector_zmax:
|
||||||
continue
|
continue
|
||||||
xlist.append(x)
|
xlist.append(x)
|
||||||
zlist.append(z)
|
zlist.append(z)
|
||||||
|
|
||||||
w = (max(xlist) - min(xlist)) * 16 + 16
|
w = (max(xlist) - min(xlist)) * 16 + 16
|
||||||
h = (max(zlist) - min(zlist)) * 16 + 16
|
h = (max(zlist) - min(zlist)) * 16 + 16
|
||||||
@ -107,118 +107,118 @@ starttime = time.time()
|
|||||||
|
|
||||||
# Go through all sectors.
|
# Go through all sectors.
|
||||||
for n in range(len(xlist)):
|
for n in range(len(xlist)):
|
||||||
#if n > 500:
|
#if n > 500:
|
||||||
# break
|
# break
|
||||||
if n % 200 == 0:
|
if n % 200 == 0:
|
||||||
nowtime = time.time()
|
nowtime = time.time()
|
||||||
dtime = nowtime - starttime
|
dtime = nowtime - starttime
|
||||||
n_per_second = 1.0 * n / dtime
|
n_per_second = 1.0 * n / dtime
|
||||||
if n_per_second != 0:
|
if n_per_second != 0:
|
||||||
seconds_per_n = 1.0 / n_per_second
|
seconds_per_n = 1.0 / n_per_second
|
||||||
time_guess = seconds_per_n * len(xlist)
|
time_guess = seconds_per_n * len(xlist)
|
||||||
remaining_s = time_guess - dtime
|
remaining_s = time_guess - dtime
|
||||||
remaining_minutes = int(remaining_s / 60)
|
remaining_minutes = int(remaining_s / 60)
|
||||||
remaining_s -= remaining_minutes * 60;
|
remaining_s -= remaining_minutes * 60;
|
||||||
print("Processing sector "+str(n)+" of "+str(len(xlist))
|
print("Processing sector "+str(n)+" of "+str(len(xlist))
|
||||||
+" ("+str(round(100.0*n/len(xlist), 1))+"%)"
|
+" ("+str(round(100.0*n/len(xlist), 1))+"%)"
|
||||||
+" (ETA: "+str(remaining_minutes)+"m "
|
+" (ETA: "+str(remaining_minutes)+"m "
|
||||||
+str(int(remaining_s))+"s)")
|
+str(int(remaining_s))+"s)")
|
||||||
|
|
||||||
xpos = xlist[n]
|
xpos = xlist[n]
|
||||||
zpos = zlist[n]
|
zpos = zlist[n]
|
||||||
|
|
||||||
xhex = int_to_hex3(xpos)
|
xhex = int_to_hex3(xpos)
|
||||||
zhex = int_to_hex3(zpos)
|
zhex = int_to_hex3(zpos)
|
||||||
xhex4 = int_to_hex4(xpos)
|
xhex4 = int_to_hex4(xpos)
|
||||||
zhex4 = int_to_hex4(zpos)
|
zhex4 = int_to_hex4(zpos)
|
||||||
|
|
||||||
sector1 = xhex4.lower() + zhex4.lower()
|
sector1 = xhex4.lower() + zhex4.lower()
|
||||||
sector2 = xhex.lower() + "/" + zhex.lower()
|
sector2 = xhex.lower() + "/" + zhex.lower()
|
||||||
|
|
||||||
ylist=[]
|
ylist=[]
|
||||||
|
|
||||||
sectortype = ""
|
sectortype = ""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
for filename in os.listdir(path + "sectors/" + sector1):
|
for filename in os.listdir(path + "sectors/" + sector1):
|
||||||
if(filename != "meta"):
|
if(filename != "meta"):
|
||||||
pos = int(filename,16)
|
pos = int(filename,16)
|
||||||
if(pos > 32767):
|
if(pos > 32767):
|
||||||
pos-=65536
|
pos-=65536
|
||||||
ylist.append(pos)
|
ylist.append(pos)
|
||||||
sectortype = "old"
|
sectortype = "old"
|
||||||
except OSError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if sectortype != "old":
|
if sectortype != "old":
|
||||||
try:
|
try:
|
||||||
for filename in os.listdir(path + "sectors2/" + sector2):
|
for filename in os.listdir(path + "sectors2/" + sector2):
|
||||||
if(filename != "meta"):
|
if(filename != "meta"):
|
||||||
pos = int(filename,16)
|
pos = int(filename,16)
|
||||||
if(pos > 32767):
|
if(pos > 32767):
|
||||||
pos-=65536
|
pos-=65536
|
||||||
ylist.append(pos)
|
ylist.append(pos)
|
||||||
sectortype = "new"
|
sectortype = "new"
|
||||||
except OSError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if sectortype == "":
|
if sectortype == "":
|
||||||
continue
|
continue
|
||||||
|
|
||||||
ylist.sort()
|
ylist.sort()
|
||||||
|
|
||||||
# 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 = []
|
||||||
for x in range(16):
|
for x in range(16):
|
||||||
for y in range(16):
|
for y in range(16):
|
||||||
pixellist.append((x,y))
|
pixellist.append((x,y))
|
||||||
|
|
||||||
# Go through the Y axis from top to bottom.
|
# Go through the Y axis from top to bottom.
|
||||||
for ypos in reversed(ylist):
|
for ypos in reversed(ylist):
|
||||||
|
|
||||||
yhex = int_to_hex4(ypos)
|
yhex = int_to_hex4(ypos)
|
||||||
|
|
||||||
filename = ""
|
filename = ""
|
||||||
if sectortype == "old":
|
if sectortype == "old":
|
||||||
filename = path + "sectors/" + sector1 + "/" + yhex.lower()
|
filename = path + "sectors/" + sector1 + "/" + yhex.lower()
|
||||||
else:
|
else:
|
||||||
filename = path + "sectors2/" + sector2 + "/" + yhex.lower()
|
filename = path + "sectors2/" + sector2 + "/" + yhex.lower()
|
||||||
|
|
||||||
f = file(filename, "rb")
|
f = file(filename, "rb")
|
||||||
|
|
||||||
# Let's just memorize these even though it's not really necessary.
|
# Let's just memorize these even though it's not really necessary.
|
||||||
version = f.read(1)
|
version = f.read(1)
|
||||||
flags = f.read(1)
|
flags = f.read(1)
|
||||||
|
|
||||||
dec_o = zlib.decompressobj()
|
dec_o = zlib.decompressobj()
|
||||||
try:
|
try:
|
||||||
mapdata = dec_o.decompress(f.read())
|
mapdata = dec_o.decompress(f.read())
|
||||||
except:
|
except:
|
||||||
mapdata = []
|
mapdata = []
|
||||||
|
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
if(len(mapdata)<4096):
|
if(len(mapdata)<4096):
|
||||||
print "bad: " + xhex+zhex+"/"+yhex + " " + len(mapdata)
|
print "bad: " + xhex+zhex+"/"+yhex + " " + len(mapdata)
|
||||||
else:
|
else:
|
||||||
chunkxpos=xpos*16
|
chunkxpos=xpos*16
|
||||||
chunkypos=ypos*16
|
chunkypos=ypos*16
|
||||||
chunkzpos=zpos*16
|
chunkzpos=zpos*16
|
||||||
for (x,z) in reversed(pixellist):
|
for (x,z) in reversed(pixellist):
|
||||||
for y in reversed(range(16)):
|
for y in reversed(range(16)):
|
||||||
datapos=x+y*16+z*256
|
datapos=x+y*16+z*256
|
||||||
if(ord(mapdata[datapos])!=254):
|
if(ord(mapdata[datapos])!=254):
|
||||||
try:
|
try:
|
||||||
pixellist.remove((x,z))
|
pixellist.remove((x,z))
|
||||||
# Memorize information on the type and height of the block and for drawing the picture.
|
# Memorize information on the type and height of the block and for drawing the picture.
|
||||||
stuff[(chunkxpos+x,chunkzpos+z)]=(chunkypos+y,ord(mapdata[datapos]))
|
stuff[(chunkxpos+x,chunkzpos+z)]=(chunkypos+y,ord(mapdata[datapos]))
|
||||||
break
|
break
|
||||||
except:
|
except:
|
||||||
print "strange block: " + xhex+zhex+"/"+yhex + " x: " + str(x) + " y: " + str(y) + " z: " + str(z) + " block: " + str(ord(mapdata[datapos]))
|
print "strange block: " + xhex+zhex+"/"+yhex + " x: " + str(x) + " y: " + str(y) + " z: " + str(z) + " block: " + str(ord(mapdata[datapos]))
|
||||||
|
|
||||||
# After finding all the pixeld in the sector, we can move on to the next sector without having to continue the Y axis.
|
# After finding all the pixeld in the sector, we can move on to the next sector without having to continue the Y axis.
|
||||||
if(len(pixellist)==0):
|
if(len(pixellist)==0):
|
||||||
break
|
break
|
||||||
|
|
||||||
print "Drawing image"
|
print "Drawing image"
|
||||||
# Drawing the picture
|
# Drawing the picture
|
||||||
@ -227,43 +227,43 @@ n = 0
|
|||||||
minx = min(xlist)
|
minx = min(xlist)
|
||||||
minz = min(zlist)
|
minz = min(zlist)
|
||||||
for (x,z) in stuff.iterkeys():
|
for (x,z) in stuff.iterkeys():
|
||||||
if n % 500000 == 0:
|
if n % 500000 == 0:
|
||||||
nowtime = time.time()
|
nowtime = time.time()
|
||||||
dtime = nowtime - starttime
|
dtime = nowtime - starttime
|
||||||
n_per_second = 1.0 * n / dtime
|
n_per_second = 1.0 * n / dtime
|
||||||
if n_per_second != 0:
|
if n_per_second != 0:
|
||||||
listlen = len(stuff)
|
listlen = len(stuff)
|
||||||
seconds_per_n = 1.0 / n_per_second
|
seconds_per_n = 1.0 / n_per_second
|
||||||
time_guess = seconds_per_n * listlen
|
time_guess = seconds_per_n * listlen
|
||||||
remaining_s = time_guess - dtime
|
remaining_s = time_guess - dtime
|
||||||
remaining_minutes = int(remaining_s / 60)
|
remaining_minutes = int(remaining_s / 60)
|
||||||
remaining_s -= remaining_minutes * 60;
|
remaining_s -= remaining_minutes * 60;
|
||||||
print("Drawing pixel "+str(n)+" of "+str(listlen)
|
print("Drawing pixel "+str(n)+" of "+str(listlen)
|
||||||
+" ("+str(round(100.0*n/listlen, 1))+"%)"
|
+" ("+str(round(100.0*n/listlen, 1))+"%)"
|
||||||
+" (ETA: "+str(remaining_minutes)+"m "
|
+" (ETA: "+str(remaining_minutes)+"m "
|
||||||
+str(int(remaining_s))+"s)")
|
+str(int(remaining_s))+"s)")
|
||||||
n += 1
|
n += 1
|
||||||
|
|
||||||
(r,g,b)=colors[stuff[(x,z)][1]]
|
(r,g,b)=colors[stuff[(x,z)][1]]
|
||||||
|
|
||||||
# Comparing heights of a couple of adjacent blocks and changing brightness accordingly.
|
# Comparing heights of a couple of adjacent blocks and changing brightness accordingly.
|
||||||
try:
|
try:
|
||||||
y1=stuff[(x-1,z)][0]
|
y1=stuff[(x-1,z)][0]
|
||||||
y2=stuff[(x,z-1)][0]
|
y2=stuff[(x,z-1)][0]
|
||||||
y=stuff[(x,z)][0]
|
y=stuff[(x,z)][0]
|
||||||
|
|
||||||
d=(y-y1+y-y2)*12
|
d=(y-y1+y-y2)*12
|
||||||
|
|
||||||
if(d>36):
|
if(d>36):
|
||||||
d=36
|
d=36
|
||||||
|
|
||||||
r=limit(r+d,0,255)
|
r=limit(r+d,0,255)
|
||||||
g=limit(g+d,0,255)
|
g=limit(g+d,0,255)
|
||||||
b=limit(b+d,0,255)
|
b=limit(b+d,0,255)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
#impix[w-1-(x-minx*16),h-1-(z-minz*16)]=(r,g,b)
|
#impix[w-1-(x-minx*16),h-1-(z-minz*16)]=(r,g,b)
|
||||||
impix[x-minx*16,h-1-(z-minz*16)]=(r,g,b)
|
impix[x-minx*16,h-1-(z-minz*16)]=(r,g,b)
|
||||||
|
|
||||||
# Flip the picture to make it right and save.
|
# Flip the picture to make it right and save.
|
||||||
#print "Transposing"
|
#print "Transposing"
|
||||||
|
Loading…
Reference in New Issue
Block a user