Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/network/synchronizeable.cc @ 7679

Last change on this file since 7679 was 6753, checked in by patrick, 19 years ago

trunk: merged network back to trunk

File size: 3.5 KB
RevLine 
[5523]1/*
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
[5547]11
[5523]12### File Specific:
13   main-programmer: Silvan Nellen
[5997]14   co-programmer: Benjamin Wuest
[5547]15*/
[5523]16
[6139]17#define DEBUG_MODULE_NETWORK
18
[6695]19#include "shared_network_data.h"
20#include "network_stream.h"
[5547]21#include "netdefs.h"
[5529]22
[6695]23#include "state.h"
[5996]24
[6753]25#include <cassert>
[6695]26
27#include "synchronizeable.h"
28
29
30
[5547]31/**
[5807]32 *  default constructor
[5547]33 */
[5996]34Synchronizeable::Synchronizeable()
[5997]35{
[6341]36  this->setClassID(CL_SYNCHRONIZEABLE, "Synchronizeable");
[6753]37  this->owner = -1;
[6695]38  this->state = 0;
39  this->hostID = SharedNetworkData::getInstance()->getHostID();
[6341]40  this->setIsServer(this->hostID == 0);
[6695]41  this->uniqueID = NET_UID_UNASSIGNED;
[6145]42  this->networkStream = NULL;
[6341]43  this->setRequestedSync( false );
[6424]44  this->setIsOutOfSync( !(this->isServer()) );
[6695]45  this->bSynchronize = false;
46
47  if( State::isOnline())
48  {
49    NetworkStream* nd = SharedNetworkData::getInstance()->getDefaultSyncStream();
50    assert(nd != NULL);
51    nd->connectSynchronizeable(*this);
52    this->setUniqueID(SharedNetworkData::getInstance()->getNewUniqueID());
53  }
[5997]54}
55
[5523]56
[5996]57
[5547]58/**
[5807]59 *  default destructor deletes all unneded stuff
[5547]60 */
61Synchronizeable::~Synchronizeable()
[6139]62{
63  if ( this->networkStream )
64    this->networkStream->disconnectSynchronizeable(*this);
65}
[5523]66
[6695]67
[5547]68/**
[5807]69 *  write data to NetworkStream
[5547]70 */
[6341]71int Synchronizeable::writeBytes(const byte* data, int length, int sender)
[6139]72{
[6341]73  PRINTF(5)("Synchronizeable::writeBytes was called\n");
[6139]74}
[5523]75
[6695]76
[5547]77/**
[5807]78 *  read data from NetworkStream
[5547]79 */
[6139]80int Synchronizeable::readBytes(byte* data, int maxLength, int * reciever)
81{
[6341]82  PRINTF(5)("Synchronizeable::readBytes was called\n");
[6139]83}
[5547]84
85
[5807]86void Synchronizeable::writeDebug() const
87{}
[5547]88
89
[5807]90void Synchronizeable::readDebug() const
91{}
[5997]92
93
94/**
95 * Sets the server flag to a given value
96 * @param isServer: the boolean value which the server flag is to set to
97 */
98void Synchronizeable::setIsServer(bool isServer)
99{
100  if( isServer )
101    this->state = this->state | STATE_SERVER;
102  else
103    this->state = this->state & (~STATE_SERVER);
104}
105
[6695]106
[5997]107/**
108 * Sets the outofsync flag to a given value
109 * @param outOfSync: the boolean value which the outofsync flag is to set to
110 */
111void Synchronizeable::setIsOutOfSync(bool outOfSync)
112{
113  if( outOfSync )
114    this->state = this->state | STATE_OUTOFSYNC;
115  else
116    this->state = this->state & (~STATE_OUTOFSYNC);
[6341]117  //PRINTF(0)("isoutofsync %s %d\n", this->getClassName(), state);
[5997]118}
119
[6695]120
[5997]121/**
122 * Determines if the server flag is set
123 * @return true, if the server flag is true, false else
124 */
125bool Synchronizeable::isServer()
126{
[6341]127  return (this->state & STATE_SERVER) >0;
[5997]128}
129
[6695]130
[5997]131/**
132 * Determines if the outofsync flag is set
133 * @return true, if the outofsync flag is true, false else
134 */
135bool Synchronizeable::isOutOfSync()
136{
[6341]137  return (this->state & STATE_OUTOFSYNC) >0;
[5997]138}
[6139]139
[6695]140
[6341]141/**
142 * Determines if the requestedSync flag is set
143 * @return true, if the requestedSync flag is true, false else
144 */
145bool Synchronizeable::requestedSync()
146{
147  return (this->state & STATE_REQUESTEDSYNC) >0;
148}
[6139]149
[6695]150
[6341]151/**
152 * Sets the requestedsync flag to a given value
153 * @param requestedSync: the boolean value which the requestedsync flag is to set to
154 */
155void Synchronizeable::setRequestedSync( bool requestedSync )
156{
157  if( requestedSync )
158    this->state = this->state | STATE_REQUESTEDSYNC;
159  else
160    this->state = this->state & (~STATE_REQUESTEDSYNC);
161}
[6139]162
[6341]163
164
Note: See TracBrowser for help on using the repository browser.