[Opentnl-cvs] tnl/zap ZAP.vcproj,1.16,1.17 gameConnection.cpp,1.11,1.12 gameConnection.h,1.9,1.10 ga
Brought to you by:
mark_frohnmayer,
s_alanet
Update of /cvsroot/opentnl/tnl/zap In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22462/zap Modified Files: ZAP.vcproj gameConnection.cpp gameConnection.h gameObject.cpp gameObject.h item.cpp main.cpp projectile.cpp projectile.h ship.cpp Log Message: Fixed bug in connection string table causing strings to never be sent in compressed form Added bandwidth usage logging per net class Substantially reduced object update size in Zap Index: main.cpp =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/main.cpp,v retrieving revision 1.28 retrieving revision 1.29 diff -C2 -d -r1.28 -r1.29 *** main.cpp 12 May 2004 01:38:00 -0000 1.28 --- main.cpp 12 May 2004 19:35:12 -0000 1.29 *************** *** 351,354 **** --- 351,355 ---- endGame(); SFXObject::shutdown(); + NetClassRep::logBitUsage(); } *************** *** 500,504 **** glTranslatef(400, 300, 0); ! atexit(endGame); glutMainLoop(); --- 501,505 ---- glTranslatef(400, 300, 0); ! atexit(onExit); glutMainLoop(); Index: projectile.cpp =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/projectile.cpp,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** projectile.cpp 5 May 2004 09:50:35 -0000 1.9 --- projectile.cpp 12 May 2004 19:35:12 -0000 1.10 *************** *** 51,58 **** U32 Projectile::packUpdate(GhostConnection *connection, U32 updateMask, BitStream *stream) { ! stream->write(pos.x); ! stream->write(pos.y); ! stream->write(velocity.x); ! stream->write(velocity.y); S32 index = -1; if(mShooter.isValid()) --- 51,57 ---- U32 Projectile::packUpdate(GhostConnection *connection, U32 updateMask, BitStream *stream) { ! ((GameConnection *) connection)->writeCompressedPoint(pos, stream); ! writeCompressedVelocity(velocity, CompressedVelocityMax, stream); ! S32 index = -1; if(mShooter.isValid()) *************** *** 66,73 **** void Projectile::unpackUpdate(GhostConnection *connection, BitStream *stream) { ! stream->read(&pos.x); ! stream->read(&pos.y); ! stream->read(&velocity.x); ! stream->read(&velocity.y); if(stream->readFlag()) --- 65,70 ---- void Projectile::unpackUpdate(GhostConnection *connection, BitStream *stream) { ! ((GameConnection *) connection)->readCompressedPoint(pos, stream); ! readCompressedVelocity(velocity, CompressedVelocityMax, stream); if(stream->readFlag()) Index: gameConnection.cpp =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/gameConnection.cpp,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** gameConnection.cpp 11 May 2004 18:26:25 -0000 1.11 --- gameConnection.cpp 12 May 2004 19:35:12 -0000 1.12 *************** *** 78,81 **** --- 78,82 ---- for(; firstMoveIndex < ((GamePacketNotify *) notify)->firstUnsentMoveIndex; firstMoveIndex++) pendingMoves.erase(U32(0)); + mServerPosition = ((GamePacketNotify *) notify)->lastControlObjectPosition; Parent::packetReceived(notify); } *************** *** 127,130 **** --- 128,134 ---- } ((GamePacketNotify *) notify)->firstUnsentMoveIndex = firstMoveIndex + pendingMoves.size(); + if(controlObject.isValid()) + ((GamePacketNotify *) notify)->lastControlObjectPosition = controlObject->getActualPos(); + highSendIndex[0] = highSendIndex[1]; highSendIndex[1] = highSendIndex[2]; *************** *** 133,142 **** else { if(bstream->writeFlag(getControlCRC() != mLastClientControlCRC)) { ! S32 ghostIndex = -1; ! if(controlObject.isValid()) ! ghostIndex = getGhostIndex(controlObject); ! if(bstream->writeFlag(ghostIndex != -1)) { bstream->writeInt(ghostIndex, GhostConnection::GhostIdBitSize); --- 137,154 ---- else { + S32 ghostIndex = -1; + if(controlObject.isValid()) + { + ghostIndex = getGhostIndex(controlObject); + mServerPosition = controlObject->getActualPos(); + } + + // we only compress points relative if we know that the + // remote side has a copy of the control object already + mCompressPointsRelative = bstream->writeFlag(ghostIndex != -1); + if(bstream->writeFlag(getControlCRC() != mLastClientControlCRC)) { ! if(ghostIndex != -1) { bstream->writeInt(ghostIndex, GhostConnection::GhostIdBitSize); *************** *** 176,190 **** else { if(bstream->readFlag()) { ! if(bstream->readFlag()) { U32 ghostIndex = bstream->readInt(GhostConnection::GhostIdBitSize); controlObject = (GameObject *) resolveGhost(ghostIndex); controlObject->readControlState(bstream); for(S32 i = 0; i < pendingMoves.size(); i++) - { controlObject->processClientMove(&pendingMoves[i], true); - } } else --- 188,207 ---- else { + bool controlObjectValid = bstream->readFlag(); + + mCompressPointsRelative = controlObjectValid; + + // CRC mismatch... if(bstream->readFlag()) { ! if(controlObjectValid) { U32 ghostIndex = bstream->readInt(GhostConnection::GhostIdBitSize); controlObject = (GameObject *) resolveGhost(ghostIndex); controlObject->readControlState(bstream); + mServerPosition = controlObject->getActualPos(); + for(S32 i = 0; i < pendingMoves.size(); i++) controlObject->processClientMove(&pendingMoves[i], true); } else *************** *** 195,198 **** --- 212,269 ---- } + void GameConnection::writeCompressedPoint(Point &p, BitStream *stream) + { + if(!mCompressPointsRelative) + { + stream->write(p.x); + stream->write(p.y); + return; + } + + Point delta = p - mServerPosition; + S32 dx = S32(delta.x + Game::PlayerHorizScopeDistance); + S32 dy = S32(delta.y + Game::PlayerVertScopeDistance); + + U32 maxx = Game::PlayerHorizScopeDistance * 2; + U32 maxy = Game::PlayerVertScopeDistance * 2; + + if(stream->writeFlag(dx >= 0 && dx <= maxx && dy >= 0 && dy <= maxy)) + { + stream->writeRangedU32(dx, 0, maxx); + stream->writeRangedU32(dy, 0, maxy); + } + else + { + stream->write(p.x); + stream->write(p.y); + } + } + + void GameConnection::readCompressedPoint(Point &p, BitStream *stream) + { + if(!mCompressPointsRelative) + { + stream->read(&p.x); + stream->read(&p.y); + return; + } + if(stream->readFlag()) + { + U32 maxx = Game::PlayerHorizScopeDistance * 2; + U32 maxy = Game::PlayerVertScopeDistance * 2; + + S32 dx = S32(stream->readRangedU32(0, maxx)) - Game::PlayerHorizScopeDistance; + S32 dy = S32(stream->readRangedU32(0, maxy)) - Game::PlayerVertScopeDistance; + + Point delta(dx, dy); + p = mServerPosition + delta; + } + else + { + stream->read(&p.x); + stream->read(&p.y); + } + } + void GameConnection::writeConnectRequest(BitStream *stream) { Index: gameObject.cpp =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/gameObject.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** gameObject.cpp 23 Apr 2004 01:49:46 -0000 1.2 --- gameObject.cpp 12 May 2004 19:35:12 -0000 1.3 *************** *** 209,212 **** --- 209,251 ---- } + void GameObject::writeCompressedVelocity(Point &vel, U32 max, BitStream *stream) + { + F32 len = vel.len(); + if(stream->writeFlag(len == 0)) + return; + + if(stream->writeFlag(len > max)) + { + stream->write(vel.x); + stream->write(vel.y); + } + else + { + F32 theta = atan2(vel.x, vel.y); + stream->writeFloat(theta * FloatInverse2Pi, 10); + stream->writeRangedU32(len, 0, max); + } + } + + void GameObject::readCompressedVelocity(Point &vel, U32 max, BitStream *stream) + { + if(stream->readFlag()) + { + vel.x = vel.y = 0; + return; + } + else if(stream->readFlag()) + { + stream->read(&vel.x); + stream->read(&vel.y); + } + else + { + F32 theta = stream->readFloat(10) * Float2Pi; + F32 magnitude = stream->readRangedU32(0, max); + vel.set(sin(theta) * magnitude, cos(theta) * magnitude); + } + } + void GameObject::processArguments(S32 argc, const char**argv) { Index: ZAP.vcproj =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/ZAP.vcproj,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** ZAP.vcproj 12 May 2004 01:38:00 -0000 1.16 --- ZAP.vcproj 12 May 2004 19:35:11 -0000 1.17 *************** *** 88,92 **** LinkIncremental="1" GenerateDebugInformation="TRUE" ! SubSystem="2" OptimizeReferences="2" EnableCOMDATFolding="2" --- 88,92 ---- LinkIncremental="1" GenerateDebugInformation="TRUE" ! SubSystem="1" OptimizeReferences="2" EnableCOMDATFolding="2" Index: projectile.h =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/projectile.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** projectile.h 23 Apr 2004 01:49:46 -0000 1.3 --- projectile.h 12 May 2004 19:35:12 -0000 1.4 *************** *** 38,41 **** --- 38,45 ---- { public: + enum { + CompressedVelocityMax = 2047, + }; + Point pos; Point velocity; Index: gameConnection.h =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/gameConnection.h,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** gameConnection.h 12 May 2004 02:54:46 -0000 1.9 --- gameConnection.h 12 May 2004 19:35:12 -0000 1.10 *************** *** 31,34 **** --- 31,36 ---- #include "../tnl/tnlGhostConnection.h" + #include "point.h" + using namespace TNL; // some angle conversion functions: *************** *** 169,172 **** --- 171,176 ---- StringTableEntry playerName; U32 mLastClientControlCRC; + Point mServerPosition; + bool mCompressPointsRelative; U32 firstMoveIndex; *************** *** 198,201 **** --- 202,206 ---- { U32 firstUnsentMoveIndex; + Point lastControlObjectPosition; GamePacketNotify() { firstUnsentMoveIndex = 0; } }; *************** *** 219,222 **** --- 224,230 ---- void onConnectionTerminated(const char *reason); + void writeCompressedPoint(Point &p, BitStream *stream); + void readCompressedPoint(Point &p, BitStream *stream); + void onConnectTimedOut(); Index: gameObject.h =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/gameObject.h,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** gameObject.h 3 May 2004 22:06:16 -0000 1.5 --- gameObject.h 12 May 2004 19:35:12 -0000 1.6 *************** *** 112,115 **** --- 112,118 ---- virtual void readControlState(BitStream *stream); + void writeCompressedVelocity(Point &vel, U32 max, BitStream *stream); + void readCompressedVelocity(Point &vel, U32 max, BitStream *stream); + virtual Point getRenderPos(); virtual Point getActualPos(); Index: item.cpp =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/item.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** item.cpp 30 Apr 2004 20:27:41 -0000 1.6 --- item.cpp 12 May 2004 19:35:12 -0000 1.7 *************** *** 168,175 **** if(stream->writeFlag(updateMask & PositionMask)) { ! stream->write(mMoveState[RenderState].pos.x); ! stream->write(mMoveState[RenderState].pos.y); ! stream->write(mMoveState[RenderState].vel.x); ! stream->write(mMoveState[RenderState].vel.y); stream->writeFlag(updateMask & WarpPositionMask); } --- 168,173 ---- if(stream->writeFlag(updateMask & PositionMask)) { ! ((GameConnection *) connection)->writeCompressedPoint(mMoveState[RenderState].pos, stream); ! writeCompressedVelocity(mMoveState[RenderState].vel, 511, stream); stream->writeFlag(updateMask & WarpPositionMask); } *************** *** 196,203 **** if(stream->readFlag()) { ! stream->read(&mMoveState[ActualState].pos.x); ! stream->read(&mMoveState[ActualState].pos.y); ! stream->read(&mMoveState[ActualState].vel.x); ! stream->read(&mMoveState[ActualState].vel.y); //posSegments.push_back(mMoveState[ActualState].pos); positionChanged = true; --- 194,199 ---- if(stream->readFlag()) { ! ((GameConnection *) connection)->readCompressedPoint(mMoveState[ActualState].pos, stream); ! readCompressedVelocity(mMoveState[ActualState].vel, 511, stream); //posSegments.push_back(mMoveState[ActualState].pos); positionChanged = true; Index: ship.cpp =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/ship.cpp,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -d -r1.26 -r1.27 *** ship.cpp 11 May 2004 18:26:25 -0000 1.26 --- ship.cpp 12 May 2004 19:35:12 -0000 1.27 *************** *** 409,412 **** --- 409,414 ---- U32 Ship::packUpdate(GhostConnection *connection, U32 updateMask, BitStream *stream) { + GameConnection *gameConnection = (GameConnection *) connection; + if(stream->writeFlag(updateMask & InitialMask)) { *************** *** 441,445 **** bool shouldWritePosition = (updateMask & InitialMask) || ! ((GameConnection *)connection)->controlObject != (GameObject *) this; if(!shouldWritePosition) --- 443,447 ---- bool shouldWritePosition = (updateMask & InitialMask) || ! gameConnection->controlObject != (GameObject *) this; if(!shouldWritePosition) *************** *** 452,460 **** if(stream->writeFlag(updateMask & PositionMask)) { ! stream->write(mMoveState[RenderState].pos.x); ! stream->write(mMoveState[RenderState].pos.y); ! stream->write(mMoveState[RenderState].vel.x); ! stream->write(mMoveState[RenderState].vel.y); ! stream->writeFlag(updateMask & WarpPositionMask); } --- 454,459 ---- if(stream->writeFlag(updateMask & PositionMask)) { ! gameConnection->writeCompressedPoint(mMoveState[RenderState].pos, stream); ! writeCompressedVelocity(mMoveState[RenderState].vel, TurboMaxVelocity + 1, stream); stream->writeFlag(updateMask & WarpPositionMask); } *************** *** 506,514 **** if(stream->readFlag()) { ! stream->read(&mMoveState[ActualState].pos.x); ! stream->read(&mMoveState[ActualState].pos.y); ! stream->read(&mMoveState[ActualState].vel.x); ! stream->read(&mMoveState[ActualState].vel.y); ! //posSegments.push_back(mMoveState[ActualState].pos); positionChanged = true; interpolate = !stream->readFlag(); --- 505,510 ---- if(stream->readFlag()) { ! ((GameConnection *) connection)->readCompressedPoint(mMoveState[ActualState].pos, stream); ! readCompressedVelocity(mMoveState[ActualState].vel, TurboMaxVelocity + 1, stream); positionChanged = true; interpolate = !stream->readFlag(); |