Cleanup: #!s, prints, exceptions, more consistent naming

This commit is contained in:
surkeh 2018-05-16 22:10:46 -07:00
parent a5abb9d24f
commit 43afe7bf70
6 changed files with 33 additions and 38 deletions

View File

@ -35,4 +35,4 @@ devil1geo.o: src/devil1geo.c
$(CC) -c $^ $(CFLAGS)
clean:
rm *.o *.gch $(TARGET) $(PEX) $(TEX) $(MEX)
rm *.o $(TARGET) $(PEX) $(TEX) $(MEX)

View File

@ -3,11 +3,7 @@ import sys, ctypes
sharedlib = './lib3ddevil1.so'
libc = ctypes.cdll.LoadLibrary(sharedlib)
if not libc:
print("Couldn't load %s" % sharedlib)
sys.exit()
# Observe how many times the .so is loaded.
print("\nlib3ddevil1 loaded.")
raise SystemExit("Couldn't load %s" % sharedlib)
# Don't need these anymore
del sys, sharedlib

27
bindings/main.py → bindings/__test__.py Normal file → Executable file
View File

@ -1,6 +1,7 @@
from py3devil1pld import PldHeader
from py3devil1tex import TEXturePack, TEXtureBatchDescriptor, TEXtureBatch
from py3devil1geo import GEOHeader, MEShHeader, MEsh
#!/usr/bin/python3
from py3devil1pld import pyPldHeader
from py3devil1tex import pyTexturePack, pyTextureBatchDescriptor, pyTextureBatch
from py3devil1geo import pyGeoHeader, pyMeshHeader, pyMesh
#print(libc)
@ -54,7 +55,7 @@ if __name__ == "__main__":
print("OK")
pldfn = Devil1PLD_FN.in_dll(libc, "DEVIL1PLD")
pldh = PldHeader()
pldh = pyPldHeader()
pldtest(pldfn, pldh)
texfn = Devil1TEX_FN.in_dll(libc, "DEVIL1TEX")
@ -68,29 +69,29 @@ if __name__ == "__main__":
def mainx():
with open("pl01.pld", "rb") as f:
data = f.read()
pld = PldHeader(data)
pld = pyPldHeader(data)
pld.show()
pld2 = PldHeader()
pld2 = pyPldHeader()
pld2.show()
with open("pl01.pld_1.txp", "rb") as f:
data = f.read()
txp = TEXturePack(data)
txp = pyTexturePack(data)
txp.show()
print(txp.getbatchno())
print(txp.getfirstbatchoffset())
tbd = TEXtureBatchDescriptor(1, data)
tbd = pyTextureBatchDescriptor(1, data)
tbd.show()
print(tbd.gettexturesize())
#tx = TEXtures(0, tbd.gettexno(), data)
tx = TEXtureBatch(0, data)
#tx = pyTextures(0, tbd.gettexno(), data)
tx = pyTextureBatch(0, data)
ts = tx.gettextures()
for i in range(0, 10):
print(ts[0].data[i])
with open("pl00.pld_0", "rb") as f:
data = f.read()
gh = GEOHeader(data)
gh = pyGeoHeader(data)
gh.show()
print("-------------")
print(gh.getmeshno())
@ -99,9 +100,9 @@ if __name__ == "__main__":
print(gh.getunknownd())
print(gh.getpadding())
print(gh.getunknownoffset())
mh = MEShHeader(3, data)
mh = pyMeshHeader(3, data)
mh.show()
m = MEsh(0, data)
m = pyMesh(0, data)
m.show()
# p = m.getpositions()
# print("positions:")

View File

@ -1,6 +1,5 @@
#!/usr/bin/python3
import ctypes
from .__init__ import libc
from __init__ import libc
#--------------------------------------+
# Basic Struct
@ -141,7 +140,7 @@ del libc
# Pythonic Object
#--------------------------------------+
class GEOHeader:
class pyGeoHeader:
def __init__(self, filedata):
self.cstruct = ctypes.pointer(Header())
ptrofptr = ctypes.byref(self.cstruct)
@ -171,7 +170,7 @@ class GEOHeader:
return hex(self.cstruct.contents.unknownOffset)
class MEShHeader:
class pyMeshHeader:
def __init__(self, i, filedata):
self.cstruct = ctypes.pointer(MeshHeader())
ptrofptr = ctypes.byref(self.cstruct)
@ -198,11 +197,11 @@ class MEShHeader:
def getflags(self):
return self.cstruct.contents.flags
class MEsh:
class pyMesh:
def __init__(self, i, filedata):
self.cstruct = Mesh()
if filedata:
mh = MEShHeader(i, filedata)
mh = pyMeshHeader(i, filedata)
# allocate memory for the size of batch * number of batches
memsize = ctypes.sizeof(Batch) * mh.getbatchno()
self.cstruct.b = ctypes.cast(

View File

@ -1,12 +1,12 @@
#!/usr/bin/python3
import ctypes
from .__init__ import libc
from __init__ import libc
#--------------------------------------+
# Basic Struct
#--------------------------------------+
class _PldHeader_(ctypes.Structure):
class PldHeader(ctypes.Structure):
_pack_ = 1
_fields_ = [
("numOffset", ctypes.c_int),
@ -17,14 +17,14 @@ class Devil1PLD_FN(ctypes.Structure):
_fields_ = [
("getheader" , ctypes.CFUNCTYPE(
ctypes.c_bool,
ctypes.POINTER(_PldHeader_),
ctypes.POINTER(PldHeader),
ctypes.c_char_p)),
("sizeofsector", ctypes.CFUNCTYPE(
ctypes.c_int,
ctypes.POINTER(_PldHeader_),
ctypes.POINTER(PldHeader),
ctypes.c_int)),
("printheader" , ctypes.CFUNCTYPE(None,
ctypes.POINTER(_PldHeader_)))
ctypes.POINTER(PldHeader)))
]
devil1pld = Devil1PLD_FN.in_dll(libc, "DEVIL1PLD")
@ -34,10 +34,10 @@ del libc
# Pythonic Object
#--------------------------------------+
class PldHeader:
class pyPldHeader:
def __init__(self, filedata = None):
# Store C Struct in order to call C functions
self.cstruct = _PldHeader_()
self.cstruct = PldHeader()
if filedata:
devil1pld.getheader(ctypes.byref(self.cstruct), filedata)
self.eof = len(filedata)

View File

@ -1,6 +1,5 @@
#!/usr/bin/python3
import ctypes
from .__init__ import libc
from __init__ import libc
#--------------------------------------+
# Basic Struct
@ -80,7 +79,7 @@ del libc
# Pythonic Object
#--------------------------------------+
class TEXturePack:
class pyTexturePack:
def __init__(self, filedata):
self.cstruct = ctypes.pointer(TexturePack())
devil1tex.getheader(ctypes.byref(self.cstruct), filedata)
@ -95,7 +94,7 @@ class TEXturePack:
def getfirstbatchoffset(self):
return self.cstruct.contents.firstBatchOffset
class TEXtureBatchDescriptor:
class pyTextureBatchDescriptor:
def __init__(self, i, filedata):
self.cstruct = ctypes.pointer(TextureBatchDescriptor())
ptrofptr = ctypes.byref(self.cstruct)
@ -118,12 +117,12 @@ class TEXtureBatchDescriptor:
def gettexturesize(self):
return self.cstruct.contents.textureSize
class TEXtureBatch:
class pyTextureBatch:
def __init__(self, i, filedata):
self.cstruct = TextureBatch()
if filedata:
self.cstruct.batch = None
tbd = TEXtureBatchDescriptor(i, filedata)
tbd = pyTextureBatchDescriptor(i, filedata)
self.amount = tbd.gettexno()
memsize = self.amount * tbd.gettexturesize()
self.cstruct.batch = ctypes.cast(