完善client agent
This commit is contained in:
1 parent
af72792875
commit
5e956f5989
3 files changed
+128
-3
No files matched your search
@@ -5,16 +5,87 @@ namespace GameCore.Network
|
||||
{
|
||||
public struct ClientAgent : IDisposable
|
||||
{
|
||||
private NativeList<int> dirtySet;
|
||||
|
||||
private struct Entry
|
||||
{
|
||||
public int srcIndex;
|
||||
public int generation;
|
||||
public int confirmedFrameId;
|
||||
public int deleteFrameId;
|
||||
public bool inView;
|
||||
}
|
||||
|
||||
private NativeList<Entry> entryList;
|
||||
private NativeHashMap<int, int> entryIndexMap;
|
||||
private NativeList<int> dirtyList;
|
||||
private NativeList<byte> tempBuffer;
|
||||
|
||||
public ClientAgent(AllocatorManager.AllocatorHandle allocator)
|
||||
{
|
||||
entryList = new NativeList<Entry>(allocator) { default };
|
||||
entryIndexMap = new NativeHashMap<int, int>(16, allocator);
|
||||
|
||||
dirtyList = new NativeList<int>(allocator);
|
||||
tempBuffer = new NativeList<byte>(allocator);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
//TODO
|
||||
entryList.Dispose();
|
||||
entryIndexMap.Dispose();
|
||||
dirtyList.Dispose();
|
||||
tempBuffer.Dispose();
|
||||
}
|
||||
|
||||
public void UpdateDirtySet(NetDatabase.Snapshot netDatabase, int frameId)
|
||||
{
|
||||
// clear inView flag
|
||||
for (int i = 1, l = entryList.Length; i < l; ++i)
|
||||
{
|
||||
entryList.ElementAt(i).inView = false;
|
||||
}
|
||||
|
||||
var tempIntList = dirtyList;
|
||||
tempIntList.Clear();
|
||||
|
||||
// 收集旧视野中的东西,包括等待删除的 entity
|
||||
for (int i = 1, l = entryList.Length; i < l; ++i)
|
||||
{
|
||||
ref readonly var entry = ref entryList.ElementAt(i);
|
||||
|
||||
if (entry.srcIndex == 0)
|
||||
{
|
||||
//TODO
|
||||
}
|
||||
else
|
||||
{
|
||||
tempIntList.Add(i);
|
||||
}
|
||||
}
|
||||
|
||||
var oldInViewCount = tempIntList.Length;
|
||||
|
||||
netDatabase.GatherNetDataIndex(tempIntList);
|
||||
|
||||
// 遍历 tempIntList 中新视野部分 (oldInViewCount 之后)
|
||||
{
|
||||
var j = oldInViewCount;
|
||||
for (int i = oldInViewCount, l = tempIntList.Length; i < l; ++i)
|
||||
{
|
||||
var srcIndex = tempIntList[i];
|
||||
if (entryIndexMap.TryGetValue(srcIndex, out var index))
|
||||
{
|
||||
entryList.ElementAt(index).inView = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
tempIntList[j++] = srcIndex;
|
||||
}
|
||||
}
|
||||
tempIntList.Resize(j, NativeArrayOptions.UninitializedMemory);
|
||||
}
|
||||
|
||||
//TODO
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user