9#ifndef AVARA3D_EXTENSION_TRANSIENTS_H
10#define AVARA3D_EXTENSION_TRANSIENTS_H
17#include <unordered_map>
21#include "a3d/scene/Scene.h"
163 void track(
const std::shared_ptr<Node>& node,
const std::string& group = {});
174 void track(
const std::vector<std::shared_ptr<Node>>& nodes,
const std::string& group = {});
263 std::weak_ptr<Node> node;
265 double creationTime {0.0};
270 static void validatePolicy(
const Policy&
policy);
271 static void validateSweepPolicy(
const SweepPolicy&
policy);
272 static void detachNodes(
const std::vector<std::shared_ptr<Node>>& nodes);
278 void performSweep(
double simulationTime);
280 bool shouldRemove(
const Entry& entry,
const Node& node,
double simulationTime)
const;
281 bool policyRemoves(
const Policy&
policy,
284 double simulationTime)
const;
286 void pruneInactiveEntries();
287 void enforceCountLimits(
const std::string& group);
288 void enforceMaxCount(std::size_t maxCount,
const std::string* group);
290 void resetSweepSchedule();
291 void resetRuntimeState();
295 std::vector<Entry> _entries;
297 std::unordered_map<std::string, Policy> _groupPolicies;
298 SweepPolicy _sweepPolicy;
299 std::uint64_t _updatesSinceSweep;
300 std::optional<double> _simulationTime;
301 std::optional<double> _nextSweepTime;
A transformable object in a Scene hierarchy.
Tracks transient scene nodes and removes them according to configurable policies.
Transients(SweepPolicy sweepPolicy=SweepPolicy::EveryUpdate())
Creates an empty registry with the supplied sweep policy.
void sweep(const Scene::StepInfo &info)
Immediately evaluates all swept removal policies.
~Transients()=default
Destroys the registry without removing tracked nodes.
void policy(const Policy &policy)
Replaces the global removal policy.
void track(const std::shared_ptr< Node > &node, const std::string &group={})
Tracks a transient node and immediately enforces applicable count limits.
void update(const Scene::StepInfo &info)
Advances registry scheduling and sweeps when the configured policy is due.
const Policy & policy() const
Returns the global removal policy.
void clear()
Forgets every tracked node and resets runtime scheduling state.
void groupPolicy(const std::string &group, const Policy &policy)
Replaces the removal policy for a named group.
void track(const std::vector< std::shared_ptr< Node > > &nodes, const std::string &group={})
Tracks a collection of nodes as members of the same transient group.
void sweepPolicy(const SweepPolicy &policy)
Replaces the scheduling policy used by update().
const SweepPolicy & sweepPolicy() const
Returns the scheduling policy used by update().
void untrack(const Node &node)
Stops tracking a node without removing it from its parent.
void removeAll()
Removes every live tracked node from its parent and clears the registry.
Timing information for one simulation step.
Maximum permitted world-space distance from a fixed point.
math::vec3 center
World-space center used for the distance test.
float radius
Maximum permitted distance from center.
Removal limits applied globally or to a named group.
std::optional< double > maxAge
Maximum node age in seconds of simulation time.
std::optional< std::size_t > maxCount
Maximum number of matching tracked nodes.
std::optional< DistanceLimit > distanceLimit
Maximum world-space distance from a fixed point.
Scheduling policy controlling when update() performs a sweep.
std::uint64_t updateInterval
Number of update() calls between sweeps in Mode::EveryNUpdates.
static SweepPolicy EveryNUpdates(std::uint64_t updates)
Creates a policy that sweeps after a fixed number of update() calls.
double timeInterval
Seconds of simulation time between sweeps in Mode::EveryInterval.
static SweepPolicy EveryUpdate()
Creates a policy that sweeps on every call to update().
static SweepPolicy EveryInterval(double seconds)
Creates a policy that sweeps at a fixed simulation-time interval.
Mode
Available sweep scheduling modes.
@ EveryUpdate
Sweep on every call to update().
Mode mode
Selected scheduling mode.