/
MapObserver.h
52 lines (41 loc) · 1.53 KB
/
MapObserver.h
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
#pragma once
#include "icommandsystem.h"
#include "iscenegraph.h"
#include "ientity.h"
#include "DiffStatus.h"
namespace gameconn
{
/**
* Private for GameConnection class: do not use directly!
* Observer for "update map" / "hot reload" feature.
* It follows all changes done to the map, remembering entities to be included into diff on next map update.
*/
class MapObserver
{
public:
~MapObserver();
//enable/disable the observer
void setEnabled(bool enabled);
//returns whether scene observer is enabled now
bool isEnabled() const;
//consider all pending changed "applied" right now
//(clears list of pending changes)
void clear();
//returns pending entity change since last clear (or since enabled)
const gameconn::DiffEntityStatuses& getChanges() const;
private:
//receives events about entity changes
void entityUpdated(const std::string& name, gameconn::DiffStatus diff);
//add/remove entity observers on the set of entity nodes
void setEntityObservers(const std::vector<IEntityNodePtr>& entityNodes, bool enable);
//the observer put onto global scene
std::unique_ptr<scene::Graph::Observer> _sceneObserver;
//observers put on every entity on scene
std::map<IEntityNode*, Entity::Observer*> _entityObservers; //note: values owned
//set of entities with changes since last clear
gameconn::DiffEntityStatuses _entityChanges;
//internal classes can call private methods
friend class MapObserver_EntityObserver;
friend class MapObserver_SceneObserver;
};
}