public static F3DEXVertexWrapper GetVertexWrapper(Vertex vertex) { if (_vertexWrappers.ContainsKey(vertex)) return _vertexWrappers[vertex]; F3DEXVertexWrapper wrapper = new F3DEXVertexWrapper(vertex); _vertexWrappers.Add(vertex, wrapper); return wrapper; }
private static void ParseCommand(F3DEXCommand command) { TileDescriptor tile; //Here handle extra command things (like if it's referencing textures and such) switch (command.CommandID) { case F3DEXCommandID.F3DEX_G_TEXTURE: F3DEX_G_Texture textureCmd = (F3DEX_G_Texture)command; tile = TMEM.TileDescriptors[textureCmd.Tile]; tile.On = (textureCmd.TurnOn & 1) == 0; tile.ScaleS = textureCmd.ScaleS; tile.ScaleT = textureCmd.ScaleT; tile.Level = textureCmd.Level; break; case F3DEXCommandID.F3DEX_G_SETTILE: _lastSetTile = (F3DEX_G_SetTile)command; tile = TMEM.TileDescriptors[_lastSetTile.Tile]; tile.CMSMirror = _lastSetTile.CMSMirror; tile.CMTMirror = _lastSetTile.CMTMirror; tile.CMSWrap = _lastSetTile.CMSWrap; tile.CMTWrap = _lastSetTile.CMTWrap; tile.ImageFormat = _lastSetTile.Format; tile.Line = _lastSetTile.Line; tile.MaskS = _lastSetTile.MaskS; tile.MaskT = _lastSetTile.MaskT; tile.Palette = _lastSetTile.Palette; tile.PixelSize = _lastSetTile.PixelSize; tile.ShiftS = _lastSetTile.ShiftS; tile.ShiftT = _lastSetTile.ShiftT; tile.TMem = _lastSetTile.TMem; break; case F3DEXCommandID.F3DEX_G_SETTILESIZE: _lastSetTileSize = (F3DEX_G_SetTileSize)command; tile = TMEM.TileDescriptors[_lastSetTileSize.Tile]; tile.LRS = _lastSetTileSize.LRS; tile.LRT = _lastSetTileSize.LRT; tile.ULS = _lastSetTileSize.ULS; tile.ULT = _lastSetTileSize.ULT; break; case F3DEXCommandID.F3DEX_G_SETTIMG: _lastSetTImg = (F3DEX_G_SetTImg)command; TMEM.LastTImgCommand = _lastSetTImg; //TMEM.RAMTexturePixelSize = _lastSetTImg.PixelSize; //TMEM.RAMTextureAddress = _lastSetTImg.ImageAddress; //TMEM.RAMTextureImageFormat = _lastSetTImg.Format; //TMEM.RAMTextureWidth = _lastSetTImg.Width; break; case F3DEXCommandID.F3DEX_G_LOADBLOCK: _lastLoadBlock = (F3DEX_G_LoadBlock)command; TMEM.LoadBlockIntoTMem(_lastLoadBlock); break; case F3DEXCommandID.F3DEX_G_LOADTLUT: _lastLoadTLut = (F3DEX_G_LoadTLut)command; TMEM.LoadTLutIntoTMem(_lastLoadTLut); break; case F3DEXCommandID.F3DEX_G_VTX: F3DEX_G_Vtx vtx = (F3DEX_G_Vtx)command; RomFile file; int offset; if(RomProject.Instance.FindRamOffset(vtx.VertexSourceAddress, out file, out offset)) { if (file.GetElementAt(offset) is VertexCollection) { //Just update the reference buffer VertexCollection collection = (VertexCollection)file.GetElementAt(offset); if (vtx.VertexCount > 0) { int startIndex = 0; bool foundVertices = false; for (int i = 0; i < collection.Vertices.Count; i++) { if (collection.Vertices[i].FileOffset == offset) { startIndex = i; foundVertices = true; } if (foundVertices) { _vertexBuffer[vtx.TargetBufferIndex + (i - startIndex)] = collection.Vertices[i]; if (i - startIndex + 1 >= vtx.VertexCount) break; } } } } else { //Actually load in the bytes as new Vertices byte[] bytes = file.GetAsBytes(); byte[] vtxBytes = new byte[0x10]; List<Vertex> vertices = new List<Vertex>(); for (int i = 0; i < vtx.VertexCount; i++) { Array.Copy(bytes, offset, vtxBytes, 0, 0x10); Vertex vertex = new Vertex(offset, vtxBytes); //Add to collection somewhere vertices.Add(vertex); offset += 0x10; _vertexBuffer[i + vtx.TargetBufferIndex] = vertex; } if (!_foundVertices.ContainsKey(file)) _foundVertices.Add(file, new List<Vertex>()); _foundVertices[file].AddRange(vertices); } } break; case F3DEXCommandID.F3DEX_G_TRI1: case F3DEXCommandID.F3DEX_G_TRI2: if (TMEM.TileDescriptors[DefaultTextureTile].SettingsChanged) { //Try seeing if the texture has been loaded before if (!TryLoadExistingTexture(TMEM.TileDescriptors[DefaultTextureTile], out _currentTexture) && TMEM.LoadedData.ContainsKey(TMEM.TileDescriptors[DefaultTextureTile].TMem)) { LoadedTMemData tmemInfo = TMEM.LoadedData[TMEM.TileDescriptors[DefaultTextureTile].TMem]; //First try loading up the palette Palette palette = null; if (!TryLoadExistingPalette(out palette) && TMEM.LoadedData.ContainsKey(PALETTE_TMEM_OFFSET)) { palette = ReadPaletteFromTMem(); if (palette != null) { tmemInfo = TMEM.LoadedData[PALETTE_TMEM_OFFSET]; if (!_foundPalettes.ContainsKey(tmemInfo.SourceFile)) _foundPalettes.Add(tmemInfo.SourceFile, new List<Palette>()); _foundPalettes[tmemInfo.SourceFile].Add(palette); } } //Load up new Texture _currentTexture = ReadTextureFromTMem(TMEM.TileDescriptors[DefaultTextureTile], palette); if (_currentTexture != null) { //Store in the found variables if (!_foundTextures.ContainsKey(tmemInfo.SourceFile)) _foundTextures.Add(tmemInfo.SourceFile, new List<Texture>()); _foundTextures[tmemInfo.SourceFile].Add(_currentTexture); } } TMEM.TileDescriptors[0].SettingsChanged = false; } if (command.CommandID == F3DEXCommandID.F3DEX_G_TRI1) { F3DEX_G_Tri1 tri = (F3DEX_G_Tri1)command; tri.TextureReference = _currentTexture; tri.Vertex1Reference = _vertexBuffer[tri.Vertex1]; tri.Vertex2Reference = _vertexBuffer[tri.Vertex2]; tri.Vertex3Reference = _vertexBuffer[tri.Vertex3]; } else if (command.CommandID == F3DEXCommandID.F3DEX_G_TRI2) { F3DEX_G_Tri2 tri = (F3DEX_G_Tri2)command; tri.TextureReference = _currentTexture; tri.Vertex1Reference = _vertexBuffer[tri.Vertex1]; tri.Vertex2Reference = _vertexBuffer[tri.Vertex2]; tri.Vertex3Reference = _vertexBuffer[tri.Vertex3]; tri.Vertex4Reference = _vertexBuffer[tri.Vertex4]; tri.Vertex5Reference = _vertexBuffer[tri.Vertex5]; tri.Vertex6Reference = _vertexBuffer[tri.Vertex6]; } break; } }
public F3DEXVertexWrapper(Vertex vertex) { Vertex = vertex; Vertex.Updated += vertexUpdated; }