Compare commits

..

No commits in common. "f487a4fcb75b0584a833b5c3af1781f81c0c2418" and "78440cce1602ae81625a915aa89cfe0b2b33c9e7" have entirely different histories.

4 changed files with 18 additions and 20 deletions

2
engine

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

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_ushort, c_void_p, POINTER, addressof from ctypes import c_ubyte, c_uint, 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)
_flags_p = POINTER(c_ubyte) _c_ubyte_p = POINTER(c_ubyte)
_mesh_p = POINTER(c_ushort) _c_uint_p = POINTER(c_uint)
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 = _flags_p(self.flags) self._flags = _c_ubyte_p(self.flags)
self.mesh = buffer(c_ushort, max_size) self.mesh = buffer(c_uint, max_size)
self._meshes = _mesh_p(self.mesh) self._meshes = _c_uint_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 _flags_p(self.flags) self._flags = None if flags else _c_ubyte_p(self.flags)
if mesh is not None: if mesh is not None:
self._meshes = None if mesh else _mesh_p(self.mesh) self._meshes = None if mesh else _c_uint_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,10 +56,9 @@ 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)")
def draw(self, time): def draw(self, time):
begin = thread_time() begin = thread_time()

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', 'meshes_db' __slots__ = 'name', 'vertices', 'indices', 'meshes'
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,18 +147,17 @@ class VerticesData:
self.name = name self.name = name
self.vertices = vertices self.vertices = vertices
self.indices = indices self.indices = indices
self.meshes = array('I', meshes.values()) self.meshes = meshes
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 self.meshes yield array('I', self.meshes.values())
def get_mesh(self, name): def get_mesh(self, name):
return self.meshes_db[name] return self.meshes[name]
@classmethod @classmethod
def from_archive(cls, file): def from_archive(cls, file):
@ -177,8 +176,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, self.meshes) _write_array(file, array('I', self.meshes.values()))
for name in self.meshes_db.keys(): for name in self.meshes.keys():
_write_string(file, name) _write_string(file, name)
class Archive: class Archive: