Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/core7/src/libraries/network/NetworkFunctionIncludes.h @ 10475

Last change on this file since 10475 was 10475, checked in by landauf, 9 years ago

refactored the interface of NetworkFunctionManager: maps are better encapsulated now

File size: 3.4 KB
Line 
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 *      Fabian 'x3n' Landau
26 *
27 */
28
29#ifndef _NetworkFunctionIncludes_H__
30#define _NetworkFunctionIncludes_H__
31
32#include "NetworkPrereqs.h"
33
34#include <boost/preprocessor/cat.hpp>
35#include <boost/static_assert.hpp>
36
37#include "NetworkFunction.h"
38#include "NetworkFunctionManager.h"
39
40namespace orxonox
41{
42    #define registerStaticNetworkFunction( functionPointer ) \
43        static void* BOOST_PP_CAT( NETWORK_FUNCTION_, __UNIQUE_NUMBER__ ) = registerStaticNetworkFunctionFct( functionPointer, #functionPointer );
44
45    #define registerMemberNetworkFunction( class, function ) \
46        static void* BOOST_PP_CAT( NETWORK_FUNCTION_##class, __UNIQUE_NUMBER__ ) = registerMemberNetworkFunctionFct<class>( &class::function, #class "_" #function);
47
48    // call it with functionPointer, clientID, args
49    #define callStaticNetworkFunction( functionPointer, ...) \
50        { \
51            NetworkFunctionPointer p1; \
52            copyPtr( functionPointer, p1 ); \
53            FunctionCallManager::addCall(NetworkFunctionManager::getInstance().getFunctionByFunctionPointer(p1)->getNetworkID(), OBJECTID_UNKNOWN, __VA_ARGS__); \
54        }
55
56    // call it with class, function, objectID, clientID, args
57    #define callMemberNetworkFunction( class, function, objectID, ...) \
58        { \
59            NetworkFunctionPointer p1; \
60            copyPtr( &class::function, p1 ); \
61            FunctionCallManager::addCall(NetworkFunctionManager::getInstance().getFunctionByFunctionPointer(p1)->getNetworkID(), objectID, __VA_ARGS__); \
62        }
63
64    template<class T> inline void* registerStaticNetworkFunctionFct( T ptr, const std::string& name )
65    {
66        BOOST_STATIC_ASSERT( sizeof(T)<=sizeof(NetworkFunctionPointer) ); // if this fails your compiler uses bigger pointers for static functions than defined above
67        NetworkFunctionPointer destptr;
68        copyPtr( ptr, destptr );
69        new NetworkFunctionStatic( createFunctor(ptr), name, destptr );
70        return 0;
71    }
72
73    template<class T, class PT> inline void* registerMemberNetworkFunctionFct( PT ptr, const std::string& name )
74    {
75        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
76        NetworkFunctionPointer destptr;
77        copyPtr( ptr, destptr );
78        new NetworkMemberFunction<T>( createFunctor(ptr), name, destptr );
79        return 0;
80    }
81
82}
83
84#endif /* _NetworkFunctionIncludes_H__ */
Note: See TracBrowser for help on using the repository browser.