Changeset 5829 in orxonox.OLD for branches/network/src/world_entities
- Timestamp:
- Nov 30, 2005, 9:43:05 AM (19 years ago)
- Location:
- branches/network/src/world_entities
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/network/src/world_entities/player.cc
r5767 r5829 39 39 40 40 CREATE_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 41 50 42 51 /** … … 107 116 */ 108 117 delete this->weaponMan; 118 if( this->outData) 119 delete[] this->outData; 120 if( this->inData) 121 delete[] this->inData; 109 122 } 110 123 … … 160 173 // this->weaponMan->setSlotDirection(9, Quaternion(+M_PI, Vector(1,0,0)));: 161 174 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]; 162 183 } 163 184 … … 282 303 //orthDirection = orthDirection.cross (direction); 283 304 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 284 316 if( this->bUp && this->getRelCoor().x < 20) 317 { 285 318 accel += direction; 319 this->outData[this->outLength++] = UP; 320 } 286 321 if( this->bDown && this->getRelCoor().x > -5) 322 { 287 323 accel -= direction; 288 324 this->outData[this->outLength++] = DOWN; 325 } 289 326 if( this->bLeft && TrackManager::getInstance()->getWidth() > -this->getRelCoor().z*2) 290 327 { … … 292 329 rot +=Vector(1,0,0); 293 330 rotVal -= .4; 331 this->outData[this->outLength++] = LEFT; 294 332 } 295 333 if( this->bRight && TrackManager::getInstance()->getWidth() > this->getRelCoor().z*2) … … 298 336 rot += Vector(1,0,0); 299 337 rotVal += .4; 338 this->outData[this->outLength++] = RIGHT; 300 339 } 301 340 if (this->bAscend ) … … 311 350 rotVal -= .4; 312 351 } 352 313 353 314 354 Vector move = accel * time *acceleration; … … 322 362 this->setRelDirSoft(Quaternion(rotVal, rot), 5); 323 363 this->shiftCoor (move); 364 365 324 366 } 325 367 … … 394 436 } 395 437 } 438 439 440 441 442 /** 443 * write data to Synchronizeable 444 */ 445 void 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 */ 522 int 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 542 void Player::writeDebug() const 543 { 544 545 } 546 547 548 void Player::readDebug() const 549 { 550 551 } 552 -
branches/network/src/world_entities/player.h
r5500 r5829 11 11 #include "event_listener.h" 12 12 13 template<class T> class tList; 13 template<class T> 14 class tList; 14 15 class Weapon; 15 16 class WeaponManager; … … 25 26 class Player : public WorldEntity, public EventListener 26 27 { 27 friend class World;28 friend class World; 28 29 29 30 public: … … 39 40 void removeWeapon(Weapon* weapon); 40 41 42 /* WorldEntity functions */ 41 43 virtual void postSpawn(); 42 44 virtual void leftWorld(); … … 48 50 virtual void process(const Event &event); 49 51 52 /* Synchronizeable functions */ 53 virtual void writeBytes(const byte* data, int length); 54 virtual int readBytes(byte* data); 50 55 51 56 private: 52 57 void move(float time); 53 58 void weaponAction(); 59 60 /* Synchronizeable functions */ 61 virtual void writeDebug() const; 62 virtual void readDebug() const; 54 63 55 64 // !! temporary !! … … 70 79 float travelSpeed; //!< the current speed of the player (to make soft movement) 71 80 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 72 91 }; 73 92 -
branches/network/src/world_entities/world_entity.cc
r5708 r5829 41 41 */ 42 42 WorldEntity::WorldEntity(const TiXmlElement* root) 43 : Synchronizeable() 43 44 { 44 45 this->setClassID(CL_WORLD_ENTITY, "WorldEntity"); -
branches/network/src/world_entities/world_entity.h
r5511 r5829 8 8 9 9 #include "p_node.h" 10 #include "synchronizeable.h" 11 #include "model.h" 10 12 11 13 #include "glincl.h" … … 21 23 22 24 //! Basis-class all interactive stuff in the world is derived from 23 class WorldEntity : public PNode 25 class WorldEntity : public PNode, public Synchronizeable 24 26 { 25 27 public:
Note: See TracChangeset
for help on using the changeset viewer.