You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
89 lines
2.5 KiB
89 lines
2.5 KiB
using System; |
|
using System.Collections.Generic; |
|
using AX.Common; |
|
|
|
namespace AX.MessageSystem |
|
{ |
|
/// <summary> |
|
/// 通信系统所用的消息类型,可在游戏内进行通知。 |
|
/// </summary> |
|
internal sealed class Message : IMessage |
|
{ |
|
/// <summary> |
|
/// 表示消息的类型。其实类似于消息的 ID,用于表示哪种消息。 |
|
/// </summary> |
|
/// <remarks> |
|
/// 为什么不用整型呢?诚然用整型分发消息性能更高,内存占用更低,但数字不易阅读和理解。 |
|
/// 而字符串类型则既可以任意表达,又容易阅读和理解。 |
|
/// </remarks> |
|
public string Type { get; set; } |
|
|
|
/// <summary> |
|
/// 表示消息的分发渠道。 |
|
/// </summary> |
|
public string[] Filters { get; set; } |
|
|
|
/// <summary> |
|
/// 表示消息的发送方。 |
|
/// </summary> |
|
public object Sender { get; set; } |
|
|
|
/// <summary> |
|
/// 表示延迟处理消息的时间,按秒计。 |
|
/// </summary> |
|
public float Delay { get; set; } |
|
|
|
/// <summary> |
|
/// 表示消息的附加数据。 |
|
/// </summary> |
|
public object Data { get; set; } |
|
|
|
/// <summary> |
|
/// 表示消息是否已发送。 |
|
/// </summary> |
|
public bool IsSent { get; set; } |
|
|
|
/// <summary> |
|
/// 表示消息是否已处理过。 |
|
/// </summary> |
|
public bool IsHandled { get; set; } |
|
|
|
/// <summary> |
|
/// 清空消息。 |
|
/// </summary> |
|
public void Clear() |
|
{ |
|
this.Type = default(string); |
|
this.Filters = default(string[]); |
|
this.Sender = default(object); |
|
this.Data = default(object); |
|
this.Delay = default(float); |
|
this.IsSent = default(bool); |
|
this.IsHandled = default(bool); |
|
} |
|
|
|
private static readonly ObjectPool<Message> pool = new ObjectPool<Message>(4, () => new Message()); |
|
|
|
/// <summary> |
|
/// 获取一个消息实例。 |
|
/// </summary> |
|
public static Message Acquire() |
|
{ |
|
return pool.Acquire(); |
|
} |
|
|
|
/// <summary> |
|
/// 释放一个消息实例。 |
|
/// </summary> |
|
/// <param name="message"></param> |
|
public static void Release(Message message) |
|
{ |
|
if (message == null) |
|
return; |
|
|
|
message.Clear(); |
|
|
|
pool.Release(message); |
|
} |
|
} |
|
}
|
|
|