From 30cbb77728c8c420c6a261692921c58498209cd9 Mon Sep 17 00:00:00 2001 From: VDm Date: Sun, 25 Feb 2024 19:10:35 +0400 Subject: [PATCH] chore(ui): implement Script_PlayGlueMusic --- src/sound/SI2.cpp | 22 +++++++++++++++++++++- src/sound/SI2.hpp | 3 ++- src/ui/CMakeLists.txt | 1 + src/ui/ScriptFunctionsGlueScriptEvents.cpp | 8 +++++++- 4 files changed, 31 insertions(+), 3 deletions(-) diff --git a/src/sound/SI2.cpp b/src/sound/SI2.cpp index 4413780..ef00636 100644 --- a/src/sound/SI2.cpp +++ b/src/sound/SI2.cpp @@ -1,6 +1,20 @@ #include "sound/SI2.hpp" #include "ui/FrameScript.hpp" #include "console/CVar.hpp" +#include + +void* F_CALL FMOD_Alloc(unsigned int size, FMOD_MEMORY_TYPE type, const char* sourcestr) { + return SMemAlloc(size, sourcestr, 0, 0); +} + +void* F_CALL FMOD_ReAlloc(void* ptr, unsigned int size, FMOD_MEMORY_TYPE type, const char* sourcestr) { + return SMemReAlloc(ptr, size, sourcestr, 0, 0); +} + +void F_CALL FMOD_Free(void* ptr, FMOD_MEMORY_TYPE type, const char* sourcestr) { + SMemFree(ptr, sourcestr, 0, 0); +} + void SI2::RegisterScriptFunctions() { FrameScript_Method* item = s_ScriptFunctions; @@ -17,7 +31,13 @@ int32_t SI2::Init(int32_t flag) { SI2_LOG(" "); SI2_LOG("=> Setting up Game Sound:"); SI2_LOG(" - SESound Engine Init"); - SI2_LOG(" - FMOD Memory Init"); + + auto errcode = FMOD::Memory_Initialize(nullptr, 0, &FMOD_Alloc, &FMOD_ReAlloc, &FMOD_Free); + SI2_ERR(errcode, " - FMOD Memory Init"); return 0; } + +void SI2::StartGlueMusic(const char* filename) { + +} diff --git a/src/sound/SI2.hpp b/src/sound/SI2.hpp index c2b5583..f4f3d43 100644 --- a/src/sound/SI2.hpp +++ b/src/sound/SI2.hpp @@ -5,7 +5,7 @@ #include #include #include -#include +#include #include @@ -26,6 +26,7 @@ class SI2 { static void Log_Write(uint32_t line, const char* filename, FMOD_RESULT errcode, const char* format, ...); static void RegisterCVars(); static int32_t Init(int32_t flag); + static void StartGlueMusic(const char* filename); }; #endif diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt index 8bf424e..17cb3aa 100644 --- a/src/ui/CMakeLists.txt +++ b/src/ui/CMakeLists.txt @@ -25,4 +25,5 @@ target_link_libraries(ui common storm tempest + fmod ) diff --git a/src/ui/ScriptFunctionsGlueScriptEvents.cpp b/src/ui/ScriptFunctionsGlueScriptEvents.cpp index 2c7aad8..376524a 100644 --- a/src/ui/ScriptFunctionsGlueScriptEvents.cpp +++ b/src/ui/ScriptFunctionsGlueScriptEvents.cpp @@ -11,6 +11,7 @@ #include "util/Lua.hpp" #include "util/SFile.hpp" #include "util/Unimplemented.hpp" +#include "sound/SI2.hpp" #include int32_t Script_IsShiftKeyDown(lua_State* L) { @@ -80,7 +81,12 @@ int32_t Script_QuitGameAndRunLauncher(lua_State* L) { } int32_t Script_PlayGlueMusic(lua_State* L) { - WHOA_UNIMPLEMENTED(0); + if (!lua_isstring(L, 1)) { + return luaL_error(L, "Usage: PlayGlueMusic(\"filename\")"); + } + + SI2::StartGlueMusic(lua_tolstring(L, 1, 0)); + return 0; } int32_t Script_PlayCreditsMusic(lua_State* L) {