Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5829 in orxonox.OLD for branches/network/src/world_entities


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

network: much work on multiplayability, does not yet work

Location:
branches/network/src/world_entities
Files:
4 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
  • branches/network/src/world_entities/player.h

    r5500 r5829  
    1111#include "event_listener.h"
    1212
    13 template<class T> class tList;
     13template<class T>
     14class tList;
    1415class Weapon;
    1516class WeaponManager;
     
    2526class Player : public WorldEntity, public EventListener
    2627{
    27   friend class World;
     28    friend class World;
    2829
    2930  public:
     
    3940    void removeWeapon(Weapon* weapon);
    4041
     42    /* WorldEntity functions */
    4143    virtual void postSpawn();
    4244    virtual void leftWorld();
     
    4850    virtual void process(const Event &event);
    4951
     52    /* Synchronizeable functions */
     53    virtual void writeBytes(const byte* data, int length);
     54    virtual int readBytes(byte* data);
    5055
    5156  private:
    5257    void move(float time);
    5358    void weaponAction();
     59
     60    /* Synchronizeable functions */
     61    virtual void writeDebug() const;
     62    virtual void readDebug() const;
    5463
    5564    // !! temporary !!
     
    7079    float                 travelSpeed;        //!< the current speed of the player (to make soft movement)
    7180    float                 acceleration;       //!< the acceleration of the player.
     81
     82    byte*                 inData;
     83    int                   inLength;
     84    int                   inBufferLength;
     85    int                   recLength;
     86    byte*                 outData;
     87    int                   outLength;
     88    int                   outBufferLength;
     89    int                   sentLength;
     90
    7291};
    7392
  • branches/network/src/world_entities/world_entity.cc

    r5708 r5829  
    4141 */
    4242WorldEntity::WorldEntity(const TiXmlElement* root)
     43  : Synchronizeable()
    4344{
    4445  this->setClassID(CL_WORLD_ENTITY, "WorldEntity");
  • branches/network/src/world_entities/world_entity.h

    r5511 r5829  
    88
    99#include "p_node.h"
     10#include "synchronizeable.h"
     11#include "model.h"
    1012
    1113#include "glincl.h"
     
    2123
    2224//! Basis-class all interactive stuff in the world is derived from
    23 class WorldEntity : public PNode
     25class WorldEntity : public PNode, public Synchronizeable
    2426{
    2527 public:
Note: See TracChangeset for help on using the changeset viewer.