- more code cleanup and game lobby force refresh bugfix when data changes

This commit is contained in:
Mark Vejvoda 2013-09-19 01:19:36 +00:00
parent 3a5c99bca5
commit d4a6645a4d
7 changed files with 112 additions and 23 deletions

View File

@ -875,7 +875,7 @@ void AiRuleProduce::produceGenericNew(const ProduceTask *pt) {
if(r != NULL && r->getAmount() < 0) {
if(aiInterface->reqsOk(ct) && aiInterface->reqsOk(producedUnit)){
produceIt= true;
//produceIt= true;
addUnitTypeToCandidates(producedUnit, ableUnits,ableUnitsGiveBack, false);
}
}

View File

@ -128,16 +128,16 @@ void PathFinder::removeUnitPrecache(Unit *unit) {
MutexSafeWrapper safeMutex(factionMutex,mutexOwnerId);
if(unit != NULL && factions.size() > unit->getFactionIndex()) {
bool clearTravelState = false;
bool clearPath = false;
//bool clearTravelState = false;
//bool clearPath = false;
if(factions[unit->getFactionIndex()].precachedTravelState.find(unit->getId()) != factions[unit->getFactionIndex()].precachedTravelState.end()) {
factions[unit->getFactionIndex()].precachedTravelState.erase(unit->getId());
clearTravelState = true;
//clearTravelState = true;
}
if(factions[unit->getFactionIndex()].precachedPath.find(unit->getId()) != factions[unit->getFactionIndex()].precachedPath.end()) {
factions[unit->getFactionIndex()].precachedPath.erase(unit->getId());
clearPath = true;
//clearPath = true;
}
// if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true) {

View File

@ -1068,7 +1068,7 @@ bool CoreData::loadGameSettingsFromFile(std::string fileName, GameSettings *game
uint32 valueFlags1 = gameSettings->getFlagTypes1();
if(Config::getInstance().getBool("EnableNetworkGameSynchChecks","false") == true) {
printf("*WARNING* - EnableNetworkGameSynchChecks is enabled\n");
//printf("*WARNING* - EnableNetworkGameSynchChecks is enabled\n");
valueFlags1 |= ft1_network_synch_checks;
gameSettings->setFlagTypes1(valueFlags1);

View File

@ -3183,7 +3183,7 @@ void MenuStateCustomGame::loadGameSettings(GameSettings *gameSettings,bool force
}
if(Config::getInstance().getBool("EnableNetworkGameSynchChecks","false") == true) {
printf("*WARNING* - EnableNetworkGameSynchChecks is enabled\n");
//printf("*WARNING* - EnableNetworkGameSynchChecks is enabled\n");
valueFlags1 |= ft1_network_synch_checks;
gameSettings->setFlagTypes1(valueFlags1);
@ -3381,7 +3381,7 @@ void MenuStateCustomGame::loadGameSettings(GameSettings *gameSettings,bool force
if(checkNetworkPlayerDataSynch(false,false,true) == false &&
last_Forced_CheckedCRCTechtreeName != gameSettings->getTech()) {
lastCheckedCRCTechtreeName = "";
bool forceRefresh = true;
forceRefresh = true;
last_Forced_CheckedCRCTechtreeName = gameSettings->getTech();
}
@ -3421,7 +3421,7 @@ void MenuStateCustomGame::loadGameSettings(GameSettings *gameSettings,bool force
if(checkNetworkPlayerDataSynch(true,false,false) == false &&
last_Forced_CheckedCRCMapName != gameSettings->getMap()) {
lastCheckedCRCMapName = "";
bool forceRefresh = true;
forceRefresh = true;
last_Forced_CheckedCRCMapName = gameSettings->getMap();
}

View File

@ -2323,18 +2323,21 @@ string Faction::getCRC_DetailsForWorldFrame(int worldFrameCount) {
return crcWorldFrameDetails[worldFrameCount];
}
std::pair<int,string> Faction::getCRC_DetailsForWorldFrameIndex(int worldFrameIndex) {
std::pair<int,string> Faction::getCRC_DetailsForWorldFrameIndex(int worldFrameIndex) const {
if(crcWorldFrameDetails.empty()) {
return make_pair<int,string>(0,"");
}
std::map<int,string>::iterator iterMap = crcWorldFrameDetails.begin();
std::map<int,string>::const_iterator iterMap = crcWorldFrameDetails.begin();
std::advance( iterMap, worldFrameIndex );
if(iterMap == crcWorldFrameDetails.end()) {
return make_pair<int,string>(0,"");
}
return make_pair<int,string>(iterMap->first,iterMap->second);
}
string Faction::getCRC_DetailsForWorldFrames() {
string Faction::getCRC_DetailsForWorldFrames() const {
string result = "";
for(std::map<int,string>::iterator iterMap = crcWorldFrameDetails.begin();
for(std::map<int,string>::const_iterator iterMap = crcWorldFrameDetails.begin();
iterMap != crcWorldFrameDetails.end(); ++iterMap) {
result += string("============================================================================\n");
result += string("** world frame: ") + intToStr(iterMap->first) + string(" detail: ") + iterMap->second;
@ -2342,7 +2345,7 @@ string Faction::getCRC_DetailsForWorldFrames() {
return result;
}
uint64 Faction:: getCRC_DetailsForWorldFrameCount() {
uint64 Faction::getCRC_DetailsForWorldFrameCount() const {
return crcWorldFrameDetails.size();
}

View File

@ -374,9 +374,9 @@ public:
Checksum getCRC();
void addCRC_DetailsForWorldFrame(int worldFrameCount,bool isNetworkServer);
string getCRC_DetailsForWorldFrame(int worldFrameCount);
std::pair<int,string> getCRC_DetailsForWorldFrameIndex(int worldFrameIndex);
string getCRC_DetailsForWorldFrames();
uint64 getCRC_DetailsForWorldFrameCount();
std::pair<int,string> getCRC_DetailsForWorldFrameIndex(int worldFrameIndex) const;
string getCRC_DetailsForWorldFrames() const;
uint64 getCRC_DetailsForWorldFrameCount() const;
private:
void init();

View File

@ -1062,29 +1062,64 @@ void Pixmap2D::savePng(const string &path) {
void Pixmap2D::getPixel(int x, int y, uint8 *value) const {
for(int i=0; i<components; ++i){
value[i]= pixels[(w*y+x)*components+i];
int index = (w*y+x)*components+i;
if(index >= getPixelByteCount()) {
char szBuf[8096];
snprintf(szBuf,8096,"Invalid pixmap index: %d for [%s], h = %d, w = %d, components = %d x = %d y = %d\n",index,path.c_str(),h,w,components,x,y);
throw megaglest_runtime_error(szBuf);
}
value[i]= pixels[index];
}
}
void Pixmap2D::getPixel(int x, int y, float32 *value) const {
for(int i=0; i<components; ++i) {
value[i]= pixels[(w*y+x)*components+i]/255.f;
int index = (w*y+x)*components+i;
if(index >= getPixelByteCount()) {
char szBuf[8096];
snprintf(szBuf,8096,"Invalid pixmap index: %d for [%s], h = %d, w = %d, components = %d x = %d y = %d\n",index,path.c_str(),h,w,components,x,y);
throw megaglest_runtime_error(szBuf);
}
value[i]= pixels[index]/255.f;
}
}
void Pixmap2D::getComponent(int x, int y, int component, uint8 &value) const {
value= pixels[(w*y+x)*components+component];
int index = (w*y+x)*components+component;
if(index >= getPixelByteCount()) {
char szBuf[8096];
snprintf(szBuf,8096,"Invalid pixmap index: %d for [%s], h = %d, w = %d, components = %d x = %d y = %d\n",index,path.c_str(),h,w,components,x,y);
throw megaglest_runtime_error(szBuf);
}
value= pixels[index];
}
void Pixmap2D::getComponent(int x, int y, int component, float32 &value) const {
value= pixels[(w*y+x)*components+component]/255.f;
int index = (w*y+x)*components+component;
if(index >= getPixelByteCount()) {
char szBuf[8096];
snprintf(szBuf,8096,"Invalid pixmap index: %d for [%s], h = %d, w = %d, components = %d x = %d y = %d\n",index,path.c_str(),h,w,components,x,y);
throw megaglest_runtime_error(szBuf);
}
value= pixels[index]/255.f;
}
//vector get
Vec4f Pixmap2D::getPixel4f(int x, int y) const {
Vec4f v(0.f);
for(int i=0; i<components && i<4; ++i){
v.ptr()[i]= pixels[(w*y+x)*components+i]/255.f;
int index = (w*y+x)*components+i;
if(index >= getPixelByteCount()) {
char szBuf[8096];
snprintf(szBuf,8096,"Invalid pixmap index: %d for [%s], h = %d, w = %d, components = %d x = %d y = %d\n",index,path.c_str(),h,w,components,x,y);
throw megaglest_runtime_error(szBuf);
}
v.ptr()[i]= pixels[index]/255.f;
}
return v;
}
@ -1092,13 +1127,25 @@ Vec4f Pixmap2D::getPixel4f(int x, int y) const {
Vec3f Pixmap2D::getPixel3f(int x, int y) const {
Vec3f v(0.f);
for(int i=0; i<components && i<3; ++i){
v.ptr()[i]= pixels[(w*y+x)*components+i]/255.f;
int index = (w*y+x)*components+i;
if(index >= getPixelByteCount()) {
char szBuf[8096];
snprintf(szBuf,8096,"Invalid pixmap index: %d for [%s], h = %d, w = %d, components = %d x = %d y = %d\n",index,path.c_str(),h,w,components,x,y);
throw megaglest_runtime_error(szBuf);
}
v.ptr()[i]= pixels[index]/255.f;
}
return v;
}
float Pixmap2D::getPixelf(int x, int y) const {
int index = (w*y+x)*components;
if(index >= getPixelByteCount()) {
char szBuf[8096];
snprintf(szBuf,8096,"Invalid pixmap index: %d for [%s], h = %d, w = %d, components = %d x = %d y = %d\n",index,path.c_str(),h,w,components,x,y);
throw megaglest_runtime_error(szBuf);
}
return pixels[index]/255.f;
}
@ -1111,6 +1158,12 @@ float Pixmap2D::getComponentf(int x, int y, int component) const {
void Pixmap2D::setPixel(int x, int y, const uint8 *value) {
for(int i=0; i<components; ++i) {
int index = (w*y+x)*components+i;
if(index >= getPixelByteCount()) {
char szBuf[8096];
snprintf(szBuf,8096,"Invalid pixmap index: %d for [%s], h = %d, w = %d, components = %d x = %d y = %d\n",index,path.c_str(),h,w,components,x,y);
throw megaglest_runtime_error(szBuf);
}
pixels[index]= value[i];
}
CalculatePixelsCRC(pixels,getPixelByteCount(), crc);
@ -1119,6 +1172,11 @@ void Pixmap2D::setPixel(int x, int y, const uint8 *value) {
void Pixmap2D::setPixel(int x, int y, const float32 *value) {
for(int i=0; i<components; ++i) {
int index = (w*y+x)*components+i;
if(index >= getPixelByteCount()) {
char szBuf[8096];
snprintf(szBuf,8096,"Invalid pixmap index: %d for [%s], h = %d, w = %d, components = %d x = %d y = %d\n",index,path.c_str(),h,w,components,x,y);
throw megaglest_runtime_error(szBuf);
}
pixels[index]= static_cast<uint8>(value[i]*255.f);
}
CalculatePixelsCRC(pixels,getPixelByteCount(), crc);
@ -1126,12 +1184,24 @@ void Pixmap2D::setPixel(int x, int y, const float32 *value) {
void Pixmap2D::setComponent(int x, int y, int component, uint8 value) {
int index = (w*y+x)*components+component;
if(index >= getPixelByteCount()) {
char szBuf[8096];
snprintf(szBuf,8096,"Invalid pixmap index: %d for [%s], h = %d, w = %d, components = %d x = %d y = %d\n",index,path.c_str(),h,w,components,x,y);
throw megaglest_runtime_error(szBuf);
}
pixels[index] = value;
CalculatePixelsCRC(pixels,getPixelByteCount(), crc);
}
void Pixmap2D::setComponent(int x, int y, int component, float32 value) {
int index = (w*y+x)*components+component;
if(index >= getPixelByteCount()) {
char szBuf[8096];
snprintf(szBuf,8096,"Invalid pixmap index: %d for [%s], h = %d, w = %d, components = %d x = %d y = %d\n",index,path.c_str(),h,w,components,x,y);
throw megaglest_runtime_error(szBuf);
}
pixels[index]= static_cast<uint8>(value*255.f);
CalculatePixelsCRC(pixels,getPixelByteCount(), crc);
}
@ -1140,6 +1210,11 @@ void Pixmap2D::setComponent(int x, int y, int component, float32 value) {
void Pixmap2D::setPixel(int x, int y, const Vec3f &p) {
for(int i = 0; i < components && i < 3; ++i) {
int index = (w*y+x)*components+i;
if(index >= getPixelByteCount()) {
char szBuf[8096];
snprintf(szBuf,8096,"Invalid pixmap index: %d for [%s], h = %d, w = %d, components = %d x = %d y = %d\n",index,path.c_str(),h,w,components,x,y);
throw megaglest_runtime_error(szBuf);
}
pixels[index]= static_cast<uint8>(p.ptr()[i]*255.f);
}
CalculatePixelsCRC(pixels,getPixelByteCount(), crc);
@ -1148,6 +1223,11 @@ void Pixmap2D::setPixel(int x, int y, const Vec3f &p) {
void Pixmap2D::setPixel(int x, int y, const Vec4f &p) {
for(int i = 0; i < components && i < 4; ++i) {
int index = (w*y+x)*components+i;
if(index >= getPixelByteCount()) {
char szBuf[8096];
snprintf(szBuf,8096,"Invalid pixmap index: %d for [%s], h = %d, w = %d, components = %d x = %d y = %d\n",index,path.c_str(),h,w,components,x,y);
throw megaglest_runtime_error(szBuf);
}
pixels[index]= static_cast<uint8>(p.ptr()[i]*255.f);
}
CalculatePixelsCRC(pixels,getPixelByteCount(), crc);
@ -1155,6 +1235,12 @@ void Pixmap2D::setPixel(int x, int y, const Vec4f &p) {
void Pixmap2D::setPixel(int x, int y, float p) {
int index = (w*y+x)*components;
if(index >= getPixelByteCount()) {
char szBuf[8096];
snprintf(szBuf,8096,"Invalid pixmap index: %d for [%s], h = %d, w = %d, components = %d x = %d y = %d\n",index,path.c_str(),h,w,components,x,y);
throw megaglest_runtime_error(szBuf);
}
pixels[index]= static_cast<uint8>(p*255.f);
CalculatePixelsCRC(pixels,getPixelByteCount(), crc);
}