Bump engine submodule and switch to custom instance parameters.
This commit is contained in:
parent
48714afaf5
commit
6d9429546c
2
engine
2
engine
@ -1 +1 @@
|
|||||||
Subproject commit 8f3612bed26d4bdb9f6c62541bf6068285f760b3
|
Subproject commit 3df976c154f76351702fe9f512f09c072dd67f60
|
@ -16,43 +16,35 @@
|
|||||||
from array import array
|
from array import array
|
||||||
|
|
||||||
from engine import (
|
from engine import (
|
||||||
INSTANCE_FLAG_SPAWNED, BATCH_MAX_SIZE, BATCH_ORIENTATION_FORMAT_NONE, create_batch, draw_batch, destroy_batch)
|
INSTANCE_FLAG_SPAWNED, BATCH_MAX_SIZE, create_batch, draw_batch, destroy_batch)
|
||||||
|
|
||||||
class Batch:
|
class Batch:
|
||||||
__slots__ = '_batch', 'max_size', 'flags', 'meshes', 'translations', 'orientations'
|
__slots__ = '_batch', 'max_size', 'flags', 'meshes', 'params'
|
||||||
|
|
||||||
def __init__(self, max_size, translation_format, orientation_format):
|
def __init__(self, max_size, params_format):
|
||||||
assert max_size <= BATCH_MAX_SIZE
|
assert max_size <= BATCH_MAX_SIZE
|
||||||
self._batch = create_batch(max_size, translation_format, orientation_format)
|
self._batch = create_batch(max_size, params_format)
|
||||||
self.max_size = max_size
|
self.max_size = max_size
|
||||||
self.flags = array('B')
|
self.flags = array('B')
|
||||||
self.meshes = array('I')
|
self.meshes = array('I')
|
||||||
self.translations = array('f')
|
self.params = [array('f') for _ in params_format]
|
||||||
if orientation_format != BATCH_ORIENTATION_FORMAT_NONE:
|
|
||||||
self.orientations = array('f')
|
|
||||||
else:
|
|
||||||
self.orientations = None
|
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
destroy_batch(self._batch)
|
destroy_batch(self._batch)
|
||||||
|
|
||||||
def append(self, flags, mesh, translation, orientation):
|
def append(self, flags, mesh, params):
|
||||||
assert len(translation) == 3
|
assert len(params) == len(self.params)
|
||||||
assert orientation is None or len(orientation) == 3
|
|
||||||
index = len(self.flags)
|
index = len(self.flags)
|
||||||
assert index < self.max_size
|
assert index < self.max_size
|
||||||
self.flags.append(flags | INSTANCE_FLAG_SPAWNED)
|
self.flags.append(flags | INSTANCE_FLAG_SPAWNED)
|
||||||
self.meshes.append(mesh)
|
self.meshes.append(mesh)
|
||||||
self.translations.extend(translation)
|
for _params, param in zip(self.params, params):
|
||||||
if self.orientations is not None:
|
_params.extend(param)
|
||||||
self.orientations.extend(orientation)
|
|
||||||
return index
|
return index
|
||||||
|
|
||||||
def set_translation(self, index, translation):
|
def set_param(self, param, index, value):
|
||||||
self.translations[index * 3 : index * 3 + 3] = translation
|
size = len(value)
|
||||||
|
self.params[param][index * size : index * size + size] = value
|
||||||
def set_orientation(self, index, orientation):
|
|
||||||
self.orientations[index * 3 : index * 3 + 3] = orientation
|
|
||||||
|
|
||||||
def draw(self):
|
def draw(self):
|
||||||
draw_batch(self._batch, self.flags, self.meshes, self.translations, self.orientations)
|
draw_batch(self._batch, self.flags, self.meshes, self.params)
|
||||||
|
53
game/game.py
53
game/game.py
@ -33,8 +33,10 @@ def main():
|
|||||||
terrain_shader = shader.load('terrain')
|
terrain_shader = shader.load('terrain')
|
||||||
sky_shader = shader.load('sky')
|
sky_shader = shader.load('sky')
|
||||||
|
|
||||||
print("Loading resources...")
|
|
||||||
select_shader(terrain_shader)
|
select_shader(terrain_shader)
|
||||||
|
terrain_environment_inputs = environment.resolve_inputs()
|
||||||
|
|
||||||
|
print("Loading resources...")
|
||||||
archive = resources.RuntimeArchive.load('data/rk_island.rkar')
|
archive = resources.RuntimeArchive.load('data/rk_island.rkar')
|
||||||
tiles_texture = archive.get_texture('tiles')
|
tiles_texture = archive.get_texture('tiles')
|
||||||
tiles_vertices = archive.get_vertices('tiles')
|
tiles_vertices = archive.get_vertices('tiles')
|
||||||
@ -45,28 +47,19 @@ def main():
|
|||||||
rock = archive.get_model('rock')
|
rock = archive.get_model('rock')
|
||||||
mud = archive.get_model('mud')
|
mud = archive.get_model('mud')
|
||||||
lava = archive.get_model('lava')
|
lava = archive.get_model('lava')
|
||||||
|
|
||||||
heightmap = create_texture(1, b'u_height_sampler',
|
heightmap = create_texture(1, b'u_height_sampler',
|
||||||
TEXTURE_FORMAT_32F, 256, 256, 0, TEXTURE_FLAG_MIN_LINEAR | TEXTURE_FLAG_MAG_LINEAR,
|
TEXTURE_FORMAT_32F, 256, 256, 0, TEXTURE_FLAG_MIN_LINEAR | TEXTURE_FLAG_MAG_LINEAR,
|
||||||
generated.packed_heights)
|
generated.packed_heights)
|
||||||
normalmap = create_texture(2, b'u_normal_sampler',
|
normalmap = create_texture(2, b'u_normal_sampler',
|
||||||
TEXTURE_FORMAT_RGB10_A2, 256, 256, 0, TEXTURE_FLAG_MIN_LINEAR | TEXTURE_FLAG_MAG_LINEAR,
|
TEXTURE_FORMAT_RGB10_A2, 256, 256, 0, TEXTURE_FLAG_MIN_LINEAR | TEXTURE_FLAG_MAG_LINEAR,
|
||||||
generated.packed_normals)
|
generated.packed_normals)
|
||||||
select_vertices(tiles_vertices)
|
|
||||||
terrain_batch = batch.Batch(
|
|
||||||
generated.size ** 2, BATCH_TRANSLATION_FORMAT_SHORT, BATCH_ORIENTATION_FORMAT_NONE)
|
|
||||||
unselect_vertices(tiles_vertices)
|
|
||||||
terrain_environment_inputs = environment.resolve_inputs()
|
|
||||||
tests_texture = archive.get_texture('tests')
|
|
||||||
tests_vertices = archive.get_vertices('tests')
|
|
||||||
blob = archive.get_model('blob')
|
|
||||||
cube = archive.get_model('cube')
|
|
||||||
clouds = archive.get_model('clouds')
|
|
||||||
select_vertices(tests_vertices)
|
|
||||||
tests_batch = batch.Batch(3, BATCH_TRANSLATION_FORMAT_FLOAT, BATCH_ORIENTATION_FORMAT_FLOAT)
|
|
||||||
unselect_vertices(tests_vertices)
|
|
||||||
|
|
||||||
#TODO: generator & for real
|
#TODO: generator & for real
|
||||||
print("Building tiles...")
|
print("Building tiles...")
|
||||||
|
select_vertices(tiles_vertices)
|
||||||
|
terrain_orientation = resolve_param(b'i_orientation')
|
||||||
|
terrain_batch = batch.Batch(generated.size ** 2, params_format(PARAM_FORMAT_VEC3_SHORT))
|
||||||
vc = generated.volcano_c
|
vc = generated.volcano_c
|
||||||
vr = generated.volcano_r
|
vr = generated.volcano_r
|
||||||
for my, mx in generated.map_coords:
|
for my, mx in generated.map_coords:
|
||||||
@ -95,15 +88,24 @@ def main():
|
|||||||
model = mud
|
model = mud
|
||||||
else:
|
else:
|
||||||
model = rock
|
model = rock
|
||||||
model.spawn(terrain_batch, (float(((mx - 128) * 8) + 4), float(((127 - my) * 8) + 4), 0.0), None)
|
model.spawn(terrain_batch, (float(((mx - 128) * 8) + 4), float(((127 - my) * 8) + 4), 0.0))
|
||||||
|
unselect_vertices(tiles_vertices)
|
||||||
|
|
||||||
|
tests_texture = archive.get_texture('tests')
|
||||||
|
tests_vertices = archive.get_vertices('tests')
|
||||||
|
blob = archive.get_model('blob')
|
||||||
|
cube = archive.get_model('cube')
|
||||||
|
clouds = archive.get_model('clouds')
|
||||||
|
select_vertices(tests_vertices)
|
||||||
|
tests_batch = batch.Batch(3, params_format(PARAM_FORMAT_VEC3_FLOAT, PARAM_FORMAT_VEC3_FLOAT))
|
||||||
blob_translation = vec3((-100.0, -500.0, 0.0))
|
blob_translation = vec3((-100.0, -500.0, 0.0))
|
||||||
cube_translation = vec3((100.0, -500.0, 0.0))
|
cube_translation = vec3((100.0, -500.0, 0.0))
|
||||||
cube_orientation = vec3(vec3_forward)
|
cube_orientation = vec3(vec3_forward)
|
||||||
clouds_orientation = vec3(vec3_forward)
|
clouds_orientation = vec3(vec3_forward)
|
||||||
blob_id = blob.spawn(tests_batch, blob_translation)
|
blob_id = blob.spawn(tests_batch, blob_translation, vec3_forward)
|
||||||
cube_id = cube.spawn(tests_batch, cube_translation, cube_orientation)
|
cube_id = cube.spawn(tests_batch, cube_translation, cube_orientation)
|
||||||
clouds_id = clouds.spawn(tests_batch, (0.0, 0.0, 32.0), clouds_orientation)
|
clouds_id = clouds.spawn(tests_batch, (0.0, 0.0, 32.0), clouds_orientation)
|
||||||
|
unselect_vertices(tests_vertices)
|
||||||
|
|
||||||
proj_hfov = pi * 0.25
|
proj_hfov = pi * 0.25
|
||||||
proj_ratio = 16.0 / 9.0
|
proj_ratio = 16.0 / 9.0
|
||||||
@ -123,7 +125,7 @@ def main():
|
|||||||
sky_camera.set_projection(proj_hfov, proj_ratio, proj_near_z, proj_far_z)
|
sky_camera.set_projection(proj_hfov, proj_ratio, proj_near_z, proj_far_z)
|
||||||
unselect_shader(sky_shader)
|
unselect_shader(sky_shader)
|
||||||
|
|
||||||
sun_direction = vec3(math.vec3_normalize((1.0, 0.0, 0.0)))
|
sun_direction = vec3(math.vec3_normalize((1.0, 0.0, 0.25)))
|
||||||
sun_power = 1.0
|
sun_power = 1.0
|
||||||
origin = vec3((0.0, -1200.0, 500.0))
|
origin = vec3((0.0, -1200.0, 500.0))
|
||||||
lookat = vec3((0.0, 500.0, -500.0))
|
lookat = vec3((0.0, 500.0, -500.0))
|
||||||
@ -160,16 +162,16 @@ def main():
|
|||||||
|
|
||||||
mat3_rotation(_rotation, up, (current_time * 0.21) % tau)
|
mat3_rotation(_rotation, up, (current_time * 0.21) % tau)
|
||||||
mat3_mul_vec3(_blob_translation, _rotation, blob_translation)
|
mat3_mul_vec3(_blob_translation, _rotation, blob_translation)
|
||||||
tests_batch.set_translation(blob_id, _blob_translation)
|
tests_batch.set_param(0, blob_id, _blob_translation)
|
||||||
tests_batch.set_orientation(blob_id, vec3(math.vec3_normalize((sun_direction[0], sun_direction[1], 0.0))))
|
tests_batch.set_param(1, blob_id, vec3(math.vec3_normalize((sun_direction[0], sun_direction[1], 0.0))))
|
||||||
mat3_mul_vec3(_cube_translation, _rotation, cube_translation)
|
mat3_mul_vec3(_cube_translation, _rotation, cube_translation)
|
||||||
tests_batch.set_translation(cube_id, _cube_translation)
|
tests_batch.set_param(0, cube_id, _cube_translation)
|
||||||
mat3_rotation(_rotation, up, (current_time * 0.43) % tau)
|
mat3_rotation(_rotation, up, (current_time * 0.43) % tau)
|
||||||
mat3_mul_vec3(_cube_orientation, _rotation, cube_orientation)
|
mat3_mul_vec3(_cube_orientation, _rotation, cube_orientation)
|
||||||
tests_batch.set_orientation(cube_id, _cube_orientation)
|
tests_batch.set_param(1, cube_id, _cube_orientation)
|
||||||
mat3_rotation(_rotation, up, (current_time * -0.037) % tau)
|
mat3_rotation(_rotation, up, (current_time * -0.037) % tau)
|
||||||
mat3_mul_vec3(_clouds_orientation, _rotation, clouds_orientation)
|
mat3_mul_vec3(_clouds_orientation, _rotation, clouds_orientation)
|
||||||
tests_batch.set_orientation(clouds_id, _clouds_orientation)
|
tests_batch.set_param(1, clouds_id, _clouds_orientation)
|
||||||
|
|
||||||
select_shader(terrain_shader)
|
select_shader(terrain_shader)
|
||||||
select_texture(heightmap)
|
select_texture(heightmap)
|
||||||
@ -177,12 +179,12 @@ def main():
|
|||||||
|
|
||||||
terrain_camera.set_view(_origin, _lookat)
|
terrain_camera.set_view(_origin, _lookat)
|
||||||
terrain_camera.update_inputs()
|
terrain_camera.update_inputs()
|
||||||
environment_values = environment.from_sun(
|
environment_values = environment.from_sun(terrain_camera.view, sun_direction, sun_power)
|
||||||
terrain_camera.view, sun_direction, sun_power)
|
|
||||||
environment.update_inputs(terrain_environment_inputs, environment_values)
|
environment.update_inputs(terrain_environment_inputs, environment_values)
|
||||||
|
|
||||||
select_texture(tiles_texture)
|
select_texture(tiles_texture)
|
||||||
select_vertices(tiles_vertices)
|
select_vertices(tiles_vertices)
|
||||||
|
set_param_vec3(terrain_orientation, vec3(vec3_forward))
|
||||||
draw_begin = time.thread_time()
|
draw_begin = time.thread_time()
|
||||||
terrain_batch.draw()
|
terrain_batch.draw()
|
||||||
draw_end = time.thread_time()
|
draw_end = time.thread_time()
|
||||||
@ -204,8 +206,7 @@ def main():
|
|||||||
vec3(math.vec3_scale(_origin, 0.001)),
|
vec3(math.vec3_scale(_origin, 0.001)),
|
||||||
vec3(math.vec3_scale(_lookat, 0.001)))
|
vec3(math.vec3_scale(_lookat, 0.001)))
|
||||||
sky_camera.update_inputs()
|
sky_camera.update_inputs()
|
||||||
environment_values = environment.from_sun(
|
environment_values = environment.from_sun(sky_camera.view, sun_direction, sun_power)
|
||||||
sky_camera.view, sun_direction, sun_power)
|
|
||||||
environment.update_inputs(sky_environment_inputs, environment_values)
|
environment.update_inputs(sky_environment_inputs, environment_values)
|
||||||
set_input_float(sea_phase, (current_time * 0.023) % 1.0)
|
set_input_float(sea_phase, (current_time * 0.023) % 1.0)
|
||||||
select_texture(sea_polar_textures)
|
select_texture(sea_polar_textures)
|
||||||
|
@ -192,8 +192,8 @@ class Model:
|
|||||||
self.flags = flags
|
self.flags = flags
|
||||||
self.mesh = mesh
|
self.mesh = mesh
|
||||||
|
|
||||||
def spawn(self, batch, translation = engine.vec3_zero, orientation = engine.vec3_forward):
|
def spawn(self, batch, *params):
|
||||||
return batch.append(self.flags, self.mesh, translation, orientation)
|
return batch.append(self.flags, self.mesh, params)
|
||||||
|
|
||||||
def create_model(data):
|
def create_model(data):
|
||||||
return Model(data.flags, data.mesh)
|
return Model(data.flags, data.mesh)
|
||||||
|
Loading…
Reference in New Issue
Block a user