美文网首页
Replication Graph

Replication Graph

作者: 珏_Gray | 来源:发表于2019-04-29 15:31 被阅读0次

Replication graph随着4.21版本正式发布。主要用于解决网络通信的效率问题。与gameplay ability system一样,replication graph也是先在《堡垒之夜》中应用,之后再在通用引擎上发布。Replication graph是纯C++的。


目前replication graph缺少学习资料,主要的视频教程有:
1、官方livestream : Networking in 4.20: The Replication Graph | Feature Highlight | Unreal Engine Livestream

堡垒之夜的Replication graph

2、 MazyModz's tutorial :Networking - ReplicationGraph (Tutorial & Overview) (明明是很好的视频,可是只有可怜的观看人数)附带的工程:https://github.com/MazyModz/UE4-DAReplicationGraphExample

Epic官方的Shooter示例项目中也使用了replication graph,可以在虚幻商店里免费下载该项目,参考其中的代码ShooterReplicationGraph.h,比起引擎自带的BasicReplicationGraph.h(a minimal version of replication graph ),它更接近实际《堡垒之夜》使用的replication graph。

那我们从所有replication graph的起源:ReplicationGraph.h开始:

ReplicationGraph


头文件的注释对于理解和使用replication graph提供了很大的帮助:

// Copyright 1998-2019 Epic Games, Inc. All Rights Reserved.


/*=============================================================================
Replication Graph

Implementation of Replication Driver. This is customizable via subclassing UReplicationGraph. Default implementation (UReplicationGraph) does not fully function and is intended to be overridden.
    Check out BasicReplicationGraph.h for a minimal implementation that works "out of the box" with a minimal feature set.
    Check out ShooterGame / UShooterReplicationGraph for a more advanced implementation.



High level overview of ReplicationGraph:
    * The graph is a collection of nodes which produce replication lists for each network connection. The graph essentially maintains persistent lists of actors to replicate and feeds them to connections. 
    
    * This allows for more work to be shared and greatly improves the scalability of the system with respect to number of actors * number of connections.
    
    * For example, one node on the graph is the spatialization node. All actors that essentially use distance based relevancy will go here. There are also always relevant nodes. Nodes can be global, per connection, or shared (E.g, "Always relevant for team" nodes).

    * The main impact here is that virtual functions like IsNetRelevantFor and GetNetPriority are not used by the replication graph. Several properties are also not used or are slightly different in use. 

    * Instead there are essentially three ways for game code to affect this part of replication:
        * The graph itself. Adding new UReplicationNodes or changing the way an actor is placed in the graph.
        * FGlobalActorReplicationInfo: The associative data the replication graph keeps, globally, about each actor. 
        * FConnectionReplicationActorInfo: The associative data that the replication keeps, per connection, about each actor. 

    * After returned from the graph, the actor lists are further culled for distance and frequency, then merged and prioritized. The end result is a sorted list of actors to replicate that we then do logic for creating or updating actor channels.



Subclasses should implement these functions:

UReplicationGraph::InitGlobalActorClassSettings
    Initialize UReplicationGraph::GlobalActorReplicationInfoMap.

UReplicationGraph::InitGlobalGraphNodes
    Instantiate new UGraphNodes via ::CreateNewNode. Use ::AddGlobalGraphNode if they are global (for all connections).

UReplicationGraph::RouteAddNetworkActorToNodes/::RouteRemoveNetworkActorToNodes
    Route actor spawning/despawning to the right node. (Or your nodes can gather the actors themselves)

UReplicationGraph::InitConnectionGraphNodes
    Initialize per-connection nodes (or associate shared nodes with them via ::AddConnectionGraphNode)


=============================================================================*/

从replication graph的名字就可以看出这是个图,是用来驱动replication系统的数据结构。在这个图中有许多不同功能节点,维护不同的列表,这些列表会被输入到下一阶段(cull for distance & frequency 、 prioritized、actor channel等等)。

要特别关注这些

  • UReplicationNodes
  • FGlobalActorReplicationInfo
  • FConnectionReplicationActorInfo
  • UReplicationGraph::InitGlobalActorClassSettings
  • UReplicationGraph::InitGlobalGraphNodes
  • UReplicationGraph::RouteAddNetworkActorToNodes/::RouteRemoveNetworkActorToNodes
  • UReplicationGraph::InitConnectionGraphNodes

BasicReplicationGraph


挖了个坑。。。。

相关文章

网友评论

      本文标题:Replication Graph

      本文链接:https://www.haomeiwen.com/subject/dzmenqtx.html