Compare commits

...

4 Commits

Author SHA1 Message Date
7ed23a5d5f
Terminate on key release. 2022-12-23 10:25:37 +01:00
34277274a3
Use the new buffer method to create ctypes arrays. 2022-12-23 10:24:21 +01:00
858dcd95bc
Bump engine submodule. 2022-12-23 10:23:32 +01:00
3e83c636ee
A little bit of clenaup. 2022-12-23 06:36:24 +01:00
3 changed files with 33 additions and 20 deletions

2
engine

@ -1 +1 @@
Subproject commit ccce6c5d83deb260d06bc525721e31c7c4edcabe Subproject commit 61cfdbccf3230b73d42eb90f6eec934dbe1ddfdb

View File

@ -14,10 +14,9 @@
# 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_uint, POINTER from ctypes import c_ubyte, c_uint, POINTER
from array import array
from engine import ( from engine import (
INSTANCE_FLAG_SPAWNED, BATCH_MAX_SIZE, create_batch, draw_batch, destroy_batch) INSTANCE_FLAG_SPAWNED, BATCH_MAX_SIZE, buffer, create_batch, draw_batch, destroy_batch)
class Batch: class Batch:
__slots__ = '_batch', '_paramsp', 'size', 'max_size', 'flags', 'meshes', 'params' __slots__ = '_batch', '_paramsp', 'size', 'max_size', 'flags', 'meshes', 'params'
@ -28,9 +27,9 @@ class Batch:
self._paramsp = POINTER(params_type) self._paramsp = POINTER(params_type)
self.size = 0 self.size = 0
self.max_size = max_size self.max_size = max_size
self.flags = (c_ubyte * max_size)() self.flags = buffer(c_ubyte, max_size)
self.meshes = (c_uint * max_size)() self.meshes = buffer(c_uint, max_size)
self.params = (params_type * max_size)() self.params = buffer(params_type, max_size)
def __del__(self): def __del__(self):
destroy_batch(self._batch) destroy_batch(self._batch)

View File

@ -20,12 +20,12 @@ from ctypes import Structure
from engine import * from engine import *
from game import math from game import math
from game import generator
from game import shader from game import shader
from game import resources
from game import batch
from game import triangles from game import triangles
from game import sea from game import sea
from game.generator import Generator
from game.resources import RuntimeArchive
from game.batch import Batch
from game.camera import Camera from game.camera import Camera
from game.environment import Environment from game.environment import Environment
@ -42,9 +42,9 @@ sun_power = 1.0
def main(): def main():
print("Generating terrain...") print("Generating terrain...")
gen_begin = time.process_time() gen_begin = time.thread_time()
generated = generator.Generator(256) generated = Generator(256)
gen_end = time.process_time() gen_end = time.thread_time()
print("Done: ", round(gen_end - gen_begin, 2), "seconds") print("Done: ", round(gen_end - gen_begin, 2), "seconds")
print("Initializing...") print("Initializing...")
@ -66,7 +66,7 @@ def main():
tests_normalmap_sampler = resolve_input(tests_shader, b'u_normal_sampler') tests_normalmap_sampler = resolve_input(tests_shader, b'u_normal_sampler')
print("Loading resources...") print("Loading resources...")
archive = resources.RuntimeArchive.load('data/rk_island.rkar') archive = RuntimeArchive.load('data/rk_island.rkar')
print("Building tiles...") print("Building tiles...")
tiles_texture = archive.get_texture('tiles') tiles_texture = archive.get_texture('tiles')
@ -79,7 +79,7 @@ def main():
rock_model = archive.get_model('rock') rock_model = archive.get_model('rock')
mud_model = archive.get_model('mud') mud_model = archive.get_model('mud')
lava_model = archive.get_model('lava') lava_model = archive.get_model('lava')
terrain_batch = batch.Batch(tiles_vertices, generated.size ** 2, params_format(PARAM_FORMAT_VEC3_SHORT), vec3) terrain_batch = Batch(tiles_vertices, generated.size ** 2, params_format(PARAM_FORMAT_VEC3_SHORT), vec3)
#TODO: generator & for real #TODO: generator & for real
vc = generated.volcano_c vc = generated.volcano_c
@ -112,7 +112,7 @@ def main():
model = rock_model model = rock_model
model.spawn(terrain_batch, vec3(float(((mx - 128) * 8) + 4), float(((127 - my) * 8) + 4), 0.0)) model.spawn(terrain_batch, vec3(float(((mx - 128) * 8) + 4), float(((127 - my) * 8) + 4), 0.0))
class testsparams(Structure): class TestsParams(Structure):
_fields_ = ('translation', vec3), ('orientation', vec3) _fields_ = ('translation', vec3), ('orientation', vec3)
tests_texture = archive.get_texture('tests') tests_texture = archive.get_texture('tests')
@ -121,14 +121,14 @@ def main():
blob_model = archive.get_model('blob') blob_model = archive.get_model('blob')
cube_model = archive.get_model('cube') cube_model = archive.get_model('cube')
clouds_model = archive.get_model('clouds') clouds_model = archive.get_model('clouds')
tests_batch = batch.Batch(tests_vertices, 3, tests_batch = Batch(tests_vertices, 3,
params_format(PARAM_FORMAT_VEC3_FLOAT, PARAM_FORMAT_VEC3_INT10 | PARAM_FORMAT_NORMALIZE), testsparams) params_format(PARAM_FORMAT_VEC3_FLOAT, PARAM_FORMAT_VEC3_INT10 | PARAM_FORMAT_NORMALIZE), TestsParams)
blob_spawn_translation = vec3(-100.0, -500.0, 0.0) blob_spawn_translation = vec3(-100.0, -500.0, 0.0)
cube_spawn_translation = vec3(100.0, -500.0, 0.0) cube_spawn_translation = vec3(100.0, -500.0, 0.0)
blob_id = blob_model.spawn(tests_batch, blob_id = blob_model.spawn(tests_batch,
testsparams(blob_spawn_translation, vec3(*math.vec3_normalize((sun_direction[0], sun_direction[1], 0.0))))) TestsParams(blob_spawn_translation, vec3(*math.vec3_normalize((sun_direction[0], sun_direction[1], 0.0)))))
cube_id = cube_model.spawn(tests_batch, testsparams(cube_spawn_translation, vec3_forward)) cube_id = cube_model.spawn(tests_batch, TestsParams(cube_spawn_translation, vec3_forward))
clouds_id = clouds_model.spawn(tests_batch, testsparams(vec3(0.0, 0.0, 32.0), vec3_forward)) clouds_id = clouds_model.spawn(tests_batch, TestsParams(vec3(0.0, 0.0, 32.0), vec3_forward))
sea_phase = resolve_input(sky_shader, b'u_sea_phase') 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')) sea_polar_textures = sea.load_polar_textures(('data/sea_bump1.png', 'data/sea_bump2.png'))
@ -154,6 +154,7 @@ def main():
clouds_orientation = tests_batch.params[clouds_id].orientation clouds_orientation = tests_batch.params[clouds_id].orientation
print("Running...") print("Running...")
events = buffer(Event, 16)
start_time = time.monotonic() start_time = time.monotonic()
current_time = 0.0 current_time = 0.0
frame_min = 10000.0 frame_min = 10000.0
@ -236,6 +237,19 @@ def main():
frame_max = max(frame_max, frame_ms) frame_max = max(frame_max, frame_ms)
frame_avg += frame_ms frame_avg += frame_ms
perf_count += 1 perf_count += 1
stop = False
while True:
nevents = consume_events(events, len(events))
if not nevents:
break
for event in events[:nevents]:
if event.type == EVENT_KEY_RELEASE:
print("EVENT_KEY_RELEASE:", event.data.key.keycode)
stop = True
if stop:
break
except KeyboardInterrupt: except KeyboardInterrupt:
pass pass