// use this region update for when a new item has no interest area and doesnt need to update position // (position update for it is done elsewhere) this is useful for projectiles and perhaps bots public void UpdateRegionSimple() { Region newRegion = this.World.GetRegion(this.Position); Region prevRegion = this.CurrentWorldRegion; if (newRegion != this.CurrentWorldRegion) { if (this.regionSubscription != null) { this.regionSubscription.Dispose(); } if (prevRegion != null) { prevRegion.DelistItem(this); // remove from regions item list } this.CurrentWorldRegion = newRegion; if (newRegion == null) { log.InfoFormat("new region was NULL"); return; } newRegion.EnlistItem(this); // add to regions item list 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 ); } }
/// <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 ); } } } }