Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5829 in orxonox.OLD for branches/network/src


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

network: much work on multiplayability, does not yet work

Location:
branches/network/src
Files:
4 added
21 edited

Legend:

Unmodified
Added
Removed
  • branches/network/src/defs/globals.h

    r5819 r5829  
    8484
    8585#define  ORXONOX_LICENSE_SHORT \
    86 "orxonox - the future of 3D-vertical-scrollers\n" \
    87 "\n" \
    88 "Copyright (C) 2004 orx\n" \
    89 "\n" \
    90 "This program is free software; you can redistribute it and/or modify\n" \
    91 "it under the terms of the GNU General Public License as published by\n" \
    92 "the Free Software Foundation; either version 2, or (at your option)\n" \
    93 "any later version.\n"
     86    "Orxonox - The Future of 3D-Action-Game\n" \
     87    "\n" \
     88    "Copyright (C) 2004 orx\n" \
     89    "\n" \
     90    "This program is free software; you can redistribute it and/or modify\n" \
     91    "it under the terms of the GNU General Public License as published by\n" \
     92    "the Free Software Foundation; either version 2, or (at your option)\n" \
     93    "any later version.\n" \
     94    "\n" \
     95    "This program is distributed in the hope that it will be useful,\n" \
     96    "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"  \
     97    "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n"   \
     98    "GNU General Public License for more details.\n" \
     99    "\n" \
     100    "You should have received a copy of the GNU General Public License\n" \
     101    "along with this program; if not, write to the Free Software Foundation,\n" \
     102    "Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n"
    94103
    95104
  • 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
  • branches/network/src/lib/network/network_manager.h

    r5822 r5829  
    1919class NetworkStream;
    2020class Synchronizeable;
    21 template<typename> class tList;
     21template<typename>
     22class tList;
    2223
    2324/* and here is the class itsself*/
     
    2526{
    2627
    27 public:
     28  public:
    2829
    29   NetworkManager();
    30   ~NetworkManager();
     30    inline static NetworkManager* getInstance() { if (!NetworkManager::singletonRef) NetworkManager::singletonRef = new NetworkManager();
     31      return NetworkManager::singletonRef; }
     32    ~NetworkManager();
    3133
    32   void initialize();
    33   void shutdown();
     34    void initialize();
     35    void shutdown();
    3436
    35   NetworkStream& establishConnection(IPaddress& address, Synchronizeable& sync);
    36   NetworkStream& establishConnection(const char& hostName, const Synchronizeable& sync);
    37   NetworkStream& createServer(Synchronizeable& sync, unsigned int port);
    38   void shutdownConnection();
     37    int establishConnection(const char* name, unsigned int port);
     38    int createServer(unsigned int port);
    3939
    40   void synchronize();
     40    NetworkStream& establishConnection(IPaddress& address, Synchronizeable& sync);
     41    NetworkStream& createServer(Synchronizeable& sync, unsigned int port);
     42    void shutdownConnection();
    4143
    42 private:
    43   std::list<BaseObject*>*    netStreamList;            // list with refs to all network streams
    44   std::list<BaseObject*>*    syncList;                 // list of synchronizeables
     44    void connectSynchronizeable(Synchronizeable& sync);
     45
     46    void synchronize();
     47
     48  private:
     49    NetworkManager();
     50
     51
     52  private:
     53    std::list<BaseObject*>*    netStreamList;            // list with refs to all network streams
     54    std::list<BaseObject*>*    syncList;                 // list of synchronizeables
     55    static NetworkManager* singletonRef;           //!< Pointer to the only instance of this Class
     56    NetworkStream*         tmpStream;              //!< FIXME: this is only for testing purposes
    4557
    4658};
  • branches/network/src/lib/network/network_socket.cc

    r5822 r5829  
    313313
    314314  while (!tempsocket && !self->terminateThread)
     315  {
    315316    tempsocket = SDLNet_TCP_Accept(self->tcpSocket);
     317    SDL_Delay(_MSECONDS_SLEEP_LISTEN);
     318  }
    316319
    317320  SDL_mutexP(self->socketMutex);
  • branches/network/src/lib/network/network_socket.h

    r5822 r5829  
    1818//sleep if outgoing buffer is empty
    1919#define _MSECONDS_SLEEP_EMPTY_BUFFER 10
     20//sleep when waiting for connections
     21#define _MSECONDS_SLEEP_LISTEN 100
    2022
    2123/* contains memmove and memcpy */
  • branches/network/src/lib/network/network_stream.cc

    r5822 r5829  
    4040
    4141NetworkStream::NetworkStream()
    42   : DataStream()
     42    : DataStream()
    4343{
    4444  this->init();
     
    5050}
    5151
     52NetworkStream::NetworkStream(IPaddress& address, NodeType type)
     53{
     54  this->init();
     55  this->networkSocket = new NetworkSocket(address);
     56  this->networkProtocol = new NetworkProtocol();
     57  this->synchronizeables = NULL;
     58  this->connectionMonitor = new ConnectionMonitor();
     59}
     60
     61
     62NetworkStream::NetworkStream(unsigned int port, NodeType type)
     63{
     64  this->init();
     65  this->networkSocket = new NetworkSocket();
     66  this->networkSocket->listen(port);
     67  this->networkProtocol = new NetworkProtocol();
     68  this->synchronizeables = NULL;
     69  this->connectionMonitor = new ConnectionMonitor();
     70}
     71
    5272
    5373NetworkStream::NetworkStream(IPaddress& address, Synchronizeable& sync, NodeType type)
    54   : DataStream()
     74    : DataStream()
    5575{
    5676  this->init();
     
    5979  this->synchronizeables = &sync;
    6080  this->connectionMonitor = new ConnectionMonitor();
     81  this->bActive = true;
    6182}
    6283
    6384
    6485NetworkStream::NetworkStream(unsigned int port, Synchronizeable& sync, NodeType type)
    65   : DataStream()
     86    : DataStream()
    6687{
    6788  this->init();
     
    7192  this->synchronizeables = &sync;
    7293  this->connectionMonitor = new ConnectionMonitor();
     94  this->bActive = true;
    7395}
    7496
     
    79101  this->setClassID(CL_NETWORK_STREAM, "NetworkStream");
    80102  this->state = NET_REC_HEADER;
     103  this->bActive = false;
    81104}
    82105
     
    85108{
    86109
    87  networkSocket->disconnectServer();
     110  networkSocket->disconnectServer();
    88111
    89  if( this->networkSocket)
    90    delete networkSocket;
     112  if( this->networkSocket)
     113    delete networkSocket;
    91114
    92  delete connectionMonitor;
    93  delete networkProtocol;
     115  delete connectionMonitor;
     116  delete networkProtocol;
    94117}
     118
     119
     120void NetworkStream::connectSynchronizeable(Synchronizeable& sync)
     121{
     122  this->synchronizeables = &sync;
     123  if( this->networkSocket != NULL)
     124    this->bActive = true;
     125}
     126
    95127
    96128void NetworkStream::processData()
     
    102134  PRINT(0)("============= DOWNSTREAM:===============\n");
    103135  /* first of all read the synchronizeable's data: */
     136  //if(this->isServer())
    104137  dataLength = this->synchronizeables->readBytes((byte*)downBuffer);
    105138
    106   /* send the received data to connectionMonitor */
    107   this->connectionMonitor->processPacket((byte*)downBuffer, dataLength);
     139  if( dataLength > 0)
     140  {
     141    /* send the received data to connectionMonitor */
     142    this->connectionMonitor->processPacket((byte*)downBuffer, dataLength);
    108143
    109   dataLength = this->networkProtocol->createHeader((byte*)downBuffer, dataLength, DATA_STREAM_BUFFER_SIZE,
    110       *(this->synchronizeables), 12/* some random number (no real id)*/);
     144    dataLength = this->networkProtocol->createHeader((byte*)downBuffer, dataLength, DATA_STREAM_BUFFER_SIZE,
     145                 *(this->synchronizeables), 12/* some random number (no real id)*/);
    111146
    112   /* pass the data to the network socket */
    113   dataLength = this->networkSocket->writeBytes((byte*)downBuffer, dataLength);
    114   /* check if there was an error */
    115   if( dataLength == -1) { PRINTF(0)("Error in writing data to the NetworkSocket\n");}
    116 
     147    /* pass the data to the network socket */
     148    dataLength = this->networkSocket->writeBytes((byte*)downBuffer, dataLength);
     149    /* check if there was an error */
     150    if( dataLength == -1)
     151    {
     152      PRINTF(0)("Error in writing data to the NetworkSocket\n");
     153    }
     154  }
    117155
    118156
     
    147185      this->connectionMonitor->processPacket((byte*)upBuffer, this->packetHeader.length);
    148186      /* now pass the data to the sync object */
     187      //if(!this->isServer())
    149188      this->synchronizeables->writeBytes((byte*)upBuffer, this->packetHeader.length);
    150189
  • branches/network/src/lib/network/network_stream.h

    r5822 r5829  
    2828{
    2929
    30 public:
    31   NetworkStream();
    32   NetworkStream(IPaddress& address, Synchronizeable& sync, NodeType type);
    33   NetworkStream(unsigned int port, Synchronizeable& sync, NodeType type);
    34   ~NetworkStream();
     30  public:
     31    NetworkStream();
     32    NetworkStream(IPaddress& address, NodeType type);
     33    NetworkStream(unsigned int port, NodeType type);
    3534
    36   void init();
     35    NetworkStream(IPaddress& address, Synchronizeable& sync, NodeType type);
     36    NetworkStream(unsigned int port, Synchronizeable& sync, NodeType type);
     37    ~NetworkStream();
     38    void init();
    3739
    38   inline bool isServer() { return (this->type == NET_SERVER)? true:false; }
    39   virtual void processData();
     40    void connectSynchronizeable(Synchronizeable& sync);
    4041
    41 private:
    42    NetworkProtocol* networkProtocol;
    43    //NetworkSocket*       networkSockets;
    44    ConnectionMonitor*      connectionMonitor;
    45    // tList<Synchronizeable>* synchronizeables;
    46    Synchronizeable*         synchronizeables;
    47    NetworkSocket* networkSocket;
    48    int                    type;
    49    int                    state;
    50    Header                 packetHeader;
     42    inline bool isServer() const { return (this->type == NET_SERVER)? true:false; }
     43    inline bool isActive() const { return this->bActive; }
     44
     45    virtual void processData();
     46
     47  private:
     48    NetworkProtocol*       networkProtocol;
     49    ConnectionMonitor*     connectionMonitor;
     50    Synchronizeable*       synchronizeables;
     51    NetworkSocket*         networkSocket;
     52    int                    type;
     53    int                    state;
     54    Header                 packetHeader;
     55    bool                   bActive;
    5156};
    5257#endif /* _NETWORK_STREAM */
    53 
  • branches/network/src/lib/network/synchronizeable.cc

    r5822 r5829  
    1818#include "netdefs.h"
    1919
     20
     21/**
     22 *  default constructor
     23 */
     24Synchronizeable::Synchronizeable()
     25{}
     26
    2027/**
    2128 *  default constructor
     
    2532  this->setName(name);
    2633}
     34
    2735
    2836/**
     
    4149 *  read data from NetworkStream
    4250 */
    43 int Synchronizeable::readBytes(byte* data) const
     51int Synchronizeable::readBytes(byte* data)
    4452{}
    4553
  • branches/network/src/lib/network/synchronizeable.h

    r5822 r5829  
    1515
    1616    Synchronizeable(const char* name);
     17    Synchronizeable();
    1718    ~Synchronizeable();
    1819
    1920    virtual void      writeBytes(const byte* data, int length);
    20     virtual int       readBytes(byte* data) const;
     21    virtual int       readBytes(byte* data);
    2122    virtual void      writeDebug() const;
    2223    virtual void      readDebug() const;
  • branches/network/src/orxonox.cc

    r5822 r5829  
    5757#include "load_param_description.h"
    5858
     59#include "network_manager.h"
     60
    5961#include <string.h>
    6062
     
    7981  this->argc = 0;
    8082  this->argv = NULL;
     83
     84  /* this way, there is no network enabled: */
     85  this->clientName = NULL;
     86  this->port = -1;
    8187
    8288  this->configFileName = NULL;
     
    118124
    119125  PRINT(3)
    120       (
    121       "===================================================\n" \
    122       "Thanks for playing orxonox.\n" \
    123       "visit: http://www.orxonox.net for new versions.\n" \
    124       "===================================================\n" \
    125       ORXONOX_LICENSE_SHORT
    126       );
     126  (
     127    "===================================================\n" \
     128    "Thanks for playing orxonox.\n" \
     129    "visit: http://www.orxonox.net for new versions.\n" \
     130    "===================================================\n" \
     131    ORXONOX_LICENSE_SHORT
     132  );
    127133
    128134  Orxonox::singletonRef = NULL;
     
    137143void Orxonox::restart()
    138144{
    139 //   int argc = this->argc;
    140 //   char** argv = this->argv;
    141 //
    142 //   Orxonox *orx = Orxonox::getInstance();
    143 //
    144 //   delete orx;
    145 //
    146 //   orx = Orxonox::getInstance();
    147 //
    148 //   if((*orx).init(argc, argv) == -1)
    149 //   {
    150 //     PRINTF(1)("! Orxonox initialization failed\n");
    151 //     return;
    152 //   }
    153 //
    154 //   printf("finished inizialisation\n");
    155 //   orx->start();
     145  //   int argc = this->argc;
     146  //   char** argv = this->argv;
     147  //
     148  //   Orxonox *orx = Orxonox::getInstance();
     149  //
     150  //   delete orx;
     151  //
     152  //   orx = Orxonox::getInstance();
     153  //
     154  //   if((*orx).init(argc, argv) == -1)
     155  //   {
     156  //     PRINTF(1)("! Orxonox initialization failed\n");
     157  //     return;
     158  //   }
     159  //
     160  //   printf("finished inizialisation\n");
     161  //   orx->start();
    156162}
    157163
     
    179185 * initialize Orxonox with command line
    180186 */
    181 int Orxonox::init (int argc, char** argv)
     187int Orxonox::init (int argc, char** argv, const char* name, int port)
    182188{
    183189  this->argc = argc;
    184190  this->argv = argv;
    185   // parse command line
    186   // config file
     191
     192  this->clientName = name;
     193  this->port = port;
    187194
    188195  // initialize the Config-file
    189196  this->getConfigFile();
    190197
    191   // initialize everything
    192   SDL_Init(SDL_INIT_TIMER);
    193198  // windows must not write into stdout.txt and stderr.txt
    194199#ifdef __WIN32__
     
    197202#endif
    198203
    199   if( initResources () == -1) return -1;
    200   if( initVideo() == -1) return -1;
    201   if( initSound() == -1) return -1;
    202   if( initInput() == -1) return -1;
    203   if( initNetworking () == -1) return -1;
    204   if( initMisc () == -1) return -1;
    205 
    206   return 0;
    207 }
     204  // initialize everything
     205  SDL_Init(SDL_INIT_TIMER);
     206  if( initResources () == -1)
     207    return -1;
     208  if( initVideo() == -1)
     209    return -1;
     210  if( initSound() == -1)
     211    return -1;
     212  if( initInput() == -1)
     213    return -1;
     214  if( initNetworking () == -1)
     215    return -1;
     216  if( initMisc () == -1)
     217    return -1;
     218
     219  return 0;
     220}
     221
    208222
    209223/**
    210224 * initializes SDL and OpenGL
    211 */
     225 */
    212226int Orxonox::initVideo()
    213227{
     
    226240  return 0;
    227241}
     242
    228243
    229244/**
     
    262277  PRINT(3)("> Initializing networking\n");
    263278
    264   printf("  ---Not yet implemented-FIXME--\n");
     279  NetworkManager::getInstance();
     280
     281  if( this->clientName != NULL) // we are a client
     282    NetworkManager::getInstance()->establishConnection(this->clientName, port);
     283  else if( this->port > 0)      // we are a server
     284    NetworkManager::getInstance()->createServer(port);
     285
    265286  return 0;
    266287}
     
    281302  {
    282303    if (!ResourceManager::getInstance()->setDataDir(dataPath) &&
    283          !ResourceManager::getInstance()->verifyDataDir(DEFAULT_DATA_DIR_CHECKFILE))
     304        !ResourceManager::getInstance()->verifyDataDir(DEFAULT_DATA_DIR_CHECKFILE))
    284305    {
    285306      PRINTF(1)("Data Could not be located in %s\n", dataPath);
     
    300321    exit(-1);
    301322  }
    302    //! @todo this is a hack and should be loadable
     323  //! @todo this is a hack and should be loadable
    303324  char* imageDir = ResourceManager::getInstance()->getFullName("maps");
    304325  ResourceManager::getInstance()->addImageDir(imageDir);
     
    374395int main(int argc, char** argv)
    375396{
    376   // here the pre-arguments are loaded, these are needed to go either to orxonx itself, Help, or Benchmark.
    377397  int i;
    378398  for(i = 1; i < argc; ++i)
     399  {
     400    if(     !strcmp( "--help", argv[i])     || !strcmp("-h", argv[i]))
     401      return showHelp(argc, argv);
     402    else if(!strcmp( "--gui", argv[i])      || !strcmp("-g", argv[i]))
     403      showGui = true;
     404    else if(!strcmp( "--client", argv[i])   || !strcmp("-c", argv[i]))
     405      return startNetworkOrxonox(argc, argv);
     406    else if(!strcmp( "--server", argv[i])   || !strcmp("-s", argv[i]))
     407      return startNetworkOrxonox(argc, argv);
     408    else if(!strcmp( "--license", argv[i])  || !strcmp("-s", argv[i]))
     409      return PRINT(0)(ORXONOX_LICENSE_SHORT);
     410  }
     411
     412  return startOrxonox(argc, argv, NULL, -1);
     413}
     414
     415
     416
     417int showHelp(int argc, char** argv)
     418{
     419  PRINT(0)("Orxonox Version %s\n", PACKAGE_VERSION);
     420  PRINT(0)(" Starts Orxonox - The most furious 3D Action Game :)\n");
     421  PRINT(0)("\n");
     422  PRINT(0)("Common options:\n");
     423  PRINT(0)(" -g, --gui                        starts the orxonox with the configuration GUI \n");
     424  PRINT(0)(" -h, --help                       shows this help\n");
     425  PRINT(0)("\n");
     426  PRINT(0)("Network options:\n");
     427  PRINT(0)(" -s, --server [port]              starts Orxonox and listens on the [port] for players\n");
     428  PRINT(0)(" -c, --client [hostname] [port]   starts Orxonox as a Client\n");
     429  PRINT(0)(" -c, --client [ip address] [port] starts Orxonox as a Client\n");
     430  PRINT(0)("\n");
     431  PRINT(0)("Other options:\n");
     432  PRINT(0)("     --license     prints the licence and exit\n\n");
     433  PRINT(0)("\n");
     434
     435  //   {
     436  //     Gui* gui = new Gui(argc, argv);
     437  //     gui->printHelp();
     438  //     delete gui;
     439  //   }
     440}
     441
     442
     443
     444
     445/**
     446 * starts orxonox in network mode
     447 * @param argc parameters count given to orxonox
     448 * @param argv parameters given to orxonox
     449 */
     450int startNetworkOrxonox(int argc, char** argv)
     451{
     452
     453  int i;
     454  for(i = 0; i < argc; ++i )
     455  {
     456    if( !strcmp( "--client", argv[i]) || !strcmp("-c", argv[i]))
    379457    {
    380       if(! strcmp( "--help", argv[i]) || !strcmp("-h", argv[i])) return startHelp(argc, argv);
    381 //      else if(!strcmp( "--benchmark", argv[i]) || !strcmp("-b", argv[i])) return startBenchmarks();
    382       else if(!strcmp( "--gui", argv[i]) || !strcmp("-g", argv[i])) showGui = true;
    383       //      else PRINTF(2)("Orxonox does not understand the arguments %s\n", argv[i]);
     458      if( argc <= (i+2))
     459      {
     460        printf(" Wrong arguments try following notations:\n");
     461        printf("   --client [server ip address] [port number]\n");
     462        printf("   --client [dns name] [port number]\n");
     463        return 0;
     464      }
     465
     466      const char* name = argv[i+1];
     467      int port = atoi(argv[i+2]);
     468      printf("Starting Orxonox as client: connecting to %s, on port %i\n", name, port);
     469
     470      startOrxonox(argc, argv, name, port);
    384471    }
    385 
    386   return startOrxonox(argc, argv);
    387 }
    388 
    389 
    390 
    391 int startHelp(int argc, char** argv)
    392 {
    393   PRINT(0)("orxonox: starts the orxonox game - rules\n");
    394   PRINT(0)("usage: orxonox [arg [arg...]]\n\n");
    395   PRINT(0)("valid options:\n");
    396   {
    397     Gui* gui = new Gui(argc, argv);
    398     gui->printHelp();
    399     delete gui;
    400   }
    401   PRINT(0)(" -b|--benchmark:\t\tstarts the orxonox benchmark\n");
    402   PRINT(0)(" -h|--help:\t\t\tshows this help\n");
     472    else if( !strcmp( "--server", argv[i]) || !strcmp("-s", argv[i]))
     473    {
     474      if( argc <= (i+1))
     475      {
     476        printf(" Wrong arguments try following notations:\n");
     477        printf("   --server [port number]\n");
     478        return 0;
     479      }
     480
     481      int port = atoi(argv[i+1]);
     482      printf("Starting Orxonox as server, listening on port %i\n", port);
     483
     484      startOrxonox(argc, argv, NULL, port);
     485    }
     486  }
    403487}
    404488
     
    410494 * @param argv parameters given to orxonox
    411495 */
    412 int startOrxonox(int argc, char** argv)
     496int startOrxonox(int argc, char** argv, const char* name, int port)
    413497{
    414498  // checking for existence of the configuration-files, or if the lock file is still used
    415499  if (showGui || (!ResourceManager::isFile("./orxonox.conf") &&
    416       !ResourceManager::isFile(DEFAULT_CONFIG_FILE))
     500                  !ResourceManager::isFile(DEFAULT_CONFIG_FILE))
    417501#if DEBUG < 3 // developers do not need to see the GUI, when orxonox fails
    418        || ResourceManager::isFile(DEFAULT_LOCK_FILE)
     502      || ResourceManager::isFile(DEFAULT_LOCK_FILE)
    419503#endif
    420504     )
    421     {
    422       if (ResourceManager::isFile(DEFAULT_LOCK_FILE))
    423         ResourceManager::deleteFile(DEFAULT_LOCK_FILE);
    424 
    425       // starting the GUI
    426       Gui* gui = new Gui(argc, argv);
    427       gui->startGui();
    428 
    429       if (! gui->startOrxonox)
    430         return 0;
    431 
    432       delete gui;
    433     }
     505  {
     506    if (ResourceManager::isFile(DEFAULT_LOCK_FILE))
     507      ResourceManager::deleteFile(DEFAULT_LOCK_FILE);
     508
     509    // starting the GUI
     510    Gui* gui = new Gui(argc, argv);
     511    gui->startGui();
     512
     513    if (! gui->startOrxonox)
     514      return 0;
     515
     516    delete gui;
     517  }
    434518
    435519  PRINT(0)(">>> Starting Orxonox <<<\n");
     
    439523  Orxonox *orx = Orxonox::getInstance();
    440524
    441   if(orx->init(argc, argv) == -1)
    442     {
    443       PRINTF(1)("! Orxonox initialization failed\n");
    444       return -1;
    445     }
    446 
    447     printf("finished inizialisation\n");
     525  if( orx->init(argc, argv, name, port) == -1)
     526  {
     527    PRINTF(1)("! Orxonox initialization failed\n");
     528    return -1;
     529  }
     530
     531  printf("finished inizialisation\n");
    448532  orx->start();
    449533
  • branches/network/src/orxonox.h

    r5207 r5829  
    2323  inline static Orxonox* getInstance() { if (!singletonRef) singletonRef = new Orxonox();  return singletonRef; };
    2424
    25   int init (int argc, char** argv);
     25  int init(int argc, char** argv, const char* name, int port);
    2626
    2727  void restart();
    2828
    2929  void start();
    30 
    31   //void graphicsHandler (SDL_Event* event);
    3230
    3331 private:
     
    4341  int initMisc ();
    4442
    45 
    4643  const char* getConfigFile ();
    4744
     
    5552  unsigned int      argc;                    //!< Count of Arguments of orxonox
    5653  char**            argv;                    //!< Values of th Arguments of orxonox.
     54
     55  const char*       clientName;              //!< Name of the Orxonox client if == NULL -> server
     56  int               port;                    //!< number of the network port of the server/client if == -1 no network
    5757};
    5858
     
    6161// Start-up functions //
    6262////////////////////////
    63 int startHelp(int argc, char** argv);
    64 int startOrxonox(int argc, char** argv);
     63int showHelp(int argc, char** argv);
     64int showLicense();
     65int startNetworkOrxonox(int argc, char** argv);
     66int startOrxonox(int argc, char** argv, const char* clientName, int port);
    6567
    6668#endif /* _ORXONOX_H */
  • branches/network/src/story_entities/world.cc

    r5819 r5829  
    7373#include "shader.h"
    7474
     75#include "network_manager.h"
     76
    7577SHELL_COMMAND(speed, World, setSpeed);
    7678SHELL_COMMAND(togglePNodeVisibility, World, togglePNodeVisibility);
     
    321323            localPlayer = (Player*) created;
    322324            CDEngine::getInstance()->setPlayer(localPlayer);
     325            NetworkManager::getInstance()->connectSynchronizeable(*(Synchronizeable*)this->localPlayer);
    323326          }
    324327          if( element->Value() != NULL && !strcmp( element->Value(), "SkyBox")) sky = (SkyBox*) created;
     
    827830  // Get remote input
    828831  // Update synchronizables
     832  NetworkManager::getInstance()->synchronize();
    829833}
    830834
  • branches/network/src/subprojects/network/Makefile.am

    r5822 r5829  
    1515network_SOURCES=  network_unit_test.cc \
    1616                  simple_sync.cc \
     17                  read_sync.cc \
     18                  write_sync.cc \
    1719                  \
    1820                  \
     
    2628
    2729noinst_HEADERS  =  network_unit_test.h \
    28                    simple_sync.h
     30                   simple_sync.h \
     31                   read_sync.h \
     32                   write_sync.h
    2933
  • branches/network/src/subprojects/network/Makefile.in

    r5822 r5829  
    5454PROGRAMS = $(bin_PROGRAMS)
    5555am_network_OBJECTS = network-network_unit_test.$(OBJEXT) \
    56         network-simple_sync.$(OBJEXT) network-base_object.$(OBJEXT) \
     56        network-simple_sync.$(OBJEXT) network-read_sync.$(OBJEXT) \
     57        network-write_sync.$(OBJEXT) network-base_object.$(OBJEXT) \
    5758        network-class_list.$(OBJEXT) network-load_param.$(OBJEXT) \
    5859        network-substring.$(OBJEXT) network-helper_functions.$(OBJEXT)
     
    193194network_SOURCES = network_unit_test.cc \
    194195                  simple_sync.cc \
     196                  read_sync.cc \
     197                  write_sync.cc \
    195198                  \
    196199                  \
     
    202205
    203206noinst_HEADERS = network_unit_test.h \
    204                    simple_sync.h
     207                   simple_sync.h \
     208                   read_sync.h \
     209                   write_sync.h
    205210
    206211all: all-am
     
    275280@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/network-load_param.Po@am__quote@
    276281@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/network-network_unit_test.Po@am__quote@
     282@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/network-read_sync.Po@am__quote@
    277283@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/network-simple_sync.Po@am__quote@
    278284@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/network-substring.Po@am__quote@
     285@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/network-write_sync.Po@am__quote@
    279286
    280287.cc.o:
     
    319326@AMDEP_TRUE@@am__fastdepCXX_FALSE@      DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
    320327@am__fastdepCXX_FALSE@  $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(network_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o network-simple_sync.obj `if test -f 'simple_sync.cc'; then $(CYGPATH_W) 'simple_sync.cc'; else $(CYGPATH_W) '$(srcdir)/simple_sync.cc'; fi`
     328
     329network-read_sync.o: read_sync.cc
     330@am__fastdepCXX_TRUE@   if $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(network_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT network-read_sync.o -MD -MP -MF "$(DEPDIR)/network-read_sync.Tpo" -c -o network-read_sync.o `test -f 'read_sync.cc' || echo '$(srcdir)/'`read_sync.cc; \
     331@am__fastdepCXX_TRUE@   then mv -f "$(DEPDIR)/network-read_sync.Tpo" "$(DEPDIR)/network-read_sync.Po"; else rm -f "$(DEPDIR)/network-read_sync.Tpo"; exit 1; fi
     332@AMDEP_TRUE@@am__fastdepCXX_FALSE@      source='read_sync.cc' object='network-read_sync.o' libtool=no @AMDEPBACKSLASH@
     333@AMDEP_TRUE@@am__fastdepCXX_FALSE@      DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
     334@am__fastdepCXX_FALSE@  $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(network_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o network-read_sync.o `test -f 'read_sync.cc' || echo '$(srcdir)/'`read_sync.cc
     335
     336network-read_sync.obj: read_sync.cc
     337@am__fastdepCXX_TRUE@   if $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(network_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT network-read_sync.obj -MD -MP -MF "$(DEPDIR)/network-read_sync.Tpo" -c -o network-read_sync.obj `if test -f 'read_sync.cc'; then $(CYGPATH_W) 'read_sync.cc'; else $(CYGPATH_W) '$(srcdir)/read_sync.cc'; fi`; \
     338@am__fastdepCXX_TRUE@   then mv -f "$(DEPDIR)/network-read_sync.Tpo" "$(DEPDIR)/network-read_sync.Po"; else rm -f "$(DEPDIR)/network-read_sync.Tpo"; exit 1; fi
     339@AMDEP_TRUE@@am__fastdepCXX_FALSE@      source='read_sync.cc' object='network-read_sync.obj' libtool=no @AMDEPBACKSLASH@
     340@AMDEP_TRUE@@am__fastdepCXX_FALSE@      DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
     341@am__fastdepCXX_FALSE@  $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(network_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o network-read_sync.obj `if test -f 'read_sync.cc'; then $(CYGPATH_W) 'read_sync.cc'; else $(CYGPATH_W) '$(srcdir)/read_sync.cc'; fi`
     342
     343network-write_sync.o: write_sync.cc
     344@am__fastdepCXX_TRUE@   if $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(network_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT network-write_sync.o -MD -MP -MF "$(DEPDIR)/network-write_sync.Tpo" -c -o network-write_sync.o `test -f 'write_sync.cc' || echo '$(srcdir)/'`write_sync.cc; \
     345@am__fastdepCXX_TRUE@   then mv -f "$(DEPDIR)/network-write_sync.Tpo" "$(DEPDIR)/network-write_sync.Po"; else rm -f "$(DEPDIR)/network-write_sync.Tpo"; exit 1; fi
     346@AMDEP_TRUE@@am__fastdepCXX_FALSE@      source='write_sync.cc' object='network-write_sync.o' libtool=no @AMDEPBACKSLASH@
     347@AMDEP_TRUE@@am__fastdepCXX_FALSE@      DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
     348@am__fastdepCXX_FALSE@  $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(network_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o network-write_sync.o `test -f 'write_sync.cc' || echo '$(srcdir)/'`write_sync.cc
     349
     350network-write_sync.obj: write_sync.cc
     351@am__fastdepCXX_TRUE@   if $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(network_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT network-write_sync.obj -MD -MP -MF "$(DEPDIR)/network-write_sync.Tpo" -c -o network-write_sync.obj `if test -f 'write_sync.cc'; then $(CYGPATH_W) 'write_sync.cc'; else $(CYGPATH_W) '$(srcdir)/write_sync.cc'; fi`; \
     352@am__fastdepCXX_TRUE@   then mv -f "$(DEPDIR)/network-write_sync.Tpo" "$(DEPDIR)/network-write_sync.Po"; else rm -f "$(DEPDIR)/network-write_sync.Tpo"; exit 1; fi
     353@AMDEP_TRUE@@am__fastdepCXX_FALSE@      source='write_sync.cc' object='network-write_sync.obj' libtool=no @AMDEPBACKSLASH@
     354@AMDEP_TRUE@@am__fastdepCXX_FALSE@      DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
     355@am__fastdepCXX_FALSE@  $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(network_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o network-write_sync.obj `if test -f 'write_sync.cc'; then $(CYGPATH_W) 'write_sync.cc'; else $(CYGPATH_W) '$(srcdir)/write_sync.cc'; fi`
    321356
    322357network-base_object.o: $(MAINSRCDIR)/lib/lang/base_object.cc
  • branches/network/src/subprojects/network/network_unit_test.cc

    r5822 r5829  
    1212
    1313#include "simple_sync.h"
     14#include "read_sync.h"
    1415
    1516int verbose = 4;
     
    2526  printf(" --server [port number]     creates a test server\n");
    2627  printf(" --client [address] [port]  connects to a server\n");
     28  printf(" --listen [address] [port]  just listens to this connection");
    2729  printf("\n");
    2830}
     
    7678
    7779#define _N_ELEMENTS 212994
     80
    7881  char sendbuf[_N_ELEMENTS+1];
    7982  char recvbuf[_N_ELEMENTS+1];
     
    131134
    132135  /* create the network manager */
    133   NetworkManager* nm = new NetworkManager();
     136  NetworkManager* nm = NetworkManager::getInstance();
    134137
    135138  /* initialize the network manager */
     
    143146  int error = SDLNet_ResolveHost(&ip, "127.0.0.1", port);
    144147  //SDLNet_ResolveHost(&ip, "localhost", port);
    145   if(error == -1) printf("\n\nerror on address resolution, program inconsistancy\n\n");
     148  if(error == -1)
     149    printf("\n\nerror on address resolution, program inconsistancy\n\n");
    146150  nm->establishConnection(ip, *clientSync);
    147151  /* adding some break for connection setup */
     
    149153
    150154  /* synchronize the data 1 time (increment for longer tests) */
    151   for( int i = 0; i < 3; i++) {
     155  for( int i = 0; i < 3; i++)
     156  {
    152157    nm->synchronize();
    153158    /* simulate the network delay */
     
    177182int startServer(int argc, char** argv)
    178183{
    179   if( argc <= 2) {
     184  if( argc <= 2)
     185  {
    180186    printf(" Wrong arguments try following notations:\n");
    181187    printf("   --server [port number]\n");
     
    186192  printf("Starting Server on port %i\n", port);
    187193
    188   NetworkManager* netMan = new NetworkManager();
     194  NetworkManager* netMan = NetworkManager::getInstance();
    189195  Synchronizeable* ss = new SimpleSync("Server\0");
    190196
    191   //NetworkStream* server = new NetworkStream(port, ss, NET_SERVER);
    192197  netMan->createServer(*ss, port);
    193198  SDL_Delay(20);
    194199
    195   for(;;) {
     200  for(;;)
     201  {
    196202    netMan->synchronize();
    197203    SDL_Delay(500);
    198204  }
     205
     206  delete netMan;
     207  delete ss;
     208
     209
    199210  return 0;
    200211}
     
    203214int startClient(int argc, char** argv)
    204215{
    205   if( argc < 3) {
     216  if( argc < 3)
     217  {
    206218    printf(" Wrong arguments try following notations:\n");
    207219    printf("   --client [server ip] [port number]\n");
    208     printf("   --server [server name] [port number]\n");
     220    printf("   --client [server name] [port number]\n");
    209221    return 0;
    210222  }
     
    216228  IPaddress ip;
    217229  int error = SDLNet_ResolveHost(&ip, name, port);
    218   //SDLNet_ResolveHost(&ip, "localhost", port);
    219   if(error == -1) printf("\n\nerror on address resolution, program inconsistancy\n\n");
    220 
    221   NetworkManager* netMan = new NetworkManager();
     230  if(error == -1)
     231    printf("\n\nerror on address resolution, program inconsistancy\n\n");
     232
     233  NetworkManager* netMan = NetworkManager::getInstance();
    222234  Synchronizeable* ss = new SimpleSync("Client\0");
    223235
    224236  netMan->establishConnection(ip, *ss);
    225237
    226   for(;;) {
     238  for(;;)
     239  {
    227240    netMan->synchronize();
    228241    SDL_Delay(500);
    229242  }
    230243
    231   //NetworkStream* client = new NetworkStream(ip, ss, NET_CLIENT);
     244
     245  delete netMan;
     246  delete ss;
     247
     248  return 0;
     249}
     250
     251
     252
     253int startListen(int argc, char** argv)
     254{
     255  if( argc < 3)
     256  {
     257    printf(" Wrong arguments try following notations:\n");
     258    printf("   --listen [server ip] [port number]\n");
     259    printf("   --listen [server name] [port number]\n");
     260    return 0;
     261  }
     262
     263  char* name = argv[2];
     264  int port = atoi(argv[3]);
     265  printf("Connecting to %s, on port %i\n", name, port);
     266
     267  IPaddress ip;
     268  int error = SDLNet_ResolveHost(&ip, name, port);
     269  if(error == -1)
     270    printf("\n\nerror on address resolution, program inconsistancy\n\n");
     271
     272  NetworkManager* netMan = NetworkManager::getInstance();
     273  Synchronizeable* ss = new ReadSync("WriteSync\0");
     274
     275  netMan->establishConnection(ip, *ss);
     276
     277  for(;;)
     278  {
     279    netMan->synchronize();
     280    SDL_Delay(10);
     281  }
    232282
    233283
     
    253303  {
    254304    //else if(!strcmp( "--gui", argv[i]) || !strcmp("-g", argv[i])) showGui = true;
    255     if (! strcmp( "--sockettest", argv[i]) || !strcmp("-st", argv[i])) return testSocket(argc, argv);
    256     else if (! strcmp( "--frameworktest", argv[i]) || !strcmp("-ft", argv[i])) return testFramework(argc, argv);
    257     else if (! strcmp( "--server", argv[i]) || !strcmp("-s", argv[i])) return startServer(argc, argv);
    258     else if (! strcmp( "--client", argv[i]) || !strcmp("-c", argv[i])) return startClient(argc, argv);
     305    if (! strcmp( "--sockettest", argv[i]) || !strcmp("-st", argv[i]))
     306      return testSocket(argc, argv);
     307    else if (! strcmp( "--frameworktest", argv[i]) || !strcmp("-ft", argv[i]))
     308      return testFramework(argc, argv);
     309    else if (! strcmp( "--server", argv[i]) || !strcmp("-s", argv[i]))
     310      return startServer(argc, argv);
     311    else if (! strcmp( "--client", argv[i]) || !strcmp("-c", argv[i]))
     312      return startClient(argc, argv);
     313    else if (! strcmp( "--listen", argv[i]) || !strcmp("-l", argv[i]))
     314      return startListen(argc, argv);
    259315  }
    260316
  • branches/network/src/subprojects/network/simple_sync.cc

    r5822 r5829  
    8686 *  read data from Synchronizeable
    8787 */
    88 int SimpleSync::readBytes(byte* data) const
     88int SimpleSync::readBytes(byte* data)
    8989{
    9090  PRINTF(0)("SimpleSync: sent %i bytes of data\n", this->outLength);
  • branches/network/src/subprojects/network/simple_sync.h

    r5822 r5829  
    1717
    1818    virtual void writeBytes(const byte* data, int length);
    19     virtual int readBytes(byte* data) const;
     19    virtual int readBytes(byte* data);
    2020
    2121
  • branches/network/src/world_entities/player.cc

    r5767 r5829  
    3939
    4040CREATE_FACTORY(Player, CL_PLAYER);
     41
     42
     43
     44#define UP    0
     45#define DOWN  1
     46#define RIGHT 2
     47#define LEFT  3
     48#define TIME  4
     49
    4150
    4251/**
     
    107116  */
    108117  delete this->weaponMan;
     118  if( this->outData)
     119    delete[] this->outData;
     120  if( this->inData)
     121    delete[] this->inData;
    109122}
    110123
     
    160173//   this->weaponMan->setSlotDirection(9, Quaternion(+M_PI, Vector(1,0,0)));:
    161174
     175  this->outBufferLength = 100;
     176  this->outLength = 0;
     177  this->recLength = 0;
     178  this->inBufferLength = 100;
     179  this->inLength = 0;
     180  this->sentLength = 0;
     181  this->outData = new byte[this->outBufferLength];
     182  this->inData = new byte[this->inBufferLength];
    162183}
    163184
     
    282303  //orthDirection = orthDirection.cross (direction);
    283304
     305
     306  if( this->outLength >= this->outBufferLength) return;
     307
     308  if( this->bUp || this->bDown || this->bRight || this->bLeft)
     309  {
     310    this->outData[this->outLength++] = TIME;
     311    this->outData[this->outLength++] = (byte)(lround(time * 100.0f));
     312
     313    PRINTF(0)("Writing TIME = %i, or %f\n", this->outData[this->outLength-1], time);
     314  }
     315
    284316  if( this->bUp && this->getRelCoor().x < 20)
     317  {
    285318    accel += direction;
     319    this->outData[this->outLength++] = UP;
     320  }
    286321  if( this->bDown && this->getRelCoor().x > -5)
     322  {
    287323    accel -= direction;
    288 
     324    this->outData[this->outLength++] = DOWN;
     325  }
    289326  if( this->bLeft && TrackManager::getInstance()->getWidth() > -this->getRelCoor().z*2)
    290327  {
     
    292329    rot +=Vector(1,0,0);
    293330    rotVal -= .4;
     331    this->outData[this->outLength++] = LEFT;
    294332  }
    295333  if( this->bRight && TrackManager::getInstance()->getWidth() > this->getRelCoor().z*2)
     
    298336    rot += Vector(1,0,0);
    299337    rotVal += .4;
     338    this->outData[this->outLength++] = RIGHT;
    300339  }
    301340  if (this->bAscend )
     
    311350    rotVal -= .4;
    312351  }
     352
    313353
    314354  Vector move = accel * time *acceleration;
     
    322362  this->setRelDirSoft(Quaternion(rotVal, rot), 5);
    323363  this->shiftCoor (move);
     364
     365
    324366}
    325367
     
    394436  }
    395437}
     438
     439
     440
     441
     442/**
     443 *  write data to Synchronizeable
     444 */
     445void Player::writeBytes(const byte* data, int length)
     446{
     447  PRINTF(0)("Player: got %i bytes of data\n", length);
     448  this->inLength = length;
     449
     450  /*
     451   bytes:  | 0  |  1  |
     452           CODE  DIST
     453
     454
     455  CODE:
     456       0 :   Up
     457       1 :   Down
     458       2 :   Right
     459       3 :   Left
     460       4 :   TIME
     461
     462  DIST:
     463      Coordinate diff multiplied by 100 and casted to a byte: byte a = (byte)(x * 100)
     464
     465  */
     466
     467  float time = 0.0f;
     468
     469  Vector accel(0.0, 0.0, 0.0);
     470  Vector direction (1.0, 0.0, 0.0);
     471  Vector orthDirection (0.0, 0.0, 1.0);
     472
     473  byte code = 0;
     474
     475  /* iterate through all bytes */
     476  for( int i = 0; i < length; i++)
     477  {
     478    code = data[i];
     479
     480    /* is it a time code? */
     481    if( code == TIME)
     482    {
     483      /* is it the first time */
     484      if( time > 0.0f )
     485      {
     486        /* apply movement */
     487        Vector move = accel * time;
     488
     489        if (accel.z < 0)
     490          this->setRelDirSoft(Quaternion(-.4, Vector(1,0,0)), 5);
     491        else if (accel.z > 0)
     492          this->setRelDirSoft(Quaternion(.4, Vector(1,0,0)), 5);
     493        else
     494          this->setRelDirSoft(Quaternion(0, Vector(1,0,0)), 5);
     495        this->shiftCoor (move);
     496      }
     497      /* read out new movement */
     498      time = (float)(data[++i] / 100.0f);
     499      PRINTF(0)("Got time: %f msec\n", time);
     500    }
     501    else if( code == UP && this->getRelCoor().x < 20)
     502      accel = accel+(direction*acceleration);
     503    else if( code == DOWN && this->getRelCoor().x > -5)
     504      accel = accel -(direction*acceleration);
     505    else if( code == LEFT && TrackManager::getInstance()->getWidth() > -this->getRelCoor().z*2)
     506      accel = accel - (orthDirection*acceleration);
     507    else if( code == RIGHT && TrackManager::getInstance()->getWidth() > this->getRelCoor().z*2)
     508      accel = accel + (orthDirection*acceleration);
     509  }
     510
     511
     512
     513
     514  /* and debug output */
     515  this->writeDebug();
     516}
     517
     518
     519/**
     520 *  read data from Synchronizeable
     521 */
     522int Player::readBytes(byte* data)
     523{
     524  PRINTF(0)("Player: sent %i bytes of data\n", this->sentLength);
     525
     526  /* copy data */
     527  for( int i = 0; i < this->outLength; ++i)
     528    data[i] = this->outData[i];
     529
     530
     531
     532  /* debug msg */
     533  this->readDebug();
     534
     535  int length = this->outLength;
     536  this->outLength = 0;
     537  /* return the length of the test */
     538  return length;
     539}
     540
     541
     542void Player::writeDebug() const
     543{
     544
     545}
     546
     547
     548void Player::readDebug() const
     549{
     550
     551}
     552
  • branches/network/src/world_entities/player.h

    r5500 r5829  
    1111#include "event_listener.h"
    1212
    13 template<class T> class tList;
     13template<class T>
     14class tList;
    1415class Weapon;
    1516class WeaponManager;
     
    2526class Player : public WorldEntity, public EventListener
    2627{
    27   friend class World;
     28    friend class World;
    2829
    2930  public:
     
    3940    void removeWeapon(Weapon* weapon);
    4041
     42    /* WorldEntity functions */
    4143    virtual void postSpawn();
    4244    virtual void leftWorld();
     
    4850    virtual void process(const Event &event);
    4951
     52    /* Synchronizeable functions */
     53    virtual void writeBytes(const byte* data, int length);
     54    virtual int readBytes(byte* data);
    5055
    5156  private:
    5257    void move(float time);
    5358    void weaponAction();
     59
     60    /* Synchronizeable functions */
     61    virtual void writeDebug() const;
     62    virtual void readDebug() const;
    5463
    5564    // !! temporary !!
     
    7079    float                 travelSpeed;        //!< the current speed of the player (to make soft movement)
    7180    float                 acceleration;       //!< the acceleration of the player.
     81
     82    byte*                 inData;
     83    int                   inLength;
     84    int                   inBufferLength;
     85    int                   recLength;
     86    byte*                 outData;
     87    int                   outLength;
     88    int                   outBufferLength;
     89    int                   sentLength;
     90
    7291};
    7392
  • branches/network/src/world_entities/world_entity.cc

    r5708 r5829  
    4141 */
    4242WorldEntity::WorldEntity(const TiXmlElement* root)
     43  : Synchronizeable()
    4344{
    4445  this->setClassID(CL_WORLD_ENTITY, "WorldEntity");
  • branches/network/src/world_entities/world_entity.h

    r5511 r5829  
    88
    99#include "p_node.h"
     10#include "synchronizeable.h"
     11#include "model.h"
    1012
    1113#include "glincl.h"
     
    2123
    2224//! Basis-class all interactive stuff in the world is derived from
    23 class WorldEntity : public PNode
     25class WorldEntity : public PNode, public Synchronizeable
    2426{
    2527 public:
Note: See TracChangeset for help on using the changeset viewer.