Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 3050 was 2949, checked in by scheusso, 16 years ago

Network Function calls possible now (already used in Pawn::fire/doFire)

include "network/NetworkFunction.h"
register network functions like this:

registerStaticNetworkFunction( functionPointer ); this is for static (member) functions
registerMemberNetworkFunction( class, function );
this is for non-static member functions

call network functions like this:

callStaticNetworkFunction( functionPointer, clientID, arg1, … ); clientID is 0 for server
callMemberNetworkFunction( class, function, objectID, clientID, arg1, … );
objectID can be obtained by this→getObjectID() for synchronisables

arguments must be supported by MultiType !!
object must inherit from Synchronisable !!

  • Property svn:eol-style set to native
File size: 5.6 KB
RevLine 
[1958]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"
[2171]32#include "core/ConsoleCommand.h"
[2937]33#include "network/NetworkFunction.h"
[1958]34#include "Test.h"
[2949]35#include "util/MultiType.h"
[1958]36
37namespace orxonox
38{
39        CreateFactory ( Test );
[2171]40 
41  SetConsoleCommand(Test, printV1, true).accessLevel(AccessLevel::User);
42  SetConsoleCommand(Test, printV2, true).accessLevel(AccessLevel::User);
43  SetConsoleCommand(Test, printV3, true).accessLevel(AccessLevel::User);
44  SetConsoleCommand(Test, printV4, true).accessLevel(AccessLevel::User);
[2937]45  SetConsoleCommand(Test, call, true).accessLevel(AccessLevel::User);
[2949]46  SetConsoleCommand(Test, call2, true).accessLevel(AccessLevel::User);
[2171]47 
[2937]48 
49  //void=* aaaaa = copyPtr<sizeof(&Test::printV1)>( &NETWORK_FUNCTION_POINTER, &Test::printV1 );
50  //void* NETWORK_FUNCTION_TEST_B = memcpy(&NETWORK_FUNCTION_POINTER, &a, sizeof(a));
51//   NetworkFunctionBase* NETWORK_FUNCTION_TEST_C = new NetworkFunctionStatic( createFunctor(&Test::printV1), "bla", NETWORK_FUNCTION_POINTER );
52 
[2948]53  registerStaticNetworkFunction( &Test::printV1 );
54  registerMemberNetworkFunction( Test, checkU1 );
[2949]55  registerMemberNetworkFunction( Test, printBlaBla );
[2937]56 
[2171]57  Test* Test::instance_ = 0;
[1958]58
[2171]59        Test::Test(BaseObject* creator) : BaseObject(creator), Synchronisable(creator)
[1958]60        {
[2171]61    assert(instance_==0);
62    instance_=this;
[1958]63                RegisterObject ( Test );
[2171]64    setConfigValues();
65    registerVariables();
[1958]66                setObjectMode(0x3);
67        }
68
69        Test::~Test()
70        {
[2171]71    instance_=0;
[1958]72        }
73
74        void Test::setConfigValues()
75        {
[2662]76                SetConfigValue ( u1, 1 )/*.callback ( this, &Test::checkV1 )*/;
77    SetConfigValue ( u2, 2 )/*.callback ( this, &Test::checkV2 )*/;
78    SetConfigValue ( u3, 3 )/*.callback ( this, &Test::checkV3 )*/;
79    SetConfigValue ( u4, 4 )/*.callback ( this, &Test::checkV4 )*/;
80   
81    SetConfigValue ( s1, 1 )/*.callback ( this, &Test::checkV1 )*/;
82    SetConfigValue ( s2, 2 )/*.callback ( this, &Test::checkV2 )*/;
83    SetConfigValue ( s3, 3 )/*.callback ( this, &Test::checkV3 )*/;
84    SetConfigValue ( s4, 4 )/*.callback ( this, &Test::checkV4 )*/;
[1958]85        }
86
87
[2944]88  void Test::registerVariables()
89  {
90    registerVariable ( u1, variableDirection::toclient, new NetworkCallback<Test> ( this, &Test::checkU1 ));
[2662]91    registerVariable ( u2, variableDirection::toserver, new NetworkCallback<Test> ( this, &Test::checkU2 ));
[2944]92    registerVariable ( u3, variableDirection::serverMaster, new NetworkCallback<Test> ( this, &Test::checkU3 ), true );
[2662]93    registerVariable ( u4, variableDirection::clientMaster, new NetworkCallback<Test> ( this, &Test::checkU4 ), true );
94   
95    registerVariable ( s1, variableDirection::toclient, new NetworkCallback<Test> ( this, &Test::checkS1 ));
96    registerVariable ( s2, variableDirection::toserver, new NetworkCallback<Test> ( this, &Test::checkS2 ));
97    registerVariable ( s3, variableDirection::serverMaster, new NetworkCallback<Test> ( this, &Test::checkS3 ), true );
98    registerVariable ( s4, variableDirection::clientMaster, new NetworkCallback<Test> ( this, &Test::checkS4 ), true );
[2944]99  }
[2937]100 
101  void Test::call(unsigned int clientID)
102  {
103    callStaticNetworkFunction( &Test::printV1, clientID );
[2944]104    callStaticNetworkFunction( &Test::printV1, clientID );
[2937]105  }
106 
[2949]107  void Test::call2(unsigned int clientID, std::string s1, std::string s2, std::string s3, std::string s4)
108  {
109    callMemberNetworkFunction( Test, printBlaBla, this->getObjectID(), clientID, s1, s2, s3, s4, s4 );
110  }
111 
[2948]112  void Test::tick(float dt)
113  {
[2949]114//     std::string str1 = "blub";
115//     //MultiType mt1(std::string("blub"));
116//     MultiType mt1(str1);
117//     uint8_t* mem = new uint8_t[mt1.getNetworkSize()];
118//     uint8_t* temp = mem;
119//     mt1.exportData( temp );
120//     assert( temp-mem == mt1.getNetworkSize() );
121//     MultiType mt2;
122//     temp = mem;
123//     mt2.importData( temp );
124//     assert( temp-mem == mt1.getNetworkSize() );
125//     COUT(0) << mt2 << endl;
[2948]126    if(!Core::isMaster())
[2949]127      call2(0, "bal", "a", "n", "ce");
128//       callMemberNetworkFunction( Test, checkU1, this->getObjectID(), 0 );
[2948]129  }
130 
[2949]131  void Test::printBlaBla(std::string s1, std::string s2, std::string s3, std::string s4, std::string s5)
132  {
133    COUT(0) << s1 << s2 << s3 << s4 << s5 << endl;
134  }
135 
[2662]136  void Test::checkU1(){ COUT(1) << "U1 changed: " << u1 << std::endl; }
137  void Test::checkU2(){ COUT(1) << "U2 changed: " << u2 << std::endl; }
138  void Test::checkU3(){ COUT(1) << "U3 changed: " << u3 << std::endl; }
139  void Test::checkU4(){ COUT(1) << "U4 changed: " << u4 << std::endl; }
[1960]140
[2662]141  void Test::checkS1(){ COUT(1) << "S1 changed: " << s1 << std::endl; }
142  void Test::checkS2(){ COUT(1) << "S2 changed: " << s2 << std::endl; }
143  void Test::checkS3(){ COUT(1) << "S3 changed: " << s3 << std::endl; }
144  void Test::checkS4(){ COUT(1) << "S4 changed: " << s4 << std::endl; }
[1960]145
[1958]146}
Note: See TracBrowser for help on using the repository browser.