Updated metaprogram to support variant types

This commit is contained in:
2024-12-21 00:54:47 +01:00
parent 07dbdcfe2c
commit 288df50558
3 changed files with 45 additions and 9 deletions

View File

@@ -53,7 +53,7 @@ Renderable :: struct {
MAX_CHILDREN :: 16; MAX_CHILDREN :: 16;
Entity :: struct { Entity :: struct {
id: Entity_Id; id: Entity_Id; @Hide
type : Type; type : Type;
enabled: bool = true; enabled: bool = true;

View File

@@ -263,7 +263,7 @@ update_entity_transform :: (e: *Entity, parent_matrix: Matrix4 = Matrix4_Identit
} }
} }
get_entity_with_id :: (scene: *Scene, id: s64) -> *Entity { get_entity_by_id :: (scene: *Scene, id: s64) -> *Entity {
for scene.entities { for scene.entities {
if it.id == id return it; if it.id == id return it;
} }

View File

@@ -129,7 +129,15 @@ generate_member_ui :: (type: *Type_Info_Struct, builder: *String_Builder, path:
new_path = tprint("%1.%2", path, it.name); new_path = tprint("%1.%2", path, it.name);
} }
if it.type.type == { type : Type_Info_Tag;
if it.type.type == .VARIANT {
info_variant := cast(*Type_Info_Variant)it.type;
type = info_variant.variant_of.type;
} else {
type = it.type.type;
}
if type == {
case .STRUCT; { case .STRUCT; {
info_struct := cast(*Type_Info_Struct) it.type; info_struct := cast(*Type_Info_Struct) it.type;
if info_struct.name == "Quaternion" { if info_struct.name == "Quaternion" {
@@ -151,7 +159,7 @@ generate_member_ui :: (type: *Type_Info_Struct, builder: *String_Builder, path:
} }
//case .ENUM; #through; //case .ENUM; #through;
case .INTEGER; { case .INTEGER; {
print_to_builder(builder, "\tui_int_field(tprint(\"%\"), *e.%);\n", new_path, new_path); print_to_builder(builder, "\tui_int_field(tprint(\"%\"), cast(*int)*e.%);\n", new_path, new_path);
} }
} }
} }
@@ -168,7 +176,15 @@ generate_member_serialization :: (type: *Type_Info_Struct, builder: *String_Buil
new_path = tprint("%1.%2", path, it.name); new_path = tprint("%1.%2", path, it.name);
} }
if it.type.type == { type : Type_Info_Tag;
if it.type.type == .VARIANT {
info_variant := cast(*Type_Info_Variant)it.type;
type = info_variant.variant_of.type;
} else {
type = it.type.type;
}
if type == {
case .STRUCT; { case .STRUCT; {
info_struct := cast(*Type_Info_Struct) it.type; info_struct := cast(*Type_Info_Struct) it.type;
generate_member_serialization(info_struct, builder, new_path); generate_member_serialization(info_struct, builder, new_path);
@@ -196,7 +212,16 @@ generate_member_deserialization :: (type: *Type_Info_Struct, builder: *String_Bu
} else { } else {
new_path = tprint("%1.%2", path, it.name); new_path = tprint("%1.%2", path, it.name);
} }
if it.type.type == {
type : Type_Info_Tag;
if it.type.type == .VARIANT {
info_variant := cast(*Type_Info_Variant)it.type;
type = info_variant.variant_of.type;
} else {
type = it.type.type;
}
if type == {
case .STRUCT; { case .STRUCT; {
info_struct := cast(*Type_Info_Struct) it.type; info_struct := cast(*Type_Info_Struct) it.type;
generate_member_deserialization(info_struct, builder, new_path); generate_member_deserialization(info_struct, builder, new_path);
@@ -207,11 +232,14 @@ generate_member_deserialization :: (type: *Type_Info_Struct, builder: *String_Bu
} }
case .BOOL; #through; case .BOOL; #through;
case .FLOAT; #through; case .FLOAT; #through;
case .ENUM; #through; case .ENUM; {
case .INTEGER; {
print_to_builder(builder, "\t\t\t\tcase \"%\";\n", new_path); print_to_builder(builder, "\t\t\t\tcase \"%\";\n", new_path);
print_to_builder(builder, "\t\t\t\t\tscan2(values[1], \"\%\", *e.%);\n", new_path); print_to_builder(builder, "\t\t\t\t\tscan2(values[1], \"\%\", *e.%);\n", new_path);
} }
case .INTEGER; {
print_to_builder(builder, "\t\t\t\tcase \"%\";\n", new_path);
print_to_builder(builder, "\t\t\t\t\tscan2(values[1], \"\%\", cast(*int)*e.%);\n", new_path);
}
} }
} }
} }
@@ -227,7 +255,15 @@ generate_member_copy :: (type: *Type_Info_Struct, builder: *String_Builder, path
new_path = tprint("%1.%2", path, it.name); new_path = tprint("%1.%2", path, it.name);
} }
if it.type.type == { type : Type_Info_Tag;
if it.type.type == .VARIANT {
info_variant := cast(*Type_Info_Variant)it.type;
type = info_variant.variant_of.type;
} else {
type = it.type.type;
}
if type == {
case .STRUCT; { case .STRUCT; {
info_struct := cast(*Type_Info_Struct) it.type; info_struct := cast(*Type_Info_Struct) it.type;
generate_member_copy(info_struct, builder, new_path); generate_member_copy(info_struct, builder, new_path);