Added scene reload command and fps display to debug vars and made minor changes to how selected entity is displayed in editor

dev
Shariq Shah 6 years ago
parent 8f9a43d1ec
commit e18b32a9a5
  1. 2
      src/common/limits.h
  2. 2
      src/common/version.h
  3. 11
      src/game/console.c
  4. 64
      src/game/editor.c
  5. 18
      src/game/game.c
  6. 4
      src/game/player.c
  7. 3
      todo.txt

@ -20,4 +20,6 @@
#define MAX_MATERIAL_REGISTERED_STATIC_MESHES 1024 #define MAX_MATERIAL_REGISTERED_STATIC_MESHES 1024
#define MAX_FRAME_TIME 0.5f
#endif #endif

@ -4,7 +4,7 @@
/* Auto generated version file. DO NOT MODIFY */ /* Auto generated version file. DO NOT MODIFY */
#define SYMMETRY_VERSION_MAJOR 0 #define SYMMETRY_VERSION_MAJOR 0
#define SYMMETRY_VERSION_MINOR 1 #define SYMMETRY_VERSION_MINOR 1
#define SYMMETRY_VERSION_REVISION 317 #define SYMMETRY_VERSION_REVISION 318
#define SYMMETRY_VERSION_BRANCH "dev" #define SYMMETRY_VERSION_BRANCH "dev"
#endif #endif

@ -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_empty(struct Console* console, const char* command);
static void console_command_scene_save(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_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_save(struct Console* console, const char* command);
static void console_command_entity_load(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); 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_empty", &console_command_scene_empty);
hashmap_ptr_set(console->commands, "scene_save", &console_command_scene_save); 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_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_save", &console_command_entity_save);
hashmap_ptr_set(console->commands, "entity_load", &console_command_entity_load); hashmap_ptr_set(console->commands, "entity_load", &console_command_entity_load);
hashmap_ptr_set(console->commands, "debug_vars_toggle", &console_command_debug_vars_toggle); 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); 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");
}

@ -204,50 +204,42 @@ void editor_render(struct Editor* editor, struct Camera * active_camera)
if(game_state->editor->selected_entity) if(game_state->editor->selected_entity)
{ {
/* Draw selected entity */ /* Visualize entity specific state */
if(editor->selected_entity->type == ET_STATIC_MESH) 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); case ET_LIGHT:
shader_bind(renderer->debug_shader); {
struct Light* light = (struct Light*)editor->selected_entity;
if(light->type != LT_POINT)
{ {
static mat4 mvp; struct Ray light_ray;
shader_set_uniform_vec4(renderer->debug_shader, "debug_color", &editor->selected_entity_color); vec3_assign(&light_ray.origin, &abs_pos);
struct Static_Mesh* mesh = (struct Static_Mesh*)editor->selected_entity; transform_get_absolute_forward(light, &light_ray.direction);
struct Model* model = &mesh->model; im_ray(&light_ray, 5.f, editor->cursor_entity_color, 3);
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);
} }
shader_unbind();
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
} if(light->type != LT_DIR)
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:
{ {
struct Light* light = (struct Light*)editor->selected_entity; quat rotation = editor->selected_entity->transform.rotation;
if(light->type != LT_POINT) 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; float yaw = quat_get_yaw(&abs_rot);
vec3_assign(&light_ray.origin, &abs_pos); float half_outer_angle = light->outer_angle / 2.f;
transform_get_absolute_forward(light, &light_ray.direction); float half_inner_angle = light->inner_angle / 2.f;
im_ray(&light_ray, 5.f, editor->cursor_entity_color, 3); 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 */ /* Draw bounding box for selected entity */

@ -35,15 +35,13 @@
#include "debug_vars.h" #include "debug_vars.h"
#include "im_render.h" #include "im_render.h"
#include "event.h" #include "event.h"
#include "../common/limits.h"
#define UNUSED(a) (void)a #define UNUSED(a) (void)a
#define MIN_NUM(a,b) ((a) < (b) ? (a) : (b)) #define MIN_NUM(a,b) ((a) < (b) ? (a) : (b))
#define MAX_NUM(a,b) ((a) < (b) ? (b) : (a)) #define MAX_NUM(a,b) ((a) < (b) ? (b) : (a))
#define LEN(a) (sizeof(a)/sizeof(a)[0]) #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_update(float dt, bool* window_should_close);
static void game_post_update(float dt); static void game_post_update(float dt);
static void game_render(void); static void game_render(void);
@ -537,7 +535,19 @@ bool game_run(void)
void game_update(float dt, bool* window_should_close) 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_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("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); if(input_map_state_get("Console_Toggle", KS_RELEASED)) console_toggle(game_state->console);

@ -171,7 +171,6 @@ void player_update(struct Player* player, struct Scene* scene, float dt)
{ {
struct Entity* colliding_entity = ray_result.entities_intersected[i]; struct Entity* colliding_entity = ray_result.entities_intersected[i];
float distance = bv_distance_ray_bounding_box(&forward_ray, &colliding_entity->derived_bounding_box); 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) if(distance > 0.f && distance <= player->min_forward_distance && colliding_entity != player->mesh)
{ {
vec3 intersection_point = forward_ray.direction; 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) if(colliding_entity == player->mesh)
continue; continue;
float distance = bv_distance_ray_bounding_box(&downward_ray, &colliding_entity->derived_bounding_box); 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) if(distance > 0.f && distance <= player->min_downward_distance && !jumping)
{ {
move_speed_vertical = 0.f; 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; translation.y = move_speed_vertical * dt;
transform_translate(player, &translation, TS_WORLD); 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); debug_vars_show_bool("Grounded", player->grounded);
} }

@ -1,6 +1,5 @@
Todo: Todo:
- Enemy ray casting and shooting - Enemy ray casting and shooting
- Scene reload command
- Player shooting - Player shooting
- Player jump cooldown, don't allow jump until a certian time interval has passed, even if we're grounded - Player jump cooldown, don't allow jump until a certian time interval has passed, even if we're grounded
- Sky Cube maps - Sky Cube maps
@ -127,6 +126,7 @@ Bugs:
- Fix quaternion resetting/flipping - Fix quaternion resetting/flipping
- Fix aggressive frustum culling when camera looks up and the object right infront of the viewer gets culled - 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 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: Done:
* Input * Input
@ -405,3 +405,4 @@ Done:
* Apply sound source properties to source instance whenever a new instance is created * 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 * 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. * 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
Loading…
Cancel
Save