Exemplo n.º 1
0
        public object Clone()
        {
            SimEntity copy = (SimEntity)MemberwiseClone();

            copy.Name        = Name;
            copy.EventBuffer = null;
            return(copy);
        }
Exemplo n.º 2
0
 public static void AddEntityDynamically(SimEntity e)
 {
     if (e == null)
     {
         throw new ArgumentException("Adding null entity.");
     }
     else
     {
         WriteMessage($"Adding: {e.Name}");
     }
     e.StartEntity();
 }
Exemplo n.º 3
0
        public static void AddEntity(SimEntity e)
        {
            SimEvent evt;

            if (_running)
            {
                evt = new SimEvent(SimEvent.CREATE, _clock, src: 1, dest: 0, tag: 0, edata: e);
                _futureQueue.AddEvent(evt);
            }
            if (e.Id == -1)
            {
                int id = _entities.Count;
                e.Id = id;
                _entities.Add(e);
                _entitiesByName.Add(e.Name, e);
            }
        }
Exemplo n.º 4
0
        private static void ProcessEvent(SimEvent e)
        {
            int       dest, src;
            SimEntity destEnt;

            if (e.EventTime < _clock)
            {
                throw new ArgumentException("Past event detected.");
            }

            _clock = e.EventTime;

            switch (e.InternalType)
            {
            case SimEvent.ENULL:
                throw new ArgumentException("Event has a null type.");

            case SimEvent.CREATE:
                SimEntity newEntity = (SimEntity)e.Data;
                AddEntityDynamically(newEntity);
                break;

            case SimEvent.SEND:
                dest = e.Destination;
                if (dest < 0)
                {
                    throw new ArgumentException("Attempt to send to null entity detected.");
                }
                else
                {
                    int tag = e.Tag;
                    destEnt = _entities.Find(ent => ent.Id == dest);
                    if (destEnt.State == SimEntity.WAITING)
                    {
                        Predicate p;
                        if (_waitPredicates.TryGetValue(dest, out p))
                        {
                            if (p == null || tag == 9999 || p.Match(e))
                            {
                                destEnt.EventBuffer = (SimEvent)e.Clone();
                                destEnt.State       = SimEntity.RUNNABLE;
                                _waitPredicates.Remove(dest);
                            }
                            else
                            {
                                _deferedQueue.AddEvent(e);
                            }
                        }
                    }
                    else
                    {
                        _deferedQueue.AddEvent(e);
                    }
                }
                break;

            case SimEvent.HOLD_DONE:
                src = e.Source;
                if (src < 0)
                {
                    throw new ArgumentException("Null entity holding.");
                }
                else
                {
                    _entities.Find(ent => ent.Id == src).State = SimEntity.RUNNABLE;
                }
                break;
            }
        }