Legends-of-Azeroth-Pandaria-5.4.8

Форк
0
119 строк · 3.0 Кб
1
/*
2
* This file is part of the Pandaria 5.4.8 Project. See THANKS file for Copyright information
3
*
4
* This program is free software; you can redistribute it and/or modify it
5
* under the terms of the GNU General Public License as published by the
6
* Free Software Foundation; either version 2 of the License, or (at your
7
* option) any later version.
8
*
9
* This program is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12
* more details.
13
*
14
* You should have received a copy of the GNU General Public License along
15
* with this program. If not, see <http://www.gnu.org/licenses/>.
16
*/
17

18
#include "EventProcessor.h"
19

20
bool RepeatableFunctionEvent::Execute(uint64, uint32)
21
{
22
    if (m_function())
23
        return true;
24

25
    m_events->Schedule(m_repeat, this);
26
    return false;
27
}
28

29
EventProcessor::EventProcessor()
30
{
31
    m_time = 0;
32
    m_aborting = false;
33
}
34

35
EventProcessor::~EventProcessor()
36
{
37
    KillAllEvents(true);
38
}
39

40
void EventProcessor::Update(uint32 p_time)
41
{
42
    // update time
43
    m_time += p_time;
44

45
    // main event loop
46
    EventList::iterator i;
47
    while (((i = m_events.begin()) != m_events.end()) && i->first <= m_time)
48
    {
49
        // get and remove event from queue
50
        BasicEvent* Event = i->second;
51
        m_events.erase(i);
52

53
        if (!Event->to_Abort)
54
        {
55
            if (Event->Execute(m_time, p_time))
56
            {
57
                // completely destroy event if it is not re-added
58
                delete Event;
59
            }
60
        }
61
        else
62
        {
63
            Event->Abort(m_time);
64
            delete Event;
65
        }
66
    }
67
}
68

69
void EventProcessor::KillAllEvents(bool force)
70
{
71
    // prevent event insertions
72
    m_aborting = true;
73

74
    // first, abort all existing events
75
    for (EventList::iterator i = m_events.begin(); i != m_events.end();)
76
    {
77
        EventList::iterator i_old = i;
78
        ++i;
79

80
        i_old->second->to_Abort = true;
81
        i_old->second->Abort(m_time);
82
        if (force || i_old->second->IsDeletable())
83
        {
84
            delete i_old->second;
85

86
            if (!force)                                      // need per-element cleanup
87
                m_events.erase (i_old);
88
        }
89
    }
90

91
    // fast clear event list (in force case)
92
    if (force)
93
        m_events.clear();
94
}
95

96
void EventProcessor::AddEvent(BasicEvent* Event, uint64 e_time, bool set_addtime)
97
{
98
    if (set_addtime) Event->m_addTime = m_time;
99
    Event->m_execTime = e_time;
100
    m_events.insert(std::pair<uint64, BasicEvent*>(e_time, Event));
101
}
102

103
void EventProcessor::RescheduleEvent(BasicEvent* event, uint64 e_time)
104
{
105
    for (auto itr = m_events.begin(); itr != m_events.end(); ++itr)
106
    {
107
        if (itr->second == event)
108
        {
109
            m_events.erase(itr);
110
            m_events.insert(std::pair<uint64, BasicEvent*>(e_time, event));
111
            break;
112
        }
113
    }
114
}
115

116
uint64 EventProcessor::CalculateTime(uint64 t_offset) const
117
{
118
    return(m_time + t_offset);
119
}
120

121

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.