MapViewController.cpp 19 KB

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