// This unloads all data internal void Unload() { // Stop background loader StopBackgroundLoader(); // Dispose preview manager previews.Dispose(); previews = null; // Dispose resources foreach (ImageData i in images.Values) { i.Dispose(); } palette = null; // Dispose containers foreach (DataReader c in containers) { c.Dispose(); } containers.Clear(); // Trash collections containers = null; images = null; imageque = null; }
// This loads all data resources internal void Load(DataLocationList locations) { // Create collections containers = new List <DataReader>(); images = new Dictionary <int, ImageData>(); imageque = new Queue <ImageData>(); previews = new PreviewManager(); imagesets = new List <MatchingImageSet>(); usedimages = new Dictionary <int, int>(); spritecategories = General.Map.Config.GetThingCategories(); spritetypes = General.Map.Config.GetThingTypes(); // Load texture sets foreach (DefinedImageSet ts in General.Map.ConfigSettings.TextureSets) { imagesets.Add(new MatchingImageSet(ts)); } // Sort the texture sets imagesets.Sort(); // Special textures sets allimages = new AllImageSet(); resourceimages = new List <ResourceImageSet>(); // Go for all locations foreach (DataLocation dl in locations) { DataReader c; try { // Choose container type switch (dl.type) { // GRP file container case DataLocationType.RESOURCE_GRP: c = new GRPReader(dl); break; case DataLocationType.RESOURCE_ART: c = new ARTReader(dl); break; // Directory container //case DataLocationType.RESOURCE_DIRECTORY: //c = new DirectoryReader(dl); //break; // PK3 file container //case DataLocationType.RESOURCE_PK3: //c = new PK3Reader(dl); //break; default: throw new NotImplementedException("Unknown DataLocationType"); } } catch (Exception e) { // Unable to load resource General.ErrorLogger.Add(ErrorType.Error, "Unable to load resources from location \"" + dl.location + "\". Please make sure the location is accessible and not in use by another program. The resources will now be loaded with this location excluded. You may reload the resources to try again.\n" + e.GetType().Name + " when creating data reader: " + e.Message); General.WriteLogLine(e.StackTrace); continue; } // Add container containers.Add(c); resourceimages.Add(c.ImageSet); } // Load stuff LoadPalette(); images = LoadImages(); // Sort things foreach (SpriteCategory tc in spritecategories) { tc.SortIfNeeded(); } // Update the used textures General.Map.Data.UpdateUsedImages(); // Add texture names to texture sets foreach (KeyValuePair <int, ImageData> img in images) { // Add to all sets where it matches foreach (var ms in imagesets) { ms.AddImage(img.Value); } // Add to all allimages.AddImage(img.Value); } // Start background loading StartBackgroundLoader(); // Output info General.WriteLogLine("Loaded " + images.Count + " images, " + spritetypes.Count + " sprite types"); }