From 9aff9842a46b63cc783d708a9a80a4f7af20ee58 Mon Sep 17 00:00:00 2001 From: titiger Date: Thu, 29 Jan 2015 17:05:07 +0100 Subject: [PATCH] camera start position shows main building in center. --- source/glest_game/game/game.cpp | 47 +++++++++++++-------------------- source/glest_game/game/game.h | 1 + 2 files changed, 20 insertions(+), 28 deletions(-) diff --git a/source/glest_game/game/game.cpp b/source/glest_game/game/game.cpp index 22651b4c..5536b5f8 100644 --- a/source/glest_game/game/game.cpp +++ b/source/glest_game/game/game.cpp @@ -1334,39 +1334,13 @@ void Game::init(bool initForPreviewOnly) { } 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); - } - - if(world.getThisFaction() != NULL) { - const Vec2i &v= map->getStartLocation(world.getThisFaction()->getStartLocationIndex()); - gameCamera.setPos(Vec2f(v.x, v.y)); - } + initCamera(map); } else { gui.loadGame(loadGameNode,&world); if(inJoinGameLoading == true) { - 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); - } - - if(world.getThisFaction() != NULL) { - const Vec2i &v= map->getStartLocation(world.getThisFaction()->getStartLocationIndex()); - gameCamera.setPos(Vec2f(v.x, v.y)); - } + initCamera(map); } } @@ -1634,6 +1608,23 @@ void Game::init(bool initForPreviewOnly) { } } +void Game::initCamera(Map *map){ + 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); + } + + if(world.getThisFaction() != NULL) { + const Vec2i &v= map->getStartLocation(world.getThisFaction()->getStartLocationIndex()); + gameCamera.setPos(Vec2f(v.x, v.y+gameCamera.getCalculatedDefault()/2)); + } +} + // ==================== update ==================== void Game::reInitGUI() { diff --git a/source/glest_game/game/game.h b/source/glest_game/game/game.h index a3b22d9c..1b5a1c67 100644 --- a/source/glest_game/game/game.h +++ b/source/glest_game/game/game.h @@ -408,6 +408,7 @@ private: void checkWinnerStandardHeadlessOrObserver(); void checkWinnerStandardPlayer(); std::map getTeamsAlive(); + void initCamera(Map *map); virtual bool clientLagHandler(int slotIndex,bool networkPauseGameForLaggedClients); };