update framework

master
abenmonkey 2 years ago
parent 3a1e97df6f
commit e3f449f183
  1. 1
      .gitignore
  2. 583
      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

@ -1,267 +1,316 @@
%YAML 1.1 %YAML 1.1
%TAG !u! tag:unity3d.com,2011: %TAG !u! tag:unity3d.com,2011:
--- !u!29 &1 --- !u!29 &1
OcclusionCullingSettings: OcclusionCullingSettings:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
serializedVersion: 2 serializedVersion: 2
m_OcclusionBakeSettings: m_OcclusionBakeSettings:
smallestOccluder: 5 smallestOccluder: 5
smallestHole: 0.25 smallestHole: 0.25
backfaceThreshold: 100 backfaceThreshold: 100
m_SceneGUID: 00000000000000000000000000000000 m_SceneGUID: 00000000000000000000000000000000
m_OcclusionCullingData: {fileID: 0} m_OcclusionCullingData: {fileID: 0}
--- !u!104 &2 --- !u!104 &2
RenderSettings: RenderSettings:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
serializedVersion: 9 serializedVersion: 9
m_Fog: 0 m_Fog: 0
m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1} m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1}
m_FogMode: 3 m_FogMode: 3
m_FogDensity: 0.01 m_FogDensity: 0.01
m_LinearFogStart: 0 m_LinearFogStart: 0
m_LinearFogEnd: 300 m_LinearFogEnd: 300
m_AmbientSkyColor: {r: 0.212, g: 0.227, b: 0.259, a: 1} m_AmbientSkyColor: {r: 0.212, g: 0.227, b: 0.259, a: 1}
m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1} m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1}
m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1} m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1}
m_AmbientIntensity: 1 m_AmbientIntensity: 1
m_AmbientMode: 0 m_AmbientMode: 0
m_SubtractiveShadowColor: {r: 0.42, g: 0.478, b: 0.627, a: 1} m_SubtractiveShadowColor: {r: 0.42, g: 0.478, b: 0.627, a: 1}
m_SkyboxMaterial: {fileID: 10304, guid: 0000000000000000f000000000000000, type: 0} m_SkyboxMaterial: {fileID: 10304, guid: 0000000000000000f000000000000000, type: 0}
m_HaloStrength: 0.5 m_HaloStrength: 0.5
m_FlareStrength: 1 m_FlareStrength: 1
m_FlareFadeSpeed: 3 m_FlareFadeSpeed: 3
m_HaloTexture: {fileID: 0} m_HaloTexture: {fileID: 0}
m_SpotCookie: {fileID: 10001, guid: 0000000000000000e000000000000000, type: 0} m_SpotCookie: {fileID: 10001, guid: 0000000000000000e000000000000000, type: 0}
m_DefaultReflectionMode: 0 m_DefaultReflectionMode: 0
m_DefaultReflectionResolution: 128 m_DefaultReflectionResolution: 128
m_ReflectionBounces: 1 m_ReflectionBounces: 1
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:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
serializedVersion: 12 serializedVersion: 12
m_GIWorkflowMode: 1 m_GIWorkflowMode: 1
m_GISettings: m_GISettings:
serializedVersion: 2 serializedVersion: 2
m_BounceScale: 1 m_BounceScale: 1
m_IndirectOutputScale: 1 m_IndirectOutputScale: 1
m_AlbedoBoost: 1 m_AlbedoBoost: 1
m_EnvironmentLightingMode: 0 m_EnvironmentLightingMode: 0
m_EnableBakedLightmaps: 1 m_EnableBakedLightmaps: 1
m_EnableRealtimeLightmaps: 0 m_EnableRealtimeLightmaps: 0
m_LightmapEditorSettings: m_LightmapEditorSettings:
serializedVersion: 12 serializedVersion: 12
m_Resolution: 2 m_Resolution: 2
m_BakeResolution: 40 m_BakeResolution: 40
m_AtlasSize: 1024 m_AtlasSize: 1024
m_AO: 0 m_AO: 0
m_AOMaxDistance: 1 m_AOMaxDistance: 1
m_CompAOExponent: 1 m_CompAOExponent: 1
m_CompAOExponentDirect: 0 m_CompAOExponentDirect: 0
m_ExtractAmbientOcclusion: 0 m_ExtractAmbientOcclusion: 0
m_Padding: 2 m_Padding: 2
m_LightmapParameters: {fileID: 0} m_LightmapParameters: {fileID: 0}
m_LightmapsBakeMode: 1 m_LightmapsBakeMode: 1
m_TextureCompression: 1 m_TextureCompression: 1
m_FinalGather: 0 m_FinalGather: 0
m_FinalGatherFiltering: 1 m_FinalGatherFiltering: 1
m_FinalGatherRayCount: 256 m_FinalGatherRayCount: 256
m_ReflectionCompression: 2 m_ReflectionCompression: 2
m_MixedBakeMode: 2 m_MixedBakeMode: 2
m_BakeBackend: 1 m_BakeBackend: 1
m_PVRSampling: 1 m_PVRSampling: 1
m_PVRDirectSampleCount: 32 m_PVRDirectSampleCount: 32
m_PVRSampleCount: 500 m_PVRSampleCount: 500
m_PVRBounces: 2 m_PVRBounces: 2
m_PVREnvironmentSampleCount: 500 m_PVREnvironmentSampleCount: 500
m_PVREnvironmentReferencePointCount: 2048 m_PVREnvironmentReferencePointCount: 2048
m_PVRFilteringMode: 2 m_PVRFilteringMode: 2
m_PVRDenoiserTypeDirect: 0 m_PVRDenoiserTypeDirect: 0
m_PVRDenoiserTypeIndirect: 0 m_PVRDenoiserTypeIndirect: 0
m_PVRDenoiserTypeAO: 0 m_PVRDenoiserTypeAO: 0
m_PVRFilterTypeDirect: 0 m_PVRFilterTypeDirect: 0
m_PVRFilterTypeIndirect: 0 m_PVRFilterTypeIndirect: 0
m_PVRFilterTypeAO: 0 m_PVRFilterTypeAO: 0
m_PVREnvironmentMIS: 0 m_PVREnvironmentMIS: 0
m_PVRCulling: 1 m_PVRCulling: 1
m_PVRFilteringGaussRadiusDirect: 1 m_PVRFilteringGaussRadiusDirect: 1
m_PVRFilteringGaussRadiusIndirect: 5 m_PVRFilteringGaussRadiusIndirect: 5
m_PVRFilteringGaussRadiusAO: 2 m_PVRFilteringGaussRadiusAO: 2
m_PVRFilteringAtrousPositionSigmaDirect: 0.5 m_PVRFilteringAtrousPositionSigmaDirect: 0.5
m_PVRFilteringAtrousPositionSigmaIndirect: 2 m_PVRFilteringAtrousPositionSigmaIndirect: 2
m_PVRFilteringAtrousPositionSigmaAO: 1 m_PVRFilteringAtrousPositionSigmaAO: 1
m_ExportTrainingData: 0 m_ExportTrainingData: 0
m_TrainingDataDestination: TrainingData m_TrainingDataDestination: TrainingData
m_LightProbeSampleCountMultiplier: 4 m_LightProbeSampleCountMultiplier: 4
m_LightingDataAsset: {fileID: 0} m_LightingDataAsset: {fileID: 0}
m_LightingSettings: {fileID: 0} m_LightingSettings: {fileID: 0}
--- !u!196 &4 --- !u!196 &4
NavMeshSettings: NavMeshSettings:
serializedVersion: 2 serializedVersion: 2
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
m_BuildSettings: m_BuildSettings:
serializedVersion: 2 serializedVersion: 2
agentTypeID: 0 agentTypeID: 0
agentRadius: 0.5 agentRadius: 0.5
agentHeight: 2 agentHeight: 2
agentSlope: 45 agentSlope: 45
agentClimb: 0.4 agentClimb: 0.4
ledgeDropHeight: 0 ledgeDropHeight: 0
maxJumpAcrossDistance: 0 maxJumpAcrossDistance: 0
minRegionArea: 2 minRegionArea: 2
manualCellSize: 0 manualCellSize: 0
cellSize: 0.16666667 cellSize: 0.16666667
manualTileSize: 0 manualTileSize: 0
tileSize: 256 tileSize: 256
accuratePlacement: 0 accuratePlacement: 0
debug: maxJobWorkers: 0
m_Flags: 0 preserveTilesOutsideBounds: 0
m_NavMeshData: {fileID: 0} debug:
--- !u!1 &705507993 m_Flags: 0
GameObject: m_NavMeshData: {fileID: 0}
m_ObjectHideFlags: 0 --- !u!1 &705507993
m_CorrespondingSourceObject: {fileID: 0} GameObject:
m_PrefabInternal: {fileID: 0} m_ObjectHideFlags: 0
serializedVersion: 6 m_CorrespondingSourceObject: {fileID: 0}
m_Component: m_PrefabInstance: {fileID: 0}
- component: {fileID: 705507995} m_PrefabAsset: {fileID: 0}
- component: {fileID: 705507994} serializedVersion: 6
m_Layer: 0 m_Component:
m_Name: Directional Light - component: {fileID: 705507995}
m_TagString: Untagged - component: {fileID: 705507994}
m_Icon: {fileID: 0} m_Layer: 0
m_NavMeshLayer: 0 m_Name: Directional Light
m_StaticEditorFlags: 0 m_TagString: Untagged
m_IsActive: 1 m_Icon: {fileID: 0}
--- !u!108 &705507994 m_NavMeshLayer: 0
Light: m_StaticEditorFlags: 0
m_ObjectHideFlags: 0 m_IsActive: 1
m_CorrespondingSourceObject: {fileID: 0} --- !u!108 &705507994
m_PrefabInternal: {fileID: 0} Light:
m_GameObject: {fileID: 705507993} m_ObjectHideFlags: 0
m_Enabled: 1 m_CorrespondingSourceObject: {fileID: 0}
serializedVersion: 8 m_PrefabInstance: {fileID: 0}
m_Type: 1 m_PrefabAsset: {fileID: 0}
m_Color: {r: 1, g: 0.95686275, b: 0.8392157, a: 1} m_GameObject: {fileID: 705507993}
m_Intensity: 1 m_Enabled: 1
m_Range: 10 serializedVersion: 10
m_SpotAngle: 30 m_Type: 1
m_CookieSize: 10 m_Shape: 0
m_Shadows: m_Color: {r: 1, g: 0.95686275, b: 0.8392157, a: 1}
m_Type: 2 m_Intensity: 1
m_Resolution: -1 m_Range: 10
m_CustomResolution: -1 m_SpotAngle: 30
m_Strength: 1 m_InnerSpotAngle: 21.802082
m_Bias: 0.05 m_CookieSize: 10
m_NormalBias: 0.4 m_Shadows:
m_NearPlane: 0.2 m_Type: 2
m_Cookie: {fileID: 0} m_Resolution: -1
m_DrawHalo: 0 m_CustomResolution: -1
m_Flare: {fileID: 0} m_Strength: 1
m_RenderMode: 0 m_Bias: 0.05
m_CullingMask: m_NormalBias: 0.4
serializedVersion: 2 m_NearPlane: 0.2
m_Bits: 4294967295 m_CullingMatrixOverride:
m_Lightmapping: 1 e00: 1
m_LightShadowCasterMode: 0 e01: 0
m_AreaSize: {x: 1, y: 1} e02: 0
m_BounceIntensity: 1 e03: 0
m_ColorTemperature: 6570 e10: 0
m_UseColorTemperature: 0 e11: 1
m_ShadowRadius: 0 e12: 0
m_ShadowAngle: 0 e13: 0
--- !u!4 &705507995 e20: 0
Transform: e21: 0
m_ObjectHideFlags: 0 e22: 1
m_CorrespondingSourceObject: {fileID: 0} e23: 0
m_PrefabInternal: {fileID: 0} e30: 0
m_GameObject: {fileID: 705507993} e31: 0
m_LocalRotation: {x: 0.40821788, y: -0.23456968, z: 0.10938163, w: 0.8754261} e32: 0
m_LocalPosition: {x: 0, y: 3, z: 0} e33: 1
m_LocalScale: {x: 1, y: 1, z: 1} m_UseCullingMatrixOverride: 0
m_Children: [] m_Cookie: {fileID: 0}
m_Father: {fileID: 0} m_DrawHalo: 0
m_RootOrder: 1 m_Flare: {fileID: 0}
m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0} m_RenderMode: 0
--- !u!1 &963194225 m_CullingMask:
GameObject: serializedVersion: 2
m_ObjectHideFlags: 0 m_Bits: 4294967295
m_CorrespondingSourceObject: {fileID: 0} m_RenderingLayerMask: 1
m_PrefabInternal: {fileID: 0} m_Lightmapping: 1
serializedVersion: 6 m_LightShadowCasterMode: 0
m_Component: m_AreaSize: {x: 1, y: 1}
- component: {fileID: 963194228} m_BounceIntensity: 1
- component: {fileID: 963194227} m_ColorTemperature: 6570
- component: {fileID: 963194226} m_UseColorTemperature: 0
m_Layer: 0 m_BoundingSphereOverride: {x: 0, y: 0, z: 0, w: 0}
m_Name: Main Camera m_UseBoundingSphereOverride: 0
m_TagString: MainCamera m_UseViewFrustumForShadowCasterCull: 1
m_Icon: {fileID: 0} m_ShadowRadius: 0
m_NavMeshLayer: 0 m_ShadowAngle: 0
m_StaticEditorFlags: 0 --- !u!4 &705507995
m_IsActive: 1 Transform:
--- !u!81 &963194226 m_ObjectHideFlags: 0
AudioListener: m_CorrespondingSourceObject: {fileID: 0}
m_ObjectHideFlags: 0 m_PrefabInstance: {fileID: 0}
m_CorrespondingSourceObject: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_PrefabInternal: {fileID: 0} m_GameObject: {fileID: 705507993}
m_GameObject: {fileID: 963194225} m_LocalRotation: {x: 0.40821788, y: -0.23456968, z: 0.10938163, w: 0.8754261}
m_Enabled: 1 m_LocalPosition: {x: 0, y: 3, z: 0}
--- !u!20 &963194227 m_LocalScale: {x: 1, y: 1, z: 1}
Camera: m_ConstrainProportionsScale: 0
m_ObjectHideFlags: 0 m_Children: []
m_CorrespondingSourceObject: {fileID: 0} m_Father: {fileID: 0}
m_PrefabInternal: {fileID: 0} m_RootOrder: 1
m_GameObject: {fileID: 963194225} m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0}
m_Enabled: 1 --- !u!1 &963194225
serializedVersion: 2 GameObject:
m_ClearFlags: 1 m_ObjectHideFlags: 0
m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0} m_CorrespondingSourceObject: {fileID: 0}
m_projectionMatrixMode: 1 m_PrefabInstance: {fileID: 0}
m_SensorSize: {x: 36, y: 24} m_PrefabAsset: {fileID: 0}
m_LensShift: {x: 0, y: 0} serializedVersion: 6
m_GateFitMode: 2 m_Component:
m_FocalLength: 50 - component: {fileID: 963194228}
m_NormalizedViewPortRect: - component: {fileID: 963194227}
serializedVersion: 2 - component: {fileID: 963194226}
x: 0 - component: {fileID: 963194229}
y: 0 m_Layer: 0
width: 1 m_Name: Main Camera
height: 1 m_TagString: MainCamera
near clip plane: 0.3 m_Icon: {fileID: 0}
far clip plane: 1000 m_NavMeshLayer: 0
field of view: 60 m_StaticEditorFlags: 0
orthographic: 0 m_IsActive: 1
orthographic size: 5 --- !u!81 &963194226
m_Depth: -1 AudioListener:
m_CullingMask: m_ObjectHideFlags: 0
serializedVersion: 2 m_CorrespondingSourceObject: {fileID: 0}
m_Bits: 4294967295 m_PrefabInstance: {fileID: 0}
m_RenderingPath: -1 m_PrefabAsset: {fileID: 0}
m_TargetTexture: {fileID: 0} m_GameObject: {fileID: 963194225}
m_TargetDisplay: 0 m_Enabled: 1
m_TargetEye: 3 --- !u!20 &963194227
m_HDR: 1 Camera:
m_AllowMSAA: 1 m_ObjectHideFlags: 0
m_AllowDynamicResolution: 0 m_CorrespondingSourceObject: {fileID: 0}
m_ForceIntoRT: 0 m_PrefabInstance: {fileID: 0}
m_OcclusionCulling: 1 m_PrefabAsset: {fileID: 0}
m_StereoConvergence: 10 m_GameObject: {fileID: 963194225}
m_StereoSeparation: 0.022 m_Enabled: 1
--- !u!4 &963194228 serializedVersion: 2
Transform: m_ClearFlags: 1
m_ObjectHideFlags: 0 m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0}
m_CorrespondingSourceObject: {fileID: 0} m_projectionMatrixMode: 1
m_PrefabInternal: {fileID: 0} m_GateFitMode: 2
m_GameObject: {fileID: 963194225} m_FOVAxisMode: 0
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_SensorSize: {x: 36, y: 24}
m_LocalPosition: {x: 0, y: 1, z: -10} m_LensShift: {x: 0, y: 0}
m_LocalScale: {x: 1, y: 1, z: 1} m_FocalLength: 50
m_Children: [] m_NormalizedViewPortRect:
m_Father: {fileID: 0} serializedVersion: 2
m_RootOrder: 0 x: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} y: 0
width: 1
height: 1
near clip plane: 0.3
far clip plane: 1000
field of view: 60
orthographic: 0
orthographic size: 5
m_Depth: -1
m_CullingMask:
serializedVersion: 2
m_Bits: 4294967295
m_RenderingPath: -1
m_TargetTexture: {fileID: 0}
m_TargetDisplay: 0
m_TargetEye: 3
m_HDR: 1
m_AllowMSAA: 1
m_AllowDynamicResolution: 0
m_ForceIntoRT: 0
m_OcclusionCulling: 1
m_StereoConvergence: 10
m_StereoSeparation: 0.022
--- !u!4 &963194228
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 963194225}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 1, z: -10}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 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