Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 422 for code/branches/FICN/src


Ignore:
Timestamp:
Dec 5, 2007, 9:17:22 PM (17 years ago)
Author:
scheusso
Message:

extended GameStateManager

Location:
code/branches/FICN/src/network
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • code/branches/FICN/src/network/GameStateManager.cc

    r413 r422  
    2424
    2525void GameStateManager::update(){
    26   reference = getSnapshot(id++);
     26  reference = getSnapshot(id);
     27  idGameState[id]=reference;
     28  ++id;
    2729  return;
    2830}
     
    3032GameStateCompressed GameStateManager::popGameState(int clientID){
    3133  GameState *client = clientGameState[clientID]; 
    32   GameState *server = &reference;
     34  GameState *server = reference;
    3335  return encode(client, server);
    3436}
     
    4143 * @return struct of type gamestate containing the size of the whole gamestate and a pointer linking to the flat list
    4244 */
    43 GameState GameStateManager::getSnapshot(int id)
     45GameState *GameStateManager::getSnapshot(int id)
    4446{
    4547  //the size of the gamestate
     
    5254  syncData sync;
    5355 
    54   GameState retval; //return value
    55   retval.id=id;
     56  GameState *retval=new GameState; //return value
     57  retval->id=id;
    5658  // reserve a little memory and increase it later on
    57   retval.data = (unsigned char*)malloc(1);
     59  retval->data = (unsigned char*)malloc(1);
    5860 
    5961  // offset of memory functions
     
    6668    totalsize+=tempsize+3*sizeof(int);
    6769    // allocate additional space
    68     retval.data = (unsigned char *)realloc((void *)retval.data, totalsize);
     70    retval->data = (unsigned char *)realloc((void *)retval->data, totalsize);
    6971   
    7072    // run Synchronisable::getData with offset and additional place for 3 ints in between (for ids and length)
    71     sync=it->getData(retval.data+offset+3*sizeof(int));
    72     *(retval.data+offset)=sync.length;
    73     *(retval.data+offset+sizeof(int))=sync.objectID;
    74     *(retval.data+offset+2*sizeof(int))=sync.classID;
     73    sync=it->getData(retval->data+offset+3*sizeof(int));
     74    *(retval->data+offset)=sync.length;
     75    *(retval->data+offset+sizeof(int))=sync.objectID;
     76    *(retval->data+offset+2*sizeof(int))=sync.classID;
    7577    // increase data pointer
    7678    offset+=tempsize+3*sizeof(int);
    7779  }
    78   retval.size=totalsize;
     80  retval->size=totalsize;
    7981  return retval;
    8082}
     
    143145}
    144146
     147void GameStateManager::ackGameState(int clientID, int gamestateID){
     148  GameState *old = clientGameState[clientID];
     149  deleteUnusedGameState(old);
     150  clientGameState[clientID]=idGameState[gamestateID];
     151}
    145152
     153bool GameStateManager::deleteUnusedGameState(GameState *state){
     154  for(unsigned int i=0; i<clientGameState.size(); i++){
     155    if(clientGameState[i]==state)
     156      return false;
     157  }
     158  delete state;
     159  return true;
     160}
    146161
    147162}
  • code/branches/FICN/src/network/GameStateManager.h

    r415 r422  
    4747  void update();
    4848  GameStateCompressed popGameState(int clientID);
     49  void ackGameState(int clientID, int gamestateID);
    4950private:
    50   GameState getSnapshot(int id);
     51  GameState *getSnapshot(int id);
    5152  GameStateCompressed encode(GameState *a, GameState *b);
    5253  GameState diff(GameState *a, GameState *b);
    5354  GameStateCompressed compress_(GameState a);
     55  bool deleteUnusedGameState(GameState *state);
    5456 
    5557  std::vector<GameState *> clientGameState;
    56   GameState reference;
     58  std::vector<GameState *> idGameState;
     59  GameState *reference;
    5760  int id;
    5861};
  • code/branches/FICN/src/network/PacketManager.h

    r415 r422  
    5050       
    5151       
    52         void acknowledgement( ENetPacket* packet );
    53         void mousem( ENetPacket* packet );
    54         void keystrike( ENetPacket* packet );
    55         void chatMessage( ENetPacket* packet );
    56         void gstate( ENetPacket* packet );
     52    void acknowledgement( ENetPacket* packet );
     53    void mousem( ENetPacket* packet );
     54    void keystrike( ENetPacket* packet );
     55    void chatMessage( ENetPacket* packet );
     56    void gstate( ENetPacket* packet );
    5757    void clid( ENetPacket *packet);
    5858       
  • code/branches/FICN/src/network/Server.cc

    r400 r422  
    103103    while(!connection.queueEmpty()){
    104104      packet = connection.getPacket(clientID);
     105      elaborate(packet, clientID);
    105106    }
    106107  }
     
    110111   */
    111112  void Server::updateGamestate(){
     113    gamestates.update();
     114    sendGameState();
     115  }
     116 
     117  bool Server::sendGameState(){
     118   
    112119  }
    113120 
  • code/branches/FICN/src/network/Server.h

    r413 r422  
    3838    void tick();
    3939    private:
     40    bool sendGameState();
    4041    ConnectionManager connection;
    4142    GameStateManager gamestates;
Note: See TracChangeset for help on using the changeset viewer.