Compare commits

...

3 Commits

3 changed files with 28 additions and 19 deletions

2
engine

@ -1 +1 @@
Subproject commit 7db5304d40013c7e4631b66ab5199f9bbd109285
Subproject commit 628f8bcaa4eb3c4da5a534b55d58218b894b9822

View File

@ -19,23 +19,28 @@ from engine import (vec3, mat3, buffer,
INSTANCE_FLAG_SPAWNED, BATCH_MAX_SIZE, param_type, params_format, create_batch, draw_batch, destroy_batch)
class Batch:
__slots__ = '_batch', 'size', 'max_size', 'flags', 'meshes', 'params', '_params'
__slots__ = '_batch', 'size', 'max_size', 'flags', 'meshes', 'params', '_params', '__dict__'
def __init__(self, vertices, max_size, *params_formats):
def __init__(self, vertices, max_size, **params_decls):
assert max_size <= BATCH_MAX_SIZE
nparams = len(params_formats)
self._batch = create_batch(vertices, max_size, params_format(*params_formats))
nparams = len(params_decls)
names = params_decls.keys()
formats = params_decls.values()
self._batch = create_batch(vertices, max_size, params_format(*formats))
self.size = 0
self.max_size = max_size
self.flags = buffer(c_ubyte, max_size)
self.meshes = buffer(c_uint, max_size)
self.params = tuple(map(lambda f: buffer(param_type(f), max_size), params_formats))
self.params = tuple(map(lambda f: buffer(param_type(f), max_size), formats))
self._params = (c_void_p * nparams)(*map(addressof, self.params))
for name, value in zip(names, self.params):
setattr(self, name, value)
def __del__(self):
destroy_batch(self._batch)
def append(self, flags, mesh, params):
assert len(params) == len(self.params)
index = self.size
assert index < self.max_size
self.flags[index] = flags | INSTANCE_FLAG_SPAWNED

View File

@ -53,7 +53,7 @@ def main():
events = Events(display)
mouse = Mouse(events, wheel = 60, wheel_min = 20)
keyboard = Keyboard(events)
render_initialize()
render_initialize(__debug__)
terrain_shader = shader.load('terrain', 'common')
tests_shader = shader.load('tests', 'common')
sky_shader = shader.load('sky')
@ -84,7 +84,7 @@ def main():
rock_model = archive.get_model('rock')
mud_model = archive.get_model('mud')
lava_model = archive.get_model('lava')
terrain_batch = Batch(tiles_vertices, generated.size ** 2, PARAM_FORMAT_VEC3_SHORT)
terrain_batch = Batch(tiles_vertices, generated.size ** 2, translation = PARAM_FORMAT_VEC3_SHORT)
#TODO: generator & for real
vc = generated.volcano_c
@ -123,7 +123,9 @@ def main():
blob_model = archive.get_model('blob')
cube_model = archive.get_model('cube')
clouds_model = archive.get_model('clouds')
tests_batch = Batch(tests_vertices, 3, PARAM_FORMAT_VEC3_FLOAT, PARAM_FORMAT_MAT3_INT10 | PARAM_FORMAT_NORMALIZE)
tests_batch = Batch(tests_vertices, 3,
translation = PARAM_FORMAT_VEC3_FLOAT,
orientation = PARAM_FORMAT_MAT3_INT10 | PARAM_FORMAT_NORMALIZE)
blob_spawn_translation = vec3(-100.0, -500.0, 0.0)
cube_spawn_translation = vec3(100.0, -500.0, 0.0)
blob_forward = math.vec3_normalize((sun_direction[0], sun_direction[1], 0.0))
@ -151,10 +153,10 @@ def main():
tests_environment_inputs = environment.resolve_inputs(tests_shader)
sky_environment_inputs = environment.resolve_inputs(sky_shader)
blob_translation = tests_batch.params[0][blob_id]
cube_translation = tests_batch.params[0][cube_id]
cube_orientation = tests_batch.params[1][cube_id]
clouds_orientation = tests_batch.params[1][clouds_id]
blob_translation = tests_batch.translation[blob_id]
cube_translation = tests_batch.translation[cube_id]
cube_orientation = tests_batch.orientation[cube_id]
clouds_orientation = tests_batch.orientation[clouds_id]
print("Running... Ctrl+c to quit")
start_time = time.monotonic()
@ -264,14 +266,16 @@ def main():
", avg =", round((frame_avg / perf_count) * 1000.0, 2), "ms")
# seed 666
# for _ in range(10000):
# current_time = 0 # time.monotonic() - start_time
# Draw * 9999 : min = 0.2 , max = 1.32 , avg = 0.27 ms
# Draw * 9999 : min = 0.2 , max = 1.34 , avg = 0.27 ms
# Draw * 9999 : min = 0.2 , max = 1.42 , avg = 0.27 ms
# Draw * 9999 : min = 0.14 , max = 0.86 , avg = 0.2 ms
# Draw * 9999 : min = 0.14 , max = 0.93 , avg = 0.2 ms
# Draw * 9999 : min = 0.14 , max = 0.77 , avg = 0.2 ms
# Frame * 9999 : min = 0.26 , max = 1.39 , avg = 0.37 ms
# Frame * 9999 : min = 0.26 , max = 1.45 , avg = 0.36 ms
# Frame * 9999 : min = 0.26 , max = 1.56 , avg = 0.36 ms
# Frame * 9999 : min = 0.20 , max = 0.95 , avg = 0.34 ms
# Frame * 9999 : min = 0.21 , max = 1.03 , avg = 0.34 ms
# Frame * 9999 : min = 0.21 , max = 1.09 , avg = 0.34 ms
print("Quitting...")
del tests_batch