Fixed bug where selecting entity using scene heirarchy would not update the cursor entity

dev
Shariq Shah 6 years ago
parent bc75bff7af
commit 329075f6f5
  1. 27
      src/game/editor.c
  2. 4
      src/game/entity.c
  3. 2
      src/game/entity.h
  4. 6
      src/game/light.c
  5. 4
      src/game/renderer.c
  6. 2
      src/game/scene.c

@ -1012,7 +1012,7 @@ void editor_entity_select(struct Editor* editor, struct Entity* entity)
{ {
if(!entity && editor->selected_entity) // Deselect if(!entity && editor->selected_entity) // Deselect
{ {
editor->selected_entity->editor_selected = false; editor->selected_entity->selected_in_editor = false;
editor->selected_entity = NULL; editor->selected_entity = NULL;
editor_tool_reset(editor); editor_tool_reset(editor);
} }
@ -1020,7 +1020,7 @@ void editor_entity_select(struct Editor* editor, struct Entity* entity)
{ {
if(editor->selected_entity && editor->selected_entity != entity) if(editor->selected_entity && editor->selected_entity != entity)
{ {
editor->selected_entity->editor_selected = false; editor->selected_entity->selected_in_editor = false;
editor->selected_entity = NULL; editor->selected_entity = NULL;
} }
@ -1030,7 +1030,7 @@ void editor_entity_select(struct Editor* editor, struct Entity* entity)
editor_axis_set(editor, EDITOR_AXIS_XZ); editor_axis_set(editor, EDITOR_AXIS_XZ);
editor->draw_cursor_entity = true; editor->draw_cursor_entity = true;
} }
entity->editor_selected = true; entity->selected_in_editor = true;
editor->selected_entity = entity; editor->selected_entity = entity;
transform_copy(editor->cursor_entity, editor->selected_entity, false); transform_copy(editor->cursor_entity, editor->selected_entity, false);
} }
@ -1304,19 +1304,14 @@ void editor_show_entity_in_list(struct Editor* editor, struct nk_context* contex
if(!entity->active) return; if(!entity->active) return;
nk_layout_row_dynamic(context, 20, 1); nk_layout_row_dynamic(context, 20, 1);
if(nk_selectable_label(context, entity->name, NK_TEXT_ALIGN_LEFT, &entity->editor_selected)) if(nk_selectable_label(context, entity->name, NK_TEXT_ALIGN_LEFT, &entity->selected_in_editor))
{ {
if(editor->selected_entity && editor->selected_entity != entity) if(editor->selected_entity && editor->selected_entity != entity)
{ editor_entity_select(editor, entity);
editor->selected_entity->editor_selected = false; else if(editor->selected_entity && editor->selected_entity == entity && !entity->selected_in_editor)
editor->selected_entity = NULL; editor_entity_select(editor, NULL);
}
else if(editor->selected_entity && editor->selected_entity == entity && !entity->editor_selected)
{
editor->selected_entity = NULL;
}
if(entity->editor_selected) if(entity->selected_in_editor)
{ {
editor->selected_entity = entity; editor->selected_entity = entity;
if(!editor->window_property_inspector) editor->window_property_inspector = true; if(!editor->window_property_inspector) editor->window_property_inspector = true;
@ -1391,7 +1386,7 @@ void editor_window_property_inspector(struct nk_context* context, struct Editor*
struct Entity* parent_ent = entity->transform.parent; struct Entity* parent_ent = entity->transform.parent;
nk_layout_row_dynamic(context, row_height, 2); nk_label(context, "Name", NK_TEXT_ALIGN_LEFT); nk_label(context, entity->name, NK_TEXT_ALIGN_RIGHT); nk_layout_row_dynamic(context, row_height, 2); nk_label(context, "Name", NK_TEXT_ALIGN_LEFT); nk_label(context, entity->name, NK_TEXT_ALIGN_RIGHT);
nk_layout_row_dynamic(context, row_height, 2); nk_label(context, "ID", NK_TEXT_ALIGN_LEFT); nk_labelf(context, NK_TEXT_ALIGN_RIGHT, "%d", entity->id); nk_layout_row_dynamic(context, row_height, 2); nk_label(context, "ID", NK_TEXT_ALIGN_LEFT); nk_labelf(context, NK_TEXT_ALIGN_RIGHT, "%d", entity->id);
nk_layout_row_dynamic(context, row_height, 2); nk_label(context, "Selected", NK_TEXT_ALIGN_LEFT); nk_labelf(context, NK_TEXT_ALIGN_RIGHT, "%s", entity->editor_selected ? "True" : "False"); nk_layout_row_dynamic(context, row_height, 2); nk_label(context, "Selected", NK_TEXT_ALIGN_LEFT); nk_labelf(context, NK_TEXT_ALIGN_RIGHT, "%s", entity->selected_in_editor ? "True" : "False");
nk_layout_row_dynamic(context, row_height, 2); nk_label(context, "Entity Type", NK_TEXT_ALIGN_LEFT); nk_labelf(context, NK_TEXT_ALIGN_RIGHT, "%s", entity_type_name_get(entity)); nk_layout_row_dynamic(context, row_height, 2); nk_label(context, "Entity Type", NK_TEXT_ALIGN_LEFT); nk_labelf(context, NK_TEXT_ALIGN_RIGHT, "%s", entity_type_name_get(entity));
nk_layout_row_dynamic(context, row_height, 2); nk_label(context, "Parent Name", NK_TEXT_ALIGN_LEFT); nk_label(context, parent_ent ? parent_ent->name : "NONE", NK_TEXT_ALIGN_RIGHT); nk_layout_row_dynamic(context, row_height, 2); nk_label(context, "Parent Name", NK_TEXT_ALIGN_LEFT); nk_label(context, parent_ent ? parent_ent->name : "NONE", NK_TEXT_ALIGN_RIGHT);
@ -1467,10 +1462,10 @@ void editor_window_property_inspector(struct nk_context* context, struct Editor*
if(light->type != LT_DIR) if(light->type != LT_DIR)
{ {
nk_layout_row_dynamic(context, row_height, 1); nk_layout_row_dynamic(context, row_height, 1);
light->outer_angle = TO_RADIANS(nk_propertyf(context, "Outer Angle", TO_DEGREES(light->inner_angle), TO_DEGREES(light->outer_angle), 360, 1.f, 0.5f)); light->outer_angle = nk_propertyf(context, "Outer Angle", light->inner_angle, light->outer_angle, 360, 1.f, 0.5f);
nk_layout_row_dynamic(context, row_height, 1); nk_layout_row_dynamic(context, row_height, 1);
light->inner_angle = TO_RADIANS(nk_propertyf(context, "Inner Angle", 1.f, TO_DEGREES(light->inner_angle), TO_DEGREES(light->outer_angle), 1.f, 0.5f)); light->inner_angle = nk_propertyf(context, "Inner Angle", 1.f, light->inner_angle, light->outer_angle, 1.f, 0.5f);
nk_layout_row_dynamic(context, row_height, 1); nk_layout_row_dynamic(context, row_height, 1);
nk_property_int(context, "Radius", 1, &light->radius, INT_MAX, 1, 1); nk_property_int(context, "Radius", 1, &light->radius, INT_MAX, 1, 1);

@ -35,7 +35,7 @@ void entity_init(struct Entity* entity, const char* name, struct Entity* parent)
entity->type = ET_DEFAULT; entity->type = ET_DEFAULT;
entity->active = true; entity->active = true;
entity->marked_for_deletion = false; entity->marked_for_deletion = false;
entity->editor_selected = false; entity->selected_in_editor = false;
transform_init(entity, parent); transform_init(entity, parent);
} }
@ -45,7 +45,7 @@ void entity_reset(struct Entity * entity, int id)
entity->id = id; entity->id = id;
entity->active = false; entity->active = false;
entity->marked_for_deletion = false; entity->marked_for_deletion = false;
entity->editor_selected = false; entity->selected_in_editor = false;
memset(entity->name, '\0', MAX_ENTITY_NAME_LEN); memset(entity->name, '\0', MAX_ENTITY_NAME_LEN);
} }

@ -65,7 +65,7 @@ struct Entity
char name[MAX_ENTITY_NAME_LEN]; char name[MAX_ENTITY_NAME_LEN];
bool marked_for_deletion; bool marked_for_deletion;
bool active; bool active;
bool editor_selected; bool selected_in_editor;
struct Transform transform; struct Transform transform;
}; };

@ -1,8 +1,6 @@
#include "light.h" #include "light.h"
#include "../common/array.h"
#include "entity.h" #include "entity.h"
#include <assert.h>
void light_init(struct Light* light, int light_type) void light_init(struct Light* light, int light_type)
{ {
@ -13,8 +11,8 @@ void light_init(struct Light* light, int light_type)
light->pcf_enabled = false; light->pcf_enabled = false;
light->intensity = 1.f; light->intensity = 1.f;
light->falloff = 1.5f; light->falloff = 1.5f;
light->outer_angle = TO_RADIANS(30.f); light->outer_angle = 30.f;
light->inner_angle = TO_RADIANS(20.f); light->inner_angle = 20.f;
light->radius = 20.f; light->radius = 20.f;
vec3_fill(&light->color, 1.f, 1.f, 1.f); vec3_fill(&light->color, 1.f, 1.f, 1.f);
} }

@ -198,11 +198,11 @@ void renderer_render(struct Renderer* renderer, struct Scene* scene)
memset(uniform_name, '\0', MAX_UNIFORM_NAME_LEN); memset(uniform_name, '\0', MAX_UNIFORM_NAME_LEN);
snprintf(uniform_name, MAX_UNIFORM_NAME_LEN, "lights[%d].outer_angle", light_count); snprintf(uniform_name, MAX_UNIFORM_NAME_LEN, "lights[%d].outer_angle", light_count);
shader_set_uniform_float(material->shader, uniform_name, light->outer_angle); shader_set_uniform_float(material->shader, uniform_name, TO_RADIANS(light->outer_angle));
memset(uniform_name, '\0', MAX_UNIFORM_NAME_LEN); memset(uniform_name, '\0', MAX_UNIFORM_NAME_LEN);
snprintf(uniform_name, MAX_UNIFORM_NAME_LEN, "lights[%d].inner_angle", light_count); snprintf(uniform_name, MAX_UNIFORM_NAME_LEN, "lights[%d].inner_angle", light_count);
shader_set_uniform_float(material->shader, uniform_name, light->inner_angle); shader_set_uniform_float(material->shader, uniform_name, TO_RADIANS(light->inner_angle));
memset(uniform_name, '\0', MAX_UNIFORM_NAME_LEN); memset(uniform_name, '\0', MAX_UNIFORM_NAME_LEN);
snprintf(uniform_name, MAX_UNIFORM_NAME_LEN, "lights[%d].falloff", light_count); snprintf(uniform_name, MAX_UNIFORM_NAME_LEN, "lights[%d].falloff", light_count);

@ -396,7 +396,7 @@ void scene_entity_remove(struct Scene* scene, struct Entity* entity)
transform_destroy(entity); transform_destroy(entity);
entity->active = false; entity->active = false;
entity->editor_selected = false; entity->selected_in_editor = false;
entity->marked_for_deletion = false; entity->marked_for_deletion = false;
memset(entity->name, '\0', MAX_ENTITY_NAME_LEN); memset(entity->name, '\0', MAX_ENTITY_NAME_LEN);
} }

Loading…
Cancel
Save