Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
frame_clock.hpp
Go to the documentation of this file.
1#pragma once
2
6
7#include <functional>
8#include <memory>
9#include <vector>
10#include <cstdint>
11
12namespace pulp::view {
13
15public:
17 void tick(float dt);
18
20 float time() const { return time_; }
21
23 float dt() const { return dt_; }
24
26 uint64_t frame() const { return frame_; }
27
30 int subscribe(std::function<bool(float dt)> callback);
31
33 void unsubscribe(int id);
34
37
38 // ── Activity channel (wake-from-idle probes) ────────────────────────────
39 // Distinct from the render subscribers above. An activity subscriber is an
40 // idle probe: the host calls pump_activity() every host tick REGARDLESS of
41 // render state, so a view can decide each tick whether it now needs
42 // continuous frames (e.g. flip set_continuous_repaint when a meter starts
43 // moving) WITHOUT the subscription itself counting as render-liveness. This
44 // separation is what lets an editor idle at 0 fps yet still wake: render
45 // subscribers (subscribe / has_active_subscribers) mean "keep painting";
46 // activity subscribers mean "let me look each tick, but don't paint for me".
47 // A wake-from-idle liveness flag driven from here is why a per-tick View
48 // vtable hook is unnecessary — self-subscribe via View::on_frame_clock_changed.
49
53 int subscribe_activity(std::function<void(float dt)> callback);
54
57
61
66 void pump_activity(float dt);
67
69 void reset();
70
75 std::weak_ptr<const void> liveness_token() const { return alive_; }
76
77private:
78 struct Subscriber {
79 int id;
80 std::function<bool(float dt)> callback;
81 bool active = true;
82 };
83 struct ActivitySubscriber {
84 int id;
85 std::function<void(float dt)> callback;
86 bool active = true;
87 };
88
89 std::vector<Subscriber> subscribers_;
90 std::vector<ActivitySubscriber> activity_subscribers_;
91 float time_ = 0;
92 float dt_ = 0;
93 uint64_t frame_ = 0;
94 int next_id_ = 1;
95 std::shared_ptr<const void> alive_ = std::make_shared<const char>('\0');
96};
97
98} // namespace pulp::view
Definition frame_clock.hpp:14
void unsubscribe(int id)
Remove a subscription by ID.
int subscribe_activity(std::function< void(float dt)> callback)
Subscribe an activity probe.
float time() const
Current elapsed time (seconds since first tick).
Definition frame_clock.hpp:20
void reset()
Reset all state (for testing).
uint64_t frame() const
Monotonic frame counter.
Definition frame_clock.hpp:26
bool has_active_subscribers() const
True if any subscribers are still active (drives repaint/invalidation).
bool has_activity_subscribers() const
True if any activity probe is registered.
void tick(float dt)
Advance the clock by dt seconds. Called once per frame by the host.
void unsubscribe_activity(int id)
Remove an activity subscription by id.
int subscribe(std::function< bool(float dt)> callback)
Subscribe to frame ticks.
float dt() const
Delta since last tick.
Definition frame_clock.hpp:23
std::weak_ptr< const void > liveness_token() const
Liveness token for holders that keep a raw FrameClock*.
Definition frame_clock.hpp:75
void pump_activity(float dt)
Fire every activity probe with dt.
Hover-cursor tracking for platform window hosts.
Definition fwd.hpp:27