diff --git a/src/Common/AnimUtil.cpp b/src/Common/AnimUtil.cpp deleted file mode 100644 index 8617687f..00000000 --- a/src/Common/AnimUtil.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include "CTimer.h" -#include - -namespace AnimUtil -{ - float SecondsMod900() - { - return fmod((float) CTimer::GlobalTime(), 900.f); - } -} diff --git a/src/Common/AnimUtil.h b/src/Common/AnimUtil.h deleted file mode 100644 index b86d4f9f..00000000 --- a/src/Common/AnimUtil.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef ANIMUTIL_H -#define ANIMUTIL_H - -namespace AnimUtil -{ - float SecondsMod900(); -} - -#endif // ANIMUTIL_H diff --git a/src/Common/CColor.cpp b/src/Common/CColor.cpp index 596c3ec0..32fd9e09 100644 --- a/src/Common/CColor.cpp +++ b/src/Common/CColor.cpp @@ -1,7 +1,7 @@ #include "CColor.h" CColor::CColor() - : r(0.f), g(0.f), b(0.f), a(0.f) + : R(0.f), G(0.f), B(0.f), A(0.f) { } @@ -9,42 +9,42 @@ CColor::CColor(IInputStream& rInput, bool Integral /*= false*/) { if (Integral) { - r = (u8) rInput.ReadByte() / 255.f; - g = (u8) rInput.ReadByte() / 255.f; - b = (u8) rInput.ReadByte() / 255.f; - a = (u8) rInput.ReadByte() / 255.f; + R = (u8) rInput.ReadByte() / 255.f; + G = (u8) rInput.ReadByte() / 255.f; + B = (u8) rInput.ReadByte() / 255.f; + A = (u8) rInput.ReadByte() / 255.f; } else { - r = rInput.ReadFloat(); - g = rInput.ReadFloat(); - b = rInput.ReadFloat(); - a = rInput.ReadFloat(); + R = rInput.ReadFloat(); + G = rInput.ReadFloat(); + B = rInput.ReadFloat(); + A = rInput.ReadFloat(); } } -CColor::CColor(float rgba) - : r(rgba), g(rgba), b(rgba), a(rgba) +CColor::CColor(float RGBA) + : R(RGBA), G(RGBA), B(RGBA), A(RGBA) { } -CColor::CColor(float _r, float _g, float _b, float _a /*= 1.f*/) - : r(_r), g(_g), b(_b), a(_a) +CColor::CColor(float _R, float _G, float _B, float _A /*= 1.f*/) + : R(_R), G(_G), B(_B), A(_A) { } -void CColor::SetIntegral(u8 rgba) +void CColor::SetIntegral(u8 RGBA) { - float f = rgba / 255.f; - r = g = b = a = f; + float f = RGBA / 255.f; + R = G = B = A = f; } -void CColor::SetIntegral(u8 _r, u8 _g, u8 _b, u8 _a /*= 255*/) +void CColor::SetIntegral(u8 _R, u8 _G, u8 _B, u8 _A /*= 255*/) { - r = _r / 255.f; - g = _g / 255.f; - b = _b / 255.f; - a = _a / 255.f; + R = _R / 255.f; + G = _G / 255.f; + B = _B / 255.f; + A = _A / 255.f; } void CColor::Write(IOutputStream &rOutput, bool Integral /*= false*/) @@ -56,37 +56,37 @@ void CColor::Write(IOutputStream &rOutput, bool Integral /*= false*/) else { - rOutput.WriteFloat(r); - rOutput.WriteFloat(g); - rOutput.WriteFloat(b); - rOutput.WriteFloat(a); + rOutput.WriteFloat(R); + rOutput.WriteFloat(G); + rOutput.WriteFloat(B); + rOutput.WriteFloat(A); } } long CColor::ToLongRGBA() const { - u8 _r = (u8) (r * 255); - u8 _g = (u8) (g * 255); - u8 _b = (u8) (b * 255); - u8 _a = (u8) (a * 255); - return (_r << 24) | (_g << 16) | (_b << 8) | _a; + u8 _R = (u8) (R * 255); + u8 _G = (u8) (G * 255); + u8 _B = (u8) (B * 255); + u8 _A = (u8) (A * 255); + return (_R << 24) | (_G << 16) | (_B << 8) | _A; } long CColor::ToLongARGB() const { - u8 _r = (u8) (r * 255); - u8 _g = (u8) (g * 255); - u8 _b = (u8) (b * 255); - u8 _a = (u8) (a * 255); - return (_a << 24) | (_r << 16) | (_g << 8) | _b; + u8 _R = (u8) (R * 255); + u8 _G = (u8) (G * 255); + u8 _B = (u8) (B * 255); + u8 _A = (u8) (A * 255); + return (_A << 24) | (_R << 16) | (_G << 8) | _B; } bool CColor::operator==(const CColor& rkOther) const { - return ((r == rkOther.r) && - (g == rkOther.g) && - (b == rkOther.b) && - (a == rkOther.a)); + return ((R == rkOther.R) && + (G == rkOther.G) && + (B == rkOther.B) && + (A == rkOther.A)); } bool CColor::operator!=(const CColor& rkOther) const @@ -96,10 +96,10 @@ bool CColor::operator!=(const CColor& rkOther) const CColor CColor::operator+(const CColor& rkOther) const { - float NewR = fmin(r + rkOther.r, 1.f); - float NewG = fmin(g + rkOther.g, 1.f); - float NewB = fmin(b + rkOther.b, 1.f); - float NewA = fmin(a + rkOther.a, 1.f); + float NewR = fmin(R + rkOther.R, 1.f); + float NewG = fmin(G + rkOther.G, 1.f); + float NewB = fmin(B + rkOther.B, 1.f); + float NewA = fmin(A + rkOther.A, 1.f); return CColor(NewR, NewG, NewB, NewA); } @@ -110,10 +110,10 @@ void CColor::operator+=(const CColor& rkOther) CColor CColor::operator-(const CColor& rkOther) const { - float NewR = fmax(r - rkOther.r, 0.f); - float NewG = fmax(g - rkOther.g, 0.f); - float NewB = fmax(b - rkOther.b, 0.f); - float NewA = fmax(a - rkOther.a, 0.f); + float NewR = fmax(R - rkOther.R, 0.f); + float NewG = fmax(G - rkOther.G, 0.f); + float NewB = fmax(B - rkOther.B, 0.f); + float NewA = fmax(A - rkOther.A, 0.f); return CColor(NewR, NewG, NewB, NewA); } @@ -124,10 +124,10 @@ void CColor::operator-=(const CColor& other) CColor CColor::operator*(const CColor& rkOther) const { - float NewR = r * rkOther.r; - float NewG = g * rkOther.g; - float NewB = b * rkOther.b; - float NewA = a * rkOther.a; + float NewR = R * rkOther.R; + float NewG = G * rkOther.G; + float NewB = B * rkOther.B; + float NewA = A * rkOther.A; return CColor(NewR, NewG, NewB, NewA); } @@ -136,26 +136,26 @@ void CColor::operator*=(const CColor& rkOther) *this = (*this * rkOther); } -CColor CColor::operator*(float other) const +CColor CColor::operator*(float Other) const { - float NewR = fmin( fmax(r * other, 0.f), 1.f); - float NewG = fmin( fmax(g * other, 0.f), 1.f); - float NewB = fmin( fmax(b * other, 0.f), 1.f); - float NewA = fmin( fmax(a * other, 0.f), 1.f); + float NewR = fmin( fmax(R * Other, 0.f), 1.f); + float NewG = fmin( fmax(G * Other, 0.f), 1.f); + float NewB = fmin( fmax(B * Other, 0.f), 1.f); + float NewA = fmin( fmax(A * Other, 0.f), 1.f); return CColor(NewR, NewG, NewB, NewA); } -void CColor::operator*=(float other) +void CColor::operator*=(float Other) { - *this = (*this * other); + *this = (*this * Other); } CColor CColor::operator/(const CColor& rkOther) const { - float NewR = (rkOther.r == 0.f) ? 0.f : r / rkOther.r; - float NewG = (rkOther.g == 0.f) ? 0.f : g / rkOther.g; - float NewB = (rkOther.b == 0.f) ? 0.f : b / rkOther.b; - float NewA = (rkOther.a == 0.f) ? 0.f : a / rkOther.a; + float NewR = (rkOther.R == 0.f) ? 0.f : R / rkOther.R; + float NewG = (rkOther.G == 0.f) ? 0.f : G / rkOther.G; + float NewB = (rkOther.B == 0.f) ? 0.f : B / rkOther.B; + float NewA = (rkOther.A == 0.f) ? 0.f : A / rkOther.A; return CColor(NewR, NewG, NewB, NewA); } @@ -165,45 +165,45 @@ void CColor::operator/=(const CColor& rkOther) } // ************ STATIC ************ -CColor CColor::Integral(u8 rgba) +CColor CColor::Integral(u8 RGBA) { - CColor out; - out.SetIntegral(rgba); - return out; + CColor Out; + Out.SetIntegral(RGBA); + return Out; } -CColor CColor::Integral(u8 _r, u8 _g, u8 _b, u8 _a /*= 255*/) +CColor CColor::Integral(u8 _R, u8 _G, u8 _B, u8 _A /*= 255*/) { - CColor out; - out.SetIntegral(_r, _g, _b, _a); - return out; + CColor Out; + Out.SetIntegral(_R, _G, _B, _A); + return Out; } -CColor CColor::RandomColor(bool transparent) +CColor CColor::RandomColor(bool Transparent) { - float _r = (rand() % 255) / 255.f; - float _g = (rand() % 255) / 255.f; - float _b = (rand() % 255) / 255.f; - float _a = (transparent ? (rand() % 255) / 255.f : 0); - return CColor(_r, _g, _b, _a); + float _R = (rand() % 255) / 255.f; + float _G = (rand() % 255) / 255.f; + float _B = (rand() % 255) / 255.f; + float _A = (Transparent ? (rand() % 255) / 255.f : 0); + return CColor(_R, _G, _B, _A); } -CColor CColor::RandomLightColor(bool transparent) +CColor CColor::RandomLightColor(bool Transparent) { - float _r = 0.5f + (rand() % 128) / 255.f; - float _g = 0.5f + (rand() % 128) / 255.f; - float _b = 0.5f + (rand() % 128) / 255.f; - float _a = (transparent ? 0.5f + ((rand() % 128) / 255.f) : 0); - return CColor(_r, _g, _b, _a); + float _R = 0.5f + (rand() % 128) / 255.f; + float _G = 0.5f + (rand() % 128) / 255.f; + float _B = 0.5f + (rand() % 128) / 255.f; + float _A = (Transparent ? 0.5f + ((rand() % 128) / 255.f) : 0); + return CColor(_R, _G, _B, _A); } -CColor CColor::RandomDarkColor(bool transparent) +CColor CColor::RandomDarkColor(bool Transparent) { - float _r = (rand() % 128) / 255.f; - float _g = (rand() % 128) / 255.f; - float _b = (rand() % 128) / 255.f; - float _a = (transparent ? (rand() % 128) / 255.f : 0); - return CColor(_r, _g, _b, _a); + float _R = (rand() % 128) / 255.f; + float _G = (rand() % 128) / 255.f; + float _B = (rand() % 128) / 255.f; + float _A = (Transparent ? (rand() % 128) / 255.f : 0); + return CColor(_R, _G, _B, _A); } // defining predefined colors diff --git a/src/Common/CColor.h b/src/Common/CColor.h index 42ab3054..d3ebf6d2 100644 --- a/src/Common/CColor.h +++ b/src/Common/CColor.h @@ -8,14 +8,14 @@ class CColor { public: - float r, g, b, a; + float R, G, B, A; CColor(); - CColor(IInputStream& rSrc, bool Integral = false); - CColor(float rgba); - CColor(float _r, float _g, float _b, float _a = 1.f); - void SetIntegral(u8 rgba); - void SetIntegral(u8 _r, u8 _g, u8 _b, u8 _a = 255); + CColor(IInputStream& rInput, bool Integral = false); + CColor(float RGBA); + CColor(float _R, float _G, float _B, float A = 1.f); + void SetIntegral(u8 RGBA); + void SetIntegral(u8 _R, u8 _G, u8 _B, u8 _A = 255); void Write(IOutputStream& rOutput, bool Integral = false); long ToLongRGBA() const; @@ -28,17 +28,17 @@ public: void operator-=(const CColor& rkOther); CColor operator*(const CColor& rkOther) const; void operator*=(const CColor& rkOther); - CColor operator*(float other) const; - void operator*=(float other); + CColor operator*(float Other) const; + void operator*=(float Other); CColor operator/(const CColor& rkOther) const; void operator/=(const CColor& rkOther); // Static - static CColor Integral(u8 rgba); - static CColor Integral(u8 _r, u8 _g, u8 _b, u8 _a = 255); - static CColor RandomColor(bool transparent); - static CColor RandomLightColor(bool transparent); - static CColor RandomDarkColor(bool transparent); + static CColor Integral(u8 RGBA); + static CColor Integral(u8 _R, u8 _G, u8 _B, u8 _A = 255); + static CColor RandomColor(bool Transparent); + static CColor RandomLightColor(bool Transparent); + static CColor RandomDarkColor(bool Transparent); // some predefined colors below for ease of use static const CColor skRed; diff --git a/src/Common/CFourCC.cpp b/src/Common/CFourCC.cpp deleted file mode 100644 index 9757d6dc..00000000 --- a/src/Common/CFourCC.cpp +++ /dev/null @@ -1,120 +0,0 @@ -#include "CFourCC.h" - -// ************ CONSTRUCTORS ************ -CFourCC::CFourCC() -{ - memset(mFourCC, 0, 4); -} - -CFourCC::CFourCC(const char *src) -{ - *this = src; -} - -CFourCC::CFourCC(const TString& src) -{ - *this = src; -} - -CFourCC::CFourCC(u32 src) -{ - *this = src; -} - -CFourCC::CFourCC(IInputStream& src) -{ - src.ReadBytes(&mFourCC[0], 4); -} - -// ************ FUNCTIONALITY ************ -void CFourCC::Write(IOutputStream &Output) -{ - Output.WriteBytes(mFourCC, 4); -} - -u32 CFourCC::ToLong() const -{ - return mFourCC[0] << 24 | mFourCC[1] << 16 | mFourCC[2] << 8 | mFourCC[3]; -} - -TString CFourCC::ToString() const -{ - return TString(mFourCC, 4); -} - -CFourCC CFourCC::ToUpper() const -{ - CFourCC Out; - - for (int c = 0; c < 4; c++) - { - if ((mFourCC[c] >= 0x61) && (mFourCC[c] <= 0x7A)) - Out.mFourCC[c] = mFourCC[c] - 0x20; - else - Out.mFourCC[c] = mFourCC[c]; - } - - return Out; -} - -// ************ OPERATORS ************ -CFourCC& CFourCC::operator=(const char *src) -{ - memcpy(&mFourCC[0], src, 4); - return *this; -} - -CFourCC& CFourCC::operator=(const TString& src) -{ - memcpy(&mFourCC[0], src.CString(), 4); - return *this; -} - -CFourCC& CFourCC::operator=(u32 src) -{ - mFourCC[0] = (src >> 24) & 0xFF; - mFourCC[1] = (src >> 16) & 0xFF; - mFourCC[2] = (src >> 8) & 0xFF; - mFourCC[3] = (src >> 0) & 0xFF; - return *this; -} - -bool CFourCC::operator==(const CFourCC& other) const -{ - return ((mFourCC[0] == other.mFourCC[0]) && (mFourCC[1] == other.mFourCC[1]) && (mFourCC[2] == other.mFourCC[2]) && (mFourCC[3] == other.mFourCC[3])); -} - -bool CFourCC::operator!=(const CFourCC& other) const -{ - return (!(*this == other)); -} - -bool CFourCC::operator>(const CFourCC& other) const -{ - return (ToLong() > other.ToLong()); -} - -bool CFourCC::operator>=(const CFourCC& other) const -{ - return (ToLong() >= other.ToLong()); -} - -bool CFourCC::operator<(const CFourCC& other) const -{ - return (ToLong() < other.ToLong()); -} - -bool CFourCC::operator<=(const CFourCC& other) const -{ - return (ToLong() <= other.ToLong()); -} - -char CFourCC::operator[](int index) -{ - return mFourCC[index]; -} - -const char CFourCC::operator[](int index) const -{ - return mFourCC[index]; -} diff --git a/src/Common/CFourCC.h b/src/Common/CFourCC.h index 5ad6a66c..fcc34483 100644 --- a/src/Common/CFourCC.h +++ b/src/Common/CFourCC.h @@ -11,30 +11,73 @@ class CFourCC char mFourCC[4]; public: // Constructors - CFourCC(); - CFourCC(const char *src); - CFourCC(const TString& src); - CFourCC(u32 src); - CFourCC(IInputStream& src); + CFourCC() { memset(mFourCC, 0, 4); } + CFourCC(const char *pkSrc) { *this = pkSrc; } + CFourCC(const TString& rkSrc) { *this = rkSrc; } + CFourCC(u32 Src) { *this = Src; } + CFourCC(IInputStream& rSrc) { rSrc.ReadBytes(&mFourCC[0], 4); } // Functionality - void Write(IOutputStream& Output); - u32 ToLong() const; - TString ToString() const; - CFourCC ToUpper() const; + inline void Write(IOutputStream& rOutput) + { + rOutput.WriteBytes(&mFourCC[0], 4); + } + + inline u32 ToLong() const + { + return mFourCC[0] << 24 | mFourCC[1] << 16 | mFourCC[2] << 8 | mFourCC[3]; + } + + inline TString ToString() const + { + return TString(mFourCC, 4); + } + + inline CFourCC ToUpper() const + { + CFourCC Out; + + for (int iChr = 0; iChr < 4; iChr++) + { + if ((mFourCC[iChr] >= 0x61) && (mFourCC[iChr] <= 0x7A)) + Out.mFourCC[iChr] = mFourCC[iChr] - 0x20; + else + Out.mFourCC[iChr] = mFourCC[iChr]; + } + + return Out; + } // Operators - CFourCC& operator=(const char *src); - CFourCC& operator=(const TString& src); - CFourCC& operator=(u32 src); - bool operator==(const CFourCC& other) const; - bool operator!=(const CFourCC& other) const; - bool operator>(const CFourCC& other) const; - bool operator>=(const CFourCC& other) const; - bool operator<(const CFourCC& other) const; - bool operator<=(const CFourCC& other) const; - char operator[](int index); - const char operator[](int index) const; + inline CFourCC& operator=(const char *pkSrc) + { + memcpy(&mFourCC[0], pkSrc, 4); + return *this; + } + + inline CFourCC& operator=(const TString& rkSrc) + { + memcpy(&mFourCC[0], rkSrc.CString(), 4); + return *this; + } + + inline CFourCC& operator=(u32 Src) + { + mFourCC[0] = (Src >> 24) & 0xFF; + mFourCC[1] = (Src >> 16) & 0xFF; + mFourCC[2] = (Src >> 8) & 0xFF; + mFourCC[3] = (Src >> 0) & 0xFF; + return *this; + } + + inline bool operator==(const CFourCC& rkOther) const { return ((mFourCC[0] == rkOther.mFourCC[0]) && (mFourCC[1] == rkOther.mFourCC[1]) && (mFourCC[2] == rkOther.mFourCC[2]) && (mFourCC[3] == rkOther.mFourCC[3])); } + inline bool operator!=(const CFourCC& rkOther) const { return (!(*this == rkOther)); } + inline bool operator>(const CFourCC& rkOther) const { return (ToLong() > rkOther.ToLong()); } + inline bool operator>=(const CFourCC& rkOther) const { return (ToLong() >= rkOther.ToLong()); } + inline bool operator<(const CFourCC& rkOther) const { return (ToLong() < rkOther.ToLong()); } + inline bool operator<=(const CFourCC& rkOther) const { return (ToLong() <= rkOther.ToLong()); } + inline char operator[](int Index) { return mFourCC[Index]; } + inline const char operator[](int Index) const { return mFourCC[Index]; } }; #endif // CFOURCC_H diff --git a/src/Common/CHashFNV1A.cpp b/src/Common/CHashFNV1A.cpp deleted file mode 100644 index c325e813..00000000 --- a/src/Common/CHashFNV1A.cpp +++ /dev/null @@ -1,72 +0,0 @@ -#include "CHashFNV1A.h" - -const u64 CHashFNV1A::skFNVOffsetBasis32 = 0x811C9DC5; -const u64 CHashFNV1A::skFNVOffsetBasis64 = 0xCBF29CE484222325; -const u64 CHashFNV1A::skFNVPrime32 = 0x1000193; -const u64 CHashFNV1A::skFNVPrime64 = 0x100000001B3; - -CHashFNV1A::CHashFNV1A() -{ - Init32(); -} - -void CHashFNV1A::Init32() -{ - mHashLength = e32Bit; - mHash = skFNVOffsetBasis32; -} - -void CHashFNV1A::Init64() -{ - mHashLength = e64Bit; - mHash = skFNVOffsetBasis64; -} - -void CHashFNV1A::HashData(const void *pData, u32 Size) -{ - const char *pCharData = (const char*) pData; - u64 FNVPrime = (mHashLength == e32Bit) ? skFNVPrime32 : skFNVPrime64; - - for (u32 i = 0; i < Size; i++) - { - mHash ^= *pCharData; - mHash *= FNVPrime; - pCharData++; - } -} - -u32 CHashFNV1A::GetHash32() -{ - return (u32) mHash; -} - -u64 CHashFNV1A::GetHash64() -{ - return mHash; -} - -// ************ CONVENIENCE FUNCTIONS ************ -void CHashFNV1A::HashByte(const u8& v) -{ - HashData(&v, 1); -} - -void CHashFNV1A::HashShort(const u16& v) -{ - HashData(&v, 2); -} - -void CHashFNV1A::HashLong(const u32& v) -{ - HashData(&v, 4); -} - -void CHashFNV1A::HashFloat(const float& v) -{ - HashData(&v, 4); -} - -void CHashFNV1A::HashString(const TString& v) -{ - HashData(v.Data(), v.Size()); -} diff --git a/src/Common/CHashFNV1A.h b/src/Common/CHashFNV1A.h index 84b6c764..04b78c5f 100644 --- a/src/Common/CHashFNV1A.h +++ b/src/Common/CHashFNV1A.h @@ -12,25 +12,51 @@ class CHashFNV1A e32Bit, e64Bit } mHashLength; - static const u64 skFNVOffsetBasis32; - static const u64 skFNVOffsetBasis64; - static const u64 skFNVPrime32; - static const u64 skFNVPrime64; + static const u64 skFNVOffsetBasis32 = 0x811C9DC5; + static const u64 skFNVOffsetBasis64 = 0xCBF29CE484222325; + static const u64 skFNVPrime32 = 0x1000193; + static const u64 skFNVPrime64 = 0x100000001B3; public: - CHashFNV1A(); - void Init32(); - void Init64(); - void HashData(const void *pData, u32 Size); - u32 GetHash32(); - u64 GetHash64(); + CHashFNV1A() + { + Init32(); + } + + void Init32() + { + mHashLength = e32Bit; + mHash = skFNVOffsetBasis32; + } + + void Init64() + { + mHashLength = e64Bit; + mHash = skFNVOffsetBasis64; + } + + void HashData(const void *pkData, u32 Size) + { + const char *pkCharData = (const char*) pkData; + u64 FNVPrime = (mHashLength == e32Bit) ? skFNVPrime32 : skFNVPrime64; + + for (u32 iByte = 0; iByte < Size; iByte++) + { + mHash ^= *pkCharData; + mHash *= FNVPrime; + pkCharData++; + } + } + + inline u32 GetHash32() { return (u32) mHash; } + inline u64 GetHash64() { return mHash; } // Convenience functions - void HashByte(const u8& v); - void HashShort(const u16& v); - void HashLong(const u32& v); - void HashFloat(const float& v); - void HashString(const TString& v); + inline void HashByte(const u8& rkVal) { HashData(&rkVal, 1); } + inline void HashShort(const u16& rkVal) { HashData(&rkVal, 2); } + inline void HashLong(const u32& rkVal) { HashData(&rkVal, 4); } + inline void HashFloat(const float& rkVal) { HashData(&rkVal, 4); } + inline void HashString(const TString& rkVal) { HashData(rkVal.Data(), rkVal.Size()); } }; #endif // CHASHFNV1A_H diff --git a/src/Common/CTimer.cpp b/src/Common/CTimer.cpp index 2a3c8a6f..f960b190 100644 --- a/src/Common/CTimer.cpp +++ b/src/Common/CTimer.cpp @@ -1,12 +1,13 @@ #include "CTimer.h" +#include #include CTimer::CTimer() + : mStartTime(0) + , mStopTime(0) + , mStarted(false) + , mPaused(false) { - mStartTime = 0; - mStopTime = 0; - mStarted = false; - mPaused = false; } void CTimer::Start() @@ -83,7 +84,13 @@ double CTimer::Time() return mStopTime; } +// ************ STATIC ************ double CTimer::GlobalTime() { return (double) clock() / CLOCKS_PER_SEC; } + +float CTimer::SecondsMod900() +{ + return fmodf((float) GlobalTime(), 900.f); +} diff --git a/src/Common/CTimer.h b/src/Common/CTimer.h index 0aa508f8..f6a60d43 100644 --- a/src/Common/CTimer.h +++ b/src/Common/CTimer.h @@ -23,6 +23,7 @@ public: // Static static double GlobalTime(); + static float SecondsMod900(); }; #endif // CTIMER_H diff --git a/src/Common/CUniqueID.cpp b/src/Common/CUniqueID.cpp index 85f85967..14a26d7f 100644 --- a/src/Common/CUniqueID.cpp +++ b/src/Common/CUniqueID.cpp @@ -11,9 +11,9 @@ using IOUtil::eLittleEndian; using IOUtil::eBigEndian; CUniqueID::CUniqueID() + : mLength(eInvalidUIDLength) { memset(mID, 0xFF, 16); - mLength = eInvalidUIDLength; } CUniqueID::CUniqueID(u64 ID) @@ -72,15 +72,15 @@ CUniqueID::CUniqueID(u64 Part1, u64 Part2) mLength = e128Bit; } -CUniqueID::CUniqueID(const char* ID) +CUniqueID::CUniqueID(const char* pkID) { - *this = CUniqueID::FromString(ID); + *this = CUniqueID::FromString(pkID); } -CUniqueID::CUniqueID(IInputStream& Input, EUIDLength Length) +CUniqueID::CUniqueID(IInputStream& rInput, EUIDLength Length) { memset(mID, 0, 16); - Input.ReadBytes(&mID[16 - Length], Length); + rInput.ReadBytes(&mID[16 - Length], Length); if (Length != e128Bit) if (kSystemEndianness == eLittleEndian) @@ -120,8 +120,8 @@ TString CUniqueID::ToString() const std::stringstream Ret; Ret << std::hex << std::setfill('0'); - for (u32 i = 0; i < 16; i++) - Ret << std::setw(2) << (u32) mID[i]; + for (u32 iByte = 0; iByte < 16; iByte++) + Ret << std::setw(2) << (u32) mID[iByte]; return Ret.str(); } @@ -159,44 +159,44 @@ bool CUniqueID::IsValid() const } // ************ OPERATORS ************ -void CUniqueID::operator=(const u64& Input) +void CUniqueID::operator=(const u64& rkInput) { - *this = CUniqueID(Input); + *this = CUniqueID(rkInput); } -void CUniqueID::operator=(const char* Input) +void CUniqueID::operator=(const char* pkInput) { - *this = CUniqueID(Input); + *this = CUniqueID(pkInput); } -bool CUniqueID::operator==(const CUniqueID& Other) const +bool CUniqueID::operator==(const CUniqueID& rkOther) const { - return ((mLength == Other.mLength) && - (memcmp(mID, Other.mID, 16) == 0)); + return ((mLength == rkOther.mLength) && + (memcmp(mID, rkOther.mID, 16) == 0)); } -bool CUniqueID::operator!=(const CUniqueID& Other) const +bool CUniqueID::operator!=(const CUniqueID& rkOther) const { - return (!(*this == Other)); + return (!(*this == rkOther)); } -bool CUniqueID::operator>(const CUniqueID& Other) const +bool CUniqueID::operator>(const CUniqueID& rkOther) const { - if (mLength != Other.mLength) - return mLength > Other.mLength; + if (mLength != rkOther.mLength) + return mLength > rkOther.mLength; switch (mLength) { case e32Bit: - return (ToLong() > Other.ToLong()); + return (ToLong() > rkOther.ToLong()); case e64Bit: - return (ToLongLong() > Other.ToLongLong()); + return (ToLongLong() > rkOther.ToLongLong()); case e128Bit: - for (u32 i = 0; i < 16; i++) - if (mID[i] != Other.mID[i]) - return (mID[i] > Other.mID[i]); + for (u32 iByte = 0; iByte < 16; iByte++) + if (mID[iByte] != rkOther.mID[iByte]) + return (mID[iByte] > rkOther.mID[iByte]); return false; default: @@ -204,28 +204,28 @@ bool CUniqueID::operator>(const CUniqueID& Other) const } } -bool CUniqueID::operator>=(const CUniqueID& Other) const +bool CUniqueID::operator>=(const CUniqueID& rkOther) const { - return ((*this == Other) || (*this > Other)); + return ((*this == rkOther) || (*this > rkOther)); } -bool CUniqueID::operator<(const CUniqueID& Other) const +bool CUniqueID::operator<(const CUniqueID& rkOther) const { - if (mLength != Other.mLength) - return mLength < Other.mLength; + if (mLength != rkOther.mLength) + return mLength < rkOther.mLength; switch (mLength) { case e32Bit: - return (ToLong() < Other.ToLong()); + return (ToLong() < rkOther.ToLong()); case e64Bit: - return (ToLongLong() < Other.ToLongLong()); + return (ToLongLong() < rkOther.ToLongLong()); case e128Bit: - for (u32 i = 0; i < 16; i++) - if (mID[i] != Other.mID[i]) - return (mID[i] < Other.mID[i]); + for (u32 iByte = 0; iByte < 16; iByte++) + if (mID[iByte] != rkOther.mID[iByte]) + return (mID[iByte] < rkOther.mID[iByte]); return false; default: @@ -233,9 +233,9 @@ bool CUniqueID::operator<(const CUniqueID& Other) const } } -bool CUniqueID::operator<=(const CUniqueID& Other) const +bool CUniqueID::operator<=(const CUniqueID& rkOther) const { - return ((*this == Other) || (*this < Other)); + return ((*this == rkOther) || (*this < rkOther)); } bool CUniqueID::operator==(u64 Other) const @@ -249,10 +249,10 @@ bool CUniqueID::operator!=(u64 Other) const } // ************ STATIC ************ -CUniqueID CUniqueID::FromString(const TString& String) +CUniqueID CUniqueID::FromString(const TString& rkString) { // If the input is a hex ID in string form, then preserve it... otherwise, generate an ID by hashing the string - TString Name = String.GetFileName(false); + TString Name = rkString.GetFileName(false); u32 NameLength = Name.Length(); if (Name.IsHexString()) @@ -296,7 +296,7 @@ CUniqueID CUniqueID::FromString(const TString& String) } } - return CUniqueID(String.Hash64()); + return CUniqueID(rkString.Hash64()); } CUniqueID CUniqueID::FromData(void *pData, EUIDLength Length) @@ -312,8 +312,8 @@ CUniqueID CUniqueID::RandomID() CUniqueID ID; ID.mLength = e128Bit; - for (u32 i = 0; i < 16; i++) - ID.mID[i] = rand() & 0xFF; + for (u32 iByte = 0; iByte < 16; iByte++) + ID.mID[iByte] = rand() & 0xFF; return ID; } diff --git a/src/Common/CUniqueID.h b/src/Common/CUniqueID.h index 8d6a17b0..8f5e6d66 100644 --- a/src/Common/CUniqueID.h +++ b/src/Common/CUniqueID.h @@ -1,8 +1,8 @@ #ifndef CUNIQUEID_H #define CUNIQUEID_H -#include "types.h" #include "TString.h" +#include "types.h" #include enum EUIDLength @@ -23,7 +23,7 @@ public: CUniqueID(u64 ID); CUniqueID(u64 ID, EUIDLength Length); CUniqueID(u64 Part1, u64 Part2); - CUniqueID(const char* ID); + CUniqueID(const char* pkID); CUniqueID(IInputStream& Input, EUIDLength Length); u32 ToLong() const; u64 ToLongLong() const; @@ -34,20 +34,20 @@ public: bool IsValid() const; // Operators - void operator=(const u64& Input); - void operator=(const char *Input); - bool operator==(const CUniqueID& Other) const; - bool operator!=(const CUniqueID& Other) const; - bool operator>(const CUniqueID& Other) const; - bool operator>=(const CUniqueID& Other) const; - bool operator<(const CUniqueID& Other) const; - bool operator<=(const CUniqueID& Other) const; + void operator=(const u64& rkInput); + void operator=(const char *pkInput); + bool operator==(const CUniqueID& rkOther) const; + bool operator!=(const CUniqueID& rkOther) const; + bool operator>(const CUniqueID& rkOther) const; + bool operator>=(const CUniqueID& rkOther) const; + bool operator<(const CUniqueID& rkOther) const; + bool operator<=(const CUniqueID& rkOther) const; bool operator==(u64 Other) const; bool operator!=(u64 Other) const; // Static - static CUniqueID FromString(const TString& String); - static CUniqueID FromData(void *pData, EUIDLength Length); + static CUniqueID FromString(const TString& rkString); + static CUniqueID FromData(void *pkData, EUIDLength Length); static CUniqueID RandomID(); static CUniqueID skInvalidID32; diff --git a/src/Common/Common.pro b/src/Common/Common.pro index 9c4a8557..433fd825 100644 --- a/src/Common/Common.pro +++ b/src/Common/Common.pro @@ -56,7 +56,6 @@ INCLUDEPATH += $$PWD/.. \ # Header Files HEADERS += \ - AnimUtil.h \ CColor.h \ CFourCC.h \ CHashFNV1A.h \ @@ -73,10 +72,7 @@ HEADERS += \ # Source Files SOURCES += \ - AnimUtil.cpp \ CColor.cpp \ - CFourCC.cpp \ - CHashFNV1A.cpp \ CompressionUtil.cpp \ CTimer.cpp \ CUniqueID.cpp \ diff --git a/src/Common/Flags.h b/src/Common/Flags.h index 38e6591b..48222ce3 100644 --- a/src/Common/Flags.h +++ b/src/Common/Flags.h @@ -10,9 +10,9 @@ class TFlags public: TFlags() : mValue(0) {} - TFlags(int v) : mValue(v) {} - TFlags(u32 v) : mValue(v) {} - TFlags(FlagEnum v) : mValue(v) {} + TFlags(int Val) : mValue(Val) {} + TFlags(u32 Val) : mValue(Val) {} + TFlags(FlagEnum Val) : mValue(Val) {} inline operator int() const { return mValue; } inline bool operator!() const { return !mValue; } diff --git a/src/Common/Log.cpp b/src/Common/Log.cpp index dbc26584..bc8005ad 100644 --- a/src/Common/Log.cpp +++ b/src/Common/Log.cpp @@ -100,7 +100,7 @@ void FileWrite(const TString& rkFilename, const TString& rkMessage) void FileWrite(const TString& rkFilename, u32 Offset, const TString& rkMessage) { - Write(rkFilename + " : " + TString::HexString(Offset) + " - " + rkMessage); + Write(rkFilename + " : " + TString::HexString(Offset, 0) + " - " + rkMessage); } void FileError(const TString& rkFilename, const TString& rkMessage) @@ -110,7 +110,7 @@ void FileError(const TString& rkFilename, const TString& rkMessage) void FileError(const TString& rkFilename, u32 Offset, const TString& rkMessage) { - Error(rkFilename + " : " + TString::HexString(Offset) + " - " + rkMessage); + Error(rkFilename + " : " + TString::HexString(Offset, 0) + " - " + rkMessage); } void FileWarning(const TString& rkFilename, const TString& rkMessage) @@ -120,7 +120,7 @@ void FileWarning(const TString& rkFilename, const TString& rkMessage) void FileWarning(const TString& rkFilename, u32 Offset, const TString& rkMessage) { - Warning(rkFilename + " : " + TString::HexString(Offset) + " - " + rkMessage); + Warning(rkFilename + " : " + TString::HexString(Offset, 0) + " - " + rkMessage); } const TStringList& GetErrorLog() diff --git a/src/Common/TString.h b/src/Common/TString.h index 50603d5b..5b5aea0c 100644 --- a/src/Common/TString.h +++ b/src/Common/TString.h @@ -47,13 +47,13 @@ public: { } - TBasicString(u32 size) - : mInternalString(size, 0) + TBasicString(u32 Size) + : mInternalString(Size, 0) { } - TBasicString(u32 size, CharType fill) - : mInternalString(size, fill) + TBasicString(u32 Size, CharType Fill) + : mInternalString(Size, Fill) { } @@ -63,8 +63,8 @@ public: mInternalString = pkText; } - TBasicString(const CharType* pkText, u32 length) - : mInternalString(pkText, length) + TBasicString(const CharType* pkText, u32 Length) + : mInternalString(pkText, Length) { } @@ -84,13 +84,13 @@ public: return mInternalString.data(); } - inline CharType At(u32 pos) const + inline CharType At(u32 Pos) const { #if _DEBUG - if (Size() <= pos) + if (Size() <= Pos) throw std::out_of_range("Invalid position passed to TBasicString::At()"); #endif - return mInternalString.at(pos); + return mInternalString.at(Pos); } inline CharType Front() const @@ -115,56 +115,56 @@ public: inline u32 IndexOf(const CharType* pkCharacters) const { - size_t pos = mInternalString.find_first_of(pkCharacters); + size_t Pos = mInternalString.find_first_of(pkCharacters); - if (pos == _TStdString::npos) + if (Pos == _TStdString::npos) return -1; else - return (u32) pos; + return (u32) Pos; } inline u32 LastIndexOf(const CharType* pkCharacters) const { - size_t pos = mInternalString.find_last_of(pkCharacters); + size_t Pos = mInternalString.find_last_of(pkCharacters); - if (pos == _TStdString::npos) + if (Pos == _TStdString::npos) return -1; else - return (u32) pos; + return (u32) Pos; } // Modify String - inline _TString SubString(int startPos, int length) const + inline _TString SubString(int StartPos, int Length) const { - return mInternalString.substr(startPos, length); + return mInternalString.substr(StartPos, Length); } - inline void Insert(u32 pos, CharType c) + inline void Insert(u32 Pos, CharType Chr) { #ifdef _DEBUG - if (Size() < pos) + if (Size() < Pos) throw std::out_of_range("Invalid pos passed to TBasicString::Insert(CharType)"); #endif - mInternalString.insert(pos, 1, c); + mInternalString.insert(Pos, 1, Chr); } - inline void Insert(u32 pos, const CharType* pkStr) + inline void Insert(u32 Pos, const CharType* pkStr) { #ifdef _DEBUG - if (Size() < pos) + if (Size() < Pos) throw std::out_of_range("Invalid pos passed to TBasicString::Insert(const CharType*)"); #endif - mInternalString.insert(pos, pkStr); + mInternalString.insert(Pos, pkStr); } - inline void Insert(u32 pos, const _TString& rkStr) + inline void Insert(u32 Pos, const _TString& rkStr) { - Insert(pos, rkStr.CString()); + Insert(Pos, rkStr.CString()); } - inline void Append(CharType c) + inline void Append(CharType Chr) { - mInternalString.append(1, c); + mInternalString.append(1, Chr); } inline void Append(const CharType* pkText) @@ -177,9 +177,9 @@ public: mInternalString.append(rkStr.CString()); } - inline void Prepend(CharType c) + inline void Prepend(CharType Chr) { - Insert(0, c); + Insert(0, Chr); } inline void Prepend(const CharType* pkText) @@ -195,134 +195,134 @@ public: _TString ToUpper() const { // todo: doesn't handle accented characters - _TString out(Size()); + _TString Out(Size()); for (u32 iChar = 0; iChar < Size(); iChar++) { - CharType c = At(iChar); + CharType Chr = At(iChar); - if (c >= 'a' && c <= 'z') - out[iChar] = c - 0x20; + if (Chr >= 'a' && Chr <= 'z') + Out[iChar] = Chr - 0x20; else - out[iChar] = c; + Out[iChar] = Chr; } - return out; + return Out; } _TString ToLower() const { // todo: doesn't handle accented characters - _TString out(Size()); + _TString Out(Size()); for (u32 iChar = 0; iChar < Size(); iChar++) { - CharType c = At(iChar); + CharType Chr = At(iChar); - if (c >= 'A' && c <= 'Z') - out[iChar] = c + 0x20; + if (Chr >= 'A' && Chr <= 'Z') + Out[iChar] = Chr + 0x20; else - out[iChar] = c; + Out[iChar] = Chr; } - return out; + return Out; } _TString Trimmed() const { - int start = -1, end = -1; + int Start = -1, End = -1; for (u32 iChar = 0; iChar < Size(); iChar++) { if (!IsWhitespace(mInternalString[iChar])) { - start = iChar; + Start = iChar; break; } } // If start is still -1 then there are no non-whitespace characters in this string. Return early. - if (start == -1) return ""; + if (Start == -1) return ""; for (int iChar = Size() - 1; iChar >= 0; iChar--) { if (!IsWhitespace(mInternalString[iChar])) { - end = iChar + 1; + End = iChar + 1; break; } } - return SubString(start, end - start); + return SubString(Start, End - Start); } - inline _TString Truncate(u32 amount) const + inline _TString Truncate(u32 Amount) const { - return SubString(0, amount); + return SubString(0, Amount); } - inline _TString ChopFront(u32 amount) const + inline _TString ChopFront(u32 Amount) const { - if (Size() <= amount) return ""; - return SubString(amount, Size() - amount); + if (Size() <= Amount) return ""; + return SubString(Amount, Size() - Amount); } - inline _TString ChopBack(u32 amount) const + inline _TString ChopBack(u32 Amount) const { - if (Size() <= amount) return ""; - return SubString(0, Size() - amount); + if (Size() <= Amount) return ""; + return SubString(0, Size() - Amount); } u32 Hash32() const { - u32 hash = 0; + u32 Hash = 0; for (u32 iChar = 0; iChar < Size(); iChar++) { - hash += At(iChar); - hash *= 101; + Hash += At(iChar); + Hash *= 101; } - return hash; + return Hash; } u64 Hash64() const { - u64 hash = 0; + u64 Hash = 0; for (u32 iChar = 0; iChar < Size(); iChar++) { - hash += At(iChar); - hash *= 101; + Hash += At(iChar); + Hash *= 101; } - return hash; + return Hash; } - inline u32 ToInt32(int base = 16) const + inline u32 ToInt32(int Base = 16) const { - return std::stoul(mInternalString, nullptr, base); + return std::stoul(mInternalString, nullptr, Base); } - inline u64 ToInt64(int base = 16) const + inline u64 ToInt64(int Base = 16) const { - return std::stoull(mInternalString, nullptr, base); + return std::stoull(mInternalString, nullptr, Base); } - void ToInt128(CharType* pOut, int base = 16) const + void ToInt128(CharType* pOut, int Base = 16) const { // TODO: only works in base 16 - u64 part1 = std::stoull(mInternalString.substr(0, 16), nullptr, base); - u64 part2 = std::stoull(mInternalString.substr(16, 16), nullptr, base); + u64 Part1 = std::stoull(mInternalString.substr(0, 16), nullptr, Base); + u64 Part2 = std::stoull(mInternalString.substr(16, 16), nullptr, Base); if (IOUtil::kSystemEndianness == IOUtil::eLittleEndian) { - IOUtil::SwapBytes(part1); - IOUtil::SwapBytes(part2); + IOUtil::SwapBytes(Part1); + IOUtil::SwapBytes(Part2); } - memcpy(pOut, &part1, 8); - memcpy(pOut + 8, &part2, 8); + memcpy(pOut, &Part1, 8); + memcpy(pOut + 8, &Part2, 8); } inline float ToFloat() const @@ -337,8 +337,8 @@ public: _TStringList Split(const CharType* pkTokens) const { - _TStringList out; - u32 lastSplit = 0; + _TStringList Out; + u32 LastSplit = 0; // Iterate over all characters in the input string for (u32 iChr = 0; iChr < Length(); iChr++) @@ -351,26 +351,26 @@ public: if (mInternalString[iChr] == pkTokens[iTok]) { // Token found - split string - if (iChr > lastSplit) - out.push_back(SubString(lastSplit, iChr - lastSplit)); + if (iChr > LastSplit) + Out.push_back(SubString(LastSplit, iChr - LastSplit)); - lastSplit = iChr + 1; + LastSplit = iChr + 1; break; } } } // Add final string - if (lastSplit != Length()) - out.push_back(SubString(lastSplit, Length() - lastSplit)); + if (LastSplit != Length()) + Out.push_back(SubString(LastSplit, Length() - LastSplit)); - return out; + return Out; } - void EnsureEndsWith(CharType chr) + void EnsureEndsWith(CharType Chr) { - if (Back() != chr) - Append(chr); + if (Back() != Chr) + Append(Chr); } void EnsureEndsWith(const CharType* pkText) @@ -385,92 +385,92 @@ public: return (Size() == 0); } - bool StartsWith(const _TString& str) const + bool StartsWith(const _TString& rkStr) const { - if (Size() < str.Size()) + if (Size() < rkStr.Size()) return false; - return (SubString(0, str.Size()) == str); + return (SubString(0, rkStr.Size()) == rkStr); } - bool EndsWith(const _TString& str) const + bool EndsWith(const _TString& rkStr) const { - if (Size() < str.Size()) + if (Size() < rkStr.Size()) return false; - return (SubString(Size() - str.Size(), str.Size()) == str); + return (SubString(Size() - rkStr.Size(), rkStr.Size()) == rkStr); } - bool Contains(_TString str, bool caseSensitive = true) const + bool Contains(_TString Str, bool CaseSensitive = true) const { - if (Size() < str.Size()) return false; + if (Size() < Str.Size()) return false; - _TString checkStr(caseSensitive ? *this : ToUpper()); - if (caseSensitive) str = str.ToUpper(); + _TString CheckStr(CaseSensitive ? *this : ToUpper()); + if (CaseSensitive) Str = Str.ToUpper(); - u32 latestPossibleStart = Size() - str.Size(); - u32 match = 0; + u32 LatestPossibleStart = Size() - Str.Size(); + u32 Match = 0; - for (u32 iChr = 0; iChr < Size() && iChr < str.Size(); iChr++) + for (u32 iChr = 0; iChr < Size() && iChr < Str.Size(); iChr++) { // If the current character matches, increment match - if (checkStr.At(iChr) == str.At(match)) - match++; + if (CheckStr.At(iChr) == Str.At(Match)) + Match++; // Otherwise... else { // We need to also compare this character to the first // character of the string (unless we just did that) - if (match > 0) + if (Match > 0) iChr--; - match = 0; + Match = 0; - if (iChr > latestPossibleStart) + if (iChr > LatestPossibleStart) break; } // If we've matched the entire string, then we can return true - if (match == str.Size()) return true; + if (Match == Str.Size()) return true; } return false; } - bool IsHexString(bool requirePrefix = false, u32 width = -1) const + bool IsHexString(bool RequirePrefix = false, u32 Width = -1) const { - _TString str(*this); - bool hasPrefix = str.StartsWith("0x"); + _TString Str(*this); + bool HasPrefix = Str.StartsWith("0x"); // If we're required to match the prefix and prefix is missing, return false - if (requirePrefix && !hasPrefix) + if (RequirePrefix && !HasPrefix) return false; - if (width == -1) + if (Width == -1) { // If the string has the 0x prefix, remove it - if (hasPrefix) - str = str.ChopFront(2); + if (HasPrefix) + Str = Str.ChopFront(2); // If we have a variable width then assign the width value to the string size - width = str.Size(); + Width = Str.Size(); } // If the string starts with the prefix and the length matches the string, remove the prefix - else if ((str.Size() == width + 2) && (hasPrefix)) - str = str.ChopFront(2); + else if ((Str.Size() == Width + 2) && (HasPrefix)) + Str = Str.ChopFront(2); // By this point, the string size and the width should match. If they don't, return false. - if (str.Size() != width) return false; + if (Str.Size() != Width) return false; // Now we can finally check the actual string and make sure all the characters are valid hex characters. - for (u32 c = 0; c < width; c++) + for (u32 iChr = 0; iChr < Width; iChr++) { - char chr = str[c]; - if (!((chr >= '0') && (chr <= '9')) && - !((chr >= 'a') && (chr <= 'f')) && - !((chr >= 'A') && (chr <= 'F'))) + char Chr = Str[iChr]; + if (!((Chr >= '0') && (Chr <= '9')) && + !((Chr >= 'a') && (Chr <= 'f')) && + !((Chr >= 'A') && (Chr <= 'F'))) return false; } @@ -485,36 +485,36 @@ public: // Get Filename Components _TString GetFileDirectory() const { - size_t endPath = mInternalString.find_last_of("\\/"); - return SubString(0, endPath + 1); + size_t EndPath = mInternalString.find_last_of("\\/"); + return SubString(0, EndPath + 1); } - _TString GetFileName(bool withExtension = true) const + _TString GetFileName(bool WithExtension = true) const { - size_t endPath = mInternalString.find_last_of("\\/") + 1; + size_t EndPath = mInternalString.find_last_of("\\/") + 1; - if (withExtension) + if (WithExtension) { - return SubString(endPath, Size() - endPath); + return SubString(EndPath, Size() - EndPath); } else { - size_t endName = mInternalString.find_last_of("."); - return SubString(endPath, endName - endPath); + size_t EndName = mInternalString.find_last_of("."); + return SubString(EndPath, EndName - EndPath); } } _TString GetFileExtension() const { - size_t endName = mInternalString.find_last_of("."); - return SubString(endName + 1, Size() - endName); + size_t EndName = mInternalString.find_last_of("."); + return SubString(EndName + 1, Size() - EndName); } _TString GetFilePathWithoutExtension() const { - size_t endName = mInternalString.find_last_of("."); - return SubString(0, endName); + size_t EndName = mInternalString.find_last_of("."); + return SubString(0, EndName); } // Operators @@ -530,14 +530,14 @@ public: return *this; } - inline CharType& operator[](int pos) + inline CharType& operator[](int Pos) { - return mInternalString[pos]; + return mInternalString[Pos]; } - inline const CharType& operator[](int pos) const + inline const CharType& operator[](int Pos) const { - return mInternalString[pos]; + return mInternalString[Pos]; } inline const CharType* operator*() const @@ -547,17 +547,17 @@ public: _TString operator+(const CharType* pkOther) const { - u32 len = CStringLength(pkOther); + u32 Len = CStringLength(pkOther); - _TString out(len + Size()); - memcpy(&out[0], mInternalString.data(), Size() * sizeof(CharType)); - memcpy(&out[Size()], pkOther, len * sizeof(CharType)); - return out; + _TString Out(Len + Size()); + memcpy(&Out[0], mInternalString.data(), Size() * sizeof(CharType)); + memcpy(&Out[Size()], pkOther, Len * sizeof(CharType)); + return Out; } - inline _TString operator+(const _TString& other) const + inline _TString operator+(const _TString& rkOther) const { - return (*this + other.CString()); + return (*this + rkOther.CString()); } inline void operator+=(const CharType* pkOther) @@ -572,20 +572,20 @@ public: inline friend _TString operator+(const CharType* pkLeft, const _TString& rkRight) { - u32 len = CStringLength(pkLeft); + u32 Len = CStringLength(pkLeft); - _TString out(len + rkRight.Size()); - memcpy(&out[0], pkLeft, len * sizeof(CharType)); - memcpy(&out[len], rkRight.CString(), rkRight.Size() * sizeof(CharType)); - return out; + _TString Out(Len + rkRight.Size()); + memcpy(&Out[0], pkLeft, Len * sizeof(CharType)); + memcpy(&Out[Len], rkRight.CString(), rkRight.Size() * sizeof(CharType)); + return Out; } inline friend _TString operator+(const _TStdString& rkLeft, const _TString& rkRight) { - _TString out(rkLeft.size() + rkRight.Size()); - memcpy(&out[0], rkLeft.data(), rkLeft.size() * sizeof(CharType)); - memcpy(&out[rkLeft.size()], rkRight.Data(), rkRight.Size() * sizeof(CharType)); - return out; + _TString Out(rkLeft.size() + rkRight.Size()); + memcpy(&Out[0], rkLeft.data(), rkLeft.size() * sizeof(CharType)); + memcpy(&Out[rkLeft.size()], rkRight.Data(), rkRight.Size() * sizeof(CharType)); + return Out; } inline bool operator==(const CharType *pkText) const @@ -721,23 +721,23 @@ public: } // Static - static TBasicString FromInt32(s32 value, int width = 0, int base = 16) + static TBasicString FromInt32(s32 Value, int Width = 0, int Base = 16) { std::basic_stringstream sstream; - sstream << std::setbase(base) << std::setw(width) << std::setfill('0') << value; + sstream << std::setbase(Base) << std::setw(Width) << std::setfill('0') << Value; return sstream.str(); } - static TBasicString FromInt64(s64 value, int width = 0, int base = 16) + static TBasicString FromInt64(s64 Value, int Width = 0, int Base = 16) { std::basic_stringstream sstream; - sstream << std::setbase(base) << std::setw(width) << std::setfill('0') << value; + sstream << std::setbase(Base) << std::setw(Width) << std::setfill('0') << Value; return sstream.str(); } - static TBasicString FromFloat(float value, int MinDecimals = 1) + static TBasicString FromFloat(float Value, int MinDecimals = 1) { - TString Out = std::to_string(value); + TString Out = std::to_string(Value); int NumZeroes = Out.Size() - (Out.IndexOf(".") + 1); while (Out.Back() == '0' && NumZeroes > MinDecimals) @@ -749,24 +749,24 @@ public: return Out; } - static TBasicString HexString(unsigned char num, bool addPrefix = true, bool uppercase = false, int width = 0) + static TBasicString HexString(unsigned char Num, int Width = 8, bool AddPrefix = true, bool Uppercase = true) { - return HexString((unsigned long) num, addPrefix, uppercase, width); + return HexString((unsigned long) Num, Width, AddPrefix, Uppercase); } - static TBasicString HexString(unsigned short num, bool addPrefix = true, bool uppercase = false, int width = 0) + static TBasicString HexString(unsigned short Num, int Width = 8, bool AddPrefix = true, bool Uppercase = true) { - return HexString((unsigned long) num, addPrefix, uppercase, width); + return HexString((unsigned long) Num, Width, AddPrefix, Uppercase); } - static TBasicString HexString(unsigned long num, bool addPrefix = true, bool uppercase = false, int width = 0) + static TBasicString HexString(unsigned long Num, int Width = 8, bool AddPrefix = true, bool Uppercase = true) { std::basic_stringstream sstream; - sstream << std::hex << std::setw(width) << std::setfill('0') << num; + sstream << std::hex << std::setw(Width) << std::setfill('0') << Num; _TString str = sstream.str(); - if (uppercase) str = str.ToUpper(); - if (addPrefix) str.Prepend("0x"); + if (Uppercase) str = str.ToUpper(); + if (AddPrefix) str.Prepend("0x"); return str; } diff --git a/src/Common/types.h b/src/Common/types.h index 18528fad..6bb4afc0 100644 --- a/src/Common/types.h +++ b/src/Common/types.h @@ -1,13 +1,13 @@ #ifndef TYPES_H #define TYPES_H -typedef unsigned char u8; -typedef unsigned short u16; -typedef unsigned long u32; -typedef unsigned long long u64; -typedef signed char s8; -typedef signed short s16; -typedef signed long s32; -typedef signed long long s64; +typedef unsigned char u8; +typedef unsigned short u16; +typedef unsigned long u32; +typedef unsigned long long u64; +typedef signed char s8; +typedef signed short s16; +typedef signed long s32; +typedef signed long long s64; #endif // TYPES_H diff --git a/src/Core/CAreaAttributes.cpp b/src/Core/CAreaAttributes.cpp index 97865738..c022ecd0 100644 --- a/src/Core/CAreaAttributes.cpp +++ b/src/Core/CAreaAttributes.cpp @@ -14,7 +14,7 @@ CAreaAttributes::~CAreaAttributes() void CAreaAttributes::SetObject(CScriptObject *pObj) { mpObj = pObj; - mGame = pObj->Template()->MasterTemplate()->GetGame(); + mGame = pObj->Template()->MasterTemplate()->Game(); } bool CAreaAttributes::IsLayerEnabled() const diff --git a/src/Core/CRayCollisionTester.cpp b/src/Core/CRayCollisionTester.cpp index 1d392c37..7fee55a9 100644 --- a/src/Core/CRayCollisionTester.cpp +++ b/src/Core/CRayCollisionTester.cpp @@ -1,8 +1,8 @@ #include "CRayCollisionTester.h" #include "Core/Scene/CSceneNode.h" -CRayCollisionTester::CRayCollisionTester(const CRay& Ray) - : mRay(Ray) +CRayCollisionTester::CRayCollisionTester(const CRay& rkRay) + : mRay(rkRay) { } @@ -13,10 +13,10 @@ CRayCollisionTester::~CRayCollisionTester() void CRayCollisionTester::AddNode(CSceneNode *pNode, u32 ComponentIndex, float Distance) { mBoxIntersectList.emplace_back(SRayIntersection()); - SRayIntersection& Intersection = mBoxIntersectList.back(); - Intersection.pNode = pNode; - Intersection.ComponentIndex = ComponentIndex; - Intersection.Distance = Distance; + SRayIntersection& rIntersection = mBoxIntersectList.back(); + rIntersection.pNode = pNode; + rIntersection.ComponentIndex = ComponentIndex; + rIntersection.Distance = Distance; } void CRayCollisionTester::AddNodeModel(CSceneNode *pNode, CBasicModel *pModel) @@ -31,13 +31,13 @@ void CRayCollisionTester::AddNodeModel(CSceneNode *pNode, CBasicModel *pModel) } } -SRayIntersection CRayCollisionTester::TestNodes(const SViewInfo& ViewInfo) +SRayIntersection CRayCollisionTester::TestNodes(const SViewInfo& rkViewInfo) { // Sort nodes by distance from ray mBoxIntersectList.sort( - [](const SRayIntersection& A, SRayIntersection& B) -> bool + [](const SRayIntersection& rkLeft, const SRayIntersection& rkRight) -> bool { - return (A.Distance < B.Distance); + return (rkLeft.Distance < rkRight.Distance); }); // Now do more precise intersection tests on geometry @@ -46,16 +46,16 @@ SRayIntersection CRayCollisionTester::TestNodes(const SViewInfo& ViewInfo) for (auto iNode = mBoxIntersectList.begin(); iNode != mBoxIntersectList.end(); iNode++) { - SRayIntersection& Intersection = *iNode; + SRayIntersection& rIntersection = *iNode; // If we have a result, and the distance for the bounding box hit is further than the current result distance // then we know that every remaining node is further away and there is no chance of finding a closer hit. - if ((Result.Hit) && (Result.Distance < Intersection.Distance)) + if ((Result.Hit) && (Result.Distance < rIntersection.Distance)) break; // Otherwise, more intersection tests... - CSceneNode *pNode = Intersection.pNode; - SRayIntersection MidResult = pNode->RayNodeIntersectTest(mRay, Intersection.ComponentIndex, ViewInfo); + CSceneNode *pNode = rIntersection.pNode; + SRayIntersection MidResult = pNode->RayNodeIntersectTest(mRay, rIntersection.ComponentIndex, rkViewInfo); if (MidResult.Hit) { diff --git a/src/Core/CRayCollisionTester.h b/src/Core/CRayCollisionTester.h index ef62a17a..b45a8112 100644 --- a/src/Core/CRayCollisionTester.h +++ b/src/Core/CRayCollisionTester.h @@ -19,17 +19,13 @@ class CRayCollisionTester std::list mBoxIntersectList; public: - CRayCollisionTester(const CRay& Ray); + CRayCollisionTester(const CRay& rkRay); ~CRayCollisionTester(); - const CRay& Ray() const; + const CRay& Ray() const { return mRay; } + void AddNode(CSceneNode *pNode, u32 AssetIndex, float Distance); void AddNodeModel(CSceneNode *pNode, CBasicModel *pModel); - SRayIntersection TestNodes(const SViewInfo& ViewInfo); + SRayIntersection TestNodes(const SViewInfo& rkViewInfo); }; -inline const CRay& CRayCollisionTester::Ray() const -{ - return mRay; -} - #endif // CRAYCOLLISIONHELPER_H diff --git a/src/Core/Core.pro b/src/Core/Core.pro index 6beac335..90a37aa6 100644 --- a/src/Core/Core.pro +++ b/src/Core/Core.pro @@ -159,7 +159,6 @@ HEADERS += \ SRayIntersection.h \ OpenGL/CDynamicVertexBuffer.h \ OpenGL/CFramebuffer.h \ - OpenGL/CGL.h \ OpenGL/CIndexBuffer.h \ OpenGL/CRenderbuffer.h \ OpenGL/CShader.h \ @@ -193,11 +192,10 @@ SOURCES += \ Render/CCamera.cpp \ Render/CDrawUtil.cpp \ Render/CGraphics.cpp \ - Render/CRenderBucket.cpp \ Render/CRenderer.cpp \ + Render/CRenderBucket.cpp \ Resource/Cooker/CMaterialCooker.cpp \ Resource/Cooker/CModelCooker.cpp \ - Resource/Cooker/CSectionMgrOut.cpp \ Resource/Cooker/CTemplateWriter.cpp \ Resource/Cooker/CTextureEncoder.cpp \ Resource/Cooker/CWorldCooker.cpp \ @@ -221,20 +219,15 @@ SOURCES += \ Resource/Script/CScriptObject.cpp \ Resource/Script/CScriptTemplate.cpp \ Resource/CAnimationParameters.cpp \ - Resource/CAnimSet.cpp \ Resource/CCollisionMesh.cpp \ - Resource/CCollisionMeshGroup.cpp \ Resource/CFont.cpp \ Resource/CGameArea.cpp \ Resource/CLight.cpp \ Resource/CMaterial.cpp \ Resource/CMaterialPass.cpp \ - Resource/CMaterialSet.cpp \ Resource/CPakFile.cpp \ Resource/CResCache.cpp \ Resource/CResource.cpp \ - Resource/CScan.cpp \ - Resource/CStringTable.cpp \ Resource/CTexture.cpp \ Resource/CWorld.cpp \ Scene/CCollisionNode.cpp \ @@ -253,12 +246,9 @@ SOURCES += \ CRayCollisionTester.cpp \ OpenGL/CDynamicVertexBuffer.cpp \ OpenGL/CFramebuffer.cpp \ - OpenGL/CGL.cpp \ OpenGL/CIndexBuffer.cpp \ - OpenGL/CRenderbuffer.cpp \ OpenGL/CShader.cpp \ OpenGL/CShaderGenerator.cpp \ - OpenGL/CUniformBuffer.cpp \ OpenGL/CVertexArrayManager.cpp \ OpenGL/CVertexBuffer.cpp \ OpenGL/GLCommon.cpp \ diff --git a/src/Core/OpenGL/CDynamicVertexBuffer.cpp b/src/Core/OpenGL/CDynamicVertexBuffer.cpp index cec0ee40..1403df43 100644 --- a/src/Core/OpenGL/CDynamicVertexBuffer.cpp +++ b/src/Core/OpenGL/CDynamicVertexBuffer.cpp @@ -6,10 +6,10 @@ static const u32 gskAttribSize[] = { }; CDynamicVertexBuffer::CDynamicVertexBuffer() + : mAttribFlags(eNoAttributes) + , mBufferedFlags(eNoAttributes) + , mNumVertices(0) { - mAttribFlags = eNoAttributes; - mBufferedFlags = eNoAttributes; - mNumVertices = 0; } CDynamicVertexBuffer::~CDynamicVertexBuffer() @@ -42,7 +42,7 @@ void CDynamicVertexBuffer::SetActiveAttribs(FVertexDescription AttribFlags) InitBuffers(); } -void CDynamicVertexBuffer::BufferAttrib(EVertexAttribute Attrib, const void *pData) +void CDynamicVertexBuffer::BufferAttrib(EVertexAttribute Attrib, const void *pkData) { u32 Index; @@ -64,16 +64,16 @@ void CDynamicVertexBuffer::BufferAttrib(EVertexAttribute Attrib, const void *pDa } glBindBuffer(GL_ARRAY_BUFFER, mAttribBuffers[Index]); - glBufferSubData(GL_ARRAY_BUFFER, 0, gskAttribSize[Index] * mNumVertices, pData); + glBufferSubData(GL_ARRAY_BUFFER, 0, gskAttribSize[Index] * mNumVertices, pkData); } void CDynamicVertexBuffer::ClearBuffers() { for (u32 iAttrib = 0; iAttrib < 12; iAttrib++) { - int bit = 1 << iAttrib; + int Bit = 1 << iAttrib; - if (mBufferedFlags & bit) + if (mBufferedFlags & Bit) glDeleteBuffers(1, &mAttribBuffers[iAttrib]); } diff --git a/src/Core/OpenGL/CDynamicVertexBuffer.h b/src/Core/OpenGL/CDynamicVertexBuffer.h index bbbf5e37..7042700a 100644 --- a/src/Core/OpenGL/CDynamicVertexBuffer.h +++ b/src/Core/OpenGL/CDynamicVertexBuffer.h @@ -3,8 +3,6 @@ #include "Core/Resource/Model/EVertexAttribute.h" #include -#include -#include #include #include @@ -23,7 +21,7 @@ public: void Bind(); void Unbind(); void SetActiveAttribs(FVertexDescription AttribFlags); - void BufferAttrib(EVertexAttribute Attrib, const void *pData); + void BufferAttrib(EVertexAttribute Attrib, const void *pkData); void ClearBuffers(); GLuint CreateVAO(); private: diff --git a/src/Core/OpenGL/CFramebuffer.cpp b/src/Core/OpenGL/CFramebuffer.cpp index 185cb06e..c724d2cb 100644 --- a/src/Core/OpenGL/CFramebuffer.cpp +++ b/src/Core/OpenGL/CFramebuffer.cpp @@ -2,21 +2,21 @@ #include CFramebuffer::CFramebuffer() + : mInitialized(false) + , mWidth(0) + , mHeight(0) + , mpRenderbuffer(nullptr) + , mpTexture(nullptr) { - mInitialized = false; - mWidth = 0; - mHeight = 0; - mpRenderbuffer = nullptr; - mpTexture = nullptr; } CFramebuffer::CFramebuffer(u32 Width, u32 Height) + : mInitialized(false) + , mWidth(0) + , mHeight(0) + , mpRenderbuffer(nullptr) + , mpTexture(nullptr) { - mInitialized = false; - mWidth = 0; - mHeight = 0; - mpRenderbuffer = nullptr; - mpTexture = nullptr; Resize(Width, Height); } diff --git a/src/Core/OpenGL/CGL.cpp b/src/Core/OpenGL/CGL.cpp deleted file mode 100644 index 38e3cce3..00000000 --- a/src/Core/OpenGL/CGL.cpp +++ /dev/null @@ -1,41 +0,0 @@ -#include "CGL.h" - -// ************ PUBLIC ************ -void CGL::SetBlendMode(EBlendFactor Source, EBlendFactor Dest) -{ - glBlendFuncSeparate(Source, Dest, eBlendZero, eBlendZero); - mBlendSrcFac = Source; - mBlendDstFac = Dest; -} - -void CGL::SetOpaqueBlend() -{ - SetBlendMode(eBlendOne, eBlendZero); -} - -void CGL::SetAlphaBlend() -{ - SetBlendMode(eBlendSrcAlpha, eBlendInvSrcAlpha); -} - -void CGL::SetAdditiveBlend() -{ - SetBlendMode(eBlendOne, eBlendOne); -} - -// ************ PRIVATE ************ -void CGL::Init() -{ - if (!mInitialized) - { - glBlendFuncSeparate(GL_ONE, GL_ZERO, GL_ZERO, GL_ZERO); - mBlendSrcFac = eBlendOne; - mBlendDstFac = eBlendZero; - mInitialized = true; - } -} - -// ************ STATIC MEMBER INITIALIZATION ************ -bool CGL::mInitialized; -EBlendFactor CGL::mBlendSrcFac; -EBlendFactor CGL::mBlendDstFac; diff --git a/src/Core/OpenGL/CGL.h b/src/Core/OpenGL/CGL.h deleted file mode 100644 index 8573f16f..00000000 --- a/src/Core/OpenGL/CGL.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef CGL_H -#define CGL_H - -#include "GLCommon.h" -#include -#include - -class CGL -{ -public: - void SetBlendMode(EBlendFactor Source, EBlendFactor Dest); - void SetOpaqueBlend(); - void SetAlphaBlend(); - void SetAdditiveBlend(); - -private: - static void Init(); - - static bool mInitialized; - static EBlendFactor mBlendSrcFac, mBlendDstFac; - static u8 mColorMask; - static bool mDepthMask; - static bool mStencilMask; -}; - -#endif // CGL_H diff --git a/src/Core/OpenGL/CIndexBuffer.cpp b/src/Core/OpenGL/CIndexBuffer.cpp index 3e97cd7c..a111ee7f 100644 --- a/src/Core/OpenGL/CIndexBuffer.cpp +++ b/src/Core/OpenGL/CIndexBuffer.cpp @@ -1,14 +1,14 @@ #include "CIndexBuffer.h" CIndexBuffer::CIndexBuffer() + : mBuffered(false) { - mBuffered = false; } -CIndexBuffer::CIndexBuffer(GLenum type) +CIndexBuffer::CIndexBuffer(GLenum Type) + : mPrimitiveType(Type) + , mBuffered(false) { - mPrimitiveType = type; - mBuffered = false; } CIndexBuffer::~CIndexBuffer() @@ -17,21 +17,21 @@ CIndexBuffer::~CIndexBuffer() glDeleteBuffers(1, &mIndexBuffer); } -void CIndexBuffer::AddIndex(u16 idx) +void CIndexBuffer::AddIndex(u16 Index) { - mIndices.push_back(idx); + mIndices.push_back(Index); } -void CIndexBuffer::AddIndices(u16 *indicesPtr, u32 count) +void CIndexBuffer::AddIndices(u16 *pIndices, u32 Count) { - Reserve(count); - for (u32 i = 0; i < count; i++) - mIndices.push_back(*indicesPtr++); + Reserve(Count); + for (u32 iIdx = 0; iIdx < Count; iIdx++) + mIndices.push_back(*pIndices++); } -void CIndexBuffer::Reserve(u32 size) +void CIndexBuffer::Reserve(u32 Size) { - mIndices.reserve(mIndices.size() + size); + mIndices.reserve(mIndices.size() + Size); } void CIndexBuffer::Clear() @@ -94,62 +94,62 @@ GLenum CIndexBuffer::GetPrimitiveType() return mPrimitiveType; } -void CIndexBuffer::SetPrimitiveType(GLenum type) +void CIndexBuffer::SetPrimitiveType(GLenum Type) { - mPrimitiveType = type; + mPrimitiveType = Type; } -void CIndexBuffer::TrianglesToStrips(u16 *indicesPtr, u32 count) +void CIndexBuffer::TrianglesToStrips(u16 *pIndices, u32 Count) { - Reserve(count + (count / 3)); + Reserve(Count + (Count / 3)); - for (u32 i = 0; i < count; i += 3) + for (u32 iIdx = 0; iIdx < Count; iIdx += 3) { - mIndices.push_back(*indicesPtr++); - mIndices.push_back(*indicesPtr++); - mIndices.push_back(*indicesPtr++); + mIndices.push_back(*pIndices++); + mIndices.push_back(*pIndices++); + mIndices.push_back(*pIndices++); mIndices.push_back(0xFFFF); } } -void CIndexBuffer::FansToStrips(u16 *indicesPtr, u32 count) +void CIndexBuffer::FansToStrips(u16 *pIndices, u32 Count) { - Reserve(count); - u16 FirstIndex = *indicesPtr; + Reserve(Count); + u16 FirstIndex = *pIndices; - for (u32 i = 2; i < count; i += 3) + for (u32 iIdx = 2; iIdx < Count; iIdx += 3) { - mIndices.push_back(indicesPtr[i - 1]); - mIndices.push_back(indicesPtr[i]); + mIndices.push_back(pIndices[iIdx - 1]); + mIndices.push_back(pIndices[iIdx]); mIndices.push_back(FirstIndex); - if (i + 1 < count) - mIndices.push_back(indicesPtr[i + 1]); - if (i + 2 < count) - mIndices.push_back(indicesPtr[i + 2]); + if (iIdx + 1 < Count) + mIndices.push_back(pIndices[iIdx + 1]); + if (iIdx + 2 < Count) + mIndices.push_back(pIndices[iIdx + 2]); mIndices.push_back(0xFFFF); } } -void CIndexBuffer::QuadsToStrips(u16 *indicesPtr, u32 count) +void CIndexBuffer::QuadsToStrips(u16 *pIndices, u32 Count) { - Reserve((u32) (count * 1.25)); + Reserve((u32) (Count * 1.25)); - u32 i = 3; - for (; i < count; i += 4) + u32 iIdx = 3; + for (; iIdx < Count; iIdx += 4) { - mIndices.push_back(indicesPtr[i - 2]); - mIndices.push_back(indicesPtr[i - 1]); - mIndices.push_back(indicesPtr[i - 3]); - mIndices.push_back(indicesPtr[i]); + mIndices.push_back(pIndices[iIdx - 2]); + mIndices.push_back(pIndices[iIdx - 1]); + mIndices.push_back(pIndices[iIdx - 3]); + mIndices.push_back(pIndices[iIdx]); mIndices.push_back(0xFFFF); } // if there's three indices present that indicates a single triangle - if (i == count) + if (iIdx == Count) { - mIndices.push_back(indicesPtr[i - 3]); - mIndices.push_back(indicesPtr[i - 2]); - mIndices.push_back(indicesPtr[i - 1]); + mIndices.push_back(pIndices[iIdx - 3]); + mIndices.push_back(pIndices[iIdx - 2]); + mIndices.push_back(pIndices[iIdx - 1]); mIndices.push_back(0xFFFF); } diff --git a/src/Core/OpenGL/CIndexBuffer.h b/src/Core/OpenGL/CIndexBuffer.h index f0a2d87d..3264a5be 100644 --- a/src/Core/OpenGL/CIndexBuffer.h +++ b/src/Core/OpenGL/CIndexBuffer.h @@ -14,11 +14,11 @@ class CIndexBuffer public: CIndexBuffer(); - CIndexBuffer(GLenum type); + CIndexBuffer(GLenum Type); ~CIndexBuffer(); - void AddIndex(u16 idx); - void AddIndices(u16 *indicesPtr, u32 count); - void Reserve(u32 size); + void AddIndex(u16 Index); + void AddIndices(u16 *pIndices, u32 Count); + void Reserve(u32 Size); void Clear(); void Buffer(); void Bind(); @@ -29,11 +29,11 @@ public: u32 GetSize(); GLenum GetPrimitiveType(); - void SetPrimitiveType(GLenum type); + void SetPrimitiveType(GLenum Type); - void TrianglesToStrips(u16 *indicesPtr, u32 count); - void FansToStrips(u16 *indicesPtr, u32 count); - void QuadsToStrips(u16 *indicesPtr, u32 count); + void TrianglesToStrips(u16 *pIndices, u32 Count); + void FansToStrips(u16 *pIndices, u32 Count); + void QuadsToStrips(u16 *pIndices, u32 Count); }; #endif // CINDEXBUFFER_H diff --git a/src/Core/OpenGL/CRenderbuffer.cpp b/src/Core/OpenGL/CRenderbuffer.cpp deleted file mode 100644 index 2c484df6..00000000 --- a/src/Core/OpenGL/CRenderbuffer.cpp +++ /dev/null @@ -1,52 +0,0 @@ -#include "CRenderbuffer.h" - -CRenderbuffer::CRenderbuffer() -{ - mInitialized = false; - mWidth = 0; - mHeight = 0; -} - -CRenderbuffer::CRenderbuffer(u32 Width, u32 Height) -{ - mInitialized = false; - mWidth = Width; - mHeight = Height; -} - -CRenderbuffer::~CRenderbuffer() -{ - if (mInitialized) - glDeleteRenderbuffers(1, &mRenderbuffer); -} - -void CRenderbuffer::Init() -{ - glGenRenderbuffers(1, &mRenderbuffer); - glBindRenderbuffer(GL_RENDERBUFFER, mRenderbuffer); - glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, mWidth, mHeight); - mInitialized = true; -} - -void CRenderbuffer::Resize(u32 Width, u32 Height) -{ - mWidth = Width; - mHeight = Height; - - if (mInitialized) - { - Bind(); - glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, mWidth, mHeight); - } -} - -void CRenderbuffer::Bind() -{ - if (!mInitialized) Init(); - glBindRenderbuffer(GL_RENDERBUFFER, mRenderbuffer); -} - -void CRenderbuffer::Unbind() -{ - glBindRenderbuffer(GL_RENDERBUFFER, 0); -} diff --git a/src/Core/OpenGL/CRenderbuffer.h b/src/Core/OpenGL/CRenderbuffer.h index 33ef78d9..a1e62837 100644 --- a/src/Core/OpenGL/CRenderbuffer.h +++ b/src/Core/OpenGL/CRenderbuffer.h @@ -11,21 +11,61 @@ class CRenderbuffer bool mInitialized; public: - CRenderbuffer(); - CRenderbuffer(u32 Width, u32 Height); - ~CRenderbuffer(); - void Init(); - void Resize(u32 Width, u32 Height); - void Bind(); - void Unbind(); + CRenderbuffer::CRenderbuffer() + : mInitialized(false) + , mWidth(0) + , mHeight(0) + { + } - // Getters - GLuint BufferID(); + CRenderbuffer::CRenderbuffer(u32 Width, u32 Height) + : mInitialized(false) + , mWidth(Width) + , mHeight(Height) + { + } + + CRenderbuffer::~CRenderbuffer() + { + if (mInitialized) + glDeleteRenderbuffers(1, &mRenderbuffer); + } + + void CRenderbuffer::Init() + { + glGenRenderbuffers(1, &mRenderbuffer); + glBindRenderbuffer(GL_RENDERBUFFER, mRenderbuffer); + glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, mWidth, mHeight); + mInitialized = true; + } + + inline void CRenderbuffer::Resize(u32 Width, u32 Height) + { + mWidth = Width; + mHeight = Height; + + if (mInitialized) + { + Bind(); + glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, mWidth, mHeight); + } + } + + inline void CRenderbuffer::Bind() + { + if (!mInitialized) Init(); + glBindRenderbuffer(GL_RENDERBUFFER, mRenderbuffer); + } + + inline void CRenderbuffer::Unbind() + { + glBindRenderbuffer(GL_RENDERBUFFER, 0); + } + + inline GLuint BufferID() + { + return mRenderbuffer; + } }; -inline GLuint CRenderbuffer::BufferID() -{ - return mRenderbuffer; -} - #endif // CRENDERBUFFER_H diff --git a/src/Core/OpenGL/CShader.cpp b/src/Core/OpenGL/CShader.cpp index 1915f33e..1ad6e1dc 100644 --- a/src/Core/OpenGL/CShader.cpp +++ b/src/Core/OpenGL/CShader.cpp @@ -21,14 +21,14 @@ CShader::CShader() mProgramExists = false; } -CShader::CShader(const char *kpVertexSource, const char *kpPixelSource) +CShader::CShader(const char *pkVertexSource, const char *pkPixelSource) { mVertexShaderExists = false; mPixelShaderExists = false; mProgramExists = false; - CompileVertexSource(kpVertexSource); - CompilePixelSource(kpPixelSource); + CompileVertexSource(pkVertexSource); + CompilePixelSource(pkPixelSource); LinkShaders(); } @@ -41,10 +41,10 @@ CShader::~CShader() if (spCurrentShader == this) spCurrentShader = 0; } -bool CShader::CompileVertexSource(const char* kpSource) +bool CShader::CompileVertexSource(const char* pkSource) { mVertexShader = glCreateShader(GL_VERTEX_SHADER); - glShaderSource(mVertexShader, 1, (const GLchar**) &kpSource, NULL); + glShaderSource(mVertexShader, 1, (const GLchar**) &pkSource, NULL); glCompileShader(mVertexShader); // Shader should be compiled - check for errors @@ -76,10 +76,10 @@ bool CShader::CompileVertexSource(const char* kpSource) return true; } -bool CShader::CompilePixelSource(const char* kpSource) +bool CShader::CompilePixelSource(const char* pkSource) { mPixelShader = glCreateShader(GL_FRAGMENT_SHADER); - glShaderSource(mPixelShader, 1, (const GLchar**) &kpSource, NULL); + glShaderSource(mPixelShader, 1, (const GLchar**) &pkSource, NULL); glCompileShader(mPixelShader); // Shader should be compiled - check for errors @@ -136,17 +136,17 @@ bool CShader::LinkShaders() GLint LogLen; glGetProgramiv(mProgram, GL_INFO_LOG_LENGTH, &LogLen); - GLchar *InfoLog = new GLchar[LogLen]; - glGetProgramInfoLog(mProgram, LogLen, NULL, InfoLog); + GLchar *pInfoLog = new GLchar[LogLen]; + glGetProgramInfoLog(mProgram, LogLen, NULL, pInfoLog); std::ofstream LinkOut; LinkOut.open(*Out); if (LogLen > 0) - LinkOut << InfoLog; + LinkOut << pInfoLog; LinkOut.close(); - delete[] InfoLog; + delete[] pInfoLog; gFailedCompileCount++; glDeleteProgram(mProgram); @@ -172,14 +172,14 @@ GLuint CShader::GetProgramID() return mProgram; } -GLuint CShader::GetUniformLocation(const char* Uniform) +GLuint CShader::GetUniformLocation(const char* pkUniform) { - return glGetUniformLocation(mProgram, Uniform); + return glGetUniformLocation(mProgram, pkUniform); } -GLuint CShader::GetUniformBlockIndex(const char* UniformBlock) +GLuint CShader::GetUniformBlockIndex(const char* pkUniformBlock) { - return glGetUniformBlockIndex(mProgram, UniformBlock); + return glGetUniformBlockIndex(mProgram, pkUniformBlock); } void CShader::SetCurrent() @@ -197,17 +197,17 @@ void CShader::SetCurrent() } // ************ STATIC ************ -CShader* CShader::FromResourceFile(const TString& ShaderName) +CShader* CShader::FromResourceFile(const TString& rkShaderName) { - TString VertexShaderFilename = "../resources/shaders/" + ShaderName + ".vs"; - TString PixelShaderFilename = "../resources/shaders/" + ShaderName + ".ps"; + TString VertexShaderFilename = "../resources/shaders/" + rkShaderName + ".vs"; + TString PixelShaderFilename = "../resources/shaders/" + rkShaderName + ".ps"; CTextInStream VertexShaderFile(VertexShaderFilename.ToStdString()); CTextInStream PixelShaderFile(PixelShaderFilename.ToStdString()); if (!VertexShaderFile.IsValid()) - Log::Error("Couldn't load vertex shader file for " + ShaderName); + Log::Error("Couldn't load vertex shader file for " + rkShaderName); if (!PixelShaderFile.IsValid()) - Log::Error("Error: Couldn't load pixel shader file for " + ShaderName); + Log::Error("Error: Couldn't load pixel shader file for " + rkShaderName); if ((!VertexShaderFile.IsValid()) || (!PixelShaderFile.IsValid())) return nullptr; std::stringstream VertexShader; @@ -236,7 +236,7 @@ void CShader::KillCachedShader() } // ************ PRIVATE ************ -void CShader::DumpShaderSource(GLuint Shader, const TString& Out) +void CShader::DumpShaderSource(GLuint Shader, const TString& rkOut) { GLint SourceLen; glGetShaderiv(Shader, GL_SHADER_SOURCE_LENGTH, &SourceLen); @@ -245,19 +245,19 @@ void CShader::DumpShaderSource(GLuint Shader, const TString& Out) GLint LogLen; glGetShaderiv(Shader, GL_INFO_LOG_LENGTH, &LogLen); - GLchar *InfoLog = new GLchar[LogLen]; - glGetShaderInfoLog(Shader, LogLen, NULL, InfoLog); + GLchar *pInfoLog = new GLchar[LogLen]; + glGetShaderInfoLog(Shader, LogLen, NULL, pInfoLog); std::ofstream ShaderOut; - ShaderOut.open(*Out); + ShaderOut.open(*rkOut); if (SourceLen > 0) ShaderOut << Source; if (LogLen > 0) - ShaderOut << InfoLog; + ShaderOut << pInfoLog; ShaderOut.close(); delete[] Source; - delete[] InfoLog; + delete[] pInfoLog; } diff --git a/src/Core/OpenGL/CShader.h b/src/Core/OpenGL/CShader.h index 5319015c..e91d301b 100644 --- a/src/Core/OpenGL/CShader.h +++ b/src/Core/OpenGL/CShader.h @@ -22,24 +22,24 @@ class CShader public: CShader(); - CShader(const char* kpVertexSource, const char* kpPixelSource); + CShader(const char* pkVertexSource, const char* pkPixelSource); ~CShader(); - bool CompileVertexSource(const char* kpSource); - bool CompilePixelSource(const char* kpSource); + bool CompileVertexSource(const char* pkSource); + bool CompilePixelSource(const char* pkSource); bool LinkShaders(); bool IsValidProgram(); GLuint GetProgramID(); - GLuint GetUniformLocation(const char* kpUniform); - GLuint GetUniformBlockIndex(const char* kpUniformBlock); + GLuint GetUniformLocation(const char* pkUniform); + GLuint GetUniformBlockIndex(const char* pkUniformBlock); void SetCurrent(); // Static - static CShader* FromResourceFile(const TString& ShaderName); + static CShader* FromResourceFile(const TString& rkShaderName); static CShader* CurrentShader(); static void KillCachedShader(); private: - void DumpShaderSource(GLuint Shader, const TString& Out); + void DumpShaderSource(GLuint Shader, const TString& rkOut); }; #endif // CSHADER_H diff --git a/src/Core/OpenGL/CShaderGenerator.cpp b/src/Core/OpenGL/CShaderGenerator.cpp index 4b1a4949..4e4dd56a 100644 --- a/src/Core/OpenGL/CShaderGenerator.cpp +++ b/src/Core/OpenGL/CShaderGenerator.cpp @@ -170,8 +170,8 @@ bool CShaderGenerator::CreateVertexShader(const CMaterial& Mat) // Output ShaderCode << "// Output\n"; if (VtxDesc & eNormal) ShaderCode << "out vec3 Normal;\n"; - if (VtxDesc & eColor0) ShaderCode << "out vec4 Color0;\n"; - if (VtxDesc & eColor1) ShaderCode << "out vec4 Color1;\n"; + if (VtxDesc & eColor0) ShaderCode << "out vec4 Color0;\n"; + if (VtxDesc & eColor1) ShaderCode << "out vec4 Color1;\n"; for (u32 iPass = 0; iPass < Mat.PassCount(); iPass++) if (Mat.Pass(iPass)->TexCoordSource() != 0xFF) @@ -299,7 +299,7 @@ bool CShaderGenerator::CreateVertexShader(const CMaterial& Mat) // Done! - return mShader->CompileVertexSource(ShaderCode.str().c_str()); + return mpShader->CompileVertexSource(ShaderCode.str().c_str()); } bool CShaderGenerator::CreatePixelShader(const CMaterial& Mat) @@ -433,17 +433,17 @@ bool CShaderGenerator::CreatePixelShader(const CMaterial& Mat) << "}\n\n"; // Done! - return mShader->CompilePixelSource(ShaderCode.str().c_str()); + return mpShader->CompilePixelSource(ShaderCode.str().c_str()); } -CShader* CShaderGenerator::GenerateShader(const CMaterial& Mat) +CShader* CShaderGenerator::GenerateShader(const CMaterial& rkMat) { CShaderGenerator Generator; - Generator.mShader = new CShader(); + Generator.mpShader = new CShader(); - bool Success = Generator.CreateVertexShader(Mat); - if (Success) Success = Generator.CreatePixelShader(Mat); + bool Success = Generator.CreateVertexShader(rkMat); + if (Success) Success = Generator.CreatePixelShader(rkMat); - Generator.mShader->LinkShaders(); - return Generator.mShader; + Generator.mpShader->LinkShaders(); + return Generator.mpShader; } diff --git a/src/Core/OpenGL/CShaderGenerator.h b/src/Core/OpenGL/CShaderGenerator.h index 0d480cf3..bb849635 100644 --- a/src/Core/OpenGL/CShaderGenerator.h +++ b/src/Core/OpenGL/CShaderGenerator.h @@ -7,15 +7,15 @@ class CShaderGenerator { - CShader *mShader; + CShader *mpShader; CShaderGenerator(); ~CShaderGenerator(); - bool CreateVertexShader(const CMaterial& Mat); - bool CreatePixelShader(const CMaterial& Mat); + bool CreateVertexShader(const CMaterial& rkMat); + bool CreatePixelShader(const CMaterial& rkMat); public: - static CShader* GenerateShader(const CMaterial& Mat); + static CShader* GenerateShader(const CMaterial& rkMat); }; #endif // SHADERGEN_H diff --git a/src/Core/OpenGL/CUniformBuffer.cpp b/src/Core/OpenGL/CUniformBuffer.cpp deleted file mode 100644 index 93827856..00000000 --- a/src/Core/OpenGL/CUniformBuffer.cpp +++ /dev/null @@ -1,60 +0,0 @@ -#include "CUniformBuffer.h" - -CUniformBuffer::CUniformBuffer() -{ - glGenBuffers(1, &mUniformBuffer); - SetBufferSize(0); -} - -CUniformBuffer::CUniformBuffer(u32 Size) -{ - glGenBuffers(1, &mUniformBuffer); - SetBufferSize(Size); -} - -CUniformBuffer::~CUniformBuffer() -{ - glDeleteBuffers(1, &mUniformBuffer); -} - -void CUniformBuffer::InitializeBuffer() -{ - Bind(); - glBufferData(GL_UNIFORM_BUFFER, mBufferSize, 0, GL_DYNAMIC_DRAW); - Unbind(); -} - -void CUniformBuffer::Bind() -{ - glBindBuffer(GL_UNIFORM_BUFFER, mUniformBuffer); -} - -void CUniformBuffer::Unbind() -{ - glBindBuffer(GL_UNIFORM_BUFFER, 0); -} - -void CUniformBuffer::BindBase(GLuint index) -{ - Bind(); - glBindBufferBase(GL_UNIFORM_BUFFER, index, mUniformBuffer); - Unbind(); -} - -void CUniformBuffer::Buffer(void *pData) -{ - Bind(); - glBufferSubData(GL_UNIFORM_BUFFER, 0, mBufferSize, pData); - Unbind(); -} - -void CUniformBuffer::SetBufferSize(u32 Size) -{ - mBufferSize = Size; - InitializeBuffer(); -} - -u32 CUniformBuffer::GetBufferSize() -{ - return mBufferSize; -} diff --git a/src/Core/OpenGL/CUniformBuffer.h b/src/Core/OpenGL/CUniformBuffer.h index 5e8d933e..4a88997a 100644 --- a/src/Core/OpenGL/CUniformBuffer.h +++ b/src/Core/OpenGL/CUniformBuffer.h @@ -10,19 +10,66 @@ class CUniformBuffer u32 mBufferSize; public: - CUniformBuffer(); - CUniformBuffer(u32 Size); - ~CUniformBuffer(); - void Bind(); - void Unbind(); - void BindBase(GLuint index); - void Buffer(void *pData); - void SetBufferSize(u32 Size); - u32 GetBufferSize(); + CUniformBuffer() + { + glGenBuffers(1, &mUniformBuffer); + SetBufferSize(0); + } + + CUniformBuffer(u32 Size) + { + glGenBuffers(1, &mUniformBuffer); + SetBufferSize(Size); + } + + ~CUniformBuffer() + { + glDeleteBuffers(1, &mUniformBuffer); + } + + void Bind() + { + glBindBuffer(GL_UNIFORM_BUFFER, mUniformBuffer); + } + + void Unbind() + { + glBindBuffer(GL_UNIFORM_BUFFER, 0); + } + + void BindBase(GLuint Index) + { + Bind(); + glBindBufferBase(GL_UNIFORM_BUFFER, Index, mUniformBuffer); + Unbind(); + } + + void Buffer(void *pData) + { + Bind(); + glBufferSubData(GL_UNIFORM_BUFFER, 0, mBufferSize, pData); + Unbind(); + } + + void SetBufferSize(u32 Size) + { + mBufferSize = Size; + InitializeBuffer(); + } + + u32 GetBufferSize() + { + return mBufferSize; + } private: - void InitializeBuffer(); + void InitializeBuffer() + { + Bind(); + glBufferData(GL_UNIFORM_BUFFER, mBufferSize, 0, GL_DYNAMIC_DRAW); + Unbind(); + } }; #endif // CUNIFORMBUFFER_H diff --git a/src/Core/OpenGL/CVertexBuffer.cpp b/src/Core/OpenGL/CVertexBuffer.cpp index 3c3da81d..f3fef626 100644 --- a/src/Core/OpenGL/CVertexBuffer.cpp +++ b/src/Core/OpenGL/CVertexBuffer.cpp @@ -21,25 +21,25 @@ CVertexBuffer::~CVertexBuffer() glDeleteBuffers(12, mAttribBuffers); } -u16 CVertexBuffer::AddVertex(const CVertex& Vert) +u16 CVertexBuffer::AddVertex(const CVertex& rkVtx) { if (mPositions.size() == 0xFFFF) throw std::overflow_error("VBO contains too many vertices"); - if (mVtxDesc & ePosition) mPositions.push_back(Vert.Position); - if (mVtxDesc & eNormal) mNormals.push_back(Vert.Normal); - if (mVtxDesc & eColor0) mColors[0].push_back(Vert.Color[0]); - if (mVtxDesc & eColor1) mColors[1].push_back(Vert.Color[1]); + if (mVtxDesc & ePosition) mPositions.push_back(rkVtx.Position); + if (mVtxDesc & eNormal) mNormals.push_back(rkVtx.Normal); + if (mVtxDesc & eColor0) mColors[0].push_back(rkVtx.Color[0]); + if (mVtxDesc & eColor1) mColors[1].push_back(rkVtx.Color[1]); for (u32 iTex = 0; iTex < 8; iTex++) - if (mVtxDesc & (eTex0 << (iTex * 2))) mTexCoords[iTex].push_back(Vert.Tex[iTex]); + if (mVtxDesc & (eTex0 << (iTex * 2))) mTexCoords[iTex].push_back(rkVtx.Tex[iTex]); for (u32 iMtx = 0; iMtx < 8; iMtx++) - if (mVtxDesc & (ePosMtx << iMtx)) mTexCoords[iMtx].push_back(Vert.MatrixIndices[iMtx]); + if (mVtxDesc & (ePosMtx << iMtx)) mTexCoords[iMtx].push_back(rkVtx.MatrixIndices[iMtx]); return (mPositions.size() - 1); } -u16 CVertexBuffer::AddIfUnique(const CVertex& Vert, u16 Start) +u16 CVertexBuffer::AddIfUnique(const CVertex& rkVtx, u16 Start) { if (Start < mPositions.size()) { @@ -49,21 +49,21 @@ u16 CVertexBuffer::AddIfUnique(const CVertex& Vert, u16 Start) bool Unique = false; if (mVtxDesc & ePosition) - if (Vert.Position != mPositions[iVert]) Unique = true; + if (rkVtx.Position != mPositions[iVert]) Unique = true; if ((!Unique) && (mVtxDesc & eNormal)) - if (Vert.Normal != mNormals[iVert]) Unique = true; + if (rkVtx.Normal != mNormals[iVert]) Unique = true; if ((!Unique) && (mVtxDesc & eColor0)) - if (Vert.Color[0] != mColors[0][iVert]) Unique = true; + if (rkVtx.Color[0] != mColors[0][iVert]) Unique = true; if ((!Unique) && (mVtxDesc & eColor1)) - if (Vert.Color[1] != mColors[1][iVert]) Unique = true; + if (rkVtx.Color[1] != mColors[1][iVert]) Unique = true; if (!Unique) for (u32 iTex = 0; iTex < 8; iTex++) if ((mVtxDesc & (eTex0 << (iTex * 2)))) - if (Vert.Tex[iTex] != mTexCoords[iTex][iVert]) + if (rkVtx.Tex[iTex] != mTexCoords[iTex][iVert]) { Unique = true; break; @@ -73,12 +73,12 @@ u16 CVertexBuffer::AddIfUnique(const CVertex& Vert, u16 Start) } } - return AddVertex(Vert); + return AddVertex(rkVtx); } -void CVertexBuffer::Reserve(u16 size) +void CVertexBuffer::Reserve(u16 Size) { - u32 ReserveSize = mPositions.size() + size; + u32 ReserveSize = mPositions.size() + Size; if (mVtxDesc & ePosition) mPositions.reserve(ReserveSize); @@ -140,18 +140,18 @@ void CVertexBuffer::Buffer() else if (iAttrib < 4) { - u8 idx = (u8) (iAttrib - 2); + u8 Index = (u8) (iAttrib - 2); glBindBuffer(GL_ARRAY_BUFFER, mAttribBuffers[iAttrib]); - glBufferData(GL_ARRAY_BUFFER, mColors[idx].size() * sizeof(CColor), mColors[idx].data(), GL_STATIC_DRAW); + glBufferData(GL_ARRAY_BUFFER, mColors[Index].size() * sizeof(CColor), mColors[Index].data(), GL_STATIC_DRAW); } else { - u8 idx = (u8) (iAttrib - 4); + u8 Index = (u8) (iAttrib - 4); glBindBuffer(GL_ARRAY_BUFFER, mAttribBuffers[iAttrib]); - glBufferData(GL_ARRAY_BUFFER, mTexCoords[idx].size() * sizeof(CVector2f), mTexCoords[idx].data(), GL_STATIC_DRAW); + glBufferData(GL_ARRAY_BUFFER, mTexCoords[Index].size() * sizeof(CVector2f), mTexCoords[Index].data(), GL_STATIC_DRAW); } } diff --git a/src/Core/OpenGL/CVertexBuffer.h b/src/Core/OpenGL/CVertexBuffer.h index 428706fd..2d03ee26 100644 --- a/src/Core/OpenGL/CVertexBuffer.h +++ b/src/Core/OpenGL/CVertexBuffer.h @@ -20,9 +20,9 @@ public: CVertexBuffer(); CVertexBuffer(FVertexDescription Desc); ~CVertexBuffer(); - u16 AddVertex(const CVertex& vtx); - u16 AddIfUnique(const CVertex& vtx, u16 start); - void Reserve(u16 size); + u16 AddVertex(const CVertex& rkVtx); + u16 AddIfUnique(const CVertex& rkVtx, u16 Start); + void Reserve(u16 Size); void Clear(); void Buffer(); void Bind(); diff --git a/src/Core/OpenGL/GLCommon.cpp b/src/Core/OpenGL/GLCommon.cpp index 74135f28..7ea3201d 100644 --- a/src/Core/OpenGL/GLCommon.cpp +++ b/src/Core/OpenGL/GLCommon.cpp @@ -1,7 +1,8 @@ #include "GLCommon.h" #include -GLenum glBlendFactor[] = { +GLenum gBlendFactor[] = +{ GL_ZERO, // GX_BL_ZERO GL_ONE, // GX_BL_ONE GL_SRC_COLOR, // GX_BL_SRCCLR / GX_BL_DSTCLR @@ -13,7 +14,8 @@ GLenum glBlendFactor[] = { }; -GLenum glZMode[] = { +GLenum gZMode[] = +{ GL_NEVER, // GX_NEVER GL_LESS, // GX_LESS GL_EQUAL, // GX_EQUAL @@ -23,15 +25,16 @@ GLenum glZMode[] = { GL_ALWAYS // GX_ALWAYS }; -GLenum GXPrimToGLPrim(EGXPrimitiveType t) { - switch (t) { - case eGX_Quads: return GL_TRIANGLE_STRIP; // Quads are converted to strips - case eGX_Triangles: return GL_TRIANGLE_STRIP; // Triangles are converted to strips - case eGX_TriangleStrip: return GL_TRIANGLE_STRIP; - case eGX_TriangleFan: return GL_TRIANGLE_STRIP; // Fans are converted to strips - case eGX_Lines: return GL_LINES; - case eGX_LineStrip: return GL_LINE_STRIP; - case eGX_Points: return GL_POINTS; - default: throw std::invalid_argument("Invalid GX primitive type"); +GLenum GXPrimToGLPrim(EGXPrimitiveType Type) +{ + switch (Type) { + case eGX_Quads: return GL_TRIANGLE_STRIP; // Quads are converted to strips + case eGX_Triangles: return GL_TRIANGLE_STRIP; // Triangles are converted to strips + case eGX_TriangleStrip: return GL_TRIANGLE_STRIP; + case eGX_TriangleFan: return GL_TRIANGLE_STRIP; // Fans are converted to strips + case eGX_Lines: return GL_LINES; + case eGX_LineStrip: return GL_LINE_STRIP; + case eGX_Points: return GL_POINTS; + default: throw std::invalid_argument("Invalid GX primitive type"); } } diff --git a/src/Core/OpenGL/GLCommon.h b/src/Core/OpenGL/GLCommon.h index beba44f5..1bc5bdf0 100644 --- a/src/Core/OpenGL/GLCommon.h +++ b/src/Core/OpenGL/GLCommon.h @@ -27,8 +27,8 @@ enum EGXPrimitiveType eGX_Points = 0xB8 }; -extern GLenum glBlendFactor[]; -extern GLenum glZMode[]; -GLenum GXPrimToGLPrim(EGXPrimitiveType t); +extern GLenum gBlendFactor[]; +extern GLenum gZMode[]; +GLenum GXPrimToGLPrim(EGXPrimitiveType Type); #endif // GLCOMMON_H diff --git a/src/Core/Render/CCamera.cpp b/src/Core/Render/CCamera.cpp index 344b6d18..027dda67 100644 --- a/src/Core/Render/CCamera.cpp +++ b/src/Core/Render/CCamera.cpp @@ -5,33 +5,31 @@ #include CCamera::CCamera() + : mMode(eFreeCamera) + , mPosition(0) + , mAspectRatio(1.7777777f) + , mYaw(-Math::skHalfPi) + , mPitch(0.f) + , mMoveSpeed(1.f) + , mLookSpeed(1.f) + , mTransformDirty(true) + , mViewDirty(true) + , mProjectionDirty(true) + , mFrustumPlanesDirty(true) { - mMode = eFreeCamera; - mPosition = CVector3f(0); - mAspectRatio = 1.7777777f; - - mYaw = -Math::skHalfPi; - mPitch = 0.0f; SetOrbit(CVector3f(0), 5.f); - - mMoveSpeed = 1.f; - mLookSpeed = 1.f; - mTransformDirty = true; - mViewDirty = true; - mProjectionDirty = true; - mFrustumPlanesDirty = true; } +// todo: make it actually look at the target! +// don't actually use this constructor, it's unfinished and won't work properly CCamera::CCamera(CVector3f Position, CVector3f /*Target*/) + : mMode(eFreeCamera) + , mMoveSpeed(1.f) + , mLookSpeed(1.f) + , mPosition(Position) + , mYaw(-Math::skHalfPi) + , mPitch(0.f) { - // todo: make it actually look at the target! - // don't actually use this constructor, it's unfinished and won't work properly - mMode = eFreeCamera; - mMoveSpeed = 1.f; - mLookSpeed = 1.f; - mPosition = Position; - mYaw = -Math::skHalfPi; - mPitch = 0.0f; } void CCamera::Pan(float XAmount, float YAmount) @@ -123,8 +121,8 @@ CRay CCamera::CastRay(CVector2f DeviceCoords) const { CMatrix4f InverseVP = (ViewMatrix().Transpose() * ProjectionMatrix().Transpose()).Inverse(); - CVector3f RayOrigin = CVector3f(DeviceCoords.x, DeviceCoords.y, -1.f) * InverseVP; - CVector3f RayTarget = CVector3f(DeviceCoords.x, DeviceCoords.y, 0.f) * InverseVP; + CVector3f RayOrigin = CVector3f(DeviceCoords.X, DeviceCoords.Y, -1.f) * InverseVP; + CVector3f RayTarget = CVector3f(DeviceCoords.X, DeviceCoords.Y, 0.f) * InverseVP; CVector3f RayDir = (RayTarget - RayOrigin).Normalized(); CRay Ray; @@ -167,9 +165,9 @@ void CCamera::SetOrbit(const CAABox& OrbitTarget, float DistScale /*= 4.f*/) CVector3f Extent = (Max - Min) / 2.f; float Dist = 0.f; - if (Extent.x >= Extent.y && Extent.x >= Extent.z) Dist = Extent.x; - else if (Extent.y >= Extent.x && Extent.y >= Extent.z) Dist = Extent.y; - else Dist = Extent.z; + if (Extent.X >= Extent.Y && Extent.X >= Extent.Z) Dist = Extent.X; + else if (Extent.Y >= Extent.X && Extent.Y >= Extent.Z) Dist = Extent.Y; + else Dist = Extent.Z; mOrbitDistance = Dist * DistScale; @@ -200,100 +198,6 @@ void CCamera::LoadMatrices() const CGraphics::UpdateMVPBlock(); } -// ************ GETTERS ************ -CVector3f CCamera::Position() const -{ - UpdateTransform(); - return mPosition; -} - -CVector3f CCamera::Direction() const -{ - UpdateTransform(); - return mDirection; -} - -CVector3f CCamera::UpVector() const -{ - UpdateTransform(); - return mUpVector; -} - -CVector3f CCamera::RightVector() const -{ - UpdateTransform(); - return mRightVector; -} - -float CCamera::Yaw() const -{ - return mYaw; -} - -float CCamera::Pitch() const -{ - return mPitch; -} - -float CCamera::FieldOfView() const -{ - return 55.f; -} - -ECameraMoveMode CCamera::MoveMode() const -{ - return mMode; -} - -const CMatrix4f& CCamera::ViewMatrix() const -{ - UpdateView(); - return mViewMatrix; -} - -const CMatrix4f& CCamera::ProjectionMatrix() const -{ - UpdateProjection(); - return mProjectionMatrix; -} - -const CFrustumPlanes& CCamera::FrustumPlanes() const -{ - UpdateFrustum(); - return mFrustumPlanes; -} - -// ************ SETTERS ************ -void CCamera::SetYaw(float Yaw) -{ - mYaw = Yaw; - mTransformDirty = true; -} - -void CCamera::SetPitch(float Pitch) -{ - mPitch = Pitch; - ValidatePitch(); - mTransformDirty = true; -} - -void CCamera::SetMoveSpeed(float MoveSpeed) -{ - mMoveSpeed = MoveSpeed; -} - -void CCamera::SetLookSpeed(float LookSpeed) -{ - mLookSpeed = LookSpeed; -} - -void CCamera::SetAspectRatio(float AspectRatio) -{ - mAspectRatio = AspectRatio; - mProjectionDirty = true; - mFrustumPlanesDirty = true; -} - // ************ PRIVATE ************ void CCamera::ValidatePitch() { @@ -341,9 +245,9 @@ void CCamera::UpdateView() const if (mViewDirty) { - glm::vec3 glmpos(mPosition.x, mPosition.y, mPosition.z); - glm::vec3 glmdir(mDirection.x, mDirection.y, mDirection.z); - glm::vec3 glmup(mUpVector.x, mUpVector.y, mUpVector.z); + glm::vec3 glmpos(mPosition.X, mPosition.Y, mPosition.Z); + glm::vec3 glmdir(mDirection.X, mDirection.Y, mDirection.Z); + glm::vec3 glmup(mUpVector.X, mUpVector.Y, mUpVector.Z); mViewMatrix = CMatrix4f::FromGlmMat4(glm::lookAt(glmpos, glmpos + glmdir, glmup)).Transpose(); mViewDirty = false; } diff --git a/src/Core/Render/CCamera.h b/src/Core/Render/CCamera.h index c7cc43e2..0dd129eb 100644 --- a/src/Core/Render/CCamera.h +++ b/src/Core/Render/CCamera.h @@ -63,29 +63,28 @@ public: void LoadMatrices() const; void SetMoveMode(ECameraMoveMode Mode); - void SetOrbit(const CVector3f& OrbitTarget, float Distance); - void SetOrbit(const CAABox& OrbitTarget, float DistScale = 4.f); + void SetOrbit(const CVector3f& rkOrbitTarget, float Distance); + void SetOrbit(const CAABox& rkOrbitTarget, float DistScale = 4.f); void SetOrbitDistance(float Distance); - // Getters - CVector3f Position() const; - CVector3f Direction() const; - CVector3f UpVector() const; - CVector3f RightVector() const; - float Yaw() const; - float Pitch() const; - float FieldOfView() const; - ECameraMoveMode MoveMode() const; - const CMatrix4f& ViewMatrix() const; - const CMatrix4f& ProjectionMatrix() const; - const CFrustumPlanes& FrustumPlanes() const; + // Inline Accessors + inline CVector3f Position() const { UpdateTransform(); return mPosition; } + inline CVector3f Direction() const { UpdateTransform(); return mDirection; } + inline CVector3f UpVector() const { UpdateTransform(); return mUpVector; } + inline CVector3f RightVector() const { UpdateTransform(); return mRightVector; } + inline float Yaw() const { return mYaw; } + inline float Pitch() const { return mPitch; } + inline float FieldOfView() const { return 55.f; } + inline ECameraMoveMode MoveMode() const { return mMode; } + inline const CMatrix4f& ViewMatrix() const { UpdateView(); return mViewMatrix; } + inline const CMatrix4f& ProjectionMatrix() const { UpdateProjection(); return mProjectionMatrix; } + inline const CFrustumPlanes& FrustumPlanes() const { UpdateFrustum(); return mFrustumPlanes; } - // Setters - void SetYaw(float Yaw); - void SetPitch(float Pitch); - void SetMoveSpeed(float MoveSpeed); - void SetLookSpeed(float LookSpeed); - void SetAspectRatio(float AspectRatio); + inline void SetYaw(float Yaw) { mYaw = Yaw; mTransformDirty = true; } + inline void SetPitch(float Pitch) { mPitch = Pitch; ValidatePitch(); mTransformDirty = true; } + inline void SetMoveSpeed(float MoveSpeed) { mMoveSpeed = MoveSpeed; } + inline void SetLookSpeed(float LookSpeed) { mLookSpeed = LookSpeed; } + inline void SetAspectRatio(float AspectRatio) { mAspectRatio = AspectRatio; mProjectionDirty = true; mFrustumPlanesDirty = true; } // Private private: diff --git a/src/Core/Render/CDrawUtil.cpp b/src/Core/Render/CDrawUtil.cpp index 979b45f9..6de0ff51 100644 --- a/src/Core/Render/CDrawUtil.cpp +++ b/src/Core/Render/CDrawUtil.cpp @@ -67,7 +67,7 @@ void CDrawUtil::DrawSquare() { // Overload with default tex coords CVector2f TexCoords[4] = { CVector2f(0.f, 1.f), CVector2f(1.f, 1.f), CVector2f(1.f, 0.f), CVector2f(0.f, 0.f) }; - DrawSquare(&TexCoords[0].x); + DrawSquare(&TexCoords[0].X); } void CDrawUtil::DrawSquare(const CVector2f& TexUL, const CVector2f& TexUR, const CVector2f& TexBR, const CVector2f& TexBL) @@ -75,7 +75,7 @@ void CDrawUtil::DrawSquare(const CVector2f& TexUL, const CVector2f& TexUR, const // Overload with tex coords specified via parameters // I don't think that parameters are guaranteed to be contiguous in memory, so: CVector2f TexCoords[4] = { TexUL, TexUR, TexBR, TexBL }; - DrawSquare(&TexCoords[0].x); + DrawSquare(&TexCoords[0].X); } void CDrawUtil::DrawSquare(const float *pTexCoords) @@ -103,7 +103,7 @@ void CDrawUtil::DrawLine(const CVector3f& PointA, const CVector3f& PointB) void CDrawUtil::DrawLine(const CVector2f& PointA, const CVector2f& PointB) { // Overload for 2D lines - DrawLine(CVector3f(PointA.x, PointA.y, 0.f), CVector3f(PointB.x, PointB.y, 0.f), CColor::skWhite); + DrawLine(CVector3f(PointA.X, PointA.Y, 0.f), CVector3f(PointB.X, PointB.Y, 0.f), CColor::skWhite); } void CDrawUtil::DrawLine(const CVector3f& PointA, const CVector3f& PointB, const CColor& LineColor) @@ -124,7 +124,7 @@ void CDrawUtil::DrawLine(const CVector3f& PointA, const CVector3f& PointB, const void CDrawUtil::DrawLine(const CVector2f& PointA, const CVector2f& PointB, const CColor& LineColor) { // Overload for 2D lines - DrawLine(CVector3f(PointA.x, PointA.y, 0.f), CVector3f(PointB.x, PointB.y, 0.f), LineColor); + DrawLine(CVector3f(PointA.X, PointA.Y, 0.f), CVector3f(PointB.X, PointB.Y, 0.f), LineColor); } void CDrawUtil::DrawCube() @@ -230,10 +230,10 @@ void CDrawUtil::DrawBillboard(CTexture* pTexture, const CVector3f& Position, con mpBillboardShader->SetCurrent(); GLuint ScaleLoc = mpBillboardShader->GetUniformLocation("BillboardScale"); - glUniform2f(ScaleLoc, Scale.x, Scale.y); + glUniform2f(ScaleLoc, Scale.X, Scale.Y); GLuint TintLoc = mpBillboardShader->GetUniformLocation("TintColor"); - glUniform4f(TintLoc, Tint.r, Tint.g, Tint.b, Tint.a); + glUniform4f(TintLoc, Tint.R, Tint.G, Tint.B, Tint.A); pTexture->Bind(0); @@ -259,13 +259,13 @@ void CDrawUtil::DrawLightBillboard(ELightType Type, const CColor& LightColor, co mpLightBillboardShader->SetCurrent(); GLuint ScaleLoc = mpLightBillboardShader->GetUniformLocation("BillboardScale"); - glUniform2f(ScaleLoc, Scale.x, Scale.y); + glUniform2f(ScaleLoc, Scale.X, Scale.Y); GLuint ColorLoc = mpLightBillboardShader->GetUniformLocation("LightColor"); - glUniform4f(ColorLoc, LightColor.r, LightColor.g, LightColor.b, LightColor.a); + glUniform4f(ColorLoc, LightColor.R, LightColor.G, LightColor.B, LightColor.A); GLuint TintLoc = mpLightBillboardShader->GetUniformLocation("TintColor"); - glUniform4f(TintLoc, Tint.r, Tint.g, Tint.b, Tint.a); + glUniform4f(TintLoc, Tint.R, Tint.G, Tint.B, Tint.A); CTexture *pTexA = GetLightTexture(Type); CTexture *pTexB = GetLightMask(Type); @@ -294,7 +294,7 @@ void CDrawUtil::UseColorShader(const CColor& kColor) mpColorShader->SetCurrent(); GLuint ColorLoc = mpColorShader->GetUniformLocation("ColorIn"); - glUniform4f(ColorLoc, kColor.r, kColor.g, kColor.b, kColor.a); + glUniform4f(ColorLoc, kColor.R, kColor.G, kColor.B, kColor.A); CMaterial::KillCachedMaterial(); } @@ -308,7 +308,7 @@ void CDrawUtil::UseColorShaderLighting(const CColor& kColor) glUniform1i(NumLightsLoc, CGraphics::sNumLights); GLuint ColorLoc = mpColorShaderLighting->GetUniformLocation("ColorIn"); - glUniform4f(ColorLoc, kColor.r, kColor.g, kColor.b, kColor.a); + glUniform4f(ColorLoc, kColor.R, kColor.G, kColor.B, kColor.A); CMaterial::KillCachedMaterial(); } @@ -324,7 +324,7 @@ void CDrawUtil::UseTextureShader(const CColor& TintColor) mpTextureShader->SetCurrent(); GLuint TintColorLoc = mpTextureShader->GetUniformLocation("TintColor"); - glUniform4f(TintColorLoc, TintColor.r, TintColor.g, TintColor.b, TintColor.a); + glUniform4f(TintColorLoc, TintColor.R, TintColor.G, TintColor.B, TintColor.A); CMaterial::KillCachedMaterial(); } @@ -336,7 +336,7 @@ void CDrawUtil::UseCollisionShader(const CColor& TintColor /*= CColor::skWhite*/ LoadCheckerboardTexture(0); GLuint TintColorLoc = mpCollisionShader->GetUniformLocation("TintColor"); - glUniform4f(TintColorLoc, TintColor.r, TintColor.g, TintColor.b, TintColor.a); + glUniform4f(TintColorLoc, TintColor.R, TintColor.G, TintColor.B, TintColor.A); CMaterial::KillCachedMaterial(); } diff --git a/src/Core/Render/CRenderBucket.cpp b/src/Core/Render/CRenderBucket.cpp index 3f25f3bc..4e9ed458 100644 --- a/src/Core/Render/CRenderBucket.cpp +++ b/src/Core/Render/CRenderBucket.cpp @@ -4,65 +4,54 @@ #include "CRenderer.h" #include -CRenderBucket::CRenderBucket() -{ - mEstSize = 0; - mSize = 0; -} - -void CRenderBucket::SetSortType(ESortType Type) -{ - mSortType = Type; -} - -void CRenderBucket::Add(const SRenderablePtr& ptr) +void CRenderBucket::Add(const SRenderablePtr& rkPtr) { if (mSize >= mEstSize) - mRenderables.push_back(ptr); + mRenderables.push_back(rkPtr); else - mRenderables[mSize] = ptr; + mRenderables[mSize] = rkPtr; mSize++; } void CRenderBucket::Sort(CCamera* pCamera) { - struct { - CCamera *pCamera; - bool operator()(SRenderablePtr left, SRenderablePtr right) { - CVector3f cPos = pCamera->Position(); - CVector3f cDir = pCamera->Direction(); - - CVector3f distL = left.AABox.ClosestPointAlongVector(cDir) - cPos; - float dotL = distL.Dot(cDir); - CVector3f distR = right.AABox.ClosestPointAlongVector(cDir) - cPos; - float dotR = distR.Dot(cDir); - return (dotL > dotR); - } - } backToFront; - backToFront.pCamera = pCamera; - - if (mSortType == BackToFront) - std::stable_sort(mRenderables.begin(), mRenderables.begin() + mSize, backToFront); - - // Test: draw node bounding boxes + vertices used for sorting - /*for (u32 iNode = 0; iNode < mNodes.size(); iNode++) + if (mEnableDepthSort) { - SMeshPointer *pNode = &mNodes[iNode]; - CVector3f Vert = pNode->AABox.ClosestPointAlongVector(Camera.GetDirection()); - CDrawUtil::DrawWireCube(pNode->AABox, CColor::skWhite); + std::stable_sort(mRenderables.begin(), mRenderables.begin() + mSize, + [&, pCamera](const SRenderablePtr& rkLeft, const SRenderablePtr& rkRight) -> bool + { + CVector3f CamPos = pCamera->Position(); + CVector3f CamDir = pCamera->Direction(); - CVector3f Dist = Vert - Camera.GetPosition(); - float Dot = Dist.Dot(Camera.GetDirection()); - if (Dot < 0.f) Dot = -Dot; - if (Dot > 50.f) Dot = 50.f; - float Intensity = 1.f - (Dot / 50.f); - CColor CubeColor(Intensity, Intensity, Intensity, 1.f); + CVector3f DistL = rkLeft.AABox.ClosestPointAlongVector(CamDir) - CamPos; + CVector3f DistR = rkRight.AABox.ClosestPointAlongVector(CamDir) - CamPos; + float DotL = DistL.Dot(CamDir); + float DotR = DistR.Dot(CamDir); + return (DotL > DotR); + }); - CGraphics::sMVPBlock.ModelMatrix = CTransform4f::TranslationMatrix(Vert).ToMatrix4f(); - CGraphics::UpdateMVPBlock(); - CDrawUtil::DrawCube(CubeColor); - }*/ + if (mEnableDepthSortDebugVisualization) + { + for (u32 iPtr = 0; iPtr < mSize; iPtr++) + { + SRenderablePtr *pPtr = &mRenderables[iPtr]; + CVector3f Point = pPtr->AABox.ClosestPointAlongVector(pCamera->Direction()); + CDrawUtil::DrawWireCube(pPtr->AABox, CColor::skWhite); + + CVector3f Dist = Point - pCamera->Position(); + float Dot = Dist.Dot(pCamera->Direction()); + if (Dot < 0.f) Dot = -Dot; + if (Dot > 50.f) Dot = 50.f; + float Intensity = 1.f - (Dot / 50.f); + CColor CubeColor(Intensity, Intensity, Intensity, 1.f); + + CGraphics::sMVPBlock.ModelMatrix = CTransform4f::TranslationMatrix(Point).ToMatrix4f(); + CGraphics::UpdateMVPBlock(); + CDrawUtil::DrawCube(CubeColor); + } + } + } } void CRenderBucket::Clear() @@ -72,18 +61,16 @@ void CRenderBucket::Clear() mSize = 0; } -void CRenderBucket::Draw(const SViewInfo& ViewInfo) +void CRenderBucket::Draw(const SViewInfo& rkViewInfo) { - FRenderOptions Options = ViewInfo.pRenderer->RenderOptions(); + FRenderOptions Options = rkViewInfo.pRenderer->RenderOptions(); - for (u32 n = 0; n < mSize; n++) + for (u32 iPtr = 0; iPtr < mSize; iPtr++) { - if (mRenderables[n].Command == eDrawMesh) - mRenderables[n].pRenderable->Draw(Options, mRenderables[n].ComponentIndex, ViewInfo); + if (mRenderables[iPtr].Command == eDrawMesh) + mRenderables[iPtr].pRenderable->Draw(Options, mRenderables[iPtr].ComponentIndex, rkViewInfo); - else if (mRenderables[n].Command == eDrawSelection) - mRenderables[n].pRenderable->DrawSelection(); - - // todo: implementation for eDrawExtras + else if (mRenderables[iPtr].Command == eDrawSelection) + mRenderables[iPtr].pRenderable->DrawSelection(); } } diff --git a/src/Core/Render/CRenderBucket.h b/src/Core/Render/CRenderBucket.h index 5b104f84..aca6f1bc 100644 --- a/src/Core/Render/CRenderBucket.h +++ b/src/Core/Render/CRenderBucket.h @@ -2,32 +2,39 @@ #define CRENDERBUCKET_H #include "CCamera.h" +#include "CDrawUtil.h" +#include "CGraphics.h" #include "FRenderOptions.h" #include "SRenderablePtr.h" #include +#include #include class CRenderBucket { -public: - enum ESortType - { - BackToFront, - FrontToBack - }; -private: - ESortType mSortType; + bool mEnableDepthSort; + bool mEnableDepthSortDebugVisualization; std::vector mRenderables; u32 mEstSize; u32 mSize; public: - CRenderBucket(); - void SetSortType(ESortType Type); - void Add(const SRenderablePtr& ptr); + CRenderBucket() + : mEnableDepthSort(false) + , mEnableDepthSortDebugVisualization(false) + , mEstSize(0) + , mSize(0) + {} + + inline void SetDepthSortingEnabled(bool Enabled) + { + mEnableDepthSort = Enabled; + } + + void Add(const SRenderablePtr& rkPtr); void Sort(CCamera* pCamera); void Clear(); - void Draw(const SViewInfo& ViewInfo); + void Draw(const SViewInfo& rkViewInfo); }; #endif // CRENDERBUCKET_H diff --git a/src/Core/Render/CRenderer.cpp b/src/Core/Render/CRenderer.cpp index a365237b..81d8c9e0 100644 --- a/src/Core/Render/CRenderer.cpp +++ b/src/Core/Render/CRenderer.cpp @@ -5,7 +5,6 @@ #include "Core/Resource/CResCache.h" #include "Core/Resource/Factory/CTextureDecoder.h" #include -#include #include #include @@ -19,14 +18,13 @@ u32 CRenderer::sNumRenderers = 0; // ************ INITIALIZATION ************ CRenderer::CRenderer() + : mOptions(eEnableUVScroll | eEnableBackfaceCull) + , mBloomMode(eNoBloom) + , mDrawGrid(true) + , mInitialized(false) + , mContextIndex(-1) { - mOptions = eEnableUVScroll | eEnableBackfaceCull; - mBloomMode = eNoBloom; - mDrawGrid = true; - mInitialized = false; - mContextIndex = -1; - mOpaqueBucket.SetSortType(CRenderBucket::FrontToBack); - mTransparentBucket.SetSortType(CRenderBucket::BackToFront); + mTransparentBucket.SetDepthSortingEnabled(true); sNumRenderers++; } @@ -45,45 +43,45 @@ void CRenderer::Init() { if (!mInitialized) { - glClearColor(mClearColor.r, mClearColor.g, mClearColor.b, mClearColor.a); + glClearColor(mClearColor.R, mClearColor.G, mClearColor.B, mClearColor.A); mContextIndex = CGraphics::GetContextIndex(); mInitialized = true; } } -// ************ GETTERS/SETTERS ************ +// ************ ACCESSORS ************ FRenderOptions CRenderer::RenderOptions() const { return mOptions; } -void CRenderer::ToggleBackfaceCull(bool b) +void CRenderer::ToggleBackfaceCull(bool Enable) { - if (b) mOptions |= eEnableBackfaceCull; - else mOptions &= ~eEnableBackfaceCull; + if (Enable) mOptions |= eEnableBackfaceCull; + else mOptions &= ~eEnableBackfaceCull; } -void CRenderer::ToggleUVAnimation(bool b) +void CRenderer::ToggleUVAnimation(bool Enable) { - if (b) mOptions |= eEnableUVScroll; - else mOptions &= ~eEnableUVScroll; + if (Enable) mOptions |= eEnableUVScroll; + else mOptions &= ~eEnableUVScroll; } -void CRenderer::ToggleGrid(bool b) +void CRenderer::ToggleGrid(bool Enable) { - mDrawGrid = b; + mDrawGrid = Enable; } -void CRenderer::ToggleOccluders(bool b) +void CRenderer::ToggleOccluders(bool Enable) { - if (b) mOptions |= eEnableOccluders; - else mOptions &= ~eEnableOccluders; + if (Enable) mOptions |= eEnableOccluders; + else mOptions &= ~eEnableOccluders; } -void CRenderer::ToggleAlphaDisabled(bool b) +void CRenderer::ToggleAlphaDisabled(bool Enable) { - if (b) mOptions |= eNoAlpha; - else mOptions &= ~eNoAlpha; + if (Enable) mOptions |= eNoAlpha; + else mOptions &= ~eNoAlpha; } void CRenderer::SetBloom(EBloomMode BloomMode) @@ -96,11 +94,11 @@ void CRenderer::SetBloom(EBloomMode BloomMode) mOptions &= ~eEnableBloom; } -void CRenderer::SetClearColor(const CColor& Clear) +void CRenderer::SetClearColor(const CColor& rkClear) { - mClearColor = Clear; - mClearColor.a = 0.f; - glClearColor(mClearColor.r, mClearColor.g, mClearColor.b, mClearColor.a); + mClearColor = rkClear; + mClearColor.A = 0.f; + glClearColor(mClearColor.R, mClearColor.G, mClearColor.B, mClearColor.A); } void CRenderer::SetViewportSize(u32 Width, u32 Height) @@ -116,7 +114,7 @@ void CRenderer::SetViewportSize(u32 Width, u32 Height) } // ************ RENDER ************ -void CRenderer::RenderBuckets(const SViewInfo& ViewInfo) +void CRenderer::RenderBuckets(const SViewInfo& rkViewInfo) { if (!mInitialized) Init(); mSceneFramebuffer.Bind(); @@ -129,10 +127,10 @@ void CRenderer::RenderBuckets(const SViewInfo& ViewInfo) glDepthRange(0.f, 1.f); glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); - mOpaqueBucket.Draw(ViewInfo); + mOpaqueBucket.Draw(rkViewInfo); mOpaqueBucket.Clear(); - mTransparentBucket.Sort(ViewInfo.pCamera); - mTransparentBucket.Draw(ViewInfo); + mTransparentBucket.Sort(rkViewInfo.pCamera); + mTransparentBucket.Draw(rkViewInfo); mTransparentBucket.Clear(); } @@ -244,7 +242,7 @@ void CRenderer::RenderBloom() glEnable(GL_DEPTH_TEST); } -void CRenderer::RenderSky(CModel *pSkyboxModel, const SViewInfo& ViewInfo) +void CRenderer::RenderSky(CModel *pSkyboxModel, const SViewInfo& rkViewInfo) { if (!mInitialized) Init(); if (!pSkyboxModel) return; @@ -261,31 +259,31 @@ void CRenderer::RenderSky(CModel *pSkyboxModel, const SViewInfo& ViewInfo) CGraphics::UpdateLightBlock(); // Load rotation-only view matrix - CGraphics::sMVPBlock.ViewMatrix = ViewInfo.RotationOnlyViewMatrix; + CGraphics::sMVPBlock.ViewMatrix = rkViewInfo.RotationOnlyViewMatrix; CGraphics::UpdateMVPBlock(); glDepthRange(1.f, 1.f); pSkyboxModel->Draw(mOptions, 0); } -void CRenderer::AddOpaqueMesh(IRenderable *pRenderable, int AssetID, CAABox& AABox, ERenderCommand Command) +void CRenderer::AddOpaqueMesh(IRenderable *pRenderable, int AssetID, const CAABox& rkAABox, ERenderCommand Command) { - SRenderablePtr ptr; - ptr.pRenderable = pRenderable; - ptr.ComponentIndex = AssetID; - ptr.AABox = AABox; - ptr.Command = Command; - mOpaqueBucket.Add(ptr); + SRenderablePtr Ptr; + Ptr.pRenderable = pRenderable; + Ptr.ComponentIndex = AssetID; + Ptr.AABox = rkAABox; + Ptr.Command = Command; + mOpaqueBucket.Add(Ptr); } -void CRenderer::AddTransparentMesh(IRenderable *pRenderable, int AssetID, CAABox& AABox, ERenderCommand Command) +void CRenderer::AddTransparentMesh(IRenderable *pRenderable, int AssetID, const CAABox& rkAABox, ERenderCommand Command) { - SRenderablePtr ptr; - ptr.pRenderable = pRenderable; - ptr.ComponentIndex = AssetID; - ptr.AABox = AABox; - ptr.Command = Command; - mTransparentBucket.Add(ptr); + SRenderablePtr Ptr; + Ptr.pRenderable = pRenderable; + Ptr.ComponentIndex = AssetID; + Ptr.AABox = rkAABox; + Ptr.Command = Command; + mTransparentBucket.Add(Ptr); } void CRenderer::BeginFrame() @@ -334,7 +332,7 @@ void CRenderer::ClearDepthBuffer() // ************ PRIVATE ************ void CRenderer::InitFramebuffer() { - glClearColor(mClearColor.r, mClearColor.g, mClearColor.b, mClearColor.a); + glClearColor(mClearColor.R, mClearColor.G, mClearColor.B, mClearColor.A); glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); glDepthMask(GL_TRUE); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); diff --git a/src/Core/Render/CRenderer.h b/src/Core/Render/CRenderer.h index c90b94e0..abea8655 100644 --- a/src/Core/Render/CRenderer.h +++ b/src/Core/Render/CRenderer.h @@ -53,23 +53,23 @@ public: ~CRenderer(); void Init(); - // Getters/Setters + // Accessors FRenderOptions RenderOptions() const; - void ToggleBackfaceCull(bool b); - void ToggleUVAnimation(bool b); - void ToggleGrid(bool b); - void ToggleOccluders(bool b); - void ToggleAlphaDisabled(bool b); + void ToggleBackfaceCull(bool Enable); + void ToggleUVAnimation(bool Enable); + void ToggleGrid(bool Enable); + void ToggleOccluders(bool Enable); + void ToggleAlphaDisabled(bool Enable); void SetBloom(EBloomMode BloomMode); - void SetClearColor(const CColor& Clear); + void SetClearColor(const CColor& rkClear); void SetViewportSize(u32 Width, u32 Height); // Render - void RenderBuckets(const SViewInfo& ViewInfo); + void RenderBuckets(const SViewInfo& rkViewInfo); void RenderBloom(); - void RenderSky(CModel *pSkyboxModel, const SViewInfo& ViewInfo); - void AddOpaqueMesh(IRenderable *pRenderable, int AssetID, CAABox& AABox, ERenderCommand Command); - void AddTransparentMesh(IRenderable *pRenderable, int AssetID, CAABox& AABox, ERenderCommand Command); + void RenderSky(CModel *pSkyboxModel, const SViewInfo& rkViewInfo); + void AddOpaqueMesh(IRenderable *pRenderable, int AssetID, const CAABox& rkAABox, ERenderCommand Command); + void AddTransparentMesh(IRenderable *pRenderable, int AssetID, const CAABox& rkAABox, ERenderCommand Command); void BeginFrame(); void EndFrame(); void ClearDepthBuffer(); diff --git a/src/Core/Render/IRenderable.h b/src/Core/Render/IRenderable.h index fdbea22c..776e9f55 100644 --- a/src/Core/Render/IRenderable.h +++ b/src/Core/Render/IRenderable.h @@ -12,8 +12,8 @@ class IRenderable public: IRenderable() {} virtual ~IRenderable() {} - virtual void AddToRenderer(CRenderer* pRenderer, const SViewInfo& ViewInfo) = 0; - virtual void Draw(FRenderOptions /*Options*/, int /*ComponentIndex*/, const SViewInfo& /*ViewInfo*/) {} + virtual void AddToRenderer(CRenderer* pRenderer, const SViewInfo& rkViewInfo) = 0; + virtual void Draw(FRenderOptions /*Options*/, int /*ComponentIndex*/, const SViewInfo& /*rkViewInfo*/) {} virtual void DrawSelection() {} }; diff --git a/src/Core/Render/SRenderablePtr.h b/src/Core/Render/SRenderablePtr.h index fdbeb037..21f9dadf 100644 --- a/src/Core/Render/SRenderablePtr.h +++ b/src/Core/Render/SRenderablePtr.h @@ -2,8 +2,7 @@ #define SRENDERABLEPTR_H #include "ERenderCommand.h" -#include "Core/Resource/CMaterial.h" -#include "Core/Scene/CSceneNode.h" +#include "IRenderable.h" #include #include diff --git a/src/Core/Resource/CAnimSet.cpp b/src/Core/Resource/CAnimSet.cpp deleted file mode 100644 index b9d069d1..00000000 --- a/src/Core/Resource/CAnimSet.cpp +++ /dev/null @@ -1,30 +0,0 @@ -#include "CAnimSet.h" - -CAnimSet::CAnimSet() : CResource() -{ -} - -CAnimSet::~CAnimSet() -{ -} - -u32 CAnimSet::getNodeCount() -{ - return nodes.size(); -} - -TString CAnimSet::getNodeName(u32 node) -{ - if (node >= nodes.size()) - return nodes[0].name; - else - return nodes[node].name; -} - -CModel* CAnimSet::getNodeModel(u32 node) -{ - if (node >= nodes.size()) - return nodes[0].model; - else - return nodes[node].model; -} diff --git a/src/Core/Resource/CAnimSet.h b/src/Core/Resource/CAnimSet.h index 42e41a20..6aa3fde6 100644 --- a/src/Core/Resource/CAnimSet.h +++ b/src/Core/Resource/CAnimSet.h @@ -16,22 +16,21 @@ class CAnimSet : public CResource struct SNode { - TString name; - TResPtr model; - u32 skinID; - u32 skelID; + TString Name; + TResPtr pModel; + u32 SkinID; + u32 SkelID; - SNode() { model = nullptr; } + SNode() { pModel = nullptr; } }; - std::vector nodes; + std::vector mNodes; public: - CAnimSet(); - ~CAnimSet(); + CAnimSet() : CResource() {} - u32 getNodeCount(); - TString getNodeName(u32 node); - CModel* getNodeModel(u32 node); + u32 NumNodes() const { return mNodes.size(); } + TString NodeName(u32 Index) { if (Index >= mNodes.size()) Index = 0; return mNodes[Index].Name; } + CModel* NodeModel(u32 Index) { if (Index >= mNodes.size()) Index = 0; return mNodes[Index].pModel; } }; #endif // CCHARACTERSET_H diff --git a/src/Core/Resource/CAnimationParameters.cpp b/src/Core/Resource/CAnimationParameters.cpp index 6ab4ac6f..b0368095 100644 --- a/src/Core/Resource/CAnimationParameters.cpp +++ b/src/Core/Resource/CAnimationParameters.cpp @@ -6,47 +6,46 @@ #include CAnimationParameters::CAnimationParameters() + : mGame(ePrime) + , mNodeIndex(0) + , mUnknown1(0) + , mUnknown2(0) + , mUnknown3(0) { - mGame = ePrime; - mNodeIndex = 0; - mUnknown1 = 0; - mUnknown2 = 0; - mUnknown3 = 0; } CAnimationParameters::CAnimationParameters(EGame Game) + : mGame(Game) + , mNodeIndex(0) + , mUnknown1(0) + , mUnknown2(0) + , mUnknown3(0) { - mGame = Game; - mNodeIndex = 0; - mUnknown1 = 0; - mUnknown2 = 0; - mUnknown3 = 0; } -CAnimationParameters::CAnimationParameters(IInputStream& SCLY, EGame Game) +CAnimationParameters::CAnimationParameters(IInputStream& rSCLY, EGame Game) + : mGame(Game) + , mNodeIndex(0) + , mUnknown1(0) + , mUnknown2(0) + , mUnknown3(0) { - mGame = Game; - mNodeIndex = 0; - mUnknown1 = 0; - mUnknown2 = 0; - mUnknown3 = 0; - if (Game <= eEchoes) { - mCharacter = CResourceInfo(SCLY.ReadLong(), "ANCS"); - mNodeIndex = SCLY.ReadLong(); - mUnknown1 = SCLY.ReadLong(); + mCharacter = CResourceInfo(rSCLY.ReadLong(), "ANCS"); + mNodeIndex = rSCLY.ReadLong(); + mUnknown1 = rSCLY.ReadLong(); } else if (Game <= eCorruption) { - mCharacter = CResourceInfo(SCLY.ReadLongLong(), "CHAR"); - mUnknown1 = SCLY.ReadLong(); + mCharacter = CResourceInfo(rSCLY.ReadLongLong(), "CHAR"); + mUnknown1 = rSCLY.ReadLong(); } else if (Game == eReturns) { - u8 Flags = SCLY.ReadByte(); + u8 Flags = rSCLY.ReadByte(); // 0x80 - CharacterAnimationSet is empty. if (Flags & 0x80) @@ -57,19 +56,19 @@ CAnimationParameters::CAnimationParameters(IInputStream& SCLY, EGame Game) return; } - mCharacter = CResourceInfo(SCLY.ReadLongLong(), "CHAR"); + mCharacter = CResourceInfo(rSCLY.ReadLongLong(), "CHAR"); // 0x20 - Default Anim is present if (Flags & 0x20) - mUnknown1 = SCLY.ReadLong(); + mUnknown1 = rSCLY.ReadLong(); else mUnknown1 = -1; // 0x40 - Two-value struct is present if (Flags & 0x40) { - mUnknown2 = SCLY.ReadLong(); - mUnknown3 = SCLY.ReadLong(); + mUnknown2 = rSCLY.ReadLong(); + mUnknown3 = rSCLY.ReadLong(); } else { @@ -147,8 +146,8 @@ CModel* CAnimationParameters::GetCurrentModel(s32 NodeIndex /*= -1*/) if (pSet->Type() != eAnimSet) return nullptr; if (NodeIndex == -1) NodeIndex = mNodeIndex; - if (pSet->getNodeCount() <= (u32) NodeIndex) return nullptr; - return pSet->getNodeModel(NodeIndex); + if (pSet->NumNodes() <= (u32) NodeIndex) return nullptr; + return pSet->NodeModel(NodeIndex); } TString CAnimationParameters::GetCurrentCharacterName(s32 NodeIndex /*= -1*/) @@ -160,26 +159,11 @@ TString CAnimationParameters::GetCurrentCharacterName(s32 NodeIndex /*= -1*/) if (pSet->Type() != eAnimSet) return ""; if (NodeIndex == -1) NodeIndex = mNodeIndex; - if (pSet->getNodeCount() <= (u32) NodeIndex) return ""; - return pSet->getNodeName((u32) NodeIndex); -} - -// ************ GETTERS ************ -EGame CAnimationParameters::Version() -{ - return mGame; -} - -CAnimSet* CAnimationParameters::AnimSet() -{ - return (CAnimSet*) mCharacter.Load(); -} - -u32 CAnimationParameters::CharacterIndex() -{ - return mNodeIndex; + if (pSet->NumNodes() <= (u32) NodeIndex) return ""; + return pSet->NodeName((u32) NodeIndex); } +// ************ ACCESSORS ************ u32 CAnimationParameters::Unknown(u32 Index) { switch (Index) @@ -191,7 +175,6 @@ u32 CAnimationParameters::Unknown(u32 Index) } } -// ************ SETTERS ************ void CAnimationParameters::SetResource(CResourceInfo Res) { if (Res.Type() == "ANCS" || Res.Type() == "CHAR") @@ -203,11 +186,6 @@ void CAnimationParameters::SetResource(CResourceInfo Res) Log::Error("Resource with invalid type passed to CAnimationParameters: " + Res.ToString()); } -void CAnimationParameters::SetNodeIndex(u32 Index) -{ - mNodeIndex = Index; -} - void CAnimationParameters::SetUnknown(u32 Index, u32 Value) { switch (Index) diff --git a/src/Core/Resource/CAnimationParameters.h b/src/Core/Resource/CAnimationParameters.h index 58c9101e..28cb81c7 100644 --- a/src/Core/Resource/CAnimationParameters.h +++ b/src/Core/Resource/CAnimationParameters.h @@ -20,21 +20,20 @@ class CAnimationParameters public: CAnimationParameters(); CAnimationParameters(EGame Game); - CAnimationParameters(IInputStream& SCLY, EGame Game); + CAnimationParameters(IInputStream& rSCLY, EGame Game); void Write(IOutputStream& rSCLY); CModel* GetCurrentModel(s32 NodeIndex = -1); TString GetCurrentCharacterName(s32 NodeIndex = -1); - // Getters - EGame Version(); - CAnimSet* AnimSet(); - u32 CharacterIndex(); - u32 Unknown(u32 index); + // Accessors + inline EGame Version() const { return mGame; } + inline CAnimSet* AnimSet() const { return (CAnimSet*) mCharacter.Load(); } + inline u32 CharacterIndex() { return mNodeIndex; } + inline void SetNodeIndex(u32 Index) { mNodeIndex = Index; } - // Setters + u32 Unknown(u32 Index); void SetResource(CResourceInfo Res); - void SetNodeIndex(u32 Index); void SetUnknown(u32 Index, u32 Value); // Operators diff --git a/src/Core/Resource/CCollisionMesh.cpp b/src/Core/Resource/CCollisionMesh.cpp index 035b2ef5..ee8f9187 100644 --- a/src/Core/Resource/CCollisionMesh.cpp +++ b/src/Core/Resource/CCollisionMesh.cpp @@ -33,32 +33,34 @@ void CCollisionMesh::BufferGL() // Add all the verts to our VBO, first... mVBO.Reserve(mCollisionVertices.size()); - for (u16 v = 0; v < mCollisionVertices.size(); v++) - mVBO.AddVertex(CVertex(mCollisionVertices[v].Pos)); + for (u16 iVtx = 0; iVtx < mCollisionVertices.size(); iVtx++) + mVBO.AddVertex(CVertex(mCollisionVertices[iVtx].Pos)); // Then add all the relevant indices to the IBO mIBO.Reserve(mCollisionFaces.size() * 3); - for (u32 v = 0; v < mCollisionFaces.size(); v++) + for (u32 iVtx = 0; iVtx < mCollisionFaces.size(); iVtx++) { u16 Verts[3]; - CCollisionFace *Face = &mCollisionFaces[v]; - CCollisionLine *LineA = GetLine(Face->Lines[0]); - CCollisionLine *LineB = GetLine(Face->Lines[1]); - Verts[0] = LineA->Vertices[0]; - Verts[1] = LineA->Vertices[1]; + CCollisionFace *pFace = &mCollisionFaces[iVtx]; + CCollisionLine *pLineA = GetLine(pFace->Lines[0]); + CCollisionLine *pLineB = GetLine(pFace->Lines[1]); + Verts[0] = pLineA->Vertices[0]; + Verts[1] = pLineA->Vertices[1]; // We have two vertex indices; the last one is one of the ones on line B, but we're not sure which one - if ((LineB->Vertices[0] != Verts[0]) && - (LineB->Vertices[0] != Verts[1])) - Verts[2] = LineB->Vertices[0]; + if ((pLineB->Vertices[0] != Verts[0]) && + (pLineB->Vertices[0] != Verts[1])) + Verts[2] = pLineB->Vertices[0]; else - Verts[2] = LineB->Vertices[1]; + Verts[2] = pLineB->Vertices[1]; // Some faces have a property that indicates they need to be inverted - if (!Face->Properties.Invert) + if (!pFace->Properties.Invert) mIBO.AddIndices(&Verts[0], 3); - else { + + else + { mIBO.AddIndex(Verts[2]); mIBO.AddIndex(Verts[1]); mIBO.AddIndex(Verts[0]); @@ -88,17 +90,17 @@ void CCollisionMesh::DrawWireframe() glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); } -CCollisionMesh::CCollisionVertex* CCollisionMesh::GetVertex(u16 index) +CCollisionMesh::CCollisionVertex* CCollisionMesh::GetVertex(u16 Index) { - return &mCollisionVertices[index]; + return &mCollisionVertices[Index]; } -CCollisionMesh::CCollisionLine* CCollisionMesh::GetLine(u16 index) +CCollisionMesh::CCollisionLine* CCollisionMesh::GetLine(u16 Index) { - return &mCollisionLines[index]; + return &mCollisionLines[Index]; } -CCollisionMesh::CCollisionFace* CCollisionMesh::GetFace(u16 index) +CCollisionMesh::CCollisionFace* CCollisionMesh::GetFace(u16 Index) { - return &mCollisionFaces[index]; + return &mCollisionFaces[Index]; } diff --git a/src/Core/Resource/CCollisionMesh.h b/src/Core/Resource/CCollisionMesh.h index bcaf0aab..e29710e2 100644 --- a/src/Core/Resource/CCollisionMesh.h +++ b/src/Core/Resource/CCollisionMesh.h @@ -27,7 +27,7 @@ class CCollisionMesh SOctreeNode *pChildren[8]; }; - SOctreeNode* Root; + SOctreeNode* mpRoot; }; struct SCollisionProperties @@ -65,16 +65,16 @@ class CCollisionMesh bool mBuffered; CAABox mAABox; - CCollisionOctree *mOctree; + CCollisionOctree *mpOctree; std::vector mFlags; std::vector mCollisionVertices; std::vector mCollisionLines; std::vector mCollisionFaces; bool mOctreeLoaded; - CCollisionVertex *GetVertex(u16 index); - CCollisionLine *GetLine(u16 index); - CCollisionFace *GetFace(u16 index); + CCollisionVertex *GetVertex(u16 Index); + CCollisionLine *GetLine(u16 Index); + CCollisionFace *GetFace(u16 Index); public: CCollisionMesh(); diff --git a/src/Core/Resource/CCollisionMeshGroup.cpp b/src/Core/Resource/CCollisionMeshGroup.cpp deleted file mode 100644 index 92123008..00000000 --- a/src/Core/Resource/CCollisionMeshGroup.cpp +++ /dev/null @@ -1,38 +0,0 @@ -#include "CCollisionMeshGroup.h" - -CCollisionMeshGroup::CCollisionMeshGroup() -{ -} - -CCollisionMeshGroup::~CCollisionMeshGroup() -{ - for (auto it = mMeshes.begin(); it != mMeshes.end(); it++) - delete *it; -} - -u32 CCollisionMeshGroup::NumMeshes() -{ - return mMeshes.size(); -} - -CCollisionMesh* CCollisionMeshGroup::MeshByIndex(u32 index) -{ - return mMeshes[index]; -} - -void CCollisionMeshGroup::AddMesh(CCollisionMesh *pMesh) -{ - mMeshes.push_back(pMesh); -} - -void CCollisionMeshGroup::Draw() -{ - for (auto it = mMeshes.begin(); it != mMeshes.end(); it++) - (*it)->Draw(); -} - -void CCollisionMeshGroup::DrawWireframe() -{ - for (auto it = mMeshes.begin(); it != mMeshes.end(); it++) - (*it)->DrawWireframe(); -} diff --git a/src/Core/Resource/CCollisionMeshGroup.h b/src/Core/Resource/CCollisionMeshGroup.h index ee30933f..a807c615 100644 --- a/src/Core/Resource/CCollisionMeshGroup.h +++ b/src/Core/Resource/CCollisionMeshGroup.h @@ -12,14 +12,29 @@ class CCollisionMeshGroup : public CResource std::vector mMeshes; public: - CCollisionMeshGroup(); - ~CCollisionMeshGroup(); + CCollisionMeshGroup() {} - u32 NumMeshes(); - CCollisionMesh* MeshByIndex(u32 index); - void AddMesh(CCollisionMesh *pMesh); - void Draw(); - void DrawWireframe(); + ~CCollisionMeshGroup() + { + for (auto it = mMeshes.begin(); it != mMeshes.end(); it++) + delete *it; + } + + inline u32 NumMeshes() const { return mMeshes.size(); } + inline CCollisionMesh* MeshByIndex(u32 Index) const { return mMeshes[Index]; } + inline void AddMesh(CCollisionMesh *pMesh) { mMeshes.push_back(pMesh); } + + inline void Draw() + { + for (auto it = mMeshes.begin(); it != mMeshes.end(); it++) + (*it)->Draw(); + } + + inline void DrawWireframe() + { + for (auto it = mMeshes.begin(); it != mMeshes.end(); it++) + (*it)->DrawWireframe(); + } }; #endif // CCOLLISIONMESHGROUP_H diff --git a/src/Core/Resource/CFont.cpp b/src/Core/Resource/CFont.cpp index c219d4de..d73457c4 100644 --- a/src/Core/Resource/CFont.cpp +++ b/src/Core/Resource/CFont.cpp @@ -2,7 +2,6 @@ #include "CResCache.h" #include "Core/Render/CDrawUtil.h" #include "Core/Render/CRenderer.h" -#include CDynamicVertexBuffer CFont::smGlyphVertices; CIndexBuffer CFont::smGlyphIndices; @@ -16,14 +15,14 @@ CFont::~CFont() { } -inline float PtsToFloat(s32 pt) +inline float PtsToFloat(s32 Pt) { // This is a bit of an arbitrary number but it works // 1 / (1280 / 1.333333f / 2) - return 0.00208333f * pt; + return 0.00208333f * Pt; } -CVector2f CFont::RenderString(const TString& String, CRenderer* /*pRenderer*/, float /*AspectRatio*/, +CVector2f CFont::RenderString(const TString& rkString, CRenderer* /*pRenderer*/, float /*AspectRatio*/, CVector2f /*Position*/, CColor FillColor, CColor StrokeColor, u32 FontSize) { // WIP @@ -49,16 +48,16 @@ CVector2f CFont::RenderString(const TString& String, CRenderer* /*pRenderer*/, f if (FontSize == CFONT_DEFAULT_SIZE) Scale = 1.f; else Scale = (float) FontSize / (mDefaultSize != 0 ? mDefaultSize : 18); - for (u32 iChar = 0; iChar < String.Length(); iChar++) + for (u32 iChar = 0; iChar < rkString.Length(); iChar++) { // Get character, check for newline - char Char = String[iChar]; + char Char = rkString[iChar]; if (Char == '\n') { pPrevGlyph = nullptr; - PrintHead.x = -1; - PrintHead.y -= (PtsToFloat(mLineHeight) + PtsToFloat(mLineMargin) + PtsToFloat(mUnknown)) * Scale; + PrintHead.X = -1; + PrintHead.Y -= (PtsToFloat(mLineHeight) + PtsToFloat(mLineMargin) + PtsToFloat(mUnknown)) * Scale; continue; } @@ -68,7 +67,7 @@ CVector2f CFont::RenderString(const TString& String, CRenderer* /*pRenderer*/, f SGlyph *pGlyph = &iGlyph->second; // Apply left padding and kerning - PrintHead.x += PtsToFloat(pGlyph->LeftPadding) * Scale; + PrintHead.X += PtsToFloat(pGlyph->LeftPadding) * Scale; if (pPrevGlyph) { @@ -77,9 +76,9 @@ CVector2f CFont::RenderString(const TString& String, CRenderer* /*pRenderer*/, f for (u32 iKern = pPrevGlyph->KerningIndex; iKern < mKerningTable.size(); iKern++) { if (mKerningTable[iKern].CharacterA != pPrevGlyph->Character) break; - if (mKerningTable[iKern].CharacterB == String[iChar]) + if (mKerningTable[iKern].CharacterB == rkString[iChar]) { - PrintHead.x += PtsToFloat(mKerningTable[iKern].Adjust) * Scale; + PrintHead.X += PtsToFloat(mKerningTable[iKern].Adjust) * Scale; break; } } @@ -87,16 +86,16 @@ CVector2f CFont::RenderString(const TString& String, CRenderer* /*pRenderer*/, f } // Add a newline if this character goes over the right edge of the screen - if (PrintHead.x + ((PtsToFloat(pGlyph->PrintAdvance) + PtsToFloat(pGlyph->RightPadding)) * Scale) > 1) + if (PrintHead.X + ((PtsToFloat(pGlyph->PrintAdvance) + PtsToFloat(pGlyph->RightPadding)) * Scale) > 1) { - PrintHead.x = -1; - PrintHead.y -= (PtsToFloat(mLineHeight) + PtsToFloat(mLineMargin) + PtsToFloat(mUnknown)) * Scale; + PrintHead.X = -1; + PrintHead.Y -= (PtsToFloat(mLineHeight) + PtsToFloat(mLineMargin) + PtsToFloat(mUnknown)) * Scale; if (Char == ' ') continue; } - float XTrans = PrintHead.x; - float YTrans = PrintHead.y + ((PtsToFloat(pGlyph->BaseOffset * 2) - PtsToFloat(mVerticalOffset * 2)) * Scale); + float XTrans = PrintHead.X; + float YTrans = PrintHead.Y + ((PtsToFloat(pGlyph->BaseOffset * 2) - PtsToFloat(mVerticalOffset * 2)) * Scale); CTransform4f GlyphTransform = PtScale; GlyphTransform.Scale(CVector3f((float) pGlyph->Width / 2, (float) pGlyph->Height, 1.f)); @@ -115,7 +114,7 @@ CVector2f CFont::RenderString(const TString& String, CRenderer* /*pRenderer*/, f // Draw fill glUniform1i(LayerLoc, GlyphLayer); - glUniform4fv(ColorLoc, 1, &FillColor.r); + glUniform4fv(ColorLoc, 1, &FillColor.R); smGlyphIndices.DrawElements(); // Draw stroke @@ -127,13 +126,13 @@ CVector2f CFont::RenderString(const TString& String, CRenderer* /*pRenderer*/, f else if (mTextureFormat == 8) StrokeLayer = GlyphLayer - 2; glUniform1i(LayerLoc, StrokeLayer); - glUniform4fv(ColorLoc, 1, &StrokeColor.r); + glUniform4fv(ColorLoc, 1, &StrokeColor.R); smGlyphIndices.DrawElements(); } // Update print head - PrintHead.x += PtsToFloat(pGlyph->PrintAdvance) * Scale; - PrintHead.x += PtsToFloat(pGlyph->RightPadding) * Scale; + PrintHead.X += PtsToFloat(pGlyph->PrintAdvance) * Scale; + PrintHead.X += PtsToFloat(pGlyph->RightPadding) * Scale; pPrevGlyph = pGlyph; } diff --git a/src/Core/Resource/CFont.h b/src/Core/Resource/CFont.h index deed82eb..1af8c9bc 100644 --- a/src/Core/Resource/CFont.h +++ b/src/Core/Resource/CFont.h @@ -61,7 +61,7 @@ public: CFont(); ~CFont(); CResource* MakeCopy(CResCache *pCopyCache); - CVector2f RenderString(const TString& String, CRenderer *pRenderer, float AspectRatio, + CVector2f RenderString(const TString& rkString, CRenderer *pRenderer, float AspectRatio, CVector2f Position = CVector2f(0,0), CColor FillColor = CColor::skWhite, CColor StrokeColor = CColor::skBlack, u32 FontSize = CFONT_DEFAULT_SIZE); diff --git a/src/Core/Resource/CGameArea.cpp b/src/Core/Resource/CGameArea.cpp index bd84fc56..4df785ad 100644 --- a/src/Core/Resource/CGameArea.cpp +++ b/src/Core/Resource/CGameArea.cpp @@ -26,17 +26,17 @@ CGameArea::~CGameArea() for (u32 iSCLY = 0; iSCLY < mScriptLayers.size(); iSCLY++) delete mScriptLayers[iSCLY]; - for (u32 lyr = 0; lyr < mLightLayers.size(); lyr++) - for (u32 lit = 0; lit < mLightLayers[lyr].size(); lit++) - delete mLightLayers[lyr][lit]; + for (u32 iLyr = 0; iLyr < mLightLayers.size(); iLyr++) + for (u32 iLight = 0; iLight < mLightLayers[iLyr].size(); iLight++) + delete mLightLayers[iLyr][iLight]; } -void CGameArea::AddWorldModel(CModel *mdl) +void CGameArea::AddWorldModel(CModel *pModel) { - mTerrainModels.push_back(mdl); - mVertexCount += mdl->GetVertexCount(); - mTriangleCount += mdl->GetTriangleCount(); - mAABox.ExpandBounds(mdl->AABox()); + mWorldModels.push_back(pModel); + mVertexCount += pModel->GetVertexCount(); + mTriangleCount += pModel->GetTriangleCount(); + mAABox.ExpandBounds(pModel->AABox()); } void CGameArea::MergeTerrain() @@ -44,9 +44,9 @@ void CGameArea::MergeTerrain() if (mTerrainMerged) return; // Nothing really complicated here - iterate through every terrain submesh, add each to a static model - for (u32 iMdl = 0; iMdl < mTerrainModels.size(); iMdl++) + for (u32 iMdl = 0; iMdl < mWorldModels.size(); iMdl++) { - CModel *pMdl = mTerrainModels[iMdl]; + CModel *pMdl = mWorldModels[iMdl]; u32 SubmeshCount = pMdl->GetSurfaceCount(); for (u32 iSurf = 0; iSurf < SubmeshCount; iSurf++) @@ -54,8 +54,8 @@ void CGameArea::MergeTerrain() SSurface *pSurf = pMdl->GetSurface(iSurf); CMaterial *pMat = mMaterialSet->MaterialByIndex(pSurf->MaterialID); - bool newMat = true; - for (std::vector::iterator it = mStaticTerrainModels.begin(); it != mStaticTerrainModels.end(); it++) + bool NewMat = true; + for (std::vector::iterator it = mStaticWorldModels.begin(); it != mStaticWorldModels.end(); it++) { if ((*it)->GetMaterial() == pMat) { @@ -66,18 +66,18 @@ void CGameArea::MergeTerrain() // This is maybe not the most efficient way to do this, but it works. CStaticModel *pStatic = *it; pStatic->AddSurface(pSurf); - mStaticTerrainModels.erase(it); - mStaticTerrainModels.push_back(pStatic); - newMat = false; + mStaticWorldModels.erase(it); + mStaticWorldModels.push_back(pStatic); + NewMat = false; break; } } - if (newMat) + if (NewMat) { CStaticModel *pStatic = new CStaticModel(pMat); pStatic->AddSurface(pSurf); - mStaticTerrainModels.push_back(pStatic); + mStaticWorldModels.push_back(pStatic); } } } @@ -85,13 +85,13 @@ void CGameArea::MergeTerrain() void CGameArea::ClearTerrain() { - for (u32 t = 0; t < mTerrainModels.size(); t++) - delete mTerrainModels[t]; - mTerrainModels.clear(); + for (u32 iModel = 0; iModel < mWorldModels.size(); iModel++) + delete mWorldModels[iModel]; + mWorldModels.clear(); - for (u32 s = 0; s < mStaticTerrainModels.size(); s++) - delete mStaticTerrainModels[s]; - mStaticTerrainModels.clear(); + for (u32 iStatic = 0; iStatic < mStaticWorldModels.size(); iStatic++) + delete mStaticWorldModels[iStatic]; + mStaticWorldModels.clear(); if (mMaterialSet) delete mMaterialSet; diff --git a/src/Core/Resource/CGameArea.h b/src/Core/Resource/CGameArea.h index e0909643..356e9793 100644 --- a/src/Core/Resource/CGameArea.h +++ b/src/Core/Resource/CGameArea.h @@ -46,8 +46,8 @@ class CGameArea : public CResource // Geometry CMaterialSet *mMaterialSet; - std::vector mTerrainModels; // TerrainModels is the original version of each model; this is currently mainly used in the POI map editor - std::vector mStaticTerrainModels; // StaticTerrainModels is the merged terrain for faster rendering in the world editor + std::vector mWorldModels; // TerrainModels is the original version of each model; this is currently mainly used in the POI map editor + std::vector mStaticWorldModels; // StaticTerrainModels is the merged terrain for faster rendering in the world editor // Script std::vector mScriptLayers; CScriptLayer *mpGeneratorLayer; @@ -63,7 +63,7 @@ public: CGameArea(); ~CGameArea(); - void AddWorldModel(CModel *mdl); + void AddWorldModel(CModel *pModel); void MergeTerrain(); void ClearTerrain(); void ClearScriptLayers(); @@ -79,24 +79,24 @@ public: void DeleteInstance(CScriptObject *pInstance); // Inline Accessors - inline EGame Version() const { return mVersion; } - inline u32 WorldIndex() const { return mWorldIndex; } - inline CTransform4f GetTransform() const { return mTransform; } - inline u32 GetTerrainModelCount() const { return mTerrainModels.size(); } - inline u32 GetStaticModelCount() const { return mStaticTerrainModels.size(); } - inline CModel* GetTerrainModel(u32 iMdl) const { return mTerrainModels[iMdl]; } - inline CStaticModel* GetStaticModel(u32 iMdl) const { return mStaticTerrainModels[iMdl]; } - inline CCollisionMeshGroup* GetCollision() const { return mpCollision; } - inline u32 GetScriptLayerCount() const { return mScriptLayers.size(); } - inline CScriptLayer* GetScriptLayer(u32 Index) const { return mScriptLayers[Index]; } - inline CScriptLayer* GetGeneratorLayer() const { return mpGeneratorLayer; } - inline u32 GetLightLayerCount() const { return mLightLayers.size(); } - inline u32 GetLightCount(u32 LayerIndex) const { return (LayerIndex < mLightLayers.size() ? mLightLayers[LayerIndex].size() : 0); } - inline CLight* GetLight(u32 LayerIndex, u32 LightIndex) const { return mLightLayers[LayerIndex][LightIndex]; } - inline CPoiToWorld* GetPoiToWorldMap() const { return mpPoiToWorldMap; } - inline CAABox AABox() const { return mAABox; } + inline EGame Version() const { return mVersion; } + inline u32 WorldIndex() const { return mWorldIndex; } + inline CTransform4f Transform() const { return mTransform; } + inline u32 NumWorldModels() const { return mWorldModels.size(); } + inline u32 NumStaticModels() const { return mStaticWorldModels.size(); } + inline CModel* TerrainModel(u32 iMdl) const { return mWorldModels[iMdl]; } + inline CStaticModel* StaticModel(u32 iMdl) const { return mStaticWorldModels[iMdl]; } + inline CCollisionMeshGroup* Collision() const { return mpCollision; } + inline u32 NumScriptLayers() const { return mScriptLayers.size(); } + inline CScriptLayer* ScriptLayer(u32 Index) const { return mScriptLayers[Index]; } + inline CScriptLayer* GeneratedObjectsLayer() const { return mpGeneratorLayer; } + inline u32 NumLightLayers() const { return mLightLayers.size(); } + inline u32 NumLights(u32 LayerIndex) const { return (LayerIndex < mLightLayers.size() ? mLightLayers[LayerIndex].size() : 0); } + inline CLight* Light(u32 LayerIndex, u32 LightIndex) const { return mLightLayers[LayerIndex][LightIndex]; } + inline CPoiToWorld* PoiToWorldMap() const { return mpPoiToWorldMap; } + inline CAABox AABox() const { return mAABox; } - inline void SetWorldIndex(u32 NewWorldIndex) { mWorldIndex = NewWorldIndex; } + inline void SetWorldIndex(u32 NewWorldIndex) { mWorldIndex = NewWorldIndex; } }; #endif // CGAMEAREA_H diff --git a/src/Core/Resource/CLight.cpp b/src/Core/Resource/CLight.cpp index d791db38..f81b4471 100644 --- a/src/Core/Resource/CLight.cpp +++ b/src/Core/Resource/CLight.cpp @@ -7,14 +7,14 @@ #define CLIGHT_NO_INTENSITY 0x80 CLight::CLight() + : mPosition(skDefaultLightPos) + , mDirection(skDefaultLightDir) + , mDistAttenCoefficients(0.f, 1.f, 0.f) + , mAngleAttenCoefficients(0.f, 1.f, 0.f) + , mCachedRadius(0.f) + , mCachedIntensity(0.f) + , mDirtyFlags(CLIGHT_NO_RADIUS | CLIGHT_NO_INTENSITY) { - mPosition = skDefaultLightPos; - mDirection = skDefaultLightDir; - mDistAttenCoefficients = CVector3f(0.f, 1.f, 0.f); - mAngleAttenCoefficients = CVector3f(0.f, 1.f, 0.f); - mCachedRadius = 0.f; - mCachedIntensity = 0.f; - mDirtyFlags = CLIGHT_NO_RADIUS | CLIGHT_NO_INTENSITY; } // ************ DATA MANIPULATION ************ @@ -22,30 +22,30 @@ CLight::CLight() // This function is reverse engineered from the kiosk demo's code float CLight::CalculateRadius() const { - if ((mDistAttenCoefficients.y >= FLT_EPSILON) || - (mDistAttenCoefficients.z >= FLT_EPSILON)) + if ((mDistAttenCoefficients.Y >= FLT_EPSILON) || + (mDistAttenCoefficients.Z >= FLT_EPSILON)) { float Intensity = GetIntensity(); - if (mDistAttenCoefficients.z > FLT_EPSILON) + if (mDistAttenCoefficients.Z > FLT_EPSILON) { if (Intensity <= FLT_EPSILON) return 0.f; - float IntensityMod = (Intensity * 5.f / 255.f * mDistAttenCoefficients.z); - return sqrt(Intensity / IntensityMod); + float IntensityMod = (Intensity * 5.f / 255.f * mDistAttenCoefficients.Z); + return sqrtf(Intensity / IntensityMod); } else { - if (mDistAttenCoefficients.y <= FLT_EPSILON) + if (mDistAttenCoefficients.Y <= FLT_EPSILON) return 0.f; float IntensityMod = (Intensity * 5.f) / 255.f; if (IntensityMod < 0.2f) IntensityMod = 0.2f; - return Intensity / (IntensityMod * mDistAttenCoefficients.y); + return Intensity / (IntensityMod * mDistAttenCoefficients.Y); } } @@ -56,10 +56,10 @@ float CLight::CalculateRadius() const float CLight::CalculateIntensity() const { // Get the color component with the greatest numeric value - float Greatest = (mColor.g >= mColor.b) ? mColor.g : mColor.b; - Greatest = (mColor.r >= Greatest) ? mColor.r : Greatest; + float Greatest = (mColor.G >= mColor.B) ? mColor.G : mColor.B; + Greatest = (mColor.R >= Greatest) ? mColor.R : Greatest; - float Multiplier = (mType == eCustom) ? mAngleAttenCoefficients.x : 1.0f; + float Multiplier = (mType == eCustom) ? mAngleAttenCoefficients.X : 1.0f; return Greatest * Multiplier; } @@ -78,42 +78,7 @@ CVector3f CLight::CalculateSpotAngleAtten() return CVector3f(0.f, -RadianCosine / InvCosine, 1.f / InvCosine); } -// ************ GETTERS ************ -ELightType CLight::GetType() const -{ - return mType; -} - -u32 CLight::GetLayerIndex() const -{ - return mLayerIndex; -} - -CVector3f CLight::GetPosition() const -{ - return mPosition; -} - -CVector3f CLight::GetDirection() const -{ - return mDirection; -} - -CColor CLight::GetColor() const -{ - return mColor; -} - -CVector3f CLight::GetDistAttenuation() const -{ - return mDistAttenCoefficients; -} - -CVector3f CLight::GetAngleAttenuation() const -{ - return mAngleAttenCoefficients; -} - +// ************ ACCESSORS ************ float CLight::GetRadius() const { if (mDirtyFlags & CLIGHT_NO_RADIUS) @@ -136,25 +101,9 @@ float CLight::GetIntensity() const return mCachedIntensity; } -// ************ SETTERS ************ -void CLight::SetLayer(u32 index) +void CLight::SetColor(const CColor& rkColor) { - mLayerIndex = index; -} - -void CLight::SetPosition(const CVector3f& Position) -{ - mPosition = Position; -} - -void CLight::SetDirection(const CVector3f& Direction) -{ - mDirection = Direction; -} - -void CLight::SetColor(const CColor& Color) -{ - mColor = Color; + mColor = rkColor; mDirtyFlags = CLIGHT_NO_RADIUS | CLIGHT_NO_INTENSITY; } @@ -166,16 +115,16 @@ void CLight::SetSpotCutoff(float Cutoff) void CLight::SetDistAtten(float DistCoefA, float DistCoefB, float DistCoefC) { - mDistAttenCoefficients.x = DistCoefA; - mDistAttenCoefficients.y = DistCoefB; - mDistAttenCoefficients.z = DistCoefC; + mDistAttenCoefficients.X = DistCoefA; + mDistAttenCoefficients.Y = DistCoefB; + mDistAttenCoefficients.Z = DistCoefC; } void CLight::SetAngleAtten(float AngleCoefA, float AngleCoefB, float AngleCoefC) { - mAngleAttenCoefficients.x = AngleCoefA; - mAngleAttenCoefficients.y = AngleCoefB; - mAngleAttenCoefficients.z = AngleCoefC; + mAngleAttenCoefficients.X = AngleCoefA; + mAngleAttenCoefficients.Y = AngleCoefB; + mAngleAttenCoefficients.Z = AngleCoefC; } // ************ OTHER ************ @@ -184,9 +133,7 @@ void CLight::Load() const u8 Index = (u8) CGraphics::sNumLights; if (Index >= 8) return; - CGraphics::SLightBlock::SGXLight *Light = &CGraphics::sLightBlock.Lights[Index]; - CVector3f PosView = CGraphics::sMVPBlock.ViewMatrix * mPosition; - CVector3f DirView = CGraphics::sMVPBlock.ViewMatrix * mDirection; + CGraphics::SLightBlock::SGXLight *pLight = &CGraphics::sLightBlock.Lights[Index]; switch (mType) { @@ -194,25 +141,25 @@ void CLight::Load() const // LocalAmbient is already accounted for in CGraphics::sAreaAmbientColor return; case eDirectional: - Light->Position = CVector4f(-mDirection * 1048576.f, 1.f); - Light->Direction = CVector4f(mDirection, 0.f); - Light->Color = mColor * CGraphics::sWorldLightMultiplier; - Light->DistAtten = CVector4f(1.f, 0.f, 0.f, 0.f); - Light->AngleAtten = CVector4f(1.f, 0.f, 0.f, 0.f); + pLight->Position = CVector4f(-mDirection * 1048576.f, 1.f); + pLight->Direction = CVector4f(mDirection, 0.f); + pLight->Color = mColor * CGraphics::sWorldLightMultiplier; + pLight->DistAtten = CVector4f(1.f, 0.f, 0.f, 0.f); + pLight->AngleAtten = CVector4f(1.f, 0.f, 0.f, 0.f); break; case eSpot: - Light->Position = CVector4f(mPosition, 1.f); - Light->Direction = CVector4f(mDirection, 0.f); - Light->Color = mColor * CGraphics::sWorldLightMultiplier; - Light->DistAtten = mDistAttenCoefficients; - Light->AngleAtten = mAngleAttenCoefficients; + pLight->Position = CVector4f(mPosition, 1.f); + pLight->Direction = CVector4f(mDirection, 0.f); + pLight->Color = mColor * CGraphics::sWorldLightMultiplier; + pLight->DistAtten = mDistAttenCoefficients; + pLight->AngleAtten = mAngleAttenCoefficients; break; case eCustom: - Light->Position = CVector4f(mPosition, 1.f); - Light->Direction = CVector4f(mDirection, 0.f); - Light->Color = mColor * CGraphics::sWorldLightMultiplier; - Light->DistAtten = mDistAttenCoefficients; - Light->AngleAtten = mAngleAttenCoefficients; + pLight->Position = CVector4f(mPosition, 1.f); + pLight->Direction = CVector4f(mDirection, 0.f); + pLight->Color = mColor * CGraphics::sWorldLightMultiplier; + pLight->DistAtten = mDistAttenCoefficients; + pLight->AngleAtten = mAngleAttenCoefficients; break; default: return; @@ -221,57 +168,57 @@ void CLight::Load() const } // ************ STATIC ************ -CLight* CLight::BuildLocalAmbient(const CVector3f& Position, const CColor& Color) +CLight* CLight::BuildLocalAmbient(const CVector3f& rkPosition, const CColor& rkColor) { - CLight *Light = new CLight; - Light->mType = eLocalAmbient; - Light->mPosition = Position; - Light->mDirection = skDefaultLightDir; - Light->mColor = Color; - Light->mSpotCutoff = 0.f; - return Light; + CLight *pLight = new CLight; + pLight->mType = eLocalAmbient; + pLight->mPosition = rkPosition; + pLight->mDirection = skDefaultLightDir; + pLight->mColor = rkColor; + pLight->mSpotCutoff = 0.f; + return pLight; } -CLight* CLight::BuildDirectional(const CVector3f& Position, const CVector3f& Direction, const CColor& Color) +CLight* CLight::BuildDirectional(const CVector3f& rkPosition, const CVector3f& rkDirection, const CColor& rkColor) { - CLight *Light = new CLight; - Light->mType = eDirectional; - Light->mPosition = Position; - Light->mDirection = Direction; - Light->mColor = Color; - Light->mSpotCutoff = 0.f; - return Light; + CLight *pLight = new CLight; + pLight->mType = eDirectional; + pLight->mPosition = rkPosition; + pLight->mDirection = rkDirection; + pLight->mColor = rkColor; + pLight->mSpotCutoff = 0.f; + return pLight; } -CLight* CLight::BuildSpot(const CVector3f& Position, const CVector3f& Direction, const CColor& Color, float Cutoff) +CLight* CLight::BuildSpot(const CVector3f& rkPosition, const CVector3f& rkDirection, const CColor& rkColor, float Cutoff) { - CLight *Light = new CLight; - Light->mType = eSpot; - Light->mPosition = Position; - Light->mDirection = -Direction.Normalized(); - Light->mColor = Color; - Light->mSpotCutoff = Cutoff * 0.5f; - Light->mAngleAttenCoefficients = Light->CalculateSpotAngleAtten(); - return Light; + CLight *pLight = new CLight; + pLight->mType = eSpot; + pLight->mPosition = rkPosition; + pLight->mDirection = -rkDirection.Normalized(); + pLight->mColor = rkColor; + pLight->mSpotCutoff = Cutoff * 0.5f; + pLight->mAngleAttenCoefficients = pLight->CalculateSpotAngleAtten(); + return pLight; } -CLight* CLight::BuildCustom(const CVector3f& Position, const CVector3f& Direction, const CColor& Color, +CLight* CLight::BuildCustom(const CVector3f& rkPosition, const CVector3f& rkDirection, const CColor& rkColor, float DistAttenA, float DistAttenB, float DistAttenC, float AngleAttenA, float AngleAttenB, float AngleAttenC) { - CLight *Light = new CLight; - Light->mType = eCustom; - Light->mPosition = Position; - Light->mDirection = Direction; - Light->mColor = Color; - Light->mSpotCutoff = 0.f; - Light->mDistAttenCoefficients.x = DistAttenA; - Light->mDistAttenCoefficients.y = DistAttenB; - Light->mDistAttenCoefficients.z = DistAttenC; - Light->mAngleAttenCoefficients.x = AngleAttenA; - Light->mAngleAttenCoefficients.y = AngleAttenB; - Light->mAngleAttenCoefficients.z = AngleAttenC * AngleAttenC; - return Light; + CLight *pLight = new CLight; + pLight->mType = eCustom; + pLight->mPosition = rkPosition; + pLight->mDirection = rkDirection; + pLight->mColor = rkColor; + pLight->mSpotCutoff = 0.f; + pLight->mDistAttenCoefficients.X = DistAttenA; + pLight->mDistAttenCoefficients.Y = DistAttenB; + pLight->mDistAttenCoefficients.Z = DistAttenC; + pLight->mAngleAttenCoefficients.X = AngleAttenA; + pLight->mAngleAttenCoefficients.Y = AngleAttenB; + pLight->mAngleAttenCoefficients.Z = AngleAttenC * AngleAttenC; + return pLight; } // ************ CONSTANTS ************ diff --git a/src/Core/Resource/CLight.h b/src/Core/Resource/CLight.h index 1a594815..2c554f32 100644 --- a/src/Core/Resource/CLight.h +++ b/src/Core/Resource/CLight.h @@ -41,22 +41,23 @@ private: CVector3f CalculateSpotAngleAtten(); public: - // Getters - ELightType GetType() const; - u32 GetLayerIndex() const; - CVector3f GetPosition() const; - CVector3f GetDirection() const; - CColor GetColor() const; - CVector3f GetDistAttenuation() const; - CVector3f GetAngleAttenuation() const; + // Accessors + inline ELightType Type() const { return mType; } + inline u32 LayerIndex() const { return mLayerIndex; } + inline CVector3f Position() const { return mPosition; } + inline CVector3f Direction() const { return mDirection; } + inline CColor Color() const { return mColor; } + inline CVector3f DistAttenuation() const { return mDistAttenCoefficients; } + inline CVector3f AngleAttenuation() const { return mAngleAttenCoefficients; } + + inline void SetLayer(u32 Index) { mLayerIndex = Index; } + inline void SetPosition(const CVector3f& rkPosition) { mPosition = rkPosition; } + inline void SetDirection(const CVector3f& rkDirection) { mDirection = rkDirection; } + float GetRadius() const; float GetIntensity() const; - // Setters - void SetLayer(u32 index); - void SetPosition(const CVector3f& Position); - void SetDirection(const CVector3f& Direction); - void SetColor(const CColor& Color); + void SetColor(const CColor& rkColor); void SetSpotCutoff(float Cutoff); void SetDistAtten(float DistCoefA, float DistCoefB, float DistCoefC); void SetAngleAtten(float AngleCoefA, float AngleCoefB, float AngleCoefC); @@ -65,10 +66,10 @@ public: void Load() const; // Static - static CLight* BuildLocalAmbient(const CVector3f& Position, const CColor& Color); - static CLight* BuildDirectional(const CVector3f& Position, const CVector3f& Direction, const CColor& Color); - static CLight* BuildSpot(const CVector3f& Position, const CVector3f& Direction, const CColor& Color, float Cutoff); - static CLight* BuildCustom(const CVector3f& Position, const CVector3f& Direction, const CColor& Color, + static CLight* BuildLocalAmbient(const CVector3f& rkPosition, const CColor& rkColor); + static CLight* BuildDirectional(const CVector3f& rkPosition, const CVector3f& rkDirection, const CColor& rkColor); + static CLight* BuildSpot(const CVector3f& rkPosition, const CVector3f& rkDirection, const CColor& rkColor, float Cutoff); + static CLight* BuildCustom(const CVector3f& rkPosition, const CVector3f& rkDirection, const CColor& rkColor, float DistAttenA, float DistAttenB, float DistAttenC, float AngleAttenA, float AngleAttenB, float AngleAttenC); diff --git a/src/Core/Resource/CMaterial.cpp b/src/Core/Resource/CMaterial.cpp index e1ed6ac2..56b039a4 100644 --- a/src/Core/Resource/CMaterial.cpp +++ b/src/Core/Resource/CMaterial.cpp @@ -13,31 +13,44 @@ u64 CMaterial::sCurrentMaterial = 0; CColor CMaterial::sCurrentTint = CColor::skWhite; CMaterial::CMaterial() + : mpShader(nullptr) + , mShaderStatus(eNoShader) + , mRecalcHash(true) + , mEnableBloom(false) + , mVersion(eUnknownVersion) + , mOptions(eNoSettings) + , mVtxDesc(eNoAttributes) + , mBlendSrcFac(GL_ONE) + , mBlendDstFac(GL_ZERO) + , mLightingEnabled(true) + , mEchoesUnknownA(0) + , mEchoesUnknownB(0) + , mpIndirectTexture(nullptr) { - mpShader = nullptr; - mShaderStatus = eNoShader; - mRecalcHash = true; - mEnableBloom = false; - mVersion = eUnknownVersion; - mOptions = eNoSettings; - mVtxDesc = eNoAttributes; - mBlendSrcFac = GL_ONE; - mBlendDstFac = GL_ZERO; - mLightingEnabled = true; - mEchoesUnknownA = 0; - mEchoesUnknownB = 0; - mpIndirectTexture = nullptr; } -CMaterial::CMaterial(EGame version, FVertexDescription vtxDesc) +CMaterial::CMaterial(EGame Version, FVertexDescription VtxDesc) + : mpShader(nullptr) + , mShaderStatus(eNoShader) + , mRecalcHash(true) + , mEnableBloom(Version == eCorruption) + , mVersion(Version) + , mOptions(eDepthWrite) + , mVtxDesc(VtxDesc) + , mBlendSrcFac(GL_ONE) + , mBlendDstFac(GL_ZERO) + , mLightingEnabled(true) + , mEchoesUnknownA(0) + , mEchoesUnknownB(0) + , mpIndirectTexture(nullptr) { mpShader = nullptr; mShaderStatus = eNoShader; mRecalcHash = true; - mEnableBloom = (version == eCorruption); - mVersion = version; + mEnableBloom = (Version == eCorruption); + mVersion = Version; mOptions = eDepthWrite; - mVtxDesc = vtxDesc; + mVtxDesc = VtxDesc; mBlendSrcFac = GL_ONE; mBlendDstFac = GL_ZERO; mLightingEnabled = true; @@ -218,114 +231,6 @@ void CMaterial::Update() mShaderStatus = eNoShader; } -// ************ GETTERS ************ -TString CMaterial::Name() const -{ - return mName; -} - -EGame CMaterial::Version() const -{ - return mVersion; -} - -CMaterial::FMaterialOptions CMaterial::Options() const -{ - return mOptions; -} - -FVertexDescription CMaterial::VtxDesc() const -{ - return mVtxDesc; -} - -GLenum CMaterial::BlendSrcFac() const { - return mBlendSrcFac; -} - -GLenum CMaterial::BlendDstFac() const { - return mBlendDstFac; -} - -CColor CMaterial::Konst(u32 KIndex) const -{ - if (KIndex > 3) return CColor::skTransparentBlack; - else return mKonstColors[KIndex]; -} - -CTexture* CMaterial::IndTexture() const -{ - return mpIndirectTexture; -} - -bool CMaterial::IsLightingEnabled() const -{ - return mLightingEnabled; -} - -u32 CMaterial::EchoesUnknownA() const -{ - return mEchoesUnknownA; -} - -u32 CMaterial::EchoesUnknownB() const -{ - return mEchoesUnknownB; -} - -u32 CMaterial::PassCount() const -{ - return mPasses.size(); -} - -CMaterialPass* CMaterial::Pass(u32 PassIndex) const -{ - return mPasses[PassIndex]; -} - - -// ************ SETTERS ************ -void CMaterial::SetName(const TString& name) -{ - mName = name; -} - -void CMaterial::SetOptions(FMaterialOptions Options) -{ - mOptions = Options; - mRecalcHash = true; -} - -void CMaterial::SetVertexDescription(FVertexDescription desc) -{ - mVtxDesc = desc; - mRecalcHash = true; -} - -void CMaterial::SetBlendMode(GLenum SrcFac, GLenum DstFac) -{ - mBlendSrcFac = SrcFac; - mBlendDstFac = DstFac; - mRecalcHash = true; -} - -void CMaterial::SetKonst(CColor& Konst, u32 KIndex) -{ - mKonstColors[KIndex] = Konst; - mRecalcHash = true; -} - -void CMaterial::SetIndTexture(CTexture *pTex) -{ - mpIndirectTexture = pTex; -} - -void CMaterial::SetLightingEnabled(bool Enabled) -{ - mLightingEnabled = Enabled; - mRecalcHash = true; -} - void CMaterial::SetNumPasses(u32 NumPasses) { if (NumPasses < mPasses.size()) @@ -345,9 +250,3 @@ void CMaterial::SetNumPasses(u32 NumPasses) mRecalcHash = true; } - -// ************ STATIC ************ -void CMaterial::KillCachedMaterial() -{ - sCurrentMaterial = 0; -} diff --git a/src/Core/Resource/CMaterial.h b/src/Core/Resource/CMaterial.h index 4e33e74d..6e58a0f0 100644 --- a/src/Core/Resource/CMaterial.h +++ b/src/Core/Resource/CMaterial.h @@ -74,41 +74,41 @@ private: public: CMaterial(); - CMaterial(EGame version, FVertexDescription vtxDesc); + CMaterial(EGame Version, FVertexDescription VtxDesc); ~CMaterial(); + CMaterial* Clone(); void GenerateShader(bool AllowRegen = true); bool SetCurrent(FRenderOptions Options); u64 HashParameters(); void Update(); - - // Getters - TString Name() const; - EGame Version() const; - FMaterialOptions Options() const; - FVertexDescription VtxDesc() const; - GLenum BlendSrcFac() const; - GLenum BlendDstFac() const; - CColor Konst(u32 KIndex) const; - CTexture* IndTexture() const; - bool IsLightingEnabled() const; - u32 EchoesUnknownA() const; - u32 EchoesUnknownB() const; - u32 PassCount() const; - CMaterialPass* Pass(u32 PassIndex) const; - - // Setters - void SetName(const TString& name); - void SetOptions(FMaterialOptions Options); - void SetVertexDescription(FVertexDescription desc); - void SetBlendMode(GLenum SrcFac, GLenum DstFac); - void SetKonst(CColor& Konst, u32 KIndex); - void SetIndTexture(CTexture *pTex); - void SetLightingEnabled(bool Enabled); void SetNumPasses(u32 NumPasses); + // Accessors + inline TString Name() const { return mName; } + inline EGame Version() const { return mVersion; } + inline FMaterialOptions Options() const { return mOptions; } + inline FVertexDescription VtxDesc() const { return mVtxDesc; } + inline GLenum BlendSrcFac() const { return mBlendSrcFac; } + inline GLenum BlendDstFac() const { return mBlendDstFac; } + inline CColor Konst(u32 KIndex) const { return mKonstColors[KIndex]; } + inline CTexture* IndTexture() const { return mpIndirectTexture; } + inline bool IsLightingEnabled() const { return mLightingEnabled; } + inline u32 EchoesUnknownA() const { return mEchoesUnknownA; } + inline u32 EchoesUnknownB() const { return mEchoesUnknownB; } + inline u32 PassCount() const { return mPasses.size(); } + inline CMaterialPass* Pass(u32 PassIndex) const { return mPasses[PassIndex]; } + + inline void SetName(const TString& rkName) { mName = rkName; } + inline void SetOptions(FMaterialOptions Options) { mOptions = Options; mRecalcHash = true; } + inline void SetVertexDescription(FVertexDescription Desc) { mVtxDesc = Desc; mRecalcHash = true; } + inline void SetBlendMode(GLenum SrcFac, GLenum DstFac) { mBlendSrcFac = SrcFac; mBlendDstFac = DstFac; mRecalcHash = true; } + inline void SetKonst(CColor& Konst, u32 KIndex) { mKonstColors[KIndex] = Konst; mRecalcHash = true; } + inline void SetIndTexture(CTexture *pTex) { mpIndirectTexture = pTex; } + inline void SetLightingEnabled(bool Enabled) { mLightingEnabled = Enabled; mRecalcHash = true; } + // Static - static void KillCachedMaterial(); + inline static void KillCachedMaterial() { sCurrentMaterial = 0; } }; #endif // MATERIAL_H diff --git a/src/Core/Resource/CMaterialPass.cpp b/src/Core/Resource/CMaterialPass.cpp index 1649bb19..0a521119 100644 --- a/src/Core/Resource/CMaterialPass.cpp +++ b/src/Core/Resource/CMaterialPass.cpp @@ -1,24 +1,22 @@ #include "CMaterialPass.h" #include "CMaterial.h" #include "Core/Render/CGraphics.h" -#include +#include CMaterialPass::CMaterialPass(CMaterial *pParent) + : mPassType("CUST") + , mSettings(eNoPassSettings) + , mpTexture(nullptr) + , mEnabled(true) + , mpParentMat(pParent) + , mColorOutput(ePrevReg) + , mAlphaOutput(ePrevReg) + , mKColorSel(eKonstOne) + , mKAlphaSel(eKonstOne) + , mRasSel(eRasColorNull) + , mTexCoordSource(0xFF) + , mAnimMode(eNoUVAnim) { - mPassType = "CUST"; - mSettings = eNoPassSettings; - mpTexture = nullptr; - mEnabled = true; - mpParentMat = pParent; - - mColorOutput = ePrevReg; - mAlphaOutput = ePrevReg; - mKColorSel = eKonstOne; - mKAlphaSel = eKonstOne; - mRasSel = eRasColorNull; - mTexCoordSource = 0xFF; - mAnimMode = eNoUVAnim; - for (u32 iParam = 0; iParam < 4; iParam++) { mColorInputs[iParam] = eZeroRGB; @@ -36,10 +34,13 @@ CMaterialPass* CMaterialPass::Clone(CMaterial *pParent) CMaterialPass *pOut = new CMaterialPass(pParent); pOut->mPassType = mPassType; pOut->mSettings = mSettings; - for (u32 iIn = 0; iIn < 4; iIn++) { + + for (u32 iIn = 0; iIn < 4; iIn++) + { pOut->mColorInputs[iIn] = mColorInputs[iIn]; pOut->mAlphaInputs[iIn] = mAlphaInputs[iIn]; } + pOut->mColorOutput = mColorOutput; pOut->mAlphaOutput = mAlphaOutput; pOut->mKColorSel = mKColorSel; @@ -48,30 +49,32 @@ CMaterialPass* CMaterialPass::Clone(CMaterial *pParent) pOut->mTexCoordSource = mTexCoordSource; pOut->mpTexture = mpTexture; pOut->mAnimMode = mAnimMode; + for (u32 iParam = 0; iParam < 4; iParam++) pOut->mAnimParams[iParam] = mAnimParams[iParam]; + pOut->mEnabled = mEnabled; return pOut; } -void CMaterialPass::HashParameters(CHashFNV1A &Hash) +void CMaterialPass::HashParameters(CHashFNV1A& rHash) { if (mEnabled) { - Hash.HashLong(mPassType.ToLong()); - Hash.HashLong(mSettings); - Hash.HashData(&mColorInputs[0], sizeof(ETevColorInput) * 4); - Hash.HashData(&mAlphaInputs[0], sizeof(ETevAlphaInput) * 4); - Hash.HashLong(mColorOutput); - Hash.HashLong(mAlphaOutput); - Hash.HashLong(mKColorSel); - Hash.HashLong(mKAlphaSel); - Hash.HashLong(mRasSel); - Hash.HashLong(mTexCoordSource); - Hash.HashLong(mAnimMode); - Hash.HashData(mAnimParams, sizeof(float) * 4); - Hash.HashByte(mEnabled); + rHash.HashLong(mPassType.ToLong()); + rHash.HashLong(mSettings); + rHash.HashData(&mColorInputs[0], sizeof(ETevColorInput) * 4); + rHash.HashData(&mAlphaInputs[0], sizeof(ETevAlphaInput) * 4); + rHash.HashLong(mColorOutput); + rHash.HashLong(mAlphaOutput); + rHash.HashLong(mKColorSel); + rHash.HashLong(mKAlphaSel); + rHash.HashLong(mRasSel); + rHash.HashLong(mTexCoordSource); + rHash.HashLong(mAnimMode); + rHash.HashData(mAnimParams, sizeof(float) * 4); + rHash.HashByte(mEnabled); } } @@ -85,7 +88,7 @@ void CMaterialPass::SetAnimCurrent(FRenderOptions Options, u32 PassIndex) { if (mAnimMode == eNoUVAnim) return; - float s = AnimUtil::SecondsMod900(); + float Seconds = CTimer::SecondsMod900(); const CMatrix4f& ModelMtx = CGraphics::sMVPBlock.ModelMatrix; const CMatrix4f& ViewMtx = CGraphics::sMVPBlock.ViewMatrix; @@ -98,9 +101,9 @@ void CMaterialPass::SetAnimCurrent(FRenderOptions Options, u32 PassIndex) case eInverseMV: // Mode 0 case eSimpleMode: // Mode 10 - maybe not correct? { - glm::mat4 mtx = glm::inverse(glm::transpose(ViewMtx.ToGlmMat4()) * glm::transpose(ModelMtx.ToGlmMat4())); - mtx[0][3] = mtx[1][3] = mtx[2][3] = 0.f; - TexMtx = CMatrix4f::FromGlmMat4(mtx); + glm::mat4 InvMV = glm::inverse(glm::transpose(ViewMtx.ToGlmMat4()) * glm::transpose(ModelMtx.ToGlmMat4())); + InvMV[0][3] = InvMV[1][3] = InvMV[2][3] = 0.f; + TexMtx = CMatrix4f::FromGlmMat4(InvMV); PostMtx = CMatrix4f(0.5f, 0.0f, 0.0f, 0.5f, 0.0f, 0.5f, 0.0f, 0.5f, 0.0f, 0.0f, 0.0f, 1.0f, @@ -110,8 +113,8 @@ void CMaterialPass::SetAnimCurrent(FRenderOptions Options, u32 PassIndex) case eInverseMVTranslated: // Mode 1 { - glm::mat4 mtx = glm::inverse(glm::transpose(ViewMtx.ToGlmMat4()) * glm::transpose(ModelMtx.ToGlmMat4())); - TexMtx = CMatrix4f::FromGlmMat4(mtx); + glm::mat4 InvMV = glm::inverse(glm::transpose(ViewMtx.ToGlmMat4()) * glm::transpose(ModelMtx.ToGlmMat4())); + TexMtx = CMatrix4f::FromGlmMat4(InvMV); PostMtx = CMatrix4f(0.5f, 0.0f, 0.0f, 0.5f, 0.0f, 0.5f, 0.0f, 0.5f, 0.0f, 0.0f, 0.0f, 1.0f, @@ -122,8 +125,8 @@ void CMaterialPass::SetAnimCurrent(FRenderOptions Options, u32 PassIndex) { if (Options & eEnableUVScroll) { - TexMtx[0][3] = (s * mAnimParams[2]) + mAnimParams[0]; - TexMtx[1][3] = (s * mAnimParams[3]) + mAnimParams[1]; + TexMtx[0][3] = (Seconds * mAnimParams[2]) + mAnimParams[0]; + TexMtx[1][3] = (Seconds * mAnimParams[3]) + mAnimParams[1]; } break; } @@ -132,7 +135,7 @@ void CMaterialPass::SetAnimCurrent(FRenderOptions Options, u32 PassIndex) { if (Options & eEnableUVScroll) { - float Angle = (s * mAnimParams[1]) + mAnimParams[0]; + float Angle = (Seconds * mAnimParams[1]) + mAnimParams[0]; float ACos = cos(Angle); float ASin = sin(Angle); @@ -152,7 +155,7 @@ void CMaterialPass::SetAnimCurrent(FRenderOptions Options, u32 PassIndex) { if (Options & eEnableUVScroll) { - float Offset = mAnimParams[2] * mAnimParams[0] * (mAnimParams[3] + s); + float Offset = mAnimParams[2] * mAnimParams[0] * (mAnimParams[3] + Seconds); Offset = (float)(short)(float)(mAnimParams[1] * fmod(Offset, 1.0f)) * mAnimParams[2]; if (mAnimMode == eHFilmstrip) TexMtx[0][3] = Offset; if (mAnimMode == eVFilmstrip) TexMtx[1][3] = Offset; @@ -175,23 +178,22 @@ void CMaterialPass::SetAnimCurrent(FRenderOptions Options, u32 PassIndex) case eConvolutedModeA: // Mode 7 { - CMatrix4f view = CGraphics::sMVPBlock.ViewMatrix; + CMatrix4f View = CGraphics::sMVPBlock.ViewMatrix; - // Oh god I seriously need a CMatrix4f inverse function. - glm::mat4 mtx = glm::inverse(glm::transpose(ViewMtx.ToGlmMat4()) * glm::transpose(ModelMtx.ToGlmMat4())); - mtx[0][3] = mtx[1][3] = mtx[2][3] = 0.f; - TexMtx = CMatrix4f::FromGlmMat4(mtx); + glm::mat4 Mtx = glm::inverse(glm::transpose(ViewMtx.ToGlmMat4()) * glm::transpose(ModelMtx.ToGlmMat4())); + Mtx[0][3] = Mtx[1][3] = Mtx[2][3] = 0.f; + TexMtx = CMatrix4f::FromGlmMat4(Mtx); - float xy = (view[3][0] + view[3][1]) * 0.025f * mAnimParams[1]; - xy = (xy - (int) xy); + float XY = (View[3][0] + View[3][1]) * 0.025f * mAnimParams[1]; + XY = (XY - (int) XY); - float z = view[3][2] * 0.05f * mAnimParams[1]; - z = (z - (int) z); + float Z = View[3][2] * 0.05f * mAnimParams[1]; + Z = (Z - (int) Z); - float halfA = mAnimParams[0] * 0.5f; + float HalfA = mAnimParams[0] * 0.5f; - PostMtx = CMatrix4f(halfA, 0.0f, 0.0f, xy, - 0.0f, 0.0f, halfA, z, + PostMtx = CMatrix4f(HalfA, 0.0f, 0.0f, XY, + 0.0f, 0.0f, HalfA, Z, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f); break; diff --git a/src/Core/Resource/CMaterialPass.h b/src/Core/Resource/CMaterialPass.h index f60497c5..3dcd1ef2 100644 --- a/src/Core/Resource/CMaterialPass.h +++ b/src/Core/Resource/CMaterialPass.h @@ -45,7 +45,7 @@ public: CMaterialPass(CMaterial *pParent); ~CMaterialPass(); CMaterialPass* Clone(CMaterial *pParent); - void HashParameters(CHashFNV1A& Hash); + void HashParameters(CHashFNV1A& rHash); void LoadTexture(u32 PassIndex); void SetAnimCurrent(FRenderOptions Options, u32 PassIndex); @@ -65,61 +65,20 @@ public: void SetEnabled(bool Enabled); // Getters - inline CFourCC Type() const { - return mPassType; - } - - inline TString NamedType() const { - return PassTypeName(mPassType); - } - - inline ETevColorInput ColorInput(u32 Input) const { - return mColorInputs[Input]; - } - - inline ETevAlphaInput AlphaInput(u32 Input) const { - return mAlphaInputs[Input]; - } - - inline ETevOutput ColorOutput() const { - return mColorOutput; - } - - inline ETevOutput AlphaOutput() const { - return mAlphaOutput; - } - - inline ETevKSel KColorSel() const { - return mKColorSel; - } - - inline ETevKSel KAlphaSel() const { - return mKAlphaSel; - } - - inline ETevRasSel RasSel() const { - return mRasSel; - } - - inline u32 TexCoordSource() const { - return mTexCoordSource; - } - - inline CTexture* Texture() const { - return mpTexture; - } - - inline EUVAnimMode AnimMode() const { - return mAnimMode; - } - - inline float AnimParam(u32 ParamIndex) const { - return mAnimParams[ParamIndex]; - } - - inline bool IsEnabled() const { - return mEnabled; - } + inline CFourCC Type() const { return mPassType; } + inline TString NamedType() const { return PassTypeName(mPassType); } + inline ETevColorInput ColorInput(u32 Input) const { return mColorInputs[Input]; } + inline ETevAlphaInput AlphaInput(u32 Input) const { return mAlphaInputs[Input]; } + inline ETevOutput ColorOutput() const { return mColorOutput; } + inline ETevOutput AlphaOutput() const { return mAlphaOutput; } + inline ETevKSel KColorSel() const { return mKColorSel; } + inline ETevKSel KAlphaSel() const { return mKAlphaSel; } + inline ETevRasSel RasSel() const { return mRasSel; } + inline u32 TexCoordSource() const { return mTexCoordSource; } + inline CTexture* Texture() const { return mpTexture; } + inline EUVAnimMode AnimMode() const { return mAnimMode; } + inline float AnimParam(u32 ParamIndex) const { return mAnimParams[ParamIndex]; } + inline bool IsEnabled() const { return mEnabled; } // Static static TString PassTypeName(CFourCC Type); diff --git a/src/Core/Resource/CMaterialSet.cpp b/src/Core/Resource/CMaterialSet.cpp deleted file mode 100644 index f78b3f1f..00000000 --- a/src/Core/Resource/CMaterialSet.cpp +++ /dev/null @@ -1,49 +0,0 @@ -#include "CMaterialSet.h" -#include "CResCache.h" -#include - -CMaterialSet::CMaterialSet() -{ -} - -CMaterialSet::~CMaterialSet() -{ - for (u32 iMat = 0; iMat < mMaterials.size(); iMat++) - delete mMaterials[iMat]; -} - -CMaterialSet* CMaterialSet::Clone() -{ - CMaterialSet *pOut = new CMaterialSet(); - - pOut->mMaterials.resize(mMaterials.size()); - for (u32 iMat = 0; iMat < mMaterials.size(); iMat++) - pOut->mMaterials[iMat] = mMaterials[iMat]->Clone(); - - return pOut; -} - -u32 CMaterialSet::NumMaterials() -{ - return mMaterials.size(); -} - -CMaterial* CMaterialSet::MaterialByIndex(u32 index) -{ - if (index >= NumMaterials()) return nullptr; - return mMaterials[index]; -} - -CMaterial* CMaterialSet::MaterialByName(const TString& name) -{ - for (auto it = mMaterials.begin(); it != mMaterials.end(); it++) - if ((*it)->Name() == name) return *it; - return nullptr; -} - -u32 CMaterialSet::MaterialIndexByName(const TString& name) -{ - for (u32 iMat = 0; iMat < mMaterials.size(); iMat++) - if (mMaterials[iMat]->Name() == name) return iMat; - return -1; -} diff --git a/src/Core/Resource/CMaterialSet.h b/src/Core/Resource/CMaterialSet.h index f89d6dbb..84250b75 100644 --- a/src/Core/Resource/CMaterialSet.h +++ b/src/Core/Resource/CMaterialSet.h @@ -14,13 +14,51 @@ class CMaterialSet std::vector mMaterials; public: - CMaterialSet(); - ~CMaterialSet(); - CMaterialSet* Clone(); - u32 NumMaterials(); - CMaterial* MaterialByIndex(u32 index); - CMaterial* MaterialByName(const TString& name); - u32 MaterialIndexByName(const TString& name); + CMaterialSet() {} + + ~CMaterialSet() + { + for (u32 iMat = 0; iMat < mMaterials.size(); iMat++) + delete mMaterials[iMat]; + } + + CMaterialSet* Clone() + { + CMaterialSet *pOut = new CMaterialSet(); + + pOut->mMaterials.resize(mMaterials.size()); + for (u32 iMat = 0; iMat < mMaterials.size(); iMat++) + pOut->mMaterials[iMat] = mMaterials[iMat]->Clone(); + + return pOut; + } + + u32 NumMaterials() + { + return mMaterials.size(); + } + + CMaterial* MaterialByIndex(u32 Index) + { + if (Index >= NumMaterials()) return nullptr; + return mMaterials[Index]; + } + + CMaterial* MaterialByName(const TString& rkName) + { + for (auto it = mMaterials.begin(); it != mMaterials.end(); it++) + if ((*it)->Name() == rkName) return *it; + + return nullptr; + } + + u32 MaterialIndexByName(const TString& rkName) + { + for (u32 iMat = 0; iMat < mMaterials.size(); iMat++) + if (mMaterials[iMat]->Name() == rkName) return iMat; + + return -1; + } }; #endif // CMATERIALSET_H diff --git a/src/Core/Resource/CPakFile.cpp b/src/Core/Resource/CPakFile.cpp index 215c1302..ae2e285a 100644 --- a/src/Core/Resource/CPakFile.cpp +++ b/src/Core/Resource/CPakFile.cpp @@ -10,161 +10,166 @@ #include CPakFile::CPakFile() + : mpPak(nullptr) { - pak = nullptr; } -CPakFile::CPakFile(IInputStream* pakfile) +CPakFile::CPakFile(IInputStream* pPakFile) { - pak = pakfile; - if (!pak->IsValid()) return; + mpPak = pPakFile; + if (!mpPak->IsValid()) return; - version = pak->ReadLong(); - pak->Seek(0x4, SEEK_CUR); + mVersion = mpPak->ReadLong(); + mpPak->Seek(0x4, SEEK_CUR); - u32 namedResCount = pak->ReadLong(); - NamedResTable.resize(namedResCount); + u32 NamedResCount = mpPak->ReadLong(); + mNamedResTable.resize(NamedResCount); - for (u32 n = 0; n < namedResCount; n++) + for (u32 iName = 0; iName < NamedResCount; iName++) { - SNamedResource *res = &NamedResTable[n]; - res->resType = CFourCC(*pak); - res->resID = (u64) pak->ReadLong(); - u32 resNameLength = pak->ReadLong(); - res->resName = pak->ReadString(resNameLength); + SNamedResource *pRes = &mNamedResTable[iName]; + pRes->Type = CFourCC(*mpPak); + pRes->ID = (u64) mpPak->ReadLong(); + u32 resNameLength = mpPak->ReadLong(); + pRes->Name = mpPak->ReadString(resNameLength); } - u32 resCount = pak->ReadLong(); - ResInfoTable.resize(resCount); + u32 ResCount = mpPak->ReadLong(); + mResInfoTable.resize(ResCount); - for (u32 r = 0; r < resCount; r++) + for (u32 iRes = 0; iRes < ResCount; iRes++) { - SResInfo *res = &ResInfoTable[r]; - res->compressed = (pak->ReadLong() != 0); - res->resType = CFourCC(*pak); - res->resID = (u64) pak->ReadLong(); - res->size = pak->ReadLong(); - res->offset = pak->ReadLong(); + SResInfo *pRes = &mResInfoTable[iRes]; + pRes->Compressed = (mpPak->ReadLong() != 0); + pRes->Type = CFourCC(*mpPak); + pRes->ID = (u64) mpPak->ReadLong(); + pRes->Size = mpPak->ReadLong(); + pRes->Offset = mpPak->ReadLong(); } } CPakFile::~CPakFile() { - if (pak) delete pak; + if (mpPak) delete mpPak; } -std::vector CPakFile::getNamedResources() +std::vector CPakFile::NamedResources() { - return NamedResTable; + return mNamedResTable; } -SResInfo CPakFile::getResourceInfo(u64 assetID, CFourCC assetType) +SResInfo CPakFile::ResourceInfo(u64 AssetID, CFourCC AssetType) { // TODO: figure out how the game finds assets in paks, implement similar system to speed things up - if (ResInfoTable.empty()) + if (mResInfoTable.empty()) return SResInfo(); - for (u32 r = 0; r < ResInfoTable.size(); r++) + for (u32 iRes = 0; iRes < mResInfoTable.size(); iRes++) { - if (((u64) (ResInfoTable[r].resID & 0xFFFFFFFF) == (u64) (assetID & 0xFFFFFFFF)) && (ResInfoTable[r].resType == assetType)) - return ResInfoTable[r]; + if (((u64) (mResInfoTable[iRes].ID & 0xFFFFFFFF) == (u64) (AssetID & 0xFFFFFFFF)) && (mResInfoTable[iRes].Type == AssetType)) + return mResInfoTable[iRes]; } return SResInfo(); } -std::vector* CPakFile::getResource(u64 assetID, CFourCC assetType) +std::vector* CPakFile::Resource(u64 AssetID, CFourCC AssetType) { - SResInfo info = getResourceInfo(assetID, assetType); + SResInfo Info = ResourceInfo(AssetID, AssetType); // make sure SResInfo is valid - if ((u64) (info.resID & 0xFFFFFFFF) != (u64) (assetID & 0xFFFFFFFF)) return nullptr; - else return getResource(info); + if ((u64) (Info.ID & 0xFFFFFFFF) != (u64) (AssetID & 0xFFFFFFFF)) return nullptr; + else return Resource(Info); } -std::vector* CPakFile::getResource(SResInfo& info) +std::vector* CPakFile::Resource(SResInfo& rInfo) { - pak->Seek(info.offset, SEEK_SET); - std::vector *res_buf = new std::vector; + mpPak->Seek(rInfo.Offset, SEEK_SET); + std::vector *pResBuf = new std::vector; - if (info.compressed) + if (rInfo.Compressed) { - u32 decmp_size = pak->ReadLong(); - res_buf->resize(decmp_size); + u32 DecmpSize = mpPak->ReadLong(); + pResBuf->resize(DecmpSize); - std::vector cmp_buf(info.size - 4); - pak->ReadBytes(&cmp_buf[0], info.size - 4); + std::vector CmpBuf(rInfo.Size - 4); + mpPak->ReadBytes(&CmpBuf[0], rInfo.Size - 4); - bool dcmp = decompress(cmp_buf.data(), cmp_buf.size(), res_buf->data(), res_buf->size()); + bool Success = Decompress(CmpBuf.data(), CmpBuf.size(), pResBuf->data(), pResBuf->size()); - if (!dcmp) { - delete res_buf; + if (!Success) + { + delete pResBuf; return nullptr; } } - else { - res_buf->resize(info.size); - pak->ReadBytes(res_buf->data(), info.size); + else + { + pResBuf->resize(rInfo.Size); + mpPak->ReadBytes(pResBuf->data(), rInfo.Size); } - return res_buf; + return pResBuf; } -bool CPakFile::decompress(u8 *src, u32 src_len, u8 *dst, u32 dst_len) +bool CPakFile::Decompress(u8 *pSrc, u32 SrcLen, u8 *pDst, u32 DstLen) { - if ((src[0] == 0x78) && (src[1] == 0xda)) + if ((pSrc[0] == 0x78) && (pSrc[1] == 0xda)) { // zlib z_stream z; z.zalloc = Z_NULL; z.zfree = Z_NULL; z.opaque = Z_NULL; - z.avail_in = src_len; - z.next_in = src; - z.avail_out = dst_len; - z.next_out = dst; + z.avail_in = SrcLen; + z.next_in = pSrc; + z.avail_out = DstLen; + z.next_out = pDst; - s32 ret = inflateInit(&z); + s32 Ret = inflateInit(&z); - if (ret == Z_OK) + if (Ret == Z_OK) { - ret = inflate(&z, Z_NO_FLUSH); + Ret = inflate(&z, Z_NO_FLUSH); - if ((ret == Z_OK) || (ret == Z_STREAM_END)) - ret = inflateEnd(&z); + if ((Ret == Z_OK) || (Ret == Z_STREAM_END)) + Ret = inflateEnd(&z); } - if ((ret != Z_OK) && (ret != Z_STREAM_END)) { - Log::Error("zlib error: " + TString::FromInt32(ret, 0, 10)); + if ((Ret != Z_OK) && (Ret != Z_STREAM_END)) { + Log::Error("zlib error: " + TString::FromInt32(Ret, 0, 10)); return false; } else return true; } - else { + else + { // LZO - lzo_uint decmp; - s32 ret; - u8 *src_end = src + src_len; - u8 *dst_end = dst + dst_len; + lzo_uint Decmp; + s32 Ret; + u8 *pSrcEnd = pSrc + SrcLen; + u8 *pDstEnd = pDst + DstLen; lzo_init(); - while ((src < src_end) && (dst < dst_end)) { - short block_size; - memcpy(&block_size, src, 2); - if (IOUtil::kSystemEndianness == IOUtil::eLittleEndian) IOUtil::SwapBytes(block_size); - src += 2; + while ((pSrc < pSrcEnd) && (pDst < pDstEnd)) + { + short BlockSize; + memcpy(&BlockSize, pSrc, 2); + if (IOUtil::kSystemEndianness == IOUtil::eLittleEndian) IOUtil::SwapBytes(BlockSize); + pSrc += 2; - ret = lzo1x_decompress(src, block_size, dst, &decmp, LZO1X_MEM_DECOMPRESS); - if (ret != LZO_E_OK) break; - src += block_size; - dst += decmp; + Ret = lzo1x_decompress(pSrc, BlockSize, pDst, &Decmp, LZO1X_MEM_DECOMPRESS); + if (Ret != LZO_E_OK) break; + pSrc += BlockSize; + pDst += Decmp; } - if (ret != LZO_E_OK) { - Log::Error("LZO error: " + TString::FromInt32(ret, 0, 10)); + if (Ret != LZO_E_OK) + { + Log::Error("LZO error: " + TString::FromInt32(Ret, 0, 10)); return false; } diff --git a/src/Core/Resource/CPakFile.h b/src/Core/Resource/CPakFile.h index 3c71388e..56dd0d0e 100644 --- a/src/Core/Resource/CPakFile.h +++ b/src/Core/Resource/CPakFile.h @@ -10,22 +10,22 @@ class CPakFile { private: - u32 version; - std::vector NamedResTable; - std::vector ResInfoTable; - IInputStream* pak; + u32 mVersion; + std::vector mNamedResTable; + std::vector mResInfoTable; + IInputStream* mpPak; - bool decompress(u8 *src, u32 src_len, u8 *dst, u32 dst_len); + bool Decompress(u8 *pSrc, u32 SrcLen, u8 *pDst, u32 DstLen); public: CPakFile(); - CPakFile(IInputStream* pakfile); + CPakFile(IInputStream* pPakFile); ~CPakFile(); - std::vector getNamedResources(); - SResInfo getResourceInfo(u64 assetID, CFourCC assetType); - std::vector* getResource(u64 assetID, CFourCC assetType); - std::vector* getResource(SResInfo& info); + std::vector NamedResources(); + SResInfo ResourceInfo(u64 AssetID, CFourCC AssetType); + std::vector* Resource(u64 AssetID, CFourCC AssetType); + std::vector* Resource(SResInfo& rInfo); }; #endif // CPAKFILE_H diff --git a/src/Core/Resource/CResCache.cpp b/src/Core/Resource/CResCache.cpp index 8c53f196..ac0937c7 100644 --- a/src/Core/Resource/CResCache.cpp +++ b/src/Core/Resource/CResCache.cpp @@ -17,8 +17,8 @@ #include CResCache::CResCache() + : mpPak(nullptr) { - mpPak = nullptr; } CResCache::~CResCache() @@ -34,11 +34,11 @@ void CResCache::Clean() // I couldn't get this to work properly using reverse iterators, lol. // Resources get cached after their dependencies, which is why I go backwards // while loop is to ensure -all- unused resources are cleaned. Not sure of a better way to do it. - int numResourcesCleaned = 1; + int NumResourcesCleaned = 1; - while (numResourcesCleaned) + while (NumResourcesCleaned) { - numResourcesCleaned = 0; + NumResourcesCleaned = 0; for (auto it = mResourceCache.end(); it != mResourceCache.begin();) { @@ -47,41 +47,42 @@ void CResCache::Clean() { delete it->second; it = mResourceCache.erase(it); - numResourcesCleaned++; + NumResourcesCleaned++; } } } Log::Write(std::to_string(mResourceCache.size()) + " resources loaded"); } -void CResCache::SetFolder(TString path) +void CResCache::SetFolder(TString Path) { - path.EnsureEndsWith("/"); - mResSource.Path = path; - mResSource.Source = SResSource::Folder; - Log::Write("Set resource folder: " + path); + Path.EnsureEndsWith("/"); + mResSource.Path = Path; + mResSource.Source = SResSource::eFolder; + Log::Write("Set resource folder: " + Path); } -void CResCache::SetPak(const TString& path) +void CResCache::SetPak(const TString& rkPath) { - CFileInStream *pakfile = new CFileInStream(path.ToStdString(), IOUtil::eBigEndian); - if (!pakfile->IsValid()) + CFileInStream *pPakFile = new CFileInStream(rkPath.ToStdString(), IOUtil::eBigEndian); + + if (!pPakFile->IsValid()) { - Log::Error("Couldn't load pak file: " + path); - delete pakfile; + Log::Error("Couldn't load pak file: " + rkPath); + delete pPakFile; return; } if (mpPak) delete mpPak; - mpPak = new CPakFile(pakfile); - mResSource.Path = path; - mResSource.Source = SResSource::PakFile; - Log::Write("Loaded pak file: " + path); + mpPak = new CPakFile(pPakFile); + mResSource.Path = rkPath; + mResSource.Source = SResSource::ePakFile; + Log::Write("Loaded pak file: " + rkPath); } -void CResCache::SetResSource(SResSource& ResSource) +void CResCache::SetResSource(SResSource& rResSource) { - mResSource = ResSource; + mResSource = rResSource; } SResSource CResCache::GetResSource() @@ -94,7 +95,7 @@ TString CResCache::GetSourcePath() return mResSource.Path; } -CResource* CResCache::GetResource(CUniqueID ResID, CFourCC type) +CResource* CResCache::GetResource(CUniqueID ResID, CFourCC Type) { if (!ResID.IsValid()) return nullptr; @@ -107,110 +108,111 @@ CResource* CResCache::GetResource(CUniqueID ResID, CFourCC type) TString Source; // Load from pak - if (mResSource.Source == SResSource::PakFile) + if (mResSource.Source == SResSource::ePakFile) { - pBuffer = mpPak->getResource(ResID.ToLongLong(), type); - Source = ResID.ToString() + "." + type.ToString(); + pBuffer = mpPak->Resource(ResID.ToLongLong(), Type); + Source = ResID.ToString() + "." + Type.ToString(); } // Load from folder else { - Source = mResSource.Path + ResID.ToString() + "." + type.ToString(); - CFileInStream file(Source.ToStdString(), IOUtil::eBigEndian); - if (!file.IsValid()) + Source = mResSource.Path + ResID.ToString() + "." + Type.ToString(); + CFileInStream File(Source.ToStdString(), IOUtil::eBigEndian); + + if (!File.IsValid()) { - Log::Error("Couldn't open resource: " + ResID.ToString() + "." + type.ToString()); + Log::Error("Couldn't open resource: " + ResID.ToString() + "." + Type.ToString()); return nullptr; } pBuffer = new std::vector; - pBuffer->resize(file.Size()); - file.ReadBytes(pBuffer->data(), pBuffer->size()); + pBuffer->resize(File.Size()); + File.ReadBytes(pBuffer->data(), pBuffer->size()); } if (!pBuffer) return nullptr; // Load resource - CMemoryInStream mem(pBuffer->data(), pBuffer->size(), IOUtil::eBigEndian); - mem.SetSourceString(*Source.GetFileName()); - CResource *Res = nullptr; + CMemoryInStream Mem(pBuffer->data(), pBuffer->size(), IOUtil::eBigEndian); + Mem.SetSourceString(*Source.GetFileName()); + CResource *pRes = nullptr; bool SupportedFormat = true; - if (type == "CMDL") Res = CModelLoader::LoadCMDL(mem); - else if (type == "TXTR") Res = CTextureDecoder::LoadTXTR(mem); - else if (type == "ANCS") Res = CAnimSetLoader::LoadANCS(mem); - else if (type == "CHAR") Res = CAnimSetLoader::LoadCHAR(mem); - else if (type == "MREA") Res = CAreaLoader::LoadMREA(mem); - else if (type == "MLVL") Res = CWorldLoader::LoadMLVL(mem); - else if (type == "STRG") Res = CStringLoader::LoadSTRG(mem); - else if (type == "FONT") Res = CFontLoader::LoadFONT(mem); - else if (type == "SCAN") Res = CScanLoader::LoadSCAN(mem); - else if (type == "DCLN") Res = CCollisionLoader::LoadDCLN(mem); - else if (type == "EGMC") Res = CPoiToWorldLoader::LoadEGMC(mem); + if (Type == "CMDL") pRes = CModelLoader::LoadCMDL(Mem); + else if (Type == "TXTR") pRes = CTextureDecoder::LoadTXTR(Mem); + else if (Type == "ANCS") pRes = CAnimSetLoader::LoadANCS(Mem); + else if (Type == "CHAR") pRes = CAnimSetLoader::LoadCHAR(Mem); + else if (Type == "MREA") pRes = CAreaLoader::LoadMREA(Mem); + else if (Type == "MLVL") pRes = CWorldLoader::LoadMLVL(Mem); + else if (Type == "STRG") pRes = CStringLoader::LoadSTRG(Mem); + else if (Type == "FONT") pRes = CFontLoader::LoadFONT(Mem); + else if (Type == "SCAN") pRes = CScanLoader::LoadSCAN(Mem); + else if (Type == "DCLN") pRes = CCollisionLoader::LoadDCLN(Mem); + else if (Type == "EGMC") pRes = CPoiToWorldLoader::LoadEGMC(Mem); else SupportedFormat = false; // Log errors if (!SupportedFormat) - Log::Write("Unsupported format; unable to load " + type.ToString() + " " + ResID.ToString()); + Log::Write("Unsupported format; unable to load " + Type.ToString() + " " + ResID.ToString()); - if (!Res) Res = new CResource(); // Default for invalid resource or unsupported format + if (!pRes) pRes = new CResource(); // Default for invalid resource or unsupported format // Add to cache and cleanup - Res->mID = ResID; - Res->mResSource = Source; - mResourceCache[ResID.ToLongLong()] = Res; + pRes->mID = ResID; + pRes->mResSource = Source; + mResourceCache[ResID.ToLongLong()] = pRes; delete pBuffer; - return Res; + return pRes; } -CResource* CResCache::GetResource(const TString& ResPath) +CResource* CResCache::GetResource(const TString& rkResPath) { // Since this function takes a string argument it always loads directly from a file - no pak - CUniqueID ResID = ResPath.Hash64(); + CUniqueID ResID = rkResPath.Hash64(); - auto got = mResourceCache.find(ResID.ToLongLong()); + auto Got = mResourceCache.find(ResID.ToLongLong()); - if (got != mResourceCache.end()) - return got->second; + if (Got != mResourceCache.end()) + return Got->second; - CFileInStream file(ResPath.ToStdString(), IOUtil::eBigEndian); - if (!file.IsValid()) + CFileInStream File(rkResPath.ToStdString(), IOUtil::eBigEndian); + if (!File.IsValid()) { - Log::Error("Couldn't open resource: " + ResPath); + Log::Error("Couldn't open resource: " + rkResPath); return nullptr; } // Save old ResSource to restore later const SResSource OldSource = mResSource; - mResSource.Source = SResSource::Folder; - mResSource.Path = ResPath.GetFileDirectory(); + mResSource.Source = SResSource::eFolder; + mResSource.Path = rkResPath.GetFileDirectory(); // Load resource - CResource *Res = nullptr; - CFourCC type = ResPath.GetFileExtension().ToUpper(); + CResource *pRes = nullptr; + CFourCC Type = rkResPath.GetFileExtension().ToUpper(); bool SupportedFormat = true; - if (type == "CMDL") Res = CModelLoader::LoadCMDL(file); - else if (type == "TXTR") Res = CTextureDecoder::LoadTXTR(file); - else if (type == "ANCS") Res = CAnimSetLoader::LoadANCS(file); - else if (type == "CHAR") Res = CAnimSetLoader::LoadCHAR(file); - else if (type == "MREA") Res = CAreaLoader::LoadMREA(file); - else if (type == "MLVL") Res = CWorldLoader::LoadMLVL(file); - else if (type == "STRG") Res = CStringLoader::LoadSTRG(file); - else if (type == "FONT") Res = CFontLoader::LoadFONT(file); - else if (type == "SCAN") Res = CScanLoader::LoadSCAN(file); - else if (type == "DCLN") Res = CCollisionLoader::LoadDCLN(file); - else if (type == "EGMC") Res = CPoiToWorldLoader::LoadEGMC(file); + if (Type == "CMDL") pRes = CModelLoader::LoadCMDL(File); + else if (Type == "TXTR") pRes = CTextureDecoder::LoadTXTR(File); + else if (Type == "ANCS") pRes = CAnimSetLoader::LoadANCS(File); + else if (Type == "CHAR") pRes = CAnimSetLoader::LoadCHAR(File); + else if (Type == "MREA") pRes = CAreaLoader::LoadMREA(File); + else if (Type == "MLVL") pRes = CWorldLoader::LoadMLVL(File); + else if (Type == "STRG") pRes = CStringLoader::LoadSTRG(File); + else if (Type == "FONT") pRes = CFontLoader::LoadFONT(File); + else if (Type == "SCAN") pRes = CScanLoader::LoadSCAN(File); + else if (Type == "DCLN") pRes = CCollisionLoader::LoadDCLN(File); + else if (Type == "EGMC") pRes = CPoiToWorldLoader::LoadEGMC(File); else SupportedFormat = false; - if (!Res) Res = new CResource(); // Default for unsupported formats + if (!pRes) pRes = new CResource(); // Default for unsupported formats // Add to cache and cleanup - Res->mID = *ResPath; - Res->mResSource = ResPath; - mResourceCache[ResID.ToLongLong()] = Res; + pRes->mID = *rkResPath; + pRes->mResSource = rkResPath; + mResourceCache[ResID.ToLongLong()] = pRes; mResSource = OldSource; - return Res; + return pRes; } CFourCC CResCache::FindResourceType(CUniqueID ResID, const TStringList& rkPossibleTypes) @@ -220,13 +222,13 @@ CFourCC CResCache::FindResourceType(CUniqueID ResID, const TStringList& rkPossib return CFourCC(rkPossibleTypes.front()); // Determine extension from pak - if (mResSource.Source == SResSource::PakFile) + if (mResSource.Source == SResSource::ePakFile) { for (auto it = rkPossibleTypes.begin(); it != rkPossibleTypes.end(); it++) { - SResInfo ResInfo = mpPak->getResourceInfo(ResID.ToLongLong(), CFourCC(*it)); + SResInfo ResInfo = mpPak->ResourceInfo(ResID.ToLongLong(), CFourCC(*it)); - if (ResInfo.resType != "NULL") + if (ResInfo.Type != "NULL") return CFourCC(*it); } } @@ -251,20 +253,20 @@ CFourCC CResCache::FindResourceType(CUniqueID ResID, const TStringList& rkPossib void CResCache::CacheResource(CResource *pRes) { u64 ID = pRes->ResID().ToLongLong(); - auto got = mResourceCache.find(ID); + auto Got = mResourceCache.find(ID); - if (got != mResourceCache.end()) + if (Got != mResourceCache.end()) mResourceCache[ID] = pRes; } void CResCache::DeleteResource(CUniqueID ResID) { - auto got = mResourceCache.find(ResID.ToLongLong()); + auto Got = mResourceCache.find(ResID.ToLongLong()); - if (got != mResourceCache.end()) + if (Got != mResourceCache.end()) { - delete got->second; - mResourceCache.erase(got, got); + delete Got->second; + mResourceCache.erase(Got, Got); } } diff --git a/src/Core/Resource/CResCache.h b/src/Core/Resource/CResCache.h index 6af0c8e6..d6d4c83c 100644 --- a/src/Core/Resource/CResCache.h +++ b/src/Core/Resource/CResCache.h @@ -11,7 +11,7 @@ struct SResSource { TString Path; enum { - Folder, PakFile + eFolder, ePakFile } Source; }; @@ -25,13 +25,13 @@ public: CResCache(); ~CResCache(); void Clean(); - void SetFolder(TString path); - void SetPak(const TString& path); - void SetResSource(SResSource& ResSource); + void SetFolder(TString Path); + void SetPak(const TString& rkPath); + void SetResSource(SResSource& rResSource); SResSource GetResSource(); TString GetSourcePath(); - CResource* GetResource(CUniqueID ResID, CFourCC type); - CResource* GetResource(const TString& ResPath); + CResource* GetResource(CUniqueID ResID, CFourCC Type); + CResource* GetResource(const TString& rkResPath); CFourCC FindResourceType(CUniqueID ResID, const TStringList& rkPossibleTypes); void CacheResource(CResource *pRes); void DeleteResource(CUniqueID ResID); diff --git a/src/Core/Resource/CResource.cpp b/src/Core/Resource/CResource.cpp index a380029e..3e14b456 100644 --- a/src/Core/Resource/CResource.cpp +++ b/src/Core/Resource/CResource.cpp @@ -1,45 +1,4 @@ #include "CResource.h" -#include "CResCache.h" -#include - -CResource::CResource() -{ - mRefCount = 0; -} - -CResource::~CResource() -{ -} - -TString CResource::Source() -{ - return mResSource.GetFileName(); -} - -TString CResource::FullSource() -{ - return mResSource; -} - -CUniqueID CResource::ResID() -{ - return mID; -} - -void CResource::Lock() -{ - mRefCount++; -} - -void CResource::Release() -{ - mRefCount--; -} - -bool CResource::IsValidResource() -{ - return (Type() != eResource); -} // ************ STATIC ************ EResType CResource::ResTypeForExtension(CFourCC Extension) diff --git a/src/Core/Resource/CResource.h b/src/Core/Resource/CResource.h index 140e4cf4..73c39cba 100644 --- a/src/Core/Resource/CResource.h +++ b/src/Core/Resource/CResource.h @@ -35,14 +35,16 @@ class CResource int mRefCount; public: - CResource(); - virtual ~CResource(); - TString Source(); - TString FullSource(); - CUniqueID ResID(); - void Lock(); - void Release(); - bool IsValidResource(); + CResource() : mRefCount(0) {} + virtual ~CResource() {} + + inline TString Source() const { return mResSource.GetFileName(); } + inline TString FullSource() const { return mResSource; } + inline CUniqueID ResID() const { return mID; } + inline void Lock() { mRefCount++; } + inline void Release() { mRefCount--; } + inline bool IsValidResource() { return (Type() != eResource); } + static EResType ResTypeForExtension(CFourCC Extension); }; diff --git a/src/Core/Resource/CScan.cpp b/src/Core/Resource/CScan.cpp deleted file mode 100644 index 01fe7a22..00000000 --- a/src/Core/Resource/CScan.cpp +++ /dev/null @@ -1,39 +0,0 @@ -#include "CScan.h" - -CScan::CScan() -{ - mpFrame = nullptr; - mpStringTable = nullptr; - mIsSlow = false; - mIsImportant = false; - mCategory = eNone; -} - -CScan::~CScan() -{ -} - -EGame CScan::Version() -{ - return mVersion; -} - -CStringTable* CScan::ScanText() -{ - return mpStringTable; -} - -bool CScan::IsImportant() -{ - return mIsImportant; -} - -bool CScan::IsSlow() -{ - return mIsSlow; -} - -CScan::ELogbookCategory CScan::LogbookCategory() -{ - return mCategory; -} diff --git a/src/Core/Resource/CScan.h b/src/Core/Resource/CScan.h index 9db9b09a..c7097f6d 100644 --- a/src/Core/Resource/CScan.h +++ b/src/Core/Resource/CScan.h @@ -31,13 +31,20 @@ private: ELogbookCategory mCategory; public: - CScan(); - ~CScan(); - EGame Version(); - CStringTable* ScanText(); - bool IsImportant(); - bool IsSlow(); - ELogbookCategory LogbookCategory(); + CScan() + : CResource() + , mpFrame(nullptr) + , mpStringTable(nullptr) + , mIsSlow(false) + , mIsImportant(false) + , mCategory(eNone) + {} + + EGame Version() const { return mVersion; } + CStringTable* ScanText() const { return mpStringTable; } + bool IsImportant() const { return mIsImportant; } + bool IsSlow() const { return mIsSlow; } + ELogbookCategory LogbookCategory() const { return mCategory; } }; #endif // CSCAN_H diff --git a/src/Core/Resource/CStringTable.cpp b/src/Core/Resource/CStringTable.cpp deleted file mode 100644 index e5b70b25..00000000 --- a/src/Core/Resource/CStringTable.cpp +++ /dev/null @@ -1,52 +0,0 @@ -#include "CStringTable.h" - -CStringTable::CStringTable() : CResource() -{ -} - -CStringTable::~CStringTable() -{ -} - -CResource* CStringTable::MakeCopy(CResCache*) -{ - // Not using parameter 1 (CResCache* - pResCache) - return new CStringTable(*this); -} - -// ************ SETTERS ************ -u32 CStringTable::GetStringCount() -{ - return mNumStrings; -} - -u32 CStringTable::GetLangCount() -{ - return mLangTables.size(); -} - -CFourCC CStringTable::GetLangTag(u32 Index) -{ - return mLangTables[Index].Language; -} - -TWideString CStringTable::GetString(CFourCC Lang, u32 StringIndex) -{ - for (u32 iLang = 0; iLang < GetLangCount(); iLang++) - { - if (GetLangTag(iLang) == Lang) - return GetString(iLang, StringIndex); - } - - return std::wstring(); -} - -TWideString CStringTable::GetString(u32 LangIndex, u32 StringIndex) -{ - return mLangTables[LangIndex].Strings[StringIndex]; -} - -TString CStringTable::GetStringName(u32 StringIndex) -{ - return mStringNames[StringIndex]; -} diff --git a/src/Core/Resource/CStringTable.h b/src/Core/Resource/CStringTable.h index 9239599d..314b209a 100644 --- a/src/Core/Resource/CStringTable.h +++ b/src/Core/Resource/CStringTable.h @@ -23,17 +23,24 @@ class CStringTable : public CResource std::vector mLangTables; public: - CStringTable(); - ~CStringTable(); - CResource* MakeCopy(CResCache *pCopyCache); + CStringTable() {} - // Getters - u32 GetStringCount(); - u32 GetLangCount(); - CFourCC GetLangTag(u32 Index); - TWideString GetString(CFourCC Lang, u32 StringIndex); - TWideString GetString(u32 LangIndex, u32 StringIndex); - TString GetStringName(u32 StringIndex); + inline u32 NumStrings() const { return mLangTables.size(); } + inline u32 NumLanguages() const { return mLangTables.size(); } + inline CFourCC LanguageTag(u32 Index) const { return mLangTables[Index].Language; } + inline TWideString String(u32 LangIndex, u32 StringIndex) const { return mLangTables[LangIndex].Strings[StringIndex]; } + inline TString StringName(u32 StringIndex) const { return mStringNames[StringIndex]; } + + TWideString String(CFourCC Lang, u32 StringIndex) const + { + for (u32 iLang = 0; iLang < NumLanguages(); iLang++) + { + if (LanguageTag(iLang) == Lang) + return String(iLang, StringIndex); + } + + return TWideString(); + } }; #endif // CSTRINGTABLE_H diff --git a/src/Core/Resource/CTexture.cpp b/src/Core/Resource/CTexture.cpp index 2df8372f..258ad7d1 100644 --- a/src/Core/Resource/CTexture.cpp +++ b/src/Core/Resource/CTexture.cpp @@ -1,51 +1,32 @@ #include "CTexture.h" -CTexture::CTexture() : CResource() +CTexture::CTexture() + : CResource() + , mTexelFormat(eRGBA8) + , mSourceTexelFormat(eRGBA8) + , mWidth(0) + , mHeight(0) + , mNumMipMaps(0) + , mLinearSize(0) + , mBufferExists(false) + , mpImgDataBuffer(nullptr) + , mImgDataSize(0) + , mGLBufferExists(false) { - mTexelFormat = eRGBA8; - mSourceTexelFormat = eRGBA8; - mWidth = 0; - mHeight = 0; - mNumMipMaps = 0; - mLinearSize = 0; - - mBufferExists = false; - mImgDataBuffer = nullptr; - mImgDataSize = 0; - - mGLBufferExists = false; -} - -CTexture::CTexture(const CTexture& Source) -{ - mTexelFormat = Source.mTexelFormat; - mSourceTexelFormat = Source.mSourceTexelFormat; - mWidth = Source.mWidth; - mHeight = Source.mHeight; - mLinearSize = Source.mLinearSize; - - mBufferExists = Source.mBufferExists; - mImgDataSize = Source.mImgDataSize; - mImgDataBuffer = new u8[mImgDataSize]; - memcpy(mImgDataBuffer, Source.mImgDataBuffer, mImgDataSize); - - mGLBufferExists = false; } CTexture::CTexture(u32 Width, u32 Height) + : mTexelFormat(eRGBA8) + , mSourceTexelFormat(eRGBA8) + , mWidth((u16) Width) + , mHeight((u16) Height) + , mNumMipMaps(1) + , mLinearSize(Width * Height * 4) + , mBufferExists(false) + , mpImgDataBuffer(nullptr) + , mImgDataSize(0) + , mGLBufferExists(false) { - mTexelFormat = eRGBA8; - mSourceTexelFormat = eRGBA8; - mWidth = (u16) Width; - mHeight = (u16) Height; - mNumMipMaps = 1; - mLinearSize = Width * Height * 4; - - mBufferExists = false; - mImgDataBuffer = nullptr; - mImgDataSize = 0; - - mGLBufferExists = false; } CTexture::~CTexture() @@ -61,8 +42,8 @@ bool CTexture::BufferGL() GLenum GLFormat, GLType; bool IsCompressed = false; - switch (mTexelFormat) { - + switch (mTexelFormat) + { case eLuminance: GLFormat = GL_LUMINANCE; GLType = GL_UNSIGNED_BYTE; @@ -97,7 +78,7 @@ bool CTexture::BufferGL() for (u32 iMip = 0; iMip < mNumMipMaps; iMip++) { - GLvoid *pData = (mBufferExists) ? (mImgDataBuffer + MipOffset) : NULL; + GLvoid *pData = (mBufferExists) ? (mpImgDataBuffer + MipOffset) : NULL; if (!IsCompressed) glTexImage2D(GL_TEXTURE_2D, iMip, GLFormat, MipW, MipH, 0, GLFormat, GLType, pData); @@ -147,16 +128,16 @@ void CTexture::Resize(u32 Width, u32 Height) } } -float CTexture::ReadTexelAlpha(const CVector2f& TexCoord) +float CTexture::ReadTexelAlpha(const CVector2f& rkTexCoord) { // todo: support texel formats other than DXT1 // DXT1 is definitely the most complicated one anyway; try reusing CTextureDecoder functions for other formats - u32 TexelX = (u32) ((mWidth - 1) * TexCoord.x); - u32 TexelY = (u32) ((mHeight - 1) * (1.f - fmodf(TexCoord.y, 1.f))); + u32 TexelX = (u32) ((mWidth - 1) * rkTexCoord.X); + u32 TexelY = (u32) ((mHeight - 1) * (1.f - fmodf(rkTexCoord.Y, 1.f))); if (mTexelFormat == eDXT1 && mBufferExists) { - CMemoryInStream Buffer(mImgDataBuffer, mImgDataSize, IOUtil::kSystemEndianness); + CMemoryInStream Buffer(mpImgDataBuffer, mImgDataSize, IOUtil::kSystemEndianness); // 8 bytes per 4x4 16-pixel block, left-to-right top-to-bottom u32 BlockIdxX = TexelX / 4; @@ -190,83 +171,84 @@ float CTexture::ReadTexelAlpha(const CVector2f& TexCoord) return 1.f; } -bool CTexture::WriteDDS(IOutputStream& out) +bool CTexture::WriteDDS(IOutputStream& rOut) { - if (!out.IsValid()) return false; + if (!rOut.IsValid()) return false; CopyGLBuffer(); - out.WriteString("DDS ", 4); // "DDS " fourCC - out.WriteLong(0x7C); // dwSize - out.WriteLong(0x21007); // dwFlags - out.WriteLong(mHeight); // dwHeight - out.WriteLong(mWidth); // dwWidth - out.WriteLong(mLinearSize); // dwPitchOrLinearSize - out.WriteLong(0); // dwDepth - out.WriteLong(mNumMipMaps - 1); // dwMipMapCount + rOut.WriteString("DDS ", 4); // "DDS " fourCC + rOut.WriteLong(0x7C); // dwSize + rOut.WriteLong(0x21007); // dwFlags + rOut.WriteLong(mHeight); // dwHeight + rOut.WriteLong(mWidth); // dwWidth + rOut.WriteLong(mLinearSize); // dwPitchOrLinearSize + rOut.WriteLong(0); // dwDepth + rOut.WriteLong(mNumMipMaps - 1); // dwMipMapCount - for (u32 i = 0; i < 11; i++) - out.WriteLong(0); // dwReserved1[11] + for (u32 iRes = 0; iRes < 11; iRes++) + rOut.WriteLong(0); // dwReserved1[11] // DDS_PIXELFORMAT - out.WriteLong(32); // DDS_PIXELFORMAT.dwSize + rOut.WriteLong(32); // DDS_PIXELFORMAT.dwSize + u32 PFFlags = 0, PFBpp = 0, PFRBitMask = 0, PFGBitMask = 0, PFBBitMask = 0, PFABitMask = 0; - u32 pfFlags = 0, pfBpp = 0, pfRBitMask = 0, pfGBitMask = 0, pfBBitMask = 0, pfABitMask = 0; - switch (mTexelFormat) { + switch (mTexelFormat) + { case eLuminance: - pfFlags = 0x20000; - pfBpp = 0x8; - pfRBitMask = 0xFF; + PFFlags = 0x20000; + PFBpp = 0x8; + PFRBitMask = 0xFF; break; case eLuminanceAlpha: - pfFlags = 0x20001; - pfBpp = 0x10; - pfRBitMask = 0x00FF; - pfABitMask = 0xFF00; + PFFlags = 0x20001; + PFBpp = 0x10; + PFRBitMask = 0x00FF; + PFABitMask = 0xFF00; break; case eRGBA4: - pfFlags = 0x41; - pfBpp = 0x10; - pfRBitMask = 0x0F00; - pfGBitMask = 0x00F0; - pfBBitMask = 0x000F; - pfABitMask = 0xF000; + PFFlags = 0x41; + PFBpp = 0x10; + PFRBitMask = 0x0F00; + PFGBitMask = 0x00F0; + PFBBitMask = 0x000F; + PFABitMask = 0xF000; break; case eRGB565: - pfFlags = 0x40; - pfBpp = 0x10; - pfRBitMask = 0xF800; - pfGBitMask = 0x7E0; - pfBBitMask = 0x1F; + PFFlags = 0x40; + PFBpp = 0x10; + PFRBitMask = 0xF800; + PFGBitMask = 0x7E0; + PFBBitMask = 0x1F; break; case eRGBA8: - pfFlags = 0x41; - pfBpp = 0x20; - pfRBitMask = 0x00FF0000; - pfGBitMask = 0x0000FF00; - pfBBitMask = 0x000000FF; - pfABitMask = 0xFF000000; + PFFlags = 0x41; + PFBpp = 0x20; + PFRBitMask = 0x00FF0000; + PFGBitMask = 0x0000FF00; + PFBBitMask = 0x000000FF; + PFABitMask = 0xFF000000; break; case eDXT1: - pfFlags = 0x4; + PFFlags = 0x4; break; } - out.WriteLong(pfFlags); // DDS_PIXELFORMAT.dwFlags - (mTexelFormat == eDXT1) ? out.WriteString("DXT1", 4) : out.WriteLong(0); // DDS_PIXELFORMAT.dwFourCC - out.WriteLong(pfBpp); // DDS_PIXELFORMAT.dwRGBBitCount - out.WriteLong(pfRBitMask); // DDS_PIXELFORMAT.dwRBitMask - out.WriteLong(pfGBitMask); // DDS_PIXELFORMAT.dwGBitMask - out.WriteLong(pfBBitMask); // DDS_PIXELFORMAT.dwBBitMask - out.WriteLong(pfABitMask); // DDS_PIXELFORMAT.dwABitMask + rOut.WriteLong(PFFlags); // DDS_PIXELFORMAT.dwFlags + (mTexelFormat == eDXT1) ? rOut.WriteString("DXT1", 4) : rOut.WriteLong(0); // DDS_PIXELFORMAT.dwFourCC + rOut.WriteLong(PFBpp); // DDS_PIXELFORMAT.dwRGBBitCount + rOut.WriteLong(PFRBitMask); // DDS_PIXELFORMAT.dwRBitMask + rOut.WriteLong(PFGBitMask); // DDS_PIXELFORMAT.dwGBitMask + rOut.WriteLong(PFBBitMask); // DDS_PIXELFORMAT.dwBBitMask + rOut.WriteLong(PFABitMask); // DDS_PIXELFORMAT.dwABitMask - out.WriteLong(0x401000); // dwCaps - out.WriteLong(0); // dwCaps2 - out.WriteLong(0); // dwCaps3 - out.WriteLong(0); // dwCaps4 - out.WriteLong(0); // dwReserved2 + rOut.WriteLong(0x401000); // dwCaps + rOut.WriteLong(0); // dwCaps2 + rOut.WriteLong(0); // dwCaps3 + rOut.WriteLong(0); // dwCaps4 + rOut.WriteLong(0); // dwReserved2 - out.WriteBytes(mImgDataBuffer, mImgDataSize); // Image data + rOut.WriteBytes(mpImgDataBuffer, mImgDataSize); // Image data return true; } @@ -325,15 +307,15 @@ void CTexture::CopyGLBuffer() // Clear existing buffer if (mBufferExists) { - delete[] mImgDataBuffer; + delete[] mpImgDataBuffer; mBufferExists = false; - mImgDataBuffer = nullptr; + mpImgDataBuffer = nullptr; mImgDataSize = 0; } // Calculate buffer size mImgDataSize = CalcTotalSize(); - mImgDataBuffer = new u8[mImgDataSize]; + mpImgDataBuffer = new u8[mImgDataSize]; mBufferExists = true; // Get texture @@ -344,7 +326,7 @@ void CTexture::CopyGLBuffer() for (u32 iMip = 0; iMip < mNumMipMaps; iMip++) { - void *pData = mImgDataBuffer + MipOffset; + void *pData = mpImgDataBuffer + MipOffset; glGetTexImage(GL_TEXTURE_2D, iMip, GL_RGBA, GL_UNSIGNED_BYTE, pData); @@ -361,9 +343,9 @@ void CTexture::DeleteBuffers() { if (mBufferExists) { - delete[] mImgDataBuffer; + delete[] mpImgDataBuffer; mBufferExists = false; - mImgDataBuffer = nullptr; + mpImgDataBuffer = nullptr; mImgDataSize = 0; } diff --git a/src/Core/Resource/CTexture.h b/src/Core/Resource/CTexture.h index e4dfbdc4..4a411631 100644 --- a/src/Core/Resource/CTexture.h +++ b/src/Core/Resource/CTexture.h @@ -21,32 +21,31 @@ class CTexture : public CResource u32 mNumMipMaps; // The number of mipmaps this texture has u32 mLinearSize; // The size of the top level mipmap, in bytes - bool mBufferExists; // Boolean that indicates whether image data buffer has valid data - u8 *mImgDataBuffer; // Pointer to image data buffer - u32 mImgDataSize; // Size of image data buffer + bool mBufferExists; // Indicates whether image data buffer has valid data + u8 *mpImgDataBuffer; // Pointer to image data buffer + u32 mImgDataSize; // Size of image data buffer - bool mGLBufferExists; // Boolean that indicates whether GL buffer has valid data + bool mGLBufferExists; // Indicates whether GL buffer has valid data GLuint mTextureID; // ID for texture GL buffer public: CTexture(); - CTexture(const CTexture& Source); CTexture(u32 Width, u32 Height); ~CTexture(); bool BufferGL(); void Bind(u32 GLTextureUnit); void Resize(u32 Width, u32 Height); - float ReadTexelAlpha(const CVector2f& TexCoord); - bool WriteDDS(IOutputStream& out); + float ReadTexelAlpha(const CVector2f& rkTexCoord); + bool WriteDDS(IOutputStream& rOut); // Getters - ETexelFormat TexelFormat(); - ETexelFormat SourceTexelFormat(); - u32 Width(); - u32 Height(); - u32 NumMipMaps(); - GLuint TextureID(); + ETexelFormat TexelFormat() const { return mTexelFormat; } + ETexelFormat SourceTexelFormat() const { return mSourceTexelFormat; } + u32 Width() const { return (u32) mWidth; } + u32 Height() const { return (u32) mHeight; } + u32 NumMipMaps() const { return mNumMipMaps; } + GLuint TextureID() const { return mTextureID; } // Static static u32 FormatBPP(ETexelFormat Format); @@ -59,28 +58,4 @@ private: void DeleteBuffers(); }; -inline ETexelFormat CTexture::TexelFormat() { - return mTexelFormat; -} - -inline ETexelFormat CTexture::SourceTexelFormat() { - return mSourceTexelFormat; -} - -inline u32 CTexture::Width() { - return (u32) mWidth; -} - -inline u32 CTexture::Height() { - return (u32) mHeight; -} - -inline u32 CTexture::NumMipMaps() { - return mNumMipMaps; -} - -inline GLuint CTexture::TextureID() { - return mTextureID; -} - #endif // CTEXTURE_H diff --git a/src/Core/Resource/CWorld.cpp b/src/Core/Resource/CWorld.cpp index 91fd5b1c..b68eaf5f 100644 --- a/src/Core/Resource/CWorld.cpp +++ b/src/Core/Resource/CWorld.cpp @@ -2,14 +2,15 @@ #include "CResCache.h" #include "Core/Resource/Script/CScriptLayer.h" -CWorld::CWorld() : CResource() +CWorld::CWorld() + : CResource() + , mWorldVersion(eUnknownVersion) + , mpWorldName(nullptr) + , mpDarkWorldName(nullptr) + , mpSaveWorld(nullptr) + , mpDefaultSkybox(nullptr) + , mpMapWorld(nullptr) { - mWorldVersion = eUnknownVersion; - mpWorldName = nullptr; - mpDarkWorldName = nullptr; - mpSaveWorld = nullptr; - mpDefaultSkybox = nullptr; - mpMapWorld = nullptr; } CWorld::~CWorld() @@ -23,76 +24,13 @@ void CWorld::SetAreaLayerInfo(CGameArea *pArea) // the start window and the start window already knows the area index. SArea& AreaInfo = mAreas[pArea->WorldIndex()]; - for (u32 iLyr = 0; iLyr < pArea->GetScriptLayerCount(); iLyr++) + for (u32 iLyr = 0; iLyr < pArea->NumScriptLayers(); iLyr++) { if (AreaInfo.Layers.size() <= iLyr) break; - CScriptLayer *pLayer = pArea->GetScriptLayer(iLyr); - SArea::SLayer& LayerInfo = AreaInfo.Layers[iLyr]; + CScriptLayer *pLayer = pArea->ScriptLayer(iLyr); + SArea::SLayer& rLayerInfo = AreaInfo.Layers[iLyr]; - pLayer->SetName(LayerInfo.LayerName); - pLayer->SetActive(LayerInfo.EnabledByDefault); + pLayer->SetName(rLayerInfo.LayerName); + pLayer->SetActive(rLayerInfo.EnabledByDefault); } } - -// ************ GETTERS ************ -// World -EGame CWorld::Version() -{ - return mWorldVersion; -} - -CStringTable* CWorld::GetWorldName() -{ - return mpWorldName; -} - -CStringTable* CWorld::GetDarkWorldName() -{ - return mpDarkWorldName; -} - -CResource* CWorld::GetSaveWorld() -{ - return mpSaveWorld; -} - -CModel* CWorld::GetDefaultSkybox() -{ - return mpDefaultSkybox; -} - -CResource* CWorld::GetMapWorld() -{ - return mpMapWorld; -} - -// Area -u32 CWorld::GetNumAreas() -{ - return mAreas.size(); -} - -u64 CWorld::GetAreaResourceID(u32 AreaIndex) -{ - return mAreas[AreaIndex].FileID; -} - -u32 CWorld::GetAreaAttachedCount(u32 AreaIndex) -{ - return mAreas[AreaIndex].AttachedAreaIDs.size(); -} - -u32 CWorld::GetAreaAttachedID(u32 AreaIndex, u32 AttachedIndex) -{ - return (u32) mAreas[AreaIndex].AttachedAreaIDs[AttachedIndex]; -} - -TString CWorld::GetAreaInternalName(u32 AreaIndex) -{ - return mAreas[AreaIndex].InternalName; -} - -CStringTable* CWorld::GetAreaName(u32 AreaIndex) -{ - return mAreas[AreaIndex].pAreaName; -} diff --git a/src/Core/Resource/CWorld.h b/src/Core/Resource/CWorld.h index 0c703700..dc294faf 100644 --- a/src/Core/Resource/CWorld.h +++ b/src/Core/Resource/CWorld.h @@ -86,20 +86,20 @@ public: void SetAreaLayerInfo(CGameArea *pArea); - // Setters - EGame Version(); - CStringTable* GetWorldName(); - CStringTable* GetDarkWorldName(); - CResource* GetSaveWorld(); - CModel* GetDefaultSkybox(); - CResource* GetMapWorld(); + // Accessors + inline EGame Version() const { return mWorldVersion; } + inline CStringTable* WorldName() const { return mpWorldName; } + inline CStringTable* DarkWorldName() const { return mpDarkWorldName; } + inline CResource* SaveWorld() const { return mpSaveWorld; } + inline CModel* DefaultSkybox() const { return mpDefaultSkybox; } + inline CResource* MapWorld() const { return mpMapWorld; } - u32 GetNumAreas(); - u64 GetAreaResourceID(u32 AreaIndex); - u32 GetAreaAttachedCount(u32 AreaIndex); - u32 GetAreaAttachedID(u32 AreaIndex, u32 AttachedIndex); - TString GetAreaInternalName(u32 AreaIndex); - CStringTable* GetAreaName(u32 AreaIndex); + inline u32 NumAreas() const { return mAreas.size(); } + inline u64 AreaResourceID(u32 AreaIndex) const { return mAreas[AreaIndex].FileID; } + inline u32 AreaAttachedCount(u32 AreaIndex) const { return mAreas[AreaIndex].AttachedAreaIDs.size(); } + inline u32 AreaAttachedID(u32 AreaIndex, u32 AttachedIndex) const { return mAreas[AreaIndex].AttachedAreaIDs[AttachedIndex]; } + inline TString AreaInternalName(u32 AreaIndex) const { return mAreas[AreaIndex].InternalName; } + inline CStringTable* AreaName(u32 AreaIndex) const { return mAreas[AreaIndex].pAreaName; } }; #endif // CWORLD_H diff --git a/src/Core/Resource/Cooker/CAreaCooker.cpp b/src/Core/Resource/Cooker/CAreaCooker.cpp index 4c9893f2..51d05ac1 100644 --- a/src/Core/Resource/Cooker/CAreaCooker.cpp +++ b/src/Core/Resource/Cooker/CAreaCooker.cpp @@ -32,8 +32,8 @@ void CAreaCooker::DetermineSectionNumbersPrime() break; } - for (u32 iMesh = 0; iMesh < mpArea->mTerrainModels.size(); iMesh++) - GeometrySections += mpArea->mTerrainModels[iMesh]->GetSurfaceCount(); + for (u32 iMesh = 0; iMesh < mpArea->mWorldModels.size(); iMesh++) + GeometrySections += mpArea->mWorldModels[iMesh]->GetSurfaceCount(); // Set section numbers u32 SecNum = GeometrySections; @@ -349,9 +349,9 @@ void CAreaCooker::WriteCookedArea(CGameArea *pArea, IOutputStream& rOut) Cooker.WriteAreaData(rOut); } -u32 CAreaCooker::GetMREAVersion(EGame version) +u32 CAreaCooker::GetMREAVersion(EGame Version) { - switch (version) + switch (Version) { case ePrimeDemo: return 0xC; case ePrime: return 0xF; diff --git a/src/Core/Resource/Cooker/CAreaCooker.h b/src/Core/Resource/Cooker/CAreaCooker.h index 3c773735..b839d84b 100644 --- a/src/Core/Resource/Cooker/CAreaCooker.h +++ b/src/Core/Resource/Cooker/CAreaCooker.h @@ -64,7 +64,7 @@ class CAreaCooker public: static void WriteCookedArea(CGameArea *pArea, IOutputStream& rOut); - static u32 GetMREAVersion(EGame version); + static u32 GetMREAVersion(EGame Version); }; #endif // CAREACOOKER_H diff --git a/src/Core/Resource/Cooker/CMaterialCooker.cpp b/src/Core/Resource/Cooker/CMaterialCooker.cpp index 35693d68..22be2372 100644 --- a/src/Core/Resource/Cooker/CMaterialCooker.cpp +++ b/src/Core/Resource/Cooker/CMaterialCooker.cpp @@ -2,11 +2,11 @@ #include CMaterialCooker::CMaterialCooker() + : mpMat(nullptr) { - mpMat = nullptr; } -void CMaterialCooker::WriteMatSetPrime(IOutputStream& Out) +void CMaterialCooker::WriteMatSetPrime(IOutputStream& rOut) { // Gather texture list from the materials before starting mTextureIDs.clear(); @@ -30,47 +30,46 @@ void CMaterialCooker::WriteMatSetPrime(IOutputStream& Out) mTextureIDs.erase(std::unique(mTextureIDs.begin(), mTextureIDs.end()), mTextureIDs.end()); // Write texture IDs - Out.WriteLong(mTextureIDs.size()); + rOut.WriteLong(mTextureIDs.size()); for (u32 iTex = 0; iTex < mTextureIDs.size(); iTex++) - Out.WriteLong(mTextureIDs[iTex]); + rOut.WriteLong(mTextureIDs[iTex]); // Write material offset filler - Out.WriteLong(NumMats); - u32 MatOffsetsStart = Out.Tell(); + rOut.WriteLong(NumMats); + u32 MatOffsetsStart = rOut.Tell(); for (u32 iMat = 0; iMat < NumMats; iMat++) - Out.WriteLong(0); + rOut.WriteLong(0); // Write materials - u32 MatsStart = Out.Tell(); + u32 MatsStart = rOut.Tell(); std::vector MatEndOffsets(NumMats); for (u32 iMat = 0; iMat < NumMats; iMat++) { mpMat = mpSet->mMaterials[iMat]; - WriteMaterialPrime(Out); - MatEndOffsets[iMat] = Out.Tell() - MatsStart; + WriteMaterialPrime(rOut); + MatEndOffsets[iMat] = rOut.Tell() - MatsStart; } // Write material offsets - u32 MatsEnd = Out.Tell(); - Out.Seek(MatOffsetsStart, SEEK_SET); + u32 MatsEnd = rOut.Tell(); + rOut.Seek(MatOffsetsStart, SEEK_SET); for (u32 iMat = 0; iMat < NumMats; iMat++) - Out.WriteLong(MatEndOffsets[iMat]); + rOut.WriteLong(MatEndOffsets[iMat]); // Done! - Out.Seek(MatsEnd, SEEK_SET); + rOut.Seek(MatsEnd, SEEK_SET); } -void CMaterialCooker::WriteMatSetCorruption(IOutputStream&) +void CMaterialCooker::WriteMatSetCorruption(IOutputStream& /*rOut*/) { - // Not using parameter 1 (IOutputStream& - Out) // todo } -void CMaterialCooker::WriteMaterialPrime(IOutputStream& Out) +void CMaterialCooker::WriteMaterialPrime(IOutputStream& rOut) { // Gather data from the passes before we start writing u32 TexFlags = 0; @@ -143,12 +142,12 @@ void CMaterialCooker::WriteMaterialPrime(IOutputStream& Out) Flags |= (HasKonst ? 0x8 : 0x0) | (mpMat->Options() & ~0x8) | (TexFlags << 16); - Out.WriteLong(Flags); + rOut.WriteLong(Flags); // Texture indices - Out.WriteLong(TexIndices.size()); + rOut.WriteLong(TexIndices.size()); for (u32 iTex = 0; iTex < TexIndices.size(); iTex++) - Out.WriteLong(TexIndices[iTex]); + rOut.WriteLong(TexIndices[iTex]); // Vertex description FVertexDescription Desc = mpMat->VtxDesc(); @@ -156,24 +155,24 @@ void CMaterialCooker::WriteMaterialPrime(IOutputStream& Out) if (mVersion < eEchoes) Desc &= 0x00FFFFFF; - Out.WriteLong(Desc); + rOut.WriteLong(Desc); // Echoes unknowns if (mVersion == eEchoes) { - Out.WriteLong(mpMat->EchoesUnknownA()); - Out.WriteLong(mpMat->EchoesUnknownB()); + rOut.WriteLong(mpMat->EchoesUnknownA()); + rOut.WriteLong(mpMat->EchoesUnknownB()); } // Group index - Out.WriteLong(GroupIndex); + rOut.WriteLong(GroupIndex); // Konst if (HasKonst) { - Out.WriteLong(NumKonst); + rOut.WriteLong(NumKonst); for (u32 iKonst = 0; iKonst < NumKonst; iKonst++) - Out.WriteLong( mpMat->Konst(iKonst).ToLongRGBA() ); + rOut.WriteLong( mpMat->Konst(iKonst).ToLongRGBA() ); } // Blend Mode @@ -182,16 +181,16 @@ void CMaterialCooker::WriteMaterialPrime(IOutputStream& Out) u16 BlendDstFac = (u16) mpMat->BlendDstFac(); if (BlendSrcFac >= 0x300) BlendSrcFac -= 0x2FE; if (BlendDstFac >= 0x300) BlendDstFac -= 0x2FE; - Out.WriteShort(BlendDstFac); - Out.WriteShort(BlendSrcFac); + rOut.WriteShort(BlendDstFac); + rOut.WriteShort(BlendSrcFac); // Color Channels - Out.WriteLong(1); - Out.WriteLong(0x3000 | (mpMat->IsLightingEnabled() ? 1 : 0)); + rOut.WriteLong(1); + rOut.WriteLong(0x3000 | (mpMat->IsLightingEnabled() ? 1 : 0)); // TEV u32 NumPasses = mpMat->PassCount(); - Out.WriteLong(NumPasses); + rOut.WriteLong(NumPasses); for (u32 iPass = 0; iPass < NumPasses; iPass++) { @@ -209,14 +208,14 @@ void CMaterialCooker::WriteMaterialPrime(IOutputStream& Out) u32 ColorOpFlags = 0x100 | (pPass->ColorOutput() << 9); u32 AlphaOpFlags = 0x100 | (pPass->AlphaOutput() << 9); - Out.WriteLong(ColorInputFlags); - Out.WriteLong(AlphaInputFlags); - Out.WriteLong(ColorOpFlags); - Out.WriteLong(AlphaOpFlags); - Out.WriteByte(0); // Padding - Out.WriteByte(pPass->KAlphaSel()); - Out.WriteByte(pPass->KColorSel()); - Out.WriteByte(pPass->RasSel()); + rOut.WriteLong(ColorInputFlags); + rOut.WriteLong(AlphaInputFlags); + rOut.WriteLong(ColorOpFlags); + rOut.WriteLong(AlphaOpFlags); + rOut.WriteByte(0); // Padding + rOut.WriteByte(pPass->KAlphaSel()); + rOut.WriteByte(pPass->KColorSel()); + rOut.WriteByte(pPass->RasSel()); } // TEV Tex/UV input selection @@ -224,22 +223,22 @@ void CMaterialCooker::WriteMaterialPrime(IOutputStream& Out) for (u32 iPass = 0; iPass < NumPasses; iPass++) { - Out.WriteShort(0); // Padding + rOut.WriteShort(0); // Padding if (mpMat->Pass(iPass)->Texture()) { - Out.WriteByte((u8) CurTexIdx); - Out.WriteByte((u8) CurTexIdx); + rOut.WriteByte((u8) CurTexIdx); + rOut.WriteByte((u8) CurTexIdx); CurTexIdx++; } else - Out.WriteShort((u16) 0xFFFF); + rOut.WriteShort((u16) 0xFFFF); } // TexGen u32 NumTexCoords = CurTexIdx; // TexIdx is currently equal to the tex coord count - Out.WriteLong(NumTexCoords); + rOut.WriteLong(NumTexCoords); u32 CurTexMtx = 0; for (u32 iPass = 0; iPass < NumPasses; iPass++) @@ -280,15 +279,15 @@ void CMaterialCooker::WriteMaterialPrime(IOutputStream& Out) } u32 TexGenFlags = (CoordSource << 4) | (TexMtxIdx << 9) | (Normalize << 14) | (PostMtxIdx << 15); - Out.WriteLong(TexGenFlags); + rOut.WriteLong(TexGenFlags); } // Animations - u32 AnimSizeOffset = Out.Tell(); + u32 AnimSizeOffset = rOut.Tell(); u32 NumAnims = CurTexMtx; // CurTexMtx is currently equal to the anim count - Out.WriteLong(0); // Anim size filler - u32 AnimsStart = Out.Tell(); - Out.WriteLong(NumAnims); + rOut.WriteLong(0); // Anim size filler + u32 AnimsStart = rOut.Tell(); + rOut.WriteLong(NumAnims); for (u32 iPass = 0; iPass < NumPasses; iPass++) { @@ -296,38 +295,37 @@ void CMaterialCooker::WriteMaterialPrime(IOutputStream& Out) u32 AnimMode = pPass->AnimMode(); if (AnimMode == eNoUVAnim) continue; - Out.WriteLong(AnimMode); + rOut.WriteLong(AnimMode); if ((AnimMode > 1) && (AnimMode != 6)) { - Out.WriteFloat(pPass->AnimParam(0)); - Out.WriteFloat(pPass->AnimParam(1)); + rOut.WriteFloat(pPass->AnimParam(0)); + rOut.WriteFloat(pPass->AnimParam(1)); if ((AnimMode == 2) || (AnimMode == 4) || (AnimMode == 5)) { - Out.WriteFloat(pPass->AnimParam(2)); - Out.WriteFloat(pPass->AnimParam(3)); + rOut.WriteFloat(pPass->AnimParam(2)); + rOut.WriteFloat(pPass->AnimParam(3)); } } } - u32 AnimsEnd = Out.Tell(); + u32 AnimsEnd = rOut.Tell(); u32 AnimsSize = AnimsEnd - AnimsStart; - Out.Seek(AnimSizeOffset, SEEK_SET); - Out.WriteLong(AnimsSize); - Out.Seek(AnimsEnd, SEEK_SET); + rOut.Seek(AnimSizeOffset, SEEK_SET); + rOut.WriteLong(AnimsSize); + rOut.Seek(AnimsEnd, SEEK_SET); // Done! } -void CMaterialCooker::WriteMaterialCorruption(IOutputStream&) +void CMaterialCooker::WriteMaterialCorruption(IOutputStream& /*rOut*/) { - // Not using parameter 1 (IOutputStream& - Out) // todo } // ************ STATIC ************ -void CMaterialCooker::WriteCookedMatSet(CMaterialSet *pSet, EGame Version, IOutputStream &Out) +void CMaterialCooker::WriteCookedMatSet(CMaterialSet *pSet, EGame Version, IOutputStream& rOut) { CMaterialCooker Cooker; Cooker.mpSet = pSet; @@ -339,12 +337,12 @@ void CMaterialCooker::WriteCookedMatSet(CMaterialSet *pSet, EGame Version, IOutp case ePrime: case eEchoesDemo: case eEchoes: - Cooker.WriteMatSetPrime(Out); + Cooker.WriteMatSetPrime(rOut); break; } } -void CMaterialCooker::WriteCookedMaterial(CMaterial *pMat, EGame Version, IOutputStream &Out) +void CMaterialCooker::WriteCookedMaterial(CMaterial *pMat, EGame Version, IOutputStream& rOut) { CMaterialCooker Cooker; Cooker.mpMat = pMat; @@ -356,7 +354,7 @@ void CMaterialCooker::WriteCookedMaterial(CMaterial *pMat, EGame Version, IOutpu case ePrime: case eEchoesDemo: case eEchoes: - Cooker.WriteMaterialPrime(Out); + Cooker.WriteMaterialPrime(rOut); break; // TODO: Corruption/Uncooked } diff --git a/src/Core/Resource/Cooker/CMaterialCooker.h b/src/Core/Resource/Cooker/CMaterialCooker.h index fecd1c45..e9bd05a0 100644 --- a/src/Core/Resource/Cooker/CMaterialCooker.h +++ b/src/Core/Resource/Cooker/CMaterialCooker.h @@ -14,14 +14,14 @@ class CMaterialCooker std::vector mMaterialHashes; CMaterialCooker(); - void WriteMatSetPrime(IOutputStream& Out); - void WriteMatSetCorruption(IOutputStream& Out); - void WriteMaterialPrime(IOutputStream& Out); - void WriteMaterialCorruption(IOutputStream& Out); + void WriteMatSetPrime(IOutputStream& rOut); + void WriteMatSetCorruption(IOutputStream& rOut); + void WriteMaterialPrime(IOutputStream& rOut); + void WriteMaterialCorruption(IOutputStream& rOut); public: - static void WriteCookedMatSet(CMaterialSet *pSet, EGame Version, IOutputStream& Out); - static void WriteCookedMaterial(CMaterial *pMat, EGame Version, IOutputStream& Out); + static void WriteCookedMatSet(CMaterialSet *pSet, EGame Version, IOutputStream& rOut); + static void WriteCookedMaterial(CMaterial *pMat, EGame Version, IOutputStream& rOut); }; #endif // CMATERIALCOOKER_H diff --git a/src/Core/Resource/Cooker/CModelCooker.cpp b/src/Core/Resource/Cooker/CModelCooker.cpp index b858067a..0ca23662 100644 --- a/src/Core/Resource/Cooker/CModelCooker.cpp +++ b/src/Core/Resource/Cooker/CModelCooker.cpp @@ -9,14 +9,6 @@ CModelCooker::CModelCooker() { } -bool SortVertsByArrayPos(const CVertex& A, const CVertex& B) { - return (A.ArrayPosition < B.ArrayPosition); -} - -bool CheckDuplicateVertsByArrayPos(const CVertex& A, const CVertex& B) { - return (A.ArrayPosition == B.ArrayPosition); -} - void CModelCooker::GenerateSurfaceData() { // Need to gather metadata from the model before we can start @@ -60,65 +52,65 @@ void CModelCooker::GenerateSurfaceData() mNumVertices = mVertices.size(); } -void CModelCooker::WriteEditorModel(IOutputStream& /*Out*/) +void CModelCooker::WriteEditorModel(IOutputStream& /*rOut*/) { } -void CModelCooker::WriteModelPrime(IOutputStream& Out) +void CModelCooker::WriteModelPrime(IOutputStream& rOut) { GenerateSurfaceData(); // Header - Out.WriteLong(0xDEADBABE); - Out.WriteLong(GetCMDLVersion(mVersion)); - Out.WriteLong(5); - mpModel->mAABox.Write(Out); + rOut.WriteLong(0xDEADBABE); + rOut.WriteLong(GetCMDLVersion(mVersion)); + rOut.WriteLong(5); + mpModel->mAABox.Write(rOut); u32 NumSections = mNumMatSets + mNumSurfaces + 6; - Out.WriteLong(NumSections); - Out.WriteLong(mNumMatSets); + rOut.WriteLong(NumSections); + rOut.WriteLong(mNumMatSets); - u32 SectionSizesOffset = Out.Tell(); + u32 SectionSizesOffset = rOut.Tell(); for (u32 iSec = 0; iSec < NumSections; iSec++) - Out.WriteLong(0); + rOut.WriteLong(0); - Out.WriteToBoundary(32, 0); + rOut.WriteToBoundary(32, 0); std::vector SectionSizes; SectionSizes.reserve(NumSections); CSectionMgrOut SectionMgr; SectionMgr.SetSectionCount(NumSections); - SectionMgr.Init(Out); + SectionMgr.Init(rOut); // Materials for (u32 iSet = 0; iSet < mNumMatSets; iSet++) { - CMaterialCooker::WriteCookedMatSet(mpModel->mMaterialSets[iSet], mVersion, Out); - Out.WriteToBoundary(32, 0); - SectionMgr.AddSize(Out); + CMaterialCooker::WriteCookedMatSet(mpModel->mMaterialSets[iSet], mVersion, rOut); + rOut.WriteToBoundary(32, 0); + SectionMgr.AddSize(rOut); } // Vertices for (u32 iPos = 0; iPos < mNumVertices; iPos++) - mVertices[iPos].Position.Write(Out); + mVertices[iPos].Position.Write(rOut); - Out.WriteToBoundary(32, 0); - SectionMgr.AddSize(Out); + rOut.WriteToBoundary(32, 0); + SectionMgr.AddSize(rOut); // Normals for (u32 iNrm = 0; iNrm < mNumVertices; iNrm++) - mVertices[iNrm].Normal.Write(Out); + mVertices[iNrm].Normal.Write(rOut); - Out.WriteToBoundary(32, 0); - SectionMgr.AddSize(Out); + rOut.WriteToBoundary(32, 0); + SectionMgr.AddSize(rOut); // Colors for (u32 iColor = 0; iColor < mNumVertices; iColor++) - mVertices[iColor].Color[0].Write(Out); + mVertices[iColor].Color[0].Write(rOut); - Out.WriteToBoundary(32, 0); - SectionMgr.AddSize(Out); + rOut.WriteToBoundary(32, 0); + SectionMgr.AddSize(rOut); // Float UV coordinates for (u32 iTexSlot = 0; iTexSlot < 8; iTexSlot++) @@ -127,50 +119,50 @@ void CModelCooker::WriteModelPrime(IOutputStream& Out) if (HasTexSlot) { for (u32 iTex = 0; iTex < mNumVertices; iTex++) - mVertices[iTex].Tex[iTexSlot].Write(Out); + mVertices[iTex].Tex[iTexSlot].Write(rOut); } } - Out.WriteToBoundary(32, 0); - SectionMgr.AddSize(Out); - SectionMgr.AddSize(Out); // Skipping short UV coordinates + rOut.WriteToBoundary(32, 0); + SectionMgr.AddSize(rOut); + SectionMgr.AddSize(rOut); // Skipping short UV coordinates // Surface offsets - Out.WriteLong(mNumSurfaces); - u32 SurfaceOffsetsStart = Out.Tell(); + rOut.WriteLong(mNumSurfaces); + u32 SurfaceOffsetsStart = rOut.Tell(); for (u32 iSurf = 0; iSurf < mNumSurfaces; iSurf++) - Out.WriteLong(0); + rOut.WriteLong(0); - Out.WriteToBoundary(32, 0); - SectionMgr.AddSize(Out); + rOut.WriteToBoundary(32, 0); + SectionMgr.AddSize(rOut); // Surfaces - u32 SurfacesStart = Out.Tell(); + u32 SurfacesStart = rOut.Tell(); std::vector SurfaceEndOffsets(mNumSurfaces); for (u32 iSurf = 0; iSurf < mNumSurfaces; iSurf++) { SSurface *pSurface = mpModel->GetSurface(iSurf); - pSurface->CenterPoint.Write(Out); - Out.WriteLong(pSurface->MaterialID); - Out.WriteShort((u16) 0x8000); - u32 PrimTableSizeOffset = Out.Tell(); - Out.WriteShort(0); - Out.WriteLongLong(0); - Out.WriteLong(0); - pSurface->ReflectionDirection.Write(Out); - Out.WriteToBoundary(32, 0); + pSurface->CenterPoint.Write(rOut); + rOut.WriteLong(pSurface->MaterialID); + rOut.WriteShort((u16) 0x8000); + u32 PrimTableSizeOffset = rOut.Tell(); + rOut.WriteShort(0); + rOut.WriteLongLong(0); + rOut.WriteLong(0); + pSurface->ReflectionDirection.Write(rOut); + rOut.WriteToBoundary(32, 0); - u32 PrimTableStart = Out.Tell(); + u32 PrimTableStart = rOut.Tell(); FVertexDescription MatAttribs = mpModel->GetMaterialBySurface(0, iSurf)->VtxDesc(); for (u32 iPrim = 0; iPrim < pSurface->Primitives.size(); iPrim++) { SSurface::SPrimitive *pPrimitive = &pSurface->Primitives[iPrim]; - Out.WriteByte((u8) pPrimitive->Type); - Out.WriteShort((u16) pPrimitive->Vertices.size()); + rOut.WriteByte((u8) pPrimitive->Type); + rOut.WriteShort((u16) pPrimitive->Vertices.size()); for (u32 iVert = 0; iVert < pPrimitive->Vertices.size(); iVert++) { @@ -180,59 +172,59 @@ void CModelCooker::WriteModelPrime(IOutputStream& Out) { for (u32 iMtxAttribs = 0; iMtxAttribs < 8; iMtxAttribs++) if (MatAttribs & (ePosMtx << iMtxAttribs)) - Out.WriteByte(pVert->MatrixIndices[iMtxAttribs]); + rOut.WriteByte(pVert->MatrixIndices[iMtxAttribs]); } u16 VertexIndex = (u16) pVert->ArrayPosition; if (MatAttribs & ePosition) - Out.WriteShort(VertexIndex); + rOut.WriteShort(VertexIndex); if (MatAttribs & eNormal) - Out.WriteShort(VertexIndex); + rOut.WriteShort(VertexIndex); if (MatAttribs & eColor0) - Out.WriteShort(VertexIndex); + rOut.WriteShort(VertexIndex); if (MatAttribs & eColor1) - Out.WriteShort(VertexIndex); + rOut.WriteShort(VertexIndex); u16 TexOffset = 0; for (u32 iTex = 0; iTex < 8; iTex++) { if (MatAttribs & (eTex0 << (iTex * 2))) { - Out.WriteShort(VertexIndex + TexOffset); + rOut.WriteShort(VertexIndex + TexOffset); TexOffset += (u16) mNumVertices; } } } } - Out.WriteToBoundary(32, 0); - u32 PrimTableEnd = Out.Tell(); + rOut.WriteToBoundary(32, 0); + u32 PrimTableEnd = rOut.Tell(); u32 PrimTableSize = PrimTableEnd - PrimTableStart; - Out.Seek(PrimTableSizeOffset, SEEK_SET); - Out.WriteShort((u16) PrimTableSize); - Out.Seek(PrimTableEnd, SEEK_SET); + rOut.Seek(PrimTableSizeOffset, SEEK_SET); + rOut.WriteShort((u16) PrimTableSize); + rOut.Seek(PrimTableEnd, SEEK_SET); - SectionMgr.AddSize(Out); - SurfaceEndOffsets[iSurf] = Out.Tell() - SurfacesStart; + SectionMgr.AddSize(rOut); + SurfaceEndOffsets[iSurf] = rOut.Tell() - SurfacesStart; } // Done writing the file - now we go back to fill in surface offsets + section sizes - Out.Seek(SurfaceOffsetsStart, SEEK_SET); + rOut.Seek(SurfaceOffsetsStart, SEEK_SET); for (u32 iSurf = 0; iSurf < mNumSurfaces; iSurf++) - Out.WriteLong(SurfaceEndOffsets[iSurf]); + rOut.WriteLong(SurfaceEndOffsets[iSurf]); - Out.Seek(SectionSizesOffset, SEEK_SET); - SectionMgr.WriteSizes(Out); + rOut.Seek(SectionSizesOffset, SEEK_SET); + SectionMgr.WriteSizes(rOut); // Done! } -void CModelCooker::WriteCookedModel(CModel *pModel, EGame Version, IOutputStream& CMDL) +void CModelCooker::WriteCookedModel(CModel *pModel, EGame Version, IOutputStream& rOut) { CModelCooker Cooker; Cooker.mpModel = pModel; @@ -244,12 +236,12 @@ void CModelCooker::WriteCookedModel(CModel *pModel, EGame Version, IOutputStream case ePrime: case eEchoesDemo: case eEchoes: - Cooker.WriteModelPrime(CMDL); + Cooker.WriteModelPrime(rOut); break; } } -void CModelCooker::WriteUncookedModel(CModel* /*pModel*/, IOutputStream& /*EMDL*/) +void CModelCooker::WriteUncookedModel(CModel* /*pModel*/, IOutputStream& /*rOut*/) { } diff --git a/src/Core/Resource/Cooker/CModelCooker.h b/src/Core/Resource/Cooker/CModelCooker.h index 3e31c800..fff03b54 100644 --- a/src/Core/Resource/Cooker/CModelCooker.h +++ b/src/Core/Resource/Cooker/CModelCooker.h @@ -18,12 +18,12 @@ class CModelCooker CModelCooker(); void GenerateSurfaceData(); - void WriteEditorModel(IOutputStream& Out); - void WriteModelPrime(IOutputStream& Out); + void WriteEditorModel(IOutputStream& rOut); + void WriteModelPrime(IOutputStream& rOut); public: - static void WriteCookedModel(CModel *pModel, EGame Version, IOutputStream& Out); - static void WriteUncookedModel(CModel *pModel, IOutputStream& Out); + static void WriteCookedModel(CModel *pModel, EGame Version, IOutputStream& rOut); + static void WriteUncookedModel(CModel *pModel, IOutputStream& rOut); static u32 GetCMDLVersion(EGame Version); }; diff --git a/src/Core/Resource/Cooker/CPoiToWorldCooker.cpp b/src/Core/Resource/Cooker/CPoiToWorldCooker.cpp index 407d8acf..92222e7d 100644 --- a/src/Core/Resource/Cooker/CPoiToWorldCooker.cpp +++ b/src/Core/Resource/Cooker/CPoiToWorldCooker.cpp @@ -12,13 +12,13 @@ void CPoiToWorldCooker::WriteEGMC(CPoiToWorld *pPoiToWorld, IOutputStream& rOut) for (u32 iPoi = 0; iPoi < pPoiToWorld->NumMappedPOIs(); iPoi++) { - const CPoiToWorld::SPoiMap *kpMap = pPoiToWorld->MapByIndex(iPoi); + const CPoiToWorld::SPoiMap *pkMap = pPoiToWorld->MapByIndex(iPoi); - for (auto it = kpMap->ModelIDs.begin(); it != kpMap->ModelIDs.end(); it++) + for (auto it = pkMap->ModelIDs.begin(); it != pkMap->ModelIDs.end(); it++) { SPoiMapping Mapping; Mapping.MeshID = *it; - Mapping.PoiID = kpMap->PoiID; + Mapping.PoiID = pkMap->PoiID; Mappings.push_back(Mapping); } } diff --git a/src/Core/Resource/Cooker/CSectionMgrOut.cpp b/src/Core/Resource/Cooker/CSectionMgrOut.cpp deleted file mode 100644 index c5197308..00000000 --- a/src/Core/Resource/Cooker/CSectionMgrOut.cpp +++ /dev/null @@ -1,33 +0,0 @@ -#include "CSectionMgrOut.h" - -CSectionMgrOut::CSectionMgrOut() -{ - mSectionCount = 0; - mCurSectionStart = 0; - mCurSectionIndex = 0; -} - -void CSectionMgrOut::SetSectionCount(u32 Count) -{ - mSectionCount = Count; - mSectionSizes.resize(Count); -} - -void CSectionMgrOut::Init(const IOutputStream& OutputStream) -{ - mCurSectionStart = OutputStream.Tell(); - mCurSectionIndex = 0; -} - -void CSectionMgrOut::AddSize(IOutputStream& OutputStream) -{ - mSectionSizes[mCurSectionIndex] = OutputStream.Tell() - mCurSectionStart; - mCurSectionIndex++; - mCurSectionStart = OutputStream.Tell(); -} - -void CSectionMgrOut::WriteSizes(IOutputStream& OutputStream) -{ - for (u32 iSec = 0; iSec < mSectionCount; iSec++) - OutputStream.WriteLong(mSectionSizes[iSec]); -} diff --git a/src/Core/Resource/Cooker/CSectionMgrOut.h b/src/Core/Resource/Cooker/CSectionMgrOut.h index 776e3a3b..37d58a9b 100644 --- a/src/Core/Resource/Cooker/CSectionMgrOut.h +++ b/src/Core/Resource/Cooker/CSectionMgrOut.h @@ -14,11 +14,36 @@ class CSectionMgrOut std::vector mSectionSizes; public: - CSectionMgrOut(); - void SetSectionCount(u32 Count); - void Init(const IOutputStream& OutputStream); - void AddSize(IOutputStream& OutputStream); - void WriteSizes(IOutputStream& OutputStream); + CSectionMgrOut() + : mSectionCount(0) + , mCurSectionStart(0) + , mCurSectionIndex(0) + {} + + void SetSectionCount(u32 Count) + { + mSectionCount = Count; + mSectionSizes.resize(Count); + } + + void Init(const IOutputStream& rOut) + { + mCurSectionStart = rOut.Tell(); + mCurSectionIndex = 0; + } + + void AddSize(IOutputStream& rOut) + { + mSectionSizes[mCurSectionIndex] = rOut.Tell() - mCurSectionStart; + mCurSectionIndex++; + mCurSectionStart = rOut.Tell(); + } + + void WriteSizes(IOutputStream& rOut) + { + for (u32 iSec = 0; iSec < mSectionCount; iSec++) + rOut.WriteLong(mSectionSizes[iSec]); + } }; #endif // CBLOCKMGROUT_H diff --git a/src/Core/Resource/Cooker/CTemplateWriter.cpp b/src/Core/Resource/Cooker/CTemplateWriter.cpp index 8cb593df..c272ade1 100644 --- a/src/Core/Resource/Cooker/CTemplateWriter.cpp +++ b/src/Core/Resource/Cooker/CTemplateWriter.cpp @@ -41,7 +41,7 @@ void CTemplateWriter::SavePropertyTemplate(IPropertyTemplate *pTemp) void CTemplateWriter::SaveAllTemplates() { // Create directory - std::list MasterList = CMasterTemplate::GetMasterList(); + std::list MasterList = CMasterTemplate::MasterList(); boost::filesystem::create_directory(smTemplatesDir.ToStdString()); // Resave property list @@ -77,8 +77,8 @@ void CTemplateWriter::SaveAllTemplates() pGame->LinkEndChild(pGameName); XMLElement *pAreaVersion = GameList.NewElement("mrea"); - u32 VersionNumber = CAreaCooker::GetMREAVersion(pMaster->GetGame()); - pAreaVersion->SetText(*TString::HexString(VersionNumber, true, true, 2)); + u32 VersionNumber = CAreaCooker::GetMREAVersion(pMaster->Game()); + pAreaVersion->SetText(*TString::HexString(VersionNumber, 2)); pGame->LinkEndChild(pAreaVersion); XMLElement *pTempPath = GameList.NewElement("master"); @@ -139,7 +139,7 @@ void CTemplateWriter::SaveGameTemplates(CMasterTemplate *pMaster) TString StrID; if (ObjID <= 0xFF) - StrID = TString::HexString(ObjID, true, true, 2); + StrID = TString::HexString(ObjID, 2); else StrID = CFourCC(ObjID).ToString(); @@ -177,7 +177,7 @@ void CTemplateWriter::SaveGameTemplates(CMasterTemplate *pMaster) } TString StrID; - if (ID <= 0xFF) StrID = TString::HexString(ID, true, true, 2); + if (ID <= 0xFF) StrID = TString::HexString(ID, 2); else StrID = CFourCC(ID).ToString(); XMLElement *pSubElem = Master.NewElement(*Type); @@ -210,7 +210,7 @@ void CTemplateWriter::SavePropertyList() TString Name = it->second; XMLElement *pElem = List.NewElement("property"); - pElem->SetAttribute("ID", *TString::HexString(ID, true, true, 8)); + pElem->SetAttribute("ID", *TString::HexString(ID)); pElem->SetAttribute("name", *Name); pBase->LinkEndChild(pElem); } @@ -262,7 +262,7 @@ void CTemplateWriter::SaveScriptTemplate(CScriptTemplate *pTemp) XMLElement *pEditorProperties = ScriptXML.NewElement("properties"); pEditor->LinkEndChild(pEditorProperties); - TString propNames[6] = { + TString PropNames[6] = { "InstanceName", "Position", "Rotation", "Scale", "Active", "LightParameters" }; @@ -277,7 +277,7 @@ void CTemplateWriter::SaveScriptTemplate(CScriptTemplate *pTemp) if (!pPropStrings[iProp]->IsEmpty()) { XMLElement *pProperty = ScriptXML.NewElement("property"); - pProperty->SetAttribute("name", *propNames[iProp]); + pProperty->SetAttribute("name", *PropNames[iProp]); pProperty->SetAttribute("ID", **pPropStrings[iProp]); pEditorProperties->LinkEndChild(pProperty); } @@ -373,7 +373,7 @@ void CTemplateWriter::SaveScriptTemplate(CScriptTemplate *pTemp) if (pProp->Type() == eBoolProperty) StrVal = (it->Value == 1 ? "true" : "false"); else - StrVal = TString::HexString((u32) it->Value, true, true, (it->Value > 0xFF ? 8 : 2)); + StrVal = TString::HexString((u32) it->Value, (it->Value > 0xFF ? 8 : 2)); XMLElement *pCondition = ScriptXML.NewElement("condition"); pCondition->SetAttribute("value", *StrVal); @@ -469,7 +469,7 @@ void CTemplateWriter::SaveProperties(XMLDocument *pDoc, XMLElement *pParent, CSt // Get ID IPropertyTemplate *pProp = pTemp->PropertyByIndex(iProp); u32 ID = pProp->PropertyID(); - TString StrID = TString::HexString(ID, true, true, (ID > 0xFF ? 8 : 2)); + TString StrID = TString::HexString(ID, (ID > 0xFF ? 8 : 2)); // Create element XMLElement *pElem; @@ -495,7 +495,7 @@ void CTemplateWriter::SaveProperties(XMLDocument *pDoc, XMLElement *pParent, CSt if (pProp->Game() >= eEchoesDemo && ID > 0xFF) { - TString MasterName = CMasterTemplate::GetPropertyName(ID); + TString MasterName = CMasterTemplate::PropertyName(ID); if (Name != MasterName) pElem->SetAttribute("name", *Name); @@ -652,7 +652,7 @@ void CTemplateWriter::SaveProperties(XMLDocument *pDoc, XMLElement *pParent, CSt else { - CStructTemplate *pOriginal = pMaster->GetStructAtSource(pStruct->mSourceFile); + CStructTemplate *pOriginal = pMaster->StructAtSource(pStruct->mSourceFile); if (pOriginal) SavePropertyOverrides(pDoc, pElem, pStruct, pOriginal); @@ -696,7 +696,7 @@ void CTemplateWriter::SavePropertyOverrides(XMLDocument *pDoc, XMLElement *pPare // ID u32 ID = pProp->PropertyID(); - pElem->SetAttribute("ID", *TString::HexString(pProp->PropertyID(), true, true, (ID > 0xFF ? 8 : 2))); + pElem->SetAttribute("ID", *TString::HexString(pProp->PropertyID(), (ID > 0xFF ? 8 : 2))); // Name if (pProp->Name() != pSource->Name()) @@ -793,7 +793,7 @@ void CTemplateWriter::SaveEnumerators(XMLDocument *pDoc, XMLElement *pParent, CE { XMLElement *pElem = pDoc->NewElement("enumerator"); u32 EnumerID = pTemp->EnumeratorID(iEnum); - pElem->SetAttribute("ID", *TString::HexString(EnumerID, true, true, (EnumerID > 0xFF ? 8 : 2))); + pElem->SetAttribute("ID", *TString::HexString(EnumerID, (EnumerID > 0xFF ? 8 : 2))); pElem->SetAttribute("name", *pTemp->EnumeratorName(iEnum)); pEnumerators->LinkEndChild(pElem); } @@ -807,7 +807,7 @@ void CTemplateWriter::SaveBitFlags(XMLDocument *pDoc, XMLElement *pParent, CBitf for (u32 iFlag = 0; iFlag < pTemp->NumFlags(); iFlag++) { XMLElement *pElem = pDoc->NewElement("flag"); - pElem->SetAttribute("mask", *TString::HexString(pTemp->FlagMask(iFlag), true, true, 8)); + pElem->SetAttribute("mask", *TString::HexString(pTemp->FlagMask(iFlag))); pElem->SetAttribute("name", *pTemp->FlagName(iFlag)); pFlags->LinkEndChild(pElem); } diff --git a/src/Core/Resource/Cooker/CTextureEncoder.cpp b/src/Core/Resource/Cooker/CTextureEncoder.cpp index a8332c5f..a462020a 100644 --- a/src/Core/Resource/Cooker/CTextureEncoder.cpp +++ b/src/Core/Resource/Cooker/CTextureEncoder.cpp @@ -2,34 +2,34 @@ #include CTextureEncoder::CTextureEncoder() + : mpTexture(nullptr) { - mpTexture = nullptr; } -void CTextureEncoder::WriteTXTR(IOutputStream& TXTR) +void CTextureEncoder::WriteTXTR(IOutputStream& rTXTR) { // Only DXT1->CMPR supported at the moment - TXTR.WriteLong(mOutputFormat); - TXTR.WriteShort(mpTexture->mWidth); - TXTR.WriteShort(mpTexture->mHeight); - TXTR.WriteLong(mpTexture->mNumMipMaps); + rTXTR.WriteLong(mOutputFormat); + rTXTR.WriteShort(mpTexture->mWidth); + rTXTR.WriteShort(mpTexture->mHeight); + rTXTR.WriteLong(mpTexture->mNumMipMaps); u32 MipW = mpTexture->Width() / 4; u32 MipH = mpTexture->Height() / 4; - CMemoryInStream Image(mpTexture->mImgDataBuffer, mpTexture->mImgDataSize, IOUtil::eLittleEndian); + CMemoryInStream Image(mpTexture->mpImgDataBuffer, mpTexture->mImgDataSize, IOUtil::eLittleEndian); u32 MipOffset = Image.Tell(); for (u32 iMip = 0; iMip < mpTexture->mNumMipMaps; iMip++) { - for (u32 BlockY = 0; BlockY < MipH; BlockY += 2) - for (u32 BlockX = 0; BlockX < MipW; BlockX += 2) - for (u32 ImgY = BlockY; ImgY < BlockY + 2; ImgY++) - for (u32 ImgX = BlockX; ImgX < BlockX + 2; ImgX++) + for (u32 iBlockY = 0; iBlockY < MipH; iBlockY += 2) + for (u32 iBlockX = 0; iBlockX < MipW; iBlockX += 2) + for (u32 iImgY = iBlockY; iImgY < iBlockY + 2; iImgY++) + for (u32 iImgX = iBlockX; iImgX < iBlockX + 2; iImgX++) { - u32 SrcPos = ((ImgY * MipW) + ImgX) * 8; + u32 SrcPos = ((iImgY * MipW) + iImgX) * 8; Image.Seek(MipOffset + SrcPos, SEEK_SET); - ReadSubBlockCMPR(Image, TXTR); + ReadSubBlockCMPR(Image, rTXTR); } MipOffset += MipW * MipH * 8; @@ -45,20 +45,21 @@ void CTextureEncoder::DetermineBestOutputFormat() // todo } -void CTextureEncoder::ReadSubBlockCMPR(IInputStream& Source, IOutputStream& Dest) +void CTextureEncoder::ReadSubBlockCMPR(IInputStream& rSource, IOutputStream& rDest) { - Dest.WriteShort(Source.ReadShort()); - Dest.WriteShort(Source.ReadShort()); + rDest.WriteShort(rSource.ReadShort()); + rDest.WriteShort(rSource.ReadShort()); - for (u32 byte = 0; byte < 4; byte++) { - u8 b = Source.ReadByte(); - b = ((b & 0x3) << 6) | ((b & 0xC) << 2) | ((b & 0x30) >> 2) | ((b & 0xC0) >> 6); - Dest.WriteByte(b); + for (u32 iByte = 0; iByte < 4; iByte++) + { + u8 Byte = rSource.ReadByte(); + Byte = ((Byte & 0x3) << 6) | ((Byte & 0xC) << 2) | ((Byte & 0x30) >> 2) | ((Byte & 0xC0) >> 6); + rDest.WriteByte(Byte); } } // ************ STATIC ************ -void CTextureEncoder::EncodeTXTR(IOutputStream& TXTR, CTexture *pTex) +void CTextureEncoder::EncodeTXTR(IOutputStream& rTXTR, CTexture *pTex) { if (pTex->mTexelFormat != eDXT1) { @@ -70,13 +71,13 @@ void CTextureEncoder::EncodeTXTR(IOutputStream& TXTR, CTexture *pTex) Encoder.mpTexture = pTex; Encoder.mSourceFormat = eDXT1; Encoder.mOutputFormat = eGX_CMPR; - Encoder.WriteTXTR(TXTR); + Encoder.WriteTXTR(rTXTR); } -void CTextureEncoder::EncodeTXTR(IOutputStream& TXTR, CTexture *pTex, ETexelFormat /*OutputFormat*/) +void CTextureEncoder::EncodeTXTR(IOutputStream& rTXTR, CTexture *pTex, ETexelFormat /*OutputFormat*/) { // todo: support for encoding a specific format - EncodeTXTR(TXTR, pTex); + EncodeTXTR(rTXTR, pTex); } ETexelFormat CTextureEncoder::GetGXFormat(ETexelFormat Format) diff --git a/src/Core/Resource/Cooker/CTextureEncoder.h b/src/Core/Resource/Cooker/CTextureEncoder.h index 52fbebc6..eaba569a 100644 --- a/src/Core/Resource/Cooker/CTextureEncoder.h +++ b/src/Core/Resource/Cooker/CTextureEncoder.h @@ -13,13 +13,13 @@ class CTextureEncoder ETexelFormat mOutputFormat; CTextureEncoder(); - void WriteTXTR(IOutputStream& TXTR); + void WriteTXTR(IOutputStream& rTXTR); void DetermineBestOutputFormat(); - void ReadSubBlockCMPR(IInputStream& Source, IOutputStream& Dest); + void ReadSubBlockCMPR(IInputStream& rSource, IOutputStream& rDest); public: - static void EncodeTXTR(IOutputStream& TXTR, CTexture *pTex); - static void EncodeTXTR(IOutputStream& TXTR, CTexture *pTex, ETexelFormat OutputFormat); + static void EncodeTXTR(IOutputStream& rTXTR, CTexture *pTex); + static void EncodeTXTR(IOutputStream& rTXTR, CTexture *pTex, ETexelFormat OutputFormat); static ETexelFormat GetGXFormat(ETexelFormat Format); static ETexelFormat GetFormat(ETexelFormat Format); }; diff --git a/src/Core/Resource/Cooker/CWorldCooker.cpp b/src/Core/Resource/Cooker/CWorldCooker.cpp index b42e1681..a462bb0e 100644 --- a/src/Core/Resource/Cooker/CWorldCooker.cpp +++ b/src/Core/Resource/Cooker/CWorldCooker.cpp @@ -4,9 +4,9 @@ CWorldCooker::CWorldCooker() { } -u32 CWorldCooker::GetMLVLVersion(EGame version) +u32 CWorldCooker::GetMLVLVersion(EGame Version) { - switch (version) + switch (Version) { case ePrimeDemo: return 0xD; case ePrime: return 0x11; diff --git a/src/Core/Resource/Cooker/CWorldCooker.h b/src/Core/Resource/Cooker/CWorldCooker.h index 8d1029df..0d7e24bf 100644 --- a/src/Core/Resource/Cooker/CWorldCooker.h +++ b/src/Core/Resource/Cooker/CWorldCooker.h @@ -8,7 +8,7 @@ class CWorldCooker { CWorldCooker(); public: - static u32 GetMLVLVersion(EGame version); + static u32 GetMLVLVersion(EGame Version); }; #endif // CWORLDCOOKER_H diff --git a/src/Core/Resource/EGame.h b/src/Core/Resource/EGame.h index bf5588ca..abcf71b7 100644 --- a/src/Core/Resource/EGame.h +++ b/src/Core/Resource/EGame.h @@ -4,14 +4,14 @@ // Global version enum that can be easily shared between loaders enum EGame { - ePrimeDemo = 0, - ePrime = 1, - eEchoesDemo = 2, - eEchoes = 3, - eCorruptionProto = 4, - eCorruption = 5, - eReturns = 6, - eUnknownVersion = -1 + ePrimeDemo = 0, + ePrime = 1, + eEchoesDemo = 2, + eEchoes = 3, + eCorruptionProto = 4, + eCorruption = 5, + eReturns = 6, + eUnknownVersion = -1 }; #endif // EGAME_H diff --git a/src/Core/Resource/Factory/CAnimSetLoader.cpp b/src/Core/Resource/Factory/CAnimSetLoader.cpp index c93b4ec8..07d0fa50 100644 --- a/src/Core/Resource/Factory/CAnimSetLoader.cpp +++ b/src/Core/Resource/Factory/CAnimSetLoader.cpp @@ -6,189 +6,192 @@ CAnimSetLoader::CAnimSetLoader() { } -CAnimSet* CAnimSetLoader::LoadCorruptionCHAR(IInputStream& CHAR) +CAnimSet* CAnimSetLoader::LoadCorruptionCHAR(IInputStream& rCHAR) { // For now, we only read enough to fetch the model - CHAR.Seek(0x1, SEEK_CUR); - set->nodes.resize(1); - CAnimSet::SNode& node = set->nodes[0]; + rCHAR.Seek(0x1, SEEK_CUR); + pSet->mNodes.resize(1); + CAnimSet::SNode& node = pSet->mNodes[0]; - node.name = CHAR.ReadString(); - node.model = gResCache.GetResource(CHAR.ReadLongLong(), "CMDL"); - return set; + node.Name = rCHAR.ReadString(); + node.pModel = gResCache.GetResource(rCHAR.ReadLongLong(), "CMDL"); + return pSet; } -CAnimSet* CAnimSetLoader::LoadReturnsCHAR(IInputStream& CHAR) +CAnimSet* CAnimSetLoader::LoadReturnsCHAR(IInputStream& rCHAR) { // For now, we only read enough to fetch the model - CHAR.Seek(0x16, SEEK_CUR); - set->nodes.resize(1); - CAnimSet::SNode& node = set->nodes[0]; + rCHAR.Seek(0x16, SEEK_CUR); + pSet->mNodes.resize(1); + CAnimSet::SNode& rNode = pSet->mNodes[0]; - node.name = CHAR.ReadString(); - CHAR.Seek(0x14, SEEK_CUR); - CHAR.ReadString(); - node.model = gResCache.GetResource(CHAR.ReadLongLong(), "CMDL"); - return set; + rNode.Name = rCHAR.ReadString(); + rCHAR.Seek(0x14, SEEK_CUR); + rCHAR.ReadString(); + rNode.pModel = gResCache.GetResource(rCHAR.ReadLongLong(), "CMDL"); + return pSet; } -void CAnimSetLoader::LoadPASDatabase(IInputStream& PAS4) +void CAnimSetLoader::LoadPASDatabase(IInputStream& rPAS4) { // For now, just parse the data; don't store it - PAS4.Seek(0x4, SEEK_CUR); // Skipping PAS4 FourCC - u32 anim_state_count = PAS4.ReadLong(); - PAS4.Seek(0x4, SEEK_CUR); // Skipping default anim state + rPAS4.Seek(0x4, SEEK_CUR); // Skipping PAS4 FourCC + u32 AnimStateCount = rPAS4.ReadLong(); + rPAS4.Seek(0x4, SEEK_CUR); // Skipping default anim state - for (u32 s = 0; s < anim_state_count; s++) + for (u32 iState = 0; iState < AnimStateCount; iState++) { - PAS4.Seek(0x4, SEEK_CUR); // Skipping unknown value - u32 parm_info_count = PAS4.ReadLong(); - u32 anim_info_count = PAS4.ReadLong(); + rPAS4.Seek(0x4, SEEK_CUR); // Skipping unknown value + u32 ParmInfoCount = rPAS4.ReadLong(); + u32 AnimInfoCount = rPAS4.ReadLong(); - u32 skip = 0; - for (u32 p = 0; p < parm_info_count; p++) + u32 Skip = 0; + for (u32 iParm = 0; iParm < ParmInfoCount; iParm++) { - u32 type = PAS4.ReadLong(); - PAS4.Seek(0x8, SEEK_CUR); + u32 Type = rPAS4.ReadLong(); + rPAS4.Seek(0x8, SEEK_CUR); - switch (type) { + switch (Type) { case 0: // Int32 case 1: // Uint32 case 2: // Real32 case 4: // Enum - PAS4.Seek(0x8, SEEK_CUR); - skip += 4; + rPAS4.Seek(0x8, SEEK_CUR); + Skip += 4; break; case 3: // Bool - PAS4.Seek(0x2, SEEK_CUR); - skip++; + rPAS4.Seek(0x2, SEEK_CUR); + Skip++; break; } } - for (u32 a = 0; a < anim_info_count; a++) - PAS4.Seek(0x4 + skip, SEEK_CUR); + for (u32 iInfo = 0; iInfo < AnimInfoCount; iInfo++) + rPAS4.Seek(0x4 + Skip, SEEK_CUR); } } // ************ STATIC ************ -CAnimSet* CAnimSetLoader::LoadANCS(IInputStream& ANCS) +CAnimSet* CAnimSetLoader::LoadANCS(IInputStream& rANCS) { - if (!ANCS.IsValid()) return nullptr; + if (!rANCS.IsValid()) return nullptr; - u32 magic = ANCS.ReadLong(); - if (magic != 0x00010001) + u32 Magic = rANCS.ReadLong(); + if (Magic != 0x00010001) { - Log::FileError(ANCS.GetSourceString(), "Invalid ANCS magic: " + TString::HexString(magic)); + Log::FileError(rANCS.GetSourceString(), "Invalid ANCS magic: " + TString::HexString(Magic)); return nullptr; } - CAnimSetLoader loader; - loader.set = new CAnimSet; + CAnimSetLoader Loader; + Loader.pSet = new CAnimSet; - u32 node_count = ANCS.ReadLong(); - loader.set->nodes.resize(node_count); + u32 NodeCount = rANCS.ReadLong(); + Loader.pSet->mNodes.resize(NodeCount); - for (u32 n = 0; n < node_count; n++) + for (u32 iNode = 0; iNode < NodeCount; iNode++) { - CAnimSet::SNode *node = &loader.set->nodes[n]; + CAnimSet::SNode *pNode = &Loader.pSet->mNodes[iNode]; - ANCS.Seek(0x4, SEEK_CUR); // Skipping node self-index - u16 unknown1 = ANCS.ReadShort(); - if (n == 0) loader.mVersion = (unknown1 == 0xA) ? eEchoes : ePrime; // Best version indicator we know of unfortunately - node->name = ANCS.ReadString(); - node->model = gResCache.GetResource(ANCS.ReadLong(), "CMDL"); - node->skinID = ANCS.ReadLong(); - node->skelID = ANCS.ReadLong(); + rANCS.Seek(0x4, SEEK_CUR); // Skipping node self-index + u16 Unknown1 = rANCS.ReadShort(); + if (iNode == 0) Loader.mVersion = (Unknown1 == 0xA) ? eEchoes : ePrime; // Best version indicator we know of unfortunately + pNode->Name = rANCS.ReadString(); + pNode->pModel = gResCache.GetResource(rANCS.ReadLong(), "CMDL"); + pNode->SkinID = rANCS.ReadLong(); + pNode->SkelID = rANCS.ReadLong(); // Unfortunately that's all that's actually supported at the moment. Hope to expand later. // Since there's no size value I have to actually read the rest of the node to reach the next one - u32 anim_count = ANCS.ReadLong(); - for (u32 a = 0; a < anim_count; a++) + u32 AnimCount = rANCS.ReadLong(); + for (u32 iAnim = 0; iAnim < AnimCount; iAnim++) { - ANCS.Seek(0x4, SEEK_CUR); - if (loader.mVersion == ePrime) ANCS.Seek(0x1, SEEK_CUR); - ANCS.ReadString(); + rANCS.Seek(0x4, SEEK_CUR); + if (Loader.mVersion == ePrime) rANCS.Seek(0x1, SEEK_CUR); + rANCS.ReadString(); } // PAS Database - loader.LoadPASDatabase(ANCS); + Loader.LoadPASDatabase(rANCS); // Particles - u32 particle_count = ANCS.ReadLong(); - ANCS.Seek(particle_count * 4, SEEK_CUR); - u32 swoosh_count = ANCS.ReadLong(); - ANCS.Seek(swoosh_count * 4, SEEK_CUR); - if (unknown1 != 5) ANCS.Seek(0x4, SEEK_CUR); - u32 electric_count = ANCS.ReadLong(); - ANCS.Seek(electric_count * 4, SEEK_CUR); - if (loader.mVersion == eEchoes) { - u32 spsc_count = ANCS.ReadLong(); - ANCS.Seek(spsc_count * 4, SEEK_CUR); - } - ANCS.Seek(0x4, SEEK_CUR); - if (loader.mVersion == eEchoes) ANCS.Seek(0x4, SEEK_CUR); + u32 ParticleCount = rANCS.ReadLong(); + rANCS.Seek(ParticleCount * 4, SEEK_CUR); + u32 SwooshCount = rANCS.ReadLong(); + rANCS.Seek(SwooshCount * 4, SEEK_CUR); + if (Unknown1 != 5) rANCS.Seek(0x4, SEEK_CUR); + u32 ElectricCount = rANCS.ReadLong(); + rANCS.Seek(ElectricCount * 4, SEEK_CUR); - u32 anim_count2 = ANCS.ReadLong(); - for (u32 a = 0; a < anim_count2; a++) + if (Loader.mVersion == eEchoes) { - ANCS.ReadString(); - ANCS.Seek(0x18, SEEK_CUR); + u32 SPSCCount = rANCS.ReadLong(); + rANCS.Seek(SPSCCount * 4, SEEK_CUR); } - u32 EffectGroupCount = ANCS.ReadLong(); - for (u32 g = 0; g < EffectGroupCount; g++) - { - ANCS.ReadString(); - u32 EffectCount = ANCS.ReadLong(); + rANCS.Seek(0x4, SEEK_CUR); + if (Loader.mVersion == eEchoes) rANCS.Seek(0x4, SEEK_CUR); - for (u32 e = 0; e < EffectCount; e++) + u32 AnimCount2 = rANCS.ReadLong(); + for (u32 iAnim = 0; iAnim < AnimCount2; iAnim++) + { + rANCS.ReadString(); + rANCS.Seek(0x18, SEEK_CUR); + } + + u32 EffectGroupCount = rANCS.ReadLong(); + for (u32 iGrp = 0; iGrp < EffectGroupCount; iGrp++) + { + rANCS.ReadString(); + u32 EffectCount = rANCS.ReadLong(); + + for (u32 iEffect = 0; iEffect < EffectCount; iEffect++) { - ANCS.ReadString(); - ANCS.Seek(0x8, SEEK_CUR); - if (loader.mVersion == ePrime) ANCS.ReadString(); - if (loader.mVersion == eEchoes) ANCS.Seek(0x4, SEEK_CUR); - ANCS.Seek(0xC, SEEK_CUR); + rANCS.ReadString(); + rANCS.Seek(0x8, SEEK_CUR); + if (Loader.mVersion == ePrime) rANCS.ReadString(); + if (Loader.mVersion == eEchoes) rANCS.Seek(0x4, SEEK_CUR); + rANCS.Seek(0xC, SEEK_CUR); } } - ANCS.Seek(0x8, SEEK_CUR); + rANCS.Seek(0x8, SEEK_CUR); - u32 unknown_count = ANCS.ReadLong(); - ANCS.Seek(unknown_count * 4, SEEK_CUR); + u32 UnknownCount = rANCS.ReadLong(); + rANCS.Seek(UnknownCount * 4, SEEK_CUR); - if (loader.mVersion == eEchoes) + if (Loader.mVersion == eEchoes) { - ANCS.Seek(0x5, SEEK_CUR); - u32 unknown_count2 = ANCS.ReadLong(); - ANCS.Seek(unknown_count2 * 0x1C, SEEK_CUR); + rANCS.Seek(0x5, SEEK_CUR); + u32 UnknownCount2 = rANCS.ReadLong(); + rANCS.Seek(UnknownCount2 * 0x1C, SEEK_CUR); } // Lots of work for data I'm not even using x.x } - return loader.set; + return Loader.pSet; } -CAnimSet* CAnimSetLoader::LoadCHAR(IInputStream &CHAR) +CAnimSet* CAnimSetLoader::LoadCHAR(IInputStream& rCHAR) { - if (!CHAR.IsValid()) return nullptr; + if (!rCHAR.IsValid()) return nullptr; - CAnimSetLoader loader; - u8 check = CHAR.ReadByte(); + CAnimSetLoader Loader; + u8 Check = rCHAR.ReadByte(); - if (check == 0x5 || check == 0x3) + if (Check == 0x5 || Check == 0x3) { - loader.mVersion = eCorruption; - loader.set = new CAnimSet(); - return loader.LoadCorruptionCHAR(CHAR); + Loader.mVersion = eCorruption; + Loader.pSet = new CAnimSet(); + return Loader.LoadCorruptionCHAR(rCHAR); } - if (check == 0x59) + if (Check == 0x59) { - loader.mVersion = eReturns; - loader.set = new CAnimSet(); - return loader.LoadReturnsCHAR(CHAR); + Loader.mVersion = eReturns; + Loader.pSet = new CAnimSet(); + return Loader.LoadReturnsCHAR(rCHAR); } - Log::FileError(CHAR.GetSourceString(), "CHAR has invalid first byte: " + TString::HexString(check)); + Log::FileError(rCHAR.GetSourceString(), "CHAR has invalid first byte: " + TString::HexString(Check, 2)); return nullptr; } diff --git a/src/Core/Resource/Factory/CAnimSetLoader.h b/src/Core/Resource/Factory/CAnimSetLoader.h index 6638f3ce..fd876162 100644 --- a/src/Core/Resource/Factory/CAnimSetLoader.h +++ b/src/Core/Resource/Factory/CAnimSetLoader.h @@ -7,18 +7,18 @@ class CAnimSetLoader { - TResPtr set; + TResPtr pSet; CResCache *mpResCache; EGame mVersion; CAnimSetLoader(); - CAnimSet* LoadCorruptionCHAR(IInputStream& CHAR); - CAnimSet* LoadReturnsCHAR(IInputStream& CHAR); - void LoadPASDatabase(IInputStream& PAS4); + CAnimSet* LoadCorruptionCHAR(IInputStream& rCHAR); + CAnimSet* LoadReturnsCHAR(IInputStream& rCHAR); + void LoadPASDatabase(IInputStream& rPAS4); public: - static CAnimSet* LoadANCS(IInputStream& ANCS); - static CAnimSet* LoadCHAR(IInputStream& CHAR); + static CAnimSet* LoadANCS(IInputStream& rANCS); + static CAnimSet* LoadCHAR(IInputStream& rCHAR); }; #endif // CCHARACTERLOADER_H diff --git a/src/Core/Resource/Factory/CAreaLoader.cpp b/src/Core/Resource/Factory/CAreaLoader.cpp index 1ce905ee..7efdd64f 100644 --- a/src/Core/Resource/Factory/CAreaLoader.cpp +++ b/src/Core/Resource/Factory/CAreaLoader.cpp @@ -11,26 +11,26 @@ #include CAreaLoader::CAreaLoader() + : mpMREA(nullptr) + , mHasDecompressedBuffer(false) + , mGeometryBlockNum(-1) + , mScriptLayerBlockNum(-1) + , mCollisionBlockNum(-1) + , mUnknownBlockNum(-1) + , mLightsBlockNum(-1) + , mEmptyBlockNum(-1) + , mPathBlockNum(-1) + , mOctreeBlockNum(-1) + , mScriptGeneratorBlockNum(-1) + , mFFFFBlockNum(-1) + , mUnknown2BlockNum(-1) + , mEGMCBlockNum(-1) + , mBoundingBoxesBlockNum(-1) + , mDependenciesBlockNum(-1) + , mGPUBlockNum(-1) + , mPVSBlockNum(-1) + , mRSOBlockNum(-1) { - mpMREA = nullptr; - mHasDecompressedBuffer = false; - mGeometryBlockNum = -1; - mScriptLayerBlockNum = -1; - mCollisionBlockNum = -1; - mUnknownBlockNum = -1; - mLightsBlockNum = -1; - mEmptyBlockNum = -1; - mPathBlockNum = -1; - mOctreeBlockNum = -1; - mScriptGeneratorBlockNum = -1; - mFFFFBlockNum = -1; - mUnknown2BlockNum = -1; - mEGMCBlockNum = -1; - mBoundingBoxesBlockNum = -1; - mDependenciesBlockNum = -1; - mGPUBlockNum = -1; - mPVSBlockNum = -1; - mRSOBlockNum = -1; } CAreaLoader::~CAreaLoader() @@ -38,7 +38,7 @@ CAreaLoader::~CAreaLoader() if (mHasDecompressedBuffer) { delete mpMREA; - delete[] mDecmpBuffer; + delete[] mpDecmpBuffer; } } @@ -177,17 +177,17 @@ void CAreaLoader::ReadLightsPrime() Log::FileWrite(mpMREA->GetSourceString(), "Reading MREA dynamic lights (MP1/MP2)"); mpSectionMgr->ToSection(mLightsBlockNum); - u32 babedead = mpMREA->ReadLong(); - if (babedead != 0xbabedead) return; + u32 BabeDead = mpMREA->ReadLong(); + if (BabeDead != 0xbabedead) return; mpArea->mLightLayers.resize(2); - for (u32 ly = 0; ly < 2; ly++) + for (u32 iLyr = 0; iLyr < 2; iLyr++) { u32 NumLights = mpMREA->ReadLong(); - mpArea->mLightLayers[ly].resize(NumLights); + mpArea->mLightLayers[iLyr].resize(NumLights); - for (u32 l = 0; l < NumLights; l++) + for (u32 iLight = 0; iLight < NumLights; iLight++) { ELightType Type = ELightType(mpMREA->ReadLong()); CVector3f Color(*mpMREA); @@ -200,9 +200,9 @@ void CAreaLoader::ReadLightsPrime() mpMREA->Seek(0x4, SEEK_CUR); // Relevant data is read - now we process and form a CLight out of it - CLight *Light; + CLight *pLight; - CColor LightColor = CColor(Color.x, Color.y, Color.z, 0.f); + CColor LightColor = CColor(Color.X, Color.Y, Color.Z, 0.f); if (Multiplier < FLT_EPSILON) Multiplier = FLT_EPSILON; @@ -212,29 +212,29 @@ void CAreaLoader::ReadLightsPrime() Color *= Multiplier; // Clamp - if (Color.x > 1.f) Color.x = 1.f; - if (Color.y > 1.f) Color.y = 1.f; - if (Color.z > 1.f) Color.z = 1.f; - CColor MultColor(Color.x, Color.y, Color.z, 1.f); + if (Color.X > 1.f) Color.X = 1.f; + if (Color.Y > 1.f) Color.Y = 1.f; + if (Color.Z > 1.f) Color.Z = 1.f; + CColor MultColor(Color.X, Color.Y, Color.Z, 1.f); - Light = CLight::BuildLocalAmbient(Position, MultColor); + pLight = CLight::BuildLocalAmbient(Position, MultColor); } // Directional else if (Type == eDirectional) { - Light = CLight::BuildDirectional(Position, Direction, LightColor); + pLight = CLight::BuildDirectional(Position, Direction, LightColor); } // Spot else if (Type == eSpot) { - Light = CLight::BuildSpot(Position, Direction.Normalized(), LightColor, SpotCutoff); + pLight = CLight::BuildSpot(Position, Direction.Normalized(), LightColor, SpotCutoff); float DistAttenA = (FalloffType == 0) ? (2.f / Multiplier) : 0.f; float DistAttenB = (FalloffType == 1) ? (250.f / Multiplier) : 0.f; float DistAttenC = (FalloffType == 2) ? (25000.f / Multiplier) : 0.f; - Light->SetDistAtten(DistAttenA, DistAttenB, DistAttenC); + pLight->SetDistAtten(DistAttenA, DistAttenB, DistAttenC); } // Custom @@ -244,13 +244,13 @@ void CAreaLoader::ReadLightsPrime() float DistAttenB = (FalloffType == 1) ? (249.9998f / Multiplier) : 0.f; float DistAttenC = (FalloffType == 2) ? (25000.f / Multiplier) : 0.f; - Light = CLight::BuildCustom(Position, Direction, LightColor, + pLight = CLight::BuildCustom(Position, Direction, LightColor, DistAttenA, DistAttenB, DistAttenC, 1.f, 0.f, 0.f); } - Light->SetLayer(ly); - mpArea->mLightLayers[ly][l] = Light; + pLight->SetLayer(iLyr); + mpArea->mLightLayers[iLyr][iLight] = pLight; } } } @@ -435,8 +435,8 @@ void CAreaLoader::ReadLightsCorruption() Log::FileWrite(mpMREA->GetSourceString(), "Reading MREA dynamic lights (MP3)"); mpSectionMgr->ToSection(mLightsBlockNum); - u32 babedead = mpMREA->ReadLong(); - if (babedead != 0xbabedead) return; + u32 BabeDead = mpMREA->ReadLong(); + if (BabeDead != 0xbabedead) return; mpArea->mLightLayers.resize(4); @@ -449,11 +449,11 @@ void CAreaLoader::ReadLightsCorruption() { ELightType Type = (ELightType) mpMREA->ReadLong(); - float r = mpMREA->ReadFloat(); - float g = mpMREA->ReadFloat(); - float b = mpMREA->ReadFloat(); - float a = mpMREA->ReadFloat(); - CColor LightColor(r, g, b, a); + float R = mpMREA->ReadFloat(); + float G = mpMREA->ReadFloat(); + float B = mpMREA->ReadFloat(); + float A = mpMREA->ReadFloat(); + CColor LightColor(R, G, B, A); CVector3f Position(*mpMREA); CVector3f Direction(*mpMREA); @@ -466,7 +466,7 @@ void CAreaLoader::ReadLightsCorruption() mpMREA->Seek(0x18, SEEK_CUR); // Relevant data is read - now we process and form a CLight out of it - CLight *Light; + CLight *pLight; if (Multiplier < FLT_EPSILON) Multiplier = FLT_EPSILON; @@ -474,24 +474,24 @@ void CAreaLoader::ReadLightsCorruption() // Local Ambient if (Type == eLocalAmbient) { - Light = CLight::BuildLocalAmbient(Position, LightColor * Multiplier); + pLight = CLight::BuildLocalAmbient(Position, LightColor * Multiplier); } // Directional else if (Type == eDirectional) { - Light = CLight::BuildDirectional(Position, Direction, LightColor); + pLight = CLight::BuildDirectional(Position, Direction, LightColor); } // Spot else if (Type == eSpot) { - Light = CLight::BuildSpot(Position, Direction.Normalized(), LightColor, SpotCutoff); + pLight = CLight::BuildSpot(Position, Direction.Normalized(), LightColor, SpotCutoff); float DistAttenA = (FalloffType == 0) ? (2.f / Multiplier) : 0.f; float DistAttenB = (FalloffType == 1) ? (250.f / Multiplier) : 0.f; float DistAttenC = (FalloffType == 2) ? (25000.f / Multiplier) : 0.f; - Light->SetDistAtten(DistAttenA, DistAttenB, DistAttenC); + pLight->SetDistAtten(DistAttenA, DistAttenB, DistAttenC); } // Custom @@ -501,13 +501,13 @@ void CAreaLoader::ReadLightsCorruption() float DistAttenB = (FalloffType == 1) ? (249.9998f / Multiplier) : 0.f; float DistAttenC = (FalloffType == 2) ? (25000.f / Multiplier) : 0.f; - Light = CLight::BuildCustom(Position, Direction, LightColor, + pLight = CLight::BuildCustom(Position, Direction, LightColor, DistAttenA, DistAttenB, DistAttenC, 1.f, 0.f, 0.f); } - Light->SetLayer(iLayer); - mpArea->mLightLayers[iLayer][iLight] = Light; + pLight->SetLayer(iLayer); + mpArea->mLightLayers[iLayer][iLight] = pLight; } } } @@ -517,15 +517,15 @@ void CAreaLoader::ReadCompressedBlocks() { mTotalDecmpSize = 0; - for (u32 c = 0; c < mClusters.size(); c++) + for (u32 iClust = 0; iClust < mClusters.size(); iClust++) { - mClusters[c].BufferSize = mpMREA->ReadLong(); - mClusters[c].DecompressedSize = mpMREA->ReadLong(); - mClusters[c].CompressedSize = mpMREA->ReadLong(); - mClusters[c].NumSections = mpMREA->ReadLong(); - mTotalDecmpSize += mClusters[c].DecompressedSize; + mClusters[iClust].BufferSize = mpMREA->ReadLong(); + mClusters[iClust].DecompressedSize = mpMREA->ReadLong(); + mClusters[iClust].CompressedSize = mpMREA->ReadLong(); + mClusters[iClust].NumSections = mpMREA->ReadLong(); + mTotalDecmpSize += mClusters[iClust].DecompressedSize; - if (mClusters[c].CompressedSize != 0) mpArea->mUsesCompression = true; + if (mClusters[iClust].CompressedSize != 0) mpArea->mUsesCompression = true; } mpMREA->SeekToBoundary(32); @@ -539,39 +539,39 @@ void CAreaLoader::Decompress() if (mVersion < eEchoes) return; // Decompress clusters - mDecmpBuffer = new u8[mTotalDecmpSize]; + mpDecmpBuffer = new u8[mTotalDecmpSize]; u32 Offset = 0; - for (u32 c = 0; c < mClusters.size(); c++) + for (u32 iClust = 0; iClust < mClusters.size(); iClust++) { - SCompressedCluster *cc = &mClusters[c]; + SCompressedCluster *pClust = &mClusters[iClust]; // Is it decompressed already? - if (mClusters[c].CompressedSize == 0) + if (mClusters[iClust].CompressedSize == 0) { - mpMREA->ReadBytes(mDecmpBuffer + Offset, cc->DecompressedSize); - Offset += cc->DecompressedSize; + mpMREA->ReadBytes(mpDecmpBuffer + Offset, pClust->DecompressedSize); + Offset += pClust->DecompressedSize; } else { - u32 StartOffset = 32 - (mClusters[c].CompressedSize % 32); // For some reason they pad the beginning instead of the end + u32 StartOffset = 32 - (mClusters[iClust].CompressedSize % 32); // For some reason they pad the beginning instead of the end if (StartOffset != 32) mpMREA->Seek(StartOffset, SEEK_CUR); - std::vector cmp(mClusters[c].CompressedSize); - mpMREA->ReadBytes(cmp.data(), cmp.size()); + std::vector CompressedBuf(mClusters[iClust].CompressedSize); + mpMREA->ReadBytes(CompressedBuf.data(), CompressedBuf.size()); - bool Success = CompressionUtil::DecompressSegmentedData(cmp.data(), cmp.size(), mDecmpBuffer + Offset, cc->DecompressedSize); + bool Success = CompressionUtil::DecompressSegmentedData(CompressedBuf.data(), CompressedBuf.size(), mpDecmpBuffer + Offset, pClust->DecompressedSize); if (!Success) throw "Failed to decompress MREA!"; - Offset += cc->DecompressedSize; + Offset += pClust->DecompressedSize; } } TString Source = mpMREA->GetSourceString(); - mpMREA = new CMemoryInStream(mDecmpBuffer, mTotalDecmpSize, IOUtil::eBigEndian); + mpMREA = new CMemoryInStream(mpDecmpBuffer, mTotalDecmpSize, IOUtil::eBigEndian); mpMREA->SetSourceString(Source.ToStdString()); mpSectionMgr->SetInputStream(mpMREA); mHasDecompressedBuffer = true; @@ -609,14 +609,14 @@ void CAreaLoader::ReadEGMC() void CAreaLoader::SetUpObjects() { // Iterate over all objects - for (u32 iLyr = 0; iLyr < mpArea->GetScriptLayerCount() + 1; iLyr++) + for (u32 iLyr = 0; iLyr < mpArea->NumScriptLayers() + 1; iLyr++) { CScriptLayer *pLayer; - if (iLyr < mpArea->GetScriptLayerCount()) pLayer = mpArea->mScriptLayers[iLyr]; + if (iLyr < mpArea->NumScriptLayers()) pLayer = mpArea->mScriptLayers[iLyr]; else { - pLayer = mpArea->GetGeneratorLayer(); + pLayer = mpArea->GeneratedObjectsLayer(); if (!pLayer) break; } @@ -657,17 +657,17 @@ CGameArea* CAreaLoader::LoadMREA(IInputStream& MREA) // Validation if (!MREA.IsValid()) return nullptr; - u32 deadbeef = MREA.ReadLong(); - if (deadbeef != 0xdeadbeef) + u32 DeadBeef = MREA.ReadLong(); + if (DeadBeef != 0xdeadbeef) { - Log::FileError(MREA.GetSourceString(), "Invalid MREA magic: " + TString::HexString(deadbeef)); + Log::FileError(MREA.GetSourceString(), "Invalid MREA magic: " + TString::HexString(DeadBeef)); return nullptr; } // Header Loader.mpArea = new CGameArea; - u32 version = MREA.ReadLong(); - Loader.mVersion = GetFormatVersion(version); + u32 Version = MREA.ReadLong(); + Loader.mVersion = GetFormatVersion(Version); Loader.mpArea->mVersion = Loader.mVersion; Loader.mpMREA = &MREA; @@ -718,7 +718,7 @@ CGameArea* CAreaLoader::LoadMREA(IInputStream& MREA) } break; default: - Log::FileError(MREA.GetSourceString(), "Unsupported MREA version: " + TString::HexString(version)); + Log::FileError(MREA.GetSourceString(), "Unsupported MREA version: " + TString::HexString(Version, 0)); Loader.mpArea.Delete(); return nullptr; } @@ -728,9 +728,9 @@ CGameArea* CAreaLoader::LoadMREA(IInputStream& MREA) return Loader.mpArea; } -EGame CAreaLoader::GetFormatVersion(u32 version) +EGame CAreaLoader::GetFormatVersion(u32 Version) { - switch (version) + switch (Version) { case 0xC: return ePrimeDemo; case 0xF: return ePrime; diff --git a/src/Core/Resource/Factory/CAreaLoader.h b/src/Core/Resource/Factory/CAreaLoader.h index db924fe3..6ffb42d0 100644 --- a/src/Core/Resource/Factory/CAreaLoader.h +++ b/src/Core/Resource/Factory/CAreaLoader.h @@ -25,7 +25,7 @@ class CAreaLoader std::unordered_map> mConnectionMap; // Compression - u8 *mDecmpBuffer; + u8 *mpDecmpBuffer; bool mHasDecompressedBuffer; std::vector mClusters; u32 mTotalDecmpSize; @@ -80,8 +80,8 @@ class CAreaLoader void SetUpObjects(); public: - static CGameArea* LoadMREA(IInputStream& MREA); - static EGame GetFormatVersion(u32 version); + static CGameArea* LoadMREA(IInputStream& rMREA); + static EGame GetFormatVersion(u32 Version); }; #endif // CAREALOADER_H diff --git a/src/Core/Resource/Factory/CCollisionLoader.cpp b/src/Core/Resource/Factory/CCollisionLoader.cpp index fca904aa..2ad885de 100644 --- a/src/Core/Resource/Factory/CCollisionLoader.cpp +++ b/src/Core/Resource/Factory/CCollisionLoader.cpp @@ -6,201 +6,201 @@ CCollisionLoader::CCollisionLoader() { } -CCollisionMesh::CCollisionOctree* CCollisionLoader::ParseOctree(IInputStream& /*src*/) +CCollisionMesh::CCollisionOctree* CCollisionLoader::ParseOctree(IInputStream& /*rSrc*/) { return nullptr; } -CCollisionMesh::CCollisionOctree::SBranch* CCollisionLoader::ParseOctreeBranch(IInputStream& /*src*/) +CCollisionMesh::CCollisionOctree::SBranch* CCollisionLoader::ParseOctreeBranch(IInputStream& /*rSrc*/) { return nullptr; } -CCollisionMesh::CCollisionOctree::SLeaf* CCollisionLoader::ParseOctreeLeaf(IInputStream& /*src*/) +CCollisionMesh::CCollisionOctree::SLeaf* CCollisionLoader::ParseOctreeLeaf(IInputStream& /*rSrc*/) { return nullptr; } -void CCollisionLoader::ParseOBBNode(IInputStream& DCLN) +void CCollisionLoader::ParseOBBNode(IInputStream& rDCLN) { bool b = false; while (b == false) { - DCLN.Seek(0x3C, SEEK_CUR); - b = (DCLN.ReadByte() == 1); - if (!b) ParseOBBNode(DCLN); + rDCLN.Seek(0x3C, SEEK_CUR); + b = (rDCLN.ReadByte() == 1); + if (!b) ParseOBBNode(rDCLN); } - u32 numFaces = DCLN.ReadLong(); - DCLN.Seek(numFaces * 2, SEEK_CUR); + u32 NumFaces = rDCLN.ReadLong(); + rDCLN.Seek(NumFaces * 2, SEEK_CUR); } -void CCollisionLoader::ReadPropertyFlags(IInputStream& src) +void CCollisionLoader::ReadPropertyFlags(IInputStream& rSrc) { - CCollisionMesh::SCollisionProperties property; + CCollisionMesh::SCollisionProperties Property; if (mVersion == ePrime) { - u32 flag = src.ReadLong(); - property.Invert = (flag >> 25) & 0x1; + u32 Flag = rSrc.ReadLong(); + Property.Invert = (Flag >> 25) & 0x1; } else if (mVersion == eEchoes) { - u64 flag = src.ReadLongLong(); - property.Invert = (flag >> 24) & 0x1; + u64 Flag = rSrc.ReadLongLong(); + Property.Invert = (Flag >> 24) & 0x1; } else if (mVersion == eReturns) { - u64 flag = src.ReadLongLong(); - property.Invert = (flag >> 28) & 0x1; + u64 Flag = rSrc.ReadLongLong(); + Property.Invert = (Flag >> 28) & 0x1; } - mProperties.push_back(property); + mProperties.push_back(Property); } -void CCollisionLoader::LoadCollisionIndices(IInputStream &file, bool buildAABox) +void CCollisionLoader::LoadCollisionIndices(IInputStream &rFile, bool BuildAABox) { // Properties - u32 propSetCount = file.ReadLong(); - for (u32 iProp = 0; iProp < propSetCount; iProp++) - ReadPropertyFlags(file); + u32 PropSetCount = rFile.ReadLong(); + for (u32 iProp = 0; iProp < PropSetCount; iProp++) + ReadPropertyFlags(rFile); // Property indices for vertices/lines/faces - u32 vtxIndexCount = file.ReadLong(); - std::vector vtxIndices(vtxIndexCount); - file.ReadBytes(vtxIndices.data(), vtxIndices.size()); + u32 VtxIndexCount = rFile.ReadLong(); + std::vector VtxIndices(VtxIndexCount); + rFile.ReadBytes(VtxIndices.data(), VtxIndices.size()); - u32 lineIndexCount = file.ReadLong(); - std::vector lineIndices(lineIndexCount); - file.ReadBytes(lineIndices.data(), lineIndices.size()); + u32 LineIndexCount = rFile.ReadLong(); + std::vector LineIndices(LineIndexCount); + rFile.ReadBytes(LineIndices.data(), LineIndices.size()); - u32 faceIndexCount = file.ReadLong(); - std::vector faceIndices(faceIndexCount); - file.ReadBytes(faceIndices.data(), faceIndices.size()); + u32 FaceIndexCount = rFile.ReadLong(); + std::vector FaceIndices(FaceIndexCount); + rFile.ReadBytes(FaceIndices.data(), FaceIndices.size()); // Lines - mpMesh->mLineCount = file.ReadLong(); + mpMesh->mLineCount = rFile.ReadLong(); mpMesh->mCollisionLines.resize(mpMesh->mLineCount); for (u32 iLine = 0; iLine < mpMesh->mLineCount; iLine++) { CCollisionMesh::CCollisionLine *pLine = &mpMesh->mCollisionLines[iLine]; - pLine->Vertices[0] = file.ReadShort(); - pLine->Vertices[1] = file.ReadShort(); - pLine->Properties = mProperties[lineIndices[iLine]]; + pLine->Vertices[0] = rFile.ReadShort(); + pLine->Vertices[1] = rFile.ReadShort(); + pLine->Properties = mProperties[LineIndices[iLine]]; } // Faces - mpMesh->mFaceCount = file.ReadLong() / 3; // Not sure why they store it this way. It's inconsistent. + mpMesh->mFaceCount = rFile.ReadLong() / 3; // Not sure why they store it this way. It's inconsistent. mpMesh->mCollisionFaces.resize(mpMesh->mFaceCount); for (u32 iFace = 0; iFace < mpMesh->mFaceCount; iFace++) { CCollisionMesh::CCollisionFace *pFace = &mpMesh->mCollisionFaces[iFace]; - pFace->Lines[0] = file.ReadShort(); - pFace->Lines[1] = file.ReadShort(); - pFace->Lines[2] = file.ReadShort(); - pFace->Properties = mProperties[faceIndices[iFace]]; + pFace->Lines[0] = rFile.ReadShort(); + pFace->Lines[1] = rFile.ReadShort(); + pFace->Lines[2] = rFile.ReadShort(); + pFace->Properties = mProperties[FaceIndices[iFace]]; } // Echoes introduces a new data chunk; don't know what it is yet, skipping for now if (mVersion >= eEchoes) { - u32 unknownCount = file.ReadLong(); - file.Seek(unknownCount * 2, SEEK_CUR); + u32 UnknownCount = rFile.ReadLong(); + rFile.Seek(UnknownCount * 2, SEEK_CUR); } // Vertices - mpMesh->mVertexCount = file.ReadLong(); + mpMesh->mVertexCount = rFile.ReadLong(); mpMesh->mCollisionVertices.resize(mpMesh->mVertexCount); - CAABox bounds; + CAABox Bounds; for (u32 iVtx = 0; iVtx < mpMesh->mVertexCount; iVtx++) { CCollisionMesh::CCollisionVertex *pVtx = &mpMesh->mCollisionVertices[iVtx]; - pVtx->Pos = CVector3f(file); - pVtx->Properties = mProperties[vtxIndices[iVtx]]; - if (buildAABox) bounds.ExpandBounds(pVtx->Pos); + pVtx->Pos = CVector3f(rFile); + pVtx->Properties = mProperties[VtxIndices[iVtx]]; + if (BuildAABox) Bounds.ExpandBounds(pVtx->Pos); } - if (buildAABox) mpMesh->mAABox = bounds; + if (BuildAABox) mpMesh->mAABox = Bounds; } // ************ STATIC ************ -CCollisionMeshGroup* CCollisionLoader::LoadAreaCollision(IInputStream& MREA) +CCollisionMeshGroup* CCollisionLoader::LoadAreaCollision(IInputStream& rMREA) { - if (!MREA.IsValid()) return nullptr; + if (!rMREA.IsValid()) return nullptr; CCollisionLoader loader; - MREA.Seek(0x8, SEEK_CUR); - u32 deafbabe = MREA.ReadLong(); - if (deafbabe != 0xDEAFBABE) + rMREA.Seek(0x8, SEEK_CUR); + u32 DeafBabe = rMREA.ReadLong(); + if (DeafBabe != 0xDEAFBABE) { - Log::FileError(MREA.GetSourceString(), MREA.Tell() - 4, "Invalid collision magic: " + TString::HexString(deafbabe)); + Log::FileError(rMREA.GetSourceString(), rMREA.Tell() - 4, "Invalid collision magic: " + TString::HexString(DeafBabe)); return nullptr; } - loader.mVersion = GetFormatVersion(MREA.ReadLong()); + loader.mVersion = GetFormatVersion(rMREA.ReadLong()); loader.mpGroup = new CCollisionMeshGroup; loader.mpMesh = new CCollisionMesh; // Octree - structure is known, but not coding this right now - loader.mpMesh->mAABox = CAABox(MREA); - MREA.Seek(0x4, SEEK_CUR); - u32 octreeSize = MREA.ReadLong(); - MREA.Seek(octreeSize, SEEK_CUR); // Skipping the octree for now + loader.mpMesh->mAABox = CAABox(rMREA); + rMREA.Seek(0x4, SEEK_CUR); + u32 OctreeSize = rMREA.ReadLong(); + rMREA.Seek(OctreeSize, SEEK_CUR); // Skipping the octree for now loader.mpMesh->mOctreeLoaded = false; // Read collision indices and return - loader.LoadCollisionIndices(MREA, false); + loader.LoadCollisionIndices(rMREA, false); loader.mpGroup->AddMesh(loader.mpMesh); return loader.mpGroup; } -CCollisionMeshGroup* CCollisionLoader::LoadDCLN(IInputStream &DCLN) +CCollisionMeshGroup* CCollisionLoader::LoadDCLN(IInputStream& rDCLN) { - if (!DCLN.IsValid()) return nullptr; + if (!rDCLN.IsValid()) return nullptr; - CCollisionLoader loader; - loader.mpGroup = new CCollisionMeshGroup; + CCollisionLoader Loader; + Loader.mpGroup = new CCollisionMeshGroup; - u32 numMeshes = DCLN.ReadLong(); + u32 NumMeshes = rDCLN.ReadLong(); - for (u32 iMesh = 0; iMesh < numMeshes; iMesh++) + for (u32 iMesh = 0; iMesh < NumMeshes; iMesh++) { - u32 deafbabe = DCLN.ReadLong(); + u32 DeafBabe = rDCLN.ReadLong(); - if (deafbabe != 0xDEAFBABE) + if (DeafBabe != 0xDEAFBABE) { - Log::FileError(DCLN.GetSourceString(), DCLN.Tell() - 4, "Invalid collision magic: " + TString::HexString(deafbabe)); - loader.mpGroup.Delete(); + Log::FileError(rDCLN.GetSourceString(), rDCLN.Tell() - 4, "Invalid collision magic: " + TString::HexString(DeafBabe)); + Loader.mpGroup.Delete(); return nullptr; } - loader.mVersion = GetFormatVersion(DCLN.ReadLong()); + Loader.mVersion = GetFormatVersion(rDCLN.ReadLong()); - loader.mpMesh = new CCollisionMesh; - loader.mpMesh->mOctreeLoaded = false; + Loader.mpMesh = new CCollisionMesh; + Loader.mpMesh->mOctreeLoaded = false; - if (loader.mVersion == eReturns) - loader.mpMesh->mAABox = CAABox(DCLN); + if (Loader.mVersion == eReturns) + Loader.mpMesh->mAABox = CAABox(rDCLN); // Read indices and return - DCLN.Seek(0x4, SEEK_CUR); - loader.LoadCollisionIndices(DCLN, loader.mVersion != eReturns); - loader.mpGroup->AddMesh(loader.mpMesh); + rDCLN.Seek(0x4, SEEK_CUR); + Loader.LoadCollisionIndices(rDCLN, Loader.mVersion != eReturns); + Loader.mpGroup->AddMesh(Loader.mpMesh); // Parse OBB tree - loader.ParseOBBNode(DCLN); + Loader.ParseOBBNode(rDCLN); } - return loader.mpGroup; + return Loader.mpGroup; } -EGame CCollisionLoader::GetFormatVersion(u32 version) +EGame CCollisionLoader::GetFormatVersion(u32 Version) { - switch (version) + switch (Version) { case 0x2: return ePrime; case 0x3: return ePrime; diff --git a/src/Core/Resource/Factory/CCollisionLoader.h b/src/Core/Resource/Factory/CCollisionLoader.h index 55587b1e..34787ab0 100644 --- a/src/Core/Resource/Factory/CCollisionLoader.h +++ b/src/Core/Resource/Factory/CCollisionLoader.h @@ -13,17 +13,17 @@ class CCollisionLoader std::vector mProperties; CCollisionLoader(); - CCollisionMesh::CCollisionOctree* ParseOctree(IInputStream& src); - CCollisionMesh::CCollisionOctree::SBranch* ParseOctreeBranch(IInputStream& src); - CCollisionMesh::CCollisionOctree::SLeaf* ParseOctreeLeaf(IInputStream& src); - void ParseOBBNode(IInputStream& DCLN); - void ReadPropertyFlags(IInputStream& src); - void LoadCollisionIndices(IInputStream& file, bool buildAABox); + CCollisionMesh::CCollisionOctree* ParseOctree(IInputStream& rSrc); + CCollisionMesh::CCollisionOctree::SBranch* ParseOctreeBranch(IInputStream& rSrc); + CCollisionMesh::CCollisionOctree::SLeaf* ParseOctreeLeaf(IInputStream& rSrc); + void ParseOBBNode(IInputStream& rDCLN); + void ReadPropertyFlags(IInputStream& rSrc); + void LoadCollisionIndices(IInputStream& rFile, bool BuildAABox); public: - static CCollisionMeshGroup* LoadAreaCollision(IInputStream& MREA); - static CCollisionMeshGroup* LoadDCLN(IInputStream& DCLN); - static EGame GetFormatVersion(u32 version); + static CCollisionMeshGroup* LoadAreaCollision(IInputStream& rMREA); + static CCollisionMeshGroup* LoadDCLN(IInputStream& rDCLN); + static EGame GetFormatVersion(u32 Version); }; #endif // CCOLLISIONLOADER_H diff --git a/src/Core/Resource/Factory/CFontLoader.cpp b/src/Core/Resource/Factory/CFontLoader.cpp index 56e685ec..baa1b955 100644 --- a/src/Core/Resource/Factory/CFontLoader.cpp +++ b/src/Core/Resource/Factory/CFontLoader.cpp @@ -6,34 +6,34 @@ CFontLoader::CFontLoader() { } -CFont* CFontLoader::LoadFont(IInputStream& FONT) +CFont* CFontLoader::LoadFont(IInputStream& rFONT) { // If I seek past a value without reading it, then it's because I don't know what it is - mpFont->mUnknown = FONT.ReadLong(); - mpFont->mLineHeight = FONT.ReadLong(); - mpFont->mVerticalOffset = FONT.ReadLong(); - mpFont->mLineMargin = FONT.ReadLong(); - if (mVersion > ePrimeDemo) FONT.Seek(0x4, SEEK_CUR); - FONT.Seek(0x2, SEEK_CUR); - mpFont->mDefaultSize = FONT.ReadLong(); - mpFont->mFontName = FONT.ReadString(); + mpFont->mUnknown = rFONT.ReadLong(); + mpFont->mLineHeight = rFONT.ReadLong(); + mpFont->mVerticalOffset = rFONT.ReadLong(); + mpFont->mLineMargin = rFONT.ReadLong(); + if (mVersion > ePrimeDemo) rFONT.Seek(0x4, SEEK_CUR); + rFONT.Seek(0x2, SEEK_CUR); + mpFont->mDefaultSize = rFONT.ReadLong(); + mpFont->mFontName = rFONT.ReadString(); - if (mVersion <= eEchoes) mpFont->mpFontTexture = gResCache.GetResource(FONT.ReadLong(), "TXTR"); - else mpFont->mpFontTexture = gResCache.GetResource(FONT.ReadLongLong(), "TXTR"); + if (mVersion <= eEchoes) mpFont->mpFontTexture = gResCache.GetResource(rFONT.ReadLong(), "TXTR"); + else mpFont->mpFontTexture = gResCache.GetResource(rFONT.ReadLongLong(), "TXTR"); - mpFont->mTextureFormat = FONT.ReadLong(); - u32 NumGlyphs = FONT.ReadLong(); + mpFont->mTextureFormat = rFONT.ReadLong(); + u32 NumGlyphs = rFONT.ReadLong(); mpFont->mGlyphs.reserve(NumGlyphs); for (u32 iGlyph = 0; iGlyph < NumGlyphs; iGlyph++) { CFont::SGlyph Glyph; - Glyph.Character = FONT.ReadShort(); + Glyph.Character = rFONT.ReadShort(); - float TexCoordL = FONT.ReadFloat(); - float TexCoordU = FONT.ReadFloat(); - float TexCoordR = FONT.ReadFloat(); - float TexCoordD = FONT.ReadFloat(); + float TexCoordL = rFONT.ReadFloat(); + float TexCoordU = rFONT.ReadFloat(); + float TexCoordR = rFONT.ReadFloat(); + float TexCoordD = rFONT.ReadFloat(); Glyph.TexCoords[0] = CVector2f(TexCoordL, TexCoordU); // Upper-left Glyph.TexCoords[1] = CVector2f(TexCoordR, TexCoordU); // Upper-right Glyph.TexCoords[2] = CVector2f(TexCoordL, TexCoordD); // Lower-left @@ -42,66 +42,66 @@ CFont* CFontLoader::LoadFont(IInputStream& FONT) if (mVersion <= ePrime) { Glyph.RGBAChannel = 0; - Glyph.LeftPadding = FONT.ReadLong(); - Glyph.PrintAdvance = FONT.ReadLong(); - Glyph.RightPadding = FONT.ReadLong(); - Glyph.Width = FONT.ReadLong(); - Glyph.Height = FONT.ReadLong(); - Glyph.BaseOffset = FONT.ReadLong(); - Glyph.KerningIndex = FONT.ReadLong(); + Glyph.LeftPadding = rFONT.ReadLong(); + Glyph.PrintAdvance = rFONT.ReadLong(); + Glyph.RightPadding = rFONT.ReadLong(); + Glyph.Width = rFONT.ReadLong(); + Glyph.Height = rFONT.ReadLong(); + Glyph.BaseOffset = rFONT.ReadLong(); + Glyph.KerningIndex = rFONT.ReadLong(); } else if (mVersion >= eEchoes) { - Glyph.RGBAChannel = FONT.ReadByte(); - Glyph.LeftPadding = FONT.ReadByte(); - Glyph.PrintAdvance = FONT.ReadByte(); - Glyph.RightPadding = FONT.ReadByte(); - Glyph.Width = FONT.ReadByte(); - Glyph.Height = FONT.ReadByte(); - Glyph.BaseOffset = FONT.ReadByte(); - Glyph.KerningIndex = FONT.ReadShort(); + Glyph.RGBAChannel = rFONT.ReadByte(); + Glyph.LeftPadding = rFONT.ReadByte(); + Glyph.PrintAdvance = rFONT.ReadByte(); + Glyph.RightPadding = rFONT.ReadByte(); + Glyph.Width = rFONT.ReadByte(); + Glyph.Height = rFONT.ReadByte(); + Glyph.BaseOffset = rFONT.ReadByte(); + Glyph.KerningIndex = rFONT.ReadShort(); } mpFont->mGlyphs[Glyph.Character] = Glyph; } - u32 NumKerningPairs = FONT.ReadLong(); + u32 NumKerningPairs = rFONT.ReadLong(); mpFont->mKerningTable.reserve(NumKerningPairs); for (u32 iKern = 0; iKern < NumKerningPairs; iKern++) { CFont::SKerningPair Pair; - Pair.CharacterA = FONT.ReadShort(); - Pair.CharacterB = FONT.ReadShort(); - Pair.Adjust = FONT.ReadLong(); + Pair.CharacterA = rFONT.ReadShort(); + Pair.CharacterB = rFONT.ReadShort(); + Pair.Adjust = rFONT.ReadLong(); mpFont->mKerningTable.push_back(Pair); } return mpFont; } -CFont* CFontLoader::LoadFONT(IInputStream& FONT) +CFont* CFontLoader::LoadFONT(IInputStream& rFONT) { - if (!FONT.IsValid()) return nullptr; + if (!rFONT.IsValid()) return nullptr; - CFourCC Magic(FONT); + CFourCC Magic(rFONT); if (Magic != "FONT") { - Log::FileError(FONT.GetSourceString(), "Invalid FONT magic: " + TString::HexString((u32) Magic.ToLong())); + Log::FileError(rFONT.GetSourceString(), "Invalid FONT magic: " + TString::HexString(Magic.ToLong())); return nullptr; } - u32 FileVersion = FONT.ReadLong(); + u32 FileVersion = rFONT.ReadLong(); EGame Version = GetFormatVersion(FileVersion); if (Version == eUnknownVersion) { - Log::FileError(FONT.GetSourceString(), "Unsupported FONT version: " + TString::HexString(FileVersion)); + Log::FileError(rFONT.GetSourceString(), "Unsupported FONT version: " + TString::HexString(FileVersion, 0)); return nullptr; } CFontLoader Loader; Loader.mpFont = new CFont(); Loader.mVersion = Version; - return Loader.LoadFont(FONT); + return Loader.LoadFont(rFONT); } EGame CFontLoader::GetFormatVersion(u32 Version) diff --git a/src/Core/Resource/Factory/CFontLoader.h b/src/Core/Resource/Factory/CFontLoader.h index 8c97000d..c260cb9b 100644 --- a/src/Core/Resource/Factory/CFontLoader.h +++ b/src/Core/Resource/Factory/CFontLoader.h @@ -11,10 +11,10 @@ class CFontLoader EGame mVersion; CFontLoader(); - CFont* LoadFont(IInputStream& FONT); + CFont* LoadFont(IInputStream& rFONT); public: - static CFont* LoadFONT(IInputStream& FONT); + static CFont* LoadFONT(IInputStream& rFONT); static EGame GetFormatVersion(u32 Version); }; diff --git a/src/Core/Resource/Factory/CMaterialLoader.cpp b/src/Core/Resource/Factory/CMaterialLoader.cpp index f4918c18..57d1540a 100644 --- a/src/Core/Resource/Factory/CMaterialLoader.cpp +++ b/src/Core/Resource/Factory/CMaterialLoader.cpp @@ -6,9 +6,9 @@ #include CMaterialLoader::CMaterialLoader() + : mCorruptionFlags(0) + , mHasOPAC(false) { - mCorruptionFlags = 0; - mHasOPAC = false; } CMaterialLoader::~CMaterialLoader() @@ -18,29 +18,29 @@ CMaterialLoader::~CMaterialLoader() void CMaterialLoader::ReadPrimeMatSet() { // Textures - u32 numTextures = mpFile->ReadLong(); - mTextures.resize(numTextures); + u32 NumTextures = mpFile->ReadLong(); + mTextures.resize(NumTextures); - for (u32 iTex = 0; iTex < numTextures; iTex++) + for (u32 iTex = 0; iTex < NumTextures; iTex++) { u32 TextureID = mpFile->ReadLong(); mTextures[iTex] = gResCache.GetResource(TextureID, "TXTR"); } // Materials - u32 numMats = mpFile->ReadLong(); - std::vector offsets(numMats); - for (u32 iMat = 0; iMat < numMats; iMat++) - offsets[iMat] = mpFile->ReadLong(); + u32 NumMats = mpFile->ReadLong(); + std::vector Offsets(NumMats); + for (u32 iMat = 0; iMat < NumMats; iMat++) + Offsets[iMat] = mpFile->ReadLong(); - u32 matsStart = mpFile->Tell(); - mpSet->mMaterials.resize(numMats); - for (u32 iMat = 0; iMat < numMats; iMat++) + u32 MatsStart = mpFile->Tell(); + mpSet->mMaterials.resize(NumMats); + for (u32 iMat = 0; iMat < NumMats; iMat++) { mpSet->mMaterials[iMat] = ReadPrimeMaterial(); mpSet->mMaterials[iMat]->mVersion = mVersion; mpSet->mMaterials[iMat]->mName = TString("Material #") + std::to_string(iMat + 1); - mpFile->Seek(matsStart + offsets[iMat], SEEK_SET); + mpFile->Seek(MatsStart + Offsets[iMat], SEEK_SET); } } @@ -87,8 +87,8 @@ CMaterial* CMaterialLoader::ReadPrimeMaterial() } // Blend mode - pMat->mBlendDstFac = glBlendFactor[mpFile->ReadShort()]; - pMat->mBlendSrcFac = glBlendFactor[mpFile->ReadShort()]; + pMat->mBlendDstFac = gBlendFactor[mpFile->ReadShort()]; + pMat->mBlendSrcFac = gBlendFactor[mpFile->ReadShort()]; // Indirect texture if (pMat->mOptions & CMaterial::eIndStage) @@ -308,7 +308,7 @@ CMaterial* CMaterialLoader::ReadCorruptionMaterial() if (ClrType == "DIFB") { - ClrVal.a = 0xFF; + ClrVal.A = 0xFF; pMat->mKonstColors[1] = ClrVal; } @@ -584,9 +584,9 @@ CMaterial* CMaterialLoader::LoadAssimpMaterial(const aiMaterial *pAiMat) // todo: generate new material using import values. CMaterial *pMat = new CMaterial(mVersion, eNoAttributes); - aiString name; - pAiMat->Get(AI_MATKEY_NAME, name); - pMat->SetName(name.C_Str()); + aiString Name; + pAiMat->Get(AI_MATKEY_NAME, Name); + pMat->SetName(Name.C_Str()); // Create generic custom pass that uses Konst color CMaterialPass *pPass = new CMaterialPass(pMat); @@ -602,11 +602,11 @@ CMaterial* CMaterialLoader::LoadAssimpMaterial(const aiMaterial *pAiMat) } // ************ STATIC ************ -CMaterialSet* CMaterialLoader::LoadMaterialSet(IInputStream& Mat, EGame Version) +CMaterialSet* CMaterialLoader::LoadMaterialSet(IInputStream& rMat, EGame Version) { CMaterialLoader Loader; Loader.mpSet = new CMaterialSet(); - Loader.mpFile = &Mat; + Loader.mpFile = &rMat; Loader.mVersion = Version; if ((Version >= ePrimeDemo) && (Version <= eEchoes)) @@ -617,17 +617,17 @@ CMaterialSet* CMaterialLoader::LoadMaterialSet(IInputStream& Mat, EGame Version) return Loader.mpSet; } -CMaterialSet* CMaterialLoader::ImportAssimpMaterials(const aiScene *pScene, EGame targetVersion) +CMaterialSet* CMaterialLoader::ImportAssimpMaterials(const aiScene *pScene, EGame TargetVersion) { - CMaterialLoader loader; - loader.mVersion = targetVersion; + CMaterialLoader Loader; + Loader.mVersion = TargetVersion; CMaterialSet *pOut = new CMaterialSet(); pOut->mMaterials.reserve(pScene->mNumMaterials); for (u32 iMat = 0; iMat < pScene->mNumMaterials; iMat++) { - CMaterial *pMat = loader.LoadAssimpMaterial(pScene->mMaterials[iMat]); + CMaterial *pMat = Loader.LoadAssimpMaterial(pScene->mMaterials[iMat]); pOut->mMaterials.push_back(pMat); } diff --git a/src/Core/Resource/Factory/CMaterialLoader.h b/src/Core/Resource/Factory/CMaterialLoader.h index 26578c23..dde3cd61 100644 --- a/src/Core/Resource/Factory/CMaterialLoader.h +++ b/src/Core/Resource/Factory/CMaterialLoader.h @@ -38,8 +38,8 @@ class CMaterialLoader // Static public: - static CMaterialSet* LoadMaterialSet(IInputStream& Mat, EGame Version); - static CMaterialSet* ImportAssimpMaterials(const aiScene *pScene, EGame targetVersion); + static CMaterialSet* LoadMaterialSet(IInputStream& rMat, EGame Version); + static CMaterialSet* ImportAssimpMaterials(const aiScene *pScene, EGame TargetVersion); }; #endif // CMATERIALLOADER_H diff --git a/src/Core/Resource/Factory/CModelLoader.cpp b/src/Core/Resource/Factory/CModelLoader.cpp index fbbca23d..6784ad8a 100644 --- a/src/Core/Resource/Factory/CModelLoader.cpp +++ b/src/Core/Resource/Factory/CModelLoader.cpp @@ -4,24 +4,24 @@ #include CModelLoader::CModelLoader() + : mFlags(eNoFlags) + , mNumVertices(0) { - mFlags = eNoFlags; - mNumVertices = 0; } CModelLoader::~CModelLoader() { } -void CModelLoader::LoadWorldMeshHeader(IInputStream &Model) +void CModelLoader::LoadWorldMeshHeader(IInputStream& rModel) { // I don't really have any need for most of this data, so - Model.Seek(0x34, SEEK_CUR); - mAABox = CAABox(Model); + rModel.Seek(0x34, SEEK_CUR); + mAABox = CAABox(rModel); mpSectionMgr->ToNextSection(); } -void CModelLoader::LoadAttribArrays(IInputStream& Model) +void CModelLoader::LoadAttribArrays(IInputStream& rModel) { // Positions if (mFlags & eShortPositions) // Shorts (DKCR only) @@ -31,10 +31,10 @@ void CModelLoader::LoadAttribArrays(IInputStream& Model) for (u32 iVtx = 0; iVtx < mPositions.size(); iVtx++) { - float x = Model.ReadShort() / Divisor; - float y = Model.ReadShort() / Divisor; - float z = Model.ReadShort() / Divisor; - mPositions[iVtx] = CVector3f(x, y, z); + float X = rModel.ReadShort() / Divisor; + float Y = rModel.ReadShort() / Divisor; + float Z = rModel.ReadShort() / Divisor; + mPositions[iVtx] = CVector3f(X, Y, Z); } } @@ -43,7 +43,7 @@ void CModelLoader::LoadAttribArrays(IInputStream& Model) mPositions.resize(mpSectionMgr->CurrentSectionSize() / 0xC); for (u32 iVtx = 0; iVtx < mPositions.size(); iVtx++) - mPositions[iVtx] = CVector3f(Model); + mPositions[iVtx] = CVector3f(rModel); } mpSectionMgr->ToNextSection(); @@ -56,10 +56,10 @@ void CModelLoader::LoadAttribArrays(IInputStream& Model) for (u32 iVtx = 0; iVtx < mNormals.size(); iVtx++) { - float x = Model.ReadShort() / Divisor; - float y = Model.ReadShort() / Divisor; - float z = Model.ReadShort() / Divisor; - mNormals[iVtx] = CVector3f(x, y, z); + float X = rModel.ReadShort() / Divisor; + float Y = rModel.ReadShort() / Divisor; + float Z = rModel.ReadShort() / Divisor; + mNormals[iVtx] = CVector3f(X, Y, Z); } } else // Floats @@ -67,7 +67,7 @@ void CModelLoader::LoadAttribArrays(IInputStream& Model) mNormals.resize(mpSectionMgr->CurrentSectionSize() / 0xC); for (u32 iVtx = 0; iVtx < mNormals.size(); iVtx++) - mNormals[iVtx] = CVector3f(Model); + mNormals[iVtx] = CVector3f(rModel); } mpSectionMgr->ToNextSection(); @@ -76,7 +76,7 @@ void CModelLoader::LoadAttribArrays(IInputStream& Model) mColors.resize(mpSectionMgr->CurrentSectionSize() / 4); for (u32 iVtx = 0; iVtx < mColors.size(); iVtx++) - mColors[iVtx] = CColor(Model); + mColors[iVtx] = CColor(rModel); mpSectionMgr->ToNextSection(); @@ -85,7 +85,7 @@ void CModelLoader::LoadAttribArrays(IInputStream& Model) mTex0.resize(mpSectionMgr->CurrentSectionSize() / 0x8); for (u32 iVtx = 0; iVtx < mTex0.size(); iVtx++) - mTex0[iVtx] = CVector2f(Model); + mTex0[iVtx] = CVector2f(rModel); mpSectionMgr->ToNextSection(); @@ -97,48 +97,48 @@ void CModelLoader::LoadAttribArrays(IInputStream& Model) for (u32 iVtx = 0; iVtx < mTex1.size(); iVtx++) { - float x = Model.ReadShort() / Divisor; - float y = Model.ReadShort() / Divisor; - mTex1[iVtx] = CVector2f(x, y); + float X = rModel.ReadShort() / Divisor; + float Y = rModel.ReadShort() / Divisor; + mTex1[iVtx] = CVector2f(X, Y); } mpSectionMgr->ToNextSection(); } } -void CModelLoader::LoadSurfaceOffsets(IInputStream& Model) +void CModelLoader::LoadSurfaceOffsets(IInputStream& rModel) { - mSurfaceCount = Model.ReadLong(); + mSurfaceCount = rModel.ReadLong(); mSurfaceOffsets.resize(mSurfaceCount); for (u32 iSurf = 0; iSurf < mSurfaceCount; iSurf++) - mSurfaceOffsets[iSurf] = Model.ReadLong(); + mSurfaceOffsets[iSurf] = rModel.ReadLong(); mpSectionMgr->ToNextSection(); } -SSurface* CModelLoader::LoadSurface(IInputStream& Model) +SSurface* CModelLoader::LoadSurface(IInputStream& rModel) { SSurface *pSurf = new SSurface; // Surface header if (mVersion < eReturns) - LoadSurfaceHeaderPrime(Model, pSurf); + LoadSurfaceHeaderPrime(rModel, pSurf); else - LoadSurfaceHeaderDKCR(Model, pSurf); + LoadSurfaceHeaderDKCR(rModel, pSurf); bool HasAABB = (pSurf->AABox != CAABox::skInfinite); CMaterial *pMat = mMaterials[0]->MaterialByIndex(pSurf->MaterialID); // Primitive table - u8 Flag = Model.ReadByte(); + u8 Flag = rModel.ReadByte(); u32 NextSurface = mpSectionMgr->NextOffset(); - while ((Flag != 0) && ((u32) Model.Tell() < NextSurface)) + while ((Flag != 0) && ((u32) rModel.Tell() < NextSurface)) { SSurface::SPrimitive Prim; Prim.Type = EGXPrimitiveType(Flag & 0xF8); - u16 VertexCount = Model.ReadShort(); + u16 VertexCount = rModel.ReadShort(); for (u16 iVtx = 0; iVtx < VertexCount; iVtx++) { @@ -146,7 +146,7 @@ SSurface* CModelLoader::LoadSurface(IInputStream& Model) FVertexDescription VtxDesc = pMat->VtxDesc(); for (u32 iMtxAttr = 0; iMtxAttr < 8; iMtxAttr++) - if (VtxDesc & (ePosMtx << iMtxAttr)) Model.Seek(0x1, SEEK_CUR); + if (VtxDesc & (ePosMtx << iMtxAttr)) rModel.Seek(0x1, SEEK_CUR); // Only thing to do here is check whether each attribute is present, and if so, read it. // A couple attributes have special considerations; normals can be floats or shorts, as can tex0, depending on vtxfmt. @@ -155,7 +155,7 @@ SSurface* CModelLoader::LoadSurface(IInputStream& Model) // Position if (VtxDesc & ePosition) { - u16 PosIndex = Model.ReadShort() & 0xFFFF; + u16 PosIndex = rModel.ReadShort() & 0xFFFF; Vtx.Position = mPositions[PosIndex]; Vtx.ArrayPosition = PosIndex; @@ -164,12 +164,12 @@ SSurface* CModelLoader::LoadSurface(IInputStream& Model) // Normal if (VtxDesc & eNormal) - Vtx.Normal = mNormals[Model.ReadShort() & 0xFFFF]; + Vtx.Normal = mNormals[rModel.ReadShort() & 0xFFFF]; // Color - for (u32 c = 0; c < 2; c++) - if (VtxDesc & (eColor0 << (c * 2))) - Vtx.Color[c] = mColors[Model.ReadShort() & 0xFFFF]; + for (u32 iClr = 0; iClr < 2; iClr++) + if (VtxDesc & (eColor0 << (iClr * 2))) + Vtx.Color[iClr] = mColors[rModel.ReadShort() & 0xFFFF]; // Tex Coords - these are done a bit differently in DKCR than in the Prime series if (mVersion < eReturns) @@ -178,15 +178,15 @@ SSurface* CModelLoader::LoadSurface(IInputStream& Model) if (VtxDesc & eTex0) { if ((mFlags & eHasTex1) && (pMat->Options() & CMaterial::eShortTexCoord)) - Vtx.Tex[0] = mTex1[Model.ReadShort() & 0xFFFF]; + Vtx.Tex[0] = mTex1[rModel.ReadShort() & 0xFFFF]; else - Vtx.Tex[0] = mTex0[Model.ReadShort() & 0xFFFF]; + Vtx.Tex[0] = mTex0[rModel.ReadShort() & 0xFFFF]; } // Tex1-7 for (u32 iTex = 1; iTex < 7; iTex++) if (VtxDesc & (eTex0 << (iTex * 2))) - Vtx.Tex[iTex] = mTex0[Model.ReadShort() & 0xFFFF]; + Vtx.Tex[iTex] = mTex0[rModel.ReadShort() & 0xFFFF]; } else @@ -197,9 +197,9 @@ SSurface* CModelLoader::LoadSurface(IInputStream& Model) if (VtxDesc & (eTex0 << iTex * 2)) { if (!mSurfaceUsingTex1) - Vtx.Tex[iTex] = mTex0[Model.ReadShort() & 0xFFFF]; + Vtx.Tex[iTex] = mTex0[rModel.ReadShort() & 0xFFFF]; else - Vtx.Tex[iTex] = mTex1[Model.ReadShort() & 0xFFFF]; + Vtx.Tex[iTex] = mTex1[rModel.ReadShort() & 0xFFFF]; } } } @@ -222,24 +222,24 @@ SSurface* CModelLoader::LoadSurface(IInputStream& Model) } pSurf->Primitives.push_back(Prim); - Flag = Model.ReadByte(); + Flag = rModel.ReadByte(); } // Primitive table end mpSectionMgr->ToNextSection(); return pSurf; } -void CModelLoader::LoadSurfaceHeaderPrime(IInputStream& Model, SSurface *pSurf) +void CModelLoader::LoadSurfaceHeaderPrime(IInputStream& rModel, SSurface *pSurf) { - pSurf->CenterPoint = CVector3f(Model); - pSurf->MaterialID = Model.ReadLong(); + pSurf->CenterPoint = CVector3f(rModel); + pSurf->MaterialID = rModel.ReadLong(); - Model.Seek(0xC, SEEK_CUR); - u32 ExtraSize = Model.ReadLong(); - pSurf->ReflectionDirection = CVector3f(Model); + rModel.Seek(0xC, SEEK_CUR); + u32 ExtraSize = rModel.ReadLong(); + pSurf->ReflectionDirection = CVector3f(rModel); if (mVersion >= eEchoesDemo) - Model.Seek(0x4, SEEK_CUR); // Skipping unknown values + rModel.Seek(0x4, SEEK_CUR); // Skipping unknown values bool HasAABox = (ExtraSize >= 0x18); // MREAs have a set of bounding box coordinates here. @@ -247,54 +247,54 @@ void CModelLoader::LoadSurfaceHeaderPrime(IInputStream& Model, SSurface *pSurf) if (HasAABox) { ExtraSize -= 0x18; - pSurf->AABox = CAABox(Model); + pSurf->AABox = CAABox(rModel); } else pSurf->AABox = CAABox::skInfinite; - Model.Seek(ExtraSize, SEEK_CUR); - Model.SeekToBoundary(32); + rModel.Seek(ExtraSize, SEEK_CUR); + rModel.SeekToBoundary(32); } -void CModelLoader::LoadSurfaceHeaderDKCR(IInputStream& Model, SSurface *pSurf) +void CModelLoader::LoadSurfaceHeaderDKCR(IInputStream& rModel, SSurface *pSurf) { - pSurf->CenterPoint = CVector3f(Model); - Model.Seek(0xE, SEEK_CUR); - pSurf->MaterialID = (u32) Model.ReadShort(); - Model.Seek(0x2, SEEK_CUR); - mSurfaceUsingTex1 = (Model.ReadByte() == 1); - u32 ExtraSize = Model.ReadByte(); + pSurf->CenterPoint = CVector3f(rModel); + rModel.Seek(0xE, SEEK_CUR); + pSurf->MaterialID = (u32) rModel.ReadShort(); + rModel.Seek(0x2, SEEK_CUR); + mSurfaceUsingTex1 = (rModel.ReadByte() == 1); + u32 ExtraSize = rModel.ReadByte(); if (ExtraSize > 0) { ExtraSize -= 0x18; - pSurf->AABox = CAABox(Model); + pSurf->AABox = CAABox(rModel); } else pSurf->AABox = CAABox::skInfinite; - Model.Seek(ExtraSize, SEEK_CUR); - Model.SeekToBoundary(32); + rModel.Seek(ExtraSize, SEEK_CUR); + rModel.SeekToBoundary(32); } -SSurface* CModelLoader::LoadAssimpMesh(const aiMesh *pMesh, CMaterialSet *pSet) +SSurface* CModelLoader::LoadAssimpMesh(const aiMesh *pkMesh, CMaterialSet *pSet) { // Create vertex description and assign it to material - CMaterial *pMat = pSet->MaterialByIndex(pMesh->mMaterialIndex); - FVertexDescription desc = pMat->VtxDesc(); + CMaterial *pMat = pSet->MaterialByIndex(pkMesh->mMaterialIndex); + FVertexDescription Desc = pMat->VtxDesc(); - if (desc == eNoAttributes) + if (Desc == eNoAttributes) { - if (pMesh->HasPositions()) desc |= ePosition; - if (pMesh->HasNormals()) desc |= eNormal; + if (pkMesh->HasPositions()) Desc |= ePosition; + if (pkMesh->HasNormals()) Desc |= eNormal; - for (u32 iUV = 0; iUV < pMesh->GetNumUVChannels(); iUV++) - desc |= (eTex0 << (iUV * 2)); + for (u32 iUV = 0; iUV < pkMesh->GetNumUVChannels(); iUV++) + Desc |= (eTex0 << (iUV * 2)); - pMat->SetVertexDescription(desc); + pMat->SetVertexDescription(Desc); // TEMP - disable dynamic lighting on geometry with no normals - if (!pMesh->HasNormals()) + if (!pkMesh->HasNormals()) { pMat->SetLightingEnabled(false); pMat->Pass(0)->SetColorInputs(eZeroRGB, eOneRGB, eKonstRGB, eZeroRGB); @@ -304,87 +304,90 @@ SSurface* CModelLoader::LoadAssimpMesh(const aiMesh *pMesh, CMaterialSet *pSet) // Create surface SSurface *pSurf = new SSurface(); - pSurf->MaterialID = pMesh->mMaterialIndex; + pSurf->MaterialID = pkMesh->mMaterialIndex; - if (pMesh->mNumFaces > 0) + if (pkMesh->mNumFaces > 0) { pSurf->Primitives.resize(1); - SSurface::SPrimitive& prim = pSurf->Primitives[0]; + SSurface::SPrimitive& rPrim = pSurf->Primitives[0]; // Check primitive type on first face - u32 numIndices = pMesh->mFaces[0].mNumIndices; - if (numIndices == 1) prim.Type = eGX_Points; - else if (numIndices == 2) prim.Type = eGX_Lines; - else if (numIndices == 3) prim.Type = eGX_Triangles; + u32 NumIndices = pkMesh->mFaces[0].mNumIndices; + if (NumIndices == 1) rPrim.Type = eGX_Points; + else if (NumIndices == 2) rPrim.Type = eGX_Lines; + else if (NumIndices == 3) rPrim.Type = eGX_Triangles; // Generate bounding box, center point, and reflection projection pSurf->CenterPoint = CVector3f::skZero; pSurf->ReflectionDirection = CVector3f::skZero; - for (u32 iVtx = 0; iVtx < pMesh->mNumVertices; iVtx++) + for (u32 iVtx = 0; iVtx < pkMesh->mNumVertices; iVtx++) { - aiVector3D aiPos = pMesh->mVertices[iVtx]; - pSurf->AABox.ExpandBounds(CVector3f(aiPos.x, aiPos.y, aiPos.z)); + aiVector3D AiPos = pkMesh->mVertices[iVtx]; + pSurf->AABox.ExpandBounds(CVector3f(AiPos.x, AiPos.y, AiPos.z)); - if (pMesh->HasNormals()) { - aiVector3D aiNrm = pMesh->mNormals[iVtx]; + if (pkMesh->HasNormals()) { + aiVector3D aiNrm = pkMesh->mNormals[iVtx]; pSurf->ReflectionDirection += CVector3f(aiNrm.x, aiNrm.y, aiNrm.z); } } pSurf->CenterPoint = pSurf->AABox.Center(); - if (pMesh->HasNormals()) - pSurf->ReflectionDirection /= (float) pMesh->mNumVertices; + if (pkMesh->HasNormals()) + pSurf->ReflectionDirection /= (float) pkMesh->mNumVertices; else pSurf->ReflectionDirection = CVector3f(1.f, 0.f, 0.f); // Set vertex/triangle count - pSurf->VertexCount = pMesh->mNumVertices; - pSurf->TriangleCount = (prim.Type == eGX_Triangles ? pMesh->mNumFaces : 0); + pSurf->VertexCount = pkMesh->mNumVertices; + pSurf->TriangleCount = (rPrim.Type == eGX_Triangles ? pkMesh->mNumFaces : 0); // Create primitive - for (u32 iFace = 0; iFace < pMesh->mNumFaces; iFace++) + for (u32 iFace = 0; iFace < pkMesh->mNumFaces; iFace++) { - for (u32 iIndex = 0; iIndex < numIndices; iIndex++) + for (u32 iIndex = 0; iIndex < NumIndices; iIndex++) { - u32 index = pMesh->mFaces[iFace].mIndices[iIndex]; + u32 Index = pkMesh->mFaces[iFace].mIndices[iIndex]; // Create vertex and add it to the primitive - CVertex vert; - vert.ArrayPosition = index + mNumVertices; + CVertex Vert; + Vert.ArrayPosition = Index + mNumVertices; - if (pMesh->HasPositions()) { - aiVector3D aiPos = pMesh->mVertices[index]; - vert.Position = CVector3f(aiPos.x, aiPos.y, aiPos.z); + if (pkMesh->HasPositions()) + { + aiVector3D AiPos = pkMesh->mVertices[Index]; + Vert.Position = CVector3f(AiPos.x, AiPos.y, AiPos.z); } - if (pMesh->HasNormals()) { - aiVector3D aiNrm = pMesh->mNormals[index]; - vert.Normal = CVector3f(aiNrm.x, aiNrm.y, aiNrm.z); + if (pkMesh->HasNormals()) + { + aiVector3D AiNrm = pkMesh->mNormals[Index]; + Vert.Normal = CVector3f(AiNrm.x, AiNrm.y, AiNrm.z); } - for (u32 iTex = 0; iTex < pMesh->GetNumUVChannels(); iTex++) { - aiVector3D aiTex = pMesh->mTextureCoords[iTex][index]; - vert.Tex[iTex] = CVector2f(aiTex.x, aiTex.y); + for (u32 iTex = 0; iTex < pkMesh->GetNumUVChannels(); iTex++) + { + aiVector3D AiTex = pkMesh->mTextureCoords[iTex][Index]; + Vert.Tex[iTex] = CVector2f(AiTex.x, AiTex.y); } - prim.Vertices.push_back(vert); + rPrim.Vertices.push_back(Vert); } } - mNumVertices += pMesh->mNumVertices; + mNumVertices += pkMesh->mNumVertices; } return pSurf; } // ************ STATIC ************ -CModel* CModelLoader::LoadCMDL(IInputStream& CMDL) +CModel* CModelLoader::LoadCMDL(IInputStream& rCMDL) { CModelLoader Loader; // CMDL header - same across the three Primes, but different structure in DKCR - u32 Magic = CMDL.ReadLong(); + u32 Magic = rCMDL.ReadLong(); u32 Version, BlockCount, MatSetCount; CAABox AABox; @@ -392,11 +395,11 @@ CModel* CModelLoader::LoadCMDL(IInputStream& CMDL) // 0xDEADBABE - Metroid Prime seres if (Magic == 0xDEADBABE) { - Version = CMDL.ReadLong(); - u32 Flags = CMDL.ReadLong(); - AABox = CAABox(CMDL); - BlockCount = CMDL.ReadLong(); - MatSetCount = CMDL.ReadLong(); + Version = rCMDL.ReadLong(); + u32 Flags = rCMDL.ReadLong(); + AABox = CAABox(rCMDL); + BlockCount = rCMDL.ReadLong(); + MatSetCount = rCMDL.ReadLong(); if (Flags & 0x2) Loader.mFlags |= eShortNormals; if (Flags & 0x4) Loader.mFlags |= eHasTex1; @@ -406,10 +409,10 @@ CModel* CModelLoader::LoadCMDL(IInputStream& CMDL) else if (Magic == 0x9381000A) { Version = Magic & 0xFFFF; - u32 Flags = CMDL.ReadLong(); - AABox = CAABox(CMDL); - BlockCount = CMDL.ReadLong(); - MatSetCount = CMDL.ReadLong(); + u32 Flags = rCMDL.ReadLong(); + AABox = CAABox(rCMDL); + BlockCount = rCMDL.ReadLong(); + MatSetCount = rCMDL.ReadLong(); // todo: unknown flags Loader.mFlags = eShortNormals | eHasTex1; @@ -420,22 +423,22 @@ CModel* CModelLoader::LoadCMDL(IInputStream& CMDL) // Skipping for now - should read in eventually if (Flags & 0x10) { - CMDL.Seek(0x4, SEEK_CUR); - u32 VisGroupCount = CMDL.ReadLong(); + rCMDL.Seek(0x4, SEEK_CUR); + u32 VisGroupCount = rCMDL.ReadLong(); for (u32 iVis = 0; iVis < VisGroupCount; iVis++) { - u32 NameLength = CMDL.ReadLong(); - CMDL.Seek(NameLength, SEEK_CUR); + u32 NameLength = rCMDL.ReadLong(); + rCMDL.Seek(NameLength, SEEK_CUR); } - CMDL.Seek(0x14, SEEK_CUR); // no clue what any of this is! + rCMDL.Seek(0x14, SEEK_CUR); // no clue what any of this is! } } else { - Log::FileError(CMDL.GetSourceString(), "Invalid CMDL magic: " + TString::HexString(Magic)); + Log::FileError(rCMDL.GetSourceString(), "Invalid CMDL magic: " + TString::HexString(Magic)); return nullptr; } @@ -444,21 +447,21 @@ CModel* CModelLoader::LoadCMDL(IInputStream& CMDL) if (Loader.mVersion == eUnknownVersion) { - Log::FileError(CMDL.GetSourceString(), "Unsupported CMDL version: " + TString::HexString(Magic)); + Log::FileError(rCMDL.GetSourceString(), "Unsupported CMDL version: " + TString::HexString(Magic, 0)); return nullptr; } CModel *pModel = new CModel(); Loader.mpModel = pModel; - Loader.mpSectionMgr = new CSectionMgrIn(BlockCount, &CMDL); - CMDL.SeekToBoundary(32); + Loader.mpSectionMgr = new CSectionMgrIn(BlockCount, &rCMDL); + rCMDL.SeekToBoundary(32); Loader.mpSectionMgr->Init(); // Materials Loader.mMaterials.resize(MatSetCount); for (u32 iMat = 0; iMat < MatSetCount; iMat++) { - Loader.mMaterials[iMat] = CMaterialLoader::LoadMaterialSet(CMDL, Loader.mVersion); + Loader.mMaterials[iMat] = CMaterialLoader::LoadMaterialSet(rCMDL, Loader.mVersion); if (Loader.mVersion < eCorruptionProto) Loader.mpSectionMgr->ToNextSection(); @@ -469,13 +472,13 @@ CModel* CModelLoader::LoadCMDL(IInputStream& CMDL) if (Loader.mVersion >= eCorruptionProto) Loader.mpSectionMgr->ToNextSection(); // Mesh - Loader.LoadAttribArrays(CMDL); - Loader.LoadSurfaceOffsets(CMDL); + Loader.LoadAttribArrays(rCMDL); + Loader.LoadSurfaceOffsets(rCMDL); pModel->mSurfaces.reserve(Loader.mSurfaceCount); for (u32 iSurf = 0; iSurf < Loader.mSurfaceCount; iSurf++) { - SSurface *pSurf = Loader.LoadSurface(CMDL); + SSurface *pSurf = Loader.LoadSurface(rCMDL); pModel->mSurfaces.push_back(pSurf); pModel->mVertexCount += pSurf->VertexCount; pModel->mTriangleCount += pSurf->TriangleCount; @@ -489,30 +492,30 @@ CModel* CModelLoader::LoadCMDL(IInputStream& CMDL) return pModel; } -CModel* CModelLoader::LoadWorldModel(IInputStream& MREA, CSectionMgrIn& BlockMgr, CMaterialSet& MatSet, EGame Version) +CModel* CModelLoader::LoadWorldModel(IInputStream& rMREA, CSectionMgrIn& rBlockMgr, CMaterialSet& rMatSet, EGame Version) { CModelLoader Loader; - Loader.mpSectionMgr = &BlockMgr; + Loader.mpSectionMgr = &rBlockMgr; Loader.mVersion = Version; Loader.mFlags = eShortNormals; if (Version != eCorruptionProto) Loader.mFlags |= eHasTex1; Loader.mMaterials.resize(1); - Loader.mMaterials[0] = &MatSet; + Loader.mMaterials[0] = &rMatSet; - Loader.LoadWorldMeshHeader(MREA); - Loader.LoadAttribArrays(MREA); - Loader.LoadSurfaceOffsets(MREA); + Loader.LoadWorldMeshHeader(rMREA); + Loader.LoadAttribArrays(rMREA); + Loader.LoadSurfaceOffsets(rMREA); CModel *pModel = new CModel(); pModel->mMaterialSets.resize(1); - pModel->mMaterialSets[0] = &MatSet; + pModel->mMaterialSets[0] = &rMatSet; pModel->mHasOwnMaterials = false; pModel->mSurfaces.reserve(Loader.mSurfaceCount); pModel->mHasOwnSurfaces = true; for (u32 iSurf = 0; iSurf < Loader.mSurfaceCount; iSurf++) { - SSurface *pSurf = Loader.LoadSurface(MREA); + SSurface *pSurf = Loader.LoadSurface(rMREA); pModel->mSurfaces.push_back(pSurf); pModel->mVertexCount += pSurf->VertexCount; pModel->mTriangleCount += pSurf->TriangleCount; @@ -522,33 +525,33 @@ CModel* CModelLoader::LoadWorldModel(IInputStream& MREA, CSectionMgrIn& BlockMgr return pModel; } -CModel* CModelLoader::LoadCorruptionWorldModel(IInputStream &MREA, CSectionMgrIn &BlockMgr, CMaterialSet &MatSet, u32 HeaderSecNum, u32 GPUSecNum, EGame Version) +CModel* CModelLoader::LoadCorruptionWorldModel(IInputStream& rMREA, CSectionMgrIn& rBlockMgr, CMaterialSet& rMatSet, u32 HeaderSecNum, u32 GPUSecNum, EGame Version) { CModelLoader Loader; - Loader.mpSectionMgr = &BlockMgr; + Loader.mpSectionMgr = &rBlockMgr; Loader.mVersion = Version; Loader.mFlags = eShortNormals; Loader.mMaterials.resize(1); - Loader.mMaterials[0] = &MatSet; + Loader.mMaterials[0] = &rMatSet; if (Version == eReturns) Loader.mFlags |= eHasTex1; // Corruption/DKCR MREAs split the mesh header and surface offsets away from the actual geometry data so I need two section numbers to read it - BlockMgr.ToSection(HeaderSecNum); - Loader.LoadWorldMeshHeader(MREA); - Loader.LoadSurfaceOffsets(MREA); - BlockMgr.ToSection(GPUSecNum); - Loader.LoadAttribArrays(MREA); + rBlockMgr.ToSection(HeaderSecNum); + Loader.LoadWorldMeshHeader(rMREA); + Loader.LoadSurfaceOffsets(rMREA); + rBlockMgr.ToSection(GPUSecNum); + Loader.LoadAttribArrays(rMREA); CModel *pModel = new CModel(); pModel->mMaterialSets.resize(1); - pModel->mMaterialSets[0] = &MatSet; + pModel->mMaterialSets[0] = &rMatSet; pModel->mHasOwnMaterials = false; pModel->mSurfaces.reserve(Loader.mSurfaceCount); pModel->mHasOwnSurfaces = true; for (u32 iSurf = 0; iSurf < Loader.mSurfaceCount; iSurf++) { - SSurface *pSurf = Loader.LoadSurface(MREA); + SSurface *pSurf = Loader.LoadSurface(rMREA); pModel->mSurfaces.push_back(pSurf); pModel->mVertexCount += pSurf->VertexCount; pModel->mTriangleCount += pSurf->TriangleCount; @@ -609,25 +612,25 @@ void CModelLoader::BuildWorldMeshes(const std::vector& rkIn, std::vecto } } -CModel* CModelLoader::ImportAssimpNode(const aiNode *pNode, const aiScene *pScene, CMaterialSet& matSet) +CModel* CModelLoader::ImportAssimpNode(const aiNode *pkNode, const aiScene *pkScene, CMaterialSet& rMatSet) { - CModelLoader loader; - loader.mpModel = new CModel(&matSet, true); - loader.mpModel->mSurfaces.reserve(pNode->mNumMeshes); + CModelLoader Loader; + Loader.mpModel = new CModel(&rMatSet, true); + Loader.mpModel->mSurfaces.reserve(pkNode->mNumMeshes); - for (u32 iMesh = 0; iMesh < pNode->mNumMeshes; iMesh++) + for (u32 iMesh = 0; iMesh < pkNode->mNumMeshes; iMesh++) { - u32 meshIndex = pNode->mMeshes[iMesh]; - const aiMesh *pMesh = pScene->mMeshes[meshIndex]; - SSurface *pSurf = loader.LoadAssimpMesh(pMesh, &matSet); + u32 MeshIndex = pkNode->mMeshes[iMesh]; + const aiMesh *pkMesh = pkScene->mMeshes[MeshIndex]; + SSurface *pSurf = Loader.LoadAssimpMesh(pkMesh, &rMatSet); - loader.mpModel->mSurfaces.push_back(pSurf); - loader.mpModel->mAABox.ExpandBounds(pSurf->AABox); - loader.mpModel->mVertexCount += pSurf->VertexCount; - loader.mpModel->mTriangleCount += pSurf->TriangleCount; + Loader.mpModel->mSurfaces.push_back(pSurf); + Loader.mpModel->mAABox.ExpandBounds(pSurf->AABox); + Loader.mpModel->mVertexCount += pSurf->VertexCount; + Loader.mpModel->mTriangleCount += pSurf->TriangleCount; } - return loader.mpModel; + return Loader.mpModel; } EGame CModelLoader::GetFormatVersion(u32 Version) diff --git a/src/Core/Resource/Factory/CModelLoader.h b/src/Core/Resource/Factory/CModelLoader.h index b9fea32c..2bf75319 100644 --- a/src/Core/Resource/Factory/CModelLoader.h +++ b/src/Core/Resource/Factory/CModelLoader.h @@ -46,21 +46,21 @@ private: CModelLoader(); ~CModelLoader(); - void LoadWorldMeshHeader(IInputStream& Model); - void LoadAttribArrays(IInputStream& Model); - void LoadAttribArraysDKCR(IInputStream& Model); - void LoadSurfaceOffsets(IInputStream& Model); - SSurface* LoadSurface(IInputStream& Model); - void LoadSurfaceHeaderPrime(IInputStream& Model, SSurface *pSurf); - void LoadSurfaceHeaderDKCR(IInputStream& Model, SSurface *pSurf); - SSurface* LoadAssimpMesh(const aiMesh *pMesh, CMaterialSet *pSet); + void LoadWorldMeshHeader(IInputStream& rModel); + void LoadAttribArrays(IInputStream& rModel); + void LoadAttribArraysDKCR(IInputStream& rModel); + void LoadSurfaceOffsets(IInputStream& rModel); + SSurface* LoadSurface(IInputStream& rModel); + void LoadSurfaceHeaderPrime(IInputStream& rModel, SSurface *pSurf); + void LoadSurfaceHeaderDKCR(IInputStream& rModel, SSurface *pSurf); + SSurface* LoadAssimpMesh(const aiMesh *pkMesh, CMaterialSet *pSet); public: - static CModel* LoadCMDL(IInputStream& CMDL); - static CModel* LoadWorldModel(IInputStream& MREA, CSectionMgrIn& BlockMgr, CMaterialSet& MatSet, EGame Version); - static CModel* LoadCorruptionWorldModel(IInputStream& MREA, CSectionMgrIn& BlockMgr, CMaterialSet& MatSet, u32 HeaderSecNum, u32 GPUSecNum, EGame Version); + static CModel* LoadCMDL(IInputStream& rCMDL); + static CModel* LoadWorldModel(IInputStream& rMREA, CSectionMgrIn& rBlockMgr, CMaterialSet& rMatSet, EGame Version); + static CModel* LoadCorruptionWorldModel(IInputStream& rMREA, CSectionMgrIn& rBlockMgr, CMaterialSet& rMatSet, u32 HeaderSecNum, u32 GPUSecNum, EGame Version); static void BuildWorldMeshes(const std::vector& rkIn, std::vector& rOut, bool DeleteInputModels); - static CModel* ImportAssimpNode(const aiNode *pNode, const aiScene *pScene, CMaterialSet& matSet); + static CModel* ImportAssimpNode(const aiNode *pkNode, const aiScene *pkScene, CMaterialSet& rMatSet); static EGame GetFormatVersion(u32 Version); }; diff --git a/src/Core/Resource/Factory/CScanLoader.cpp b/src/Core/Resource/Factory/CScanLoader.cpp index 5bb4d066..c7462e6a 100644 --- a/src/Core/Resource/Factory/CScanLoader.cpp +++ b/src/Core/Resource/Factory/CScanLoader.cpp @@ -6,132 +6,132 @@ CScanLoader::CScanLoader() { } -CScan* CScanLoader::LoadScanMP1(IInputStream &SCAN) +CScan* CScanLoader::LoadScanMP1(IInputStream& rSCAN) { // Basic support at the moment - don't read animation/scan image data - SCAN.Seek(0x4, SEEK_CUR); // Skip FRME ID - mpScan->mpStringTable = gResCache.GetResource(SCAN.ReadLong(), "STRG"); - mpScan->mIsSlow = (SCAN.ReadLong() != 0); - mpScan->mCategory = (CScan::ELogbookCategory) SCAN.ReadLong(); - mpScan->mIsImportant = (SCAN.ReadByte() == 1); + rSCAN.Seek(0x4, SEEK_CUR); // Skip FRME ID + mpScan->mpStringTable = gResCache.GetResource(rSCAN.ReadLong(), "STRG"); + mpScan->mIsSlow = (rSCAN.ReadLong() != 0); + mpScan->mCategory = (CScan::ELogbookCategory) rSCAN.ReadLong(); + mpScan->mIsImportant = (rSCAN.ReadByte() == 1); mpScan->mVersion = ePrime; return mpScan; } -CScan* CScanLoader::LoadScanMP2(IInputStream& SCAN) +CScan* CScanLoader::LoadScanMP2(IInputStream& rSCAN) { // The SCAN format in MP2 embeds a SNFO object using the same format as SCLY // However since the contents of the file are consistent there's no need to delegate to CScriptLoader - SCAN.Seek(0x1, SEEK_CUR); - u32 NumInstances = SCAN.ReadLong(); + rSCAN.Seek(0x1, SEEK_CUR); + u32 NumInstances = rSCAN.ReadLong(); if (NumInstances != 1) { - Log::FileError(SCAN.GetSourceString(), "SCAN has multiple instances"); + Log::FileError(rSCAN.GetSourceString(), "SCAN has multiple instances"); return nullptr; } - u32 ScanInfoStart = SCAN.Tell(); + u32 ScanInfoStart = rSCAN.Tell(); - CFourCC SNFO(SCAN); + CFourCC SNFO(rSCAN); if (SNFO != "SNFO") { - Log::FileError(SCAN.GetSourceString(), ScanInfoStart, "Unrecognized SCAN object type: " + SNFO.ToString()); + Log::FileError(rSCAN.GetSourceString(), ScanInfoStart, "Unrecognized SCAN object type: " + SNFO.ToString()); return nullptr; } - SCAN.Seek(0x6, SEEK_CUR); - u16 NumConnections = SCAN.ReadShort(); + rSCAN.Seek(0x6, SEEK_CUR); + u16 NumConnections = rSCAN.ReadShort(); if (NumConnections > 0) { - Log::FileWarning(SCAN.GetSourceString(), ScanInfoStart, "SNFO object in SCAN has connections"); - SCAN.Seek(NumConnections * 0xC, SEEK_CUR); + Log::FileWarning(rSCAN.GetSourceString(), ScanInfoStart, "SNFO object in SCAN has connections"); + rSCAN.Seek(NumConnections * 0xC, SEEK_CUR); } - u32 BasePropID = SCAN.ReadLong(); + u32 BasePropID = rSCAN.ReadLong(); if (BasePropID != 0xFFFFFFFF) { - Log::FileError(SCAN.GetSourceString(), SCAN.Tell() - 4, "Invalid base proprty ID: " + TString::HexString(BasePropID)); + Log::FileError(rSCAN.GetSourceString(), rSCAN.Tell() - 4, "Invalid base property ID: " + TString::HexString(BasePropID)); return nullptr; } - SCAN.Seek(0x2, SEEK_CUR); - u16 NumProperties = SCAN.ReadShort(); + rSCAN.Seek(0x2, SEEK_CUR); + u16 NumProperties = rSCAN.ReadShort(); switch (NumProperties) { case 0x14: case 0xB: mpScan = new CScan(); - LoadParamsMP2(SCAN); + LoadParamsMP2(rSCAN); break; case 0x12: case 0x16: mpScan = new CScan(); - LoadParamsMP3(SCAN); + LoadParamsMP3(rSCAN); break; default: - Log::FileError(SCAN.GetSourceString(), SCAN.Tell() - 2, "Invalid SNFO property count: " + TString::HexString(NumProperties)); + Log::FileError(rSCAN.GetSourceString(), rSCAN.Tell() - 2, "Invalid SNFO property count: " + TString::HexString(NumProperties)); return nullptr; } return mpScan; } -void CScanLoader::LoadParamsMP2(IInputStream& SCAN) +void CScanLoader::LoadParamsMP2(IInputStream& rSCAN) { // Function begins after the SNFO property count for (u32 iProp = 0; iProp < 20; iProp++) { - u32 PropertyID = SCAN.ReadLong(); - u16 PropertySize = SCAN.ReadShort(); - u32 Next = SCAN.Tell() + PropertySize; + u32 PropertyID = rSCAN.ReadLong(); + u16 PropertySize = rSCAN.ReadShort(); + u32 Next = rSCAN.Tell() + PropertySize; switch (PropertyID) { case 0x2F5B6423: - mpScan->mpStringTable = gResCache.GetResource(SCAN.ReadLong(), "STRG"); + mpScan->mpStringTable = gResCache.GetResource(rSCAN.ReadLong(), "STRG"); break; case 0xC308A322: - mpScan->mIsSlow = (SCAN.ReadLong() != 0); + mpScan->mIsSlow = (rSCAN.ReadLong() != 0); break; case 0x7B714814: - mpScan->mIsImportant = (SCAN.ReadByte() != 0); + mpScan->mIsImportant = (rSCAN.ReadByte() != 0); break; } - SCAN.Seek(Next, SEEK_SET); + rSCAN.Seek(Next, SEEK_SET); } mpScan->mCategory = CScan::eNone; mpScan->mVersion = eEchoes; } -void CScanLoader::LoadParamsMP3(IInputStream& SCAN) +void CScanLoader::LoadParamsMP3(IInputStream& rSCAN) { // Function begins after the SNFO property count // Function is near-identical to the MP2 one, but when I add support // for the other params, there will be more differences for (u32 iProp = 0; iProp < 20; iProp++) { - u32 PropertyID = SCAN.ReadLong(); - u16 PropertySize = SCAN.ReadShort(); - u32 Next = SCAN.Tell() + PropertySize; + u32 PropertyID = rSCAN.ReadLong(); + u16 PropertySize = rSCAN.ReadShort(); + u32 Next = rSCAN.Tell() + PropertySize; switch (PropertyID) { case 0x2F5B6423: - mpScan->mpStringTable = gResCache.GetResource(SCAN.ReadLongLong(), "STRG"); + mpScan->mpStringTable = gResCache.GetResource(rSCAN.ReadLongLong(), "STRG"); break; case 0xC308A322: - mpScan->mIsSlow = (SCAN.ReadLong() != 0); + mpScan->mIsSlow = (rSCAN.ReadLong() != 0); break; case 0x7B714814: - mpScan->mIsImportant = (SCAN.ReadByte() != 0); + mpScan->mIsImportant = (rSCAN.ReadByte() != 0); break; } - SCAN.Seek(Next, SEEK_SET); + rSCAN.Seek(Next, SEEK_SET); } mpScan->mCategory = CScan::eNone; @@ -139,43 +139,43 @@ void CScanLoader::LoadParamsMP3(IInputStream& SCAN) } // ************ STATIC/PUBLIC ************ -CScan* CScanLoader::LoadSCAN(IInputStream &SCAN) +CScan* CScanLoader::LoadSCAN(IInputStream& rSCAN) { - if (!SCAN.IsValid()) return nullptr; + if (!rSCAN.IsValid()) return nullptr; /* Switching to EGame enum here isn't really useful unfortunately * because the MP1 demo can be 1, 2, or 3, while MP1 is 5 and MP2+ is 2 * MP1 is the only one that starts with 5 so that is a consistent check for now * Better version checks will be implemented when the other versions are * better-understood. */ - u32 fileVersion = SCAN.ReadLong(); - u32 magic = SCAN.ReadLong(); + u32 FileVersion = rSCAN.ReadLong(); + u32 Magic = rSCAN.ReadLong(); // Echoes+ - if (CFourCC(fileVersion) == "SCAN") + if (CFourCC(FileVersion) == "SCAN") { // The MP2 load function will check for MP3 - CScanLoader loader; - loader.mVersion = eEchoes; - if (magic == 0x01000000) SCAN.Seek(-4, SEEK_CUR); // The version number isn't present in the Echoes demo - return loader.LoadScanMP2(SCAN); + CScanLoader Loader; + Loader.mVersion = eEchoes; + if (Magic == 0x01000000) rSCAN.Seek(-4, SEEK_CUR); // The version number isn't present in the Echoes demo + return Loader.LoadScanMP2(rSCAN); } - if (magic != 0x0BADBEEF) + if (Magic != 0x0BADBEEF) { - Log::FileError(SCAN.GetSourceString(), "Invalid SCAN magic: " + TString::HexString(magic)); + Log::FileError(rSCAN.GetSourceString(), "Invalid SCAN magic: " + TString::HexString(Magic)); return nullptr; } - if (fileVersion != 5) + if (FileVersion != 5) { - Log::FileError(SCAN.GetSourceString(), "Unsupported SCAN version: " + TString::HexString(fileVersion)); + Log::FileError(rSCAN.GetSourceString(), "Unsupported SCAN version: " + TString::HexString(FileVersion, 0)); return nullptr; } // MP1 SCAN - read the file! - CScanLoader loader; - loader.mVersion = ePrime; - loader.mpScan = new CScan(); - return loader.LoadScanMP1(SCAN); + CScanLoader Loader; + Loader.mVersion = ePrime; + Loader.mpScan = new CScan(); + return Loader.LoadScanMP1(rSCAN); } diff --git a/src/Core/Resource/Factory/CScanLoader.h b/src/Core/Resource/Factory/CScanLoader.h index beb27578..19b343a5 100644 --- a/src/Core/Resource/Factory/CScanLoader.h +++ b/src/Core/Resource/Factory/CScanLoader.h @@ -10,13 +10,13 @@ class CScanLoader EGame mVersion; CScanLoader(); - CScan* LoadScanMP1(IInputStream& SCAN); - CScan* LoadScanMP2(IInputStream& SCAN); - void LoadParamsMP2(IInputStream& SCAN); - void LoadParamsMP3(IInputStream& SCAN); + CScan* LoadScanMP1(IInputStream& rSCAN); + CScan* LoadScanMP2(IInputStream& rSCAN); + void LoadParamsMP2(IInputStream& rSCAN); + void LoadParamsMP3(IInputStream& rSCAN); public: - static CScan* LoadSCAN(IInputStream& SCAN); + static CScan* LoadSCAN(IInputStream& rSCAN); }; #endif // CSCANLOADER_H diff --git a/src/Core/Resource/Factory/CScriptLoader.cpp b/src/Core/Resource/Factory/CScriptLoader.cpp index 3955af97..3709e8de 100644 --- a/src/Core/Resource/Factory/CScriptLoader.cpp +++ b/src/Core/Resource/Factory/CScriptLoader.cpp @@ -7,8 +7,8 @@ #include CScriptLoader::CScriptLoader() + : mpObj(nullptr) { - mpObj = nullptr; } void CScriptLoader::ReadProperty(IProperty *pProp, u32 Size, IInputStream& rSCLY) @@ -18,85 +18,96 @@ void CScriptLoader::ReadProperty(IProperty *pProp, u32 Size, IInputStream& rSCLY switch (pTemp->Type()) { - case eBoolProperty: { + case eBoolProperty: + { TBoolProperty *pBoolCast = static_cast(pProp); pBoolCast->Set( (rSCLY.ReadByte() != 0) ); break; } - case eByteProperty: { + case eByteProperty: + { TByteProperty *pByteCast = static_cast(pProp); pByteCast->Set(rSCLY.ReadByte()); break; } - case eShortProperty: { + case eShortProperty: + { TShortProperty *pShortCast = static_cast(pProp); pShortCast->Set(rSCLY.ReadShort()); break; } - case eLongProperty: { + case eLongProperty: + { TLongProperty *pLongCast = static_cast(pProp); pLongCast->Set(rSCLY.ReadLong()); break; } - case eBitfieldProperty: { + case eBitfieldProperty: + { TBitfieldProperty *pBitfieldCast = static_cast(pProp); pBitfieldCast->Set(rSCLY.ReadLong()); // Validate - u32 mask = 0; + u32 Mask = 0; CBitfieldTemplate *pBitfieldTemp = static_cast(pTemp); for (u32 iMask = 0; iMask < pBitfieldTemp->NumFlags(); iMask++) - mask |= pBitfieldTemp->FlagMask(iMask); + Mask |= pBitfieldTemp->FlagMask(iMask); - u32 check = pBitfieldCast->Get() & ~mask; - if (check != 0) - Log::FileWarning(rSCLY.GetSourceString(), rSCLY.Tell() - 4, "Bitfield property \"" + pBitfieldTemp->Name() + "\" in struct \"" + pTemp->Name() + "\" has flags set that aren't in the template: " + TString::HexString(check, true, true, 8)); + u32 Check = pBitfieldCast->Get() & ~Mask; + if (Check != 0) + Log::FileWarning(rSCLY.GetSourceString(), rSCLY.Tell() - 4, "Bitfield property \"" + pBitfieldTemp->Name() + "\" in struct \"" + pTemp->Name() + "\" has flags set that aren't in the template: " + TString::HexString(Check)); break; } - case eEnumProperty: { + case eEnumProperty: + { TEnumProperty *pEnumCast = static_cast(pProp); CEnumTemplate *pEnumTemp = static_cast(pTemp); u32 ID = rSCLY.ReadLong(); // Validate u32 Index = pEnumTemp->EnumeratorIndex(ID); - if (Index == -1) Log::FileError(rSCLY.GetSourceString(), rSCLY.Tell() - 4, "Enum property \"" + pEnumTemp->Name() + "\" in struct \"" + pTemp->Name() + "\" has invalid enumerator value: " + TString::HexString(ID, true, true, 8)); + if (Index == -1) Log::FileError(rSCLY.GetSourceString(), rSCLY.Tell() - 4, "Enum property \"" + pEnumTemp->Name() + "\" in struct \"" + pTemp->Name() + "\" has invalid enumerator value: " + TString::HexString(ID)); pEnumCast->Set(ID); break; } - case eFloatProperty: { + case eFloatProperty: + { TFloatProperty *pFloatCast = static_cast(pProp); pFloatCast->Set(rSCLY.ReadFloat()); break; } - case eStringProperty: { + case eStringProperty: + { TStringProperty *pStringCast = static_cast(pProp); pStringCast->Set(rSCLY.ReadString()); break; } - case eVector3Property: { + case eVector3Property: + { TVector3Property *pVector3Cast = static_cast(pProp); pVector3Cast->Set(CVector3f(rSCLY)); break; } - case eColorProperty: { + case eColorProperty: + { TColorProperty *pColorCast = static_cast(pProp); pColorCast->Set(CColor(rSCLY)); break; } - case eFileProperty: { + case eFileProperty: + { TFileProperty *pFileCast = static_cast(pProp); CUniqueID ResID = (mVersion < eCorruptionProto ? rSCLY.ReadLong() : rSCLY.ReadLongLong()); @@ -114,7 +125,8 @@ void CScriptLoader::ReadProperty(IProperty *pProp, u32 Size, IInputStream& rSCLY break; } - case eStructProperty: { + case eStructProperty: + { CPropertyStruct *pStructCast = static_cast(pProp); if (mVersion < eEchoesDemo) @@ -124,7 +136,8 @@ void CScriptLoader::ReadProperty(IProperty *pProp, u32 Size, IInputStream& rSCLY break; } - case eArrayProperty: { + case eArrayProperty: + { CArrayProperty *pArrayCast = static_cast(pProp); int Count = rSCLY.ReadLong(); @@ -140,13 +153,15 @@ void CScriptLoader::ReadProperty(IProperty *pProp, u32 Size, IInputStream& rSCLY break; } - case eCharacterProperty: { + case eCharacterProperty: + { TCharacterProperty *pAnimCast = static_cast(pProp); - pAnimCast->Set(CAnimationParameters(rSCLY, mpMaster->GetGame())); + pAnimCast->Set(CAnimationParameters(rSCLY, mpMaster->Game())); break; } - case eMayaSplineProperty: { + case eMayaSplineProperty: + { TMayaSplineProperty *pSplineCast = static_cast(pProp); std::vector Buffer(Size); rSCLY.ReadBytes(Buffer.data(), Buffer.size()); @@ -154,7 +169,8 @@ void CScriptLoader::ReadProperty(IProperty *pProp, u32 Size, IInputStream& rSCLY break; } - case eUnknownProperty: { + case eUnknownProperty: + { TUnknownProperty *pUnknownCast = static_cast(pProp); std::vector Buffer(Size); rSCLY.ReadBytes(Buffer.data(), Buffer.size()); @@ -182,7 +198,7 @@ void CScriptLoader::LoadStructMP1(IInputStream& rSCLY, CPropertyStruct *pStruct, TIDString IDString = pTemp->IDString(true); if (!IDString.IsEmpty()) IDString = " (" + IDString + ")"; - Log::FileWarning(rSCLY.GetSourceString(), StructStart, "Struct \"" + pTemp->Name() + "\"" + IDString + " template prop count doesn't match file; template is " + TString::HexString(PropCount, true, true, 2) + ", file is " + TString::HexString(FilePropCount, true, true, 2)); + Log::FileWarning(rSCLY.GetSourceString(), StructStart, "Struct \"" + pTemp->Name() + "\"" + IDString + " template prop count doesn't match file; template is " + TString::HexString(PropCount, 2) + ", file is " + TString::HexString(FilePropCount, 2)); Version = 0; } } @@ -209,7 +225,7 @@ CScriptObject* CScriptLoader::LoadObjectMP1(IInputStream& rSCLY) if (!pTemp) { // No valid template for this object; can't load - Log::FileError(rSCLY.GetSourceString(), ObjStart, "Unknown object ID encountered: " + TString::HexString(Type)); + Log::FileError(rSCLY.GetSourceString(), ObjStart, "Unknown object ID encountered: " + TString::HexString(Type, 2)); rSCLY.Seek(End, SEEK_SET); return nullptr; } @@ -381,7 +397,7 @@ CScriptLayer* CScriptLoader::LoadLayer(IInputStream& rSCLY, CGameArea *pArea, EG CScriptLoader Loader; Loader.mVersion = Version; - Loader.mpMaster = CMasterTemplate::GetMasterForGame(Version); + Loader.mpMaster = CMasterTemplate::MasterForGame(Version); Loader.mpArea = pArea; if (!Loader.mpMaster) @@ -405,7 +421,7 @@ CScriptObject* CScriptLoader::LoadInstance(IInputStream& rSCLY, CGameArea *pArea CScriptLoader Loader; Loader.mVersion = (ForceReturnsFormat ? eReturns : Version); - Loader.mpMaster = CMasterTemplate::GetMasterForGame(Version); + Loader.mpMaster = CMasterTemplate::MasterForGame(Version); Loader.mpArea = pArea; Loader.mpLayer = pLayer; diff --git a/src/Core/Resource/Factory/CScriptLoader.h b/src/Core/Resource/Factory/CScriptLoader.h index adc43e3c..5170ee54 100644 --- a/src/Core/Resource/Factory/CScriptLoader.h +++ b/src/Core/Resource/Factory/CScriptLoader.h @@ -28,7 +28,7 @@ class CScriptLoader public: static CScriptLayer* LoadLayer(IInputStream& rSCLY, CGameArea *pArea, EGame Version); - static CScriptObject* LoadInstance(IInputStream& rSCLY, CGameArea *pArea, CScriptLayer *pLayer,EGame Version, bool ForceReturnsFormat); + static CScriptObject* LoadInstance(IInputStream& rSCLY, CGameArea *pArea, CScriptLayer *pLayer, EGame Version, bool ForceReturnsFormat); }; #endif // CSCRIPTLOADER_H diff --git a/src/Core/Resource/Factory/CSectionMgrIn.h b/src/Core/Resource/Factory/CSectionMgrIn.h index b52cb774..87575e78 100644 --- a/src/Core/Resource/Factory/CSectionMgrIn.h +++ b/src/Core/Resource/Factory/CSectionMgrIn.h @@ -50,11 +50,11 @@ public: mCurSec++; } - inline u32 NextOffset() { return mCurSecStart + mSectionSizes[mCurSec]; } - inline u32 CurrentSection() { return mCurSec; } - inline u32 CurrentSectionSize() { return mSectionSizes[mCurSec]; } - inline u32 NumSections() { return mSectionSizes.size(); } - inline void SetInputStream(IInputStream *pIn) { mpInputStream = pIn; } + inline u32 NextOffset() { return mCurSecStart + mSectionSizes[mCurSec]; } + inline u32 CurrentSection() { return mCurSec; } + inline u32 CurrentSectionSize() { return mSectionSizes[mCurSec]; } + inline u32 NumSections() { return mSectionSizes.size(); } + inline void SetInputStream(IInputStream *pIn) { mpInputStream = pIn; } }; #endif // CSECTIONMGRIN_H diff --git a/src/Core/Resource/Factory/CStringLoader.cpp b/src/Core/Resource/Factory/CStringLoader.cpp index 0afd3566..19a8f1dd 100644 --- a/src/Core/Resource/Factory/CStringLoader.cpp +++ b/src/Core/Resource/Factory/CStringLoader.cpp @@ -5,39 +5,39 @@ CStringLoader::CStringLoader() { } -void CStringLoader::LoadPrimeDemoSTRG(IInputStream& STRG) +void CStringLoader::LoadPrimeDemoSTRG(IInputStream& rSTRG) { // This function starts at 0x4 in the file - right after the size // This STRG version only supports one language per file mpStringTable->mLangTables.resize(1); CStringTable::SLangTable* Lang = &mpStringTable->mLangTables[1]; Lang->Language = "ENGL"; - u32 TableStart = STRG.Tell(); + u32 TableStart = rSTRG.Tell(); // Header - u32 NumStrings = STRG.ReadLong(); + u32 NumStrings = rSTRG.ReadLong(); Lang->Strings.resize(NumStrings); mpStringTable->mNumStrings = NumStrings; // String offsets (yeah, that wasn't much of a header) std::vector StringOffsets(NumStrings); for (u32 iOff = 0; iOff < StringOffsets.size(); iOff++) - StringOffsets[iOff] = STRG.ReadLong(); + StringOffsets[iOff] = rSTRG.ReadLong(); // Strings for (u32 iStr = 0; iStr < NumStrings; iStr++) { - STRG.Seek(TableStart + StringOffsets[iStr], SEEK_SET); - Lang->Strings[iStr] = STRG.ReadWString(); + rSTRG.Seek(TableStart + StringOffsets[iStr], SEEK_SET); + Lang->Strings[iStr] = rSTRG.ReadWString(); } } -void CStringLoader::LoadPrimeSTRG(IInputStream& STRG) +void CStringLoader::LoadPrimeSTRG(IInputStream& rSTRG) { // This function starts at 0x8 in the file, after magic/version // Header - u32 NumLanguages = STRG.ReadLong(); - u32 NumStrings = STRG.ReadLong(); + u32 NumLanguages = rSTRG.ReadLong(); + u32 NumStrings = rSTRG.ReadLong(); mpStringTable->mNumStrings = NumStrings; // Language definitions @@ -46,70 +46,70 @@ void CStringLoader::LoadPrimeSTRG(IInputStream& STRG) for (u32 iLang = 0; iLang < NumLanguages; iLang++) { - mpStringTable->mLangTables[iLang].Language = CFourCC(STRG); - LangOffsets[iLang] = STRG.ReadLong(); - if (mVersion == eEchoes) STRG.Seek(0x4, SEEK_CUR); // Skipping strings size + mpStringTable->mLangTables[iLang].Language = CFourCC(rSTRG); + LangOffsets[iLang] = rSTRG.ReadLong(); + if (mVersion == eEchoes) rSTRG.Seek(0x4, SEEK_CUR); // Skipping strings size } // String names if (mVersion == eEchoes) - LoadNameTable(STRG); + LoadNameTable(rSTRG); // Strings - u32 StringsStart = STRG.Tell(); + u32 StringsStart = rSTRG.Tell(); for (u32 iLang = 0; iLang < NumLanguages; iLang++) { - STRG.Seek(StringsStart + LangOffsets[iLang], SEEK_SET); - if (mVersion == ePrime) STRG.Seek(0x4, SEEK_CUR); // Skipping strings size + rSTRG.Seek(StringsStart + LangOffsets[iLang], SEEK_SET); + if (mVersion == ePrime) rSTRG.Seek(0x4, SEEK_CUR); // Skipping strings size - u32 LangStart = STRG.Tell(); + u32 LangStart = rSTRG.Tell(); CStringTable::SLangTable* pLang = &mpStringTable->mLangTables[iLang]; pLang->Strings.resize(NumStrings); // Offsets std::vector StringOffsets(NumStrings); for (u32 iOff = 0; iOff < NumStrings; iOff++) - StringOffsets[iOff] = STRG.ReadLong(); + StringOffsets[iOff] = rSTRG.ReadLong(); // The actual strings for (u32 iStr = 0; iStr < NumStrings; iStr++) { - STRG.Seek(LangStart + StringOffsets[iStr], SEEK_SET); - pLang->Strings[iStr] = STRG.ReadWString(); + rSTRG.Seek(LangStart + StringOffsets[iStr], SEEK_SET); + pLang->Strings[iStr] = rSTRG.ReadWString(); } } } -void CStringLoader::LoadCorruptionSTRG(IInputStream& STRG) +void CStringLoader::LoadCorruptionSTRG(IInputStream& rSTRG) { // This function starts at 0x8 in the file, after magic/version // Header - u32 NumLanguages = STRG.ReadLong(); - u32 NumStrings = STRG.ReadLong(); + u32 NumLanguages = rSTRG.ReadLong(); + u32 NumStrings = rSTRG.ReadLong(); mpStringTable->mNumStrings = NumStrings; // String names - LoadNameTable(STRG); + LoadNameTable(rSTRG); // Language definitions mpStringTable->mLangTables.resize(NumLanguages); std::vector> LangOffsets(NumLanguages); for (u32 iLang = 0; iLang < NumLanguages; iLang++) - mpStringTable->mLangTables[iLang].Language = CFourCC(STRG); + mpStringTable->mLangTables[iLang].Language = CFourCC(rSTRG); for (u32 iLang = 0; iLang < NumLanguages; iLang++) { LangOffsets[iLang].resize(NumStrings); - STRG.Seek(0x4, SEEK_CUR); // Skipping total string size + rSTRG.Seek(0x4, SEEK_CUR); // Skipping total string size for (u32 iStr = 0; iStr < NumStrings; iStr++) - LangOffsets[iLang][iStr] = STRG.ReadLong(); + LangOffsets[iLang][iStr] = rSTRG.ReadLong(); } // Strings - u32 StringsStart = STRG.Tell(); + u32 StringsStart = rSTRG.Tell(); for (u32 iLang = 0; iLang < NumLanguages; iLang++) { @@ -118,20 +118,20 @@ void CStringLoader::LoadCorruptionSTRG(IInputStream& STRG) for (u32 iStr = 0; iStr < NumStrings; iStr++) { - STRG.Seek(StringsStart + LangOffsets[iLang][iStr], SEEK_SET); - STRG.Seek(0x4, SEEK_CUR); // Skipping string size + rSTRG.Seek(StringsStart + LangOffsets[iLang][iStr], SEEK_SET); + rSTRG.Seek(0x4, SEEK_CUR); // Skipping string size - pLang->Strings[iStr] = STRG.ReadString(); + pLang->Strings[iStr] = rSTRG.ReadString(); } } } -void CStringLoader::LoadNameTable(IInputStream& STRG) +void CStringLoader::LoadNameTable(IInputStream& rSTRG) { // Name table header - u32 NameCount = STRG.ReadLong(); - u32 NameTableSize = STRG.ReadLong(); - u32 NameTableStart = STRG.Tell(); + u32 NameCount = rSTRG.ReadLong(); + u32 NameTableSize = rSTRG.ReadLong(); + u32 NameTableStart = rSTRG.Tell(); u32 NameTableEnd = NameTableStart + NameTableSize; // Name definitions @@ -142,8 +142,8 @@ void CStringLoader::LoadNameTable(IInputStream& STRG) for (u32 iName = 0; iName < NameCount; iName++) { - NameDefs[iName].NameOffset = STRG.ReadLong() + NameTableStart; - NameDefs[iName].StringIndex = STRG.ReadLong(); + NameDefs[iName].NameOffset = rSTRG.ReadLong() + NameTableStart; + NameDefs[iName].StringIndex = rSTRG.ReadLong(); } // Name strings @@ -151,47 +151,47 @@ void CStringLoader::LoadNameTable(IInputStream& STRG) for (u32 iName = 0; iName < NameCount; iName++) { SNameDef *pDef = &NameDefs[iName]; - STRG.Seek(pDef->NameOffset, SEEK_SET); - mpStringTable->mStringNames[pDef->StringIndex] = STRG.ReadString(); + rSTRG.Seek(pDef->NameOffset, SEEK_SET); + mpStringTable->mStringNames[pDef->StringIndex] = rSTRG.ReadString(); } - STRG.Seek(NameTableEnd, SEEK_SET); + rSTRG.Seek(NameTableEnd, SEEK_SET); } // ************ STATIC ************ -CStringTable* CStringLoader::LoadSTRG(IInputStream& STRG) +CStringTable* CStringLoader::LoadSTRG(IInputStream& rSTRG) { // Verify that this is a valid STRG - if (!STRG.IsValid()) return nullptr; + if (!rSTRG.IsValid()) return nullptr; - u32 Magic = STRG.ReadLong(); + u32 Magic = rSTRG.ReadLong(); EGame Version = eUnknownVersion; if (Magic != 0x87654321) { // Check for MP1 Demo STRG format - no magic/version; the first value is actually the filesize // so the best I can do is verify the first value actually points to the end of the file - if (Magic <= (u32) STRG.Size()) + if (Magic <= (u32) rSTRG.Size()) { - STRG.Seek(Magic, SEEK_SET); - if ((STRG.EoF()) || (STRG.ReadShort() == 0xFFFF)) + rSTRG.Seek(Magic, SEEK_SET); + if ((rSTRG.EoF()) || (rSTRG.ReadShort() == 0xFFFF)) Version = ePrimeDemo; } if (Version != ePrimeDemo) { - Log::FileError(STRG.GetSourceString(), "Invalid STRG magic: " + TString::HexString(Magic)); + Log::FileError(rSTRG.GetSourceString(), "Invalid STRG magic: " + TString::HexString(Magic)); return nullptr; } } else { - u32 FileVersion = STRG.ReadLong(); + u32 FileVersion = rSTRG.ReadLong(); Version = GetFormatVersion(FileVersion); if (FileVersion == eUnknownVersion) { - Log::FileError(STRG.GetSourceString(), "Unsupported STRG version: " + TString::HexString(FileVersion)); + Log::FileError(rSTRG.GetSourceString(), "Unsupported STRG version: " + TString::HexString(FileVersion, 0)); return nullptr; } } @@ -201,9 +201,9 @@ CStringTable* CStringLoader::LoadSTRG(IInputStream& STRG) Loader.mpStringTable = new CStringTable(); Loader.mVersion = Version; - if (Version == ePrimeDemo) Loader.LoadPrimeDemoSTRG(STRG); - else if (Version < eCorruption) Loader.LoadPrimeSTRG(STRG); - else Loader.LoadCorruptionSTRG(STRG); + if (Version == ePrimeDemo) Loader.LoadPrimeDemoSTRG(rSTRG); + else if (Version < eCorruption) Loader.LoadPrimeSTRG(rSTRG); + else Loader.LoadCorruptionSTRG(rSTRG); return Loader.mpStringTable; } diff --git a/src/Core/Resource/Factory/CStringLoader.h b/src/Core/Resource/Factory/CStringLoader.h index 15f5146c..f2090047 100644 --- a/src/Core/Resource/Factory/CStringLoader.h +++ b/src/Core/Resource/Factory/CStringLoader.h @@ -12,13 +12,13 @@ class CStringLoader EGame mVersion; CStringLoader(); - void LoadPrimeDemoSTRG(IInputStream& STRG); - void LoadPrimeSTRG(IInputStream& STRG); - void LoadCorruptionSTRG(IInputStream& STRG); - void LoadNameTable(IInputStream& STRG); + void LoadPrimeDemoSTRG(IInputStream& rSTRG); + void LoadPrimeSTRG(IInputStream& rSTRG); + void LoadCorruptionSTRG(IInputStream& rSTRG); + void LoadNameTable(IInputStream& rSTRG); public: - static CStringTable* LoadSTRG(IInputStream& STRG); + static CStringTable* LoadSTRG(IInputStream& rSTRG); static EGame GetFormatVersion(u32 Version); }; diff --git a/src/Core/Resource/Factory/CTemplateLoader.cpp b/src/Core/Resource/Factory/CTemplateLoader.cpp index a04106d9..43837feb 100644 --- a/src/Core/Resource/Factory/CTemplateLoader.cpp +++ b/src/Core/Resource/Factory/CTemplateLoader.cpp @@ -30,10 +30,10 @@ IPropertyTemplate* CTemplateLoader::LoadProperty(XMLElement *pElem, CScriptTempl if (!NameAttr.IsEmpty()) Name = NameAttr; else if (mGame >= eEchoesDemo) - Name = CMasterTemplate::GetPropertyName(ID); + Name = CMasterTemplate::PropertyName(ID); else { - Log::Error(rkTemplateName + ": Property " + TString::HexString(ID, true, true, 8) + " doesn't have a name either in the template itself nor in the master list"); + Log::Error(rkTemplateName + ": Property " + TString::HexString(ID) + " doesn't have a name either in the template itself nor in the master list"); return nullptr; } @@ -53,9 +53,9 @@ IPropertyTemplate* CTemplateLoader::LoadProperty(XMLElement *pElem, CScriptTempl if (Type == eInvalidProperty) { if (TypeStr.IsEmpty()) - Log::Error(rkTemplateName + ": Property " + TString::HexString(ID, true, true, 8) + " doesn't have a type set"); + Log::Error(rkTemplateName + ": Property " + TString::HexString(ID) + " doesn't have a type set"); else - Log::Error(rkTemplateName + ": Property " + TString::HexString(ID, true, true, 8) + " has an invalid type set: " + TypeStr); + Log::Error(rkTemplateName + ": Property " + TString::HexString(ID) + " has an invalid type set: " + TypeStr); return nullptr; } @@ -64,7 +64,7 @@ IPropertyTemplate* CTemplateLoader::LoadProperty(XMLElement *pElem, CScriptTempl if (!pProp) { - Log::Error(rkTemplateName + ": Property " + TString::HexString(ID, true, true, 8) + " seems to be using a valid but unsupported property type? (" + TypeStr + ")"); + Log::Error(rkTemplateName + ": Property " + TString::HexString(ID) + " seems to be using a valid but unsupported property type? (" + TypeStr + ")"); return nullptr; } } @@ -87,10 +87,10 @@ IPropertyTemplate* CTemplateLoader::LoadProperty(XMLElement *pElem, CScriptTempl while (pVersion) { TString VerName = pVersion->GetText(); - u32 VerIdx = mpMaster->GetGameVersion(VerName); + u32 VerIdx = mpMaster->GameVersion(VerName); if (VerIdx == -1) - Log::Error(rkTemplateName + ": Property " + TString::HexString(ID, true, true, 8) + " has invalid version \"" + VerName + "\""); + Log::Error(rkTemplateName + ": Property " + TString::HexString(ID) + " has invalid version \"" + VerName + "\""); else pProp->mAllowedVersions.push_back(VerIdx); @@ -886,13 +886,13 @@ void CTemplateLoader::LoadGameList() void CTemplateLoader::LoadGameTemplates(EGame Game) { - std::list MasterList = CMasterTemplate::GetMasterList(); + std::list MasterList = CMasterTemplate::MasterList(); for (auto it = MasterList.begin(); it != MasterList.end(); it++) { CMasterTemplate *pMaster = *it; - if (pMaster->GetGame() == Game && !pMaster->IsLoadedSuccessfully()) + if (pMaster->Game() == Game && !pMaster->IsLoadedSuccessfully()) { XMLDocument MasterXML; OpenXML(mskTemplatesDir + pMaster->mSourceFile, MasterXML); @@ -911,7 +911,7 @@ void CTemplateLoader::LoadGameTemplates(EGame Game) void CTemplateLoader::LoadAllGames() { - std::list MasterList = CMasterTemplate::GetMasterList(); + std::list MasterList = CMasterTemplate::MasterList(); for (auto it = MasterList.begin(); it != MasterList.end(); it++) { @@ -925,7 +925,7 @@ void CTemplateLoader::LoadAllGames() if (!MasterXML.Error()) { CTemplateLoader Loader(mskTemplatesDir); - Loader.mGame = pMaster->GetGame(); + Loader.mGame = pMaster->Game(); Loader.LoadMasterTemplate(&MasterXML, pMaster); } } diff --git a/src/Core/Resource/Factory/CTextureDecoder.cpp b/src/Core/Resource/Factory/CTextureDecoder.cpp index 74428ef3..6d333fe3 100644 --- a/src/Core/Resource/Factory/CTextureDecoder.cpp +++ b/src/Core/Resource/Factory/CTextureDecoder.cpp @@ -50,11 +50,12 @@ CTexture* CTextureDecoder::CreateTexture() pTex->mHeight = mHeight; pTex->mNumMipMaps = mNumMipMaps; pTex->mLinearSize = (u32) (mWidth * mHeight * gskPixelsToBytes[mTexelFormat]); - pTex->mImgDataBuffer = mpDataBuffer; + pTex->mpImgDataBuffer = mpDataBuffer; pTex->mImgDataSize = mDataBufferSize; pTex->mBufferExists = true; - switch (mTexelFormat) { + switch (mTexelFormat) + { case eGX_I4: case eGX_I8: case eGX_IA4: @@ -90,86 +91,85 @@ CTexture* CTextureDecoder::CreateTexture() } // ************ STATIC ************ -CTexture* CTextureDecoder::LoadTXTR(IInputStream& TXTR) +CTexture* CTextureDecoder::LoadTXTR(IInputStream& rTXTR) { CTextureDecoder Decoder; - Decoder.ReadTXTR(TXTR); - Decoder.PartialDecodeGXTexture(TXTR); + Decoder.ReadTXTR(rTXTR); + Decoder.PartialDecodeGXTexture(rTXTR); return Decoder.CreateTexture(); } -CTexture* CTextureDecoder::DoFullDecode(IInputStream &TXTR) +CTexture* CTextureDecoder::DoFullDecode(IInputStream& rTXTR) { CTextureDecoder Decoder; - Decoder.ReadTXTR(TXTR); - Decoder.FullDecodeGXTexture(TXTR); + Decoder.ReadTXTR(rTXTR); + Decoder.FullDecodeGXTexture(rTXTR); CTexture *pTexture = Decoder.CreateTexture(); pTexture->mTexelFormat = eRGBA8; return pTexture; } -CTexture* CTextureDecoder::LoadDDS(IInputStream &DDS) +CTexture* CTextureDecoder::LoadDDS(IInputStream& rDDS) { CTextureDecoder Decoder; - Decoder.ReadDDS(DDS); - Decoder.DecodeDDS(DDS); + Decoder.ReadDDS(rDDS); + Decoder.DecodeDDS(rDDS); return Decoder.CreateTexture(); } -CTexture* CTextureDecoder::DoFullDecode(CTexture*) +CTexture* CTextureDecoder::DoFullDecode(CTexture* /*pTexture*/) { - // Not using parameter 1 (CTexture* - pTexture) return nullptr; } // ************ READ ************ -void CTextureDecoder::ReadTXTR(IInputStream& TXTR) +void CTextureDecoder::ReadTXTR(IInputStream& rTXTR) { // Read TXTR header - mTexelFormat = ETexelFormat(TXTR.ReadLong()); - mWidth = TXTR.ReadShort(); - mHeight = TXTR.ReadShort(); - mNumMipMaps = TXTR.ReadLong(); + mTexelFormat = ETexelFormat(rTXTR.ReadLong()); + mWidth = rTXTR.ReadShort(); + mHeight = rTXTR.ReadShort(); + mNumMipMaps = rTXTR.ReadLong(); // For C4 and C8 images, read palette if ((mTexelFormat == eGX_C4) || (mTexelFormat == eGX_C8)) { mHasPalettes = true; - mPaletteFormat = EGXPaletteFormat(TXTR.ReadLong()); - TXTR.Seek(0x4, SEEK_CUR); + mPaletteFormat = EGXPaletteFormat(rTXTR.ReadLong()); + rTXTR.Seek(0x4, SEEK_CUR); u32 PaletteEntryCount = (mTexelFormat == eGX_C4) ? 16 : 256; mPalettes.resize(PaletteEntryCount * 2); - TXTR.ReadBytes(mPalettes.data(), mPalettes.size()); + rTXTR.ReadBytes(mPalettes.data(), mPalettes.size()); mPaletteInput.SetData(mPalettes.data(), mPalettes.size(), IOUtil::eBigEndian); } else mHasPalettes = false; } -void CTextureDecoder::ReadDDS(IInputStream& DDS) +void CTextureDecoder::ReadDDS(IInputStream& rDDS) { // Header - CFourCC Magic(DDS); + CFourCC Magic(rDDS); if (Magic != "DDS ") { - Log::FileError(DDS.GetSourceString(), "Invalid DDS magic: " + TString::HexString((u32) Magic.ToLong())); + Log::FileError(rDDS.GetSourceString(), "Invalid DDS magic: " + TString::HexString(Magic.ToLong())); return; } - u32 ImageDataStart = DDS.Tell() + DDS.ReadLong(); - DDS.Seek(0x4, SEEK_CUR); // Skipping flags - mHeight = (u16) DDS.ReadLong(); - mWidth = (u16) DDS.ReadLong(); - DDS.Seek(0x8, SEEK_CUR); // Skipping linear size + depth - mNumMipMaps = DDS.ReadLong() + 1; // DDS doesn't seem to count the first mipmap - DDS.Seek(0x2C, SEEK_CUR); // Skipping reserved + u32 ImageDataStart = rDDS.Tell() + rDDS.ReadLong(); + rDDS.Seek(0x4, SEEK_CUR); // Skipping flags + mHeight = (u16) rDDS.ReadLong(); + mWidth = (u16) rDDS.ReadLong(); + rDDS.Seek(0x8, SEEK_CUR); // Skipping linear size + depth + mNumMipMaps = rDDS.ReadLong() + 1; // DDS doesn't seem to count the first mipmap + rDDS.Seek(0x2C, SEEK_CUR); // Skipping reserved // Pixel Format - DDS.Seek(0x4, SEEK_CUR); // Skipping size - mDDSInfo.Flags = DDS.ReadLong(); - CFourCC Format(DDS); + rDDS.Seek(0x4, SEEK_CUR); // Skipping size + mDDSInfo.Flags = rDDS.ReadLong(); + CFourCC Format(rDDS); if (Format == "DXT1") mDDSInfo.Format = SDDSInfo::DXT1; else if (Format == "DXT2") mDDSInfo.Format = SDDSInfo::DXT2; @@ -179,11 +179,11 @@ void CTextureDecoder::ReadDDS(IInputStream& DDS) else { mDDSInfo.Format = SDDSInfo::RGBA; - mDDSInfo.BitCount = DDS.ReadLong(); - mDDSInfo.RBitMask = DDS.ReadLong(); - mDDSInfo.GBitMask = DDS.ReadLong(); - mDDSInfo.BBitMask = DDS.ReadLong(); - mDDSInfo.ABitMask = DDS.ReadLong(); + mDDSInfo.BitCount = rDDS.ReadLong(); + mDDSInfo.RBitMask = rDDS.ReadLong(); + mDDSInfo.GBitMask = rDDS.ReadLong(); + mDDSInfo.BBitMask = rDDS.ReadLong(); + mDDSInfo.ABitMask = rDDS.ReadLong(); mDDSInfo.RShift = CalculateShiftForMask(mDDSInfo.RBitMask); mDDSInfo.GShift = CalculateShiftForMask(mDDSInfo.GBitMask); mDDSInfo.BShift = CalculateShiftForMask(mDDSInfo.BBitMask); @@ -195,7 +195,7 @@ void CTextureDecoder::ReadDDS(IInputStream& DDS) } // Skip the rest - DDS.Seek(ImageDataStart, SEEK_SET); + rDDS.Seek(ImageDataStart, SEEK_SET); } // ************ DECODE ************ @@ -235,12 +235,12 @@ void CTextureDecoder::PartialDecodeGXTexture(IInputStream& TXTR) for (u32 iMip = 0; iMip < mNumMipMaps; iMip++) { - for (u32 BlockY = 0; BlockY < MipH; BlockY += BHeight) - for (u32 BlockX = 0; BlockX < MipW; BlockX += BWidth) { - for (u32 ImgY = BlockY; ImgY < BlockY + BHeight; ImgY++) { - for (u32 ImgX = BlockX; ImgX < BlockX + BWidth; ImgX++) + for (u32 iBlockY = 0; iBlockY < MipH; iBlockY += BHeight) + for (u32 iBlockX = 0; iBlockX < MipW; iBlockX += BWidth) { + for (u32 iImgY = iBlockY; iImgY < iBlockY + BHeight; iImgY++) { + for (u32 iImgX = iBlockX; iImgX < iBlockX + BWidth; iImgX++) { - u32 DstPos = ((ImgY * MipW) + ImgX) * PixelStride; + u32 DstPos = ((iImgY * MipW) + iImgX) * PixelStride; Out.Seek(MipOffset + DstPos, SEEK_SET); if (mTexelFormat == eGX_I4) ReadPixelsI4(TXTR, Out); @@ -255,7 +255,7 @@ void CTextureDecoder::PartialDecodeGXTexture(IInputStream& TXTR) else if (mTexelFormat == eGX_CMPR) ReadSubBlockCMPR(TXTR, Out); // I4 and C4 have 4bpp images, so I'm forced to read two pixels at a time. - if ((mTexelFormat == eGX_I4) || (mTexelFormat == eGX_C4)) ImgX++; + if ((mTexelFormat == eGX_I4) || (mTexelFormat == eGX_C4)) iImgX++; } } if (mTexelFormat == eGX_RGBA8) TXTR.Seek(0x20, SEEK_CUR); @@ -272,13 +272,13 @@ void CTextureDecoder::PartialDecodeGXTexture(IInputStream& TXTR) } } -void CTextureDecoder::FullDecodeGXTexture(IInputStream& TXTR) +void CTextureDecoder::FullDecodeGXTexture(IInputStream& rTXTR) { // Get image data size, create output buffer - u32 ImageStart = TXTR.Tell(); - TXTR.Seek(0x0, SEEK_END); - u32 ImageSize = TXTR.Tell() - ImageStart; - TXTR.Seek(ImageStart, SEEK_SET); + u32 ImageStart = rTXTR.Tell(); + rTXTR.Seek(0x0, SEEK_END); + u32 ImageSize = rTXTR.Tell() - ImageStart; + rTXTR.Seek(ImageStart, SEEK_SET); mDataBufferSize = ImageSize * (32 / gskSourceBpp[mTexelFormat]); mpDataBuffer = new u8[mDataBufferSize]; @@ -296,53 +296,54 @@ void CTextureDecoder::FullDecodeGXTexture(IInputStream& TXTR) // CMPR stores pixels in 8x8 blocks, with four 4x4 subblocks. // An easy way to convert it is to pretend each block is 2x2 and each subblock is one pixel. // So to do that we need to calculate the "new" dimensions of the image, 1/4 the size of the original. - if (mTexelFormat == eGX_CMPR) { + if (mTexelFormat == eGX_CMPR) + { MipW /= 4; MipH /= 4; } for (u32 iMip = 0; iMip < mNumMipMaps; iMip++) { - for (u32 BlockY = 0; BlockY < MipH; BlockY += BHeight) - for (u32 BlockX = 0; BlockX < MipW; BlockX += BWidth) { - for (u32 ImgY = BlockY; ImgY < BlockY + BHeight; ImgY++) { - for (u32 ImgX = BlockX; ImgX < BlockX + BWidth; ImgX++) + for (u32 iBlockY = 0; iBlockY < MipH; iBlockY += BHeight) + for (u32 iBlockX = 0; iBlockX < MipW; iBlockX += BWidth) { + for (u32 iImgY = iBlockY; iImgY < iBlockY + BHeight; iImgY++) { + for (u32 iImgX = iBlockX; iImgX < iBlockX + BWidth; iImgX++) { - u32 DstPos = (mTexelFormat == eGX_CMPR) ? ((ImgY * (MipW * 4)) + ImgX) * 16 : ((ImgY * MipW) + ImgX) * 4; + u32 DstPos = (mTexelFormat == eGX_CMPR) ? ((iImgY * (MipW * 4)) + iImgX) * 16 : ((iImgY * MipW) + iImgX) * 4; Out.Seek(MipOffset + DstPos, SEEK_SET); // I4/C4/CMPR require reading more than one pixel at a time if (mTexelFormat == eGX_I4) { - u8 Byte = TXTR.ReadByte(); + u8 Byte = rTXTR.ReadByte(); Out.WriteLong( DecodePixelI4(Byte, 0).ToLongARGB() ); Out.WriteLong( DecodePixelI4(Byte, 1).ToLongARGB() ); } else if (mTexelFormat == eGX_C4) { - u8 Byte = TXTR.ReadByte(); + u8 Byte = rTXTR.ReadByte(); Out.WriteLong( DecodePixelC4(Byte, 0, mPaletteInput).ToLongARGB() ); Out.WriteLong( DecodePixelC4(Byte, 1, mPaletteInput).ToLongARGB() ); } - else if (mTexelFormat == eGX_CMPR) DecodeSubBlockCMPR(TXTR, Out, (u16) (MipW * 4)); + else if (mTexelFormat == eGX_CMPR) DecodeSubBlockCMPR(rTXTR, Out, (u16) (MipW * 4)); else { CColor Pixel; - if (mTexelFormat == eGX_I8) Pixel = DecodePixelI8(TXTR.ReadByte()); - else if (mTexelFormat == eGX_IA4) Pixel = DecodePixelIA4(TXTR.ReadByte()); - else if (mTexelFormat == eGX_IA8) Pixel = DecodePixelIA8(TXTR.ReadShort()); - else if (mTexelFormat == eGX_C8) Pixel = DecodePixelC8(TXTR.ReadByte(), mPaletteInput); - else if (mTexelFormat == eGX_RGB565) Pixel = DecodePixelRGB565(TXTR.ReadShort()); - else if (mTexelFormat == eGX_RGB5A3) Pixel = DecodePixelRGB5A3(TXTR.ReadShort()); - else if (mTexelFormat == eGX_RGBA8) Pixel = CColor(TXTR, true); + if (mTexelFormat == eGX_I8) Pixel = DecodePixelI8(rTXTR.ReadByte()); + else if (mTexelFormat == eGX_IA4) Pixel = DecodePixelIA4(rTXTR.ReadByte()); + else if (mTexelFormat == eGX_IA8) Pixel = DecodePixelIA8(rTXTR.ReadShort()); + else if (mTexelFormat == eGX_C8) Pixel = DecodePixelC8(rTXTR.ReadByte(), mPaletteInput); + else if (mTexelFormat == eGX_RGB565) Pixel = DecodePixelRGB565(rTXTR.ReadShort()); + else if (mTexelFormat == eGX_RGB5A3) Pixel = DecodePixelRGB5A3(rTXTR.ReadShort()); + else if (mTexelFormat == eGX_RGBA8) Pixel = CColor(rTXTR, true); Out.WriteLong(Pixel.ToLongARGB()); } } } - if (mTexelFormat == eGX_RGBA8) TXTR.Seek(0x20, SEEK_CUR); + if (mTexelFormat == eGX_RGBA8) rTXTR.Seek(0x20, SEEK_CUR); } u32 MipSize = MipW * MipH * 4; @@ -356,13 +357,13 @@ void CTextureDecoder::FullDecodeGXTexture(IInputStream& TXTR) } } -void CTextureDecoder::DecodeDDS(IInputStream &DDS) +void CTextureDecoder::DecodeDDS(IInputStream& rDDS) { // Get image data size, create output buffer - u32 ImageStart = DDS.Tell(); - DDS.Seek(0x0, SEEK_END); - u32 ImageSize = DDS.Tell() - ImageStart; - DDS.Seek(ImageStart, SEEK_SET); + u32 ImageStart = rDDS.Tell(); + rDDS.Seek(0x0, SEEK_END); + u32 ImageSize = rDDS.Tell() - ImageStart; + rDDS.Seek(ImageStart, SEEK_SET); mDataBufferSize = ImageSize; if (mDDSInfo.Format == SDDSInfo::DXT1) mDataBufferSize *= 8; @@ -408,7 +409,7 @@ void CTextureDecoder::DecodeDDS(IInputStream &DDS) Out.Seek(MipOffset, SEEK_SET); u32 MipSize = MipW * MipH / 2; std::vector MipBuffer(MipSize); - DDS.ReadBytes(MipBuffer.data(), MipBuffer.size()); + rDDS.ReadBytes(MipBuffer.data(), MipBuffer.size()); Out.WriteBytes(MipBuffer.data(), MipBuffer.size()); MipOffset += MipSize; @@ -421,32 +422,32 @@ void CTextureDecoder::DecodeDDS(IInputStream &DDS) // Otherwise we do a full decode to RGBA8 else { - for (u32 y = 0; y < MipH; y++) + for (u32 Y = 0; Y < MipH; Y++) { - for (u32 x = 0; x < MipW; x++) + for (u32 X = 0; X < MipW; X++) { u32 OutPos = MipOffset; if (mDDSInfo.Format == SDDSInfo::RGBA) { - OutPos += ((y * MipW) + x) * 4; + OutPos += ((Y * MipW) + X) * 4; Out.Seek(OutPos, SEEK_SET); - CColor Pixel = DecodeDDSPixel(DDS); + CColor Pixel = DecodeDDSPixel(rDDS); Out.WriteLong(Pixel.ToLongARGB()); } else { - OutPos += ((y * (MipW * 4)) + x) * 16; + OutPos += ((Y * (MipW * 4)) + X) * 16; Out.Seek(OutPos, SEEK_SET); if (mDDSInfo.Format == SDDSInfo::DXT1) - DecodeBlockBC1(DDS, Out, MipW * 4); + DecodeBlockBC1(rDDS, Out, MipW * 4); else if ((mDDSInfo.Format == SDDSInfo::DXT2) || (mDDSInfo.Format == SDDSInfo::DXT3)) - DecodeBlockBC2(DDS, Out, MipW * 4); + DecodeBlockBC2(rDDS, Out, MipW * 4); else if ((mDDSInfo.Format == SDDSInfo::DXT4) || (mDDSInfo.Format == SDDSInfo::DXT5)) - DecodeBlockBC3(DDS, Out, MipW * 4); + DecodeBlockBC3(rDDS, Out, MipW * 4); } } } @@ -467,135 +468,136 @@ void CTextureDecoder::DecodeDDS(IInputStream &DDS) } // ************ READ PIXELS (PARTIAL DECODE) ************ -void CTextureDecoder::ReadPixelsI4(IInputStream& src, IOutputStream& dst) +void CTextureDecoder::ReadPixelsI4(IInputStream& rSrc, IOutputStream& rDst) { - u8 px = src.ReadByte(); - dst.WriteByte(Extend4to8(px >> 4)); - dst.WriteByte(Extend4to8(px >> 4)); - dst.WriteByte(Extend4to8(px)); - dst.WriteByte(Extend4to8(px)); + u8 Pixels = rSrc.ReadByte(); + rDst.WriteByte(Extend4to8(Pixels >> 4)); + rDst.WriteByte(Extend4to8(Pixels >> 4)); + rDst.WriteByte(Extend4to8(Pixels)); + rDst.WriteByte(Extend4to8(Pixels)); } -void CTextureDecoder::ReadPixelI8(IInputStream& src, IOutputStream& dst) +void CTextureDecoder::ReadPixelI8(IInputStream& rSrc, IOutputStream& rDst) { - u8 px = src.ReadByte(); - dst.WriteByte(px); - dst.WriteByte(px); + u8 Pixel = rSrc.ReadByte(); + rDst.WriteByte(Pixel); + rDst.WriteByte(Pixel); } -void CTextureDecoder::ReadPixelIA4(IInputStream& src, IOutputStream& dst) +void CTextureDecoder::ReadPixelIA4(IInputStream& rSrc, IOutputStream& rDst) { // this can be left as-is for DDS conversion, but opengl doesn't support two components in one byte... - u8 byte = src.ReadByte(); - u8 a = Extend4to8(byte >> 4); - u8 l = Extend4to8(byte); - dst.WriteShort((l << 8) | a); + u8 Byte = rSrc.ReadByte(); + u8 Alpha = Extend4to8(Byte >> 4); + u8 Lum = Extend4to8(Byte); + rDst.WriteShort((Lum << 8) | Alpha); } -void CTextureDecoder::ReadPixelIA8(IInputStream& src, IOutputStream& dst) +void CTextureDecoder::ReadPixelIA8(IInputStream& rSrc, IOutputStream& rDst) { - dst.WriteShort(src.ReadShort()); + rDst.WriteShort(rSrc.ReadShort()); } -void CTextureDecoder::ReadPixelsC4(IInputStream& src, IOutputStream& dst) +void CTextureDecoder::ReadPixelsC4(IInputStream& rSrc, IOutputStream& rDst) { // This isn't how C4 works, but due to the way Retro packed font textures (which use C4) // this is the only way to get them to decode correctly for now. // Commented-out code is proper C4 decoding. Dedicated font texture-decoding function // is probably going to be necessary in the future. - u8 byte = src.ReadByte(); - u8 indices[2]; - indices[0] = (byte >> 4) & 0xF; - indices[1] = byte & 0xF; + u8 Byte = rSrc.ReadByte(); + u8 Indices[2]; + Indices[0] = (Byte >> 4) & 0xF; + Indices[1] = Byte & 0xF; - for (u32 i = 0; i < 2; i++) + for (u32 iIdx = 0; iIdx < 2; iIdx++) { - u8 r, g, b, a; - ((indices[i] >> 3) & 0x1) ? r = 0xFF : r = 0x0; - ((indices[i] >> 2) & 0x1) ? g = 0xFF : g = 0x0; - ((indices[i] >> 1) & 0x1) ? b = 0xFF : b = 0x0; - ((indices[i] >> 0) & 0x1) ? a = 0xFF : a = 0x0; - u32 rgba = (r << 24) | (g << 16) | (b << 8) | (a); - dst.WriteLong(rgba); + u8 R, G, B, A; + ((Indices[iIdx] >> 3) & 0x1) ? R = 0xFF : R = 0x0; + ((Indices[iIdx] >> 2) & 0x1) ? G = 0xFF : G = 0x0; + ((Indices[iIdx] >> 1) & 0x1) ? B = 0xFF : B = 0x0; + ((Indices[iIdx] >> 0) & 0x1) ? A = 0xFF : A = 0x0; + u32 RGBA = (R << 24) | (G << 16) | (B << 8) | (A); + rDst.WriteLong(RGBA); - /*paletteInput->Seek(indices[i] * 2, SEEK_SET); + /*mPaletteInput.Seek(indices[i] * 2, SEEK_SET); - if (paletteFormat == PaletteIA8) readPixelIA8(*paletteInput, dst); - else if (paletteFormat == PaletteRGB565) readPixelRGB565(*paletteInput, dst); - else if (paletteFormat == PaletteRGB5A3) readPixelRGB5A3(*paletteInput, dst);*/ + if (mPaletteFormat == ePalette_IA8) readPixelIA8(mPaletteInput, rDst); + else if (mPaletteFormat == ePalette_RGB565) readPixelRGB565(mPaletteInput, rDst); + else if (mPaletteFormat == ePalette_RGB5A3) readPixelRGB5A3(mPaletteInput, rDst);*/ } } -void CTextureDecoder::ReadPixelC8(IInputStream& src, IOutputStream& dst) +void CTextureDecoder::ReadPixelC8(IInputStream& rSrc, IOutputStream& rDst) { // DKCR fonts use C8 :| - u8 index = src.ReadByte(); + u8 Index = rSrc.ReadByte(); - /*u8 r, g, b, a; - ((index >> 3) & 0x1) ? r = 0xFF : r = 0x0; - ((index >> 2) & 0x1) ? g = 0xFF : g = 0x0; - ((index >> 1) & 0x1) ? b = 0xFF : b = 0x0; - ((index >> 0) & 0x1) ? a = 0xFF : a = 0x0; - u32 rgba = (r << 24) | (g << 16) | (b << 8) | (a); - dst.WriteLong(rgba);*/ + /*u8 R, G, B, A; + ((Index >> 3) & 0x1) ? R = 0xFF : R = 0x0; + ((Index >> 2) & 0x1) ? G = 0xFF : G = 0x0; + ((Index >> 1) & 0x1) ? B = 0xFF : B = 0x0; + ((Index >> 0) & 0x1) ? A = 0xFF : A = 0x0; + u32 RGBA = (R << 24) | (G << 16) | (B << 8) | (A); + dst.WriteLong(RGBA);*/ - mPaletteInput.Seek(index * 2, SEEK_SET); + mPaletteInput.Seek(Index * 2, SEEK_SET); - if (mPaletteFormat == ePalette_IA8) ReadPixelIA8(mPaletteInput, dst); - else if (mPaletteFormat == ePalette_RGB565) ReadPixelRGB565(mPaletteInput, dst); - else if (mPaletteFormat == ePalette_RGB5A3) ReadPixelRGB5A3(mPaletteInput, dst); + if (mPaletteFormat == ePalette_IA8) ReadPixelIA8(mPaletteInput, rDst); + else if (mPaletteFormat == ePalette_RGB565) ReadPixelRGB565(mPaletteInput, rDst); + else if (mPaletteFormat == ePalette_RGB5A3) ReadPixelRGB5A3(mPaletteInput, rDst); } -void CTextureDecoder::ReadPixelRGB565(IInputStream& src, IOutputStream& dst) +void CTextureDecoder::ReadPixelRGB565(IInputStream& rSrc, IOutputStream& rDst) { // RGB565 can be used as-is. - dst.WriteShort(src.ReadShort()); + rDst.WriteShort(rSrc.ReadShort()); } -void CTextureDecoder::ReadPixelRGB5A3(IInputStream& src, IOutputStream& dst) +void CTextureDecoder::ReadPixelRGB5A3(IInputStream& rSrc, IOutputStream& rDst) { - u16 px = src.ReadShort(); - u8 r, g, b, a; + u16 Pixel = rSrc.ReadShort(); + u8 R, G, B, A; - if (px & 0x8000) // RGB5 + if (Pixel & 0x8000) // RGB5 { - b = Extend5to8(px >> 10); - g = Extend5to8(px >> 5); - r = Extend5to8(px >> 0); - a = 255; + B = Extend5to8(Pixel >> 10); + G = Extend5to8(Pixel >> 5); + R = Extend5to8(Pixel >> 0); + A = 255; } else // RGB4A3 { - a = Extend3to8(px >> 12); - b = Extend4to8(px >> 8); - g = Extend4to8(px >> 4); - r = Extend4to8(px >> 0); + A = Extend3to8(Pixel >> 12); + B = Extend4to8(Pixel >> 8); + G = Extend4to8(Pixel >> 4); + R = Extend4to8(Pixel >> 0); } - u32 c = (a << 24) | (r << 16) | (g << 8) | b; - dst.WriteLong(c); + u32 Color = (A << 24) | (R << 16) | (G << 8) | B; + rDst.WriteLong(Color); } -void CTextureDecoder::ReadPixelRGBA8(IInputStream& src, IOutputStream& dst) +void CTextureDecoder::ReadPixelRGBA8(IInputStream& rSrc, IOutputStream& rDst) { - u16 ar = src.ReadShort(); - src.Seek(0x1E, SEEK_CUR); - u16 gb = src.ReadShort(); - src.Seek(-0x20, SEEK_CUR); - u32 px = (ar << 16) | gb; - dst.WriteLong(px); + u16 AR = rSrc.ReadShort(); + rSrc.Seek(0x1E, SEEK_CUR); + u16 GB = rSrc.ReadShort(); + rSrc.Seek(-0x20, SEEK_CUR); + u32 Pixel = (AR << 16) | GB; + rDst.WriteLong(Pixel); } -void CTextureDecoder::ReadSubBlockCMPR(IInputStream& src, IOutputStream& dst) +void CTextureDecoder::ReadSubBlockCMPR(IInputStream& rSrc, IOutputStream& rDst) { - dst.WriteShort(src.ReadShort()); - dst.WriteShort(src.ReadShort()); + rDst.WriteShort(rSrc.ReadShort()); + rDst.WriteShort(rSrc.ReadShort()); - for (u32 byte = 0; byte < 4; byte++) { - u8 b = src.ReadByte(); - b = ((b & 0x3) << 6) | ((b & 0xC) << 2) | ((b & 0x30) >> 2) | ((b & 0xC0) >> 6); - dst.WriteByte(b); + for (u32 iByte = 0; iByte < 4; iByte++) + { + u8 Byte = rSrc.ReadByte(); + Byte = ((Byte & 0x3) << 6) | ((Byte & 0xC) << 2) | ((Byte & 0x30) >> 2) | ((Byte & 0xC0) >> 6); + rDst.WriteByte(Byte); } } @@ -603,8 +605,8 @@ void CTextureDecoder::ReadSubBlockCMPR(IInputStream& src, IOutputStream& dst) CColor CTextureDecoder::DecodePixelI4(u8 Byte, u8 WhichPixel) { if (WhichPixel == 1) Byte >>= 4; - u8 px = Extend4to8(Byte); - return CColor::Integral(px, px, px); + u8 Pixel = Extend4to8(Byte); + return CColor::Integral(Pixel, Pixel, Pixel); } CColor CTextureDecoder::DecodePixelI8(u8 Byte) @@ -626,60 +628,60 @@ CColor CTextureDecoder::DecodePixelIA8(u16 Short) return CColor::Integral(Lum, Lum, Lum, Alpha); } -CColor CTextureDecoder::DecodePixelC4(u8 Byte, u8 WhichPixel, IInputStream& PaletteStream) +CColor CTextureDecoder::DecodePixelC4(u8 Byte, u8 WhichPixel, IInputStream& rPaletteStream) { if (WhichPixel == 1) Byte >>= 4; Byte &= 0xF; - PaletteStream.Seek(Byte * 2, SEEK_SET); - if (mPaletteFormat == ePalette_IA8) return DecodePixelIA8(PaletteStream.ReadShort()); - else if (mPaletteFormat == ePalette_RGB565) return DecodePixelIA8(PaletteStream.ReadShort()); - else if (mPaletteFormat == ePalette_RGB5A3) return DecodePixelIA8(PaletteStream.ReadShort()); + rPaletteStream.Seek(Byte * 2, SEEK_SET); + if (mPaletteFormat == ePalette_IA8) return DecodePixelIA8(rPaletteStream.ReadShort()); + else if (mPaletteFormat == ePalette_RGB565) return DecodePixelIA8(rPaletteStream.ReadShort()); + else if (mPaletteFormat == ePalette_RGB5A3) return DecodePixelIA8(rPaletteStream.ReadShort()); else return CColor::skTransparentBlack; } -CColor CTextureDecoder::DecodePixelC8(u8 Byte, IInputStream& PaletteStream) +CColor CTextureDecoder::DecodePixelC8(u8 Byte, IInputStream& rPaletteStream) { - PaletteStream.Seek(Byte * 2, SEEK_SET); - if (mPaletteFormat == ePalette_IA8) return DecodePixelIA8(PaletteStream.ReadShort()); - else if (mPaletteFormat == ePalette_RGB565) return DecodePixelIA8(PaletteStream.ReadShort()); - else if (mPaletteFormat == ePalette_RGB5A3) return DecodePixelIA8(PaletteStream.ReadShort()); + rPaletteStream.Seek(Byte * 2, SEEK_SET); + if (mPaletteFormat == ePalette_IA8) return DecodePixelIA8(rPaletteStream.ReadShort()); + else if (mPaletteFormat == ePalette_RGB565) return DecodePixelIA8(rPaletteStream.ReadShort()); + else if (mPaletteFormat == ePalette_RGB5A3) return DecodePixelIA8(rPaletteStream.ReadShort()); else return CColor::skTransparentBlack; } CColor CTextureDecoder::DecodePixelRGB565(u16 Short) { - u8 b = Extend5to8( (u8) (Short >> 11) ); - u8 g = Extend6to8( (u8) (Short >> 5) ); - u8 r = Extend5to8( (u8) (Short) ); - return CColor::Integral(r, g, b, 0xFF); + u8 B = Extend5to8( (u8) (Short >> 11) ); + u8 G = Extend6to8( (u8) (Short >> 5) ); + u8 R = Extend5to8( (u8) (Short) ); + return CColor::Integral(R, G, B, 0xFF); } CColor CTextureDecoder::DecodePixelRGB5A3(u16 Short) { if (Short & 0x8000) // RGB5 { - u8 b = Extend5to8( (u8) (Short >> 10)); - u8 g = Extend5to8( (u8) (Short >> 5)); - u8 r = Extend5to8( (u8) (Short) ); - return CColor::Integral(r, g, b, 0xFF); + u8 B = Extend5to8( (u8) (Short >> 10)); + u8 G = Extend5to8( (u8) (Short >> 5)); + u8 R = Extend5to8( (u8) (Short) ); + return CColor::Integral(R, G, B, 0xFF); } else // RGB4A3 { - u8 a = Extend3to8( (u8) (Short >> 12) ); - u8 b = Extend4to8( (u8) (Short >> 8) ); - u8 g = Extend4to8( (u8) (Short >> 4) ); - u8 r = Extend4to8( (u8) (Short) ); - return CColor::Integral(r, g, b, a); + u8 A = Extend3to8( (u8) (Short >> 12) ); + u8 B = Extend4to8( (u8) (Short >> 8) ); + u8 G = Extend4to8( (u8) (Short >> 4) ); + u8 R = Extend4to8( (u8) (Short) ); + return CColor::Integral(R, G, B, A); } } -void CTextureDecoder::DecodeSubBlockCMPR(IInputStream& src, IOutputStream& dst, u16 Width) +void CTextureDecoder::DecodeSubBlockCMPR(IInputStream& rSrc, IOutputStream& rDst, u16 Width) { CColor Palettes[4]; - u16 PaletteA = src.ReadShort(); - u16 PaletteB = src.ReadShort(); + u16 PaletteA = rSrc.ReadShort(); + u16 PaletteB = rSrc.ReadShort(); Palettes[0] = DecodePixelRGB565(PaletteA); Palettes[1] = DecodePixelRGB565(PaletteB); @@ -694,29 +696,29 @@ void CTextureDecoder::DecodeSubBlockCMPR(IInputStream& src, IOutputStream& dst, Palettes[3] = CColor::skTransparentBlack; } - for (u32 y = 0; y < 4; y++) + for (u32 iBlockY = 0; iBlockY < 4; iBlockY++) { - u8 Byte = src.ReadByte(); + u8 Byte = rSrc.ReadByte(); - for (u32 x = 0; x < 4; x++) + for (u32 iBlockX = 0; iBlockX < 4; iBlockX++) { - u8 Shift = (u8) (6 - (x * 2)); + u8 Shift = (u8) (6 - (iBlockX * 2)); u8 PaletteIndex = (Byte >> Shift) & 0x3; CColor Pixel = Palettes[PaletteIndex]; - dst.WriteLong(Pixel.ToLongARGB()); + rDst.WriteLong(Pixel.ToLongARGB()); } - dst.Seek((Width - 4) * 4, SEEK_CUR); + rDst.Seek((Width - 4) * 4, SEEK_CUR); } } -void CTextureDecoder::DecodeBlockBC1(IInputStream& src, IOutputStream& dst, u32 Width) +void CTextureDecoder::DecodeBlockBC1(IInputStream& rSrc, IOutputStream& rDst, u32 Width) { // Very similar to the CMPR subblock function, but unfortunately a slight // difference in the order the pixel indices are read requires a separate function CColor Palettes[4]; - u16 PaletteA = src.ReadShort(); - u16 PaletteB = src.ReadShort(); + u16 PaletteA = rSrc.ReadShort(); + u16 PaletteB = rSrc.ReadShort(); Palettes[0] = DecodePixelRGB565(PaletteA); Palettes[1] = DecodePixelRGB565(PaletteB); @@ -731,27 +733,27 @@ void CTextureDecoder::DecodeBlockBC1(IInputStream& src, IOutputStream& dst, u32 Palettes[3] = CColor::skTransparentBlack; } - for (u32 y = 0; y < 4; y++) + for (u32 iBlockY = 0; iBlockY < 4; iBlockY++) { - u8 Byte = src.ReadByte(); + u8 Byte = rSrc.ReadByte(); - for (u32 x = 0; x < 4; x++) + for (u32 iBlockX = 0; iBlockX < 4; iBlockX++) { - u8 Shift = (u8) (x * 2); + u8 Shift = (u8) (iBlockX * 2); u8 PaletteIndex = (Byte >> Shift) & 0x3; CColor Pixel = Palettes[PaletteIndex]; - dst.WriteLong(Pixel.ToLongARGB()); + rDst.WriteLong(Pixel.ToLongARGB()); } - dst.Seek((Width - 4) * 4, SEEK_CUR); + rDst.Seek((Width - 4) * 4, SEEK_CUR); } } -void CTextureDecoder::DecodeBlockBC2(IInputStream& src, IOutputStream& dst, u32 Width) +void CTextureDecoder::DecodeBlockBC2(IInputStream& rSrc, IOutputStream& rDst, u32 Width) { CColor CPalettes[4]; - u16 PaletteA = src.ReadShort(); - u16 PaletteB = src.ReadShort(); + u16 PaletteA = rSrc.ReadShort(); + u16 PaletteB = rSrc.ReadShort(); CPalettes[0] = DecodePixelRGB565(PaletteA); CPalettes[1] = DecodePixelRGB565(PaletteB); @@ -766,27 +768,27 @@ void CTextureDecoder::DecodeBlockBC2(IInputStream& src, IOutputStream& dst, u32 CPalettes[3] = CColor::skTransparentBlack; } - for (u32 y = 0; y < 4; y++) + for (u32 iBlockY = 0; iBlockY < 4; iBlockY++) { - u8 Byte = src.ReadByte(); + u8 Byte = rSrc.ReadByte(); - for (u32 x = 0; x < 4; x++) + for (u32 iBlockX = 0; iBlockX < 4; iBlockX++) { - u8 Shift = (u8) (x * 2); + u8 Shift = (u8) (iBlockX * 2); u8 PaletteIndex = (Byte >> Shift) & 0x3; CColor Pixel = CPalettes[PaletteIndex]; - dst.WriteLong(Pixel.ToLongARGB()); + rDst.WriteLong(Pixel.ToLongARGB()); } - dst.Seek((Width - 4) * 4, SEEK_CUR); + rDst.Seek((Width - 4) * 4, SEEK_CUR); } } -void CTextureDecoder::DecodeBlockBC3(IInputStream& src, IOutputStream& dst, u32 Width) +void CTextureDecoder::DecodeBlockBC3(IInputStream& rSrc, IOutputStream& rDst, u32 Width) { CColor Palettes[4]; - u16 PaletteA = src.ReadShort(); - u16 PaletteB = src.ReadShort(); + u16 PaletteA = rSrc.ReadShort(); + u16 PaletteB = rSrc.ReadShort(); Palettes[0] = DecodePixelRGB565(PaletteA); Palettes[1] = DecodePixelRGB565(PaletteB); @@ -801,50 +803,50 @@ void CTextureDecoder::DecodeBlockBC3(IInputStream& src, IOutputStream& dst, u32 Palettes[3] = CColor::skTransparentBlack; } - for (u32 y = 0; y < 4; y++) + for (u32 iBlockY = 0; iBlockY < 4; iBlockY++) { - u8 Byte = src.ReadByte(); + u8 Byte = rSrc.ReadByte(); - for (u32 x = 0; x < 4; x++) + for (u32 iBlockX = 0; iBlockX < 4; iBlockX++) { - u8 Shift = (u8) (x * 2); + u8 Shift = (u8) (iBlockX * 2); u8 PaletteIndex = (Byte >> Shift) & 0x3; CColor Pixel = Palettes[PaletteIndex]; - dst.WriteLong(Pixel.ToLongARGB()); + rDst.WriteLong(Pixel.ToLongARGB()); } - dst.Seek((Width - 4) * 4, SEEK_CUR); + rDst.Seek((Width - 4) * 4, SEEK_CUR); } } -CColor CTextureDecoder::DecodeDDSPixel(IInputStream& /*DDS*/) +CColor CTextureDecoder::DecodeDDSPixel(IInputStream& /*rDDS*/) { return CColor::skWhite; } // ************ UTILITY ************ -u8 CTextureDecoder::Extend3to8(u8 in) +u8 CTextureDecoder::Extend3to8(u8 In) { - in &= 0x7; - return (in << 5) | (in << 2) | (in >> 1); + In &= 0x7; + return (In << 5) | (In << 2) | (In >> 1); } -u8 CTextureDecoder::Extend4to8(u8 in) +u8 CTextureDecoder::Extend4to8(u8 In) { - in &= 0xF; - return (in << 4) | in; + In &= 0xF; + return (In << 4) | In; } -u8 CTextureDecoder::Extend5to8(u8 in) +u8 CTextureDecoder::Extend5to8(u8 In) { - in &= 0x1F; - return (in << 3) | (in >> 2); + In &= 0x1F; + return (In << 3) | (In >> 2); } -u8 CTextureDecoder::Extend6to8(u8 in) +u8 CTextureDecoder::Extend6to8(u8 In) { - in &= 0x3F; - return (in << 2) | (in >> 4); + In &= 0x3F; + return (In << 2) | (In >> 4); } u32 CTextureDecoder::CalculateShiftForMask(u32 BitMask) diff --git a/src/Core/Resource/Factory/CTextureDecoder.h b/src/Core/Resource/Factory/CTextureDecoder.h index e8e6c895..09e891db 100644 --- a/src/Core/Resource/Factory/CTextureDecoder.h +++ b/src/Core/Resource/Factory/CTextureDecoder.h @@ -38,55 +38,55 @@ class CTextureDecoder CTexture* CreateTexture(); // Read - void ReadTXTR(IInputStream& TXTR); - void ReadDDS(IInputStream& DDS); + void ReadTXTR(IInputStream& rTXTR); + void ReadDDS(IInputStream& rDDS); // Decode - void PartialDecodeGXTexture(IInputStream& TXTR); - void FullDecodeGXTexture(IInputStream& TXTR); - void DecodeDDS(IInputStream& DDS); + void PartialDecodeGXTexture(IInputStream& rTXTR); + void FullDecodeGXTexture(IInputStream& rTXTR); + void DecodeDDS(IInputStream& rDDS); // Decode Pixels (preserve compression) - void ReadPixelsI4(IInputStream& src, IOutputStream& dst); - void ReadPixelI8(IInputStream& src, IOutputStream& dst); - void ReadPixelIA4(IInputStream& src, IOutputStream& dst); - void ReadPixelIA8(IInputStream& src, IOutputStream& dst); - void ReadPixelsC4(IInputStream& src, IOutputStream& dst); - void ReadPixelC8(IInputStream& src, IOutputStream& dst); - void ReadPixelRGB565(IInputStream& src, IOutputStream& dst); - void ReadPixelRGB5A3(IInputStream& src, IOutputStream& dst); - void ReadPixelRGBA8(IInputStream& src, IOutputStream& dst); - void ReadSubBlockCMPR(IInputStream& src, IOutputStream& dst); + void ReadPixelsI4(IInputStream& rSrc, IOutputStream& rDst); + void ReadPixelI8(IInputStream& rSrc, IOutputStream& rDst); + void ReadPixelIA4(IInputStream& rSrc, IOutputStream& rDst); + void ReadPixelIA8(IInputStream& rSrc, IOutputStream& rDst); + void ReadPixelsC4(IInputStream& rSrc, IOutputStream& rDst); + void ReadPixelC8(IInputStream& rSrc, IOutputStream& rDst); + void ReadPixelRGB565(IInputStream& rSrc, IOutputStream& rDst); + void ReadPixelRGB5A3(IInputStream& rSrc, IOutputStream& rDst); + void ReadPixelRGBA8(IInputStream& rSrc, IOutputStream& rDst); + void ReadSubBlockCMPR(IInputStream& rSrc, IOutputStream& rDst); // Decode Pixels (convert to RGBA8) CColor DecodePixelI4(u8 Byte, u8 WhichPixel); CColor DecodePixelI8(u8 Byte); CColor DecodePixelIA4(u8 Byte); CColor DecodePixelIA8(u16 Short); - CColor DecodePixelC4(u8 Byte, u8 WhichPixel, IInputStream& PaletteStream); - CColor DecodePixelC8(u8 Byte, IInputStream& PaletteStream); + CColor DecodePixelC4(u8 Byte, u8 WhichPixel, IInputStream& rPaletteStream); + CColor DecodePixelC8(u8 Byte, IInputStream& rPaletteStream); CColor DecodePixelRGB565(u16 Short); CColor DecodePixelRGB5A3(u16 Short); - CColor DecodePixelRGBA8(IInputStream& src, IOutputStream& dst); - void DecodeSubBlockCMPR(IInputStream& src, IOutputStream& dst, u16 Width); + CColor DecodePixelRGBA8(IInputStream& rSrc, IOutputStream& rDst); + void DecodeSubBlockCMPR(IInputStream& rSrc, IOutputStream& rDst, u16 Width); - void DecodeBlockBC1(IInputStream& src, IOutputStream& dst, u32 Width); - void DecodeBlockBC2(IInputStream& src, IOutputStream& dst, u32 Width); - void DecodeBlockBC3(IInputStream& src, IOutputStream& dst, u32 Width); - CColor DecodeDDSPixel(IInputStream& DDS); + void DecodeBlockBC1(IInputStream& rSrc, IOutputStream& rDst, u32 Width); + void DecodeBlockBC2(IInputStream& rSrc, IOutputStream& rDst, u32 Width); + void DecodeBlockBC3(IInputStream& rSrc, IOutputStream& rDst, u32 Width); + CColor DecodeDDSPixel(IInputStream& rDDS); // Static public: - static CTexture* LoadTXTR(IInputStream& TXTR); - static CTexture* LoadDDS(IInputStream& DDS); - static CTexture* DoFullDecode(IInputStream& TXTR); + static CTexture* LoadTXTR(IInputStream& rTXTR); + static CTexture* LoadDDS(IInputStream& rDDS); + static CTexture* DoFullDecode(IInputStream& rTXTR); static CTexture* DoFullDecode(CTexture *pTexture); // Utility - static u8 Extend3to8(u8 in); - static u8 Extend4to8(u8 in); - static u8 Extend5to8(u8 in); - static u8 Extend6to8(u8 in); + static u8 Extend3to8(u8 In); + static u8 Extend4to8(u8 In); + static u8 Extend5to8(u8 In); + static u8 Extend6to8(u8 In); static u32 CalculateShiftForMask(u32 BitMask); static u32 CalculateMaskBitCount(u32 BitMask); }; diff --git a/src/Core/Resource/Factory/CWorldLoader.cpp b/src/Core/Resource/Factory/CWorldLoader.cpp index d0301867..eece52cb 100644 --- a/src/Core/Resource/Factory/CWorldLoader.cpp +++ b/src/Core/Resource/Factory/CWorldLoader.cpp @@ -1,13 +1,12 @@ #include "CWorldLoader.h" #include "Core/Resource/CResCache.h" #include -#include CWorldLoader::CWorldLoader() { } -void CWorldLoader::LoadPrimeMLVL(IInputStream& MLVL) +void CWorldLoader::LoadPrimeMLVL(IInputStream& rMLVL) { /* * This function loads MLVL files from Prime 1/2 @@ -16,41 +15,41 @@ void CWorldLoader::LoadPrimeMLVL(IInputStream& MLVL) // Header if (mVersion < eCorruptionProto) { - mpWorld->mpWorldName = gResCache.GetResource(MLVL.ReadLong(), "STRG"); - if (mVersion == eEchoes) mpWorld->mpDarkWorldName = gResCache.GetResource(MLVL.ReadLong(), "STRG"); - if (mVersion >= eEchoes) mpWorld->mUnknown1 = MLVL.ReadLong(); - if (mVersion >= ePrime) mpWorld->mpSaveWorld = gResCache.GetResource(MLVL.ReadLong(), "SAVW"); - mpWorld->mpDefaultSkybox = gResCache.GetResource(MLVL.ReadLong(), "CMDL"); + mpWorld->mpWorldName = gResCache.GetResource(rMLVL.ReadLong(), "STRG"); + if (mVersion == eEchoes) mpWorld->mpDarkWorldName = gResCache.GetResource(rMLVL.ReadLong(), "STRG"); + if (mVersion >= eEchoes) mpWorld->mUnknown1 = rMLVL.ReadLong(); + if (mVersion >= ePrime) mpWorld->mpSaveWorld = gResCache.GetResource(rMLVL.ReadLong(), "SAVW"); + mpWorld->mpDefaultSkybox = gResCache.GetResource(rMLVL.ReadLong(), "CMDL"); } else { - mpWorld->mpWorldName = gResCache.GetResource(MLVL.ReadLongLong(), "STRG"); - MLVL.Seek(0x4, SEEK_CUR); // Skipping unknown value - mpWorld->mpSaveWorld = gResCache.GetResource(MLVL.ReadLongLong(), "SAVW"); - mpWorld->mpDefaultSkybox = gResCache.GetResource(MLVL.ReadLongLong(), "CMDL"); + mpWorld->mpWorldName = gResCache.GetResource(rMLVL.ReadLongLong(), "STRG"); + rMLVL.Seek(0x4, SEEK_CUR); // Skipping unknown value + mpWorld->mpSaveWorld = gResCache.GetResource(rMLVL.ReadLongLong(), "SAVW"); + mpWorld->mpDefaultSkybox = gResCache.GetResource(rMLVL.ReadLongLong(), "CMDL"); } // Memory relays - only in MP1 if (mVersion == ePrime) { - u32 NumMemoryRelays = MLVL.ReadLong(); + u32 NumMemoryRelays = rMLVL.ReadLong(); mpWorld->mMemoryRelays.reserve(NumMemoryRelays); for (u32 iMem = 0; iMem < NumMemoryRelays; iMem++) { CWorld::SMemoryRelay MemRelay; - MemRelay.InstanceID = MLVL.ReadLong(); - MemRelay.TargetID = MLVL.ReadLong(); - MemRelay.Message = MLVL.ReadShort(); - MemRelay.Unknown = MLVL.ReadByte(); + MemRelay.InstanceID = rMLVL.ReadLong(); + MemRelay.TargetID = rMLVL.ReadLong(); + MemRelay.Message = rMLVL.ReadShort(); + MemRelay.Unknown = rMLVL.ReadByte(); mpWorld->mMemoryRelays.push_back(MemRelay); } } // Areas - here's the real meat of the file - u32 NumAreas = MLVL.ReadLong(); - if (mVersion == ePrime) mpWorld->mUnknownAreas = MLVL.ReadLong(); + u32 NumAreas = rMLVL.ReadLong(); + if (mVersion == ePrime) mpWorld->mUnknownAreas = rMLVL.ReadLong(); mpWorld->mAreas.resize(NumAreas); for (u32 iArea = 0; iArea < NumAreas; iArea++) @@ -59,45 +58,45 @@ void CWorldLoader::LoadPrimeMLVL(IInputStream& MLVL) CWorld::SArea *pArea = &mpWorld->mAreas[iArea]; if (mVersion < eCorruptionProto) - pArea->pAreaName = gResCache.GetResource(MLVL.ReadLong(), "STRG"); + pArea->pAreaName = gResCache.GetResource(rMLVL.ReadLong(), "STRG"); else - pArea->pAreaName = gResCache.GetResource(MLVL.ReadLongLong(), "STRG"); + pArea->pAreaName = gResCache.GetResource(rMLVL.ReadLongLong(), "STRG"); - pArea->Transform = CTransform4f(MLVL); - pArea->AetherBox = CAABox(MLVL); + pArea->Transform = CTransform4f(rMLVL); + pArea->AetherBox = CAABox(rMLVL); if (mVersion < eCorruptionProto) { - pArea->FileID = MLVL.ReadLong() & 0xFFFFFFFF; // This is the MREA ID; not actually loading it for obvious reasons - pArea->AreaID = MLVL.ReadLong() & 0xFFFFFFFF; + pArea->FileID = rMLVL.ReadLong() & 0xFFFFFFFF; // This is the MREA ID; not actually loading it for obvious reasons + pArea->AreaID = rMLVL.ReadLong() & 0xFFFFFFFF; } else { - pArea->FileID = MLVL.ReadLongLong(); - pArea->AreaID = MLVL.ReadLongLong(); + pArea->FileID = rMLVL.ReadLongLong(); + pArea->AreaID = rMLVL.ReadLongLong(); } // Attached areas - u32 NumAttachedAreas = MLVL.ReadLong(); + u32 NumAttachedAreas = rMLVL.ReadLong(); pArea->AttachedAreaIDs.reserve(NumAttachedAreas); for (u32 iAttached = 0; iAttached < NumAttachedAreas; iAttached++) - pArea->AttachedAreaIDs.push_back( MLVL.ReadShort() ); + pArea->AttachedAreaIDs.push_back( rMLVL.ReadShort() ); if (mVersion < eCorruptionProto) - MLVL.Seek(0x4, SEEK_CUR); // Skipping unknown value (always 0) + rMLVL.Seek(0x4, SEEK_CUR); // Skipping unknown value (always 0) // Depedencies if (mVersion < eCorruptionProto) { - u32 NumDependencies = MLVL.ReadLong(); + u32 NumDependencies = rMLVL.ReadLong(); pArea->Dependencies.reserve(NumDependencies); for (u32 iDep = 0; iDep < NumDependencies; iDep++) { SDependency Dependency; - Dependency.ResID = MLVL.ReadLong() & 0xFFFFFFFF; - Dependency.ResType = MLVL.ReadLong(); + Dependency.ResID = rMLVL.ReadLong() & 0xFFFFFFFF; + Dependency.ResType = rMLVL.ReadLong(); pArea->Dependencies.push_back(Dependency); } @@ -105,26 +104,26 @@ void CWorldLoader::LoadPrimeMLVL(IInputStream& MLVL) * Dependency offsets - indicates an offset into the dependency list where each layer's dependencies start * The count is the layer count + 1 because the last offset is for common dependencies, like terrain textures */ - u32 NumDependencyOffsets = MLVL.ReadLong(); + u32 NumDependencyOffsets = rMLVL.ReadLong(); pArea->Layers.resize(NumDependencyOffsets - 1); for (u32 iOff = 0; iOff < NumDependencyOffsets; iOff++) { - u32 *Target; - if (iOff == NumDependencyOffsets - 1) Target = &pArea->CommonDependenciesStart; - else Target = &pArea->Layers[iOff].LayerDependenciesStart; + u32 *pTarget; + if (iOff == NumDependencyOffsets - 1) pTarget = &pArea->CommonDependenciesStart; + else pTarget = &pArea->Layers[iOff].LayerDependenciesStart; - *Target = MLVL.ReadLong(); + *pTarget = rMLVL.ReadLong(); } } // Docks - u32 NumDocks = MLVL.ReadLong(); + u32 NumDocks = rMLVL.ReadLong(); pArea->Docks.resize(NumDocks); for (u32 iDock = 0; iDock < NumDocks; iDock++) { - u32 NumConnectingDocks = MLVL.ReadLong(); + u32 NumConnectingDocks = rMLVL.ReadLong(); CWorld::SArea::SDock* pDock = &pArea->Docks[iDock]; pDock->ConnectingDocks.reserve(NumConnectingDocks); @@ -132,110 +131,110 @@ void CWorldLoader::LoadPrimeMLVL(IInputStream& MLVL) for (u32 iConnect = 0; iConnect < NumConnectingDocks; iConnect++) { CWorld::SArea::SDock::SConnectingDock ConnectingDock; - ConnectingDock.AreaIndex = MLVL.ReadLong(); - ConnectingDock.DockIndex = MLVL.ReadLong(); + ConnectingDock.AreaIndex = rMLVL.ReadLong(); + ConnectingDock.DockIndex = rMLVL.ReadLong(); pDock->ConnectingDocks.push_back(ConnectingDock); } - u32 NumCoordinates = MLVL.ReadLong(); + u32 NumCoordinates = rMLVL.ReadLong(); if (NumCoordinates != 4) Log::Error("Dock coordinate count not 4"); for (u32 iCoord = 0; iCoord < NumCoordinates; iCoord++) - pDock->DockCoordinates[iCoord] = CVector3f(MLVL); + pDock->DockCoordinates[iCoord] = CVector3f(rMLVL); } // Rels if ( (mVersion == eEchoesDemo) || (mVersion == eEchoes) ) { - u32 NumRels = MLVL.ReadLong(); + u32 NumRels = rMLVL.ReadLong(); pArea->RelFilenames.resize(NumRels); for (u32 iRel = 0; iRel < NumRels; iRel++) - pArea->RelFilenames[iRel] = MLVL.ReadString(); + pArea->RelFilenames[iRel] = rMLVL.ReadString(); if (mVersion == eEchoes) { - u32 NumRelOffsets = MLVL.ReadLong(); // Don't know what these offsets correspond to + u32 NumRelOffsets = rMLVL.ReadLong(); // Don't know what these offsets correspond to pArea->RelOffsets.resize(NumRelOffsets); for (u32 iOff = 0; iOff < NumRelOffsets; iOff++) - pArea->RelOffsets[iOff] = MLVL.ReadLong(); + pArea->RelOffsets[iOff] = rMLVL.ReadLong(); } } // Footer if (mVersion >= eEchoesDemo) - pArea->InternalName = MLVL.ReadString(); + pArea->InternalName = rMLVL.ReadString(); } // MapWorld if (mVersion < eCorruptionProto) - mpWorld->mpMapWorld = gResCache.GetResource(MLVL.ReadLong(), "MAPW"); + mpWorld->mpMapWorld = gResCache.GetResource(rMLVL.ReadLong(), "MAPW"); else - mpWorld->mpMapWorld = gResCache.GetResource(MLVL.ReadLongLong(), "MAPW"); - MLVL.Seek(0x5, SEEK_CUR); // Unknown values which are always 0 + mpWorld->mpMapWorld = gResCache.GetResource(rMLVL.ReadLongLong(), "MAPW"); + rMLVL.Seek(0x5, SEEK_CUR); // Unknown values which are always 0 // AudioGrps if (mVersion == ePrime) { - u32 NumAudioGrps = MLVL.ReadLong(); + u32 NumAudioGrps = rMLVL.ReadLong(); mpWorld->mAudioGrps.reserve(NumAudioGrps); for (u32 iGrp = 0; iGrp < NumAudioGrps; iGrp++) { CWorld::SAudioGrp AudioGrp; - AudioGrp.Unknown = MLVL.ReadLong(); - AudioGrp.ResID = MLVL.ReadLong() & 0xFFFFFFFF; + AudioGrp.Unknown = rMLVL.ReadLong(); + AudioGrp.ResID = rMLVL.ReadLong() & 0xFFFFFFFF; mpWorld->mAudioGrps.push_back(AudioGrp); } - MLVL.Seek(0x1, SEEK_CUR); // Unknown values which are always 0 + rMLVL.Seek(0x1, SEEK_CUR); // Unknown values which are always 0 } // Layer flags - MLVL.Seek(0x4, SEEK_CUR); // Skipping redundant area count + rMLVL.Seek(0x4, SEEK_CUR); // Skipping redundant area count for (u32 iArea = 0; iArea < NumAreas; iArea++) { CWorld::SArea* pArea = &mpWorld->mAreas[iArea]; - u32 NumLayers = MLVL.ReadLong(); + u32 NumLayers = rMLVL.ReadLong(); if (NumLayers != pArea->Layers.size()) pArea->Layers.resize(NumLayers); - u64 LayerFlags = MLVL.ReadLongLong(); + u64 LayerFlags = rMLVL.ReadLongLong(); for (u32 iLayer = 0; iLayer < NumLayers; iLayer++) pArea->Layers[iLayer].EnabledByDefault = (((LayerFlags >> iLayer) & 0x1) == 1); } // Layer names - MLVL.Seek(0x4, SEEK_CUR); // Skipping redundant layer count + rMLVL.Seek(0x4, SEEK_CUR); // Skipping redundant layer count for (u32 iArea = 0; iArea < NumAreas; iArea++) { CWorld::SArea* pArea = &mpWorld->mAreas[iArea]; u32 NumLayers = pArea->Layers.size(); for (u32 iLayer = 0; iLayer < NumLayers; iLayer++) - pArea->Layers[iLayer].LayerName = MLVL.ReadString(); + pArea->Layers[iLayer].LayerName = rMLVL.ReadString(); } // Last part of the file is layer name offsets, but we don't need it // todo: Layer ID support for MP3 } -void CWorldLoader::LoadReturnsMLVL(IInputStream& MLVL) +void CWorldLoader::LoadReturnsMLVL(IInputStream& rMLVL) { - mpWorld->mpWorldName = gResCache.GetResource(MLVL.ReadLongLong(), "STRG"); + mpWorld->mpWorldName = gResCache.GetResource(rMLVL.ReadLongLong(), "STRG"); - bool Check = (MLVL.ReadByte() != 0); + bool Check = (rMLVL.ReadByte() != 0); if (Check) { - MLVL.ReadString(); - MLVL.Seek(0x10, SEEK_CUR); + rMLVL.ReadString(); + rMLVL.Seek(0x10, SEEK_CUR); } - mpWorld->mpSaveWorld = gResCache.GetResource(MLVL.ReadLongLong(), "SAVW"); - mpWorld->mpDefaultSkybox = gResCache.GetResource(MLVL.ReadLongLong(), "CMDL"); + mpWorld->mpSaveWorld = gResCache.GetResource(rMLVL.ReadLongLong(), "SAVW"); + mpWorld->mpDefaultSkybox = gResCache.GetResource(rMLVL.ReadLongLong(), "CMDL"); // Areas - u32 NumAreas = MLVL.ReadLong(); + u32 NumAreas = rMLVL.ReadLong(); mpWorld->mAreas.resize(NumAreas); for (u32 iArea = 0; iArea < NumAreas; iArea++) @@ -243,61 +242,61 @@ void CWorldLoader::LoadReturnsMLVL(IInputStream& MLVL) // Area header CWorld::SArea *pArea = &mpWorld->mAreas[iArea]; - pArea->pAreaName = gResCache.GetResource(MLVL.ReadLongLong(), "STRG"); - pArea->Transform = CTransform4f(MLVL); - pArea->AetherBox = CAABox(MLVL); - pArea->FileID = MLVL.ReadLongLong(); - pArea->AreaID = MLVL.ReadLongLong(); + pArea->pAreaName = gResCache.GetResource(rMLVL.ReadLongLong(), "STRG"); + pArea->Transform = CTransform4f(rMLVL); + pArea->AetherBox = CAABox(rMLVL); + pArea->FileID = rMLVL.ReadLongLong(); + pArea->AreaID = rMLVL.ReadLongLong(); - MLVL.Seek(0x4, SEEK_CUR); - pArea->InternalName = MLVL.ReadString(); + rMLVL.Seek(0x4, SEEK_CUR); + pArea->InternalName = rMLVL.ReadString(); } // Layer flags - MLVL.Seek(0x4, SEEK_CUR); // Skipping redundant area count + rMLVL.Seek(0x4, SEEK_CUR); // Skipping redundant area count for (u32 iArea = 0; iArea < NumAreas; iArea++) { CWorld::SArea* pArea = &mpWorld->mAreas[iArea]; - u32 NumLayers = MLVL.ReadLong(); + u32 NumLayers = rMLVL.ReadLong(); pArea->Layers.resize(NumLayers); - u64 LayerFlags = MLVL.ReadLongLong(); + u64 LayerFlags = rMLVL.ReadLongLong(); for (u32 iLayer = 0; iLayer < NumLayers; iLayer++) pArea->Layers[iLayer].EnabledByDefault = (((LayerFlags >> iLayer) & 0x1) == 1); } // Layer names - MLVL.Seek(0x4, SEEK_CUR); // Skipping redundant layer count + rMLVL.Seek(0x4, SEEK_CUR); // Skipping redundant layer count for (u32 iArea = 0; iArea < NumAreas; iArea++) { CWorld::SArea* pArea = &mpWorld->mAreas[iArea]; u32 NumLayers = pArea->Layers.size(); for (u32 iLayer = 0; iLayer < NumLayers; iLayer++) - pArea->Layers[iLayer].LayerName = MLVL.ReadString(); + pArea->Layers[iLayer].LayerName = rMLVL.ReadString(); } // Last part of the file is layer name offsets, but we don't need it // todo: Layer ID support } -CWorld* CWorldLoader::LoadMLVL(IInputStream& MLVL) +CWorld* CWorldLoader::LoadMLVL(IInputStream& rMLVL) { - if (!MLVL.IsValid()) return nullptr; + if (!rMLVL.IsValid()) return nullptr; - u32 Magic = MLVL.ReadLong(); + u32 Magic = rMLVL.ReadLong(); if (Magic != 0xDEAFBABE) { - Log::FileError(MLVL.GetSourceString(), "Invalid MLVL magic: " + TString::HexString(Magic)); + Log::FileError(rMLVL.GetSourceString(), "Invalid MLVL magic: " + TString::HexString(Magic)); return nullptr; } - u32 FileVersion = MLVL.ReadLong(); + u32 FileVersion = rMLVL.ReadLong(); EGame Version = GetFormatVersion(FileVersion); if (Version == eUnknownVersion) { - Log::FileError(MLVL.GetSourceString(), "Unsupported MLVL version: " + TString::HexString(FileVersion)); + Log::FileError(rMLVL.GetSourceString(), "Unsupported MLVL version: " + TString::HexString(FileVersion, 2)); return nullptr; } @@ -308,9 +307,9 @@ CWorld* CWorldLoader::LoadMLVL(IInputStream& MLVL) Loader.mVersion = Version; if (Version != eReturns) - Loader.LoadPrimeMLVL(MLVL); + Loader.LoadPrimeMLVL(rMLVL); else - Loader.LoadReturnsMLVL(MLVL); + Loader.LoadReturnsMLVL(rMLVL); return Loader.mpWorld; } diff --git a/src/Core/Resource/Factory/CWorldLoader.h b/src/Core/Resource/Factory/CWorldLoader.h index 6b360db1..beef1859 100644 --- a/src/Core/Resource/Factory/CWorldLoader.h +++ b/src/Core/Resource/Factory/CWorldLoader.h @@ -13,11 +13,11 @@ class CWorldLoader EGame mVersion; CWorldLoader(); - void LoadPrimeMLVL(IInputStream& MLVL); - void LoadReturnsMLVL(IInputStream& MLVL); + void LoadPrimeMLVL(IInputStream& rMLVL); + void LoadReturnsMLVL(IInputStream& rMLVL); public: - static CWorld* LoadMLVL(IInputStream& MLVL); + static CWorld* LoadMLVL(IInputStream& rMLVL); static EGame GetFormatVersion(u32 Version); }; diff --git a/src/Core/Resource/Model/CBasicModel.cpp b/src/Core/Resource/Model/CBasicModel.cpp index 6db326ac..997ca8a6 100644 --- a/src/Core/Resource/Model/CBasicModel.cpp +++ b/src/Core/Resource/Model/CBasicModel.cpp @@ -2,11 +2,14 @@ #include #include -CBasicModel::CBasicModel() : CResource() +CBasicModel::CBasicModel() + : CResource() + , mVertexCount(0) + , mTriangleCount(0) + , mBuffered(false) + , mHasOwnMaterials(false) + , mHasOwnSurfaces(false) { - mVertexCount = 0; - mTriangleCount = 0; - mBuffered = false; } CBasicModel::~CBasicModel() diff --git a/src/Core/Resource/Model/CModel.cpp b/src/Core/Resource/Model/CModel.cpp index 587f1d0f..8e98b0d1 100644 --- a/src/Core/Resource/Model/CModel.cpp +++ b/src/Core/Resource/Model/CModel.cpp @@ -3,20 +3,18 @@ #include "Core/Render/CRenderer.h" #include "Core/OpenGL/GLCommon.h" -CModel::CModel() : CBasicModel() +CModel::CModel() + : CBasicModel() { mHasOwnMaterials = true; mHasOwnSurfaces = true; - mVertexCount = 0; - mTriangleCount = 0; } -CModel::CModel(CMaterialSet *pSet, bool ownsMatSet) +CModel::CModel(CMaterialSet *pSet, bool OwnsMatSet) + : CBasicModel() { - mHasOwnMaterials = ownsMatSet; + mHasOwnMaterials = OwnsMatSet; mHasOwnSurfaces = true; - mVertexCount = 0; - mTriangleCount = 0; mMaterialSets.resize(1); mMaterialSets[0] = pSet; @@ -25,8 +23,8 @@ CModel::CModel(CMaterialSet *pSet, bool ownsMatSet) CModel::~CModel() { if (mHasOwnMaterials) - for (u32 m = 0; m < mMaterialSets.size(); m++) - delete mMaterialSets[m]; + for (u32 iMat = 0; iMat < mMaterialSets.size(); iMat++) + delete mMaterialSets[iMat]; } void CModel::BufferGL() @@ -56,7 +54,8 @@ void CModel::BufferGL() Indices[iVert] = mVBO.AddIfUnique(pPrim->Vertices[iVert], VBOStartOffset); // then add the indices to the IBO. We convert some primitives to strips to minimize draw calls. - switch (pPrim->Type) { + switch (pPrim->Type) + { case eGX_Triangles: pIBO->TrianglesToStrips(Indices.data(), Indices.size()); break; @@ -147,7 +146,7 @@ void CModel::DrawWireframe(FRenderOptions Options, CColor WireColor /*= CColor:: if (!mBuffered) BufferGL(); // Set up wireframe - WireColor.a = 0; + WireColor.A = 0; CDrawUtil::UseColorShader(WireColor); Options |= eNoMaterialSetup; glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); diff --git a/src/Core/Resource/Model/CModel.h b/src/Core/Resource/Model/CModel.h index 710cad0d..70a95fa4 100644 --- a/src/Core/Resource/Model/CModel.h +++ b/src/Core/Resource/Model/CModel.h @@ -19,7 +19,7 @@ class CModel : public CBasicModel public: CModel(); - CModel(CMaterialSet *pSet, bool ownsMatSet); + CModel(CMaterialSet *pSet, bool OwnsMatSet); ~CModel(); void BufferGL(); diff --git a/src/Core/Resource/Model/CStaticModel.cpp b/src/Core/Resource/Model/CStaticModel.cpp index dbf04d25..da44e374 100644 --- a/src/Core/Resource/Model/CStaticModel.cpp +++ b/src/Core/Resource/Model/CStaticModel.cpp @@ -3,20 +3,18 @@ #include "Core/Render/CRenderer.h" #include "Core/OpenGL/GLCommon.h" -CStaticModel::CStaticModel() : CBasicModel() +CStaticModel::CStaticModel() + : CBasicModel() + , mpMaterial(nullptr) + , mTransparent(false) { - mpMaterial = nullptr; - mTransparent = false; - mHasOwnSurfaces = false; - mHasOwnMaterials = false; } -CStaticModel::CStaticModel(CMaterial *pMat) : CBasicModel() +CStaticModel::CStaticModel(CMaterial *pMat) + : CBasicModel() + , mpMaterial(pMat) + , mTransparent((pMat->Options() & CMaterial::eTransparent) != 0) { - mpMaterial = pMat; - mTransparent = ((pMat->Options() & CMaterial::eTransparent) != 0); - mHasOwnSurfaces = false; - mHasOwnMaterials = false; } CStaticModel::~CStaticModel() @@ -58,7 +56,8 @@ void CStaticModel::BufferGL() Indices[iVert] = mVBO.AddIfUnique(pPrim->Vertices[iVert], VBOStartOffset); // then add the indices to the IBO. We convert some primitives to strips to minimize draw calls. - switch (pPrim->Type) { + switch (pPrim->Type) + { case eGX_Triangles: pIBO->TrianglesToStrips(Indices.data(), Indices.size()); break; @@ -158,7 +157,7 @@ void CStaticModel::DrawWireframe(FRenderOptions Options, CColor WireColor /*= CC if (!mBuffered) BufferGL(); // Set up wireframe - WireColor.a = 0; + WireColor.A = 0; CDrawUtil::UseColorShader(WireColor); Options |= eNoMaterialSetup; glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); diff --git a/src/Core/Resource/Model/CVertex.h b/src/Core/Resource/Model/CVertex.h index 363e33db..af48fb89 100644 --- a/src/Core/Resource/Model/CVertex.h +++ b/src/Core/Resource/Model/CVertex.h @@ -18,24 +18,24 @@ public: CVertex() {} - CVertex(CVector3f& Pos) + CVertex(CVector3f& rPos) { - Position = Pos; + Position = rPos; } - bool operator==(const CVertex& other) { - return ((Position == other.Position) && - (Normal == other.Normal) && - (Color[0] == other.Color[0]) && - (Color[1] == other.Color[1]) && - (Tex[0] == other.Tex[0]) && - (Tex[1] == other.Tex[1]) && - (Tex[2] == other.Tex[2]) && - (Tex[3] == other.Tex[3]) && - (Tex[4] == other.Tex[4]) && - (Tex[5] == other.Tex[5]) && - (Tex[6] == other.Tex[6]) && - (Tex[7] == other.Tex[7])); + bool operator==(const CVertex& rkOther) { + return ((Position == rkOther.Position) && + (Normal == rkOther.Normal) && + (Color[0] == rkOther.Color[0]) && + (Color[1] == rkOther.Color[1]) && + (Tex[0] == rkOther.Tex[0]) && + (Tex[1] == rkOther.Tex[1]) && + (Tex[2] == rkOther.Tex[2]) && + (Tex[3] == rkOther.Tex[3]) && + (Tex[4] == rkOther.Tex[4]) && + (Tex[5] == rkOther.Tex[5]) && + (Tex[6] == rkOther.Tex[6]) && + (Tex[7] == rkOther.Tex[7])); } }; diff --git a/src/Core/Resource/Model/EVertexAttribute.h b/src/Core/Resource/Model/EVertexAttribute.h index e31e0637..9d5a4216 100644 --- a/src/Core/Resource/Model/EVertexAttribute.h +++ b/src/Core/Resource/Model/EVertexAttribute.h @@ -5,27 +5,27 @@ enum EVertexAttribute { - eNoAttributes = 0x0, - ePosition = 0x3, - eNormal = 0xC, - eColor0 = 0x30, - eColor1 = 0xC0, - eTex0 = 0x300, - eTex1 = 0xC00, - eTex2 = 0x3000, - eTex3 = 0xC000, - eTex4 = 0x30000, - eTex5 = 0xC0000, - eTex6 = 0x300000, - eTex7 = 0xC00000, - ePosMtx = 0x1000000, - eTex0Mtx = 0x2000000, - eTex1Mtx = 0x4000000, - eTex2Mtx = 0x8000000, - eTex3Mtx = 0x10000000, - eTex4Mtx = 0x20000000, - eTex5Mtx = 0x40000000, - eTex6Mtx = 0x80000000 + eNoAttributes = 0x0, + ePosition = 0x3, + eNormal = 0xC, + eColor0 = 0x30, + eColor1 = 0xC0, + eTex0 = 0x300, + eTex1 = 0xC00, + eTex2 = 0x3000, + eTex3 = 0xC000, + eTex4 = 0x30000, + eTex5 = 0xC0000, + eTex6 = 0x300000, + eTex7 = 0xC00000, + ePosMtx = 0x1000000, + eTex0Mtx = 0x2000000, + eTex1Mtx = 0x4000000, + eTex2Mtx = 0x8000000, + eTex3Mtx = 0x10000000, + eTex4Mtx = 0x20000000, + eTex5Mtx = 0x40000000, + eTex6Mtx = 0x80000000 }; DECLARE_FLAGS(EVertexAttribute, FVertexDescription) diff --git a/src/Core/Resource/Model/SSurface.cpp b/src/Core/Resource/Model/SSurface.cpp index 6b38f509..23282650 100644 --- a/src/Core/Resource/Model/SSurface.cpp +++ b/src/Core/Resource/Model/SSurface.cpp @@ -3,7 +3,7 @@ #include "Core/CRayCollisionTester.h" #include -std::pair SSurface::IntersectsRay(const CRay& Ray, bool allowBackfaces, float LineThreshold) +std::pair SSurface::IntersectsRay(const CRay& rkRay, bool AllowBackfaces, float LineThreshold) { bool Hit = false; float HitDist; @@ -25,43 +25,43 @@ std::pair SSurface::IntersectsRay(const CRay& Ray, bool allowBackfac for (u32 iTri = 0; iTri < NumTris; iTri++) { - CVector3f vtxA, vtxB, vtxC; + CVector3f VtxA, VtxB, VtxC; // Get the three vertices that make up the current tri if (pPrim->Type == eGX_Triangles) { u32 VertIndex = iTri * 3; - vtxA = pPrim->Vertices[VertIndex].Position; - vtxB = pPrim->Vertices[VertIndex+1].Position; - vtxC = pPrim->Vertices[VertIndex+2].Position; + VtxA = pPrim->Vertices[VertIndex].Position; + VtxB = pPrim->Vertices[VertIndex+1].Position; + VtxC = pPrim->Vertices[VertIndex+2].Position; } else if (pPrim->Type == eGX_TriangleFan) { - vtxA = pPrim->Vertices[0].Position; - vtxB = pPrim->Vertices[iTri+1].Position; - vtxC = pPrim->Vertices[iTri+2].Position; + VtxA = pPrim->Vertices[0].Position; + VtxB = pPrim->Vertices[iTri+1].Position; + VtxC = pPrim->Vertices[iTri+2].Position; } else if (pPrim->Type = eGX_TriangleStrip) { if (iTri & 0x1) { - vtxA = pPrim->Vertices[iTri+2].Position; - vtxB = pPrim->Vertices[iTri+1].Position; - vtxC = pPrim->Vertices[iTri].Position; + VtxA = pPrim->Vertices[iTri+2].Position; + VtxB = pPrim->Vertices[iTri+1].Position; + VtxC = pPrim->Vertices[iTri].Position; } else { - vtxA = pPrim->Vertices[iTri].Position; - vtxB = pPrim->Vertices[iTri+1].Position; - vtxC = pPrim->Vertices[iTri+2].Position; + VtxA = pPrim->Vertices[iTri].Position; + VtxB = pPrim->Vertices[iTri+1].Position; + VtxC = pPrim->Vertices[iTri+2].Position; } } // Intersection test - std::pair TriResult = Math::RayTriangleIntersection(Ray, vtxA, vtxB, vtxC, allowBackfaces); + std::pair TriResult = Math::RayTriangleIntersection(rkRay, VtxA, VtxB, VtxC, AllowBackfaces); if (TriResult.first) { @@ -86,22 +86,22 @@ std::pair SSurface::IntersectsRay(const CRay& Ray, bool allowBackfac for (u32 iLine = 0; iLine < NumLines; iLine++) { - CVector3f vtxA, vtxB; + CVector3f VtxA, VtxB; // Get the two vertices that make up the current line - u32 index = (pPrim->Type == eGX_Lines ? iLine * 2 : iLine); - vtxA = pPrim->Vertices[index].Position; - vtxB = pPrim->Vertices[index+1].Position; + u32 Index = (pPrim->Type == eGX_Lines ? iLine * 2 : iLine); + VtxA = pPrim->Vertices[Index].Position; + VtxB = pPrim->Vertices[Index+1].Position; // Intersection test - std::pair result = Math::RayLineIntersection(Ray, vtxA, vtxB, LineThreshold); + std::pair Result = Math::RayLineIntersection(rkRay, VtxA, VtxB, LineThreshold); - if (result.first) + if (Result.first) { - if ((!Hit) || (result.second < HitDist)) + if ((!Hit) || (Result.second < HitDist)) { Hit = true; - HitDist = result.second; + HitDist = Result.second; } } } diff --git a/src/Core/Resource/Model/SSurface.h b/src/Core/Resource/Model/SSurface.h index 232027ba..5c5a76c2 100644 --- a/src/Core/Resource/Model/SSurface.h +++ b/src/Core/Resource/Model/SSurface.h @@ -30,12 +30,13 @@ struct SSurface }; std::vector Primitives; - SSurface() { + SSurface() + { VertexCount = 0; TriangleCount = 0; } - std::pair IntersectsRay(const CRay& Ray, bool allowBackfaces = false, float LineThreshold = 0.02f); + std::pair IntersectsRay(const CRay& rkRay, bool AllowBackfaces = false, float LineThreshold = 0.02f); }; #endif // SSURFACE_H diff --git a/src/Core/Resource/SNamedResource.h b/src/Core/Resource/SNamedResource.h index 7a9faa0a..cd2c5b3f 100644 --- a/src/Core/Resource/SNamedResource.h +++ b/src/Core/Resource/SNamedResource.h @@ -6,9 +6,9 @@ struct SNamedResource { - CFourCC resType; - TString resName; - u64 resID; + CFourCC Type; + TString Name; + u64 ID; }; #endif // SNAMEDRESOURCE_H diff --git a/src/Core/Resource/SResInfo.h b/src/Core/Resource/SResInfo.h index 63b9944b..9ed21ba0 100644 --- a/src/Core/Resource/SResInfo.h +++ b/src/Core/Resource/SResInfo.h @@ -6,14 +6,14 @@ struct SResInfo { - bool compressed; - CFourCC resType; - u64 resID; - u32 offset; - u32 size; + bool Compressed; + CFourCC Type; + u64 ID; + u32 Offset; + u32 Size; SResInfo() - : compressed(false), resType("NULL"), resID(0), offset(0), size(0) {} + : Compressed(false), Type("NULL"), ID(0), Offset(0), Size(0) {} }; #endif // SRESINFO_H diff --git a/src/Core/Resource/Script/CMasterTemplate.cpp b/src/Core/Resource/Script/CMasterTemplate.cpp index 9129a011..2a9eb764 100644 --- a/src/Core/Resource/Script/CMasterTemplate.cpp +++ b/src/Core/Resource/Script/CMasterTemplate.cpp @@ -3,9 +3,9 @@ #include CMasterTemplate::CMasterTemplate() + : mVersion(0) + , mFullyLoaded(false) { - mVersion = 0; - mFullyLoaded = false; } CMasterTemplate::~CMasterTemplate() @@ -14,18 +14,7 @@ CMasterTemplate::~CMasterTemplate() delete it->second; } -EGame CMasterTemplate::GetGame() -{ - return mGame; -} - -u32 CMasterTemplate::NumGameVersions() -{ - if (mGameVersions.empty()) return 1; - else return mGameVersions.size(); -} - -u32 CMasterTemplate::GetGameVersion(TString VersionName) +u32 CMasterTemplate::GameVersion(TString VersionName) { VersionName = VersionName.ToLower(); @@ -99,12 +88,7 @@ SMessage CMasterTemplate::MessageByIndex(u32 Index) return (std::next(it, Index))->second; } -TString CMasterTemplate::GetDirectory() const -{ - return mSourceFile.GetFileDirectory(); -} - -CStructTemplate* CMasterTemplate::GetStructAtSource(const TString& rkSource) +CStructTemplate* CMasterTemplate::StructAtSource(const TString& rkSource) { auto InfoIt = mStructTemplates.find(rkSource); @@ -114,13 +98,8 @@ CStructTemplate* CMasterTemplate::GetStructAtSource(const TString& rkSource) else return nullptr; } -bool CMasterTemplate::IsLoadedSuccessfully() -{ - return mFullyLoaded; -} - // ************ STATIC ************ -CMasterTemplate* CMasterTemplate::GetMasterForGame(EGame Game) +CMasterTemplate* CMasterTemplate::MasterForGame(EGame Game) { auto it = smMasterMap.find(Game); @@ -130,7 +109,7 @@ CMasterTemplate* CMasterTemplate::GetMasterForGame(EGame Game) return nullptr; } -std::list CMasterTemplate::GetMasterList() +std::list CMasterTemplate::MasterList() { std::list list; @@ -140,7 +119,7 @@ std::list CMasterTemplate::GetMasterList() return list; } -TString CMasterTemplate::GetPropertyName(u32 PropertyID) +TString CMasterTemplate::PropertyName(u32 PropertyID) { auto it = smPropertyNames.find(PropertyID); @@ -250,7 +229,7 @@ void CMasterTemplate::RenameProperty(IPropertyTemplate *pTemp, const TString& rk } } -std::vector CMasterTemplate::GetXMLsUsingID(u32 ID) +std::vector CMasterTemplate::XMLsUsingID(u32 ID) { auto InfoIt = smIDMap.find(ID); @@ -263,7 +242,7 @@ std::vector CMasterTemplate::GetXMLsUsingID(u32 ID) return std::vector(); } -const std::vector* CMasterTemplate::GetTemplatesWithMatchingID(IPropertyTemplate *pTemp) +const std::vector* CMasterTemplate::TemplatesWithMatchingID(IPropertyTemplate *pTemp) { u32 ID = pTemp->PropertyID(); if (ID <= 0xFF) ID = CreatePropertyID(pTemp); diff --git a/src/Core/Resource/Script/CMasterTemplate.h b/src/Core/Resource/Script/CMasterTemplate.h index ab57be5b..d023acc2 100644 --- a/src/Core/Resource/Script/CMasterTemplate.h +++ b/src/Core/Resource/Script/CMasterTemplate.h @@ -1,8 +1,8 @@ #ifndef CMASTERTEMPLATE_H #define CMASTERTEMPLATE_H -#include "CScriptTemplate.h" #include "CLink.h" +#include "CScriptTemplate.h" #include "Core/Resource/EGame.h" #include #include @@ -38,12 +38,7 @@ class CMasterTemplate public: CMasterTemplate(); ~CMasterTemplate(); - EGame GetGame(); - u32 NumGameVersions(); - u32 GetGameVersion(TString VersionName); - u32 NumScriptTemplates(); - u32 NumStates(); - u32 NumMessages(); + u32 GameVersion(TString VersionName); CScriptTemplate* TemplateByID(u32 ObjectID); CScriptTemplate* TemplateByID(const CFourCC& ObjectID); CScriptTemplate* TemplateByIndex(u32 Index); @@ -53,31 +48,26 @@ public: SMessage MessageByID(u32 MessageID); SMessage MessageByID(const CFourCC& MessageID); SMessage MessageByIndex(u32 Index); - TString GetDirectory() const; - CStructTemplate* GetStructAtSource(const TString& rkSource); - bool IsLoadedSuccessfully(); + CStructTemplate* StructAtSource(const TString& rkSource); - static CMasterTemplate* GetMasterForGame(EGame Game); - static std::list GetMasterList(); - static TString GetPropertyName(u32 PropertyID); + // Inline Accessors + EGame Game() const { return mGame; } + u32 NumGameVersions() const { return mGameVersions.empty() ? 1 : mGameVersions.size(); } + u32 NumScriptTemplates() const { return mTemplates.size(); } + u32 NumStates() const { return mStates.size(); } + u32 NumMessages() const { return mMessages.size(); } + bool IsLoadedSuccessfully() { return mFullyLoaded; } + TString GetDirectory() const { return mSourceFile.GetFileDirectory(); } + + // Static + static CMasterTemplate* MasterForGame(EGame Game); + static std::list MasterList(); + static TString PropertyName(u32 PropertyID); static u32 CreatePropertyID(IPropertyTemplate *pTemp); static void AddProperty(IPropertyTemplate *pTemp, const TString& rkTemplateName = ""); static void RenameProperty(IPropertyTemplate *pTemp, const TString& rkNewName); - static std::vector GetXMLsUsingID(u32 ID); - static const std::vector* GetTemplatesWithMatchingID(IPropertyTemplate *pTemp); + static std::vector XMLsUsingID(u32 ID); + static const std::vector* TemplatesWithMatchingID(IPropertyTemplate *pTemp); }; -// ************ INLINE ************ -inline u32 CMasterTemplate::NumScriptTemplates() { - return mTemplates.size(); -} - -inline u32 CMasterTemplate::NumStates() { - return mStates.size(); -} - -inline u32 CMasterTemplate::NumMessages() { - return mMessages.size(); -} - #endif // CMASTERTEMPLATE_H diff --git a/src/Core/Resource/Script/CScriptLayer.h b/src/Core/Resource/Script/CScriptLayer.h index 02c150a2..7f015aff 100644 --- a/src/Core/Resource/Script/CScriptLayer.h +++ b/src/Core/Resource/Script/CScriptLayer.h @@ -101,14 +101,14 @@ public: inline u32 AreaIndex() const { - for (u32 iLyr = 0; iLyr < mpArea->GetScriptLayerCount(); iLyr++) + for (u32 iLyr = 0; iLyr < mpArea->NumScriptLayers(); iLyr++) { - if (mpArea->GetScriptLayer(iLyr) == this) + if (mpArea->ScriptLayer(iLyr) == this) return iLyr; } - if (mpArea->GetGeneratorLayer() == this) - return mpArea->GetScriptLayerCount(); + if (mpArea->GeneratedObjectsLayer() == this) + return mpArea->NumScriptLayers(); return -1; } diff --git a/src/Core/Resource/Script/CScriptObject.cpp b/src/Core/Resource/Script/CScriptObject.cpp index 26312980..8fa998e8 100644 --- a/src/Core/Resource/Script/CScriptObject.cpp +++ b/src/Core/Resource/Script/CScriptObject.cpp @@ -160,72 +160,6 @@ bool CScriptObject::HasNearVisibleActivation() const return false; } -// ************ GETTERS ************ -IProperty* CScriptObject::PropertyByIndex(u32 index) const -{ - return mpProperties->PropertyByIndex(index); -} - -IProperty* CScriptObject::PropertyByIDString(const TString& str) const -{ - return mpProperties->PropertyByIDString(str); -} - -CScriptTemplate* CScriptObject::Template() const -{ - return mpTemplate; -} - -CMasterTemplate* CScriptObject::MasterTemplate() const -{ - return mpTemplate->MasterTemplate(); -} - -CGameArea* CScriptObject::Area() const -{ - return mpArea; -} - -CScriptLayer* CScriptObject::Layer() const -{ - return mpLayer; -} - -u32 CScriptObject::Version() const -{ - return mVersion; -} - -CPropertyStruct* CScriptObject::Properties() const -{ - return mpProperties; -} - -u32 CScriptObject::NumProperties() const -{ - return mpProperties->Count(); -} - -u32 CScriptObject::ObjectTypeID() const -{ - return mpTemplate->ObjectID(); -} - -u32 CScriptObject::InstanceID() const -{ - return mInstanceID; -} - -u32 CScriptObject::NumLinks(ELinkType Type) const -{ - return (Type == eIncoming ? mInLinks.size() : mOutLinks.size()); -} - -CLink* CScriptObject::Link(ELinkType Type, u32 Index) const -{ - return (Type == eIncoming ? mInLinks[Index] : mOutLinks[Index]); -} - void CScriptObject::AddLink(ELinkType Type, CLink *pLink, u32 Index /*= -1*/) { std::vector *pLinkVec = (Type == eIncoming ? &mInLinks : &mOutLinks); @@ -273,103 +207,3 @@ void CScriptObject::BreakAllLinks() mInLinks.clear(); mOutLinks.clear(); } - -TString CScriptObject::InstanceName() const -{ - if (mpInstanceName) - return mpInstanceName->Get(); - else - return ""; -} - -CVector3f CScriptObject::Position() const -{ - if (mpPosition) - return mpPosition->Get(); - else - return CVector3f::skZero; -} - -CVector3f CScriptObject::Rotation() const -{ - if (mpRotation) - return mpRotation->Get(); - else - return CVector3f::skZero; -} - -CVector3f CScriptObject::Scale() const -{ - if (mpScale) - return mpScale->Get(); - else - return CVector3f::skOne; -} - -bool CScriptObject::IsActive() const -{ - if (mpActive) - return mpActive->Get(); - else - return false; -} - -bool CScriptObject::HasInGameModel() const -{ - return mHasInGameModel; -} - -void CScriptObject::SetPosition(const CVector3f& newPos) -{ - if (mpPosition) mpPosition->Set(newPos); -} - -void CScriptObject::SetRotation(const CVector3f& newRot) -{ - if (mpRotation) mpRotation->Set(newRot); -} - -void CScriptObject::SetScale(const CVector3f& newScale) -{ - if (mpScale) mpScale->Set(newScale); -} - -void CScriptObject::SetName(const TString& newName) -{ - if (mpInstanceName) mpInstanceName->Set(newName); -} - -void CScriptObject::SetActive(bool isActive) -{ - if (mpActive) mpActive->Set(isActive); -} - -CPropertyStruct* CScriptObject::LightParameters() const -{ - return mpLightParameters; -} - -CModel* CScriptObject::GetDisplayModel() const -{ - return mpDisplayModel; -} - -CTexture* CScriptObject::GetBillboard() const -{ - return mpBillboard; -} - -CCollisionMeshGroup* CScriptObject::GetCollision() const -{ - return mpCollision; -} - -EVolumeShape CScriptObject::VolumeShape() const -{ - return mVolumeShape; -} - -float CScriptObject::VolumeScale() const -{ - return mVolumeScale; -} diff --git a/src/Core/Resource/Script/CScriptObject.h b/src/Core/Resource/Script/CScriptObject.h index 91733b7a..422def70 100644 --- a/src/Core/Resource/Script/CScriptObject.h +++ b/src/Core/Resource/Script/CScriptObject.h @@ -63,41 +63,42 @@ public: u32 LayerIndex() const; bool HasNearVisibleActivation() const; - CScriptTemplate* Template() const; - CMasterTemplate* MasterTemplate() const; - CGameArea* Area() const; - CScriptLayer* Layer() const; - u32 Version() const; - CPropertyStruct* Properties() const; - u32 NumProperties() const; - IProperty* PropertyByIndex(u32 index) const; - IProperty* PropertyByIDString(const TIDString& str) const; - u32 ObjectTypeID() const; - u32 InstanceID() const; - - u32 NumLinks(ELinkType Type) const; - CLink* Link(ELinkType Type, u32 Index) const; void AddLink(ELinkType Type, CLink *pLink, u32 Index = -1); void RemoveLink(ELinkType Type, CLink *pLink); void BreakAllLinks(); - CVector3f Position() const; - CVector3f Rotation() const; - CVector3f Scale() const; - TString InstanceName() const; - bool IsActive() const; - bool HasInGameModel() const; - void SetPosition(const CVector3f& newPos); - void SetRotation(const CVector3f& newRot); - void SetScale(const CVector3f& newScale); - void SetName(const TString& newName); - void SetActive(bool isActive); - CPropertyStruct* LightParameters() const; - CModel* GetDisplayModel() const; - CTexture* GetBillboard() const; - CCollisionMeshGroup* GetCollision() const; - EVolumeShape VolumeShape() const; - float VolumeScale() const; + // Accessors + CScriptTemplate* Template() const { return mpTemplate; } + CMasterTemplate* MasterTemplate() const { return mpTemplate->MasterTemplate(); } + CGameArea* Area() const { return mpArea; } + CScriptLayer* Layer() const { return mpLayer; } + u32 Version() const { return mVersion; } + CPropertyStruct* Properties() const { return mpProperties; } + u32 NumProperties() const { return mpProperties->Count(); } + IProperty* PropertyByIndex(u32 Index) const { return mpProperties->PropertyByIndex(Index); } + IProperty* PropertyByIDString(const TIDString& rkStr) const { return mpProperties->PropertyByIDString(rkStr); } + u32 ObjectTypeID() const { return mpTemplate->ObjectID(); } + u32 InstanceID() const { return mInstanceID; } + u32 NumLinks(ELinkType Type) const { return (Type == eIncoming ? mInLinks.size() : mOutLinks.size()); } + CLink* Link(ELinkType Type, u32 Index) const { return (Type == eIncoming ? mInLinks[Index] : mOutLinks[Index]); } + + CVector3f Position() const { return mpPosition ? mpPosition->Get() : CVector3f::skZero; } + CVector3f Rotation() const { return mpRotation ? mpRotation->Get() : CVector3f::skZero; } + CVector3f Scale() const { return mpScale ? mpScale->Get() : CVector3f::skZero; } + TString InstanceName() const { return mpInstanceName ? mpInstanceName->Get() : ""; } + bool IsActive() const { return mpActive ? mpActive->Get() : false; } + bool HasInGameModel() const { return mHasInGameModel; } + void SetPosition(const CVector3f& rkNewPos) { if (mpPosition) mpPosition->Set(rkNewPos); } + void SetRotation(const CVector3f& rkNewRot) { if (mpRotation) mpRotation->Set(rkNewRot); } + void SetScale(const CVector3f& rkNewScale) { if (mpScale) mpScale->Set(rkNewScale); } + void SetName(const TString& rkNewName) { if (mpInstanceName) mpInstanceName->Set(rkNewName); } + void SetActive(bool Active) { if (mpActive) mpActive->Set(Active); } + CPropertyStruct* LightParameters() const { return mpLightParameters; } + CModel* GetDisplayModel() const { return mpDisplayModel; } + CTexture* GetBillboard() const { return mpBillboard; } + CCollisionMeshGroup* GetCollision() const { return mpCollision; } + EVolumeShape VolumeShape() const { return mVolumeShape; } + float VolumeScale() const { return mVolumeScale; } TStringProperty* InstanceNameProperty() const { return mpInstanceName; } TVector3Property* PositionProperty() const { return mpPosition; } diff --git a/src/Core/Resource/Script/CScriptTemplate.cpp b/src/Core/Resource/Script/CScriptTemplate.cpp index 2da0ce69..35c42931 100644 --- a/src/Core/Resource/Script/CScriptTemplate.cpp +++ b/src/Core/Resource/Script/CScriptTemplate.cpp @@ -23,74 +23,24 @@ CScriptTemplate::~CScriptTemplate() delete mpBaseStruct; } -CMasterTemplate* CScriptTemplate::MasterTemplate() +EGame CScriptTemplate::Game() const { - return mpMaster; -} - -EGame CScriptTemplate::Game() -{ - return mpMaster->GetGame(); -} - -TString CScriptTemplate::Name() const -{ - return mTemplateName; -} - -CScriptTemplate::ERotationType CScriptTemplate::RotationType() const -{ - return mRotationType; -} - -CScriptTemplate::EScaleType CScriptTemplate::ScaleType() const -{ - return mScaleType; -} - -float CScriptTemplate::PreviewScale() const -{ - return mPreviewScale; -} - -u32 CScriptTemplate::ObjectID() const -{ - return mObjectID; -} - -void CScriptTemplate::SetVisible(bool visible) -{ - mVisible = visible; -} - -bool CScriptTemplate::IsVisible() const -{ - return mVisible; -} - -void CScriptTemplate::DebugPrintProperties() -{ - mpBaseStruct->DebugPrintProperties(""); + return mpMaster->Game(); } // ************ PROPERTY FETCHING ************ -template -t TFetchProperty(CPropertyStruct *pProperties, const TIDString& ID) +template +PropType TFetchProperty(CPropertyStruct *pProperties, const TIDString& rkID) { - if (ID.IsEmpty()) return nullptr; - IProperty *pProp = pProperties->PropertyByIDString(ID); + if (rkID.IsEmpty()) return nullptr; + IProperty *pProp = pProperties->PropertyByIDString(rkID); - if (pProp && (pProp->Type() == propType)) - return static_cast(pProp); + if (pProp && (pProp->Type() == PropEnum)) + return static_cast(pProp); else return nullptr; } -CStructTemplate* CScriptTemplate::BaseStruct() -{ - return mpBaseStruct; -} - EVolumeShape CScriptTemplate::VolumeShape(CScriptObject *pObj) { if (pObj->Template() != this) @@ -101,9 +51,9 @@ EVolumeShape CScriptTemplate::VolumeShape(CScriptObject *pObj) if (mVolumeShape == eConditionalShape) { - s32 index = CheckVolumeConditions(pObj, true); - if (index == -1) return eInvalidShape; - else return mVolumeConditions[index].Shape; + s32 Index = CheckVolumeConditions(pObj, true); + if (Index == -1) return eInvalidShape; + else return mVolumeConditions[Index].Shape; } else return mVolumeShape; } @@ -118,9 +68,9 @@ float CScriptTemplate::VolumeScale(CScriptObject *pObj) if (mVolumeShape == eConditionalShape) { - s32 index = CheckVolumeConditions(pObj, false); - if (index == -1) return mVolumeScale; - else return mVolumeConditions[index].Scale; + s32 Index = CheckVolumeConditions(pObj, false); + if (Index == -1) return mVolumeScale; + else return mVolumeConditions[Index].Scale; } else return mVolumeScale; } @@ -133,40 +83,40 @@ s32 CScriptTemplate::CheckVolumeConditions(CScriptObject *pObj, bool LogErrors) IProperty *pProp = pObj->Properties()->PropertyByIDString(mVolumeConditionIDString); // Get value of the condition test property (only boolean, integral, and enum types supported) - int v; + int Val; + switch (pProp->Type()) { case eBoolProperty: - v = (static_cast(pProp)->Get() ? 1 : 0); + Val = (static_cast(pProp)->Get() ? 1 : 0); break; case eByteProperty: - v = (int) static_cast(pProp)->Get(); + Val = (int) static_cast(pProp)->Get(); break; case eShortProperty: - v = (int) static_cast(pProp)->Get(); + Val = (int) static_cast(pProp)->Get(); break; case eLongProperty: - v = (int) static_cast(pProp)->Get(); + Val = (int) static_cast(pProp)->Get(); break; - case eEnumProperty: { - v = (int) static_cast(pProp)->Get(); + case eEnumProperty: + Val = (int) static_cast(pProp)->Get(); break; } - } // Test and check whether any of the conditions are true for (u32 iCon = 0; iCon < mVolumeConditions.size(); iCon++) { - if (mVolumeConditions[iCon].Value == v) + if (mVolumeConditions[iCon].Value == Val) return iCon; } if (LogErrors) - Log::Error(pObj->Template()->Name() + " instance " + TString::HexString(pObj->InstanceID(), true, true, 8) + " has unexpected volume shape value of " + TString::HexString((u32) v, true, true)); + Log::Error(pObj->Template()->Name() + " instance " + TString::HexString(pObj->InstanceID()) + " has unexpected volume shape value of " + TString::HexString((u32) Val, 0)); } return -1; @@ -213,8 +163,8 @@ CModel* CScriptTemplate::FindDisplayModel(CPropertyStruct *pProperties) // File if (it->AssetSource == SEditorAsset::eFile) { - TString path = "../resources/" + it->AssetLocation; - pRes = gResCache.GetResource(path); + TString Path = "../resources/" + it->AssetLocation; + pRes = gResCache.GetResource(Path); } // Property diff --git a/src/Core/Resource/Script/CScriptTemplate.h b/src/Core/Resource/Script/CScriptTemplate.h index ef139b24..91c5e791 100644 --- a/src/Core/Resource/Script/CScriptTemplate.h +++ b/src/Core/Resource/Script/CScriptTemplate.h @@ -12,7 +12,6 @@ #include #include -class CMasterTemplate; class CScriptObject; typedef TString TIDString; @@ -89,21 +88,9 @@ private: public: CScriptTemplate(CMasterTemplate *pMaster); ~CScriptTemplate(); - - CMasterTemplate* MasterTemplate(); - EGame Game(); - TString Name() const; - u32 NumPropertySets() const; - ERotationType RotationType() const; - EScaleType ScaleType() const; - float PreviewScale() const; - u32 ObjectID() const; - void SetVisible(bool visible); - bool IsVisible() const; - void DebugPrintProperties(); + EGame Game() const; // Property Fetching - CStructTemplate* BaseStruct(); EVolumeShape VolumeShape(CScriptObject *pObj); float VolumeScale(CScriptObject *pObj); TStringProperty* FindInstanceName(CPropertyStruct *pProperties); @@ -117,12 +104,26 @@ public: CCollisionMeshGroup* FindCollision(CPropertyStruct *pProperties); bool HasInGameModel(CPropertyStruct *pProperties); - inline TString SourceFile() const { return mSourceFile; } - inline bool HasName() const { return !mNameIDString.IsEmpty(); } - inline bool HasPosition() const { return !mPositionIDString.IsEmpty(); } - inline bool HasRotation() const { return !mRotationIDString.IsEmpty(); } - inline bool HasScale() const { return !mScaleIDString.IsEmpty(); } - inline bool HasActive() const { return !mActiveIDString.IsEmpty(); } + // Accessors + inline CMasterTemplate* MasterTemplate() const { return mpMaster; } + inline TString Name() const { return mTemplateName; } + inline ERotationType RotationType() const { return mRotationType; } + inline EScaleType ScaleType() const { return mScaleType; } + inline float PreviewScale() const { return mPreviewScale; } + inline u32 ObjectID() const { return mObjectID; } + inline bool IsVisible() const { return mVisible; } + inline TString SourceFile() const { return mSourceFile; } + inline CStructTemplate* BaseStruct() const { return mpBaseStruct; } + + inline bool HasName() const { return !mNameIDString.IsEmpty(); } + inline bool HasPosition() const { return !mPositionIDString.IsEmpty(); } + inline bool HasRotation() const { return !mRotationIDString.IsEmpty(); } + inline bool HasScale() const { return !mScaleIDString.IsEmpty(); } + inline bool HasActive() const { return !mActiveIDString.IsEmpty(); } + + inline void SetVisible(bool Visible) { mVisible = Visible; } + + inline void DebugPrintProperties() { mpBaseStruct->DebugPrintProperties(""); } // Object Tracking u32 NumObjects() const; diff --git a/src/Core/Resource/Script/IProperty.cpp b/src/Core/Resource/Script/IProperty.cpp index 6abf5adc..c73fd152 100644 --- a/src/Core/Resource/Script/IProperty.cpp +++ b/src/Core/Resource/Script/IProperty.cpp @@ -50,7 +50,7 @@ TIDString IProperty::IDString(bool FullPath) const if (!Out.IsEmpty()) Out += ":"; } - Out += TString::HexString(ID(), true, true, 8); + Out += TString::HexString(ID()); } return Out; diff --git a/src/Core/Resource/Script/IPropertyTemplate.cpp b/src/Core/Resource/Script/IPropertyTemplate.cpp index 6b310f78..5b3cc00e 100644 --- a/src/Core/Resource/Script/IPropertyTemplate.cpp +++ b/src/Core/Resource/Script/IPropertyTemplate.cpp @@ -5,7 +5,7 @@ // ************ IPropertyTemplate ************ EGame IPropertyTemplate::Game() const { - return (mpMasterTemplate ? mpMasterTemplate->GetGame() : eUnknownVersion); + return (mpMasterTemplate ? mpMasterTemplate->Game() : eUnknownVersion); } bool IPropertyTemplate::IsInVersion(u32 Version) const @@ -32,7 +32,7 @@ TIDString IPropertyTemplate::IDString(bool FullPath) const if (!out.IsEmpty()) out += ":"; } - out += TIDString::HexString(mID, true, true, 8); + out += TIDString::HexString(mID); return out; } else return ""; diff --git a/src/Core/Resource/Script/IPropertyValue.h b/src/Core/Resource/Script/IPropertyValue.h index d6d33848..6e1f374d 100644 --- a/src/Core/Resource/Script/IPropertyValue.h +++ b/src/Core/Resource/Script/IPropertyValue.h @@ -168,13 +168,13 @@ public: TString ToString() const { - return TString::HexString(mValue, true, true, mValue > 0xFF ? 8 : 2); + return TString::HexString(mValue, 8); } void FromString(const TString& rkString) { - u32 base = (rkString.StartsWith("0x") ? 16 : 10); - mValue = (s32) rkString.ToInt32(base); + u32 Base = (rkString.StartsWith("0x") ? 16 : 10); + mValue = (s32) rkString.ToInt32(Base); } IPropertyValue* Clone() const @@ -237,10 +237,10 @@ public: TString ToString() const { TString out; - out += TString::FromFloat(mValue.r) + ", "; - out += TString::FromFloat(mValue.g) + ", "; - out += TString::FromFloat(mValue.b) + ", "; - out += TString::FromFloat(mValue.a); + out += TString::FromFloat(mValue.R) + ", "; + out += TString::FromFloat(mValue.G) + ", "; + out += TString::FromFloat(mValue.B) + ", "; + out += TString::FromFloat(mValue.A); return out; } @@ -255,8 +255,8 @@ public: return; } - float *pPtr = &mValue.r; - mValue.a = 1.0f; + float *pPtr = &mValue.R; + mValue.A = 1.0f; for (auto it = Components.begin(); it != Components.end(); it++) { @@ -280,9 +280,9 @@ public: TString ToString() const { TString out; - out += TString::FromFloat(mValue.x) + ", "; - out += TString::FromFloat(mValue.y) + ", "; - out += TString::FromFloat(mValue.z); + out += TString::FromFloat(mValue.X) + ", "; + out += TString::FromFloat(mValue.Y) + ", "; + out += TString::FromFloat(mValue.Z); return out; } @@ -297,7 +297,7 @@ public: return; } - float *pPtr = &mValue.x; + float *pPtr = &mValue.X; for (auto it = Components.begin(); it != Components.end(); it++) { diff --git a/src/Core/Scene/CCollisionNode.cpp b/src/Core/Scene/CCollisionNode.cpp index 3c20500f..32a88044 100644 --- a/src/Core/Scene/CCollisionNode.cpp +++ b/src/Core/Scene/CCollisionNode.cpp @@ -15,11 +15,11 @@ ENodeType CCollisionNode::NodeType() return eCollisionNode; } -void CCollisionNode::AddToRenderer(CRenderer *pRenderer, const SViewInfo& ViewInfo) +void CCollisionNode::AddToRenderer(CRenderer *pRenderer, const SViewInfo& rkViewInfo) { if (!mpCollision) return; - if (!ViewInfo.ViewFrustum.BoxInFrustum(AABox())) return; - if (ViewInfo.GameMode) return; + if (!rkViewInfo.ViewFrustum.BoxInFrustum(AABox())) return; + if (rkViewInfo.GameMode) return; pRenderer->AddOpaqueMesh(this, -1, AABox(), eDrawMesh); @@ -27,7 +27,7 @@ void CCollisionNode::AddToRenderer(CRenderer *pRenderer, const SViewInfo& ViewIn pRenderer->AddOpaqueMesh(this, -1, AABox(), eDrawSelection); } -void CCollisionNode::Draw(FRenderOptions /*Options*/, int /*ComponentIndex*/, const SViewInfo& ViewInfo) +void CCollisionNode::Draw(FRenderOptions /*Options*/, int /*ComponentIndex*/, const SViewInfo& rkViewInfo) { if (!mpCollision) return; @@ -37,13 +37,13 @@ void CCollisionNode::Draw(FRenderOptions /*Options*/, int /*ComponentIndex*/, co glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); glDepthMask(GL_TRUE); - CDrawUtil::UseCollisionShader(TintColor(ViewInfo)); + CDrawUtil::UseCollisionShader(TintColor(rkViewInfo)); mpCollision->Draw(); CDrawUtil::UseColorShader(CColor::skTransparentBlack); mpCollision->DrawWireframe(); } -SRayIntersection CCollisionNode::RayNodeIntersectTest(const CRay& /*Ray*/, u32 /*AssetID*/, const SViewInfo& /*ViewInfo*/) +SRayIntersection CCollisionNode::RayNodeIntersectTest(const CRay& /*rkRay*/, u32 /*AssetID*/, const SViewInfo& /*rkViewInfo*/) { // todo SRayIntersection Result; diff --git a/src/Core/Scene/CCollisionNode.h b/src/Core/Scene/CCollisionNode.h index b0614092..dcfa4464 100644 --- a/src/Core/Scene/CCollisionNode.h +++ b/src/Core/Scene/CCollisionNode.h @@ -11,9 +11,9 @@ class CCollisionNode : public CSceneNode public: CCollisionNode(CScene *pScene, u32 NodeID, CSceneNode *pParent = 0, CCollisionMeshGroup *pCollision = 0); ENodeType NodeType(); - void AddToRenderer(CRenderer *pRenderer, const SViewInfo& ViewInfo); - void Draw(FRenderOptions Options, int ComponentIndex, const SViewInfo& ViewInfo); - SRayIntersection RayNodeIntersectTest(const CRay &Ray, u32 AssetID, const SViewInfo& ViewInfo); + void AddToRenderer(CRenderer *pRenderer, const SViewInfo& rkViewInfo); + void Draw(FRenderOptions Options, int ComponentIndex, const SViewInfo& rkViewInfo); + SRayIntersection RayNodeIntersectTest(const CRay& rkRay, u32 AssetID, const SViewInfo& rkViewInfo); void SetCollision(CCollisionMeshGroup *pCollision); }; diff --git a/src/Core/Scene/CLightNode.cpp b/src/Core/Scene/CLightNode.cpp index c366d55e..0294da0f 100644 --- a/src/Core/Scene/CLightNode.cpp +++ b/src/Core/Scene/CLightNode.cpp @@ -4,14 +4,14 @@ #include "Core/Render/CRenderer.h" #include -CLightNode::CLightNode(CScene *pScene, u32 NodeID, CSceneNode *pParent, CLight *Light) +CLightNode::CLightNode(CScene *pScene, u32 NodeID, CSceneNode *pParent, CLight *pLight) : CSceneNode(pScene, NodeID, pParent) + , mpLight(pLight) { - mpLight = Light; mLocalAABox = CAABox::skOne; - mPosition = Light->GetPosition(); + mPosition = pLight->Position(); - switch (Light->GetType()) + switch (pLight->Type()) { case eLocalAmbient: SetName("Ambient Light"); break; case eDirectional: SetName("Directional Light"); break; @@ -25,104 +25,104 @@ ENodeType CLightNode::NodeType() return eLightNode; } -void CLightNode::AddToRenderer(CRenderer *pRenderer, const SViewInfo& ViewInfo) +void CLightNode::AddToRenderer(CRenderer *pRenderer, const SViewInfo& rkViewInfo) { - if (ViewInfo.GameMode) return; + if (rkViewInfo.GameMode) return; - if (ViewInfo.ViewFrustum.BoxInFrustum(AABox())) + if (rkViewInfo.ViewFrustum.BoxInFrustum(AABox())) pRenderer->AddOpaqueMesh(this, -1, AABox(), eDrawMesh); - if (IsSelected() && mpLight->GetType() == eCustom) + if (IsSelected() && mpLight->Type() == eCustom) { CAABox RadiusBox = (CAABox::skOne * 2.f * mpLight->GetRadius()) + mPosition; - if (ViewInfo.ViewFrustum.BoxInFrustum(RadiusBox)) + if (rkViewInfo.ViewFrustum.BoxInFrustum(RadiusBox)) pRenderer->AddOpaqueMesh(this, -1, AABox(), eDrawSelection); } } -void CLightNode::Draw(FRenderOptions /*Options*/, int /*ComponentIndex*/, const SViewInfo& ViewInfo) +void CLightNode::Draw(FRenderOptions /*Options*/, int /*ComponentIndex*/, const SViewInfo& rkViewInfo) { - CDrawUtil::DrawLightBillboard(mpLight->GetType(), mpLight->GetColor(), mPosition, BillboardScale(), TintColor(ViewInfo)); + CDrawUtil::DrawLightBillboard(mpLight->Type(), mpLight->Color(), mPosition, BillboardScale(), TintColor(rkViewInfo)); } void CLightNode::DrawSelection() { - CDrawUtil::DrawWireSphere(mPosition, mpLight->GetRadius(), mpLight->GetColor()); + CDrawUtil::DrawWireSphere(mPosition, mpLight->GetRadius(), mpLight->Color()); } -void CLightNode::RayAABoxIntersectTest(CRayCollisionTester& Tester, const SViewInfo& /*ViewInfo*/) +void CLightNode::RayAABoxIntersectTest(CRayCollisionTester& rTester, const SViewInfo& /*ViewInfo*/) { CVector2f BillScale = BillboardScale(); - float ScaleXY = (BillScale.x > BillScale.y ? BillScale.x : BillScale.y); + float ScaleXY = (BillScale.X > BillScale.Y ? BillScale.X : BillScale.Y); - CAABox BillBox = CAABox(mPosition + CVector3f(-ScaleXY, -ScaleXY, -BillScale.y), - mPosition + CVector3f( ScaleXY, ScaleXY, BillScale.y)); + CAABox BillBox = CAABox(mPosition + CVector3f(-ScaleXY, -ScaleXY, -BillScale.Y), + mPosition + CVector3f( ScaleXY, ScaleXY, BillScale.Y)); - std::pair BoxResult = BillBox.IntersectsRay(Tester.Ray()); - if (BoxResult.first) Tester.AddNode(this, 0, BoxResult.second); + std::pair BoxResult = BillBox.IntersectsRay(rTester.Ray()); + if (BoxResult.first) rTester.AddNode(this, 0, BoxResult.second); } -SRayIntersection CLightNode::RayNodeIntersectTest(const CRay& Ray, u32 AssetID, const SViewInfo& ViewInfo) +SRayIntersection CLightNode::RayNodeIntersectTest(const CRay& rkRay, u32 AssetID, const SViewInfo& rkViewInfo) { // todo: come up with a better way to share this code between CScriptNode and CLightNode - SRayIntersection out; - out.pNode = this; - out.ComponentIndex = AssetID; + SRayIntersection Out; + Out.pNode = this; + Out.ComponentIndex = AssetID; - CTexture *pBillboard = CDrawUtil::GetLightTexture(mpLight->GetType()); + CTexture *pBillboard = CDrawUtil::GetLightTexture(mpLight->Type()); if (!pBillboard) { - out.Hit = false; - return out; + Out.Hit = false; + return Out; } // Step 1: check whether the ray intersects with the plane the billboard is on - CPlane BillboardPlane(-ViewInfo.pCamera->Direction(), mPosition); - std::pair PlaneTest = Math::RayPlaneIntersecton(Ray, BillboardPlane); + CPlane BillboardPlane(-rkViewInfo.pCamera->Direction(), mPosition); + std::pair PlaneTest = Math::RayPlaneIntersecton(rkRay, BillboardPlane); if (PlaneTest.first) { // Step 2: transform the hit point into the plane's local space - CVector3f PlaneHitPoint = Ray.PointOnRay(PlaneTest.second); + CVector3f PlaneHitPoint = rkRay.PointOnRay(PlaneTest.second); CVector3f RelHitPoint = PlaneHitPoint - mPosition; - CVector3f PlaneForward = -ViewInfo.pCamera->Direction(); - CVector3f PlaneRight = -ViewInfo.pCamera->RightVector(); - CVector3f PlaneUp = ViewInfo.pCamera->UpVector(); + CVector3f PlaneForward = -rkViewInfo.pCamera->Direction(); + CVector3f PlaneRight = -rkViewInfo.pCamera->RightVector(); + CVector3f PlaneUp = rkViewInfo.pCamera->UpVector(); CQuaternion PlaneRot = CQuaternion::FromAxes(PlaneRight, PlaneForward, PlaneUp); CVector3f RotatedHitPoint = PlaneRot.Inverse() * RelHitPoint; - CVector2f LocalHitPoint = RotatedHitPoint.xz() / BillboardScale(); + CVector2f LocalHitPoint = RotatedHitPoint.XZ() / BillboardScale(); // Step 3: check whether the transformed hit point is in the -1 to 1 range - if ((LocalHitPoint.x >= -1.f) && (LocalHitPoint.x <= 1.f) && (LocalHitPoint.y >= -1.f) && (LocalHitPoint.y <= 1.f)) + if ((LocalHitPoint.X >= -1.f) && (LocalHitPoint.X <= 1.f) && (LocalHitPoint.Y >= -1.f) && (LocalHitPoint.Y <= 1.f)) { // Step 4: look up the hit texel and check whether it's transparent or opaque CVector2f TexCoord = (LocalHitPoint + CVector2f(1.f)) * 0.5f; - TexCoord.x = -TexCoord.x + 1.f; + TexCoord.X = -TexCoord.X + 1.f; float TexelAlpha = pBillboard->ReadTexelAlpha(TexCoord); if (TexelAlpha < 0.25f) - out.Hit = false; + Out.Hit = false; else { // It's opaque... we have a hit! - out.Hit = true; - out.Distance = PlaneTest.second; + Out.Hit = true; + Out.Distance = PlaneTest.second; } } else - out.Hit = false; + Out.Hit = false; } else - out.Hit = false; + Out.Hit = false; - return out; + return Out; } CLight* CLightNode::Light() @@ -132,7 +132,7 @@ CLight* CLightNode::Light() CVector2f CLightNode::BillboardScale() { - return AbsoluteScale().xz() * 0.75f; + return AbsoluteScale().XZ() * 0.75f; } void CLightNode::CalculateTransform(CTransform4f& rOut) const diff --git a/src/Core/Scene/CModelNode.cpp b/src/Core/Scene/CModelNode.cpp index f0c583de..556488eb 100644 --- a/src/Core/Scene/CModelNode.cpp +++ b/src/Core/Scene/CModelNode.cpp @@ -6,13 +6,13 @@ CModelNode::CModelNode(CScene *pScene, u32 NodeID, CSceneNode *pParent, CModel *pModel) : CSceneNode(pScene, NodeID, pParent) + , mWorldModel(false) + , mForceAlphaOn(false) + , mEnableScanOverlay(false) + , mTintColor(CColor::skWhite) { + mScale = CVector3f::skOne; SetModel(pModel); - mScale = CVector3f(1.f); - mWorldModel = false; - mForceAlphaOn = false; - mEnableScanOverlay = false; - mTintColor = CColor::skWhite; } ENodeType CModelNode::NodeType() @@ -29,22 +29,22 @@ void CModelNode::PostLoad() } } -void CModelNode::AddToRenderer(CRenderer *pRenderer, const SViewInfo& ViewInfo) +void CModelNode::AddToRenderer(CRenderer *pRenderer, const SViewInfo& rkViewInfo) { if (!mpModel) return; - if (!ViewInfo.ViewFrustum.BoxInFrustum(AABox())) return; - if (ViewInfo.GameMode) return; + if (!rkViewInfo.ViewFrustum.BoxInFrustum(AABox())) return; + if (rkViewInfo.GameMode) return; if (!mpModel->HasTransparency(mActiveMatSet)) pRenderer->AddOpaqueMesh(this, -1, AABox(), eDrawMesh); else - AddSurfacesToRenderer(pRenderer, mpModel, mActiveMatSet, ViewInfo); + AddSurfacesToRenderer(pRenderer, mpModel, mActiveMatSet, rkViewInfo); if (mSelected) pRenderer->AddOpaqueMesh(this, -1, AABox(), eDrawSelection); } -void CModelNode::Draw(FRenderOptions Options, int ComponentIndex, const SViewInfo& ViewInfo) +void CModelNode::Draw(FRenderOptions Options, int ComponentIndex, const SViewInfo& rkViewInfo) { if (!mpModel) return; if (mForceAlphaOn) Options = (FRenderOptions) (Options & ~eNoAlpha); @@ -59,7 +59,7 @@ void CModelNode::Draw(FRenderOptions Options, int ComponentIndex, const SViewInf } else { - bool IsLightingEnabled = CGraphics::sLightMode == CGraphics::eWorldLighting || ViewInfo.GameMode; + bool IsLightingEnabled = CGraphics::sLightMode == CGraphics::eWorldLighting || rkViewInfo.GameMode; if (IsLightingEnabled) { @@ -71,7 +71,7 @@ void CModelNode::Draw(FRenderOptions Options, int ComponentIndex, const SViewInf else { - LoadLights(ViewInfo); + LoadLights(rkViewInfo); if (CGraphics::sLightMode == CGraphics::eNoLighting) CGraphics::sVertexBlock.COLOR0_Amb = CColor::skWhite; } @@ -80,7 +80,7 @@ void CModelNode::Draw(FRenderOptions Options, int ComponentIndex, const SViewInf CGraphics::sPixelBlock.TevColor = CColor(Mul,Mul,Mul); } - CGraphics::sPixelBlock.TintColor = TintColor(ViewInfo); + CGraphics::sPixelBlock.TintColor = TintColor(rkViewInfo); LoadModelMatrix(); if (ComponentIndex < 0) @@ -108,40 +108,40 @@ void CModelNode::DrawSelection() mpModel->DrawWireframe(eNoRenderOptions, WireframeColor()); } -void CModelNode::RayAABoxIntersectTest(CRayCollisionTester& Tester, const SViewInfo& /*ViewInfo*/) +void CModelNode::RayAABoxIntersectTest(CRayCollisionTester& rTester, const SViewInfo& /*rkViewInfo*/) { if (!mpModel) return; - const CRay& Ray = Tester.Ray(); - std::pair BoxResult = AABox().IntersectsRay(Ray); + const CRay& rkRay = rTester.Ray(); + std::pair BoxResult = AABox().IntersectsRay(rkRay); if (BoxResult.first) - Tester.AddNodeModel(this, mpModel); + rTester.AddNodeModel(this, mpModel); } -SRayIntersection CModelNode::RayNodeIntersectTest(const CRay &Ray, u32 AssetID, const SViewInfo& ViewInfo) +SRayIntersection CModelNode::RayNodeIntersectTest(const CRay& rkRay, u32 AssetID, const SViewInfo& rkViewInfo) { - SRayIntersection out; - out.pNode = this; - out.ComponentIndex = AssetID; + SRayIntersection Out; + Out.pNode = this; + Out.ComponentIndex = AssetID; - CRay TransformedRay = Ray.Transformed(Transform().Inverse()); - FRenderOptions options = ViewInfo.pRenderer->RenderOptions(); - std::pair Result = mpModel->GetSurface(AssetID)->IntersectsRay(TransformedRay, ((options & eEnableBackfaceCull) == 0)); + CRay TransformedRay = rkRay.Transformed(Transform().Inverse()); + FRenderOptions Options = rkViewInfo.pRenderer->RenderOptions(); + std::pair Result = mpModel->GetSurface(AssetID)->IntersectsRay(TransformedRay, ((Options & eEnableBackfaceCull) == 0)); if (Result.first) { - out.Hit = true; + Out.Hit = true; CVector3f HitPoint = TransformedRay.PointOnRay(Result.second); CVector3f WorldHitPoint = Transform() * HitPoint; - out.Distance = Math::Distance(Ray.Origin(), WorldHitPoint); + Out.Distance = Math::Distance(rkRay.Origin(), WorldHitPoint); } else - out.Hit = false; + Out.Hit = false; - return out; + return Out; } CColor CModelNode::TintColor(const SViewInfo& /*rkViewInfo*/) const diff --git a/src/Core/Scene/CModelNode.h b/src/Core/Scene/CModelNode.h index 799d5476..13a7d10d 100644 --- a/src/Core/Scene/CModelNode.h +++ b/src/Core/Scene/CModelNode.h @@ -19,11 +19,11 @@ public: virtual ENodeType NodeType(); virtual void PostLoad(); - virtual void AddToRenderer(CRenderer *pRenderer, const SViewInfo& ViewInfo); - virtual void Draw(FRenderOptions Options, int ComponentIndex, const SViewInfo& ViewInfo); + virtual void AddToRenderer(CRenderer *pRenderer, const SViewInfo& rkViewInfo); + virtual void Draw(FRenderOptions Options, int ComponentIndex, const SViewInfo& rkViewInfo); virtual void DrawSelection(); - virtual void RayAABoxIntersectTest(CRayCollisionTester& Tester, const SViewInfo& ViewInfo); - virtual SRayIntersection RayNodeIntersectTest(const CRay &Ray, u32 AssetID, const SViewInfo& ViewInfo); + virtual void RayAABoxIntersectTest(CRayCollisionTester& Tester, const SViewInfo& rkViewInfo); + virtual SRayIntersection RayNodeIntersectTest(const CRay &Ray, u32 AssetID, const SViewInfo& rkViewInfo); virtual CColor TintColor(const SViewInfo& rkViewInfo) const; // Setters diff --git a/src/Core/Scene/CRootNode.h b/src/Core/Scene/CRootNode.h index 2389be67..46ead301 100644 --- a/src/Core/Scene/CRootNode.h +++ b/src/Core/Scene/CRootNode.h @@ -12,13 +12,15 @@ public: : CSceneNode(pScene, NodeID, pParent) {} ~CRootNode() {} - ENodeType NodeType() { + ENodeType NodeType() + { return eRootNode; } inline void RayAABoxIntersectTest(CRayCollisionTester&, const SViewInfo&) {} - inline SRayIntersection RayNodeIntersectTest(const CRay &, u32, const SViewInfo&) { + inline SRayIntersection RayNodeIntersectTest(const CRay &, u32, const SViewInfo&) + { return SRayIntersection(); } diff --git a/src/Core/Scene/CScene.cpp b/src/Core/Scene/CScene.cpp index fabc5c79..39a2efa9 100644 --- a/src/Core/Scene/CScene.cpp +++ b/src/Core/Scene/CScene.cpp @@ -147,17 +147,17 @@ void CScene::DeleteNode(CSceneNode *pNode) { CScriptNode *pScript = static_cast(pNode); - auto it = mScriptMap.find(pScript->Object()->InstanceID()); + auto it = mScriptMap.find(pScript->Instance()->InstanceID()); if (it != mScriptMap.end()) mScriptMap.erase(it); - switch (pScript->Object()->ObjectTypeID()) + switch (pScript->Instance()->ObjectTypeID()) { case 0x4E: case 0x52454141: for (auto it = mAreaAttributesObjects.begin(); it != mAreaAttributesObjects.end(); it++) { - if ((*it).Instance() == pScript->Object()) + if ((*it).Instance() == pScript->Instance()) { mAreaAttributesObjects.erase(it); break; @@ -182,32 +182,32 @@ void CScene::SetActiveArea(CGameArea *pArea) mpAreaRootNode = new CRootNode(this, -1, mpSceneRootNode); // Create static nodes - u32 Count = mpArea->GetStaticModelCount(); + u32 Count = mpArea->NumStaticModels(); for (u32 iMdl = 0; iMdl < Count; iMdl++) { - CStaticNode *pNode = CreateStaticNode(mpArea->GetStaticModel(iMdl)); + CStaticNode *pNode = CreateStaticNode(mpArea->StaticModel(iMdl)); pNode->SetName("Static World Model " + TString::FromInt32(iMdl, 0, 10)); } // Create model nodes - Count = mpArea->GetTerrainModelCount(); + Count = mpArea->NumWorldModels(); for (u32 iMdl = 0; iMdl < Count; iMdl++) { - CModel *pModel = mpArea->GetTerrainModel(iMdl); + CModel *pModel = mpArea->TerrainModel(iMdl); CModelNode *pNode = CreateModelNode(pModel); pNode->SetName("World Model " + TString::FromInt32(iMdl, 0, 10)); pNode->SetWorldModel(true); } - CreateCollisionNode(mpArea->GetCollision()); + CreateCollisionNode(mpArea->Collision()); - u32 NumLayers = mpArea->GetScriptLayerCount(); + u32 NumLayers = mpArea->NumScriptLayers(); for (u32 iLyr = 0; iLyr < NumLayers; iLyr++) { - CScriptLayer *pLayer = mpArea->GetScriptLayer(iLyr); + CScriptLayer *pLayer = mpArea->ScriptLayer(iLyr); u32 NumObjects = pLayer->NumInstances(); mNodes[eScriptNode].reserve(mNodes[eScriptNode].size() + NumObjects); @@ -218,7 +218,7 @@ void CScene::SetActiveArea(CGameArea *pArea) } } - CScriptLayer *pGenLayer = mpArea->GetGeneratorLayer(); + CScriptLayer *pGenLayer = mpArea->GeneratedObjectsLayer(); if (pGenLayer) { for (u32 iObj = 0; iObj < pGenLayer->NumInstances(); iObj++) @@ -236,19 +236,19 @@ void CScene::SetActiveArea(CGameArea *pArea) pScript->BuildLightList(mpArea); } - u32 NumLightLayers = mpArea->GetLightLayerCount(); + u32 NumLightLayers = mpArea->NumLightLayers(); CGraphics::sAreaAmbientColor = CColor::skBlack; for (u32 iLyr = 0; iLyr < NumLightLayers; iLyr++) { - u32 NumLights = mpArea->GetLightCount(iLyr); + u32 NumLights = mpArea->NumLights(iLyr); for (u32 iLit = 0; iLit < NumLights; iLit++) { - CLight *pLight = mpArea->GetLight(iLyr, iLit); + CLight *pLight = mpArea->Light(iLyr, iLit); - if (pLight->GetType() == eLocalAmbient) - CGraphics::sAreaAmbientColor += pLight->GetColor(); + if (pLight->Type() == eLocalAmbient) + CGraphics::sAreaAmbientColor += pLight->Color(); CreateLightNode(pLight); } @@ -285,36 +285,36 @@ void CScene::ClearScene() mpArea = nullptr; } -void CScene::AddSceneToRenderer(CRenderer *pRenderer, const SViewInfo& ViewInfo) +void CScene::AddSceneToRenderer(CRenderer *pRenderer, const SViewInfo& rkViewInfo) { // Call PostLoad the first time the scene is rendered to ensure the OpenGL context has been created before it runs. if (!mRanPostLoad) PostLoad(); // Override show flags in game mode - FShowFlags ShowFlags = (ViewInfo.GameMode ? gkGameModeShowFlags : ViewInfo.ShowFlags); + FShowFlags ShowFlags = (rkViewInfo.GameMode ? gkGameModeShowFlags : rkViewInfo.ShowFlags); FNodeFlags NodeFlags = NodeFlagsForShowFlags(ShowFlags); for (CSceneIterator It(this, NodeFlags, false); It; ++It) { - if (ViewInfo.GameMode || It->IsVisible()) - It->AddToRenderer(pRenderer, ViewInfo); + if (rkViewInfo.GameMode || It->IsVisible()) + It->AddToRenderer(pRenderer, rkViewInfo); } } -SRayIntersection CScene::SceneRayCast(const CRay& Ray, const SViewInfo& ViewInfo) +SRayIntersection CScene::SceneRayCast(const CRay& rkRay, const SViewInfo& rkViewInfo) { - FShowFlags ShowFlags = (ViewInfo.GameMode ? gkGameModeShowFlags : ViewInfo.ShowFlags); + FShowFlags ShowFlags = (rkViewInfo.GameMode ? gkGameModeShowFlags : rkViewInfo.ShowFlags); FNodeFlags NodeFlags = NodeFlagsForShowFlags(ShowFlags); - CRayCollisionTester Tester(Ray); + CRayCollisionTester Tester(rkRay); for (CSceneIterator It(this, NodeFlags, false); It; ++It) { if (It->IsVisible()) - It->RayAABoxIntersectTest(Tester, ViewInfo); + It->RayAABoxIntersectTest(Tester, rkViewInfo); } - return Tester.TestNodes(ViewInfo); + return Tester.TestNodes(rkViewInfo); } CSceneNode* CScene::NodeByID(u32 NodeID) @@ -333,7 +333,7 @@ CScriptNode* CScene::NodeForInstanceID(u32 InstanceID) else return nullptr; } -CScriptNode* CScene::NodeForObject(CScriptObject *pObj) +CScriptNode* CScene::NodeForInstance(CScriptObject *pObj) { return NodeForInstanceID(pObj->InstanceID()); } @@ -352,7 +352,7 @@ CLightNode* CScene::NodeForLight(CLight *pLight) return nullptr; } -CModel* CScene::GetActiveSkybox() +CModel* CScene::ActiveSkybox() { bool SkyEnabled = false; @@ -372,11 +372,11 @@ CModel* CScene::GetActiveSkybox() } } - if (SkyEnabled) return mpWorld->GetDefaultSkybox(); + if (SkyEnabled) return mpWorld->DefaultSkybox(); else return nullptr; } -CGameArea* CScene::GetActiveArea() +CGameArea* CScene::ActiveArea() { return mpArea; } diff --git a/src/Core/Scene/CScene.h b/src/Core/Scene/CScene.h index 255f2d35..6a42b174 100644 --- a/src/Core/Scene/CScene.h +++ b/src/Core/Scene/CScene.h @@ -64,12 +64,10 @@ public: SRayIntersection SceneRayCast(const CRay& rkRay, const SViewInfo& rkViewInfo); CSceneNode* NodeByID(u32 NodeID); CScriptNode* NodeForInstanceID(u32 InstanceID); - CScriptNode* NodeForObject(CScriptObject *pObj); + CScriptNode* NodeForInstance(CScriptObject *pObj); CLightNode* NodeForLight(CLight *pLight); - - // Setters/Getters - CModel* GetActiveSkybox(); - CGameArea* GetActiveArea(); + CModel* ActiveSkybox(); + CGameArea* ActiveArea(); // Static static FShowFlags ShowFlagsForNodeFlags(FNodeFlags NodeFlags); diff --git a/src/Core/Scene/CSceneNode.cpp b/src/Core/Scene/CSceneNode.cpp index 99975881..197944c7 100644 --- a/src/Core/Scene/CSceneNode.cpp +++ b/src/Core/Scene/CSceneNode.cpp @@ -4,7 +4,6 @@ #include "Core/Render/CDrawUtil.h" #include "Core/Resource/CGameArea.h" #include "Core/Resource/CResCache.h" -#include #include #include @@ -13,27 +12,23 @@ u32 CSceneNode::smNumNodes = 0; CColor CSceneNode::skSelectionTint = CColor::Integral(39, 154, 167); CSceneNode::CSceneNode(CScene *pScene, u32 NodeID, CSceneNode *pParent) + : mpScene(pScene) + , mpParent(pParent) + , _mID(NodeID) + , mPosition(CVector3f::skZero) + , mRotation(CQuaternion::skIdentity) + , mScale(CVector3f::skOne) + , _mTransformDirty(true) + , _mInheritsPosition(true) + , _mInheritsRotation(true) + , _mInheritsScale(true) + , mLightLayerIndex(0) + , mLightCount(0) + , mMouseHovering(false) + , mSelected(false) + , mVisible(true) { smNumNodes++; - mpScene = pScene; - mpParent = pParent; - _mID = NodeID; - - mPosition = CVector3f::skZero; - mRotation = CQuaternion::skIdentity; - mScale = CVector3f::skOne; - _mTransformDirty = true; - - _mInheritsPosition = true; - _mInheritsRotation = true; - _mInheritsScale = true; - - mLightLayerIndex = 0; - mLightCount = 0; - - mMouseHovering = false; - mSelected = false; - mVisible = true; if (mpParent) mpParent->mChildren.push_back(this); @@ -53,13 +48,13 @@ void CSceneNode::DrawSelection() CDrawUtil::DrawWireCube(AABox(), CColor::skWhite); } -void CSceneNode::RayAABoxIntersectTest(CRayCollisionTester& Tester, const SViewInfo& /*ViewInfo*/) +void CSceneNode::RayAABoxIntersectTest(CRayCollisionTester& rTester, const SViewInfo& /*rkViewInfo*/) { // Default implementation for virtual function - std::pair result = AABox().IntersectsRay(Tester.Ray()); + std::pair Result = AABox().IntersectsRay(rTester.Ray()); - if (result.first) - Tester.AddNode(this, -1, result.second); + if (Result.first) + rTester.AddNode(this, -1, Result.second); } bool CSceneNode::IsVisible() const @@ -68,10 +63,10 @@ bool CSceneNode::IsVisible() const return mVisible; } -CColor CSceneNode::TintColor(const SViewInfo& ViewInfo) const +CColor CSceneNode::TintColor(const SViewInfo& rkViewInfo) const { // Default implementation for virtual function - return (IsSelected() && !ViewInfo.GameMode ? skSelectionTint : CColor::skWhite); + return (IsSelected() && !rkViewInfo.GameMode ? skSelectionTint : CColor::skWhite); } CColor CSceneNode::WireframeColor() const @@ -138,8 +133,8 @@ void CSceneNode::BuildLightList(CGameArea *pArea) mLightCount = 0; mAmbientColor = CColor::skBlack; - u32 index = mLightLayerIndex; - if ((pArea->GetLightLayerCount() <= index) || (pArea->GetLightCount(index) == 0)) index = 0; + u32 Index = mLightLayerIndex; + if ((pArea->NumLightLayers() <= Index) || (pArea->NumLights(Index) == 0)) Index = 0; struct SLightEntry { CLight *pLight; @@ -148,32 +143,32 @@ void CSceneNode::BuildLightList(CGameArea *pArea) SLightEntry(CLight *_pLight, float _Distance) : pLight(_pLight), Distance(_Distance) {} - bool operator<(const SLightEntry& other) { - return (Distance < other.Distance); + bool operator<(const SLightEntry& rkOther) { + return (Distance < rkOther.Distance); } }; std::vector LightEntries; // Default ambient color to white if there are no lights on the selected layer - u32 numLights = pArea->GetLightCount(index); - if (numLights == 0) mAmbientColor = CColor::skWhite; + u32 NumLights = pArea->NumLights(Index); + if (NumLights == 0) mAmbientColor = CColor::skWhite; - for (u32 iLight = 0; iLight < numLights; iLight++) + for (u32 iLight = 0; iLight < NumLights; iLight++) { - CLight* pLight = pArea->GetLight(index, iLight); + CLight* pLight = pArea->Light(Index, iLight); // Ambient lights should only be present one per layer; need to check how the game deals with multiple ambients - if (pLight->GetType() == eLocalAmbient) - mAmbientColor = pLight->GetColor(); + if (pLight->Type() == eLocalAmbient) + mAmbientColor = pLight->Color(); // Other lights will be used depending which are closest to the node else { - bool IsInRange = AABox().IntersectsSphere(pLight->GetPosition(), pLight->GetRadius()); + bool IsInRange = AABox().IntersectsSphere(pLight->Position(), pLight->GetRadius()); if (IsInRange) { - float Dist = mPosition.Distance(pLight->GetPosition()); + float Dist = mPosition.Distance(pLight->Position()); LightEntries.push_back(SLightEntry(pLight, Dist)); } } @@ -183,14 +178,14 @@ void CSceneNode::BuildLightList(CGameArea *pArea) std::sort(LightEntries.begin(), LightEntries.end()); mLightCount = (LightEntries.size() > 8) ? 8 : LightEntries.size(); - for (u32 i = 0; i < mLightCount; i++) - mLights[i] = LightEntries[i].pLight; + for (u32 iLight = 0; iLight < mLightCount; iLight++) + mLights[iLight] = LightEntries[iLight].pLight; } -void CSceneNode::LoadLights(const SViewInfo& ViewInfo) +void CSceneNode::LoadLights(const SViewInfo& rkViewInfo) { CGraphics::sNumLights = 0; - CGraphics::ELightingMode Mode = (ViewInfo.GameMode ? CGraphics::eWorldLighting : CGraphics::sLightMode); + CGraphics::ELightingMode Mode = (rkViewInfo.GameMode ? CGraphics::eWorldLighting : CGraphics::sLightMode); switch (Mode) { @@ -248,38 +243,38 @@ void CSceneNode::AddSurfacesToRenderer(CRenderer *pRenderer, CModel *pModel, u32 } // ************ TRANSFORM ************ -void CSceneNode::Translate(const CVector3f& translation, ETransformSpace transformSpace) +void CSceneNode::Translate(const CVector3f& rkTranslation, ETransformSpace TransformSpace) { - switch (transformSpace) + switch (TransformSpace) { case eWorldTransform: - mPosition += translation; + mPosition += rkTranslation; break; case eLocalTransform: - mPosition += mRotation * translation; + mPosition += mRotation * rkTranslation; break; } MarkTransformChanged(); } -void CSceneNode::Rotate(const CQuaternion& rotation, ETransformSpace transformSpace) +void CSceneNode::Rotate(const CQuaternion& rkRotation, ETransformSpace TransformSpace) { - switch (transformSpace) + switch (TransformSpace) { case eWorldTransform: - mRotation = rotation * mRotation; + mRotation = rkRotation * mRotation; break; case eLocalTransform: - mRotation *= rotation; + mRotation *= rkRotation; break; } MarkTransformChanged(); } -void CSceneNode::Scale(const CVector3f& scale) +void CSceneNode::Scale(const CVector3f& rkScale) { // No support for stretch/skew world-space scaling; local only - mScale *= scale; + mScale *= rkScale; MarkTransformChanged(); } @@ -327,31 +322,6 @@ void CSceneNode::CalculateTransform(CTransform4f& rOut) const } // ************ GETTERS ************ -TString CSceneNode::Name() const -{ - return mName; -} - -CSceneNode* CSceneNode::Parent() const -{ - return mpParent; -} - -CScene* CSceneNode::Scene() const -{ - return mpScene; -} - -u32 CSceneNode::ID() const -{ - return _mID; -} - -CVector3f CSceneNode::LocalPosition() const -{ - return mPosition; -} - CVector3f CSceneNode::AbsolutePosition() const { CVector3f ret = mPosition; @@ -362,11 +332,6 @@ CVector3f CSceneNode::AbsolutePosition() const return ret; } -CQuaternion CSceneNode::LocalRotation() const -{ - return mRotation; -} - CQuaternion CSceneNode::AbsoluteRotation() const { CQuaternion ret = mRotation; @@ -377,11 +342,6 @@ CQuaternion CSceneNode::AbsoluteRotation() const return ret; } -CVector3f CSceneNode::LocalScale() const -{ - return mScale; -} - CVector3f CSceneNode::AbsoluteScale() const { CVector3f ret = mScale; @@ -399,96 +359,3 @@ CAABox CSceneNode::AABox() const return _mCachedAABox; } - -CVector3f CSceneNode::CenterPoint() const -{ - return AABox().Center(); -} - -u32 CSceneNode::LightLayerIndex() const -{ - return mLightLayerIndex; -} - -bool CSceneNode::MarkedVisible() const -{ - // The reason I have this function is because the instance view needs to know whether a node is marked - // visible independently from other factors that may affect node visibility (as returned by IsVisible()). - // It's a little confusing, so maybe there's a better way to set this up. - return mVisible; -} - -bool CSceneNode::IsMouseHovering() const -{ - return mMouseHovering; -} - -bool CSceneNode::IsSelected() const -{ - return mSelected; -} - -bool CSceneNode::InheritsPosition() const -{ - return _mInheritsPosition; -} - -bool CSceneNode::InheritsRotation() const -{ - return _mInheritsRotation; -} - -bool CSceneNode::InheritsScale() const -{ - return _mInheritsScale; -} - -// ************ SETTERS ************ -void CSceneNode::SetName(const TString& Name) -{ - mName = Name; -} - -void CSceneNode::SetPosition(const CVector3f& position) -{ - mPosition = position; - MarkTransformChanged(); -} - -void CSceneNode::SetRotation(const CQuaternion& rotation) -{ - mRotation = rotation; - MarkTransformChanged(); -} - -void CSceneNode::SetRotation(const CVector3f& rotEuler) -{ - mRotation = CQuaternion::FromEuler(rotEuler); - MarkTransformChanged(); -} - -void CSceneNode::SetScale(const CVector3f& scale) -{ - mScale = scale; - MarkTransformChanged(); -} - -void CSceneNode::SetLightLayerIndex(u32 index) -{ - mLightLayerIndex = index; -} - -void CSceneNode::SetMouseHovering(bool Hovering) -{ - mMouseHovering = Hovering; -} - -void CSceneNode::SetSelected(bool Selected) -{ - mSelected = Selected; -} - -void CSceneNode::SetVisible(bool Visible) -{ - mVisible = Visible; -} diff --git a/src/Core/Scene/CSceneNode.h b/src/Core/Scene/CSceneNode.h index 99daa083..c5583ed1 100644 --- a/src/Core/Scene/CSceneNode.h +++ b/src/Core/Scene/CSceneNode.h @@ -58,15 +58,15 @@ public: virtual ENodeType NodeType() = 0; virtual void PostLoad() {} virtual void OnTransformed() {} - virtual void AddToRenderer(CRenderer* /*pRenderer*/, const SViewInfo& /*ViewInfo*/) {} + virtual void AddToRenderer(CRenderer* /*pRenderer*/, const SViewInfo& /*rkViewInfo*/) {} virtual void DrawSelection(); - virtual void RayAABoxIntersectTest(CRayCollisionTester& Tester, const SViewInfo& ViewInfo); - virtual SRayIntersection RayNodeIntersectTest(const CRay& Ray, u32 AssetID, const SViewInfo& ViewInfo) = 0; + virtual void RayAABoxIntersectTest(CRayCollisionTester& rTester, const SViewInfo& rkViewInfo); + virtual SRayIntersection RayNodeIntersectTest(const CRay& rkRay, u32 AssetID, const SViewInfo& rkViewInfo) = 0; virtual bool AllowsTranslate() const { return true; } virtual bool AllowsRotate() const { return true; } virtual bool AllowsScale() const { return true; } virtual bool IsVisible() const; - virtual CColor TintColor(const SViewInfo& ViewInfo) const; + virtual CColor TintColor(const SViewInfo& rkViewInfo) const; virtual CColor WireframeColor() const; void OnLoadFinished(); @@ -76,15 +76,15 @@ public: void SetInheritance(bool InheritPos, bool InheritRot, bool InheritScale); void LoadModelMatrix(); void BuildLightList(CGameArea *pArea); - void LoadLights(const SViewInfo& ViewInfo); + void LoadLights(const SViewInfo& rkViewInfo); void DrawBoundingBox() const; void DrawRotationArrow() const; - void AddSurfacesToRenderer(CRenderer *pRenderer, CModel *pModel, u32 MatSet, const SViewInfo& ViewInfo); + void AddSurfacesToRenderer(CRenderer *pRenderer, CModel *pModel, u32 MatSet, const SViewInfo& rkViewInfo); // Transform - void Translate(const CVector3f& translation, ETransformSpace transformSpace); - void Rotate(const CQuaternion& rotation, ETransformSpace transformSpace); - void Scale(const CVector3f& scale); + void Translate(const CVector3f& rkTranslation, ETransformSpace TransformSpace); + void Rotate(const CQuaternion& rkRotation, ETransformSpace TransformSpace); + void Scale(const CVector3f& rkScale); const CTransform4f& Transform() const; protected: void MarkTransformChanged() const; @@ -92,37 +92,38 @@ protected: virtual void CalculateTransform(CTransform4f& rOut) const; public: - // Getters - TString Name() const; - CSceneNode* Parent() const; - CScene* Scene() const; - u32 ID() const; - CVector3f LocalPosition() const; CVector3f AbsolutePosition() const; - CQuaternion LocalRotation() const; CQuaternion AbsoluteRotation() const; - CVector3f LocalScale() const; CVector3f AbsoluteScale() const; CAABox AABox() const; - CVector3f CenterPoint() const; - u32 LightLayerIndex() const; - bool MarkedVisible() const; - bool IsMouseHovering() const; - bool IsSelected() const; - bool InheritsPosition() const; - bool InheritsRotation() const; - bool InheritsScale() const; + + // Inline Accessors + TString Name() const { return mName; } + CSceneNode* Parent() const { return mpParent; } + CScene* Scene() const { return mpScene; } + u32 ID() const { return _mID; } + CVector3f LocalPosition() const { return mPosition; } + CQuaternion LocalRotation() const { return mRotation; } + CVector3f LocalScale() const { return mScale; } + CVector3f CenterPoint() const { return AABox().Center(); } + u32 LightLayerIndex() const { return mLightLayerIndex; } + bool MarkedVisible() const { return mVisible; } + bool IsMouseHovering() const { return mMouseHovering; } + bool IsSelected() const { return mSelected; } + bool InheritsPosition() const { return _mInheritsPosition; } + bool InheritsRotation() const { return _mInheritsRotation; } + bool InheritsScale() const { return _mInheritsScale; } // Setters - void SetName(const TString& Name); - void SetPosition(const CVector3f& position); - void SetRotation(const CQuaternion& rotation); - void SetRotation(const CVector3f& rotEuler); - void SetScale(const CVector3f& scale); - void SetLightLayerIndex(u32 index); - void SetMouseHovering(bool Hovering); - void SetSelected(bool Selected); - void SetVisible(bool Visible); + void SetName(const TString& rkName) { mName = rkName; } + void SetPosition(const CVector3f& rkPosition) { mPosition = rkPosition; MarkTransformChanged(); } + void SetRotation(const CQuaternion& rkRotation) { mRotation = rkRotation; MarkTransformChanged(); } + void SetRotation(const CVector3f& rkRotEuler) { mRotation = CQuaternion::FromEuler(rkRotEuler); MarkTransformChanged(); } + void SetScale(const CVector3f& rkScale) { mScale = rkScale; MarkTransformChanged(); } + void SetLightLayerIndex(u32 Index) { mLightLayerIndex = Index; } + void SetMouseHovering(bool Hovering) { mMouseHovering = Hovering; } + void SetSelected(bool Selected) { mSelected = Selected; } + void SetVisible(bool Visible) { mVisible = Visible; } // Static inline static int NumNodes() { return smNumNodes; } diff --git a/src/Core/Scene/CScriptNode.cpp b/src/Core/Scene/CScriptNode.cpp index 54638319..672d8f9d 100644 --- a/src/Core/Scene/CScriptNode.cpp +++ b/src/Core/Scene/CScriptNode.cpp @@ -7,20 +7,19 @@ #include "Core/Resource/Script/CMasterTemplate.h" #include "Core/Resource/Script/CScriptLayer.h" #include "Core/ScriptExtra/CScriptExtra.h" -#include #include -CScriptNode::CScriptNode(CScene *pScene, u32 NodeID, CSceneNode *pParent, CScriptObject *pObject) +CScriptNode::CScriptNode(CScene *pScene, u32 NodeID, CSceneNode *pParent, CScriptObject *pInstance) : CSceneNode(pScene, NodeID, pParent) , mGameModeVisibility(eUntested) + , mpVolumePreviewNode(nullptr) + , mHasVolumePreview(false) + , mpInstance(pInstance) + , mpBillboard(nullptr) { - mpVolumePreviewNode = nullptr; - mHasVolumePreview = false; // Evaluate instance - mpInstance = pObject; SetActiveModel(nullptr); - mpBillboard = nullptr; mpCollisionNode = new CCollisionNode(pScene, -1, this); mpCollisionNode->SetInheritance(true, true, false); @@ -57,7 +56,7 @@ CScriptNode::CScriptNode(CScene *pScene, u32 NodeID, CSceneNode *pParent, CScrip } // Fetch LightParameters - mpLightParameters = new CLightParameters(mpInstance->LightParameters(), mpInstance->MasterTemplate()->GetGame()); + mpLightParameters = new CLightParameters(mpInstance->LightParameters(), mpInstance->MasterTemplate()->Game()); SetLightLayerIndex(mpLightParameters->LightLayerIndex()); } @@ -104,15 +103,15 @@ void CScriptNode::OnTransformed() mpExtra->OnTransformed(); } -void CScriptNode::AddToRenderer(CRenderer *pRenderer, const SViewInfo& ViewInfo) +void CScriptNode::AddToRenderer(CRenderer *pRenderer, const SViewInfo& rkViewInfo) { if (!mpInstance) return; // Add script extra to renderer first - if (mpExtra) mpExtra->AddToRenderer(pRenderer, ViewInfo); + if (mpExtra) mpExtra->AddToRenderer(pRenderer, rkViewInfo); // If we're in game mode, then override other visibility settings. - if (ViewInfo.GameMode) + if (rkViewInfo.GameMode) { if (mGameModeVisibility == eUntested) TestGameModeVisibility(); @@ -127,12 +126,12 @@ void CScriptNode::AddToRenderer(CRenderer *pRenderer, const SViewInfo& ViewInfo) if (ShouldDraw) { // Otherwise, we proceed as normal - if ((ViewInfo.ShowFlags & eShowObjectCollision) && (!ViewInfo.GameMode)) - mpCollisionNode->AddToRenderer(pRenderer, ViewInfo); + if ((rkViewInfo.ShowFlags & eShowObjectCollision) && (!rkViewInfo.GameMode)) + mpCollisionNode->AddToRenderer(pRenderer, rkViewInfo); - if (ViewInfo.ShowFlags & eShowObjectGeometry || ViewInfo.GameMode) + if (rkViewInfo.ShowFlags & eShowObjectGeometry || rkViewInfo.GameMode) { - if (ViewInfo.ViewFrustum.BoxInFrustum(AABox())) + if (rkViewInfo.ViewFrustum.BoxInFrustum(AABox())) { if (!mpActiveModel) pRenderer->AddOpaqueMesh(this, -1, AABox(), eDrawMesh); @@ -142,13 +141,13 @@ void CScriptNode::AddToRenderer(CRenderer *pRenderer, const SViewInfo& ViewInfo) if (!mpActiveModel->HasTransparency(0)) pRenderer->AddOpaqueMesh(this, -1, AABox(), eDrawMesh); else - AddSurfacesToRenderer(pRenderer, mpActiveModel, 0, ViewInfo); + AddSurfacesToRenderer(pRenderer, mpActiveModel, 0, rkViewInfo); } } } } - if (IsSelected() && !ViewInfo.GameMode) + if (IsSelected() && !rkViewInfo.GameMode) { // Script nodes always draw their selections regardless of frustum planes // in order to ensure that script connection lines don't get improperly culled. @@ -156,11 +155,11 @@ void CScriptNode::AddToRenderer(CRenderer *pRenderer, const SViewInfo& ViewInfo) pRenderer->AddOpaqueMesh(this, -1, AABox(), eDrawSelection); if (mHasVolumePreview && (!mpExtra || mpExtra->ShouldDrawVolume())) - mpVolumePreviewNode->AddToRenderer(pRenderer, ViewInfo); + mpVolumePreviewNode->AddToRenderer(pRenderer, rkViewInfo); } } -void CScriptNode::Draw(FRenderOptions Options, int ComponentIndex, const SViewInfo& ViewInfo) +void CScriptNode::Draw(FRenderOptions Options, int ComponentIndex, const SViewInfo& rkViewInfo) { if (!mpInstance) return; @@ -187,7 +186,7 @@ void CScriptNode::Draw(FRenderOptions Options, int ComponentIndex, const SViewIn } else - LoadLights(ViewInfo); + LoadLights(rkViewInfo); } LoadModelMatrix(); @@ -198,7 +197,7 @@ void CScriptNode::Draw(FRenderOptions Options, int ComponentIndex, const SViewIn if (mpExtra) CGraphics::sPixelBlock.TevColor = mpExtra->TevColor(); else CGraphics::sPixelBlock.TevColor = CColor::skWhite; - CGraphics::sPixelBlock.TintColor = TintColor(ViewInfo); + CGraphics::sPixelBlock.TintColor = TintColor(rkViewInfo); CGraphics::UpdatePixelBlock(); if (ComponentIndex < 0) @@ -214,14 +213,14 @@ void CScriptNode::Draw(FRenderOptions Options, int ComponentIndex, const SViewIn glDepthMask(GL_TRUE); CGraphics::UpdateVertexBlock(); CGraphics::UpdatePixelBlock(); - CDrawUtil::DrawShadedCube(CColor::skTransparentPurple * TintColor(ViewInfo)); + CDrawUtil::DrawShadedCube(CColor::skTransparentPurple * TintColor(rkViewInfo)); } } // Draw billboard else if (mpBillboard) { - CDrawUtil::DrawBillboard(mpBillboard, mPosition, BillboardScale(), TintColor(ViewInfo)); + CDrawUtil::DrawBillboard(mpBillboard, mPosition, BillboardScale(), TintColor(rkViewInfo)); } } @@ -275,7 +274,7 @@ void CScriptNode::DrawSelection() } } -void CScriptNode::RayAABoxIntersectTest(CRayCollisionTester& Tester, const SViewInfo& ViewInfo) +void CScriptNode::RayAABoxIntersectTest(CRayCollisionTester& rTester, const SViewInfo& rkViewInfo) { if (!mpInstance) return; @@ -283,7 +282,7 @@ void CScriptNode::RayAABoxIntersectTest(CRayCollisionTester& Tester, const SView // Let script extra do ray check first if (mpExtra) { - mpExtra->RayAABoxIntersectTest(Tester, ViewInfo); + mpExtra->RayAABoxIntersectTest(rTester, rkViewInfo); // If the extra doesn't want us rendering, then don't do the ray test either if (!mpExtra->ShouldDrawNormalAssets()) @@ -291,7 +290,7 @@ void CScriptNode::RayAABoxIntersectTest(CRayCollisionTester& Tester, const SView } // If we're in game mode, then check whether we're visible before proceeding with the ray test. - if (ViewInfo.GameMode) + if (rkViewInfo.GameMode) { if (mGameModeVisibility == eUntested) TestGameModeVisibility(); @@ -301,16 +300,16 @@ void CScriptNode::RayAABoxIntersectTest(CRayCollisionTester& Tester, const SView } // Otherwise, proceed with the ray test as normal... - const CRay& Ray = Tester.Ray(); + const CRay& rkRay = rTester.Ray(); if (UsesModel()) { - std::pair BoxResult = AABox().IntersectsRay(Ray); + std::pair BoxResult = AABox().IntersectsRay(rkRay); if (BoxResult.first) { - if (mpActiveModel) Tester.AddNodeModel(this, mpActiveModel); - else Tester.AddNode(this, 0, BoxResult.second); + if (mpActiveModel) rTester.AddNodeModel(this, mpActiveModel); + else rTester.AddNode(this, 0, BoxResult.second); } } @@ -318,43 +317,43 @@ void CScriptNode::RayAABoxIntersectTest(CRayCollisionTester& Tester, const SView { // Because the billboard rotates a lot, expand the AABox on the X/Y axes to cover any possible orientation CVector2f BillScale = BillboardScale(); - float ScaleXY = (BillScale.x > BillScale.y ? BillScale.x : BillScale.y); + float ScaleXY = (BillScale.X > BillScale.Y ? BillScale.X : BillScale.Y); - CAABox BillBox = CAABox(mPosition + CVector3f(-ScaleXY, -ScaleXY, -BillScale.y), - mPosition + CVector3f( ScaleXY, ScaleXY, BillScale.y)); + CAABox BillBox = CAABox(mPosition + CVector3f(-ScaleXY, -ScaleXY, -BillScale.Y), + mPosition + CVector3f( ScaleXY, ScaleXY, BillScale.Y)); - std::pair BoxResult = BillBox.IntersectsRay(Ray); - if (BoxResult.first) Tester.AddNode(this, 0, BoxResult.second); + std::pair BoxResult = BillBox.IntersectsRay(rkRay); + if (BoxResult.first) rTester.AddNode(this, 0, BoxResult.second); } } -SRayIntersection CScriptNode::RayNodeIntersectTest(const CRay& Ray, u32 AssetID, const SViewInfo& ViewInfo) +SRayIntersection CScriptNode::RayNodeIntersectTest(const CRay& rkRay, u32 AssetID, const SViewInfo& rkViewInfo) { - FRenderOptions Options = ViewInfo.pRenderer->RenderOptions(); + FRenderOptions Options = rkViewInfo.pRenderer->RenderOptions(); - SRayIntersection out; - out.pNode = this; - out.ComponentIndex = AssetID; + SRayIntersection Out; + Out.pNode = this; + Out.ComponentIndex = AssetID; // Model test if (UsesModel()) { CModel *pModel = (mpActiveModel ? mpActiveModel : CDrawUtil::GetCubeModel()); - CRay TransformedRay = Ray.Transformed(Transform().Inverse()); + CRay TransformedRay = rkRay.Transformed(Transform().Inverse()); std::pair Result = pModel->GetSurface(AssetID)->IntersectsRay(TransformedRay, ((Options & eEnableBackfaceCull) == 0)); if (Result.first) { - out.Hit = true; + Out.Hit = true; CVector3f HitPoint = TransformedRay.PointOnRay(Result.second); CVector3f WorldHitPoint = Transform() * HitPoint; - out.Distance = Math::Distance(Ray.Origin(), WorldHitPoint); + Out.Distance = Math::Distance(rkRay.Origin(), WorldHitPoint); } else - out.Hit = false; + Out.Hit = false; } // Billboard test @@ -362,51 +361,51 @@ SRayIntersection CScriptNode::RayNodeIntersectTest(const CRay& Ray, u32 AssetID, else { // Step 1: check whether the ray intersects with the plane the billboard is on - CPlane BillboardPlane(-ViewInfo.pCamera->Direction(), mPosition); - std::pair PlaneTest = Math::RayPlaneIntersecton(Ray, BillboardPlane); + CPlane BillboardPlane(-rkViewInfo.pCamera->Direction(), mPosition); + std::pair PlaneTest = Math::RayPlaneIntersecton(rkRay, BillboardPlane); if (PlaneTest.first) { // Step 2: transform the hit point into the plane's local space - CVector3f PlaneHitPoint = Ray.PointOnRay(PlaneTest.second); + CVector3f PlaneHitPoint = rkRay.PointOnRay(PlaneTest.second); CVector3f RelHitPoint = PlaneHitPoint - mPosition; - CVector3f PlaneForward = -ViewInfo.pCamera->Direction(); - CVector3f PlaneRight = -ViewInfo.pCamera->RightVector(); - CVector3f PlaneUp = ViewInfo.pCamera->UpVector(); + CVector3f PlaneForward = -rkViewInfo.pCamera->Direction(); + CVector3f PlaneRight = -rkViewInfo.pCamera->RightVector(); + CVector3f PlaneUp = rkViewInfo.pCamera->UpVector(); CQuaternion PlaneRot = CQuaternion::FromAxes(PlaneRight, PlaneForward, PlaneUp); CVector3f RotatedHitPoint = PlaneRot.Inverse() * RelHitPoint; - CVector2f LocalHitPoint = RotatedHitPoint.xz() / BillboardScale(); + CVector2f LocalHitPoint = RotatedHitPoint.XZ() / BillboardScale(); // Step 3: check whether the transformed hit point is in the -1 to 1 range - if ((LocalHitPoint.x >= -1.f) && (LocalHitPoint.x <= 1.f) && (LocalHitPoint.y >= -1.f) && (LocalHitPoint.y <= 1.f)) + if ((LocalHitPoint.X >= -1.f) && (LocalHitPoint.X <= 1.f) && (LocalHitPoint.Y >= -1.f) && (LocalHitPoint.Y <= 1.f)) { // Step 4: look up the hit texel and check whether it's transparent or opaque CVector2f TexCoord = (LocalHitPoint + CVector2f(1.f)) * 0.5f; - TexCoord.x = -TexCoord.x + 1.f; + TexCoord.X = -TexCoord.X + 1.f; float TexelAlpha = mpBillboard->ReadTexelAlpha(TexCoord); if (TexelAlpha < 0.25f) - out.Hit = false; + Out.Hit = false; else { // It's opaque... we have a hit! - out.Hit = true; - out.Distance = PlaneTest.second; + Out.Hit = true; + Out.Distance = PlaneTest.second; } } else - out.Hit = false; + Out.Hit = false; } else - out.Hit = false; + Out.Hit = false; } - return out; + return Out; } bool CScriptNode::AllowsRotate() const @@ -539,7 +538,7 @@ void CScriptNode::GeneratePosition() if (!mHasValidPosition) { // Default to center of the active area; this is to preven recursion issues - CTransform4f& AreaTransform = mpScene->GetActiveArea()->GetTransform(); + CTransform4f& AreaTransform = mpScene->ActiveArea()->Transform(); mPosition = CVector3f(AreaTransform[0][3], AreaTransform[1][3], AreaTransform[2][3]); mHasValidPosition = true; MarkTransformChanged(); @@ -555,9 +554,9 @@ void CScriptNode::GeneratePosition() CScriptNode *pNode = mpScene->NodeForInstanceID(LinkedID); pNode->GeneratePosition(); mPosition = pNode->AbsolutePosition(); - mPosition.z += (pNode->AABox().Size().z / 2.f); - mPosition.z += (AABox().Size().z / 2.f); - mPosition.z += 2.f; + mPosition.Z += (pNode->AABox().Size().Z / 2.f); + mPosition.Z += (AABox().Size().Z / 2.f); + mPosition.Z += 2.f; } // For two or more links, average out the position of the connected objects. @@ -588,7 +587,7 @@ void CScriptNode::GeneratePosition() } mPosition = NewPos / (float) NumLinks; - mPosition.x += 2.f; + mPosition.X += 2.f; } MarkTransformChanged(); @@ -611,7 +610,7 @@ CColor CScriptNode::WireframeColor() const return CColor::Integral(12, 135, 194); } -CScriptObject* CScriptNode::Object() const +CScriptObject* CScriptNode::Instance() const { return mpInstance; } @@ -651,8 +650,8 @@ CAABox CScriptNode::PreviewVolumeAABox() const CVector2f CScriptNode::BillboardScale() const { - CVector2f out = (Template()->ScaleType() == CScriptTemplate::eScaleEnabled ? AbsoluteScale().xz() : CVector2f(1.f)); - return out * 0.5f * Template()->PreviewScale(); + CVector2f Out = (Template()->ScaleType() == CScriptTemplate::eScaleEnabled ? AbsoluteScale().XZ() : CVector2f(1.f)); + return Out * 0.5f * Template()->PreviewScale(); } // ************ PROTECTED ************ diff --git a/src/Core/Scene/CScriptNode.h b/src/Core/Scene/CScriptNode.h index 2e1b6ba5..f6648105 100644 --- a/src/Core/Scene/CScriptNode.h +++ b/src/Core/Scene/CScriptNode.h @@ -34,15 +34,15 @@ public: ENodeType NodeType(); void PostLoad(); void OnTransformed(); - void AddToRenderer(CRenderer *pRenderer, const SViewInfo& ViewInfo); - void Draw(FRenderOptions Options, int ComponentIndex, const SViewInfo& ViewInfo); + void AddToRenderer(CRenderer *pRenderer, const SViewInfo& rkViewInfo); + void Draw(FRenderOptions Options, int ComponentIndex, const SViewInfo& rkViewInfo); void DrawSelection(); - void RayAABoxIntersectTest(CRayCollisionTester& Tester, const SViewInfo& ViewInfo); - SRayIntersection RayNodeIntersectTest(const CRay &Ray, u32 AssetID, const SViewInfo& ViewInfo); + void RayAABoxIntersectTest(CRayCollisionTester& rTester, const SViewInfo& rkViewInfo); + SRayIntersection RayNodeIntersectTest(const CRay& rkRay, u32 AssetID, const SViewInfo& rkViewInfo); bool AllowsRotate() const; bool AllowsScale() const; bool IsVisible() const; - CColor TintColor(const SViewInfo &ViewInfo) const; + CColor TintColor(const SViewInfo& rkViewInfo) const; CColor WireframeColor() const; void LinksModified(); @@ -50,7 +50,7 @@ public: void UpdatePreviewVolume(); void GeneratePosition(); void TestGameModeVisibility(); - CScriptObject* Object() const; + CScriptObject* Instance() const; CScriptTemplate* Template() const; CScriptExtra* Extra() const; CModel* ActiveModel() const; diff --git a/src/Core/Scene/CStaticNode.cpp b/src/Core/Scene/CStaticNode.cpp index cd714940..660e0401 100644 --- a/src/Core/Scene/CStaticNode.cpp +++ b/src/Core/Scene/CStaticNode.cpp @@ -2,15 +2,14 @@ #include "Core/Render/CGraphics.h" #include "Core/Render/CDrawUtil.h" #include "Core/Render/CRenderer.h" -#include #include CStaticNode::CStaticNode(CScene *pScene, u32 NodeID, CSceneNode *pParent, CStaticModel *pModel) : CSceneNode(pScene, NodeID, pParent) + , mpModel(pModel) { - mpModel = pModel; mLocalAABox = mpModel->AABox(); - mScale = CVector3f(1.f, 1.f, 1.f); + mScale = CVector3f::skOne; SetName("Static Node"); } @@ -28,11 +27,11 @@ void CStaticNode::PostLoad() } } -void CStaticNode::AddToRenderer(CRenderer *pRenderer, const SViewInfo& ViewInfo) +void CStaticNode::AddToRenderer(CRenderer *pRenderer, const SViewInfo& rkViewInfo) { if (!mpModel) return; if (mpModel->IsOccluder()) return; - if (!ViewInfo.ViewFrustum.BoxInFrustum(AABox())) return; + if (!rkViewInfo.ViewFrustum.BoxInFrustum(AABox())) return; if (!mpModel->IsTransparent()) pRenderer->AddOpaqueMesh(this, -1, AABox(), eDrawMesh); @@ -44,20 +43,20 @@ void CStaticNode::AddToRenderer(CRenderer *pRenderer, const SViewInfo& ViewInfo) { CAABox TransformedBox = mpModel->GetSurfaceAABox(iSurf).Transformed(Transform()); - if (ViewInfo.ViewFrustum.BoxInFrustum(TransformedBox)) + if (rkViewInfo.ViewFrustum.BoxInFrustum(TransformedBox)) pRenderer->AddTransparentMesh(this, iSurf, TransformedBox, eDrawMesh); } } - if (mSelected && !ViewInfo.GameMode) + if (mSelected && !rkViewInfo.GameMode) pRenderer->AddOpaqueMesh(this, -1, AABox(), eDrawSelection); } -void CStaticNode::Draw(FRenderOptions Options, int ComponentIndex, const SViewInfo& ViewInfo) +void CStaticNode::Draw(FRenderOptions Options, int ComponentIndex, const SViewInfo& rkViewInfo) { if (!mpModel) return; - bool IsLightingEnabled = CGraphics::sLightMode == CGraphics::eWorldLighting || ViewInfo.GameMode; + bool IsLightingEnabled = CGraphics::sLightMode == CGraphics::eWorldLighting || rkViewInfo.GameMode; bool UseWhiteAmbient = (mpModel->GetMaterial()->Options() & CMaterial::eDrawWhiteAmbientDKCR) != 0; if (IsLightingEnabled) @@ -70,14 +69,14 @@ void CStaticNode::Draw(FRenderOptions Options, int ComponentIndex, const SViewIn else { - LoadLights(ViewInfo); + LoadLights(rkViewInfo); if (CGraphics::sLightMode == CGraphics::eNoLighting || UseWhiteAmbient) CGraphics::sVertexBlock.COLOR0_Amb = CColor::skWhite; } float Mul = CGraphics::sWorldLightMultiplier; CGraphics::sPixelBlock.TevColor = CColor(Mul,Mul,Mul); - CGraphics::sPixelBlock.TintColor = TintColor(ViewInfo); + CGraphics::sPixelBlock.TintColor = TintColor(rkViewInfo); LoadModelMatrix(); if (ComponentIndex < 0) @@ -93,47 +92,47 @@ void CStaticNode::DrawSelection() mpModel->DrawWireframe(eNoRenderOptions, WireframeColor()); } -void CStaticNode::RayAABoxIntersectTest(CRayCollisionTester& Tester, const SViewInfo& /*ViewInfo*/) +void CStaticNode::RayAABoxIntersectTest(CRayCollisionTester& rTester, const SViewInfo& /*rkViewInfo*/) { if ((!mpModel) || (mpModel->IsOccluder())) return; - const CRay& Ray = Tester.Ray(); - std::pair BoxResult = AABox().IntersectsRay(Ray); + const CRay& rkRay = rTester.Ray(); + std::pair BoxResult = AABox().IntersectsRay(rkRay); if (BoxResult.first) { for (u32 iSurf = 0; iSurf < mpModel->GetSurfaceCount(); iSurf++) { - std::pair SurfResult = mpModel->GetSurfaceAABox(iSurf).Transformed(Transform()).IntersectsRay(Ray); + std::pair SurfResult = mpModel->GetSurfaceAABox(iSurf).Transformed(Transform()).IntersectsRay(rkRay); if (SurfResult.first) - Tester.AddNode(this, iSurf, SurfResult.second); + rTester.AddNode(this, iSurf, SurfResult.second); } } } -SRayIntersection CStaticNode::RayNodeIntersectTest(const CRay &Ray, u32 AssetID, const SViewInfo& ViewInfo) +SRayIntersection CStaticNode::RayNodeIntersectTest(const CRay& rkRay, u32 AssetID, const SViewInfo& rkViewInfo) { - SRayIntersection out; - out.pNode = this; - out.ComponentIndex = AssetID; + SRayIntersection Out; + Out.pNode = this; + Out.ComponentIndex = AssetID; - CRay TransformedRay = Ray.Transformed(Transform().Inverse()); - FRenderOptions options = ViewInfo.pRenderer->RenderOptions(); - std::pair Result = mpModel->GetSurface(AssetID)->IntersectsRay(TransformedRay, ((options & eEnableBackfaceCull) == 0)); + CRay TransformedRay = rkRay.Transformed(Transform().Inverse()); + FRenderOptions Options = rkViewInfo.pRenderer->RenderOptions(); + std::pair Result = mpModel->GetSurface(AssetID)->IntersectsRay(TransformedRay, ((Options & eEnableBackfaceCull) == 0)); if (Result.first) { - out.Hit = true; + Out.Hit = true; CVector3f HitPoint = TransformedRay.PointOnRay(Result.second); CVector3f WorldHitPoint = Transform() * HitPoint; - out.Distance = Math::Distance(Ray.Origin(), WorldHitPoint); + Out.Distance = Math::Distance(rkRay.Origin(), WorldHitPoint); } else - out.Hit = false; + Out.Hit = false; - return out; + return Out; } diff --git a/src/Core/Scene/CStaticNode.h b/src/Core/Scene/CStaticNode.h index 022c519d..b3bf03c5 100644 --- a/src/Core/Scene/CStaticNode.h +++ b/src/Core/Scene/CStaticNode.h @@ -12,11 +12,11 @@ public: CStaticNode(CScene *pScene, u32 NodeID, CSceneNode *pParent = 0, CStaticModel *pModel = 0); ENodeType NodeType(); void PostLoad(); - void AddToRenderer(CRenderer *pRenderer, const SViewInfo& ViewInfo); - void Draw(FRenderOptions Options, int ComponentIndex, const SViewInfo& ViewInfo); + void AddToRenderer(CRenderer *pRenderer, const SViewInfo& rkViewInfo); + void Draw(FRenderOptions Options, int ComponentIndex, const SViewInfo& rkViewInfo); void DrawSelection(); - void RayAABoxIntersectTest(CRayCollisionTester& Tester, const SViewInfo& ViewInfo); - SRayIntersection RayNodeIntersectTest(const CRay &Ray, u32 AssetID, const SViewInfo& ViewInfo); + void RayAABoxIntersectTest(CRayCollisionTester& rTester, const SViewInfo& rkViewInfo); + SRayIntersection RayNodeIntersectTest(const CRay& rkRay, u32 AssetID, const SViewInfo& rkViewInfo); }; #endif // CSTATICNODE_H diff --git a/src/Core/ScriptExtra/CDamageableTriggerExtra.cpp b/src/Core/ScriptExtra/CDamageableTriggerExtra.cpp index 5229b7b5..a4fe1b5f 100644 --- a/src/Core/ScriptExtra/CDamageableTriggerExtra.cpp +++ b/src/Core/ScriptExtra/CDamageableTriggerExtra.cpp @@ -87,10 +87,10 @@ void CDamageableTriggerExtra::UpdatePlaneTransform() { float Scalar = (mRenderSide == eNorth ? 1.f : -1.f); - mPosition = CVector3f(0.f, Extent.y * Scalar, 0.f); + mPosition = CVector3f(0.f, Extent.Y * Scalar, 0.f); mRotation = CQuaternion::FromEuler(CVector3f(90.f * Scalar, 0.f, 0.f)); - mScale = CVector3f(Extent.x, Extent.z, 0.f); - mCoordScale = mPlaneSize.xz(); + mScale = CVector3f(Extent.X, Extent.Z, 0.f); + mCoordScale = mPlaneSize.XZ(); break; } @@ -99,10 +99,10 @@ void CDamageableTriggerExtra::UpdatePlaneTransform() { float Scalar = (mRenderSide == eWest ? 1.f : -1.f); - mPosition = CVector3f(-Extent.x * Scalar, 0.f, 0.f); + mPosition = CVector3f(-Extent.X * Scalar, 0.f, 0.f); mRotation = CQuaternion::FromEuler(CVector3f(0.f, 90.f * Scalar, 0.f)); - mScale = CVector3f(Extent.z, Extent.y, 0.f); - mCoordScale = -mPlaneSize.yz(); + mScale = CVector3f(Extent.Z, Extent.Y, 0.f); + mCoordScale = -mPlaneSize.YZ(); break; } @@ -112,10 +112,10 @@ void CDamageableTriggerExtra::UpdatePlaneTransform() float Scalar = (mRenderSide == eUp ? 1.f : -1.f); float RotAngle = (mRenderSide == eUp ? 180.f : 0.f); - mPosition = CVector3f(0.f, 0.f, Extent.z * Scalar); + mPosition = CVector3f(0.f, 0.f, Extent.Z * Scalar); mRotation = CQuaternion::FromEuler(CVector3f(0.f, RotAngle, 0.f)); - mScale = CVector3f(Extent.x, Extent.y, 0.f); - mCoordScale = -mPlaneSize.xy(); + mScale = CVector3f(Extent.X, Extent.Y, 0.f); + mCoordScale = -mPlaneSize.XY(); break; } @@ -172,33 +172,33 @@ bool CDamageableTriggerExtra::ShouldDrawNormalAssets() return (mRenderSide == eNoRender); } -void CDamageableTriggerExtra::AddToRenderer(CRenderer *pRenderer, const SViewInfo& ViewInfo) +void CDamageableTriggerExtra::AddToRenderer(CRenderer *pRenderer, const SViewInfo& rkViewInfo) { - if (ViewInfo.GameMode && !mpInstance->IsActive()) + if (rkViewInfo.GameMode && !mpInstance->IsActive()) return; - if (!ViewInfo.GameMode && ((ViewInfo.ShowFlags & eShowObjectGeometry) == 0)) + if (!rkViewInfo.GameMode && ((rkViewInfo.ShowFlags & eShowObjectGeometry) == 0)) return; if (mRenderSide != eNoRender) { - if (ViewInfo.ViewFrustum.BoxInFrustum(AABox())) + if (rkViewInfo.ViewFrustum.BoxInFrustum(AABox())) pRenderer->AddTransparentMesh(this, -1, AABox(), eDrawMesh); - if (mpParent->IsSelected() && !ViewInfo.GameMode) + if (mpParent->IsSelected() && !rkViewInfo.GameMode) pRenderer->AddOpaqueMesh(this, -1, AABox(), eDrawSelection); } } -void CDamageableTriggerExtra::Draw(FRenderOptions Options, int /*ComponentIndex*/, const SViewInfo& ViewInfo) +void CDamageableTriggerExtra::Draw(FRenderOptions Options, int /*ComponentIndex*/, const SViewInfo& rkViewInfo) { LoadModelMatrix(); - CGraphics::sPixelBlock.TintColor = mpParent->TintColor(ViewInfo); + CGraphics::sPixelBlock.TintColor = mpParent->TintColor(rkViewInfo); mpMat->SetCurrent(Options); // Note: The plane the game renders this onto is 5x4.5, which is why we divide the tex coords by this value - CVector2f TexUL(0.f, mCoordScale.y / 4.5f); - CVector2f TexUR(mCoordScale.x / 5.f, mCoordScale.y / 4.5f); - CVector2f TexBR(mCoordScale.x / 5.f, 0.f); + CVector2f TexUL(0.f, mCoordScale.Y / 4.5f); + CVector2f TexUR(mCoordScale.X / 5.f, mCoordScale.Y / 4.5f); + CVector2f TexBR(mCoordScale.X / 5.f, 0.f); CVector2f TexBL(0.f, 0.f); CDrawUtil::DrawSquare(TexUL, TexUR, TexBR, TexBL); } @@ -213,40 +213,40 @@ void CDamageableTriggerExtra::DrawSelection() glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); } -void CDamageableTriggerExtra::RayAABoxIntersectTest(CRayCollisionTester& Tester, const SViewInfo& ViewInfo) +void CDamageableTriggerExtra::RayAABoxIntersectTest(CRayCollisionTester& rTester, const SViewInfo& rkViewInfo) { if (mRenderSide == eNoRender) return; - if (ViewInfo.GameMode && !mpInstance->IsActive()) return; + if (rkViewInfo.GameMode && !mpInstance->IsActive()) return; - const CRay& Ray = Tester.Ray(); + const CRay& rkRay = rTester.Ray(); - if (ViewInfo.pRenderer->RenderOptions() & eEnableBackfaceCull) + if (rkViewInfo.pRenderer->RenderOptions() & eEnableBackfaceCull) { // We're guaranteed to be axis-aligned, so we can take advantage of that // to perform a very simple backface check. switch (mRenderSide) { - case eNorth: if (Ray.Origin().y > AbsolutePosition().y) return; break; - case eSouth: if (Ray.Origin().y < AbsolutePosition().y) return; break; - case eWest: if (Ray.Origin().x < AbsolutePosition().x) return; break; - case eEast: if (Ray.Origin().x > AbsolutePosition().x) return; break; - case eUp: if (Ray.Origin().z > AbsolutePosition().z) return; break; - case eDown: if (Ray.Origin().z < AbsolutePosition().z) return; break; + case eNorth: if (rkRay.Origin().Y > AbsolutePosition().Y) return; break; + case eSouth: if (rkRay.Origin().Y < AbsolutePosition().Y) return; break; + case eWest: if (rkRay.Origin().X < AbsolutePosition().X) return; break; + case eEast: if (rkRay.Origin().X > AbsolutePosition().X) return; break; + case eUp: if (rkRay.Origin().Z > AbsolutePosition().Z) return; break; + case eDown: if (rkRay.Origin().Z < AbsolutePosition().Z) return; break; } } - std::pair Result = AABox().IntersectsRay(Ray); + std::pair Result = AABox().IntersectsRay(rkRay); if (Result.first) { - Tester.AddNode(this, -1, Result.second); + rTester.AddNode(this, -1, Result.second); mCachedRayDistance = Result.second; } } -SRayIntersection CDamageableTriggerExtra::RayNodeIntersectTest(const CRay& Ray, u32 /*ComponentIndex*/, const SViewInfo& /*ViewInfo*/) +SRayIntersection CDamageableTriggerExtra::RayNodeIntersectTest(const CRay& rkRay, u32 /*ComponentIndex*/, const SViewInfo& /*rkViewInfo*/) { // The bounding box and all other tests already passed in RayAABoxIntersectTest, so we // already know that we have a positive. - return SRayIntersection(true, mCachedRayDistance, Ray.PointOnRay(mCachedRayDistance), mpParent, -1); + return SRayIntersection(true, mCachedRayDistance, rkRay.PointOnRay(mCachedRayDistance), mpParent, -1); } diff --git a/src/Core/ScriptExtra/CDamageableTriggerExtra.h b/src/Core/ScriptExtra/CDamageableTriggerExtra.h index 9204a096..26d47c7e 100644 --- a/src/Core/ScriptExtra/CDamageableTriggerExtra.h +++ b/src/Core/ScriptExtra/CDamageableTriggerExtra.h @@ -38,11 +38,11 @@ public: void OnTransformed(); void PropertyModified(IProperty *pProperty); bool ShouldDrawNormalAssets(); - void AddToRenderer(CRenderer *pRenderer, const SViewInfo& ViewInfo); - void Draw(FRenderOptions Options, int ComponentIndex, const SViewInfo& ViewInfo); + void AddToRenderer(CRenderer *pRenderer, const SViewInfo& rkViewInfo); + void Draw(FRenderOptions Options, int ComponentIndex, const SViewInfo& rkViewInfo); void DrawSelection(); - void RayAABoxIntersectTest(CRayCollisionTester& Tester, const SViewInfo& ViewInfo); - SRayIntersection RayNodeIntersectTest(const CRay& Ray, u32 ComponentIndex, const SViewInfo& ViewInfo); + void RayAABoxIntersectTest(CRayCollisionTester& rTester, const SViewInfo& rkViewInfo); + SRayIntersection RayNodeIntersectTest(const CRay& rkRay, u32 ComponentIndex, const SViewInfo& rkViewInfo); }; #endif // CDAMAGEABLETRIGGEREXTRA_H diff --git a/src/Core/ScriptExtra/CDoorExtra.cpp b/src/Core/ScriptExtra/CDoorExtra.cpp index c59b7e5d..bb40aa77 100644 --- a/src/Core/ScriptExtra/CDoorExtra.cpp +++ b/src/Core/ScriptExtra/CDoorExtra.cpp @@ -56,33 +56,33 @@ void CDoorExtra::PropertyModified(IProperty *pProperty) } } -void CDoorExtra::AddToRenderer(CRenderer *pRenderer, const SViewInfo& ViewInfo) +void CDoorExtra::AddToRenderer(CRenderer *pRenderer, const SViewInfo& rkViewInfo) { if (!mpShieldModel) return; - if (ViewInfo.GameMode && !mpInstance->IsActive()) return; - if (!ViewInfo.GameMode && ((ViewInfo.ShowFlags & eShowObjectGeometry) == 0)) return; + if (rkViewInfo.GameMode && !mpInstance->IsActive()) return; + if (!rkViewInfo.GameMode && ((rkViewInfo.ShowFlags & eShowObjectGeometry) == 0)) return; - if (mpParent->IsVisible() && ViewInfo.ViewFrustum.BoxInFrustum(AABox())) + if (mpParent->IsVisible() && rkViewInfo.ViewFrustum.BoxInFrustum(AABox())) { if (mpShieldModel->HasTransparency(0)) - AddSurfacesToRenderer(pRenderer, mpShieldModel, 0, ViewInfo); + AddSurfacesToRenderer(pRenderer, mpShieldModel, 0, rkViewInfo); else pRenderer->AddOpaqueMesh(this, -1, AABox(), eDrawMesh); - if (mpParent->IsSelected() && !ViewInfo.GameMode) + if (mpParent->IsSelected() && !rkViewInfo.GameMode) pRenderer->AddOpaqueMesh(this, -1, AABox(), eDrawSelection); } } -void CDoorExtra::Draw(FRenderOptions Options, int ComponentIndex, const SViewInfo& ViewInfo) +void CDoorExtra::Draw(FRenderOptions Options, int ComponentIndex, const SViewInfo& rkViewInfo) { LoadModelMatrix(); - mpParent->LoadLights(ViewInfo); + mpParent->LoadLights(rkViewInfo); CGraphics::SetupAmbientColor(); CGraphics::UpdateVertexBlock(); - CColor Tint = mpParent->TintColor(ViewInfo) * mShieldColor; + CColor Tint = mpParent->TintColor(rkViewInfo) * mShieldColor; CGraphics::sPixelBlock.TintColor = Tint; CGraphics::sPixelBlock.TevColor = CColor::skWhite; @@ -101,27 +101,27 @@ void CDoorExtra::DrawSelection() mpShieldModel->DrawWireframe(eNoRenderOptions, mpParent->WireframeColor()); } -void CDoorExtra::RayAABoxIntersectTest(CRayCollisionTester& Tester, const SViewInfo& ViewInfo) +void CDoorExtra::RayAABoxIntersectTest(CRayCollisionTester& rTester, const SViewInfo& rkViewInfo) { if (!mpShieldModel) return; - if (ViewInfo.GameMode && !mpInstance->IsActive()) return; + if (rkViewInfo.GameMode && !mpInstance->IsActive()) return; - const CRay& Ray = Tester.Ray(); + const CRay& Ray = rTester.Ray(); std::pair BoxResult = AABox().IntersectsRay(Ray); if (BoxResult.first) - Tester.AddNodeModel(this, mpShieldModel); + rTester.AddNodeModel(this, mpShieldModel); } -SRayIntersection CDoorExtra::RayNodeIntersectTest(const CRay &Ray, u32 AssetID, const SViewInfo& ViewInfo) +SRayIntersection CDoorExtra::RayNodeIntersectTest(const CRay& rkRay, u32 AssetID, const SViewInfo& rkViewInfo) { - FRenderOptions Options = ViewInfo.pRenderer->RenderOptions(); + FRenderOptions Options = rkViewInfo.pRenderer->RenderOptions(); SRayIntersection out; out.pNode = mpParent; out.ComponentIndex = AssetID; - CRay TransformedRay = Ray.Transformed(Transform().Inverse()); + CRay TransformedRay = rkRay.Transformed(Transform().Inverse()); std::pair Result = mpShieldModel->GetSurface(AssetID)->IntersectsRay(TransformedRay, ((Options & eEnableBackfaceCull) == 0)); if (Result.first) @@ -129,7 +129,7 @@ SRayIntersection CDoorExtra::RayNodeIntersectTest(const CRay &Ray, u32 AssetID, out.Hit = true; CVector3f HitPoint = TransformedRay.PointOnRay(Result.second); CVector3f WorldHitPoint = Transform() * HitPoint; - out.Distance = Ray.Origin().Distance(WorldHitPoint); + out.Distance = rkRay.Origin().Distance(WorldHitPoint); } else out.Hit = false; diff --git a/src/Core/ScriptExtra/CDoorExtra.h b/src/Core/ScriptExtra/CDoorExtra.h index 86fbd8ff..2a528df9 100644 --- a/src/Core/ScriptExtra/CDoorExtra.h +++ b/src/Core/ScriptExtra/CDoorExtra.h @@ -15,11 +15,11 @@ class CDoorExtra : public CScriptExtra public: explicit CDoorExtra(CScriptObject *pInstance, CScene *pScene, CSceneNode *pParent = 0); void PropertyModified(IProperty *pProperty); - void AddToRenderer(CRenderer *pRenderer, const SViewInfo& ViewInfo); - void Draw(FRenderOptions Options, int ComponentIndex, const SViewInfo& ViewInfo); + void AddToRenderer(CRenderer *pRenderer, const SViewInfo& rkViewInfo); + void Draw(FRenderOptions Options, int ComponentIndex, const SViewInfo& rkViewInfo); void DrawSelection(); - void RayAABoxIntersectTest(CRayCollisionTester& Tester, const SViewInfo& ViewInfo); - SRayIntersection RayNodeIntersectTest(const CRay &Ray, u32 AssetID, const SViewInfo& ViewInfo); + void RayAABoxIntersectTest(CRayCollisionTester& rTester, const SViewInfo& rkViewInfo); + SRayIntersection RayNodeIntersectTest(const CRay& rkRay, u32 AssetID, const SViewInfo& rkViewInfo); }; #endif // CDOOREXTRA_H diff --git a/src/Core/ScriptExtra/CScriptExtra.cpp b/src/Core/ScriptExtra/CScriptExtra.cpp index dd49e4f5..e3a3880a 100644 --- a/src/Core/ScriptExtra/CScriptExtra.cpp +++ b/src/Core/ScriptExtra/CScriptExtra.cpp @@ -11,7 +11,7 @@ CScriptExtra* CScriptExtra::CreateExtra(CScriptNode *pNode) { CScriptExtra *pExtra = nullptr; - CScriptObject *pObj = pNode->Object(); + CScriptObject *pObj = pNode->Instance(); if (pObj) { diff --git a/src/Core/ScriptExtra/CScriptExtra.h b/src/Core/ScriptExtra/CScriptExtra.h index 7b9cf41b..ffd6c84a 100644 --- a/src/Core/ScriptExtra/CScriptExtra.h +++ b/src/Core/ScriptExtra/CScriptExtra.h @@ -32,7 +32,7 @@ public: // Default implementations for CSceneNode virtual ENodeType NodeType() { return eScriptExtraNode; } - virtual SRayIntersection RayNodeIntersectTest(const CRay& /*Ray*/, u32 /*AssetID*/, const SViewInfo& /*ViewInfo*/) + virtual SRayIntersection RayNodeIntersectTest(const CRay& /*rkRay*/, u32 /*AssetID*/, const SViewInfo& /*rkViewInfo*/) { SRayIntersection out; out.Hit = false; diff --git a/src/Core/ScriptExtra/CSplinePathExtra.cpp b/src/Core/ScriptExtra/CSplinePathExtra.cpp index d55c955d..3f1fc74f 100644 --- a/src/Core/ScriptExtra/CSplinePathExtra.cpp +++ b/src/Core/ScriptExtra/CSplinePathExtra.cpp @@ -55,7 +55,7 @@ void CSplinePathExtra::AddWaypoints() { CScriptNode *pNode = mpScene->NodeForInstanceID(pLink->ReceiverID()); - if (pNode && pNode->Object()->ObjectTypeID() == 0x57415950) // Waypoint + if (pNode && pNode->Instance()->ObjectTypeID() == 0x57415950) // Waypoint { CWaypointExtra *pWaypoint = static_cast(pNode->Extra()); FindAttachedWaypoints(CheckedWaypoints, pWaypoint); diff --git a/src/Core/ScriptExtra/CWaypointExtra.cpp b/src/Core/ScriptExtra/CWaypointExtra.cpp index 2e29a9c3..4f85c1db 100644 --- a/src/Core/ScriptExtra/CWaypointExtra.cpp +++ b/src/Core/ScriptExtra/CWaypointExtra.cpp @@ -46,7 +46,7 @@ void CWaypointExtra::CheckColor() mColor = CColor::skCyan; } - mColor.a = 0; + mColor.A = 0; } void CWaypointExtra::AddToSplinePath(CSplinePathExtra *pPath) @@ -120,7 +120,7 @@ bool CWaypointExtra::IsPathLink(CLink *pLink) CScriptNode *pNode = mpScene->NodeForInstanceID(pLink->ReceiverID()); if (pNode) - return pNode->Object()->ObjectTypeID() == mpInstance->ObjectTypeID(); + return pNode->Instance()->ObjectTypeID() == mpInstance->ObjectTypeID(); } return false; @@ -154,25 +154,25 @@ void CWaypointExtra::LinksModified() BuildLinks(); } -void CWaypointExtra::AddToRenderer(CRenderer *pRenderer, const SViewInfo& ViewInfo) +void CWaypointExtra::AddToRenderer(CRenderer *pRenderer, const SViewInfo& rkViewInfo) { // This call is necessary because if we try to build links in the constructor, it // won't work properly because we haven't finished loading the scene yet. if (!mLinksBuilt) BuildLinks(); - if (!ViewInfo.GameMode && (ViewInfo.ShowFlags & eShowObjectGeometry) && mpParent->IsVisible() && !mpParent->IsSelected()) + if (!rkViewInfo.GameMode && (rkViewInfo.ShowFlags & eShowObjectGeometry) && mpParent->IsVisible() && !mpParent->IsSelected()) { for (u32 iLink = 0; iLink < mLinks.size(); iLink++) { CScriptNode *pNode = mLinks[iLink].pWaypoint; - if (pNode->IsVisible() && !pNode->IsSelected() && ViewInfo.ViewFrustum.BoxInFrustum(mLinks[iLink].LineAABB)) + if (pNode->IsVisible() && !pNode->IsSelected() && rkViewInfo.ViewFrustum.BoxInFrustum(mLinks[iLink].LineAABB)) pRenderer->AddOpaqueMesh(this, iLink, mLinks[iLink].LineAABB, eDrawMesh); } } } -void CWaypointExtra::Draw(FRenderOptions /*Options*/, int ComponentIndex, const SViewInfo& /*ViewInfo*/) +void CWaypointExtra::Draw(FRenderOptions /*Options*/, int ComponentIndex, const SViewInfo& /*rkViewInfo*/) { glBlendFunc(GL_ONE, GL_ZERO); glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); diff --git a/src/Core/ScriptExtra/CWaypointExtra.h b/src/Core/ScriptExtra/CWaypointExtra.h index 0b2c2e92..620fe6a0 100644 --- a/src/Core/ScriptExtra/CWaypointExtra.h +++ b/src/Core/ScriptExtra/CWaypointExtra.h @@ -31,8 +31,8 @@ public: void OnTransformed(); void LinksModified(); - void AddToRenderer(CRenderer *pRenderer, const SViewInfo& ViewInfo); - void Draw(FRenderOptions Options, int ComponentIndex, const SViewInfo& ViewInfo); + void AddToRenderer(CRenderer *pRenderer, const SViewInfo& rkViewInfo); + void Draw(FRenderOptions Options, int ComponentIndex, const SViewInfo& rkViewInfo); CColor TevColor(); }; diff --git a/src/Editor/CBasicViewport.cpp b/src/Editor/CBasicViewport.cpp index aafb4305..955062f0 100644 --- a/src/Editor/CBasicViewport.cpp +++ b/src/Editor/CBasicViewport.cpp @@ -7,13 +7,13 @@ #include -CBasicViewport::CBasicViewport(QWidget *pParent) : - QOpenGLWidget(pParent), - mLastDrawTime(CTimer::GlobalTime()), - mKeysPressed(0), - mButtonsPressed(0), - mCursorState(Qt::ArrowCursor), - mCursorVisible(true) +CBasicViewport::CBasicViewport(QWidget *pParent) + : QOpenGLWidget(pParent) + , mLastDrawTime(CTimer::GlobalTime()) + , mKeysPressed(0) + , mButtonsPressed(0) + , mCursorState(Qt::ArrowCursor) + , mCursorVisible(true) { setMouseTracking(true); mCamera.SetAspectRatio((float) width() / height()); @@ -65,10 +65,10 @@ void CBasicViewport::paintGL() DrawAxes(); } -void CBasicViewport::resizeGL(int w, int h) +void CBasicViewport::resizeGL(int Width, int Height) { - mCamera.SetAspectRatio((float) w / h); - glViewport(0, 0, w, h); + mCamera.SetAspectRatio((float) Width / Height); + glViewport(0, 0, Width, Height); OnResize(); } @@ -183,19 +183,19 @@ void CBasicViewport::SetGameMode(bool Enabled) mViewInfo.GameMode = Enabled; } -void CBasicViewport::SetCursorState(const QCursor &Cursor) +void CBasicViewport::SetCursorState(const QCursor& rkCursor) { - mCursorState = Cursor; + mCursorState = rkCursor; if (IsCursorVisible()) - setCursor(Cursor); + setCursor(rkCursor); } -void CBasicViewport::SetCursorVisible(bool visible) +void CBasicViewport::SetCursorVisible(bool Visible) { - mCursorVisible = visible; + mCursorVisible = Visible; - if (visible) + if (Visible) setCursor(mCursorState); else setCursor(Qt::BlankCursor); @@ -272,11 +272,11 @@ void CBasicViewport::ProcessInput() mCamera.ProcessKeyInput((FKeyInputs) mKeysPressed, DeltaTime); // Update view info - const CMatrix4f& View = mCamera.ViewMatrix(); - mViewInfo.RotationOnlyViewMatrix = CMatrix4f(View[0][0], View[0][1], View[0][2], 0.f, - View[1][0], View[1][1], View[1][2], 0.f, - View[2][0], View[2][1], View[2][2], 0.f, - View[3][0], View[3][1], View[3][2], 1.f); + const CMatrix4f& rkView = mCamera.ViewMatrix(); + mViewInfo.RotationOnlyViewMatrix = CMatrix4f(rkView[0][0], rkView[0][1], rkView[0][2], 0.f, + rkView[1][0], rkView[1][1], rkView[1][2], 0.f, + rkView[2][0], rkView[2][1], rkView[2][2], 0.f, + rkView[3][0], rkView[3][1], rkView[3][2], 1.f); mViewInfo.ViewFrustum = mCamera.FrustumPlanes(); diff --git a/src/Editor/CBasicViewport.h b/src/Editor/CBasicViewport.h index 58c04e49..3b96761e 100644 --- a/src/Editor/CBasicViewport.h +++ b/src/Editor/CBasicViewport.h @@ -42,7 +42,7 @@ public: ~CBasicViewport(); void initializeGL(); void paintGL(); - void resizeGL(int w, int h); + void resizeGL(int Width, int Height); void mousePressEvent(QMouseEvent *pEvent); void mouseReleaseEvent(QMouseEvent *pEvent); void mouseMoveEvent(QMouseEvent *pEvent); @@ -53,8 +53,8 @@ public: void contextMenuEvent(QContextMenuEvent *pEvent); void SetGameMode(bool Enabled); - void SetCursorState(const QCursor& Cursor); - void SetCursorVisible(bool visible); + void SetCursorState(const QCursor& rkCursor); + void SetCursorVisible(bool Visible); bool IsCursorVisible(); bool IsMouseInputActive(); bool IsKeyboardInputActive(); diff --git a/src/Editor/CDarkStyle.cpp b/src/Editor/CDarkStyle.cpp deleted file mode 100644 index c800a513..00000000 --- a/src/Editor/CDarkStyle.cpp +++ /dev/null @@ -1,5 +0,0 @@ -#include "CDarkStyle.h" - -CDarkStyle::CDarkStyle() -{ -} diff --git a/src/Editor/CDarkStyle.h b/src/Editor/CDarkStyle.h deleted file mode 100644 index cbb1619c..00000000 --- a/src/Editor/CDarkStyle.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef CDARKSTYLE_H -#define CDARKSTYLE_H - -#include - -class CDarkStyle : public QProxyStyle -{ - Q_OBJECT - -public: - CDarkStyle(); -}; - -#endif // CDARKSTYLE_H diff --git a/src/Editor/CErrorLogDialog.cpp b/src/Editor/CErrorLogDialog.cpp index 63c73fd6..8bb15043 100644 --- a/src/Editor/CErrorLogDialog.cpp +++ b/src/Editor/CErrorLogDialog.cpp @@ -3,9 +3,9 @@ #include "UICommon.h" #include -CErrorLogDialog::CErrorLogDialog(QWidget *parent) : - QDialog(parent), - ui(new Ui::CErrorLogDialog) +CErrorLogDialog::CErrorLogDialog(QWidget *pParent) + : QDialog(pParent) + , ui(new Ui::CErrorLogDialog) { ui->setupUi(this); connect(ui->CloseButton, SIGNAL(clicked()), this, SLOT(close())); diff --git a/src/Editor/CErrorLogDialog.h b/src/Editor/CErrorLogDialog.h index b554183d..71c84a56 100644 --- a/src/Editor/CErrorLogDialog.h +++ b/src/Editor/CErrorLogDialog.h @@ -12,7 +12,7 @@ class CErrorLogDialog : public QDialog Q_OBJECT public: - explicit CErrorLogDialog(QWidget *parent = 0); + explicit CErrorLogDialog(QWidget *pParent = 0); ~CErrorLogDialog(); bool GatherErrors(); diff --git a/src/Editor/CGizmo.cpp b/src/Editor/CGizmo.cpp index 70690706..d5331d03 100644 --- a/src/Editor/CGizmo.cpp +++ b/src/Editor/CGizmo.cpp @@ -10,32 +10,29 @@ #include CGizmo::CGizmo() + : mSelectedAxes(eNone) + , mTransformSpace(eWorldTransform) + , mGizmoSize(1.f) + , mCameraDist(0.f) + , mIsTransforming(false) + , mHasTransformed(false) + , mWrapOffset(0.f) + , mEnableCursorWrap(true) + , mPosition(CVector3f::skZero) + , mRotation(CQuaternion::skIdentity) + , mLocalRotation(CQuaternion::skIdentity) + , mScale(CVector3f::skOne) + , mFlipScaleX(false) + , mFlipScaleY(false) + , mFlipScaleZ(false) + , mDeltaTranslation(CVector3f::skZero) + , mDeltaRotation(CQuaternion::skIdentity) + , mDeltaScale(CVector3f::skOne) + , mTotalScale(CVector3f::skOne) + , mSetOffset(false) { LoadModels(); - SetMode(eTranslate); - mSelectedAxes = eNone; - mTransformSpace = eWorldTransform; - mGizmoSize = 1.f; - mCameraDist = 0.f; - mIsTransforming = false; - mHasTransformed = false; - mWrapOffset = 0.f; - mEnableCursorWrap = true; - - mPosition = CVector3f::skZero; - mRotation = CQuaternion::skIdentity; - mLocalRotation = CQuaternion::skIdentity; - mScale = CVector3f::skOne; - mFlipScaleX = false; - mFlipScaleY = false; - mFlipScaleZ = false; - - mDeltaTranslation = CVector3f::skZero; - mDeltaRotation = CQuaternion::skIdentity; - mDeltaScale = CVector3f::skOne; - mTotalScale = CVector3f::skOne; - mSetOffset = false; } CGizmo::~CGizmo() @@ -55,12 +52,12 @@ void CGizmo::AddToRenderer(CRenderer *pRenderer, const SViewInfo&) CModel *pModel = pPart->pModel; // Determine whether to use the mat set for regular (0) or highlight (1) - FGizmoAxes partAxes = pPart->modelAxes; - bool isHighlighted = (partAxes != eNone) && ((mSelectedAxes & partAxes) == pPart->modelAxes); - u32 setID = (isHighlighted ? 1 : 0); + FGizmoAxes PartAxes = pPart->ModelAxes; + bool IsHighlighted = (PartAxes != eNone) && ((mSelectedAxes & PartAxes) == pPart->ModelAxes); + u32 SetID = (IsHighlighted ? 1 : 0); // Add to renderer... - if (pModel->HasTransparency(setID)) + if (pModel->HasTransparency(SetID)) pRenderer->AddTransparentMesh(this, iPart, pModel->AABox().Transformed(mTransform), eDrawMesh); else pRenderer->AddOpaqueMesh(this, iPart, pModel->AABox().Transformed(mTransform), eDrawMesh); @@ -69,16 +66,16 @@ void CGizmo::AddToRenderer(CRenderer *pRenderer, const SViewInfo&) } } -void CGizmo::Draw(FRenderOptions /*Options*/, int ComponentIndex, const SViewInfo& /*ViewInfo*/) +void CGizmo::Draw(FRenderOptions /*Options*/, int ComponentIndex, const SViewInfo& /*rkViewInfo*/) { // Determine which SModelPart array to use if (ComponentIndex >= (int) mNumCurrentParts) return; SModelPart *pPart = mpCurrentParts; // Set model matrix - if (pPart[ComponentIndex].isBillboard) + if (pPart[ComponentIndex].IsBillboard) CGraphics::sMVPBlock.ModelMatrix = mBillboardTransform.ToMatrix4f(); - else if ((mMode == eScale) && ((mSelectedAxes & pPart[ComponentIndex].modelAxes) != 0)) + else if ((mMode == eScale) && ((mSelectedAxes & pPart[ComponentIndex].ModelAxes) != 0)) CGraphics::sMVPBlock.ModelMatrix = mScaledTransform.ToMatrix4f(); else CGraphics::sMVPBlock.ModelMatrix = mTransform.ToMatrix4f(); @@ -90,12 +87,12 @@ void CGizmo::Draw(FRenderOptions /*Options*/, int ComponentIndex, const SViewInf CGraphics::UpdatePixelBlock(); // Choose material set - FGizmoAxes partAxes = pPart[ComponentIndex].modelAxes; - bool isHighlighted = (partAxes != eNone) && ((mSelectedAxes & partAxes) == pPart[ComponentIndex].modelAxes); - u32 setID = (isHighlighted ? 1 : 0); + FGizmoAxes PartAxes = pPart[ComponentIndex].ModelAxes; + bool IsHighlighted = (PartAxes != eNone) && ((mSelectedAxes & PartAxes) == pPart[ComponentIndex].ModelAxes); + u32 SetID = (IsHighlighted ? 1 : 0); // Draw model - pPart[ComponentIndex].pModel->Draw((FRenderOptions) 0, setID); + pPart[ComponentIndex].pModel->Draw((FRenderOptions) 0, SetID); } void CGizmo::IncrementSize() @@ -116,80 +113,80 @@ void CGizmo::DecrementSize() if (mGizmoSize < skMinSize) mGizmoSize = skMinSize; } -void CGizmo::UpdateForCamera(const CCamera &camera) +void CGizmo::UpdateForCamera(const CCamera& rkCamera) { - CVector3f camPos = camera.Position(); - CVector3f cameraToGizmo = (mPosition - camPos).Normalized(); - mFlipScaleX = (mRotation.XAxis().Dot(cameraToGizmo) >= 0.f); - mFlipScaleY = (mRotation.YAxis().Dot(cameraToGizmo) >= 0.f); - mFlipScaleZ = (mRotation.ZAxis().Dot(cameraToGizmo) >= 0.f); + CVector3f CamPos = rkCamera.Position(); + CVector3f CameraToGizmo = (mPosition - CamPos).Normalized(); + mFlipScaleX = (mRotation.XAxis().Dot(CameraToGizmo) >= 0.f); + mFlipScaleY = (mRotation.YAxis().Dot(CameraToGizmo) >= 0.f); + mFlipScaleZ = (mRotation.ZAxis().Dot(CameraToGizmo) >= 0.f); if ((!mIsTransforming) || (mMode != eTranslate)) - mCameraDist = mPosition.Distance(camPos); + mCameraDist = mPosition.Distance(CamPos); // todo: make this cleaner... - CVector3f billDir = (camPos - mPosition).Normalized(); - CVector3f axis = CVector3f::skForward.Cross(billDir); - float angle = acosf(CVector3f::skForward.Dot(billDir)); - mBillboardRotation = CQuaternion::FromAxisAngle(angle, axis); + CVector3f BillDir = (CamPos - mPosition).Normalized(); + CVector3f Axis = CVector3f::skForward.Cross(BillDir); + float Angle = acosf(CVector3f::skForward.Dot(BillDir)); + mBillboardRotation = CQuaternion::FromAxisAngle(Angle, Axis); } -bool CGizmo::CheckSelectedAxes(const CRay &ray) +bool CGizmo::CheckSelectedAxes(const CRay& rkRay) { - CRay localRay = ray.Transformed(mTransform.Inverse()); - CRay billRay = ray.Transformed(mBillboardTransform.Inverse()); + CRay LocalRay = rkRay.Transformed(mTransform.Inverse()); + CRay BillRay = rkRay.Transformed(mBillboardTransform.Inverse()); // Do raycast on each model SModelPart *pPart = mpCurrentParts; struct SResult { SModelPart *pPart; - float dist; + float Dist; }; - std::list results; + std::list Results; for (u32 iPart = 0; iPart < mNumCurrentParts; iPart++) { - if (!pPart->enableRayCast) + if (!pPart->EnableRayCast) { pPart++; continue; } CModel *pModel = pPart->pModel; - CRay& partRay = (pPart->isBillboard ? billRay : localRay); + CRay& rPartRay = (pPart->IsBillboard ? BillRay : LocalRay); // Ray/Model AABox test - allow buffer room because lines are small CAABox AABox = pModel->AABox(); AABox.ExpandBy(CVector3f::skOne); - bool modelBoxCheck = Math::RayBoxIntersection(partRay, AABox).first; + bool ModelBoxCheck = Math::RayBoxIntersection(rPartRay, AABox).first; - if (modelBoxCheck) + if (ModelBoxCheck) { - bool hit = false; - float dist; + bool Hit = false; + float Dist; for (u32 iSurf = 0; iSurf < pModel->GetSurfaceCount(); iSurf++) { // Skip surface/box check - since we use lines the boxes might be too small SSurface *pSurf = pModel->GetSurface(iSurf); - std::pair surfCheck = pSurf->IntersectsRay(partRay, false, 0.05f); + std::pair SurfCheck = pSurf->IntersectsRay(rPartRay, false, 0.05f); - if (surfCheck.first) + if (SurfCheck.first) { - if ((!hit) || (surfCheck.second < dist)) - dist = surfCheck.second; + if ((!Hit) || (SurfCheck.second < Dist)) + Dist = SurfCheck.second; - hit = true; + Hit = true; } } - if (hit) + if (Hit) { - SResult result; - result.pPart = pPart; - result.dist = dist; - results.push_back(result); + SResult Result; + Result.pPart = pPart; + Result.Dist = Dist; + Results.push_back(Result); } } @@ -197,33 +194,33 @@ bool CGizmo::CheckSelectedAxes(const CRay &ray) } // Results list empty = no hits - if (results.empty()) + if (Results.empty()) { mSelectedAxes = eNone; return false; } // Otherwise, we have at least one hit - sort results and set selected axes - results.sort([](const SResult& a, SResult& b) -> bool + Results.sort([](const SResult& rkLeft, SResult& rkRight) -> bool { - return (a.dist < b.dist); + return (rkLeft.Dist < rkRight.Dist); }); - CRay& partRay = (pPart->isBillboard ? billRay : localRay); - mSelectedAxes = results.front().pPart->modelAxes; - mHitPoint = mTransform * partRay.PointOnRay(results.front().dist); + CRay& rPartRay = (pPart->IsBillboard ? BillRay : LocalRay); + mSelectedAxes = Results.front().pPart->ModelAxes; + mHitPoint = mTransform * rPartRay.PointOnRay(Results.front().Dist); return (mSelectedAxes != eNone); } u32 CGizmo::NumSelectedAxes() { - u32 out = 0; + u32 Out = 0; for (u32 iAxis = 1; iAxis < 8; iAxis <<= 1) - if (mSelectedAxes & FGizmoAxes(iAxis)) out++; + if (mSelectedAxes & FGizmoAxes(iAxis)) Out++; - return out; + return Out; } void CGizmo::ResetSelectedAxes() @@ -245,13 +242,13 @@ void CGizmo::StartTransform() // Set rotation direction if (mMode == eRotate) { - CVector3f axis; - if (mSelectedAxes & eX) axis = mRotation.XAxis(); - else if (mSelectedAxes & eY) axis = mRotation.YAxis(); - else axis = mRotation.ZAxis(); + CVector3f Axis; + if (mSelectedAxes & eX) Axis = mRotation.XAxis(); + else if (mSelectedAxes & eY) Axis = mRotation.YAxis(); + else Axis = mRotation.ZAxis(); - CVector3f gizmoToHit = (mHitPoint - mPosition).Normalized(); - mMoveDir = axis.Cross(gizmoToHit); + CVector3f GizmoToHit = (mHitPoint - mPosition).Normalized(); + mMoveDir = Axis.Cross(GizmoToHit); } // Set scale direction @@ -271,78 +268,78 @@ void CGizmo::StartTransform() // Two axes; interpolate between the two selected axes else if (NumSelectedAxes() == 2) { - CVector3f axisA = (mSelectedAxes & eX ? mRotation.XAxis() : mRotation.YAxis()); - CVector3f axisB = (mSelectedAxes & eZ ? mRotation.ZAxis() : mRotation.YAxis()); - mMoveDir = (axisA + axisB) / 2.f; + CVector3f AxisA = (mSelectedAxes & eX ? mRotation.XAxis() : mRotation.YAxis()); + CVector3f AxisB = (mSelectedAxes & eZ ? mRotation.ZAxis() : mRotation.YAxis()); + mMoveDir = (AxisA + AxisB) / 2.f; } } } } -bool CGizmo::TransformFromInput(const CRay& ray, CCamera& camera) +bool CGizmo::TransformFromInput(const CRay& rkRay, CCamera& rCamera) { // Wrap cursor (this has no effect until the next time this function is called) if (mEnableCursorWrap && (mMode != eTranslate)) WrapCursor(); // Calculate normalized cursor position - QPoint cursorPos = QCursor::pos(); - QRect geom = QApplication::desktop()->screenGeometry(); - CVector2f mouseCoords( - (((2.f * cursorPos.x()) / geom.width()) - 1.f), - (1.f - ((2.f * cursorPos.y()) / geom.height())) + QPoint CursorPos = QCursor::pos(); + QRect Geom = QApplication::desktop()->screenGeometry(); + CVector2f MouseCoords( + (((2.f * CursorPos.x()) / Geom.width()) - 1.f), + (1.f - ((2.f * CursorPos.y()) / Geom.height())) ); // Translate if (mMode == eTranslate) { // Create translate plane - CVector3f axisA, axisB; - u32 numAxes = NumSelectedAxes(); + CVector3f AxisA, AxisB; + u32 NumAxes = NumSelectedAxes(); - if (numAxes == 1) + if (NumAxes == 1) { - if (mSelectedAxes & eX) axisB = mRotation.XAxis(); - else if (mSelectedAxes & eY) axisB = mRotation.YAxis(); - else axisB = mRotation.ZAxis(); + if (mSelectedAxes & eX) AxisB = mRotation.XAxis(); + else if (mSelectedAxes & eY) AxisB = mRotation.YAxis(); + else AxisB = mRotation.ZAxis(); - CVector3f gizmoToCamera = (mPosition - camera.Position()).Normalized(); - axisA = axisB.Cross(gizmoToCamera); + CVector3f GizmoToCamera = (mPosition - rCamera.Position()).Normalized(); + AxisA = AxisB.Cross(GizmoToCamera); } - else if (numAxes == 2) + else if (NumAxes == 2) { - axisA = (mSelectedAxes & eX ? mRotation.XAxis() : mRotation.YAxis()); - axisB = (mSelectedAxes & eZ ? mRotation.ZAxis() : mRotation.YAxis()); + AxisA = (mSelectedAxes & eX ? mRotation.XAxis() : mRotation.YAxis()); + AxisB = (mSelectedAxes & eZ ? mRotation.ZAxis() : mRotation.YAxis()); } - CVector3f planeNormal = axisA.Cross(axisB); - mTranslatePlane.Redefine(planeNormal, mPosition); + CVector3f PlaneNormal = AxisA.Cross(AxisB); + mTranslatePlane.Redefine(PlaneNormal, mPosition); // Do translate - std::pair result = Math::RayPlaneIntersecton(ray, mTranslatePlane); + std::pair Result = Math::RayPlaneIntersecton(rkRay, mTranslatePlane); - if (result.first) + if (Result.first) { - CVector3f hit = ray.PointOnRay(result.second); - CVector3f localDelta = mRotation.Inverse() * (hit - mPosition); + CVector3f Hit = rkRay.PointOnRay(Result.second); + CVector3f LocalDelta = mRotation.Inverse() * (Hit - mPosition); // Calculate new position - CVector3f newPos = mPosition; - if (mSelectedAxes & eX) newPos += mRotation.XAxis() * localDelta.x; - if (mSelectedAxes & eY) newPos += mRotation.YAxis() * localDelta.y; - if (mSelectedAxes & eZ) newPos += mRotation.ZAxis() * localDelta.z; + CVector3f NewPos = mPosition; + if (mSelectedAxes & eX) NewPos += mRotation.XAxis() * LocalDelta.X; + if (mSelectedAxes & eY) NewPos += mRotation.YAxis() * LocalDelta.Y; + if (mSelectedAxes & eZ) NewPos += mRotation.ZAxis() * LocalDelta.Z; // Check relativity of new pos to camera to reduce issue where the gizmo might // go flying off into the distance if newPosToCamera is parallel to the plane - CVector3f newPosToCamera = (newPos - camera.Position()).Normalized(); - float dot = Math::Abs(planeNormal.Dot(newPosToCamera)); - if (dot < 0.02f) return false; + CVector3f NewPosToCamera = (NewPos - rCamera.Position()).Normalized(); + float Dot = Math::Abs(PlaneNormal.Dot(NewPosToCamera)); + if (Dot < 0.02f) return false; // Set offset if (!mSetOffset) { - mTranslateOffset = mPosition - newPos; + mTranslateOffset = mPosition - NewPos; mDeltaTranslation = CVector3f::skZero; mSetOffset = true; return false; @@ -351,10 +348,10 @@ bool CGizmo::TransformFromInput(const CRay& ray, CCamera& camera) // Apply translation else { - mDeltaTranslation = mRotation.Inverse() * (newPos - mPosition + mTranslateOffset); - if (!(mSelectedAxes & eX)) mDeltaTranslation.x = 0.f; - if (!(mSelectedAxes & eY)) mDeltaTranslation.y = 0.f; - if (!(mSelectedAxes & eZ)) mDeltaTranslation.z = 0.f; + mDeltaTranslation = mRotation.Inverse() * (NewPos - mPosition + mTranslateOffset); + if (!(mSelectedAxes & eX)) mDeltaTranslation.X = 0.f; + if (!(mSelectedAxes & eY)) mDeltaTranslation.Y = 0.f; + if (!(mSelectedAxes & eZ)) mDeltaTranslation.Z = 0.f; mTotalTranslation += mDeltaTranslation; mPosition += mRotation * mDeltaTranslation; @@ -377,42 +374,42 @@ bool CGizmo::TransformFromInput(const CRay& ray, CCamera& camera) else if (mMode == eRotate) { // Choose rotation axis - CVector3f axis; - if (mSelectedAxes & eX) axis = CVector3f::skUnitX; - else if (mSelectedAxes & eY) axis = CVector3f::skUnitY; - else axis = CVector3f::skUnitZ; + CVector3f Axis; + if (mSelectedAxes & eX) Axis = CVector3f::skUnitX; + else if (mSelectedAxes & eY) Axis = CVector3f::skUnitY; + else Axis = CVector3f::skUnitZ; // Convert hit point + move direction into a line in screen space // Clockwise direction is set in StartTransform(). Is there a cleaner way to calculate the direction? - CMatrix4f VP = camera.ViewMatrix().Transpose() * camera.ProjectionMatrix().Transpose(); - CVector2f lineOrigin = (mHitPoint * VP).xy(); - CVector2f lineDir = (((mHitPoint + mMoveDir) * VP).xy() - lineOrigin).Normalized(); - float rotAmount = lineDir.Dot(mouseCoords + mWrapOffset - lineOrigin) * 180.f; + CMatrix4f VP = rCamera.ViewMatrix().Transpose() * rCamera.ProjectionMatrix().Transpose(); + CVector2f LineOrigin = (mHitPoint * VP).XY(); + CVector2f LineDir = (((mHitPoint + mMoveDir) * VP).XY() - LineOrigin).Normalized(); + float RotAmount = LineDir.Dot(MouseCoords + mWrapOffset - LineOrigin) * 180.f; // Set offset if (!mSetOffset) { - mRotateOffset = -rotAmount; + mRotateOffset = -RotAmount; mDeltaRotation = CQuaternion::skIdentity; mSetOffset = true; return false; } // Apply rotation - rotAmount += mRotateOffset; - CQuaternion oldRot = mCurrentRotation; - mCurrentRotation = CQuaternion::FromAxisAngle(Math::DegreesToRadians(rotAmount), axis); - mDeltaRotation = mCurrentRotation * oldRot.Inverse(); + RotAmount += mRotateOffset; + CQuaternion OldRot = mCurrentRotation; + mCurrentRotation = CQuaternion::FromAxisAngle(Math::DegreesToRadians(RotAmount), Axis); + mDeltaRotation = mCurrentRotation * OldRot.Inverse(); if (mTransformSpace == eLocalTransform) mRotation *= mDeltaRotation; // Add to total - if (mSelectedAxes & eX) mTotalRotation.x = rotAmount; - else if (mSelectedAxes & eY) mTotalRotation.y = rotAmount; - else mTotalRotation.z = rotAmount; + if (mSelectedAxes & eX) mTotalRotation.X = RotAmount; + else if (mSelectedAxes & eY) mTotalRotation.Y = RotAmount; + else mTotalRotation.Z = RotAmount; - if (!mHasTransformed && (rotAmount != 0.f)) + if (!mHasTransformed && (RotAmount != 0.f)) mHasTransformed = true; return mHasTransformed; @@ -422,66 +419,66 @@ bool CGizmo::TransformFromInput(const CRay& ray, CCamera& camera) else if (mMode == eScale) { // Create a line in screen space. First step: line origin - CMatrix4f VP = camera.ViewMatrix().Transpose() * camera.ProjectionMatrix().Transpose(); - CVector2f lineOrigin = (mPosition * VP).xy(); + CMatrix4f VP = rCamera.ViewMatrix().Transpose() * rCamera.ProjectionMatrix().Transpose(); + CVector2f LineOrigin = (mPosition * VP).XY(); // Next step: determine the appropriate world space direction using the selected axes and then convert to screen space // Since the axes can be flipped while the gizmo is transforming, this has to be done every frame rather than // pre-saving the world space direction like the rotate gizmo does. - CVector3f dirX = (mFlipScaleX ? -mRotation.XAxis() : mRotation.XAxis()); - CVector3f dirY = (mFlipScaleY ? -mRotation.YAxis() : mRotation.YAxis()); - CVector3f dirZ = (mFlipScaleZ ? -mRotation.ZAxis() : mRotation.ZAxis()); - CVector2f lineDir; + CVector3f DirX = (mFlipScaleX ? -mRotation.XAxis() : mRotation.XAxis()); + CVector3f DirY = (mFlipScaleY ? -mRotation.YAxis() : mRotation.YAxis()); + CVector3f DirZ = (mFlipScaleZ ? -mRotation.ZAxis() : mRotation.ZAxis()); + CVector2f LineDir; // One axis - world space direction is just the selected axis if (NumSelectedAxes() == 1) { - CVector3f worldDir; - if (mSelectedAxes & eX) worldDir = dirX; - else if (mSelectedAxes & eY) worldDir = dirY; - else worldDir = dirZ; - lineDir = (((mPosition + worldDir) * VP).xy() - lineOrigin).Normalized(); + CVector3f WorldDir; + if (mSelectedAxes & eX) WorldDir = DirX; + else if (mSelectedAxes & eY) WorldDir = DirY; + else WorldDir = DirZ; + LineDir = (((mPosition + WorldDir) * VP).XY() - LineOrigin).Normalized(); } // Two axes - take the two selected axes and convert them to world space, then average them for the line direction else if (NumSelectedAxes() == 2) { - CVector3f axisA = (mSelectedAxes & eX ? dirX : dirY); - CVector3f axisB = (mSelectedAxes & eZ ? dirZ : dirY); - CVector2f screenA = (((mPosition + axisA) * VP).xy() - lineOrigin).Normalized(); - CVector2f screenB = (((mPosition + axisB) * VP).xy() - lineOrigin).Normalized(); - lineDir = ((screenA + screenB) / 2.f).Normalized(); + CVector3f AxisA = (mSelectedAxes & eX ? DirX : DirY); + CVector3f AxisB = (mSelectedAxes & eZ ? DirZ : DirY); + CVector2f ScreenA = (((mPosition + AxisA) * VP).XY() - LineOrigin).Normalized(); + CVector2f ScreenB = (((mPosition + AxisB) * VP).XY() - LineOrigin).Normalized(); + LineDir = ((ScreenA + ScreenB) / 2.f).Normalized(); } // Three axes - use straight up - else lineDir = CVector2f::skUp; + else LineDir = CVector2f::skUp; - float scaleAmount = lineDir.Dot(mouseCoords + mWrapOffset - lineOrigin) * 5.f; + float ScaleAmount = LineDir.Dot(MouseCoords + mWrapOffset - LineOrigin) * 5.f; // Set offset if (!mSetOffset) { - mScaleOffset = -scaleAmount; + mScaleOffset = -ScaleAmount; mDeltaScale = CVector3f::skOne; mSetOffset = true; return false; } // Apply scale - scaleAmount = scaleAmount + mScaleOffset + 1.f; + ScaleAmount = ScaleAmount + mScaleOffset + 1.f; // A multiplier is applied to the scale amount of it's less than 1 to prevent it from going negative - if (scaleAmount < 1.f) - scaleAmount = 1.f / (-(scaleAmount - 1.f) + 1.f); + if (ScaleAmount < 1.f) + ScaleAmount = 1.f / (-(ScaleAmount - 1.f) + 1.f); - CVector3f oldScale = mTotalScale; + CVector3f OldScale = mTotalScale; mTotalScale = CVector3f::skOne; - if (mSelectedAxes & eX) mTotalScale.x = scaleAmount; - if (mSelectedAxes & eY) mTotalScale.y = scaleAmount; - if (mSelectedAxes & eZ) mTotalScale.z = scaleAmount; + if (mSelectedAxes & eX) mTotalScale.X = ScaleAmount; + if (mSelectedAxes & eY) mTotalScale.Y = ScaleAmount; + if (mSelectedAxes & eZ) mTotalScale.Z = ScaleAmount; - mDeltaScale = mTotalScale / oldScale; + mDeltaScale = mTotalScale / OldScale; - if (!mHasTransformed && (scaleAmount != 1.f)) + if (!mHasTransformed && (ScaleAmount != 1.f)) mHasTransformed = true; return mHasTransformed; @@ -496,76 +493,11 @@ void CGizmo::EndTransform() mIsTransforming = false; } -bool CGizmo::IsTransforming() const +void CGizmo::SetMode(EGizmoMode Mode) { - return mIsTransforming; -} + mMode = Mode; -bool CGizmo::HasTransformed() const -{ - return mHasTransformed; -} - -CGizmo::EGizmoMode CGizmo::Mode() const -{ - return mMode; -} - -ETransformSpace CGizmo::TransformSpace() const -{ - return mTransformSpace; -} - -CVector3f CGizmo::Position() const -{ - return mPosition; -} - -CVector3f CGizmo::DeltaTranslation() const -{ - return mDeltaTranslation; -} - -CVector3f CGizmo::TotalTranslation() const -{ - return mTotalTranslation; -} - -CQuaternion CGizmo::Rotation() const -{ - return mRotation; -} - -CQuaternion CGizmo::DeltaRotation() const -{ - return mDeltaRotation; -} - -CVector3f CGizmo::TotalRotation() const -{ - return mTotalRotation; -} - -CVector3f CGizmo::Scale() const -{ - return mScale; -} - -CVector3f CGizmo::DeltaScale() const -{ - return mDeltaScale; -} - -CVector3f CGizmo::TotalScale() const -{ - return mTotalScale; -} - -void CGizmo::SetMode(EGizmoMode mode) -{ - mMode = mode; - - switch (mode) + switch (Mode) { case eTranslate: mpCurrentParts = smTranslateModels; @@ -590,32 +522,22 @@ void CGizmo::SetMode(EGizmoMode mode) } } -void CGizmo::SetTransformSpace(ETransformSpace space) +void CGizmo::SetTransformSpace(ETransformSpace Space) { - mTransformSpace = space; + mTransformSpace = Space; - if (space == eWorldTransform) + if (Space == eWorldTransform) mRotation = CQuaternion::skIdentity; else mRotation = mLocalRotation; } -void CGizmo::SetPosition(const CVector3f& position) +void CGizmo::SetLocalRotation(const CQuaternion& rkOrientation) { - mPosition = position; -} - -void CGizmo::SetLocalRotation(const CQuaternion& orientation) -{ - mLocalRotation = orientation; + mLocalRotation = rkOrientation; if (mTransformSpace == eLocalTransform) - mRotation = orientation; -} - -void CGizmo::EnableCursorWrap(bool wrap) -{ - mEnableCursorWrap = wrap; + mRotation = rkOrientation; } // ************ PRIVATE STATIC ************ @@ -666,9 +588,9 @@ void CGizmo::UpdateTransform() // Scale also factors in axis flip if mode is Scale. if (mMode == eScale) { - if (mFlipScaleX) mScale.x = -mScale.x; - if (mFlipScaleY) mScale.y = -mScale.y; - if (mFlipScaleZ) mScale.z = -mScale.z; + if (mFlipScaleX) mScale.X = -mScale.X; + if (mFlipScaleY) mScale.Y = -mScale.Y; + if (mFlipScaleZ) mScale.Z = -mScale.Z; } // Create transform @@ -698,33 +620,33 @@ void CGizmo::UpdateTransform() void CGizmo::WrapCursor() { - QRect geom = QApplication::desktop()->screenGeometry(); - QPoint cursorPos = QCursor::pos(); + QRect Geom = QApplication::desktop()->screenGeometry(); + QPoint CursorPos = QCursor::pos(); // Horizontal - if (cursorPos.x() == geom.width() - 1) + if (CursorPos.x() == Geom.width() - 1) { - QCursor::setPos(1, cursorPos.y()); - mWrapOffset.x += 2.f; + QCursor::setPos(1, CursorPos.y()); + mWrapOffset.X += 2.f; } - else if (cursorPos.x() == 0) + else if (CursorPos.x() == 0) { - QCursor::setPos(geom.width() - 2, cursorPos.y()); - mWrapOffset.x -= 2.f; + QCursor::setPos(Geom.width() - 2, CursorPos.y()); + mWrapOffset.X -= 2.f; } // Vertical - cursorPos = QCursor::pos(); // Grab again to account for changes on horizontal wrap + CursorPos = QCursor::pos(); // Grab again to account for changes on horizontal wrap - if (cursorPos.y() == geom.height() - 1) + if (CursorPos.y() == Geom.height() - 1) { - QCursor::setPos(cursorPos.x(), 1); - mWrapOffset.y -= 2.f; + QCursor::setPos(CursorPos.x(), 1); + mWrapOffset.Y -= 2.f; } - else if (cursorPos.y() == 0) + else if (CursorPos.y() == 0) { - QCursor::setPos(cursorPos.x(), geom.height() - 2); - mWrapOffset.y += 2.f; + QCursor::setPos(CursorPos.x(), Geom.height() - 2); + mWrapOffset.Y += 2.f; } } diff --git a/src/Editor/CGizmo.h b/src/Editor/CGizmo.h index df4c8614..3e303141 100644 --- a/src/Editor/CGizmo.h +++ b/src/Editor/CGizmo.h @@ -105,14 +105,14 @@ private: // Model parts struct SModelPart { - FGizmoAxes modelAxes; - bool enableRayCast; - bool isBillboard; + FGizmoAxes ModelAxes; + bool EnableRayCast; + bool IsBillboard; TResPtr pModel; SModelPart() {} - SModelPart(FGizmoAxes axes, bool rayCastOn, bool billboard, TResPtr _pModel) : - modelAxes(axes), enableRayCast(rayCastOn), isBillboard(billboard), pModel(_pModel) {} + SModelPart(FGizmoAxes Axes, bool RayCastOn, bool Billboard, TResPtr _pModel) : + ModelAxes(Axes), EnableRayCast(RayCastOn), IsBillboard(Billboard), pModel(_pModel) {} }; SModelPart *mpCurrentParts; u32 mNumCurrentParts; @@ -127,37 +127,39 @@ public: CGizmo(); ~CGizmo(); - void AddToRenderer(CRenderer *pRenderer, const SViewInfo& ViewInfo); - void Draw(FRenderOptions Options, int ComponentIndex, const SViewInfo& ViewInfo); + void AddToRenderer(CRenderer *pRenderer, const SViewInfo& rkViewInfo); + void Draw(FRenderOptions Options, int ComponentIndex, const SViewInfo& rkViewInfo); void IncrementSize(); void DecrementSize(); - void UpdateForCamera(const CCamera& camera); - bool CheckSelectedAxes(const CRay& ray); + void UpdateForCamera(const CCamera& rkCamera); + bool CheckSelectedAxes(const CRay& rkRay); u32 NumSelectedAxes(); void ResetSelectedAxes(); void StartTransform(); - bool TransformFromInput(const CRay& ray, CCamera& camera); + bool TransformFromInput(const CRay& rkRay, CCamera& rkCamera); void EndTransform(); - bool IsTransforming() const; - bool HasTransformed() const; - EGizmoMode Mode() const; - ETransformSpace TransformSpace() const; - CVector3f Position() const; - CVector3f DeltaTranslation() const; - CVector3f TotalTranslation() const; - CQuaternion Rotation() const; - CQuaternion DeltaRotation() const; - CVector3f TotalRotation() const; - CVector3f Scale() const; - CVector3f DeltaScale() const; - CVector3f TotalScale() const; + // Accessors + inline EGizmoMode Mode() const { return mMode; } + inline ETransformSpace TransformSpace() const { return mTransformSpace; } + inline CVector3f Position() const { return mPosition; } + inline CVector3f DeltaTranslation() const { return mDeltaTranslation; } + inline CVector3f TotalTranslation() const { return mTotalTranslation; } + inline CQuaternion Rotation() const { return mRotation; } + inline CQuaternion DeltaRotation() const { return mDeltaRotation; } + inline CVector3f TotalRotation() const { return mTotalRotation; } + inline CVector3f Scale() const { return mScale; } + inline CVector3f DeltaScale() const { return mDeltaScale; } + inline CVector3f TotalScale() const { return mTotalScale; } + inline bool IsTransforming() const { return mIsTransforming; } + inline bool HasTransformed() const { return mHasTransformed; } + + inline void SetPosition(const CVector3f& rkPosition) { mPosition = rkPosition; } + inline void EnableCursorWrap(bool Enable) { mEnableCursorWrap = Enable; } void SetMode(EGizmoMode mode); - void SetTransformSpace(ETransformSpace space); - void SetPosition(const CVector3f& position); - void SetLocalRotation(const CQuaternion& orientation); - void EnableCursorWrap(bool wrap); + void SetTransformSpace(ETransformSpace Space); + void SetLocalRotation(const CQuaternion& rkOrientation); // Protected protected: diff --git a/src/Editor/CNodeCopyMimeData.h b/src/Editor/CNodeCopyMimeData.h index 8e493e40..26883020 100644 --- a/src/Editor/CNodeCopyMimeData.h +++ b/src/Editor/CNodeCopyMimeData.h @@ -66,11 +66,11 @@ public: if (rNode.Type == eScriptNode) { - CScriptObject *pInst = static_cast(*It)->Object(); + CScriptObject *pInst = static_cast(*It)->Instance(); rNode.OriginalInstanceID = pInst->InstanceID(); CVectorOutStream Out(&rNode.InstanceData, IOUtil::eBigEndian); - CScriptCooker::CookInstance(eReturns, static_cast(*It)->Object(), Out); + CScriptCooker::CookInstance(eReturns, static_cast(*It)->Instance(), Out); // Replace instance ID with 0xFFFFFFFF to force it to generate a new one. Out.Seek(0x6, SEEK_SET); @@ -100,8 +100,8 @@ public: return -1; } - CUniqueID AreaID() const { return mAreaID; } - EGame Game() const { return mGame; } + CUniqueID AreaID() const { return mAreaID; } + EGame Game() const { return mGame; } const QVector& CopiedNodes() const { return mCopiedNodes; } }; diff --git a/src/Editor/CPakToolDialog.h b/src/Editor/CPakToolDialog.h index 5942738c..eec07fc4 100644 --- a/src/Editor/CPakToolDialog.h +++ b/src/Editor/CPakToolDialog.h @@ -136,6 +136,7 @@ private slots: mSetMax = true; } + // Deferring UI updates is necessary because trying to do them on this thread causes crashes for a lot of people QTimer::singleShot(0, this, SLOT(UpdateUI())); } } diff --git a/src/Editor/CSceneViewport.cpp b/src/Editor/CSceneViewport.cpp index 9176d21b..5a1105b5 100644 --- a/src/Editor/CSceneViewport.cpp +++ b/src/Editor/CSceneViewport.cpp @@ -10,15 +10,15 @@ #include CSceneViewport::CSceneViewport(QWidget *pParent) - : CBasicViewport(pParent), - mpEditor(nullptr), - mpScene(nullptr), - mRenderingMergedWorld(true), - mGizmoTransforming(false), - mpHoverNode(nullptr), - mHoverPoint(CVector3f::skZero), - mpContextMenu(nullptr), - mpMenuNode(nullptr) + : CBasicViewport(pParent) + , mpEditor(nullptr) + , mpScene(nullptr) + , mRenderingMergedWorld(true) + , mGizmoTransforming(false) + , mpHoverNode(nullptr) + , mHoverPoint(CVector3f::skZero) + , mpContextMenu(nullptr) + , mpMenuNode(nullptr) { mpRenderer = new CRenderer(); mpRenderer->SetClearColor(CColor::skBlack); @@ -58,14 +58,14 @@ void CSceneViewport::SetShowWorld(bool Visible) SetShowFlag(eShowSplitWorld, Visible); } -void CSceneViewport::SetRenderMergedWorld(bool b) +void CSceneViewport::SetRenderMergedWorld(bool RenderMerged) { - mRenderingMergedWorld = b; + mRenderingMergedWorld = RenderMerged; if (mViewInfo.ShowFlags & (eShowSplitWorld | eShowMergedWorld)) { - SetShowFlag(eShowSplitWorld, !b); - SetShowFlag(eShowMergedWorld, b); + SetShowFlag(eShowSplitWorld, !RenderMerged); + SetShowFlag(eShowMergedWorld, RenderMerged); } } @@ -89,7 +89,7 @@ CVector3f CSceneViewport::HoverPoint() return mHoverPoint; } -void CSceneViewport::CheckGizmoInput(const CRay& ray) +void CSceneViewport::CheckGizmoInput(const CRay& rkRay) { CGizmo *pGizmo = mpEditor->Gizmo(); @@ -97,7 +97,7 @@ void CSceneViewport::CheckGizmoInput(const CRay& ray) if (!pGizmo->IsTransforming()) { if (mpEditor->IsGizmoVisible()) - mGizmoHovering = pGizmo->CheckSelectedAxes(ray); + mGizmoHovering = pGizmo->CheckSelectedAxes(rkRay); else mGizmoHovering = false; } @@ -105,7 +105,7 @@ void CSceneViewport::CheckGizmoInput(const CRay& ray) // Gizmo transforming: Run gizmo input with ray/mouse coords else if (mGizmoTransforming) { - bool transformed = pGizmo->TransformFromInput(ray, mCamera); + bool transformed = pGizmo->TransformFromInput(rkRay, mCamera); if (transformed) emit GizmoMoved(); } @@ -152,7 +152,7 @@ bool CSceneViewport::IsHoveringGizmo() return mGizmoHovering; } -void CSceneViewport::keyPressEvent(QKeyEvent* pEvent) +void CSceneViewport::keyPressEvent(QKeyEvent *pEvent) { CBasicViewport::keyPressEvent(pEvent); @@ -246,7 +246,7 @@ void CSceneViewport::FindConnectedObjects(u32 InstanceID, bool SearchOutgoing, b CScriptNode *pScript = mpScene->NodeForInstanceID(InstanceID); if (!pScript) return; - CScriptObject *pInst = pScript->Object(); + CScriptObject *pInst = pScript->Instance(); rIDList << InstanceID; if (SearchOutgoing) @@ -309,7 +309,7 @@ void CSceneViewport::Paint() if ((mViewInfo.ShowFlags & eShowSky) || mViewInfo.GameMode) { - CModel *pSky = mpScene->GetActiveSkybox(); + CModel *pSky = mpScene->ActiveSkybox(); if (pSky) mpRenderer->RenderSky(pSky, mViewInfo); } @@ -342,7 +342,7 @@ void CSceneViewport::Paint() mpRenderer->EndFrame(); } -void CSceneViewport::ContextMenu(QContextMenuEvent* pEvent) +void CSceneViewport::ContextMenu(QContextMenuEvent *pEvent) { // mpHoverNode is cleared during mouse input, so this call is necessary. todo: better way? mRayIntersection = SceneRayCast(CastRay()); @@ -366,7 +366,7 @@ void CSceneViewport::ContextMenu(QContextMenuEvent* pEvent) if (HasHoverNode) { - TString Name = IsScriptNode ? static_cast(mpHoverNode)->Object()->InstanceName() : mpHoverNode->Name(); + TString Name = IsScriptNode ? static_cast(mpHoverNode)->Instance()->InstanceName() : mpHoverNode->Name(); if (mpHoverNode->IsSelected()) mpToggleSelectAction->setText(QString("Deselect %1").arg(TO_QSTRING(Name))); @@ -377,9 +377,9 @@ void CSceneViewport::ContextMenu(QContextMenuEvent* pEvent) if (IsScriptNode) { CScriptNode *pScript = static_cast(mpHoverNode); - NodeName = pScript->Object()->InstanceName(); + NodeName = pScript->Instance()->InstanceName(); mpHideHoverTypeAction->setText( QString("Hide all %1 objects").arg(TO_QSTRING(pScript->Template()->Name())) ); - mpHideHoverLayerAction->setText( QString("Hide layer %1").arg(TO_QSTRING(pScript->Object()->Layer()->Name())) ); + mpHideHoverLayerAction->setText( QString("Hide layer %1").arg(TO_QSTRING(pScript->Instance()->Layer()->Name())) ); } else if (HasHoverNode) @@ -399,10 +399,10 @@ void CSceneViewport::OnResize() void CSceneViewport::OnMouseClick(QMouseEvent *pEvent) { - bool altPressed = ((pEvent->modifiers() & Qt::AltModifier) != 0); - bool ctrlPressed = ((pEvent->modifiers() & Qt::ControlModifier) != 0); + bool AltPressed = ((pEvent->modifiers() & Qt::AltModifier) != 0); + bool CtrlPressed = ((pEvent->modifiers() & Qt::ControlModifier) != 0); - if (mGizmoHovering && !altPressed && !ctrlPressed) + if (mGizmoHovering && !AltPressed && !CtrlPressed) { mGizmoTransforming = true; mpEditor->Gizmo()->StartTransform(); @@ -443,7 +443,7 @@ void CSceneViewport::OnSelectConnected() QList InstanceIDs; bool SearchOutgoing = (sender() == mpSelectConnectedOutgoingAction || sender() == mpSelectConnectedAllAction); bool SearchIncoming = (sender() == mpSelectConnectedIncomingAction || sender() == mpSelectConnectedAllAction); - FindConnectedObjects(static_cast(mpMenuNode)->Object()->InstanceID(), SearchOutgoing, SearchIncoming, InstanceIDs); + FindConnectedObjects(static_cast(mpMenuNode)->Instance()->InstanceID(), SearchOutgoing, SearchIncoming, InstanceIDs); QList Nodes; foreach (u32 ID, InstanceIDs) @@ -478,7 +478,7 @@ void CSceneViewport::OnHideType() void CSceneViewport::OnHideLayer() { - static_cast(mpMenuNode)->Object()->Layer()->SetVisible(false); + static_cast(mpMenuNode)->Instance()->Layer()->SetVisible(false); } void CSceneViewport::OnUnhideAll() @@ -502,7 +502,7 @@ void CSceneViewport::OnUnhideAll() else { pScript->Template()->SetVisible(true); - pScript->Object()->Layer()->SetVisible(true); + pScript->Instance()->Layer()->SetVisible(true); } } } diff --git a/src/Editor/CSceneViewport.h b/src/Editor/CSceneViewport.h index e5993071..dc541372 100644 --- a/src/Editor/CSceneViewport.h +++ b/src/Editor/CSceneViewport.h @@ -49,13 +49,13 @@ public: void SetScene(INodeEditor *pEditor, CScene *pScene); void SetShowFlag(EShowFlag Flag, bool Visible); void SetShowWorld(bool Visible); - void SetRenderMergedWorld(bool b); + void SetRenderMergedWorld(bool RenderMerged); FShowFlags ShowFlags() const; CRenderer* Renderer(); CSceneNode* HoverNode(); CVector3f HoverPoint(); - void CheckGizmoInput(const CRay& ray); - SRayIntersection SceneRayCast(const CRay& ray); + void CheckGizmoInput(const CRay& rkRay); + SRayIntersection SceneRayCast(const CRay& rkRay); void ResetHover(); bool IsHoveringGizmo(); diff --git a/src/Editor/CStartWindow.cpp b/src/Editor/CStartWindow.cpp index 8808f72e..001c4f78 100644 --- a/src/Editor/CStartWindow.cpp +++ b/src/Editor/CStartWindow.cpp @@ -13,9 +13,9 @@ #include #include -CStartWindow::CStartWindow(QWidget *parent) : - QMainWindow(parent), - ui(new Ui::CStartWindow) +CStartWindow::CStartWindow(QWidget *parent) + : QMainWindow(parent) + , ui(new Ui::CStartWindow) { ui->setupUi(this); mpWorld = nullptr; @@ -62,10 +62,10 @@ void CStartWindow::on_actionOpen_MLVL_triggered() void CStartWindow::FillWorldUI() { - CStringTable *pWorldName = mpWorld->GetWorldName(); + CStringTable *pWorldName = mpWorld->WorldName(); if (pWorldName) { - TWideString WorldName = pWorldName->GetString("ENGL", 0); + TWideString WorldName = pWorldName->String("ENGL", 0); ui->WorldNameLabel->setText( QString("") + TO_QSTRING(WorldName) + QString("") ); ui->WorldNameSTRGLineEdit->setText(TO_QSTRING(pWorldName->Source())); @@ -80,39 +80,40 @@ void CStartWindow::FillWorldUI() Log::Write("Loaded " + mpWorld->Source() + " (unnamed world)"); } - CStringTable *pDarkWorldName = mpWorld->GetDarkWorldName(); + CStringTable *pDarkWorldName = mpWorld->DarkWorldName(); if (pDarkWorldName) ui->DarkWorldNameSTRGLineEdit->setText(TO_QSTRING(pDarkWorldName->Source())); else ui->DarkWorldNameSTRGLineEdit->clear(); - CModel *pDefaultSkybox = mpWorld->GetDefaultSkybox(); + CModel *pDefaultSkybox = mpWorld->DefaultSkybox(); if (pDefaultSkybox) ui->DefaultSkyboxCMDLLineEdit->setText(TO_QSTRING(pDefaultSkybox->Source())); else ui->DefaultSkyboxCMDLLineEdit->clear(); - CResource *pSaveWorld = mpWorld->GetSaveWorld(); + CResource *pSaveWorld = mpWorld->SaveWorld(); if (pSaveWorld) ui->WorldSAVWLineEdit->setText(TO_QSTRING(pSaveWorld->Source())); else ui->WorldSAVWLineEdit->clear(); - CResource *pMapWorld = mpWorld->GetMapWorld(); + CResource *pMapWorld = mpWorld->MapWorld(); if (pMapWorld) ui->WorldMAPWLineEdit->setText(TO_QSTRING(pMapWorld->Source())); else ui->WorldMAPWLineEdit->clear(); - u32 NumAreas = mpWorld->GetNumAreas(); + u32 NumAreas = mpWorld->NumAreas(); ui->AreaSelectComboBox->blockSignals(true); ui->AreaSelectComboBox->clear(); ui->AreaSelectComboBox->blockSignals(false); ui->AreaSelectComboBox->setDisabled(false); + for (u32 iArea = 0; iArea < NumAreas; iArea++) { - CStringTable *pAreaName = mpWorld->GetAreaName(iArea); - QString AreaName = (pAreaName != nullptr) ? TO_QSTRING(pAreaName->GetString("ENGL", 0)) : QString("!!") + TO_QSTRING(mpWorld->GetAreaInternalName(iArea)); + CStringTable *pAreaName = mpWorld->AreaName(iArea); + QString AreaName = (pAreaName != nullptr) ? TO_QSTRING(pAreaName->String("ENGL", 0)) : QString("!!") + TO_QSTRING(mpWorld->AreaInternalName(iArea)); ui->AreaSelectComboBox->addItem(AreaName); } } @@ -128,15 +129,15 @@ void CStartWindow::FillAreaUI() ui->AreaSelectComboBox->setCurrentIndex(mSelectedAreaIndex); ui->AreaSelectComboBox->blockSignals(false); - ui->AreaNameLineEdit->setText(TO_QSTRING(mpWorld->GetAreaInternalName(mSelectedAreaIndex))); + ui->AreaNameLineEdit->setText(TO_QSTRING(mpWorld->AreaInternalName(mSelectedAreaIndex))); - CStringTable *pAreaName = mpWorld->GetAreaName(mSelectedAreaIndex); + CStringTable *pAreaName = mpWorld->AreaName(mSelectedAreaIndex); if (pAreaName) ui->AreaNameSTRGLineEdit->setText(TO_QSTRING(pAreaName->Source())); else ui->AreaNameSTRGLineEdit->clear(); - u64 MREA = mpWorld->GetAreaResourceID(mSelectedAreaIndex); + u64 MREA = mpWorld->AreaResourceID(mSelectedAreaIndex); TString MREAStr; if (MREA & 0xFFFFFFFF00000000) MREAStr = TString::FromInt64(MREA, 16); @@ -145,20 +146,20 @@ void CStartWindow::FillAreaUI() ui->AreaMREALineEdit->setText(TO_QSTRING(MREAStr) + QString(".MREA")); - u32 NumAttachedAreas = mpWorld->GetAreaAttachedCount(mSelectedAreaIndex); + u32 NumAttachedAreas = mpWorld->AreaAttachedCount(mSelectedAreaIndex); ui->AttachedAreasList->clear(); for (u32 iArea = 0; iArea < NumAttachedAreas; iArea++) { - u32 AttachedAreaIndex = mpWorld->GetAreaAttachedID(mSelectedAreaIndex, iArea); + u32 AttachedAreaIndex = mpWorld->AreaAttachedID(mSelectedAreaIndex, iArea); - CStringTable *AttachedAreaSTRG = mpWorld->GetAreaName(AttachedAreaIndex); + CStringTable *AttachedAreaSTRG = mpWorld->AreaName(AttachedAreaIndex); QString AttachedStr; if (AttachedAreaSTRG) - AttachedStr = TO_QSTRING(AttachedAreaSTRG->GetString("ENGL", 0)); + AttachedStr = TO_QSTRING(AttachedAreaSTRG->String("ENGL", 0)); else - AttachedStr = QString("!") + TO_QSTRING(mpWorld->GetAreaInternalName(AttachedAreaIndex)); + AttachedStr = QString("!") + TO_QSTRING(mpWorld->AreaInternalName(AttachedAreaIndex)); ui->AttachedAreasList->addItem(AttachedStr); } @@ -166,15 +167,15 @@ void CStartWindow::FillAreaUI() ui->LaunchWorldEditorButton->setDisabled(false); } -void CStartWindow::on_AreaSelectComboBox_currentIndexChanged(int index) +void CStartWindow::on_AreaSelectComboBox_currentIndexChanged(int Index) { - mSelectedAreaIndex = index; + mSelectedAreaIndex = Index; FillAreaUI(); } -void CStartWindow::on_AttachedAreasList_doubleClicked(const QModelIndex &index) +void CStartWindow::on_AttachedAreasList_doubleClicked(const QModelIndex& rkIndex) { - mSelectedAreaIndex = mpWorld->GetAreaAttachedID(mSelectedAreaIndex, index.row()); + mSelectedAreaIndex = mpWorld->AreaAttachedID(mSelectedAreaIndex, rkIndex.row()); FillAreaUI(); } @@ -184,7 +185,7 @@ void CStartWindow::on_LaunchWorldEditorButton_clicked() { Log::ClearErrorLog(); - u64 AreaID = mpWorld->GetAreaResourceID(mSelectedAreaIndex); + u64 AreaID = mpWorld->AreaResourceID(mSelectedAreaIndex); TResPtr pArea = gResCache.GetResource(AreaID, "MREA"); if (!pArea) diff --git a/src/Editor/CStartWindow.h b/src/Editor/CStartWindow.h index fea920d5..314237b5 100644 --- a/src/Editor/CStartWindow.h +++ b/src/Editor/CStartWindow.h @@ -24,23 +24,17 @@ class CStartWindow : public QMainWindow CModelEditorWindow *mpModelEditor; public: - explicit CStartWindow(QWidget *parent = 0); + explicit CStartWindow(QWidget *pParent = 0); ~CStartWindow(); void closeEvent(QCloseEvent *pEvent); private slots: void on_actionOpen_MLVL_triggered(); - - void on_AreaSelectComboBox_currentIndexChanged(int index); - - void on_AttachedAreasList_doubleClicked(const QModelIndex &index); - + void on_AreaSelectComboBox_currentIndexChanged(int Index); + void on_AttachedAreasList_doubleClicked(const QModelIndex& rkIndex); void on_LaunchWorldEditorButton_clicked(); - void on_actionLaunch_model_viewer_triggered(); - void on_actionExtract_PAK_triggered(); - void About(); private: diff --git a/src/Editor/Editor.pro b/src/Editor/Editor.pro index 48b49a1d..72157483 100644 --- a/src/Editor/Editor.pro +++ b/src/Editor/Editor.pro @@ -96,12 +96,10 @@ HEADERS += \ Undo/UndoCommands.h \ Widgets/IPreviewPanel.h \ Widgets/WAnimParamsEditor.h \ - Widgets/WCollapsibleGroupBox.h \ Widgets/WColorPicker.h \ Widgets/WDraggableSpinBox.h \ Widgets/WIntegralSpinBox.h \ Widgets/WResourceSelector.h \ - Widgets/WRollout.h \ Widgets/WScanPreviewPanel.h \ Widgets/WStringPreviewPanel.h \ Widgets/WTextureGLWidget.h \ @@ -115,7 +113,6 @@ HEADERS += \ WorldEditor/WInstancesTab.h \ WorldEditor/WModifyTab.h \ CBasicViewport.h \ - CDarkStyle.h \ CGizmo.h \ CNodeSelection.h \ CSceneViewport.h \ @@ -170,12 +167,10 @@ SOURCES += \ Undo/CTranslateNodeCommand.cpp \ Widgets/IPreviewPanel.cpp \ Widgets/WAnimParamsEditor.cpp \ - Widgets/WCollapsibleGroupBox.cpp \ Widgets/WColorPicker.cpp \ Widgets/WDraggableSpinBox.cpp \ Widgets/WIntegralSpinBox.cpp \ Widgets/WResourceSelector.cpp \ - Widgets/WRollout.cpp \ Widgets/WScanPreviewPanel.cpp \ Widgets/WStringPreviewPanel.cpp \ Widgets/WTextureGLWidget.cpp \ @@ -189,7 +184,6 @@ SOURCES += \ WorldEditor/WInstancesTab.cpp \ WorldEditor/WModifyTab.cpp \ CBasicViewport.cpp \ - CDarkStyle.cpp \ CGizmo.cpp \ CSceneViewport.cpp \ CStartWindow.cpp \ diff --git a/src/Editor/INodeEditor.cpp b/src/Editor/INodeEditor.cpp index 88afe9f3..d6713d27 100644 --- a/src/Editor/INodeEditor.cpp +++ b/src/Editor/INodeEditor.cpp @@ -322,22 +322,22 @@ void INodeEditor::OnGizmoMoved() { case CGizmo::eTranslate: { - CVector3f delta = mGizmo.DeltaTranslation(); - mUndoStack.push(new CTranslateNodeCommand(this, mpSelection->SelectedNodeList(), delta, mTranslateSpace)); + CVector3f Delta = mGizmo.DeltaTranslation(); + mUndoStack.push(new CTranslateNodeCommand(this, mpSelection->SelectedNodeList(), Delta, mTranslateSpace)); break; } case CGizmo::eRotate: { - CQuaternion delta = mGizmo.DeltaRotation(); - mUndoStack.push(new CRotateNodeCommand(this, mpSelection->SelectedNodeList(), CVector3f::skZero, delta, mRotateSpace)); + CQuaternion Delta = mGizmo.DeltaRotation(); + mUndoStack.push(new CRotateNodeCommand(this, mpSelection->SelectedNodeList(), CVector3f::skZero, Delta, mRotateSpace)); break; } case CGizmo::eScale: { - CVector3f delta = mGizmo.DeltaScale(); - mUndoStack.push(new CScaleNodeCommand(this, mpSelection->SelectedNodeList(), CVector3f::skZero, delta)); + CVector3f Delta = mGizmo.DeltaScale(); + mUndoStack.push(new CScaleNodeCommand(this, mpSelection->SelectedNodeList(), CVector3f::skZero, Delta)); break; } } @@ -512,16 +512,16 @@ void INodeEditor::OnScaleTriggered() UpdateGizmoUI(); } -void INodeEditor::OnTransformSpaceChanged(int spaceIndex) +void INodeEditor::OnTransformSpaceChanged(int SpaceIndex) { if ((mGizmo.Mode() == CGizmo::eScale) || (mGizmo.Mode() == CGizmo::eOff)) return; - ETransformSpace space = (spaceIndex == 0 ? eWorldTransform : eLocalTransform); + ETransformSpace Space = (SpaceIndex == 0 ? eWorldTransform : eLocalTransform); if (mGizmo.Mode() == CGizmo::eTranslate) - mTranslateSpace = space; + mTranslateSpace = Space; else - mRotateSpace = space; + mRotateSpace = Space; - mGizmo.SetTransformSpace(space); + mGizmo.SetTransformSpace(Space); } diff --git a/src/Editor/INodeEditor.h b/src/Editor/INodeEditor.h index 055d9da7..152defdd 100644 --- a/src/Editor/INodeEditor.h +++ b/src/Editor/INodeEditor.h @@ -117,7 +117,7 @@ private slots: void OnTranslateTriggered(); void OnRotateTriggered(); void OnScaleTriggered(); - void OnTransformSpaceChanged(int spaceIndex); + void OnTransformSpaceChanged(int SpaceIndex); }; #endif // INODEEDITOR_H diff --git a/src/Editor/ModelEditor/CModelEditorViewport.cpp b/src/Editor/ModelEditor/CModelEditorViewport.cpp index f782007c..77d44cdc 100644 --- a/src/Editor/ModelEditor/CModelEditorViewport.cpp +++ b/src/Editor/ModelEditor/CModelEditorViewport.cpp @@ -2,11 +2,11 @@ #include CModelEditorViewport::CModelEditorViewport(QWidget *pParent) - : CBasicViewport(pParent), - mMode(eDrawMesh), - mpActiveMaterial(nullptr), - mpModelNode(nullptr), - mGridEnabled(true) + : CBasicViewport(pParent) + , mMode(eDrawMesh) + , mpActiveMaterial(nullptr) + , mpModelNode(nullptr) + , mGridEnabled(true) { mpRenderer = new CRenderer(); mpRenderer->SetViewportSize(width(), height()); @@ -33,14 +33,14 @@ void CModelEditorViewport::SetActiveMaterial(CMaterial *pMat) mpActiveMaterial = pMat; } -void CModelEditorViewport::SetDrawMode(EDrawMode mode) +void CModelEditorViewport::SetDrawMode(EDrawMode Mode) { - mMode = mode; + mMode = Mode; } -void CModelEditorViewport::SetClearColor(CColor color) +void CModelEditorViewport::SetClearColor(CColor Color) { - mpRenderer->SetClearColor(color); + mpRenderer->SetClearColor(Color); } void CModelEditorViewport::SetGridEnabled(bool Enable) diff --git a/src/Editor/ModelEditor/CModelEditorViewport.h b/src/Editor/ModelEditor/CModelEditorViewport.h index bef4dd33..f008179e 100644 --- a/src/Editor/ModelEditor/CModelEditorViewport.h +++ b/src/Editor/ModelEditor/CModelEditorViewport.h @@ -23,8 +23,8 @@ public: ~CModelEditorViewport(); void SetNode(CModelNode *pNode); void SetActiveMaterial(CMaterial *pMat); - void SetDrawMode(EDrawMode mode); - void SetClearColor(CColor color); + void SetDrawMode(EDrawMode Mode); + void SetClearColor(CColor Color); void SetGridEnabled(bool Enable); void Paint(); void OnResize(); diff --git a/src/Editor/ModelEditor/CModelEditorWindow.cpp b/src/Editor/ModelEditor/CModelEditorWindow.cpp index 4a292503..6bd03ac7 100644 --- a/src/Editor/ModelEditor/CModelEditorWindow.cpp +++ b/src/Editor/ModelEditor/CModelEditorWindow.cpp @@ -22,27 +22,26 @@ #include #include -CModelEditorWindow::CModelEditorWindow(QWidget *parent) : - QMainWindow(parent), - ui(new Ui::CModelEditorWindow) +CModelEditorWindow::CModelEditorWindow(QWidget *pParent) + : QMainWindow(pParent) + , ui(new Ui::CModelEditorWindow) + , mpScene(new CScene()) + , mpCurrentMat(nullptr) + , mpCurrentModel(nullptr) + , mpCurrentModelNode(new CModelNode(mpScene, -1)) + , mpCurrentPass(nullptr) + , mIgnoreSignals(false) { ui->setupUi(this); - mpScene = new CScene(); - mpCurrentMat = nullptr; - mpCurrentModel = nullptr; - mpCurrentModelNode = new CModelNode(mpScene, -1); - mpCurrentPass = nullptr; - mIgnoreSignals = false; - ui->Viewport->SetNode(mpCurrentModelNode); ui->Viewport->SetClearColor(CColor(0.3f, 0.3f, 0.3f, 1.f)); - CCamera& camera = ui->Viewport->Camera(); - camera.Snap(CVector3f(0, 3, 1)); - camera.SetMoveMode(eOrbitCamera); - camera.SetOrbit(CVector3f(0, 0, 1), 3.f); - camera.SetMoveSpeed(0.5f); + CCamera& rCamera = ui->Viewport->Camera(); + rCamera.Snap(CVector3f(0, 3, 1)); + rCamera.SetMoveMode(eOrbitCamera); + rCamera.SetOrbit(CVector3f(0, 0, 1), 3.f); + rCamera.SetMoveSpeed(0.5f); // UI initialization UpdateAnimParamUI(-1); @@ -52,7 +51,7 @@ CModelEditorWindow::CModelEditorWindow(QWidget *parent) : ui->PassTextureResSelector->SetPreviewPanelEnabled(true); ui->PassTable->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch); ui->PassTable->horizontalHeader()->setSectionResizeMode(1, QHeaderView::ResizeToContents); - ui->ClearColorPicker->setColor(QColor(76, 76, 76, 255)); + ui->ClearColorPicker->SetColor(QColor(76, 76, 76, 255)); // Viewport Signal/Slot setup connect(&mRefreshTimer, SIGNAL(timeout()), this, SLOT(RefreshViewport())); @@ -156,18 +155,18 @@ void CModelEditorWindow::SetActiveModel(CModel *pModel) mpCurrentModel = pModel; ui->Viewport->Camera().SetOrbit(pModel->AABox()); - u32 numVertices = (pModel ? pModel->GetVertexCount() : 0); - u32 numTriangles = (pModel ? pModel->GetTriangleCount() : 0); - u32 numMats = (pModel ? pModel->GetMatCount() : 0); - u32 numMatSets = (pModel ? pModel->GetMatSetCount() : 0); - ui->MeshInfoLabel->setText(QString::number(numVertices) + " vertices, " + QString::number(numTriangles) + " triangles"); - ui->MatInfoLabel->setText(QString::number(numMats) + " materials, " + QString::number(numMatSets) + " set" + (numMatSets == 1 ? "" : "s")); + u32 NumVertices = (pModel ? pModel->GetVertexCount() : 0); + u32 NumTriangles = (pModel ? pModel->GetTriangleCount() : 0); + u32 NumMats = (pModel ? pModel->GetMatCount() : 0); + u32 NumMatSets = (pModel ? pModel->GetMatSetCount() : 0); + ui->MeshInfoLabel->setText(QString::number(NumVertices) + " vertices, " + QString::number(NumTriangles) + " triangles"); + ui->MatInfoLabel->setText(QString::number(NumMats) + " materials, " + QString::number(NumMatSets) + " set" + (NumMatSets == 1 ? "" : "s")); // Set items in matset combo box ui->SetSelectionComboBox->blockSignals(true); ui->SetSelectionComboBox->clear(); - for (u32 iSet = 0; iSet < numMatSets; iSet++) + for (u32 iSet = 0; iSet < NumMatSets; iSet++) ui->SetSelectionComboBox->addItem("Set #" + QString::number(iSet + 1)); ui->SetSelectionComboBox->setCurrentIndex(0); @@ -177,22 +176,22 @@ void CModelEditorWindow::SetActiveModel(CModel *pModel) ui->MatSelectionComboBox->blockSignals(true); ui->MatSelectionComboBox->clear(); - for (u32 iMat = 0; iMat < numMats; iMat++) + for (u32 iMat = 0; iMat < NumMats; iMat++) { - TString matName = pModel->GetMaterialByIndex(0, iMat)->Name(); - ui->MatSelectionComboBox->addItem(TO_QSTRING(matName)); + TString MatName = pModel->GetMaterialByIndex(0, iMat)->Name(); + ui->MatSelectionComboBox->addItem(TO_QSTRING(MatName)); } ui->MatSelectionComboBox->setCurrentIndex(0); - ui->MatSelectionComboBox->setEnabled( numMats > 1 ); + ui->MatSelectionComboBox->setEnabled( NumMats > 1 ); ui->MatSelectionComboBox->blockSignals(false); // Emit signals to set up UI ui->SetSelectionComboBox->currentIndexChanged(0); // Gray out set selection for models with one set - ui->SetSelectionComboBox->setEnabled( numMatSets > 1 ); - ui->MatSelectionComboBox->setEnabled( numMats > 1 ); + ui->SetSelectionComboBox->setEnabled( NumMatSets > 1 ); + ui->MatSelectionComboBox->setEnabled( NumMats > 1 ); } void CModelEditorWindow::SetActiveMaterial(int MatIndex) @@ -203,7 +202,6 @@ void CModelEditorWindow::SetActiveMaterial(int MatIndex) mpCurrentMat = mpCurrentModel->GetMaterialByIndex(SetIndex, MatIndex); ui->Viewport->SetActiveMaterial(mpCurrentMat); if (!mpCurrentMat) return; - //mpCurrentMat->SetTint(CColor(1.f, 0.5f, 0.5f, 1.f)); // Set up UI CMaterial::FMaterialOptions Settings = mpCurrentMat->Options(); @@ -234,15 +232,15 @@ void CModelEditorWindow::SetActiveMaterial(int MatIndex) { QColor Color; CColor KColor = mpCurrentMat->Konst(iKonst); - Color.setRed(KColor.r * 255); - Color.setGreen(KColor.g * 255); - Color.setBlue(KColor.b * 255); - Color.setAlpha(KColor.a * 255); + Color.setRed(KColor.R * 255); + Color.setGreen(KColor.G * 255); + Color.setBlue(KColor.B * 255); + Color.setAlpha(KColor.A * 255); - if (iKonst == 0) ui->KonstColorPickerA->setColor(Color); - else if (iKonst == 1) ui->KonstColorPickerB->setColor(Color); - else if (iKonst == 2) ui->KonstColorPickerC->setColor(Color); - else if (iKonst == 3) ui->KonstColorPickerD->setColor(Color); + if (iKonst == 0) ui->KonstColorPickerA->SetColor(Color); + else if (iKonst == 1) ui->KonstColorPickerB->SetColor(Color); + else if (iKonst == 2) ui->KonstColorPickerC->SetColor(Color); + else if (iKonst == 3) ui->KonstColorPickerD->SetColor(Color); } u32 PassCount = mpCurrentMat->PassCount(); @@ -827,13 +825,13 @@ void CModelEditorWindow::on_actionImport_triggered() void CModelEditorWindow::on_actionSave_as_triggered() { - QString filename = QFileDialog::getSaveFileName(this, "Save model", "", "Retro Model (*.CMDL)"); - if (filename.isEmpty()) return; + QString FileName = QFileDialog::getSaveFileName(this, "Save model", "", "Retro Model (*.CMDL)"); + if (FileName.isEmpty()) return; - mOutputFilename = filename; + mOutputFilename = FileName; on_actionSave_triggered(); - TString name = TString(filename.toStdString()); + TString name = TString(FileName.toStdString()); setWindowTitle("Prime World Editor - Model Editor: " + TO_QSTRING(name)); } @@ -866,10 +864,10 @@ void CModelEditorWindow::on_actionConvert_DDS_to_TXTR_triggered() if (Input.isEmpty()) return; TString TexFilename = TO_TSTRING(Input); - CTexture *Tex = CTextureDecoder::LoadDDS(CFileInStream(TexFilename.ToStdString(), IOUtil::eLittleEndian)); + CTexture *pTex = CTextureDecoder::LoadDDS(CFileInStream(TexFilename.ToStdString(), IOUtil::eLittleEndian)); TString OutName = TexFilename.GetFilePathWithoutExtension() + ".txtr"; - if ((Tex->TexelFormat() != eDXT1) || (Tex->NumMipMaps() > 1)) + if ((pTex->TexelFormat() != eDXT1) || (pTex->NumMipMaps() > 1)) QMessageBox::warning(this, "Error", "Can't convert DDS to TXTR! Save your texture as a DXT1 DDS with no mipmaps, then try again."); else @@ -879,13 +877,13 @@ void CModelEditorWindow::on_actionConvert_DDS_to_TXTR_triggered() else { - CTextureEncoder::EncodeTXTR(Out, Tex, eGX_CMPR); + CTextureEncoder::EncodeTXTR(Out, pTex, eGX_CMPR); QMessageBox::information(this, "Success", "Successfully converted to TXTR!"); } } } -void CModelEditorWindow::on_ToggleGridButton_toggled(bool checked) +void CModelEditorWindow::on_ToggleGridButton_toggled(bool Checked) { - ui->Viewport->SetGridEnabled(checked); + ui->Viewport->SetGridEnabled(Checked); } diff --git a/src/Editor/ModelEditor/CModelEditorWindow.h b/src/Editor/ModelEditor/CModelEditorWindow.h index 890d7151..8d2b7127 100644 --- a/src/Editor/ModelEditor/CModelEditorWindow.h +++ b/src/Editor/ModelEditor/CModelEditorWindow.h @@ -31,7 +31,7 @@ class CModelEditorWindow : public QMainWindow QTimer mRefreshTimer; public: - explicit CModelEditorWindow(QWidget *parent = 0); + explicit CModelEditorWindow(QWidget *pParent = 0); ~CModelEditorWindow(); void SetActiveModel(CModel *pModel); void closeEvent(QCloseEvent *pEvent); @@ -45,7 +45,7 @@ public slots: void UpdateMaterial(int ValueA, int ValueB); void UpdateMaterial(double Value); void UpdateMaterial(bool Value); - void UpdateMaterial(QColor eColorProperty); + void UpdateMaterial(QColor Value); void UpdateMaterial(QString Value); void UpdateUI(int Value); void UpdateAnimParamUI(int Mode); diff --git a/src/Editor/PropertyEdit/CPropertyDelegate.cpp b/src/Editor/PropertyEdit/CPropertyDelegate.cpp index c46507cb..2091b35e 100644 --- a/src/Editor/PropertyEdit/CPropertyDelegate.cpp +++ b/src/Editor/PropertyEdit/CPropertyDelegate.cpp @@ -267,12 +267,12 @@ void CPropertyDelegate::setEditorData(QWidget *pEditor, const QModelIndex &rkInd CColor SrcColor = pColor->Get(); QColor Color; - Color.setRed(SrcColor.r * 255); - Color.setGreen(SrcColor.g * 255); - Color.setBlue(SrcColor.b * 255); - Color.setAlpha(SrcColor.a * 255); + Color.setRed(SrcColor.R * 255); + Color.setGreen(SrcColor.G * 255); + Color.setBlue(SrcColor.B * 255); + Color.setAlpha(SrcColor.A * 255); - pColorPicker->setColor(Color); + pColorPicker->SetColor(Color); break; } @@ -352,9 +352,9 @@ void CPropertyDelegate::setEditorData(QWidget *pEditor, const QModelIndex &rkInd TVector3Property *pVector = static_cast(pProp); CVector3f Vector = pVector->Get(); - if (rkIndex.row() == 0) Value = Vector.x; - if (rkIndex.row() == 1) Value = Vector.y; - if (rkIndex.row() == 2) Value = Vector.z; + if (rkIndex.row() == 0) Value = Vector.X; + if (rkIndex.row() == 1) Value = Vector.Y; + if (rkIndex.row() == 2) Value = Vector.Z; } else if (pProp->Type() == eColorProperty) @@ -362,10 +362,10 @@ void CPropertyDelegate::setEditorData(QWidget *pEditor, const QModelIndex &rkInd TColorProperty *pColor = static_cast(pProp); CColor Color = pColor->Get(); - if (rkIndex.row() == 0) Value = Color.r; - if (rkIndex.row() == 1) Value = Color.g; - if (rkIndex.row() == 2) Value = Color.b; - if (rkIndex.row() == 3) Value = Color.a; + if (rkIndex.row() == 0) Value = Color.R; + if (rkIndex.row() == 1) Value = Color.G; + if (rkIndex.row() == 2) Value = Color.B; + if (rkIndex.row() == 3) Value = Color.A; } pSpinBox->setValue((double) Value); @@ -430,12 +430,12 @@ void CPropertyDelegate::setModelData(QWidget *pEditor, QAbstractItemModel* /*pMo WColorPicker *pColorPicker = static_cast(pEditor); TColorProperty *pColor = static_cast(pProp); - QColor SrcColor = pColorPicker->getColor(); + QColor SrcColor = pColorPicker->Color(); CColor Color; - Color.r = SrcColor.red() / 255.f; - Color.g = SrcColor.green() / 255.f; - Color.b = SrcColor.blue() / 255.f; - Color.a = SrcColor.alpha() / 255.f; + Color.R = SrcColor.red() / 255.f; + Color.G = SrcColor.green() / 255.f; + Color.B = SrcColor.blue() / 255.f; + Color.A = SrcColor.alpha() / 255.f; pColor->Set(Color); break; } @@ -514,9 +514,9 @@ void CPropertyDelegate::setModelData(QWidget *pEditor, QAbstractItemModel* /*pMo TVector3Property *pVector = static_cast(pProp); CVector3f Value = pVector->Get(); - if (rkIndex.row() == 0) Value.x = (float) pSpinBox->value(); - if (rkIndex.row() == 1) Value.y = (float) pSpinBox->value(); - if (rkIndex.row() == 2) Value.z = (float) pSpinBox->value(); + if (rkIndex.row() == 0) Value.X = (float) pSpinBox->value(); + if (rkIndex.row() == 1) Value.Y = (float) pSpinBox->value(); + if (rkIndex.row() == 2) Value.Z = (float) pSpinBox->value(); pVector->Set(Value); } @@ -526,10 +526,10 @@ void CPropertyDelegate::setModelData(QWidget *pEditor, QAbstractItemModel* /*pMo TColorProperty *pColor = static_cast(pProp); CColor Value = pColor->Get(); - if (rkIndex.row() == 0) Value.r = (float) pSpinBox->value(); - if (rkIndex.row() == 1) Value.g = (float) pSpinBox->value(); - if (rkIndex.row() == 2) Value.b = (float) pSpinBox->value(); - if (rkIndex.row() == 3) Value.a = (float) pSpinBox->value(); + if (rkIndex.row() == 0) Value.R = (float) pSpinBox->value(); + if (rkIndex.row() == 1) Value.G = (float) pSpinBox->value(); + if (rkIndex.row() == 2) Value.B = (float) pSpinBox->value(); + if (rkIndex.row() == 3) Value.A = (float) pSpinBox->value(); pColor->Set(Value); } @@ -612,8 +612,8 @@ QWidget* CPropertyDelegate::CreateCharacterEditor(QWidget *pParent, const QModel if (pAnimSet) { - for (u32 iChr = 0; iChr < pAnimSet->getNodeCount(); iChr++) - pComboBox->addItem(TO_QSTRING(pAnimSet->getNodeName(iChr))); + for (u32 iChr = 0; iChr < pAnimSet->NumNodes(); iChr++) + pComboBox->addItem(TO_QSTRING(pAnimSet->NodeName(iChr))); } CONNECT_RELAY(pComboBox, rkIndex, currentIndexChanged(int)); diff --git a/src/Editor/PropertyEdit/CPropertyModel.cpp b/src/Editor/PropertyEdit/CPropertyModel.cpp index 99edac37..87938772 100644 --- a/src/Editor/PropertyEdit/CPropertyModel.cpp +++ b/src/Editor/PropertyEdit/CPropertyModel.cpp @@ -199,7 +199,7 @@ QVariant CPropertyModel::data(const QModelIndex& rkIndex, int Role) const if (Role == Qt::DisplayRole) return ""; else - return TO_QSTRING(TString::HexString(pBitfield->FlagMask(rkIndex.row()), true, true, 8)); + return TO_QSTRING(TString::HexString(pBitfield->FlagMask(rkIndex.row()))); } } @@ -377,9 +377,9 @@ QVariant CPropertyModel::data(const QModelIndex& rkIndex, int Role) const CVector3f Value = pVec->Get(); CVector3f Default = pTemp->GetDefaultValue(); - if (rkIndex.row() == 0) Bold = (Value.x != Default.x); - if (rkIndex.row() == 1) Bold = (Value.y != Default.y); - if (rkIndex.row() == 2) Bold = (Value.z != Default.z); + if (rkIndex.row() == 0) Bold = (Value.X != Default.X); + if (rkIndex.row() == 1) Bold = (Value.Y != Default.Y); + if (rkIndex.row() == 2) Bold = (Value.Z != Default.Z); } else if (pProp->Type() == eColorProperty) @@ -390,10 +390,10 @@ QVariant CPropertyModel::data(const QModelIndex& rkIndex, int Role) const CColor Value = pColor->Get(); CColor Default = pTemp->GetDefaultValue(); - if (rkIndex.row() == 0) Bold = (Value.r != Default.r); - if (rkIndex.row() == 1) Bold = (Value.g != Default.g); - if (rkIndex.row() == 2) Bold = (Value.b != Default.b); - if (rkIndex.row() == 3) Bold = (Value.a != Default.a); + if (rkIndex.row() == 0) Bold = (Value.R != Default.R); + if (rkIndex.row() == 1) Bold = (Value.G != Default.G); + if (rkIndex.row() == 2) Bold = (Value.B != Default.B); + if (rkIndex.row() == 3) Bold = (Value.A != Default.A); } } diff --git a/src/Editor/TestDialog.cpp b/src/Editor/TestDialog.cpp index ed2860ef..50c65ac5 100644 --- a/src/Editor/TestDialog.cpp +++ b/src/Editor/TestDialog.cpp @@ -1,29 +1,11 @@ #include "TestDialog.h" #include "ui_TestDialog.h" -#include "Editor/PropertyEdit/CPropertyDelegate.h" -#include "Editor/Widgets/WResourceSelector.h" -#include "Editor/Widgets/WTextureGLWidget.h" -#include -#include -#include -#include -#include -#include - -TestDialog::TestDialog(QWidget *parent) : - QDialog(parent), - ui(new Ui::TestDialog) +TestDialog::TestDialog(QWidget *pParent) + : QDialog(pParent) + , ui(new Ui::TestDialog) { ui->setupUi(this); - - /*CTemplateLoader::LoadGameTemplates(eCorruption); - CMasterTemplate *pMaster = CMasterTemplate::GetMasterForGame(eCorruption); - CScriptTemplate *pTemp = pMaster->TemplateByID("PCKP"); - - CPropertyStruct *pBase = static_cast(pTemp->BaseStruct()->InstantiateProperty(nullptr)); - ui->treeView->setItemDelegate(new CPropertyDelegate(ui->treeView)); - ui->treeView->SetObject(pBase);*/ } TestDialog::~TestDialog() diff --git a/src/Editor/TestDialog.h b/src/Editor/TestDialog.h index 89b06f23..6aadf993 100644 --- a/src/Editor/TestDialog.h +++ b/src/Editor/TestDialog.h @@ -14,7 +14,7 @@ class TestDialog : public QDialog CPropertyModel *mpModel; public: - explicit TestDialog(QWidget *parent = 0); + explicit TestDialog(QWidget *pParent = 0); ~TestDialog(); private: diff --git a/src/Editor/UICommon.cpp b/src/Editor/UICommon.cpp index 77adf8a5..b21c24fb 100644 --- a/src/Editor/UICommon.cpp +++ b/src/Editor/UICommon.cpp @@ -48,14 +48,14 @@ QMap FilterMap = { { "WPSC", "Projectile (*.WPSC)" } }; -QString ExtensionFilterString(const QString& extension) +QString ExtensionFilterString(const QString& rkExtension) { - QMap::const_iterator it = FilterMap.find(extension.toUpper()); + QMap::const_iterator it = FilterMap.find(rkExtension.toUpper()); if (it != FilterMap.end()) return it.value(); else - return "Unknown Extension (*." + extension + ")"; + return "Unknown Extension (*." + rkExtension + ")"; } } diff --git a/src/Editor/UICommon.h b/src/Editor/UICommon.h index 6638e741..b4f1a43b 100644 --- a/src/Editor/UICommon.h +++ b/src/Editor/UICommon.h @@ -7,32 +7,32 @@ #define TO_QSTRING(str) UICommon::ToQString(str) #define TO_TSTRING(str) UICommon::ToTString(str) -#define TO_TWIDESTRING(str) UICommon::ToTWideSTring(str) +#define TO_TWIDESTRING(str) UICommon::ToTWideString(str) namespace UICommon { extern QMap FilterMap; -QString ExtensionFilterString(const QString& extension); +QString ExtensionFilterString(const QString& rkExtension); // TString/TWideString <-> QString -inline QString ToQString(const TString& str) +inline QString ToQString(const TString& rkStr) { - return QString::fromStdString(str.ToStdString()); + return QString::fromStdString(rkStr.ToStdString()); } -inline QString ToQString(const TWideString& str) +inline QString ToQString(const TWideString& rkStr) { - return QString::fromStdWString(str.ToStdString()); + return QString::fromStdWString(rkStr.ToStdString()); } -inline TString ToTString(const QString& str) +inline TString ToTString(const QString& rkStr) { - return TString(str.toStdString()); + return TString(rkStr.toStdString()); } -inline TWideString ToTWideString(const QString& str) +inline TWideString ToTWideString(const QString& rkStr) { - return TWideString(str.toStdWString()); + return TWideString(rkStr.toStdWString()); } } diff --git a/src/Editor/Undo/CChangeLayerCommand.cpp b/src/Editor/Undo/CChangeLayerCommand.cpp index 2ed1121d..a21f9088 100644 --- a/src/Editor/Undo/CChangeLayerCommand.cpp +++ b/src/Editor/Undo/CChangeLayerCommand.cpp @@ -7,7 +7,7 @@ CChangeLayerCommand::CChangeLayerCommand(CWorldEditor *pEditor, const QListObject()->Layer(); + CScriptLayer *pLayer = pNode->Instance()->Layer(); if (pLayer != pNewLayer && !mNodes.contains(pNode)) { @@ -26,7 +26,7 @@ void CChangeLayerCommand::undo() foreach (CSceneNode *pNode, Nodes) ScriptNodes << static_cast(pNode); foreach (CScriptNode *pNode, ScriptNodes) - pNode->Object()->SetLayer(mOldLayers[pNode->ID()]); + pNode->Instance()->SetLayer(mOldLayers[pNode->ID()]); mpEditor->InstancesLayerChanged(ScriptNodes); } @@ -40,7 +40,7 @@ void CChangeLayerCommand::redo() foreach (CSceneNode *pNode, Nodes) ScriptNodes << static_cast(pNode); foreach (CScriptNode *pNode, ScriptNodes) - pNode->Object()->SetLayer(mpNewLayer); + pNode->Instance()->SetLayer(mpNewLayer); mpEditor->InstancesLayerChanged(ScriptNodes); } diff --git a/src/Editor/Undo/CCloneSelectionCommand.cpp b/src/Editor/Undo/CCloneSelectionCommand.cpp index ea064868..c3343106 100644 --- a/src/Editor/Undo/CCloneSelectionCommand.cpp +++ b/src/Editor/Undo/CCloneSelectionCommand.cpp @@ -15,14 +15,14 @@ CCloneSelectionCommand::CCloneSelectionCommand(INodeEditor *pEditor) // Fetch linked objects CScriptNode *pScript = static_cast(*It); - CScriptObject *pInst = pScript->Object(); + CScriptObject *pInst = pScript->Instance(); for (u32 iLink = 0; iLink < pInst->NumLinks(eOutgoing); iLink++) { - CScriptNode *pNode = mpEditor->Scene()->NodeForObject(pInst->Link(eOutgoing, iLink)->Receiver()); + CScriptNode *pNode = mpEditor->Scene()->NodeForInstance(pInst->Link(eOutgoing, iLink)->Receiver()); if (!pNode->IsSelected()) - mLinkedInstances << pNode->Object(); + mLinkedInstances << pNode->Instance(); } } } @@ -35,7 +35,7 @@ void CCloneSelectionCommand::undo() foreach (CSceneNode *pNode, ClonedNodes) { - CScriptObject *pInst = static_cast(pNode)->Object(); + CScriptObject *pInst = static_cast(pNode)->Instance(); mpEditor->NotifyNodeAboutToBeDeleted(pNode); mpEditor->Scene()->DeleteNode(pNode); @@ -60,7 +60,7 @@ void CCloneSelectionCommand::redo() { mpEditor->NotifyNodeAboutToBeSpawned(); CScriptNode *pScript = static_cast(pNode); - CScriptObject *pInstance = pScript->Object(); + CScriptObject *pInstance = pScript->Instance(); CScriptObject *pCloneInst = mpEditor->ActiveArea()->SpawnInstance(pInstance->Template(), pInstance->Layer()); pCloneInst->Properties()->Copy(pInstance->Properties()); @@ -82,8 +82,8 @@ void CCloneSelectionCommand::redo() // Clone outgoing links from source object; incoming ones are discarded for (int iNode = 0; iNode < ClonedNodes.size(); iNode++) { - CScriptObject *pSrc = static_cast(ToClone[iNode])->Object(); - CScriptObject *pClone = static_cast(ClonedNodes[iNode])->Object(); + CScriptObject *pSrc = static_cast(ToClone[iNode])->Instance(); + CScriptObject *pClone = static_cast(ClonedNodes[iNode])->Instance(); for (u32 iLink = 0; iLink < pSrc->NumLinks(eOutgoing); iLink++) { diff --git a/src/Editor/Undo/CCreateInstanceCommand.cpp b/src/Editor/Undo/CCreateInstanceCommand.cpp index 2a1af2ee..5bdd4224 100644 --- a/src/Editor/Undo/CCreateInstanceCommand.cpp +++ b/src/Editor/Undo/CCreateInstanceCommand.cpp @@ -30,7 +30,7 @@ void CCreateInstanceCommand::redo() { mpEditor->NotifyNodeAboutToBeSpawned(); - CScriptLayer *pLayer = (mLayerIndex == -1 ? mpArea->GetGeneratorLayer() : mpArea->GetScriptLayer(mLayerIndex)); + CScriptLayer *pLayer = (mLayerIndex == -1 ? mpArea->GeneratedObjectsLayer() : mpArea->ScriptLayer(mLayerIndex)); CScriptObject *pNewInst = mpArea->SpawnInstance(mpTemplate, pLayer, mSpawnPosition); CScriptNode *pNewNode = mpScene->CreateScriptNode(pNewInst); pNewNode->SetPosition(mSpawnPosition); diff --git a/src/Editor/Undo/CDeleteSelectionCommand.cpp b/src/Editor/Undo/CDeleteSelectionCommand.cpp index 23350f83..5551943a 100644 --- a/src/Editor/Undo/CDeleteSelectionCommand.cpp +++ b/src/Editor/Undo/CDeleteSelectionCommand.cpp @@ -18,7 +18,7 @@ CDeleteSelectionCommand::CDeleteSelectionCommand(CWorldEditor *pEditor, const QS if (It->NodeType() == eScriptNode) { CScriptNode *pScript = static_cast(*It); - CScriptObject *pInst = pScript->Object(); + CScriptObject *pInst = pScript->Instance(); mDeletedNodes.push_back(SDeletedNode()); SDeletedNode& rNode = mDeletedNodes.back(); @@ -74,7 +74,7 @@ CDeleteSelectionCommand::CDeleteSelectionCommand(CWorldEditor *pEditor, const QS // Remove selected objects from the linked instances list. foreach (CScriptObject *pInst, LinkedInstances) { - if (mpEditor->Scene()->NodeForObject(pInst)->IsSelected()) + if (mpEditor->Scene()->NodeForInstance(pInst)->IsSelected()) LinkedInstances.removeOne(pInst); } @@ -153,7 +153,7 @@ void CDeleteSelectionCommand::redo() { SDeletedNode& rNode = mDeletedNodes[iNode]; CSceneNode *pNode = *rNode.NodePtr; - CScriptObject *pInst = static_cast(pNode)->Object(); + CScriptObject *pInst = static_cast(pNode)->Instance(); mpEditor->NotifyNodeAboutToBeDeleted(pNode); mpEditor->Scene()->DeleteNode(pNode); diff --git a/src/Editor/Undo/CPasteNodesCommand.cpp b/src/Editor/Undo/CPasteNodesCommand.cpp index e735285a..3442d0ff 100644 --- a/src/Editor/Undo/CPasteNodesCommand.cpp +++ b/src/Editor/Undo/CPasteNodesCommand.cpp @@ -27,7 +27,7 @@ void CPasteNodesCommand::undo() foreach (CSceneNode *pNode, PastedNodes) { - CScriptObject *pInst = (pNode->NodeType() == eScriptNode ? static_cast(pNode)->Object() : nullptr); + CScriptObject *pInst = (pNode->NodeType() == eScriptNode ? static_cast(pNode)->Instance() : nullptr); mpEditor->NotifyNodeAboutToBeDeleted(pNode); mpEditor->Scene()->DeleteNode(pNode); if (pInst) mpEditor->ActiveArea()->DeleteInstance(pInst); @@ -91,7 +91,7 @@ void CPasteNodesCommand::redo() { if (pNode && pNode->NodeType() == eScriptNode) { - CScriptObject *pInstance = static_cast(pNode)->Object(); + CScriptObject *pInstance = static_cast(pNode)->Instance(); for (u32 iLink = 0; iLink < pInstance->NumLinks(eOutgoing); iLink++) { @@ -100,7 +100,7 @@ void CPasteNodesCommand::redo() if (Index != -1) { - CScriptObject *pNewTarget = static_cast(PastedNodes[Index])->Object(); + CScriptObject *pNewTarget = static_cast(PastedNodes[Index])->Instance(); pLink->SetReceiver(pNewTarget->InstanceID()); } diff --git a/src/Editor/Widgets/WAnimParamsEditor.cpp b/src/Editor/Widgets/WAnimParamsEditor.cpp index 7f8c88ad..ec540773 100644 --- a/src/Editor/Widgets/WAnimParamsEditor.cpp +++ b/src/Editor/Widgets/WAnimParamsEditor.cpp @@ -5,11 +5,11 @@ #include WAnimParamsEditor::WAnimParamsEditor(QWidget *pParent) - : QWidget(pParent), - mpGroupBox(new QGroupBox("Animation Parameters", this)), - mpGroupLayout(nullptr), - mpSelector(nullptr), - mpCharComboBox(nullptr) + : QWidget(pParent) + , mpGroupBox(new QGroupBox("Animation Parameters", this)) + , mpGroupLayout(nullptr) + , mpSelector(nullptr) + , mpCharComboBox(nullptr) { for (u32 iBox = 0; iBox < 4; iBox++) mpSpinBoxes[iBox] = nullptr; @@ -25,12 +25,12 @@ WAnimParamsEditor::WAnimParamsEditor(QWidget *pParent) setLayout(pLayout); } -WAnimParamsEditor::WAnimParamsEditor(const CAnimationParameters& params, QWidget *pParent) - : QWidget(pParent), - mpGroupBox(new QGroupBox("Animation Parameters", this)), - mpGroupLayout(nullptr), - mpSelector(nullptr), - mpCharComboBox(nullptr) +WAnimParamsEditor::WAnimParamsEditor(const CAnimationParameters& rkParams, QWidget *pParent) + : QWidget(pParent) + , mpGroupBox(new QGroupBox("Animation Parameters", this)) + , mpGroupLayout(nullptr) + , mpSelector(nullptr) + , mpCharComboBox(nullptr) { for (u32 iBox = 0; iBox < 4; iBox++) mpSpinBoxes[iBox] = nullptr; @@ -45,7 +45,7 @@ WAnimParamsEditor::WAnimParamsEditor(const CAnimationParameters& params, QWidget pLayout->setContentsMargins(0,0,0,0); setLayout(pLayout); - mParams = params; + mParams = rkParams; SetupUI(); } @@ -53,30 +53,30 @@ WAnimParamsEditor::~WAnimParamsEditor() { } -void WAnimParamsEditor::SetTitle(const QString& title) +void WAnimParamsEditor::SetTitle(const QString& rkTitle) { - mpGroupBox->setTitle(title); + mpGroupBox->setTitle(rkTitle); } -void WAnimParamsEditor::SetParameters(const CAnimationParameters& params) +void WAnimParamsEditor::SetParameters(const CAnimationParameters& rkParams) { - mParams = params; + mParams = rkParams; SetupUI(); } // ************ PRIVATE SLOTS ************ -void WAnimParamsEditor::OnResourceChanged(QString path) +void WAnimParamsEditor::OnResourceChanged(QString Path) { - CResourceInfo ResInfo(path.toStdString()); + CResourceInfo ResInfo(Path.toStdString()); if (ResInfo.Type() != "ANCS" && ResInfo.Type() != "CHAR") ResInfo = CResourceInfo(); mParams.SetResource(ResInfo); emit ParametersChanged(mParams); } -void WAnimParamsEditor::OnCharacterChanged(int index) +void WAnimParamsEditor::OnCharacterChanged(int Index) { - mParams.SetNodeIndex(index); + mParams.SetNodeIndex(Index); emit ParametersChanged(mParams); } @@ -140,8 +140,8 @@ void WAnimParamsEditor::SetupUI() CAnimSet *pSet = static_cast(mParams.AnimSet()); if (pSet) - for (u32 iChar = 0; iChar < pSet->getNodeCount(); iChar++) - mpCharComboBox->addItem(TO_QSTRING(pSet->getNodeName(iChar))); + for (u32 iChar = 0; iChar < pSet->NumNodes(); iChar++) + mpCharComboBox->addItem(TO_QSTRING(pSet->NodeName(iChar))); mpCharComboBox->setCurrentIndex(mParams.CharacterIndex()); mpLabels[1] = new QLabel("Character", this); diff --git a/src/Editor/Widgets/WAnimParamsEditor.h b/src/Editor/Widgets/WAnimParamsEditor.h index d4e08205..ca86e073 100644 --- a/src/Editor/Widgets/WAnimParamsEditor.h +++ b/src/Editor/Widgets/WAnimParamsEditor.h @@ -30,17 +30,17 @@ class WAnimParamsEditor : public QWidget public: WAnimParamsEditor(QWidget *pParent = 0); - WAnimParamsEditor(const CAnimationParameters& params, QWidget *pParent = 0); + WAnimParamsEditor(const CAnimationParameters& rkParams, QWidget *pParent = 0); ~WAnimParamsEditor(); - void SetTitle(const QString& title); - void SetParameters(const CAnimationParameters& params); + void SetTitle(const QString& rkTitle); + void SetParameters(const CAnimationParameters& rkParams); signals: - void ParametersChanged(const CAnimationParameters& params); + void ParametersChanged(const CAnimationParameters& rkParams); private slots: - void OnResourceChanged(QString path); - void OnCharacterChanged(int index); + void OnResourceChanged(QString Path); + void OnCharacterChanged(int Index); void OnUnknownChanged(); private: diff --git a/src/Editor/Widgets/WCollapsibleGroupBox.cpp b/src/Editor/Widgets/WCollapsibleGroupBox.cpp deleted file mode 100644 index 63936307..00000000 --- a/src/Editor/Widgets/WCollapsibleGroupBox.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include "WCollapsibleGroupBox.h" - -WCollapsibleGroupBox::WCollapsibleGroupBox() -{ - -} - -WCollapsibleGroupBox::~WCollapsibleGroupBox() -{ - -} - diff --git a/src/Editor/Widgets/WCollapsibleGroupBox.h b/src/Editor/Widgets/WCollapsibleGroupBox.h deleted file mode 100644 index 3e1aa362..00000000 --- a/src/Editor/Widgets/WCollapsibleGroupBox.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef WCOLLAPSIBLEGROUPBOX_H -#define WCOLLAPSIBLEGROUPBOX_H - - -class WCollapsibleGroupBox -{ -public: - WCollapsibleGroupBox(); - ~WCollapsibleGroupBox(); -}; - -#endif // WCOLLAPSIBLEGROUPBOX_H diff --git a/src/Editor/Widgets/WColorPicker.cpp b/src/Editor/Widgets/WColorPicker.cpp index ebc0672f..6498b2ac 100644 --- a/src/Editor/Widgets/WColorPicker.cpp +++ b/src/Editor/Widgets/WColorPicker.cpp @@ -1,16 +1,12 @@ #include "WColorPicker.h" -#include #include #include #include #include -WColorPicker::WColorPicker(QWidget *parent) : QWidget(parent) -{ - mColor = Qt::transparent; -} - -WColorPicker::~WColorPicker() +WColorPicker::WColorPicker(QWidget *parent) + : QWidget(parent) + , mColor(Qt::transparent) { } @@ -40,9 +36,9 @@ void WColorPicker::paintEvent(QPaintEvent *) } } -void WColorPicker::keyPressEvent(QKeyEvent *Event) +void WColorPicker::keyPressEvent(QKeyEvent *pEvent) { - if (Event->key() == Qt::Key_Return) + if (pEvent->key() == Qt::Key_Return) { QColorDialog ColorPick; ColorPick.setOptions(QColorDialog::ShowAlphaChannel); @@ -52,7 +48,7 @@ void WColorPicker::keyPressEvent(QKeyEvent *Event) if (result) { mColor = ColorPick.currentColor(); - emit colorChanged(mColor); + emit ColorChanged(mColor); } } } @@ -62,34 +58,34 @@ void WColorPicker::mousePressEvent(QMouseEvent *) setFocus(); } -void WColorPicker::mouseReleaseEvent(QMouseEvent *Event) +void WColorPicker::mouseReleaseEvent(QMouseEvent *pEvent) { - if ((Event->x() < width()) && (Event->y() < height())) + if ((pEvent->x() < width()) && (pEvent->y() < height())) { QColorDialog ColorPick; ColorPick.setOptions(QColorDialog::ShowAlphaChannel); ColorPick.setCurrentColor(mColor); - int result = ColorPick.exec(); + int Result = ColorPick.exec(); - if (result) + if (Result) { mColor = ColorPick.currentColor(); - emit colorChanged(mColor); + emit ColorChanged(mColor); } } } -QColor WColorPicker::getColor() +QColor WColorPicker::Color() { return mColor; } -void WColorPicker::setColor(QColor Color) +void WColorPicker::SetColor(QColor Color) { if (mColor != Color) { mColor = Color; - emit colorChanged(mColor); + emit ColorChanged(mColor); update(); } } diff --git a/src/Editor/Widgets/WColorPicker.h b/src/Editor/Widgets/WColorPicker.h index 231b0bd6..f9a4286b 100644 --- a/src/Editor/Widgets/WColorPicker.h +++ b/src/Editor/Widgets/WColorPicker.h @@ -10,17 +10,16 @@ class WColorPicker : public QWidget QColor mColor; public: - explicit WColorPicker(QWidget *parent = 0); - ~WColorPicker(); + explicit WColorPicker(QWidget *pParent = 0); void paintEvent(QPaintEvent *); - void keyPressEvent(QKeyEvent *Event); + void keyPressEvent(QKeyEvent *pEvent); void mousePressEvent(QMouseEvent *); - void mouseReleaseEvent(QMouseEvent *Event); - QColor getColor(); - void setColor(QColor Color); + void mouseReleaseEvent(QMouseEvent *pEvent); + QColor Color(); + void SetColor(QColor Color); signals: - void colorChanged(QColor NewColor); + void ColorChanged(QColor NewColor); public slots: }; diff --git a/src/Editor/Widgets/WDraggableSpinBox.cpp b/src/Editor/Widgets/WDraggableSpinBox.cpp index e4d45dc3..47def267 100644 --- a/src/Editor/Widgets/WDraggableSpinBox.cpp +++ b/src/Editor/Widgets/WDraggableSpinBox.cpp @@ -4,12 +4,13 @@ #include #include -WDraggableSpinBox::WDraggableSpinBox(QWidget *parent) : QDoubleSpinBox(parent) +WDraggableSpinBox::WDraggableSpinBox(QWidget *parent) + : QDoubleSpinBox(parent) + , mBeingDragged(false) + , mDefaultValue(0) + , mMinDecimals(1) + , mTrimTrailingZeroes(true) { - mBeingDragged = false; - mDefaultValue = 0; - mMinDecimals = 1; - mTrimTrailingZeroes = true; setMinimum(-1000000.0); setMaximum(1000000.0); setDecimals(6); @@ -30,23 +31,23 @@ void WDraggableSpinBox::mousePressEvent(QMouseEvent *pEvent) } } -void WDraggableSpinBox::mouseReleaseEvent(QMouseEvent *Event) +void WDraggableSpinBox::mouseReleaseEvent(QMouseEvent *pEvent) { mBeingDragged = false; setCursor(Qt::ArrowCursor); - if (Event->button() == Qt::LeftButton) + if (pEvent->button() == Qt::LeftButton) { if (!mBeenDragged) { - if (Event->y() <= height() / 2) + if (pEvent->y() <= height() / 2) stepUp(); else stepDown(); } } - else if (Event->button() == Qt::RightButton) + else if (pEvent->button() == Qt::RightButton) { setValue(mDefaultValue); } @@ -58,19 +59,19 @@ void WDraggableSpinBox::mouseMoveEvent(QMouseEvent*) { if (mBeingDragged) { - QPoint cursorPos = QCursor::pos(); + QPoint CursorPos = QCursor::pos(); // Update value - double DragAmount = (singleStep() / 10.0) * (mLastY - cursorPos.y()); + double DragAmount = (singleStep() / 10.0) * (mLastY - CursorPos.y()); setValue(value() + DragAmount); // Wrap cursor - int screenHeight = QApplication::desktop()->screenGeometry().height(); + int ScreenHeight = QApplication::desktop()->screenGeometry().height(); - if (cursorPos.y() == screenHeight - 1) - QCursor::setPos(cursorPos.x(), 1); - if (cursorPos.y() == 0) - QCursor::setPos(cursorPos.x(), screenHeight - 2); + if (CursorPos.y() == ScreenHeight - 1) + QCursor::setPos(CursorPos.x(), 1); + if (CursorPos.y() == 0) + QCursor::setPos(CursorPos.x(), ScreenHeight - 2); // Set cursor shape if (DragAmount != 0) @@ -98,39 +99,41 @@ bool WDraggableSpinBox::eventFilter(QObject *, QEvent *pEvent) return false; } -QString WDraggableSpinBox::textFromValue(double val) const +QString WDraggableSpinBox::textFromValue(double Val) const { - QString str = QString::number(val, 'f', decimals()); - int decIndex = str.indexOf('.'); - int numDecs; + QString Str = QString::number(Val, 'f', decimals()); + int DecIndex = Str.indexOf('.'); + int NumDecs; - if (decIndex == -1) - numDecs = 0; + if (DecIndex == -1) + NumDecs = 0; else - numDecs = str.size() - decIndex - 1; + NumDecs = Str.size() - DecIndex - 1; - if (numDecs < mMinDecimals) + if (NumDecs < mMinDecimals) { - int size = str.size() + mMinDecimals + 1; - str.reserve(size); + int Size = Str.size() + mMinDecimals + 1; + Str.reserve(Size); - str += '.'; + Str += '.'; for (int iDec = 0; iDec < mMinDecimals; iDec++) - str += '0'; + Str += '0'; } - else if ((numDecs > mMinDecimals) && mTrimTrailingZeroes) + else if ((NumDecs > mMinDecimals) && mTrimTrailingZeroes) { - while (numDecs > mMinDecimals) + while (NumDecs > mMinDecimals) { - if (str.endsWith('0')) { - str.chop(1); - numDecs--; + if (Str.endsWith('0')) + { + Str.chop(1); + NumDecs--; } - else if (str.endsWith('.')) { - str.chop(1); + else if (Str.endsWith('.')) + { + Str.chop(1); break; } @@ -138,7 +141,7 @@ QString WDraggableSpinBox::textFromValue(double val) const } } - return str; + return Str; } bool WDraggableSpinBox::IsBeingDragged() @@ -146,17 +149,17 @@ bool WDraggableSpinBox::IsBeingDragged() return mBeingDragged; } -void WDraggableSpinBox::SetDefaultValue(double value) +void WDraggableSpinBox::SetDefaultValue(double Value) { - mDefaultValue = value; + mDefaultValue = Value; } -void WDraggableSpinBox::SetMinDecimals(int dec) +void WDraggableSpinBox::SetMinDecimals(int Dec) { - mMinDecimals = dec; + mMinDecimals = Dec; } -void WDraggableSpinBox::TrimTrailingZeroes(bool trim) +void WDraggableSpinBox::TrimTrailingZeroes(bool Trim) { - mTrimTrailingZeroes = trim; + mTrimTrailingZeroes = Trim; } diff --git a/src/Editor/Widgets/WDraggableSpinBox.h b/src/Editor/Widgets/WDraggableSpinBox.h index 376d3aff..2aeb1622 100644 --- a/src/Editor/Widgets/WDraggableSpinBox.h +++ b/src/Editor/Widgets/WDraggableSpinBox.h @@ -14,18 +14,18 @@ class WDraggableSpinBox : public QDoubleSpinBox bool mTrimTrailingZeroes; public: - explicit WDraggableSpinBox(QWidget *parent = 0); + explicit WDraggableSpinBox(QWidget *pParent = 0); ~WDraggableSpinBox(); void mousePressEvent(QMouseEvent *pEvent); void mouseReleaseEvent(QMouseEvent *pEvent); void mouseMoveEvent(QMouseEvent *pEvent); void wheelEvent(QWheelEvent *pEvent); bool eventFilter(QObject *pObj, QEvent *pEvent); - QString textFromValue(double val) const; + QString textFromValue(double Val) const; bool IsBeingDragged(); - void SetDefaultValue(double value); - void SetMinDecimals(int dec); - void TrimTrailingZeroes(bool trim); + void SetDefaultValue(double Value); + void SetMinDecimals(int Dec); + void TrimTrailingZeroes(bool Trim); }; #endif // WDRAGGABLESPINBOX_H diff --git a/src/Editor/Widgets/WResourceSelector.cpp b/src/Editor/Widgets/WResourceSelector.cpp index 814bfe19..ae9f8980 100644 --- a/src/Editor/Widgets/WResourceSelector.cpp +++ b/src/Editor/Widgets/WResourceSelector.cpp @@ -10,22 +10,20 @@ #include #include -WResourceSelector::WResourceSelector(QWidget *parent) : QWidget(parent) +WResourceSelector::WResourceSelector(QWidget *parent) + : QWidget(parent) + // Selector Members + , mShowEditButton(false) + , mShowExportButton(false) + // Preview Panel Members + , mpPreviewPanel(nullptr) + , mEnablePreviewPanel(true) + , mPreviewPanelValid(false) + , mShowingPreviewPanel(false) + , mAdjustPreviewToParent(false) + // Resource Members + , mResourceValid(false) { - // Initialize Selector Members - mShowEditButton = false; - mShowExportButton = false; - - // Initialize Preview Panel Members - mpPreviewPanel = nullptr; - mEnablePreviewPanel = true; - mPreviewPanelValid = false; - mShowingPreviewPanel = false; - mAdjustPreviewToParent = false; - - // Initialize Resource Members - mResourceValid = false; - // Create Widgets mUI.LineEdit = new QLineEdit(this); mUI.BrowseButton = new QPushButton(this); @@ -93,10 +91,10 @@ bool WResourceSelector::eventFilter(QObject* /*pObj*/, QEvent *pEvent) return false; } -bool WResourceSelector::IsSupportedExtension(const QString& extension) +bool WResourceSelector::IsSupportedExtension(const QString& rkExtension) { foreach(const QString& str, mSupportedExtensions) - if (str == extension) return true; + if (str == rkExtension) return true; return false; } @@ -201,23 +199,23 @@ void WResourceSelector::SetResource(const CResourceInfo& rkRes) } } -void WResourceSelector::SetAllowedExtensions(const QString& extension) +void WResourceSelector::SetAllowedExtensions(const QString& rkExtension) { - TStringList list = TString(extension.toStdString()).Split(","); + TStringList list = TString(rkExtension.toStdString()).Split(","); SetAllowedExtensions(list); } -void WResourceSelector::SetAllowedExtensions(const TStringList& extensions) +void WResourceSelector::SetAllowedExtensions(const TStringList& rkExtensions) { mSupportedExtensions.clear(); - for (auto it = extensions.begin(); it != extensions.end(); it++) + for (auto it = rkExtensions.begin(); it != rkExtensions.end(); it++) mSupportedExtensions << TO_QSTRING(*it); } -void WResourceSelector::SetText(const QString& ResPath) +void WResourceSelector::SetText(const QString& rkResPath) { - mUI.LineEdit->setText(ResPath); - SetResource(ResPath); + mUI.LineEdit->setText(rkResPath); + SetResource(rkResPath); } void WResourceSelector::SetEditButtonEnabled(bool Enabled) @@ -240,9 +238,9 @@ void WResourceSelector::SetPreviewPanelEnabled(bool Enabled) if (!mPreviewPanelValid) CreatePreviewPanel(); } -void WResourceSelector::AdjustPreviewToParent(bool adjust) +void WResourceSelector::AdjustPreviewToParent(bool Adjust) { - mAdjustPreviewToParent = adjust; + mAdjustPreviewToParent = Adjust; } // ************ SLOTS ************ diff --git a/src/Editor/Widgets/WResourceSelector.h b/src/Editor/Widgets/WResourceSelector.h index 62afb844..322dda47 100644 --- a/src/Editor/Widgets/WResourceSelector.h +++ b/src/Editor/Widgets/WResourceSelector.h @@ -43,16 +43,16 @@ class WResourceSelector : public QWidget // Functions signals: - void ResourceChanged(const QString& NewResPath); + void ResourceChanged(const QString& rkNewResPath); void EditResource(const CResourceInfo& rkRes); void ExportResource(const CResourceInfo& rkRes); public: - explicit WResourceSelector(QWidget *parent = 0); + explicit WResourceSelector(QWidget *pParent = 0); ~WResourceSelector(); bool event(QEvent *); bool eventFilter(QObject *, QEvent *); - bool IsSupportedExtension(const QString& extension); + bool IsSupportedExtension(const QString& rkExtension); bool HasSupportedExtension(const CResourceInfo& rkRes); void UpdateFrameColor(); @@ -68,14 +68,14 @@ public: void SetResource(CResource *pRes); void SetResource(const QString& rkRes); void SetResource(const CResourceInfo& rkRes); - void SetAllowedExtensions(const QString& extension); - void SetAllowedExtensions(const QStringList& extensions); - void SetAllowedExtensions(const TStringList& extensions); - void SetText(const QString& ResPath); + void SetAllowedExtensions(const QString& rkExtension); + void SetAllowedExtensions(const QStringList& rkExtensions); + void SetAllowedExtensions(const TStringList& rkExtensions); + void SetText(const QString& rkResPath); void SetEditButtonEnabled(bool Enabled); void SetExportButtonEnabled(bool Enabled); void SetPreviewPanelEnabled(bool Enabled); - void AdjustPreviewToParent(bool adjust); + void AdjustPreviewToParent(bool Adjust); // Slots public slots: diff --git a/src/Editor/Widgets/WRollout.cpp b/src/Editor/Widgets/WRollout.cpp deleted file mode 100644 index 80366d4b..00000000 --- a/src/Editor/Widgets/WRollout.cpp +++ /dev/null @@ -1,64 +0,0 @@ -#include "WRollout.h" -#include -#include -#include -#include -#include -#include - -WRollout::WRollout(QWidget *parent) : QWidget(parent) -{ - this->setContentsMargins(10, 20, 10, 10); -} - -WRollout::~WRollout() -{ -} - -void WRollout::setCollapsed(bool collapsed) -{ - mCollapsed = collapsed; -} - -bool WRollout::isCollapsed() -{ - return mCollapsed; -} - -void WRollout::setName(const QString& name) -{ - mpTopButton->setText(name); -} - -QString WRollout::getName() -{ - return mpTopButton->text(); -} - -void WRollout::paintEvent(QPaintEvent *) -{ - QPainter Painter(this); - - // Draw box - QPen Pen; - Pen.setColor(Qt::white); - Painter.setPen(Pen); - QBrush Brush; - Brush.setColor(Qt::white); - Painter.setBrush(Brush); - - int AreaBoxTop = (mCollapsed) ? 7 : 10; - QRect Area(QPoint(0,AreaBoxTop), size() - QSize(Pen.width(), Pen.width() + AreaBoxTop)); - Painter.drawRoundedRect(Area, 5.f, 5.f); - - // Draw button - QRect TopButton(QPoint(10,0), QSize(width() - 20, 21)); - QPalette Palette = qApp->palette(); - Painter.setBrush(Palette.color(QPalette::Text)); - - Painter.drawRect(TopButton); -} - -void WRollout::resizeEvent(QResizeEvent *) -{ -} diff --git a/src/Editor/Widgets/WRollout.h b/src/Editor/Widgets/WRollout.h deleted file mode 100644 index 14baed66..00000000 --- a/src/Editor/Widgets/WRollout.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef WROLLOUT_H -#define WROLLOUT_H - -#include -#include - -class WRollout : public QWidget -{ - Q_PROPERTY(bool mCollapsed READ isCollapsed WRITE setCollapsed) - QPushButton *mpTopButton; - QWidget *mpContainerWidget; - bool mCollapsed; - -public: - explicit WRollout(QWidget *parent = 0); - ~WRollout(); - void setCollapsed(bool collapsed); - bool isCollapsed(); - void setName(const QString& name); - QString getName(); - - void paintEvent(QPaintEvent *); - void resizeEvent(QResizeEvent *); - -private: - bool mouseInButton(int x, int y); -}; - -#endif // WROLLOUT_H diff --git a/src/Editor/Widgets/WScanPreviewPanel.cpp b/src/Editor/Widgets/WScanPreviewPanel.cpp index d2603da1..00af1314 100644 --- a/src/Editor/Widgets/WScanPreviewPanel.cpp +++ b/src/Editor/Widgets/WScanPreviewPanel.cpp @@ -3,9 +3,9 @@ #include "WStringPreviewPanel.h" #include -WScanPreviewPanel::WScanPreviewPanel(QWidget *parent) : - IPreviewPanel(parent), - ui(new Ui::WScanPreviewPanel) +WScanPreviewPanel::WScanPreviewPanel(QWidget *pParent) + : IPreviewPanel(pParent) + , ui(new Ui::WScanPreviewPanel) { ui->setupUi(this); diff --git a/src/Editor/Widgets/WScanPreviewPanel.h b/src/Editor/Widgets/WScanPreviewPanel.h index f5a406cf..5b0776cb 100644 --- a/src/Editor/Widgets/WScanPreviewPanel.h +++ b/src/Editor/Widgets/WScanPreviewPanel.h @@ -12,7 +12,7 @@ class WScanPreviewPanel : public IPreviewPanel Q_OBJECT public: - explicit WScanPreviewPanel(QWidget *parent = 0); + explicit WScanPreviewPanel(QWidget *pParent = 0); ~WScanPreviewPanel(); QSize sizeHint() const; EResType ResType(); diff --git a/src/Editor/Widgets/WStringPreviewPanel.cpp b/src/Editor/Widgets/WStringPreviewPanel.cpp index 0f4dab0a..4aa2ae9a 100644 --- a/src/Editor/Widgets/WStringPreviewPanel.cpp +++ b/src/Editor/Widgets/WStringPreviewPanel.cpp @@ -5,7 +5,8 @@ #include #include -WStringPreviewPanel::WStringPreviewPanel(QWidget *pParent) : IPreviewPanel(pParent) +WStringPreviewPanel::WStringPreviewPanel(QWidget *pParent) + : IPreviewPanel(pParent) { mpLayout = new QVBoxLayout(this); mpLayout->setAlignment(Qt::AlignTop); @@ -36,11 +37,11 @@ void WStringPreviewPanel::SetResource(CResource *pRes) if (pRes && (pRes->Type() == eStringTable)) { CStringTable *pString = static_cast(pRes); - mLabels.reserve(pString->GetStringCount()); + mLabels.reserve(pString->NumStrings()); - for (u32 iStr = 0; iStr < pString->GetStringCount(); iStr++) + for (u32 iStr = 0; iStr < pString->NumStrings(); iStr++) { - QString text = TO_QSTRING(pString->GetString("ENGL", iStr)); + QString text = TO_QSTRING(pString->String("ENGL", iStr)); QLabel *pLabel = new QLabel(text, this); pLabel->setWordWrap(true); pLabel->setFrameStyle(QFrame::Plain | QFrame::Box); diff --git a/src/Editor/Widgets/WTextureGLWidget.cpp b/src/Editor/Widgets/WTextureGLWidget.cpp index d6f38b64..47344855 100644 --- a/src/Editor/Widgets/WTextureGLWidget.cpp +++ b/src/Editor/Widgets/WTextureGLWidget.cpp @@ -1,5 +1,4 @@ #include "WTextureGLWidget.h" -#include #include #include #include @@ -7,7 +6,8 @@ #include #include -WTextureGLWidget::WTextureGLWidget(QWidget *parent, CTexture *pTex) : QOpenGLWidget(parent) +WTextureGLWidget::WTextureGLWidget(QWidget *pParent, CTexture *pTex) + : QOpenGLWidget(pParent) { SetTexture(pTex); mInitialized = false; @@ -44,7 +44,7 @@ void WTextureGLWidget::paintGL() CDrawUtil::UseTextureShader(); glDepthMask(GL_FALSE); CDrawUtil::LoadCheckerboardTexture(0); - CDrawUtil::DrawSquare(&mCheckerCoords[0].x); + CDrawUtil::DrawSquare(&mCheckerCoords[0].X); // Make it darker CDrawUtil::UseColorShader(CColor::Integral(0.0f, 0.0f, 0.0f, 0.5f)); @@ -64,10 +64,10 @@ void WTextureGLWidget::paintGL() glEnable(GL_DEPTH_TEST); } -void WTextureGLWidget::resizeGL(int w, int h) +void WTextureGLWidget::resizeGL(int Width, int Height) { - mAspectRatio = (float) w / (float) h; - glViewport(0, 0, w, h); + mAspectRatio = (float) Width / (float) Height; + glViewport(0, 0, Width, Height); CalcTexTransform(); CalcCheckerCoords(); diff --git a/src/Editor/Widgets/WTextureGLWidget.h b/src/Editor/Widgets/WTextureGLWidget.h index 8b3e7178..97078ea3 100644 --- a/src/Editor/Widgets/WTextureGLWidget.h +++ b/src/Editor/Widgets/WTextureGLWidget.h @@ -23,11 +23,11 @@ class WTextureGLWidget : public QOpenGLWidget bool mInitialized; public: - explicit WTextureGLWidget(QWidget *parent = 0, CTexture *pTex = 0); + explicit WTextureGLWidget(QWidget *pParent = 0, CTexture *pTex = 0); ~WTextureGLWidget(); void initializeGL(); void paintGL(); - void resizeGL(int w, int h); + void resizeGL(int Width, int Height); void SetTexture(CTexture *pTex); private: diff --git a/src/Editor/Widgets/WTexturePreviewPanel.cpp b/src/Editor/Widgets/WTexturePreviewPanel.cpp index 7447a245..de0bd573 100644 --- a/src/Editor/Widgets/WTexturePreviewPanel.cpp +++ b/src/Editor/Widgets/WTexturePreviewPanel.cpp @@ -3,9 +3,9 @@ #include "WTextureGLWidget.h" #include "Editor/UICommon.h" -WTexturePreviewPanel::WTexturePreviewPanel(QWidget *parent, CTexture *pTexture) : - IPreviewPanel(parent), - ui(new Ui::WTexturePreviewPanel) +WTexturePreviewPanel::WTexturePreviewPanel(QWidget *parent, CTexture *pTexture) + : IPreviewPanel(parent) + , ui(new Ui::WTexturePreviewPanel) { ui->setupUi(this); SetResource(pTexture); diff --git a/src/Editor/Widgets/WTexturePreviewPanel.h b/src/Editor/Widgets/WTexturePreviewPanel.h index 519d5db2..04dccea8 100644 --- a/src/Editor/Widgets/WTexturePreviewPanel.h +++ b/src/Editor/Widgets/WTexturePreviewPanel.h @@ -13,7 +13,7 @@ class WTexturePreviewPanel : public IPreviewPanel Q_OBJECT public: - explicit WTexturePreviewPanel(QWidget *parent = 0, CTexture *pTexture = 0); + explicit WTexturePreviewPanel(QWidget *pParent = 0, CTexture *pTexture = 0); ~WTexturePreviewPanel(); EResType ResType(); void SetResource(CResource *pRes); diff --git a/src/Editor/Widgets/WVectorEditor.cpp b/src/Editor/Widgets/WVectorEditor.cpp index 7b7c51f2..e2eb4ee8 100644 --- a/src/Editor/Widgets/WVectorEditor.cpp +++ b/src/Editor/Widgets/WVectorEditor.cpp @@ -1,22 +1,26 @@ #include "WVectorEditor.h" -WVectorEditor::WVectorEditor(QWidget *pParent) : QWidget(pParent) +WVectorEditor::WVectorEditor(QWidget *pParent) + : QWidget(pParent) + , mValue(CVector3f::skZero) + , mEditing(false) { SetupUI(); - mValue = CVector3f::skZero; mpSpinBoxX->setValue(0.0); mpSpinBoxY->setValue(0.0); mpSpinBoxZ->setValue(0.0); - mEditing = false; } -WVectorEditor::WVectorEditor(const CVector3f& value, QWidget *pParent) : QWidget(pParent) +WVectorEditor::WVectorEditor(const CVector3f& rkValue, QWidget *pParent) + : QWidget(pParent) + , mValue(rkValue) + , mEditing(false) { SetupUI(); - mValue = value; - mpSpinBoxX->setValue((double) value.x); - mpSpinBoxY->setValue((double) value.y); - mpSpinBoxZ->setValue((double) value.z); + mValue = rkValue; + mpSpinBoxX->setValue((double) rkValue.X); + mpSpinBoxY->setValue((double) rkValue.Y); + mpSpinBoxZ->setValue((double) rkValue.Z); mEditing = false; } @@ -30,24 +34,24 @@ CVector3f WVectorEditor::Value() return mValue; } -void WVectorEditor::SetValue(const CVector3f& value) +void WVectorEditor::SetValue(const CVector3f& rkValue) { - mValue = value; + mValue = rkValue; mpSpinBoxX->blockSignals(true); mpSpinBoxY->blockSignals(true); mpSpinBoxZ->blockSignals(true); - mpSpinBoxX->setValue((double) value.x); - mpSpinBoxY->setValue((double) value.y); - mpSpinBoxZ->setValue((double) value.z); + mpSpinBoxX->setValue((double) rkValue.X); + mpSpinBoxY->setValue((double) rkValue.Y); + mpSpinBoxZ->setValue((double) rkValue.Z); mpSpinBoxX->blockSignals(false); mpSpinBoxY->blockSignals(false); mpSpinBoxZ->blockSignals(false); } -void WVectorEditor::SetOrientation(Qt::Orientation orientation) +void WVectorEditor::SetOrientation(Qt::Orientation Orientation) { - mOrientation = orientation; + mOrientation = Orientation; if (mpLayout) { @@ -57,7 +61,7 @@ void WVectorEditor::SetOrientation(Qt::Orientation orientation) delete mpLayout; } - mpLayout = (orientation == Qt::Horizontal ? (QLayout*) new QHBoxLayout : (QLayout*) new QVBoxLayout); + mpLayout = (Orientation == Qt::Horizontal ? (QLayout*) new QHBoxLayout : (QLayout*) new QVBoxLayout); mpLayout->addItem(mpXLayout); mpLayout->addItem(mpYLayout); mpLayout->addItem(mpZLayout); @@ -65,23 +69,23 @@ void WVectorEditor::SetOrientation(Qt::Orientation orientation) setLayout(mpLayout); } -void WVectorEditor::SetDefaultValue(double value) +void WVectorEditor::SetDefaultValue(double Value) { - mpSpinBoxX->SetDefaultValue(value); - mpSpinBoxY->SetDefaultValue(value); - mpSpinBoxZ->SetDefaultValue(value); + mpSpinBoxX->SetDefaultValue(Value); + mpSpinBoxY->SetDefaultValue(Value); + mpSpinBoxZ->SetDefaultValue(Value); } -void WVectorEditor::SetSingleStep(double step) +void WVectorEditor::SetSingleStep(double Step) { - mpSpinBoxX->setSingleStep(step); - mpSpinBoxY->setSingleStep(step); - mpSpinBoxZ->setSingleStep(step); + mpSpinBoxX->setSingleStep(Step); + mpSpinBoxY->setSingleStep(Step); + mpSpinBoxZ->setSingleStep(Step); } -void WVectorEditor::SetLabelsHidden(bool hidden) +void WVectorEditor::SetLabelsHidden(bool Hidden) { - if (hidden) + if (Hidden) { mpLabelX->hide(); mpLabelY->hide(); @@ -107,14 +111,14 @@ bool WVectorEditor::IsBeingEdited() const } // ************ PUBLIC SLOTS ************ -void WVectorEditor::SetX(double x) +void WVectorEditor::SetX(double X) { - mValue.x = (float) x; + mValue.X = (float) X; if (sender() != mpSpinBoxX) { mpSpinBoxX->blockSignals(true); - mpSpinBoxX->setValue((double) x); + mpSpinBoxX->setValue((double) X); mpSpinBoxX->blockSignals(false); } @@ -122,14 +126,14 @@ void WVectorEditor::SetX(double x) emit ValueChanged(mValue); } -void WVectorEditor::SetY(double y) +void WVectorEditor::SetY(double Y) { - mValue.y = (float) y; + mValue.Y = (float) Y; if (sender() != mpSpinBoxY) { mpSpinBoxY->blockSignals(true); - mpSpinBoxY->setValue((double) y); + mpSpinBoxY->setValue((double) Y); mpSpinBoxY->blockSignals(false); } @@ -137,14 +141,14 @@ void WVectorEditor::SetY(double y) emit ValueChanged(mValue); } -void WVectorEditor::SetZ(double z) +void WVectorEditor::SetZ(double Z) { - mValue.z = (float) z; + mValue.Z = (float) Z; if (sender() != mpSpinBoxZ) { mpSpinBoxZ->blockSignals(true); - mpSpinBoxZ->setValue((double) z); + mpSpinBoxZ->setValue((double) Z); mpSpinBoxZ->blockSignals(false); } diff --git a/src/Editor/Widgets/WVectorEditor.h b/src/Editor/Widgets/WVectorEditor.h index b4260c06..9a515cc5 100644 --- a/src/Editor/Widgets/WVectorEditor.h +++ b/src/Editor/Widgets/WVectorEditor.h @@ -31,25 +31,25 @@ class WVectorEditor : public QWidget public: explicit WVectorEditor(QWidget *pParent = 0); - WVectorEditor(const CVector3f& value, QWidget *pParent = 0); + WVectorEditor(const CVector3f& rkValue, QWidget *pParent = 0); ~WVectorEditor(); CVector3f Value(); - void SetOrientation(Qt::Orientation orientation); - void SetValue(const CVector3f& value); - void SetDefaultValue(double value); - void SetSingleStep(double step); - void SetLabelsHidden(bool hidden); + void SetOrientation(Qt::Orientation Orientation); + void SetValue(const CVector3f& rkValue); + void SetDefaultValue(double Value); + void SetSingleStep(double Step); + void SetLabelsHidden(bool Hidden); bool IsBeingDragged() const; bool IsBeingEdited() const; public slots: - void SetX(double x); - void SetY(double y); - void SetZ(double z); + void SetX(double X); + void SetY(double Y); + void SetZ(double Z); signals: - void ValueChanged(const CVector3f& value); - void EditingDone(const CVector3f& value); + void ValueChanged(const CVector3f& rkValue); + void EditingDone(const CVector3f& rkValue); private: void SetupUI(); diff --git a/src/Editor/WorldEditor/CInstancesModel.cpp b/src/Editor/WorldEditor/CInstancesModel.cpp index f858eeb9..421341a2 100644 --- a/src/Editor/WorldEditor/CInstancesModel.cpp +++ b/src/Editor/WorldEditor/CInstancesModel.cpp @@ -26,27 +26,28 @@ #define TYPES_NODE_TYPE_SHIFT 1 #define TYPES_ITEM_TYPE_SHIFT 0 -CInstancesModel::CInstancesModel(QObject *pParent) : QAbstractItemModel(pParent) +CInstancesModel::CInstancesModel(QObject *pParent) + : QAbstractItemModel(pParent) + , mpEditor(nullptr) + , mpScene(nullptr) + , mpArea(nullptr) + , mpCurrentMaster(nullptr) + , mModelType(eLayers) + , mShowColumnEnabled(true) + , mChangingLayout(false) { - mpEditor = nullptr; - mpScene = nullptr; - mpArea = nullptr; - mpCurrentMaster = nullptr; - mModelType = eLayers; - mShowColumnEnabled = true; mBaseItems << "Script"; - mChangingLayout = false; } CInstancesModel::~CInstancesModel() { } -QVariant CInstancesModel::headerData(int section, Qt::Orientation orientation, int role) const +QVariant CInstancesModel::headerData(int Section, Qt::Orientation Orientation, int Role) const { - if ((orientation == Qt::Horizontal) && (role == Qt::DisplayRole)) + if ((Orientation == Qt::Horizontal) && (Role == Qt::DisplayRole)) { - switch (section) + switch (Section) { case 0: return "Name"; case 1: return (mModelType == eLayers ? "Type" : "Layer"); @@ -56,52 +57,52 @@ QVariant CInstancesModel::headerData(int section, Qt::Orientation orientation, i return QVariant::Invalid; } -QModelIndex CInstancesModel::index(int row, int column, const QModelIndex &parent) const +QModelIndex CInstancesModel::index(int Row, int Column, const QModelIndex& rkParent) const { - if (!hasIndex(row, column, parent)) + if (!hasIndex(Row, Column, rkParent)) return QModelIndex(); - EIndexType type = IndexType(parent); + EIndexType Type = IndexType(rkParent); // Node type index - if (type == eRootIndex) + if (Type == eRootIndex) { - if (row < mBaseItems.count()) - return createIndex(row, column, quint32(0)); + if (Row < mBaseItems.count()) + return createIndex(Row, Column, quint32(0)); else return QModelIndex(); } // Object type index - else if (type == eNodeTypeIndex) - return createIndex(row, column, ((row << TYPES_ROW_INDEX_SHIFT) | (parent.row() << TYPES_NODE_TYPE_SHIFT) | 1)); + else if (Type == eNodeTypeIndex) + return createIndex(Row, Column, ((Row << TYPES_ROW_INDEX_SHIFT) | (rkParent.row() << TYPES_NODE_TYPE_SHIFT) | 1)); // Instance index - else if (type == eObjectTypeIndex) + else if (Type == eObjectTypeIndex) { - u32 RootRow = parent.parent().row(); + u32 RootRow = rkParent.parent().row(); // Object if (RootRow == 0) { if (mModelType == eLayers) { - CScriptLayer *pLayer = mpArea->GetScriptLayer(parent.row()); - if ((u32) row >= pLayer->NumInstances()) + CScriptLayer *pLayer = mpArea->ScriptLayer(rkParent.row()); + if ((u32) Row >= pLayer->NumInstances()) return QModelIndex(); else - return createIndex(row, column, (*pLayer)[row]); + return createIndex(Row, Column, (*pLayer)[Row]); } else if (mModelType == eTypes) { - const std::list& list = mTemplateList[parent.row()]->ObjectList(); - if ((u32) row >= list.size()) + const std::list& list = mTemplateList[rkParent.row()]->ObjectList(); + if ((u32) Row >= list.size()) return QModelIndex(); else { - auto it = std::next(list.begin(), row); - return createIndex(row, column, *it); + auto it = std::next(list.begin(), Row); + return createIndex(Row, Column, *it); } } } @@ -112,33 +113,33 @@ QModelIndex CInstancesModel::index(int row, int column, const QModelIndex &paren return QModelIndex(); } -QModelIndex CInstancesModel::parent(const QModelIndex &child) const +QModelIndex CInstancesModel::parent(const QModelIndex& rkChild) const { - EIndexType type = IndexType(child); + EIndexType Type = IndexType(rkChild); // Root parent - if (type == eNodeTypeIndex) + if (Type == eNodeTypeIndex) return QModelIndex(); // Node type parent - if (type == eObjectTypeIndex) + if (Type == eObjectTypeIndex) { - u32 NodeTypeRow = (child.internalId() & TYPES_NODE_TYPE_MASK) >> TYPES_NODE_TYPE_SHIFT; + u32 NodeTypeRow = (rkChild.internalId() & TYPES_NODE_TYPE_MASK) >> TYPES_NODE_TYPE_SHIFT; return createIndex(NodeTypeRow, 0, quint32(0)); } // Object type parent - else if (type == eInstanceIndex) + else if (Type == eInstanceIndex) { - CScriptObject *pObj = static_cast (child.internalPointer()); + CScriptObject *pObj = static_cast (rkChild.internalPointer()); if (mModelType == eLayers) { CScriptLayer *pLayer = pObj->Layer(); - for (u32 iLyr = 0; iLyr < mpArea->GetScriptLayerCount(); iLyr++) + for (u32 iLyr = 0; iLyr < mpArea->NumScriptLayers(); iLyr++) { - if (mpArea->GetScriptLayer(iLyr) == pLayer) + if (mpArea->ScriptLayer(iLyr) == pLayer) return createIndex(iLyr, 0, (iLyr << TYPES_ROW_INDEX_SHIFT) | 1); } } @@ -158,21 +159,22 @@ QModelIndex CInstancesModel::parent(const QModelIndex &child) const return QModelIndex(); } -int CInstancesModel::rowCount(const QModelIndex &parent) const +int CInstancesModel::rowCount(const QModelIndex& rkParent) const { - EIndexType type = IndexType(parent); + EIndexType Type = IndexType(rkParent); // Node types - if (type == eRootIndex) + if (Type == eRootIndex) return mBaseItems.count(); // Object types - else if (type == eNodeTypeIndex) + else if (Type == eNodeTypeIndex) { // Script Objects - if (parent.row() == 0) { + if (rkParent.row() == 0) + { if (mModelType == eLayers) - return (mpArea ? mpArea->GetScriptLayerCount() : 0); + return (mpArea ? mpArea->NumScriptLayers() : 0); else return mTemplateList.size(); } @@ -181,11 +183,11 @@ int CInstancesModel::rowCount(const QModelIndex &parent) const } // Instances - else if (type == eObjectTypeIndex) + else if (Type == eObjectTypeIndex) { - u32 RowIndex = ((parent.internalId() & TYPES_ROW_INDEX_MASK) >> TYPES_ROW_INDEX_SHIFT); + u32 RowIndex = ((rkParent.internalId() & TYPES_ROW_INDEX_MASK) >> TYPES_ROW_INDEX_SHIFT); if (mModelType == eLayers) - return (mpArea ? mpArea->GetScriptLayer(RowIndex)->NumInstances() : 0); + return (mpArea ? mpArea->ScriptLayer(RowIndex)->NumInstances() : 0); else return mTemplateList[RowIndex]->NumObjects(); } @@ -194,36 +196,37 @@ int CInstancesModel::rowCount(const QModelIndex &parent) const return 0; } -int CInstancesModel::columnCount(const QModelIndex& /*parent*/) const +int CInstancesModel::columnCount(const QModelIndex& /*rkParent*/) const { return (mShowColumnEnabled ? 3 : 2); } -QVariant CInstancesModel::data(const QModelIndex &index, int role) const +QVariant CInstancesModel::data(const QModelIndex& rkIndex, int Role) const { - EIndexType type = IndexType(index); + EIndexType Type = IndexType(rkIndex); // Name/Layer - if ((role == Qt::DisplayRole) || (role == Qt::ToolTipRole)) + if ((Role == Qt::DisplayRole) || (Role == Qt::ToolTipRole)) { // Node types - if (type == eNodeTypeIndex) + if (Type == eNodeTypeIndex) { - if (index.column() == 0) - return mBaseItems[index.row()]; + if (rkIndex.column() == 0) + return mBaseItems[rkIndex.row()]; else return QVariant::Invalid; } // Object types - else if (type == eObjectTypeIndex) + else if (Type == eObjectTypeIndex) { - if (index.column() == 0) { + if (rkIndex.column() == 0) + { if (mModelType == eLayers) - return TO_QSTRING(mpEditor->ActiveArea()->GetScriptLayer(index.row())->Name()); + return TO_QSTRING(mpEditor->ActiveArea()->ScriptLayer(rkIndex.row())->Name()); else - return TO_QSTRING(mTemplateList[index.row()]->Name()); + return TO_QSTRING(mTemplateList[rkIndex.row()]->Name()); } // todo: show/hide button in column 2 else @@ -231,15 +234,15 @@ QVariant CInstancesModel::data(const QModelIndex &index, int role) const } // Instances - else if (type == eInstanceIndex) + else if (Type == eInstanceIndex) { // todo: show/hide button - CScriptObject *pObj = static_cast(index.internalPointer()); + CScriptObject *pObj = static_cast(rkIndex.internalPointer()); - if (index.column() == 0) + if (rkIndex.column() == 0) return TO_QSTRING(pObj->InstanceName()); - else if (index.column() == 1) + else if (rkIndex.column() == 1) { if (mModelType == eLayers) return TO_QSTRING(pObj->Template()->Name()); @@ -253,7 +256,7 @@ QVariant CInstancesModel::data(const QModelIndex &index, int role) const } // Show/Hide Buttons - else if ((role == Qt::DecorationRole) && (index.column() == 2)) + else if ((Role == Qt::DecorationRole) && (rkIndex.column() == 2)) { if (!mpScene) return QVariant::Invalid; @@ -261,7 +264,7 @@ QVariant CInstancesModel::data(const QModelIndex &index, int role) const static QIcon Invisible(":/icons/Hide.png"); // Show/Hide Node Types - if (type == eNodeTypeIndex) + if (Type == eNodeTypeIndex) { // Commented out pending a proper implementation of turning node types on/off from the instance view /*bool IsVisible; @@ -278,28 +281,28 @@ QVariant CInstancesModel::data(const QModelIndex &index, int role) const } // Show/Hide Object Types - else if (type == eObjectTypeIndex) + else if (Type == eObjectTypeIndex) { if (mModelType == eLayers) { - CScriptLayer *pLayer = IndexLayer(index); + CScriptLayer *pLayer = IndexLayer(rkIndex); if (pLayer->IsVisible()) return Visible; else return Invisible; } else if (mModelType == eTypes) { - CScriptTemplate *pTemp = IndexTemplate(index); + CScriptTemplate *pTemp = IndexTemplate(rkIndex); if (pTemp->IsVisible()) return Visible; else return Invisible; } } // Show/Hide Instance - else if (type == eInstanceIndex) + else if (Type == eInstanceIndex) { - CScriptObject *pObj = IndexObject(index); - CScriptNode *pNode = mpScene->NodeForObject(pObj); + CScriptObject *pObj = IndexObject(rkIndex); + CScriptNode *pNode = mpScene->NodeForInstance(pObj); if (pNode->MarkedVisible()) return Visible; else return Invisible; } @@ -337,9 +340,9 @@ void CInstancesModel::SetArea(CGameArea *pArea) endResetModel(); } -void CInstancesModel::SetModelType(EInstanceModelType type) +void CInstancesModel::SetModelType(EInstanceModelType Type) { - mModelType = type; + mModelType = Type; } void CInstancesModel::SetShowColumnEnabled(bool Enabled) @@ -348,30 +351,30 @@ void CInstancesModel::SetShowColumnEnabled(bool Enabled) emit layoutChanged(); } -CScriptLayer* CInstancesModel::IndexLayer(const QModelIndex& index) const +CScriptLayer* CInstancesModel::IndexLayer(const QModelIndex& rkIndex) const { - if ((mModelType != eLayers) || (IndexNodeType(index) != eScriptType) || (IndexType(index) != eObjectTypeIndex)) + if ((mModelType != eLayers) || (IndexNodeType(rkIndex) != eScriptType) || (IndexType(rkIndex) != eObjectTypeIndex)) return nullptr; - u32 RowIndex = ((index.internalId() & TYPES_ROW_INDEX_MASK) >> TYPES_ROW_INDEX_SHIFT); - return mpArea->GetScriptLayer(RowIndex); + u32 RowIndex = ((rkIndex.internalId() & TYPES_ROW_INDEX_MASK) >> TYPES_ROW_INDEX_SHIFT); + return mpArea->ScriptLayer(RowIndex); } -CScriptTemplate* CInstancesModel::IndexTemplate(const QModelIndex& index) const +CScriptTemplate* CInstancesModel::IndexTemplate(const QModelIndex& rkIndex) const { - if ((mModelType != eTypes) || (IndexNodeType(index) != eScriptType) || (IndexType(index) != eObjectTypeIndex)) + if ((mModelType != eTypes) || (IndexNodeType(rkIndex) != eScriptType) || (IndexType(rkIndex) != eObjectTypeIndex)) return nullptr; - u32 RowIndex = ((index.internalId() & TYPES_ROW_INDEX_MASK) >> TYPES_ROW_INDEX_SHIFT); + u32 RowIndex = ((rkIndex.internalId() & TYPES_ROW_INDEX_MASK) >> TYPES_ROW_INDEX_SHIFT); return mTemplateList[RowIndex]; } -CScriptObject* CInstancesModel::IndexObject(const QModelIndex& index) const +CScriptObject* CInstancesModel::IndexObject(const QModelIndex& rkIndex) const { - if ((IndexNodeType(index) != eScriptType) || (IndexType(index) != eInstanceIndex)) + if ((IndexNodeType(rkIndex) != eScriptType) || (IndexType(rkIndex) != eInstanceIndex)) return nullptr; - return static_cast(index.internalPointer()); + return static_cast(rkIndex.internalPointer()); } // ************ PUBLIC SLOTS ************ @@ -397,7 +400,7 @@ void CInstancesModel::NodeCreated(CSceneNode *pNode) if (pNode->NodeType() == eScriptNode) { CScriptNode *pScript = static_cast(pNode); - CScriptObject *pObj = pScript->Object(); + CScriptObject *pObj = pScript->Instance(); pObj->Template()->SortObjects(); if (pObj->Template()->NumObjects() == 1) @@ -426,7 +429,7 @@ void CInstancesModel::NodeAboutToBeDeleted(CSceneNode *pNode) if (mModelType == eTypes) { CScriptNode *pScript = static_cast(pNode); - CScriptObject *pObj = pScript->Object(); + CScriptObject *pObj = pScript->Instance(); if (pObj->Template()->NumObjects() <= 1) { @@ -500,7 +503,7 @@ void CInstancesModel::InstancesLayerPostChange(const QList& rkInst { QList InstanceList; foreach (CScriptNode *pNode, rkInstanceList) - InstanceList << pNode->Object(); + InstanceList << pNode->Instance(); QModelIndex ScriptIdx = index(0, 0, QModelIndex()); @@ -528,24 +531,24 @@ void CInstancesModel::InstancesLayerPostChange(const QList& rkInst } // ************ STATIC ************ -CInstancesModel::EIndexType CInstancesModel::IndexType(const QModelIndex& index) +CInstancesModel::EIndexType CInstancesModel::IndexType(const QModelIndex& rkIndex) { - if (!index.isValid()) return eRootIndex; - else if (index.internalId() == 0) return eNodeTypeIndex; - else if (((index.internalId() & TYPES_ITEM_TYPE_MASK) >> TYPES_ITEM_TYPE_SHIFT) == 1) return eObjectTypeIndex; + if (!rkIndex.isValid()) return eRootIndex; + else if (rkIndex.internalId() == 0) return eNodeTypeIndex; + else if (((rkIndex.internalId() & TYPES_ITEM_TYPE_MASK) >> TYPES_ITEM_TYPE_SHIFT) == 1) return eObjectTypeIndex; else return eInstanceIndex; } -CInstancesModel::ENodeType CInstancesModel::IndexNodeType(const QModelIndex& index) +CInstancesModel::ENodeType CInstancesModel::IndexNodeType(const QModelIndex& rkIndex) { - EIndexType type = IndexType(index); + EIndexType type = IndexType(rkIndex); switch (type) { case eRootIndex: return eInvalidType; - case eNodeTypeIndex: return (ENodeType) index.row(); - case eObjectTypeIndex: return (ENodeType) index.parent().row(); - case eInstanceIndex: return (ENodeType) index.parent().parent().row(); + case eNodeTypeIndex: return (ENodeType) rkIndex.row(); + case eObjectTypeIndex: return (ENodeType) rkIndex.parent().row(); + case eInstanceIndex: return (ENodeType) rkIndex.parent().parent().row(); default: return eInvalidType; } } diff --git a/src/Editor/WorldEditor/CInstancesModel.h b/src/Editor/WorldEditor/CInstancesModel.h index 8aadd4f4..5a936bfe 100644 --- a/src/Editor/WorldEditor/CInstancesModel.h +++ b/src/Editor/WorldEditor/CInstancesModel.h @@ -14,17 +14,20 @@ class CInstancesModel : public QAbstractItemModel Q_OBJECT public: - enum EIndexType { + enum EIndexType + { eRootIndex, eNodeTypeIndex, eObjectTypeIndex, eInstanceIndex }; - enum ENodeType { + enum ENodeType + { eScriptType = 0x0, eLightType = 0x1, eInvalidType = 0xFF }; - enum EInstanceModelType { + enum EInstanceModelType + { eLayers, eTypes }; @@ -42,21 +45,21 @@ private: public: explicit CInstancesModel(QObject *pParent = 0); ~CInstancesModel(); - QVariant headerData(int section, Qt::Orientation orientation, int role) const; - QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const; - QModelIndex parent(const QModelIndex &child) const; - int rowCount(const QModelIndex &parent) const; - int columnCount(const QModelIndex &parent) const; - QVariant data(const QModelIndex &index, int role) const; + QVariant headerData(int Section, Qt::Orientation Orientation, int Role) const; + QModelIndex index(int Row, int Column, const QModelIndex& rkParent = QModelIndex()) const; + QModelIndex parent(const QModelIndex& rkChild) const; + int rowCount(const QModelIndex& rkParent) const; + int columnCount(const QModelIndex& rkParent) const; + QVariant data(const QModelIndex& rkIndex, int Role) const; void SetEditor(CWorldEditor *pEditor); void SetMaster(CMasterTemplate *pMaster); void SetArea(CGameArea *pArea); - void SetModelType(EInstanceModelType type); + void SetModelType(EInstanceModelType Type); void SetShowColumnEnabled(bool Enabled); - CScriptLayer* IndexLayer(const QModelIndex& index) const; - CScriptTemplate* IndexTemplate(const QModelIndex& index) const; - CScriptObject* IndexObject(const QModelIndex& index) const; + CScriptLayer* IndexLayer(const QModelIndex& rkIndex) const; + CScriptTemplate* IndexTemplate(const QModelIndex& rkIndex) const; + CScriptObject* IndexObject(const QModelIndex& rkIndex) const; public slots: void NodeAboutToBeCreated(); @@ -69,12 +72,11 @@ public slots: void InstancesLayerPostChange(const QList& rkInstanceList); // Static - static EIndexType IndexType(const QModelIndex& index); - static ENodeType IndexNodeType(const QModelIndex& index); + static EIndexType IndexType(const QModelIndex& rkIndex); + static ENodeType IndexNodeType(const QModelIndex& rkIndex); private: void GenerateList(); - }; #endif // CTYPESINSTANCEMODEL_H diff --git a/src/Editor/WorldEditor/CLayerEditor.cpp b/src/Editor/WorldEditor/CLayerEditor.cpp index 1a2a4c45..04c5a4c9 100644 --- a/src/Editor/WorldEditor/CLayerEditor.cpp +++ b/src/Editor/WorldEditor/CLayerEditor.cpp @@ -4,14 +4,13 @@ #include -CLayerEditor::CLayerEditor(QWidget *parent) : - QDialog(parent), - ui(new Ui::CLayerEditor) +CLayerEditor::CLayerEditor(QWidget *parent) + : QDialog(parent) + , ui(new Ui::CLayerEditor) + , mpArea(nullptr) + , mpModel(new CLayerModel(this)) { ui->setupUi(this); - - mpArea = nullptr; - mpModel = new CLayerModel(this); ui->LayerSelectComboBox->setModel(mpModel); connect(ui->LayerSelectComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(SetCurrentIndex(int))); @@ -32,26 +31,26 @@ void CLayerEditor::SetArea(CGameArea *pArea) } // ************ SLOTS ************ -void CLayerEditor::SetCurrentIndex(int index) +void CLayerEditor::SetCurrentIndex(int Index) { ui->LayerSelectComboBox->blockSignals(true); - ui->LayerSelectComboBox->setCurrentIndex(index); + ui->LayerSelectComboBox->setCurrentIndex(Index); ui->LayerSelectComboBox->blockSignals(false); - QModelIndex ModelIndex = mpModel->index(index); + QModelIndex ModelIndex = mpModel->index(Index); mpCurrentLayer = mpModel->Layer(ModelIndex); ui->NameLineEdit->setText(TO_QSTRING(mpCurrentLayer->Name())); ui->ActiveCheckBox->setChecked(mpCurrentLayer->IsActive()); } -void CLayerEditor::EditLayerName(const QString &name) +void CLayerEditor::EditLayerName(const QString& rkName) { - mpCurrentLayer->SetName(name.toStdString()); + mpCurrentLayer->SetName(rkName.toStdString()); ui->LayerSelectComboBox->update(); } -void CLayerEditor::EditLayerActive(bool active) +void CLayerEditor::EditLayerActive(bool Active) { - mpCurrentLayer->SetActive(active); + mpCurrentLayer->SetActive(Active); } diff --git a/src/Editor/WorldEditor/CLayerEditor.h b/src/Editor/WorldEditor/CLayerEditor.h index 7cce3b0d..352de01c 100644 --- a/src/Editor/WorldEditor/CLayerEditor.h +++ b/src/Editor/WorldEditor/CLayerEditor.h @@ -21,9 +21,9 @@ public: void SetArea(CGameArea *pArea); public slots: - void SetCurrentIndex(int index); - void EditLayerName(const QString& name); - void EditLayerActive(bool active); + void SetCurrentIndex(int Index); + void EditLayerName(const QString& rkName); + void EditLayerActive(bool Active); private: Ui::CLayerEditor *ui; diff --git a/src/Editor/WorldEditor/CLayerModel.cpp b/src/Editor/WorldEditor/CLayerModel.cpp index b1c196c5..6e1c04ee 100644 --- a/src/Editor/WorldEditor/CLayerModel.cpp +++ b/src/Editor/WorldEditor/CLayerModel.cpp @@ -15,8 +15,8 @@ CLayerModel::~CLayerModel() int CLayerModel::rowCount(const QModelIndex& /*parent*/) const { if (!mpArea) return 0; - if (mHasGenerateLayer) return mpArea->GetScriptLayerCount() + 1; - else return mpArea->GetScriptLayerCount(); + if (mHasGenerateLayer) return mpArea->NumScriptLayers() + 1; + else return mpArea->NumScriptLayers(); } QVariant CLayerModel::data(const QModelIndex &index, int role) const @@ -30,19 +30,19 @@ QVariant CLayerModel::data(const QModelIndex &index, int role) const void CLayerModel::SetArea(CGameArea *pArea) { mpArea = pArea; - mHasGenerateLayer = (pArea->GetGeneratorLayer() != nullptr); + mHasGenerateLayer = (pArea->GeneratedObjectsLayer() != nullptr); emit layoutChanged(); } CScriptLayer* CLayerModel::Layer(const QModelIndex& index) const { if (!mpArea) return nullptr; - u32 NumLayers = mpArea->GetScriptLayerCount(); + u32 NumLayers = mpArea->NumScriptLayers(); if (index.row() < (int) NumLayers) - return mpArea->GetScriptLayer(index.row()); + return mpArea->ScriptLayer(index.row()); if (mHasGenerateLayer && (index.row() == NumLayers)) - return mpArea->GetGeneratorLayer(); + return mpArea->GeneratedObjectsLayer(); return nullptr; } diff --git a/src/Editor/WorldEditor/CLinkDialog.cpp b/src/Editor/WorldEditor/CLinkDialog.cpp index afb9e52b..b91d3d17 100644 --- a/src/Editor/WorldEditor/CLinkDialog.cpp +++ b/src/Editor/WorldEditor/CLinkDialog.cpp @@ -219,9 +219,9 @@ void CLinkDialog::OnPickModeClick(const SRayIntersection& rkHit, QMouseEvent* /* CScriptNode *pScript = static_cast(rkHit.pNode); if (ui->SenderPickFromViewport->isChecked()) - SetSender(pScript->Object()); + SetSender(pScript->Instance()); else - SetReceiver(pScript->Object()); + SetReceiver(pScript->Instance()); mpEditor->ExitPickMode(); } diff --git a/src/Editor/WorldEditor/CLinkModel.cpp b/src/Editor/WorldEditor/CLinkModel.cpp index a0674f79..b3b3e04c 100644 --- a/src/Editor/WorldEditor/CLinkModel.cpp +++ b/src/Editor/WorldEditor/CLinkModel.cpp @@ -3,10 +3,11 @@ #include #include -CLinkModel::CLinkModel(QObject *pParent) : QAbstractTableModel(pParent) +CLinkModel::CLinkModel(QObject *pParent) + : QAbstractTableModel(pParent) + , mpObject(nullptr) + , mType(eOutgoing) { - mpObject = nullptr; - mType = eOutgoing; } void CLinkModel::SetObject(CScriptObject *pObj) @@ -15,9 +16,9 @@ void CLinkModel::SetObject(CScriptObject *pObj) emit layoutChanged(); } -void CLinkModel::SetConnectionType(ELinkType type) +void CLinkModel::SetConnectionType(ELinkType Type) { - mType = type; + mType = Type; emit layoutChanged(); } @@ -29,20 +30,20 @@ int CLinkModel::rowCount(const QModelIndex&) const else return 0; } -int CLinkModel::columnCount(const QModelIndex& /*parent*/) const +int CLinkModel::columnCount(const QModelIndex& /*rkParent*/) const { return 3; } -QVariant CLinkModel::data(const QModelIndex &index, int role) const +QVariant CLinkModel::data(const QModelIndex& rkIndex, int Role) const { if (!mpObject) return QVariant::Invalid; - else if ((role == Qt::DisplayRole) || (role == Qt::ToolTipRole)) + else if ((Role == Qt::DisplayRole) || (Role == Qt::ToolTipRole)) { - CLink *pLink = mpObject->Link(mType, index.row()); + CLink *pLink = mpObject->Link(mType, rkIndex.row()); - switch (index.column()) + switch (rkIndex.column()) { case 0: // Column 0 - Target Object @@ -50,11 +51,14 @@ QVariant CLinkModel::data(const QModelIndex &index, int role) const u32 TargetID = (mType == eIncoming ? pLink->SenderID() : pLink->ReceiverID()); CScriptObject *pTarget = mpObject->Area()->InstanceByID(TargetID); - if (pTarget) { + if (pTarget) + { QString ObjType = QString("[%1] ").arg(UICommon::ToQString(pTarget->Template()->Name())); return ObjType + UICommon::ToQString(pTarget->InstanceName()); } - else { + + else + { QString strID = QString::number(TargetID, 16); while (strID.length() < 8) strID = "0" + strID; return QString("External: 0x") + strID; @@ -81,11 +85,11 @@ QVariant CLinkModel::data(const QModelIndex &index, int role) const else return QVariant::Invalid; } -QVariant CLinkModel::headerData(int section, Qt::Orientation orientation, int role) const +QVariant CLinkModel::headerData(int Section, Qt::Orientation Orientation, int Role) const { - if ((orientation == Qt::Horizontal) && (role == Qt::DisplayRole)) + if ((Orientation == Qt::Horizontal) && (Role == Qt::DisplayRole)) { - switch (section) + switch (Section) { case 0: return (mType == eIncoming ? "Sender" : "Target"); case 1: return "State"; diff --git a/src/Editor/WorldEditor/CLinkModel.h b/src/Editor/WorldEditor/CLinkModel.h index 6d42f16d..3486fc97 100644 --- a/src/Editor/WorldEditor/CLinkModel.h +++ b/src/Editor/WorldEditor/CLinkModel.h @@ -14,11 +14,11 @@ class CLinkModel : public QAbstractTableModel public: explicit CLinkModel(QObject *pParent = 0); void SetObject(CScriptObject *pObj); - void SetConnectionType(ELinkType type); - int rowCount(const QModelIndex& parent = QModelIndex()) const; - int columnCount(const QModelIndex &parent) const; - QVariant data(const QModelIndex &index, int role) const; - QVariant headerData(int section, Qt::Orientation orientation, int role) const; + void SetConnectionType(ELinkType Type); + int rowCount(const QModelIndex& rkParent = QModelIndex()) const; + int columnCount(const QModelIndex& rkParent) const; + QVariant data(const QModelIndex& rkIndex, int Role) const; + QVariant headerData(int Section, Qt::Orientation Orientation, int Role) const; }; #endif // CCONNECTIONMODEL_H diff --git a/src/Editor/WorldEditor/CPoiListDialog.h b/src/Editor/WorldEditor/CPoiListDialog.h index cc7d4c21..a39fd829 100644 --- a/src/Editor/WorldEditor/CPoiListDialog.h +++ b/src/Editor/WorldEditor/CPoiListDialog.h @@ -34,7 +34,7 @@ public: for (auto it = rkObjList.begin(); it != rkObjList.end(); it++) { - CScriptNode *pNode = pScene->NodeForObject(*it); + CScriptNode *pNode = pScene->NodeForInstance(*it); if (!pMapModel->IsPoiTracked(pNode)) mObjList << pNode; @@ -51,7 +51,7 @@ public: if (!rkIndex.isValid()) return QVariant::Invalid; if (Role == Qt::DisplayRole) - return TO_QSTRING(mObjList[rkIndex.row()]->Object()->InstanceName()); + return TO_QSTRING(mObjList[rkIndex.row()]->Instance()->InstanceName()); if (Role == Qt::DecorationRole) { diff --git a/src/Editor/WorldEditor/CPoiMapEditDialog.cpp b/src/Editor/WorldEditor/CPoiMapEditDialog.cpp index 135acf50..48302b05 100644 --- a/src/Editor/WorldEditor/CPoiMapEditDialog.cpp +++ b/src/Editor/WorldEditor/CPoiMapEditDialog.cpp @@ -15,8 +15,8 @@ const CColor CPoiMapEditDialog::skNormalColor(0.137255f, 0.184314f, 0.776471f, 0 const CColor CPoiMapEditDialog::skImportantColor(0.721569f, 0.066667f, 0.066667f, 0.5f); const CColor CPoiMapEditDialog::skHoverColor(0.047059f, 0.2f, 0.003922f, 0.5f); -CPoiMapEditDialog::CPoiMapEditDialog(CWorldEditor *pEditor, QWidget *parent) - : QMainWindow(parent) +CPoiMapEditDialog::CPoiMapEditDialog(CWorldEditor *pEditor, QWidget *pParent) + : QMainWindow(pParent) , ui(new Ui::CPoiMapEditDialog) , mpEditor(pEditor) , mSourceModel(pEditor, this) @@ -183,7 +183,7 @@ QModelIndex CPoiMapEditDialog::GetSelectedRow() const void CPoiMapEditDialog::Save() { - CPoiToWorld *pPoiToWorld = mpEditor->ActiveArea()->GetPoiToWorldMap(); + CPoiToWorld *pPoiToWorld = mpEditor->ActiveArea()->PoiToWorldMap(); TString FileName = pPoiToWorld->FullSource(); CFileOutStream Out(FileName.ToStdString(), IOUtil::eBigEndian); @@ -344,7 +344,7 @@ void CPoiMapEditDialog::StopPicking() void CPoiMapEditDialog::OnInstanceListButtonClicked() { EGame Game = mpEditor->ActiveArea()->Version(); - CScriptTemplate *pPoiTemplate = CMasterTemplate::GetMasterForGame(Game)->TemplateByID("POIN"); + CScriptTemplate *pPoiTemplate = CMasterTemplate::MasterForGame(Game)->TemplateByID("POIN"); CPoiListDialog Dialog(pPoiTemplate, &mSourceModel, mpEditor->Scene(), this); Dialog.exec(); @@ -374,7 +374,7 @@ void CPoiMapEditDialog::OnRemovePoiButtonClicked() void CPoiMapEditDialog::OnPoiPicked(const SRayIntersection& rkIntersect, QMouseEvent *pEvent) { CScriptNode *pPOI = static_cast(rkIntersect.pNode); - if (pPOI->Object()->ObjectTypeID() != CFourCC("POIN").ToLong()) return; + if (pPOI->Instance()->ObjectTypeID() != CFourCC("POIN").ToLong()) return; mSourceModel.AddPOI(pPOI); mModel.sort(0); diff --git a/src/Editor/WorldEditor/CPoiMapEditDialog.h b/src/Editor/WorldEditor/CPoiMapEditDialog.h index 926e1362..550ac40c 100644 --- a/src/Editor/WorldEditor/CPoiMapEditDialog.h +++ b/src/Editor/WorldEditor/CPoiMapEditDialog.h @@ -45,7 +45,7 @@ class CPoiMapEditDialog : public QMainWindow static const CColor skHoverColor; public: - explicit CPoiMapEditDialog(CWorldEditor *pEditor, QWidget *parent = 0); + explicit CPoiMapEditDialog(CWorldEditor *pEditor, QWidget *pParent = 0); ~CPoiMapEditDialog(); void closeEvent(QCloseEvent *pEvent); void HighlightPoiModels(const QModelIndex& rkIndex); diff --git a/src/Editor/WorldEditor/CPoiMapModel.cpp b/src/Editor/WorldEditor/CPoiMapModel.cpp index 0709fc4c..af09805c 100644 --- a/src/Editor/WorldEditor/CPoiMapModel.cpp +++ b/src/Editor/WorldEditor/CPoiMapModel.cpp @@ -8,7 +8,7 @@ CPoiMapModel::CPoiMapModel(CWorldEditor *pEditor, QObject *pParent /*= 0*/) : QAbstractListModel(pParent) , mpEditor(pEditor) , mpArea(pEditor->ActiveArea()) - , mpPoiToWorld(mpArea->GetPoiToWorldMap()) + , mpPoiToWorld(mpArea->PoiToWorldMap()) { if (mpPoiToWorld) { @@ -81,7 +81,7 @@ QVariant CPoiMapModel::data(const QModelIndex& rkIndex, int Role) const else if (Role == Qt::DecorationRole) { - CScriptNode *pNode = mpEditor->Scene()->NodeForObject(pPOI); + CScriptNode *pNode = mpEditor->Scene()->NodeForInstance(pPOI); bool IsImportant = false; if (pNode) @@ -112,7 +112,7 @@ void CPoiMapModel::AddPOI(CScriptNode *pPOI) QList *pList = new QList; mModelMap[pPOI] = pList; - mpPoiToWorld->AddPoi(pPOI->Object()->InstanceID()); + mpPoiToWorld->AddPoi(pPOI->Instance()->InstanceID()); endInsertRows(); } @@ -127,7 +127,7 @@ void CPoiMapModel::AddMapping(const QModelIndex& rkIndex, CModelNode *pNode) if (!pList->contains(pNode)) pList->append(pNode); - mpPoiToWorld->AddPoiMeshMap(pPOI->Object()->InstanceID(), pNode->FindMeshID()); + mpPoiToWorld->AddPoiMeshMap(pPOI->Instance()->InstanceID(), pNode->FindMeshID()); } void CPoiMapModel::RemovePOI(const QModelIndex& rkIndex) @@ -141,7 +141,7 @@ void CPoiMapModel::RemovePOI(const QModelIndex& rkIndex) mModelMap.remove(pPOI); } - mpPoiToWorld->RemovePoi(pPOI->Object()->InstanceID()); + mpPoiToWorld->RemovePoi(pPOI->Instance()->InstanceID()); endRemoveRows(); } @@ -153,10 +153,10 @@ void CPoiMapModel::RemoveMapping(const QModelIndex& rkIndex, CModelNode *pNode) { QList *pList = mModelMap[pPOI]; pList->removeOne(pNode); - mpPoiToWorld->RemovePoiMeshMap(pPOI->Object()->InstanceID(), pNode->FindMeshID()); + mpPoiToWorld->RemovePoiMeshMap(pPOI->Instance()->InstanceID(), pNode->FindMeshID()); } else - mpPoiToWorld->RemovePoiMeshMap(pPOI->Object()->InstanceID(), pNode->FindMeshID()); + mpPoiToWorld->RemovePoiMeshMap(pPOI->Instance()->InstanceID(), pNode->FindMeshID()); } bool CPoiMapModel::IsPoiTracked(CScriptNode *pPOI) const diff --git a/src/Editor/WorldEditor/CSelectInstanceDialog.cpp b/src/Editor/WorldEditor/CSelectInstanceDialog.cpp index e72012ec..9beb2126 100644 --- a/src/Editor/WorldEditor/CSelectInstanceDialog.cpp +++ b/src/Editor/WorldEditor/CSelectInstanceDialog.cpp @@ -19,7 +19,7 @@ CSelectInstanceDialog::CSelectInstanceDialog(CWorldEditor *pEditor, QWidget *pPa mTypesModel.SetModelType(CInstancesModel::eTypes); mTypesModel.SetEditor(pEditor); mTypesModel.SetArea(pEditor->ActiveArea()); - mTypesModel.SetMaster(CMasterTemplate::GetMasterForGame(pEditor->CurrentGame())); + mTypesModel.SetMaster(CMasterTemplate::MasterForGame(pEditor->CurrentGame())); mTypesModel.SetShowColumnEnabled(false); int Col0Width = ui->LayersTreeView->width() * 0.9; diff --git a/src/Editor/WorldEditor/CTemplateEditDialog.cpp b/src/Editor/WorldEditor/CTemplateEditDialog.cpp index b4fab768..4b6b5670 100644 --- a/src/Editor/WorldEditor/CTemplateEditDialog.cpp +++ b/src/Editor/WorldEditor/CTemplateEditDialog.cpp @@ -10,13 +10,12 @@ CTemplateEditDialog::CTemplateEditDialog(IPropertyTemplate *pTemplate, QWidget * : QDialog(pParent) , ui(new Ui::CTemplateEditDialog) , mpTemplate(pTemplate) + , mGame(pTemplate->Game()) + , mOriginalName(pTemplate->Name()) + , mOriginalDescription(pTemplate->Description()) { ui->setupUi(this); - mGame = pTemplate->Game(); - mOriginalName = pTemplate->Name(); - mOriginalDescription = pTemplate->Description(); - ui->IDDisplayLabel->setText(TO_QSTRING(pTemplate->IDString(false))); ui->PathDisplayLabel->setText(TO_QSTRING(pTemplate->IDString(true))); ui->NameLineEdit->setText(TO_QSTRING(pTemplate->Name())); @@ -32,7 +31,7 @@ CTemplateEditDialog::CTemplateEditDialog(IPropertyTemplate *pTemplate, QWidget * else { CTemplateLoader::LoadAllGames(); - std::vector TemplateList = CMasterTemplate::GetXMLsUsingID(pTemplate->PropertyID()); + std::vector TemplateList = CMasterTemplate::XMLsUsingID(pTemplate->PropertyID()); for (u32 iTemp = 0; iTemp < TemplateList.size(); iTemp++) ui->TemplatesListWidget->addItem(TO_QSTRING(TemplateList[iTemp])); @@ -96,7 +95,7 @@ void CTemplateEditDialog::ApplyChanges() CMasterTemplate::RenameProperty(mpTemplate, NewName); // Add modified templates to pending resave list - const std::vector *pList = CMasterTemplate::GetTemplatesWithMatchingID(mpTemplate); + const std::vector *pList = CMasterTemplate::TemplatesWithMatchingID(mpTemplate); if (pList) { @@ -136,7 +135,7 @@ void CTemplateEditDialog::AddTemplate(IPropertyTemplate *pTemp) if (!Source.IsEmpty()) { - CStructTemplate *pStruct = pTemp->MasterTemplate()->GetStructAtSource(Source); + CStructTemplate *pStruct = pTemp->MasterTemplate()->StructAtSource(Source); if (!mStructTemplatesToResave.contains(pStruct)) mStructTemplatesToResave << pStruct; @@ -170,7 +169,7 @@ void CTemplateEditDialog::UpdateDescription(const TString& rkNewDesc) if (!SourceFile.IsEmpty()) { - const std::vector *pkTemplates = CMasterTemplate::GetTemplatesWithMatchingID(mpTemplate); + const std::vector *pkTemplates = CMasterTemplate::TemplatesWithMatchingID(mpTemplate); if (pkTemplates) { @@ -219,7 +218,7 @@ void CTemplateEditDialog::FindEquivalentProperties(IPropertyTemplate *pTemp) } } - QList MasterList = QList::fromStdList(CMasterTemplate::GetMasterList()); + QList MasterList = QList::fromStdList(CMasterTemplate::MasterList()); if (Source.IsEmpty()) { @@ -227,7 +226,7 @@ void CTemplateEditDialog::FindEquivalentProperties(IPropertyTemplate *pTemp) foreach (CMasterTemplate *pMaster, MasterList) { - if (pMaster == pTemp->MasterTemplate() || pMaster->GetGame() <= ePrime) continue; + if (pMaster == pTemp->MasterTemplate() || pMaster->Game() <= ePrime) continue; CScriptTemplate *pNewScript = pMaster->TemplateByID(ObjectID); if (pNewScript) @@ -244,8 +243,8 @@ void CTemplateEditDialog::FindEquivalentProperties(IPropertyTemplate *pTemp) { foreach (CMasterTemplate *pMaster, MasterList) { - if (pMaster == pTemp->MasterTemplate() || pMaster->GetGame() <= ePrime) continue; - CStructTemplate *pStruct = pMaster->GetStructAtSource(Source); + if (pMaster == pTemp->MasterTemplate() || pMaster->Game() <= ePrime) continue; + CStructTemplate *pStruct = pMaster->StructAtSource(Source); if (pStruct) { diff --git a/src/Editor/WorldEditor/CWorldEditor.cpp b/src/Editor/WorldEditor/CWorldEditor.cpp index 72aacda9..ba623b79 100644 --- a/src/Editor/WorldEditor/CWorldEditor.cpp +++ b/src/Editor/WorldEditor/CWorldEditor.cpp @@ -180,7 +180,7 @@ void CWorldEditor::SetArea(CWorld *pWorld, CGameArea *pArea) if (pCamera->MoveMode() == eFreeCamera) { - CTransform4f AreaTransform = pArea->GetTransform(); + CTransform4f AreaTransform = pArea->Transform(); CVector3f AreaPosition(AreaTransform[0][3], AreaTransform[1][3], AreaTransform[2][3]); pCamera->Snap(AreaPosition); } @@ -197,7 +197,7 @@ void CWorldEditor::SetArea(CWorld *pWorld, CGameArea *pArea) ui->ActionEditPoiToWorldMap->setEnabled(AllowEGMC); // Set up sidebar tabs - CMasterTemplate *pMaster = CMasterTemplate::GetMasterForGame(mpArea->Version()); + CMasterTemplate *pMaster = CMasterTemplate::MasterForGame(mpArea->Version()); ui->CreateTabContents->SetMaster(pMaster); ui->InstancesTabContents->SetMaster(pMaster); @@ -205,13 +205,13 @@ void CWorldEditor::SetArea(CWorld *pWorld, CGameArea *pArea) mpLinkDialog->SetMaster(pMaster); // Set window title - CStringTable *pWorldNameTable = mpWorld->GetWorldName(); - TWideString WorldName = pWorldNameTable ? pWorldNameTable->GetString("ENGL", 0) : "[Untitled World]"; + CStringTable *pWorldNameTable = mpWorld->WorldName(); + TWideString WorldName = pWorldNameTable ? pWorldNameTable->String("ENGL", 0) : "[Untitled World]"; if (CurrentGame() < eReturns) { - CStringTable *pAreaNameTable = mpWorld->GetAreaName(mpArea->WorldIndex()); - TWideString AreaName = pAreaNameTable ? pAreaNameTable->GetString("ENGL", 0) : (TWideString("!") + mpWorld->GetAreaInternalName(mpArea->WorldIndex()).ToUTF16()); + CStringTable *pAreaNameTable = mpWorld->AreaName(mpArea->WorldIndex()); + TWideString AreaName = pAreaNameTable ? pAreaNameTable->String("ENGL", 0) : (TWideString("!") + mpWorld->AreaInternalName(mpArea->WorldIndex()).ToUTF16()); if (AreaName.IsEmpty()) AreaName = "[Untitled Area]"; @@ -224,7 +224,7 @@ void CWorldEditor::SetArea(CWorld *pWorld, CGameArea *pArea) { QString LevelName; if (pWorldNameTable) LevelName = TO_QSTRING(WorldName); - else LevelName = "!" + TO_QSTRING(mpWorld->GetAreaInternalName(mpArea->WorldIndex())); + else LevelName = "!" + TO_QSTRING(mpWorld->AreaInternalName(mpArea->WorldIndex())); setWindowTitle(QString("Prime World Editor - %1[*]").arg(LevelName)); Log::Write("Loaded level: World " + mpWorld->Source() + " / Area " + mpArea->Source() + " (" + TO_TSTRING(LevelName) + ")"); @@ -385,7 +385,7 @@ void CWorldEditor::OnLinksModified(const QList& rkInstances) { foreach (CScriptObject *pInstance, rkInstances) { - CScriptNode *pNode = mScene.NodeForObject(pInstance); + CScriptNode *pNode = mScene.NodeForInstance(pInstance); pNode->LinksModified(); } @@ -403,7 +403,7 @@ void CWorldEditor::OnPropertyModified(IProperty *pProp) pScript->PropertyModified(pProp); // Check editor property - if (pScript->Object()->IsEditorProperty(pProp)) + if (pScript->Instance()->IsEditorProperty(pProp)) EditorProperty = true; // If this is an editor property, update other parts of the UI to reflect the new value. @@ -425,7 +425,7 @@ void CWorldEditor::OnPropertyModified(IProperty *pProp) SelectionModified(); // Emit signal so other widgets can react to the property change - emit PropertyModified(pScript->Object(), pProp); + emit PropertyModified(pScript->Instance(), pProp); } } @@ -439,7 +439,7 @@ void CWorldEditor::SetSelectionActive(bool Active) if (It->NodeType() == eScriptNode) { CScriptNode *pScript = static_cast(*It); - CScriptObject *pInst = pScript->Object(); + CScriptObject *pInst = pScript->Instance(); IProperty *pActive = pInst->ActiveProperty(); if (pActive) @@ -470,7 +470,7 @@ void CWorldEditor::SetSelectionInstanceNames(const QString& rkNewName, bool IsDo if (mpSelection->Size() == 1 && mpSelection->Front()->NodeType() == eScriptNode) { CScriptNode *pNode = static_cast(mpSelection->Front()); - CScriptObject *pInst = pNode->Object(); + CScriptObject *pInst = pNode->Instance(); IProperty *pName = pInst->InstanceNameProperty(); if (pName) @@ -531,7 +531,7 @@ void CWorldEditor::UpdateGizmoUI() // Update transform XYZ spin boxes if (!ui->TransformSpinBox->IsBeingEdited()) { - CVector3f spinBoxValue = CVector3f::skZero; + CVector3f SpinBoxValue = CVector3f::skZero; // If the gizmo is transforming, use the total transform amount // Otherwise, use the first selected node transform, or 0 if no selection @@ -541,30 +541,30 @@ void CWorldEditor::UpdateGizmoUI() { case CGizmo::eTranslate: if (mGizmoTransforming && mGizmo.HasTransformed()) - spinBoxValue = mGizmo.TotalTranslation(); + SpinBoxValue = mGizmo.TotalTranslation(); else if (!mpSelection->IsEmpty()) - spinBoxValue = mpSelection->Front()->AbsolutePosition(); + SpinBoxValue = mpSelection->Front()->AbsolutePosition(); break; case CGizmo::eRotate: if (mGizmoTransforming && mGizmo.HasTransformed()) - spinBoxValue = mGizmo.TotalRotation(); + SpinBoxValue = mGizmo.TotalRotation(); else if (!mpSelection->IsEmpty()) - spinBoxValue = mpSelection->Front()->AbsoluteRotation().ToEuler(); + SpinBoxValue = mpSelection->Front()->AbsoluteRotation().ToEuler(); break; case CGizmo::eScale: if (mGizmoTransforming && mGizmo.HasTransformed()) - spinBoxValue = mGizmo.TotalScale(); + SpinBoxValue = mGizmo.TotalScale(); else if (!mpSelection->IsEmpty()) - spinBoxValue = mpSelection->Front()->AbsoluteScale(); + SpinBoxValue = mpSelection->Front()->AbsoluteScale(); break; } } - else if (!mpSelection->IsEmpty()) spinBoxValue = mpSelection->Front()->AbsolutePosition(); + else if (!mpSelection->IsEmpty()) SpinBoxValue = mpSelection->Front()->AbsolutePosition(); ui->TransformSpinBox->blockSignals(true); - ui->TransformSpinBox->SetValue(spinBoxValue); + ui->TransformSpinBox->SetValue(SpinBoxValue); ui->TransformSpinBox->blockSignals(false); } @@ -620,8 +620,8 @@ void CWorldEditor::UpdateNewLinkLine() // Check if there is a sender+receiver if (mpLinkDialog->isVisible() && mpLinkDialog->Sender() && mpLinkDialog->Receiver() && !mpLinkDialog->IsPicking()) { - CVector3f Start = mScene.NodeForObject(mpLinkDialog->Sender())->CenterPoint(); - CVector3f End = mScene.NodeForObject(mpLinkDialog->Receiver())->CenterPoint(); + CVector3f Start = mScene.NodeForInstance(mpLinkDialog->Sender())->CenterPoint(); + CVector3f End = mScene.NodeForInstance(mpLinkDialog->Receiver())->CenterPoint(); ui->MainViewport->SetLinkLineEnabled(true); ui->MainViewport->SetLinkLine(Start, End); } @@ -642,7 +642,7 @@ void CWorldEditor::UpdateNewLinkLine() else if (mIsMakingLink && mpNewLinkSender) pSender = mpNewLinkSender; else if (ui->ModifyTabContents->IsPicking() && ui->ModifyTabContents->EditNode()->NodeType() == eScriptNode) - pSender = static_cast(ui->ModifyTabContents->EditNode())->Object(); + pSender = static_cast(ui->ModifyTabContents->EditNode())->Instance(); // No sender and no receiver = no line if (!pSender && !pReceiver) @@ -652,7 +652,7 @@ void CWorldEditor::UpdateNewLinkLine() else if (pSender && pReceiver) { ui->MainViewport->SetLinkLineEnabled(true); - ui->MainViewport->SetLinkLine( mScene.NodeForObject(pSender)->CenterPoint(), mScene.NodeForObject(pReceiver)->CenterPoint() ); + ui->MainViewport->SetLinkLine( mScene.NodeForInstance(pSender)->CenterPoint(), mScene.NodeForInstance(pReceiver)->CenterPoint() ); } // Compensate for missing sender or missing receiver @@ -665,7 +665,7 @@ void CWorldEditor::UpdateNewLinkLine() CSceneNode *pHoverNode = ui->MainViewport->HoverNode(); CScriptObject *pInst = (pSender ? pSender : pReceiver); - CVector3f Start = mScene.NodeForObject(pInst)->CenterPoint(); + CVector3f Start = mScene.NodeForInstance(pInst)->CenterPoint(); CVector3f End = (pHoverNode && pHoverNode->NodeType() == eScriptNode ? pHoverNode->CenterPoint() : ui->MainViewport->HoverPoint()); ui->MainViewport->SetLinkLineEnabled(true); ui->MainViewport->SetLinkLine(Start, End); @@ -728,12 +728,12 @@ void CWorldEditor::OnLinkClick(const SRayIntersection& rkIntersect) { if (!mpNewLinkSender) { - mpNewLinkSender = static_cast(rkIntersect.pNode)->Object(); + mpNewLinkSender = static_cast(rkIntersect.pNode)->Instance(); } else { - mpNewLinkReceiver = static_cast(rkIntersect.pNode)->Object(); + mpNewLinkReceiver = static_cast(rkIntersect.pNode)->Instance(); mpLinkDialog->NewLink(mpNewLinkSender, mpNewLinkReceiver); mpLinkDialog->show(); ExitPickMode(); @@ -773,7 +773,7 @@ void CWorldEditor::OnUnlinkClicked() foreach (CScriptNode *pNode, SelectedScriptNodes) { - CScriptObject *pInst = pNode->Object(); + CScriptObject *pInst = pNode->Instance(); if (UnlinkIncoming) { @@ -891,17 +891,17 @@ void CWorldEditor::UpdateCameraOrbit() pCamera->SetOrbit(mpArea->AABox(), 1.5f); } -void CWorldEditor::OnCameraSpeedChange(double speed) +void CWorldEditor::OnCameraSpeedChange(double Speed) { static const double skDefaultSpeed = 1.0; - ui->MainViewport->Camera().SetMoveSpeed(skDefaultSpeed * speed); + ui->MainViewport->Camera().SetMoveSpeed(skDefaultSpeed * Speed); ui->CamSpeedSpinBox->blockSignals(true); - ui->CamSpeedSpinBox->setValue(speed); + ui->CamSpeedSpinBox->setValue(Speed); ui->CamSpeedSpinBox->blockSignals(false); } -void CWorldEditor::OnTransformSpinBoxModified(CVector3f value) +void CWorldEditor::OnTransformSpinBoxModified(CVector3f Value) { if (mpSelection->IsEmpty()) return; @@ -910,22 +910,22 @@ void CWorldEditor::OnTransformSpinBoxModified(CVector3f value) // Use absolute position/rotation, but relative scale. (This way spinbox doesn't show preview multiplier) case CGizmo::eTranslate: { - CVector3f delta = value - mpSelection->Front()->AbsolutePosition(); - mUndoStack.push(new CTranslateNodeCommand(this, mpSelection->SelectedNodeList(), delta, mTranslateSpace)); + CVector3f Delta = Value - mpSelection->Front()->AbsolutePosition(); + mUndoStack.push(new CTranslateNodeCommand(this, mpSelection->SelectedNodeList(), Delta, mTranslateSpace)); break; } case CGizmo::eRotate: { - CQuaternion delta = CQuaternion::FromEuler(value) * mpSelection->Front()->AbsoluteRotation().Inverse(); - mUndoStack.push(new CRotateNodeCommand(this, mpSelection->SelectedNodeList(), CVector3f::skZero, delta, mRotateSpace)); + CQuaternion Delta = CQuaternion::FromEuler(Value) * mpSelection->Front()->AbsoluteRotation().Inverse(); + mUndoStack.push(new CRotateNodeCommand(this, mpSelection->SelectedNodeList(), CVector3f::skZero, Delta, mRotateSpace)); break; } case CGizmo::eScale: { - CVector3f delta = value / mpSelection->Front()->AbsoluteScale(); - mUndoStack.push(new CScaleNodeCommand(this, mpSelection->SelectedNodeList(), CVector3f::skZero, delta)); + CVector3f Delta = Value / mpSelection->Front()->AbsoluteScale(); + mUndoStack.push(new CScaleNodeCommand(this, mpSelection->SelectedNodeList(), CVector3f::skZero, Delta)); break; } } diff --git a/src/Editor/WorldEditor/CWorldEditor.h b/src/Editor/WorldEditor/CWorldEditor.h index 837086b1..3e3f9c9b 100644 --- a/src/Editor/WorldEditor/CWorldEditor.h +++ b/src/Editor/WorldEditor/CWorldEditor.h @@ -58,9 +58,9 @@ public: bool CheckUnsavedChanges(); bool HasAnyScriptNodesSelected() const; - inline CGameArea* ActiveArea() const { return mpArea; } - inline EGame CurrentGame() const { return mpArea ? mpArea->Version() : eUnknownVersion; } - inline CLinkDialog* LinkDialog() const { return mpLinkDialog; } + inline CGameArea* ActiveArea() const { return mpArea; } + inline EGame CurrentGame() const { return mpArea ? mpArea->Version() : eUnknownVersion; } + inline CLinkDialog* LinkDialog() const { return mpLinkDialog; } CSceneViewport* Viewport() const; inline void SetWorldDir(QString WorldDir) { mWorldDir = (QDir(WorldDir).exists() ? WorldDir : ""); } @@ -91,7 +91,7 @@ public slots: void UpdateNewLinkLine(); protected: - void GizmoModeChanged(CGizmo::EGizmoMode mode); + void GizmoModeChanged(CGizmo::EGizmoMode Mode); private slots: void OnClipboardDataModified(); @@ -107,9 +107,9 @@ private slots: void OnPickModeExit(); void RefreshViewport(); void UpdateCameraOrbit(); - void OnCameraSpeedChange(double speed); - void OnTransformSpinBoxModified(CVector3f value); - void OnTransformSpinBoxEdited(CVector3f value); + void OnCameraSpeedChange(double Speed); + void OnTransformSpinBoxModified(CVector3f Value); + void OnTransformSpinBoxEdited(CVector3f Value); void OnClosePoiEditDialog(); void on_ActionDrawWorld_triggered(); void on_ActionDrawCollision_triggered(); diff --git a/src/Editor/WorldEditor/WCreateTab.cpp b/src/Editor/WorldEditor/WCreateTab.cpp index c8c042ca..19c651d7 100644 --- a/src/Editor/WorldEditor/WCreateTab.cpp +++ b/src/Editor/WorldEditor/WCreateTab.cpp @@ -72,8 +72,8 @@ void WCreateTab::OnLayersChanged() ui->SpawnLayerComboBox->blockSignals(true); ui->SpawnLayerComboBox->clear(); - for (u32 iLyr = 0; iLyr < pArea->GetScriptLayerCount(); iLyr++) - ui->SpawnLayerComboBox->addItem(TO_QSTRING(pArea->GetScriptLayer(iLyr)->Name())); + for (u32 iLyr = 0; iLyr < pArea->NumScriptLayers(); iLyr++) + ui->SpawnLayerComboBox->addItem(TO_QSTRING(pArea->ScriptLayer(iLyr)->Name())); ui->SpawnLayerComboBox->setCurrentIndex(0); ui->SpawnLayerComboBox->blockSignals(false); @@ -84,5 +84,5 @@ void WCreateTab::OnLayersChanged() void WCreateTab::OnSpawnLayerChanged(int LayerIndex) { CGameArea *pArea = mpEditor->ActiveArea(); - mpSpawnLayer = pArea->GetScriptLayer(LayerIndex); + mpSpawnLayer = pArea->ScriptLayer(LayerIndex); } diff --git a/src/Editor/WorldEditor/WEditorProperties.cpp b/src/Editor/WorldEditor/WEditorProperties.cpp index e0e0776b..38859787 100644 --- a/src/Editor/WorldEditor/WEditorProperties.cpp +++ b/src/Editor/WorldEditor/WEditorProperties.cpp @@ -77,10 +77,10 @@ void WEditorProperties::SetLayerComboBox() if (mpDisplayNode && mpDisplayNode->NodeType() == eScriptNode) { CScriptNode *pScript = static_cast(mpDisplayNode); - CScriptLayer *pLayer = pScript->Object()->Layer(); - for (u32 iLyr = 0; iLyr < mpEditor->ActiveArea()->GetScriptLayerCount(); iLyr++) + CScriptLayer *pLayer = pScript->Instance()->Layer(); + for (u32 iLyr = 0; iLyr < mpEditor->ActiveArea()->NumScriptLayers(); iLyr++) { - if (mpEditor->ActiveArea()->GetScriptLayer(iLyr) == pLayer) + if (mpEditor->ActiveArea()->ScriptLayer(iLyr) == pLayer) { mpLayersComboBox->setCurrentIndex(iLyr); break; @@ -129,7 +129,7 @@ void WEditorProperties::OnSelectionModified() else { CScriptNode *pScript = static_cast(mpDisplayNode); - TString InstanceID = TString::HexString(pScript->Object()->InstanceID(), false, true, 8); + TString InstanceID = TString::HexString(pScript->Instance()->InstanceID(), 8, false); TString ObjectType = pScript->Template()->Name(); mpInstanceInfoLabel->setText(QString("[%1] [%2]").arg( TO_QSTRING(ObjectType) ).arg( TO_QSTRING(InstanceID) )); @@ -161,8 +161,8 @@ void WEditorProperties::OnLayersModified() if (pArea) { - for (u32 iLyr = 0; iLyr < pArea->GetScriptLayerCount(); iLyr++) - mpLayersComboBox->addItem(TO_QSTRING(pArea->GetScriptLayer(iLyr)->Name())); + for (u32 iLyr = 0; iLyr < pArea->NumScriptLayers(); iLyr++) + mpLayersComboBox->addItem(TO_QSTRING(pArea->ScriptLayer(iLyr)->Name())); } SetLayerComboBox(); @@ -171,7 +171,7 @@ void WEditorProperties::OnLayersModified() void WEditorProperties::UpdatePropertyValues() { CScriptNode *pScript = static_cast(mpDisplayNode); - CScriptObject *pInst = pScript->Object(); + CScriptObject *pInst = pScript->Instance(); mpActiveCheckBox->setChecked(pInst->IsActive()); mpActiveCheckBox->setEnabled(pInst->ActiveProperty() != nullptr); @@ -210,7 +210,7 @@ void WEditorProperties::OnLayerChanged() if (Index >= 0) { - CScriptLayer *pLayer = mpEditor->ActiveArea()->GetScriptLayer(Index); + CScriptLayer *pLayer = mpEditor->ActiveArea()->ScriptLayer(Index); mpEditor->SetSelectionLayer(pLayer); } } diff --git a/src/Editor/WorldEditor/WInstancesTab.cpp b/src/Editor/WorldEditor/WInstancesTab.cpp index 200975f0..4858b49a 100644 --- a/src/Editor/WorldEditor/WInstancesTab.cpp +++ b/src/Editor/WorldEditor/WInstancesTab.cpp @@ -108,7 +108,7 @@ void WInstancesTab::OnTreeClick(QModelIndex Index) if (pObj) { - CScriptNode *pNode = mpScene->NodeForObject(pObj); + CScriptNode *pNode = mpScene->NodeForInstance(pObj); if (pNode) pNode->SetVisible(!pNode->IsVisible()); @@ -147,7 +147,7 @@ void WInstancesTab::OnTreeDoubleClick(QModelIndex Index) if (NodeType == CInstancesModel::eScriptType) { - CSceneNode *pSelectedNode = mpScene->NodeForObject( static_cast(SourceIndex.internalPointer()) ); + CSceneNode *pSelectedNode = mpScene->NodeForInstance( static_cast(SourceIndex.internalPointer()) ); mpEditor->ClearAndSelectNode(pSelectedNode); } } @@ -182,7 +182,7 @@ void WInstancesTab::OnTreeContextMenu(QPoint Pos) else if (mMenuIndexType == CInstancesModel::eInstanceIndex) { pObject = ( IsLayers ? mpLayersModel->IndexObject(mMenuIndex) : mpTypesModel->IndexObject(mMenuIndex) ); - mpMenuObject = mpScene->NodeForObject(pObject); + mpMenuObject = mpScene->NodeForInstance(pObject); if (IsLayers) mpMenuLayer = pObject->Layer(); @@ -302,9 +302,9 @@ void WInstancesTab::OnHideAllExceptTypeAction() { CGameArea *pArea = mpEditor->ActiveArea(); - for (u32 iLyr = 0; iLyr < pArea->GetScriptLayerCount(); iLyr++) + for (u32 iLyr = 0; iLyr < pArea->NumScriptLayers(); iLyr++) { - CScriptLayer *pLayer = pArea->GetScriptLayer(iLyr); + CScriptLayer *pLayer = pArea->ScriptLayer(iLyr); pLayer->SetVisible( pLayer == mpMenuLayer ? true : false ); } @@ -314,7 +314,7 @@ void WInstancesTab::OnHideAllExceptTypeAction() else { EGame Game = mpEditor->ActiveArea()->Version(); - CMasterTemplate *pMaster = CMasterTemplate::GetMasterForGame(Game); + CMasterTemplate *pMaster = CMasterTemplate::MasterForGame(Game); for (u32 iTemp = 0; iTemp < pMaster->NumScriptTemplates(); iTemp++) { @@ -336,8 +336,8 @@ void WInstancesTab::OnUnhideAllTypes() { CGameArea *pArea = mpEditor->ActiveArea(); - for (u32 iLyr = 0; iLyr < pArea->GetScriptLayerCount(); iLyr++) - pArea->GetScriptLayer(iLyr)->SetVisible(true); + for (u32 iLyr = 0; iLyr < pArea->NumScriptLayers(); iLyr++) + pArea->ScriptLayer(iLyr)->SetVisible(true); mpLayersModel->dataChanged( mpLayersModel->index(0, 2, TypeParent), mpLayersModel->index(mpLayersModel->rowCount(TypeParent) - 1, 2, TypeParent) ); } @@ -345,7 +345,7 @@ void WInstancesTab::OnUnhideAllTypes() else { EGame Game = mpEditor->ActiveArea()->Version(); - CMasterTemplate *pMaster = CMasterTemplate::GetMasterForGame(Game); + CMasterTemplate *pMaster = CMasterTemplate::MasterForGame(Game); for (u32 iTemp = 0; iTemp < pMaster->NumScriptTemplates(); iTemp++) pMaster->TemplateByIndex(iTemp)->SetVisible(true); @@ -367,8 +367,8 @@ void WInstancesTab::OnUnhideAll() { CGameArea *pArea = mpEditor->ActiveArea(); - for (u32 iLyr = 0; iLyr < pArea->GetScriptLayerCount(); iLyr++) - pArea->GetScriptLayer(iLyr)->SetVisible(true); + for (u32 iLyr = 0; iLyr < pArea->NumScriptLayers(); iLyr++) + pArea->ScriptLayer(iLyr)->SetVisible(true); mpLayersModel->dataChanged( mpLayersModel->index(0, 2, LayersRoot), mpLayersModel->index(mpLayersModel->rowCount(LayersRoot) - 1, 2, LayersRoot) ); } @@ -379,7 +379,7 @@ void WInstancesTab::OnUnhideAll() if (TypesRoot.isValid()) { EGame Game = mpEditor->ActiveArea()->Version(); - CMasterTemplate *pMaster = CMasterTemplate::GetMasterForGame(Game); + CMasterTemplate *pMaster = CMasterTemplate::MasterForGame(Game); for (u32 iTemp = 0; iTemp < pMaster->NumScriptTemplates(); iTemp++) pMaster->TemplateByIndex(iTemp)->SetVisible(true); diff --git a/src/Editor/WorldEditor/WModifyTab.cpp b/src/Editor/WorldEditor/WModifyTab.cpp index 5f3460f1..a993418e 100644 --- a/src/Editor/WorldEditor/WModifyTab.cpp +++ b/src/Editor/WorldEditor/WModifyTab.cpp @@ -92,7 +92,7 @@ void WModifyTab::GenerateUI() { ui->ObjectsTabWidget->show(); CScriptNode *pScriptNode = static_cast(mpSelectedNode); - CScriptObject *pObj = pScriptNode->Object(); + CScriptObject *pObj = pScriptNode->Instance(); // Set up UI ui->PropertyView->SetInstance(pObj); @@ -114,7 +114,7 @@ void WModifyTab::OnInstanceLinksModified(const QList& rkInstance { if (mpSelectedNode && mpSelectedNode->NodeType() == eScriptNode) { - CScriptObject *pInstance = static_cast(mpSelectedNode)->Object(); + CScriptObject *pInstance = static_cast(mpSelectedNode)->Instance(); if (pInstance && rkInstances.contains(pInstance)) { @@ -173,7 +173,7 @@ void WModifyTab::OnAddLinkActionClicked(QAction *pAction) if (pTarget) { CLinkDialog *pLinkDialog = mpWorldEditor->LinkDialog(); - CScriptObject *pSelected = static_cast(mpSelectedNode)->Object(); + CScriptObject *pSelected = static_cast(mpSelectedNode)->Instance(); CScriptObject *pSender = (mAddLinkType == eOutgoing ? pSelected : pTarget); CScriptObject *pReceiver = (mAddLinkType == eOutgoing ? pTarget : pSelected); @@ -187,12 +187,12 @@ void WModifyTab::OnAddLinkActionClicked(QAction *pAction) void WModifyTab::OnPickModeClick(const SRayIntersection& rkIntersect) { mpWorldEditor->ExitPickMode(); - CScriptObject *pTarget = static_cast(rkIntersect.pNode)->Object(); + CScriptObject *pTarget = static_cast(rkIntersect.pNode)->Instance(); if (pTarget) { CLinkDialog *pDialog = mpWorldEditor->LinkDialog(); - CScriptObject *pSelected = static_cast(mpSelectedNode)->Object(); + CScriptObject *pSelected = static_cast(mpSelectedNode)->Instance(); CScriptObject *pSender = (mAddLinkType == eOutgoing ? pSelected : pTarget); CScriptObject *pReceiver = (mAddLinkType == eOutgoing ? pTarget : pSelected); @@ -222,7 +222,7 @@ void WModifyTab::OnDeleteLinksClicked() for (int iIdx = 0; iIdx < SelectedIndices.size(); iIdx++) Indices << SelectedIndices[iIdx].row(); - CScriptObject *pInst = static_cast(mpSelectedNode)->Object(); + CScriptObject *pInst = static_cast(mpSelectedNode)->Instance(); CDeleteLinksCommand *pCmd = new CDeleteLinksCommand(mpWorldEditor, pInst, Type, Indices); mpWorldEditor->UndoStack()->push(pCmd); } @@ -238,7 +238,7 @@ void WModifyTab::OnEditLinkClicked() if (SelectedIndices.size() == 1) { - CScriptObject *pInst = static_cast(mpSelectedNode)->Object(); + CScriptObject *pInst = static_cast(mpSelectedNode)->Instance(); CLinkDialog *pDialog = mpWorldEditor->LinkDialog(); pDialog->EditLink(pInst->Link(Type, SelectedIndices.front().row())); pDialog->show(); @@ -256,9 +256,9 @@ void WModifyTab::OnLinkTableDoubleClick(QModelIndex Index) u32 InstanceID; if (sender() == ui->InLinksTableView) - InstanceID = pNode->Object()->Link(eIncoming, Index.row())->SenderID(); + InstanceID = pNode->Instance()->Link(eIncoming, Index.row())->SenderID(); else if (sender() == ui->OutLinksTableView) - InstanceID = pNode->Object()->Link(eOutgoing, Index.row())->ReceiverID(); + InstanceID = pNode->Instance()->Link(eOutgoing, Index.row())->ReceiverID(); CScriptNode *pLinkedNode = pNode->Scene()->NodeForInstanceID(InstanceID); diff --git a/src/Editor/main.cpp b/src/Editor/main.cpp index 420b4190..14c1d475 100644 --- a/src/Editor/main.cpp +++ b/src/Editor/main.cpp @@ -1,5 +1,4 @@ #include "CStartWindow.h" -#include "CDarkStyle.h" #include #include @@ -24,8 +23,8 @@ int main(int argc, char *argv[]) { // Create application QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts); - QApplication app(argc, argv); - app.setWindowIcon(QIcon(":/icons/AppIcon.ico")); + QApplication App(argc, argv); + App.setWindowIcon(QIcon(":/icons/AppIcon.ico")); // Init log bool Initialized = Log::InitLog("primeworldeditor.log"); @@ -35,31 +34,27 @@ int main(int argc, char *argv[]) // Load templates CTemplateLoader::LoadGameList(); - // Set up dark style - app.setStyle(new CDarkStyle); + // Set up dark theme qApp->setStyle(QStyleFactory::create("Fusion")); - - QPalette darkPalette; - darkPalette.setColor(QPalette::Window, QColor(53,53,53)); - darkPalette.setColor(QPalette::WindowText, Qt::white); - darkPalette.setColor(QPalette::Base, QColor(25,25,25)); - darkPalette.setColor(QPalette::AlternateBase, QColor(35,35,35)); - darkPalette.setColor(QPalette::ToolTipBase, Qt::white); - darkPalette.setColor(QPalette::ToolTipText, Qt::white); - darkPalette.setColor(QPalette::Text, Qt::white); - darkPalette.setColor(QPalette::Button, QColor(53,53,53)); - darkPalette.setColor(QPalette::ButtonText, Qt::white); - darkPalette.setColor(QPalette::BrightText, Qt::red); - darkPalette.setColor(QPalette::Link, QColor(42, 130, 218)); - - darkPalette.setColor(QPalette::Highlight, QColor(42, 130, 218)); - darkPalette.setColor(QPalette::HighlightedText, Qt::white); - - qApp->setPalette(darkPalette); + QPalette DarkPalette; + DarkPalette.setColor(QPalette::Window, QColor(53,53,53)); + DarkPalette.setColor(QPalette::WindowText, Qt::white); + DarkPalette.setColor(QPalette::Base, QColor(25,25,25)); + DarkPalette.setColor(QPalette::AlternateBase, QColor(35,35,35)); + DarkPalette.setColor(QPalette::ToolTipBase, Qt::white); + DarkPalette.setColor(QPalette::ToolTipText, Qt::white); + DarkPalette.setColor(QPalette::Text, Qt::white); + DarkPalette.setColor(QPalette::Button, QColor(53,53,53)); + DarkPalette.setColor(QPalette::ButtonText, Qt::white); + DarkPalette.setColor(QPalette::BrightText, Qt::red); + DarkPalette.setColor(QPalette::Link, QColor(42, 130, 218)); + DarkPalette.setColor(QPalette::Highlight, QColor(42, 130, 218)); + DarkPalette.setColor(QPalette::HighlightedText, Qt::white); + qApp->setPalette(DarkPalette); // Execute application - CStartWindow w; - w.show(); + CStartWindow StartWindow; + StartWindow.show(); - return app.exec(); + return App.exec(); } diff --git a/src/FileIO/CFileInStream.cpp b/src/FileIO/CFileInStream.cpp index 0dbcd6fc..5069ac0c 100644 --- a/src/FileIO/CFileInStream.cpp +++ b/src/FileIO/CFileInStream.cpp @@ -1,25 +1,25 @@ #include "CFileInStream.h" CFileInStream::CFileInStream() + : mpFStream(nullptr) { - mpFStream = nullptr; } CFileInStream::CFileInStream(const std::string& rkFile) + : mpFStream(nullptr) { - mpFStream = nullptr; Open(rkFile, IOUtil::eBigEndian); } CFileInStream::CFileInStream(const std::string& rkFile, IOUtil::EEndianness FileEndianness) + : mpFStream(nullptr) { - mpFStream = nullptr; Open(rkFile, FileEndianness); } CFileInStream::CFileInStream(const CFileInStream& rkSrc) + : mpFStream(nullptr) { - mpFStream = nullptr; Open(rkSrc.mName, rkSrc.mDataEndianness); if (rkSrc.IsValid()) diff --git a/src/FileIO/CFileInStream.h b/src/FileIO/CFileInStream.h index bbf9ceb3..20db4bd1 100644 --- a/src/FileIO/CFileInStream.h +++ b/src/FileIO/CFileInStream.h @@ -20,9 +20,9 @@ public: void Open(const std::string& rkFile, IOUtil::EEndianness FileEndianness); void Close(); - void ReadBytes(void *pDst, unsigned long count); - bool Seek(long offset, long origin); - bool Seek64(long long offset, long origin); + void ReadBytes(void *pDst, unsigned long Count); + bool Seek(long Offset, long Origin); + bool Seek64(long long Offset, long Origin); long Tell() const; long long Tell64() const; bool EoF() const; diff --git a/src/FileIO/CFileOutStream.cpp b/src/FileIO/CFileOutStream.cpp index 9d009490..e1b4fc2f 100644 --- a/src/FileIO/CFileOutStream.cpp +++ b/src/FileIO/CFileOutStream.cpp @@ -1,26 +1,26 @@ #include "CFileOutStream.h" CFileOutStream::CFileOutStream() + : mpFStream(nullptr) + , mSize(0) { - mpFStream = nullptr; - mSize = 0; } CFileOutStream::CFileOutStream(const std::string& rkFile) + : mpFStream(nullptr) { - mpFStream = nullptr; Open(rkFile, IOUtil::eBigEndian); } CFileOutStream::CFileOutStream(const std::string& rkFile, IOUtil::EEndianness FileEndianness) + : mpFStream(nullptr) { - mpFStream = nullptr; Open(rkFile, FileEndianness); } CFileOutStream::CFileOutStream(const CFileOutStream& rkSrc) + : mpFStream(nullptr) { - mpFStream = nullptr; Open(rkSrc.mName, rkSrc.mDataEndianness); if (rkSrc.IsValid()) diff --git a/src/FileIO/CFileOutStream.h b/src/FileIO/CFileOutStream.h index 6226b8fd..2b407d6f 100644 --- a/src/FileIO/CFileOutStream.h +++ b/src/FileIO/CFileOutStream.h @@ -21,9 +21,9 @@ public: void Update(const std::string& rkFile, IOUtil::EEndianness FileEndianness); void Close(); - void WriteBytes(void *pSrc, unsigned long count); - bool Seek(long offset, long origin); - bool Seek64(long long offset, long origin); + void WriteBytes(void *pSrc, unsigned long Count); + bool Seek(long Offset, long Origin); + bool Seek64(long long Offset, long Origin); long Tell() const; long long Tell64() const; bool EoF() const; diff --git a/src/FileIO/CMemoryInStream.cpp b/src/FileIO/CMemoryInStream.cpp index 0a2a2362..399cd6b5 100644 --- a/src/FileIO/CMemoryInStream.cpp +++ b/src/FileIO/CMemoryInStream.cpp @@ -1,10 +1,10 @@ #include "CMemoryInStream.h" CMemoryInStream::CMemoryInStream() + : mpDataStart(nullptr) + , mDataSize(0) + , mPos(0) { - mpDataStart = nullptr; - mDataSize = 0; - mPos = 0; } CMemoryInStream::CMemoryInStream(const void *pData, unsigned long Size, IOUtil::EEndianness DataEndianness) { @@ -51,12 +51,14 @@ bool CMemoryInStream::Seek(long Offset, long Origin) return false; } - if (mPos < 0) { + if (mPos < 0) + { mPos = 0; return false; } - if (mPos > mDataSize) { + if (mPos > mDataSize) + { mPos = mDataSize; return false; } diff --git a/src/FileIO/CMemoryInStream.h b/src/FileIO/CMemoryInStream.h index f0491725..499f5d3a 100644 --- a/src/FileIO/CMemoryInStream.h +++ b/src/FileIO/CMemoryInStream.h @@ -17,7 +17,7 @@ public: void SetData(const void *pData, unsigned long Size, IOUtil::EEndianness dataEndianness); void ReadBytes(void *pDst, unsigned long Count); - bool Seek(long offset, long Origin); + bool Seek(long Offset, long Origin); long Tell() const; bool EoF() const; bool IsValid() const; diff --git a/src/FileIO/CMemoryOutStream.cpp b/src/FileIO/CMemoryOutStream.cpp index 2f4e03e8..ea76708b 100644 --- a/src/FileIO/CMemoryOutStream.cpp +++ b/src/FileIO/CMemoryOutStream.cpp @@ -1,11 +1,11 @@ #include "CMemoryOutStream.h" CMemoryOutStream::CMemoryOutStream() + : mpDataStart(nullptr) + , mDataSize(0) + , mPos(0) + , mUsed(0) { - mpDataStart = nullptr; - mDataSize = 0; - mPos = 0; - mUsed = 0; } CMemoryOutStream::CMemoryOutStream(void *pData, unsigned long Size, IOUtil::EEndianness DataEndianness) @@ -57,12 +57,14 @@ bool CMemoryOutStream::Seek(long Offset, long Origin) return false; } - if (mPos < 0) { + if (mPos < 0) + { mPos = 0; return false; } - if (mPos > mDataSize) { + if (mPos > mDataSize) + { mPos = mDataSize; return false; } diff --git a/src/FileIO/CMemoryOutStream.h b/src/FileIO/CMemoryOutStream.h index c40195dc..de7e7cde 100644 --- a/src/FileIO/CMemoryOutStream.h +++ b/src/FileIO/CMemoryOutStream.h @@ -16,8 +16,8 @@ public: ~CMemoryOutStream(); void SetData(void *pData, unsigned long Size, IOUtil::EEndianness mDataEndianness); - void WriteBytes(void *pSrc, unsigned long count); - bool Seek(long offset, long origin); + void WriteBytes(void *pSrc, unsigned long Count); + bool Seek(long Offset, long Origin); long Tell() const; bool EoF() const; bool IsValid() const; diff --git a/src/FileIO/CTextInStream.cpp b/src/FileIO/CTextInStream.cpp index d2a7fbdb..28d6f9b2 100644 --- a/src/FileIO/CTextInStream.cpp +++ b/src/FileIO/CTextInStream.cpp @@ -3,19 +3,19 @@ #include CTextInStream::CTextInStream() + : mpFStream(nullptr) { - mpFStream = nullptr; } CTextInStream::CTextInStream(const std::string& rkFile) + : mpFStream(nullptr) { - mpFStream = nullptr; Open(rkFile); } CTextInStream::CTextInStream(const CTextInStream& rkSrc) + : mpFStream(nullptr) { - mpFStream = nullptr; Open(rkSrc.mFileName); if (rkSrc.IsValid()) diff --git a/src/FileIO/CTextOutStream.cpp b/src/FileIO/CTextOutStream.cpp index 50bbec34..beaf132c 100644 --- a/src/FileIO/CTextOutStream.cpp +++ b/src/FileIO/CTextOutStream.cpp @@ -2,20 +2,20 @@ #include CTextOutStream::CTextOutStream() + : mpFStream(nullptr) + , mSize(0) { - mpFStream = nullptr; - mSize = 0; } CTextOutStream::CTextOutStream(const std::string& rkFile) + : mpFStream(nullptr) { - mpFStream = nullptr; Open(rkFile.c_str()); } CTextOutStream::CTextOutStream(const CTextOutStream& rkSrc) + : mpFStream(nullptr) { - mpFStream = nullptr; Open(rkSrc.mFileName); if (rkSrc.IsValid()) @@ -52,10 +52,10 @@ void CTextOutStream::Print(const char *pkFormat, ... ) vfprintf(mpFStream, pkFormat, Args); } -void CTextOutStream::WriteChar(char c) +void CTextOutStream::WriteChar(char Chr) { if (!IsValid()) return; - fputc(c, mpFStream); + fputc(Chr, mpFStream); if ((unsigned long) Tell() > mSize) mSize = Tell(); } diff --git a/src/FileIO/CTextOutStream.h b/src/FileIO/CTextOutStream.h index 395572e6..f5dbc329 100644 --- a/src/FileIO/CTextOutStream.h +++ b/src/FileIO/CTextOutStream.h @@ -14,12 +14,12 @@ public: CTextOutStream(const std::string& rkFile); CTextOutStream(const CTextOutStream& rkSrc); ~CTextOutStream(); - void Open(const std::string& file); + void Open(const std::string& rkFile); void Close(); void Print(const char *pkFormat, ... ); - void WriteChar(char c); - void WriteString(const std::string& Str); + void WriteChar(char Chr); + void WriteString(const std::string& rkStr); bool Seek(long Offset, long Origin); long Tell() const; diff --git a/src/FileIO/CVectorOutStream.cpp b/src/FileIO/CVectorOutStream.cpp index e1f82c7c..47f2a147 100644 --- a/src/FileIO/CVectorOutStream.cpp +++ b/src/FileIO/CVectorOutStream.cpp @@ -1,39 +1,39 @@ #include "CVectorOutStream.h" CVectorOutStream::CVectorOutStream() + : mpVector(new std::vector) + , mOwnsVector(true) + , mPos(0) + , mUsed(0) { mDataEndianness = IOUtil::eBigEndian; - mpVector = new std::vector; - mOwnsVector = true; - mPos = 0; - mUsed = 0; } CVectorOutStream::CVectorOutStream(IOUtil::EEndianness DataEndianness) + : mpVector(new std::vector) + , mOwnsVector(true) + , mPos(0) + , mUsed(0) { mDataEndianness = DataEndianness; - mpVector = new std::vector; - mOwnsVector = true; - mPos = 0; - mUsed = 0; } CVectorOutStream::CVectorOutStream(unsigned long InitialSize, IOUtil::EEndianness DataEndianness) + : mpVector(new std::vector(InitialSize)) + , mOwnsVector(true) + , mPos(0) + , mUsed(0) { mDataEndianness = DataEndianness; - mpVector = new std::vector(InitialSize); - mOwnsVector = true; - mPos = 0; - mUsed = 0; } CVectorOutStream::CVectorOutStream(std::vector *pVector, IOUtil::EEndianness DataEndianness) + : mpVector(pVector) + , mOwnsVector(false) + , mPos(0) + , mUsed(0) { mDataEndianness = DataEndianness; - mpVector = pVector; - mOwnsVector = false; - mPos = 0; - mUsed = 0; } CVectorOutStream::~CVectorOutStream() @@ -75,7 +75,8 @@ bool CVectorOutStream::Seek(long Offset, long Origin) return false; } - if (mPos < 0) { + if (mPos < 0) + { mPos = 0; return false; } diff --git a/src/FileIO/IInputStream.cpp b/src/FileIO/IInputStream.cpp index 9e9df496..9379acf5 100644 --- a/src/FileIO/IInputStream.cpp +++ b/src/FileIO/IInputStream.cpp @@ -54,12 +54,12 @@ double IInputStream::ReadDouble() std::string IInputStream::ReadString() { std::string Str; - char c = 1; + char Chr = 1; - while ((c != 0) && (!EoF())) + while ((Chr != 0) && (!EoF())) { - c = ReadByte(); - if (c != 0) Str.push_back(c); + Chr = ReadByte(); + if (Chr != 0) Str.push_back(Chr); } return Str; @@ -69,8 +69,8 @@ std::string IInputStream::ReadString(unsigned long Count) { std::string Str(Count, 0); - for (unsigned long c = 0; c < Count; c++) - Str[c] = ReadByte(); + for (unsigned long iChr = 0; iChr < Count; iChr++) + Str[iChr] = ReadByte(); return Str; } @@ -78,12 +78,12 @@ std::string IInputStream::ReadString(unsigned long Count) std::wstring IInputStream::ReadWString() { std::wstring WStr; - short c = 1; + short Chr = 1; - while (c != 0) + while (Chr != 0) { - c = ReadShort(); - if (c != 0) WStr.push_back(c); + Chr = ReadShort(); + if (Chr != 0) WStr.push_back(Chr); } return WStr; diff --git a/src/FileIO/IInputStream.h b/src/FileIO/IInputStream.h index 7ddde1f6..2ff87527 100644 --- a/src/FileIO/IInputStream.h +++ b/src/FileIO/IInputStream.h @@ -19,9 +19,9 @@ public: float ReadFloat(); double ReadDouble(); std::string ReadString(); - std::string ReadString(unsigned long count); + std::string ReadString(unsigned long Count); std::wstring ReadWString(); - std::wstring ReadWString(unsigned long count); + std::wstring ReadWString(unsigned long Count); char PeekByte(); short PeekShort(); @@ -30,16 +30,16 @@ public: float PeekFloat(); double PeekDouble(); - void SeekToBoundary(unsigned long boundary); - void SetEndianness(IOUtil::EEndianness endianness); + void SeekToBoundary(unsigned long Boundary); + void SetEndianness(IOUtil::EEndianness Endianness); void SetSourceString(const std::string& rkSource); IOUtil::EEndianness GetEndianness() const; std::string GetSourceString() const; virtual ~IInputStream(); - virtual void ReadBytes(void *pDst, unsigned long count) = 0; - virtual bool Seek(long offset, long origin) = 0; - virtual bool Seek64(long long offset, long origin); + virtual void ReadBytes(void *pDst, unsigned long Count) = 0; + virtual bool Seek(long Offset, long Origin) = 0; + virtual bool Seek64(long long Offset, long Origin); virtual long Tell() const = 0; virtual long long Tell64() const; virtual bool EoF() const = 0; diff --git a/src/FileIO/IOutputStream.cpp b/src/FileIO/IOutputStream.cpp index add3a9d5..0e0f4114 100644 --- a/src/FileIO/IOutputStream.cpp +++ b/src/FileIO/IOutputStream.cpp @@ -50,8 +50,8 @@ void IOutputStream::WriteString(const std::string& rkVal) void IOutputStream::WriteString(const std::string& rkVal, unsigned long Count, bool Terminate) { - for (unsigned int i = 0; i < Count; i++) - WriteByte(rkVal[i]); + for (unsigned int iChr = 0; iChr < Count; iChr++) + WriteByte(rkVal[iChr]); if (Terminate && (rkVal[Count-1] != '\0')) WriteByte(0); @@ -59,8 +59,8 @@ void IOutputStream::WriteString(const std::string& rkVal, unsigned long Count, b void IOutputStream::WriteWideString(const std::wstring& rkVal) { - for (unsigned int i = 0; i < rkVal.size(); i++) - WriteShort(rkVal[i]); + for (unsigned int iChr = 0; iChr < rkVal.size(); iChr++) + WriteShort(rkVal[iChr]); if ((!rkVal.empty()) && (rkVal.back() != '\0')) WriteShort(0); @@ -68,8 +68,8 @@ void IOutputStream::WriteWideString(const std::wstring& rkVal) void IOutputStream::WriteWideString(const std::wstring& rkVal, unsigned long Count, bool Terminate) { - for (unsigned int i = 0; i < Count; i++) - WriteShort(rkVal[i]); + for (unsigned int iChr = 0; iChr < Count; iChr++) + WriteShort(rkVal[iChr]); if (Terminate && (rkVal[Count-1] != 0)) WriteShort(0); @@ -79,7 +79,7 @@ void IOutputStream::WriteToBoundary(unsigned long Boundary, char Fill) { long Num = Boundary - (Tell() % Boundary); if (Num == Boundary) return; - for (int i = 0; i < Num; i++) + for (int iByte = 0; iByte < Num; iByte++) WriteByte(Fill); } diff --git a/src/Math/CAABox.cpp b/src/Math/CAABox.cpp index a7192005..c271e00e 100644 --- a/src/Math/CAABox.cpp +++ b/src/Math/CAABox.cpp @@ -5,27 +5,27 @@ #include CAABox::CAABox() + : mMin(CVector3f::skInfinite) + , mMax(-CVector3f::skInfinite) { - mMin = CVector3f::skInfinite; - mMax = -CVector3f::skInfinite; } -CAABox::CAABox(const CVector3f& Min, const CVector3f& Max) +CAABox::CAABox(const CVector3f& rkMin, const CVector3f& rkMax) + : mMin(rkMin) + , mMax(rkMax) { - mMin = Min; - mMax = Max; } -CAABox::CAABox(IInputStream& input) +CAABox::CAABox(IInputStream& rInput) + : mMin(rInput) + , mMax(rInput) { - mMin = CVector3f(input); - mMax = CVector3f(input); } -void CAABox::Write(IOutputStream& Output) +void CAABox::Write(IOutputStream& rOutput) { - mMin.Write(Output); - mMax.Write(Output); + mMin.Write(rOutput); + mMax.Write(rOutput); } CVector3f CAABox::Center() const @@ -48,14 +48,14 @@ CVector3f CAABox::Max() const return mMax; } -void CAABox::SetMin(const CVector3f& min) +void CAABox::SetMin(const CVector3f& rkMin) { - mMin = min; + mMin = rkMin; } -void CAABox::SetMax(const CVector3f& max) +void CAABox::SetMax(const CVector3f& rkMax) { - mMax = max; + mMax = rkMax; } bool CAABox::IsNull() const @@ -68,119 +68,119 @@ bool CAABox::IsInfinite() const return (Size() == CVector3f::skInfinite); } -void CAABox::ExpandBounds(const CVector3f& vtx) +void CAABox::ExpandBounds(const CVector3f& rkVtx) { // take an input vertex coordinate and expand the bounding box to fit it, if necessary - if (vtx.x < mMin.x) mMin.x = vtx.x; - if (vtx.x > mMax.x) mMax.x = vtx.x; - if (vtx.y < mMin.y) mMin.y = vtx.y; - if (vtx.y > mMax.y) mMax.y = vtx.y; - if (vtx.z < mMin.z) mMin.z = vtx.z; - if (vtx.z > mMax.z) mMax.z = vtx.z; + if (rkVtx.X < mMin.X) mMin.X = rkVtx.X; + if (rkVtx.X > mMax.X) mMax.X = rkVtx.X; + if (rkVtx.Y < mMin.Y) mMin.Y = rkVtx.Y; + if (rkVtx.Y > mMax.Y) mMax.Y = rkVtx.Y; + if (rkVtx.Z < mMin.Z) mMin.Z = rkVtx.Z; + if (rkVtx.Z > mMax.Z) mMax.Z = rkVtx.Z; } -void CAABox::ExpandBounds(const CAABox& AABox) +void CAABox::ExpandBounds(const CAABox& rkAABox) { - ExpandBounds(AABox.mMin); - ExpandBounds(AABox.mMax); + ExpandBounds(rkAABox.mMin); + ExpandBounds(rkAABox.mMax); } -void CAABox::ExpandBy(const CVector3f& amount) +void CAABox::ExpandBy(const CVector3f& rkAmount) { - CVector3f halfAmount = amount / 2.f; + CVector3f halfAmount = rkAmount / 2.f; mMin -= halfAmount; mMax += halfAmount; } -CAABox CAABox::Transformed(const CTransform4f& transform) const +CAABox CAABox::Transformed(const CTransform4f& rkTransform) const { CAABox AABox; - AABox.ExpandBounds(transform * CVector3f(mMin.x, mMin.y, mMin.z)); - AABox.ExpandBounds(transform * CVector3f(mMin.x, mMin.y, mMax.z)); - AABox.ExpandBounds(transform * CVector3f(mMin.x, mMax.y, mMax.z)); - AABox.ExpandBounds(transform * CVector3f(mMin.x, mMax.y, mMin.z)); - AABox.ExpandBounds(transform * CVector3f(mMax.x, mMin.y, mMin.z)); - AABox.ExpandBounds(transform * CVector3f(mMax.x, mMin.y, mMax.z)); - AABox.ExpandBounds(transform * CVector3f(mMax.x, mMax.y, mMax.z)); - AABox.ExpandBounds(transform * CVector3f(mMax.x, mMax.y, mMin.z)); + AABox.ExpandBounds(rkTransform * CVector3f(mMin.X, mMin.Y, mMin.Z)); + AABox.ExpandBounds(rkTransform * CVector3f(mMin.X, mMin.Y, mMax.Z)); + AABox.ExpandBounds(rkTransform * CVector3f(mMin.X, mMax.Y, mMax.Z)); + AABox.ExpandBounds(rkTransform * CVector3f(mMin.X, mMax.Y, mMin.Z)); + AABox.ExpandBounds(rkTransform * CVector3f(mMax.X, mMin.Y, mMin.Z)); + AABox.ExpandBounds(rkTransform * CVector3f(mMax.X, mMin.Y, mMax.Z)); + AABox.ExpandBounds(rkTransform * CVector3f(mMax.X, mMax.Y, mMax.Z)); + AABox.ExpandBounds(rkTransform * CVector3f(mMax.X, mMax.Y, mMin.Z)); return AABox; } -bool CAABox::IsPointInBox(const CVector3f& Point) const +bool CAABox::IsPointInBox(const CVector3f& rkPoint) const { - return ( ((Point.x >= mMin.x) && (Point.x <= mMax.x)) && - ((Point.y >= mMin.y) && (Point.y <= mMax.y)) && - ((Point.z >= mMin.z) && (Point.z <= mMax.z)) ); + return ( ((rkPoint.X >= mMin.X) && (rkPoint.X <= mMax.X)) && + ((rkPoint.Y >= mMin.Y) && (rkPoint.Y <= mMax.Y)) && + ((rkPoint.Z >= mMin.Z) && (rkPoint.Z <= mMax.Z)) ); } -CVector3f CAABox::ClosestPointAlongVector(const CVector3f& dir) const +CVector3f CAABox::ClosestPointAlongVector(const CVector3f& rkDir) const { CVector3f out; - out.x = (dir.x >= 0.f) ? mMin.x : mMax.x; - out.y = (dir.y >= 0.f) ? mMin.y : mMax.y; - out.z = (dir.z >= 0.f) ? mMin.z : mMax.z; + out.X = (rkDir.X >= 0.f) ? mMin.X : mMax.X; + out.Y = (rkDir.Y >= 0.f) ? mMin.Y : mMax.Y; + out.Z = (rkDir.Z >= 0.f) ? mMin.Z : mMax.Z; return out; } -CVector3f CAABox::FurthestPointAlongVector(const CVector3f& dir) const +CVector3f CAABox::FurthestPointAlongVector(const CVector3f& rkDir) const { CVector3f out; - out.x = (dir.x >= 0.f) ? mMax.x : mMin.x; - out.y = (dir.y >= 0.f) ? mMax.y : mMin.y; - out.z = (dir.z >= 0.f) ? mMax.z : mMin.z; + out.X = (rkDir.X >= 0.f) ? mMax.X : mMin.X; + out.Y = (rkDir.Y >= 0.f) ? mMax.Y : mMin.Y; + out.Z = (rkDir.Z >= 0.f) ? mMax.Z : mMin.Z; return out; } // ************ INTERSECTION TESTS ************ // These tests are kinda bad and probably inaccurate, they need rewrites -bool CAABox::IntersectsAABox(const CAABox& AABox) +bool CAABox::IntersectsAABox(const CAABox& rkAABox) { - return ((mMax > AABox.mMin) && (mMin < AABox.mMax)); + return ((mMax > rkAABox.mMin) && (mMin < rkAABox.mMax)); } -bool CAABox::IntersectsSphere(const CVector3f& SphereCenter, const float SphereRadius) +bool CAABox::IntersectsSphere(const CVector3f& rkSphereCenter, float SphereRadius) { // Placeholder for proper sphere intersection test // Generate an AABox for the sphere and do an AABox/AABox intersection test instead - return IntersectsAABox(CAABox(SphereCenter - SphereRadius, SphereCenter + SphereRadius)); + return IntersectsAABox(CAABox(rkSphereCenter - SphereRadius, rkSphereCenter + SphereRadius)); } -std::pair CAABox::IntersectsRay(const CRay &Ray) const +std::pair CAABox::IntersectsRay(const CRay& rkRay) const { - return Math::RayBoxIntersection(Ray, *this); + return Math::RayBoxIntersection(rkRay, *this); } // ************ OPERATORS ************ -CAABox CAABox::operator+(const CVector3f& translate) const +CAABox CAABox::operator+(const CVector3f& rkTranslate) const { - return CAABox(mMin + translate, mMax + translate); + return CAABox(mMin + rkTranslate, mMax + rkTranslate); } -void CAABox::operator+=(const CVector3f& translate) +void CAABox::operator+=(const CVector3f& rkTranslate) { - *this = *this + translate; + *this = *this + rkTranslate; } -CAABox CAABox::operator*(float scalar) const +CAABox CAABox::operator*(float Scalar) const { - return CAABox(mMin * scalar, mMax * scalar); + return CAABox(mMin * Scalar, mMax * Scalar); } -void CAABox::operator*=(float scalar) +void CAABox::operator*=(float Scalar) { - *this = *this * scalar; + *this = *this * Scalar; } -bool CAABox::operator==(const CAABox& Other) const +bool CAABox::operator==(const CAABox& rkOther) const { - return ((mMin == Other.mMin) && (mMax == Other.mMax)); + return ((mMin == rkOther.mMin) && (mMax == rkOther.mMax)); } -bool CAABox::operator!=(const CAABox& Other) const +bool CAABox::operator!=(const CAABox& rkOther) const { - return (!(*this == Other)); + return (!(*this == rkOther)); } // ************ CONSTANTS ************ diff --git a/src/Math/CAABox.h b/src/Math/CAABox.h index dfec056e..5bbfc56a 100644 --- a/src/Math/CAABox.h +++ b/src/Math/CAABox.h @@ -15,39 +15,39 @@ class CAABox public: CAABox(); - CAABox(const CVector3f& Min, const CVector3f& Max); - CAABox(IInputStream& input); - void Write(IOutputStream& Output); + CAABox(const CVector3f& rkMin, const CVector3f& rkMax); + CAABox(IInputStream& rInput); + void Write(IOutputStream& rOutput); CVector3f Center() const; CVector3f Size() const; CVector3f Min() const; CVector3f Max() const; - void SetMin(const CVector3f& min); - void SetMax(const CVector3f& max); + void SetMin(const CVector3f& rkMin); + void SetMax(const CVector3f& rkMax); bool IsNull() const; bool IsInfinite() const; - void ExpandBounds(const CVector3f& vtx); - void ExpandBounds(const CAABox& AABox); - void ExpandBy(const CVector3f& amount); - CAABox Transformed(const CTransform4f& transform) const; + void ExpandBounds(const CVector3f& rkVtx); + void ExpandBounds(const CAABox& rkAABox); + void ExpandBy(const CVector3f& rkAmount); + CAABox Transformed(const CTransform4f& rkTransform) const; - bool IsPointInBox(const CVector3f& Point) const; - CVector3f ClosestPointAlongVector(const CVector3f& dir) const; - CVector3f FurthestPointAlongVector(const CVector3f& dir) const; + bool IsPointInBox(const CVector3f& rkPoint) const; + CVector3f ClosestPointAlongVector(const CVector3f& rkDir) const; + CVector3f FurthestPointAlongVector(const CVector3f& rkDir) const; // Intersection Tests - bool IntersectsAABox(const CAABox& AABox); - bool IntersectsSphere(const CVector3f& SphereCenter, const float SphereRadius); - std::pair IntersectsRay(const CRay& Ray) const; + bool IntersectsAABox(const CAABox& rkAABox); + bool IntersectsSphere(const CVector3f& rkSphereCenter, float SphereRadius); + std::pair IntersectsRay(const CRay& rkRay) const; // Operators - CAABox operator+(const CVector3f& translate) const; - void operator+=(const CVector3f& translate); - CAABox operator*(float scalar) const; - void operator*=(float scalar); - bool operator==(const CAABox& Other) const; - bool operator!=(const CAABox& Other) const; + CAABox operator+(const CVector3f& rkTranslate) const; + void operator+=(const CVector3f& rkTranslate); + CAABox operator*(float Scalar) const; + void operator*=(float Scalar); + bool operator==(const CAABox& rkOther) const; + bool operator!=(const CAABox& rkOther) const; // Constants static const CAABox skInfinite; diff --git a/src/Math/CFrustumPlanes.cpp b/src/Math/CFrustumPlanes.cpp index ffe64079..1790b31e 100644 --- a/src/Math/CFrustumPlanes.cpp +++ b/src/Math/CFrustumPlanes.cpp @@ -4,95 +4,89 @@ CFrustumPlanes::CFrustumPlanes() { - } -CFrustumPlanes::~CFrustumPlanes() +const CPlane& CFrustumPlanes::GetPlane(EFrustumSide Side) const { - + return mPlanes[Side]; } -const CPlane& CFrustumPlanes::GetPlane(EFrustumSide side) const -{ - return mPlanes[side]; -} - -void CFrustumPlanes::SetPlanes(const CVector3f& position, const CVector3f& direction, float fieldOfView, float aspectRatio, float near, float far) +void CFrustumPlanes::SetPlanes(const CVector3f& rkPosition, const CVector3f& rkDirection, float FieldOfView, float AspectRatio, float Near, float Far) { // Calculate up/right vectors - CVector3f right = direction.Cross(CVector3f::skUp).Normalized(); - CVector3f up = right.Cross(direction).Normalized(); + CVector3f Right = rkDirection.Cross(CVector3f::skUp).Normalized(); + CVector3f Up = Right.Cross(rkDirection).Normalized(); // Calculate dimensions of near plane - float nearHeight = 2 * tanf(Math::DegreesToRadians(fieldOfView) / 2.f) * near; - float nearWidth = nearHeight * aspectRatio; + float NearHeight = 2 * tanf(Math::DegreesToRadians(FieldOfView) / 2.f) * Near; + float NearWidth = NearHeight * AspectRatio; // Define the planes - CVector3f nearCenter = position + (direction * near); - mPlanes[eNearPlane].Redefine(direction, nearCenter); + CVector3f NearCenter = rkPosition + (rkDirection * Near); + mPlanes[eNearPlane].Redefine(rkDirection, NearCenter); - CVector3f farCenter = position + (direction * far); - mPlanes[eFarPlane].Redefine(-direction, farCenter); + CVector3f FarCenter = rkPosition + (rkDirection * Far); + mPlanes[eFarPlane].Redefine(-rkDirection, FarCenter); - CVector3f midRight = nearCenter + (right * (nearWidth / 2.f)); - CVector3f rightNormal = up.Cross((midRight - position).Normalized()); - mPlanes[eRightPlane].Redefine(rightNormal, position); + CVector3f MidRight = NearCenter + (Right * (NearWidth / 2.f)); + CVector3f RightNormal = Up.Cross((MidRight - rkPosition).Normalized()); + mPlanes[eRightPlane].Redefine(RightNormal, rkPosition); - CVector3f midLeft = nearCenter - (right * (nearWidth / 2.f)); - CVector3f leftNormal = (midLeft - position).Normalized().Cross(up); - mPlanes[eLeftPlane].Redefine(leftNormal, position); + CVector3f MidLeft = NearCenter - (Right * (NearWidth / 2.f)); + CVector3f LeftNormal = (MidLeft - rkPosition).Normalized().Cross(Up); + mPlanes[eLeftPlane].Redefine(LeftNormal, rkPosition); - CVector3f midTop = nearCenter + (up * (nearHeight / 2.f)); - CVector3f topNormal = (midTop - position).Normalized().Cross(right); - mPlanes[eTopPlane].Redefine(topNormal, position); + CVector3f MidTop = NearCenter + (Up * (NearHeight / 2.f)); + CVector3f TopNormal = (MidTop - rkPosition).Normalized().Cross(Right); + mPlanes[eTopPlane].Redefine(TopNormal, rkPosition); - CVector3f midBottom = nearCenter - (up * (nearHeight / 2.f)); - CVector3f bottomNormal = right.Cross((midBottom - position).Normalized()); - mPlanes[eBottomPlane].Redefine(bottomNormal, position); + CVector3f MidBottom = NearCenter - (Up * (NearHeight / 2.f)); + CVector3f BottomNormal = Right.Cross((MidBottom - rkPosition).Normalized()); + mPlanes[eBottomPlane].Redefine(BottomNormal, rkPosition); } -bool CFrustumPlanes::PointInFrustum(const CVector3f& point) const +bool CFrustumPlanes::PointInFrustum(const CVector3f& rkPoint) const { for (u32 iPlane = 0; iPlane < 6; iPlane++) { - const CPlane& plane = mPlanes[iPlane]; + const CPlane& rkPlane = mPlanes[iPlane]; - if (plane.Normal().Dot(point) + plane.Dist() < 0.f) + if (rkPlane.Normal().Dot(rkPoint) + rkPlane.Dist() < 0.f) return false; } return true; } -bool CFrustumPlanes::BoxInFrustum(const CAABox& box) const +bool CFrustumPlanes::BoxInFrustum(const CAABox& rkBox) const { - CVector3f min = box.Min(); - CVector3f max = box.Max(); + CVector3f Min = rkBox.Min(); + CVector3f Max = rkBox.Max(); - CVector3f points[8]; - points[0] = min; - points[1] = max; - points[2] = CVector3f(min.x, min.y, max.z); - points[3] = CVector3f(min.x, max.y, min.z); - points[4] = CVector3f(min.x, max.y, max.z); - points[5] = CVector3f(max.x, min.y, max.z); - points[6] = CVector3f(max.x, max.y, min.z); - points[7] = CVector3f(max.x, min.y, min.z); + CVector3f Points[8]; + Points[0] = Min; + Points[1] = Max; + Points[2] = CVector3f(Min.X, Min.Y, Max.Z); + Points[3] = CVector3f(Min.X, Max.Y, Min.Z); + Points[4] = CVector3f(Min.X, Max.Y, Max.Z); + Points[5] = CVector3f(Max.X, Min.Y, Max.Z); + Points[6] = CVector3f(Max.X, Max.Y, Min.Z); + Points[7] = CVector3f(Max.X, Min.Y, Min.Z); for (u32 iPlane = 0; iPlane < 6; iPlane++) { - const CPlane& plane = mPlanes[iPlane]; - int numPoints = 0; + const CPlane& rkPlane = mPlanes[iPlane]; + int NumPoints = 0; for (u32 iPoint = 0; iPoint < 8; iPoint++) { - if (plane.Normal().Dot(points[iPoint]) + plane.Dist() < 0.f) - numPoints++; + if (rkPlane.Normal().Dot(Points[iPoint]) + rkPlane.Dist() < 0.f) + NumPoints++; else break; } - if (numPoints == 8) return false; + if (NumPoints == 8) return false; } return true; } diff --git a/src/Math/CFrustumPlanes.h b/src/Math/CFrustumPlanes.h index d25e9b55..c7b8e628 100644 --- a/src/Math/CFrustumPlanes.h +++ b/src/Math/CFrustumPlanes.h @@ -20,11 +20,10 @@ private: public: CFrustumPlanes(); - ~CFrustumPlanes(); - const CPlane& GetPlane(EFrustumSide side) const; - void SetPlanes(const CVector3f& position, const CVector3f& direction, float fieldOfView, float aspectRatio, float near, float far); - bool PointInFrustum(const CVector3f& point) const; - bool BoxInFrustum(const CAABox& box) const; + const CPlane& GetPlane(EFrustumSide Side) const; + void SetPlanes(const CVector3f& rkPosition, const CVector3f& rkDirection, float FieldOfView, float AspectRatio, float Near, float Far); + bool PointInFrustum(const CVector3f& rkPoint) const; + bool BoxInFrustum(const CAABox& rkBox) const; }; #endif // CFRUSTUMPLANES_H diff --git a/src/Math/CMatrix4f.cpp b/src/Math/CMatrix4f.cpp index 46d7750d..0aa71805 100644 --- a/src/Math/CMatrix4f.cpp +++ b/src/Math/CMatrix4f.cpp @@ -7,19 +7,19 @@ CMatrix4f::CMatrix4f() { } -CMatrix4f::CMatrix4f(float v) +CMatrix4f::CMatrix4f(float Diagonal) { *this = skZero; - m[0][0] = v; - m[1][1] = v; - m[2][2] = v; - m[3][3] = v; + m[0][0] = Diagonal; + m[1][1] = Diagonal; + m[2][2] = Diagonal; + m[3][3] = Diagonal; } CMatrix4f::CMatrix4f(float m00, float m01, float m02, float m03, - float m10, float m11, float m12, float m13, - float m20, float m21, float m22, float m23, - float m30, float m31, float m32, float m33) + float m10, float m11, float m12, float m13, + float m20, float m21, float m22, float m23, + float m30, float m31, float m32, float m33) { m[0][0] = m00; m[0][1] = m01; @@ -139,93 +139,93 @@ float CMatrix4f::Determinant() const glm::mat4 CMatrix4f::ToGlmMat4() const { - glm::mat4 out = glm::mat4(1); - memcpy(&out[0][0], &m[0][0], sizeof(glm::mat4)); - return out; + glm::mat4 Out = glm::mat4(1); + memcpy(&Out[0][0], &m[0][0], sizeof(glm::mat4)); + return Out; } // ************ STATIC ************ -CMatrix4f CMatrix4f::FromGlmMat4(glm::mat4 src) +CMatrix4f CMatrix4f::FromGlmMat4(const glm::mat4& rkSrc) { - CMatrix4f out; - memcpy(&out[0][0], &src[0][0], sizeof(CMatrix4f)); - return out; + CMatrix4f Out; + memcpy(&Out[0][0], &rkSrc[0][0], sizeof(CMatrix4f)); + return Out; } // ************ OPERATORS ************ -inline float* CMatrix4f::operator[](long index) +inline float* CMatrix4f::operator[](long Index) { - return m[index]; + return m[Index]; } -inline const float* CMatrix4f::operator[](long index) const +inline const float* CMatrix4f::operator[](long Index) const { - return m[index]; + return m[Index]; } -CVector3f CMatrix4f::operator*(const CVector3f& vec) const +CVector3f CMatrix4f::operator*(const CVector3f& rkVec) const { // For vec3 multiplication, the vector w component is considered to be 1.0 CVector3f out; - float w = (m[3][0] * vec.x) + (m[3][1] * vec.y) + (m[3][2] * vec.z) + m[3][3]; - out.x = ((m[0][0] * vec.x) + (m[0][1] * vec.y) + (m[0][2] * vec.z) + m[0][3]) / w; - out.y = ((m[1][0] * vec.x) + (m[1][1] * vec.y) + (m[1][2] * vec.z) + m[1][3]) / w; - out.z = ((m[2][0] * vec.x) + (m[2][1] * vec.y) + (m[2][2] * vec.z) + m[1][3]) / w; + float w = (m[3][0] * rkVec.X) + (m[3][1] * rkVec.Y) + (m[3][2] * rkVec.Z) + m[3][3]; + out.X = ((m[0][0] * rkVec.X) + (m[0][1] * rkVec.Y) + (m[0][2] * rkVec.Z) + m[0][3]) / w; + out.Y = ((m[1][0] * rkVec.X) + (m[1][1] * rkVec.Y) + (m[1][2] * rkVec.Z) + m[1][3]) / w; + out.Z = ((m[2][0] * rkVec.X) + (m[2][1] * rkVec.Y) + (m[2][2] * rkVec.Z) + m[1][3]) / w; return out; } -CVector4f CMatrix4f::operator*(const CVector4f& vec) const +CVector4f CMatrix4f::operator*(const CVector4f& rkVec) const { CVector4f out; - out.x = (m[0][0] * vec.x) + (m[0][1] * vec.y) + (m[0][2] * vec.z) + (m[0][3] * vec.w); - out.y = (m[1][0] * vec.x) + (m[1][1] * vec.y) + (m[1][2] * vec.z) + (m[1][3] * vec.w); - out.z = (m[2][0] * vec.x) + (m[2][1] * vec.y) + (m[2][2] * vec.z) + (m[2][3] * vec.w); - out.w = (m[3][0] * vec.x) + (m[3][1] * vec.y) + (m[3][2] * vec.z) + (m[3][3] * vec.w); + out.X = (m[0][0] * rkVec.X) + (m[0][1] * rkVec.Y) + (m[0][2] * rkVec.Z) + (m[0][3] * rkVec.W); + out.Y = (m[1][0] * rkVec.X) + (m[1][1] * rkVec.Y) + (m[1][2] * rkVec.Z) + (m[1][3] * rkVec.W); + out.Z = (m[2][0] * rkVec.X) + (m[2][1] * rkVec.Y) + (m[2][2] * rkVec.Z) + (m[2][3] * rkVec.W); + out.W = (m[3][0] * rkVec.X) + (m[3][1] * rkVec.Y) + (m[3][2] * rkVec.Z) + (m[3][3] * rkVec.W); return out; } -CMatrix4f CMatrix4f::operator*(const CTransform4f& mtx) const +CMatrix4f CMatrix4f::operator*(const CTransform4f& rkMtx) const { // CTransform4f is a 3x4 matrix with an implicit fourth row of {0, 0, 0, 1} CMatrix4f out; - out[0][0] = (m[0][0] * mtx[0][0]) + (m[0][1] * mtx[1][0]) + (m[0][2] * mtx[2][0]); - out[0][1] = (m[0][0] * mtx[0][1]) + (m[0][1] * mtx[1][1]) + (m[0][2] * mtx[2][1]); - out[0][2] = (m[0][0] * mtx[0][2]) + (m[0][1] * mtx[1][2]) + (m[0][2] * mtx[2][2]); - out[0][3] = (m[0][0] * mtx[0][3]) + (m[0][1] * mtx[1][3]) + (m[0][2] * mtx[2][3]) + m[0][3]; - out[1][0] = (m[1][0] * mtx[0][0]) + (m[1][1] * mtx[1][0]) + (m[1][2] * mtx[2][0]); - out[1][1] = (m[1][0] * mtx[0][1]) + (m[1][1] * mtx[1][1]) + (m[1][2] * mtx[2][1]); - out[1][2] = (m[1][0] * mtx[0][2]) + (m[1][1] * mtx[1][2]) + (m[1][2] * mtx[2][2]); - out[1][3] = (m[1][0] * mtx[0][3]) + (m[1][1] * mtx[1][3]) + (m[1][2] * mtx[2][3]) + m[1][3]; - out[2][0] = (m[2][0] * mtx[0][0]) + (m[2][1] * mtx[1][0]) + (m[2][2] * mtx[2][0]); - out[2][1] = (m[2][0] * mtx[0][1]) + (m[2][1] * mtx[1][1]) + (m[2][2] * mtx[2][1]); - out[2][2] = (m[2][0] * mtx[0][2]) + (m[2][1] * mtx[1][2]) + (m[2][2] * mtx[2][2]); - out[2][3] = (m[2][0] * mtx[0][3]) + (m[2][1] * mtx[1][3]) + (m[2][2] * mtx[2][3]) + m[2][3]; - out[3][0] = (m[3][0] * mtx[0][0]) + (m[3][1] * mtx[1][0]) + (m[3][2] * mtx[2][0]); - out[3][1] = (m[3][0] * mtx[0][1]) + (m[3][1] * mtx[1][1]) + (m[3][2] * mtx[2][1]); - out[3][2] = (m[3][0] * mtx[0][2]) + (m[3][1] * mtx[1][2]) + (m[3][2] * mtx[2][2]); - out[3][3] = (m[3][0] * mtx[0][3]) + (m[3][1] * mtx[1][3]) + (m[3][2] * mtx[2][3]) + m[3][3]; + out[0][0] = (m[0][0] * rkMtx[0][0]) + (m[0][1] * rkMtx[1][0]) + (m[0][2] * rkMtx[2][0]); + out[0][1] = (m[0][0] * rkMtx[0][1]) + (m[0][1] * rkMtx[1][1]) + (m[0][2] * rkMtx[2][1]); + out[0][2] = (m[0][0] * rkMtx[0][2]) + (m[0][1] * rkMtx[1][2]) + (m[0][2] * rkMtx[2][2]); + out[0][3] = (m[0][0] * rkMtx[0][3]) + (m[0][1] * rkMtx[1][3]) + (m[0][2] * rkMtx[2][3]) + m[0][3]; + out[1][0] = (m[1][0] * rkMtx[0][0]) + (m[1][1] * rkMtx[1][0]) + (m[1][2] * rkMtx[2][0]); + out[1][1] = (m[1][0] * rkMtx[0][1]) + (m[1][1] * rkMtx[1][1]) + (m[1][2] * rkMtx[2][1]); + out[1][2] = (m[1][0] * rkMtx[0][2]) + (m[1][1] * rkMtx[1][2]) + (m[1][2] * rkMtx[2][2]); + out[1][3] = (m[1][0] * rkMtx[0][3]) + (m[1][1] * rkMtx[1][3]) + (m[1][2] * rkMtx[2][3]) + m[1][3]; + out[2][0] = (m[2][0] * rkMtx[0][0]) + (m[2][1] * rkMtx[1][0]) + (m[2][2] * rkMtx[2][0]); + out[2][1] = (m[2][0] * rkMtx[0][1]) + (m[2][1] * rkMtx[1][1]) + (m[2][2] * rkMtx[2][1]); + out[2][2] = (m[2][0] * rkMtx[0][2]) + (m[2][1] * rkMtx[1][2]) + (m[2][2] * rkMtx[2][2]); + out[2][3] = (m[2][0] * rkMtx[0][3]) + (m[2][1] * rkMtx[1][3]) + (m[2][2] * rkMtx[2][3]) + m[2][3]; + out[3][0] = (m[3][0] * rkMtx[0][0]) + (m[3][1] * rkMtx[1][0]) + (m[3][2] * rkMtx[2][0]); + out[3][1] = (m[3][0] * rkMtx[0][1]) + (m[3][1] * rkMtx[1][1]) + (m[3][2] * rkMtx[2][1]); + out[3][2] = (m[3][0] * rkMtx[0][2]) + (m[3][1] * rkMtx[1][2]) + (m[3][2] * rkMtx[2][2]); + out[3][3] = (m[3][0] * rkMtx[0][3]) + (m[3][1] * rkMtx[1][3]) + (m[3][2] * rkMtx[2][3]) + m[3][3]; return out; } -CMatrix4f CMatrix4f::operator*(const CMatrix4f& mtx) const +CMatrix4f CMatrix4f::operator*(const CMatrix4f& rkMtx) const { CMatrix4f out; - out[0][0] = (m[0][0] * mtx[0][0]) + (m[0][1] * mtx[1][0]) + (m[0][2] * mtx[2][0]) + (m[0][3] * mtx[3][0]); - out[0][1] = (m[0][0] * mtx[0][1]) + (m[0][1] * mtx[1][1]) + (m[0][2] * mtx[2][1]) + (m[0][3] * mtx[3][1]); - out[0][2] = (m[0][0] * mtx[0][2]) + (m[0][1] * mtx[1][2]) + (m[0][2] * mtx[2][2]) + (m[0][3] * mtx[3][2]); - out[0][3] = (m[0][0] * mtx[0][3]) + (m[0][1] * mtx[1][3]) + (m[0][2] * mtx[2][3]) + (m[0][3] * mtx[3][3]); - out[1][0] = (m[1][0] * mtx[0][0]) + (m[1][1] * mtx[1][0]) + (m[1][2] * mtx[2][0]) + (m[1][3] * mtx[3][0]); - out[1][1] = (m[1][0] * mtx[0][1]) + (m[1][1] * mtx[1][1]) + (m[1][2] * mtx[2][1]) + (m[1][3] * mtx[3][1]); - out[1][2] = (m[1][0] * mtx[0][2]) + (m[1][1] * mtx[1][2]) + (m[1][2] * mtx[2][2]) + (m[1][3] * mtx[3][2]); - out[1][3] = (m[1][0] * mtx[0][3]) + (m[1][1] * mtx[1][3]) + (m[1][2] * mtx[2][3]) + (m[1][3] * mtx[3][3]); - out[2][0] = (m[2][0] * mtx[0][0]) + (m[2][1] * mtx[1][0]) + (m[2][2] * mtx[2][0]) + (m[2][3] * mtx[3][0]); - out[2][1] = (m[2][0] * mtx[0][1]) + (m[2][1] * mtx[1][1]) + (m[2][2] * mtx[2][1]) + (m[2][3] * mtx[3][1]); - out[2][2] = (m[2][0] * mtx[0][2]) + (m[2][1] * mtx[1][2]) + (m[2][2] * mtx[2][2]) + (m[2][3] * mtx[3][2]); - out[2][3] = (m[2][0] * mtx[0][3]) + (m[2][1] * mtx[1][3]) + (m[2][2] * mtx[2][3]) + (m[2][3] * mtx[3][3]); - out[3][0] = (m[3][0] * mtx[0][0]) + (m[3][1] * mtx[1][0]) + (m[3][2] * mtx[2][0]) + (m[3][3] * mtx[3][0]); - out[3][1] = (m[3][0] * mtx[0][1]) + (m[3][1] * mtx[1][1]) + (m[3][2] * mtx[2][1]) + (m[3][3] * mtx[3][1]); - out[3][2] = (m[3][0] * mtx[0][2]) + (m[3][1] * mtx[1][2]) + (m[3][2] * mtx[2][2]) + (m[3][3] * mtx[3][2]); - out[3][3] = (m[3][0] * mtx[0][3]) + (m[3][1] * mtx[1][3]) + (m[3][2] * mtx[2][3]) + (m[3][3] * mtx[3][3]); + out[0][0] = (m[0][0] * rkMtx[0][0]) + (m[0][1] * rkMtx[1][0]) + (m[0][2] * rkMtx[2][0]) + (m[0][3] * rkMtx[3][0]); + out[0][1] = (m[0][0] * rkMtx[0][1]) + (m[0][1] * rkMtx[1][1]) + (m[0][2] * rkMtx[2][1]) + (m[0][3] * rkMtx[3][1]); + out[0][2] = (m[0][0] * rkMtx[0][2]) + (m[0][1] * rkMtx[1][2]) + (m[0][2] * rkMtx[2][2]) + (m[0][3] * rkMtx[3][2]); + out[0][3] = (m[0][0] * rkMtx[0][3]) + (m[0][1] * rkMtx[1][3]) + (m[0][2] * rkMtx[2][3]) + (m[0][3] * rkMtx[3][3]); + out[1][0] = (m[1][0] * rkMtx[0][0]) + (m[1][1] * rkMtx[1][0]) + (m[1][2] * rkMtx[2][0]) + (m[1][3] * rkMtx[3][0]); + out[1][1] = (m[1][0] * rkMtx[0][1]) + (m[1][1] * rkMtx[1][1]) + (m[1][2] * rkMtx[2][1]) + (m[1][3] * rkMtx[3][1]); + out[1][2] = (m[1][0] * rkMtx[0][2]) + (m[1][1] * rkMtx[1][2]) + (m[1][2] * rkMtx[2][2]) + (m[1][3] * rkMtx[3][2]); + out[1][3] = (m[1][0] * rkMtx[0][3]) + (m[1][1] * rkMtx[1][3]) + (m[1][2] * rkMtx[2][3]) + (m[1][3] * rkMtx[3][3]); + out[2][0] = (m[2][0] * rkMtx[0][0]) + (m[2][1] * rkMtx[1][0]) + (m[2][2] * rkMtx[2][0]) + (m[2][3] * rkMtx[3][0]); + out[2][1] = (m[2][0] * rkMtx[0][1]) + (m[2][1] * rkMtx[1][1]) + (m[2][2] * rkMtx[2][1]) + (m[2][3] * rkMtx[3][1]); + out[2][2] = (m[2][0] * rkMtx[0][2]) + (m[2][1] * rkMtx[1][2]) + (m[2][2] * rkMtx[2][2]) + (m[2][3] * rkMtx[3][2]); + out[2][3] = (m[2][0] * rkMtx[0][3]) + (m[2][1] * rkMtx[1][3]) + (m[2][2] * rkMtx[2][3]) + (m[2][3] * rkMtx[3][3]); + out[3][0] = (m[3][0] * rkMtx[0][0]) + (m[3][1] * rkMtx[1][0]) + (m[3][2] * rkMtx[2][0]) + (m[3][3] * rkMtx[3][0]); + out[3][1] = (m[3][0] * rkMtx[0][1]) + (m[3][1] * rkMtx[1][1]) + (m[3][2] * rkMtx[2][1]) + (m[3][3] * rkMtx[3][1]); + out[3][2] = (m[3][0] * rkMtx[0][2]) + (m[3][1] * rkMtx[1][2]) + (m[3][2] * rkMtx[2][2]) + (m[3][3] * rkMtx[3][2]); + out[3][3] = (m[3][0] * rkMtx[0][3]) + (m[3][1] * rkMtx[1][3]) + (m[3][2] * rkMtx[2][3]) + (m[3][3] * rkMtx[3][3]); return out; } diff --git a/src/Math/CMatrix4f.h b/src/Math/CMatrix4f.h index c6af8269..43a39865 100644 --- a/src/Math/CMatrix4f.h +++ b/src/Math/CMatrix4f.h @@ -17,7 +17,7 @@ class CMatrix4f public: CMatrix4f(); - CMatrix4f(float v); + CMatrix4f(float Diagonal); CMatrix4f(float m00, float m01, float m02, float m03, float m10, float m11, float m12, float m13, float m20, float m21, float m22, float m23, @@ -32,15 +32,15 @@ public: glm::mat4 ToGlmMat4() const; // Static - static CMatrix4f FromGlmMat4(glm::mat4 src); + static CMatrix4f FromGlmMat4(const glm::mat4& rkSrc); // Operators - inline float* operator[](long index); - inline const float* operator[](long index) const; - CVector3f operator*(const CVector3f& vec) const; - CVector4f operator*(const CVector4f& vec) const; - CMatrix4f operator*(const CTransform4f& mtx) const; - CMatrix4f operator*(const CMatrix4f& mtx) const; + inline float* operator[](long Index); + inline const float* operator[](long Index) const; + CVector3f operator*(const CVector3f& rkVec) const; + CVector4f operator*(const CVector4f& rkVec) const; + CMatrix4f operator*(const CTransform4f& rkMtx) const; + CMatrix4f operator*(const CMatrix4f& rkMtx) const; // Constants static const CMatrix4f skZero; diff --git a/src/Math/CPlane.cpp b/src/Math/CPlane.cpp deleted file mode 100644 index 0ec3e607..00000000 --- a/src/Math/CPlane.cpp +++ /dev/null @@ -1,44 +0,0 @@ -#include "CPlane.h" - -CPlane::CPlane() -{ - mNormal = CVector3f::skUp; - mDist = 0.f; -} - -CPlane::CPlane(const CVector3f& normal, float dist) -{ - mNormal = normal; - mDist = dist; -} - -CPlane::CPlane(const CVector3f& normal, const CVector3f& origin) -{ - Redefine(normal, origin); -} - -void CPlane::Redefine(const CVector3f& normal, const CVector3f& origin) -{ - mNormal = normal; - mDist = -normal.Dot(origin); -} - -CVector3f CPlane::Normal() const -{ - return mNormal; -} - -float CPlane::Dist() const -{ - return mDist; -} - -void CPlane::SetNormal(const CVector3f& normal) -{ - mNormal = normal; -} - -void CPlane::SetDist(float dist) -{ - mDist = dist; -} diff --git a/src/Math/CPlane.h b/src/Math/CPlane.h index 7a06dd20..906f4aaa 100644 --- a/src/Math/CPlane.h +++ b/src/Math/CPlane.h @@ -9,15 +9,31 @@ class CPlane float mDist; public: - CPlane(); - CPlane(const CVector3f& normal, float dist); - CPlane(const CVector3f& normal, const CVector3f& origin); + CPlane() + : mNormal(CVector3f::skUp) + , mDist(0.f) + {} - void Redefine(const CVector3f& normal, const CVector3f& origin); - CVector3f Normal() const; - float Dist() const; - void SetNormal(const CVector3f& normal); - void SetDist(float dist); + CPlane(const CVector3f& rkNormal, float Dist) + : mNormal(rkNormal) + , mDist(Dist) + {} + + CPlane(const CVector3f& rkNormal, const CVector3f& rkOrigin) + { + Redefine(rkNormal, rkOrigin); + } + + void Redefine(const CVector3f& rkNormal, const CVector3f& rkOrigin) + { + mNormal = rkNormal; + mDist = -rkNormal.Dot(rkOrigin); + } + + CVector3f Normal() const { return mNormal; } + float Dist() const { return mDist; } + void SetNormal(const CVector3f& rkNormal) { mNormal = rkNormal; } + void SetDist(float Dist) { mDist = Dist; } }; #endif // CPLANE_H diff --git a/src/Math/CQuaternion.cpp b/src/Math/CQuaternion.cpp index db001827..51816f60 100644 --- a/src/Math/CQuaternion.cpp +++ b/src/Math/CQuaternion.cpp @@ -5,19 +5,19 @@ #include CQuaternion::CQuaternion() + : W(0.f) + , X(0.f) + , Y(0.f) + , Z(0.f) { - w = 0.f; - x = 0.f; - y = 0.f; - z = 0.f; } -CQuaternion::CQuaternion(float _w, float _x, float _y, float _z) +CQuaternion::CQuaternion(float _W, float _X, float _Y, float _Z) + : W(_W) + , X(_X) + , Y(_Y) + , Z(_Z) { - w = _w; - x = _x; - y = _y; - z = _z; } CVector3f CQuaternion::XAxis() const @@ -37,12 +37,12 @@ CVector3f CQuaternion::ZAxis() const CQuaternion CQuaternion::Inverse() const { - float fNorm = (w * w) + (x * x) + (y * y) + (z * z); + float Norm = (W * W) + (X * X) + (Y * Y) + (Z * Z); - if (fNorm > 0.f) + if (Norm > 0.f) { - float fInvNorm = 1.f / fNorm; - return CQuaternion( w * fInvNorm, -x * fInvNorm, -y * fInvNorm, -z * fInvNorm); + float InvNorm = 1.f / Norm; + return CQuaternion( W * InvNorm, -X * InvNorm, -Y * InvNorm, -Z * InvNorm); } else return CQuaternion::skZero; @@ -55,42 +55,42 @@ CVector3f CQuaternion::ToEuler() const // we can just have a single conversion function. Handy! // https://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles - float ex = atan2f(2 * (w*x + y*z), 1 - (2 * (Math::Pow(x,2) + Math::Pow(y,2)))); - float ey = asinf(2 * (w*y - z*x)); - float ez = atan2f(2 * (w*z + x*y), 1 - (2 * (Math::Pow(y,2) + Math::Pow(z,2)))); - return CVector3f(Math::RadiansToDegrees(ex), Math::RadiansToDegrees(ey), Math::RadiansToDegrees(ez)); + float EulerX = atan2f(2 * (W*X + Y*Z), 1 - (2 * (Math::Pow(X,2) + Math::Pow(Y,2)))); + float EulerY = asinf(2 * (W*Y - Z*X)); + float EulerZ = atan2f(2 * (W*Z + X*Y), 1 - (2 * (Math::Pow(Y,2) + Math::Pow(Z,2)))); + return CVector3f(Math::RadiansToDegrees(EulerX), Math::RadiansToDegrees(EulerY), Math::RadiansToDegrees(EulerZ)); } // ************ OPERATORS ************ -CVector3f CQuaternion::operator*(const CVector3f& vec) const +CVector3f CQuaternion::operator*(const CVector3f& rkVec) const { CVector3f uv, uuv; - CVector3f qvec(x, y, z); - uv = qvec.Cross(vec); + CVector3f qvec(X, Y, Z); + uv = qvec.Cross(rkVec); uuv = qvec.Cross(uv); - uv *= (2.0f * w); + uv *= (2.0f * W); uuv *= 2.0f; - return vec + uv + uuv; + return rkVec + uv + uuv; } -CQuaternion CQuaternion::operator*(const CQuaternion& other) const +CQuaternion CQuaternion::operator*(const CQuaternion& rkOther) const { CQuaternion out; - out.w = (-x * other.x) - (y * other.y) - (z * other.z) + (w * other.w); - out.x = ( x * other.w) + (y * other.z) - (z * other.y) + (w * other.x); - out.y = (-x * other.z) + (y * other.w) + (z * other.x) + (w * other.y); - out.z = ( x * other.y) - (y * other.x) + (z * other.w) + (w * other.z); + out.W = (-X * rkOther.X) - (Y * rkOther.Y) - (Z * rkOther.Z) + (W * rkOther.W); + out.X = ( X * rkOther.W) + (Y * rkOther.Z) - (Z * rkOther.Y) + (W * rkOther.X); + out.Y = (-X * rkOther.Z) + (Y * rkOther.W) + (Z * rkOther.X) + (W * rkOther.Y); + out.Z = ( X * rkOther.Y) - (Y * rkOther.X) + (Z * rkOther.W) + (W * rkOther.Z); return out; } -void CQuaternion::operator *= (const CQuaternion& other) +void CQuaternion::operator *= (const CQuaternion& rkOther) { - *this = *this * other; + *this = *this * rkOther; } // ************ STATIC ************ -CQuaternion CQuaternion::FromEuler(CVector3f euler) +CQuaternion CQuaternion::FromEuler(CVector3f Euler) { /** * The commented-out code below might be faster but the conversion isn't completely correct @@ -116,76 +116,76 @@ CQuaternion CQuaternion::FromEuler(CVector3f euler) quat.y = ((c1 * s2 * c3) - (s1 * c2 * s3)); quat.z = ((s1 * s2 * c3) + (c1 * c2 * s3));*/ - CQuaternion x = CQuaternion::FromAxisAngle(Math::DegreesToRadians(euler.x), CVector3f(1,0,0)); - CQuaternion y = CQuaternion::FromAxisAngle(Math::DegreesToRadians(euler.y), CVector3f(0,1,0)); - CQuaternion z = CQuaternion::FromAxisAngle(Math::DegreesToRadians(euler.z), CVector3f(0,0,1)); - CQuaternion quat = z * y * x; + CQuaternion X = CQuaternion::FromAxisAngle(Math::DegreesToRadians(Euler.X), CVector3f(1,0,0)); + CQuaternion Y = CQuaternion::FromAxisAngle(Math::DegreesToRadians(Euler.Y), CVector3f(0,1,0)); + CQuaternion Z = CQuaternion::FromAxisAngle(Math::DegreesToRadians(Euler.Z), CVector3f(0,0,1)); + CQuaternion Quat = Z * Y * X; - return quat; + return Quat; } -CQuaternion CQuaternion::FromAxisAngle(float angle, CVector3f axis) +CQuaternion CQuaternion::FromAxisAngle(float Angle, CVector3f Axis) { - CQuaternion quat; - axis = axis.Normalized(); + CQuaternion Quat; + Axis = Axis.Normalized(); - float sa = sinf(angle / 2); - quat.w = cosf(angle / 2); - quat.x = axis.x * sa; - quat.y = axis.y * sa; - quat.z = axis.z * sa; - return quat; + float sa = sinf(Angle / 2); + Quat.W = cosf(Angle / 2); + Quat.X = Axis.X * sa; + Quat.Y = Axis.Y * sa; + Quat.Z = Axis.Z * sa; + return Quat; } -CQuaternion CQuaternion::FromRotationMatrix(const CMatrix4f& RotMtx) +CQuaternion CQuaternion::FromRotationMatrix(const CMatrix4f& rkRotMtx) { // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/ - CQuaternion out; - float trace = RotMtx[0][0] + RotMtx[1][1] + RotMtx[2][2]; + CQuaternion Out; + float Trace = rkRotMtx[0][0] + rkRotMtx[1][1] + rkRotMtx[2][2]; - if (trace > 0.f) + if (Trace > 0.f) { - float s = Math::Sqrt(trace + 1.f) * 2; // s = 4*w - out.w = 0.25f * s; - out.x = (RotMtx[2][1] - RotMtx[1][2]) / s; - out.y = (RotMtx[0][2] - RotMtx[2][0]) / s; - out.z = (RotMtx[1][0] - RotMtx[0][1]) / s; + float s = Math::Sqrt(Trace + 1.f) * 2; // s = 4*w + Out.W = 0.25f * s; + Out.X = (rkRotMtx[2][1] - rkRotMtx[1][2]) / s; + Out.Y = (rkRotMtx[0][2] - rkRotMtx[2][0]) / s; + Out.Z = (rkRotMtx[1][0] - rkRotMtx[0][1]) / s; } - else if ((RotMtx[0][0] > RotMtx[1][1]) && (RotMtx[0][0] > RotMtx[2][2])) + else if ((rkRotMtx[0][0] > rkRotMtx[1][1]) && (rkRotMtx[0][0] > rkRotMtx[2][2])) { - float s = Math::Sqrt(1.f + RotMtx[0][0] - RotMtx[1][1] - RotMtx[2][2]) * 2; // s = 4*x - out.w = (RotMtx[2][1] - RotMtx[1][2]) / s; - out.x = 0.25f * s; - out.y = (RotMtx[0][1] + RotMtx[1][0]) / s; - out.z = (RotMtx[0][2] + RotMtx[2][0]) / s; + float s = Math::Sqrt(1.f + rkRotMtx[0][0] - rkRotMtx[1][1] - rkRotMtx[2][2]) * 2; // s = 4*x + Out.W = (rkRotMtx[2][1] - rkRotMtx[1][2]) / s; + Out.X = 0.25f * s; + Out.Y = (rkRotMtx[0][1] + rkRotMtx[1][0]) / s; + Out.Z = (rkRotMtx[0][2] + rkRotMtx[2][0]) / s; } - else if (RotMtx[1][1] > RotMtx[2][2]) { - float s = Math::Sqrt(1.f + RotMtx[1][1] - RotMtx[0][0] - RotMtx[2][2]) * 2; // s = 4*y - out.w = (RotMtx[0][2] - RotMtx[2][0]) / s; - out.x = (RotMtx[0][1] + RotMtx[1][0]) / s; - out.y = 0.25f * s; - out.z = (RotMtx[1][2] + RotMtx[2][1]) / s; + else if (rkRotMtx[1][1] > rkRotMtx[2][2]) { + float s = Math::Sqrt(1.f + rkRotMtx[1][1] - rkRotMtx[0][0] - rkRotMtx[2][2]) * 2; // s = 4*y + Out.W = (rkRotMtx[0][2] - rkRotMtx[2][0]) / s; + Out.X = (rkRotMtx[0][1] + rkRotMtx[1][0]) / s; + Out.Y = 0.25f * s; + Out.Z = (rkRotMtx[1][2] + rkRotMtx[2][1]) / s; } else { - float s = Math::Sqrt(1.f + RotMtx[2][2] - RotMtx[0][0] - RotMtx[1][1]) * 2; // S=4*qz - out.w = (RotMtx[1][0] - RotMtx[0][1]) / s; - out.x = (RotMtx[0][2] + RotMtx[2][0]) / s; - out.y = (RotMtx[1][2] + RotMtx[2][1]) / s; - out.z = 0.25f * s; + float s = Math::Sqrt(1.f + rkRotMtx[2][2] - rkRotMtx[0][0] - rkRotMtx[1][1]) * 2; // S=4*qz + Out.W = (rkRotMtx[1][0] - rkRotMtx[0][1]) / s; + Out.X = (rkRotMtx[0][2] + rkRotMtx[2][0]) / s; + Out.Y = (rkRotMtx[1][2] + rkRotMtx[2][1]) / s; + Out.Z = 0.25f * s; } - return out; + return Out; } -CQuaternion CQuaternion::FromAxes(const CVector3f& X, const CVector3f& Y, const CVector3f& Z) +CQuaternion CQuaternion::FromAxes(const CVector3f& rkX, const CVector3f& rkY, const CVector3f& rkZ) { - CMatrix4f RotMtx(X.x, Y.x, Z.x, 0.f, - X.y, Y.y, Z.y, 0.f, - X.z, Y.z, Z.z, 0.f, + CMatrix4f RotMtx(rkX.X, rkY.X, rkZ.X, 0.f, + rkX.Y, rkY.Y, rkZ.Y, 0.f, + rkX.Z, rkY.Z, rkZ.Z, 0.f, 0.f, 0.f, 0.f, 1.f); return CQuaternion::FromRotationMatrix(RotMtx); diff --git a/src/Math/CQuaternion.h b/src/Math/CQuaternion.h index 659bef1e..fa20128c 100644 --- a/src/Math/CQuaternion.h +++ b/src/Math/CQuaternion.h @@ -6,10 +6,10 @@ class CQuaternion { public: - float w, x, y, z; + float W, X, Y, Z; CQuaternion(); - CQuaternion(float _w, float _x, float _y, float _z); + CQuaternion(float _W, float _X, float _Y, float _Z); CVector3f XAxis() const; CVector3f YAxis() const; @@ -18,15 +18,15 @@ public: CVector3f ToEuler() const; // Operators - CVector3f operator*(const CVector3f& vec) const; - CQuaternion operator*(const CQuaternion& other) const; - void operator *= (const CQuaternion& other); + CVector3f operator*(const CVector3f& rkVec) const; + CQuaternion operator*(const CQuaternion& rkOther) const; + void operator *= (const CQuaternion& rkOther); // Static - static CQuaternion FromEuler(CVector3f euler); - static CQuaternion FromAxisAngle(float angle, CVector3f axis); - static CQuaternion FromRotationMatrix(const CMatrix4f& RotMtx); - static CQuaternion FromAxes(const CVector3f& X, const CVector3f& Y, const CVector3f& Z); + static CQuaternion FromEuler(CVector3f Euler); + static CQuaternion FromAxisAngle(float Angle, CVector3f Axis); + static CQuaternion FromRotationMatrix(const CMatrix4f& rkRotMtx); + static CQuaternion FromAxes(const CVector3f& rkX, const CVector3f& rkY, const CVector3f& rkZ); static CQuaternion skIdentity; static CQuaternion skZero; diff --git a/src/Math/CRay.cpp b/src/Math/CRay.cpp deleted file mode 100644 index ca99c15b..00000000 --- a/src/Math/CRay.cpp +++ /dev/null @@ -1,43 +0,0 @@ -#include "CRay.h" -#include "CVector4f.h" -#include "CTransform4f.h" -#include - -CRay::CRay() -{ -} - -CRay::CRay(const CVector3f& Origin, const CVector3f& Direction) - : mOrigin(Origin), mDirection(Direction) -{ -} - -CRay::~CRay() -{ -} - -void CRay::SetOrigin(const CVector3f& Origin) -{ - mOrigin = Origin; -} - -void CRay::SetDirection(const CVector3f& Direction) -{ - mDirection = Direction; -} - -CRay CRay::Transformed(const CTransform4f &Matrix) const -{ - CRay out; - out.mOrigin = Matrix * mOrigin; - - CVector3f Point = Matrix * (mOrigin + mDirection); - out.mDirection = (Point - out.mOrigin).Normalized(); - - return out; -} - -CVector3f CRay::PointOnRay(float Distance) const -{ - return mOrigin + (mDirection * Distance); -} diff --git a/src/Math/CRay.h b/src/Math/CRay.h index 4bef54bd..66006f53 100644 --- a/src/Math/CRay.h +++ b/src/Math/CRay.h @@ -1,6 +1,7 @@ #ifndef CRAY_H #define CRAY_H +#include "CTransform4f.h" #include "CVector3f.h" class CRay @@ -9,27 +10,28 @@ class CRay CVector3f mDirection; public: - CRay(); - CRay(const CVector3f& Origin, const CVector3f& Direction); - ~CRay(); - const CVector3f& Origin() const; - const CVector3f& Direction() const; - void SetOrigin(const CVector3f& Origin); - void SetDirection(const CVector3f& Direction); + CRay() {} - CRay Transformed(const CTransform4f& Matrix) const; - CVector3f PointOnRay(float Distance) const; + CRay(const CVector3f& rkOrigin, const CVector3f& rkDirection) + : mOrigin(rkOrigin), mDirection(rkDirection) {} + + const CVector3f& Origin() const { return mOrigin; } + const CVector3f& Direction() const { return mDirection; } + void SetOrigin(const CVector3f& rkOrigin) { mOrigin = rkOrigin; } + void SetDirection(const CVector3f& rkDirection) { mDirection = rkDirection; } + + CRay Transformed(const CTransform4f& rkMatrix) const + { + CRay Out; + Out.mOrigin = rkMatrix * mOrigin; + + CVector3f Point = rkMatrix * (mOrigin + mDirection); + Out.mDirection = (Point - Out.mOrigin).Normalized(); + + return Out; + } + + CVector3f PointOnRay(float Distance) const { return mOrigin + (mDirection * Distance); } }; -// ************ INLINE FUNCTIONS ************ -inline const CVector3f& CRay::Origin() const -{ - return mOrigin; -} - -inline const CVector3f& CRay::Direction() const -{ - return mDirection; -} - #endif // CRAY_H diff --git a/src/Math/CTransform4f.cpp b/src/Math/CTransform4f.cpp index fbb6f7e6..6242c633 100644 --- a/src/Math/CTransform4f.cpp +++ b/src/Math/CTransform4f.cpp @@ -10,18 +10,18 @@ CTransform4f::CTransform4f() *this = skIdentity; } -CTransform4f::CTransform4f(IInputStream& input) +CTransform4f::CTransform4f(IInputStream& rInput) { - for (int v = 0; v < 12; v++) - _m[v] = input.ReadFloat(); + for (int iVal = 0; iVal < 12; iVal++) + _m[iVal] = rInput.ReadFloat(); } -CTransform4f::CTransform4f(float v) +CTransform4f::CTransform4f(float Diagonal) { *this = skZero; - m[0][0] = v; - m[1][1] = v; - m[2][2] = v; + m[0][0] = Diagonal; + m[1][1] = Diagonal; + m[2][2] = Diagonal; } CTransform4f::CTransform4f(float m00, float m01, float m02, float m03, @@ -100,22 +100,22 @@ void CTransform4f::Scale(float XScale, float YScale, float ZScale) Scale(CVector3f(XScale, YScale, ZScale)); } -CTransform4f CTransform4f::MultiplyIgnoreTranslation(const CTransform4f& mtx) const +CTransform4f CTransform4f::MultiplyIgnoreTranslation(const CTransform4f& rkMtx) const { - CTransform4f out; - out[0][0] = (m[0][0] * mtx[0][0]) + (m[0][1] * mtx[1][0]) + (m[0][2] * mtx[2][0]); - out[0][1] = (m[0][0] * mtx[0][1]) + (m[0][1] * mtx[1][1]) + (m[0][2] * mtx[2][1]); - out[0][2] = (m[0][0] * mtx[0][2]) + (m[0][1] * mtx[1][2]) + (m[0][2] * mtx[2][2]); - out[1][0] = (m[1][0] * mtx[0][0]) + (m[1][1] * mtx[1][0]) + (m[1][2] * mtx[2][0]); - out[1][1] = (m[1][0] * mtx[0][1]) + (m[1][1] * mtx[1][1]) + (m[1][2] * mtx[2][1]); - out[1][2] = (m[1][0] * mtx[0][2]) + (m[1][1] * mtx[1][2]) + (m[1][2] * mtx[2][2]); - out[2][0] = (m[2][0] * mtx[0][0]) + (m[2][1] * mtx[1][0]) + (m[2][2] * mtx[2][0]); - out[2][1] = (m[2][0] * mtx[0][1]) + (m[2][1] * mtx[1][1]) + (m[2][2] * mtx[2][1]); - out[2][2] = (m[2][0] * mtx[0][2]) + (m[2][1] * mtx[1][2]) + (m[2][2] * mtx[2][2]); - out[0][3] = 0.f; - out[1][3] = 0.f; - out[2][3] = 0.f; - return out; + CTransform4f Out; + Out[0][0] = (m[0][0] * rkMtx[0][0]) + (m[0][1] * rkMtx[1][0]) + (m[0][2] * rkMtx[2][0]); + Out[0][1] = (m[0][0] * rkMtx[0][1]) + (m[0][1] * rkMtx[1][1]) + (m[0][2] * rkMtx[2][1]); + Out[0][2] = (m[0][0] * rkMtx[0][2]) + (m[0][1] * rkMtx[1][2]) + (m[0][2] * rkMtx[2][2]); + Out[1][0] = (m[1][0] * rkMtx[0][0]) + (m[1][1] * rkMtx[1][0]) + (m[1][2] * rkMtx[2][0]); + Out[1][1] = (m[1][0] * rkMtx[0][1]) + (m[1][1] * rkMtx[1][1]) + (m[1][2] * rkMtx[2][1]); + Out[1][2] = (m[1][0] * rkMtx[0][2]) + (m[1][1] * rkMtx[1][2]) + (m[1][2] * rkMtx[2][2]); + Out[2][0] = (m[2][0] * rkMtx[0][0]) + (m[2][1] * rkMtx[1][0]) + (m[2][2] * rkMtx[2][0]); + Out[2][1] = (m[2][0] * rkMtx[0][1]) + (m[2][1] * rkMtx[1][1]) + (m[2][2] * rkMtx[2][1]); + Out[2][2] = (m[2][0] * rkMtx[0][2]) + (m[2][1] * rkMtx[1][2]) + (m[2][2] * rkMtx[2][2]); + Out[0][3] = 0.f; + Out[1][3] = 0.f; + Out[2][3] = 0.f; + return Out; } CTransform4f CTransform4f::Inverse() const @@ -159,77 +159,77 @@ CTransform4f CTransform4f::RotationOnly() const } // ************ OPERATORS ************ -float* CTransform4f::operator[](long index) +float* CTransform4f::operator[](long Index) { - return m[index]; + return m[Index]; } -const float* CTransform4f::operator[](long index) const +const float* CTransform4f::operator[](long Index) const { - return m[index]; + return m[Index]; } -CVector3f CTransform4f::operator*(const CVector3f& vec) const +CVector3f CTransform4f::operator*(const CVector3f& rkVec) const { CVector3f out; - out.x = (m[0][0] * vec.x) + (m[0][1] * vec.y) + (m[0][2] * vec.z) + (m[0][3]); - out.y = (m[1][0] * vec.x) + (m[1][1] * vec.y) + (m[1][2] * vec.z) + (m[1][3]); - out.z = (m[2][0] * vec.x) + (m[2][1] * vec.y) + (m[2][2] * vec.z) + (m[2][3]); + out.X = (m[0][0] * rkVec.X) + (m[0][1] * rkVec.Y) + (m[0][2] * rkVec.Z) + (m[0][3]); + out.Y = (m[1][0] * rkVec.X) + (m[1][1] * rkVec.Y) + (m[1][2] * rkVec.Z) + (m[1][3]); + out.Z = (m[2][0] * rkVec.X) + (m[2][1] * rkVec.Y) + (m[2][2] * rkVec.Z) + (m[2][3]); return out; } -CVector4f CTransform4f::operator*(const CVector4f& vec) const +CVector4f CTransform4f::operator*(const CVector4f& rkVec) const { CVector4f out; - out.x = (m[0][0] * vec.x) + (m[0][1] * vec.y) + (m[0][2] * vec.z) + (m[0][3] * vec.w); - out.y = (m[1][0] * vec.x) + (m[1][1] * vec.y) + (m[1][2] * vec.z) + (m[1][3] * vec.w); - out.z = (m[2][0] * vec.x) + (m[2][1] * vec.y) + (m[2][2] * vec.z) + (m[2][3] * vec.w); - out.w = vec.w; + out.X = (m[0][0] * rkVec.X) + (m[0][1] * rkVec.Y) + (m[0][2] * rkVec.Z) + (m[0][3] * rkVec.W); + out.Y = (m[1][0] * rkVec.X) + (m[1][1] * rkVec.Y) + (m[1][2] * rkVec.Z) + (m[1][3] * rkVec.W); + out.Z = (m[2][0] * rkVec.X) + (m[2][1] * rkVec.Y) + (m[2][2] * rkVec.Z) + (m[2][3] * rkVec.W); + out.W = rkVec.W; return out; } -CTransform4f CTransform4f::operator*(const CTransform4f& mtx) const +CTransform4f CTransform4f::operator*(const CTransform4f& rkMtx) const { CTransform4f out; - out[0][0] = (m[0][0] * mtx[0][0]) + (m[0][1] * mtx[1][0]) + (m[0][2] * mtx[2][0]); - out[0][1] = (m[0][0] * mtx[0][1]) + (m[0][1] * mtx[1][1]) + (m[0][2] * mtx[2][1]); - out[0][2] = (m[0][0] * mtx[0][2]) + (m[0][1] * mtx[1][2]) + (m[0][2] * mtx[2][2]); - out[0][3] = (m[0][0] * mtx[0][3]) + (m[0][1] * mtx[1][3]) + (m[0][2] * mtx[2][3]) + m[0][3]; - out[1][0] = (m[1][0] * mtx[0][0]) + (m[1][1] * mtx[1][0]) + (m[1][2] * mtx[2][0]); - out[1][1] = (m[1][0] * mtx[0][1]) + (m[1][1] * mtx[1][1]) + (m[1][2] * mtx[2][1]); - out[1][2] = (m[1][0] * mtx[0][2]) + (m[1][1] * mtx[1][2]) + (m[1][2] * mtx[2][2]); - out[1][3] = (m[1][0] * mtx[0][3]) + (m[1][1] * mtx[1][3]) + (m[1][2] * mtx[2][3]) + m[1][3]; - out[2][0] = (m[2][0] * mtx[0][0]) + (m[2][1] * mtx[1][0]) + (m[2][2] * mtx[2][0]); - out[2][1] = (m[2][0] * mtx[0][1]) + (m[2][1] * mtx[1][1]) + (m[2][2] * mtx[2][1]); - out[2][2] = (m[2][0] * mtx[0][2]) + (m[2][1] * mtx[1][2]) + (m[2][2] * mtx[2][2]); - out[2][3] = (m[2][0] * mtx[0][3]) + (m[2][1] * mtx[1][3]) + (m[2][2] * mtx[2][3]) + m[2][3]; + out[0][0] = (m[0][0] * rkMtx[0][0]) + (m[0][1] * rkMtx[1][0]) + (m[0][2] * rkMtx[2][0]); + out[0][1] = (m[0][0] * rkMtx[0][1]) + (m[0][1] * rkMtx[1][1]) + (m[0][2] * rkMtx[2][1]); + out[0][2] = (m[0][0] * rkMtx[0][2]) + (m[0][1] * rkMtx[1][2]) + (m[0][2] * rkMtx[2][2]); + out[0][3] = (m[0][0] * rkMtx[0][3]) + (m[0][1] * rkMtx[1][3]) + (m[0][2] * rkMtx[2][3]) + m[0][3]; + out[1][0] = (m[1][0] * rkMtx[0][0]) + (m[1][1] * rkMtx[1][0]) + (m[1][2] * rkMtx[2][0]); + out[1][1] = (m[1][0] * rkMtx[0][1]) + (m[1][1] * rkMtx[1][1]) + (m[1][2] * rkMtx[2][1]); + out[1][2] = (m[1][0] * rkMtx[0][2]) + (m[1][1] * rkMtx[1][2]) + (m[1][2] * rkMtx[2][2]); + out[1][3] = (m[1][0] * rkMtx[0][3]) + (m[1][1] * rkMtx[1][3]) + (m[1][2] * rkMtx[2][3]) + m[1][3]; + out[2][0] = (m[2][0] * rkMtx[0][0]) + (m[2][1] * rkMtx[1][0]) + (m[2][2] * rkMtx[2][0]); + out[2][1] = (m[2][0] * rkMtx[0][1]) + (m[2][1] * rkMtx[1][1]) + (m[2][2] * rkMtx[2][1]); + out[2][2] = (m[2][0] * rkMtx[0][2]) + (m[2][1] * rkMtx[1][2]) + (m[2][2] * rkMtx[2][2]); + out[2][3] = (m[2][0] * rkMtx[0][3]) + (m[2][1] * rkMtx[1][3]) + (m[2][2] * rkMtx[2][3]) + m[2][3]; return out; } -void CTransform4f::operator*=(const CTransform4f& mtx) +void CTransform4f::operator*=(const CTransform4f& rkMtx) { - *this = *this * mtx; + *this = *this * rkMtx; } -bool CTransform4f::operator==(const CTransform4f& mtx) const +bool CTransform4f::operator==(const CTransform4f& rkMtx) const { - return ((m[0][0] == mtx[0][0]) && - (m[0][1] == mtx[0][1]) && - (m[0][2] == mtx[0][2]) && - (m[0][3] == mtx[0][3]) && - (m[1][0] == mtx[1][0]) && - (m[1][1] == mtx[1][1]) && - (m[1][2] == mtx[1][2]) && - (m[1][3] == mtx[1][3]) && - (m[2][0] == mtx[2][0]) && - (m[2][1] == mtx[2][1]) && - (m[2][2] == mtx[2][2]) && - (m[2][3] == mtx[2][3])); + return ((m[0][0] == rkMtx[0][0]) && + (m[0][1] == rkMtx[0][1]) && + (m[0][2] == rkMtx[0][2]) && + (m[0][3] == rkMtx[0][3]) && + (m[1][0] == rkMtx[1][0]) && + (m[1][1] == rkMtx[1][1]) && + (m[1][2] == rkMtx[1][2]) && + (m[1][3] == rkMtx[1][3]) && + (m[2][0] == rkMtx[2][0]) && + (m[2][1] == rkMtx[2][1]) && + (m[2][2] == rkMtx[2][2]) && + (m[2][3] == rkMtx[2][3])); } -bool CTransform4f::operator!=(const CTransform4f& mtx) const +bool CTransform4f::operator!=(const CTransform4f& rkMtx) const { - return (!(*this == mtx)); + return (!(*this == rkMtx)); } // ************ CONVERSION ************ @@ -245,19 +245,19 @@ CMatrix4f CTransform4f::ToMatrix4f() const CTransform4f CTransform4f::TranslationMatrix(CVector3f Translation) { CTransform4f out = skIdentity; - out[0][3] = Translation.x; - out[1][3] = Translation.y; - out[2][3] = Translation.z; + out[0][3] = Translation.X; + out[1][3] = Translation.Y; + out[2][3] = Translation.Z; return out; } CTransform4f CTransform4f::RotationMatrix(CQuaternion Rotation) { CTransform4f out = skIdentity; - float x = Rotation.x; - float y = Rotation.y; - float z = Rotation.z; - float w = Rotation.w; + float x = Rotation.X; + float y = Rotation.Y; + float z = Rotation.Z; + float w = Rotation.W; float x2 = x * x; float y2 = y * y; float z2 = z * z; @@ -277,28 +277,28 @@ CTransform4f CTransform4f::RotationMatrix(CQuaternion Rotation) CTransform4f CTransform4f::ScaleMatrix(CVector3f Scale) { CTransform4f out = skIdentity; - out[0][0] = Scale.x; - out[1][1] = Scale.y; - out[2][2] = Scale.z; + out[0][0] = Scale.X; + out[1][1] = Scale.Y; + out[2][2] = Scale.Z; return out; } -CTransform4f CTransform4f::FromMatrix4f(const CMatrix4f& mtx) +CTransform4f CTransform4f::FromMatrix4f(const CMatrix4f& rkMtx) { - CTransform4f out; - for (int r = 0; r < 3; r++) - for (int c = 0; c < 4; c++) - out[r][c] = mtx[r][c]; - return out; + CTransform4f Out; + for (int iRow = 0; iRow < 3; iRow++) + for (int iCol = 0; iCol < 4; iCol++) + Out[iRow][iCol] = rkMtx[iRow][iCol]; + return Out; } -CTransform4f CTransform4f::FromGlmMat4(const glm::mat4& mtx) +CTransform4f CTransform4f::FromGlmMat4(const glm::mat4& rkMtx) { - CTransform4f out; - for (int r = 0; r < 3; r++) - for (int c = 0; c < 4; c++) - out[r][c] = mtx[r][c]; - return out; + CTransform4f Out; + for (int iRow = 0; iRow < 3; iRow++) + for (int iCol = 0; iCol < 4; iCol++) + Out[iRow][iCol] = rkMtx[iRow][iCol]; + return Out; } static CTransform4f FromGlmMat4(const glm::mat4&) diff --git a/src/Math/CTransform4f.h b/src/Math/CTransform4f.h index dbf73fd7..a0b0b778 100644 --- a/src/Math/CTransform4f.h +++ b/src/Math/CTransform4f.h @@ -20,8 +20,8 @@ class CTransform4f public: CTransform4f(); - CTransform4f(IInputStream& input); - CTransform4f(float v); + CTransform4f(IInputStream& rInput); + CTransform4f(float Diagonal); CTransform4f(float m00, float m01, float m02, float m03, float m10, float m11, float m12, float m13, float m20, float m21, float m22, float m23); @@ -37,7 +37,7 @@ public: void Rotate(float XRot, float YRot, float ZRot); void Scale(CVector3f Scale); void Scale(float XScale, float YScale, float ZScale); - CTransform4f MultiplyIgnoreTranslation(const CTransform4f& mtx) const; + CTransform4f MultiplyIgnoreTranslation(const CTransform4f& rkMtx) const; CTransform4f Inverse() const; CTransform4f QuickInverse() const; CTransform4f NoTranslation() const; @@ -50,18 +50,18 @@ public: static CTransform4f TranslationMatrix(CVector3f Translation); static CTransform4f RotationMatrix(CQuaternion Rotation); static CTransform4f ScaleMatrix(CVector3f Scale); - static CTransform4f FromMatrix4f(const CMatrix4f& mtx); - static CTransform4f FromGlmMat4(const glm::mat4& mtx); + static CTransform4f FromMatrix4f(const CMatrix4f& rkMtx); + static CTransform4f FromGlmMat4(const glm::mat4& rkMtx); // Operators - float* operator[](long index); - const float* operator[](long index) const; - CVector3f operator*(const CVector3f& vec) const; - CVector4f operator*(const CVector4f& vec) const; - CTransform4f operator*(const CTransform4f& mtx) const; - void operator*=(const CTransform4f& mtx); - bool operator==(const CTransform4f& mtx) const; - bool operator!=(const CTransform4f& mtx) const; + float* operator[](long Index); + const float* operator[](long Index) const; + CVector3f operator*(const CVector3f& rkVec) const; + CVector4f operator*(const CVector4f& rkVec) const; + CTransform4f operator*(const CTransform4f& rkMtx) const; + void operator*=(const CTransform4f& rkMtx); + bool operator==(const CTransform4f& rkMtx) const; + bool operator!=(const CTransform4f& rkMtx) const; // Constant static const CTransform4f skIdentity; diff --git a/src/Math/CVector2f.cpp b/src/Math/CVector2f.cpp index d4a341d7..f2bbed78 100644 --- a/src/Math/CVector2f.cpp +++ b/src/Math/CVector2f.cpp @@ -2,30 +2,30 @@ CVector2f::CVector2f() { - x = y = 0.f; + X = Y = 0.f; } -CVector2f::CVector2f(float xy) +CVector2f::CVector2f(float XY) { - x = y = xy; + X = Y = XY; } -CVector2f::CVector2f(float _x, float _y) +CVector2f::CVector2f(float _X, float _Y) { - x = _x; - y = _y; + X = _X; + Y = _Y; } -CVector2f::CVector2f(IInputStream& Input) +CVector2f::CVector2f(IInputStream& rInput) { - x = Input.ReadFloat(); - y = Input.ReadFloat(); + X = rInput.ReadFloat(); + Y = rInput.ReadFloat(); } -void CVector2f::Write(IOutputStream &Output) +void CVector2f::Write(IOutputStream& rOutput) { - Output.WriteFloat(x); - Output.WriteFloat(y); + rOutput.WriteFloat(X); + rOutput.WriteFloat(Y); } float CVector2f::Magnitude() const @@ -43,138 +43,138 @@ CVector2f CVector2f::Normalized() const return *this / Magnitude(); } -float CVector2f::Dot(const CVector2f& other) const +float CVector2f::Dot(const CVector2f& rkOther) const { - return ((x * other.x) + (y * other.y)); + return ((X * rkOther.X) + (Y * rkOther.Y)); } -CVector2f CVector2f::operator+(const CVector2f& src) const +CVector2f CVector2f::operator+(const CVector2f& rkSrc) const { - CVector2f out; - out.x = this->x + src.x; - out.y = this->y + src.y; - return out; + CVector2f Out; + Out.X = this->X + rkSrc.X; + Out.Y = this->Y + rkSrc.Y; + return Out; } -CVector2f CVector2f::operator-(const CVector2f& src) const +CVector2f CVector2f::operator-(const CVector2f& rkSrc) const { - CVector2f out; - out.x = this->x - src.x; - out.y = this->y - src.y; - return out; + CVector2f Out; + Out.X = this->X - rkSrc.X; + Out.Y = this->Y - rkSrc.Y; + return Out; } -CVector2f CVector2f::operator*(const CVector2f& src) const +CVector2f CVector2f::operator*(const CVector2f& rkSrc) const { - CVector2f out; - out.x = this->x * src.x; - out.y = this->y * src.y; - return out; + CVector2f Out; + Out.X = this->X * rkSrc.X; + Out.Y = this->Y * rkSrc.Y; + return Out; } -CVector2f CVector2f::operator/(const CVector2f& src) const +CVector2f CVector2f::operator/(const CVector2f& rkSrc) const { - CVector2f out; - out.x = this->x / src.x; - out.y = this->y / src.y; - return out; + CVector2f Out; + Out.X = this->X / rkSrc.X; + Out.Y = this->Y / rkSrc.Y; + return Out; } -void CVector2f::operator+=(const CVector2f& other) +void CVector2f::operator+=(const CVector2f& rkOther) { - *this = *this + other; + *this = *this + rkOther; } -void CVector2f::operator-=(const CVector2f& other) +void CVector2f::operator-=(const CVector2f& rkOther) { - *this = *this - other; + *this = *this - rkOther; } -void CVector2f::operator*=(const CVector2f& other) +void CVector2f::operator*=(const CVector2f& rkOther) { - *this = *this * other; + *this = *this * rkOther; } -void CVector2f::operator/=(const CVector2f& other) +void CVector2f::operator/=(const CVector2f& rkOther) { - *this = *this / other; + *this = *this / rkOther; } -CVector2f CVector2f::operator+(const float src) const +CVector2f CVector2f::operator+(const float Src) const { - CVector2f out; - out.x = this->x + src; - out.y = this->y + src; - return out; + CVector2f Out; + Out.X = this->X + Src; + Out.Y = this->Y + Src; + return Out; } -CVector2f CVector2f::operator-(const float src) const +CVector2f CVector2f::operator-(const float Src) const { - CVector2f out; - out.x = this->x - src; - out.y = this->y - src; - return out; + CVector2f Out; + Out.X = this->X - Src; + Out.Y = this->Y - Src; + return Out; } -CVector2f CVector2f::operator*(const float src) const +CVector2f CVector2f::operator*(const float Src) const { - CVector2f out; - out.x = this->x * src; - out.y = this->y * src; - return out; + CVector2f Out; + Out.X = this->X * Src; + Out.Y = this->Y * Src; + return Out; } -CVector2f CVector2f::operator/(const float src) const +CVector2f CVector2f::operator/(const float Src) const { - CVector2f out; - out.x = this->x / src; - out.y = this->y / src; - return out; + CVector2f Out; + Out.X = this->X / Src; + Out.Y = this->Y / Src; + return Out; } -void CVector2f::operator+=(const float other) +void CVector2f::operator+=(const float Other) { - *this = *this + other; + *this = *this + Other; } -void CVector2f::operator-=(const float other) +void CVector2f::operator-=(const float Other) { - *this = *this - other; + *this = *this - Other; } -void CVector2f::operator*=(const float other) +void CVector2f::operator*=(const float Other) { - *this = *this * other; + *this = *this * Other; } -void CVector2f::operator/=(const float other) +void CVector2f::operator/=(const float Other) { - *this = *this / other; + *this = *this / Other; } -bool CVector2f::operator==(const CVector2f& other) const +bool CVector2f::operator==(const CVector2f& rkOther) const { - return ((x == other.x) && (y == other.y)); + return ((X == rkOther.X) && (Y == rkOther.Y)); } -bool CVector2f::operator!=(const CVector2f& other) const +bool CVector2f::operator!=(const CVector2f& rkOther) const { - return (!(*this == other)); + return (!(*this == rkOther)); } CVector2f CVector2f::operator-() const { - return CVector2f(-x, -y); + return CVector2f(-X, -Y); } -float& CVector2f::operator[](long index) +float& CVector2f::operator[](long Index) { - return (&x)[index]; + return (&X)[Index]; } -const float& CVector2f::operator[](long index) const +const float& CVector2f::operator[](long Index) const { - return (&x)[index]; + return (&X)[Index]; } // ************ STATIC MEMBER INITIALIZATION ************ diff --git a/src/Math/CVector2f.h b/src/Math/CVector2f.h index 273371ce..e5a604b5 100644 --- a/src/Math/CVector2f.h +++ b/src/Math/CVector2f.h @@ -7,39 +7,39 @@ class CVector2f { public: - float x, y; + float X, Y; CVector2f(); - CVector2f(float xy); - CVector2f(float _x, float _y); - CVector2f(IInputStream& Input); - void Write(IOutputStream& Output); + CVector2f(float XY); + CVector2f(float _X, float _Y); + CVector2f(IInputStream& rInput); + void Write(IOutputStream& rOutput); float Magnitude() const; float SquaredMagnitude() const; CVector2f Normalized() const; - float Dot(const CVector2f& other) const; + float Dot(const CVector2f& rkOther) const; - CVector2f operator+(const CVector2f& other) const; - CVector2f operator-(const CVector2f& other) const; - CVector2f operator*(const CVector2f& other) const; - CVector2f operator/(const CVector2f& other) const; - void operator+=(const CVector2f& other); - void operator-=(const CVector2f& other); - void operator*=(const CVector2f& other); - void operator/=(const CVector2f& other); - CVector2f operator+(const float other) const; - CVector2f operator-(const float other) const; - CVector2f operator*(const float other) const; - CVector2f operator/(const float other) const; - void operator+=(const float other); - void operator-=(const float other); - void operator*=(const float other); - void operator/=(const float other); - bool operator==(const CVector2f& other) const; - bool operator!=(const CVector2f& other) const; + CVector2f operator+(const CVector2f& rkOther) const; + CVector2f operator-(const CVector2f& rkOther) const; + CVector2f operator*(const CVector2f& rkOther) const; + CVector2f operator/(const CVector2f& rkOther) const; + void operator+=(const CVector2f& rkOther); + void operator-=(const CVector2f& rkOther); + void operator*=(const CVector2f& rkOther); + void operator/=(const CVector2f& rkOther); + CVector2f operator+(const float Other) const; + CVector2f operator-(const float Other) const; + CVector2f operator*(const float Other) const; + CVector2f operator/(const float Other) const; + void operator+=(const float Other); + void operator-=(const float Other); + void operator*=(const float Other); + void operator/=(const float Other); + bool operator==(const CVector2f& rkOther) const; + bool operator!=(const CVector2f& rkOther) const; CVector2f operator-() const; - float& operator[](long index); - const float& operator[](long index) const; + float& operator[](long Index); + const float& operator[](long Index) const; // Static Members static const CVector2f skZero; diff --git a/src/Math/CVector2i.cpp b/src/Math/CVector2i.cpp index 88922bc5..02d9b0b7 100644 --- a/src/Math/CVector2i.cpp +++ b/src/Math/CVector2i.cpp @@ -2,137 +2,137 @@ CVector2i::CVector2i() { - x = y = 0; + X = Y = 0; } -CVector2i::CVector2i(int xy) +CVector2i::CVector2i(int XY) { - x = y = xy; + X = Y = XY; } -CVector2i::CVector2i(int _x, int _y) +CVector2i::CVector2i(int _X, int _Y) { - x = _x; - y = _y; + X = _X; + Y = _Y; } -CVector2i CVector2i::operator+(const CVector2i& other) const +CVector2i CVector2i::operator+(const CVector2i& rkOther) const { - CVector2i out; - out.x = this->x + other.x; - out.y = this->y + other.y; - return out; + CVector2i Out; + Out.X = this->X + rkOther.X; + Out.Y = this->Y + rkOther.Y; + return Out; } -CVector2i CVector2i::operator-(const CVector2i& other) const +CVector2i CVector2i::operator-(const CVector2i& rkOther) const { - CVector2i out; - out.x = this->x - other.x; - out.y = this->y - other.y; - return out; + CVector2i Out; + Out.X = this->X - rkOther.X; + Out.Y = this->Y - rkOther.Y; + return Out; } -CVector2i CVector2i::operator*(const CVector2i& other) const +CVector2i CVector2i::operator*(const CVector2i& rkOther) const { - CVector2i out; - out.x = this->x * other.x; - out.y = this->y * other.y; - return out; + CVector2i Out; + Out.X = this->X * rkOther.X; + Out.Y = this->Y * rkOther.Y; + return Out; } -CVector2i CVector2i::operator/(const CVector2i& other) const +CVector2i CVector2i::operator/(const CVector2i& rkOther) const { - CVector2i out; - out.x = this->x / other.x; - out.y = this->y / other.y; - return out; + CVector2i Out; + Out.X = this->X / rkOther.X; + Out.Y = this->Y / rkOther.Y; + return Out; } -void CVector2i::operator+=(const CVector2i& other) +void CVector2i::operator+=(const CVector2i& rkOther) { - *this = *this + other; + *this = *this + rkOther; } -void CVector2i::operator-=(const CVector2i& other) +void CVector2i::operator-=(const CVector2i& rkOther) { - *this = *this - other; + *this = *this - rkOther; } -void CVector2i::operator*=(const CVector2i& other) +void CVector2i::operator*=(const CVector2i& rkOther) { - *this = *this * other; + *this = *this * rkOther; } -void CVector2i::operator/=(const CVector2i& other) +void CVector2i::operator/=(const CVector2i& rkOther) { - *this = *this / other; + *this = *this / rkOther; } -CVector2i CVector2i::operator+(const int other) const +CVector2i CVector2i::operator+(const int Other) const { - CVector2i out; - out.x = this->x + other; - out.y = this->y + other; - return out; + CVector2i Out; + Out.X = this->X + Other; + Out.Y = this->Y + Other; + return Out; } -CVector2i CVector2i::operator-(const int other) const +CVector2i CVector2i::operator-(const int Other) const { - CVector2i out; - out.x = this->x - other; - out.y = this->y - other; - return out; + CVector2i Out; + Out.X = this->X - Other; + Out.Y = this->Y - Other; + return Out; } -CVector2i CVector2i::operator*(const int other) const +CVector2i CVector2i::operator*(const int Other) const { - CVector2i out; - out.x = this->x * other; - out.y = this->y * other; - return out; + CVector2i Out; + Out.X = this->X * Other; + Out.Y = this->Y * Other; + return Out; } -CVector2i CVector2i::operator/(const int other) const +CVector2i CVector2i::operator/(const int Other) const { - CVector2i out; - out.x = this->x / other; - out.y = this->y / other; - return out; + CVector2i Out; + Out.X = this->X / Other; + Out.Y = this->Y / Other; + return Out; } -void CVector2i::operator+=(const int other) +void CVector2i::operator+=(const int Other) { - *this = *this + other; + *this = *this + Other; } -void CVector2i::operator-=(const int other) +void CVector2i::operator-=(const int Other) { - *this = *this - other; + *this = *this - Other; } -void CVector2i::operator*=(const int other) +void CVector2i::operator*=(const int Other) { - *this = *this * other; + *this = *this * Other; } -void CVector2i::operator/=(const int other) +void CVector2i::operator/=(const int Other) { - *this = *this / other; + *this = *this / Other; } -bool CVector2i::operator==(const CVector2i& other) const +bool CVector2i::operator==(const CVector2i& rkOther) const { - return ((this->x == other.x) && (this->y == other.y)); + return ((this->X == rkOther.X) && (this->Y == rkOther.Y)); } -bool CVector2i::operator!=(const CVector2i& other) const +bool CVector2i::operator!=(const CVector2i& rkOther) const { - return (!(*this == other)); + return (!(*this == rkOther)); } -int& CVector2i::operator[](int index) +int& CVector2i::operator[](int Index) { - return (&x)[index]; + return (&X)[Index]; } // ************ STATIC MEMBER INTIALIZATION ************ diff --git a/src/Math/CVector2i.h b/src/Math/CVector2i.h index 8d93a6e8..3cc91b60 100644 --- a/src/Math/CVector2i.h +++ b/src/Math/CVector2i.h @@ -7,30 +7,30 @@ class CVector2i { public: - int x, y; + int X, Y; CVector2i(); - CVector2i(int xy); - CVector2i(int _x, int _y); + CVector2i(int XY); + CVector2i(int _X, int _Y); - CVector2i operator+(const CVector2i& other) const; - CVector2i operator-(const CVector2i& other) const; - CVector2i operator*(const CVector2i& other) const; - CVector2i operator/(const CVector2i& other) const; - void operator+=(const CVector2i& other); - void operator-=(const CVector2i& other); - void operator*=(const CVector2i& other); - void operator/=(const CVector2i& other); - CVector2i operator+(const int other) const; - CVector2i operator-(const int other) const; - CVector2i operator*(const int other) const; - CVector2i operator/(const int other) const; - void operator+=(const int other); - void operator-=(const int other); - void operator*=(const int other); - void operator/=(const int other); - bool operator==(const CVector2i& other) const; - bool operator!=(const CVector2i& other) const; - int& operator[](int index); + CVector2i operator+(const CVector2i& rkOther) const; + CVector2i operator-(const CVector2i& rkOther) const; + CVector2i operator*(const CVector2i& rkOther) const; + CVector2i operator/(const CVector2i& rkOther) const; + void operator+=(const CVector2i& rkOther); + void operator-=(const CVector2i& rkOther); + void operator*=(const CVector2i& rkOther); + void operator/=(const CVector2i& rkOther); + CVector2i operator+(const int Other) const; + CVector2i operator-(const int Other) const; + CVector2i operator*(const int Other) const; + CVector2i operator/(const int Other) const; + void operator+=(const int Other); + void operator-=(const int Other); + void operator*=(const int Other); + void operator/=(const int Other); + bool operator==(const CVector2i& rkOther) const; + bool operator!=(const CVector2i& rkOther) const; + int& operator[](int Index); // Static Members static const CVector2i skZero; diff --git a/src/Math/CVector3f.cpp b/src/Math/CVector3f.cpp index 2a8fc1b1..2f06f034 100644 --- a/src/Math/CVector3f.cpp +++ b/src/Math/CVector3f.cpp @@ -7,49 +7,49 @@ CVector3f::CVector3f() { - x = y = z = 0.f; + X = Y = Z = 0.f; } -CVector3f::CVector3f(float xyz) +CVector3f::CVector3f(float XYZ) { - x = y = z = xyz; + X = Y = Z = XYZ; } -CVector3f::CVector3f(float _x, float _y, float _z) +CVector3f::CVector3f(float _X, float _Y, float _Z) { - x = _x; - y = _y; - z = _z; + X = _X; + Y = _Y; + Z = _Z; } -CVector3f::CVector3f(IInputStream& Input) +CVector3f::CVector3f(IInputStream& rInput) { - x = Input.ReadFloat(); - y = Input.ReadFloat(); - z = Input.ReadFloat(); + X = rInput.ReadFloat(); + Y = rInput.ReadFloat(); + Z = rInput.ReadFloat(); } -void CVector3f::Write(IOutputStream &Output) +void CVector3f::Write(IOutputStream& rOutput) { - Output.WriteFloat(x); - Output.WriteFloat(y); - Output.WriteFloat(z); + rOutput.WriteFloat(X); + rOutput.WriteFloat(Y); + rOutput.WriteFloat(Z); } // ************ SWIZZLE ************ -CVector2f CVector3f::xy() +CVector2f CVector3f::XY() { - return CVector2f(x, y); + return CVector2f(X, Y); } -CVector2f CVector3f::xz() +CVector2f CVector3f::XZ() { - return CVector2f(x, z); + return CVector2f(X, Z); } -CVector2f CVector3f::yz() +CVector2f CVector3f::YZ() { - return CVector2f(y, z); + return CVector2f(Y, Z); } // ************ MATH ************ @@ -68,211 +68,211 @@ CVector3f CVector3f::Normalized() const return *this / Magnitude(); } -float CVector3f::Dot(const CVector3f& other) const +float CVector3f::Dot(const CVector3f& rkOther) const { - return (x * other.x) + (y * other.y) + (z * other.z); + return (X * rkOther.X) + (Y * rkOther.Y) + (Z * rkOther.Z); } -CVector3f CVector3f::Cross(const CVector3f& other) const +CVector3f CVector3f::Cross(const CVector3f& rkOther) const { - return CVector3f((y * other.z) - (z * other.y), (z * other.x) - (x * other.z), (x * other.y) - (y * other.x)); + return CVector3f((Y * rkOther.Z) - (Z * rkOther.Y), (Z * rkOther.X) - (X * rkOther.Z), (X * rkOther.Y) - (Y * rkOther.X)); } -float CVector3f::Distance(const CVector3f& point) const +float CVector3f::Distance(const CVector3f& rkPoint) const { - return (*this - point).Magnitude(); + return (*this - rkPoint).Magnitude(); } -float CVector3f::SquaredDistance(const CVector3f& point) const +float CVector3f::SquaredDistance(const CVector3f& rkPoint) const { - return (*this - point).SquaredMagnitude(); + return (*this - rkPoint).SquaredMagnitude(); } // ************ OPERATORS ************ // VECTOR/VECTOR -CVector3f CVector3f::operator+(const CVector3f& src) const +CVector3f CVector3f::operator+(const CVector3f& rkSrc) const { - CVector3f out; - out.x = this->x + src.x; - out.y = this->y + src.y; - out.z = this->z + src.z; - return out; + CVector3f Out; + Out.X = this->X + rkSrc.X; + Out.Y = this->Y + rkSrc.Y; + Out.Z = this->Z + rkSrc.Z; + return Out; } -CVector3f CVector3f::operator-(const CVector3f& src) const +CVector3f CVector3f::operator-(const CVector3f& rkSrc) const { - CVector3f out; - out.x = this->x - src.x; - out.y = this->y - src.y; - out.z = this->z - src.z; - return out; + CVector3f Out; + Out.X = this->X - rkSrc.X; + Out.Y = this->Y - rkSrc.Y; + Out.Z = this->Z - rkSrc.Z; + return Out; } -CVector3f CVector3f::operator*(const CVector3f& src) const +CVector3f CVector3f::operator*(const CVector3f& rkSrc) const { - CVector3f out; - out.x = this->x * src.x; - out.y = this->y * src.y; - out.z = this->z * src.z; - return out; + CVector3f Out; + Out.X = this->X * rkSrc.X; + Out.Y = this->Y * rkSrc.Y; + Out.Z = this->Z * rkSrc.Z; + return Out; } -CVector3f CVector3f::operator/(const CVector3f& src) const +CVector3f CVector3f::operator/(const CVector3f& rkSrc) const { - CVector3f out; - out.x = this->x / src.x; - out.y = this->y / src.y; - out.z = this->z / src.z; - return out; + CVector3f Out; + Out.X = this->X / rkSrc.X; + Out.Y = this->Y / rkSrc.Y; + Out.Z = this->Z / rkSrc.Z; + return Out; } -void CVector3f::operator+=(const CVector3f& other) +void CVector3f::operator+=(const CVector3f& rkOther) { - *this = *this + other; + *this = *this + rkOther; } -void CVector3f::operator-=(const CVector3f& other) +void CVector3f::operator-=(const CVector3f& rkOther) { - *this = *this - other; + *this = *this - rkOther; } -void CVector3f::operator*=(const CVector3f& other) +void CVector3f::operator*=(const CVector3f& rkOther) { - *this = *this * other; + *this = *this * rkOther; } -void CVector3f::operator/=(const CVector3f& other) +void CVector3f::operator/=(const CVector3f& rkOther) { - *this = *this / other; + *this = *this / rkOther; } -bool CVector3f::operator> (const CVector3f& other) const +bool CVector3f::operator> (const CVector3f& rkOther) const { - return ((x > other.x) && (y > other.y) && (z > other.z)); + return ((X > rkOther.X) && (Y > rkOther.Y) && (Z > rkOther.Z)); } -bool CVector3f::operator>=(const CVector3f& other) const +bool CVector3f::operator>=(const CVector3f& rkOther) const { - return ((x >= other.x) && (y >= other.y) && (z >= other.z)); + return ((X >= rkOther.X) && (Y >= rkOther.Y) && (Z >= rkOther.Z)); } -bool CVector3f::operator< (const CVector3f& other) const +bool CVector3f::operator< (const CVector3f& rkOther) const { - return ((x < other.x) && (y < other.y) && (z < other.z)); + return ((X < rkOther.X) && (Y < rkOther.Y) && (Z < rkOther.Z)); } -bool CVector3f::operator<=(const CVector3f& other) const +bool CVector3f::operator<=(const CVector3f& rkOther) const { - return ((x <= other.x) && (y <= other.y) && (z <= other.z)); + return ((X <= rkOther.X) && (Y <= rkOther.Y) && (Z <= rkOther.Z)); } -bool CVector3f::operator==(const CVector3f& other) const +bool CVector3f::operator==(const CVector3f& rkOther) const { - return ((x == other.x) && (y == other.y) && (z == other.z)); + return ((X == rkOther.X) && (Y == rkOther.Y) && (Z == rkOther.Z)); } -bool CVector3f::operator!=(const CVector3f& other) const +bool CVector3f::operator!=(const CVector3f& rkOther) const { - return (!(*this == other)); + return (!(*this == rkOther)); } // VECTOR/FLOAT -CVector3f CVector3f::operator+(const float src) const +CVector3f CVector3f::operator+(const float Src) const { - CVector3f out; - out.x = this->x + src; - out.y = this->y + src; - out.z = this->z + src; - return out; + CVector3f Out; + Out.X = this->X + Src; + Out.Y = this->Y + Src; + Out.Z = this->Z + Src; + return Out; } -CVector3f CVector3f::operator-(const float src) const +CVector3f CVector3f::operator-(const float Src) const { - CVector3f out; - out.x = this->x - src; - out.y = this->y - src; - out.z = this->z - src; - return out; + CVector3f Out; + Out.X = this->X - Src; + Out.Y = this->Y - Src; + Out.Z = this->Z - Src; + return Out; } -CVector3f CVector3f::operator*(const float src) const +CVector3f CVector3f::operator*(const float Src) const { - CVector3f out; - out.x = this->x * src; - out.y = this->y * src; - out.z = this->z * src; - return out; + CVector3f Out; + Out.X = this->X * Src; + Out.Y = this->Y * Src; + Out.Z = this->Z * Src; + return Out; } -CVector3f CVector3f::operator/(const float src) const +CVector3f CVector3f::operator/(const float Src) const { - CVector3f out; - out.x = this->x / src; - out.y = this->y / src; - out.z = this->z / src; - return out; + CVector3f Out; + Out.X = this->X / Src; + Out.Y = this->Y / Src; + Out.Z = this->Z / Src; + return Out; } -void CVector3f::operator+=(const float other) +void CVector3f::operator+=(const float Other) { - *this = *this + other; + *this = *this + Other; } -void CVector3f::operator-=(const float other) +void CVector3f::operator-=(const float Other) { - *this = *this - other; + *this = *this - Other; } -void CVector3f::operator*=(const float other) +void CVector3f::operator*=(const float Other) { - *this = *this * other; + *this = *this * Other; } -void CVector3f::operator/=(const float other) +void CVector3f::operator/=(const float Other) { - *this = *this / other; + *this = *this / Other; } // VECTOR/MATRIX -CVector3f CVector3f::operator*(const CTransform4f& mtx) const +CVector3f CVector3f::operator*(const CTransform4f& rkMtx) const { - CVector3f out; - out.x = (x * mtx[0][0]) + (y * mtx[1][0]) + (z * mtx[2][0]); - out.y = (x * mtx[0][1]) + (y * mtx[1][1]) + (z * mtx[2][1]); - out.z = (x * mtx[0][2]) + (y * mtx[1][2]) + (z * mtx[2][2]); - return out; + CVector3f Out; + Out.X = (X * rkMtx[0][0]) + (Y * rkMtx[1][0]) + (Z * rkMtx[2][0]); + Out.Y = (X * rkMtx[0][1]) + (Y * rkMtx[1][1]) + (Z * rkMtx[2][1]); + Out.Z = (X * rkMtx[0][2]) + (Y * rkMtx[1][2]) + (Z * rkMtx[2][2]); + return Out; } -void CVector3f::operator*=(const CTransform4f& mtx) +void CVector3f::operator*=(const CTransform4f& rkMtx) { - *this = *this * mtx; + *this = *this * rkMtx; } -CVector3f CVector3f::operator*(const CMatrix4f& mtx) const +CVector3f CVector3f::operator*(const CMatrix4f& rkMtx) const { // To multiply by a Matrix4f, we consider the vector w component to be 1 - CVector3f out; - float w = (x * mtx[0][3]) + (y * mtx[1][3]) + (z * mtx[2][3]) + mtx[3][3]; - out.x = ((x * mtx[0][0]) + (y * mtx[1][0]) + (z * mtx[2][0]) + mtx[3][0]) / w; - out.y = ((x * mtx[0][1]) + (y * mtx[1][1]) + (z * mtx[2][1]) + mtx[3][1]) / w; - out.z = ((x * mtx[0][2]) + (y * mtx[1][2]) + (z * mtx[2][2]) + mtx[3][2]) / w; - return out; + CVector3f Out; + float W = (X * rkMtx[0][3]) + (Y * rkMtx[1][3]) + (Z * rkMtx[2][3]) + rkMtx[3][3]; + Out.X = ((X * rkMtx[0][0]) + (Y * rkMtx[1][0]) + (Z * rkMtx[2][0]) + rkMtx[3][0]) / W; + Out.Y = ((X * rkMtx[0][1]) + (Y * rkMtx[1][1]) + (Z * rkMtx[2][1]) + rkMtx[3][1]) / W; + Out.Z = ((X * rkMtx[0][2]) + (Y * rkMtx[1][2]) + (Z * rkMtx[2][2]) + rkMtx[3][2]) / W; + return Out; } // UNARY CVector3f CVector3f::operator-() const { - return CVector3f(-x, -y, -z); + return CVector3f(-X, -Y, -Z); } -float& CVector3f::operator[](long index) +float& CVector3f::operator[](long Index) { - return (&x)[index]; + return (&X)[Index]; } -const float& CVector3f::operator[](long index) const +const float& CVector3f::operator[](long Index) const { - return (&x)[index]; + return (&X)[Index]; } // ************ CONSTANTS ************ @@ -290,20 +290,20 @@ const CVector3f CVector3f::skUp = CVector3f::skUnitZ; const CVector3f CVector3f::skDown = -CVector3f::skUnitZ; // ************ OTHER ************ -std::ostream& operator<<(std::ostream& o, const CVector3f& Vector) +std::ostream& operator<<(std::ostream& rOut, const CVector3f& rkVector) { - o << std::setprecision(6) + rOut << std::setprecision(6) << std::fixed << "[" - << ((Vector.x >= 0) ? " " : "") - << Vector.x + << ((rkVector.X >= 0) ? " " : "") + << rkVector.X << ", " - << ((Vector.y >= 0) ? " " : "") - << Vector.y + << ((rkVector.Y >= 0) ? " " : "") + << rkVector.Y << ", " - << ((Vector.z >= 0) ? " " : "") - << Vector.z + << ((rkVector.Z >= 0) ? " " : "") + << rkVector.Z << "]"; - return o; + return rOut; } diff --git a/src/Math/CVector3f.h b/src/Math/CVector3f.h index d59e4ec5..b89638a3 100644 --- a/src/Math/CVector3f.h +++ b/src/Math/CVector3f.h @@ -13,63 +13,63 @@ class CTransform4f; class CVector3f { public: - float x, y, z; + float X, Y, Z; CVector3f(); - CVector3f(float xyz); - CVector3f(float _x, float _y, float _z); - CVector3f(IInputStream& Input); - void Write(IOutputStream& Output); + CVector3f(float XYZ); + CVector3f(float _X, float _Y, float _Z); + CVector3f(IInputStream& rInput); + void Write(IOutputStream& rOutput); // Swizzle - CVector2f xy(); - CVector2f xz(); - CVector2f yz(); + CVector2f XY(); + CVector2f XZ(); + CVector2f YZ(); // Math float Magnitude() const; float SquaredMagnitude() const; CVector3f Normalized() const; - float Dot(const CVector3f& other) const; - CVector3f Cross(const CVector3f& other) const; - float Distance(const CVector3f& point) const; - float SquaredDistance(const CVector3f& point) const; + float Dot(const CVector3f& rkOther) const; + CVector3f Cross(const CVector3f& rkOther) const; + float Distance(const CVector3f& rkPoint) const; + float SquaredDistance(const CVector3f& rkPoint) const; // Vector/Vector - CVector3f operator+(const CVector3f& other) const; - CVector3f operator-(const CVector3f& other) const; - CVector3f operator*(const CVector3f& other) const; - CVector3f operator/(const CVector3f& other) const; - void operator+=(const CVector3f& other); - void operator-=(const CVector3f& other); - void operator*=(const CVector3f& other); - void operator/=(const CVector3f& other); - bool operator> (const CVector3f& other) const; - bool operator>=(const CVector3f& other) const; - bool operator< (const CVector3f& other) const; - bool operator<=(const CVector3f& other) const; - bool operator==(const CVector3f& other) const; - bool operator!=(const CVector3f& other) const; + CVector3f operator+(const CVector3f& rkOther) const; + CVector3f operator-(const CVector3f& rkOther) const; + CVector3f operator*(const CVector3f& rkOther) const; + CVector3f operator/(const CVector3f& rkOther) const; + void operator+=(const CVector3f& rkOther); + void operator-=(const CVector3f& rkOther); + void operator*=(const CVector3f& rkOther); + void operator/=(const CVector3f& rkOther); + bool operator> (const CVector3f& rkOther) const; + bool operator>=(const CVector3f& rkOther) const; + bool operator< (const CVector3f& rkOther) const; + bool operator<=(const CVector3f& rkOther) const; + bool operator==(const CVector3f& rkOther) const; + bool operator!=(const CVector3f& rkOther) const; // Vector/Float - CVector3f operator+(const float other) const; - CVector3f operator-(const float other) const; - CVector3f operator*(const float other) const; - CVector3f operator/(const float other) const; - void operator+=(const float other); - void operator-=(const float other); - void operator*=(const float other); - void operator/=(const float other); + CVector3f operator+(const float Other) const; + CVector3f operator-(const float Other) const; + CVector3f operator*(const float Other) const; + CVector3f operator/(const float Other) const; + void operator+=(const float Other); + void operator-=(const float Other); + void operator*=(const float Other); + void operator/=(const float Other); // Vector/Matrix - CVector3f operator*(const CTransform4f& mtx) const; - void operator*=(const CTransform4f& mtx); - CVector3f operator*(const CMatrix4f& mtx) const; + CVector3f operator*(const CTransform4f& rkMtx) const; + void operator*=(const CTransform4f& rkMtx); + CVector3f operator*(const CMatrix4f& rkMtx) const; // Unary CVector3f operator-() const; - float& operator[](long index); - const float& operator[](long index) const; + float& operator[](long Index); + const float& operator[](long Index) const; // Constants static const CVector3f skZero; @@ -86,7 +86,7 @@ public: static const CVector3f skDown; // Other - friend std::ostream& operator<<(std::ostream& o, const CVector3f& Vector); + friend std::ostream& operator<<(std::ostream& rOut, const CVector3f& rkVector); }; #endif // CVECTOR3F_H diff --git a/src/Math/CVector4f.cpp b/src/Math/CVector4f.cpp index fb8ccc9a..b37b64bf 100644 --- a/src/Math/CVector4f.cpp +++ b/src/Math/CVector4f.cpp @@ -5,269 +5,269 @@ CVector4f::CVector4f() { - x = y = z = w = 0.f; + X = Y = Z = W = 0.f; } -CVector4f::CVector4f(float xyzw) +CVector4f::CVector4f(float XYZW) { - x = y = z = w = xyzw; + X = Y = Z = W = XYZW; } -CVector4f::CVector4f(float _x, float _y, float _z, float _w) +CVector4f::CVector4f(float _X, float _Y, float _Z, float _W) { - x = _x; - y = _y; - z = _z; - w = _w; + X = _X; + Y = _Y; + Z = _Z; + W = _W; } -CVector4f::CVector4f(const CVector2f& xy, float _z, float _w) +CVector4f::CVector4f(const CVector2f& rkXY, float _Z, float _W) { - x = xy.x; - y = xy.y; - z = _z; - w = _w; + X = rkXY.X; + Y = rkXY.Y; + Z = _Z; + W = _W; } -CVector4f::CVector4f(const CVector3f& xyz) +CVector4f::CVector4f(const CVector3f& rkXYZ) { - x = xyz.x; - y = xyz.y; - z = xyz.z; - w = 1.f; + X = rkXYZ.X; + Y = rkXYZ.Y; + Z = rkXYZ.Z; + W = 1.f; } -CVector4f::CVector4f(const CVector3f& xyz, float _w) +CVector4f::CVector4f(const CVector3f& rkXYZ, float _W) { - x = xyz.x; - y = xyz.y; - z = xyz.z; - w = _w; + X = rkXYZ.X; + Y = rkXYZ.Y; + Z = rkXYZ.Z; + W = _W; } -CVector4f::CVector4f(IInputStream& Input) +CVector4f::CVector4f(IInputStream& rInput) { - x = Input.ReadFloat(); - y = Input.ReadFloat(); - z = Input.ReadFloat(); - w = Input.ReadFloat(); + X = rInput.ReadFloat(); + Y = rInput.ReadFloat(); + Z = rInput.ReadFloat(); + W = rInput.ReadFloat(); } -void CVector4f::Write(IOutputStream &Output) +void CVector4f::Write(IOutputStream& rOutput) { - Output.WriteFloat(x); - Output.WriteFloat(y); - Output.WriteFloat(z); - Output.WriteFloat(w); + rOutput.WriteFloat(X); + rOutput.WriteFloat(Y); + rOutput.WriteFloat(Z); + rOutput.WriteFloat(W); } // ************ SWIZZLE ************ -CVector3f CVector4f::xyz() +CVector3f CVector4f::XYZ() const { - return CVector3f(x, y, z); + return CVector3f(X, Y, Z); } -CVector3f CVector4f::xzw() +CVector3f CVector4f::XZW() const { - return CVector3f(x, z, w); + return CVector3f(X, Z, W); } -CVector3f CVector4f::yzw() +CVector3f CVector4f::YZW() const { - return CVector3f(y, z, w); + return CVector3f(Y, Z, W); } -CVector2f CVector4f::xy() +CVector2f CVector4f::XY() const { - return CVector2f(x, y); + return CVector2f(X, Y); } -CVector2f CVector4f::xz() +CVector2f CVector4f::XZ() const { - return CVector2f(x, z); + return CVector2f(X, Z); } -CVector2f CVector4f::xw() +CVector2f CVector4f::XW() const { - return CVector2f(x, w); + return CVector2f(X, W); } -CVector2f CVector4f::yz() +CVector2f CVector4f::YZ() const { - return CVector2f(y, z); + return CVector2f(Y, Z); } -CVector2f CVector4f::yw() +CVector2f CVector4f::YW() const { - return CVector2f(y, w); + return CVector2f(Y, W); } -CVector2f CVector4f::zw() +CVector2f CVector4f::ZW() const { - return CVector2f(z, w); + return CVector2f(Z, W); } // ************ MATH ************ // ************ VECTOR/VECTOR ************ -CVector4f CVector4f::operator+(const CVector4f& src) const +CVector4f CVector4f::operator+(const CVector4f& rkSrc) const { - CVector4f out; - out.x = this->x + src.x; - out.y = this->y + src.y; - out.z = this->z + src.z; - out.w = this->w + src.w; - return out; + CVector4f Out; + Out.X = this->X + rkSrc.X; + Out.Y = this->Y + rkSrc.Y; + Out.Z = this->Z + rkSrc.Z; + Out.W = this->W + rkSrc.W; + return Out; } -CVector4f CVector4f::operator-(const CVector4f& src) const +CVector4f CVector4f::operator-(const CVector4f& rkSrc) const { - CVector4f out; - out.x = this->x - src.x; - out.y = this->y - src.y; - out.z = this->z - src.z; - out.w = this->w - src.w; - return out; + CVector4f Out; + Out.X = this->X - rkSrc.X; + Out.Y = this->Y - rkSrc.Y; + Out.Z = this->Z - rkSrc.Z; + Out.W = this->W - rkSrc.W; + return Out; } -CVector4f CVector4f::operator*(const CVector4f& src) const +CVector4f CVector4f::operator*(const CVector4f& rkSrc) const { - CVector4f out; - out.x = this->x * src.x; - out.y = this->y * src.y; - out.z = this->z * src.z; - out.w = this->w * src.w; - return out; + CVector4f Out; + Out.X = this->X * rkSrc.X; + Out.Y = this->Y * rkSrc.Y; + Out.Z = this->Z * rkSrc.Z; + Out.W = this->W * rkSrc.W; + return Out; } -CVector4f CVector4f::operator/(const CVector4f& src) const +CVector4f CVector4f::operator/(const CVector4f& rkSrc) const { - CVector4f out; - out.x = this->x / src.x; - out.y = this->y / src.y; - out.z = this->z / src.z; - out.w = this->w / src.w; - return out; + CVector4f Out; + Out.X = this->X / rkSrc.X; + Out.Y = this->Y / rkSrc.Y; + Out.Z = this->Z / rkSrc.Z; + Out.W = this->W / rkSrc.W; + return Out; } -void CVector4f::operator+=(const CVector4f& other) +void CVector4f::operator+=(const CVector4f& rkOther) { - *this = *this + other; + *this = *this + rkOther; } -void CVector4f::operator-=(const CVector4f& other) +void CVector4f::operator-=(const CVector4f& rkOther) { - *this = *this - other; + *this = *this - rkOther; } -void CVector4f::operator*=(const CVector4f& other) +void CVector4f::operator*=(const CVector4f& rkOther) { - *this = *this * other; + *this = *this * rkOther; } -void CVector4f::operator/=(const CVector4f& other) +void CVector4f::operator/=(const CVector4f& rkOther) { - *this = *this / other; + *this = *this / rkOther; } -bool CVector4f::operator==(const CVector4f& other) const +bool CVector4f::operator==(const CVector4f& rkOther) const { - return ((x == other.x) && (y == other.y) && (z == other.z) && (w == other.w)); + return ((X == rkOther.X) && (Y == rkOther.Y) && (Z == rkOther.Z) && (W == rkOther.W)); } // ************ VECTOR/FLOAT ************ -CVector4f CVector4f::operator+(const float src) const +CVector4f CVector4f::operator+(const float Src) const { - CVector4f out; - out.x = this->x + src; - out.y = this->y + src; - out.z = this->z + src; - out.w = this->w + src; - return out; + CVector4f Out; + Out.X = this->X + Src; + Out.Y = this->Y + Src; + Out.Z = this->Z + Src; + Out.W = this->W + Src; + return Out; } -CVector4f CVector4f::operator-(const float src) const +CVector4f CVector4f::operator-(const float Src) const { - CVector4f out; - out.x = this->x - src; - out.y = this->y - src; - out.z = this->z - src; - out.w = this->w - src; - return out; + CVector4f Out; + Out.X = this->X - Src; + Out.Y = this->Y - Src; + Out.Z = this->Z - Src; + Out.W = this->W - Src; + return Out; } -CVector4f CVector4f::operator*(const float src) const +CVector4f CVector4f::operator*(const float Src) const { - CVector4f out; - out.x = this->x * src; - out.y = this->y * src; - out.z = this->z * src; - out.w = this->w * src; - return out; + CVector4f Out; + Out.X = this->X * Src; + Out.Y = this->Y * Src; + Out.Z = this->Z * Src; + Out.W = this->W * Src; + return Out; } -CVector4f CVector4f::operator/(const float src) const +CVector4f CVector4f::operator/(const float Src) const { - CVector4f out; - out.x = this->x / src; - out.y = this->y / src; - out.z = this->z / src; - out.w = this->w / src; - return out; + CVector4f Out; + Out.X = this->X / Src; + Out.Y = this->Y / Src; + Out.Z = this->Z / Src; + Out.W = this->W / Src; + return Out; } -void CVector4f::operator+=(const float other) +void CVector4f::operator+=(const float Other) { - *this = *this + other; + *this = *this + Other; } -void CVector4f::operator-=(const float other) +void CVector4f::operator-=(const float Other) { - *this = *this - other; + *this = *this - Other; } -void CVector4f::operator*=(const float other) +void CVector4f::operator*=(const float Other) { - *this = *this * other; + *this = *this * Other; } -void CVector4f::operator/=(const float other) +void CVector4f::operator/=(const float Other) { - *this = *this / other; + *this = *this / Other; } // ************ VECTOR/MATRIX ************ -CVector4f CVector4f::operator*(const CTransform4f& mtx) const +CVector4f CVector4f::operator*(const CTransform4f& rkMtx) const { - CVector4f out; - out.x = (x * mtx[0][0]) + (y * mtx[1][0]) + (z * mtx[2][0]); - out.y = (x * mtx[0][1]) + (y * mtx[1][1]) + (z * mtx[2][1]); - out.z = (x * mtx[0][2]) + (y * mtx[1][2]) + (z * mtx[2][2]); - out.w = (x * mtx[0][3]) + (y * mtx[1][3]) + (z * mtx[2][3]) + w; - return out; + CVector4f Out; + Out.X = (X * rkMtx[0][0]) + (Y * rkMtx[1][0]) + (Z * rkMtx[2][0]); + Out.Y = (X * rkMtx[0][1]) + (Y * rkMtx[1][1]) + (Z * rkMtx[2][1]); + Out.Z = (X * rkMtx[0][2]) + (Y * rkMtx[1][2]) + (Z * rkMtx[2][2]); + Out.W = (X * rkMtx[0][3]) + (Y * rkMtx[1][3]) + (Z * rkMtx[2][3]) + W; + return Out; } -void CVector4f::operator*=(const CTransform4f& mtx) +void CVector4f::operator*=(const CTransform4f& rkMtx) { - *this = *this * mtx; + *this = *this * rkMtx; } -CVector4f CVector4f::operator*(const CMatrix4f& mtx) const +CVector4f CVector4f::operator*(const CMatrix4f& rkMtx) const { - CVector4f out; - out.x = (x * mtx[0][0]) + (y * mtx[1][0]) + (z * mtx[2][0]) + (w * mtx[3][0]); - out.y = (x * mtx[0][1]) + (y * mtx[1][1]) + (z * mtx[2][1]) + (w * mtx[3][1]); - out.z = (x * mtx[0][2]) + (y * mtx[1][2]) + (z * mtx[2][2]) + (w * mtx[3][2]); - out.w = (x * mtx[0][3]) + (y * mtx[1][3]) + (z * mtx[2][3]) + (w * mtx[3][3]); - return out; + CVector4f Out; + Out.X = (X * rkMtx[0][0]) + (Y * rkMtx[1][0]) + (Z * rkMtx[2][0]) + (W * rkMtx[3][0]); + Out.Y = (X * rkMtx[0][1]) + (Y * rkMtx[1][1]) + (Z * rkMtx[2][1]) + (W * rkMtx[3][1]); + Out.Z = (X * rkMtx[0][2]) + (Y * rkMtx[1][2]) + (Z * rkMtx[2][2]) + (W * rkMtx[3][2]); + Out.W = (X * rkMtx[0][3]) + (Y * rkMtx[1][3]) + (Z * rkMtx[2][3]) + (W * rkMtx[3][3]); + return Out; } -void CVector4f::operator*=(const CMatrix4f& mtx) +void CVector4f::operator*=(const CMatrix4f& rkMtx) { - *this = *this * mtx; + *this = *this * rkMtx; } // ************ UNARY ************ -float& CVector4f::operator[](long index) +float& CVector4f::operator[](long Index) { - return (&x)[index]; + return (&X)[Index]; } diff --git a/src/Math/CVector4f.h b/src/Math/CVector4f.h index 42f7bcb8..e3819f41 100644 --- a/src/Math/CVector4f.h +++ b/src/Math/CVector4f.h @@ -12,57 +12,57 @@ class CVector3f; class CVector4f { public: - float x, y, z, w; + float X, Y, Z, W; CVector4f(); - CVector4f(float xyzw); - CVector4f(float _x, float _y, float _z, float _w); - CVector4f(const CVector2f& xy, float _z, float _w); - CVector4f(const CVector3f& xyz); - CVector4f(const CVector3f& xyz, float _w); - CVector4f(IInputStream& Input); - void Write(IOutputStream& Output); + CVector4f(float XYZW); + CVector4f(float _X, float _Y, float _Z, float _W); + CVector4f(const CVector2f& rkXY, float _Z, float _W); + CVector4f(const CVector3f& rkXYZ); + CVector4f(const CVector3f& rkXYZ, float _W); + CVector4f(IInputStream& rInput); + void Write(IOutputStream& rOutput); // Swizzle - CVector3f xyz(); - CVector3f xzw(); - CVector3f yzw(); - CVector2f xy(); - CVector2f xz(); - CVector2f xw(); - CVector2f yz(); - CVector2f yw(); - CVector2f zw(); + CVector3f XYZ() const; + CVector3f XZW() const; + CVector3f YZW() const; + CVector2f XY() const; + CVector2f XZ() const; + CVector2f XW() const; + CVector2f YZ() const; + CVector2f YW() const; + CVector2f ZW() const; // Vector/Vector - CVector4f operator+(const CVector4f& other) const; - CVector4f operator-(const CVector4f& other) const; - CVector4f operator*(const CVector4f& other) const; - CVector4f operator/(const CVector4f& other) const; - void operator+=(const CVector4f& other); - void operator-=(const CVector4f& other); - void operator*=(const CVector4f& other); - void operator/=(const CVector4f& other); - bool operator==(const CVector4f& other) const; + CVector4f operator+(const CVector4f& rkOther) const; + CVector4f operator-(const CVector4f& rkOther) const; + CVector4f operator*(const CVector4f& rkOther) const; + CVector4f operator/(const CVector4f& rkOther) const; + void operator+=(const CVector4f& rkOther); + void operator-=(const CVector4f& rkOther); + void operator*=(const CVector4f& rkOther); + void operator/=(const CVector4f& rkOther); + bool operator==(const CVector4f& rkOther) const; // Vector/Float - CVector4f operator+(const float other) const; - CVector4f operator-(const float other) const; - CVector4f operator*(const float other) const; - CVector4f operator/(const float other) const; - void operator+=(const float other); - void operator-=(const float other); - void operator*=(const float other); - void operator/=(const float other); + CVector4f operator+(const float Other) const; + CVector4f operator-(const float Other) const; + CVector4f operator*(const float Other) const; + CVector4f operator/(const float Other) const; + void operator+=(const float Other); + void operator-=(const float Other); + void operator*=(const float Other); + void operator/=(const float Other); // Vector/Matrix - CVector4f operator*(const CTransform4f& mtx) const; - void operator*=(const CTransform4f& mtx); - CVector4f operator*(const CMatrix4f& mtx) const; - void operator*=(const CMatrix4f& mtx); + CVector4f operator*(const CTransform4f& rkMtx) const; + void operator*=(const CTransform4f& rkMtx); + CVector4f operator*(const CMatrix4f& rkMtx) const; + void operator*=(const CMatrix4f& rkMtx); // Unary - float& operator[](long index); + float& operator[](long Index); }; #endif // CVECTOR4F diff --git a/src/Math/Math.pro b/src/Math/Math.pro index aaa3ba76..4a5d407c 100644 --- a/src/Math/Math.pro +++ b/src/Math/Math.pro @@ -80,9 +80,7 @@ SOURCES += \ CAABox.cpp \ CFrustumPlanes.cpp \ CMatrix4f.cpp \ - CPlane.cpp \ CQuaternion.cpp \ - CRay.cpp \ CTransform4f.cpp \ CVector2f.cpp \ CVector2i.cpp \ diff --git a/src/Math/MathUtil.cpp b/src/Math/MathUtil.cpp index 6587c96a..314d58db 100644 --- a/src/Math/MathUtil.cpp +++ b/src/Math/MathUtil.cpp @@ -5,9 +5,9 @@ namespace Math { -float Abs(float v) +float Abs(float Value) { - return fabs(v); + return fabs(Value); } float Pow(float Base, float Exponent) @@ -15,60 +15,60 @@ float Pow(float Base, float Exponent) return pow(Base, Exponent); } -float Sqrt(float v) +float Sqrt(float Value) { - return sqrtf(v); + return sqrtf(Value); } -float Distance(const CVector3f& A, const CVector3f& B) +float Distance(const CVector3f& rkA, const CVector3f& rkB) { - return sqrtf( Pow(B.x - A.x, 2.f) + - Pow(B.y - A.y, 2.f) + - Pow(B.z - A.z, 2.f) ); + return sqrtf( Pow(rkB.X - rkA.X, 2.f) + + Pow(rkB.Y - rkA.Y, 2.f) + + Pow(rkB.Z - rkA.Z, 2.f) ); } -float DegreesToRadians(float deg) +float DegreesToRadians(float Deg) { - return deg * skPi / 180.f; + return Deg * skPi / 180.f; } -float RadiansToDegrees(float rad) +float RadiansToDegrees(float Rad) { - return rad * 180.f / skPi; + return Rad * 180.f / skPi; } -std::pair RayPlaneIntersecton(const CRay& ray, const CPlane& plane) +std::pair RayPlaneIntersecton(const CRay& rkRay, const CPlane& plane) { // Code based on ray/plane intersect code from Ogre // https://bitbucket.org/sinbad/ogre/src/197116fd2ac62c57cdeed1666f9866c3dddd4289/OgreMain/src/OgreMath.cpp?at=default#OgreMath.cpp-350 // Are ray and plane parallel? - float denom = plane.Normal().Dot(ray.Direction()); + float Denom = plane.Normal().Dot(rkRay.Direction()); - if (Abs(denom) < FLT_EPSILON) + if (Abs(Denom) < FLT_EPSILON) return std::pair(false, 0.f); // Not parallel - float nom = plane.Normal().Dot(ray.Origin()) + plane.Dist(); - float t = -(nom / denom); + float nom = plane.Normal().Dot(rkRay.Origin()) + plane.Dist(); + float t = -(nom / Denom); return std::pair(t >= 0.f, t); } -std::pair RayBoxIntersection(const CRay& Ray, const CAABox& Box) +std::pair RayBoxIntersection(const CRay& rkRay, const CAABox& rkBox) { // Code slightly modified from Ogre // https://github.com/ehsan/ogre/blob/master/OgreMain/src/OgreMath.cpp - if (Box.IsNull()) return std::pair(false, 0.f); - if (Box.IsInfinite()) return std::pair(true, 0.f); + if (rkBox.IsNull()) return std::pair(false, 0.f); + if (rkBox.IsInfinite()) return std::pair(true, 0.f); float lowt = 0.0f; float t; bool Hit = false; CVector3f HitPoint; - const CVector3f& RayOrig = Ray.Origin(); - const CVector3f& RayDir = Ray.Direction(); - const CVector3f Min = Box.Min(); - const CVector3f Max = Box.Max(); + const CVector3f& RayOrig = rkRay.Origin(); + const CVector3f& RayDir = rkRay.Direction(); + const CVector3f Min = rkBox.Min(); + const CVector3f Max = rkBox.Max(); // Check origin inside first if ( RayOrig > Min && RayOrig < Max ) @@ -78,15 +78,15 @@ std::pair RayBoxIntersection(const CRay& Ray, const CAABox& Box) // Check each face in turn, only check closest 3 // Min x - if (RayOrig.x <= Min.x && RayDir.x > 0) + if (RayOrig.X <= Min.X && RayDir.X > 0) { - t = (Min.x - RayOrig.x) / RayDir.x; + t = (Min.X - RayOrig.X) / RayDir.X; if (t >= 0) { // Substitute t back into ray and check bounds and dist HitPoint = RayOrig + RayDir * t; - if (HitPoint.y >= Min.y && HitPoint.y <= Max.y && - HitPoint.z >= Min.z && HitPoint.z <= Max.z && + if (HitPoint.Y >= Min.Y && HitPoint.Y <= Max.Y && + HitPoint.Z >= Min.Z && HitPoint.Z <= Max.Z && (!Hit || t < lowt)) { Hit = true; @@ -95,15 +95,15 @@ std::pair RayBoxIntersection(const CRay& Ray, const CAABox& Box) } } // Max x - if (RayOrig.x >= Max.x && RayDir.x < 0) + if (RayOrig.X >= Max.X && RayDir.X < 0) { - t = (Max.x - RayOrig.x) / RayDir.x; + t = (Max.X - RayOrig.X) / RayDir.X; if (t >= 0) { // Substitute t back into ray and check bounds and dist HitPoint = RayOrig + RayDir * t; - if (HitPoint.y >= Min.y && HitPoint.y <= Max.y && - HitPoint.z >= Min.z && HitPoint.z <= Max.z && + if (HitPoint.Y >= Min.Y && HitPoint.Y <= Max.Y && + HitPoint.Z >= Min.Z && HitPoint.Z <= Max.Z && (!Hit || t < lowt)) { Hit = true; @@ -112,15 +112,15 @@ std::pair RayBoxIntersection(const CRay& Ray, const CAABox& Box) } } // Min y - if (RayOrig.y <= Min.y && RayDir.y > 0) + if (RayOrig.Y <= Min.Y && RayDir.Y > 0) { - t = (Min.y - RayOrig.y) / RayDir.y; + t = (Min.Y - RayOrig.Y) / RayDir.Y; if (t >= 0) { // Substitute t back into ray and check bounds and dist HitPoint = RayOrig + RayDir * t; - if (HitPoint.x >= Min.x && HitPoint.x <= Max.x && - HitPoint.z >= Min.z && HitPoint.z <= Max.z && + if (HitPoint.X >= Min.X && HitPoint.X <= Max.X && + HitPoint.Z >= Min.Z && HitPoint.Z <= Max.Z && (!Hit || t < lowt)) { Hit = true; @@ -129,15 +129,15 @@ std::pair RayBoxIntersection(const CRay& Ray, const CAABox& Box) } } // Max y - if (RayOrig.y >= Max.y && RayDir.y < 0) + if (RayOrig.Y >= Max.Y && RayDir.Y < 0) { - t = (Max.y - RayOrig.y) / RayDir.y; + t = (Max.Y - RayOrig.Y) / RayDir.Y; if (t >= 0) { // Substitute t back into ray and check bounds and dist HitPoint = RayOrig + RayDir * t; - if (HitPoint.x >= Min.x && HitPoint.x <= Max.x && - HitPoint.z >= Min.z && HitPoint.z <= Max.z && + if (HitPoint.X >= Min.X && HitPoint.X <= Max.X && + HitPoint.Z >= Min.Z && HitPoint.Z <= Max.Z && (!Hit || t < lowt)) { Hit = true; @@ -146,15 +146,15 @@ std::pair RayBoxIntersection(const CRay& Ray, const CAABox& Box) } } // Min z - if (RayOrig.z <= Min.z && RayDir.z > 0) + if (RayOrig.Z <= Min.Z && RayDir.Z > 0) { - t = (Min.z - RayOrig.z) / RayDir.z; + t = (Min.Z - RayOrig.Z) / RayDir.Z; if (t >= 0) { // Substitute t back into ray and check bounds and dist HitPoint = RayOrig + RayDir * t; - if (HitPoint.x >= Min.x && HitPoint.x <= Max.x && - HitPoint.y >= Min.y && HitPoint.y <= Max.y && + if (HitPoint.X >= Min.X && HitPoint.X <= Max.X && + HitPoint.Y >= Min.Y && HitPoint.Y <= Max.Y && (!Hit || t < lowt)) { Hit = true; @@ -163,15 +163,15 @@ std::pair RayBoxIntersection(const CRay& Ray, const CAABox& Box) } } // Max z - if (RayOrig.z >= Max.z && RayDir.z < 0) + if (RayOrig.Z >= Max.Z && RayDir.Z < 0) { - t = (Max.z - RayOrig.z) / RayDir.z; + t = (Max.Z - RayOrig.Z) / RayDir.Z; if (t >= 0) { // Substitute t back into ray and check bounds and dist HitPoint = RayOrig + RayDir * t; - if (HitPoint.x >= Min.x && HitPoint.x <= Max.x && - HitPoint.y >= Min.y && HitPoint.y <= Max.y && + if (HitPoint.X >= Min.X && HitPoint.X <= Max.X && + HitPoint.Y >= Min.Y && HitPoint.Y <= Max.Y && (!Hit || t < lowt)) { Hit = true; @@ -183,14 +183,14 @@ std::pair RayBoxIntersection(const CRay& Ray, const CAABox& Box) return std::pair(Hit, lowt); } -std::pair RayLineIntersection(const CRay& ray, const CVector3f& pointA, - const CVector3f& pointB, float threshold) +std::pair RayLineIntersection(const CRay& rkRay, const CVector3f& rkPointA, + const CVector3f& rkPointB, float Threshold) { // http://geomalgorithms.com/a07-_distance.html // http://www.gamedev.net/topic/589705-rayline-intersection-in-3d/ - CVector3f u = ray.Direction(); - CVector3f v = pointB - pointA; - CVector3f w = ray.Origin() - pointA; + CVector3f u = rkRay.Direction(); + CVector3f v = rkPointB - rkPointA; + CVector3f w = rkRay.Origin() - rkPointA; float a = u.Dot(u); float b = u.Dot(v); float c = v.Dot(v); @@ -242,24 +242,24 @@ std::pair RayLineIntersection(const CRay& ray, const CVector3f& poin tc = (fabs(tN) < FLT_EPSILON ? 0.f : tN / tD); CVector3f dP = w + (u * sc) - (v * tc); - bool hit = (dP.Magnitude() <= threshold); + bool hit = (dP.Magnitude() <= Threshold); return std::pair(hit, sc); } -std::pair RayTriangleIntersection(const CRay& Ray, - const CVector3f& vtxA, const CVector3f& vtxB, - const CVector3f& vtxC, bool AllowBackfaces) +std::pair RayTriangleIntersection(const CRay& rkRay, + const CVector3f& rkVtxA, const CVector3f& rkVtxB, + const CVector3f& rkVtxC, bool AllowBackfaces) { // Ogre code cuz I'm lazy and bad at math // https://github.com/ehsan/ogre/blob/master/OgreMain/src/OgreMath.cpp#L709 - CVector3f FaceNormal = (vtxB - vtxA).Cross(vtxC - vtxA); + CVector3f FaceNormal = (rkVtxB - rkVtxA).Cross(rkVtxC - rkVtxA); // // Calculate intersection with plane. // float t; { - float denom = FaceNormal.Dot(Ray.Direction()); + float denom = FaceNormal.Dot(rkRay.Direction()); // Check intersect side if (denom > + std::numeric_limits::epsilon()) @@ -274,7 +274,7 @@ std::pair RayTriangleIntersection(const CRay& Ray, return std::pair(false, 0.f); } - t = FaceNormal.Dot(vtxA - Ray.Origin()) / denom; + t = FaceNormal.Dot(rkVtxA - rkRay.Origin()) / denom; if (t < 0) { @@ -307,12 +307,12 @@ std::pair RayTriangleIntersection(const CRay& Ray, // Check the intersection point is inside the triangle. // { - float u1 = vtxB[i0] - vtxA[i0]; - float v1 = vtxB[i1] - vtxA[i1]; - float u2 = vtxC[i0] - vtxA[i0]; - float v2 = vtxC[i1] - vtxA[i1]; - float u0 = t * Ray.Direction()[i0] + Ray.Origin()[i0] - vtxA[i0]; - float v0 = t * Ray.Direction()[i1] + Ray.Origin()[i1] - vtxA[i1]; + float u1 = rkVtxB[i0] - rkVtxA[i0]; + float v1 = rkVtxB[i1] - rkVtxA[i1]; + float u2 = rkVtxC[i0] - rkVtxA[i0]; + float v2 = rkVtxC[i1] - rkVtxA[i1]; + float u0 = t * rkRay.Direction()[i0] + rkRay.Origin()[i0] - rkVtxA[i0]; + float v0 = t * rkRay.Direction()[i1] + rkRay.Origin()[i1] - rkVtxA[i1]; float alpha = u0 * v2 - u2 * v0; float beta = u1 * v0 - u0 * v1; @@ -338,15 +338,15 @@ std::pair RayTriangleIntersection(const CRay& Ray, return std::pair(true, t); } -CMatrix4f PerspectiveMatrix(float fov, float aspect, float near, float far) +CMatrix4f PerspectiveMatrix(float FOV, float Aspect, float Near, float Far) { // todo: don't use glm - return CMatrix4f::FromGlmMat4(glm::perspective(fov, aspect, near, far)).Transpose(); + return CMatrix4f::FromGlmMat4(glm::perspective(FOV, Aspect, Near, Far)).Transpose(); } -CMatrix4f OrthographicMatrix(float left, float right, float bottom, float top, float near, float far) +CMatrix4f OrthographicMatrix(float Left, float Right, float Bottom, float Top, float Near, float Far) { - return CMatrix4f::FromGlmMat4(glm::ortho(left, right, bottom, top, near, far)).Transpose(); + return CMatrix4f::FromGlmMat4(glm::ortho(Left, Right, Bottom, Top, Near, Far)).Transpose(); } } // End namespace diff --git a/src/Math/MathUtil.h b/src/Math/MathUtil.h index 0fbeaa0a..1c1be75d 100644 --- a/src/Math/MathUtil.h +++ b/src/Math/MathUtil.h @@ -10,32 +10,32 @@ namespace Math { -float Abs(float v); +float Abs(float Value); float Pow(float Base, float Exponent); -float Sqrt(float v); +float Sqrt(float Value); -float Distance(const CVector3f& A, const CVector3f& B); +float Distance(const CVector3f& rkA, const CVector3f& rkB); -float DegreesToRadians(float deg); +float DegreesToRadians(float Deg); -float RadiansToDegrees(float rad); +float RadiansToDegrees(float Rad); -std::pair RayPlaneIntersecton(const CRay& ray, const CPlane& plane); +std::pair RayPlaneIntersecton(const CRay& rkRay, const CPlane& rkPlane); -std::pair RayBoxIntersection(const CRay& Ray, const CAABox& Box); +std::pair RayBoxIntersection(const CRay& rkRay, const CAABox& rkBox); -std::pair RayLineIntersection(const CRay& ray, const CVector3f& pointA, - const CVector3f& pointB, float threshold = 0.02f); +std::pair RayLineIntersection(const CRay& rkRay, const CVector3f& rkPointA, + const CVector3f& rkPointB, float Threshold = 0.02f); -std::pair RayTriangleIntersection(const CRay& Ray, const CVector3f& PointA, - const CVector3f& PointB, const CVector3f& PointC, +std::pair RayTriangleIntersection(const CRay& rkRay, const CVector3f& rkPointA, + const CVector3f& rkPointB, const CVector3f& rkPointC, bool AllowBackfaces = false); -CMatrix4f PerspectiveMatrix(float fov, float aspect, float near, float far); +CMatrix4f PerspectiveMatrix(float FOV, float Aspect, float Near, float Far); -CMatrix4f OrthographicMatrix(float left, float right, float bottom, float top, float near, float far); +CMatrix4f OrthographicMatrix(float Left, float Right, float Bottom, float Top, float Near, float Far); // Constants static const float skPi = 3.14159265358979323846f;