Blender
V4.3
intern
ghost
intern
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
19
GHOST_TimerManager::GHOST_TimerManager
() {}
20
21
GHOST_TimerManager::~GHOST_TimerManager
()
22
{
23
disposeTimers
();
24
}
25
26
uint32_t
GHOST_TimerManager::getNumTimers
()
27
{
28
return
uint32_t
(
m_timers
.size());
29
}
30
31
bool
GHOST_TimerManager::getTimerFound
(
GHOST_TimerTask
*
timer
)
32
{
33
TTimerVector::const_iterator iter = std::find(
m_timers
.begin(),
m_timers
.end(),
timer
);
34
return
iter !=
m_timers
.end();
35
}
36
37
GHOST_TSuccess
GHOST_TimerManager::addTimer
(
GHOST_TimerTask
*
timer
)
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
51
GHOST_TSuccess
GHOST_TimerManager::removeTimer
(
GHOST_TimerTask
*
timer
)
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
67
uint64_t
GHOST_TimerManager::nextFireTime
()
68
{
69
uint64_t
smallest =
GHOST_kFireTimeNever
;
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
83
bool
GHOST_TimerManager::fireTimers
(
uint64_t
time)
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
97
bool
GHOST_TimerManager::fireTimer
(
uint64_t
time,
GHOST_TimerTask
*task)
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
120
void
GHOST_TimerManager::disposeTimers
()
121
{
122
while
(
m_timers
.empty() ==
false
) {
123
delete
m_timers
[0];
124
m_timers
.erase(
m_timers
.begin());
125
}
126
}
GHOST_TimerManager.hh
GHOST_TimerTask.hh
GHOST_TimerProcPtr
void(* GHOST_TimerProcPtr)(struct GHOST_TimerTaskHandle__ *task, uint64_t time)
Definition
GHOST_Types.h:774
GHOST_TSuccess
GHOST_TSuccess
Definition
GHOST_Types.h:87
GHOST_kFailure
@ GHOST_kFailure
Definition
GHOST_Types.h:87
GHOST_kSuccess
@ GHOST_kSuccess
Definition
GHOST_Types.h:87
GHOST_kFireTimeNever
@ GHOST_kFireTimeNever
Definition
GHOST_Types.h:182
GHOST_TimerManager::GHOST_TimerManager
GHOST_TimerManager()
Definition
GHOST_TimerManager.cc:19
GHOST_TimerManager::getNumTimers
uint32_t getNumTimers()
Definition
GHOST_TimerManager.cc:26
GHOST_TimerManager::fireTimers
bool fireTimers(uint64_t time)
Definition
GHOST_TimerManager.cc:83
GHOST_TimerManager::removeTimer
GHOST_TSuccess removeTimer(GHOST_TimerTask *timer)
Definition
GHOST_TimerManager.cc:51
GHOST_TimerManager::fireTimer
bool fireTimer(uint64_t time, GHOST_TimerTask *task)
Definition
GHOST_TimerManager.cc:97
GHOST_TimerManager::getTimerFound
bool getTimerFound(GHOST_TimerTask *timer)
Definition
GHOST_TimerManager.cc:31
GHOST_TimerManager::disposeTimers
void disposeTimers()
Definition
GHOST_TimerManager.cc:120
GHOST_TimerManager::nextFireTime
uint64_t nextFireTime()
Definition
GHOST_TimerManager.cc:67
GHOST_TimerManager::addTimer
GHOST_TSuccess addTimer(GHOST_TimerTask *timer)
Definition
GHOST_TimerManager.cc:37
GHOST_TimerManager::m_timers
TTimerVector m_timers
Definition
GHOST_TimerManager.hh:93
GHOST_TimerManager::~GHOST_TimerManager
~GHOST_TimerManager()
Definition
GHOST_TimerManager.cc:21
GHOST_TimerTask
Definition
GHOST_TimerTask.hh:17
next
static ulong * next
Definition
mathutils_noise.cc:59
uint32_t
unsigned int uint32_t
Definition
stdint.h:80
uint64_t
unsigned __int64 uint64_t
Definition
stdint.h:90
timer
wmTimer * timer
Definition
uvedit_unwrap_ops.cc:2061
Generated on Thu Feb 6 2025 07:36:39 for Blender by
doxygen
1.11.0