public Context(int totalComponents,
int startCreationIndex,
ContextInfo contextInfo)
{
_totalComponents = totalComponents;
_creationIndex = startCreationIndex;
if(contextInfo != null) {
_contextInfo = contextInfo;
if(contextInfo.componentNames.Length != totalComponents) {
throw new ContextInfoException(this, contextInfo);
}
} else {
// If Contexts.CreateContext() was used to create the context,
// we will never end up here.
// This is a fallback when the context is created manually.
var componentNames = new string[totalComponents];
const string prefix = "Index ";
for (int i = 0; i < componentNames.Length; i++) {
componentNames[i] = prefix + i;
}
_contextInfo = new ContextInfo(
"Unnamed Context", componentNames, null
);
}
_groupsForIndex = new List<Group>[totalComponents];
_componentPools = new Stack<IComponent>[totalComponents];
_entityIndices = new Dictionary<string, IEntityIndex>();
// Cache delegates to avoid gc allocations
_cachedEntityChanged = updateGroupsComponentAddedOrRemoved;
_cachedComponentReplaced = updateGroupsComponentReplaced;
_cachedEntityReleased = onEntityReleased;
}