Completed sound serialization to/from file and fixed issue with wav files not loading

dev
Shariq Shah 6 years ago
parent 7b84fbdc01
commit 33c181e0cb
  1. 6
      src/common/log.c
  2. 16
      src/game/console.c
  3. 4
      src/game/editor.c
  4. 36
      src/game/entity.c
  5. 4
      src/game/game.c
  6. 3
      src/game/scene.c
  7. 11
      src/system/sound.c
  8. 8
      todo.txt

@ -103,7 +103,7 @@ void log_message(const char* message, ...)
va_copy(file_list, console_list);
vfprintf(log_file, message, file_list);
vprintf(message, console_list);
//message_callback(message, console_list);
message_callback(message, console_list);
va_end(console_list);
va_end(file_list);
printf("\n%s", COL_RESET);
@ -120,7 +120,7 @@ void log_warning(const char* message, ...)
va_copy(file_list, console_list);
vfprintf(log_file, message, file_list);
vprintf(message, console_list);
//warning_callback(message, console_list);
warning_callback(message, console_list);
va_end(console_list);
va_end(file_list);
printf("\n");
@ -137,7 +137,7 @@ void log_error(const char* context, const char* error, ...)
va_copy(file_list, console_list);
vfprintf(log_file, error, file_list);
vprintf(error, console_list);
//error_callback(context, error, console_list);
error_callback(context, error, console_list);
va_end(console_list);
va_end(file_list);
printf("\n%s", COL_RESET);

@ -17,6 +17,7 @@ static int console_filter(const struct nk_text_edit *box, nk_rune unicode);
static void console_command_entity_save(struct Console* console, const char* command);
static void console_command_entity_load(struct Console* console, const char* command);
static void console_command_help(struct Console* console, const char* command);
void console_init(struct Console* console)
{
@ -44,6 +45,7 @@ void console_init(struct Console* console)
console->console_commands = hashmap_new();
hashmap_ptr_set(console->console_commands, "entity_save", &console_command_entity_save);
hashmap_ptr_set(console->console_commands, "entity_load", &console_command_entity_load);
hashmap_ptr_set(console->console_commands, "help", &console_command_help);
}
void console_toggle(struct Console* console)
@ -208,3 +210,17 @@ void console_command_entity_load(struct Console* console, const char* command)
return;
}
}
void console_command_help(struct Console* console, const char* command)
{
char* key = NULL;
Console_Command_Handler value;
log_message("======================================");
log_message("Available Commands");
log_message("======================================");
HASHMAP_FOREACH(console->console_commands, key, value)
{
log_message("%s", key);
}
log_message("======================================");
}

@ -114,7 +114,7 @@ void editor_init(struct Editor* editor)
editor->selected_entity = NULL;
editor->hovered_entity = NULL;
editor->top_panel_height = 30;
editor->camera_turn_speed = 50.f;
editor->camera_turn_speed = 90.f;
editor->camera_move_speed = 20.f;
editor->camera_sprint_multiplier = 2.f;
editor->current_tool = EDITOR_TOOL_NORMAL;
@ -1344,7 +1344,7 @@ void editor_camera_update(struct Editor* editor, float dt)
if(input_mousebutton_state_get(MSB_RIGHT, KS_PRESSED))
{
const float scale = 0.1f;
const float scale = 0.5f;
int cursor_lr, cursor_ud;
input_mouse_delta_get(&cursor_lr, &cursor_ud);
editor->camera_looking_around = true;

@ -310,29 +310,22 @@ struct Entity* entity_read(struct Parser_Object* object)
break;
case ET_SOUND_SOURCE:
{
struct Sound_Source* sound_source = scene_sound_source_create(scene, name, NULL, "teh_beatz.wav", ST_WAV, true, true);
sound_source->type = ST_WAV;
sound_source->playing = false;
sound_source->loop = false;
sound_source->source_instance = 0;
sound_source->min_distance = 1.f;
sound_source->max_distance = 1000.f;
sound_source->volume = 1.f;
sound_source->rolloff_factor = 1.f;
sound_source->attenuation_type = SA_EXPONENTIAL;
sound_source->source_buffer = NULL;
if(hashmap_value_exists(object->data, "playing")) sound_source->playing = hashmap_bool_get(object->data, "playing");
if(hashmap_value_exists(object->data, "loop")) sound_source->loop = hashmap_bool_get(object->data, "loop");
if(hashmap_value_exists(object->data, "sound_min_distance")) sound_source->min_distance = hashmap_float_get(object->data, "sound_min_distance");
if(hashmap_value_exists(object->data, "sound_max_distance")) sound_source->max_distance = hashmap_float_get(object->data, "sound_max_distance");
if(hashmap_value_exists(object->data, "volume")) sound_source->volume = hashmap_float_get(object->data, "volume");
if(hashmap_value_exists(object->data, "rolloff_factor")) sound_source->rolloff_factor = hashmap_float_get(object->data, "rolloff_factor");
if(hashmap_value_exists(object->data, "sound_type")) sound_source->type = hashmap_int_get(object->data, "sound_type");
if(hashmap_value_exists(object->data, "sound_attenuation_type")) sound_source->attenuation_type = hashmap_int_get(object->data, "sound_attenuation_type");
struct Sound_Source* sound_source = scene_sound_source_create(scene, name, NULL, "sounds/teh_beatz.wav", ST_WAV, true, true);
struct Sound_Source_Buffer* default_source_buffer = sound_source->source_buffer;
uint default_source_instance = sound_source->source_instance;
sound_source->playing = (hashmap_value_exists(object->data, "playing")) ? hashmap_bool_get(object->data, "playing") : true;
sound_source->loop = (hashmap_value_exists(object->data, "loop")) ? hashmap_bool_get(object->data, "loop") : true;
sound_source->min_distance = (hashmap_value_exists(object->data, "sound_min_distance")) ? hashmap_float_get(object->data, "sound_min_distance") : 1.f;
sound_source->max_distance = (hashmap_value_exists(object->data, "sound_max_distance")) ? hashmap_float_get(object->data, "sound_max_distance") : 1000.f;
sound_source->volume = (hashmap_value_exists(object->data, "volume")) ? hashmap_float_get(object->data, "volume") : 1.f;
sound_source->rolloff_factor = (hashmap_value_exists(object->data, "rolloff_factor")) ? hashmap_float_get(object->data, "rolloff_factor") : 1.f;
sound_source->type = (hashmap_value_exists(object->data, "sound_type")) ? hashmap_int_get(object->data, "sound_type") : ST_WAV;
sound_source->attenuation_type = (hashmap_value_exists(object->data, "sound_attenuation_type")) ? hashmap_int_get(object->data, "sound_attenuation_type") : SA_EXPONENTIAL;
if(hashmap_value_exists(object->data, "source_filename"))
{
struct Sound* sound = game_state_get()->sound;
sound_source->source_buffer = sound_source_create(sound, hashmap_str_get(object->data, "source_filename"), sound_source->type);
if(sound_source->source_buffer)
{
@ -350,6 +343,9 @@ struct Entity* entity_read(struct Parser_Object* object)
sound_update_3d(sound);
if(sound_source->playing)
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);
}
else
{

@ -311,8 +311,8 @@ 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);
//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);

@ -544,6 +544,9 @@ void* scene_find(struct Scene* scene, const char* name)
entity = scene_static_mesh_find(scene, name);
if(entity) return entity;
entity = scene_sound_source_find(scene, name);
if(entity) return entity;
return entity;
}

@ -229,29 +229,32 @@ struct Sound_Source_Buffer* sound_source_create(struct Sound* sound, const char*
case ST_WAV:
{
Wav* wave = Wav_create();
int rc = Wav_loadMem(wave, memory, (uint)size);
// Tell soloud to copy the memory and not to take ownership of memory provided in order
// to avoid crash when soloud tries to free the memory allocated by us across the dll boundary
int rc = Wav_loadMemEx(wave, memory, (uint)size, true, false);
if(rc != 0)
{
log_error("sound:source_create", "Failed to load %s, Soloud: %s", filename, Soloud_getErrorString(sound->soloud_context, rc));
free(memory);
return 0;
}
source->type = ST_WAV;
source->wav = wave;
free(memory);
}
break;
case ST_WAV_STREAM:
{
WavStream* wave_stream = WavStream_create();
int rc = WavStream_loadMem(wave_stream, memory, (uint)size);
//int rc = WavStream_loadMem(wave_stream, memory, (uint)size);
int rc = WavStream_loadMemEx(wave_stream, memory, (uint)size, true, false);
if(rc != 0)
{
log_error("sound:source_create", "Failed to load %s, Soloud: %s", filename, Soloud_getErrorString(sound->soloud_context, rc));
free(memory);
return 0;
}
source->type = ST_WAV_STREAM;
source->wavstream = wave_stream;
free(memory);
}
break;
default: log_error("sound:source_create", "Invalid source type %d", type); break;

@ -1,6 +1,7 @@
Todo:
- Fix all sound related bugs before moving on and finish sound
serialization to file
- Display default mesh when selected entity type in editor does not have a mesh
- Allow picking and selecting other entity types in editor i.e. the ones that don't have meshes
- Separate entity types in entity heirarchy view by the entity type or use a tree view to show parent/child relation or use differnt colours for different entity types
- 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
@ -117,7 +118,7 @@ Bugs:
- Fix arc angles resetting when rotating
- Fix shader preprocessor failing when the file in //include directive is empty
- Fix bug with blinn shader reaching maximum uniform number on mac
- Fix Deployment target issue in xcode build on macos
- Fix delete in editor not working when the cursor is hovering over scene heirarchy window
Done:
* Input
@ -317,3 +318,4 @@ Done:
to reduce inconsistencies
* Fixed symlink issue in genie for macos which interferes with fopen operations
* Implement/Fix copying libraries to executable folder after build completes on mac os
* Fixed all sound related bugs and completede sound to/from file

Loading…
Cancel
Save