- Replaced static parts by per-instance parts of of several classes when they were not threadsafe (AIMomirPlayer, SimpleMenu, Trash, AIAction, MTGCardInstance, ATutorialMessage, MTGRules). The direct consequence is that we could consumme more memory. So, tell me if you have problems with low memory devices (PSP), there are some threadsafe optimizations that could be implemented if needed.

- Reworked the testsuite to be able to work multithreaded. This is deactivated by default everywhere except in QT_CONFIG as one testcase still refuses to pass in multithreaded mode. On my 4 cores linux desktop, the 650 tests passes now in 4 seconds (1 fails).
- Replaced usage of CardSelectorSingleton by a card selector per game observer.
- Modified the resource manager to be optionnal and per game observer instance instead of being a singleton. Two reasons here : threading AND Open Gl access. I only updated the crashing parts called from the game observer, so most of the code is still using the single instance. Beware of copy-paste concerning resources ...
- Cleaned up the game observer constructors
- Fixed several problems in action logging code while testing proliferate decks
- Cleaned up Threading implementation based on QThread
This commit is contained in:
Xawotihs
2011-11-06 17:31:44 +00:00
parent b0cb955c53
commit e50fdba648
38 changed files with 509 additions and 382 deletions

View File

@@ -6,6 +6,7 @@
#define MAX_TESTSUITE_ACTIONS 100
#define MAX_TESTUITE_CARDS 100
#include "Threading.h"
#include "AIPlayerBaka.h"
class TestSuiteActions
@@ -19,6 +20,7 @@ public:
};
class TestSuiteGame;
class TestSuite;
class TestSuiteAI;
class TestSuiteState
@@ -30,64 +32,87 @@ public:
~TestSuiteState();
vector<TestSuiteAI*> players;
void cleanup(TestSuite*);
void cleanup(TestSuiteGame* tsGame);
};
class TestSuitePregame
class TestSuiteGame
{
friend class TestSuiteAI;
friend class TestSuite;
protected:
string filename;
int summoningSickness;
bool forceAbility;
GameType gameType;
unsigned int seed;
int aiMaxCalls;
TestSuiteState endState;
TestSuiteState initState;
TestSuiteActions actions;
float timerLimit;
bool isOK;
int currentAction;
GameObserver* observer;
static boost::mutex mMutex;
virtual void handleResults(bool wasAI, int error);
TestSuite* testsuite;
bool load();
public:
virtual void performTest() = 0;
~TestSuiteGame();
TestSuiteGame(TestSuite* testsuite);
TestSuiteGame(TestSuite* testsuite, string _filename);
void initGame();
void assertGame();
MTGPlayerCards * buildDeck(Player* player, int playerId);
GameType getGameType() { return gameType; };
string getNextAction();
Interruptible * getActionByMTGId(int mtgid);
static int Log(const char * text);
void setObserver(GameObserver* anObserver) {observer = anObserver; };
};
class TestSuite
class TestSuite : public TestSuiteGame
{
private:
int currentfile;
int nbfiles;
string files[1024];
TestSuiteState endState;
TestSuiteActions actions;
bool forceAbility;
int load(const char * filename);
void cleanup();
public:
/* but only used by the testsuite classes */
float timerLimit;
int aiMaxCalls;
int currentAction;
int summoningSickness;
TestSuiteState initState;
string getNextAction();
MTGPlayerCards * buildDeck(Player*, int playerId);
Interruptible * getActionByMTGId(GameObserver* observer, int mtgid);
int assertGame(GameObserver*);
vector<boost::thread> mWorkerThread;
Rules* mRules;
bool mProcessing;
public:
int startTime, endTime;
GameType gameType;
unsigned int seed;
int nbFailed, nbTests, nbAIFailed, nbAITests;
TestSuite(const char * filename);
void initGame(GameObserver* g);
void pregameTests();
int loadNext();
static int Log(const char * text);
string getNextFile() {
boost::mutex::scoped_lock lock(mMutex);
if (currentfile >= nbfiles) return "";
currentfile++;
return files[currentfile - 1];
};
static void ThreadProc(void* inParam);
void setRules(Rules* rules) {mRules = rules;};
void handleResults(bool wasAI, int error);
};
// TODO This should inherit from AIPlayer instead!
class TestSuiteAI:public AIPlayerBaka
{
private:
MTGCardInstance * getCard(string action);
float timer;
TestSuite * suite;
TestSuiteGame * suite;
public:
TestSuiteAI(GameObserver *observer, TestSuite * suite, int playerId);
TestSuiteAI(TestSuiteGame *tsGame, int playerId);
virtual int Act(float dt);
virtual int displayStack();
bool summoningSickness() {return (suite->summoningSickness == 1); }