diff --git a/source/common/scripting/interface/vmnatives.cpp b/source/common/scripting/interface/vmnatives.cpp index 6276ac906..477863378 100644 --- a/source/common/scripting/interface/vmnatives.cpp +++ b/source/common/scripting/interface/vmnatives.cpp @@ -50,6 +50,8 @@ #include "i_interface.h" #include "base_sbar.h" #include "image.h" +#include "s_soundinternal.h" +#include "i_time.h" //========================================================================== // @@ -989,6 +991,44 @@ DEFINE_ACTION_FUNCTION(_Console, Printf) return 0; } +static void StopAllSounds() +{ + soundEngine->StopAllChannels(); +} + +DEFINE_ACTION_FUNCTION_NATIVE(_System, StopAllSounds, StopAllSounds) +{ + StopAllSounds(); + return 0; +} + +static void Mus_Stop() +{ + S_StopMusic(true); +} + +DEFINE_ACTION_FUNCTION_NATIVE(_System, StopMusic, Mus_Stop) +{ + Mus_Stop(); + return 0; +} + +DEFINE_ACTION_FUNCTION_NATIVE(_System, SoundEnabled, SoundEnabled) +{ + ACTION_RETURN_INT(SoundEnabled()); +} + +DEFINE_ACTION_FUNCTION_NATIVE(_System, MusicEnabled, MusicEnabled) +{ + ACTION_RETURN_INT(MusicEnabled()); +} + +DEFINE_ACTION_FUNCTION_NATIVE(_System, GetTimeFrac, I_GetTimeFrac) +{ + ACTION_RETURN_FLOAT(I_GetTimeFrac()); +} + + DEFINE_GLOBAL_NAMED(mus_playing, musplaying); DEFINE_FIELD_X(MusPlayingInfo, MusPlayingInfo, name); DEFINE_FIELD_X(MusPlayingInfo, MusPlayingInfo, baseorder); diff --git a/source/core/gamecontrol.cpp b/source/core/gamecontrol.cpp index 5a4dc2a22..cae67657d 100644 --- a/source/core/gamecontrol.cpp +++ b/source/core/gamecontrol.cpp @@ -1480,33 +1480,6 @@ DEFINE_ACTION_FUNCTION_NATIVE(_Raze, ShadeToLight, shadeToLight) ACTION_RETURN_INT(shadeToLight(shade)); } -DEFINE_ACTION_FUNCTION_NATIVE(_Raze, StopAllSounds, FX_StopAllSounds) -{ - FX_StopAllSounds(); - return 0; -} - -DEFINE_ACTION_FUNCTION_NATIVE(_Raze, StopMusic, Mus_Stop) -{ - Mus_Stop(); - return 0; -} - -DEFINE_ACTION_FUNCTION_NATIVE(_Raze, SoundEnabled, SoundEnabled) -{ - ACTION_RETURN_INT(SoundEnabled()); -} - -DEFINE_ACTION_FUNCTION_NATIVE(_Raze, MusicEnabled, MusicEnabled) -{ - ACTION_RETURN_INT(MusicEnabled()); -} - -DEFINE_ACTION_FUNCTION_NATIVE(_Raze, GetTimeFrac, I_GetTimeFrac) -{ - ACTION_RETURN_FLOAT(I_GetTimeFrac()); -} - DEFINE_ACTION_FUNCTION(_Raze, PlayerName) { PARAM_PROLOGUE; diff --git a/wadsrc/static/zscript.txt b/wadsrc/static/zscript.txt index 5c3479e0a..f207778ed 100644 --- a/wadsrc/static/zscript.txt +++ b/wadsrc/static/zscript.txt @@ -3,6 +3,7 @@ version "4.3" #include "zscript/engine/dynarrays.zs" #include "zscript/engine/inputevents.zs" #include "zscript/engine/dictionary.zs" +#include "zscript/engine/screenjob.zs" #include "zscript/engine/ui/menu/colorpickermenu.zs" #include "zscript/engine/ui/menu/joystickmenu.zs" @@ -28,7 +29,7 @@ version "4.3" #include "zscript/constants.zs" #include "zscript/razebase.zs" -#include "zscript/screenjob.zs" +#include "zscript/summary.zs" #include "zscript/statusbar.zs" #include "zscript/games/duke/dukegame.zs" #include "zscript/games/duke/ui/sbar.zs" diff --git a/wadsrc/static/zscript/engine/base.zs b/wadsrc/static/zscript/engine/base.zs index 21115a193..5deef7ec0 100644 --- a/wadsrc/static/zscript/engine/base.zs +++ b/wadsrc/static/zscript/engine/base.zs @@ -180,6 +180,27 @@ struct _ native // These are the global variables, the struct is only here to av native MenuDelegateBase menuDelegate; native readonly int consoleplayer; native readonly double NotifyFontScale; + native readonly int paused; +} + +struct System native +{ + native static void StopMusic(); + native static void StopAllSounds(); + native static bool SoundEnabled(); + native static bool MusicEnabled(); + native static double GetTimeFrac(); + + static bool specialKeyEvent(InputEvent ev) + { + if (ev.type == InputEvent.Type_KeyDown || ev.type == InputEvent.Type_KeyUp) + { + int key = ev.KeyScan; + if (key == InputEvent.KEY_VOLUMEDOWN || key == InputEvent.KEY_VOLUMEUP || (key > InputEvent.KEY_LASTJOYBUTTON && key < InputEvent.KEY_PAD_LTHUMB_RIGHT)) return true; + } + return false; + } + } struct MusPlayingInfo native diff --git a/wadsrc/static/zscript/screenjob.zs b/wadsrc/static/zscript/engine/screenjob.zs similarity index 93% rename from wadsrc/static/zscript/screenjob.zs rename to wadsrc/static/zscript/engine/screenjob.zs index dd7763cd9..fcd9d07e8 100644 --- a/wadsrc/static/zscript/screenjob.zs +++ b/wadsrc/static/zscript/engine/screenjob.zs @@ -57,8 +57,8 @@ class ScreenJob : Object int GetFadeState() { return fadestate; } override void OnDestroy() { - if (flags & stopmusic) Raze.StopMusic(); - if (flags & stopsound) Raze.StopAllSounds(); + if (flags & stopmusic) System.StopMusic(); + if (flags & stopsound) System.StopAllSounds(); } } @@ -78,7 +78,7 @@ class SkippableScreenJob : ScreenJob override bool OnEvent(InputEvent evt) { - if (evt.type == InputEvent.Type_KeyDown && !Raze.specialKeyEvent(evt)) + if (evt.type == InputEvent.Type_KeyDown && !System.specialKeyEvent(evt)) { jobstate = skipped; OnSkip(); @@ -186,34 +186,6 @@ class ImageScreen : SkippableScreenJob } } -//--------------------------------------------------------------------------- -// -// this is to have a unified interface to the summary screens -// that can be set up automatically by the games to avoid direct access to game data. -// -//--------------------------------------------------------------------------- - -class SummaryScreenBase : ScreenJob -{ - MapRecord level; - SummaryInfo stats; - - void SetParameters(MapRecord map, SummaryInfo thestats) - { - level = map; - stats = thestats; - } - - String FormatTime(int time) - { - if (time >= 60 * 50) - return String.Format("%02d:%02d:%02d", time / (60*60), (time / 60) % 60, time % 60); - else - return String.Format("%02d:%02d", (time / 60) % 60, time % 60); - } - -} - //--------------------------------------------------------------------------- // // internal polymorphic movie player object diff --git a/wadsrc/static/zscript/games/blood/ui/screens.zs b/wadsrc/static/zscript/games/blood/ui/screens.zs index ba0b38585..0419255f8 100644 --- a/wadsrc/static/zscript/games/blood/ui/screens.zs +++ b/wadsrc/static/zscript/games/blood/ui/screens.zs @@ -147,7 +147,7 @@ class BloodSummaryScreen : SummaryScreenBase override bool OnEvent(InputEvent ev) { - if (ev.type == InputEvent.Type_KeyDown && !Raze.specialKeyEvent(ev)) + if (ev.type == InputEvent.Type_KeyDown && !System.specialKeyEvent(ev)) { jobstate = skipped; return true; @@ -202,7 +202,7 @@ class BloodSummaryScreen : SummaryScreenBase override void OnDestroy() { - Raze.StopAllSounds(); + System.StopAllSounds(); } } diff --git a/wadsrc/static/zscript/games/duke/dukegame.zs b/wadsrc/static/zscript/games/duke/dukegame.zs index 97f49acac..6445ee80b 100644 --- a/wadsrc/static/zscript/games/duke/dukegame.zs +++ b/wadsrc/static/zscript/games/duke/dukegame.zs @@ -72,7 +72,7 @@ struct Duke native static void PlayBonusMusic() { - if (Raze.MusicEnabled()) + if (System.MusicEnabled()) PlaySound(DukeSnd.BONUSMUSIC, CHAN_AUTO, CHANF_UI); } diff --git a/wadsrc/static/zscript/games/duke/ui/screens.zs b/wadsrc/static/zscript/games/duke/ui/screens.zs index 440e05221..21b402103 100644 --- a/wadsrc/static/zscript/games/duke/ui/screens.zs +++ b/wadsrc/static/zscript/games/duke/ui/screens.zs @@ -319,7 +319,7 @@ class Episode3End : ImageScreen override void OnSkip() { - Raze.StopAllSounds(); + System.StopAllSounds(); } override void OnTick() @@ -367,7 +367,7 @@ class Episode3End : ImageScreen if (!Duke.CheckSoundPlaying(DukeSnd.ENDSEQVOL3SND9)) { soundstate++; - finishtime = ticks + GameTicRate * (Raze.SoundEnabled() ? 1 : 5); // if sound is off this wouldn't wait without a longer delay here. + finishtime = ticks + GameTicRate * (System.SoundEnabled() ? 1 : 5); // if sound is off this wouldn't wait without a longer delay here. } break; @@ -381,7 +381,7 @@ class Episode3End : ImageScreen default: break; } - if (jobstate != running) Raze.StopAllSounds(); + if (jobstate != running) System.StopAllSounds(); } override void OnDestroy() @@ -600,7 +600,7 @@ class DukeLevelSummaryScreen : SummaryScreenBase override bool OnEvent(InputEvent ev) { - if (ev.type == InputEvent.Type_KeyDown && !Raze.specialKeyEvent(ev)) + if (ev.type == InputEvent.Type_KeyDown && !System.specialKeyEvent(ev)) { if ((displaystate & printStatsAll) != printStatsAll) { @@ -837,7 +837,7 @@ class RRLevelSummaryScreen : SummaryScreenBase override bool OnEvent(InputEvent ev) { - if (ev.type == InputEvent.Type_KeyDown && !Raze.specialKeyEvent(ev)) + if (ev.type == InputEvent.Type_KeyDown && !System.specialKeyEvent(ev)) { if ((displaystate & printStatsAll) != printStatsAll) { diff --git a/wadsrc/static/zscript/games/exhumed/ui/screens.zs b/wadsrc/static/zscript/games/exhumed/ui/screens.zs index 4cdbbafbf..dbb986639 100644 --- a/wadsrc/static/zscript/games/exhumed/ui/screens.zs +++ b/wadsrc/static/zscript/games/exhumed/ui/screens.zs @@ -345,7 +345,7 @@ class MapScreen : ScreenJob } return true; } - if (!Raze.specialKeyEvent(ev)) jobstate = skipped; + if (!System.specialKeyEvent(ev)) jobstate = skipped; return true; } return false; @@ -527,7 +527,7 @@ class Cinema : SkippableScreenJob override void Start() { - Raze.StopAllSounds(); + System.StopAllSounds(); if (cdtrack != -1) { Exhumed.playCDtrack(cdtrack, false); @@ -652,7 +652,7 @@ class LastLevelCinema : ScreenJob override bool OnEvent(InputEvent ev) { - if (ev.type == InputEvent.Type_KeyDown && !Raze.specialKeyEvent(ev)) skiprequest = true; + if (ev.type == InputEvent.Type_KeyDown && !System.specialKeyEvent(ev)) skiprequest = true; return true; } @@ -775,7 +775,7 @@ class ExCredits : ScreenJob override bool OnEvent(InputEvent ev) { - if (ev.type == InputEvent.Type_KeyDown && !Raze.specialKeyEvent(ev)) skiprequest = true; + if (ev.type == InputEvent.Type_KeyDown && !System.specialKeyEvent(ev)) skiprequest = true; return true; } @@ -919,7 +919,7 @@ class ExhumedCutscenes static void BuildGameOverScene(ScreenJobRunner runner, MapRecord map) { - Raze.StopMusic(); + System.StopMusic(); Exhumed.PlayLocalSound(ExhumedSnd.kSoundJonLaugh2, 0, false, CHANF_UI); runner.Append(ImageScreen.CreateNamed("Gameover", ScreenJob.fadein | ScreenJob.fadeout, 0x7fffffff, Translation.MakeID(Translation_BasePalette, 16))); } diff --git a/wadsrc/static/zscript/games/sw/ui/screens.zs b/wadsrc/static/zscript/games/sw/ui/screens.zs index 6b2a15fde..e51ccb05e 100644 --- a/wadsrc/static/zscript/games/sw/ui/screens.zs +++ b/wadsrc/static/zscript/games/sw/ui/screens.zs @@ -207,7 +207,7 @@ class SWSummaryScreen : SummaryScreenBase override bool OnEvent(InputEvent ev) { - if (ev.type == InputEvent.Type_KeyDown && !Raze.specialKeyEvent(ev)) + if (ev.type == InputEvent.Type_KeyDown && !System.specialKeyEvent(ev)) { if (animstate == 0) animstate = 1; } @@ -216,7 +216,7 @@ class SWSummaryScreen : SummaryScreenBase override void Start() { - Raze.StopAllSounds(); + System.StopAllSounds(); SW.PlaySong(1); } diff --git a/wadsrc/static/zscript/razebase.zs b/wadsrc/static/zscript/razebase.zs index 22d754d37..a801d7b20 100644 --- a/wadsrc/static/zscript/razebase.zs +++ b/wadsrc/static/zscript/razebase.zs @@ -68,7 +68,6 @@ extend struct _ { native @UserConfigStruct userConfig; native readonly MapRecord currentLevel; - native readonly int paused; native readonly int automapMode; native readonly int PlayClock; } @@ -143,27 +142,12 @@ struct Raze } native static Color shadeToLight(int shade); - native static void StopAllSounds(); - native static bool SoundEnabled(); - native static void StopMusic(); - native static bool MusicEnabled(); native static String PlayerName(int i); - native static double GetTimeFrac(); native static int bsin(int angle, int shift = 0); native static int bcos(int angle, int shift = 0); native static TextureID PickTexture(TextureID texid); native static int GetBuildTime(); - static bool specialKeyEvent(InputEvent ev) - { - if (ev.type == InputEvent.Type_KeyDown || ev.type == InputEvent.Type_KeyUp) - { - int key = ev.KeyScan; - if (key == InputEvent.KEY_VOLUMEDOWN || key == InputEvent.KEY_VOLUMEUP || (key > InputEvent.KEY_LASTJOYBUTTON && key < InputEvent.KEY_PAD_LTHUMB_RIGHT)) return true; - } - return false; - } - // game check shortcuts static bool isNam() { diff --git a/wadsrc/static/zscript/summary.zs b/wadsrc/static/zscript/summary.zs new file mode 100644 index 000000000..5eae05fbe --- /dev/null +++ b/wadsrc/static/zscript/summary.zs @@ -0,0 +1,28 @@ +//--------------------------------------------------------------------------- +// +// this is to have a unified interface to the summary screens +// that can be set up automatically by the games to avoid direct access to game data. +// +//--------------------------------------------------------------------------- + +class SummaryScreenBase : ScreenJob +{ + MapRecord level; + SummaryInfo stats; + + void SetParameters(MapRecord map, SummaryInfo thestats) + { + level = map; + stats = thestats; + } + + String FormatTime(int time) + { + if (time >= 60 * 50) + return String.Format("%02d:%02d:%02d", time / (60*60), (time / 60) % 60, time % 60); + else + return String.Format("%02d:%02d", (time / 60) % 60, time % 60); + } + +} +