|
|
|
|
@ -16,10 +16,10 @@ namespace GameCore.Network |
|
|
|
|
public ushort historyOffset; |
|
|
|
|
public ushort historyCount; |
|
|
|
|
public int parentIndex; |
|
|
|
|
public int childrenIndex; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private NativeDataContainer<Entry> entries; |
|
|
|
|
private NativeHashMap<int, UnsafeList<int>> childrenIndexMap; |
|
|
|
|
private NativeArray<UnsafeDataContainer> dataContainers; |
|
|
|
|
private NativeList<FrameHistoryItem> frameHistoryList; |
|
|
|
|
|
|
|
|
|
@ -30,6 +30,7 @@ namespace GameCore.Network |
|
|
|
|
AllocatorManager.AllocatorHandle allocator) |
|
|
|
|
{ |
|
|
|
|
entries = new(allocator); |
|
|
|
|
childrenIndexMap = new(8, allocator); |
|
|
|
|
|
|
|
|
|
var typeCount = typeMetaDatabase.GetTotalTypeCount(); |
|
|
|
|
dataContainers = new NativeArray<UnsafeDataContainer>(typeCount, allocator.ToAllocator); |
|
|
|
|
@ -51,6 +52,12 @@ namespace GameCore.Network |
|
|
|
|
{ |
|
|
|
|
entries.Dispose(); |
|
|
|
|
|
|
|
|
|
foreach (var kvp in childrenIndexMap) |
|
|
|
|
{ |
|
|
|
|
kvp.Value.Dispose(); |
|
|
|
|
} |
|
|
|
|
childrenIndexMap.Dispose(); |
|
|
|
|
|
|
|
|
|
var typeCount = dataContainers.Length; |
|
|
|
|
for (var i = 0; i < typeCount; i++) |
|
|
|
|
{ |
|
|
|
|
@ -66,23 +73,7 @@ namespace GameCore.Network |
|
|
|
|
{ |
|
|
|
|
var typeIndex = typeMetaDatabase.TypeIndexOf<T>(); |
|
|
|
|
|
|
|
|
|
var childrenIndex = 0; |
|
|
|
|
generation = 0; |
|
|
|
|
// if (parentIndex > 0) |
|
|
|
|
// { |
|
|
|
|
// if (parentIndex >= entryList.Length) |
|
|
|
|
// return 0; |
|
|
|
|
// |
|
|
|
|
// ref var parentEntry = ref entryList.ElementAt(parentIndex); |
|
|
|
|
// if (parentEntry.childrenIndex > 0) |
|
|
|
|
// { |
|
|
|
|
// childrenIndex = parentEntry.childrenIndex; |
|
|
|
|
// } |
|
|
|
|
// else |
|
|
|
|
// { |
|
|
|
|
// //TODO |
|
|
|
|
// } |
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
var entryIndex = entries.Alloc(UnsafeDataContainer.AllocOptions.ClearNew); |
|
|
|
|
ref var entry = ref entries.ElementAt(entryIndex); |
|
|
|
|
@ -95,8 +86,16 @@ namespace GameCore.Network |
|
|
|
|
entry.dataIndex = dataIndex; |
|
|
|
|
dataContainer.ElementAt<T>(dataIndex) = data; |
|
|
|
|
|
|
|
|
|
//TODO |
|
|
|
|
//entry.parentIndex = parentIndex; |
|
|
|
|
entry.parentIndex = parentIndex; |
|
|
|
|
if (parentIndex > 0) |
|
|
|
|
{ |
|
|
|
|
if (!childrenIndexMap.TryGetValue(parentIndex, out var list)) |
|
|
|
|
{ |
|
|
|
|
list = new UnsafeList<int>(4, allocator); |
|
|
|
|
} |
|
|
|
|
list.Add(entryIndex); |
|
|
|
|
childrenIndexMap[parentIndex] = list; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
entry.historyOffset = 0; |
|
|
|
|
var fieldSizeArray = typeMetaDatabase.GetFieldSizeArray(typeIndex); |
|
|
|
|
@ -164,16 +163,43 @@ namespace GameCore.Network |
|
|
|
|
|
|
|
|
|
public bool Remove(int index) |
|
|
|
|
{ |
|
|
|
|
if (!entries.Free(index)) |
|
|
|
|
return RemoveInternal(index, true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private bool RemoveInternal(int index, bool removeFromParent) |
|
|
|
|
{ |
|
|
|
|
if (!entries.HasValue(index)) |
|
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
ref var entry = ref entries.ElementAt(index); |
|
|
|
|
ref var dataContainer = ref dataContainers.GetRef(entry.dataIndex); |
|
|
|
|
ref var dataContainer = ref dataContainers.GetRef(entry.typeIndex); |
|
|
|
|
if (!dataContainer.Free(entry.dataIndex)) |
|
|
|
|
throw new Exception("Data mismatch"); |
|
|
|
|
|
|
|
|
|
//TODO |
|
|
|
|
if (entry.parentIndex > 0) |
|
|
|
|
{ |
|
|
|
|
if (removeFromParent && childrenIndexMap.TryGetValue(entry.parentIndex, out var list)) |
|
|
|
|
{ |
|
|
|
|
var i = list.IndexOf(index); |
|
|
|
|
list.RemoveAtSwapBack(i); |
|
|
|
|
childrenIndexMap[entry.parentIndex] = list; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
{ |
|
|
|
|
if (childrenIndexMap.TryGetValue(index, out var list)) |
|
|
|
|
{ |
|
|
|
|
for (int i = 0, len = list.Length; i < len; ++i) |
|
|
|
|
{ |
|
|
|
|
RemoveInternal(list[i], false); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
list.Dispose(); |
|
|
|
|
childrenIndexMap.Remove(index); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
entries.Free(index); |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|