[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] | 28 | Synchronizeable::Synchronizeable() |
---|
[5997] | 29 | { |
---|
[5996] | 30 | |
---|
[6139] | 31 | owner = 0; |
---|
| 32 | hostID = NetworkManager::getInstance()->getHostID(); |
---|
| 33 | uniqueID = -1; |
---|
[5997] | 34 | //state = ?; |
---|
| 35 | |
---|
| 36 | } |
---|
| 37 | |
---|
[5996] | 38 | /** |
---|
| 39 | * default constructor |
---|
| 40 | */ |
---|
[5804] | 41 | Synchronizeable::Synchronizeable(const char* name) |
---|
[5523] | 42 | { |
---|
[5807] | 43 | this->setName(name); |
---|
[5523] | 44 | } |
---|
| 45 | |
---|
[5996] | 46 | |
---|
[5547] | 47 | /** |
---|
[5807] | 48 | * default destructor deletes all unneded stuff |
---|
[5547] | 49 | */ |
---|
| 50 | Synchronizeable::~Synchronizeable() |
---|
[6139] | 51 | { |
---|
| 52 | if ( this->networkStream ) |
---|
| 53 | this->networkStream->disconnectSynchronizeable(*this); |
---|
| 54 | } |
---|
[5523] | 55 | |
---|
[5547] | 56 | /** |
---|
[5807] | 57 | * write data to NetworkStream |
---|
[5547] | 58 | */ |
---|
[5807] | 59 | void Synchronizeable::writeBytes(const byte* data, int length) |
---|
[6139] | 60 | { |
---|
| 61 | PRINTF(1)("Synchronizeable::writeBytes was called\n"); |
---|
| 62 | } |
---|
[5523] | 63 | |
---|
[5547] | 64 | /** |
---|
[5807] | 65 | * read data from NetworkStream |
---|
[5547] | 66 | */ |
---|
[6139] | 67 | int Synchronizeable::readBytes(byte* data, int maxLength, int * reciever) |
---|
| 68 | { |
---|
| 69 | PRINTF(1)("Synchronizeable::readBytes was called\n"); |
---|
| 70 | } |
---|
[5547] | 71 | |
---|
| 72 | |
---|
[5807] | 73 | void Synchronizeable::writeDebug() const |
---|
| 74 | {} |
---|
[5547] | 75 | |
---|
| 76 | |
---|
[5807] | 77 | void Synchronizeable::readDebug() const |
---|
| 78 | {} |
---|
[5997] | 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 | } |
---|
[6139] | 122 | |
---|
| 123 | |
---|
| 124 | |
---|