VR-Engage  2.3
Loading...
Searching...
No Matches
functionQueue.h
Go to the documentation of this file.
1/*********************************************************************************
2** Copyright (c) 2026 MAK Technologies
3** All rights reserved.
4*********************************************************************************/
5
6#pragma once
7
8//! \file functionQueue.h
9//! \brief Deferred function queue
10
11#include "vreUtil/export.h"
12
13#include <functional>
14#include <list>
15#include <utility>
16
17namespace makVrv
18{
19class DtDe;
20}
21
22namespace makVre
23{
24
26{
27public:
28 DtFunctionQueue() = default;
30
36
37 //! \brief Defers a function to be executed after a number of ticks
38 //! \param f Function to execute
39 //! \param delayInTicks Number of ticks to wait before execution (default: 0)
40 //! \param timing Tick phase in which to execute: PRE_TICK or POST_TICK (default: PRE_TICK)
41 //!
42 //! Schedules a function to be executed after the specified number of ticks.
43 void add(std::function<void()> f, int delayInTicks = 0, ExecTiming timing = PRE_TICK);
44
45 //! \brief Defers a function to be executed after a time delay
46 //! \param f Function to execute
47 //! \param delayInSeconds Seconds to wait before execution
48 //! \param timing Tick phase in which to execute: PRE_TICK or POST_TICK (default: PRE_TICK)
49 //!
50 //! Schedules a function to be executed after the specified time delay in seconds.
51 void add(std::function<void()> f, double delayInSeconds, ExecTiming timing = PRE_TICK);
52
53protected:
54 //! \brief Structure for deferred function execution
55 //!
56 //! Stores a list of functions to be executed after a delay.
57 //! Functions are executed on DtDe preTick or postTick once tick delay or timer reaches zero.
59 {
60 //! \brief Function to be executed
61 std::function<void()> f;
62
63 //! \brief Number of ticks to wait before execution
64 int ticks;
65
66 //! \brief Time in seconds to wait before execution
67 double time;
68
69 //! \brief Constructor
70 //! \param _f Function to execute
71 //! \param _ticks Number of ticks to wait
72 //! \param _time Time in seconds to wait
73 QueuedFunction(std::function<void()> _f, int _ticks, double _time)
74 : f(std::move(_f))
75 , ticks(_ticks)
76 , time(_time)
77 {
78 }
79 };
80
81 void preTick(makVrv::DtDe&);
82 void postTick();
84 void processQueue(std::list<QueuedFunction>& queue, double dt);
85
86 //! \brief List of deferred functions
87 //!
88 //! Contains functions that are scheduled to be executed after a delay.
89 std::list<QueuedFunction> myPreTickQueue;
90 std::list<QueuedFunction> myPostTickQueue;
91
92 bool myTicksConnected = false;
93 double myPreTickLastTime = 0.0;
94 double myPostTickLastTime = 0.0;
95
96 makVrv::DtDe* myDe = nullptr;
97};
98
99}//namespace makVre
bool myTicksConnected
Definition functionQueue.h:92
makVrv::DtDe * myDe
Definition functionQueue.h:96
double myPreTickLastTime
Definition functionQueue.h:93
std::list< QueuedFunction > myPreTickQueue
List of deferred functions.
Definition functionQueue.h:89
void add(std::function< void()> f, double delayInSeconds, ExecTiming timing=PRE_TICK)
Defers a function to be executed after a time delay.
void preTick(makVrv::DtDe &)
void add(std::function< void()> f, int delayInTicks=0, ExecTiming timing=PRE_TICK)
Defers a function to be executed after a number of ticks.
std::list< QueuedFunction > myPostTickQueue
Definition functionQueue.h:90
void processQueue(std::list< QueuedFunction > &queue, double dt)
double myPostTickLastTime
Definition functionQueue.h:94
ExecTiming
Definition functionQueue.h:32
@ PRE_TICK
Definition functionQueue.h:33
@ POST_TICK
Definition functionQueue.h:34
Defines export macros for the VREngage Utility library.
#define UTIL_DLL
Export/import macro for non-Windows platforms.
Definition export.h:39
!
Definition glsVreMessageUtil.h:50
Definition appLauncherComponent.h:28
double time
Time in seconds to wait before execution.
Definition functionQueue.h:67
std::function< void()> f
Function to be executed.
Definition functionQueue.h:61
QueuedFunction(std::function< void()> _f, int _ticks, double _time)
Constructor.
Definition functionQueue.h:73
int ticks
Number of ticks to wait before execution.
Definition functionQueue.h:64