Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 6656 was 6424, checked in by bensch, 19 years ago

orxonox/trunk: merged the branche network back to the trunk
merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/network . -r 6351:HEAD
no conflicts

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