- attempt to ensure color picking ALWAYS has unique colors
- better handling of scenario's that are missing techtrees
This commit is contained in:
parent
8414077d7a
commit
ceb799a66e
|
@ -1121,6 +1121,12 @@ void Game::load(int loadTypes) {
|
|||
world.loadTech( config.getPathListForType(ptTechs,scenarioDir), techName,
|
||||
factions, &checksum,loadedFileList);
|
||||
|
||||
if(world.getTechTree() == NULL || world.getTechTree()->getNameUntranslated() == "") {
|
||||
char szBuf[8096]="";
|
||||
snprintf(szBuf,8096,"Line ref: %d, ERROR: Cannot find techtree: [%s]",__LINE__,techName.c_str());
|
||||
|
||||
throw megaglest_runtime_error(szBuf, true);
|
||||
}
|
||||
// Validate the faction setup to ensure we don't have any bad associations
|
||||
/*
|
||||
std::vector<std::string> results = world.validateFactionTypes();
|
||||
|
|
|
@ -378,7 +378,20 @@ void MenuStateScenario::launchGame() {
|
|||
if(scenarioInfo.file != "" && scenarioInfo.tilesetName != "" && scenarioInfo.mapName != "" && scenarioInfo.techTreeName != "") {
|
||||
GameSettings gameSettings;
|
||||
loadGameSettings(&scenarioInfo, &gameSettings);
|
||||
|
||||
const vector<string> pathTechList = Config::getInstance().getPathListForType(ptTechs,gameSettings.getScenarioDir());
|
||||
if(TechTree::exists(gameSettings.getTech(), pathTechList) == false) {
|
||||
char szBuf[8096]="";
|
||||
snprintf(szBuf,8096,"Line ref: %d Error: cannot find techtree [%s]\n",__LINE__,scenarioInfo.techTreeName.c_str());
|
||||
SystemFlags::OutputDebug(SystemFlags::debugError,szBuf);
|
||||
|
||||
mainMessageBoxState=1;
|
||||
showMessageBox( szBuf, "Error detected", false);
|
||||
|
||||
return;
|
||||
}
|
||||
program->setState(new Game(program, &gameSettings, false));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -174,6 +174,16 @@ Checksum TechTree::loadTech(const string &techName,
|
|||
return techtreeChecksum;
|
||||
}
|
||||
|
||||
bool TechTree::exists(const string &techName, const vector<string> &pathTechList) {
|
||||
bool techFound = false;
|
||||
std::auto_ptr<TechTree> techTree(new TechTree(pathTechList));
|
||||
string path = techTree->findPath(techName);
|
||||
if(path != "") {
|
||||
techFound = true;
|
||||
}
|
||||
return techFound;
|
||||
}
|
||||
|
||||
string TechTree::findPath(const string &techName) const {
|
||||
return findPath(techName,pathList);
|
||||
}
|
||||
|
|
|
@ -68,7 +68,9 @@ public:
|
|||
std::map<string,vector<pair<string, string> > > &loadedFileList,
|
||||
bool validationMode=false);
|
||||
string findPath(const string &techName) const;
|
||||
|
||||
static string findPath(const string &techName, const vector<string> &pathTechList);
|
||||
static bool exists(const string &techName, const vector<string> &pathTechList);
|
||||
|
||||
TechTree(const vector<string> pathList);
|
||||
~TechTree();
|
||||
|
|
|
@ -286,9 +286,12 @@ private:
|
|||
|
||||
static unsigned char nextColorID[COLOR_COMPONENTS];
|
||||
static vector<vector<unsigned char> > nextColorIDReuseList;
|
||||
static map<string,bool> usedColorIDList;
|
||||
static Mutex mutexNextColorID;
|
||||
|
||||
static auto_ptr<PixelBufferWrapper> pbo;
|
||||
|
||||
void assign_color();
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
|
|
|
@ -1830,6 +1830,7 @@ PixelBufferWrapper::~PixelBufferWrapper() {
|
|||
//unsigned char BaseColorPickEntity::nextColorID[COLOR_COMPONENTS] = {1, 1, 1, 1};
|
||||
unsigned char BaseColorPickEntity::nextColorID[COLOR_COMPONENTS] = { 1, 1, 1 };
|
||||
vector<vector<unsigned char> > BaseColorPickEntity::nextColorIDReuseList;
|
||||
map<string,bool> BaseColorPickEntity::usedColorIDList;
|
||||
Mutex BaseColorPickEntity::mutexNextColorID;
|
||||
auto_ptr<PixelBufferWrapper> BaseColorPickEntity::pbo;
|
||||
|
||||
|
@ -1841,6 +1842,16 @@ void BaseColorPickEntity::recycleUniqueColor() {
|
|||
reUseColor.push_back(uniqueColorID[1]);
|
||||
reUseColor.push_back(uniqueColorID[2]);
|
||||
nextColorIDReuseList.push_back(reUseColor);
|
||||
|
||||
if(usedColorIDList.size() > 0) {
|
||||
string color_key = getColorDescription();
|
||||
if(usedColorIDList.find(color_key) != usedColorIDList.end()) {
|
||||
usedColorIDList.erase(color_key);
|
||||
}
|
||||
else {
|
||||
printf("Line ref: %d *WARNING* color [%s] used count: %d NOT FOUND in history list!\n",__LINE__,color_key.c_str(),(int)usedColorIDList.size());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void BaseColorPickEntity::resetUniqueColors() {
|
||||
|
@ -1850,17 +1861,30 @@ void BaseColorPickEntity::resetUniqueColors() {
|
|||
BaseColorPickEntity::nextColorID[1] = 1;
|
||||
BaseColorPickEntity::nextColorID[2] = 1;
|
||||
nextColorIDReuseList.clear();
|
||||
usedColorIDList.clear();
|
||||
}
|
||||
|
||||
BaseColorPickEntity::BaseColorPickEntity() {
|
||||
MutexSafeWrapper safeMutex(&mutexNextColorID);
|
||||
assign_color();
|
||||
}
|
||||
|
||||
void BaseColorPickEntity::assign_color() {
|
||||
if(nextColorIDReuseList.empty() == false) {
|
||||
uniqueColorID[0] = nextColorIDReuseList.back()[0];
|
||||
uniqueColorID[1] = nextColorIDReuseList.back()[1];
|
||||
uniqueColorID[2] = nextColorIDReuseList.back()[2];
|
||||
|
||||
nextColorIDReuseList.pop_back();
|
||||
|
||||
string color_key = getColorDescription();
|
||||
if(usedColorIDList.find(color_key) == usedColorIDList.end()) {
|
||||
usedColorIDList[color_key] = true;
|
||||
}
|
||||
else {
|
||||
printf("Line ref: %d *WARNING* color [%s] ALREADY FOUND in history list!\n",__LINE__,color_key.c_str());
|
||||
assign_color();
|
||||
}
|
||||
}
|
||||
else {
|
||||
uniqueColorID[0] = nextColorID[0];
|
||||
|
@ -1904,6 +1928,15 @@ BaseColorPickEntity::BaseColorPickEntity() {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
string color_key = getColorDescription();
|
||||
if(usedColorIDList.find(color_key) == usedColorIDList.end()) {
|
||||
usedColorIDList[color_key] = true;
|
||||
}
|
||||
else {
|
||||
printf("Line ref: %d *WARNING* color [%s] ALREADY FOUND in history list!\n",__LINE__,color_key.c_str());
|
||||
assign_color();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue