Exemple #1
0
 private static void Discharge(BaseGameEntity receiver, Telegram t)
 {
     if (!receiver.HandleMessage(t))
     {
         LogTelegram("Message for {0} not handled", receiver.Name);
     }
 }
Exemple #2
0
 public void RegisterEntity(BaseGameEntity entity)
 {
     if (entity == null)
     {
         throw new ArgumentNullException("entity", "Cannot register null entity");
     }
     try {
         _entityIdMap.Add(entity.Id, entity);
     } catch (ArgumentException aex) {
         throw new ArgumentException("Cannot register duplicate entity id: " + entity.Id, "entity.Id", aex);
     }
     try {
         _entityNameMap.Add(entity.Name, entity);
     } catch (ArgumentException aex) {
         throw new ArgumentException("Cannot register duplicate entity name: " + entity.Name, "entity.Name", aex);
     }
 }
Exemple #3
0
        public void DispatchMessage(double delay, BaseGameEntity sender, BaseGameEntity receiver, MessageType msg, object extraInfo)
        {
            var telegram = new Telegram {
                DispatchTime = 0,
                Sender       = sender.Id,
                Receiver     = receiver.Id,
                MessageType  = msg,
                ExtraData    = extraInfo
            };

            if (delay <= 0)
            {
                LogTelegram("Instant telegram dispatched at time: {0} by {1} to {2}. Msg is {3}", Clock.GlobalClock.GetCurrentTime(), sender.Name, receiver.Name, msg);
                Discharge(receiver, telegram);
            }
            else
            {
                telegram.DispatchTime = Clock.GlobalClock.GetCurrentTime() + delay;
                _priorityQueue.Enqueue(telegram.DispatchTime, telegram);
                LogTelegram("Delayed telegram from {0} recorded at time {1} for {2}. Msg is {3}", sender.Name, Clock.GlobalClock.GetCurrentTime(), receiver.Name, msg);
            }
        }
Exemple #4
0
 public void RemoveEntity(BaseGameEntity entity)
 {
     _entityIdMap.Remove(entity.Id);
     _entityNameMap.Remove(entity.Name);
 }