移除 重构

移除 重构
This commit is contained in:
ALEXTANG
2023-07-13 12:46:26 +08:00
parent 8757e1f550
commit a69f53592e
1165 changed files with 0 additions and 41317 deletions

View File

@@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: fdae3569c5cbfe54e97778a1f7e7af21
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: 8d0854a24c1619b43ace830bfa1b6e69
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,15 +0,0 @@
using System;
namespace ET
{
[AttributeUsage(AttributeTargets.Class)]
public class ChildOfAttribute : Attribute
{
public Type type;
public ChildOfAttribute(Type type = null)
{
this.type = type;
}
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 9e06bd31e846d9a4abe88d5864a0a4d3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,20 +0,0 @@
using System;
namespace ET
{
/// <summary>
/// 组件类父级实体类型约束
/// 父级实体类型唯一的 标记指定父级实体类型[ComponentOf(typeof(parentType)]
/// 不唯一则标记[ComponentOf]
/// </summary>
[AttributeUsage(AttributeTargets.Class)]
public class ComponentOfAttribute : Attribute
{
public Type Type;
public ComponentOfAttribute(Type type = null)
{
this.Type = type;
}
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 3e17786fd2fafce4f9d9fbdcdbf5b9fc
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,15 +0,0 @@
using System;
namespace ET
{
/// <summary>
/// 当方法或属性内需要访问Entity类的child和component时 使用此标签
/// 仅供必要时使用 大多数情况推荐通过Entity的子类访问
/// </summary>
[AttributeUsage(AttributeTargets.Method|AttributeTargets.Property)]
public class EnableAccessEntiyChildAttribute : Attribute
{
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 5b4d17f76cb73474e94eb82e30be2560
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,6 +0,0 @@
namespace ET
{
public class EnableClassAttribute: BaseAttribute
{
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 41028c857d1434bd78bb45a748e476e8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,13 +0,0 @@
using System;
namespace ET
{
/// <summary>
/// 对于特殊实体类 允许类内部声明方法的标签
/// </summary>
[AttributeUsage(AttributeTargets.Class, Inherited = false)]
public class EnableMethodAttribute : Attribute
{
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: ce20015df46fb774eaf1cacc7cd9e35b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,26 +0,0 @@
using System;
namespace ET
{
[AttributeUsage(AttributeTargets.Class)]
public class EntitySystemOfAttribute: BaseAttribute
{
public Type type;
public EntitySystemOfAttribute(Type type)
{
this.type = type;
}
}
[AttributeUsage(AttributeTargets.Class)]
public class LSEntitySystemOfAttribute: BaseAttribute
{
public Type type;
public LSEntitySystemOfAttribute(Type type)
{
this.type = type;
}
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 50901d1f8551c05499583f1a5d362d06
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,16 +0,0 @@
using System;
namespace ET
{
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = false)]
public class FriendOfAttribute : Attribute
{
public Type Type;
public FriendOfAttribute(Type type)
{
this.Type = type;
}
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 516811198a72ec541a5f8f0e40454fa5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,36 +0,0 @@
using System;
namespace ET
{
/// <summary>
/// 静态字段需加此标签
/// valueToAssign: 初始化时的字段值
/// assignNewTypeInstance: 从默认构造函数初始化
/// </summary>
[AttributeUsage(AttributeTargets.Field)]
public class StaticFieldAttribute: Attribute
{
public readonly object valueToAssign;
public readonly bool assignNewTypeInstance;
public StaticFieldAttribute()
{
this.valueToAssign = null;
this.assignNewTypeInstance = false;
}
public StaticFieldAttribute(object valueToAssign )
{
this.valueToAssign = valueToAssign ;
this.assignNewTypeInstance = false;
}
public StaticFieldAttribute(bool assignNewTypeInstance)
{
this.valueToAssign = null;
this.assignNewTypeInstance = assignNewTypeInstance;
}
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: f0f1fd366c9df9c439b8e552ac26e607
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,24 +0,0 @@
using System;
namespace ET
{
/// <summary>
/// 唯一Id标签
/// 使用此标签标记的类 会检测类内部的 const int 字段成员是否唯一
/// 可以指定唯一Id的最小值 最大值区间
/// </summary>
[AttributeUsage(AttributeTargets.Class, Inherited = false)]
public class UniqueIdAttribute : Attribute
{
public int Min;
public int Max;
public UniqueIdAttribute(int min = int.MinValue, int max = int.MaxValue)
{
this.Min = min;
this.Max = max;
}
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 62584bd88ecb9ce439aeaaf2f76605f5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,144 +0,0 @@
using System;
using System.Collections.Generic;
namespace ET
{
public class DoubleMap<K, V>
{
private readonly Dictionary<K, V> kv = new Dictionary<K, V>();
private readonly Dictionary<V, K> vk = new Dictionary<V, K>();
public DoubleMap()
{
}
public DoubleMap(int capacity)
{
kv = new Dictionary<K, V>(capacity);
vk = new Dictionary<V, K>(capacity);
}
public void ForEach(Action<K, V> action)
{
if (action == null)
{
return;
}
Dictionary<K, V>.KeyCollection keys = kv.Keys;
foreach (K key in keys)
{
action(key, kv[key]);
}
}
public List<K> Keys
{
get
{
return new List<K>(kv.Keys);
}
}
public List<V> Values
{
get
{
return new List<V>(vk.Keys);
}
}
public void Add(K key, V value)
{
if (key == null || value == null || kv.ContainsKey(key) || vk.ContainsKey(value))
{
return;
}
kv.Add(key, value);
vk.Add(value, key);
}
public V GetValueByKey(K key)
{
if (key != null && kv.ContainsKey(key))
{
return kv[key];
}
return default(V);
}
public K GetKeyByValue(V value)
{
if (value != null && vk.ContainsKey(value))
{
return vk[value];
}
return default(K);
}
public void RemoveByKey(K key)
{
if (key == null)
{
return;
}
V value;
if (!kv.TryGetValue(key, out value))
{
return;
}
kv.Remove(key);
vk.Remove(value);
}
public void RemoveByValue(V value)
{
if (value == null)
{
return;
}
K key;
if (!vk.TryGetValue(value, out key))
{
return;
}
kv.Remove(key);
vk.Remove(value);
}
public void Clear()
{
kv.Clear();
vk.Clear();
}
public bool ContainsKey(K key)
{
if (key == null)
{
return false;
}
return kv.ContainsKey(key);
}
public bool ContainsValue(V value)
{
if (value == null)
{
return false;
}
return vk.ContainsKey(value);
}
public bool Contains(K key, V value)
{
if (key == null || value == null)
{
return false;
}
return kv.ContainsKey(key) && vk.ContainsKey(value);
}
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 715c9cf0f50f1fb4c98a8783cb1da714
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: afe14daee40145d44938d748993f4775
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,15 +0,0 @@
#if ENABLE_VIEW && UNITY_EDITOR
using UnityEngine;
namespace ET
{
public class ComponentView: MonoBehaviour
{
public Entity Component
{
get;
set;
}
}
}
#endif

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 97f627452e3dae143943e08b0c5b20ef
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load Diff

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 580c95b9e9aaeba43a04eff4ff74b46e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,30 +0,0 @@
namespace ET
{
public static class EntityHelper
{
public static int Zone(this Entity entity)
{
return entity.IScene.Fiber.Zone;
}
public static Scene Scene(this Entity entity)
{
return entity.IScene as Scene;
}
public static T Scene<T>(this Entity entity) where T: class, IScene
{
return entity.IScene as T;
}
public static Scene Root(this Entity entity)
{
return entity.IScene.Fiber.Root;
}
public static Fiber Fiber(this Entity entity)
{
return entity.IScene.Fiber;
}
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 3ac02684a9489804d80e99f7ae99b548
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,103 +0,0 @@
using System;
namespace ET
{
public readonly struct EntityRef<T> where T: Entity
{
private readonly long instanceId;
private readonly T entity;
private EntityRef(T t)
{
if (t == null)
{
this.instanceId = 0;
this.entity = null;
return;
}
this.instanceId = t.InstanceId;
this.entity = t;
}
private T UnWrap
{
get
{
if (this.entity == null)
{
return null;
}
if (this.entity.InstanceId != this.instanceId)
{
return null;
}
return this.entity;
}
}
public static implicit operator EntityRef<T>(T t)
{
return new EntityRef<T>(t);
}
public static implicit operator T(EntityRef<T> v)
{
return v.UnWrap;
}
}
public struct EntityWeakRef<T> where T: Entity
{
private long instanceId;
// 使用WeakReference这样不会导致entity dispose了却无法gc的问题
// 不过暂时没有测试WeakReference的性能
private readonly WeakReference<T> weakRef;
private EntityWeakRef(T t)
{
if (t != null)
{
this.instanceId = 0;
this.weakRef = null;
return;
}
this.instanceId = t.InstanceId;
this.weakRef = new WeakReference<T>(t);
}
private T UnWrap
{
get
{
if (this.instanceId == 0)
{
return null;
}
if (!this.weakRef.TryGetTarget(out T entity))
{
this.instanceId = 0;
return null;
}
if (entity.InstanceId != this.instanceId)
{
this.instanceId = 0;
return null;
}
return entity;
}
}
public static implicit operator EntityWeakRef<T>(T t)
{
return new EntityWeakRef<T>(t);
}
public static implicit operator T(EntityWeakRef<T> v)
{
return v.UnWrap;
}
}
}

View File

@@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: ef22211834964fd8aced938aa4307f76
timeCreated: 1683206917

View File

@@ -1,12 +0,0 @@
namespace ET
{
public static class EntitySceneFactory
{
public static Scene CreateScene(Entity parent, long id, long instanceId, SceneType sceneType, string name)
{
Scene scene = new(parent.Fiber(), id, instanceId, sceneType, name);
parent?.AddChild(scene);
return scene;
}
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 91cb0fe18962a644b8760cf0191d3da3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,9 +0,0 @@
using System;
namespace ET
{
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
public class EntitySystemAttribute: BaseAttribute
{
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: da6ad6e58e6b617428d5fa989149b624
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,302 +0,0 @@
using System;
using System.Collections.Generic;
namespace ET
{
public class EntitySystemSingleton: SingletonLock<EntitySystemSingleton>, ISingletonAwake
{
public TypeSystems TypeSystems { get; private set; }
public void Awake()
{
this.TypeSystems = new TypeSystems(InstanceQueueIndex.Max);
foreach (Type type in EventSystem.Instance.GetTypes(typeof (EntitySystemAttribute)))
{
object obj = Activator.CreateInstance(type);
if (obj is ISystemType iSystemType)
{
TypeSystems.OneTypeSystems oneTypeSystems = this.TypeSystems.GetOrCreateOneTypeSystems(iSystemType.Type());
oneTypeSystems.Map.Add(iSystemType.SystemType(), obj);
int index = iSystemType.GetInstanceQueueIndex();
if (index > InstanceQueueIndex.None && index < InstanceQueueIndex.Max)
{
oneTypeSystems.QueueFlag[index] = true;
}
}
}
}
public override void Load()
{
World.Instance.AddSingleton<EntitySystemSingleton>(true);
}
public void Serialize(Entity component)
{
if (component is not ISerialize)
{
return;
}
List<object> iSerializeSystems = this.TypeSystems.GetSystems(component.GetType(), typeof (ISerializeSystem));
if (iSerializeSystems == null)
{
return;
}
foreach (ISerializeSystem serializeSystem in iSerializeSystems)
{
if (serializeSystem == null)
{
continue;
}
try
{
serializeSystem.Run(component);
}
catch (Exception e)
{
Log.Error(e);
}
}
}
public void Deserialize(Entity component)
{
if (component is not IDeserialize)
{
return;
}
List<object> iDeserializeSystems = this.TypeSystems.GetSystems(component.GetType(), typeof (IDeserializeSystem));
if (iDeserializeSystems == null)
{
return;
}
foreach (IDeserializeSystem deserializeSystem in iDeserializeSystems)
{
if (deserializeSystem == null)
{
continue;
}
try
{
deserializeSystem.Run(component);
}
catch (Exception e)
{
Log.Error(e);
}
}
}
// GetComponentSystem
public void GetComponent(Entity entity, Entity component)
{
List<object> iGetSystem = this.TypeSystems.GetSystems(entity.GetType(), typeof (IGetComponentSystem));
if (iGetSystem == null)
{
return;
}
foreach (IGetComponentSystem getSystem in iGetSystem)
{
if (getSystem == null)
{
continue;
}
try
{
getSystem.Run(entity, component);
}
catch (Exception e)
{
Log.Error(e);
}
}
}
// AddComponentSystem
public void AddComponent(Entity entity, Entity component)
{
List<object> iAddSystem = this.TypeSystems.GetSystems(entity.GetType(), typeof (IAddComponentSystem));
if (iAddSystem == null)
{
return;
}
foreach (IAddComponentSystem addComponentSystem in iAddSystem)
{
if (addComponentSystem == null)
{
continue;
}
try
{
addComponentSystem.Run(entity, component);
}
catch (Exception e)
{
Log.Error(e);
}
}
}
public void Awake(Entity component)
{
List<object> iAwakeSystems = this.TypeSystems.GetSystems(component.GetType(), typeof (IAwakeSystem));
if (iAwakeSystems == null)
{
return;
}
foreach (IAwakeSystem aAwakeSystem in iAwakeSystems)
{
if (aAwakeSystem == null)
{
continue;
}
try
{
aAwakeSystem.Run(component);
}
catch (Exception e)
{
Log.Error(e);
}
}
}
public void Awake<P1>(Entity component, P1 p1)
{
if (component is not IAwake<P1>)
{
return;
}
List<object> iAwakeSystems = this.TypeSystems.GetSystems(component.GetType(), typeof (IAwakeSystem<P1>));
if (iAwakeSystems == null)
{
return;
}
foreach (IAwakeSystem<P1> aAwakeSystem in iAwakeSystems)
{
if (aAwakeSystem == null)
{
continue;
}
try
{
aAwakeSystem.Run(component, p1);
}
catch (Exception e)
{
Log.Error(e);
}
}
}
public void Awake<P1, P2>(Entity component, P1 p1, P2 p2)
{
if (component is not IAwake<P1, P2>)
{
return;
}
List<object> iAwakeSystems = this.TypeSystems.GetSystems(component.GetType(), typeof (IAwakeSystem<P1, P2>));
if (iAwakeSystems == null)
{
return;
}
foreach (IAwakeSystem<P1, P2> aAwakeSystem in iAwakeSystems)
{
if (aAwakeSystem == null)
{
continue;
}
try
{
aAwakeSystem.Run(component, p1, p2);
}
catch (Exception e)
{
Log.Error(e);
}
}
}
public void Awake<P1, P2, P3>(Entity component, P1 p1, P2 p2, P3 p3)
{
if (component is not IAwake<P1, P2, P3>)
{
return;
}
List<object> iAwakeSystems = this.TypeSystems.GetSystems(component.GetType(), typeof (IAwakeSystem<P1, P2, P3>));
if (iAwakeSystems == null)
{
return;
}
foreach (IAwakeSystem<P1, P2, P3> aAwakeSystem in iAwakeSystems)
{
if (aAwakeSystem == null)
{
continue;
}
try
{
aAwakeSystem.Run(component, p1, p2, p3);
}
catch (Exception e)
{
Log.Error(e);
}
}
}
public void Destroy(Entity component)
{
if (component is not IDestroy)
{
return;
}
List<object> iDestroySystems = this.TypeSystems.GetSystems(component.GetType(), typeof (IDestroySystem));
if (iDestroySystems == null)
{
return;
}
foreach (IDestroySystem iDestroySystem in iDestroySystems)
{
if (iDestroySystem == null)
{
continue;
}
try
{
iDestroySystem.Run(component);
}
catch (Exception e)
{
Log.Error(e);
}
}
}
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: ab1220efbaef9ff4ba4b28802b82707d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,39 +0,0 @@
using System;
namespace ET
{
public interface IAddComponent
{
}
public interface IAddComponentSystem: ISystemType
{
void Run(Entity o, Entity component);
}
[EntitySystem]
public abstract class AddComponentSystem<T> : IAddComponentSystem where T: Entity, IAddComponent
{
void IAddComponentSystem.Run(Entity o, Entity component)
{
this.AddComponent((T)o, component);
}
Type ISystemType.SystemType()
{
return typeof(IAddComponentSystem);
}
int ISystemType.GetInstanceQueueIndex()
{
return InstanceQueueIndex.None;
}
Type ISystemType.Type()
{
return typeof(T);
}
protected abstract void AddComponent(T self, Entity component);
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 02bfd8725134ded4b9aa4b56067911ca
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,179 +0,0 @@
using System;
namespace ET
{
public interface IAwake
{
}
public interface IAwake<A>
{
}
public interface IAwake<A, B>
{
}
public interface IAwake<A, B, C>
{
}
public interface IAwake<A, B, C, D>
{
}
public interface IAwakeSystem: ISystemType
{
void Run(Entity o);
}
public interface IAwakeSystem<A>: ISystemType
{
void Run(Entity o, A a);
}
public interface IAwakeSystem<A, B>: ISystemType
{
void Run(Entity o, A a, B b);
}
public interface IAwakeSystem<A, B, C>: ISystemType
{
void Run(Entity o, A a, B b, C c);
}
public interface IAwakeSystem<A, B, C, D>: ISystemType
{
void Run(Entity o, A a, B b, C c, D d);
}
[EntitySystem]
public abstract class AwakeSystem<T> : IAwakeSystem where T: Entity, IAwake
{
Type ISystemType.Type()
{
return typeof(T);
}
Type ISystemType.SystemType()
{
return typeof(IAwakeSystem);
}
int ISystemType.GetInstanceQueueIndex()
{
return InstanceQueueIndex.None;
}
void IAwakeSystem.Run(Entity o)
{
this.Awake((T)o);
}
protected abstract void Awake(T self);
}
[EntitySystem]
public abstract class AwakeSystem<T, A> : IAwakeSystem<A> where T: Entity, IAwake<A>
{
Type ISystemType.Type()
{
return typeof(T);
}
Type ISystemType.SystemType()
{
return typeof(IAwakeSystem<A>);
}
int ISystemType.GetInstanceQueueIndex()
{
return InstanceQueueIndex.None;
}
void IAwakeSystem<A>.Run(Entity o, A a)
{
this.Awake((T)o, a);
}
protected abstract void Awake(T self, A a);
}
[EntitySystem]
public abstract class AwakeSystem<T, A, B> : IAwakeSystem<A, B> where T: Entity, IAwake<A, B>
{
Type ISystemType.Type()
{
return typeof(T);
}
Type ISystemType.SystemType()
{
return typeof(IAwakeSystem<A, B>);
}
int ISystemType.GetInstanceQueueIndex()
{
return InstanceQueueIndex.None;
}
void IAwakeSystem<A, B>.Run(Entity o, A a, B b)
{
this.Awake((T)o, a, b);
}
protected abstract void Awake(T self, A a, B b);
}
[EntitySystem]
public abstract class AwakeSystem<T, A, B, C> : IAwakeSystem<A, B, C> where T: Entity, IAwake<A, B, C>
{
Type ISystemType.Type()
{
return typeof(T);
}
Type ISystemType.SystemType()
{
return typeof(IAwakeSystem<A, B, C>);
}
int ISystemType.GetInstanceQueueIndex()
{
return InstanceQueueIndex.None;
}
void IAwakeSystem<A, B, C>.Run(Entity o, A a, B b, C c)
{
this.Awake((T)o, a, b, c);
}
protected abstract void Awake(T self, A a, B b, C c);
}
[EntitySystem]
public abstract class AwakeSystem<T, A, B, C, D> : IAwakeSystem<A, B, C, D> where T: Entity, IAwake<A, B, C, D>
{
Type ISystemType.Type()
{
return typeof(T);
}
Type ISystemType.SystemType()
{
return typeof(IAwakeSystem<A, B, C, D>);
}
int ISystemType.GetInstanceQueueIndex()
{
return InstanceQueueIndex.None;
}
void IAwakeSystem<A, B, C, D>.Run(Entity o, A a, B b, C c, D d)
{
this.Awake((T)o, a, b, c, d);
}
protected abstract void Awake(T self, A a, B b, C c, D d);
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 0a89095a5a372eb46ab2bec0761147a5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,43 +0,0 @@
using System;
namespace ET
{
public interface IDeserialize
{
}
public interface IDeserializeSystem: ISystemType
{
void Run(Entity o);
}
/// <summary>
/// 反序列化后执行的System
/// </summary>
/// <typeparam name="T"></typeparam>
[EntitySystem]
public abstract class DeserializeSystem<T> : IDeserializeSystem where T: Entity, IDeserialize
{
void IDeserializeSystem.Run(Entity o)
{
this.Deserialize((T)o);
}
Type ISystemType.SystemType()
{
return typeof(IDeserializeSystem);
}
int ISystemType.GetInstanceQueueIndex()
{
return InstanceQueueIndex.None;
}
Type ISystemType.Type()
{
return typeof(T);
}
protected abstract void Deserialize(T self);
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: b3eef0324ea2ae64aa1dbd2eedeb969b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,39 +0,0 @@
using System;
namespace ET
{
public interface IDestroy
{
}
public interface IDestroySystem: ISystemType
{
void Run(Entity o);
}
[EntitySystem]
public abstract class DestroySystem<T> : IDestroySystem where T: Entity, IDestroy
{
void IDestroySystem.Run(Entity o)
{
this.Destroy((T)o);
}
Type ISystemType.SystemType()
{
return typeof(IDestroySystem);
}
int ISystemType.GetInstanceQueueIndex()
{
return InstanceQueueIndex.None;
}
Type ISystemType.Type()
{
return typeof(T);
}
protected abstract void Destroy(T self);
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: a5e8cbd88e2fbf7449f64a9c21902e14
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,43 +0,0 @@
using System;
namespace ET
{
// GetComponentSystem有巨大作用比如每次保存Unit的数据不需要所有组件都保存只需要保存Unit变化过的组件
// 是否变化可以通过判断该组件是否GetComponentGet了就记录该组件
// 这样可以只保存Unit变化过的组件
// 再比如传送也可以做此类优化
public interface IGetComponent
{
}
public interface IGetComponentSystem: ISystemType
{
void Run(Entity o, Entity component);
}
[EntitySystem]
public abstract class GetComponentSystem<T> : IGetComponentSystem where T: Entity, IGetComponent
{
void IGetComponentSystem.Run(Entity o, Entity component)
{
this.GetComponent((T)o, component);
}
Type ISystemType.SystemType()
{
return typeof(IGetComponentSystem);
}
int ISystemType.GetInstanceQueueIndex()
{
return InstanceQueueIndex.None;
}
Type ISystemType.Type()
{
return typeof(T);
}
protected abstract void GetComponent(T self, Entity component);
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 29d1c2616b1b96540a5f57836f3175e2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,39 +0,0 @@
using System;
namespace ET
{
public interface ILateUpdate
{
}
public interface ILateUpdateSystem: ISystemType
{
void Run(Entity o);
}
[EntitySystem]
public abstract class LateUpdateSystem<T> : ILateUpdateSystem where T: Entity, ILateUpdate
{
void ILateUpdateSystem.Run(Entity o)
{
this.LateUpdate((T)o);
}
Type ISystemType.Type()
{
return typeof(T);
}
Type ISystemType.SystemType()
{
return typeof(ILateUpdateSystem);
}
int ISystemType.GetInstanceQueueIndex()
{
return InstanceQueueIndex.LateUpdate;
}
protected abstract void LateUpdate(T self);
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: b5b9e3fed1722394e93a75aa14151a96
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,8 +0,0 @@
namespace ET
{
public interface IScene
{
Fiber Fiber { get; set; }
SceneType SceneType { get; set; }
}
}

View File

@@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 18e1047315ac4b4e9d873d9056514569
timeCreated: 1687171102

View File

@@ -1,43 +0,0 @@
using System;
namespace ET
{
public interface ISerialize
{
}
public interface ISerializeSystem: ISystemType
{
void Run(Entity o);
}
/// <summary>
/// 序列化前执行的System
/// </summary>
/// <typeparam name="T"></typeparam>
[EntitySystem]
public abstract class SerializeSystem<T> : ISerializeSystem where T: Entity, ISerialize
{
void ISerializeSystem.Run(Entity o)
{
this.Serialize((T)o);
}
Type ISystemType.SystemType()
{
return typeof(ISerializeSystem);
}
int ISystemType.GetInstanceQueueIndex()
{
return InstanceQueueIndex.None;
}
Type ISystemType.Type()
{
return typeof(T);
}
protected abstract void Serialize(T self);
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 9616e34ec2374bd4da31fc60b48d4cb7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,6 +0,0 @@
namespace ET
{
public interface ISerializeToEntity
{
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 3ab4ba4dfcb46e143a33b1e1597cee9a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,11 +0,0 @@
using System;
namespace ET
{
public interface ISystemType
{
Type Type();
Type SystemType();
int GetInstanceQueueIndex();
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: f5e007ff607d40c4a94a00007a2cb150
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,8 +0,0 @@
namespace ET
{
// Unit的组件有这个接口说明需要传送
public interface ITransfer
{
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 382f25012ae6c8747bb25dd3070bf703
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,39 +0,0 @@
using System;
namespace ET
{
public interface IUpdate
{
}
public interface IUpdateSystem: ISystemType
{
void Run(Entity o);
}
[EntitySystem]
public abstract class UpdateSystem<T> : IUpdateSystem where T: Entity, IUpdate
{
void IUpdateSystem.Run(Entity o)
{
this.Update((T)o);
}
Type ISystemType.Type()
{
return typeof(T);
}
Type ISystemType.SystemType()
{
return typeof(IUpdateSystem);
}
int ISystemType.GetInstanceQueueIndex()
{
return InstanceQueueIndex.Update;
}
protected abstract void Update(T self);
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 2b8bad203b3067940b9f4264adacecef
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,11 +0,0 @@
namespace ET
{
public static class InstanceQueueIndex
{
public const int None = -1;
public const int Update = 0;
public const int LateUpdate = 1;
public const int Load = 2;
public const int Max = 3;
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 839a3936286df0e46b43323334005d63
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,54 +0,0 @@
using System.Diagnostics;
using MongoDB.Bson.Serialization.Attributes;
namespace ET
{
[EnableMethod]
[ChildOf]
public class Scene: Entity, IScene
{
[BsonIgnore]
public Fiber Fiber { get; set; }
public string Name { get; }
public SceneType SceneType
{
get;
set;
}
public Scene()
{
}
public Scene(Fiber fiber, long id, long instanceId, SceneType sceneType, string name)
{
this.Id = id;
this.Name = name;
this.InstanceId = instanceId;
this.SceneType = sceneType;
this.IsCreated = true;
this.IsNew = true;
this.Fiber = fiber;
this.IScene = this;
this.IsRegister = true;
Log.Info($"scene create: {this.SceneType} {this.Id} {this.InstanceId}");
}
public override void Dispose()
{
base.Dispose();
Log.Info($"scene dispose: {this.SceneType} {this.Id} {this.InstanceId}");
}
protected override string ViewName
{
get
{
return $"{this.GetType().Name} ({this.SceneType})";
}
}
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: b20fe3ac8d3755b4582fbc0751d8cf8b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,51 +0,0 @@
using System;
namespace ET
{
[Flags]
public enum SceneType: long
{
None = 0,
Main = 1, // 主纤程,一个进程一个, 初始化从这里开始
NetInner = 1 << 2, // 负责进程间消息通信
Realm = 1 << 3,
Gate = 1 << 4,
Http = 1 << 5,
Location = 1 << 6,
Map = 1 << 7,
Router = 1 << 8,
RouterManager = 1 << 9,
Robot = 1 << 10,
BenchmarkClient = 1 << 11,
BenchmarkServer = 1 << 12,
Benchmark = 1 << 13,
Match = 1 << 14,
Room = 1 << 15,
LockStepClient = 1 << 16,
LockStepServer = 1 << 17,
RoomRoot = 1 << 18,
Watcher = 1 << 19,
// 客户端
Demo = 1 << 30,
Current = 1L << 31,
LockStep = 1L << 32,
LockStepView = 1L << 33,
DemoView = 1L << 34,
NetClient = 1L << 35,
All = long.MaxValue,
}
public static class SceneTypeHelper
{
public static bool HasSameFlag(this SceneType a, SceneType b)
{
if (((ulong) a & (ulong) b) == 0)
{
return false;
}
return true;
}
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: b36ca6be079a1bb458f59657482f6260
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: 2fd29b3ff6f09434a9de8b2a26016ea8
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,134 +0,0 @@
using System;
using System.Collections.Generic;
namespace ET
{
public class EntitySystem
{
private readonly Queue<EntityRef<Entity>>[] queues = new Queue<EntityRef<Entity>>[InstanceQueueIndex.Max];
public EntitySystem()
{
for (int i = 0; i < this.queues.Length; i++)
{
this.queues[i] = new Queue<EntityRef<Entity>>();
}
}
public virtual void RegisterSystem(Entity component)
{
Type type = component.GetType();
TypeSystems.OneTypeSystems oneTypeSystems = EntitySystemSingleton.Instance.TypeSystems.GetOneTypeSystems(type);
if (oneTypeSystems == null)
{
return;
}
for (int i = 0; i < oneTypeSystems.QueueFlag.Length; ++i)
{
if (!oneTypeSystems.QueueFlag[i])
{
continue;
}
this.queues[i].Enqueue(component);
}
}
public void Update()
{
Queue<EntityRef<Entity>> queue = this.queues[InstanceQueueIndex.Update];
int count = queue.Count;
while (count-- > 0)
{
Entity component = queue.Dequeue();
if (component == null)
{
continue;
}
if (component.IsDisposed)
{
continue;
}
if (component is not IUpdate)
{
continue;
}
try
{
List<object> iUpdateSystems = EntitySystemSingleton.Instance.TypeSystems.GetSystems(component.GetType(), typeof (IUpdateSystem));
if (iUpdateSystems == null)
{
continue;
}
queue.Enqueue(component);
foreach (IUpdateSystem iUpdateSystem in iUpdateSystems)
{
try
{
iUpdateSystem.Run(component);
}
catch (Exception e)
{
Log.Error(e);
}
}
}
catch (Exception e)
{
throw new Exception($"entity system update fail: {component.GetType().FullName}", e);
}
}
}
public void LateUpdate()
{
Queue<EntityRef<Entity>> queue = this.queues[InstanceQueueIndex.LateUpdate];
int count = queue.Count;
while (count-- > 0)
{
Entity component = queue.Dequeue();
if (component == null)
{
continue;
}
if (component.IsDisposed)
{
continue;
}
if (component is not ILateUpdate)
{
continue;
}
List<object> iLateUpdateSystems = EntitySystemSingleton.Instance.TypeSystems.GetSystems(component.GetType(), typeof (ILateUpdateSystem));
if (iLateUpdateSystems == null)
{
continue;
}
queue.Enqueue(component);
foreach (ILateUpdateSystem iLateUpdateSystem in iLateUpdateSystems)
{
try
{
iLateUpdateSystem.Run(component);
}
catch (Exception e)
{
Log.Error(e);
}
}
}
}
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 322c7636f08cf8443b7c6db151a61ce4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,153 +0,0 @@
using System;
using System.Collections.Generic;
using System.Threading;
namespace ET
{
public static class FiberHelper
{
public static ActorId GetActorId(this Entity self)
{
Fiber root = self.Fiber();
return new ActorId(root.Process, root.Id, self.InstanceId);
}
}
public class Fiber: IDisposable
{
public bool IsDisposed;
public int Id;
public int Zone;
public Scene Root { get; }
public Address Address
{
get
{
return new Address(this.Process, this.Id);
}
}
public int Process { get; }
public EntitySystem EntitySystem { get; }
public TimeInfo TimeInfo { get; }
public IdGenerater IdGenerater { get; private set; }
public Mailboxes Mailboxes { get; private set; }
public ThreadSynchronizationContext ThreadSynchronizationContext { get; }
private EntityRef<TimerComponent> timerCompnent;
public TimerComponent TimerComponent
{
get
{
return this.timerCompnent;
}
set
{
this.timerCompnent = value;
}
}
private EntityRef<CoroutineLockComponent> coroutineLockComponent;
public CoroutineLockComponent CoroutineLockComponent
{
get
{
return this.coroutineLockComponent;
}
set
{
this.coroutineLockComponent = value;
}
}
private EntityRef<ActorInnerComponent> actorInnerComponent;
public ActorInnerComponent ActorInnerComponent
{
get
{
return this.actorInnerComponent;
}
set
{
this.actorInnerComponent = value;
}
}
private readonly Queue<ETTask> frameFinishTasks = new();
internal Fiber(int id, int process, int zone, SceneType sceneType, string name)
{
this.Id = id;
this.Process = process;
this.Zone = zone;
this.EntitySystem = new EntitySystem();
this.TimeInfo = new TimeInfo();
this.IdGenerater = new IdGenerater(process, this.TimeInfo);
this.Mailboxes = new Mailboxes();
this.ThreadSynchronizationContext = new ThreadSynchronizationContext();
this.Root = new Scene(this, id, 1, sceneType, name);
}
internal void Update()
{
try
{
this.TimeInfo.Update();
this.EntitySystem.Update();
}
catch (Exception e)
{
Log.Error(e);
}
}
internal void LateUpdate()
{
try
{
this.EntitySystem.LateUpdate();
FrameFinishUpdate();
this.ThreadSynchronizationContext.Update();
}
catch (Exception e)
{
Log.Error(e);
}
}
public async ETTask WaitFrameFinish()
{
ETTask task = ETTask.Create(true);
this.frameFinishTasks.Enqueue(task);
await task;
}
private void FrameFinishUpdate()
{
while (this.frameFinishTasks.Count > 0)
{
ETTask task = this.frameFinishTasks.Dequeue();
task.SetResult();
}
}
public void Dispose()
{
if (this.IsDisposed)
{
return;
}
this.IsDisposed = true;
FiberManager.Instance.RemoveReal(this.Id);
this.Root.Dispose();
}
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 490d7e982e85adf41a5bfd1307271d25
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,155 +0,0 @@
using System;
using System.Runtime.InteropServices;
namespace ET
{
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct IdStruct
{
public short Process; // 14bit
public uint Time; // 30bit
public uint Value; // 20bit
public long ToLong()
{
ulong result = 0;
result |= (ushort) this.Process;
result <<= 14;
result |= this.Time;
result <<= 30;
result |= this.Value;
return (long) result;
}
public IdStruct(uint time, short process, uint value)
{
this.Process = process;
this.Time = time;
this.Value = value;
}
public IdStruct(long id)
{
ulong result = (ulong) id;
this.Value = (ushort) (result & IdGenerater.Mask20bit);
result >>= 20;
this.Time = (uint) result & IdGenerater.Mask30bit;
result >>= 30;
this.Process = (short) (result & IdGenerater.Mask14bit);
}
public override string ToString()
{
return $"process: {this.Process}, time: {this.Time}, value: {this.Value}";
}
}
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct InstanceIdStruct
{
public uint Time; // 32bit
public uint Value; // 32bit
public long ToLong()
{
ulong result = 0;
result |= this.Time;
result <<= 32;
result |= this.Value;
return (long) result;
}
public InstanceIdStruct(uint time, uint value)
{
this.Time = time;
this.Value = value;
}
public InstanceIdStruct(long id)
{
ulong result = (ulong) id;
this.Value = (uint)(result & uint.MaxValue);
result >>= 32;
this.Time = (uint)(result & uint.MaxValue);
}
public override string ToString()
{
return $"time: {this.Time}, value: {this.Value}";
}
}
public class IdGenerater
{
public const int MaxZone = 1024;
public const int Mask14bit = 0x3fff;
public const int Mask30bit = 0x3fffffff;
public const int Mask20bit = 0xfffff;
private readonly long epoch2022;
private uint value;
private uint lastIdTime;
private readonly TimeInfo timeInfo;
private readonly int process;
private uint instanceIdValue;
public IdGenerater(int process, TimeInfo timeInfo)
{
this.process = process;
this.timeInfo = timeInfo;
long epoch1970tick = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).Ticks / 10000;
this.epoch2022 = new DateTime(2022, 1, 1, 0, 0, 0, DateTimeKind.Utc).Ticks / 10000 - epoch1970tick;
this.lastIdTime = TimeSince2022();
if (this.lastIdTime <= 0)
{
Log.Warning($"lastIdTime less than 0: {this.lastIdTime}");
this.lastIdTime = 1;
}
}
private uint TimeSince2022()
{
uint a = (uint)((this.timeInfo.FrameTime - this.epoch2022) / 1000);
return a;
}
public long GenerateId()
{
uint time = TimeSince2022();
// 时间不会倒退
if (time > this.lastIdTime)
{
this.lastIdTime = time;
}
this.value = IdValueGenerater.Instance.Value;
IdStruct idStruct = new(this.lastIdTime, (short)this.process, value);
return idStruct.ToLong();
}
public long GenerateInstanceId()
{
uint time = this.TimeSince2022();
// 时间不会倒退
if (time > this.lastIdTime)
{
this.lastIdTime = time;
}
++this.instanceIdValue;
if (this.instanceIdValue >= int.MaxValue)
{
this.instanceIdValue = 0;
}
InstanceIdStruct instanceIdStruct = new(this.lastIdTime, this.instanceIdValue);
return instanceIdStruct.ToLong();
}
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 01dd1407fbf957f41a818bcfb700c7ed
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,50 +0,0 @@
namespace ET
{
[EntitySystemOf(typeof(MailBoxComponent))]
[FriendOf(typeof(MailBoxComponent))]
public static partial class MailBoxComponentSystem
{
[EntitySystem]
private static void Awake(this MailBoxComponent self, MailBoxType mailBoxType)
{
Fiber fiber = self.Fiber();
self.MailBoxType = mailBoxType;
self.ParentInstanceId = self.Parent.InstanceId;
fiber.Mailboxes.Add(self);
self.CoroutineLockComponent = fiber.CoroutineLockComponent;
}
[EntitySystem]
private static void Destroy(this MailBoxComponent self)
{
self.Fiber().Mailboxes.Remove(self.ParentInstanceId);
}
// 加到mailbox
public static void Add(this MailBoxComponent self, Address fromAddress, MessageObject messageObject)
{
// 根据mailboxType进行分发处理
EventSystem.Instance.Invoke((long)self.MailBoxType, new MailBoxInvoker() {MailBoxComponent = self, MessageObject = messageObject, FromAddress = fromAddress});
}
}
public struct MailBoxInvoker
{
public Address FromAddress;
public MessageObject MessageObject;
public MailBoxComponent MailBoxComponent;
}
/// <summary>
/// 挂上这个组件表示该Entity是一个Actor,接收的消息将会队列处理
/// </summary>
[ComponentOf]
public class MailBoxComponent: Entity, IAwake<MailBoxType>, IDestroy
{
public long ParentInstanceId { get; set; }
// Mailbox的类型
public MailBoxType MailBoxType { get; set; }
public CoroutineLockComponent CoroutineLockComponent { get; set; }
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: c7ab28162e70e0a45b7935f05a5526de
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,9 +0,0 @@
namespace ET
{
public enum MailBoxType
{
OrderedMessage = 1,
UnOrderedMessage,
GateSession,
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 75dc09ab9ad11c744ba5e2a9aba5d848
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,25 +0,0 @@
using System.Collections.Generic;
namespace ET
{
public class Mailboxes
{
private readonly Dictionary<long, MailBoxComponent> mailboxes = new();
public void Add(MailBoxComponent mailBoxComponent)
{
this.mailboxes.Add(mailBoxComponent.Parent.InstanceId, mailBoxComponent);
}
public void Remove(long instanceId)
{
this.mailboxes.Remove(instanceId);
}
public MailBoxComponent Get(long instanceId)
{
this.mailboxes.TryGetValue(instanceId, out MailBoxComponent entity);
return entity;
}
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: b7748d833ec77144bbadc98f35a923fa
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: ca1c1efa24a1cc648bba7858f5040e69
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: 43270a1ae7e8422458e49f6855475e8c
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,16 +0,0 @@
using System;
namespace ET
{
public static class ActorHelper
{
public static IActorResponse CreateResponse(IActorRequest iActorRequest, int error)
{
Type responseType = OpcodeType.Instance.GetResponseType(iActorRequest.GetType());
IActorResponse response = (IActorResponse)ObjectPool.Instance.Fetch(responseType);
response.Error = error;
response.RpcId = iActorRequest.RpcId;
return response;
}
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: a98f0108855505546a19aa3fb9aeba48
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,16 +0,0 @@
using System.Collections.Generic;
namespace ET
{
[ComponentOf(typeof(Scene))]
public class ActorInnerComponent: Entity, IAwake, IDestroy, IUpdate
{
public const long TIMEOUT_TIME = 40 * 1000;
public int RpcId;
public readonly Dictionary<int, ActorMessageSender> requestCallback = new();
public readonly List<ActorMessageInfo> list = new();
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: d74a2fe39353d9c498e360f72bca8080
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,193 +0,0 @@
using System;
using System.Collections.Generic;
using System.IO;
namespace ET
{
[EntitySystemOf(typeof(ActorInnerComponent))]
[FriendOf(typeof(ActorInnerComponent))]
public static partial class ActorInnerComponentSystem
{
[EntitySystem]
private static void Destroy(this ActorInnerComponent self)
{
Fiber fiber = self.Fiber();
ActorMessageQueue.Instance.RemoveQueue(fiber.Id);
}
[EntitySystem]
private static void Awake(this ActorInnerComponent self)
{
Fiber fiber = self.Fiber();
ActorMessageQueue.Instance.AddQueue(fiber.Id);
fiber.ActorInnerComponent = self;
}
[EntitySystem]
private static void Update(this ActorInnerComponent self)
{
self.list.Clear();
Fiber fiber = self.Fiber();
ActorMessageQueue.Instance.Fetch(fiber.Id, 1000, self.list);
ActorInnerComponent actorInnerComponent = fiber.Root.GetComponent<ActorInnerComponent>();
foreach (ActorMessageInfo actorMessageInfo in self.list)
{
if (actorMessageInfo.MessageObject is IActorResponse response)
{
actorInnerComponent.HandleIActorResponse(response);
continue;
}
ActorId actorId = actorMessageInfo.ActorId;
MessageObject message = actorMessageInfo.MessageObject;
MailBoxComponent mailBoxComponent = self.Fiber().Mailboxes.Get(actorId.InstanceId);
if (mailBoxComponent == null)
{
Log.Warning($"actor not found mailbox, from: {actorId} current: {fiber.Address} {message}");
if (message is IActorRequest request)
{
IActorResponse resp = ActorHelper.CreateResponse(request, ErrorCore.ERR_NotFoundActor);
actorInnerComponent.Reply(actorId.Address, resp);
}
return;
}
mailBoxComponent.Add(actorId.Address, message);
}
}
public static void HandleIActorResponse(this ActorInnerComponent self, IActorResponse response)
{
if (!self.requestCallback.Remove(response.RpcId, out ActorMessageSender actorMessageSender))
{
return;
}
Run(actorMessageSender, response);
}
private static void Run(ActorMessageSender self, IActorResponse response)
{
if (response.Error == ErrorCore.ERR_ActorTimeout)
{
self.Tcs.SetException(new Exception($"Rpc error: request, 注意Actor消息超时请注意查看是否死锁或者没有reply: actorId: {self.ActorId} {self.Request}, response: {response}"));
return;
}
if (self.NeedException && ErrorCore.IsRpcNeedThrowException(response.Error))
{
self.Tcs.SetException(new Exception($"Rpc error: actorId: {self.ActorId} request: {self.Request}, response: {response}"));
return;
}
self.Tcs.SetResult(response);
}
public static void Reply(this ActorInnerComponent self, Address fromAddress, IActorResponse message)
{
self.Send(new ActorId(fromAddress, 0), message);
}
public static void Send(this ActorInnerComponent self, ActorId actorId, IActorMessage message)
{
Fiber fiber = self.Fiber();
// 如果发向同一个进程,则扔到消息队列中
if (actorId.Process != fiber.Process)
{
throw new Exception($"actor inner process diff: {actorId.Process} {fiber.Process}");
}
ActorMessageQueue.Instance.Send(fiber.Address, actorId, (MessageObject)message);
}
private static void SendInner(this ActorInnerComponent self, ActorId actorId, MessageObject message)
{
Fiber fiber = self.Fiber();
ActorMessageQueue.Instance.Send(fiber.Address, actorId, message);
}
public static int GetRpcId(this ActorInnerComponent self)
{
return ++self.RpcId;
}
public static async ETTask<IActorResponse> Call(
this ActorInnerComponent self,
ActorId actorId,
IActorRequest request,
bool needException = true
)
{
request.RpcId = self.GetRpcId();
if (actorId == default)
{
throw new Exception($"actor id is 0: {request}");
}
return await self.Call(actorId, request.RpcId, request, needException);
}
public static async ETTask<IActorResponse> Call(
this ActorInnerComponent self,
ActorId actorId,
int rpcId,
IActorRequest iActorRequest,
bool needException = true
)
{
if (actorId == default)
{
throw new Exception($"actor id is 0: {iActorRequest}");
}
Fiber fiber = self.Fiber();
if (fiber.Process != actorId.Process)
{
throw new Exception($"actor inner process diff: {actorId.Process} {fiber.Process}");
}
var tcs = ETTask<IActorResponse>.Create(true);
self.requestCallback.Add(rpcId, new ActorMessageSender(actorId, iActorRequest, tcs, needException));
self.SendInner(actorId, iActorRequest as MessageObject);
async ETTask Timeout()
{
await fiber.TimerComponent.WaitAsync(ActorInnerComponent.TIMEOUT_TIME);
if (!self.requestCallback.Remove(rpcId, out ActorMessageSender action))
{
return;
}
if (needException)
{
action.Tcs.SetException(new Exception($"actor sender timeout: {iActorRequest}"));
}
else
{
IActorResponse response = ActorHelper.CreateResponse(iActorRequest, ErrorCore.ERR_Timeout);
action.Tcs.SetResult(response);
}
}
Timeout().Coroutine();
long beginTime = fiber.TimeInfo.ServerFrameTime();
IActorResponse response = await tcs;
long endTime = fiber.TimeInfo.ServerFrameTime();
long costTime = endTime - beginTime;
if (costTime > 200)
{
Log.Warning($"actor rpc time > 200: {costTime} {iActorRequest}");
}
return response;
}
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: ceb83d81c9c72a340887562f24d51629
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,24 +0,0 @@
using System.IO;
namespace ET
{
// 知道对方的instanceId使用这个类发actor消息
public readonly struct ActorMessageSender
{
public ActorId ActorId { get; }
public IActorRequest Request { get; }
public bool NeedException { get; }
public ETTask<IActorResponse> Tcs { get; }
public ActorMessageSender(ActorId actorId, IActorRequest iActorRequest, ETTask<IActorResponse> tcs, bool needException)
{
this.ActorId = actorId;
this.Request = iActorRequest;
this.Tcs = tcs;
this.NeedException = needException;
}
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: b51d51733a35791478b6a487b5196dd3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: 25135ca97055fb64fa240b23a01794cb
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,33 +0,0 @@
using System;
namespace ET
{
[EntitySystemOf(typeof(CoroutineLock))]
public static partial class CoroutineLockSystem
{
[EntitySystem]
private static void Awake(this CoroutineLock self, int type, long k, int count)
{
self.type = type;
self.key = k;
self.level = count;
}
[EntitySystem]
private static void Destroy(this CoroutineLock self)
{
self.Scene<CoroutineLockComponent>().RunNextCoroutine(self.type, self.key, self.level + 1);
self.type = CoroutineLockType.None;
self.key = 0;
self.level = 0;
}
}
[ChildOf(typeof(CoroutineLockQueue))]
public class CoroutineLock: Entity, IAwake<int, long, int>, IDestroy
{
public int type;
public long key;
public int level;
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 92e2f035a00b77c498465fbfb5bc4f0d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,62 +0,0 @@
using System;
using System.Collections.Generic;
namespace ET
{
[EntitySystemOf(typeof(CoroutineLockComponent))]
public static partial class CoroutineLockComponentSystem
{
[EntitySystem]
public static void Awake(this CoroutineLockComponent self)
{
self.Fiber.CoroutineLockComponent = self;
}
[EntitySystem]
public static void Update(this CoroutineLockComponent self)
{
// 循环过程中会有对象继续加入队列
while (self.nextFrameRun.Count > 0)
{
(int coroutineLockType, long key, int count) = self.nextFrameRun.Dequeue();
self.Notify(coroutineLockType, key, count);
}
}
public static void RunNextCoroutine(this CoroutineLockComponent self, int coroutineLockType, long key, int level)
{
// 一个协程队列一帧处理超过100个,说明比较多了,打个warning,检查一下是否够正常
if (level == 100)
{
Log.Warning($"too much coroutine level: {coroutineLockType} {key}");
}
self.nextFrameRun.Enqueue((coroutineLockType, key, level));
}
public static async ETTask<CoroutineLock> Wait(this CoroutineLockComponent self, int coroutineLockType, long key, int time = 60000)
{
CoroutineLockQueueType coroutineLockQueueType = self.GetChild<CoroutineLockQueueType>(coroutineLockType) ?? self.AddChildWithId<CoroutineLockQueueType>(coroutineLockType);
return await coroutineLockQueueType.Wait(key, time);
}
private static void Notify(this CoroutineLockComponent self, int coroutineLockType, long key, int level)
{
CoroutineLockQueueType coroutineLockQueueType = self.GetChild<CoroutineLockQueueType>(coroutineLockType);
if (coroutineLockQueueType == null)
{
return;
}
coroutineLockQueueType.Notify(key, level);
}
}
[ComponentOf(typeof(Scene))]
public class CoroutineLockComponent: Entity, IAwake, IScene, IUpdate
{
public Fiber Fiber { get; set; }
public SceneType SceneType { get; set; }
public readonly Queue<(int, long, int)> nextFrameRun = new();
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: c025fcd3d7a7add45851a0c7b93c6674
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,91 +0,0 @@
using System;
using System.Collections.Generic;
namespace ET
{
[EntitySystemOf(typeof(CoroutineLockQueue))]
public static partial class CoroutineLockQueueSystem
{
[EntitySystem]
private static void Awake(this CoroutineLockQueue self, int type)
{
self.type = type;
}
[EntitySystem]
private static void Destroy(this CoroutineLockQueue self)
{
self.queue.Clear();
self.type = 0;
self.CurrentCoroutineLock = null;
}
public static async ETTask<CoroutineLock> Wait(this CoroutineLockQueue self, int time)
{
if (self.CurrentCoroutineLock == null)
{
self.CurrentCoroutineLock = self.AddChild<CoroutineLock, int, long, int>(self.type, self.Id, 1, true);
return self.CurrentCoroutineLock;
}
WaitCoroutineLock waitCoroutineLock = WaitCoroutineLock.Create();
self.queue.Enqueue(waitCoroutineLock);
if (time > 0)
{
long tillTime = self.Fiber().TimeInfo.ClientFrameTime() + time;
self.Root().GetComponent<TimerComponent>().NewOnceTimer(tillTime, TimerCoreInvokeType.CoroutineTimeout, waitCoroutineLock);
}
self.CurrentCoroutineLock = await waitCoroutineLock.Wait();
return self.CurrentCoroutineLock;
}
public static void Notify(this CoroutineLockQueue self, int level)
{
// 有可能WaitCoroutineLock已经超时抛出异常所以要找到一个未处理的WaitCoroutineLock
while (self.queue.Count > 0)
{
WaitCoroutineLock waitCoroutineLock = self.queue.Dequeue();
if (waitCoroutineLock.IsDisposed())
{
continue;
}
CoroutineLock coroutineLock = self.AddChild<CoroutineLock, int, long, int>(self.type, self.Id, level, true);
waitCoroutineLock.SetResult(coroutineLock);
break;
}
}
}
[ChildOf(typeof(CoroutineLockQueueType))]
public class CoroutineLockQueue: Entity, IAwake<int>, IDestroy
{
public int type;
private EntityRef<CoroutineLock> currentCoroutineLock;
public CoroutineLock CurrentCoroutineLock
{
get
{
return this.currentCoroutineLock;
}
set
{
this.currentCoroutineLock = value;
}
}
public Queue<WaitCoroutineLock> queue = new();
public int Count
{
get
{
return this.queue.Count;
}
}
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 75bebf4862d839045a78140d260ecc11
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,57 +0,0 @@
using System.Collections.Generic;
namespace ET
{
[EntitySystemOf(typeof(CoroutineLockQueueType))]
[FriendOf(typeof(CoroutineLockQueueType))]
public static partial class CoroutineLockQueueTypeSystem
{
[EntitySystem]
private static void Awake(this CoroutineLockQueueType self)
{
}
public static CoroutineLockQueue Get(this CoroutineLockQueueType self, long key)
{
return self.GetChild<CoroutineLockQueue>(key);
}
public static CoroutineLockQueue New(this CoroutineLockQueueType self, long key)
{
CoroutineLockQueue queue = self.AddChildWithId<CoroutineLockQueue, int>(key, (int)self.Id, true);
return queue;
}
public static void Remove(this CoroutineLockQueueType self, long key)
{
self.RemoveChild(key);
}
public static async ETTask<CoroutineLock> Wait(this CoroutineLockQueueType self, long key, int time)
{
CoroutineLockQueue queue = self.Get(key) ?? self.New(key);
return await queue.Wait(time);
}
public static void Notify(this CoroutineLockQueueType self, long key, int level)
{
CoroutineLockQueue queue = self.Get(key);
if (queue == null)
{
return;
}
if (queue.Count == 0)
{
self.Remove(key);
}
queue.Notify(level);
}
}
[ChildOf(typeof(CoroutineLockComponent))]
public class CoroutineLockQueueType: Entity, IAwake
{
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: d57848ad9cf65e3478460a513cfb6434
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,16 +0,0 @@
namespace ET
{
public static class CoroutineLockType
{
public const int None = 0;
public const int Location = 1; // location进程上使用
public const int ActorLocationSender = 2; // ActorLocationSender中队列消息
public const int Mailbox = 3; // Mailbox中队列
public const int UnitId = 4; // Map服务器上线下线时使用
public const int DB = 5;
public const int Resources = 6;
public const int ResourcesLoader = 7;
public const int Max = 100; // 这个必须最大
}
}

Some files were not shown because too many files have changed in this diff Show More