diff --git a/source/glest_game/ai/path_finder.cpp b/source/glest_game/ai/path_finder.cpp index d257ba01..8e91673d 100644 --- a/source/glest_game/ai/path_finder.cpp +++ b/source/glest_game/ai/path_finder.cpp @@ -995,7 +995,7 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout const Vec2i unitPos = unit->getPos(); const Vec2i finalPos= computeNearestFreePos(unit, targetPos); - float dist= unitPos.dist(finalPos); + double dist= unitPos.dist(finalPos); 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()); @@ -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(nodeLimitReached == true) { if(factions[unitFactionIndex].closedNodesList.size() > 0) { - float bestHeuristic = factions[unitFactionIndex].closedNodesList.begin()->first; + double bestHeuristic = factions[unitFactionIndex].closedNodesList.begin()->first; if(bestHeuristic < lastNode->heuristic) { lastNode= factions[unitFactionIndex].closedNodesList.begin()->second[0]; } @@ -1520,10 +1520,10 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout 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); if(map->isAproxFreeCells(currPos, size, field, teamIndex)) { - float dist= currPos.dist(finalPos); + double dist= currPos.dist(finalPos); //if nearer from finalPos if(dist < nearestDist){ @@ -1557,7 +1557,7 @@ Vec2i PathFinder::computeNearestFreePos(const Unit *unit, const Vec2i &finalPos) //find nearest pos Vec2i unitPos= unit->getPosNotThreadSafe(); Vec2i nearestPos= unitPos; - float nearestDist= unitPos.dist(finalPos); + double nearestDist= unitPos.dist(finalPos); for(int i= -maxFreeSearchRadius; i <= maxFreeSearchRadius; ++i) { for(int j= -maxFreeSearchRadius; j <= maxFreeSearchRadius; ++j) { @@ -1639,7 +1639,7 @@ void PathFinder::saveGame(XmlNode *rootNode) { nodePoolNode->addAttribute("next",intToStr(nextIdx), mapTagReplacements); int prevIdx = findNodeIndex(curNode->prev, factionState.nodePool); 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); } diff --git a/source/glest_game/ai/path_finder.h b/source/glest_game/ai/path_finder.h index 7f060434..c04e492c 100644 --- a/source/glest_game/ai/path_finder.h +++ b/source/glest_game/ai/path_finder.h @@ -95,7 +95,7 @@ public: Vec2i pos; Node *next; Node *prev; - float heuristic; + double heuristic; bool exploredCell; }; typedef vector Nodes; @@ -119,8 +119,8 @@ public: //fa = NULL; } std::map openPosList; - std::map openNodesList; - std::map closedNodesList; + std::map openNodesList; + std::map closedNodesList; std::vector nodePool; int nodePoolCount; RandomGen random; @@ -201,7 +201,7 @@ private: Vec2i computeNearestFreePos(const Unit *unit, const Vec2i &targetPos); //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); } @@ -277,7 +277,7 @@ private: 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); diff --git a/source/glest_game/graphics/renderer.cpp b/source/glest_game/graphics/renderer.cpp index b85ab757..b57ed42d 100644 --- a/source/glest_game/graphics/renderer.cpp +++ b/source/glest_game/graphics/renderer.cpp @@ -4636,7 +4636,7 @@ void Renderer::renderObjects(const int renderFps) { Model *objModel= o->getModelPtr(); //objModel->updateInterpolationData(o->getAnimProgress(), true); - const Vec3f &v= o->getConstPos(); + const Vec3f v= Vec3f(o->getConstPos()); if(modelRenderStarted == false) { modelRenderStarted = true; @@ -5383,7 +5383,7 @@ void Renderer::renderSelectionEffects() { int defaultValue= r->getType()->getDefResPerPatch(); float colorValue=static_cast(r->getAmount())/static_cast(defaultValue); glColor4f(0.1f, 0.1f , colorValue, 0.4f); - renderSelectionCircle(selectedResourceObject->getPos(),2, selectionCircleRadius); + renderSelectionCircle(Vec3f(selectedResourceObject->getPos()),2, selectionCircleRadius); } //target arrow if(selection->getCount() == 1) { @@ -5481,7 +5481,7 @@ void Renderer::renderSelectionEffects() { if(object->isHighlighted()) { float highlight= object->getHightlight(); glColor4f(0.1f, 0.1f , 1.0f, highlight); - Vec3f v= object->getPos(); + Vec3f v= Vec3f(object->getPos()); v.y+= 0.3f; renderSelectionCircle(v, 2, 0.4f+0.4f*highlight ); } @@ -7589,7 +7589,7 @@ vector Renderer::renderObjectsFast(bool renderingShadows, bool resour //objModel->updateInterpolationData(o->getAnimProgress(), true); //} - const Vec3f &v= o->getConstPos(); + const Vec3f v= Vec3f(o->getConstPos()); if(colorPickingSelection == false) { glPushName(OBJECT_SELECT_OFFSET+visibleIndex); diff --git a/source/glest_game/type_instances/faction.cpp b/source/glest_game/type_instances/faction.cpp index e85a2d89..e2aca5f8 100644 --- a/source/glest_game/type_instances/faction.cpp +++ b/source/glest_game/type_instances/faction.cpp @@ -125,8 +125,8 @@ bool CommandGroupUnitSorter::compare(const Unit *l, const Unit *r) { result = curCommandGroupId < commandPeer->getUnitCommandGroupId(); } else { - float unitDist = l->getCenteredPos().dist(command->getPos()); - float unitDistPeer = r->getCenteredPos().dist(commandPeer->getPos()); + double unitDist = l->getCenteredPos().dist(command->getPos()); + double unitDistPeer = r->getCenteredPos().dist(commandPeer->getPos()); // Closest unit in commandgroup result = (unitDist < unitDistPeer); diff --git a/source/glest_game/type_instances/object.cpp b/source/glest_game/type_instances/object.cpp index ea2e09e9..36a600be 100644 --- a/source/glest_game/type_instances/object.cpp +++ b/source/glest_game/type_instances/object.cpp @@ -34,22 +34,22 @@ ObjectStateInterface *Object::stateCallback=NULL; // 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; - random.init(static_cast(pos.x*pos.z)); + random.init(static_cast(pos.x * pos.z)); this->lastRenderFrame = 0; this->objectType= objectType; resource= NULL; highlight= 0.f; animated= false; 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); if(objectType!=NULL){ variation = random.randRange(0, objectType->getModelCount()-1); TilesetModelType *tmt=objectType->getTilesetModelType(variation); - if(tmt->getRotationAllowed()!=true){ + if(tmt->getRotationAllowed() != true) { rotation=0; } animated=tmt->getAnimSpeed()>0; @@ -109,7 +109,7 @@ void Object::initParticlesFromTypes(const ModelParticleSystemTypes *particleType UnitParticleSystem *ups= new UnitParticleSystem(200); ups->setParticleOwner(this); (*it)->setValues(ups); - ups->setPos(Vec3d(this->pos)); + ups->setPos(this->pos); ups->setRotation(this->rotation); ups->setFactionColor(Vec3f(0, 0, 0)); ups->setVisible(false); @@ -126,13 +126,13 @@ void Object::end(ParticleSystem *particleSystem) { } } -void Object::setHeight(float height) { - pos.y=height; +void Object::setHeight(double height) { + pos.y = height; for(UnitParticleSystems::iterator it= unitParticleSystems.begin(); it != unitParticleSystems.end(); ++it) { bool particleValid = Renderer::getInstance().validateParticleSystemStillExists((*it),rsGame); 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); if(objectType != NULL && objectType->getTilesetModelType(variation) != NULL) { - float heightFactor = 1.f; - const float speedDivider= 100.f; - float speedDenominator = (speedDivider * GameConstants::updateFps); + double heightFactor = 1.f; + const double speedDivider= 100.f; + double speedDenominator = (speedDivider * GameConstants::updateFps); // smooth TwoFrameanimations - float f=1.0f; + double f=1.0f; if(objectType->getTilesetModelType(variation)->getSmoothTwoFrameAnim()==true){ 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", // ((float)objectType->getTilesetModelType(variation)->getAnimSpeed() * heightFactor), @@ -265,7 +265,7 @@ void Object::saveGame(XmlNode *rootNode) { // Vec3f pos; objectNode->addAttribute("pos",pos.getString(), mapTagReplacements); // float rotation; - objectNode->addAttribute("rotation",floatToStr(rotation,16), mapTagReplacements); + objectNode->addAttribute("rotation",doubleToStr(rotation,16), mapTagReplacements); // int variation; objectNode->addAttribute("variation",intToStr(variation), mapTagReplacements); // int lastRenderFrame; @@ -297,7 +297,7 @@ void Object::loadGame(const XmlNode *rootNode,const TechTree *techTree) { resource->loadGame(objectNode,0,techTree); } // Vec3f pos; - pos = Vec3f::strToVec3(objectNode->getAttribute("pos")->getValue()); + pos = Vec3d::strToVec3(objectNode->getAttribute("pos")->getValue()); // float rotation; rotation = objectNode->getAttribute("rotation")->getFloatValue(); // int variation; diff --git a/source/glest_game/type_instances/object.h b/source/glest_game/type_instances/object.h index 352fc16e..b5b3e3b7 100644 --- a/source/glest_game/type_instances/object.h +++ b/source/glest_game/type_instances/object.h @@ -57,20 +57,20 @@ private: ObjectType *objectType; vector unitParticleSystems; Resource *resource; - Vec3f pos; - float rotation; + Vec3d pos; + double rotation; int variation; int lastRenderFrame; Vec2i mapPos; bool visible; bool animated; - float animProgress; + double animProgress; float highlight; static ObjectStateInterface *stateCallback; public: - Object(ObjectType *objectType, const Vec3f &pos, const Vec2i &mapPos); + Object(ObjectType *objectType, const Vec3d &pos, const Vec2i &mapPos); virtual ~Object(); void end(); //to kill particles @@ -80,10 +80,10 @@ public: const ObjectType *getType() const {return objectType;} Resource *getResource() const {return resource;} - Vec3f getPos() const {return pos;} + Vec3d getPos() const {return pos;} bool isVisible() const {return visible;} - const Vec3f & getConstPos() const {return pos;} - float getRotation() const {return rotation;} + const Vec3d & getConstPos() const {return pos;} + double getRotation() const {return rotation;} const Model *getModel() const; Model *getModelPtr() const; bool getWalkable() const; @@ -94,7 +94,7 @@ public: void resetHighlight(); void setResource(const ResourceType *resourceType, const Vec2i &pos); - void setHeight(float height); + void setHeight(double height); void setVisible(bool visible); int getLastRenderFrame() const { return lastRenderFrame; } @@ -104,7 +104,7 @@ public: void updateHighlight(); void update(); - float getAnimProgress() const { return animProgress;} + double getAnimProgress() const { return animProgress;} virtual string getUniquePickName() const; void saveGame(XmlNode *rootNode); diff --git a/source/glest_game/types/unit_type.cpp b/source/glest_game/types/unit_type.cpp index 0c29c031..bbd7e22f 100644 --- a/source/glest_game/types/unit_type.cpp +++ b/source/glest_game/types/unit_type.cpp @@ -1080,7 +1080,7 @@ std::string UnitType::toString() const { result += " sight = " + intToStr(sight); result += " size = " + intToStr(size); result += " height = " + intToStr(height); - result += " rotatedBuildPos = " + floatToStr(rotatedBuildPos,16); + result += " rotatedBuildPos = " + doubleToStr(rotatedBuildPos,16); result += " rotationAllowed = " + intToStr(rotationAllowed); if(cellMap != NULL) { diff --git a/source/glest_game/types/unit_type.h b/source/glest_game/types/unit_type.h index cabc5f7c..e29cd516 100644 --- a/source/glest_game/types/unit_type.h +++ b/source/glest_game/types/unit_type.h @@ -123,7 +123,7 @@ private: int sight; int size; //size in cells int height; - float rotatedBuildPos; + double rotatedBuildPos; bool rotationAllowed; //cellmap @@ -249,8 +249,8 @@ public: const CommandType* findCommandTypeById(int id) const; string getCommandTypeListDesc() const; - inline float getRotatedBuildPos() { return rotatedBuildPos; } - inline void setRotatedBuildPos(float value) { rotatedBuildPos = value; } + inline double getRotatedBuildPos() { return rotatedBuildPos; } + inline void setRotatedBuildPos(double value) { rotatedBuildPos = value; } //other virtual string getReqDesc(bool translatedValue) const; diff --git a/source/glest_game/world/map.cpp b/source/glest_game/world/map.cpp index 2b2bb865..a7586920 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(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; if(heightFactor>100){ heightFactor=heightFactor/100; - heightFactor = truncateDecimal(heightFactor); + heightFactor = truncateDecimal(heightFactor,16); } - waterLevel= static_cast((header.waterLevel-0.01f)/heightFactor); - waterLevel = truncateDecimal(waterLevel); + waterLevel= static_cast((header.waterLevel-0.01f)/heightFactor); + waterLevel = truncateDecimal(waterLevel,16); title= header.title; maxPlayers= header.maxFactions; @@ -395,8 +395,8 @@ Checksum Map::load(const string &path, TechTree *techTree, Tileset *tileset) { else if(header.version==2){ //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); + cliffLevel=static_cast((header.version2.cliffLevel-0.01f)/(heightFactor),16); + cliffLevel = truncateDecimal(cliffLevel,16); } if(header.version2.cameraHeight > 0 && header.version2.cameraHeight < 5000) { cameraHeight = header.version2.cameraHeight; @@ -481,7 +481,7 @@ Checksum Map::load(const string &path, TechTree *techTree, Tileset *tileset) { sc->setObject(NULL); } 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); for(int k = 0; k < techTree->getResourceTypeCount(); ++k) { const ResourceType *rt= techTree->getResourceType(k); @@ -492,7 +492,7 @@ Checksum Map::load(const string &path, TechTree *techTree, Tileset *tileset) { } else{ 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)); sc->setObject(o); } @@ -529,8 +529,8 @@ void Map::init(Tileset *tileset) { class FindBestPos { public: - float distanceFromUnitNoAdjustment; - float distanceFromClickNoAdjustment; + double distanceFromUnitNoAdjustment; + double distanceFromClickNoAdjustment; Vec2i resourcePosNoAdjustment; }; @@ -540,8 +540,8 @@ bool Map::isResourceNear(int frameIndex,const Vec2i &pos, const ResourceType *rt Vec2i *resourceClickPos) const { bool resourceNear = false; - float distanceFromUnit=-1; - float distanceFromClick=-1; + double distanceFromUnit=-1; + double distanceFromClick=-1; 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()); @@ -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) { FindBestPos &bestPosItem = bestPosList[i]; @@ -1115,12 +1115,12 @@ Vec2i Map::computeDestPos( const Vec2i &refUnitPos, const Vec2i &unitPos, return pos; } -std::pair Map::getUnitDistanceToPos(const Unit *unit,Vec2i pos,const UnitType *ut) { +std::pair Map::getUnitDistanceToPos(const Unit *unit,Vec2i pos,const UnitType *ut) { if(unit == NULL) { throw megaglest_runtime_error("unit == NULL"); } - std::pair result(-1,Vec2i(0)); + std::pair result(-1,Vec2i(0)); //int unitId= unit->getId(); Vec2i unitPos= computeDestPos(unit->getPosNotThreadSafe(), unit->getPosNotThreadSafe(), pos); @@ -1136,7 +1136,7 @@ std::pair Map::getUnitDistanceToPos(const Unit *unit,Vec2i pos,cons Vec2i testPos(i,j); 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) { result.first = distance; result.second = testPos; @@ -1155,7 +1155,7 @@ const Unit * Map::findClosestUnitToPos(const Selection *selection, Vec2i origina Vec2i pos = originalBuildPos; - float bestRange = -1; + double bestRange = -1; Vec2i start = pos - Vec2i(1); 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){ Vec2i testPos(i,j); if(isInUnitTypeCells(ut, originalBuildPos,testPos) == false) { - float distance = unitBuilderPos.dist(testPos); + double distance = unitBuilderPos.dist(testPos); if(bestRange < 0 || bestRange > distance) { bestRange = distance; pos = testPos; @@ -1198,7 +1198,7 @@ Vec2i Map::findBestBuildApproach(const Unit *unit, Vec2i originalBuildPos,const Vec2i unitBuilderPos = unit->getPosNotThreadSafe(); Vec2i pos = originalBuildPos; - float bestRange = -1; + double bestRange = -1; Vec2i start = pos - Vec2i(unit->getType()->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) { Vec2i testPos(i,j); if(isInUnitTypeCells(ut, originalBuildPos,testPos) == false) { - float distance = unitBuilderPos.dist(testPos); + double distance = unitBuilderPos.dist(testPos); if(bestRange < 0 || bestRange > distance) { // Check if the cell is occupied by another unit if(isFreeCellOrHasUnit(testPos, unit->getType()->getField(), unit) == true) { @@ -1532,7 +1532,7 @@ void Map::prepareTerrain(const Unit *unit) { // ==================== compute ==================== 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 j=-1; j<=unit->getType()->getSize(); ++j){ Vec2i pos= unit->getPosNotThreadSafe()+Vec2i(i, j); @@ -1641,8 +1641,8 @@ void Map::smoothSurface(Tileset *tileset) { } if (formerObject == NULL) { Object *o = new Object(tileset->getObjectType(9), - getSurfaceCell(i, j)->getVertex(), Vec2i(i, - j)); + Vec3d(getSurfaceCell(i, j)->getVertex()), + Vec2i(i,j)); getSurfaceCell(i, j)->setObject(o); } } @@ -1733,11 +1733,11 @@ void Map::saveGame(XmlNode *rootNode) const { // string title; mapNode->addAttribute("title",title, mapTagReplacements); // float waterLevel; - mapNode->addAttribute("waterLevel",floatToStr(waterLevel,16), mapTagReplacements); + mapNode->addAttribute("waterLevel",doubleToStr(waterLevel,16), mapTagReplacements); // float heightFactor; - mapNode->addAttribute("heightFactor",floatToStr(heightFactor,16), mapTagReplacements); + mapNode->addAttribute("heightFactor",doubleToStr(heightFactor,16), mapTagReplacements); // float cliffLevel; - mapNode->addAttribute("cliffLevel",floatToStr(cliffLevel,16), mapTagReplacements); + mapNode->addAttribute("cliffLevel",doubleToStr(cliffLevel,16), mapTagReplacements); // int cameraHeight; mapNode->addAttribute("cameraHeight",intToStr(cameraHeight), mapTagReplacements); // int w; @@ -1817,7 +1817,7 @@ void Map::saveGame(XmlNode *rootNode) const { // Checksum checksumValue; // mapNode->addAttribute("checksumValue",intToStr(checksumValue.getSum()), mapTagReplacements); // float maxMapHeight; - mapNode->addAttribute("maxMapHeight",floatToStr(maxMapHeight,16), mapTagReplacements); + mapNode->addAttribute("maxMapHeight",doubleToStr(maxMapHeight,16), mapTagReplacements); // string mapFile; mapNode->addAttribute("mapFile",mapFile, mapTagReplacements); } diff --git a/source/glest_game/world/map.h b/source/glest_game/world/map.h index bdb49dd3..8cf7f2ad 100644 --- a/source/glest_game/world/map.h +++ b/source/glest_game/world/map.h @@ -58,7 +58,7 @@ class Cell { private: Unit *units[fieldCount]; //units on this cell Unit *unitsWithEmptyCellMap[fieldCount]; //units with an empty cellmap on this cell - float height; + double height; private: Cell(Cell&); @@ -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 truncateDecimal(height);} + inline double getHeight() const {return truncateDecimal(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 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(height);} + inline void setHeight(double height) {this->height = truncateDecimal(height,16);} inline bool isFree(Field field) const { Unit *unit = getUnit(field); @@ -213,9 +213,9 @@ public: private: string title; - float waterLevel; - float heightFactor; - float cliffLevel; + double waterLevel; + double heightFactor; + double cliffLevel; int cameraHeight; int w; int h; @@ -228,7 +228,7 @@ private: SurfaceCell *surfaceCells; Vec2i *startLocations; Checksum checksumValue; - float maxMapHeight; + double maxMapHeight; string mapFile; private: @@ -296,11 +296,11 @@ public: inline int getSurfaceW() const {return surfaceW;} inline int getSurfaceH() const {return surfaceH;} 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 double getHeightFactor() const {return truncateDecimal(heightFactor,16);} + inline double getWaterLevel() const {return truncateDecimal(waterLevel,16);} + inline double getCliffLevel() const {return truncateDecimal(cliffLevel,16);} inline int getCameraHeight() const {return cameraHeight;} - inline float getMaxMapHeight() const {return truncateDecimal(maxMapHeight);} + inline double getMaxMapHeight() const {return truncateDecimal(maxMapHeight,16);} Vec2i getStartLocation(int locationIndex) const; inline bool getSubmerged(const SurfaceCell *sc) const {return sc->getHeight()getHeight() getUnitDistanceToPos(const Unit *unit,Vec2i pos,const UnitType *ut); + std::pair getUnitDistanceToPos(const Unit *unit,Vec2i pos,const UnitType *ut); //misc bool isNextTo(const Vec2i &pos, const Unit *unit) const; diff --git a/source/shared_lib/include/util/util.h b/source/shared_lib/include/util/util.h index e707e04e..164cf792 100644 --- a/source/shared_lib/include/util/util.h +++ b/source/shared_lib/include/util/util.h @@ -231,10 +231,10 @@ void copyStringToBuffer(char *buffer, int bufferSize, const string& s); //numeric fcs 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); -float saturate(float value); -int round(float f); +double saturate(double value); +int round(double f); //misc bool checkVersionComptability(string clientVersionString, string serverVersionString); diff --git a/source/shared_lib/sources/util/randomgen.cpp b/source/shared_lib/sources/util/randomgen.cpp index 818a3157..2099b38c 100644 --- a/source/shared_lib/sources/util/randomgen.cpp +++ b/source/shared_lib/sources/util/randomgen.cpp @@ -73,23 +73,15 @@ std::string RandomGen::getLastCaller() const { return result; } int RandomGen::randRange(int min, int max,string lastCaller) { - //assert(min<=max); if(min > max) { char szBuf[8096]=""; snprintf(szBuf,8096,"In [%s::%s Line: %d] min > max, min = %d, max = %d",__FILE__,__FUNCTION__,__LINE__,min,max); throw megaglest_runtime_error(szBuf); } -//#ifdef USE_STREFLOP -// int res = streflop::Random(min, max); // streflop -//#else int diff= max-min; - //int res= min + static_cast(truncateDecimal(static_cast(diff+1),2)*RandomGen::rand() / m); double numerator = static_cast(diff + 1) * static_cast(RandomGen::rand(lastCaller)); - int res= min + static_cast(truncateDecimal(numerator / static_cast(m))); - //int res= min + static_cast(truncateDecimal(static_cast(diff+1 * RandomGen::rand()) / static_cast(m))); -//#endif - //assert(res>=min && res<=max); + int res= min + static_cast(truncateDecimal(numerator / static_cast(m),16)); if(res < min || res > max) { 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); @@ -102,22 +94,16 @@ int RandomGen::randRange(int min, int max,string lastCaller) { } double RandomGen::randRange(double min, double max,string lastCaller) { - //assert(min<=max); if(min > max) { char szBuf[8096]=""; snprintf(szBuf,8096,"In [%s::%s Line: %d] min > max, min = %f, max = %f",__FILE__,__FUNCTION__,__LINE__,min,max); throw megaglest_runtime_error(szBuf); } -//#ifdef USE_STREFLOP -// float res = streflop::Random(min, max, randomState); // streflop -//#else - double rand01= static_cast(RandomGen::rand(lastCaller))/(m-1); - double res= min+(max-min)*rand01; - res = truncateDecimal(res); -//#endif + double rand01 = static_cast(RandomGen::rand(lastCaller)) / (m-1); + double res= min + (max - min) * rand01; + res = truncateDecimal(res,16); - //assert(res>=min && res<=max); if(res < min || res > max) { 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); diff --git a/source/shared_lib/sources/util/util.cpp b/source/shared_lib/sources/util/util.cpp index 8de1f56c..7afa38ae 100644 --- a/source/shared_lib/sources/util/util.cpp +++ b/source/shared_lib/sources/util/util.cpp @@ -710,11 +710,11 @@ void copyStringToBuffer(char *buffer, int bufferSize, const string& s){ // ==================== numeric fcs ==================== -float saturate(float value){ - if (value<0.f){ +double saturate(double value) { + if (value < 0.f){ return 0.f; } - if (value>1.f){ + if (value > 1.f){ return 1.f; } return value; @@ -740,17 +740,17 @@ int64 clamp(int64 value, int64 min, int64 max){ return value; } -float clamp(float value, float min, float max){ - if (valuemax){ + if (value > max) { return max; } return value; } -int round(float f){ +int round(double f){ return (int) f; }