work on world storage

This commit is contained in:
Tuomas Katajisto 2025-09-01 23:37:48 +03:00
parent 6b62b78595
commit 3f314c23c9
5 changed files with 8791 additions and 46 deletions

File diff suppressed because it is too large Load Diff

View File

@ -59,6 +59,7 @@ get_level_editor_camera :: () -> Camera {
return camera;
}
tick_level_editor_camera :: () {
if console_open_ignore_input then return;
@ -199,16 +200,26 @@ draw_tacoma_tab :: (theme: *GR.Overall_Theme, total_r: GR.Rect) {
#scope_export
add_trile :: (name: string, x: float, y: float, z: float) {
for world.positions {
if it.trileName == name {
array_add(*it.positions, Vector4.{x,y,z,1});
return;
}
}
poses := TrilePositions.{
trileName = name,
};
array_add(*poses.positions, Vector4.{x,y,z,1});
array_add(*world.positions, poses);
} @Command
tick_level_editor :: () {
tick_level_editor_camera();
}
draw_level_editor :: () {
positions : [4096]Vector4;
positions[0] = .{1, 0, 0, 1};
positions[1] = .{0, 1, 1, 1};
draw_sky(*get_level_editor_camera(), *world.conf);
cam := get_level_editor_camera();
mvp := create_viewproj(*cam);
@ -217,33 +228,37 @@ draw_level_editor :: () {
vs_params.mvp = mvp.floats;
vs_params.camera = cam.position.component;
trilegfx := get_trile_gfx(editor_current_trile.name);
sg_update_buffer(gPipelines.trile.bind.vertex_buffers[3], *(sg_range.{
ptr = positions.data,
size = size_of(type_of(positions)),
}));
sg_apply_pipeline(gPipelines.trile.pipeline);
world_conf : Trile_World_Config;
world_config_to_shader_type(*world.conf, *world_conf);
for world.positions {
positions : [4096]Vector4;
trilegfx := get_trile_gfx(it.trileName);
idx : s32 = 0;
for pos : it.positions {
positions[idx] = pos;
idx += 1;
}
bindings : sg_bindings;
bindings.vertex_buffers[0] = trilegfx.vertex_buffer;
bindings.vertex_buffers[1] = trilegfx.normal_buffer;
bindings.vertex_buffers[2] = trilegfx.centre_buffer;
bindings.vertex_buffers[3] = gPipelines.trile.bind.vertex_buffers[3];
bindings.samplers[0] = gPipelines.trile.bind.samplers[0];
bindings.images[0] = trilegfx.trixel_colors;
sg_update_buffer(gPipelines.trile.bind.vertex_buffers[3], *(sg_range.{
ptr = positions.data,
size = size_of(type_of(positions)),
}));
sg_apply_bindings(*bindings);
sg_apply_uniforms(UB_trile_vs_params, *(sg_range.{ ptr = *vs_params, size = size_of(type_of(vs_params))}));
sg_apply_uniforms(UB_trile_world_config, *(sg_range.{ptr = *world_conf, size = size_of(type_of(world_conf))}));
sg_draw(0, cast(s32) trilegfx.vertex_count, 2);
bindings : sg_bindings;
bindings.vertex_buffers[0] = trilegfx.vertex_buffer;
bindings.vertex_buffers[1] = trilegfx.normal_buffer;
bindings.vertex_buffers[2] = trilegfx.centre_buffer;
bindings.vertex_buffers[3] = gPipelines.trile.bind.vertex_buffers[3];
bindings.samplers[0] = gPipelines.trile.bind.samplers[0];
bindings.images[0] = trilegfx.trixel_colors;
sg_apply_bindings(*bindings);
sg_apply_uniforms(UB_trile_vs_params, *(sg_range.{ ptr = *vs_params, size = size_of(type_of(vs_params))}));
sg_apply_uniforms(UB_trile_world_config, *(sg_range.{ptr = *world_conf, size = size_of(type_of(world_conf))}));
sg_draw(0, cast(s32) trilegfx.vertex_count, idx+1);
}
}

View File

@ -259,7 +259,7 @@ draw_trile_editor :: () {
}
draw_trile :: () {
// if editor_current_trile == null then return;
if editor_current_trile == null then return;
cam := get_trile_editor_camera();
mvp := create_viewproj(*cam);

View File

@ -155,7 +155,7 @@ trile_from_serialize_form :: (ts: TrileSerialize) -> Trile {
matinfo := ts.trixels[i][j][k];
mat := material_from_rgba(matinfo[1], matinfo[2], matinfo[3], matinfo[4]);
t.trixels[i][j][k].material = mat;
t.trixels[i][j][k].empty = cast(bool) matinfo[0];
t.trixels[i][j][k].empty = matinfo[0] == 0;
}
}
}
@ -202,7 +202,6 @@ draw_trile_picker :: (theme: *GR.Overall_Theme) {
r.h = ui_h(4,4);
count := 0;
for v : tpt {
print("Current trile name: %\n", editor_current_trile.name);
if GR.button(r, v.name, *t_button_selectable(theme, editor_current_trile != null && editor_current_trile.name == v.name), count) {
editor_current_trile = get_trile(v.name);
}

View File

@ -32,23 +32,13 @@ world_config_to_shader_type :: (wc: *World_Config, data: *$T) {
#insert #run,stallable generate_copy_code();
}
IVector3 :: struct {
x: s32;
y: s32;
z: s32;
TrilePositions :: struct {
trileName: string;
positions: [..]Vector4;
}
ivec_comp :: (a: IVector3, b: IVector3) -> bool {
if a.x != b.x || a.y != b.y || a.z != b.z then return false;
return true;
}
ivec_hash :: (v: IVector3) -> u32 {
return sdbm_hash(*v, size_of(IVector3));
}
World :: struct {
conf : World_Config;
triles : Table(IVector3, string, ivec_hash, ivec_comp);
// @ToDo: Add a pool into here so we allocate all of the world stuff in it's own pool.
conf : World_Config;
positions : [..]TrilePositions;
}