Erwan
- various optimization fixes
This commit is contained in:
@@ -599,7 +599,7 @@ MTGCardInstance * AIPlayerBaka::FindCardToPlay(ManaCost * pMana, const char * ty
|
||||
cd.setType(type);
|
||||
card = NULL;
|
||||
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;
|
||||
int currentCost = card->getManaCost()->getConvertedCost();
|
||||
int hasX = card->getManaCost()->hasX();
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "../include/GameObserver.h"
|
||||
#include "../include/Targetable.h"
|
||||
#include "../include/WEvent.h"
|
||||
#include <assert.h>
|
||||
|
||||
MTGAbility* ActionLayer::getAbility(int type){
|
||||
for (int i = 1; i < mCount; i++){
|
||||
@@ -17,6 +18,7 @@ MTGAbility* ActionLayer::getAbility(int type){
|
||||
int ActionLayer::moveToGarbage(ActionElement * e){
|
||||
int i = getIndexOf(e);
|
||||
if (i != -1){
|
||||
if (isWaitingForAnswer() == e) setCurrentWaitingAction(NULL);
|
||||
e->destroy();
|
||||
mObjects.erase(mObjects.begin()+i);
|
||||
mCount--;
|
||||
@@ -125,13 +127,19 @@ void ActionLayer::Render (){
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ActionLayer::setCurrentWaitingAction(ActionElement * ae){
|
||||
assert(!ae || !currentWaitingAction);
|
||||
currentWaitingAction = ae;
|
||||
}
|
||||
|
||||
TargetChooser * ActionLayer::getCurrentTargetChooser(){
|
||||
for (int i=0;i<mCount;i++){
|
||||
/* for (int i=0;i<mCount;i++){
|
||||
ActionElement * currentAction = (ActionElement *)mObjects[i];
|
||||
if(currentAction->waitingForAnswer) return currentAction->tc;
|
||||
}
|
||||
return NULL;*/
|
||||
if (currentWaitingAction && currentWaitingAction->waitingForAnswer)
|
||||
return currentWaitingAction->tc;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -139,14 +147,13 @@ int ActionLayer::cancelCurrentAction(){
|
||||
ActionElement * ae = isWaitingForAnswer();
|
||||
if (!ae) return 0;
|
||||
ae->waitingForAnswer = 0; //TODO MOVE THIS IS ActionElement
|
||||
setCurrentWaitingAction(NULL);
|
||||
return 1;
|
||||
}
|
||||
|
||||
ActionElement * ActionLayer::isWaitingForAnswer(){
|
||||
for (int i=0;i<mCount;i++){
|
||||
ActionElement * currentAction = (ActionElement *)mObjects[i];
|
||||
if(currentAction->waitingForAnswer) return currentAction;
|
||||
}
|
||||
if (currentWaitingAction && currentWaitingAction->waitingForAnswer)
|
||||
return currentWaitingAction;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -182,12 +189,8 @@ int ActionLayer::isReactingToTargetClick(Targetable * card){
|
||||
int ActionLayer::reactToTargetClick(Targetable * card){
|
||||
int result = 0;
|
||||
|
||||
for (int i=0;i<mCount;i++){
|
||||
ActionElement * currentAction = (ActionElement *)mObjects[i];
|
||||
if(currentAction->waitingForAnswer){
|
||||
return reactToTargetClick(currentAction,card);
|
||||
}
|
||||
}
|
||||
ActionElement * ae = isWaitingForAnswer();
|
||||
if (ae) return reactToTargetClick(ae,card);
|
||||
|
||||
for (int i=0;i<mCount;i++){
|
||||
ActionElement * currentAction = (ActionElement *)mObjects[i];
|
||||
@@ -202,7 +205,6 @@ int ActionLayer::isReactingToClick(MTGCardInstance * card){
|
||||
|
||||
if (isWaitingForAnswer()) return -1;
|
||||
|
||||
|
||||
for (int i=0;i<mCount;i++){
|
||||
ActionElement * currentAction = (ActionElement *)mObjects[i];
|
||||
result += currentAction->isReactingToClick(card);
|
||||
@@ -214,12 +216,8 @@ int ActionLayer::isReactingToClick(MTGCardInstance * card){
|
||||
int ActionLayer::reactToClick(MTGCardInstance * card){
|
||||
int result = 0;
|
||||
|
||||
for (int i=0;i<mCount;i++){
|
||||
ActionElement * currentAction = (ActionElement *)mObjects[i];
|
||||
if(currentAction->waitingForAnswer){
|
||||
return reactToClick(currentAction,card);
|
||||
}
|
||||
}
|
||||
ActionElement * ae = isWaitingForAnswer();
|
||||
if (ae) return reactToClick(ae,card);
|
||||
|
||||
for (int i=0;i<mCount;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(){
|
||||
SAFE_DELETE(abilitiesMenu);
|
||||
cleanGarbage();
|
||||
|
||||
@@ -20,7 +20,7 @@ void CardDescriptor::unsecureSetTapped(int i){
|
||||
}
|
||||
|
||||
void CardDescriptor::setNegativeSubtype( string value){
|
||||
int id = Subtypes::subtypesList->Add(value);
|
||||
int id = Subtypes::subtypesList->find(value);
|
||||
addType(-id);
|
||||
}
|
||||
|
||||
@@ -30,12 +30,12 @@ MTGCardInstance * CardDescriptor::match_or(MTGCardInstance * card){
|
||||
found = 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;
|
||||
break;
|
||||
}
|
||||
}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;
|
||||
break;
|
||||
}
|
||||
@@ -67,11 +67,11 @@ MTGCardInstance * CardDescriptor::match_and(MTGCardInstance * card){
|
||||
MTGCardInstance * match = card;
|
||||
for (int i = 0; i< nb_types; i++){
|
||||
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;
|
||||
}
|
||||
}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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,11 @@ GameState::GameState(GameApp* parent): mParent(parent)
|
||||
|
||||
GameApp::GameApp(): JApp()
|
||||
{
|
||||
#ifdef DEBUG
|
||||
nbUpdates = 0;
|
||||
totalFPS = 0;
|
||||
#endif
|
||||
|
||||
mScreenShotCount = 0;
|
||||
|
||||
for (int i=0; i < MAX_STATE ; i++)
|
||||
@@ -286,6 +291,20 @@ void GameApp::Render()
|
||||
resources.DebugRender();
|
||||
#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)
|
||||
|
||||
@@ -29,8 +29,6 @@ void GameStateShop::Start()
|
||||
|
||||
|
||||
mStage = STAGE_SHOP_SHOP;
|
||||
|
||||
bgTexture = resources.RetrieveTexture("shop.jpg",RETRIEVE_LOCK);
|
||||
|
||||
//alternateRender doesn't lock, so lock our thumbnails for hgeDistort.
|
||||
altThumb[0] = resources.RetrieveTexture("artifact_thumb.jpg", RETRIEVE_LOCK);
|
||||
@@ -42,7 +40,7 @@ void GameStateShop::Start()
|
||||
altThumb[6] = resources.RetrieveTexture("land_thumb.jpg", RETRIEVE_LOCK);
|
||||
altThumb[7] = resources.RetrieveTexture("gold_thumb.jpg", RETRIEVE_LOCK);
|
||||
|
||||
mBg = resources.RetrieveQuad("shop.jpg");
|
||||
|
||||
mBack = resources.GetQuad("back");
|
||||
|
||||
menuFont = resources.GetJLBFont(Constants::MENU_FONT);
|
||||
@@ -125,7 +123,6 @@ void GameStateShop::load(){
|
||||
void GameStateShop::End()
|
||||
{
|
||||
JRenderer::GetInstance()->EnableVSync(false);
|
||||
resources.Release(bgTexture);
|
||||
|
||||
//Release alternate thumbnails.
|
||||
for(int i=0;i<8;i++){
|
||||
@@ -169,6 +166,7 @@ void GameStateShop::Render()
|
||||
//Erase
|
||||
JRenderer * r = JRenderer::GetInstance();
|
||||
r->ClearScreen(ARGB(0,0,0,0));
|
||||
JQuad * mBg = resources.RetrieveQuad("shop.jpg");
|
||||
if (mBg) r->RenderQuad(mBg,0,0);
|
||||
|
||||
if (shop)
|
||||
|
||||
@@ -32,8 +32,10 @@ GuiFrame::GuiFrame()
|
||||
|
||||
step = 0.0;
|
||||
|
||||
gold2->SetColor(ARGB(127, 255, 255, 255));
|
||||
gold2->SetHFlip(true);
|
||||
if (gold2){
|
||||
gold2->SetColor(ARGB(127, 255, 255, 255));
|
||||
gold2->SetHFlip(true);
|
||||
}
|
||||
}
|
||||
|
||||
GuiFrame::~GuiFrame()
|
||||
|
||||
@@ -64,7 +64,6 @@ void GuiPlay::VertStack::Enstack(CardView* card)
|
||||
card->x = x + baseX; card->y = y + baseY;
|
||||
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)
|
||||
|
||||
@@ -186,7 +186,6 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG
|
||||
MTGCardInstance * target = card->target;
|
||||
if (!target) target = card;
|
||||
|
||||
|
||||
TriggeredAbility * trigger = NULL;
|
||||
trigger = parseTrigger(s,id,spell,card,target);
|
||||
//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;
|
||||
for (int i = 0; i < inplay->nb_cards; i++){
|
||||
MTGCardInstance * current = inplay->cards[i];
|
||||
if (current->hasType("land")) current->tap();
|
||||
if (current->hasType(Subtypes::TYPE_LAND)) current->tap();
|
||||
}
|
||||
player->getManaPool()->init();
|
||||
}
|
||||
@@ -1560,7 +1559,7 @@ void AbilityFactory::addAbilities(int _id, Spell * spell){
|
||||
Damageable * target = spell->getNextDamageableTarget();
|
||||
for (int j = card->controller()->game->inPlay->nb_cards-1; j >=0 ; --j){
|
||||
MTGCardInstance * current = card->controller()->game->inPlay->cards[j];
|
||||
if (current->hasType("Creature")){
|
||||
if (current->hasType(Subtypes::TYPE_CREATURE)){
|
||||
card->controller()->game->putInGraveyard(current);
|
||||
damage+= current->power;
|
||||
}
|
||||
@@ -1822,6 +1821,7 @@ void TargetAbility::Update(float dt){
|
||||
JGE * mEngine = JGE::GetInstance();
|
||||
if (waitingForAnswer){
|
||||
if(mEngine->GetButtonClick(PSP_CTRL_CROSS)){
|
||||
game->mLayers->actionLayer()->setCurrentWaitingAction(NULL);
|
||||
waitingForAnswer = 0;
|
||||
}else if(tc->targetsReadyCheck() == TARGET_OK_FULL){
|
||||
//waitingForAnswer = 0;
|
||||
@@ -1835,6 +1835,7 @@ int TargetAbility::reactToTargetClick(Targetable * object){
|
||||
if (waitingForAnswer){
|
||||
if (tc->toggleTarget(object) == TARGET_OK_FULL){
|
||||
waitingForAnswer = 0;
|
||||
game->mLayers->actionLayer()->setCurrentWaitingAction(NULL);
|
||||
return ActivatedAbility::reactToClick(source);
|
||||
}
|
||||
return 1;
|
||||
@@ -1847,18 +1848,23 @@ int TargetAbility::reactToClick(MTGCardInstance * card){
|
||||
if (!waitingForAnswer) {
|
||||
if (isReactingToClick(card)){
|
||||
waitingForAnswer = 1;
|
||||
game->mLayers->actionLayer()->setCurrentWaitingAction(this);
|
||||
tc->initTargets();
|
||||
return 1;
|
||||
}
|
||||
}else{
|
||||
if (card == source && (tc->targetsReadyCheck() == TARGET_OK || tc->targetsReadyCheck() == TARGET_OK_FULL)){
|
||||
waitingForAnswer = 0;
|
||||
game->mLayers->actionLayer()->setCurrentWaitingAction(NULL);
|
||||
return ActivatedAbility::reactToClick(source);
|
||||
}else{
|
||||
if (tc->toggleTarget(card) == TARGET_OK_FULL){
|
||||
|
||||
int result = ActivatedAbility::reactToClick(source);
|
||||
if (result) waitingForAnswer = 0;
|
||||
if (result) {
|
||||
waitingForAnswer = 0;
|
||||
game->mLayers->actionLayer()->setCurrentWaitingAction(NULL);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return 1;
|
||||
@@ -2198,7 +2204,7 @@ AManaProducer::AManaProducer(int id, MTGCardInstance * card, ManaCost * _output,
|
||||
int AManaProducer::isReactingToClick(MTGCardInstance * _card, ManaCost * mana){
|
||||
int result = 0;
|
||||
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;
|
||||
}
|
||||
return result;
|
||||
|
||||
@@ -45,7 +45,7 @@ MTGCard::MTGCard(MTGCard * source){
|
||||
manaCost.copy(source->getManaCost());
|
||||
|
||||
text = source->text;
|
||||
name = source->name;
|
||||
setName(source->name);
|
||||
strcpy(image_name, source->image_name);
|
||||
|
||||
rarity = source->rarity;
|
||||
@@ -120,10 +120,10 @@ const vector<string>& MTGCard::formattedText()
|
||||
|
||||
|
||||
bool MTGCard::isCreature(){
|
||||
return hasSubtype("creature");
|
||||
return hasSubtype(Subtypes::TYPE_CREATURE);
|
||||
}
|
||||
bool MTGCard::isLand(){
|
||||
return hasSubtype("land");
|
||||
return hasSubtype(Subtypes::TYPE_LAND);
|
||||
}
|
||||
bool MTGCard::isSpell(){
|
||||
return (!isCreature() && !isLand());
|
||||
@@ -217,7 +217,7 @@ void MTGCard::addType(char * _type_text){
|
||||
}
|
||||
|
||||
void MTGCard::setSubtype( string value){
|
||||
int id = Subtypes::subtypesList->Add(value);
|
||||
int id = Subtypes::subtypesList->find(value);
|
||||
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
|
||||
int MTGCard::removeType(string value, int removeAll){
|
||||
|
||||
int id = Subtypes::subtypesList->Add(value);
|
||||
int id = Subtypes::subtypesList->find(value);
|
||||
return removeType(id, removeAll);
|
||||
}
|
||||
|
||||
@@ -271,15 +271,22 @@ void MTGCard::addMagicText(string value){
|
||||
|
||||
void MTGCard::setName( string 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"
|
||||
//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{
|
||||
return name;
|
||||
}
|
||||
|
||||
const string MTGCard::getLCName() const{
|
||||
return lcname;
|
||||
}
|
||||
|
||||
|
||||
|
||||
ManaCost* MTGCard::getManaCost(){
|
||||
return &manaCost;
|
||||
@@ -299,18 +306,18 @@ bool MTGCard::hasSubtype(int _subtype){
|
||||
}
|
||||
|
||||
bool MTGCard::hasType(const char * _type){
|
||||
int id = Subtypes::subtypesList->Add(_type);
|
||||
int id = Subtypes::subtypesList->find(_type);
|
||||
return hasType(id);
|
||||
}
|
||||
|
||||
|
||||
bool MTGCard::hasSubtype(const char * _subtype){
|
||||
int id = Subtypes::subtypesList->Add(_subtype);
|
||||
int id = Subtypes::subtypesList->find(_subtype);
|
||||
return hasType(id);
|
||||
}
|
||||
|
||||
bool MTGCard::hasSubtype(string _subtype){
|
||||
int id = Subtypes::subtypesList->Add(_subtype);
|
||||
int id = Subtypes::subtypesList->find(_subtype);
|
||||
return hasType(id);
|
||||
}
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ void MTGCardInstance::copy(MTGCardInstance * card){
|
||||
manaCost.copy(source->getManaCost());
|
||||
|
||||
text = source->text;
|
||||
name = source->name;
|
||||
setName(source->name);
|
||||
|
||||
power = source->power;
|
||||
toughness = source->toughness;
|
||||
@@ -130,11 +130,11 @@ void MTGCardInstance::setType(const char * type_text){
|
||||
}
|
||||
|
||||
void MTGCardInstance::setSubtype(string value){
|
||||
int id = Subtypes::subtypesList->Add(value);
|
||||
int id = Subtypes::subtypesList->find(value);
|
||||
addType(id);
|
||||
}
|
||||
int MTGCardInstance::removeType(string value,int removeAll){
|
||||
int id = Subtypes::subtypesList->Add(value);
|
||||
int id = Subtypes::subtypesList->find(value);
|
||||
return removeType(id,removeAll);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,42 +6,34 @@
|
||||
Subtypes * Subtypes::subtypesList = NEW 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 result = find(value);
|
||||
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 );
|
||||
int Subtypes::find(string value, bool forceAdd){
|
||||
if (value[0]>=97 && value[0]<=122) value[0]-=32; //Poor man's camelcase. We assume strings we get are either Camelcased or lowercase
|
||||
map<string,int>::iterator it = values.find(value);
|
||||
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;
|
||||
return (find(value));
|
||||
|
||||
}
|
||||
|
||||
string Subtypes::find(int id){
|
||||
map<int,string>::iterator it=valuesById.find(id);;
|
||||
if (it != valuesById.end()) return it->second;
|
||||
return "";
|
||||
string Subtypes::find(unsigned int id){
|
||||
if (valuesById.size() < id || !id) return "";
|
||||
return valuesById[id - 1];
|
||||
}
|
||||
|
||||
@@ -176,7 +176,7 @@ TargetChooser * TargetChooserFactory::createTargetChooser(string s, MTGCardInsta
|
||||
typeName = typeName.substr(0,found);
|
||||
}
|
||||
//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);
|
||||
maxtargets = -1;
|
||||
}
|
||||
@@ -358,7 +358,7 @@ bool CardTargetChooser::canTarget(Targetable * target ){
|
||||
Choose anything that has a given list of types
|
||||
**/
|
||||
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;
|
||||
addType(id);
|
||||
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){
|
||||
int id = Subtypes::subtypesList->Add(_type);
|
||||
int id = Subtypes::subtypesList->find(_type);
|
||||
nbtypes = 0;
|
||||
addType(id);
|
||||
if (nbzones == 0){
|
||||
@@ -378,7 +378,7 @@ TypeTargetChooser::TypeTargetChooser(const char * _type, int * _zones, int nbzon
|
||||
}
|
||||
|
||||
void TypeTargetChooser::addType(const char * _type){
|
||||
int id = Subtypes::subtypesList->Add(_type);
|
||||
int id = Subtypes::subtypesList->find(_type);
|
||||
addType(id);
|
||||
}
|
||||
|
||||
@@ -393,7 +393,7 @@ bool TypeTargetChooser::canTarget(Targetable * target){
|
||||
MTGCardInstance * card = (MTGCardInstance *) target;
|
||||
for (int i= 0; i < nbtypes; i++){
|
||||
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;
|
||||
}else if (target->typeAsTarget() == TARGET_STACKACTION){
|
||||
|
||||
@@ -227,12 +227,12 @@ bool WCachedTexture::isGood(){
|
||||
return (texture != NULL);
|
||||
}
|
||||
|
||||
void WCachedTexture::Refresh(string filename){
|
||||
void WCachedTexture::Refresh(){
|
||||
int error = 0;
|
||||
JTexture* old = texture;
|
||||
texture = NULL;
|
||||
|
||||
if(!Attempt(filename,loadedMode, error))
|
||||
if(!Attempt(mFilename,loadedMode, error))
|
||||
SAFE_DELETE(texture);
|
||||
|
||||
if(!texture)
|
||||
@@ -247,6 +247,7 @@ void WCachedTexture::Refresh(string filename){
|
||||
}
|
||||
|
||||
bool WCachedTexture::Attempt(string filename, int submode, int & error){
|
||||
mFilename = filename;
|
||||
int format = TEXTURE_FORMAT;
|
||||
loadedMode = submode;
|
||||
string realname;
|
||||
@@ -366,7 +367,7 @@ bool WCachedSample::isGood(){
|
||||
|
||||
return true;
|
||||
}
|
||||
void WCachedSample::Refresh(string filename){
|
||||
void WCachedSample::Refresh(){
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -403,11 +404,11 @@ unsigned long WCachedParticles::size(){
|
||||
}
|
||||
|
||||
//Only effects future particle systems, of course.
|
||||
void WCachedParticles::Refresh(string filename){
|
||||
void WCachedParticles::Refresh(){
|
||||
hgeParticleSystemInfo * old = particles;
|
||||
|
||||
int error = 0;
|
||||
Attempt(filename,loadedMode,error);
|
||||
Attempt(mFilename,loadedMode,error);
|
||||
|
||||
if(isGood())
|
||||
SAFE_DELETE(old);
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
#include "../include/WResourceManager.h"
|
||||
|
||||
|
||||
int idCounter = OTHERS_OFFSET;
|
||||
|
||||
WResourceManager resources;
|
||||
unsigned int vTime = 0;
|
||||
int WResourceManager::RetrieveError(){
|
||||
@@ -196,11 +198,11 @@ JQuad * WResourceManager::RetrieveCard(MTGCard * card, int style, int submode){
|
||||
|
||||
submode = submode | TEXTURE_SUB_CARD;
|
||||
|
||||
|
||||
string filename = card->getSetName();
|
||||
filename += "/";
|
||||
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;
|
||||
if(jq){
|
||||
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;
|
||||
}
|
||||
|
||||
WCachedTexture * jtex = textureWCache.Retrieve(textureName,RETRIEVE_MANAGE);
|
||||
WCachedTexture * jtex = textureWCache.Retrieve(0,textureName,RETRIEVE_MANAGE);
|
||||
lastError = textureWCache.mError;
|
||||
|
||||
//Somehow, jtex wasn't promoted.
|
||||
@@ -275,7 +277,7 @@ JQuad * WResourceManager::RetrieveTempQuad(string filename){
|
||||
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;
|
||||
|
||||
//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!
|
||||
WCachedTexture * jtex = NULL;
|
||||
if(style == RETRIEVE_MANAGE || style == RETRIEVE_EXISTING)
|
||||
jtex = textureWCache.Retrieve(filename,style,submode);
|
||||
jtex = textureWCache.Retrieve(id,filename,style,submode);
|
||||
else
|
||||
jtex = textureWCache.Retrieve(filename,RETRIEVE_NORMAL,submode);
|
||||
jtex = textureWCache.Retrieve(id, filename,RETRIEVE_NORMAL,submode);
|
||||
|
||||
lastError = textureWCache.mError;
|
||||
|
||||
@@ -345,7 +347,7 @@ void WResourceManager::Release(JQuad * quad){
|
||||
if(!quad)
|
||||
return;
|
||||
|
||||
map<string,WCachedTexture*>::iterator it;
|
||||
map<int,WCachedTexture*>::iterator it;
|
||||
for(it = textureWCache.cache.begin();it!=textureWCache.cache.end();it++){
|
||||
if(it->second && it->second->ReleaseQuad(quad))
|
||||
break;
|
||||
@@ -395,7 +397,7 @@ JTexture * WResourceManager::RetrieveTexture(string filename, int style, int sub
|
||||
style = RETRIEVE_NORMAL;
|
||||
}
|
||||
|
||||
res = textureWCache.Retrieve(filename,style,submode);
|
||||
res = textureWCache.Retrieve(0,filename,style,submode);
|
||||
lastError = textureWCache.mError;
|
||||
|
||||
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){
|
||||
map<string,WCachedTexture*>::iterator it;
|
||||
map<int,WCachedTexture*>::iterator it;
|
||||
JTexture *jtex = NULL;
|
||||
|
||||
if(id == INVALID_ID)
|
||||
@@ -470,7 +472,7 @@ hgeParticleSystemInfo * WResourceManager::RetrievePSI(string filename, JQuad * t
|
||||
if(!texture)
|
||||
return NULL;
|
||||
|
||||
WCachedParticles * res = psiWCache.Retrieve(filename,style,submode);
|
||||
WCachedParticles * res = psiWCache.Retrieve(0,filename,style,submode);
|
||||
lastError = psiWCache.mError;
|
||||
|
||||
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){
|
||||
WCachedSample * tc = NULL;
|
||||
tc = sampleWCache.Retrieve(filename,style,submode);
|
||||
tc = sampleWCache.Retrieve(0,filename,style,submode);
|
||||
lastError = sampleWCache.mError;
|
||||
|
||||
//Sample exists! Get it.
|
||||
@@ -870,9 +872,9 @@ void WResourceManager::Refresh(){
|
||||
//WCache
|
||||
template <class cacheItem,class cacheActual>
|
||||
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()
|
||||
&& (oldest == cache.end() || it->second->lastTime < oldest->second->lastTime))
|
||||
oldest = it;
|
||||
@@ -889,7 +891,7 @@ bool WCache<cacheItem, cacheActual>::RemoveOldest(){
|
||||
}
|
||||
template <class cacheItem, class cacheActual>
|
||||
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){
|
||||
next = it;
|
||||
@@ -910,7 +912,7 @@ void WCache<cacheItem, cacheActual>::Clear(){
|
||||
|
||||
template <class cacheItem, class cacheActual>
|
||||
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){
|
||||
next = it;
|
||||
@@ -928,7 +930,7 @@ void WCache<cacheItem, cacheActual>::ClearUnlocked(){
|
||||
|
||||
template <class cacheItem, class cacheActual>
|
||||
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){
|
||||
next = it;
|
||||
@@ -995,14 +997,14 @@ cacheItem* WCache<cacheItem, cacheActual>::AttemptNew(string filename, int submo
|
||||
}
|
||||
|
||||
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.
|
||||
cacheItem * tc = NULL;
|
||||
|
||||
if(style == RETRIEVE_EXISTING || style == RETRIEVE_RESOURCE)
|
||||
tc = Get(filename,style,submode|CACHE_EXISTING);
|
||||
tc = Get(id,filename,style,submode|CACHE_EXISTING);
|
||||
else
|
||||
tc = Get(filename,style,submode);
|
||||
tc = Get(id, filename,style,submode);
|
||||
|
||||
//Retrieve resource only works on permanent items.
|
||||
if(style == RETRIEVE_RESOURCE && tc && !tc->isPermanent()){
|
||||
@@ -1021,7 +1023,7 @@ cacheItem * WCache<cacheItem, cacheActual>::Retrieve(string filename, int style,
|
||||
UnlinkCache(tc);
|
||||
|
||||
//Post it in managed resources.
|
||||
managed[makeID(filename,submode)] = tc;
|
||||
managed[makeID(id,filename,submode)] = tc;
|
||||
tc->deadbolt();
|
||||
}
|
||||
break;
|
||||
@@ -1040,34 +1042,35 @@ cacheItem * WCache<cacheItem, cacheActual>::Retrieve(string filename, int style,
|
||||
|
||||
//Record managed failure. Cache failure is recorded in Get().
|
||||
if(style == RETRIEVE_MANAGE || style == RETRIEVE_RESOURCE)
|
||||
managed[makeID(filename,submode)] = NULL;
|
||||
managed[makeID(id,filename,submode)] = NULL;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
template <class cacheItem, class cacheActual>
|
||||
string WCache<cacheItem, cacheActual>::makeID(string id, int submode){
|
||||
string lookup = id;
|
||||
int WCache<cacheItem, cacheActual>::makeID(int id, string filename, int submode){
|
||||
int mId = id;
|
||||
if (!mId) {
|
||||
mId = ids[filename];
|
||||
if (!mId){
|
||||
mId = idCounter++;
|
||||
ids[filename] = mId;
|
||||
}
|
||||
}
|
||||
|
||||
//To differentiate between cached thumbnails and the real thing.
|
||||
if(submode & TEXTURE_SUB_THUMB)
|
||||
lookup.insert(0,"T");
|
||||
|
||||
return lookup;
|
||||
if(submode & TEXTURE_SUB_THUMB){
|
||||
if (mId < 0)
|
||||
mId-=THUMBNAILS_OFFSET;
|
||||
else
|
||||
mId+=THUMBNAILS_OFFSET;
|
||||
}
|
||||
return mId;
|
||||
}
|
||||
|
||||
template <class cacheItem, class cacheActual>
|
||||
string WCache<cacheItem, cacheActual>::makeFilename(string id, int submode){
|
||||
//To differentiate between cached thumbnails and the real thing.
|
||||
if(submode & TEXTURE_SUB_THUMB)
|
||||
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);
|
||||
cacheItem * WCache<cacheItem, cacheActual>::Get(int id, string filename, int style, int submode){
|
||||
typename map<int,cacheItem*>::iterator it;
|
||||
int lookup = makeID(id,filename, submode);
|
||||
|
||||
//Check for managed resources first. Always
|
||||
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
|
||||
cacheItem * item = AttemptNew(id,submode);
|
||||
cacheItem * item = AttemptNew(filename,submode);
|
||||
|
||||
if(style == RETRIEVE_MANAGE){
|
||||
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>
|
||||
void WCache<cacheItem, cacheActual>::Refresh(){
|
||||
typename map<string,cacheItem*>::iterator it;
|
||||
typename map<int,cacheItem*>::iterator it;
|
||||
ClearUnlocked();
|
||||
|
||||
for(it = cache.begin();it!=cache.end();it++){
|
||||
if(it->second){
|
||||
it->second->Refresh(makeFilename(it->first,it->second->loadedMode));
|
||||
it->second->Refresh();
|
||||
}
|
||||
}
|
||||
for(it = managed.begin();it!=managed.end();it++){
|
||||
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>
|
||||
WCache<cacheItem, cacheActual>::~WCache(){
|
||||
typename map<string,cacheItem*>::iterator it;
|
||||
typename map<int,cacheItem*>::iterator it;
|
||||
|
||||
//Delete from cache & managed
|
||||
for(it=cache.begin();it!=cache.end();it++){
|
||||
@@ -1196,13 +1199,13 @@ unsigned int WCache<cacheItem, cacheActual>::Flatten(){
|
||||
unsigned int youngest = 65535;
|
||||
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->lastTime < youngest) youngest = 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;
|
||||
it->second->lastTime -= youngest;
|
||||
}
|
||||
@@ -1211,11 +1214,11 @@ unsigned int WCache<cacheItem, cacheActual>::Flatten(){
|
||||
}
|
||||
|
||||
template <class cacheItem, class cacheActual>
|
||||
bool WCache<cacheItem, cacheActual>::RemoveMiss(string id){
|
||||
typename map<string,cacheItem*>::iterator it = cache.end();
|
||||
bool WCache<cacheItem, cacheActual>::RemoveMiss(int id){
|
||||
typename map<int,cacheItem*>::iterator it = cache.end();
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -1230,7 +1233,7 @@ bool WCache<cacheItem, cacheActual>::RemoveMiss(string id){
|
||||
|
||||
template <class cacheItem, class cacheActual>
|
||||
bool WCache<cacheItem, cacheActual>::RemoveItem(cacheItem * item, bool force){
|
||||
typename map<string,cacheItem*>::iterator it;
|
||||
typename map<int,cacheItem*>::iterator it;
|
||||
|
||||
if(item == NULL)
|
||||
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>
|
||||
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)
|
||||
return false; //Use RemoveMiss to remove cache misses, not this.
|
||||
@@ -1298,7 +1301,7 @@ bool WCache<cacheItem, cacheActual>::Release(cacheActual* actual){
|
||||
if(!actual)
|
||||
return false;
|
||||
|
||||
typename map<string,cacheItem*>::iterator it;
|
||||
typename map<int,cacheItem*>::iterator it;
|
||||
for(it=cache.begin();it!=cache.end();it++){
|
||||
if(it->second && it->second->compare(actual))
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user