public void AddRegion(RegionContextBase rcontext) { m_log.Log(LogLevel.DWORLD, "Simulator connected " + rcontext.Name); RegionContextBase foundRegion = null; lock (m_regionList) { foundRegion = GetRegion(rcontext.Name); if (foundRegion == null) { // we don't know about this region. Add it and connect to events m_regionList.Add(rcontext); IEntityCollection coll; if (rcontext.TryGet<IEntityCollection>(out coll)) { if (Region_OnNewEntityCallback == null) { Region_OnNewEntityCallback = new EntityNewCallback(Region_OnNewEntity); } coll.OnEntityNew += Region_OnNewEntityCallback; if (Region_OnUpdateEntityCallback == null) { Region_OnUpdateEntityCallback = new EntityUpdateCallback(Region_OnUpdateEntity); } coll.OnEntityUpdate += Region_OnUpdateEntityCallback; if (Region_OnRemovedEntityCallback == null) { Region_OnRemovedEntityCallback = new EntityRemovedCallback(Region_OnRemovedEntity); } coll.OnEntityRemoved += Region_OnRemovedEntityCallback; } if (Region_OnRegionUpdatedCallback == null) { Region_OnRegionUpdatedCallback = new RegionRegionUpdatedCallback(Region_OnRegionUpdated); } rcontext.OnRegionUpdated += Region_OnRegionUpdatedCallback; } } // tell the world there is a new region (do it outside the lock) if (foundRegion == null) { if (OnWorldRegionNew != null) OnWorldRegionNew(rcontext); } }
public void RemoveRegion(RegionContextBase rcontext) { RegionContextBase foundRegion = null; lock (m_regionList) { foundRegion = GetRegion(rcontext.Name); if (foundRegion != null) { // we know about this region so remove it and disconnect from events m_regionList.Remove(foundRegion); m_log.Log(LogLevel.DWORLD, "Removing region " + foundRegion.Name); IEntityCollection coll; if (rcontext.TryGet<IEntityCollection>(out coll)) { if (Region_OnNewEntityCallback != null) { coll.OnEntityNew -= Region_OnNewEntityCallback; } if (Region_OnUpdateEntityCallback != null) { coll.OnEntityUpdate -= Region_OnUpdateEntityCallback; } if (Region_OnRemovedEntityCallback != null) { coll.OnEntityRemoved -= Region_OnRemovedEntityCallback; } } if (Region_OnRegionUpdatedCallback != null) { rcontext.OnRegionUpdated -= Region_OnRegionUpdatedCallback; } if (OnWorldRegionRemoved != null) OnWorldRegionRemoved(rcontext); } else { m_log.Log(LogLevel.DBADERROR, "RemoveRegion: asked to remove region we don't have. Name={0}", rcontext.Name); } } }
// create and initialize the renderinfoblock private RegionRenderInfo GetRegionRenderInfo(RegionContextBase rcontext) { RegionRenderInfo ret = null; if (!rcontext.TryGet<RegionRenderInfo>(out ret)) { ret = new RegionRenderInfo(); rcontext.RegisterInterface<RegionRenderInfo>(ret); ret.oceanHeight = rcontext.TerrainInfo.WaterHeight; } return ret; }