Bump engine submodule and add static batch.
This commit is contained in:
parent
7219039980
commit
a96ea8bb6b
2
engine
2
engine
@ -1 +1 @@
|
|||||||
Subproject commit beca8798bf91edba954d31eb4e1a619ec2140c83
|
Subproject commit ed87f292ffa3cf89903cddcdec396115893f7d66
|
@ -15,11 +15,12 @@
|
|||||||
|
|
||||||
from ctypes import c_ubyte, c_uint, c_void_p, addressof
|
from ctypes import c_ubyte, c_uint, c_void_p, addressof
|
||||||
|
|
||||||
from engine import (vec3, mat3, buffer,
|
from engine import (
|
||||||
INSTANCE_FLAG_SPAWNED, BATCH_MAX_SIZE, param_type, params_format, create_batch, draw_batch, destroy_batch)
|
buffer, INSTANCE_FLAG_SPAWNED, BATCH_MAX_SIZE, param_type, params_format,
|
||||||
|
create_batch, fill_batch, draw_batch, destroy_batch)
|
||||||
|
|
||||||
class Batch:
|
class Batch:
|
||||||
__slots__ = '_batch', 'vertices', 'size', 'max_size', 'flags', 'meshes', 'params', '_params', '__dict__'
|
__slots__ = '_batch', '_static', 'vertices', 'size', 'max_size', 'flags', 'meshes', 'params', '_params', '__dict__'
|
||||||
|
|
||||||
def __init__(self, vertices, max_size, max_meshes, **params_decls):
|
def __init__(self, vertices, max_size, max_meshes, **params_decls):
|
||||||
assert max_size <= BATCH_MAX_SIZE
|
assert max_size <= BATCH_MAX_SIZE
|
||||||
@ -27,13 +28,17 @@ class Batch:
|
|||||||
names = params_decls.keys()
|
names = params_decls.keys()
|
||||||
formats = params_decls.values()
|
formats = params_decls.values()
|
||||||
self._batch = create_batch(vertices._vertices, max_size, max_meshes, params_format(*formats))
|
self._batch = create_batch(vertices._vertices, max_size, max_meshes, params_format(*formats))
|
||||||
|
self._static = False
|
||||||
self.vertices = vertices
|
self.vertices = vertices
|
||||||
self.size = 0
|
self.size = 0
|
||||||
self.max_size = max_size
|
self.max_size = max_size
|
||||||
self.flags = buffer(c_ubyte, max_size)
|
self.flags = buffer(c_ubyte, max_size)
|
||||||
self.meshes = buffer(c_uint, max_size)
|
self.meshes = buffer(c_uint, max_size)
|
||||||
self.params = tuple(map(lambda f: buffer(param_type(f), max_size), formats))
|
self.params = tuple(map(lambda f: buffer(param_type(f), max_size), formats))
|
||||||
|
if nparams:
|
||||||
self._params = (c_void_p * nparams)(*map(addressof, self.params))
|
self._params = (c_void_p * nparams)(*map(addressof, self.params))
|
||||||
|
else:
|
||||||
|
self._params = None
|
||||||
for name, value in zip(names, self.params):
|
for name, value in zip(names, self.params):
|
||||||
setattr(self, name, value)
|
setattr(self, name, value)
|
||||||
|
|
||||||
@ -51,5 +56,11 @@ class Batch:
|
|||||||
self.size += 1
|
self.size += 1
|
||||||
return index
|
return index
|
||||||
|
|
||||||
|
def make_static(self):
|
||||||
|
fill_batch(self._batch, self.size, self.flags, self.meshes, self._params)
|
||||||
|
self._static = True
|
||||||
|
|
||||||
def draw(self):
|
def draw(self):
|
||||||
draw_batch(self._batch, self.size, self.flags, self.meshes, self._params)
|
if not self._static:
|
||||||
|
fill_batch(self._batch, self.size, self.flags, self.meshes, self._params)
|
||||||
|
draw_batch(self._batch)
|
||||||
|
@ -166,6 +166,7 @@ def create_scene(keyboard, mouse):
|
|||||||
else:
|
else:
|
||||||
model = rock_model
|
model = rock_model
|
||||||
tiles_batch.spawn(model, vec3(float(((mx - 128) * 8) + 4), float(((127 - my) * 8) + 4), 0.0))
|
tiles_batch.spawn(model, vec3(float(((mx - 128) * 8) + 4), float(((127 - my) * 8) + 4), 0.0))
|
||||||
|
tiles_batch.make_static()
|
||||||
|
|
||||||
tests_texture = Texture(*archive.get_texture('tests'))
|
tests_texture = Texture(*archive.get_texture('tests'))
|
||||||
tests_vertices = Vertices(*archive.get_vertices('tests'))
|
tests_vertices = Vertices(*archive.get_vertices('tests'))
|
||||||
|
Loading…
Reference in New Issue
Block a user