rework world arhetype implementation

This commit is contained in:
Mikhail 2023-03-30 01:14:43 +08:00
parent f093a7896a
commit cb121b8397
8 changed files with 52 additions and 38 deletions

5
src/Builtin/Worlds.cs Normal file
View File

@ -0,0 +1,5 @@
namespace DCFApixels.DragonECS
{
public sealed class EcsDefaultWrold : EcsWorld<EcsDefaultWrold> { }
public sealed class EcsEventWrold : EcsWorld<EcsDefaultWrold> { }
}

View File

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

View File

@ -7,7 +7,7 @@ namespace DCFApixels.DragonECS
#region Incs/Excs base #region Incs/Excs base
public interface IMaskCondition public interface IMaskCondition
{ {
public int[] GetComponentsIDs<TWorldArchetype>() where TWorldArchetype : IWorldArchetype; public int[] GetComponentsIDs<TWorldArchetype>() where TWorldArchetype : EcsWorld<TWorldArchetype>;
} }
#endregion #endregion
@ -15,11 +15,11 @@ namespace DCFApixels.DragonECS
public interface IInc : IMaskCondition { } public interface IInc : IMaskCondition { }
public struct Inc : IInc public struct Inc : IInc
{ {
public int[] GetComponentsIDs<TWorldArchetype>() where TWorldArchetype : IWorldArchetype => Array.Empty<int>(); public int[] GetComponentsIDs<TWorldArchetype>() where TWorldArchetype : EcsWorld<TWorldArchetype> => Array.Empty<int>();
} }
public struct Inc<T0> : IInc public struct Inc<T0> : IInc
{ {
public int[] GetComponentsIDs<TWorldArchetype>() where TWorldArchetype : IWorldArchetype public int[] GetComponentsIDs<TWorldArchetype>() where TWorldArchetype : EcsWorld<TWorldArchetype>
{ {
return new int[] return new int[]
{ {
@ -29,7 +29,7 @@ namespace DCFApixels.DragonECS
} }
public struct Inc<T0, T1> : IInc public struct Inc<T0, T1> : IInc
{ {
public int[] GetComponentsIDs<TWorldArchetype>() where TWorldArchetype : IWorldArchetype public int[] GetComponentsIDs<TWorldArchetype>() where TWorldArchetype : EcsWorld<TWorldArchetype>
{ {
return new int[] return new int[]
{ {
@ -40,7 +40,7 @@ namespace DCFApixels.DragonECS
} }
public struct Inc<T0, T1, T2> : IInc public struct Inc<T0, T1, T2> : IInc
{ {
public int[] GetComponentsIDs<TWorldArchetype>() where TWorldArchetype : IWorldArchetype public int[] GetComponentsIDs<TWorldArchetype>() where TWorldArchetype : EcsWorld<TWorldArchetype>
{ {
return new int[] return new int[]
{ {
@ -52,7 +52,7 @@ namespace DCFApixels.DragonECS
} }
public struct Inc<T0, T1, T2, T3> : IInc public struct Inc<T0, T1, T2, T3> : IInc
{ {
public int[] GetComponentsIDs<TWorldArchetype>() where TWorldArchetype : IWorldArchetype public int[] GetComponentsIDs<TWorldArchetype>() where TWorldArchetype : EcsWorld<TWorldArchetype>
{ {
return new int[] return new int[]
{ {
@ -65,7 +65,7 @@ namespace DCFApixels.DragonECS
} }
public struct Inc<T0, T1, T2, T3, T4> : IInc public struct Inc<T0, T1, T2, T3, T4> : IInc
{ {
public int[] GetComponentsIDs<TWorldArchetype>() where TWorldArchetype : IWorldArchetype public int[] GetComponentsIDs<TWorldArchetype>() where TWorldArchetype : EcsWorld<TWorldArchetype>
{ {
return new int[] return new int[]
{ {
@ -79,7 +79,7 @@ namespace DCFApixels.DragonECS
} }
public struct Inc<T0, T1, T2, T3, T4, T5> : IInc public struct Inc<T0, T1, T2, T3, T4, T5> : IInc
{ {
public int[] GetComponentsIDs<TWorldArchetype>() where TWorldArchetype : IWorldArchetype public int[] GetComponentsIDs<TWorldArchetype>() where TWorldArchetype : EcsWorld<TWorldArchetype>
{ {
return new int[] return new int[]
{ {
@ -94,7 +94,7 @@ namespace DCFApixels.DragonECS
} }
public struct Inc<T0, T1, T2, T3, T4, T5, T6> : IInc public struct Inc<T0, T1, T2, T3, T4, T5, T6> : IInc
{ {
public int[] GetComponentsIDs<TWorldArchetype>() where TWorldArchetype : IWorldArchetype public int[] GetComponentsIDs<TWorldArchetype>() where TWorldArchetype : EcsWorld<TWorldArchetype>
{ {
return new int[] return new int[]
{ {
@ -110,7 +110,7 @@ namespace DCFApixels.DragonECS
} }
public struct Inc<T0, T1, T2, T3, T4, T5, T6, T7> : IInc public struct Inc<T0, T1, T2, T3, T4, T5, T6, T7> : IInc
{ {
public int[] GetComponentsIDs<TWorldArchetype>() where TWorldArchetype : IWorldArchetype public int[] GetComponentsIDs<TWorldArchetype>() where TWorldArchetype : EcsWorld<TWorldArchetype>
{ {
return new int[] return new int[]
{ {
@ -127,7 +127,7 @@ namespace DCFApixels.DragonECS
} }
public struct Inc<T0, T1, T2, T3, T4, T5, T6, T7, T8> : IInc public struct Inc<T0, T1, T2, T3, T4, T5, T6, T7, T8> : IInc
{ {
public int[] GetComponentsIDs<TWorldArchetype>() where TWorldArchetype : IWorldArchetype public int[] GetComponentsIDs<TWorldArchetype>() where TWorldArchetype : EcsWorld<TWorldArchetype>
{ {
return new int[] return new int[]
{ {
@ -145,7 +145,7 @@ namespace DCFApixels.DragonECS
} }
public struct Inc<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> : IInc public struct Inc<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> : IInc
{ {
public int[] GetComponentsIDs<TWorldArchetype>() where TWorldArchetype : IWorldArchetype public int[] GetComponentsIDs<TWorldArchetype>() where TWorldArchetype : EcsWorld<TWorldArchetype>
{ {
return new int[] return new int[]
{ {
@ -164,7 +164,7 @@ namespace DCFApixels.DragonECS
} }
public struct Inc<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> : IInc public struct Inc<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> : IInc
{ {
public int[] GetComponentsIDs<TWorldArchetype>() where TWorldArchetype : IWorldArchetype public int[] GetComponentsIDs<TWorldArchetype>() where TWorldArchetype : EcsWorld<TWorldArchetype>
{ {
return new int[] return new int[]
{ {
@ -184,7 +184,7 @@ namespace DCFApixels.DragonECS
} }
public struct Inc<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> : IInc public struct Inc<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> : IInc
{ {
public int[] GetComponentsIDs<TWorldArchetype>() where TWorldArchetype : IWorldArchetype public int[] GetComponentsIDs<TWorldArchetype>() where TWorldArchetype : EcsWorld<TWorldArchetype>
{ {
return new int[] return new int[]
{ {
@ -209,11 +209,11 @@ namespace DCFApixels.DragonECS
public interface IExc : IMaskCondition { } public interface IExc : IMaskCondition { }
public struct Exc : IExc public struct Exc : IExc
{ {
public int[] GetComponentsIDs<TWorldArchetype>() where TWorldArchetype : IWorldArchetype => Array.Empty<int>(); public int[] GetComponentsIDs<TWorldArchetype>() where TWorldArchetype : EcsWorld<TWorldArchetype> => Array.Empty<int>();
} }
public struct Exc<T0> : IExc public struct Exc<T0> : IExc
{ {
public int[] GetComponentsIDs<TWorldArchetype>() where TWorldArchetype : IWorldArchetype public int[] GetComponentsIDs<TWorldArchetype>() where TWorldArchetype : EcsWorld<TWorldArchetype>
{ {
return new int[] return new int[]
{ {
@ -223,7 +223,7 @@ namespace DCFApixels.DragonECS
} }
public struct Exc<T0, T1> : IExc public struct Exc<T0, T1> : IExc
{ {
public int[] GetComponentsIDs<TWorldArchetype>() where TWorldArchetype : IWorldArchetype public int[] GetComponentsIDs<TWorldArchetype>() where TWorldArchetype : EcsWorld<TWorldArchetype>
{ {
return new int[] return new int[]
{ {
@ -234,7 +234,7 @@ namespace DCFApixels.DragonECS
} }
public struct Exc<T0, T1, T2> : IExc public struct Exc<T0, T1, T2> : IExc
{ {
public int[] GetComponentsIDs<TWorldArchetype>() where TWorldArchetype : IWorldArchetype public int[] GetComponentsIDs<TWorldArchetype>() where TWorldArchetype : EcsWorld<TWorldArchetype>
{ {
return new int[] return new int[]
{ {
@ -246,7 +246,7 @@ namespace DCFApixels.DragonECS
} }
public struct Exc<T0, T1, T2, T3> : IExc public struct Exc<T0, T1, T2, T3> : IExc
{ {
public int[] GetComponentsIDs<TWorldArchetype>() where TWorldArchetype : IWorldArchetype public int[] GetComponentsIDs<TWorldArchetype>() where TWorldArchetype : EcsWorld<TWorldArchetype>
{ {
return new int[] return new int[]
{ {
@ -259,7 +259,7 @@ namespace DCFApixels.DragonECS
} }
public struct Exc<T0, T1, T2, T3, T4> : IExc public struct Exc<T0, T1, T2, T3, T4> : IExc
{ {
public int[] GetComponentsIDs<TWorldArchetype>() where TWorldArchetype : IWorldArchetype public int[] GetComponentsIDs<TWorldArchetype>() where TWorldArchetype : EcsWorld<TWorldArchetype>
{ {
return new int[] return new int[]
{ {
@ -273,7 +273,7 @@ namespace DCFApixels.DragonECS
} }
public struct Exc<T0, T1, T2, T3, T4, T5> : IExc public struct Exc<T0, T1, T2, T3, T4, T5> : IExc
{ {
public int[] GetComponentsIDs<TWorldArchetype>() where TWorldArchetype : IWorldArchetype public int[] GetComponentsIDs<TWorldArchetype>() where TWorldArchetype : EcsWorld<TWorldArchetype>
{ {
return new int[] return new int[]
{ {
@ -316,7 +316,7 @@ namespace DCFApixels.DragonECS
} }
public static class EcsMaskMap<TWorldArchetype> public static class EcsMaskMap<TWorldArchetype>
where TWorldArchetype : IWorldArchetype where TWorldArchetype : EcsWorld<TWorldArchetype>
{ {
private static int _count; private static int _count;
private static int _capacity; private static int _capacity;

View File

@ -1,15 +1,9 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Text;
namespace DCFApixels.DragonECS namespace DCFApixels.DragonECS
{ {
public interface IWorldArchetype { }
public struct DefaultWorld : IWorldArchetype { }
public interface IEcsWorld public interface IEcsWorld
{ {
#region Properties #region Properties
@ -37,14 +31,6 @@ namespace DCFApixels.DragonECS
#endregion #endregion
} }
public static class IEcsWorldExt
{
public static void DelEntity(this IEcsWorld self, ent entity)
{
self.DelEntity(entity.id);
}
}
public abstract class EcsWorld public abstract class EcsWorld
{ {
internal static IEcsWorld[] Worlds = new IEcsWorld[8]; internal static IEcsWorld[] Worlds = new IEcsWorld[8];
@ -59,8 +45,8 @@ namespace DCFApixels.DragonECS
} }
} }
public sealed class EcsWorld<TArchetype> : EcsWorld, IEcsWorld public abstract class EcsWorld<TArchetype> : EcsWorld, IEcsWorld
where TArchetype : IWorldArchetype where TArchetype : EcsWorld<TArchetype>
{ {
private IntDispenser _entityDispenser; private IntDispenser _entityDispenser;
private EcsGroup _entities; private EcsGroup _entities;
@ -364,4 +350,16 @@ namespace DCFApixels.DragonECS
} }
#endregion #endregion
} }
public static class IEcsWorldExt
{
public static void DelEntity(this IEcsWorld self, ent entity)
{
self.DelEntity(entity.id);
}
}
} }