static int[] distinctIndices(IList <int> indices) { var indicesSet = EntitasCache.GetIntHashSet(); foreach (var index in indices) { indicesSet.Add(index); } var uniqueIndices = new int[indicesSet.Count]; indicesSet.CopyTo(uniqueIndices); Array.Sort(uniqueIndices); EntitasCache.PushIntHashSet(indicesSet); return(uniqueIndices); }
/// Returns all indices of added components. public int[] GetComponentIndices() { if (mComponentIndicesCache == null) { var indices = EntitasCache.GetIntList(); for (int i = 0; i < mComponents.Length; i++) { if (mComponents[i] != null) { indices.Add(i); } } mComponentIndicesCache = indices.ToArray(); EntitasCache.PushIntList(indices); } return(mComponentIndicesCache); }
/// Returns all added components. public IComponent[] GetComponents() { if (mComponentsCache == null) { var components = EntitasCache.GetIComponentList(); for (int i = 0; i < mComponents.Length; i++) { IComponent component = mComponents[i]; if (component != null) { components.Add(component); } } mComponentsCache = components.ToArray(); EntitasCache.PushIComponentList(components); } return(mComponentsCache); }
static int[] mergeIndices(int[] allOfIndices, int[] anyOfIndices, int[] noneOfIndices) { var indicesList = EntitasCache.GetIntList(); if (allOfIndices != null) { indicesList.AddRange(allOfIndices); } if (anyOfIndices != null) { indicesList.AddRange(anyOfIndices); } if (noneOfIndices != null) { indicesList.AddRange(noneOfIndices); } var mergedIndices = distinctIndices(indicesList); EntitasCache.PushIntList(indicesList); return(mergedIndices); }