The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
fake_unit_manager.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014 - 2016 by Chris Beck <[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 #include "fake_unit_manager.hpp"
16 
17 #include "display.hpp"
18 #include "fake_unit_ptr.hpp"
19 #include "log.hpp"
20 #include "units/unit.hpp"
22 
23 static lg::log_domain log_engine("engine");
24 #define ERR_NG LOG_STREAM(err, log_engine)
25 
26 /** Temporarily register a unit to be drawn on the map (moving: can overlap others).
27  * The temp unit is added at the end of the temporary unit dequeue,
28  * and therefore gets drawn last, over other units and temp units.
29  * Adding the same unit twice isn't allowed.
30  */
32 {
33  if(std::find(fake_units_.begin(),fake_units_.end(), u) != fake_units_.end()) {
34  ERR_NG << "In fake_unit_manager::place_temporary_unit: attempt to add duplicate fake unit." << std::endl;
35  } else {
36  fake_units_.push_back(u);
37  my_display_.invalidate(u->get_location());
38  }
39 }
40 
41 /** Removes any instances of this unit from the temporary unit database. */
43 {
44  int removed = 0;
46  std::remove(fake_units_.begin(), fake_units_.end(), u);
47  if (it != fake_units_.end()) {
48  removed = std::distance(it, fake_units_.end());
49  //std::remove doesn't remove anything without using erase afterwards.
50  fake_units_.erase(it, fake_units_.end());
51  my_display_.invalidate(u->get_location());
52  // Redraw with no location to get rid of haloes
53  u->anim_comp().clear_haloes();
54  }
55  if (removed > 1) {
56  ERR_NG << "Error: duplicate temp unit found in fake_unit_manager::remove_temporary_unit" << std::endl;
57  }
58  return removed;
59 }
60 
bool invalidate(const map_location &loc)
Function to invalidate a specific tile for redrawing.
Definition: display.cpp:3536
static lg::log_domain log_engine("engine")
int remove_temporary_unit(internal_ptr_type)
Deregister a unit from this manager.
std::deque< internal_ptr_type > fake_units_
collection of units destined to be drawn but not put into the unit map
map_display and display: classes which take care of displaying the map and game-data on the screen...
unit const * internal_ptr_type
display & my_display_
Reference to my display. The display owns me in a scoped_ptr, so this should never be a dangling refe...
void place_temporary_unit(internal_ptr_type)
Register a unit with this manager.
bool find(E event, F functor)
Tests whether an event handler is available.
Standard logging facilities (interface).
const std::string remove
remove directive
std::string::const_iterator iterator
Definition: tokenizer.hpp:21
#define ERR_NG