From dc503d634000536ce39c9a0e7d0e19d90766955c Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Wed, 2 Oct 2013 20:22:10 +0000 Subject: [PATCH] - attempt to see if this makes stability better --- source/g3d_viewer/main.cpp | 6 +- source/glest_game/ai/path_finder.cpp | 2 +- source/glest_game/game/game.cpp | 14 +- source/glest_game/game/game_camera.cpp | 24 +- source/glest_game/game/stats.cpp | 4 +- source/glest_game/graphics/particle_type.cpp | 30 +- source/glest_game/graphics/particle_type.h | 30 +- source/glest_game/graphics/renderer.cpp | 4 +- .../graphics/unit_particle_type.cpp | 16 +- .../glest_game/graphics/unit_particle_type.h | 22 +- source/glest_game/gui/gui.cpp | 2 +- source/glest_game/gui/selection.cpp | 2 +- source/glest_game/gui/selection.h | 2 +- source/glest_game/menu/menu_background.cpp | 2 +- source/glest_game/type_instances/object.cpp | 20 +- source/glest_game/type_instances/object.h | 18 +- source/glest_game/type_instances/unit.cpp | 134 ++-- source/glest_game/type_instances/unit.h | 40 +- source/glest_game/types/skill_type.cpp | 6 +- source/glest_game/types/skill_type.h | 12 +- source/glest_game/types/unit_type.cpp | 2 +- source/glest_game/types/unit_type.h | 6 +- source/glest_game/world/map.cpp | 28 +- source/glest_game/world/map.h | 22 +- source/glest_game/world/tileset.cpp | 16 +- source/glest_game/world/tileset.h | 16 +- source/glest_game/world/time_flow.cpp | 6 +- source/glest_game/world/unit_updater.cpp | 40 +- source/glest_game/world/unit_updater.h | 4 +- source/shared_lib/include/graphics/particle.h | 198 +++--- .../shared_lib/sources/graphics/particle.cpp | 670 +++++++++--------- source/shared_lib/sources/util/properties.cpp | 2 +- source/shared_lib/sources/util/randomgen.cpp | 4 +- 33 files changed, 692 insertions(+), 712 deletions(-) diff --git a/source/g3d_viewer/main.cpp b/source/g3d_viewer/main.cpp index b0c1acf2..5d7f0ae1 100644 --- a/source/g3d_viewer/main.cpp +++ b/source/g3d_viewer/main.cpp @@ -1340,7 +1340,7 @@ void MainWindow::loadParticle(string path) { (*it)->setValues(ups); if(size > 0) { //getCurrVectorFlat() + Vec3f(0.f, type->getHeight()/2.f, 0.f); - Vec3d vec = Vec3d(0.f, height / 2.f, 0.f); + Vec3f vec = Vec3f(0.f, height / 2.f, 0.f); ups->setPos(vec); } //ups->setFactionColor(getFaction()->getTexture()->getPixmap()->getPixel3f(0,0)); @@ -1453,10 +1453,10 @@ void MainWindow::loadProjectileParticle(string path) { ProjectileParticleSystem *ps = (*it)->create(NULL); if(size > 0) { - Vec3d vec = Vec3d(0.f, height / 2.f, 0.f); + Vec3f vec = Vec3f(0.f, height / 2.f, 0.f); //ps->setPos(vec); - Vec3d vec2 = Vec3d(size * 2.f, height * 2.f, height * 2.f); + Vec3f vec2 = Vec3f(size * 2.f, height * 2.f, height * 2.f); ps->setPath(vec, vec2); } ps->setFactionColor(renderer->getPlayerColorTexture(playerColor)->getPixmap()->getPixel3f(0,0)); diff --git a/source/glest_game/ai/path_finder.cpp b/source/glest_game/ai/path_finder.cpp index b576b38f..1f52bd72 100644 --- a/source/glest_game/ai/path_finder.cpp +++ b/source/glest_game/ai/path_finder.cpp @@ -1639,7 +1639,7 @@ void PathFinder::saveGame(XmlNode *rootNode) { nodePoolNode->addAttribute("next",intToStr(nextIdx), mapTagReplacements); int prevIdx = findNodeIndex(curNode->prev, factionState.nodePool); nodePoolNode->addAttribute("prev",intToStr(prevIdx), mapTagReplacements); - nodePoolNode->addAttribute("heuristic",doubleToStr(curNode->heuristic,10), mapTagReplacements); + nodePoolNode->addAttribute("heuristic",doubleToStr(curNode->heuristic,6), mapTagReplacements); nodePoolNode->addAttribute("exploredCell",intToStr(curNode->exploredCell), mapTagReplacements); } diff --git a/source/glest_game/game/game.cpp b/source/glest_game/game/game.cpp index 7f72e583..70405966 100644 --- a/source/glest_game/game/game.cpp +++ b/source/glest_game/game/game.cpp @@ -1418,14 +1418,14 @@ void Game::init(bool initForPreviewOnly) { logger.add(Lang::getInstance().get("LogScreenGameLoadingCreatingRainParticles","",true), true); weatherParticleSystem= new RainParticleSystem(); weatherParticleSystem->setSpeed(12.f / GameConstants::updateFps); - weatherParticleSystem->setPos(Vec3d(gameCamera.getPos())); + weatherParticleSystem->setPos(gameCamera.getPos()); renderer.manageParticleSystem(weatherParticleSystem, rsGame); } else if(world.getTileset()->getWeather() == wSnowy) { logger.add(Lang::getInstance().get("LogScreenGameLoadingCreatingSnowParticles","",true), true); weatherParticleSystem= new SnowParticleSystem(1200); weatherParticleSystem->setSpeed(1.5f / GameConstants::updateFps); - weatherParticleSystem->setPos(Vec3d(gameCamera.getPos())); + weatherParticleSystem->setPos(gameCamera.getPos()); weatherParticleSystem->setTexture(coreData.getSnowTexture()); renderer.manageParticleSystem(weatherParticleSystem, rsGame); } @@ -2143,7 +2143,7 @@ void Game::update() { } if(currentCameraFollowUnit!=NULL){ - Vec3d c=currentCameraFollowUnit->getCurrVector(); + Vec3f c=currentCameraFollowUnit->getCurrVector(); int rotation=currentCameraFollowUnit->getRotation(); double angle=rotation+180; @@ -2192,7 +2192,7 @@ void Game::update() { //Particle systems if(weatherParticleSystem != NULL) { - weatherParticleSystem->setPos(Vec3d(gameCamera.getPos())); + weatherParticleSystem->setPos(gameCamera.getPos()); } if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld [weather particle updating i = %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis(),i); @@ -6242,7 +6242,7 @@ string Game::saveGame(string name, string path) { //bool showFullConsole; //bool mouseMoved; //float scrollSpeed; - gameNode->addAttribute("scrollSpeed",floatToStr(scrollSpeed,10), mapTagReplacements); + gameNode->addAttribute("scrollSpeed",floatToStr(scrollSpeed,6), mapTagReplacements); //bool camLeftButtonDown; //bool camRightButtonDown; //bool camUpButtonDown; @@ -6336,8 +6336,8 @@ string Game::saveGame(string name, string path) { HighlightSpecialUnitInfo &info = iterMap->second; XmlNode *infoNode = unitHighlightListNode->addChild("info"); infoNode->addAttribute("unitid",intToStr(iterMap->first), mapTagReplacements); - infoNode->addAttribute("radius",floatToStr(info.radius,10), mapTagReplacements); - infoNode->addAttribute("thickness",floatToStr(info.thickness,10), mapTagReplacements); + infoNode->addAttribute("radius",floatToStr(info.radius,6), mapTagReplacements); + infoNode->addAttribute("thickness",floatToStr(info.thickness,6), mapTagReplacements); infoNode->addAttribute("color",info.color.getString(), mapTagReplacements); } diff --git a/source/glest_game/game/game_camera.cpp b/source/glest_game/game/game_camera.cpp index 8a5d514d..a0879016 100644 --- a/source/glest_game/game/game_camera.cpp +++ b/source/glest_game/game/game_camera.cpp @@ -466,18 +466,18 @@ void GameCamera::saveGame(XmlNode *rootNode) { gamecameraNode->addAttribute("destPos",destPos.getString(), mapTagReplacements); // // float hAng; //YZ plane positive -Z axis - gamecameraNode->addAttribute("hAng",floatToStr(hAng,10), mapTagReplacements); + gamecameraNode->addAttribute("hAng",floatToStr(hAng,6), mapTagReplacements); // float vAng; //XZ plane positive +Z axis - gamecameraNode->addAttribute("vAng",floatToStr(vAng,10), mapTagReplacements); + gamecameraNode->addAttribute("vAng",floatToStr(vAng,6), mapTagReplacements); // float lastHAng; - gamecameraNode->addAttribute("lastHAng",floatToStr(lastHAng,10), mapTagReplacements); + gamecameraNode->addAttribute("lastHAng",floatToStr(lastHAng,6), mapTagReplacements); // float lastVAng; - gamecameraNode->addAttribute("lastVAng",floatToStr(lastVAng,10), mapTagReplacements); + gamecameraNode->addAttribute("lastVAng",floatToStr(lastVAng,6), mapTagReplacements); // Vec2f destAng; gamecameraNode->addAttribute("destAng",destAng.getString(), mapTagReplacements); // float rotate; - gamecameraNode->addAttribute("rotate",floatToStr(rotate,10), mapTagReplacements); + gamecameraNode->addAttribute("rotate",floatToStr(rotate,6), mapTagReplacements); // Vec3f move; gamecameraNode->addAttribute("move",move.getString(), mapTagReplacements); // State state; @@ -488,24 +488,24 @@ void GameCamera::saveGame(XmlNode *rootNode) { gamecameraNode->addAttribute("limitY",intToStr(limitY), mapTagReplacements); // //config // float speed; - gamecameraNode->addAttribute("speed",floatToStr(speed,10), mapTagReplacements); + gamecameraNode->addAttribute("speed",floatToStr(speed,6), mapTagReplacements); // bool clampBounds; gamecameraNode->addAttribute("clampBounds",intToStr(clampBounds), mapTagReplacements); // //float maxRenderDistance; // float maxHeight; - gamecameraNode->addAttribute("maxHeight",floatToStr(maxHeight,10), mapTagReplacements); + gamecameraNode->addAttribute("maxHeight",floatToStr(maxHeight,6), mapTagReplacements); // float minHeight; - gamecameraNode->addAttribute("minHeight",floatToStr(minHeight,10), mapTagReplacements); + gamecameraNode->addAttribute("minHeight",floatToStr(minHeight,6), mapTagReplacements); // //float maxCameraDist; // //float minCameraDist; // float minVAng; - gamecameraNode->addAttribute("minVAng",floatToStr(minVAng,10), mapTagReplacements); + gamecameraNode->addAttribute("minVAng",floatToStr(minVAng,6), mapTagReplacements); // float maxVAng; - gamecameraNode->addAttribute("maxVAng",floatToStr(maxVAng,10), mapTagReplacements); + gamecameraNode->addAttribute("maxVAng",floatToStr(maxVAng,6), mapTagReplacements); // float fov; - gamecameraNode->addAttribute("fov",floatToStr(fov,10), mapTagReplacements); + gamecameraNode->addAttribute("fov",floatToStr(fov,6), mapTagReplacements); // float calculatedDefault; - gamecameraNode->addAttribute("calculatedDefault",floatToStr(calculatedDefault,10), mapTagReplacements); + gamecameraNode->addAttribute("calculatedDefault",floatToStr(calculatedDefault,6), mapTagReplacements); // std::map > > cacheVisibleQuad; // int MaxVisibleQuadItemCache; gamecameraNode->addAttribute("MaxVisibleQuadItemCache",intToStr(MaxVisibleQuadItemCache), mapTagReplacements); diff --git a/source/glest_game/game/stats.cpp b/source/glest_game/game/stats.cpp index bd67cd31..7ff8f727 100644 --- a/source/glest_game/game/stats.cpp +++ b/source/glest_game/game/stats.cpp @@ -179,7 +179,7 @@ void Stats::saveGame(XmlNode *rootNode) { // ControlType control; statsNodePlayer->addAttribute("control",intToStr(stat.control), mapTagReplacements); // float resourceMultiplier; - statsNodePlayer->addAttribute("resourceMultiplier",floatToStr(stat.resourceMultiplier,10), mapTagReplacements); + statsNodePlayer->addAttribute("resourceMultiplier",floatToStr(stat.resourceMultiplier,6), mapTagReplacements); // string factionTypeName; statsNodePlayer->addAttribute("factionTypeName",stat.factionTypeName, mapTagReplacements); // FactionPersonalityType personalityType; @@ -211,7 +211,7 @@ void Stats::saveGame(XmlNode *rootNode) { statsNode->addAttribute("thisFactionIndex",intToStr(thisFactionIndex), mapTagReplacements); // // float worldTimeElapsed; - statsNode->addAttribute("worldTimeElapsed",floatToStr(worldTimeElapsed,10), mapTagReplacements); + statsNode->addAttribute("worldTimeElapsed",floatToStr(worldTimeElapsed,6), mapTagReplacements); // int framesPlayed; statsNode->addAttribute("framesPlayed",intToStr(framesPlayed), mapTagReplacements); // int framesToCalculatePlaytime; diff --git a/source/glest_game/graphics/particle_type.cpp b/source/glest_game/graphics/particle_type.cpp index 5cb6620e..5cb2c3fe 100644 --- a/source/glest_game/graphics/particle_type.cpp +++ b/source/glest_game/graphics/particle_type.cpp @@ -327,7 +327,7 @@ void ParticleSystemType::saveGame(XmlNode *rootNode) { // Texture2D *texture; // Model *model; // float modelCycle; - particleSystemTypeNode->addAttribute("modelCycle",doubleToStr(modelCycle,10), mapTagReplacements); + particleSystemTypeNode->addAttribute("modelCycle",floatToStr(modelCycle,6), mapTagReplacements); // string primitive; particleSystemTypeNode->addAttribute("primitive",primitive, mapTagReplacements); // Vec3f offset; @@ -337,15 +337,15 @@ void ParticleSystemType::saveGame(XmlNode *rootNode) { // Vec4f colorNoEnergy; particleSystemTypeNode->addAttribute("colorNoEnergy",colorNoEnergy.getString(), mapTagReplacements); // float size; - particleSystemTypeNode->addAttribute("size",doubleToStr(size,10), mapTagReplacements); + particleSystemTypeNode->addAttribute("size",floatToStr(size,6), mapTagReplacements); // float sizeNoEnergy; - particleSystemTypeNode->addAttribute("sizeNoEnergy",doubleToStr(sizeNoEnergy,10), mapTagReplacements); + particleSystemTypeNode->addAttribute("sizeNoEnergy",floatToStr(sizeNoEnergy,6), mapTagReplacements); // float speed; - particleSystemTypeNode->addAttribute("speed",doubleToStr(speed,10), mapTagReplacements); + particleSystemTypeNode->addAttribute("speed",floatToStr(speed,6), mapTagReplacements); // float gravity; - particleSystemTypeNode->addAttribute("gravity",doubleToStr(gravity,10), mapTagReplacements); + particleSystemTypeNode->addAttribute("gravity",floatToStr(gravity,6), mapTagReplacements); // float emissionRate; - particleSystemTypeNode->addAttribute("emissionRate",doubleToStr(emissionRate,10), mapTagReplacements); + particleSystemTypeNode->addAttribute("emissionRate",floatToStr(emissionRate,6), mapTagReplacements); // int energyMax; particleSystemTypeNode->addAttribute("energyMax",intToStr(energyMax), mapTagReplacements); // int energyVar; @@ -413,7 +413,7 @@ void ParticleSystemTypeProjectile::load(const XmlNode* particleFileNode, const s //trajectory speed const XmlNode *tajectorySpeedNode= tajectoryNode->getChild("speed"); - trajectorySpeed= tajectorySpeedNode->getAttribute("value")->getFloatValue() / (double)GameConstants::updateFps; + trajectorySpeed= tajectorySpeedNode->getAttribute("value")->getFloatValue() / (float)GameConstants::updateFps; //printf("[%s] trajectorySpeed = %f\n",path.c_str(),trajectorySpeed); if(trajectory=="parabolic" || trajectory=="spiral"){ @@ -466,11 +466,11 @@ void ParticleSystemTypeProjectile::saveGame(XmlNode *rootNode) { // string trajectory; particleSystemTypeProjectileNode->addAttribute("trajectory",trajectory, mapTagReplacements); // float trajectorySpeed; - particleSystemTypeProjectileNode->addAttribute("trajectorySpeed",doubleToStr(trajectorySpeed,10), mapTagReplacements); + particleSystemTypeProjectileNode->addAttribute("trajectorySpeed",floatToStr(trajectorySpeed,6), mapTagReplacements); // float trajectoryScale; - particleSystemTypeProjectileNode->addAttribute("trajectoryScale",doubleToStr(trajectoryScale,10), mapTagReplacements); + particleSystemTypeProjectileNode->addAttribute("trajectoryScale",floatToStr(trajectoryScale,6), mapTagReplacements); // float trajectoryFrequency; - particleSystemTypeProjectileNode->addAttribute("trajectoryFrequency",doubleToStr(trajectoryFrequency,10), mapTagReplacements); + particleSystemTypeProjectileNode->addAttribute("trajectoryFrequency",floatToStr(trajectoryFrequency,6), mapTagReplacements); } // =========================================================== @@ -549,15 +549,15 @@ void ParticleSystemTypeSplash::saveGame(XmlNode *rootNode) { XmlNode *particleSystemTypeSplashNode = rootNode->addChild("ParticleSystemTypeSplash"); // float emissionRateFade; - particleSystemTypeSplashNode->addAttribute("emissionRateFade",doubleToStr(emissionRateFade,10), mapTagReplacements); + particleSystemTypeSplashNode->addAttribute("emissionRateFade",floatToStr(emissionRateFade,6), mapTagReplacements); // float verticalSpreadA; - particleSystemTypeSplashNode->addAttribute("verticalSpreadA",doubleToStr(verticalSpreadA,10), mapTagReplacements); + particleSystemTypeSplashNode->addAttribute("verticalSpreadA",floatToStr(verticalSpreadA,6), mapTagReplacements); // float verticalSpreadB; - particleSystemTypeSplashNode->addAttribute("verticalSpreadB",doubleToStr(verticalSpreadB,10), mapTagReplacements); + particleSystemTypeSplashNode->addAttribute("verticalSpreadB",floatToStr(verticalSpreadB,6), mapTagReplacements); // float horizontalSpreadA; - particleSystemTypeSplashNode->addAttribute("horizontalSpreadA",doubleToStr(horizontalSpreadA,10), mapTagReplacements); + particleSystemTypeSplashNode->addAttribute("horizontalSpreadA",floatToStr(horizontalSpreadA,6), mapTagReplacements); // float horizontalSpreadB; - particleSystemTypeSplashNode->addAttribute("horizontalSpreadB",doubleToStr(horizontalSpreadB,10), mapTagReplacements); + particleSystemTypeSplashNode->addAttribute("horizontalSpreadB",floatToStr(horizontalSpreadB,6), mapTagReplacements); } }}//end mamespace diff --git a/source/glest_game/graphics/particle_type.h b/source/glest_game/graphics/particle_type.h index 0ed38bbd..2ab47aed 100644 --- a/source/glest_game/graphics/particle_type.h +++ b/source/glest_game/graphics/particle_type.h @@ -57,16 +57,16 @@ protected: string type; Texture2D *texture; Model *model; - double modelCycle; + float modelCycle; string primitive; - Vec3d offset; + Vec3f offset; Vec4f color; Vec4f colorNoEnergy; - double size; - double sizeNoEnergy; - double speed; - double gravity; - double emissionRate; + int size; + int sizeNoEnergy; + float speed; + float gravity; + int emissionRate; int energyMax; int energyVar; string mode; @@ -123,9 +123,9 @@ protected: class ParticleSystemTypeProjectile: public ParticleSystemType{ private: string trajectory; - double trajectorySpeed; - double trajectoryScale; - double trajectoryFrequency; + float trajectorySpeed; + float trajectoryScale; + float trajectoryFrequency; public: ParticleSystemTypeProjectile(); @@ -153,11 +153,11 @@ public: virtual void saveGame(XmlNode *rootNode); private: - double emissionRateFade; - double verticalSpreadA; - double verticalSpreadB; - double horizontalSpreadA; - double horizontalSpreadB; + float emissionRateFade; + float verticalSpreadA; + float verticalSpreadB; + float horizontalSpreadA; + float horizontalSpreadB; }; }}//end namespace diff --git a/source/glest_game/graphics/renderer.cpp b/source/glest_game/graphics/renderer.cpp index f5052f5d..ba133f89 100644 --- a/source/glest_game/graphics/renderer.cpp +++ b/source/glest_game/graphics/renderer.cpp @@ -1054,7 +1054,7 @@ void Renderer::setupLighting() { Unit *unit = qCache.visibleQuadUnitList[visibleUnitIndex]; if(world->toRenderUnit(unit) && - unit->getCurrVector().dist(Vec3d(gameCamera->getPos())) < maxLightDist && + unit->getCurrVector().dist(gameCamera->getPos()) < maxLightDist && unit->getType()->getLight() && unit->isOperative()) { //printf("$$$ Show light for faction: %s # %d / %d for Unit [%d - %s]\n",world->getFaction(i)->getType()->getName().c_str(),lightCount,maxLights,unit->getId(),unit->getFullName().c_str()); @@ -6662,7 +6662,7 @@ void Renderer::selectUsingFrustumSelection(Selection::UnitContainer &units, visibleUnitIndex < qCache.visibleQuadUnitList.size(); ++visibleUnitIndex) { Unit *unit = qCache.visibleQuadUnitList[visibleUnitIndex]; if(unit != NULL && unit->isAlive()) { - Vec3d unitPos = unit->getCurrVector(); + Vec3f unitPos = unit->getCurrVector(); bool insideQuad = CubeInFrustum(quadSelectionCacheItem.frustumData, unitPos.x, unitPos.y, unitPos.z, unit->getType()->getSize()); if(insideQuad == true) { diff --git a/source/glest_game/graphics/unit_particle_type.cpp b/source/glest_game/graphics/unit_particle_type.cpp index 2462bfa4..a6639029 100644 --- a/source/glest_game/graphics/unit_particle_type.cpp +++ b/source/glest_game/graphics/unit_particle_type.cpp @@ -172,7 +172,7 @@ void UnitParticleSystemType::load(const XmlNode *particleSystemNode, const strin // delay if(particleSystemNode->hasChild("delay")) { const XmlNode* delayNode = particleSystemNode->getChild("delay"); - const double delay_secs = delayNode->getAttribute("value")->getFloatValue(); + const float delay_secs = delayNode->getAttribute("value")->getFloatValue(); if(delay_secs < 0) throw megaglest_runtime_error("particle effect delay cannot be negative"); delay = (int)delay_secs * GameConstants::updateFps; @@ -183,7 +183,7 @@ void UnitParticleSystemType::load(const XmlNode *particleSystemNode, const strin // lifetime if(particleSystemNode->hasChild("lifetime")) { const XmlNode* lifetimeNode = particleSystemNode->getChild("lifetime"); - const double lifetime_secs = lifetimeNode->getAttribute("value")->getFloatValue(); + const float lifetime_secs = lifetimeNode->getAttribute("value")->getFloatValue(); if(lifetime_secs < 0 && lifetime_secs != -1) throw megaglest_runtime_error("particle effect lifetime cannot be negative (-1 means inherited from parent particle)"); lifetime = (int)lifetime_secs * GameConstants::updateFps; @@ -300,13 +300,13 @@ void UnitParticleSystemType::saveGame(XmlNode *rootNode) { // UnitParticleSystem::Shape shape; unitParticleSystemTypeNode->addAttribute("shape",intToStr(shape), mapTagReplacements); // float angle; - unitParticleSystemTypeNode->addAttribute("angle",doubleToStr(angle,10), mapTagReplacements); + unitParticleSystemTypeNode->addAttribute("angle",floatToStr(angle,6), mapTagReplacements); // float radius; - unitParticleSystemTypeNode->addAttribute("radius",doubleToStr(radius,10), mapTagReplacements); + unitParticleSystemTypeNode->addAttribute("radius",floatToStr(radius,6), mapTagReplacements); // float minRadius; - unitParticleSystemTypeNode->addAttribute("minRadius",doubleToStr(minRadius,10), mapTagReplacements); + unitParticleSystemTypeNode->addAttribute("minRadius",floatToStr(minRadius,6), mapTagReplacements); // float emissionRateFade; - unitParticleSystemTypeNode->addAttribute("emissionRateFade",doubleToStr(emissionRateFade,10), mapTagReplacements); + unitParticleSystemTypeNode->addAttribute("emissionRateFade",floatToStr(emissionRateFade,6), mapTagReplacements); // Vec3f direction; unitParticleSystemTypeNode->addAttribute("direction",direction.getString(), mapTagReplacements); // bool relative; @@ -330,9 +330,9 @@ void UnitParticleSystemType::saveGame(XmlNode *rootNode) { // int lifetime; unitParticleSystemTypeNode->addAttribute("lifetime",intToStr(lifetime), mapTagReplacements); // float startTime; - unitParticleSystemTypeNode->addAttribute("startTime",doubleToStr(startTime,10), mapTagReplacements); + unitParticleSystemTypeNode->addAttribute("startTime",floatToStr(startTime,6), mapTagReplacements); // float endTime; - unitParticleSystemTypeNode->addAttribute("endTime",doubleToStr(endTime,10), mapTagReplacements); + unitParticleSystemTypeNode->addAttribute("endTime",floatToStr(endTime,6), mapTagReplacements); } }}//end mamespace diff --git a/source/glest_game/graphics/unit_particle_type.h b/source/glest_game/graphics/unit_particle_type.h index b2a9ceac..17ed5232 100644 --- a/source/glest_game/graphics/unit_particle_type.h +++ b/source/glest_game/graphics/unit_particle_type.h @@ -52,11 +52,11 @@ using Shared::Xml::XmlNode; class UnitParticleSystemType: public ParticleSystemType { protected: UnitParticleSystem::Shape shape; - double angle; - double radius; - double minRadius; - double emissionRateFade; - Vec3d direction; + float angle; + float radius; + float minRadius; + float emissionRateFade; + Vec3f direction; bool relative; bool relativeDirection; bool fixed; @@ -67,8 +67,8 @@ protected: bool radiusBasedStartenergy; int delay; int lifetime; - double startTime; - double endTime; + float startTime; + float endTime; public: UnitParticleSystemType(); @@ -81,10 +81,10 @@ public: std::map > > &loadedFileList,string parentLoader, string techtreePath); - void setStartTime(double startTime) { this->startTime = startTime; } - double getStartTime() const { return this->startTime; } - void setEndTime(double endTime) { this->endTime = endTime; } - double getEndTime() const { return this->endTime; } + void setStartTime(float startTime) { this->startTime = startTime; } + float getStartTime() const { return this->startTime; } + void setEndTime(float endTime) { this->endTime = endTime; } + float getEndTime() const { return this->endTime; } const void setValues (UnitParticleSystem *uts); bool hasTexture() const { return(texture != NULL); } diff --git a/source/glest_game/gui/gui.cpp b/source/glest_game/gui/gui.cpp index e2ad7368..68928ccf 100644 --- a/source/glest_game/gui/gui.cpp +++ b/source/glest_game/gui/gui.cpp @@ -540,7 +540,7 @@ void Gui::giveTwoClickOrders(int x, int y , bool prepared) { void Gui::centerCameraOnSelection() { if(selection.isEmpty() == false) { - Vec3d refPos= selection.getRefPos(); + Vec3f refPos= selection.getRefPos(); gameCamera->centerXZ(refPos.x, refPos.z); } } diff --git a/source/glest_game/gui/selection.cpp b/source/glest_game/gui/selection.cpp index ae8eb9c8..9286e148 100644 --- a/source/glest_game/gui/selection.cpp +++ b/source/glest_game/gui/selection.cpp @@ -186,7 +186,7 @@ bool Selection::isMeetable() const{ selectedUnits.front()->getType()->getMeetingPoint(); } -Vec3d Selection::getRefPos() const{ +Vec3f Selection::getRefPos() const{ return getFrontUnit()->getCurrVector(); } diff --git a/source/glest_game/gui/selection.h b/source/glest_game/gui/selection.h index e193595e..293cbb85 100644 --- a/source/glest_game/gui/selection.h +++ b/source/glest_game/gui/selection.h @@ -85,7 +85,7 @@ public: const Unit *getUnit(int i) const {return selectedUnits[i];} Unit *getUnitPtr(int i) {return selectedUnits[i];} const Unit *getFrontUnit() const {return selectedUnits.front();} - Vec3d getRefPos() const; + Vec3f getRefPos() const; bool hasUnit(const Unit* unit) const; void assignGroup(int groupIndex,const UnitContainer *pUnits=NULL); diff --git a/source/glest_game/menu/menu_background.cpp b/source/glest_game/menu/menu_background.cpp index 317afc1b..1d4638a6 100644 --- a/source/glest_game/menu/menu_background.cpp +++ b/source/glest_game/menu/menu_background.cpp @@ -160,7 +160,7 @@ void MenuBackground::createRainParticleSystem() { rps->setSpeed(12.f/GameConstants::updateFps); rps->setEmissionRate(25); rps->setWind(-90.f, 4.f/GameConstants::updateFps); - rps->setPos(Vec3d(0.f, 25.f, 0.f)); + rps->setPos(Vec3f(0.f, 25.f, 0.f)); rps->setColor(Vec4f(1.f, 1.f, 1.f, 0.2f)); rps->setRadius(30.f); diff --git a/source/glest_game/type_instances/object.cpp b/source/glest_game/type_instances/object.cpp index 1d3f050f..0b2b1b85 100644 --- a/source/glest_game/type_instances/object.cpp +++ b/source/glest_game/type_instances/object.cpp @@ -34,7 +34,7 @@ ObjectStateInterface *Object::stateCallback=NULL; // class Object // ===================================================== -Object::Object(ObjectType *objectType, const Vec3d &pos, const Vec2i &mapPos) : BaseColorPickEntity() { +Object::Object(ObjectType *objectType, const Vec3f &pos, const Vec2i &mapPos) : BaseColorPickEntity() { RandomGen random; random.init(static_cast(pos.x * pos.z)); @@ -44,7 +44,7 @@ Object::Object(ObjectType *objectType, const Vec3d &pos, const Vec2i &mapPos) : highlight= 0.f; animated= false; this->mapPos = mapPos; - this->pos= pos + Vec3d(random.randRange(-0.6f, 0.6f), 0.0f, random.randRange(-0.6f, 0.6f)); + this->pos= pos + Vec3f(random.randRange(-0.6f, 0.6f), 0.0f, random.randRange(-0.6f, 0.6f)); rotation= random.randRange(0.f, 360.f); if(objectType!=NULL){ variation = random.randRange(0, objectType->getModelCount()-1); @@ -126,7 +126,7 @@ void Object::end(ParticleSystem *particleSystem) { } } -void Object::setHeight(double height) { +void Object::setHeight(float height) { pos.y = height; for(UnitParticleSystems::iterator it= unitParticleSystems.begin(); it != unitParticleSystems.end(); ++it) { @@ -153,17 +153,17 @@ void Object::update() { // printf("#1 Object updating [%s] Speed [%d] animProgress [%f]\n",this->objectType->getTilesetModelType(variation)->getModel()->getFileName().c_str(),objectType->getTilesetModelType(variation)->getAnimSpeed(),animProgress); if(objectType != NULL && objectType->getTilesetModelType(variation) != NULL) { - double heightFactor = 1.f; - const double speedDivider= 100.f; - double speedDenominator = (speedDivider * GameConstants::updateFps); + float heightFactor = 1.f; + const float speedDivider= 100.f; + float speedDenominator = (speedDivider * GameConstants::updateFps); // smooth TwoFrameanimations - double f=1.0f; + float f=1.0f; if(objectType->getTilesetModelType(variation)->getSmoothTwoFrameAnim()==true){ f=abs(std::sin(animProgress*2*3.16))+0.4f; } - double newAnimProgress = animProgress + f*(((double)objectType->getTilesetModelType(variation)->getAnimSpeed() * heightFactor) / speedDenominator); + float newAnimProgress = animProgress + f*(((float)objectType->getTilesetModelType(variation)->getAnimSpeed() * heightFactor) / speedDenominator); animProgress = newAnimProgress; if(animProgress > 1.f) { @@ -256,7 +256,7 @@ void Object::saveGame(XmlNode *rootNode) { // Vec3f pos; objectNode->addAttribute("pos",pos.getString(), mapTagReplacements); // float rotation; - objectNode->addAttribute("rotation",doubleToStr(rotation,10), mapTagReplacements); + objectNode->addAttribute("rotation",floatToStr(rotation,6), mapTagReplacements); // int variation; objectNode->addAttribute("variation",intToStr(variation), mapTagReplacements); // int lastRenderFrame; @@ -288,7 +288,7 @@ void Object::loadGame(const XmlNode *rootNode,const TechTree *techTree) { resource->loadGame(objectNode,0,techTree); } // Vec3f pos; - pos = Vec3d::strToVec3(objectNode->getAttribute("pos")->getValue()); + pos = Vec3f::strToVec3(objectNode->getAttribute("pos")->getValue()); // float rotation; rotation = objectNode->getAttribute("rotation")->getFloatValue(); // int variation; diff --git a/source/glest_game/type_instances/object.h b/source/glest_game/type_instances/object.h index b5b3e3b7..352fc16e 100644 --- a/source/glest_game/type_instances/object.h +++ b/source/glest_game/type_instances/object.h @@ -57,20 +57,20 @@ private: ObjectType *objectType; vector unitParticleSystems; Resource *resource; - Vec3d pos; - double rotation; + Vec3f pos; + float rotation; int variation; int lastRenderFrame; Vec2i mapPos; bool visible; bool animated; - double animProgress; + float animProgress; float highlight; static ObjectStateInterface *stateCallback; public: - Object(ObjectType *objectType, const Vec3d &pos, const Vec2i &mapPos); + Object(ObjectType *objectType, const Vec3f &pos, const Vec2i &mapPos); virtual ~Object(); void end(); //to kill particles @@ -80,10 +80,10 @@ public: const ObjectType *getType() const {return objectType;} Resource *getResource() const {return resource;} - Vec3d getPos() const {return pos;} + Vec3f getPos() const {return pos;} bool isVisible() const {return visible;} - const Vec3d & getConstPos() const {return pos;} - double getRotation() const {return rotation;} + const Vec3f & getConstPos() const {return pos;} + float getRotation() const {return rotation;} const Model *getModel() const; Model *getModelPtr() const; bool getWalkable() const; @@ -94,7 +94,7 @@ public: void resetHighlight(); void setResource(const ResourceType *resourceType, const Vec2i &pos); - void setHeight(double height); + void setHeight(float height); void setVisible(bool visible); int getLastRenderFrame() const { return lastRenderFrame; } @@ -104,7 +104,7 @@ public: void updateHighlight(); void update(); - double getAnimProgress() const { return animProgress;} + float getAnimProgress() const { return animProgress;} virtual string getUniquePickName() const; void saveGame(XmlNode *rootNode); diff --git a/source/glest_game/type_instances/unit.cpp b/source/glest_game/type_instances/unit.cpp index 97449871..125aeb75 100644 --- a/source/glest_game/type_instances/unit.cpp +++ b/source/glest_game/type_instances/unit.cpp @@ -453,7 +453,7 @@ Unit::Unit(int id, UnitPathInterface *unitpath, const Vec2i &pos, this->map= map; this->targetRef = NULL; this->targetField = fLand; - this->targetVec = Vec3d(0.0); + this->targetVec = Vec3f(0.0); this->targetPos = Vec2i(0); this->lastRenderFrame = 0; this->visible = true; @@ -496,9 +496,9 @@ Unit::Unit(int id, UnitPathInterface *unitpath, const Vec2i &pos, alive= true; if (type->hasSkillClass(scBeBuilt) == false) { - double rot= 0.f; + float rot= 0.f; random.init(id); - rot+= random.randRange(-5, 5,intToStr(__LINE__)); + rot += random.randRange(-5, 5,intToStr(__LINE__)); rotation= rot; lastRotation= rot; targetRotation= rot; @@ -700,7 +700,7 @@ Vec2i Unit::getCenteredPos() const { return pos + Vec2i(type->getSize()/2, type->getSize()/2); } -Vec2d Unit::getFloatCenteredPos() const { +Vec2f Unit::getFloatCenteredPos() const { static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__); MutexSafeWrapper safeMutex(mutexCommands,mutexOwnerId); @@ -710,7 +710,7 @@ Vec2d Unit::getFloatCenteredPos() const { throw megaglest_runtime_error(szBuf); } - return Vec2d(pos.x-0.5f+type->getSize()/2.f, pos.y-0.5f+type->getSize()/2.f); + return Vec2f(pos.x-0.5f+type->getSize()/2.f, pos.y-0.5f+type->getSize()/2.f); } Vec2i Unit::getCellPos() const { @@ -815,11 +815,11 @@ void Unit::calculateXZRotation(){ } } -double Unit::getRotationZ() const{ +float Unit::getRotationZ() const{ return rotationZ; } -double Unit::getRotationX() const{ +float Unit::getRotationX() const{ return rotationX; } @@ -1267,13 +1267,13 @@ void Unit::setTargetPos(const Vec2i &targetPos) { Vec2i relPos= targetPos - pos; //map->clampPos(relPos); - Vec2d relPosf= Vec2d((double)relPos.x, (double)relPos.y); + Vec2f relPosf= Vec2f((float)relPos.x, (float)relPos.y); #ifdef USE_STREFLOP targetRotation= radToDeg(streflop::atan2(static_cast(relPosf.x), static_cast(relPosf.y))); #else targetRotation= radToDeg(atan2(relPosf.x, relPosf.y)); #endif - targetRotation = truncateDecimal(targetRotation,10); + targetRotation = truncateDecimal(targetRotation,6); targetRef= NULL; @@ -1409,60 +1409,48 @@ bool Unit::checkModelStateInfoForNewHpValue() { return result; } -Vec3d Unit::getCurrVector() const{ +Vec3f Unit::getCurrVector() const{ if(type == NULL) { char szBuf[8096]=""; snprintf(szBuf,8096,"In [%s::%s Line: %d] ERROR: type == NULL, Unit = [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,this->toString().c_str()); throw megaglest_runtime_error(szBuf); } - Vec3d result = getCurrVectorFlat() + Vec3d(0.f, type->getHeight() /2.f, 0.f); - result.x = truncateDecimal(result.x,10); - result.y = truncateDecimal(result.y,10); - result.z = truncateDecimal(result.z,10); - + Vec3f result = getCurrVectorFlat() + Vec3f(0.f, type->getHeight() / 2.f, 0.f); return result; } -Vec3d Unit::getCurrVectorFlat() const{ +Vec3f Unit::getCurrVectorFlat() const{ return getVectorFlat(lastPos, pos); } double Unit::getProgressAsFloat() const { double result = (static_cast(progress) / static_cast(PROGRESS_SPEED_MULTIPLIER)); - result = truncateDecimal(result,10); + result = truncateDecimal(result,6); return result; } -Vec3d Unit::getVectorFlat(const Vec2i &lastPosValue, const Vec2i &curPosValue) const { - Vec3d v; +Vec3f Unit::getVectorFlat(const Vec2i &lastPosValue, const Vec2i &curPosValue) const { + Vec3f v; - double y1= computeHeight(lastPosValue); - double y2= computeHeight(curPosValue); + float y1= computeHeight(lastPosValue); + float y2= computeHeight(curPosValue); if(currSkill->getClass() == scMove) { - double progressAsDouble = getProgressAsFloat(); + float progressAsFloat = getProgressAsFloat(); - v.x= lastPosValue.x + progressAsDouble * (curPosValue.x - lastPosValue.x); - v.z= lastPosValue.y + progressAsDouble * (curPosValue.y - lastPosValue.y); - v.y= y1 + progressAsDouble * (y2-y1); + v.x = lastPosValue.x + progressAsFloat * (curPosValue.x - lastPosValue.x); + v.z = lastPosValue.y + progressAsFloat * (curPosValue.y - lastPosValue.y); + v.y = y1 + progressAsFloat * (y2-y1); } else { - v.x= static_cast(curPosValue.x); - v.z= static_cast(curPosValue.y); - v.y= y2; + v.x = static_cast(curPosValue.x); + v.z = static_cast(curPosValue.y); + v.y = y2; } - v.x = truncateDecimal(v.x,10); - v.y = truncateDecimal(v.y,10); - v.z = truncateDecimal(v.z,10); - v.x += type->getSize() / 2.f - 0.5f; v.z += type->getSize() / 2.f - 0.5f; - v.x = truncateDecimal(v.x,10); - v.y = truncateDecimal(v.y,10); - v.z = truncateDecimal(v.z,10); - return v; } @@ -2402,8 +2390,8 @@ bool Unit::update() { rotation= lastRotation + (targetRotation - lastRotation) * getProgressAsFloat() * rotFactor; else { - double rotationTerm = targetRotation > lastRotation ? -360.f: +360.f; - rotation = lastRotation + (targetRotation - lastRotation + rotationTerm) * + float rotationTerm = targetRotation > lastRotation ? -360.f: +360.f; + rotation = lastRotation + (targetRotation - lastRotation + rotationTerm) * getProgressAsFloat() * rotFactor; } } @@ -2508,7 +2496,7 @@ void Unit::updateTimedParticles() { for(int i = queuedUnitParticleSystemTypes.size() - 1; i >= 0; i--) { UnitParticleSystemType *pst = queuedUnitParticleSystemTypes[i]; if(pst != NULL) { - if(truncateDecimal(pst->getStartTime(),10) <= truncateDecimal(getAnimProgressAsFloat(),10)) { + if(truncateDecimal(pst->getStartTime(),6) <= truncateDecimal(getAnimProgressAsFloat(),6)) { UnitParticleSystem *ups = new UnitParticleSystem(200); ups->setParticleOwner(this); @@ -2535,13 +2523,13 @@ void Unit::updateTimedParticles() { UnitParticleSystem *ps = unitParticleSystems[i]; if(ps != NULL) { if(Renderer::getInstance().validateParticleSystemStillExists(ps,rsGame) == true) { - double pst = ps->getStartTime(); - double pet = ps->getEndTime(); - double particleStartTime = truncateDecimal(pst,10); - double particleEndTime = truncateDecimal(pet,10); + float pst = ps->getStartTime(); + float pet = ps->getEndTime(); + float particleStartTime = truncateDecimal(pst,6); + float particleEndTime = truncateDecimal(pet,6); if(particleStartTime != 0.0 || particleEndTime != 1.0) { - double animProgressTime = truncateDecimal(getAnimProgressAsFloat(),10); + float animProgressTime = truncateDecimal(getAnimProgressAsFloat(),6); if(animProgressTime >= 0.99 || animProgressTime >= particleEndTime) { ps->fade(); @@ -3343,7 +3331,7 @@ bool Unit::morph(const MorphCommandType *mct) { // ==================== PRIVATE ==================== -double Unit::computeHeight(const Vec2i &pos) const { +float Unit::computeHeight(const Vec2i &pos) const { //printf("CRASHING FOR UNIT: %d alive = %d\n",this->getId(),this->isAlive()); //printf("[%s]\n",this->getType()->getName().c_str()); if(map->isInside(pos) == false || map->isInsideSurface(map->toSurfCoords(pos)) == false) { @@ -3352,26 +3340,25 @@ double Unit::computeHeight(const Vec2i &pos) const { throw megaglest_runtime_error("#7 Invalid path position = " + pos.getString()); } - double height= map->getCell(pos)->getHeight(); - height = truncateDecimal(height,10); + float height= map->getCell(pos)->getHeight(); if(currField == fAir) { - const double airHeight=game->getWorld()->getTileset()->getAirHeight(); + const float airHeight=game->getWorld()->getTileset()->getAirHeight(); height += airHeight; - height = truncateDecimal(height,10); + height = truncateDecimal(height,6); Unit *unit = map->getCell(pos)->getUnit(fLand); if(unit != NULL && unit->getType()->getHeight() > airHeight) { - height += (std::min((double)unit->getType()->getHeight(),Tileset::standardAirHeight * 3) - airHeight); - height = truncateDecimal(height,10); + height += (std::min((float)unit->getType()->getHeight(),Tileset::standardAirHeight * 3) - airHeight); + height = truncateDecimal(height,6); } else { SurfaceCell *sc = map->getSurfaceCell(map->toSurfCoords(pos)); if(sc != NULL && sc->getObject() != NULL && sc->getObject()->getType() != NULL) { if(sc->getObject()->getType()->getHeight() > airHeight) { - height += (std::min((double)sc->getObject()->getType()->getHeight(),Tileset::standardAirHeight * 3) - airHeight); - height = truncateDecimal(height,10); + height += (std::min((float)sc->getObject()->getType()->getHeight(),Tileset::standardAirHeight * 3) - airHeight); + height = truncateDecimal(height,6); } } } @@ -3387,20 +3374,13 @@ void Unit::updateTarget(){ //update target pos targetPos= target->getCellPos(); Vec2i relPos= targetPos - pos; - Vec2d relPosf= Vec2d((double)relPos.x, (double)relPos.y); + Vec2f relPosf= Vec2f((float)relPos.x, (float)relPos.y); #ifdef USE_STREFLOP targetRotation= radToDeg(streflop::atan2(static_cast(relPosf.x), static_cast(relPosf.y))); #else targetRotation= radToDeg(atan2(relPosf.x, relPosf.y)); #endif - targetRotation = truncateDecimal(targetRotation,10); - //update target vec targetVec= target->getCurrVector(); - - //if(getFrameCount() % 40 == 0) { - //logSynchData(string(__FILE__) + string("::") + string(__FUNCTION__) + string(" Line: ") + intToStr(__LINE__)); - //logSynchData(); - //} } } @@ -3835,8 +3815,8 @@ void Unit::startDamageParticles() { ups->setColor(Vec4f(0.115f, 0.115f, 0.115f, 0.22f)); ups->setPos(getCurrVector()); ups->setBlendMode(ups->strToBlendMode("black")); - ups->setOffset(Vec3d(0,2,0)); - ups->setDirection(Vec3d(0,1,-0.2f)); + ups->setOffset(Vec3f(0,2,0)); + ups->setDirection(Vec3f(0,1,-0.2f)); ups->setRadius(type->getSize()/3.f); ups->setShape(Shared::Graphics::UnitParticleSystem::sLinear); ups->setTexture(CoreData::getInstance().getFireTexture()); @@ -3857,7 +3837,7 @@ void Unit::startDamageParticles() { checkCustomizedParticleTriggers(false); } -void Unit::setTargetVec(const Vec3d &targetVec) { +void Unit::setTargetVec(const Vec3f &targetVec) { this->targetVec= targetVec; logSynchData(extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__); } @@ -4173,7 +4153,7 @@ std::string Unit::toString(bool crcMode) const { if(crcMode == false) { result += " lastAnimProgress = " + intToStr(this->lastAnimProgress); result += " animProgress = " + intToStr(this->animProgress); - result += " highlight = " + doubleToStr(this->highlight,10); + result += " highlight = " + floatToStr(this->highlight,6); } result += " progress2 = " + intToStr(this->progress2); result += " kills = " + intToStr(this->kills); @@ -4202,9 +4182,9 @@ std::string Unit::toString(bool crcMode) const { result += "\n"; if(crcMode == false) { - result += " lastRotation = " + doubleToStr(this->lastRotation,10); - result += " targetRotation = " + doubleToStr(this->targetRotation,10); - result += " rotation = " + doubleToStr(this->rotation,10); + result += " lastRotation = " + floatToStr(this->lastRotation,6); + result += " targetRotation = " + floatToStr(this->targetRotation,6); + result += " rotation = " + floatToStr(this->rotation,6); } if(loadType != NULL) { @@ -4312,7 +4292,7 @@ void Unit::saveGame(XmlNode *rootNode) { // float animProgress; //between 0 and 1 unitNode->addAttribute("animProgress",intToStr(animProgress), mapTagReplacements); // float highlight; - unitNode->addAttribute("highlight",doubleToStr(highlight,10), mapTagReplacements); + unitNode->addAttribute("highlight",floatToStr(highlight,6), mapTagReplacements); // int progress2; unitNode->addAttribute("progress2",intToStr(progress2), mapTagReplacements); // int kills; @@ -4342,19 +4322,19 @@ void Unit::saveGame(XmlNode *rootNode) { unitNode->addAttribute("meetingPos",meetingPos.getString(), mapTagReplacements); // // float lastRotation; //in degrees - unitNode->addAttribute("lastRotation",doubleToStr(lastRotation,10), mapTagReplacements); + unitNode->addAttribute("lastRotation",floatToStr(lastRotation,6), mapTagReplacements); // float targetRotation; - unitNode->addAttribute("targetRotation",doubleToStr(targetRotation,10), mapTagReplacements); + unitNode->addAttribute("targetRotation",floatToStr(targetRotation,6), mapTagReplacements); // float rotation; - unitNode->addAttribute("rotation",doubleToStr(rotation,10), mapTagReplacements); + unitNode->addAttribute("rotation",floatToStr(rotation,6), mapTagReplacements); // float targetRotationZ; - unitNode->addAttribute("targetRotationZ",doubleToStr(targetRotationZ,10), mapTagReplacements); + unitNode->addAttribute("targetRotationZ",floatToStr(targetRotationZ,6), mapTagReplacements); // float targetRotationX; - unitNode->addAttribute("targetRotationX",doubleToStr(targetRotationX,10), mapTagReplacements); + unitNode->addAttribute("targetRotationX",floatToStr(targetRotationX,6), mapTagReplacements); // float rotationZ; - unitNode->addAttribute("rotationZ",doubleToStr(rotationZ,10), mapTagReplacements); + unitNode->addAttribute("rotationZ",floatToStr(rotationZ,6), mapTagReplacements); // float rotationX; - unitNode->addAttribute("rotationX",doubleToStr(rotationX,10), mapTagReplacements); + unitNode->addAttribute("rotationX",floatToStr(rotationX,6), mapTagReplacements); // const UnitType *type; unitNode->addAttribute("type",type->getName(false), mapTagReplacements); @@ -4699,7 +4679,7 @@ Unit * Unit::loadGame(const XmlNode *rootNode, GameSettings *settings, Faction * // Vec2i targetPos; //absolute target pos result->targetPos = Vec2i::strToVec2(unitNode->getAttribute("targetPos")->getValue()); // Vec3f targetVec; - result->targetVec = Vec3d::strToVec3(unitNode->getAttribute("targetVec")->getValue()); + result->targetVec = Vec3f::strToVec3(unitNode->getAttribute("targetVec")->getValue()); // Vec2i meetingPos; result->meetingPos = Vec2i::strToVec2(unitNode->getAttribute("meetingPos")->getValue()); // diff --git a/source/glest_game/type_instances/unit.h b/source/glest_game/type_instances/unit.h index 53b59a18..d0a57914 100644 --- a/source/glest_game/type_instances/unit.h +++ b/source/glest_game/type_instances/unit.h @@ -353,7 +353,7 @@ private: int64 progress; //between 0 and 1 int64 lastAnimProgress; //between 0 and 1 int64 animProgress; //between 0 and 1 - double highlight; + float highlight; int32 progress2; int32 kills; int32 enemyKills; @@ -368,16 +368,16 @@ private: Vec2i pos; Vec2i lastPos; Vec2i targetPos; //absolute target pos - Vec3d targetVec; + Vec3f targetVec; Vec2i meetingPos; - double lastRotation; //in degrees - double targetRotation; - double rotation; - double targetRotationZ; - double targetRotationX; - double rotationZ; - double rotationX; + float lastRotation; //in degrees + float targetRotation; + float rotation; + float targetRotationZ; + float targetRotationX; + float rotationZ; + float rotationX; const UnitType *preMorph_type; const UnitType *type; @@ -520,7 +520,7 @@ public: inline double getLastAnimProgressAsFloat() const {return static_cast(lastAnimProgress) / ANIMATION_SPEED_MULTIPLIER;} inline double getAnimProgressAsFloat() const {return static_cast(animProgress) / ANIMATION_SPEED_MULTIPLIER;} - inline double getHightlight() const {return highlight;} + inline float getHightlight() const {return highlight;} inline int getProgress2() const {return progress2;} inline int getFactionIndex() const { return faction->getIndex(); @@ -536,7 +536,7 @@ public: double getEpRatio() const; inline bool getToBeUndertaken() const {return toBeUndertaken;} inline Vec2i getTargetPos() const {return targetPos;} - inline Vec3d getTargetVec() const {return targetVec;} + inline Vec3f getTargetVec() const {return targetVec;} inline Field getTargetField() const {return targetField;} inline Vec2i getMeetingPos() const {return meetingPos;} inline Faction *getFaction() const {return faction;} @@ -546,9 +546,9 @@ public: inline const SkillType *getCurrSkill() const {return currSkill;} inline const TotalUpgrade *getTotalUpgrade() const {return &totalUpgrade;} - inline double getRotation() const {return rotation;} - double getRotationX() const; - double getRotationZ() const; + inline float getRotation() const {return rotation;} + float getRotationX() const; + float getRotationZ() const; ParticleSystem *getFire() const; inline int getKills() const {return kills;} inline int getEnemyKills() const {return enemyKills;} @@ -574,7 +574,7 @@ public: Vec2i getPosWithCellMapSet() const; inline Vec2i getLastPos() const {return lastPos;} Vec2i getCenteredPos() const; - Vec2d getFloatCenteredPos() const; + Vec2f getFloatCenteredPos() const; Vec2i getCellPos() const; //is @@ -613,7 +613,7 @@ public: void refreshPos(); void setTargetPos(const Vec2i &targetPos); void setTarget(const Unit *unit); - void setTargetVec(const Vec3d &targetVec); + void setTargetVec(const Vec3f &targetVec); void setMeetingPos(const Vec2i &meetingPos); void setVisible(const bool visible); inline bool getVisible() const { return visible; } @@ -621,9 +621,9 @@ public: //render related const Model *getCurrentModel(); Model *getCurrentModelPtr(); - Vec3d getCurrVector() const; - Vec3d getCurrVectorFlat() const; - Vec3d getVectorFlat(const Vec2i &lastPosValue, const Vec2i &curPosValue) const; + Vec3f getCurrVector() const; + Vec3f getCurrVectorFlat() const; + Vec3f getVectorFlat(const Vec2i &lastPosValue, const Vec2i &curPosValue) const; //command related bool anyCommand(bool validateCommandtype=false) const; @@ -794,7 +794,7 @@ private: void addNetworkCRCDecHp(string info) { } string getNetworkCRCDecHpList() const; - double computeHeight(const Vec2i &pos) const; + float computeHeight(const Vec2i &pos) const; void calculateXZRotation(); void updateTarget(); void clearCommands(); diff --git a/source/glest_game/types/skill_type.cpp b/source/glest_game/types/skill_type.cpp index 62abe547..040697e6 100644 --- a/source/glest_game/types/skill_type.cpp +++ b/source/glest_game/types/skill_type.cpp @@ -665,7 +665,7 @@ void SkillType::saveGame(XmlNode *rootNode) { // // SoundContainer sounds; // float soundStartTime; - skillTypeNode->addAttribute("soundStartTime",doubleToStr(soundStartTime,10), mapTagReplacements); + skillTypeNode->addAttribute("soundStartTime",floatToStr(soundStartTime,6), mapTagReplacements); // RandomGen random; skillTypeNode->addAttribute("random",intToStr(random.getLastNumber()), mapTagReplacements); // AttackBoost attackBoost; @@ -897,7 +897,7 @@ void AttackSkillType::saveGame(XmlNode *rootNode) { attackFieldsNode->addAttribute("value",intToStr(attackFields[i]), mapTagReplacements); } // float attackStartTime; - attackSkillTypeNode->addAttribute("attackStartTime",doubleToStr(attackStartTime,10), mapTagReplacements); + attackSkillTypeNode->addAttribute("attackStartTime",floatToStr(attackStartTime,6), mapTagReplacements); // string spawnUnit; attackSkillTypeNode->addAttribute("spawnUnit",spawnUnit, mapTagReplacements); // int spawnUnitcount; @@ -1220,7 +1220,7 @@ void FogOfWarSkillType::saveGame(XmlNode *rootNode) { fogSkillTypeNode->addAttribute("enable-fog",intToStr(fowEnable), mapTagReplacements); fogSkillTypeNode->addAttribute("apply-team",intToStr(applyToTeam), mapTagReplacements); - fogSkillTypeNode->addAttribute("duration",doubleToStr(durationTime,10), mapTagReplacements); + fogSkillTypeNode->addAttribute("duration",floatToStr(durationTime,6), mapTagReplacements); } // ===================================================== diff --git a/source/glest_game/types/skill_type.h b/source/glest_game/types/skill_type.h index bdfe4d64..510864f1 100644 --- a/source/glest_game/types/skill_type.h +++ b/source/glest_game/types/skill_type.h @@ -137,7 +137,7 @@ protected: vector animationAttributes; SoundContainer sounds; - double soundStartTime; + float soundStartTime; RandomGen random; AttackBoost attackBoost; @@ -177,7 +177,7 @@ public: int getAnimSpeed() const {return animSpeed;} Model *getAnimation(double animProgress=0, const Unit *unit=NULL, int *lastAnimationIndex=NULL, int *animationRandomCycleCount=NULL) const; StaticSound *getSound() const {return sounds.getRandSound();} - double getSoundStartTime() const {return soundStartTime;} + float getSoundStartTime() const {return soundStartTime;} bool isAttackBoostEnabled() const { return attackBoost.enabled; } const AttackBoost * getAttackBoost() const { return &attackBoost; } @@ -226,7 +226,7 @@ private: int attackRange; const AttackType *attackType; bool attackFields[fieldCount]; - double attackStartTime; + float attackStartTime; string spawnUnit; int spawnUnitcount; @@ -253,7 +253,7 @@ public: inline int getAttackRange() const {return attackRange;} inline const AttackType *getAttackType() const {return attackType;} inline bool getAttackField(Field field) const {return attackFields[field];} - inline double getAttackStartTime() const {return attackStartTime;} + inline float getAttackStartTime() const {return attackStartTime;} inline string getSpawnUnit() const {return spawnUnit;} inline int getSpawnUnitCount() const {return spawnUnitcount;} @@ -419,13 +419,13 @@ class FogOfWarSkillType: public SkillType { private: bool fowEnable; bool applyToTeam; - double durationTime; + float durationTime; public: FogOfWarSkillType(); bool getFowEnable() const {return fowEnable;} bool getApplyToTeam() const {return applyToTeam;} - double getDurationTime() const {return durationTime;} + float getDurationTime() const {return durationTime;} virtual void load(const XmlNode *sn, const XmlNode *attackBoostsNode, const string &dir, const TechTree *tt, const FactionType *ft, std::map > > &loadedFileList, diff --git a/source/glest_game/types/unit_type.cpp b/source/glest_game/types/unit_type.cpp index f6203f4d..f2c00324 100644 --- a/source/glest_game/types/unit_type.cpp +++ b/source/glest_game/types/unit_type.cpp @@ -1080,7 +1080,7 @@ std::string UnitType::toString() const { result += " sight = " + intToStr(sight); result += " size = " + intToStr(size); result += " height = " + intToStr(height); - result += " rotatedBuildPos = " + doubleToStr(rotatedBuildPos,10); + result += " rotatedBuildPos = " + floatToStr(rotatedBuildPos,6); result += " rotationAllowed = " + intToStr(rotationAllowed); if(cellMap != NULL) { diff --git a/source/glest_game/types/unit_type.h b/source/glest_game/types/unit_type.h index e29cd516..cabc5f7c 100644 --- a/source/glest_game/types/unit_type.h +++ b/source/glest_game/types/unit_type.h @@ -123,7 +123,7 @@ private: int sight; int size; //size in cells int height; - double rotatedBuildPos; + float rotatedBuildPos; bool rotationAllowed; //cellmap @@ -249,8 +249,8 @@ public: const CommandType* findCommandTypeById(int id) const; string getCommandTypeListDesc() const; - inline double getRotatedBuildPos() { return rotatedBuildPos; } - inline void setRotatedBuildPos(double value) { rotatedBuildPos = value; } + inline float getRotatedBuildPos() { return rotatedBuildPos; } + inline void setRotatedBuildPos(float value) { rotatedBuildPos = value; } //other virtual string getReqDesc(bool translatedValue) const; diff --git a/source/glest_game/world/map.cpp b/source/glest_game/world/map.cpp index 1a0cf9fa..a3e0b8d3 100644 --- a/source/glest_game/world/map.cpp +++ b/source/glest_game/world/map.cpp @@ -93,7 +93,7 @@ void Cell::saveGame(XmlNode *rootNode, int index) const { } // float height; - cellNode->addAttribute("height",doubleToStr(getHeight(),10), mapTagReplacements); + cellNode->addAttribute("height",floatToStr(getHeight(),6), mapTagReplacements); } } @@ -374,10 +374,10 @@ Checksum Map::load(const string &path, TechTree *techTree, Tileset *tileset) { heightFactor= header.heightFactor; if(heightFactor>100){ heightFactor=heightFactor/100; - heightFactor = truncateDecimal(heightFactor,10); + heightFactor = truncateDecimal(heightFactor,6); } - waterLevel= static_cast((header.waterLevel-0.01f)/heightFactor); - waterLevel = truncateDecimal(waterLevel,10); + waterLevel= static_cast((header.waterLevel-0.01f)/heightFactor); + waterLevel = truncateDecimal(waterLevel,6); title= header.title; maxPlayers= header.maxFactions; @@ -395,8 +395,8 @@ Checksum Map::load(const string &path, TechTree *techTree, Tileset *tileset) { else if(header.version==2){ //desc = header.version2.short_desc; if(header.version2.cliffLevel > 0 && header.version2.cliffLevel < 5000){ - cliffLevel=static_cast((header.version2.cliffLevel-0.01f)/(heightFactor),10); - cliffLevel = truncateDecimal(cliffLevel,10); + cliffLevel=static_cast((header.version2.cliffLevel-0.01f)/(heightFactor),6); + cliffLevel = truncateDecimal(cliffLevel,6); } if(header.version2.cameraHeight > 0 && header.version2.cameraHeight < 5000) { cameraHeight = header.version2.cameraHeight; @@ -481,7 +481,7 @@ Checksum Map::load(const string &path, TechTree *techTree, Tileset *tileset) { sc->setObject(NULL); } else if(objNumber <= Tileset::objCount) { - Object *o= new Object(tileset->getObjectType(objNumber-1), Vec3d(sc->getVertex()),Vec2i(i, j)); + Object *o= new Object(tileset->getObjectType(objNumber-1), sc->getVertex(),Vec2i(i, j)); sc->setObject(o); for(int k = 0; k < techTree->getResourceTypeCount(); ++k) { const ResourceType *rt= techTree->getResourceType(k); @@ -492,7 +492,7 @@ Checksum Map::load(const string &path, TechTree *techTree, Tileset *tileset) { } else{ const ResourceType *rt= techTree->getTechResourceType(objNumber - Tileset::objCount) ; - Object *o= new Object(NULL, Vec3d(sc->getVertex()),Vec2i(i, j)); + Object *o= new Object(NULL, sc->getVertex(),Vec2i(i, j)); o->setResource(rt, Vec2i(i, j)); sc->setObject(o); } @@ -1532,7 +1532,7 @@ void Map::prepareTerrain(const Unit *unit) { // ==================== compute ==================== void Map::flatternTerrain(const Unit *unit){ - double refHeight= getSurfaceCell(toSurfCoords(unit->getCenteredPos()))->getHeight(); + float refHeight= getSurfaceCell(toSurfCoords(unit->getCenteredPos()))->getHeight(); for(int i=-1; i<=unit->getType()->getSize(); ++i){ for(int j=-1; j<=unit->getType()->getSize(); ++j){ Vec2i pos= unit->getPosNotThreadSafe()+Vec2i(i, j); @@ -1641,7 +1641,7 @@ void Map::smoothSurface(Tileset *tileset) { } if (formerObject == NULL) { Object *o = new Object(tileset->getObjectType(9), - Vec3d(getSurfaceCell(i, j)->getVertex()), + getSurfaceCell(i, j)->getVertex(), Vec2i(i,j)); getSurfaceCell(i, j)->setObject(o); } @@ -1733,11 +1733,11 @@ void Map::saveGame(XmlNode *rootNode) const { // string title; mapNode->addAttribute("title",title, mapTagReplacements); // float waterLevel; - mapNode->addAttribute("waterLevel",doubleToStr(waterLevel,10), mapTagReplacements); + mapNode->addAttribute("waterLevel",floatToStr(waterLevel,6), mapTagReplacements); // float heightFactor; - mapNode->addAttribute("heightFactor",doubleToStr(heightFactor,10), mapTagReplacements); + mapNode->addAttribute("heightFactor",floatToStr(heightFactor,6), mapTagReplacements); // float cliffLevel; - mapNode->addAttribute("cliffLevel",doubleToStr(cliffLevel,10), mapTagReplacements); + mapNode->addAttribute("cliffLevel",floatToStr(cliffLevel,6), mapTagReplacements); // int cameraHeight; mapNode->addAttribute("cameraHeight",intToStr(cameraHeight), mapTagReplacements); // int w; @@ -1817,7 +1817,7 @@ void Map::saveGame(XmlNode *rootNode) const { // Checksum checksumValue; // mapNode->addAttribute("checksumValue",intToStr(checksumValue.getSum()), mapTagReplacements); // float maxMapHeight; - mapNode->addAttribute("maxMapHeight",doubleToStr(maxMapHeight,10), mapTagReplacements); + mapNode->addAttribute("maxMapHeight",floatToStr(maxMapHeight,6), mapTagReplacements); // string mapFile; mapNode->addAttribute("mapFile",mapFile, mapTagReplacements); } diff --git a/source/glest_game/world/map.h b/source/glest_game/world/map.h index d2aa4dd4..d473460c 100644 --- a/source/glest_game/world/map.h +++ b/source/glest_game/world/map.h @@ -58,7 +58,7 @@ class Cell { private: Unit *units[fieldCount]; //units on this cell Unit *unitsWithEmptyCellMap[fieldCount]; //units with an empty cellmap on this cell - double height; + float height; private: Cell(Cell&); @@ -70,11 +70,11 @@ public: //get inline Unit *getUnit(int field) const { if(field >= fieldCount) { throw megaglest_runtime_error("Invalid field value" + intToStr(field));} return units[field];} inline Unit *getUnitWithEmptyCellMap(int field) const { if(field >= fieldCount) { throw megaglest_runtime_error("Invalid field value" + intToStr(field));} return unitsWithEmptyCellMap[field];} - inline double getHeight() const {return truncateDecimal(height,10);} + inline float getHeight() const {return truncateDecimal(height,6);} inline void setUnit(int field, Unit *unit) { if(field >= fieldCount) { throw megaglest_runtime_error("Invalid field value" + intToStr(field));} units[field]= unit;} inline void setUnitWithEmptyCellMap(int field, Unit *unit) { if(field >= fieldCount) { throw megaglest_runtime_error("Invalid field value" + intToStr(field));} unitsWithEmptyCellMap[field]= unit;} - inline void setHeight(double height) {this->height = truncateDecimal(height,10);} + inline void setHeight(float height) {this->height = truncateDecimal(height,6);} inline bool isFree(Field field) const { Unit *unit = getUnit(field); @@ -213,9 +213,9 @@ public: private: string title; - double waterLevel; - double heightFactor; - double cliffLevel; + float waterLevel; + float heightFactor; + float cliffLevel; int cameraHeight; int w; int h; @@ -228,7 +228,7 @@ private: SurfaceCell *surfaceCells; Vec2i *startLocations; Checksum checksumValue; - double maxMapHeight; + float maxMapHeight; string mapFile; private: @@ -296,11 +296,11 @@ public: inline int getSurfaceW() const {return surfaceW;} inline int getSurfaceH() const {return surfaceH;} inline int getMaxPlayers() const {return maxPlayers;} - inline double getHeightFactor() const {return truncateDecimal(heightFactor,10);} - inline double getWaterLevel() const {return truncateDecimal(waterLevel,10);} - inline double getCliffLevel() const {return truncateDecimal(cliffLevel,10);} + inline float getHeightFactor() const {return truncateDecimal(heightFactor,6);} + inline float getWaterLevel() const {return truncateDecimal(waterLevel,6);} + inline float getCliffLevel() const {return truncateDecimal(cliffLevel,6);} inline int getCameraHeight() const {return cameraHeight;} - inline double getMaxMapHeight() const {return truncateDecimal(maxMapHeight,10);} + inline float getMaxMapHeight() const {return truncateDecimal(maxMapHeight,6);} Vec2i getStartLocation(int locationIndex) const; inline bool getSubmerged(const SurfaceCell *sc) const {return sc->getHeight()getHeight()getChild("weather"); - double sunnyProb= weatherNode->getAttribute("sun")->getFloatValue(0.f, 1.f); - double rainyProb= weatherNode->getAttribute("rain")->getFloatValue(0.f, 1.f) + sunnyProb; + float sunnyProb= weatherNode->getAttribute("sun")->getFloatValue(0.f, 1.f); + float rainyProb= weatherNode->getAttribute("rain")->getFloatValue(0.f, 1.f) + sunnyProb; if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); #ifdef USE_STREFLOP - double rnd= streflop::fabs(static_cast(random.randRange(-1.f, 1.f))); + float rnd= streflop::fabs(static_cast(random.randRange(-1.f, 1.f))); #else - double rnd= fabs(random.randRange(-1.f, 1.f)); + float rnd= fabs(random.randRange(-1.f, 1.f)); #endif if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); @@ -505,7 +505,7 @@ void Tileset::addSurfTex(int leftUp, int rightUp, int leftDown, int rightDown, V //center textures if(leftUp == rightUp && leftUp == leftDown && leftUp == rightDown) { //texture variation according to probability - double r= random.randRange(0.f, 1.f); + float r= random.randRange(0.f, 1.f); const Pixmap2D *pixmap = NULL; if(surfProbs[leftUp][0] < 0) { @@ -514,7 +514,7 @@ void Tileset::addSurfTex(int leftUp, int rightUp, int leftDown, int rightDown, V pixmap = getSurfPixmap(leftUp, (mapY % parts) * parts + (mapX % parts)); } else { - double max= 0.f; + float max= 0.f; int var= 0; for(int i=0; i < surfProbs[leftUp].size(); ++i) { max += surfProbs[leftUp][i]; diff --git a/source/glest_game/world/tileset.h b/source/glest_game/world/tileset.h index 05cac1ff..c427171c 100644 --- a/source/glest_game/world/tileset.h +++ b/source/glest_game/world/tileset.h @@ -120,8 +120,8 @@ public: static const int surfCount= 6; static const int objCount= 10; static const int transitionVars= 2; //number or different transition textures - static const double standardAirHeight; - static const double standardShadowIntensity; + static const float standardAirHeight; + static const float standardShadowIntensity; public: typedef vector SurfProbs; @@ -142,13 +142,13 @@ private: bool waterEffects; bool fog; int fogMode; - double fogDensity; + float fogDensity; Vec3f fogColor; Vec3f sunLightColor; Vec3f moonLightColor; - double shadowIntensity; + float shadowIntensity; Weather weather; - double airHeight; + float airHeight; AmbientSounds ambientSounds; Checksum checksumValue; @@ -178,7 +178,7 @@ public: Checksum * getChecksumValue() { return &checksumValue; } //get - double getAirHeight()const {return airHeight;} + float getAirHeight()const {return airHeight;} const SurfaceAtlas *getSurfaceAtlas() const {return &surfaceAtlas;} ObjectType *getObjectType(int i) {return &objectTypes[i];} float getSurfProb(int surf, int var) const {return surfProbs[surf][var];} @@ -186,11 +186,11 @@ public: bool getWaterEffects() const {return waterEffects;} bool getFog() const {return fog;} int getFogMode() const {return fogMode;} - double getFogDensity() const {return fogDensity;} + float getFogDensity() const {return fogDensity;} const Vec3f &getFogColor() const {return fogColor;} const Vec3f &getSunLightColor() const {return sunLightColor;} const Vec3f &getMoonLightColor() const {return moonLightColor;} - double getShadowIntense()const {return shadowIntensity;} + float getShadowIntense()const {return shadowIntensity;} Weather getWeather() const {return weather;} void setWeather(Weather value) { weather = value; } diff --git a/source/glest_game/world/time_flow.cpp b/source/glest_game/world/time_flow.cpp index 1060b4b3..38595148 100644 --- a/source/glest_game/world/time_flow.cpp +++ b/source/glest_game/world/time_flow.cpp @@ -160,12 +160,12 @@ void TimeFlow::saveGame(XmlNode *rootNode) { // bool firstTime; // Tileset *tileset; // float time; - timeflowNode->addAttribute("time",floatToStr(time,10), mapTagReplacements); + timeflowNode->addAttribute("time",floatToStr(time,6), mapTagReplacements); // float lastTime; - timeflowNode->addAttribute("lastTime",floatToStr(lastTime,10), mapTagReplacements); + timeflowNode->addAttribute("lastTime",floatToStr(lastTime,6), mapTagReplacements); // float timeInc; //printf("#2 timeInc = %f\n",timeInc); - timeflowNode->addAttribute("timeInc",floatToStr(timeInc,10), mapTagReplacements); + timeflowNode->addAttribute("timeInc",floatToStr(timeInc,6), mapTagReplacements); //printf("#3 timeInc = %f\n",timeInc); } diff --git a/source/glest_game/world/unit_updater.cpp b/source/glest_game/world/unit_updater.cpp index 4f5d2cf8..419a9dcc 100644 --- a/source/glest_game/world/unit_updater.cpp +++ b/source/glest_game/world/unit_updater.cpp @@ -119,7 +119,7 @@ bool UnitUpdater::updateUnit(Unit *unit) { //play skill sound const SkillType *currSkill= unit->getCurrSkill(); if(currSkill->getSound() != NULL) { - double soundStartTime= currSkill->getSoundStartTime(); + float soundStartTime= currSkill->getSoundStartTime(); if(soundStartTime >= unit->getLastAnimProgressAsFloat() && soundStartTime < unit->getAnimProgressAsFloat()) { if(map->getSurfaceCell(Map::toSurfCoords(unit->getPos()))->isVisible(world->getThisTeamIndex()) || (game->getWorld()->showWorldForPlayer(game->getWorld()->getThisTeamIndex()) == true)) { @@ -138,9 +138,9 @@ bool UnitUpdater::updateUnit(Unit *unit) { if(unit->getCurrSkill()->getClass() == scAttack) { const AttackSkillType *ast= static_cast(unit->getCurrSkill()); - double attackStartTime = truncateDecimal(ast->getAttackStartTime(),10); - double lastAnimProgress = truncateDecimal(unit->getLastAnimProgressAsFloat(),10); - double animProgress = truncateDecimal(unit->getAnimProgressAsFloat(),10); + float attackStartTime = truncateDecimal(ast->getAttackStartTime(),6); + float lastAnimProgress = truncateDecimal(unit->getLastAnimProgressAsFloat(),6); + float animProgress = truncateDecimal(unit->getAnimProgressAsFloat(),6); bool startAttackParticleSystemNow = (attackStartTime >= lastAnimProgress && attackStartTime < animProgress); char szBuf[8096]=""; @@ -2211,7 +2211,7 @@ void UnitUpdater::hit(Unit *attacker, const AttackSkillType* ast, const Vec2i &t scriptManager->onUnitAttacking(attacker); double distance = pci.getPos().dist(targetPos); - distance = truncateDecimal(distance,10); + distance = truncateDecimal(distance,6); damage(attacker, ast, attacked, distance); } } @@ -2241,7 +2241,7 @@ void UnitUpdater::damage(Unit *attacker, const AttackSkillType* ast, Unit *attac int var = ast->getAttackVar(); int armor = attacked->getType()->getTotalArmor(attacked->getTotalUpgrade()); double damageMultiplier = world->getTechTree()->getDamageMultiplier(ast->getAttackType(), attacked->getType()->getArmorType()); - damageMultiplier = truncateDecimal(damageMultiplier,10); + damageMultiplier = truncateDecimal(damageMultiplier,6); //compute damage //damage += random.randRange(-var, var); @@ -2249,7 +2249,7 @@ void UnitUpdater::damage(Unit *attacker, const AttackSkillType* ast, Unit *attac damage /= distance+1; damage -= armor; damage *= damageMultiplier; - damage = truncateDecimal(damage,10); + damage = truncateDecimal(damage,6); if(damage < 1) { damage= 1; @@ -2296,8 +2296,8 @@ void UnitUpdater::startAttackParticleSystem(Unit *unit){ ParticleSystemTypeProjectile *pstProj= ast->getProjParticleType(); ParticleSystemTypeSplash *pstSplash= ast->getSplashParticleType(); - Vec3d startPos= unit->getCurrVector(); - Vec3d endPos= unit->getTargetVec(); + Vec3f startPos= unit->getCurrVector(); + Vec3f endPos= unit->getTargetVec(); //make particle system const SurfaceCell *sc= map->getSurfaceCell(Map::toSurfCoords(unit->getPos())); @@ -2490,7 +2490,7 @@ bool UnitUpdater::unitOnRange(Unit *unit, int range, Unit **rangedPtr, //aux vars int size = unit->getType()->getSize(); Vec2i center = unit->getPos(); - Vec2d floatCenter = unit->getFloatCenteredPos(); + Vec2f floatCenter = unit->getFloatCenteredPos(); //bool foundInCache = true; if(findCachedCellsEnemies(center,range,size,enemies,ast, @@ -2502,9 +2502,9 @@ bool UnitUpdater::unitOnRange(Unit *unit, int range, Unit **rangedPtr, for(int j = center.y - range; j < center.y + range + size; ++j) { //cells inside map and in range #ifdef USE_STREFLOP - if(map->isInside(i, j) && streflop::floor(static_cast(floatCenter.dist(Vec2d((double)i, (double)j)))) <= (range+1)){ + if(map->isInside(i, j) && streflop::floor(static_cast(floatCenter.dist(Vec2f((float)i, (float)j)))) <= (range+1)){ #else - if(map->isInside(i, j) && floor(floatCenter.dist(Vec2d((double)i, (double)j))) <= (range+1)){ + if(map->isInside(i, j) && floor(floatCenter.dist(Vec2f((float)i, (float)j))) <= (range+1)){ #endif Cell *cell = map->getCell(i,j); findEnemiesForCell(ast,cell,unit,commandTarget,enemies); @@ -2595,7 +2595,7 @@ bool UnitUpdater::unitOnRange(Unit *unit, int range, Unit **rangedPtr, if(evalMode == false && onlyEnemyUnits == false && enemyUnit->getTeam() != world->getThisTeamIndex()) { - Vec2d enemyFloatCenter = enemyUnit->getFloatCenteredPos(); + Vec2f enemyFloatCenter = enemyUnit->getFloatCenteredPos(); // find nearest Attack and cleanup old dates AttackWarningData *nearest = NULL; double currentDistance = 0.f; @@ -2684,7 +2684,7 @@ vector UnitUpdater::enemyUnitsOnRange(const Unit *unit,const AttackSkillT //aux vars int size = unit->getType()->getSize(); Vec2i center = unit->getPosNotThreadSafe(); - Vec2d floatCenter = unit->getFloatCenteredPos(); + Vec2f floatCenter = unit->getFloatCenteredPos(); //bool foundInCache = true; if(findCachedCellsEnemies(center,range,size,enemies,ast, @@ -2696,9 +2696,9 @@ vector UnitUpdater::enemyUnitsOnRange(const Unit *unit,const AttackSkillT for(int j = center.y - range; j < center.y + range + size; ++j) { //cells inside map and in range #ifdef USE_STREFLOP - if(map->isInside(i, j) && streflop::floor(static_cast(floatCenter.dist(Vec2d((double)i, (double)j)))) <= (range+1)){ + if(map->isInside(i, j) && streflop::floor(static_cast(floatCenter.dist(Vec2f((float)i, (float)j)))) <= (range+1)){ #else - if(map->isInside(i, j) && floor(floatCenter.dist(Vec2d((double)i, (double)j))) <= (range+1)){ + if(map->isInside(i, j) && floor(floatCenter.dist(Vec2f((float)i, (float)j))) <= (range+1)){ #endif Cell *cell = map->getCell(i,j); findEnemiesForCell(ast,cell,unit,commandTarget,enemies); @@ -2744,7 +2744,7 @@ vector UnitUpdater::findUnitsInRange(const Unit *unit, int radius) { //aux vars int size = unit->getType()->getSize(); Vec2i center = unit->getPosNotThreadSafe(); - Vec2d floatCenter = unit->getFloatCenteredPos(); + Vec2f floatCenter = unit->getFloatCenteredPos(); //nearby cells //UnitRangeCellsLookupItem cacheItem; @@ -2752,9 +2752,9 @@ vector UnitUpdater::findUnitsInRange(const Unit *unit, int radius) { for(int j = center.y - range; j < center.y + range + size; ++j) { //cells inside map and in range #ifdef USE_STREFLOP - if(map->isInside(i, j) && streflop::floor(static_cast(floatCenter.dist(Vec2d((double)i, (double)j)))) <= (range+1)){ + if(map->isInside(i, j) && streflop::floor(static_cast(floatCenter.dist(Vec2f((float)i, (float)j)))) <= (range+1)){ #else - if(map->isInside(i, j) && floor(floatCenter.dist(Vec2d((double)i, (double)j))) <= (range+1)){ + if(map->isInside(i, j) && floor(floatCenter.dist(Vec2f((float)i, (float)j))) <= (range+1)){ #endif Cell *cell = map->getCell(i,j); findUnitsForCell(cell,unit,units); @@ -2817,7 +2817,7 @@ void UnitUpdater::saveGame(XmlNode *rootNode) { // RandomGen random; //unitupdaterNode->addAttribute("random",intToStr(random.getLastNumber()), mapTagReplacements); // float attackWarnRange; - unitupdaterNode->addAttribute("attackWarnRange",doubleToStr(attackWarnRange,10), mapTagReplacements); + unitupdaterNode->addAttribute("attackWarnRange",floatToStr(attackWarnRange,6), mapTagReplacements); // AttackWarnings attackWarnings; // // Mutex mutexUnitRangeCellsLookupItemCache; diff --git a/source/glest_game/world/unit_updater.h b/source/glest_game/world/unit_updater.h index ea49f164..02a15004 100644 --- a/source/glest_game/world/unit_updater.h +++ b/source/glest_game/world/unit_updater.h @@ -55,7 +55,7 @@ public: class AttackWarningData { public: - Vec2d attackPosition; + Vec2f attackPosition; int lastFrameCount; }; @@ -81,7 +81,7 @@ private: Game *game; //RandomGen random; Mutex mutexAttackWarnings; - double attackWarnRange; + float attackWarnRange; AttackWarnings attackWarnings; Mutex mutexUnitRangeCellsLookupItemCache; diff --git a/source/shared_lib/include/graphics/particle.h b/source/shared_lib/include/graphics/particle.h index e81a2fa9..fc55e328 100644 --- a/source/shared_lib/include/graphics/particle.h +++ b/source/shared_lib/include/graphics/particle.h @@ -45,12 +45,12 @@ class Model; class Particle { public: //attributes - Vec3d pos; - Vec3d lastPos; - Vec3d speed; - Vec3d accel; + Vec3f pos; + Vec3f lastPos; + Vec3f speed; + Vec3f accel; Vec4f color; - double size; + float size; int energy; public: @@ -59,12 +59,12 @@ public: energy = 0; } //get - Vec3d getPos() const {return pos;} - Vec3d getLastPos() const {return lastPos;} - Vec3d getSpeed() const {return speed;} - Vec3d getAccel() const {return accel;} + Vec3f getPos() const {return pos;} + Vec3f getLastPos() const {return lastPos;} + Vec3f getSpeed() const {return speed;} + Vec3f getAccel() const {return accel;} Vec4f getColor() const {return color;} - double getSize() const {return size;} + float getSize() const {return size;} int getEnergy() const {return energy;} void saveGame(XmlNode *rootNode); @@ -135,15 +135,15 @@ protected: int textureFileLoadDeferredComponents; Texture *texture; - Vec3d pos; + Vec3f pos; Vec4f color; Vec4f colorNoEnergy; - double emissionRate; - double emissionState; + float emissionRate; + float emissionState; int maxParticleEnergy; int varParticleEnergy; - double particleSize; - double speed; + float particleSize; + float speed; Vec3f factionColor; bool teamcolorNoEnergy; bool teamcolorEnergy; @@ -166,7 +166,7 @@ public: State getState() const {return state;} BlendMode getBlendMode() const {return blendMode;} Texture *getTexture() const {return texture;} - Vec3d getPos() const {return pos;} + Vec3f getPos() const {return pos;} Particle *getParticle(int i) {return &particles[i];} const Particle *getParticle(int i) const {return &particles[i];} int getAliveParticleCount() const {return aliveParticleCount;} @@ -181,14 +181,14 @@ public: //set virtual void setState(State state); void setTexture(Texture *texture); - virtual void setPos(Vec3d pos); + virtual void setPos(Vec3f pos); void setColor(Vec4f color); void setColorNoEnergy(Vec4f color); - void setEmissionRate(double emissionRate); + void setEmissionRate(float emissionRate); void setMaxParticleEnergy(int maxParticleEnergy); void setVarParticleEnergy(int varParticleEnergy); - void setParticleSize(double particleSize); - void setSpeed(double speed); + void setParticleSize(float particleSize); + void setSpeed(float speed); virtual void setActive(bool active); void setObserver(ParticleObserver *particleObserver); virtual void setVisible(bool visible); @@ -236,8 +236,8 @@ protected: class FireParticleSystem: public ParticleSystem{ private: - double radius; - Vec3d windSpeed; + float radius; + Vec3f windSpeed; public: FireParticleSystem(int particleCount= 2000); @@ -249,8 +249,8 @@ public: virtual void updateParticle(Particle *p); //set params - void setRadius(double radius); - void setWind(double windAngle, double windSpeed); + void setRadius(float radius); + void setWind(float windAngle, float windSpeed); virtual void saveGame(XmlNode *rootNode); virtual void loadGame(const XmlNode *rootNode); @@ -280,17 +280,17 @@ public: ParticleSystem* getChild(int i); void addChild(UnitParticleSystem* child); void removeChild(UnitParticleSystem* child); - void setPos(Vec3d pos); - void setOffset(Vec3d offset); + void setPos(Vec3f pos); + void setOffset(Vec3f offset); void setModel(Model *model) {this->model= model;} virtual void render(ParticleRenderer *pr, ModelRenderer *mr); - double getTween() { return tween; } // 0.0 -> 1.0 for animation of model + float getTween() { return tween; } // 0.0 -> 1.0 for animation of model Model *getModel() const {return model;} virtual string getModelFileLoadDeferred(); void setPrimitive(Primitive primitive) {this->primitive= primitive;} - Vec3d getDirection() const {return direction;} - void setModelCycle(double modelCycle) {this->modelCycle= modelCycle;} + Vec3f getDirection() const {return direction;} + void setModelCycle(float modelCycle) {this->modelCycle= modelCycle;} virtual void saveGame(XmlNode *rootNode); virtual void loadGame(const XmlNode *rootNode); @@ -306,14 +306,14 @@ protected: string modelFileLoadDeferred; Model *model; - double modelCycle; - Vec3d offset; - Vec3d direction; - double tween; + float modelCycle; + Vec3f offset; + Vec3f direction; + float tween; GameParticleSystem(int particleCount); void positionChildren(); - void setTween(double relative,double absolute); + void setTween(float relative,float absolute); }; // ===================================================== @@ -325,15 +325,15 @@ public: static bool isNight; static Vec3f lightColor; private: - double radius; - double minRadius; - Vec3d windSpeed; - Vec3d cRotation; - Vec3d fixedAddition; - Vec3d oldPosition; + float radius; + float minRadius; + Vec3f windSpeed; + Vec3f cRotation; + Vec3f fixedAddition; + Vec3f oldPosition; bool energyUp; - double startTime; - double endTime; + float startTime; + float endTime; public: enum Shape{ @@ -345,10 +345,10 @@ public: bool relativeDirection; bool fixed; Shape shape; - double angle; - double sizeNoEnergy; - double gravity; - double rotation; + float angle; + float sizeNoEnergy; + float gravity; + float rotation; bool isVisibleAtNight; bool isVisibleAtDay; bool isDaylightAffected; @@ -356,7 +356,7 @@ public: int staticParticleCount; int delay; int lifetime; - double emissionRateFade; + float emissionRateFade; GameParticleSystem* parent; public: @@ -373,22 +373,22 @@ public: virtual void fade(); virtual void render(ParticleRenderer *pr, ModelRenderer *mr); - virtual void setStartTime(double startTime) { this->startTime = startTime; } - virtual double getStartTime() const { return this->startTime; } - virtual void setEndTime(double endTime) { this->endTime = endTime; } - virtual double getEndTime() const { return this->endTime; } + virtual void setStartTime(float startTime) { this->startTime = startTime; } + virtual float getStartTime() const { return this->startTime; } + virtual void setEndTime(float endTime) { this->endTime = endTime; } + virtual float getEndTime() const { return this->endTime; } //set params - void setRadius(double radius) {this->radius= radius;} - void setMinRadius(double minRadius) {this->minRadius= minRadius;} - void setEmissionRateFade(double emissionRateFade) {this->emissionRateFade= emissionRateFade;} + void setRadius(float radius) {this->radius= radius;} + void setMinRadius(float minRadius) {this->minRadius= minRadius;} + void setEmissionRateFade(float emissionRateFade) {this->emissionRateFade= emissionRateFade;} - void setWind(double windAngle, double windSpeed); + void setWind(float windAngle, float windSpeed); - void setDirection(Vec3d direction) {this->direction= direction;} - void setSizeNoEnergy(double sizeNoEnergy) {this->sizeNoEnergy= sizeNoEnergy;} - void setGravity(double gravity) {this->gravity= gravity;} - void setRotation(double rotation); + void setDirection(Vec3f direction) {this->direction= direction;} + void setSizeNoEnergy(float sizeNoEnergy) {this->sizeNoEnergy= sizeNoEnergy;} + void setGravity(float gravity) {this->gravity= gravity;} + void setRotation(float rotation); void setRelative(bool relative) {this->relative= relative;} void setRelativeDirection(bool relativeDirection) {this->relativeDirection= relativeDirection;} void setFixed(bool fixed) {this->fixed= fixed;} @@ -399,12 +399,12 @@ public: void setIsVisibleAtDay(bool value) {this->isVisibleAtDay= value;} void setRadiusBasedStartenergy(bool value) {this->radiusBasedStartenergy= value;} void setShape(Shape shape) {this->shape= shape;} - void setAngle(double angle) {this->angle= angle;} + void setAngle(float angle) {this->angle= angle;} void setDelay(int delay) {this->delay= delay;} void setLifetime(int lifetime) {this->lifetime= lifetime;} void setParent(GameParticleSystem* parent) {this->parent= parent;} GameParticleSystem* getParent() const {return parent;} - void setParentDirection(Vec3d parentDirection); + void setParentDirection(Vec3f parentDirection); static Shape strToShape(const string& str); @@ -422,8 +422,8 @@ public: class RainParticleSystem: public ParticleSystem{ private: - Vec3d windSpeed; - double radius; + Vec3f windSpeed; + float radius; public: RainParticleSystem(int particleCount= 4000); @@ -435,8 +435,8 @@ public: virtual void initParticle(Particle *p, int particleIndex); virtual bool deathTest(Particle *p); - void setRadius(double radius); - void setWind(double windAngle, double windSpeed); + void setRadius(float radius); + void setWind(float windAngle, float windSpeed); virtual string toString() const; @@ -449,8 +449,8 @@ public: class SnowParticleSystem: public ParticleSystem{ private: - Vec3d windSpeed; - double radius; + Vec3f windSpeed; + float radius; public: SnowParticleSystem(int particleCount= 4000); @@ -460,8 +460,8 @@ public: virtual void initParticle(Particle *p, int particleIndex); virtual bool deathTest(Particle *p); - void setRadius(double radius); - void setWind(double windAngle, double windSpeed); + void setRadius(float radius); + void setWind(float windAngle, float windSpeed); virtual string toString() const; @@ -477,15 +477,15 @@ public: class AttackParticleSystem: public GameParticleSystem { protected: - double sizeNoEnergy; - double gravity; + float sizeNoEnergy; + float gravity; public: AttackParticleSystem(int particleCount); virtual ParticleSystemType getParticleSystemType() const { return pst_ProjectileParticleSystem;} - void setSizeNoEnergy(double sizeNoEnergy) {this->sizeNoEnergy= sizeNoEnergy;} - void setGravity(double gravity) {this->gravity= gravity;} + void setSizeNoEnergy(float sizeNoEnergy) {this->sizeNoEnergy= sizeNoEnergy;} + void setGravity(float gravity) {this->gravity= gravity;} virtual void initParticleSystem() {} // opportunity to do any initialization when the system has been created and all settings set @@ -514,23 +514,23 @@ public: private: SplashParticleSystem *nextParticleSystem; - Vec3d lastPos; - Vec3d startPos; - Vec3d endPos; - Vec3d flatPos; + Vec3f lastPos; + Vec3f startPos; + Vec3f endPos; + Vec3f flatPos; - Vec3d xVector; - Vec3d yVector; - Vec3d zVector; + Vec3f xVector; + Vec3f yVector; + Vec3f zVector; Trajectory trajectory; - double trajectorySpeed; + float trajectorySpeed; //parabolic - double trajectoryScale; - double trajectoryFrequency; + float trajectoryScale; + float trajectoryFrequency; - double arriveDestinationDistance; + float arriveDestinationDistance; void rotateChildren(); public: @@ -546,11 +546,11 @@ public: virtual void updateParticle(Particle *p); void setTrajectory(Trajectory trajectory) {this->trajectory= trajectory;} - void setTrajectorySpeed(double trajectorySpeed) {this->trajectorySpeed= trajectorySpeed;} - void setTrajectoryScale(double trajectoryScale) {this->trajectoryScale= trajectoryScale;} - void setTrajectoryFrequency(double trajectoryFrequency) {this->trajectoryFrequency= trajectoryFrequency;} + void setTrajectorySpeed(float trajectorySpeed) {this->trajectorySpeed= trajectorySpeed;} + void setTrajectoryScale(float trajectoryScale) {this->trajectoryScale= trajectoryScale;} + void setTrajectoryFrequency(float trajectoryFrequency) {this->trajectoryFrequency= trajectoryFrequency;} - void setPath(Vec3d startPos, Vec3d endPos); + void setPath(Vec3f startPos, Vec3f endPos); static Trajectory strToTrajectory(const string &str); @@ -573,13 +573,13 @@ public: private: ProjectileParticleSystem *prevParticleSystem; - double emissionRateFade; - double verticalSpreadA; - double verticalSpreadB; - double horizontalSpreadA; - double horizontalSpreadB; + float emissionRateFade; + float verticalSpreadA; + float verticalSpreadB; + float horizontalSpreadA; + float horizontalSpreadB; - double startEmissionRate; + float startEmissionRate; public: SplashParticleSystem(int particleCount= 1000); @@ -591,11 +591,11 @@ public: virtual void initParticleSystem(); - void setEmissionRateFade(double emissionRateFade) {this->emissionRateFade= emissionRateFade;} - void setVerticalSpreadA(double verticalSpreadA) {this->verticalSpreadA= verticalSpreadA;} - void setVerticalSpreadB(double verticalSpreadB) {this->verticalSpreadB= verticalSpreadB;} - void setHorizontalSpreadA(double horizontalSpreadA) {this->horizontalSpreadA= horizontalSpreadA;} - void setHorizontalSpreadB(double horizontalSpreadB) {this->horizontalSpreadB= horizontalSpreadB;} + void setEmissionRateFade(float emissionRateFade) {this->emissionRateFade= emissionRateFade;} + void setVerticalSpreadA(float verticalSpreadA) {this->verticalSpreadA= verticalSpreadA;} + void setVerticalSpreadB(float verticalSpreadB) {this->verticalSpreadB= verticalSpreadB;} + void setHorizontalSpreadA(float horizontalSpreadA) {this->horizontalSpreadA= horizontalSpreadA;} + void setHorizontalSpreadB(float horizontalSpreadB) {this->horizontalSpreadB= horizontalSpreadB;} virtual void saveGame(XmlNode *rootNode); virtual void loadGame(const XmlNode *rootNode); diff --git a/source/shared_lib/sources/graphics/particle.cpp b/source/shared_lib/sources/graphics/particle.cpp index e024aca4..b60587f6 100644 --- a/source/shared_lib/sources/graphics/particle.cpp +++ b/source/shared_lib/sources/graphics/particle.cpp @@ -55,7 +55,7 @@ void Particle::saveGame(XmlNode *rootNode) { // Vec4f color; particleNode->addAttribute("color",color.getString(), mapTagReplacements); // float size; - particleNode->addAttribute("size",doubleToStr(size,10), mapTagReplacements); + particleNode->addAttribute("size",floatToStr(size,6), mapTagReplacements); // int energy; particleNode->addAttribute("energy",intToStr(energy), mapTagReplacements); } @@ -65,13 +65,13 @@ void Particle::loadGame(const XmlNode *rootNode) { //particleNode = aiNode->getAttribute("startLoc")->getIntValue(); // Vec3f pos; - pos = Vec3d::strToVec3(particleNode->getAttribute("pos")->getValue()); + pos = Vec3f::strToVec3(particleNode->getAttribute("pos")->getValue()); // Vec3f lastPos; - lastPos = Vec3d::strToVec3(particleNode->getAttribute("lastPos")->getValue()); + lastPos = Vec3f::strToVec3(particleNode->getAttribute("lastPos")->getValue()); // Vec3f speed; - speed = Vec3d::strToVec3(particleNode->getAttribute("speed")->getValue()); + speed = Vec3f::strToVec3(particleNode->getAttribute("speed")->getValue()); // Vec3f accel; - accel = Vec3d::strToVec3(particleNode->getAttribute("accel")->getValue()); + accel = Vec3f::strToVec3(particleNode->getAttribute("accel")->getValue()); // Vec4f color; color = Vec4f::strToVec4(particleNode->getAttribute("color")->getValue()); // float size; @@ -112,7 +112,7 @@ ParticleSystem::ParticleSystem(int particleCount) { //this->particleCount= particles.size(); maxParticleEnergy= 250; varParticleEnergy= 50; - pos= Vec3d(0.0f); + pos= Vec3f(0.0f); color= Vec4f(1.0f); colorNoEnergy= Vec4f(0.0f); emissionRate= 15.0f; @@ -216,8 +216,8 @@ void ParticleSystem::update() { Particle *p= createParticle(); initParticle(p, i); } - emissionState = emissionState - (double) emissionIntValue; - emissionState = truncateDecimal(emissionState,10); + emissionState = emissionState - (float) emissionIntValue; + emissionState = truncateDecimal(emissionState,6); } } } @@ -252,7 +252,7 @@ void ParticleSystem::setTexture(Texture *texture){ this->texture= texture; } -void ParticleSystem::setPos(Vec3d pos){ +void ParticleSystem::setPos(Vec3f pos){ this->pos= pos; for(int i=getChildCount()-1; i>=0; i--) getChild(i)->setPos(pos); @@ -266,9 +266,9 @@ void ParticleSystem::setColorNoEnergy(Vec4f colorNoEnergy){ this->colorNoEnergy= colorNoEnergy; } -void ParticleSystem::setEmissionRate(double emissionRate){ +void ParticleSystem::setEmissionRate(float emissionRate){ this->emissionRate= emissionRate; - this->emissionRate = truncateDecimal(this->emissionRate,10); + this->emissionRate = truncateDecimal(this->emissionRate,6); } void ParticleSystem::setMaxParticleEnergy(int maxParticleEnergy){ @@ -279,14 +279,14 @@ void ParticleSystem::setVarParticleEnergy(int varParticleEnergy){ this->varParticleEnergy= varParticleEnergy; } -void ParticleSystem::setParticleSize(double particleSize){ +void ParticleSystem::setParticleSize(float particleSize){ this->particleSize= particleSize; - this->particleSize = truncateDecimal(this->particleSize,10); + this->particleSize = truncateDecimal(this->particleSize,6); } -void ParticleSystem::setSpeed(double speed){ +void ParticleSystem::setSpeed(float speed){ this->speed= speed; - this->speed = truncateDecimal(this->speed,10); + this->speed = truncateDecimal(this->speed,6); } void ParticleSystem::setActive(bool active){ @@ -339,12 +339,12 @@ string ParticleSystem::toString() const { result += "\npos = " + pos.getString(); result += "\ncolor = " + color.getString(); result += "\ncolorNoEnergy = " + colorNoEnergy.getString(); - result += "\nemissionRate = " + doubleToStr(emissionRate,10); - result += "\nemissionState = " + doubleToStr(emissionState,10); + result += "\nemissionRate = " + floatToStr(emissionRate,6); + result += "\nemissionState = " + floatToStr(emissionState,6); result += "\nmaxParticleEnergy = " + intToStr(maxParticleEnergy); result += "\nvarParticleEnergy = " + intToStr(varParticleEnergy); - result += "\nparticleSize = " + doubleToStr(particleSize,10); - result += "\nspeed = " + doubleToStr(speed,10); + result += "\nparticleSize = " + floatToStr(particleSize,6); + result += "\nspeed = " + floatToStr(speed,6); result += "\nfactionColor = " + factionColor.getString(); result += "\nteamcolorNoEnergy = " + intToStr(teamcolorNoEnergy); result += "\nteamcolorEnergy = " + intToStr(teamcolorEnergy); @@ -397,17 +397,17 @@ void ParticleSystem::saveGame(XmlNode *rootNode) { // Vec4f colorNoEnergy; particleSystemNode->addAttribute("colorNoEnergy",colorNoEnergy.getString(), mapTagReplacements); // float emissionRate; - particleSystemNode->addAttribute("emissionRate",doubleToStr(emissionRate,10), mapTagReplacements); + particleSystemNode->addAttribute("emissionRate",floatToStr(emissionRate,6), mapTagReplacements); // float emissionState; - particleSystemNode->addAttribute("emissionState",doubleToStr(emissionState,10), mapTagReplacements); + particleSystemNode->addAttribute("emissionState",floatToStr(emissionState,6), mapTagReplacements); // int maxParticleEnergy; particleSystemNode->addAttribute("maxParticleEnergy",intToStr(maxParticleEnergy), mapTagReplacements); // int varParticleEnergy; particleSystemNode->addAttribute("varParticleEnergy",intToStr(varParticleEnergy), mapTagReplacements); // float particleSize; - particleSystemNode->addAttribute("particleSize",doubleToStr(particleSize,10), mapTagReplacements); + particleSystemNode->addAttribute("particleSize",floatToStr(particleSize,6), mapTagReplacements); // float speed; - particleSystemNode->addAttribute("speed",doubleToStr(speed,10), mapTagReplacements); + particleSystemNode->addAttribute("speed",floatToStr(speed,6), mapTagReplacements); // Vec3f factionColor; particleSystemNode->addAttribute("factionColor",factionColor.getString(), mapTagReplacements); // bool teamcolorNoEnergy; @@ -490,7 +490,7 @@ void ParticleSystem::loadGame(const XmlNode *rootNode) { } // Vec3f pos; - pos = Vec3d::strToVec3(particleSystemNode->getAttribute("pos")->getValue()); + pos = Vec3f::strToVec3(particleSystemNode->getAttribute("pos")->getValue()); // Vec4f color; color = Vec4f::strToVec4(particleSystemNode->getAttribute("color")->getValue()); // Vec4f colorNoEnergy; @@ -585,11 +585,11 @@ Particle * ParticleSystem::createParticle() { void ParticleSystem::initParticle(Particle *p, int particleIndex) { p->pos= pos; p->lastPos= p->pos; - p->speed= Vec3d(0.0f); - p->accel= Vec3d(0.0f); + p->speed= Vec3f(0.0f); + p->accel= Vec3f(0.0f); p->color= Vec4f(1.0f, 1.0f, 1.0f, 1.0); p->size= particleSize; - p->size = truncateDecimal(p->size,10); + p->size = truncateDecimal(p->size,6); p->energy= maxParticleEnergy + random.randRange(-varParticleEnergy, varParticleEnergy); } @@ -632,7 +632,7 @@ FireParticleSystem::FireParticleSystem(int particleCount) : radius= 0.5f; speed= 0.01f; - windSpeed= Vec3d(0.0f); + windSpeed= Vec3f(0.0f); setParticleSize(0.6f); setColorNoEnergy(Vec4f(1.0f, 0.5f, 0.0f, 1.0f)); @@ -641,37 +641,37 @@ FireParticleSystem::FireParticleSystem(int particleCount) : void FireParticleSystem::initParticle(Particle *p, int particleIndex){ ParticleSystem::initParticle(p, particleIndex); - double ang= random.randRange(-2.0f * pi, 2.0f * pi); + float ang= random.randRange(-2.0f * pi, 2.0f * pi); #ifdef USE_STREFLOP - double mod= streflop::fabsf(static_cast(random.randRange(-radius, radius))); + float mod= streflop::fabsf(static_cast(random.randRange(-radius, radius))); - double x= streflop::sinf(static_cast(ang))*mod; - double y= streflop::cosf(static_cast(ang))*mod; + float x= streflop::sinf(static_cast(ang))*mod; + float y= streflop::cosf(static_cast(ang))*mod; - double radRatio= streflop::sqrtf(static_cast(mod/radius)); + float radRatio= streflop::sqrtf(static_cast(mod/radius)); #else - double mod= fabsf(random.randRange(-radius, radius)); + float mod= fabsf(random.randRange(-radius, radius)); - double x= sinf(ang) * mod; - double y= cosf(ang) * mod; + float x= sinf(ang) * mod; + float y= cosf(ang) * mod; - double radRatio= sqrtf((mod / radius)); + float radRatio= sqrtf((mod / radius)); #endif p->color= colorNoEnergy * 0.5f + colorNoEnergy * 0.5f * radRatio; p->energy= static_cast (maxParticleEnergy * radRatio) + random.randRange(-varParticleEnergy, varParticleEnergy); - p->pos= Vec3d(pos.x + x, pos.y + random.randRange(-radius / 2, radius / 2), pos.z + y); - p->pos.x = truncateDecimal(p->pos.x,10); - p->pos.y = truncateDecimal(p->pos.y,10); - p->pos.z = truncateDecimal(p->pos.z,10); + p->pos= Vec3f(pos.x + x, pos.y + random.randRange(-radius / 2, radius / 2), pos.z + y); + p->pos.x = truncateDecimal(p->pos.x,6); + p->pos.y = truncateDecimal(p->pos.y,6); + p->pos.z = truncateDecimal(p->pos.z,6); p->lastPos= pos; p->size= particleSize; - p->speed= Vec3d(0, speed + speed * random.randRange(-0.5f, 0.5f), 0) + windSpeed; - p->speed.x = truncateDecimal(p->speed.x,10); - p->speed.y = truncateDecimal(p->speed.y,10); - p->speed.z = truncateDecimal(p->speed.z,10); + p->speed= Vec3f(0, speed + speed * random.randRange(-0.5f, 0.5f), 0) + windSpeed; + p->speed.x = truncateDecimal(p->speed.x,6); + p->speed.y = truncateDecimal(p->speed.y,6); + p->speed.z = truncateDecimal(p->speed.z,6); } @@ -688,9 +688,9 @@ void FireParticleSystem::updateParticle(Particle *p){ p->color.w*= 0.98f; p->speed.x*= 1.001f; - p->speed.x = truncateDecimal(p->speed.x,10); - p->speed.y = truncateDecimal(p->speed.y,10); - p->speed.z = truncateDecimal(p->speed.z,10); + p->speed.x = truncateDecimal(p->speed.x,6); + p->speed.y = truncateDecimal(p->speed.y,6); + p->speed.z = truncateDecimal(p->speed.z,6); } @@ -698,18 +698,18 @@ string FireParticleSystem::toString() const { string result = ParticleSystem::toString(); result += "\nFireParticleSystem "; - result += "\nradius = " + doubleToStr(radius); + result += "\nradius = " + floatToStr(radius); result += "\nwindSpeed = " + windSpeed.getString(); return result; } // ================= SET PARAMS ==================== -void FireParticleSystem::setRadius(double radius){ +void FireParticleSystem::setRadius(float radius){ this->radius= radius; } -void FireParticleSystem::setWind(double windAngle, double windSpeed) { +void FireParticleSystem::setWind(float windAngle, float windSpeed) { #ifdef USE_STREFLOP this->windSpeed.x= streflop::sinf(static_cast(degToRad(windAngle)))*windSpeed; this->windSpeed.y= 0.0f; @@ -720,9 +720,9 @@ void FireParticleSystem::setWind(double windAngle, double windSpeed) { this->windSpeed.z= cosf(degToRad(windAngle)) * windSpeed; #endif - this->windSpeed.x = truncateDecimal(this->windSpeed.x,10); - this->windSpeed.y = truncateDecimal(this->windSpeed.y,10); - this->windSpeed.z = truncateDecimal(this->windSpeed.z,10); + this->windSpeed.x = truncateDecimal(this->windSpeed.x,6); + this->windSpeed.y = truncateDecimal(this->windSpeed.y,6); + this->windSpeed.z = truncateDecimal(this->windSpeed.z,6); } void FireParticleSystem::saveGame(XmlNode *rootNode) { @@ -732,7 +732,7 @@ void FireParticleSystem::saveGame(XmlNode *rootNode) { ParticleSystem::saveGame(fireParticleSystemNode); // float radius; - fireParticleSystemNode->addAttribute("radius",doubleToStr(radius,10), mapTagReplacements); + fireParticleSystemNode->addAttribute("radius",floatToStr(radius,6), mapTagReplacements); // Vec3f windSpeed; fireParticleSystemNode->addAttribute("windSpeed",windSpeed.getString(), mapTagReplacements); } @@ -744,7 +744,7 @@ void FireParticleSystem::loadGame(const XmlNode *rootNode) { // float radius; radius = fireParticleSystemNode->getAttribute("radius")->getFloatValue(); // Vec3f windSpeed; - windSpeed = Vec3d::strToVec3(fireParticleSystemNode->getAttribute("windSpeed")->getValue()); + windSpeed = Vec3f::strToVec3(fireParticleSystemNode->getAttribute("windSpeed")->getValue()); } Checksum FireParticleSystem::getCRC() { @@ -810,18 +810,18 @@ void GameParticleSystem::removeChild(UnitParticleSystem* child){ children.erase(it); } -void GameParticleSystem::setPos(Vec3d pos){ +void GameParticleSystem::setPos(Vec3f pos){ this->pos= pos; positionChildren(); } void GameParticleSystem::positionChildren() { - Vec3d child_pos = pos - offset; + Vec3f child_pos = pos - offset; for(int i=getChildCount()-1; i>=0; i--) getChild(i)->setPos(child_pos); } -void GameParticleSystem::setOffset(Vec3d offset){ +void GameParticleSystem::setOffset(Vec3f offset){ this->offset= offset; positionChildren(); } @@ -845,7 +845,7 @@ void GameParticleSystem::render(ParticleRenderer *pr, ModelRenderer *mr){ } } -void GameParticleSystem::setTween(double relative,double absolute) { +void GameParticleSystem::setTween(float relative,float absolute) { if(model) { // animation? //printf("#1 Particle model meshcount [%d] modelCycle = %f, relative = %f, absolute = %f\n",model->getMeshCount(),modelCycle,relative,absolute); @@ -870,7 +870,7 @@ void GameParticleSystem::setTween(double relative,double absolute) { } } - tween = truncateDecimal(tween,10); + tween = truncateDecimal(tween,6); 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); //assert(tween >= 0.0f && tween <= 1.0f); @@ -908,13 +908,13 @@ void GameParticleSystem::saveGame(XmlNode *rootNode) { gameParticleSystemNode->addAttribute("model",model->getFileName(), mapTagReplacements); } // float modelCycle; - gameParticleSystemNode->addAttribute("modelCycle",doubleToStr(modelCycle,10), mapTagReplacements); + gameParticleSystemNode->addAttribute("modelCycle",floatToStr(modelCycle,6), mapTagReplacements); // Vec3f offset; gameParticleSystemNode->addAttribute("offset",offset.getString(), mapTagReplacements); // Vec3f direction; gameParticleSystemNode->addAttribute("direction",direction.getString(), mapTagReplacements); // float tween; - gameParticleSystemNode->addAttribute("tween",doubleToStr(tween,10), mapTagReplacements); + gameParticleSystemNode->addAttribute("tween",floatToStr(tween,6), mapTagReplacements); } void GameParticleSystem::loadGame(const XmlNode *rootNode) { const XmlNode *gameParticleSystemNode = rootNode->getChild("GameParticleSystem"); @@ -952,9 +952,9 @@ void GameParticleSystem::loadGame(const XmlNode *rootNode) { //gameParticleSystemNode->addAttribute("modelCycle",floatToStr(modelCycle), mapTagReplacements); modelCycle = gameParticleSystemNode->getAttribute("modelCycle")->getFloatValue(); // Vec3f offset; - offset = Vec3d::strToVec3(gameParticleSystemNode->getAttribute("offset")->getValue()); + offset = Vec3f::strToVec3(gameParticleSystemNode->getAttribute("offset")->getValue()); // Vec3f direction; - direction = Vec3d::strToVec3(gameParticleSystemNode->getAttribute("direction")->getValue()); + direction = Vec3f::strToVec3(gameParticleSystemNode->getAttribute("direction")->getValue()); // float tween; tween = gameParticleSystemNode->getAttribute("tween")->getFloatValue(); } @@ -974,10 +974,10 @@ string GameParticleSystem::toString() const { //string modelFileLoadDeferred; //Model *model; - result += "\nmodelCycle = " + doubleToStr(modelCycle); + result += "\nmodelCycle = " + floatToStr(modelCycle); result += "\noffset = " + offset.getString(); result += "\ndirection = " + direction.getString(); - result += "\ntween = " + doubleToStr(tween); + result += "\ntween = " + floatToStr(tween); return result; } @@ -992,7 +992,7 @@ UnitParticleSystem::UnitParticleSystem(int particleCount) : GameParticleSystem(particleCount), parent(NULL) { radius= 0.5f; speed= 0.01f; - windSpeed= Vec3d(0.0f); + windSpeed= Vec3f(0.0f); minRadius = 0.0; setParticleSize(0.6f); @@ -1014,11 +1014,11 @@ UnitParticleSystem::UnitParticleSystem(int particleCount) : isVisibleAtDay= true; isDaylightAffected= false; - cRotation= Vec3d(1.0f, 1.0f, 1.0f); - fixedAddition= Vec3d(0.0f, 0.0f, 0.0f); + cRotation= Vec3f(1.0f, 1.0f, 1.0f); + fixedAddition= Vec3f(0.0f, 0.0f, 0.0f); //prepare system for given staticParticleCount if(staticParticleCount > 0){ - emissionState= (double) staticParticleCount; + emissionState= (float) staticParticleCount; } energyUp= false; @@ -1053,7 +1053,7 @@ void UnitParticleSystem::render(ParticleRenderer *pr, ModelRenderer *mr) { GameParticleSystem::render(pr,mr); } -void UnitParticleSystem::setRotation(double rotation){ +void UnitParticleSystem::setRotation(float rotation){ this->rotation= rotation; for(Children::iterator it= children.begin(); it != children.end(); ++it) (*it)->setRotation(rotation); @@ -1083,13 +1083,13 @@ UnitParticleSystem::Shape UnitParticleSystem::strToShape(const string& str){ void UnitParticleSystem::initParticle(Particle *p, int particleIndex){ ParticleSystem::initParticle(p, particleIndex); - const double ang= random.randRange(-2.0f * pi, 2.0f * pi); + const float ang= random.randRange(-2.0f * pi, 2.0f * pi); #ifdef USE_STREFLOP - const double mod= streflop::fabsf(static_cast(random.randRange(-radius, radius))); - const double radRatio= streflop::sqrtf(static_cast(mod/radius)); + const float mod= streflop::fabsf(static_cast(random.randRange(-radius, radius))); + const float radRatio= streflop::sqrtf(static_cast(mod/radius)); #else - const double mod= fabsf(random.randRange(-radius, radius)); - const double radRatio= sqrtf(mod / radius); + const float mod= fabsf(random.randRange(-radius, radius)); + const float radRatio= sqrtf(mod / radius); #endif p->color= color; @@ -1110,87 +1110,87 @@ void UnitParticleSystem::initParticle(Particle *p, int particleIndex){ p->lastPos= pos; oldPosition= pos; p->size= particleSize; - p->accel= Vec3d(0.0f, -gravity, 0.0f); - p->accel.x = truncateDecimal(p->accel.x,10); - p->accel.y = truncateDecimal(p->accel.y,10); - p->accel.z = truncateDecimal(p->accel.z,10); + p->accel= Vec3f(0.0f, -gravity, 0.0f); + p->accel.x = truncateDecimal(p->accel.x,6); + p->accel.y = truncateDecimal(p->accel.y,6); + p->accel.z = truncateDecimal(p->accel.z,6); // work out where we start for our shape (set speed and pos) switch(shape){ case sSpherical: - angle = (double)random.randRange(0,360); + angle = (float)random.randRange(0,360); // fall through case sConical:{ - Vec2d horiz = Vec2d(1,0).rotate(ang); - Vec2d vert = Vec2d(1,0).rotate(degToRad(angle)); - Vec3d start = Vec3d(horiz.x*vert.y,vert.x,horiz.y).getNormalized(); // close enough + Vec2f horiz = Vec2f(1,0).rotate(ang); + Vec2f vert = Vec2f(1,0).rotate(degToRad(angle)); + Vec3f start = Vec3f(horiz.x*vert.y,vert.x,horiz.y).getNormalized(); // close enough p->speed = start * speed; - p->speed.x = truncateDecimal(p->speed.x,10); - p->speed.y = truncateDecimal(p->speed.y,10); - p->speed.z = truncateDecimal(p->speed.z,10); + p->speed.x = truncateDecimal(p->speed.x,6); + p->speed.y = truncateDecimal(p->speed.y,6); + p->speed.z = truncateDecimal(p->speed.z,6); start = start * random.randRange(minRadius,radius); p->pos = pos + offset + start; - p->pos.x = truncateDecimal(p->pos.x,10); - p->pos.y = truncateDecimal(p->pos.y,10); - p->pos.z = truncateDecimal(p->pos.z,10); + p->pos.x = truncateDecimal(p->pos.x,6); + p->pos.y = truncateDecimal(p->pos.y,6); + p->pos.z = truncateDecimal(p->pos.z,6); } break; case sLinear:{ #ifdef USE_STREFLOP - double x= streflop::sinf(static_cast(ang))*mod; - double y= streflop::cosf(static_cast(ang))*mod; + float x= streflop::sinf(static_cast(ang))*mod; + float y= streflop::cosf(static_cast(ang))*mod; #else - double x= sinf(ang) * mod; - double y= cosf(ang) * mod; + float x= sinf(ang) * mod; + float y= cosf(ang) * mod; #endif - const double rad= degToRad(rotation); + const float rad= degToRad(rotation); if(!relative){ - p->pos= Vec3d(pos.x + x + offset.x, pos.y + + p->pos= Vec3f(pos.x + x + offset.x, pos.y + random.randRange(-radius / 2, radius / 2) + offset.y, pos.z + y + offset.z); - p->pos.x = truncateDecimal(p->pos.x,10); - p->pos.y = truncateDecimal(p->pos.y,10); - p->pos.z = truncateDecimal(p->pos.z,10); + p->pos.x = truncateDecimal(p->pos.x,6); + p->pos.y = truncateDecimal(p->pos.y,6); + p->pos.z = truncateDecimal(p->pos.z,6); } else {// rotate it according to rotation #ifdef USE_STREFLOP - p->pos= Vec3d(pos.x+x+offset.z*streflop::sinf(static_cast(rad))+offset.x*streflop::cosf(static_cast(rad)), pos.y+random.randRange(-radius/2, radius/2)+offset.y, pos.z+y+(offset.z*streflop::cosf(static_cast(rad))-offset.x*streflop::sinf(static_cast(rad)))); + p->pos= Vec3f(pos.x+x+offset.z*streflop::sinf(static_cast(rad))+offset.x*streflop::cosf(static_cast(rad)), pos.y+random.randRange(-radius/2, radius/2)+offset.y, pos.z+y+(offset.z*streflop::cosf(static_cast(rad))-offset.x*streflop::sinf(static_cast(rad)))); #else - p->pos= Vec3d(pos.x + x + offset.z * sinf(rad) + offset.x * cosf(rad), pos.y + random.randRange(-radius / 2, + p->pos= Vec3f(pos.x + x + offset.z * sinf(rad) + offset.x * cosf(rad), pos.y + random.randRange(-radius / 2, radius / 2) + offset.y, pos.z + y + (offset.z * cosf(rad) - offset.x * sinf(rad))); #endif - p->pos.x = truncateDecimal(p->pos.x,10); - p->pos.y = truncateDecimal(p->pos.y,10); - p->pos.z = truncateDecimal(p->pos.z,10); + p->pos.x = truncateDecimal(p->pos.x,6); + p->pos.y = truncateDecimal(p->pos.y,6); + p->pos.z = truncateDecimal(p->pos.z,6); } - p->speed= Vec3d(direction.x + direction.x * random.randRange(-0.5f, 0.5f), direction.y + direction.y + p->speed= Vec3f(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)); p->speed= p->speed * speed; - p->speed.x = truncateDecimal(p->speed.x,10); - p->speed.y = truncateDecimal(p->speed.y,10); - p->speed.z = truncateDecimal(p->speed.z,10); + p->speed.x = truncateDecimal(p->speed.x,6); + p->speed.y = truncateDecimal(p->speed.y,6); + p->speed.z = truncateDecimal(p->speed.z,6); if(relative && relativeDirection) { #ifdef USE_STREFLOP - p->speed=Vec3d(p->speed.z*streflop::sinf( + p->speed=Vec3f(p->speed.z*streflop::sinf( static_cast(rad)) + p->speed.x * streflop::cosf(static_cast(rad)), p->speed.y, (p->speed.z * streflop::cosf( static_cast(rad)) - p->speed.x * streflop::sinf(static_cast(rad)))); #else - p->speed= Vec3d(p->speed.z * sinf(rad) + p->speed.x * cosf(rad), + p->speed= Vec3f(p->speed.z * sinf(rad) + p->speed.x * cosf(rad), p->speed.y, (p->speed.z * cosf(rad) - p->speed.x * sinf(rad))); #endif - p->speed.x = truncateDecimal(p->speed.x,10); - p->speed.y = truncateDecimal(p->speed.y,10); - p->speed.z = truncateDecimal(p->speed.z,10); + p->speed.x = truncateDecimal(p->speed.x,6); + p->speed.y = truncateDecimal(p->speed.y,6); + p->speed.z = truncateDecimal(p->speed.z,6); } } break; default: throw megaglest_runtime_error("bad shape"); @@ -1207,17 +1207,17 @@ void UnitParticleSystem::update(){ } if(state != sPause) { emissionRate-= emissionRateFade; - emissionRate = truncateDecimal(emissionRate,10); + emissionRate = truncateDecimal(emissionRate,6); if(parent && emissionRate < 0.0f) { fade(); } } if(fixed) { - fixedAddition= Vec3d(pos.x - oldPosition.x, pos.y - oldPosition.y, pos.z - oldPosition.z); - fixedAddition.x = truncateDecimal(fixedAddition.x,10); - fixedAddition.y = truncateDecimal(fixedAddition.y,10); - fixedAddition.z = truncateDecimal(fixedAddition.z,10); + fixedAddition= Vec3f(pos.x - oldPosition.x, pos.y - oldPosition.y, pos.z - oldPosition.z); + fixedAddition.x = truncateDecimal(fixedAddition.x,6); + fixedAddition.y = truncateDecimal(fixedAddition.y,6); + fixedAddition.z = truncateDecimal(fixedAddition.z,6); oldPosition= pos; } @@ -1225,10 +1225,10 @@ void UnitParticleSystem::update(){ } void UnitParticleSystem::updateParticle(Particle *p){ - double energyRatio; + float energyRatio; if(alternations > 0){ int interval= (maxParticleEnergy / alternations); - double moduloValue= (double)((int)(static_cast (p->energy)) % interval); + float moduloValue= (float)((int)(static_cast (p->energy)) % interval); if(moduloValue < interval / 2){ energyRatio= (interval - moduloValue) / interval; @@ -1239,36 +1239,36 @@ void UnitParticleSystem::updateParticle(Particle *p){ energyRatio= clamp(energyRatio, 0.f, 1.f); } else{ - energyRatio= clamp(static_cast (p->energy) / maxParticleEnergy, 0.f, 1.f); + energyRatio= clamp(static_cast (p->energy) / maxParticleEnergy, 0.f, 1.f); } - energyRatio = truncateDecimal(energyRatio,10); + energyRatio = truncateDecimal(energyRatio,6); p->lastPos += p->speed; - p->lastPos.x = truncateDecimal(p->lastPos.x,10); - p->lastPos.y = truncateDecimal(p->lastPos.y,10); - p->lastPos.z = truncateDecimal(p->lastPos.z,10); + p->lastPos.x = truncateDecimal(p->lastPos.x,6); + p->lastPos.y = truncateDecimal(p->lastPos.y,6); + p->lastPos.z = truncateDecimal(p->lastPos.z,6); p->pos += p->speed; - p->pos.x = truncateDecimal(p->pos.x,10); - p->pos.y = truncateDecimal(p->pos.y,10); - p->pos.z = truncateDecimal(p->pos.z,10); + p->pos.x = truncateDecimal(p->pos.x,6); + p->pos.y = truncateDecimal(p->pos.y,6); + p->pos.z = truncateDecimal(p->pos.z,6); if(fixed) { p->lastPos += fixedAddition; - p->lastPos.x = truncateDecimal(p->lastPos.x,10); - p->lastPos.y = truncateDecimal(p->lastPos.y,10); - p->lastPos.z = truncateDecimal(p->lastPos.z,10); + p->lastPos.x = truncateDecimal(p->lastPos.x,6); + p->lastPos.y = truncateDecimal(p->lastPos.y,6); + p->lastPos.z = truncateDecimal(p->lastPos.z,6); p->pos += fixedAddition; - p->pos.x = truncateDecimal(p->pos.x,10); - p->pos.y = truncateDecimal(p->pos.y,10); - p->pos.z = truncateDecimal(p->pos.z,10); + p->pos.x = truncateDecimal(p->pos.x,6); + p->pos.y = truncateDecimal(p->pos.y,6); + p->pos.z = truncateDecimal(p->pos.z,6); } p->speed += p->accel; - p->speed.x = truncateDecimal(p->speed.x,10); - p->speed.y = truncateDecimal(p->speed.y,10); - p->speed.z = truncateDecimal(p->speed.z,10); + p->speed.x = truncateDecimal(p->speed.x,6); + p->speed.y = truncateDecimal(p->speed.y,6); + p->speed.z = truncateDecimal(p->speed.z,6); p->color= color * energyRatio + colorNoEnergy * (1.0f - energyRatio); if(isDaylightAffected==true) { @@ -1277,7 +1277,7 @@ void UnitParticleSystem::updateParticle(Particle *p){ p->color.z=p->color.z*lightColor.z; } p->size= particleSize * energyRatio + sizeNoEnergy * (1.0f - energyRatio); - p->size = truncateDecimal(p->size,10); + p->size = truncateDecimal(p->size,6); if(state == ParticleSystem::sFade || staticParticleCount < 1){ p->energy--; @@ -1303,7 +1303,7 @@ void UnitParticleSystem::updateParticle(Particle *p){ // ================= SET PARAMS ==================== -void UnitParticleSystem::setWind(double windAngle, double windSpeed){ +void UnitParticleSystem::setWind(float windAngle, float windSpeed){ #ifdef USE_STREFLOP this->windSpeed.x= streflop::sinf(static_cast(degToRad(windAngle)))*windSpeed; this->windSpeed.y= 0.0f; @@ -1314,9 +1314,9 @@ void UnitParticleSystem::setWind(double windAngle, double windSpeed){ this->windSpeed.z= cosf(degToRad(windAngle)) * windSpeed; #endif - this->windSpeed.x = truncateDecimal(this->windSpeed.x,10); - this->windSpeed.y = truncateDecimal(this->windSpeed.y,10); - this->windSpeed.z = truncateDecimal(this->windSpeed.z,10); + this->windSpeed.x = truncateDecimal(this->windSpeed.x,6); + this->windSpeed.y = truncateDecimal(this->windSpeed.y,6); + this->windSpeed.z = truncateDecimal(this->windSpeed.z,6); } void UnitParticleSystem::saveGame(XmlNode *rootNode) { @@ -1326,9 +1326,9 @@ void UnitParticleSystem::saveGame(XmlNode *rootNode) { GameParticleSystem::saveGame(unitParticleSystemNode); // float radius; - unitParticleSystemNode->addAttribute("radius",doubleToStr(radius,10), mapTagReplacements); + unitParticleSystemNode->addAttribute("radius",floatToStr(radius,6), mapTagReplacements); // float minRadius; - unitParticleSystemNode->addAttribute("minRadius",doubleToStr(minRadius,10), mapTagReplacements); + unitParticleSystemNode->addAttribute("minRadius",floatToStr(minRadius,6), mapTagReplacements); // Vec3f windSpeed; unitParticleSystemNode->addAttribute("windSpeed",windSpeed.getString(), mapTagReplacements); // Vec3f cRotation; @@ -1340,9 +1340,9 @@ void UnitParticleSystem::saveGame(XmlNode *rootNode) { // bool energyUp; unitParticleSystemNode->addAttribute("energyUp",intToStr(energyUp), mapTagReplacements); // float startTime; - unitParticleSystemNode->addAttribute("startTime",doubleToStr(startTime,10), mapTagReplacements); + unitParticleSystemNode->addAttribute("startTime",floatToStr(startTime,6), mapTagReplacements); // float endTime; - unitParticleSystemNode->addAttribute("endTime",doubleToStr(endTime,10), mapTagReplacements); + unitParticleSystemNode->addAttribute("endTime",floatToStr(endTime,6), mapTagReplacements); // bool relative; unitParticleSystemNode->addAttribute("relative",intToStr(relative), mapTagReplacements); // bool relativeDirection; @@ -1352,13 +1352,13 @@ void UnitParticleSystem::saveGame(XmlNode *rootNode) { // Shape shape; unitParticleSystemNode->addAttribute("shape",intToStr(shape), mapTagReplacements); // float angle; - unitParticleSystemNode->addAttribute("angle",doubleToStr(angle,10), mapTagReplacements); + unitParticleSystemNode->addAttribute("angle",floatToStr(angle,6), mapTagReplacements); // float sizeNoEnergy; - unitParticleSystemNode->addAttribute("sizeNoEnergy",doubleToStr(sizeNoEnergy,10), mapTagReplacements); + unitParticleSystemNode->addAttribute("sizeNoEnergy",floatToStr(sizeNoEnergy,6), mapTagReplacements); // float gravity; - unitParticleSystemNode->addAttribute("gravity",doubleToStr(gravity,10), mapTagReplacements); + unitParticleSystemNode->addAttribute("gravity",floatToStr(gravity,6), mapTagReplacements); // float rotation; - unitParticleSystemNode->addAttribute("rotation",doubleToStr(rotation,10), mapTagReplacements); + unitParticleSystemNode->addAttribute("rotation",floatToStr(rotation,6), mapTagReplacements); // bool isVisibleAtNight; unitParticleSystemNode->addAttribute("isVisibleAtNight",intToStr(isVisibleAtNight), mapTagReplacements); // bool isVisibleAtDay; @@ -1374,7 +1374,7 @@ void UnitParticleSystem::saveGame(XmlNode *rootNode) { // int lifetime; unitParticleSystemNode->addAttribute("lifetime",intToStr(lifetime), mapTagReplacements); // float emissionRateFade; - unitParticleSystemNode->addAttribute("emissionRateFade",doubleToStr(emissionRateFade,10), mapTagReplacements); + unitParticleSystemNode->addAttribute("emissionRateFade",floatToStr(emissionRateFade,6), mapTagReplacements); // GameParticleSystem* parent; //if(parent != NULL) { // parent->saveGame(unitParticleSystemNode); @@ -1392,13 +1392,13 @@ void UnitParticleSystem::loadGame(const XmlNode *rootNode) { // float minRadius; minRadius = unitParticleSystemNode->getAttribute("minRadius")->getFloatValue(); // Vec3f windSpeed; - windSpeed = Vec3d::strToVec3(unitParticleSystemNode->getAttribute("windSpeed")->getValue()); + windSpeed = Vec3f::strToVec3(unitParticleSystemNode->getAttribute("windSpeed")->getValue()); // Vec3f cRotation; - windSpeed = Vec3d::strToVec3(unitParticleSystemNode->getAttribute("cRotation")->getValue()); + windSpeed = Vec3f::strToVec3(unitParticleSystemNode->getAttribute("cRotation")->getValue()); // Vec3f fixedAddition; - fixedAddition = Vec3d::strToVec3(unitParticleSystemNode->getAttribute("fixedAddition")->getValue()); + fixedAddition = Vec3f::strToVec3(unitParticleSystemNode->getAttribute("fixedAddition")->getValue()); // Vec3f oldPosition; - oldPosition = Vec3d::strToVec3(unitParticleSystemNode->getAttribute("oldPosition")->getValue()); + oldPosition = Vec3f::strToVec3(unitParticleSystemNode->getAttribute("oldPosition")->getValue()); // bool energyUp; energyUp = unitParticleSystemNode->getAttribute("energyUp")->getIntValue() != 0; // float startTime; @@ -1462,24 +1462,24 @@ string UnitParticleSystem::toString() const { string result = ParticleSystem::toString(); result += "\nUnitParticleSystem "; - result += "\nradius = " + doubleToStr(radius); - result += "\nminRadius = " + doubleToStr(minRadius); + result += "\nradius = " + floatToStr(radius); + result += "\nminRadius = " + floatToStr(minRadius); result += "\nwindSpeed = " + windSpeed.getString(); result += "\ncRotation = " + cRotation.getString(); result += "\nfixedAddition = " + fixedAddition.getString(); result += "\noldPosition = " + oldPosition.getString(); result += "\nenergyUp = " + intToStr(energyUp); - result += "\nstartTime = " + doubleToStr(startTime); - result += "\nendTime = " + doubleToStr(endTime); + result += "\nstartTime = " + floatToStr(startTime); + result += "\nendTime = " + floatToStr(endTime); result += "\nrelative = " + intToStr(relative); result += "\nrelativeDirection = " + intToStr(relativeDirection); result += "\nfixed = " + intToStr(fixed); result += "\nshape = " + intToStr(shape); - result += "\nangle = " + doubleToStr(angle); - result += "\nsizeNoEnergy = " + doubleToStr(sizeNoEnergy); - result += "\ngravity = " + doubleToStr(gravity); - result += "\nrotation = " + doubleToStr(rotation); + result += "\nangle = " + floatToStr(angle); + result += "\nsizeNoEnergy = " + floatToStr(sizeNoEnergy); + result += "\ngravity = " + floatToStr(gravity); + result += "\nrotation = " + floatToStr(rotation); result += "\nisVisibleAtNight = " + intToStr(isVisibleAtNight); result += "\nisVisibleAtDay = " + intToStr(isVisibleAtDay); result += "\nisDaylightAffected = " + intToStr(isDaylightAffected); @@ -1487,7 +1487,7 @@ string UnitParticleSystem::toString() const { result += "\nstaticParticleCount = " + intToStr(staticParticleCount); result += "\ndelay = " + intToStr(delay); result += "\nlifetime = " + intToStr(lifetime); - result += "\nemissionRateFade = " + doubleToStr(emissionRateFade); + result += "\nemissionRateFade = " + floatToStr(emissionRateFade); //GameParticleSystem* parent; return result; @@ -1514,33 +1514,33 @@ void RainParticleSystem::render(ParticleRenderer *pr, ModelRenderer *mr){ void RainParticleSystem::initParticle(Particle *p, int particleIndex){ ParticleSystem::initParticle(p, particleIndex); - double x= random.randRange(-radius, radius); - double y= random.randRange(-radius, radius); + float x= random.randRange(-radius, radius); + float y= random.randRange(-radius, radius); p->color= color; p->energy= 10000; - p->pos= Vec3d(pos.x + x, pos.y, pos.z + y); - p->pos.x = truncateDecimal(p->pos.x,10); - p->pos.y = truncateDecimal(p->pos.y,10); - p->pos.z = truncateDecimal(p->pos.z,10); + p->pos= Vec3f(pos.x + x, pos.y, pos.z + y); + p->pos.x = truncateDecimal(p->pos.x,6); + p->pos.y = truncateDecimal(p->pos.y,6); + p->pos.z = truncateDecimal(p->pos.z,6); p->lastPos= p->pos; - p->speed= Vec3d(random.randRange(-speed / 10, speed / 10), -speed, + p->speed= Vec3f(random.randRange(-speed / 10, speed / 10), -speed, random.randRange(-speed / 10, speed / 10)) + windSpeed; - p->speed.x = truncateDecimal(p->speed.x,10); - p->speed.y = truncateDecimal(p->speed.y,10); - p->speed.z = truncateDecimal(p->speed.z,10); + p->speed.x = truncateDecimal(p->speed.x,6); + p->speed.y = truncateDecimal(p->speed.y,6); + p->speed.z = truncateDecimal(p->speed.z,6); } bool RainParticleSystem::deathTest(Particle *p){ return p->pos.y < 0; } -void RainParticleSystem::setRadius(double radius) { +void RainParticleSystem::setRadius(float radius) { this->radius= radius; } -void RainParticleSystem::setWind(double windAngle, double windSpeed){ +void RainParticleSystem::setWind(float windAngle, float windSpeed){ #ifdef USE_STREFLOP this->windSpeed.x= streflop::sinf(static_cast(degToRad(windAngle)))*windSpeed; this->windSpeed.y= 0.0f; @@ -1551,9 +1551,9 @@ void RainParticleSystem::setWind(double windAngle, double windSpeed){ this->windSpeed.z= cosf(degToRad(windAngle)) * windSpeed; #endif - this->windSpeed.x = truncateDecimal(this->windSpeed.x,10); - this->windSpeed.y = truncateDecimal(this->windSpeed.y,10); - this->windSpeed.z = truncateDecimal(this->windSpeed.z,10); + this->windSpeed.x = truncateDecimal(this->windSpeed.x,6); + this->windSpeed.y = truncateDecimal(this->windSpeed.y,6); + this->windSpeed.z = truncateDecimal(this->windSpeed.z,6); } Checksum RainParticleSystem::getCRC() { @@ -1567,7 +1567,7 @@ string RainParticleSystem::toString() const { result += "\nRainParticleSystem "; result += "\nwindSpeed = " + windSpeed.getString(); - result += "\nradius = " + doubleToStr(radius); + result += "\nradius = " + floatToStr(radius); return result; } @@ -1591,35 +1591,35 @@ void SnowParticleSystem::initParticle(Particle *p, int particleIndex){ ParticleSystem::initParticle(p, particleIndex); - double x= random.randRange(-radius, radius); - double y= random.randRange(-radius, radius); + float x= random.randRange(-radius, radius); + float y= random.randRange(-radius, radius); p->color= color; p->energy= 10000; - p->pos= Vec3d(pos.x + x, pos.y, pos.z + y); - p->pos.x = truncateDecimal(p->pos.x,10); - p->pos.y = truncateDecimal(p->pos.y,10); - p->pos.z = truncateDecimal(p->pos.z,10); + p->pos= Vec3f(pos.x + x, pos.y, pos.z + y); + p->pos.x = truncateDecimal(p->pos.x,6); + p->pos.y = truncateDecimal(p->pos.y,6); + p->pos.z = truncateDecimal(p->pos.z,6); p->lastPos= p->pos; - p->speed= Vec3d(0.0f, -speed, 0.0f) + windSpeed; + p->speed= Vec3f(0.0f, -speed, 0.0f) + windSpeed; p->speed.x+= random.randRange(-0.005f, 0.005f); p->speed.y+= random.randRange(-0.005f, 0.005f); - p->speed.x = truncateDecimal(p->speed.x,10); - p->speed.y = truncateDecimal(p->speed.y,10); - p->speed.z = truncateDecimal(p->speed.z,10); + p->speed.x = truncateDecimal(p->speed.x,6); + p->speed.y = truncateDecimal(p->speed.y,6); + p->speed.z = truncateDecimal(p->speed.z,6); } bool SnowParticleSystem::deathTest(Particle *p){ return p->pos.y < 0; } -void SnowParticleSystem::setRadius(double radius){ +void SnowParticleSystem::setRadius(float radius){ this->radius= radius; } -void SnowParticleSystem::setWind(double windAngle, double windSpeed){ +void SnowParticleSystem::setWind(float windAngle, float windSpeed){ #ifdef USE_STREFLOP this->windSpeed.x= streflop::sinf(static_cast(degToRad(windAngle)))*windSpeed; this->windSpeed.y= 0.0f; @@ -1630,9 +1630,9 @@ void SnowParticleSystem::setWind(double windAngle, double windSpeed){ this->windSpeed.z= cosf(degToRad(windAngle)) * windSpeed; #endif - this->windSpeed.x = truncateDecimal(this->windSpeed.x,10); - this->windSpeed.y = truncateDecimal(this->windSpeed.y,10); - this->windSpeed.z = truncateDecimal(this->windSpeed.z,10); + this->windSpeed.x = truncateDecimal(this->windSpeed.x,6); + this->windSpeed.y = truncateDecimal(this->windSpeed.y,6); + this->windSpeed.z = truncateDecimal(this->windSpeed.z,6); } @@ -1647,7 +1647,7 @@ string SnowParticleSystem::toString() const { result += "\nSnowParticleSystem "; result += "\nwindSpeed = " + windSpeed.getString(); - result += "\nradius = " + doubleToStr(radius); + result += "\nradius = " + floatToStr(radius); return result; } @@ -1670,9 +1670,9 @@ void AttackParticleSystem::saveGame(XmlNode *rootNode) { GameParticleSystem::saveGame(attackParticleSystemNode); // float sizeNoEnergy; - attackParticleSystemNode->addAttribute("sizeNoEnergy",doubleToStr(sizeNoEnergy,10), mapTagReplacements); + attackParticleSystemNode->addAttribute("sizeNoEnergy",floatToStr(sizeNoEnergy,6), mapTagReplacements); // float gravity; - attackParticleSystemNode->addAttribute("gravity",doubleToStr(gravity,10), mapTagReplacements); + attackParticleSystemNode->addAttribute("gravity",floatToStr(gravity,6), mapTagReplacements); } void AttackParticleSystem::loadGame(const XmlNode *rootNode) { @@ -1696,8 +1696,8 @@ string AttackParticleSystem::toString() const { string result = ParticleSystem::toString(); result += "\nAttackParticleSystem "; - result += "\nsizeNoEnergy = " + doubleToStr(sizeNoEnergy); - result += "\ngravity = " + doubleToStr(gravity); + result += "\nsizeNoEnergy = " + floatToStr(sizeNoEnergy); + result += "\ngravity = " + floatToStr(gravity); return result; } @@ -1745,24 +1745,24 @@ void ProjectileParticleSystem::update(){ if(state == sPlay){ lastPos = pos; - flatPos += zVector * truncateDecimal(trajectorySpeed,10); - flatPos.x = truncateDecimal(flatPos.x,10); - flatPos.y = truncateDecimal(flatPos.y,10); - flatPos.z = truncateDecimal(flatPos.z,10); + flatPos += zVector * truncateDecimal(trajectorySpeed,6); + flatPos.x = truncateDecimal(flatPos.x,6); + flatPos.y = truncateDecimal(flatPos.y,6); + flatPos.z = truncateDecimal(flatPos.z,6); - Vec3d targetVector = endPos - startPos; - targetVector.x = truncateDecimal(targetVector.x,10); - targetVector.y = truncateDecimal(targetVector.y,10); - targetVector.z = truncateDecimal(targetVector.z,10); + Vec3f targetVector = endPos - startPos; + targetVector.x = truncateDecimal(targetVector.x,6); + targetVector.y = truncateDecimal(targetVector.y,6); + targetVector.z = truncateDecimal(targetVector.z,6); - Vec3d currentVector = flatPos - startPos; - currentVector.x = truncateDecimal(currentVector.x,10); - currentVector.y = truncateDecimal(currentVector.y,10); - currentVector.z = truncateDecimal(currentVector.z,10); + Vec3f currentVector = flatPos - startPos; + currentVector.x = truncateDecimal(currentVector.x,6); + currentVector.y = truncateDecimal(currentVector.y,6); + currentVector.z = truncateDecimal(currentVector.z,6); // ratio - double relative= clamp(currentVector.length() / targetVector.length(), 0.0f, 1.0f); - relative = truncateDecimal(relative,10); + float relative= clamp(currentVector.length() / targetVector.length(), 0.0f, 1.0f); + relative = truncateDecimal(relative,6); //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); @@ -1773,7 +1773,7 @@ void ProjectileParticleSystem::update(){ //#endif //printf("#a currentVector.length() = %f, targetVector.length() = %f, relative = %f, absolute = %f, trajectorySpeed = %f\n",currentVector.length(),targetVector.length(),relative,absolute,trajectorySpeed); - double absolute = relative; + float absolute = relative; setTween(relative,absolute); @@ -1785,12 +1785,12 @@ void ProjectileParticleSystem::update(){ break; case tParabolic: { - double scaledT = truncateDecimal(2.0f * (relative - 0.5f),10); - double paraboleY = truncateDecimal((1.0f - scaledT * scaledT) * trajectoryScale,10); + float scaledT = truncateDecimal(2.0f * (relative - 0.5f),6); + float paraboleY = truncateDecimal((1.0f - scaledT * scaledT) * trajectoryScale,6); pos= flatPos; pos.y += paraboleY; - pos.y = truncateDecimal(pos.y,10); + pos.y = truncateDecimal(pos.y,6); } break; @@ -1803,9 +1803,9 @@ void ProjectileParticleSystem::update(){ pos+= xVector * cos(relative * trajectoryFrequency * targetVector.length()) * trajectoryScale; pos+= yVector * sin(relative * trajectoryFrequency * targetVector.length()) * trajectoryScale; #endif - pos.x = truncateDecimal(pos.x,10); - pos.y = truncateDecimal(pos.y,10); - pos.z = truncateDecimal(pos.z,10); + pos.x = truncateDecimal(pos.x,6); + pos.y = truncateDecimal(pos.y,6); + pos.z = truncateDecimal(pos.z,6); } break; @@ -1816,16 +1816,16 @@ void ProjectileParticleSystem::update(){ direction= pos - lastPos; direction.normalize(); - direction.x = truncateDecimal(direction.x,10); - direction.y = truncateDecimal(direction.y,10); - direction.z = truncateDecimal(direction.z,10); + direction.x = truncateDecimal(direction.x,6); + direction.y = truncateDecimal(direction.y,6); + direction.z = truncateDecimal(direction.z,6); // trigger update of child particles positionChildren(); rotateChildren(); //arrive destination - arriveDestinationDistance = truncateDecimal(flatPos.dist(endPos),10); + arriveDestinationDistance = truncateDecimal(flatPos.dist(endPos),6); if(arriveDestinationDistance < 0.5f) { fade(); model= NULL; @@ -1849,11 +1849,11 @@ void ProjectileParticleSystem::update(){ void ProjectileParticleSystem::rotateChildren() { //### only on horizontal plane :( #ifdef USE_STREFLOP - double rotation = truncateDecimal(streflop::atan2(static_cast(direction.x), static_cast(direction.z)),10); + float rotation = truncateDecimal(streflop::atan2(static_cast(direction.x), static_cast(direction.z)),6); #else - double rotation = truncateDecimal(atan2(direction.x, direction.z),10); + float rotation = truncateDecimal(atan2(direction.x, direction.z),6); #endif - rotation = truncateDecimal(radToDeg(rotation),10); + rotation = truncateDecimal(radToDeg(rotation),6); for(Children::iterator it = children.begin(); it != children.end(); ++it) (*it)->setRotation(rotation); } @@ -1862,88 +1862,88 @@ void ProjectileParticleSystem::initParticle(Particle *p, int particleIndex){ ParticleSystem::initParticle(p, particleIndex); - double t= static_cast (particleIndex) / emissionRate; - t = truncateDecimal(t,10); + float t= static_cast (particleIndex) / emissionRate; + t = truncateDecimal(t,6); p->pos= pos + (lastPos - pos) * t; - p->pos.x = truncateDecimal(p->pos.x,10); - p->pos.y = truncateDecimal(p->pos.y,10); - p->pos.z = truncateDecimal(p->pos.z,10); + p->pos.x = truncateDecimal(p->pos.x,6); + p->pos.y = truncateDecimal(p->pos.y,6); + p->pos.z = truncateDecimal(p->pos.z,6); p->lastPos= lastPos; - p->speed= Vec3d(random.randRange(-0.1f, 0.1f), random.randRange(-0.1f, 0.1f), + p->speed= Vec3f(random.randRange(-0.1f, 0.1f), random.randRange(-0.1f, 0.1f), random.randRange(-0.1f, 0.1f)) * speed; - p->speed.x = truncateDecimal(p->speed.x,10); - p->speed.y = truncateDecimal(p->speed.y,10); - p->speed.z = truncateDecimal(p->speed.z,10); + p->speed.x = truncateDecimal(p->speed.x,6); + p->speed.y = truncateDecimal(p->speed.y,6); + p->speed.z = truncateDecimal(p->speed.z,6); - p->accel= Vec3d(0.0f, -gravity, 0.0f); - p->accel.x = truncateDecimal(p->accel.x,10); - p->accel.y = truncateDecimal(p->accel.y,10); - p->accel.z = truncateDecimal(p->accel.z,10); + p->accel= Vec3f(0.0f, -gravity, 0.0f); + p->accel.x = truncateDecimal(p->accel.x,6); + p->accel.y = truncateDecimal(p->accel.y,6); + p->accel.z = truncateDecimal(p->accel.z,6); updateParticle(p); } void ProjectileParticleSystem::updateParticle(Particle *p){ - double energyRatio= clamp(static_cast (p->energy) / maxParticleEnergy, 0.f, 1.f); - energyRatio = truncateDecimal(energyRatio,10); + float energyRatio= clamp(static_cast (p->energy) / maxParticleEnergy, 0.f, 1.f); + energyRatio = truncateDecimal(energyRatio,6); p->lastPos += p->speed; - p->lastPos.x = truncateDecimal(p->lastPos.x,10); - p->lastPos.y = truncateDecimal(p->lastPos.y,10); - p->lastPos.z = truncateDecimal(p->lastPos.z,10); + p->lastPos.x = truncateDecimal(p->lastPos.x,6); + p->lastPos.y = truncateDecimal(p->lastPos.y,6); + p->lastPos.z = truncateDecimal(p->lastPos.z,6); p->pos += p->speed; - p->pos.x = truncateDecimal(p->pos.x,10); - p->pos.y = truncateDecimal(p->pos.y,10); - p->pos.z = truncateDecimal(p->pos.z,10); + p->pos.x = truncateDecimal(p->pos.x,6); + p->pos.y = truncateDecimal(p->pos.y,6); + p->pos.z = truncateDecimal(p->pos.z,6); p->speed += p->accel; - p->speed.x = truncateDecimal(p->speed.x,10); - p->speed.y = truncateDecimal(p->speed.y,10); - p->speed.z = truncateDecimal(p->speed.z,10); + p->speed.x = truncateDecimal(p->speed.x,6); + p->speed.y = truncateDecimal(p->speed.y,6); + p->speed.z = truncateDecimal(p->speed.z,6); p->color= color * energyRatio + colorNoEnergy * (1.0f - energyRatio); p->size = particleSize * energyRatio + sizeNoEnergy * (1.0f - energyRatio); - p->size = truncateDecimal(p->size,10); + p->size = truncateDecimal(p->size,6); p->energy--; } -void ProjectileParticleSystem::setPath(Vec3d startPos, Vec3d endPos){ +void ProjectileParticleSystem::setPath(Vec3f startPos, Vec3f endPos) { //compute axis zVector= endPos - startPos; - zVector.x = truncateDecimal(zVector.x,10); - zVector.y = truncateDecimal(zVector.y,10); - zVector.z = truncateDecimal(zVector.z,10); + zVector.x = truncateDecimal(zVector.x,6); + zVector.y = truncateDecimal(zVector.y,6); + zVector.z = truncateDecimal(zVector.z,6); zVector.normalize(); - zVector.x = truncateDecimal(zVector.x,10); - zVector.y = truncateDecimal(zVector.y,10); - zVector.z = truncateDecimal(zVector.z,10); + zVector.x = truncateDecimal(zVector.x,6); + zVector.y = truncateDecimal(zVector.y,6); + zVector.z = truncateDecimal(zVector.z,6); - yVector= Vec3d(0.0f, 1.0f, 0.0f); + yVector= Vec3f(0.0f, 1.0f, 0.0f); xVector= zVector.cross(yVector); - xVector.x = truncateDecimal(xVector.x,10); - xVector.y = truncateDecimal(xVector.y,10); - xVector.z = truncateDecimal(xVector.z,10); + xVector.x = truncateDecimal(xVector.x,6); + xVector.y = truncateDecimal(xVector.y,6); + xVector.z = truncateDecimal(xVector.z,6); //apply offset startPos += xVector * offset.x; - startPos.x = truncateDecimal(startPos.x,10); - startPos.y = truncateDecimal(startPos.y,10); - startPos.z = truncateDecimal(startPos.z,10); + startPos.x = truncateDecimal(startPos.x,6); + startPos.y = truncateDecimal(startPos.y,6); + startPos.z = truncateDecimal(startPos.z,6); startPos+= yVector * offset.y; - startPos.x = truncateDecimal(startPos.x,10); - startPos.y = truncateDecimal(startPos.y,10); - startPos.z = truncateDecimal(startPos.z,10); + startPos.x = truncateDecimal(startPos.x,6); + startPos.y = truncateDecimal(startPos.y,6); + startPos.z = truncateDecimal(startPos.z,6); startPos+= zVector * offset.z; - startPos.x = truncateDecimal(startPos.x,10); - startPos.y = truncateDecimal(startPos.y,10); - startPos.z = truncateDecimal(startPos.z,10); + startPos.x = truncateDecimal(startPos.x,6); + startPos.y = truncateDecimal(startPos.y,6); + startPos.z = truncateDecimal(startPos.z,6); pos= startPos; lastPos= startPos; @@ -1951,20 +1951,20 @@ void ProjectileParticleSystem::setPath(Vec3d startPos, Vec3d endPos){ //recompute axis zVector= endPos - startPos; - zVector.x = truncateDecimal(zVector.x,10); - zVector.y = truncateDecimal(zVector.y,10); - zVector.z = truncateDecimal(zVector.z,10); + zVector.x = truncateDecimal(zVector.x,6); + zVector.y = truncateDecimal(zVector.y,6); + zVector.z = truncateDecimal(zVector.z,6); zVector.normalize(); - zVector.x = truncateDecimal(zVector.x,10); - zVector.y = truncateDecimal(zVector.y,10); - zVector.z = truncateDecimal(zVector.z,10); + zVector.x = truncateDecimal(zVector.x,6); + zVector.y = truncateDecimal(zVector.y,6); + zVector.z = truncateDecimal(zVector.z,6); - yVector= Vec3d(0.0f, 1.0f, 0.0f); + yVector= Vec3f(0.0f, 1.0f, 0.0f); xVector= zVector.cross(yVector); - xVector.x = truncateDecimal(xVector.x,10); - xVector.y = truncateDecimal(xVector.y,10); - xVector.z = truncateDecimal(xVector.z,10); + xVector.x = truncateDecimal(xVector.x,6); + xVector.y = truncateDecimal(xVector.y,6); + xVector.z = truncateDecimal(xVector.z,6); // set members this->startPos= startPos; @@ -1972,14 +1972,14 @@ void ProjectileParticleSystem::setPath(Vec3d startPos, Vec3d endPos){ // direction direction = (endPos - lastPos); - direction.x = truncateDecimal(direction.x,10); - direction.y = truncateDecimal(direction.y,10); - direction.z = truncateDecimal(direction.z,10); + direction.x = truncateDecimal(direction.x,6); + direction.y = truncateDecimal(direction.y,6); + direction.z = truncateDecimal(direction.z,6); direction.normalize(); - direction.x = truncateDecimal(direction.x,10); - direction.y = truncateDecimal(direction.y,10); - direction.z = truncateDecimal(direction.z,10); + direction.x = truncateDecimal(direction.x,6); + direction.y = truncateDecimal(direction.y,6); + direction.z = truncateDecimal(direction.z,6); rotateChildren(); } @@ -2027,12 +2027,12 @@ void ProjectileParticleSystem::saveGame(XmlNode *rootNode) { // Trajectory trajectory; projectileParticleSystemNode->addAttribute("trajectory",intToStr(trajectory), mapTagReplacements); // float trajectorySpeed; - projectileParticleSystemNode->addAttribute("trajectorySpeed",doubleToStr(trajectorySpeed,10), mapTagReplacements); + projectileParticleSystemNode->addAttribute("trajectorySpeed",floatToStr(trajectorySpeed,6), mapTagReplacements); // //parabolic // float trajectoryScale; - projectileParticleSystemNode->addAttribute("trajectoryScale",doubleToStr(trajectoryScale,10), mapTagReplacements); + projectileParticleSystemNode->addAttribute("trajectoryScale",floatToStr(trajectoryScale,6), mapTagReplacements); // float trajectoryFrequency; - projectileParticleSystemNode->addAttribute("trajectoryFrequency",doubleToStr(trajectoryFrequency,10), mapTagReplacements); + projectileParticleSystemNode->addAttribute("trajectoryFrequency",floatToStr(trajectoryFrequency,6), mapTagReplacements); } void ProjectileParticleSystem::loadGame(const XmlNode *rootNode) { @@ -2051,20 +2051,20 @@ void ProjectileParticleSystem::loadGame(const XmlNode *rootNode) { nextParticleSystem->loadGame(splashParticleSystemNode); } // Vec3f lastPos; - lastPos = Vec3d::strToVec3(projectileParticleSystemNode->getAttribute("lastPos")->getValue()); + lastPos = Vec3f::strToVec3(projectileParticleSystemNode->getAttribute("lastPos")->getValue()); // Vec3f startPos; - startPos = Vec3d::strToVec3(projectileParticleSystemNode->getAttribute("startPos")->getValue()); + startPos = Vec3f::strToVec3(projectileParticleSystemNode->getAttribute("startPos")->getValue()); // Vec3f endPos; - endPos = Vec3d::strToVec3(projectileParticleSystemNode->getAttribute("endPos")->getValue()); + endPos = Vec3f::strToVec3(projectileParticleSystemNode->getAttribute("endPos")->getValue()); // Vec3f flatPos; - flatPos = Vec3d::strToVec3(projectileParticleSystemNode->getAttribute("flatPos")->getValue()); + flatPos = Vec3f::strToVec3(projectileParticleSystemNode->getAttribute("flatPos")->getValue()); // // Vec3f xVector; - xVector = Vec3d::strToVec3(projectileParticleSystemNode->getAttribute("xVector")->getValue()); + xVector = Vec3f::strToVec3(projectileParticleSystemNode->getAttribute("xVector")->getValue()); // Vec3f yVector; - yVector = Vec3d::strToVec3(projectileParticleSystemNode->getAttribute("yVector")->getValue()); + yVector = Vec3f::strToVec3(projectileParticleSystemNode->getAttribute("yVector")->getValue()); // Vec3f zVector; - zVector = Vec3d::strToVec3(projectileParticleSystemNode->getAttribute("zVector")->getValue()); + zVector = Vec3f::strToVec3(projectileParticleSystemNode->getAttribute("zVector")->getValue()); // Trajectory trajectory; trajectory = static_cast(projectileParticleSystemNode->getAttribute("trajectory")->getIntValue()); // float trajectorySpeed; @@ -2100,11 +2100,11 @@ string ProjectileParticleSystem::toString() const { result += "\nzVector = " + zVector.getString(); result += "\ntrajectory = " + intToStr(trajectory); - result += "\ntrajectorySpeed = " + doubleToStr(trajectorySpeed); - result += "\ntrajectoryScale = " + doubleToStr(trajectoryScale); - result += "\ntrajectoryFrequency = " + doubleToStr(trajectoryFrequency); + result += "\ntrajectorySpeed = " + floatToStr(trajectorySpeed); + result += "\ntrajectoryScale = " + floatToStr(trajectoryScale); + result += "\ntrajectoryFrequency = " + floatToStr(trajectoryFrequency); - result += "\narriveDestinationDistance = " + doubleToStr(arriveDestinationDistance); + result += "\narriveDestinationDistance = " + floatToStr(arriveDestinationDistance); return result; } @@ -2145,10 +2145,10 @@ void SplashParticleSystem::update() { ParticleSystem::update(); if(state != sPause) { emissionRate -= emissionRateFade; - emissionRate = truncateDecimal(emissionRate,10); + emissionRate = truncateDecimal(emissionRate,6); - double t = 1.0f - ((emissionRate + startEmissionRate) / (startEmissionRate * 2.0f)); - t = truncateDecimal(t,10); + float t = 1.0f - ((emissionRate + startEmissionRate) / (startEmissionRate * 2.0f)); + t = truncateDecimal(t,6); t= clamp(t, 0.0f, 1.0f); setTween(t,t); @@ -2166,40 +2166,40 @@ void SplashParticleSystem::initParticle(Particle *p, int particleIndex){ p->size= particleSize; p->color= color; - p->speed= Vec3d(horizontalSpreadA * random.randRange(-1.0f, 1.0f) + horizontalSpreadB, verticalSpreadA + p->speed= Vec3f(horizontalSpreadA * random.randRange(-1.0f, 1.0f) + horizontalSpreadB, verticalSpreadA * random.randRange(-1.0f, 1.0f) + verticalSpreadB, horizontalSpreadA * random.randRange(-1.0f, 1.0f) + horizontalSpreadB); p->speed.normalize(); p->speed= p->speed * speed; - p->speed.x = truncateDecimal(p->speed.x,10); - p->speed.y = truncateDecimal(p->speed.y,10); - p->speed.z = truncateDecimal(p->speed.z,10); + p->speed.x = truncateDecimal(p->speed.x,6); + p->speed.y = truncateDecimal(p->speed.y,6); + p->speed.z = truncateDecimal(p->speed.z,6); - p->accel= Vec3d(0.0f, -gravity, 0.0f); - p->accel.x = truncateDecimal(p->accel.x,10); - p->accel.y = truncateDecimal(p->accel.y,10); - p->accel.z = truncateDecimal(p->accel.z,10); + p->accel= Vec3f(0.0f, -gravity, 0.0f); + p->accel.x = truncateDecimal(p->accel.x,6); + p->accel.y = truncateDecimal(p->accel.y,6); + p->accel.z = truncateDecimal(p->accel.z,6); } void SplashParticleSystem::updateParticle(Particle *p){ - double energyRatio= clamp(static_cast (p->energy) / maxParticleEnergy, 0.f, 1.f); + float energyRatio= clamp(static_cast (p->energy) / maxParticleEnergy, 0.f, 1.f); p->lastPos= p->pos; p->pos= p->pos + p->speed; - p->pos.x = truncateDecimal(p->pos.x,10); - p->pos.y = truncateDecimal(p->pos.y,10); - p->pos.z = truncateDecimal(p->pos.z,10); + p->pos.x = truncateDecimal(p->pos.x,6); + p->pos.y = truncateDecimal(p->pos.y,6); + p->pos.z = truncateDecimal(p->pos.z,6); p->speed= p->speed + p->accel; - p->speed.x = truncateDecimal(p->speed.x,10); - p->speed.y = truncateDecimal(p->speed.y,10); - p->speed.z = truncateDecimal(p->speed.z,10); + p->speed.x = truncateDecimal(p->speed.x,6); + p->speed.y = truncateDecimal(p->speed.y,6); + p->speed.z = truncateDecimal(p->speed.z,6); p->energy--; p->color= color * energyRatio + colorNoEnergy * (1.0f - energyRatio); p->size= particleSize * energyRatio + sizeNoEnergy * (1.0f - energyRatio); - p->size = truncateDecimal(p->size,10); + p->size = truncateDecimal(p->size,6); } void SplashParticleSystem::saveGame(XmlNode *rootNode) { @@ -2214,18 +2214,18 @@ void SplashParticleSystem::saveGame(XmlNode *rootNode) { } // float emissionRateFade; - splashParticleSystemNode->addAttribute("emissionRateFade",doubleToStr(emissionRateFade,10), mapTagReplacements); + splashParticleSystemNode->addAttribute("emissionRateFade",floatToStr(emissionRateFade,6), mapTagReplacements); // float verticalSpreadA; - splashParticleSystemNode->addAttribute("verticalSpreadA",doubleToStr(verticalSpreadA,10), mapTagReplacements); + splashParticleSystemNode->addAttribute("verticalSpreadA",floatToStr(verticalSpreadA,6), mapTagReplacements); // float verticalSpreadB; - splashParticleSystemNode->addAttribute("verticalSpreadB",doubleToStr(verticalSpreadB,10), mapTagReplacements); + splashParticleSystemNode->addAttribute("verticalSpreadB",floatToStr(verticalSpreadB,6), mapTagReplacements); // float horizontalSpreadA; - splashParticleSystemNode->addAttribute("horizontalSpreadA",doubleToStr(horizontalSpreadA,10), mapTagReplacements); + splashParticleSystemNode->addAttribute("horizontalSpreadA",floatToStr(horizontalSpreadA,6), mapTagReplacements); // float horizontalSpreadB; - splashParticleSystemNode->addAttribute("horizontalSpreadB",doubleToStr(horizontalSpreadB,10), mapTagReplacements); + splashParticleSystemNode->addAttribute("horizontalSpreadB",floatToStr(horizontalSpreadB,6), mapTagReplacements); // // float startEmissionRate; - splashParticleSystemNode->addAttribute("startEmissionRate",doubleToStr(startEmissionRate,10), mapTagReplacements); + splashParticleSystemNode->addAttribute("startEmissionRate",floatToStr(startEmissionRate,6), mapTagReplacements); } void SplashParticleSystem::loadGame(const XmlNode *rootNode) { @@ -2273,12 +2273,12 @@ string SplashParticleSystem::toString() const { result += "\nprevParticleSystem = NOT NULL\n"; } - result += "\nemissionRateFade = " + doubleToStr(emissionRateFade); - result += "\nverticalSpreadA = " + doubleToStr(verticalSpreadA); - result += "\nverticalSpreadB = " + doubleToStr(verticalSpreadB); - result += "\nhorizontalSpreadA = " + doubleToStr(horizontalSpreadA); - result += "\nhorizontalSpreadB = " + doubleToStr(horizontalSpreadB); - result += "\nstartEmissionRate = " + doubleToStr(startEmissionRate); + result += "\nemissionRateFade = " + floatToStr(emissionRateFade); + result += "\nverticalSpreadA = " + floatToStr(verticalSpreadA); + result += "\nverticalSpreadB = " + floatToStr(verticalSpreadB); + result += "\nhorizontalSpreadA = " + floatToStr(horizontalSpreadA); + result += "\nhorizontalSpreadB = " + floatToStr(horizontalSpreadB); + result += "\nstartEmissionRate = " + floatToStr(startEmissionRate); return result; } diff --git a/source/shared_lib/sources/util/properties.cpp b/source/shared_lib/sources/util/properties.cpp index b67622f2..04651fa4 100644 --- a/source/shared_lib/sources/util/properties.cpp +++ b/source/shared_lib/sources/util/properties.cpp @@ -519,7 +519,7 @@ void Properties::setBool(const string &key, bool value){ } void Properties::setFloat(const string &key, float value){ - setString(key, floatToStr(value,10)); + setString(key, floatToStr(value,6)); } void Properties::setString(const string &key, const string &value){ diff --git a/source/shared_lib/sources/util/randomgen.cpp b/source/shared_lib/sources/util/randomgen.cpp index dc41e99a..715b36b7 100644 --- a/source/shared_lib/sources/util/randomgen.cpp +++ b/source/shared_lib/sources/util/randomgen.cpp @@ -81,7 +81,7 @@ int RandomGen::randRange(int min, int max,string lastCaller) { int diff= max-min; double numerator = static_cast(diff + 1) * static_cast(RandomGen::rand(lastCaller)); - int res= min + static_cast(truncateDecimal(numerator / static_cast(m),10)); + int res= min + static_cast(truncateDecimal(numerator / static_cast(m),6)); if(res < min || res > max) { char szBuf[8096]=""; snprintf(szBuf,8096,"In [%s::%s Line: %d] res < min || res > max, min = %d, max = %d, res = %d",__FILE__,__FUNCTION__,__LINE__,min,max,res); @@ -102,7 +102,7 @@ double RandomGen::randRange(double min, double max,string lastCaller) { double rand01 = static_cast(RandomGen::rand(lastCaller)) / (m-1); double res= min + (max - min) * rand01; - res = truncateDecimal(res,10); + res = truncateDecimal(res,6); if(res < min || res > max) { char szBuf[8096]="";