Scene loading/saving improvements, transform gizmo, entity creation
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
Entity_Id :: #type, isa s64;
|
||||
|
||||
Entity_Flags :: enum_flags u8 {
|
||||
Entity_Flags :: enum_flags u16 {
|
||||
NONE;
|
||||
RENDERABLE;
|
||||
COLLISION;
|
||||
@@ -10,6 +10,9 @@ Entity_Flags :: enum_flags u8 {
|
||||
|
||||
ANIMATED;
|
||||
|
||||
SNAP_TO_GRID;
|
||||
UNIFORM_SCALE;
|
||||
|
||||
DONT_SAVE;
|
||||
}
|
||||
|
||||
@@ -66,6 +69,7 @@ Entity :: struct {
|
||||
transform: Transform;
|
||||
|
||||
snap_offset: Vector3;
|
||||
snap_intervals: Vector3;
|
||||
|
||||
renderable: Renderable; @DontSerialize
|
||||
animator: Animator; @DontSerialize
|
||||
@@ -182,9 +186,8 @@ destroy_entity :: (e: *Entity, remove_from_scene: bool = true) {
|
||||
}
|
||||
|
||||
if remove_from_scene {
|
||||
array_unordered_remove_by_value(*game_state.engine.current_scene.entities, e);
|
||||
if e.type == {
|
||||
case Block; bucket_array_remove(*game_state.engine.current_scene.by_type._Block, e._locator);
|
||||
}
|
||||
array_unordered_remove_by_value(*engine.current_scene.entities, e);
|
||||
|
||||
delete_entity(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
#load "../renderer/directional_light.jai";
|
||||
#load "particles.jai";
|
||||
|
||||
#placeholder init_scene;
|
||||
#placeholder Entity_Storage;
|
||||
#placeholder delete_entity;
|
||||
#placeholder serialize_entity;
|
||||
#placeholder deserialize_entity;
|
||||
|
||||
@@ -26,7 +28,7 @@ Scene :: struct {
|
||||
}
|
||||
|
||||
Entity_File_Info :: struct {
|
||||
id: s64;
|
||||
id: Entity_Id;
|
||||
full_path: string;
|
||||
}
|
||||
|
||||
@@ -38,28 +40,40 @@ visitor :: (info : *File_Visit_Info, files: *[..] Entity_File_Info) {
|
||||
// Entity text files
|
||||
if ext == "ent" && basename != "cam" {
|
||||
file_info : Entity_File_Info;
|
||||
file_info.id = cast(s32)string_to_int(basename);
|
||||
file_info.id = cast(Entity_Id)string_to_int(basename);
|
||||
file_info.full_path = copy_temporary_string(info.full_name);
|
||||
array_add(files, file_info);
|
||||
}
|
||||
}
|
||||
|
||||
load_scene :: (path: string) -> *Scene {
|
||||
split_path := split(path, "/");
|
||||
name := split_path[split_path.count-1];
|
||||
load_scene :: (name: string) -> *Scene {
|
||||
scene := create_scene(name, 1024);
|
||||
path := tprint("../assets/scenes/%", name);
|
||||
|
||||
files : [..] Entity_File_Info;
|
||||
files.allocator = temp;
|
||||
visit_files(path, true, *files, visitor);
|
||||
|
||||
for file: files {
|
||||
deserialize_entity(scene, file.full_path);
|
||||
deserialize_entity(scene, file.id, file.full_path);
|
||||
}
|
||||
|
||||
|
||||
calculate_aabbs(scene);
|
||||
make_sure_nothing_collides(scene);
|
||||
|
||||
if engine.procs.on_scene_loaded != null {
|
||||
engine.procs.on_scene_loaded(scene, engine.mode);
|
||||
}
|
||||
|
||||
return scene;
|
||||
}
|
||||
|
||||
save_scene :: (scene: *Scene) {
|
||||
path := "../assets/scenes/";
|
||||
save_scene(scene, path);
|
||||
}
|
||||
|
||||
save_scene :: (scene: *Scene, path: string) {
|
||||
builder : String_Builder;
|
||||
builder.allocator = temp;
|
||||
@@ -85,10 +99,17 @@ unload_scene :: (scene: *Scene) {
|
||||
destroy_entity(e, false);
|
||||
}
|
||||
|
||||
free(scene.name);
|
||||
fini(*scene.pool);
|
||||
free(scene);
|
||||
}
|
||||
|
||||
reload_scene :: (scene: *Scene) {
|
||||
name := copy_temporary_string(scene.name);
|
||||
unload_scene(engine.current_scene);
|
||||
engine.current_scene = load_scene(name);
|
||||
}
|
||||
|
||||
create_scene :: (name: string = "", max_entities: s64 = 256) -> *Scene {
|
||||
scene := New(Scene);
|
||||
new_name := name;
|
||||
@@ -112,6 +133,8 @@ create_scene :: (name: string = "", max_entities: s64 = 256) -> *Scene {
|
||||
scene.allocator.data = *scene.pool;
|
||||
scene.allocator.proc = flat_pool_allocator_proc;
|
||||
|
||||
init_scene(scene);
|
||||
|
||||
// Assign allocator to everything that needs allocations
|
||||
scene.entities.allocator = scene.allocator;
|
||||
scene.particle_systems.allocator = scene.allocator;
|
||||
@@ -129,11 +152,15 @@ create_scene :: (name: string = "", max_entities: s64 = 256) -> *Scene {
|
||||
return scene;
|
||||
}
|
||||
|
||||
register_entity :: (scene: *Scene, entity: *Entity) {
|
||||
register_entity :: (scene: *Scene, entity: *Entity, id: Entity_Id = -1) {
|
||||
entity.scene = scene;
|
||||
entity.id = next_entity_id;
|
||||
if id != -1 {
|
||||
entity.id = id;
|
||||
} else {
|
||||
entity.id = next_entity_id;
|
||||
next_entity_id += 1;
|
||||
}
|
||||
array_add(*scene.entities, entity);
|
||||
next_entity_id += 1;
|
||||
|
||||
#if NETWORKING {
|
||||
if net_data.net_mode == {
|
||||
|
||||
Reference in New Issue
Block a user