Fixed several sound related bugs and added missing functionality

dev
Shariq Shah 6 years ago
parent c443e4d9ee
commit adcdab7aad
  1. BIN
      assets/sounds/algebra_loop.ogg
  2. BIN
      assets/sounds/windy_ambience.ogg
  3. 4
      build/genie.lua
  4. BIN
      lib/windows/soloud/soloud_x64.dll
  5. BIN
      lib/windows/soloud/soloud_x64.exp
  6. BIN
      lib/windows/soloud/soloud_x64.lib
  7. BIN
      lib/windows/soloud/soloud_x64_d.dll
  8. BIN
      lib/windows/soloud/soloud_x64_d.exp
  9. BIN
      lib/windows/soloud/soloud_x64_d.ilk
  10. BIN
      lib/windows/soloud/soloud_x64_d.lib
  11. BIN
      lib/windows/soloud/soloud_x64_d.pdb
  12. 58
      src/game/editor.c
  13. 7
      src/game/game.c
  14. 3
      src/game/player.c
  15. 21
      src/game/scene.c
  16. 1
      src/game/transform.c
  17. 15
      src/system/sound.c
  18. 2
      src/system/sound.h
  19. 2
      todo.txt

Binary file not shown.

Binary file not shown.

@ -102,14 +102,14 @@ solution "Symmetry"
configuration {"windows", "Debug", "vs2017"}
postbuildcommands
{
"copy ..\\..\\lib\\windows\\sdl2\\SDL2d.dll debug\\ /Y",
"copy ..\\..\\lib\\windows\\sdl2\\SDL2.dll debug\\ /Y",
"copy ..\\..\\lib\\windows\\soloud\\soloud_x64_d.dll debug\\ /Y",
"copy ..\\..\\lib\\windows\\ode\\ode_doubled.dll debug\\ /Y",
"copy ..\\..\\lib\\windows\\ode\\ode_doubled.pdb debug\\ /Y",
"rmdir debug\\assets",
"mklink /D debug\\assets ..\\..\\..\\assets"
}
links {"ode_doubled", "SDL2d"}
links {"ode_doubled", "SDL2"}
newaction {
trigger = "build_addon",

Binary file not shown.

Binary file not shown.

Binary file not shown.

@ -1539,6 +1539,7 @@ void editor_window_scene_heirarchy(struct nk_context* context, struct Editor* ed
for(int i = 0; i < MAX_CAMERAS; i++) editor_show_entity_in_list(editor, context, scene, &scene->cameras[i]);
for(int i = 0; i < MAX_LIGHTS; i++) editor_show_entity_in_list(editor, context, scene, &scene->lights[i]);
for(int i = 0; i < MAX_STATIC_MESHES; i++) editor_show_entity_in_list(editor, context, scene, &scene->static_meshes[i]);
for(int i = 0; i < MAX_SOUND_SOURCES; i++) editor_show_entity_in_list(editor, context, scene, &scene->sound_sources[i]);
nk_group_end(context);
}
@ -1752,6 +1753,63 @@ void editor_window_property_inspector(struct nk_context* context, struct Editor*
nk_tree_pop(context);
}
}
/* Sound Source */
if(entity->type == ET_SOUND_SOURCE)
{
struct Sound* sound = game_state->sound;
struct Sound_Source* sound_source = (struct Sound_Source*)entity;
if(nk_tree_push(context, NK_TREE_TAB, "Sound Source", NK_MAXIMIZED))
{
nk_layout_row_dynamic(context, row_height, 2);
nk_label(context, "Playing", NK_TEXT_ALIGN_LEFT | NK_TEXT_ALIGN_MIDDLE);
int is_playing = sound_source_instance_is_paused(sound, sound_source->source_instance);
int playing = nk_check_label(context, "", is_playing);
if(is_playing && !playing)
sound_source_instance_pause(sound, sound_source->source_instance);
else if(!is_playing && playing)
sound_source_instance_play(sound, sound_source->source_instance);
nk_label(context, "Loop", NK_TEXT_ALIGN_LEFT | NK_TEXT_ALIGN_MIDDLE);
int is_looping = sound_source_instance_loop_get(sound, sound_source->source_instance);
int looping = nk_check_label(context, "", is_looping);
if(is_looping != looping)
sound_source_instance_loop_set(sound, sound_source->source_instance, looping);
nk_layout_row_dynamic(context, row_height, 1);
float volume = sound_source_instance_volume_get(sound, sound_source->source_instance);
volume = nk_propertyf(context, "Volume", 0.f, volume, 10.f, 0.5f, 0.1f);
sound_source_instance_volume_set(sound, sound_source->source_instance, volume);
nk_layout_row_dynamic(context, 30, 2);
static char filename_buffer[MAX_FILENAME_LEN];
strncpy(filename_buffer, sound_source->source_buffer->filename, MAX_FILENAME_LEN);
nk_label(context, "File", NK_TEXT_ALIGN_LEFT | NK_TEXT_ALIGN_MIDDLE);
int edit_flags = NK_EDIT_GOTO_END_ON_ACTIVATE | NK_EDIT_FIELD | NK_EDIT_SIG_ENTER;
int edit_state = nk_edit_string_zero_terminated(context, edit_flags, filename_buffer, MAX_FILENAME_LEN, NULL);
if(edit_state & NK_EDIT_COMMITED)
{
if(strncmp(filename_buffer, sound_source->source_buffer->filename, MAX_FILENAME_LEN) != 0)
{
struct Sound_Source_Buffer* new_source_buffer = sound_source_create(sound, filename_buffer, ST_WAV_STREAM);
if(new_source_buffer)
{
sound_source_stop_all(sound, sound_source->source_buffer);
sound_source_instance_destroy(sound, sound_source->source_instance);
sound_source->source_instance = sound_source_instance_create(sound, new_source_buffer, true);
sound_source->source_buffer = new_source_buffer;
sound_source->base.transform.is_modified = true; // Fake a transformation so that post-update the new sound source position is updated
if(playing)
sound_source_instance_play(sound, sound_source->source_instance);
}
}
}
nk_tree_pop(context);
}
}
}
else
{

@ -310,6 +310,10 @@ void game_scene_setup(void)
}
//struct Sound_Source* sound_source = scene_sound_source_create(game_state->scene, "Beats", NULL, "sounds/windy_ambience.ogg", ST_WAV_STREAM, true, true);
struct Sound_Source* sound_source = scene_sound_source_create(game_state->scene, "Beats", NULL, "sounds/algebra_loop.ogg", ST_WAV_STREAM, true, true);
//struct Sound_Source* sound_source = scene_sound_source_create(game_state->scene, "Beats", NULL, "sounds/teh_beatz.wav", ST_WAV, true, true);
transform_translate(sound_source, &(vec3){0.f, 3.f, 0.f}, TS_WORLD);
struct Light* light = scene_light_create(game_state->scene, "Test_Light", NULL, LT_POINT);
light->color.x = 1.f;
@ -1890,6 +1894,7 @@ void game_cleanup(void)
texture_cleanup();
shader_cleanup();
sound_cleanup(game_state->sound);
physics_cleanup();
event_manager_cleanup(game_state->event_manager);
free(game_state->editor);
@ -1903,8 +1908,6 @@ void game_cleanup(void)
free(game_state);
game_state = NULL;
}
physics_cleanup();
}
struct Game_State* game_state_get(void)

@ -47,7 +47,8 @@ void player_init(struct Player* player, struct Scene* scene)
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);
sound_listener_set(game_state->sound, player_camera);
sound_listener_update(game_state->sound);
}
void player_destroy(struct Player* player)

@ -199,7 +199,6 @@ void scene_post_update(struct Scene* scene)
if(scene->player.base.transform.is_modified)
{
sound_listener_update(sound);
scene->player.base.transform.is_modified = false;
}
}
@ -325,7 +324,7 @@ struct Sound_Source* scene_sound_source_create(struct Scene* scene, const char*
struct Sound_Source* new_sound_source = NULL;
for(int i = 0; i < MAX_SOUND_SOURCES; i++)
{
struct Sound_Source* sound_source = &scene->static_meshes[i];
struct Sound_Source* sound_source = &scene->sound_sources[i];
if(!sound_source->base.active)
{
new_sound_source = sound_source;
@ -356,7 +355,7 @@ struct Sound_Source* scene_sound_source_create(struct Scene* scene, const char*
new_sound_source->min_distance = 0.f;
new_sound_source->max_distance = 10.f;
new_sound_source->playing = play;
new_sound_source->attenuation_type = SA_INVERSE;
new_sound_source->attenuation_type = SA_LINEAR;
new_sound_source->rolloff_factor = 0.95f;
new_sound_source->volume = 1.f;
new_sound_source->type = type;
@ -394,6 +393,7 @@ void scene_light_remove(struct Scene* scene, struct Light* light)
{
assert(scene && light);
scene_entity_base_remove(scene, &light->base);
light->valid = false;
}
void scene_camera_remove(struct Scene* scene, struct Camera* camera)
@ -583,21 +583,6 @@ void scene_ray_intersect(struct Scene* scene, struct Ray* ray, struct Raycast_Re
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

@ -86,6 +86,7 @@ void transform_copy(struct Entity* copy_to, struct Entity* copy_from, bool copy_
copy_to->transform.parent = current_parent;
}
copy_to->transform.is_modified = true;
copy_to->transform.children = current_children;
}

@ -77,6 +77,7 @@ void sound_master_volume_set(struct Sound* sound, float volume)
void sound_update_3d(struct Sound* sound)
{
sound_listener_update(sound);
Soloud_update3dAudio(sound->soloud_context);
}
@ -85,12 +86,9 @@ void sound_cleanup(struct Sound* sound)
for(int i = 0; i < MAX_SOUND_BUFFERS; i++ )
{
struct Sound_Source_Buffer* source = &sound->sound_buffers[i];
sound_source_stop_all(sound, source);
switch(source->type)
{
case ST_WAV: Wav_destroy(source->wav); break;
case ST_WAV_STREAM: WavStream_destroy(source->wavstream); break;
}
if(source->type != ST_NONE)
sound_source_destroy(sound, source);
}
Soloud_deinit(sound->soloud_context);
@ -253,13 +251,13 @@ struct Sound_Source_Buffer* sound_source_create(struct Sound* sound, const char*
return 0;
}
source->type = ST_WAV_STREAM;
source->wavstream = wave_stream;
}
break;
default: log_error("sound:source_create", "Invalid source type %d", type); break;
}
strncpy(source->filename, filename, MAX_FILENAME_LEN);
free(memory);
return source;
}
@ -280,9 +278,8 @@ struct Sound_Source_Buffer* sound_source_get(struct Sound* sound, const char* na
return source;
}
void sound_source_destroy(struct Sound* sound, const char* name)
void sound_source_destroy(struct Sound* sound, struct Sound_Source_Buffer* source)
{
struct Sound_Source_Buffer* source = sound_source_get(sound, name);
if(source)
{
sound_source_stop_all(sound, source);

@ -70,7 +70,7 @@ bool sound_source_instance_is_paused(struct Sound* sound, uint source_instance)
struct Sound_Source_Buffer* sound_source_create(struct Sound* sound, const char* filename, int type);
struct Sound_Source_Buffer* sound_source_get(struct Sound* sound, const char* name);
void sound_source_destroy(struct Sound* sound, const char* buffer_name);
void sound_source_destroy(struct Sound* sound, struct Sound_Source_Buffer* source);
void sound_source_volume_set(struct Sound* sound, struct Sound_Source_Buffer* source, float volume);
void sound_source_loop_set(struct Sound* sound, struct Sound_Source_Buffer* source, bool loop);
void sound_source_stop_all(struct Sound* sound, struct Sound_Source_Buffer* source);

@ -1,4 +1,6 @@
Todo:
- Fix all sound related bugs before moving on and finish sound
serialization to file
- Finish mesh and material properties serialization to and from file
- Editor functionality to add entity from specific file to scene
- Scene read/write to file with scene file only containing names of

Loading…
Cancel
Save