diff --git a/src/common/version.h b/src/common/version.h index 0c602c5..e317ed1 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 311 +#define SYMMETRY_VERSION_REVISION 312 #define SYMMETRY_VERSION_BRANCH "dev" #endif \ No newline at end of file diff --git a/src/game/entity.h b/src/game/entity.h index 9ebd905..f0c3d8c 100755 --- a/src/game/entity.h +++ b/src/game/entity.h @@ -175,6 +175,10 @@ struct Player float move_speed; float move_speed_multiplier; float turn_speed; + float jump_speed; + float gravity; + float min_downward_distance; + float min_forward_distance; bool grounded; }; diff --git a/src/game/player.c b/src/game/player.c index 668b7f1..a7dae85 100755 --- a/src/game/player.c +++ b/src/game/player.c @@ -26,9 +26,13 @@ void player_init(struct Player* player, struct Scene* scene) player->base.type = ET_PLAYER; struct Hashmap* config = game_state->cvars; - player->move_speed = hashmap_int_get(config, "player_move_speed"); - player->move_speed_multiplier = hashmap_int_get(config, "player_move_speed_multiplier"); - player->turn_speed = hashmap_int_get(config, "player_turn_speed"); + player->move_speed = hashmap_float_get(config, "player_move_speed"); + player->move_speed_multiplier = hashmap_float_get(config, "player_move_speed_multiplier"); + 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->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->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); vec3 cam_translation = {0.f, 1.5f, 0.f}; 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_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); /* Movement */ - float gravity = -0.25f; - float jump_velocity = 50.f; float move_speed = player->move_speed; 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 float move_speed_vertical = 0.f; @@ -139,8 +129,7 @@ void player_update(struct Player* player, struct Scene* scene, float dt) { if(player->grounded) { - //velocity.y += jump_velocity; - move_speed_vertical += jump_velocity; + move_speed_vertical += player->jump_speed; jumping = true; 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) 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; platform_mouse_position_get(&mouse_x, &mouse_y); 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 // or equal to min_collision_distance then we are colliding - float min_collision_distance = 5.0f; struct Raycast_Result ray_result; scene_ray_intersect(scene, &forward_ray, &ray_result, ERM_STATIC_MESH); 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]; 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 <= 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_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); 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)); vec3 norm_scaled = { 0.f }; @@ -193,16 +181,15 @@ void player_update(struct Player* player, struct Scene* scene, float dt) } } - /* Check for collisions below */ - move_speed_vertical += gravity; + // Check for collisions below + move_speed_vertical += player->gravity; + struct Raycast_Result down_ray_result; struct Ray downward_ray; transform_get_absolute_position(player->mesh, &downward_ray.origin); 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); 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++) { 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; 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 <= min_downward_distance && !jumping) + if(distance > 0.f && distance <= player->min_downward_distance && !jumping) { - //velocity.y = 0.f; move_speed_vertical = 0.f; 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 - offset.x *= move_speed * dt; - offset.z *= move_speed * dt; - offset.y = move_speed_vertical * dt; - debug_vars_show_vec3("Translation", &offset); + vec3 translation = {0.f, 0.f, 0.f}; + vec3_assign(&translation, &move_direction); - 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*/ if(input_mousebutton_state_get(MSB_RIGHT, KS_PRESSED)) diff --git a/src/system/config_vars.c b/src/system/config_vars.c index 2a601dd..d9c97a1 100755 --- a/src/system/config_vars.c +++ b/src/system/config_vars.c @@ -13,25 +13,29 @@ void config_vars_init(struct Hashmap* cvars) { /* Initialize with default values incase there is no config file */ - hashmap_int_set(cvars, "render_width", 1280); - hashmap_int_set(cvars, "render_height", 720); - hashmap_bool_set(cvars, "vsync_enabled", true); - hashmap_int_set(cvars, "fog_mode", 1); - 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_start_dist", 10.f); - hashmap_float_set(cvars, "fog_max_dist", 450.f); - hashmap_vec3_setf(cvars, "ambient_light", 0.1f, 0.1f, 0.1f); - hashmap_bool_set(cvars, "msaa_enabled", true); - hashmap_int_set(cvars, "msaa_levels", 4); - hashmap_bool_set(cvars, "debug_draw_enabled", false); - hashmap_bool_set(cvars, "debug_draw_physics", false); - hashmap_int_set(cvars, "video_driver_linux", VD_WAYLAND); - hashmap_int_set(cvars, "debug_draw_mode", 0); - 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_multiplier", 2.f); - hashmap_float_set(cvars, "player_turn_speed", 45.f); + hashmap_int_set(cvars, "render_width", 1280); + hashmap_int_set(cvars, "render_height", 720); + hashmap_bool_set(cvars, "vsync_enabled", true); + hashmap_int_set(cvars, "fog_mode", 1); + 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_start_dist", 10.f); + hashmap_float_set(cvars, "fog_max_dist", 450.f); + hashmap_vec3_setf(cvars, "ambient_light", 0.1f, 0.1f, 0.1f); + hashmap_bool_set(cvars, "msaa_enabled", true); + hashmap_int_set(cvars, "msaa_levels", 4); + hashmap_bool_set(cvars, "debug_draw_enabled", false); + hashmap_bool_set(cvars, "debug_draw_physics", false); + hashmap_int_set(cvars, "video_driver_linux", VD_WAYLAND); + hashmap_int_set(cvars, "debug_draw_mode", 0); + 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_multiplier", 1.75f); + 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) diff --git a/todo.txt b/todo.txt index bb24a39..16f0750 100644 --- a/todo.txt +++ b/todo.txt @@ -1,8 +1,7 @@ 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 - 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? ? 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 @@ -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 * 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 - * Improve player collision by impelenting sliding along collision plane in case of collision \ No newline at end of file + * 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 \ No newline at end of file