- Timestamp:
- Jan 30, 2006, 4:41:19 PM (19 years ago)
- Location:
- trunk/src
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/defs/debug.h
r6834 r6868 32 32 33 33 #include <stdio.h> 34 #include <cassert> 34 35 35 36 // DEFINE ERROR MODES -
trunk/src/lib/network/network_game_manager.cc
r6815 r6868 575 575 if ( (*it)->getUniqueID() == uniqueID ) 576 576 { 577 delete *it; 577 assert((*it)->isA(CL_WORLD_ENTITY)); 578 dynamic_cast<WorldEntity*>(*it)->toList(OM_DEAD); 578 579 break; 579 580 } -
trunk/src/lib/network/network_stream.cc
r6737 r6868 263 263 if ( reciever!=0 ) 264 264 { 265 if ( networkSockets[reciever] != NULL ) 266 { 267 PRINTF(5)("write %d bytes to socket %d\n", dataLength, reciever); 268 networkSockets[reciever]->writePacket(downBuffer, dataLength); 265 if ( reciever < 0) 266 { 267 for ( int i = 0; i<networkSockets.size(); i++) 268 { 269 if ( i!=-reciever && networkSockets[i] != NULL ) 270 { 271 PRINTF(5)("write %d bytes to socket %d\n", dataLength, i); 272 networkSockets[i]->writePacket(downBuffer, dataLength); 273 } 274 } 269 275 } 270 276 else 271 277 { 272 PRINTF(1)("networkSockets[reciever] == NULL\n"); 278 if ( networkSockets[reciever] != NULL ) 279 { 280 PRINTF(5)("write %d bytes to socket %d\n", dataLength, reciever); 281 networkSockets[reciever]->writePacket(downBuffer, dataLength); 282 } 283 else 284 { 285 PRINTF(1)("networkSockets[reciever] == NULL\n"); 286 } 273 287 } 274 288 } -
trunk/src/lib/network/synchronizeable.h
r6815 r6868 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 ); \ -
trunk/src/world_entities/playable.cc
r6804 r6868 40 40 41 41 this->bFire = false; 42 this->oldFlags = 0; 42 43 43 44 this->setSynchronized(true); … … 246 247 { 247 248 } 249 250 #define FLAGS_bFire 1 251 252 int Playable::writeSync( const byte * data, int length, int sender ) 253 { 254 SYNCHELP_READ_BEGIN(); 255 256 byte flags; 257 258 SYNCHELP_READ_BYTE( flags, NWT_PL_FLAGS ); 259 260 bFire = (flags & FLAGS_bFire) != 0; 261 262 return SYNCHELP_READ_N; 263 } 264 265 int Playable::readSync( byte * data, int maxLength ) 266 { 267 SYNCHELP_WRITE_BEGIN(); 268 byte flags = 0; 269 270 if ( bFire ) 271 flags |= FLAGS_bFire; 272 273 274 SYNCHELP_WRITE_BYTE( flags, NWT_PL_FLAGS ); 275 oldFlags = flags; 276 277 278 return SYNCHELP_WRITE_N; 279 } 280 281 bool Playable::needsReadSync( ) 282 { 283 byte flags = 0; 284 285 if ( bFire ) 286 flags |= FLAGS_bFire; 287 288 return flags!=oldFlags; 289 } -
trunk/src/world_entities/playable.h
r6804 r6868 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 }; -
trunk/src/world_entities/space_ships/space_ship.cc
r6825 r6868 95 95 else 96 96 { 97 this->loadModel("models/ships/reap_#.obj"); 97 //this->loadModel("models/ships/reap_#.obj"); 98 this->loadModel( "models/ships/fighter.obj" ); 98 99 } 99 100 … … 127 128 128 129 bUp = bDown = bLeft = bRight = bAscend = bDescend = bRollL = bRollR = false; 129 bFire = false; 130 130 131 xMouse = yMouse = 0; 131 132 yInvert = 1; … … 516 517 #define MASK_bAscend 16 517 518 #define MASK_bDescend 32 518 #define MASK_bFire 64 519 #define MASK_bRollL 128 520 #define MASK_bRollR 256 519 #define MASK_bRollL 64 520 #define MASK_bRollR 128 521 521 522 522 #define DATA_state 1 … … 525 525 #define DATA_sync 4 526 526 #define DATA_velocity 5 527 #define DATA_playables 6 527 528 528 529 int SpaceShip::writeBytes( const byte * data, int length, int sender ) … … 547 548 if ( b == DATA_flags ) 548 549 { 549 int flags = 0; 550 SYNCHELP_READ_INT( flags, NWT_SS_FLAGS ); 551 552 bUp = (flags & MASK_bUp) != 0; 553 bDown = (flags & MASK_bDown) != 0; 554 bLeft = (flags & MASK_bLeft) != 0; 555 bRight = (flags & MASK_bRight) != 0; 556 bAscend = (flags & MASK_bAscend) != 0; 557 bDescend = (flags & MASK_bDescend) != 0; 558 bFire = (flags & MASK_bFire) != 0; 559 bRollL = (flags & MASK_bRollL) != 0; 560 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 } 565 else 566 assert(false); 561 567 562 568 continue; … … 565 571 if ( b == DATA_mouse ) 566 572 { 567 SYNCHELP_READ_FLOAT( mouseDir.w, NWT_SS_MOUSEDIRW ); 568 SYNCHELP_READ_FLOAT( mouseDir.v.x, NWT_SS_MOUSEDIRX ); 569 SYNCHELP_READ_FLOAT( mouseDir.v.y, NWT_SS_MOUSEDIRY ); 570 SYNCHELP_READ_FLOAT( mouseDir.v.z, NWT_SS_MOUSEDIRZ ); 573 if ( this->getOwner() != this->getHostID() ) 574 { 575 SYNCHELP_READ_FLOAT( mouseDir.w, NWT_SS_MOUSEDIRW ); 576 SYNCHELP_READ_FLOAT( mouseDir.v.x, NWT_SS_MOUSEDIRX ); 577 SYNCHELP_READ_FLOAT( mouseDir.v.y, NWT_SS_MOUSEDIRY ); 578 SYNCHELP_READ_FLOAT( mouseDir.v.z, NWT_SS_MOUSEDIRZ ); 579 } 580 else 581 assert(false); 571 582 572 583 continue; … … 576 587 { 577 588 if ( this->getOwner() != this->getHostID() ) 589 { 578 590 SYNCHELP_READ_FKT( PNode::writeSync, NWT_SS_PN_SYNC ); 591 } 592 else 593 assert(false); 579 594 580 595 continue; … … 583 598 if ( b == DATA_velocity ) 584 599 { 585 SYNCHELP_READ_FLOAT( velocity.x, NWT_SS_VELX ); 586 SYNCHELP_READ_FLOAT( velocity.y, NWT_SS_VELY ); 587 SYNCHELP_READ_FLOAT( velocity.z, NWT_SS_VELZ ); 600 if ( this->getOwner() != this->getHostID() ) 601 { 602 SYNCHELP_READ_FLOAT( velocity.x, NWT_SS_VELX ); 603 SYNCHELP_READ_FLOAT( velocity.y, NWT_SS_VELY ); 604 SYNCHELP_READ_FLOAT( velocity.z, NWT_SS_VELZ ); 605 } 606 else 607 assert(false); 608 609 continue; 610 } 611 612 if ( b == DATA_playables ) 613 { 614 if ( this->getOwner() != this->getHostID() ) 615 { 616 SYNCHELP_READ_FKT( Playable::writeSync, NWT_SS_PL_SYNC ); 617 } 618 else 619 assert(false); 588 620 } 589 621 } … … 615 647 616 648 SYNCHELP_WRITE_FKT( WorldEntity::readState, NWT_SS_WE_STATE ); 617 //SYNCHELP_WRITE_FLOAT( cycle );618 649 619 650 return SYNCHELP_WRITE_N; 620 651 } 621 652 622 *reciever = 0; 623 624 if ( this->getOwner() == this->getHostID() && PNode::needsReadSync() ) 653 *reciever = -this->getOwner(); 654 bool sentSomething = false; 655 656 if ( ( this->getHostID()==0 || this->getOwner() == this->getHostID() ) && PNode::needsReadSync() ) 625 657 { 626 658 SYNCHELP_WRITE_BYTE( DATA_sync, NWT_SS_B ); … … 628 660 } 629 661 630 if ( this->getHostID()== this->getOwner() )631 { 632 intmask = 0;662 if ( this->getHostID()==0 || this->getHostID()==this->getOwner() ) 663 { 664 byte mask = 0; 633 665 634 666 if ( bUp ) … … 642 674 if ( bAscend ) 643 675 mask |= MASK_bAscend; 644 if ( bFire )645 mask |= MASK_bFire;646 676 if ( bRollL ) 647 677 mask |= MASK_bRollL; … … 650 680 651 681 652 //static float oldxMouse = xMouse + 1.0;653 //static float oldyMouse = yMouse + 1.0;654 655 682 if ( mask != oldMask ) 656 683 { 657 684 oldMask = mask; 685 sentSomething = true; 658 686 SYNCHELP_WRITE_BYTE( DATA_flags, NWT_SS_B ); 659 SYNCHELP_WRITE_ INT( mask, NWT_SS_FLAGS );687 SYNCHELP_WRITE_BYTE( mask, NWT_SS_FLAGS ); 660 688 } 661 689 #define __OFFSET_MDIR_W 0.01 … … 670 698 SYNCHELP_WRITE_BYTE( DATA_mouse, NWT_SS_B ); 671 699 PRINTF(0)("SENDING mousedir\n"); 700 sentSomething = true; 672 701 SYNCHELP_WRITE_FLOAT( mouseDir.w, NWT_SS_MOUSEDIRW ); 673 702 SYNCHELP_WRITE_FLOAT( mouseDir.v.x, NWT_SS_MOUSEDIRX ); … … 681 710 { 682 711 oldVelocity = velocity; 683 PRINTF(0)("SENDING velocity\n"); 684 SYNCHELP_WRITE_BYTE( DATA_velocity, NWT_SS_B ); 685 SYNCHELP_WRITE_FLOAT( velocity.x, NWT_SS_VELX ); 686 SYNCHELP_WRITE_FLOAT( velocity.y, NWT_SS_VELY ); 687 SYNCHELP_WRITE_FLOAT( velocity.z, NWT_SS_VELZ ); 688 } 689 690 } 712 //PRINTF(0)("SENDING velocity\n"); 713 //SYNCHELP_WRITE_BYTE( DATA_velocity, NWT_SS_B ); 714 //SYNCHELP_WRITE_FLOAT( velocity.x, NWT_SS_VELX ); 715 //SYNCHELP_WRITE_FLOAT( velocity.y, NWT_SS_VELY ); 716 //SYNCHELP_WRITE_FLOAT( velocity.z, NWT_SS_VELZ ); 717 } 718 719 if ( Playable::needsReadSync() ) 720 { 721 sentSomething = true; 722 SYNCHELP_WRITE_BYTE( DATA_playables, NWT_SS_B ); 723 SYNCHELP_WRITE_FKT( Playable::readSync, NWT_SS_PL_SYNC ); 724 } 725 726 } 727 728 if ( !sentSomething ) 729 reciever = 0; 691 730 692 731 return SYNCHELP_WRITE_N; -
trunk/src/world_entities/space_ships/space_ship.h
r6815 r6868 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.