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
Line 
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
11
12### File Specific:
13   main-programmer: Silvan Nellen
14   co-programmer: Benjamin Wuest
15*/
16
17#define DEBUG_MODULE_NETWORK
18
19#include "synchronizeable.h"
20
21#include "netdefs.h"
22#include "network_manager.h"
23#include "network_game_manager.h"
24#include "network_stream.h"
25
26#include "assert.h"
27
28
29/**
30 *  default constructor
31 */
32Synchronizeable::Synchronizeable()
33{
34  this->setClassID(CL_SYNCHRONIZEABLE, "Synchronizeable");
35  this->owner = 0;
36  this->state = 0;
37  this->hostID = NetworkManager::getInstance()->getHostID();
38  this->setIsServer(this->hostID == 0);
39  this->uniqueID = -1;
40  this->networkStream = NULL;
41  this->setRequestedSync( false );
42  this->setIsOutOfSync( !(this->isServer()) );
43
44  this->bSynchronize = false;
45  NetworkStream* nd = NetworkManager::getInstance()->getDefaultSyncStream();
46  assert(nd != NULL);
47  nd->connectSynchronizeable(*this);
48}
49
50
51
52/**
53 *  default destructor deletes all unneded stuff
54 */
55Synchronizeable::~Synchronizeable()
56{
57  if ( this->networkStream )
58    this->networkStream->disconnectSynchronizeable(*this);
59}
60
61
62/**
63 *  write data to NetworkStream
64 */
65int Synchronizeable::writeBytes(const byte* data, int length, int sender)
66{
67  PRINTF(5)("Synchronizeable::writeBytes was called\n");
68}
69
70
71/**
72 *  read data from NetworkStream
73 */
74int Synchronizeable::readBytes(byte* data, int maxLength, int * reciever)
75{
76  PRINTF(5)("Synchronizeable::readBytes was called\n");
77}
78
79
80void Synchronizeable::writeDebug() const
81{}
82
83
84void Synchronizeable::readDebug() const
85{}
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
100
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);
111  //PRINTF(0)("isoutofsync %s %d\n", this->getClassName(), state);
112}
113
114
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{
121  return (this->state & STATE_SERVER) >0;
122}
123
124
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{
131  return (this->state & STATE_OUTOFSYNC) >0;
132}
133
134
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}
143
144
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}
156
157
158
Note: See TracBrowser for help on using the repository browser.