Example #1
0
        public void RegisterComponentType <TInst>(DrawComponentsFunc <TInst> drawFunc)
            where TInst : struct, IInstance, IEquatable <TInst>
        {
            // FIXME: Better error
            if (ComponentsDict.ContainsKey(typeof(TInst)))
            {
                throw new Exception($"Instance type already registered! (type: {typeof(TInst)})");
            }

            InstanceList list = InstanceList.Create <TInst>(16);

            ComponentsDict.Add(typeof(TInst), list);
            DrawFuncs.Add((cr, comps) => drawFunc(cr, comps.GetInstances <TInst>()));
            AddFuncDict.Add(typeof(TInst), (list, inst) => list.Add((TInst)inst));
            RemoveFuncDict.Add(typeof(TInst), (list, inst) => list.Remove((TInst)inst));
        }