-
-
Notifications
You must be signed in to change notification settings - Fork 994
/
pump.hpp
135 lines (108 loc) · 4.04 KB
/
pump.hpp
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*
Copyright (C) 2003 - 2014 by David White <dave@whitevine.net>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program 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; either version 2 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.
See the COPYING file for more details.
*/
/**
* @file
* Define the game's event mechanism.
*
* Events might be units moving or fighting, or when victory or defeat occurs.
* A scenario's configuration file will define actions to take when certain events occur.
* This module is responsible for the processing of events.
*
* Note that game events have nothing to do with SDL events,
* like mouse movement, keyboard events, etc.
* See events.hpp for how they are handled.
*/
#ifndef GAME_EVENTS_PUMP_H_INCLUDED
#define GAME_EVENTS_PUMP_H_INCLUDED
#include "entity_location.hpp"
#include "../config.hpp"
class vconfig;
namespace game_events
{
struct queued_event {
queued_event(const std::string& name, const entity_location& loc1,
const entity_location& loc2, const config& data)
: name(name), loc1(loc1), loc2(loc2), data(data)
{}
std::string name;
entity_location loc1;
entity_location loc2;
config data;
};
/// The general environment within which events are processed.
class context {
/// State when processing a particular flight of events or commands.
struct state {
bool mutated;
bool skip_messages;
explicit state(bool s) : mutated(true), skip_messages(s) {}
};
public:
/// Context state with automatic lifetime handling.
class scoped {
public:
scoped();
~scoped();
private:
context::state *old_context_;
context::state new_context_;
};
friend class scoped;
public:
// No constructor needed since this is a static-only class for now.
/// Returns whether or not we believe WML might have changed something.
static bool mutated() { return current_context_->mutated; }
/// Sets whether or not we believe WML might have changed something.
static void mutated(bool mutated) { current_context_->mutated = mutated; }
/// Returns whether or not the screen (map visuals) needs to be rebuilt.
static bool screen_needs_rebuild() { return rebuild_screen_; }
/// Sets whether or not the screen (map visuals) needs to be rebuilt.
static void screen_needs_rebuild(bool rebuild) { rebuild_screen_ = rebuild; }
/// Returns whether or not we are skipping messages.
static bool skip_messages() { return current_context_->skip_messages; }
/// Sets whether or not we are skipping messages.
static void skip_messages(bool skip) { current_context_->skip_messages = skip; }
private:
static state * current_context_;
static bool rebuild_screen_;
/// A default value used to avoid NULL pointers.
static state default_context_;
};
/// Helper function which determines whether a wml_message text can
/// really be pushed into the wml_messages_stream, and does it.
void put_wml_message(const std::string& logger, const std::string& message, bool in_chat);
/**
* Function to fire an event.
*
* Events may have up to two arguments, both of which must be locations.
*/
bool fire(const std::string& event,
const entity_location& loc1=entity_location::null_entity,
const entity_location& loc2=entity_location::null_entity,
const config& data=config());
void raise(const std::string& event,
const entity_location& loc1=entity_location::null_entity,
const entity_location& loc2=entity_location::null_entity,
const config& data=config());
bool pump();
/// Clears all events tha have been raised (and not pumped).
void clear_events();
/**
* Flushes WML messages and errors.
*/
void flush_messages();
/**
* This function can be used to detect when no WML/Lua has been executed.
*/
size_t wml_tracking();
}
#endif // GAME_EVENTS_PUMP_H_INCLUDED