mirror of
https://codeberg.org/comaps/comaps
synced 2025-12-23 22:53:43 +00:00
Organic Maps sources as of 02.04.2025 (fad26bbf22ac3da75e01e62aa01e5c8e11861005)
To expand with full Organic Maps and Maps.ME commits history run: git remote add om-historic [om-historic.git repo url] git fetch --tags om-historic git replace squashed-history historic-commits
This commit is contained in:
102
drape_frontend/scenario_manager.hpp
Normal file
102
drape_frontend/scenario_manager.hpp
Normal file
@@ -0,0 +1,102 @@
|
||||
#pragma once
|
||||
|
||||
#include "drape_frontend/frontend_renderer.hpp"
|
||||
|
||||
#include "drape/drape_diagnostics.hpp"
|
||||
|
||||
#include "geometry/point2d.hpp"
|
||||
|
||||
#include "base/stl_helpers.hpp"
|
||||
#include "base/thread.hpp"
|
||||
|
||||
#include <chrono>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <vector>
|
||||
|
||||
namespace df
|
||||
{
|
||||
|
||||
class ScenarioManager
|
||||
{
|
||||
public:
|
||||
enum class ActionType
|
||||
{
|
||||
CenterViewport,
|
||||
WaitForTime
|
||||
};
|
||||
|
||||
class Action
|
||||
{
|
||||
public:
|
||||
virtual ~Action() {}
|
||||
virtual ActionType GetType() = 0;
|
||||
};
|
||||
|
||||
class CenterViewportAction : public Action
|
||||
{
|
||||
public:
|
||||
CenterViewportAction(m2::PointD const & pt, int zoomLevel)
|
||||
: m_center(pt), m_zoomLevel(zoomLevel) {}
|
||||
|
||||
ActionType GetType() override { return ActionType::CenterViewport; }
|
||||
|
||||
m2::PointD const & GetCenter() const { return m_center; }
|
||||
int GetZoomLevel() const { return m_zoomLevel; }
|
||||
private:
|
||||
m2::PointD const m_center;
|
||||
int const m_zoomLevel;
|
||||
};
|
||||
|
||||
class WaitForTimeAction : public Action
|
||||
{
|
||||
public:
|
||||
using Duration = std::chrono::steady_clock::duration;
|
||||
|
||||
WaitForTimeAction(Duration const & duration)
|
||||
: m_duration(duration) {}
|
||||
|
||||
ActionType GetType() override { return ActionType::WaitForTime; }
|
||||
|
||||
Duration const & GetDuration() const { return m_duration; }
|
||||
private:
|
||||
Duration m_duration;
|
||||
};
|
||||
|
||||
using Scenario = std::vector<std::unique_ptr<Action>>;
|
||||
using ScenarioCallback = std::function<void(std::string const & name)>;
|
||||
|
||||
struct ScenarioData
|
||||
{
|
||||
std::string m_name;
|
||||
Scenario m_scenario;
|
||||
};
|
||||
|
||||
ScenarioManager(FrontendRenderer * frontendRenderer);
|
||||
~ScenarioManager();
|
||||
|
||||
bool RunScenario(ScenarioData && scenarioData,
|
||||
ScenarioCallback const & startHandler, ScenarioCallback const & finishHandler);
|
||||
void Interrupt();
|
||||
bool IsRunning();
|
||||
|
||||
private:
|
||||
void ThreadRoutine();
|
||||
void InterruptImpl();
|
||||
|
||||
FrontendRenderer * m_frontendRenderer;
|
||||
|
||||
std::mutex m_mutex;
|
||||
ScenarioData m_scenarioData;
|
||||
bool m_needInterrupt;
|
||||
bool m_isFinished;
|
||||
ScenarioCallback m_onStartHandler;
|
||||
ScenarioCallback m_onFinishHandler;
|
||||
#ifdef DEBUG
|
||||
std::thread::id m_threadId;
|
||||
#endif
|
||||
std::unique_ptr<threads::SimpleThread> m_thread;
|
||||
};
|
||||
|
||||
} // namespace df
|
||||
Reference in New Issue
Block a user