From 8c5eb2c8075509064f96988b78df2feb1c4c9696 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 9 Nov 2023 19:20:04 +0100 Subject: [PATCH] use FTranslationID in all places where strict type checking is needed. This means all properties in serializable classes now use this wrapper type. The backend hasn't been changed yet --- src/am_map.cpp | 8 +-- src/common/engine/i_interface.h | 1 + src/common/engine/palettecontainer.cpp | 15 ++-- src/common/engine/palettecontainer.h | 70 +++++++++++++++---- src/common/fonts/font.cpp | 2 +- src/common/fonts/hexfont.cpp | 4 +- src/common/fonts/singlelumpfont.cpp | 2 +- src/common/fonts/specialfont.cpp | 2 +- src/common/scripting/backend/codegen.cpp | 2 +- src/common/scripting/backend/codegen.h | 8 +++ src/common/scripting/interface/vmnatives.cpp | 6 +- src/common/statusbar/base_sbar.cpp | 13 ++-- src/common/statusbar/base_sbar.h | 4 +- src/g_statusbar/sbar.h | 2 +- src/g_statusbar/sbarinfo.cpp | 15 ++-- src/g_statusbar/shared_sbar.cpp | 2 +- src/gamedata/d_dehacked.cpp | 13 ++-- src/gamedata/decallib.cpp | 6 +- src/gamedata/decallib.h | 5 +- src/intermission/intermission.cpp | 6 +- src/intermission/intermission.h | 2 +- src/playsim/a_decals.cpp | 25 ++----- src/playsim/a_sharedglobal.h | 12 ++-- src/playsim/actor.h | 4 +- src/playsim/p_lnspec.cpp | 8 +-- src/playsim/p_map.cpp | 4 +- src/playsim/p_mobj.cpp | 4 +- src/playsim/p_pspr.cpp | 8 +-- src/playsim/p_pspr.h | 5 +- src/r_data/models.cpp | 6 +- src/r_data/r_translate.cpp | 32 ++++----- src/r_data/r_translate.h | 4 +- src/rendering/hwrenderer/hw_precache.cpp | 2 +- src/rendering/hwrenderer/scene/hw_decal.cpp | 2 +- src/rendering/hwrenderer/scene/hw_sprites.cpp | 2 +- src/rendering/hwrenderer/scene/hw_weapon.cpp | 4 +- src/rendering/swrenderer/things/r_decal.cpp | 2 +- .../swrenderer/things/r_playersprite.cpp | 4 +- src/rendering/swrenderer/things/r_sprite.cpp | 2 +- src/rendering/swrenderer/things/r_voxel.cpp | 2 +- .../swrenderer/things/r_wallsprite.cpp | 2 +- src/scripting/thingdef_properties.cpp | 6 +- 42 files changed, 189 insertions(+), 139 deletions(-) diff --git a/src/am_map.cpp b/src/am_map.cpp index bf0c61b7d5..938540d961 100644 --- a/src/am_map.cpp +++ b/src/am_map.cpp @@ -996,7 +996,7 @@ class DAutomap :public DAutomapBase void calcMinMaxMtoF(); void DrawMarker(FGameTexture *tex, double x, double y, int yadjust, - INTBOOL flip, double xscale, double yscale, int translation, double alpha, uint32_t fillcolor, FRenderStyle renderstyle); + INTBOOL flip, double xscale, double yscale, FTranslationID translation, double alpha, uint32_t fillcolor, FRenderStyle renderstyle); void rotatePoint(double *x, double *y); void rotate(double *x, double *y, DAngle an); @@ -3074,7 +3074,7 @@ void DAutomap::drawThings () //============================================================================= void DAutomap::DrawMarker (FGameTexture *tex, double x, double y, int yadjust, - INTBOOL flip, double xscale, double yscale, int translation, double alpha, uint32_t fillcolor, FRenderStyle renderstyle) + INTBOOL flip, double xscale, double yscale, FTranslationID translation, double alpha, uint32_t fillcolor, FRenderStyle renderstyle) { if (tex == nullptr || !tex->isValid()) { @@ -3097,7 +3097,7 @@ void DAutomap::DrawMarker (FGameTexture *tex, double x, double y, int yadjust, DTA_ClipLeft, f_x, DTA_ClipRight, f_x + f_w, DTA_FlipX, flip, - DTA_TranslationIndex, translation, + DTA_TranslationIndex, translation.index(), DTA_Alpha, alpha, DTA_FillColor, fillcolor, DTA_RenderStyle, renderstyle.AsDWORD, @@ -3128,7 +3128,7 @@ void DAutomap::drawMarks () if (font == nullptr) { DrawMarker(TexMan.GetGameTexture(marknums[i], true), markpoints[i].x, markpoints[i].y, -3, 0, - 1, 1, 0, 1, 0, LegacyRenderStyles[STYLE_Normal]); + 1, 1, NO_TRANSLATION, 1, 0, LegacyRenderStyles[STYLE_Normal]); } else { diff --git a/src/common/engine/i_interface.h b/src/common/engine/i_interface.h index bdc05198ed..6679184dec 100644 --- a/src/common/engine/i_interface.h +++ b/src/common/engine/i_interface.h @@ -10,6 +10,7 @@ class FGameTexture; class FTextureID; enum EUpscaleFlags : int; class FConfigFile; +struct FTranslationID; struct SystemCallbacks { diff --git a/src/common/engine/palettecontainer.cpp b/src/common/engine/palettecontainer.cpp index 800dc31c65..23d26f88fc 100644 --- a/src/common/engine/palettecontainer.cpp +++ b/src/common/engine/palettecontainer.cpp @@ -220,7 +220,7 @@ FRemapTable* PaletteContainer::AddRemap(FRemapTable* remap) // //---------------------------------------------------------------------------- -void PaletteContainer::UpdateTranslation(int trans, FRemapTable* remap) +void PaletteContainer::UpdateTranslation(FTranslationID trans, FRemapTable* remap) { auto newremap = AddRemap(remap); TranslationTables[GetTranslationType(trans)].SetVal(GetTranslationIndex(trans), newremap); @@ -232,7 +232,7 @@ void PaletteContainer::UpdateTranslation(int trans, FRemapTable* remap) // //---------------------------------------------------------------------------- -int PaletteContainer::AddTranslation(int slot, FRemapTable* remap, int count) +FTranslationID PaletteContainer::AddTranslation(int slot, FRemapTable* remap, int count) { uint32_t id = 0; for (int i = 0; i < count; i++) @@ -249,9 +249,9 @@ int PaletteContainer::AddTranslation(int slot, FRemapTable* remap, int count) // //---------------------------------------------------------------------------- -void PaletteContainer::CopyTranslation(int dest, int src) +void PaletteContainer::CopyTranslation(FTranslationID dest, FTranslationID src) { - TranslationTables[GetTranslationType(dest)].SetVal(GetTranslationIndex(dest), TranslationToTable(src)); + TranslationTables[GetTranslationType(dest)].SetVal(GetTranslationIndex(dest), TranslationToTable(src.index())); } //---------------------------------------------------------------------------- @@ -260,8 +260,9 @@ void PaletteContainer::CopyTranslation(int dest, int src) // //---------------------------------------------------------------------------- -FRemapTable *PaletteContainer::TranslationToTable(int translation) +FRemapTable *PaletteContainer::TranslationToTable(int translation) const { + if (IsLuminosityTranslation(translation)) return nullptr; unsigned int type = GetTranslationType(translation); unsigned int index = GetTranslationIndex(translation); @@ -278,14 +279,14 @@ FRemapTable *PaletteContainer::TranslationToTable(int translation) // //---------------------------------------------------------------------------- -int PaletteContainer::StoreTranslation(int slot, FRemapTable *remap) +FTranslationID PaletteContainer::StoreTranslation(int slot, FRemapTable *remap) { unsigned int i; auto size = NumTranslations(slot); for (i = 0; i < size; i++) { - if (*remap == *TranslationToTable(TRANSLATION(slot, i))) + if (*remap == *TranslationToTable(TRANSLATION(slot, i).index())) { // A duplicate of this translation already exists return TRANSLATION(slot, i); diff --git a/src/common/engine/palettecontainer.h b/src/common/engine/palettecontainer.h index 96413fe1f6..b7869e2763 100644 --- a/src/common/engine/palettecontainer.h +++ b/src/common/engine/palettecontainer.h @@ -43,6 +43,8 @@ private: }; + +// outside facing translation ID struct FTranslationID { public: @@ -67,21 +69,22 @@ public: { return ID == other.ID; } - bool operator ==(int other) const = delete; - bool operator !=(int other) const = delete; constexpr int index() const { return ID; } constexpr bool isvalid() const { - return ID > 0; + return ID >= 0; } private: int ID; }; +constexpr FTranslationID NO_TRANSLATION = FTranslationID::fromInt(0); +constexpr FTranslationID INVALID_TRANSLATION = FTranslationID::fromInt(-1); + // A class that initializes unusued pointers to NULL. This is used so that when // the TAutoGrowArray below is expanded, the new elements will be NULLed. class FRemapTablePtr @@ -107,28 +110,45 @@ enum TRANSLATIONTYPE_MASK = (255 << TRANSLATION_SHIFT) }; -inline constexpr uint32_t TRANSLATION(uint8_t a, uint32_t b) +inline constexpr FTranslationID TRANSLATION(uint8_t a, uint32_t b) { - return (a << TRANSLATION_SHIFT) | b; + return FTranslationID::fromInt((a << TRANSLATION_SHIFT) | b); } -inline constexpr uint32_t LuminosityTranslation(int range, uint8_t min, uint8_t max) +inline constexpr int MakeLuminosityTranslation(int range, uint8_t min, uint8_t max) { // ensure that the value remains positive. return ( (1 << 30) | ((range&0x3fff) << 16) | (min << 8) | max ); } +inline constexpr bool IsLuminosityTranslation(FTranslationID trans) +{ + return trans.index() > 0 && (trans.index() & (1 << 30)); +} + inline constexpr bool IsLuminosityTranslation(int trans) { return trans > 0 && (trans & (1 << 30)); } -inline constexpr int GetTranslationType(uint32_t trans) +inline constexpr int GetTranslationType(FTranslationID trans) +{ + assert(!IsLuminosityTranslation(trans)); + return (trans.index() & TRANSLATIONTYPE_MASK) >> TRANSLATION_SHIFT; +} + +inline constexpr int GetTranslationIndex(FTranslationID trans) +{ + assert(!IsLuminosityTranslation(trans)); + return (trans.index() & TRANSLATION_MASK); +} + +inline constexpr int GetTranslationType(int trans) { assert(!IsLuminosityTranslation(trans)); return (trans & TRANSLATIONTYPE_MASK) >> TRANSLATION_SHIFT; } -inline constexpr int GetTranslationIndex(uint32_t trans) +inline constexpr int GetTranslationIndex(int trans) { assert(!IsLuminosityTranslation(trans)); return (trans & TRANSLATION_MASK); @@ -162,11 +182,11 @@ public: void Clear(); int DetermineTranslucency(FileReader& file); FRemapTable* AddRemap(FRemapTable* remap); - void UpdateTranslation(int trans, FRemapTable* remap); - int AddTranslation(int slot, FRemapTable* remap, int count = 1); - void CopyTranslation(int dest, int src); - int StoreTranslation(int slot, FRemapTable* remap); - FRemapTable* TranslationToTable(int translation); + void UpdateTranslation(FTranslationID trans, FRemapTable* remap); + FTranslationID AddTranslation(int slot, FRemapTable* remap, int count = 1); + void CopyTranslation(FTranslationID dest, FTranslationID src); + FTranslationID StoreTranslation(int slot, FRemapTable* remap); + FRemapTable* TranslationToTable(int translation) const; void GenerateGlobalBrightmapFromColormap(const uint8_t* cmapdata, int numlevels); void PushIdentityTable(int slot) @@ -174,7 +194,7 @@ public: AddTranslation(slot, nullptr); } - FRemapTable* GetTranslation(int slot, int index) + FRemapTable* GetTranslation(int slot, int index) const { if (TranslationTables.Size() <= (unsigned)slot) return nullptr; return TranslationTables[slot].GetVal(index); @@ -192,6 +212,28 @@ public: return TranslationTables[slot].Size(); } + +}; + +struct LuminosityTranslationDesc +{ + int colorrange; + int lum_min; + int lum_max; + + static LuminosityTranslationDesc fromInt(int translation) + { + LuminosityTranslationDesc t; + t.colorrange = (translation >> 16) & 0x3fff; + t.lum_min = (translation >> 8) & 0xff; + t.lum_max = translation & 0xff; + return t; + } + + static LuminosityTranslationDesc fromID(FTranslationID translation) + { + return fromInt(translation.index()); + } }; extern PaletteContainer GPalette; diff --git a/src/common/fonts/font.cpp b/src/common/fonts/font.cpp index c12d254b1e..c622eab3be 100644 --- a/src/common/fonts/font.cpp +++ b/src/common/fonts/font.cpp @@ -1060,7 +1060,7 @@ void FFont::LoadTranslations() for (int i = 0; i < NumTextColors; i++) { if (i == CR_UNTRANSLATED) Translations[i] = 0; - else Translations[i] = LuminosityTranslation(i*2 + TranslationType, minlum, maxlum); + else Translations[i] = MakeLuminosityTranslation(i*2 + TranslationType, minlum, maxlum); } } diff --git a/src/common/fonts/hexfont.cpp b/src/common/fonts/hexfont.cpp index 3ec2816e6a..d72c50e8a1 100644 --- a/src/common/fonts/hexfont.cpp +++ b/src/common/fonts/hexfont.cpp @@ -324,7 +324,7 @@ public: for (int i = 0; i < NumTextColors; i++) { if (i == CR_UNTRANSLATED) Translations[i] = 0; - else Translations[i] = LuminosityTranslation(i * 2 + 1, minlum, maxlum); + else Translations[i] = MakeLuminosityTranslation(i * 2 + 1, minlum, maxlum); } } @@ -388,7 +388,7 @@ public: for (int i = 0; i < NumTextColors; i++) { if (i == CR_UNTRANSLATED) Translations[i] = 0; - else Translations[i] = LuminosityTranslation(i * 2, minlum, maxlum); + else Translations[i] = MakeLuminosityTranslation(i * 2, minlum, maxlum); } } }; diff --git a/src/common/fonts/singlelumpfont.cpp b/src/common/fonts/singlelumpfont.cpp index b40a86bff4..ca40519da8 100644 --- a/src/common/fonts/singlelumpfont.cpp +++ b/src/common/fonts/singlelumpfont.cpp @@ -195,7 +195,7 @@ void FSingleLumpFont::LoadTranslations() for (int i = 0; i < NumTextColors; i++) { if (i == CR_UNTRANSLATED) Translations[i] = 0; - else Translations[i] = LuminosityTranslation(i * 2 + (FontType == FONT1 ? 1 : 0), minlum, maxlum); + else Translations[i] = MakeLuminosityTranslation(i * 2 + (FontType == FONT1 ? 1 : 0), minlum, maxlum); } } diff --git a/src/common/fonts/specialfont.cpp b/src/common/fonts/specialfont.cpp index 9c35f2a8a0..6547778c09 100644 --- a/src/common/fonts/specialfont.cpp +++ b/src/common/fonts/specialfont.cpp @@ -196,7 +196,7 @@ void FSpecialFont::LoadTranslations() remap.Remap[i] = i; } } - trans = GPalette.StoreTranslation(TRANSLATION_Internal, &remap); + trans = GPalette.StoreTranslation(TRANSLATION_Internal, &remap).index(); } } diff --git a/src/common/scripting/backend/codegen.cpp b/src/common/scripting/backend/codegen.cpp index 7f3a410ca5..da487fad85 100644 --- a/src/common/scripting/backend/codegen.cpp +++ b/src/common/scripting/backend/codegen.cpp @@ -49,7 +49,7 @@ extern FRandom pr_exrandom; FMemArena FxAlloc(65536); CompileEnvironment compileEnvironment; -int R_FindCustomTranslation(FName name); +FTranslationID R_FindCustomTranslation(FName name); struct FLOP { diff --git a/src/common/scripting/backend/codegen.h b/src/common/scripting/backend/codegen.h index e1ad37856f..3f73a09c52 100644 --- a/src/common/scripting/backend/codegen.h +++ b/src/common/scripting/backend/codegen.h @@ -48,6 +48,7 @@ #include "types.h" #include "vmintern.h" #include "c_cvars.h" +#include "palettecontainer.h" struct FState; // needed for FxConstant. Maybe move the state constructor to a subclass later? @@ -508,6 +509,13 @@ public: isresolved = true; } + FxConstant(FTranslationID state, const FScriptPosition& pos) : FxExpression(EFX_Constant, pos) + { + value.Int = state.index(); + ValueType = value.Type = TypeTranslationID; + isresolved = true; + } + FxConstant(VMFunction* state, const FScriptPosition& pos) : FxExpression(EFX_Constant, pos) { value.pointer = state; diff --git a/src/common/scripting/interface/vmnatives.cpp b/src/common/scripting/interface/vmnatives.cpp index 6242d556b4..317ae6bfdf 100644 --- a/src/common/scripting/interface/vmnatives.cpp +++ b/src/common/scripting/interface/vmnatives.cpp @@ -1372,16 +1372,16 @@ DEFINE_ACTION_FUNCTION_NATIVE(DObject, FindFunction, FindFunctionPointer) ACTION_RETURN_POINTER(FindFunctionPointer(cls, fn.GetIndex())); } -int R_FindCustomTranslation(FName name); +FTranslationID R_FindCustomTranslation(FName name); static int ZFindTranslation(int intname) { - return R_FindCustomTranslation(ENamedName(intname)); + return R_FindCustomTranslation(ENamedName(intname)).index(); } static int MakeTransID(int g, int s) { - return TRANSLATION(g, s); + return TRANSLATION(g, s).index(); } DEFINE_ACTION_FUNCTION_NATIVE(_Translation, GetID, ZFindTranslation) diff --git a/src/common/statusbar/base_sbar.cpp b/src/common/statusbar/base_sbar.cpp index d7908233c4..51950e8b29 100644 --- a/src/common/statusbar/base_sbar.cpp +++ b/src/common/statusbar/base_sbar.cpp @@ -601,7 +601,7 @@ void DStatusBarCore::DrawGraphic(FGameTexture* tex, double x, double y, int flag DTA_ClipBottom, twod->GetHeight(), DTA_ClipRight, clipwidth < 0? twod->GetWidth() : int(x + boxwidth * clipwidth), DTA_Color, color, - DTA_TranslationIndex, translation? translation : (flags & DI_TRANSLATABLE) ? GetTranslation() : 0, + DTA_TranslationIndex, translation? translation : (flags & DI_TRANSLATABLE) ? GetTranslation().index() : 0, DTA_ColorOverlay, (flags & DI_DIM) ? MAKEARGB(170, 0, 0, 0) : 0, DTA_Alpha, Alpha, DTA_AlphaChannel, !!(flags & DI_ALPHAMAPPED), @@ -686,7 +686,7 @@ void DStatusBarCore::DrawRotated(FGameTexture* tex, double x, double y, int flag DTA_Color, color, DTA_CenterOffsetRel, !!(flags & DI_ITEM_RELCENTER), DTA_Rotate, angle, - DTA_TranslationIndex, translation ? translation : (flags & DI_TRANSLATABLE) ? GetTranslation() : 0, + DTA_TranslationIndex, translation ? translation : (flags & DI_TRANSLATABLE) ? GetTranslation().index() : 0, DTA_ColorOverlay, (flags & DI_DIM) ? MAKEARGB(170, 0, 0, 0) : 0, DTA_Alpha, Alpha, DTA_AlphaChannel, !!(flags & DI_ALPHAMAPPED), @@ -704,7 +704,7 @@ void DStatusBarCore::DrawRotated(FGameTexture* tex, double x, double y, int flag // //============================================================================ -void DStatusBarCore::DrawString(FFont* font, const FString& cstring, double x, double y, int flags, double Alpha, int translation, int spacing, EMonospacing monospacing, int shadowX, int shadowY, double scaleX, double scaleY, int pt, int style) +void DStatusBarCore::DrawString(FFont* font, const FString& cstring, double x, double y, int flags, double Alpha, int translation, int spacing, EMonospacing monospacing, int shadowX, int shadowY, double scaleX, double scaleY, FTranslationID pt, int style) { bool monospaced = monospacing != EMonospacing::Off; double dx = 0; @@ -823,11 +823,11 @@ void DStatusBarCore::DrawString(FFont* font, const FString& cstring, double x, d DTA_FillColor, 0, TAG_DONE); } - DrawChar(twod, font, pt == 0? fontcolor : CR_NATIVEPAL, rx, ry, ch, + DrawChar(twod, font, pt == NO_TRANSLATION? fontcolor : CR_NATIVEPAL, rx, ry, ch, DTA_DestWidthF, rw, DTA_DestHeightF, rh, DTA_Alpha, Alpha, - DTA_TranslationIndex, pt, + DTA_TranslationIndex, pt.index(), DTA_LegacyRenderStyle, ERenderStyle(style), TAG_DONE); @@ -840,10 +840,11 @@ void DStatusBarCore::DrawString(FFont* font, const FString& cstring, double x, d } } -void SBar_DrawString(DStatusBarCore* self, DHUDFont* font, const FString& string, double x, double y, int flags, int trans, double alpha, int wrapwidth, int linespacing, double scaleX, double scaleY, int pt, int style) +void SBar_DrawString(DStatusBarCore* self, DHUDFont* font, const FString& string, double x, double y, int flags, int trans, double alpha, int wrapwidth, int linespacing, double scaleX, double scaleY, int pt_, int style) { if (font == nullptr || font->mFont == nullptr) ThrowAbortException(X_READ_NIL, nullptr); if (!twod->HasBegun2D()) ThrowAbortException(X_OTHER, "Attempt to draw to screen outside a draw function"); + auto pt = FTranslationID::fromInt(pt_); // resolve auto-alignment before making any adjustments to the position values. if (!(flags & DI_SCREEN_MANUAL_ALIGN)) diff --git a/src/common/statusbar/base_sbar.h b/src/common/statusbar/base_sbar.h index f095ab80d2..444e5257a1 100644 --- a/src/common/statusbar/base_sbar.h +++ b/src/common/statusbar/base_sbar.h @@ -179,7 +179,7 @@ public: void BeginHUD(int resW, int resH, double Alpha, bool forceScaled = false); void SetSize(int reltop = 32, int hres = 320, int vres = 200, int hhres = -1, int hvres = -1); virtual DVector2 GetHUDScale() const; - virtual uint32_t GetTranslation() const { return 0; } + virtual FTranslationID GetTranslation() const { return NO_TRANSLATION; } void SetDrawSize(int reltop, int hres, int vres); virtual void SetScale(); void ValidateResolution(int& hres, int& vres) const; @@ -188,7 +188,7 @@ public: void DrawGraphic(FTextureID texture, double x, double y, int flags, double Alpha, double boxwidth, double boxheight, double scaleX, double scaleY, ERenderStyle style = STYLE_Translucent, PalEntry color = 0xffffffff, int translation = 0, double clipwidth = -1.0); void DrawRotated(FTextureID texture, double x, double y, int flags, double angle, double Alpha, double scaleX, double scaleY, PalEntry color = 0xffffffff, int translation = 0, ERenderStyle style = STYLE_Translucent); void DrawRotated(FGameTexture* tex, double x, double y, int flags, double angle, double Alpha, double scaleX, double scaleY, PalEntry color = 0xffffffff, int translation = 0, ERenderStyle style = STYLE_Translucent); - void DrawString(FFont* font, const FString& cstring, double x, double y, int flags, double Alpha, int translation, int spacing, EMonospacing monospacing, int shadowX, int shadowY, double scaleX, double scaleY, int pt, int style); + void DrawString(FFont* font, const FString& cstring, double x, double y, int flags, double Alpha, int translation, int spacing, EMonospacing monospacing, int shadowX, int shadowY, double scaleX, double scaleY, FTranslationID pt, int style); void TransformRect(double& x, double& y, double& w, double& h, int flags = 0); void Fill(PalEntry color, double x, double y, double w, double h, int flags = 0); void SetClipRect(double x, double y, double w, double h, int flags = 0); diff --git a/src/g_statusbar/sbar.h b/src/g_statusbar/sbar.h index b19a29245c..a1fa6926c9 100644 --- a/src/g_statusbar/sbar.h +++ b/src/g_statusbar/sbar.h @@ -402,7 +402,7 @@ public: virtual bool MustDrawLog(EHudState state); virtual void SetMugShotState (const char *state_name, bool wait_till_done=false, bool reset=false); void DrawLog(); - uint32_t GetTranslation() const override; + FTranslationID GetTranslation() const override; void CreateAltHUD(); void DrawAltHUD(); diff --git a/src/g_statusbar/sbarinfo.cpp b/src/g_statusbar/sbarinfo.cpp index dd864a550d..1d855cc232 100644 --- a/src/g_statusbar/sbarinfo.cpp +++ b/src/g_statusbar/sbarinfo.cpp @@ -1247,7 +1247,7 @@ public: DTA_ClipTop, static_cast(dcy), DTA_ClipRight, static_cast(min(INT_MAX, dcr)), DTA_ClipBottom, static_cast(min(INT_MAX, dcb)), - DTA_TranslationIndex, translate ? GetTranslation() : 0, + DTA_TranslationIndex, GetTranslationIndex(translate), DTA_ColorOverlay, dim ? DIM_OVERLAY : 0, DTA_CenterBottomOffset, (offsetflags & SBarInfoCommand::CENTER_BOTTOM) == SBarInfoCommand::CENTER_BOTTOM, DTA_Alpha, Alpha, @@ -1264,7 +1264,7 @@ public: DTA_ClipTop, static_cast(dcy), DTA_ClipRight, static_cast(min(INT_MAX, dcr)), DTA_ClipBottom, static_cast(min(INT_MAX, dcb)), - DTA_TranslationIndex, translate ? GetTranslation() : 0, + DTA_TranslationIndex, GetTranslationIndex(translate), DTA_ColorOverlay, dim ? DIM_OVERLAY : 0, DTA_CenterBottomOffset, (offsetflags & SBarInfoCommand::CENTER_BOTTOM) == SBarInfoCommand::CENTER_BOTTOM, DTA_Alpha, Alpha, @@ -1319,7 +1319,7 @@ public: DTA_ClipTop, static_cast(rcy), DTA_ClipRight, static_cast(rcr), DTA_ClipBottom, static_cast(rcb), - DTA_TranslationIndex, translate ? GetTranslation() : 0, + DTA_TranslationIndex, GetTranslationIndex(translate), DTA_ColorOverlay, dim ? DIM_OVERLAY : 0, DTA_CenterBottomOffset, (offsetflags & SBarInfoCommand::CENTER_BOTTOM) == SBarInfoCommand::CENTER_BOTTOM, DTA_Alpha, Alpha, @@ -1336,7 +1336,7 @@ public: DTA_ClipTop, static_cast(rcy), DTA_ClipRight, static_cast(rcr), DTA_ClipBottom, static_cast(rcb), - DTA_TranslationIndex, translate ? GetTranslation() : 0, + DTA_TranslationIndex, GetTranslationIndex(translate), DTA_ColorOverlay, dim ? DIM_OVERLAY : 0, DTA_CenterBottomOffset, (offsetflags & SBarInfoCommand::CENTER_BOTTOM) == SBarInfoCommand::CENTER_BOTTOM, DTA_Alpha, Alpha, @@ -1467,13 +1467,18 @@ public: } } - uint32_t GetTranslation() const + FTranslationID GetTranslation() const { if(gameinfo.gametype & GAME_Raven) return TRANSLATION(TRANSLATION_PlayersExtra, int(CPlayer - players)); return TRANSLATION(TRANSLATION_Players, int(CPlayer - players)); } + int GetTranslationIndex(bool translate) const + { + return translate? GetTranslation().index() : 0; + } + PClassActor *AmmoType(int no) const { auto w = StatusBar->CPlayer->ReadyWeapon; diff --git a/src/g_statusbar/shared_sbar.cpp b/src/g_statusbar/shared_sbar.cpp index ce3dc84a37..47b4e0f2c5 100644 --- a/src/g_statusbar/shared_sbar.cpp +++ b/src/g_statusbar/shared_sbar.cpp @@ -1376,7 +1376,7 @@ AActor *DBaseStatusBar::ValidateInvFirst (int numVisible) const return nullptr; } -uint32_t DBaseStatusBar::GetTranslation() const +FTranslationID DBaseStatusBar::GetTranslation() const { if (gameinfo.gametype & GAME_Raven) return TRANSLATION(TRANSLATION_PlayersExtra, int(CPlayer - players)); diff --git a/src/gamedata/d_dehacked.cpp b/src/gamedata/d_dehacked.cpp index 79d663505c..b7d970e00f 100644 --- a/src/gamedata/d_dehacked.cpp +++ b/src/gamedata/d_dehacked.cpp @@ -1390,7 +1390,7 @@ static int PatchThing (int thingy) if (val > 8 || val < 0) val = 0; unsigned color = bloodcolor[val]; info->BloodColor = color; - info->BloodTranslation = val == 0? 0 : TRANSLATION(TRANSLATION_Blood, CreateBloodTranslation(color)); + info->BloodTranslation = val == 0? NO_TRANSLATION : CreateBloodTranslation(color); } else if (linelen == 10 && stricmp(Line1, "MBF21 Bits") == 0) { @@ -3966,10 +3966,9 @@ bool CheckTranslucent(AActor* a) return !(a->renderflags & RF_ZDOOMTRANS) && a->Alpha < 1 - FLT_EPSILON; } -constexpr int t0 = 0; -constexpr int t1 = TRANSLATION(TRANSLATION_Standard, 0); -constexpr int t2 = TRANSLATION(TRANSLATION_Standard, 1); -constexpr int t3 = TRANSLATION(TRANSLATION_Standard, 2); +constexpr FTranslationID t1 = TRANSLATION(TRANSLATION_Standard, 0); +constexpr FTranslationID t2 = TRANSLATION(TRANSLATION_Standard, 1); +constexpr FTranslationID t3 = TRANSLATION(TRANSLATION_Standard, 2); void SetTranslation1(AActor* a) { @@ -3980,7 +3979,7 @@ void SetTranslation1(AActor* a) void ClearTranslation1(AActor* a) { if (a->Translation == t3 || a->Translation == t2) a->Translation = t2; - else a->Translation = t0; + else a->Translation = NO_TRANSLATION; } bool CheckTranslation1(AActor* a) @@ -3997,7 +3996,7 @@ void SetTranslation2(AActor* a) void ClearTranslation2(AActor* a) { if (a->Translation == t3 || a->Translation == t1) a->Translation = t1; - else a->Translation = t0; + else a->Translation = NO_TRANSLATION; } bool CheckTranslation2(AActor* a) diff --git a/src/gamedata/decallib.cpp b/src/gamedata/decallib.cpp index 06ba2c83f8..8dee4e7fd4 100644 --- a/src/gamedata/decallib.cpp +++ b/src/gamedata/decallib.cpp @@ -92,7 +92,7 @@ struct FDecalLib::FTranslation uint32_t StartColor, EndColor; FTranslation *Next; - uint32_t Index; + FTranslationID Index; }; struct FDecalAnimator @@ -1002,7 +1002,7 @@ FDecalLib::FTranslation::FTranslation (uint32_t start, uint32_t end) if (DecalTranslations.Size() == 256*256) { Printf ("Too many decal translations defined\n"); - Index = 0; + Index = NO_TRANSLATION; return; } @@ -1028,7 +1028,7 @@ FDecalLib::FTranslation::FTranslation (uint32_t start, uint32_t end) table[i] = ColorMatcher.Pick (ri >> 24, gi >> 24, bi >> 24); } table[0] = table[1]; - Index = (uint32_t)TRANSLATION(TRANSLATION_Decals, tablei >> 8); + Index = TRANSLATION(TRANSLATION_Decals, tablei >> 8); } FDecalLib::FTranslation *FDecalLib::FTranslation::LocateTranslation (uint32_t start, uint32_t end) diff --git a/src/gamedata/decallib.h b/src/gamedata/decallib.h index 3a6ede299a..d077c6c460 100644 --- a/src/gamedata/decallib.h +++ b/src/gamedata/decallib.h @@ -38,6 +38,7 @@ #include "doomtype.h" #include "renderstyle.h" +#include "palettecontainer.h" class FScanner; class FDecalTemplate; @@ -67,7 +68,7 @@ class FDecalTemplate : public FDecalBase { friend class FDecalLib; public: - FDecalTemplate () : Translation (0) {} + FDecalTemplate () : Translation (NO_TRANSLATION) {} void ApplyToDecal (DBaseDecal *actor, side_t *wall) const; const FDecalTemplate *GetDecal () const; @@ -75,7 +76,7 @@ public: double ScaleX, ScaleY; uint32_t ShadeColor; - uint32_t Translation; + FTranslationID Translation; FRenderStyle RenderStyle; FTextureID PicNum; uint16_t RenderFlags; diff --git a/src/intermission/intermission.cpp b/src/intermission/intermission.cpp index 8b5135b99f..004f4cfd92 100644 --- a/src/intermission/intermission.cpp +++ b/src/intermission/intermission.cpp @@ -514,8 +514,8 @@ void DIntermissionScreenCast::Init(FIntermissionAction *desc, bool first) else { advplayerstate = NULL; - casttranslation = 0; - if (mDefaults->Translation != 0) + casttranslation = NO_TRANSLATION; + if (mDefaults->Translation != NO_TRANSLATION) { casttranslation = mDefaults->Translation; } @@ -707,7 +707,7 @@ void DIntermissionScreenCast::Drawer () DTA_DestWidthF, pic->GetDisplayWidth() * castscale.X, DTA_RenderStyle, mDefaults->RenderStyle, DTA_Alpha, mDefaults->Alpha, - DTA_TranslationIndex, casttranslation, + DTA_TranslationIndex, casttranslation.index(), TAG_DONE); } } diff --git a/src/intermission/intermission.h b/src/intermission/intermission.h index e25354c875..45c2efd8bc 100644 --- a/src/intermission/intermission.h +++ b/src/intermission/intermission.h @@ -246,7 +246,7 @@ class DIntermissionScreenCast : public DIntermissionScreen TArray mCastSounds; int casttics; - uint32_t casttranslation; // [RH] Draw "our hero" with their chosen suit color + FTranslationID casttranslation; // [RH] Draw "our hero" with their chosen suit color FState* caststate; FState* basestate; FState* advplayerstate; diff --git a/src/playsim/a_decals.cpp b/src/playsim/a_decals.cpp index fdb63a0a64..1d9aa9b266 100644 --- a/src/playsim/a_decals.cpp +++ b/src/playsim/a_decals.cpp @@ -243,17 +243,6 @@ void DBaseDecal::SetShade (int r, int g, int b) AlphaColor = MAKEARGB(ColorMatcher.Pick (r, g, b), r, g, b); } -//---------------------------------------------------------------------------- -// -// -// -//---------------------------------------------------------------------------- - -void DBaseDecal::SetTranslation(uint32_t trans) -{ - Translation = trans; -} - //---------------------------------------------------------------------------- // // Returns the texture the decal stuck to. @@ -708,7 +697,7 @@ void DImpactDecal::Expired() // //---------------------------------------------------------------------------- -DBaseDecal* DImpactDecal::StaticCreate (FLevelLocals *Level, const char *name, const DVector3 &pos, side_t *wall, F3DFloor * ffloor, PalEntry color, uint32_t bloodTranslation) +DBaseDecal* DImpactDecal::StaticCreate (FLevelLocals *Level, const char *name, const DVector3 &pos, side_t *wall, F3DFloor * ffloor, PalEntry color, FTranslationID bloodTranslation) { if (cl_maxdecals > 0) { @@ -728,7 +717,7 @@ DBaseDecal* DImpactDecal::StaticCreate (FLevelLocals *Level, const char *name, c // //---------------------------------------------------------------------------- -DBaseDecal* DImpactDecal::StaticCreate (FLevelLocals *Level, const FDecalTemplate *tpl, const DVector3 &pos, side_t *wall, F3DFloor * ffloor, PalEntry color, uint32_t bloodTranslation, bool permanent) +DBaseDecal* DImpactDecal::StaticCreate (FLevelLocals *Level, const FDecalTemplate *tpl, const DVector3 &pos, side_t *wall, F3DFloor * ffloor, PalEntry color, FTranslationID bloodTranslation, bool permanent) { DBaseDecal *decal = NULL; if (tpl != NULL && ((cl_maxdecals > 0 && !(wall->Flags & WALLF_NOAUTODECALS)) || permanent)) @@ -743,9 +732,7 @@ DBaseDecal* DImpactDecal::StaticCreate (FLevelLocals *Level, const FDecalTemplat if (tpl->ShadeColor != tpl_low->ShadeColor) lowercolor=0; else lowercolor = color; - uint32_t lowerTrans = (bloodTranslation != 0 ? bloodTranslation : 0); - - StaticCreate (Level, tpl_low, pos, wall, ffloor, lowercolor, lowerTrans, permanent); + StaticCreate (Level, tpl_low, pos, wall, ffloor, lowercolor, bloodTranslation, permanent); } if (!permanent) decal = Level->CreateThinker(pos.Z); else decal = Level->CreateThinker(pos.Z); @@ -768,7 +755,7 @@ DBaseDecal* DImpactDecal::StaticCreate (FLevelLocals *Level, const FDecalTemplat } // [Nash] opaque blood - if (bloodTranslation != 0 && tpl->ShadeColor == 0 && tpl->opaqueBlood) + if (bloodTranslation != NO_TRANSLATION && tpl->ShadeColor == 0 && tpl->opaqueBlood) { decal->SetTranslation(bloodTranslation); decal->RenderStyle = STYLE_Normal; @@ -860,7 +847,7 @@ void SprayDecal(AActor *shooter, const char *name, double distance, DVector3 off else dir = direction; - uint32_t bloodTrans = useBloodColor ? shooter->BloodTranslation : 0; + auto bloodTrans = useBloodColor ? shooter->BloodTranslation : NO_TRANSLATION; PalEntry entry = !useBloodColor ? (PalEntry)decalColor : shooter->BloodColor; if (Trace(off, shooter->Sector, dir, distance, 0, ML_BLOCKEVERYTHING, shooter, trace, TRACE_NoSky)) @@ -891,7 +878,7 @@ DBaseDecal *ShootDecal(FLevelLocals *Level, const FDecalTemplate *tpl, sector_t if (trace.HitType == TRACE_HitWall) { - return DImpactDecal::StaticCreate(Level, tpl, trace.HitPos, trace.Line->sidedef[trace.Side], trace.ffloor, 0, 0, permanent); + return DImpactDecal::StaticCreate(Level, tpl, trace.HitPos, trace.Line->sidedef[trace.Side], trace.ffloor, 0, NO_TRANSLATION, permanent); } return NULL; } diff --git a/src/playsim/a_sharedglobal.h b/src/playsim/a_sharedglobal.h index 466ec5c607..83d3a471d6 100644 --- a/src/playsim/a_sharedglobal.h +++ b/src/playsim/a_sharedglobal.h @@ -31,7 +31,11 @@ public: double GetRealZ (const side_t *wall) const; void SetShade (uint32_t rgb); void SetShade (int r, int g, int b); - void SetTranslation(uint32_t trans); + void SetTranslation(FTranslationID trans) + { + Translation = trans; + } + void Spread (const FDecalTemplate *tpl, side_t *wall, double x, double y, double z, F3DFloor * ffloor); void GetXY (side_t *side, double &x, double &y) const; @@ -42,7 +46,7 @@ public: double ScaleX = 1, ScaleY = 1; double Alpha = 1; uint32_t AlphaColor = 0; - int Translation = 0; + FTranslationID Translation = NO_TRANSLATION; FTextureID PicNum; uint32_t RenderFlags = 0; FRenderStyle RenderStyle; @@ -69,8 +73,8 @@ public: } void Construct(side_t *wall, const FDecalTemplate *templ); - static DBaseDecal *StaticCreate(FLevelLocals *Level, const char *name, const DVector3 &pos, side_t *wall, F3DFloor * ffloor, PalEntry color = 0, uint32_t bloodTranslation = 0); - static DBaseDecal *StaticCreate(FLevelLocals *Level, const FDecalTemplate *tpl, const DVector3 &pos, side_t *wall, F3DFloor * ffloor, PalEntry color = 0, uint32_t bloodTranslation = 0, bool permanent = false); + static DBaseDecal *StaticCreate(FLevelLocals *Level, const char *name, const DVector3 &pos, side_t *wall, F3DFloor * ffloor, PalEntry color = 0, FTranslationID bloodTranslation = NO_TRANSLATION); + static DBaseDecal *StaticCreate(FLevelLocals *Level, const FDecalTemplate *tpl, const DVector3 &pos, side_t *wall, F3DFloor * ffloor, PalEntry color = 0, FTranslationID bloodTranslation = NO_TRANSLATION, bool permanent = false); void BeginPlay (); void Expired() override; diff --git a/src/playsim/actor.h b/src/playsim/actor.h index 1bef8815ab..1e3013b273 100644 --- a/src/playsim/actor.h +++ b/src/playsim/actor.h @@ -1082,7 +1082,7 @@ public: FRenderStyle RenderStyle; // Style to draw this actor with FTextureID picnum; // Draw this instead of sprite if valid uint32_t fillcolor; // Color to draw when STYLE_Shaded - uint32_t Translation; + FTranslationID Translation; uint32_t RenderRequired; // current renderer must have this feature set uint32_t RenderHidden; // current renderer must *not* have any of these features @@ -1262,7 +1262,7 @@ public: uint8_t FriendPlayer; // [RH] Player # + 1 this friendly monster works for (so 0 is no player, 1 is player 0, etc) double FloatBobStrength; PalEntry BloodColor; - uint32_t BloodTranslation; + FTranslationID BloodTranslation; // [RH] Stuff that used to be part of an Actor Info FSoundID SeeSound; diff --git a/src/playsim/p_lnspec.cpp b/src/playsim/p_lnspec.cpp index 3eb4835ece..4eb379f724 100644 --- a/src/playsim/p_lnspec.cpp +++ b/src/playsim/p_lnspec.cpp @@ -1877,7 +1877,7 @@ FUNC(LS_Thing_SetTranslation) // Thing_SetTranslation (tid, range) { auto iterator = Level->GetActorIterator(arg0); - int range; + FTranslationID range; AActor *target; bool ok = false; @@ -1895,7 +1895,7 @@ FUNC(LS_Thing_SetTranslation) } else { - range = 0; + range = NO_TRANSLATION; } if (arg0 == 0) @@ -1903,7 +1903,7 @@ FUNC(LS_Thing_SetTranslation) if (it != NULL) { ok = true; - it->Translation = range==0? it->GetDefault()->Translation : range; + it->Translation = range == NO_TRANSLATION ? it->GetDefault()->Translation : range; } } else @@ -1911,7 +1911,7 @@ FUNC(LS_Thing_SetTranslation) while ( (target = iterator.Next ()) ) { ok = true; - target->Translation = range==0? target->GetDefault()->Translation : range; + target->Translation = range == NO_TRANSLATION ? target->GetDefault()->Translation : range; } } diff --git a/src/playsim/p_map.cpp b/src/playsim/p_map.cpp index dda393aaea..636304db80 100644 --- a/src/playsim/p_map.cpp +++ b/src/playsim/p_map.cpp @@ -5163,7 +5163,7 @@ void P_TraceBleed(int damage, const DVector3 &pos, AActor *actor, DAngle angle, bloodcolor.a = 1; } - uint32_t bloodTrans = (bloodcolor != 0 ? actor->BloodTranslation : 0); + auto bloodTrans = (bloodcolor != 0 ? actor->BloodTranslation : NO_TRANSLATION); DImpactDecal::StaticCreate(actor->Level, bloodType, bleedtrace.HitPos, bleedtrace.Line->sidedef[bleedtrace.Side], bleedtrace.ffloor, bloodcolor, bloodTrans); @@ -6481,7 +6481,7 @@ void P_DoCrunch(AActor *thing, FChangePosition *cpos) mo->Vel.X = pr_crunch.Random2() / 16.; mo->Vel.Y = pr_crunch.Random2() / 16.; - if (thing->BloodTranslation != 0 && !(mo->flags2 & MF2_DONTTRANSLATE)) + if (thing->BloodTranslation != NO_TRANSLATION && !(mo->flags2 & MF2_DONTTRANSLATE)) { mo->Translation = thing->BloodTranslation; } diff --git a/src/playsim/p_mobj.cpp b/src/playsim/p_mobj.cpp index dc445fc002..8420d4826b 100644 --- a/src/playsim/p_mobj.cpp +++ b/src/playsim/p_mobj.cpp @@ -7558,8 +7558,8 @@ void AActor::SetTranslation(FName trname) return; } - int tnum = R_FindCustomTranslation(trname); - if (tnum >= 0) + auto tnum = R_FindCustomTranslation(trname); + if (tnum != INVALID_TRANSLATION) { Translation = tnum; } diff --git a/src/playsim/p_pspr.cpp b/src/playsim/p_pspr.cpp index 91e9dafc8e..4a190d0c29 100644 --- a/src/playsim/p_pspr.cpp +++ b/src/playsim/p_pspr.cpp @@ -171,7 +171,7 @@ DPSprite::DPSprite(player_t *owner, AActor *caller, int id) InterpolateTic(false), firstTic(true), Tics(0), - Translation(0), + Translation(NO_TRANSLATION), Flags(0), Owner(owner), State(nullptr), @@ -1023,12 +1023,12 @@ DEFINE_ACTION_FUNCTION(AActor, A_OverlayTranslation) { // an empty string resets to the default // (unlike AActor::SetTranslation, there is no Default block for PSprites, so just set the translation to 0) - pspr->Translation = 0; + pspr->Translation = NO_TRANSLATION; return 0; } - int tnum = R_FindCustomTranslation(trname); - if (tnum >= 0) + auto tnum = R_FindCustomTranslation(trname); + if (tnum != INVALID_TRANSLATION) { pspr->Translation = tnum; } diff --git a/src/playsim/p_pspr.h b/src/playsim/p_pspr.h index 85add7b6bf..de019e62fc 100644 --- a/src/playsim/p_pspr.h +++ b/src/playsim/p_pspr.h @@ -31,6 +31,7 @@ #define __P_PSPR_H__ #include "renderstyle.h" +#include "palettecontainer.h" // Basic data types. // Needs fixed point, and BAM angles. @@ -104,7 +105,7 @@ public: int GetSprite() const { return Sprite; } int GetFrame() const { return Frame; } int GetTics() const { return Tics; } - uint32_t GetTranslation() { return Translation; } + FTranslationID GetTranslation() { return Translation; } FState* GetState() const { return State; } DPSprite* GetNext() { return Next; } AActor* GetCaller() { return Caller; } @@ -127,7 +128,7 @@ public: WeaponInterp Vert; // Current Position bool firstTic; int Tics; - uint32_t Translation; + FTranslationID Translation; int Flags; FRenderStyle Renderstyle; diff --git a/src/r_data/models.cpp b/src/r_data/models.cpp index 80460649c9..6b31fbf8bc 100644 --- a/src/r_data/models.cpp +++ b/src/r_data/models.cpp @@ -64,7 +64,7 @@ void RenderModel(FModelRenderer *renderer, float x, float y, float z, FSpriteMod int translation = 0; if (!(smf->flags & MDL_IGNORETRANSLATION)) - translation = actor->Translation; + translation = actor->Translation.index(); // y scale for a sprite means height, i.e. z in the world! float scaleFactorX = actor->Scale.X * smf->xscale; @@ -245,8 +245,8 @@ void RenderHUDModel(FModelRenderer *renderer, DPSprite *psp, FVector3 translatio float orientation = smf->xscale * smf->yscale * smf->zscale; renderer->BeginDrawHUDModel(playermo->RenderStyle, objectToWorldMatrix, orientation < 0, smf); - uint32_t trans = psp->GetTranslation() != 0 ? psp->GetTranslation() : 0; - if ((psp->Flags & PSPF_PLAYERTRANSLATED)) trans = psp->Owner->mo->Translation; + uint32_t trans = psp->GetTranslation().index(); + if ((psp->Flags & PSPF_PLAYERTRANSLATED)) trans = psp->Owner->mo->Translation.index(); RenderFrameModels(renderer, playermo->Level, smf, psp->GetState(), psp->GetTics(), psp->Caller->modelData != nullptr ? psp->Caller->modelData->modelDef != NAME_None ? PClass::FindActor(psp->Caller->modelData->modelDef) : psp->Caller->GetClass() : psp->Caller->GetClass(), trans, psp->Caller); renderer->EndDrawHUDModel(playermo->RenderStyle, smf); } diff --git a/src/r_data/r_translate.cpp b/src/r_data/r_translate.cpp index ca2b34fbef..f79cfce805 100644 --- a/src/r_data/r_translate.cpp +++ b/src/r_data/r_translate.cpp @@ -79,7 +79,7 @@ void StaticSerializeTranslations(FSerializer &arc) auto size = GPalette.NumTranslations(TRANSLATION_LevelScripted); for (unsigned int i = 0; i < size; ++i) { - trans = GPalette.TranslationToTable(TRANSLATION(TRANSLATION_LevelScripted, i)); + trans = GPalette.GetTranslation(TRANSLATION_LevelScripted, i); if (trans != NULL && !trans->IsIdentity()) { if (arc.BeginObject(nullptr)) @@ -114,7 +114,7 @@ void StaticSerializeTranslations(FSerializer &arc) static TArray BloodTranslationColors; -int CreateBloodTranslation(PalEntry color) +FTranslationID CreateBloodTranslation(PalEntry color) { unsigned int i; @@ -132,7 +132,7 @@ int CreateBloodTranslation(PalEntry color) color.b == BloodTranslationColors[i].b) { // A duplicate of this translation already exists - return i; + return TRANSLATION(TRANSLATION_Blood, i); } } if (BloodTranslationColors.Size() >= MAX_DECORATE_TRANSLATIONS) @@ -152,7 +152,7 @@ int CreateBloodTranslation(PalEntry color) trans.Remap[i] = entry; } GPalette.AddTranslation(TRANSLATION_Blood, &trans); - return BloodTranslationColors.Push(color); + return TRANSLATION(TRANSLATION_Blood, BloodTranslationColors.Push(color)); } //---------------------------------------------------------------------------- @@ -628,9 +628,9 @@ DEFINE_ACTION_FUNCTION(_Translation, SetPlayerTranslation) // // //---------------------------------------------------------------------------- -static TMap customTranslationMap; +static TMap customTranslationMap; -int R_FindCustomTranslation(FName name) +FTranslationID R_FindCustomTranslation(FName name) { switch (name.GetIndex()) { @@ -639,7 +639,7 @@ int R_FindCustomTranslation(FName name) return TRANSLATION(TRANSLATION_Standard, 7); case NAME_None: - return 0; + return NO_TRANSLATION; case NAME_RainPillar1: case NAME_RainPillar2: @@ -662,8 +662,8 @@ int R_FindCustomTranslation(FName name) return TRANSLATION(TRANSLATION_Players, name.GetIndex() - NAME_Player1); } - int *t = customTranslationMap.CheckKey(name); - return (t != nullptr)? *t : -1; + auto t = customTranslationMap.CheckKey(name); + return (t != nullptr)? *t : INVALID_TRANSLATION; } //---------------------------------------------------------------------------- @@ -698,16 +698,16 @@ void R_ParseTrnslate() { sc.ScriptError("Translation must be in the range [0,%d]", max); } - NewTranslation = *GPalette.TranslationToTable(TRANSLATION(TRANSLATION_Standard, sc.Number)); + NewTranslation = *GPalette.GetTranslation(TRANSLATION_Standard, sc.Number); } else if (sc.TokenType == TK_Identifier) { - int tnum = R_FindCustomTranslation(sc.String); - if (tnum == -1) + auto tnum = R_FindCustomTranslation(sc.String); + if (tnum == INVALID_TRANSLATION) { sc.ScriptError("Base translation '%s' not found in '%s'", sc.String, newtrans.GetChars()); } - NewTranslation = *GPalette.TranslationToTable(tnum); + NewTranslation = *GPalette.TranslationToTable(tnum.index()); } else { @@ -746,7 +746,7 @@ void R_ParseTrnslate() } } while (sc.CheckToken(',')); - int trans = GPalette.StoreTranslation(TRANSLATION_Custom, &NewTranslation); + auto trans = GPalette.StoreTranslation(TRANSLATION_Custom, &NewTranslation); customTranslationMap[newtrans] = trans; } } @@ -773,7 +773,7 @@ DEFINE_ACTION_FUNCTION(_Translation, AddTranslation) { NewTranslation.Remap[i] = ColorMatcher.Pick(self->colors[i]); } - int trans = GPalette.StoreTranslation(TRANSLATION_Custom, &NewTranslation); - ACTION_RETURN_INT(trans); + auto trans = GPalette.StoreTranslation(TRANSLATION_Custom, &NewTranslation); + ACTION_RETURN_INT(trans.index()); } diff --git a/src/r_data/r_translate.h b/src/r_data/r_translate.h index 534c497951..036aeabaeb 100644 --- a/src/r_data/r_translate.h +++ b/src/r_data/r_translate.h @@ -38,9 +38,9 @@ void R_InitTranslationTables (void); void R_BuildPlayerTranslation (int player); // [RH] Actually create a player's translation table. void R_GetPlayerTranslation (int color, const struct FPlayerColorSet *colorset, class FPlayerSkin *skin, struct FRemapTable *table); -int CreateBloodTranslation(PalEntry color); +FTranslationID CreateBloodTranslation(PalEntry color); -int R_FindCustomTranslation(FName name); +FTranslationID R_FindCustomTranslation(FName name); void R_ParseTrnslate(); void StaticSerializeTranslations(FSerializer& arc); diff --git a/src/rendering/hwrenderer/hw_precache.cpp b/src/rendering/hwrenderer/hw_precache.cpp index 7ea1ecb388..699faf7061 100644 --- a/src/rendering/hwrenderer/hw_precache.cpp +++ b/src/rendering/hwrenderer/hw_precache.cpp @@ -152,7 +152,7 @@ void hw_PrecacheTexture(uint8_t *texhitlist, TMap &actorhitl while (it.NextPair(pair)) { PClassActor *cls = pair->Key; - auto remap = GPalette.TranslationToTable(GetDefaultByType(cls)->Translation); + auto remap = GPalette.TranslationToTable(GetDefaultByType(cls)->Translation.index()); int gltrans = remap == nullptr ? 0 : remap->Index; for (unsigned i = 0; i < cls->GetStateCount(); i++) diff --git a/src/rendering/hwrenderer/scene/hw_decal.cpp b/src/rendering/hwrenderer/scene/hw_decal.cpp index 1e28cdd5fa..f6d515d171 100644 --- a/src/rendering/hwrenderer/scene/hw_decal.cpp +++ b/src/rendering/hwrenderer/scene/hw_decal.cpp @@ -76,7 +76,7 @@ void HWDecal::DrawDecal(HWDrawInfo *di, FRenderState &state) state.SetTextureMode(decal->RenderStyle); state.SetRenderStyle(decal->RenderStyle); - state.SetMaterial(texture, UF_Sprite, 0, CLAMP_XY, decal->Translation, -1); + state.SetMaterial(texture, UF_Sprite, 0, CLAMP_XY, decal->Translation.index(), -1); // If srcalpha is one it looks better with a higher alpha threshold diff --git a/src/rendering/hwrenderer/scene/hw_sprites.cpp b/src/rendering/hwrenderer/scene/hw_sprites.cpp index 8007c9f253..f573f3f08a 100644 --- a/src/rendering/hwrenderer/scene/hw_sprites.cpp +++ b/src/rendering/hwrenderer/scene/hw_sprites.cpp @@ -1077,7 +1077,7 @@ void HWSprite::Process(HWDrawInfo *di, AActor* thing, sector_t * sector, area_t } } - translation = thing->Translation; + translation = thing->Translation.index(); OverrideShader = -1; trans = thing->Alpha; diff --git a/src/rendering/hwrenderer/scene/hw_weapon.cpp b/src/rendering/hwrenderer/scene/hw_weapon.cpp index cc5ed53a65..4cabd6b5eb 100644 --- a/src/rendering/hwrenderer/scene/hw_weapon.cpp +++ b/src/rendering/hwrenderer/scene/hw_weapon.cpp @@ -98,8 +98,8 @@ void HWDrawInfo::DrawPSprite(HUDSprite *huds, FRenderState &state) { float thresh = (huds->texture->GetTranslucency() || huds->OverrideShader != -1) ? 0.f : gl_mask_sprite_threshold; state.AlphaFunc(Alpha_GEqual, thresh); - uint32_t trans = huds->weapon->GetTranslation() != 0 ? huds->weapon->GetTranslation() : 0; - if ((huds->weapon->Flags & PSPF_PLAYERTRANSLATED)) trans = huds->owner->Translation; + uint32_t trans = huds->weapon->GetTranslation().index(); + if ((huds->weapon->Flags & PSPF_PLAYERTRANSLATED)) trans = huds->owner->Translation.index(); state.SetMaterial(huds->texture, UF_Sprite, CTF_Expand, CLAMP_XY_NOMIP, trans, huds->OverrideShader); state.Draw(DT_TriangleStrip, huds->mx, 4); } diff --git a/src/rendering/swrenderer/things/r_decal.cpp b/src/rendering/swrenderer/things/r_decal.cpp index 533b8876ca..2d865fbb55 100644 --- a/src/rendering/swrenderer/things/r_decal.cpp +++ b/src/rendering/swrenderer/things/r_decal.cpp @@ -241,7 +241,7 @@ namespace swrenderer cmlight.SetColormap(thread, MINZ, light.GetLightLevel(), light.GetFoggy(), usecolormap, decal->RenderFlags & RF_FULLBRIGHT, false, false, false, false); SpriteDrawerArgs drawerargs; - bool visible = drawerargs.SetStyle(thread->Viewport.get(), decal->RenderStyle, (float)decal->Alpha, decal->Translation, decal->AlphaColor, cmlight); + bool visible = drawerargs.SetStyle(thread->Viewport.get(), decal->RenderStyle, (float)decal->Alpha, decal->Translation.index(), decal->AlphaColor, cmlight); if (visible) { drawerargs.DrawMasked(thread, zpos + WallSpriteTile->GetTopOffset(0) * decal->ScaleY, decal->ScaleY, decal->RenderFlags & RF_XFLIP, decal->RenderFlags & RF_YFLIP, WallC, clipper->x1, clipper->x2, light, WallSpriteTile, mfloorclip, mceilingclip, decal->RenderStyle); diff --git a/src/rendering/swrenderer/things/r_playersprite.cpp b/src/rendering/swrenderer/things/r_playersprite.cpp index 87ae074961..3659909aeb 100644 --- a/src/rendering/swrenderer/things/r_playersprite.cpp +++ b/src/rendering/swrenderer/things/r_playersprite.cpp @@ -307,8 +307,8 @@ namespace swrenderer vis.yscale = float(pspriteyscale / stex->GetScale().Y); vis.pic = stex; - uint32_t trans = pspr->GetTranslation() != 0 ? pspr->GetTranslation() : 0; - if ((pspr->Flags & PSPF_PLAYERTRANSLATED)) trans = owner->Translation; + uint32_t trans = pspr->GetTranslation().index(); + if ((pspr->Flags & PSPF_PLAYERTRANSLATED)) trans = owner->Translation.index(); vis.Translation = trans; // If flip is used, provided that it's not already flipped (that would just invert itself) diff --git a/src/rendering/swrenderer/things/r_sprite.cpp b/src/rendering/swrenderer/things/r_sprite.cpp index 39c2e82e35..667296cf45 100644 --- a/src/rendering/swrenderer/things/r_sprite.cpp +++ b/src/rendering/swrenderer/things/r_sprite.cpp @@ -173,7 +173,7 @@ namespace swrenderer vis->RenderStyle = LegacyRenderStyles[STYLE_Normal]; } vis->FillColor = thing->fillcolor; - vis->Translation = thing->Translation; // [RH] thing translation table + vis->Translation = thing->Translation.index(); // [RH] thing translation table vis->FakeFlatStat = fakeside; vis->Alpha = float(thing->Alpha); vis->fakefloor = fakefloor; diff --git a/src/rendering/swrenderer/things/r_voxel.cpp b/src/rendering/swrenderer/things/r_voxel.cpp index 455ad48ab5..8f476e0c4f 100644 --- a/src/rendering/swrenderer/things/r_voxel.cpp +++ b/src/rendering/swrenderer/things/r_voxel.cpp @@ -157,7 +157,7 @@ namespace swrenderer vis->renderflags |= RF_FULLBRIGHT; // kg3D vis->RenderStyle = thing->RenderStyle; vis->FillColor = thing->fillcolor; - vis->Translation = thing->Translation; // [RH] thing translation table + vis->Translation = thing->Translation.index(); // [RH] thing translation table vis->FakeFlatStat = fakeside; vis->Alpha = float(thing->Alpha); vis->fakefloor = fakefloor; diff --git a/src/rendering/swrenderer/things/r_wallsprite.cpp b/src/rendering/swrenderer/things/r_wallsprite.cpp index b4dcc9bf23..0b1bcb8930 100644 --- a/src/rendering/swrenderer/things/r_wallsprite.cpp +++ b/src/rendering/swrenderer/things/r_wallsprite.cpp @@ -128,7 +128,7 @@ namespace swrenderer if (thing->flags5 & MF5_BRIGHT) vis->renderflags |= RF_FULLBRIGHT; // kg3D vis->RenderStyle = thing->RenderStyle; vis->FillColor = thing->fillcolor; - vis->Translation = thing->Translation; + vis->Translation = thing->Translation.index(); vis->FakeFlatStat = WaterFakeSide::Center; vis->Alpha = float(thing->Alpha); vis->fakefloor = NULL; diff --git a/src/scripting/thingdef_properties.cpp b/src/scripting/thingdef_properties.cpp index 11a3313bc1..fa7a5b13f3 100644 --- a/src/scripting/thingdef_properties.cpp +++ b/src/scripting/thingdef_properties.cpp @@ -747,8 +747,8 @@ DEFINE_PROPERTY(translation, L, Actor) for(int i = 1; i < PROP_PARM_COUNT; i++) { PROP_STRING_PARM(str, i); - int tnum; - if (i== 1 && PROP_PARM_COUNT == 2 && (tnum = R_FindCustomTranslation(str)) != -1) + FTranslationID tnum; + if (i== 1 && PROP_PARM_COUNT == 2 && (tnum = R_FindCustomTranslation(str)) != INVALID_TRANSLATION) { defaults->Translation = tnum; return; @@ -789,7 +789,7 @@ DEFINE_PROPERTY(bloodcolor, C, Actor) defaults->BloodColor = color; defaults->BloodColor.a = 255; // a should not be 0. - defaults->BloodTranslation = TRANSLATION(TRANSLATION_Blood, CreateBloodTranslation(color)); + defaults->BloodTranslation = CreateBloodTranslation(color); } //==========================================================================