Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/network/src/lib/network/synchronizeable.cc @ 6659

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

network: the Synchronizeables now all get connected

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