- Timestamp:
- May 25, 2015, 5:37:15 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core7/src/libraries/network/NetworkFunctionIncludes.h
r10476 r10478 36 36 37 37 #include "NetworkFunction.h" 38 #include "NetworkFunctionManager.h"39 38 #include "core/module/StaticallyInitializedInstance.h" 40 39 … … 47 46 = (new orxonox::SI_NF(orxonox::registerMemberNetworkFunctionFct<class>( &class::function, #class "_" #function)))->getFunction() 48 47 49 // call it with functionPointer, clientID, args50 #define callStaticNetworkFunction( functionPointer, ...) \51 { \52 NetworkFunctionPointer p1; \53 copyPtr( functionPointer, p1 ); \54 FunctionCallManager::addCall(NetworkFunctionManager::getInstance().getFunctionByFunctionPointer(p1)->getNetworkID(), OBJECTID_UNKNOWN, __VA_ARGS__); \55 }56 57 // call it with class, function, objectID, clientID, args58 #define callMemberNetworkFunction( class, function, objectID, ...) \59 { \60 NetworkFunctionPointer p1; \61 copyPtr( &class::function, p1 ); \62 FunctionCallManager::addCall(NetworkFunctionManager::getInstance().getFunctionByFunctionPointer(p1)->getNetworkID(), objectID, __VA_ARGS__); \63 }64 65 48 namespace orxonox 66 49 { 67 class _ CoreExport StaticallyInitializedNetworkFunction : public StaticallyInitializedInstance50 class _NetworkExport StaticallyInitializedNetworkFunction : public StaticallyInitializedInstance 68 51 { 69 52 public: 70 53 StaticallyInitializedNetworkFunction(NetworkFunctionBase* function) : function_(function) {} 71 54 72 virtual void load() 73 { NetworkFunctionManager::getInstance().registerFunction(this->function_); } 74 virtual void unload() 75 { NetworkFunctionManager::getInstance().unregisterFunction(this->function_); } 55 virtual void load(); 56 virtual void unload(); 76 57 77 58 inline NetworkFunctionBase& getFunction() … … 84 65 typedef StaticallyInitializedNetworkFunction SI_NF; 85 66 86 template<class T> inline NetworkFunctionBase* registerStaticNetworkFunctionFct( T ptr, const std::string& name ) 67 template<class PT> 68 inline NetworkFunctionBase* registerStaticNetworkFunctionFct(PT ptr, const std::string& name) 87 69 { 88 BOOST_STATIC_ASSERT( sizeof(T)<=sizeof(NetworkFunctionPointer)); // if this fails your compiler uses bigger pointers for static functions than defined above70 BOOST_STATIC_ASSERT(sizeof(PT) <= sizeof(NetworkFunctionPointer)); // if this fails your compiler uses bigger pointers for static functions than defined above 89 71 NetworkFunctionPointer destptr; 90 copyPtr( ptr, destptr);91 return new NetworkFunctionStatic( createFunctor(ptr), name, destptr);72 copyPtr(ptr, destptr); 73 return new NetworkFunctionStatic(createFunctor(ptr), name, destptr); 92 74 } 93 75 94 template<class T, class PT> inline NetworkFunctionBase* registerMemberNetworkFunctionFct( PT ptr, const std::string& name ) 76 template<class T, class PT> 77 inline NetworkFunctionBase* registerMemberNetworkFunctionFct(PT ptr, const std::string& name) 95 78 { 96 BOOST_STATIC_ASSERT( sizeof(PT)<=sizeof(NetworkFunctionPointer)); // if this fails your compiler uses bigger pointers for a specific kind of member functions than defined above79 BOOST_STATIC_ASSERT(sizeof(PT) <= sizeof(NetworkFunctionPointer)); // if this fails your compiler uses bigger pointers for a specific kind of member functions than defined above 97 80 NetworkFunctionPointer destptr; 98 copyPtr( ptr, destptr ); 99 return new NetworkMemberFunction<T>( createFunctor(ptr), name, destptr ); 81 copyPtr(ptr, destptr); 82 return new NetworkMemberFunction<T>(createFunctor(ptr), name, destptr); 83 } 84 85 _NetworkExport uint32_t getNetworkIdForPointer(const NetworkFunctionPointer& pointer); 86 87 // call it with functionPointer, clientID, args 88 template<class PT> 89 void callStaticNetworkFunction(PT ptr, uint32_t clientID, const MultiType& mt1 = MultiType::Null, const MultiType& mt2 = MultiType::Null, const MultiType& mt3 = MultiType::Null, const MultiType& mt4 = MultiType::Null, const MultiType& mt5 = MultiType::Null) 90 { 91 NetworkFunctionPointer destptr; 92 copyPtr(ptr, destptr); 93 FunctionCallManager::addCall(getNetworkIdForPointer(destptr), OBJECTID_UNKNOWN, clientID, mt1, mt2, mt3, mt4, mt5); 94 } 95 96 // call it with class::function, objectID, clientID, args 97 template<class PT> 98 void callMemberNetworkFunction(PT ptr, uint32_t objectID, uint32_t clientID, const MultiType& mt1 = MultiType::Null, const MultiType& mt2 = MultiType::Null, const MultiType& mt3 = MultiType::Null, const MultiType& mt4 = MultiType::Null, const MultiType& mt5 = MultiType::Null) 99 { 100 NetworkFunctionPointer destptr; 101 copyPtr(ptr, destptr); 102 FunctionCallManager::addCall(getNetworkIdForPointer(destptr), objectID, clientID, mt1, mt2, mt3, mt4, mt5); 103 } 104 105 template<class PT> 106 inline void copyPtr(PT ptr, NetworkFunctionPointer& destptr) 107 { 108 if (sizeof(NetworkFunctionPointer) - sizeof(PT) > 0) 109 memset((uint8_t*)&destptr + sizeof(PT), 0, sizeof(NetworkFunctionPointer) - sizeof(PT)); 110 PT p2 = ptr; 111 memcpy(&destptr, &p2, sizeof(PT)); 100 112 } 101 113 }
Note: See TracChangeset
for help on using the changeset viewer.