- attempt to fix additional oos issues

This commit is contained in:
Mark Vejvoda 2013-09-30 17:38:26 +00:00
parent dc944b2a79
commit de8b083329
17 changed files with 330 additions and 345 deletions

View File

@ -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",doubleToStr(curNode->heuristic,16), mapTagReplacements); nodePoolNode->addAttribute("heuristic",doubleToStr(curNode->heuristic,10), mapTagReplacements);
nodePoolNode->addAttribute("exploredCell",intToStr(curNode->exploredCell), mapTagReplacements); nodePoolNode->addAttribute("exploredCell",intToStr(curNode->exploredCell), mapTagReplacements);
} }

View File

@ -6242,7 +6242,7 @@ string Game::saveGame(string name, string path) {
//bool showFullConsole; //bool showFullConsole;
//bool mouseMoved; //bool mouseMoved;
//float scrollSpeed; //float scrollSpeed;
gameNode->addAttribute("scrollSpeed",floatToStr(scrollSpeed,16), mapTagReplacements); gameNode->addAttribute("scrollSpeed",floatToStr(scrollSpeed,10), mapTagReplacements);
//bool camLeftButtonDown; //bool camLeftButtonDown;
//bool camRightButtonDown; //bool camRightButtonDown;
//bool camUpButtonDown; //bool camUpButtonDown;
@ -6336,8 +6336,8 @@ string Game::saveGame(string name, string path) {
HighlightSpecialUnitInfo &info = iterMap->second; HighlightSpecialUnitInfo &info = iterMap->second;
XmlNode *infoNode = unitHighlightListNode->addChild("info"); XmlNode *infoNode = unitHighlightListNode->addChild("info");
infoNode->addAttribute("unitid",intToStr(iterMap->first), mapTagReplacements); infoNode->addAttribute("unitid",intToStr(iterMap->first), mapTagReplacements);
infoNode->addAttribute("radius",floatToStr(info.radius,16), mapTagReplacements); infoNode->addAttribute("radius",floatToStr(info.radius,10), mapTagReplacements);
infoNode->addAttribute("thickness",floatToStr(info.thickness,16), mapTagReplacements); infoNode->addAttribute("thickness",floatToStr(info.thickness,10), mapTagReplacements);
infoNode->addAttribute("color",info.color.getString(), mapTagReplacements); infoNode->addAttribute("color",info.color.getString(), mapTagReplacements);
} }

View File

@ -466,18 +466,18 @@ void GameCamera::saveGame(XmlNode *rootNode) {
gamecameraNode->addAttribute("destPos",destPos.getString(), mapTagReplacements); gamecameraNode->addAttribute("destPos",destPos.getString(), mapTagReplacements);
// //
// float hAng; //YZ plane positive -Z axis // float hAng; //YZ plane positive -Z axis
gamecameraNode->addAttribute("hAng",floatToStr(hAng,16), mapTagReplacements); gamecameraNode->addAttribute("hAng",floatToStr(hAng,10), mapTagReplacements);
// float vAng; //XZ plane positive +Z axis // float vAng; //XZ plane positive +Z axis
gamecameraNode->addAttribute("vAng",floatToStr(vAng,16), mapTagReplacements); gamecameraNode->addAttribute("vAng",floatToStr(vAng,10), mapTagReplacements);
// float lastHAng; // float lastHAng;
gamecameraNode->addAttribute("lastHAng",floatToStr(lastHAng,16), mapTagReplacements); gamecameraNode->addAttribute("lastHAng",floatToStr(lastHAng,10), mapTagReplacements);
// float lastVAng; // float lastVAng;
gamecameraNode->addAttribute("lastVAng",floatToStr(lastVAng,16), mapTagReplacements); gamecameraNode->addAttribute("lastVAng",floatToStr(lastVAng,10), mapTagReplacements);
// Vec2f destAng; // Vec2f destAng;
gamecameraNode->addAttribute("destAng",destAng.getString(), mapTagReplacements); gamecameraNode->addAttribute("destAng",destAng.getString(), mapTagReplacements);
// float rotate; // float rotate;
gamecameraNode->addAttribute("rotate",floatToStr(rotate,16), mapTagReplacements); gamecameraNode->addAttribute("rotate",floatToStr(rotate,10), mapTagReplacements);
// Vec3f move; // Vec3f move;
gamecameraNode->addAttribute("move",move.getString(), mapTagReplacements); gamecameraNode->addAttribute("move",move.getString(), mapTagReplacements);
// State state; // State state;
@ -488,24 +488,24 @@ void GameCamera::saveGame(XmlNode *rootNode) {
gamecameraNode->addAttribute("limitY",intToStr(limitY), mapTagReplacements); gamecameraNode->addAttribute("limitY",intToStr(limitY), mapTagReplacements);
// //config // //config
// float speed; // float speed;
gamecameraNode->addAttribute("speed",floatToStr(speed,16), mapTagReplacements); gamecameraNode->addAttribute("speed",floatToStr(speed,10), mapTagReplacements);
// bool clampBounds; // bool clampBounds;
gamecameraNode->addAttribute("clampBounds",intToStr(clampBounds), mapTagReplacements); gamecameraNode->addAttribute("clampBounds",intToStr(clampBounds), mapTagReplacements);
// //float maxRenderDistance; // //float maxRenderDistance;
// float maxHeight; // float maxHeight;
gamecameraNode->addAttribute("maxHeight",floatToStr(maxHeight,16), mapTagReplacements); gamecameraNode->addAttribute("maxHeight",floatToStr(maxHeight,10), mapTagReplacements);
// float minHeight; // float minHeight;
gamecameraNode->addAttribute("minHeight",floatToStr(minHeight,16), mapTagReplacements); gamecameraNode->addAttribute("minHeight",floatToStr(minHeight,10), mapTagReplacements);
// //float maxCameraDist; // //float maxCameraDist;
// //float minCameraDist; // //float minCameraDist;
// float minVAng; // float minVAng;
gamecameraNode->addAttribute("minVAng",floatToStr(minVAng,16), mapTagReplacements); gamecameraNode->addAttribute("minVAng",floatToStr(minVAng,10), mapTagReplacements);
// float maxVAng; // float maxVAng;
gamecameraNode->addAttribute("maxVAng",floatToStr(maxVAng,16), mapTagReplacements); gamecameraNode->addAttribute("maxVAng",floatToStr(maxVAng,10), mapTagReplacements);
// float fov; // float fov;
gamecameraNode->addAttribute("fov",floatToStr(fov,16), mapTagReplacements); gamecameraNode->addAttribute("fov",floatToStr(fov,10), mapTagReplacements);
// float calculatedDefault; // float calculatedDefault;
gamecameraNode->addAttribute("calculatedDefault",floatToStr(calculatedDefault,16), mapTagReplacements); gamecameraNode->addAttribute("calculatedDefault",floatToStr(calculatedDefault,10), mapTagReplacements);
// std::map<float, std::map<float, std::map<Vec3f, Quad2i> > > cacheVisibleQuad; // std::map<float, std::map<float, std::map<Vec3f, Quad2i> > > cacheVisibleQuad;
// int MaxVisibleQuadItemCache; // int MaxVisibleQuadItemCache;
gamecameraNode->addAttribute("MaxVisibleQuadItemCache",intToStr(MaxVisibleQuadItemCache), mapTagReplacements); gamecameraNode->addAttribute("MaxVisibleQuadItemCache",intToStr(MaxVisibleQuadItemCache), mapTagReplacements);

View File

@ -179,7 +179,7 @@ void Stats::saveGame(XmlNode *rootNode) {
// ControlType control; // ControlType control;
statsNodePlayer->addAttribute("control",intToStr(stat.control), mapTagReplacements); statsNodePlayer->addAttribute("control",intToStr(stat.control), mapTagReplacements);
// float resourceMultiplier; // float resourceMultiplier;
statsNodePlayer->addAttribute("resourceMultiplier",floatToStr(stat.resourceMultiplier,16), mapTagReplacements); statsNodePlayer->addAttribute("resourceMultiplier",floatToStr(stat.resourceMultiplier,10), mapTagReplacements);
// string factionTypeName; // string factionTypeName;
statsNodePlayer->addAttribute("factionTypeName",stat.factionTypeName, mapTagReplacements); statsNodePlayer->addAttribute("factionTypeName",stat.factionTypeName, mapTagReplacements);
// FactionPersonalityType personalityType; // FactionPersonalityType personalityType;
@ -211,7 +211,7 @@ void Stats::saveGame(XmlNode *rootNode) {
statsNode->addAttribute("thisFactionIndex",intToStr(thisFactionIndex), mapTagReplacements); statsNode->addAttribute("thisFactionIndex",intToStr(thisFactionIndex), mapTagReplacements);
// //
// float worldTimeElapsed; // float worldTimeElapsed;
statsNode->addAttribute("worldTimeElapsed",floatToStr(worldTimeElapsed,16), mapTagReplacements); statsNode->addAttribute("worldTimeElapsed",floatToStr(worldTimeElapsed,10), mapTagReplacements);
// int framesPlayed; // int framesPlayed;
statsNode->addAttribute("framesPlayed",intToStr(framesPlayed), mapTagReplacements); statsNode->addAttribute("framesPlayed",intToStr(framesPlayed), mapTagReplacements);
// int framesToCalculatePlaytime; // int framesToCalculatePlaytime;

View File

@ -327,7 +327,7 @@ void ParticleSystemType::saveGame(XmlNode *rootNode) {
// Texture2D *texture; // Texture2D *texture;
// Model *model; // Model *model;
// float modelCycle; // float modelCycle;
particleSystemTypeNode->addAttribute("modelCycle",doubleToStr(modelCycle,16), mapTagReplacements); particleSystemTypeNode->addAttribute("modelCycle",doubleToStr(modelCycle,10), mapTagReplacements);
// string primitive; // string primitive;
particleSystemTypeNode->addAttribute("primitive",primitive, mapTagReplacements); particleSystemTypeNode->addAttribute("primitive",primitive, mapTagReplacements);
// Vec3f offset; // Vec3f offset;
@ -337,15 +337,15 @@ void ParticleSystemType::saveGame(XmlNode *rootNode) {
// Vec4f colorNoEnergy; // Vec4f colorNoEnergy;
particleSystemTypeNode->addAttribute("colorNoEnergy",colorNoEnergy.getString(), mapTagReplacements); particleSystemTypeNode->addAttribute("colorNoEnergy",colorNoEnergy.getString(), mapTagReplacements);
// float size; // float size;
particleSystemTypeNode->addAttribute("size",doubleToStr(size,16), mapTagReplacements); particleSystemTypeNode->addAttribute("size",doubleToStr(size,10), mapTagReplacements);
// float sizeNoEnergy; // float sizeNoEnergy;
particleSystemTypeNode->addAttribute("sizeNoEnergy",doubleToStr(sizeNoEnergy,16), mapTagReplacements); particleSystemTypeNode->addAttribute("sizeNoEnergy",doubleToStr(sizeNoEnergy,10), mapTagReplacements);
// float speed; // float speed;
particleSystemTypeNode->addAttribute("speed",doubleToStr(speed,16), mapTagReplacements); particleSystemTypeNode->addAttribute("speed",doubleToStr(speed,10), mapTagReplacements);
// float gravity; // float gravity;
particleSystemTypeNode->addAttribute("gravity",doubleToStr(gravity,16), mapTagReplacements); particleSystemTypeNode->addAttribute("gravity",doubleToStr(gravity,10), mapTagReplacements);
// float emissionRate; // float emissionRate;
particleSystemTypeNode->addAttribute("emissionRate",doubleToStr(emissionRate,16), mapTagReplacements); particleSystemTypeNode->addAttribute("emissionRate",doubleToStr(emissionRate,10), mapTagReplacements);
// int energyMax; // int energyMax;
particleSystemTypeNode->addAttribute("energyMax",intToStr(energyMax), mapTagReplacements); particleSystemTypeNode->addAttribute("energyMax",intToStr(energyMax), mapTagReplacements);
// int energyVar; // int energyVar;
@ -466,11 +466,11 @@ void ParticleSystemTypeProjectile::saveGame(XmlNode *rootNode) {
// string trajectory; // string trajectory;
particleSystemTypeProjectileNode->addAttribute("trajectory",trajectory, mapTagReplacements); particleSystemTypeProjectileNode->addAttribute("trajectory",trajectory, mapTagReplacements);
// float trajectorySpeed; // float trajectorySpeed;
particleSystemTypeProjectileNode->addAttribute("trajectorySpeed",doubleToStr(trajectorySpeed,16), mapTagReplacements); particleSystemTypeProjectileNode->addAttribute("trajectorySpeed",doubleToStr(trajectorySpeed,10), mapTagReplacements);
// float trajectoryScale; // float trajectoryScale;
particleSystemTypeProjectileNode->addAttribute("trajectoryScale",doubleToStr(trajectoryScale,16), mapTagReplacements); particleSystemTypeProjectileNode->addAttribute("trajectoryScale",doubleToStr(trajectoryScale,10), mapTagReplacements);
// float trajectoryFrequency; // float trajectoryFrequency;
particleSystemTypeProjectileNode->addAttribute("trajectoryFrequency",doubleToStr(trajectoryFrequency,16), mapTagReplacements); particleSystemTypeProjectileNode->addAttribute("trajectoryFrequency",doubleToStr(trajectoryFrequency,10), mapTagReplacements);
} }
// =========================================================== // ===========================================================
@ -549,15 +549,15 @@ void ParticleSystemTypeSplash::saveGame(XmlNode *rootNode) {
XmlNode *particleSystemTypeSplashNode = rootNode->addChild("ParticleSystemTypeSplash"); XmlNode *particleSystemTypeSplashNode = rootNode->addChild("ParticleSystemTypeSplash");
// float emissionRateFade; // float emissionRateFade;
particleSystemTypeSplashNode->addAttribute("emissionRateFade",doubleToStr(emissionRateFade,16), mapTagReplacements); particleSystemTypeSplashNode->addAttribute("emissionRateFade",doubleToStr(emissionRateFade,10), mapTagReplacements);
// float verticalSpreadA; // float verticalSpreadA;
particleSystemTypeSplashNode->addAttribute("verticalSpreadA",doubleToStr(verticalSpreadA,16), mapTagReplacements); particleSystemTypeSplashNode->addAttribute("verticalSpreadA",doubleToStr(verticalSpreadA,10), mapTagReplacements);
// float verticalSpreadB; // float verticalSpreadB;
particleSystemTypeSplashNode->addAttribute("verticalSpreadB",doubleToStr(verticalSpreadB,16), mapTagReplacements); particleSystemTypeSplashNode->addAttribute("verticalSpreadB",doubleToStr(verticalSpreadB,10), mapTagReplacements);
// float horizontalSpreadA; // float horizontalSpreadA;
particleSystemTypeSplashNode->addAttribute("horizontalSpreadA",doubleToStr(horizontalSpreadA,16), mapTagReplacements); particleSystemTypeSplashNode->addAttribute("horizontalSpreadA",doubleToStr(horizontalSpreadA,10), mapTagReplacements);
// float horizontalSpreadB; // float horizontalSpreadB;
particleSystemTypeSplashNode->addAttribute("horizontalSpreadB",doubleToStr(horizontalSpreadB,16), mapTagReplacements); particleSystemTypeSplashNode->addAttribute("horizontalSpreadB",doubleToStr(horizontalSpreadB,10), mapTagReplacements);
} }
}}//end mamespace }}//end mamespace

View File

@ -300,13 +300,13 @@ void UnitParticleSystemType::saveGame(XmlNode *rootNode) {
// UnitParticleSystem::Shape shape; // UnitParticleSystem::Shape shape;
unitParticleSystemTypeNode->addAttribute("shape",intToStr(shape), mapTagReplacements); unitParticleSystemTypeNode->addAttribute("shape",intToStr(shape), mapTagReplacements);
// float angle; // float angle;
unitParticleSystemTypeNode->addAttribute("angle",doubleToStr(angle,16), mapTagReplacements); unitParticleSystemTypeNode->addAttribute("angle",doubleToStr(angle,10), mapTagReplacements);
// float radius; // float radius;
unitParticleSystemTypeNode->addAttribute("radius",doubleToStr(radius,16), mapTagReplacements); unitParticleSystemTypeNode->addAttribute("radius",doubleToStr(radius,10), mapTagReplacements);
// float minRadius; // float minRadius;
unitParticleSystemTypeNode->addAttribute("minRadius",doubleToStr(minRadius,16), mapTagReplacements); unitParticleSystemTypeNode->addAttribute("minRadius",doubleToStr(minRadius,10), mapTagReplacements);
// float emissionRateFade; // float emissionRateFade;
unitParticleSystemTypeNode->addAttribute("emissionRateFade",doubleToStr(emissionRateFade,16), mapTagReplacements); unitParticleSystemTypeNode->addAttribute("emissionRateFade",doubleToStr(emissionRateFade,10), mapTagReplacements);
// Vec3f direction; // Vec3f direction;
unitParticleSystemTypeNode->addAttribute("direction",direction.getString(), mapTagReplacements); unitParticleSystemTypeNode->addAttribute("direction",direction.getString(), mapTagReplacements);
// bool relative; // bool relative;
@ -330,9 +330,9 @@ void UnitParticleSystemType::saveGame(XmlNode *rootNode) {
// int lifetime; // int lifetime;
unitParticleSystemTypeNode->addAttribute("lifetime",intToStr(lifetime), mapTagReplacements); unitParticleSystemTypeNode->addAttribute("lifetime",intToStr(lifetime), mapTagReplacements);
// float startTime; // float startTime;
unitParticleSystemTypeNode->addAttribute("startTime",doubleToStr(startTime,16), mapTagReplacements); unitParticleSystemTypeNode->addAttribute("startTime",doubleToStr(startTime,10), mapTagReplacements);
// float endTime; // float endTime;
unitParticleSystemTypeNode->addAttribute("endTime",doubleToStr(endTime,16), mapTagReplacements); unitParticleSystemTypeNode->addAttribute("endTime",doubleToStr(endTime,10), mapTagReplacements);
} }
}}//end mamespace }}//end mamespace

View File

@ -256,7 +256,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",doubleToStr(rotation,16), mapTagReplacements); objectNode->addAttribute("rotation",doubleToStr(rotation,10), mapTagReplacements);
// int variation; // int variation;
objectNode->addAttribute("variation",intToStr(variation), mapTagReplacements); objectNode->addAttribute("variation",intToStr(variation), mapTagReplacements);
// int lastRenderFrame; // int lastRenderFrame;

View File

@ -1273,7 +1273,7 @@ void Unit::setTargetPos(const Vec2i &targetPos) {
#else #else
targetRotation= radToDeg(atan2(relPosf.x, relPosf.y)); targetRotation= radToDeg(atan2(relPosf.x, relPosf.y));
#endif #endif
targetRotation = truncateDecimal<double>(targetRotation,16); targetRotation = truncateDecimal<double>(targetRotation,10);
targetRef= NULL; targetRef= NULL;
@ -1417,9 +1417,9 @@ Vec3d Unit::getCurrVector() const{
} }
Vec3d result = getCurrVectorFlat() + Vec3d(0.f, type->getHeight() /2.f, 0.f); Vec3d result = getCurrVectorFlat() + Vec3d(0.f, type->getHeight() /2.f, 0.f);
result.x = truncateDecimal<double>(result.x,16); result.x = truncateDecimal<double>(result.x,10);
result.y = truncateDecimal<double>(result.y,16); result.y = truncateDecimal<double>(result.y,10);
result.z = truncateDecimal<double>(result.z,16); result.z = truncateDecimal<double>(result.z,10);
return result; return result;
} }
@ -1430,7 +1430,7 @@ Vec3d Unit::getCurrVectorFlat() const{
double Unit::getProgressAsFloat() const { double Unit::getProgressAsFloat() const {
double result = (static_cast<double>(progress) / static_cast<double>(PROGRESS_SPEED_MULTIPLIER)); double result = (static_cast<double>(progress) / static_cast<double>(PROGRESS_SPEED_MULTIPLIER));
result = truncateDecimal<double>(result,16); result = truncateDecimal<double>(result,10);
return result; return result;
} }
@ -1452,16 +1452,16 @@ Vec3d Unit::getVectorFlat(const Vec2i &lastPosValue, const Vec2i &curPosValue) c
v.z= static_cast<double>(curPosValue.y); v.z= static_cast<double>(curPosValue.y);
v.y= y2; v.y= y2;
} }
v.x = truncateDecimal<double>(v.x,16); v.x = truncateDecimal<double>(v.x,10);
v.y = truncateDecimal<double>(v.y,16); v.y = truncateDecimal<double>(v.y,10);
v.z = truncateDecimal<double>(v.z,16); v.z = truncateDecimal<double>(v.z,10);
v.x += type->getSize() / 2.f - 0.5f; v.x += type->getSize() / 2.f - 0.5f;
v.z += type->getSize() / 2.f - 0.5f; v.z += type->getSize() / 2.f - 0.5f;
v.x = truncateDecimal<double>(v.x,16); v.x = truncateDecimal<double>(v.x,10);
v.y = truncateDecimal<double>(v.y,16); v.y = truncateDecimal<double>(v.y,10);
v.z = truncateDecimal<double>(v.z,16); v.z = truncateDecimal<double>(v.z,10);
return v; return v;
} }
@ -2508,7 +2508,7 @@ void Unit::updateTimedParticles() {
for(int i = queuedUnitParticleSystemTypes.size() - 1; i >= 0; i--) { for(int i = queuedUnitParticleSystemTypes.size() - 1; i >= 0; i--) {
UnitParticleSystemType *pst = queuedUnitParticleSystemTypes[i]; UnitParticleSystemType *pst = queuedUnitParticleSystemTypes[i];
if(pst != NULL) { if(pst != NULL) {
if(truncateDecimal<double>(pst->getStartTime(),16) <= truncateDecimal<double>(getAnimProgressAsFloat(),16)) { if(truncateDecimal<double>(pst->getStartTime(),10) <= truncateDecimal<double>(getAnimProgressAsFloat(),10)) {
UnitParticleSystem *ups = new UnitParticleSystem(200); UnitParticleSystem *ups = new UnitParticleSystem(200);
ups->setParticleOwner(this); ups->setParticleOwner(this);
@ -2537,11 +2537,11 @@ void Unit::updateTimedParticles() {
if(Renderer::getInstance().validateParticleSystemStillExists(ps,rsGame) == true) { if(Renderer::getInstance().validateParticleSystemStillExists(ps,rsGame) == true) {
double pst = ps->getStartTime(); double pst = ps->getStartTime();
double pet = ps->getEndTime(); double pet = ps->getEndTime();
double particleStartTime = truncateDecimal<double>(pst,16); double particleStartTime = truncateDecimal<double>(pst,10);
double particleEndTime = truncateDecimal<double>(pet,16); double particleEndTime = truncateDecimal<double>(pet,10);
if(particleStartTime != 0.0 || particleEndTime != 1.0) { if(particleStartTime != 0.0 || particleEndTime != 1.0) {
double animProgressTime = truncateDecimal<double>(getAnimProgressAsFloat(),16); double animProgressTime = truncateDecimal<double>(getAnimProgressAsFloat(),10);
if(animProgressTime >= 0.99 || animProgressTime >= particleEndTime) { if(animProgressTime >= 0.99 || animProgressTime >= particleEndTime) {
ps->fade(); ps->fade();
@ -3353,25 +3353,25 @@ double Unit::computeHeight(const Vec2i &pos) const {
} }
double height= map->getCell(pos)->getHeight(); double height= map->getCell(pos)->getHeight();
height = truncateDecimal<double>(height,16); height = truncateDecimal<double>(height,10);
if(currField == fAir) { if(currField == fAir) {
const double airHeight=game->getWorld()->getTileset()->getAirHeight(); const double airHeight=game->getWorld()->getTileset()->getAirHeight();
height += airHeight; height += airHeight;
height = truncateDecimal<double>(height,16); height = truncateDecimal<double>(height,10);
Unit *unit = map->getCell(pos)->getUnit(fLand); Unit *unit = map->getCell(pos)->getUnit(fLand);
if(unit != NULL && unit->getType()->getHeight() > airHeight) { if(unit != NULL && unit->getType()->getHeight() > airHeight) {
height += (std::min((double)unit->getType()->getHeight(),Tileset::standardAirHeight * 3) - airHeight); height += (std::min((double)unit->getType()->getHeight(),Tileset::standardAirHeight * 3) - airHeight);
height = truncateDecimal<double>(height,16); height = truncateDecimal<double>(height,10);
} }
else { else {
SurfaceCell *sc = map->getSurfaceCell(map->toSurfCoords(pos)); SurfaceCell *sc = map->getSurfaceCell(map->toSurfCoords(pos));
if(sc != NULL && sc->getObject() != NULL && sc->getObject()->getType() != NULL) { if(sc != NULL && sc->getObject() != NULL && sc->getObject()->getType() != NULL) {
if(sc->getObject()->getType()->getHeight() > airHeight) { if(sc->getObject()->getType()->getHeight() > airHeight) {
height += (std::min((double)sc->getObject()->getType()->getHeight(),Tileset::standardAirHeight * 3) - airHeight); height += (std::min((double)sc->getObject()->getType()->getHeight(),Tileset::standardAirHeight * 3) - airHeight);
height = truncateDecimal<double>(height,16); height = truncateDecimal<double>(height,10);
} }
} }
} }
@ -3393,7 +3393,7 @@ void Unit::updateTarget(){
#else #else
targetRotation= radToDeg(atan2(relPosf.x, relPosf.y)); targetRotation= radToDeg(atan2(relPosf.x, relPosf.y));
#endif #endif
targetRotation = truncateDecimal<double>(targetRotation,16); targetRotation = truncateDecimal<double>(targetRotation,10);
//update target vec //update target vec
targetVec= target->getCurrVector(); targetVec= target->getCurrVector();
@ -4173,7 +4173,7 @@ std::string Unit::toString(bool crcMode) const {
if(crcMode == false) { if(crcMode == false) {
result += " lastAnimProgress = " + intToStr(this->lastAnimProgress); result += " lastAnimProgress = " + intToStr(this->lastAnimProgress);
result += " animProgress = " + intToStr(this->animProgress); result += " animProgress = " + intToStr(this->animProgress);
result += " highlight = " + doubleToStr(this->highlight,16); result += " highlight = " + doubleToStr(this->highlight,10);
} }
result += " progress2 = " + intToStr(this->progress2); result += " progress2 = " + intToStr(this->progress2);
result += " kills = " + intToStr(this->kills); result += " kills = " + intToStr(this->kills);
@ -4202,9 +4202,9 @@ std::string Unit::toString(bool crcMode) const {
result += "\n"; result += "\n";
if(crcMode == false) { if(crcMode == false) {
result += " lastRotation = " + doubleToStr(this->lastRotation,16); result += " lastRotation = " + doubleToStr(this->lastRotation,10);
result += " targetRotation = " + doubleToStr(this->targetRotation,16); result += " targetRotation = " + doubleToStr(this->targetRotation,10);
result += " rotation = " + doubleToStr(this->rotation,16); result += " rotation = " + doubleToStr(this->rotation,10);
} }
if(loadType != NULL) { if(loadType != NULL) {
@ -4312,7 +4312,7 @@ void Unit::saveGame(XmlNode *rootNode) {
// float animProgress; //between 0 and 1 // float animProgress; //between 0 and 1
unitNode->addAttribute("animProgress",intToStr(animProgress), mapTagReplacements); unitNode->addAttribute("animProgress",intToStr(animProgress), mapTagReplacements);
// float highlight; // float highlight;
unitNode->addAttribute("highlight",doubleToStr(highlight,16), mapTagReplacements); unitNode->addAttribute("highlight",doubleToStr(highlight,10), mapTagReplacements);
// int progress2; // int progress2;
unitNode->addAttribute("progress2",intToStr(progress2), mapTagReplacements); unitNode->addAttribute("progress2",intToStr(progress2), mapTagReplacements);
// int kills; // int kills;
@ -4342,19 +4342,19 @@ void Unit::saveGame(XmlNode *rootNode) {
unitNode->addAttribute("meetingPos",meetingPos.getString(), mapTagReplacements); unitNode->addAttribute("meetingPos",meetingPos.getString(), mapTagReplacements);
// //
// float lastRotation; //in degrees // float lastRotation; //in degrees
unitNode->addAttribute("lastRotation",doubleToStr(lastRotation,16), mapTagReplacements); unitNode->addAttribute("lastRotation",doubleToStr(lastRotation,10), mapTagReplacements);
// float targetRotation; // float targetRotation;
unitNode->addAttribute("targetRotation",doubleToStr(targetRotation,16), mapTagReplacements); unitNode->addAttribute("targetRotation",doubleToStr(targetRotation,10), mapTagReplacements);
// float rotation; // float rotation;
unitNode->addAttribute("rotation",doubleToStr(rotation,16), mapTagReplacements); unitNode->addAttribute("rotation",doubleToStr(rotation,10), mapTagReplacements);
// float targetRotationZ; // float targetRotationZ;
unitNode->addAttribute("targetRotationZ",doubleToStr(targetRotationZ,16), mapTagReplacements); unitNode->addAttribute("targetRotationZ",doubleToStr(targetRotationZ,10), mapTagReplacements);
// float targetRotationX; // float targetRotationX;
unitNode->addAttribute("targetRotationX",doubleToStr(targetRotationX,16), mapTagReplacements); unitNode->addAttribute("targetRotationX",doubleToStr(targetRotationX,10), mapTagReplacements);
// float rotationZ; // float rotationZ;
unitNode->addAttribute("rotationZ",doubleToStr(rotationZ,16), mapTagReplacements); unitNode->addAttribute("rotationZ",doubleToStr(rotationZ,10), mapTagReplacements);
// float rotationX; // float rotationX;
unitNode->addAttribute("rotationX",doubleToStr(rotationX,16), mapTagReplacements); unitNode->addAttribute("rotationX",doubleToStr(rotationX,10), mapTagReplacements);
// const UnitType *type; // const UnitType *type;
unitNode->addAttribute("type",type->getName(false), mapTagReplacements); unitNode->addAttribute("type",type->getName(false), mapTagReplacements);

View File

@ -665,7 +665,7 @@ void SkillType::saveGame(XmlNode *rootNode) {
// //
// SoundContainer sounds; // SoundContainer sounds;
// float soundStartTime; // float soundStartTime;
skillTypeNode->addAttribute("soundStartTime",doubleToStr(soundStartTime,16), mapTagReplacements); skillTypeNode->addAttribute("soundStartTime",doubleToStr(soundStartTime,10), mapTagReplacements);
// RandomGen random; // RandomGen random;
skillTypeNode->addAttribute("random",intToStr(random.getLastNumber()), mapTagReplacements); skillTypeNode->addAttribute("random",intToStr(random.getLastNumber()), mapTagReplacements);
// AttackBoost attackBoost; // AttackBoost attackBoost;
@ -897,7 +897,7 @@ void AttackSkillType::saveGame(XmlNode *rootNode) {
attackFieldsNode->addAttribute("value",intToStr(attackFields[i]), mapTagReplacements); attackFieldsNode->addAttribute("value",intToStr(attackFields[i]), mapTagReplacements);
} }
// float attackStartTime; // float attackStartTime;
attackSkillTypeNode->addAttribute("attackStartTime",doubleToStr(attackStartTime,16), mapTagReplacements); attackSkillTypeNode->addAttribute("attackStartTime",doubleToStr(attackStartTime,10), mapTagReplacements);
// string spawnUnit; // string spawnUnit;
attackSkillTypeNode->addAttribute("spawnUnit",spawnUnit, mapTagReplacements); attackSkillTypeNode->addAttribute("spawnUnit",spawnUnit, mapTagReplacements);
// int spawnUnitcount; // int spawnUnitcount;
@ -1220,7 +1220,7 @@ void FogOfWarSkillType::saveGame(XmlNode *rootNode) {
fogSkillTypeNode->addAttribute("enable-fog",intToStr(fowEnable), mapTagReplacements); fogSkillTypeNode->addAttribute("enable-fog",intToStr(fowEnable), mapTagReplacements);
fogSkillTypeNode->addAttribute("apply-team",intToStr(applyToTeam), mapTagReplacements); fogSkillTypeNode->addAttribute("apply-team",intToStr(applyToTeam), mapTagReplacements);
fogSkillTypeNode->addAttribute("duration",doubleToStr(durationTime,16), mapTagReplacements); fogSkillTypeNode->addAttribute("duration",doubleToStr(durationTime,10), mapTagReplacements);
} }
// ===================================================== // =====================================================

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 = " + doubleToStr(rotatedBuildPos,16); result += " rotatedBuildPos = " + doubleToStr(rotatedBuildPos,10);
result += " rotationAllowed = " + intToStr(rotationAllowed); result += " rotationAllowed = " + intToStr(rotationAllowed);
if(cellMap != NULL) { if(cellMap != NULL) {

View File

@ -93,7 +93,7 @@ void Cell::saveGame(XmlNode *rootNode, int index) const {
} }
// float height; // float height;
cellNode->addAttribute("height",doubleToStr(getHeight(),16), mapTagReplacements); cellNode->addAttribute("height",doubleToStr(getHeight(),10), 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<double>(heightFactor,16); heightFactor = truncateDecimal<double>(heightFactor,10);
} }
waterLevel= static_cast<double>((header.waterLevel-0.01f)/heightFactor); waterLevel= static_cast<double>((header.waterLevel-0.01f)/heightFactor);
waterLevel = truncateDecimal<double>(waterLevel,16); waterLevel = truncateDecimal<double>(waterLevel,10);
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<double>((header.version2.cliffLevel-0.01f)/(heightFactor),16); cliffLevel=static_cast<double>((header.version2.cliffLevel-0.01f)/(heightFactor),10);
cliffLevel = truncateDecimal<double>(cliffLevel,16); cliffLevel = truncateDecimal<double>(cliffLevel,10);
} }
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;
@ -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",doubleToStr(waterLevel,16), mapTagReplacements); mapNode->addAttribute("waterLevel",doubleToStr(waterLevel,10), mapTagReplacements);
// float heightFactor; // float heightFactor;
mapNode->addAttribute("heightFactor",doubleToStr(heightFactor,16), mapTagReplacements); mapNode->addAttribute("heightFactor",doubleToStr(heightFactor,10), mapTagReplacements);
// float cliffLevel; // float cliffLevel;
mapNode->addAttribute("cliffLevel",doubleToStr(cliffLevel,16), mapTagReplacements); mapNode->addAttribute("cliffLevel",doubleToStr(cliffLevel,10), 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",doubleToStr(maxMapHeight,16), mapTagReplacements); mapNode->addAttribute("maxMapHeight",doubleToStr(maxMapHeight,10), mapTagReplacements);
// string mapFile; // string mapFile;
mapNode->addAttribute("mapFile",mapFile, mapTagReplacements); mapNode->addAttribute("mapFile",mapFile, mapTagReplacements);
} }

View File

@ -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 double getHeight() const {return truncateDecimal<double>(height,16);} inline double getHeight() const {return truncateDecimal<double>(height,10);}
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(double height) {this->height = truncateDecimal<double>(height,16);} inline void setHeight(double height) {this->height = truncateDecimal<double>(height,10);}
inline bool isFree(Field field) const { inline bool isFree(Field field) const {
Unit *unit = getUnit(field); Unit *unit = getUnit(field);
@ -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 double getHeightFactor() const {return truncateDecimal<double>(heightFactor,16);} inline double getHeightFactor() const {return truncateDecimal<double>(heightFactor,10);}
inline double getWaterLevel() const {return truncateDecimal<double>(waterLevel,16);} inline double getWaterLevel() const {return truncateDecimal<double>(waterLevel,10);}
inline double getCliffLevel() const {return truncateDecimal<double>(cliffLevel,16);} inline double getCliffLevel() const {return truncateDecimal<double>(cliffLevel,10);}
inline int getCameraHeight() const {return cameraHeight;} inline int getCameraHeight() const {return cameraHeight;}
inline double getMaxMapHeight() const {return truncateDecimal<double>(maxMapHeight,16);} inline double getMaxMapHeight() const {return truncateDecimal<double>(maxMapHeight,10);}
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;}

View File

@ -160,12 +160,12 @@ void TimeFlow::saveGame(XmlNode *rootNode) {
// bool firstTime; // bool firstTime;
// Tileset *tileset; // Tileset *tileset;
// float time; // float time;
timeflowNode->addAttribute("time",floatToStr(time,16), mapTagReplacements); timeflowNode->addAttribute("time",floatToStr(time,10), mapTagReplacements);
// float lastTime; // float lastTime;
timeflowNode->addAttribute("lastTime",floatToStr(lastTime,16), mapTagReplacements); timeflowNode->addAttribute("lastTime",floatToStr(lastTime,10), mapTagReplacements);
// float timeInc; // float timeInc;
//printf("#2 timeInc = %f\n",timeInc); //printf("#2 timeInc = %f\n",timeInc);
timeflowNode->addAttribute("timeInc",floatToStr(timeInc,16), mapTagReplacements); timeflowNode->addAttribute("timeInc",floatToStr(timeInc,10), mapTagReplacements);
//printf("#3 timeInc = %f\n",timeInc); //printf("#3 timeInc = %f\n",timeInc);
} }

View File

@ -138,9 +138,9 @@ bool UnitUpdater::updateUnit(Unit *unit) {
if(unit->getCurrSkill()->getClass() == scAttack) { if(unit->getCurrSkill()->getClass() == scAttack) {
const AttackSkillType *ast= static_cast<const AttackSkillType*>(unit->getCurrSkill()); const AttackSkillType *ast= static_cast<const AttackSkillType*>(unit->getCurrSkill());
double attackStartTime = truncateDecimal<double>(ast->getAttackStartTime(),16); double attackStartTime = truncateDecimal<double>(ast->getAttackStartTime(),10);
double lastAnimProgress = truncateDecimal<double>(unit->getLastAnimProgressAsFloat(),16); double lastAnimProgress = truncateDecimal<double>(unit->getLastAnimProgressAsFloat(),10);
double animProgress = truncateDecimal<double>(unit->getAnimProgressAsFloat(),16); double animProgress = truncateDecimal<double>(unit->getAnimProgressAsFloat(),10);
bool startAttackParticleSystemNow = (attackStartTime >= lastAnimProgress && attackStartTime < animProgress); bool startAttackParticleSystemNow = (attackStartTime >= lastAnimProgress && attackStartTime < animProgress);
char szBuf[8096]=""; char szBuf[8096]="";
@ -2211,7 +2211,7 @@ void UnitUpdater::hit(Unit *attacker, const AttackSkillType* ast, const Vec2i &t
scriptManager->onUnitAttacking(attacker); scriptManager->onUnitAttacking(attacker);
double distance = pci.getPos().dist(targetPos); double distance = pci.getPos().dist(targetPos);
distance = truncateDecimal<double>(distance,16); distance = truncateDecimal<double>(distance,10);
damage(attacker, ast, attacked, distance); damage(attacker, ast, attacked, distance);
} }
} }
@ -2241,7 +2241,7 @@ void UnitUpdater::damage(Unit *attacker, const AttackSkillType* ast, Unit *attac
int var = ast->getAttackVar(); int var = ast->getAttackVar();
int armor = attacked->getType()->getTotalArmor(attacked->getTotalUpgrade()); int armor = attacked->getType()->getTotalArmor(attacked->getTotalUpgrade());
double damageMultiplier = world->getTechTree()->getDamageMultiplier(ast->getAttackType(), attacked->getType()->getArmorType()); double damageMultiplier = world->getTechTree()->getDamageMultiplier(ast->getAttackType(), attacked->getType()->getArmorType());
damageMultiplier = truncateDecimal<double>(damageMultiplier,16); damageMultiplier = truncateDecimal<double>(damageMultiplier,10);
//compute damage //compute damage
//damage += random.randRange(-var, var); //damage += random.randRange(-var, var);
@ -2249,7 +2249,7 @@ void UnitUpdater::damage(Unit *attacker, const AttackSkillType* ast, Unit *attac
damage /= distance+1; damage /= distance+1;
damage -= armor; damage -= armor;
damage *= damageMultiplier; damage *= damageMultiplier;
damage = truncateDecimal<double>(damage,16); damage = truncateDecimal<double>(damage,10);
if(damage < 1) { if(damage < 1) {
damage= 1; damage= 1;
@ -2817,7 +2817,7 @@ void UnitUpdater::saveGame(XmlNode *rootNode) {
// RandomGen random; // RandomGen random;
//unitupdaterNode->addAttribute("random",intToStr(random.getLastNumber()), mapTagReplacements); //unitupdaterNode->addAttribute("random",intToStr(random.getLastNumber()), mapTagReplacements);
// float attackWarnRange; // float attackWarnRange;
unitupdaterNode->addAttribute("attackWarnRange",doubleToStr(attackWarnRange,16), mapTagReplacements); unitupdaterNode->addAttribute("attackWarnRange",doubleToStr(attackWarnRange,10), mapTagReplacements);
// AttackWarnings attackWarnings; // AttackWarnings attackWarnings;
// //
// Mutex mutexUnitRangeCellsLookupItemCache; // Mutex mutexUnitRangeCellsLookupItemCache;

View File

@ -55,7 +55,7 @@ void Particle::saveGame(XmlNode *rootNode) {
// Vec4f color; // Vec4f color;
particleNode->addAttribute("color",color.getString(), mapTagReplacements); particleNode->addAttribute("color",color.getString(), mapTagReplacements);
// float size; // float size;
particleNode->addAttribute("size",doubleToStr(size,16), mapTagReplacements); particleNode->addAttribute("size",doubleToStr(size,10), mapTagReplacements);
// int energy; // int energy;
particleNode->addAttribute("energy",intToStr(energy), mapTagReplacements); particleNode->addAttribute("energy",intToStr(energy), mapTagReplacements);
} }
@ -217,6 +217,7 @@ void ParticleSystem::update(){
initParticle(p, i); initParticle(p, i);
} }
emissionState = emissionState - (double) emissionIntValue; emissionState = emissionState - (double) emissionIntValue;
emissionState = truncateDecimal<double>(emissionState,10);
} }
} }
} }
@ -267,6 +268,7 @@ void ParticleSystem::setColorNoEnergy(Vec4f colorNoEnergy){
void ParticleSystem::setEmissionRate(double emissionRate){ void ParticleSystem::setEmissionRate(double emissionRate){
this->emissionRate= emissionRate; this->emissionRate= emissionRate;
this->emissionRate = truncateDecimal<double>(this->emissionRate,10);
} }
void ParticleSystem::setMaxParticleEnergy(int maxParticleEnergy){ void ParticleSystem::setMaxParticleEnergy(int maxParticleEnergy){
@ -279,10 +281,12 @@ void ParticleSystem::setVarParticleEnergy(int varParticleEnergy){
void ParticleSystem::setParticleSize(double particleSize){ void ParticleSystem::setParticleSize(double particleSize){
this->particleSize= particleSize; this->particleSize= particleSize;
this->particleSize = truncateDecimal<double>(this->particleSize,10);
} }
void ParticleSystem::setSpeed(double speed){ void ParticleSystem::setSpeed(double speed){
this->speed= speed; this->speed= speed;
this->speed = truncateDecimal<double>(this->speed,10);
} }
void ParticleSystem::setActive(bool active){ void ParticleSystem::setActive(bool active){
@ -301,9 +305,10 @@ ParticleSystem* ParticleSystem::getChild(int i){
void ParticleSystem::setVisible(bool visible){ void ParticleSystem::setVisible(bool visible){
this->visible= visible; this->visible= visible;
for(int i=getChildCount()-1; i>=0; i--) for(int i=getChildCount()-1; i>=0; i--) {
getChild(i)->setVisible(visible); getChild(i)->setVisible(visible);
} }
}
string ParticleSystem::toString() const { string ParticleSystem::toString() const {
string result = "ParticleSystem "; string result = "ParticleSystem ";
@ -334,12 +339,12 @@ string ParticleSystem::toString() const {
result += "\npos = " + pos.getString(); result += "\npos = " + pos.getString();
result += "\ncolor = " + color.getString(); result += "\ncolor = " + color.getString();
result += "\ncolorNoEnergy = " + colorNoEnergy.getString(); result += "\ncolorNoEnergy = " + colorNoEnergy.getString();
result += "\nemissionRate = " + doubleToStr(emissionRate,16); result += "\nemissionRate = " + doubleToStr(emissionRate,10);
result += "\nemissionState = " + doubleToStr(emissionState,16); result += "\nemissionState = " + doubleToStr(emissionState,10);
result += "\nmaxParticleEnergy = " + intToStr(maxParticleEnergy); result += "\nmaxParticleEnergy = " + intToStr(maxParticleEnergy);
result += "\nvarParticleEnergy = " + intToStr(varParticleEnergy); result += "\nvarParticleEnergy = " + intToStr(varParticleEnergy);
result += "\nparticleSize = " + doubleToStr(particleSize,16); result += "\nparticleSize = " + doubleToStr(particleSize,10);
result += "\nspeed = " + doubleToStr(speed,16); result += "\nspeed = " + doubleToStr(speed,10);
result += "\nfactionColor = " + factionColor.getString(); result += "\nfactionColor = " + factionColor.getString();
result += "\nteamcolorNoEnergy = " + intToStr(teamcolorNoEnergy); result += "\nteamcolorNoEnergy = " + intToStr(teamcolorNoEnergy);
result += "\nteamcolorEnergy = " + intToStr(teamcolorEnergy); result += "\nteamcolorEnergy = " + intToStr(teamcolorEnergy);
@ -392,17 +397,17 @@ void ParticleSystem::saveGame(XmlNode *rootNode) {
// Vec4f colorNoEnergy; // Vec4f colorNoEnergy;
particleSystemNode->addAttribute("colorNoEnergy",colorNoEnergy.getString(), mapTagReplacements); particleSystemNode->addAttribute("colorNoEnergy",colorNoEnergy.getString(), mapTagReplacements);
// float emissionRate; // float emissionRate;
particleSystemNode->addAttribute("emissionRate",doubleToStr(emissionRate,16), mapTagReplacements); particleSystemNode->addAttribute("emissionRate",doubleToStr(emissionRate,10), mapTagReplacements);
// float emissionState; // float emissionState;
particleSystemNode->addAttribute("emissionState",doubleToStr(emissionState,16), mapTagReplacements); particleSystemNode->addAttribute("emissionState",doubleToStr(emissionState,10), mapTagReplacements);
// int maxParticleEnergy; // int maxParticleEnergy;
particleSystemNode->addAttribute("maxParticleEnergy",intToStr(maxParticleEnergy), mapTagReplacements); particleSystemNode->addAttribute("maxParticleEnergy",intToStr(maxParticleEnergy), mapTagReplacements);
// int varParticleEnergy; // int varParticleEnergy;
particleSystemNode->addAttribute("varParticleEnergy",intToStr(varParticleEnergy), mapTagReplacements); particleSystemNode->addAttribute("varParticleEnergy",intToStr(varParticleEnergy), mapTagReplacements);
// float particleSize; // float particleSize;
particleSystemNode->addAttribute("particleSize",doubleToStr(particleSize,16), mapTagReplacements); particleSystemNode->addAttribute("particleSize",doubleToStr(particleSize,10), mapTagReplacements);
// float speed; // float speed;
particleSystemNode->addAttribute("speed",doubleToStr(speed,16), mapTagReplacements); particleSystemNode->addAttribute("speed",doubleToStr(speed,10), mapTagReplacements);
// Vec3f factionColor; // Vec3f factionColor;
particleSystemNode->addAttribute("factionColor",factionColor.getString(), mapTagReplacements); particleSystemNode->addAttribute("factionColor",factionColor.getString(), mapTagReplacements);
// bool teamcolorNoEnergy; // bool teamcolorNoEnergy;
@ -548,7 +553,7 @@ void ParticleSystem::fade(){
} }
int ParticleSystem::isEmpty() const { int ParticleSystem::isEmpty() const {
assert(aliveParticleCount>=0); //assert(aliveParticleCount>=0);
return aliveParticleCount == 0 && state != sPause; return aliveParticleCount == 0 && state != sPause;
} }
@ -575,27 +580,6 @@ Particle * ParticleSystem::createParticle(){
} }
} }
return &particles[minEnergyParticle]; return &particles[minEnergyParticle];
/*
//if any dead particles
if(aliveParticleCount < particleCount) {
++aliveParticleCount;
return &particles[aliveParticleCount-1];
}
//if not
int minEnergy = particles[0].energy;
int minEnergyParticle = 0;
for(int i = 0; i < particleCount; ++i){
if(particles[i].energy < minEnergy){
minEnergy = particles[i].energy;
minEnergyParticle = i;
}
}
return &particles[minEnergyParticle];
*/
} }
void ParticleSystem::initParticle(Particle *p, int particleIndex) { void ParticleSystem::initParticle(Particle *p, int particleIndex) {
@ -605,6 +589,7 @@ void ParticleSystem::initParticle(Particle *p, int particleIndex){
p->accel= Vec3d(0.0f); p->accel= Vec3d(0.0f);
p->color= Vec4f(1.0f, 1.0f, 1.0f, 1.0); p->color= Vec4f(1.0f, 1.0f, 1.0f, 1.0);
p->size= particleSize; p->size= particleSize;
p->size = truncateDecimal<double>(p->size,10);
p->energy= maxParticleEnergy + random.randRange(-varParticleEnergy, varParticleEnergy); p->energy= maxParticleEnergy + random.randRange(-varParticleEnergy, varParticleEnergy);
} }
@ -677,16 +662,16 @@ void FireParticleSystem::initParticle(Particle *p, int particleIndex){
p->energy= static_cast<int> (maxParticleEnergy * radRatio) p->energy= static_cast<int> (maxParticleEnergy * radRatio)
+ random.randRange(-varParticleEnergy, varParticleEnergy); + random.randRange(-varParticleEnergy, varParticleEnergy);
p->pos= Vec3d(pos.x + x, pos.y + random.randRange(-radius / 2, radius / 2), pos.z + y); p->pos= Vec3d(pos.x + x, pos.y + random.randRange(-radius / 2, radius / 2), pos.z + y);
p->pos.x = truncateDecimal<double>(p->pos.x,16); p->pos.x = truncateDecimal<double>(p->pos.x,10);
p->pos.y = truncateDecimal<double>(p->pos.y,16); p->pos.y = truncateDecimal<double>(p->pos.y,10);
p->pos.z = truncateDecimal<double>(p->pos.z,16); p->pos.z = truncateDecimal<double>(p->pos.z,10);
p->lastPos= pos; p->lastPos= pos;
p->size= particleSize; p->size= particleSize;
p->speed= Vec3d(0, speed + speed * random.randRange(-0.5f, 0.5f), 0) + windSpeed; p->speed= Vec3d(0, speed + speed * random.randRange(-0.5f, 0.5f), 0) + windSpeed;
p->speed.x = truncateDecimal<double>(p->speed.x,16); p->speed.x = truncateDecimal<double>(p->speed.x,10);
p->speed.y = truncateDecimal<double>(p->speed.y,16); p->speed.y = truncateDecimal<double>(p->speed.y,10);
p->speed.z = truncateDecimal<double>(p->speed.z,16); p->speed.z = truncateDecimal<double>(p->speed.z,10);
} }
@ -703,9 +688,9 @@ void FireParticleSystem::updateParticle(Particle *p){
p->color.w*= 0.98f; p->color.w*= 0.98f;
p->speed.x*= 1.001f; p->speed.x*= 1.001f;
p->speed.x = truncateDecimal<double>(p->speed.x,16); p->speed.x = truncateDecimal<double>(p->speed.x,10);
p->speed.y = truncateDecimal<double>(p->speed.y,16); p->speed.y = truncateDecimal<double>(p->speed.y,10);
p->speed.z = truncateDecimal<double>(p->speed.z,16); p->speed.z = truncateDecimal<double>(p->speed.z,10);
} }
@ -735,9 +720,9 @@ void FireParticleSystem::setWind(double windAngle, double windSpeed) {
this->windSpeed.z= cosf(degToRad(windAngle)) * windSpeed; this->windSpeed.z= cosf(degToRad(windAngle)) * windSpeed;
#endif #endif
this->windSpeed.x = truncateDecimal<double>(this->windSpeed.x,16); this->windSpeed.x = truncateDecimal<double>(this->windSpeed.x,10);
this->windSpeed.y = truncateDecimal<double>(this->windSpeed.y,16); this->windSpeed.y = truncateDecimal<double>(this->windSpeed.y,10);
this->windSpeed.z = truncateDecimal<double>(this->windSpeed.z,16); this->windSpeed.z = truncateDecimal<double>(this->windSpeed.z,10);
} }
void FireParticleSystem::saveGame(XmlNode *rootNode) { void FireParticleSystem::saveGame(XmlNode *rootNode) {
@ -747,7 +732,7 @@ void FireParticleSystem::saveGame(XmlNode *rootNode) {
ParticleSystem::saveGame(fireParticleSystemNode); ParticleSystem::saveGame(fireParticleSystemNode);
// float radius; // float radius;
fireParticleSystemNode->addAttribute("radius",doubleToStr(radius,16), mapTagReplacements); fireParticleSystemNode->addAttribute("radius",doubleToStr(radius,10), mapTagReplacements);
// Vec3f windSpeed; // Vec3f windSpeed;
fireParticleSystemNode->addAttribute("windSpeed",windSpeed.getString(), mapTagReplacements); fireParticleSystemNode->addAttribute("windSpeed",windSpeed.getString(), mapTagReplacements);
} }
@ -885,7 +870,7 @@ void GameParticleSystem::setTween(double relative,double absolute) {
} }
} }
tween = truncateDecimal<double>(tween,16); tween = truncateDecimal<double>(tween,10);
if(tween < 0.0f || tween > 1.0f) { if(tween < 0.0f || tween > 1.0f) {
//printf("In [%s::%s Line: %d] WARNING setting tween to [%f] clamping tween, modelCycle [%f] absolute [%f] relative [%f]\n",__FILE__,__FUNCTION__,__LINE__,tween,modelCycle,absolute,relative); //printf("In [%s::%s Line: %d] WARNING setting tween to [%f] clamping tween, modelCycle [%f] absolute [%f] relative [%f]\n",__FILE__,__FUNCTION__,__LINE__,tween,modelCycle,absolute,relative);
//assert(tween >= 0.0f && tween <= 1.0f); //assert(tween >= 0.0f && tween <= 1.0f);
@ -923,13 +908,13 @@ void GameParticleSystem::saveGame(XmlNode *rootNode) {
gameParticleSystemNode->addAttribute("model",model->getFileName(), mapTagReplacements); gameParticleSystemNode->addAttribute("model",model->getFileName(), mapTagReplacements);
} }
// float modelCycle; // float modelCycle;
gameParticleSystemNode->addAttribute("modelCycle",doubleToStr(modelCycle,16), mapTagReplacements); gameParticleSystemNode->addAttribute("modelCycle",doubleToStr(modelCycle,10), mapTagReplacements);
// Vec3f offset; // Vec3f offset;
gameParticleSystemNode->addAttribute("offset",offset.getString(), mapTagReplacements); gameParticleSystemNode->addAttribute("offset",offset.getString(), mapTagReplacements);
// Vec3f direction; // Vec3f direction;
gameParticleSystemNode->addAttribute("direction",direction.getString(), mapTagReplacements); gameParticleSystemNode->addAttribute("direction",direction.getString(), mapTagReplacements);
// float tween; // float tween;
gameParticleSystemNode->addAttribute("tween",doubleToStr(tween,16), mapTagReplacements); gameParticleSystemNode->addAttribute("tween",doubleToStr(tween,10), mapTagReplacements);
} }
void GameParticleSystem::loadGame(const XmlNode *rootNode) { void GameParticleSystem::loadGame(const XmlNode *rootNode) {
const XmlNode *gameParticleSystemNode = rootNode->getChild("GameParticleSystem"); const XmlNode *gameParticleSystemNode = rootNode->getChild("GameParticleSystem");
@ -1126,9 +1111,9 @@ void UnitParticleSystem::initParticle(Particle *p, int particleIndex){
oldPosition= pos; oldPosition= pos;
p->size= particleSize; p->size= particleSize;
p->accel= Vec3d(0.0f, -gravity, 0.0f); p->accel= Vec3d(0.0f, -gravity, 0.0f);
p->accel.x = truncateDecimal<double>(p->accel.x,16); p->accel.x = truncateDecimal<double>(p->accel.x,10);
p->accel.y = truncateDecimal<double>(p->accel.y,16); p->accel.y = truncateDecimal<double>(p->accel.y,10);
p->accel.z = truncateDecimal<double>(p->accel.z,16); p->accel.z = truncateDecimal<double>(p->accel.z,10);
// work out where we start for our shape (set speed and pos) // work out where we start for our shape (set speed and pos)
switch(shape){ switch(shape){
@ -1140,15 +1125,15 @@ void UnitParticleSystem::initParticle(Particle *p, int particleIndex){
Vec2d vert = Vec2d(1,0).rotate(degToRad(angle)); Vec2d vert = Vec2d(1,0).rotate(degToRad(angle));
Vec3d start = Vec3d(horiz.x*vert.y,vert.x,horiz.y).getNormalized(); // close enough Vec3d start = Vec3d(horiz.x*vert.y,vert.x,horiz.y).getNormalized(); // close enough
p->speed = start * speed; p->speed = start * speed;
p->speed.x = truncateDecimal<double>(p->speed.x,16); p->speed.x = truncateDecimal<double>(p->speed.x,10);
p->speed.y = truncateDecimal<double>(p->speed.y,16); p->speed.y = truncateDecimal<double>(p->speed.y,10);
p->speed.z = truncateDecimal<double>(p->speed.z,16); p->speed.z = truncateDecimal<double>(p->speed.z,10);
start = start * random.randRange(minRadius,radius); start = start * random.randRange(minRadius,radius);
p->pos = pos + offset + start; p->pos = pos + offset + start;
p->pos.x = truncateDecimal<double>(p->pos.x,16); p->pos.x = truncateDecimal<double>(p->pos.x,10);
p->pos.y = truncateDecimal<double>(p->pos.y,16); p->pos.y = truncateDecimal<double>(p->pos.y,10);
p->pos.z = truncateDecimal<double>(p->pos.z,16); p->pos.z = truncateDecimal<double>(p->pos.z,10);
} break; } break;
case sLinear:{ case sLinear:{
@ -1164,9 +1149,9 @@ void UnitParticleSystem::initParticle(Particle *p, int particleIndex){
p->pos= Vec3d(pos.x + x + offset.x, pos.y + p->pos= Vec3d(pos.x + x + offset.x, pos.y +
random.randRange(-radius / 2, radius / 2) + offset.y, random.randRange(-radius / 2, radius / 2) + offset.y,
pos.z + y + offset.z); pos.z + y + offset.z);
p->pos.x = truncateDecimal<double>(p->pos.x,16); p->pos.x = truncateDecimal<double>(p->pos.x,10);
p->pos.y = truncateDecimal<double>(p->pos.y,16); p->pos.y = truncateDecimal<double>(p->pos.y,10);
p->pos.z = truncateDecimal<double>(p->pos.z,16); p->pos.z = truncateDecimal<double>(p->pos.z,10);
} }
else {// rotate it according to rotation else {// rotate it according to rotation
@ -1177,18 +1162,18 @@ void UnitParticleSystem::initParticle(Particle *p, int particleIndex){
radius / 2) + offset.y, pos.z + y + (offset.z * cosf(rad) - offset.x * sinf(rad))); radius / 2) + offset.y, pos.z + y + (offset.z * cosf(rad) - offset.x * sinf(rad)));
#endif #endif
p->pos.x = truncateDecimal<double>(p->pos.x,16); p->pos.x = truncateDecimal<double>(p->pos.x,10);
p->pos.y = truncateDecimal<double>(p->pos.y,16); p->pos.y = truncateDecimal<double>(p->pos.y,10);
p->pos.z = truncateDecimal<double>(p->pos.z,16); p->pos.z = truncateDecimal<double>(p->pos.z,10);
} }
p->speed= Vec3d(direction.x + direction.x * random.randRange(-0.5f, 0.5f), direction.y + direction.y p->speed= Vec3d(direction.x + direction.x * random.randRange(-0.5f, 0.5f), direction.y + direction.y
* random.randRange(-0.5f, 0.5f), direction.z + direction.z * random.randRange(-0.5f, 0.5f)); * random.randRange(-0.5f, 0.5f), direction.z + direction.z * random.randRange(-0.5f, 0.5f));
p->speed= p->speed * speed; p->speed= p->speed * speed;
p->speed.x = truncateDecimal<double>(p->speed.x,16); p->speed.x = truncateDecimal<double>(p->speed.x,10);
p->speed.y = truncateDecimal<double>(p->speed.y,16); p->speed.y = truncateDecimal<double>(p->speed.y,10);
p->speed.z = truncateDecimal<double>(p->speed.z,16); p->speed.z = truncateDecimal<double>(p->speed.z,10);
if(relative && relativeDirection) { if(relative && relativeDirection) {
#ifdef USE_STREFLOP #ifdef USE_STREFLOP
@ -1203,9 +1188,9 @@ void UnitParticleSystem::initParticle(Particle *p, int particleIndex){
p->speed.y, (p->speed.z * cosf(rad) - p->speed.x * sinf(rad))); p->speed.y, (p->speed.z * cosf(rad) - p->speed.x * sinf(rad)));
#endif #endif
p->speed.x = truncateDecimal<double>(p->speed.x,16); p->speed.x = truncateDecimal<double>(p->speed.x,10);
p->speed.y = truncateDecimal<double>(p->speed.y,16); p->speed.y = truncateDecimal<double>(p->speed.y,10);
p->speed.z = truncateDecimal<double>(p->speed.z,16); p->speed.z = truncateDecimal<double>(p->speed.z,10);
} }
} break; } break;
default: throw megaglest_runtime_error("bad shape"); default: throw megaglest_runtime_error("bad shape");
@ -1222,7 +1207,7 @@ void UnitParticleSystem::update(){
} }
if(state != sPause) { if(state != sPause) {
emissionRate-= emissionRateFade; emissionRate-= emissionRateFade;
emissionRate = truncateDecimal<double>(emissionRate,16); emissionRate = truncateDecimal<double>(emissionRate,10);
if(parent && emissionRate < 0.0f) { if(parent && emissionRate < 0.0f) {
fade(); fade();
@ -1230,9 +1215,9 @@ void UnitParticleSystem::update(){
} }
if(fixed) { if(fixed) {
fixedAddition= Vec3d(pos.x - oldPosition.x, pos.y - oldPosition.y, pos.z - oldPosition.z); fixedAddition= Vec3d(pos.x - oldPosition.x, pos.y - oldPosition.y, pos.z - oldPosition.z);
fixedAddition.x = truncateDecimal<double>(fixedAddition.x,16); fixedAddition.x = truncateDecimal<double>(fixedAddition.x,10);
fixedAddition.y = truncateDecimal<double>(fixedAddition.y,16); fixedAddition.y = truncateDecimal<double>(fixedAddition.y,10);
fixedAddition.z = truncateDecimal<double>(fixedAddition.z,16); fixedAddition.z = truncateDecimal<double>(fixedAddition.z,10);
oldPosition= pos; oldPosition= pos;
} }
@ -1257,33 +1242,33 @@ void UnitParticleSystem::updateParticle(Particle *p){
energyRatio= clamp(static_cast<double> (p->energy) / maxParticleEnergy, 0.f, 1.f); energyRatio= clamp(static_cast<double> (p->energy) / maxParticleEnergy, 0.f, 1.f);
} }
energyRatio = truncateDecimal<double>(energyRatio,16); energyRatio = truncateDecimal<double>(energyRatio,10);
p->lastPos += p->speed; p->lastPos += p->speed;
p->lastPos.x = truncateDecimal<double>(p->lastPos.x,16); p->lastPos.x = truncateDecimal<double>(p->lastPos.x,10);
p->lastPos.y = truncateDecimal<double>(p->lastPos.y,16); p->lastPos.y = truncateDecimal<double>(p->lastPos.y,10);
p->lastPos.z = truncateDecimal<double>(p->lastPos.z,16); p->lastPos.z = truncateDecimal<double>(p->lastPos.z,10);
p->pos += p->speed; p->pos += p->speed;
p->pos.x = truncateDecimal<double>(p->pos.x,16); p->pos.x = truncateDecimal<double>(p->pos.x,10);
p->pos.y = truncateDecimal<double>(p->pos.y,16); p->pos.y = truncateDecimal<double>(p->pos.y,10);
p->pos.z = truncateDecimal<double>(p->pos.z,16); p->pos.z = truncateDecimal<double>(p->pos.z,10);
if(fixed) { if(fixed) {
p->lastPos += fixedAddition; p->lastPos += fixedAddition;
p->lastPos.x = truncateDecimal<double>(p->lastPos.x,16); p->lastPos.x = truncateDecimal<double>(p->lastPos.x,10);
p->lastPos.y = truncateDecimal<double>(p->lastPos.y,16); p->lastPos.y = truncateDecimal<double>(p->lastPos.y,10);
p->lastPos.z = truncateDecimal<double>(p->lastPos.z,16); p->lastPos.z = truncateDecimal<double>(p->lastPos.z,10);
p->pos += fixedAddition; p->pos += fixedAddition;
p->pos.x = truncateDecimal<double>(p->pos.x,16); p->pos.x = truncateDecimal<double>(p->pos.x,10);
p->pos.y = truncateDecimal<double>(p->pos.y,16); p->pos.y = truncateDecimal<double>(p->pos.y,10);
p->pos.z = truncateDecimal<double>(p->pos.z,16); p->pos.z = truncateDecimal<double>(p->pos.z,10);
} }
p->speed += p->accel; p->speed += p->accel;
p->speed.x = truncateDecimal<double>(p->speed.x,16); p->speed.x = truncateDecimal<double>(p->speed.x,10);
p->speed.y = truncateDecimal<double>(p->speed.y,16); p->speed.y = truncateDecimal<double>(p->speed.y,10);
p->speed.z = truncateDecimal<double>(p->speed.z,16); p->speed.z = truncateDecimal<double>(p->speed.z,10);
p->color= color * energyRatio + colorNoEnergy * (1.0f - energyRatio); p->color= color * energyRatio + colorNoEnergy * (1.0f - energyRatio);
if(isDaylightAffected==true) { if(isDaylightAffected==true) {
@ -1292,7 +1277,7 @@ void UnitParticleSystem::updateParticle(Particle *p){
p->color.z=p->color.z*lightColor.z; p->color.z=p->color.z*lightColor.z;
} }
p->size= particleSize * energyRatio + sizeNoEnergy * (1.0f - energyRatio); p->size= particleSize * energyRatio + sizeNoEnergy * (1.0f - energyRatio);
p->size = truncateDecimal<double>(p->size,16); p->size = truncateDecimal<double>(p->size,10);
if(state == ParticleSystem::sFade || staticParticleCount < 1){ if(state == ParticleSystem::sFade || staticParticleCount < 1){
p->energy--; p->energy--;
@ -1329,9 +1314,9 @@ void UnitParticleSystem::setWind(double windAngle, double windSpeed){
this->windSpeed.z= cosf(degToRad(windAngle)) * windSpeed; this->windSpeed.z= cosf(degToRad(windAngle)) * windSpeed;
#endif #endif
this->windSpeed.x = truncateDecimal<double>(this->windSpeed.x,16); this->windSpeed.x = truncateDecimal<double>(this->windSpeed.x,10);
this->windSpeed.y = truncateDecimal<double>(this->windSpeed.y,16); this->windSpeed.y = truncateDecimal<double>(this->windSpeed.y,10);
this->windSpeed.z = truncateDecimal<double>(this->windSpeed.z,16); this->windSpeed.z = truncateDecimal<double>(this->windSpeed.z,10);
} }
void UnitParticleSystem::saveGame(XmlNode *rootNode) { void UnitParticleSystem::saveGame(XmlNode *rootNode) {
@ -1341,9 +1326,9 @@ void UnitParticleSystem::saveGame(XmlNode *rootNode) {
GameParticleSystem::saveGame(unitParticleSystemNode); GameParticleSystem::saveGame(unitParticleSystemNode);
// float radius; // float radius;
unitParticleSystemNode->addAttribute("radius",doubleToStr(radius,16), mapTagReplacements); unitParticleSystemNode->addAttribute("radius",doubleToStr(radius,10), mapTagReplacements);
// float minRadius; // float minRadius;
unitParticleSystemNode->addAttribute("minRadius",doubleToStr(minRadius,16), mapTagReplacements); unitParticleSystemNode->addAttribute("minRadius",doubleToStr(minRadius,10), mapTagReplacements);
// Vec3f windSpeed; // Vec3f windSpeed;
unitParticleSystemNode->addAttribute("windSpeed",windSpeed.getString(), mapTagReplacements); unitParticleSystemNode->addAttribute("windSpeed",windSpeed.getString(), mapTagReplacements);
// Vec3f cRotation; // Vec3f cRotation;
@ -1355,9 +1340,9 @@ void UnitParticleSystem::saveGame(XmlNode *rootNode) {
// bool energyUp; // bool energyUp;
unitParticleSystemNode->addAttribute("energyUp",intToStr(energyUp), mapTagReplacements); unitParticleSystemNode->addAttribute("energyUp",intToStr(energyUp), mapTagReplacements);
// float startTime; // float startTime;
unitParticleSystemNode->addAttribute("startTime",doubleToStr(startTime,16), mapTagReplacements); unitParticleSystemNode->addAttribute("startTime",doubleToStr(startTime,10), mapTagReplacements);
// float endTime; // float endTime;
unitParticleSystemNode->addAttribute("endTime",doubleToStr(endTime,16), mapTagReplacements); unitParticleSystemNode->addAttribute("endTime",doubleToStr(endTime,10), mapTagReplacements);
// bool relative; // bool relative;
unitParticleSystemNode->addAttribute("relative",intToStr(relative), mapTagReplacements); unitParticleSystemNode->addAttribute("relative",intToStr(relative), mapTagReplacements);
// bool relativeDirection; // bool relativeDirection;
@ -1367,13 +1352,13 @@ void UnitParticleSystem::saveGame(XmlNode *rootNode) {
// Shape shape; // Shape shape;
unitParticleSystemNode->addAttribute("shape",intToStr(shape), mapTagReplacements); unitParticleSystemNode->addAttribute("shape",intToStr(shape), mapTagReplacements);
// float angle; // float angle;
unitParticleSystemNode->addAttribute("angle",doubleToStr(angle,16), mapTagReplacements); unitParticleSystemNode->addAttribute("angle",doubleToStr(angle,10), mapTagReplacements);
// float sizeNoEnergy; // float sizeNoEnergy;
unitParticleSystemNode->addAttribute("sizeNoEnergy",doubleToStr(sizeNoEnergy,16), mapTagReplacements); unitParticleSystemNode->addAttribute("sizeNoEnergy",doubleToStr(sizeNoEnergy,10), mapTagReplacements);
// float gravity; // float gravity;
unitParticleSystemNode->addAttribute("gravity",doubleToStr(gravity,16), mapTagReplacements); unitParticleSystemNode->addAttribute("gravity",doubleToStr(gravity,10), mapTagReplacements);
// float rotation; // float rotation;
unitParticleSystemNode->addAttribute("rotation",doubleToStr(rotation,16), mapTagReplacements); unitParticleSystemNode->addAttribute("rotation",doubleToStr(rotation,10), mapTagReplacements);
// bool isVisibleAtNight; // bool isVisibleAtNight;
unitParticleSystemNode->addAttribute("isVisibleAtNight",intToStr(isVisibleAtNight), mapTagReplacements); unitParticleSystemNode->addAttribute("isVisibleAtNight",intToStr(isVisibleAtNight), mapTagReplacements);
// bool isVisibleAtDay; // bool isVisibleAtDay;
@ -1389,7 +1374,7 @@ void UnitParticleSystem::saveGame(XmlNode *rootNode) {
// int lifetime; // int lifetime;
unitParticleSystemNode->addAttribute("lifetime",intToStr(lifetime), mapTagReplacements); unitParticleSystemNode->addAttribute("lifetime",intToStr(lifetime), mapTagReplacements);
// float emissionRateFade; // float emissionRateFade;
unitParticleSystemNode->addAttribute("emissionRateFade",doubleToStr(emissionRateFade,16), mapTagReplacements); unitParticleSystemNode->addAttribute("emissionRateFade",doubleToStr(emissionRateFade,10), mapTagReplacements);
// GameParticleSystem* parent; // GameParticleSystem* parent;
//if(parent != NULL) { //if(parent != NULL) {
// parent->saveGame(unitParticleSystemNode); // parent->saveGame(unitParticleSystemNode);
@ -1535,16 +1520,16 @@ void RainParticleSystem::initParticle(Particle *p, int particleIndex){
p->color= color; p->color= color;
p->energy= 10000; p->energy= 10000;
p->pos= Vec3d(pos.x + x, pos.y, pos.z + y); p->pos= Vec3d(pos.x + x, pos.y, pos.z + y);
p->pos.x = truncateDecimal<double>(p->pos.x,16); p->pos.x = truncateDecimal<double>(p->pos.x,10);
p->pos.y = truncateDecimal<double>(p->pos.y,16); p->pos.y = truncateDecimal<double>(p->pos.y,10);
p->pos.z = truncateDecimal<double>(p->pos.z,16); p->pos.z = truncateDecimal<double>(p->pos.z,10);
p->lastPos= p->pos; p->lastPos= p->pos;
p->speed= Vec3d(random.randRange(-speed / 10, speed / 10), -speed, p->speed= Vec3d(random.randRange(-speed / 10, speed / 10), -speed,
random.randRange(-speed / 10, speed / 10)) + windSpeed; random.randRange(-speed / 10, speed / 10)) + windSpeed;
p->speed.x = truncateDecimal<double>(p->speed.x,16); p->speed.x = truncateDecimal<double>(p->speed.x,10);
p->speed.y = truncateDecimal<double>(p->speed.y,16); p->speed.y = truncateDecimal<double>(p->speed.y,10);
p->speed.z = truncateDecimal<double>(p->speed.z,16); p->speed.z = truncateDecimal<double>(p->speed.z,10);
} }
bool RainParticleSystem::deathTest(Particle *p){ bool RainParticleSystem::deathTest(Particle *p){
@ -1566,9 +1551,9 @@ void RainParticleSystem::setWind(double windAngle, double windSpeed){
this->windSpeed.z= cosf(degToRad(windAngle)) * windSpeed; this->windSpeed.z= cosf(degToRad(windAngle)) * windSpeed;
#endif #endif
this->windSpeed.x = truncateDecimal<double>(this->windSpeed.x,16); this->windSpeed.x = truncateDecimal<double>(this->windSpeed.x,10);
this->windSpeed.y = truncateDecimal<double>(this->windSpeed.y,16); this->windSpeed.y = truncateDecimal<double>(this->windSpeed.y,10);
this->windSpeed.z = truncateDecimal<double>(this->windSpeed.z,16); this->windSpeed.z = truncateDecimal<double>(this->windSpeed.z,10);
} }
Checksum RainParticleSystem::getCRC() { Checksum RainParticleSystem::getCRC() {
@ -1612,18 +1597,18 @@ void SnowParticleSystem::initParticle(Particle *p, int particleIndex){
p->color= color; p->color= color;
p->energy= 10000; p->energy= 10000;
p->pos= Vec3d(pos.x + x, pos.y, pos.z + y); p->pos= Vec3d(pos.x + x, pos.y, pos.z + y);
p->pos.x = truncateDecimal<double>(p->pos.x,16); p->pos.x = truncateDecimal<double>(p->pos.x,10);
p->pos.y = truncateDecimal<double>(p->pos.y,16); p->pos.y = truncateDecimal<double>(p->pos.y,10);
p->pos.z = truncateDecimal<double>(p->pos.z,16); p->pos.z = truncateDecimal<double>(p->pos.z,10);
p->lastPos= p->pos; p->lastPos= p->pos;
p->speed= Vec3d(0.0f, -speed, 0.0f) + windSpeed; p->speed= Vec3d(0.0f, -speed, 0.0f) + windSpeed;
p->speed.x+= random.randRange(-0.005f, 0.005f); p->speed.x+= random.randRange(-0.005f, 0.005f);
p->speed.y+= random.randRange(-0.005f, 0.005f); p->speed.y+= random.randRange(-0.005f, 0.005f);
p->speed.x = truncateDecimal<double>(p->speed.x,16); p->speed.x = truncateDecimal<double>(p->speed.x,10);
p->speed.y = truncateDecimal<double>(p->speed.y,16); p->speed.y = truncateDecimal<double>(p->speed.y,10);
p->speed.z = truncateDecimal<double>(p->speed.z,16); p->speed.z = truncateDecimal<double>(p->speed.z,10);
} }
bool SnowParticleSystem::deathTest(Particle *p){ bool SnowParticleSystem::deathTest(Particle *p){
@ -1645,9 +1630,9 @@ void SnowParticleSystem::setWind(double windAngle, double windSpeed){
this->windSpeed.z= cosf(degToRad(windAngle)) * windSpeed; this->windSpeed.z= cosf(degToRad(windAngle)) * windSpeed;
#endif #endif
this->windSpeed.x = truncateDecimal<double>(this->windSpeed.x,16); this->windSpeed.x = truncateDecimal<double>(this->windSpeed.x,10);
this->windSpeed.y = truncateDecimal<double>(this->windSpeed.y,16); this->windSpeed.y = truncateDecimal<double>(this->windSpeed.y,10);
this->windSpeed.z = truncateDecimal<double>(this->windSpeed.z,16); this->windSpeed.z = truncateDecimal<double>(this->windSpeed.z,10);
} }
@ -1685,9 +1670,9 @@ void AttackParticleSystem::saveGame(XmlNode *rootNode) {
GameParticleSystem::saveGame(attackParticleSystemNode); GameParticleSystem::saveGame(attackParticleSystemNode);
// float sizeNoEnergy; // float sizeNoEnergy;
attackParticleSystemNode->addAttribute("sizeNoEnergy",doubleToStr(sizeNoEnergy,16), mapTagReplacements); attackParticleSystemNode->addAttribute("sizeNoEnergy",doubleToStr(sizeNoEnergy,10), mapTagReplacements);
// float gravity; // float gravity;
attackParticleSystemNode->addAttribute("gravity",doubleToStr(gravity,16), mapTagReplacements); attackParticleSystemNode->addAttribute("gravity",doubleToStr(gravity,10), mapTagReplacements);
} }
void AttackParticleSystem::loadGame(const XmlNode *rootNode) { void AttackParticleSystem::loadGame(const XmlNode *rootNode) {
@ -1760,24 +1745,24 @@ void ProjectileParticleSystem::update(){
if(state == sPlay){ if(state == sPlay){
lastPos = pos; lastPos = pos;
flatPos += zVector * truncateDecimal<double>(trajectorySpeed,16); flatPos += zVector * truncateDecimal<double>(trajectorySpeed,10);
flatPos.x = truncateDecimal<double>(flatPos.x,16); flatPos.x = truncateDecimal<double>(flatPos.x,10);
flatPos.y = truncateDecimal<double>(flatPos.y,16); flatPos.y = truncateDecimal<double>(flatPos.y,10);
flatPos.z = truncateDecimal<double>(flatPos.z,16); flatPos.z = truncateDecimal<double>(flatPos.z,10);
Vec3d targetVector = endPos - startPos; Vec3d targetVector = endPos - startPos;
targetVector.x = truncateDecimal<double>(targetVector.x,16); targetVector.x = truncateDecimal<double>(targetVector.x,10);
targetVector.y = truncateDecimal<double>(targetVector.y,16); targetVector.y = truncateDecimal<double>(targetVector.y,10);
targetVector.z = truncateDecimal<double>(targetVector.z,16); targetVector.z = truncateDecimal<double>(targetVector.z,10);
Vec3d currentVector = flatPos - startPos; Vec3d currentVector = flatPos - startPos;
currentVector.x = truncateDecimal<double>(currentVector.x,16); currentVector.x = truncateDecimal<double>(currentVector.x,10);
currentVector.y = truncateDecimal<double>(currentVector.y,16); currentVector.y = truncateDecimal<double>(currentVector.y,10);
currentVector.z = truncateDecimal<double>(currentVector.z,16); currentVector.z = truncateDecimal<double>(currentVector.z,10);
// ratio // ratio
double relative= clamp(currentVector.length() / targetVector.length(), 0.0f, 1.0f); double relative= clamp(currentVector.length() / targetVector.length(), 0.0f, 1.0f);
relative = truncateDecimal<double>(relative,16); relative = truncateDecimal<double>(relative,10);
//printf("Update particle targetVector [%s][%f] currentVector [%s][%f] relative = %f\n",targetVector.getString().c_str(),targetVector.length(),currentVector.getString().c_str(),currentVector.length(),relative); //printf("Update particle targetVector [%s][%f] currentVector [%s][%f] relative = %f\n",targetVector.getString().c_str(),targetVector.length(),currentVector.getString().c_str(),currentVector.length(),relative);
@ -1800,12 +1785,12 @@ void ProjectileParticleSystem::update(){
break; break;
case tParabolic: { case tParabolic: {
double scaledT = truncateDecimal<double>(2.0f * (relative - 0.5f),16); double scaledT = truncateDecimal<double>(2.0f * (relative - 0.5f),10);
double paraboleY = truncateDecimal<double>((1.0f - scaledT * scaledT) * trajectoryScale,16); double paraboleY = truncateDecimal<double>((1.0f - scaledT * scaledT) * trajectoryScale,10);
pos= flatPos; pos= flatPos;
pos.y += paraboleY; pos.y += paraboleY;
pos.y = truncateDecimal<double>(pos.y,16); pos.y = truncateDecimal<double>(pos.y,10);
} }
break; break;
@ -1818,9 +1803,9 @@ void ProjectileParticleSystem::update(){
pos+= xVector * cos(relative * trajectoryFrequency * targetVector.length()) * trajectoryScale; pos+= xVector * cos(relative * trajectoryFrequency * targetVector.length()) * trajectoryScale;
pos+= yVector * sin(relative * trajectoryFrequency * targetVector.length()) * trajectoryScale; pos+= yVector * sin(relative * trajectoryFrequency * targetVector.length()) * trajectoryScale;
#endif #endif
pos.x = truncateDecimal<double>(pos.x,16); pos.x = truncateDecimal<double>(pos.x,10);
pos.y = truncateDecimal<double>(pos.y,16); pos.y = truncateDecimal<double>(pos.y,10);
pos.z = truncateDecimal<double>(pos.z,16); pos.z = truncateDecimal<double>(pos.z,10);
} }
break; break;
@ -1831,16 +1816,16 @@ void ProjectileParticleSystem::update(){
direction= pos - lastPos; direction= pos - lastPos;
direction.normalize(); direction.normalize();
direction.x = truncateDecimal<double>(direction.x,16); direction.x = truncateDecimal<double>(direction.x,10);
direction.y = truncateDecimal<double>(direction.y,16); direction.y = truncateDecimal<double>(direction.y,10);
direction.z = truncateDecimal<double>(direction.z,16); direction.z = truncateDecimal<double>(direction.z,10);
// trigger update of child particles // trigger update of child particles
positionChildren(); positionChildren();
rotateChildren(); rotateChildren();
//arrive destination //arrive destination
arriveDestinationDistance = truncateDecimal<double>(flatPos.dist(endPos),16); arriveDestinationDistance = truncateDecimal<double>(flatPos.dist(endPos),10);
if(arriveDestinationDistance < 0.5f) { if(arriveDestinationDistance < 0.5f) {
fade(); fade();
model= NULL; model= NULL;
@ -1864,11 +1849,11 @@ void ProjectileParticleSystem::update(){
void ProjectileParticleSystem::rotateChildren() { void ProjectileParticleSystem::rotateChildren() {
//### only on horizontal plane :( //### only on horizontal plane :(
#ifdef USE_STREFLOP #ifdef USE_STREFLOP
double rotation = truncateDecimal<double>(streflop::atan2(static_cast<streflop::Simple>(direction.x), static_cast<streflop::Simple>(direction.z)),16); double rotation = truncateDecimal<double>(streflop::atan2(static_cast<streflop::Simple>(direction.x), static_cast<streflop::Simple>(direction.z)),10);
#else #else
double rotation = truncateDecimal<double>(atan2(direction.x, direction.z),16); double rotation = truncateDecimal<double>(atan2(direction.x, direction.z),10);
#endif #endif
rotation = truncateDecimal<double>(radToDeg(rotation),16); rotation = truncateDecimal<double>(radToDeg(rotation),10);
for(Children::iterator it = children.begin(); it != children.end(); ++it) for(Children::iterator it = children.begin(); it != children.end(); ++it)
(*it)->setRotation(rotation); (*it)->setRotation(rotation);
} }
@ -1878,50 +1863,50 @@ void ProjectileParticleSystem::initParticle(Particle *p, int particleIndex){
ParticleSystem::initParticle(p, particleIndex); ParticleSystem::initParticle(p, particleIndex);
double t= static_cast<double> (particleIndex) / emissionRate; double t= static_cast<double> (particleIndex) / emissionRate;
t = truncateDecimal<double>(t,16); t = truncateDecimal<double>(t,10);
p->pos= pos + (lastPos - pos) * t; p->pos= pos + (lastPos - pos) * t;
p->pos.x = truncateDecimal<double>(p->pos.x,16); p->pos.x = truncateDecimal<double>(p->pos.x,10);
p->pos.y = truncateDecimal<double>(p->pos.y,16); p->pos.y = truncateDecimal<double>(p->pos.y,10);
p->pos.z = truncateDecimal<double>(p->pos.z,16); p->pos.z = truncateDecimal<double>(p->pos.z,10);
p->lastPos= lastPos; p->lastPos= lastPos;
p->speed= Vec3d(random.randRange(-0.1f, 0.1f), random.randRange(-0.1f, 0.1f), p->speed= Vec3d(random.randRange(-0.1f, 0.1f), random.randRange(-0.1f, 0.1f),
random.randRange(-0.1f, 0.1f)) * speed; random.randRange(-0.1f, 0.1f)) * speed;
p->speed.x = truncateDecimal<double>(p->speed.x,16); p->speed.x = truncateDecimal<double>(p->speed.x,10);
p->speed.y = truncateDecimal<double>(p->speed.y,16); p->speed.y = truncateDecimal<double>(p->speed.y,10);
p->speed.z = truncateDecimal<double>(p->speed.z,16); p->speed.z = truncateDecimal<double>(p->speed.z,10);
p->accel= Vec3d(0.0f, -gravity, 0.0f); p->accel= Vec3d(0.0f, -gravity, 0.0f);
p->accel.x = truncateDecimal<double>(p->accel.x,16); p->accel.x = truncateDecimal<double>(p->accel.x,10);
p->accel.y = truncateDecimal<double>(p->accel.y,16); p->accel.y = truncateDecimal<double>(p->accel.y,10);
p->accel.z = truncateDecimal<double>(p->accel.z,16); p->accel.z = truncateDecimal<double>(p->accel.z,10);
updateParticle(p); updateParticle(p);
} }
void ProjectileParticleSystem::updateParticle(Particle *p){ void ProjectileParticleSystem::updateParticle(Particle *p){
double energyRatio= clamp(static_cast<double> (p->energy) / maxParticleEnergy, 0.f, 1.f); double energyRatio= clamp(static_cast<double> (p->energy) / maxParticleEnergy, 0.f, 1.f);
energyRatio = truncateDecimal<double>(energyRatio,16); energyRatio = truncateDecimal<double>(energyRatio,10);
p->lastPos += p->speed; p->lastPos += p->speed;
p->lastPos.x = truncateDecimal<double>(p->lastPos.x,16); p->lastPos.x = truncateDecimal<double>(p->lastPos.x,10);
p->lastPos.y = truncateDecimal<double>(p->lastPos.y,16); p->lastPos.y = truncateDecimal<double>(p->lastPos.y,10);
p->lastPos.z = truncateDecimal<double>(p->lastPos.z,16); p->lastPos.z = truncateDecimal<double>(p->lastPos.z,10);
p->pos += p->speed; p->pos += p->speed;
p->pos.x = truncateDecimal<double>(p->pos.x,16); p->pos.x = truncateDecimal<double>(p->pos.x,10);
p->pos.y = truncateDecimal<double>(p->pos.y,16); p->pos.y = truncateDecimal<double>(p->pos.y,10);
p->pos.z = truncateDecimal<double>(p->pos.z,16); p->pos.z = truncateDecimal<double>(p->pos.z,10);
p->speed += p->accel; p->speed += p->accel;
p->speed.x = truncateDecimal<double>(p->speed.x,16); p->speed.x = truncateDecimal<double>(p->speed.x,10);
p->speed.y = truncateDecimal<double>(p->speed.y,16); p->speed.y = truncateDecimal<double>(p->speed.y,10);
p->speed.z = truncateDecimal<double>(p->speed.z,16); p->speed.z = truncateDecimal<double>(p->speed.z,10);
p->color= color * energyRatio + colorNoEnergy * (1.0f - energyRatio); p->color= color * energyRatio + colorNoEnergy * (1.0f - energyRatio);
p->size = particleSize * energyRatio + sizeNoEnergy * (1.0f - energyRatio); p->size = particleSize * energyRatio + sizeNoEnergy * (1.0f - energyRatio);
p->size = truncateDecimal<double>(p->size,16); p->size = truncateDecimal<double>(p->size,10);
p->energy--; p->energy--;
} }
@ -1929,36 +1914,36 @@ void ProjectileParticleSystem::setPath(Vec3d startPos, Vec3d endPos){
//compute axis //compute axis
zVector= endPos - startPos; zVector= endPos - startPos;
zVector.x = truncateDecimal<double>(zVector.x,16); zVector.x = truncateDecimal<double>(zVector.x,10);
zVector.y = truncateDecimal<double>(zVector.y,16); zVector.y = truncateDecimal<double>(zVector.y,10);
zVector.z = truncateDecimal<double>(zVector.z,16); zVector.z = truncateDecimal<double>(zVector.z,10);
zVector.normalize(); zVector.normalize();
zVector.x = truncateDecimal<double>(zVector.x,16); zVector.x = truncateDecimal<double>(zVector.x,10);
zVector.y = truncateDecimal<double>(zVector.y,16); zVector.y = truncateDecimal<double>(zVector.y,10);
zVector.z = truncateDecimal<double>(zVector.z,16); zVector.z = truncateDecimal<double>(zVector.z,10);
yVector= Vec3d(0.0f, 1.0f, 0.0f); yVector= Vec3d(0.0f, 1.0f, 0.0f);
xVector= zVector.cross(yVector); xVector= zVector.cross(yVector);
xVector.x = truncateDecimal<double>(xVector.x,16); xVector.x = truncateDecimal<double>(xVector.x,10);
xVector.y = truncateDecimal<double>(xVector.y,16); xVector.y = truncateDecimal<double>(xVector.y,10);
xVector.z = truncateDecimal<double>(xVector.z,16); xVector.z = truncateDecimal<double>(xVector.z,10);
//apply offset //apply offset
startPos += xVector * offset.x; startPos += xVector * offset.x;
startPos.x = truncateDecimal<double>(startPos.x,16); startPos.x = truncateDecimal<double>(startPos.x,10);
startPos.y = truncateDecimal<double>(startPos.y,16); startPos.y = truncateDecimal<double>(startPos.y,10);
startPos.z = truncateDecimal<double>(startPos.z,16); startPos.z = truncateDecimal<double>(startPos.z,10);
startPos+= yVector * offset.y; startPos+= yVector * offset.y;
startPos.x = truncateDecimal<double>(startPos.x,16); startPos.x = truncateDecimal<double>(startPos.x,10);
startPos.y = truncateDecimal<double>(startPos.y,16); startPos.y = truncateDecimal<double>(startPos.y,10);
startPos.z = truncateDecimal<double>(startPos.z,16); startPos.z = truncateDecimal<double>(startPos.z,10);
startPos+= zVector * offset.z; startPos+= zVector * offset.z;
startPos.x = truncateDecimal<double>(startPos.x,16); startPos.x = truncateDecimal<double>(startPos.x,10);
startPos.y = truncateDecimal<double>(startPos.y,16); startPos.y = truncateDecimal<double>(startPos.y,10);
startPos.z = truncateDecimal<double>(startPos.z,16); startPos.z = truncateDecimal<double>(startPos.z,10);
pos= startPos; pos= startPos;
lastPos= startPos; lastPos= startPos;
@ -1966,20 +1951,20 @@ void ProjectileParticleSystem::setPath(Vec3d startPos, Vec3d endPos){
//recompute axis //recompute axis
zVector= endPos - startPos; zVector= endPos - startPos;
zVector.x = truncateDecimal<double>(zVector.x,16); zVector.x = truncateDecimal<double>(zVector.x,10);
zVector.y = truncateDecimal<double>(zVector.y,16); zVector.y = truncateDecimal<double>(zVector.y,10);
zVector.z = truncateDecimal<double>(zVector.z,16); zVector.z = truncateDecimal<double>(zVector.z,10);
zVector.normalize(); zVector.normalize();
zVector.x = truncateDecimal<double>(zVector.x,16); zVector.x = truncateDecimal<double>(zVector.x,10);
zVector.y = truncateDecimal<double>(zVector.y,16); zVector.y = truncateDecimal<double>(zVector.y,10);
zVector.z = truncateDecimal<double>(zVector.z,16); zVector.z = truncateDecimal<double>(zVector.z,10);
yVector= Vec3d(0.0f, 1.0f, 0.0f); yVector= Vec3d(0.0f, 1.0f, 0.0f);
xVector= zVector.cross(yVector); xVector= zVector.cross(yVector);
xVector.x = truncateDecimal<double>(xVector.x,16); xVector.x = truncateDecimal<double>(xVector.x,10);
xVector.y = truncateDecimal<double>(xVector.y,16); xVector.y = truncateDecimal<double>(xVector.y,10);
xVector.z = truncateDecimal<double>(xVector.z,16); xVector.z = truncateDecimal<double>(xVector.z,10);
// set members // set members
this->startPos= startPos; this->startPos= startPos;
@ -1987,14 +1972,14 @@ void ProjectileParticleSystem::setPath(Vec3d startPos, Vec3d endPos){
// direction // direction
direction = (endPos - lastPos); direction = (endPos - lastPos);
direction.x = truncateDecimal<double>(direction.x,16); direction.x = truncateDecimal<double>(direction.x,10);
direction.y = truncateDecimal<double>(direction.y,16); direction.y = truncateDecimal<double>(direction.y,10);
direction.z = truncateDecimal<double>(direction.z,16); direction.z = truncateDecimal<double>(direction.z,10);
direction.normalize(); direction.normalize();
direction.x = truncateDecimal<double>(direction.x,16); direction.x = truncateDecimal<double>(direction.x,10);
direction.y = truncateDecimal<double>(direction.y,16); direction.y = truncateDecimal<double>(direction.y,10);
direction.z = truncateDecimal<double>(direction.z,16); direction.z = truncateDecimal<double>(direction.z,10);
rotateChildren(); rotateChildren();
} }
@ -2042,12 +2027,12 @@ void ProjectileParticleSystem::saveGame(XmlNode *rootNode) {
// Trajectory trajectory; // Trajectory trajectory;
projectileParticleSystemNode->addAttribute("trajectory",intToStr(trajectory), mapTagReplacements); projectileParticleSystemNode->addAttribute("trajectory",intToStr(trajectory), mapTagReplacements);
// float trajectorySpeed; // float trajectorySpeed;
projectileParticleSystemNode->addAttribute("trajectorySpeed",doubleToStr(trajectorySpeed,16), mapTagReplacements); projectileParticleSystemNode->addAttribute("trajectorySpeed",doubleToStr(trajectorySpeed,10), mapTagReplacements);
// //parabolic // //parabolic
// float trajectoryScale; // float trajectoryScale;
projectileParticleSystemNode->addAttribute("trajectoryScale",doubleToStr(trajectoryScale,16), mapTagReplacements); projectileParticleSystemNode->addAttribute("trajectoryScale",doubleToStr(trajectoryScale,10), mapTagReplacements);
// float trajectoryFrequency; // float trajectoryFrequency;
projectileParticleSystemNode->addAttribute("trajectoryFrequency",doubleToStr(trajectoryFrequency,16), mapTagReplacements); projectileParticleSystemNode->addAttribute("trajectoryFrequency",doubleToStr(trajectoryFrequency,10), mapTagReplacements);
} }
void ProjectileParticleSystem::loadGame(const XmlNode *rootNode) { void ProjectileParticleSystem::loadGame(const XmlNode *rootNode) {
@ -2160,10 +2145,10 @@ void SplashParticleSystem::update() {
ParticleSystem::update(); ParticleSystem::update();
if(state != sPause) { if(state != sPause) {
emissionRate -= emissionRateFade; emissionRate -= emissionRateFade;
emissionRate = truncateDecimal<double>(emissionRate,16); emissionRate = truncateDecimal<double>(emissionRate,10);
double t = 1.0f - ((emissionRate + startEmissionRate) / (startEmissionRate * 2.0f)); double t = 1.0f - ((emissionRate + startEmissionRate) / (startEmissionRate * 2.0f));
t = truncateDecimal<double>(t,16); t = truncateDecimal<double>(t,10);
t= clamp(t, 0.0f, 1.0f); t= clamp(t, 0.0f, 1.0f);
setTween(t,t); setTween(t,t);
@ -2186,14 +2171,14 @@ void SplashParticleSystem::initParticle(Particle *p, int particleIndex){
+ horizontalSpreadB); + horizontalSpreadB);
p->speed.normalize(); p->speed.normalize();
p->speed= p->speed * speed; p->speed= p->speed * speed;
p->speed.x = truncateDecimal<double>(p->speed.x,16); p->speed.x = truncateDecimal<double>(p->speed.x,10);
p->speed.y = truncateDecimal<double>(p->speed.y,16); p->speed.y = truncateDecimal<double>(p->speed.y,10);
p->speed.z = truncateDecimal<double>(p->speed.z,16); p->speed.z = truncateDecimal<double>(p->speed.z,10);
p->accel= Vec3d(0.0f, -gravity, 0.0f); p->accel= Vec3d(0.0f, -gravity, 0.0f);
p->accel.x = truncateDecimal<double>(p->accel.x,16); p->accel.x = truncateDecimal<double>(p->accel.x,10);
p->accel.y = truncateDecimal<double>(p->accel.y,16); p->accel.y = truncateDecimal<double>(p->accel.y,10);
p->accel.z = truncateDecimal<double>(p->accel.z,16); p->accel.z = truncateDecimal<double>(p->accel.z,10);
} }
@ -2202,19 +2187,19 @@ void SplashParticleSystem::updateParticle(Particle *p){
p->lastPos= p->pos; p->lastPos= p->pos;
p->pos= p->pos + p->speed; p->pos= p->pos + p->speed;
p->pos.x = truncateDecimal<double>(p->pos.x,16); p->pos.x = truncateDecimal<double>(p->pos.x,10);
p->pos.y = truncateDecimal<double>(p->pos.y,16); p->pos.y = truncateDecimal<double>(p->pos.y,10);
p->pos.z = truncateDecimal<double>(p->pos.z,16); p->pos.z = truncateDecimal<double>(p->pos.z,10);
p->speed= p->speed + p->accel; p->speed= p->speed + p->accel;
p->speed.x = truncateDecimal<double>(p->speed.x,16); p->speed.x = truncateDecimal<double>(p->speed.x,10);
p->speed.y = truncateDecimal<double>(p->speed.y,16); p->speed.y = truncateDecimal<double>(p->speed.y,10);
p->speed.z = truncateDecimal<double>(p->speed.z,16); p->speed.z = truncateDecimal<double>(p->speed.z,10);
p->energy--; p->energy--;
p->color= color * energyRatio + colorNoEnergy * (1.0f - energyRatio); p->color= color * energyRatio + colorNoEnergy * (1.0f - energyRatio);
p->size= particleSize * energyRatio + sizeNoEnergy * (1.0f - energyRatio); p->size= particleSize * energyRatio + sizeNoEnergy * (1.0f - energyRatio);
p->size = truncateDecimal<double>(p->size,16); p->size = truncateDecimal<double>(p->size,10);
} }
void SplashParticleSystem::saveGame(XmlNode *rootNode) { void SplashParticleSystem::saveGame(XmlNode *rootNode) {
@ -2229,18 +2214,18 @@ void SplashParticleSystem::saveGame(XmlNode *rootNode) {
} }
// float emissionRateFade; // float emissionRateFade;
splashParticleSystemNode->addAttribute("emissionRateFade",doubleToStr(emissionRateFade,16), mapTagReplacements); splashParticleSystemNode->addAttribute("emissionRateFade",doubleToStr(emissionRateFade,10), mapTagReplacements);
// float verticalSpreadA; // float verticalSpreadA;
splashParticleSystemNode->addAttribute("verticalSpreadA",doubleToStr(verticalSpreadA,16), mapTagReplacements); splashParticleSystemNode->addAttribute("verticalSpreadA",doubleToStr(verticalSpreadA,10), mapTagReplacements);
// float verticalSpreadB; // float verticalSpreadB;
splashParticleSystemNode->addAttribute("verticalSpreadB",doubleToStr(verticalSpreadB,16), mapTagReplacements); splashParticleSystemNode->addAttribute("verticalSpreadB",doubleToStr(verticalSpreadB,10), mapTagReplacements);
// float horizontalSpreadA; // float horizontalSpreadA;
splashParticleSystemNode->addAttribute("horizontalSpreadA",doubleToStr(horizontalSpreadA,16), mapTagReplacements); splashParticleSystemNode->addAttribute("horizontalSpreadA",doubleToStr(horizontalSpreadA,10), mapTagReplacements);
// float horizontalSpreadB; // float horizontalSpreadB;
splashParticleSystemNode->addAttribute("horizontalSpreadB",doubleToStr(horizontalSpreadB,16), mapTagReplacements); splashParticleSystemNode->addAttribute("horizontalSpreadB",doubleToStr(horizontalSpreadB,10), mapTagReplacements);
// //
// float startEmissionRate; // float startEmissionRate;
splashParticleSystemNode->addAttribute("startEmissionRate",doubleToStr(startEmissionRate,16), mapTagReplacements); splashParticleSystemNode->addAttribute("startEmissionRate",doubleToStr(startEmissionRate,10), mapTagReplacements);
} }
void SplashParticleSystem::loadGame(const XmlNode *rootNode) { void SplashParticleSystem::loadGame(const XmlNode *rootNode) {

View File

@ -519,7 +519,7 @@ void Properties::setBool(const string &key, bool value){
} }
void Properties::setFloat(const string &key, float value){ void Properties::setFloat(const string &key, float value){
setString(key, floatToStr(value,16)); setString(key, floatToStr(value,10));
} }
void Properties::setString(const string &key, const string &value){ void Properties::setString(const string &key, const string &value){

View File

@ -81,7 +81,7 @@ int RandomGen::randRange(int min, int max,string lastCaller) {
int diff= max-min; int diff= max-min;
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),16)); int res= min + static_cast<int>(truncateDecimal<double>(numerator / static_cast<double>(m),10));
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,7 +102,7 @@ double RandomGen::randRange(double min, double max,string lastCaller) {
double rand01 = static_cast<double>(RandomGen::rand(lastCaller)) / (m-1); double rand01 = static_cast<double>(RandomGen::rand(lastCaller)) / (m-1);
double res= min + (max - min) * rand01; double res= min + (max - min) * rand01;
res = truncateDecimal<double>(res,16); res = truncateDecimal<double>(res,10);
if(res < min || res > max) { if(res < min || res > max) {
char szBuf[8096]=""; char szBuf[8096]="";