Skip to content

Commit

Permalink
Change SelectionSystem signal and observer handling a bit
Browse files Browse the repository at this point in the history
Call signal only after _selectionInfo structure is updated.
Switch to std::set to handle double-registrations.
  • Loading branch information
codereader committed Jul 1, 2017
1 parent fab4a32 commit 90aef32
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 24 deletions.
40 changes: 17 additions & 23 deletions radiant/selection/RadiantSelectionSystem.cpp
Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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;

Expand All @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion radiant/selection/RadiantSelectionSystem.h
Expand Up @@ -25,7 +25,7 @@ class RadiantSelectionSystem :
{
ManipulationPivot _pivot;

typedef std::list<Observer*> ObserverList;
typedef std::set<Observer*> ObserverList;
ObserverList _observers;

// The 3D volume surrounding the most recent selection.
Expand Down

0 comments on commit 90aef32

Please sign in to comment.