Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/libraries/core/singleton/ScopeManager.cc @ 11071

Last change on this file since 11071 was 11071, checked in by landauf, 8 years ago

merged branch cpp11_v3 back to trunk

  • Property svn:eol-style set to native
File size: 2.9 KB
RevLine 
[5640]1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Fabian 'x3n' Landau
24 *   Co-authors:
25 *      ...
26 *
27 */
28
[7401]29/**
30    @file
[10513]31    @brief Implementation of orxonox::ScopeManager.
[7401]32*/
33
[10462]34#include "ScopeManager.h"
35
[5640]36#include "Scope.h"
37
38namespace orxonox
39{
[11071]40    ScopeManager* ScopeManager::singletonPtr_s = nullptr;
[10462]41
[10463]42    void ScopeManager::addScope(ScopeID::Value scope)
43    {
44        this->activeScopes_.insert(scope);
[10513]45        this->activateListenersForScope(scope);
[10463]46    }
47
48    void ScopeManager::removeScope(ScopeID::Value scope)
49    {
50        this->activeScopes_.erase(scope);
[10513]51        this->deactivateListenersForScope(scope);
[10463]52    }
53
54    bool ScopeManager::isActive(ScopeID::Value scope)
55    {
56        return this->activeScopes_.find(scope) != this->activeScopes_.end();
57    }
58
[10514]59    void ScopeManager::addListener(ScopeListener* listener, ScopeID::Value scope)
[10412]60    {
[10514]61        this->listeners_[scope].insert(listener);
[10538]62        if (this->isActive(scope))
63            this->activateListener(listener);
[10412]64    }
[10462]65
[10514]66    void ScopeManager::removeListener(ScopeListener* listener, ScopeID::Value scope)
[10462]67    {
[10538]68        if (this->isActive(scope))
69            this->deactivateListener(listener);
[10514]70        this->listeners_[scope].erase(listener);
[10462]71    }
[10513]72
73    void ScopeManager::activateListenersForScope(ScopeID::Value scope)
74    {
[11071]75        for (ScopeListener* listener : this->listeners_[scope])
76            this->activateListener(listener);
[10513]77    }
78
79    void ScopeManager::deactivateListenersForScope(ScopeID::Value scope)
80    {
[11071]81        for (ScopeListener* listener : this->listeners_[scope])
82            this->deactivateListener(listener);
[10513]83    }
84
85    void ScopeManager::activateListener(ScopeListener* listener)
86    {
87        listener->activated();
88        listener->bActivated_ = true;
89    }
90
91    void ScopeManager::deactivateListener(ScopeListener* listener)
92    {
[10538]93        if (listener->bActivated_)
[10515]94        {
[10538]95            try
96                { listener->deactivated(); }
97            catch (...)
98                { orxout(internal_warning) << "ScopeListener::deactivated() failed! This MUST NOT happen, fix it!" << endl; }
99            listener->bActivated_ = false;
[10515]100        }
[10513]101    }
[5640]102}
Note: See TracBrowser for help on using the repository browser.