MapViewController.cpp 19 KB

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