Entity deletion
This commit is contained in:
@@ -14,6 +14,7 @@ Entity_Flags :: enum_flags u16 {
|
||||
UNIFORM_SCALE;
|
||||
|
||||
DONT_SAVE;
|
||||
DELETED;
|
||||
}
|
||||
|
||||
Renderable_Type :: enum {
|
||||
@@ -166,9 +167,11 @@ load_model_into_entity :: (e: *Entity, model: *Model) {
|
||||
}
|
||||
}
|
||||
|
||||
destroy_entity :: (e: *Entity, remove_from_scene: bool = true) {
|
||||
free(e.name);
|
||||
mark_entity_deleted :: (e: *Entity) {
|
||||
e.flags |= .DELETED;
|
||||
}
|
||||
|
||||
destroy_entity :: (e: *Entity) {
|
||||
for 0..e.renderable.num_nodes-1 {
|
||||
node_data := e.renderable.nodes[it];
|
||||
|
||||
@@ -185,9 +188,5 @@ destroy_entity :: (e: *Entity, remove_from_scene: bool = true) {
|
||||
}
|
||||
}
|
||||
|
||||
if remove_from_scene {
|
||||
array_unordered_remove_by_value(*engine.current_scene.entities, e);
|
||||
|
||||
delete_entity(e);
|
||||
}
|
||||
free(e.name);
|
||||
}
|
||||
|
||||
@@ -84,10 +84,18 @@ save_scene :: (scene: *Scene, path: string) {
|
||||
|
||||
for scene.entities {
|
||||
if it.flags & .DONT_SAVE continue;
|
||||
if it.flags & .DELETED continue;
|
||||
|
||||
serialize_entity(it, full_path);
|
||||
}
|
||||
|
||||
for scene.entities {
|
||||
if it.flags & .DELETED {
|
||||
delete_entity(it);
|
||||
remove it;
|
||||
}
|
||||
}
|
||||
|
||||
// Save camera
|
||||
//print_to_builder(*builder, "Camera: % % % % %\n", scene.camera.position.x, scene.camera.position.y, scene.camera.position.z, scene.camera.rotation.yaw, scene.camera.rotation.pitch);
|
||||
|
||||
@@ -96,7 +104,7 @@ save_scene :: (scene: *Scene, path: string) {
|
||||
|
||||
unload_scene :: (scene: *Scene) {
|
||||
for e: scene.entities {
|
||||
destroy_entity(e, false);
|
||||
destroy_entity(e);
|
||||
}
|
||||
|
||||
free(scene.name);
|
||||
|
||||
Reference in New Issue
Block a user