From 6aa61e72b598c64e0f05af950bf1d35ab9f9d80c Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 22 Jul 2023 09:54:00 +0200 Subject: [PATCH] - backend update from GZDoom. * cleanup on the sound init code. * added #pragma once in several headers. * macOS version detection overhaul. --- source/common/audio/music/i_music.cpp | 5 +-- source/common/audio/music/i_music.h | 13 +----- source/common/audio/music/music.cpp | 4 ++ source/common/audio/sound/i_soundinternal.h | 24 +++++------ source/common/console/c_commandbuffer.h | 1 + source/common/console/c_consolebuffer.h | 1 + source/common/engine/palettecontainer.cpp | 2 +- source/common/engine/palettecontainer.h | 2 +- source/common/engine/serializer.h | 2 +- source/common/engine/serializer_internal.h | 1 + source/common/filesystem/ancientzip.h | 1 + source/common/menu/menudef.cpp | 1 + source/common/objects/dobjtype.cpp | 3 ++ .../platform/posix/cocoa/i_joystick.cpp | 5 ++- source/common/platform/posix/cocoa/i_main.mm | 21 +++++----- .../common/platform/posix/sdl/i_joystick.cpp | 6 ++- source/common/platform/posix/sdl/st_start.cpp | 24 ++++++++--- source/common/platform/win32/winres.h | 1 + .../rendering/hwrenderer/data/hw_cvars.h | 1 - .../hwrenderer/data/hw_viewpointbuffer.h | 2 +- .../vulkan/renderer/vk_renderpass.cpp | 1 + .../common/scripting/interface/vmnatives.cpp | 9 ++++- source/common/scripting/jit/jitintern.h | 2 +- source/common/scripting/vm/vm.h | 24 ++--------- source/common/textures/animlib.h | 1 + .../textures/hires/hqnx_asm/hqnx_asm_Image.h | 1 + source/common/utility/tarray.h | 21 ++++++++++ source/common/utility/vectors.h | 40 ++++++++++++------- source/common/utility/weightedlist.h | 1 + source/core/actorinfo.cpp | 1 + source/core/gamefuncs.h | 2 +- source/core/raze_music.cpp | 3 +- 32 files changed, 135 insertions(+), 91 deletions(-) diff --git a/source/common/audio/music/i_music.cpp b/source/common/audio/music/i_music.cpp index 0bc858292..6b8580724 100644 --- a/source/common/audio/music/i_music.cpp +++ b/source/common/audio/music/i_music.cpp @@ -40,7 +40,6 @@ #include #include -#include "m_argv.h" #include "filesystem.h" #include "c_dispatch.h" @@ -218,13 +217,13 @@ static void SetupDMXGUS() // //========================================================================== -void I_InitMusic(void) +void I_InitMusic(int musicstate) { I_InitSoundFonts(); snd_musicvolume->Callback (); - nomusic = !!Args->CheckParm("-nomusic") || !!Args->CheckParm("-nosound"); + nomusic = musicstate; snd_mididevice->Callback(); diff --git a/source/common/audio/music/i_music.h b/source/common/audio/music/i_music.h index a6609eadb..aa2d48e62 100644 --- a/source/common/audio/music/i_music.h +++ b/source/common/audio/music/i_music.h @@ -34,27 +34,16 @@ #ifndef __I_MUSIC_H__ #define __I_MUSIC_H__ -#include "c_cvars.h" - -class FileReader; -struct FOptionValues; - // // MUSIC I/O // -void I_InitMusic (); -void I_BuildMIDIMenuList (FOptionValues *); +void I_InitMusic (int); // Volume. void I_SetRelativeVolume(float); void I_SetMusicVolume (double volume); -extern int nomusic; - -EXTERN_CVAR(Bool, mus_enabled) -EXTERN_CVAR(Float, snd_musicvolume) - inline float AmplitudeTodB(float amplitude) { diff --git a/source/common/audio/music/music.cpp b/source/common/audio/music/music.cpp index 610f0368f..6101dc1cc 100644 --- a/source/common/audio/music/music.cpp +++ b/source/common/audio/music/music.cpp @@ -53,9 +53,11 @@ #include "gain_analysis.h" #include "i_specialpaths.h" #include "configfile.h" +#include "c_cvars.h" // EXTERNAL FUNCTION PROTOTYPES -------------------------------------------- +extern int nomusic; extern float S_GetMusicVolume (const char *music); static void S_ActivatePlayList(bool goBack); @@ -81,6 +83,8 @@ static MusicCallbacks mus_cb = { nullptr, DefaultOpenMusic }; // PUBLIC DATA DEFINITIONS ------------------------------------------------- +EXTERN_CVAR(Bool, mus_enabled) +EXTERN_CVAR(Float, snd_musicvolume) EXTERN_CVAR(Int, snd_mididevice) EXTERN_CVAR(Float, mod_dumb_mastervolume) EXTERN_CVAR(Float, fluid_gain) diff --git a/source/common/audio/sound/i_soundinternal.h b/source/common/audio/sound/i_soundinternal.h index 4787aa12a..52dabeea3 100644 --- a/source/common/audio/sound/i_soundinternal.h +++ b/source/common/audio/sound/i_soundinternal.h @@ -5,7 +5,6 @@ #include #include "vectors.h" -#include "tarray.h" #include "tflags.h" enum EChanFlag @@ -38,8 +37,6 @@ enum EChanFlag typedef TFlags EChanFlags; DEFINE_TFLAGS_OPERATORS(EChanFlags) -class FileReader; - // For convenience, this structure matches FMOD_REVERB_PROPERTIES. // Since I can't very well #include system-specific stuff in the // main game files, I duplicate it here. @@ -78,14 +75,17 @@ struct REVERB_PROPERTIES unsigned int Flags; }; -#define REVERB_FLAGS_DECAYTIMESCALE 0x00000001 -#define REVERB_FLAGS_REFLECTIONSSCALE 0x00000002 -#define REVERB_FLAGS_REFLECTIONSDELAYSCALE 0x00000004 -#define REVERB_FLAGS_REVERBSCALE 0x00000008 -#define REVERB_FLAGS_REVERBDELAYSCALE 0x00000010 -#define REVERB_FLAGS_DECAYHFLIMIT 0x00000020 -#define REVERB_FLAGS_ECHOTIMESCALE 0x00000040 -#define REVERB_FLAGS_MODULATIONTIMESCALE 0x00000080 +enum EReverbFlags +{ + REVERB_FLAGS_DECAYTIMESCALE = 0x00000001, + REVERB_FLAGS_REFLECTIONSSCALE = 0x00000002, + REVERB_FLAGS_REFLECTIONSDELAYSCALE = 0x00000004, + REVERB_FLAGS_REVERBSCALE = 0x00000008, + REVERB_FLAGS_REVERBDELAYSCALE = 0x00000010, + REVERB_FLAGS_DECAYHFLIMIT = 0x00000020, + REVERB_FLAGS_ECHOTIMESCALE = 0x00000040, + REVERB_FLAGS_MODULATIONTIMESCALE = 0x00000080, +}; struct ReverbContainer { @@ -144,8 +144,6 @@ struct FISoundChannel EChanFlags ChanFlags; }; -class SoundStream; - void S_SetSoundPaused(int state); diff --git a/source/common/console/c_commandbuffer.h b/source/common/console/c_commandbuffer.h index 179651c45..637027b27 100644 --- a/source/common/console/c_commandbuffer.h +++ b/source/common/console/c_commandbuffer.h @@ -1,3 +1,4 @@ +#pragma once #include #include "zstring.h" diff --git a/source/common/console/c_consolebuffer.h b/source/common/console/c_consolebuffer.h index 58bc0edea..8d4e235d5 100644 --- a/source/common/console/c_consolebuffer.h +++ b/source/common/console/c_consolebuffer.h @@ -32,6 +32,7 @@ **--------------------------------------------------------------------------- ** */ +#pragma once #include #include diff --git a/source/common/engine/palettecontainer.cpp b/source/common/engine/palettecontainer.cpp index 9648f2528..800dc31c6 100644 --- a/source/common/engine/palettecontainer.cpp +++ b/source/common/engine/palettecontainer.cpp @@ -367,7 +367,7 @@ static bool IndexOutOfRange(const int start1, const int end1, const int start2, // //---------------------------------------------------------------------------- -bool FRemapTable::operator==(const FRemapTable& o) +bool FRemapTable::operator==(const FRemapTable& o) const { // Two translations are identical when they have the same amount of colors // and the palette values for both are identical. diff --git a/source/common/engine/palettecontainer.h b/source/common/engine/palettecontainer.h index e1d0befd3..a220873a6 100644 --- a/source/common/engine/palettecontainer.h +++ b/source/common/engine/palettecontainer.h @@ -19,7 +19,7 @@ struct FRemapTable FRemapTable(const FRemapTable& o) = default; FRemapTable& operator=(const FRemapTable& o) = default; - bool operator==(const FRemapTable& o); + bool operator==(const FRemapTable& o) const; void MakeIdentity(); bool IsIdentity() const; bool AddIndexRange(int start, int end, int pal1, int pal2); diff --git a/source/common/engine/serializer.h b/source/common/engine/serializer.h index b337cd832..c9cc26320 100644 --- a/source/common/engine/serializer.h +++ b/source/common/engine/serializer.h @@ -234,6 +234,7 @@ FSerializer &Serialize(FSerializer &arc, const char *key, FName &value, FName *d FSerializer &Serialize(FSerializer &arc, const char *key, FSoundID &sid, FSoundID *def); FSerializer &Serialize(FSerializer &arc, const char *key, FString &sid, FString *def); FSerializer &Serialize(FSerializer &arc, const char *key, NumericValue &sid, NumericValue *def); +FSerializer &Serialize(FSerializer &arc, const char *key, struct ModelOverride &sid, struct ModelOverride *def); template >*/> FSerializer &Serialize(FSerializer &arc, const char *key, T *&value, T **) @@ -244,7 +245,6 @@ FSerializer &Serialize(FSerializer &arc, const char *key, T *&value, T **) return arc; } - template FSerializer &Serialize(FSerializer &arc, const char *key, TArray &value, TArray *def) { diff --git a/source/common/engine/serializer_internal.h b/source/common/engine/serializer_internal.h index 31cf76c1a..05b6dcad0 100644 --- a/source/common/engine/serializer_internal.h +++ b/source/common/engine/serializer_internal.h @@ -1,3 +1,4 @@ +#pragma once const char* UnicodeToString(const char* cc); const char* StringToUnicode(const char* cc, int size = -1); diff --git a/source/common/filesystem/ancientzip.h b/source/common/filesystem/ancientzip.h index 621505504..6241f775d 100644 --- a/source/common/filesystem/ancientzip.h +++ b/source/common/filesystem/ancientzip.h @@ -1,3 +1,4 @@ +#pragma once #include "files.h" #include "engineerrors.h" diff --git a/source/common/menu/menudef.cpp b/source/common/menu/menudef.cpp index 4fbeeb0bb..e81bda2d2 100644 --- a/source/common/menu/menudef.cpp +++ b/source/common/menu/menudef.cpp @@ -1662,6 +1662,7 @@ static void InitMusicMenus() // Special menus will be created once all engine data is loaded // //============================================================================= +void I_BuildMIDIMenuList(FOptionValues*); void M_CreateMenus() { diff --git a/source/common/objects/dobjtype.cpp b/source/common/objects/dobjtype.cpp index b39c930f8..f9ccc4c77 100644 --- a/source/common/objects/dobjtype.cpp +++ b/source/common/objects/dobjtype.cpp @@ -231,6 +231,8 @@ void PClass::StaticInit () // //========================================================================== +void ClearServices(); + void PClass::StaticShutdown () { if (WP_NOCHANGE != nullptr) @@ -238,6 +240,7 @@ void PClass::StaticShutdown () delete WP_NOCHANGE; } + ClearServices(); // delete all variables containing pointers to script functions. for (auto p : FunctionPtrList) { diff --git a/source/common/platform/posix/cocoa/i_joystick.cpp b/source/common/platform/posix/cocoa/i_joystick.cpp index 8d9e80127..733380366 100644 --- a/source/common/platform/posix/cocoa/i_joystick.cpp +++ b/source/common/platform/posix/cocoa/i_joystick.cpp @@ -1202,7 +1202,10 @@ void I_GetJoysticks(TArray& sticks) void I_GetAxes(float axes[NUM_JOYAXIS]) { - memset(axes, 0, sizeof(float) * NUM_JOYAXIS); + for (size_t i = 0; i < NUM_JOYAXIS; ++i) + { + axes[i] = 0.0f; + } if (use_joystick && NULL != s_joystickManager) { diff --git a/source/common/platform/posix/cocoa/i_main.mm b/source/common/platform/posix/cocoa/i_main.mm index 3e257a5ce..8a9d96b07 100644 --- a/source/common/platform/posix/cocoa/i_main.mm +++ b/source/common/platform/posix/cocoa/i_main.mm @@ -151,21 +151,24 @@ void I_DetectOS() case 10: switch (version.minorVersion) { - case 12: name = "macOS Sierra"; break; - case 13: name = "macOS High Sierra"; break; - case 14: name = "macOS Mojave"; break; - case 15: name = "macOS Catalina"; break; - case 16: name = "macOS Big Sur"; break; + case 12: name = "Sierra"; break; + case 13: name = "High Sierra"; break; + case 14: name = "Mojave"; break; + case 15: name = "Catalina"; break; + case 16: name = "Big Sur"; break; } break; case 11: - name = "macOS Big Sur"; + name = "Big Sur"; break; case 12: - name = "macOS Monterey"; + name = "Monterey"; break; case 13: - name = "macOS Ventura"; + name = "Ventura"; + break; + case 14: + name = "Sonoma"; break; } @@ -186,7 +189,7 @@ void I_DetectOS() "Unknown"; #endif - Printf("%s running %s %d.%d.%d (%s) %s\n", model, name, + Printf("%s running macOS %s %d.%d.%d (%s) %s\n", model, name, int(version.majorVersion), int(version.minorVersion), int(version.patchVersion), release, architecture); } diff --git a/source/common/platform/posix/sdl/i_joystick.cpp b/source/common/platform/posix/sdl/i_joystick.cpp index f3c30e8e8..0fa33ba63 100644 --- a/source/common/platform/posix/sdl/i_joystick.cpp +++ b/source/common/platform/posix/sdl/i_joystick.cpp @@ -324,8 +324,10 @@ void I_GetJoysticks(TArray &sticks) void I_GetAxes(float axes[NUM_JOYAXIS]) { - memset(axes, 0, sizeof(float) * NUM_JOYAXIS); - + for (int i = 0; i < NUM_JOYAXIS; ++i) + { + axes[i] = 0; + } if (use_joystick && JoystickManager) { JoystickManager->AddAxes(axes); diff --git a/source/common/platform/posix/sdl/st_start.cpp b/source/common/platform/posix/sdl/st_start.cpp index d372e79bc..c068e682a 100644 --- a/source/common/platform/posix/sdl/st_start.cpp +++ b/source/common/platform/posix/sdl/st_start.cpp @@ -257,6 +257,7 @@ bool FTTYStartupScreen::NetLoop(bool (*timer_callback)(void *), void *userdata) struct timeval tv; int retval; char k; + bool stdin_eof = false; for (;;) { @@ -265,7 +266,10 @@ bool FTTYStartupScreen::NetLoop(bool (*timer_callback)(void *), void *userdata) tv.tv_usec = 500000; FD_ZERO (&rfds); - FD_SET (STDIN_FILENO, &rfds); + if (!stdin_eof) + { + FD_SET (STDIN_FILENO, &rfds); + } retval = select (1, &rfds, NULL, NULL, &tv); @@ -281,13 +285,21 @@ bool FTTYStartupScreen::NetLoop(bool (*timer_callback)(void *), void *userdata) return true; } } - else if (read (STDIN_FILENO, &k, 1) == 1) + else { - // Check input on stdin - if (k == 'q' || k == 'Q') + ssize_t amt = read (STDIN_FILENO, &k, 1); // Check input on stdin + if (amt == 0) { - fprintf (stderr, "\nNetwork game synchronization aborted."); - return false; + // EOF. Stop reading + stdin_eof = true; + } + else if (amt == 1) + { + if (k == 'q' || k == 'Q') + { + fprintf (stderr, "\nNetwork game synchronization aborted."); + return false; + } } } } diff --git a/source/common/platform/win32/winres.h b/source/common/platform/win32/winres.h index 6d78230d8..a2b8711a6 100644 --- a/source/common/platform/win32/winres.h +++ b/source/common/platform/win32/winres.h @@ -10,6 +10,7 @@ // winres.h - Windows resource definitions // extracted from WINUSER.H and COMMCTRL.H +#pragma once #ifdef _AFX_MINREBUILD #pragma component(minrebuild, off) diff --git a/source/common/rendering/hwrenderer/data/hw_cvars.h b/source/common/rendering/hwrenderer/data/hw_cvars.h index 0b9d8f09b..cf2364979 100644 --- a/source/common/rendering/hwrenderer/data/hw_cvars.h +++ b/source/common/rendering/hwrenderer/data/hw_cvars.h @@ -18,7 +18,6 @@ EXTERN_CVAR (Bool, gl_light_shadowmap); EXTERN_CVAR (Int, gl_shadowmap_quality); EXTERN_CVAR(Int, gl_fogmode) -EXTERN_CVAR(Int, gl_lightmode) EXTERN_CVAR(Bool,gl_mirror_envmap) EXTERN_CVAR(Bool,gl_mirrors) diff --git a/source/common/rendering/hwrenderer/data/hw_viewpointbuffer.h b/source/common/rendering/hwrenderer/data/hw_viewpointbuffer.h index f52af7ebc..8efe61738 100644 --- a/source/common/rendering/hwrenderer/data/hw_viewpointbuffer.h +++ b/source/common/rendering/hwrenderer/data/hw_viewpointbuffer.h @@ -1,4 +1,4 @@ - +#pragma once #include "tarray.h" #include "hwrenderer/data/buffers.h" diff --git a/source/common/rendering/vulkan/renderer/vk_renderpass.cpp b/source/common/rendering/vulkan/renderer/vk_renderpass.cpp index 257f35c16..e445723d0 100644 --- a/source/common/rendering/vulkan/renderer/vk_renderpass.cpp +++ b/source/common/rendering/vulkan/renderer/vk_renderpass.cpp @@ -35,6 +35,7 @@ #include "hw_viewpointuniforms.h" #include "v_2ddrawer.h" #include "i_specialpaths.h" +#include "cmdlib.h" VkRenderPassManager::VkRenderPassManager(VulkanRenderDevice* fb) : fb(fb) { diff --git a/source/common/scripting/interface/vmnatives.cpp b/source/common/scripting/interface/vmnatives.cpp index 2c7df6fb7..54cc0d2a9 100644 --- a/source/common/scripting/interface/vmnatives.cpp +++ b/source/common/scripting/interface/vmnatives.cpp @@ -57,8 +57,8 @@ static ZSMap AllServices; -static void MarkServices() { - +static void MarkServices() +{ ZSMap::Iterator it(AllServices); ZSMap::Pair* pair; while (it.NextPair(pair)) @@ -82,6 +82,11 @@ void InitServices() GC::AddMarkerFunc(&MarkServices); } +void ClearServices() +{ + AllServices.Clear(); +} + //========================================================================== diff --git a/source/common/scripting/jit/jitintern.h b/source/common/scripting/jit/jitintern.h index aaf8d70a6..05dfd62df 100644 --- a/source/common/scripting/jit/jitintern.h +++ b/source/common/scripting/jit/jitintern.h @@ -1,4 +1,4 @@ - +#pragma once #include "jit.h" #include "types.h" diff --git a/source/common/scripting/vm/vm.h b/source/common/scripting/vm/vm.h index db2e305da..4b9334c04 100644 --- a/source/common/scripting/vm/vm.h +++ b/source/common/scripting/vm/vm.h @@ -45,6 +45,7 @@ #include "memarena.h" #include "name.h" #include "scopebarrier.h" +#include class DObject; union VMOP; @@ -618,6 +619,8 @@ namespace template struct native_is_valid { static const bool value = true; static const bool retval = true; }; template<> struct native_is_valid { static const bool value = true; static const bool retval = true; }; template<> struct native_is_valid { static const bool value = true; static const bool retval = true; }; + // [RL0] this is disabled for now due to graf's concerns + // template<> struct native_is_valid { static const bool value = true; static const bool retval = true; static_assert(sizeof(FName) == sizeof(int)); static_assert(std::is_pod_v);}; template<> struct native_is_valid { static const bool value = true; static const bool retval = true; }; template<> struct native_is_valid { static const bool value = true; static const bool retval = true; }; template<> struct native_is_valid { static const bool value = true; static const bool retval = false;}; // Bool as return does not work! @@ -628,26 +631,7 @@ struct DirectNativeDesc { DirectNativeDesc() = default; - #define TP(n) typename P##n - #define VP(n) ValidateType() - template DirectNativeDesc(Ret(*func)()) : Ptr(reinterpret_cast(func)) { ValidateRet(); } - template DirectNativeDesc(Ret(*func)(P1)) : Ptr(reinterpret_cast(func)) { ValidateRet(); VP(1); } - template DirectNativeDesc(Ret(*func)(P1,P2)) : Ptr(reinterpret_cast(func)) { ValidateRet(); VP(1); VP(2); } - template DirectNativeDesc(Ret(*func)(P1,P2,P3)) : Ptr(reinterpret_cast(func)) { ValidateRet(); VP(1); VP(2); VP(3); } - template DirectNativeDesc(Ret(*func)(P1, P2, P3, P4)) : Ptr(reinterpret_cast(func)) { ValidateRet(); VP(1); VP(2); VP(3); VP(4); } - template DirectNativeDesc(Ret(*func)(P1, P2, P3, P4, P5)) : Ptr(reinterpret_cast(func)) { ValidateRet(); VP(1); VP(2); VP(3); VP(4); VP(5); } - template DirectNativeDesc(Ret(*func)(P1, P2, P3, P4, P5, P6)) : Ptr(reinterpret_cast(func)) { ValidateRet(); VP(1); VP(2); VP(3); VP(4); VP(5); VP(6); } - template DirectNativeDesc(Ret(*func)(P1, P2, P3, P4, P5, P6, P7)) : Ptr(reinterpret_cast(func)) { ValidateRet(); VP(1); VP(2); VP(3); VP(4); VP(5); VP(6); VP(7); } - template DirectNativeDesc(Ret(*func)(P1, P2, P3, P4, P5, P6, P7, P8)) : Ptr(reinterpret_cast(func)) { ValidateRet(); VP(1); VP(2); VP(3); VP(4); VP(5); VP(6); VP(7); VP(8); } - template DirectNativeDesc(Ret(*func)(P1, P2, P3, P4, P5, P6, P7, P8, P9)) : Ptr(reinterpret_cast(func)) { ValidateRet(); VP(1); VP(2); VP(3); VP(4); VP(5); VP(6); VP(7); VP(8); VP(9); } - template DirectNativeDesc(Ret(*func)(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10)) : Ptr(reinterpret_cast(func)) { ValidateRet(); VP(1); VP(2); VP(3); VP(4); VP(5); VP(6); VP(7); VP(8); VP(9); VP(10); } - template DirectNativeDesc(Ret(*func)(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11)) : Ptr(reinterpret_cast(func)) { ValidateRet(); VP(1); VP(2); VP(3); VP(4); VP(5); VP(6); VP(7); VP(8); VP(9); VP(10); VP(11); } - template DirectNativeDesc(Ret(*func)(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12)) : Ptr(reinterpret_cast(func)) { ValidateRet(); VP(1); VP(2); VP(3); VP(4); VP(5); VP(6); VP(7); VP(8); VP(9); VP(10); VP(11); VP(12); } - template DirectNativeDesc(Ret(*func)(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13)) : Ptr(reinterpret_cast(func)) { ValidateRet(); VP(1); VP(2); VP(3); VP(4); VP(5); VP(6); VP(7); VP(8); VP(9); VP(10); VP(11); VP(12); VP(13); } - template DirectNativeDesc(Ret(*func)(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14)) : Ptr(reinterpret_cast(func)) { ValidateRet(); VP(1); VP(2); VP(3); VP(4); VP(5); VP(6); VP(7); VP(8); VP(9); VP(10); VP(11); VP(12); VP(13), VP(14); } - template DirectNativeDesc(Ret(*func)(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14)) : Ptr(reinterpret_cast(func)) { ValidateRet(); VP(1); VP(2); VP(3); VP(4); VP(5); VP(6); VP(7); VP(8); VP(9); VP(10); VP(11); VP(12); VP(13), VP(14), VP(15); } -#undef TP - #undef VP + template DirectNativeDesc(Ret(*func)(Params...)) : Ptr(reinterpret_cast(func)) { ValidateRet(); (ValidateType(), ...); } template void ValidateType() { static_assert(native_is_valid::value, "Argument type is not valid as a direct native parameter or return type"); } template void ValidateRet() { static_assert(native_is_valid::retval, "Return type is not valid as a direct native parameter or return type"); } diff --git a/source/common/textures/animlib.h b/source/common/textures/animlib.h index 23d0d89da..661f00fb2 100644 --- a/source/common/textures/animlib.h +++ b/source/common/textures/animlib.h @@ -24,6 +24,7 @@ Prepared for public release: 03/21/2003 - Charlie Wiederhold, 3D Realms Modifications for JonoF's port by Jonathon Fowler (jf@jonof.id.au) */ //------------------------------------------------------------------------- +#pragma once #include ///////////////////////////////////////////////////////////////////////////// diff --git a/source/common/textures/hires/hqnx_asm/hqnx_asm_Image.h b/source/common/textures/hires/hqnx_asm/hqnx_asm_Image.h index 918b904fe..6e2a93108 100644 --- a/source/common/textures/hires/hqnx_asm/hqnx_asm_Image.h +++ b/source/common/textures/hires/hqnx_asm/hqnx_asm_Image.h @@ -19,6 +19,7 @@ //#ifdef WIN32 //#define DLL __declspec(dllexport) //#else +#pragma once #define DLL //#endif diff --git a/source/common/utility/tarray.h b/source/common/utility/tarray.h index a21226095..3d49f1868 100644 --- a/source/common/utility/tarray.h +++ b/source/common/utility/tarray.h @@ -54,6 +54,7 @@ #include #include #include +#include #if !defined(_WIN32) #include // for intptr_t @@ -420,6 +421,26 @@ public: return start; } + unsigned AppendFill(const T& val, unsigned append_count) + { + unsigned start = Count; + + Grow(append_count); + Count += append_count; + if constexpr (std::is_trivially_copyable::value) + { + std::fill(Array + start, Array + Count, val); + } + else + { + for (unsigned i = 0; i < append_count; i++) + { + new(&Array[start + i]) T(val); + } + } + return start; + } + bool Pop () { if (Count > 0) diff --git a/source/common/utility/vectors.h b/source/common/utility/vectors.h index 140c310f0..6b82cc5cb 100644 --- a/source/common/utility/vectors.h +++ b/source/common/utility/vectors.h @@ -44,23 +44,32 @@ #include #include #include + +// this is needed to properly normalize angles. We cannot do that with compiler provided conversions because they differ too much #include "xs_Float.h" -#include "math/cmath.h" -#include "basics.h" -#include "cmdlib.h" - - -#define EQUAL_EPSILON (1/65536.) // make this a local inline function to avoid any dependencies on other headers and not pollute the global namespace namespace pi { inline constexpr double pi() { return 3.14159265358979323846; } - inline constexpr double pif() { return 3.14159265358979323846f; } + inline constexpr float pif() { return 3.14159265358979323846f; } } +// optionally use reliable math routines if reproducability across hardware is important, but let this still compile without them. +#if __has_include("math/cmath.h") +#include "math/cmath.h" +#else +double g_cosdeg(double v) { return cos(v * (pi::pi() / 180.)); } +double g_sindeg(double v) { return sin(v * (pi::pi() / 180.)); } +double g_cos(double v) { return cos(v); } +double g_sin(double v) { return sin(v); } +double g_sqrt(double v) { return sqrt(v); } +double g_atan2(double v, double w) { return atan2(v, w); } +#endif +#define EQUAL_EPSILON (1/65536.) + template struct TVector3; template struct TRotator; template struct TAngle; @@ -561,7 +570,7 @@ struct TVector3 void GetRightUp(TVector3 &right, TVector3 &up) { TVector3 n(X, Y, Z); - TVector3 fn(fabs(n.X), fabs(n.Y), fabs(n.Z)); + TVector3 fn((vec_t)fabs(n.X), (vec_t)fabs(n.Y), (vec_t)fabs(n.Z)); int major = 0; if (fn[1] > fn[major]) major = 1; @@ -1450,8 +1459,13 @@ public: double Tan() const { + // use an optimized approach if we have a sine table. If not just call the CRT's tan function. +#if __has_include("math/cmath.h") const auto bam = BAMs(); return g_sinbam(bam) / g_cosbam(bam); +#else + return vec_t(tan(Radians())); +#endif } // This is for calculating vertical velocity. For high pitches the tangent will become too large to be useful. @@ -1460,9 +1474,11 @@ public: return clamp(Tan(), -max, max); } + // returns sign of the NORMALIZED angle. int Sgn() const { - return ::Sgn(int(BAMs())); + auto val = int(BAMs()); + return (val > 0) - (val < 0); } }; @@ -1490,12 +1506,6 @@ inline TAngle absangle(const TAngle &a1, const TAngle &a2) return fabs(deltaangle(a2, a1)); } -template -inline TAngle clamp(const TAngle &angle, const TAngle &min, const TAngle &max) -{ - return TAngle::fromDeg(clamp(angle.Degrees(), min.Degrees(), max.Degrees())); -} - inline TAngle VecToAngle(double x, double y) { return TAngle::fromRad(g_atan2(y, x)); diff --git a/source/common/utility/weightedlist.h b/source/common/utility/weightedlist.h index cd6a4ba0e..fb956a462 100644 --- a/source/common/utility/weightedlist.h +++ b/source/common/utility/weightedlist.h @@ -31,6 +31,7 @@ **--------------------------------------------------------------------------- ** */ +#pragma once #include #include diff --git a/source/core/actorinfo.cpp b/source/core/actorinfo.cpp index 7e1b6e556..f42d4cbc9 100644 --- a/source/core/actorinfo.cpp +++ b/source/core/actorinfo.cpp @@ -34,6 +34,7 @@ */ +#include "vectors.h" #include "actorinfo.h" #include "c_dispatch.h" #include "d_net.h" diff --git a/source/core/gamefuncs.h b/source/core/gamefuncs.h index 23ce11f11..8b0190f5a 100644 --- a/source/core/gamefuncs.h +++ b/source/core/gamefuncs.h @@ -472,7 +472,7 @@ inline DAngle GetMaxPitch() return !cl_clampedpitch ? (minAngle - DAngle90) : gi->playerPitchMax(); } -inline DAngle ClampViewPitch(const DAngle pitch) +inline DAngle ClampViewPitch(const DAngle& pitch) { return clamp(pitch, GetMaxPitch(), GetMinPitch()); } diff --git a/source/core/raze_music.cpp b/source/core/raze_music.cpp index a27b4146f..43594c570 100644 --- a/source/core/raze_music.cpp +++ b/source/core/raze_music.cpp @@ -40,6 +40,7 @@ #include "filesystem.h" #include "files.h" #include "i_music.h" +#include "m_argv.h" #include "gamecontrol.h" #include "serializer.h" @@ -249,7 +250,7 @@ void Mus_UpdateMusic() void Mus_InitMusic() { - I_InitMusic(); + I_InitMusic(Args->CheckParm("-nomusic") || Args->CheckParm("-nosound")); static MusicCallbacks mus_cb = { LookupMusicCB,