Changeset 1916 for code/branches/objecthierarchy/src/network
- Timestamp:
- Oct 14, 2008, 12:20:14 AM (16 years ago)
- Location:
- code/branches/objecthierarchy/src/network
- Files:
-
- 22 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/objecthierarchy/src/network/CMakeLists.txt
r1907 r1916 21 21 22 22 IF(WIN32) 23 ADD_LIBRARY( network ${NETWORK_SRC_FILES} )23 ADD_LIBRARY( network SHARED ${NETWORK_SRC_FILES} ) 24 24 ELSE(WIN32) 25 25 ADD_LIBRARY( network SHARED ${NETWORK_SRC_FILES} ) -
code/branches/objecthierarchy/src/network/ClientConnection.h
r1907 r1916 60 60 61 61 62 class ClientConnection{62 class _NetworkExport ClientConnection{ 63 63 public: 64 64 ClientConnection(int port, std::string address); … … 96 96 ENetPeer *server; 97 97 boost::thread *receiverThread_; 98 98 99 99 static boost::recursive_mutex enet_mutex_; 100 100 }; -
code/branches/objecthierarchy/src/network/ClientInformation.h
r1735 r1916 57 57 * @author Oliver Scheuss 58 58 */ 59 class ClientInformation{59 class _NetworkExport ClientInformation{ 60 60 public: 61 61 ClientInformation(); … … 66 66 ClientInformation *prev(); 67 67 static ClientInformation *insertBack(ClientInformation *ins); 68 68 69 69 // set functions 70 70 void setID(int clientID); … … 73 73 bool setPartialGamestateID(int id); 74 74 inline void setShipID(unsigned int id){ShipID_=id;} 75 75 76 76 // get functions 77 77 inline unsigned int getShipID(){return ShipID_;} … … 80 80 int getPartialGamestateID(); 81 81 ENetPeer *getPeer(); 82 82 83 83 int getFailures(); 84 84 void addFailure(); … … 86 86 enet_uint32 getRTT(); 87 87 enet_uint32 getPacketLoss(); 88 88 89 89 static bool removeClient(int clientID); 90 90 static bool removeClient(ENetPeer *peer); … … 99 99 private: 100 100 static ClientInformation *head_; 101 101 102 102 bool setNext(ClientInformation *next); 103 103 bool setPrev(ClientInformation *prev); 104 104 ClientInformation *insertAfter(ClientInformation *ins); 105 105 ClientInformation *insertBefore(ClientInformation *ins); 106 106 107 107 ClientInformation *preve; 108 108 ClientInformation *nexte; … … 115 115 bool synched_; 116 116 unsigned short failures_; 117 117 118 118 }; 119 119 -
code/branches/objecthierarchy/src/network/ConnectionManager.cc
r1907 r1916 49 49 #include "core/BaseObject.h" 50 50 #include "core/Iterator.h" 51 #include "objects/SpaceShip.h"52 51 #include "util/Math.h" 53 52 #include "util/Sleep.h" … … 331 330 332 331 333 334 bool ConnectionManager::removeShip(ClientInformation *client){335 unsigned int id=client->getShipID();336 orxonox::ObjectList<orxonox::SpaceShip>::iterator it;337 for(it = orxonox::ObjectList<orxonox::SpaceShip>::begin(); it; ++it){338 if(it->getObjectID()!=id)339 continue;340 delete *it;341 }342 return true;343 }344 345 346 332 void ConnectionManager::disconnectClient(ClientInformation *client){ 347 333 { … … 350 336 lock.unlock(); 351 337 } 352 removeShip(client);353 338 } 354 339 -
code/branches/objecthierarchy/src/network/ConnectionManager.h
r1785 r1916 66 66 const int NETWORK_DEFAULT_CHANNEL = 0; 67 67 68 struct ClientList{68 struct _NetworkExport ClientList{ 69 69 ENetEvent *event; 70 70 int ID; … … 72 72 }; 73 73 74 class ConnectionManager{74 class _NetworkExport ConnectionManager{ 75 75 public: 76 76 static boost::recursive_mutex enet_mutex; … … 107 107 int getClientID(ENetAddress address); 108 108 ENetPeer *getClientPeer(int clientID); 109 //bool createShip(ClientInformation *client);110 bool removeShip(ClientInformation *client);111 109 PacketBuffer buffer; 112 110 -
code/branches/objecthierarchy/src/network/GamestateClient.cc
r1907 r1916 40 40 namespace network 41 41 { 42 struct GameStateItem{42 struct _NetworkExport GameStateItem{ 43 43 packet::Gamestate *state; 44 44 int id; … … 50 50 last_gamestate_=GAMESTATEID_INITIAL-1; 51 51 tempGamestate_=NULL; 52 myShip_=NULL;53 52 } 54 53 … … 75 74 return false; 76 75 int id = GAMESTATEID_INITIAL; 77 bool b = saveShipCache();78 76 packet::Gamestate *processed = processGamestate(tempGamestate_); 79 if(!processed){80 if(b)81 loadShipCache();82 return false;83 }84 77 // assert(processed); 85 78 //successfully loaded data from gamestate. now save gamestate for diff and delete the old gs … … 87 80 gamestateMap_[processed->getID()]=processed; 88 81 last_diff_ = processed->getID(); 89 if(b)90 loadShipCache();91 82 id = processed->getID(); 92 83 sendAck(id); … … 134 125 135 126 } 136 127 137 128 bool GamestateClient::sendAck(unsigned int gamestateID){ 138 129 packet::Acknowledgement *ack = new packet::Acknowledgement(gamestateID, 0); … … 145 136 return true; 146 137 } 147 }148 149 bool GamestateClient::saveShipCache(){150 if(myShip_==NULL){151 myShip_ = orxonox::SpaceShip::getLocalShip();152 // COUT(2) << "myShip_: " << myShip_ << " getLocalShip(): " << orxonox::SpaceShip::getLocalShip() << std::endl;153 if(!myShip_)154 return false;155 }156 if(myShip_){157 // unsigned char *data = new unsigned char[myShip_->getSize()];158 int size=myShip_->getSize(0, 0x1);159 if(size==0)160 return false;161 shipCache_ = new unsigned char [size];162 unsigned char *temp = shipCache_;163 if(!myShip_->getData(temp, 0, 0x1))164 COUT(3) << "could not save shipCache" << std::endl;165 return true;166 }else167 return false;168 }169 170 bool GamestateClient::loadShipCache(){171 myShip_=orxonox::SpaceShip::getLocalShip(); //TODO: remove this (only a hack)172 if(myShip_ && shipCache_){173 assert(myShip_->getIdentifier());174 unsigned char *temp = shipCache_;175 myShip_->updateData(temp, 0x2);176 delete shipCache_;177 return true;178 }else179 return false;180 138 } 181 139 -
code/branches/objecthierarchy/src/network/GamestateClient.h
r1769 r1916 46 46 #include "core/CorePrereqs.h" 47 47 #include "packet/Gamestate.h" 48 #include "objects/SpaceShip.h"49 48 #include "GamestateHandler.h" 50 49 … … 53 52 namespace network 54 53 { 55 class GamestateClient: public GamestateHandler54 class _NetworkExport GamestateClient: public GamestateHandler 56 55 { 57 56 public: … … 70 69 void printGamestateMap(); 71 70 bool sendAck(unsigned int gamestateID); 72 bool saveShipCache();73 bool loadShipCache();74 71 75 72 int last_diff_; … … 77 74 std::map<int, packet::Gamestate *> gamestateMap_; 78 75 packet::Gamestate *tempGamestate_; // we save the received gamestates here during processQueue 79 orxonox::SpaceShip *myShip_;80 76 unsigned char *shipCache_; 81 77 -
code/branches/objecthierarchy/src/network/GamestateHandler.h
r1763 r1916 39 39 @author Oliver Scheuss 40 40 */ 41 class GamestateHandler{41 class _NetworkExport GamestateHandler{ 42 42 private: 43 43 virtual bool add(packet::Gamestate *gs, int clientID)=0; -
code/branches/objecthierarchy/src/network/GamestateManager.h
r1907 r1916 66 66 * @author Oliver Scheuss 67 67 */ 68 class GamestateManager: public GamestateHandler{68 class _NetworkExport GamestateManager: public GamestateHandler{ 69 69 public: 70 70 GamestateManager(); -
code/branches/objecthierarchy/src/network/Host.h
r1907 r1916 44 44 * @author Oliver Scheuss 45 45 */ 46 class Host{46 class _NetworkExport Host{ 47 47 private: 48 48 //TODO add theese functions or adequate … … 72 72 static void setClientID(unsigned int id){ instance_->clientID_ = id; } 73 73 static void setShipID(unsigned int id){ instance_->shipID_ = id; } 74 static bool isServer(){ return instance_->isServer_(); } 74 static bool isServer(){ return instance_->isServer_(); } 75 75 static bool Chat(std::string message); 76 76 static bool incomingChat(std::string message, unsigned int playerID); -
code/branches/objecthierarchy/src/network/NetworkCallback.h
r1536 r1916 2 2 #define _NETWORK_CALLBACK__ 3 3 4 #include "NetworkPrereqs.h" 5 4 6 namespace network{ 5 class NetworkCallbackBase7 class _NetworkExport NetworkCallbackBase 6 8 { 7 9 public: … … 9 11 virtual ~NetworkCallbackBase() {} 10 12 }; 11 13 12 14 template <class T> 13 class NetworkCallback: public NetworkCallbackBase15 class _NetworkExport NetworkCallback: public NetworkCallbackBase 14 16 { 15 17 public: … … 18 20 virtual void call() 19 21 { (this->object_->*function_)(); } 20 22 21 23 private: 22 24 T* object_; 23 25 void (T::*function_) (void); 24 }; 26 }; 25 27 26 28 -
code/branches/objecthierarchy/src/network/PacketBuffer.h
r1505 r1916 49 49 namespace network 50 50 { 51 struct PacketEnvelope{51 struct _NetworkExport PacketEnvelope{ 52 52 int length; 53 53 int data; 54 54 }; 55 55 56 struct QueueItem{56 struct _NetworkExport QueueItem{ 57 57 ENetEvent *event; 58 58 //ENetAddress address; … … 60 60 }; 61 61 62 class PacketBuffer{62 class _NetworkExport PacketBuffer{ 63 63 public: 64 64 PacketBuffer(); -
code/branches/objecthierarchy/src/network/Server.cc
r1907 r1916 49 49 #include "ClientInformation.h" 50 50 #include "util/Sleep.h" 51 #include "objects/SpaceShip.h"52 51 #include "core/ConsoleCommand.h" 53 52 #include "core/CoreIncludes.h" … … 101 100 gamestates_ = new GamestateManager(); 102 101 } 103 102 104 103 /** 105 104 * @brief Destructor … … 304 303 COUT(4) << "Con.Man: creating client id: " << temp->getID() << std::endl; 305 304 connection->syncClassid(temp->getID()); 306 COUT(5) << "creating spaceship for clientid: " << temp->getID() << std::endl;307 // TODO: this is only a hack, untill we have a possibility to define default player-join actions308 if(!createShip(temp))309 COUT(2) << "Con.Man. could not create ship for clientid: " << clientID << std::endl;310 else311 COUT(3) << "created spaceship" << std::endl;312 305 temp->setSynched(true); 313 306 COUT(3) << "sending welcome" << std::endl; … … 327 320 } 328 321 329 bool Server::createShip(ClientInformation *client){330 if(!client)331 return false;332 orxonox::Identifier* id = ClassByName("SpaceShip");333 if(!id){334 COUT(4) << "We could not create the SpaceShip for client: " << client->getID() << std::endl;335 return false;336 }337 orxonox::SpaceShip *no = dynamic_cast<orxonox::SpaceShip *>(id->fabricate());338 no->classID = id->getNetworkID();339 client->setShipID(no->getObjectID());340 no->setPosition(orxonox::Vector3(0,0,80));341 no->setScale(10);342 //no->setYawPitchRoll(orxonox::Degree(-90),orxonox::Degree(-90),orxonox::Degree(0));343 no->setMesh("assff.mesh");344 no->setMaxSpeed(500);345 no->setMaxSideAndBackSpeed(50);346 no->setMaxRotation(1.0);347 no->setTransAcc(200);348 no->setRotAcc(3.0);349 no->setTransDamp(75);350 no->setRotDamp(1.0);351 no->setCamera(std::string("cam_") + convertToString(client->getID()));352 no->create();353 354 return true;355 }356 357 322 bool Server::disconnectClient(ENetEvent *event){ 358 323 COUT(4) << "removing client from list" << std::endl; … … 360 325 361 326 //boost::recursive_mutex::scoped_lock lock(head_->mutex_); 362 orxonox::ObjectList<orxonox::SpaceShip>::iterator it = orxonox::ObjectList<orxonox::SpaceShip>::begin();363 327 ClientInformation *client = ClientInformation::findClient(&event->peer->address); 364 328 if(!client) 365 329 return false; 366 330 gamestates_->removeClient(client); 367 while(it){ 368 if(it->getObjectID()!=client->getShipID()){ 369 ++it; 370 continue; 371 } 372 orxonox::ObjectList<orxonox::SpaceShip>::iterator temp=it; 373 ++it; 374 delete *temp; 375 return ClientInformation::removeClient(event->peer); 376 } 377 return false; 331 return ClientInformation::removeClient(event->peer); 378 332 } 379 333 … … 387 341 gamestates_->removeClient(client); 388 342 } 389 343 390 344 bool Server::chat(std::string message){ 391 345 ClientInformation *temp = ClientInformation::getBegin(); -
code/branches/objecthierarchy/src/network/Server.h
r1907 r1916 52 52 { 53 53 const int CLIENTID_SERVER = 0; 54 54 55 55 /** 56 56 * This class is the root class of the network module for a server. … … 64 64 Server(int port, const char *bindAddress); 65 65 ~Server(); 66 66 67 67 void open(); 68 68 void close(); … … 77 77 unsigned int shipID(){return 0;} 78 78 unsigned int playerID(){return 0;} 79 79 80 80 bool addClient(ENetEvent *event); 81 81 bool createClient(int clientID); 82 bool createShip(ClientInformation *client);83 82 bool disconnectClient(ENetEvent *event); 84 83 void disconnectClient(int clientID); … … 88 87 bool sendObjectDeletes(); 89 88 virtual bool chat(std::string message); 90 89 91 90 //void processChat( chat *data, int clientId); 92 91 ConnectionManager *connection; 93 92 GamestateManager *gamestates_; 94 93 95 94 96 95 float timeSinceLastUpdate_; 97 96 }; -
code/branches/objecthierarchy/src/network/Synchronisable.h
r1910 r1916 46 46 #define REGISTERSTRING_WITHDIR(stringname, mode) registerVar(&stringname, stringname.length()+1, network::STRING, mode) 47 47 48 //TODO: this is only a very ugly hack ...49 namespace orxonox{50 class SpaceShip;51 }52 53 48 namespace network 54 49 { … … 60 55 }; 61 56 } 62 57 63 58 namespace syncmode{ 64 59 enum mode{ … … 67 62 }; 68 63 } 69 64 70 65 enum variableType{ 71 66 DATA, … … 73 68 }; 74 69 75 struct synchronisableHeader{70 struct _NetworkExport synchronisableHeader{ 76 71 uint32_t size:31; 77 72 bool dataAvailable:1; … … 80 75 }; 81 76 82 typedef struct synchronisableVariable{77 typedef struct _NetworkExport synchronisableVariable{ 83 78 unsigned int size; 84 79 int mode; // this determines in which direction the variable gets synchronised … … 98 93 friend class GamestateClient; 99 94 friend class Server; 100 friend class orxonox::SpaceShip;101 95 virtual ~Synchronisable(); 102 96 103 97 104 98 virtual bool create(); 105 99 static void setClient(bool b); 106 100 107 101 static Synchronisable *fabricate(uint8_t*& mem, int mode=0x0); 108 102 static bool deleteObject(unsigned int objectID); … … 110 104 static unsigned int getNumberOfDeletedObject(){ return deletedObjects_.size(); } 111 105 static unsigned int popDeletedObject(){ unsigned int i = deletedObjects_.front(); deletedObjects_.pop(); return i; } 112 106 113 107 inline unsigned int getObjectID(){return objectID;} 114 108 inline unsigned int getClassID(){return classID;} … … 119 113 void setObjectFrequency(unsigned int freq){ objectFrequency_ = freq; } 120 114 virtual void registerAllVariables()=0; 121 122 115 116 123 117 private: 124 118 bool getData(uint8_t*& men, unsigned int id, int mode=0x0); … … 128 122 bool doSelection(unsigned int id); 129 123 bool isMyTick(unsigned int id); 130 124 131 125 unsigned int objectID; 132 126 unsigned int classID; 133 127 134 128 std::list<synchronisableVariable *> *syncList; 135 129 static int state_; // detemines wheter we are server (default) or client -
code/branches/objecthierarchy/src/network/packet/Acknowledgement.h
r1907 r1916 29 29 #define NETWORKACKNOLEDGEMENT_H 30 30 31 #include "../NetworkPrereqs.h" 31 32 #include "Packet.h" 32 33 … … 35 36 namespace packet { 36 37 /** 37 @author 38 @author 38 39 */ 39 class Acknowledgement : public Packet40 class _NetworkExport Acknowledgement : public Packet 40 41 { 41 42 public: … … 43 44 Acknowledgement( uint8_t* data, unsigned int clientID ); 44 45 ~Acknowledgement(); 45 46 46 47 inline unsigned int getSize() const; 47 48 bool process(); 48 49 49 50 unsigned int getAckID(); 50 51 private: -
code/branches/objecthierarchy/src/network/packet/Chat.h
r1907 r1916 2 2 #ifndef NETWORKCHAT_H 3 3 #define NETWORKCHAT_H 4 5 #include "../NetworkPrereqs.h" 4 6 5 7 #include <string> … … 11 13 namespace packet { 12 14 /** 13 @author 15 @author 14 16 */ 15 class Chat : public Packet17 class _NetworkExport Chat : public Packet 16 18 { 17 19 public: … … 19 21 Chat( uint8_t* data, unsigned int clientID ); 20 22 ~Chat(); 21 23 22 24 inline unsigned int getSize() const; 23 25 bool process(); 24 26 25 27 unsigned int getMessageLength(){ return messageLength_; }; 26 28 unsigned char *getMessage(); -
code/branches/objecthierarchy/src/network/packet/ClassID.h
r1907 r1916 29 29 #define NETWORKCLASSID_H 30 30 31 #include "../NetworkPrereqs.h" 32 31 33 #include <string> 32 34 … … 37 39 38 40 /** 39 @author 41 @author 40 42 */ 41 class ClassID : public Packet43 class _NetworkExport ClassID : public Packet 42 44 { 43 45 public: … … 45 47 ClassID( uint8_t* data, unsigned int clientID ); 46 48 ~ClassID(); 47 49 48 50 inline unsigned int getSize() const; 49 51 bool process(); 50 52 51 53 unsigned int getClassID(); 52 54 unsigned int getClassNameLength(){ return classNameLength_; } -
code/branches/objecthierarchy/src/network/packet/DeleteObjects.h
r1907 r1916 29 29 #define NETWORKPACKETDELETEOBJECTS_H 30 30 31 #include "../NetworkPrereqs.h" 32 31 33 #include "Packet.h" 32 34 … … 35 37 namespace packet { 36 38 /** 37 @author 39 @author 38 40 */ 39 class DeleteObjects : public Packet41 class _NetworkExport DeleteObjects : public Packet 40 42 { 41 43 public: … … 43 45 DeleteObjects( uint8_t* data, unsigned int clientID ); 44 46 ~DeleteObjects(); 45 47 46 48 bool fetchIDs(); 47 49 48 50 inline unsigned int getSize() const; 49 51 bool process(); 50 52 51 53 private: 52 54 }; -
code/branches/objecthierarchy/src/network/packet/Gamestate.h
r1907 r1916 27 27 */ 28 28 29 30 #ifndef NETWORK_PACKETGAMESTATE_H 31 #define NETWORK_PACKETGAMESTATE_H 32 33 #include "../NetworkPrereqs.h" 34 29 35 #include "Packet.h" 30 36 #include "network/Synchronisable.h" … … 34 40 #endif 35 41 36 37 #ifndef NETWORK_PACKETGAMESTATE_H38 #define NETWORK_PACKETGAMESTATE_H39 40 42 namespace network { 41 43 42 44 namespace packet { 43 45 44 struct GamestateHeader{46 struct _NetworkExport GamestateHeader{ 45 47 ENUM::Type packetType; 46 48 int32_t id; // id of the gamestate … … 59 61 @author Oliver Scheuss 60 62 */ 61 class Gamestate: public Packet{63 class _NetworkExport Gamestate: public Packet{ 62 64 public: 63 65 Gamestate(); -
code/branches/objecthierarchy/src/network/packet/Packet.h
r1907 r1916 29 29 #define NETWORKPACKET_H 30 30 31 #include "../NetworkPrereqs.h" 32 31 33 #include <map> 32 34 #include <enet/enet.h> … … 37 39 38 40 namespace packet{ 39 41 40 42 namespace ENUM{ 41 43 enum Direction{ … … 53 55 }; 54 56 } 55 57 56 58 /** 57 59 @author Oliver Scheuss <scheusso [at] ee.ethz.ch> 58 60 */ 59 class Packet{61 class _NetworkExport Packet{ 60 62 public: 61 63 Packet(const Packet &p); … … 63 65 static Packet *createPacket(ENetPacket *packet, ENetPeer *peer); 64 66 static void deletePacket(ENetPacket *packet); 65 67 66 68 virtual unsigned char *getData(){ return data_; }; 67 69 virtual unsigned int getSize() const =0; … … 73 75 void setClientID( int id ) 74 76 { clientID_ = id; } 75 77 76 78 bool send(); 77 79 protected: -
code/branches/objecthierarchy/src/network/packet/Welcome.h
r1907 r1916 29 29 #define NETWORKWELCOME_H 30 30 31 #include "../NetworkPrereqs.h" 32 31 33 #include "Packet.h" 32 34 … … 35 37 36 38 /** 37 @author 39 @author 38 40 */ 39 class Welcome : public Packet41 class _NetworkExport Welcome : public Packet 40 42 { 41 43 public: … … 43 45 Welcome( uint8_t* data, unsigned int clientID ); 44 46 virtual ~Welcome(); 45 47 46 48 uint8_t *getData(); 47 49 inline unsigned int getSize() const; 48 50 bool process(); 49 51 50 52 private: 51 53 };
Note: See TracChangeset
for help on using the changeset viewer.