Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/Test.cc @ 7996

Last change on this file since 7996 was 7284, checked in by landauf, 14 years ago

merged consolecommands3 branch back to trunk.

note: the console command interface has changed completely, but the documentation is not yet up to date. just copy an existing command and change it to your needs, it's pretty self-explanatory. also the include files related to console commands are now located in core/command/. in the game it should work exactly like before, except for some changes in the auto-completion.

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