-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AWM-17410 Optimize movement component replicated data #61
Changes from 1 commit
193fb6a
01eae28
d7c13b2
82347e7
47234cc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -229,6 +229,10 @@ UPrvVehicleMovementComponent::UPrvVehicleMovementComponent(const FObjectInitiali | |
|
||
LastAntiRolloverValue = 0.f; | ||
bUseMeshRotationForEffect = true; | ||
|
||
RepEngineRPM = 0; | ||
RepLeftTrackEffectiveAngularSpeed = 0; | ||
RepRightTrackEffectiveAngularSpeed = 0; | ||
} | ||
|
||
|
||
|
@@ -321,6 +325,8 @@ void UPrvVehicleMovementComponent::TickComponent(float DeltaTime, enum ELevelTic | |
{ | ||
UpdateAntiRollover(DeltaTime); | ||
} | ||
|
||
PrepareOptimizedRepData(); | ||
} | ||
else | ||
{ | ||
|
@@ -2610,6 +2616,29 @@ bool UPrvVehicleMovementComponent::GetCameraVector(FVector& RelativeCameraVector | |
////////////////////////////////////////////////////////////////////////// | ||
// Replication | ||
|
||
void UPrvVehicleMovementComponent::PrepareOptimizedRepData() | ||
{ | ||
RepEngineRPM = static_cast<uint8>((FMath::Min(EngineRPM, MaxEngineRPM) / MaxEngineRPM) * 255.f); | ||
RepLeftTrackEffectiveAngularSpeed = static_cast<int8>(FMath::Clamp(FMath::RoundHalfFromZero(LeftTrackEffectiveAngularSpeed), -127.f, 127.f)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Точно ли TrackEffectiveAngularSpeed влезет в int8? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Пока гонял не видел чтобы превышало 50 и -20 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 50 — это уже половина до допустимого предела. Думаю, здесь лучше тоже передавать с уменьшенной точностью значение, чтобы защититься от overflow. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @IlinAleksey , проконсультируйся с Игорем, как он скажет. Вообще по ощущениям uint8 хватит, просто клэпмить. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @IlinAleksey , тогда гуд |
||
RepRightTrackEffectiveAngularSpeed = static_cast<int8>(FMath::Clamp(FMath::RoundHalfFromZero(RightTrackEffectiveAngularSpeed), -127.f, 127.f)); | ||
} | ||
|
||
|
||
void UPrvVehicleMovementComponent::OnRep_RepEngineRPM() | ||
{ | ||
EngineRPM = static_cast<float>(RepEngineRPM) / 255.f * MaxEngineRPM; | ||
} | ||
|
||
void UPrvVehicleMovementComponent::OnRep_RepLeftTrackEffectiveAngularSpeed() | ||
{ | ||
LeftTrackEffectiveAngularSpeed = static_cast<float>(RepLeftTrackEffectiveAngularSpeed); | ||
} | ||
|
||
void UPrvVehicleMovementComponent::OnRep_RepRightTrackEffectiveAngularSpeed() | ||
{ | ||
RightTrackEffectiveAngularSpeed = static_cast<float>(RepRightTrackEffectiveAngularSpeed); | ||
} | ||
|
||
void UPrvVehicleMovementComponent::GetLifetimeReplicatedProps(TArray< FLifetimeProperty > & OutLifetimeProps) const | ||
{ | ||
Super::GetLifetimeReplicatedProps(OutLifetimeProps); | ||
|
@@ -2619,18 +2648,16 @@ void UPrvVehicleMovementComponent::GetLifetimeReplicatedProps(TArray< FLifetimeP | |
|
||
if (bFakeAutonomousProxy) | ||
{ | ||
DOREPLIFETIME(UPrvVehicleMovementComponent, EngineRPM); | ||
DOREPLIFETIME(UPrvVehicleMovementComponent, EffectiveSteeringAngularSpeed); | ||
DOREPLIFETIME(UPrvVehicleMovementComponent, RepEngineRPM); | ||
|
||
DOREPLIFETIME(UPrvVehicleMovementComponent, LeftTrackEffectiveAngularSpeed); | ||
DOREPLIFETIME(UPrvVehicleMovementComponent, RightTrackEffectiveAngularSpeed); | ||
DOREPLIFETIME(UPrvVehicleMovementComponent, RepLeftTrackEffectiveAngularSpeed); | ||
DOREPLIFETIME(UPrvVehicleMovementComponent, RepRightTrackEffectiveAngularSpeed); | ||
} | ||
else | ||
{ | ||
DOREPLIFETIME_CONDITION(UPrvVehicleMovementComponent, EngineRPM, COND_SimulatedOnly); | ||
DOREPLIFETIME_CONDITION(UPrvVehicleMovementComponent, EffectiveSteeringAngularSpeed, COND_SimulatedOnly); | ||
DOREPLIFETIME_CONDITION(UPrvVehicleMovementComponent, RepEngineRPM, COND_SimulatedOnly); | ||
|
||
DOREPLIFETIME_CONDITION(UPrvVehicleMovementComponent, LeftTrackEffectiveAngularSpeed, COND_SimulatedOnly); | ||
DOREPLIFETIME_CONDITION(UPrvVehicleMovementComponent, RightTrackEffectiveAngularSpeed, COND_SimulatedOnly); | ||
DOREPLIFETIME_CONDITION(UPrvVehicleMovementComponent, RepLeftTrackEffectiveAngularSpeed, COND_SimulatedOnly); | ||
DOREPLIFETIME_CONDITION(UPrvVehicleMovementComponent, RepRightTrackEffectiveAngularSpeed, COND_SimulatedOnly); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Вообще, я бы запихнул это в структурку все три данных, и в одном онрепе это обрабатывал. Нет смысла делать три онрепа, которые по сути конвертят значения, которые постоянно меняются. Мол, FCosmeticRepData , что-то такое