Changeset 332
- Timestamp:
- Nov 28, 2007, 5:20:23 PM (17 years ago)
- Location:
- code/branches
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/AI/bin/resources.cfg
r212 r332 8 8 FileSystem=../Media 9 9 FileSystem=../Media/fonts 10 FileSystem=../Media/materials/programs11 FileSystem=../Media/materials/scripts12 FileSystem=../Media/materials/textures13 FileSystem=../Media/models10 #FileSystem=../Media/materials/programs 11 #FileSystem=../Media/materials/scripts 12 #FileSystem=../Media/materials/textures 13 #FileSystem=../Media/models 14 14 #FileSystem=../Media/overlays 15 15 #FileSystem=../Media/particle -
code/branches/merger/CMakeLists.txt
r303 r332 32 32 # if on tardis change compiler 33 33 IF (IS_TARDIS) 34 MESSAGE("System is a TARDIS: Setting Compiler to g++- 3.4.3")35 SET(CMAKE_CXX_COMPILER "g++- 3.4.3")34 MESSAGE("System is a TARDIS: Setting Compiler to g++-4.1.1") 35 SET(CMAKE_CXX_COMPILER "g++-4.1.1") 36 36 # reset eNet serach path 37 37 SET(Boost_INCLUDE_DIR "/usr/pack/boost-1.34.1-sd/i686-debian-linux3.1/include/boost-1_34_1") … … 42 42 #This sets where to look for "Find*.cmake" files 43 43 SET(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) 44 # SET(BOOST_LIBDIR /usr/pack/boost-1.33.1-mo/i686-debian-linux3.1/lib/) 45 # SET(BOOST_INCDIR /usr/pack/boost-1.33.1-mo/i686-debian-linux3.1/include/) 46 44 47 #Performs the search and sets the variables 45 48 FIND_PACKAGE(OGRE) … … 52 55 #Sets the search paths for the linking 53 56 LINK_DIRECTORIES(${OGRE_LIB_DIR} ${OIS_LIB_DIR} ${CEGUI_LIB_DIR} ${CEGUI_OGRE_LIB_DIR} ${ENet_LIBRARY} ${Boost_LIBRARY_DIRS} core objects loader network weapon classHierarchy) 57 54 58 #Sets the search path for include files 55 59 INCLUDE_DIRECTORIES(${OGRE_INCLUDE_DIR} ${OIS_INCLUDE_DIR} ${CEGUI_INCLUDE_DIR} ${CEGUI_OGRE_INCLUDE_DIR} ${ENet_INCLUDE_DIR} ${Boost_INCLUDE_DIRS}) 60 56 61 57 62 #add main source dir -
code/branches/merger/src/network/CMakeLists.txt
r319 r332 1 1 PROJECT(Orxonox) 2 2 3 SET(SRC_FILES Client.cc ConnectionManager.cc PacketBuffer.cc PacketGenerator.cc Synchronisable.cc dummyclient2.cc ClientConnection.cc GameStateManager.cc PacketDecoder.cc Server.cc dummyclient.cc dummyserver.cc)3 SET(SRC_FILES Client.cc ConnectionManager.cc PacketBuffer.cc PacketGenerator.cc Synchronisable.cc ClientConnection.cc GameStateManager.cc PacketDecoder.cc Server.cc) 4 4 5 ADD_LIBRARY(network ${SRC_FILES}) 5 INCLUDE_DIRECTORIES(..) 6 7 ADD_LIBRARY(network ${SRC_FILES} ${ENet_LIBRARY}) -
code/branches/merger/src/network/GameStateManager.cc
r278 r332 22 22 } 23 23 24 GameState GameStateManager::getSnapshot(){ 24 /** 25 * This function goes through the whole list of synchronisables and 26 * saves all the synchronisables to a flat "list". 27 * @return struct of type gamestate containing the size of the whole gamestate and a pointer linking to the flat list 28 */ 29 GameState GameStateManager::getSnapshot(int id) 30 { 31 //the size of the gamestate 32 int totalsize=0; 33 //the size of one specific synchronisable 34 int tempsize=0; 35 // get the start of the Synchronisable list 36 orxonox::Iterator<Synchronisable> it; 37 // struct for return value of Synchronisable::getData() 38 syncData sync; 39 40 GameState retval; //return value 41 retval.id=id; 42 // reserve a little memory and increase it later on 43 retval.data = (unsigned char*)malloc(1); 44 45 // offset of memory functions 46 int offset=0; 47 // go through all Synchronisables 48 for(it = orxonox::ObjectList<Synchronisable>::start(); it != 0; ++it){ 49 //get size of the synchronisable 50 tempsize=it->getSize(); 51 // add place for data and 3 ints (length,classid,objectid) 52 totalsize+=tempsize+3*sizeof(int); 53 // allocate additional space 54 retval.data = (unsigned char *)realloc((void *)retval.data, totalsize); 55 56 // run Synchronisable::getData with offset and additional place for 3 ints in between (for ids and length) 57 sync=it->getData(retval.data+offset+3*sizeof(int)); 58 *(retval.data+offset)=sync.length; 59 *(retval.data+offset+sizeof(int))=sync.objectID; 60 *(retval.data+offset+2*sizeof(int))=sync.classID; 61 // increase data pointer 62 offset+=tempsize+3*sizeof(int); 63 } 64 retval.size=totalsize; 65 return retval; 66 } 67 68 /** 69 * This function loads a Snapshort of the gamestate into the universe 70 * @param state a GameState struct containing the size of the gamestate and a pointer linking to a flat list (returned by getSnapshot) 71 */ 72 bool GameStateManager::loadSnapshot(GameState state) 73 { 74 unsigned char *data=state.data; 75 // get the start of the Synchronisable list 76 orxonox::Iterator<Synchronisable> it=orxonox::ObjectList<Synchronisable>::start(); 77 syncData sync; 78 // loop as long as we have some data ;) 79 while(data < state.data+state.size){ 80 // prepare the syncData struct 81 sync.length = *(int *)data; 82 data+=sizeof(int); 83 sync.objectID = *(int *)data; 84 data+=sizeof(int); 85 sync.classID = *(int *)data; 86 data+=sizeof(int); 87 sync.data = data; 88 data+=sync.length; 89 90 if(it->objectID!=sync.objectID){ 91 // bad luck ;) 92 // delete the synchronisable (obviously seems to be deleted on the server) 93 while(it != 0 && it->objectID!=sync.objectID){ 94 removeObject(it); 95 } 96 if(it==0){ // add the new object 97 98 } 99 } else { 100 // we have our object 101 if(! it->updateData(sync)) 102 std::cout << "We couldn't update objectID: " \ 103 << sync.objectID << "; classID: " << sync.classID << std::endl; 104 } 105 106 } 107 25 108 26 109 } 27 110 28 bool GameStateManager::loadSnapshot(GameState state){ 29 111 /** 112 * This function removes a Synchronisable out of the universe 113 * @param it iterator of the list pointing to the object 114 * @return iterator pointing to the next object in the list 115 */ 116 // orxonox::Iterator<Synchronisable> removeObject(orxonox::Iterator<Synchronisable> it){ 117 void removeObject(orxonox::Iterator<Synchronisable> &it){ 118 orxonox::Iterator<Synchronisable> temp=it; 119 ++it; 120 delete *temp; 121 // return it; 30 122 } 31 123 124 32 125 } 126 127 -
code/branches/merger/src/network/GameStateManager.h
r278 r332 13 13 #define NETWORK_GAMESTATEMANAGER_H 14 14 15 #include "Synchronisable.h" 16 #include "orxonox/core/IdentifierIncludes.h" 17 #include "orxonox/core/Iterator.h" 18 15 19 namespace network { 16 20 … … 20 24 * data: pointer to the data allocated in the memory 21 25 */ 22 struct GameState{ 26 struct GameState{ 27 int id; 23 28 int size; 24 29 unsigned char *data; … … 36 41 GameStateManager(); 37 42 ~GameStateManager(); 38 GameState getSnapshot( );43 GameState getSnapshot(int id); 39 44 bool loadSnapshot(GameState state); 40 45 private: 41 46 bool removeObject(orxonox::Iterator<Synchronisable> it); 47 42 48 }; 43 49 -
code/branches/merger/src/network/PacketDecoder.cc
r278 r332 1 1 /* 2 2 * Class contains functions to determine and decode incomming packages 3 * ->don't read this without the class PacketGenerator, since they belong together 3 4 * 4 5 * Autor: Dumeni Manatschal 5 6 * 6 7 */ 7 8 8 9 9 #include "enet/enet.h" … … 21 21 { 22 22 int client = clientId; 23 cout << "clientId: " << client << endl; 24 int id = (int)*packet->data; 23 cout << "clientId: " << client << endl; //control cout, not important, just debugging info 24 int id = (int)*packet->data; //the first 4 bytes are always the enet packet id 25 25 switch( id ) { 26 26 case ACK: … … 40 40 return true; 41 41 break; 42 case GAMESTATE: 43 gstate( packet ); 44 return true; 45 break; 42 46 } 43 47 return false; … … 49 53 { 50 54 ack* a = new ack; 51 *a = *(ack*)packet->data; 52 printAck( a ); 55 *a = *(ack*)packet->data; //press pattern of ack on new data 56 57 //clean memory 58 enet_packet_destroy( packet ); 59 60 printAck( a ); //debug info 53 61 } 54 62 … … 56 64 { 57 65 mouse* mouseMove = new mouse; 58 *mouseMove = *(mouse*)packet->data; 59 printMouse( mouseMove ); 66 //copy data of packet->data to new struct 67 *mouseMove = *(mouse*)packet->data; 68 69 //clean memory 70 enet_packet_destroy( packet ); 71 72 printMouse( mouseMove ); //debug info 60 73 } 61 74 … … 63 76 { 64 77 keyboard* key = new keyboard; 65 *key = *(keyboard*)packet->data; 66 printKey( key ); 78 *key = *(keyboard*)packet->data; //see above 79 80 //clean memory 81 enet_packet_destroy( packet ); 82 83 printKey( key ); //debug info 84 67 85 } 68 86 … … 70 88 { 71 89 chat* chatting = new chat; 72 chatting->id = (int)*packet->data; 73 char* reserve = new char[packet->dataLength-4]; 74 memcpy( &reserve[0], packet->data+sizeof(int), packet->dataLength-4 ); 90 chatting->id = (int)*packet->data; //first copy id into new struct 91 //since the chat message is a char*, allocate the memory needed 92 char* reserve = new char[packet->dataLength-4]; 93 //copy the transmitted bytestream into the new generated char*, 94 //note the lenght of the message is represented as "packet->dataLength-sizeof( int )" 95 memcpy( &reserve[0], packet->data+sizeof(int), packet->dataLength-sizeof(int) ); 96 //put pointer of chatting struct to the begining of the new generated char* 75 97 chatting->message = reserve; 76 printChat( chatting ); 98 99 //clean memory 100 enet_packet_destroy( packet ); 101 102 printChat( chatting ); //debug info 103 104 } 105 106 void PacketDecoder::gstate( ENetPacket* packet ) 107 { 108 GameState* currentState = new GameState; 109 //since it's not alowed to use void* for pointer arithmetic 110 unsigned char* data = (unsigned char*)packet->data; 111 //copy the gamestate id into the struct, which is located at second place data+sizeof( int ) 112 memcpy( (void*)&(currentState->id), (const void*)(data+sizeof( int )), sizeof( int ) ); 113 //copy the size of the gamestate data into the new gamestate struct, located at 3th 114 //position of the data stream, data+2*sizeof( int ) 115 memcpy( (void*)&(currentState->size), (const void*)(data+2*sizeof( int )), sizeof( int) ); 116 //since data is not allocated, because it's just a pointer, allocate it with size of gamestatedatastream 117 currentState->data = (unsigned char*)(malloc( currentState->size )); 118 //copy the gamestate data 119 memcpy( (void*)(currentState->data), (const void*)(data+3*sizeof( int )), currentState->size ); 120 121 //clean memory 122 enet_packet_destroy( packet ); 77 123 } 78 124 … … 100 146 { 101 147 cout << "data id: " << data->id << endl; 102 cout << "blablabla" << endl;103 148 cout << "data: " << data->message << endl; 104 149 } 150 151 void PacketDecoder::printGamestate( GameState* data ) 152 { 153 cout << "id of gamestate: " << data->id << endl; 154 cout << "size of gamestate: " << data->size << endl; 155 } -
code/branches/merger/src/network/PacketGenerator.cc
r278 r332 1 1 /* 2 2 *Class generates packets that can be send by enet 3 * ->don't read this without the class PacketDecoder, since they belong together 3 4 * 4 5 * Autor: Dumeni Manatschal … … 68 69 } 69 70 71 /*### gamestate packet */ 72 ENetPacket* PacketGenerator::gstate( GameState* states, int reliable ) 73 { 74 int* gid; *gid = GAMESTATE; //first assign the correct enet id 75 int totalLen = 3*sizeof( int ) + states->size; //calculate the total size of the datastream memory 76 unsigned char* data = (unsigned char*)malloc( totalLen ); //allocate the memory for datastream 77 memcpy( (void*)(data), (const void*)gid, sizeof( int ) ); //this is the enet id 78 memcpy( (void*)(data+sizeof(int)), (const void*)&(states->id), sizeof(int) ); //the gamestate id 79 //this is the size of the gamestate data, place at 3th position of the enet datastream 80 memcpy( (void*)(data+2*sizeof(int)), (const void*)&(states->size), sizeof(int)); 81 //place the gamestate data at the end of the enet datastream 82 memcpy( (void*)(data+3*sizeof( int )), (const void*)states->data, states->size ); 83 //create an enet packet with the generated bytestream 84 ENetPacket *packet = enet_packet_create( data , totalLen, reliable ); 85 86 return packet; 87 } -
code/branches/merger/src/network/PacketManager.h
r278 r332 3 3 4 4 #include <enet/enet.h> 5 #include <network/GameStateManager.h> 5 6 6 7 //enum netowk generaly used to set the type ID of a packet … … 11 12 MOUSE, 12 13 KEYBOARD, 13 CHAT 14 CHAT, 15 GAMESTATE 14 16 }; 15 17 … … 17 19 * class to generate packets 18 20 * 19 * Autor: Dumeni Manatschal21 * @autor: Dumeni Manatschal 20 22 * 21 23 */ … … 29 31 ENetPacket* keystrike( char press, int reliable = ENET_PACKET_FLAG_RELIABLE ); 30 32 ENetPacket* chatMessage( const char* message, int reliable = ENET_PACKET_FLAG_RELIABLE ); 33 ENetPacket* gstate( GameState* states, int reliable = ENET_PACKET_FLAG_RELIABLE ); 31 34 private: 32 35 //used to set the bytes in the right order … … 51 54 * class used to decode incoming packets 52 55 * 53 * Autor: Dumeni Manatschal56 * @autor: Dumeni Manatschal 54 57 * 55 58 */ … … 87 90 void keystrike( ENetPacket* packet ); 88 91 void chatMessage( ENetPacket* packet ); 92 void gstate( ENetPacket* packet ); 89 93 90 94 //print functions … … 93 97 void printKey( keyboard* data ); 94 98 void printChat( chat* data ); 95 void print Peer( ENetPeer* peer);99 void printGamestate( GameState* data ); 96 100 }; 97 101 } -
code/branches/merger/src/network/Synchronisable.h
r278 r332 14 14 15 15 #include <list> 16 #include <iostream> 17 18 #include "orxonox/core/IdentifierIncludes.h" 16 19 17 20 namespace network { … … 20 23 struct syncData{ 21 24 int length; 25 int objectID; 22 26 int classID; 23 int objectID;24 27 unsigned char *data; 25 28 }; … … 40 43 Synchronisable(); 41 44 42 ~Synchronisable();45 virtual ~Synchronisable(); 43 46 int objectID; 44 47 int classID; … … 52 55 53 56 private: 57 /* bool removeObject(Iterator<Synchronisable> it);*/ 58 54 59 std::list<SYNCVAR> syncList; 55 60 int datasize; -
code/branches/merger/src/orxonox/core/Iterator.h
r258 r332 1 #ifndef _Iterator_H __2 #define _Iterator_H __1 #ifndef _Iterator_H2__ 2 #define _Iterator_H2__ 3 3 4 4 namespace orxonox
Note: See TracChangeset
for help on using the changeset viewer.