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 | */ |
---|
28 | Synchronizeable::Synchronizeable() |
---|
29 | { |
---|
30 | |
---|
31 | owner = 0; |
---|
32 | hostID = NetworkManager::getInstance()->getHostID(); |
---|
33 | uniqueID = -1; |
---|
34 | //state = ?; |
---|
35 | |
---|
36 | } |
---|
37 | |
---|
38 | /** |
---|
39 | * default constructor |
---|
40 | */ |
---|
41 | Synchronizeable::Synchronizeable(const char* name) |
---|
42 | { |
---|
43 | this->setName(name); |
---|
44 | } |
---|
45 | |
---|
46 | |
---|
47 | /** |
---|
48 | * default destructor deletes all unneded stuff |
---|
49 | */ |
---|
50 | Synchronizeable::~Synchronizeable() |
---|
51 | { |
---|
52 | if ( this->networkStream ) |
---|
53 | this->networkStream->disconnectSynchronizeable(*this); |
---|
54 | } |
---|
55 | |
---|
56 | /** |
---|
57 | * write data to NetworkStream |
---|
58 | */ |
---|
59 | void Synchronizeable::writeBytes(const byte* data, int length) |
---|
60 | { |
---|
61 | PRINTF(1)("Synchronizeable::writeBytes was called\n"); |
---|
62 | } |
---|
63 | |
---|
64 | /** |
---|
65 | * read data from NetworkStream |
---|
66 | */ |
---|
67 | int Synchronizeable::readBytes(byte* data, int maxLength, int * reciever) |
---|
68 | { |
---|
69 | PRINTF(1)("Synchronizeable::readBytes was called\n"); |
---|
70 | } |
---|
71 | |
---|
72 | |
---|
73 | void Synchronizeable::writeDebug() const |
---|
74 | {} |
---|
75 | |
---|
76 | |
---|
77 | void Synchronizeable::readDebug() const |
---|
78 | {} |
---|
79 | |
---|
80 | |
---|
81 | /** |
---|
82 | * Sets the server flag to a given value |
---|
83 | * @param isServer: the boolean value which the server flag is to set to |
---|
84 | */ |
---|
85 | void Synchronizeable::setIsServer(bool isServer) |
---|
86 | { |
---|
87 | if( isServer ) |
---|
88 | this->state = this->state | STATE_SERVER; |
---|
89 | else |
---|
90 | this->state = this->state & (~STATE_SERVER); |
---|
91 | } |
---|
92 | |
---|
93 | /** |
---|
94 | * Sets the outofsync flag to a given value |
---|
95 | * @param outOfSync: the boolean value which the outofsync flag is to set to |
---|
96 | */ |
---|
97 | void Synchronizeable::setIsOutOfSync(bool outOfSync) |
---|
98 | { |
---|
99 | if( outOfSync ) |
---|
100 | this->state = this->state | STATE_OUTOFSYNC; |
---|
101 | else |
---|
102 | this->state = this->state & (~STATE_OUTOFSYNC); |
---|
103 | } |
---|
104 | |
---|
105 | /** |
---|
106 | * Determines if the server flag is set |
---|
107 | * @return true, if the server flag is true, false else |
---|
108 | */ |
---|
109 | bool Synchronizeable::isServer() |
---|
110 | { |
---|
111 | return this->state & STATE_SERVER == STATE_SERVER; |
---|
112 | } |
---|
113 | |
---|
114 | /** |
---|
115 | * Determines if the outofsync flag is set |
---|
116 | * @return true, if the outofsync flag is true, false else |
---|
117 | */ |
---|
118 | bool Synchronizeable::isOutOfSync() |
---|
119 | { |
---|
120 | return this->state & STATE_OUTOFSYNC == STATE_OUTOFSYNC; |
---|
121 | } |
---|
122 | |
---|
123 | |
---|
124 | |
---|