Bump engine submodule and add static batch.

This commit is contained in:
Roz K 2023-01-02 17:20:34 +01:00
parent 7219039980
commit a96ea8bb6b
Signed by: roz
GPG Key ID: 51FBF4E483E1C822
3 changed files with 18 additions and 6 deletions

2
engine

@ -1 +1 @@
Subproject commit beca8798bf91edba954d31eb4e1a619ec2140c83
Subproject commit ed87f292ffa3cf89903cddcdec396115893f7d66

View File

@ -15,11 +15,12 @@
from ctypes import c_ubyte, c_uint, c_void_p, addressof
from engine import (vec3, mat3, buffer,
INSTANCE_FLAG_SPAWNED, BATCH_MAX_SIZE, param_type, params_format, create_batch, draw_batch, destroy_batch)
from engine import (
buffer, INSTANCE_FLAG_SPAWNED, BATCH_MAX_SIZE, param_type, params_format,
create_batch, fill_batch, draw_batch, destroy_batch)
class Batch:
__slots__ = '_batch', 'vertices', 'size', 'max_size', 'flags', 'meshes', 'params', '_params', '__dict__'
__slots__ = '_batch', '_static', 'vertices', 'size', 'max_size', 'flags', 'meshes', 'params', '_params', '__dict__'
def __init__(self, vertices, max_size, max_meshes, **params_decls):
assert max_size <= BATCH_MAX_SIZE
@ -27,13 +28,17 @@ class Batch:
names = params_decls.keys()
formats = params_decls.values()
self._batch = create_batch(vertices._vertices, max_size, max_meshes, params_format(*formats))
self._static = False
self.vertices = vertices
self.size = 0
self.max_size = max_size
self.flags = buffer(c_ubyte, max_size)
self.meshes = buffer(c_uint, max_size)
self.params = tuple(map(lambda f: buffer(param_type(f), max_size), formats))
self._params = (c_void_p * nparams)(*map(addressof, self.params))
if nparams:
self._params = (c_void_p * nparams)(*map(addressof, self.params))
else:
self._params = None
for name, value in zip(names, self.params):
setattr(self, name, value)
@ -51,5 +56,11 @@ class Batch:
self.size += 1
return index
def make_static(self):
fill_batch(self._batch, self.size, self.flags, self.meshes, self._params)
self._static = True
def draw(self):
draw_batch(self._batch, self.size, self.flags, self.meshes, self._params)
if not self._static:
fill_batch(self._batch, self.size, self.flags, self.meshes, self._params)
draw_batch(self._batch)

View File

@ -166,6 +166,7 @@ def create_scene(keyboard, mouse):
else:
model = rock_model
tiles_batch.spawn(model, vec3(float(((mx - 128) * 8) + 4), float(((127 - my) * 8) + 4), 0.0))
tiles_batch.make_static()
tests_texture = Texture(*archive.get_texture('tests'))
tests_vertices = Vertices(*archive.get_vertices('tests'))