Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 6341 was 6341, checked in by bensch, 18 years ago

orxonox/trunk: merged the network branche back to the trunk, so we do not get away from each other to fast

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