summaryrefslogtreecommitdiffstats
path: root/engine/flattask.cpp
blob: 02e584eb4ad37a064c60766390c32debfbf9be96 (plain)
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
#include "flattask.h"

bool task_prior::operator()(task_s* s, task_s* g) const
{
    return s->getPriority() <= g->getPriority();
}

/* Static variable definition */
task_set task_s::pre_process_tasks;
task_set task_s::post_process_tasks;

task_s::task_s(bool pre_process, Uint8 priority) 

    : pre_process(pre_process), priority(priority)
{
    /* Push into the public callback list */
    if (pre_process)
        pre_process_tasks.insert(this);
    else
        post_process_tasks.insert(this);
}

task_s::~task_s()
{
    /* Remove from the public callback list */
    if (pre_process)
        pre_process_tasks.erase(this);
    else
        post_process_tasks.erase(this);
}

Uint8 task_s::getPriority() const
{
    return priority;
}
    
void task_s::setPriority(Uint8 priority)
{
    this->priority = priority;
}

void task_s::executePreProcess()
{
    for (task_s * task : task_s::pre_process_tasks)
        task->exec();
}

void task_s::executePostProcess()
{
    for (task_s * task : task_s::post_process_tasks)
        task->exec();
}