目录
相关性
优先级
创建、查找、加入房间(Session)
网络游戏是通过计算机硬件通信方案将多台终端连接,组建的玩家沟通环境,从而使得玩家连接到一起游戏。
受限于网络传输环境的影响,软件设计本身必须要考虑网络资源的应用合理性。不能无限制使用网络带宽。软件设计的本质是优化资源分配,合理使用资源。
从引擎使用层面上,Unreal设计了很多策略来解决网络带宽的节约。
虚幻引擎(依次)参照以下规则确定玩家的相关Actor类组,在AActor::IsNetRelevantFor 中进行:
代码如下:
// Engine\Souce\Runtime\Engine\Private\ActotReplication.cpp
bool AActor::IsNetRelevantFor(const AActor* RealViewer, const AActor* ViewTarget, const FVector& SrcLocation) const
{if (bAlwaysRelevant || IsOwnedBy(ViewTarget) || IsOwnedBy(RealViewer) || this == ViewTarget || ViewTarget == GetInstigator()){return true;}else if (bNetUseOwnerRelevancy && Owner){return Owner->IsNetRelevantFor(RealViewer, ViewTarget, SrcLocation);}else if (bOnlyRelevantToOwner){return false;}else if (RootComponent && RootComponent->GetAttachParent() && RootComponent->GetAttachParent()->GetOwner() && (Cast(RootComponent->GetAttachParent()) || (RootComponent->GetAttachParent()->GetOwner() == Owner))){return RootComponent->GetAttachParent()->GetOwner()->IsNetRelevantFor(RealViewer, ViewTarget, SrcLocation);}else if(IsHidden() && (!RootComponent || !RootComponent->IsCollisionEnabled())){return false;}if (!RootComponent){UE_LOG(LogNet, Warning, TEXT("Actor %s / %s has no root component in AActor::IsNetRelevantFor. (Make bAlwaysRelevant=true?)"), *GetClass()->GetName(), *GetName() );return false;}return !GetDefault()->bUseDistanceBasedRelevancy ||IsWithinNetRelevancyDistance(SrcLocation);
}bool AActor::IsReplayRelevantFor(const AActor* RealViewer, const AActor* ViewTarget, const FVector& SrcLocation, const float CullDistanceOverrideSq) const
{return IsNetRelevantFor(RealViewer, ViewTarget, SrcLocation);
}
有时没有足够的带宽复制所有相关的Actor。因此Actor拥有优先级,决定优先复制的Actor。
PS:Unreal一般不建议使用OpenLevel来加载地图和关卡,推荐使用StreamLevel。
下图是手动方式,也可以通过Level Streaming Volume来自动生成
上一篇:牛客C/C++刷题笔记(四)
下一篇:jvm参数调优