summaryrefslogtreecommitdiff
path: root/utilities
diff options
context:
space:
mode:
authorKris Parker2009-12-12 15:24:01 +0000
committerKris Parker2009-12-12 15:24:01 +0000
commitca61395a22bf8b717797aaf63f6ecaf97c6faf2a (patch)
treedd8145c346a07bf3c7bf6a4f7df534fbbad54b72 /utilities
parent830dd362b8445f9d15d191f6cc9aa5267b86500c (diff)
downloadstonesense-ca61395a22bf8b717797aaf63f6ecaf97c6faf2a.tar.gz
stonesense-ca61395a22bf8b717797aaf63f6ecaf97c6faf2a.tar.bz2
stonesense-ca61395a22bf8b717797aaf63f6ecaf97c6faf2a.tar.xz
Trunking the RampBLUT
Diffstat (limited to 'utilities')
-rw-r--r--utilities/blutmaker.py262
1 files changed, 262 insertions, 0 deletions
diff --git a/utilities/blutmaker.py b/utilities/blutmaker.py
new file mode 100644
index 0000000..87696c5
--- /dev/null
+++ b/utilities/blutmaker.py
@@ -0,0 +1,262 @@
+#!/usr/bin/env python
+
+dirs = (
+ (1,"N "),
+ (2,"NE"),
+ (4,"E "),
+ (8,"SE"),
+ (16,"S "),
+ (32,"SW"),
+ (64,"W "),
+ (128,"NW ")
+)
+
+n=1
+ne=2
+e=4
+se=8
+s=16
+sw=32
+w=64
+nw=128
+
+# mapping of basic wall configurations to outputs
+maps = [
+ (0,0),
+ (n,n+ne+nw),
+ (ne,ne),
+ (n+ne,n+ne+nw),
+ (n+e,nw+n+ne+e+se),
+ (n+ne+e,nw+n+ne+e+se),
+ (n+se,n+ne+nw),
+ (ne+se,ne+se),
+ (n+ne+se,nw+n+ne),
+ (n+e+se,nw+n+ne+e+se),
+ (ne+e+se,ne+e+se),
+ (n+ne+e+se,nw+n+ne+e+se),
+ (n+s,nw+n+ne+se+s+sw),
+ (n+ne+s,nw+n+ne+se+s+sw),
+ (n+e+s,nw+n+ne+e+se),
+ (n+ne+e+s,nw+n+ne+e+se),
+ (n+ne+se+s,nw+n+ne+se+s+sw),
+ (n+ne+e+se+s,nw+n+ne+se+s+sw),
+ (ne+sw,ne+sw),
+ (n+ne+sw,nw+n+ne),
+ (n+e+sw,nw+n+ne+e+se),
+ (n+ne+e+sw,nw+n+ne+e+se),
+ (n+se+sw,nw+ne+sw+se),
+ (ne+se+sw,ne+se+sw),
+ (n+ne+se+sw,nw+ne+se+sw),
+ (n+e+se+sw,nw+n+ne+e+se),
+ (ne+e+se+sw,ne+e+se),
+ (n+ne+e+se+sw,nw+n+ne+e+se),
+ (n+ne+s+sw,nw+n+ne+se+s+sw),
+ (n+e+s+sw,nw+n+ne+se+s+sw),
+ (ne+e+s+sw,ne+e+se+s+sw),
+ (n+ne+e+s+sw,nw+n+ne+se+s+sw),
+ (n+se+s+sw,nw+n+ne+se+s+sw),
+ (n+ne+se+s+sw,nw+n+ne+se+s+sw),
+ (n+e+se+s+sw,nw+n+ne+se+s+sw),
+ (ne+e+se+s+sw,ne+e+se+s+sw),
+ (n+ne+e+se+s+sw,nw+n+ne+se+s+sw),
+ (n+e+s+w,nw+ne+se+sw),
+ (n+ne+e+s+w,nw+n+ne+e+se),
+ (n+ne+se+s+w,nw+n+ne+se+s+sw),
+ (n+ne+e+se+s+w,nw+n+ne+se+s+sw),
+ (n+ne+se+sw+w,nw+n+ne+sw+w),
+ (n+ne+e+se+sw+w,nw+w+sw+se+e+ne),
+ (n+ne+e+s+sw+w,ne+sw),
+ (n+ne+e+se+s+sw+w,ne+e+se+s+sw),
+ (ne+se+sw+nw,nw+ne+se+sw),
+ (n+nw+ne+se+sw,nw+ne+se+sw),
+ (nw+n+ne+e+se+sw,nw+n+ne+e+se),
+ (nw+n+ne+se+s+sw,nw+n+ne+se+s+sw),
+ (nw+n+ne+e+se+s+sw,nw+n+ne+se+s+sw),
+ (nw+n+ne+e+se+s+sw+w,nw+ne+se+sw),
+]
+
+outs = [
+]
+
+sprites = [
+]
+
+# rotation/mirror equivalence table
+remaps = (
+ (0,1,2,3,4,5,6,7),
+ (6,7,0,1,2,3,4,5),
+ (4,5,6,7,0,1,2,3),
+ (2,3,4,5,6,7,0,1),
+ (0,7,6,5,4,3,2,1),
+ (2,1,0,7,6,5,4,3),
+ (4,3,2,1,0,7,6,5),
+ (6,5,4,3,2,1,0,7)
+)
+
+# binary to sprite index mapping
+spriteindexes = [
+ (0,1),
+ (2,8),
+ (8,9),
+ (10,21),
+ (14,4),
+ (32,7),
+ (34,14),
+ (40,20),
+ (42,25),
+ (56,5),
+ (62,13),
+ (128,6),
+ (130,19),
+ (131,2),
+ (136,15),
+ (138,24),
+ (143,12),
+ (160,18),
+ (162,22),
+ (168,23),
+ (170,26),
+ (187,16),
+ (224,3),
+ (227,10),
+ (238,17),
+ (248,11)
+]
+
+def newvalue(input, list) :
+ nv = 0
+ for x in (0,1,2,3,4,5,6,7) :
+ if ( input & (dirs[x])[0] ):
+ nv = nv + (dirs[list[x]])[0]
+ return nv
+
+# find any rotated or mirrored equivalents
+def doremap(input, output) :
+ for x in (0,1,2,3,4,5,6,7) :
+ newin = newvalue(input,remaps[x])
+ newout = newvalue(output,remaps[x])
+ outs[newin]=newout
+
+def tog(dat,map) :
+ if (dat&dirs[map][0]) :
+ return "#"
+ else :
+ return "."
+
+# print value as list of direction components
+def listDirs(value) :
+ for elem in dirs :
+ if ( elem[0] & value ) :
+ print elem[1],
+ else :
+ print " ",
+ print
+
+i=0
+while i<256 :
+ outs.insert(0,-1)
+ sprites.insert(0,0)
+ i=i+1
+
+i=-1
+while i<255 :
+ i = i+1
+
+ domap = False
+ finelem = -1
+ if (outs[i] != -1) :
+ finelem = outs[i]
+ else :
+ for map in maps :
+ if (map[0] == i) :
+ finelem = map[1]
+ domap = True
+ break
+
+ if ( finelem > -1 ) :
+ if domap:
+ doremap(i,finelem)
+ print
+ print "-----"
+ print
+ print "from",i
+ listDirs(i)
+ print
+ print tog(i,7)," ",tog(i,0)," ",tog(i,1)
+ print " ",tog(finelem,7),tog(finelem,0),tog(finelem,1)
+ print tog(i,6),tog(finelem,6)," ",tog(finelem,2),tog(i,2)
+ print " ",tog(finelem,5),tog(finelem,4),tog(finelem,3)
+ print tog(i,5)," ",tog(i,4)," ",tog(i,3)
+ print
+ else :
+ print "-----"
+ print i, "missing!"
+ print tog(i,7),tog(i,0),tog(i,1)
+ print tog(i,6)," ",tog(i,2)
+ print tog(i,5),tog(i,4),tog(i,3)
+ listDirs(i)
+ break
+
+print
+print "========"
+print
+print "sprite list"
+print
+
+for sprite in outs :
+ sprites[sprite] = 1
+
+i=-1
+total = 0
+while (i<255) :
+ i=i+1
+ if (sprites[i] == 0) :
+ continue
+ total = total + 1
+ print i,":"
+ print tog(i,7),tog(i,0),tog(i,1)
+ print tog(i,6),"*",tog(i,2)
+ print tog(i,5),tog(i,4),tog(i,3)
+ print
+print 1,"..",total
+print
+print "========"
+print
+print "raw output"
+
+print outs
+print
+
+print "========"
+
+print
+print "// generated by blutmaker.py"
+print "{",
+comma = 0
+looper = 0
+for outval in outs :
+ outmapped = 0
+ for indexmap in spriteindexes :
+ if (indexmap[0] == outval) :
+ if comma :
+ print ",",
+ if (looper == 0) :
+ print
+ print "\t",
+ looper = 16
+ looper = looper - 1
+ if ( indexmap[1] < 10 ):
+ print "",
+ print indexmap[1],
+ comma = 1
+ outmapped = 1
+ break
+ if (outmapped == 0) :
+ print "missing:", outval
+ break
+print
+print "};"
+print
+print "======="
+
+ \ No newline at end of file