Erwan
- various optimization fixes
This commit is contained in:
+1
-1
@@ -28,7 +28,7 @@
|
|||||||
|
|
||||||
#ifdef DEVHOOK
|
#ifdef DEVHOOK
|
||||||
PSP_MODULE_INFO(JGEApp_Title, 0, 1, 1);
|
PSP_MODULE_INFO(JGEApp_Title, 0, 1, 1);
|
||||||
PSP_MAIN_THREAD_ATTR(0);
|
PSP_MAIN_THREAD_ATTR(PSP_THREAD_ATTR_USER);
|
||||||
PSP_HEAP_SIZE_KB(-256);
|
PSP_HEAP_SIZE_KB(-256);
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ class ActionLayer: public GuiLayer, public JGuiListener{
|
|||||||
virtual void Update(float dt);
|
virtual void Update(float dt);
|
||||||
int unstoppableRenderInProgress();
|
int unstoppableRenderInProgress();
|
||||||
bool CheckUserInput(u32 key);
|
bool CheckUserInput(u32 key);
|
||||||
ActionLayer(){ menuObject = NULL; abilitiesMenu = NULL; stuffHappened = 0;};
|
ActionLayer();
|
||||||
~ActionLayer();
|
~ActionLayer();
|
||||||
int cancelCurrentAction();
|
int cancelCurrentAction();
|
||||||
ActionElement * isWaitingForAnswer();
|
ActionElement * isWaitingForAnswer();
|
||||||
@@ -42,9 +42,12 @@ class ActionLayer: public GuiLayer, public JGuiListener{
|
|||||||
void ButtonPressed(int controllerid, int controlid);
|
void ButtonPressed(int controllerid, int controlid);
|
||||||
void doReactTo(int menuIndex);
|
void doReactTo(int menuIndex);
|
||||||
TargetChooser * getCurrentTargetChooser();
|
TargetChooser * getCurrentTargetChooser();
|
||||||
|
void setCurrentWaitingAction(ActionElement * ae);
|
||||||
MTGAbility * getAbility(int type);
|
MTGAbility * getAbility(int type);
|
||||||
int moveToGarbage(ActionElement * e);
|
int moveToGarbage(ActionElement * e);
|
||||||
int cleanGarbage();
|
int cleanGarbage();
|
||||||
|
protected:
|
||||||
|
ActionElement * currentWaitingAction;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -579,11 +579,11 @@ public:
|
|||||||
while (s.size()){
|
while (s.size()){
|
||||||
unsigned int found = s.find(" ");
|
unsigned int found = s.find(" ");
|
||||||
if (found != string::npos){
|
if (found != string::npos){
|
||||||
int id = Subtypes::subtypesList->Add(s.substr(0,found));
|
int id = Subtypes::subtypesList->find(s.substr(0,found));
|
||||||
types.push_back(id);
|
types.push_back(id);
|
||||||
s = s.substr(found+1);
|
s = s.substr(found+1);
|
||||||
}else{
|
}else{
|
||||||
int id = Subtypes::subtypesList->Add(s);
|
int id = Subtypes::subtypesList->find(s);
|
||||||
types.push_back(id);
|
types.push_back(id);
|
||||||
s = "";
|
s = "";
|
||||||
}
|
}
|
||||||
@@ -1502,7 +1502,7 @@ class AConvertLandToCreatures:public ListMaintainerAbility{
|
|||||||
int type;
|
int type;
|
||||||
int power, toughness;
|
int power, toughness;
|
||||||
AConvertLandToCreatures(int _id, MTGCardInstance * _source, const char * _type, int _power = 1, int _toughness = 1):ListMaintainerAbility(_id, _source),power(_power),toughness(_toughness){
|
AConvertLandToCreatures(int _id, MTGCardInstance * _source, const char * _type, int _power = 1, int _toughness = 1):ListMaintainerAbility(_id, _source),power(_power),toughness(_toughness){
|
||||||
type = Subtypes::subtypesList->Add(_type);
|
type = Subtypes::subtypesList->find(_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -2054,11 +2054,11 @@ public:
|
|||||||
while (s.size()){
|
while (s.size()){
|
||||||
unsigned int found = s.find(" ");
|
unsigned int found = s.find(" ");
|
||||||
if (found != string::npos){
|
if (found != string::npos){
|
||||||
int id = Subtypes::subtypesList->Add(s.substr(0,found));
|
int id = Subtypes::subtypesList->find(s.substr(0,found));
|
||||||
types.push_back(id);
|
types.push_back(id);
|
||||||
s = s.substr(found+1);
|
s = s.substr(found+1);
|
||||||
}else{
|
}else{
|
||||||
int id = Subtypes::subtypesList->Add(s);
|
int id = Subtypes::subtypesList->find(s);
|
||||||
types.push_back(id);
|
types.push_back(id);
|
||||||
s = "";
|
s = "";
|
||||||
}
|
}
|
||||||
@@ -2243,7 +2243,7 @@ class AAnkhOfMishra: public ListMaintainerAbility{
|
|||||||
}
|
}
|
||||||
|
|
||||||
int canBeInList(MTGCardInstance * card){
|
int canBeInList(MTGCardInstance * card){
|
||||||
if (card->hasType("land") && game->isInPlay(card)) return 1;
|
if (card->hasType(Subtypes::TYPE_LAND) && game->isInPlay(card)) return 1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2541,7 +2541,7 @@ class ADingusEgg: public ListMaintainerAbility{
|
|||||||
}
|
}
|
||||||
|
|
||||||
int canBeInList(MTGCardInstance * card){
|
int canBeInList(MTGCardInstance * card){
|
||||||
if (card->hasType("land") && game->isInPlay(card)) return 1;
|
if (card->hasType(Subtypes::TYPE_LAND) && game->isInPlay(card)) return 1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2583,7 +2583,10 @@ class ADisruptingScepter:public TargetAbility{
|
|||||||
if(waitingForAnswer){
|
if(waitingForAnswer){
|
||||||
MTGCardInstance * card = ((AIPlayer *)game->opponent())->chooseCard(tc, source);
|
MTGCardInstance * card = ((AIPlayer *)game->opponent())->chooseCard(tc, source);
|
||||||
if (card) tc->toggleTarget(card);
|
if (card) tc->toggleTarget(card);
|
||||||
if (!card || tc->targetsReadyCheck() == TARGET_OK) waitingForAnswer = 0;
|
if (!card || tc->targetsReadyCheck() == TARGET_OK) {
|
||||||
|
waitingForAnswer = 0;
|
||||||
|
game->mLayers->actionLayer()->setCurrentWaitingAction(NULL);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
TargetAbility::Update(dt);
|
TargetAbility::Update(dt);
|
||||||
}else{
|
}else{
|
||||||
@@ -3138,7 +3141,7 @@ class AKudzu: public TargetAbility{
|
|||||||
int testDestroy(){
|
int testDestroy(){
|
||||||
int stillLandsInPlay = 0;
|
int stillLandsInPlay = 0;
|
||||||
for (int i = 0; i < 2; i++){
|
for (int i = 0; i < 2; i++){
|
||||||
if (game->players[i]->game->inPlay->hasType("land")) stillLandsInPlay = 1;
|
if (game->players[i]->game->inPlay->hasType("Land")) stillLandsInPlay = 1;
|
||||||
}
|
}
|
||||||
if (!stillLandsInPlay){
|
if (!stillLandsInPlay){
|
||||||
source->controller()->game->putInGraveyard(source);
|
source->controller()->game->putInGraveyard(source);
|
||||||
@@ -4051,7 +4054,7 @@ class AAngelicChorus: public ListMaintainerAbility{
|
|||||||
}
|
}
|
||||||
|
|
||||||
int canBeInList(MTGCardInstance * card){
|
int canBeInList(MTGCardInstance * card){
|
||||||
if (card->hasType("creature") && game->isInPlay(card)) return 1;
|
if (card->hasType(Subtypes::TYPE_CREATURE) && game->isInPlay(card)) return 1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -50,6 +50,10 @@ class GameApp: public JApp
|
|||||||
{
|
{
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
#ifdef DEBUG
|
||||||
|
int nbUpdates;
|
||||||
|
float totalFPS;
|
||||||
|
#endif
|
||||||
bool mShowDebugInfo;
|
bool mShowDebugInfo;
|
||||||
int mScreenShotCount;
|
int mScreenShotCount;
|
||||||
|
|
||||||
|
|||||||
@@ -21,8 +21,6 @@ class GameStateShop: public GameState, public JGuiListener
|
|||||||
ShopItems * shop;
|
ShopItems * shop;
|
||||||
JLBFont * menuFont;
|
JLBFont * menuFont;
|
||||||
JLBFont * itemFont;
|
JLBFont * itemFont;
|
||||||
JQuad * mBg;
|
|
||||||
JTexture * bgTexture;
|
|
||||||
JTexture * altThumb[8];
|
JTexture * altThumb[8];
|
||||||
JQuad * mBack;
|
JQuad * mBack;
|
||||||
SimpleMenu * menu;
|
SimpleMenu * menu;
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ class MTGCard {
|
|||||||
char image_name[MTGCARD_NAME_SIZE];
|
char image_name[MTGCARD_NAME_SIZE];
|
||||||
vector<string> ftdText;
|
vector<string> ftdText;
|
||||||
int init();
|
int init();
|
||||||
|
string lcname;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
string text;
|
string text;
|
||||||
@@ -77,6 +78,7 @@ class MTGCard {
|
|||||||
|
|
||||||
void setName(string value);
|
void setName(string value);
|
||||||
const string getName() const;
|
const string getName() const;
|
||||||
|
const string getLCName() const;
|
||||||
|
|
||||||
void addType(char * type_text);
|
void addType(char * type_text);
|
||||||
void addType(int id);
|
void addType(int id);
|
||||||
|
|||||||
@@ -4,22 +4,31 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <map>
|
#include <map>
|
||||||
using std::string;
|
#include <vector>
|
||||||
using std::map;
|
using namespace std;
|
||||||
|
|
||||||
|
|
||||||
class Subtypes{
|
class Subtypes{
|
||||||
|
public:
|
||||||
|
enum {
|
||||||
|
TYPE_CREATURE = 1,
|
||||||
|
TYPE_ENCHANTMENT = 2,
|
||||||
|
TYPE_SORCERY = 3,
|
||||||
|
TYPE_INSTANT = 4,
|
||||||
|
TYPE_LAND = 5,
|
||||||
|
TYPE_ARTIFACT = 6,
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
map<string,int> values;
|
map<string,int> values;
|
||||||
map<int,string> valuesById;
|
vector<string> valuesById;
|
||||||
int nb_items;
|
|
||||||
public:
|
public:
|
||||||
static Subtypes * subtypesList;
|
static Subtypes * subtypesList;
|
||||||
Subtypes();
|
Subtypes();
|
||||||
int Add(const char * subtype);
|
int find(const char * subtype, bool forceAdd = true);
|
||||||
int find(const char * subtype);
|
int find(string subtype, bool forceAdd = true);
|
||||||
int Add(string subtype);
|
string find(unsigned int id);
|
||||||
int find(string subtype);
|
|
||||||
string find(int id);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -41,7 +41,8 @@ public:
|
|||||||
|
|
||||||
virtual ~WCachedResource() {};
|
virtual ~WCachedResource() {};
|
||||||
|
|
||||||
virtual void Refresh(string filename)=0; //Basically calls Attempt(filename) and remaps in situ.
|
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().
|
virtual bool Attempt(string filename, int submode, int & error)=0; //Returns true if we've loaded our data and isGood().
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -65,7 +66,7 @@ public:
|
|||||||
WCachedTexture();
|
WCachedTexture();
|
||||||
~WCachedTexture();
|
~WCachedTexture();
|
||||||
|
|
||||||
void Refresh(string filename);
|
void Refresh();
|
||||||
unsigned long size();
|
unsigned long size();
|
||||||
bool isGood();
|
bool isGood();
|
||||||
bool isLocked();
|
bool isLocked();
|
||||||
@@ -98,7 +99,7 @@ public:
|
|||||||
|
|
||||||
void Nullify();
|
void Nullify();
|
||||||
void Trash();
|
void Trash();
|
||||||
void Refresh(string filename);
|
void Refresh();
|
||||||
unsigned long size();
|
unsigned long size();
|
||||||
|
|
||||||
bool isGood();
|
bool isGood();
|
||||||
@@ -121,7 +122,7 @@ public:
|
|||||||
bool compare(JSample * s) {return (s == sample);};
|
bool compare(JSample * s) {return (s == sample);};
|
||||||
unsigned long size();
|
unsigned long size();
|
||||||
bool isGood();
|
bool isGood();
|
||||||
void Refresh(string filename);
|
void Refresh();
|
||||||
bool Attempt(string filename, int submode, int & error);
|
bool Attempt(string filename, int submode, int & error);
|
||||||
|
|
||||||
JSample * Actual(); //Return this sample.
|
JSample * Actual(); //Return this sample.
|
||||||
|
|||||||
@@ -13,6 +13,10 @@
|
|||||||
#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 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 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 1000000
|
#define MIN_LINEAR_RAM 1000000
|
||||||
|
|
||||||
|
#define THUMBNAILS_OFFSET 100000000
|
||||||
|
#define OTHERS_OFFSET 2000000000
|
||||||
|
|
||||||
//Hard Limits.
|
//Hard Limits.
|
||||||
#define MAX_CACHE_OBJECTS 300
|
#define MAX_CACHE_OBJECTS 300
|
||||||
#define MAX_CACHE_ATTEMPTS 10
|
#define MAX_CACHE_ATTEMPTS 10
|
||||||
@@ -70,9 +74,9 @@ public:
|
|||||||
WCache();
|
WCache();
|
||||||
~WCache();
|
~WCache();
|
||||||
|
|
||||||
cacheItem* Retrieve(string filename, int style = RETRIEVE_NORMAL, int submode = CACHE_NORMAL); //Primary interface function.
|
cacheItem* Retrieve(int id, 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 Release(cacheActual* actual); //Releases an item, and deletes it if unlocked.
|
||||||
bool RemoveMiss(string id=""); //Removes a cache miss.
|
bool RemoveMiss(int id=0); //Removes a cache miss.
|
||||||
bool RemoveOldest(); //Remove oldest unlocked item.
|
bool RemoveOldest(); //Remove oldest unlocked item.
|
||||||
bool Cleanup(); //Repeats RemoveOldest() until cache fits in size limits
|
bool Cleanup(); //Repeats RemoveOldest() until cache fits in size limits
|
||||||
void Clear(); //Removes everything cached. Not lock safe, does not remove managed items.
|
void Clear(); //Removes everything cached. Not lock safe, does not remove managed items.
|
||||||
@@ -86,14 +90,14 @@ protected:
|
|||||||
bool RemoveItem(cacheItem * item, bool force = true); //Removes an item, deleting it. if(force), ignores locks / permanent
|
bool RemoveItem(cacheItem * item, bool force = true); //Removes an item, deleting it. if(force), ignores locks / permanent
|
||||||
bool UnlinkCache(cacheItem * item); //Removes an item from our cache, does not delete it. Use with care.
|
bool UnlinkCache(cacheItem * item); //Removes an item from our cache, does not delete it. Use with care.
|
||||||
bool Delete(cacheItem * item); //SAFE_DELETE and garbage collect. If maxCached == 0, nullify first. (This means you have to free that cacheActual later!)
|
bool Delete(cacheItem * item); //SAFE_DELETE and garbage collect. If maxCached == 0, nullify first. (This means you have to free that cacheActual later!)
|
||||||
cacheItem* Get(string id, int style = RETRIEVE_NORMAL, int submode = CACHE_NORMAL); //Subordinate to Retrieve.
|
cacheItem* Get(int id, string filename, int style = RETRIEVE_NORMAL, int submode = CACHE_NORMAL); //Subordinate to Retrieve.
|
||||||
cacheItem* AttemptNew(string filename, int submode); //Attempts a new cache item, progressively clearing cache if it fails.
|
cacheItem* AttemptNew(string filename, int submode); //Attempts a new cache item, progressively clearing cache if it fails.
|
||||||
|
|
||||||
string makeID(string filename, int submode); //Makes an ID appropriate to the submode.
|
int makeID(int id, string filename, int submode); //Makes an ID appropriate to the submode.
|
||||||
string makeFilename(string id, int submode); //Makes a filename from an ID.
|
|
||||||
|
|
||||||
map<string,cacheItem*> cache;
|
map<string,int> ids;
|
||||||
map<string,cacheItem*> managed; //Cache can be arbitrarily large, so managed items are seperate.
|
map<int,cacheItem*> cache;
|
||||||
|
map<int,cacheItem*> managed; //Cache can be arbitrarily large, so managed items are seperate.
|
||||||
unsigned long totalSize;
|
unsigned long totalSize;
|
||||||
unsigned long cacheSize;
|
unsigned long cacheSize;
|
||||||
|
|
||||||
@@ -104,8 +108,10 @@ protected:
|
|||||||
unsigned int cacheItems;
|
unsigned int cacheItems;
|
||||||
int mError;
|
int mError;
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
struct WManagedQuad {
|
struct WManagedQuad {
|
||||||
WCachedTexture * texture;
|
WCachedTexture * texture;
|
||||||
string resname;
|
string resname;
|
||||||
@@ -121,7 +127,7 @@ public:
|
|||||||
JQuad * RetrieveCard(MTGCard * card, int style = RETRIEVE_NORMAL,int submode = CACHE_NORMAL);
|
JQuad * RetrieveCard(MTGCard * card, int style = RETRIEVE_NORMAL,int submode = CACHE_NORMAL);
|
||||||
JSample * RetrieveSample(string filename, int style = RETRIEVE_NORMAL, int submode = CACHE_NORMAL);
|
JSample * RetrieveSample(string filename, int style = RETRIEVE_NORMAL, int submode = CACHE_NORMAL);
|
||||||
JTexture * RetrieveTexture(string filename, int style = RETRIEVE_NORMAL, int submode = CACHE_NORMAL);
|
JTexture * RetrieveTexture(string filename, int style = RETRIEVE_NORMAL, int submode = CACHE_NORMAL);
|
||||||
JQuad * RetrieveQuad(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);
|
JQuad * RetrieveQuad(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(string filename);
|
JQuad * RetrieveTempQuad(string filename);
|
||||||
hgeParticleSystemInfo * RetrievePSI(string filename, JQuad * texture, int style = RETRIEVE_NORMAL, int submode = CACHE_NORMAL);
|
hgeParticleSystemInfo * RetrievePSI(string filename, JQuad * texture, int style = RETRIEVE_NORMAL, int submode = CACHE_NORMAL);
|
||||||
int RetrieveError();
|
int RetrieveError();
|
||||||
|
|||||||
@@ -599,7 +599,7 @@ MTGCardInstance * AIPlayerBaka::FindCardToPlay(ManaCost * pMana, const char * ty
|
|||||||
cd.setType(type);
|
cd.setType(type);
|
||||||
card = NULL;
|
card = NULL;
|
||||||
while((card = cd.nextmatch(game->hand, card))){
|
while((card = cd.nextmatch(game->hand, card))){
|
||||||
if (card->hasType("land") && !this->canPutLandsIntoPlay) continue;
|
if (card->hasType(Subtypes::TYPE_LAND) && !this->canPutLandsIntoPlay) continue;
|
||||||
if (card->has(Constants::LEGENDARY) && game->inPlay->findByName(card->name)) continue;
|
if (card->has(Constants::LEGENDARY) && game->inPlay->findByName(card->name)) continue;
|
||||||
int currentCost = card->getManaCost()->getConvertedCost();
|
int currentCost = card->getManaCost()->getConvertedCost();
|
||||||
int hasX = card->getManaCost()->hasX();
|
int hasX = card->getManaCost()->hasX();
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
#include "../include/GameObserver.h"
|
#include "../include/GameObserver.h"
|
||||||
#include "../include/Targetable.h"
|
#include "../include/Targetable.h"
|
||||||
#include "../include/WEvent.h"
|
#include "../include/WEvent.h"
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
MTGAbility* ActionLayer::getAbility(int type){
|
MTGAbility* ActionLayer::getAbility(int type){
|
||||||
for (int i = 1; i < mCount; i++){
|
for (int i = 1; i < mCount; i++){
|
||||||
@@ -17,6 +18,7 @@ MTGAbility* ActionLayer::getAbility(int type){
|
|||||||
int ActionLayer::moveToGarbage(ActionElement * e){
|
int ActionLayer::moveToGarbage(ActionElement * e){
|
||||||
int i = getIndexOf(e);
|
int i = getIndexOf(e);
|
||||||
if (i != -1){
|
if (i != -1){
|
||||||
|
if (isWaitingForAnswer() == e) setCurrentWaitingAction(NULL);
|
||||||
e->destroy();
|
e->destroy();
|
||||||
mObjects.erase(mObjects.begin()+i);
|
mObjects.erase(mObjects.begin()+i);
|
||||||
mCount--;
|
mCount--;
|
||||||
@@ -125,13 +127,19 @@ void ActionLayer::Render (){
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ActionLayer::setCurrentWaitingAction(ActionElement * ae){
|
||||||
|
assert(!ae || !currentWaitingAction);
|
||||||
|
currentWaitingAction = ae;
|
||||||
|
}
|
||||||
|
|
||||||
TargetChooser * ActionLayer::getCurrentTargetChooser(){
|
TargetChooser * ActionLayer::getCurrentTargetChooser(){
|
||||||
for (int i=0;i<mCount;i++){
|
/* for (int i=0;i<mCount;i++){
|
||||||
ActionElement * currentAction = (ActionElement *)mObjects[i];
|
ActionElement * currentAction = (ActionElement *)mObjects[i];
|
||||||
if(currentAction->waitingForAnswer) return currentAction->tc;
|
if(currentAction->waitingForAnswer) return currentAction->tc;
|
||||||
}
|
}
|
||||||
|
return NULL;*/
|
||||||
|
if (currentWaitingAction && currentWaitingAction->waitingForAnswer)
|
||||||
|
return currentWaitingAction->tc;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,14 +147,13 @@ int ActionLayer::cancelCurrentAction(){
|
|||||||
ActionElement * ae = isWaitingForAnswer();
|
ActionElement * ae = isWaitingForAnswer();
|
||||||
if (!ae) return 0;
|
if (!ae) return 0;
|
||||||
ae->waitingForAnswer = 0; //TODO MOVE THIS IS ActionElement
|
ae->waitingForAnswer = 0; //TODO MOVE THIS IS ActionElement
|
||||||
|
setCurrentWaitingAction(NULL);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ActionElement * ActionLayer::isWaitingForAnswer(){
|
ActionElement * ActionLayer::isWaitingForAnswer(){
|
||||||
for (int i=0;i<mCount;i++){
|
if (currentWaitingAction && currentWaitingAction->waitingForAnswer)
|
||||||
ActionElement * currentAction = (ActionElement *)mObjects[i];
|
return currentWaitingAction;
|
||||||
if(currentAction->waitingForAnswer) return currentAction;
|
|
||||||
}
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -182,12 +189,8 @@ int ActionLayer::isReactingToTargetClick(Targetable * card){
|
|||||||
int ActionLayer::reactToTargetClick(Targetable * card){
|
int ActionLayer::reactToTargetClick(Targetable * card){
|
||||||
int result = 0;
|
int result = 0;
|
||||||
|
|
||||||
for (int i=0;i<mCount;i++){
|
ActionElement * ae = isWaitingForAnswer();
|
||||||
ActionElement * currentAction = (ActionElement *)mObjects[i];
|
if (ae) return reactToTargetClick(ae,card);
|
||||||
if(currentAction->waitingForAnswer){
|
|
||||||
return reactToTargetClick(currentAction,card);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i=0;i<mCount;i++){
|
for (int i=0;i<mCount;i++){
|
||||||
ActionElement * currentAction = (ActionElement *)mObjects[i];
|
ActionElement * currentAction = (ActionElement *)mObjects[i];
|
||||||
@@ -202,7 +205,6 @@ int ActionLayer::isReactingToClick(MTGCardInstance * card){
|
|||||||
|
|
||||||
if (isWaitingForAnswer()) return -1;
|
if (isWaitingForAnswer()) return -1;
|
||||||
|
|
||||||
|
|
||||||
for (int i=0;i<mCount;i++){
|
for (int i=0;i<mCount;i++){
|
||||||
ActionElement * currentAction = (ActionElement *)mObjects[i];
|
ActionElement * currentAction = (ActionElement *)mObjects[i];
|
||||||
result += currentAction->isReactingToClick(card);
|
result += currentAction->isReactingToClick(card);
|
||||||
@@ -214,12 +216,8 @@ int ActionLayer::isReactingToClick(MTGCardInstance * card){
|
|||||||
int ActionLayer::reactToClick(MTGCardInstance * card){
|
int ActionLayer::reactToClick(MTGCardInstance * card){
|
||||||
int result = 0;
|
int result = 0;
|
||||||
|
|
||||||
for (int i=0;i<mCount;i++){
|
ActionElement * ae = isWaitingForAnswer();
|
||||||
ActionElement * currentAction = (ActionElement *)mObjects[i];
|
if (ae) return reactToClick(ae,card);
|
||||||
if(currentAction->waitingForAnswer){
|
|
||||||
return reactToClick(currentAction,card);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i=0;i<mCount;i++){
|
for (int i=0;i<mCount;i++){
|
||||||
ActionElement * currentAction = (ActionElement *)mObjects[i];
|
ActionElement * currentAction = (ActionElement *)mObjects[i];
|
||||||
@@ -273,6 +271,13 @@ void ActionLayer::ButtonPressed(int controllerid, int controlid){
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ActionLayer::ActionLayer(){
|
||||||
|
menuObject = NULL;
|
||||||
|
abilitiesMenu = NULL;
|
||||||
|
stuffHappened = 0;
|
||||||
|
currentWaitingAction = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
ActionLayer::~ActionLayer(){
|
ActionLayer::~ActionLayer(){
|
||||||
SAFE_DELETE(abilitiesMenu);
|
SAFE_DELETE(abilitiesMenu);
|
||||||
cleanGarbage();
|
cleanGarbage();
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ void CardDescriptor::unsecureSetTapped(int i){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CardDescriptor::setNegativeSubtype( string value){
|
void CardDescriptor::setNegativeSubtype( string value){
|
||||||
int id = Subtypes::subtypesList->Add(value);
|
int id = Subtypes::subtypesList->find(value);
|
||||||
addType(-id);
|
addType(-id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -30,12 +30,12 @@ MTGCardInstance * CardDescriptor::match_or(MTGCardInstance * card){
|
|||||||
found = 0;
|
found = 0;
|
||||||
if (types[i] >= 0){
|
if (types[i] >= 0){
|
||||||
|
|
||||||
if (card->hasSubtype(types[i]) || (Subtypes::subtypesList->find(card->name) == types[i])){
|
if (card->hasSubtype(types[i]) || (Subtypes::subtypesList->find(card->getLCName(),false) == types[i])){
|
||||||
found = 1;
|
found = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
if (!card->hasSubtype(-types[i]) && (Subtypes::subtypesList->find(card->name) != -types[i])){
|
if (!card->hasSubtype(-types[i]) && (Subtypes::subtypesList->find(card->getLCName(), false) != -types[i])){
|
||||||
found = 1;
|
found = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -67,11 +67,11 @@ MTGCardInstance * CardDescriptor::match_and(MTGCardInstance * card){
|
|||||||
MTGCardInstance * match = card;
|
MTGCardInstance * match = card;
|
||||||
for (int i = 0; i< nb_types; i++){
|
for (int i = 0; i< nb_types; i++){
|
||||||
if (types[i] >= 0){
|
if (types[i] >= 0){
|
||||||
if (!card->hasSubtype(types[i]) && !(Subtypes::subtypesList->find(card->name) == types[i])){
|
if (!card->hasSubtype(types[i]) && !(Subtypes::subtypesList->find(card->getLCName(),false) == types[i])){
|
||||||
match = NULL;
|
match = NULL;
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
if(card->hasSubtype(-types[i]) || (Subtypes::subtypesList->find(card->name) == -types[i])){
|
if(card->hasSubtype(-types[i]) || (Subtypes::subtypesList->find(card->getLCName(),false) == -types[i])){
|
||||||
match = NULL;
|
match = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,11 @@ GameState::GameState(GameApp* parent): mParent(parent)
|
|||||||
|
|
||||||
GameApp::GameApp(): JApp()
|
GameApp::GameApp(): JApp()
|
||||||
{
|
{
|
||||||
|
#ifdef DEBUG
|
||||||
|
nbUpdates = 0;
|
||||||
|
totalFPS = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
mScreenShotCount = 0;
|
mScreenShotCount = 0;
|
||||||
|
|
||||||
for (int i=0; i < MAX_STATE ; i++)
|
for (int i=0; i < MAX_STATE ; i++)
|
||||||
@@ -286,6 +291,20 @@ void GameApp::Render()
|
|||||||
resources.DebugRender();
|
resources.DebugRender();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
JGE* mEngine = JGE::GetInstance();
|
||||||
|
float fps = mEngine->GetFPS();
|
||||||
|
totalFPS += fps;
|
||||||
|
nbUpdates+=1;
|
||||||
|
JLBFont * mFont= resources.GetJLBFont("simon");
|
||||||
|
char buf[512];
|
||||||
|
sprintf(buf, "avg:%f - %f fps",totalFPS/nbUpdates, fps);
|
||||||
|
if (mFont) {
|
||||||
|
mFont->SetColor(ARGB(255,255,255,255));
|
||||||
|
mFont->DrawString(buf,1,1);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameApp::SetNextState(int state)
|
void GameApp::SetNextState(int state)
|
||||||
|
|||||||
@@ -30,8 +30,6 @@ void GameStateShop::Start()
|
|||||||
|
|
||||||
mStage = STAGE_SHOP_SHOP;
|
mStage = STAGE_SHOP_SHOP;
|
||||||
|
|
||||||
bgTexture = resources.RetrieveTexture("shop.jpg",RETRIEVE_LOCK);
|
|
||||||
|
|
||||||
//alternateRender doesn't lock, so lock our thumbnails for hgeDistort.
|
//alternateRender doesn't lock, so lock our thumbnails for hgeDistort.
|
||||||
altThumb[0] = resources.RetrieveTexture("artifact_thumb.jpg", RETRIEVE_LOCK);
|
altThumb[0] = resources.RetrieveTexture("artifact_thumb.jpg", RETRIEVE_LOCK);
|
||||||
altThumb[1] = resources.RetrieveTexture("green_thumb.jpg", RETRIEVE_LOCK);
|
altThumb[1] = resources.RetrieveTexture("green_thumb.jpg", RETRIEVE_LOCK);
|
||||||
@@ -42,7 +40,7 @@ void GameStateShop::Start()
|
|||||||
altThumb[6] = resources.RetrieveTexture("land_thumb.jpg", RETRIEVE_LOCK);
|
altThumb[6] = resources.RetrieveTexture("land_thumb.jpg", RETRIEVE_LOCK);
|
||||||
altThumb[7] = resources.RetrieveTexture("gold_thumb.jpg", RETRIEVE_LOCK);
|
altThumb[7] = resources.RetrieveTexture("gold_thumb.jpg", RETRIEVE_LOCK);
|
||||||
|
|
||||||
mBg = resources.RetrieveQuad("shop.jpg");
|
|
||||||
mBack = resources.GetQuad("back");
|
mBack = resources.GetQuad("back");
|
||||||
|
|
||||||
menuFont = resources.GetJLBFont(Constants::MENU_FONT);
|
menuFont = resources.GetJLBFont(Constants::MENU_FONT);
|
||||||
@@ -125,7 +123,6 @@ void GameStateShop::load(){
|
|||||||
void GameStateShop::End()
|
void GameStateShop::End()
|
||||||
{
|
{
|
||||||
JRenderer::GetInstance()->EnableVSync(false);
|
JRenderer::GetInstance()->EnableVSync(false);
|
||||||
resources.Release(bgTexture);
|
|
||||||
|
|
||||||
//Release alternate thumbnails.
|
//Release alternate thumbnails.
|
||||||
for(int i=0;i<8;i++){
|
for(int i=0;i<8;i++){
|
||||||
@@ -169,6 +166,7 @@ void GameStateShop::Render()
|
|||||||
//Erase
|
//Erase
|
||||||
JRenderer * r = JRenderer::GetInstance();
|
JRenderer * r = JRenderer::GetInstance();
|
||||||
r->ClearScreen(ARGB(0,0,0,0));
|
r->ClearScreen(ARGB(0,0,0,0));
|
||||||
|
JQuad * mBg = resources.RetrieveQuad("shop.jpg");
|
||||||
if (mBg) r->RenderQuad(mBg,0,0);
|
if (mBg) r->RenderQuad(mBg,0,0);
|
||||||
|
|
||||||
if (shop)
|
if (shop)
|
||||||
|
|||||||
@@ -32,9 +32,11 @@ GuiFrame::GuiFrame()
|
|||||||
|
|
||||||
step = 0.0;
|
step = 0.0;
|
||||||
|
|
||||||
|
if (gold2){
|
||||||
gold2->SetColor(ARGB(127, 255, 255, 255));
|
gold2->SetColor(ARGB(127, 255, 255, 255));
|
||||||
gold2->SetHFlip(true);
|
gold2->SetHFlip(true);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
GuiFrame::~GuiFrame()
|
GuiFrame::~GuiFrame()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -64,7 +64,6 @@ void GuiPlay::VertStack::Enstack(CardView* card)
|
|||||||
card->x = x + baseX; card->y = y + baseY;
|
card->x = x + baseX; card->y = y + baseY;
|
||||||
y += 12;
|
y += 12;
|
||||||
if (++count == total-1 && y == 12) y += 12;
|
if (++count == total-1 && y == 12) y += 12;
|
||||||
cerr << card->card->name << " " << card->x << "x" << card->y << " : " << nextX() << endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiPlay::VertStack::Render(CardView* card, iterator begin, iterator end)
|
void GuiPlay::VertStack::Render(CardView* card, iterator begin, iterator end)
|
||||||
|
|||||||
@@ -186,7 +186,6 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG
|
|||||||
MTGCardInstance * target = card->target;
|
MTGCardInstance * target = card->target;
|
||||||
if (!target) target = card;
|
if (!target) target = card;
|
||||||
|
|
||||||
|
|
||||||
TriggeredAbility * trigger = NULL;
|
TriggeredAbility * trigger = NULL;
|
||||||
trigger = parseTrigger(s,id,spell,card,target);
|
trigger = parseTrigger(s,id,spell,card,target);
|
||||||
//Dirty way to remove the trigger text (could get in the way)
|
//Dirty way to remove the trigger text (could get in the way)
|
||||||
@@ -1180,7 +1179,7 @@ void AbilityFactory::addAbilities(int _id, Spell * spell){
|
|||||||
MTGInPlay * inplay = player->game->inPlay;
|
MTGInPlay * inplay = player->game->inPlay;
|
||||||
for (int i = 0; i < inplay->nb_cards; i++){
|
for (int i = 0; i < inplay->nb_cards; i++){
|
||||||
MTGCardInstance * current = inplay->cards[i];
|
MTGCardInstance * current = inplay->cards[i];
|
||||||
if (current->hasType("land")) current->tap();
|
if (current->hasType(Subtypes::TYPE_LAND)) current->tap();
|
||||||
}
|
}
|
||||||
player->getManaPool()->init();
|
player->getManaPool()->init();
|
||||||
}
|
}
|
||||||
@@ -1560,7 +1559,7 @@ void AbilityFactory::addAbilities(int _id, Spell * spell){
|
|||||||
Damageable * target = spell->getNextDamageableTarget();
|
Damageable * target = spell->getNextDamageableTarget();
|
||||||
for (int j = card->controller()->game->inPlay->nb_cards-1; j >=0 ; --j){
|
for (int j = card->controller()->game->inPlay->nb_cards-1; j >=0 ; --j){
|
||||||
MTGCardInstance * current = card->controller()->game->inPlay->cards[j];
|
MTGCardInstance * current = card->controller()->game->inPlay->cards[j];
|
||||||
if (current->hasType("Creature")){
|
if (current->hasType(Subtypes::TYPE_CREATURE)){
|
||||||
card->controller()->game->putInGraveyard(current);
|
card->controller()->game->putInGraveyard(current);
|
||||||
damage+= current->power;
|
damage+= current->power;
|
||||||
}
|
}
|
||||||
@@ -1822,6 +1821,7 @@ void TargetAbility::Update(float dt){
|
|||||||
JGE * mEngine = JGE::GetInstance();
|
JGE * mEngine = JGE::GetInstance();
|
||||||
if (waitingForAnswer){
|
if (waitingForAnswer){
|
||||||
if(mEngine->GetButtonClick(PSP_CTRL_CROSS)){
|
if(mEngine->GetButtonClick(PSP_CTRL_CROSS)){
|
||||||
|
game->mLayers->actionLayer()->setCurrentWaitingAction(NULL);
|
||||||
waitingForAnswer = 0;
|
waitingForAnswer = 0;
|
||||||
}else if(tc->targetsReadyCheck() == TARGET_OK_FULL){
|
}else if(tc->targetsReadyCheck() == TARGET_OK_FULL){
|
||||||
//waitingForAnswer = 0;
|
//waitingForAnswer = 0;
|
||||||
@@ -1835,6 +1835,7 @@ int TargetAbility::reactToTargetClick(Targetable * object){
|
|||||||
if (waitingForAnswer){
|
if (waitingForAnswer){
|
||||||
if (tc->toggleTarget(object) == TARGET_OK_FULL){
|
if (tc->toggleTarget(object) == TARGET_OK_FULL){
|
||||||
waitingForAnswer = 0;
|
waitingForAnswer = 0;
|
||||||
|
game->mLayers->actionLayer()->setCurrentWaitingAction(NULL);
|
||||||
return ActivatedAbility::reactToClick(source);
|
return ActivatedAbility::reactToClick(source);
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
@@ -1847,18 +1848,23 @@ int TargetAbility::reactToClick(MTGCardInstance * card){
|
|||||||
if (!waitingForAnswer) {
|
if (!waitingForAnswer) {
|
||||||
if (isReactingToClick(card)){
|
if (isReactingToClick(card)){
|
||||||
waitingForAnswer = 1;
|
waitingForAnswer = 1;
|
||||||
|
game->mLayers->actionLayer()->setCurrentWaitingAction(this);
|
||||||
tc->initTargets();
|
tc->initTargets();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
if (card == source && (tc->targetsReadyCheck() == TARGET_OK || tc->targetsReadyCheck() == TARGET_OK_FULL)){
|
if (card == source && (tc->targetsReadyCheck() == TARGET_OK || tc->targetsReadyCheck() == TARGET_OK_FULL)){
|
||||||
waitingForAnswer = 0;
|
waitingForAnswer = 0;
|
||||||
|
game->mLayers->actionLayer()->setCurrentWaitingAction(NULL);
|
||||||
return ActivatedAbility::reactToClick(source);
|
return ActivatedAbility::reactToClick(source);
|
||||||
}else{
|
}else{
|
||||||
if (tc->toggleTarget(card) == TARGET_OK_FULL){
|
if (tc->toggleTarget(card) == TARGET_OK_FULL){
|
||||||
|
|
||||||
int result = ActivatedAbility::reactToClick(source);
|
int result = ActivatedAbility::reactToClick(source);
|
||||||
if (result) waitingForAnswer = 0;
|
if (result) {
|
||||||
|
waitingForAnswer = 0;
|
||||||
|
game->mLayers->actionLayer()->setCurrentWaitingAction(NULL);
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
@@ -2198,7 +2204,7 @@ AManaProducer::AManaProducer(int id, MTGCardInstance * card, ManaCost * _output,
|
|||||||
int AManaProducer::isReactingToClick(MTGCardInstance * _card, ManaCost * mana){
|
int AManaProducer::isReactingToClick(MTGCardInstance * _card, ManaCost * mana){
|
||||||
int result = 0;
|
int result = 0;
|
||||||
if (!mana) mana = game->currentlyActing()->getManaPool();
|
if (!mana) mana = game->currentlyActing()->getManaPool();
|
||||||
if (_card == source && (!tap || !source->isTapped()) && game->currentlyActing()->game->inPlay->hasCard(source) && (source->hasType("land") || !tap || !source->hasSummoningSickness()) ){
|
if (_card == source && (!tap || !source->isTapped()) && game->currentlyActing()->game->inPlay->hasCard(source) && (source->hasType(Subtypes::TYPE_LAND) || !tap || !source->hasSummoningSickness()) ){
|
||||||
if (!cost || mana->canAfford(cost)) result = 1;
|
if (!cost || mana->canAfford(cost)) result = 1;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ MTGCard::MTGCard(MTGCard * source){
|
|||||||
manaCost.copy(source->getManaCost());
|
manaCost.copy(source->getManaCost());
|
||||||
|
|
||||||
text = source->text;
|
text = source->text;
|
||||||
name = source->name;
|
setName(source->name);
|
||||||
strcpy(image_name, source->image_name);
|
strcpy(image_name, source->image_name);
|
||||||
|
|
||||||
rarity = source->rarity;
|
rarity = source->rarity;
|
||||||
@@ -120,10 +120,10 @@ const vector<string>& MTGCard::formattedText()
|
|||||||
|
|
||||||
|
|
||||||
bool MTGCard::isCreature(){
|
bool MTGCard::isCreature(){
|
||||||
return hasSubtype("creature");
|
return hasSubtype(Subtypes::TYPE_CREATURE);
|
||||||
}
|
}
|
||||||
bool MTGCard::isLand(){
|
bool MTGCard::isLand(){
|
||||||
return hasSubtype("land");
|
return hasSubtype(Subtypes::TYPE_LAND);
|
||||||
}
|
}
|
||||||
bool MTGCard::isSpell(){
|
bool MTGCard::isSpell(){
|
||||||
return (!isCreature() && !isLand());
|
return (!isCreature() && !isLand());
|
||||||
@@ -217,7 +217,7 @@ void MTGCard::addType(char * _type_text){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MTGCard::setSubtype( string value){
|
void MTGCard::setSubtype( string value){
|
||||||
int id = Subtypes::subtypesList->Add(value);
|
int id = Subtypes::subtypesList->find(value);
|
||||||
addType(id);
|
addType(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -232,7 +232,7 @@ void MTGCard::addType(int id){
|
|||||||
//If removeAll is true, removes all occurences of this type, otherwise only removes the first occurence
|
//If removeAll is true, removes all occurences of this type, otherwise only removes the first occurence
|
||||||
int MTGCard::removeType(string value, int removeAll){
|
int MTGCard::removeType(string value, int removeAll){
|
||||||
|
|
||||||
int id = Subtypes::subtypesList->Add(value);
|
int id = Subtypes::subtypesList->find(value);
|
||||||
return removeType(id, removeAll);
|
return removeType(id, removeAll);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -271,15 +271,22 @@ void MTGCard::addMagicText(string value){
|
|||||||
|
|
||||||
void MTGCard::setName( string value){
|
void MTGCard::setName( string value){
|
||||||
name = value;
|
name = value;
|
||||||
|
lcname = value;
|
||||||
|
std::transform( lcname.begin(), lcname.end(),lcname.begin(),::tolower );
|
||||||
//This is a bug fix for plague rats and the "foreach ability"
|
//This is a bug fix for plague rats and the "foreach ability"
|
||||||
//Right now we add names as types, so that they get recognized
|
//Right now we add names as types, so that they get recognized
|
||||||
if (value.at(value.length()-1) == 's') Subtypes::subtypesList->Add(value);
|
if (lcname.at(value.length()-1) == 's') Subtypes::subtypesList->find(lcname);
|
||||||
}
|
}
|
||||||
|
|
||||||
const string MTGCard::getName() const{
|
const string MTGCard::getName() const{
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const string MTGCard::getLCName() const{
|
||||||
|
return lcname;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ManaCost* MTGCard::getManaCost(){
|
ManaCost* MTGCard::getManaCost(){
|
||||||
return &manaCost;
|
return &manaCost;
|
||||||
@@ -299,18 +306,18 @@ bool MTGCard::hasSubtype(int _subtype){
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool MTGCard::hasType(const char * _type){
|
bool MTGCard::hasType(const char * _type){
|
||||||
int id = Subtypes::subtypesList->Add(_type);
|
int id = Subtypes::subtypesList->find(_type);
|
||||||
return hasType(id);
|
return hasType(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool MTGCard::hasSubtype(const char * _subtype){
|
bool MTGCard::hasSubtype(const char * _subtype){
|
||||||
int id = Subtypes::subtypesList->Add(_subtype);
|
int id = Subtypes::subtypesList->find(_subtype);
|
||||||
return hasType(id);
|
return hasType(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MTGCard::hasSubtype(string _subtype){
|
bool MTGCard::hasSubtype(string _subtype){
|
||||||
int id = Subtypes::subtypesList->Add(_subtype);
|
int id = Subtypes::subtypesList->find(_subtype);
|
||||||
return hasType(id);
|
return hasType(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ void MTGCardInstance::copy(MTGCardInstance * card){
|
|||||||
manaCost.copy(source->getManaCost());
|
manaCost.copy(source->getManaCost());
|
||||||
|
|
||||||
text = source->text;
|
text = source->text;
|
||||||
name = source->name;
|
setName(source->name);
|
||||||
|
|
||||||
power = source->power;
|
power = source->power;
|
||||||
toughness = source->toughness;
|
toughness = source->toughness;
|
||||||
@@ -130,11 +130,11 @@ void MTGCardInstance::setType(const char * type_text){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MTGCardInstance::setSubtype(string value){
|
void MTGCardInstance::setSubtype(string value){
|
||||||
int id = Subtypes::subtypesList->Add(value);
|
int id = Subtypes::subtypesList->find(value);
|
||||||
addType(id);
|
addType(id);
|
||||||
}
|
}
|
||||||
int MTGCardInstance::removeType(string value,int removeAll){
|
int MTGCardInstance::removeType(string value,int removeAll){
|
||||||
int id = Subtypes::subtypesList->Add(value);
|
int id = Subtypes::subtypesList->find(value);
|
||||||
return removeType(id,removeAll);
|
return removeType(id,removeAll);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,42 +6,34 @@
|
|||||||
Subtypes * Subtypes::subtypesList = NEW Subtypes();
|
Subtypes * Subtypes::subtypesList = NEW Subtypes();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Subtypes::Subtypes(){
|
Subtypes::Subtypes(){
|
||||||
nb_items = 100;
|
//Add the more common types, so that they can be accessed through ints
|
||||||
|
//these should be added in the same order as the enum defined in subtypes.h!!!
|
||||||
|
find("Creature");
|
||||||
|
find("Enchantment");
|
||||||
|
find("Sorcery");
|
||||||
|
find("Instant");
|
||||||
|
find("Land");
|
||||||
|
find("Artifact");
|
||||||
}
|
}
|
||||||
|
|
||||||
int Subtypes::Add(string value){
|
int Subtypes::find(string value, bool forceAdd){
|
||||||
int result = find(value);
|
if (value[0]>=97 && value[0]<=122) value[0]-=32; //Poor man's camelcase. We assume strings we get are either Camelcased or lowercase
|
||||||
if (result) return result;
|
|
||||||
std::transform( value.begin(), value.end(), value.begin(), ::tolower );
|
|
||||||
nb_items++;
|
|
||||||
values[value] = nb_items;
|
|
||||||
valuesById[nb_items] = value;
|
|
||||||
return nb_items;
|
|
||||||
}
|
|
||||||
|
|
||||||
int Subtypes::Add(const char * subtype){
|
|
||||||
string value = subtype;
|
|
||||||
return Add(value);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
int Subtypes::find(string value){
|
|
||||||
std::transform( value.begin(), value.end(), value.begin(), ::tolower );
|
|
||||||
map<string,int>::iterator it = values.find(value);
|
map<string,int>::iterator it = values.find(value);
|
||||||
if (it != values.end()) return it->second;
|
if (it != values.end()) return it->second;
|
||||||
return 0;
|
if (!forceAdd) return 0;
|
||||||
|
int id = (int)(valuesById.size() + 1);
|
||||||
|
values[value] = id;
|
||||||
|
valuesById.push_back(value);
|
||||||
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Subtypes::find(const char * subtype){
|
int Subtypes::find(const char * subtype, bool forceAdd){
|
||||||
string value = subtype;
|
string value = subtype;
|
||||||
return (find(value));
|
return (find(value));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
string Subtypes::find(int id){
|
string Subtypes::find(unsigned int id){
|
||||||
map<int,string>::iterator it=valuesById.find(id);;
|
if (valuesById.size() < id || !id) return "";
|
||||||
if (it != valuesById.end()) return it->second;
|
return valuesById[id - 1];
|
||||||
return "";
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -176,7 +176,7 @@ TargetChooser * TargetChooserFactory::createTargetChooser(string s, MTGCardInsta
|
|||||||
typeName = typeName.substr(0,found);
|
typeName = typeName.substr(0,found);
|
||||||
}
|
}
|
||||||
//X targets allowed ?
|
//X targets allowed ?
|
||||||
if (typeName.at(typeName.length()-1) == 's' && !Subtypes::subtypesList->find(typeName) && typeName.compare("this")!=0){
|
if (typeName.at(typeName.length()-1) == 's' && !Subtypes::subtypesList->find(typeName,false) && typeName.compare("this")!=0){
|
||||||
typeName = typeName.substr(0,typeName.length()-1);
|
typeName = typeName.substr(0,typeName.length()-1);
|
||||||
maxtargets = -1;
|
maxtargets = -1;
|
||||||
}
|
}
|
||||||
@@ -358,7 +358,7 @@ bool CardTargetChooser::canTarget(Targetable * target ){
|
|||||||
Choose anything that has a given list of types
|
Choose anything that has a given list of types
|
||||||
**/
|
**/
|
||||||
TypeTargetChooser::TypeTargetChooser(const char * _type, MTGCardInstance * card, int _maxtargets,bool other):TargetZoneChooser(card, _maxtargets,other){
|
TypeTargetChooser::TypeTargetChooser(const char * _type, MTGCardInstance * card, int _maxtargets,bool other):TargetZoneChooser(card, _maxtargets,other){
|
||||||
int id = Subtypes::subtypesList->Add(_type);
|
int id = Subtypes::subtypesList->find(_type);
|
||||||
nbtypes = 0;
|
nbtypes = 0;
|
||||||
addType(id);
|
addType(id);
|
||||||
int default_zones[] = {MTGGameZone::MY_BATTLEFIELD, MTGGameZone::OPPONENT_BATTLEFIELD};
|
int default_zones[] = {MTGGameZone::MY_BATTLEFIELD, MTGGameZone::OPPONENT_BATTLEFIELD};
|
||||||
@@ -366,7 +366,7 @@ TypeTargetChooser::TypeTargetChooser(const char * _type, MTGCardInstance * card,
|
|||||||
}
|
}
|
||||||
|
|
||||||
TypeTargetChooser::TypeTargetChooser(const char * _type, int * _zones, int nbzones, MTGCardInstance * card, int _maxtargets,bool other):TargetZoneChooser(card, _maxtargets,other){
|
TypeTargetChooser::TypeTargetChooser(const char * _type, int * _zones, int nbzones, MTGCardInstance * card, int _maxtargets,bool other):TargetZoneChooser(card, _maxtargets,other){
|
||||||
int id = Subtypes::subtypesList->Add(_type);
|
int id = Subtypes::subtypesList->find(_type);
|
||||||
nbtypes = 0;
|
nbtypes = 0;
|
||||||
addType(id);
|
addType(id);
|
||||||
if (nbzones == 0){
|
if (nbzones == 0){
|
||||||
@@ -378,7 +378,7 @@ TypeTargetChooser::TypeTargetChooser(const char * _type, int * _zones, int nbzon
|
|||||||
}
|
}
|
||||||
|
|
||||||
void TypeTargetChooser::addType(const char * _type){
|
void TypeTargetChooser::addType(const char * _type){
|
||||||
int id = Subtypes::subtypesList->Add(_type);
|
int id = Subtypes::subtypesList->find(_type);
|
||||||
addType(id);
|
addType(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -393,7 +393,7 @@ bool TypeTargetChooser::canTarget(Targetable * target){
|
|||||||
MTGCardInstance * card = (MTGCardInstance *) target;
|
MTGCardInstance * card = (MTGCardInstance *) target;
|
||||||
for (int i= 0; i < nbtypes; i++){
|
for (int i= 0; i < nbtypes; i++){
|
||||||
if (card->hasSubtype(types[i])) return true;
|
if (card->hasSubtype(types[i])) return true;
|
||||||
if (Subtypes::subtypesList->find(card->name) == types[i]) return true;
|
if (Subtypes::subtypesList->find(card->getLCName()) == types[i]) return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}else if (target->typeAsTarget() == TARGET_STACKACTION){
|
}else if (target->typeAsTarget() == TARGET_STACKACTION){
|
||||||
|
|||||||
@@ -227,12 +227,12 @@ bool WCachedTexture::isGood(){
|
|||||||
return (texture != NULL);
|
return (texture != NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WCachedTexture::Refresh(string filename){
|
void WCachedTexture::Refresh(){
|
||||||
int error = 0;
|
int error = 0;
|
||||||
JTexture* old = texture;
|
JTexture* old = texture;
|
||||||
texture = NULL;
|
texture = NULL;
|
||||||
|
|
||||||
if(!Attempt(filename,loadedMode, error))
|
if(!Attempt(mFilename,loadedMode, error))
|
||||||
SAFE_DELETE(texture);
|
SAFE_DELETE(texture);
|
||||||
|
|
||||||
if(!texture)
|
if(!texture)
|
||||||
@@ -247,6 +247,7 @@ void WCachedTexture::Refresh(string filename){
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool WCachedTexture::Attempt(string filename, int submode, int & error){
|
bool WCachedTexture::Attempt(string filename, int submode, int & error){
|
||||||
|
mFilename = filename;
|
||||||
int format = TEXTURE_FORMAT;
|
int format = TEXTURE_FORMAT;
|
||||||
loadedMode = submode;
|
loadedMode = submode;
|
||||||
string realname;
|
string realname;
|
||||||
@@ -366,7 +367,7 @@ bool WCachedSample::isGood(){
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
void WCachedSample::Refresh(string filename){
|
void WCachedSample::Refresh(){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -403,11 +404,11 @@ unsigned long WCachedParticles::size(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Only effects future particle systems, of course.
|
//Only effects future particle systems, of course.
|
||||||
void WCachedParticles::Refresh(string filename){
|
void WCachedParticles::Refresh(){
|
||||||
hgeParticleSystemInfo * old = particles;
|
hgeParticleSystemInfo * old = particles;
|
||||||
|
|
||||||
int error = 0;
|
int error = 0;
|
||||||
Attempt(filename,loadedMode,error);
|
Attempt(mFilename,loadedMode,error);
|
||||||
|
|
||||||
if(isGood())
|
if(isGood())
|
||||||
SAFE_DELETE(old);
|
SAFE_DELETE(old);
|
||||||
|
|||||||
@@ -10,6 +10,8 @@
|
|||||||
#include "../include/WResourceManager.h"
|
#include "../include/WResourceManager.h"
|
||||||
|
|
||||||
|
|
||||||
|
int idCounter = OTHERS_OFFSET;
|
||||||
|
|
||||||
WResourceManager resources;
|
WResourceManager resources;
|
||||||
unsigned int vTime = 0;
|
unsigned int vTime = 0;
|
||||||
int WResourceManager::RetrieveError(){
|
int WResourceManager::RetrieveError(){
|
||||||
@@ -196,11 +198,11 @@ JQuad * WResourceManager::RetrieveCard(MTGCard * card, int style, int submode){
|
|||||||
|
|
||||||
submode = submode | TEXTURE_SUB_CARD;
|
submode = submode | TEXTURE_SUB_CARD;
|
||||||
|
|
||||||
|
|
||||||
string filename = card->getSetName();
|
string filename = card->getSetName();
|
||||||
filename += "/";
|
filename += "/";
|
||||||
filename += card->getImageName();
|
filename += card->getImageName();
|
||||||
JQuad * jq = RetrieveQuad(filename,0,0,0,0,"",style,submode|TEXTURE_SUB_5551);
|
int id = card->getMTGId();
|
||||||
|
JQuad * jq = RetrieveQuad(filename,0,0,0,0, "",style,submode|TEXTURE_SUB_5551,id);
|
||||||
lastError = textureWCache.mError;
|
lastError = textureWCache.mError;
|
||||||
if(jq){
|
if(jq){
|
||||||
jq->SetHotSpot(jq->mTex->mWidth / 2, jq->mTex->mHeight / 2);
|
jq->SetHotSpot(jq->mTex->mWidth / 2, jq->mTex->mHeight / 2);
|
||||||
@@ -224,7 +226,7 @@ int WResourceManager::CreateQuad(const string &quadName, const string &textureNa
|
|||||||
return pos;
|
return pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
WCachedTexture * jtex = textureWCache.Retrieve(textureName,RETRIEVE_MANAGE);
|
WCachedTexture * jtex = textureWCache.Retrieve(0,textureName,RETRIEVE_MANAGE);
|
||||||
lastError = textureWCache.mError;
|
lastError = textureWCache.mError;
|
||||||
|
|
||||||
//Somehow, jtex wasn't promoted.
|
//Somehow, jtex wasn't promoted.
|
||||||
@@ -275,7 +277,7 @@ JQuad * WResourceManager::RetrieveTempQuad(string filename){
|
|||||||
return RetrieveQuad(filename,0,0,0,0,"temporary",RETRIEVE_NORMAL);
|
return RetrieveQuad(filename,0,0,0,0,"temporary",RETRIEVE_NORMAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
JQuad * WResourceManager::RetrieveQuad(string filename, float offX, float offY, float width, float height, string resname, int style, int submode){
|
JQuad * WResourceManager::RetrieveQuad(string filename, float offX, float offY, float width, float height, string resname, int style, int submode, int id){
|
||||||
JQuad * jq = NULL;
|
JQuad * jq = NULL;
|
||||||
|
|
||||||
//Lookup managed resources, but only with a real resname.
|
//Lookup managed resources, but only with a real resname.
|
||||||
@@ -298,9 +300,9 @@ JQuad * WResourceManager::RetrieveQuad(string filename, float offX, float offY,
|
|||||||
//No quad, but we have a managed texture for this!
|
//No quad, but we have a managed texture for this!
|
||||||
WCachedTexture * jtex = NULL;
|
WCachedTexture * jtex = NULL;
|
||||||
if(style == RETRIEVE_MANAGE || style == RETRIEVE_EXISTING)
|
if(style == RETRIEVE_MANAGE || style == RETRIEVE_EXISTING)
|
||||||
jtex = textureWCache.Retrieve(filename,style,submode);
|
jtex = textureWCache.Retrieve(id,filename,style,submode);
|
||||||
else
|
else
|
||||||
jtex = textureWCache.Retrieve(filename,RETRIEVE_NORMAL,submode);
|
jtex = textureWCache.Retrieve(id, filename,RETRIEVE_NORMAL,submode);
|
||||||
|
|
||||||
lastError = textureWCache.mError;
|
lastError = textureWCache.mError;
|
||||||
|
|
||||||
@@ -345,7 +347,7 @@ void WResourceManager::Release(JQuad * quad){
|
|||||||
if(!quad)
|
if(!quad)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
map<string,WCachedTexture*>::iterator it;
|
map<int,WCachedTexture*>::iterator it;
|
||||||
for(it = textureWCache.cache.begin();it!=textureWCache.cache.end();it++){
|
for(it = textureWCache.cache.begin();it!=textureWCache.cache.end();it++){
|
||||||
if(it->second && it->second->ReleaseQuad(quad))
|
if(it->second && it->second->ReleaseQuad(quad))
|
||||||
break;
|
break;
|
||||||
@@ -395,7 +397,7 @@ JTexture * WResourceManager::RetrieveTexture(string filename, int style, int sub
|
|||||||
style = RETRIEVE_NORMAL;
|
style = RETRIEVE_NORMAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
res = textureWCache.Retrieve(filename,style,submode);
|
res = textureWCache.Retrieve(0,filename,style,submode);
|
||||||
lastError = textureWCache.mError;
|
lastError = textureWCache.mError;
|
||||||
|
|
||||||
if(res){ //a non-null result will always be good.
|
if(res){ //a non-null result will always be good.
|
||||||
@@ -448,7 +450,7 @@ JTexture* WResourceManager::GetTexture(const string &textureName){
|
|||||||
}
|
}
|
||||||
|
|
||||||
JTexture* WResourceManager::GetTexture(int id){
|
JTexture* WResourceManager::GetTexture(int id){
|
||||||
map<string,WCachedTexture*>::iterator it;
|
map<int,WCachedTexture*>::iterator it;
|
||||||
JTexture *jtex = NULL;
|
JTexture *jtex = NULL;
|
||||||
|
|
||||||
if(id == INVALID_ID)
|
if(id == INVALID_ID)
|
||||||
@@ -470,7 +472,7 @@ hgeParticleSystemInfo * WResourceManager::RetrievePSI(string filename, JQuad * t
|
|||||||
if(!texture)
|
if(!texture)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
WCachedParticles * res = psiWCache.Retrieve(filename,style,submode);
|
WCachedParticles * res = psiWCache.Retrieve(0,filename,style,submode);
|
||||||
lastError = psiWCache.mError;
|
lastError = psiWCache.mError;
|
||||||
|
|
||||||
if(res) //A non-null result will always be good.
|
if(res) //A non-null result will always be good.
|
||||||
@@ -485,7 +487,7 @@ hgeParticleSystemInfo * WResourceManager::RetrievePSI(string filename, JQuad * t
|
|||||||
|
|
||||||
JSample * WResourceManager::RetrieveSample(string filename, int style, int submode){
|
JSample * WResourceManager::RetrieveSample(string filename, int style, int submode){
|
||||||
WCachedSample * tc = NULL;
|
WCachedSample * tc = NULL;
|
||||||
tc = sampleWCache.Retrieve(filename,style,submode);
|
tc = sampleWCache.Retrieve(0,filename,style,submode);
|
||||||
lastError = sampleWCache.mError;
|
lastError = sampleWCache.mError;
|
||||||
|
|
||||||
//Sample exists! Get it.
|
//Sample exists! Get it.
|
||||||
@@ -870,9 +872,9 @@ void WResourceManager::Refresh(){
|
|||||||
//WCache
|
//WCache
|
||||||
template <class cacheItem,class cacheActual>
|
template <class cacheItem,class cacheActual>
|
||||||
bool WCache<cacheItem, cacheActual>::RemoveOldest(){
|
bool WCache<cacheItem, cacheActual>::RemoveOldest(){
|
||||||
typename map<string,cacheItem*> ::iterator oldest = cache.end();
|
typename map<int,cacheItem*> ::iterator oldest = cache.end();
|
||||||
|
|
||||||
for(typename map<string,cacheItem *>::iterator it = cache.begin();it!=cache.end();it++){
|
for(typename map<int,cacheItem *>::iterator it = cache.begin();it!=cache.end();it++){
|
||||||
if(it->second && !it->second->isLocked()
|
if(it->second && !it->second->isLocked()
|
||||||
&& (oldest == cache.end() || it->second->lastTime < oldest->second->lastTime))
|
&& (oldest == cache.end() || it->second->lastTime < oldest->second->lastTime))
|
||||||
oldest = it;
|
oldest = it;
|
||||||
@@ -889,7 +891,7 @@ bool WCache<cacheItem, cacheActual>::RemoveOldest(){
|
|||||||
}
|
}
|
||||||
template <class cacheItem, class cacheActual>
|
template <class cacheItem, class cacheActual>
|
||||||
void WCache<cacheItem, cacheActual>::Clear(){
|
void WCache<cacheItem, cacheActual>::Clear(){
|
||||||
typename map<string,cacheItem*>::iterator it, next;
|
typename map<int,cacheItem*>::iterator it, next;
|
||||||
|
|
||||||
for(it = cache.begin(); it != cache.end();it=next){
|
for(it = cache.begin(); it != cache.end();it=next){
|
||||||
next = it;
|
next = it;
|
||||||
@@ -910,7 +912,7 @@ void WCache<cacheItem, cacheActual>::Clear(){
|
|||||||
|
|
||||||
template <class cacheItem, class cacheActual>
|
template <class cacheItem, class cacheActual>
|
||||||
void WCache<cacheItem, cacheActual>::ClearUnlocked(){
|
void WCache<cacheItem, cacheActual>::ClearUnlocked(){
|
||||||
typename map<string,cacheItem*>::iterator it, next;
|
typename map<int,cacheItem*>::iterator it, next;
|
||||||
|
|
||||||
for(it = cache.begin(); it != cache.end();it=next){
|
for(it = cache.begin(); it != cache.end();it=next){
|
||||||
next = it;
|
next = it;
|
||||||
@@ -928,7 +930,7 @@ void WCache<cacheItem, cacheActual>::ClearUnlocked(){
|
|||||||
|
|
||||||
template <class cacheItem, class cacheActual>
|
template <class cacheItem, class cacheActual>
|
||||||
void WCache<cacheItem, cacheActual>::ClearMisses(){
|
void WCache<cacheItem, cacheActual>::ClearMisses(){
|
||||||
typename map<string,cacheItem*>::iterator it, next;
|
typename map<int,cacheItem*>::iterator it, next;
|
||||||
|
|
||||||
for(it = cache.begin(); it != cache.end();it=next){
|
for(it = cache.begin(); it != cache.end();it=next){
|
||||||
next = it;
|
next = it;
|
||||||
@@ -995,14 +997,14 @@ cacheItem* WCache<cacheItem, cacheActual>::AttemptNew(string filename, int submo
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <class cacheItem, class cacheActual>
|
template <class cacheItem, class cacheActual>
|
||||||
cacheItem * WCache<cacheItem, cacheActual>::Retrieve(string filename, int style, int submode){
|
cacheItem * WCache<cacheItem, cacheActual>::Retrieve(int id, string filename, int style, int submode){
|
||||||
//Check cache.
|
//Check cache.
|
||||||
cacheItem * tc = NULL;
|
cacheItem * tc = NULL;
|
||||||
|
|
||||||
if(style == RETRIEVE_EXISTING || style == RETRIEVE_RESOURCE)
|
if(style == RETRIEVE_EXISTING || style == RETRIEVE_RESOURCE)
|
||||||
tc = Get(filename,style,submode|CACHE_EXISTING);
|
tc = Get(id,filename,style,submode|CACHE_EXISTING);
|
||||||
else
|
else
|
||||||
tc = Get(filename,style,submode);
|
tc = Get(id, filename,style,submode);
|
||||||
|
|
||||||
//Retrieve resource only works on permanent items.
|
//Retrieve resource only works on permanent items.
|
||||||
if(style == RETRIEVE_RESOURCE && tc && !tc->isPermanent()){
|
if(style == RETRIEVE_RESOURCE && tc && !tc->isPermanent()){
|
||||||
@@ -1021,7 +1023,7 @@ cacheItem * WCache<cacheItem, cacheActual>::Retrieve(string filename, int style,
|
|||||||
UnlinkCache(tc);
|
UnlinkCache(tc);
|
||||||
|
|
||||||
//Post it in managed resources.
|
//Post it in managed resources.
|
||||||
managed[makeID(filename,submode)] = tc;
|
managed[makeID(id,filename,submode)] = tc;
|
||||||
tc->deadbolt();
|
tc->deadbolt();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -1040,34 +1042,35 @@ cacheItem * WCache<cacheItem, cacheActual>::Retrieve(string filename, int style,
|
|||||||
|
|
||||||
//Record managed failure. Cache failure is recorded in Get().
|
//Record managed failure. Cache failure is recorded in Get().
|
||||||
if(style == RETRIEVE_MANAGE || style == RETRIEVE_RESOURCE)
|
if(style == RETRIEVE_MANAGE || style == RETRIEVE_RESOURCE)
|
||||||
managed[makeID(filename,submode)] = NULL;
|
managed[makeID(id,filename,submode)] = NULL;
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
template <class cacheItem, class cacheActual>
|
template <class cacheItem, class cacheActual>
|
||||||
string WCache<cacheItem, cacheActual>::makeID(string id, int submode){
|
int WCache<cacheItem, cacheActual>::makeID(int id, string filename, int submode){
|
||||||
string lookup = id;
|
int mId = id;
|
||||||
|
if (!mId) {
|
||||||
|
mId = ids[filename];
|
||||||
|
if (!mId){
|
||||||
|
mId = idCounter++;
|
||||||
|
ids[filename] = mId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//To differentiate between cached thumbnails and the real thing.
|
//To differentiate between cached thumbnails and the real thing.
|
||||||
if(submode & TEXTURE_SUB_THUMB)
|
if(submode & TEXTURE_SUB_THUMB){
|
||||||
lookup.insert(0,"T");
|
if (mId < 0)
|
||||||
|
mId-=THUMBNAILS_OFFSET;
|
||||||
return lookup;
|
else
|
||||||
|
mId+=THUMBNAILS_OFFSET;
|
||||||
|
}
|
||||||
|
return mId;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class cacheItem, class cacheActual>
|
template <class cacheItem, class cacheActual>
|
||||||
string WCache<cacheItem, cacheActual>::makeFilename(string id, int submode){
|
cacheItem * WCache<cacheItem, cacheActual>::Get(int id, string filename, int style, int submode){
|
||||||
//To differentiate between cached thumbnails and the real thing.
|
typename map<int,cacheItem*>::iterator it;
|
||||||
if(submode & TEXTURE_SUB_THUMB)
|
int lookup = makeID(id,filename, submode);
|
||||||
return id.substr(1);
|
|
||||||
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class cacheItem, class cacheActual>
|
|
||||||
cacheItem * WCache<cacheItem, cacheActual>::Get(string id, int style, int submode){
|
|
||||||
typename map<string,cacheItem*>::iterator it;
|
|
||||||
string lookup = makeID(id,submode);
|
|
||||||
|
|
||||||
//Check for managed resources first. Always
|
//Check for managed resources first. Always
|
||||||
it = managed.find(lookup);
|
it = managed.find(lookup);
|
||||||
@@ -1101,7 +1104,7 @@ cacheItem * WCache<cacheItem, cacheActual>::Get(string id, int style, int submod
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Space in cache, make new texture
|
//Space in cache, make new texture
|
||||||
cacheItem * item = AttemptNew(id,submode);
|
cacheItem * item = AttemptNew(filename,submode);
|
||||||
|
|
||||||
if(style == RETRIEVE_MANAGE){
|
if(style == RETRIEVE_MANAGE){
|
||||||
managed[lookup] = item; //Record a hit or miss.
|
managed[lookup] = item; //Record a hit or miss.
|
||||||
@@ -1130,17 +1133,17 @@ cacheItem * WCache<cacheItem, cacheActual>::Get(string id, int style, int submod
|
|||||||
|
|
||||||
template <class cacheItem, class cacheActual>
|
template <class cacheItem, class cacheActual>
|
||||||
void WCache<cacheItem, cacheActual>::Refresh(){
|
void WCache<cacheItem, cacheActual>::Refresh(){
|
||||||
typename map<string,cacheItem*>::iterator it;
|
typename map<int,cacheItem*>::iterator it;
|
||||||
ClearUnlocked();
|
ClearUnlocked();
|
||||||
|
|
||||||
for(it = cache.begin();it!=cache.end();it++){
|
for(it = cache.begin();it!=cache.end();it++){
|
||||||
if(it->second){
|
if(it->second){
|
||||||
it->second->Refresh(makeFilename(it->first,it->second->loadedMode));
|
it->second->Refresh();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for(it = managed.begin();it!=managed.end();it++){
|
for(it = managed.begin();it!=managed.end();it++){
|
||||||
if(it->second){
|
if(it->second){
|
||||||
it->second->Refresh(makeFilename(it->first,it->second->loadedMode));
|
it->second->Refresh();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1159,7 +1162,7 @@ WCache<cacheItem, cacheActual>::WCache(){
|
|||||||
|
|
||||||
template <class cacheItem, class cacheActual>
|
template <class cacheItem, class cacheActual>
|
||||||
WCache<cacheItem, cacheActual>::~WCache(){
|
WCache<cacheItem, cacheActual>::~WCache(){
|
||||||
typename map<string,cacheItem*>::iterator it;
|
typename map<int,cacheItem*>::iterator it;
|
||||||
|
|
||||||
//Delete from cache & managed
|
//Delete from cache & managed
|
||||||
for(it=cache.begin();it!=cache.end();it++){
|
for(it=cache.begin();it!=cache.end();it++){
|
||||||
@@ -1196,13 +1199,13 @@ unsigned int WCache<cacheItem, cacheActual>::Flatten(){
|
|||||||
unsigned int youngest = 65535;
|
unsigned int youngest = 65535;
|
||||||
unsigned int oldest = 0;
|
unsigned int oldest = 0;
|
||||||
|
|
||||||
for (typename map<string,cacheItem*>::iterator it = cache.begin(); it != cache.end(); ++it){
|
for (typename map<int,cacheItem*>::iterator it = cache.begin(); it != cache.end(); ++it){
|
||||||
if(!it->second) continue;
|
if(!it->second) continue;
|
||||||
if(it->second->lastTime < youngest) youngest = it->second->lastTime;
|
if(it->second->lastTime < youngest) youngest = it->second->lastTime;
|
||||||
if(it->second->lastTime > oldest) oldest = it->second->lastTime;
|
if(it->second->lastTime > oldest) oldest = it->second->lastTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (typename map<string,cacheItem*>::iterator it = cache.begin(); it != cache.end(); ++it){
|
for (typename map<int,cacheItem*>::iterator it = cache.begin(); it != cache.end(); ++it){
|
||||||
if(!it->second) continue;
|
if(!it->second) continue;
|
||||||
it->second->lastTime -= youngest;
|
it->second->lastTime -= youngest;
|
||||||
}
|
}
|
||||||
@@ -1211,11 +1214,11 @@ unsigned int WCache<cacheItem, cacheActual>::Flatten(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <class cacheItem, class cacheActual>
|
template <class cacheItem, class cacheActual>
|
||||||
bool WCache<cacheItem, cacheActual>::RemoveMiss(string id){
|
bool WCache<cacheItem, cacheActual>::RemoveMiss(int id){
|
||||||
typename map<string,cacheItem*>::iterator it = cache.end();
|
typename map<int,cacheItem*>::iterator it = cache.end();
|
||||||
|
|
||||||
for(it = cache.begin();it!=cache.end();it++){
|
for(it = cache.begin();it!=cache.end();it++){
|
||||||
if((id == "" || it->first == id) && it->second == NULL)
|
if((id == 0 || it->first == id) && it->second == NULL)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1230,7 +1233,7 @@ bool WCache<cacheItem, cacheActual>::RemoveMiss(string id){
|
|||||||
|
|
||||||
template <class cacheItem, class cacheActual>
|
template <class cacheItem, class cacheActual>
|
||||||
bool WCache<cacheItem, cacheActual>::RemoveItem(cacheItem * item, bool force){
|
bool WCache<cacheItem, cacheActual>::RemoveItem(cacheItem * item, bool force){
|
||||||
typename map<string,cacheItem*>::iterator it;
|
typename map<int,cacheItem*>::iterator it;
|
||||||
|
|
||||||
if(item == NULL)
|
if(item == NULL)
|
||||||
return false; //Use RemoveMiss to remove cache misses, not this.
|
return false; //Use RemoveMiss to remove cache misses, not this.
|
||||||
@@ -1250,7 +1253,7 @@ bool WCache<cacheItem, cacheActual>::RemoveItem(cacheItem * item, bool force){
|
|||||||
|
|
||||||
template <class cacheItem, class cacheActual>
|
template <class cacheItem, class cacheActual>
|
||||||
bool WCache<cacheItem, cacheActual>::UnlinkCache(cacheItem * item){
|
bool WCache<cacheItem, cacheActual>::UnlinkCache(cacheItem * item){
|
||||||
typename map<string,cacheItem*>::iterator it = cache.end();
|
typename map<int,cacheItem*>::iterator it = cache.end();
|
||||||
|
|
||||||
if(item == NULL)
|
if(item == NULL)
|
||||||
return false; //Use RemoveMiss to remove cache misses, not this.
|
return false; //Use RemoveMiss to remove cache misses, not this.
|
||||||
@@ -1298,7 +1301,7 @@ bool WCache<cacheItem, cacheActual>::Release(cacheActual* actual){
|
|||||||
if(!actual)
|
if(!actual)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
typename map<string,cacheItem*>::iterator it;
|
typename map<int,cacheItem*>::iterator it;
|
||||||
for(it=cache.begin();it!=cache.end();it++){
|
for(it=cache.begin();it!=cache.end();it++){
|
||||||
if(it->second && it->second->compare(actual))
|
if(it->second && it->second->compare(actual))
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user