/// <summary> /// Publishes a ItemPositionMessage in the PositionUpdateChannel /// Subscribes and unsubscribes regions if changed. /// </summary> public void UpdateInterestManagement(bool sendMessage) { if (sendMessage) { // inform attached interst area and radar ItemPositionMessage message = this.GetPositionUpdateMessage(this.Position); this.positionUpdateChannel.Publish(message); } // Object obj = new Object(); // lock (obj) { // update subscriptions if region changed Region prevRegion = this.CurrentWorldRegion; Region newRegion = this.World.GetRegion(this.Position); if (newRegion != this.CurrentWorldRegion) { this.CurrentWorldRegion = newRegion; if (this.regionSubscription != null) { this.regionSubscription.Dispose(); } var snapshot = this.GetItemSnapshot(); var regMessage = new ItemRegionChangedMessage(prevRegion, newRegion, snapshot); if (prevRegion != null) { prevRegion.DelistItem(this); // remove from regions item list prevRegion.ItemRegionChangedChannel.Publish(regMessage); // i think for non avatar items like bullet - since they are not tied to ClientInterestArea // their OnItemEnter and OnItemExit are empty or something idk. this was an attempt to // manually unsub the fiber so that the on item enter/exit events don't keep getting called // a good test would be to make the bullet last only .1sec so that it stays in only 1 region // then see if the current setup removes the fiber subscription //if (this.type == (byte)ItemType.Bullet) //{ // Fiber.DeregisterSubscription(prevRegion.RequestItemEnterChannel); // Fiber.DeregisterSubscription(prevRegion.RequestItemExitChannel); // Fiber.DeregisterSubscription(this.eventChannel); //} } if (newRegion != null) { newRegion.EnlistItem(this); // add to regions item list newRegion.ItemRegionChangedChannel.Publish(regMessage); this.regionSubscription = new UnsubscriberCollection( this.EventChannel.Subscribe(this.Fiber, (m) => newRegion.ItemEventChannel.Publish(m)), // route events through region to interest area newRegion.RequestItemEnterChannel.Subscribe(this.Fiber, (m) => { m.InterestArea.OnItemEnter(this.GetItemSnapshot()); }), // region entered interest area fires message to let item notify interest area about enter newRegion.RequestItemExitChannel.Subscribe(this.Fiber, (m) => { m.InterestArea.OnItemExit(this); }) // region exited interest area fires message to let item notify interest area about exit ); } } } }
private void UpdatePosition(ItemPositionMessage message) { Item item = message.Source; if (this.itemPositions.ContainsKey(item)) { this.itemPositions[item] = message.Position; this.PublishUpdate(item, message.Position, false, true); } }
/// <summary> /// The update position. /// </summary> /// <param name="message"> /// The message. /// </param> private void UpdatePosition(ItemPositionMessage message) { var positionUpdate = (MmoItemPositionUpdate)message; Item item = message.Source; if (this.itemPositions.ContainsKey(item)) { this.itemPositions[item] = positionUpdate.Coordinate; this.PublishUpdate(item, positionUpdate.Coordinate, true); } }
private void AttachedItem_OnItemPosition(ItemPositionMessage message) { MessageCounters.CounterReceive.Increment(); lock (this.SyncRoot) { if (this.AttachedItem == message.Source) { this.Position = message.Position; this.UpdateInterestManagement(); } } }
/// <summary> /// Publishes a ItemPositionMessage in the PositionUpdateChannel /// Subscribes and unsubscribes regions if changed. /// </summary> public void UpdateInterestManagement() { // inform attached interst area and radar ItemPositionMessage message = this.GetPositionUpdateMessage(this.Position); this.positionUpdateChannel.Publish(message); // update subscriptions if region changed Region prevRegion = this.CurrentWorldRegion; Region newRegion = this.World.GetRegion(this.Position); if (newRegion != this.CurrentWorldRegion) { this.CurrentWorldRegion = newRegion; if (this.regionSubscription != null) { this.regionSubscription.Dispose(); } var snapshot = this.GetItemSnapshot(); var regMessage = new ItemRegionChangedMessage(prevRegion, newRegion, snapshot); if (prevRegion != null) { prevRegion.ItemRegionChangedChannel.Publish(regMessage); } if (newRegion != null) { newRegion.ItemRegionChangedChannel.Publish(regMessage); this.regionSubscription = new UnsubscriberCollection( this.EventChannel.Subscribe(this.Fiber, (m) => newRegion.ItemEventChannel.Publish(m)), // route events through region to interest area newRegion.RequestItemEnterChannel.Subscribe(this.Fiber, (m) => { m.InterestArea.OnItemEnter(this.GetItemSnapshot()); }), // region entered interest area fires message to let item notify interest area about enter newRegion.RequestItemExitChannel.Subscribe(this.Fiber, (m) => { m.InterestArea.OnItemExit(this); }) // region exited interest area fires message to let item notify interest area about exit ); } } }
private void UpdatePosition(ItemPositionMessage message) { Item item = message.Source; if (this.itemPositions.ContainsKey(item)) { this.itemPositions[item] = message.Position; this.PublishUpdate(item, message.Position, false, true); } }