source: osgVisual/include/cluster/dataIO_clusterENet_implementation.h @ 74

Last change on this file since 74 was 69, checked in by Torben Dannhauer, 14 years ago

Network sync:
now works:

  • serialization of transport container
  • transport via ENet UDP
  • de-serialization of the transport container.
  • transport of viewmatrix and framenumber to the slave.

ToDo?: apply viewmatrix on slave still do not work.

File size: 2.7 KB
Line 
1#pragma once
2/* -*-c++-*- osgVisual - Copyright (C) 2009-2010 Torben Dannhauer
3 *
4 * This library is based on OpenSceneGraph, open source and may be redistributed and/or modified under
5 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
6 * (at your option) any later version.  The full license is in LICENSE file
7 * included with this distribution, and on the openscenegraph.org website.
8 *
9 * osgVisual requires for some proprietary modules a license from the correspondig manufacturer.
10 * You have to aquire licenses for all used proprietary modules.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * OpenSceneGraph Public License for more details.
16*/
17
18
19#include <osg/referenced>
20#include <enet/enet.h>
21#include <iostream>
22#include <string>
23#include <vector>
24
25namespace osgVisual
26{
27
28class dataIO_clusterENet_implementation :       public osg::Referenced
29{
30public:
31        dataIO_clusterENet_implementation(std::string& receivedTransportContainer_);
32        ~dataIO_clusterENet_implementation();
33
34        enum role {SERVER, CLIENT};
35
36        bool init( dataIO_clusterENet_implementation::role role_, unsigned short port_, int maxClients_=10, int maxChannels_=2, int maxInBandwidth_=0, int maxOutBandwidth_=0 );        // client & server                                                              // Done
37        bool connectTo( const char* remoteAddr_, int connectTimeout_ms_, int clientInfo_=0,  int channelToAlloc_=2 );   // only as client                                                                       // Done
38        void sendPacket( ENetPacket* packet_, enet_uint8 channelID_, unsigned int peerID_=0, bool autoFlush_=false );   // by PeerID    // Done
39        void sendPacket( ENetPacket* packet_, enet_uint8 channelID_, std::string peerName_, bool autoFlush_=false );    // by peer name // Done
40        void broadcastPacket( enet_uint8 channelID_, ENetPacket* packet_, bool autoFlush_=false );      // only as server.                                      // Done
41        void processEvents( int timeout_ms_ = 0 );                                                                                                                                                                              // Done
42       
43        virtual inline void onReceivePacket(ENetEvent* event_);
44        virtual inline void onConnect(ENetEvent* event_);               // This function will be called only by the host waiting for the connection.
45        virtual inline void onDisconnect(ENetEvent* event_);
46
47protected:
48        unsigned short port;
49        dataIO_clusterENet_implementation::role currentRole;
50        static int activeENetInstances;
51        bool serverInitialized; // shows if the complete server is initialized. (After init())
52        ENetAddress address;
53    ENetHost* host;
54        std::vector<ENetPeer*> peerList;        // client: only one peer to server,    Server: multiple peers for all clients
55        ENetEvent event;
56        std::string& receivedTransportContainer;
57};
58
59}       // END NAMESPACE
Note: See TracBrowser for help on using the repository browser.