Compare commits
No commits in common. "cbae4ec0e7e0a1f69f501ee6f8e84543e77e0679" and "f487a4fcb75b0584a833b5c3af1781f81c0c2418" have entirely different histories.
cbae4ec0e7
...
f487a4fcb7
2
engine
2
engine
@ -1 +1 @@
|
|||||||
Subproject commit b46b4bddba6c609307ca198438c60d617e20c752
|
Subproject commit a5adfacdfd6dbb52bd5d1438eef90a370976531e
|
@ -19,10 +19,8 @@ from engine import (
|
|||||||
buffer, INSTANCE_FLAG_SPAWNED, BATCH_MAX_SIZE, param_type, params_format,
|
buffer, INSTANCE_FLAG_SPAWNED, BATCH_MAX_SIZE, param_type, params_format,
|
||||||
create_batch, fill_batch, draw_batch, destroy_batch)
|
create_batch, fill_batch, draw_batch, destroy_batch)
|
||||||
|
|
||||||
_flags_t = c_ubyte
|
_flags_p = POINTER(c_ubyte)
|
||||||
_flags_p = POINTER(_flags_t)
|
_mesh_p = POINTER(c_ushort)
|
||||||
_mesh_t = c_ushort
|
|
||||||
_mesh_p = POINTER(_mesh_t)
|
|
||||||
|
|
||||||
class Batch:
|
class Batch:
|
||||||
__slots__ = ('_batch', 'vertices', 'max_size', 'size',
|
__slots__ = ('_batch', 'vertices', 'max_size', 'size',
|
||||||
@ -38,9 +36,9 @@ class Batch:
|
|||||||
self.vertices = vertices
|
self.vertices = vertices
|
||||||
self.max_size = max_size
|
self.max_size = max_size
|
||||||
self.size = 0
|
self.size = 0
|
||||||
self.flags = buffer(_flags_t, max_size)
|
self.flags = buffer(c_ubyte, max_size)
|
||||||
self._flags = _flags_p(self.flags)
|
self._flags = _flags_p(self.flags)
|
||||||
self.mesh = buffer(_mesh_t, max_size)
|
self.mesh = buffer(c_ushort, max_size)
|
||||||
self._meshes = _mesh_p(self.mesh)
|
self._meshes = _mesh_p(self.mesh)
|
||||||
if nparams:
|
if nparams:
|
||||||
self.param = tuple(map(lambda f: buffer(param_type(f), max_size), params_decls.values()))
|
self.param = tuple(map(lambda f: buffer(param_type(f), max_size), params_decls.values()))
|
||||||
|
41
game/game.py
41
game/game.py
@ -129,15 +129,16 @@ 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 = archive.get_vertices('tiles')
|
tiles_vertices_data = archive.get_vertices('tiles')
|
||||||
water_mesh = tiles_vertices.get_mesh('water')
|
tiles_vertices = Vertices(*tiles_vertices_data)
|
||||||
sand_mesh = tiles_vertices.get_mesh('sand')
|
water_mesh = tiles_vertices_data.get_mesh('water')
|
||||||
grass_mesh = tiles_vertices.get_mesh('grass')
|
sand_mesh = tiles_vertices_data.get_mesh('sand')
|
||||||
forest_mesh = tiles_vertices.get_mesh('forest')
|
grass_mesh = tiles_vertices_data.get_mesh('grass')
|
||||||
rock_mesh = tiles_vertices.get_mesh('rock')
|
forest_mesh = tiles_vertices_data.get_mesh('forest')
|
||||||
mud_mesh = tiles_vertices.get_mesh('mud')
|
rock_mesh = tiles_vertices_data.get_mesh('rock')
|
||||||
lava_mesh = tiles_vertices.get_mesh('lava')
|
mud_mesh = tiles_vertices_data.get_mesh('mud')
|
||||||
tiles_batch = Batch(Vertices(*tiles_vertices), generated.size ** 2, translation = PARAM_FORMAT_VEC3_SHORT)
|
lava_mesh = tiles_vertices_data.get_mesh('lava')
|
||||||
|
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
|
||||||
@ -174,11 +175,12 @@ 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 = archive.get_vertices('tests')
|
tests_vertices_data = archive.get_vertices('tests')
|
||||||
blob_mesh = tests_vertices.get_mesh('blob')
|
tests_vertices = Vertices(*tests_vertices_data)
|
||||||
cube_mesh = tests_vertices.get_mesh('cube')
|
blob_mesh = tests_vertices_data.get_mesh('blob')
|
||||||
clouds_mesh = tests_vertices.get_mesh('clouds')
|
cube_mesh = tests_vertices_data.get_mesh('cube')
|
||||||
tests_batch = Batch(Vertices(*tests_vertices), 3,
|
clouds_mesh = tests_vertices_data.get_mesh('clouds')
|
||||||
|
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))
|
||||||
@ -190,8 +192,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 = 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'))
|
||||||
sea_detail = sea.load_detail_texture('data/sea_bump.png')
|
sea_detail_texture = 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
|
||||||
@ -213,7 +215,8 @@ 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({sea_shader.u_polar_sampler: sea_polar, sea_shader.u_detail_sampler: sea_detail},
|
TextureGroup(
|
||||||
|
{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',
|
||||||
@ -225,14 +228,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
|
||||||
|
|
||||||
|
@ -195,7 +195,7 @@ class ObjArchive(Archive):
|
|||||||
|
|
||||||
vertices = []
|
vertices = []
|
||||||
indices = []
|
indices = []
|
||||||
meshes = {}
|
models = {}
|
||||||
for name, mesh in sorted(objects.items()):
|
for name, mesh in sorted(objects.items()):
|
||||||
offset = len(indices)
|
offset = len(indices)
|
||||||
assert offset < 65536
|
assert offset < 65536
|
||||||
@ -213,7 +213,7 @@ class ObjArchive(Archive):
|
|||||||
assert count < 65536
|
assert count < 65536
|
||||||
vertices.extend(mesh_vertices)
|
vertices.extend(mesh_vertices)
|
||||||
indices.extend(mesh_indices)
|
indices.extend(mesh_indices)
|
||||||
meshes[name] = (offset, count)
|
models[name] = (offset, count)
|
||||||
|
|
||||||
name = str(objpath.stem)
|
name = str(objpath.stem)
|
||||||
assert name not in self.vertices_db.keys()
|
assert name not in self.vertices_db.keys()
|
||||||
@ -226,6 +226,9 @@ class ObjArchive(Archive):
|
|||||||
n = (pack_10(_nz) << 20) | (pack_10(_ny) << 10) | pack_10(_nx)
|
n = (pack_10(_nz) << 20) | (pack_10(_ny) << 10) | pack_10(_nx)
|
||||||
t = ((_tl & 1023) << 20) | (pack_u10(_t) << 10) | pack_u10(_s)
|
t = ((_tl & 1023) << 20) | (pack_u10(_t) << 10) | pack_u10(_s)
|
||||||
return struct.pack('fffII', _px, _py, _pz, n, t)
|
return struct.pack('fffII', _px, _py, _pz, n, t)
|
||||||
|
meshes = {}
|
||||||
|
for mesh_name, (offset, count) in sorted(models.items()):
|
||||||
|
meshes[mesh_name] = offset | (count << 16)
|
||||||
self.vertices_db[name] = VerticesData(name,
|
self.vertices_db[name] = VerticesData(name,
|
||||||
array('B', b''.join(starmap(pack_vertex, vertices))),
|
array('B', b''.join(starmap(pack_vertex, vertices))),
|
||||||
array('H', indices),
|
array('H', indices),
|
||||||
|
@ -13,7 +13,6 @@
|
|||||||
# You should have received a copy of the GNU Affero General Public License
|
# 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/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
from itertools import chain
|
|
||||||
import struct
|
import struct
|
||||||
from array import array
|
from array import array
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
@ -148,7 +147,7 @@ class VerticesData:
|
|||||||
self.name = name
|
self.name = name
|
||||||
self.vertices = vertices
|
self.vertices = vertices
|
||||||
self.indices = indices
|
self.indices = indices
|
||||||
self.meshes = meshes.values()
|
self.meshes = array('I', meshes.values())
|
||||||
self.meshes_db = dict(zip(meshes.keys(), range(len(meshes))))
|
self.meshes_db = dict(zip(meshes.keys(), range(len(meshes))))
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
@ -156,7 +155,7 @@ class VerticesData:
|
|||||||
yield len(self.vertices) // VERTEX_SIZE
|
yield len(self.vertices) // VERTEX_SIZE
|
||||||
yield self.vertices
|
yield self.vertices
|
||||||
yield self.indices
|
yield self.indices
|
||||||
yield array('I', chain.from_iterable(self.meshes))
|
yield self.meshes
|
||||||
|
|
||||||
def get_mesh(self, name):
|
def get_mesh(self, name):
|
||||||
return self.meshes_db[name]
|
return self.meshes_db[name]
|
||||||
@ -168,20 +167,19 @@ class VerticesData:
|
|||||||
nvertices, nindices, nmeshes = _read_struct(file, 'III')
|
nvertices, nindices, nmeshes = _read_struct(file, 'III')
|
||||||
vertices = _read_array(file, 'B', nvertices * VERTEX_SIZE)
|
vertices = _read_array(file, 'B', nvertices * VERTEX_SIZE)
|
||||||
indices = _read_array(file, 'H', nindices)
|
indices = _read_array(file, 'H', nindices)
|
||||||
|
meshes = _read_array(file, 'I', nmeshes)
|
||||||
names = [_read_string(file) for _ in range(nmeshes)]
|
names = [_read_string(file) for _ in range(nmeshes)]
|
||||||
meshes = [_read_struct(file, 'II') for _ in range(nmeshes)]
|
|
||||||
return cls(name, vertices, indices, dict(zip(names, meshes)))
|
return cls(name, vertices, indices, dict(zip(names, meshes)))
|
||||||
|
|
||||||
def to_archive(self, file):
|
def to_archive(self, file):
|
||||||
_write_magic(file, b'VERT')
|
_write_magic(file, b'VERT')
|
||||||
_write_string(file, self.name)
|
_write_string(file, self.name)
|
||||||
_write_struct(file, 'III', len(self.vertices) // VERTEX_SIZE, len(self.indices), len(self.meshes_db))
|
_write_struct(file, 'III', len(self.vertices) // VERTEX_SIZE, len(self.indices), len(self.meshes))
|
||||||
_write_array(file, self.vertices)
|
_write_array(file, self.vertices)
|
||||||
_write_array(file, self.indices)
|
_write_array(file, self.indices)
|
||||||
|
_write_array(file, self.meshes)
|
||||||
for name in self.meshes_db.keys():
|
for name in self.meshes_db.keys():
|
||||||
_write_string(file, name)
|
_write_string(file, name)
|
||||||
for mesh in self.meshes:
|
|
||||||
_write_struct(file, 'II', *mesh)
|
|
||||||
|
|
||||||
class Archive:
|
class Archive:
|
||||||
__slots__ = 'textures_db', 'vertices_db'
|
__slots__ = 'textures_db', 'vertices_db'
|
||||||
|
Loading…
Reference in New Issue
Block a user