internal ArcheType *FindArcheType(ArcheType.Pair *pairArray, int count) { foreach (var archeTypePtr in _archeTypes) { var archeType = (ArcheType *)archeTypePtr; if (archeType->IsEqual(pairArray, count)) { return(archeType); } } return(null); }
internal ArcheType *FindArcheType(params Type[] types) { int len = types.Length; ArcheType.Pair *pairArray = stackalloc ArcheType.Pair[len]; for (int i = 0; i < len; ++i) { var t = types[i]; pairArray[i].Hash = t.GetHashCode(); pairArray[i].Size = Marshal.SizeOf(t); } return(FindArcheType(pairArray, len)); }
internal ArcheType *CreateArcheType(ArcheType *baseArcheType, params Type[] types) { int newlen = (baseArcheType != null)? baseArcheType->Count + types.Length : types.Length; int newsize = sizeof(ArcheType) + (sizeof(ArcheType.Pair) * newlen); ArcheType.Pair *candidateArray = stackalloc ArcheType.Pair[newlen]; if (baseArcheType != null) { for (int i = 0; i < baseArcheType->Count; ++i) { var p = &candidateArray[i]; p->Hash = baseArcheType->GetHash(i); p->Size = baseArcheType->GetSize(i); } } int ofs = (baseArcheType != null)? baseArcheType->Count : 0; for (int i = ofs; i < newlen; ++i) { var t = types[i - ofs]; Assert.IsTrue(t.IsValueType); Assert.IsNotNull(t.GetInterface("SimpleECS.IComponentData", false)); var p = &candidateArray[i]; p->Hash = t.GetHashCode(); p->Size = Marshal.SizeOf(t); } var archeType = FindArcheType(candidateArray, newlen); if (archeType != null) { return(archeType); } // var ptr = _buffer.Allocate(newsize, sizeof(int)); archeType = (ArcheType *)ptr; archeType->Count = newlen; var pairArray = (ArcheType.Pair *)(ptr + sizeof(ArcheType)); for (int i = 0; i < newlen; ++i) { pairArray[i] = candidateArray[i]; } _archeTypes.Add((IntPtr)archeType); return(archeType); }