Blender V4.3
GHOST_TimerManager.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
13#include "GHOST_TimerManager.hh"
14
15#include <algorithm>
16
17#include "GHOST_TimerTask.hh"
18
20
25
30
32{
33 TTimerVector::const_iterator iter = std::find(m_timers.begin(), m_timers.end(), timer);
34 return iter != m_timers.end();
35}
36
38{
39 GHOST_TSuccess success;
40 if (!getTimerFound(timer)) {
41 /* Add the timer task. */
42 m_timers.push_back(timer);
43 success = GHOST_kSuccess;
44 }
45 else {
46 success = GHOST_kFailure;
47 }
48 return success;
49}
50
52{
53 GHOST_TSuccess success;
54 TTimerVector::iterator iter = std::find(m_timers.begin(), m_timers.end(), timer);
55 if (iter != m_timers.end()) {
56 /* Remove the timer task. */
57 m_timers.erase(iter);
58 delete timer;
59 success = GHOST_kSuccess;
60 }
61 else {
62 success = GHOST_kFailure;
63 }
64 return success;
65}
66
68{
70 TTimerVector::iterator iter;
71
72 for (iter = m_timers.begin(); iter != m_timers.end(); ++iter) {
73 const uint64_t next = (*iter)->getNext();
74
75 if (next < smallest) {
76 smallest = next;
77 }
78 }
79
80 return smallest;
81}
82
84{
85 TTimerVector::iterator iter;
86 bool anyProcessed = false;
87
88 for (iter = m_timers.begin(); iter != m_timers.end(); ++iter) {
89 if (fireTimer(time, *iter)) {
90 anyProcessed = true;
91 }
92 }
93
94 return anyProcessed;
95}
96
98{
99 uint64_t next = task->getNext();
100
101 /* Check if the timer should be fired. */
102 if (time > next) {
103 /* Fire the timer. */
104 GHOST_TimerProcPtr timerProc = task->getTimerProc();
105 uint64_t start = task->getStart();
106 timerProc(task, time - start);
107
108 /* Update the time at which we will fire it again. */
109 uint64_t interval = task->getInterval();
110 uint64_t numCalls = (next - start) / interval;
111 numCalls++;
112 next = start + numCalls * interval;
113 task->setNext(next);
114
115 return true;
116 }
117 return false;
118}
119
121{
122 while (m_timers.empty() == false) {
123 delete m_timers[0];
124 m_timers.erase(m_timers.begin());
125 }
126}
void(* GHOST_TimerProcPtr)(struct GHOST_TimerTaskHandle__ *task, uint64_t time)
GHOST_TSuccess
Definition GHOST_Types.h:87
@ GHOST_kFailure
Definition GHOST_Types.h:87
@ GHOST_kSuccess
Definition GHOST_Types.h:87
@ GHOST_kFireTimeNever
bool fireTimers(uint64_t time)
GHOST_TSuccess removeTimer(GHOST_TimerTask *timer)
bool fireTimer(uint64_t time, GHOST_TimerTask *task)
bool getTimerFound(GHOST_TimerTask *timer)
GHOST_TSuccess addTimer(GHOST_TimerTask *timer)
static ulong * next
unsigned int uint32_t
Definition stdint.h:80
unsigned __int64 uint64_t
Definition stdint.h:90
wmTimer * timer