Entity deletion
This commit is contained in:
@@ -30,11 +30,19 @@ editor_ui_entity_creation :: () -> *Entity {
|
|||||||
// String added via add_build_string() from c:/Personal/games/onegameamonth/oct24/modules/Coven/metaprogram.jai:271.
|
// String added via add_build_string() from c:/Personal/games/onegameamonth/oct24/modules/Coven/metaprogram.jai:271.
|
||||||
//
|
//
|
||||||
delete_entity :: (e: *Entity) {
|
delete_entity :: (e: *Entity) {
|
||||||
|
// Delete the file too
|
||||||
|
path := tprint("../assets/scenes/%/%.ent", e.scene.name, e.id);
|
||||||
|
File.file_delete(path);
|
||||||
|
|
||||||
|
destroy_entity(e);
|
||||||
|
|
||||||
if e.type == {
|
if e.type == {
|
||||||
case Block; bucket_array_remove(*e.scene.by_type._Block, e._locator); case Character; bucket_array_remove(*e.scene.by_type._Character, e._locator); case Item; bucket_array_remove(*e.scene.by_type._Item, e._locator);
|
case Block; bucket_array_remove(*e.scene.by_type._Block, e._locator); case Character; bucket_array_remove(*e.scene.by_type._Character, e._locator); case Item; bucket_array_remove(*e.scene.by_type._Item, e._locator);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//#import "File";
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// String added via add_build_string() from c:/Personal/games/onegameamonth/oct24/modules/Coven/metaprogram.jai:282.
|
// String added via add_build_string() from c:/Personal/games/onegameamonth/oct24/modules/Coven/metaprogram.jai:282.
|
||||||
@@ -95,6 +103,78 @@ if _scene == null {
|
|||||||
_scene = engine.current_scene; }
|
_scene = engine.current_scene; }
|
||||||
p, locator := find_and_occupy_empty_slot(*_scene.by_type._Item); p._locator = locator; register_entity(_scene, p); p.transform = create_identity_transform(); init_entity(p); return p; }
|
p, locator := find_and_occupy_empty_slot(*_scene.by_type._Item); p._locator = locator; register_entity(_scene, p); p.transform = create_identity_transform(); init_entity(p); return p; }
|
||||||
|
|
||||||
|
//
|
||||||
|
// String added via add_build_string() from c:/Personal/games/onegameamonth/oct24/modules/Coven/metaprogram.jai:307.
|
||||||
|
//
|
||||||
|
serialize_entity :: (e: *Item, builder: *String_Builder) {
|
||||||
|
print_to_builder(builder, "type: Item\n");
|
||||||
|
print_to_builder(builder, "entity.enabled: %\n", e.entity.enabled);
|
||||||
|
print_to_builder(builder, "entity.flags: %\n", e.entity.flags);
|
||||||
|
print_to_builder(builder, "entity.transform.position.x: %\n", e.entity.transform.position.x);
|
||||||
|
print_to_builder(builder, "entity.transform.position.y: %\n", e.entity.transform.position.y);
|
||||||
|
print_to_builder(builder, "entity.transform.position.z: %\n", e.entity.transform.position.z);
|
||||||
|
print_to_builder(builder, "entity.transform.orientation.x: %\n", e.entity.transform.orientation.x);
|
||||||
|
print_to_builder(builder, "entity.transform.orientation.y: %\n", e.entity.transform.orientation.y);
|
||||||
|
print_to_builder(builder, "entity.transform.orientation.z: %\n", e.entity.transform.orientation.z);
|
||||||
|
print_to_builder(builder, "entity.transform.orientation.w: %\n", e.entity.transform.orientation.w);
|
||||||
|
print_to_builder(builder, "entity.transform.scale.x: %\n", e.entity.transform.scale.x);
|
||||||
|
print_to_builder(builder, "entity.transform.scale.y: %\n", e.entity.transform.scale.y);
|
||||||
|
print_to_builder(builder, "entity.transform.scale.z: %\n", e.entity.transform.scale.z);
|
||||||
|
print_to_builder(builder, "entity.snap_offset.x: %\n", e.entity.snap_offset.x);
|
||||||
|
print_to_builder(builder, "entity.snap_offset.y: %\n", e.entity.snap_offset.y);
|
||||||
|
print_to_builder(builder, "entity.snap_offset.z: %\n", e.entity.snap_offset.z);
|
||||||
|
print_to_builder(builder, "entity.snap_intervals.x: %\n", e.entity.snap_intervals.x);
|
||||||
|
print_to_builder(builder, "entity.snap_intervals.y: %\n", e.entity.snap_intervals.y);
|
||||||
|
print_to_builder(builder, "entity.snap_intervals.z: %\n", e.entity.snap_intervals.z);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// String added via add_build_string() from c:/Personal/games/onegameamonth/oct24/modules/Coven/metaprogram.jai:307.
|
||||||
|
//
|
||||||
|
deserialize_entity :: (scene: *Scene, lines: [] string, e: *Item) {
|
||||||
|
for line: lines {
|
||||||
|
values := split(line, ":");
|
||||||
|
if values.count == 2 {
|
||||||
|
if trim(values[0], " ") == {
|
||||||
|
case "entity.enabled";
|
||||||
|
scan2(values[1], "%", *e.entity.enabled);
|
||||||
|
case "entity.transform.position.x";
|
||||||
|
scan2(values[1], "%", *e.entity.transform.position.x);
|
||||||
|
case "entity.transform.position.y";
|
||||||
|
scan2(values[1], "%", *e.entity.transform.position.y);
|
||||||
|
case "entity.transform.position.z";
|
||||||
|
scan2(values[1], "%", *e.entity.transform.position.z);
|
||||||
|
case "entity.transform.orientation.x";
|
||||||
|
scan2(values[1], "%", *e.entity.transform.orientation.x);
|
||||||
|
case "entity.transform.orientation.y";
|
||||||
|
scan2(values[1], "%", *e.entity.transform.orientation.y);
|
||||||
|
case "entity.transform.orientation.z";
|
||||||
|
scan2(values[1], "%", *e.entity.transform.orientation.z);
|
||||||
|
case "entity.transform.orientation.w";
|
||||||
|
scan2(values[1], "%", *e.entity.transform.orientation.w);
|
||||||
|
case "entity.transform.scale.x";
|
||||||
|
scan2(values[1], "%", *e.entity.transform.scale.x);
|
||||||
|
case "entity.transform.scale.y";
|
||||||
|
scan2(values[1], "%", *e.entity.transform.scale.y);
|
||||||
|
case "entity.transform.scale.z";
|
||||||
|
scan2(values[1], "%", *e.entity.transform.scale.z);
|
||||||
|
case "entity.snap_offset.x";
|
||||||
|
scan2(values[1], "%", *e.entity.snap_offset.x);
|
||||||
|
case "entity.snap_offset.y";
|
||||||
|
scan2(values[1], "%", *e.entity.snap_offset.y);
|
||||||
|
case "entity.snap_offset.z";
|
||||||
|
scan2(values[1], "%", *e.entity.snap_offset.z);
|
||||||
|
case "entity.snap_intervals.x";
|
||||||
|
scan2(values[1], "%", *e.entity.snap_intervals.x);
|
||||||
|
case "entity.snap_intervals.y";
|
||||||
|
scan2(values[1], "%", *e.entity.snap_intervals.y);
|
||||||
|
case "entity.snap_intervals.z";
|
||||||
|
scan2(values[1], "%", *e.entity.snap_intervals.z);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// String added via add_build_string() from c:/Personal/games/onegameamonth/oct24/modules/Coven/metaprogram.jai:307.
|
// String added via add_build_string() from c:/Personal/games/onegameamonth/oct24/modules/Coven/metaprogram.jai:307.
|
||||||
//
|
//
|
||||||
@@ -171,78 +251,6 @@ deserialize_entity :: (scene: *Scene, lines: [] string, e: *Block) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
|
||||||
// String added via add_build_string() from c:/Personal/games/onegameamonth/oct24/modules/Coven/metaprogram.jai:307.
|
|
||||||
//
|
|
||||||
serialize_entity :: (e: *Item, builder: *String_Builder) {
|
|
||||||
print_to_builder(builder, "type: Item\n");
|
|
||||||
print_to_builder(builder, "entity.enabled: %\n", e.entity.enabled);
|
|
||||||
print_to_builder(builder, "entity.flags: %\n", e.entity.flags);
|
|
||||||
print_to_builder(builder, "entity.transform.position.x: %\n", e.entity.transform.position.x);
|
|
||||||
print_to_builder(builder, "entity.transform.position.y: %\n", e.entity.transform.position.y);
|
|
||||||
print_to_builder(builder, "entity.transform.position.z: %\n", e.entity.transform.position.z);
|
|
||||||
print_to_builder(builder, "entity.transform.orientation.x: %\n", e.entity.transform.orientation.x);
|
|
||||||
print_to_builder(builder, "entity.transform.orientation.y: %\n", e.entity.transform.orientation.y);
|
|
||||||
print_to_builder(builder, "entity.transform.orientation.z: %\n", e.entity.transform.orientation.z);
|
|
||||||
print_to_builder(builder, "entity.transform.orientation.w: %\n", e.entity.transform.orientation.w);
|
|
||||||
print_to_builder(builder, "entity.transform.scale.x: %\n", e.entity.transform.scale.x);
|
|
||||||
print_to_builder(builder, "entity.transform.scale.y: %\n", e.entity.transform.scale.y);
|
|
||||||
print_to_builder(builder, "entity.transform.scale.z: %\n", e.entity.transform.scale.z);
|
|
||||||
print_to_builder(builder, "entity.snap_offset.x: %\n", e.entity.snap_offset.x);
|
|
||||||
print_to_builder(builder, "entity.snap_offset.y: %\n", e.entity.snap_offset.y);
|
|
||||||
print_to_builder(builder, "entity.snap_offset.z: %\n", e.entity.snap_offset.z);
|
|
||||||
print_to_builder(builder, "entity.snap_intervals.x: %\n", e.entity.snap_intervals.x);
|
|
||||||
print_to_builder(builder, "entity.snap_intervals.y: %\n", e.entity.snap_intervals.y);
|
|
||||||
print_to_builder(builder, "entity.snap_intervals.z: %\n", e.entity.snap_intervals.z);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// String added via add_build_string() from c:/Personal/games/onegameamonth/oct24/modules/Coven/metaprogram.jai:307.
|
|
||||||
//
|
|
||||||
deserialize_entity :: (scene: *Scene, lines: [] string, e: *Item) {
|
|
||||||
for line: lines {
|
|
||||||
values := split(line, ":");
|
|
||||||
if values.count == 2 {
|
|
||||||
if trim(values[0], " ") == {
|
|
||||||
case "entity.enabled";
|
|
||||||
scan2(values[1], "%", *e.entity.enabled);
|
|
||||||
case "entity.transform.position.x";
|
|
||||||
scan2(values[1], "%", *e.entity.transform.position.x);
|
|
||||||
case "entity.transform.position.y";
|
|
||||||
scan2(values[1], "%", *e.entity.transform.position.y);
|
|
||||||
case "entity.transform.position.z";
|
|
||||||
scan2(values[1], "%", *e.entity.transform.position.z);
|
|
||||||
case "entity.transform.orientation.x";
|
|
||||||
scan2(values[1], "%", *e.entity.transform.orientation.x);
|
|
||||||
case "entity.transform.orientation.y";
|
|
||||||
scan2(values[1], "%", *e.entity.transform.orientation.y);
|
|
||||||
case "entity.transform.orientation.z";
|
|
||||||
scan2(values[1], "%", *e.entity.transform.orientation.z);
|
|
||||||
case "entity.transform.orientation.w";
|
|
||||||
scan2(values[1], "%", *e.entity.transform.orientation.w);
|
|
||||||
case "entity.transform.scale.x";
|
|
||||||
scan2(values[1], "%", *e.entity.transform.scale.x);
|
|
||||||
case "entity.transform.scale.y";
|
|
||||||
scan2(values[1], "%", *e.entity.transform.scale.y);
|
|
||||||
case "entity.transform.scale.z";
|
|
||||||
scan2(values[1], "%", *e.entity.transform.scale.z);
|
|
||||||
case "entity.snap_offset.x";
|
|
||||||
scan2(values[1], "%", *e.entity.snap_offset.x);
|
|
||||||
case "entity.snap_offset.y";
|
|
||||||
scan2(values[1], "%", *e.entity.snap_offset.y);
|
|
||||||
case "entity.snap_offset.z";
|
|
||||||
scan2(values[1], "%", *e.entity.snap_offset.z);
|
|
||||||
case "entity.snap_intervals.x";
|
|
||||||
scan2(values[1], "%", *e.entity.snap_intervals.x);
|
|
||||||
case "entity.snap_intervals.y";
|
|
||||||
scan2(values[1], "%", *e.entity.snap_intervals.y);
|
|
||||||
case "entity.snap_intervals.z";
|
|
||||||
scan2(values[1], "%", *e.entity.snap_intervals.z);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// String added via add_build_string() from c:/Personal/games/onegameamonth/oct24/modules/Coven/metaprogram.jai:307.
|
// String added via add_build_string() from c:/Personal/games/onegameamonth/oct24/modules/Coven/metaprogram.jai:307.
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -59,6 +59,10 @@ play_audio_event :: (evt: Audio_Event, delay: float = -1.0) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
stop_audio_event :: (evt: Audio_Event) {
|
||||||
|
assert(FMOD_Studio_EventInstance_Stop(evt.instance, .ALLOWFADEOUT) == .FMOD_OK);
|
||||||
|
}
|
||||||
|
|
||||||
create_sound :: (path: string) -> Sound_Handle {
|
create_sound :: (path: string) -> Sound_Handle {
|
||||||
sound: Sound;
|
sound: Sound;
|
||||||
assert(FMOD_System_CreateSound(audio_system.fmod, to_temp_c_string(path), FMOD_DEFAULT, null, *sound.fmod_sound) == .FMOD_OK);
|
assert(FMOD_System_CreateSound(audio_system.fmod, to_temp_c_string(path), FMOD_DEFAULT, null, *sound.fmod_sound) == .FMOD_OK);
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ Entity_Flags :: enum_flags u16 {
|
|||||||
UNIFORM_SCALE;
|
UNIFORM_SCALE;
|
||||||
|
|
||||||
DONT_SAVE;
|
DONT_SAVE;
|
||||||
|
DELETED;
|
||||||
}
|
}
|
||||||
|
|
||||||
Renderable_Type :: enum {
|
Renderable_Type :: enum {
|
||||||
@@ -166,9 +167,11 @@ load_model_into_entity :: (e: *Entity, model: *Model) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
destroy_entity :: (e: *Entity, remove_from_scene: bool = true) {
|
mark_entity_deleted :: (e: *Entity) {
|
||||||
free(e.name);
|
e.flags |= .DELETED;
|
||||||
|
}
|
||||||
|
|
||||||
|
destroy_entity :: (e: *Entity) {
|
||||||
for 0..e.renderable.num_nodes-1 {
|
for 0..e.renderable.num_nodes-1 {
|
||||||
node_data := e.renderable.nodes[it];
|
node_data := e.renderable.nodes[it];
|
||||||
|
|
||||||
@@ -185,9 +188,5 @@ destroy_entity :: (e: *Entity, remove_from_scene: bool = true) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if remove_from_scene {
|
free(e.name);
|
||||||
array_unordered_remove_by_value(*engine.current_scene.entities, e);
|
|
||||||
|
|
||||||
delete_entity(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -84,10 +84,18 @@ save_scene :: (scene: *Scene, path: string) {
|
|||||||
|
|
||||||
for scene.entities {
|
for scene.entities {
|
||||||
if it.flags & .DONT_SAVE continue;
|
if it.flags & .DONT_SAVE continue;
|
||||||
|
if it.flags & .DELETED continue;
|
||||||
|
|
||||||
serialize_entity(it, full_path);
|
serialize_entity(it, full_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for scene.entities {
|
||||||
|
if it.flags & .DELETED {
|
||||||
|
delete_entity(it);
|
||||||
|
remove it;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Save camera
|
// 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);
|
//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) {
|
unload_scene :: (scene: *Scene) {
|
||||||
for e: scene.entities {
|
for e: scene.entities {
|
||||||
destroy_entity(e, false);
|
destroy_entity(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(scene.name);
|
free(scene.name);
|
||||||
|
|||||||
@@ -153,6 +153,7 @@ editor_ui :: () {
|
|||||||
{
|
{
|
||||||
new_entity := editor_ui_entity_creation();
|
new_entity := editor_ui_entity_creation();
|
||||||
if new_entity != null {
|
if new_entity != null {
|
||||||
|
set_position(*new_entity.transform, engine.editor.camera.position + engine.editor.camera.forward * 20.0);
|
||||||
engine.editor.selected_entities.count = 0;
|
engine.editor.selected_entities.count = 0;
|
||||||
array_add(*engine.editor.selected_entities, new_entity);
|
array_add(*engine.editor.selected_entities, new_entity);
|
||||||
}
|
}
|
||||||
@@ -249,6 +250,14 @@ base_editor_update :: () {
|
|||||||
//show_message("Saved scene");
|
//show_message("Saved scene");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if key_down(.DELETE) || key_down(.BACKSPACE) {
|
||||||
|
for engine.editor.selected_entities {
|
||||||
|
mark_entity_deleted(it);
|
||||||
|
}
|
||||||
|
|
||||||
|
engine.editor.selected_entities.count = 0;
|
||||||
|
}
|
||||||
|
|
||||||
//if entity != null {
|
//if entity != null {
|
||||||
// // @Incomplete:@Incomplete: Duplicate
|
// // @Incomplete:@Incomplete: Duplicate
|
||||||
// //if key_pressed(.CTRL) && key_down(.D) {
|
// //if key_pressed(.CTRL) && key_down(.D) {
|
||||||
|
|||||||
@@ -338,11 +338,19 @@ DONE
|
|||||||
|
|
||||||
DELETE_ENTITY :: #string DONE
|
DELETE_ENTITY :: #string DONE
|
||||||
delete_entity :: (e: *Entity) {
|
delete_entity :: (e: *Entity) {
|
||||||
|
// Delete the file too
|
||||||
|
path := tprint("../assets/scenes/%%/%%.ent", e.scene.name, e.id);
|
||||||
|
File.file_delete(path);
|
||||||
|
|
||||||
|
destroy_entity(e);
|
||||||
|
|
||||||
if e.type == {
|
if e.type == {
|
||||||
%1
|
%1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//#import "File";
|
||||||
|
|
||||||
DONE
|
DONE
|
||||||
|
|
||||||
SERIALIZE_ENTITY :: #string DONE
|
SERIALIZE_ENTITY :: #string DONE
|
||||||
|
|||||||
Reference in New Issue
Block a user