Cleanup game script.

This commit is contained in:
Roz K 2023-01-04 09:38:27 +01:00
parent efdbbb5815
commit cbae4ec0e7
Signed by: roz
GPG Key ID: 51FBF4E483E1C822

View File

@ -129,16 +129,15 @@ def create_scene(keyboard, mouse):
print("Building tiles...") print("Building tiles...")
tiles_texture = Texture(*archive.get_texture('tiles')) tiles_texture = Texture(*archive.get_texture('tiles'))
tiles_vertices_data = archive.get_vertices('tiles') tiles_vertices = archive.get_vertices('tiles')
tiles_vertices = Vertices(*tiles_vertices_data) water_mesh = tiles_vertices.get_mesh('water')
water_mesh = tiles_vertices_data.get_mesh('water') sand_mesh = tiles_vertices.get_mesh('sand')
sand_mesh = tiles_vertices_data.get_mesh('sand') grass_mesh = tiles_vertices.get_mesh('grass')
grass_mesh = tiles_vertices_data.get_mesh('grass') forest_mesh = tiles_vertices.get_mesh('forest')
forest_mesh = tiles_vertices_data.get_mesh('forest') rock_mesh = tiles_vertices.get_mesh('rock')
rock_mesh = tiles_vertices_data.get_mesh('rock') mud_mesh = tiles_vertices.get_mesh('mud')
mud_mesh = tiles_vertices_data.get_mesh('mud') lava_mesh = tiles_vertices.get_mesh('lava')
lava_mesh = tiles_vertices_data.get_mesh('lava') tiles_batch = Batch(Vertices(*tiles_vertices), generated.size ** 2, translation = PARAM_FORMAT_VEC3_SHORT)
tiles_batch = Batch(tiles_vertices, generated.size ** 2, translation = PARAM_FORMAT_VEC3_SHORT)
#TODO: generator & for real #TODO: generator & for real
vc = generated.volcano_c vc = generated.volcano_c
@ -175,12 +174,11 @@ def create_scene(keyboard, mouse):
tiles_batch.freeze(flags = True, mesh = True, translation = True) tiles_batch.freeze(flags = True, mesh = True, translation = True)
tests_texture = Texture(*archive.get_texture('tests')) tests_texture = Texture(*archive.get_texture('tests'))
tests_vertices_data = archive.get_vertices('tests') tests_vertices = archive.get_vertices('tests')
tests_vertices = Vertices(*tests_vertices_data) blob_mesh = tests_vertices.get_mesh('blob')
blob_mesh = tests_vertices_data.get_mesh('blob') cube_mesh = tests_vertices.get_mesh('cube')
cube_mesh = tests_vertices_data.get_mesh('cube') clouds_mesh = tests_vertices.get_mesh('clouds')
clouds_mesh = tests_vertices_data.get_mesh('clouds') tests_batch = Batch(Vertices(*tests_vertices), 3,
tests_batch = Batch(tests_vertices, 3,
translation = PARAM_FORMAT_VEC3_FLOAT, translation = PARAM_FORMAT_VEC3_FLOAT,
orientation = PARAM_FORMAT_MAT3_INT10 | PARAM_FORMAT_NORMALIZE) orientation = PARAM_FORMAT_MAT3_INT10 | PARAM_FORMAT_NORMALIZE)
blob_forward = math.vec3_normalize((sun_direction[0], sun_direction[1], 0.0)) blob_forward = math.vec3_normalize((sun_direction[0], sun_direction[1], 0.0))
@ -192,8 +190,8 @@ def create_scene(keyboard, mouse):
tests_batch.fill() tests_batch.fill()
tests_batch.freeze(flags = True, mesh = True) tests_batch.freeze(flags = True, mesh = True)
sea_polar_textures = sea.load_polar_textures(('data/sea_bump1.png', 'data/sea_bump2.png')) sea_polar = sea.load_polar_textures(('data/sea_bump1.png', 'data/sea_bump2.png'))
sea_detail_texture = sea.load_detail_texture('data/sea_bump.png') sea_detail = sea.load_detail_texture('data/sea_bump.png')
sea_triangles = sea.sea_triangles(64, proj_far_z - 0.1, proj_ratio) sea_triangles = sea.sea_triangles(64, proj_far_z - 0.1, proj_ratio)
assert tiles_shader.u_height_sampler == tests_shader.u_height_sampler assert tiles_shader.u_height_sampler == tests_shader.u_height_sampler
@ -215,8 +213,7 @@ def create_scene(keyboard, mouse):
PerfGroup('tests_batch', PerfGroup('tests_batch',
DrawNode(tests_batch))))), DrawNode(tests_batch))))),
FuncNode(update_sea, (camera, sea_phase)), FuncNode(update_sea, (camera, sea_phase)),
TextureGroup( TextureGroup({sea_shader.u_polar_sampler: sea_polar, sea_shader.u_detail_sampler: sea_detail},
{sea_shader.u_polar_sampler: sea_polar_textures, sea_shader.u_detail_sampler: sea_detail_texture},
ShaderGroup(sea_shader, ShaderGroup(sea_shader,
InputNode(sea_shader, camera, environment, sea_phase), InputNode(sea_shader, camera, environment, sea_phase),
PerfGroup('sea_triangles', PerfGroup('sea_triangles',
@ -228,14 +225,14 @@ def loop(display):
mouse = Mouse(events, wheel = 60, wheel_min = 20) mouse = Mouse(events, wheel = 60, wheel_min = 20)
scene = create_scene(keyboard, mouse) scene = create_scene(keyboard, mouse)
print("Running... Ctrl+c to quit") print("Running... Ctrl+c to quit")
time = Time()
try: try:
time = Time()
while not keyboard.quit: while not keyboard.quit:
events.update() events.update()
time.update()
clear_buffer(True, True, True) clear_buffer(True, True, True)
scene.draw(time) scene.draw(time)
swap_buffers(display) swap_buffers(display)
time.update()
except KeyboardInterrupt: except KeyboardInterrupt:
pass pass