Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 6513 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
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#include "netdefs.h"
21#include "network_manager.h"
22#include "network_stream.h"
23
24
25/**
26 *  default constructor
27 */
28Synchronizeable::Synchronizeable()
29{
30  this->setClassID(CL_SYNCHRONIZEABLE, "Synchronizeable");
31  owner = 0;
32  state = 0;
33  hostID = NetworkManager::getInstance()->getHostID();
34  this->setIsServer(this->hostID == 0);
35  uniqueID = -1;
36  this->networkStream = NULL;
37  this->setRequestedSync( false );
38  this->setIsOutOfSync( !(this->isServer()) );
39}
40
41
42
43/**
44 *  default destructor deletes all unneded stuff
45 */
46Synchronizeable::~Synchronizeable()
47{
48  if ( this->networkStream )
49    this->networkStream->disconnectSynchronizeable(*this);
50}
51
52/**
53 *  write data to NetworkStream
54 */
55int Synchronizeable::writeBytes(const byte* data, int length, int sender)
56{
57  PRINTF(5)("Synchronizeable::writeBytes was called\n");
58}
59
60/**
61 *  read data from NetworkStream
62 */
63int Synchronizeable::readBytes(byte* data, int maxLength, int * reciever)
64{
65  PRINTF(5)("Synchronizeable::readBytes was called\n");
66}
67
68
69void Synchronizeable::writeDebug() const
70{}
71
72
73void Synchronizeable::readDebug() const
74{}
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);
99  //PRINTF(0)("isoutofsync %s %d\n", this->getClassName(), state);
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{
108  return (this->state & STATE_SERVER) >0;
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{
117  return (this->state & STATE_OUTOFSYNC) >0;
118}
119
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}
128
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}
140
141
142
Note: See TracBrowser for help on using the repository browser.