deinit_entity
This commit is contained in:
@@ -201,6 +201,8 @@ entity_should_be_rendered :: (e: *Entity) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
destroy_entity :: (e: *Entity) {
|
destroy_entity :: (e: *Entity) {
|
||||||
|
call_correct_deinit_entity(e);
|
||||||
|
|
||||||
if e.collider.mesh.vertices.data != null {
|
if e.collider.mesh.vertices.data != null {
|
||||||
array_free(e.collider.mesh.vertices);
|
array_free(e.collider.mesh.vertices);
|
||||||
}
|
}
|
||||||
|
|||||||
25
core/panic_allocator.jai
Normal file
25
core/panic_allocator.jai
Normal file
@@ -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";
|
||||||
@@ -456,9 +456,9 @@ generate_serialize_procedure_for_entity :: (code_struct: *Code_Struct) {
|
|||||||
deserialize : String_Builder;
|
deserialize : String_Builder;
|
||||||
print_to_builder(*deserialize, "deserialize_entity :: (scene: *Scene, lines: [] string, e: *%) {\n", name);
|
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, "\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\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);
|
generate_member_deserialization(code_struct.defined_type, *deserialize);
|
||||||
|
|
||||||
@@ -526,9 +526,15 @@ message_loop :: () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for typechecked.procedure_headers {
|
for typechecked.procedure_headers {
|
||||||
for note: it.expression.notes {
|
if it.expression.name == "deinit_entity" {
|
||||||
if to_lower_copy(note.text,, allocator = temp) == "newentity" {
|
//struct_type := cast(*Type_Info_Struct)it.expression.arguments[0].type_inst.pointer_to;
|
||||||
array_add(*new_entity_procs, it.expression.name);
|
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);
|
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;
|
builder: String_Builder;
|
||||||
|
|
||||||
@@ -691,6 +708,7 @@ generate_code :: (w: Workspace) {
|
|||||||
generated_code := false;
|
generated_code := false;
|
||||||
entity_type_names: [..] string;
|
entity_type_names: [..] string;
|
||||||
new_entity_procs: [..] string;
|
new_entity_procs: [..] string;
|
||||||
|
deinit_entity_procs: [..] string;
|
||||||
|
|
||||||
// INSERTION_STRING represents the code we want to add to the target program.
|
// 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.
|
// 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);
|
content := File.read_entire_file(path);
|
||||||
if content.count == 0 return null;
|
if content.count == 0 return null;
|
||||||
|
|
||||||
lines := split(content, "\n");
|
lines := split(content, "\n",, temp);
|
||||||
first_line := split(lines[0], ":");
|
first_line := split(lines[0], ":",, temp);
|
||||||
|
|
||||||
if first_line.count != 2 return null;
|
if first_line.count != 2 return null;
|
||||||
|
|
||||||
@@ -781,6 +799,16 @@ entity_ui :: (e: *Entity) {
|
|||||||
}
|
}
|
||||||
DONE
|
DONE
|
||||||
|
|
||||||
|
DEINIT_ENTITY :: #string DONE
|
||||||
|
#if EDITOR {
|
||||||
|
call_correct_deinit_entity :: (e: *Entity) {
|
||||||
|
if e.type == {
|
||||||
|
%1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
DONE
|
||||||
|
|
||||||
INIT_SCENE :: #string DONE
|
INIT_SCENE :: #string DONE
|
||||||
init_scene :: (scene: *Scene) {
|
init_scene :: (scene: *Scene) {
|
||||||
%1
|
%1
|
||||||
@@ -803,8 +831,10 @@ PLACEHOLDER :: #string DONE
|
|||||||
#poke_name Coven Entity_Storage;
|
#poke_name Coven Entity_Storage;
|
||||||
#poke_name Coven delete_entity;
|
#poke_name Coven delete_entity;
|
||||||
#poke_name Coven deserialize_entity;
|
#poke_name Coven deserialize_entity;
|
||||||
|
#poke_name Coven deinit_entity;
|
||||||
#poke_name Coven serialize_entity;
|
#poke_name Coven serialize_entity;
|
||||||
#poke_name Coven new_mesh_entity;
|
#poke_name Coven new_mesh_entity;
|
||||||
|
#poke_name Coven call_correct_deinit_entity;
|
||||||
|
|
||||||
#if EDITOR {
|
#if EDITOR {
|
||||||
#poke_name Coven editor_ui_entity_creation;
|
#poke_name Coven editor_ui_entity_creation;
|
||||||
|
|||||||
Reference in New Issue
Block a user