Otclient
14/8/2020
scheduledevent.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2010-2020 OTClient <https://github.com/edubart/otclient>
3
*
4
* Permission is hereby granted, free of charge, to any person obtaining a copy
5
* of this software and associated documentation files (the "Software"), to deal
6
* in the Software without restriction, including without limitation the rights
7
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
* copies of the Software, and to permit persons to whom the Software is
9
* furnished to do so, subject to the following conditions:
10
*
11
* The above copyright notice and this permission notice shall be included in
12
* all copies or substantial portions of the Software.
13
*
14
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
* THE SOFTWARE.
21
*/
22
23
#ifndef SCHEDULEDEVENT_H
24
#define SCHEDULEDEVENT_H
25
26
#include "
event.h
"
27
#include "
clock.h
"
28
29
// @bindclass
30
class
ScheduledEvent
:
public
Event
31
{
32
public
:
33
ScheduledEvent
(
const
std::function<
void
()>& callback,
int
delay
,
int
maxCycles
);
34
void
execute
();
35
bool
nextCycle
();
36
37
int
ticks
() {
return
m_ticks; }
38
int
remainingTicks
() {
return
m_ticks -
g_clock
.
millis
(); }
39
int
delay
() {
return
m_delay; }
40
int
cyclesExecuted
() {
return
m_cyclesExecuted; }
41
int
maxCycles
() {
return
m_maxCycles; }
42
43
private
:
44
ticks_t
m_ticks;
45
int
m_delay;
46
int
m_maxCycles;
47
int
m_cyclesExecuted;
48
};
49
50
struct
lessScheduledEvent
: std::binary_function<ScheduledEventPtr, ScheduledEventPtr&, bool> {
51
bool
operator()
(
const
ScheduledEventPtr
& a,
const
ScheduledEventPtr
& b) {
52
return
b->
ticks
() < a->
ticks
();
53
}
54
};
55
56
#endif
ScheduledEvent::ticks
int ticks()
Definition:
scheduledevent.h:37
ScheduledEvent::remainingTicks
int remainingTicks()
Definition:
scheduledevent.h:38
ScheduledEvent::execute
void execute()
Definition:
scheduledevent.cpp:33
ScheduledEvent::ScheduledEvent
ScheduledEvent(const std::function< void()> &callback, int delay, int maxCycles)
Definition:
scheduledevent.cpp:25
ticks_t
int64 ticks_t
Definition:
types.h:43
ScheduledEvent::maxCycles
int maxCycles()
Definition:
scheduledevent.h:41
ScheduledEvent::cyclesExecuted
int cyclesExecuted()
Definition:
scheduledevent.h:40
clock.h
Event
Definition:
event.h:29
ScheduledEvent::nextCycle
bool nextCycle()
Definition:
scheduledevent.cpp:47
event.h
lessScheduledEvent::operator()
bool operator()(const ScheduledEventPtr &a, const ScheduledEventPtr &b)
Definition:
scheduledevent.h:51
lessScheduledEvent
Definition:
scheduledevent.h:50
ScheduledEvent::delay
int delay()
Definition:
scheduledevent.h:39
stdext::shared_object_ptr< ScheduledEvent >
ScheduledEvent
Definition:
scheduledevent.h:30
Clock::millis
ticks_t millis()
Definition:
clock.h:37
g_clock
Clock g_clock
Definition:
clock.cpp:25
src
framework
core
scheduledevent.h
Generated by
1.8.17
For more information visit
https://forum.opentibia.dev/