1
0
mirror of https://github.com/narzoul/DDrawCompat synced 2024-12-30 08:55:36 +01:00

Improved debug logging

Debug logs are extended to expand DDSURFACEDESC and related structs.
Pointers to pointers are now also expanded if possible.
This commit is contained in:
narzoul 2015-12-28 12:49:33 +01:00
parent 7b8f68fe23
commit a0d3459e42
2 changed files with 80 additions and 13 deletions

View File

@ -4,17 +4,65 @@
#include "DDrawLog.h"
std::ostream& operator<<(std::ostream& os, LPRECT rect)
namespace
{
if (rect)
template <typename T>
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

View File

@ -2,10 +2,9 @@
#define CINTERFACE
#include <ddraw.h>
#include <fstream>
struct _GUID;
struct tagRECT;
#include <type_traits>
#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 T>
typename std::enable_if<std::is_class<T>::value && !std::is_same<T, std::string>::value, std::ostream&>::type
operator<<(std::ostream& os, const T& t)
{
return os << &guid;
return os << static_cast<const void*>(&t);
}
std::ostream& operator<<(std::ostream& os, tagRECT* rect);
template <typename T>
typename std::enable_if<std::is_class<T>::value, std::ostream&>::type
operator<<(std::ostream& os, const T* t)
{
return t ? (os << *t) : (os << "null");
}
template <typename T>
std::ostream& operator<<(std::ostream& os, T** t)
{
return t ? (os << reinterpret_cast<void*>(t) << '=' << *t) : (os << "null");
}
namespace Compat
{
@ -88,7 +107,7 @@ namespace Compat
template <typename Result>
void operator<<(const Result& result)
{
static_cast<Log&>(*this) << " = " << result;
static_cast<Log&>(*this) << " = " << std::hex << result << std::dec;
}
};
#else