private void AssetsUnloaded(AssetsUnloadedEventArgs e) { // need to make sure that the regions are removed BEFORE the textures are removed so that we don't try to draw on non existant texture // maybe check to see if there is a content manager for that region before we try to draw anything for that region? RegionsUnloaded(e); RemoveUnloadedContent(e); }
private void RemoveUnloadedContent(AssetsUnloadedEventArgs e) { lock (_contentToRemove) { _contentToRemove.AddRange(e.RegionsUnloaded); } lock (_crossRegionNpcContentToRemove) { _crossRegionNpcContentToRemove.AddRange(e.CrossRegionNpcsUnloaded); } lock (_crossRegionSoundContentToRemove) { _crossRegionSoundContentToRemove.AddRange(e.CrossRegionSoundUnloaded); } }
private void ExecuteLoadUnloadRequest(List <RegionNames> regionsToLoad, List <RegionNames> regionsToUnload) { if (regionsToLoad.Count == 0 && regionsToUnload.Count == 0) { return; } var crossRegionNpcsToLoad = NpcMapper.GetCrossRegionNpcsForRegions(regionsToLoad); var currentCrossRegionNpcsUnload = NpcMapper.GetCrossRegionNpcsForRegions(_currentLoadedRegions); var crossRegionSoundsToLoad = SoundMapper.GetCrossRegionSoundEffects(regionsToLoad); var currentCrossRegionSoundsUnload = SoundMapper.GetCrossRegionSoundEffects(_currentLoadedRegions); foreach (var npc in crossRegionNpcsToLoad) { foreach (var region in NpcMapper.GetRegionsForCrossRegionNpc(npc)) { if (_currentLoadedRegions.Contains(region)) { crossRegionNpcsToLoad.Remove(npc); break; } } } foreach (var sound in crossRegionSoundsToLoad) { foreach (var region in SoundMapper.GetRegionsForSound(sound)) { if (_currentLoadedRegions.Contains(region)) { crossRegionSoundsToLoad.Remove(sound); break; } } } foreach (var region in regionsToLoad) { _currentLoadedRegions.Add(region); } foreach (var region in regionsToUnload) { _currentLoadedRegions.Remove(region); } foreach (var npc in currentCrossRegionNpcsUnload) { foreach (var region in NpcMapper.GetRegionsForCrossRegionNpc(npc)) { if (_currentLoadedRegions.Contains(region)) { currentCrossRegionNpcsUnload.Remove(npc); break; } } } foreach (var sound in currentCrossRegionSoundsUnload) { foreach (var region in SoundMapper.GetRegionsForSound(sound)) { if (_currentLoadedRegions.Contains(region)) { currentCrossRegionSoundsUnload.Remove(sound); break; } } } var saveData = DataHelper.GetCopySaveDataForCurrentFile(); // we need to use this to create the regions var regionContent = RegionContentLoader.LoadContentForRegions(_serviceProvider, _rootDirectory, regionsToLoad); var regions = RegionFactory.CreateRegions(regionsToLoad, saveData); var crossRegionNpcs = NpcMapper.CreateCrossRegionNpcs(crossRegionNpcsToLoad, saveData); var crossRegionContent = NpcContentLoader.LoadCrossRegionNpcContent(_serviceProvider, _rootDirectory, crossRegionNpcsToLoad); crossRegionContent.AddRange(SoundMapper.CreateCrossRegionSoundContent(_serviceProvider, _rootDirectory, crossRegionSoundsToLoad)); var loadedArgs = new AssetsLoadedEventArgs(); loadedArgs.RegionContent = regionContent; loadedArgs.Regions = regions; loadedArgs.CrossRegionContent = crossRegionContent; loadedArgs.CrossRegionNpcs = crossRegionNpcs; var unloadedArgs = new AssetsUnloadedEventArgs(); unloadedArgs.RegionsUnloaded = regionsToUnload; unloadedArgs.CrossRegionSoundUnloaded = currentCrossRegionSoundsUnload; unloadedArgs.CrossRegionNpcsUnloaded = currentCrossRegionNpcsUnload; AssetsLoaded(loadedArgs); AssetsUnloaded(unloadedArgs); }