- copied constexpr declarations plus a few fixed in utility code and fixed a few places where this triggered a compile error now.

This commit is contained in:
Christoph Oelckers 2020-09-27 08:36:30 +02:00
parent b66349d4cf
commit db895b43b2
9 changed files with 49 additions and 28 deletions

View file

@ -450,7 +450,7 @@ void FStringTable::InsertString(int lumpnum, int langid, FName label, const FStr
auto replace = allMacros.CheckKey(lookupname); auto replace = allMacros.CheckKey(lookupname);
for (int i = 0; i < 4; i++) for (int i = 0; i < 4; i++)
{ {
const char *replacement = replace && replace->Replacements[i] ? replace->Replacements[i].GetChars() : ""; const char *replacement = replace? replace->Replacements[i].GetChars() : "";
te.strings[i].Substitute(replacee, replacement); te.strings[i].Substitute(replacee, replacement);
} }
} }

View file

@ -43,7 +43,7 @@ inline int32_t FixedDiv (int32_t a, int32_t b)
return (int32_t)(((int64_t)a << 16) / b); return (int32_t)(((int64_t)a << 16) / b);
} }
__forceinline int32_t FixedMul(int32_t a, int32_t b) __forceinline constexpr int32_t FixedMul(int32_t a, int32_t b)
{ {
return (int32_t)(((int64_t)a * b) >> 16); return (int32_t)(((int64_t)a * b) >> 16);
} }
@ -53,9 +53,19 @@ inline fixed_t FloatToFixed(double f)
return xs_Fix<16>::ToFix(f); return xs_Fix<16>::ToFix(f);
} }
inline double FixedToFloat(fixed_t f) inline constexpr fixed_t IntToFixed(int32_t f)
{ {
return f / 65536.; return f << FRACBITS;
}
inline constexpr double FixedToFloat(fixed_t f)
{
return f * (1/65536.);
}
inline constexpr int32_t FixedToInt(fixed_t f)
{
return (f + FRACUNIT/2) >> FRACBITS;
} }
inline unsigned FloatToAngle(double f) inline unsigned FloatToAngle(double f)
@ -63,12 +73,12 @@ inline unsigned FloatToAngle(double f)
return xs_CRoundToInt((f)* (0x40000000 / 90.)); return xs_CRoundToInt((f)* (0x40000000 / 90.));
} }
inline double AngleToFloat(unsigned f) inline constexpr double AngleToFloat(unsigned f)
{ {
return f * (90. / 0x40000000); return f * (90. / 0x40000000);
} }
inline double AngleToFloat(int f) inline constexpr double AngleToFloat(int f)
{ {
return f * (90. / 0x40000000); return f * (90. / 0x40000000);
} }

View file

@ -12,7 +12,7 @@
struct PalEntry struct PalEntry
{ {
PalEntry() = default; PalEntry() = default;
PalEntry (uint32_t argb) { d = argb; } constexpr PalEntry (uint32_t argb) : d(argb) { }
operator uint32_t () const { return d; } operator uint32_t () const { return d; }
void SetRGB(PalEntry other) void SetRGB(PalEntry other)
{ {
@ -36,35 +36,35 @@ struct PalEntry
return other; return other;
} }
} }
int Luminance() const constexpr int Luminance() const
{ {
return (r * 77 + g * 143 + b * 37) >> 8; return (r * 77 + g * 143 + b * 37) >> 8;
} }
int Amplitude() const constexpr int Amplitude() const
{ {
return std::max(r, std::max(g, b)); return std::max(r, std::max(g, b));
} }
void Decolorize() // this for 'nocoloredspritelighting' and not the same as desaturation. The normal formula results in a value that's too dark. constexpr void Decolorize() // this for 'nocoloredspritelighting' and not the same as desaturation. The normal formula results in a value that's too dark.
{ {
int v = (r + g + b); int v = (r + g + b);
r = g = b = ((255*3) + v + v) / 9; r = g = b = ((255*3) + v + v) / 9;
} }
bool isBlack() const constexpr bool isBlack() const
{ {
return (d & 0xffffff) == 0; return (d & 0xffffff) == 0;
} }
bool isWhite() const constexpr bool isWhite() const
{ {
return (d & 0xffffff) == 0xffffff; return (d & 0xffffff) == 0xffffff;
} }
PalEntry &operator= (const PalEntry &other) = default; PalEntry &operator= (const PalEntry &other) = default;
PalEntry &operator= (uint32_t other) { d = other; return *this; } constexpr PalEntry &operator= (uint32_t other) { d = other; return *this; }
PalEntry InverseColor() const { PalEntry nc; nc.a = a; nc.r = 255 - r; nc.g = 255 - g; nc.b = 255 - b; return nc; } constexpr PalEntry InverseColor() const { PalEntry nc(a, 255 - r, 255 - g, 255 - b); return nc; }
#ifdef __BIG_ENDIAN__ #ifdef __BIG_ENDIAN__
PalEntry (uint8_t ir, uint8_t ig, uint8_t ib) : a(0), r(ir), g(ig), b(ib) {} constexpr PalEntry (uint8_t ir, uint8_t ig, uint8_t ib) : a(0), r(ir), g(ig), b(ib) {}
PalEntry (uint8_t ia, uint8_t ir, uint8_t ig, uint8_t ib) : a(ia), r(ir), g(ig), b(ib) {} constexpr PalEntry (uint8_t ia, uint8_t ir, uint8_t ig, uint8_t ib) : a(ia), r(ir), g(ig), b(ib) {}
union union
{ {
struct struct
@ -74,8 +74,8 @@ struct PalEntry
uint32_t d; uint32_t d;
}; };
#else #else
PalEntry (uint8_t ir, uint8_t ig, uint8_t ib) : b(ib), g(ig), r(ir), a(0) {} constexpr PalEntry (uint8_t ir, uint8_t ig, uint8_t ib) : b(ib), g(ig), r(ir), a(0) {}
PalEntry (uint8_t ia, uint8_t ir, uint8_t ig, uint8_t ib) : b(ib), g(ig), r(ir), a(ia) {} constexpr PalEntry (uint8_t ia, uint8_t ir, uint8_t ig, uint8_t ib) : b(ib), g(ig), r(ir), a(ia) {}
union union
{ {
struct struct
@ -87,7 +87,7 @@ struct PalEntry
#endif #endif
}; };
inline int Luminance(int r, int g, int b) constexpr inline int Luminance(int r, int g, int b)
{ {
return (r * 77 + g * 143 + b * 37) >> 8; return (r * 77 + g * 143 + b * 37) >> 8;
} }

View file

@ -1527,6 +1527,16 @@ public:
{ {
memset(&bytes[0], on ? -1 : 0, sizeof(bytes)); memset(&bytes[0], on ? -1 : 0, sizeof(bytes));
} }
// These are for utilities that need access to the raw storage. The serializer needs this to do its work, for example.
uint8_t* Storage()
{
return bytes;
}
unsigned StorageSize() const
{
return sizeof(bytes);
}
}; };
// A wrapper to externally stored data. // A wrapper to externally stored data.

View file

@ -249,7 +249,7 @@ const char *MakeUTF8(const char *outline, int *numchars)
UTF8String.Push(encode[i]); UTF8String.Push(encode[i]);
} }
} }
if (numchars) *numchars++; if (numchars) (*numchars)++;
} }
UTF8String.Push(0); UTF8String.Push(0);
return UTF8String.Data(); return UTF8String.Data();

View file

@ -164,6 +164,10 @@ public:
std::swap(Chars, other.Chars); std::swap(Chars, other.Chars);
} }
// We do not want any implicit conversions from FString in conditionals.
explicit operator bool() = delete; // this is needed to render the operator const char * ineffective when used in boolean constructs.
bool operator !() = delete;
operator const char *() const { return Chars; } operator const char *() const { return Chars; }
const char *GetChars() const { return Chars; } const char *GetChars() const { return Chars; }

View file

@ -3805,7 +3805,7 @@ void I_UpdateWindowTitle()
switch (I_FriendlyWindowTitle) switch (I_FriendlyWindowTitle)
{ {
case 1: case 1:
if (level.LevelName && level.LevelName.GetChars()[0]) if (level.LevelName.IsNotEmpty())
{ {
titlestr.Format("%s - %s", level.LevelName.GetChars(), GameStartupInfo.Name.GetChars()); titlestr.Format("%s - %s", level.LevelName.GetChars(), GameStartupInfo.Name.GetChars());
break; break;

View file

@ -2375,7 +2375,7 @@ static int DoInclude (int dummy)
// Try looking for the included file in the same directory // Try looking for the included file in the same directory
// as the patch before looking in the current file. // as the patch before looking in the current file.
const char *lastSlash = savepatchname ? strrchr (savepatchname, '/') : NULL; const char *lastSlash = strrchr(savepatchname, '/');
char *path = data; char *path = data;
if (lastSlash != NULL) if (lastSlash != NULL)

View file

@ -236,12 +236,9 @@ void DIntermissionScreen::Drawer ()
if (CheckOverlay(i)) if (CheckOverlay(i))
DrawTexture(twod, TexMan.GetGameTexture(mOverlays[i].mPic), mOverlays[i].x, mOverlays[i].y, DTA_320x200, true, TAG_DONE); DrawTexture(twod, TexMan.GetGameTexture(mOverlays[i].mPic), mOverlays[i].x, mOverlays[i].y, DTA_320x200, true, TAG_DONE);
} }
if (mSubtitle) const char *sub = mSubtitle.GetChars();
{ if (sub && *sub == '$') sub = GStrings[sub + 1];
const char *sub = mSubtitle.GetChars(); if (sub) DrawFullscreenSubtitle(sub);
if (sub && *sub == '$') sub = GStrings[sub + 1];
if (sub) DrawFullscreenSubtitle(sub);
}
} }
void DIntermissionScreen::OnDestroy() void DIntermissionScreen::OnDestroy()