Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 385


Ignore:
Timestamp:
Dec 5, 2007, 12:05:46 AM (17 years ago)
Author:
scheusso
Message:

extended GameStateManager:
added functions

  • encode (takes two gamestates and returns a diffed and compressed gamestate)
  • decode (opposite of encode)
  • compress (called by encode) — not yet implemented
  • decompress (called by decode) — not yet implemented
  • diff (called by en/decode)
Location:
code/branches/FICN/src/network
Files:
2 edited

Legend:

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

    r369 r385  
    118118 * @return iterator pointing to the next object in the list
    119119 */
    120 // orxonox::Iterator<Synchronisable> removeObject(orxonox::Iterator<Synchronisable> it){
    121120void GameStateManager::removeObject(orxonox::Iterator<Synchronisable> &it){
    122121  orxonox::Iterator<Synchronisable> temp=it;
     
    126125}
    127126
     127GameState GameStateManager::encode(GameState a, GameState b){
     128  GameState r = diff(a,b);
     129  return compress(r);
     130}
     131
     132GameState GameStateManager::decode(GameState a, GameState x){
     133  GameState t = decompress(x);
     134  return diff(a, t);
     135}
     136
     137GameState GameStateManager::diff(GameState a, GameState b){
     138  unsigned char *ap = a.data, *bp = b.data;
     139  int of=0; // pointers offset
     140  int dest_length=0;
     141  if(a.size>=b.size)
     142    dest_length=a.size;
     143  else
     144    dest_length=b.size;
     145  unsigned char *dp = (unsigned char *)malloc(dest_length*sizeof(unsigned char));
     146  while(of<a.size && of<b.size){
     147    *(dp+of)=*(ap+of)^*(bp+of); // do the xor
     148    ++of;
     149  }
     150  if(a.size!=b.size){ // do we have to fill up ?
     151    unsigned char n=0;
     152    if(a.size<b.size){
     153      while(of<dest_length){
     154        *(dp+of)=n^*(bp+of);
     155        of++;
     156      }
     157    } else{
     158      while(of<dest_length){
     159        *(dp+of)=*(ap+of)^n;
     160        of++;
     161      }
     162    }
     163  }
     164  // should be finished now
     165  GameState r = {b.id, dest_length, dp};
     166  return r;
     167}
     168
     169GameState GameStateManager::compress(GameState a){
     170  // to be implemented !!!!!!!!!!!!!!
     171  return a;
     172}
     173
     174GameState GameStateManager::decompress(GameState a){
     175  // to be implemented !!!!!!!!!!!!!!
     176  return a;
     177}
    128178
    129179}
  • code/branches/FICN/src/network/GameStateManager.h

    r346 r385  
    3535 * - writing gamestates to universe
    3636 * - diffing gamestates ?
     37 *
     38 * EN/DECODATION:
     39 * a: last Gamestate a client has received
     40 * b: new Gamestate
     41 * x: diffed and compressed gamestate
     42 * x=(a^b)
     43 * b=(a^x)
     44 * diff(a,diff(a,x))=x (hope this is correct)
    3745 * @author Oliver Scheuss
    3846*/
     
    4351  GameState getSnapshot(int id);
    4452  bool loadSnapshot(GameState state);
     53  GameState encode(GameState a, GameState b);
     54  GameState decode(GameState a, GameState x);
    4555private:
    4656  void removeObject(orxonox::Iterator<Synchronisable> &it);
    47 
     57  GameState diff(GameState a, GameState b);
     58  GameState compress(GameState a);
     59  GameState decompress(GameState a);
    4860};
    4961
Note: See TracChangeset for help on using the changeset viewer.