| 517 | } |
| 518 | |
| 519 | void NetConnection::ghostReadPacket(BitStream *bstream) |
| 520 | { |
| 521 | #ifdef TORQUE_DEBUG_NET |
| 522 | U32 sum = bstream->readInt(32); |
| 523 | AssertISV(sum == DebugChecksum, "Invalid checksum."); |
| 524 | #endif |
| 525 | |
| 526 | if(!isGhostingTo()) |
| 527 | return; |
| 528 | if(!bstream->readFlag()) |
| 529 | return; |
| 530 | |
| 531 | S32 idSize; |
| 532 | idSize = bstream->readInt( GhostIndexBitSize); |
| 533 | idSize += 3; |
| 534 | |
| 535 | // while there's an object waiting... |
| 536 | gGhostUpdates = 0; |
| 537 | |
| 538 | while(bstream->readFlag()) |
| 539 | { |
| 540 | |
| 541 | gGhostUpdates++; |
| 542 | |
| 543 | U32 index; |
| 544 | //S32 startPos = bstream->getCurPos(); |
| 545 | index = (U32) bstream->readInt(idSize); |
| 546 | if(bstream->readFlag()) // is this ghost being deleted? |
| 547 | { |
| 548 | mGhostsActive--; |
| 549 | AssertFatal(mLocalGhosts[index] != NULL, "Error, NULL ghost encountered."); |
| 550 | mLocalGhosts[index]->deleteObject(); |
| 551 | mLocalGhosts[index] = NULL; |
| 552 | } |
| 553 | else |
| 554 | { |
| 555 | if(!mLocalGhosts[index]) // it's a new ghost... cool |
| 556 | { |
| 557 | mGhostsActive++; |
| 558 | S32 classId = bstream->readClassId(NetClassTypeObject, getNetClassGroup()); |
| 559 | if(classId == -1) |
| 560 | { |
| 561 | setLastError("Invalid packet. (invalid new ghost class id)"); |
| 562 | return; |
| 563 | } |
| 564 | |
| 565 | NetObject *obj = (NetObject *) ConsoleObject::create(getNetClassGroup(), NetClassTypeObject, classId); |
| 566 | if(!obj) |
| 567 | { |
| 568 | setLastError("Invalid packet. (failed to create new ghost)"); |
| 569 | return; |
| 570 | } |
| 571 | // remove all flags associated with netobject |
| 572 | obj->mNetFlags &= ~(BIT(NetObject::MaxNetFlagBit+1)-1); |
| 573 | // we're a ghost... |
| 574 | obj->mNetFlags |= NetObject::IsGhost; |
| 575 | |
| 576 | // object gets initial update before adding to the manager |
nothing calls this directly
no test coverage detected