Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 30, 2005, 9:43:05 AM (18 years ago)
Author:
patrick
Message:

network: much work on multiplayability, does not yet work

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/network/src/lib/network/network_manager.cc

    r5822 r5829  
    3535
    3636
    37 /************************************
    38   What you will see here are the function definitions from the header file (network_manager.h) with doxygen documentation. Here is an example:
    39 
    40 
    41  In file network_manager.h
    42 
    43  class NetworkManager
    44  {
    45    int doSomeStuff(float argument, float* pointer);
    46  }
    47 
    48  will be implemented in the source file as follows:
    49 
    50  In file network_manager.cc
    51 
    52  / **
    53   *  this is the short description for this function: it just does some stuff
    54   * @param argument: this is the first argument, stuff...
    55   * @param pointer:  this is the pointer to nowhereland
    56   * return: whatever the function returns: for example an index, number, etc.
    57   * /
    58  int NetworkManager::doSomeStuff(float argument, float* pointer)
    59  {
    60    // whaterver you want to do
    61  }
    62 
    63 
    64  if you want to make automake compile your files: you will want to add the file names to the local Makefile.am
    65 
    66  ************************************/
    67 
    68 
     37NetworkManager* NetworkManager::singletonRef = NULL;
    6938
    7039/**
     
    7948  this->netStreamList = NULL;
    8049  this->syncList = NULL;
     50  this->tmpStream = NULL;
    8151
    8252  PRINTF(0)("NetworkManager created\n");
     
    11484 *  creates a connection from one object to a host
    11585 * @param hostName: the name of the destination host
    116  * @param synchronizeable: reference to the sync object
    11786 */
    118 NetworkStream& establishConnection(const char& hostName, const Synchronizeable& sync)
    119 {}
     87int NetworkManager::establishConnection(const char* name, unsigned int port)
     88{
     89  IPaddress ipAddress;
     90  int error = SDLNet_ResolveHost(&ipAddress, name, port);
     91  if( error == -1) {
     92    printf("\n\nerror on address resolution, program inconsistency\n\n");
     93    return -1;
     94  }
     95
     96  this->tmpStream = new NetworkStream(ipAddress, NET_CLIENT);
     97  return 1;
     98}
     99
     100
     101/**
     102 *  creates a new NetworkStream of server type
     103 * @param port: number of the TCP port
     104 */
     105int NetworkManager::createServer(unsigned int port)
     106{
     107  this->tmpStream = new NetworkStream(port, NET_SERVER);
     108  SDL_Delay(20);
     109  return 1;
     110}
    120111
    121112
     
    127118NetworkStream& NetworkManager::establishConnection(IPaddress& address, Synchronizeable& sync)
    128119{
    129   printf("Establish connection to server %s, on port %u\n", SDLNet_ResolveIP(&address), address.port);
    130120  /* creating a new network stream, it will register itself automaticaly to the class list */
    131   NetworkStream* netStream = new NetworkStream(address, sync, NET_CLIENT);
     121  this->tmpStream = new NetworkStream(address, sync, NET_CLIENT);
    132122}
     123
    133124
    134125/**
     
    140131  PRINTF(0)("Create a new server socket\n");
    141132  /* creating a new network stream, it will register itself automaticaly to the class list */
    142   NetworkStream* netStream = new NetworkStream(port, sync, NET_SERVER);
     133  this->tmpStream = new NetworkStream(port, sync, NET_SERVER);
    143134}
    144135
     
    153144
    154145
     146void NetworkManager::connectSynchronizeable(Synchronizeable& sync)
     147{
     148  this->tmpStream->connectSynchronizeable(sync);
     149}
     150
    155151
    156152/**
     
    161157  if (this->netStreamList != NULL || (this->netStreamList = ClassList::getList(CL_NETWORK_STREAM)) != NULL)
    162158  {
     159//     tIterator<BaseObject>* iterator = this->netStreamList->getIterator();
     160//     NetworkStream* stream = (NetworkStream*)(iterator->firstElement());
     161//     while( stream)
     162//     {
     163//       if(stream->isActive())
     164//         stream->processData();
     165//       stream = (NetworkStream*)(iterator->nextElement());
     166//     }
     167//     delete iterator;
    163168    std::list<BaseObject*>::iterator stream;
    164169    for (stream = this->netStreamList->begin(); stream != this->netStreamList->end(); ++stream)
    165       static_cast<NetworkStream*>(*stream)->processData();
     170      if( static_cast<NetworkStream*>(*stream)->isActive())
     171        static_cast<NetworkStream*>(*stream)->processData();
     172
    166173  }
    167174
Note: See TracChangeset for help on using the changeset viewer.