Freeciv21
Develop your civilization from humble roots to a global empire
map_updates_handler.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2022 Louis Moureaux <m_louis30@yahoo.com>
3  *
4  * SPDX-License-Identifier: GPLv3-or-later
5  */
6 
7 #pragma once
8 
9 #include <map>
10 
11 #include <QObject>
12 
13 #include "listener.h"
14 
15 struct city;
16 struct tile;
17 struct unit;
18 
19 namespace freeciv {
20 
21 class map_updates_handler : public QObject,
22  public listener<map_updates_handler> {
23  Q_OBJECT
24 
25 public:
29  enum class update_type {
30  tile_single = 0x01,
31  tile_full = 0x02,
32  unit = 0x04,
33  city_description = 0x08,
34  city_map = 0x10,
35  tile_label = 0x20,
36  };
37  Q_DECLARE_FLAGS(updates, update_type)
38 
39  explicit map_updates_handler(QObject *parent = nullptr);
40  virtual ~map_updates_handler() = default;
41 
43  bool full() const { return m_full_update; }
44 
46  auto list() const { return m_updates; }
47 
48  void clear();
49 
50  void update(const city *city, bool full);
51  void update(const tile *tile, bool full);
52  void update(const unit *unit, bool full);
53  void update_all();
54  void update_city_description(const city *city);
55  void update_tile_label(const tile *tile);
56 
57 signals:
59 
60 private:
61  bool m_full_update = false;
62  std::map<const tile *, updates> m_updates;
63 };
64 
65 Q_DECLARE_OPERATORS_FOR_FLAGS(map_updates_handler::updates)
66 
67 } // namespace freeciv
Records regions of the map that should be updated.
void update_all()
Requests an update of the whole (visible) map.
void update_tile_label(const tile *tile)
Registers a tile label for update.
std::map< const tile *, updates > m_updates
bool full() const
Returns true if the whole map should be updated.
void update_city_description(const city *city)
Registers a city label for update.
update_type
What kind of update should be performed.
void clear()
Clears all pending updates.
map_updates_handler(QObject *parent=nullptr)
Constructor.
auto list() const
Returns the list of pending updates.
virtual ~map_updates_handler()=default
void update(const city *city, bool full)
Registers a city for update.
Definition: path.cpp:10
Definition: city.h:291
Definition: tile.h:42
Definition: unit.h:134