[Opentnl-cvs] tnl/zap CTFGame.cpp,1.7,1.8 gameConnection.cpp,1.5,1.6 gameConnection.h,1.2,1.3 ship.c
Brought to you by:
mark_frohnmayer,
s_alanet
From: Mark F. <mar...@us...> - 2004-04-22 20:42:34
|
Update of /cvsroot/opentnl/tnl/zap In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23137/zap Modified Files: CTFGame.cpp gameConnection.cpp gameConnection.h ship.cpp Log Message: Reduced bandwidth usage of ship updates Does not send server state of control object if it is unchanged on client Added CRC capability to ByteBuffer class Index: gameConnection.h =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/gameConnection.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** gameConnection.h 21 Apr 2004 02:23:08 -0000 1.2 --- gameConnection.h 22 Apr 2004 20:42:25 -0000 1.3 *************** *** 161,164 **** --- 161,165 ---- static U32 currentClientId; U32 mClientId; + U32 mLastClientControlCRC; U32 firstMoveIndex; *************** *** 180,183 **** --- 181,185 ---- GameObject *getControlObject() { return controlObject; } + U32 getControlCRC(); void linkToClientList(); Index: gameConnection.cpp =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/gameConnection.cpp,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** gameConnection.cpp 21 Apr 2004 22:40:43 -0000 1.5 --- gameConnection.cpp 22 Apr 2004 20:42:25 -0000 1.6 *************** *** 46,49 **** --- 46,50 ---- highSendIndex[1] = 0; highSendIndex[2] = 0; + mLastClientControlCRC = 0; firstMoveIndex = 1; theGame = game; *************** *** 89,92 **** --- 90,107 ---- } + U32 GameConnection::getControlCRC() + { + PacketStream stream; + GameObject *co = getControlObject(); + + if(!co) + return 0; + + stream.writeInt(getGhostIndex(co), GhostConnection::GhostIdBitSize); + co->writeControlState(&stream); + stream.zeroToByteBoundary(); + return stream.calculateCRC(0, stream.getBytePosition()); + } + void GameConnection::writePacket(BitStream *bstream, PacketNotify *notify) { *************** *** 97,100 **** --- 112,117 ---- firstSendIndex = firstMoveIndex; + bstream->write(getControlCRC()); + bstream->write(firstSendIndex); U32 skipCount = firstSendIndex - firstMoveIndex; *************** *** 116,126 **** else { ! S32 ghostIndex = -1; ! if(controlObject.isValid()) ! ghostIndex = getGhostIndex(controlObject); ! if(bstream->writeFlag(ghostIndex != -1)) { ! bstream->writeInt(ghostIndex, GhostConnection::GhostIdBitSize); ! controlObject->writeControlState(bstream); } } --- 133,146 ---- 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); ! controlObject->writeControlState(bstream); ! } } } *************** *** 132,135 **** --- 152,157 ---- if(isConnectionToClient()) { + bstream->read(&mLastClientControlCRC); + U32 firstMove; bstream->read(&firstMove); *************** *** 156,166 **** 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); } } } --- 178,193 ---- 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 + controlObject = NULL; } } Index: CTFGame.cpp =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/CTFGame.cpp,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** CTFGame.cpp 22 Apr 2004 02:57:51 -0000 1.7 --- CTFGame.cpp 22 Apr 2004 20:42:25 -0000 1.8 *************** *** 133,137 **** UserInterface::drawStringf(xr - 70, curRowY, fontSize, "%d", mClientList[j].ping); curRowY += maxHeight; ! } } } --- 133,137 ---- UserInterface::drawStringf(xr - 70, curRowY, fontSize, "%d", mClientList[j].ping); curRowY += maxHeight; ! } } } Index: ship.cpp =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/ship.cpp,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** ship.cpp 22 Apr 2004 00:35:45 -0000 1.7 --- ship.cpp 22 Apr 2004 20:42:25 -0000 1.8 *************** *** 141,145 **** Point dir(sin(mMoveState[ActualState].angle), cos(mMoveState[ActualState].angle) ); Point projVel = mMoveState[ActualState].vel + dir * 500; ! Projectile *proj = new Projectile(mMoveState[ActualState].pos + dir * 25, projVel, 1000, this); proj->addToGame(getGame()); } --- 141,145 ---- Point dir(sin(mMoveState[ActualState].angle), cos(mMoveState[ActualState].angle) ); Point projVel = mMoveState[ActualState].vel + dir * 500; ! Projectile *proj = new Projectile(mMoveState[ActualState].pos + dir * (CollisionRadius-1), projVel, 1000, this); proj->addToGame(getGame()); } *************** *** 292,298 **** { connection->packStringTableEntry(stream, mPlayerName); ! stream->write(color.r); ! stream->write(color.g); ! stream->write(color.b); stream->write(mass); --- 292,298 ---- { connection->packStringTableEntry(stream, mPlayerName); ! stream->writeFloat(color.r, 8); ! stream->writeFloat(color.g, 8); ! stream->writeFloat(color.b, 8); stream->write(mass); *************** *** 331,337 **** stream->write(mMoveState[RenderState].pos.x); stream->write(mMoveState[RenderState].pos.y); - stream->write(mMoveState[RenderState].angle); stream->write(mMoveState[RenderState].vel.x); stream->write(mMoveState[RenderState].vel.y); stream->writeFlag(updateMask & WarpPositionMask); } --- 331,337 ---- 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); } *************** *** 352,358 **** { mPlayerName = connection->unpackStringTableEntry(stream); ! stream->read(&color.r); ! stream->read(&color.g); ! stream->read(&color.b); stream->read(&mass); --- 352,358 ---- { mPlayerName = connection->unpackStringTableEntry(stream); ! color.r = stream->readFloat(8); ! color.g = stream->readFloat(8); ! color.b = stream->readFloat(8); stream->read(&mass); *************** *** 373,377 **** stream->read(&mMoveState[ActualState].pos.x); stream->read(&mMoveState[ActualState].pos.y); - stream->read(&mMoveState[ActualState].angle); stream->read(&mMoveState[ActualState].vel.x); stream->read(&mMoveState[ActualState].vel.y); --- 373,376 ---- *************** *** 385,388 **** --- 384,389 ---- lastMove.unpack(stream); } + mMoveState[ActualState].angle = lastMove.angle; + if(positionChanged) { *************** *** 575,579 **** // Render name... ! if(OptionsMenuUserInterface::showNames) { static char buff[255]; --- 576,580 ---- // Render name... ! if(gClientGame->getConnectionToServer()->getControlObject() != this) //OptionsMenuUserInterface::showNames) { static char buff[255]; *************** *** 583,587 **** glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); ! glColor4f(1,1,1,0.55); //glColor3f(color.r*1.2,color.g*1.2,color.b*1.2); UserInterface::drawString( UserInterface::getStringWidth(14, buff) * -0.5, 30, 14, buff ); --- 584,588 ---- glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); ! glColor4f(1,1,1,0.5); //glColor3f(color.r*1.2,color.g*1.2,color.b*1.2); UserInterface::drawString( UserInterface::getStringWidth(14, buff) * -0.5, 30, 14, buff ); |