diff --git a/core/entity.jai b/core/entity.jai index e188e84..d304e49 100644 --- a/core/entity.jai +++ b/core/entity.jai @@ -201,6 +201,8 @@ entity_should_be_rendered :: (e: *Entity) -> bool { } destroy_entity :: (e: *Entity) { + call_correct_deinit_entity(e); + if e.collider.mesh.vertices.data != null { array_free(e.collider.mesh.vertices); } diff --git a/core/panic_allocator.jai b/core/panic_allocator.jai new file mode 100644 index 0000000..deb7799 --- /dev/null +++ b/core/panic_allocator.jai @@ -0,0 +1,25 @@ +Panic_Allocator :: struct { + +} + +panic_alloc :: (mode : Allocator_Mode, requested_size : s64, old_size : s64, old_memory : *void, allocator_data : *void) -> *void { + if mode == .THREAD_START return null; + if mode == .THREAD_STOP return null; + + assert(false, "You are attempting to use the default allocator, which for this project has been set to panic."); + return null; +} + +make_panic_allocator :: () -> Allocator #c_call { + result : Allocator = ---; + + result.proc = panic_alloc; + result.data = null; + + return result; +} + + +#scope_module + +#import "Basic"; diff --git a/metaprogram.jai b/metaprogram.jai index bfa138e..ff25b95 100644 --- a/metaprogram.jai +++ b/metaprogram.jai @@ -456,9 +456,9 @@ generate_serialize_procedure_for_entity :: (code_struct: *Code_Struct) { deserialize : String_Builder; print_to_builder(*deserialize, "deserialize_entity :: (scene: *Scene, lines: [] string, e: *%) {\n", name); print_to_builder(*deserialize, "\tfor line: lines {\n"); - print_to_builder(*deserialize, "\t\tvalues := split(line, \":\");\n"); + print_to_builder(*deserialize, "\t\tvalues := split(line, \":\",, temp);\n"); print_to_builder(*deserialize, "\t\tif values.count == 2 {\n"); - print_to_builder(*deserialize, "\t\t\tif trim(values[0], \" \") == {\n"); + print_to_builder(*deserialize, "\t\t\tif trim(values[0], \" \",, temp) == {\n"); generate_member_deserialization(code_struct.defined_type, *deserialize); @@ -526,9 +526,15 @@ message_loop :: () { } for typechecked.procedure_headers { - for note: it.expression.notes { - if to_lower_copy(note.text,, allocator = temp) == "newentity" { - array_add(*new_entity_procs, it.expression.name); + if it.expression.name == "deinit_entity" { + //struct_type := cast(*Type_Info_Struct)it.expression.arguments[0].type_inst.pointer_to; + struct_type := cast(*Type_Info_Struct)it.expression.arguments[0].type_inst.pointer_to.result; + array_add(*deinit_entity_procs, struct_type.name); + } else { + for note: it.expression.notes { + if to_lower_copy(note.text,, allocator = temp) == "newentity" { + array_add(*new_entity_procs, it.expression.name); + } } } } @@ -662,6 +668,17 @@ generate_code :: (w: Workspace) { add_build_string(build_string, w); } + { + builder: String_Builder; + + for deinit_entity_procs { + print_to_builder(*builder, "\tcase %1; deinit_entity(cast(*%1)e);\n", it); + } + + build_string := sprint(DEINIT_ENTITY, builder_to_string(*builder)); + add_build_string(build_string, w); + } + { builder: String_Builder; @@ -691,6 +708,7 @@ generate_code :: (w: Workspace) { generated_code := false; entity_type_names: [..] string; new_entity_procs: [..] string; +deinit_entity_procs: [..] string; // INSERTION_STRING represents the code we want to add to the target program. // We'll use print to insert useful things where the % markers are. @@ -742,8 +760,8 @@ deserialize_entity :: (scene: *Scene, id: Entity_Id, path: string) -> *Entity { content := File.read_entire_file(path); if content.count == 0 return null; - lines := split(content, "\n"); - first_line := split(lines[0], ":"); + lines := split(content, "\n",, temp); + first_line := split(lines[0], ":",, temp); if first_line.count != 2 return null; @@ -781,6 +799,16 @@ entity_ui :: (e: *Entity) { } DONE +DEINIT_ENTITY :: #string DONE +#if EDITOR { +call_correct_deinit_entity :: (e: *Entity) { + if e.type == { + %1 + } +} +} +DONE + INIT_SCENE :: #string DONE init_scene :: (scene: *Scene) { %1 @@ -803,8 +831,10 @@ PLACEHOLDER :: #string DONE #poke_name Coven Entity_Storage; #poke_name Coven delete_entity; #poke_name Coven deserialize_entity; +#poke_name Coven deinit_entity; #poke_name Coven serialize_entity; #poke_name Coven new_mesh_entity; +#poke_name Coven call_correct_deinit_entity; #if EDITOR { #poke_name Coven editor_ui_entity_creation;