The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
pump.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2016 by David White <[email protected]>
3  Part of the Battle for Wesnoth Project http://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 /**
16  * @file
17  * Define the game's event mechanism.
18  *
19  * Events might be units moving or fighting, or when victory or defeat occurs.
20  * A scenario's configuration file will define actions to take when certain events occur.
21  * This module is responsible for the processing of events.
22  *
23  * Note that game events have nothing to do with SDL events,
24  * like mouse movement, keyboard events, etc.
25  * See events.hpp for how they are handled.
26  */
27 
28 #ifndef GAME_EVENTS_PUMP_H_INCLUDED
29 #define GAME_EVENTS_PUMP_H_INCLUDED
30 
32 #include "game_events/handlers.hpp"
33 
34 #include "config.hpp"
35 
36 #include<string>
37 #include<sstream>
38 
39 class game_display;
40 class vconfig;
41 
42 namespace lg { class logger; }
43 
44 namespace game_events
45 {
46  struct queued_event {
48  const entity_location& loc2, const config& data)
49  : name(name), loc1(loc1), loc2(loc2), data(data)
50  {
51  std::replace(this->name.begin(), this->name.end(), ' ', '_');
52  }
53 
58  };
59 
60  struct pump_impl;
61 
62  struct t_context;
63 
64  class manager;
65 
66  class t_pump {
67  boost::scoped_ptr<pump_impl> impl_;
68  public:
69  t_pump(manager &);
70  ~t_pump();
71  /// Context: The general environment within which events are processed.
72  /// Returns whether or not we believe WML might have changed something.
73  bool context_mutated();
74  /// Sets whether or not we believe WML might have changed something.
75  void context_mutated(bool mutated);
76  /// Returns whether or not we are skipping messages.
77  bool context_skip_messages();
78  /// Sets whether or not we are skipping messages.
79  void context_skip_messages(bool skip);
80 
81  /// Helper function which determines whether a wml_message text can
82  /// really be pushed into the wml_messages_stream, and does it.
83  void put_wml_message(const std::string& logger, const std::string& message, bool in_chat);
84 
85  /**
86  * Function to fire an event.
87  *
88  * Events may have up to two arguments, both of which must be locations.
89  */
90  bool fire(const std::string& event,
93  const config& data=config());
94 
95  void raise(const std::string& event,
98  const config& data=config());
99 
100  bool operator()();
101 
102  /**
103  * Flushes WML messages and errors.
104  */
105  void flush_messages();
106 
107  /**
108  * This function can be used to detect when no WML/Lua has been executed.
109  */
110  size_t wml_tracking();
111 
112  private:
113  bool filter_event(const event_handler& handler, const queued_event& ev);
114 
115  bool process_event(handler_ptr& handler_p, const queued_event& ev);
116 
117  void fill_wml_messages_map(std::map<std::string, int>& msg_map, std::stringstream& source);
118 
119  void show_wml_messages(std::stringstream& source, const std::string & caption, bool to_cerr);
120 
121  void show_wml_errors();
122 
123  void show_wml_messages();
124 
125  void put_wml_message(lg::logger& logger, const std::string& prefix, const std::string& message, bool in_chat);
126  };
127 }
128 
129 #endif // GAME_EVENTS_PUMP_H_INCLUDED
130 
bool context_skip_messages()
Returns whether or not we are skipping messages.
Definition: pump.cpp:442
static thandler * handler
Definition: handler.cpp:60
entity_location loc2
Definition: pump.hpp:56
boost::scoped_ptr< pump_impl > impl_
Definition: pump.hpp:67
t_pump(manager &)
Definition: pump.cpp:607
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())
Function to fire an event.
Definition: pump.cpp:471
void show_wml_messages()
Shows a summary of the messages generated so far by WML.
Definition: pump.cpp:395
std::string name
Definition: pump.hpp:54
void flush_messages()
Flushes WML messages and errors.
Definition: pump.cpp:577
bool process_event(handler_ptr &handler_p, const queued_event &ev)
Processes an event through a single event handler.
Definition: pump.cpp:279
GLint GLenum GLsizei GLint GLsizei const GLvoid * data
Definition: glew.h:1347
Definitions for the interface to Wesnoth Markup Language (WML).
static const entity_location null_entity
bool operator()()
Definition: pump.cpp:493
void fill_wml_messages_map(std::map< std::string, int > &msg_map, std::stringstream &source)
Helper function for show_wml_messages(), which gathers the messages from a stringstream.
Definition: pump.cpp:315
size_t wml_tracking()
This function can be used to detect when no WML/Lua has been executed.
Definition: pump.cpp:602
Domain specific events.
Definition: action_wml.cpp:93
Definition: pump.hpp:42
bool filter_event(const event_handler &handler, const queued_event &ev)
Returns true iff the given event passes all its filters.
Definition: pump.cpp:187
queued_event(const std::string &name, const entity_location &loc1, const entity_location &loc2, const config &data)
Definition: pump.hpp:47
The game event manager loads the scenario configuration object, and ensures that events are handled a...
Definition: manager.hpp:47
bool context_mutated()
Context: The general environment within which events are processed.
Definition: pump.cpp:430
std::string replace(std::string str, const std::string &src, const std::string &dst)
Replace all instances of src in str with dst.
GLuint const GLchar * name
Definition: glew.h:1782
entity_location loc1
Definition: pump.hpp:55
void show_wml_errors()
Shows a summary of the errors encountered in WML so far, to avoid a lot of the same messages to be sh...
Definition: pump.cpp:381
Define the handlers for the game's events mechanism.
cl_event event
Definition: glew.h:3070
A variable-expanding proxy for the config class.
Definition: variable.hpp:36
GLsizei GLenum GLuint GLuint GLsizei char * message
Definition: glew.h:2499
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
void put_wml_message(const std::string &logger, const std::string &message, bool in_chat)
Helper function which determines whether a wml_message text can really be pushed into the wml_message...
Definition: pump.cpp:458
GLsizei const GLcharARB ** string
Definition: glew.h:4503
GLsizei GLsizei GLchar * source
Definition: glew.h:1800
Define locations as used by the game's events mechanism.