Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Event handler buffering is no longer needed.

Fixes bug #18713.
  • Loading branch information...
commit 3a78062d3e0cc8b48d4e5e5bc226fc3aac0a37d9 1 parent 21ae9bb
Ja-MiT authored November 02, 2013
2  changelog
@@ -137,6 +137,8 @@ Version 1.11.6+dev:
137 137
    * Some support for negative healing. This is not guaranteed to work correctly
138 138
      in all cases, but it does restore the basic functionality that was
139 139
      (probably accidentally) in 1.10.
  140
+   * Overhaul of the game events engine. Among less noticeable details, this
  141
+     grants feature request #18713.
140 142
  * Units:
141 143
    * Gave the Death Knight proper skeletal resistances, as well as submerge.
142 144
  * User interface:
131  src/game_events/handlers.cpp
@@ -60,9 +60,6 @@ namespace { // Types
60 60
 
61 61
 	private:
62 62
 		handler_vec active_; ///Active event handlers. Will not have elements removed unless the t_event_handlers is clear()ed.
63  
-		handler_vec insert_buffer_; ///Event handlers added while pumping events
64  
-		std::set<std::string> remove_buffer_; ///Event handlers removed while pumping events
65  
-		bool buffering_;
66 63
 
67 64
 
68 65
 		void log_handler(std::stringstream& ss,
@@ -74,18 +71,13 @@ namespace { // Types
74 71
 		typedef handler_vec::size_type size_type;
75 72
 
76 73
 		t_event_handlers()
77  
-			: active_(), insert_buffer_(), remove_buffer_(), buffering_(false)
  74
+			: active_()
78 75
 		{}
79 76
 
80 77
 		/// Adds an event handler.
81 78
 		void add_event_handler(const config & cfg, bool is_menu_item=false);
82 79
 		/// Removes an event handler, identified by its ID.
83 80
 		void remove_event_handler(std::string const & id);
84  
-		/// Starts buffering.
85  
-		void start_buffering();
86  
-		void stop_buffering();
87  
-		/// Commits all buffered events.
88  
-		void commit_buffer();
89 81
 		void clear();
90 82
 
91 83
 		iterator begin() { return active_.begin(); }
@@ -120,54 +112,39 @@ namespace { // Types
120 112
 
121 113
 		std::stringstream ss;
122 114
 		log_handler(ss, active_, "active");
123  
-		log_handler(ss, insert_buffer_, "insert buffered");
124  
-		BOOST_FOREACH(const std::string& h, remove_buffer_){
125  
-			ss << "id=" << h << "; ";
126  
-		}
127  
-		DBG_EH << "remove buffered handlers are now " << ss.str() << "\n";
128 115
 	}
129 116
 
130 117
 	/**
131 118
 	 * Adds an event handler.
132 119
 	 * An event with a nonempty ID will not be added if an event with that
133  
-	 * ID already exists.  This method respects this class's buffering
134  
-	 * functionality.
  120
+	 * ID already exists.
135 121
 	 */
136 122
 	void t_event_handlers::add_event_handler(const config & cfg, bool is_menu_item)
137 123
 	{
138  
-		if(buffering_) {
139  
-			DBG_EH << "buffering event handler for name=" << cfg["name"] <<
140  
-			" with id " << cfg["id"] << "\n";
141  
-			insert_buffer_.push_back(handler_ptr(new event_handler(cfg, is_menu_item)));
142  
-			log_handlers();
143  
-		}
144  
-		else {
145  
-			std::string id = cfg["id"];
146  
-			if(!id.empty()) {
147  
-				BOOST_FOREACH( handler_ptr const & eh, active_ ) {
148  
-					if ( !eh )
149  
-						continue;
150  
-					config const & temp_config(eh->get_config());
151  
-					if(id == temp_config["id"]) {
152  
-						DBG_EH << "ignoring event handler for name=" << cfg["name"] <<
153  
-							" with id " << id << "\n";
154  
-						return;
155  
-					}
  124
+		std::string id = cfg["id"];
  125
+		if(!id.empty()) {
  126
+			BOOST_FOREACH( handler_ptr const & eh, active_ ) {
  127
+				if ( !eh )
  128
+					continue;
  129
+				config const & temp_config(eh->get_config());
  130
+				if(id == temp_config["id"]) {
  131
+					DBG_EH << "ignoring event handler for name=" << cfg["name"] <<
  132
+						" with id " << id << "\n";
  133
+					return;
156 134
 				}
157 135
 			}
158  
-			DBG_EH << "inserting event handler for name=" << cfg["name"] <<
159  
-				" with id=" << id << "\n";
160  
-			handler_ptr new_handler(new event_handler(cfg, is_menu_item));
161  
-			new_handler->set_index(active_.size());
162  
-			active_.push_back(new_handler);
163  
-			log_handlers();
164 136
 		}
  137
+		DBG_EH << "inserting event handler for name=" << cfg["name"] <<
  138
+			" with id=" << id << "\n";
  139
+		handler_ptr new_handler(new event_handler(cfg, is_menu_item));
  140
+		new_handler->set_index(active_.size());
  141
+		active_.push_back(new_handler);
  142
+		log_handlers();
165 143
 	}
166 144
 
167 145
 	/**
168 146
 	 * Removes an event handler, identified by its ID.
169  
-	 * Events with empty IDs cannot be removed.  This method respects this
170  
-	 * class's buffering functionality.
  147
+	 * Events with empty IDs cannot be removed.
171 148
 	 */
172 149
 	void t_event_handlers::remove_event_handler(std::string const & id)
173 150
 	{
@@ -176,12 +153,8 @@ namespace { // Types
176 153
 
177 154
 		DBG_EH << "removing event handler with id " << id << "\n";
178 155
 
179  
-		// If buffering, remember this ID for later.
180  
-		if(buffering_) { remove_buffer_.insert(id); }
181  
-
182 156
 		// Loop through the applicable handler_vec.
183  
-		handler_vec &temp = buffering_ ? insert_buffer_ : active_;
184  
-		for ( handler_vec::iterator i = temp.begin(); i != temp.end(); ++i ) {
  157
+		for ( handler_vec::iterator i = active_.begin(); i != active_.end(); ++i ) {
185 158
 			if ( !*i )
186 159
 				continue;
187 160
 			// Try to match the id
@@ -192,55 +165,9 @@ namespace { // Types
192 165
 		log_handlers();
193 166
 	}
194 167
 
195  
-	/**
196  
-	 * Starts buffering.
197  
-	 * While buffering, any calls to add_event_handler() and
198  
-	 * remove_event_handler() will not take effect until commit_buffer()
199  
-	 * is called.  This function is idempotent - starting a buffer
200  
-	 * when already buffering will not start a second buffer.
201  
-	 */
202  
-	void t_event_handlers::start_buffering()
203  
-	{
204  
-		buffering_ = true;
205  
-		DBG_EH << "starting buffering...\n";
206  
-	}
207  
-
208  
-	void t_event_handlers::stop_buffering()
209  
-	{
210  
-		DBG_EH << "stopping buffering...\n";
211  
-		buffering_ = false;
212  
-	}
213  
-
214  
-	/**
215  
-	 * Commits all buffered events.
216  
-	 */
217  
-	void t_event_handlers::commit_buffer()
218  
-	{
219  
-		DBG_EH << "committing buffered event handlers, buffering: " << buffering_ << "\n";
220  
-		if(buffering_)
221  
-			return;
222  
-
223  
-		// Commit any event removals
224  
-		BOOST_FOREACH( std::string const & i, remove_buffer_ ){
225  
-			remove_event_handler(i); }
226  
-		remove_buffer_.clear();
227  
-
228  
-		// Commit any spawned events-within-events
229  
-		BOOST_FOREACH( handler_ptr const & i, insert_buffer_ ){
230  
-			if ( !i )
231  
-				continue;
232  
-			add_event_handler(i->get_config(), i->is_menu_item()); }
233  
-		insert_buffer_.clear();
234  
-
235  
-		log_handlers();
236  
-	}
237  
-
238 168
 	void t_event_handlers::clear()
239 169
 	{
240 170
 		active_.clear();
241  
-		insert_buffer_.clear();
242  
-		remove_buffer_.clear();
243  
-		buffering_ = false;
244 171
 	}
245 172
 
246 173
 }// end anonymous namespace (types)
@@ -394,24 +321,6 @@ manager::~manager() {
394 321
 	used_items.clear();
395 322
 }
396 323
 
397  
-/** Starts buffering event handler creation. */
398  
-void manager::start_buffering()
399  
-{
400  
-	event_handlers.start_buffering();
401  
-}
402  
-
403  
-/** Ends buffering event handler creation. */
404  
-void manager::stop_buffering()
405  
-{
406  
-	event_handlers.stop_buffering();
407  
-}
408  
-
409  
-/** Commits the event handlers that were buffered. */
410  
-void manager::commit_buffer()
411  
-{
412  
-	event_handlers.commit_buffer();
413  
-}
414  
-
415 324
 
416 325
 /* ** manager::iteration ** */
417 326
 
7  src/game_events/handlers.hpp
@@ -123,13 +123,6 @@ namespace game_events
123 123
 		/// and must remain valid for the life of the object.
124 124
 		explicit manager(const config& scenario_cfg);
125 125
 		~manager();
126  
-
127  
-		/// Starts buffering event handler creation.
128  
-		static void start_buffering();
129  
-		/// Ends buffering event handler creation.
130  
-		static void stop_buffering();
131  
-		/// Commits the event handlers that were buffered.
132  
-		static void commit_buffer();
133 126
 	};
134 127
 
135 128
 	/// Create an event handler.
8  src/game_events/pump.cpp
@@ -480,9 +480,6 @@ bool pump()
480 480
 	// Loop through the events we need to process.
481 481
 	while ( !pump_instance.done() )
482 482
 	{
483  
-		if(pump_manager::count() <= 1)
484  
-			manager::start_buffering();
485  
-
486 483
 		queued_event & ev = pump_instance.next();
487 484
 		const std::string& event_name = ev.name;
488 485
 
@@ -518,8 +515,6 @@ bool pump()
518 515
 			}
519 516
 		}
520 517
 
521  
-		if(pump_manager::count() <= 1)
522  
-			manager::stop_buffering();
523 518
 		// Only commit new handlers when finished iterating over event_handlers.
524 519
 		commit();
525 520
 	}
@@ -540,9 +535,8 @@ void clear_events()
540 535
 
541 536
 void commit()
542 537
 {
543  
-	DBG_EH << "committing new event handlers, number of pump_instances: " <<
  538
+	DBG_EH << "committing new WML menu item commands; number of pump_instances: " <<
544 539
 	          pump_manager::count() << "\n";
545  
-	manager::commit_buffer();
546 540
 	commit_wmi_commands();
547 541
 	// Dialogs can only be shown if the display is not locked
548 542
 	if (!resources::screen->video().update_locked()) {

0 notes on commit 3a78062

Please sign in to comment.
Something went wrong with that request. Please try again.