void Model::update(double totalTime) { if (addHero) { CHECK(playerControl && playerControl->isRetired()); landHeroPlayer(); addHero = false; } int absoluteTime = view->getTimeMilliAbsolute(); if (playerControl) { if (absoluteTime - lastUpdate > 50) { playerControl->render(view); lastUpdate = absoluteTime; } } do { Creature* creature = timeQueue.getNextCreature(); CHECK(creature) << "No more creatures"; Debug() << creature->getTheName() << " moving now " << creature->getTime(); currentTime = creature->getTime(); if (playerControl && !playerControl->isTurnBased()) { while (1) { UserInput input = view->getAction(); if (input.getId() == UserInputId::IDLE) break; else lastUpdate = -10; playerControl->processInput(view, input); } } if (currentTime > totalTime) return; if (currentTime >= lastTick + 1) { MEASURE({ tick(currentTime); }, "ticking time"); }
optional<Model::ExitInfo> Model::update(double totalTime) { if (addHero) { CHECK(playerControl && playerControl->isRetired()); landHeroPlayer(); addHero = false; } int absoluteTime = view->getTimeMilliAbsolute(); if (playerControl && absoluteTime - lastUpdate > 20) { playerControl->render(view); lastUpdate = absoluteTime; } else if (spectator && absoluteTime - lastUpdate > 20) { view->updateView(spectator.get(), false); lastUpdate = absoluteTime; } do { Creature* creature = timeQueue.getNextCreature(); CHECK(creature) << "No more creatures"; //Debug() << creature->getName().the() << " moving now " << creature->getTime(); currentTime = creature->getTime(); if (spectator) while (1) { UserInput input = view->getAction(); if (input.getId() == UserInputId::EXIT) return ExitInfo::abandonGame(); if (input.getId() == UserInputId::IDLE) break; } if (playerControl && !playerControl->isTurnBased()) { while (1) { UserInput input = view->getAction(); if (input.getId() == UserInputId::IDLE) break; else lastUpdate = -10; playerControl->processInput(view, input); if (exitInfo) return exitInfo; } } if (currentTime > totalTime) return none; if (currentTime >= lastTick + 1) { MEASURE({ tick(currentTime); }, "ticking time"); }