Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 25, 2008, 7:56:40 PM (16 years ago)
Author:
scheusso
Message:

use the new media path now

Location:
code/branches/objecthierarchy/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • code/branches/objecthierarchy/src/network/Synchronisable.cc

    r1990 r2011  
    4242
    4343#include <cstring>
     44#include <string>
    4445#include <iostream>
    4546#include <assert.h>
     
    198199  */
    199200  void Synchronisable::registerVar(void *var, int size, variableType t, int mode, NetworkCallbackBase *cb){
     201    assert( mode==direction::toclient || mode==direction::toserver || mode==direction::serverMaster || mode==direction::clientMaster);
    200202    // create temporary synch.Var struct
    201203    synchronisableVariable *temp = new synchronisableVariable;
     
    205207    temp->type = t;
    206208    temp->callback = cb;
     209    if( ( mode & direction::bidirectional ) )
     210    {
     211      temp->varBuffer = new uint8_t[size];
     212      memcpy(temp->varBuffer, temp->var, size); //now fill the buffer for the first time
     213      temp->varReference = 0;
     214    }
    207215    COUT(5) << "Syncronisable::registering var with size: " << temp->size << " and type: " << temp->type << std::endl;
    208216    //std::cout << "push temp to syncList (at the bottom) " << datasize << std::endl;
     
    270278        continue;  // this variable should only be received
    271279      }
     280      // if the variable gets synchronised bidirectional, then add the reference to the bytestream
     281      if( ( (*i)->mode & direction::bidirectional ) )
     282      {
     283        *(uint8_t*)mem = (*i)->varReference;
     284        mem += sizeof( (*i)->varReference );
     285      }
    272286      switch((*i)->type){
    273287        case DATA:
    274288          memcpy( (void *)(mem), (void*)((*i)->var), (*i)->size);
    275289          mem+=(*i)->size;
    276           tempsize+=(*i)->size;
     290          tempsize+=(*i)->size + sizeof( (*i)->varReference );
    277291          break;
    278292        case STRING:
    279           memcpy( (void *)(mem), (void *)&((*i)->size), sizeof(int) );
    280           mem+=sizeof(int);
     293          memcpy( (void *)(mem), (void *)&((*i)->size), sizeof(size_t) );
     294          mem+=sizeof(size_t);
    281295          const char *data = ( ( *(std::string *) (*i)->var).c_str());
    282296          memcpy( mem, (void*)data, (*i)->size);
    283297          COUT(5) << "synchronisable: char: " << (const char *)(mem) << " data: " << data << " string: " << *(std::string *)((*i)->var) << std::endl;
    284298          mem+=(*i)->size;
    285           tempsize+=(*i)->size + 4;
     299          tempsize+=(*i)->size + sizeof( (*i)->varReference ) + sizeof(size_t);
    286300          break;
    287301      }
     
    331345      switch((*i)->type){
    332346        case DATA:
     347          if( ( (*i)->mode & direction::bidirectional ) )
     348          {
     349            if( ( mode == 0x1 && (*i)->mode == direction::serverMaster ) || \
     350                  ( mode == 0x2 && (*i)->mode == direction::clientMaster ) )    // if true we are master on this variable
     351            {
     352              uint8_t refNr = *(uint8_t *)mem;
     353              if( refNr != (*i)->varReference )
     354              {
     355                mem += sizeof((*i)->varReference) + (*i)->size; // the reference for this variable is not recent, discard data
     356                break;
     357              }
     358            }
     359            else //we are slave for this variable
     360            {
     361              (*i)->varReference = *(uint8_t *)mem; //copy the reference value for this variable
     362            }
     363            mem += sizeof((*i)->varReference);
     364          }
    333365          if((*i)->callback) // check whether this variable changed (but only if callback was set)
    334366            if(strncmp((char *)(*i)->var, (char *)mem, (*i)->size)!=0)
     
    338370          break;
    339371        case STRING:
    340           (*i)->size = *(uint32_t *)mem;
     372          if( ( (*i)->mode & direction::bidirectional ) )
     373          {
     374            if( ( mode == 0x1 && (*i)->mode == direction::serverMaster ) || \
     375                  ( mode == 0x2 && (*i)->mode == direction::clientMaster ) )    // if true we are master for this variable
     376            {
     377              uint8_t refNr = *(uint8_t *)mem;
     378              mem += sizeof( (*i)->varReference );
     379              if( refNr != (*i)->varReference ){
     380                mem += sizeof(size_t) + *(size_t *)mem; // the reference for this variable is not recent, discard data
     381                break;
     382              }
     383            }
     384            else //we are slave for this variable
     385            {
     386              (*i)->varReference = *(uint8_t *)mem; //copy the reference value for this variable
     387            }
     388            mem += sizeof( (*i)->varReference );
     389          }
     390          (*i)->size = *(size_t *)mem;
    341391          COUT(5) << "string size: " << (*i)->size << std::endl;
    342           mem+=sizeof(int);
     392          mem += sizeof(size_t);
    343393          if((*i)->callback) // check whether this string changed
    344394            if( *(std::string *)((*i)->var) != std::string((char *)mem) )
     
    383433        break;
    384434      }
     435      if( ( (*i)->mode & direction::bidirectional ) != 0)
     436      {
     437        tsize+=sizeof( (*i)->varReference );
     438      }
    385439    }
    386440    return tsize;
  • code/branches/objecthierarchy/src/network/Synchronisable.h

    r1990 r2011  
    5454      toclient=0x1,
    5555      toserver=0x2,
    56       bidirectional=0x3
     56      bidirectional=0x3,
     57      serverMaster=0x3,
     58      clientMaster=0x7
    5759    };
    5860  }
     
    7779  };
    7880
    79   typedef struct _NetworkExport synchronisableVariable{
     81  struct _NetworkExport synchronisableVariable{
    8082    unsigned int size;
    8183    int mode; // this determines in which direction the variable gets synchronised
     
    8385    variableType type;
    8486    NetworkCallbackBase *callback;
    85   }SYNCVAR;
     87    void *varBuffer;
     88    uint8_t varReference;
     89  };
    8690
    8791  /**
  • code/branches/objecthierarchy/src/orxonox/Settings.cc

    r1949 r2011  
    6262    void Settings::setConfigValues()
    6363    {
    64         SetConfigValue(dataPath_, "../../Media/").description("Relative path to the game data.").callback(this, &Settings::dataPathChanged);
     64        SetConfigValue(dataPath_, "../../media/").description("Relative path to the game data.").callback(this, &Settings::dataPathChanged);
    6565    }
    6666
Note: See TracChangeset for help on using the changeset viewer.