Files
wagic/projects/mtg/include/GameStateShop.h
wrenczes@gmail.com 76cba56a1c 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.
2011-02-01 10:37:21 +00:00

124 lines
2.9 KiB
C++

#ifndef _GAME_STATE_SHOP_H_
#define _GAME_STATE_SHOP_H_
#include <JGE.h>
#include "GameState.h"
#include "SimpleMenu.h"
#include "OptionItem.h"
#include "PriceList.h"
#include "PlayerData.h"
#include "CardDisplay.h"
#include "DeckDataWrapper.h"
#include "Tasks.h"
#define STATE_BUY 1
#define STATE_SELL 2
#define STAGE_SHOP_MENU 3
#define STAGE_SHOP_SHOP 4
#define STAGE_SHOP_TASKS 5
#define STAGE_FADE_IN 6
#define STAGE_ASK_ABOUT 7
#define STAGE_SHOP_PURCHASE 8
#define BOOSTER_SLOTS 3
#define SHOP_SLOTS 11
#define SHOP_ITEMS SHOP_SLOTS+1
#define LIST_FADEIN 15
class MTGPack;
class MTGPacks;
class BoosterDisplay: public CardDisplay
{
public:
BoosterDisplay(int id, GameObserver* game, int x, int y, JGuiListener * listener = NULL, TargetChooser * tc = NULL,
int nb_displayed_items = 7);
bool CheckUserInput(JButton key);
};
class ShopBooster
{
public:
ShopBooster();
string getName();
void randomize(MTGPacks * packlist);
int basePrice();
int maxInventory();
void addToDeck(MTGDeck * d, WSrcCards * srcCards);
string getSort();
#ifdef TESTSUITE
bool unitTest();
#endif
private:
void randomCustom(MTGPacks * packlist);
void randomStandard();
MTGPack * pack;
MTGSetInfo * mainSet;
MTGSetInfo * altSet;
};
class GameStateShop: public GameState, public JGuiListener
{
private:
JQuadPtr pspIcons[8];
WSrcCards * srcCards;
JTexture * altThumb[8];
TaskList * taskList;
float mElapsed;
WGuiMenu * shopMenu;
WGuiFilters * filterMenu; //Filter menu slides in sideways from right, or up from bottom.
WGuiCardImage * bigDisplay;
BoosterDisplay * boosterDisplay;
vector<MTGCardInstance*> subBooster;
MTGDeck * booster;
bool bListCards;
void beginFilters();
void deleteDisplay();
WSyncable bigSync;
SimpleMenu * menu;
PriceList * pricelist;
PlayerData * playerdata;
MTGPacks * packlist;
bool mTouched;
bool needLoad;
int mPrices[SHOP_ITEMS];
int mCounts[SHOP_ITEMS];
int mInventory[SHOP_ITEMS];
int lightAlpha;
int alphaChange;
int mBuying;
DeckDataWrapper * myCollection;
int mStage;
ShopBooster mBooster[BOOSTER_SLOTS];
void load();
void save(bool force = false);
void updateCounts();
void beginPurchase(int controlId);
void purchaseCard(int controlId);
void purchaseBooster(int controlId);
void cancelCard(int controlId);
void cancelBooster(int controlId);
int purchasePrice(int offset);
string descPurchase(int controlId, bool tiny = false);
public:
GameStateShop(GameApp* parent);
virtual ~GameStateShop();
virtual void Start();
virtual void End();
virtual void Create();
virtual void Destroy();
virtual void Update(float dt);
virtual void Render();
virtual void ButtonPressed(int controllerId, int controlId);
static float _x1[], _y1[], _x2[], _y2[], _x3[], _y3[], _x4[], _y4[];
};
#endif