update framework

master
abenmonkey 2 years ago
parent 3a1e97df6f
commit e3f449f183
  1. 1
      .gitignore
  2. 69
      Assets/Scenes/SampleScene.unity
  3. 13
      Assets/Scripts/EntityData.cs
  4. 18
      Assets/Scripts/Game.Test.asmdef
  5. 2
      Assets/Scripts/Game.Test.asmdef.meta
  6. 3
      Assets/Scripts/Main.cs
  7. 22
      Assets/Scripts/TestEntityDataBlock.cs
  8. 3
      Assets/Scripts/TestEntityDataBlock.cs.meta
  9. 8
      LocalPackages/com.nimin.lowlevel/Runtime.meta
  10. 21
      LocalPackages/com.nimin.lowlevel/Runtime/StructUtility.cs
  11. 3
      LocalPackages/com.nimin.lowlevel/Runtime/StructUtility.cs.meta
  12. 2
      LocalPackages/com.nimin.lowlevel/Runtime/nimin.lowlevel.asmdef
  13. 7
      LocalPackages/com.nimin.lowlevel/Runtime/nimin.lowlevel.asmdef.meta
  14. 15
      LocalPackages/com.nimin.lowlevel/package.json
  15. 7
      LocalPackages/com.nimin.lowlevel/package.json.meta
  16. 25
      LocalPackages/com.nimin.tinyecs/Runtime/ComponentId.cs
  17. 11
      LocalPackages/com.nimin.tinyecs/Runtime/ComponentId.cs.meta
  18. 34
      LocalPackages/com.nimin.tinyecs/Runtime/Entity.cs
  19. 201
      LocalPackages/com.nimin.tinyecs/Runtime/EntityDataBlock.cs
  20. 3
      LocalPackages/com.nimin.tinyecs/Runtime/EntityDataBlock.cs.meta
  21. 45
      LocalPackages/com.nimin.tinyecs/Runtime/EntityDataBlock.gen.cs
  22. 3
      LocalPackages/com.nimin.tinyecs/Runtime/EntityDataBlock.gen.cs.meta
  23. 14
      LocalPackages/com.nimin.tinyecs/Runtime/EntityDataSet.cs
  24. 11
      LocalPackages/com.nimin.tinyecs/Runtime/EntityDataSet.cs.meta
  25. 34
      LocalPackages/com.nimin.tinyecs/Runtime/nimin.tinyecs.asmdef
  26. 7
      LocalPackages/com.nimin.tinyecs/Runtime/nimin.tinyecs.asmdef.meta
  27. 10
      LocalPackages/com.nimin.tinyecs/package.json
  28. 1
      Packages/manifest.json
  29. 12
      Packages/packages-lock.json
  30. 5
      ProjectSettings/ProjectSettings.asset
  31. 167
      ProjectSettings/SceneTemplateSettings.json

1
.gitignore vendored

@ -6,6 +6,7 @@
/UserSettings/ /UserSettings/
.vs/ .vs/
.idea/
*.csproj *.csproj
*.unityproj *.unityproj
*.sln *.sln

@ -38,7 +38,7 @@ RenderSettings:
m_ReflectionIntensity: 1 m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0} m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 705507994} m_Sun: {fileID: 705507994}
m_IndirectSpecularColor: {r: 0, g: 0, b: 0, a: 1} m_IndirectSpecularColor: {r: 0.44657815, g: 0.49641192, b: 0.57481617, a: 1}
m_UseRadianceAmbientProbe: 0 m_UseRadianceAmbientProbe: 0
--- !u!157 &3 --- !u!157 &3
LightmapSettings: LightmapSettings:
@ -118,6 +118,8 @@ NavMeshSettings:
manualTileSize: 0 manualTileSize: 0
tileSize: 256 tileSize: 256
accuratePlacement: 0 accuratePlacement: 0
maxJobWorkers: 0
preserveTilesOutsideBounds: 0
debug: debug:
m_Flags: 0 m_Flags: 0
m_NavMeshData: {fileID: 0} m_NavMeshData: {fileID: 0}
@ -125,7 +127,8 @@ NavMeshSettings:
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0} m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0} m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6 serializedVersion: 6
m_Component: m_Component:
- component: {fileID: 705507995} - component: {fileID: 705507995}
@ -141,15 +144,18 @@ GameObject:
Light: Light:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0} m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0} m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 705507993} m_GameObject: {fileID: 705507993}
m_Enabled: 1 m_Enabled: 1
serializedVersion: 8 serializedVersion: 10
m_Type: 1 m_Type: 1
m_Shape: 0
m_Color: {r: 1, g: 0.95686275, b: 0.8392157, a: 1} m_Color: {r: 1, g: 0.95686275, b: 0.8392157, a: 1}
m_Intensity: 1 m_Intensity: 1
m_Range: 10 m_Range: 10
m_SpotAngle: 30 m_SpotAngle: 30
m_InnerSpotAngle: 21.802082
m_CookieSize: 10 m_CookieSize: 10
m_Shadows: m_Shadows:
m_Type: 2 m_Type: 2
@ -159,6 +165,24 @@ Light:
m_Bias: 0.05 m_Bias: 0.05
m_NormalBias: 0.4 m_NormalBias: 0.4
m_NearPlane: 0.2 m_NearPlane: 0.2
m_CullingMatrixOverride:
e00: 1
e01: 0
e02: 0
e03: 0
e10: 0
e11: 1
e12: 0
e13: 0
e20: 0
e21: 0
e22: 1
e23: 0
e30: 0
e31: 0
e32: 0
e33: 1
m_UseCullingMatrixOverride: 0
m_Cookie: {fileID: 0} m_Cookie: {fileID: 0}
m_DrawHalo: 0 m_DrawHalo: 0
m_Flare: {fileID: 0} m_Flare: {fileID: 0}
@ -166,23 +190,29 @@ Light:
m_CullingMask: m_CullingMask:
serializedVersion: 2 serializedVersion: 2
m_Bits: 4294967295 m_Bits: 4294967295
m_RenderingLayerMask: 1
m_Lightmapping: 1 m_Lightmapping: 1
m_LightShadowCasterMode: 0 m_LightShadowCasterMode: 0
m_AreaSize: {x: 1, y: 1} m_AreaSize: {x: 1, y: 1}
m_BounceIntensity: 1 m_BounceIntensity: 1
m_ColorTemperature: 6570 m_ColorTemperature: 6570
m_UseColorTemperature: 0 m_UseColorTemperature: 0
m_BoundingSphereOverride: {x: 0, y: 0, z: 0, w: 0}
m_UseBoundingSphereOverride: 0
m_UseViewFrustumForShadowCasterCull: 1
m_ShadowRadius: 0 m_ShadowRadius: 0
m_ShadowAngle: 0 m_ShadowAngle: 0
--- !u!4 &705507995 --- !u!4 &705507995
Transform: Transform:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0} m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0} m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 705507993} m_GameObject: {fileID: 705507993}
m_LocalRotation: {x: 0.40821788, y: -0.23456968, z: 0.10938163, w: 0.8754261} m_LocalRotation: {x: 0.40821788, y: -0.23456968, z: 0.10938163, w: 0.8754261}
m_LocalPosition: {x: 0, y: 3, z: 0} m_LocalPosition: {x: 0, y: 3, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: [] m_Children: []
m_Father: {fileID: 0} m_Father: {fileID: 0}
m_RootOrder: 1 m_RootOrder: 1
@ -191,12 +221,14 @@ Transform:
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0} m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0} m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6 serializedVersion: 6
m_Component: m_Component:
- component: {fileID: 963194228} - component: {fileID: 963194228}
- component: {fileID: 963194227} - component: {fileID: 963194227}
- component: {fileID: 963194226} - component: {fileID: 963194226}
- component: {fileID: 963194229}
m_Layer: 0 m_Layer: 0
m_Name: Main Camera m_Name: Main Camera
m_TagString: MainCamera m_TagString: MainCamera
@ -208,23 +240,26 @@ GameObject:
AudioListener: AudioListener:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0} m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0} m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 963194225} m_GameObject: {fileID: 963194225}
m_Enabled: 1 m_Enabled: 1
--- !u!20 &963194227 --- !u!20 &963194227
Camera: Camera:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0} m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0} m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 963194225} m_GameObject: {fileID: 963194225}
m_Enabled: 1 m_Enabled: 1
serializedVersion: 2 serializedVersion: 2
m_ClearFlags: 1 m_ClearFlags: 1
m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0} m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0}
m_projectionMatrixMode: 1 m_projectionMatrixMode: 1
m_GateFitMode: 2
m_FOVAxisMode: 0
m_SensorSize: {x: 36, y: 24} m_SensorSize: {x: 36, y: 24}
m_LensShift: {x: 0, y: 0} m_LensShift: {x: 0, y: 0}
m_GateFitMode: 2
m_FocalLength: 50 m_FocalLength: 50
m_NormalizedViewPortRect: m_NormalizedViewPortRect:
serializedVersion: 2 serializedVersion: 2
@ -256,12 +291,26 @@ Camera:
Transform: Transform:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0} m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0} m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 963194225} m_GameObject: {fileID: 963194225}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 1, z: -10} m_LocalPosition: {x: 0, y: 1, z: -10}
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: [] m_Children: []
m_Father: {fileID: 0} m_Father: {fileID: 0}
m_RootOrder: 0 m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &963194229
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 963194225}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 694d8256118344eb2b130fceb1a11b7f, type: 3}
m_Name:
m_EditorClassIdentifier:

@ -1,7 +1,20 @@
using GameCore.TinyECS; using GameCore.TinyECS;
using Unity.Mathematics;
namespace GameCore.Test namespace GameCore.Test
{ {
using Entity = Entity<EntityType>; using Entity = Entity<EntityType>;
public struct TransformData
{
public float3 position;
public float scale;
public quaternion rotation;
}
public struct StateData
{
public bool death;
public int hp;
}
} }

@ -0,0 +1,18 @@
{
"name": "Game.Test",
"rootNamespace": "",
"references": [
"nimin.tinyecs",
"Unity.Mathematics",
"Unity.Burst"
],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}

@ -1,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: c2bd585c8e44341079d076e23cd9d3eb guid: 21d33bf0450d14e5289fe083b8566dbe
AssemblyDefinitionImporter: AssemblyDefinitionImporter:
externalObjects: {} externalObjects: {}
userData: userData:

@ -1,5 +1,6 @@
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using GameCore.Test;
using UnityEngine; using UnityEngine;
public class Main : MonoBehaviour public class Main : MonoBehaviour
@ -7,7 +8,7 @@ public class Main : MonoBehaviour
// Start is called before the first frame update // Start is called before the first frame update
void Start() void Start()
{ {
TestEntityDataBlock.Run();
} }
// Update is called once per frame // Update is called once per frame

@ -0,0 +1,22 @@
using GameCore.TinyECS;
using UnityEngine;
namespace GameCore.Test
{
public static class TestEntityDataBlock
{
public static void Run()
{
var meta = EntityDataBlockMeta.Create<TransformData, StateData>();
using var blockChain = new EntityDataBlockChain(meta, 1000);
blockChain.Add();
ref var stateData = ref blockChain.GetData<StateData>(0);
stateData.hp = 1000;
var view = blockChain.AsBlockView(0);
var hp = view.GetData<StateData>(0).hp;
Debug.LogError($"hp: {hp}");
}
}
}

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: e5d058ca04eb44268eb93d1871dd132c
timeCreated: 1668273920

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

@ -0,0 +1,21 @@
using Unity.Collections.LowLevel.Unsafe;
namespace GameCore.LowLevel
{
public static class StructUtility
{
public static int OffsetOf<T, F>()
where T : struct
where F : struct
{
var fields = typeof(T).GetFields();
foreach (var f in fields)
{
if (f.DeclaringType == typeof(F))
return UnsafeUtility.GetFieldOffset(f);
}
return -1;
}
}
}

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: fde8ecf3379244d6885eb6d4ca9d8d31
timeCreated: 1668240297

@ -1,5 +1,5 @@
{ {
"name": "TinyECS.Runtime", "name": "nimin.lowlevel",
"rootNamespace": "", "rootNamespace": "",
"references": [ "references": [
"Unity.Collections", "Unity.Collections",

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 10ae496f407b04f038c880a464f55c72
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,15 @@
{
"name": "com.nimin.lowlevel",
"displayName": "GameCore LowLevel",
"version": "0.1.0",
"unity": "2021.3",
"description": "Low-level helper, contains custom collections",
"dependencies": {
"com.unity.collections": "1.2.4",
"com.unity.burst": "1.8.1"
},
"keywords": [
"LowLevel",
"Collections"
]
}

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 5f9f2b0e6f5f7472e8088bca5daed5ee
PackageManifestImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,25 @@
using System;
namespace GameCore.TinyECS
{
public struct ComponentId
{
struct Inner<T> where T : unmanaged
{
public int id;
private Inner(int i) => id = i;
public static Inner<T> Instance = default;
}
static int currentId;
public static int Get<T>() where T : unmanaged
{
if (Inner<T>.Instance.id == 0)
{
Inner<T>.Instance.id = ++currentId;
}
return Inner<T>.Instance.id;
}
}
}

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

@ -15,34 +15,12 @@ namespace GameCore.TinyECS
this.generation = generation; this.generation = generation;
} }
public override string ToString() public override string ToString() => $"Entity<{type}>({index},{generation})";
{ public bool Equals(Entity<TEnum> other) => type.Equals(other.type) && index == other.index && generation == other.generation;
return $"Entity<{type}>({index},{generation})"; public override bool Equals(object obj) => obj is Entity<TEnum> other && Equals(other);
} public override int GetHashCode() => HashCode.Combine(type, index, generation);
public static bool operator ==(Entity<TEnum> lhs, Entity<TEnum> rhs) => lhs.Equals(rhs);
public bool Equals(Entity<TEnum> other) public static bool operator !=(Entity<TEnum> lhs, Entity<TEnum> rhs) => !(lhs == rhs);
{
return type.Equals(other.type) && index == other.index && generation == other.generation;
}
public override bool Equals(object obj)
{
return obj is Entity<TEnum> other && Equals(other);
}
public override int GetHashCode()
{
return HashCode.Combine(type, index, generation);
}
public static bool operator ==(Entity<TEnum> lhs, Entity<TEnum> rhs)
{
return lhs.Equals(rhs);
}
public static bool operator !=(Entity<TEnum> lhs, Entity<TEnum> rhs)
{
return !(lhs == rhs);
}
} }
} }

@ -0,0 +1,201 @@
using System;
using Unity.Collections;
using Unity.Collections.LowLevel.Unsafe;
using System.Diagnostics;
namespace GameCore.TinyECS
{
public partial struct EntityDataBlockMeta
{
public FixedList64Bytes<byte> componentIdToIndex;
public FixedList128Bytes<short> componentIdToOffset;
public int elementSize;
public int elementAlign;
}
public unsafe struct EntityDataBlockChain : IDisposable
{
public readonly EntityDataBlockMeta blockMeta;
private FixedList512Bytes<IntPtr> blockPtrList;
private int maxElementCountPerBlock;
private int elementCount;
public int BlockCount => blockPtrList.Length;
public int BlockCapacity => blockPtrList.Capacity;
public int ElementCount => elementCount;
public int MaxElementCount => MaxElementCountPerBlock * BlockCapacity;
public int MaxElementCountPerBlock => maxElementCountPerBlock;
public bool IsFull => elementCount == MaxElementCount;
public bool IsEmpty => elementCount == 0;
public EntityDataBlockChain(EntityDataBlockMeta blockMeta, int maxElementCountPerBlock)
{
this.blockMeta = blockMeta;
blockPtrList = default;
this.maxElementCountPerBlock = maxElementCountPerBlock;
elementCount = 0;
}
public void Dispose()
{
for (var i = BlockCount - 1; i >= 0; --i)
{
ReleaseBlock(i);
}
}
void AllocBlock()
{
var bufferSize = blockMeta.elementSize * maxElementCountPerBlock;
var ptr = UnsafeUtility.Malloc(bufferSize, blockMeta.elementAlign, Allocator.Persistent);
blockPtrList.Add((IntPtr)ptr);
}
void ReleaseBlock(int blockIndex)
{
var pBlock = (void*)blockPtrList[blockIndex];
if (pBlock != null)
{
UnsafeUtility.Free(pBlock, Allocator.Persistent);
blockPtrList.RemoveAt(blockIndex);
}
}
void* ElementPtrAt(int elementIndex)
{
var blockIndex = elementIndex / maxElementCountPerBlock;
var pBlock = blockPtrList[blockIndex];
return (byte*)pBlock + elementIndex * blockMeta.elementSize;
}
void* ComponentPtrAt<T>(int elementIndex) where T : unmanaged
{
var componentId = ComponentId.Get<T>();
var componentIndex = blockMeta.componentIdToIndex[componentId];
if (componentIndex > 0)
{
var pElement = ElementPtrAt(elementIndex);
return (byte*)pElement + blockMeta.componentIdToOffset[componentId];
}
return null;
}
[Conditional("DEBUG")]
void CheckElementIndex(int index)
{
if (index < 0 || index >= elementCount)
throw new IndexOutOfRangeException($"Invalid index: {index}");
}
[Conditional("DEBUG")]
void CheckBlockIndex(int index)
{
if (index < 0 || index > (elementCount / maxElementCountPerBlock))
throw new IndexOutOfRangeException($"Invalid index: {index}");
}
public void Clear()
{
elementCount = 0;
}
public void Add()
{
if (elementCount % maxElementCountPerBlock == 0)
{
if (IsFull)
throw new OutOfMemoryException("Block chain is full!");
var blockIndex = elementCount / maxElementCountPerBlock;
if (blockIndex >= BlockCount)
AllocBlock();
}
void* ptr = ElementPtrAt(elementCount);
UnsafeUtility.MemClear(ptr, blockMeta.elementSize);
elementCount++;
}
public void Remove(int index)
{
CheckElementIndex(index);
if (index != elementCount - 1)
{
var src = ElementPtrAt(elementCount - 1);
var dst = ElementPtrAt(index);
UnsafeUtility.MemCpy(dst, src, blockMeta.elementSize);
}
elementCount--;
}
public ref T GetData<T>(int index) where T : unmanaged
{
CheckElementIndex(index);
var pComponent = ComponentPtrAt<T>(index);
if (pComponent == null)
throw new Exception($"Invalid component type: {typeof(T)}");
return ref UnsafeUtility.AsRef<T>(pComponent);
}
public EntityDataBlockView AsBlockView(int blockIndex)
{
CheckBlockIndex(blockIndex);
var ptr = (void*)blockPtrList[blockIndex];
return new(ptr, blockMeta, maxElementCountPerBlock * blockIndex, elementCount);
}
}
public unsafe readonly struct EntityDataBlockView
{
private readonly void* ptr;
public readonly EntityDataBlockMeta meta;
public readonly int elementStartIndex;
public readonly int elementCount;
public EntityDataBlockView(void* ptr, EntityDataBlockMeta meta, int elementStartIndex, int elementCount)
{
this.ptr = ptr;
this.meta = meta;
this.elementStartIndex = elementStartIndex;
this.elementCount = elementCount;
}
void* ElementPtrAt(int elementIndex)
{
return (byte*)ptr + elementIndex * meta.elementSize;
}
void* ComponentPtrAt<T>(int elementIndex) where T : unmanaged
{
var componentId = ComponentId.Get<T>();
var componentIndex = meta.componentIdToIndex[componentId];
if (componentIndex > 0)
{
var pElement = ElementPtrAt(elementIndex);
return (byte*)pElement + meta.componentIdToOffset[componentId];
}
return null;
}
[Conditional("DEBUG")]
void CheckIndex(int index)
{
if (index < elementStartIndex || index >= elementStartIndex + elementCount)
throw new IndexOutOfRangeException($"Invalid index: {index}");
}
public ref T GetData<T>(int index) where T : unmanaged
{
var pComponent = ComponentPtrAt<T>(index);
if (pComponent == null)
throw new Exception($"Invalid component type: {typeof(T)}");
return ref UnsafeUtility.AsRef<T>(pComponent);
}
}
}

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 24392c1216204b6ea64acd57bb43441b
timeCreated: 1668251924

@ -0,0 +1,45 @@
using System;
using Unity.Collections;
using Unity.Collections.LowLevel.Unsafe;
using System.Diagnostics;
using GameCore.LowLevel;
namespace GameCore.TinyECS
{
public partial struct EntityDataBlockMeta
{
public static EntityDataBlockMeta Create<T1>()
where T1 : unmanaged
{
var meta = new EntityDataBlockMeta();
meta.componentIdToIndex.Length = meta.componentIdToIndex.Capacity;
meta.componentIdToOffset.Length = meta.componentIdToOffset.Capacity;
var id1 = ComponentId.Get<T1>();
meta.componentIdToIndex[id1] = 1;
meta.componentIdToOffset[id1] = 0;
meta.elementSize = UnsafeUtility.SizeOf<T1>();
meta.elementAlign = UnsafeUtility.AlignOf<T1>();
return meta;
}
public static EntityDataBlockMeta Create<T1, T2>()
where T1 : unmanaged
where T2 : unmanaged
{
var meta = new EntityDataBlockMeta();
meta.componentIdToIndex.Length = meta.componentIdToIndex.Capacity;
meta.componentIdToOffset.Length = meta.componentIdToOffset.Capacity;
var id1 = ComponentId.Get<T1>();
var id2 = ComponentId.Get<T2>();
meta.componentIdToIndex[id1] = 1;
meta.componentIdToIndex[id2] = 2;
meta.componentIdToOffset[id1] = (short)StructUtility.OffsetOf<(T1, T2), T1>();
meta.componentIdToOffset[id2] = (short)StructUtility.OffsetOf<(T1, T2), T2>();
meta.elementSize = UnsafeUtility.SizeOf<(T1, T2)>();
meta.elementAlign = UnsafeUtility.AlignOf<(T2, T2)>();
return meta;
}
}
}

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: c9227b743e78463b8df770cefc98fb18
timeCreated: 1668274486

@ -0,0 +1,14 @@
using System;
using Unity.Collections;
using Unity.Mathematics;
namespace GameCore.TinyECS
{
public struct EntityDataSet : IDisposable
{
public void Dispose()
{
//TODO
}
}
}

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

@ -0,0 +1,34 @@
{
"name": "nimin.tinyecs",
"rootNamespace": "",
"references": [
"Unity.Collections",
"Unity.Mathematics",
"nimin.lowlevel"
],
"includePlatforms": [
"Android",
"Editor",
"iOS",
"LinuxStandalone64",
"Lumin",
"macOSStandalone",
"PS4",
"Stadia",
"Switch",
"tvOS",
"WSA",
"WebGL",
"WindowsStandalone32",
"WindowsStandalone64",
"XboxOne"
],
"excludePlatforms": [],
"allowUnsafeCode": true,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 9cf4bf50619414a2296aa8fb1643a952
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

@ -1,14 +1,14 @@
{ {
"name": "com.nimin.tinyecs", "name": "com.nimin.tinyecs",
"displayName": "Tiny ECS", "displayName": "GameCore TinyECS",
"version": "0.1.0", "version": "0.1.0",
"unity": "2021.3", "unity": "2021.3",
"description": "Data oriented ECS famework", "description": "Data oriented ECS famework",
"dependencies": { "dependencies": {
"com.unity.collections": "1.2.4", "com.nimin.lowlevel": "0.1.0"
"com.unity.burst": "1.8.1"
}, },
"keywords": [ "keywords": [
"ECS", "JobSystem" "ECS",
"JobSystem"
] ]
} }

@ -41,6 +41,7 @@
"com.unity.modules.vr": "1.0.0", "com.unity.modules.vr": "1.0.0",
"com.unity.modules.wind": "1.0.0", "com.unity.modules.wind": "1.0.0",
"com.unity.modules.xr": "1.0.0", "com.unity.modules.xr": "1.0.0",
"com.nimin.lowlevel": "file:../LocalPackages/com.nimin.lowlevel",
"com.nimin.tinyecs": "file:../LocalPackages/com.nimin.tinyecs" "com.nimin.tinyecs": "file:../LocalPackages/com.nimin.tinyecs"
} }
} }

@ -1,7 +1,7 @@
{ {
"dependencies": { "dependencies": {
"com.nimin.tinyecs": { "com.nimin.lowlevel": {
"version": "file:../LocalPackages/com.nimin.tinyecs", "version": "file:../LocalPackages/com.nimin.lowlevel",
"depth": 0, "depth": 0,
"source": "local", "source": "local",
"dependencies": { "dependencies": {
@ -9,6 +9,14 @@
"com.unity.burst": "1.8.1" "com.unity.burst": "1.8.1"
} }
}, },
"com.nimin.tinyecs": {
"version": "file:../LocalPackages/com.nimin.tinyecs",
"depth": 0,
"source": "local",
"dependencies": {
"com.nimin.lowlevel": "0.1.0"
}
},
"com.unity.burst": { "com.unity.burst": {
"version": "1.8.1", "version": "1.8.1",
"depth": 1, "depth": 1,

@ -165,7 +165,8 @@ PlayerSettings:
resetResolutionOnWindowResize: 0 resetResolutionOnWindowResize: 0
androidSupportedAspectRatio: 1 androidSupportedAspectRatio: 1
androidMaxAspectRatio: 2.1 androidMaxAspectRatio: 2.1
applicationIdentifier: {} applicationIdentifier:
Standalone: com.DefaultCompany.UnityECS
buildNumber: buildNumber:
Standalone: 0 Standalone: 0
iPhone: 0 iPhone: 0
@ -818,7 +819,7 @@ PlayerSettings:
managedStrippingLevel: {} managedStrippingLevel: {}
incrementalIl2cppBuild: {} incrementalIl2cppBuild: {}
suppressCommonWarnings: 1 suppressCommonWarnings: 1
allowUnsafeCode: 0 allowUnsafeCode: 1
useDeterministicCompilation: 1 useDeterministicCompilation: 1
enableRoslynAnalyzers: 1 enableRoslynAnalyzers: 1
additionalIl2CppArgs: additionalIl2CppArgs:

@ -0,0 +1,167 @@
{
"templatePinStates": [],
"dependencyTypeInfos": [
{
"userAdded": false,
"type": "UnityEngine.AnimationClip",
"ignore": false,
"defaultInstantiationMode": 0,
"supportsModification": true
},
{
"userAdded": false,
"type": "UnityEditor.Animations.AnimatorController",
"ignore": false,
"defaultInstantiationMode": 0,
"supportsModification": true
},
{
"userAdded": false,
"type": "UnityEngine.AnimatorOverrideController",
"ignore": false,
"defaultInstantiationMode": 0,
"supportsModification": true
},
{
"userAdded": false,
"type": "UnityEditor.Audio.AudioMixerController",
"ignore": false,
"defaultInstantiationMode": 0,
"supportsModification": true
},
{
"userAdded": false,
"type": "UnityEngine.ComputeShader",
"ignore": true,
"defaultInstantiationMode": 1,
"supportsModification": true
},
{
"userAdded": false,
"type": "UnityEngine.Cubemap",
"ignore": false,
"defaultInstantiationMode": 0,
"supportsModification": true
},
{
"userAdded": false,
"type": "UnityEngine.GameObject",
"ignore": false,
"defaultInstantiationMode": 0,
"supportsModification": true
},
{
"userAdded": false,
"type": "UnityEditor.LightingDataAsset",
"ignore": false,
"defaultInstantiationMode": 0,
"supportsModification": false
},
{
"userAdded": false,
"type": "UnityEngine.LightingSettings",
"ignore": false,
"defaultInstantiationMode": 0,
"supportsModification": true
},
{
"userAdded": false,
"type": "UnityEngine.Material",
"ignore": false,
"defaultInstantiationMode": 0,
"supportsModification": true
},
{
"userAdded": false,
"type": "UnityEditor.MonoScript",
"ignore": true,
"defaultInstantiationMode": 1,
"supportsModification": true
},
{
"userAdded": false,
"type": "UnityEngine.PhysicMaterial",
"ignore": false,
"defaultInstantiationMode": 0,
"supportsModification": true
},
{
"userAdded": false,
"type": "UnityEngine.PhysicsMaterial2D",
"ignore": false,
"defaultInstantiationMode": 0,
"supportsModification": true
},
{
"userAdded": false,
"type": "UnityEngine.Rendering.PostProcessing.PostProcessProfile",
"ignore": false,
"defaultInstantiationMode": 0,
"supportsModification": true
},
{
"userAdded": false,
"type": "UnityEngine.Rendering.PostProcessing.PostProcessResources",
"ignore": false,
"defaultInstantiationMode": 0,
"supportsModification": true
},
{
"userAdded": false,
"type": "UnityEngine.Rendering.VolumeProfile",
"ignore": false,
"defaultInstantiationMode": 0,
"supportsModification": true
},
{
"userAdded": false,
"type": "UnityEditor.SceneAsset",
"ignore": false,
"defaultInstantiationMode": 0,
"supportsModification": false
},
{
"userAdded": false,
"type": "UnityEngine.Shader",
"ignore": true,
"defaultInstantiationMode": 1,
"supportsModification": true
},
{
"userAdded": false,
"type": "UnityEngine.ShaderVariantCollection",
"ignore": true,
"defaultInstantiationMode": 1,
"supportsModification": true
},
{
"userAdded": false,
"type": "UnityEngine.Texture",
"ignore": false,
"defaultInstantiationMode": 0,
"supportsModification": true
},
{
"userAdded": false,
"type": "UnityEngine.Texture2D",
"ignore": false,
"defaultInstantiationMode": 0,
"supportsModification": true
},
{
"userAdded": false,
"type": "UnityEngine.Timeline.TimelineAsset",
"ignore": false,
"defaultInstantiationMode": 0,
"supportsModification": true
}
],
"defaultDependencyTypeInfo": {
"userAdded": false,
"type": "<default_scene_template_dependencies>",
"ignore": false,
"defaultInstantiationMode": 1,
"supportsModification": true
},
"newSceneOverride": 0
}
Loading…
Cancel
Save