public Dictionary<int, N64DataElement> LoadedElements; //Info of existing elements loaded into TMEM (used when parsing previously parsed data) public TMem() { Data = new byte[4096]; TileDescriptors = new TileDescriptor[8]; for (int i = 0; i < TileDescriptors.Length; i++) TileDescriptors[i] = new TileDescriptor((byte)i); LoadedData = new Dictionary<int, LoadedTMemData>(); LoadedElements = new Dictionary<int, N64DataElement>(); }
private static Texture ReadTextureFromTMem(TileDescriptor tile, Palette palette = null) { Texture newTexture; if (!TMEM.LoadedData.ContainsKey(tile.TMem)) return null; //if (!tile.On) //Not sure if used?? // return null; int offset = TMEM.LoadedData[tile.TMem].FileOffset; int sizeOfData = TMEM.LoadedData[tile.TMem].Size; int widthInBytes = 8 * tile.Line; double texelSize = 1; switch (tile.PixelSize) { case Texture.PixelInfo.Size_4b: texelSize = 0.5; break; case Texture.PixelInfo.Size_16b: texelSize = 2; break; case Texture.PixelInfo.Size_32b: texelSize = 4; break; } int widthInTexels = (int)Math.Round(widthInBytes / texelSize); int heightInTexels = sizeOfData / widthInBytes; byte[] data = new byte[sizeOfData]; Array.Copy(TMEM.Data, tile.TMemInBytes, data, 0, sizeOfData); if(tile.ImageFormat == Texture.ImageFormat.CI) newTexture = new Texture(offset, data, tile.ImageFormat, tile.PixelSize, widthInTexels, heightInTexels, palette, tile.Palette); else newTexture = new Texture(offset, data, tile.ImageFormat, tile.PixelSize, widthInTexels, heightInTexels, null); tile.SettingsChanged = false; return newTexture; }
private static bool TryLoadExistingTexture(TileDescriptor tile, out Texture texture) { texture = null; if (TMEM.LoadedElements.ContainsKey(TMEM.TileDescriptors[DefaultTextureTile].TMem)) { texture = (TMEM.LoadedElements[TMEM.TileDescriptors[DefaultTextureTile].TMem] as Texture); Palette newPalette; if (TryLoadExistingPalette(out newPalette)) texture.ImagePalette = newPalette; return true; } if (!TMEM.LoadedData.ContainsKey(TMEM.TileDescriptors[DefaultTextureTile].TMem)) return false; LoadedTMemData tmemInfo = TMEM.LoadedData[TMEM.TileDescriptors[DefaultTextureTile].TMem]; if(tmemInfo.SourceFile == null || !_foundTextures.ContainsKey(tmemInfo.SourceFile)) return false; for (int i = 0; i < _foundTextures[tmemInfo.SourceFile].Count; i++) { if (_foundTextures[tmemInfo.SourceFile][i].FileOffset == tmemInfo.FileOffset) { texture = _foundTextures[tmemInfo.SourceFile][i]; return true; } } return false; }
public LoadedTMemData GetTexturePaletteInfo(TileDescriptor tile) { if (LoadedData.ContainsKey(tile.TMem)) return null; return LoadedData[tile.TMem]; }