diff --git a/source/glest_game/type_instances/faction.cpp b/source/glest_game/type_instances/faction.cpp index ff4d2e0a..9d6856b3 100644 --- a/source/glest_game/type_instances/faction.cpp +++ b/source/glest_game/type_instances/faction.cpp @@ -1315,7 +1315,7 @@ void Faction::addCloseResourceTargetToCache(const Vec2i &pos) { } } -Vec2i Faction::getClosestResourceTypeTargetFromCache(Unit *unit, const ResourceType *type) { +Vec2i Faction::getClosestResourceTypeTargetFromCache(Unit *unit, const ResourceType *type, int frameIndex) { Vec2i result(-1); if(cachingDisabled == false) { @@ -1422,10 +1422,15 @@ Vec2i Faction::getClosestResourceTypeTargetFromCache(Unit *unit, const ResourceT snprintf(szBuf,8096,"[cleaning old resource targets] deleteList.size() [" MG_SIZE_T_SPECIFIER "] cacheResourceTargetList.size() [" MG_SIZE_T_SPECIFIER "] result [%s]", deleteList.size(),cacheResourceTargetList.size(),result.getString().c_str()); - unit->logSynchData(__FILE__,__LINE__,szBuf); + if(frameIndex < 0) { + unit->logSynchData(__FILE__,__LINE__,szBuf); + } + else { + unit->logSynchDataThreaded(__FILE__,__LINE__,szBuf); + } } - cleanupResourceTypeTargetCache(&deleteList); + cleanupResourceTypeTargetCache(&deleteList,frameIndex); } } } @@ -1534,7 +1539,7 @@ Vec2i Faction::getClosestResourceTypeTargetFromCache(const Vec2i &pos, const Res return result; } -void Faction::cleanupResourceTypeTargetCache(std::vector *deleteListPtr) { +void Faction::cleanupResourceTypeTargetCache(std::vector *deleteListPtr,int frameIndex) { if(cachingDisabled == false) { if(cacheResourceTargetList.empty() == false) { const int cleanupInterval = (GameConstants::updateFps * 5); @@ -1569,10 +1574,26 @@ void Faction::cleanupResourceTypeTargetCache(std::vector *deleteListPtr) snprintf(szBuf,8096,"[cleaning old resource targets] deleteList.size() [" MG_SIZE_T_SPECIFIER "] cacheResourceTargetList.size() [" MG_SIZE_T_SPECIFIER "], needToCleanup [%d]", deleteList.size(),cacheResourceTargetList.size(),needToCleanup); //unit->logSynchData(szBuf); - SystemFlags::OutputDebug(SystemFlags::debugWorldSynch,"----------------------------------- START [%d] ------------------------------------------------\n",getFrameCount()); - SystemFlags::OutputDebug(SystemFlags::debugWorldSynch,"[%s::%d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__); - SystemFlags::OutputDebug(SystemFlags::debugWorldSynch,"%s\n",szBuf); - SystemFlags::OutputDebug(SystemFlags::debugWorldSynch,"------------------------------------ END [%d] -------------------------------------------------\n",getFrameCount()); + + char szBuf1[8096]=""; + snprintf(szBuf1,8096,"----------------------------------- START [%d] ------------------------------------------------\n",getFrameCount()); + string logDataText = szBuf1; + + snprintf(szBuf1,8096,"[%s::%d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__); + logDataText += szBuf1; + + snprintf(szBuf1,8096,"%s\n",szBuf); + logDataText += szBuf1; + + snprintf(szBuf1,8096,"------------------------------------ END [%d] -------------------------------------------------\n",getFrameCount()); + logDataText += szBuf1; + + if(frameIndex < 0) { + SystemFlags::OutputDebug(SystemFlags::debugWorldSynch,"%s",logDataText.c_str()); + } + else { + addWorldSynchThreadedLogList(logDataText); + } } for(int i = 0; i < deleteList.size(); ++i) { diff --git a/source/glest_game/type_instances/faction.h b/source/glest_game/type_instances/faction.h index 82151487..46bb76b5 100644 --- a/source/glest_game/type_instances/faction.h +++ b/source/glest_game/type_instances/faction.h @@ -335,9 +335,9 @@ public: void addResourceTargetToCache(const Vec2i &pos,bool incrementUseCounter=true); void removeResourceTargetFromCache(const Vec2i &pos); void addCloseResourceTargetToCache(const Vec2i &pos); - Vec2i getClosestResourceTypeTargetFromCache(Unit *unit, const ResourceType *type); + Vec2i getClosestResourceTypeTargetFromCache(Unit *unit, const ResourceType *type,int frameIndex); Vec2i getClosestResourceTypeTargetFromCache(const Vec2i &pos, const ResourceType *type); - void cleanupResourceTypeTargetCache(std::vector *deleteListPtr); + void cleanupResourceTypeTargetCache(std::vector *deleteListPtr,int frameIndex); inline int getCacheResourceTargetListSize() const { return cacheResourceTargetList.size(); } Unit * findClosestUnitWithSkillClass(const Vec2i &pos,const CommandClass &cmdClass, diff --git a/source/glest_game/type_instances/unit.cpp b/source/glest_game/type_instances/unit.cpp index 5161aeb0..3c3bb7c7 100644 --- a/source/glest_game/type_instances/unit.cpp +++ b/source/glest_game/type_instances/unit.cpp @@ -1351,13 +1351,13 @@ Vec3f Unit::getVectorFlat(const Vec2i &lastPosValue, const Vec2i &curPosValue) c v.z= lastPosValue.y + getProgessAsFloat() * (curPosValue.y - lastPosValue.y); v.y= y1 + getProgessAsFloat() * (y2-y1); } - else{ + else { v.x= static_cast(curPosValue.x); v.z= static_cast(curPosValue.y); v.y= y2; } - v.x+= type->getSize()/2.f-0.5f; - v.z+= type->getSize()/2.f-0.5f; + v.x += type->getSize() / 2.f - 0.5f; + v.z += type->getSize() / 2.f - 0.5f; return v; } @@ -2975,7 +2975,7 @@ bool Unit::morph(const MorphCommandType *mct){ // ==================== PRIVATE ==================== -float Unit::computeHeight(const Vec2i &pos) const{ +float Unit::computeHeight(const Vec2i &pos) const { //printf("CRASHING FOR UNIT: %d alive = %d\n",this->getId(),this->isAlive()); //printf("[%s]\n",this->getType()->getName().c_str()); if(map->isInside(pos) == false || map->isInsideSurface(map->toSurfCoords(pos)) == false) { @@ -2988,16 +2988,19 @@ float Unit::computeHeight(const Vec2i &pos) const{ if(currField == fAir) { height += World::airHeight; + height = truncateDecimal(height); Unit *unit = map->getCell(pos)->getUnit(fLand); if(unit != NULL && unit->getType()->getHeight() > World::airHeight) { height += (std::min((float)unit->getType()->getHeight(),World::airHeight * 3) - World::airHeight); + height = truncateDecimal(height); } else { SurfaceCell *sc = map->getSurfaceCell(map->toSurfCoords(pos)); if(sc != NULL && sc->getObject() != NULL && sc->getObject()->getType() != NULL) { if(sc->getObject()->getType()->getHeight() > World::airHeight) { height += (std::min((float)sc->getObject()->getType()->getHeight(),World::airHeight * 3) - World::airHeight); + height = truncateDecimal(height); } } } diff --git a/source/glest_game/world/map.cpp b/source/glest_game/world/map.cpp index b9635c1a..acace77e 100644 --- a/source/glest_game/world/map.cpp +++ b/source/glest_game/world/map.cpp @@ -93,7 +93,7 @@ void Cell::saveGame(XmlNode *rootNode, int index) const { } // float height; - cellNode->addAttribute("height",floatToStr(height,16), mapTagReplacements); + cellNode->addAttribute("height",floatToStr(getHeight(),16), mapTagReplacements); } } @@ -157,6 +157,7 @@ void SurfaceCell::deleteResource() { } void SurfaceCell::setHeight(float height, bool cellChangedFromOriginalMapLoadValue) { + height = truncateDecimal(height); vertex.y= height; if(cellChangedFromOriginalMapLoadValue == true) { this->cellChangedFromOriginalMapLoad = true; @@ -373,8 +374,10 @@ Checksum Map::load(const string &path, TechTree *techTree, Tileset *tileset) { heightFactor= header.heightFactor; if(heightFactor>100){ heightFactor=heightFactor/100; + heightFactor = truncateDecimal(heightFactor); } waterLevel= static_cast((header.waterLevel-0.01f)/heightFactor); + waterLevel = truncateDecimal(waterLevel); title= header.title; maxPlayers= header.maxFactions; @@ -393,9 +396,9 @@ Checksum Map::load(const string &path, TechTree *techTree, Tileset *tileset) { //desc = header.version2.short_desc; if(header.version2.cliffLevel > 0 && header.version2.cliffLevel < 5000){ cliffLevel=static_cast((header.version2.cliffLevel-0.01f)/(heightFactor)); + cliffLevel = truncateDecimal(cliffLevel); } - if(header.version2.cameraHeight > 0 && header.version2.cameraHeight < 5000) - { + if(header.version2.cameraHeight > 0 && header.version2.cameraHeight < 5000) { cameraHeight = header.version2.cameraHeight; } } @@ -532,7 +535,7 @@ public: }; //returns if there is a resource next to a unit, in "resourcePos" is stored the relative position of the resource -bool Map::isResourceNear(const Vec2i &pos, const ResourceType *rt, Vec2i &resourcePos, +bool Map::isResourceNear(int frameIndex,const Vec2i &pos, const ResourceType *rt, Vec2i &resourcePos, int size, Unit *unit, bool fallbackToPeersHarvestingSameResource, Vec2i *resourceClickPos) const { @@ -606,7 +609,7 @@ bool Map::isResourceNear(const Vec2i &pos, const ResourceType *rt, Vec2i &resour // Check the faction cache for a known position where we can harvest // this resource type - Vec2i result = unit->getFaction()->getClosestResourceTypeTargetFromCache(unit, rt); + Vec2i result = unit->getFaction()->getClosestResourceTypeTargetFromCache(unit, rt,frameIndex); if(result.x >= 0) { resourcePos = result; @@ -614,7 +617,13 @@ bool Map::isResourceNear(const Vec2i &pos, const ResourceType *rt, Vec2i &resour char szBuf[8096]=""; snprintf(szBuf,8096,"[found peer harvest pos] pos [%s] resourcePos [%s] unit->getFaction()->getCacheResourceTargetListSize() [%d]", pos.getString().c_str(),resourcePos.getString().c_str(),unit->getFaction()->getCacheResourceTargetListSize()); - unit->logSynchData(__FILE__,__LINE__,szBuf); + + if(frameIndex < 0) { + unit->logSynchData(__FILE__,__LINE__,szBuf); + } + else { + unit->logSynchDataThreaded(__FILE__,__LINE__,szBuf); + } } if(unit->getPos().dist(resourcePos) <= size) { diff --git a/source/glest_game/world/map.h b/source/glest_game/world/map.h index 71de63eb..bdb49dd3 100644 --- a/source/glest_game/world/map.h +++ b/source/glest_game/world/map.h @@ -70,11 +70,11 @@ public: //get inline Unit *getUnit(int field) const { if(field >= fieldCount) { throw megaglest_runtime_error("Invalid field value" + intToStr(field));} return units[field];} inline Unit *getUnitWithEmptyCellMap(int field) const { if(field >= fieldCount) { throw megaglest_runtime_error("Invalid field value" + intToStr(field));} return unitsWithEmptyCellMap[field];} - inline float getHeight() const {return height;} + inline float getHeight() const {return truncateDecimal(height);} inline void setUnit(int field, Unit *unit) { if(field >= fieldCount) { throw megaglest_runtime_error("Invalid field value" + intToStr(field));} units[field]= unit;} inline void setUnitWithEmptyCellMap(int field, Unit *unit) { if(field >= fieldCount) { throw megaglest_runtime_error("Invalid field value" + intToStr(field));} unitsWithEmptyCellMap[field]= unit;} - inline void setHeight(float height) {this->height= height;} + inline void setHeight(float height) {this->height = truncateDecimal(height);} inline bool isFree(Field field) const { Unit *unit = getUnit(field); @@ -295,12 +295,12 @@ public: inline int getH() const {return h;} inline int getSurfaceW() const {return surfaceW;} inline int getSurfaceH() const {return surfaceH;} - inline int getMaxPlayers() const {return maxPlayers;} - inline float getHeightFactor() const {return heightFactor;} - inline float getWaterLevel() const {return waterLevel;} - inline float getCliffLevel() const {return cliffLevel;} + inline int getMaxPlayers() const {return maxPlayers;} + inline float getHeightFactor() const {return truncateDecimal(heightFactor);} + inline float getWaterLevel() const {return truncateDecimal(waterLevel);} + inline float getCliffLevel() const {return truncateDecimal(cliffLevel);} inline int getCameraHeight() const {return cameraHeight;} - inline float getMaxMapHeight() const {return maxMapHeight;} + inline float getMaxMapHeight() const {return truncateDecimal(maxMapHeight);} Vec2i getStartLocation(int locationIndex) const; inline bool getSubmerged(const SurfaceCell *sc) const {return sc->getHeight()getHeight()getOriginalPos(); if(newHarvestPath == true) { - isNearResource = map->isResourceNear(unit->getPos(), r->getType(), targetPos,unit->getType()->getSize(),unit, false,&clickPos); + isNearResource = map->isResourceNear(frameIndex,unit->getPos(), r->getType(), targetPos,unit->getType()->getSize(),unit, false,&clickPos); } else { - isNearResource = map->isResourceNear(unit->getPos(), r->getType(), targetPos,unit->getType()->getSize(),unit); + isNearResource = map->isResourceNear(frameIndex,unit->getPos(), r->getType(), targetPos,unit->getType()->getSize(),unit); } if(isNearResource == true) { if((unit->getPos().dist(command->getPos()) < harvestDistance || unit->getPos().dist(targetPos) < harvestDistance) && isNearResource == true) { @@ -1350,7 +1350,7 @@ void UnitUpdater::updateHarvest(Unit *unit, int frameIndex) { switch(this->game->getGameSettings()->getPathFinderType()) { case pfBasic: { - bool isNearResource = map->isResourceNear(unit->getPos(), r->getType(), targetPos,unit->getType()->getSize(),unit,true); + bool isNearResource = map->isResourceNear(frameIndex,unit->getPos(), r->getType(), targetPos,unit->getType()->getSize(),unit,true); if(isNearResource == true) { if((unit->getPos().dist(command->getPos()) < harvestDistance || unit->getPos().dist(targetPos) < harvestDistance) && isNearResource == true) { canHarvestDestPos = true;