From cdf13f50a7b1fed5dd264ef8d1494055283fdef6 Mon Sep 17 00:00:00 2001 From: Roz K Date: Tue, 20 Dec 2022 14:40:17 +0100 Subject: [PATCH] Bump engine submodule and move batch flags and meshes to ctypes. --- engine | 2 +- game/batch.py | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/engine b/engine index 84ea17f..abf1e87 160000 --- a/engine +++ b/engine @@ -1 +1 @@ -Subproject commit 84ea17f1cca7d4d9c27be716c38e19f70335fa8a +Subproject commit abf1e87a3677cc01543f295df588cfa5c54db4e4 diff --git a/game/batch.py b/game/batch.py index 07cd6e7..c099ec9 100644 --- a/game/batch.py +++ b/game/batch.py @@ -13,34 +13,36 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -from ctypes import POINTER +from ctypes import c_ubyte, c_uint, POINTER from array import array from engine import ( INSTANCE_FLAG_SPAWNED, BATCH_MAX_SIZE, create_batch, draw_batch, destroy_batch) class Batch: - __slots__ = '_batch', '_paramsp', 'max_size', 'flags', 'meshes', 'params' + __slots__ = '_batch', '_paramsp', 'size', 'max_size', 'flags', 'meshes', 'params' def __init__(self, vertices, max_size, params_format, params_type): assert max_size <= BATCH_MAX_SIZE self._batch = create_batch(vertices, max_size, params_format) self._paramsp = POINTER(params_type) + self.size = 0 self.max_size = max_size - self.flags = array('B') - self.meshes = array('I') + self.flags = (c_ubyte * max_size)() + self.meshes = (c_uint * max_size)() self.params = (params_type * max_size)() def __del__(self): destroy_batch(self._batch) def append(self, flags, mesh, params): - index = len(self.flags) + index = self.size assert index < self.max_size - self.flags.append(flags | INSTANCE_FLAG_SPAWNED) - self.meshes.append(mesh) + self.flags[index] = flags | INSTANCE_FLAG_SPAWNED + self.meshes[index] = mesh self.params[index] = params + self.size += 1 return index def draw(self): - draw_batch(self._batch, self.flags, self.meshes, self._paramsp(self.params)) + draw_batch(self._batch, self.size, self.flags, self.meshes, self._paramsp(self.params))