删除plot_core
This commit is contained in:
@@ -77,21 +77,32 @@ std::optional<double> action_number(const Gallery_Action_Request& request) {
|
||||
return std::nullopt;
|
||||
return std::get<double>(*request.argument);
|
||||
}
|
||||
Frame_Control_Mode core_frame_mode(Gallery_Frame_Mode mode) {
|
||||
const auto result = magic_enum::enum_cast<Frame_Control_Mode>(
|
||||
magic_enum::enum_name(mode));
|
||||
if (!result)
|
||||
throw std::logic_error("Gallery frame mode has no Kernel strategy");
|
||||
return *result;
|
||||
}
|
||||
} // namespace
|
||||
class Gallery_Scene final {
|
||||
class Gallery_Scene_Interface {
|
||||
public:
|
||||
Gallery_Scene(std::uint64_t session_id, std::string case_id,
|
||||
Gallery_Frame_Mode frame_mode, bool automatic_low_latency)
|
||||
: session_id_(session_id), case_id_(std::move(case_id)),
|
||||
frame_mode_(frame_mode), automatic_low_latency_(automatic_low_latency),
|
||||
plot_(core_frame_mode(frame_mode)), performance_started_(std::chrono::steady_clock::now()) {
|
||||
virtual ~Gallery_Scene_Interface() = default;
|
||||
[[nodiscard]] virtual const std::string& case_id() const noexcept = 0;
|
||||
[[nodiscard]] virtual nlohmann::json controls() const = 0;
|
||||
[[nodiscard]] virtual Gallery_Frame_Mode frame_mode() const noexcept = 0;
|
||||
virtual void reset_monitoring() = 0;
|
||||
[[nodiscard]] virtual bool can_render_automatically() const noexcept = 0;
|
||||
[[nodiscard]] virtual std::uint64_t kernel_refresh_interval_ns() const = 0;
|
||||
virtual void set_client_metrics(Gallery_Client_Performance metrics) noexcept = 0;
|
||||
[[nodiscard]] virtual adminive::Update_Result apply_patch(std::string_view target, const nlohmann::json& patch) = 0;
|
||||
virtual void resize(Size size) = 0;
|
||||
virtual void dispatch(const Event& event) = 0;
|
||||
virtual bool render_latest_frame() = 0;
|
||||
[[nodiscard]] virtual std::optional<std::string> encode_latest_pixels() = 0;
|
||||
virtual void record_pixel_response(std::chrono::steady_clock::time_point request_started, std::chrono::steady_clock::time_point encode_started, std::chrono::steady_clock::time_point encode_finished, std::size_t pixel_bytes) = 0;
|
||||
[[nodiscard]] virtual std::string action(const Gallery_Action_Request& request, bool& recognized) = 0;
|
||||
virtual void record_action_notice_if_empty(std::string_view notice) = 0;
|
||||
[[nodiscard]] virtual std::string telemetry_json() const = 0;
|
||||
};
|
||||
template <class Scene_Type>
|
||||
class Gallery_Scene final : public Gallery_Scene_Interface {
|
||||
public:
|
||||
Gallery_Scene(std::uint64_t session_id, std::string case_id, Gallery_Frame_Mode frame_mode, bool automatic_low_latency)
|
||||
: session_id_(session_id), case_id_(std::move(case_id)), frame_mode_(frame_mode), automatic_low_latency_(automatic_low_latency), performance_started_(std::chrono::steady_clock::now()) {
|
||||
plot_.init();
|
||||
plot_.set_viewport_size({560, 320});
|
||||
root_ = plot_.root_renderable();
|
||||
@@ -104,7 +115,7 @@ public:
|
||||
build_axes();
|
||||
build_primary();
|
||||
apply_layout();
|
||||
session_control_ = std::make_unique<Gallery_Session_Control>(
|
||||
session_control_ = std::make_unique<Gallery_Session_Control<Scene_Type>>(
|
||||
plot_, *primary_, feedback_policy_);
|
||||
register_controls();
|
||||
set_performance_plot_name(plot_, case_id_ + "/" + gallery_enum_id(frame_mode_));
|
||||
@@ -1236,9 +1247,9 @@ private:
|
||||
std::string case_id_;
|
||||
Gallery_Frame_Mode frame_mode_ = Gallery_Frame_Mode::Low_Latency;
|
||||
bool automatic_low_latency_{};
|
||||
Plot_Core plot_;
|
||||
Scene_Type plot_;
|
||||
Gallery_Feedback_Policy feedback_policy_;
|
||||
std::unique_ptr<Gallery_Session_Control> session_control_;
|
||||
std::unique_ptr<Gallery_Session_Control<Scene_Type>> session_control_;
|
||||
Gallery_Controls controls_;
|
||||
std::chrono::steady_clock::time_point performance_started_;
|
||||
std::chrono::steady_clock::time_point last_performance_log_;
|
||||
@@ -1280,6 +1291,17 @@ private:
|
||||
bool rendered_since_last_pixel_{};
|
||||
std::string last_action_result_;
|
||||
};
|
||||
std::unique_ptr<Gallery_Scene_Interface> make_gallery_scene(std::uint64_t session_id, std::string case_id, Gallery_Frame_Mode mode, bool automatic_low_latency) {
|
||||
switch (mode) {
|
||||
case Gallery_Frame_Mode::Manual:
|
||||
return std::make_unique<Gallery_Scene<Manual_Scene2D>>(session_id, std::move(case_id), mode, automatic_low_latency);
|
||||
case Gallery_Frame_Mode::Low_Latency:
|
||||
return std::make_unique<Gallery_Scene<Scene2D>>(session_id, std::move(case_id), mode, automatic_low_latency);
|
||||
case Gallery_Frame_Mode::Playback:
|
||||
return std::make_unique<Gallery_Scene<Playback_Scene2D>>(session_id, std::move(case_id), mode, automatic_low_latency);
|
||||
}
|
||||
throw std::invalid_argument("unknown gallery frame mode");
|
||||
}
|
||||
struct Gallery_Plot_Session::Impl {
|
||||
explicit Impl(bool enable_automatic_low_latency)
|
||||
: automatic_low_latency(enable_automatic_low_latency),
|
||||
@@ -1433,7 +1455,7 @@ struct Gallery_Plot_Session::Impl {
|
||||
},
|
||||
event);
|
||||
}
|
||||
std::unique_ptr<Gallery_Scene> scene;
|
||||
std::unique_ptr<Gallery_Scene_Interface> scene;
|
||||
std::mutex mutex;
|
||||
std::condition_variable scheduler_condition;
|
||||
std::uint64_t scheduler_revision{};
|
||||
@@ -1452,8 +1474,7 @@ struct Gallery_Plot_Session::Impl {
|
||||
Web_Response_Type::Json,
|
||||
Gallery_Protocol::error_json("未知的 gallery case 或 frame_mode", "case")
|
||||
};
|
||||
scene = std::make_unique<Gallery_Scene>(
|
||||
session_id, open->case_id, open->frame_mode, automatic_low_latency);
|
||||
scene = make_gallery_scene(session_id, open->case_id, open->frame_mode, automatic_low_latency);
|
||||
++scene_generation;
|
||||
if (scene->frame_mode() == Gallery_Frame_Mode::Low_Latency)
|
||||
ensure_render_worker();
|
||||
@@ -1538,8 +1559,7 @@ struct Gallery_Plot_Session::Impl {
|
||||
if (action->id == "reset") {
|
||||
const std::string id = scene->case_id();
|
||||
const auto mode = scene->frame_mode();
|
||||
scene = std::make_unique<Gallery_Scene>(
|
||||
session_id, id, mode, automatic_low_latency);
|
||||
scene = make_gallery_scene(session_id, id, mode, automatic_low_latency);
|
||||
++scene_generation;
|
||||
return Web_Response{
|
||||
Web_Response_Type::Json,
|
||||
|
||||
Reference in New Issue
Block a user