diff --git a/DDrawCompat/DDrawLog.cpp b/DDrawCompat/DDrawLog.cpp index ddbec78..cbdc7d1 100644 --- a/DDrawCompat/DDrawLog.cpp +++ b/DDrawCompat/DDrawLog.cpp @@ -4,17 +4,65 @@ #include "DDrawLog.h" -std::ostream& operator<<(std::ostream& os, LPRECT rect) +namespace { - if (rect) + template + bool isEmptyStruct(const T& t) { - os << "RECT(" << rect->left << ',' << rect->top << ',' << rect->right << ',' << rect->bottom << ')'; + static T empty = {}; + empty.dwSize = t.dwSize; + return 0 == memcmp(&t, &empty, sizeof(t)); } - else +} + +std::ostream& operator<<(std::ostream& os, const RECT& rect) +{ + return os << "R(" << rect.left << ',' << rect.top << ',' << rect.right << ',' << rect.bottom << ')'; +} + +std::ostream& operator<<(std::ostream& os, const DDSCAPS& caps) +{ + return os << "C(" << std::hex << caps.dwCaps << std::dec << ')'; +} + +std::ostream& operator<<(std::ostream& os, const DDSCAPS2& caps) +{ + return os << "C(" << std::hex << + caps.dwCaps << ',' << caps.dwCaps2 << ',' << caps.dwCaps3 << ',' << caps.dwCaps4 << std::dec << ')'; +} + +std::ostream& operator<<(std::ostream& os, const DDPIXELFORMAT& pf) +{ + if (isEmptyStruct(pf)) { - os << "NullRect"; + return os << "PF()"; } - return os; + + return os << "PF(" << std::hex << pf.dwFlags << "," << pf.dwFourCC << "," << + std::dec << pf.dwRGBBitCount << "," << + std::hex << pf.dwRBitMask << "," << pf.dwGBitMask << "," << pf.dwBBitMask << "," << + pf.dwRGBAlphaBitMask << std::dec << ')'; +} + +std::ostream& operator<<(std::ostream& os, const DDSURFACEDESC& sd) +{ + DDSURFACEDESC2 sd2 = {}; + memcpy(&sd2, &sd, sizeof(sd)); + sd2.dwSize = sizeof(sd2); + return os << sd2; +} + +std::ostream& operator<<(std::ostream& os, const DDSURFACEDESC2& sd) +{ + if (isEmptyStruct(sd)) + { + return os << "SD()"; + } + + return os << "SD(" << std::hex << sd.dwFlags << std::dec << "," << + sd.dwHeight << "," << sd.dwWidth << "," << sd.lPitch << "," << sd.dwBackBufferCount << "," << + sd.dwMipMapCount << "," << sd.dwAlphaBitDepth << "," << sd.dwReserved << "," << + sd.lpSurface << "," << sd.ddpfPixelFormat << "," << sd.ddsCaps << "," << sd.dwTextureStage << ')'; } namespace Compat diff --git a/DDrawCompat/DDrawLog.h b/DDrawCompat/DDrawLog.h index 0a4bf4c..630838a 100644 --- a/DDrawCompat/DDrawLog.h +++ b/DDrawCompat/DDrawLog.h @@ -2,10 +2,9 @@ #define CINTERFACE +#include #include - -struct _GUID; -struct tagRECT; +#include #define LOG_ONCE(msg) \ static bool isAlreadyLogged##__LINE__ = false; \ @@ -15,12 +14,32 @@ struct tagRECT; isAlreadyLogged##__LINE__ = true; \ } -inline std::ostream& operator<<(std::ostream& os, const _GUID& guid) +std::ostream& operator<<(std::ostream& os, const RECT& rect); +std::ostream& operator<<(std::ostream& os, const DDSCAPS& caps); +std::ostream& operator<<(std::ostream& os, const DDSCAPS2& caps); +std::ostream& operator<<(std::ostream& os, const DDPIXELFORMAT& pf); +std::ostream& operator<<(std::ostream& os, const DDSURFACEDESC& sd); +std::ostream& operator<<(std::ostream& os, const DDSURFACEDESC2& sd); + +template +typename std::enable_if::value && !std::is_same::value, std::ostream&>::type +operator<<(std::ostream& os, const T& t) { - return os << &guid; + return os << static_cast(&t); } -std::ostream& operator<<(std::ostream& os, tagRECT* rect); +template +typename std::enable_if::value, std::ostream&>::type +operator<<(std::ostream& os, const T* t) +{ + return t ? (os << *t) : (os << "null"); +} + +template +std::ostream& operator<<(std::ostream& os, T** t) +{ + return t ? (os << reinterpret_cast(t) << '=' << *t) : (os << "null"); +} namespace Compat { @@ -88,7 +107,7 @@ namespace Compat template void operator<<(const Result& result) { - static_cast(*this) << " = " << result; + static_cast(*this) << " = " << std::hex << result << std::dec; } }; #else