提交 2026d35b 编写于 作者: T tanghai

1.目前一秒可以生成65535个Id,InstanceId也占用了这个空间,其实InstanceId跟Id是不会冲突的,所以没必要占用Id的空间,直接自增就行了,不需要带上时间戳

2.InstanceId的Set方法改成private,不应该由使用者来设置
上级 f5d9b283
......@@ -27,7 +27,7 @@ namespace ETHotfix
{
self.ActorId = await Game.Scene.GetComponent<LocationProxyComponent>().Get(self.Id);
self.Address = StartConfigComponent.Instance.GetInnerAddress(IdGenerater.GetAppIdFromId(self.ActorId));
self.Address = StartConfigComponent.Instance.GetInnerAddress(IdGenerater.GetAppId(self.ActorId));
self.UpdateAsync().Coroutine();
}
......@@ -158,7 +158,7 @@ namespace ETHotfix
// 等待0.5s再发送
await Game.Scene.GetComponent<TimerComponent>().WaitAsync(500);
self.ActorId = await Game.Scene.GetComponent<LocationProxyComponent>().Get(self.Id);
self.Address = StartConfigComponent.Instance.GetInnerAddress(IdGenerater.GetAppIdFromId(self.ActorId));
self.Address = StartConfigComponent.Instance.GetInnerAddress(IdGenerater.GetAppId(self.ActorId));
self.AllowGet();
return;
......
......@@ -11,7 +11,7 @@ namespace ETModel
{
throw new Exception($"actor id is 0");
}
IPEndPoint ipEndPoint = StartConfigComponent.Instance.GetInnerAddress(IdGenerater.GetAppIdFromId(actorId));
IPEndPoint ipEndPoint = StartConfigComponent.Instance.GetInnerAddress(IdGenerater.GetAppId(actorId));
ActorMessageSender actorMessageSender = new ActorMessageSender(actorId, ipEndPoint);
return actorMessageSender;
}
......
......@@ -11,7 +11,7 @@ namespace ETHotfix
public abstract class Component : Object, IDisposable
{
[BsonIgnore]
public long InstanceId { get; protected set; }
public long InstanceId { get; private set; }
#if !SERVER
public static GameObject Global { get; } = GameObject.Find("/Global");
......@@ -41,7 +41,7 @@ namespace ETHotfix
if (this.InstanceId == 0)
{
this.InstanceId = IdGenerater.GenerateId();
this.InstanceId = IdGenerater.GenerateInstanceId();
}
}
}
......@@ -99,7 +99,7 @@ namespace ETHotfix
protected Component()
{
this.InstanceId = IdGenerater.GenerateId();
this.InstanceId = IdGenerater.GenerateInstanceId();
#if !SERVER
if (!this.GetType().IsDefined(typeof(HideInHierarchy), true))
{
......
......@@ -8,12 +8,10 @@ namespace ETHotfix
public Scene()
{
this.InstanceId = IdGenerater.GenerateId();
}
public Scene(long id): base(id)
{
this.InstanceId = IdGenerater.GenerateId();
}
public override void Dispose()
......
fileFormatVersion: 2
guid: d84361f4f81274c3d807bb783cc8a864
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
......@@ -2,7 +2,18 @@
{
public static class IdGenerater
{
public static long AppId { private get; set; }
private static long instanceIdGenerator;
private static long appId;
public static long AppId
{
set
{
appId = value;
instanceIdGenerator = appId << 48;
}
}
private static ushort value;
......@@ -10,12 +21,17 @@
{
long time = TimeHelper.ClientNowSeconds();
return (AppId << 48) + (time << 16) + ++value;
return (appId << 48) + (time << 16) + ++value;
}
public static long GenerateInstanceId()
{
return ++instanceIdGenerator;
}
public static int GetAppIdFromId(long id)
public static int GetAppId(long v)
{
return (int)(id >> 48);
return (int)(v >> 48);
}
}
}
\ No newline at end of file
......@@ -11,7 +11,7 @@ namespace ETModel
public abstract class Component : Object, IDisposable
{
[BsonIgnore]
public long InstanceId { get; protected set; }
public long InstanceId { get; private set; }
#if !SERVER
public static GameObject Global { get; } = GameObject.Find("/Global");
......@@ -41,7 +41,7 @@ namespace ETModel
if (this.InstanceId == 0)
{
this.InstanceId = IdGenerater.GenerateId();
this.InstanceId = IdGenerater.GenerateInstanceId();
}
}
}
......@@ -99,7 +99,7 @@ namespace ETModel
protected Component()
{
this.InstanceId = IdGenerater.GenerateId();
this.InstanceId = IdGenerater.GenerateInstanceId();
#if !SERVER
if (!this.GetType().IsDefined(typeof(HideInHierarchy), true))
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册