diff --git a/engine b/engine index 3df976c..5c9e10e 160000 --- a/engine +++ b/engine @@ -1 +1 @@ -Subproject commit 3df976c154f76351702fe9f512f09c072dd67f60 +Subproject commit 5c9e10eea8059353c7bd8d48e669a9009b60c218 diff --git a/game/batch.py b/game/batch.py index 0966230..036f5cb 100644 --- a/game/batch.py +++ b/game/batch.py @@ -19,32 +19,34 @@ from engine import ( INSTANCE_FLAG_SPAWNED, BATCH_MAX_SIZE, create_batch, draw_batch, destroy_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): assert max_size <= BATCH_MAX_SIZE self._batch = create_batch(max_size, params_format) self.max_size = max_size + self.format = params_format self.flags = array('B') self.meshes = array('I') - self.params = [array('f') for _ in params_format] + self.params = array('f') def __del__(self): destroy_batch(self._batch) def append(self, flags, mesh, params): - assert len(params) == len(self.params) + assert len(params) == len(self.format) index = len(self.flags) assert index < self.max_size self.flags.append(flags | INSTANCE_FLAG_SPAWNED) self.meshes.append(mesh) - for _params, param in zip(self.params, params): - _params.extend(param) - return index + def append_param(param): + start = len(self.params) + self.params.extend(param) + return slice(start, len(self.params)) + return tuple(map(append_param, params)) - def set_param(self, param, index, value): - size = len(value) - self.params[param][index * size : index * size + size] = value + def set_param(self, param, id, value): + self.params[id[param]] = value def draw(self): draw_batch(self._batch, self.flags, self.meshes, self.params) diff --git a/game/game.py b/game/game.py index 7293b8d..cb3228f 100644 --- a/game/game.py +++ b/game/game.py @@ -97,7 +97,8 @@ def main(): cube = archive.get_model('cube') clouds = archive.get_model('clouds') 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)) cube_translation = vec3((100.0, -500.0, 0.0)) cube_orientation = vec3(vec3_forward) @@ -151,7 +152,7 @@ def main(): perf_count = 0 try: for frame in range(10000): - current_time = 0 #time.monotonic() - start_time + current_time = time.monotonic() - start_time begin_frame() frame_begin = time.thread_time() @@ -247,9 +248,9 @@ def main(): # lookat = vec3((0.0, 500.0, -500.0)) # for x in range(10000) # current_time = 0 - # Draw * 9999 : min = 0.18 , max = 1.98 , avg = 0.24 ms - # Draw * 9999 : min = 0.21 , max = 2.19 , avg = 0.27 ms - # Draw * 9999 : min = 0.19 , max = 2.13 , avg = 0.25 ms + # Draw * 9999 : min = 0.2 , max = 2.16 , avg = 0.26 ms + # Draw * 9999 : min = 0.2 , max = 2.77 , avg = 0.27 ms + # Draw * 9999 : min = 0.2 , max = 2.00 , avg = 0.27 ms print("Quitting...") del tests_batch