Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/network/network_manager.cc @ 9059

Last change on this file since 9059 was 9059, checked in by patrick, 18 years ago

merged the network branche with the trunk

File size: 3.8 KB
RevLine 
[5530]1/*
[5520]2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11   ### File Specific:
12   main-programmer: Patrick Boenzli
13   co-programmer: ...
14*/
15
16
[5525]17/* this is for debug output. It just says, that all calls to PRINT() belong to the DEBUG_MODULE_NETWORK module
[5530]18   For more information refere to https://www.orxonox.net/cgi-bin/trac.cgi/wiki/DebugOutput
[5525]19*/
[5530]20#define DEBUG_MODULE_NETWORK
[5525]21
[5572]22#include "class_list.h"
[5605]23#include "debug.h"
[6695]24#include "shell_command.h"
[5566]25
[5525]26/* include your own header */
[5520]27#include "network_manager.h"
[6695]28#include "shared_network_data.h"
29#include "network_stream.h"
[7954]30#include "preferences.h"
31#include "network_log.h"
[8147]32#include "network_game_manager.h"
[5520]33
[5530]34
[5525]35/* using namespace std is default, this needs to be here */
[5520]36using namespace std;
37
[6695]38SHELL_COMMAND(debug, NetworkManager, debug);
[5520]39
[6695]40
[5996]41NetworkManager* NetworkManager::singletonRef = NULL;
[5520]42
43/**
44 *  standard constructor
45 */
46NetworkManager::NetworkManager()
[5566]47{
[5572]48  /* set the class id for the base object */
[5575]49  this->setClassID(CL_NETWORK_MANAGER, "NetworkManager");
[6341]50  PRINTF(0)("START\n");
[5804]51
[5572]52  /* initialize the references */
[8228]53  this->networkStream = NULL;
[7954]54  this->elapsedTime = 0.0f;
55 
56   
57  int port = Preferences::getInstance()->getInt( "network", "telnetport", 0 );
58 
59  if ( port > 0 )
60    NetworkLog::getInstance()->listen( port );
[6341]61
[5605]62  PRINTF(0)("NetworkManager created\n");
[5566]63}
[5520]64
65
66/**
67 *  standard deconstructor
68 */
69NetworkManager::~NetworkManager()
[8228]70{
[9059]71  PRINTF(0)("NetworkManager destructor\n");
[8228]72  if ( this->networkStream )
73  {
74    delete this->networkStream;
75    this->networkStream = NULL;
76  }
[9059]77 
78  NetworkManager::singletonRef = NULL;
[8228]79}
[5520]80
[5522]81
82/**
83 *  initializes the network manager
84 */
85void NetworkManager::initialize()
[5572]86{
[5605]87  PRINTF(0)("NetworkManager initzalized\n");
[5572]88}
[5522]89
[5530]90
[5522]91/**
92 *  shutsdown the network manager
93 */
94void NetworkManager::shutdown()
[5578]95{
[5522]96
[5578]97}
[5522]98
[5578]99
[5522]100/**
101 *  creates a connection from one object to a host
[5647]102 * @param hostName: the name of the destination host
103 */
[7256]104int NetworkManager::establishConnection(const std::string & name, unsigned int port)
[5996]105{
[8228]106  this->networkStream = new NetworkStream( name, port );
[9059]107  SharedNetworkData::getInstance()->setDefaultSyncStream(this->networkStream);
[8228]108  this->networkStream->startHandshake();
[5996]109  return 1;
110}
[5647]111
[5996]112
[5647]113/**
[5996]114 *  creates a new NetworkStream of server type
115 * @param port: number of the TCP port
116 */
117int NetworkManager::createServer(unsigned int port)
118{
[9059]119  SharedNetworkData::getInstance()->setHostID(0);
120  SharedNetworkData::getInstance()->setGameServer(true);
[8228]121  this->networkStream = new NetworkStream(port);
[9059]122  SharedNetworkData::getInstance()->setDefaultSyncStream(this->networkStream);
[8228]123  this->networkStream->createNetworkGameManager();
[6695]124  PRINTF(0)("CREATE SERVER\n");
[5996]125  SDL_Delay(20);
126  return 1;
127}
128
129
130void NetworkManager::connectSynchronizeable(Synchronizeable& sync)
131{
[8228]132  if( this->networkStream)
133    this->networkStream->connectSynchronizeable(sync);
[5996]134}
[5522]135
[5996]136
[5522]137/**
138 *  sync the network
[7954]139 *  @param dtS: the seceonds elapsed since the last synchronize call
[5522]140 */
[7954]141void NetworkManager::synchronize( float dtS)
[5578]142{
[7954]143  this->elapsedTime += dtS;
144  if( likely(this->elapsedTime < 1.0f / NETWORK_FREQUENCY))
145    return;
146  this->elapsedTime = 0.0f;
147
[9059]148  if ( networkStream )
[8228]149    networkStream->processData();
[8147]150 
151  NetworkGameManager::getInstance()->tick( this->elapsedTime );
[5578]152}
[5997]153
[6695]154
155
[5997]156/**
[6695]157 * debug output
[5997]158 */
[6695]159 void NetworkManager::debug()
[5997]160{
[6695]161  PRINT(0)("=================Network::debug()=========\n");
[8228]162  this->networkStream->debug();
[6695]163  PRINT(0)("===========================================\n");
[5997]164}
Note: See TracBrowser for help on using the repository browser.