diff --git a/assets/sounds/algebra_loop.ogg b/assets/sounds/algebra_loop.ogg new file mode 100644 index 0000000..34404bb Binary files /dev/null and b/assets/sounds/algebra_loop.ogg differ diff --git a/assets/sounds/windy_ambience.ogg b/assets/sounds/windy_ambience.ogg new file mode 100644 index 0000000..1a536b0 Binary files /dev/null and b/assets/sounds/windy_ambience.ogg differ diff --git a/build/genie.lua b/build/genie.lua index a951995..0bf3fe9 100644 --- a/build/genie.lua +++ b/build/genie.lua @@ -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", diff --git a/lib/windows/soloud/soloud_x64.dll b/lib/windows/soloud/soloud_x64.dll index e25c171..d4bbaba 100755 Binary files a/lib/windows/soloud/soloud_x64.dll and b/lib/windows/soloud/soloud_x64.dll differ diff --git a/lib/windows/soloud/soloud_x64.exp b/lib/windows/soloud/soloud_x64.exp index 2db2ffc..45e116f 100755 Binary files a/lib/windows/soloud/soloud_x64.exp and b/lib/windows/soloud/soloud_x64.exp differ diff --git a/lib/windows/soloud/soloud_x64.lib b/lib/windows/soloud/soloud_x64.lib index 254d485..4cbf402 100755 Binary files a/lib/windows/soloud/soloud_x64.lib and b/lib/windows/soloud/soloud_x64.lib differ diff --git a/lib/windows/soloud/soloud_x64_d.dll b/lib/windows/soloud/soloud_x64_d.dll index ebc68a9..d0ca26f 100755 Binary files a/lib/windows/soloud/soloud_x64_d.dll and b/lib/windows/soloud/soloud_x64_d.dll differ diff --git a/lib/windows/soloud/soloud_x64_d.exp b/lib/windows/soloud/soloud_x64_d.exp index 1933887..e1c66a7 100755 Binary files a/lib/windows/soloud/soloud_x64_d.exp and b/lib/windows/soloud/soloud_x64_d.exp differ diff --git a/lib/windows/soloud/soloud_x64_d.ilk b/lib/windows/soloud/soloud_x64_d.ilk index b779c9a..fc7ec20 100755 Binary files a/lib/windows/soloud/soloud_x64_d.ilk and b/lib/windows/soloud/soloud_x64_d.ilk differ diff --git a/lib/windows/soloud/soloud_x64_d.lib b/lib/windows/soloud/soloud_x64_d.lib index 627534b..b49fefc 100755 Binary files a/lib/windows/soloud/soloud_x64_d.lib and b/lib/windows/soloud/soloud_x64_d.lib differ diff --git a/lib/windows/soloud/soloud_x64_d.pdb b/lib/windows/soloud/soloud_x64_d.pdb index 4258ee1..4e8c461 100755 Binary files a/lib/windows/soloud/soloud_x64_d.pdb and b/lib/windows/soloud/soloud_x64_d.pdb differ diff --git a/src/game/editor.c b/src/game/editor.c index 2fef6e4..6d45fbe 100755 --- a/src/game/editor.c +++ b/src/game/editor.c @@ -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 { diff --git a/src/game/game.c b/src/game/game.c index 962abaa..84be597 100755 --- a/src/game/game.c +++ b/src/game/game.c @@ -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) diff --git a/src/game/player.c b/src/game/player.c index 423a2d7..d421600 100755 --- a/src/game/player.c +++ b/src/game/player.c @@ -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) diff --git a/src/game/scene.c b/src/game/scene.c index 170c0c0..a38c772 100755 --- a/src/game/scene.c +++ b/src/game/scene.c @@ -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; @@ -385,7 +384,7 @@ void scene_entity_base_remove(struct Scene* scene, struct Entity* entity) transform_destroy(entity); entity->active = false; - entity->selected_in_editor = false; + entity->selected_in_editor = false; entity->marked_for_deletion = false; memset(entity->name, '\0', MAX_ENTITY_NAME_LEN); } @@ -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 } - - - - - - - - - - - - - - - //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/game/transform.c b/src/game/transform.c index 8ab199c..6a6aa26 100755 --- a/src/game/transform.c +++ b/src/game/transform.c @@ -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; } diff --git a/src/system/sound.c b/src/system/sound.c index 8367bb9..293d0bb 100755 --- a/src/system/sound.c +++ b/src/system/sound.c @@ -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); diff --git a/src/system/sound.h b/src/system/sound.h index a02515d..f358b84 100755 --- a/src/system/sound.h +++ b/src/system/sound.h @@ -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); diff --git a/todo.txt b/todo.txt index d7149ec..507f0f3 100644 --- a/todo.txt +++ b/todo.txt @@ -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