From f6bfc48d9f8a20c99055a74fbe5454a18ee4d551 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 11 Feb 2023 12:05:45 +0100 Subject: [PATCH] - Backend update from Raze. --- src/common/audio/sound/i_sound.cpp | 2 +- src/common/audio/sound/i_sound.h | 2 +- src/common/audio/sound/oalsound.cpp | 13 +++++++++++-- src/common/audio/sound/oalsound.h | 2 +- src/common/audio/sound/s_sound.cpp | 4 ++-- src/common/audio/sound/s_soundinternal.h | 2 ++ src/common/fonts/font.cpp | 9 +++++++-- src/common/fonts/v_font.h | 2 ++ src/common/menu/menu.cpp | 6 ++++++ src/common/menu/menudef.cpp | 4 ++-- src/common/scripting/backend/codegen.cpp | 14 +++++++------- src/common/statusbar/base_sbar.cpp | 6 +++--- src/common/utility/i_time.cpp | 15 +++++---------- src/common/utility/i_time.h | 2 +- src/common/utility/vectors.h | 17 +++++++---------- src/rendering/r_utility.cpp | 2 +- 16 files changed, 59 insertions(+), 43 deletions(-) diff --git a/src/common/audio/sound/i_sound.cpp b/src/common/audio/sound/i_sound.cpp index 90fda4be29..5f9fdda189 100644 --- a/src/common/audio/sound/i_sound.cpp +++ b/src/common/audio/sound/i_sound.cpp @@ -131,7 +131,7 @@ public: void SetMusicVolume (float volume) { } - SoundHandle LoadSound(uint8_t *sfxdata, int length) + SoundHandle LoadSound(uint8_t *sfxdata, int length, int def_loop_start, int def_loop_end) { SoundHandle retval = { NULL }; return retval; diff --git a/src/common/audio/sound/i_sound.h b/src/common/audio/sound/i_sound.h index b2f281f29b..0805154946 100644 --- a/src/common/audio/sound/i_sound.h +++ b/src/common/audio/sound/i_sound.h @@ -105,7 +105,7 @@ public: virtual bool IsNull() { return false; } virtual void SetSfxVolume (float volume) = 0; virtual void SetMusicVolume (float volume) = 0; - virtual SoundHandle LoadSound(uint8_t *sfxdata, int length) = 0; + virtual SoundHandle LoadSound(uint8_t *sfxdata, int length, int def_loop_start, int def_loop_end) = 0; SoundHandle LoadSoundVoc(uint8_t *sfxdata, int length); virtual SoundHandle LoadSoundRaw(uint8_t *sfxdata, int length, int frequency, int channels, int bits, int loopstart, int loopend = -1) = 0; virtual void UnloadSound (SoundHandle sfx) = 0; // unloads a sound from memory diff --git a/src/common/audio/sound/oalsound.cpp b/src/common/audio/sound/oalsound.cpp index 81ec4cae73..6f6e4e3ee0 100644 --- a/src/common/audio/sound/oalsound.cpp +++ b/src/common/audio/sound/oalsound.cpp @@ -1096,7 +1096,7 @@ SoundHandle OpenALSoundRenderer::LoadSoundRaw(uint8_t *sfxdata, int length, int return retval; } -SoundHandle OpenALSoundRenderer::LoadSound(uint8_t *sfxdata, int length) +SoundHandle OpenALSoundRenderer::LoadSound(uint8_t *sfxdata, int length, int def_loop_start, int def_loop_end) { SoundHandle retval = { NULL }; ALenum format = AL_NONE; @@ -1106,7 +1106,16 @@ SoundHandle OpenALSoundRenderer::LoadSound(uint8_t *sfxdata, int length) uint32_t loop_start = 0, loop_end = ~0u; zmusic_bool startass = false, endass = false; - FindLoopTags(sfxdata, length, &loop_start, &startass, &loop_end, &endass); + if (def_loop_start < 0) + { + FindLoopTags(sfxdata, length, &loop_start, &startass, &loop_end, &endass); + } + else + { + loop_start = def_loop_start; + loop_end = def_loop_end; + startass = endass = true; + } auto decoder = CreateDecoder(sfxdata, length, true); if (!decoder) return retval; diff --git a/src/common/audio/sound/oalsound.h b/src/common/audio/sound/oalsound.h index 90cb8c8bd2..4b277bc25a 100644 --- a/src/common/audio/sound/oalsound.h +++ b/src/common/audio/sound/oalsound.h @@ -34,7 +34,7 @@ public: virtual void SetSfxVolume(float volume); virtual void SetMusicVolume(float volume); - virtual SoundHandle LoadSound(uint8_t *sfxdata, int length); + virtual SoundHandle LoadSound(uint8_t *sfxdata, int length, int def_loop_start, int def_loop_end); virtual SoundHandle LoadSoundRaw(uint8_t *sfxdata, int length, int frequency, int channels, int bits, int loopstart, int loopend = -1); virtual void UnloadSound(SoundHandle sfx); virtual unsigned int GetMSLength(SoundHandle sfx); diff --git a/src/common/audio/sound/s_sound.cpp b/src/common/audio/sound/s_sound.cpp index 11c598f043..f3b0fb4122 100644 --- a/src/common/audio/sound/s_sound.cpp +++ b/src/common/audio/sound/s_sound.cpp @@ -382,7 +382,7 @@ static float CalcPitch(int pitchmask, float defpitch, float defpitchmax) { if (defpitchmax > 0.0 && defpitch != defpitchmax) { - defpitch = pr_soundpitch.GenRand_Real1() * (defpitchmax - defpitch) + defpitch; + defpitch = (float)pr_soundpitch.GenRand_Real1() * (defpitchmax - defpitch) + defpitch; } return defpitch; } @@ -769,7 +769,7 @@ sfxinfo_t *SoundEngine::LoadSound(sfxinfo_t *sfx) // If that fails, let the sound system try and figure it out. else { - sfx->data = GSnd->LoadSound(sfxdata.Data(), size); + sfx->data = GSnd->LoadSound(sfxdata.Data(), size, sfx->LoopStart, sfx->LoopEnd); } } diff --git a/src/common/audio/sound/s_soundinternal.h b/src/common/audio/sound/s_soundinternal.h index b29081fda4..dae8a0ee29 100644 --- a/src/common/audio/sound/s_soundinternal.h +++ b/src/common/audio/sound/s_soundinternal.h @@ -97,11 +97,13 @@ constexpr FSoundID INVALID_SOUND = FSoundID::fromInt(-1); bool bUsed = false; bool bSingular = false; bool bTentative = true; + bool bExternal = false; TArray UserData; int RawRate = 0; // Sample rate to use when bLoadRAW is true int LoopStart = -1; // -1 means no specific loop defined + int LoopEnd = -1; // -1 means no specific loop defined FSoundID link = NO_LINK; constexpr static FSoundID NO_LINK = FSoundID::fromInt(-1); diff --git a/src/common/fonts/font.cpp b/src/common/fonts/font.cpp index 98763724f0..f78985b436 100644 --- a/src/common/fonts/font.cpp +++ b/src/common/fonts/font.cpp @@ -120,7 +120,7 @@ FFont::FFont (const char *name, const char *nametemplate, const char *filetempla sc.MustGetValue(false); GlobalKerning = sc.Number; } - if (sc.Compare("Altfont")) + else if (sc.Compare("Altfont")) { sc.MustGetString(); AltFontName = sc.String; @@ -179,6 +179,11 @@ FFont::FFont (const char *name, const char *nametemplate, const char *filetempla sc.ScriptError("Unknown translation type %s", sc.String); } } + else if (sc.Compare("lowercaselatinonly")) + { + lowercaselatinonly = true; + } + } } } @@ -755,7 +760,7 @@ int FFont::GetCharCode(int code, bool needpic) const // Use different substitution logic based on the fonts content: // In a font which has both upper and lower case, prefer unaccented small characters over capital ones. // In a pure upper-case font, do not check for lower case replacements. - if (!MixedCase) + if (!MixedCase || (lowercaselatinonly && code >= 0x380 && code < 0x500)) { // Try converting lowercase characters to uppercase. if (myislower(code)) diff --git a/src/common/fonts/v_font.h b/src/common/fonts/v_font.h index 343cbaf5dc..407ee0f5ed 100644 --- a/src/common/fonts/v_font.h +++ b/src/common/fonts/v_font.h @@ -167,6 +167,7 @@ public: forceremap = other.forceremap; Chars = other.Chars; Translations = other.Translations; + lowercaselatinonly = other.lowercaselatinonly; Lump = other.Lump; } @@ -189,6 +190,7 @@ protected: bool noTranslate = false; bool MixedCase = false; bool forceremap = false; + bool lowercaselatinonly = false; struct CharData { FGameTexture *OriginalPic = nullptr; diff --git a/src/common/menu/menu.cpp b/src/common/menu/menu.cpp index c5890080c2..67ed85a6ed 100644 --- a/src/common/menu/menu.cpp +++ b/src/common/menu/menu.cpp @@ -924,10 +924,16 @@ void M_Init (void) } catch (CVMAbortException &err) { + menuDelegate = nullptr; err.MaybePrintMessage(); Printf(PRINT_NONOTIFY | PRINT_BOLD, "%s", err.stacktrace.GetChars()); I_FatalError("Failed to initialize menus"); } + catch (...) + { + menuDelegate = nullptr; + throw; + } M_CreateMenus(); } diff --git a/src/common/menu/menudef.cpp b/src/common/menu/menudef.cpp index 7076f8b7b3..4fbeeb0bb6 100644 --- a/src/common/menu/menudef.cpp +++ b/src/common/menu/menudef.cpp @@ -150,13 +150,13 @@ void DeinitMenus() pair->Value = nullptr; } } - MenuDescriptors.Clear(); - OptionValues.Clear(); if (menuDelegate) { menuDelegate->Destroy(); menuDelegate = nullptr; } + MenuDescriptors.Clear(); + OptionValues.Clear(); } FTextureID GetMenuTexture(const char* const name) diff --git a/src/common/scripting/backend/codegen.cpp b/src/common/scripting/backend/codegen.cpp index cd41618379..02f03d6918 100644 --- a/src/common/scripting/backend/codegen.cpp +++ b/src/common/scripting/backend/codegen.cpp @@ -275,13 +275,13 @@ bool AreCompatiblePointerTypes(PType *dest, PType *source, bool forcompare) auto fromtype = source->toPointer(); auto totype = dest->toPointer(); // implicit pointer casts - if( fromtype->isClassPointer() && !totype->isClassPointer() ) totype->toClassPointer(fromtype); // just to make sure they're compatible pointer types - else if( !fromtype->isClassPointer() && totype->isClassPointer() ) fromtype->toClassPointer(totype); // just to make sure they're compatible pointer types - else if( fromtype->PointedType != totype->PointedType ) - { - auto res = fromtype->PointedType->toClass(totype->PointedType); - if(!res || res != totype->PointedType) return false; - } + if( fromtype->isClassPointer() && !totype->isClassPointer() ) totype->toClassPointer(fromtype); // just to make sure they're compatible pointer types + else if( !fromtype->isClassPointer() && totype->isClassPointer() ) fromtype->toClassPointer(totype); // just to make sure they're compatible pointer types + else if( fromtype->PointedType != totype->PointedType ) + { + auto res = fromtype->PointedType->toClass(totype->PointedType); + if(!res || res != totype->PointedType) return false; + } // null pointers can be assigned to everything, everything can be assigned to void pointers. if (fromtype == nullptr || totype == TypeVoidPtr) return true; // when comparing const-ness does not matter. diff --git a/src/common/statusbar/base_sbar.cpp b/src/common/statusbar/base_sbar.cpp index b1fb2d79aa..d7908233c4 100644 --- a/src/common/statusbar/base_sbar.cpp +++ b/src/common/statusbar/base_sbar.cpp @@ -368,7 +368,7 @@ void DStatusBarCore::SetScale() double screenaspect = w / double(h); double aspectscale = 1.0; - double ViewportAspect = ViewportPixelAspect(); + const double ViewportAspect = 1. / ViewportPixelAspect(); if ((horz == 320 && vert == 200) || (horz == 640 && vert == 400)) { @@ -387,9 +387,9 @@ void DStatusBarCore::SetScale() refw = h * refaspect; } refw *= hud_scalefactor; - refh *= hud_scalefactor * aspectscale / ViewportAspect; + refh *= hud_scalefactor * aspectscale * ViewportAspect; - int sby = vert - int(RelTop * hud_scalefactor * aspectscale / ViewportAspect); + int sby = vert - int(RelTop * hud_scalefactor * aspectscale * ViewportAspect); // Use full pixels for destination size. ST_X = xs_CRoundToInt((w - refw) / 2); diff --git a/src/common/utility/i_time.cpp b/src/common/utility/i_time.cpp index d9117d8ea3..b3312b89f5 100644 --- a/src/common/utility/i_time.cpp +++ b/src/common/utility/i_time.cpp @@ -210,17 +210,12 @@ void I_ResetFrameTime() FirstFrameStartTime += (CurrentFrameStartTime - ft); } -double I_GetInputFrac(bool const synchronised) +double I_GetInputFrac() { - if (!synchronised) - { - const double now = I_msTimeF(); - const double result = (now - lastinputtime) * GameTicRate * (1. / 1000.); - lastinputtime = now; - return result; - } - - return 1; + const double now = I_msTimeF(); + const double result = (now - lastinputtime) * GameTicRate * (1. / 1000.); + lastinputtime = now; + return result; } void I_ResetInputTime() diff --git a/src/common/utility/i_time.h b/src/common/utility/i_time.h index e5d3d5c8df..a77640fb5d 100644 --- a/src/common/utility/i_time.h +++ b/src/common/utility/i_time.h @@ -42,7 +42,7 @@ uint64_t I_nsTime(); void I_ResetFrameTime(); // Return a decimal fraction to scale input operations at framerate -double I_GetInputFrac(bool const synchronised); +double I_GetInputFrac(); // Reset the last input check to after a lengthy operation void I_ResetInputTime(); diff --git a/src/common/utility/vectors.h b/src/common/utility/vectors.h index 89c5a642d1..140c310f08 100644 --- a/src/common/utility/vectors.h +++ b/src/common/utility/vectors.h @@ -230,7 +230,7 @@ struct TVector2 // Vector length vec_t Length() const { - return (vec_t)g_sqrt (X*X + Y*Y); + return (vec_t)g_sqrt (LengthSquared()); } vec_t LengthSquared() const @@ -613,7 +613,7 @@ struct TVector3 // Vector length double Length() const { - return g_sqrt (X*X + Y*Y + Z*Z); + return g_sqrt (LengthSquared()); } double LengthSquared() const @@ -928,7 +928,7 @@ struct TVector4 // Vector length double Length() const { - return g_sqrt(X*X + Y*Y + Z*Z + W*W); + return g_sqrt(LengthSquared()); } double LengthSquared() const @@ -1450,7 +1450,7 @@ public: double Tan() const { - auto bam = BAMs(); + const auto bam = BAMs(); return g_sinbam(bam) / g_cosbam(bam); } @@ -1487,7 +1487,7 @@ inline TAngle deltaangle(const TAngle &a1, const TAngle &a2) template inline TAngle absangle(const TAngle &a1, const TAngle &a2) { - return fabs((a1 - a2).Normalized180()); + return fabs(deltaangle(a2, a1)); } template @@ -1528,7 +1528,7 @@ TAngle TVector3::Angle() const template TAngle TVector3::Pitch() const { - return -VecToAngle(TVector2(X, Y).Length(), Z); + return -VecToAngle(XY().Length(), Z); } template @@ -1694,13 +1694,10 @@ struct TRotator }; // Create a forward vector from a rotation (ignoring roll) - template inline TVector3::TVector3 (const TRotator &rot) { - double pcos = rot.Pitch.Cos(); - X = pcos * rot.Yaw.Cos(); - Y = pcos * rot.Yaw.Sin(); + XY() = rot.Pitch.Cos() * rot.Yaw.ToVector(); Z = rot.Pitch.Sin(); } diff --git a/src/rendering/r_utility.cpp b/src/rendering/r_utility.cpp index 1ce0df498e..6942236889 100644 --- a/src/rendering/r_utility.cpp +++ b/src/rendering/r_utility.cpp @@ -843,7 +843,7 @@ void R_SetupFrame (FRenderViewpoint &viewpoint, FViewWindow &viewwindow, AActor } // [MR] Get the input fraction, even if we don't need it this frame. Must run every frame. - const auto scaleAdjust = I_GetInputFrac(false); + const auto scaleAdjust = I_GetInputFrac(); // [MR] Process player angle changes if permitted to do so. if (player && (player->cheats & CF_SCALEDNOLERP) && P_NoInterpolation(player, viewpoint.camera))