attempt to improve threaded logging and see if we fix targetVec

This commit is contained in:
Mark Vejvoda 2013-05-25 05:31:32 +00:00
parent 4d0917e13b
commit 85ab3c76cc
6 changed files with 64 additions and 31 deletions

View File

@ -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<Vec2i> *deleteListPtr) {
void Faction::cleanupResourceTypeTargetCache(std::vector<Vec2i> *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<Vec2i> *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) {

View File

@ -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<Vec2i> *deleteListPtr);
void cleanupResourceTypeTargetCache(std::vector<Vec2i> *deleteListPtr,int frameIndex);
inline int getCacheResourceTargetListSize() const { return cacheResourceTargetList.size(); }
Unit * findClosestUnitWithSkillClass(const Vec2i &pos,const CommandClass &cmdClass,

View File

@ -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<float>(curPosValue.x);
v.z= static_cast<float>(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<float>(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<float>(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<float>(height);
}
}
}

View File

@ -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<float>(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<float>(heightFactor);
}
waterLevel= static_cast<float>((header.waterLevel-0.01f)/heightFactor);
waterLevel = truncateDecimal<float>(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<float>((header.version2.cliffLevel-0.01f)/(heightFactor));
cliffLevel = truncateDecimal<float>(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) {

View File

@ -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<float>(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<float>(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<float>(heightFactor);}
inline float getWaterLevel() const {return truncateDecimal<float>(waterLevel);}
inline float getCliffLevel() const {return truncateDecimal<float>(cliffLevel);}
inline int getCameraHeight() const {return cameraHeight;}
inline float getMaxMapHeight() const {return maxMapHeight;}
inline float getMaxMapHeight() const {return truncateDecimal<float>(maxMapHeight);}
Vec2i getStartLocation(int locationIndex) const;
inline bool getSubmerged(const SurfaceCell *sc) const {return sc->getHeight()<waterLevel;}
inline bool getSubmerged(const Cell *c) const {return c->getHeight()<waterLevel;}
@ -321,7 +321,7 @@ public:
inline bool isInsideSurface(const Vec2i &sPos) const {
return isInsideSurface(sPos.x, sPos.y);
}
bool isResourceNear(const Vec2i &pos, const ResourceType *rt, Vec2i &resourcePos, int size, Unit *unit=NULL,bool fallbackToPeersHarvestingSameResource=false,Vec2i *resourceClickPos=NULL) const;
bool isResourceNear(int frameIndex,const Vec2i &pos, const ResourceType *rt, Vec2i &resourcePos, int size, Unit *unit=NULL,bool fallbackToPeersHarvestingSameResource=false,Vec2i *resourceClickPos=NULL) const;
//free cells
bool isFreeCell(const Vec2i &pos, Field field) const;

View File

@ -1221,10 +1221,10 @@ void UnitUpdater::updateHarvest(Unit *unit, int frameIndex) {
bool isNearResource = false;
Vec2i clickPos = command->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;