Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 25, 2011, 8:22:36 PM (13 years ago)
Author:
scheusso
Message:

merging network6 into trunk

Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/libraries/network/Connection.h

    r7801 r8327  
    4444
    4545#include <deque>
     46#include <map>
    4647#include <enet/enet.h>
     48#include <boost/concept_check.hpp>
    4749
    4850namespace boost
     
    5961  const unsigned int NETWORK_MAX_QUEUE_PROCESS_TIME = 5;
    6062 
     63  namespace incomingEventType
     64  {
     65    enum Value
     66    {
     67      receivePacket   = 1,  // incoming packet
     68      peerConnect     = 2,  // incoming connect request
     69      peerDisconnect  = 3   // incoming disconnect request
     70    };
     71   
     72  }
     73 
    6174  namespace outgoingEventType
    6275  {
    6376    enum Value
    6477    {
    65       sendPacket      = 1,
    66       disconnectPeer  = 2,
    67       broadcastPacket = 3
     78      sendPacket      = 1,  // outgoing packet
     79      broadcastPacket = 2,  // outgoing broadcast packet
     80      disconnectPeer  = 3,  // outgoing disconnect request
     81      disconnectPeers = 4   // outgoing disconnect request
    6882    };
    6983   
    7084  }
    7185 
     86  struct _NetworkExport incomingEvent
     87  {
     88    uint32_t                  peerID;
     89    incomingEventType::Value  type;
     90    packet::Packet*           packet;
     91  };
     92 
    7293  struct _NetworkExport outgoingEvent
    7394  {
    74     ENetPeer*                 peer;
     95    uint32_t                  peerID;
    7596    outgoingEventType::Value  type;
    7697    ENetPacket*               packet;
     
    83104    virtual ~Connection();
    84105
    85     void addPacket(ENetPacket *packet, ENetPeer *peer, uint8_t channelID);
    86     void broadcastPacket(ENetPacket* packet, uint8_t channelID);
    87 //     ENetHost* getHost(){ return this->host_; }
    88 
    89106  protected:
    90     Connection();
    91 //     static Connection* getInstance(){ return Connection::instance_; }
    92 
    93 //     int service(ENetEvent* event);
     107    Connection(uint32_t firstPeerID = NETWORK_PEER_ID_SERVER+1);
     108   
    94109    void startCommunicationThread();
    95110    void stopCommunicationThread();
    96     void communicationThread();
    97     virtual void disconnectPeer(ENetPeer *peer);
     111   
     112    void addPacket(ENetPacket *packet, uint32_t peerID, uint8_t channelID);
     113    void broadcastPacket(ENetPacket* packet, uint8_t channelID);
     114    void disconnectPeer(uint32_t peerID);
     115    void disconnectPeers();
    98116   
    99117    void enableCompression();
    100118
    101119    void processQueue();
    102     virtual void addPeer(ENetEvent* event)=0;
    103     virtual void removePeer(ENetEvent* event)=0;
     120    void waitOutgoingQueue();     // wait for the outgoing queue to become empty (everything processed by communication thread)
     121    virtual void addPeer(uint32_t peerID)=0;
     122    virtual void removePeer(uint32_t peerID)=0;
    104123    virtual void processPacket( packet::Packet* packet)=0;
    105     virtual packet::Packet* createPacket(ENetEvent* event);
     124   
     125    incomingEvent preprocessConnectEvent(ENetEvent& event);
     126    incomingEvent preprocessDisconnectEvent(ENetEvent& event);
     127    incomingEvent preprocessReceiveEvent(ENetEvent& event);
     128   
     129    void processIncomingEvent(ENetEvent& event);
     130    void processOutgoingEvent(outgoingEvent& event);
     131   
     132    void disconnectPeersInternal();
    106133
    107     ENetHost*                   host_;
     134    ENetHost*                     host_;
    108135  private:
    109     boost::thread*              communicationThread_;
    110     bool                        bCommunicationThreadRunning_;
    111     ENetAddress*                bindAddress_;
    112     std::deque<ENetEvent>       incomingEvents_;
    113     std::deque<outgoingEvent>   outgoingEvents_;
    114     boost::mutex*               incomingEventsMutex_;
    115     boost::mutex*               outgoingEventsMutex_;
    116 
    117 //     static Connection *instance_;
     136    void communicationThread();
     137   
     138    boost::thread*                communicationThread_;
     139    bool                          bCommunicationThreadRunning_;
     140    ENetAddress*                  bindAddress_;
     141    std::deque<incomingEvent>     incomingEvents_;
     142    std::deque<outgoingEvent>     outgoingEvents_;
     143    boost::mutex*                 incomingEventsMutex_;
     144    boost::mutex*                 outgoingEventsMutex_;
     145    boost::mutex*                 overallMutex_;
     146    std::map<uint32_t, ENetPeer*> peerMap_;
     147    std::map<ENetPeer*, uint32_t> peerIDMap_;
     148    uint32_t                      nextPeerID_;
    118149
    119150  };
Note: See TracChangeset for help on using the changeset viewer.