Hid Subtypes behind MTGAllCards and added a mutex to be able to use both singleton from several threads.
This commit is contained in:
@@ -2506,13 +2506,13 @@ public:
|
||||
size_t found = s.find(" ");
|
||||
if (found != string::npos)
|
||||
{
|
||||
int id = Subtypes::subtypesList->find(s.substr(0, found));
|
||||
int id = MTGAllCards::findType(s.substr(0, found));
|
||||
types.push_back(id);
|
||||
s = s.substr(found + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
int id = Subtypes::subtypesList->find(s);
|
||||
int id = MTGAllCards::findType(s);
|
||||
types.push_back(id);
|
||||
s = "";
|
||||
}
|
||||
@@ -5066,6 +5066,6 @@ public:
|
||||
|
||||
void PopulateColorIndexVector(list<int>& colors, const string& colorsString, char delimiter = ',');
|
||||
void PopulateAbilityIndexVector(list<int>& abilities, const string& abilitiesString, char delimiter = ',');
|
||||
void PopulateSubtypesIndexVector(list<int>& subtypes, const string& subtypesString, char delimiter = ' ');
|
||||
void PopulateSubtypesIndexVector(list<int>& types, const string& subtypesString, char delimiter = ' ');
|
||||
|
||||
#endif
|
||||
|
||||
@@ -7,7 +7,8 @@
|
||||
#include "GameApp.h"
|
||||
#include "WResourceManager.h"
|
||||
#include <dirent.h>
|
||||
|
||||
#include <Threading.h>
|
||||
#include <Subtypes.h>
|
||||
#include <string>
|
||||
|
||||
using std::string;
|
||||
@@ -104,7 +105,6 @@ protected:
|
||||
void init();
|
||||
void initCounters();
|
||||
MTGAllCards();
|
||||
MTGAllCards(const char * config_file, const char * set_name);
|
||||
~MTGAllCards();
|
||||
|
||||
public:
|
||||
@@ -132,11 +132,40 @@ public:
|
||||
int totalCards();
|
||||
int randomCardId();
|
||||
|
||||
static int findType(string subtype, bool forceAdd = true) {
|
||||
boost::mutex::scoped_lock lock(instance->mMutex);
|
||||
return instance->subtypesList.find(subtype, forceAdd);
|
||||
};
|
||||
static int add(string value, unsigned int parentType) {
|
||||
boost::mutex::scoped_lock lock(instance->mMutex);
|
||||
return instance->subtypesList.add(value, parentType);
|
||||
};
|
||||
static string findType(unsigned int id) {
|
||||
return instance->subtypesList.find(id);
|
||||
};
|
||||
static const vector<string>& getValuesById() {
|
||||
return instance->subtypesList.getValuesById();
|
||||
};
|
||||
static bool isSubtypeOfType(unsigned int subtype, unsigned int type) {
|
||||
return instance->subtypesList.isSubtypeOfType(subtype, type);
|
||||
};
|
||||
static bool isSuperType(unsigned int type) {
|
||||
return instance->subtypesList.isSuperType(type);
|
||||
};
|
||||
static bool isType(unsigned int type) {
|
||||
return instance->subtypesList.isType(type);
|
||||
};
|
||||
static bool isSubType(unsigned int type) {
|
||||
return instance->subtypesList.isSubType(type);
|
||||
};
|
||||
|
||||
static void loadInstance();
|
||||
static void unloadAll();
|
||||
static inline MTGAllCards* getInstance() { return instance; };
|
||||
|
||||
private:
|
||||
boost::mutex mMutex;
|
||||
Subtypes subtypesList;
|
||||
map<string, MTGCard *> mtgCardByNameCache;
|
||||
int processConfLine(string &s, MTGCard* card, CardPrimitive * primitive);
|
||||
bool addCardToCollection(MTGCard * card, int setId);
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
|
||||
class Subtypes
|
||||
@@ -37,7 +38,6 @@ protected:
|
||||
vector<string> valuesById;
|
||||
vector<unsigned int> subtypesToType;
|
||||
public:
|
||||
static Subtypes * subtypesList;
|
||||
Subtypes();
|
||||
int find(string subtype, bool forceAdd = true);
|
||||
string find(unsigned int id);
|
||||
|
||||
Reference in New Issue
Block a user