Example #1
0
        private void Dispatch(int id, IProto proto)
        {
            LazySet <Action <IProto> > handlers = null;

            if (this.actions.TryGetValue(id, out handlers) && handlers.Count > 0)
            {
                foreach (var action in handlers)
                {
                    action(proto);
                }
            }
        }
Example #2
0
        public void OnPacket(int id, Action <IProto> action)
        {
            LazySet <Action <IProto> > handlers = null;

            if (!this.actions.TryGetValue(id, out handlers))
            {
                this.actions.Add(id, handlers = new LazySet <Action <IProto> >());
            }

            if (!handlers.Contains(action))
            {
                handlers.Add(action);
            }
        }
        public bool Off(MessageDef type, Action <MessageDef, object[]> handler)
        {
            if (null == handler)
            {
                return(false);
            }

            LazySet <Action <MessageDef, object[]> > set = null;

            if (!this.handlers.TryGetValue(type, out set))
            {
                return(false);
            }

            return(set.Remove(handler));
        }
        public override void OnUpdate(IEntityContainer container, float deltaTime)
        {
            foreach (var e in this.filter.Target)
            {
                var msg = e.GetTrait <Message>();
                LazySet <Action <MessageDef, object[]> > set = null;
                if (this.handlers.TryGetValue(msg.Type, out set) && set.Count > 0)
                {
                    foreach (var handler in set)
                    {
                        handler(msg.Type, msg.Payload);
                    }
                }

                e.Dispose();
            }
        }
Example #5
0
 public Enumerator(LazySet <T> lazySet)
 {
     this.lazySet = lazySet;
     this.it      = lazySet.set.GetEnumerator();
     LockSet();
 }