Update player.cpp

fixed validator stuff
This commit is contained in:
Sir-Skurpsalot 2026-04-15 17:08:10 -06:00 committed by GitHub
parent b351b3ffbe
commit 7e72dfba81
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -120,9 +120,9 @@ static U32 sCollisionMoveMask = TerrainObjectType |
PlayerObjectType | PlayerObjectType |
StaticShapeObjectType | StaticShapeObjectType |
VehicleObjectType | VehicleObjectType |
PhysicalZoneObjectType | PhysicalZoneObjectType |
// PATHSHAPE // PATHSHAPE
PathShapeObjectType; PathShapeObjectType;
// PATHSHAPE END // PATHSHAPE END
static U32 sServerCollisionContactMask = sCollisionMoveMask | static U32 sServerCollisionContactMask = sCollisionMoveMask |
@ -740,7 +740,7 @@ void PlayerData::initPersistFields()
addFieldV( "maxFreelookAngle", TypeRangedF32, Offset(maxFreelookAngle, PlayerData), &CommonValidators::PositiveFloat, addFieldV( "maxFreelookAngle", TypeRangedF32, Offset(maxFreelookAngle, PlayerData), &CommonValidators::PositiveFloat,
"@brief Defines the maximum left and right angles (in radians) the player can " "@brief Defines the maximum left and right angles (in radians) the player can "
"look in freelook mode.\n\n" ); "look in freelook mode.\n\n" );
addField( "minProneLookAngle", TypeF32, Offset(minProneLookAngle, PlayerData), addField( "minProneLookAngle", TypeF32, Offset(minProneLookAngle, PlayerData),
"@brief Lowest angle (in radians) the player can look when Prone.\n\n" "@brief Lowest angle (in radians) the player can look when Prone.\n\n"
"@note An angle of zero is straight ahead, with positive up and negative down." ); //Skurps "@note An angle of zero is straight ahead, with positive up and negative down." ); //Skurps
addField( "maxProneLookAngle", TypeF32, Offset(maxProneLookAngle, PlayerData), addField( "maxProneLookAngle", TypeF32, Offset(maxProneLookAngle, PlayerData),
@ -1004,28 +1004,28 @@ void PlayerData::initPersistFields()
"@brief Collision bounding box used when the player is swimming.\n\n" "@brief Collision bounding box used when the player is swimming.\n\n"
"@see boundingBox" ); "@see boundingBox" );
// Damage collision boxes changed by Skurps // Damage collision boxes changed by Skurps
addField( "boxHeadPercentage", TypeF32, Offset(boxHeadPercentage, PlayerData), &CommonValidators::NormalizedFloat, addFieldV( "boxHeadPercentage", TypeRangedF32, Offset(boxHeadPercentage, PlayerData), &CommonValidators::NormalizedFloat,
"@brief Percentage of the player's bounding box height that represents the head.\n\n" "@brief Percentage of the player's bounding box height that represents the head.\n\n"
"Used when computing the damage location.\n" "Used when computing the damage location.\n"
"@see Player::getDamageLocation" ); "@see Player::getDamageLocation" );
addField( "boxTorsoPercentage", TypeF32, Offset(boxTorsoPercentage, PlayerData), &CommonValidators::NormalizedFloat, addFieldV( "boxTorsoPercentage", TypeRangedF32, Offset(boxTorsoPercentage, PlayerData), &CommonValidators::NormalizedFloat,
"@brief Percentage of the player's bounding box height that represents the torso.\n\n" "@brief Percentage of the player's bounding box height that represents the torso.\n\n"
"Used when computing the damage location.\n" "Used when computing the damage location.\n"
"@see Player::getDamageLocation" ); "@see Player::getDamageLocation" );
addField( "boxTorsoLeftPercentage", TypeF32, Offset(boxTorsoLeftPercentage, PlayerData), &CommonValidators::NormalizedFloat, addFieldV( "boxTorsoLeftPercentage", TypeRangedF32, Offset(boxTorsoLeftPercentage, PlayerData), &CommonValidators::NormalizedFloat,
"@brief Percentage of the player's bounding box width that represents the left side of the torso.\n\n" "@brief Percentage of the player's bounding box width that represents the left side of the torso.\n\n"
"Used when computing the damage location.\n" "Used when computing the damage location.\n"
"@see Player::getDamageLocation" ); "@see Player::getDamageLocation" );
addField( "boxTorsoRightPercentage", TypeF32, Offset(boxTorsoRightPercentage, PlayerData), &CommonValidators::NormalizedFloat, addFieldV( "boxTorsoRightPercentage", TypeRangedF32, Offset(boxTorsoRightPercentage, PlayerData), &CommonValidators::NormalizedFloat,
"@brief Percentage of the player's bounding box width that represents the right side of the torso.\n\n" "@brief Percentage of the player's bounding box width that represents the right side of the torso.\n\n"
"Used when computing the damage location.\n" "Used when computing the damage location.\n"
"@see Player::getDamageLocation" ); "@see Player::getDamageLocation" );
addField( "boxTorsoBackPercentage", TypeF32, Offset(boxTorsoBackPercentage, PlayerData), &CommonValidators::NormalizedFloat, addFieldV( "boxTorsoBackPercentage", TypeRangedF32, Offset(boxTorsoBackPercentage, PlayerData), &CommonValidators::NormalizedFloat,
"@brief Percentage of the player's bounding box depth that represents the back side of the torso.\n\n" "@brief Percentage of the player's bounding box depth that represents the back side of the torso.\n\n"
"Used when computing the damage location.\n" "Used when computing the damage location.\n"
"@see Player::getDamageLocation" ); "@see Player::getDamageLocation" );
addField( "boxTorsoFrontPercentage", TypeF32, Offset(boxTorsoFrontPercentage, PlayerData), &CommonValidators::NormalizedFloat, addFieldV( "boxTorsoFrontPercentage", TypeRangedF32, Offset(boxTorsoFrontPercentage, PlayerData), &CommonValidators::NormalizedFloat,
"@brief Percentage of the player's bounding box depth that represents the front side of the torso.\n\n" "@brief Percentage of the player's bounding box depth that represents the front side of the torso.\n\n"
"Used when computing the damage location.\n" "Used when computing the damage location.\n"
"@see Player::getDamageLocation" ); "@see Player::getDamageLocation" );
@ -2061,18 +2061,18 @@ void Player::processTick(const Move* move)
} }
// Warp to catch up to server // Warp to catch up to server
if (mDelta.warpTicks > 0) { if (mDelta.warpTicks > 0) {
mDelta.warpTicks--; mDelta.warpTicks--;
// Set new pos // Set new pos
getTransform().getColumn(3, &mDelta.pos); getTransform().getColumn(3, &mDelta.pos);
mDelta.pos += mDelta.warpOffset; mDelta.pos += mDelta.warpOffset;
mDelta.rot += mDelta.rotOffset; mDelta.rot += mDelta.rotOffset;
// Wrap yaw to +/-PI // Wrap yaw to +/-PI
if (mDelta.rot.z < - M_PI_F) if (mDelta.rot.z < - M_PI_F)
mDelta.rot.z += M_2PI_F; mDelta.rot.z += M_2PI_F;
else if (mDelta.rot.z > M_PI_F) else if (mDelta.rot.z > M_PI_F)
mDelta.rot.z -= M_2PI_F; mDelta.rot.z -= M_2PI_F;
if (!ignore_updates) if (!ignore_updates)
{ {
@ -2082,8 +2082,8 @@ void Player::processTick(const Move* move)
updateLookAnimation(); updateLookAnimation();
// Backstepping // Backstepping
mDelta.posVec = -mDelta.warpOffset; mDelta.posVec = -mDelta.warpOffset;
mDelta.rotVec = -mDelta.rotOffset; mDelta.rotVec = -mDelta.rotOffset;
} }
else { else {
// If there is no move, the player is either an // If there is no move, the player is either an
@ -2583,7 +2583,7 @@ void Player::updateMove(const Move* move)
// Update current orientation // Update current orientation
if (mDamageState == Enabled) { if (mDamageState == Enabled) {
F32 prevZRot = mRot.z; F32 prevZRot = mRot.z;
mDelta.headVec = mHead; mDelta.headVec = mHead;
bool doStandardMove = true; bool doStandardMove = true;
bool absoluteDelta = false; bool absoluteDelta = false;
@ -2715,7 +2715,7 @@ void Player::updateMove(const Move* move)
if (p > M_PI_F) if (p > M_PI_F)
p -= M_2PI_F; p -= M_2PI_F;
//Skurps - use different min/max if prone //Skurps - use different min/max if prone
F32 curMinLookAngle = mPose == PronePose ? mDataBlock->minProneLookAngle : mDataBlock->minLookAngle; F32 curMinLookAngle = mPose == PronePose ? mDataBlock->minProneLookAngle : mDataBlock->minLookAngle;
F32 curMaxLookAngle = mPose == PronePose ? mDataBlock->maxProneLookAngle : mDataBlock->maxLookAngle; F32 curMaxLookAngle = mPose == PronePose ? mDataBlock->maxProneLookAngle : mDataBlock->maxLookAngle;
@ -2749,21 +2749,21 @@ void Player::updateMove(const Move* move)
mRot.z -= M_2PI_F; mRot.z -= M_2PI_F;
} }
mDelta.rot = mRot; mDelta.rot = mRot;
mDelta.rotVec.x = mDelta.rotVec.y = 0.0f; mDelta.rotVec.x = mDelta.rotVec.y = 0.0f;
mDelta.rotVec.z = prevZRot - mRot.z; mDelta.rotVec.z = prevZRot - mRot.z;
if (mDelta.rotVec.z > M_PI_F) if (mDelta.rotVec.z > M_PI_F)
mDelta.rotVec.z -= M_2PI_F; mDelta.rotVec.z -= M_2PI_F;
else if (mDelta.rotVec.z < -M_PI_F) else if (mDelta.rotVec.z < -M_PI_F)
mDelta.rotVec.z += M_2PI_F; mDelta.rotVec.z += M_2PI_F;
mDelta.head = mHead; mDelta.head = mHead;
mDelta.headVec -= mHead; mDelta.headVec -= mHead;
if (absoluteDelta) if (absoluteDelta)
{ {
mDelta.headVec = Point3F(0, 0, 0); mDelta.headVec = Point3F(0, 0, 0);
mDelta.rotVec = Point3F(0, 0, 0); mDelta.rotVec = Point3F(0, 0, 0);
} }
for(U32 i=0; i<3; ++i) for(U32 i=0; i<3; ++i)
@ -2850,7 +2850,7 @@ void Player::updateMove(const Move* move)
// Acceleration due to gravity // Acceleration due to gravity
VectorF acc(0.0f, 0.0f, mNetGravity/(1.0 - mBuoyancy) * TickSec); VectorF acc(0.0f, 0.0f, mNetGravity/(1.0 - mBuoyancy) * TickSec);
if (getParent() !=NULL) if (getParent() !=NULL)
acc = VectorF::Zero; acc = VectorF::Zero;
// Determine ground contact normal. Only look for contacts if // Determine ground contact normal. Only look for contacts if
// we can move and aren't mounted. // we can move and aren't mounted.
@ -3967,7 +3967,7 @@ void Player::updateActionThread()
playFootstepSound( triggeredLeft, material, rInfo.object ); playFootstepSound( triggeredLeft, material, rInfo.object );
} }
} }
//Prone crawl sound - Skurps //Prone crawl sound - Skurps
if( mShapeInstance->getTriggerState( 3 ) ) if( mShapeInstance->getTriggerState( 3 ) )
{ {
playCrawlSound(); playCrawlSound();
@ -5280,8 +5280,8 @@ bool Player::updatePos(const F32 travelTime)
if (isClientObject()) if (isClientObject())
{ {
mDelta.pos = newPos; mDelta.pos = newPos;
mDelta.posVec = mDelta.posVec - mDelta.pos; mDelta.posVec = mDelta.posVec - mDelta.pos;
mDelta.dt = 1.0f; mDelta.dt = 1.0f;
} }
setPosition( newPos, mRot ); setPosition( newPos, mRot );
@ -6305,7 +6305,7 @@ void Player::readPacketData(GameConnection *connection, BitStream *stream)
stream->read(&mVelocity.y); stream->read(&mVelocity.y);
stream->read(&mVelocity.z); stream->read(&mVelocity.z);
stream->setCompressionPoint(pos); stream->setCompressionPoint(pos);
mDelta.pos = pos; mDelta.pos = pos;
mJumpSurfaceLastContact = stream->readInt(4); mJumpSurfaceLastContact = stream->readInt(4);
if (stream->readFlag()) if (stream->readFlag())
@ -6421,12 +6421,12 @@ U32 Player::packUpdate(NetConnection *con, U32 mask, BitStream *stream)
mRot.z = mWrapF(mRot.z, 0.0f, M_2PI_F); mRot.z = mWrapF(mRot.z, 0.0f, M_2PI_F);
stream->writeFloat(mRot.z / M_2PI_F, 7); stream->writeFloat(mRot.z / M_2PI_F, 7);
//Skurps - use different min/max if prone //Skurps - use different min/max if prone
F32 curMinLookAngle = mPose == PronePose ? mDataBlock->minProneLookAngle : mDataBlock->minLookAngle; F32 curMinLookAngle = mPose == PronePose ? mDataBlock->minProneLookAngle : mDataBlock->minLookAngle;
F32 curMaxLookAngle = mPose == PronePose ? mDataBlock->maxProneLookAngle : mDataBlock->maxLookAngle; F32 curMaxLookAngle = mPose == PronePose ? mDataBlock->maxProneLookAngle : mDataBlock->maxLookAngle;
stream->writeSignedFloat(mHead.x / ( curMaxLookAngle - curMinLookAngle), 6); //Skurps stream->writeSignedFloat(mHead.x / ( curMaxLookAngle - curMinLookAngle), 6); //Skurps
stream->writeSignedFloat(mHead.z / mDataBlock->maxFreelookAngle, 6); stream->writeSignedFloat(mHead.z / mDataBlock->maxFreelookAngle, 6);
mDelta.move.pack(stream); mDelta.move.pack(stream);
stream->writeFlag(!(mask & NoWarpMask)); stream->writeFlag(!(mask & NoWarpMask));
} }
// Ghost need energy to predict reliably // Ghost need energy to predict reliably
@ -6530,33 +6530,33 @@ void Player::unpackUpdate(NetConnection *con, BitStream *stream)
rot.y = rot.x = 0.0f; rot.y = rot.x = 0.0f;
rot.z = stream->readFloat(7) * M_2PI_F; rot.z = stream->readFloat(7) * M_2PI_F;
//Skurps - use different min/max if prone //Skurps - use different min/max if prone
F32 curMinLookAngle = mPose == PronePose ? mDataBlock->minProneLookAngle : mDataBlock->minLookAngle; //Skurps F32 curMinLookAngle = mPose == PronePose ? mDataBlock->minProneLookAngle : mDataBlock->minLookAngle; //Skurps
F32 curMaxLookAngle = mPose == PronePose ? mDataBlock->maxProneLookAngle : mDataBlock->maxLookAngle; //Skurps F32 curMaxLookAngle = mPose == PronePose ? mDataBlock->maxProneLookAngle : mDataBlock->maxLookAngle; //Skurps
mHead.x = stream->readSignedFloat(6) * (curMaxLookAngle - curMinLookAngle); //Skurps mHead.x = stream->readSignedFloat(6) * (curMaxLookAngle - curMinLookAngle); //Skurps
mHead.z = stream->readSignedFloat(6) * mDataBlock->maxFreelookAngle; mHead.z = stream->readSignedFloat(6) * mDataBlock->maxFreelookAngle;
mDelta.move.unpack(stream); mDelta.move.unpack(stream);
mDelta.head = mHead; mDelta.head = mHead;
mDelta.headVec.set(0.0f, 0.0f, 0.0f); mDelta.headVec.set(0.0f, 0.0f, 0.0f);
if (stream->readFlag() && isProperlyAdded()) if (stream->readFlag() && isProperlyAdded())
{ {
// Determine number of ticks to warp based on the average // Determine number of ticks to warp based on the average
// of the client and server velocities. // of the client and server velocities.
mDelta.warpOffset = pos - mDelta.pos; mDelta.warpOffset = pos - mDelta.pos;
F32 as = (speed + mVelocity.len()) * 0.5f * TickSec; F32 as = (speed + mVelocity.len()) * 0.5f * TickSec;
F32 dt = (as > 0.00001f) ? mDelta.warpOffset.len() / as: sMaxWarpTicks; F32 dt = (as > 0.00001f) ? mDelta.warpOffset.len() / as: sMaxWarpTicks;
mDelta.warpTicks = (S32)((dt > sMinWarpTicks) ? getMax(mFloor(dt + 0.5f), 1.0f) : 0.0f); mDelta.warpTicks = (S32)((dt > sMinWarpTicks) ? getMax(mFloor(dt + 0.5f), 1.0f) : 0.0f);
if (mDelta.warpTicks) if (mDelta.warpTicks)
{ {
// Setup the warp to start on the next tick. // Setup the warp to start on the next tick.
if (mDelta.warpTicks > sMaxWarpTicks) if (mDelta.warpTicks > sMaxWarpTicks)
mDelta.warpTicks = sMaxWarpTicks; mDelta.warpTicks = sMaxWarpTicks;
mDelta.warpOffset /= (F32)mDelta.warpTicks; mDelta.warpOffset /= (F32)mDelta.warpTicks;
mDelta.rotOffset = rot - mDelta.rot; mDelta.rotOffset = rot - mDelta.rot;
// Ignore small rotation differences // Ignore small rotation differences
if (mFabs(mDelta.rotOffset.z) < 0.001f) if (mFabs(mDelta.rotOffset.z) < 0.001f)
@ -6564,11 +6564,11 @@ void Player::unpackUpdate(NetConnection *con, BitStream *stream)
// Wrap rotation to +/-PI // Wrap rotation to +/-PI
if(mDelta.rotOffset.z < - M_PI_F) if(mDelta.rotOffset.z < - M_PI_F)
mDelta.rotOffset.z += M_2PI_F; mDelta.rotOffset.z += M_2PI_F;
else if(mDelta.rotOffset.z > M_PI_F) else if(mDelta.rotOffset.z > M_PI_F)
mDelta.rotOffset.z -= M_2PI_F; mDelta.rotOffset.z -= M_2PI_F;
mDelta.rotOffset /= (F32)mDelta.warpTicks; mDelta.rotOffset /= (F32)mDelta.warpTicks;
} }
else else
{ {
@ -6584,18 +6584,18 @@ void Player::unpackUpdate(NetConnection *con, BitStream *stream)
else else
{ {
F32 dti = 1.0f / mDelta.dt; F32 dti = 1.0f / mDelta.dt;
mDelta.posVec = (cp - pos) * dti; mDelta.posVec = (cp - pos) * dti;
mDelta.rotVec.z = mRot.z - rot.z; mDelta.rotVec.z = mRot.z - rot.z;
if(mDelta.rotVec.z > M_PI_F) if(mDelta.rotVec.z > M_PI_F)
mDelta.rotVec.z -= M_2PI_F; mDelta.rotVec.z -= M_2PI_F;
else if(mDelta.rotVec.z < -M_PI_F) else if(mDelta.rotVec.z < -M_PI_F)
mDelta.rotVec.z += M_2PI_F; mDelta.rotVec.z += M_2PI_F;
mDelta.rotVec.z *= dti; mDelta.rotVec.z *= dti;
} }
mDelta.pos = pos; mDelta.pos = pos;
mDelta.rot = rot; mDelta.rot = rot;
if (!ignore_updates) if (!ignore_updates)
setPosition(pos,rot); setPosition(pos,rot);
} }
@ -6605,10 +6605,10 @@ void Player::unpackUpdate(NetConnection *con, BitStream *stream)
// Set the player to the server position // Set the player to the server position
mDelta.pos = pos; mDelta.pos = pos;
mDelta.rot = rot; mDelta.rot = rot;
mDelta.posVec.set(0.0f, 0.0f, 0.0f); mDelta.posVec.set(0.0f, 0.0f, 0.0f);
mDelta.rotVec.set(0.0f, 0.0f, 0.0f); mDelta.rotVec.set(0.0f, 0.0f, 0.0f);
mDelta.warpTicks = 0; mDelta.warpTicks = 0;
mDelta.dt = 0.0f; mDelta.dt = 0.0f;
if (!ignore_updates) if (!ignore_updates)
setPosition(pos,rot); setPosition(pos,rot);
} }