Fixed issue with paused sounds playing when game is resumed from pause state

dev
Shariq Shah 6 years ago
parent 5abc152ab8
commit 1aa4d1149d
  1. 9
      src/common/limits.h
  2. 2
      src/common/version.h
  3. 5
      src/game/console.h
  4. 5
      src/game/debug_vars.h
  5. 6
      src/game/entity.c
  6. 1
      src/game/entity.h
  7. 5
      src/game/gui_game.c
  8. 1
      src/game/player.c
  9. 17
      src/game/scene.c

@ -26,4 +26,13 @@
#define MAX_ENEMY_SOUND_SOURCES 2 #define MAX_ENEMY_SOUND_SOURCES 2
#define MAX_ENEMY_MESHES 1 #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 #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 336 #define SYMMETRY_VERSION_REVISION 337
#define SYMMETRY_VERSION_BRANCH "dev" #define SYMMETRY_VERSION_BRANCH "dev"
#endif #endif

@ -2,14 +2,11 @@
#define CONSOLE_H #define CONSOLE_H
#include "../common/hashmap.h" #include "../common/hashmap.h"
#include "../common/limits.h"
#include <stdbool.h> #include <stdbool.h>
#include <stdarg.h> #include <stdarg.h>
#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 Gui;
struct Console; struct Console;

@ -2,10 +2,7 @@
#define DEBUG_VARS_H #define DEBUG_VARS_H
#include "../common/variant.h" #include "../common/variant.h"
#include "../common/limits.h"
#define MAX_DEBUG_VAR_NAME 64
#define MAX_DEBUG_VARS_PER_FRAME_NUMERIC 64
#define MAX_DEBUG_VARS_PER_FRAME_TEXTURES 8
struct Debug_Variable struct Debug_Variable
{ {

@ -386,6 +386,9 @@ 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); sound_source->source_buffer = sound_source_buffer_create(sound, hashmap_str_get(object->data, "source_filename"), sound_source->type);
if(sound_source->source_buffer) if(sound_source->source_buffer)
{
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); sound_source->source_instance = sound_source_instance_create(sound, sound_source->source_buffer, true);
@ -399,9 +402,8 @@ struct Entity* entity_read(struct Parser_Object* object, struct Entity* parent_e
sound_source_instance_volume_set(sound, sound_source->source_instance, sound_source->volume); sound_source_instance_volume_set(sound, sound_source->source_instance, sound_source->volume);
sound_update_3d(sound); sound_update_3d(sound);
bool paused = hashmap_value_exists(object->data, "paused") ? hashmap_bool_get(object->data, "paused") : false;
if(!paused)
sound_source_instance_play(sound, sound_source->source_instance); sound_source_instance_play(sound, sound_source->source_instance);
}
//Stop the default sound source from playing now that we have loaded the actual buffer //Stop the default sound source from playing now that we have loaded the actual buffer
sound_source_instance_destroy(sound, default_source_instance); sound_source_instance_destroy(sound, default_source_instance);

@ -187,6 +187,7 @@ struct Player
struct Static_Mesh* mesh; struct Static_Mesh* mesh;
struct Camera* camera; struct Camera* camera;
struct Sound_Source* weapon_sound; struct Sound_Source* weapon_sound;
int health;
float move_speed; float move_speed;
float move_speed_multiplier; float move_speed_multiplier;
float turn_speed; float turn_speed;

@ -24,10 +24,11 @@ void gui_game_update(struct Gui* gui_game, float dt)
if(game_state->game_mode == GAME_MODE_GAME) 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_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); nk_end(context);
} }
} }

@ -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_downward_distance = hashmap_float_get(config, "player_min_downward_distance");
player->min_forward_distance = hashmap_float_get(config, "player_min_forward_distance"); player->min_forward_distance = hashmap_float_get(config, "player_min_forward_distance");
player->grounded = true; player->grounded = true;
player->health = 100;
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);

@ -209,6 +209,7 @@ bool scene_load(struct Scene* scene, const char* filename, int directory_type)
transform_update_transmat(player); 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, "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++; num_objects_loaded++;
} }
break; 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); struct Parser_Object* player_object = parser_object_new(parser, PO_PLAYER);
entity_write(&scene->player, player_object, true); entity_write(&scene->player, player_object, true);
hashmap_vec4_set(player_object->data, "camera_clear_color", &scene->player.camera->clear_color); 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_DEFAULT, parser);
scene_write_entity_list(scene, ET_LIGHT, 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; 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->loop = loop;
new_sound_source->min_distance = 0.f; new_sound_source->min_distance = 0.f;
new_sound_source->max_distance = 10.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->volume = 1.f;
new_sound_source->type = type; new_sound_source->type = type;
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_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_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_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_source_instance_volume_set(sound, new_sound_source->source_instance, new_sound_source->volume);
sound_update_3d(sound); sound_update_3d(sound);
if(play) sound_source_instance_play(sound, new_sound_source->source_instance); sound_source_instance_play(sound, new_sound_source->source_instance);
}
} }
else else
{ {

Loading…
Cancel
Save