/** Return amount of time to tick or simulate to make up for network lag */ virtualfloatGetPredictionTime();
/** How long fake projectile should sleep before starting to simulate (because client ping is greater than MaxPredictionPing). */ virtualfloatGetProjectileSleepTime();
/** List of fake projectiles currently out there for this client */ UPROPERTY() TArray<classAUTProjectile*> FakeProjectiles;
classUNREALTOURNAMENT_APIAUTCharacter :public ACharacter, public IUTTeamInterface { //...略 /** Stored past positions of this player. Used for bot aim error model, and for server side hit resolution. */ UPROPERTY() TArray<FSavedPosition> SavedPositions;
/** Maximum interval to hold saved positions for. */ UPROPERTY() float MaxSavedPositionAge; /** Mark the last saved position as where a shot was spawned so can synch firing to client position. */ virtualvoidNotifyPendingServerFire();
/** Called by CharacterMovement after movement */ virtualvoidPositionUpdated(bool bShotSpawned);
/** Returns this character's position PredictionTime seconds ago. */ UFUNCTION(BlueprintCallable, Category = Pawn) virtual FVector GetRewindLocation(float PredictionTime, AUTPlayerController* DebugViewer=nullptr);
/** Max time server will look back to found client synchronized shot position. */ UPROPERTY(EditAnyWhere, Category = "Weapon") float MaxShotSynchDelay;
/** Returns most recent position with bShotSpawned. */ virtual FVector GetDelayedShotPosition(); virtual FRotator GetDelayedShotRotation();
/** Return true if there's a recent delayed shot */ virtualboolDelayedShotFound();
/** returns a simplified set of SavedPositions containing only the latest position for a given frame (i.e. each element has a unique Time) * @param bStopAtTeleport - removes any positions prior to and including the most recent teleportation */ voidGetSimplifiedSavedPositions(TArray<FSavedPosition>& OutPositions, bool bStopAtTeleport)const; //...略 }
voidAUTProjectile::PostNetReceiveLocationAndRotation() { //...略 // forward predict to get to position on server now if (!bFakeClientProjectile) { AUTPlayerController* MyPlayer = Cast<AUTPlayerController>(InstigatorController ? InstigatorController : GEngine->GetFirstLocalPlayerController(GetWorld())); if (MyPlayer) { float CatchupTickDelta = MyPlayer->GetPredictionTime(); if ((CatchupTickDelta > 0.f) && ProjectileMovement) { ProjectileMovement->TickComponent(CatchupTickDelta, LEVELTICK_All, NULL); } } } //...略 }
voidAUTProjectile::BeginPlay() { //...略 if (Role == ROLE_Authority) { //...略 } else { AUTPlayerController* MyPlayer = Cast<AUTPlayerController>(InstigatorController ? InstigatorController : GEngine->GetFirstLocalPlayerController(GetWorld())); if (MyPlayer) { // Move projectile to match where it is on server now (to make up for replication time) float CatchupTickDelta = MyPlayer->GetPredictionTime(); if (CatchupTickDelta > 0.f) { CatchupTick(CatchupTickDelta); } //...略 } } //...略 }
那么 Rewind 机制是在哪儿使用的咧? 我们查找寻回角色历史位置的函数
1 2 3
/** Returns this character's position PredictionTime seconds ago. */ UFUNCTION(BlueprintCallable, Category = Pawn) virtual FVector GetRewindLocation(float PredictionTime, AUTPlayerController* DebugViewer=nullptr);