Version: Unreal 4.26

问题

  • 为啥UE编辑器会有EPlayNetMode有三种让你选择。
  • 为啥描述World 的ENetMode 会有4种,而不只是(Client/Server 2种)。
  • 为何Actor 会有Role的概念。

EPlayNetMode

UENUM()
enum EPlayNetMode
{
/** A non-networked game will be started. This can be used in combination with bLaunchSeparateServer to test menu -> server flow in your game. */
PIE_Standalone UMETA(DisplayName="Play Offline"),
/** The editor will act as both a Server and a Client. Additional instances may be opened beyond that depending on the number of clients. */
PIE_ListenServer UMETA(DisplayName="Play As Listen Server"),
/** The editor will act as a Client. A server will be started for you behind the scenes to connect to. */
PIE_Client UMETA(DisplayName="Play As Client"),
};
  • PIE_Standalone

    单机玩法,本地直接有一个所谓的服务器和一个或多个玩家。因此尤其注意相关网络请求rpc,值复制等都是同步执行的。

    应用:一般游戏的训练场啊,游戏大厅,新手引导关卡。不需要跟其他玩家交互的场景。

  • PIE_Client

    一般用于多人在线联网战斗局内,比如吃鸡游戏那种开房间成功后进入局内战斗,就是所谓的战斗局内,用这个比较多。

    应用:比如吃鸡游戏的战斗场景(与其他联网玩家战斗交互)。

  • PIE_ListenServer

    一般用于开发局域网游戏。

    应用:无(我没用过,现在好像没有开发局域网游戏的了吧)。


综上:就是方便为了给UE 编辑器用户开发测试使用。

ENetMode


//* The network mode the game is currently running.*/
enum ENetMode
{
/** Standalone: a game without networking, with one or more local players. Still considered a server because it has all server functionality. */
NM_Standalone, /** Dedicated server: server with no local players. */
NM_DedicatedServer, /** Listen server: a server that also has a local player who is hosting the game, available to other players on the network. */
NM_ListenServer, /**
* Network client: client connected to a remote server.
* Note that every mode less than this value is a kind of server, so checking NetMode < NM_Client is always some variety of server.
*/
NM_Client,
};
  • NM_Standalone

    如果你开启的是PIE_Standalone,所谓的客户端和服务器的World()->GetNetMode()都会只是NM_Standalone.

  • NM_DedicatedServer

    如果你开启的是PIE_Client,服务器上的World()->GetNetMode()才会是NM_DedicatedServer.

  • NM_Client

    如果你开启的是PIE_Client,客户端上的World()->GetNetMode()才会是NM_Client.

  • NM_ListenServer

    如果你开启的是PIE_Standalone,所谓的客户端和服务器的World()->NetMode 都会只是PIE_Standalone.

ENetRole

class ENGINE_API AActor : public UObject
{
/** Describes how much control the local machine has over the actor. */
UPROPERTY(Replicated)
TEnumAsByte<enum ENetRole> Role; /** Returns how much control the remote machine has over this actor. */
UPROPERTY(Replicated, Transient)
TEnumAsByte<enum ENetRole> RemoteRole;
} /** The network role of an actor on a local/remote network context */
enum ENetRole
{
/** No role at all. */
ROLE_None,
/** Locally simulated proxy of this actor. */
ROLE_SimulatedProxy,
/** Locally autonomous proxy of this actor. */
ROLE_AutonomousProxy,
/** Authoritative control over the actor. */
ROLE_Authority,
};

前面的ENetMode针对的是世界才能调用的,这个ENetRole是Actor才能调用的。你需要了解Actor是作为UE 可以同步的最小单元。

主要是Actor的Role和RemoteRole,大概描述的是这个Actor本地的控制性和远端的控制性。还有一点需要申明,只能是服务器复制Actor到客户端,客户端不会复制Actor到服务器。

服务器创建Actor

  • 不复制到客户端
  • Role:ROLE_Authority
  • RemoteRole:ROLE_None
  • 复制到客户端
  • Role:ROLE_Authority
  • RemoteRole:ROLE_SimulatedProxy 或 ROLE_AutonomousProxy

客户端创建Actor

  • Role:ROLE_Authority
  • RemoteRole:ROLE_None

应用:

从服务器复制一个Actor到ABCD四个客户端,那么我可以在这个Actor 的BeginPlay里判断打印log。

this->GetLocalRole() == ROLE_AutonomousProxy 就是A客户端,只打印一次。
this->GetLocalRole() == ROLE_Authority 就是服务器,只打印一次。
this->GetLocalRole() == ROLE_SimulatedProxy 就是BCD客户端,打印三次。

通俗的说:目的是为了描述这个Actor是服务器生成的;还是客户端生成的;还是服务器生成复制到客户端的;还是服务器复制到客户端,这个客户端是本地玩家还是非本地玩家。

本地玩家的,还是非本地玩家的,这是个相对的概念,客户端是我,就是本地玩家,专业术语是主控端(是我),还是模拟端。。

参考

最新文章

  1. 关于MariaDB5.5不是有效的Win32 应用程序
  2. mysql 常用查询
  3. 深入理解PHP内核(六)哈希表以及PHP的哈希表实现
  4. jQuery als.js 跑马灯
  5. js闭包详解
  6. 安装oracle 12c RAC遇到的一些问题
  7. 【转载】jQuery插件开发精品教程,让你的jQuery提升一个台阶
  8. Android的startActivityForResult()与onActivityResult()与setResult()参数分析,activity带参数的返回
  9. Linq 学习
  10. C#学习笔记(三)
  11. Android中一般支持的常用的距离单位
  12. Java利用递归算法统计1-6的数组排列组合数
  13. BZOJ2751 [HAOI2012]容易题
  14. 一封来自恶魔的挑战邀请函,那些你见过或者没见过的C语言指针都在这里了
  15. VGA、DVI、HDMI三种视频信号接口
  16. UUID简记
  17. 20175317 MyCP(课下作业,必做)
  18. Win 10 System Restore Fail 0x80070091
  19. Linux Sysstat性能监控工具安装及常见8个命令使用例子
  20. Oracle的安装与配置

热门文章

  1. 零基础学Java(14)对象构造
  2. day27--Java集合10
  3. 【java】学习路径21-基本类型的包装类
  4. 金九银十,收下这份 Java String 面试题
  5. KingbaseES ALTER TABLE 中 USING 子句的用法
  6. JMeter测试dubbo接口总结
  7. git 密码修改
  8. 全能成熟稳定开源分布式存储Ceph破冰之旅-上
  9. 日志:Redo Log 和 Undo Log
  10. 解决swiper组件autoplay报错问题