[2937] | 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 | * Oliver Scheuss |
---|
| 24 | * Co-authors: |
---|
| 25 | * ... |
---|
| 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
[3214] | 29 | #ifndef _NetworkFunction_H__ |
---|
| 30 | #define _NetworkFunction_H__ |
---|
[2937] | 31 | |
---|
| 32 | #include "NetworkPrereqs.h" |
---|
| 33 | |
---|
[3214] | 34 | #include <cassert> |
---|
| 35 | #include <cstring> |
---|
| 36 | #include <map> |
---|
[2937] | 37 | #include <string> |
---|
[3214] | 38 | |
---|
[7284] | 39 | #include "core/command/Functor.h" |
---|
[3214] | 40 | #include "FunctionCallManager.h" |
---|
[2937] | 41 | #include "synchronisable/Synchronisable.h" |
---|
| 42 | |
---|
| 43 | namespace orxonox |
---|
| 44 | { |
---|
| 45 | |
---|
[3304] | 46 | #if defined(ORXONOX_COMPILER_GCC) && defined(ORXONOX_ARCH_32) |
---|
[11071] | 47 | static constexpr unsigned int MAX_FUNCTION_POINTER_SIZE = 8; |
---|
[3304] | 48 | #else |
---|
[11071] | 49 | static constexpr unsigned int MAX_FUNCTION_POINTER_SIZE = 16; |
---|
[2937] | 50 | #endif //ORXONOX_COMPILER_GCC |
---|
[11071] | 51 | static constexpr unsigned int MAX_FUNCTION_POINTER_INTS = (MAX_FUNCTION_POINTER_SIZE-1)/4+1; |
---|
[2937] | 52 | |
---|
| 53 | struct _NetworkExport NetworkFunctionPointer { |
---|
| 54 | uint32_t pointer[MAX_FUNCTION_POINTER_INTS]; |
---|
| 55 | bool operator<(const NetworkFunctionPointer& b) const |
---|
| 56 | { |
---|
[3304] | 57 | #if defined(ORXONOX_COMPILER_GCC) && defined(ORXONOX_ARCH_32) |
---|
[10624] | 58 | if (pointer[0] != b.pointer[0]) |
---|
| 59 | return pointer[0] < b.pointer[0]; |
---|
| 60 | else if (pointer[1] != b.pointer[1]) |
---|
| 61 | return pointer[1] < b.pointer[1]; |
---|
| 62 | else |
---|
| 63 | return false; |
---|
| 64 | #else |
---|
| 65 | if (pointer[0] != b.pointer[0]) |
---|
| 66 | return pointer[0] < b.pointer[0]; |
---|
| 67 | else if (pointer[1] != b.pointer[1]) |
---|
| 68 | return pointer[1] < b.pointer[1]; |
---|
| 69 | else if (pointer[2] != b.pointer[2]) |
---|
| 70 | return pointer[2] < b.pointer[2]; |
---|
| 71 | else if (pointer[3] != b.pointer[3]) |
---|
| 72 | return pointer[3] < b.pointer[3]; |
---|
| 73 | else |
---|
| 74 | return false; |
---|
| 75 | #endif |
---|
[2937] | 76 | } |
---|
| 77 | }; |
---|
| 78 | |
---|
| 79 | |
---|
| 80 | |
---|
| 81 | |
---|
| 82 | |
---|
[10624] | 83 | class _NetworkExport NetworkFunctionBase { |
---|
[2937] | 84 | public: |
---|
[10624] | 85 | NetworkFunctionBase(const std::string& name, const NetworkFunctionPointer& pointer); |
---|
| 86 | virtual ~NetworkFunctionBase() {} |
---|
[6417] | 87 | |
---|
[10624] | 88 | void setNetworkID(uint32_t id); |
---|
| 89 | inline uint32_t getNetworkID() const { return this->networkID_; } |
---|
| 90 | inline const std::string& getName() const { return this->name_; } |
---|
| 91 | inline const NetworkFunctionPointer& getPointer() const { return this->pointer_; } |
---|
[6417] | 92 | |
---|
[10624] | 93 | virtual bool call(uint32_t objectID)=0; |
---|
| 94 | virtual bool call(uint32_t objectID, const MultiType& mt1)=0; |
---|
| 95 | virtual bool call(uint32_t objectID, const MultiType& mt1, const MultiType& mt2)=0; |
---|
| 96 | virtual bool call(uint32_t objectID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3)=0; |
---|
| 97 | virtual bool call(uint32_t objectID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4)=0; |
---|
| 98 | virtual bool call(uint32_t objectID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5)=0; |
---|
[6417] | 99 | |
---|
[2937] | 100 | private: |
---|
| 101 | uint32_t networkID_; |
---|
| 102 | std::string name_; |
---|
[10624] | 103 | NetworkFunctionPointer pointer_; |
---|
[6417] | 104 | |
---|
[2937] | 105 | }; |
---|
| 106 | |
---|
| 107 | |
---|
| 108 | class _NetworkExport NetworkFunctionStatic: public NetworkFunctionBase { |
---|
| 109 | public: |
---|
[10624] | 110 | NetworkFunctionStatic(const FunctorStaticPtr& functor, const std::string& name, const NetworkFunctionPointer& p) |
---|
| 111 | : NetworkFunctionBase(name, p) |
---|
| 112 | , functor_(functor) |
---|
| 113 | { } |
---|
[6417] | 114 | |
---|
[10624] | 115 | // ignore the objectID because its a static function |
---|
[11071] | 116 | virtual bool call(uint32_t objectID) override{ (*this->functor_)(); return true; } |
---|
| 117 | virtual bool call(uint32_t objectID, const MultiType& mt1) override{ (*this->functor_)(mt1); return true; } |
---|
| 118 | virtual bool call(uint32_t objectID, const MultiType& mt1, const MultiType& mt2) override{ (*this->functor_)(mt1, mt2); return true; } |
---|
| 119 | virtual bool call(uint32_t objectID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3) override{ (*this->functor_)(mt1, mt2, mt3); return true; } |
---|
| 120 | virtual bool call(uint32_t objectID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4) override{ (*this->functor_)(mt1, mt2, mt3, mt4); return true; } |
---|
| 121 | virtual bool call(uint32_t objectID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5) override{ (*this->functor_)(mt1, mt2, mt3, mt4, mt5); return true; } |
---|
[6417] | 122 | |
---|
[2937] | 123 | private: |
---|
[7284] | 124 | FunctorStaticPtr functor_; |
---|
[6417] | 125 | |
---|
[2937] | 126 | }; |
---|
| 127 | |
---|
| 128 | |
---|
[2941] | 129 | class _NetworkExport NetworkMemberFunctionBase: public NetworkFunctionBase { |
---|
[2937] | 130 | public: |
---|
[10624] | 131 | NetworkMemberFunctionBase(const std::string& name, const NetworkFunctionPointer& p) |
---|
| 132 | : NetworkFunctionBase(name, p) |
---|
| 133 | { } |
---|
[2937] | 134 | }; |
---|
| 135 | |
---|
| 136 | |
---|
[2995] | 137 | template <class T> class NetworkMemberFunction: public NetworkMemberFunctionBase { |
---|
[2937] | 138 | public: |
---|
[10624] | 139 | NetworkMemberFunction(const FunctorMemberPtr<T>& functor, const std::string& name, const NetworkFunctionPointer& p) |
---|
| 140 | : NetworkMemberFunctionBase(name, p) |
---|
| 141 | , functor_(functor) |
---|
| 142 | { } |
---|
[6417] | 143 | |
---|
[11071] | 144 | virtual inline bool call(uint32_t objectID) override |
---|
[6417] | 145 | { |
---|
[11071] | 146 | if ( Synchronisable::getSynchronisable(objectID)!=nullptr ) |
---|
[7495] | 147 | { |
---|
[3325] | 148 | (*this->functor_)(orxonox_cast<T*>(Synchronisable::getSynchronisable(objectID))); |
---|
[7495] | 149 | return true; |
---|
| 150 | } |
---|
| 151 | else |
---|
| 152 | return false; |
---|
[2951] | 153 | } |
---|
[11071] | 154 | virtual inline bool call(uint32_t objectID, const MultiType& mt1) override |
---|
[6417] | 155 | { |
---|
[11071] | 156 | if ( Synchronisable::getSynchronisable(objectID)!=nullptr ) |
---|
[7495] | 157 | { |
---|
[3325] | 158 | (*this->functor_)(orxonox_cast<T*>(Synchronisable::getSynchronisable(objectID)), mt1); |
---|
[7495] | 159 | return true; |
---|
| 160 | } |
---|
| 161 | else |
---|
| 162 | return false; |
---|
[2951] | 163 | } |
---|
[11071] | 164 | virtual inline bool call(uint32_t objectID, const MultiType& mt1, const MultiType& mt2) override |
---|
[6417] | 165 | { |
---|
[11071] | 166 | if ( Synchronisable::getSynchronisable(objectID)!=nullptr ) |
---|
[7495] | 167 | { |
---|
[3325] | 168 | (*this->functor_)(orxonox_cast<T*>(Synchronisable::getSynchronisable(objectID)), mt1, mt2); |
---|
[7495] | 169 | return true; |
---|
| 170 | } |
---|
| 171 | else |
---|
| 172 | return false; |
---|
[2951] | 173 | } |
---|
[11071] | 174 | virtual inline bool call(uint32_t objectID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3) override |
---|
[6417] | 175 | { |
---|
[11071] | 176 | if ( Synchronisable::getSynchronisable(objectID)!=nullptr ) |
---|
[7495] | 177 | { |
---|
[3325] | 178 | (*this->functor_)(orxonox_cast<T*>(Synchronisable::getSynchronisable(objectID)), mt1, mt2, mt3); |
---|
[7495] | 179 | return true; |
---|
| 180 | } |
---|
| 181 | else |
---|
| 182 | return false; |
---|
[2951] | 183 | } |
---|
[11071] | 184 | virtual inline bool call(uint32_t objectID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4) override |
---|
[6417] | 185 | { |
---|
[11071] | 186 | if ( Synchronisable::getSynchronisable(objectID)!=nullptr ) |
---|
[7495] | 187 | { |
---|
[3325] | 188 | (*this->functor_)(orxonox_cast<T*>(Synchronisable::getSynchronisable(objectID)), mt1, mt2, mt3, mt4); |
---|
[7495] | 189 | return true; |
---|
| 190 | } |
---|
| 191 | else |
---|
| 192 | return false; |
---|
[2951] | 193 | } |
---|
[11071] | 194 | virtual inline bool call(uint32_t objectID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5) override |
---|
[6417] | 195 | { |
---|
[11071] | 196 | if ( Synchronisable::getSynchronisable(objectID)!=nullptr ) |
---|
[7495] | 197 | { |
---|
[3325] | 198 | (*this->functor_)(orxonox_cast<T*>(Synchronisable::getSynchronisable(objectID)), mt1, mt2, mt3, mt4, mt5); |
---|
[7495] | 199 | return true; |
---|
| 200 | } |
---|
| 201 | else |
---|
| 202 | return false; |
---|
[2951] | 203 | } |
---|
[6417] | 204 | |
---|
[2937] | 205 | private: |
---|
[7284] | 206 | FunctorMemberPtr<T> functor_; |
---|
[2937] | 207 | }; |
---|
| 208 | |
---|
[2944] | 209 | } |
---|
[2937] | 210 | |
---|
[3214] | 211 | #endif /* _NetworkFunction_H__ */ |
---|