Changeset 314 for code/branches/network/src
- Timestamp:
- Nov 28, 2007, 2:41:41 PM (17 years ago)
- Location:
- code/branches/network/src/network
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/network/src/network/GameStateManager.cc
r290 r314 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) 25 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 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 = malloc(1); 44 45 // offset of memory functions 46 int offset=0; 47 // go through all Synchronisables 48 for(it = 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+*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 Iterator<Synchronisable> it=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 } else { 93 // we have our object 94 if(! it->updateData(sync)) 95 std::cout << "We couldn't update objectID: " << sync.objectID << "; classID: " << sync.classID << std::endl; 96 } 97 } 26 98 27 99 } 28 100 29 bool GameStateManager::loadSnapshot(GameState state) 30 { 31 101 102 103 32 104 } 33 105 34 } 106 -
code/branches/network/src/network/GameStateManager.h
r247 r314 13 13 #define NETWORK_GAMESTATEMANAGER_H 14 14 15 #include "network/Synchronisable.h" 16 15 17 namespace network { 16 18 … … 20 22 * data: pointer to the data allocated in the memory 21 23 */ 22 struct GameState{ 24 struct GameState{ 25 int id; 23 26 int size; 24 27 unsigned char *data; … … 36 39 GameStateManager(); 37 40 ~GameStateManager(); 38 GameState getSnapshot( );41 GameState getSnapshot(int id); 39 42 bool loadSnapshot(GameState state); 40 43 private: -
code/branches/network/src/network/Synchronisable.h
r247 r314 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 };
Note: See TracChangeset
for help on using the changeset viewer.