Erwan
- fixed a bug with Flagstones of Trokair. There was no easy fix (cloned objects deleting stuff from their parents...) and I ended up using a "garbage collect at end of turn" technique the way I did with the ActionStack. As a result, the memory print of a turn will become bigger, and even more bugs might occur at the end of a turn... I'm ready to discuss this, although I think it's the best solution (in terms of result/amount of work) given the way abilities work right now - Test suite now gives the number of failed/success at the end of the tests
This commit is contained in:
@@ -14,6 +14,27 @@ MTGAbility* ActionLayer::getAbility(int type){
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int ActionLayer::moveToGarbage(ActionElement * e){
|
||||
int i = getIndexOf(e);
|
||||
if (i != -1){
|
||||
e->destroy();
|
||||
mObjects.erase(mObjects.begin()+i);
|
||||
mCount--;
|
||||
garbage.push_back(e);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
int ActionLayer::cleanGarbage(){
|
||||
for (size_t i = 0; i < garbage.size(); ++i){
|
||||
delete(garbage[i]);
|
||||
}
|
||||
garbage.clear();
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ActionLayer::reactToClick(ActionElement * ability, MTGCardInstance * card){
|
||||
int result = ability->reactToClick(card);
|
||||
if (result) stuffHappened = 1;
|
||||
@@ -72,7 +93,7 @@ void ActionLayer::Update(float dt){
|
||||
if (mObjects[i]!= NULL){
|
||||
ActionElement * currentAction = (ActionElement *)mObjects[i];
|
||||
if (currentAction->testDestroy())
|
||||
game->removeObserver(currentAction);
|
||||
game->removeObserver(currentAction);
|
||||
}
|
||||
}
|
||||
int newPhase = game->getCurrentGamePhase();
|
||||
@@ -254,4 +275,5 @@ void ActionLayer::ButtonPressed(int controllerid, int controlid){
|
||||
|
||||
ActionLayer::~ActionLayer(){
|
||||
SAFE_DELETE(abilitiesMenu);
|
||||
cleanGarbage();
|
||||
}
|
||||
|
||||
@@ -117,6 +117,7 @@ void GameObserver::nextGamePhase(){
|
||||
//Auto Hand cleaning, in case the player didn't do it himself
|
||||
while(currentPlayer->game->hand->nb_cards > 7)
|
||||
currentPlayer->game->putInGraveyard(currentPlayer->game->hand->cards[0]);
|
||||
mLayers->actionLayer()->cleanGarbage(); //clean abilities history for this turn;
|
||||
mLayers->stackLayer()->garbageCollect(); //clean stack history for this turn;
|
||||
mLayers->actionLayer()->Update(0);
|
||||
for (int i=0; i < 2; i++){
|
||||
@@ -240,13 +241,8 @@ void GameObserver::addObserver(MTGAbility * observer){
|
||||
|
||||
|
||||
void GameObserver::removeObserver(ActionElement * observer){
|
||||
if (observer)
|
||||
{
|
||||
if (mLayers->actionLayer()->getIndexOf(observer) != -1){
|
||||
observer->destroy();
|
||||
mLayers->actionLayer()->Remove(observer);
|
||||
}
|
||||
}
|
||||
if (observer)mLayers->actionLayer()->moveToGarbage(observer);
|
||||
|
||||
else
|
||||
{} //TODO log error
|
||||
}
|
||||
|
||||
@@ -181,31 +181,22 @@ void GameStateDuel::loadPlayer(int playerId, int decknb, int isAI){
|
||||
|
||||
#ifdef TESTSUITE
|
||||
void GameStateDuel::loadTestSuitePlayers(){
|
||||
OutputDebugString ("loading suite 1\n");
|
||||
if (!testSuite) return;
|
||||
for (int i = 0; i < 2; i++){
|
||||
SAFE_DELETE(mPlayers[i]);
|
||||
SAFE_DELETE(deck[i]);
|
||||
mPlayers[i] = NEW TestSuiteAI(testSuite, i);
|
||||
OutputDebugString ("loading suite 2\n");
|
||||
deck[i] = mPlayers[i]->game;
|
||||
}
|
||||
mParent->gameType = testSuite->gameType;
|
||||
if (game) delete game;
|
||||
game = NULL;
|
||||
if (!game){
|
||||
GameObserver::Init(mPlayers, 2);
|
||||
OutputDebugString ("loading suite 3\n");
|
||||
game = GameObserver::GetInstance();
|
||||
OutputDebugString ("loading suite 4\n");
|
||||
game->startGame(0,0);
|
||||
OutputDebugString ("loading suite 5\n");
|
||||
|
||||
if (mParent->gameType == GAME_TYPE_MOMIR){
|
||||
game->addObserver(NEW MTGMomirRule(-1, mParent->collection));
|
||||
for (int i = 0; i < 2; i++){
|
||||
game->players[i]->life+=4;
|
||||
}
|
||||
SAFE_DELETE(game);
|
||||
GameObserver::Init(mPlayers, 2);
|
||||
game = GameObserver::GetInstance();
|
||||
game->startGame(0,0);
|
||||
if (mParent->gameType == GAME_TYPE_MOMIR){
|
||||
game->addObserver(NEW MTGMomirRule(-1, mParent->collection));
|
||||
for (int i = 0; i < 2; i++){
|
||||
game->players[i]->life+=4;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -405,6 +396,21 @@ void GameStateDuel::Render()
|
||||
JRenderer * r = JRenderer::GetInstance();
|
||||
r->ClearScreen(ARGB(200,0,0,0));
|
||||
credits->Render();
|
||||
#ifdef TESTSUITE
|
||||
if (mParent->players[1] == PLAYER_TYPE_TESTSUITE){
|
||||
r->ClearScreen(ARGB(255,0,0,0));
|
||||
char buf[4096];
|
||||
int nbFailed = testSuite->nbFailed;
|
||||
int nbTests = testSuite->nbTests;
|
||||
if (!nbFailed){
|
||||
sprintf(buf, "All %i tests successful!", nbTests);
|
||||
}else{
|
||||
sprintf(buf, "%i tests out of %i FAILED!", nbFailed, nbTests);
|
||||
}
|
||||
|
||||
mFont->DrawString(buf,0,SCREEN_HEIGHT/2);
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
case DUEL_STATE_ERROR:
|
||||
|
||||
@@ -379,7 +379,11 @@ int TestSuite::assertGame(){
|
||||
}
|
||||
}
|
||||
}
|
||||
if (error) return 0;
|
||||
nbTests++;
|
||||
if (error) {
|
||||
nbFailed++;
|
||||
return 0;
|
||||
}
|
||||
Log("<span class=\"success\">==Test Succesful !==</span>");
|
||||
return 1;
|
||||
}
|
||||
@@ -391,6 +395,8 @@ TestSuite::TestSuite(const char * filename,MTGAllCards* _collection){
|
||||
std::string s;
|
||||
nbfiles = 0;
|
||||
currentfile = 0;
|
||||
nbFailed = 0;
|
||||
nbTests = 0;
|
||||
int comment = 0;
|
||||
if(file){
|
||||
while(std::getline(file,s)){
|
||||
|
||||
Reference in New Issue
Block a user