| [11052] | 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 | |
|---|
| 29 | #include "NetworkFunctionManager.h" |
|---|
| 30 | #include "NetworkFunction.h" |
|---|
| 31 | |
|---|
| 32 | namespace orxonox |
|---|
| 33 | { |
|---|
| [11071] | 34 | NetworkFunctionManager* NetworkFunctionManager::singletonPtr_s = nullptr; |
|---|
| [11052] | 35 | |
|---|
| 36 | void NetworkFunctionManager::registerFunction(NetworkFunctionBase* function) |
|---|
| 37 | { |
|---|
| 38 | this->functions_.insert(function); |
|---|
| 39 | this->nameMap_[function->getName()] = function; |
|---|
| 40 | this->idMap_[function->getNetworkID()] = function; |
|---|
| 41 | this->functorMap_[function->getPointer()] = function; |
|---|
| 42 | } |
|---|
| 43 | |
|---|
| 44 | void NetworkFunctionManager::unregisterFunction(NetworkFunctionBase* function) |
|---|
| 45 | { |
|---|
| 46 | this->functions_.erase(function); |
|---|
| 47 | this->nameMap_.erase(function->getName()); |
|---|
| 48 | this->idMap_.erase(function->getNetworkID()); |
|---|
| 49 | this->functorMap_.erase(function->getPointer()); |
|---|
| 50 | } |
|---|
| 51 | |
|---|
| 52 | NetworkFunctionBase* NetworkFunctionManager::getFunctionByName(const std::string& name) |
|---|
| 53 | { |
|---|
| 54 | std::map<std::string, NetworkFunctionBase*>::iterator it = nameMap_.find(name); |
|---|
| 55 | assert(it != nameMap_.end()); |
|---|
| 56 | return it->second; |
|---|
| 57 | } |
|---|
| 58 | |
|---|
| 59 | NetworkFunctionBase* NetworkFunctionManager::getFunctionByFunctionPointer(const NetworkFunctionPointer& p) |
|---|
| 60 | { |
|---|
| 61 | std::map<NetworkFunctionPointer, NetworkFunctionBase*>::iterator it = functorMap_.find(p); |
|---|
| 62 | assert(it != functorMap_.end()); |
|---|
| 63 | return it->second; |
|---|
| 64 | } |
|---|
| 65 | |
|---|
| 66 | NetworkFunctionBase* NetworkFunctionManager::getFunctionByNetworkId(uint32_t id) |
|---|
| 67 | { |
|---|
| 68 | std::map<uint32_t, NetworkFunctionBase*>::iterator it = idMap_.find(id); |
|---|
| 69 | assert(it != idMap_.end()); |
|---|
| 70 | if(it != idMap_.end()) |
|---|
| 71 | return it->second; |
|---|
| 72 | else |
|---|
| [11071] | 73 | return nullptr; |
|---|
| [11052] | 74 | } |
|---|
| 75 | |
|---|
| 76 | /** |
|---|
| 77 | @brief Cleans the NetworkID map (needed on clients for correct initialization) |
|---|
| 78 | */ |
|---|
| 79 | void NetworkFunctionManager::clearNetworkIDs() |
|---|
| 80 | { |
|---|
| 81 | this->idMap_.clear(); |
|---|
| 82 | } |
|---|
| 83 | } |
|---|