Photon——Basic Concepts 基本概念

 

Basic Concepts 基本概念

 
     The following article will show you the important basic concepts for Photon.
     以下是要告诉你的Photon重要基本概念
 

     Applications 应用程序

     An Application is the server side logic for a game. All features of a game (e.g. remote procedure calls, data storing, etc.) are implemented in a Photon application. The C# source is compiled and the resulting assemblies are loaded by Photons native core. To setup applications and to define start parameters the Photon Core uses configuration files.
     一个应用既是一个服务端的游戏逻辑,一个游戏的所有特征是在Photon应用中被实现的。由C#编写的源码被编译成程序集并加载到Photons native core。部署应用并且在Photon配置文件中定义参数。
 
     Usually, all logics of a game are provided in a single application. Photon is still able to run several applications at the same time. Each application can have a different task. For example, a separate application can be made to send out policy files for web-based clients. By running a separate Policy Application next to your game logic you can add functionality.
     通常,一个游戏的所有逻辑是由一个应用程序提供的,Photon 是可以同时运行多个应用程序,每个应用程序可以有不同的任务。比如,一个独立的应用程序可以被用于为基于Web的客户端发送policy文件,通过运行一个独立的Policy应用程序为你的游戏逻辑添加功能
     
     A client chooses the application it wants to use by simply providing the application’s name on connect.
     一个客户端在连接的时候需要使用应用的名字去选择应用程序

     Game Logic 游戏逻辑

     The game logic defines how a client can interact with the server. It implements operations, events, and anything that the server does by itself.
     游戏逻辑定义了客户端如何与服务器进行交互。它实现了操作、事件和其他服务器想做的事情
 
     A good basis for room based games is provided as “Lite” Application , found in the SDK folder src-server/Lite. It does not know (your) game’s logic (yet), but provides rooms where players can communicate and interact easily. The application “Lite Lobby” extends Lite with lists of rooms if you want your users to select a room manually.
     Lite是一个很好的基于房间的游戏基础应用,src-server/Lite中可以找到它,它不知道你的游戏逻辑,但是提供了房间,玩家可以轻松的进行交流与互动。Lite Lobby扩展了Lite,提供了房间列表,以便于用户可以手动选择房间
 
     If your game is going to be a single, huge world, the MMO Demo Application is a good basis for it. This application handles interest management for your clients and provides classes for items, properties, actors and more.
     如果你的游戏是一个独立的巨大的世界,那MMO是一个很好的基础应用,这个应用为你的客户端提供了兴趣管理和一些类型,例如商品、属性、玩家等等。
     
     Alternatively any game logic can be developed directly on top of the C# framework. The entry point for this is the application class, defined in the Photon.Socketserver.dll.
     或者任何游戏的逻辑都可以在C# framework之上进行开发,这程序的入口必须定义在Photon.Socketserver.dll

     Operations 操作

     An operation is Photon’s equivalent to a remote procedure call. Photon clients use operation calls for anything they want to get done.
     一个操作相当于是一次远程过程调用(RPC)。Photon客户端使用操作调用进行他们想要做的事情
 
     Operations and all of their parameters are defined in the server-side application as needed. Clients can call any operation by setting up a hashtable with keys and values fitting the operation’s conventions. The client and server frameworks take care of serialization, transfer and deserialization.
     操作和属性是被定义在服务端的应用程序中的。客户端可以调用任意操作,只要通过设置一个hashtable 的键和值来制定该操作的合约即可,客户端和服务端的frameworks负责序列化、传递和反序列化
     
     Each operation can also provide a result. This is one way to provide a client with requested data. Of course the result can be skipped, which saves bandwidth.
     每个操作也可以提供一个结果。这是一个提供给客户端请求数据的方法,当然结果是可以被跳过的,跳过可以节省带宽流量
 
     Operation calls and results are a thing between one client and the server. The other clients won’t know about these.
     操作的调用和结果是一个客户端和服务器之间发生的,其他客户端是无法得知。

     Events 事件

     Photon Events are messages for clients. Each event is typed by a byte code and carries game updates. The Lite Application defines several events but it’s possible to define custom events purely on the client side.
     Photon事件是对客户端的消息,每个事件的类型是一个byte代码,Lite定义了许多的事件,也可以在客户端定义通用的事件
 
     Unlike operation results, a received event is most likely caused another client’s operation call. This means: Events might arrive anytime. Lite sends events when someone joins or leaves a room.
     不像操作结果,一个接受到的事件最有可能触发其他客户端的操作调用,这意味着,事件可能随时发生,Lite应用中当某个玩家加入和离开房间时会发送事件
 
     The Operation RaiseEvent (in Lite) makes events truly universal: Any client can create new events by putting together a hashtable with the data and applying a code on sending it. Game data can be sent without any need to change the server.
     这个RaiseEvent操作使得事件真正的通用:任意客户端可以创建一个装有数据和应用代码的hashtable的新的事件进行发送,游戏数据可以被发送无需去改变服务器
 
     Of course, for more elaborate server side reaction to events, custom operations can be defined which check event data, compile it or create other events.
     当然,对于更为复杂的服务器端事件的反应,通用操作可以被定义为检查、编译事件数据或创建其他事件

     Connections and Timeouts 连接与超时

     Unlike plain UDP, Photon’s reliable UDP protocol establishes a connection between server and clients: Commands within a UDP package have sequence numbers and a flag if they are reliable. If so, the receiving end has to acknowledge the command. Reliable commands are repeated in short intervals until an acknowledgement arrives. If it does not arrive, the connection is timed out.
     不像常规的UDP,Photon使用的是可靠的UDP协议建立客户端与服务端的连接:命令在一个UDP包中,其中包含序列化的数字和一个可靠性标志,这样接收端才能识别这个命令,可靠的命令是在很短的时间间隔内重复直到被确认,如果不被确认到,则连接超时
 
     Both sides monitor this connection independently from their perspective. Both sides have their rules to decide if the other is still available.
     两端监控连接都是独立的,两端还可以定义自己的规则
 
     If a timeouts is detected, a disconnect happens on that side of the connection. As we think the other side does not respond anymore, no message is sent to it. This is why timeout disconnects are one sided and not synchronous.
     如果一个超时被检测到,就会断开连接,这时我们认为另一边未响应,没有信息可以发送给它,这就是为什么超时断开是发生在一侧并且是不同步的
posted @ 2013-05-15 13:35  M守护神  阅读(1001)  评论(0编辑  收藏  举报