From f7a3e6a4ee65275868b4e507a11b709fbd39e4fc Mon Sep 17 00:00:00 2001 From: "ulukyn@gmail.com" Date: Wed, 25 Oct 2017 18:42:30 +0200 Subject: [PATCH] Changed: Try to implement better pos correct from gpms (using deceleration + acceleration) --HG-- branch : compatibility-develop --- code/ryzom/client/src/net_manager.cpp | 2 +- code/ryzom/client/src/user_entity.cpp | 15 +++++++++++---- code/ryzom/client/src/user_entity.h | 14 ++++++++++++-- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/code/ryzom/client/src/net_manager.cpp b/code/ryzom/client/src/net_manager.cpp index 2742edeff..787a33515 100644 --- a/code/ryzom/client/src/net_manager.cpp +++ b/code/ryzom/client/src/net_manager.cpp @@ -1406,7 +1406,7 @@ void impulseCorrectPos(NLMISC::CBitMemStream &impulse) { if (x == 0) // Get SpeedAdjustement { - UserEntity->setSpeedServerAdjust((float)y/1000.0f); + UserEntity->setSpeedServerAdjust(-0.2f); } else { diff --git a/code/ryzom/client/src/user_entity.cpp b/code/ryzom/client/src/user_entity.cpp index 7ae8cec5d..2d5819d69 100644 --- a/code/ryzom/client/src/user_entity.cpp +++ b/code/ryzom/client/src/user_entity.cpp @@ -144,6 +144,8 @@ CUserEntity::CUserEntity() _FrontVelocity = 0.0f; _LateralVelocity = 0.0f; + _SpeedServerAdjust = 1.0f; + // \todo GUIGUI : do it more generic. _First_Pos = false; @@ -1205,7 +1207,11 @@ void CUserEntity::applyMotion(CEntityCL *target) speed = CVectorD::Null; } else + { speed = getVelocity()*_SpeedFactor.getValue(); + _SpeedFactor.addFactorValue(0.005f); + } + // SPEED VECTOR NULL -> NO MOVE if(speed == CVectorD::Null) return; @@ -1218,7 +1224,6 @@ void CUserEntity::applyMotion(CEntityCL *target) // don't increase speed clamp(modif, 0.0, 1.0); speed *= modif; - speed *= _SpeedServerAdjust; // Move _HasMoved = true; _Primitive->move(speed, dynamicWI); @@ -1228,7 +1233,9 @@ void CUserEntity::applyMotion(CEntityCL *target) // Third Person View else { - speed *= _SpeedServerAdjust; + double modif = (100.0f/(float)NetMngr.getMsPerTick()); + clamp(modif, 0.0, 1.0); + speed *= modif; speed += pos(); sint64 x = (sint64)((sint32)(speed.x * 1000.0)); sint64 y = (sint64)((sint32)(speed.y * 1000.0)); @@ -1246,8 +1253,7 @@ void CUserEntity::applyMotion(CEntityCL *target) } } - _SpeedServerAdjust += 0.05; - clamp(_SpeedServerAdjust, 0.8, 1.0); + }// applyMotion // @@ -3484,6 +3490,7 @@ void CUserEntity::light() void CUserEntity::CSpeedFactor::init() { _Value = 1.0f; // Default speed factor is 1. + _ServerFactor = 1.0f; CInterfaceManager *IM = CInterfaceManager::getInstance (); CCDBNodeLeaf *pNodeLeaf = NLGUI::CDBManager::getInstance()->getDbProp("SERVER:USER:SPEED_FACTOR", false); if(pNodeLeaf) diff --git a/code/ryzom/client/src/user_entity.h b/code/ryzom/client/src/user_entity.h index fc6d56ea1..24162622e 100644 --- a/code/ryzom/client/src/user_entity.h +++ b/code/ryzom/client/src/user_entity.h @@ -297,7 +297,7 @@ public: // get the velocity vector of the entity NLMISC::CVector getVelocity() const; - inline void setSpeedServerAdjust(float speed) {_SpeedServerAdjust = speed;} + inline void setSpeedServerAdjust(float speed) {_SpeedFactor.addFactorValue(speed);} /// Check if the mount is able to run, and force walking mode if not void checkMountAbleToRun(); @@ -499,13 +499,23 @@ protected: /// Release void release(); /// Return the speed factor. - float getValue() const {return _Value;} + float getValue() const { return _Value * _ServerFactor; } + void setFactorValue(float value) {_ServerFactor = value;} + void addFactorValue(float value) { + _ServerFactor += value; + if (_ServerFactor > 1.0) + _ServerFactor = 1.0; + if (_ServerFactor < 0.1) + _ServerFactor = 0.1; + } + virtual void serial(class NLMISC::IStream &f) throw(NLMISC::EStream) {f.serial(_Value);} protected: /// Method called when the ping message is back. virtual void update(NLMISC::ICDBNode* leaf); private: float _Value; + float _ServerFactor; }; class CMountHunger