Resolve issue with getting textures.

This commit is contained in:
_ 2018-05-13 14:38:53 -07:00
parent 2f98c2a1a2
commit b1b281cccd

View File

@ -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()