From 4407fc29708aaffb451e9d578263f163f874863c Mon Sep 17 00:00:00 2001 From: kaetemi Date: Tue, 8 Jun 2021 21:01:34 +0800 Subject: [PATCH] Position speed checks should be based on the client tick. This fixes excessive rubber banding --- ryzom/client/src/user_entity.cpp | 1 + ryzom/common/data_common/msg.xml | 2 +- ryzom/common/src/game_share/msg_client_server.h | 2 ++ ryzom/server/src/gpm_service/client_messages.cpp | 13 +++++++------ .../src/gpm_service/world_position_manager.cpp | 10 ++-------- 5 files changed, 13 insertions(+), 15 deletions(-) diff --git a/ryzom/client/src/user_entity.cpp b/ryzom/client/src/user_entity.cpp index 2ed7355b0..0fc3546ed 100644 --- a/ryzom/client/src/user_entity.cpp +++ b/ryzom/client/src/user_entity.cpp @@ -1711,6 +1711,7 @@ bool CUserEntity::sendToServer(CBitMemStream &out) if (_Primitive) _Primitive->getGlobalPosition(_LastGPosSent, dynamicWI); // Send Position & Orientation CPositionMsg positionMsg; + positionMsg.Tick = NetMngr.getCurrentClientTick(); positionMsg.X = (sint32)(pos().x * 1000); positionMsg.Y = (sint32)(pos().y * 1000); positionMsg.Z = (sint32)(pos().z * 1000); diff --git a/ryzom/common/data_common/msg.xml b/ryzom/common/data_common/msg.xml index 93468fe64..122d89792 100644 --- a/ryzom/common/data_common/msg.xml +++ b/ryzom/common/data_common/msg.xml @@ -43,7 +43,7 @@ - + diff --git a/ryzom/common/src/game_share/msg_client_server.h b/ryzom/common/src/game_share/msg_client_server.h index 64f803e0a..5a1ac3bf4 100644 --- a/ryzom/common/src/game_share/msg_client_server.h +++ b/ryzom/common/src/game_share/msg_client_server.h @@ -563,6 +563,7 @@ public: class CPositionMsg { public: + NLMISC::TGameCycle Tick; sint32 X; sint32 Y; sint32 Z; @@ -571,6 +572,7 @@ public: void serial(NLMISC::CBitMemStream &f) { // Serialize the user character. + f.serial(Tick); f.serial(X); f.serial(Y); f.serial(Z); diff --git a/ryzom/server/src/gpm_service/client_messages.cpp b/ryzom/server/src/gpm_service/client_messages.cpp index 4f42660f5..8ddd9147c 100644 --- a/ryzom/server/src/gpm_service/client_messages.cpp +++ b/ryzom/server/src/gpm_service/client_messages.cpp @@ -50,8 +50,8 @@ void cbClientPosition( CMessage& msgin, const string &serviceName, NLNET::TServi H_AUTO(cbClientPosition); CEntityId id; - NLMISC::TGameCycle tick; - msgin.serial(id, tick); + NLMISC::TGameCycle fsTick; + msgin.serial(id, fsTick); TDataSetRow entityIndex = TheDataset.getDataSetRow( id ); if ( !entityIndex.isValid() ) @@ -62,15 +62,16 @@ void cbClientPosition( CMessage& msgin, const string &serviceName, NLNET::TServi } // entity pos (x, y, z, theta) + NLMISC::TGameCycle clientTick; sint32 x, y, z; float heading; - msgin.serial(x, y, z, heading); + msgin.serial(clientTick, x, y, z, heading); if (IsRingShard) { // make sure the move that the player is trying to make is legal // if the move wasn't legal then the values of 'x' and 'y' will be changed to make them legal - bool moveWasLegal= pCGPMS->MoveChecker->checkMove(entityIndex, x, y, tick); + bool moveWasLegal= pCGPMS->MoveChecker->checkMove(entityIndex, x, y, clientTick); // if the move wasn't legal then dispatch a message to the player if (!moveWasLegal) @@ -102,7 +103,7 @@ void cbClientPosition( CMessage& msgin, const string &serviceName, NLNET::TServi CMirrorPropValue1DS( TheDataset, entityIndex, DSPropertyPOSY )= y; CMirrorPropValue1DS( TheDataset, entityIndex, DSPropertyPOSZ )= (z&~7) + (local ? 1 : 0) + (interior ? 2 : 0) + (water ? 4 : 0); CMirrorPropValue1DS( TheDataset, entityIndex, DSPropertyORIENTATION )= heading; - CMirrorPropValue1DS( TheDataset, entityIndex, DSPropertyTICK_POS )= tick; + CMirrorPropValue1DS( TheDataset, entityIndex, DSPropertyTICK_POS )= clientTick; CMirrorPropValue1DS cell ( TheDataset, entityIndex, DSPropertyCELL ); uint32 cx = (uint16) ( + x/CWorldPositionManager::getCellSize() ); @@ -143,7 +144,7 @@ void cbClientPosition( CMessage& msgin, const string &serviceName, NLNET::TServi //CWorldPositionManager::setEntityPosition(id, x, y, z, heading, tick); if (player->getType() == CWorldEntity::Player && player->CheckMotion && player->PosInitialised) { - CWorldPositionManager::movePlayer(player, x, y, z, heading, tick); + CWorldPositionManager::movePlayer(player, x, y, z, heading, clientTick); } } } // cbClientPosition // diff --git a/ryzom/server/src/gpm_service/world_position_manager.cpp b/ryzom/server/src/gpm_service/world_position_manager.cpp index 2f859cc54..87a8f2e77 100644 --- a/ryzom/server/src/gpm_service/world_position_manager.cpp +++ b/ryzom/server/src/gpm_service/world_position_manager.cpp @@ -2218,14 +2218,8 @@ void CWorldPositionManager::movePlayer(CWorldEntity *entity, sint32 x, sint32 y, if (movNorm > sqr(maxDist)) { - if (movNorm > sqr(5 * SecuritySpeedFactor * CTickEventHandler::getGameTimeStep() * ticksSinceLastUpdate)) { - movVector *= (maxDist / sqrt(movNorm)); - nlwarning("Player limitSpeed=%2.f, entitySpeed=%.2f, masterSpeed=%.2f", limitSpeedToUse, maxSpeed(), mountWalkSpeed); - } - else - { - nlwarning("Player limitSpeed=%2.f, entitySpeed=%.2f, masterSpeed=%.2f", limitSpeedToUse, maxSpeed(), mountWalkSpeed); - } + movVector *= (maxDist / sqrt(movNorm)); + nlwarning("Player limitSpeed=%2.f, entitySpeed=%.2f, masterSpeed=%.2f", limitSpeedToUse, maxSpeed(), mountWalkSpeed); } }