Files
wagic/projects/mtg/include/CardGui.h
wrenczes@gmail.com 87909bed08 Fix for issue 550, heap crashed game in turn 6.
The core problem I fixed was in CardView's (missing) destructor - on construction, a CardView will set itself as a member of its parent CardInstance, so it stands to reason that when it's about to be destroyed, it should do the inverse and remove itself in the same fashion from its parent.   This explains why weird graphic glitches were seen when casting Animate Dead on cards in a graveyard - the position data it was trying to use was already deleted from memory (a cardview is deleted on cleanup at the end of a turn if it's gone to the graveyard), but no one nulled out the deleted card view reference from the instance, so we'd access invalid data.

Some peripheral changes in this checkin:  two helper functions in CardGui (GetCenterX, GetCenterY)  that are part of my navigation patch are included.  They're unused in the current code base, so this has zero impact. (I'm only checking them in as it's more work than it's worth to refactor them into a separate changelist.  The core of the nav patch requires my mods to Closest.cpp / CardSelector.cpp to have any effect.)  I also included a helper function in the debug routines to spit out hex pointer addresses in trace outputs, which I used to chase down this bug.
2010-12-16 09:32:42 +00:00

87 lines
2.1 KiB
C++

/* Graphical representation of a Card Instance, used in game */
#ifndef _CARD_GUI_H_
#define _CARD_GUI_H_
#include <hge/hgeparticle.h>
#include <JGui.h>
#include "Pos.h"
#include "PlayGuiObject.h"
#include "MTGCardInstance.h"
class MTGCardInstance;
class PlayGuiObject;
namespace DrawMode
{
enum
{
kNormal = 0,
kText,
kHidden
};
const int kNumDrawModes = 3;
}
struct CardGui : public PlayGuiObject {
protected:
/*
** Tries to render the Big version of a card picture, backups to text version in case of failure
*/
static void RenderBig(MTGCard * card, const Pos& pos);
void RenderCountersBig(const Pos& pos);
static void AlternateRender(MTGCard * card, const Pos& pos);
static void TinyCropRender(MTGCard * card, const Pos& pos, JQuad * quad);
public:
static const float Width;
static const float Height;
static const float BigWidth;
static const float BigHeight;
MTGCardInstance* card;
CardGui(MTGCardInstance* card, float x, float y);
CardGui(MTGCardInstance* card, const Pos& ref);
virtual void Render();
virtual void Update(float dt);
void DrawCard(const Pos& inPosition, int inMode = DrawMode::kNormal);
static void DrawCard(MTGCard* inCard, const Pos& inPosition, int inMode = DrawMode::kNormal);
static JQuad * AlternateThumbQuad(MTGCard * card);
virtual ostream& toString(ostream&) const;
};
class CardView : public CardGui {
public:
typedef enum {
nullZone, handZone, playZone
} SelectorZone;
const SelectorZone owner;
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 {
public:
TransientCardView(MTGCardInstance* card, float x, float y);
TransientCardView(MTGCardInstance* card, const Pos& ref);
};
#endif