public HandlerInvokeData GetInvokeData(Handler handler, Type eventType, ICollection <Entity> entities)
        {
            HandlerInvokeData data;

            if ((entities.Count == 0) || (entities.Count > 2))
            {
                return(Cache.flowInvokeData.GetInstance().Init(handler));
            }
            long id = 0L;
            long id = 0L;

            Collections.Enumerator <Entity> enumerator = Collections.GetEnumerator <Entity>(entities);
            while (enumerator.MoveNext())
            {
                if (id == 0L)
                {
                    id = enumerator.Current.Id;
                    continue;
                }
                id = enumerator.Current.Id;
            }
            HandlerContextDescription key = new HandlerContextDescription(handler, eventType, id, id);

            if (!this.invokeDataByDescription.TryGetValue(key, out data))
            {
                data = new HandlerInvokeData(handler);
                this.invokeDataByDescription.Add(key, data);
                enumerator = Collections.GetEnumerator <Entity>(entities);
                while (enumerator.MoveNext())
                {
                    this.contextDescriptionsByEntity.Add(enumerator.Current.Id, key);
                }
            }
            return(data);
        }
        public Node CreateNode(EntityInternal entity)
        {
            Node node2;
            Node nodeInstance = Cache.GetNodeInstance(this.nodeClass);

            nodeInstance.Entity = entity;
            try
            {
                Collections.Enumerator <Type> enumerator = Collections.GetEnumerator <Type>(this.nodeDescription.Components);
                while (true)
                {
                    if (!enumerator.MoveNext())
                    {
                        node2 = nodeInstance;
                        break;
                    }
                    Type current = enumerator.Current;
                    this.SetComponent(nodeInstance, current, entity.GetComponent(current));
                }
            }
            catch (Exception exception)
            {
                throw new ConvertEntityToNodeException(this.nodeClass, entity, exception);
            }
            return(node2);
        }
示例#3
0
 public void OnEntityDeleted(Entity entity)
 {
     Collections.Enumerator <BroadcastInvokeDataStorage> enumerator = Collections.GetEnumerator <BroadcastInvokeDataStorage>(this.handlersByType.Values);
     while (enumerator.MoveNext())
     {
         enumerator.Current.Remove(entity);
     }
 }
示例#4
0
 private void SendNodeRemovedForCollectors(NodeDescription nodeDescription)
 {
     Collections.Enumerator <EntityListener> enumerator = Collections.GetEnumerator <EntityListener>(this.entityListeners);
     while (enumerator.MoveNext())
     {
         enumerator.Current.OnNodeRemoved(this, nodeDescription);
     }
 }
示例#5
0
 private void NotifyAddComponent(Component component)
 {
     Collections.Enumerator <ComponentListener> enumerator = Collections.GetEnumerator <ComponentListener>(this.engineService.ComponentListeners);
     while (enumerator.MoveNext())
     {
         enumerator.Current.OnComponentAdded(this, component);
     }
 }
示例#6
0
 private void OnRemoveMemberWithoutRemovingListener(EntityInternal member)
 {
     Collections.Enumerator <NodeDescription> enumerator = Collections.GetEnumerator <NodeDescription>(member.NodeDescriptionStorage.GetNodeDescriptions());
     while (enumerator.MoveNext())
     {
         this.nodeCollector.Detach(member, enumerator.Current);
     }
     this.members.Remove(member);
 }
示例#7
0
 public EventBuilder AttachAll(ICollection <Entity> entities)
 {
     Collections.Enumerator <Entity> enumerator = Collections.GetEnumerator <Entity>(entities);
     while (enumerator.MoveNext())
     {
         this.Attach(enumerator.Current);
     }
     return(this);
 }
示例#8
0
 private void SendEntityDeletedForAllListeners()
 {
     Collections.Enumerator <EntityListener> enumerator = Collections.GetEnumerator <EntityListener>(this.entityListeners);
     while (enumerator.MoveNext())
     {
         enumerator.Current.OnEntityDeleted(this);
     }
     this.entityListeners.Clear();
 }
示例#9
0
 public EventBuilder Attach <T>(ICollection <T> nodes) where T : Node
 {
     Collections.Enumerator <T> enumerator = Collections.GetEnumerator <T>(nodes);
     while (enumerator.MoveNext())
     {
         T current = enumerator.Current;
         this.Attach(current.Entity);
     }
     return(this);
 }
示例#10
0
        private void NotifyComponentRemove(Type componentType)
        {
            Component component = this.storage.GetComponent(componentType);

            Collections.Enumerator <ComponentListener> enumerator = Collections.GetEnumerator <ComponentListener>(this.engineService.ComponentListeners);
            while (enumerator.MoveNext())
            {
                enumerator.Current.OnComponentRemoved(this, component);
            }
        }
示例#11
0
 public void OnNodeRemoved(Entity entity, NodeDescription node)
 {
     Collections.Enumerator <KeyValuePair <Type, BroadcastInvokeDataStorage> > enumerator = Collections.GetEnumerator <KeyValuePair <Type, BroadcastInvokeDataStorage> >(this.handlersByType);
     while (enumerator.MoveNext())
     {
         KeyValuePair <Type, BroadcastInvokeDataStorage> current = enumerator.Current;
         ICollection <Handler> handlers = this.handlerCollector.GetHandlers(current.Key, node);
         KeyValuePair <Type, BroadcastInvokeDataStorage> pair2 = enumerator.Current;
         pair2.Value.Remove(entity, handlers);
     }
 }
示例#12
0
        public void AttachedToEntity(Entity entity)
        {
            EntityInternal item = (EntityInternal)entity;

            this.members.Add(item);
            item.AddEntityListener(this);
            Collections.Enumerator <NodeDescription> enumerator = Collections.GetEnumerator <NodeDescription>(item.NodeDescriptionStorage.GetNodeDescriptions());
            while (enumerator.MoveNext())
            {
                this.nodeCollector.Attach(item, enumerator.Current);
            }
        }
        public static ICollection <Handler> CollectHandlers(HandlerCollector handlerCollector, Type handlerType, ICollection <NodeDescription> changedNodes)
        {
            Collections.Enumerator <NodeDescription> enumerator = Collections.GetEnumerator <NodeDescription>(changedNodes);
            enumerator.MoveNext();
            ICollection <Handler> handlers = handlerCollector.GetHandlers(handlerType, enumerator.Current);

            if (!enumerator.MoveNext())
            {
                return(handlers);
            }
            List <Handler> list = new List <Handler>(handlers);

            while (true)
            {
                list.AddRange(handlerCollector.GetHandlers(handlerType, enumerator.Current));
                if (!enumerator.MoveNext())
                {
                    return(list);
                }
            }
        }
示例#14
0
 private void FillEntityNodesBySelectAll(ArgumentNode argumentNode)
 {
     Collections.Enumerator <Entity> enumerator = Collections.GetEnumerator <Entity>(Flow.Current.NodeCollector.GetEntities(argumentNode.argument.NodeDescription));
     while (enumerator.MoveNext())
     {
         EntityNode node;
         Entity     current = enumerator.Current;
         if (argumentNode.TryGetEntityNode(current, out node))
         {
             argumentNode.entityNodes.Add(node);
         }
     }
 }
示例#15
0
 public void FillEntityNodes(ArgumentNode argumentNode, ICollection <Entity> entities)
 {
     Collections.Enumerator <Entity> enumerator = Collections.GetEnumerator <Entity>(entities);
     while (enumerator.MoveNext())
     {
         EntityNode node;
         Entity     current = enumerator.Current;
         if (argumentNode.TryGetEntityNode(current, out node))
         {
             argumentNode.entityNodes.Add(node);
         }
     }
 }
示例#16
0
        private IList ConvertNodeCollection(NodeClassInstanceDescription nodeClassInstanceDescription, ICollection <Entity> entities)
        {
            int   count = entities.Count;
            IList genericListInstance = Cache.GetGenericListInstance(nodeClassInstanceDescription.NodeClass, count);

            Collections.Enumerator <Entity> enumerator = Collections.GetEnumerator <Entity>(entities);
            while (enumerator.MoveNext())
            {
                Node node = this.GetNode(enumerator.Current, nodeClassInstanceDescription);
                genericListInstance.Add(node);
            }
            return(genericListInstance);
        }
示例#17
0
 public Component CreateNewComponentInstance(Type componentType)
 {
     Collections.Enumerator <ComponentConstructor> enumerator = Collections.GetEnumerator <ComponentConstructor>(this.engineService.ComponentConstructors);
     while (enumerator.MoveNext())
     {
         ComponentConstructor current = enumerator.Current;
         if (current.IsAcceptable(componentType, this))
         {
             return(current.GetComponentInstance(componentType, this));
         }
     }
     return((Component)componentType.GetConstructor(EmptyTypes).Invoke(Collections.EmptyArray));
 }
示例#18
0
 public void Add(Entity entity, ICollection <Handler> handlers)
 {
     if (handlers.Count != 0)
     {
         Collections.Enumerator <Handler> enumerator = Collections.GetEnumerator <Handler>(handlers);
         while (enumerator.MoveNext())
         {
             Handler current = enumerator.Current;
             HandlerBroadcastInvokeData item = new HandlerBroadcastInvokeData(current, entity);
             this.datas.Add(item);
         }
     }
 }
示例#19
0
 private void FillEntityNodesByJoin(JoinType join, ICollection <Entity> contextEntities, EntityNode fromEntityNode, ArgumentNode toArgumentNode)
 {
     Collections.Enumerator <Entity> enumerator = Collections.GetEnumerator <Entity>(join.GetEntities(Flow.Current.NodeCollector, toArgumentNode.argument.NodeDescription, fromEntityNode.entity));
     while (enumerator.MoveNext())
     {
         EntityNode node;
         Entity     current = enumerator.Current;
         if (!this.FilterByContext(toArgumentNode.argument, current, contextEntities) && toArgumentNode.TryGetEntityNode(current, out node))
         {
             toArgumentNode.entityNodes.Add(node);
             fromEntityNode.nextArgumentEntityNodes.Add(node);
         }
     }
 }
示例#20
0
 protected void FillEntityNodesByJoin(JoinType join, EntityNode fromEntityNode, ArgumentNode toArgumentNode, Entity contextEntity)
 {
     toArgumentNode.filled = true;
     Collections.Enumerator <Entity> enumerator = Collections.GetEnumerator <Entity>(join.GetEntities(Flow.Current.NodeCollector, toArgumentNode.argument.NodeDescription, fromEntityNode.entity));
     while (enumerator.MoveNext())
     {
         EntityNode node;
         Entity     current = enumerator.Current;
         if (((contextEntity == null) || contextEntity.Equals(current)) && toArgumentNode.TryGetEntityNode(current, out node))
         {
             node.nextArgumentEntityNodes.Add(fromEntityNode);
             toArgumentNode.entityNodes.Add(node);
         }
     }
 }
示例#21
0
        protected ICollection <NodeDescription> GetRemovedNodes(EntityInternal entity, Type componentClass)
        {
            BitSet componentsBitId          = entity.ComponentsBitId;
            List <NodeDescription> instance = flowInstances.listNodeDescription.GetInstance();

            Collections.Enumerator <NodeDescription> enumerator = Collections.GetEnumerator <NodeDescription>(NodeDescriptionRegistry.GetNodeDescriptionsByNotComponent(componentClass));
            while (enumerator.MoveNext())
            {
                NodeDescription current = enumerator.Current;
                if (componentsBitId.Mask(current.NodeComponentBitId) && (!componentsBitId.MaskNot(current.NotNodeComponentBitId) && entity.NodeDescriptionStorage.Contains(current)))
                {
                    instance.Add(current);
                }
            }
            return(instance);
        }
示例#22
0
        public ICollection <Entity> FilterEntities(ICollection <Entity> values, NodeDescription nodeDescription)
        {
            HashSet <Entity> set;

            if (nodeDescription.IsEmpty)
            {
                List <Entity> list = Cache.listEntity.GetInstance();
                Collections.Enumerator <Entity> enumerator = Collections.GetEnumerator <Entity>(values);
                while (enumerator.MoveNext())
                {
                    Entity current = enumerator.Current;
                    if (((EntityInternal)current).Alive)
                    {
                        list.Add(current);
                    }
                }
                return(list);
            }
            if (values.Count == 1)
            {
                Entity onlyElement = Collections.GetOnlyElement <Entity>(values);
                if (((EntityInternal)onlyElement).Contains(nodeDescription))
                {
                    return(Collections.SingletonList <Entity>(onlyElement));
                }
            }
            if (!this.entitiesByDescription.TryGetValue(nodeDescription, out set))
            {
                return(Collections.EmptyList <Entity>());
            }
            List <Entity> instance = Cache.listEntity.GetInstance();

            Collections.Enumerator <Entity> enumerator2 = Collections.GetEnumerator <Entity>(values);
            while (enumerator2.MoveNext())
            {
                Entity current = enumerator2.Current;
                if (set.Contains(current))
                {
                    instance.Add(current);
                }
            }
            return(instance);
        }
示例#23
0
 public void Remove(Entity entity, ICollection <Handler> handlers)
 {
     if (handlers.Count != 0)
     {
         Collections.Enumerator <Handler> enumerator = Collections.GetEnumerator <Handler>(handlers);
         while (enumerator.MoveNext())
         {
             for (int i = this.datas.Count - 1; i >= 0; i--)
             {
                 HandlerBroadcastInvokeData data = this.datas[i];
                 Handler current = enumerator.Current;
                 if (ReferenceEquals(data.Handler, current) && data.Entity.Equals(entity))
                 {
                     this.datas.RemoveAt(i);
                 }
             }
         }
     }
 }
示例#24
0
        public virtual IList <HandlerInvokeData> Resolve(ICollection <Handler> handlers, Event eventInstance, Entity entity, ICollection <NodeDescription> changedNodes)
        {
            if (handlers.Count == 0)
            {
                return(Collections.EmptyList <HandlerInvokeData>());
            }
            List <HandlerInvokeData> instance = Cache.listHandlersInvokeData.GetInstance();

            Collections.Enumerator <Handler> enumerator = Collections.GetEnumerator <Handler>(handlers);
            while (enumerator.MoveNext())
            {
                Handler           current    = enumerator.Current;
                HandlerInvokeData invokeData = Cache.flowInvokeData.GetInstance().Init(current);
                if (this.UpdateInvokeData(invokeData, current, eventInstance, entity, changedNodes))
                {
                    instance.Add(invokeData);
                }
            }
            return(instance);
        }
示例#25
0
        public virtual IList <HandlerInvokeData> Resolve(ICollection <Handler> handlers, Event eventInstance, ICollection <Entity> contextEntities)
        {
            if (handlers.Count == 0)
            {
                return(Collections.EmptyList <HandlerInvokeData>());
            }
            List <HandlerInvokeData> instance = Cache.listHandlersInvokeData.GetInstance();

            Collections.Enumerator <Handler> enumerator = Collections.GetEnumerator <Handler>(handlers);
            while (enumerator.MoveNext())
            {
                Handler           current    = enumerator.Current;
                HandlerInvokeData invokeData = ((EngineServiceImpl)EngineService).HandlerContextDataStorage.GetInvokeData(current, eventInstance.GetType(), contextEntities);
                if (invokeData.Reuse(eventInstance) || this.UpdateInvokeData(invokeData, current, eventInstance, contextEntities))
                {
                    instance.Add(invokeData);
                }
            }
            return(instance);
        }
 public void OnEventSend(Event evt, ICollection <Entity> entities)
 {
     if (evt.GetType().IsDefined(typeof(Shared), true))
     {
         Collections.Enumerator <Entity> enumerator = Collections.GetEnumerator <Entity>(entities);
         object[] instanceArray = AbstractCommandCollector.Cache.array.GetInstanceArray(entities.Count);
         int      length        = 0;
         while (enumerator.MoveNext())
         {
             Entity current = enumerator.Current;
             if (this.entityRegistry.IsShared(current.Id))
             {
                 instanceArray[length++] = current;
             }
         }
         if (length > 0)
         {
             Entity[] destinationArray = AbstractCommandCollector.Cache.entityArray.GetInstanceArray(length);
             Array.Copy(instanceArray, destinationArray, length);
             base.AddCommand(new SendEventCommand().Init(destinationArray, evt));
         }
     }
 }
示例#27
0
        public void RegisterPart(Type templatePartClass)
        {
            if (templatePartClass.GetCustomAttributes(typeof(TemplatePart), true).Length == 0)
            {
                throw new MissingTemplatePartAttributeException(templatePartClass);
            }
            ICollection <Type> directInterfaces = this.GetDirectInterfaces(templatePartClass);

            if (directInterfaces.Count != 1)
            {
                throw new TemplatePartShouldExtendSingleTemplateException(templatePartClass);
            }
            Collections.Enumerator <Type> enumerator = Collections.GetEnumerator <Type>(directInterfaces);
            enumerator.MoveNext();
            Type current = enumerator.Current;

            if (!typeof(Template).IsAssignableFrom(current) || ReferenceEquals(typeof(Template), current))
            {
                throw new TemplatePartShouldExtendSingleTemplateException(templatePartClass, current);
            }
            Type templateClass = current;

            ((TemplateDescriptionImpl)this.GetTemplateInfo(templateClass)).AddComponentInfoFromClass(templatePartClass);
        }