From e18b32a9a5ee467f9ffaded914a0eaf3072d9d31 Mon Sep 17 00:00:00 2001 From: Shariq Shah Date: Wed, 22 Jan 2020 21:56:07 +1100 Subject: [PATCH] Added scene reload command and fps display to debug vars and made minor changes to how selected entity is displayed in editor --- src/common/limits.h | 2 ++ src/common/version.h | 2 +- src/game/console.c | 11 ++++++++ src/game/editor.c | 64 +++++++++++++++++++------------------------- src/game/game.c | 18 ++++++++++--- src/game/player.c | 4 --- todo.txt | 5 ++-- 7 files changed, 59 insertions(+), 47 deletions(-) diff --git a/src/common/limits.h b/src/common/limits.h index c2d4dae..b90cb41 100644 --- a/src/common/limits.h +++ b/src/common/limits.h @@ -20,4 +20,6 @@ #define MAX_MATERIAL_REGISTERED_STATIC_MESHES 1024 +#define MAX_FRAME_TIME 0.5f + #endif diff --git a/src/common/version.h b/src/common/version.h index 82c748f..5ccd18e 100755 --- a/src/common/version.h +++ b/src/common/version.h @@ -4,7 +4,7 @@ /* Auto generated version file. DO NOT MODIFY */ #define SYMMETRY_VERSION_MAJOR 0 #define SYMMETRY_VERSION_MINOR 1 -#define SYMMETRY_VERSION_REVISION 317 +#define SYMMETRY_VERSION_REVISION 318 #define SYMMETRY_VERSION_BRANCH "dev" #endif \ No newline at end of file diff --git a/src/game/console.c b/src/game/console.c index e1bb915..b26826e 100755 --- a/src/game/console.c +++ b/src/game/console.c @@ -22,6 +22,7 @@ static void console_on_key_release(struct Event* event); static void console_command_scene_empty(struct Console* console, const char* command); static void console_command_scene_save(struct Console* console, const char* command); static void console_command_scene_load(struct Console* console, const char* command); +static void console_command_scene_reload(struct Console* console, const char* command); static void console_command_entity_save(struct Console* console, const char* command); static void console_command_entity_load(struct Console* console, const char* command); static void console_command_debug_vars_toggle(struct Console* console, const char* command); @@ -60,6 +61,7 @@ void console_init(struct Console* console) hashmap_ptr_set(console->commands, "scene_empty", &console_command_scene_empty); hashmap_ptr_set(console->commands, "scene_save", &console_command_scene_save); hashmap_ptr_set(console->commands, "scene_load", &console_command_scene_load); + hashmap_ptr_set(console->commands, "scene_reload", &console_command_scene_reload); hashmap_ptr_set(console->commands, "entity_save", &console_command_entity_save); hashmap_ptr_set(console->commands, "entity_load", &console_command_entity_load); hashmap_ptr_set(console->commands, "debug_vars_toggle", &console_command_debug_vars_toggle); @@ -349,3 +351,12 @@ void console_command_debug_vars_location_set(struct Console* console, const char debug_vars_location_set(debug_vars, location); } + +void console_command_scene_reload(struct Console* console, const char* command) +{ + struct Scene* scene = game_state_get()->scene; + char filename[MAX_FILENAME_LEN]; + strncpy(filename, scene->filename, MAX_FILENAME_LEN); + if(!scene_load(scene, filename, DIRT_INSTALL)) + log_error("scene_load", "Command failed"); +} diff --git a/src/game/editor.c b/src/game/editor.c index 98b235b..2a50449 100755 --- a/src/game/editor.c +++ b/src/game/editor.c @@ -204,50 +204,42 @@ void editor_render(struct Editor* editor, struct Camera * active_camera) if(game_state->editor->selected_entity) { - /* Draw selected entity */ - if(editor->selected_entity->type == ET_STATIC_MESH) + /* Visualize entity specific state */ + vec3 abs_pos; + quat abs_rot; + transform_get_absolute_position(editor->selected_entity, &abs_pos); + transform_get_absolute_rot(editor->selected_entity, &abs_rot); + switch(editor->selected_entity->type) { - glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); - shader_bind(renderer->debug_shader); + case ET_LIGHT: + { + struct Light* light = (struct Light*)editor->selected_entity; + if(light->type != LT_POINT) { - static mat4 mvp; - shader_set_uniform_vec4(renderer->debug_shader, "debug_color", &editor->selected_entity_color); - struct Static_Mesh* mesh = (struct Static_Mesh*)editor->selected_entity; - struct Model* model = &mesh->model; - struct Transform* transform = &mesh->base.transform; - int geometry = model->geometry_index; - mat4_identity(&mvp); - mat4_mul(&mvp, &active_camera->view_proj_mat, &transform->trans_mat); - shader_set_uniform_mat4(renderer->debug_shader, "mvp", &mvp); - geom_render(geometry, GDM_TRIANGLES); + struct Ray light_ray; + vec3_assign(&light_ray.origin, &abs_pos); + transform_get_absolute_forward(light, &light_ray.direction); + im_ray(&light_ray, 5.f, editor->cursor_entity_color, 3); } - shader_unbind(); - glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); - } - else - { - //For now draw a placeholder sphere just to visually denote that the entity is selected - vec3 abs_pos; - quat abs_rot; - transform_get_absolute_position(editor->selected_entity, &abs_pos); - transform_get_absolute_rot(editor->selected_entity, &abs_rot); - im_sphere(1.f, abs_pos, abs_rot, editor->selected_entity_color, GDM_TRIANGLES, 1); - switch(editor->selected_entity->type) - { - case ET_LIGHT: + if(light->type != LT_DIR) { - struct Light* light = (struct Light*)editor->selected_entity; - if(light->type != LT_POINT) + quat rotation = editor->selected_entity->transform.rotation; + vec3 axis = { 1.f, 0.f, 0.f }; + quat_axis_angle(&rotation, &axis, -90.f); + im_circle(light->radius, 30, false, abs_pos, rotation, editor->cursor_entity_color, 3); + + if(light->type == LT_SPOT) { - struct Ray light_ray; - vec3_assign(&light_ray.origin, &abs_pos); - transform_get_absolute_forward(light, &light_ray.direction); - im_ray(&light_ray, 5.f, editor->cursor_entity_color, 3); + float yaw = quat_get_yaw(&abs_rot); + float half_outer_angle = light->outer_angle / 2.f; + float half_inner_angle = light->inner_angle / 2.f; + im_arc(light->radius, yaw - half_outer_angle, yaw + half_outer_angle, 15, false, abs_pos, rotation, editor->selected_entity_color, 3); + im_arc(light->radius, yaw - half_inner_angle, yaw + half_inner_angle, 15, false, abs_pos, rotation, editor->cursor_entity_color, 4); } } - break; - } + } + break; } /* Draw bounding box for selected entity */ diff --git a/src/game/game.c b/src/game/game.c index fc9597d..2125d3d 100755 --- a/src/game/game.c +++ b/src/game/game.c @@ -35,15 +35,13 @@ #include "debug_vars.h" #include "im_render.h" #include "event.h" +#include "../common/limits.h" #define UNUSED(a) (void)a #define MIN_NUM(a,b) ((a) < (b) ? (a) : (b)) #define MAX_NUM(a,b) ((a) < (b) ? (b) : (a)) #define LEN(a) (sizeof(a)/sizeof(a)[0]) - -#define MAX_FRAME_TIME 0.5f - static void game_update(float dt, bool* window_should_close); static void game_post_update(float dt); static void game_render(void); @@ -537,7 +535,19 @@ bool game_run(void) void game_update(float dt, bool* window_should_close) { - //if(input_is_key_pressed(KEY_ESCAPE)) *window_should_close = true; + static int frames = 0; + static int fps = 0; + static float seconds = 0.f; + seconds += dt; + frames++; + if(seconds >= 1.f) + { + fps = frames; + seconds = 0.f; + frames = 0; + } + debug_vars_show_float("FPS", fps); + if(input_map_state_get("Window_Fullscreen", KS_RELEASED)) window_fullscreen_set(game_state->window, true); if(input_map_state_get("Window_Maximize", KS_RELEASED)) window_fullscreen_set(game_state->window, false); if(input_map_state_get("Console_Toggle", KS_RELEASED)) console_toggle(game_state->console); diff --git a/src/game/player.c b/src/game/player.c index ae879a9..75afff9 100755 --- a/src/game/player.c +++ b/src/game/player.c @@ -171,7 +171,6 @@ void player_update(struct Player* player, struct Scene* scene, float dt) { struct Entity* colliding_entity = ray_result.entities_intersected[i]; float distance = bv_distance_ray_bounding_box(&forward_ray, &colliding_entity->derived_bounding_box); - debug_vars_show_float("Collision ahead", distance); if(distance > 0.f && distance <= player->min_forward_distance && colliding_entity != player->mesh) { vec3 intersection_point = forward_ray.direction; @@ -210,7 +209,6 @@ void player_update(struct Player* player, struct Scene* scene, float dt) if(colliding_entity == player->mesh) continue; float distance = bv_distance_ray_bounding_box(&downward_ray, &colliding_entity->derived_bounding_box); - debug_vars_show_float("Collision below", distance); if(distance > 0.f && distance <= player->min_downward_distance && !jumping) { move_speed_vertical = 0.f; @@ -228,8 +226,6 @@ void player_update(struct Player* player, struct Scene* scene, float dt) translation.y = move_speed_vertical * dt; transform_translate(player, &translation, TS_WORLD); - debug_vars_show_float("MoveSpeed", move_speed); - debug_vars_show_vec3("Translation", &translation); debug_vars_show_bool("Grounded", player->grounded); } diff --git a/todo.txt b/todo.txt index 9c7161a..07beca6 100644 --- a/todo.txt +++ b/todo.txt @@ -1,6 +1,5 @@ Todo: - Enemy ray casting and shooting - - Scene reload command - Player shooting - Player jump cooldown, don't allow jump until a certian time interval has passed, even if we're grounded - Sky Cube maps @@ -127,6 +126,7 @@ Bugs: - Fix quaternion resetting/flipping - Fix aggressive frustum culling when camera looks up and the object right infront of the viewer gets culled - Fix crash when exiting from fullscreen mode + - Fix arc/circle direction in im_draw based functions not aligning with entity's actual current forward direction Done: * Input @@ -404,4 +404,5 @@ Done: * Sound source entity functions that automatically track if handles are valid and create/update as necessary * Apply sound source properties to source instance whenever a new instance is created * Imlemented reading/writing enemy mesh and weapon sound to file and resetting it in code - * Implemented on_load and on_update callbacks for enemies. Different enemy types have different callbacks that are assigned when they are created. \ No newline at end of file + * Implemented on_load and on_update callbacks for enemies. Different enemy types have different callbacks that are assigned when they are created. + * Added Scene reload command \ No newline at end of file