- Timestamp:
- Jan 30, 2006, 10:24:20 AM (19 years ago)
- Location:
- branches/network/src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/network/src/lib/network/synchronizeable.h
r6815 r6861 33 33 NWT_SS_VELY, 34 34 NWT_SS_VELZ, 35 NWT_SS_PL_SYNC, 35 36 36 37 NWT_HS_HOST_ID, 37 38 NWT_HS_NGM_ID, 39 40 NWT_PL_FLAGS, 38 41 39 42 NWT_PN_BO_WRITESTATE, … … 101 104 * with the same argument names! 102 105 * 106 * id is one int out of that enum on top of this comment it is used to identify 107 * read/write. when you read a value you have to use exactly the same as you used 108 * to write or you will see an assertion failing. 109 * 103 110 * SYNCHELP_WRITE_BEGIN() 104 * SYNCHELP_WRITE_INT(i )105 * SYNCHELP_WRITE_FLOAT(f )106 * SYNCHELP_WRITE_BYTE(b )107 * SYNCHELP_WRITE_STRING(s )111 * SYNCHELP_WRITE_INT(i,id) 112 * SYNCHELP_WRITE_FLOAT(f,id) 113 * SYNCHELP_WRITE_BYTE(b,id) 114 * SYNCHELP_WRITE_STRING(s,id) 108 115 * SYNCHELP_WRITE_N 109 116 * 110 117 * SYNCHELP_READ_BEGIN() 111 * SYNCHELP_READ_INT(i) 112 * SYNCHELP_READ_FLOAT(f) 113 * SYNCHELP_READ_STRING(s,l) l = size of buffer s 114 * SYNCHELP_READ_STRINGM(s) allocates memory for string! you have to free this after 115 * SYNCHELP_READ_BYTE(b) 118 * SYNCHELP_READ_INT(i,id) 119 * SYNCHELP_READ_FLOAT(f,id) 120 * SYNCHELP_READ_STRING(s,l,id) l = size of buffer s 121 * SYNCHELP_READ_STRINGM(s,id) allocates memory for string! you have to delete this later 122 * SYNCHELP_READ_BYTE(b,id) 123 * SYNCHELP_READ_REMAINING() returns the remaining buffer size 124 * SYNCHELP_READ_NEXTBYTE() reads the next byte but it is not removed from the buffer 116 125 * SYNCHELP_READ_N 117 126 * … … 122 131 * SYNCHELP_READ_FLOAT(size); 123 132 * SYNCHELP_READ_STRING( textureName, 1024 ); //1024 is the length of textureName 133 * delete[] textureName; 134 * textureName = NULL; 135 * SYNCHELP_READ_STRINGM( texturename ); //this will call new char[strlen()+1] 124 136 * 125 137 * Example 2: … … 130 142 * 131 143 */ 144 132 145 #define SYNCHELP_WRITE_DEBUG(n) {\ 133 146 __synchelp_write_n = Converter::intToByteArray( n, data+__synchelp_write_i, maxLength-__synchelp_write_i ); \ -
branches/network/src/world_entities/playable.cc
r6804 r6861 246 246 { 247 247 } 248 249 #define FLAGS_bFire 1 250 251 int Playable::writeSync( const byte * data, int length, int sender ) 252 { 253 SYNCHELP_READ_BEGIN(); 254 255 byte flags; 256 257 SYNCHELP_READ_BYTE( flags, NWT_PL_FLAGS ); 258 259 bFire = (flags & FLAGS_bFire) != 0; 260 261 return SYNCHELP_READ_N; 262 } 263 264 int Playable::readSync( byte * data, int maxLength ) 265 { 266 SYNCHELP_WRITE_BEGIN(); 267 byte flags = 0; 268 269 if ( bFire ) 270 flags |= FLAGS_bFire; 271 272 273 SYNCHELP_WRITE_BYTE( flags, NWT_PL_FLAGS ); 274 oldFlags = flags; 275 276 277 return SYNCHELP_WRITE_N; 278 } 279 280 bool Playable::needsReadSync( ) 281 { 282 byte flags = 0; 283 284 if ( bFire ) 285 flags |= FLAGS_bFire; 286 287 return flags!=oldFlags; 288 } -
branches/network/src/world_entities/playable.h
r6804 r6861 54 54 /** @return a List of Events in PEV_* sytle */ 55 55 inline const std::list<int>& getEventList() { return this->events; }; 56 57 int writeSync(const byte* data, int length, int sender); 58 int readSync(byte* data, int maxLength ); 59 bool needsReadSync(); 56 60 57 61 protected: … … 68 72 69 73 bool bFire; //!< If the Ship is firing. 74 int oldFlags; //!< Used for synchronisation 70 75 71 76 }; -
branches/network/src/world_entities/space_ships/space_ship.cc
r6820 r6861 128 128 129 129 bUp = bDown = bLeft = bRight = bAscend = bDescend = bRollL = bRollR = false; 130 bFire = false; 130 131 131 xMouse = yMouse = 0; 132 132 yInvert = 1; … … 517 517 #define MASK_bAscend 16 518 518 #define MASK_bDescend 32 519 #define MASK_bFire 64 520 #define MASK_bRollL 128 521 #define MASK_bRollR 256 519 #define MASK_bRollL 64 520 #define MASK_bRollR 128 522 521 523 522 #define DATA_state 1 … … 526 525 #define DATA_sync 4 527 526 #define DATA_velocity 5 527 #define DATA_playables 6 528 528 529 529 int SpaceShip::writeBytes( const byte * data, int length, int sender ) … … 548 548 if ( b == DATA_flags ) 549 549 { 550 int flags = 0; 551 SYNCHELP_READ_INT( flags, NWT_SS_FLAGS ); 552 553 bUp = (flags & MASK_bUp) != 0; 554 bDown = (flags & MASK_bDown) != 0; 555 bLeft = (flags & MASK_bLeft) != 0; 556 bRight = (flags & MASK_bRight) != 0; 557 bAscend = (flags & MASK_bAscend) != 0; 558 bDescend = (flags & MASK_bDescend) != 0; 559 bFire = (flags & MASK_bFire) != 0; 560 bRollL = (flags & MASK_bRollL) != 0; 561 bRollR = (flags & MASK_bRollR) != 0; 550 if ( this->getOwner() != this->getHostID() ) 551 { 552 byte flags = 0; 553 SYNCHELP_READ_BYTE( flags, NWT_SS_FLAGS ); 554 555 bUp = (flags & MASK_bUp) != 0; 556 bDown = (flags & MASK_bDown) != 0; 557 bLeft = (flags & MASK_bLeft) != 0; 558 bRight = (flags & MASK_bRight) != 0; 559 bAscend = (flags & MASK_bAscend) != 0; 560 bDescend = (flags & MASK_bDescend) != 0; 561 bRollL = (flags & MASK_bRollL) != 0; 562 bRollR = (flags & MASK_bRollR) != 0; 563 564 } 562 565 563 566 continue; … … 566 569 if ( b == DATA_mouse ) 567 570 { 568 SYNCHELP_READ_FLOAT( mouseDir.w, NWT_SS_MOUSEDIRW ); 569 SYNCHELP_READ_FLOAT( mouseDir.v.x, NWT_SS_MOUSEDIRX ); 570 SYNCHELP_READ_FLOAT( mouseDir.v.y, NWT_SS_MOUSEDIRY ); 571 SYNCHELP_READ_FLOAT( mouseDir.v.z, NWT_SS_MOUSEDIRZ ); 571 if ( this->getOwner() != this->getHostID() ) 572 { 573 SYNCHELP_READ_FLOAT( mouseDir.w, NWT_SS_MOUSEDIRW ); 574 SYNCHELP_READ_FLOAT( mouseDir.v.x, NWT_SS_MOUSEDIRX ); 575 SYNCHELP_READ_FLOAT( mouseDir.v.y, NWT_SS_MOUSEDIRY ); 576 SYNCHELP_READ_FLOAT( mouseDir.v.z, NWT_SS_MOUSEDIRZ ); 577 } 572 578 573 579 continue; … … 584 590 if ( b == DATA_velocity ) 585 591 { 586 SYNCHELP_READ_FLOAT( velocity.x, NWT_SS_VELX ); 587 SYNCHELP_READ_FLOAT( velocity.y, NWT_SS_VELY ); 588 SYNCHELP_READ_FLOAT( velocity.z, NWT_SS_VELZ ); 592 if ( this->getOwner() != this->getHostID() ) 593 { 594 SYNCHELP_READ_FLOAT( velocity.x, NWT_SS_VELX ); 595 SYNCHELP_READ_FLOAT( velocity.y, NWT_SS_VELY ); 596 SYNCHELP_READ_FLOAT( velocity.z, NWT_SS_VELZ ); 597 } 598 599 continue; 600 } 601 602 if ( b == DATA_playables ) 603 { 604 if ( this->getOwner() != this->getHostID() ) 605 SYNCHELP_READ_FKT( Playable::writeSync, NWT_SS_PL_SYNC ); 589 606 } 590 607 } … … 616 633 617 634 SYNCHELP_WRITE_FKT( WorldEntity::readState, NWT_SS_WE_STATE ); 618 //SYNCHELP_WRITE_FLOAT( cycle );619 635 620 636 return SYNCHELP_WRITE_N; … … 631 647 if ( this->getHostID()==this->getOwner() ) 632 648 { 633 intmask = 0;649 byte mask = 0; 634 650 635 651 if ( bUp ) … … 643 659 if ( bAscend ) 644 660 mask |= MASK_bAscend; 645 if ( bFire )646 mask |= MASK_bFire;647 661 if ( bRollL ) 648 662 mask |= MASK_bRollL; … … 651 665 652 666 653 //static float oldxMouse = xMouse + 1.0;654 //static float oldyMouse = yMouse + 1.0;655 656 667 if ( mask != oldMask ) 657 668 { 658 669 oldMask = mask; 659 670 SYNCHELP_WRITE_BYTE( DATA_flags, NWT_SS_B ); 660 SYNCHELP_WRITE_ INT( mask, NWT_SS_FLAGS );671 SYNCHELP_WRITE_BYTE( mask, NWT_SS_FLAGS ); 661 672 } 662 673 #define __OFFSET_MDIR_W 0.01 … … 688 699 SYNCHELP_WRITE_FLOAT( velocity.z, NWT_SS_VELZ ); 689 700 } 701 702 if ( Playable::needsReadSync() ) 703 { 704 SYNCHELP_WRITE_BYTE( DATA_playables, NWT_SS_B ); 705 SYNCHELP_WRITE_FKT( Playable::readSync, NWT_SS_PL_SYNC ); 706 } 690 707 691 708 } -
branches/network/src/world_entities/space_ships/space_ship.h
r6815 r6861 56 56 bool bAscend; //!< ascend button pressed. 57 57 bool bDescend; //!< descend button presses. 58 bool bFire; //!< fire button pressed. 58 // bool bFire; //!< fire button pressed.(moved to playable) 59 59 bool bRollL; //!< rolling button pressed (left) 60 60 bool bRollR; //!< rolling button pressed (right) … … 80 80 float airViscosity; 81 81 82 int oldMask;82 byte oldMask; //!< used for synchronisation 83 83 84 84 ParticleEmitter* burstEmitter;
Note: See TracChangeset
for help on using the changeset viewer.