Compare commits

..

2 Commits

Author SHA1 Message Date
f487a4fcb7
Bump engine submodule. 2023-01-03 14:10:43 +01:00
4cb67c0d79
Fix perf node division by zero. 2023-01-03 14:10:04 +01:00
4 changed files with 20 additions and 18 deletions

2
engine

@ -1 +1 @@
Subproject commit d0741afda706be3a7daa7ef0efd6559eb1824c3a Subproject commit a5adfacdfd6dbb52bd5d1438eef90a370976531e

View File

@ -13,14 +13,14 @@
# You should have received a copy of the GNU Affero General Public License # 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/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
from ctypes import c_ubyte, c_uint, c_void_p, POINTER, addressof from ctypes import c_ubyte, c_ushort, c_void_p, POINTER, addressof
from engine import ( from engine import (
buffer, INSTANCE_FLAG_SPAWNED, BATCH_MAX_SIZE, param_type, params_format, buffer, INSTANCE_FLAG_SPAWNED, BATCH_MAX_SIZE, param_type, params_format,
create_batch, fill_batch, draw_batch, destroy_batch) create_batch, fill_batch, draw_batch, destroy_batch)
_c_ubyte_p = POINTER(c_ubyte) _flags_p = POINTER(c_ubyte)
_c_uint_p = POINTER(c_uint) _mesh_p = POINTER(c_ushort)
class Batch: class Batch:
__slots__ = ('_batch', 'vertices', 'max_size', 'size', __slots__ = ('_batch', 'vertices', 'max_size', 'size',
@ -37,9 +37,9 @@ class Batch:
self.max_size = max_size self.max_size = max_size
self.size = 0 self.size = 0
self.flags = buffer(c_ubyte, max_size) self.flags = buffer(c_ubyte, max_size)
self._flags = _c_ubyte_p(self.flags) self._flags = _flags_p(self.flags)
self.mesh = buffer(c_uint, max_size) self.mesh = buffer(c_ushort, max_size)
self._meshes = _c_uint_p(self.mesh) self._meshes = _mesh_p(self.mesh)
if nparams: if nparams:
self.param = tuple(map(lambda f: buffer(param_type(f), max_size), params_decls.values())) self.param = tuple(map(lambda f: buffer(param_type(f), max_size), params_decls.values()))
self._params = (c_void_p * nparams)(*map(addressof, self.param)) self._params = (c_void_p * nparams)(*map(addressof, self.param))
@ -66,9 +66,9 @@ class Batch:
def freeze(self, flags = None, mesh = None, **params): def freeze(self, flags = None, mesh = None, **params):
if flags is not None: if flags is not None:
self._flags = None if flags else _c_ubyte_p(self.flags) self._flags = None if flags else _flags_p(self.flags)
if mesh is not None: if mesh is not None:
self._meshes = None if mesh else _c_uint_p(self.mesh) self._meshes = None if mesh else _mesh_p(self.mesh)
for name, value in params.items(): for name, value in params.items():
if value is not None: if value is not None:
index = self._name[name] index = self._name[name]

View File

@ -56,6 +56,7 @@ class PerfGroup(Group):
self._name = name self._name = name
def __del__(self): def __del__(self):
if self._count:
avg = round(self._total / self._count, 2) avg = round(self._total / self._count, 2)
print(self._name, "*", self._count, print(self._name, "*", self._count,
": min =", round(self._min, 2), ", max =", round(self._max, 2), ", avg =", avg, "(ms)") ": min =", round(self._min, 2), ", max =", round(self._max, 2), ", avg =", avg, "(ms)")

View File

@ -139,7 +139,7 @@ class TextureData:
_write_blob(file, self.pixels) _write_blob(file, self.pixels)
class VerticesData: class VerticesData:
__slots__ = 'name', 'vertices', 'indices', 'meshes' __slots__ = 'name', 'vertices', 'indices', 'meshes', 'meshes_db'
def __init__(self, name, vertices, indices, meshes): def __init__(self, name, vertices, indices, meshes):
if len(vertices) % VERTEX_SIZE != 0: if len(vertices) % VERTEX_SIZE != 0:
@ -147,17 +147,18 @@ class VerticesData:
self.name = name self.name = name
self.vertices = vertices self.vertices = vertices
self.indices = indices self.indices = indices
self.meshes = meshes self.meshes = array('I', meshes.values())
self.meshes_db = dict(zip(meshes.keys(), range(len(meshes))))
def __iter__(self): def __iter__(self):
yield VERTEX_FORMAT yield VERTEX_FORMAT
yield len(self.vertices) // VERTEX_SIZE yield len(self.vertices) // VERTEX_SIZE
yield self.vertices yield self.vertices
yield self.indices yield self.indices
yield array('I', self.meshes.values()) yield self.meshes
def get_mesh(self, name): def get_mesh(self, name):
return self.meshes[name] return self.meshes_db[name]
@classmethod @classmethod
def from_archive(cls, file): def from_archive(cls, file):
@ -176,8 +177,8 @@ class VerticesData:
_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))
_write_array(file, self.vertices) _write_array(file, self.vertices)
_write_array(file, self.indices) _write_array(file, self.indices)
_write_array(file, array('I', self.meshes.values())) _write_array(file, self.meshes)
for name in self.meshes.keys(): for name in self.meshes_db.keys():
_write_string(file, name) _write_string(file, name)
class Archive: class Archive: