策略抽离
This commit is contained in:
@@ -3,19 +3,21 @@
|
||||
namespace renderive {
|
||||
|
||||
Explicit_Plot_Private::Explicit_Plot_Private()
|
||||
: Abs_Plot_Private(std::make_unique<Explicit_Refresh_Strategy>()) {
|
||||
explicit_strategy = static_cast<Explicit_Refresh_Strategy*>(strategy);
|
||||
: Abs_Plot_Private(std::make_unique<Explicit_Frame_Flow>()) {
|
||||
explicit_flow = static_cast<Explicit_Frame_Flow*>(flow);
|
||||
}
|
||||
|
||||
Explicit_Plot::Explicit_Plot()
|
||||
: Abs_Plot(new Explicit_Plot_Private()) {}
|
||||
|
||||
void Explicit_Plot::replot() {
|
||||
Render_Ticket Explicit_Plot::replot() {
|
||||
auto* data = static_cast<Explicit_Plot_Private*>(d);
|
||||
if (data->explicit_strategy) {
|
||||
data->explicit_strategy->request_render();
|
||||
data->core->request_manual_refresh();
|
||||
if (data->explicit_flow) {
|
||||
Render_Ticket ticket = data->explicit_flow->request_render();
|
||||
data->core->request_explicit_render();
|
||||
return ticket;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
} // namespace renderive
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
#pragma once
|
||||
#include "Core/flow/Render_Ticket.h"
|
||||
#include "Plot.h"
|
||||
namespace renderive {
|
||||
class LIB_DECL Explicit_Plot : public Abs_Plot {
|
||||
public:
|
||||
Explicit_Plot();
|
||||
~Explicit_Plot() override = default;
|
||||
void replot();
|
||||
Render_Ticket replot();
|
||||
};
|
||||
} // namespace renderive
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
#pragma once
|
||||
#include "Explicit_Plot.h"
|
||||
#include "Plot_p.h"
|
||||
#include "Core/plot/Explicit_Refresh_Strategy.h"
|
||||
#include "Core/flow/explicit/Explicit_Frame_Flow.h"
|
||||
|
||||
namespace renderive {
|
||||
|
||||
struct Explicit_Plot_Private : Abs_Plot_Private {
|
||||
Explicit_Plot_Private();
|
||||
Explicit_Refresh_Strategy* explicit_strategy{};
|
||||
Explicit_Frame_Flow* explicit_flow{};
|
||||
};
|
||||
|
||||
} // namespace renderive
|
||||
|
||||
@@ -1,28 +1,37 @@
|
||||
#include "Latency_Eager_Plot_p.h"
|
||||
namespace renderive {
|
||||
Latency_Eager_Plot_Private::Latency_Eager_Plot_Private()
|
||||
: Abs_Plot_Private(std::make_unique<Latency_Eager_Refresh_Strategy>()) {
|
||||
latency_strategy = static_cast<Latency_Eager_Refresh_Strategy*>(strategy);
|
||||
: Abs_Plot_Private(std::make_unique<Low_Latency_Frame_Flow>()) {
|
||||
latency_flow = static_cast<Low_Latency_Frame_Flow*>(flow);
|
||||
}
|
||||
Latency_Eager_Plot::Latency_Eager_Plot()
|
||||
: Abs_Plot(new Latency_Eager_Plot_Private()) {}
|
||||
void Latency_Eager_Plot::start() {
|
||||
d->core->activate_view();
|
||||
}
|
||||
void Latency_Eager_Plot::pause() {
|
||||
d->core->deactivate_view();
|
||||
}
|
||||
bool Latency_Eager_Plot::running() const {
|
||||
return d->core->view_active();
|
||||
}
|
||||
double Latency_Eager_Plot::max_render_fps() const {
|
||||
auto* data = static_cast<Latency_Eager_Plot_Private*>(d);
|
||||
return data->latency_strategy ? data->latency_strategy->max_render_fps() : 0.0;
|
||||
return data->latency_flow ? data->latency_flow->max_render_fps() : 0.0;
|
||||
}
|
||||
void Latency_Eager_Plot::set_max_render_fps(double fps) {
|
||||
auto* data = static_cast<Latency_Eager_Plot_Private*>(d);
|
||||
if (data->latency_strategy) {
|
||||
data->latency_strategy->set_max_render_fps(fps);
|
||||
data->core->mark_render_state_dirty();
|
||||
if (data->latency_flow) {
|
||||
data->latency_flow->set_max_render_fps(fps);
|
||||
data->core->notify_model_dirty();
|
||||
}
|
||||
}
|
||||
Low_Latency_Diagnostics Latency_Eager_Plot::diagnostics() const {
|
||||
auto* data = static_cast<Latency_Eager_Plot_Private*>(d);
|
||||
return data->latency_flow ? data->latency_flow->low_latency_diagnostics() : Low_Latency_Diagnostics{};
|
||||
}
|
||||
Refresh_Control_Snapshot Latency_Eager_Plot::refresh_feedback_snapshot() const {
|
||||
auto* data = static_cast<Latency_Eager_Plot_Private*>(d);
|
||||
return data->latency_strategy ? data->latency_strategy->feedback_state() : Refresh_Control_Snapshot{};
|
||||
}
|
||||
void Latency_Eager_Plot::start_render(int max_render_fps) {
|
||||
set_max_render_fps(max_render_fps);
|
||||
Abs_Plot::start_render();
|
||||
return data->latency_flow ? data->latency_flow->feedback_state() : Refresh_Control_Snapshot{};
|
||||
}
|
||||
} // namespace renderive
|
||||
|
||||
@@ -1,13 +1,17 @@
|
||||
#pragma once
|
||||
#include "Core/flow/Flow_Diagnostics.h"
|
||||
#include "Plot.h"
|
||||
namespace renderive {
|
||||
class LIB_DECL Latency_Eager_Plot : public Abs_Plot {
|
||||
public:
|
||||
Latency_Eager_Plot();
|
||||
~Latency_Eager_Plot() override = default;
|
||||
void start();
|
||||
void pause();
|
||||
[[nodiscard]] bool running() const;
|
||||
[[nodiscard]] double max_render_fps() const;
|
||||
void set_max_render_fps(double fps);
|
||||
[[nodiscard]] Low_Latency_Diagnostics diagnostics() const;
|
||||
[[nodiscard]] Refresh_Control_Snapshot refresh_feedback_snapshot() const;
|
||||
void start_render(int max_render_fps);
|
||||
};
|
||||
} // namespace renderive
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
#pragma once
|
||||
#include "Latency_Eager_Plot.h"
|
||||
#include "Plot_p.h"
|
||||
#include "Core/plot/Latency_Eager_Refresh_Strategy.h"
|
||||
#include "Core/flow/low_latency/Low_Latency_Frame_Flow.h"
|
||||
|
||||
namespace renderive {
|
||||
|
||||
struct Latency_Eager_Plot_Private : Abs_Plot_Private {
|
||||
Latency_Eager_Plot_Private();
|
||||
Latency_Eager_Refresh_Strategy* latency_strategy{};
|
||||
Low_Latency_Frame_Flow* latency_flow{};
|
||||
};
|
||||
|
||||
} // namespace renderive
|
||||
|
||||
+7
-23
@@ -38,9 +38,9 @@ void start_render_scheduler(Render_Runtime_Config config) {
|
||||
Global::instance()->start_render_scheduler(config);
|
||||
}
|
||||
|
||||
Abs_Plot_Private::Abs_Plot_Private(std::unique_ptr<Refresh_Strategy> refresh_strategy)
|
||||
: strategy(refresh_strategy.get()),
|
||||
core(std::make_unique<Plot_Core>(std::move(refresh_strategy))) {}
|
||||
Abs_Plot_Private::Abs_Plot_Private(std::unique_ptr<Frame_Flow> frame_flow)
|
||||
: flow(frame_flow.get()),
|
||||
core(std::make_unique<Plot_Core>(std::move(frame_flow))) {}
|
||||
|
||||
Abs_Plot_Private::~Abs_Plot_Private() = default;
|
||||
|
||||
@@ -71,7 +71,7 @@ Abs_Plot::Abs_Plot(Abs_Plot_Private* private_data)
|
||||
Abs_Plot::~Abs_Plot() {
|
||||
if (d) {
|
||||
set_performance_overlay_update_callback(*d->core, {});
|
||||
d->core->pause_render();
|
||||
d->core->deactivate_view();
|
||||
delete d;
|
||||
d = nullptr;
|
||||
}
|
||||
@@ -101,18 +101,6 @@ void Abs_Plot::remove_renderable(const std::shared_ptr<Renderable>& able) {
|
||||
d->core->remove_renderable(able);
|
||||
}
|
||||
|
||||
bool Abs_Plot::is_rendering() {
|
||||
return d->core->is_rendering();
|
||||
}
|
||||
|
||||
void Abs_Plot::start_render() {
|
||||
d->core->start_render();
|
||||
}
|
||||
|
||||
void Abs_Plot::pause_render() {
|
||||
d->core->pause_render();
|
||||
}
|
||||
|
||||
QColor Abs_Plot::background_color() {
|
||||
return to_qcolor(d->core->background_color());
|
||||
}
|
||||
@@ -121,10 +109,6 @@ void Abs_Plot::set_background_color(const QColor& color) {
|
||||
d->core->set_background_color(from_qcolor(color));
|
||||
}
|
||||
|
||||
void Abs_Plot::mark_render_state_dirty() {
|
||||
d->core->mark_render_state_dirty();
|
||||
}
|
||||
|
||||
void Abs_Plot::paintEvent(QPaintEvent* event) {
|
||||
d->paint_event(this, event);
|
||||
}
|
||||
@@ -182,19 +166,19 @@ bool Abs_Plot_Private::event(Abs_Plot* plot, QEvent* event, bool base_result) {
|
||||
core->set_viewport_size(Qt_Event_Adapter::to_size(resize_event->size()));
|
||||
notify_performance_overlay_viewport_changed(*core);
|
||||
core->dispatch_event(Qt_Event_Adapter::to_resize_event(resize_event));
|
||||
core->mark_render_state_dirty();
|
||||
core->notify_model_dirty();
|
||||
break;
|
||||
}
|
||||
case QEvent::Show: {
|
||||
Event show_event(Event_Type::Show);
|
||||
core->dispatch_event(show_event);
|
||||
core->start_render();
|
||||
core->activate_view();
|
||||
break;
|
||||
}
|
||||
case QEvent::Hide: {
|
||||
Event hide_event(Event_Type::Hide);
|
||||
core->dispatch_event(hide_event);
|
||||
core->pause_render();
|
||||
core->deactivate_view();
|
||||
break;
|
||||
}
|
||||
case QEvent::Leave: {
|
||||
|
||||
@@ -25,12 +25,8 @@ public:
|
||||
[[nodiscard]] std::shared_ptr<Renderable> create_renderable_node(const std::shared_ptr<Renderable>& parent, const QString& object_name = {}) const;
|
||||
QString object_name;
|
||||
void set_background_color(const QColor& color);
|
||||
void mark_render_state_dirty();
|
||||
void remove_renderable(const std::shared_ptr<Renderable>& able);
|
||||
virtual void init_renderable_tree();
|
||||
bool is_rendering();
|
||||
void start_render();
|
||||
void pause_render();
|
||||
~Abs_Plot() override;
|
||||
protected:
|
||||
explicit Abs_Plot(Abs_Plot_Private* private_data);
|
||||
|
||||
+3
-3
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
#include "Plot.h"
|
||||
#include "Core/flow/Frame_Flow.h"
|
||||
#include "Core/plot/Plot_Core.h"
|
||||
#include "Core/plot/Refresh_Strategy.h"
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace renderive {
|
||||
class Qt_Presentation_Sink;
|
||||
|
||||
struct Abs_Plot_Private {
|
||||
explicit Abs_Plot_Private(std::unique_ptr<Refresh_Strategy> refresh_strategy);
|
||||
explicit Abs_Plot_Private(std::unique_ptr<Frame_Flow> frame_flow);
|
||||
virtual ~Abs_Plot_Private();
|
||||
|
||||
void attach_widget(Abs_Plot* plot);
|
||||
@@ -18,7 +18,7 @@ struct Abs_Plot_Private {
|
||||
void paint_event(Abs_Plot* plot, QPaintEvent* event);
|
||||
void request_performance_overlay_update(Abs_Plot* plot);
|
||||
|
||||
Refresh_Strategy* strategy{};
|
||||
Frame_Flow* flow{};
|
||||
std::unique_ptr<Plot_Core> core;
|
||||
std::shared_ptr<Qt_Presentation_Sink> presentation_sink;
|
||||
std::shared_ptr<std::atomic_bool> performance_update_pending = std::make_shared<std::atomic_bool>(false);
|
||||
|
||||
Reference in New Issue
Block a user