From 25d1d85ebf6a862fdd32a12cccbf54902c25287d Mon Sep 17 00:00:00 2001 From: stechyo Date: Sun, 18 Aug 2024 08:55:42 +0100 Subject: [PATCH] Fixes for 4.3 compat. --- .gitmodules | 2 +- project/project.godot | 22 +++++++++++----------- project/scenes/demo.tscn | 2 -- src/lib/godot-cpp | 2 +- src/register_types.cpp | 11 ++++++++--- src/server.cpp | 7 +++++-- src/server.hpp | 4 ++-- src/stream.cpp | 2 +- 8 files changed, 29 insertions(+), 23 deletions(-) diff --git a/.gitmodules b/.gitmodules index 8f753a4..b2e21d0 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,7 +1,7 @@ [submodule "src/lib/godot-cpp"] path = src/lib/godot-cpp url = https://github.com/stechyo/godot-cpp - branch = gdext/steam-audio + branch = 4.3-steam-audio [submodule "src/lib/steamaudio"] path = src/lib/steamaudio url = https://github.com/ValveSoftware/steam-audio diff --git a/project/project.godot b/project/project.godot index 47542ff..296c6d0 100644 --- a/project/project.godot +++ b/project/project.godot @@ -12,50 +12,50 @@ config_version=5 config/name="Godot-SteamAudio Demo" run/main_scene="res://scenes/demo.tscn" -config/features=PackedStringArray("4.2") +config/features=PackedStringArray("4.3") config/icon="res://icon.svg" [input] ui_left={ "deadzone": 0.5, -"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194319,"physical_keycode":0,"key_label":0,"unicode":0,"echo":false,"script":null) +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194319,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null) , Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":13,"pressure":0.0,"pressed":false,"script":null) , Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":0,"axis_value":-1.0,"script":null) -, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":65,"key_label":0,"unicode":97,"echo":false,"script":null) +, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":65,"key_label":0,"unicode":97,"location":0,"echo":false,"script":null) ] } ui_right={ "deadzone": 0.5, -"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194321,"physical_keycode":0,"key_label":0,"unicode":0,"echo":false,"script":null) +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194321,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null) , Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":14,"pressure":0.0,"pressed":false,"script":null) , Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":0,"axis_value":1.0,"script":null) -, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":68,"key_label":0,"unicode":100,"echo":false,"script":null) +, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":68,"key_label":0,"unicode":100,"location":0,"echo":false,"script":null) ] } ui_up={ "deadzone": 0.5, -"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194320,"physical_keycode":0,"key_label":0,"unicode":0,"echo":false,"script":null) +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194320,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null) , Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":11,"pressure":0.0,"pressed":false,"script":null) , Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":1,"axis_value":-1.0,"script":null) -, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":87,"key_label":0,"unicode":119,"echo":false,"script":null) +, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":87,"key_label":0,"unicode":119,"location":0,"echo":false,"script":null) ] } ui_down={ "deadzone": 0.5, -"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194322,"physical_keycode":0,"key_label":0,"unicode":0,"echo":false,"script":null) +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194322,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null) , Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":12,"pressure":0.0,"pressed":false,"script":null) , Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":1,"axis_value":1.0,"script":null) -, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":83,"key_label":0,"unicode":115,"echo":false,"script":null) +, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":83,"key_label":0,"unicode":115,"location":0,"echo":false,"script":null) ] } toggle_door={ "deadzone": 0.5, -"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":49,"key_label":0,"unicode":49,"echo":false,"script":null) +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":49,"key_label":0,"unicode":49,"location":0,"echo":false,"script":null) ] } move_door={ "deadzone": 0.5, -"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":50,"key_label":0,"unicode":50,"echo":false,"script":null) +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":50,"key_label":0,"unicode":50,"location":0,"echo":false,"script":null) ] } diff --git a/project/scenes/demo.tscn b/project/scenes/demo.tscn index 9be67e2..e13d7f0 100644 --- a/project/scenes/demo.tscn +++ b/project/scenes/demo.tscn @@ -46,9 +46,7 @@ material = SubResource("StandardMaterial3D_dg8l6") [sub_resource type="AudioStreamRandomizer" id="AudioStreamRandomizer_w72gs"] streams_count = 2 stream_0/stream = ExtResource("5_00edw") -stream_0/weight = 1.0 stream_1/stream = ExtResource("6_dw5dv") -stream_1/weight = 1.0 [sub_resource type="StandardMaterial3D" id="StandardMaterial3D_pyn86"] albedo_color = Color(0.976471, 0.133333, 0.286275, 1) diff --git a/src/lib/godot-cpp b/src/lib/godot-cpp index 1d5ef38..45aeb1c 160000 --- a/src/lib/godot-cpp +++ b/src/lib/godot-cpp @@ -1 +1 @@ -Subproject commit 1d5ef3878945b536b56ab1cfe3205363bf124ac6 +Subproject commit 45aeb1c69c72c915461cdf3473c7be882de62b90 diff --git a/src/register_types.cpp b/src/register_types.cpp index 8eb9325..a659ed7 100644 --- a/src/register_types.cpp +++ b/src/register_types.cpp @@ -3,6 +3,7 @@ #include "config.hpp" #include "geometry.hpp" #include "geometry_dynamic.hpp" +#include "godot_cpp/core/memory.hpp" #include "listener.hpp" #include "material.hpp" #include "player.hpp" @@ -16,6 +17,8 @@ using namespace godot; +SteamAudioServer *srv; + void init_ext(ModuleInitializationLevel p_level) { if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE && p_level != MODULE_INITIALIZATION_LEVEL_SERVERS) { return; @@ -34,13 +37,15 @@ void init_ext(ModuleInitializationLevel p_level) { if (p_level == MODULE_INITIALIZATION_LEVEL_SERVERS) { GDREGISTER_CLASS(SteamAudioServer); - auto sa = memnew(SteamAudioServer); + srv = memnew(SteamAudioServer); } } void uninit_ext(ModuleInitializationLevel p_level) { - if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE && p_level != MODULE_INITIALIZATION_LEVEL_SERVERS) { - return; + if (p_level == MODULE_INITIALIZATION_LEVEL_SERVERS) { + // Should call this to not leak, but thread->wait_for_finish() crashes... + // the program is exiting anyway so I'm not too concerned + // memdelete(srv); } } diff --git a/src/server.cpp b/src/server.cpp index b7be93f..aab9fa3 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -2,6 +2,7 @@ #include "godot_cpp/classes/engine.hpp" #include "godot_cpp/classes/project_settings.hpp" #include "godot_cpp/core/class_db.hpp" +#include "godot_cpp/core/memory.hpp" #include "godot_cpp/variant/callable_method_pointer.hpp" #include "phonon.h" #include "server_init.hpp" @@ -208,7 +209,7 @@ GlobalSteamAudioState *SteamAudioServer::get_global_state(bool should_init) { } void SteamAudioServer::start_refl_sim() { - refl_thread.start(callable_mp(this, &SteamAudioServer::run_refl_sim)); + refl_thread->start(callable_mp(this, &SteamAudioServer::run_refl_sim)); } void SteamAudioServer::run_refl_sim() { @@ -290,11 +291,13 @@ SteamAudioServer::SteamAudioServer() { is_refl_thread_processing.store(false); is_running.store(true); local_states_have_changed.store(false); + refl_thread = memnew(Thread); } SteamAudioServer::~SteamAudioServer() { is_running.store(false); - refl_thread.wait_to_finish(); + refl_thread->wait_to_finish(); + memdelete(refl_thread); if (!self->is_global_state_init.load()) { return; diff --git a/src/server.hpp b/src/server.hpp index 6421636..ef15603 100644 --- a/src/server.hpp +++ b/src/server.hpp @@ -32,12 +32,12 @@ class SteamAudioServer : public Object { std::vector dynamic_meshes_to_add; // TODO: allow for multiple - SteamAudioListener *listener; + SteamAudioListener *listener = nullptr; void init_scene(IPLSceneSettings *scene_cfg); void start_refl_sim(); void run_refl_sim(); - Thread refl_thread = Thread(); + Thread *refl_thread = nullptr; protected: static void _bind_methods(); diff --git a/src/stream.cpp b/src/stream.cpp index 23eff02..6560674 100644 --- a/src/stream.cpp +++ b/src/stream.cpp @@ -67,7 +67,7 @@ int32_t SteamAudioStreamPlayback::_mix(AudioFrame *buffer, double rate_scale, in return frames; } - PackedVector2Array mixed_frames = stream_playback->get_raw_audio(rate_scale, frames); + PackedVector2Array mixed_frames = stream_playback->mix_audio(rate_scale, frames); frames = int(mixed_frames.size()); for (int i = 0; i < frames; i++) {