In a multiplayer session, game state information is communicated between multiple machines over an internet connection rather than residing solely on a single computer.

尽早规划多人

因为多人游戏当做单击游戏一样可以正常运作,反之则不一定,因此如果程序将来有多人需求的话,应尽早在最开始就朝着多人的方向来规划。

Client-Server模型

In a single-player or local multiplayer game, your game is run locally on a standalone game. Players connect input to a single computer and control everything on it directly, and everything in the game, including the Actors, the world, and the user interface for each player, exists on that local machine.

ue4-standalone.png

Single-player and local multiplayer take place on only one machine.

NetworkPlayExample.png

In network multiplayer, the game takes place between a server (1) and several clients (2) that are connected to it. The server processes gameplay, and the clients show the game to users.

基本网络概念

Network Modes and Server Types

Network mode describes a computer's relationship to a network multiplayer session.

Network Mode

Description

Standalone

不接收远程终端的连接。所有Player均严格限定为local玩家。单人游戏和local多人游戏采用该模式。同时运行server-side logic和client-side logic为local players。

Client

网络多人会话中连接到server的终端。不运行server-side logic。

Listen Server

网络多人会话的服务器。接收远程终端的连接,同时有local玩家运行在该server上。

Dedicated Server

网络多人会话的服务器。接收远程终端的连接,但不运行local players。因此,它舍弃了graphics, sound, input and other other player-oriented features in order to run more effeciently.

Actor Replication

Replication是网络会话中在多台机器之间同步游戏状态信息的过程。同步也可以叫reproducing. 默认绝大部分Actor的replication配置是关闭的,需要手动激活。

以下是绝大部分的replication features:

Replication Feature

Description

Creation and Destruction

当一个激活了replication的Actor母版在server端产生时,会自动创建其远程代理在各个客户终端上。该Actor会replicate信息到那些远程代理。如果销毁母版Actor,远端代理会被自动销毁。

Movement Replication

如果母版Actor激活了Replicate Movement属性(或者bReplicateMovement=true in C++),它会自动replicate其Location,Rotation,Velocity到远端代理。

Variable Replication

激活了Replicate的变量属性,会自动replicate其值从母版Actor到远端代理,当值变时。

Component Replication

Actor的Components的Replication是作为其所属的Actor的Replication的一部分。如果母版Actor没有激活Replication配置,那其包含的Components自然就不会有Replication发生。Component里的Variable的Replication同上。

Remote Procedure Calls(RPCs)

Several common features of Actors, Pawns, and Characters do not replicate:

Each of these runs separately on all clients. However, if the variables that drive these visual elements are replicated, it will ensure that all client has the same information and therefore simulates them in approximately the same way.

Network Role and Authority

一个Actor的Network Role用于确定网络游戏中的哪台机器拥有Actor的控制权。典型的,一个authoritative Actor控制着该Actor的state,其会replicate information到游戏网络中的其他机器。而一个remote proxy则是远端机器上的一个拷贝,其接收replicated information从authoritative Actor。

Actor的LocalRoleRemoteRole变量用于追踪这些,其合法取值如下:

Network Role

Description

None

The Actor has no role in a network game and does not replicate.

Authority

The Actor is authoritative and replicates its information to remote proxies of it on other machines.

Simulated Proxy

The Actor is a remote proxy that is controlled entirely by an authoritative Actor on another machine. Most Actors in a network game, like pickups, projectiles, or interactive objects, will appear as Simulated Proxies on remote clients.

Autonomous Proxy

The Actor is a remote proxy that is capable of performing some functions locally, but receives corrections from an authoritative Actor. Autonomous Proxy is usually reserved for Actors under the direct control of a player, like Pawns.