diff --git a/JGE/include/DebugRoutines.h b/JGE/include/DebugRoutines.h index 89ecfcd77..e68fa3e22 100644 --- a/JGE/include/DebugRoutines.h +++ b/JGE/include/DebugRoutines.h @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -13,19 +14,28 @@ #if defined (WIN32) || defined (LINUX) #ifdef _DEBUG +template +std::string ToHex(T* pointer) +{ + std::ostringstream stream; + stream << std::hex << showbase << setfill('0') << setw(8) << (int) pointer; + return stream.str(); +} + + #ifndef QT_CONFIG #define DebugTrace(inString) \ -{ \ +{ \ std::ostringstream stream; \ - stream << inString << std::endl; \ - OutputDebugString(stream.str().c_str()); \ + stream << inString << std::endl; \ + OutputDebugString(stream.str().c_str()); \ } #else #define DebugTrace(inString) \ -{ \ +{ \ std::ostringstream stream; \ - stream << inString << std::endl; \ - qDebug(stream.str().c_str()); \ + stream << inString << std::endl; \ + qDebug(stream.str().c_str()); \ } #endif //QT_CONFIG @@ -34,8 +44,8 @@ #if defined (IOS) && defined (DEBUG) #define DebugTrace(inString) \ -{ \ - std::cout << inString << std::endl; \ +{ \ + std::cout << inString << std::endl; \ } #endif // IOS, DEBUG diff --git a/projects/mtg/include/CardGui.h b/projects/mtg/include/CardGui.h index 54e5e2f9f..471c47c70 100644 --- a/projects/mtg/include/CardGui.h +++ b/projects/mtg/include/CardGui.h @@ -67,9 +67,14 @@ class CardView : public CardGui { MTGCardInstance* getCard(); // remove this when possible CardView(const SelectorZone, MTGCardInstance* card, float x, float y); CardView(const SelectorZone, MTGCardInstance* card, const Pos& ref); + virtual ~CardView(); + void Render(){CardGui::Render();}; void Render(JQuad* q){Pos::Render(q);}; virtual ostream& toString(ostream&) const; + + float GetCenterX(); + float GetCenterY(); }; class TransientCardView : public CardGui { diff --git a/projects/mtg/include/MTGCardInstance.h b/projects/mtg/include/MTGCardInstance.h index 9d5a95efa..e0cbf2dff 100644 --- a/projects/mtg/include/MTGCardInstance.h +++ b/projects/mtg/include/MTGCardInstance.h @@ -120,7 +120,7 @@ class MTGCardInstance: public CardPrimitive, public MTGCard, public Damageable { int triggerRegenerate(); Player * controller(); - ~MTGCardInstance(); + virtual ~MTGCardInstance(); int bury(); int destroy(); diff --git a/projects/mtg/src/CardGui.cpp b/projects/mtg/src/CardGui.cpp index 6d8a7b98b..b081a0c60 100644 --- a/projects/mtg/src/CardGui.cpp +++ b/projects/mtg/src/CardGui.cpp @@ -44,6 +44,23 @@ CardGui::CardGui(MTGCardInstance* card, const Pos& ref) : { } +float CardView::GetCenterX() +{ + bool largeCard = mHeight == BigHeight; + + float centerX = x + (largeCard ? BigWidth : Width) * 0.5f * zoom; + return centerX; +} + +float CardView::GetCenterY() +{ + bool largeCard = mHeight == BigHeight; + + float centerY = y + (largeCard ? BigHeight : Height) * 0.5f * zoom; + return centerY; +} + + CardView::CardView(const SelectorZone owner, MTGCardInstance* card, float x, float y) : CardGui(card, x, y), owner(owner) { @@ -68,6 +85,20 @@ CardView::CardView(const SelectorZone owner, MTGCardInstance* card, const Pos& r } } +CardView::~CardView() +{ + if (card) + { + const Pos* r = card->view; + while (card) + { + if (r == card->view) + card->view = NULL; + card = card->next; + } + } +} + void CardGui::Update(float dt) { PlayGuiObject::Update(dt); diff --git a/projects/mtg/src/MTGCardInstance.cpp b/projects/mtg/src/MTGCardInstance.cpp index 3562d91ec..08b499754 100644 --- a/projects/mtg/src/MTGCardInstance.cpp +++ b/projects/mtg/src/MTGCardInstance.cpp @@ -88,7 +88,11 @@ void MTGCardInstance::copy(MTGCardInstance * card) MTGCardInstance::~MTGCardInstance() { SAFE_DELETE(counters); - SAFE_DELETE(previous); + if (previous != NULL) + { + //DebugTrace("MTGCardInstance::~MTGCardInstance(): deleting " << ToHex(previous)); + SAFE_DELETE(previous); + } } int MTGCardInstance::init() @@ -411,6 +415,7 @@ int MTGCardInstance::cleanup() } if (previous && !previous->stillInUse()) { + //DebugTrace("MTGCardInstance::cleanup(): deleting " << ToHex(previous)); SAFE_DELETE(previous); } regenerateTokens = 0;