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