Size: 5107
Comment:
|
Size: 7344
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 62: | Line 62: |
=== Network Role and Authority === | ==== Network Role and Authority ==== |
Line 72: | Line 72: |
UE引擎默认使用server-authoritative模型,就是说server总是拥有game state的控制权限,且information总是从server同步到clients。你可以预期server上的Actor的LocalRole属性值为Authority,相应的,也可以预期remote clients上的Proxies的LocalRole属性值为Simulated或Autonomous Proxy。 ==== Client Ownership ==== 终端的所有权。网络游戏里的每个Pawn都是归某个特定client机器上的一个'''PlayerController'''所有的. Any time that Pawn calls a client-only function, it will be directed only to the owning player's machine no matter which machine calls the function. Actors that have their '''Owner''' variable set to a specific Pawn belong to that Pawn's owning client by association, and will also direct client-only functions to their owner's machine. 这两句话很复杂,经过测试表明:ListenServer上的Pawn的'''Owner'''属性值为ListenServer上的PlayerController,server上有3个Pawn的话,其Owner分别对应3个PlayerController(至少在ListenServer的情形里是这样),而remote client里只有一个Pawn的Owner属性有值(该Pawn的'''IsLocallyControlled'''属性为True),且值是该remote client上的PlayerController,这个client里的其他Pawn的Owner属性值均为空(这些Pawn的'''IsLocallyControlled'''属性为False)。Pawn里设置了一个ClientOnlyFn函数,功能为移动场景里的一个Cube,在remote client里按键触发一个操作:寻找一个IsLocallyControlled属性为False的Pawn,调用该Pawn的ClientOnlyFn函数,结果是'''只有'''该remote client里的Cube被移动了=>这表明该Pawn的这个ClientOnlyFn函数在'''这个'''remote client上起作用了。将remote client里的按键触发操作改为:寻找一个IsLocallyControlled属性为True的Pawn,调用该Pawn的ClientOnlyFn函数,结果仍然是'''只有'''该remote client里的Cube被移动了=>这两种按键动作都表明,ClientOnlyFn函数在哪个client上调用,就在哪个client上执行。这里需要追加一句:这个按键动作在server上执行时,只有server上的Cube被移动,结论不变。因为server也是一个client。 === Variable Replication === |
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.
Single-player and local multiplayer take place on only one machine.
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:
- Skeletal Mesh and Static Mesh Components
- Materials
- Animation Blueprints
- Particle Systems
- Sound Emitters
- Physics Objects
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的LocalRole和RemoteRole变量用于追踪这些,其合法取值如下:
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. |
UE引擎默认使用server-authoritative模型,就是说server总是拥有game state的控制权限,且information总是从server同步到clients。你可以预期server上的Actor的LocalRole属性值为Authority,相应的,也可以预期remote clients上的Proxies的LocalRole属性值为Simulated或Autonomous Proxy。
Client Ownership
终端的所有权。网络游戏里的每个Pawn都是归某个特定client机器上的一个PlayerController所有的.
Any time that Pawn calls a client-only function, it will be directed only to the owning player's machine no matter which machine calls the function. Actors that have their Owner variable set to a specific Pawn belong to that Pawn's owning client by association, and will also direct client-only functions to their owner's machine. 这两句话很复杂,经过测试表明:ListenServer上的Pawn的Owner属性值为ListenServer上的PlayerController,server上有3个Pawn的话,其Owner分别对应3个PlayerController(至少在ListenServer的情形里是这样),而remote client里只有一个Pawn的Owner属性有值(该Pawn的IsLocallyControlled属性为True),且值是该remote client上的PlayerController,这个client里的其他Pawn的Owner属性值均为空(这些Pawn的IsLocallyControlled属性为False)。Pawn里设置了一个ClientOnlyFn函数,功能为移动场景里的一个Cube,在remote client里按键触发一个操作:寻找一个IsLocallyControlled属性为False的Pawn,调用该Pawn的ClientOnlyFn函数,结果是只有该remote client里的Cube被移动了=>这表明该Pawn的这个ClientOnlyFn函数在这个remote client上起作用了。将remote client里的按键触发操作改为:寻找一个IsLocallyControlled属性为True的Pawn,调用该Pawn的ClientOnlyFn函数,结果仍然是只有该remote client里的Cube被移动了=>这两种按键动作都表明,ClientOnlyFn函数在哪个client上调用,就在哪个client上执行。这里需要追加一句:这个按键动作在server上执行时,只有server上的Cube被移动,结论不变。因为server也是一个client。