aboutsummaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
Diffstat (limited to 'util')
-rw-r--r--util/colors.txt3
-rw-r--r--[-rwxr-xr-x]util/minetestmapper.py62
-rwxr-xr-xutil/sectors2sqlite.py25
3 files changed, 61 insertions, 29 deletions
diff --git a/util/colors.txt b/util/colors.txt
index b605a9e2e..2c350a826 100644
--- a/util/colors.txt
+++ b/util/colors.txt
@@ -24,7 +24,7 @@ f 128 79 0 # CONTENT_CHEST
80d 219 202 178 # CONTENT_MOSSYCOBBLE
80e 78 154 6 # CONTENT_GRAVEL
80f 204 0 0 # CONTENT_SANDSTONE
-810 211 215 207 # CONTENT_CACTUS
+810 0 215 0 # CONTENT_CACTUS
811 170 50 25 # CONTENT_BRICK
812 104 78 42 # CONTENT_CLAY
813 58 105 18 # CONTENT_PAPYRUS
@@ -33,3 +33,4 @@ f 128 79 0 # CONTENT_CHEST
816 62 101 25 # CONTENT_JUNGLEGRASS
817 255 153 255 # CONTENT_NC
818 102 50 255 # CONTENT_NC_RB
+819 200 0 0 # CONTENT_APPLE
diff --git a/util/minetestmapper.py b/util/minetestmapper.py
index c7ec0774e..a1f1e3473 100755..100644
--- a/util/minetestmapper.py
+++ b/util/minetestmapper.py
@@ -56,6 +56,25 @@ TRANSLATION_TABLE = {
28: 0x813, # CONTENT_PAPYRUS
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):
i = int(h, 16)
@@ -88,9 +107,19 @@ def int_to_hex4(i):
def getBlockAsInteger(p):
return p[2]*16777216 + p[1]*4096 + p[0]
-def getIntegerAsBlock(i):
- return i%4096, int(i/4096)%4096, int(i/16777216)%4096
+def unsignedToSigned(i, max_positive):
+ if i < max_positive:
+ return i
+ else:
+ return i - 2*max_positive
+def getIntegerAsBlock(i):
+ x = unsignedToSigned(i % 4096, 2048)
+ i = int((i - x) / 4096)
+ y = unsignedToSigned(i % 4096, 2048)
+ i = int((i - y) / 4096)
+ z = unsignedToSigned(i % 4096, 2048)
+ return x,y,z
def limit(i, l, h):
if(i > h):
@@ -160,9 +189,9 @@ if path[-1:] != "/" and path[-1:] != "\\":
# Load color information for the blocks.
colors = {}
try:
- f = file("colors.txt")
+ f = file("colors.txt")
except IOError:
- f = file(os.path.join(os.path.dirname(__file__), "colors.txt"))
+ f = file(os.path.join(os.path.dirname(__file__), "colors.txt"))
for line in f:
values = string.split(line)
colors[int(values[0], 16)] = (
@@ -190,7 +219,7 @@ if os.path.exists(path + "map.sqlite"):
if not r:
break
- x, y, z = getIntegerAsBlock (r[0])
+ x, y, z = getIntegerAsBlock(r[0])
if x < sector_xmin or x > sector_xmax:
continue
@@ -223,6 +252,9 @@ if os.path.exists(path + "sectors"):
xlist.append(x)
zlist.append(z)
+# Get rid of doubles
+xlist, zlist = zip(*sorted(set(zip(xlist, zlist))))
+
minx = min(xlist)
minz = min(zlist)
maxx = max(xlist)
@@ -372,7 +404,8 @@ for n in range(len(xlist)):
if sectortype == "":
continue
- ylist.sort()
+ #ylist.sort()
+ ylist = sorted(set(ylist))
# Make a list of pixels of the sector that are to be looked for.
pixellist = []
@@ -395,17 +428,14 @@ for n in range(len(xlist)):
r = cur.fetchone()
if not r:
continue
- filename = "mtm_tmp"
- f = file(filename, 'wb')
- f.write(r[0])
- f.close()
+ f = Bytestream(r[0])
else:
if sectortype == "old":
filename = path + "sectors/" + sector1 + "/" + yhex.lower()
else:
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.
version = ord(f.read(1))
@@ -431,12 +461,7 @@ for n in range(len(xlist)):
r = cur.fetchone()
if not r:
continue
- filename = "mtm_tmp"
- f = file(filename, 'wb')
- f.write(r[0])
- f.close()
-
- f = file(filename, "rb")
+ f = Bytestream(r[0])
version = ord(f.read(1))
flags = f.read(1)
@@ -557,8 +582,5 @@ if drawplayers:
except OSError:
pass
-if os.path.isfile("mtm_tmp"):
- os.remove("mtm_tmp")
-
print "Saving"
im.save(output)
diff --git a/util/sectors2sqlite.py b/util/sectors2sqlite.py
index 16ee7aae4..38261a498 100755
--- a/util/sectors2sqlite.py
+++ b/util/sectors2sqlite.py
@@ -3,7 +3,7 @@
# Loads block files from sectors folders into map.sqlite database.
# The sectors folder should be safe to remove after this prints "Finished."
-import time, os
+import time, os, sys
try:
import sqlite3
@@ -23,10 +23,14 @@ if os.path.isdir(path + 'sectors/'):
if not paths:
exit('Could not find sectors folder at ' + path + 'sectors2/ or ' + path + 'sectors/')
-def uint(u):
+def parseSigned12bit(u):
u = int('0x'+u, 16)
return (u if u < 2**11 else u - 2**12)
+def parseSigned16bit(u):
+ u = int('0x'+u, 16)
+ return (u if u < 2**15 else u - 2**16)
+
def int64(u):
while u >= 2**63:
u -= 2**64
@@ -38,12 +42,12 @@ def int64(u):
def getSectorPos(dirname):
if len(dirname) == 8:
# Old layout
- x = uint(dirname[:4])
- z = uint(dirname[4:])
+ x = parseSigned16bit(dirname[:4])
+ z = parseSigned16bit(dirname[4:])
elif len(dirname) == 7:
# New layout
- x = uint(dirname[:3])
- z = uint(dirname[4:])
+ x = parseSigned12bit(dirname[:3])
+ z = parseSigned12bit(dirname[4:])
else:
print('Terrible sector at ' + dirname)
return
@@ -60,7 +64,7 @@ def getBlockPos(sectordir, blockfile):
if len(blockfile) != 4:
print("Invalid block filename: " + blockfile)
- y = uint(blockfile)
+ y = parseSigned16bit(blockfile)
return p2d[0], y, p2d[1]
@@ -110,8 +114,13 @@ for base in paths:
continue
f = open(root+'/'+block, 'rb')
- cur.execute('INSERT OR IGNORE INTO `blocks` VALUES(?, ?)', (pos, f.read()))
+ blob = f.read()
f.close()
+ if sys.version_info.major == 2:
+ blob = buffer(blob)
+ else:
+ blob = memoryview(blob)
+ cur.execute('INSERT OR IGNORE INTO `blocks` VALUES(?, ?)', (pos, blob))
count += 1
if(time.time() - t > 3):