|
|
@@ -1,4 +1,4 @@
|
|
|
-#!/usr/bin/env python
|
|
|
+#!/usr/bin/env python3
|
|
|
""" This simple Python script can be run to generate
|
|
|
ztriangle_code_*.h, ztriangle_table.*, and ztriangle_*.cxx, which
|
|
|
are a poor man's form of generated code to cover the explosion of
|
|
|
@@ -34,6 +34,7 @@ Options = [
|
|
|
]
|
|
|
|
|
|
# The total number of different combinations of the various Options, above.
|
|
|
+from functools import reduce
|
|
|
OptionsCount = reduce(lambda a, b: a * b, map(lambda o: len(o), Options))
|
|
|
|
|
|
# The various combinations of these options are explicit within
|
|
|
@@ -99,7 +100,7 @@ ZTriangleStub = """
|
|
|
"""
|
|
|
ops = [0] * len(Options)
|
|
|
|
|
|
-class DoneException:
|
|
|
+class DoneException(Exception):
|
|
|
pass
|
|
|
|
|
|
# We write the code that actually instantiates the various
|
|
|
@@ -148,11 +149,11 @@ def getFref(ops):
|
|
|
def closeCode():
|
|
|
""" Close the previously-opened code file. """
|
|
|
if code:
|
|
|
- print >> code, ''
|
|
|
- print >> code, 'ZB_fillTriangleFunc ztriangle_code_%s[%s] = {' % (codeSeg, len(fnameList))
|
|
|
+ print('', file=code)
|
|
|
+ print('ZB_fillTriangleFunc ztriangle_code_%s[%s] = {' % (codeSeg, len(fnameList)), file=code)
|
|
|
for fname in fnameList:
|
|
|
- print >> code, ' %s,' % (fname)
|
|
|
- print >> code, '};'
|
|
|
+ print(' %s,' % (fname), file=code)
|
|
|
+ print('};', file=code)
|
|
|
code.close()
|
|
|
|
|
|
|
|
|
@@ -173,13 +174,13 @@ def openCode(count):
|
|
|
fnameList = []
|
|
|
|
|
|
# Open a new file.
|
|
|
- code = open('ztriangle_code_%s.h' % (codeSeg), 'wb')
|
|
|
- print >> code, '/* This file is generated code--do not edit. See ztriangle.py. */'
|
|
|
- print >> code, ''
|
|
|
+ code = open('ztriangle_code_%s.h' % (codeSeg), 'w')
|
|
|
+ print('/* This file is generated code--do not edit. See ztriangle.py. */', file=code)
|
|
|
+ print('', file=code)
|
|
|
|
|
|
# Also generate ztriangle_*.cxx, to include the above file.
|
|
|
- zt = open('ztriangle_%s.cxx' % (codeSeg), 'wb')
|
|
|
- print >> zt, ZTriangleStub % (codeSeg)
|
|
|
+ zt = open('ztriangle_%s.cxx' % (codeSeg), 'w')
|
|
|
+ print(ZTriangleStub % (codeSeg), file=zt)
|
|
|
|
|
|
# First, generate the code.
|
|
|
count = 0
|
|
|
@@ -189,14 +190,14 @@ try:
|
|
|
|
|
|
for i in range(len(ops)):
|
|
|
keyword = Options[i][ops[i]]
|
|
|
- print >> code, CodeTable[keyword]
|
|
|
+ print(CodeTable[keyword], file=code)
|
|
|
|
|
|
# This reference gets just the initial fname: omitting the
|
|
|
# ExtraOptions, which are implicit in ztriangle_two.h.
|
|
|
fname = getFname(ops)
|
|
|
- print >> code, '#define FNAME(name) %s_ ## name' % (fname)
|
|
|
- print >> code, '#include "ztriangle_two.h"'
|
|
|
- print >> code, ''
|
|
|
+ print('#define FNAME(name) %s_ ## name' % (fname), file=code)
|
|
|
+ print('#include "ztriangle_two.h"', file=code)
|
|
|
+ print('', file=code)
|
|
|
|
|
|
# We store the full fnames generated by the above lines
|
|
|
# (including the ExtraOptions) in the fnameDict and fnameList
|
|
|
@@ -220,22 +221,22 @@ closeCode()
|
|
|
|
|
|
# The external reference for the table containing the above function
|
|
|
# pointers gets written here.
|
|
|
-table_decl = open('ztriangle_table.h', 'wb')
|
|
|
-print >> table_decl, '/* This file is generated code--do not edit. See ztriangle.py. */'
|
|
|
-print >> table_decl, ''
|
|
|
+table_decl = open('ztriangle_table.h', 'w')
|
|
|
+print('/* This file is generated code--do not edit. See ztriangle.py. */', file=table_decl)
|
|
|
+print('', file=table_decl)
|
|
|
|
|
|
# The actual table definition gets written here.
|
|
|
-table_def = open('ztriangle_table.cxx', 'wb')
|
|
|
-print >> table_def, '/* This file is generated code--do not edit. See ztriangle.py. */'
|
|
|
-print >> table_def, ''
|
|
|
-print >> table_def, '#include "pandabase.h"'
|
|
|
-print >> table_def, '#include "zbuffer.h"'
|
|
|
-print >> table_def, '#include "ztriangle_table.h"'
|
|
|
-print >> table_def, ''
|
|
|
+table_def = open('ztriangle_table.cxx', 'w')
|
|
|
+print('/* This file is generated code--do not edit. See ztriangle.py. */', file=table_def)
|
|
|
+print('', file=table_def)
|
|
|
+print('#include "pandabase.h"', file=table_def)
|
|
|
+print('#include "zbuffer.h"', file=table_def)
|
|
|
+print('#include "ztriangle_table.h"', file=table_def)
|
|
|
+print('', file=table_def)
|
|
|
|
|
|
for i in range(NumSegments):
|
|
|
- print >> table_def, 'extern ZB_fillTriangleFunc ztriangle_code_%s[];' % (i + 1)
|
|
|
-print >> table_def, ''
|
|
|
+ print('extern ZB_fillTriangleFunc ztriangle_code_%s[];' % (i + 1), file=table_def)
|
|
|
+print('', file=table_def)
|
|
|
|
|
|
def writeTableEntry(ops):
|
|
|
indent = ' ' * (len(ops) + 1)
|
|
|
@@ -245,27 +246,27 @@ def writeTableEntry(ops):
|
|
|
if i + 1 == len(FullOptions):
|
|
|
# The last level: write out the actual function names.
|
|
|
for j in range(numOps - 1):
|
|
|
- print >> table_def, indent + getFref(ops + [j]) + ','
|
|
|
- print >> table_def, indent + getFref(ops + [numOps - 1])
|
|
|
+ print(indent + getFref(ops + [j]) + ',', file=table_def)
|
|
|
+ print(indent + getFref(ops + [numOps - 1]), file=table_def)
|
|
|
|
|
|
else:
|
|
|
# Intermediate levels: write out a nested reference.
|
|
|
for j in range(numOps - 1):
|
|
|
- print >> table_def, indent + '{'
|
|
|
+ print(indent + '{', file=table_def)
|
|
|
writeTableEntry(ops + [j])
|
|
|
- print >> table_def, indent + '},'
|
|
|
- print >> table_def, indent + '{'
|
|
|
+ print(indent + '},', file=table_def)
|
|
|
+ print(indent + '{', file=table_def)
|
|
|
writeTableEntry(ops + [numOps - 1])
|
|
|
- print >> table_def, indent + '}'
|
|
|
+ print(indent + '}', file=table_def)
|
|
|
|
|
|
arraySizeList = []
|
|
|
for opList in FullOptions:
|
|
|
arraySizeList.append('[%s]' % (len(opList)))
|
|
|
arraySize = ''.join(arraySizeList)
|
|
|
|
|
|
-print >> table_def, 'const ZB_fillTriangleFunc fill_tri_funcs%s = {' % (arraySize)
|
|
|
-print >> table_decl, 'extern const ZB_fillTriangleFunc fill_tri_funcs%s;' % (arraySize)
|
|
|
+print('const ZB_fillTriangleFunc fill_tri_funcs%s = {' % (arraySize), file=table_def)
|
|
|
+print('extern const ZB_fillTriangleFunc fill_tri_funcs%s;' % (arraySize), file=table_decl)
|
|
|
|
|
|
writeTableEntry([])
|
|
|
-print >> table_def, '};'
|
|
|
+print('};', file=table_def)
|
|
|
|