Minor addition and refinements in editor behaviour

dev
Shariq Shah 6 years ago
parent bd55fc66bf
commit 76a6e48f5e
  1. 42
      assets/scenes/Level_1.symtres
  2. 56
      assets/scenes/default.symtres
  3. 45
      src/game/editor.c
  4. 2
      src/game/scene.c
  5. 1
      src/game/scene.h
  6. 8
      todo.txt

@ -0,0 +1,42 @@
Scene_Config
{
debug_draw_color : 0.800 0.400 0.100 1.000
fog_type : 1
fog_density : 0.1000
fog_color : 0.170 0.490 0.630
debug_draw_physics : false
fog_start_distance : 10.0000
fog_max_distance : 450.0000
debug_draw_enabled : false
debug_draw_mode : 0
ambient_light : 0.100 0.100 0.100
}
Player
{
type : 2
scale : 1.000 1.000 1.000
rotation : 0.000 0.997 0.000 -0.078
active : true
position : 32.290 10.461 -8.782
name : Player
}
Scene_Entity_Entry
{
scale : 68.000 1.000 68.000
rotation : 0.000 0.000 0.000 1.000
position : -17.000 0.000 -20.000
filename : cube
name : Cube
}
Scene_Entity_Entry
{
scale : 68.000 3.000 1.000
rotation : 0.000 0.000 0.000 1.000
position : -18.000 3.000 -57.000
filename : cube
name : Cube
}

@ -16,9 +16,9 @@ Player
{ {
type : 2 type : 2
scale : 1.000 1.000 1.000 scale : 1.000 1.000 1.000
rotation : 0.000 0.000 0.000 1.000 rotation : 0.000 0.002 0.000 1.000
active : true active : true
position : 5.970 1.130 16.740 position : 5.970 1.130 17.850
name : Player name : Player
} }
@ -45,21 +45,23 @@ Entity
Entity Entity
{ {
type : 7 type : 5
scale : 1.000 1.000 1.000 scale : 1.000 1.000 1.000
volume : 1.0000 inner_angle : 20.0000
rolloff_factor : 0.9500 falloff : 1.5000
light_type : 2
depth_bias : 0.0005
rotation : 0.000 0.000 0.000 1.000 rotation : 0.000 0.000 0.000 1.000
loop : true cast_shadow : false
sound_min_distance : 0.0000 intensity : 1.0000
color : 1.000 1.000 1.000
active : true active : true
playing : true radius : 20.0000
position : 0.000 3.000 0.000 position : 0.000 5.000 0.000
source_filename : sounds/teh_beatz.wav outer_angle : 30.0000
sound_type : 1 name : Test_Light
sound_max_distance : 10.0000 pcf_enabled : false
name : Beats valid : true
sound_attenuation_type : 2
} }
Entity Entity
@ -948,22 +950,20 @@ Entity
Entity Entity
{ {
type : 5 type : 7
scale : 1.000 1.000 1.000 scale : 1.000 1.000 1.000
inner_angle : 20.0000 volume : 1.0000
falloff : 1.5000 rolloff_factor : 0.9500
light_type : 2
depth_bias : 0.0005
rotation : 0.000 0.000 0.000 1.000 rotation : 0.000 0.000 0.000 1.000
cast_shadow : false loop : true
intensity : 1.0000 sound_min_distance : 0.0000
color : 1.000 1.000 1.000
active : true active : true
radius : 20.0000 playing : true
position : 0.000 5.000 0.000 position : 0.000 3.000 0.000
outer_angle : 30.0000 source_filename : sounds/teh_beatz.wav
name : Test_Light sound_type : 1
pcf_enabled : false sound_max_distance : 10.0000
valid : true name : Beats
sound_attenuation_type : 2
} }

@ -725,7 +725,7 @@ void editor_scene_dialog(struct Editor* editor, struct nk_context* context)
int row_height = 25; int row_height = 25;
int popup_x = 0; int popup_x = 0;
int popup_y = 0; int popup_y = 0;
int popup_width = 200; int popup_width = 300;
int popup_height = 200; int popup_height = 200;
int display_width = 0; int display_width = 0;
int display_height = 0; int display_height = 0;
@ -751,11 +751,13 @@ void editor_scene_dialog(struct Editor* editor, struct nk_context* context)
if(copy_scene_filename) if(copy_scene_filename)
{ {
memset(scene_filename, '\0', MAX_FILENAME_LEN); memset(scene_filename, '\0', MAX_FILENAME_LEN);
strncpy(scene_filename, scene->filename, MAX_FILENAME_LEN);
} }
int scene_filename_flags = NK_EDIT_SIG_ENTER | NK_EDIT_GOTO_END_ON_ACTIVATE | NK_EDIT_FIELD; int scene_filename_flags = NK_EDIT_SIG_ENTER | NK_EDIT_FIELD | NK_EDIT_AUTO_SELECT | NK_EDIT_SELECTABLE | NK_EDIT_GOTO_END_ON_ACTIVATE;
nk_edit_focus(context, scene_filename_flags);
int scene_filename_state = nk_edit_string_zero_terminated(context, scene_filename_flags, scene_filename, MAX_FILENAME_LEN, NULL); int scene_filename_state = nk_edit_string_zero_terminated(context, scene_filename_flags, scene_filename, MAX_FILENAME_LEN, NULL);
if(scene_filename_state & NK_EDIT_ACTIVATED) if(scene_filename_state & NK_EDIT_ACTIVATED || scene_filename_state & NK_EDIT_ACTIVE)
{ {
copy_scene_filename = false; copy_scene_filename = false;
} }
@ -1159,9 +1161,24 @@ void editor_on_key_release(const struct Event* event)
struct Game_State* game_state = game_state_get(); struct Game_State* game_state = game_state_get();
struct Editor* editor = game_state->editor; struct Editor* editor = game_state->editor;
struct Gui* gui = game_state->gui; struct Gui* gui = game_state->gui;
if(game_state->game_mode != GAME_MODE_EDITOR || nk_window_is_any_hovered(&gui->context) || game_state->console->visible) if(game_state->game_mode != GAME_MODE_EDITOR || game_state->console->visible)
return; return;
/* Valid shortcuts when a ui element is hovered */
if(event->key.key == KEY_ESCAPE)
{
if(editor->window_entity_dialog == 1)
editor->window_entity_dialog = 0;
else if(editor->window_scene_dialog == 1)
editor->window_scene_dialog = 0;
else
editor_entity_select(editor, NULL);
}
if(nk_window_is_any_hovered(&gui->context))
return;
/* All other shortcuts*/
/* Tool Cycle */ /* Tool Cycle */
if(event->key.key == KEY_TAB) if(event->key.key == KEY_TAB)
{ {
@ -1210,7 +1227,6 @@ void editor_on_key_release(const struct Event* event)
if(event->key.key == KEY_0) editor->grid_scale = 0.5f; if(event->key.key == KEY_0) editor->grid_scale = 0.5f;
if(event->key.key == KEY_G) editor->grid_enabled = !editor->grid_enabled; if(event->key.key == KEY_G) editor->grid_enabled = !editor->grid_enabled;
if(event->key.key == KEY_ESCAPE) editor_entity_select(editor, NULL);
if(event->key.key == KEY_DELETE && editor->selected_entity) if(event->key.key == KEY_DELETE && editor->selected_entity)
{ {
@ -1226,6 +1242,18 @@ void editor_on_key_release(const struct Event* event)
editor_entity_select(editor, new_entity); editor_entity_select(editor, new_entity);
} }
} }
if(event->key.key == KEY_S && input_is_key_pressed(KEY_LCTRL) && !editor->camera_looking_around)
{
struct Scene* scene = game_state->scene;
scene_save(scene, scene->filename, DIRT_INSTALL);
}
if(event->key.key == KEY_O && input_is_key_pressed(KEY_LCTRL) && !editor->camera_looking_around)
{
editor->scene_operation_save = false;
editor->window_scene_dialog = 1;
}
} }
void editor_tool_set(struct Editor* editor, int tool) void editor_tool_set(struct Editor* editor, int tool)
@ -1743,7 +1771,7 @@ void editor_window_property_inspector(struct nk_context* context, struct Editor*
nk_layout_row_dynamic(context, row_height, 1); nk_label(context, "Position", NK_TEXT_ALIGN_CENTERED); nk_layout_row_dynamic(context, row_height, 1); nk_label(context, "Position", NK_TEXT_ALIGN_CENTERED);
vec3 abs_pos = { 0.f, 0.f, 0.f }; vec3 abs_pos = { 0.f, 0.f, 0.f };
transform_get_absolute_position(entity, &abs_pos); transform_get_absolute_position(entity, &abs_pos);
if(editor_widget_v3(context, &abs_pos, "#X", "#Y", "#Z", -FLT_MAX, FLT_MAX, 5.f, 1.f, row_height)) transform_set_position(entity, &abs_pos); if(editor_widget_v3(context, &abs_pos, "#X", "#Y", "#Z", -FLT_MAX, FLT_MAX, 1.f, 1.f, row_height)) transform_set_position(entity, &abs_pos);
nk_layout_row_dynamic(context, row_height, 1); nk_label(context, "Rotation", NK_TEXT_ALIGN_CENTERED); nk_layout_row_dynamic(context, row_height, 1); nk_label(context, "Rotation", NK_TEXT_ALIGN_CENTERED);
quat abs_rot = { 0.f, 0.f, 0.f, 1.f }; quat abs_rot = { 0.f, 0.f, 0.f, 1.f };
@ -2250,13 +2278,14 @@ void editor_entity_dialog(struct Editor* editor, struct nk_context* context)
if(copy_entity_filename) if(copy_entity_filename)
{ {
memset(entity_filename, '\0', MAX_FILENAME_LEN); memset(entity_filename, '\0', MAX_FILENAME_LEN);
if(editor->selected_entity->archetype_index != -1) if(save && editor->selected_entity->archetype_index != -1)
strncpy(entity_filename, scene->entity_archetypes[editor->selected_entity->archetype_index], MAX_FILENAME_LEN); strncpy(entity_filename, scene->entity_archetypes[editor->selected_entity->archetype_index], MAX_FILENAME_LEN);
} }
int entity_filename_flags = NK_EDIT_SIG_ENTER | NK_EDIT_GOTO_END_ON_ACTIVATE | NK_EDIT_FIELD; int entity_filename_flags = NK_EDIT_SIG_ENTER | NK_EDIT_GOTO_END_ON_ACTIVATE | NK_EDIT_FIELD;
nk_edit_focus(context, entity_filename_flags);
int entity_filename_state = nk_edit_string_zero_terminated(context, entity_filename_flags, entity_filename, MAX_FILENAME_LEN, NULL); int entity_filename_state = nk_edit_string_zero_terminated(context, entity_filename_flags, entity_filename, MAX_FILENAME_LEN, NULL);
if(entity_filename_state & NK_EDIT_ACTIVATED) if(entity_filename_state & NK_EDIT_ACTIVATED || entity_filename_state & NK_EDIT_ACTIVE)
{ {
copy_entity_filename = false; copy_entity_filename = false;
} }

@ -30,6 +30,7 @@ void scene_init(struct Scene* scene)
assert(scene); assert(scene);
struct Game_State* game_state = game_state_get(); struct Game_State* game_state = game_state_get();
strncpy(scene->filename, "UNNAMED_SCENE", MAX_FILENAME_LEN);
//Initialize the root entity //Initialize the root entity
entity_init(&scene->root_entity, "ROOT_ENTITY", NULL); entity_init(&scene->root_entity, "ROOT_ENTITY", NULL);
scene->root_entity.flags |= EF_ACTIVE; scene->root_entity.flags |= EF_ACTIVE;
@ -194,6 +195,7 @@ bool scene_load(struct Scene* scene, const char* filename, int directory_type)
parser_free(parsed_file); parser_free(parsed_file);
fclose(scene_file); fclose(scene_file);
strncpy(scene->filename, filename, MAX_FILENAME_LEN);
return num_objects_loaded > 0 ? true : false; return num_objects_loaded > 0 ? true : false;
} }

@ -16,6 +16,7 @@ struct Raycast_Result;
struct Scene struct Scene
{ {
char filename[MAX_FILENAME_LEN];
struct Entity root_entity; struct Entity root_entity;
struct Player player; struct Player player;
struct Entity entities[MAX_ENTITIES]; struct Entity entities[MAX_ENTITIES];

@ -1,4 +1,6 @@
Todo: Todo:
- Allow picking and selecting other entity types in editor i.e. the ones that don't have meshes
- Separate entity types in entity hierarchy view by the entity type or use a tree view to show parent/child relation or use different colours for different entity types
- When loading entities, show an additional optional textfield where user can enter the name they want for the entity after it is loaded - When loading entities, show an additional optional textfield where user can enter the name they want for the entity after it is loaded
- Add editor undo for transformation operations - Add editor undo for transformation operations
- Decide how to handle scale when checking sphere-ray intersection - Decide how to handle scale when checking sphere-ray intersection
@ -20,9 +22,6 @@ Todo:
- Multisampled buffers to bring back aa - Multisampled buffers to bring back aa
- Change mouse behaviour to lock cursor when looking around so as not to interfere with gui elements when in editor mode - Change mouse behaviour to lock cursor when looking around so as not to interfere with gui elements when in editor mode
- Folder management api to create/delete folders when none exist. Dirent would suffice for our simple needs? - Folder management api to create/delete folders when none exist. Dirent would suffice for our simple needs?
- Display default mesh when selected entity type in editor does not have a mesh
- Allow picking and selecting other entity types in editor i.e. the ones that don't have meshes
- Separate entity types in entity hierarchy view by the entity type or use a tree view to show parent/child relation or use different colours for different entity types
? Entity creator window to create new types of entities and write them ? Entity creator window to create new types of entities and write them
to disk to disk
- Entity browser window which lists all existing entity types from - Entity browser window which lists all existing entity types from
@ -381,3 +380,6 @@ Done:
* Implelement contextual actions for entites that are shown in scene hierarchy * Implelement contextual actions for entites that are shown in scene hierarchy
* For entities that have archetypes, check read/write them to the file they were loaded from when showing the save entity dialog * For entities that have archetypes, check read/write them to the file they were loaded from when showing the save entity dialog
* Duplicate with Ctrl-D * Duplicate with Ctrl-D
* Display default mesh when selected entity type in editor does not have a mesh
* Associate each scene with a file so that when C-s is pressed the scene is automatically saved to that file
* Change the increments in the editor from 5 to 1
Loading…
Cancel
Save