该项目的目的是同时测试和演示来自 Unity DOTS 技术堆栈的多个新包。
您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 

53 行
1.2 KiB

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SparseTickBuffer
{
public SparseTickBuffer(int size)
{
m_ticks = new uint[size];
}
public int Register(uint tick)
{
uint lastSetTick = currentIndex != -1 ? m_ticks[currentIndex] : 0;
if (tick != lastSetTick)
{
if (tick < lastSetTick)
{
// When recieving lower tick we clear all registered stated after tick
while (m_ticks[currentIndex] > tick)
{
m_ticks[currentIndex] = 0;
currentIndex--;
if (currentIndex < 0)
currentIndex += m_ticks.Length;
}
}
else
currentIndex = (currentIndex + 1) % m_ticks.Length;
m_ticks[currentIndex] = tick;
}
return currentIndex;
}
public int GetIndex(uint tick)
{
for (int i = 0; i < m_ticks.Length; i++)
{
if (m_ticks[i] == tick)
{
return i;
}
}
return -1;
}
uint[] m_ticks;
int currentIndex = -1;
}