diff --git a/radiant/selection/RadiantSelectionSystem.cpp b/radiant/selection/RadiantSelectionSystem.cpp index 989e411a4a..6f8ad1174a 100644 --- a/radiant/selection/RadiantSelectionSystem.cpp +++ b/radiant/selection/RadiantSelectionSystem.cpp @@ -47,34 +47,26 @@ const SelectionInfo& RadiantSelectionSystem::getSelectionInfo() { return _selectionInfo; } -void RadiantSelectionSystem::addObserver(Observer* observer) { - if (observer != NULL) { +void RadiantSelectionSystem::addObserver(Observer* observer) +{ + if (observer != nullptr) + { // Add the passed observer to the list - _observers.push_back(observer); + _observers.insert(observer); } } -void RadiantSelectionSystem::removeObserver(Observer* observer) { - // Cycle through the list of observers and call the moved method - for (ObserverList::iterator i = _observers.begin(); i != _observers.end(); ++i) { - Observer* registered = *i; - - if (registered == observer) { - _observers.erase(i); - return; // Don't continue the loop, the iterator is obsolete - } - } +void RadiantSelectionSystem::removeObserver(Observer* observer) +{ + _observers.erase(observer); } -void RadiantSelectionSystem::notifyObservers(const scene::INodePtr& node, bool isComponent) { - +void RadiantSelectionSystem::notifyObservers(const scene::INodePtr& node, bool isComponent) +{ // Cycle through the list of observers and call the moved method - for (ObserverList::iterator i = _observers.begin(); i != _observers.end(); ++i) { - Observer* observer = *i; - - if (observer != NULL) { - observer->selectionChanged(node, isComponent); - } + for (ObserverList::iterator i = _observers.begin(); i != _observers.end(); ) + { + (*i++)->selectionChanged(node, isComponent); } } @@ -373,8 +365,7 @@ void RadiantSelectionSystem::onComponentSelection(const scene::INodePtr& node, c int delta = selectable.isSelected() ? +1 : -1; _countComponent += delta; - _sigSelectionChanged(selectable); - + _selectionInfo.totalCount += delta; _selectionInfo.componentCount += delta; @@ -386,6 +377,9 @@ void RadiantSelectionSystem::onComponentSelection(const scene::INodePtr& node, c _componentSelection.erase(node); } + // Moved here, since the _selectionInfo struct needs to be up to date + _sigSelectionChanged(selectable); + // Notify observers, TRUE => this is a component selection change notifyObservers(node, true); diff --git a/radiant/selection/RadiantSelectionSystem.h b/radiant/selection/RadiantSelectionSystem.h index 3eb3a5b445..1cbb59b831 100644 --- a/radiant/selection/RadiantSelectionSystem.h +++ b/radiant/selection/RadiantSelectionSystem.h @@ -25,7 +25,7 @@ class RadiantSelectionSystem : { ManipulationPivot _pivot; - typedef std::list ObserverList; + typedef std::set ObserverList; ObserverList _observers; // The 3D volume surrounding the most recent selection.