revert most doubles back to float and truncate at 6 decimals
This commit is contained in:
parent
0eeb526e27
commit
9e60723296
|
@ -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);
|
||||
|
||||
double dist= unitPos.dist(finalPos);
|
||||
float 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) {
|
||||
double bestHeuristic = factions[unitFactionIndex].closedNodesList.begin()->first;
|
||||
float 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, double &nearestDist) {
|
||||
void PathFinder::processNearestFreePos(const Vec2i &finalPos, int i, int j, int size, Field field, int teamIndex,Vec2i unitPos, Vec2i &nearestPos, float &nearestDist) {
|
||||
Vec2i currPos= finalPos + Vec2i(i, j);
|
||||
if(map->isAproxFreeCells(currPos, size, field, teamIndex)) {
|
||||
double dist= currPos.dist(finalPos);
|
||||
float 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;
|
||||
double nearestDist= unitPos.dist(finalPos);
|
||||
float 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",doubleToStr(curNode->heuristic,6), mapTagReplacements);
|
||||
nodePoolNode->addAttribute("heuristic",floatToStr(curNode->heuristic,6), mapTagReplacements);
|
||||
nodePoolNode->addAttribute("exploredCell",intToStr(curNode->exploredCell), mapTagReplacements);
|
||||
}
|
||||
|
||||
|
|
|
@ -95,7 +95,7 @@ public:
|
|||
Vec2i pos;
|
||||
Node *next;
|
||||
Node *prev;
|
||||
double heuristic;
|
||||
float heuristic;
|
||||
bool exploredCell;
|
||||
};
|
||||
typedef vector<Node*> Nodes;
|
||||
|
@ -119,8 +119,8 @@ public:
|
|||
//fa = NULL;
|
||||
}
|
||||
std::map<Vec2i, bool> openPosList;
|
||||
std::map<double, Nodes> openNodesList;
|
||||
std::map<double, Nodes> closedNodesList;
|
||||
std::map<float, Nodes> openNodesList;
|
||||
std::map<float, Nodes> closedNodesList;
|
||||
std::vector<Node> 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 double heuristic(const Vec2i &pos, const Vec2i &finalPos) {
|
||||
inline static float 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, double &nearestDist);
|
||||
void processNearestFreePos(const Vec2i &finalPos, int i, int j, int size, Field field, int teamIndex,Vec2i unitPos, Vec2i &nearestPos, float &nearestDist);
|
||||
int getPathFindExtendRefreshNodeCount(int factionIndex);
|
||||
|
||||
|
||||
|
|
|
@ -2145,14 +2145,14 @@ void Game::update() {
|
|||
if(currentCameraFollowUnit!=NULL){
|
||||
Vec3f c=currentCameraFollowUnit->getCurrVector();
|
||||
int rotation=currentCameraFollowUnit->getRotation();
|
||||
double angle=rotation+180;
|
||||
float angle=rotation+180;
|
||||
|
||||
c.z=c.z+4*std::cos(degToRad(angle));
|
||||
c.x=c.x+4*std::sin(degToRad(angle));
|
||||
|
||||
c.y=c.y+currentCameraFollowUnit->getType()->getHeight()/2.f+2.0f;
|
||||
|
||||
getGameCameraPtr()->setPos(Vec3f(c));
|
||||
getGameCameraPtr()->setPos(c);
|
||||
|
||||
rotation=(540-rotation)%360;
|
||||
getGameCameraPtr()->rotateToVH(18.0f,rotation);
|
||||
|
@ -4426,7 +4426,7 @@ void Game::startCameraFollowUnit() {
|
|||
if(currentUnit != NULL) {
|
||||
currentCameraFollowUnit = currentUnit;
|
||||
getGameCameraPtr()->setState(GameCamera::sUnit);
|
||||
getGameCameraPtr()->setPos(Vec3f(currentCameraFollowUnit->getCurrVector()));
|
||||
getGameCameraPtr()->setPos(currentCameraFollowUnit->getCurrVector());
|
||||
|
||||
int rotation=currentCameraFollowUnit->getRotation();
|
||||
getGameCameraPtr()->stop();
|
||||
|
@ -5159,7 +5159,7 @@ string Game::getDebugStats(std::map<int,string> &factionDebugInfo) {
|
|||
}
|
||||
|
||||
//intToStr(stats.getFramesToCalculatePlaytime()/GameConstants::updateFps/60
|
||||
str+= "Time: " + doubleToStr(world.getTimeFlow()->getTime(),2) + " [" + doubleToStr((double)world.getStats()->getFramesToCalculatePlaytime() / (double)GameConstants::updateFps / 60.0,2) + "]\n";
|
||||
str+= "Time: " + floatToStr(world.getTimeFlow()->getTime(),2) + " [" + floatToStr((double)world.getStats()->getFramesToCalculatePlaytime() / (float)GameConstants::updateFps / 60.0,2) + "]\n";
|
||||
|
||||
if(SystemFlags::getThreadedLoggerRunning() == true) {
|
||||
str+= "Log buffer count: " + intToStr(SystemFlags::getLogEntryBufferCount())+"\n";
|
||||
|
@ -5203,7 +5203,7 @@ string Game::getDebugStats(std::map<int,string> &factionDebugInfo) {
|
|||
// }
|
||||
str+= "\n";
|
||||
|
||||
str+= "Visible quad area: " + doubleToStr(visibleQuad.area()) +"\n";
|
||||
str+= "Visible quad area: " + floatToStr(visibleQuad.area()) +"\n";
|
||||
// str+= "Visible quad camera area: " + floatToStr(visibleQuadCamera.area()) +"\n";
|
||||
|
||||
// Rect2i boundingRect= visibleQuad.computeBoundingRect();
|
||||
|
|
|
@ -1058,7 +1058,7 @@ void Renderer::setupLighting() {
|
|||
unit->getType()->getLight() && unit->isOperative()) {
|
||||
//printf("$$$ Show light for faction: %s # %d / %d for Unit [%d - %s]\n",world->getFaction(i)->getType()->getName().c_str(),lightCount,maxLights,unit->getId(),unit->getFullName().c_str());
|
||||
|
||||
Vec4f pos= Vec4f(Vec3f(unit->getCurrVector()));
|
||||
Vec4f pos= Vec4f(unit->getCurrVector());
|
||||
pos.y+=4.f;
|
||||
|
||||
GLenum lightEnum= GL_LIGHT0 + lightCount;
|
||||
|
@ -4584,7 +4584,7 @@ void Renderer::renderObjects(const int renderFps) {
|
|||
|
||||
Model *objModel= o->getModelPtr();
|
||||
//objModel->updateInterpolationData(o->getAnimProgress(), true);
|
||||
const Vec3f v= Vec3f(o->getConstPos());
|
||||
const Vec3f v= o->getConstPos();
|
||||
|
||||
if(modelRenderStarted == false) {
|
||||
modelRenderStarted = true;
|
||||
|
@ -4826,7 +4826,7 @@ void Renderer::renderTeamColorCircle(){
|
|||
for(int visibleUnitIndex = 0;
|
||||
visibleUnitIndex < qCache.visibleQuadUnitList.size(); ++visibleUnitIndex) {
|
||||
Unit *unit = qCache.visibleQuadUnitList[visibleUnitIndex];
|
||||
Vec3f currVec= Vec3f(unit->getCurrVectorFlat());
|
||||
Vec3f currVec= unit->getCurrVectorFlat();
|
||||
Vec3f color=unit->getFaction()->getTexture()->getPixmapConst()->getPixel3f(0,0);
|
||||
glColor4f(color.x, color.y, color.z, 0.7f);
|
||||
renderSelectionCircle(currVec, unit->getType()->getSize(), 0.8f, 0.05f);
|
||||
|
@ -4881,7 +4881,7 @@ void Renderer::renderSpecialHighlightUnits(std::map<int,HighlightSpecialUnitInfo
|
|||
|
||||
glColor4f(color.x, color.y, color.z, alpha);
|
||||
|
||||
Vec3f currVec= Vec3f(unit->getCurrVectorFlat());
|
||||
Vec3f currVec= unit->getCurrVectorFlat();
|
||||
renderSelectionCircle(currVec, unit->getType()->getSize(), radius, thickness);
|
||||
}
|
||||
}
|
||||
|
@ -4905,7 +4905,7 @@ void Renderer::renderTeamColorPlane(){
|
|||
for(int visibleUnitIndex = 0;
|
||||
visibleUnitIndex < qCache.visibleQuadUnitList.size(); ++visibleUnitIndex){
|
||||
Unit *unit = qCache.visibleQuadUnitList[visibleUnitIndex];
|
||||
Vec3f currVec= Vec3f(unit->getCurrVectorFlat());
|
||||
Vec3f currVec= unit->getCurrVectorFlat();
|
||||
renderTeamColorEffect(currVec,visibleUnitIndex,unit->getType()->getSize(),
|
||||
unit->getFaction()->getTexture()->getPixmapConst()->getPixel3f(0,0),texture);
|
||||
}
|
||||
|
@ -5022,7 +5022,7 @@ void Renderer::renderUnits(const int renderFps) {
|
|||
glPushMatrix();
|
||||
|
||||
//translate
|
||||
Vec3f currVec= Vec3f(unit->getCurrVectorFlat());
|
||||
Vec3f currVec= unit->getCurrVectorFlat();
|
||||
glTranslatef(currVec.x, currVec.y, currVec.z);
|
||||
|
||||
//rotate
|
||||
|
@ -5193,7 +5193,7 @@ void Renderer::renderMorphEffects(){
|
|||
initialized=true;
|
||||
}
|
||||
|
||||
Vec3f currVec= Vec3f(unit->getCurrVectorFlat());
|
||||
Vec3f currVec= unit->getCurrVectorFlat();
|
||||
currVec=Vec3f(currVec.x,currVec.y+0.3f,currVec.z);
|
||||
if(mType->getField() == fAir && unit->getType()->getField()== fLand) {
|
||||
currVec=Vec3f(currVec.x,currVec.y+game->getWorld()->getTileset()->getAirHeight(),currVec.z);
|
||||
|
@ -5247,7 +5247,7 @@ void Renderer::renderSelectionEffects() {
|
|||
const Unit *unit= selection->getUnit(i);
|
||||
if(unit != NULL) {
|
||||
//translate
|
||||
Vec3f currVec= Vec3f(unit->getCurrVectorFlat());
|
||||
Vec3f currVec= unit->getCurrVectorFlat();
|
||||
currVec.y+= 0.3f;
|
||||
|
||||
//selection circle
|
||||
|
@ -5283,7 +5283,7 @@ void Renderer::renderSelectionEffects() {
|
|||
if(i == 0) {
|
||||
lastPosValue = curPosValue;
|
||||
}
|
||||
Vec3f currVec2 = Vec3f(unit->getVectorFlat(lastPosValue,curPosValue));
|
||||
Vec3f currVec2 = unit->getVectorFlat(lastPosValue,curPosValue);
|
||||
currVec2.y+= 0.3f;
|
||||
renderSelectionCircle(currVec2, 1, selectionCircleRadius);
|
||||
//renderSelectionCircle(currVec2, unit->getType()->getSize(), selectionCircleRadius);
|
||||
|
@ -5315,7 +5315,7 @@ void Renderer::renderSelectionEffects() {
|
|||
int findUnitId = effect.currentAttackBoostUnits[i];
|
||||
Unit *affectedUnit = game->getWorld()->findUnitById(findUnitId);
|
||||
if(affectedUnit != NULL) {
|
||||
Vec3f currVecBoost = Vec3f(affectedUnit->getCurrVectorFlat());
|
||||
Vec3f currVecBoost = affectedUnit->getCurrVectorFlat();
|
||||
currVecBoost.y += 0.3f;
|
||||
|
||||
renderSelectionCircle(currVecBoost, affectedUnit->getType()->getSize(), 1.f);
|
||||
|
@ -5331,7 +5331,7 @@ void Renderer::renderSelectionEffects() {
|
|||
int defaultValue= r->getType()->getDefResPerPatch();
|
||||
float colorValue=static_cast<float>(r->getAmount())/static_cast<float>(defaultValue);
|
||||
glColor4f(0.1f, 0.1f , colorValue, 0.4f);
|
||||
renderSelectionCircle(Vec3f(selectedResourceObject->getPos()),2, selectionCircleRadius);
|
||||
renderSelectionCircle(selectedResourceObject->getPos(),2, selectionCircleRadius);
|
||||
}
|
||||
//target arrow
|
||||
if(selection->getCount() == 1) {
|
||||
|
@ -5361,7 +5361,7 @@ void Renderer::renderSelectionEffects() {
|
|||
Vec3f arrowTarget;
|
||||
Command *c= unit->getCurrCommand();
|
||||
if(c->getUnit() != NULL) {
|
||||
arrowTarget= Vec3f(c->getUnit()->getCurrVectorFlat());
|
||||
arrowTarget= c->getUnit()->getCurrVectorFlat();
|
||||
}
|
||||
else {
|
||||
Vec2i pos= c->getPos();
|
||||
|
@ -5370,7 +5370,7 @@ void Renderer::renderSelectionEffects() {
|
|||
arrowTarget= Vec3f(pos.x, map->getCell(pos)->getHeight(), pos.y);
|
||||
}
|
||||
|
||||
renderArrow(Vec3f(unit->getCurrVectorFlat()), arrowTarget, arrowColor, 0.3f);
|
||||
renderArrow(unit->getCurrVectorFlat(), arrowTarget, arrowColor, 0.3f);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5380,7 +5380,7 @@ void Renderer::renderSelectionEffects() {
|
|||
map->clampPos(pos);
|
||||
|
||||
Vec3f arrowTarget= Vec3f(pos.x, map->getCell(pos)->getHeight(), pos.y);
|
||||
renderArrow(Vec3f(unit->getCurrVectorFlat()), arrowTarget, Vec3f(0.f, 0.f, 1.f), 0.3f);
|
||||
renderArrow(unit->getCurrVectorFlat(), arrowTarget, Vec3f(0.f, 0.f, 1.f), 0.3f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5398,7 +5398,7 @@ void Renderer::renderSelectionEffects() {
|
|||
glColor4f(1.f, 0.f, 0.f, highlight);
|
||||
}
|
||||
|
||||
Vec3f v= Vec3f(unit->getCurrVectorFlat());
|
||||
Vec3f v= unit->getCurrVectorFlat();
|
||||
v.y+= 0.3f;
|
||||
renderSelectionCircle(v, unit->getType()->getSize(), 0.5f+0.4f*highlight );
|
||||
}
|
||||
|
@ -5429,7 +5429,7 @@ void Renderer::renderSelectionEffects() {
|
|||
if(object->isHighlighted()) {
|
||||
float highlight= object->getHightlight();
|
||||
glColor4f(0.1f, 0.1f , 1.0f, highlight);
|
||||
Vec3f v= Vec3f(object->getPos());
|
||||
Vec3f v= object->getPos();
|
||||
v.y+= 0.3f;
|
||||
renderSelectionCircle(v, 2, 0.4f+0.4f*highlight );
|
||||
}
|
||||
|
@ -7434,7 +7434,7 @@ vector<Unit *> Renderer::renderUnitsFast(bool renderingShadows, bool colorPickin
|
|||
glPushMatrix();
|
||||
|
||||
//translate
|
||||
Vec3f currVec= Vec3f(unit->getCurrVectorFlat());
|
||||
Vec3f currVec= unit->getCurrVectorFlat();
|
||||
glTranslatef(currVec.x, currVec.y, currVec.z);
|
||||
|
||||
//rotate
|
||||
|
@ -7537,7 +7537,7 @@ vector<Object *> Renderer::renderObjectsFast(bool renderingShadows, bool resour
|
|||
//objModel->updateInterpolationData(o->getAnimProgress(), true);
|
||||
|
||||
//}
|
||||
const Vec3f v= Vec3f(o->getConstPos());
|
||||
const Vec3f v= o->getConstPos();
|
||||
|
||||
if(colorPickingSelection == false) {
|
||||
glPushName(OBJECT_SELECT_OFFSET+visibleIndex);
|
||||
|
|
|
@ -305,7 +305,7 @@ void Gui::mouseUpLeftGraphics(int x, int y) {
|
|||
if(selection.isCommandable() && random.randRange(0, 1)==0){
|
||||
SoundRenderer::getInstance().playFx(
|
||||
selection.getFrontUnit()->getType()->getSelectionSound(),
|
||||
Vec3f(selection.getFrontUnit()->getCurrVector()),
|
||||
selection.getFrontUnit()->getCurrVector(),
|
||||
gameCamera->getPos());
|
||||
}
|
||||
selectionQuad.disable();
|
||||
|
@ -477,7 +477,7 @@ void Gui::giveDefaultOrders(int x, int y,const Unit *targetUnit, bool paintMouse
|
|||
if(random.randRange(0, 1)==0){
|
||||
SoundRenderer::getInstance().playFx(
|
||||
selection.getFrontUnit()->getType()->getCommandSound(),
|
||||
Vec3f(selection.getFrontUnit()->getCurrVector()),
|
||||
selection.getFrontUnit()->getCurrVector(),
|
||||
gameCamera->getPos());
|
||||
}
|
||||
}
|
||||
|
@ -532,7 +532,7 @@ void Gui::giveTwoClickOrders(int x, int y , bool prepared) {
|
|||
if(random.randRange(0, 1) == 0) {
|
||||
SoundRenderer::getInstance().playFx(
|
||||
selection.getFrontUnit()->getType()->getCommandSound(),
|
||||
Vec3f(selection.getFrontUnit()->getCurrVector()),
|
||||
selection.getFrontUnit()->getCurrVector(),
|
||||
gameCamera->getPos());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -125,8 +125,8 @@ bool CommandGroupUnitSorter::compare(const Unit *l, const Unit *r) {
|
|||
result = curCommandGroupId < commandPeer->getUnitCommandGroupId();
|
||||
}
|
||||
else {
|
||||
double unitDist = l->getCenteredPos().dist(command->getPos());
|
||||
double unitDistPeer = r->getCenteredPos().dist(commandPeer->getPos());
|
||||
float unitDist = l->getCenteredPos().dist(command->getPos());
|
||||
float unitDistPeer = r->getCenteredPos().dist(commandPeer->getPos());
|
||||
|
||||
// Closest unit in commandgroup
|
||||
result = (unitDist < unitDistPeer);
|
||||
|
|
|
@ -388,7 +388,7 @@ void UnitAttackBoostEffectOriginator::saveGame(XmlNode *rootNode) {
|
|||
// class Unit
|
||||
// =====================================================
|
||||
|
||||
const double Unit::ANIMATION_SPEED_MULTIPLIER = 100000.f;
|
||||
const float Unit::ANIMATION_SPEED_MULTIPLIER = 100000.f;
|
||||
//const float Unit::PROGRESS_SPEED_MULTIPLIER = 100000.f;
|
||||
const int64 Unit::PROGRESS_SPEED_MULTIPLIER = 100000;
|
||||
|
||||
|
@ -726,14 +726,14 @@ Vec2i Unit::getCellPos() const {
|
|||
|
||||
//find nearest pos to center that is free
|
||||
Vec2i centeredPos= getCenteredPos();
|
||||
double nearestDist= -1.f;
|
||||
float nearestDist= -1.f;
|
||||
Vec2i nearestPos= pos;
|
||||
|
||||
for(int i=0; i<type->getSize(); ++i){
|
||||
for(int j=0; j<type->getSize(); ++j){
|
||||
if(type->getCellMapCell(i, j, modelFacing)){
|
||||
Vec2i currPos= pos + Vec2i(i, j);
|
||||
double dist= currPos.dist(centeredPos);
|
||||
float dist= currPos.dist(centeredPos);
|
||||
if(nearestDist == -1.f || dist < nearestDist) {
|
||||
nearestDist= dist;
|
||||
nearestPos= currPos;
|
||||
|
@ -836,7 +836,7 @@ int Unit::getProductionPercent() const{
|
|||
return -1;
|
||||
}
|
||||
|
||||
double Unit::getProgressRatio() const{
|
||||
float Unit::getProgressRatio() const{
|
||||
if(anyCommand()){
|
||||
const ProducibleType *produced= commands.front()->getCommandType()->getProduced();
|
||||
if(produced != NULL){
|
||||
|
@ -844,28 +844,28 @@ double Unit::getProgressRatio() const{
|
|||
return 0.f;
|
||||
}
|
||||
|
||||
double help = progress2;
|
||||
float help = progress2;
|
||||
return clamp(help / produced->getProductionTime(), 0.f, 1.f);
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
double Unit::getHpRatio() const {
|
||||
float Unit::getHpRatio() const {
|
||||
if(type == NULL) {
|
||||
char szBuf[8096]="";
|
||||
snprintf(szBuf,8096,"In [%s::%s Line: %d] ERROR: type == NULL, Unit = [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,this->toString().c_str());
|
||||
throw megaglest_runtime_error(szBuf);
|
||||
}
|
||||
|
||||
double maxHpAllowed = type->getTotalMaxHp(&totalUpgrade);
|
||||
float maxHpAllowed = type->getTotalMaxHp(&totalUpgrade);
|
||||
if(maxHpAllowed == 0.f) {
|
||||
return 0.f;
|
||||
}
|
||||
return clamp(static_cast<double>(hp) / maxHpAllowed, 0.f, 1.f);
|
||||
return clamp(static_cast<float>(hp) / maxHpAllowed, 0.f, 1.f);
|
||||
}
|
||||
|
||||
double Unit::getEpRatio() const {
|
||||
float Unit::getEpRatio() const {
|
||||
if(type == NULL) {
|
||||
char szBuf[8096]="";
|
||||
snprintf(szBuf,8096,"In [%s::%s Line: %d] ERROR: type == NULL, Unit = [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,this->toString().c_str());
|
||||
|
@ -876,11 +876,11 @@ double Unit::getEpRatio() const {
|
|||
return 0.f;
|
||||
}
|
||||
else {
|
||||
double maxEpAllowed = type->getTotalMaxEp(&totalUpgrade);
|
||||
float maxEpAllowed = type->getTotalMaxEp(&totalUpgrade);
|
||||
if(maxEpAllowed == 0.f) {
|
||||
return 0.f;
|
||||
}
|
||||
return clamp(static_cast<double>(ep) / maxEpAllowed, 0.f, 1.f);
|
||||
return clamp(static_cast<float>(ep) / maxEpAllowed, 0.f, 1.f);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1225,7 +1225,7 @@ FowAlphaCellsLookupItem Unit::getFogOfWarRadius(bool useCache) const {
|
|||
Vec2i surfPos= Map::toSurfCoords(sightpos);
|
||||
|
||||
//compute max alpha
|
||||
double maxAlpha= 0.0f;
|
||||
float maxAlpha= 0.0f;
|
||||
if(surfPos.x > 1 && surfPos.y > 1 && surfPos.x < map->getSurfaceW() -2 && surfPos.y < map->getSurfaceH() -2) {
|
||||
maxAlpha= 1.f;
|
||||
}
|
||||
|
@ -1234,8 +1234,8 @@ FowAlphaCellsLookupItem Unit::getFogOfWarRadius(bool useCache) const {
|
|||
}
|
||||
|
||||
//compute alpha
|
||||
double alpha = maxAlpha;
|
||||
double dist = this->getPosNotThreadSafe().dist(sightpos);
|
||||
float alpha = maxAlpha;
|
||||
float dist = this->getPosNotThreadSafe().dist(sightpos);
|
||||
if(dist > sightRange) {
|
||||
alpha= clamp(1.f-(dist - sightRange) / (World::indirectSightRange), 0.f, maxAlpha);
|
||||
}
|
||||
|
@ -1424,9 +1424,9 @@ Vec3f Unit::getCurrVectorFlat() const{
|
|||
return getVectorFlat(lastPos, pos);
|
||||
}
|
||||
|
||||
double Unit::getProgressAsFloat() const {
|
||||
double result = (static_cast<double>(progress) / static_cast<double>(PROGRESS_SPEED_MULTIPLIER));
|
||||
result = truncateDecimal<double>(result,6);
|
||||
float Unit::getProgressAsFloat() const {
|
||||
float result = (static_cast<float>(progress) / static_cast<float>(PROGRESS_SPEED_MULTIPLIER));
|
||||
result = truncateDecimal<float>(result,6);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -2023,8 +2023,8 @@ int64 Unit::getHeightFactor(int64 speedMultiplier) {
|
|||
throw megaglest_runtime_error("targetCell == NULL");
|
||||
}
|
||||
|
||||
int64 heightDiff= ((truncateDecimal<double>(unitCell->getHeight(),2) * speedMultiplier) -
|
||||
(truncateDecimal<double>(targetCell->getHeight(),2) * speedMultiplier));
|
||||
int64 heightDiff= ((truncateDecimal<float>(unitCell->getHeight(),2) * speedMultiplier) -
|
||||
(truncateDecimal<float>(targetCell->getHeight(),2) * speedMultiplier));
|
||||
//heightFactor= clamp(speedMultiplier + heightDiff / (5.f * speedMultiplier), 0.2f * speedMultiplier, 5.f * speedMultiplier);
|
||||
heightFactor= clamp(speedMultiplier + heightDiff / (5 * speedMultiplier), (2 * (speedMultiplier / 10)), 5 * speedMultiplier);
|
||||
}
|
||||
|
@ -2328,7 +2328,7 @@ bool Unit::update() {
|
|||
//printf("Test progress = %d for unit [%d - %s]\n",progress,id,getType()->getName().c_str());
|
||||
|
||||
if(isAnimProgressBound() == true) {
|
||||
double targetProgress=0;
|
||||
float targetProgress=0;
|
||||
if(currSkill->getClass() == scBeBuilt) {
|
||||
targetProgress = this->getHpRatio();
|
||||
}
|
||||
|
@ -2342,10 +2342,10 @@ bool Unit::update() {
|
|||
targetProgress = this->getProgressRatio();
|
||||
}
|
||||
|
||||
double targetProgressIntValue = targetProgress * ANIMATION_SPEED_MULTIPLIER;
|
||||
float targetProgressIntValue = targetProgress * ANIMATION_SPEED_MULTIPLIER;
|
||||
if(this->animProgress < targetProgressIntValue) {
|
||||
double diff = targetProgressIntValue - this->animProgress;
|
||||
double progressIncrease = static_cast<double>(this->animProgress) + diff / static_cast<double>(GameConstants::updateFps);
|
||||
float diff = targetProgressIntValue - this->animProgress;
|
||||
float progressIncrease = static_cast<float>(this->animProgress) + diff / static_cast<float>(GameConstants::updateFps);
|
||||
// Ensure we increment at least a value of 1 of the action will be stuck infinitely
|
||||
if(diff > 0.f && GameConstants::updateFps > 0 && progressIncrease == 0.f) {
|
||||
progressIncrease = 1.f;
|
||||
|
|
|
@ -330,7 +330,7 @@ private:
|
|||
static std::map<Unit *,bool> mapMemoryList;
|
||||
#endif
|
||||
|
||||
static const double ANIMATION_SPEED_MULTIPLIER;
|
||||
static const float ANIMATION_SPEED_MULTIPLIER;
|
||||
static const int64 PROGRESS_SPEED_MULTIPLIER;
|
||||
|
||||
public:
|
||||
|
@ -517,8 +517,8 @@ public:
|
|||
|
||||
//inline int getLastAnimProgress() const {return lastAnimProgress;}
|
||||
//inline int getAnimProgress() const {return animProgress;}
|
||||
inline double getLastAnimProgressAsFloat() const {return static_cast<double>(lastAnimProgress) / ANIMATION_SPEED_MULTIPLIER;}
|
||||
inline double getAnimProgressAsFloat() const {return static_cast<double>(animProgress) / ANIMATION_SPEED_MULTIPLIER;}
|
||||
inline float getLastAnimProgressAsFloat() const {return static_cast<float>(lastAnimProgress) / ANIMATION_SPEED_MULTIPLIER;}
|
||||
inline float getAnimProgressAsFloat() const {return static_cast<float>(animProgress) / ANIMATION_SPEED_MULTIPLIER;}
|
||||
|
||||
inline float getHightlight() const {return highlight;}
|
||||
inline int getProgress2() const {return progress2;}
|
||||
|
@ -531,9 +531,9 @@ public:
|
|||
inline int getHp() const {return hp;}
|
||||
inline int getEp() const {return ep;}
|
||||
int getProductionPercent() const;
|
||||
double getProgressRatio() const;
|
||||
double getHpRatio() const;
|
||||
double getEpRatio() const;
|
||||
float getProgressRatio() const;
|
||||
float getHpRatio() const;
|
||||
float getEpRatio() const;
|
||||
inline bool getToBeUndertaken() const {return toBeUndertaken;}
|
||||
inline Vec2i getTargetPos() const {return targetPos;}
|
||||
inline Vec3f getTargetVec() const {return targetVec;}
|
||||
|
@ -742,7 +742,7 @@ public:
|
|||
|
||||
std::string toString(bool crcMode=false) const;
|
||||
bool needToUpdate();
|
||||
double getProgressAsFloat() const;
|
||||
float getProgressAsFloat() const;
|
||||
int64 getUpdateProgress();
|
||||
int64 getDiagonalFactor();
|
||||
int64 getHeightFactor(int64 speedMultiplier=PROGRESS_SPEED_MULTIPLIER);
|
||||
|
|
|
@ -140,7 +140,7 @@ bool AttackBoost::isAffected(const Unit *source, const Unit *dest) const {
|
|||
}
|
||||
|
||||
if(destUnitMightApply == true) {
|
||||
double distance = source->getCenteredPos().dist(dest->getCenteredPos());
|
||||
float distance = source->getCenteredPos().dist(dest->getCenteredPos());
|
||||
if(distance <= radius) {
|
||||
result = true;
|
||||
}
|
||||
|
@ -516,7 +516,7 @@ const AnimationAttributes SkillType::getAnimationAttribute(int index) const {
|
|||
return animationAttributes[index];
|
||||
}
|
||||
|
||||
Model *SkillType::getAnimation(double animProgress, const Unit *unit,
|
||||
Model *SkillType::getAnimation(float animProgress, const Unit *unit,
|
||||
int *lastAnimationIndex, int *animationRandomCycleCount) const {
|
||||
int modelIndex = 0;
|
||||
//printf("Count [%d] animProgress = [%f] for skill [%s] animationRandomCycleCount = %d\n",animations.size(),animProgress,name.c_str(),*animationRandomCycleCount);
|
||||
|
|
|
@ -175,7 +175,7 @@ public:
|
|||
int getHpCost() const {return hpCost;}
|
||||
int getSpeed() const {return speed;}
|
||||
int getAnimSpeed() const {return animSpeed;}
|
||||
Model *getAnimation(double animProgress=0, const Unit *unit=NULL, int *lastAnimationIndex=NULL, int *animationRandomCycleCount=NULL) const;
|
||||
Model *getAnimation(float animProgress=0, const Unit *unit=NULL, int *lastAnimationIndex=NULL, int *animationRandomCycleCount=NULL) const;
|
||||
StaticSound *getSound() const {return sounds.getRandSound();}
|
||||
float getSoundStartTime() const {return soundStartTime;}
|
||||
|
||||
|
|
|
@ -529,8 +529,8 @@ void Map::init(Tileset *tileset) {
|
|||
|
||||
class FindBestPos {
|
||||
public:
|
||||
double distanceFromUnitNoAdjustment;
|
||||
double distanceFromClickNoAdjustment;
|
||||
float distanceFromUnitNoAdjustment;
|
||||
float distanceFromClickNoAdjustment;
|
||||
Vec2i resourcePosNoAdjustment;
|
||||
};
|
||||
|
||||
|
@ -540,8 +540,8 @@ bool Map::isResourceNear(int frameIndex,const Vec2i &pos, const ResourceType *rt
|
|||
Vec2i *resourceClickPos) const {
|
||||
|
||||
bool resourceNear = false;
|
||||
double distanceFromUnit=-1;
|
||||
double distanceFromClick=-1;
|
||||
float distanceFromUnit=-1;
|
||||
float 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
|
|||
}
|
||||
}
|
||||
|
||||
double bestUnitDist = distanceFromUnit;
|
||||
float 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<double,Vec2i> Map::getUnitDistanceToPos(const Unit *unit,Vec2i pos,const UnitType *ut) {
|
||||
std::pair<float,Vec2i> Map::getUnitDistanceToPos(const Unit *unit,Vec2i pos,const UnitType *ut) {
|
||||
if(unit == NULL) {
|
||||
throw megaglest_runtime_error("unit == NULL");
|
||||
}
|
||||
|
||||
std::pair<double,Vec2i> result(-1,Vec2i(0));
|
||||
std::pair<float,Vec2i> result(-1,Vec2i(0));
|
||||
//int unitId= unit->getId();
|
||||
Vec2i unitPos= computeDestPos(unit->getPosNotThreadSafe(), unit->getPosNotThreadSafe(), pos);
|
||||
|
||||
|
@ -1136,7 +1136,7 @@ std::pair<double,Vec2i> Map::getUnitDistanceToPos(const Unit *unit,Vec2i pos,con
|
|||
Vec2i testPos(i,j);
|
||||
|
||||
if(ut == NULL || isInUnitTypeCells(ut, pos,testPos) == false) {
|
||||
double distance = unitPos.dist(testPos);
|
||||
float 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;
|
||||
|
||||
double bestRange = -1;
|
||||
float 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) {
|
||||
double distance = unitBuilderPos.dist(testPos);
|
||||
float 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;
|
||||
|
||||
double bestRange = -1;
|
||||
float 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) {
|
||||
double distance = unitBuilderPos.dist(testPos);
|
||||
float 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) {
|
||||
|
|
|
@ -346,7 +346,7 @@ public:
|
|||
bool isInUnitTypeCells(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;
|
||||
std::pair<double,Vec2i> getUnitDistanceToPos(const Unit *unit,Vec2i pos,const UnitType *ut);
|
||||
std::pair<float,Vec2i> getUnitDistanceToPos(const Unit *unit,Vec2i pos,const UnitType *ut);
|
||||
|
||||
//misc
|
||||
bool isNextTo(const Vec2i &pos, const Unit *unit) const;
|
||||
|
|
|
@ -123,7 +123,7 @@ bool UnitUpdater::updateUnit(Unit *unit) {
|
|||
if(soundStartTime >= unit->getLastAnimProgressAsFloat() && soundStartTime < unit->getAnimProgressAsFloat()) {
|
||||
if(map->getSurfaceCell(Map::toSurfCoords(unit->getPos()))->isVisible(world->getThisTeamIndex()) ||
|
||||
(game->getWorld()->showWorldForPlayer(game->getWorld()->getThisTeamIndex()) == true)) {
|
||||
soundRenderer.playFx(currSkill->getSound(), Vec3f(unit->getCurrVector()), gameCamera->getPos());
|
||||
soundRenderer.playFx(currSkill->getSound(), unit->getCurrVector(), gameCamera->getPos());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -276,7 +276,7 @@ bool UnitUpdater::updateUnit(Unit *unit) {
|
|||
if(Config::getInstance().getBool("DisableWaterSounds","false") == false) {
|
||||
soundRenderer.playFx(
|
||||
CoreData::getInstance().getWaterSound(),
|
||||
Vec3f(unit->getCurrVector()),
|
||||
unit->getCurrVector(),
|
||||
gameCamera->getPos()
|
||||
);
|
||||
|
||||
|
@ -713,7 +713,7 @@ void UnitUpdater::updateAttackStopped(Unit *unit, int frameIndex) {
|
|||
return;
|
||||
}
|
||||
|
||||
double distToUnit=-1;
|
||||
float distToUnit=-1;
|
||||
std::pair<bool,Unit *> result = make_pair(false,(Unit *)NULL);
|
||||
unitBeingAttacked(result, unit, asct->getAttackSkillType(), &distToUnit);
|
||||
if(result.first == true) {
|
||||
|
@ -749,10 +749,10 @@ void UnitUpdater::updateAttackStopped(Unit *unit, int frameIndex) {
|
|||
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld --------------------------- [END OF METHOD] ---------------------------\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
|
||||
}
|
||||
|
||||
void UnitUpdater::unitBeingAttacked(std::pair<bool,Unit *> &result, const Unit *unit, const AttackSkillType *ast, double *currentDistToUnit) {
|
||||
void UnitUpdater::unitBeingAttacked(std::pair<bool,Unit *> &result, const Unit *unit, const AttackSkillType *ast, float *currentDistToUnit) {
|
||||
//std::pair<bool,Unit *> result = make_pair(false,(Unit *)NULL);
|
||||
|
||||
double distToUnit = -1;
|
||||
float distToUnit = -1;
|
||||
if(currentDistToUnit != NULL) {
|
||||
distToUnit = *currentDistToUnit;
|
||||
}
|
||||
|
@ -787,7 +787,7 @@ void UnitUpdater::unitBeingAttacked(std::pair<bool,Unit *> &result, const Unit *
|
|||
std::pair<bool,Unit *> UnitUpdater::unitBeingAttacked(const Unit *unit) {
|
||||
std::pair<bool,Unit *> result = make_pair(false,(Unit *)NULL);
|
||||
|
||||
double distToUnit = -1;
|
||||
float distToUnit = -1;
|
||||
for(unsigned int i = 0; i < unit->getType()->getSkillTypeCount(); ++i) {
|
||||
const SkillType *st = unit->getType()->getSkillType(i);
|
||||
const AttackSkillType *ast = dynamic_cast<const AttackSkillType *>(st);
|
||||
|
@ -931,7 +931,7 @@ void UnitUpdater::updateBuild(Unit *unit, int frameIndex) {
|
|||
(game->getWorld()->showWorldForPlayer(game->getWorld()->getThisTeamIndex()) == true)) {
|
||||
SoundRenderer::getInstance().playFx(
|
||||
bct->getStartSound(),
|
||||
Vec3f(unit->getCurrVector()),
|
||||
unit->getCurrVector(),
|
||||
gameCamera->getPos());
|
||||
}
|
||||
|
||||
|
@ -1023,7 +1023,7 @@ void UnitUpdater::updateBuild(Unit *unit, int frameIndex) {
|
|||
(game->getWorld()->showWorldForPlayer(game->getWorld()->getThisTeamIndex()) == true)) {
|
||||
SoundRenderer::getInstance().playFx(
|
||||
bct->getBuiltSound(),
|
||||
Vec3f(unit->getCurrVector()),
|
||||
unit->getCurrVector(),
|
||||
gameCamera->getPos());
|
||||
}
|
||||
}
|
||||
|
@ -2210,8 +2210,8 @@ void UnitUpdater::hit(Unit *attacker, const AttackSkillType* ast, const Vec2i &t
|
|||
attacker->setLastAttackedUnitId(attacked->getId());
|
||||
scriptManager->onUnitAttacking(attacker);
|
||||
|
||||
double distance = pci.getPos().dist(targetPos);
|
||||
distance = truncateDecimal<double>(distance,6);
|
||||
float distance = pci.getPos().dist(targetPos);
|
||||
distance = truncateDecimal<float>(distance,6);
|
||||
damage(attacker, ast, attacked, distance);
|
||||
}
|
||||
}
|
||||
|
@ -2225,7 +2225,7 @@ void UnitUpdater::hit(Unit *attacker, const AttackSkillType* ast, const Vec2i &t
|
|||
}
|
||||
}
|
||||
|
||||
void UnitUpdater::damage(Unit *attacker, const AttackSkillType* ast, Unit *attacked, double distance) {
|
||||
void UnitUpdater::damage(Unit *attacker, const AttackSkillType* ast, Unit *attacked, float distance) {
|
||||
if(attacker == NULL) {
|
||||
throw megaglest_runtime_error("attacker == NULL");
|
||||
}
|
||||
|
@ -2237,11 +2237,11 @@ void UnitUpdater::damage(Unit *attacker, const AttackSkillType* ast, Unit *attac
|
|||
}
|
||||
|
||||
//get vars
|
||||
double damage = ast->getTotalAttackStrength(attacker->getTotalUpgrade());
|
||||
float damage = ast->getTotalAttackStrength(attacker->getTotalUpgrade());
|
||||
int var = ast->getAttackVar();
|
||||
int armor = attacked->getType()->getTotalArmor(attacked->getTotalUpgrade());
|
||||
double damageMultiplier = world->getTechTree()->getDamageMultiplier(ast->getAttackType(), attacked->getType()->getArmorType());
|
||||
damageMultiplier = truncateDecimal<double>(damageMultiplier,6);
|
||||
float damageMultiplier = world->getTechTree()->getDamageMultiplier(ast->getAttackType(), attacked->getType()->getArmorType());
|
||||
damageMultiplier = truncateDecimal<float>(damageMultiplier,6);
|
||||
|
||||
//compute damage
|
||||
//damage += random.randRange(-var, var);
|
||||
|
@ -2249,7 +2249,7 @@ void UnitUpdater::damage(Unit *attacker, const AttackSkillType* ast, Unit *attac
|
|||
damage /= distance+1;
|
||||
damage -= armor;
|
||||
damage *= damageMultiplier;
|
||||
damage = truncateDecimal<double>(damage,6);
|
||||
damage = truncateDecimal<float>(damage,6);
|
||||
|
||||
if(damage < 1) {
|
||||
damage= 1;
|
||||
|
@ -2524,10 +2524,10 @@ bool UnitUpdater::unitOnRange(Unit *unit, int range, Unit **rangedPtr,
|
|||
}
|
||||
|
||||
//attack enemies that can attack first
|
||||
double distToUnit= -1;
|
||||
float distToUnit= -1;
|
||||
Unit* enemySeen= NULL;
|
||||
|
||||
double distToStandingUnit= -1;
|
||||
float distToStandingUnit= -1;
|
||||
Unit* attackingEnemySeen= NULL;
|
||||
ControlType controlType= unit->getFaction()->getControlType();
|
||||
bool isUltra= controlType == ctCpuUltra || controlType == ctNetworkCpuUltra;
|
||||
|
@ -2547,7 +2547,7 @@ bool UnitUpdater::unitOnRange(Unit *unit, int range, Unit **rangedPtr,
|
|||
|
||||
// Attackers get first priority
|
||||
if(enemy->getType()->hasSkillClass(scAttack) == true) {
|
||||
double currentDist = unit->getCenteredPos().dist(enemy->getCenteredPos());
|
||||
float currentDist = unit->getCenteredPos().dist(enemy->getCenteredPos());
|
||||
|
||||
// Select closest attacking unit
|
||||
if(distToUnit < 0 || currentDist< distToUnit) {
|
||||
|
@ -2598,8 +2598,8 @@ bool UnitUpdater::unitOnRange(Unit *unit, int range, Unit **rangedPtr,
|
|||
Vec2f enemyFloatCenter = enemyUnit->getFloatCenteredPos();
|
||||
// find nearest Attack and cleanup old dates
|
||||
AttackWarningData *nearest = NULL;
|
||||
double currentDistance = 0.f;
|
||||
double nearestDistance = 0.f;
|
||||
float currentDistance = 0.f;
|
||||
float nearestDistance = 0.f;
|
||||
|
||||
MutexSafeWrapper safeMutex(&mutexAttackWarnings,string(__FILE__) + "_" + intToStr(__LINE__));
|
||||
for(int i = attackWarnings.size() - 1; i >= 0; --i) {
|
||||
|
@ -2866,7 +2866,7 @@ void ParticleDamager::update(ParticleSystem *particleSystem) {
|
|||
//play sound
|
||||
StaticSound *projSound= ast->getProjSound();
|
||||
if(particleSystem->getVisible() && projSound != NULL) {
|
||||
SoundRenderer::getInstance().playFx(projSound, Vec3f(attacker->getCurrVector()), gameCamera->getPos());
|
||||
SoundRenderer::getInstance().playFx(projSound, attacker->getCurrVector(), gameCamera->getPos());
|
||||
}
|
||||
}
|
||||
particleSystem->setObserver(NULL);
|
||||
|
|
|
@ -124,7 +124,7 @@ public:
|
|||
|
||||
inline unsigned int getAttackWarningCount() const { return attackWarnings.size(); }
|
||||
std::pair<bool,Unit *> unitBeingAttacked(const Unit *unit);
|
||||
void unitBeingAttacked(std::pair<bool,Unit *> &result, const Unit *unit, const AttackSkillType *ast,double *currentDistToUnit=NULL);
|
||||
void unitBeingAttacked(std::pair<bool,Unit *> &result, const Unit *unit, const AttackSkillType *ast,float *currentDistToUnit=NULL);
|
||||
vector<Unit*> enemyUnitsOnRange(const Unit *unit,const AttackSkillType *ast);
|
||||
void findEnemiesForCell(const Vec2i pos, int size, int sightRange, const Faction *faction, vector<Unit*> &enemies, bool attackersOnly) const;
|
||||
|
||||
|
@ -142,7 +142,7 @@ private:
|
|||
//attack
|
||||
void hit(Unit *attacker);
|
||||
void hit(Unit *attacker, const AttackSkillType* ast, const Vec2i &targetPos, Field targetField);
|
||||
void damage(Unit *attacker, const AttackSkillType* ast, Unit *attacked, double distance);
|
||||
void damage(Unit *attacker, const AttackSkillType* ast, Unit *attacked, float distance);
|
||||
void startAttackParticleSystem(Unit *unit);
|
||||
|
||||
//misc
|
||||
|
|
|
@ -1164,7 +1164,7 @@ void World::addAttackEffects(const Unit *unit) {
|
|||
|
||||
//returns the nearest unit that can store a type of resource given a position and a faction
|
||||
Unit *World::nearestStore(const Vec2i &pos, int factionIndex, const ResourceType *rt) {
|
||||
double currDist = infinity;
|
||||
float currDist = infinity;
|
||||
Unit *currUnit= NULL;
|
||||
|
||||
if(factionIndex >= getFactionCount()) {
|
||||
|
@ -1174,7 +1174,7 @@ Unit *World::nearestStore(const Vec2i &pos, int factionIndex, const ResourceType
|
|||
for(int i=0; i < getFaction(factionIndex)->getUnitCount(); ++i) {
|
||||
Unit *u= getFaction(factionIndex)->getUnit(i);
|
||||
if(u != NULL) {
|
||||
double tmpDist= u->getPos().dist(pos);
|
||||
float tmpDist= u->getPos().dist(pos);
|
||||
if(tmpDist < currDist && u->getType() != NULL && u->getType()->getStore(rt) > 0 && u->isOperative()) {
|
||||
currDist= tmpDist;
|
||||
currUnit= u;
|
||||
|
@ -2348,7 +2348,7 @@ void World::exploreCells(const Vec2i &newPos, int sightRange, int teamIndex) {
|
|||
}
|
||||
|
||||
//explore
|
||||
double posLength = currRelPos.length();
|
||||
float posLength = currRelPos.length();
|
||||
//if(Vec2i(0).dist(currRelPos) < surfSightRange + indirectSightRange + 1) {
|
||||
if(posLength < surfSightRange + indirectSightRange + 1) {
|
||||
sc->setExplored(teamIndex, true);
|
||||
|
|
|
@ -233,7 +233,7 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
double area() {
|
||||
float area() {
|
||||
Vec2i v0= p[3]-p[0];
|
||||
Vec2i v1= p[1]-p[2];
|
||||
|
||||
|
@ -312,54 +312,6 @@ inline T radToDeg(T rad){
|
|||
//#endif
|
||||
//}
|
||||
|
||||
template<typename T>
|
||||
inline T truncateDecimal(const T &value, int precision=6) {
|
||||
|
||||
/*
|
||||
int iSigned = value >= 0 ? 1: -1;
|
||||
|
||||
#ifdef USE_STREFLOP
|
||||
unsigned int uiTemp = (unsigned int)(value * streflop::pow((streflop::Simple)10, (streflop::Simple)precision)) * iSigned; //Note I'm using unsigned int so that I can increase the precision of the truncate
|
||||
T result = (((T)uiTemp) / streflop::pow((streflop::Simple)10,(streflop::Simple)precision) * iSigned);
|
||||
#else
|
||||
unsigned int uiTemp = (value * pow((T)10, precision)) * iSigned; //Note I'm using unsigned int so that I can increase the precision of the truncate
|
||||
T result = (((double)uiTemp) / pow((T)10,precision) * iSigned);
|
||||
#endif
|
||||
return result;
|
||||
*/
|
||||
|
||||
T precNum = 0;
|
||||
if(precision == 0) {
|
||||
precNum = 1;
|
||||
}
|
||||
else if(precision == 1) {
|
||||
precNum = 10;
|
||||
}
|
||||
else if(precision == 2) {
|
||||
precNum = 100;
|
||||
}
|
||||
else if(precision == 3) {
|
||||
precNum = 1000;
|
||||
}
|
||||
else if(precision == 4) {
|
||||
precNum = 10000;
|
||||
}
|
||||
else if(precision == 5) {
|
||||
precNum = 100000;
|
||||
}
|
||||
else if(precision == 6) {
|
||||
precNum = 1000000;
|
||||
}
|
||||
else {
|
||||
precNum = std::pow((T)10,(T)precision);
|
||||
}
|
||||
|
||||
int64 resultInt = (T)value * (T)precNum;
|
||||
|
||||
T result = (long double)resultInt / precNum;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
}}//end namespace
|
||||
|
||||
|
|
|
@ -24,10 +24,61 @@
|
|||
//#include <tr1/unordered_map>
|
||||
//using namespace std::tr1;
|
||||
|
||||
#include "data_types.h"
|
||||
#include "leak_dumper.h"
|
||||
|
||||
using namespace Shared::Platform;
|
||||
|
||||
namespace Shared{ namespace Graphics{
|
||||
|
||||
template<typename T>
|
||||
inline T truncateDecimal(const T &value, int precision=6) {
|
||||
|
||||
/*
|
||||
int iSigned = value >= 0 ? 1: -1;
|
||||
|
||||
#ifdef USE_STREFLOP
|
||||
unsigned int uiTemp = (unsigned int)(value * streflop::pow((streflop::Simple)10, (streflop::Simple)precision)) * iSigned; //Note I'm using unsigned int so that I can increase the precision of the truncate
|
||||
T result = (((T)uiTemp) / streflop::pow((streflop::Simple)10,(streflop::Simple)precision) * iSigned);
|
||||
#else
|
||||
unsigned int uiTemp = (value * pow((T)10, precision)) * iSigned; //Note I'm using unsigned int so that I can increase the precision of the truncate
|
||||
T result = (((double)uiTemp) / pow((T)10,precision) * iSigned);
|
||||
#endif
|
||||
return result;
|
||||
*/
|
||||
|
||||
T precNum = 0;
|
||||
if(precision == 0) {
|
||||
precNum = 1;
|
||||
}
|
||||
else if(precision == 1) {
|
||||
precNum = 10;
|
||||
}
|
||||
else if(precision == 2) {
|
||||
precNum = 100;
|
||||
}
|
||||
else if(precision == 3) {
|
||||
precNum = 1000;
|
||||
}
|
||||
else if(precision == 4) {
|
||||
precNum = 10000;
|
||||
}
|
||||
else if(precision == 5) {
|
||||
precNum = 100000;
|
||||
}
|
||||
else if(precision == 6) {
|
||||
precNum = 1000000;
|
||||
}
|
||||
else {
|
||||
precNum = std::pow((T)10,(T)precision);
|
||||
}
|
||||
|
||||
int64 resultInt = (T)value * (T)precNum;
|
||||
|
||||
T result = (long double)resultInt / precNum;
|
||||
return result;
|
||||
}
|
||||
|
||||
inline std::vector<std::string> TokenizeString(const std::string str,const std::string delimiters) {
|
||||
std::vector<std::string> tokens;
|
||||
// Assume textLine contains the line of text to parse.
|
||||
|
@ -206,8 +257,10 @@ public:
|
|||
return x*v.x+y*v.y;
|
||||
}
|
||||
|
||||
inline double dist(const Vec2<T> &v) const{
|
||||
return Vec2<T>(v-*this).length();
|
||||
inline float dist(const Vec2<T> &v) const{
|
||||
float distance = Vec2<T>(v-*this).length();
|
||||
distance = truncateDecimal<float>(distance,6);
|
||||
return distance;
|
||||
}
|
||||
|
||||
// strict week ordering, so Vec2<T> can be used as key for set<> or map<>
|
||||
|
@ -215,7 +268,7 @@ public:
|
|||
return x < v.x || (x == v.x && y < v.y);
|
||||
}
|
||||
|
||||
inline double length() const {
|
||||
inline float length() const {
|
||||
//#ifdef USE_STREFLOP
|
||||
// if(requireAccuracy == true) {
|
||||
// return static_cast<float>(streflop::sqrt(static_cast<streflop::Simple>(x*x + y*y)));
|
||||
|
@ -224,7 +277,9 @@ public:
|
|||
//#else
|
||||
// return static_cast<float>(sqrt(static_cast<float>(x*x + y*y)));
|
||||
//#endif
|
||||
return static_cast<double>(std::sqrt(static_cast<double>(x*x + y*y)));
|
||||
float len = static_cast<float>(std::sqrt(static_cast<float>(x*x + y*y)));
|
||||
len = truncateDecimal<float>(len,6);
|
||||
return len;
|
||||
}
|
||||
|
||||
inline void normalize(){
|
||||
|
@ -233,7 +288,7 @@ public:
|
|||
y/= m;
|
||||
}
|
||||
|
||||
inline Vec2<T> rotate(double rad) {
|
||||
inline Vec2<T> rotate(float rad) {
|
||||
// const float
|
||||
//#ifdef USE_STREFLOP
|
||||
// c = streflop::cosf(rad),
|
||||
|
@ -242,13 +297,13 @@ public:
|
|||
// c = cosf(rad),
|
||||
// s = sinf(rad);
|
||||
//#endif
|
||||
double c = std::cos(rad),
|
||||
float c = std::cos(rad),
|
||||
s = std::sin(rad);
|
||||
|
||||
return Vec2<T>(x*c-y*s,x*s+y*c);
|
||||
}
|
||||
|
||||
inline Vec2<T> rotateAround(double rad,const Vec2<T>& pt){
|
||||
inline Vec2<T> rotateAround(float rad,const Vec2<T>& pt) {
|
||||
return pt+(*this-pt).rotate(rad);
|
||||
}
|
||||
|
||||
|
@ -452,11 +507,13 @@ public:
|
|||
return x*v.x + y*v.y + z*v.z;
|
||||
}
|
||||
|
||||
inline double dist(const Vec3<T> &v) const{
|
||||
return Vec3<T>(v-*this).length();
|
||||
inline float dist(const Vec3<T> &v) const {
|
||||
float distance = Vec3<T>(v-*this).length();
|
||||
distance = truncateDecimal<float>(distance,6);
|
||||
return distance;
|
||||
}
|
||||
|
||||
inline double length() const {
|
||||
inline float length() const {
|
||||
//#ifdef USE_STREFLOP
|
||||
// if(requireAccuracy == true) {
|
||||
// return static_cast<float>(streflop::sqrt(static_cast<streflop::Simple>(x*x + y*y + z*z)));
|
||||
|
@ -465,7 +522,9 @@ public:
|
|||
//#else
|
||||
// return static_cast<float>(sqrt(x*x + y*y + z*z));
|
||||
//#endif
|
||||
return static_cast<double>(std::sqrt(x*x + y*y + z*z));
|
||||
float len = static_cast<float>(std::sqrt(x*x + y*y + z*z));
|
||||
len = truncateDecimal<float>(len,6);
|
||||
return len;
|
||||
}
|
||||
|
||||
inline void normalize() {
|
||||
|
|
|
@ -43,7 +43,7 @@ public:
|
|||
void init(int seed);
|
||||
|
||||
int randRange(int min, int max,std::string lastCaller="");
|
||||
double randRange(double min, double max,std::string lastCaller="");
|
||||
float randRange(float min, float max,std::string lastCaller="");
|
||||
|
||||
int getLastNumber() const { return lastNumber; }
|
||||
void setLastNumber(int value) { lastNumber = value; }
|
||||
|
|
|
@ -231,10 +231,10 @@ void copyStringToBuffer(char *buffer, int bufferSize, const string& s);
|
|||
|
||||
//numeric fcs
|
||||
int clamp(int value, int min, int max);
|
||||
double clamp(double value, double min, double max);
|
||||
float clamp(float value, float min, float max);
|
||||
int64 clamp(int64 value, int64 min, int64 max);
|
||||
double saturate(double value);
|
||||
int round(double f);
|
||||
float saturate(float value);
|
||||
int round(float f);
|
||||
|
||||
//misc
|
||||
bool checkVersionComptability(string clientVersionString, string serverVersionString);
|
||||
|
|
|
@ -109,7 +109,7 @@ void ParticleRendererGl::renderSystem(ParticleSystem *ps){
|
|||
for(int i=0; i<ps->getAliveParticleCount(); ++i){
|
||||
const Particle *particle= ps->getParticle(i);
|
||||
float size= particle->getSize()/2.0f;
|
||||
Vec3f pos= Vec3f(particle->getPos());
|
||||
Vec3f pos= particle->getPos();
|
||||
Vec4f color= particle->getColor();
|
||||
|
||||
vertexBuffer[bufferIndex] = pos - (rightVector - upVector) * size;
|
||||
|
@ -159,8 +159,8 @@ void ParticleRendererGl::renderSystemLine(ParticleSystem *ps){
|
|||
particle= ps->getParticle(i);
|
||||
Vec4f color= particle->getColor();
|
||||
|
||||
vertexBuffer[bufferIndex] = Vec3f(particle->getPos());
|
||||
vertexBuffer[bufferIndex+1] = Vec3f(particle->getLastPos());
|
||||
vertexBuffer[bufferIndex] = particle->getPos();
|
||||
vertexBuffer[bufferIndex+1] = particle->getLastPos();
|
||||
|
||||
colorBuffer[bufferIndex]= color;
|
||||
colorBuffer[bufferIndex+1]= color;
|
||||
|
@ -203,8 +203,8 @@ void ParticleRendererGl::renderSystemLineAlpha(ParticleSystem *ps){
|
|||
particle= ps->getParticle(i);
|
||||
Vec4f color= particle->getColor();
|
||||
|
||||
vertexBuffer[bufferIndex] = Vec3f(particle->getPos());
|
||||
vertexBuffer[bufferIndex+1] = Vec3f(particle->getLastPos());
|
||||
vertexBuffer[bufferIndex] = particle->getPos();
|
||||
vertexBuffer[bufferIndex+1] = particle->getLastPos();
|
||||
|
||||
colorBuffer[bufferIndex]= color;
|
||||
colorBuffer[bufferIndex+1]= color;
|
||||
|
@ -236,11 +236,11 @@ void ParticleRendererGl::renderModel(GameParticleSystem *ps, ModelRenderer *mr){
|
|||
glPushMatrix();
|
||||
|
||||
//translate
|
||||
Vec3f pos= Vec3f(ps->getPos());
|
||||
Vec3f pos= ps->getPos();
|
||||
glTranslatef(pos.x, pos.y, pos.z);
|
||||
|
||||
//rotate
|
||||
Vec3f direction= Vec3f(ps->getDirection());
|
||||
Vec3f direction= ps->getDirection();
|
||||
Vec3f flatDirection= Vec3f(direction.x, 0.f, direction.z);
|
||||
Vec3f rotVector= Vec3f(0.f, 1.f, 0.f).cross(flatDirection);
|
||||
|
||||
|
|
|
@ -80,8 +80,8 @@ int RandomGen::randRange(int min, int max,string lastCaller) {
|
|||
}
|
||||
|
||||
int diff= max-min;
|
||||
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),6));
|
||||
float numerator = static_cast<float>(diff + 1) * static_cast<float>(RandomGen::rand(lastCaller));
|
||||
int res= min + static_cast<int>(truncateDecimal<float>(numerator / static_cast<float>(m),6));
|
||||
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);
|
||||
|
@ -93,16 +93,16 @@ int RandomGen::randRange(int min, int max,string lastCaller) {
|
|||
return res;
|
||||
}
|
||||
|
||||
double RandomGen::randRange(double min, double max,string lastCaller) {
|
||||
float RandomGen::randRange(float min, float max,string lastCaller) {
|
||||
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);
|
||||
}
|
||||
|
||||
double rand01 = static_cast<double>(RandomGen::rand(lastCaller)) / (m-1);
|
||||
double res= min + (max - min) * rand01;
|
||||
res = truncateDecimal<double>(res,6);
|
||||
float rand01 = static_cast<float>(RandomGen::rand(lastCaller)) / (m-1);
|
||||
float res= min + (max - min) * rand01;
|
||||
res = truncateDecimal<float>(res,6);
|
||||
|
||||
if(res < min || res > max) {
|
||||
char szBuf[8096]="";
|
||||
|
|
|
@ -710,7 +710,7 @@ void copyStringToBuffer(char *buffer, int bufferSize, const string& s){
|
|||
|
||||
// ==================== numeric fcs ====================
|
||||
|
||||
double saturate(double value) {
|
||||
float saturate(float value) {
|
||||
if (value < 0.f){
|
||||
return 0.f;
|
||||
}
|
||||
|
@ -740,7 +740,7 @@ int64 clamp(int64 value, int64 min, int64 max){
|
|||
return value;
|
||||
}
|
||||
|
||||
double clamp(double value, double min, double max) {
|
||||
float clamp(float value, float min, float max) {
|
||||
if (value < min) {
|
||||
return min;
|
||||
}
|
||||
|
@ -750,7 +750,7 @@ double clamp(double value, double min, double max) {
|
|||
return value;
|
||||
}
|
||||
|
||||
int round(double f){
|
||||
int round(float f){
|
||||
return (int) f;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue