提交 5449ef4b 编写于 作者: T tanghai

1.Mongo库在反序列化时会调用类的无参构造函数,这样在Component的无参构造函数中就不

能将对象Add到EventSystem中。
2.协程中将IsDispose判断对象释放改成用InstanceId来判断,因为对象池的原因,IsDisposed
方法并不能精确的判断对象是否释放,有可能释放之后又被重用了。
3.更新运行指南
上级 d08a45f6
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeEditing/Intellisense/CodeCompletion/IntelliSenseCompletingCharacters/CSharpCompletingCharacters/NonCompletingCharacters/@EntryValue"></s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=40533600_002D4E69_002D4F7D_002DA924_002DE1A3B4127255_002Fd_003ABase_002Fd_003AObject_002Ff_003AComponentWithId_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=40533600_002D4E69_002D4F7D_002DA924_002DE1A3B4127255_002Fd_003ABase_002Fd_003AObject_002Ff_003AEntity_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AC2G_005FEnterMapHandler_002Ecs_002Fl_003AServer_003FHotfix_003FHandler_003FC2G_005FEnterMapHandler_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AInnerOpcode_002Ecs_002Fl_003AServer_003FModel_003FEntity_003FMessage_003FInnerOpcode_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003APlayer_002Ecs_002Fl_003AUnity_003FAssets_003FScripts_003FEntity_003FPlayer_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003APlayerComponent_002Ecs_002Fl_003AUnity_003FAssets_003FScripts_003FComponent_003FPlayerComponent_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003APlayerFactory_002Ecs_002Fl_003AUnity_003FAssets_003FScripts_003FFactory_003FPlayerFactory_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AUnitComponent_002Ecs_002Fl_003AUnity_003FAssets_003FScripts_003FComponent_003FUnitComponent_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=CF118143_002D7E37_002D744F_002DBE45_002D3F55345FEC40_002Fd_003AAssets_002Fd_003AScripts_002Fd_003ABase_002Fd_003AObject_002Ff_003AComponent_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=CF118143_002D7E37_002D744F_002DBE45_002D3F55345FEC40_002Fd_003AAssets_002Fd_003AScripts_002Fd_003ABase_002Fd_003AObject_002Ff_003AComponentWithId_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=CF118143_002D7E37_002D744F_002DBE45_002D3F55345FEC40_002Fd_003AAssets_002Fd_003AScripts_002Fd_003ABase_002Fd_003AObject_002Ff_003AEntity_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=CF118143_002D7E37_002D744F_002DBE45_002D3F55345FEC40_002Fd_003AAssets_002Fd_003AScripts_002Fd_003AComponent_002Fd_003AConfig_002Ff_003AClientConfig_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=CF118143_002D7E37_002D744F_002DBE45_002D3F55345FEC40_002Fd_003AAssets_002Fd_003AScripts_002Fd_003AComponent_002Fd_003AConfig_002Ff_003AInnerConfig_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=EE38E3D2_002D3D2A_002D4061_002DBD50_002DAE8568126C7D_002Fd_003ABase_002Fd_003AObject_002Ff_003AEntityType_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=EE38E3D2_002D3D2A_002D4061_002DBD50_002DAE8568126C7D_002Fd_003AEntity_002Fd_003AConfig_002Ff_003AStartConfig_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=EE38E3D2_002D3D2A_002D4061_002DBD50_002DAE8568126C7D_002Fd_003AModule_002Fd_003AMessage_002Ff_003ANetInnerComponent_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/AnalysisEnabled/@EntryValue">VISIBLE_FILES</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=EnforceForeachStatementBraces/@EntryIndexedValue">HINT</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=EnforceIfStatementBraces/@EntryIndexedValue">HINT</s:String>
......
##### 1.visual studio必须使用vs2017(更新到最新版),其它版本不支持,VS2017需要勾选安装以下内容:
##### 1.visual studio必须使用vs2017(更新到最新版), Unity必须2017以上, VS2017需要勾选安装以下内容:
a. .net 桌面开发
b. visual studio tools for unity
c. .netcore2.0
##### 2. unity一定要安装 unity 2017.1.0p5到2017.1.2,其它版本不支持
##### 2. unity一定要安装 unity 2017.1.0p5到2017.1.2,其它版本参考初见的爬坑教程(readme中有链接),unity2018请自己摸索
##### 3. 启动unity2017, 菜单 File->open project->open 选中Egametang/Unity文件夹,点击选择文件夹按钮。
......@@ -23,7 +23,7 @@ VS2017 15.4版本vstools有bug,Hotfix工程请重新引用UnityEngin跟UnityEn
2.中文目录。
3.vs没有安装vs tools或者不是最新的vs tools。
4.没安装.netcore2.0
5.VS要更新到最新的15.5.4版本
5.VS要更新到最新的15.5.4版本以上
## 测试帧同步
......
......@@ -85,9 +85,12 @@ namespace ETHotfix
public static async void HandleAsync(this MailBoxComponent self)
{
ActorMessageDispatherComponent actorMessageDispatherComponent = Game.Scene.GetComponent<ActorMessageDispatherComponent>();
long instanceId = self.InstanceId;
while (true)
{
if (self.IsDisposed)
if (self.InstanceId != instanceId)
{
return;
}
......
......@@ -25,9 +25,11 @@ namespace ETHotfix
{
TimerComponent timerComponent = Game.Scene.GetComponent<TimerComponent>();
long instanceId = self.InstanceId;
while (true)
{
if (self.IsDisposed)
if (self.InstanceId != instanceId)
{
return;
}
......
......@@ -74,11 +74,13 @@ namespace ETModel
/// </summary>
private async void WatchProcessAsync()
{
long instanceId = this.InstanceId;
while (true)
{
await Game.Scene.GetComponent<TimerComponent>().WaitAsync(5000);
if (this.IsDisposed)
if (this.InstanceId != instanceId)
{
return;
}
......
......@@ -68,10 +68,13 @@ namespace ETModel
}
int rpcId = request.RpcId;
long instanceId = session.InstanceId;
await this.Run(e, request, response =>
{
// 等回调回来,session可以已经断开了
if (session.IsDisposed)
// 等回调回来,session可以已经断开了,所以需要判断session InstanceId是否一样
if (session.InstanceId != instanceId)
{
return;
}
......
......@@ -18,9 +18,11 @@ namespace ETModel
{
public override async void Start(DBTaskQueue self)
{
long instanceId = self.InstanceId;
while (true)
{
if (self.IsDisposed)
if (self.InstanceId != instanceId)
{
return;
}
......
......@@ -176,9 +176,11 @@ namespace ETModel
public async void Accept()
{
long instanceId = this.InstanceId;
while (true)
{
if (this.IsDisposed)
if (this.InstanceId != instanceId)
{
return;
}
......
......@@ -25,10 +25,13 @@ namespace ETModel
}
int rpcId = request.RpcId;
long instanceId = session.InstanceId;
this.Run(session, request, response =>
{
// 等回调回来,session可以已经断开了,所以需要判断session id是否为0
if (session.IsDisposed)
// 等回调回来,session可以已经断开了,所以需要判断session InstanceId是否一样
if (session.InstanceId != instanceId)
{
return;
}
......
......@@ -4,7 +4,7 @@ using MongoDB.Bson.Serialization.Attributes;
namespace ETModel
{
[BsonIgnoreExtraElements]
public abstract partial class Component : Object, IDisposable
public abstract class Component : Object, IDisposable
{
[BsonIgnore]
public long InstanceId { get; protected set; }
......@@ -23,11 +23,17 @@ namespace ETModel
{
this.isFromPool = value;
if (!this.isFromPool)
{
return;
}
if (this.InstanceId == 0)
{
this.InstanceId = IdGenerater.GenerateId();
Game.EventSystem.Add(this);
}
Game.EventSystem.Add(this);
}
}
......@@ -56,11 +62,10 @@ namespace ETModel
return this.Parent as Entity;
}
}
protected Component()
{
this.InstanceId = IdGenerater.GenerateId();
Game.EventSystem.Add(this);
}
public virtual void Dispose()
......
......@@ -4,7 +4,7 @@ using MongoDB.Bson.Serialization.Attributes;
namespace ETModel
{
[BsonIgnoreExtraElements]
public abstract partial class ComponentWithId : Component
public abstract class ComponentWithId : Component
{
[BsonIgnoreIfDefault]
[BsonDefaultValue(0L)]
......
......@@ -6,7 +6,7 @@ using MongoDB.Bson.Serialization.Attributes;
namespace ETModel
{
[BsonIgnoreExtraElements]
public partial class Entity : ComponentWithId
public class Entity : ComponentWithId
{
[BsonElement]
[BsonIgnoreIfNull]
......@@ -15,7 +15,7 @@ namespace ETModel
[BsonIgnore]
private Dictionary<Type, Component> componentDict;
protected Entity()
public Entity()
{
this.components = new HashSet<Component>();
this.componentDict = new Dictionary<Type, Component>();
......@@ -211,18 +211,12 @@ namespace ETModel
return this.componentDict.Values.ToArray();
}
public override void BeginInit()
{
this.components = new HashSet<Component>();
this.componentDict = new Dictionary<Type, Component>();
}
public override void EndInit()
{
try
{
this.InstanceId = IdGenerater.GenerateId();
base.EndInit();
this.componentDict.Clear();
if (this.components != null)
......
......@@ -19,17 +19,18 @@ namespace ETModel
if (queue.Count > 0)
{
obj = queue.Dequeue();
obj.IsFromPool = true;
return obj;
}
obj = (Component)Activator.CreateInstance(type);
else
{
obj = (Component)Activator.CreateInstance(type);
}
obj.IsFromPool = true;
return obj;
}
public T Fetch<T>() where T: Component
{
T t = (T) this.Fetch(typeof(T));
t.IsFromPool = true;
return t;
}
......
......@@ -18,12 +18,12 @@ namespace ETModel
public override async void Start(UILoadingComponent self)
{
TimerComponent timerComponent = Game.Scene.GetComponent<TimerComponent>();
long instanceId = self.InstanceId;
while (true)
{
await timerComponent.WaitAsync(1000);
if (self.IsDisposed)
if (self.InstanceId != instanceId)
{
return;
}
......
......@@ -4,7 +4,7 @@ using MongoDB.Bson.Serialization.Attributes;
namespace ETHotfix
{
[BsonIgnoreExtraElements]
public abstract partial class Component : Object, IDisposable
public abstract class Component : Object, IDisposable
{
[BsonIgnore]
public long InstanceId { get; protected set; }
......@@ -23,11 +23,17 @@ namespace ETHotfix
{
this.isFromPool = value;
if (!this.isFromPool)
{
return;
}
if (this.InstanceId == 0)
{
this.InstanceId = IdGenerater.GenerateId();
Game.EventSystem.Add(this);
}
Game.EventSystem.Add(this);
}
}
......@@ -60,9 +66,8 @@ namespace ETHotfix
protected Component()
{
this.InstanceId = IdGenerater.GenerateId();
Game.EventSystem.Add(this);
}
public virtual void Dispose()
{
if (this.IsDisposed)
......
......@@ -4,7 +4,7 @@ using MongoDB.Bson.Serialization.Attributes;
namespace ETHotfix
{
[BsonIgnoreExtraElements]
public abstract partial class ComponentWithId : Component
public abstract class ComponentWithId : Component
{
[BsonIgnoreIfDefault]
[BsonDefaultValue(0L)]
......
......@@ -191,17 +191,11 @@ namespace ETHotfix
return this.componentDict.Values.ToArray();
}
public override void BeginInit()
{
this.components = new HashSet<Component>();
this.componentDict = new Dictionary<Type, Component>();
}
public override void EndInit()
{
try
{
this.InstanceId = IdGenerater.GenerateId();
base.EndInit();
this.componentDict.Clear();
......
......@@ -19,20 +19,21 @@ namespace ETHotfix
if (queue.Count > 0)
{
obj = queue.Dequeue();
obj.IsFromPool = true;
return obj;
}
obj = (Component)Activator.CreateInstance(type);
else
{
obj = (Component)Activator.CreateInstance(type);
}
obj.IsFromPool = true;
return obj;
}
public T Fetch<T>() where T : Component
public T Fetch<T>() where T: Component
{
T t = (T)this.Fetch(typeof(T));
t.IsFromPool = true;
T t = (T) this.Fetch(typeof(T));
return t;
}
public void Recycle(Component obj)
{
Type type = obj.GetType();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册