MapViewController.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684
  1. /*
  2. * MapViewController.cpp, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #include "StdInc.h"
  11. #include "MapViewController.h"
  12. #include "MapRendererContext.h"
  13. #include "MapRendererContextState.h"
  14. #include "MapViewCache.h"
  15. #include "MapViewModel.h"
  16. #include "../CCallback.h"
  17. #include "../CPlayerInterface.h"
  18. #include "../adventureMap/AdventureMapInterface.h"
  19. #include "../gui/CGuiHandler.h"
  20. #include "../gui/WindowHandler.h"
  21. #include "../eventsSDL/InputHandler.h"
  22. #include "../../lib/CConfigHandler.h"
  23. #include "../../lib/StartInfo.h"
  24. #include "../../lib/UnlockGuard.h"
  25. #include "../../lib/mapObjects/CGHeroInstance.h"
  26. #include "../../lib/mapObjects/MiscObjects.h"
  27. #include "../../lib/pathfinder/CGPathNode.h"
  28. #include "../../lib/spells/ViewSpellInt.h"
  29. void MapViewController::setViewCenter(const int3 & position)
  30. {
  31. setViewCenter(Point(position) * model->getSingleTileSize() + model->getSingleTileSize() / 2, position.z);
  32. }
  33. void MapViewController::setViewCenter(const Point & position, int level)
  34. {
  35. Point upperLimit = Point(context->getMapSize()) * model->getSingleTileSize();
  36. Point lowerLimit = Point(0, 0);
  37. if(worldViewContext)
  38. {
  39. Point area = model->getPixelsVisibleDimensions();
  40. Point mapCenter = upperLimit / 2;
  41. Point desiredLowerLimit = lowerLimit + area / 2;
  42. Point desiredUpperLimit = upperLimit - area / 2;
  43. Point actualLowerLimit{
  44. std::min(desiredLowerLimit.x, mapCenter.x),
  45. std::min(desiredLowerLimit.y, mapCenter.y)
  46. };
  47. Point actualUpperLimit{
  48. std::max(desiredUpperLimit.x, mapCenter.x),
  49. std::max(desiredUpperLimit.y, mapCenter.y)
  50. };
  51. upperLimit = actualUpperLimit;
  52. lowerLimit = actualLowerLimit;
  53. }
  54. Point betterPosition = {std::clamp(position.x, lowerLimit.x, upperLimit.x), std::clamp(position.y, lowerLimit.y, upperLimit.y)};
  55. model->setViewCenter(betterPosition);
  56. model->setLevel(std::clamp(level, 0, context->getMapSize().z));
  57. if(adventureInt && !puzzleMapContext) // may be called before adventureInt is initialized
  58. adventureInt->onMapViewMoved(model->getTilesTotalRect(), model->getLevel());
  59. }
  60. void MapViewController::setTileSize(const Point & tileSize, bool setTarget)
  61. {
  62. Point oldSize = model->getSingleTileSize();
  63. model->setTileSize(tileSize);
  64. double scaleChangeX = 1.0 * tileSize.x / oldSize.x;
  65. double scaleChangeY = 1.0 * tileSize.y / oldSize.y;
  66. Point newViewCenter {
  67. static_cast<int>(std::round(model->getMapViewCenter().x * scaleChangeX)),
  68. static_cast<int>(std::round(model->getMapViewCenter().y * scaleChangeY))
  69. };
  70. // force update of view center since changing tile size may invalidated it
  71. setViewCenter(newViewCenter, model->getLevel());
  72. if(setTarget)
  73. targetTileSize = tileSize;
  74. }
  75. void MapViewController::modifyTileSize(int stepsChange, bool useDeadZone)
  76. {
  77. // we want to zoom in/out in fixed 10% steps, to allow player to return back to exactly 100% zoom just by scrolling
  78. // so, zooming in for 5 steps will put game at 1.1^5 = 1.61 scale
  79. // try to determine current zooming level and change it by requested number of steps
  80. double currentZoomFactor = targetTileSize.x / static_cast<double>(defaultTileSize);
  81. double currentZoomSteps = std::round(std::log(currentZoomFactor) / std::log(1.01));
  82. double newZoomSteps = stepsChange != 0 ? currentZoomSteps + stepsChange : stepsChange;
  83. double newZoomFactor = std::pow(1.01, newZoomSteps);
  84. Point currentZoom = targetTileSize;
  85. Point desiredZoom = Point(defaultTileSize,defaultTileSize) * newZoomFactor;
  86. if (desiredZoom == currentZoom && stepsChange < 0)
  87. desiredZoom -= Point(1,1);
  88. if (desiredZoom == currentZoom && stepsChange > 0)
  89. desiredZoom += Point(1,1);
  90. Point minimal = model->getSingleTileSizeLowerLimit();
  91. Point maximal = model->getSingleTileSizeUpperLimit();
  92. Point actualZoom = {
  93. std::clamp(desiredZoom.x, minimal.x, maximal.x),
  94. std::clamp(desiredZoom.y, minimal.y, maximal.y)
  95. };
  96. if (actualZoom != currentZoom)
  97. {
  98. targetTileSize = actualZoom;
  99. if (useDeadZone)
  100. {
  101. if(actualZoom.x >= defaultTileSize - zoomTileDeadArea && actualZoom.x <= defaultTileSize + zoomTileDeadArea)
  102. actualZoom.x = defaultTileSize;
  103. if(actualZoom.y >= defaultTileSize - zoomTileDeadArea && actualZoom.y <= defaultTileSize + zoomTileDeadArea)
  104. actualZoom.y = defaultTileSize;
  105. }
  106. bool isInDeadZone = targetTileSize != actualZoom || actualZoom == Point(defaultTileSize, defaultTileSize);
  107. if(!wasInDeadZone && isInDeadZone)
  108. GH.input().hapticFeedback();
  109. wasInDeadZone = isInDeadZone;
  110. setTileSize(actualZoom, false);
  111. Settings tileZoom = persistentStorage.write["tileZoom"];
  112. tileZoom->Integer() = actualZoom.x;
  113. }
  114. }
  115. MapViewController::MapViewController(std::shared_ptr<MapViewModel> model, std::shared_ptr<MapViewCache> view)
  116. : state(new MapRendererContextState())
  117. , model(std::move(model))
  118. , view(view)
  119. {
  120. adventureContext = std::make_shared<MapRendererAdventureContext>(*state);
  121. context = adventureContext;
  122. }
  123. std::shared_ptr<IMapRendererContext> MapViewController::getContext() const
  124. {
  125. return context;
  126. }
  127. void MapViewController::tick(uint32_t timeDelta)
  128. {
  129. // confirmed to match H3 for
  130. // - hero embarking on boat (500 ms)
  131. // - hero disembarking from boat (500 ms)
  132. // - TODO: picking up resources
  133. // - TODO: killing mosters
  134. // - teleporting ( 250 ms)
  135. static const double fadeOutDuration = 500;
  136. static const double fadeInDuration = 500;
  137. static const double heroTeleportDuration = 250;
  138. if(movementContext)
  139. {
  140. const auto * object = context->getObject(movementContext->target);
  141. const auto * hero = dynamic_cast<const CGHeroInstance *>(object);
  142. const auto * boat = dynamic_cast<const CGBoat *>(object);
  143. assert(boat || hero);
  144. if(!hero)
  145. hero = boat->hero;
  146. double heroMoveTime = LOCPLINT->playerID == hero->getOwner() ?
  147. settings["adventure"]["heroMoveTime"].Float() :
  148. settings["adventure"]["enemyMoveTime"].Float();
  149. movementContext->progress += timeDelta / heroMoveTime;
  150. movementContext->progress = std::min( 1.0, movementContext->progress);
  151. Point positionFrom = Point(hero->convertToVisitablePos(movementContext->tileFrom)) * model->getSingleTileSize() + model->getSingleTileSize() / 2;
  152. Point positionDest = Point(hero->convertToVisitablePos(movementContext->tileDest)) * model->getSingleTileSize() + model->getSingleTileSize() / 2;
  153. Point positionCurr = vstd::lerp(positionFrom, positionDest, movementContext->progress);
  154. setViewCenter(positionCurr, movementContext->tileDest.z);
  155. }
  156. if(teleportContext)
  157. {
  158. teleportContext->progress += timeDelta / heroTeleportDuration;
  159. teleportContext->progress = std::min( 1.0, teleportContext->progress);
  160. }
  161. if(fadingOutContext)
  162. {
  163. fadingOutContext->progress -= timeDelta / fadeOutDuration;
  164. fadingOutContext->progress = std::max( 0.0, fadingOutContext->progress);
  165. }
  166. if(fadingInContext)
  167. {
  168. fadingInContext->progress += timeDelta / fadeInDuration;
  169. fadingInContext->progress = std::min( 1.0, fadingInContext->progress);
  170. }
  171. if (adventureContext)
  172. adventureContext->animationTime += timeDelta;
  173. updateState();
  174. }
  175. void MapViewController::updateState()
  176. {
  177. if(adventureContext)
  178. {
  179. adventureContext->settingsSessionSpectate = settings["session"]["spectate"].Bool();
  180. adventureContext->settingsAdventureObjectAnimation = settings["adventure"]["objectAnimation"].Bool();
  181. adventureContext->settingsAdventureTerrainAnimation = settings["adventure"]["terrainAnimation"].Bool();
  182. adventureContext->settingShowGrid = settings["gameTweaks"]["showGrid"].Bool();
  183. adventureContext->settingShowVisitable = settings["session"]["showVisitable"].Bool();
  184. adventureContext->settingShowBlocked = settings["session"]["showBlocked"].Bool();
  185. adventureContext->settingSpellRange = settings["session"]["showSpellRange"].Bool();
  186. adventureContext->settingTextOverlay = (GH.isKeyboardAltDown() || GH.input().getNumTouchFingers() == 2) && settings["general"]["enableOverlay"].Bool();
  187. }
  188. }
  189. void MapViewController::afterRender()
  190. {
  191. if(movementContext)
  192. {
  193. const auto * object = context->getObject(movementContext->target);
  194. const auto * hero = dynamic_cast<const CGHeroInstance *>(object);
  195. const auto * boat = dynamic_cast<const CGBoat *>(object);
  196. assert(boat || hero);
  197. if(!hero)
  198. hero = boat->hero;
  199. if(movementContext->progress >= 0.999)
  200. {
  201. logGlobal->debug("Ending movement animation");
  202. setViewCenter(hero->getSightCenter());
  203. removeObject(context->getObject(movementContext->target));
  204. addObject(context->getObject(movementContext->target));
  205. activateAdventureContext(movementContext->animationTime);
  206. }
  207. }
  208. if(teleportContext && teleportContext->progress >= 0.999)
  209. {
  210. logGlobal->debug("Ending teleport animation");
  211. activateAdventureContext(teleportContext->animationTime);
  212. }
  213. if(fadingOutContext && fadingOutContext->progress <= 0.001)
  214. {
  215. logGlobal->debug("Ending fade out animation");
  216. removeObject(context->getObject(fadingOutContext->target));
  217. activateAdventureContext(fadingOutContext->animationTime);
  218. }
  219. if(fadingInContext && fadingInContext->progress >= 0.999)
  220. {
  221. logGlobal->debug("Ending fade in animation");
  222. activateAdventureContext(fadingInContext->animationTime);
  223. }
  224. }
  225. bool MapViewController::isEventInstant(const CGObjectInstance * obj, const PlayerColor & initiator)
  226. {
  227. if(settings["gameTweaks"]["skipAdventureMapAnimations"].Bool())
  228. return true;
  229. if (!isEventVisible(obj, initiator))
  230. return true;
  231. if (!initiator.isValidPlayer())
  232. return true; // skip effects such as new monsters on new month
  233. if(initiator != LOCPLINT->playerID && settings["adventure"]["enemyMoveTime"].Float() <= 0)
  234. return true; // instant movement speed
  235. if(initiator == LOCPLINT->playerID && settings["adventure"]["heroMoveTime"].Float() <= 0)
  236. return true; // instant movement speed
  237. return false;
  238. }
  239. bool MapViewController::isEventVisible(const CGObjectInstance * obj, const PlayerColor & initiator)
  240. {
  241. if(adventureContext == nullptr)
  242. return false;
  243. if(initiator != LOCPLINT->playerID && settings["adventure"]["enemyMoveTime"].Float() < 0)
  244. return false; // enemy move speed set to "hidden/none"
  245. if(!GH.windows().isTopWindow(adventureInt))
  246. return false;
  247. // do not focus on actions of other players except for AI with simturns off
  248. if (initiator != LOCPLINT->playerID && initiator.isValidPlayer())
  249. {
  250. if (LOCPLINT->makingTurn)
  251. return false;
  252. if (LOCPLINT->cb->getStartInfo()->playerInfos.at(initiator).isControlledByHuman() && !settings["session"]["adventureTrackHero"].Bool())
  253. return false;
  254. }
  255. if(obj->isVisitable())
  256. return context->isVisible(obj->visitablePos());
  257. else
  258. return context->isVisible(obj->anchorPos());
  259. }
  260. bool MapViewController::isEventVisible(const CGHeroInstance * obj, const int3 & from, const int3 & dest)
  261. {
  262. if(adventureContext == nullptr)
  263. return false;
  264. if(obj->getOwner() != LOCPLINT->playerID && settings["adventure"]["enemyMoveTime"].Float() < 0)
  265. return false; // enemy move speed set to "hidden/none"
  266. if(!GH.windows().isTopWindow(adventureInt))
  267. return false;
  268. // do not focus on actions of other players except for AI with simturns off
  269. if (obj->getOwner() != LOCPLINT->playerID)
  270. {
  271. if (LOCPLINT->makingTurn)
  272. return false;
  273. if (LOCPLINT->cb->getStartInfo()->playerInfos.at(obj->getOwner()).isControlledByHuman() && !settings["session"]["adventureTrackHero"].Bool())
  274. return false;
  275. }
  276. if(context->isVisible(obj->convertToVisitablePos(from)))
  277. return true;
  278. if(context->isVisible(obj->convertToVisitablePos(dest)))
  279. return true;
  280. return false;
  281. }
  282. void MapViewController::fadeOutObject(const CGObjectInstance * obj)
  283. {
  284. animationWait.setBusy();
  285. logGlobal->debug("Starting fade out animation");
  286. fadingOutContext = std::make_shared<MapRendererAdventureFadingContext>(*state);
  287. fadingOutContext->animationTime = adventureContext->animationTime;
  288. adventureContext = fadingOutContext;
  289. context = fadingOutContext;
  290. const CGObjectInstance * movingObject = obj;
  291. if (obj->ID == Obj::HERO)
  292. {
  293. auto * hero = dynamic_cast<const CGHeroInstance*>(obj);
  294. if (hero->boat)
  295. movingObject = hero->boat;
  296. }
  297. fadingOutContext->target = movingObject->id;
  298. fadingOutContext->progress = 1.0;
  299. }
  300. void MapViewController::fadeInObject(const CGObjectInstance * obj)
  301. {
  302. animationWait.setBusy();
  303. logGlobal->debug("Starting fade in animation");
  304. fadingInContext = std::make_shared<MapRendererAdventureFadingContext>(*state);
  305. fadingInContext->animationTime = adventureContext->animationTime;
  306. adventureContext = fadingInContext;
  307. context = fadingInContext;
  308. const CGObjectInstance * movingObject = obj;
  309. if (obj->ID == Obj::HERO)
  310. {
  311. auto * hero = dynamic_cast<const CGHeroInstance*>(obj);
  312. if (hero->boat)
  313. movingObject = hero->boat;
  314. }
  315. fadingInContext->target = movingObject->id;
  316. fadingInContext->progress = 0.0;
  317. }
  318. void MapViewController::removeObject(const CGObjectInstance * obj)
  319. {
  320. if (obj->ID == Obj::BOAT)
  321. {
  322. auto * boat = dynamic_cast<const CGBoat*>(obj);
  323. if (boat->hero)
  324. {
  325. view->invalidate(context, boat->hero->id);
  326. state->removeObject(boat->hero);
  327. }
  328. }
  329. if (obj->ID == Obj::HERO)
  330. {
  331. auto * hero = dynamic_cast<const CGHeroInstance*>(obj);
  332. if (hero->boat)
  333. {
  334. view->invalidate(context, hero->boat->id);
  335. state->removeObject(hero->boat);
  336. }
  337. }
  338. view->invalidate(context, obj->id);
  339. state->removeObject(obj);
  340. }
  341. void MapViewController::addObject(const CGObjectInstance * obj)
  342. {
  343. state->addObject(obj);
  344. view->invalidate(context, obj->id);
  345. }
  346. void MapViewController::onBeforeHeroEmbark(const CGHeroInstance * obj, const int3 & from, const int3 & dest)
  347. {
  348. if(isEventVisible(obj, from, dest))
  349. {
  350. if (!isEventInstant(obj, obj->getOwner()))
  351. fadeOutObject(obj);
  352. setViewCenter(obj->getSightCenter());
  353. }
  354. else
  355. removeObject(obj);
  356. }
  357. void MapViewController::onAfterHeroEmbark(const CGHeroInstance * obj, const int3 & from, const int3 & dest)
  358. {
  359. if(isEventVisible(obj, from, dest))
  360. setViewCenter(obj->getSightCenter());
  361. }
  362. void MapViewController::onBeforeHeroDisembark(const CGHeroInstance * obj, const int3 & from, const int3 & dest)
  363. {
  364. if(isEventVisible(obj, from, dest))
  365. setViewCenter(obj->getSightCenter());
  366. }
  367. void MapViewController::onAfterHeroDisembark(const CGHeroInstance * obj, const int3 & from, const int3 & dest)
  368. {
  369. if(isEventVisible(obj, from, dest))
  370. {
  371. if (!isEventInstant(obj, obj->getOwner()))
  372. fadeInObject(obj);
  373. setViewCenter(obj->getSightCenter());
  374. }
  375. addObject(obj);
  376. }
  377. void MapViewController::onObjectFadeIn(const CGObjectInstance * obj, const PlayerColor & initiator)
  378. {
  379. assert(!hasOngoingAnimations());
  380. if(isEventVisible(obj, initiator) && !isEventInstant(obj, initiator) )
  381. fadeInObject(obj);
  382. addObject(obj);
  383. }
  384. void MapViewController::onObjectFadeOut(const CGObjectInstance * obj, const PlayerColor & initiator)
  385. {
  386. assert(!hasOngoingAnimations());
  387. if(isEventVisible(obj, initiator) && !isEventInstant(obj, initiator) )
  388. fadeOutObject(obj);
  389. else
  390. removeObject(obj);
  391. }
  392. void MapViewController::onObjectInstantAdd(const CGObjectInstance * obj, const PlayerColor & initiator)
  393. {
  394. addObject(obj);
  395. };
  396. void MapViewController::onObjectInstantRemove(const CGObjectInstance * obj, const PlayerColor & initiator)
  397. {
  398. removeObject(obj);
  399. };
  400. void MapViewController::onBeforeHeroTeleported(const CGHeroInstance * obj, const int3 & from, const int3 & dest)
  401. {
  402. assert(!hasOngoingAnimations());
  403. if(isEventVisible(obj, from, dest))
  404. {
  405. setViewCenter(obj->getSightCenter());
  406. view->createTransitionSnapshot(context);
  407. }
  408. }
  409. void MapViewController::onAfterHeroTeleported(const CGHeroInstance * obj, const int3 & from, const int3 & dest)
  410. {
  411. assert(!hasOngoingAnimations());
  412. const CGObjectInstance * movingObject = obj;
  413. if(obj->boat)
  414. movingObject = obj->boat;
  415. removeObject(movingObject);
  416. addObject(movingObject);
  417. if(isEventVisible(obj, from, dest))
  418. {
  419. animationWait.setBusy();
  420. logGlobal->debug("Starting teleport animation");
  421. teleportContext = std::make_shared<MapRendererAdventureTransitionContext>(*state);
  422. teleportContext->animationTime = adventureContext->animationTime;
  423. adventureContext = teleportContext;
  424. context = teleportContext;
  425. setViewCenter(movingObject->getSightCenter());
  426. }
  427. }
  428. void MapViewController::onHeroMoved(const CGHeroInstance * obj, const int3 & from, const int3 & dest)
  429. {
  430. assert(!hasOngoingAnimations());
  431. // revisiting via spacebar, no need to animate
  432. if(from == dest)
  433. return;
  434. const CGObjectInstance * movingObject = obj;
  435. if(obj->boat)
  436. movingObject = obj->boat;
  437. removeObject(movingObject);
  438. if(!isEventVisible(obj, from, dest))
  439. {
  440. addObject(movingObject);
  441. return;
  442. }
  443. double movementTime = LOCPLINT->playerID == obj->tempOwner ?
  444. settings["adventure"]["heroMoveTime"].Float() :
  445. settings["adventure"]["enemyMoveTime"].Float();
  446. if(movementTime > 1)
  447. {
  448. animationWait.setBusy();
  449. logGlobal->debug("Starting movement animation");
  450. movementContext = std::make_shared<MapRendererAdventureMovingContext>(*state);
  451. movementContext->animationTime = adventureContext->animationTime;
  452. adventureContext = movementContext;
  453. context = movementContext;
  454. state->addMovingObject(movingObject, from, dest);
  455. movementContext->target = movingObject->id;
  456. movementContext->tileFrom = from;
  457. movementContext->tileDest = dest;
  458. movementContext->progress = 0.0;
  459. }
  460. else // instant movement
  461. {
  462. addObject(movingObject);
  463. setViewCenter(movingObject->visitablePos());
  464. }
  465. }
  466. bool MapViewController::hasOngoingAnimations()
  467. {
  468. if(movementContext)
  469. return true;
  470. if(fadingOutContext)
  471. return true;
  472. if(fadingInContext)
  473. return true;
  474. if(teleportContext)
  475. return true;
  476. return false;
  477. }
  478. void MapViewController::waitForOngoingAnimations()
  479. {
  480. auto unlockInterface = vstd::makeUnlockGuard(GH.interfaceMutex);
  481. animationWait.waitWhileBusy();
  482. }
  483. void MapViewController::endNetwork()
  484. {
  485. animationWait.requestTermination();
  486. }
  487. void MapViewController::activateAdventureContext(uint32_t animationTime)
  488. {
  489. resetContext();
  490. adventureContext = std::make_shared<MapRendererAdventureContext>(*state);
  491. adventureContext->animationTime = animationTime;
  492. context = adventureContext;
  493. updateState();
  494. }
  495. void MapViewController::activateAdventureContext()
  496. {
  497. activateAdventureContext(0);
  498. }
  499. void MapViewController::activateWorldViewContext()
  500. {
  501. if(worldViewContext)
  502. return;
  503. resetContext();
  504. worldViewContext = std::make_shared<MapRendererWorldViewContext>(*state);
  505. context = worldViewContext;
  506. }
  507. void MapViewController::activateSpellViewContext()
  508. {
  509. if(spellViewContext)
  510. return;
  511. resetContext();
  512. spellViewContext = std::make_shared<MapRendererSpellViewContext>(*state);
  513. worldViewContext = spellViewContext;
  514. context = spellViewContext;
  515. }
  516. void MapViewController::activatePuzzleMapContext(const int3 & grailPosition)
  517. {
  518. resetContext();
  519. puzzleMapContext = std::make_shared<MapRendererPuzzleMapContext>(*state);
  520. context = puzzleMapContext;
  521. CGPathNode fakeNode;
  522. fakeNode.coord = grailPosition;
  523. puzzleMapContext->grailPos = std::make_unique<CGPath>();
  524. // create two nodes since 1st one is normally not visible
  525. puzzleMapContext->grailPos->nodes.push_back(fakeNode);
  526. puzzleMapContext->grailPos->nodes.push_back(fakeNode);
  527. }
  528. void MapViewController::resetContext()
  529. {
  530. adventureContext.reset();
  531. movementContext.reset();
  532. fadingOutContext.reset();
  533. fadingInContext.reset();
  534. teleportContext.reset();
  535. worldViewContext.reset();
  536. spellViewContext.reset();
  537. puzzleMapContext.reset();
  538. animationWait.setFree();
  539. }
  540. void MapViewController::setTerrainVisibility(bool showAllTerrain)
  541. {
  542. assert(spellViewContext);
  543. spellViewContext->showAllTerrain = showAllTerrain;
  544. }
  545. void MapViewController::setOverlayVisibility(const std::vector<ObjectPosInfo> & objectPositions)
  546. {
  547. assert(spellViewContext);
  548. spellViewContext->additionalOverlayIcons = objectPositions;
  549. }