diff --git a/src/audio/backend.jai b/src/audio/backend.jai index 3b9ae26..4d6a378 100644 --- a/src/audio/backend.jai +++ b/src/audio/backend.jai @@ -1,4 +1,21 @@ +AUDIO_THREAD_TEMP_STORAGE_SIZE :: 4096; +audio_thread_temp_storage : Temporary_Storage; +audio_thread_temp_storage_data : [AUDIO_THREAD_TEMP_STORAGE_SIZE] u8 #align 64; +audio_thread_context_ready : bool = false; +audio_thread_context : #Context; + +audio_init_thread_context :: () { + audio_thread_context = default_context; + audio_thread_context.temporary_storage = *audio_thread_temp_storage; + audio_thread_temp_storage.data = audio_thread_temp_storage_data.data; + audio_thread_temp_storage.size = audio_thread_temp_storage_data.count; + audio_thread_temp_storage.original_data = audio_thread_temp_storage_data.data; + audio_thread_temp_storage.original_size = audio_thread_temp_storage_data.count; + audio_thread_context_ready = true; +} + sokol_audio_callback :: (buffer: *float, num_frames: s32, num_channels: s32) #c_call { - push_context,defer_pop default_context; + if !audio_thread_context_ready then return; + push_context,defer_pop audio_thread_context; mixer_get_samples(buffer, num_frames, num_channels); } diff --git a/src/main.jai b/src/main.jai index 679242c..68a3332 100644 --- a/src/main.jai +++ b/src/main.jai @@ -94,6 +94,8 @@ init :: () { logger = .{ func = slog_func }, })); asset_manager_init(); + Thread.init(*g_mixer.mutex); + audio_init_thread_context(); saudio_setup(*(saudio_desc.{ logger = .{ func = slog_func }, stream_cb = sokol_audio_callback, diff --git a/src/rendering/animation.jai b/src/rendering/animation.jai index f6a36a5..537a799 100644 --- a/src/rendering/animation.jai +++ b/src/rendering/animation.jai @@ -37,7 +37,7 @@ animation_player_tick :: (player: *Animation_Player) { animation_draw :: (player: *Animation_Player, position: Vector3, flipX: bool = false, flipY: bool = false) { animation_player_tick(player); - if player.current_animation == null then log_warn("Trying to draw a null animation!!"); + if player.current_animation == null then return; create_billboard_rendering_task(position, player.current_animation, player.current_frame, flipX, flipY); } @@ -57,6 +57,7 @@ animation_set_if_not :: (player: *Animation_Player, animation: string) { } animation_is :: (player: *Animation_Player, animation: string) -> bool { + if player.current_animation == null then return false; _, pack, anim := split_from_left(animation, "."); return player.current_animation.name == anim; }