From 1aa4d1149dfc2fcc19a1ae1111ac88c123663d83 Mon Sep 17 00:00:00 2001 From: Shariq Shah Date: Tue, 17 Mar 2020 14:26:06 +1100 Subject: [PATCH] Fixed issue with paused sounds playing when game is resumed from pause state --- src/common/limits.h | 9 +++++++++ src/common/version.h | 2 +- src/game/console.h | 5 +---- src/game/debug_vars.h | 5 +---- src/game/entity.c | 24 +++++++++++++----------- src/game/entity.h | 1 + src/game/gui_game.c | 5 +++-- src/game/player.c | 1 + src/game/scene.c | 29 +++++++++++++++++------------ 9 files changed, 47 insertions(+), 34 deletions(-) diff --git a/src/common/limits.h b/src/common/limits.h index efd34b9..bc242bb 100644 --- a/src/common/limits.h +++ b/src/common/limits.h @@ -26,4 +26,13 @@ #define MAX_ENEMY_SOUND_SOURCES 2 #define MAX_ENEMY_MESHES 1 +#define MAX_CONSOLE_MESSAGE_LEN 256 +#define MAX_CONSOLE_MESSAGES 1024 +#define MAX_CONSOLE_COMMAND_LEN 32 +#define MAX_CONSOLE_HISTORY 64 + +#define MAX_DEBUG_VAR_NAME 64 +#define MAX_DEBUG_VARS_PER_FRAME_NUMERIC 64 +#define MAX_DEBUG_VARS_PER_FRAME_TEXTURES 8 + #endif diff --git a/src/common/version.h b/src/common/version.h index 80661b5..df2fbff 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 336 +#define SYMMETRY_VERSION_REVISION 337 #define SYMMETRY_VERSION_BRANCH "dev" #endif \ No newline at end of file diff --git a/src/game/console.h b/src/game/console.h index f477bcc..bf6810e 100755 --- a/src/game/console.h +++ b/src/game/console.h @@ -2,14 +2,11 @@ #define CONSOLE_H #include "../common/hashmap.h" +#include "../common/limits.h" #include #include -#define MAX_CONSOLE_MESSAGE_LEN 256 -#define MAX_CONSOLE_MESSAGES 1024 -#define MAX_CONSOLE_COMMAND_LEN 32 -#define MAX_CONSOLE_HISTORY 64 struct Gui; struct Console; diff --git a/src/game/debug_vars.h b/src/game/debug_vars.h index cbf14b0..35510c5 100755 --- a/src/game/debug_vars.h +++ b/src/game/debug_vars.h @@ -2,10 +2,7 @@ #define DEBUG_VARS_H #include "../common/variant.h" - -#define MAX_DEBUG_VAR_NAME 64 -#define MAX_DEBUG_VARS_PER_FRAME_NUMERIC 64 -#define MAX_DEBUG_VARS_PER_FRAME_TEXTURES 8 +#include "../common/limits.h" struct Debug_Variable { diff --git a/src/game/entity.c b/src/game/entity.c index 1b435e3..97f384e 100755 --- a/src/game/entity.c +++ b/src/game/entity.c @@ -387,21 +387,23 @@ struct Entity* entity_read(struct Parser_Object* object, struct Entity* parent_e sound_source->source_buffer = sound_source_buffer_create(sound, hashmap_str_get(object->data, "source_filename"), sound_source->type); if(sound_source->source_buffer) { - sound_source->source_instance = sound_source_instance_create(sound, sound_source->source_buffer, true); + bool paused = hashmap_value_exists(object->data, "paused") ? hashmap_bool_get(object->data, "paused") : false; + if(!paused) + { + sound_source->source_instance = sound_source_instance_create(sound, sound_source->source_buffer, true); - vec3 abs_pos = {0.f, 0.f, 0.f}; - transform_get_absolute_position(sound_source, &abs_pos); - sound_source_instance_update_position(sound, sound_source->source_instance, abs_pos); + vec3 abs_pos = { 0.f, 0.f, 0.f }; + transform_get_absolute_position(sound_source, &abs_pos); + sound_source_instance_update_position(sound, sound_source->source_instance, abs_pos); - sound_source_instance_loop_set(sound, sound_source->source_instance, sound_source->loop); - sound_source_instance_min_max_distance_set(sound, sound_source->source_instance, sound_source->min_distance, sound_source->max_distance); - sound_source_instance_attenuation_set(sound, sound_source->source_instance, sound_source->attenuation_type, sound_source->rolloff_factor); - sound_source_instance_volume_set(sound, sound_source->source_instance, sound_source->volume); + sound_source_instance_loop_set(sound, sound_source->source_instance, sound_source->loop); + sound_source_instance_min_max_distance_set(sound, sound_source->source_instance, sound_source->min_distance, sound_source->max_distance); + sound_source_instance_attenuation_set(sound, sound_source->source_instance, sound_source->attenuation_type, sound_source->rolloff_factor); + sound_source_instance_volume_set(sound, sound_source->source_instance, sound_source->volume); - sound_update_3d(sound); - bool paused = hashmap_value_exists(object->data, "paused") ? hashmap_bool_get(object->data, "paused") : false; - if(!paused) + sound_update_3d(sound); sound_source_instance_play(sound, sound_source->source_instance); + } //Stop the default sound source from playing now that we have loaded the actual buffer sound_source_instance_destroy(sound, default_source_instance); diff --git a/src/game/entity.h b/src/game/entity.h index 0c12876..431e668 100755 --- a/src/game/entity.h +++ b/src/game/entity.h @@ -187,6 +187,7 @@ struct Player struct Static_Mesh* mesh; struct Camera* camera; struct Sound_Source* weapon_sound; + int health; float move_speed; float move_speed_multiplier; float turn_speed; diff --git a/src/game/gui_game.c b/src/game/gui_game.c index 855e06d..d3c0203 100644 --- a/src/game/gui_game.c +++ b/src/game/gui_game.c @@ -24,10 +24,11 @@ void gui_game_update(struct Gui* gui_game, float dt) if(game_state->game_mode == GAME_MODE_GAME) { - if(nk_begin(context, "Game Gui", nk_rect(50, 50, 400, 200), NK_WINDOW_CLOSABLE)) + struct Player* player = &game_state->scene->player; + if(nk_begin(context, "Game Gui", nk_rect(50, 50, 200, 100), NK_WINDOW_CLOSABLE)) { nk_layout_row_dynamic(context, 30, 1); - nk_label(context, "Hello from the game gui!", NK_TEXT_ALIGN_CENTERED | NK_TEXT_ALIGN_MIDDLE); + nk_labelf(context, NK_TEXT_ALIGN_CENTERED | NK_TEXT_ALIGN_MIDDLE, "HP: %d", player->health); nk_end(context); } } diff --git a/src/game/player.c b/src/game/player.c index ad70d20..e8b1eef 100755 --- a/src/game/player.c +++ b/src/game/player.c @@ -40,6 +40,7 @@ void player_init(struct Player* player, struct Scene* scene) 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->health = 100; player->mesh = scene_static_mesh_create(scene, "Player_Mesh", player, "sphere.symbres", MAT_BLINN); diff --git a/src/game/scene.c b/src/game/scene.c index 6d69c7b..872c6a3 100755 --- a/src/game/scene.c +++ b/src/game/scene.c @@ -209,6 +209,7 @@ bool scene_load(struct Scene* scene, const char* filename, int directory_type) transform_update_transmat(player); if(hashmap_value_exists(player_data, "camera_clear_color")) player->camera->clear_color = hashmap_vec4_get(player_data, "camera_clear_color"); + if(hashmap_value_exists(player_data, "player_health")) player->health = hashmap_int_get(player_data, "player_health"); num_objects_loaded++; } break; @@ -267,6 +268,7 @@ bool scene_save(struct Scene* scene, const char* filename, int directory_type) struct Parser_Object* player_object = parser_object_new(parser, PO_PLAYER); entity_write(&scene->player, player_object, true); hashmap_vec4_set(player_object->data, "camera_clear_color", &scene->player.camera->clear_color); + hashmap_int_set(player_object->data, "player_health", &scene->player.health); scene_write_entity_list(scene, ET_DEFAULT, parser); scene_write_entity_list(scene, ET_LIGHT, parser); @@ -670,11 +672,6 @@ struct Sound_Source* scene_sound_source_create(struct Scene* scene, const char* return new_sound_source; } - new_sound_source->source_instance = sound_source_instance_create(sound, new_sound_source->source_buffer, true); - vec3 abs_pos = { 0.f, 0.f, 0.f }; - transform_get_absolute_position(entity, &abs_pos); - sound_source_instance_update_position(sound, new_sound_source->source_instance, abs_pos); - new_sound_source->loop = loop; new_sound_source->min_distance = 0.f; new_sound_source->max_distance = 10.f; @@ -683,13 +680,21 @@ struct Sound_Source* scene_sound_source_create(struct Scene* scene, const char* new_sound_source->volume = 1.f; new_sound_source->type = type; - sound_source_instance_loop_set(sound, new_sound_source->source_instance, new_sound_source->loop); - sound_source_instance_min_max_distance_set(sound, new_sound_source->source_instance, new_sound_source->min_distance, new_sound_source->max_distance); - sound_source_instance_attenuation_set(sound, new_sound_source->source_instance, new_sound_source->attenuation_type, new_sound_source->rolloff_factor); - sound_source_instance_volume_set(sound, new_sound_source->source_instance, new_sound_source->volume); - - sound_update_3d(sound); - if(play) sound_source_instance_play(sound, new_sound_source->source_instance); + if(play) + { + new_sound_source->source_instance = sound_source_instance_create(sound, new_sound_source->source_buffer, true); + vec3 abs_pos = { 0.f, 0.f, 0.f }; + transform_get_absolute_position(entity, &abs_pos); + sound_source_instance_update_position(sound, new_sound_source->source_instance, abs_pos); + + sound_source_instance_loop_set(sound, new_sound_source->source_instance, new_sound_source->loop); + sound_source_instance_min_max_distance_set(sound, new_sound_source->source_instance, new_sound_source->min_distance, new_sound_source->max_distance); + sound_source_instance_attenuation_set(sound, new_sound_source->source_instance, new_sound_source->attenuation_type, new_sound_source->rolloff_factor); + sound_source_instance_volume_set(sound, new_sound_source->source_instance, new_sound_source->volume); + + sound_update_3d(sound); + sound_source_instance_play(sound, new_sound_source->source_instance); + } } else {