diff --git a/autogen/lua_definitions/functions.lua b/autogen/lua_definitions/functions.lua index 3a09077fb..d90952d3b 100644 --- a/autogen/lua_definitions/functions.lua +++ b/autogen/lua_definitions/functions.lua @@ -10180,6 +10180,12 @@ function audio_sample_play(audio, position, volume) -- ... end +--- @return integer +--- Allocates an `audio` sequence +function allocate_seq() + -- ... +end + --- Resets camera config overrides function camera_reset_overrides() -- ... diff --git a/docs/lua/functions-6.md b/docs/lua/functions-6.md index 7bb215c22..ac77b3a13 100644 --- a/docs/lua/functions-6.md +++ b/docs/lua/functions-6.md @@ -1458,6 +1458,27 @@ Plays an `audio` sample at `position` with `volume`
+## [allocate_seq](#allocate_seq) + +### Description +Allocates an `audio` sequence + +### Lua Example +`local integerValue = allocate_seq()` + +### Parameters +- None + +### Returns +- `integer` + +### C Prototype +`u32 allocate_seq(void);` + +[:arrow_up_small:](#) + +
+ --- # functions from smlua_camera_utils.h diff --git a/docs/lua/functions.md b/docs/lua/functions.md index 1f1f41c22..df13bcbde 100644 --- a/docs/lua/functions.md +++ b/docs/lua/functions.md @@ -1824,6 +1824,7 @@ - [audio_sample_destroy](functions-6.md#audio_sample_destroy) - [audio_sample_stop](functions-6.md#audio_sample_stop) - [audio_sample_play](functions-6.md#audio_sample_play) + - [allocate_seq](functions-6.md#allocate_seq)
diff --git a/src/pc/lua/smlua_functions_autogen.c b/src/pc/lua/smlua_functions_autogen.c index fdd758841..81c517d02 100644 --- a/src/pc/lua/smlua_functions_autogen.c +++ b/src/pc/lua/smlua_functions_autogen.c @@ -30759,6 +30759,21 @@ int smlua_func_audio_sample_play(lua_State* L) { return 1; } +int smlua_func_allocate_seq(UNUSED lua_State* L) { + if (L == NULL) { return 0; } + + int top = lua_gettop(L); + if (top != 0) { + LOG_LUA_LINE("Improper param count for '%s': Expected %u, Received %u", "allocate_seq", 0, top); + return 0; + } + + + lua_pushinteger(L, allocate_seq()); + + return 1; +} + ////////////////////////// // smlua_camera_utils.h // ////////////////////////// @@ -38038,6 +38053,7 @@ void smlua_bind_functions_autogen(void) { smlua_bind_function(L, "audio_sample_destroy", smlua_func_audio_sample_destroy); smlua_bind_function(L, "audio_sample_stop", smlua_func_audio_sample_stop); smlua_bind_function(L, "audio_sample_play", smlua_func_audio_sample_play); + smlua_bind_function(L, "allocate_seq", smlua_func_allocate_seq); // smlua_camera_utils.h smlua_bind_function(L, "camera_reset_overrides", smlua_func_camera_reset_overrides); diff --git a/src/pc/lua/utils/smlua_audio_utils.c b/src/pc/lua/utils/smlua_audio_utils.c index 2345b0878..6067b3ea2 100644 --- a/src/pc/lua/utils/smlua_audio_utils.c +++ b/src/pc/lua/utils/smlua_audio_utils.c @@ -4,6 +4,8 @@ #define STB_VORBIS_HEADER_ONLY #include "pc/utils/stb_vorbis.c" +#define MAX_CUSTOM_SEQS 1024 + #include "types.h" #include "seq_ids.h" #include "audio/external.h" @@ -29,6 +31,8 @@ struct AudioOverride { struct AudioOverride sAudioOverrides[MAX_AUDIO_OVERRIDE] = { 0 }; +static u32 sCustomSeqsCount = 0; + static void smlua_audio_utils_reset(struct AudioOverride* override) { if (override == NULL) { return; } @@ -65,6 +69,7 @@ void smlua_audio_utils_reset_all(void) { #endif smlua_audio_utils_reset(&sAudioOverrides[i]); } + sCustomSeqsCount = 0; } bool smlua_audio_utils_override(u8 sequenceId, s32* bankId, void** seqData) { @@ -619,3 +624,12 @@ void smlua_audio_custom_deinit(void) { sModAudioPool = NULL; } } + + +u32 allocate_seq() { + if ((sCustomSeqsCount + SEQ_COUNT) < MAX_CUSTOM_SEQS) { + return (++sCustomSeqsCount + SEQ_COUNT); + } + LOG_ERROR("Cannot allocate more custom sequences."); + return 0; +} \ No newline at end of file diff --git a/src/pc/lua/utils/smlua_audio_utils.h b/src/pc/lua/utils/smlua_audio_utils.h index 4fc276548..193c0b4cd 100644 --- a/src/pc/lua/utils/smlua_audio_utils.h +++ b/src/pc/lua/utils/smlua_audio_utils.h @@ -76,4 +76,7 @@ void audio_custom_update_volume(void); void audio_custom_shutdown(void); void smlua_audio_custom_deinit(void); +/* |description|Allocates an `audio` sequence|descriptionEnd| */ +u32 allocate_seq(void); + #endif