diff --git a/CSharp/CSharp.sln b/CSharp/CSharp.sln index 8ee0f35f4cb6cddad4bb39dcc74b9f7c14f86c6a..fb75f87dfda434b3010195751c0fc0e1107c94ce 100644 --- a/CSharp/CSharp.sln +++ b/CSharp/CSharp.sln @@ -32,8 +32,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Game", "Game", "{D0CC1FF4-2 EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BehaviorTree", "Game\BehaviorTree\BehaviorTree.csproj", "{C4E7A34A-095C-4983-AB63-FC2D20CD6824}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "World", "Game\World\World.csproj", "{CBEDBE33-A883-4BFA-AE0A-8B3573F09BD0}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ENetExe", "Platform\ENetExe\ENetExe.csproj", "{CBA52DC8-1C80-4A79-9AC5-73514EBBD749}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{2814EB55-E1C2-4751-AC14-94116DA9D22B}" @@ -140,18 +138,6 @@ Global {C4E7A34A-095C-4983-AB63-FC2D20CD6824}.Release|Mixed Platforms.Build.0 = Release|Any CPU {C4E7A34A-095C-4983-AB63-FC2D20CD6824}.Release|Win32.ActiveCfg = Release|Any CPU {C4E7A34A-095C-4983-AB63-FC2D20CD6824}.Release|x86.ActiveCfg = Release|Any CPU - {CBEDBE33-A883-4BFA-AE0A-8B3573F09BD0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {CBEDBE33-A883-4BFA-AE0A-8B3573F09BD0}.Debug|Any CPU.Build.0 = Debug|Any CPU - {CBEDBE33-A883-4BFA-AE0A-8B3573F09BD0}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU - {CBEDBE33-A883-4BFA-AE0A-8B3573F09BD0}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU - {CBEDBE33-A883-4BFA-AE0A-8B3573F09BD0}.Debug|Win32.ActiveCfg = Debug|Any CPU - {CBEDBE33-A883-4BFA-AE0A-8B3573F09BD0}.Debug|x86.ActiveCfg = Debug|Any CPU - {CBEDBE33-A883-4BFA-AE0A-8B3573F09BD0}.Release|Any CPU.ActiveCfg = Release|Any CPU - {CBEDBE33-A883-4BFA-AE0A-8B3573F09BD0}.Release|Any CPU.Build.0 = Release|Any CPU - {CBEDBE33-A883-4BFA-AE0A-8B3573F09BD0}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU - {CBEDBE33-A883-4BFA-AE0A-8B3573F09BD0}.Release|Mixed Platforms.Build.0 = Release|Any CPU - {CBEDBE33-A883-4BFA-AE0A-8B3573F09BD0}.Release|Win32.ActiveCfg = Release|Any CPU - {CBEDBE33-A883-4BFA-AE0A-8B3573F09BD0}.Release|x86.ActiveCfg = Release|Any CPU {CBA52DC8-1C80-4A79-9AC5-73514EBBD749}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {CBA52DC8-1C80-4A79-9AC5-73514EBBD749}.Debug|Any CPU.Build.0 = Debug|Any CPU {CBA52DC8-1C80-4A79-9AC5-73514EBBD749}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU @@ -260,7 +246,6 @@ Global {D0B4CFAC-A368-4742-9863-68776CFA9938} = {ADBF5F67-B480-4A93-9D50-C81856FC61A9} {901A8E5C-C4C6-4C3C-8E18-068D75119F5D} = {ADBF5F67-B480-4A93-9D50-C81856FC61A9} {C4E7A34A-095C-4983-AB63-FC2D20CD6824} = {D0CC1FF4-2747-4278-A51F-BE9AA959175B} - {CBEDBE33-A883-4BFA-AE0A-8B3573F09BD0} = {D0CC1FF4-2747-4278-A51F-BE9AA959175B} {CBA52DC8-1C80-4A79-9AC5-73514EBBD749} = {ADBF5F67-B480-4A93-9D50-C81856FC61A9} {B42D431A-3A54-4649-942A-C5356D7F9FBC} = {ADBF5F67-B480-4A93-9D50-C81856FC61A9} {F176D1FA-63E5-4B89-9A03-D44CCCCC069A} = {ADBF5F67-B480-4A93-9D50-C81856FC61A9} diff --git a/CSharp/Config/BuffConfig/1.json b/CSharp/Config/BuffConfig/1.json new file mode 100644 index 0000000000000000000000000000000000000000..79fe3b2b9a28747ff0522983ef1c609e68397537 --- /dev/null +++ b/CSharp/Config/BuffConfig/1.json @@ -0,0 +1,6 @@ +{ + "_id" : 1, + "Type" : 0, + "Name" : "yun", + "Duration" : 1500, +} \ No newline at end of file diff --git a/CSharp/Config/GlobalConfig/1.json b/CSharp/Config/GlobalConfig/1.json index 4a1809f70a815d1b2fd71ea22349c9f581231c0f..51d648b2fe4a94367d449e8830ad1da7b49d511d 100644 --- a/CSharp/Config/GlobalConfig/1.json +++ b/CSharp/Config/GlobalConfig/1.json @@ -1,3 +1,4 @@ -{ +{ + "_id": 1 "Type" : 1 } \ No newline at end of file diff --git a/CSharp/Game/BehaviorTree/BehaviorTree.csproj b/CSharp/Game/BehaviorTree/BehaviorTree.csproj index 22b01a2303a48d05783e50bdc04b6e3f1711e0c4..8c587e6d07f323b8896e84398442cfd255c4bbd5 100644 --- a/CSharp/Game/BehaviorTree/BehaviorTree.csproj +++ b/CSharp/Game/BehaviorTree/BehaviorTree.csproj @@ -46,7 +46,6 @@ - @@ -60,6 +59,10 @@ {19f8f043-1f99-4550-99df-dea5c7d77e55} Common + + {0FA529D1-D0A9-4A8E-90F5-117CE80F2EDE} + Model + diff --git a/CSharp/Game/BehaviorTree/BehaviorTreeFactory.cs b/CSharp/Game/BehaviorTree/BehaviorTreeFactory.cs index 6c45113dbafeda67b2cbef8ded1a468b50b4e404..766bad4327e74076f3b13d4e809849dc3cbed083 100644 --- a/CSharp/Game/BehaviorTree/BehaviorTreeFactory.cs +++ b/CSharp/Game/BehaviorTree/BehaviorTreeFactory.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Reflection; +using Model; namespace BehaviorTree { diff --git a/CSharp/Game/BehaviorTree/Node.cs b/CSharp/Game/BehaviorTree/Node.cs index f138ed0285f319bf31b8d450e8aa84b5e9bda7f8..adc6f5cd9d13d7e4b0d13f7d990f57776963ad4c 100644 --- a/CSharp/Game/BehaviorTree/Node.cs +++ b/CSharp/Game/BehaviorTree/Node.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using Model; namespace BehaviorTree { diff --git a/CSharp/Game/BehaviorTree/Not.cs b/CSharp/Game/BehaviorTree/Not.cs index e5e9d643309a9fadd4ef04d03f95bf6e04f03f8f..1f867e5314d14c9d3be77ba1003d952c64f163cb 100644 --- a/CSharp/Game/BehaviorTree/Not.cs +++ b/CSharp/Game/BehaviorTree/Not.cs @@ -1,4 +1,6 @@ -namespace BehaviorTree +using Model; + +namespace BehaviorTree { [Node(NodeType.Not)] public class Not: Node diff --git a/CSharp/Game/BehaviorTree/Selector.cs b/CSharp/Game/BehaviorTree/Selector.cs index 0ff2ecb899c1beb944d1472c236599eb7c3b325b..37a8742100c3b83f47ea8af493ef8f7453a0e733 100644 --- a/CSharp/Game/BehaviorTree/Selector.cs +++ b/CSharp/Game/BehaviorTree/Selector.cs @@ -1,4 +1,6 @@ -namespace BehaviorTree +using Model; + +namespace BehaviorTree { [Node(NodeType.Selector)] public class Selector: Node diff --git a/CSharp/Game/BehaviorTree/Sequence.cs b/CSharp/Game/BehaviorTree/Sequence.cs index d8de93ba5eff0aebc6a6e695fd5863fb73be25bb..d482abba63d5e15dc1db50d0bcb7e5b3da4fb16b 100644 --- a/CSharp/Game/BehaviorTree/Sequence.cs +++ b/CSharp/Game/BehaviorTree/Sequence.cs @@ -1,4 +1,6 @@ -namespace BehaviorTree +using Model; + +namespace BehaviorTree { [Node(NodeType.Sequence)] internal class Sequence: Node diff --git a/CSharp/Game/Model/Buff.cs b/CSharp/Game/Model/Buff.cs index 5d4c197ecf9ccb5c4537ff5fb4bf4e95661d33a0..552b75f4e01ce25df00a0ade8545e6d3c124e22d 100644 --- a/CSharp/Game/Model/Buff.cs +++ b/CSharp/Game/Model/Buff.cs @@ -4,6 +4,19 @@ namespace Model { public class Buff: Object { - public BuffType Type { get; set; } + private int ConfigId { get; set; } + + public Buff(int configId) + { + this.ConfigId = configId; + } + + public BuffConfig Config + { + get + { + return World.Instance.ConfigManager.Get(this.ConfigId); + } + } } } \ No newline at end of file diff --git a/CSharp/Game/Model/BuffComponent.cs b/CSharp/Game/Model/BuffComponent.cs index ffcaf203e12969c28c7b6363f880d40169df7db9..1d0cd6e2a973a7fd51aa76ea51f9a934c6f6633b 100644 --- a/CSharp/Game/Model/BuffComponent.cs +++ b/CSharp/Game/Model/BuffComponent.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using Common.Base; using MongoDB.Bson; using MongoDB.Bson.Serialization.Attributes; @@ -11,14 +12,14 @@ namespace Model [BsonElement] private HashSet Buffs { get; set; } - private Dictionary buffGuidDict { get; set; } + private Dictionary buffIdDict { get; set; } private MultiMap buffTypeMMap { get; set; } public BuffComponent() { this.Buffs = new HashSet(); - this.buffGuidDict = new Dictionary(); + this.buffIdDict = new Dictionary(); this.buffTypeMMap = new MultiMap(); } @@ -26,43 +27,36 @@ namespace Model { foreach (var buff in this.Buffs) { - this.buffGuidDict.Add(buff.Guid, buff); - this.buffTypeMMap.Add(buff.Type, buff); + this.buffIdDict.Add(buff.Id, buff); + this.buffTypeMMap.Add(buff.Config.Type, buff); } } - public bool Add(Buff buff) + public void Add(Buff buff) { if (this.Buffs.Contains(buff)) { - return false; - } - - if (this.buffGuidDict.ContainsKey(buff.Guid)) - { - return false; + throw new ArgumentException(string.Format("already exist same buff, Id: {0} ConfigId: {1}", buff.Id, buff.Config.Id)); } - if (this.buffTypeMMap.GetOne(buff.Type) != null) + if (this.buffIdDict.ContainsKey(buff.Id)) { - return false; + throw new ArgumentException(string.Format("already exist same buff, Id: {0} ConfigId: {1}", buff.Id, buff.Config.Id)); } this.Buffs.Add(buff); - this.buffGuidDict.Add(buff.Guid, buff); - this.buffTypeMMap.Add(buff.Type, buff); - - return true; + this.buffIdDict.Add(buff.Id, buff); + this.buffTypeMMap.Add(buff.Config.Type, buff); } - public Buff GetByGuid(ObjectId guid) + public Buff GetById(ObjectId id) { - if (!this.buffGuidDict.ContainsKey(guid)) + if (!this.buffIdDict.ContainsKey(id)) { return null; } - return this.buffGuidDict[guid]; + return this.buffIdDict[id]; } public Buff GetOneByType(BuffType type) @@ -83,15 +77,15 @@ namespace Model } this.Buffs.Remove(buff); - this.buffGuidDict.Remove(buff.Guid); - this.buffTypeMMap.Remove(buff.Type, buff); + this.buffIdDict.Remove(buff.Id); + this.buffTypeMMap.Remove(buff.Config.Type, buff); return true; } - public bool RemoveByGuid(ObjectId guid) + public bool RemoveById(ObjectId id) { - Buff buff = this.GetByGuid(guid); + Buff buff = this.GetById(id); return this.Remove(buff); } diff --git a/CSharp/Game/Model/BuffConfig.cs b/CSharp/Game/Model/BuffConfig.cs new file mode 100644 index 0000000000000000000000000000000000000000..9e0ce52f941a38a9a49cc86408c1d6274c123467 --- /dev/null +++ b/CSharp/Game/Model/BuffConfig.cs @@ -0,0 +1,24 @@ +using System.Collections.Generic; +using Common.Config; + +namespace Model +{ + public class BuffConfig: AConfig + { + public BuffType Type { get; set; } + public string Name { get; set; } + public long Duration { get; set; } + public int MaxStack { get; set; } + public List Effects { get; set; } + + public BuffConfig() + { + this.Effects = new List(); + } + } + + [Config] + public class BuffCategory : ACategory + { + } +} diff --git a/CSharp/Game/Model/GameObjectManager.cs b/CSharp/Game/Model/GameObjectManager.cs index 89722a72a7a5143e19d818078f3d8ed9f42b5747..b076b512d781b541f7c5d0bfea8b19cad7fad737 100644 --- a/CSharp/Game/Model/GameObjectManager.cs +++ b/CSharp/Game/Model/GameObjectManager.cs @@ -15,18 +15,18 @@ namespace Model public void Add(GameObject gameObject) { - this.gameObjects.Add(gameObject.Guid, gameObject); + this.gameObjects.Add(gameObject.Id, gameObject); if (!this.typeGameObjects.ContainsKey(gameObject.Type)) { this.typeGameObjects.Add(gameObject.Type, new Dictionary()); } - this.typeGameObjects[gameObject.Type].Add(gameObject.Guid, gameObject); + this.typeGameObjects[gameObject.Type].Add(gameObject.Id, gameObject); } - public GameObject Get(ObjectId guid) + public GameObject Get(ObjectId id) { GameObject gameObject = null; - this.gameObjects.TryGetValue(guid, out gameObject); + this.gameObjects.TryGetValue(id, out gameObject); return gameObject; } @@ -46,20 +46,20 @@ namespace Model { throw new ArgumentNullException("gameObject"); } - if (!this.gameObjects.Remove(gameObject.Guid)) + if (!this.gameObjects.Remove(gameObject.Id)) { return false; } - if (!this.typeGameObjects[gameObject.Type].Remove(gameObject.Guid)) + if (!this.typeGameObjects[gameObject.Type].Remove(gameObject.Id)) { return false; } return true; } - public bool Remove(ObjectId guid) + public bool Remove(ObjectId id) { - GameObject gameObject = this.Get(guid); + GameObject gameObject = this.Get(id); if (gameObject == null) { return false; diff --git a/CSharp/Game/World/Config/GlobalConfig.cs b/CSharp/Game/Model/GlobalConfig.cs similarity index 52% rename from CSharp/Game/World/Config/GlobalConfig.cs rename to CSharp/Game/Model/GlobalConfig.cs index d696cae41cd74e362e2381932086cf16a061d5db..5d0715dba880385473c9818bb054578db2fcd4d7 100644 --- a/CSharp/Game/World/Config/GlobalConfig.cs +++ b/CSharp/Game/Model/GlobalConfig.cs @@ -1,10 +1,10 @@ using Common.Config; -namespace World.Config +namespace Model { - public class GlobalConfig: IConfig + public class GlobalConfig: AConfig { - public int Id { get; set; } + public int Type { get; set; } } [Config] diff --git a/CSharp/Game/Model/Model.csproj b/CSharp/Game/Model/Model.csproj index e0137ead6dc70c6430b299104499a8cd0db5e20e..cebde35d769a51a07e5072655bf2b5de0af35a66 100644 --- a/CSharp/Game/Model/Model.csproj +++ b/CSharp/Game/Model/Model.csproj @@ -47,9 +47,13 @@ + + + + diff --git a/CSharp/Game/BehaviorTree/NodeConfig.cs b/CSharp/Game/Model/NodeConfig.cs similarity index 74% rename from CSharp/Game/BehaviorTree/NodeConfig.cs rename to CSharp/Game/Model/NodeConfig.cs index 1114eb2b0466c54b48009cb6ba1e804f1aaa4151..9ea310ea041c07f90d005519b4cd13a770f43d9b 100644 --- a/CSharp/Game/BehaviorTree/NodeConfig.cs +++ b/CSharp/Game/Model/NodeConfig.cs @@ -2,12 +2,10 @@ using Common.Config; using MongoDB.Bson.Serialization.Attributes; -namespace BehaviorTree +namespace Model { - public class NodeConfig: IConfig + public class NodeConfig: AConfig { - public int Id { get; set; } - [BsonIgnoreIfNull] public List Args { get; set; } diff --git a/CSharp/Game/World/World.cs b/CSharp/Game/Model/World.cs similarity index 83% rename from CSharp/Game/World/World.cs rename to CSharp/Game/Model/World.cs index b402eefa86029f85045345fc5c97f3664a6350b4..53cff98277efe3fe6f406953d6aee41db9616ca0 100644 --- a/CSharp/Game/World/World.cs +++ b/CSharp/Game/Model/World.cs @@ -1,13 +1,12 @@ using Common.Config; -using Model; -namespace World +namespace Model { public class World { private static readonly World instance = new World(); - private readonly ConfigManager configManager = new ConfigManager(); + private readonly ConfigManager configManager = ConfigManager.Instance; private readonly GameObjectManager gameObjectManager = new GameObjectManager(); diff --git a/CSharp/Game/MongoDBTest/MongoDBTest.cs b/CSharp/Game/MongoDBTest/MongoDBTest.cs index 03e6d788ca6ebf70bdd0022c393eeb5ee6eff1b3..4213c79b9e6b1c1e419e069d3da3728bf092d4f0 100644 --- a/CSharp/Game/MongoDBTest/MongoDBTest.cs +++ b/CSharp/Game/MongoDBTest/MongoDBTest.cs @@ -21,12 +21,12 @@ namespace MongoDBTest var collection = database.GetCollection("GameObjects"); GameObject player1 = GameObjectFactory.CreatePlayer(); - player1.GetComponent().Add(new Buff()); + player1.GetComponent().Add(new Buff(1)); player1["hp"] = 10; collection.Insert(player1); - var query = Query.EQ(e => e.Guid, player1.Guid); + var query = Query.EQ(e => e.Id, player1.Id); GameObject player2 = collection.FindOne(query); Console.WriteLine(MongoHelper.ToJson(player2)); diff --git a/CSharp/Game/World/Properties/AssemblyInfo.cs b/CSharp/Game/World/Properties/AssemblyInfo.cs deleted file mode 100644 index d475e9816513797b48c9ab9be5e76f34bc4f89b9..0000000000000000000000000000000000000000 --- a/CSharp/Game/World/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,39 +0,0 @@ -using System.Reflection; -using System.Runtime.InteropServices; - -// 有关程序集的常规信息通过以下 -// 特性集控制。更改这些特性值可修改 -// 与程序集关联的信息。 - -[assembly: AssemblyTitle("Component")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("Component")] -[assembly: AssemblyCopyright("Copyright © 2013")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// 将 ComVisible 设置为 false 使此程序集中的类型 -// 对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型, -// 则将该类型上的 ComVisible 特性设置为 true。 - -[assembly: ComVisible(false)] - -// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID - -[assembly: Guid("55cc5b17-d8c8-4c34-922c-47afac13d174")] - -// 程序集的版本信息由下面四个值组成: -// -// 主版本 -// 次版本 -// 生成号 -// 修订号 -// -// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, -// 方法是按如下所示使用“*”: -// [assembly: AssemblyVersion("1.0.*")] - -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] \ No newline at end of file diff --git a/CSharp/Game/World/World.csproj b/CSharp/Game/World/World.csproj deleted file mode 100644 index ddcb1598e2b4958c455d609754456f843402ab5b..0000000000000000000000000000000000000000 --- a/CSharp/Game/World/World.csproj +++ /dev/null @@ -1,63 +0,0 @@ - - - - - Debug - AnyCPU - {CBEDBE33-A883-4BFA-AE0A-8B3573F09BD0} - Library - Properties - World - World - v4.5.1 - 512 - ..\..\ - true - - - - true - full - false - ..\..\Bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - ..\..\Bin\Release\ - TRACE - prompt - 4 - - - - - - - - - - - - - {19f8f043-1f99-4550-99df-dea5c7d77e55} - Common - - - {0fa529d1-d0a9-4a8e-90f5-117ce80f2ede} - Model - - - - - - \ No newline at end of file diff --git a/CSharp/Platform/Common/Base/Component.cs b/CSharp/Platform/Common/Base/Component.cs index afa3e07425467a1aa285d4cc8dbecc5146a1420f..72498c310dd49f3a653976682211aef8172dd61d 100644 --- a/CSharp/Platform/Common/Base/Component.cs +++ b/CSharp/Platform/Common/Base/Component.cs @@ -3,6 +3,9 @@ using MongoDB.Bson.Serialization.Attributes; namespace Common.Base { + /// + /// Component的Id与Owner Entity Id一样 + /// public abstract class Component : Object, ISupportInitialize { private Entity owner; @@ -17,7 +20,7 @@ namespace Common.Base set { this.owner = value; - this.Guid = this.owner.Guid; + this.Id = this.owner.Id; } } diff --git a/CSharp/Platform/Common/Base/Entity.cs b/CSharp/Platform/Common/Base/Entity.cs index 4783f99f7cd496aa37db1c3e1570dff3f774fc9c..efbd65bd8c058d80dcfb3b3e549c2a22271017cd 100644 --- a/CSharp/Platform/Common/Base/Entity.cs +++ b/CSharp/Platform/Common/Base/Entity.cs @@ -21,6 +21,12 @@ namespace Common.Base public void AddComponent() where T : Component, new() { + if (this.ComponentDict.ContainsKey(typeof (T))) + { + throw new Exception( + string.Format("AddComponent, component already exist, id: {0}, component: {1}", + this.Id, typeof(T).Name)); + } T t = new T { Owner = this }; this.Components.Add(t); this.ComponentDict.Add(typeof (T), t); @@ -29,7 +35,13 @@ namespace Common.Base public void RemoveComponent() where T : Component { Component t; - this.ComponentDict.TryGetValue(typeof(T), out t); + if (!this.ComponentDict.TryGetValue(typeof (T), out t)) + { + throw new Exception( + string.Format("RemoveComponent, component not exist, id: {0}, component: {1}", + this.Id, typeof(T).Name)); + } + this.Components.Remove(t); this.ComponentDict.Remove(typeof(T)); } @@ -39,7 +51,9 @@ namespace Common.Base Component t; if (!this.ComponentDict.TryGetValue(typeof (T), out t)) { - return null; + throw new Exception( + string.Format("GetComponent, component not exist, id: {0}, component: {1}", + this.Id, typeof(T).Name)); } return (T) t; } @@ -57,8 +71,8 @@ namespace Common.Base { foreach (Component component in this.Components) { - this.ComponentDict.Add(component.GetType(), component); component.Owner = this; + this.ComponentDict.Add(component.GetType(), component); } } } diff --git a/CSharp/Platform/Common/Base/Object.cs b/CSharp/Platform/Common/Base/Object.cs index 92c2760c7c97c515829222ebb9fc17259e63c8ad..b08114be9c267750add33d260860ccc212d5109d 100644 --- a/CSharp/Platform/Common/Base/Object.cs +++ b/CSharp/Platform/Common/Base/Object.cs @@ -7,7 +7,7 @@ namespace Common.Base public abstract class Object { [BsonId] - public ObjectId Guid { get; protected set; } + public ObjectId Id { get; protected set; } [BsonElement] [BsonIgnoreIfNull] @@ -15,12 +15,12 @@ namespace Common.Base protected Object() { - this.Guid = ObjectId.GenerateNewId(); + this.Id = ObjectId.GenerateNewId(); } - protected Object(ObjectId guid) + protected Object(ObjectId id) { - this.Guid = guid; + this.Id = id; } public object this[string key] diff --git a/CSharp/Platform/Common/Common.csproj b/CSharp/Platform/Common/Common.csproj index caf0f4009ed6f698d3b1f9030a150c97b2ab2d47..0529f8b902ba61a8390a1fb8e9952234c020247d 100644 --- a/CSharp/Platform/Common/Common.csproj +++ b/CSharp/Platform/Common/Common.csproj @@ -70,7 +70,7 @@ - + diff --git a/CSharp/Platform/Common/Config/ACategory.cs b/CSharp/Platform/Common/Config/ACategory.cs index 1178d65afc67ca716553a5b3dc6cf043a91ef356..8051ebfaffb7275a0806c3cb704968a1d75016f0 100644 --- a/CSharp/Platform/Common/Config/ACategory.cs +++ b/CSharp/Platform/Common/Config/ACategory.cs @@ -6,13 +6,13 @@ using Common.Helper; namespace Common.Config { - public abstract class ACategory: ICategory where T : IConfig + public abstract class ACategory: ICategory where T : AConfig { protected readonly Dictionary dict = new Dictionary(); - public void BeginInit() + public virtual void BeginInit() { - string path = Path.Combine(@"./Config/", this.Name); + string path = Path.Combine(@"../../Config/", typeof(T).Name); if (!Directory.Exists(path)) { @@ -26,23 +26,23 @@ namespace Common.Config } } - public void EndInit() - { - } - - public T this[int type] + public Type ConfigType { get { - return this.dict[type]; + return typeof (T); } } - public string Name + public virtual void EndInit() + { + } + + public T this[int type] { get { - return typeof (T).Name; + return this.dict[type]; } } diff --git a/CSharp/Platform/Common/Config/AConfig.cs b/CSharp/Platform/Common/Config/AConfig.cs new file mode 100644 index 0000000000000000000000000000000000000000..cd169c5f5cd3bf2d78110bcfa0503be2edb0443e --- /dev/null +++ b/CSharp/Platform/Common/Config/AConfig.cs @@ -0,0 +1,19 @@ +using System.ComponentModel; +using MongoDB.Bson.Serialization.Attributes; + +namespace Common.Config +{ + public abstract class AConfig: ISupportInitialize + { + [BsonId] + public int Id { get; set; } + + public virtual void BeginInit() + { + } + + public virtual void EndInit() + { + } + } +} \ No newline at end of file diff --git a/CSharp/Platform/Common/Config/ConfigManager.cs b/CSharp/Platform/Common/Config/ConfigManager.cs index 9d712b67d1e9567bfb6c8820913985abc27c5009..6a5de6ac1280e963ae103cf618ae0a2a16d2b502 100644 --- a/CSharp/Platform/Common/Config/ConfigManager.cs +++ b/CSharp/Platform/Common/Config/ConfigManager.cs @@ -1,20 +1,36 @@ using System; using System.Collections.Generic; using System.Reflection; +using Common.Logger; namespace Common.Config { public class ConfigManager { - public Dictionary allConfig; + private static ConfigManager instance = new ConfigManager(); + + public static ConfigManager Instance + { + get + { + return instance; + } + } + + public Dictionary allConfig; + + private ConfigManager() + { + } public void Load(Assembly assembly) { - var localAllConfig = new Dictionary(); + var localAllConfig = new Dictionary(); Type[] types = assembly.GetTypes(); - foreach (var type in types) + foreach (Type type in types) { object[] attrs = type.GetCustomAttributes(typeof (ConfigAttribute), false); + Log.Debug(type.Name); if (attrs.Length == 0) { continue; @@ -25,34 +41,45 @@ namespace Common.Config ICategory iCategory = obj as ICategory; if (iCategory == null) { - throw new Exception(string.Format("class: {0} not inherit from ACategory", - type.Name)); + throw new Exception( + string.Format("class: {0} not inherit from ACategory", type.Name)); } iCategory.BeginInit(); iCategory.EndInit(); - localAllConfig[type.Name] = obj; + localAllConfig[iCategory.ConfigType] = iCategory; } this.allConfig = localAllConfig; } - public T Get(int type) where T : IConfig + public T Get(int id) where T : AConfig { - var configCategory = (ACategory) this.allConfig[typeof (T).Name]; - return configCategory[type]; + Type type = typeof (T); + ICategory configCategory; + if (!this.allConfig.TryGetValue(type, out configCategory)) + { + throw new KeyNotFoundException(string.Format("ConfigManager not found key: {0}", type.FullName)); + } + return ((ACategory) configCategory)[id]; } - public T[] GetAll() where T : IConfig + public T[] GetAll() where T : AConfig { - var configCategory = (ACategory) this.allConfig[typeof (T).Name]; - return configCategory.GetAll(); + Type type = typeof(T); + ICategory configCategory; + if (!this.allConfig.TryGetValue(type, out configCategory)) + { + throw new KeyNotFoundException(string.Format("ConfigManager not found key: {0}", type.FullName)); + } + return ((ACategory)configCategory).GetAll(); } public T GetCategory() where T : class, ICategory, new() { T t = new T(); - object category; - bool ret = this.allConfig.TryGetValue(t.Name, out category); + Type type = t.ConfigType; + ICategory category; + bool ret = this.allConfig.TryGetValue(type, out category); return ret? (T) category : null; } } diff --git a/CSharp/Platform/Common/Config/ICategory.cs b/CSharp/Platform/Common/Config/ICategory.cs index c91f92827005b967c0178c50863797468ec243af..021dcca6d6f0feb3d9d4912688e61e1a569a59aa 100644 --- a/CSharp/Platform/Common/Config/ICategory.cs +++ b/CSharp/Platform/Common/Config/ICategory.cs @@ -1,9 +1,10 @@ -using System.ComponentModel; +using System; +using System.ComponentModel; namespace Common.Config { public interface ICategory: ISupportInitialize { - string Name { get; } + Type ConfigType { get; } } } \ No newline at end of file diff --git a/CSharp/Platform/Common/Config/IConfig.cs b/CSharp/Platform/Common/Config/IConfig.cs deleted file mode 100644 index 7e1be02f256377ce2c637d937ebe539ffb7016e3..0000000000000000000000000000000000000000 --- a/CSharp/Platform/Common/Config/IConfig.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace Common.Config -{ - public interface IConfig - { - int Id { get; } - } -} \ No newline at end of file diff --git a/CSharp/Platform/ENetTest/ENetTest.csproj b/CSharp/Platform/ENetTest/ENetTest.csproj index 21e67575458fe0b007485b7942c1516d6f634d67..c5c1491ae5ff7ae2420558b49dfd09a13c32c061 100644 --- a/CSharp/Platform/ENetTest/ENetTest.csproj +++ b/CSharp/Platform/ENetTest/ENetTest.csproj @@ -55,7 +55,6 @@ - @@ -67,6 +66,9 @@ ENet + + + diff --git a/CSharp/Platform/ENetTest/Properties/AssemblyInfo.cs b/CSharp/Platform/ENetTest/Properties/AssemblyInfo.cs deleted file mode 100644 index 71e4b0c25db3998292d24446cee72167bed0da67..0000000000000000000000000000000000000000 --- a/CSharp/Platform/ENetTest/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,39 +0,0 @@ -using System.Reflection; -using System.Runtime.InteropServices; - -// 有关程序集的常规信息通过以下特性集 -// 控制。更改这些特性值可修改 -// 与程序集关联的信息。 - -[assembly: AssemblyTitle("ENetCSTest")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Microsoft")] -[assembly: AssemblyProduct("ENetCSTest")] -[assembly: AssemblyCopyright("Copyright © Microsoft 2012")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// 将 ComVisible 设置为 false 会使此程序集中的类型 -// 对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型, -// 请将该类型上的 ComVisible 特性设置为 true。 - -[assembly: ComVisible(false)] - -// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID - -[assembly: Guid("b52f4804-3f6e-4268-810a-08fe8ca12bd0")] - -// 程序集的版本信息由以下四个值组成: -// -// 主版本 -// 次版本 -// 生成号 -// 修订号 -// -// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, -// 方法是按如下所示使用“*”: -// [assembly: AssemblyVersion("1.0.*")] - -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] \ No newline at end of file