Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/netp2/src/orxonox/objects/Test.cc @ 2939

Last change on this file since 2939 was 2937, checked in by scheusso, 16 years ago

commit for testing reasons

  • added possibility to transfer function calls over network
  • made MultiType serialisable
  • put serialise functions from synchronisable to util
  • … (can't remember )
  • Property svn:eol-style set to native
File size: 4.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 *      Oli Scheuss
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#include "OrxonoxStableHeaders.h"
30#include "core/CoreIncludes.h"
31#include "core/ConfigValueIncludes.h"
32#include "core/ConsoleCommand.h"
33#include "network/NetworkFunction.h"
34#include "Test.h"
35
36namespace orxonox
37{
38        CreateFactory ( Test );
39 
40  SetConsoleCommand(Test, printV1, true).accessLevel(AccessLevel::User);
41  SetConsoleCommand(Test, printV2, true).accessLevel(AccessLevel::User);
42  SetConsoleCommand(Test, printV3, true).accessLevel(AccessLevel::User);
43  SetConsoleCommand(Test, printV4, true).accessLevel(AccessLevel::User);
44  SetConsoleCommand(Test, call, true).accessLevel(AccessLevel::User);
45 
46 
47  //void=* aaaaa = copyPtr<sizeof(&Test::printV1)>( &NETWORK_FUNCTION_POINTER, &Test::printV1 );
48  //void* NETWORK_FUNCTION_TEST_B = memcpy(&NETWORK_FUNCTION_POINTER, &a, sizeof(a));
49//   NetworkFunctionBase* NETWORK_FUNCTION_TEST_C = new NetworkFunctionStatic( createFunctor(&Test::printV1), "bla", NETWORK_FUNCTION_POINTER );
50 
51  registerStaticNetworkFunction( &Test::printV1, "printV1" );
52 
53  Test* Test::instance_ = 0;
54
55        Test::Test(BaseObject* creator) : BaseObject(creator), Synchronisable(creator)
56        {
57    assert(instance_==0);
58    instance_=this;
59                RegisterObject ( Test );
60    setConfigValues();
61    registerVariables();
62                setObjectMode(0x3);
63        }
64
65        Test::~Test()
66        {
67    instance_=0;
68        }
69
70        void Test::setConfigValues()
71        {
72                SetConfigValue ( u1, 1 )/*.callback ( this, &Test::checkV1 )*/;
73    SetConfigValue ( u2, 2 )/*.callback ( this, &Test::checkV2 )*/;
74    SetConfigValue ( u3, 3 )/*.callback ( this, &Test::checkV3 )*/;
75    SetConfigValue ( u4, 4 )/*.callback ( this, &Test::checkV4 )*/;
76   
77    SetConfigValue ( s1, 1 )/*.callback ( this, &Test::checkV1 )*/;
78    SetConfigValue ( s2, 2 )/*.callback ( this, &Test::checkV2 )*/;
79    SetConfigValue ( s3, 3 )/*.callback ( this, &Test::checkV3 )*/;
80    SetConfigValue ( s4, 4 )/*.callback ( this, &Test::checkV4 )*/;
81        }
82
83
84        void Test::registerVariables()
85        {
86                registerVariable ( u1, variableDirection::toclient, new NetworkCallback<Test> ( this, &Test::checkU1 ));
87    registerVariable ( u2, variableDirection::toserver, new NetworkCallback<Test> ( this, &Test::checkU2 ));
88                registerVariable ( u3, variableDirection::serverMaster, new NetworkCallback<Test> ( this, &Test::checkU3 ), true );
89    registerVariable ( u4, variableDirection::clientMaster, new NetworkCallback<Test> ( this, &Test::checkU4 ), true );
90   
91    registerVariable ( s1, variableDirection::toclient, new NetworkCallback<Test> ( this, &Test::checkS1 ));
92    registerVariable ( s2, variableDirection::toserver, new NetworkCallback<Test> ( this, &Test::checkS2 ));
93    registerVariable ( s3, variableDirection::serverMaster, new NetworkCallback<Test> ( this, &Test::checkS3 ), true );
94    registerVariable ( s4, variableDirection::clientMaster, new NetworkCallback<Test> ( this, &Test::checkS4 ), true );
95        }
96 
97  void Test::call(unsigned int clientID)
98  {
99    callStaticNetworkFunction( &Test::printV1, clientID );
100  }
101 
102  void Test::checkU1(){ COUT(1) << "U1 changed: " << u1 << std::endl; }
103  void Test::checkU2(){ COUT(1) << "U2 changed: " << u2 << std::endl; }
104  void Test::checkU3(){ COUT(1) << "U3 changed: " << u3 << std::endl; }
105  void Test::checkU4(){ COUT(1) << "U4 changed: " << u4 << std::endl; }
106
107  void Test::checkS1(){ COUT(1) << "S1 changed: " << s1 << std::endl; }
108  void Test::checkS2(){ COUT(1) << "S2 changed: " << s2 << std::endl; }
109  void Test::checkS3(){ COUT(1) << "S3 changed: " << s3 << std::endl; }
110  void Test::checkS4(){ COUT(1) << "S4 changed: " << s4 << std::endl; }
111
112}
Note: See TracBrowser for help on using the repository browser.