- attempt to fix additional oos issues

This commit is contained in:
Mark Vejvoda 2013-09-28 05:06:04 +00:00
parent 91b7803270
commit 9967df316c
13 changed files with 98 additions and 112 deletions

View File

@ -995,7 +995,7 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
const Vec2i unitPos = unit->getPos(); const Vec2i unitPos = unit->getPos();
const Vec2i finalPos= computeNearestFreePos(unit, targetPos); const Vec2i finalPos= computeNearestFreePos(unit, targetPos);
float dist= unitPos.dist(finalPos); double dist= unitPos.dist(finalPos);
factions[unitFactionIndex].useMaxNodeCount = PathFinder::pathFindNodesMax; factions[unitFactionIndex].useMaxNodeCount = PathFinder::pathFindNodesMax;
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled == true && chrono.getMillis() > 4) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis()); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled == true && chrono.getMillis() > 4) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis());
@ -1352,7 +1352,7 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
//if consumed all nodes find best node (to avoid strange behaviour) //if consumed all nodes find best node (to avoid strange behaviour)
if(nodeLimitReached == true) { if(nodeLimitReached == true) {
if(factions[unitFactionIndex].closedNodesList.size() > 0) { if(factions[unitFactionIndex].closedNodesList.size() > 0) {
float bestHeuristic = factions[unitFactionIndex].closedNodesList.begin()->first; double bestHeuristic = factions[unitFactionIndex].closedNodesList.begin()->first;
if(bestHeuristic < lastNode->heuristic) { if(bestHeuristic < lastNode->heuristic) {
lastNode= factions[unitFactionIndex].closedNodesList.begin()->second[0]; lastNode= factions[unitFactionIndex].closedNodesList.begin()->second[0];
} }
@ -1520,10 +1520,10 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
return ts; return ts;
} }
void PathFinder::processNearestFreePos(const Vec2i &finalPos, int i, int j, int size, Field field, int teamIndex,Vec2i unitPos, Vec2i &nearestPos, float &nearestDist) { void PathFinder::processNearestFreePos(const Vec2i &finalPos, int i, int j, int size, Field field, int teamIndex,Vec2i unitPos, Vec2i &nearestPos, double &nearestDist) {
Vec2i currPos= finalPos + Vec2i(i, j); Vec2i currPos= finalPos + Vec2i(i, j);
if(map->isAproxFreeCells(currPos, size, field, teamIndex)) { if(map->isAproxFreeCells(currPos, size, field, teamIndex)) {
float dist= currPos.dist(finalPos); double dist= currPos.dist(finalPos);
//if nearer from finalPos //if nearer from finalPos
if(dist < nearestDist){ if(dist < nearestDist){
@ -1557,7 +1557,7 @@ Vec2i PathFinder::computeNearestFreePos(const Unit *unit, const Vec2i &finalPos)
//find nearest pos //find nearest pos
Vec2i unitPos= unit->getPosNotThreadSafe(); Vec2i unitPos= unit->getPosNotThreadSafe();
Vec2i nearestPos= unitPos; Vec2i nearestPos= unitPos;
float nearestDist= unitPos.dist(finalPos); double nearestDist= unitPos.dist(finalPos);
for(int i= -maxFreeSearchRadius; i <= maxFreeSearchRadius; ++i) { for(int i= -maxFreeSearchRadius; i <= maxFreeSearchRadius; ++i) {
for(int j= -maxFreeSearchRadius; j <= maxFreeSearchRadius; ++j) { for(int j= -maxFreeSearchRadius; j <= maxFreeSearchRadius; ++j) {
@ -1639,7 +1639,7 @@ void PathFinder::saveGame(XmlNode *rootNode) {
nodePoolNode->addAttribute("next",intToStr(nextIdx), mapTagReplacements); nodePoolNode->addAttribute("next",intToStr(nextIdx), mapTagReplacements);
int prevIdx = findNodeIndex(curNode->prev, factionState.nodePool); int prevIdx = findNodeIndex(curNode->prev, factionState.nodePool);
nodePoolNode->addAttribute("prev",intToStr(prevIdx), mapTagReplacements); nodePoolNode->addAttribute("prev",intToStr(prevIdx), mapTagReplacements);
nodePoolNode->addAttribute("heuristic",floatToStr(curNode->heuristic,16), mapTagReplacements); nodePoolNode->addAttribute("heuristic",doubleToStr(curNode->heuristic,16), mapTagReplacements);
nodePoolNode->addAttribute("exploredCell",intToStr(curNode->exploredCell), mapTagReplacements); nodePoolNode->addAttribute("exploredCell",intToStr(curNode->exploredCell), mapTagReplacements);
} }

View File

@ -95,7 +95,7 @@ public:
Vec2i pos; Vec2i pos;
Node *next; Node *next;
Node *prev; Node *prev;
float heuristic; double heuristic;
bool exploredCell; bool exploredCell;
}; };
typedef vector<Node*> Nodes; typedef vector<Node*> Nodes;
@ -119,8 +119,8 @@ public:
//fa = NULL; //fa = NULL;
} }
std::map<Vec2i, bool> openPosList; std::map<Vec2i, bool> openPosList;
std::map<float, Nodes> openNodesList; std::map<double, Nodes> openNodesList;
std::map<float, Nodes> closedNodesList; std::map<double, Nodes> closedNodesList;
std::vector<Node> nodePool; std::vector<Node> nodePool;
int nodePoolCount; int nodePoolCount;
RandomGen random; RandomGen random;
@ -201,7 +201,7 @@ private:
Vec2i computeNearestFreePos(const Unit *unit, const Vec2i &targetPos); Vec2i computeNearestFreePos(const Unit *unit, const Vec2i &targetPos);
//float heuristic(const Vec2i &pos, const Vec2i &finalPos); //float heuristic(const Vec2i &pos, const Vec2i &finalPos);
inline static float heuristic(const Vec2i &pos, const Vec2i &finalPos) { inline static double heuristic(const Vec2i &pos, const Vec2i &finalPos) {
return pos.dist(finalPos); return pos.dist(finalPos);
} }
@ -277,7 +277,7 @@ private:
return result; return result;
} }
void processNearestFreePos(const Vec2i &finalPos, int i, int j, int size, Field field, int teamIndex,Vec2i unitPos, Vec2i &nearestPos, float &nearestDist); void processNearestFreePos(const Vec2i &finalPos, int i, int j, int size, Field field, int teamIndex,Vec2i unitPos, Vec2i &nearestPos, double &nearestDist);
int getPathFindExtendRefreshNodeCount(int factionIndex); int getPathFindExtendRefreshNodeCount(int factionIndex);

View File

@ -4636,7 +4636,7 @@ void Renderer::renderObjects(const int renderFps) {
Model *objModel= o->getModelPtr(); Model *objModel= o->getModelPtr();
//objModel->updateInterpolationData(o->getAnimProgress(), true); //objModel->updateInterpolationData(o->getAnimProgress(), true);
const Vec3f &v= o->getConstPos(); const Vec3f v= Vec3f(o->getConstPos());
if(modelRenderStarted == false) { if(modelRenderStarted == false) {
modelRenderStarted = true; modelRenderStarted = true;
@ -5383,7 +5383,7 @@ void Renderer::renderSelectionEffects() {
int defaultValue= r->getType()->getDefResPerPatch(); int defaultValue= r->getType()->getDefResPerPatch();
float colorValue=static_cast<float>(r->getAmount())/static_cast<float>(defaultValue); float colorValue=static_cast<float>(r->getAmount())/static_cast<float>(defaultValue);
glColor4f(0.1f, 0.1f , colorValue, 0.4f); glColor4f(0.1f, 0.1f , colorValue, 0.4f);
renderSelectionCircle(selectedResourceObject->getPos(),2, selectionCircleRadius); renderSelectionCircle(Vec3f(selectedResourceObject->getPos()),2, selectionCircleRadius);
} }
//target arrow //target arrow
if(selection->getCount() == 1) { if(selection->getCount() == 1) {
@ -5481,7 +5481,7 @@ void Renderer::renderSelectionEffects() {
if(object->isHighlighted()) { if(object->isHighlighted()) {
float highlight= object->getHightlight(); float highlight= object->getHightlight();
glColor4f(0.1f, 0.1f , 1.0f, highlight); glColor4f(0.1f, 0.1f , 1.0f, highlight);
Vec3f v= object->getPos(); Vec3f v= Vec3f(object->getPos());
v.y+= 0.3f; v.y+= 0.3f;
renderSelectionCircle(v, 2, 0.4f+0.4f*highlight ); renderSelectionCircle(v, 2, 0.4f+0.4f*highlight );
} }
@ -7589,7 +7589,7 @@ vector<Object *> Renderer::renderObjectsFast(bool renderingShadows, bool resour
//objModel->updateInterpolationData(o->getAnimProgress(), true); //objModel->updateInterpolationData(o->getAnimProgress(), true);
//} //}
const Vec3f &v= o->getConstPos(); const Vec3f v= Vec3f(o->getConstPos());
if(colorPickingSelection == false) { if(colorPickingSelection == false) {
glPushName(OBJECT_SELECT_OFFSET+visibleIndex); glPushName(OBJECT_SELECT_OFFSET+visibleIndex);

View File

@ -125,8 +125,8 @@ bool CommandGroupUnitSorter::compare(const Unit *l, const Unit *r) {
result = curCommandGroupId < commandPeer->getUnitCommandGroupId(); result = curCommandGroupId < commandPeer->getUnitCommandGroupId();
} }
else { else {
float unitDist = l->getCenteredPos().dist(command->getPos()); double unitDist = l->getCenteredPos().dist(command->getPos());
float unitDistPeer = r->getCenteredPos().dist(commandPeer->getPos()); double unitDistPeer = r->getCenteredPos().dist(commandPeer->getPos());
// Closest unit in commandgroup // Closest unit in commandgroup
result = (unitDist < unitDistPeer); result = (unitDist < unitDistPeer);

View File

@ -34,22 +34,22 @@ ObjectStateInterface *Object::stateCallback=NULL;
// class Object // class Object
// ===================================================== // =====================================================
Object::Object(ObjectType *objectType, const Vec3f &pos, const Vec2i &mapPos) : BaseColorPickEntity() { Object::Object(ObjectType *objectType, const Vec3d &pos, const Vec2i &mapPos) : BaseColorPickEntity() {
RandomGen random; RandomGen random;
random.init(static_cast<int>(pos.x*pos.z)); random.init(static_cast<int>(pos.x * pos.z));
this->lastRenderFrame = 0; this->lastRenderFrame = 0;
this->objectType= objectType; this->objectType= objectType;
resource= NULL; resource= NULL;
highlight= 0.f; highlight= 0.f;
animated= false; animated= false;
this->mapPos = mapPos; this->mapPos = mapPos;
this->pos= pos + Vec3f(random.randRange(-0.6f, 0.6f), 0.0f, random.randRange(-0.6f, 0.6f)); this->pos= pos + Vec3d(random.randRange(-0.6f, 0.6f), 0.0f, random.randRange(-0.6f, 0.6f));
rotation= random.randRange(0.f, 360.f); rotation= random.randRange(0.f, 360.f);
if(objectType!=NULL){ if(objectType!=NULL){
variation = random.randRange(0, objectType->getModelCount()-1); variation = random.randRange(0, objectType->getModelCount()-1);
TilesetModelType *tmt=objectType->getTilesetModelType(variation); TilesetModelType *tmt=objectType->getTilesetModelType(variation);
if(tmt->getRotationAllowed()!=true){ if(tmt->getRotationAllowed() != true) {
rotation=0; rotation=0;
} }
animated=tmt->getAnimSpeed()>0; animated=tmt->getAnimSpeed()>0;
@ -109,7 +109,7 @@ void Object::initParticlesFromTypes(const ModelParticleSystemTypes *particleType
UnitParticleSystem *ups= new UnitParticleSystem(200); UnitParticleSystem *ups= new UnitParticleSystem(200);
ups->setParticleOwner(this); ups->setParticleOwner(this);
(*it)->setValues(ups); (*it)->setValues(ups);
ups->setPos(Vec3d(this->pos)); ups->setPos(this->pos);
ups->setRotation(this->rotation); ups->setRotation(this->rotation);
ups->setFactionColor(Vec3f(0, 0, 0)); ups->setFactionColor(Vec3f(0, 0, 0));
ups->setVisible(false); ups->setVisible(false);
@ -126,13 +126,13 @@ void Object::end(ParticleSystem *particleSystem) {
} }
} }
void Object::setHeight(float height) { void Object::setHeight(double height) {
pos.y=height; pos.y = height;
for(UnitParticleSystems::iterator it= unitParticleSystems.begin(); it != unitParticleSystems.end(); ++it) { for(UnitParticleSystems::iterator it= unitParticleSystems.begin(); it != unitParticleSystems.end(); ++it) {
bool particleValid = Renderer::getInstance().validateParticleSystemStillExists((*it),rsGame); bool particleValid = Renderer::getInstance().validateParticleSystemStillExists((*it),rsGame);
if(particleValid == true) { if(particleValid == true) {
(*it)->setPos(Vec3d(this->pos)); (*it)->setPos(this->pos);
} }
} }
} }
@ -153,17 +153,17 @@ void Object::update() {
// printf("#1 Object updating [%s] Speed [%d] animProgress [%f]\n",this->objectType->getTilesetModelType(variation)->getModel()->getFileName().c_str(),objectType->getTilesetModelType(variation)->getAnimSpeed(),animProgress); // printf("#1 Object updating [%s] Speed [%d] animProgress [%f]\n",this->objectType->getTilesetModelType(variation)->getModel()->getFileName().c_str(),objectType->getTilesetModelType(variation)->getAnimSpeed(),animProgress);
if(objectType != NULL && objectType->getTilesetModelType(variation) != NULL) { if(objectType != NULL && objectType->getTilesetModelType(variation) != NULL) {
float heightFactor = 1.f; double heightFactor = 1.f;
const float speedDivider= 100.f; const double speedDivider= 100.f;
float speedDenominator = (speedDivider * GameConstants::updateFps); double speedDenominator = (speedDivider * GameConstants::updateFps);
// smooth TwoFrameanimations // smooth TwoFrameanimations
float f=1.0f; double f=1.0f;
if(objectType->getTilesetModelType(variation)->getSmoothTwoFrameAnim()==true){ if(objectType->getTilesetModelType(variation)->getSmoothTwoFrameAnim()==true){
f=abs(std::sin(animProgress*2*3.16))+0.4f; f=abs(std::sin(animProgress*2*3.16))+0.4f;
} }
float newAnimProgress = animProgress + f*(((float)objectType->getTilesetModelType(variation)->getAnimSpeed() * heightFactor) / speedDenominator); double newAnimProgress = animProgress + f*(((double)objectType->getTilesetModelType(variation)->getAnimSpeed() * heightFactor) / speedDenominator);
// printf("A [%f] B [%f] C [%f] D [%f] E [%f] F [%f]\n", // printf("A [%f] B [%f] C [%f] D [%f] E [%f] F [%f]\n",
// ((float)objectType->getTilesetModelType(variation)->getAnimSpeed() * heightFactor), // ((float)objectType->getTilesetModelType(variation)->getAnimSpeed() * heightFactor),
@ -265,7 +265,7 @@ void Object::saveGame(XmlNode *rootNode) {
// Vec3f pos; // Vec3f pos;
objectNode->addAttribute("pos",pos.getString(), mapTagReplacements); objectNode->addAttribute("pos",pos.getString(), mapTagReplacements);
// float rotation; // float rotation;
objectNode->addAttribute("rotation",floatToStr(rotation,16), mapTagReplacements); objectNode->addAttribute("rotation",doubleToStr(rotation,16), mapTagReplacements);
// int variation; // int variation;
objectNode->addAttribute("variation",intToStr(variation), mapTagReplacements); objectNode->addAttribute("variation",intToStr(variation), mapTagReplacements);
// int lastRenderFrame; // int lastRenderFrame;
@ -297,7 +297,7 @@ void Object::loadGame(const XmlNode *rootNode,const TechTree *techTree) {
resource->loadGame(objectNode,0,techTree); resource->loadGame(objectNode,0,techTree);
} }
// Vec3f pos; // Vec3f pos;
pos = Vec3f::strToVec3(objectNode->getAttribute("pos")->getValue()); pos = Vec3d::strToVec3(objectNode->getAttribute("pos")->getValue());
// float rotation; // float rotation;
rotation = objectNode->getAttribute("rotation")->getFloatValue(); rotation = objectNode->getAttribute("rotation")->getFloatValue();
// int variation; // int variation;

View File

@ -57,20 +57,20 @@ private:
ObjectType *objectType; ObjectType *objectType;
vector<UnitParticleSystem*> unitParticleSystems; vector<UnitParticleSystem*> unitParticleSystems;
Resource *resource; Resource *resource;
Vec3f pos; Vec3d pos;
float rotation; double rotation;
int variation; int variation;
int lastRenderFrame; int lastRenderFrame;
Vec2i mapPos; Vec2i mapPos;
bool visible; bool visible;
bool animated; bool animated;
float animProgress; double animProgress;
float highlight; float highlight;
static ObjectStateInterface *stateCallback; static ObjectStateInterface *stateCallback;
public: public:
Object(ObjectType *objectType, const Vec3f &pos, const Vec2i &mapPos); Object(ObjectType *objectType, const Vec3d &pos, const Vec2i &mapPos);
virtual ~Object(); virtual ~Object();
void end(); //to kill particles void end(); //to kill particles
@ -80,10 +80,10 @@ public:
const ObjectType *getType() const {return objectType;} const ObjectType *getType() const {return objectType;}
Resource *getResource() const {return resource;} Resource *getResource() const {return resource;}
Vec3f getPos() const {return pos;} Vec3d getPos() const {return pos;}
bool isVisible() const {return visible;} bool isVisible() const {return visible;}
const Vec3f & getConstPos() const {return pos;} const Vec3d & getConstPos() const {return pos;}
float getRotation() const {return rotation;} double getRotation() const {return rotation;}
const Model *getModel() const; const Model *getModel() const;
Model *getModelPtr() const; Model *getModelPtr() const;
bool getWalkable() const; bool getWalkable() const;
@ -94,7 +94,7 @@ public:
void resetHighlight(); void resetHighlight();
void setResource(const ResourceType *resourceType, const Vec2i &pos); void setResource(const ResourceType *resourceType, const Vec2i &pos);
void setHeight(float height); void setHeight(double height);
void setVisible(bool visible); void setVisible(bool visible);
int getLastRenderFrame() const { return lastRenderFrame; } int getLastRenderFrame() const { return lastRenderFrame; }
@ -104,7 +104,7 @@ public:
void updateHighlight(); void updateHighlight();
void update(); void update();
float getAnimProgress() const { return animProgress;} double getAnimProgress() const { return animProgress;}
virtual string getUniquePickName() const; virtual string getUniquePickName() const;
void saveGame(XmlNode *rootNode); void saveGame(XmlNode *rootNode);

View File

@ -1080,7 +1080,7 @@ std::string UnitType::toString() const {
result += " sight = " + intToStr(sight); result += " sight = " + intToStr(sight);
result += " size = " + intToStr(size); result += " size = " + intToStr(size);
result += " height = " + intToStr(height); result += " height = " + intToStr(height);
result += " rotatedBuildPos = " + floatToStr(rotatedBuildPos,16); result += " rotatedBuildPos = " + doubleToStr(rotatedBuildPos,16);
result += " rotationAllowed = " + intToStr(rotationAllowed); result += " rotationAllowed = " + intToStr(rotationAllowed);
if(cellMap != NULL) { if(cellMap != NULL) {

View File

@ -123,7 +123,7 @@ private:
int sight; int sight;
int size; //size in cells int size; //size in cells
int height; int height;
float rotatedBuildPos; double rotatedBuildPos;
bool rotationAllowed; bool rotationAllowed;
//cellmap //cellmap
@ -249,8 +249,8 @@ public:
const CommandType* findCommandTypeById(int id) const; const CommandType* findCommandTypeById(int id) const;
string getCommandTypeListDesc() const; string getCommandTypeListDesc() const;
inline float getRotatedBuildPos() { return rotatedBuildPos; } inline double getRotatedBuildPos() { return rotatedBuildPos; }
inline void setRotatedBuildPos(float value) { rotatedBuildPos = value; } inline void setRotatedBuildPos(double value) { rotatedBuildPos = value; }
//other //other
virtual string getReqDesc(bool translatedValue) const; virtual string getReqDesc(bool translatedValue) const;

View File

@ -93,7 +93,7 @@ void Cell::saveGame(XmlNode *rootNode, int index) const {
} }
// float height; // float height;
cellNode->addAttribute("height",floatToStr(getHeight(),16), mapTagReplacements); cellNode->addAttribute("height",doubleToStr(getHeight(),16), mapTagReplacements);
} }
} }
@ -374,10 +374,10 @@ Checksum Map::load(const string &path, TechTree *techTree, Tileset *tileset) {
heightFactor= header.heightFactor; heightFactor= header.heightFactor;
if(heightFactor>100){ if(heightFactor>100){
heightFactor=heightFactor/100; heightFactor=heightFactor/100;
heightFactor = truncateDecimal<float>(heightFactor); heightFactor = truncateDecimal<double>(heightFactor,16);
} }
waterLevel= static_cast<float>((header.waterLevel-0.01f)/heightFactor); waterLevel= static_cast<double>((header.waterLevel-0.01f)/heightFactor);
waterLevel = truncateDecimal<float>(waterLevel); waterLevel = truncateDecimal<double>(waterLevel,16);
title= header.title; title= header.title;
maxPlayers= header.maxFactions; maxPlayers= header.maxFactions;
@ -395,8 +395,8 @@ Checksum Map::load(const string &path, TechTree *techTree, Tileset *tileset) {
else if(header.version==2){ else if(header.version==2){
//desc = header.version2.short_desc; //desc = header.version2.short_desc;
if(header.version2.cliffLevel > 0 && header.version2.cliffLevel < 5000){ if(header.version2.cliffLevel > 0 && header.version2.cliffLevel < 5000){
cliffLevel=static_cast<float>((header.version2.cliffLevel-0.01f)/(heightFactor)); cliffLevel=static_cast<double>((header.version2.cliffLevel-0.01f)/(heightFactor),16);
cliffLevel = truncateDecimal<float>(cliffLevel); cliffLevel = truncateDecimal<double>(cliffLevel,16);
} }
if(header.version2.cameraHeight > 0 && header.version2.cameraHeight < 5000) { if(header.version2.cameraHeight > 0 && header.version2.cameraHeight < 5000) {
cameraHeight = header.version2.cameraHeight; cameraHeight = header.version2.cameraHeight;
@ -481,7 +481,7 @@ Checksum Map::load(const string &path, TechTree *techTree, Tileset *tileset) {
sc->setObject(NULL); sc->setObject(NULL);
} }
else if(objNumber <= Tileset::objCount) { else if(objNumber <= Tileset::objCount) {
Object *o= new Object(tileset->getObjectType(objNumber-1), sc->getVertex(),Vec2i(i, j)); Object *o= new Object(tileset->getObjectType(objNumber-1), Vec3d(sc->getVertex()),Vec2i(i, j));
sc->setObject(o); sc->setObject(o);
for(int k = 0; k < techTree->getResourceTypeCount(); ++k) { for(int k = 0; k < techTree->getResourceTypeCount(); ++k) {
const ResourceType *rt= techTree->getResourceType(k); const ResourceType *rt= techTree->getResourceType(k);
@ -492,7 +492,7 @@ Checksum Map::load(const string &path, TechTree *techTree, Tileset *tileset) {
} }
else{ else{
const ResourceType *rt= techTree->getTechResourceType(objNumber - Tileset::objCount) ; const ResourceType *rt= techTree->getTechResourceType(objNumber - Tileset::objCount) ;
Object *o= new Object(NULL, sc->getVertex(),Vec2i(i, j)); Object *o= new Object(NULL, Vec3d(sc->getVertex()),Vec2i(i, j));
o->setResource(rt, Vec2i(i, j)); o->setResource(rt, Vec2i(i, j));
sc->setObject(o); sc->setObject(o);
} }
@ -529,8 +529,8 @@ void Map::init(Tileset *tileset) {
class FindBestPos { class FindBestPos {
public: public:
float distanceFromUnitNoAdjustment; double distanceFromUnitNoAdjustment;
float distanceFromClickNoAdjustment; double distanceFromClickNoAdjustment;
Vec2i resourcePosNoAdjustment; Vec2i resourcePosNoAdjustment;
}; };
@ -540,8 +540,8 @@ bool Map::isResourceNear(int frameIndex,const Vec2i &pos, const ResourceType *rt
Vec2i *resourceClickPos) const { Vec2i *resourceClickPos) const {
bool resourceNear = false; bool resourceNear = false;
float distanceFromUnit=-1; double distanceFromUnit=-1;
float distanceFromClick=-1; double distanceFromClick=-1;
if(resourceClickPos) { if(resourceClickPos) {
//printf("+++++++++ unit [%s - %d] pos = [%s] resourceClickPos [%s]\n",unit->getFullName().c_str(),unit->getId(),pos.getString().c_str(),resourceClickPos->getString().c_str()); //printf("+++++++++ unit [%s - %d] pos = [%s] resourceClickPos [%s]\n",unit->getFullName().c_str(),unit->getId(),pos.getString().c_str(),resourceClickPos->getString().c_str());
@ -694,7 +694,7 @@ bool Map::isResourceNear(int frameIndex,const Vec2i &pos, const ResourceType *rt
} }
} }
float bestUnitDist = distanceFromUnit; double bestUnitDist = distanceFromUnit;
for(unsigned int i = 0; i < bestPosList.size(); ++i) { for(unsigned int i = 0; i < bestPosList.size(); ++i) {
FindBestPos &bestPosItem = bestPosList[i]; FindBestPos &bestPosItem = bestPosList[i];
@ -1115,12 +1115,12 @@ Vec2i Map::computeDestPos( const Vec2i &refUnitPos, const Vec2i &unitPos,
return pos; return pos;
} }
std::pair<float,Vec2i> Map::getUnitDistanceToPos(const Unit *unit,Vec2i pos,const UnitType *ut) { std::pair<double,Vec2i> Map::getUnitDistanceToPos(const Unit *unit,Vec2i pos,const UnitType *ut) {
if(unit == NULL) { if(unit == NULL) {
throw megaglest_runtime_error("unit == NULL"); throw megaglest_runtime_error("unit == NULL");
} }
std::pair<float,Vec2i> result(-1,Vec2i(0)); std::pair<double,Vec2i> result(-1,Vec2i(0));
//int unitId= unit->getId(); //int unitId= unit->getId();
Vec2i unitPos= computeDestPos(unit->getPosNotThreadSafe(), unit->getPosNotThreadSafe(), pos); Vec2i unitPos= computeDestPos(unit->getPosNotThreadSafe(), unit->getPosNotThreadSafe(), pos);
@ -1136,7 +1136,7 @@ std::pair<float,Vec2i> Map::getUnitDistanceToPos(const Unit *unit,Vec2i pos,cons
Vec2i testPos(i,j); Vec2i testPos(i,j);
if(ut == NULL || isInUnitTypeCells(ut, pos,testPos) == false) { if(ut == NULL || isInUnitTypeCells(ut, pos,testPos) == false) {
float distance = unitPos.dist(testPos); double distance = unitPos.dist(testPos);
if(result.first < 0 || result.first > distance) { if(result.first < 0 || result.first > distance) {
result.first = distance; result.first = distance;
result.second = testPos; result.second = testPos;
@ -1155,7 +1155,7 @@ const Unit * Map::findClosestUnitToPos(const Selection *selection, Vec2i origina
Vec2i pos = originalBuildPos; Vec2i pos = originalBuildPos;
float bestRange = -1; double bestRange = -1;
Vec2i start = pos - Vec2i(1); Vec2i start = pos - Vec2i(1);
int unitTypeSize = 0; int unitTypeSize = 0;
@ -1173,7 +1173,7 @@ const Unit * Map::findClosestUnitToPos(const Selection *selection, Vec2i origina
for(int j = start.y; j <= end.y; ++j){ for(int j = start.y; j <= end.y; ++j){
Vec2i testPos(i,j); Vec2i testPos(i,j);
if(isInUnitTypeCells(ut, originalBuildPos,testPos) == false) { if(isInUnitTypeCells(ut, originalBuildPos,testPos) == false) {
float distance = unitBuilderPos.dist(testPos); double distance = unitBuilderPos.dist(testPos);
if(bestRange < 0 || bestRange > distance) { if(bestRange < 0 || bestRange > distance) {
bestRange = distance; bestRange = distance;
pos = testPos; pos = testPos;
@ -1198,7 +1198,7 @@ Vec2i Map::findBestBuildApproach(const Unit *unit, Vec2i originalBuildPos,const
Vec2i unitBuilderPos = unit->getPosNotThreadSafe(); Vec2i unitBuilderPos = unit->getPosNotThreadSafe();
Vec2i pos = originalBuildPos; Vec2i pos = originalBuildPos;
float bestRange = -1; double bestRange = -1;
Vec2i start = pos - Vec2i(unit->getType()->getSize()); Vec2i start = pos - Vec2i(unit->getType()->getSize());
Vec2i end = pos + Vec2i(ut->getSize()); Vec2i end = pos + Vec2i(ut->getSize());
@ -1207,7 +1207,7 @@ Vec2i Map::findBestBuildApproach(const Unit *unit, Vec2i originalBuildPos,const
for(int j = start.y; j <= end.y; ++j) { for(int j = start.y; j <= end.y; ++j) {
Vec2i testPos(i,j); Vec2i testPos(i,j);
if(isInUnitTypeCells(ut, originalBuildPos,testPos) == false) { if(isInUnitTypeCells(ut, originalBuildPos,testPos) == false) {
float distance = unitBuilderPos.dist(testPos); double distance = unitBuilderPos.dist(testPos);
if(bestRange < 0 || bestRange > distance) { if(bestRange < 0 || bestRange > distance) {
// Check if the cell is occupied by another unit // Check if the cell is occupied by another unit
if(isFreeCellOrHasUnit(testPos, unit->getType()->getField(), unit) == true) { if(isFreeCellOrHasUnit(testPos, unit->getType()->getField(), unit) == true) {
@ -1532,7 +1532,7 @@ void Map::prepareTerrain(const Unit *unit) {
// ==================== compute ==================== // ==================== compute ====================
void Map::flatternTerrain(const Unit *unit){ void Map::flatternTerrain(const Unit *unit){
float refHeight= getSurfaceCell(toSurfCoords(unit->getCenteredPos()))->getHeight(); double refHeight= getSurfaceCell(toSurfCoords(unit->getCenteredPos()))->getHeight();
for(int i=-1; i<=unit->getType()->getSize(); ++i){ for(int i=-1; i<=unit->getType()->getSize(); ++i){
for(int j=-1; j<=unit->getType()->getSize(); ++j){ for(int j=-1; j<=unit->getType()->getSize(); ++j){
Vec2i pos= unit->getPosNotThreadSafe()+Vec2i(i, j); Vec2i pos= unit->getPosNotThreadSafe()+Vec2i(i, j);
@ -1641,8 +1641,8 @@ void Map::smoothSurface(Tileset *tileset) {
} }
if (formerObject == NULL) { if (formerObject == NULL) {
Object *o = new Object(tileset->getObjectType(9), Object *o = new Object(tileset->getObjectType(9),
getSurfaceCell(i, j)->getVertex(), Vec2i(i, Vec3d(getSurfaceCell(i, j)->getVertex()),
j)); Vec2i(i,j));
getSurfaceCell(i, j)->setObject(o); getSurfaceCell(i, j)->setObject(o);
} }
} }
@ -1733,11 +1733,11 @@ void Map::saveGame(XmlNode *rootNode) const {
// string title; // string title;
mapNode->addAttribute("title",title, mapTagReplacements); mapNode->addAttribute("title",title, mapTagReplacements);
// float waterLevel; // float waterLevel;
mapNode->addAttribute("waterLevel",floatToStr(waterLevel,16), mapTagReplacements); mapNode->addAttribute("waterLevel",doubleToStr(waterLevel,16), mapTagReplacements);
// float heightFactor; // float heightFactor;
mapNode->addAttribute("heightFactor",floatToStr(heightFactor,16), mapTagReplacements); mapNode->addAttribute("heightFactor",doubleToStr(heightFactor,16), mapTagReplacements);
// float cliffLevel; // float cliffLevel;
mapNode->addAttribute("cliffLevel",floatToStr(cliffLevel,16), mapTagReplacements); mapNode->addAttribute("cliffLevel",doubleToStr(cliffLevel,16), mapTagReplacements);
// int cameraHeight; // int cameraHeight;
mapNode->addAttribute("cameraHeight",intToStr(cameraHeight), mapTagReplacements); mapNode->addAttribute("cameraHeight",intToStr(cameraHeight), mapTagReplacements);
// int w; // int w;
@ -1817,7 +1817,7 @@ void Map::saveGame(XmlNode *rootNode) const {
// Checksum checksumValue; // Checksum checksumValue;
// mapNode->addAttribute("checksumValue",intToStr(checksumValue.getSum()), mapTagReplacements); // mapNode->addAttribute("checksumValue",intToStr(checksumValue.getSum()), mapTagReplacements);
// float maxMapHeight; // float maxMapHeight;
mapNode->addAttribute("maxMapHeight",floatToStr(maxMapHeight,16), mapTagReplacements); mapNode->addAttribute("maxMapHeight",doubleToStr(maxMapHeight,16), mapTagReplacements);
// string mapFile; // string mapFile;
mapNode->addAttribute("mapFile",mapFile, mapTagReplacements); mapNode->addAttribute("mapFile",mapFile, mapTagReplacements);
} }

View File

@ -58,7 +58,7 @@ class Cell {
private: private:
Unit *units[fieldCount]; //units on this cell Unit *units[fieldCount]; //units on this cell
Unit *unitsWithEmptyCellMap[fieldCount]; //units with an empty cellmap on this cell Unit *unitsWithEmptyCellMap[fieldCount]; //units with an empty cellmap on this cell
float height; double height;
private: private:
Cell(Cell&); Cell(Cell&);
@ -70,11 +70,11 @@ public:
//get //get
inline Unit *getUnit(int field) const { if(field >= fieldCount) { throw megaglest_runtime_error("Invalid field value" + intToStr(field));} return units[field];} 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 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 truncateDecimal<float>(height);} inline double getHeight() const {return truncateDecimal<double>(height,16);}
inline void setUnit(int field, Unit *unit) { if(field >= fieldCount) { throw megaglest_runtime_error("Invalid field value" + intToStr(field));} units[field]= unit;} 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 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 = truncateDecimal<float>(height);} inline void setHeight(double height) {this->height = truncateDecimal<double>(height,16);}
inline bool isFree(Field field) const { inline bool isFree(Field field) const {
Unit *unit = getUnit(field); Unit *unit = getUnit(field);
@ -213,9 +213,9 @@ public:
private: private:
string title; string title;
float waterLevel; double waterLevel;
float heightFactor; double heightFactor;
float cliffLevel; double cliffLevel;
int cameraHeight; int cameraHeight;
int w; int w;
int h; int h;
@ -228,7 +228,7 @@ private:
SurfaceCell *surfaceCells; SurfaceCell *surfaceCells;
Vec2i *startLocations; Vec2i *startLocations;
Checksum checksumValue; Checksum checksumValue;
float maxMapHeight; double maxMapHeight;
string mapFile; string mapFile;
private: private:
@ -296,11 +296,11 @@ public:
inline int getSurfaceW() const {return surfaceW;} inline int getSurfaceW() const {return surfaceW;}
inline int getSurfaceH() const {return surfaceH;} inline int getSurfaceH() const {return surfaceH;}
inline int getMaxPlayers() const {return maxPlayers;} inline int getMaxPlayers() const {return maxPlayers;}
inline float getHeightFactor() const {return truncateDecimal<float>(heightFactor);} inline double getHeightFactor() const {return truncateDecimal<double>(heightFactor,16);}
inline float getWaterLevel() const {return truncateDecimal<float>(waterLevel);} inline double getWaterLevel() const {return truncateDecimal<double>(waterLevel,16);}
inline float getCliffLevel() const {return truncateDecimal<float>(cliffLevel);} inline double getCliffLevel() const {return truncateDecimal<double>(cliffLevel,16);}
inline int getCameraHeight() const {return cameraHeight;} inline int getCameraHeight() const {return cameraHeight;}
inline float getMaxMapHeight() const {return truncateDecimal<float>(maxMapHeight);} inline double getMaxMapHeight() const {return truncateDecimal<double>(maxMapHeight,16);}
Vec2i getStartLocation(int locationIndex) const; Vec2i getStartLocation(int locationIndex) const;
inline bool getSubmerged(const SurfaceCell *sc) const {return sc->getHeight()<waterLevel;} inline bool getSubmerged(const SurfaceCell *sc) const {return sc->getHeight()<waterLevel;}
inline bool getSubmerged(const Cell *c) const {return c->getHeight()<waterLevel;} inline bool getSubmerged(const Cell *c) const {return c->getHeight()<waterLevel;}
@ -347,7 +347,7 @@ public:
bool isInUnitTypeCells(const UnitType *ut, const Vec2i &pos,const Vec2i &testPos) const; bool isInUnitTypeCells(const UnitType *ut, const Vec2i &pos,const Vec2i &testPos) const;
bool isNextToUnitTypeCells(const UnitType *ut, const Vec2i &pos,const Vec2i &testPos) const; bool isNextToUnitTypeCells(const UnitType *ut, const Vec2i &pos,const Vec2i &testPos) const;
Vec2i findBestBuildApproach(const Unit *unit, Vec2i originalBuildPos,const UnitType *ut) const; Vec2i findBestBuildApproach(const Unit *unit, Vec2i originalBuildPos,const UnitType *ut) const;
std::pair<float,Vec2i> getUnitDistanceToPos(const Unit *unit,Vec2i pos,const UnitType *ut); std::pair<double,Vec2i> getUnitDistanceToPos(const Unit *unit,Vec2i pos,const UnitType *ut);
//misc //misc
bool isNextTo(const Vec2i &pos, const Unit *unit) const; bool isNextTo(const Vec2i &pos, const Unit *unit) const;

View File

@ -231,10 +231,10 @@ void copyStringToBuffer(char *buffer, int bufferSize, const string& s);
//numeric fcs //numeric fcs
int clamp(int value, int min, int max); int clamp(int value, int min, int max);
float clamp(float value, float min, float max); double clamp(double value, double min, double max);
int64 clamp(int64 value, int64 min, int64 max); int64 clamp(int64 value, int64 min, int64 max);
float saturate(float value); double saturate(double value);
int round(float f); int round(double f);
//misc //misc
bool checkVersionComptability(string clientVersionString, string serverVersionString); bool checkVersionComptability(string clientVersionString, string serverVersionString);

View File

@ -73,23 +73,15 @@ std::string RandomGen::getLastCaller() const {
return result; return result;
} }
int RandomGen::randRange(int min, int max,string lastCaller) { int RandomGen::randRange(int min, int max,string lastCaller) {
//assert(min<=max);
if(min > max) { if(min > max) {
char szBuf[8096]=""; char szBuf[8096]="";
snprintf(szBuf,8096,"In [%s::%s Line: %d] min > max, min = %d, max = %d",__FILE__,__FUNCTION__,__LINE__,min,max); snprintf(szBuf,8096,"In [%s::%s Line: %d] min > max, min = %d, max = %d",__FILE__,__FUNCTION__,__LINE__,min,max);
throw megaglest_runtime_error(szBuf); throw megaglest_runtime_error(szBuf);
} }
//#ifdef USE_STREFLOP
// int res = streflop::Random<true, false, float>(min, max); // streflop
//#else
int diff= max-min; int diff= max-min;
//int res= min + static_cast<int>(truncateDecimal<double>(static_cast<double>(diff+1),2)*RandomGen::rand() / m);
double numerator = static_cast<double>(diff + 1) * static_cast<double>(RandomGen::rand(lastCaller)); double numerator = static_cast<double>(diff + 1) * static_cast<double>(RandomGen::rand(lastCaller));
int res= min + static_cast<int>(truncateDecimal<double>(numerator / static_cast<double>(m))); int res= min + static_cast<int>(truncateDecimal<double>(numerator / static_cast<double>(m),16));
//int res= min + static_cast<int>(truncateDecimal<double>(static_cast<double>(diff+1 * RandomGen::rand()) / static_cast<double>(m)));
//#endif
//assert(res>=min && res<=max);
if(res < min || res > max) { if(res < min || res > max) {
char szBuf[8096]=""; char szBuf[8096]="";
snprintf(szBuf,8096,"In [%s::%s Line: %d] res < min || res > max, min = %d, max = %d, res = %d",__FILE__,__FUNCTION__,__LINE__,min,max,res); snprintf(szBuf,8096,"In [%s::%s Line: %d] res < min || res > max, min = %d, max = %d, res = %d",__FILE__,__FUNCTION__,__LINE__,min,max,res);
@ -102,22 +94,16 @@ int RandomGen::randRange(int min, int max,string lastCaller) {
} }
double RandomGen::randRange(double min, double max,string lastCaller) { double RandomGen::randRange(double min, double max,string lastCaller) {
//assert(min<=max);
if(min > max) { if(min > max) {
char szBuf[8096]=""; char szBuf[8096]="";
snprintf(szBuf,8096,"In [%s::%s Line: %d] min > max, min = %f, max = %f",__FILE__,__FUNCTION__,__LINE__,min,max); snprintf(szBuf,8096,"In [%s::%s Line: %d] min > max, min = %f, max = %f",__FILE__,__FUNCTION__,__LINE__,min,max);
throw megaglest_runtime_error(szBuf); throw megaglest_runtime_error(szBuf);
} }
//#ifdef USE_STREFLOP double rand01 = static_cast<double>(RandomGen::rand(lastCaller)) / (m-1);
// float res = streflop::Random<true, false, float>(min, max, randomState); // streflop double res= min + (max - min) * rand01;
//#else res = truncateDecimal<double>(res,16);
double rand01= static_cast<double>(RandomGen::rand(lastCaller))/(m-1);
double res= min+(max-min)*rand01;
res = truncateDecimal<double>(res);
//#endif
//assert(res>=min && res<=max);
if(res < min || res > max) { if(res < min || res > max) {
char szBuf[8096]=""; char szBuf[8096]="";
snprintf(szBuf,8096,"In [%s::%s Line: %d] res < min || res > max, min = %f, max = %f, res = %f",__FILE__,__FUNCTION__,__LINE__,min,max,res); snprintf(szBuf,8096,"In [%s::%s Line: %d] res < min || res > max, min = %f, max = %f, res = %f",__FILE__,__FUNCTION__,__LINE__,min,max,res);

View File

@ -710,11 +710,11 @@ void copyStringToBuffer(char *buffer, int bufferSize, const string& s){
// ==================== numeric fcs ==================== // ==================== numeric fcs ====================
float saturate(float value){ double saturate(double value) {
if (value<0.f){ if (value < 0.f){
return 0.f; return 0.f;
} }
if (value>1.f){ if (value > 1.f){
return 1.f; return 1.f;
} }
return value; return value;
@ -740,17 +740,17 @@ int64 clamp(int64 value, int64 min, int64 max){
return value; return value;
} }
float clamp(float value, float min, float max){ double clamp(double value, double min, double max) {
if (value<min){ if (value < min) {
return min; return min;
} }
if (value>max){ if (value > max) {
return max; return max;
} }
return value; return value;
} }
int round(float f){ int round(double f){
return (int) f; return (int) f;
} }