DarkRadiant: master 9d7fe174

Author Committer Branch Timestamp Parent
orbweaver orbweaver master 09.12.2021 14:48 master 763655ef
Changeset Implement auto-disconnection for KeyObserver class

Now that KeyObserverMap is using sigc::signals internally to allow
auto-disconnection, we can make use of this to implement auto-disconnection
when explicit KeyObserver classes are used instead of pure slots. This is
achieved by changing insert() to call observeKey() to attach to
onKeyValueChanged() directly, rather than storing the actual KeyObserver
pointer internally. KeyObserver now inherits from sigc::trackable to enable
auto-disconnection in this case.

This required some internal changes to handle explicit disconnection using
erase(). We now store a sigc::connection object, indexed by KeyObserver
pointer, to remove the connection if requested. This is actually a minor change
in behaviour: erase() now disconnects the given KeyObserver from *all* keys,
rather than just a specific key, but this would only matter if the same
KeyObserver was connected to multiple keys and the calling code wanted to
disconnect it from just one of them. As far as I can see there are no cases
where this behaviour would be needed — it's a 1:1 mapping between keys and
KeyObserver objects everywhere.
mod - radiantcore/entity/EntityNode.cpp Diff File
mod - radiantcore/entity/KeyObserverMap.h Diff File
mod - radiantcore/entity/ShaderParms.cpp Diff File
mod - test/Entity.cpp Diff File