| 1 |
#pragma once |
| 2 |
|
| 3 |
#include "icommandsystem.h" |
| 4 |
#include "iscenegraph.h" |
| 5 |
#include "ientity.h" |
| 6 |
#include "DiffStatus.h" |
| 7 |
|
| 8 |
namespace gameconn |
| 9 |
{ |
| 10 |
|
| 11 |
/** |
| 12 |
* Private for GameConnection class: do not use directly! |
| 13 |
* Observer for "update map" / "hot reload" feature. |
| 14 |
* It follows all changes done to the map, remembering entities to be included into diff on next map update. |
| 15 |
*/ |
| 16 |
class MapObserver |
| 17 |
{ |
| 18 |
public: |
| 19 |
~MapObserver(); |
| 20 |
|
| 21 |
//enable/disable the observer |
| 22 |
void setEnabled(bool enabled); |
| 23 |
|
| 24 |
//returns whether scene observer is enabled now |
| 25 |
bool isEnabled() const; |
| 26 |
|
| 27 |
//consider all pending changed "applied" right now |
| 28 |
//(clears list of pending changes) |
| 29 |
void clear(); |
| 30 |
|
| 31 |
//returns pending entity change since last clear (or since enabled) |
| 32 |
const DiffEntityStatuses& getChanges() const; |
| 33 |
|
| 34 |
private: |
| 35 |
//receives events about entity changes |
| 36 |
void entityUpdated(const std::string& name, const DiffStatus& diff); |
| 37 |
//add/remove entity observers on the set of entity nodes |
| 38 |
void enableEntityObservers(const std::vector<IEntityNodePtr>& entityNodes); |
| 39 |
void disableEntityObservers(const std::vector<IEntityNodePtr>& entityNodes); |
| 40 |
|
| 41 |
//the observer put onto global scene |
| 42 |
std::unique_ptr<scene::Graph::Observer> _sceneObserver; |
| 43 |
//observers put on every entity on scene |
| 44 |
std::map<IEntityNode*, Entity::Observer*> _entityObservers; //note: values owned |
| 45 |
//set of entities with changes since last clear |
| 46 |
DiffEntityStatuses _entityChanges; |
| 47 |
|
| 48 |
//internal classes can call private methods |
| 49 |
friend class MapObserver_EntityObserver; |
| 50 |
friend class MapObserver_SceneObserver; |
| 51 |
}; |
| 52 |
|
| 53 |
} |