4 * This file is part of OpenTTD.
5 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
6 * OpenTTD 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.
7 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
10 /** @file script_event.cpp Implementation of ScriptEvent. */
12 #include "../../stdafx.h"
13 #include "script_event_types.hpp"
17 #include "../../safeguards.h"
19 /** The queue of events for a script. */
20 struct ScriptEventData
{
21 std::queue
<ScriptEvent
*> stack
; ///< The actual queue.
24 /* static */ void ScriptEventController::CreateEventPointer()
26 assert(ScriptObject::GetEventPointer() == NULL
);
28 ScriptObject::GetEventPointer() = new ScriptEventData();
31 /* static */ void ScriptEventController::FreeEventPointer()
33 ScriptEventData
*data
= (ScriptEventData
*)ScriptObject::GetEventPointer();
35 /* Free all waiting events (if any) */
36 while (!data
->stack
.empty()) {
37 ScriptEvent
*e
= data
->stack
.front();
42 /* Now kill our data pointer */
46 /* static */ bool ScriptEventController::IsEventWaiting()
48 if (ScriptObject::GetEventPointer() == NULL
) ScriptEventController::CreateEventPointer();
49 ScriptEventData
*data
= (ScriptEventData
*)ScriptObject::GetEventPointer();
51 return !data
->stack
.empty();
54 /* static */ ScriptEvent
*ScriptEventController::GetNextEvent()
56 if (ScriptObject::GetEventPointer() == NULL
) ScriptEventController::CreateEventPointer();
57 ScriptEventData
*data
= (ScriptEventData
*)ScriptObject::GetEventPointer();
59 if (data
->stack
.empty()) return NULL
;
61 ScriptEvent
*e
= data
->stack
.front();
66 /* static */ void ScriptEventController::InsertEvent(ScriptEvent
*event
)
68 if (ScriptObject::GetEventPointer() == NULL
) ScriptEventController::CreateEventPointer();
69 ScriptEventData
*data
= (ScriptEventData
*)ScriptObject::GetEventPointer();
72 data
->stack
.push(event
);