Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 95 for code/branches


Ignore:
Timestamp:
Oct 24, 2007, 7:28:55 PM (16 years ago)
Author:
anonymous
Message:

first trys with network libraries

Location:
code/branches/network/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/network/src/CMakeLists.txt

    r89 r95  
    44SET(SRC_FILES orxonox.cc)
    55SET(INC_FILES ExampleApplication.h  ExampleFrameListener.h)
     6include_directories( "./tnl" )
    67
    78#Creates an executable
    89ADD_EXECUTABLE(../bin/main ${SRC_FILES} ${INC_FILES})
    910#Links the executable against OGRE and OIS
    10 TARGET_LINK_LIBRARIES(../bin/main ${OGRE_LIBRARIES} ${OIS_LIBRARIES})
    11 
     11#TARGET_LINK_LIBRARIES(../bin/main ${OGRE_LIBRARIES} ${OIS_LIBRARIES} /home/scheusso/orxonox/network/src/raklib/libraknet.so.2.4.5.2)
  • code/branches/network/src/orxonox.cc

    r89 r95  
    2626 */
    2727
    28 // TODO: Change this to orxonox.h and include all necessary functions there
    29 #include "ExampleApplication.h"
     28#include "tnl.h"
     29#include "tnlEventConnection.h"
     30#include "tnlNetInterface.h"
     31#include "tnlRPC.h"
     32#include <stdio.h>
     33bool gQuit = false; // a flag used when the client wants to quit. using namespace TNL; // make sure we can simply use the TNL classes.
    3034
    31 // TODO: Put creation of SceneNode and implementation of FrameListener into an extern file
    32 SceneNode *lightNode;
     35class SimpleEventConnection : public EventConnection
     36{
     37    typedef EventConnection Parent;
    3338
    34 class FrameListener : public ExampleFrameListener
     39public:
     40    // Let the network system know this is a valid network connection.
     41    TNL_DECLARE_NETCONNECTION(SimpleEventConnection);
     42
     43    // declare the client to server message
     44    TNL_DECLARE_RPC(rpcMessageClientToServer, (const char *theMessageString));
     45
     46    // declare the server to client message
     47    TNL_DECLARE_RPC(rpcMessageServerToClient, (const char *theMessageString));
     48};
     49
     50TNL_IMPLEMENT_NETCONNECTION(SimpleEventConnection, NetClassGroupGame, true);
     51
     52TNL_IMPLEMENT_RPC(SimpleEventConnection, rpcMessageClientToServer, (const char *messageString), NetClassGroupGameMask, RPCGuaranteedOrdered, RPCDirClientToServer, 0)
    3553{
    36   public:
    37     FrameListener(RenderWindow* win, Camera* cam, SceneManager *sceneMgr)
    38   : ExampleFrameListener(win, cam, false, false)
     54    // display the message the client sent
     55    printf("Got message from client: %s\n", messageString);
     56    // send a hello world back to the client.
     57    rpcMessageServerToClient("Hello, World!");
     58}
     59
     60TNL_IMPLEMENT_RPC(SimpleEventConnection, rpcMessageServerToClient, (const char *messageString), NetClassGroupGameMask, RPCGuaranteedOrdered, RPCDirServerToClient, 0)
     61{
     62    // display the message the server sent
     63    printf("Got a message from server: %s\n", messageString);
     64
     65    // once the client has heard back from the server, it should quit.
     66    gQuit = true;
     67}
     68
     69int main(int argc, const char **argv)
     70{
     71    if(argc != 3)
    3972    {
     73        printf("usage: simpletnltest <-server|-client> <connectAddress>");
     74        return 1;
     75    }
     76    bool isClient = !strcmp(argv[1], "-client");
     77
     78    // convert the command-line address into TNL address form
     79    Address cmdAddress(argv[2]);
     80
     81    RefPtr<NetInterface> theNetInterface;
     82    if(isClient)
     83    {
     84        Address bindAddress(IPProtocol, Address::Any, 0);
     85
     86        // create a new NetInterface bound to any interface, any port (0)
     87        theNetInterface = new NetInterface(bindAddress);
     88       
     89        // create a new SimpleEventConnection and tell it to connect to the
     90        // server at cmdAddress.
     91        SimpleEventConnection *newConnection = new SimpleEventConnection;
     92        newConnection->connect(theNetInterface, cmdAddress);
     93
     94        // post an RPC, to be executed when the connection is established
     95        newConnection->rpcMessageClientToServer("Hello??");
     96    }
     97    else
     98    {
     99        // create a server net interface, bound to the cmdAddress
     100        theNetInterface = new NetInterface(cmdAddress);
     101
     102        // notify the NetInterface that it can allow connections
     103        theNetInterface->setAllowsConnections(true);
    40104    }
    41105
    42     bool frameStarted(const FrameEvent &evt)
     106    // now just loop, processing incoming packets and sending outgoing packets
     107    // until the global quit flag is set.
     108    while(!gQuit)
    43109    {
    44         // add tutorial code here:
    45         // ...
    46       lightNode->translate(Vector3(0, -10 * evt.timeSinceLastFrame, 0));
    47 
    48       return ExampleFrameListener::frameStarted(evt);
     110         theNetInterface->checkIncomingPackets();
     111         theNetInterface->processConnections();
     112         Platform::sleep(1);
    49113    }
    50   private:
    51 };
    52 
    53 // TODO: Make Doxygen tags work and create scene AFTER loading in an extern file
    54 //! This is the application class of Orxonox
    55 /**
    56   Application class. The starting point of Orxonox.
    57   Loading of ressources should start in here.
    58   ...
    59 */
    60 class Orxonox : public ExampleApplication
    61 {
    62   protected:
    63   public:
    64     Orxonox()
    65     {
    66     }
    67 
    68     ~Orxonox()
    69     {
    70     }
    71   protected:
    72     void createCamera(void)
    73     {
    74         // create camera
    75       mCamera = mSceneMgr->createCamera("PlayerCam");
    76       mCamera->setNearClipDistance(5);
    77       mCamera->setPosition(Vector3(0,10,500));
    78       mCamera->lookAt(Vector3(0,0,0));
    79     }
    80 
    81     void createScene(void)
    82     {
    83         // add tutorial code here:
    84         // ...
    85       mSceneMgr->setAmbientLight( ColourValue( 0.3, 0.3, 0.3 ) );
    86       //Entity* head = mSceneMgr->createEntity("head", "ogrehead.mesh");
    87 
    88       //Entity* head2 = mSceneMgr->createEntity("head2", "ogrehead.mesh");
    89 
    90       SceneNode *node = mSceneMgr->getRootSceneNode()->createChildSceneNode( "OgreHeadNode", Vector3( 0, 0, 0 ) );
    91       //node->attachObject( head );
    92 
    93       SceneNode *node2 = mSceneMgr->getRootSceneNode()->createChildSceneNode( "OgreHeadNode2", Vector3( 50, 0, 0 ) );
    94       //node2->attachObject( head2 );
    95 
    96 
    97       //mSceneMgr->setSkyBox(true, "Examples/SpaceSkyBox");
    98 
    99       Light *light = mSceneMgr->createLight("Light1");
    100       light->setType(Light::LT_POINT);
    101       light->setPosition(Vector3(0, 100, 0));
    102       light->setDiffuseColour(0.5, 0.5, 0.0);
    103       light->setSpecularColour(0.5, 0.5, 0.0);
    104 
    105       BillboardSet *bbs = mSceneMgr->createBillboardSet("bb", 1);
    106       bbs->createBillboard(Vector3::ZERO, ColourValue(1.0, 0.0, 0.0));
    107       //bbs->setMaterialName("Examples/Flare");
    108 
    109       lightNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("LightNode", Vector3(0, 100, 0));
    110       lightNode->attachObject(bbs);
    111       lightNode->attachObject(light);
    112       light->setPosition(0.0, 0.0, 0.0);
    113     }
    114 
    115     void createFrameListener(void)
    116     {
    117         // create frame listener
    118       mFrameListener = new ExampleFrameListener(mWindow, mCamera, mSceneMgr);
    119       mRoot->addFrameListener(mFrameListener);
    120     }
    121 };
    122 
    123 #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
    124 #define WIN32_LEAN_AND_MEAN
    125 #include "windows.h"
    126 
    127 INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )
    128 #else
    129 
    130 int main(int argc, char **argv)
    131 #endif
    132 {
    133   // Create application object
    134   Orxonox orxonox;
    135 
    136   try {
    137     orxonox.go();
    138   } catch( Exception& e ) {
    139 #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
    140     MessageBox( NULL, e.getFullDescription().c_str(), "An exception has occurred!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
    141 #else
    142     fprintf(stderr, "An exception has occurred: %s\n",
    143             e.getFullDescription().c_str());
    144 #endif
    145   }
    146 
    147   return 0;
     114    return 0;
    148115}
Note: See TracChangeset for help on using the changeset viewer.