From b2545f804200d7211fe62aa0dd24a8987607f3d6 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 23 May 2021 16:21:04 +0200 Subject: [PATCH] - PlayMusic script function. --- source/common/scripting/interface/vmnatives.cpp | 14 ++++++++++++++ source/core/raze_music.cpp | 5 ----- wadsrc/static/zscript/engine/base.zs | 1 + 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/source/common/scripting/interface/vmnatives.cpp b/source/common/scripting/interface/vmnatives.cpp index 25bbdd2e1..cb86e5cd2 100644 --- a/source/common/scripting/interface/vmnatives.cpp +++ b/source/common/scripting/interface/vmnatives.cpp @@ -1014,6 +1014,20 @@ DEFINE_ACTION_FUNCTION_NATIVE(_System, StopAllSounds, StopAllSounds) return 0; } +static int PlayMusic(const FString& musname, int order, int looped) +{ + return S_ChangeMusic(musname, order, !!looped, true); +} + +DEFINE_ACTION_FUNCTION_NATIVE(_System, PlayMusic, PlayMusic) +{ + PARAM_PROLOGUE; + PARAM_STRING(name); + PARAM_INT(order); + PARAM_BOOL(looped); + ACTION_RETURN_BOOL(PlayMusic(name, order, looped)); +} + static void Mus_Stop() { S_StopMusic(true); diff --git a/source/core/raze_music.cpp b/source/core/raze_music.cpp index 2423ad25d..4e7e941f5 100644 --- a/source/core/raze_music.cpp +++ b/source/core/raze_music.cpp @@ -190,14 +190,9 @@ static FString LookupMusicCB(const char* musicname, int& order) } -static FString lastMusic; int Mus_Play(const char *fn, bool loop) { if (mus_blocked) return 1; // Caller should believe it succeeded. - if (*fn == '/') fn++; - // Store the requested names for resuming. - lastMusic = fn; - return S_ChangeMusic(fn, 0, loop, true); } diff --git a/wadsrc/static/zscript/engine/base.zs b/wadsrc/static/zscript/engine/base.zs index 0937cd93c..e81f9cc0b 100644 --- a/wadsrc/static/zscript/engine/base.zs +++ b/wadsrc/static/zscript/engine/base.zs @@ -188,6 +188,7 @@ struct _ native // These are the global variables, the struct is only here to av struct System native { + native static void PlayMusic(String mus, int order = 0, bool looped = true); native static void StopMusic(); native static void StopAllSounds(); native static bool SoundEnabled();