- Timestamp:
- Oct 12, 2008, 7:40:47 PM (16 years ago)
- Location:
- code/trunk
- Files:
-
- 42 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/TODO
r1534 r1907 1 - should we use enet_peer_ping to test if a client is still alive ? 2 - enet_host_broadcast ? (to all peers) 1 todo: 2 !!! check that enet does not cause a packet traffic jam when a reliable packet gets missed !!! 3 [implemented] new gamestate concept 4 5 !!! ensure that objects get synched, when newly created, even if not their tick 6 7 setvariable mode 8 objectmode 9 priorities (put into gamestatehandler) 10 manage delete object handling (only send deletes of acked objects) 11 static (sync once) & triggerSync 12 13 REMARKS: 14 try to allocate sort the bytestream before copy (putt all 0's in one place) -
code/trunk/bin/ogre.cfg-init
r1505 r1907 4 4 FSAA=0 5 5 Full Screen=No 6 RTT Preferred Mode= FBO7 Video Mode= 1024 x 7686 RTT Preferred Mode=PBuffer 7 Video Mode=640 x 480 -
code/trunk/src/network/CMakeLists.txt
r1740 r1907 17 17 packet/Gamestate.cc 18 18 packet/Welcome.cc 19 packet/DeleteObjects.cc 19 20 ) 20 21 -
code/trunk/src/network/Client.cc
r1769 r1907 43 43 #include "Synchronisable.h" 44 44 #include "core/CoreIncludes.h" 45 #include "core/ConsoleCommand.h"46 45 #include "packet/Packet.h" 47 46 // #include "packet/Acknowledgement.h" … … 61 60 isSynched_=false; 62 61 gameStateFailure_=false; 63 isServer_ = false;64 62 } 65 63 … … 73 71 isSynched_=false; 74 72 gameStateFailure_=false; 75 isServer_ = false;76 73 } 77 74 … … 85 82 isSynched_=false; 86 83 gameStateFailure_=false; 87 isServer_ = false;88 84 } 89 85 … … 118 114 } 119 115 120 bool Client::processChat(packet::Chat *message, unsigned int clientID){ 121 return message->process(); 116 bool Client::processChat(std::string message, unsigned int playerID){ 117 COUT(1) << "Player " << playerID << ": " << message << std::endl; 118 return true; 122 119 } 123 124 /*bool Client::sendChat(packet::Chat *chat){ 125 chat->process(); 126 packet::Packet *p = new packet::Packet(chat); 127 return p->send(); 128 }*/ 120 121 /** 122 * This function implements the method of sending a chat message to the server 123 * @param message message to be sent 124 * @return result(true/false) 125 */ 126 bool Client::chat(std::string message){ 127 packet::Chat *m = new packet::Chat(message, Host::getPlayerID()); 128 return m->send(); 129 } 129 130 130 131 131 132 /** 132 * submits a chat message to the server 133 * @param message message to send 134 * @return true/false 135 */ 136 bool Client::sendChat( std::string message ){ 137 // generate packet and add it to queue 138 if(!isConnected) 139 return false; 140 packet::Chat chat(message, 0); 141 return chat.send(); 142 // send packets 143 } 144 145 /** 146 * Performs a GameState update 147 */ 133 * Processes incoming packets, sends a gamestate to the server and does the cleanup 134 * @param time 135 */ 148 136 void Client::tick(float time){ 149 137 // COUT(3) << "."; … … 164 152 COUT(5) << "tick packet size " << event->packet->dataLength << std::endl; 165 153 packet::Packet *packet = packet::Packet::createPacket(event->packet, event->peer); 166 assert(packet->process()); 154 bool b = packet->process(); 155 assert(b); 167 156 } 168 157 if(gamestate.processGamestates()) … … 170 159 if(!isSynched_) 171 160 isSynched_=true; 172 }else 173 COUT(3) << "gamestate has not been processed sucessfully" << std::endl; 161 } 174 162 gamestate.cleanup(); 175 163 return; -
code/trunk/src/network/Client.h
r1735 r1907 73 73 bool closeConnection(); 74 74 bool queuePacket(ENetPacket *packet, int clientID); 75 bool processChat(packet::Chat *message, unsigned int clientID); 75 bool processChat(std::string message, unsigned int playerID); 76 virtual bool chat(std::string message); 76 77 //bool sendChat(packet::Chat *chat); 77 78 78 79 // static void Chat( std::string message ); 79 80 80 unsigned int shipID(){return shipID_;}81 int playerID(){return clientID_;}82 81 //static void setShipID( unsigned int shipID){ dynamic_cast<Client *>(instance_)->shipID_=shipID; } 83 82 static void setClientID( unsigned int clientID){ dynamic_cast<Client *>(instance_)->clientID_=clientID; } … … 86 85 87 86 private: 87 virtual bool isServer_(){return false;} 88 88 89 89 ClientConnection client_connection; … … 91 91 bool isConnected; 92 92 bool isSynched_; 93 94 bool sendChat( std::string message );95 93 96 // implement data processing functions of PacketDecoder97 // void processChat( chat *data, int clientId );98 int clientID_; // this is the id the server gave to us99 int shipID_;100 94 bool gameStateFailure_; 101 95 }; -
code/trunk/src/network/ClientConnection.cc
r1755 r1907 77 77 } 78 78 79 80 /*ENetPacket *ClientConnection::getPacket(ENetAddress &address) { 81 if(!buffer.isEmpty()) { 82 //std::cout << "###BUFFER IS NOT EMPTY###" << std::endl; 83 return buffer.pop(address); 84 } 85 else{ 86 return NULL; 87 } 88 } 89 90 ENetPacket *ClientConnection::getPacket() { 91 ENetAddress address; //sems that address is not needed 92 return getPacket(address); 93 }*/ 79 ClientConnection::~ClientConnection(){ 80 if(established) 81 closeConnection(); 82 } 94 83 95 84 ENetEvent *ClientConnection::getEvent(){ -
code/trunk/src/network/ClientConnection.h
r1785 r1907 64 64 ClientConnection(int port, std::string address); 65 65 ClientConnection(int port, const char* address); 66 //ENetPacket *getPacket(ENetAddress &address); // thread1 67 //ENetPacket *getPacket(); // thread1 66 ~ClientConnection(); 68 67 ENetEvent *getEvent(); 69 68 // check wheter the packet queue is empty -
code/trunk/src/network/ConnectionManager.cc
r1856 r1907 81 81 boost::recursive_mutex ConnectionManager::enet_mutex; 82 82 83 // ConnectionManager::ConnectionManager(ClientInformation *head) : receiverThread_(0) {84 // assert(instance_==0);85 // instance_=this;86 // quit=false;87 // bindAddress.host = ENET_HOST_ANY;88 // bindAddress.port = NETWORK_PORT;89 // }90 91 83 ConnectionManager::ConnectionManager(int port){ 92 84 assert(instance_==0); … … 114 106 115 107 ConnectionManager::~ConnectionManager(){ 116 instance_=0;117 108 if(!quit) 118 109 quitListener(); 119 } 120 121 /*ENetPacket *ConnectionManager::getPacket(ENetAddress &address) { 122 if(!buffer.isEmpty()) 123 return buffer.pop(address); 124 else 125 return NULL; 126 }*/ 127 /** 128 This function only pops the first element in PacketBuffer (first in first out) 129 used by processQueue in Server.cc 130 */ 131 /*ENetPacket *ConnectionManager::getPacket(int &clientID) { 132 ENetAddress address; 133 ENetPacket *packet=getPacket(address); 134 ClientInformation *temp =head_->findClient(&address); 135 if(!temp) 136 return NULL; 137 clientID=temp->getID(); 138 return packet; 139 }*/ 110 instance_=0; 111 } 112 140 113 141 114 ENetEvent *ConnectionManager::getEvent(){ … … 164 137 } 165 138 166 // bool ConnectionManager::addPacket(Packet::Packet *packet){167 // ClientInformation *temp = instance_->head_->findClient(packet->getClientID());168 // if(!temp){169 // COUT(3) << "C.Man: addPacket findClient failed" << std::endl;170 // return false;171 // }172 // ENetPacket *packet = new ENetPacket;173 // // TODO: finish implementation174 // }175 //176 139 177 140 bool ConnectionManager::addPacket(ENetPacket *packet, ENetPeer *peer) { … … 373 336 orxonox::ObjectList<orxonox::SpaceShip>::iterator it; 374 337 for(it = orxonox::ObjectList<orxonox::SpaceShip>::begin(); it; ++it){ 375 if(it-> objectID!=id)338 if(it->getObjectID()!=id) 376 339 continue; 377 340 delete *it; -
code/trunk/src/network/GamestateClient.cc
r1769 r1907 156 156 if(myShip_){ 157 157 // unsigned char *data = new unsigned char[myShip_->getSize()]; 158 int size=myShip_->getSize 2(0, 0x1);158 int size=myShip_->getSize(0, 0x1); 159 159 if(size==0) 160 160 return false; … … 182 182 packet::Gamestate *GamestateClient::processGamestate(packet::Gamestate *gs){ 183 183 if(gs->isCompressed()) 184 assert(gs->decompressData()); 184 { 185 bool b = gs->decompressData(); 186 assert(b); 187 } 185 188 if(gs->isDiffed()){ 186 189 packet::Gamestate *base = gamestateMap_[gs->getBaseID()]; … … 189 192 return 0; 190 193 } 191 // assert(base); //TODO: fix this194 // assert(base); //TODO: fix this 192 195 packet::Gamestate *undiffed = gs->undiff(base); 193 196 delete gs; -
code/trunk/src/network/GamestateManager.cc
r1769 r1907 61 61 62 62 bool GamestateManager::update(){ 63 cleanup();63 // cleanup(); 64 64 return getSnapshot(); 65 65 } … … 92 92 reference = new packet::Gamestate(); 93 93 reference->collectData(++id_); 94 COUT(4) << "inserting gamestate: " << reference << std::endl;95 gamestateMap.insert(std::pair<int, packet::Gamestate*>(id_, reference));96 gamestateUsed[id_]=0;94 //COUT(4) << "inserting gamestate: " << reference << std::endl; 95 //gamestateMap_.insert(std::pair<int, packet::Gamestate*>(id_, reference)); 96 // gamestateUsed[id_]=0; 97 97 return true; 98 98 } … … 104 104 * 105 105 */ 106 void GamestateManager::cleanup(){106 /* void GamestateManager::cleanup(){ 107 107 std::map<int,int>::iterator it = gamestateUsed.begin(); 108 108 while(it!=gamestateUsed.end()){ … … 124 124 it++; 125 125 } 126 } 126 }*/ 127 127 128 128 packet::Gamestate *GamestateManager::popGameState(int clientID) { … … 131 131 packet::Gamestate *gs; 132 132 int gID = ClientInformation::findClient(clientID)->getGamestateID(); 133 //COUT(4) << "G.St.Man: popgamestate: sending gstate_id: " << id_ << " diffed from: " << gID << std::endl; 133 gs = reference->doSelection(clientID); 134 // gs = new packet::Gamestate(*reference); 135 // gs = new packet::Gamestate(*reference); 136 // save the (undiffed) gamestate in the clients gamestate map 137 gamestateMap_[clientID].insert(std::pair<int, packet::Gamestate*>(gs->getID(), gs)); 134 138 //chose wheather the next gamestate is the first or not 139 packet::Gamestate *client=NULL; 135 140 if(gID != GAMESTATEID_INITIAL){ 136 packet::Gamestate *client=NULL; 137 std::map<int, packet::Gamestate*>::iterator it = gamestateMap.find(gID); 138 if(it!=gamestateMap.end()) 139 client = it->second; 140 if(client) 141 gs = reference->diff(client); 142 else 143 gs = new packet::Gamestate(*reference); 144 } else { 145 COUT(4) << "we got a GAMESTATEID_INITIAL for clientID: " << clientID << std::endl; 146 gs = new packet::Gamestate(*reference); 147 } 148 assert(gs->compressData()); 141 std::map<unsigned int, std::map<int, packet::Gamestate*> >::iterator clientMap = gamestateMap_.find(clientID); 142 if(clientMap!=gamestateMap_.end()){ 143 std::map<int, packet::Gamestate*>::iterator it = clientMap->second.find(gID); 144 if(it!=clientMap->second.end()) 145 client = it->second; 146 } 147 } 148 if(client){ 149 // COUT(3) << "diffing" << std::endl; 150 gs = gs->diff(client); 151 } 152 else{ 153 // COUT(3) << "not diffing" << std::endl; 154 gs = new packet::Gamestate(*gs); 155 } 156 bool b = gs->compressData(); 157 assert(b); 149 158 return gs; 150 159 } … … 153 162 bool GamestateManager::ack(int gamestateID, int clientID) { 154 163 ClientInformation *temp = ClientInformation::findClient(clientID); 155 if(temp==0) 156 return false; 164 assert(temp); 157 165 int curid = temp->getGamestateID(); 158 166 159 167 if(gamestateID == 0){ 160 168 temp->setGamestateID(GAMESTATEID_INITIAL); 161 if(curid!=GAMESTATEID_INITIAL){162 assert(gamestateUsed.find(curid)!=gamestateUsed.end());163 --(gamestateUsed.find(curid)->second);164 }165 169 return true; 166 170 } 167 //if(curid > gamestateID)171 168 172 assert(curid<gamestateID); 169 // the network packets got messed up170 //return true;171 173 COUT(4) << "acking gamestate " << gamestateID << " for clientid: " << clientID << " curid: " << curid << std::endl; 172 // decrease usage of gamestate and save it 173 // deleteUnusedGameState(curid); 174 //increase gamestateused 175 std::map<int, int>::iterator it = gamestateUsed.find(curid); 176 if(curid!=GAMESTATEID_INITIAL){ 177 if(it!=gamestateUsed.end()) 178 --(it->second); 179 } 180 it = gamestateUsed.find(gamestateID); 181 if(it!=gamestateUsed.end()){ 182 ++(it->second); 183 temp->setGamestateID(gamestateID); 184 } 174 std::map<int, packet::Gamestate*>::iterator it, tempit; 175 for(it = gamestateMap_[clientID].begin(); it!=gamestateMap_[clientID].end() && it->first<gamestateID; it++){ 176 delete it->second; 177 tempit=it++; 178 gamestateMap_[clientID].erase(tempit); 179 } 180 temp->setGamestateID(gamestateID); 185 181 return true; 186 182 } 187 183 188 184 void GamestateManager::removeClient(ClientInformation* client){ 189 if(!client) 190 return; 191 if(client->getGamestateID()>=0) 192 gamestateUsed[client->getGamestateID()]--; 185 assert(client); 186 std::map<unsigned int, std::map<int, packet::Gamestate*> >::iterator clientMap = gamestateMap_.find(client->getID()); 187 // first delete all remained gamestates 188 std::map<int, packet::Gamestate*>::iterator it; 189 for(it=clientMap->second.begin(); it!=clientMap->second.end(); it++) 190 delete it->second; 191 // now delete the clients gamestatemap 192 gamestateMap_.erase(clientMap); 193 193 } 194 194 195 195 bool GamestateManager::processGamestate(packet::Gamestate *gs){ 196 196 if(gs->isCompressed()) 197 assert(gs->decompressData()); 197 { 198 bool b = gs->decompressData(); 199 assert(b); 200 } 198 201 assert(!gs->isDiffed()); 199 202 return gs->spreadData(); -
code/trunk/src/network/GamestateManager.h
r1785 r1907 81 81 void removeClient(ClientInformation *client); 82 82 private: 83 void cleanup(); // "garbage handler"83 // void cleanup(); // "garbage handler" 84 84 bool processGamestate(packet::Gamestate *gs); 85 85 86 std::map<int, packet::Gamestate*> gamestateMap; //map gsID to gamestate* 87 std::map<int, int> gamestateUsed; // save the number of clients, that use the specific gamestate 86 std::map<unsigned int, std::map<int, packet::Gamestate*> > gamestateMap_; 87 //std::map<int, packet::Gamestate*> gamestateMap; //map gsID to gamestate* 88 //std::map<int, int> gamestateUsed; // save the number of clients, that use the specific gamestate 88 89 std::map<int, packet::Gamestate*> gamestateQueue; 89 90 packet::Gamestate *reference; -
code/trunk/src/network/Host.cc
r1751 r1907 30 30 31 31 #include "Host.h" 32 #include "core/ConsoleCommand.h" 32 33 #include "packet/Packet.h" 33 34 34 35 namespace network { 35 36 37 SetConsoleCommandShortcut(Host, Chat); 38 36 39 Host *Host::instance_=0; 37 40 41 /** 42 * @brief Constructor: assures that only one reference will be created and sets the pointer 43 */ 38 44 Host::Host() 39 45 { 46 clientID_=0; 40 47 assert(instance_==0); 41 48 instance_=this; … … 43 50 44 51 52 /** 53 * @brief Destructor: resets the instance pointer to 0 54 */ 45 55 Host::~Host() 46 56 { … … 48 58 } 49 59 60 /** 61 * This function is used to add an enetpacket to be sent to another peer 62 * @param packet Packet to be added 63 * @param clientID ID of the client the packet should be sent to 64 * @return success? 65 */ 50 66 bool Host::addPacket(ENetPacket *packet, int clientID){ 51 67 if(instance_) … … 70 86 // } 71 87 72 int Host::getPlayerID(){ 88 /** 89 * This function returns the ID of the player 90 * @return playerID 91 */ 92 unsigned int Host::getPlayerID(){ 73 93 if(!instance_) 74 94 return 0; 75 return instance_-> playerID();95 return instance_->clientID_; 76 96 } 77 97 78 // unsigned int Host::getShipID(){ 79 // if(!instance_) 80 // assert(0); 81 // return instance_->shipID(); 82 // } 98 bool Host::Chat(std::string message){ 99 if(!instance_) 100 return false; 101 return instance_->chat(message); 102 } 103 104 bool Host::incomingChat(std::string message, unsigned int playerID){ 105 return instance_->processChat(message, playerID); 106 } 83 107 84 108 }//namespace network -
code/trunk/src/network/Host.h
r1751 r1907 37 37 38 38 /** 39 @author Oliver Scheuss 39 * @brief Base class of Server and Client 40 * This is the Base class of the Server and Client classes 41 * - Makes server and client a singleton 42 * - defines static functions available on both server and client 43 * - is the interface to be used when communicating with the network 44 * @author Oliver Scheuss 40 45 */ 41 46 class Host{ … … 45 50 //virtual bool sendChat(packet::Chat *chat)=0; 46 51 virtual bool queuePacket(ENetPacket *packet, int clientID)=0; 47 virtual unsigned int shipID()=0; 48 virtual int playerID()=0; 52 virtual bool chat(std::string message)=0; 53 virtual bool processChat(std::string message, unsigned int playerID)=0; 54 virtual bool isServer_()=0; 49 55 50 56 … … 54 60 virtual ~Host(); 55 61 static Host *instance_; 56 bool isServer_; 62 unsigned int clientID_; 63 unsigned int shipID_; 57 64 58 65 public: … … 61 68 //static bool chat(std::string& message); 62 69 // static bool receiveChat(packet::Chat *message, unsigned int clientID); 63 static int getPlayerID();70 static unsigned int getPlayerID(); 64 71 static unsigned int getShipID(){return instance_->shipID_;} 65 72 static void setClientID(unsigned int id){ instance_->clientID_ = id; } 66 73 static void setShipID(unsigned int id){ instance_->shipID_ = id; } 67 static bool isServer(){ return instance_->isServer_; } 74 static bool isServer(){ return instance_->isServer_(); } 75 static bool Chat(std::string message); 76 static bool incomingChat(std::string message, unsigned int playerID); 68 77 private: 69 unsigned int clientID_;70 unsigned int shipID_;71 78 }; 72 79 -
code/trunk/src/network/Server.cc
r1856 r1907 56 56 #include "packet/Packet.h" 57 57 #include "packet/Welcome.h" 58 #include "packet/DeleteObjects.h" 58 59 #include <util/Convert.h> 59 60 … … 71 72 connection = new ConnectionManager(); 72 73 gamestates_ = new GamestateManager(); 73 isServer_ = true;74 74 } 75 75 … … 78 78 connection = new ConnectionManager(port); 79 79 gamestates_ = new GamestateManager(); 80 isServer_ = true;81 80 } 82 81 … … 90 89 connection = new ConnectionManager(port, bindAddress); 91 90 gamestates_ = new GamestateManager(); 92 isServer_ = true;93 91 } 94 92 … … 102 100 connection = new ConnectionManager(port, bindAddress); 103 101 gamestates_ = new GamestateManager(); 104 isServer_ = true; 102 } 103 104 /** 105 * @brief Destructor 106 */ 107 Server::~Server(){ 108 if(connection) 109 delete connection; 110 if(gamestates_) 111 delete gamestates_; 105 112 } 106 113 … … 121 128 } 122 129 123 bool Server::processChat( packet::Chat *message, unsigned int clientID){130 bool Server::processChat(std::string message, unsigned int playerID){ 124 131 ClientInformation *temp = ClientInformation::getBegin(); 132 packet::Chat *chat; 125 133 while(temp){ 126 message->setClientID(temp->getID()); 127 if(!message->send()) 128 COUT(3) << "could not send Chat message to client ID: " << temp->getID() << std::endl; 129 temp = temp->next(); 130 } 131 return message->process(); 132 } 133 134 /** 135 * This function sends out a message to all clients 136 * @param msg message 137 * @return true/false 138 */ 139 bool Server::sendChat(packet::Chat *chat) { 140 //TODO: change this (no informations about who wrote a message) 141 assert(0); 142 ClientInformation *temp = ClientInformation::getBegin(); 143 while(temp){ 134 chat = new packet::Chat(message, playerID); 144 135 chat->setClientID(temp->getID()); 145 136 if(!chat->send()) 146 137 COUT(3) << "could not send Chat message to client ID: " << temp->getID() << std::endl; 147 } 148 return chat->process();; 149 } 150 151 /** 152 * This function sends out a message to all clients 153 * @param msg message 154 * @return true/false 155 */ 156 // bool Server::sendChat(const char *msg) { 157 // char *message = new char [strlen(msg)+10+1]; 158 // sprintf(message, "Player %d: %s", CLIENTID_SERVER, msg); 159 // COUT(1) << message << std::endl; 160 // ENetPacket *packet = packet_gen.chatMessage(message); 161 // COUT(5) <<"Server: adding Packets" << std::endl; 162 // return connection->addPacketAll(packet); 163 // } 138 temp = temp->next(); 139 } 140 COUT(1) << "Player " << playerID << ": " << message << std::endl; 141 return true; 142 } 143 164 144 165 145 /** … … 174 154 if(timeSinceLastUpdate_>=(1./NETWORK_FREQUENCY)){ 175 155 timeSinceLastUpdate_=(float)((int)(timeSinceLastUpdate_*NETWORK_FREQUENCY))/timeSinceLastUpdate_; 176 // timeSinceLastUpdate_-=1./NETWORK_FREQUENCY;177 156 gamestates_->processGamestates(); 178 157 updateGamestate(); 179 158 } 180 /*while(timeSinceLastUpdate_>1./NETWORK_FREQUENCY)181 timeSinceLastUpdate_-=1./NETWORK_FREQUENCY;*/182 // usleep(5000); // TODO remove183 return;184 159 } 185 160 … … 230 205 //if(clients->getGamestateID()!=GAMESTATEID_INITIAL) 231 206 sendGameState(); 207 sendObjectDeletes(); 232 208 COUT(5) << "Server: one sendGameState turn complete, repeat in next tick" << std::endl; 233 209 //std::cout << "sent gamestate" << std::endl; … … 276 252 // gs gets automatically deleted by enet callback 277 253 } 278 /*if(added) { 279 //std::cout << "send gamestates from server.cc in sendGameState" << std::endl; 280 return connection->sendPackets(); 281 }*/ 282 //COUT(5) << "Server: had no gamestates to send" << std::endl; 283 return true; 284 } 285 286 // void Server::processChat( chat *data, int clientId){ 287 // char *message = new char [strlen(data->message)+10+1]; 288 // sprintf(message, "Player %d: %s", clientId, data->message); 289 // COUT(1) << message << std::endl; 290 // ENetPacket *pck = packet_gen.chatMessage(message); 291 // connection->addPacketAll(pck); 292 // delete[] data->message; 293 // delete data; 294 // } 254 return true; 255 } 256 257 bool Server::sendObjectDeletes(){ 258 ClientInformation *temp = ClientInformation::getBegin(); 259 packet::DeleteObjects *del = new packet::DeleteObjects(); 260 if(!del->fetchIDs()) 261 return true; //everything ok (no deletes this tick) 262 // COUT(3) << "sending DeleteObjects" << std::endl; 263 while(temp != NULL){ 264 if( !(temp->getSynched()) ){ 265 COUT(5) << "Server: not sending gamestate" << std::endl; 266 temp=temp->next(); 267 continue; 268 } 269 int cid = temp->getID(); //get client id 270 packet::DeleteObjects *cd = new packet::DeleteObjects(*del); 271 assert(cd); 272 cd->setClientID(cid); 273 if ( !cd->send() ) 274 COUT(3) << "Server: packet with client id (cid): " << cid << " not sended: " << temp->getFailures() << std::endl; 275 temp=temp->next(); 276 // gs gets automatically deleted by enet callback 277 } 278 return true; 279 } 280 295 281 296 282 bool Server::addClient(ENetEvent *event){ … … 328 314 packet::Welcome *w = new packet::Welcome(temp->getID(), temp->getShipID()); 329 315 w->setClientID(temp->getID()); 330 assert(w->send()); 316 bool b = w->send(); 317 assert(b); 331 318 packet::Gamestate *g = new packet::Gamestate(); 332 319 g->setClientID(temp->getID()); 333 assert(g->collectData(0)); 334 assert(g->compressData()); 335 assert(g->send()); 320 b = g->collectData(0); 321 assert(b); 322 b = g->compressData(); 323 assert(b); 324 b = g->send(); 325 assert(b); 336 326 return true; 337 327 } … … 347 337 orxonox::SpaceShip *no = dynamic_cast<orxonox::SpaceShip *>(id->fabricate()); 348 338 no->classID = id->getNetworkID(); 349 client->setShipID(no-> objectID);339 client->setShipID(no->getObjectID()); 350 340 no->setPosition(orxonox::Vector3(0,0,80)); 351 341 no->setScale(10); … … 376 366 gamestates_->removeClient(client); 377 367 while(it){ 378 if(it-> objectID!=client->getShipID()){368 if(it->getObjectID()!=client->getShipID()){ 379 369 ++it; 380 370 continue; … … 397 387 gamestates_->removeClient(client); 398 388 } 389 390 bool Server::chat(std::string message){ 391 ClientInformation *temp = ClientInformation::getBegin(); 392 packet::Chat *chat; 393 while(temp){ 394 chat = new packet::Chat(message, Host::getPlayerID()); 395 chat->setClientID(temp->getID()); 396 if(!chat->send()) 397 COUT(3) << "could not send Chat message to client ID: " << temp->getID() << std::endl; 398 temp = temp->next(); 399 } 400 COUT(1) << "Player " << Host::getPlayerID() << ": " << message << std::endl; 401 return true; 402 } 399 403 400 404 } -
code/trunk/src/network/Server.h
r1785 r1907 63 63 Server(int port, std::string bindAddress); 64 64 Server(int port, const char *bindAddress); 65 ~Server(); 65 66 66 67 void open(); 67 68 void close(); 68 bool processChat(packet::Chat *message, unsigned int clientID); 69 bool sendChat(packet::Chat *chat); 69 bool processChat(std::string message, unsigned int playerID); 70 70 bool queuePacket(ENetPacket *packet, int clientID); 71 71 void tick(float time); … … 74 74 void updateGamestate(); 75 75 private: 76 virtual bool isServer_(){return true;} 76 77 unsigned int shipID(){return 0;} 77 int playerID(){return 0;}78 unsigned int playerID(){return 0;} 78 79 79 80 bool addClient(ENetEvent *event); … … 85 86 bool processPacket( ENetPacket *packet, ENetPeer *peer ); 86 87 bool sendGameState(); 87 88 bool sendObjectDeletes(); 89 virtual bool chat(std::string message); 88 90 89 91 //void processChat( chat *data, int clientId); -
code/trunk/src/network/Synchronisable.cc
r1856 r1907 51 51 namespace network 52 52 { 53 53 54 55 std::map<unsigned int, Synchronisable *> Synchronisable::objectMap_; 56 std::queue<unsigned int> Synchronisable::deletedObjects_; 54 57 55 58 int Synchronisable::state_=0x1; // detemines wheter we are server (default) or client … … 57 60 /** 58 61 * Constructor: 59 * calls registarAllVariables, that has to be implemented by the inheriting classID62 * Initializes all Variables and sets the right objectID 60 63 */ 61 64 Synchronisable::Synchronisable(){ 62 65 RegisterRootObject(Synchronisable); 63 static int idCounter=0; 64 datasize=0; 66 static uint32_t idCounter=0; 65 67 objectFrequency_=1; 66 objectMode_=0x1; // by default do not send data to server e68 objectMode_=0x1; // by default do not send data to server 67 69 objectID=idCounter++; 68 70 syncList = new std::list<synchronisableVariable *>; 69 //registerAllVariables(); 70 } 71 71 } 72 73 /** 74 * Destructor: 75 * Delete all callback objects and remove objectID from the objectMap_ 76 */ 72 77 Synchronisable::~Synchronisable(){ 73 78 // delete callback function objects 74 if(!orxonox::Identifier::isCreatingHierarchy()) 79 if(!orxonox::Identifier::isCreatingHierarchy()){ 75 80 for(std::list<synchronisableVariable *>::iterator it = syncList->begin(); it!=syncList->end(); it++) 76 81 delete (*it)->callback; 77 } 78 82 deletedObjects_.push(objectID); 83 // COUT(3) << "destruct synchronisable +++" << objectID << " | " << classID << std::endl; 84 // COUT(3) << " bump ---" << objectID << " | " << &objectMap_ << std::endl; 85 // assert(objectMap_[objectID]->objectID==objectID); 86 // objectMap_.erase(objectID); 87 } 88 } 89 90 /** 91 * This function gets called after all neccessary data has been passed to the object 92 * Overload this function and recall the create function of the parent class 93 * @return true/false 94 */ 79 95 bool Synchronisable::create(){ 80 96 this->classID = this->getIdentifier()->getNetworkID(); 81 COUT(4) << "creating synchronisable: setting classid from " << this->getIdentifier()->getName() << " to: " << classID << std::endl; 97 // COUT(4) << "creating synchronisable: setting classid from " << this->getIdentifier()->getName() << " to: " << classID << std::endl; 98 99 // COUT(3) << "construct synchronisable +++" << objectID << " | " << classID << std::endl; 100 // objectMap_[objectID]=this; 101 // assert(objectMap_[objectID]==this); 102 // assert(objectMap_[objectID]->objectID==objectID); 82 103 return true; 83 104 } 84 105 85 106 107 /** 108 * This function sets the internal mode for synchronisation 109 * @param b true if this object is located on a client or on a server 110 */ 86 111 void Synchronisable::setClient(bool b){ 87 112 if(b) // client … … 91 116 } 92 117 93 bool Synchronisable::fabricate(unsigned char*& mem, int mode) 118 /** 119 * This function fabricated a new synchrnisable (and children of it), sets calls updateData and create 120 * After calling this function the mem pointer will be increased by the size of the needed data 121 * @param mem pointer to where the appropriate data is located 122 * @param mode defines the mode, how the data should be loaded 123 * @return pointer to the newly created synchronisable 124 */ 125 Synchronisable *Synchronisable::fabricate(uint8_t*& mem, int mode) 94 126 { 95 unsigned int size, objectID, classID; 96 size = *(unsigned int *)mem; 97 objectID = *(unsigned int*)(mem+sizeof(unsigned int)); 98 classID = *(unsigned int*)(mem+2*sizeof(unsigned int)); 99 100 if(size==3*sizeof(unsigned int)){ //not our turn, dont do anything 101 mem+=3*sizeof(unsigned int); 102 return true; 103 } 104 105 orxonox::Identifier* id = ClassByID(classID); 106 if(!id){ 107 COUT(3) << "We could not identify a new object; classid: " << classID << " uint: " << (unsigned int)classID << " objectID: " << objectID << " size: " << size << std::endl; 108 assert(0); 109 return false; // most probably the gamestate is corrupted 110 } 127 synchronisableHeader *header = (synchronisableHeader *)mem; 128 129 COUT(3) << "fabricating object with id: " << header->objectID << std::endl; 130 131 orxonox::Identifier* id = ClassByID(header->classID); 132 assert(id); 111 133 orxonox::BaseObject *bo = id->fabricate(); 112 134 Synchronisable *no = dynamic_cast<Synchronisable *>(bo); 113 135 assert(no); 114 no->objectID= objectID;115 no->classID= classID;136 no->objectID=header->objectID; 137 no->classID=header->classID; 116 138 COUT(3) << "fabricate objectID: " << no->objectID << " classID: " << no->classID << std::endl; 117 139 // update data and create object/entity... 118 if( !no->updateData(mem, mode) ){ 119 COUT(1) << "We couldn't update the object: " << objectID << std::endl; 140 bool b = no->updateData(mem, mode); 141 assert(b); 142 b = no->create(); 143 assert(b); 144 return no; 145 } 146 147 148 /** 149 * Finds and deletes the Synchronisable with the appropriate objectID 150 * @param objectID objectID of the Synchronisable 151 * @return true/false 152 */ 153 bool Synchronisable::deleteObject(unsigned int objectID){ 154 // assert(getSynchronisable(objectID)); 155 if(!getSynchronisable(objectID)) 120 156 return false; 121 } 122 if( !no->create() ) 123 { 124 COUT(1) << "We couldn't manifest (create() ) the object: " << objectID << std::endl; 157 assert(getSynchronisable(objectID)->objectID==objectID); 158 // delete objectMap_[objectID]; 159 Synchronisable *s = getSynchronisable(objectID); 160 if(s) 161 delete s; 162 else 125 163 return false; 126 }127 164 return true; 128 165 } 129 166 167 /** 168 * This function looks up the objectID in the objectMap_ and returns a pointer to the right Synchronisable 169 * @param objectID objectID of the Synchronisable 170 * @return pointer to the Synchronisable with the objectID 171 */ 172 Synchronisable* Synchronisable::getSynchronisable(unsigned int objectID){ 173 orxonox::ObjectList<Synchronisable>::iterator it; 174 for(it = orxonox::ObjectList<Synchronisable>::begin(); it; ++it){ 175 if( it->getObjectID()==objectID ) 176 return *it; 177 } 178 return NULL; 179 180 // std::map<unsigned int, Synchronisable *>::iterator i = objectMap_.find(objectID); 181 // if(i==objectMap_.end()) 182 // return NULL; 183 // assert(i->second->objectID==objectID); 184 // return (*i).second; 185 } 186 187 130 188 /** 131 189 * This function is used to register a variable to be synchronized … … 133 191 * @param var pointer to the variable 134 192 * @param size size of the datatype the variable consists of 193 * @param t the type of the variable (network::DATA or network::STRING 194 * @param mode same as in getData 195 * @param cb callback object that should get called, if the value of the variable changes 135 196 */ 136 197 void Synchronisable::registerVar(void *var, int size, variableType t, int mode, NetworkCallbackBase *cb){ … … 143 204 temp->callback = cb; 144 205 COUT(5) << "Syncronisable::registering var with size: " << temp->size << " and type: " << temp->type << std::endl; 145 // increase datasize146 datasize+=sizeof(int)+size;147 206 //std::cout << "push temp to syncList (at the bottom) " << datasize << std::endl; 148 207 COUT(5) << "Syncronisable::objectID: " << objectID << " this: " << this << " name: " << this->getIdentifier()->getName() << " networkID: " << this->getIdentifier()->getNetworkID() << std::endl; 149 208 syncList->push_back(temp); 150 } 151 152 /** 153 * This function takes all SynchronisableVariables out of the Synchronisable and saves it into a syncData struct 154 * Difference to the above function: 209 #ifndef NDEBUG 210 std::list<synchronisableVariable *>::iterator it = syncList->begin(); 211 while(it!=syncList->end()){ 212 assert(*it!=var); 213 it++; 214 } 215 #endif 216 } 217 218 /** 219 * This function takes all SynchronisableVariables out of the Synchronisable and saves them together with the size, objectID and classID to the given memory 155 220 * takes a pointer to already allocated memory (must have at least getSize bytes length) 156 221 * structure of the bitstream: 157 * (var1_size,var1,var2_size,var2,...) 158 * varx_size: size = sizeof(int) 159 * varx: size = varx_size 160 * @return data containing all variables and their sizes 161 */ 162 bool Synchronisable::getData(unsigned char*& mem, unsigned int id, int mode){ 222 * |totalsize,objectID,classID,var1,var2,string1_length,string1,var3,...| 223 * length of varx: size saved int syncvarlist 224 * @param mem pointer to allocated memory with enough size 225 * @param id gamestateid of the gamestate to be saved (important for priorities) 226 * @param mode defines the direction in which the data will be send/received 227 * 0x1: server->client 228 * 0x2: client->server (not recommended) 229 * 0x3: bidirectional 230 * @return true: if !isMyTick or if everything was successfully saved 231 */ 232 bool Synchronisable::getData(uint8_t*& mem, unsigned int id, int mode){ 233 //if this tick is we dont synchronise, then abort now 234 if(!isMyTick(id)) 235 return true; 163 236 //std::cout << "inside getData" << std::endl; 164 237 unsigned int tempsize = 0; … … 167 240 if(classID==0) 168 241 COUT(3) << "classid 0 " << this->getIdentifier()->getName() << std::endl; 169 this->classID=this->getIdentifier()->getNetworkID(); // TODO: correct this 242 assert(this->classID==this->getIdentifier()->getNetworkID()); 243 // this->classID=this->getIdentifier()->getNetworkID(); // TODO: correct this 170 244 std::list<synchronisableVariable *>::iterator i; 171 245 unsigned int size; 172 size=getSize 2(id, mode);246 size=getSize(id, mode); 173 247 174 248 // start copy header 175 memcpy(mem, &size, sizeof(unsigned int));176 mem+=sizeof(unsigned int);177 memcpy(mem, &(this->objectID), sizeof(unsigned int));178 mem+=sizeof(unsigned int);179 memcpy(mem, &(this->classID), sizeof(unsigned int));180 mem+=sizeof(unsigned int);181 tempsize+=12;249 synchronisableHeader *header = (synchronisableHeader *)mem; 250 header->size = size; 251 header->objectID = this->objectID; 252 header->classID = this->classID; 253 header->dataAvailable = true; 254 tempsize+=sizeof(synchronisableHeader); 255 mem+=sizeof(synchronisableHeader); 182 256 // end copy header 183 257 184 //if this tick is we dont synchronise, then abort now185 if(!isMyTick(id))186 return true;187 258 188 259 COUT(5) << "Synchronisable getting data from objectID: " << objectID << " classID: " << classID << " length: " << size << std::endl; 189 260 // copy to location 190 261 for(i=syncList->begin(); i!=syncList->end(); ++i){ 191 //(std::memcpy(retVal.data+n, (const void*)(&(i->size)), sizeof(int));192 262 if( ((*i)->mode & mode) == 0 ){ 193 263 COUT(5) << "not getting data: " << std::endl; … … 217 287 218 288 /** 219 * This function takes a syncData struct and takes it to update the variables 220 * @param vars data of the variables 289 * This function takes a bytestream and loads the data into the registered variables 290 * @param mem pointer to the bytestream 291 * @param mode same as in getData 221 292 * @return true/false 222 293 */ 223 bool Synchronisable::updateData(unsigned char*& mem, int mode){ 224 unsigned char *data = mem; 294 bool Synchronisable::updateData(uint8_t*& mem, int mode){ 225 295 if(mode==0x0) 226 296 mode=state_; … … 231 301 } 232 302 303 uint8_t *data=mem; 233 304 // start extract header 234 unsigned int objectID, classID, size; 235 size = *(int *)mem; 236 mem+=sizeof(size); 237 objectID = *(int *)mem; 238 mem+=sizeof(objectID); 239 classID = *(int *)mem; 240 mem+=sizeof(classID); 305 synchronisableHeader *syncHeader = (synchronisableHeader *)mem; 306 assert(syncHeader->objectID==this->objectID); 307 if(syncHeader->dataAvailable==false){ 308 mem+=syncHeader->size; 309 return true; 310 } 311 312 mem+=sizeof(synchronisableHeader); 241 313 // stop extract header 242 assert(this->objectID==objectID); 243 assert(this->classID==classID); 244 if(size==3*sizeof(unsigned int)) //if true, only the header is available 245 return true; 246 //assert(0); 247 248 COUT(5) << "Synchronisable: objectID " << objectID << ", classID " << classID << " size: " << size << " synchronising data" << std::endl; 249 for(i=syncList->begin(); i!=syncList->end() && mem <= data+size; i++){ 314 assert(this->objectID==syncHeader->objectID); 315 // assert(this->classID==syncHeader->classID); //TODO: fix this!!! maybe a problem with the identifier ? 316 317 COUT(5) << "Synchronisable: objectID " << syncHeader->objectID << ", classID " << syncHeader->classID << " size: " << syncHeader->size << " synchronising data" << std::endl; 318 for(i=syncList->begin(); i!=syncList->end() && mem <= data+syncHeader->size; i++){ 250 319 if( ((*i)->mode ^ mode) == 0 ){ 251 320 COUT(5) << "synchronisable: not updating variable " << std::endl; … … 263 332 break; 264 333 case STRING: 265 (*i)->size = *( int *)mem;334 (*i)->size = *(uint32_t *)mem; 266 335 COUT(5) << "string size: " << (*i)->size << std::endl; 267 336 mem+=sizeof(int); … … 283 352 /** 284 353 * This function returns the total amount of bytes needed by getData to save the whole content of the variables 354 * @param id id of the gamestate 355 * @param mode same as getData 285 356 * @return amount of bytes 286 357 */ 287 int Synchronisable::getSize(unsigned int id, int mode){358 uint32_t Synchronisable::getSize(unsigned int id, int mode){ 288 359 if(!isMyTick(id)) 289 360 return 0; 290 int tsize= 0;361 int tsize=sizeof(synchronisableHeader); 291 362 if(mode==0x0) 292 363 mode=state_; … … 311 382 312 383 /** 313 * This function returns the total amount of bytes needed by getData to save the whole content of the variables 314 * @return amount of bytes 315 */ 316 int Synchronisable::getSize2(unsigned int id, int mode){ 317 return sizeof(synchronisableHeader) + getSize( id, mode ); 318 } 319 320 /** 321 * 322 * @param id 323 * @return 384 * This function determines, wheter the object should be saved to the bytestream (according to its syncmode/direction) 385 * @param id gamestate id 386 * @return true/false 324 387 */ 325 388 bool Synchronisable::isMyTick(unsigned int id){ 326 // return true; 389 return ( (objectMode_&state_)!=0 ); 390 } 391 392 bool Synchronisable::doSelection(unsigned int id){ 327 393 return ( id==0 || id%objectFrequency_==objectID%objectFrequency_ ) && ((objectMode_&state_)!=0); 328 394 } 329 395 330 bool Synchronisable::isMyData(unsigned char* mem) 396 /** 397 * This function looks at the header located in the bytestream and checks wheter objectID and classID match with the Synchronisables ones 398 * @param mem pointer to the bytestream 399 */ 400 bool Synchronisable::isMyData(uint8_t* mem) 331 401 { 332 unsigned int objectID, classID, size;333 size = *(int *)mem;334 mem+=sizeof(size);335 objectID = *(int *)mem;336 mem+=sizeof(objectID); 337 classID = *(int *)mem;338 mem+=sizeof(classID);339 340 assert(classID == this->classID);341 return (objectID == this->objectID);342 }343 402 synchronisableHeader *header = (synchronisableHeader *)mem; 403 assert(header->objectID==this->objectID); 404 return header->dataAvailable; 405 } 406 407 /** 408 * This function sets the synchronisation mode of the object 409 * If set to 0x1 variables will only be synchronised to the client 410 * If set to 0x2 variables will only be synchronised to the server 411 * If set to 0x3 variables will be synchronised bidirectionally (only if set so in registerVar) 412 * @param mode same as in registerVar 413 */ 344 414 void Synchronisable::setObjectMode(int mode){ 345 415 assert(mode==0x1 || mode==0x2 || mode==0x3); -
code/trunk/src/network/Synchronisable.h
r1841 r1907 33 33 34 34 #include <list> 35 #include <map> 36 #include <queue> 35 37 #include "core/OrxonoxClass.h" 36 38 #include "core/XMLIncludes.h" 37 39 #include "NetworkCallback.h" 38 40 41 #define REGISTERDATA(varname) registerVar(&varname, sizeof(varname), network::DATA) 42 #define REGISTERDATA_WITHDIR(varname, mode) registerVar(&varname, sizeof(varname), network::DATA, mode) 43 #define REGISTERSTRING(stringname) registerVar(&stringname, stringname.length()+1, network::STRING) 44 #define REGISTERSTRING_WITHDIR(stringname, mode) registerVar(&stringname, stringname.length()+1, network::STRING, mode) 45 46 //TODO: this is only a very ugly hack ... 47 namespace orxonox{ 48 class SpaceShip; 49 } 50 39 51 namespace network 40 52 { 53 namespace direction{ 54 enum syncdirection{ 55 toclient=0x1, 56 toserver=0x2, 57 bidirectional=0x3 58 }; 59 } 60 61 namespace syncmode{ 62 enum mode{ 63 one=0, 64 always=1 65 }; 66 } 67 41 68 enum variableType{ 42 69 DATA, … … 45 72 46 73 struct synchronisableHeader{ 47 unsigned int size; 48 unsigned int objectID; 49 unsigned int classID; 74 uint32_t size:31; 75 bool dataAvailable:1; 76 uint32_t objectID; 77 uint32_t classID; 50 78 }; 51 79 … … 58 86 }SYNCVAR; 59 87 60 61 88 /** 62 89 * This class is the base class of all the Objects in the universe that need to be synchronised over the network 63 * Every class, t 64 int mode;hat inherits from this class has to link the DATA THAT NEEDS TO BE SYNCHRONISED into the linked list. Additionally it also has to provide a Constructor, that takes exactly the variables in this linked list. 90 * Every class, that inherits from this class has to link the DATA THAT NEEDS TO BE SYNCHRONISED into the linked list. 65 91 * @author Oliver Scheuss 66 92 */ 67 93 class _NetworkExport Synchronisable : virtual public orxonox::OrxonoxClass{ 68 94 public: 95 friend class packet::Gamestate; 96 friend class GamestateClient; 97 friend class Server; 98 friend class orxonox::SpaceShip; 99 virtual ~Synchronisable(); 100 69 101 70 virtual ~Synchronisable();71 unsigned int objectID;72 unsigned int classID;73 74 void registerVar(void *var, int size, variableType t, int mode=1, NetworkCallbackBase *cb=0);75 bool getData(unsigned char*& men, unsigned int id, int mode=0x0);76 int getSize2(unsigned int id, int mode=0x0);77 bool updateData(unsigned char*& mem, int mode=0x0);78 bool isMyData(unsigned char* mem);79 void setObjectMode(int mode);80 void setObjectFrequency(unsigned int freq){ objectFrequency_ = freq; }81 82 virtual void registerAllVariables()=0;83 102 virtual bool create(); 84 103 static void setClient(bool b); 85 104 86 static bool fabricate(unsigned char*& mem, int mode=0x0); 105 static Synchronisable *fabricate(uint8_t*& mem, int mode=0x0); 106 static bool deleteObject(unsigned int objectID); 107 static Synchronisable *getSynchronisable(unsigned int objectID); 108 static unsigned int getNumberOfDeletedObject(){ return deletedObjects_.size(); } 109 static unsigned int popDeletedObject(){ unsigned int i = deletedObjects_.front(); deletedObjects_.pop(); return i; } 110 111 inline unsigned int getObjectID(){return objectID;} 112 inline unsigned int getClassID(){return classID;} 87 113 protected: 88 114 Synchronisable(); 115 void registerVar(void *var, int size, variableType t, int mode=1, NetworkCallbackBase *cb=0); 116 void setObjectMode(int mode); 117 void setObjectFrequency(unsigned int freq){ objectFrequency_ = freq; } 118 virtual void registerAllVariables()=0; 119 120 89 121 private: 90 int getSize(unsigned int id, int mode=0x0); 122 bool getData(uint8_t*& men, unsigned int id, int mode=0x0); 123 uint32_t getSize(unsigned int id, int mode=0x0); 124 bool updateData(uint8_t*& mem, int mode=0x0); 125 bool isMyData(uint8_t* mem); 126 bool doSelection(unsigned int id); 91 127 bool isMyTick(unsigned int id); 128 129 unsigned int objectID; 130 unsigned int classID; 131 92 132 std::list<synchronisableVariable *> *syncList; 93 int datasize;94 133 static int state_; // detemines wheter we are server (default) or client 95 134 bool backsync_; // if true the variables with mode > 1 will be synchronised to server (client -> server) 96 135 unsigned int objectFrequency_; 97 136 int objectMode_; 137 static std::map<unsigned int, Synchronisable *> objectMap_; 138 static std::queue<unsigned int> deletedObjects_; 98 139 }; 99 140 } -
code/trunk/src/network/packet/Acknowledgement.cc
r1769 r1907 40 40 #define _ACKID _PACKETID + sizeof(network::packet::ENUM::Type) 41 41 42 Acknowledgement::Acknowledgement( unsigned int id, int clientID )42 Acknowledgement::Acknowledgement( unsigned int id, unsigned int clientID ) 43 43 : Packet() 44 44 { 45 45 flags_ = flags_ | PACKET_FLAGS_ACK; 46 data_=new u nsigned char[ getSize() ];46 data_=new uint8_t[ getSize() ]; 47 47 *(ENUM::Type *)(data_ + _PACKETID ) = ENUM::Acknowledgement; 48 *(u nsigned int *)(data_ + _ACKID ) = id;48 *(uint32_t *)(data_ + _ACKID ) = id; 49 49 clientID_=clientID; 50 50 } 51 51 52 Acknowledgement::Acknowledgement( u nsigned char *data,int clientID )52 Acknowledgement::Acknowledgement( uint8_t *data, unsigned int clientID ) 53 53 : Packet(data, clientID) 54 54 { … … 60 60 61 61 unsigned int Acknowledgement::getSize() const{ 62 return _ACKID + sizeof(u nsigned int);62 return _ACKID + sizeof(uint32_t); 63 63 } 64 64 … … 70 70 71 71 unsigned int Acknowledgement::getAckID(){ 72 return *(u nsigned int *)(data_ + _ACKID);72 return *(uint32_t *)(data_ + _ACKID); 73 73 } 74 74 -
code/trunk/src/network/packet/Acknowledgement.h
r1763 r1907 40 40 { 41 41 public: 42 Acknowledgement( unsigned int id, int clientID );43 Acknowledgement( u nsigned char* data,int clientID );42 Acknowledgement( unsigned int id, unsigned int clientID ); 43 Acknowledgement( uint8_t* data, unsigned int clientID ); 44 44 ~Acknowledgement(); 45 45 -
code/trunk/src/network/packet/Chat.cc
r1763 r1907 29 29 #include "Chat.h" 30 30 #include <assert.h> 31 #include "network/Host.h" 31 32 32 33 namespace network { 33 34 namespace packet { 34 35 35 #define PACKET_FLAGS_CHAT ENET_PACKET_FLAG_RELIABLE 36 #define _PACKETID 0 37 #define _MESSAGELENGTH _PACKETID + sizeof(ENUM::Type) 38 #define _MESSAGE _MESSAGELENGTH + sizeof(unsigned int) 36 #define PACKET_FLAGS_CHAT ENET_PACKET_FLAG_RELIABLE 37 #define _PACKETID 0 38 const int _PLAYERID = _PACKETID + sizeof(ENUM::Type); 39 #define _MESSAGELENGTH _PLAYERID + sizeof(uint32_t) 40 #define _MESSAGE _MESSAGELENGTH + sizeof(uint32_t) 39 41 40 Chat::Chat( std::string & message, int clientID )42 Chat::Chat( std::string message, unsigned int playerID ) 41 43 : Packet() 42 44 { … … 44 46 messageLength_ = message.length()+1; 45 47 data_=new unsigned char[ getSize() ]; 46 *(ENUM::Type *) &data_[ _PACKETID ]= ENUM::Chat;47 *(unsigned int *) &data_[ _MESSAGELENGTH ] = messageLength_;48 memcpy( &data_[ _MESSAGE ], (void *)message.c_str(), messageLength_ );49 clientID_=clientID;48 *(ENUM::Type *)(data_ + _PACKETID ) = ENUM::Chat; 49 *(unsigned int *)(data_ + _PLAYERID ) = playerID; 50 *(unsigned int *)(data_ + _MESSAGELENGTH ) = messageLength_; 51 memcpy( data_+_MESSAGE, (void *)message.c_str(), messageLength_ ); 50 52 } 51 53 52 Chat::Chat( u nsigned char *data,int clientID )54 Chat::Chat( uint8_t* data, unsigned int clientID ) 53 55 : Packet(data, clientID) 54 56 { 55 messageLength_ = *(u nsigned int *)&data[ _MESSAGELENGTH ];57 messageLength_ = *(uint32_t *)(data + _MESSAGELENGTH ); 56 58 } 57 59 … … 65 67 66 68 bool Chat::process(){ 67 //TODO: change this !!! 68 assert(0); 69 bool b = Host::incomingChat(std::string((const char*)data_+_MESSAGE), *(uint32_t *)(data_+_PLAYERID)); 69 70 delete this; 70 return true;71 return b; 71 72 } 72 73 73 74 unsigned char *Chat::getMessage(){ 74 return &data_[ _MESSAGE ];75 return data_ + _MESSAGE; 75 76 } 76 77 -
code/trunk/src/network/packet/Chat.h
r1837 r1907 16 16 { 17 17 public: 18 Chat( std::string & message, int clientID );19 Chat( u nsigned char* data,int clientID );18 Chat( std::string message, unsigned int playerID ); 19 Chat( uint8_t* data, unsigned int clientID ); 20 20 ~Chat(); 21 21 … … 26 26 unsigned char *getMessage(); 27 27 private: 28 u nsigned int messageLength_;29 int clientID_;28 uint32_t messageLength_; 29 unsigned int clientID_; 30 30 }; 31 31 -
code/trunk/src/network/packet/ClassID.cc
r1856 r1907 40 40 #define _PACKETID 0 41 41 #define _CLASSID _PACKETID + sizeof(ENUM::Type) 42 #define _CLASSNAMELENGTH _CLASSID + sizeof(u nsigned int)42 #define _CLASSNAMELENGTH _CLASSID + sizeof(uint32_t) 43 43 #define _CLASSNAME _CLASSNAMELENGTH + sizeof(classNameLength_) 44 44 … … 57 57 } 58 58 59 ClassID::ClassID( u nsigned char *data,int clientID )59 ClassID::ClassID( uint8_t* data, unsigned int clientID ) 60 60 : Packet(data, clientID) 61 61 { … … 68 68 69 69 unsigned int ClassID::getSize() const{ 70 return sizeof(network::packet::ENUM::Type) + 2*sizeof(u nsigned int) + classNameLength_;70 return sizeof(network::packet::ENUM::Type) + 2*sizeof(uint32_t) + classNameLength_; 71 71 } 72 72 … … 82 82 83 83 unsigned int ClassID::getClassID(){ 84 return *(u nsigned int *)&data_[ _CLASSID ];84 return *(uint32_t *)(data_ + _CLASSID); 85 85 } 86 86 -
code/trunk/src/network/packet/ClassID.h
r1763 r1907 43 43 public: 44 44 ClassID( unsigned int classID, std::string className ); 45 ClassID( u nsigned char* data,int clientID );45 ClassID( uint8_t* data, unsigned int clientID ); 46 46 ~ClassID(); 47 47 … … 53 53 unsigned char *getClassName(); 54 54 private: 55 u nsigned int classNameLength_;55 uint32_t classNameLength_; 56 56 }; 57 57 -
code/trunk/src/network/packet/Gamestate.cc
r1767 r1907 46 46 #define HEADER GAMESTATE_HEADER(data_) 47 47 48 49 #define PACKET_FLAG_GAMESTATE ENET_PACKET_FLAG_RELIABLE 50 48 51 Gamestate::Gamestate() 49 52 { 50 } 51 52 Gamestate::Gamestate(unsigned char *data, int clientID): 53 flags_ = flags_ | PACKET_FLAG_GAMESTATE; 54 } 55 56 Gamestate::Gamestate(uint8_t *data, unsigned int clientID): 53 57 Packet(data, clientID) 54 58 { 59 flags_ = flags_ | PACKET_FLAG_GAMESTATE; 60 } 61 62 Gamestate::Gamestate(uint8_t *data) 63 { 64 flags_ = flags_ | PACKET_FLAG_GAMESTATE; 65 data_=data; 55 66 } 56 67 … … 74 85 return false; 75 86 } 76 87 88 #ifndef NDEBUG 89 std::list<Synchronisable*> slist; 90 std::list<Synchronisable*>::iterator iit; 91 #endif 77 92 //start collect data synchronisable by synchronisable 78 u nsigned char*mem=data_;93 uint8_t *mem=data_; 79 94 mem+=sizeof(GamestateHeader); 80 95 orxonox::ObjectList<Synchronisable>::iterator it; 81 96 for(it = orxonox::ObjectList<Synchronisable>::begin(); it; ++it){ 82 tempsize=it->getSize 2(id, mode);97 tempsize=it->getSize(id, mode); 83 98 84 99 if(currentsize+tempsize > size){ … … 88 103 int addsize=tempsize; 89 104 while(++temp) 90 addsize+=temp->getSize 2(id, mode);91 data_ = (u nsigned char*)realloc(data_, sizeof(GamestateHeader) + currentsize + addsize);105 addsize+=temp->getSize(id, mode); 106 data_ = (uint8_t *)realloc(data_, sizeof(GamestateHeader) + currentsize + addsize); 92 107 if(!data_) 93 108 return false; … … 95 110 }// stop allocate additional memory 96 111 112 #ifndef NDEBUG 113 for(iit=slist.begin(); iit!=slist.end(); iit++) 114 assert((*iit)!=*it); 115 slist.push_back(*it); 116 #endif 117 118 //if(it->doSelection(id)) 119 dataMap_[mem-data_]=(*it); // save the mem location of the synchronisable data 97 120 if(!it->getData(mem, id, mode)) 98 121 return false; // mem pointer gets automatically increased because of call by reference … … 105 128 HEADER->packetType = ENUM::Gamestate; 106 129 assert( *(ENUM::Type *)(data_) == ENUM::Gamestate); 107 HEADER-> normsize = currentsize;130 HEADER->datasize = currentsize; 108 131 HEADER->id = id; 109 132 HEADER->diffed = false; … … 122 145 assert(!HEADER->compressed); 123 146 assert(!HEADER->diffed); 124 unsigned int size, objectID, classID; 125 unsigned char *mem=data_+sizeof(GamestateHeader); 147 uint8_t *mem=data_+sizeof(GamestateHeader); 126 148 // get the start of the Synchronisable list 127 orxonox::ObjectList<Synchronisable>::iterator it=orxonox::ObjectList<Synchronisable>::begin(); 128 129 while(mem < data_+sizeof(GamestateHeader)+HEADER->normsize){ 130 // extract synchronisable header 131 size = *(unsigned int *)mem; 132 objectID = *(unsigned int*)(mem+sizeof(unsigned int)); 133 classID = *(unsigned int*)(mem+2*sizeof(unsigned int)); 134 135 if(!it || it->objectID!=objectID || it->classID!=classID){ 136 // bad luck ;) 137 // delete the synchronisable (obviously seems to be deleted on the server) 138 while(it && it->objectID!=objectID) 139 removeObject(it); 140 141 if(!it){ 142 //fabricate the new synchronisable 143 if(!Synchronisable::fabricate(mem, mode)) 144 return false; 145 it=orxonox::ObjectList<Synchronisable>::end(); 146 }else{ 147 if(! it->updateData(mem, mode)) 148 { 149 COUT(1) << "We couldn't update objectID: " \ 150 << objectID << "; classID: " << classID << std::endl; 151 } 152 } 153 } else 149 //orxonox::ObjectList<Synchronisable>::iterator it=orxonox::ObjectList<Synchronisable>::begin(); 150 Synchronisable *s; 151 152 // update the data of the objects we received 153 while(mem < data_+sizeof(GamestateHeader)+HEADER->datasize){ 154 synchronisableHeader *objectheader = (synchronisableHeader*)mem; 155 156 s = Synchronisable::getSynchronisable( objectheader->objectID ); 157 if(!s) 154 158 { 155 // we have our object 156 if(! it->updateData(mem, mode)) 157 { 158 COUT(1) << "We couldn't update objectID: " \ 159 << objectID << "; classID: " << classID << std::endl; 160 } 161 } 162 ++it; 159 s = Synchronisable::fabricate(mem, mode); 160 assert(s); 161 // if(!s) 162 // return false; 163 } 164 else 165 { 166 bool b = s->updateData(mem, mode); 167 assert(b); 168 //if(!s->updateData(mem, mode)) 169 //return false; 170 } 163 171 } 164 172 165 173 return true; 166 174 } 175 176 167 177 168 178 int Gamestate::getID(){ … … 177 187 else 178 188 { 179 return HEADER-> normsize+sizeof(GamestateHeader);189 return HEADER->datasize+sizeof(GamestateHeader); 180 190 } 181 191 } 182 192 183 193 bool Gamestate::operator==(packet::Gamestate gs){ 184 u nsigned char*d1 = data_+sizeof(GamestateHeader);185 u nsigned char*d2 = gs.data_+sizeof(GamestateHeader);194 uint8_t *d1 = data_+sizeof(GamestateHeader); 195 uint8_t *d2 = gs.data_+sizeof(GamestateHeader); 186 196 assert(!isCompressed()); 187 197 assert(!gs.isCompressed()); 188 while(d1<data_+HEADER-> normsize)198 while(d1<data_+HEADER->datasize) 189 199 { 190 200 if(*d1!=*d2) … … 201 211 } 202 212 213 214 203 215 bool Gamestate::compressData() 204 216 { 205 217 assert(HEADER); 206 218 assert(!HEADER->compressed); 207 uLongf buffer = (uLongf)(((HEADER-> normsize + 12)*1.01)+1);219 uLongf buffer = (uLongf)(((HEADER->datasize + 12)*1.01)+1); 208 220 if(buffer==0) 209 221 return false; 210 222 211 u nsigned char *ndata = new unsigned char[buffer+sizeof(GamestateHeader)];212 u nsigned char*dest = GAMESTATE_START(ndata);223 uint8_t *ndata = new uint8_t[buffer+sizeof(GamestateHeader)]; 224 uint8_t *dest = GAMESTATE_START(ndata); 213 225 //unsigned char *dest = new unsigned char[buffer]; 214 u nsigned char*source = GAMESTATE_START(data_);226 uint8_t *source = GAMESTATE_START(data_); 215 227 int retval; 216 retval = compress( dest, &buffer, source, (uLong)(HEADER-> normsize) );228 retval = compress( dest, &buffer, source, (uLong)(HEADER->datasize) ); 217 229 switch ( retval ) { 218 230 case Z_OK: COUT(5) << "G.St.Man: compress: successfully compressed" << std::endl; break; … … 223 235 #ifndef NDEBUG 224 236 //decompress and compare the start and the decompressed data 225 u nsigned char *rdata = new unsigned char[HEADER->normsize+sizeof(GamestateHeader)];226 u nsigned char*d2 = GAMESTATE_START(rdata);227 uLongf length2 = HEADER-> normsize;237 uint8_t *rdata = new uint8_t[HEADER->datasize+sizeof(GamestateHeader)]; 238 uint8_t *d2 = GAMESTATE_START(rdata); 239 uLongf length2 = HEADER->datasize; 228 240 uncompress(d2, &length2, dest, buffer); 229 for(unsigned int i=0; i<HEADER-> normsize; i++){241 for(unsigned int i=0; i<HEADER->datasize; i++){ 230 242 assert(*(source+i)==*(d2+i)); 231 243 } … … 235 247 //copy and modify header 236 248 #ifndef NDEBUG 237 HEADER->crc32 = calcCRC(data_+sizeof(GamestateHeader), HEADER-> normsize);249 HEADER->crc32 = calcCRC(data_+sizeof(GamestateHeader), HEADER->datasize); 238 250 #endif 239 251 *GAMESTATE_HEADER(ndata) = *HEADER; … … 245 257 HEADER->compressed = true; 246 258 assert(HEADER->compressed); 247 COUT(3) << "gamestate compress normsize: " << HEADER->normsize << " compsize: " << HEADER->compsize << std::endl;259 COUT(3) << "gamestate compress datasize: " << HEADER->datasize << " compsize: " << HEADER->compsize << std::endl; 248 260 return true; 249 261 } … … 252 264 assert(HEADER); 253 265 assert(HEADER->compressed); 254 COUT(3) << "GameStateClient: uncompressing gamestate. id: " << HEADER->id << ", baseid: " << HEADER->base_id << ", normsize: " << HEADER->normsize << ", compsize: " << HEADER->compsize << std::endl;255 unsigned int normsize = HEADER->normsize;266 COUT(3) << "GameStateClient: uncompressing gamestate. id: " << HEADER->id << ", baseid: " << HEADER->base_id << ", datasize: " << HEADER->datasize << ", compsize: " << HEADER->compsize << std::endl; 267 unsigned int datasize = HEADER->datasize; 256 268 unsigned int compsize = HEADER->compsize; 257 269 unsigned int bufsize; 258 assert(compsize<= normsize);259 bufsize = normsize;270 assert(compsize<=datasize); 271 bufsize = datasize; 260 272 assert(bufsize!=0); 261 u nsigned char *ndata = new unsigned char[bufsize + sizeof(GamestateHeader)];262 u nsigned char*dest = ndata + sizeof(GamestateHeader);263 u nsigned char*source = data_ + sizeof(GamestateHeader);273 uint8_t *ndata = new uint8_t[bufsize + sizeof(GamestateHeader)]; 274 uint8_t *dest = ndata + sizeof(GamestateHeader); 275 uint8_t *source = data_ + sizeof(GamestateHeader); 264 276 int retval; 265 277 uLongf length=bufsize; … … 272 284 } 273 285 #ifndef NDEBUG 274 assert(HEADER->crc32==calcCRC(ndata+sizeof(GamestateHeader), HEADER-> normsize));286 assert(HEADER->crc32==calcCRC(ndata+sizeof(GamestateHeader), HEADER->datasize)); 275 287 #endif 276 288 … … 282 294 data_ = ndata; 283 295 HEADER->compressed = false; 284 assert(HEADER-> normsize==normsize);296 assert(HEADER->datasize==datasize); 285 297 assert(HEADER->compsize==compsize); 286 298 return true; … … 293 305 assert(!HEADER->diffed); 294 306 //unsigned char *basep = base->getGs()/*, *gs = getGs()*/; 295 u nsigned char*basep = GAMESTATE_START(base->data_), *gs = GAMESTATE_START(this->data_);307 uint8_t *basep = GAMESTATE_START(base->data_), *gs = GAMESTATE_START(this->data_); 296 308 unsigned int of=0; // pointers offset 297 309 unsigned int dest_length=0; 298 dest_length=HEADER-> normsize;310 dest_length=HEADER->datasize; 299 311 if(dest_length==0) 300 312 return NULL; 301 u nsigned char *ndata = new unsigned char[dest_length*sizeof(unsigned char)+sizeof(GamestateHeader)];302 u nsigned char*dest = ndata + sizeof(GamestateHeader);303 while(of < GAMESTATE_HEADER(base->data_)-> normsize && of < HEADER->normsize){313 uint8_t *ndata = new uint8_t[dest_length*sizeof(uint8_t)+sizeof(GamestateHeader)]; 314 uint8_t *dest = ndata + sizeof(GamestateHeader); 315 while(of < GAMESTATE_HEADER(base->data_)->datasize && of < HEADER->datasize){ 304 316 *(dest+of)=*(basep+of)^*(gs+of); // do the xor 305 317 ++of; 306 318 } 307 if(GAMESTATE_HEADER(base->data_)-> normsize!=HEADER->normsize){308 u nsigned charn=0;309 if(GAMESTATE_HEADER(base->data_)-> normsize < HEADER->normsize){319 if(GAMESTATE_HEADER(base->data_)->datasize!=HEADER->datasize){ 320 uint8_t n=0; 321 if(GAMESTATE_HEADER(base->data_)->datasize < HEADER->datasize){ 310 322 while(of<dest_length){ 311 323 *(dest+of)=n^*(gs+of); … … 324 336 } 325 337 338 Gamestate* Gamestate::doSelection(unsigned int clientID){ 339 assert(data_); 340 std::map<unsigned int, Synchronisable *>::iterator it; 341 342 // allocate memory for new data 343 uint8_t *gdata = new uint8_t[HEADER->datasize+sizeof(GamestateHeader)]; 344 // create a gamestate out of it 345 Gamestate *gs = new Gamestate(gdata); 346 uint8_t *newdata = gdata + sizeof(GamestateHeader); 347 uint8_t *origdata = GAMESTATE_START(data_); 348 349 //copy the GamestateHeader 350 *(GamestateHeader*)gdata = *HEADER; 351 352 synchronisableHeader *oldobjectheader, *newobjectheader; 353 unsigned int objectOffset; 354 355 //copy in the zeros 356 for(it=dataMap_.begin(); it!=dataMap_.end(); it++){ 357 oldobjectheader = (synchronisableHeader*)origdata; 358 newobjectheader = (synchronisableHeader*)newdata; 359 unsigned int objectsize = oldobjectheader->size; 360 assert(it->second->objectID==oldobjectheader->objectID); 361 *newobjectheader = *oldobjectheader; 362 objectOffset=sizeof(uint8_t)+sizeof(bool); //skip the size and the availableDate variables in the objectheader 363 if(it->second->doSelection(HEADER->id)){ 364 newobjectheader->dataAvailable=true; //TODO: probably not neccessary 365 while(objectOffset<objectsize){ 366 *(newdata + objectOffset)=*(origdata + objectOffset); // copy the data 367 objectOffset++; 368 } 369 }else{ 370 newobjectheader->dataAvailable=false; 371 while(objectOffset<objectsize){ 372 *(newdata+objectOffset)=0; // set to 0 373 objectOffset++; 374 } 375 assert(objectOffset==objectsize); 376 } 377 newdata += objectsize; 378 origdata += objectsize; 379 } 380 return gs; 381 } 382 383 384 Gamestate* Gamestate::intelligentDiff(Gamestate *base, unsigned int clientID){ 385 // asserts 386 assert(data_); 387 assert(base->data_); 388 assert(!GAMESTATE_HEADER(base->data_)->diffed); 389 assert(!GAMESTATE_HEADER(base->data_)->compressed); 390 assert(!HEADER->compressed); 391 assert(!HEADER->diffed); 392 393 //preparations 394 std::map<unsigned int, Synchronisable *>::iterator it; 395 uint8_t *origdata, *basedata, *destdata, *ndata; 396 unsigned int objectOffset, streamOffset=0; //data offset 397 unsigned int minsize = (HEADER->datasize < GAMESTATE_HEADER(base->data_)->datasize) ? HEADER->datasize : GAMESTATE_HEADER(base->data_)->datasize; 398 synchronisableHeader *origheader; 399 synchronisableHeader *destheader; 400 401 origdata = GAMESTATE_START(this->data_); 402 basedata = GAMESTATE_START(base->data_); 403 ndata = new uint8_t[HEADER->datasize + sizeof(GamestateHeader)]; 404 destdata = ndata + sizeof(GamestateHeader); 405 406 // do the diff 407 for(it=dataMap_.begin(); it!=dataMap_.end(); it++){ 408 assert(streamOffset<HEADER->datasize); 409 bool sendData = it->second->doSelection(HEADER->id); 410 origheader = (synchronisableHeader *)(origdata+streamOffset); 411 destheader = (synchronisableHeader *)(destdata+streamOffset); 412 413 //copy and partially diff the object header 414 assert(sizeof(synchronisableHeader)==3*sizeof(unsigned int)+sizeof(bool)); 415 *(uint32_t*)destdata = *(uint32_t*)origdata; //size (do not diff) 416 *(bool*)(destdata+sizeof(uint32_t)) = sendData; 417 if(sendData){ 418 *(uint32_t*)(destdata+sizeof(uint32_t)+sizeof(bool)) = *(uint32_t*)(basedata+sizeof(uint32_t)+sizeof(bool)) ^ *(uint32_t*)(origdata+sizeof(uint32_t)+sizeof(bool)); //objectid (diff it) 419 *(uint32_t*)(destdata+2*sizeof(uint32_t)+sizeof(bool)) = *(uint32_t*)(basedata+2*sizeof(uint32_t)+sizeof(bool)) ^ *(uint32_t*)(origdata+2*sizeof(uint32_t)+sizeof(bool)); //classid (diff it) 420 }else{ 421 *(uint32_t*)(destdata+sizeof(uint32_t)+sizeof(bool)) = 0; 422 *(uint32_t*)(destdata+2*sizeof(uint32_t)+sizeof(bool)) = 0; 423 } 424 objectOffset=sizeof(synchronisableHeader); 425 streamOffset+=sizeof(synchronisableHeader); 426 427 //now handle the object data or fill with zeros 428 while(objectOffset<origheader->size ){ 429 430 if(sendData && streamOffset<minsize) 431 *(destdata+objectOffset)=*(basedata+objectOffset)^*(origdata+objectOffset); // do the xor 432 else if(sendData) 433 *(destdata+objectOffset)=((uint8_t)0)^*(origdata+objectOffset); // xor with 0 (basestream is too short) 434 else 435 *(destdata+objectOffset)=0; // set to 0 because this object should not be transfered 436 437 objectOffset++; 438 streamOffset++; 439 } 440 destdata+=objectOffset; 441 origdata+=objectOffset; 442 basedata+=objectOffset; 443 } 444 445 //copy over the gamestate header and set the diffed flag 446 *(GamestateHeader *)ndata = *HEADER; //copy over the header 447 Gamestate *gs = new Gamestate(ndata); 448 GAMESTATE_HEADER(ndata)->diffed=true; 449 return gs; 450 } 451 452 Gamestate* Gamestate::intelligentUnDiff(Gamestate *base){ 453 // asserts 454 assert(data_); 455 assert(base->data_); 456 assert(!GAMESTATE_HEADER(base->data_)->diffed); 457 assert(!GAMESTATE_HEADER(base->data_)->compressed); 458 assert(!HEADER->compressed); 459 assert(HEADER->diffed); 460 461 //preparations 462 std::map<unsigned int, Synchronisable *>::iterator it; 463 uint8_t *origdata, *basedata, *destdata, *ndata; 464 unsigned int objectOffset, streamOffset=0; //data offset 465 unsigned int minsize = (HEADER->datasize < GAMESTATE_HEADER(base->data_)->datasize) ? HEADER->datasize : GAMESTATE_HEADER(base->data_)->datasize; 466 synchronisableHeader *origheader; 467 synchronisableHeader *destheader; 468 469 origdata = GAMESTATE_START(this->data_); 470 basedata = GAMESTATE_START(base->data_); 471 ndata = new uint8_t[HEADER->datasize + sizeof(GamestateHeader)]; 472 destdata = ndata + sizeof(GamestateHeader); 473 474 // do the undiff 475 for(it=dataMap_.begin(); it!=dataMap_.end(); it++){ 476 assert(streamOffset<HEADER->datasize); 477 origheader = (synchronisableHeader *)(origdata+streamOffset); 478 destheader = (synchronisableHeader *)(destdata+streamOffset); 479 bool sendData; 480 481 //copy and partially diff the object header 482 assert(sizeof(synchronisableHeader)==3*sizeof(unsigned int)+sizeof(bool)); 483 *(unsigned int*)destdata = *(unsigned int*)origdata; //size (do not diff) 484 *(bool*)(destdata+sizeof(unsigned int)) = *(bool*)(origdata+sizeof(unsigned int)); 485 sendData = *(bool*)(origdata+sizeof(unsigned int)); 486 if(sendData){ 487 *(unsigned int*)(destdata+sizeof(unsigned int)+sizeof(bool)) = *(unsigned int*)(basedata+sizeof(unsigned int)+sizeof(bool)) ^ *(unsigned int*)(origdata+sizeof(unsigned int)+sizeof(bool)); //objectid (diff it) 488 *(unsigned int*)(destdata+2*sizeof(unsigned int)+sizeof(bool)) = *(unsigned int*)(basedata+2*sizeof(unsigned int)+sizeof(bool)) ^ *(unsigned int*)(origdata+2*sizeof(unsigned int)+sizeof(bool)); //classid (diff it) 489 }else{ 490 *(unsigned int*)(destdata+sizeof(unsigned int)+sizeof(bool)) = 0; 491 *(unsigned int*)(destdata+2*sizeof(unsigned int)+sizeof(bool)) = 0; 492 } 493 objectOffset=sizeof(synchronisableHeader); 494 streamOffset+=sizeof(synchronisableHeader); 495 496 //now handle the object data or fill with zeros 497 while(objectOffset<origheader->size ){ 498 499 if(sendData && streamOffset<minsize) 500 *(destdata+objectOffset)=*(basedata+objectOffset)^*(origdata+objectOffset); // do the xor 501 else if(sendData) 502 *(destdata+objectOffset)=((unsigned char)0)^*(origdata+objectOffset); // xor with 0 (basestream is too short) 503 else 504 *(destdata+objectOffset)=0; // set to 0 because this object should not be transfered 505 506 objectOffset++; 507 streamOffset++; 508 } 509 destdata+=objectOffset; 510 origdata+=objectOffset; 511 basedata+=objectOffset; 512 } 513 514 //copy over the gamestate header and set the diffed flag 515 *(GamestateHeader *)ndata = *HEADER; //copy over the header 516 Gamestate *gs = new Gamestate(ndata); 517 GAMESTATE_HEADER(ndata)->diffed=false; 518 return gs; 519 } 520 326 521 Gamestate *Gamestate::undiff(Gamestate *base) 327 522 { … … 330 525 assert(!HEADER->compressed && !GAMESTATE_HEADER(base->data_)->compressed); 331 526 //unsigned char *basep = base->getGs()/*, *gs = getGs()*/; 332 u nsigned char*basep = GAMESTATE_START(base->data_);333 u nsigned char*gs = GAMESTATE_START(this->data_);527 uint8_t *basep = GAMESTATE_START(base->data_); 528 uint8_t *gs = GAMESTATE_START(this->data_); 334 529 unsigned int of=0; // pointers offset 335 530 unsigned int dest_length=0; 336 dest_length=HEADER-> normsize;531 dest_length=HEADER->datasize; 337 532 if(dest_length==0) 338 533 return NULL; 339 u nsigned char *ndata = new unsigned char[dest_length*sizeof(unsigned char)+sizeof(GamestateHeader)];340 u nsigned char*dest = ndata + sizeof(GamestateHeader);341 while(of < GAMESTATE_HEADER(base->data_)-> normsize && of < HEADER->normsize){534 uint8_t *ndata = new uint8_t[dest_length*sizeof(uint8_t)+sizeof(GamestateHeader)]; 535 uint8_t *dest = ndata + sizeof(GamestateHeader); 536 while(of < GAMESTATE_HEADER(base->data_)->datasize && of < HEADER->datasize){ 342 537 *(dest+of)=*(basep+of)^*(gs+of); // do the xor 343 538 ++of; 344 539 } 345 if(GAMESTATE_HEADER(base->data_)-> normsize!=HEADER->normsize){346 u nsigned charn=0;347 if(GAMESTATE_HEADER(base->data_)-> normsize < HEADER->normsize){540 if(GAMESTATE_HEADER(base->data_)->datasize!=HEADER->datasize){ 541 uint8_t n=0; 542 if(GAMESTATE_HEADER(base->data_)->datasize < HEADER->datasize){ 348 543 while(of < dest_length){ 349 544 *(dest+of)=n^*(gs+of); … … 370 565 // get total size of gamestate 371 566 for(it = orxonox::ObjectList<Synchronisable>::begin(); it; ++it) 372 size+=it->getSize 2(id, mode); // size of the actual data of the synchronisable567 size+=it->getSize(id, mode); // size of the actual data of the synchronisable 373 568 // size+=sizeof(GamestateHeader); 374 569 return size; -
code/trunk/src/network/packet/Gamestate.h
r1763 r1907 29 29 #include "Packet.h" 30 30 #include "network/Synchronisable.h" 31 #include <map> 31 32 #ifndef NDEBUG 32 33 #include "util/CRC32.h" 33 34 #endif 35 34 36 35 37 #ifndef NETWORK_PACKETGAMESTATE_H … … 42 44 struct GamestateHeader{ 43 45 ENUM::Type packetType; 44 int id; // id of the gamestate45 u nsigned int compsize;46 u nsigned int normsize;47 int base_id; // id of the base-gamestate diffed from48 bool diffed ; // wheter diffed or not49 bool complete ; // wheter it is a complete gamestate or only partial50 bool compressed ;46 int32_t id; // id of the gamestate 47 uint32_t compsize; 48 uint32_t datasize; 49 int32_t base_id; // id of the base-gamestate diffed from 50 bool diffed:1; // wheter diffed or not 51 bool complete:1; // wheter it is a complete gamestate or only partial 52 bool compressed:1; 51 53 #ifndef NDEBUG 52 54 uint32_t crc32; … … 55 57 56 58 /** 57 @author 59 @author Oliver Scheuss 58 60 */ 59 61 class Gamestate: public Packet{ 60 62 public: 61 63 Gamestate(); 62 Gamestate(unsigned char *data, int clientID); 64 Gamestate(uint8_t *data, unsigned int clientID); 65 Gamestate(uint8_t *data); 63 66 64 67 ~Gamestate(); … … 71 74 int getBaseID(); 72 75 Gamestate *diff(Gamestate *base); 76 Gamestate* intelligentDiff(Gamestate *base, unsigned int clientID); 73 77 Gamestate *undiff(Gamestate *base); 78 Gamestate* intelligentUnDiff(Gamestate *base); 79 Gamestate* doSelection(unsigned int clientID); 74 80 bool compressData(); 75 81 bool decompressData(); 76 82 77 83 // Packet functions 84 private: 78 85 virtual unsigned int getSize() const; 79 86 virtual bool process(); … … 83 90 unsigned int calcGamestateSize(unsigned int id, int mode=0x0); 84 91 void removeObject(orxonox::ObjectListIterator<Synchronisable> &it); 85 86 87 //Bytestream *bs_; 88 //GamestateHeader *header_; 92 std::map<unsigned int, Synchronisable*> dataMap_; 89 93 }; 90 94 -
code/trunk/src/network/packet/Packet.cc
r1763 r1907 42 42 #include "Gamestate.h" 43 43 #include "Welcome.h" 44 #include "DeleteObjects.h" 44 45 #include "network/Host.h" 45 46 #include "core/CoreIncludes.h" … … 66 67 } 67 68 68 Packet::Packet(u nsigned char *data,int clientID){69 Packet::Packet(uint8_t *data, unsigned int clientID){ 69 70 flags_ = PACKET_FLAG_DEFAULT; 70 71 packetDirection_ = ENUM::Incoming; … … 74 75 } 75 76 76 /*Packet::Packet(ENetPacket *packet, ENetPeer *peer){77 packetDirection_ = ENUM::Incoming;78 enetPacket_ = packet;79 clientID_ = ClientInformation::findClient(&peer->address)->getID();80 data_ = packet->data;81 }*/82 77 83 78 Packet::Packet(const Packet &p){ … … 87 82 clientID_ = p.clientID_; 88 83 if(p.data_){ 89 data_ = new u nsigned char[p.getSize()];84 data_ = new uint8_t[p.getSize()]; 90 85 memcpy(data_, p.data_, p.getSize()); 91 86 }else … … 125 120 case ENUM::Gamestate: 126 121 case ENUM::Welcome: 122 case ENUM::DeleteObjects: 127 123 break; 128 124 default: … … 138 134 139 135 Packet *Packet::createPacket(ENetPacket *packet, ENetPeer *peer){ 140 u nsigned char*data = packet->data;136 uint8_t *data = packet->data; 141 137 unsigned int clientID = ClientInformation::findClient(&peer->address)->getID(); 142 138 Packet *p; 143 COUT( 3) << "packet type: " << *(ENUM::Type *)&data[_PACKETID] << std::endl;139 COUT(5) << "packet type: " << *(ENUM::Type *)&data[_PACKETID] << std::endl; 144 140 switch( *(ENUM::Type *)(data + _PACKETID) ) 145 141 { 146 142 case ENUM::Acknowledgement: 147 COUT( 3) << "ack" << std::endl;143 COUT(4) << "ack" << std::endl; 148 144 p = new Acknowledgement( data, clientID ); 149 145 break; 150 146 case ENUM::Chat: 151 COUT( 3) << "chat" << std::endl;147 COUT(4) << "chat" << std::endl; 152 148 p = new Chat( data, clientID ); 153 149 break; 154 150 case ENUM::ClassID: 155 COUT( 3) << "classid" << std::endl;151 COUT(4) << "classid" << std::endl; 156 152 p = new ClassID( data, clientID ); 157 153 break; 158 154 case ENUM::Gamestate: 159 COUT( 3) << "gamestate" << std::endl;155 COUT(4) << "gamestate" << std::endl; 160 156 // TODO: remove brackets 161 157 p = new Gamestate( data, clientID ); 162 158 break; 163 159 case ENUM::Welcome: 164 COUT( 3) << "welcome" << std::endl;160 COUT(4) << "welcome" << std::endl; 165 161 p = new Welcome( data, clientID ); 162 break; 163 case ENUM::DeleteObjects: 164 COUT(4) << "deleteobjects" << std::endl; 165 p = new DeleteObjects( data, clientID ); 166 166 break; 167 167 default: -
code/trunk/src/network/packet/Packet.h
r1763 r1907 32 32 #include <enet/enet.h> 33 33 34 #include "util/Integers.h" 35 34 36 namespace network { 35 37 … … 47 49 ClassID, 48 50 Chat, 49 Welcome 51 Welcome, 52 DeleteObjects 50 53 }; 51 54 } … … 74 77 protected: 75 78 Packet(); 76 Packet(u nsigned char *data,int clientID);79 Packet(uint8_t *data, unsigned int clientID); 77 80 // Packet(ENetPacket *packet, ENetPeer *peer); 78 81 enet_uint32 flags_; 79 int clientID_;82 unsigned int clientID_; 80 83 ENUM::Direction packetDirection_; 81 u nsigned char*data_;84 uint8_t *data_; 82 85 private: 83 86 static std::map<ENetPacket *, Packet *> packetMap_; -
code/trunk/src/network/packet/Welcome.cc
r1763 r1907 42 42 #define _PACKETID 0 43 43 #define _CLIENTID _PACKETID + sizeof(ENUM::Type) 44 #define _SHIPID _CLIENTID + sizeof(u nsigned int)44 #define _SHIPID _CLIENTID + sizeof(uint32_t) 45 45 46 46 Welcome::Welcome( unsigned int clientID, unsigned int shipID ) … … 49 49 flags_ = flags_ | PACKET_FLAGS_CLASSID; 50 50 assert(getSize()); 51 data_=new u nsigned char[ getSize() ];51 data_=new uint8_t[ getSize() ]; 52 52 assert(data_); 53 53 *(packet::ENUM::Type *)(data_ + _PACKETID ) = packet::ENUM::Welcome; 54 *(u nsigned int *)&data_[ _CLIENTID ] = clientID;55 *(u nsigned int *)&data_[ _SHIPID ] = shipID;54 *(uint32_t *)&data_[ _CLIENTID ] = clientID; 55 *(uint32_t *)&data_[ _SHIPID ] = shipID; 56 56 } 57 57 58 Welcome::Welcome( u nsigned char *data,int clientID )58 Welcome::Welcome( uint8_t* data, unsigned int clientID ) 59 59 : Packet(data, clientID) 60 60 { … … 65 65 } 66 66 67 u nsigned char*Welcome::getData(){67 uint8_t *Welcome::getData(){ 68 68 return data_; 69 69 } 70 70 71 71 unsigned int Welcome::getSize() const{ 72 return sizeof(network::packet::ENUM::Type) + 2*sizeof(u nsigned int);72 return sizeof(network::packet::ENUM::Type) + 2*sizeof(uint32_t); 73 73 } 74 74 75 75 bool Welcome::process(){ 76 76 unsigned int shipID, clientID; 77 clientID = *(u nsigned int *)&data_[ _CLIENTID ];78 shipID = *(u nsigned int *)&data_[ _SHIPID ];77 clientID = *(uint32_t *)&data_[ _CLIENTID ]; 78 shipID = *(uint32_t *)&data_[ _SHIPID ]; 79 79 Host::setClientID(clientID); 80 80 Host::setShipID(shipID); -
code/trunk/src/network/packet/Welcome.h
r1763 r1907 41 41 public: 42 42 Welcome( unsigned int clientID, unsigned int shipID ); 43 Welcome( u nsigned char* data,int clientID );43 Welcome( uint8_t* data, unsigned int clientID ); 44 44 virtual ~Welcome(); 45 45 46 u nsigned char*getData();46 uint8_t *getData(); 47 47 inline unsigned int getSize() const; 48 48 bool process(); -
code/trunk/src/orxonox/Settings.cc
r1755 r1907 51 51 : bShowsGraphics_(false) 52 52 , bHasServer_(false) 53 , bIsClient_(false) 53 54 { 54 55 RegisterRootObject(Settings); -
code/trunk/src/orxonox/Settings.h
r1784 r1907 52 52 friend class GSGraphics; 53 53 friend class GSServer; 54 friend class GSClient; 54 55 friend class GSDedicated; 55 56 … … 63 64 static bool showsGraphics() { assert(singletonRef_s); return singletonRef_s->bShowsGraphics_; } 64 65 static bool hasServer() { assert(singletonRef_s); return singletonRef_s->bHasServer_; } 66 static bool isClient() { assert(singletonRef_s); return singletonRef_s->bIsClient_; } 65 67 66 68 private: … … 68 70 static void setShowsGraphics(bool val) { assert(singletonRef_s); singletonRef_s->bShowsGraphics_ = val; } 69 71 static void setHasServer (bool val) { assert(singletonRef_s); singletonRef_s->bHasServer_ = val; } 72 static void setIsClient (bool val) { assert(singletonRef_s); singletonRef_s->bIsClient_ = val; } 70 73 71 74 Settings(); … … 81 84 bool bShowsGraphics_; //!< global variable that tells whether to show graphics 82 85 bool bHasServer_; //!< global variable that tells whether this is a server 86 bool bIsClient_; 83 87 84 88 std::string dataPath_; //!< Path to the game data -
code/trunk/src/orxonox/gamestates/GSClient.cc
r1755 r1907 33 33 #include "core/CommandLine.h" 34 34 #include "network/Client.h" 35 #include "Settings.h" 35 36 36 37 namespace orxonox … … 50 51 void GSClient::enter() 51 52 { 53 Settings::_getInstance().bIsClient_ = true; 54 52 55 GSLevel::enter(); 53 56 … … 77 80 78 81 GSLevel::leave(); 82 83 Settings::_getInstance().bIsClient_ = false; 79 84 } 80 85 -
code/trunk/src/orxonox/gamestates/GSServer.cc
r1755 r1907 83 83 this->server_->close(); 84 84 delete this->server_; 85 Settings::_getInstance().bHasServer_ = false; 85 86 86 87 GSLevel::leave(); 87 88 Settings::_getInstance().bHasServer_ = false;89 88 } 90 89 -
code/trunk/src/orxonox/objects/Backlight.cc
r1755 r1907 53 53 this->traillength_ = 1; 54 54 55 this->getNode()->setInheritScale(false); 55 this->configure(maxspeed, brakingtime, scale); 56 } 57 58 bool Backlight::create(){ 59 if(!WorldEntity::create()) 60 return false; 61 62 this->getNode()->setInheritScale(false); 56 63 57 58 64 this->billboard_.setBillboardSet("Flares/backlightflare"); 65 this->attachObject(this->billboard_.getBillboardSet()); 59 66 60 61 62 63 67 this->ribbonTrail_ = GraphicsEngine::getInstance().getLevelSceneManager()->createRibbonTrail(this->getName() + "RibbonTrail"); 68 this->ribbonTrailNode_ = GraphicsEngine::getInstance().getLevelSceneManager()->getRootSceneNode()->createChildSceneNode(this->getName() + "RibbonTrailNode"); 69 this->ribbonTrailNode_->attachObject(this->ribbonTrail_); 70 this->ribbonTrail_->addNode(this->getNode()); 64 71 65 this->configure(maxspeed, brakingtime, scale);66 72 67 68 73 this->ribbonTrail_->setTrailLength(this->maxTraillength_); 74 this->ribbonTrail_->setMaterialName("Trail/backlighttrail"); 69 75 70 76 //this->setTimeFactor(Orxonox::getInstance().getTimeFactor()); 71 this->setTimeFactor(1.0f); 77 this->setTimeFactor(1.0f); 78 79 this->ribbonTrail_->setMaxChainElements(this->maxTrailsegments_); 80 this->ribbonTrail_->setTrailLength(this->traillength_ = 2 * this->maxTrailsegments_); 81 this->ribbonTrail_->setInitialWidth(0, this->width_ * this->getScale()); 82 this->ribbonTrail_->setWidthChange(0, this->width_ * this->getScale() / this->maxLifeTime_ * Backlight::timeFactor_s); 83 return true; 72 84 } 73 85 … … 100 112 { 101 113 this->ribbonTrail_->setColourChange(0, ColourValue(0, 0, 0, this->maxTraillength_ / this->traillength_ / this->maxLifeTime_ * Backlight::timeFactor_s)); 114 } 115 116 117 void Backlight::XMLPort(Element& xmlelement, XMLPort::Mode mode){ 118 SUPER(Backlight, XMLPort, xmlelement, mode); 119 120 Backlight::create(); 102 121 } 103 122 … … 136 155 this->maxTraillength_ = this->maxLifeTime_ * maxspeed; 137 156 this->maxTrailsegments_ = (size_t)(this->maxTraillength_ / this->trailSegmentLength_); 138 this->ribbonTrail_->setMaxChainElements(this->maxTrailsegments_);139 this->ribbonTrail_->setTrailLength(this->traillength_ = 2 * this->maxTrailsegments_);140 157 141 158 this->brakefactor_ = this->maxLifeTime_ / brakingtime; 142 159 143 160 this->scale(scale); 144 this->ribbonTrail_->setInitialWidth(0, this->width_ * scale);145 this->ribbonTrail_->setWidthChange(0, this->width_ * scale / this->maxLifeTime_ * Backlight::timeFactor_s);146 161 } 147 162 -
code/trunk/src/orxonox/objects/Backlight.h
r1608 r1907 45 45 46 46 void setConfigValues(); 47 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 47 48 virtual void tick(float dt); 48 49 virtual void changedVisibility(); 50 virtual bool create(); 49 51 50 52 void setColour(const ColourValue& colour); -
code/trunk/src/orxonox/objects/BillboardProjectile.cc
r1747 r1907 42 42 RegisterObject(BillboardProjectile); 43 43 44 if (this->owner_) 45 { 46 this->billboard_.setBillboardSet("Examples/Flare", ColourValue(1.0, 1.0, 0.5), 1); 47 this->attachObject(this->billboard_.getBillboardSet()); 48 this->scale(0.5); 49 } 44 this->billboard_.setBillboardSet("Examples/Flare", ColourValue(1.0, 1.0, 0.5), 1); 45 this->attachObject(this->billboard_.getBillboardSet()); 46 this->scale(0.5); 50 47 } 51 48 -
code/trunk/src/orxonox/objects/Model.cc
r1789 r1907 46 46 47 47 /** 48 * 48 * @brief Constructor 49 49 */ 50 50 Model::Model() … … 54 54 } 55 55 56 /** 57 * @brief Destructor 58 */ 56 59 Model::~Model() 57 60 { … … 86 89 } 87 90 if(this->isExactlyA(Class(Model))) 88 setObjectFrequency(300); //sync all 10 seconds (this only applies to asteroids and other isExactlyA(Model) 91 setObjectFrequency(300); //sync all 10 seconds (this only applies to asteroids and other isExactlyA(Model)'s 89 92 return true; 90 93 } -
code/trunk/src/orxonox/objects/ParticleProjectile.cc
r1747 r1907 42 42 RegisterObject(ParticleProjectile); 43 43 44 this->particles_ = new ParticleInterface("Orxonox/shot2", LODParticle::normal); 45 this->particles_->addToSceneNode(this->getNode()); 46 this->particles_->setKeepParticlesInLocalSpace(true); 44 47 if (this->owner_) 45 48 { 46 this->particles_ = new ParticleInterface("Orxonox/shot2", LODParticle::normal);47 this->particles_->addToSceneNode(this->getNode());48 this->particles_->getAllEmitters()->setDirection(-this->owner_->getInitialDir());49 this->particles_->setKeepParticlesInLocalSpace(true);50 49 } 51 else52 {53 this->particles_ = 0;54 }50 // else 51 // { 52 // this->particles_ = 0; 53 // } 55 54 56 55 this->setConfigValues(); … … 73 72 this->particles_->setEnabled(this->isVisible()); 74 73 } 74 75 bool ParticleProjectile::create(){ 76 if(!Projectile::create()) 77 return false; 78 this->particles_->getAllEmitters()->setDirection(-this->getOrientation()*Vector3(1,0,0)); 79 return true; 80 } 75 81 } -
code/trunk/src/orxonox/objects/ParticleProjectile.h
r1747 r1907 45 45 virtual void changedVisibility(); 46 46 void setConfigValues(); 47 48 virtual bool create(); 47 49 48 50 private: -
code/trunk/src/orxonox/objects/Projectile.cc
r1824 r1907 41 41 #include "ParticleSpawner.h" 42 42 #include "Model.h" 43 #include "Settings.h" 43 44 44 45 namespace orxonox … … 56 57 this->setStatic(false); 57 58 this->translate(Vector3(55, 0, 0), Ogre::Node::TS_LOCAL); 58 59 59 60 if (this->owner_) 60 61 { 62 this->setOrientation(this->owner_->getOrientation()); 61 63 this->setPosition(this->owner_->getPosition()); 62 this->setOrientation(this->owner_->getOrientation());63 64 this->setVelocity(this->owner_->getInitialDir() * this->speed_); 64 65 } 65 66 66 this->destroyTimer_.setTimer(this->lifetime_, false, this, createExecutor(createFunctor(&Projectile::destroyObject))); 67 if(!orxonox::Settings::isClient()) //only if not on client 68 this->destroyTimer_.setTimer(this->lifetime_, false, this, createExecutor(createFunctor(&Projectile::destroyObject))); 67 69 } 68 70 … … 122 124 delete this; 123 125 } 126 127 bool Projectile::create(){ 128 return WorldEntity::create(); 129 } 124 130 } -
code/trunk/src/orxonox/objects/Projectile.h
r1747 r1907 45 45 void destroyObject(); 46 46 virtual void tick(float dt); 47 48 virtual bool create(); 47 49 48 50 static float getSpeed() -
code/trunk/src/orxonox/objects/SpaceShip.cc
r1789 r1907 78 78 for(it = ObjectList<SpaceShip>::begin(); it; ++it){ 79 79 assert(it->isA(Class(SpaceShip))); 80 if( (it)->myShip_ || (network::Host::running() && network::Host::getShipID()==(it)-> objectID) ){80 if( (it)->myShip_ || (network::Host::running() && network::Host::getShipID()==(it)->getObjectID()) ){ 81 81 // COUT(1) << "^^^^^^^^^^ myShip_:" << *it << " classname: " << (*it)->getIdentifier()->getName() << " objectid: " << (*it)->objectID << std::endl; 82 82 return *it; … … 173 173 if (!myShip_) 174 174 { 175 if (network::Host::running()) 176 //COUT(3) << "this id: " << this->objectID << " myShipID: " << network::Host::getShipID() << std::endl; 177 if (network::Host::running() && objectID == network::Host::getShipID()) 178 { 179 if (!network::Host::isServer()) 180 setObjectMode(0x3); 181 myShip_ = true; 182 } 183 } 184 else 185 this->setRadarObjectColour(this->getProjectileColour()); 186 assert(Model::create()); 187 this->init(); 188 return true; 175 if (network::Host::running() && getObjectID() == network::Host::getShipID()) 176 { 177 if (!network::Host::isServer()) 178 setObjectMode(0x3); 179 myShip_ = true; 180 } 181 else 182 this->setRadarObjectColour(this->getProjectileColour()); 183 } 184 Model::create(); 185 this->init(); 186 return true; 189 187 } 190 188 … … 258 256 259 257 // START CREATING ADDITIONAL EFFECTS 260 /*this->backlight_ = new Backlight(this->maxSpeed_, 0.8); 261 this->attachObject(this->backlight_); 262 this->backlight_->setPosition(-2.35, 0, 0.2); 263 this->backlight_->setColour(this->getProjectileColour()); 264 265 this->smoke_ = new ParticleSpawner(); 266 this->smoke_->setParticle("Orxonox/smoke5", LODParticle::normal, 0, 0, 3); 267 this->attachObject(this->smoke_); 268 269 this->fire_ = new ParticleSpawner(); 270 this->fire_->setParticle("Orxonox/fire3", LODParticle::normal, 0, 0, 1); 271 this->attachObject(this->fire_); 272 */ 258 if(!network::Host::running()){ 259 this->backlight_ = new Backlight(this->maxSpeed_, 0.8); 260 this->backlight_->create(); 261 this->attachObject(this->backlight_); 262 this->backlight_->setPosition(-2.35, 0, 0.2); 263 this->backlight_->setColour(this->getProjectileColour()); 264 265 this->smoke_ = new ParticleSpawner(); 266 this->smoke_->setParticle("Orxonox/smoke5", LODParticle::normal, 0, 0, 3); 267 this->attachObject(this->smoke_); 268 269 this->fire_ = new ParticleSpawner(); 270 this->fire_->setParticle("Orxonox/fire3", LODParticle::normal, 0, 0, 1); 271 this->attachObject(this->fire_); 272 } 273 273 274 // END CREATING ADDITIONAL EFFECTS 274 275 … … 374 375 //if(!network::Host::running() || network::Host::getShipID()==objectID){ //TODO: check this 375 376 if(myShip_){ 376 COUT( 4) << "requesting focus for camera" << std::endl;377 COUT(5) << "requesting focus for camera" << std::endl; 377 378 //CameraHandler::getInstance()->requestFocus(cam_); 378 379 if(this->isExactlyA(Class(SpaceShip))){ 379 380 getFocus(); 380 COUT(4) << "getting focus for obj id: " << objectID<< std::endl;381 COUT(4) << "getting focus for obj id: " << getObjectID() << std::endl; 381 382 }else 382 COUT( 4) << "not getting focus (not exactly spaceship) for obj id: " << objectID<< std::endl;383 COUT(5) << "not getting focus (not exactly spaceship) for obj id: " << getObjectID() << std::endl; 383 384 }else 384 COUT( 4) << "not getting focus (not my ship) for obj id: " << objectID<< std::endl;385 COUT(5) << "not getting focus (not my ship) for obj id: " << getObjectID() << std::endl; 385 386 } 386 387 … … 478 479 projectile->setColour(this->getProjectileColour()); 479 480 projectile->create(); 480 if (projectile-> classID== 0)481 if (projectile->getClassID() == 0) 481 482 { 482 483 COUT(3) << "generated projectile with classid 0" << std::endl; // TODO: remove this output … … 573 574 } 574 575 575 COUT(5) << "steering our ship: " << objectID<< std::endl;576 COUT(5) << "steering our ship: " << getObjectID() << std::endl; 576 577 this->acceleration_.x = 0; 577 578 this->acceleration_.y = 0;
Note: See TracChangeset
for help on using the changeset viewer.