/
scheduler.h
87 lines (72 loc) · 2.37 KB
/
scheduler.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/** @file scheduler.h Script scheduling utility.
*
* @authors Copyright (c) 2015 Jaakko Keränen <jaakko.keranen@iki.fi>
*
* @par License
* LGPL: http://www.gnu.org/licenses/lgpl.html
*
* <small>This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at your
* option) any later version. This program is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
* General Public License for more details. You should have received a copy of
* the GNU Lesser General Public License along with this program; if not, see:
* http://www.gnu.org/licenses</small>
*/
#ifndef LIBDENG2_SCHEDULER_H
#define LIBDENG2_SCHEDULER_H
#include "../libcore.h"
#include "../Time"
#include "../String"
namespace de {
class Script;
class Record;
/**
* Script scheduling utility.
*
* Scheduler owns the parsed scripts, and can be re-run if rewound.
*/
class DENG2_PUBLIC Scheduler
{
public:
Scheduler();
void clear();
/**
* Sets the execution context, i.e., global namespace for the scripts. All
* scripts of the scheduler run in the same context.
*
* @param context Global namespace.
*/
void setContext(Record &context);
/**
* Adds a new script to the scheduler.
*
* @param at Point in time when the script is to be executed.
* @param source Script source. This will be parsed before the method returns.
* @param sourcePath Path where the source comes from.
*
* @return Scheduled Script (owned by Scheduler).
*/
Script &addScript(TimeDelta at, String const &source, String const &sourcePath = "");
/**
* Returns the current time of the scheduler.
*/
TimeDelta at() const;
/**
* Rewinds the current time of the Scheduler back to zero.
*/
void rewind();
/**
* Advances the current time of the Schduler and executes any scripts whose
* execution time has arrived.
*
* @param elapsed Time elapsed since the previous call.
*/
void advanceTime(TimeDelta const &elapsed);
private:
DENG2_PRIVATE(d)
};
} // namespace de
#endif // LIBDENG2_SCHEDULER_H