Sound source properties are now applied to each newly created instance

dev
Shariq Shah 6 years ago
parent c3305a9522
commit ddfbbbfa2d
  1. 2
      src/common/version.h
  2. 31
      src/game/enemy.c
  3. 2
      src/game/enemy.h
  4. 2
      src/game/entity.h
  5. 2
      src/game/scene.c
  6. 45
      src/game/sound_source.c
  7. 3
      src/game/sound_source.h
  8. 4
      src/system/sound.c
  9. 2
      src/system/sound.h
  10. 2
      todo.txt

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

@ -53,8 +53,28 @@ void enemy_init(struct Enemy* enemy, int type)
if(!mesh)
log_error("enemy:init", "Failed to add mesh from file for %s", enemy->base.name);
enemy->mesh->base.flags |= EF_TRANSIENT;
enemy->weapon_sound->base.flags |= EF_TRANSIENT;
if(enemy->mesh) enemy->mesh->base.flags |= EF_TRANSIENT;
if(enemy->weapon_sound) enemy->weapon_sound->base.flags |= EF_TRANSIENT;
}
void enemy_weapon_sound_set(struct Enemy* enemy, const char* sound_filename, int type)
{
sound_source_buffer_set(game_state_get()->sound, sound_filename, type);
}
void enemy_static_mesh_set(struct Enemy* enemy, const char* geometry_filename, int material_type)
{
struct Scene* scene = game_state_get()->scene;
char mesh_name[MAX_ENTITY_NAME_LEN];
memset(mesh_name, '\0', sizeof(char) * MAX_ENTITY_NAME_LEN);
snprintf(mesh_name, MAX_ENTITY_NAME_LEN, "%s_Mesh", enemy->base.name);
struct Static_Mesh* new_mesh = scene_static_mesh_create(scene, mesh_name, enemy, geometry_filename, material_type);
if(new_mesh)
{
if(enemy->mesh) scene_static_mesh_remove(scene, enemy->mesh);
enemy->mesh = new_mesh;
}
}
void enemy_update(struct Enemy* enemy, struct Scene* scene, float dt)
@ -75,8 +95,9 @@ void enemy_update(struct Enemy* enemy, struct Scene* scene, float dt)
void enemy_reset(struct Enemy* enemy)
{
entity_reset(enemy, enemy->base.id);
enemy->base.flags = EF_NONE;
enemy->type = -1;
enemy->damage = 0;
enemy->health = 0;
}
struct Enemy* enemy_read(struct Parser_Object* object, const char* name, struct Entity* parent_entity)
@ -89,7 +110,7 @@ struct Enemy* enemy_read(struct Parser_Object* object, const char* name, struct
if(enemy_type != -1)
{
new_enemy = scene_enemy_create(scene, name, parent_entity, enemy_type);
new_enemy = scene_enemy_create(scene, name, parent_entity, enemy_type); // Create enemy with default values then read and update from file if necessary
if(!new_enemy)
return new_enemy;
if(hashmap_value_exists(object->data, "health")) new_enemy->health = hashmap_int_get(object->data, "health");

@ -12,5 +12,7 @@ void enemy_update(struct Enemy* enemy, struct Scene* scene, float dt);
void enemy_reset(struct Enemy* enemy);
struct Enemy* enemy_read(struct Parser_Object* object, const char* name, struct Entity* parent_entity);
void enemy_write(struct Enemy* enemy, struct Hashmap* entity_data);
void enemy_weapon_sound_set(struct Enemy* enemy, const char* sound_filename, int type);
void enemy_static_mesh_set(struct Enemy* enemy, const char* geometry_filename, int material_type);
#endif

@ -59,7 +59,7 @@ enum Entity_Flags
EF_ACTIVE = 1 << 0,
EF_SELECTED_IN_EDITOR = 1 << 1,
EF_MARKED_FOR_DELETION = 1 << 2,
EF_TRANSIENT = 1 << 3,
EF_TRANSIENT = 1 << 3, // Do not save the entity when saving the scene. The entity will still be saved if it is individually saved to file
EF_HIDE_IN_EDITOR_SCENE_HIERARCHY = 1 << 4,
EF_SKIP_RENDER = 1 << 5,
EF_IGNORE_RAYCAST = 1 << 6

@ -413,7 +413,7 @@ void scene_post_update(struct Scene* scene)
if(sound_source->base.transform.is_modified)
{
sound_source_update(sound, sound_source);
sound_source_update_position(sound, sound_source);
sound_source->base.transform.is_modified = false;
}
}

@ -4,17 +4,30 @@
#include "transform.h"
#include "../common/log.h"
static void sound_source_validate_instance(struct Sound* sound, struct Sound_Source* entity)
static void sound_source_validate_instance(struct Sound* sound, struct Sound_Source* entity);
static void sound_source_apply_params_to_instance(struct Sound* sound, struct Sound_Source* entity);
void sound_source_validate_instance(struct Sound* sound, struct Sound_Source* entity)
{
if(!sound_source_instance_is_valid(sound, entity->source_instance))
{
entity->source_instance = sound_source_instance_create(sound, entity->source_buffer, true);
vec3 abs_position = { 0.f };
transform_get_absolute_position(entity, &abs_position);
sound_source_instance_update_position(sound, entity->source_instance, abs_position);
sound_source_apply_params_to_instance(sound, entity);
}
}
void sound_source_apply_params_to_instance(struct Sound* sound, struct Sound_Source* entity)
{
// This function assumes that the handle to the sound source is valid
vec3 abs_position = { 0.f };
transform_get_absolute_position(entity, &abs_position);
sound_source_instance_update_position(sound, entity->source_instance, abs_position);
sound_source_instance_loop_set(sound, entity->source_instance, entity->loop);
sound_source_instance_min_max_distance_set(sound, entity->source_instance, entity->min_distance, entity->max_distance);
sound_source_instance_attenuation_set(sound, entity->source_instance, entity->attenuation_type, entity->rolloff_factor);
sound_source_instance_volume_set(sound, entity->source_instance, entity->volume);
}
void sound_source_play(struct Sound* sound, struct Sound_Source* entity)
{
sound_source_validate_instance(sound, entity);
@ -34,7 +47,7 @@ void sound_source_stop(struct Sound* sound, struct Sound_Source* entity)
sound_source_instance_stop(sound, entity->source_instance);
}
void sound_source_update(struct Sound* sound, struct Sound_Source* entity)
void sound_source_update_position(struct Sound* sound, struct Sound_Source* entity)
{
if(sound_source_instance_is_valid(sound, entity->source_instance))
{
@ -43,3 +56,25 @@ void sound_source_update(struct Sound* sound, struct Sound_Source* entity)
sound_source_instance_update_position(sound, entity->source_instance, abs_position);
}
}
void sound_source_buffer_set(struct Sound* sound, struct Sound_Source* entity, const char* filename, int type)
{
if(entity->source_buffer)
{
struct Sound_Source_Buffer* new_buffer = sound_source_buffer_create(sound, filename, type);
if(new_buffer)
{
sound_source_instance_destroy(sound, entity->source_instance);
sound_source_buffer_destroy(sound, entity->source_buffer);
entity->source_buffer = new_buffer;
entity->type = type;
entity->source_instance = sound_source_instance_create(sound, entity->source_buffer, true);
sound_source_apply_params_to_instance(sound, entity);
}
else
{
log_error("sound_source:buffer_set", "Failed to set buffer for %s", entity->base.name);
}
}
}

@ -7,6 +7,7 @@ struct Sound;
void sound_source_play(struct Sound* sound, struct Sound_Source* entity);
void sound_source_pause(struct Sound* sound, struct Sound_Source* entity);
void sound_source_stop(struct Sound* sound, struct Sound_Source* entity);
void sound_source_update(struct Sound* sound, struct Sound_Source* entity);
void sound_source_update_position(struct Sound* sound, struct Sound_Source* entity);
void sound_source_buffer_set(struct Sound* sound, struct Sound_Source* entity);
#endif

@ -195,7 +195,7 @@ struct Sound_Source_Buffer* sound_source_buffer_create(struct Sound* sound, cons
if(!filename)
return NULL;
struct Sound_Source_Buffer* source = sound_source_buffer(sound, filename);
struct Sound_Source_Buffer* source = sound_source_buffer_get(sound, filename);
// See if we've already loaded this file otherwise, get the next empty slot.
// If we can't find an empty slot, print error and return NULL
@ -269,7 +269,7 @@ struct Sound_Source_Buffer* sound_source_buffer_create(struct Sound* sound, cons
return source;
}
struct Sound_Source_Buffer* sound_source_buffer(struct Sound* sound, const char* name)
struct Sound_Source_Buffer* sound_source_buffer_get(struct Sound* sound, const char* name)
{
struct Sound_Source_Buffer* source = NULL;
for(int i = 0; i < MAX_SOUND_BUFFERS; i++)

@ -70,7 +70,7 @@ bool sound_source_instance_loop_get(struct Sound* sound, uint source_instance);
bool sound_source_instance_is_paused(struct Sound* sound, uint source_instance);
struct Sound_Source_Buffer* sound_source_buffer_create(struct Sound* sound, const char* filename, int type);
struct Sound_Source_Buffer* sound_source_buffer(struct Sound* sound, const char* name);
struct Sound_Source_Buffer* sound_source_buffer_get(struct Sound* sound, const char* name);
int sound_source_buffer_play_3d(struct Sound* sound, struct Sound_Source_Buffer* source, vec3 position);
int sound_source_buffer_play_clocked_3d(struct Sound* sound, struct Sound_Source_Buffer* source, float delay, vec3 position);
void sound_source_buffer_destroy(struct Sound* sound, struct Sound_Source_Buffer* source);

@ -1,6 +1,5 @@
Todo:
- Imlement reading/writing enemy mesh and weapon sound to file and resetting it in code
- Apply sound source properties to source instance whenever a new instance is created
- Enemy ray casting and shooting
- Player shooting
- Player jump cooldown, don't allow jump until a certian time interval has passed, even if we're grounded
@ -402,3 +401,4 @@ Done:
* Move player movement related variables from function to player struct and load them from config file
* Screen mouse coordinates to world-coordinates for aiming
* Sound source entity functions that automatically track if handles are valid and create/update as necessary
* Apply sound source properties to source instance whenever a new instance is created
Loading…
Cancel
Save