Bump engine submodule and switch back to SoA parameters.
This commit is contained in:
parent
66a099e51f
commit
8e020915a6
2
engine
2
engine
@ -1 +1 @@
|
||||
Subproject commit 414630ecfd64ba443770ddafd15c67397073b4b8
|
||||
Subproject commit 7db5304d40013c7e4631b66ab5199f9bbd109285
|
@ -13,23 +13,24 @@
|
||||
# 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/>.
|
||||
|
||||
from ctypes import c_ubyte, c_uint, POINTER
|
||||
from ctypes import c_ubyte, c_uint, c_void_p, addressof
|
||||
|
||||
from engine import (
|
||||
INSTANCE_FLAG_SPAWNED, BATCH_MAX_SIZE, buffer, create_batch, draw_batch, destroy_batch)
|
||||
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', '_paramsp', 'size', 'max_size', 'flags', 'meshes', 'params'
|
||||
__slots__ = '_batch', 'size', 'max_size', 'flags', 'meshes', 'params', '_params'
|
||||
|
||||
def __init__(self, vertices, max_size, params_format, params_type):
|
||||
def __init__(self, vertices, max_size, *params_formats):
|
||||
assert max_size <= BATCH_MAX_SIZE
|
||||
self._batch = create_batch(vertices, max_size, params_format)
|
||||
self._paramsp = POINTER(params_type)
|
||||
nparams = len(params_formats)
|
||||
self._batch = create_batch(vertices, max_size, params_format(*params_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 = buffer(params_type, max_size)
|
||||
self.params = tuple(map(lambda f: buffer(param_type(f), max_size), params_formats))
|
||||
self._params = (c_void_p * nparams)(*map(addressof, self.params))
|
||||
|
||||
def __del__(self):
|
||||
destroy_batch(self._batch)
|
||||
@ -39,9 +40,10 @@ class Batch:
|
||||
assert index < self.max_size
|
||||
self.flags[index] = flags | INSTANCE_FLAG_SPAWNED
|
||||
self.meshes[index] = mesh
|
||||
self.params[index] = params
|
||||
for self_params, param in zip(self.params, params):
|
||||
self_params[index] = param
|
||||
self.size += 1
|
||||
return index
|
||||
|
||||
def draw(self):
|
||||
draw_batch(self._batch, self.size, self.flags, self.meshes, self._paramsp(self.params))
|
||||
draw_batch(self._batch, self.size, self.flags, self.meshes, self._params)
|
||||
|
22
game/game.py
22
game/game.py
@ -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, params_format(PARAM_FORMAT_VEC3_SHORT), vec3)
|
||||
terrain_batch = Batch(tiles_vertices, generated.size ** 2, PARAM_FORMAT_VEC3_SHORT)
|
||||
|
||||
#TODO: generator & for real
|
||||
vc = generated.volcano_c
|
||||
@ -117,25 +117,21 @@ def main():
|
||||
model = rock_model
|
||||
model.spawn(terrain_batch, vec3(float(((mx - 128) * 8) + 4), float(((127 - my) * 8) + 4), 0.0))
|
||||
|
||||
class TestsParams(Structure):
|
||||
_fields_ = ('translation', vec3), ('orientation', mat3)
|
||||
|
||||
tests_texture = archive.get_texture('tests')
|
||||
tests_sampler = resolve_input(tests_shader, b'u_texture_sampler')
|
||||
tests_vertices = archive.get_vertices('tests')
|
||||
blob_model = archive.get_model('blob')
|
||||
cube_model = archive.get_model('cube')
|
||||
clouds_model = archive.get_model('clouds')
|
||||
tests_batch = Batch(tests_vertices, 3,
|
||||
params_format(PARAM_FORMAT_VEC3_FLOAT, PARAM_FORMAT_MAT3_INT10 | PARAM_FORMAT_NORMALIZE), TestsParams)
|
||||
tests_batch = Batch(tests_vertices, 3, PARAM_FORMAT_VEC3_FLOAT, 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))
|
||||
blob_right = math.vec3_cross(blob_forward, math.vec3_up)
|
||||
blob_id = blob_model.spawn(tests_batch,
|
||||
TestsParams(blob_spawn_translation, mat3(vec3(*blob_right), vec3(*blob_forward), vec3_up)))
|
||||
cube_id = cube_model.spawn(tests_batch, TestsParams(cube_spawn_translation, mat3_identity))
|
||||
clouds_id = clouds_model.spawn(tests_batch, TestsParams(vec3(0.0, 0.0, 32.0), mat3_identity))
|
||||
blob_spawn_translation, mat3(vec3(*blob_right), vec3(*blob_forward), vec3_up))
|
||||
cube_id = cube_model.spawn(tests_batch, cube_spawn_translation, mat3_identity)
|
||||
clouds_id = clouds_model.spawn(tests_batch, vec3(0.0, 0.0, 32.0), mat3_identity)
|
||||
|
||||
sea_phase = resolve_input(sky_shader, b'u_sea_phase')
|
||||
sea_polar_textures = sea.load_polar_textures(('data/sea_bump1.png', 'data/sea_bump2.png'))
|
||||
@ -155,10 +151,10 @@ def main():
|
||||
tests_environment_inputs = environment.resolve_inputs(tests_shader)
|
||||
sky_environment_inputs = environment.resolve_inputs(sky_shader)
|
||||
|
||||
blob_translation = tests_batch.params[blob_id].translation
|
||||
cube_translation = tests_batch.params[cube_id].translation
|
||||
cube_orientation = tests_batch.params[cube_id].orientation
|
||||
clouds_orientation = tests_batch.params[clouds_id].orientation
|
||||
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]
|
||||
|
||||
print("Running... Ctrl+c to quit")
|
||||
start_time = time.monotonic()
|
||||
|
@ -191,7 +191,7 @@ class Model:
|
||||
self.flags = flags
|
||||
self.mesh = mesh
|
||||
|
||||
def spawn(self, batch, params):
|
||||
def spawn(self, batch, *params):
|
||||
return batch.append(self.flags, self.mesh, params)
|
||||
|
||||
def create_model(data):
|
||||
|
Loading…
Reference in New Issue
Block a user