Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 30, 2005, 9:43:05 AM (19 years ago)
Author:
patrick
Message:

network: much work on multiplayability, does not yet work

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/network/src/world_entities/player.cc

    r5767 r5829  
    3939
    4040CREATE_FACTORY(Player, CL_PLAYER);
     41
     42
     43
     44#define UP    0
     45#define DOWN  1
     46#define RIGHT 2
     47#define LEFT  3
     48#define TIME  4
     49
    4150
    4251/**
     
    107116  */
    108117  delete this->weaponMan;
     118  if( this->outData)
     119    delete[] this->outData;
     120  if( this->inData)
     121    delete[] this->inData;
    109122}
    110123
     
    160173//   this->weaponMan->setSlotDirection(9, Quaternion(+M_PI, Vector(1,0,0)));:
    161174
     175  this->outBufferLength = 100;
     176  this->outLength = 0;
     177  this->recLength = 0;
     178  this->inBufferLength = 100;
     179  this->inLength = 0;
     180  this->sentLength = 0;
     181  this->outData = new byte[this->outBufferLength];
     182  this->inData = new byte[this->inBufferLength];
    162183}
    163184
     
    282303  //orthDirection = orthDirection.cross (direction);
    283304
     305
     306  if( this->outLength >= this->outBufferLength) return;
     307
     308  if( this->bUp || this->bDown || this->bRight || this->bLeft)
     309  {
     310    this->outData[this->outLength++] = TIME;
     311    this->outData[this->outLength++] = (byte)(lround(time * 100.0f));
     312
     313    PRINTF(0)("Writing TIME = %i, or %f\n", this->outData[this->outLength-1], time);
     314  }
     315
    284316  if( this->bUp && this->getRelCoor().x < 20)
     317  {
    285318    accel += direction;
     319    this->outData[this->outLength++] = UP;
     320  }
    286321  if( this->bDown && this->getRelCoor().x > -5)
     322  {
    287323    accel -= direction;
    288 
     324    this->outData[this->outLength++] = DOWN;
     325  }
    289326  if( this->bLeft && TrackManager::getInstance()->getWidth() > -this->getRelCoor().z*2)
    290327  {
     
    292329    rot +=Vector(1,0,0);
    293330    rotVal -= .4;
     331    this->outData[this->outLength++] = LEFT;
    294332  }
    295333  if( this->bRight && TrackManager::getInstance()->getWidth() > this->getRelCoor().z*2)
     
    298336    rot += Vector(1,0,0);
    299337    rotVal += .4;
     338    this->outData[this->outLength++] = RIGHT;
    300339  }
    301340  if (this->bAscend )
     
    311350    rotVal -= .4;
    312351  }
     352
    313353
    314354  Vector move = accel * time *acceleration;
     
    322362  this->setRelDirSoft(Quaternion(rotVal, rot), 5);
    323363  this->shiftCoor (move);
     364
     365
    324366}
    325367
     
    394436  }
    395437}
     438
     439
     440
     441
     442/**
     443 *  write data to Synchronizeable
     444 */
     445void Player::writeBytes(const byte* data, int length)
     446{
     447  PRINTF(0)("Player: got %i bytes of data\n", length);
     448  this->inLength = length;
     449
     450  /*
     451   bytes:  | 0  |  1  |
     452           CODE  DIST
     453
     454
     455  CODE:
     456       0 :   Up
     457       1 :   Down
     458       2 :   Right
     459       3 :   Left
     460       4 :   TIME
     461
     462  DIST:
     463      Coordinate diff multiplied by 100 and casted to a byte: byte a = (byte)(x * 100)
     464
     465  */
     466
     467  float time = 0.0f;
     468
     469  Vector accel(0.0, 0.0, 0.0);
     470  Vector direction (1.0, 0.0, 0.0);
     471  Vector orthDirection (0.0, 0.0, 1.0);
     472
     473  byte code = 0;
     474
     475  /* iterate through all bytes */
     476  for( int i = 0; i < length; i++)
     477  {
     478    code = data[i];
     479
     480    /* is it a time code? */
     481    if( code == TIME)
     482    {
     483      /* is it the first time */
     484      if( time > 0.0f )
     485      {
     486        /* apply movement */
     487        Vector move = accel * time;
     488
     489        if (accel.z < 0)
     490          this->setRelDirSoft(Quaternion(-.4, Vector(1,0,0)), 5);
     491        else if (accel.z > 0)
     492          this->setRelDirSoft(Quaternion(.4, Vector(1,0,0)), 5);
     493        else
     494          this->setRelDirSoft(Quaternion(0, Vector(1,0,0)), 5);
     495        this->shiftCoor (move);
     496      }
     497      /* read out new movement */
     498      time = (float)(data[++i] / 100.0f);
     499      PRINTF(0)("Got time: %f msec\n", time);
     500    }
     501    else if( code == UP && this->getRelCoor().x < 20)
     502      accel = accel+(direction*acceleration);
     503    else if( code == DOWN && this->getRelCoor().x > -5)
     504      accel = accel -(direction*acceleration);
     505    else if( code == LEFT && TrackManager::getInstance()->getWidth() > -this->getRelCoor().z*2)
     506      accel = accel - (orthDirection*acceleration);
     507    else if( code == RIGHT && TrackManager::getInstance()->getWidth() > this->getRelCoor().z*2)
     508      accel = accel + (orthDirection*acceleration);
     509  }
     510
     511
     512
     513
     514  /* and debug output */
     515  this->writeDebug();
     516}
     517
     518
     519/**
     520 *  read data from Synchronizeable
     521 */
     522int Player::readBytes(byte* data)
     523{
     524  PRINTF(0)("Player: sent %i bytes of data\n", this->sentLength);
     525
     526  /* copy data */
     527  for( int i = 0; i < this->outLength; ++i)
     528    data[i] = this->outData[i];
     529
     530
     531
     532  /* debug msg */
     533  this->readDebug();
     534
     535  int length = this->outLength;
     536  this->outLength = 0;
     537  /* return the length of the test */
     538  return length;
     539}
     540
     541
     542void Player::writeDebug() const
     543{
     544
     545}
     546
     547
     548void Player::readDebug() const
     549{
     550
     551}
     552
Note: See TracChangeset for help on using the changeset viewer.