mirror of
https://notabug.org/scuti/lib3ddevil1
synced 2024-11-24 07:49:48 +05:30
Cleanup: #!s, prints, exceptions, more consistent naming
This commit is contained in:
parent
a5abb9d24f
commit
43afe7bf70
2
Makefile
2
Makefile
@ -35,4 +35,4 @@ devil1geo.o: src/devil1geo.c
|
|||||||
$(CC) -c $^ $(CFLAGS)
|
$(CC) -c $^ $(CFLAGS)
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm *.o *.gch $(TARGET) $(PEX) $(TEX) $(MEX)
|
rm *.o $(TARGET) $(PEX) $(TEX) $(MEX)
|
||||||
|
@ -3,11 +3,7 @@ import sys, ctypes
|
|||||||
sharedlib = './lib3ddevil1.so'
|
sharedlib = './lib3ddevil1.so'
|
||||||
libc = ctypes.cdll.LoadLibrary(sharedlib)
|
libc = ctypes.cdll.LoadLibrary(sharedlib)
|
||||||
if not libc:
|
if not libc:
|
||||||
print("Couldn't load %s" % sharedlib)
|
raise SystemExit("Couldn't load %s" % sharedlib)
|
||||||
sys.exit()
|
|
||||||
|
|
||||||
# Observe how many times the .so is loaded.
|
|
||||||
print("\nlib3ddevil1 loaded.")
|
|
||||||
|
|
||||||
# Don't need these anymore
|
# Don't need these anymore
|
||||||
del sys, sharedlib
|
del sys, sharedlib
|
||||||
|
27
bindings/main.py → bindings/__test__.py
Normal file → Executable file
27
bindings/main.py → bindings/__test__.py
Normal file → Executable file
@ -1,6 +1,7 @@
|
|||||||
from py3devil1pld import PldHeader
|
#!/usr/bin/python3
|
||||||
from py3devil1tex import TEXturePack, TEXtureBatchDescriptor, TEXtureBatch
|
from py3devil1pld import pyPldHeader
|
||||||
from py3devil1geo import GEOHeader, MEShHeader, MEsh
|
from py3devil1tex import pyTexturePack, pyTextureBatchDescriptor, pyTextureBatch
|
||||||
|
from py3devil1geo import pyGeoHeader, pyMeshHeader, pyMesh
|
||||||
|
|
||||||
#print(libc)
|
#print(libc)
|
||||||
|
|
||||||
@ -54,7 +55,7 @@ if __name__ == "__main__":
|
|||||||
print("OK")
|
print("OK")
|
||||||
|
|
||||||
pldfn = Devil1PLD_FN.in_dll(libc, "DEVIL1PLD")
|
pldfn = Devil1PLD_FN.in_dll(libc, "DEVIL1PLD")
|
||||||
pldh = PldHeader()
|
pldh = pyPldHeader()
|
||||||
pldtest(pldfn, pldh)
|
pldtest(pldfn, pldh)
|
||||||
|
|
||||||
texfn = Devil1TEX_FN.in_dll(libc, "DEVIL1TEX")
|
texfn = Devil1TEX_FN.in_dll(libc, "DEVIL1TEX")
|
||||||
@ -68,29 +69,29 @@ if __name__ == "__main__":
|
|||||||
def mainx():
|
def mainx():
|
||||||
with open("pl01.pld", "rb") as f:
|
with open("pl01.pld", "rb") as f:
|
||||||
data = f.read()
|
data = f.read()
|
||||||
pld = PldHeader(data)
|
pld = pyPldHeader(data)
|
||||||
pld.show()
|
pld.show()
|
||||||
pld2 = PldHeader()
|
pld2 = pyPldHeader()
|
||||||
pld2.show()
|
pld2.show()
|
||||||
|
|
||||||
with open("pl01.pld_1.txp", "rb") as f:
|
with open("pl01.pld_1.txp", "rb") as f:
|
||||||
data = f.read()
|
data = f.read()
|
||||||
txp = TEXturePack(data)
|
txp = pyTexturePack(data)
|
||||||
txp.show()
|
txp.show()
|
||||||
print(txp.getbatchno())
|
print(txp.getbatchno())
|
||||||
print(txp.getfirstbatchoffset())
|
print(txp.getfirstbatchoffset())
|
||||||
tbd = TEXtureBatchDescriptor(1, data)
|
tbd = pyTextureBatchDescriptor(1, data)
|
||||||
tbd.show()
|
tbd.show()
|
||||||
print(tbd.gettexturesize())
|
print(tbd.gettexturesize())
|
||||||
#tx = TEXtures(0, tbd.gettexno(), data)
|
#tx = pyTextures(0, tbd.gettexno(), data)
|
||||||
tx = TEXtureBatch(0, data)
|
tx = pyTextureBatch(0, data)
|
||||||
ts = tx.gettextures()
|
ts = tx.gettextures()
|
||||||
for i in range(0, 10):
|
for i in range(0, 10):
|
||||||
print(ts[0].data[i])
|
print(ts[0].data[i])
|
||||||
|
|
||||||
with open("pl00.pld_0", "rb") as f:
|
with open("pl00.pld_0", "rb") as f:
|
||||||
data = f.read()
|
data = f.read()
|
||||||
gh = GEOHeader(data)
|
gh = pyGeoHeader(data)
|
||||||
gh.show()
|
gh.show()
|
||||||
print("-------------")
|
print("-------------")
|
||||||
print(gh.getmeshno())
|
print(gh.getmeshno())
|
||||||
@ -99,9 +100,9 @@ if __name__ == "__main__":
|
|||||||
print(gh.getunknownd())
|
print(gh.getunknownd())
|
||||||
print(gh.getpadding())
|
print(gh.getpadding())
|
||||||
print(gh.getunknownoffset())
|
print(gh.getunknownoffset())
|
||||||
mh = MEShHeader(3, data)
|
mh = pyMeshHeader(3, data)
|
||||||
mh.show()
|
mh.show()
|
||||||
m = MEsh(0, data)
|
m = pyMesh(0, data)
|
||||||
m.show()
|
m.show()
|
||||||
# p = m.getpositions()
|
# p = m.getpositions()
|
||||||
# print("positions:")
|
# print("positions:")
|
@ -1,6 +1,5 @@
|
|||||||
#!/usr/bin/python3
|
|
||||||
import ctypes
|
import ctypes
|
||||||
from .__init__ import libc
|
from __init__ import libc
|
||||||
|
|
||||||
#--------------------------------------+
|
#--------------------------------------+
|
||||||
# Basic Struct
|
# Basic Struct
|
||||||
@ -141,7 +140,7 @@ del libc
|
|||||||
# Pythonic Object
|
# Pythonic Object
|
||||||
#--------------------------------------+
|
#--------------------------------------+
|
||||||
|
|
||||||
class GEOHeader:
|
class pyGeoHeader:
|
||||||
def __init__(self, filedata):
|
def __init__(self, filedata):
|
||||||
self.cstruct = ctypes.pointer(Header())
|
self.cstruct = ctypes.pointer(Header())
|
||||||
ptrofptr = ctypes.byref(self.cstruct)
|
ptrofptr = ctypes.byref(self.cstruct)
|
||||||
@ -171,7 +170,7 @@ class GEOHeader:
|
|||||||
return hex(self.cstruct.contents.unknownOffset)
|
return hex(self.cstruct.contents.unknownOffset)
|
||||||
|
|
||||||
|
|
||||||
class MEShHeader:
|
class pyMeshHeader:
|
||||||
def __init__(self, i, filedata):
|
def __init__(self, i, filedata):
|
||||||
self.cstruct = ctypes.pointer(MeshHeader())
|
self.cstruct = ctypes.pointer(MeshHeader())
|
||||||
ptrofptr = ctypes.byref(self.cstruct)
|
ptrofptr = ctypes.byref(self.cstruct)
|
||||||
@ -198,11 +197,11 @@ class MEShHeader:
|
|||||||
def getflags(self):
|
def getflags(self):
|
||||||
return self.cstruct.contents.flags
|
return self.cstruct.contents.flags
|
||||||
|
|
||||||
class MEsh:
|
class pyMesh:
|
||||||
def __init__(self, i, filedata):
|
def __init__(self, i, filedata):
|
||||||
self.cstruct = Mesh()
|
self.cstruct = Mesh()
|
||||||
if filedata:
|
if filedata:
|
||||||
mh = MEShHeader(i, filedata)
|
mh = pyMeshHeader(i, filedata)
|
||||||
# allocate memory for the size of batch * number of batches
|
# allocate memory for the size of batch * number of batches
|
||||||
memsize = ctypes.sizeof(Batch) * mh.getbatchno()
|
memsize = ctypes.sizeof(Batch) * mh.getbatchno()
|
||||||
self.cstruct.b = ctypes.cast(
|
self.cstruct.b = ctypes.cast(
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
import ctypes
|
import ctypes
|
||||||
from .__init__ import libc
|
from __init__ import libc
|
||||||
|
|
||||||
#--------------------------------------+
|
#--------------------------------------+
|
||||||
# Basic Struct
|
# Basic Struct
|
||||||
#--------------------------------------+
|
#--------------------------------------+
|
||||||
|
|
||||||
class _PldHeader_(ctypes.Structure):
|
class PldHeader(ctypes.Structure):
|
||||||
_pack_ = 1
|
_pack_ = 1
|
||||||
_fields_ = [
|
_fields_ = [
|
||||||
("numOffset", ctypes.c_int),
|
("numOffset", ctypes.c_int),
|
||||||
@ -17,14 +17,14 @@ class Devil1PLD_FN(ctypes.Structure):
|
|||||||
_fields_ = [
|
_fields_ = [
|
||||||
("getheader" , ctypes.CFUNCTYPE(
|
("getheader" , ctypes.CFUNCTYPE(
|
||||||
ctypes.c_bool,
|
ctypes.c_bool,
|
||||||
ctypes.POINTER(_PldHeader_),
|
ctypes.POINTER(PldHeader),
|
||||||
ctypes.c_char_p)),
|
ctypes.c_char_p)),
|
||||||
("sizeofsector", ctypes.CFUNCTYPE(
|
("sizeofsector", ctypes.CFUNCTYPE(
|
||||||
ctypes.c_int,
|
ctypes.c_int,
|
||||||
ctypes.POINTER(_PldHeader_),
|
ctypes.POINTER(PldHeader),
|
||||||
ctypes.c_int)),
|
ctypes.c_int)),
|
||||||
("printheader" , ctypes.CFUNCTYPE(None,
|
("printheader" , ctypes.CFUNCTYPE(None,
|
||||||
ctypes.POINTER(_PldHeader_)))
|
ctypes.POINTER(PldHeader)))
|
||||||
]
|
]
|
||||||
|
|
||||||
devil1pld = Devil1PLD_FN.in_dll(libc, "DEVIL1PLD")
|
devil1pld = Devil1PLD_FN.in_dll(libc, "DEVIL1PLD")
|
||||||
@ -34,10 +34,10 @@ del libc
|
|||||||
# Pythonic Object
|
# Pythonic Object
|
||||||
#--------------------------------------+
|
#--------------------------------------+
|
||||||
|
|
||||||
class PldHeader:
|
class pyPldHeader:
|
||||||
def __init__(self, filedata = None):
|
def __init__(self, filedata = None):
|
||||||
# Store C Struct in order to call C functions
|
# Store C Struct in order to call C functions
|
||||||
self.cstruct = _PldHeader_()
|
self.cstruct = PldHeader()
|
||||||
if filedata:
|
if filedata:
|
||||||
devil1pld.getheader(ctypes.byref(self.cstruct), filedata)
|
devil1pld.getheader(ctypes.byref(self.cstruct), filedata)
|
||||||
self.eof = len(filedata)
|
self.eof = len(filedata)
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
#!/usr/bin/python3
|
|
||||||
import ctypes
|
import ctypes
|
||||||
from .__init__ import libc
|
from __init__ import libc
|
||||||
|
|
||||||
#--------------------------------------+
|
#--------------------------------------+
|
||||||
# Basic Struct
|
# Basic Struct
|
||||||
@ -80,7 +79,7 @@ del libc
|
|||||||
# Pythonic Object
|
# Pythonic Object
|
||||||
#--------------------------------------+
|
#--------------------------------------+
|
||||||
|
|
||||||
class TEXturePack:
|
class pyTexturePack:
|
||||||
def __init__(self, filedata):
|
def __init__(self, filedata):
|
||||||
self.cstruct = ctypes.pointer(TexturePack())
|
self.cstruct = ctypes.pointer(TexturePack())
|
||||||
devil1tex.getheader(ctypes.byref(self.cstruct), filedata)
|
devil1tex.getheader(ctypes.byref(self.cstruct), filedata)
|
||||||
@ -95,7 +94,7 @@ class TEXturePack:
|
|||||||
def getfirstbatchoffset(self):
|
def getfirstbatchoffset(self):
|
||||||
return self.cstruct.contents.firstBatchOffset
|
return self.cstruct.contents.firstBatchOffset
|
||||||
|
|
||||||
class TEXtureBatchDescriptor:
|
class pyTextureBatchDescriptor:
|
||||||
def __init__(self, i, filedata):
|
def __init__(self, i, filedata):
|
||||||
self.cstruct = ctypes.pointer(TextureBatchDescriptor())
|
self.cstruct = ctypes.pointer(TextureBatchDescriptor())
|
||||||
ptrofptr = ctypes.byref(self.cstruct)
|
ptrofptr = ctypes.byref(self.cstruct)
|
||||||
@ -118,12 +117,12 @@ class TEXtureBatchDescriptor:
|
|||||||
def gettexturesize(self):
|
def gettexturesize(self):
|
||||||
return self.cstruct.contents.textureSize
|
return self.cstruct.contents.textureSize
|
||||||
|
|
||||||
class TEXtureBatch:
|
class pyTextureBatch:
|
||||||
def __init__(self, i, filedata):
|
def __init__(self, i, filedata):
|
||||||
self.cstruct = TextureBatch()
|
self.cstruct = TextureBatch()
|
||||||
if filedata:
|
if filedata:
|
||||||
self.cstruct.batch = None
|
self.cstruct.batch = None
|
||||||
tbd = TEXtureBatchDescriptor(i, filedata)
|
tbd = pyTextureBatchDescriptor(i, filedata)
|
||||||
self.amount = tbd.gettexno()
|
self.amount = tbd.gettexno()
|
||||||
memsize = self.amount * tbd.gettexturesize()
|
memsize = self.amount * tbd.gettexturesize()
|
||||||
self.cstruct.batch = ctypes.cast(
|
self.cstruct.batch = ctypes.cast(
|
||||||
|
Loading…
Reference in New Issue
Block a user