Brought back sprinting and moved player movement related variables to config file

dev
Shariq Shah 6 years ago
parent e6a748c458
commit 708a9f9853
  1. 2
      src/common/version.h
  2. 4
      src/game/entity.h
  3. 69
      src/game/player.c
  4. 42
      src/system/config_vars.c
  5. 7
      todo.txt

@ -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 311 #define SYMMETRY_VERSION_REVISION 312
#define SYMMETRY_VERSION_BRANCH "dev" #define SYMMETRY_VERSION_BRANCH "dev"
#endif #endif

@ -175,6 +175,10 @@ struct Player
float move_speed; float move_speed;
float move_speed_multiplier; float move_speed_multiplier;
float turn_speed; float turn_speed;
float jump_speed;
float gravity;
float min_downward_distance;
float min_forward_distance;
bool grounded; bool grounded;
}; };

@ -26,9 +26,13 @@ void player_init(struct Player* player, struct Scene* scene)
player->base.type = ET_PLAYER; player->base.type = ET_PLAYER;
struct Hashmap* config = game_state->cvars; struct Hashmap* config = game_state->cvars;
player->move_speed = hashmap_int_get(config, "player_move_speed"); player->move_speed = hashmap_float_get(config, "player_move_speed");
player->move_speed_multiplier = hashmap_int_get(config, "player_move_speed_multiplier"); player->move_speed_multiplier = hashmap_float_get(config, "player_move_speed_multiplier");
player->turn_speed = hashmap_int_get(config, "player_turn_speed"); player->turn_speed = hashmap_float_get(config, "player_turn_speed");
player->jump_speed = hashmap_float_get(config, "player_jump_speed");
player->gravity = hashmap_float_get(config, "player_gravity");
player->min_downward_distance = hashmap_float_get(config, "player_min_downward_distance");
player->min_forward_distance = hashmap_float_get(config, "player_min_forward_distance");
player->grounded = true; player->grounded = true;
player->mesh = scene_static_mesh_create(scene, "Player_Mesh", player, "sphere.symbres", MAT_BLINN); player->mesh = scene_static_mesh_create(scene, "Player_Mesh", player, "sphere.symbres", MAT_BLINN);
@ -46,22 +50,11 @@ void player_init(struct Player* player, struct Scene* scene)
player->camera_node->base.flags |= EF_TRANSIENT; player->camera_node->base.flags |= EF_TRANSIENT;
player->mesh->base.flags |= EF_TRANSIENT; player->mesh->base.flags |= EF_TRANSIENT;
//if(player_camera->fbo == -1)
//{
// int render_width = hashmap_int_get(config, "render_width");
// int render_height = hashmap_int_get(config, "render_height");
// window_get_drawable_size(game_state->window, &render_width, &render_height);
// camera_attach_fbo(player_camera, render_width, render_height, true, true, true);
//}
transform_parent_set(player_camera, player, true); transform_parent_set(player_camera, player, true);
vec3 cam_translation = {0.f, 1.5f, 0.f}; vec3 cam_translation = {0.f, 1.5f, 0.f};
transform_translate(player_camera, &cam_translation, TS_LOCAL); transform_translate(player_camera, &cam_translation, TS_LOCAL);
//vec3 cam_axis = {-1.f, 0.f, 0.f};
//transform_rotate(player_camera, &cam_axis, 85.f, TS_LOCAL);
sound_listener_set(game_state->sound, player_camera); sound_listener_set(game_state->sound, player_camera);
sound_listener_update(game_state->sound); sound_listener_update(game_state->sound);
} }
@ -118,11 +111,8 @@ void player_update(struct Player* player, struct Scene* scene, float dt)
transform_rotate(player->camera_node, &rot_axis_pitch, pitch, TS_LOCAL); transform_rotate(player->camera_node, &rot_axis_pitch, pitch, TS_LOCAL);
/* Movement */ /* Movement */
float gravity = -0.25f;
float jump_velocity = 50.f;
float move_speed = player->move_speed; float move_speed = player->move_speed;
vec3 move_direction = { 0.f }; vec3 move_direction = { 0.f };
vec3 max_velocity = { player->move_speed * player->move_speed_multiplier, jump_velocity, player->move_speed * player->move_speed_multiplier };
static bool jumping = false; static bool jumping = false;
static float move_speed_vertical = 0.f; static float move_speed_vertical = 0.f;
@ -139,8 +129,7 @@ void player_update(struct Player* player, struct Scene* scene, float dt)
{ {
if(player->grounded) if(player->grounded)
{ {
//velocity.y += jump_velocity; move_speed_vertical += player->jump_speed;
move_speed_vertical += jump_velocity;
jumping = true; jumping = true;
player->grounded = false; player->grounded = false;
} }
@ -150,7 +139,7 @@ void player_update(struct Player* player, struct Scene* scene, float dt)
if(move_direction.x != 0 || move_direction.z != 0) if(move_direction.x != 0 || move_direction.z != 0)
quat_mul_vec3(&move_direction, &player->base.transform.rotation, &move_direction); quat_mul_vec3(&move_direction, &player->base.transform.rotation, &move_direction);
/* Check for collisions ahead */ // Check for collisions in the directions we want to move
int mouse_x = 0, mouse_y = 0; int mouse_x = 0, mouse_y = 0;
platform_mouse_position_get(&mouse_x, &mouse_y); platform_mouse_position_get(&mouse_x, &mouse_y);
struct Ray forward_ray = { 0 }; struct Ray forward_ray = { 0 };
@ -159,7 +148,6 @@ void player_update(struct Player* player, struct Scene* scene, float dt)
// Get all the entities that intersect then check the distance if it is less than // Get all the entities that intersect then check the distance if it is less than
// or equal to min_collision_distance then we are colliding // or equal to min_collision_distance then we are colliding
float min_collision_distance = 5.0f;
struct Raycast_Result ray_result; struct Raycast_Result ray_result;
scene_ray_intersect(scene, &forward_ray, &ray_result, ERM_STATIC_MESH); scene_ray_intersect(scene, &forward_ray, &ray_result, ERM_STATIC_MESH);
debug_vars_show_int("Colliding Entities", ray_result.num_entities_intersected); debug_vars_show_int("Colliding Entities", ray_result.num_entities_intersected);
@ -170,7 +158,7 @@ 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); debug_vars_show_float("Collision ahead", distance);
if(distance > 0.f && distance <= min_collision_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;
vec3_scale(&intersection_point, &intersection_point, distance); vec3_scale(&intersection_point, &intersection_point, distance);
@ -180,7 +168,7 @@ void player_update(struct Player* player, struct Scene* scene, float dt)
vec3 normal = bv_bounding_box_normal_from_intersection_point(box, intersection_point); vec3 normal = bv_bounding_box_normal_from_intersection_point(box, intersection_point);
im_ray_origin_dir(intersection_point, normal, 5.f, (vec4) { 1.f, 0.f, 0.f, 1.f }, 3); im_ray_origin_dir(intersection_point, normal, 5.f, (vec4) { 1.f, 0.f, 0.f, 1.f }, 3);
im_ray(&forward_ray, min_collision_distance, (vec4) { 0.f, 1.f, 0.f, 1.f }, 3); im_ray(&forward_ray, player->min_forward_distance, (vec4) { 0.f, 1.f, 0.f, 1.f }, 3);
float dot = (vec3_dot(&move_direction, &normal)); float dot = (vec3_dot(&move_direction, &normal));
vec3 norm_scaled = { 0.f }; vec3 norm_scaled = { 0.f };
@ -193,16 +181,15 @@ void player_update(struct Player* player, struct Scene* scene, float dt)
} }
} }
/* Check for collisions below */ // Check for collisions below
move_speed_vertical += gravity; move_speed_vertical += player->gravity;
struct Raycast_Result down_ray_result;
struct Ray downward_ray; struct Ray downward_ray;
transform_get_absolute_position(player->mesh, &downward_ray.origin); transform_get_absolute_position(player->mesh, &downward_ray.origin);
vec3_fill(&downward_ray.direction, 0.f, -1.f, 0.f); vec3_fill(&downward_ray.direction, 0.f, -1.f, 0.f);
struct Raycast_Result down_ray_result;
scene_ray_intersect(scene, &downward_ray, &down_ray_result, ERM_STATIC_MESH); scene_ray_intersect(scene, &downward_ray, &down_ray_result, ERM_STATIC_MESH);
if(down_ray_result.num_entities_intersected > 0) if(down_ray_result.num_entities_intersected > 0)
{ {
float min_downward_distance = 2.f;
for(int i = 0; i < down_ray_result.num_entities_intersected; i++) for(int i = 0; i < down_ray_result.num_entities_intersected; i++)
{ {
struct Entity* colliding_entity = down_ray_result.entities_intersected[i]; struct Entity* colliding_entity = down_ray_result.entities_intersected[i];
@ -210,32 +197,26 @@ void player_update(struct Player* player, struct Scene* scene, float dt)
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); debug_vars_show_float("Collision below", distance);
if(distance > 0.f && distance <= min_downward_distance && !jumping) if(distance > 0.f && distance <= player->min_downward_distance && !jumping)
{ {
//velocity.y = 0.f;
move_speed_vertical = 0.f; move_speed_vertical = 0.f;
player->grounded = true; player->grounded = true;
} }
} }
} }
debug_vars_show_bool("Grounded", player->grounded);
vec3 offset = {0.f, 0.f, 0.f};
vec3_assign(&offset, &move_direction);
//if(offset.x != 0 || offset.z != 0)
//{
// quat_mul_vec3(&offset, &player->camera_node->base.transform.rotation, &offset);
// offset.y = 0.f;
//}
// Apply speed to direction then translate // Apply speed to direction then translate
offset.x *= move_speed * dt; vec3 translation = {0.f, 0.f, 0.f};
offset.z *= move_speed * dt; vec3_assign(&translation, &move_direction);
offset.y = move_speed_vertical * dt;
debug_vars_show_vec3("Translation", &offset);
transform_translate(player, &offset, TS_WORLD); translation.x *= move_speed * dt;
translation.z *= move_speed * 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);
/* Aiming and Projectiles*/ /* Aiming and Projectiles*/
if(input_mousebutton_state_get(MSB_RIGHT, KS_PRESSED)) if(input_mousebutton_state_get(MSB_RIGHT, KS_PRESSED))

@ -13,25 +13,29 @@
void config_vars_init(struct Hashmap* cvars) void config_vars_init(struct Hashmap* cvars)
{ {
/* Initialize with default values incase there is no config file */ /* Initialize with default values incase there is no config file */
hashmap_int_set(cvars, "render_width", 1280); hashmap_int_set(cvars, "render_width", 1280);
hashmap_int_set(cvars, "render_height", 720); hashmap_int_set(cvars, "render_height", 720);
hashmap_bool_set(cvars, "vsync_enabled", true); hashmap_bool_set(cvars, "vsync_enabled", true);
hashmap_int_set(cvars, "fog_mode", 1); hashmap_int_set(cvars, "fog_mode", 1);
hashmap_vec3_setf(cvars, "fog_color", 0.17f, 0.49f, 0.63f); hashmap_vec3_setf(cvars, "fog_color", 0.17f, 0.49f, 0.63f);
hashmap_float_set(cvars, "fog_density", 0.1f); hashmap_float_set(cvars, "fog_density", 0.1f);
hashmap_float_set(cvars, "fog_start_dist", 10.f); hashmap_float_set(cvars, "fog_start_dist", 10.f);
hashmap_float_set(cvars, "fog_max_dist", 450.f); hashmap_float_set(cvars, "fog_max_dist", 450.f);
hashmap_vec3_setf(cvars, "ambient_light", 0.1f, 0.1f, 0.1f); hashmap_vec3_setf(cvars, "ambient_light", 0.1f, 0.1f, 0.1f);
hashmap_bool_set(cvars, "msaa_enabled", true); hashmap_bool_set(cvars, "msaa_enabled", true);
hashmap_int_set(cvars, "msaa_levels", 4); hashmap_int_set(cvars, "msaa_levels", 4);
hashmap_bool_set(cvars, "debug_draw_enabled", false); hashmap_bool_set(cvars, "debug_draw_enabled", false);
hashmap_bool_set(cvars, "debug_draw_physics", false); hashmap_bool_set(cvars, "debug_draw_physics", false);
hashmap_int_set(cvars, "video_driver_linux", VD_WAYLAND); hashmap_int_set(cvars, "video_driver_linux", VD_WAYLAND);
hashmap_int_set(cvars, "debug_draw_mode", 0); hashmap_int_set(cvars, "debug_draw_mode", 0);
hashmap_vec4_setf(cvars, "debug_draw_color", 0.8f, 0.4f, 0.1f, 1.f); hashmap_vec4_setf(cvars, "debug_draw_color", 0.8f, 0.4f, 0.1f, 1.f);
hashmap_float_set(cvars, "player_move_speed", 20.f); hashmap_float_set(cvars, "player_move_speed", 20.f);
hashmap_float_set(cvars, "player_move_speed_multiplier", 2.f); hashmap_float_set(cvars, "player_move_speed_multiplier", 1.75f);
hashmap_float_set(cvars, "player_turn_speed", 45.f); hashmap_float_set(cvars, "player_turn_speed", 45.f);
hashmap_float_set(cvars, "player_jump_speed", 50.f);
hashmap_float_set(cvars, "player_gravity", -0.25f);
hashmap_float_set(cvars, "player_min_forward_distance", 5.f);
hashmap_float_set(cvars, "player_min_downward_distance", 2.f);
} }
void config_vars_cleanup(struct Hashmap* cvars) void config_vars_cleanup(struct Hashmap* cvars)

@ -1,8 +1,7 @@
Todo: Todo:
- Bring back sprinting - 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
- Check if running in a lower frame rate affects movement - Check if running in a lower frame rate affects movement
- Move player movement related variables from function to player struct and load them from config file
? Write entity flags to scene file or when saving entity to file? ? Write entity flags to scene file or when saving entity to file?
? Add scene init/de-init function hashmap that maps a function that should be called when scene is loaded and unloaded. Save this to file for every scene or map functions based on the name of the scene? ? Add scene init/de-init function hashmap that maps a function that should be called when scene is loaded and unloaded. Save this to file for every scene or map functions based on the name of the scene?
- Command to create a placeholder entity of a particular type in a file - Command to create a placeholder entity of a particular type in a file
@ -400,4 +399,6 @@ Done:
* We no longer keep geoemtry data loaded from files as it is not needed after data is passed on to opengl * We no longer keep geoemtry data loaded from files as it is not needed after data is passed on to opengl
* Shift-A to add entity to scene * Shift-A to add entity to scene
* Fixed crash where if an entity is hoverd in editor and deleted, the game crashes because the hovered variable in editor doesn't know that the entity was deleted * Fixed crash where if an entity is hoverd in editor and deleted, the game crashes because the hovered variable in editor doesn't know that the entity was deleted
* Improve player collision by impelenting sliding along collision plane in case of collision * Improve player collision by impelenting sliding along collision plane in case of collision
* Brought back sprinting by fixing a bug where player movement related variables were written to file as floats but read back as ints
* Move player movement related variables from function to player struct and load them from config file
Loading…
Cancel
Save