Scene loading fixes

This commit is contained in:
Daniel Bross
2025-01-09 22:02:23 +01:00
parent 4d97d7bc39
commit 040a5fa23a
5 changed files with 21 additions and 4 deletions

View File

@@ -29,8 +29,9 @@ cmd_new_scene :: (arguments: [] string) {
unload_scene(engine.current_scene);
}
engine.current_scene = create_scene(arguments[0]);
make_directory_if_it_does_not_exist(scene_path);
engine.current_scene = create_scene(arguments[0]);
switch_to_scene(arguments[0]);
console_success("Scene '%' loaded\n", arguments[0]);

View File

@@ -33,6 +33,8 @@ Particle_System :: struct {
_locator: Bucket_Locator;
on_particle_update: (*Particle_System, float);
scene: *Scene;
}
create_particle_system :: (pipeline: Pipeline_State_Handle, update_func: (*Particle_System, float), owning_entity: *Entity = null, scene: *Scene = null) -> *Particle_System {
@@ -43,9 +45,15 @@ create_particle_system :: (pipeline: Pipeline_State_Handle, update_func: (*Parti
particle_system.pipeline = pipeline;
particle_system.on_particle_update = update_func;
particle_system.owning_entity = owning_entity;
particle_system.scene = scene;
return particle_system;
}
destroy_particle_system :: (system: *Particle_System) {
destroy_buffer(engine.renderer, system.vertex_buffer);
bucket_array_remove(*system.scene.particle_systems, system._locator);
}
spawn_particle :: (system: *Particle_System, position: Vector3, velocity: Vector3 = .{0,0,0}, size: float = 1.0, lifetime: float = 1.0, color: Vector4 = .{1,1,1,1}) {
particle: Particle;
particle.position = position;

View File

@@ -10,7 +10,7 @@ Scene :: struct {
entities : [..] *Entity;
particle_systems : Bucket_Array(Particle_System, 64);
particle_systems : Bucket_Array(Particle_System, 128);
by_type : Entity_Storage;
@@ -20,6 +20,7 @@ Scene :: struct {
camera : Camera;
directional_light : Directional_Light;
mode: Engine_Mode;
}
Entity_File_Info :: struct {
@@ -43,6 +44,7 @@ visitor :: (info : *File_Visit_Info, files: *[..] Entity_File_Info) {
load_scene :: (name: string) -> *Scene {
scene := create_scene(name, 1024);
scene.mode = engine.mode;
if engine.procs.on_scene_loaded != null {
engine.procs.on_pre_scene_loaded(scene, engine.mode);
@@ -125,6 +127,10 @@ save_scene :: (scene: *Scene, path: string) {
}
unload_scene :: (scene: *Scene) {
if engine.procs.on_pre_scene_unloaded != null {
engine.procs.on_pre_scene_unloaded(scene);
}
for e: scene.entities {
destroy_entity(e);
}
@@ -165,6 +171,7 @@ create_scene :: (name: string = "", max_entities: s64 = 256) -> *Scene {
}
scene.name = copy_string(new_name);
scene.mode = engine.mode;
// Setup allocator
scene.pool = .{};

View File

@@ -38,6 +38,7 @@ Engine_Core :: struct {
procs: struct {
on_scene_loaded: (*Scene, Engine_Mode);
on_pre_scene_loaded: (*Scene, Engine_Mode);
on_pre_scene_unloaded: (*Scene);
on_trigger_enter: (*Entity, *Entity);
on_trigger_exit: (*Entity, *Entity);
}

View File

@@ -546,7 +546,7 @@ ui_figure_out_sizes :: () {
// Downwards-dependent
for *box : ui_state.boxes {
if box.semantic_size[0].size_kind == .CHILDREN_SUM {
assert(box.num_children != 0);
//assert(box.num_children != 0);
size : float = 0.0;
child := box.first_child;
@@ -564,7 +564,7 @@ ui_figure_out_sizes :: () {
box.size.x = size + box.padding_left + box.padding_right;
}
if box.semantic_size[1].size_kind == .CHILDREN_SUM {
assert(box.num_children != 0);
//assert(box.num_children != 0);
size : float = 0.0;
child := box.first_child;