整理EntityDatabase代码
This commit is contained in:
1 parent
6d912005a5
commit
6c8108e3ea
13 files changed
+73
-25
No files matched your search
@@ -2,8 +2,7 @@ namespace ECSTest
|
||||
{
|
||||
public enum EntityType
|
||||
{
|
||||
Unit,
|
||||
Monster,
|
||||
Cannon,
|
||||
Bullet,
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ namespace ECSTest.Server
|
||||
{
|
||||
public struct WorldManager
|
||||
{
|
||||
public EntityCollection<EntityType> entities;
|
||||
public EntityDataBlockChain chain;
|
||||
public EntityDatabase<EntityType, EntityDataBlockChain> bulletDatabase;
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 24392c1216204b6ea64acd57bb43441b
|
||||
timeCreated: 1668251924
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c9227b743e78463b8df770cefc98fb18
|
||||
timeCreated: 1668274486
|
||||
@@ -1,14 +0,0 @@
|
||||
using System;
|
||||
using Unity.Collections;
|
||||
using Unity.Mathematics;
|
||||
|
||||
namespace GameCore.TinyECS
|
||||
{
|
||||
public struct EntityDataSet : IDisposable
|
||||
{
|
||||
public void Dispose()
|
||||
{
|
||||
//TODO
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -13,7 +13,7 @@ namespace GameCore.TinyECS
|
||||
public int elementAlign;
|
||||
}
|
||||
|
||||
public unsafe struct EntityDataBlockChain : IDisposable
|
||||
public unsafe struct EntityDataBlockChain : IEntityDataStruct
|
||||
{
|
||||
public readonly EntityDataBlockMeta blockMeta;
|
||||
private FixedList512Bytes<IntPtr> blockPtrList;
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7b0b5bb1c56f2114ba60d9154d447872
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
File renamed without changes.
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 747b2bec360ee8141b0b46886b09f92d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,10 @@
|
||||
using System;
|
||||
|
||||
namespace GameCore.TinyECS
|
||||
{
|
||||
public interface IEntityDataStruct : IDisposable
|
||||
{
|
||||
void Add();
|
||||
void Remove(int index);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 933c4528e6cf415dbfb79a148896839d
|
||||
timeCreated: 1765943532
|
||||
@@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using Unity.Collections;
|
||||
using Unity.Mathematics;
|
||||
|
||||
namespace GameCore.TinyECS
|
||||
{
|
||||
public struct EntityDatabase<TEnum, TData> : IDisposable where TEnum : unmanaged where TData : unmanaged, IEntityDataStruct
|
||||
{
|
||||
public TData dataStruct;
|
||||
public EntityGenerator<TEnum> generator;
|
||||
public EntityCollection<TEnum> collection;
|
||||
|
||||
public Entity<TEnum> AddEntity()
|
||||
{
|
||||
var entity = generator.Create();
|
||||
collection.Add(entity);
|
||||
dataStruct.Add();
|
||||
return entity;
|
||||
}
|
||||
|
||||
public void RemoveEntity(Entity<TEnum> entity)
|
||||
{
|
||||
generator.Delete(entity);
|
||||
if (collection.Remove(entity, out var index, out var _))
|
||||
dataStruct.Remove(index);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
generator.Dispose();
|
||||
collection.Dispose();
|
||||
dataStruct.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user