Bump engine submodule and move instance parameters to AoS.

This commit is contained in:
Roz K 2022-12-17 16:56:52 +01:00
parent f3bc6d6165
commit d2d6c8c241
Signed by: roz
GPG Key ID: 51FBF4E483E1C822
3 changed files with 18 additions and 15 deletions

2
engine

@ -1 +1 @@
Subproject commit 3df976c154f76351702fe9f512f09c072dd67f60 Subproject commit 5c9e10eea8059353c7bd8d48e669a9009b60c218

View File

@ -19,32 +19,34 @@ from engine import (
INSTANCE_FLAG_SPAWNED, BATCH_MAX_SIZE, create_batch, draw_batch, destroy_batch) INSTANCE_FLAG_SPAWNED, BATCH_MAX_SIZE, create_batch, draw_batch, destroy_batch)
class Batch: class Batch:
__slots__ = '_batch', 'max_size', 'flags', 'meshes', 'params' __slots__ = '_batch', 'max_size', 'format', 'flags', 'meshes', 'params'
def __init__(self, max_size, params_format): def __init__(self, max_size, params_format):
assert max_size <= BATCH_MAX_SIZE assert max_size <= BATCH_MAX_SIZE
self._batch = create_batch(max_size, params_format) self._batch = create_batch(max_size, params_format)
self.max_size = max_size self.max_size = max_size
self.format = params_format
self.flags = array('B') self.flags = array('B')
self.meshes = array('I') self.meshes = array('I')
self.params = [array('f') for _ in params_format] self.params = array('f')
def __del__(self): def __del__(self):
destroy_batch(self._batch) destroy_batch(self._batch)
def append(self, flags, mesh, params): def append(self, flags, mesh, params):
assert len(params) == len(self.params) assert len(params) == len(self.format)
index = len(self.flags) index = len(self.flags)
assert index < self.max_size assert index < self.max_size
self.flags.append(flags | INSTANCE_FLAG_SPAWNED) self.flags.append(flags | INSTANCE_FLAG_SPAWNED)
self.meshes.append(mesh) self.meshes.append(mesh)
for _params, param in zip(self.params, params): def append_param(param):
_params.extend(param) start = len(self.params)
return index self.params.extend(param)
return slice(start, len(self.params))
return tuple(map(append_param, params))
def set_param(self, param, index, value): def set_param(self, param, id, value):
size = len(value) self.params[id[param]] = value
self.params[param][index * size : index * size + size] = value
def draw(self): def draw(self):
draw_batch(self._batch, self.flags, self.meshes, self.params) draw_batch(self._batch, self.flags, self.meshes, self.params)

View File

@ -97,7 +97,8 @@ def main():
cube = archive.get_model('cube') cube = archive.get_model('cube')
clouds = archive.get_model('clouds') clouds = archive.get_model('clouds')
select_vertices(tests_vertices) select_vertices(tests_vertices)
tests_batch = batch.Batch(3, params_format(PARAM_FORMAT_VEC3_FLOAT, PARAM_FORMAT_VEC3_FLOAT)) tests_batch = batch.Batch(3,
params_format(PARAM_FORMAT_VEC3_FLOAT, PARAM_FORMAT_VEC3_INT10 | PARAM_FORMAT_NORMALIZE))
blob_translation = vec3((-100.0, -500.0, 0.0)) blob_translation = vec3((-100.0, -500.0, 0.0))
cube_translation = vec3((100.0, -500.0, 0.0)) cube_translation = vec3((100.0, -500.0, 0.0))
cube_orientation = vec3(vec3_forward) cube_orientation = vec3(vec3_forward)
@ -151,7 +152,7 @@ def main():
perf_count = 0 perf_count = 0
try: try:
for frame in range(10000): for frame in range(10000):
current_time = 0 #time.monotonic() - start_time current_time = time.monotonic() - start_time
begin_frame() begin_frame()
frame_begin = time.thread_time() frame_begin = time.thread_time()
@ -247,9 +248,9 @@ def main():
# lookat = vec3((0.0, 500.0, -500.0)) # lookat = vec3((0.0, 500.0, -500.0))
# for x in range(10000) # for x in range(10000)
# current_time = 0 # current_time = 0
# Draw * 9999 : min = 0.18 , max = 1.98 , avg = 0.24 ms # Draw * 9999 : min = 0.2 , max = 2.16 , avg = 0.26 ms
# Draw * 9999 : min = 0.21 , max = 2.19 , avg = 0.27 ms # Draw * 9999 : min = 0.2 , max = 2.77 , avg = 0.27 ms
# Draw * 9999 : min = 0.19 , max = 2.13 , avg = 0.25 ms # Draw * 9999 : min = 0.2 , max = 2.00 , avg = 0.27 ms
print("Quitting...") print("Quitting...")
del tests_batch del tests_batch