From b1b281cccdae99f072f76e69b6648c2ee31c07c8 Mon Sep 17 00:00:00 2001 From: _ <_> Date: Sun, 13 May 2018 14:38:53 -0700 Subject: [PATCH] Resolve issue with getting textures. --- bindings/py3devil1.py | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/bindings/py3devil1.py b/bindings/py3devil1.py index e0de918..d63c10b 100755 --- a/bindings/py3devil1.py +++ b/bindings/py3devil1.py @@ -53,7 +53,7 @@ class TextureBatchDescriptor(ctypes.Structure): class Texture(ctypes.Structure): _pack_ = 1 _fields_ = [ - ("data", ctypes.c_ubyte) + ("data", ctypes.POINTER(ctypes.c_ubyte)) ] class TextureBatch(ctypes.Structure): @@ -305,16 +305,23 @@ class TEXtureBatchDescriptor: def gettexturesize(self): return self.cstruct.contents.textureSize - -# Needs testing / correction - gettextures will 'return by parameter' -# a dynamic array of textures. Need to be able to access multiple Texture() -class TEXtures: - def __init__(self, i, count, filedata): - self.cstruct = ctypes.byref(Texture()) +class TEXtureBatch: + def __init__(self, i, filedata): + self.cstruct = TextureBatch() if filedata: - devil1tex.gettextures(self.cstruct, i, filedata, len(filedata)) + self.cstruct.batch = None + tbd = TEXtureBatchDescriptor(i, filedata) + self.amount = tbd.gettexno() + memsize = self.amount * tbd.gettexturesize() + self.cstruct.batch = ctypes.cast( + ctypes.create_string_buffer(memsize), + ctypes.POINTER(Texture)) + devil1tex.gettextures(self.cstruct.batch, i, filedata, len(filedata)) return + def gettextures(self): + return self.cstruct.batch[:self.amount] + class GEOHeader: def __init__(self, filedata): self.cstruct = ctypes.pointer(Header()) @@ -497,7 +504,11 @@ if __name__ == "__main__": tbd = TEXtureBatchDescriptor(1, data) tbd.show() print(tbd.gettexturesize()) - tx = TEXtures(0, tbd.gettexno(), data) + #tx = TEXtures(0, tbd.gettexno(), data) + tx = TEXtureBatch(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()