diff --git a/source/glest_game/game/game.cpp b/source/glest_game/game/game.cpp index ec4db5102..7ca561229 100644 --- a/source/glest_game/game/game.cpp +++ b/source/glest_game/game/game.cpp @@ -870,19 +870,21 @@ void Game::init(bool initForPreviewOnly) { console.clearStoredLines(); } - gameCamera.init(map->getW(), map->getH()); + if(this->loadGameNode == NULL) { + gameCamera.init(map->getW(), map->getH()); - // camera default height calculation - if(map->getCameraHeight()>0 && gameCamera.getCalculatedDefault()getCameraHeight()){ - gameCamera.setCalculatedDefault(map->getCameraHeight()); - } - else if(gameCamera.getCalculatedDefault()getMaxMapHeight()+13.0f){ - gameCamera.setCalculatedDefault(map->getMaxMapHeight()+13.0f); - } + // camera default height calculation + if(map->getCameraHeight()>0 && gameCamera.getCalculatedDefault()getCameraHeight()){ + gameCamera.setCalculatedDefault(map->getCameraHeight()); + } + else if(gameCamera.getCalculatedDefault()getMaxMapHeight()+13.0f){ + gameCamera.setCalculatedDefault(map->getMaxMapHeight()+13.0f); + } - if(world.getThisFaction() != NULL) { - const Vec2i &v= map->getStartLocation(world.getThisFaction()->getStartLocationIndex()); - gameCamera.setPos(Vec2f(v.x, v.y)); + if(world.getThisFaction() != NULL) { + const Vec2i &v= map->getStartLocation(world.getThisFaction()->getStartLocationIndex()); + gameCamera.setPos(Vec2f(v.x, v.y)); + } } if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); @@ -1488,8 +1490,10 @@ void Game::render() { if(isFirstRender == true) { isFirstRender = false; - gameCamera.resetPosition(); - this->restoreToStartXY(); + if(this->loadGameNode == NULL) { + gameCamera.resetPosition(); + this->restoreToStartXY(); + } } canRender(); @@ -3615,6 +3619,7 @@ void Game::loadGame(string name,Program *programPtr,bool isMasterserverMode) { Game *newGame = new Game(programPtr, &newGameSettings, isMasterserverMode); newGame->loadGameNode = gameNode; + newGame->gameCamera.loadGame(gameNode); const XmlNode *worldNode = gameNode->getChild("World"); newGame->world.loadGame(worldNode); diff --git a/source/glest_game/game/game_camera.cpp b/source/glest_game/game/game_camera.cpp index 5fb14e957..e93841a22 100644 --- a/source/glest_game/game/game_camera.cpp +++ b/source/glest_game/game/game_camera.cpp @@ -466,4 +466,62 @@ void GameCamera::saveGame(XmlNode *rootNode) { // int MaxVisibleQuadItemCache; gamecameraNode->addAttribute("MaxVisibleQuadItemCache",intToStr(MaxVisibleQuadItemCache), mapTagReplacements); } + +void GameCamera::loadGame(const XmlNode *rootNode) { + const XmlNode *gamecameraNode = rootNode->getChild("GameCamera"); + + //firstTime = timeflowNode->getAttribute("firstTime")->getFloatValue(); + + // Vec3f pos; + pos = Vec3f::strToVec3(gamecameraNode->getAttribute("pos")->getValue()); + // Vec3f destPos; + destPos = Vec3f::strToVec3(gamecameraNode->getAttribute("destPos")->getValue()); + // + // float hAng; //YZ plane positive -Z axis + hAng = gamecameraNode->getAttribute("hAng")->getFloatValue(); + // float vAng; //XZ plane positive +Z axis + vAng = gamecameraNode->getAttribute("vAng")->getFloatValue(); + // float lastHAng; + lastHAng = gamecameraNode->getAttribute("lastHAng")->getFloatValue(); + + // float lastVAng; + lastVAng = gamecameraNode->getAttribute("lastVAng")->getFloatValue(); + // Vec2f destAng; + destAng = Vec2f::strToVec2(gamecameraNode->getAttribute("destAng")->getValue()); + // float rotate; + rotate = gamecameraNode->getAttribute("rotate")->getFloatValue(); + // Vec3f move; + move = Vec3f::strToVec3(gamecameraNode->getAttribute("move")->getValue()); + // State state; + state = static_cast(gamecameraNode->getAttribute("state")->getIntValue()); + // int limitX; + limitX = gamecameraNode->getAttribute("limitX")->getIntValue(); + // int limitY; + limitY = gamecameraNode->getAttribute("limitY")->getIntValue(); + // //config + // float speed; + speed = gamecameraNode->getAttribute("speed")->getFloatValue(); + // bool clampBounds; + clampBounds = gamecameraNode->getAttribute("clampBounds")->getIntValue(); + // //float maxRenderDistance; + // float maxHeight; + maxHeight = gamecameraNode->getAttribute("maxHeight")->getFloatValue(); + // float minHeight; + minHeight = gamecameraNode->getAttribute("minHeight")->getFloatValue(); + // //float maxCameraDist; + // //float minCameraDist; + // float minVAng; + minVAng = gamecameraNode->getAttribute("minVAng")->getFloatValue(); + // float maxVAng; + maxVAng = gamecameraNode->getAttribute("maxVAng")->getFloatValue(); + // float fov; + fov = gamecameraNode->getAttribute("fov")->getFloatValue(); + // float calculatedDefault; + calculatedDefault = gamecameraNode->getAttribute("calculatedDefault")->getFloatValue(); + // std::map > > cacheVisibleQuad; + // int MaxVisibleQuadItemCache; + MaxVisibleQuadItemCache = gamecameraNode->getAttribute("MaxVisibleQuadItemCache")->getIntValue(); + +} + }}//end namespace diff --git a/source/glest_game/game/game_camera.h b/source/glest_game/game/game_camera.h index 787d5df80..0ecb41e09 100644 --- a/source/glest_game/game/game_camera.h +++ b/source/glest_game/game/game_camera.h @@ -144,6 +144,7 @@ public: void setMaxVAng(float value) { maxVAng = value; } void saveGame(XmlNode *rootNode); + void loadGame(const XmlNode *rootNode); private: void clampPosXYZ(float x1, float x2, float y1, float y2, float z1, float z2); diff --git a/source/glest_game/world/time_flow.cpp b/source/glest_game/world/time_flow.cpp index 41b62d618..ccb8316c0 100644 --- a/source/glest_game/world/time_flow.cpp +++ b/source/glest_game/world/time_flow.cpp @@ -145,7 +145,7 @@ void TimeFlow::loadGame(const XmlNode *rootNode) { const XmlNode *timeflowNode = rootNode->getChild("TimeFlow"); firstTime = timeflowNode->getAttribute("firstTime")->getFloatValue(); - time = timeflowNode->getAttribute("time")->getIntValue(); + time = timeflowNode->getAttribute("time")->getFloatValue(); lastTime = timeflowNode->getAttribute("lastTime")->getFloatValue(); timeInc = timeflowNode->getAttribute("timeInc")->getFloatValue(); } diff --git a/source/shared_lib/include/graphics/vec.h b/source/shared_lib/include/graphics/vec.h index 02b4930ef..ebf3d81fb 100644 --- a/source/shared_lib/include/graphics/vec.h +++ b/source/shared_lib/include/graphics/vec.h @@ -451,6 +451,42 @@ public: return result; } + // playerColor="x [1] y [0] z [0]" + static inline Vec3 strToVec3(std::string value) { + Vec3 result; + + std::vector tokens = TokenizeString(value,"["); + //for(unsigned int i = 0; i < tokens.size(); ++i) { + //printf("#1 Vec2T i = %d [%s]\n",i,tokens[i].c_str()); + //} + if(tokens.size() == 4) { + std::vector tokens2 = TokenizeString(tokens[1],"]"); + //for(unsigned int i = 0; i < tokens2.size(); ++i) { + //printf("#2 Vec2T i = %d [%s]\n",i,tokens2[i].c_str()); + //} + std::vector tokens3 = TokenizeString(tokens[2],"]"); + //for(unsigned int i = 0; i < tokens3.size(); ++i) { + //printf("#3 Vec2T i = %d [%s]\n",i,tokens3[i].c_str()); + //} + + std::vector tokens4 = TokenizeString(tokens[3],"]"); + //for(unsigned int i = 0; i < tokens3.size(); ++i) { + //printf("#3 Vec2T i = %d [%s]\n",i,tokens3[i].c_str()); + //} + + if(tokens2.size() == 2 && tokens3.size() == 2 && tokens4.size() == 2) { + result.x = (T)strToType(tokens2[0]); + result.y = (T)strToType(tokens3[0]); + result.z = (T)strToType(tokens4[0]); + + //printf("#3 Vec2T [%s]\n",result.getString().c_str()); + } + } + + + return result; + } + }; typedef Vec3 Vec3i;