Tiny refactor

This commit is contained in:
2024-10-18 16:12:24 +02:00
parent 8ee000ab74
commit 1d5b4499a4
38 changed files with 645 additions and 637 deletions

View File

@@ -64,7 +64,7 @@ Editor :: struct {
should_check_entities: bool;
camera: Camera;
transform_gizmo: Transform_Gizmo;
selected_entity: *Entity;
selected_entities: [..] *Entity;
mouse_viewport_state: Interaction_State;
last_right_mouse_click_time: float;
@@ -262,12 +262,12 @@ update_transform_gizmo :: (ray: Ray, mouse_position: Vector2) -> bool {
// r1.direction = rotate(axis_vec, engine.editor.transform_gizmo.transform.orientation);
// // Shoot a ray from screen to world
// mouse_position : Vector2;
// mouse_position.x = xx engine.input.mouse.x;
// mouse_position.y = xx engine.input.mouse.y;
// mouse_position.x = xx engine.engine.input.mouse.x;
// mouse_position.y = xx engine.engine.input.mouse.y;
//
// screen_size : Vector2;
// screen_size.x = cast(float)engine.window.width;
// screen_size.y = cast(float)engine.window.height;
// screen_size.x = cast(float)engine.engine.window.width;
// screen_size.y = cast(float)engine.engine.window.height;
//
// r2 := screen_to_ray_v2(*engine.editor.camera, mouse_position, screen_size);
//

View File

@@ -1,13 +1,13 @@
#load "../ui/widgets.jai";
pick_scene_view_at :: (coordinates: Vector2) {
ray := normalized_screen_to_ray_v2(*current_scene.camera, coordinates);
ray := normalized_screen_to_ray_v2(*engine.current_scene.camera, coordinates);
if editor.should_check_entities {
hit_entity : *Entity;
closest : float = 100000000;
for current_scene.entities {
for engine.current_scene.entities {
if !(it.flags & .RENDERABLE) continue;
//if it.flags & Entity_Flags.DELETED || !it.selectable || it.parent != null continue;
@@ -19,11 +19,14 @@ pick_scene_view_at :: (coordinates: Vector2) {
}
if hit_entity != null {
if cast(*Entity)hit_entity != editor.selected_entity {
editor.selected_entity = hit_entity;
if !array_find(editor.selected_entities, hit_entity) {
if !key_pressed(.CTRL) {
editor.selected_entities.count = 0;
}
array_add(*editor.selected_entities, hit_entity);
}
} else if editor.selected_entity != null {
editor.selected_entity = null;
} else {
editor.selected_entities.count = 0;
}
}
}
@@ -55,16 +58,16 @@ editor_ui :: () {
// case .PLAYING; {
// ui_set_next_background_color(.{0,0.6,0,1});
// if ui_button_with_texture(editor.icons.stop) {
// edit_current_scene();
// edit_engine.current_scene();
// }
// ui_label(tprint("Playing '%'", current_scene.name), .{0,0.7,0,1});
// ui_label(tprint("Playing '%'", engine.current_scene.name), .{0,0.7,0,1});
// }
// case .EDITING; {
ui_set_next_background_color(.{0.6,0,0,1});
//if ui_button_with_texture(editor.icons.play) {
// play_current_editor_scene();
//}
ui_label(tprint("Editing '%'", current_scene.name), .{1,1,1,1});
ui_label(tprint("Editing '%'", engine.current_scene.name), .{1,1,1,1});
//}
//}
}
@@ -93,17 +96,18 @@ editor_ui :: () {
ui_set_next_size_x(.PCT, 1.0);
ui_tab_title_bar("ENTITIES");
for current_scene.entities {
for engine.current_scene.entities {
ui_set_next_padding(20);
clicked := false;
selected := array_find(editor.selected_entities, it);
if it.name.count == 0 {
clicked = ui_clickable_label(tprint("%", it.type), it == editor.selected_entity, it_index);
clicked = ui_clickable_label(tprint("%", it.type), selected, it_index);
} else {
clicked = ui_clickable_label(it.name, it == editor.selected_entity, it_index);
clicked = ui_clickable_label(it.name, selected, it_index);
}
if clicked {
editor.selected_entity = it;
if clicked && !selected {
array_add(*editor.selected_entities, it);
}
//ui_space(0, 5);
}
@@ -149,14 +153,14 @@ editor_ui :: () {
ui_set_next_size_x(.PCT, 1.0);
ui_tab_title_bar("PROPERTIES");
if editor.selected_entity != null {
ui_slider(*slider_value, 0.0, 1.0);
ui_label(tprint("Name: %", editor.selected_entity.name));
ui_label(tprint("Id: %", editor.selected_entity.id));
ui_label(tprint("Position: % % %", editor.selected_entity.transform.position.x, editor.selected_entity.transform.position.y, editor.selected_entity.transform.position.z));
ui_label(tprint("Rotation: % % % %", editor.selected_entity.transform.orientation.x, editor.selected_entity.transform.orientation.y, editor.selected_entity.transform.orientation.z, editor.selected_entity.transform.orientation.w));
ui_label(tprint("Scale: % % %", editor.selected_entity.transform.scale.x, editor.selected_entity.transform.scale.y, editor.selected_entity.transform.scale.z));
}
//if editor.selected_entity != null {
// ui_slider(*slider_value, 0.0, 1.0);
// ui_label(tprint("Name: %", editor.selected_entity.name));
// ui_label(tprint("Id: %", editor.selected_entity.id));
// ui_label(tprint("Position: % % %", editor.selected_entity.transform.position.x, editor.selected_entity.transform.position.y, editor.selected_entity.transform.position.z));
// ui_label(tprint("Rotation: % % % %", editor.selected_entity.transform.orientation.x, editor.selected_entity.transform.orientation.y, editor.selected_entity.transform.orientation.z, editor.selected_entity.transform.orientation.w));
// ui_label(tprint("Scale: % % %", editor.selected_entity.transform.scale.x, editor.selected_entity.transform.scale.y, editor.selected_entity.transform.scale.z));
//}
}
ui_pop_parent();
@@ -178,18 +182,18 @@ base_editor_update :: () {
// @Incomplete: MOVE THIS
editor.should_check_entities = true;
if editor.selected_entity != null {
gizmo_scale := distance(editor.selected_entity.transform.position, editor.camera.position) * 0.1 * 0.5;
editor.transform_gizmo.uniform_gizmo_scale = gizmo_scale;
set_scale(*editor.transform_gizmo.transform, .{gizmo_scale, gizmo_scale, gizmo_scale});
//if editor.selected_entity != null {
// gizmo_scale := distance(editor.selected_entity.transform.position, editor.camera.position) * 0.1 * 0.5;
// editor.transform_gizmo.uniform_gizmo_scale = gizmo_scale;
// set_scale(*editor.transform_gizmo.transform, .{gizmo_scale, gizmo_scale, gizmo_scale});
coordinates := Vector2.{editor.mouse_viewport_state.normalized_local_mouse_coordinates.x, 1.0 - editor.mouse_viewport_state.normalized_local_mouse_coordinates.y};
ray := normalized_screen_to_ray_v2(*editor.camera, coordinates);
// coordinates := Vector2.{editor.mouse_viewport_state.normalized_local_mouse_coordinates.x, 1.0 - editor.mouse_viewport_state.normalized_local_mouse_coordinates.y};
// ray := normalized_screen_to_ray_v2(*editor.camera, coordinates);
if update_transform_gizmo(ray, coordinates) {
editor.should_check_entities = false;
}
}
// if update_transform_gizmo(ray, coordinates) {
// editor.should_check_entities = false;
// }
//}
editor_ui();
@@ -206,27 +210,27 @@ base_editor_update :: () {
camera := *editor.camera;
if key_pressed(.CTRL) && key_down(.S) {
save_scene(current_scene, "../assets/scenes/");
save_scene(engine.current_scene, "../assets/scenes/");
//show_message("Saved scene");
}
if editor.selected_entity != null {
// @Incomplete:@Incomplete: Duplicate
//if key_pressed(.CTRL) && key_down(.D) {
// make_directory_if_it_does_not_exist("../temp");
// save_entity(editor.selected_entity, "../temp/", "temp");
// duplicated := load_entity(editor_scene, "../temp/temp.ent");
// editor.selected_entity = duplicated;
//}
//if editor.selected_entity != null {
// // @Incomplete:@Incomplete: Duplicate
// //if key_pressed(.CTRL) && key_down(.D) {
// // make_directory_if_it_does_not_exist("../temp");
// // save_entity(editor.selected_entity, "../temp/", "temp");
// // duplicated := load_entity(editor_scene, "../temp/temp.ent");
// // editor.selected_entity = duplicated;
// //}
// DELETE
// DELETE
//if key_down(.DELETE) || key_down(.BACKSPACE) {
// delete_entity(editor.selected_entity);
// editor.selected_entity = null;
// editor.transform_gizmo.selected_axis = .NONE;
//}
}
// // DELETE
// // DELETE
// //if key_down(.DELETE) || key_down(.BACKSPACE) {
// // delete_entity(editor.selected_entity);
// // editor.selected_entity = null;
// // editor.transform_gizmo.selected_axis = .NONE;
// //}
//}
//if key_pressed(.CTRL) && key_down(.Z) {
// editor_undo();
@@ -266,8 +270,8 @@ base_editor_update :: () {
}
MOUSE_SENSITIVITY :: 0.06;
camera.rotation.yaw -= input.mouse.delta_x * MOUSE_SENSITIVITY;
camera.rotation.pitch += -input.mouse.delta_y * MOUSE_SENSITIVITY;
camera.rotation.yaw -= engine.input.mouse.delta_x * MOUSE_SENSITIVITY;
camera.rotation.pitch += -engine.input.mouse.delta_y * MOUSE_SENSITIVITY;
if key_down(.MOUSE_RIGHT) {
editor.last_right_mouse_click_time = time;
@@ -277,11 +281,11 @@ base_editor_update :: () {
if time - editor.last_right_mouse_click_time < 0.2 {
mouse_position : Vector2;
mouse_position.x = xx input.mouse.x;
mouse_position.y = xx input.mouse.y;
mouse_position.x = xx engine.input.mouse.x;
mouse_position.y = xx engine.input.mouse.y;
editor.show_menu = true;
editor.menu_position.x = mouse_position.x;
editor.menu_position.y = cast(float)renderer.render_target_height - mouse_position.y;
editor.menu_position.y = cast(float)engine.renderer.render_target_height - mouse_position.y;
}
if key_down(.W) {
@@ -300,11 +304,11 @@ base_editor_update :: () {
update_view_matrix(camera);
}
if editor.selected_entity != null {
e := editor.selected_entity;
set_position(*editor.transform_gizmo.transform, e.transform.position);
update_gizmo_buffers();
}
//if editor.selected_entity != null {
// e := editor.selected_entity;
// set_position(*editor.transform_gizmo.transform, e.transform.position);
// update_gizmo_buffers();
//}
//edit_scene_settings(*game_state.current_scene.settings);
//edit_scene_settings(*game_state.engine.current_scene.settings);
}