[8850] | 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 | |
---|
[8853] | 29 | /** |
---|
| 30 | @file |
---|
| 31 | @brief Implementation of the SubcontextOutputListener interface. |
---|
| 32 | */ |
---|
| 33 | |
---|
[8850] | 34 | #include "SubcontextOutputListener.h" |
---|
| 35 | |
---|
| 36 | namespace orxonox |
---|
| 37 | { |
---|
[8853] | 38 | /** |
---|
| 39 | @brief Constructor, initializes the context masks. |
---|
| 40 | */ |
---|
[8850] | 41 | SubcontextOutputListener::SubcontextOutputListener(bool bRegister) : OutputListener(bRegister) |
---|
| 42 | { |
---|
| 43 | this->subcontextsCheckMask_ = context::none; |
---|
| 44 | this->subcontextsNoCheckMask_ = context::none; |
---|
| 45 | } |
---|
| 46 | |
---|
[8853] | 47 | /** |
---|
| 48 | @brief Destructor. |
---|
| 49 | */ |
---|
[8850] | 50 | SubcontextOutputListener::~SubcontextOutputListener() |
---|
| 51 | { |
---|
| 52 | } |
---|
| 53 | |
---|
[8853] | 54 | /** |
---|
| 55 | @brief Overwritten implementation of the function defined by OutputListener. |
---|
| 56 | |
---|
| 57 | Contexts defined with this function are accepted independent of the |
---|
| 58 | sub-context. The "final" mask of additional contexts is defined by the |
---|
| 59 | combination of this mask and the masks of all accepted sub-contexts. |
---|
| 60 | */ |
---|
[8850] | 61 | void SubcontextOutputListener::setAdditionalContextsMask(OutputContextMask mask) |
---|
| 62 | { |
---|
| 63 | this->subcontextsNoCheckMask_ = mask; |
---|
| 64 | |
---|
| 65 | OutputListener::setAdditionalContextsMask(this->subcontextsCheckMask_ | this->subcontextsNoCheckMask_); |
---|
| 66 | } |
---|
| 67 | |
---|
[8853] | 68 | /** |
---|
| 69 | @brief Defines the set of accepted sub-contexts. |
---|
| 70 | |
---|
| 71 | The masks of sub-contexts in this set are added to the mask of |
---|
| 72 | additional contexts, but output is only accepted if the exact |
---|
| 73 | sub-context exists in this set. |
---|
| 74 | */ |
---|
[8850] | 75 | void SubcontextOutputListener::setAdditionalSubcontexts(const std::set<const OutputContextContainer*>& subcontexts) |
---|
| 76 | { |
---|
| 77 | this->subcontextsCheckMask_ = context::none; |
---|
| 78 | this->subcontexts_.clear(); |
---|
| 79 | |
---|
[8853] | 80 | // compose the mask of subcontexts and build the set of sub-context-IDs |
---|
[11071] | 81 | for (const OutputContextContainer* subcontext : subcontexts) |
---|
[8850] | 82 | { |
---|
[11071] | 83 | this->subcontextsCheckMask_ |= subcontext->mask; |
---|
| 84 | this->subcontexts_.insert(subcontext->sub_id); |
---|
[8850] | 85 | } |
---|
| 86 | |
---|
| 87 | OutputListener::setAdditionalContextsMask(this->subcontextsCheckMask_ | this->subcontextsNoCheckMask_); |
---|
| 88 | } |
---|
| 89 | |
---|
| 90 | /** |
---|
[8853] | 91 | @brief Returns true if this listener accepts output of the given level and context, based on the levels and contexts masks, as well as the set of accepted sub-contexts. |
---|
[8850] | 92 | */ |
---|
| 93 | bool SubcontextOutputListener::acceptsOutput(OutputLevel level, const OutputContextContainer& context) const |
---|
| 94 | { |
---|
| 95 | // check if the output level is accepted by the level mask (independent of the context) |
---|
| 96 | if (this->getLevelMask() & level) |
---|
| 97 | return true; |
---|
| 98 | |
---|
| 99 | // check if the output level is accepted by the additional contexts level mask |
---|
| 100 | if (this->getAdditionalContextsLevelMask() & level) |
---|
| 101 | { |
---|
| 102 | // check if the output context is accepted by the "no check" mask |
---|
| 103 | if (this->subcontextsNoCheckMask_ & context.mask) |
---|
| 104 | return true; |
---|
| 105 | |
---|
| 106 | // check if the output context is accepted by the "check" mask |
---|
| 107 | if (this->subcontextsCheckMask_ & context.mask) |
---|
| 108 | { |
---|
| 109 | // check if the output's subcontext is in the set of accepted sub-context |
---|
| 110 | if (this->subcontexts_.find(context.sub_id) != this->subcontexts_.end()) |
---|
| 111 | return true; |
---|
| 112 | } |
---|
| 113 | } |
---|
| 114 | |
---|
| 115 | // otherwise we don't accept the output |
---|
| 116 | return false; |
---|
| 117 | } |
---|
| 118 | } |
---|