Bump engine submodules and rework vertices data for the new mesh struct.

This commit is contained in:
Roz K 2023-01-04 09:38:04 +01:00
parent f487a4fcb7
commit efdbbb5815
Signed by: roz
GPG Key ID: 51FBF4E483E1C822
4 changed files with 16 additions and 15 deletions

2
engine

@ -1 +1 @@
Subproject commit a5adfacdfd6dbb52bd5d1438eef90a370976531e
Subproject commit b46b4bddba6c609307ca198438c60d617e20c752

View File

@ -19,8 +19,10 @@ from engine import (
buffer, INSTANCE_FLAG_SPAWNED, BATCH_MAX_SIZE, param_type, params_format,
create_batch, fill_batch, draw_batch, destroy_batch)
_flags_p = POINTER(c_ubyte)
_mesh_p = POINTER(c_ushort)
_flags_t = c_ubyte
_flags_p = POINTER(_flags_t)
_mesh_t = c_ushort
_mesh_p = POINTER(_mesh_t)
class Batch:
__slots__ = ('_batch', 'vertices', 'max_size', 'size',
@ -36,9 +38,9 @@ class Batch:
self.vertices = vertices
self.max_size = max_size
self.size = 0
self.flags = buffer(c_ubyte, max_size)
self.flags = buffer(_flags_t, max_size)
self._flags = _flags_p(self.flags)
self.mesh = buffer(c_ushort, max_size)
self.mesh = buffer(_mesh_t, max_size)
self._meshes = _mesh_p(self.mesh)
if nparams:
self.param = tuple(map(lambda f: buffer(param_type(f), max_size), params_decls.values()))

View File

@ -195,7 +195,7 @@ class ObjArchive(Archive):
vertices = []
indices = []
models = {}
meshes = {}
for name, mesh in sorted(objects.items()):
offset = len(indices)
assert offset < 65536
@ -213,7 +213,7 @@ class ObjArchive(Archive):
assert count < 65536
vertices.extend(mesh_vertices)
indices.extend(mesh_indices)
models[name] = (offset, count)
meshes[name] = (offset, count)
name = str(objpath.stem)
assert name not in self.vertices_db.keys()
@ -226,9 +226,6 @@ class ObjArchive(Archive):
n = (pack_10(_nz) << 20) | (pack_10(_ny) << 10) | pack_10(_nx)
t = ((_tl & 1023) << 20) | (pack_u10(_t) << 10) | pack_u10(_s)
return struct.pack('fffII', _px, _py, _pz, n, t)
meshes = {}
for mesh_name, (offset, count) in sorted(models.items()):
meshes[mesh_name] = offset | (count << 16)
self.vertices_db[name] = VerticesData(name,
array('B', b''.join(starmap(pack_vertex, vertices))),
array('H', indices),

View File

@ -13,6 +13,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from itertools import chain
import struct
from array import array
from pathlib import Path
@ -147,7 +148,7 @@ class VerticesData:
self.name = name
self.vertices = vertices
self.indices = indices
self.meshes = array('I', meshes.values())
self.meshes = meshes.values()
self.meshes_db = dict(zip(meshes.keys(), range(len(meshes))))
def __iter__(self):
@ -155,7 +156,7 @@ class VerticesData:
yield len(self.vertices) // VERTEX_SIZE
yield self.vertices
yield self.indices
yield self.meshes
yield array('I', chain.from_iterable(self.meshes))
def get_mesh(self, name):
return self.meshes_db[name]
@ -167,19 +168,20 @@ class VerticesData:
nvertices, nindices, nmeshes = _read_struct(file, 'III')
vertices = _read_array(file, 'B', nvertices * VERTEX_SIZE)
indices = _read_array(file, 'H', nindices)
meshes = _read_array(file, 'I', nmeshes)
names = [_read_string(file) for _ in range(nmeshes)]
meshes = [_read_struct(file, 'II') for _ in range(nmeshes)]
return cls(name, vertices, indices, dict(zip(names, meshes)))
def to_archive(self, file):
_write_magic(file, b'VERT')
_write_string(file, self.name)
_write_struct(file, 'III', len(self.vertices) // VERTEX_SIZE, len(self.indices), len(self.meshes))
_write_struct(file, 'III', len(self.vertices) // VERTEX_SIZE, len(self.indices), len(self.meshes_db))
_write_array(file, self.vertices)
_write_array(file, self.indices)
_write_array(file, self.meshes)
for name in self.meshes_db.keys():
_write_string(file, name)
for mesh in self.meshes:
_write_struct(file, 'II', *mesh)
class Archive:
__slots__ = 'textures_db', 'vertices_db'