Resuming on my threading support work with the card caching mechanism. This change unfortunately touches quite a few files, but I needed to get it out of the way before things got out of hand: one significant hurdle is the assumed lifetime of a JQuad pointer. In a single threaded model, the life time of the pointer is clear: you fetch it into the cache, the cache makes room, you use the pointer immediately. In a multithreaded context however, it's unsafe, as the drawing thread can request a few JQuads, and the cache operating on a separate thread can potentially bounce a JQuad out of the cache before the draw routine is done using it, which ends up in an access violation when you attempt to draw using an invalidated quad pointer. To prevent this, the bulk of this change swaps out the use of naked JQuad* pointers in the code with a JQuadPtr, which is basically a typedef to a boost shared_ptr<JQuad>.

This btw points out another circular dependancy between the texture and the JQuad - a texture owns a bunch of JQuads, yet the renderer uses JQuads and always assumes that the texture is valid.  We're going to need to add more defensiveness to JGE to protect against this.

Other changes in this check-in:  WResourceManager doesn't derive from JResourceManager anymore.  It actually didn't require anything from the base, so I killed the dependency.  Also cleaned up the notion of a WTrackedQuad in the WCachedResource - it didn't need a separate class, just a better container.

I've build this & tested against PSP, win, linux, QT (linux).  I haven't tried against iOS and QT Win, or Maemo.  If these other platforms are broken, I apologize in advance! - I'm hoping it should be fairly simple to put them back into play.
This commit is contained in:
wrenczes@gmail.com
2011-02-01 10:37:21 +00:00
parent 0b2f83c499
commit 76cba56a1c
51 changed files with 783 additions and 1025 deletions

View File

@@ -1,8 +1,8 @@
/*
* Wagic, The Homebrew ?! is licensed under the BSD license
* See LICENSE in the Folder's root
* http://wololo.net/wagic/
*/
* Wagic, The Homebrew ?! is licensed under the BSD license
* See LICENSE in the Folder's root
* http://wololo.net/wagic/
*/
#ifndef _SPELLSTACK_H_
#define _SPELLSTACK_H_
@@ -27,6 +27,8 @@
#include "TargetsList.h"
#include "Targetable.h"
#include "WResource_Fwd.h"
class GuiLayer;
class PlayGuiObject;
class MTGCardInstance;
@@ -43,168 +45,206 @@ class TargetChooser;
#define ACTIONSTACK_STANDARD 0
#define ACTIONSTACK_TARGET 1
class Interruptible: public PlayGuiObject, public Targetable{
public:
//TODO : remove these when they are back in PlayGuiObject
float x, y;
class Interruptible: public PlayGuiObject, public Targetable
{
public:
//TODO : remove these when they are back in PlayGuiObject
float x, y;
int state, display;
MTGCardInstance * source;
virtual void Entering()
{
mHasFocus = true;
}
virtual bool Leaving(JButton key)
{
mHasFocus = false;
return true;
}
virtual bool ButtonPressed()
{
return true;
}
virtual int resolve()
{
return 0;
}
virtual void Render()
{
}
int typeAsTarget()
{
return TARGET_STACKACTION;
}
Interruptible(bool hasFocus = false) : PlayGuiObject(40,x,y,hasFocus)
{
state = NOT_RESOLVED;
display = 0;
source = NULL;
}
virtual const string getDisplayName() const;
void Render(MTGCardInstance * source, JQuad * targetQuad, string alt1, string alt2, string action, bool bigQuad = false);
virtual int receiveEvent(WEvent * event)
{
return 0;
}
int state, display;
MTGCardInstance * source;
virtual void Entering(){mHasFocus = true;};
virtual bool Leaving(JButton key){mHasFocus = false;return true;};
virtual bool ButtonPressed(){return true;};
virtual int resolve(){return 0;};
virtual void Render(){};
int typeAsTarget(){return TARGET_STACKACTION;};
Interruptible(bool hasFocus = false):PlayGuiObject(40,x,y,hasFocus){state=NOT_RESOLVED;display=0;source=NULL;};
virtual const string getDisplayName() const;
void Render(MTGCardInstance * source, JQuad * targetQuad, string alt1, string alt2, string action, bool bigQuad = false);
virtual int receiveEvent(WEvent * event) {return 0;};
#if defined (WIN32) || defined (LINUX) || defined (IOS)
virtual void Dump();
virtual void Dump();
#endif
protected:
float GetVerticalTextOffset() const;
float GetVerticalTextOffset() const;
};
class NextGamePhase: public Interruptible {
public:
int resolve();
bool extraDamagePhase();
void Render();
virtual ostream& toString(ostream& out) const;
virtual const string getDisplayName() const;
NextGamePhase(int id);
class NextGamePhase: public Interruptible
{
public:
int resolve();
bool extraDamagePhase();
void Render();
virtual ostream& toString(ostream& out) const;
virtual const string getDisplayName() const;
NextGamePhase(int id);
};
class Spell: public Interruptible {
protected:
class Spell: public Interruptible
{
protected:
public:
MTGGameZone * from;
TargetChooser * tc;
ManaCost * cost;
int payResult;
int computeX(MTGCardInstance * card);
int computeXX(MTGCardInstance * card);
Spell(MTGCardInstance* _source);
Spell(int id, MTGCardInstance* _source, TargetChooser *_tc, ManaCost * _cost, int payResult);
~Spell();
int resolve();
void Render();
bool FullfilledAlternateCost(const int &costType);
const string getDisplayName() const;
virtual ostream& toString(ostream& out) const;
MTGCardInstance * getNextCardTarget(MTGCardInstance * previous = 0);
Player * getNextPlayerTarget(Player * previous = 0);
Damageable * getNextDamageableTarget(Damageable * previous = 0);
Interruptible * getNextInterruptible(Interruptible * previous, int type);
Spell * getNextSpellTarget(Spell * previous = 0);
Damage * getNextDamageTarget(Damage * previous = 0);
Targetable * getNextTarget(Targetable * previous = 0, int type = -1);
int getNbTargets();
public:
MTGGameZone * from;
TargetChooser * tc;
ManaCost * cost;
int payResult;
int computeX(MTGCardInstance * card);
int computeXX(MTGCardInstance * card);
Spell(MTGCardInstance* _source);
Spell(int id, MTGCardInstance* _source, TargetChooser *_tc, ManaCost * _cost, int payResult);
~Spell();
int resolve();
void Render();
bool FullfilledAlternateCost(const int &costType);
const string getDisplayName() const;
virtual ostream& toString(ostream& out) const;
MTGCardInstance * getNextCardTarget(MTGCardInstance * previous = 0);
Player * getNextPlayerTarget(Player * previous = 0);
Damageable * getNextDamageableTarget(Damageable * previous = 0);
Interruptible * getNextInterruptible(Interruptible * previous, int type);
Spell * getNextSpellTarget(Spell * previous = 0);
Damage * getNextDamageTarget(Damage * previous = 0);
Targetable * getNextTarget(Targetable * previous = 0, int type = -1);
int getNbTargets();
};
class StackAbility: public Interruptible {
public:
MTGAbility * ability;
int resolve();
void Render();
virtual ostream& toString(ostream& out) const;
virtual const string getDisplayName() const;
StackAbility(int id, MTGAbility * _ability);
class StackAbility: public Interruptible
{
public:
MTGAbility * ability;
int resolve();
void Render();
virtual ostream& toString(ostream& out) const;
virtual const string getDisplayName() const;
StackAbility(int id, MTGAbility * _ability);
};
class PutInGraveyard: public Interruptible {
public:
MTGCardInstance * card;
int removeFromGame;
int resolve();
void Render();
virtual ostream& toString(ostream& out) const;
PutInGraveyard(int id, MTGCardInstance * _card);
public:
MTGCardInstance * card;
int removeFromGame;
int resolve();
void Render();
virtual ostream& toString(ostream& out) const;
PutInGraveyard(int id, MTGCardInstance * _card);
};
class DrawAction: public Interruptible {
public:
int nbcards;
Player * player;
int resolve();
void Render();
virtual ostream& toString(ostream& out) const;
DrawAction(int id, Player * _player, int _nbcards);
class DrawAction: public Interruptible
{
public:
int nbcards;
Player * player;
int resolve();
void Render();
virtual ostream& toString(ostream& out) const;
DrawAction(int id, Player * _player, int _nbcards);
};
class LifeAction: public Interruptible {
public:
int amount;
Damageable * target;
int resolve();
void Render();
virtual ostream& toString(ostream& out) const;
LifeAction(int id, Damageable * _target, int amount);
class LifeAction: public Interruptible
{
public:
int amount;
Damageable * target;
int resolve();
void Render();
virtual ostream& toString(ostream& out) const;
LifeAction(int id, Damageable * _target, int amount);
};
class ActionStack :public GuiLayer{
protected:
JQuad * pspIcons[8];
GameObserver* game;
int interruptDecision[2];
float timer;
int currentState;
int mode;
int checked;
class ActionStack :public GuiLayer
{
protected:
JQuadPtr pspIcons[8];
GameObserver* game;
int interruptDecision[2];
float timer;
int currentState;
int mode;
int checked;
public:
public:
enum
{
NOT_DECIDED = 0,
INTERRUPT = -1,
DONT_INTERRUPT = 1,
DONT_INTERRUPT_ALL = 2,
};
enum
{
NOT_DECIDED = 0,
INTERRUPT = -1,
DONT_INTERRUPT = 1,
DONT_INTERRUPT_ALL = 2,
};
int setIsInterrupting(Player * player);
int count( int type = 0 , int state = 0 , int display = -1);
Interruptible * getPrevious(Interruptible * next, int type = 0, int state = 0 , int display = -1);
int getPreviousIndex(Interruptible * next, int type = 0, int state = 0 , int display = -1);
Interruptible * getNext(Interruptible * previous, int type = 0, int state = 0 , int display = -1);
int getNextIndex(Interruptible * previous, int type = 0, int state = 0 , int display = -1);
void Fizzle(Interruptible * action);
Interruptible * getAt(int id);
void cancelInterruptOffer(int cancelMode = 1);
void endOfInterruption();
Interruptible * getLatest(int state);
Player * askIfWishesToInterrupt;
int garbageCollect();
int addAction(Interruptible * interruptible);
Spell * addSpell(MTGCardInstance* card, TargetChooser * tc, ManaCost * mana, int payResult, int storm);
int AddNextGamePhase();
int AddNextCombatStep();
int addPutInGraveyard(MTGCardInstance * card);
int addDraw(Player * player, int nbcards = 1);
int addLife(Damageable * _target,int amount = 0);
int addDamage(MTGCardInstance * _source, Damageable * target, int _damage);
int addAbility(MTGAbility * ability);
void Update(float dt);
bool CheckUserInput(JButton key);
virtual void Render();
ActionStack(GameObserver* game);
int resolve();
int has(Interruptible * action);
int has(MTGAbility * ability);
int receiveEventPlus(WEvent * event);
int setIsInterrupting(Player * player);
int count( int type = 0 , int state = 0 , int display = -1);
Interruptible * getPrevious(Interruptible * next, int type = 0, int state = 0 , int display = -1);
int getPreviousIndex(Interruptible * next, int type = 0, int state = 0 , int display = -1);
Interruptible * getNext(Interruptible * previous, int type = 0, int state = 0 , int display = -1);
int getNextIndex(Interruptible * previous, int type = 0, int state = 0 , int display = -1);
void Fizzle(Interruptible * action);
Interruptible * getAt(int id);
void cancelInterruptOffer(int cancelMode = 1);
void endOfInterruption();
Interruptible * getLatest(int state);
Player * askIfWishesToInterrupt;
int garbageCollect();
int addAction(Interruptible * interruptible);
Spell * addSpell(MTGCardInstance* card, TargetChooser * tc, ManaCost * mana, int payResult, int storm);
int AddNextGamePhase();
int AddNextCombatStep();
int addPutInGraveyard(MTGCardInstance * card);
int addDraw(Player * player, int nbcards = 1);
int addLife(Damageable * _target,int amount = 0);
int addDamage(MTGCardInstance * _source, Damageable * target, int _damage);
int addAbility(MTGAbility * ability);
void Update(float dt);
bool CheckUserInput(JButton key);
virtual void Render();
ActionStack(GameObserver* game);
int resolve();
int has(Interruptible * action);
int has(MTGAbility * ability);
int receiveEventPlus(WEvent * event);
#if defined (WIN32) || defined (LINUX) || defined (IOS)
void Dump();
void Dump();
#endif
};
#endif

View File

@@ -16,7 +16,7 @@ namespace DrawMode
{
enum
{
kNormal,
kNormal = 0,
kText,
kHidden
};
@@ -28,8 +28,8 @@ struct CardGui: public PlayGuiObject
protected:
/*
** Tries to render the Big version of a card picture, backups to text version in case of failure
*/
** 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);
@@ -51,7 +51,7 @@ public:
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);
static JQuadPtr AlternateThumbQuad(MTGCard * card);
virtual ostream& toString(ostream&) const;
};
@@ -75,12 +75,12 @@ public:
{
CardGui::Render();
}
;
void Render(JQuad* q)
{
Pos::Render(q);
}
;
virtual ostream& toString(ostream&) const;
float GetCenterX();

View File

@@ -31,7 +31,7 @@ private:
int isRandomDeckUnlocked();
int IsMoreAIDecksUnlocked(DeckStats * stats);
string unlockedTextureName;
JQuad * GetUnlockedQuad(string texturename);
JQuadPtr GetUnlockedQuad(string texturename);
public:
int value;
Player * p1, *p2;

View File

@@ -4,6 +4,7 @@
#include <JGui.h>
#include "GuiLayers.h"
#include "ActionStack.h"
#include "WResource_Fwd.h"
class GuiLayer;
class JGuiObject;
@@ -17,7 +18,8 @@ class GameObserver;
#define DAMAGE_COMBAT 1
#define DAMAGE_OTHER 2
class Damageable:public Targetable {
class Damageable:public Targetable
{
protected:
public:
int life;
@@ -33,10 +35,11 @@ public:
virtual int afterDamage(){return 0;}
virtual int poisoned(){return 0;}
virtual int prevented(){return 0;}
virtual JQuad * getIcon(){return NULL;};
virtual JQuadPtr getIcon(){return JQuadPtr();}
};
class Damage: public Interruptible {
class Damage: public Interruptible
{
protected:
void init(MTGCardInstance * source, Damageable * target, int damage, int typeOfDamage);
public:
@@ -50,8 +53,8 @@ class Damage: public Interruptible {
virtual ostream& toString(ostream& out) const;
};
class DamageStack : public GuiLayer, public Interruptible{
class DamageStack : public GuiLayer, public Interruptible
{
protected:
int currentState;
GameObserver* game;

View File

@@ -53,7 +53,7 @@ public:
float mSelectionTargetY;
//used for detailed info button
JQuad * pspIcons[8];
JQuadPtr pspIcons[8];
JTexture * pspIconsTexture;
DeckMenu(int id, JGuiListener* listener, int fontId, const string _title = "", const int& startIndex = 0, bool alwaysShowDetailsButton = false);

View File

@@ -83,6 +83,6 @@ public:
};
extern JQuad* manaIcons[7];
extern JQuadPtr manaIcons[7];
#endif

View File

@@ -81,8 +81,8 @@ enum DECK_VIEWER_MENU_ITEMS
class GameStateDeckViewer: public GameState, public JGuiListener
{
private:
JQuad * mIcons[CARDS_DISPLAYED];
JQuad * pspIcons[8];
JQuadPtr mIcons[CARDS_DISPLAYED];
JQuadPtr pspIcons[8];
JTexture * pspIconsTexture;
float last_user_activity;
float onScreenTransition;
@@ -92,7 +92,6 @@ private:
int mStage;
int useFilter;
JMusic * bgMusic;
JQuad * backQuad;
int lastPos;
int lastTotal;

View File

@@ -16,10 +16,9 @@ private:
SimpleMenu* subMenuController;
SimpleMenu* gameTypeMenu;
int hasChosenGameType;
JQuad * mIcons[10];
JQuadPtr mIcons[10];
JTexture * bgTexture;
JQuad * mBg;
JQuad * mSplash;
JQuadPtr mBg;
JTexture * splashTex;
float mCreditsYPos;
int currentState;

View File

@@ -61,10 +61,9 @@ private:
class GameStateShop: public GameState, public JGuiListener
{
private:
JQuad * pspIcons[8];
JQuadPtr pspIcons[8];
WSrcCards * srcCards;
JTexture * altThumb[8];
JQuad * mBack;
TaskList * taskList;
float mElapsed;
WGuiMenu * shopMenu;

View File

@@ -3,11 +3,11 @@
#include "GuiLayers.h"
class GuiFrame: public GuiLayer
class GuiFrame : public GuiLayer
{
protected:
JQuad* wood;
JQuad* gold1, *gold2, *goldGlow;
JQuadPtr wood;
JQuadPtr gold1, gold2, goldGlow;
float step;
public:

View File

@@ -9,7 +9,7 @@
class GuiHand;
struct HandLimitor: public Limitor
struct HandLimitor : public Limitor
{
GuiHand* hand;
virtual bool select(Target*);
@@ -18,7 +18,7 @@ struct HandLimitor: public Limitor
HandLimitor(GuiHand* hand);
};
class GuiHand: public GuiLayer
class GuiHand : public GuiLayer
{
public:
static const float ClosedRowX;
@@ -32,7 +32,7 @@ public:
protected:
const MTGHand* hand;
JQuad *back;
JQuadPtr back;
vector<CardView*> cards;
public:
@@ -44,7 +44,7 @@ public:
friend struct HandLimitor;
};
class GuiHandOpponent: public GuiHand
class GuiHandOpponent : public GuiHand
{
public:
GuiHandOpponent(MTGHand* hand);
@@ -53,12 +53,13 @@ public:
virtual int receiveEventMinus(WEvent* e);
};
class GuiHandSelf: public GuiHand
class GuiHandSelf : public GuiHand
{
protected:
typedef enum
{
Open, Closed
Open,
Closed
} HandState;
HandState state;
Pos backpos;
@@ -79,7 +80,6 @@ public:
{
return state;
}
;
HandLimitor* limitor;
};

View File

@@ -6,10 +6,10 @@
#include "GameApp.h"
#include "GuiLayers.h"
class ManaIcon: public Pos
class ManaIcon : public Pos
{
hgeParticleSystem* particleSys;
JQuad* icon;
JQuadPtr icon;
float zoomP1, zoomP2, zoomP3, zoomP4, zoomP5, zoomP6;
float xP1, xP2, xP3;
@@ -35,7 +35,7 @@ public:
~ManaIcon();
};
class GuiMana: public GuiLayer
class GuiMana : public GuiLayer
{
protected:
vector<ManaIcon*> manas;

View File

@@ -183,7 +183,7 @@ class MTGCardInstance: public CardPrimitive, public MTGCard, public Damageable {
int isInPlay();
JSample * getSample();
JQuad * getIcon();
JQuadPtr getIcon();
ostream& toString(ostream&) const;

View File

@@ -141,6 +141,7 @@ public:
virtual void confirmChange(bool confirmed);
OptionThemeStyle(string _displayValue);
};
class OptionDirectory: public OptionSelect
{
public:
@@ -157,7 +158,7 @@ private:
static const string DIRTESTER;
public:
OptionTheme(OptionThemeStyle * style = NULL);
JQuad * getImage();
JQuadPtr getImage();
virtual void updateValue();
virtual float getHeight();
virtual void Render();

View File

@@ -25,7 +25,7 @@ public:
};
JTexture * mAvatarTex;
JQuad * mAvatar;
JQuadPtr mAvatar;
int playMode;
bool canPutLandsIntoPlay;
int landsPlayerCanStillPlay;
@@ -88,7 +88,7 @@ public:
Player * opponent();
int getId();
JQuad * getIcon();
JQuadPtr getIcon();
virtual int receiveEvent(WEvent * event)
{

View File

@@ -1,6 +1,6 @@
/*
A class for very simple menus structure
*/
A class for very simple menus structure
*/
#ifndef _SIMPLEMENU_H_
#define _SIMPLEMENU_H_
@@ -9,6 +9,8 @@
#include "WFont.h"
#include "hge/hgeparticle.h"
#include "WResource_Fwd.h"
class SimpleMenu: public JGuiController
{
private:
@@ -21,7 +23,7 @@ private:
float timeOpen;
bool mClosed;
static JQuad *spadeR, *spadeL, *jewel, *side;
static JQuadPtr spadeR, spadeL, jewel, side;
static JTexture *spadeRTex, *spadeLTex, *jewelTex, *sideTex;
static WFont* titleFont;
static hgeParticleSystem* stars;

View File

@@ -8,6 +8,8 @@
#define INVALID_MTEX -1
#endif
#include "WResource_Fwd.h"
class WResource
{
public:
@@ -18,118 +20,105 @@ public:
WResource();
virtual ~WResource();
virtual unsigned long size()=0; //Size of cached item in bytes.
virtual bool isGood()=0; //Return true if this has data.
virtual bool isLocked(); //Is the resource locked?
virtual void lock(); //Lock it.
virtual void unlock(bool force = false); //Unlock it. Forcing a lock will also remove "permanent" status.
virtual unsigned long size() = 0; //Size of cached item in bytes.
virtual bool isGood() = 0; //Return true if this has data.
virtual bool isLocked(); //Is the resource locked?
virtual void lock(); //Lock it.
virtual void unlock(bool force = false); //Unlock it. Forcing a lock will also remove "permanent" status.
bool isPermanent(); //Is the resource permanent?
void deadbolt(); //Make it permanent.
void hit(); //Update resource's last used time.
bool isPermanent(); //Is the resource permanent?
void deadbolt(); //Make it permanent.
void hit(); //Update resource's last used time.
protected:
int loadedMode; //What submode settings were we loaded with? (For refresh)
unsigned int lastTime; //When was the last time we were hit?
unsigned char locks; //Remember to unlock when we're done using locked stuff, or else this'll be useless.
int loadedMode; //What submode settings were we loaded with? (For refresh)
unsigned int lastTime; //When was the last time we were hit?
unsigned char locks; //Remember to unlock when we're done using locked stuff, or else this'll be useless.
};
class WCachedResource: public WResource
{
public:
friend class WResourceManager;
template<class cacheItem, class cacheActual> friend class WCache;
template<class cacheItem,class cacheActual> friend class WCache;
virtual ~WCachedResource();
string mFilename;
virtual void Refresh()=0; //Basically calls Attempt(filename) and remaps in situ.
virtual bool Attempt(string filename, int submode, int & error)=0; //Returns true if we've loaded our data and isGood().
};
class WTrackedQuad: public WResource
{
public:
WTrackedQuad(string _resname);
~WTrackedQuad();
bool isGood();
unsigned long size();
string resname;
JQuad * quad;
virtual void Refresh() = 0; //Basically calls Attempt(filename) and remaps in situ.
virtual bool Attempt(const string& filename, int submode, int & error) = 0; //Returns true if we've loaded our data and isGood().
};
class WCachedTexture: public WCachedResource
{
public:
friend class WResourceManager;
template<class cacheItem, class cacheActual> friend class WCache;
template<class cacheItem,class cacheActual> friend class WCache;
WCachedTexture();
~WCachedTexture();
void Refresh();
unsigned long size();
bool isGood();
bool isLocked(); //Is the resource locked?
bool Attempt(string filename, int submode, int & error);
bool isLocked(); //Is the resource locked?
bool Attempt(const string& filename, int submode, int & error);
bool compare(JTexture * t)
{
return (t == texture);
}
;
JTexture * Actual(); //Return this texture as is. Does not make a new one.
JQuad * GetQuad(string resname);
WTrackedQuad
* GetTrackedQuad(float offX = 0.0f, float offY = 0.0f, float width = 0.0f, float height = 0.0f, string resname = ""); //Get us a new/existing quad.
JTexture* Actual(); //Return this texture as is. Does not make a new one.
JQuadPtr GetQuad(const string& resname);
JQuad * GetQuad(float offX = 0.0f, float offY = 0.0f, float width = 0.0f, float height = 0.0f, string resname = ""); //Alias to GetTrackedQuad.
JQuad * GetCard(float offX = 0.0f, float offY = 0.0f, float width = 0.0f, float height = 0.0f, string resname = ""); //Same as above, but centered when new.
JQuadPtr GetQuad(float offX = 0.0f, float offY = 0.0f, float width = 0.0f, float height = 0.0f, const string& resname="");
JQuadPtr GetCard(float offX = 0.0f, float offY = 0.0f, float width = 0.0f, float height = 0.0f, const string& resname=""); //Same as above, but centered when new.
bool ReleaseQuad(JQuad* quad); //We're done with this quad, so delete and stop tracking. True if existed.
protected:
JTexture * texture;
vector<WTrackedQuad*> trackedQuads;
JTexture* texture;
map<string, JQuadPtr> mTrackedQuads;
};
class WCachedParticles: public WCachedResource
{
public:
friend class WResourceManager;
template<class cacheItem, class cacheActual> friend class WCache;
template<class cacheItem,class cacheActual> friend class WCache;
WCachedParticles();
~WCachedParticles();
void Refresh();
unsigned long size();
bool isGood();
bool Attempt(string filename, int submode, int & error);
bool Attempt(const string& filename, int submode, int& error);
bool compare(hgeParticleSystemInfo * p)
{
return (p == particles);
}
;
hgeParticleSystemInfo * Actual();
hgeParticleSystemInfo* Actual();
protected:
hgeParticleSystemInfo * particles;
hgeParticleSystemInfo* particles;
};
class WCachedSample: public WCachedResource
{
public:
friend class WResourceManager;
template<class cacheItem, class cacheActual> friend class WCache;
template<class cacheItem,class cacheActual> friend class WCache;
WCachedSample();
~WCachedSample();
bool compare(JSample * s)
{
return (s == sample);
}
;
unsigned long size();
bool isGood();
void Refresh();
bool Attempt(string filename, int submode, int & error);
bool Attempt(const string& filename, int submode, int & error);
JSample * Actual(); //Return this sample.
protected:

View File

@@ -1,6 +1,8 @@
#ifndef _WDATASRC_H_
#define _WDATASRC_H_
#include "WResource_Fwd.h"
class WCardFilter;
struct WCardSort;
struct WDistort;
@@ -18,24 +20,24 @@ public:
hooked = NULL;
currentPos = 0;
}
;
virtual ~WSyncable()
{
}
;
//Local
virtual bool Hook(WSyncable* s);
virtual int getOffset()
{
return currentPos;
}
;
virtual bool setOffset(int i)
{
currentPos = i;
return true;
}
;
//Recursive
virtual int getPos();
virtual bool next();
@@ -51,47 +53,48 @@ public:
WDataSource()
{
}
;
virtual JQuad * getImage(int offset = 0)
virtual JQuadPtr getImage(int offset = 0)
{
return NULL;
return JQuadPtr();
}
;
virtual JQuad * getThumb(int offset = 0)
virtual JQuadPtr getThumb(int offset = 0)
{
return NULL;
return JQuadPtr();
}
;
virtual MTGCard * getCard(int offset = 0, bool ignore = false)
{
return NULL;
}
;
virtual MTGDeck * getDeck(int offset = 0)
{
return NULL;
}
;
virtual WDistort * getDistort(int offset = 0)
{
return NULL;
}
;
virtual bool thisCard(int mtgid)
{
return false;
}
;
virtual int getControlID()
{
return -1;
}
; //TODO FIXME: Need a "not a valid button" define.
//TODO FIXME: Need a "not a valid button" define.
virtual void Update(float dt)
{
mLastInput += dt;
}
;
virtual void Touch()
{
mLastInput = 0;
@@ -101,12 +104,12 @@ public:
{
return mLastInput;
}
;
virtual void setElapsed(float f)
{
mLastInput = f;
}
;
protected:
float mLastInput;
};
@@ -114,7 +117,7 @@ protected:
class WSrcImage: public WDataSource
{
public:
virtual JQuad * getImage(int offset = 0);
virtual JQuadPtr getImage(int offset = 0);
WSrcImage(string s);
protected:
@@ -133,8 +136,8 @@ public:
WSrcCards(float delay = 0.2);
~WSrcCards();
virtual JQuad * getImage(int offset = 0);
virtual JQuad * getThumb(int offset = 0);
virtual JQuadPtr getImage(int offset = 0);
virtual JQuadPtr getThumb(int offset = 0);
virtual MTGCard * getCard(int offset = 0, bool ignore = false);
virtual int Size(bool all = false); //Returns the number of cards, or the number of cards that match the filter.
@@ -171,7 +174,6 @@ public:
{
return filtersRoot;
}
;
enum
{
@@ -191,141 +193,141 @@ public:
void swapSrc();
//Wrapped functions
JQuad * getImage(int offset = 0)
JQuadPtr getImage(int offset = 0)
{
return active->getImage(offset);
}
;
JQuad * getThumb(int offset = 0)
JQuadPtr getThumb(int offset = 0)
{
return active->getThumb(offset);
}
;
MTGCard * getCard(int offset = 0, bool ignore = false)
{
return active->getCard(offset, ignore);
}
;
int Size(bool all = false)
{
return active->Size();
}
;
WCardFilter * getfiltersRoot()
{
return active->getFiltersRoot();
}
;
void Shuffle()
{
active->Shuffle();
}
;
bool thisCard(int mtgid)
{
return active->thisCard(mtgid);
}
;
bool next()
{
return active->next();
}
;
bool prev()
{
return active->prev();
}
;
void Sort(int method)
{
active->Sort(method);
}
;
bool setOffset(int pos)
{
return active->setOffset(pos);
}
;
bool isEmptySet(WCardFilter * f)
{
return active->isEmptySet(f);
}
;
void addFilter(WCardFilter * f)
{
active->addFilter(f);
}
;
void clearFilters()
{
active->clearFilters();
}
;
WCardFilter* unhookFilters()
{
return active->unhookFilters();
}
;
bool matchesFilters(MTGCard * c)
{
return active->matchesFilters(c);
}
;
void validate()
{
active->validate();
}
;
void bakeFilters()
{
active->bakeFilters();
}
; //Discards all invalidated cards.
//Discards all invalidated cards.
float filterFee()
{
return active->filterFee();
}
;
void updateCounts()
{
active->updateCounts();
}
;
void clearCounts()
{
active->clearCounts();
}
;
void addCount(MTGCard * c, int qty = 1)
{
active->addCount(c, qty);
}
;
int loadMatches(MTGAllCards* ac)
{
return active->loadMatches(ac);
}
;
int loadMatches(MTGDeck * deck)
{
return active->loadMatches(deck);
}
;
int loadMatches(WSrcCards* src, bool all = false)
{
return loadMatches(src, all);
}
;
int addRandomCards(MTGDeck * i, int howmany = 1)
{
return active->addRandomCards(i, howmany);
}
;
int addToDeck(MTGDeck * i, int num = -1)
{
return active->addToDeck(i, num);
}
;
protected:
WSrcCards * active;
WSrcCards * inactive;

View File

@@ -5,12 +5,13 @@
#include <JTypes.h>
#include "MTGDeck.h"
#include "MTGCard.h"
#include "utils.h"
#include "WCachedResource.h"
#include "WFont.h"
#define HUGE_CACHE_LIMIT 20000000 // Size of the cache for Windows and Linux
#define SAMPLES_CACHE_SIZE 1500000 // Size in bytes of the cached samples
#define PSI_CACHE_SIZE 500000 // Size in bytes of the cahed particles
#define PSI_CACHE_SIZE 500000 // Size in bytes of the cached particles
#define TEXTURES_CACHE_MINSIZE 2000000 // Minimum size of the cache on the PSP. The program should complain if the cache ever gets smaller than this
#define OPERATIONAL_SIZE 5000000 // Size required by Wagic for operational stuff. 3MB is not enough. The cache will usually try to take (Total Ram - Operational size)
#define MIN_LINEAR_RAM 1500000
@@ -20,6 +21,7 @@
#define MAX_CACHE_TIME 2000000000
#endif
#define THUMBNAILS_OFFSET 100000000
#define OTHERS_OFFSET 2000000000
@@ -30,41 +32,39 @@
#define MAX_CACHED_SAMPLES 50
#define MAX_CACHE_GARBAGE 10
enum ENUM_WRES_INFO
{
WRES_UNLOCKED = 0, //Resource is unlocked.
WRES_MAX_LOCK = 250, //Maximum number of locks for a resource.
WRES_PERMANENT = 251, //Resource is permanent (ie, managed)
WRES_UNDERLOCKED = 252,
//Resource was released too many times.
WRES_UNLOCKED = 0, //Resource is unlocked.
WRES_MAX_LOCK = 250, //Maximum number of locks for a resource.
WRES_PERMANENT = 251, //Resource is permanent (ie, managed)
WRES_UNDERLOCKED = 252, //Resource was released too many times.
};
enum ENUM_RETRIEVE_STYLE
{
RETRIEVE_EXISTING, //Only returns a resource if it already exists. Does not lock or unlock.
RETRIEVE_NORMAL, //Returns or creates a resource. Does not change lock status.
RETRIEVE_LOCK, //As above, locks cached resource. Not for quads.
RETRIEVE_UNLOCK, //As above, unlocks cached resource. Not for quads.
RETRIEVE_RESOURCE, //Only retrieves a managed resource. Does not make a new one.
RETRIEVE_MANAGE, //Makes resource permanent.
RETRIEVE_THUMB, //Retrieve it as a thumbnail.
CACHE_THUMB = RETRIEVE_THUMB,
//Backwords compatibility.
RETRIEVE_EXISTING, //Only returns a resource if it already exists. Does not lock or unlock.
RETRIEVE_NORMAL, //Returns or creates a resource. Does not change lock status.
RETRIEVE_LOCK, //As above, locks cached resource. Not for quads.
RETRIEVE_UNLOCK, //As above, unlocks cached resource. Not for quads.
RETRIEVE_RESOURCE, //Only retrieves a managed resource. Does not make a new one.
RETRIEVE_MANAGE, //Makes resource permanent.
RETRIEVE_THUMB, //Retrieve it as a thumbnail.
CACHE_THUMB = RETRIEVE_THUMB, //Backwards compatibility.
};
enum ENUM_CACHE_SUBTYPE
{
CACHE_NORMAL = (1 << 0), //Use default values. Not really a flag.
CACHE_EXISTING = (1 << 1), //Retrieve it only if it already exists
CACHE_NORMAL = (1<<0), //Use default values. Not really a flag.
CACHE_EXISTING = (1<<1), //Retrieve it only if it already exists
//Because these bits only modify how a cached resource's Attempt() is called,
//We can use them over and over for each resource type.
TEXTURE_SUB_EXACT = (1 << 2), //Don't do any fiddling with the filename.
TEXTURE_SUB_CARD = (1 << 3), //Retrieve using cardFile, not graphicsFile.
TEXTURE_SUB_AVATAR = (1 << 4), //Retrieve using avatarFile, not graphicsFile.
TEXTURE_SUB_THUMB = (1 << 5),//Retrieve prepending "thumbnails\" to the filename.
TEXTURE_SUB_5551 = (1 << 6),
//For textures. If we have to allocate, use RGBA5551.
TEXTURE_SUB_EXACT = (1<<2), //Don't do any fiddling with the filename.
TEXTURE_SUB_CARD = (1<<3), //Retrieve using cardFile, not graphicsFile.
TEXTURE_SUB_AVATAR = (1<<4), //Retrieve using avatarFile, not graphicsFile.
TEXTURE_SUB_THUMB = (1<<5), //Retrieve prepending "thumbnails\" to the filename.
TEXTURE_SUB_5551 = (1<<6), //For textures. If we have to allocate, use RGBA5551.
};
@@ -73,8 +73,8 @@ enum ENUM_CACHE_ERROR
CACHE_ERROR_NONE = 0,
CACHE_ERROR_NOT_CACHED = CACHE_ERROR_NONE,
CACHE_ERROR_404,
CACHE_ERROR_BAD, //Something went wrong with item->attempt()
CACHE_ERROR_BAD_ALLOC, //Couldn't allocate item
CACHE_ERROR_BAD, //Something went wrong with item->attempt()
CACHE_ERROR_BAD_ALLOC, //Couldn't allocate item
CACHE_ERROR_LOST,
CACHE_ERROR_NOT_MANAGED,
};
@@ -84,7 +84,7 @@ struct WCacheSort
bool operator()(const WResource * l, const WResource * r); //Predicate for use in sorting. See flatten().
};
template<class cacheItem, class cacheActual>
template <class cacheItem, class cacheActual>
class WCache
{
public:
@@ -93,13 +93,13 @@ public:
WCache();
~WCache();
cacheItem* Retrieve(int id, const string& filename, int style = RETRIEVE_NORMAL, int submode = CACHE_NORMAL); //Primary interface function.
cacheItem* Retrieve(int id, const string& filename, int style = RETRIEVE_NORMAL, int submode = CACHE_NORMAL); //Primary interface function.
bool Release(cacheActual* actual); //Releases an item, and deletes it if unlocked.
bool RemoveMiss(int id = 0); //Removes a cache miss.
bool RemoveOldest(); //Remove oldest unlocked item.
bool Cleanup(); //Repeats RemoveOldest() until cache fits in size limits
void ClearUnlocked(); //Remove all unlocked items.
void Refresh(); //Refreshes all cache items.
bool RemoveMiss(int id=0); //Removes a cache miss.
bool RemoveOldest(); //Remove oldest unlocked item.
bool Cleanup(); //Repeats RemoveOldest() until cache fits in size limits
void ClearUnlocked(); //Remove all unlocked items.
void Refresh(); //Refreshes all cache items.
unsigned int Flatten(); //Ensures that the times don't loop. Returns new lastTime.
void Resize(unsigned long size, int items); //Sets new limits, then enforces them. Lock safe, so not a "hard limit".
protected:
@@ -127,12 +127,11 @@ protected:
struct WManagedQuad
{
WCachedTexture * texture;
WCachedTexture* texture;
string resname;
};
//This class is a wrapper for JResourceManager
class WResourceManager: public JResourceManager
class WResourceManager
{
public:
static WResourceManager* Instance()
@@ -154,11 +153,11 @@ public:
virtual ~WResourceManager();
void Unmiss(string filename);
JQuad * RetrieveCard(MTGCard * card, int style = RETRIEVE_NORMAL, int submode = CACHE_NORMAL);
JQuadPtr RetrieveCard(MTGCard * card, int style = RETRIEVE_NORMAL,int submode = CACHE_NORMAL);
JSample * RetrieveSample(const string& filename, int style = RETRIEVE_NORMAL, int submode = CACHE_NORMAL);
JTexture * RetrieveTexture(const string& filename, int style = RETRIEVE_NORMAL, int submode = CACHE_NORMAL);
JQuad * RetrieveQuad(const string& filename, float offX = 0.0f, float offY = 0.0f, float width = 0.0f, float height = 0.0f, string resname = "", int style = RETRIEVE_LOCK, int submode = CACHE_NORMAL, int id = 0);
JQuad * RetrieveTempQuad(const string& filename, int submode = CACHE_NORMAL);
JQuadPtr RetrieveQuad(const string& filename, float offX=0.0f, float offY=0.0f, float width=0.0f, float height=0.0f, string resname="", int style = RETRIEVE_LOCK, int submode = CACHE_NORMAL, int id = 0);
JQuadPtr RetrieveTempQuad(const string& filename, int submode = CACHE_NORMAL);
hgeParticleSystemInfo * RetrievePSI(const string& filename, JQuad * texture, int style = RETRIEVE_NORMAL, int submode = CACHE_NORMAL);
int RetrieveError();
@@ -166,9 +165,8 @@ public:
void Release(JSample * sample);
bool RemoveOldest();
bool Cleanup(); //Force a cleanup. Return false if nothing removed.
void ClearUnlocked(); //Remove unlocked items.
void Refresh(); //Refreshes all files in cache, for when mode/profile changes.
void Refresh(); //Refreshes all files in cache, for when mode/profile changes.
unsigned int nowTime();
@@ -181,8 +179,8 @@ public:
unsigned int CountManaged();
int CreateQuad(const string &quadName, const string &textureName, float x, float y, float width, float height);
JQuad* GetQuad(const string &quadName);
JQuad* GetQuad(int id);
JQuadPtr GetQuad(const string &quadName);
JQuadPtr GetQuad(int id);
int AddQuadToManaged(const WManagedQuad& inManagedQuad);
@@ -222,17 +220,17 @@ public:
private:
/*
** Singleton object only accessibly via Instance(), constructor is private
*/
** Singleton object only accessibly via Instance(), constructor is private
*/
WResourceManager();
bool bThemedCards; //Does the theme have a "sets" directory for overwriting cards?
void FlattenTimes(); //To prevent bad cache timing on int overflow
bool bThemedCards; //Does the theme have a "sets" directory for overwriting cards?
void FlattenTimes(); //To prevent bad cache timing on int overflow
//For cached stuff
WCache<WCachedTexture, JTexture> textureWCache;
WCache<WCachedSample, JSample> sampleWCache;
WCache<WCachedParticles, hgeParticleSystemInfo> psiWCache;
WCache<WCachedTexture,JTexture> textureWCache;
WCache<WCachedSample,JSample> sampleWCache;
WCache<WCachedParticles,hgeParticleSystemInfo> psiWCache;
typedef std::map<std::string, WManagedQuad> ManagedQuadMap;
ManagedQuadMap mManagedQuads;

View File

@@ -0,0 +1,8 @@
#ifndef WRESOURCE_FWD_H
#define WRESOURCE_FWD_H
#include <boost/shared_ptr.hpp>
typedef boost::shared_ptr<JQuad> JQuadPtr;
#endif

View File

@@ -1275,9 +1275,7 @@ AIPlayerBaka::AIPlayerBaka(MTGDeck * deck, string file, string fileSmall, string
if (mAvatarTex)
mAvatar = WResourceManager::Instance()->RetrieveQuad(avatarFile, 0, 0, 35, 50, "bakaAvatar", RETRIEVE_NORMAL,
TEXTURE_SUB_AVATAR);
else
mAvatar = NULL;
TEXTURE_SUB_AVATAR);
initTimer();
}

View File

@@ -96,14 +96,14 @@ void Interruptible::Render(MTGCardInstance * source, JQuad * targetQuad, string
mFont->DrawString(_(action).c_str(), x + 35, y + GetVerticalTextOffset(), JGETEXT_LEFT);
JRenderer * renderer = JRenderer::GetInstance();
JQuad * quad = WResourceManager::Instance()->RetrieveCard(source, CACHE_THUMB);
if (!quad)
JQuadPtr quad = WResourceManager::Instance()->RetrieveCard(source, CACHE_THUMB);
if (!quad.get())
quad = CardGui::AlternateThumbQuad(source);
if (quad)
if (quad.get())
{
quad->SetColor(ARGB(255,255,255,255));
float scale = mHeight / quad->mHeight;
renderer->RenderQuad(quad, x + (quad->mWidth * scale / 2), y + (quad->mHeight * scale / 2), 0, scale, scale);
renderer->RenderQuad(quad.get(), x + (quad->mWidth * scale / 2), y + (quad->mHeight * scale / 2), 0, scale, scale);
}
else if (alt1.size())
{
@@ -157,7 +157,7 @@ void StackAbility::Render()
target = (Damageable *) _target;
}
JQuad * quad = NULL;
JQuadPtr quad;
string alt2 = "";
if (target)
{
@@ -168,7 +168,7 @@ void StackAbility::Render()
}
}
Interruptible::Render(source, quad, alt1, alt2, action);
Interruptible::Render(source, quad.get(), alt1, alt2, action);
}
StackAbility::StackAbility(int id, MTGAbility * _ability) :
Interruptible(id), ability(_ability)
@@ -220,8 +220,7 @@ Interruptible(id), tc(tc), cost(_cost), payResult(payResult)
int Spell::computeX(MTGCardInstance * card)
{
ManaCost * c = cost->Diff(card->getManaCost());
int x = 0;
x = c->getCost(Constants::MTG_NB_COLORS);
int x = c->getCost(Constants::MTG_NB_COLORS);
delete c;
return x;
}
@@ -229,8 +228,7 @@ int Spell::computeX(MTGCardInstance * card)
int Spell::computeXX(MTGCardInstance * card)
{
ManaCost * c = cost->Diff(card->getManaCost());
int xx = 0;
xx = c->getCost(Constants::MTG_NB_COLORS) / 2;
int xx = c->getCost(Constants::MTG_NB_COLORS) / 2;
delete c;
return xx;
}
@@ -351,9 +349,9 @@ void Spell::Render()
string action = source->getName();
string alt1 = "";
JQuad * quad = NULL;
string alt2 = "";
Damageable * target = getNextDamageableTarget();
JQuadPtr quad;
if (target)
{
quad = target->getIcon();
@@ -362,7 +360,7 @@ void Spell::Render()
alt2 = ((MTGCardInstance *) target)->name;
}
}
Interruptible::Render(source, quad, alt1, alt2, action, true);
Interruptible::Render(source, quad.get(), alt1, alt2, action, true);
}
ostream& Spell::toString(ostream& out) const
@@ -407,12 +405,12 @@ void PutInGraveyard::Render()
mFont->DrawString(_("is exiled").c_str(), x + 30, y, JGETEXT_LEFT);
}
JRenderer * renderer = JRenderer::GetInstance();
JQuad * quad = WResourceManager::Instance()->RetrieveCard(card, CACHE_THUMB);
if (quad)
JQuadPtr quad = WResourceManager::Instance()->RetrieveCard(card, CACHE_THUMB);
if (quad.get())
{
quad->SetColor(ARGB(255,255,255,255));
float scale = 30 / quad->mHeight;
renderer->RenderQuad(quad, x, y, 0, scale, scale);
renderer->RenderQuad(quad.get(), x, y, 0, scale, scale);
}
else
{
@@ -1117,21 +1115,21 @@ void ActionStack::Render()
static const float kIconVerticalOffset = 24;
if (mCount > 1)
{
renderer->RenderQuad(pspIcons[7], x0 + 10, kIconVerticalOffset, 0, kGamepadIconSize, kGamepadIconSize);
renderer->RenderQuad(pspIcons[7].get(), x0 + 10, kIconVerticalOffset, 0, kGamepadIconSize, kGamepadIconSize);
mFont->DrawString(kInterruptString, x0 + 19, kIconVerticalOffset - 6);
renderer->RenderQuad(pspIcons[4], x0 + 97, kIconVerticalOffset, 0, kGamepadIconSize, kGamepadIconSize);
renderer->RenderQuad(pspIcons[4].get(), x0 + 97, kIconVerticalOffset, 0, kGamepadIconSize, kGamepadIconSize);
mFont->DrawString(kNoString, x0 + 106, kIconVerticalOffset - 6);
renderer->RenderQuad(pspIcons[6], x0 + 145, kIconVerticalOffset, 0, kGamepadIconSize, kGamepadIconSize);
renderer->RenderQuad(pspIcons[6].get(), x0 + 145, kIconVerticalOffset, 0, kGamepadIconSize, kGamepadIconSize);
mFont->DrawString(kNoToAllString, x0 + 154, kIconVerticalOffset - 6);
}
else
{
renderer->RenderQuad(pspIcons[7], x0 + 40, kIconVerticalOffset, 0, kGamepadIconSize, kGamepadIconSize);
renderer->RenderQuad(pspIcons[7].get(), x0 + 40, kIconVerticalOffset, 0, kGamepadIconSize, kGamepadIconSize);
mFont->DrawString(kInterruptString, x0 + 49, kIconVerticalOffset - 6);
renderer->RenderQuad(pspIcons[4], x0 + 140, kIconVerticalOffset - 6, 0, kGamepadIconSize, kGamepadIconSize);
renderer->RenderQuad(pspIcons[4].get(), x0 + 140, kIconVerticalOffset - 6, 0, kGamepadIconSize, kGamepadIconSize);
mFont->DrawString(kNoString, x0 + 146, kIconVerticalOffset - 6);
}

View File

@@ -140,13 +140,14 @@ void CardGui::Render()
tc = game->getCurrentTargetChooser();
bool alternate = true;
JQuad * quad = WResourceManager::Instance()->RetrieveCard(card, CACHE_THUMB);
JQuadPtr quad = WResourceManager::Instance()->RetrieveCard(card, CACHE_THUMB);
#if defined (WIN32) || defined (LINUX)
//On pcs we render the big image if the thumbnail is not available
if (!quad) quad = WResourceManager::Instance()->RetrieveCard(card);
if (!quad.get())
quad = WResourceManager::Instance()->RetrieveCard(card);
#endif
if (quad)
if (quad.get())
alternate = false;
else
quad = AlternateThumbQuad(card);
@@ -154,24 +155,26 @@ void CardGui::Render()
float cardScale = quad ? 40 / quad->mHeight : 1;
float scale = actZ * cardScale;
JQuad* shadow = NULL;
JQuadPtr shadow;
if (actZ > 1)
{
shadow = WResourceManager::Instance()->GetQuad("shadow");
shadow->SetColor(ARGB(static_cast<unsigned char>(actA)/2,255,255,255));
renderer->RenderQuad(shadow, actX + (actZ - 1) * 15, actY + (actZ - 1) * 15, actT, 28 * actZ / 16, 40 * actZ / 16);
renderer->RenderQuad(shadow.get(), actX + (actZ - 1) * 15, actY + (actZ - 1) * 15, actT, 28 * actZ / 16, 40 * actZ / 16);
}
JQuad* extracostshadow = NULL;
if(card->isExtraCostTarget )
JQuadPtr extracostshadow;
if (card->isExtraCostTarget)
{
extracostshadow = WResourceManager::Instance()->GetQuad("extracostshadow");
extracostshadow->SetColor(ARGB(static_cast<unsigned char>(actA)/2,100,0,0));
renderer->RenderQuad(extracostshadow, actX + (actZ - 1) * 15, actY + (actZ - 1) * 15, actT, 28 * actZ / 16, 40 * actZ / 16);
renderer->RenderQuad(extracostshadow.get(), actX + (actZ - 1) * 15, actY + (actZ - 1) * 15, actT, 28 * actZ / 16, 40 * actZ / 16);
}
if (quad)
{
quad->SetColor(ARGB(static_cast<unsigned char>(actA),255,255,255));
renderer->RenderQuad(quad, actX, actY, actT, scale, scale);
renderer->RenderQuad(quad.get(), actX, actY, actT, scale, scale);
}
if (alternate)
@@ -181,7 +184,7 @@ void CardGui::Render()
mFont->DrawString(_(card->getName()), actX - actZ * Width / 2 + 1, actY - actZ * Height / 2 + 1);
mFont->SetScale(DEFAULT_MAIN_FONT_SCALE);
JQuad * icon = NULL;
JQuadPtr icon;
if (card->hasSubtype("plains"))
icon = WResourceManager::Instance()->GetQuad("c_white");
else if (card->hasSubtype("swamp"))
@@ -192,21 +195,21 @@ void CardGui::Render()
icon = WResourceManager::Instance()->GetQuad("c_red");
else if (card->hasSubtype("island"))
icon = WResourceManager::Instance()->GetQuad("c_blue");
if (icon)
if (icon.get())
{
icon->SetColor(ARGB(static_cast<unsigned char>(actA),255,255,255));
renderer->RenderQuad(icon, actX, actY, 0);
renderer->RenderQuad(icon.get(), actX, actY, 0);
icon->SetColor(ARGB(255,255,255,255)); //Putting color back as this quad is shared
}
}
JQuad * mor = NULL;
JQuadPtr mor;
if(card->isMorphed && !alternate)
{
mor = WResourceManager::Instance()->GetQuad("morph");
mor->SetColor(ARGB(255,255,255,255));
renderer->RenderQuad(mor, actX, actY, actT,scale, scale);
renderer->RenderQuad(mor.get(), actX, actY, actT,scale, scale);
}
//draws the numbers power/toughness
@@ -249,14 +252,15 @@ void CardGui::Render()
if (!shadow)
shadow = WResourceManager::Instance()->GetQuad("shadow");
shadow->SetColor(ARGB(200,255,255,255));
renderer->RenderQuad(shadow, actX, actY, actT, (28 * actZ + 1) / 16, 40 * actZ / 16);
renderer->RenderQuad(shadow.get(), actX, actY, actT, (28 * actZ + 1) / 16, 40 * actZ / 16);
}
PlayGuiObject::Render();
}
JQuad * CardGui::AlternateThumbQuad(MTGCard * card)
JQuadPtr CardGui::AlternateThumbQuad(MTGCard * card)
{
JQuad * q;
JQuadPtr q;
if (card->data->countColors() > 1)
{
@@ -301,7 +305,7 @@ void CardGui::AlternateRender(MTGCard * card, const Pos& pos)
{
// Draw the "unknown" card model
JRenderer * renderer = JRenderer::GetInstance();
JQuad * q;
JQuadPtr q;
float x = pos.actX;
@@ -339,13 +343,13 @@ void CardGui::AlternateRender(MTGCard * card, const Pos& pos)
break;
}
}
if (q && q->mTex)
if (q.get() && q->mTex)
{
q->SetHotSpot(static_cast<float> (q->mTex->mWidth / 2), static_cast<float> (q->mTex->mHeight / 2));
float scale = pos.actZ * 250 / q->mHeight;
q->SetColor(ARGB((int)pos.actA,255,255,255));
renderer->RenderQuad(q, x, pos.actY, pos.actT, scale, scale);
renderer->RenderQuad(q.get(), x, pos.actY, pos.actT, scale, scale);
}
// Write the title
WFont * font = WResourceManager::Instance()->GetWFont(Fonts::MAGIC_FONT);
@@ -395,19 +399,19 @@ void CardGui::AlternateRender(MTGCard * card, const Pos& pos)
if (scale < 0)
{
renderer->RenderQuad(manaIcons[h->color1], x + (-12 * j + 75 + 3 * SineHelperFunction((float) t)) * pos.actZ,
renderer->RenderQuad(manaIcons[h->color1].get(), x + (-12 * j + 75 + 3 * SineHelperFunction((float) t)) * pos.actZ,
pos.actY + (yOffset + 3 * CosineHelperFunction((float) t)) * pos.actZ, 0, 0.4f + scale, 0.4f
+ scale);
renderer->RenderQuad(manaIcons[h->color2], x + (-12 * j + 75 + 3 * SineHelperFunction((float) v)) * pos.actZ,
renderer->RenderQuad(manaIcons[h->color2].get(), x + (-12 * j + 75 + 3 * SineHelperFunction((float) v)) * pos.actZ,
pos.actY + (yOffset + 3 * CosineHelperFunction((float) v)) * pos.actZ, 0, 0.4f - scale, 0.4f
- scale);
}
else
{
renderer->RenderQuad(manaIcons[h->color2], x + (-12 * j + 75 + 3 * SineHelperFunction((float) v)) * pos.actZ,
renderer->RenderQuad(manaIcons[h->color2].get(), x + (-12 * j + 75 + 3 * SineHelperFunction((float) v)) * pos.actZ,
pos.actY + (yOffset + 3 * CosineHelperFunction((float) v)) * pos.actZ, 0, 0.4f - scale, 0.4f
- scale);
renderer->RenderQuad(manaIcons[h->color1], x + (-12 * j + 75 + 3 * SineHelperFunction((float) t)) * pos.actZ,
renderer->RenderQuad(manaIcons[h->color1].get(), x + (-12 * j + 75 + 3 * SineHelperFunction((float) t)) * pos.actZ,
pos.actY + (yOffset + 3 * CosineHelperFunction((float) t)) * pos.actZ, 0, 0.4f + scale, 0.4f
+ scale);
}
@@ -417,7 +421,7 @@ void CardGui::AlternateRender(MTGCard * card, const Pos& pos)
{
for (int cost = manacost->getCost(i); cost > 0; --cost)
{
renderer->RenderQuad(manaIcons[i], x + (-12 * j + 75) * pos.actZ, pos.actY + (yOffset) * pos.actZ, 0, 0.4f
renderer->RenderQuad(manaIcons[i].get(), x + (-12 * j + 75) * pos.actZ, pos.actY + (yOffset) * pos.actZ, 0, 0.4f
* pos.actZ, 0.4f * pos.actZ);
++j;
}
@@ -427,7 +431,7 @@ void CardGui::AlternateRender(MTGCard * card, const Pos& pos)
{
char buffer[10];
sprintf(buffer, "%d", cost);
renderer->RenderQuad(manaIcons[0], x + (-12 * j + 75) * pos.actZ, pos.actY + (yOffset) * pos.actZ, 0, 0.4f * pos.actZ,
renderer->RenderQuad(manaIcons[0].get(), x + (-12 * j + 75) * pos.actZ, pos.actY + (yOffset) * pos.actZ, 0, 0.4f * pos.actZ,
0.4f * pos.actZ);
float w = font->GetStringWidth(buffer);
font->DrawString(buffer, x + (-12 * j + 76 - w / 2) * pos.actZ, pos.actY + (yOffset - 5) * pos.actZ);
@@ -438,7 +442,7 @@ void CardGui::AlternateRender(MTGCard * card, const Pos& pos)
{
char buffer[10];
sprintf(buffer, "X");
renderer->RenderQuad(manaIcons[0], x + (-12 * j + 75) * pos.actZ, pos.actY + (yOffset) * pos.actZ, 0, 0.4f * pos.actZ,
renderer->RenderQuad(manaIcons[0].get(), x + (-12 * j + 75) * pos.actZ, pos.actY + (yOffset) * pos.actZ, 0, 0.4f * pos.actZ,
0.4f * pos.actZ);
float w = font->GetStringWidth(buffer);
font->DrawString(buffer, x + (-12 * j + 76 - w / 2) * pos.actZ, pos.actY + (yOffset - 5) * pos.actZ);
@@ -522,12 +526,11 @@ font->SetScale(backup_scale);
void CardGui::TinyCropRender(MTGCard * card, const Pos& pos, JQuad * quad)
{
if (!quad)
return;
JRenderer * renderer = JRenderer::GetInstance();
JQuad * q;
JQuadPtr q;
float x = pos.actX;
float displayScale = 250 / BigHeight;
@@ -566,14 +569,13 @@ void CardGui::TinyCropRender(MTGCard * card, const Pos& pos, JQuad * quad)
break;
}
}
if (q && q->mTex)
if (q.get() && q->mTex)
{
q->SetHotSpot(static_cast<float> (q->mTex->mWidth / 2), static_cast<float> (q->mTex->mHeight / 2));
float scale = pos.actZ * displayScale * BigHeight / q->mHeight;
q->SetColor(ARGB((int)pos.actA,255,255,255));
renderer->RenderQuad(q, x, pos.actY, pos.actT, scale, scale);
renderer->RenderQuad(q.get(), x, pos.actY, pos.actT, scale, scale);
}
const std::vector<string> txt = card->data->formattedText();
@@ -638,21 +640,21 @@ void CardGui::TinyCropRender(MTGCard * card, const Pos& pos, JQuad * quad)
if (scale < 0)
{
renderer->RenderQuad(manaIcons[h->color1], x + (-12 * j + 75 + 3 * SineHelperFunction((float) t)) * pos.actZ,
pos.actY + (yOffset + 3 * CosineHelperFunction((float) t)) * pos.actZ, 0, 0.4f + scale, 0.4f
+ scale);
renderer->RenderQuad(manaIcons[h->color2], x + (-12 * j + 75 + 3 * SineHelperFunction((float) v)) * pos.actZ,
pos.actY + (yOffset + 3 * CosineHelperFunction((float) v)) * pos.actZ, 0, 0.4f - scale, 0.4f
- scale);
renderer->RenderQuad(manaIcons[h->color1].get(), x + (-12 * j + 75 + 3 * SineHelperFunction((float) t)) * pos.actZ,
pos.actY + (yOffset + 3 * CosineHelperFunction((float) t)) * pos.actZ, 0, 0.4f + scale, 0.4f
+ scale);
renderer->RenderQuad(manaIcons[h->color2].get(), x + (-12 * j + 75 + 3 * SineHelperFunction((float) v)) * pos.actZ,
pos.actY + (yOffset + 3 * CosineHelperFunction((float) v)) * pos.actZ, 0, 0.4f - scale, 0.4f
- scale);
}
else
{
renderer->RenderQuad(manaIcons[h->color2], x + (-12 * j + 75 + 3 * SineHelperFunction((float) v)) * pos.actZ,
pos.actY + (yOffset + 3 * CosineHelperFunction((float) v)) * pos.actZ, 0, 0.4f - scale, 0.4f
- scale);
renderer->RenderQuad(manaIcons[h->color1], x + (-12 * j + 75 + 3 * SineHelperFunction((float) t)) * pos.actZ,
pos.actY + (yOffset + 3 * CosineHelperFunction((float) t)) * pos.actZ, 0, 0.4f + scale, 0.4f
+ scale);
renderer->RenderQuad(manaIcons[h->color2].get(), x + (-12 * j + 75 + 3 * SineHelperFunction((float) v)) * pos.actZ,
pos.actY + (yOffset + 3 * CosineHelperFunction((float) v)) * pos.actZ, 0, 0.4f - scale, 0.4f
- scale);
renderer->RenderQuad(manaIcons[h->color1].get(), x + (-12 * j + 75 + 3 * SineHelperFunction((float) t)) * pos.actZ,
pos.actY + (yOffset + 3 * CosineHelperFunction((float) t)) * pos.actZ, 0, 0.4f + scale, 0.4f
+ scale);
}
++j;
}
@@ -660,8 +662,8 @@ void CardGui::TinyCropRender(MTGCard * card, const Pos& pos, JQuad * quad)
{
for (int cost = manacost->getCost(i); cost > 0; --cost)
{
renderer->RenderQuad(manaIcons[i], x + (-12 * j + 75) * pos.actZ, pos.actY + (yOffset) * pos.actZ, 0, 0.4f
* pos.actZ, 0.4f * pos.actZ);
renderer->RenderQuad(manaIcons[i].get(), x + (-12 * j + 75) * pos.actZ, pos.actY + (yOffset) * pos.actZ, 0, 0.4f
* pos.actZ, 0.4f * pos.actZ);
++j;
}
}
@@ -670,19 +672,19 @@ void CardGui::TinyCropRender(MTGCard * card, const Pos& pos, JQuad * quad)
{
char buffer[10];
sprintf(buffer, "%d", cost);
renderer->RenderQuad(manaIcons[0], x + (-12 * j + 75) * pos.actZ, pos.actY + (yOffset) * pos.actZ, 0, 0.4f * pos.actZ,
0.4f * pos.actZ);
renderer->RenderQuad(manaIcons[0].get(), x + (-12 * j + 75) * pos.actZ, pos.actY + (yOffset) * pos.actZ, 0, 0.4f * pos.actZ,
0.4f * pos.actZ);
float w = font->GetStringWidth(buffer);
font->DrawString(buffer, x + (-12 * j + 76 - w / 2) * pos.actZ, pos.actY + (yOffset - 5) * pos.actZ);
++j;
}
//Has X?
if (manacost->hasX())
if (int cost = manacost->hasX())
{
char buffer[10];
sprintf(buffer, "X");
renderer->RenderQuad(manaIcons[0], x + (-12 * j + 75) * pos.actZ, pos.actY + (yOffset) * pos.actZ, 0, 0.4f * pos.actZ,
0.4f * pos.actZ);
renderer->RenderQuad(manaIcons[0].get(), x + (-12 * j + 75) * pos.actZ, pos.actY + (yOffset) * pos.actZ, 0, 0.4f * pos.actZ,
0.4f * pos.actZ);
float w = font->GetStringWidth(buffer);
font->DrawString(buffer, x + (-12 * j + 76 - w / 2) * pos.actZ, pos.actY + (yOffset - 5) * pos.actZ);
}
@@ -700,59 +702,59 @@ void CardGui::TinyCropRender(MTGCard * card, const Pos& pos, JQuad * quad)
s += _(Subtypes::subtypesList->find(card->data->types[0]));
else
{
DebugTrace ("Typeless card: " << setlist[card->setId].c_str() << card->data->getName() << card->getId());
DebugTrace("Typeless card: " << setlist[card->setId].c_str() << card->data->getName() << card->getId());
}
font->DrawString(s.c_str(), x + (22 - BigWidth / 2)*pos.actZ, pos.actY + (49 - BigHeight / 2)*pos.actZ);
}
font->DrawString(s.c_str(), x + (22 - BigWidth / 2)*pos.actZ, pos.actY + (49 - BigHeight / 2)*pos.actZ);
}
//expansion and rarity
font->SetColor(ARGB((int)pos.actA, 0, 0, 0));
{
char buf[512];
switch(card->getRarity())
//expansion and rarity
font->SetColor(ARGB((int)pos.actA, 0, 0, 0));
{
char buf[512];
switch(card->getRarity())
{
case Constants::RARITY_M:
sprintf(buf,_("%s Mythic").c_str(),setlist[card->setId].c_str());
break;
sprintf(buf,_("%s Mythic").c_str(),setlist[card->setId].c_str());
break;
case Constants::RARITY_R:
sprintf(buf,_("%s Rare").c_str(),setlist[card->setId].c_str());
break;
sprintf(buf,_("%s Rare").c_str(),setlist[card->setId].c_str());
break;
case Constants::RARITY_U:
sprintf(buf,_("%s Uncommon").c_str(),setlist[card->setId].c_str());
break;
sprintf(buf,_("%s Uncommon").c_str(),setlist[card->setId].c_str());
break;
case Constants::RARITY_C:
sprintf(buf,_("%s Common").c_str(),setlist[card->setId].c_str());
break;
sprintf(buf,_("%s Common").c_str(),setlist[card->setId].c_str());
break;
case Constants::RARITY_L:
sprintf(buf,_("%s Land").c_str(),setlist[card->setId].c_str());
break;
sprintf(buf,_("%s Land").c_str(),setlist[card->setId].c_str());
break;
case Constants::RARITY_T:
sprintf(buf,_("%s Token").c_str(),setlist[card->setId].c_str());
break;
sprintf(buf,_("%s Token").c_str(),setlist[card->setId].c_str());
break;
default:
case Constants::RARITY_S:
sprintf(buf,_("%s Special").c_str(),setlist[card->setId].c_str());
break;
}
sprintf(buf,_("%s Special").c_str(),setlist[card->setId].c_str());
break;
}
switch(card->data->getColor())
{
switch(card->data->getColor())
{
case Constants::MTG_COLOR_BLACK:
case Constants::MTG_COLOR_GREEN:
case Constants::MTG_COLOR_BLUE:
case Constants::MTG_COLOR_LAND:
font->SetColor(ARGB((int)pos.actA,255,255,255));
font->DrawString(buf, x + (22 - BigWidth / 2)*pos.actZ, pos.actY + (BigHeight / 2 - 30)*pos.actZ);
break;
font->SetColor(ARGB((int)pos.actA,255,255,255));
font->DrawString(buf, x + (22 - BigWidth / 2)*pos.actZ, pos.actY + (BigHeight / 2 - 30)*pos.actZ);
break;
default:
font->DrawString(buf, x + (22 - BigWidth / 2)*pos.actZ, pos.actY + (BigHeight / 2 - 30)*pos.actZ);
break; //Leave black
font->DrawString(buf, x + (22 - BigWidth / 2)*pos.actZ, pos.actY + (BigHeight / 2 - 30)*pos.actZ);
break; //Leave black
}
}
}
font->SetScale(backup_scale);
font->SetScale(backup_scale);
}
//Renders a big card on screen. Defaults to the "alternate" rendering if no image is found
@@ -762,26 +764,26 @@ void CardGui::RenderBig(MTGCard* card, const Pos& pos)
float x = pos.actX;
JQuad * quad = WResourceManager::Instance()->RetrieveCard(card);
if (quad)
JQuadPtr quad = WResourceManager::Instance()->RetrieveCard(card);
if (quad.get())
{
if (quad->mHeight < quad->mWidth)
{
return TinyCropRender(card, pos, quad);
return TinyCropRender(card, pos, quad.get());
}
quad->SetColor(ARGB(255,255,255,255));
float scale = pos.actZ * 257.f / quad->mHeight;
renderer->RenderQuad(quad, x, pos.actY, pos.actT, scale, scale);
renderer->RenderQuad(quad.get(), x, pos.actY, pos.actT, scale, scale);
return;
}
//No card found, attempt to render the thumbnail instead (better than nothing, even if it gets super stretched)
JQuad * q;
JQuadPtr q;
if ((q = WResourceManager::Instance()->RetrieveCard(card, CACHE_THUMB)))
{
float scale = pos.actZ * 250 / q->mHeight;
q->SetColor(ARGB(255,255,255,255));
renderer->RenderQuad(q, x, pos.actY, pos.actT, scale, scale);
renderer->RenderQuad(q.get(), x, pos.actY, pos.actT, scale, scale);
return;
}

View File

@@ -201,12 +201,12 @@ void Credits::compute(Player * _p1, Player * _p2, GameApp * _app)
SAFE_DELETE(playerdata);
}
JQuad * Credits::GetUnlockedQuad(string textureName)
JQuadPtr Credits::GetUnlockedQuad(string textureName)
{
if (!textureName.size()) return NULL;
if (!textureName.size()) return JQuadPtr();
JTexture * unlockedTex = WResourceManager::Instance()->RetrieveTexture(textureName);
if (!unlockedTex) return NULL;
if (!unlockedTex) return JQuadPtr();
return WResourceManager::Instance()->RetrieveQuad(unlockedTextureName, 2, 2, unlockedTex->mWidth - 4, unlockedTex->mHeight - 4);
@@ -239,11 +239,11 @@ void Credits::Render()
if (g->gameOver != p1)
{
sprintf(buffer, _("Congratulations! You earn %i credits").c_str(), value);
JQuad * unlockedQuad = GetUnlockedQuad(unlockedTextureName);
JQuadPtr unlockedQuad = GetUnlockedQuad(unlockedTextureName);
if (unlockedQuad)
{
showMsg = 0;
r->RenderQuad(unlockedQuad, 20, 20);
r->RenderQuad(unlockedQuad.get(), 20, 20);
}
if (unlockedString.size())
{

View File

@@ -193,21 +193,21 @@ void Damage::Render()
sprintf(buffer, _("Deals %i damage to").c_str(), damage);
mFont->DrawString(buffer, x + 20, y, JGETEXT_LEFT);
JRenderer * renderer = JRenderer::GetInstance();
JQuad * quad = WResourceManager::Instance()->RetrieveCard(source, CACHE_THUMB);
if (quad)
JQuadPtr quad = WResourceManager::Instance()->RetrieveCard(source, CACHE_THUMB);
if (quad.get())
{
float scale = 30 / quad->mHeight;
renderer->RenderQuad(quad, x, y, 0, scale, scale);
renderer->RenderQuad(quad.get(), x, y, 0, scale, scale);
}
else
{
mFont->DrawString(_(source->getName()).c_str(), x, y - 15);
}
quad = target->getIcon();
if (quad)
if (quad.get())
{
float scale = 30 / quad->mHeight;
renderer->RenderQuad(quad, x + 150, y, 0, scale, scale);
renderer->RenderQuad(quad.get(), x + 150, y, 0, scale, scale);
}
else
{

View File

@@ -92,8 +92,8 @@ JGuiController(id, listener), fontId(fontId), mShowDetailsScreen( showDetailsOve
mSelectionTargetY = selectionY = kVerticalMargin;
if (NULL == stars)
stars = NEW hgeParticleSystem(WResourceManager::Instance()->RetrievePSI("stars.psi", WResourceManager::Instance()->GetQuad("stars")));
if (NULL == stars)
stars = NEW hgeParticleSystem(WResourceManager::Instance()->RetrievePSI("stars.psi", WResourceManager::Instance()->GetQuad("stars").get()));
stars->FireAt(mX, mY);
updateScroller();
@@ -101,8 +101,6 @@ JGuiController(id, listener), fontId(fontId), mShowDetailsScreen( showDetailsOve
void DeckMenu::RenderDeckManaColors()
{
JRenderer *renderer = JRenderer::GetInstance();
// display the deck mana colors if known
// We only want to display the mana symbols on the game screens and not the Deck Editor screens.
// Need a better way to determine where/when to display the mana symbols. Perhaps make it a property setting.
@@ -120,7 +118,7 @@ void DeckMenu::RenderDeckManaColors()
{
if ( (deckManaColors.at(colorIdx) == '1') != 0)
{
renderer->RenderQuad(manaIcons[colorIdx], manaIconX, manaIconY, 0, 0.5f, 0.5f);
JRenderer::GetInstance()->RenderQuad(manaIcons[colorIdx].get(), manaIconX, manaIconY, 0, 0.5f, 0.5f);
manaIconX += 15;
}
}
@@ -138,9 +136,9 @@ void DeckMenu::RenderBackground()
static bool loadBackground = true;
if (loadBackground)
{
JQuad *background = WResourceManager::Instance()->RetrieveTempQuad(bgFilename.str(), TEXTURE_SUB_5551);
if (background)
JRenderer::GetInstance()->RenderQuad(background, 0, 0);
JQuadPtr background = WResourceManager::Instance()->RetrieveTempQuad(bgFilename.str(), TEXTURE_SUB_5551);
if (background.get())
JRenderer::GetInstance()->RenderQuad(background.get(), 0, 0);
else
loadBackground = false;
}
@@ -227,6 +225,7 @@ void DeckMenu::Render()
mSelectedDeck = currentMenuItem->meta;
WFont *mainFont = WResourceManager::Instance()->GetWFont(Fonts::MAIN_FONT);
// display the "more info" button if special condition is met
if (showDetailsScreen())
{
@@ -236,7 +235,7 @@ void DeckMenu::Render()
float boxStartX = detailedInfoBoxX - stringWidth / 2;
DWORD currentColor = mainFont->GetColor();
renderer->FillRoundRect( boxStartX, detailedInfoBoxY - 5, stringWidth, mainFont->GetHeight() + 15, .5, ARGB( 255, 0, 0, 0) );
renderer->RenderQuad(pspIcons[5], detailedInfoBoxX, detailedInfoBoxY + 2, 0, pspIconsSize, pspIconsSize);
renderer->RenderQuad(pspIcons[5].get(), detailedInfoBoxX, detailedInfoBoxY + 2, 0, pspIconsSize, pspIconsSize);
mainFont->SetColor(currentColor);
mainFont->DrawString(detailedInfoString, boxStartX, detailedInfoBoxY + 10);
}
@@ -244,8 +243,9 @@ void DeckMenu::Render()
// display the avatar image
if (currentMenuItem->imageFilename.size() > 0)
{
JQuad * quad = WResourceManager::Instance()->RetrieveTempQuad(currentMenuItem->imageFilename, TEXTURE_SUB_AVATAR);
if (quad) renderer->RenderQuad(quad, avatarX, avatarY);
JQuadPtr quad = WResourceManager::Instance()->RetrieveTempQuad(currentMenuItem->imageFilename, TEXTURE_SUB_AVATAR);
if (quad.get())
renderer->RenderQuad(quad.get(), avatarX, avatarY);
}
// fill in the description part of the screen
string text = wordWrap(currentMenuItem->desc, descWidth, mainFont->mFontID );

View File

@@ -26,7 +26,7 @@ DeckMenuItem::DeckMenuItem(DeckMenu* _parent, int id, int fontId, string text, f
JTexture * tex = WResourceManager::Instance()->RetrieveTexture("new.png");
if (tex)
{
JQuad * quad = WResourceManager::Instance()->RetrieveQuad("new.png", 2.0f, 2.0f, tex->mWidth - 4.0f, tex->mHeight - 4.0f); //avoids weird rectangle around the texture because of bilinear filtering
JQuadPtr quad = WResourceManager::Instance()->RetrieveQuad("new.png", 2.0f, 2.0f, tex->mWidth - 4.0f, tex->mHeight - 4.0f); //avoids weird rectangle around the texture because of bilinear filtering
newImageWidth = quad->mWidth;
}
}
@@ -74,10 +74,10 @@ void DeckMenuItem::RenderWithOffset(float yOffset)
JTexture * tex = WResourceManager::Instance()->RetrieveTexture("new.png");
if (tex)
{
JQuad * quad = WResourceManager::Instance()->RetrieveQuad("new.png", 2.0f, 2.0f, tex->mWidth - 4.0f, tex->mHeight - 4.0f); //avoids weird rectangle aroudn the texture because of bilinear filtering
JQuadPtr quad = WResourceManager::Instance()->RetrieveQuad("new.png", 2.0f, 2.0f, tex->mWidth - 4.0f, tex->mHeight - 4.0f); //avoids weird rectangle aroudn the texture because of bilinear filtering
quad->SetHotSpot(quad->mWidth/2.0f, quad->mHeight/2.0f);
float x = mX + min(ITEM_PX_WIDTH - quad->mWidth, GetWidth() )/2 + quad->mWidth/2;
if (quad) JRenderer::GetInstance()->RenderQuad(quad, x , mY + yOffset + quad->mHeight/2, 0.5);
if (quad) JRenderer::GetInstance()->RenderQuad(quad.get(), x , mY + yOffset + quad->mHeight/2, 0.5);
}
}
}

View File

@@ -35,7 +35,7 @@ JMusic * GameApp::music = NULL;
string GameApp::currentMusicFile = "";
string GameApp::systemError = "";
JQuad* manaIcons[7] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL };
JQuadPtr manaIcons[7];
GameState::GameState(GameApp* parent) :
mParent(parent)
@@ -156,13 +156,13 @@ void GameApp::Create()
RETRIEVE_MANAGE);
for (int i = sizeof(manaIcons) / sizeof(manaIcons[0]) - 1; i >= 0; --i)
if (manaIcons[i])
if (manaIcons[i].get())
manaIcons[i]->SetHotSpot(16, 16);
LOG("--Loading back.jpg");
WResourceManager::Instance()->RetrieveTexture("back.jpg", RETRIEVE_MANAGE);
JQuad * jq = WResourceManager::Instance()->RetrieveQuad("back.jpg", 0, 0, 0, 0, "back", RETRIEVE_MANAGE);
if (jq)
JQuadPtr jq = WResourceManager::Instance()->RetrieveQuad("back.jpg", 0, 0, 0, 0, "back", RETRIEVE_MANAGE);
if (jq.get())
jq->SetHotSpot(jq->mWidth / 2, jq->mHeight / 2);
WResourceManager::Instance()->RetrieveTexture("back_thumb.jpg", RETRIEVE_MANAGE);

View File

@@ -137,9 +137,9 @@ void GameStateAwards::Render()
JRenderer * r = JRenderer::GetInstance();
r->ClearScreen(ARGB(0,0,0,0));
JQuad * mBg = WResourceManager::Instance()->RetrieveTempQuad("awardback.jpg", TEXTURE_SUB_5551);
if (mBg)
r->RenderQuad(mBg, 0, 0);
JQuadPtr background = WResourceManager::Instance()->RetrieveTempQuad("awardback.jpg", TEXTURE_SUB_5551);
if (background.get())
r->RenderQuad(background.get(), 0, 0);
switch (mState)
{

View File

@@ -94,7 +94,7 @@ void GameStateDeckViewer::rebuildFilters()
{
if (!filterMenu) filterMenu = NEW WGuiFilters("Filter by...", NULL);
if (source)
SAFE_DELETE(source);
SAFE_DELETE(source);
source = NEW WSrcDeckViewer(myDeck, myCollection);
filterMenu->setSrc(source);
if (displayed_deck != myDeck) source->swapSrc();
@@ -184,7 +184,7 @@ void GameStateDeckViewer::buildEditorMenu()
deckSummaryInformation << "All changes are final." << endl;
if (menu)
SAFE_DELETE( menu );
SAFE_DELETE( menu );
//Build menu.
JRenderer::GetInstance()->FillRoundRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 100, ARGB(0, 0, 0, 0) );
menu = NEW DeckEditorMenu(MENU_DECK_BUILDER, this, Fonts::OPTION_FONT, "Deck Editor", myDeck, stw);
@@ -245,8 +245,6 @@ void GameStateDeckViewer::Start()
pspIcons[i]->SetHotSpot(16, 16);
}
backQuad = WResourceManager::Instance()->GetQuad("back");
//init welcome menu
updateDecks();
@@ -449,7 +447,7 @@ void GameStateDeckViewer::Update(float dt)
{
filterMenu = NEW WGuiFilters("Filter by...", NULL);
if (source)
SAFE_DELETE(source);
SAFE_DELETE(source);
source = NEW WSrcDeckViewer(myDeck, myCollection);
filterMenu->setSrc(source);
if (displayed_deck != myDeck) source->swapSrc();
@@ -633,7 +631,7 @@ void GameStateDeckViewer::renderOnScreenBasicInfo()
renderer->FillRoundRect(SCREEN_WIDTH - (w + 27), y + 5, w + 10, 15, 5, ARGB(128,0,0,0));
mFont->DrawString(buffer, SCREEN_WIDTH - 22, y + 15, JGETEXT_RIGHT);
if (useFilter != 0) renderer->RenderQuad(mIcons[useFilter - 1], SCREEN_WIDTH - 10, y + 15, 0.0f, 0.5, 0.5);
if (useFilter != 0) renderer->RenderQuad(mIcons[useFilter - 1].get(), SCREEN_WIDTH - 10, y + 15, 0.0f, 0.5, 0.5);
}
//returns position of the current card (cusor) in the currently viewed color/filter
@@ -743,10 +741,10 @@ void GameStateDeckViewer::renderOnScreenMenu()
//LEFT PSP CIRCLE render
r->FillCircle(leftPspX, leftPspY, 40, ARGB(128,50,50,50));
r->RenderQuad(pspIcons[0], leftPspX, leftPspY - 20, 0, pspIconsSize, pspIconsSize);
r->RenderQuad(pspIcons[1], leftPspX, leftPspY + 20, 0, pspIconsSize, pspIconsSize);
r->RenderQuad(pspIcons[2], leftPspX - 20, leftPspY, 0, pspIconsSize, pspIconsSize);
r->RenderQuad(pspIcons[3], leftPspX + 20, leftPspY, 0, pspIconsSize, pspIconsSize);
r->RenderQuad(pspIcons[0].get(), leftPspX, leftPspY - 20, 0, pspIconsSize, pspIconsSize);
r->RenderQuad(pspIcons[1].get(), leftPspX, leftPspY + 20, 0, pspIconsSize, pspIconsSize);
r->RenderQuad(pspIcons[2].get(), leftPspX - 20, leftPspY, 0, pspIconsSize, pspIconsSize);
r->RenderQuad(pspIcons[3].get(), leftPspX + 20, leftPspY, 0, pspIconsSize, pspIconsSize);
font->DrawString(_("Prev."), leftPspX - 35, leftPspY - 15);
font->DrawString(_("Next"), leftPspX + 15, leftPspY - 15);
@@ -757,10 +755,10 @@ void GameStateDeckViewer::renderOnScreenMenu()
//RIGHT PSP CIRCLE render
r->FillCircle(rightPspX + (onScreenTransition * 204), rightPspY, 40, ARGB(128,50,50,50));
r->RenderQuad(pspIcons[4], rightPspX + 20, rightPspY, 0, pspIconsSize, pspIconsSize);
r->RenderQuad(pspIcons[5], rightPspX, rightPspY - 20, 0, pspIconsSize, pspIconsSize);
r->RenderQuad(pspIcons[6], rightPspX - 20, rightPspY, 0, pspIconsSize, pspIconsSize);
r->RenderQuad(pspIcons[7], rightPspX, rightPspY + 20, 0, pspIconsSize, pspIconsSize);
r->RenderQuad(pspIcons[4].get(), rightPspX + 20, rightPspY, 0, pspIconsSize, pspIconsSize);
r->RenderQuad(pspIcons[5].get(), rightPspX, rightPspY - 20, 0, pspIconsSize, pspIconsSize);
r->RenderQuad(pspIcons[6].get(), rightPspX - 20, rightPspY, 0, pspIconsSize, pspIconsSize);
r->RenderQuad(pspIcons[7].get(), rightPspX, rightPspY + 20, 0, pspIconsSize, pspIconsSize);
font->DrawString(_("Toggle Images"), rightPspX - 35, rightPspY - 40);
@@ -789,8 +787,8 @@ void GameStateDeckViewer::renderOnScreenMenu()
{
sprintf(buffer, "%i", value);
font->DrawString(buffer, SCREEN_WIDTH - 190 + rightTransition + nb_letters * 13, SCREEN_HEIGHT / 2 + 40);
r->RenderQuad(mIcons[j], SCREEN_WIDTH - 197 + rightTransition + nb_letters * 13, SCREEN_HEIGHT / 2 + 46, 0, 0.5,
0.5);
r->RenderQuad(mIcons[j].get(), SCREEN_WIDTH - 197 + rightTransition + nb_letters * 13, SCREEN_HEIGHT / 2 + 46, 0, 0.5,
0.5);
if (value > 9)
{
nb_letters += 3;
@@ -863,7 +861,7 @@ void GameStateDeckViewer::renderOnScreenMenu()
{
sprintf(buffer, "%i", value);
font->DrawString(buffer, 38 + nb_letters * 13 + leftTransition, posY + 5);
r->RenderQuad(mIcons[j], 30 + nb_letters * 13 + leftTransition, posY + 11, 0, 0.5, 0.5);
r->RenderQuad(mIcons[j].get(), 30 + nb_letters * 13 + leftTransition, posY + 11, 0, 0.5, 0.5);
if (value > 9)
{
nb_letters += 3;
@@ -976,7 +974,7 @@ void GameStateDeckViewer::renderOnScreenMenu()
// Column titles
for (int j = 0; j < Constants::MTG_NB_COLORS - 1; j++)
{
r->RenderQuad(mIcons[j], 52 + j * 15 + leftTransition, posY - 10, 0, 0.5, 0.5);
r->RenderQuad(mIcons[j].get(), 52 + j * 15 + leftTransition, posY - 10, 0, 0.5, 0.5);
}
//font->DrawString(_("C"), 30 + leftTransition, posY-16);
@@ -1060,7 +1058,7 @@ void GameStateDeckViewer::renderOnScreenMenu()
posX = 72;
for (int j = 0; j < stw->countLandsPerColor[i] + stw->countBasicLandsPerColor[i]; j++)
{
r->RenderQuad(mIcons[i], posX + leftTransition, posY + 6, 0, 0.5, 0.5);
r->RenderQuad(mIcons[i].get(), posX + leftTransition, posY + 6, 0, 0.5, 0.5);
posX += ((j + 1) % 10 == 0) ? 17 : 13;
if ((((j + 1) % 30) == 0) && (j < stw->countLandsPerColor[i] + stw->countBasicLandsPerColor[i] - 1))
{
@@ -1122,7 +1120,7 @@ void GameStateDeckViewer::renderOnScreenMenu()
// Column titles
for (int j = 0; j < Constants::MTG_NB_COLORS - 1; j++)
{
r->RenderQuad(mIcons[j], 67 + j * 15 + leftTransition, posY - 10, 0, 0.5, 0.5);
r->RenderQuad(mIcons[j].get(), 67 + j * 15 + leftTransition, posY - 10, 0, 0.5, 0.5);
}
font->DrawString(_("C"), 30 + leftTransition, posY - 16);
@@ -1234,7 +1232,7 @@ void GameStateDeckViewer::renderOnScreenMenu()
posX = 72;
for (int j = 0; j < stw->totalCostPerColor[i]; j++)
{
r->RenderQuad(mIcons[i], posX + leftTransition, posY + 6, 0, 0.5, 0.5);
r->RenderQuad(mIcons[i].get(), posX + leftTransition, posY + 6, 0, 0.5, 0.5);
posX += ((j + 1) % 10 == 0) ? 17 : 13;
if ((((j + 1) % 30) == 0) && (j < stw->totalCostPerColor[i] - 1))
{
@@ -1306,53 +1304,14 @@ void GameStateDeckViewer::renderCard(int id, float rotation)
int alpha = (int) (255 * (scale + 1.0 - max_scale));
if (!card) return;
JQuad * quad = NULL;
int cacheError = CACHE_ERROR_NONE;
int mode = !options[Options::DISABLECARDS].number ? DrawMode::kNormal : DrawMode::kText;
if (!options[Options::DISABLECARDS].number)
{
quad = WResourceManager::Instance()->RetrieveCard(card, RETRIEVE_EXISTING);
cacheError = WResourceManager::Instance()->RetrieveError();
if (!quad && cacheError != CACHE_ERROR_404)
{
if (last_user_activity > (abs(2 - id) + 1) * NO_USER_ACTIVITY_SHOWCARD_DELAY)
quad = WResourceManager::Instance()->RetrieveCard(card);
else
{
quad = backQuad;
}
}
}
Pos pos = Pos(x, y, scale * 285 / 250, 0.0, 255);
CardGui::DrawCard(card, pos, mode);
int quadAlpha = alpha;
if (!displayed_deck->count(card)) quadAlpha /= 2;
if (quad)
{
if (quad == backQuad)
{
quad->SetColor(ARGB(255,255,255,255));
float _scale = scale * (285 / quad->mHeight);
JRenderer::GetInstance()->RenderQuad(quad, x, y, 0.0f, _scale, _scale);
}
else
{
Pos pos = Pos(x, y, scale * 285 / 250, 0.0, 255);
CardGui::DrawCard(card, pos);
}
}
else
{
Pos pos = Pos(x, y, scale * 285 / 250, 0.0, 255);
CardGui::DrawCard(card, pos, DrawMode::kText);
if (!options[Options::DISABLECARDS].number) quad = WResourceManager::Instance()->RetrieveCard(card, CACHE_THUMB);
if (quad)
{
float _scale = 285 * scale / quad->mHeight;
quad->SetColor(ARGB(40,255,255,255));
JRenderer::GetInstance()->RenderQuad(quad, x, y, 0, _scale, _scale);
}
}
quadAlpha = 255 - quadAlpha;
if (quadAlpha > 0)
{
@@ -1385,9 +1344,8 @@ void GameStateDeckViewer::Render()
{
WFont * mFont = WResourceManager::Instance()->GetWFont(Fonts::MAIN_FONT);
JRenderer * r = JRenderer::GetInstance();
r->ClearScreen(ARGB(0,0,0,0));
JRenderer::GetInstance()->ClearScreen(ARGB(0,0,0,0));
if (displayed_deck == myDeck && mStage != STAGE_MENU)
renderDeckBackground();
int order[3] = { 1, 2, 3 };

View File

@@ -73,8 +73,6 @@ GameStateMenu::GameStateMenu(GameApp* parent) :
mGuiController = NULL;
subMenuController = NULL;
gameTypeMenu = NULL;
mSplash = NULL;
mBg = NULL;
//bgMusic = NULL;
timeIndex = 0;
angleMultiplier = MIN_ANGLE_MULTIPLIER;
@@ -129,8 +127,6 @@ void GameStateMenu::Create()
scrollerSet = 0;
splashTex = NULL;
mSplash = NULL;
}
void GameStateMenu::Destroy()
@@ -428,16 +424,16 @@ void GameStateMenu::ensureMGuiController()
{
WFont * mFont = WResourceManager::Instance()->GetWFont(Fonts::MENU_FONT);
mFont->SetColor(ARGB(255,255,255,255));
mGuiController->Add(NEW MenuItem(MENUITEM_PLAY, mFont, "Play", 80, 50 + SCREEN_HEIGHT / 2, mIcons[8], mIcons[9],
"particle1.psi", WResourceManager::Instance()->GetQuad("particles"), true));
mGuiController->Add(NEW MenuItem(MENUITEM_DECKEDITOR, mFont, "Deck Editor", 160, 50 + SCREEN_HEIGHT / 2, mIcons[2],
mIcons[3], "particle2.psi", WResourceManager::Instance()->GetQuad("particles")));
mGuiController->Add(NEW MenuItem(MENUITEM_SHOP, mFont, "Shop", 240, 50 + SCREEN_HEIGHT / 2, mIcons[0], mIcons[1],
"particle3.psi", WResourceManager::Instance()->GetQuad("particles")));
mGuiController->Add(NEW MenuItem(MENUITEM_OPTIONS, mFont, "Options", 320, 50 + SCREEN_HEIGHT / 2, mIcons[6], mIcons[7],
"particle4.psi", WResourceManager::Instance()->GetQuad("particles")));
mGuiController->Add(NEW MenuItem(MENUITEM_EXIT, mFont, "Exit", 400, 50 + SCREEN_HEIGHT / 2, mIcons[4], mIcons[5],
"particle5.psi", WResourceManager::Instance()->GetQuad("particles")));
mGuiController->Add(NEW MenuItem(MENUITEM_PLAY, mFont, "Play", 80, 50 + SCREEN_HEIGHT / 2, mIcons[8].get(), mIcons[9].get(),
"particle1.psi", WResourceManager::Instance()->GetQuad("particles").get(), true));
mGuiController->Add(NEW MenuItem(MENUITEM_DECKEDITOR, mFont, "Deck Editor", 160, 50 + SCREEN_HEIGHT / 2, mIcons[2].get(),
mIcons[3].get(), "particle2.psi", WResourceManager::Instance()->GetQuad("particles").get()));
mGuiController->Add(NEW MenuItem(MENUITEM_SHOP, mFont, "Shop", 240, 50 + SCREEN_HEIGHT / 2, mIcons[0].get(), mIcons[1].get(),
"particle3.psi", WResourceManager::Instance()->GetQuad("particles").get()));
mGuiController->Add(NEW MenuItem(MENUITEM_OPTIONS, mFont, "Options", 320, 50 + SCREEN_HEIGHT / 2, mIcons[6].get(), mIcons[7].get(),
"particle4.psi", WResourceManager::Instance()->GetQuad("particles").get()));
mGuiController->Add(NEW MenuItem(MENUITEM_EXIT, mFont, "Exit", 400, 50 + SCREEN_HEIGHT / 2, mIcons[4].get(), mIcons[5].get(),
"particle5.psi", WResourceManager::Instance()->GetQuad("particles").get()));
}
}
}
@@ -499,7 +495,6 @@ void GameStateMenu::Update(float dt)
//Release splash texture
WResourceManager::Instance()->Release(splashTex);
splashTex = NULL;
mSplash = NULL;
//check for deleted collection / first-timer
wagic::ifstream file(options.profileFile(PLAYER_COLLECTION).c_str());
@@ -644,26 +639,17 @@ void GameStateMenu::Render()
}
else if ((currentState & MENU_STATE_MAJOR) == MENU_STATE_MAJOR_LOADING_CARDS)
{
if (!splashTex)
string wp = loadRandomWallpaper();
if (wp.size())
{
splashTex = WResourceManager::Instance()->RetrieveTexture("splash.jpg", RETRIEVE_LOCK);
mSplash = WResourceManager::Instance()->RetrieveTempQuad("splash.jpg");
}
if (mSplash)
renderer->RenderQuad(mSplash, 0, 0);
else
{
string wp = loadRandomWallpaper();
if (wp.size())
JTexture * wpTex = WResourceManager::Instance()->RetrieveTexture(wp);
if (wpTex)
{
JTexture * wpTex = WResourceManager::Instance()->RetrieveTexture(wp);
if (wpTex)
{
JQuad * wpQuad = WResourceManager::Instance()->RetrieveTempQuad(wp);
renderer->RenderQuad(wpQuad, 0, 0, 0, SCREEN_WIDTH_F / wpQuad->mWidth, SCREEN_HEIGHT_F / wpQuad->mHeight);
}
JQuadPtr wpQuad = WResourceManager::Instance()->RetrieveTempQuad(wp);
renderer->RenderQuad(wpQuad.get(), 0, 0, 0, SCREEN_WIDTH_F / wpQuad->mWidth, SCREEN_HEIGHT_F / wpQuad->mHeight);
}
}
char text[512];
if (mCurrentSetName[0])
{
@@ -702,11 +688,11 @@ void GameStateMenu::Render()
renderer->FillRoundRect(SCREEN_WIDTH / 2 - 100, SCREEN_HEIGHT, 191, 6, 5, ARGB(100,10,5,0));
scroller->Render();
if (mBg)
renderer->RenderQuad(mBg, SCREEN_WIDTH / 2, 50);
if (mBg.get())
renderer->RenderQuad(mBg.get(), SCREEN_WIDTH / 2, 50);
JQuad * jq = WResourceManager::Instance()->RetrieveTempQuad("button_shoulder.png");
if (jq)
JQuadPtr jq = WResourceManager::Instance()->RetrieveTempQuad("button_shoulder.png");
if (jq.get())
{
int alp = 255;
if (options.newAward())
@@ -719,7 +705,7 @@ void GameStateMenu::Render()
;
mFont->SetScale(1.0f);
mFont->SetScale(50.0f / mFont->GetStringWidth(s.c_str()));
renderer->RenderQuad(jq, SCREEN_WIDTH - 64, 2);
renderer->RenderQuad(jq.get(), SCREEN_WIDTH - 64, 2);
mFont->DrawString(s, SCREEN_WIDTH - 10, 9, JGETEXT_RIGHT);
mFont = WResourceManager::Instance()->GetWFont(Fonts::MENU_FONT);
mFont->SetScale(olds);

View File

@@ -55,7 +55,6 @@ GameStateShop::GameStateShop(GameApp* parent) :
menu = NULL;
for (int i = 0; i < 8; i++)
altThumb[i] = NULL;
mBack = NULL;
boosterDisplay = NULL;
taskList = NULL;
srcCards = NULL;
@@ -143,8 +142,6 @@ void GameStateShop::Start()
altThumb[6] = WResourceManager::Instance()->RetrieveTexture("land_thumb.jpg", RETRIEVE_LOCK);
altThumb[7] = WResourceManager::Instance()->RetrieveTexture("gold_thumb.jpg", RETRIEVE_LOCK);
mBack = WResourceManager::Instance()->GetQuad("back");
for (int i = 0; i < 8; ++i)
{
std::ostringstream stream;
@@ -674,17 +671,17 @@ void GameStateShop::Render()
if (mStage == STAGE_FADE_IN)
return;
JQuad * mBg = WResourceManager::Instance()->RetrieveTempQuad("shop.jpg", TEXTURE_SUB_5551);
if (mBg)
r->RenderQuad(mBg, 0, 0);
JQuadPtr mBg = WResourceManager::Instance()->RetrieveTempQuad("shop.jpg", TEXTURE_SUB_5551);
if (mBg.get())
r->RenderQuad(mBg.get(), 0, 0);
JQuad * quad = WResourceManager::Instance()->RetrieveTempQuad("shop_light.jpg", TEXTURE_SUB_5551);
if (quad)
JQuadPtr quad = WResourceManager::Instance()->RetrieveTempQuad("shop_light.jpg", TEXTURE_SUB_5551);
if (quad.get())
{
r->EnableTextureFilter(false);
r->SetTexBlend(BLEND_SRC_ALPHA, BLEND_ONE);
quad->SetColor(ARGB(lightAlpha,255,255,255));
r->RenderQuad(quad, 0, 0);
r->RenderQuad(quad.get(), 0, 0);
r->SetTexBlend(BLEND_SRC_ALPHA, BLEND_ONE_MINUS_SRC_ALPHA);
r->EnableTextureFilter(true);
}
@@ -740,7 +737,7 @@ void GameStateShop::Render()
mFont->DrawString(stream.str(), 5, SCREEN_HEIGHT - 14);
float len = 4 + mFont->GetStringWidth(kOtherCardsString.c_str());
r->RenderQuad(pspIcons[6], SCREEN_WIDTH - len - kGamepadIconSize - 10, SCREEN_HEIGHT - 8, 0, kGamepadIconSize, kGamepadIconSize);
r->RenderQuad(pspIcons[6].get(), SCREEN_WIDTH - len - kGamepadIconSize - 10, SCREEN_HEIGHT - 8, 0, kGamepadIconSize, kGamepadIconSize);
mFont->DrawString(kOtherCardsString, SCREEN_WIDTH - len, SCREEN_HEIGHT - 14);
mFont->SetColor(ARGB(255,255,255,0));

View File

@@ -16,17 +16,18 @@ GuiBackground::~GuiBackground()
void GuiBackground::Render()
{
JRenderer* renderer = JRenderer::GetInstance();
JQuad * quad = NULL;
JQuadPtr quad;
GameObserver * go = GameObserver::GetInstance();
if (go && go->mRules && go->mRules->bg.size())
{
quad = WResourceManager::Instance()->RetrieveTempQuad(go->mRules->bg);
}
if (!quad)
if (!quad.get())
{
quad = WResourceManager::Instance()->RetrieveTempQuad("backdrop.jpg");
}
if (!quad)
return;
renderer->RenderQuad(quad, 0, 18);
if (quad.get())
{
renderer->RenderQuad(quad.get(), 0, 18);
}
}

View File

@@ -390,7 +390,7 @@ void GuiCombat::Render()
if (activeAtk->card->has(Constants::TRAMPLE))
{
go->opponent()->mAvatar->SetHotSpot(18, 25);
enemy_avatar.Render(go->opponent()->mAvatar);
enemy_avatar.Render(go->opponent()->mAvatar.get());
WFont * mFont = WResourceManager::Instance()->GetWFont(Fonts::MAIN_FONT);
mFont->SetColor(ARGB(255, 255, 64, 0));
{
@@ -402,9 +402,9 @@ void GuiCombat::Render()
}
if (ok_tex)
{
JQuad *ok_quad = WResourceManager::Instance()->RetrieveTempQuad("Ok.png");
JQuadPtr ok_quad = WResourceManager::Instance()->RetrieveTempQuad("Ok.png");
ok_quad->SetHotSpot(28, 22);
ok.Render(ok_quad);
ok.Render(ok_quad.get());
}
renderer->DrawLine(0, SCREEN_HEIGHT / 2 + 10, SCREEN_WIDTH, SCREEN_HEIGHT / 2 + 10, ARGB(255, 255, 64, 0));
if (FIRST_STRIKE == step)

View File

@@ -9,11 +9,9 @@ GuiFrame::GuiFrame()
wood = WResourceManager::Instance()->RetrieveQuad("wood.png", 0, 0, SCREEN_WIDTH, 28);
else
{
wood = NULL;
GameApp::systemError += "Can't load wood texture : " __FILE__ "\n";
}
goldGlow = gold1 = gold2 = NULL;
if (WResourceManager::Instance()->GetTexture("gold.png"))
{
gold1 = WResourceManager::Instance()->RetrieveQuad("gold.png", 0, 0, SCREEN_WIDTH, 6, "gold1");
@@ -41,23 +39,23 @@ void GuiFrame::Render()
float sized = step / 4;
if (sized > SCREEN_WIDTH)
sized -= SCREEN_WIDTH;
renderer->RenderQuad(wood, 0, 0);
if (gold1)
renderer->RenderQuad(wood.get(), 0, 0);
if (gold1.get())
{
renderer->RenderQuad(gold1, -sized, 16);
renderer->RenderQuad(gold1, -sized + 479, 16);
renderer->RenderQuad(gold1.get(), -sized, 16);
renderer->RenderQuad(gold1.get(), -sized + 479, 16);
if (goldGlow)
if (goldGlow.get())
{
goldGlow->SetColor(ARGB((100+(rand()%50)), 255, 255, 255));
renderer->RenderQuad(goldGlow, -sized, 9);
renderer->RenderQuad(goldGlow, -sized + 480, 9);
renderer->RenderQuad(goldGlow.get(), -sized, 9);
renderer->RenderQuad(goldGlow.get(), -sized + 480, 9);
}
if (gold2)
if (gold2.get())
{
renderer->RenderQuad(gold2, step / 2, 16);
renderer->RenderQuad(gold2, step / 2 - 479, 16);
renderer->RenderQuad(gold2.get(), step / 2, 16);
renderer->RenderQuad(gold2.get(), step / 2 - 479, 16);
}
}
}

View File

@@ -36,7 +36,7 @@ GuiHand::GuiHand(MTGHand* hand) :
GuiLayer(), hand(hand)
{
back = WResourceManager::Instance()->RetrieveTempQuad("handback.png");
if (back)
if (back.get())
back->SetTextureRect(1, 0, 100, 250);
else
GameApp::systemError = "Error loading hand texture : " __FILE__;
@@ -68,7 +68,7 @@ GuiHandOpponent::GuiHandOpponent(MTGHand* hand) :
void GuiHandOpponent::Render()
{
JQuad * quad = WResourceManager::Instance()->GetQuad("back_thumb");
JQuadPtr quad = WResourceManager::Instance()->GetQuad("back_thumb");
float x = 45;
for (vector<CardView*>::iterator it = cards.begin(); it != cards.end(); ++it)
@@ -76,7 +76,7 @@ void GuiHandOpponent::Render()
(*it)->x = x;
(*it)->y = 2;
(*it)->zoom = 0.3f;
(*it)->Render(quad);
(*it)->Render(quad.get());
x += 18;
}
}
@@ -207,16 +207,16 @@ void GuiHandSelf::Render()
if (OptionHandDirection::HORIZONTAL == options[Options::HANDDIRECTION].number)
{
back->SetColor(ARGB(255,255,0,0));
JRenderer::GetInstance()->RenderQuad(back, backpos.actX, backpos.actY, backpos.actT, backpos.actZ, backpos.actZ);
JRenderer::GetInstance()->RenderQuad(back.get(), backpos.actX, backpos.actY, backpos.actT, backpos.actZ, backpos.actZ);
back->SetColor(ARGB(255,255,255,255));
mFont->DrawString("0", SCREEN_WIDTH - 10, backpos.actY);
}
else
backpos.Render(back);
backpos.Render(back.get());
return;
}
backpos.Render(back);
backpos.Render(back.get());
if (OptionClosedHand::VISIBLE == options[Options::CLOSEDHAND].number || state == Open)
for (vector<CardView*>::iterator it = cards.begin(); it != cards.end(); ++it)
(*it)->Render();

View File

@@ -11,9 +11,9 @@ ManaIcon::ManaIcon(int color, float x, float y, float destx, float desty) :
Pos(x, y, 0.5, 0.0, 255), f(-1), destx(destx), desty(desty), mode(ALIVE), color(color)
{
hgeParticleSystemInfo * psi = NULL;
JQuad * mq = WResourceManager::Instance()->GetQuad("stars");
JQuadPtr mq = WResourceManager::Instance()->GetQuad("stars");
if (!mq)
if (!mq.get())
{
particleSys = NULL;
return;
@@ -22,22 +22,22 @@ ManaIcon::ManaIcon(int color, float x, float y, float destx, float desty) :
switch (color)
{
case Constants::MTG_COLOR_RED:
psi = WResourceManager::Instance()->RetrievePSI("manared.psi", mq);
psi = WResourceManager::Instance()->RetrievePSI("manared.psi", mq.get());
break;
case Constants::MTG_COLOR_BLUE:
psi = WResourceManager::Instance()->RetrievePSI("manablue.psi", mq);
psi = WResourceManager::Instance()->RetrievePSI("manablue.psi", mq.get());
break;
case Constants::MTG_COLOR_GREEN:
psi = WResourceManager::Instance()->RetrievePSI("managreen.psi", mq);
psi = WResourceManager::Instance()->RetrievePSI("managreen.psi", mq.get());
break;
case Constants::MTG_COLOR_BLACK:
psi = WResourceManager::Instance()->RetrievePSI("manablack.psi", mq);
psi = WResourceManager::Instance()->RetrievePSI("manablack.psi", mq.get());
break;
case Constants::MTG_COLOR_WHITE:
psi = WResourceManager::Instance()->RetrievePSI("manawhite.psi", mq);
psi = WResourceManager::Instance()->RetrievePSI("manawhite.psi", mq.get());
break;
default:
psi = WResourceManager::Instance()->RetrievePSI("mana.psi", mq);
psi = WResourceManager::Instance()->RetrievePSI("mana.psi", mq.get());
}
if (!psi)
@@ -45,7 +45,7 @@ ManaIcon::ManaIcon(int color, float x, float y, float destx, float desty) :
psi = NEW hgeParticleSystemInfo();
if (!psi)
return;
hgeParticleSystemInfo * defaults = WResourceManager::Instance()->RetrievePSI("mana.psi", mq);
hgeParticleSystemInfo * defaults = WResourceManager::Instance()->RetrievePSI("mana.psi", mq.get());
if (defaults)
{
memcpy(psi, defaults, sizeof(hgeParticleSystemInfo));
@@ -66,7 +66,7 @@ ManaIcon::ManaIcon(int color, float x, float y, float destx, float desty) :
psi->fSizeVar = 0.25396827f;
psi->fSpinStart = -5.5555553f;
psi->fAlphaVar = 0.77777779f;
psi->sprite = mq;
psi->sprite = mq.get();
}
switch (color)
@@ -150,7 +150,7 @@ void ManaIcon::Render()
renderer->SetTexBlend(BLEND_SRC_ALPHA, BLEND_ONE);
particleSys->Render();
renderer->SetTexBlend(BLEND_SRC_ALPHA, BLEND_ONE_MINUS_SRC_ALPHA);
renderer->RenderQuad(icon, actX, actY, actT, actZ + zoomP1 * sinf(M_PI * zoomP3), actZ + zoomP2 * cosf(M_PI * zoomP4));
renderer->RenderQuad(icon.get(), actX, actY, actT, actZ + zoomP1 * sinf(M_PI * zoomP3), actZ + zoomP2 * cosf(M_PI * zoomP4));
}
void ManaIcon::Update(float dt, float shift)
{
@@ -269,7 +269,7 @@ void GuiMana::RenderStatic()
if (values[i])
{
offset -= 20;
r->RenderQuad(manaIcons[i], xEnd + 15 + offset, y + 5, 0, 0.7f, 0.7f);
r->RenderQuad(manaIcons[i].get(), xEnd + 15 + offset, y + 5, 0, 0.7f, 0.7f);
}
}
r->FillRoundRect(x0, y, static_cast<float> (20 * totalColors + 5), 8, 2, ARGB(100,0,0,0));

View File

@@ -43,8 +43,8 @@ namespace
GuiPhaseBar::GuiPhaseBar() :
phase(NULL), angle(0.0f)
{
JQuad * quad = NULL;
if ((quad = WResourceManager::Instance()->GetQuad("phasebar")) != NULL)
JQuadPtr quad = WResourceManager::Instance()->GetQuad("phasebar");
if (quad.get() != NULL)
{
quad->mHeight = kHeight;
quad->mWidth = kWidth;
@@ -68,7 +68,7 @@ void GuiPhaseBar::Update(float dt)
void GuiPhaseBar::Render()
{
GameObserver * g = GameObserver::GetInstance();
JQuad * quad = WResourceManager::Instance()->GetQuad("phasebar");
JQuadPtr quad = WResourceManager::Instance()->GetQuad("phasebar");
JRenderer::GetInstance()->DrawLine(0, CENTER, SCREEN_WIDTH, CENTER, ARGB(255, 255, 255, 255));
@@ -79,7 +79,7 @@ void GuiPhaseBar::Render()
for (int glyph = 3; glyph < 6; ++glyph)
{
scale = ICONSCALE * sinf(angle + glyph * M_PI / 6) / 2;
DrawGlyph(quad, glyph, yPos, angle, p, scale);
DrawGlyph(quad.get(), glyph, yPos, angle, p, scale);
yPos += kWidth * scale;
}
@@ -88,7 +88,7 @@ void GuiPhaseBar::Render()
{
scale = ICONSCALE * sinf(angle + glyph * M_PI / 6) / 2;
yPos -= kWidth * scale;
DrawGlyph(quad, glyph, yPos, angle, p, scale);
DrawGlyph(quad.get(), glyph, yPos, angle, p, scale);
}
if (angle > 0)
@@ -97,7 +97,7 @@ void GuiPhaseBar::Render()
yPos -= kWidth * scale;
float xPos = static_cast<float> (p % (kPhases * (int) (kWidth + 1)));
quad->SetTextureRect(xPos, kHeight, kWidth, kHeight);
JRenderer::GetInstance()->RenderQuad(quad, 0, yPos, 0.0, scale, scale);
JRenderer::GetInstance()->RenderQuad(quad.get(), 0, yPos, 0.0, scale, scale);
}
//print phase name

View File

@@ -57,28 +57,27 @@ void GuiAvatar::Render()
float x0 = actX;
float y0 = actY;
JQuad * quad = player->mAvatar;
if (quad)
if (player->mAvatar.get())
{
if (corner == BOTTOM_RIGHT)
{
x0 -= quad->mWidth * actZ;
y0 -= quad->mHeight * actZ;
x0 -= player->mAvatar->mWidth * actZ;
y0 -= player->mAvatar->mHeight * actZ;
}
switch (corner)
{
case TOP_LEFT:
quad->SetHotSpot(0, 0);
player->mAvatar->SetHotSpot(0, 0);
break;
case BOTTOM_RIGHT:
quad->SetHotSpot(35, 50);
player->mAvatar->SetHotSpot(35, 50);
break;
}
quad->SetColor(ARGB((int)actA, 255, avatarRed, avatarRed));
r->RenderQuad(quad, actX, actY, actT, actZ, actZ);
player->mAvatar->SetColor(ARGB((int)actA, 255, avatarRed, avatarRed));
r->RenderQuad(player->mAvatar.get(), actX, actY, actT, actZ, actZ);
if (mHasFocus)
{
r->FillRect(x0, x0, quad->mWidth * actZ, quad->mHeight * actZ, ARGB(abs(128 - wave),255,255,255));
r->FillRect(x0, x0, player->mAvatar->mWidth * actZ, player->mAvatar->mHeight * actZ, ARGB(abs(128 - wave),255,255,255));
}
}
@@ -152,11 +151,11 @@ void GuiGameZone::toggleDisplay()
void GuiGameZone::Render()
{
//Texture
JQuad * quad = WResourceManager::Instance()->GetQuad("back_thumb");
JQuadPtr quad = WResourceManager::Instance()->GetQuad("back_thumb");
float scale = defaultHeight / quad->mHeight;
quad->SetColor(ARGB((int)(actA),255,255,255));
JRenderer::GetInstance()->RenderQuad(quad, actX, actY, 0.0, scale * actZ, scale * actZ);
JRenderer::GetInstance()->RenderQuad(quad.get(), actX, actY, 0.0, scale * actZ, scale * actZ);
float x0 = actX;
if (x0 < SCREEN_WIDTH / 2)

View File

@@ -642,7 +642,7 @@ int MTGCardInstance::canBlock(MTGCardInstance * opponent)
return 1;
}
JQuad * MTGCardInstance::getIcon()
JQuadPtr MTGCardInstance::getIcon()
{
return WResourceManager::Instance()->RetrieveCard(this, CACHE_THUMB);
}

View File

@@ -203,11 +203,11 @@ void OptionProfile::Render()
else
sprintf(buf, "profiles/%s/avatar.jpg", selections[value].c_str());
string filename = buf;
JQuad * mAvatar = WResourceManager::Instance()->RetrieveTempQuad(filename, TEXTURE_SUB_EXACT);
JQuadPtr avatar = WResourceManager::Instance()->RetrieveTempQuad(filename, TEXTURE_SUB_EXACT);
if (mAvatar)
if (avatar)
{
renderer->RenderQuad(mAvatar, x, pY);
renderer->RenderQuad(avatar.get(), x, pY);
pX += 40;
}
@@ -460,7 +460,7 @@ OptionTheme::OptionTheme(OptionThemeStyle * style) :
ts = style;
}
JQuad * OptionTheme::getImage()
JQuadPtr OptionTheme::getImage()
{
char buf[512];
string val = selections[value];
@@ -510,11 +510,11 @@ void OptionTheme::Render()
}
sprintf(buf, _("Theme: %s").c_str(), selections[value].c_str());
JQuad * q = getImage();
JQuadPtr q = getImage();
if (q)
{
float scale = 128 / q->mHeight;
renderer->RenderQuad(q, x, y, 0, scale, scale);
renderer->RenderQuad(q.get(), x, y, 0, scale, scale);
}
WFont * mFont = WResourceManager::Instance()->GetWFont(Fonts::OPTION_FONT);

View File

@@ -28,7 +28,6 @@ Damageable(20)
poisonCount = 0;
damageCount = 0;
preventable = 0;
mAvatar = NULL;
mAvatarTex = NULL;
type_as_damageable = DAMAGEABLE_PLAYER;
playMode = MODE_HUMAN;
@@ -51,7 +50,6 @@ Player::~Player()
SAFE_DELETE(manaPool);
SAFE_DELETE(game);
WResourceManager::Instance()->Release(mAvatarTex);
mAvatar = NULL;
mAvatarTex = NULL;
}
@@ -60,14 +58,11 @@ void Player::loadAvatar(string file)
if (mAvatarTex)
{
WResourceManager::Instance()->Release(mAvatarTex);
mAvatar = NULL;
mAvatarTex = NULL;
}
mAvatarTex = WResourceManager::Instance()->RetrieveTexture(file, RETRIEVE_LOCK, TEXTURE_SUB_AVATAR);
if (mAvatarTex)
mAvatar = WResourceManager::Instance()->RetrieveQuad(file, 0, 0, 35, 50, "playerAvatar", RETRIEVE_NORMAL, TEXTURE_SUB_AVATAR);
else
mAvatar = NULL;
}
const string Player::getDisplayName() const
@@ -92,7 +87,7 @@ int Player::getId()
return -1;
}
JQuad * Player::getIcon()
JQuadPtr Player::getIcon()
{
return mAvatar;
}

View File

@@ -19,10 +19,10 @@ namespace
const float kSpadeRightBottomOffset = 3;
}
JQuad* SimpleMenu::spadeR = NULL;
JQuad* SimpleMenu::spadeL = NULL;
JQuad* SimpleMenu::jewel = NULL;
JQuad* SimpleMenu::side = NULL;
JQuadPtr SimpleMenu::spadeR;
JQuadPtr SimpleMenu::spadeL;
JQuadPtr SimpleMenu::jewel;
JQuadPtr SimpleMenu::side;
JTexture* SimpleMenu::spadeRTex = NULL;
JTexture* SimpleMenu::spadeLTex = NULL;
JTexture* SimpleMenu::jewelTex = NULL;
@@ -52,15 +52,15 @@ SimpleMenu::SimpleMenu(int id, JGuiListener* listener, int fontId, float x, floa
if (!spadeRTex) spadeRTex = WResourceManager::Instance()->RetrieveTexture("spade_ur.png", RETRIEVE_MANAGE);
if (!jewelTex) jewelTex = renderer->CreateTexture(5, 5, TEX_TYPE_USE_VRAM);
if (!sideTex) sideTex = WResourceManager::Instance()->RetrieveTexture("menuside.png", RETRIEVE_MANAGE);
if (NULL == spadeL) spadeL = WResourceManager::Instance()->RetrieveQuad("spade_ul.png", 0, 0, 0, 0, "spade_ul", RETRIEVE_MANAGE);
if (NULL == spadeR) spadeR = WResourceManager::Instance()->RetrieveQuad("spade_ur.png", 0, 0, 0, 0, "spade_ur", RETRIEVE_MANAGE);
if (NULL == jewel) jewel = NEW JQuad(jewelTex, 1, 1, 3, 3);
if (NULL == side) side = WResourceManager::Instance()->RetrieveQuad("menuside.png", 1, 1, 1, kPoleWidth, "menuside", RETRIEVE_MANAGE);
spadeL = WResourceManager::Instance()->RetrieveQuad("spade_ul.png", 0, 0, 0, 0, "spade_ul", RETRIEVE_MANAGE);
spadeR = WResourceManager::Instance()->RetrieveQuad("spade_ur.png", 0, 0, 0, 0, "spade_ur", RETRIEVE_MANAGE);
jewel.reset(NEW JQuad(jewelTex, 1, 1, 3, 3));
side = WResourceManager::Instance()->RetrieveQuad("menuside.png", 1, 1, 1, kPoleWidth, "menuside", RETRIEVE_MANAGE);
if (NULL == stars) stars = NEW hgeParticleSystem(WResourceManager::Instance()->RetrievePSI("stars.psi", WResourceManager::Instance()->GetQuad("stars")));
if (NULL == stars)
stars = NEW hgeParticleSystem(WResourceManager::Instance()->RetrievePSI("stars.psi", WResourceManager::Instance()->GetQuad("stars").get()));
stars->FireAt(mX, mY);
}
SimpleMenu::~SimpleMenu()
@@ -83,14 +83,14 @@ void SimpleMenu::drawHorzPole(float x, float y, float width)
rightXOffset = kSpadeRightBottomOffset;
}
renderer->RenderQuad(side, x, y, 0, width);
renderer->RenderQuad(side.get(), x, y, 0, width);
spadeR->SetHFlip(true);
spadeL->SetHFlip(false);
renderer->RenderQuad(spadeR, x - leftXOffset, y - yOffset );
renderer->RenderQuad(spadeL, x + width - rightXOffset, y - yOffset);
renderer->RenderQuad(spadeR.get(), x - leftXOffset, y - yOffset );
renderer->RenderQuad(spadeL.get(), x + width - rightXOffset, y - yOffset);
renderer->RenderQuad(jewel, x, y - 1);
renderer->RenderQuad(jewel, x + width - 1, y - 1);
renderer->RenderQuad(jewel.get(), x, y - 1);
renderer->RenderQuad(jewel.get(), x + width - 1, y - 1);
}
void SimpleMenu::drawVertPole(float x, float y, float height)
@@ -110,14 +110,14 @@ void SimpleMenu::drawVertPole(float x, float y, float height)
bottomYOffset = kSpadeRightBottomOffset;
}
renderer->RenderQuad(side, x + kPoleWidth, y, M_PI / 2, height);
renderer->RenderQuad(side.get(), x + kPoleWidth, y, M_PI / 2, height);
spadeR->SetHFlip(true);
spadeL->SetHFlip(false);
renderer->RenderQuad(spadeR, x + kPoleWidth + xOffset, y - topYOffset, M_PI / 2);
renderer->RenderQuad(spadeL, x + kPoleWidth + xOffset, y + height - bottomYOffset, M_PI / 2);
renderer->RenderQuad(spadeR.get(), x + kPoleWidth + xOffset, y - topYOffset, M_PI / 2);
renderer->RenderQuad(spadeL.get(), x + kPoleWidth + xOffset, y + height - bottomYOffset, M_PI / 2);
renderer->RenderQuad(jewel, x - 1, y - 1);
renderer->RenderQuad(jewel, x - 1, y + height - 1);
renderer->RenderQuad(jewel.get(), x - 1, y - 1);
renderer->RenderQuad(jewel.get(), x - 1, y + height - 1);
}
void SimpleMenu::Render()
@@ -236,7 +236,7 @@ void SimpleMenu::Close()
void SimpleMenu::destroy()
{
SAFE_DELETE(SimpleMenu::jewel);
SimpleMenu::jewel.reset();
SAFE_DELETE(SimpleMenu::stars);
SAFE_DELETE(SimpleMenu::jewelTex);
}

View File

@@ -128,11 +128,11 @@ void SimplePopup::drawCorner(string imageName, bool flipX, bool flipY, float x,
{
LOG(" Drawing a Corner! ");
JRenderer* r = JRenderer::GetInstance();
JQuad *horizontalBarImage = WResourceManager::Instance()->RetrieveTempQuad( imageName, TEXTURE_SUB_5551);
JQuadPtr horizontalBarImage = WResourceManager::Instance()->RetrieveTempQuad( imageName, TEXTURE_SUB_5551);
horizontalBarImage->SetHFlip(flipX);
horizontalBarImage->SetVFlip(flipY);
r->RenderQuad( horizontalBarImage, x, y);
r->RenderQuad(horizontalBarImage.get(), x, y);
LOG(" Done Drawing a Corner! ");
}
@@ -140,13 +140,13 @@ void SimplePopup::drawHorzPole(string imageName, bool flipX = false, bool flipY
{
LOG(" Drawing a horizontal border! ");
JRenderer* r = JRenderer::GetInstance();
JQuad *horizontalBarImage = WResourceManager::Instance()->RetrieveTempQuad( imageName, TEXTURE_SUB_5551);
JQuadPtr horizontalBarImage = WResourceManager::Instance()->RetrieveTempQuad( imageName, TEXTURE_SUB_5551);
if ( horizontalBarImage != NULL )
{
horizontalBarImage->SetHFlip(flipX);
horizontalBarImage->SetVFlip(flipY);
r->RenderQuad( horizontalBarImage, x, y, 0, width );
r->RenderQuad(horizontalBarImage.get(), x, y, 0, width);
}
else
{
@@ -159,13 +159,13 @@ void SimplePopup::drawVertPole(string imageName, bool flipX = false, bool flipY
{
LOG(" Drawing a Vertical border! ");
JRenderer* r = JRenderer::GetInstance();
JQuad *verticalBarImage = WResourceManager::Instance()->RetrieveTempQuad( imageName, TEXTURE_SUB_5551);
JQuadPtr verticalBarImage = WResourceManager::Instance()->RetrieveTempQuad( imageName, TEXTURE_SUB_5551);
if ( verticalBarImage != NULL )
{
verticalBarImage->SetHFlip(flipX);
verticalBarImage->SetVFlip(flipY);
r->RenderQuad( verticalBarImage, x, y, 0, 1.0f, height);
r->RenderQuad(verticalBarImage.get(), x, y, 0, 1.0f, height);
}
else
{

View File

@@ -193,7 +193,7 @@ StoryImage::StoryImage(string img, float mX, float mY) :
}
void StoryImage::Render()
{
JQuad * quad = WResourceManager::Instance()->RetrieveTempQuad(img);
JQuadPtr quad = WResourceManager::Instance()->RetrieveTempQuad(img);
if (quad)
{
float x = mX;
@@ -202,13 +202,13 @@ void StoryImage::Render()
x = SCREEN_WIDTH / 2;
quad->SetHotSpot(quad->mWidth / 2, 0);
}
JRenderer::GetInstance()->RenderQuad(quad, x, mY);
JRenderer::GetInstance()->RenderQuad(quad.get(), x, mY);
}
}
float StoryImage::getHeight()
{
JQuad * quad = WResourceManager::Instance()->RetrieveQuad(img);
JQuadPtr quad = WResourceManager::Instance()->RetrieveQuad(img);
if (quad)
{
return quad->mHeight;

View File

@@ -112,19 +112,19 @@ const KeyRep& translateKey(LocalKeySym key)
KeyRep& k = res->second;
switch (key)
{
case PSP_CTRL_SELECT : k.second = WResourceManager::Instance()->RetrieveQuad("iconspsp.png", (float)2*32, 32, 64, 32, "PSP_CTRL_SELECT", RETRIEVE_NORMAL); break;
case PSP_CTRL_START : k.second = WResourceManager::Instance()->RetrieveQuad("iconspsp.png", (float)0*32, 32, 64, 32, "PSP_CTRL_START", RETRIEVE_NORMAL); break;
case PSP_CTRL_UP : k.second = WResourceManager::Instance()->RetrieveQuad("iconspsp.png", (float)0*32, 0, 32, 32, "PSP_CTRL_UP", RETRIEVE_NORMAL); break;
case PSP_CTRL_RIGHT : k.second = WResourceManager::Instance()->RetrieveQuad("iconspsp.png", (float)3*32, 0, 32, 32, "PSP_CTRL_RIGHT", RETRIEVE_NORMAL); break;
case PSP_CTRL_DOWN : k.second = WResourceManager::Instance()->RetrieveQuad("iconspsp.png", (float)1*32, 0, 32, 32, "PSP_CTRL_DOWN", RETRIEVE_NORMAL); break;
case PSP_CTRL_LEFT : k.second = WResourceManager::Instance()->RetrieveQuad("iconspsp.png", (float)2*32, 0, 32, 32, "PSP_CTRL_LEFT", RETRIEVE_NORMAL); break;
case PSP_CTRL_LTRIGGER : k.second = WResourceManager::Instance()->RetrieveQuad("iconspsp.png", (float)6*32, 32, 64, 32, "PSP_CTRL_LTRIGGER", RETRIEVE_NORMAL); break;
case PSP_CTRL_RTRIGGER : k.second = WResourceManager::Instance()->RetrieveQuad("iconspsp.png", (float)8*32, 32, 64, 32, "PSP_CTRL_RTRIGGER", RETRIEVE_NORMAL); break;
case PSP_CTRL_TRIANGLE : k.second = WResourceManager::Instance()->RetrieveQuad("iconspsp.png", (float)5*32, 0, 32, 32, "PSP_CTRL_TRIANGLE", RETRIEVE_NORMAL); break;
case PSP_CTRL_CIRCLE : k.second = WResourceManager::Instance()->RetrieveQuad("iconspsp.png", (float)4*32, 0, 32, 32, "PSP_CTRL_CIRCLE", RETRIEVE_NORMAL); break;
case PSP_CTRL_CROSS : k.second = WResourceManager::Instance()->RetrieveQuad("iconspsp.png", (float)7*32, 0, 32, 32, "PSP_CTRL_CROSS", RETRIEVE_NORMAL); break;
case PSP_CTRL_SQUARE : k.second = WResourceManager::Instance()->RetrieveQuad("iconspsp.png", (float)6*32, 0, 32, 32, "PSP_CTRL_SQUARE", RETRIEVE_NORMAL); break;
case PSP_CTRL_HOLD : k.second = WResourceManager::Instance()->RetrieveQuad("iconspsp.png", (float)4*32, 0, 32, 32, "PSP_CTRL_HOLD", RETRIEVE_NORMAL); break;
case PSP_CTRL_SELECT : k.second = WResourceManager::Instance()->RetrieveQuad("iconspsp.png", (float)2*32, 32, 64, 32, "PSP_CTRL_SELECT", RETRIEVE_NORMAL).get(); break;
case PSP_CTRL_START : k.second = WResourceManager::Instance()->RetrieveQuad("iconspsp.png", (float)0*32, 32, 64, 32, "PSP_CTRL_START", RETRIEVE_NORMAL).get(); break;
case PSP_CTRL_UP : k.second = WResourceManager::Instance()->RetrieveQuad("iconspsp.png", (float)0*32, 0, 32, 32, "PSP_CTRL_UP", RETRIEVE_NORMAL).get(); break;
case PSP_CTRL_RIGHT : k.second = WResourceManager::Instance()->RetrieveQuad("iconspsp.png", (float)3*32, 0, 32, 32, "PSP_CTRL_RIGHT", RETRIEVE_NORMAL).get(); break;
case PSP_CTRL_DOWN : k.second = WResourceManager::Instance()->RetrieveQuad("iconspsp.png", (float)1*32, 0, 32, 32, "PSP_CTRL_DOWN", RETRIEVE_NORMAL).get(); break;
case PSP_CTRL_LEFT : k.second = WResourceManager::Instance()->RetrieveQuad("iconspsp.png", (float)2*32, 0, 32, 32, "PSP_CTRL_LEFT", RETRIEVE_NORMAL).get(); break;
case PSP_CTRL_LTRIGGER : k.second = WResourceManager::Instance()->RetrieveQuad("iconspsp.png", (float)6*32, 32, 64, 32, "PSP_CTRL_LTRIGGER", RETRIEVE_NORMAL).get(); break;
case PSP_CTRL_RTRIGGER : k.second = WResourceManager::Instance()->RetrieveQuad("iconspsp.png", (float)8*32, 32, 64, 32, "PSP_CTRL_RTRIGGER", RETRIEVE_NORMAL).get(); break;
case PSP_CTRL_TRIANGLE : k.second = WResourceManager::Instance()->RetrieveQuad("iconspsp.png", (float)5*32, 0, 32, 32, "PSP_CTRL_TRIANGLE", RETRIEVE_NORMAL).get(); break;
case PSP_CTRL_CIRCLE : k.second = WResourceManager::Instance()->RetrieveQuad("iconspsp.png", (float)4*32, 0, 32, 32, "PSP_CTRL_CIRCLE", RETRIEVE_NORMAL).get(); break;
case PSP_CTRL_CROSS : k.second = WResourceManager::Instance()->RetrieveQuad("iconspsp.png", (float)7*32, 0, 32, 32, "PSP_CTRL_CROSS", RETRIEVE_NORMAL).get(); break;
case PSP_CTRL_SQUARE : k.second = WResourceManager::Instance()->RetrieveQuad("iconspsp.png", (float)6*32, 0, 32, 32, "PSP_CTRL_SQUARE", RETRIEVE_NORMAL).get(); break;
case PSP_CTRL_HOLD : k.second = WResourceManager::Instance()->RetrieveQuad("iconspsp.png", (float)4*32, 0, 32, 32, "PSP_CTRL_HOLD", RETRIEVE_NORMAL).get(); break;
default: /* Unknown key : no icon */ ;
}
return k;
@@ -191,18 +191,18 @@ const KeyRep& translateKey(JButton key) {
KeyRep& k = res->second;
switch (key)
{
case JGE_BTN_CTRL : k.second = WResourceManager::Instance()->RetrieveQuad("iconspsp.png", (float)2*32, 32, 64, 32, "PSP_CTRL_SELECT", RETRIEVE_NORMAL); break;
case JGE_BTN_MENU : k.second = WResourceManager::Instance()->RetrieveQuad("iconspsp.png", (float)0*32, 32, 64, 32, "PSP_CTRL_START", RETRIEVE_NORMAL); break;
case JGE_BTN_UP : k.second = WResourceManager::Instance()->RetrieveQuad("iconspsp.png", (float)0*32, 0, 32, 32, "PSP_CTRL_UP", RETRIEVE_NORMAL); break;
case JGE_BTN_RIGHT : k.second = WResourceManager::Instance()->RetrieveQuad("iconspsp.png", (float)3*32, 0, 32, 32, "PSP_CTRL_RIGHT", RETRIEVE_NORMAL); break;
case JGE_BTN_DOWN : k.second = WResourceManager::Instance()->RetrieveQuad("iconspsp.png", (float)1*32, 0, 32, 32, "PSP_CTRL_DOWN", RETRIEVE_NORMAL); break;
case JGE_BTN_LEFT : k.second = WResourceManager::Instance()->RetrieveQuad("iconspsp.png", (float)2*32, 0, 32, 32, "PSP_CTRL_LEFT", RETRIEVE_NORMAL); break;
case JGE_BTN_PREV : k.second = WResourceManager::Instance()->RetrieveQuad("iconspsp.png", (float)6*32, 32, 64, 32, "PSP_CTRL_LTRIGGER", RETRIEVE_NORMAL); break;
case JGE_BTN_NEXT : k.second = WResourceManager::Instance()->RetrieveQuad("iconspsp.png", (float)8*32, 32, 64, 32, "PSP_CTRL_RTRIGGER", RETRIEVE_NORMAL); break;
case JGE_BTN_CANCEL : k.second = WResourceManager::Instance()->RetrieveQuad("iconspsp.png", (float)5*32, 0, 32, 32, "PSP_CTRL_TRIANGLE", RETRIEVE_NORMAL); break;
case JGE_BTN_OK : k.second = WResourceManager::Instance()->RetrieveQuad("iconspsp.png", (float)4*32, 0, 32, 32, "PSP_CTRL_CIRCLE", RETRIEVE_NORMAL); break;
case JGE_BTN_SEC : k.second = WResourceManager::Instance()->RetrieveQuad("iconspsp.png", (float)7*32, 0, 32, 32, "PSP_CTRL_CROSS", RETRIEVE_NORMAL); break;
case JGE_BTN_PRI : k.second = WResourceManager::Instance()->RetrieveQuad("iconspsp.png", (float)6*32, 0, 32, 32, "PSP_CTRL_SQUARE", RETRIEVE_NORMAL); break;
case JGE_BTN_CTRL : k.second = WResourceManager::Instance()->RetrieveQuad("iconspsp.png", (float)2*32, 32, 64, 32, "PSP_CTRL_SELECT", RETRIEVE_NORMAL).get(); break;
case JGE_BTN_MENU : k.second = WResourceManager::Instance()->RetrieveQuad("iconspsp.png", (float)0*32, 32, 64, 32, "PSP_CTRL_START", RETRIEVE_NORMAL).get(); break;
case JGE_BTN_UP : k.second = WResourceManager::Instance()->RetrieveQuad("iconspsp.png", (float)0*32, 0, 32, 32, "PSP_CTRL_UP", RETRIEVE_NORMAL).get(); break;
case JGE_BTN_RIGHT : k.second = WResourceManager::Instance()->RetrieveQuad("iconspsp.png", (float)3*32, 0, 32, 32, "PSP_CTRL_RIGHT", RETRIEVE_NORMAL).get(); break;
case JGE_BTN_DOWN : k.second = WResourceManager::Instance()->RetrieveQuad("iconspsp.png", (float)1*32, 0, 32, 32, "PSP_CTRL_DOWN", RETRIEVE_NORMAL).get(); break;
case JGE_BTN_LEFT : k.second = WResourceManager::Instance()->RetrieveQuad("iconspsp.png", (float)2*32, 0, 32, 32, "PSP_CTRL_LEFT", RETRIEVE_NORMAL).get(); break;
case JGE_BTN_PREV : k.second = WResourceManager::Instance()->RetrieveQuad("iconspsp.png", (float)6*32, 32, 64, 32, "PSP_CTRL_LTRIGGER", RETRIEVE_NORMAL).get(); break;
case JGE_BTN_NEXT : k.second = WResourceManager::Instance()->RetrieveQuad("iconspsp.png", (float)8*32, 32, 64, 32, "PSP_CTRL_RTRIGGER", RETRIEVE_NORMAL).get(); break;
case JGE_BTN_CANCEL : k.second = WResourceManager::Instance()->RetrieveQuad("iconspsp.png", (float)5*32, 0, 32, 32, "PSP_CTRL_TRIANGLE", RETRIEVE_NORMAL).get(); break;
case JGE_BTN_OK : k.second = WResourceManager::Instance()->RetrieveQuad("iconspsp.png", (float)4*32, 0, 32, 32, "PSP_CTRL_CIRCLE", RETRIEVE_NORMAL).get(); break;
case JGE_BTN_SEC : k.second = WResourceManager::Instance()->RetrieveQuad("iconspsp.png", (float)7*32, 0, 32, 32, "PSP_CTRL_CROSS", RETRIEVE_NORMAL).get(); break;
case JGE_BTN_PRI : k.second = WResourceManager::Instance()->RetrieveQuad("iconspsp.png", (float)6*32, 0, 32, 32, "PSP_CTRL_SQUARE", RETRIEVE_NORMAL).get(); break;
default: /* Unknown key : no icon */ ;
}
return k;

View File

@@ -77,19 +77,7 @@ WCachedTexture::WCachedTexture()
WCachedTexture::~WCachedTexture()
{
if (texture)
SAFE_DELETE(texture);
if (!trackedQuads.size()) return;
vector<WTrackedQuad*>::iterator it;
WTrackedQuad * tq = NULL;
for (it = trackedQuads.begin(); it != trackedQuads.end(); it++)
{
tq = (*it);
SAFE_DELETE(tq);
}
trackedQuads.clear();
SAFE_DELETE(texture);
}
JTexture * WCachedTexture::Actual()
@@ -99,135 +87,44 @@ JTexture * WCachedTexture::Actual()
bool WCachedTexture::isLocked()
{
if (locks != WRES_UNLOCKED) return true;
for (vector<WTrackedQuad*>::iterator it = trackedQuads.begin(); it != trackedQuads.end(); it++)
{
if ((*it) && (*it)->isLocked()) return true;
//null case
//tokens that were using workarounds such as mixes of aslongas with CD checks
//and thisforeach would call to cache the tokens image, but since the effect never resolved it was NULL
//when it came time to check if it was locked, it would trigger a break point here.
}
return false;
return (locks != WRES_UNLOCKED);
}
bool WCachedTexture::ReleaseQuad(JQuad* quad)
JQuadPtr WCachedTexture::GetQuad(float offX, float offY, float width, float height, const string& resname)
{
if (quad == NULL) return false;
WTrackedQuad * tq = NULL;
vector<WTrackedQuad*>::iterator nit;
for (vector<WTrackedQuad*>::iterator it = trackedQuads.begin(); it != trackedQuads.end(); it = nit)
{
nit = it;
nit++;
if ((*it) && (*it)->quad == quad)
{
tq = (*it);
tq->unlock();
if (!tq->isLocked())
{
SAFE_DELETE(tq);
trackedQuads.erase(it);
}
return true; //Returns true when found.
}
}
return false;
}
WTrackedQuad * WCachedTexture::GetTrackedQuad(float offX, float offY, float width, float height, string resname)
{
if (!texture) return NULL;
bool allocated = false;
WTrackedQuad * tq = NULL;
JQuad * quad = NULL;
vector<WTrackedQuad*>::iterator it;
if (!texture) return JQuadPtr();
if (width == 0.0f || width > static_cast<float> (texture->mWidth)) width = static_cast<float> (texture->mWidth);
if (height == 0.0f || height > static_cast<float> (texture->mHeight)) height = static_cast<float> (texture->mHeight);
for (it = trackedQuads.begin(); it != trackedQuads.end(); it++)
{
if ((*it) && (*it)->resname == resname)
{
tq = (*it);
break;
}
}
std::map<string, JQuadPtr>::iterator iter = mTrackedQuads.find(resname);
if (iter != mTrackedQuads.end())
return iter->second;
if (!tq)
{
allocated = true;
tq = NEW WTrackedQuad(resname);
if (!tq) return NULL;
}
quad = tq->quad;
if (!quad)
{
quad = NEW JQuad(texture, offX, offY, width, height);
/*
There's a risk this erases the texture calling the quad creation.... Erwan 2010/03/13
if(!quad) {
//Probably out of memory. Try again.
WResourceManager::Instance()->Cleanup();
quad = NEW JQuad(texture,offX,offY,width,height);
}
*/
if (!quad)
{
if (allocated && tq)
SAFE_DELETE(tq);
fprintf(stderr, "WCACHEDRESOURCE:GetTrackedQuad - Quad is null\n");
return NULL; //Probably a crash.
}
tq->quad = quad;
if (allocated) trackedQuads.push_back(tq);
return tq;
}
JQuadPtr quad(NEW JQuad(texture, offX, offY, width, height));
//Update JQ's values to what we called this with.
quad->SetTextureRect(offX, offY, width, height);
return tq;
mTrackedQuads.insert(std::pair<string, JQuadPtr>(resname, quad));
return quad;
}
JQuad * WCachedTexture::GetQuad(float offX, float offY, float width, float height, string resname)
JQuadPtr WCachedTexture::GetQuad(const string& resname)
{
WTrackedQuad * tq = GetTrackedQuad(offX, offY, width, height, resname);
JQuadPtr result;
std::map<string, JQuadPtr>::iterator iter = mTrackedQuads.find(resname);
if (iter != mTrackedQuads.end())
result = iter->second;
if (tq) return tq->quad;
return NULL;
return result;
}
JQuad * WCachedTexture::GetQuad(string resname)
JQuadPtr WCachedTexture::GetCard(float offX, float offY, float width, float height, const string& resname)
{
vector<WTrackedQuad*>::iterator it;
for (it = trackedQuads.begin(); it != trackedQuads.end(); it++)
{
if ((*it) && (*it)->resname == resname)
{
return (*it)->quad;
}
}
return NULL;
}
JQuad * WCachedTexture::GetCard(float offX, float offY, float width, float height, string resname)
{
JQuad * jq = GetQuad(offX, offY, width, height, resname);
if (jq) jq->SetHotSpot(static_cast<float> (jq->mTex->mWidth / 2), static_cast<float> (jq->mTex->mHeight / 2));
JQuadPtr jq = GetQuad(offX, offY, width, height, resname);
if (jq.get())
jq->SetHotSpot(static_cast<float> (jq->mTex->mWidth / 2), static_cast<float> (jq->mTex->mHeight / 2));
return jq;
}
@@ -265,46 +162,45 @@ void WCachedTexture::Refresh()
JRenderer::GetInstance()->TransferTextureToGLContext(*texture);
for (vector<WTrackedQuad*>::iterator it = trackedQuads.begin(); it != trackedQuads.end(); it++)
for (map<string, JQuadPtr>::iterator it = mTrackedQuads.begin(); it != mTrackedQuads.end(); ++it)
{
if ((*it) && (*it)->quad) (*it)->quad->mTex = texture;
if (it->second.get())
it->second->mTex = texture;
}
}
bool WCachedTexture::Attempt(string filename, int submode, int & error)
bool WCachedTexture::Attempt(const string& filename, int submode, int & error)
{
mFilename = filename;
int format = TEXTURE_FORMAT;
loadedMode = submode;
string realname;
string realname = filename;
//Form correct filename.
if (submode & TEXTURE_SUB_EXACT)
realname = filename;
else if (submode & TEXTURE_SUB_CARD)
if (submode & TEXTURE_SUB_CARD)
{
if (submode & TEXTURE_SUB_THUMB)
{
for (string::size_type i = 0; i < filename.size(); i++)
for (string::size_type i = 0; i < realname.size(); i++)
{
if (filename[i] == '\\' || filename[i] == '/')
if (realname[i] == '\\' || realname[i] == '/')
{
filename.insert(i + 1, "thumbnails/");
realname.insert(i + 1, "thumbnails/");
break;
}
}
}
realname = WResourceManager::Instance()->cardFile(filename);
realname = WResourceManager::Instance()->cardFile(realname);
}
else
{
if (submode & TEXTURE_SUB_THUMB) filename.insert(0, "thumbnails/");
if (submode & TEXTURE_SUB_THUMB) realname.insert(0, "thumbnails/");
if (submode & TEXTURE_SUB_AVATAR)
realname = WResourceManager::Instance()->avatarFile(filename);
realname = WResourceManager::Instance()->avatarFile(realname);
else
realname = WResourceManager::Instance()->graphicsFile(filename);
realname = WResourceManager::Instance()->graphicsFile(realname);
}
//Apply pixel mode
@@ -364,7 +260,7 @@ void WCachedSample::Refresh()
return;
}
bool WCachedSample::Attempt(string filename, int submode, int & error)
bool WCachedSample::Attempt(const string& filename, int submode, int & error)
{
loadedMode = submode;
@@ -418,7 +314,7 @@ void WCachedParticles::Refresh()
return;
}
bool WCachedParticles::Attempt(string filename, int submode, int & error)
bool WCachedParticles::Attempt(const string& filename, int submode, int & error)
{
JFileSystem* fileSys = JFileSystem::GetInstance();
@@ -459,26 +355,3 @@ WCachedParticles::~WCachedParticles()
{
SAFE_DELETE(particles);
}
//WTrackedQuad
unsigned long WTrackedQuad::size()
{
return sizeof(JQuad);
}
bool WTrackedQuad::isGood()
{
return (quad != NULL);
}
WTrackedQuad::WTrackedQuad(string _resname)
{
quad = NULL;
resname = _resname;
}
WTrackedQuad::~WTrackedQuad()
{
if (quad)
SAFE_DELETE(quad);
}

View File

@@ -35,7 +35,7 @@ bool WSyncable::prev()
}
//WSrcImage
JQuad * WSrcImage::getImage(int offset)
JQuadPtr WSrcImage::getImage(int offset)
{
return WResourceManager::Instance()->RetrieveTempQuad(filename);
}
@@ -54,7 +54,7 @@ WSrcCards::WSrcCards(float delay)
filtersRoot = NULL;
}
JQuad * WSrcCards::getImage(int offset)
JQuadPtr WSrcCards::getImage(int offset)
{
#if defined WIN32 || defined LINUX //Loading delay only on PSP.
#else
@@ -66,7 +66,7 @@ JQuad * WSrcCards::getImage(int offset)
return WResourceManager::Instance()->RetrieveCard(getCard(offset));
}
JQuad * WSrcCards::getThumb(int offset)
JQuadPtr WSrcCards::getThumb(int offset)
{
return WResourceManager::Instance()->RetrieveCard(getCard(offset), RETRIEVE_THUMB);
}

View File

@@ -504,22 +504,22 @@ void WFBFont::DrawString(const char *s, float x, float y, int align, float leftO
float scale = 0.05f * cosf(2 * M_PI * ((float) t) / 256.0f);
if (scale < 0)
{
mRenderer->RenderQuad(manaIcons[mana], xx + 3 * sinf(2 * M_PI * ((float) t) / 256.0f), yy + 3 * cosf(2
mRenderer->RenderQuad(manaIcons[mana].get(), xx + 3 * sinf(2 * M_PI * ((float) t) / 256.0f), yy + 3 * cosf(2
* M_PI * ((float) (t - 35)) / 256.0f), 0, 0.5f * mScale, 0.5f * mScale);
mRenderer->RenderQuad(manaIcons[mana2], xx + 3 * sinf(2 * M_PI * ((float) v) / 256.0f), yy + 3 * cosf(2
mRenderer->RenderQuad(manaIcons[mana2].get(), xx + 3 * sinf(2 * M_PI * ((float) v) / 256.0f), yy + 3 * cosf(2
* M_PI * ((float) (v - 35)) / 256.0f), 0, 0.5f * mScale, 0.5f * mScale);
}
else
{
mRenderer->RenderQuad(manaIcons[mana2], xx + 3 * sinf(2 * M_PI * ((float) v) / 256.0f), yy + 3 * cosf(2
mRenderer->RenderQuad(manaIcons[mana2].get(), xx + 3 * sinf(2 * M_PI * ((float) v) / 256.0f), yy + 3 * cosf(2
* M_PI * ((float) (v - 35)) / 256.0f), 0, 0.5f * mScale, 0.5f * mScale);
mRenderer->RenderQuad(manaIcons[mana], xx + 3 * sinf(2 * M_PI * ((float) t) / 256.0f), yy + 3 * cosf(2
mRenderer->RenderQuad(manaIcons[mana].get(), xx + 3 * sinf(2 * M_PI * ((float) t) / 256.0f), yy + 3 * cosf(2
* M_PI * ((float) (t - 35)) / 256.0f), 0, 0.5f * mScale, 0.5f * mScale);
}
mana = Constants::MTG_NB_COLORS + 1; // do not draw colorless cost in hybrid mana cost
}
else
mRenderer->RenderQuad(manaIcons[mana], xx, yy, 0, 0.5f * mScale, 0.5f * mScale);
mRenderer->RenderQuad(manaIcons[mana].get(), xx, yy, 0, 0.5f * mScale, 0.5f * mScale);
mRenderer->BindTexture(mTexture); // manaIcons use different texture, so we need to rebind it.
}
@@ -923,22 +923,22 @@ void WGBKFont::DrawString(const char *s, float x, float y, int align, float left
float scale = 0.05f * cosf(2 * M_PI * ((float) t) / 256.0f);
if (scale < 0)
{
mRenderer->RenderQuad(manaIcons[mana], xx + 3 * sinf(2 * M_PI * ((float) t) / 256.0f), yy + 3 * cosf(2
mRenderer->RenderQuad(manaIcons[mana].get(), xx + 3 * sinf(2 * M_PI * ((float) t) / 256.0f), yy + 3 * cosf(2
* M_PI * ((float) (t - 35)) / 256.0f), 0, 0.5f * mScale, 0.5f * mScale);
mRenderer->RenderQuad(manaIcons[mana2], xx + 3 * sinf(2 * M_PI * ((float) v) / 256.0f), yy + 3 * cosf(2
mRenderer->RenderQuad(manaIcons[mana2].get(), xx + 3 * sinf(2 * M_PI * ((float) v) / 256.0f), yy + 3 * cosf(2
* M_PI * ((float) (v - 35)) / 256.0f), 0, 0.5f * mScale, 0.5f * mScale);
}
else
{
mRenderer->RenderQuad(manaIcons[mana2], xx + 3 * sinf(2 * M_PI * ((float) v) / 256.0f), yy + 3 * cosf(2
mRenderer->RenderQuad(manaIcons[mana2].get(), xx + 3 * sinf(2 * M_PI * ((float) v) / 256.0f), yy + 3 * cosf(2
* M_PI * ((float) (v - 35)) / 256.0f), 0, 0.5f * mScale, 0.5f * mScale);
mRenderer->RenderQuad(manaIcons[mana], xx + 3 * sinf(2 * M_PI * ((float) t) / 256.0f), yy + 3 * cosf(2
mRenderer->RenderQuad(manaIcons[mana].get(), xx + 3 * sinf(2 * M_PI * ((float) t) / 256.0f), yy + 3 * cosf(2
* M_PI * ((float) (t - 35)) / 256.0f), 0, 0.5f * mScale, 0.5f * mScale);
}
mana = Constants::MTG_NB_COLORS + 1; // donot draw colorless cost in hybrid mana cost
}
else
mRenderer->RenderQuad(manaIcons[mana], xx, yy, 0, 0.5f * mScale, 0.5f * mScale);
mRenderer->RenderQuad(manaIcons[mana].get(), xx, yy, 0, 0.5f * mScale, 0.5f * mScale);
mRenderer->BindTexture(mTexture); // manaIcons use different texture, so we need to rebind it.
}

View File

@@ -38,6 +38,7 @@ PIXEL_TYPE WGuiBase::getColor(int type)
}
return ARGB(150,50,50,50);
}
/**
Renders the backdrop of a WGui item.
Meant to be overriden in subclasses that require a unique backdrop.
@@ -102,7 +103,6 @@ bool WGuiItem::Leaving(JButton key)
void WGuiItem::Render()
{
WFont * mFont = WResourceManager::Instance()->GetWFont(Fonts::OPTION_FONT);
DWORD oldcolor = mFont->GetColor();
mFont->SetColor(getColor(WGuiColor::TEXT));
@@ -1203,10 +1203,10 @@ void WGuiAward::Overlay()
float fH = mFont->GetHeight();
if (fH < 16) fH = 18;
JQuad * button = WResourceManager::Instance()->RetrieveQuad("iconspsp.png", (float) 4 * 32, 0, 32, 32, "", RETRIEVE_NORMAL);
JQuadPtr button = WResourceManager::Instance()->RetrieveQuad("iconspsp.png", (float) 4 * 32, 0, 32, 32, "", RETRIEVE_NORMAL);
r->FillRoundRect(5, 10, fW + 32, fH + 2, 2, getColor(WGuiColor::BACK));
if (button) r->RenderQuad(button, 10, 12, 0, .5, .5);
if (button) r->RenderQuad(button.get(), 10, 12, 0, .5, .5);
mFont->DrawString(::_(s), 30, 16);
}
@@ -1215,8 +1215,7 @@ void WGuiAward::Overlay()
void WGuiAward::Underlay()
{
char buf[1024];
JRenderer * r = JRenderer::GetInstance();
JQuad * trophy = NULL;
JQuadPtr trophy;
string n = Options::getName(id);
if (n.size())
@@ -1230,12 +1229,12 @@ void WGuiAward::Underlay()
trophy = WResourceManager::Instance()->RetrieveTempQuad("trophy_set.png"); //TODO FIXME: Should look in set dir too.
}
if (!trophy) //Fallback to basic trophy image.
if (!trophy.get()) //Fallback to basic trophy image.
trophy = WResourceManager::Instance()->RetrieveTempQuad("trophy.png");
if (trophy)
if (trophy.get())
{
r->RenderQuad(trophy, 0, SCREEN_HEIGHT - trophy->mHeight);
JRenderer::GetInstance()->RenderQuad(trophy.get(), 0, SCREEN_HEIGHT - trophy->mHeight);
}
}
@@ -1245,7 +1244,6 @@ void WGuiAward::Render()
if (!goa) return;
JRenderer * renderer = JRenderer::GetInstance();
WFont * mFont = WResourceManager::Instance()->GetWFont(Fonts::OPTION_FONT);
mFont->SetScale(1);
mFont->SetColor(getColor(WGuiColor::TEXT));
@@ -1256,7 +1254,7 @@ void WGuiAward::Render()
float fM = fH / 5; //Font Margin is 20% font height
myX += fM;
renderer->FillRoundRect(x - fM / 2, y - fM, getWidth() - fM, fH - fM, fM, getColor(WGuiColor::BACK_TAB));
JRenderer::GetInstance()->FillRoundRect(x - fM / 2, y - fM, getWidth() - fM, fH - fM, fM, getColor(WGuiColor::BACK_TAB));
mFont->DrawString(::_(displayValue).c_str(), myX, myY, JGETEXT_LEFT);
myY += fH + 3 * fM;
@@ -1292,7 +1290,7 @@ WGuiAward::~WGuiAward()
}
bool WGuiAward::Visible()
{
//WGuiAward is only visible when it's tied to an already acchieved award.
//WGuiAward is only visible when it's tied to an already achieved award.
GameOptionAward * goa = dynamic_cast<GameOptionAward*> (&options[id]);
if (!goa || !goa->number) return false;
return true;
@@ -1316,11 +1314,11 @@ void WGuiImage::imageScale(float _w, float _h)
float WGuiImage::getHeight()
{
JQuad * q = NULL;
JQuadPtr q = source->getImage();
if (imgH == 0)
{
if (source && (q = source->getImage())) //Intentional assignment.
if (source && q.get())
return MAX(height,q->mHeight+(2*margin));
}
@@ -1331,15 +1329,14 @@ void WGuiImage::Render()
{
if (!source) return;
JRenderer * renderer = JRenderer::GetInstance();
JQuad * q = source->getImage();
JQuadPtr q = source->getImage();
if (q)
{
float xS = 1, yS = 1;
if (imgH != 0 && q->mHeight != 0) yS = imgH / q->mHeight;
if (imgW != 0 && q->mWidth != 0) xS = imgW / q->mWidth;
renderer->RenderQuad(q, x + margin, y + margin, 0, xS, yS);
JRenderer::GetInstance()->RenderQuad(q.get(), x + margin, y + margin, 0, xS, yS);
}
}
@@ -1358,7 +1355,7 @@ void WGuiCardImage::Render()
if (!source || (c = source->getCard(mOffset.getPos())) == NULL)
{ //No card, use card back.
JQuad * q;
JQuadPtr q;
if (bThumb)
{
q = WResourceManager::Instance()->GetQuad("back_thumb");
@@ -1371,13 +1368,13 @@ void WGuiCardImage::Render()
q = WResourceManager::Instance()->GetQuad("back");
float scale = p.actZ * 257.f / q->mHeight;
q->SetColor(ARGB(255,255,255,255));
renderer->RenderQuad(q, p.x, p.y, 0, scale, scale);
renderer->RenderQuad(q.get(), p.x, p.y, 0, scale, scale);
}
else
{ //Have card.
if (bThumb)
{ //Thumbnail.
JQuad * q = NULL;
JQuadPtr q;
if (!options[Options::DISABLECARDS].number)
{
q = source->getThumb(mOffset.getPos());
@@ -1386,14 +1383,19 @@ void WGuiCardImage::Render()
q = source->getImage(mOffset.getPos());
#endif
}
if (!q && (q = CardGui::AlternateThumbQuad(c)) == NULL) return; //TODO Some kind of error image.
renderer->RenderQuad(q, p.x, p.y);
if (!q.get())
{
q = CardGui::AlternateThumbQuad(c);
if (q.get() == NULL)
return; //TODO Some kind of error image.
}
renderer->RenderQuad(q.get(), p.x, p.y);
}
else
{ //Normal card.
JQuad * q = source->getImage(mOffset.getPos());
JQuadPtr q = source->getImage(mOffset.getPos());
int mode = (!q || options[Options::DISABLECARDS].number) ? DrawMode::kText : DrawMode::kNormal;
int mode = (!q.get() || options[Options::DISABLECARDS].number) ? DrawMode::kText : DrawMode::kNormal;
CardGui::DrawCard(c, p, mode);
}
}
@@ -1413,7 +1415,7 @@ WGuiCardDistort::~WGuiCardDistort()
void WGuiCardDistort::Render()
{
JQuad * q = NULL;
JQuadPtr q;
if (distortSrc)
{
@@ -1455,7 +1457,7 @@ void WGuiCardDistort::Render()
if (!q || options[Options::DISABLECARDS].number) q = CardGui::AlternateThumbQuad(c); //TODO alternateX should render to texture.
}
}
if (!q) return;
if (!q.get()) return;
mesh->SetTexture(q->mTex);
float x0, y0, w0, h0;
q->GetTextureRect(&x0, &y0, &w0, &h0);
@@ -1511,7 +1513,6 @@ WDistort::WDistort(float x1, float y1, float x2, float y2, float x3, float y3, f
void WGuiListRow::Render()
{
int start = 0, nowPos = 0, vHeight = 0;
int nbitems = (int) items.size();

View File

@@ -172,13 +172,6 @@ WResourceManager::WResourceManager()
#ifdef DEBUG_CACHE
menuCached = 0;
#endif
mTextureList.clear();
mTextureList.reserve(0);
mTextureMap.clear();
mQuadList.clear();
mQuadList.reserve(0);
mQuadMap.clear();
psiWCache.Resize(PSI_CACHE_SIZE, 20);
sampleWCache.Resize(SAMPLES_CACHE_SIZE, MAX_CACHED_SAMPLES);
@@ -192,16 +185,15 @@ WResourceManager::WResourceManager()
WResourceManager::~WResourceManager()
{
LOG("==Destroying WResourceManager==");
RemoveAll();
RemoveWFonts();
LOG("==Successfully Destroyed WResourceManager==");
}
JQuad * WResourceManager::RetrieveCard(MTGCard * card, int style, int submode)
JQuadPtr WResourceManager::RetrieveCard(MTGCard * card, int style, int submode)
{
//Cards are never, ever resource managed, so just check cache.
if (!card || options[Options::DISABLECARDS].number) return NULL;
if (!card || options[Options::DISABLECARDS].number) return JQuadPtr();
submode = submode | TEXTURE_SUB_CARD;
@@ -224,14 +216,14 @@ JQuad * WResourceManager::RetrieveCard(MTGCard * card, int style, int submode)
// In that case, we "unmiss" it after trying the [id].jpg, in order to give a chance to the [name.jpg]
bool canUnmiss = false;
{
JQuad * tempQuad = RetrieveQuad(filename1, 0, 0, 0, 0, "", RETRIEVE_EXISTING, submode | TEXTURE_SUB_5551, id);
JQuadPtr tempQuad = RetrieveQuad(filename1, 0, 0, 0, 0, "", RETRIEVE_EXISTING, submode | TEXTURE_SUB_5551, id);
lastError = textureWCache.mError;
if (!tempQuad && lastError != CACHE_ERROR_404)
{
canUnmiss = true;
}
}
JQuad * jq = RetrieveQuad(filename1, 0, 0, 0, 0, "", style, submode | TEXTURE_SUB_5551, id);
JQuadPtr jq = RetrieveQuad(filename1, 0, 0, 0, 0, "", style, submode | TEXTURE_SUB_5551, id);
if (!jq)
{
if (canUnmiss)
@@ -258,7 +250,7 @@ JQuad * WResourceManager::RetrieveCard(MTGCard * card, int style, int submode)
return jq;
}
return NULL;
return JQuadPtr();
}
int WResourceManager::AddQuadToManaged(const WManagedQuad& inQuad)
@@ -288,11 +280,11 @@ int WResourceManager::CreateQuad(const string &quadName, const string &textureNa
if (jtex)
{
WTrackedQuad * tq = jtex->GetTrackedQuad(x, y, width, height, quadName);
JQuadPtr quad = jtex->GetQuad(x, y, width, height, quadName);
if (tq)
if (quad.get())
{
tq->deadbolt();
jtex->deadbolt();
WManagedQuad mq;
mq.resname = quadName;
@@ -305,10 +297,9 @@ int WResourceManager::CreateQuad(const string &quadName, const string &textureNa
return id;
}
JQuad* WResourceManager::GetQuad(const string &quadName)
JQuadPtr WResourceManager::GetQuad(const string &quadName)
{
JQuad* result = NULL;
JQuadPtr result;
ManagedQuadMap::const_iterator found = mManagedQuads.find(quadName);
if (found != mManagedQuads.end())
{
@@ -318,16 +309,15 @@ JQuad* WResourceManager::GetQuad(const string &quadName)
return result;
}
JQuad * WResourceManager::GetQuad(int id)
JQuadPtr WResourceManager::GetQuad(int id)
{
JQuad* result = NULL;
JQuadPtr result;
if (id < 0 || id >= (int) mManagedQuads.size()) return result;
IDLookupMap::const_iterator key = mIDLookupMap.find(id);
if (key != mIDLookupMap.end())
{
WCachedTexture * jtex = mManagedQuads[key->second].texture;
WCachedTexture* jtex = mManagedQuads[key->second].texture;
if (jtex)
{
result = jtex->GetQuad(key->second);
@@ -337,21 +327,19 @@ JQuad * WResourceManager::GetQuad(int id)
return result;
}
JQuad * WResourceManager::RetrieveTempQuad(const string& filename, int submode)
JQuadPtr WResourceManager::RetrieveTempQuad(const string& filename, int submode)
{
return RetrieveQuad(filename, 0, 0, 0, 0, "temporary", RETRIEVE_NORMAL, submode);
}
JQuad * WResourceManager::RetrieveQuad(const string& filename, float offX, float offY, float width, float height, string resname,
JQuadPtr WResourceManager::RetrieveQuad(const string& filename, float offX, float offY, float width, float height, string resname,
int style, int submode, int id)
{
JQuad * jq = NULL;
//Lookup managed resources, but only with a real resname.
if (resname.size() && (style == RETRIEVE_MANAGE || style == RETRIEVE_RESOURCE))
{
jq = GetQuad(resname);
if (jq || style == RETRIEVE_RESOURCE) return jq;
JQuadPtr quad = GetQuad(resname);
if (quad.get() || style == RETRIEVE_RESOURCE) return quad;
}
//Aliases.
@@ -374,14 +362,15 @@ JQuad * WResourceManager::RetrieveQuad(const string& filename, float offX, float
lastError = textureWCache.mError;
//Somehow, jtex wasn't promoted.
if (style == RETRIEVE_MANAGE && jtex && !jtex->isPermanent()) return NULL;
if (style == RETRIEVE_MANAGE && jtex && !jtex->isPermanent()) return JQuadPtr();
//Make this quad, overwriting any similarly resname'd quads.
if (jtex)
{
WTrackedQuad * tq = jtex->GetTrackedQuad(offX, offY, width, height, resname);
JQuadPtr quad = jtex->GetQuad(offX, offY, width, height, resname);
if (!tq) return NULL;
if (!quad.get())
return quad;
if (style == RETRIEVE_MANAGE && resname != "")
{
@@ -392,16 +381,16 @@ JQuad * WResourceManager::RetrieveQuad(const string& filename, float offX, float
}
if (style == RETRIEVE_LOCK)
tq->lock();
jtex->lock();
else if (style == RETRIEVE_UNLOCK)
tq->unlock();
else if (style == RETRIEVE_MANAGE) tq->deadbolt();
jtex->unlock();
else if (style == RETRIEVE_MANAGE) jtex->deadbolt();
return tq->quad;
return quad;
}
//Texture doesn't exist, so no quad.
return NULL;
return JQuadPtr();
}
void WResourceManager::Release(JTexture * tex)
@@ -442,16 +431,7 @@ void WResourceManager::ClearUnlocked()
sampleWCache.ClearUnlocked();
psiWCache.ClearUnlocked();
}
bool WResourceManager::Cleanup()
{
int check = 0;
if (textureWCache.Cleanup()) check++;
if (sampleWCache.Cleanup()) check++;
if (psiWCache.Cleanup()) check++;
return (check > 0);
}
void WResourceManager::Release(JSample * sample)
{
if (!sample) return;
@@ -985,74 +965,6 @@ void WResourceManager::Refresh()
textureWCache.Refresh();
psiWCache.Refresh();
map<string, WCachedTexture*>::iterator it;
vector<JQuad*>::iterator q;
//Now do some juggling so that managed resources also reload.
map<JTexture *, JTexture *> oldTextures;
map<JTexture *, string> newNames;
map<JTexture *, JTexture *>::iterator oldIt;
vector<JTexture*>::iterator jtex;
map<string, int>::iterator mapping;
JTexture * newtex;
JTexture * oldtex = NULL;
//Store old mappings.
for (mapping = mTextureMap.begin(); mapping != mTextureMap.end(); mapping++)
{
if (oldTextures[mTextureList[mapping->second]] == NULL)
{
newtex = JRenderer::GetInstance()->LoadTexture(graphicsFile(mapping->first).c_str(), 0, TEXTURE_FORMAT);
oldtex = mTextureList[mapping->second];
if (!newtex)
newNames[oldtex] = mapping->first;
else
{
newNames[newtex] = mapping->first;
}
oldTextures[oldtex] = newtex;
}
}
//Remap quads.
for (q = mQuadList.begin(); q != mQuadList.end(); q++)
{
newtex = oldTextures[(*q)->mTex];
if (newtex != NULL) (*q)->mTex = newtex;
}
//Rebuild mTextureList and mapping.
mTextureList.clear();
mTextureMap.clear();
int x = 0;
for (oldIt = oldTextures.begin(); oldIt != oldTextures.end(); oldIt++)
{
if (oldIt->second)
newtex = oldIt->second;
else
newtex = oldIt->first;
mTextureList.push_back(newtex);
mTextureMap[newNames[newtex]] = x;
x++;
}
//Rebuild mapping.
for (mapping = mTextureMap.begin(); mapping != mTextureMap.end(); mapping++)
{
if (oldTextures[mTextureList[mapping->second]] == NULL) continue;
}
//Delete unused textures.
for (oldIt = oldTextures.begin(); oldIt != oldTextures.end(); oldIt++)
{
if (!oldIt->second || !oldIt->first) continue;
SAFE_DELETE(oldtex);
}
//Check for card images in theme.
bThemedCards = false;
if (!options[Options::ACTIVE_THEME].isDefault())
@@ -1199,7 +1111,7 @@ cacheItem* WCache<cacheItem, cacheActual>::Retrieve(int id, const string& filena
//Unlink the managed resource from the cache.
UnlinkCache(tc);
//Post it in managed WResourceManager::Instance()->
//Post it in managed resources.
managed[makeID(id, filename, submode)] = tc;
tc->deadbolt();
}
@@ -1221,8 +1133,8 @@ cacheItem* WCache<cacheItem, cacheActual>::Retrieve(int id, const string& filena
}
//Record managed failure. Cache failure is recorded in Get().
if ((style == RETRIEVE_MANAGE || style == RETRIEVE_RESOURCE) && mError == CACHE_ERROR_404) managed[makeID(id, filename, submode)]
= NULL;
if ((style == RETRIEVE_MANAGE || style == RETRIEVE_RESOURCE) && mError == CACHE_ERROR_404)
managed[makeID(id, filename, submode)] = NULL;
return NULL;
}