diff --git a/src/Application/Data/OW/overworld.cc b/src/Application/Data/OW/overworld.cc index 0a640c81..5b54eba7 100644 --- a/src/Application/Data/OW/overworld.cc +++ b/src/Application/Data/OW/overworld.cc @@ -10,17 +10,19 @@ using namespace Core; using namespace Graphics; Overworld::~Overworld() { - // for (int i = 0; i < (int) tiles32.size(); i++) { - // free(allmapsTilesLW[i]); - // free(allmapsTilesDW[i]); - // free(allmapsTilesSP[i]); - // } - // free(allmapsTilesLW); - // free(allmapsTilesDW); - // free(allmapsTilesSP); + if (isLoaded) { + for (int i = 0; i < (int)tiles32.size(); i++) { + free(allmapsTilesLW[i]); + free(allmapsTilesDW[i]); + free(allmapsTilesSP[i]); + } + free(allmapsTilesLW); + free(allmapsTilesDW); + free(allmapsTilesSP); - // delete[] overworldMapPointer; - // delete[] owactualMapPointer; + delete[] overworldMapPointer; + delete[] owactualMapPointer; + } } static TileInfo GetTilesInfo(ushort tile) { diff --git a/src/Application/Data/OW/overworld_map.cc b/src/Application/Data/OW/overworld_map.cc index a636444c..d0c2b37a 100644 --- a/src/Application/Data/OW/overworld_map.cc +++ b/src/Application/Data/OW/overworld_map.cc @@ -126,7 +126,6 @@ void OverworldMap::BuildMap(byte* mapParent, int count, int gameState, BuildTileset(gameState); BuildTiles16Gfx(count); // build on GFX.mapgfx16Ptr - // LoadPalette(); int world = 0; @@ -276,280 +275,6 @@ void OverworldMap::CopyTileToMap(int x, int y, int xx, int yy, int offset, gfx16Pointer[index + r] = (byte)(((pixel >> 4) & 0x0F) + tile.palette_ * 16); } -/* -void OverworldMap::LoadPalette() { - int previousPalId = 0; - int previousSprPalId = 0; - if (index > 0) { - previousPalId = - rom_.GetRawData()[Constants::overworldMapPalette + parent - 1]; - previousSprPalId = - rom_.GetRawData()[Constants::overworldSpritePalette + parent - 1]; - } - - if (palette >= 0xA3) { - palette = 0xA3; - } - - byte pal0 = 0; - - byte pal1 = rom_.GetRawData()[Constants::overworldMapPaletteGroup + - (palette * 4)]; // aux1 - byte pal2 = rom_.GetRawData()[Constants::overworldMapPaletteGroup + - (palette * 4) + 1]; // aux2 - byte pal3 = rom_.GetRawData()[Constants::overworldMapPaletteGroup + - (palette * 4) + 2]; // animated - - byte pal4 = rom_.GetRawData()[Constants::overworldSpritePaletteGroup + - (sprpalette[ow_.gameState] * 2)]; // spr3 - byte pal5 = rom_.GetRawData()[Constants::overworldSpritePaletteGroup + - (sprpalette[ow_.gameState] * 2) + 1]; // spr4 - - ImVec4 aux1, aux2, main, animated, hud, spr, spr2; - ImVec4 bgr = Palettes.overworld_GrassPalettes[0]; - - if (pal1 == 255) { - pal1 = rom_.GetRawData()[Constants::overworldMapPaletteGroup + - (previousPalId * 4)]; - } - if (pal1 != 255) { - if (pal1 >= 20) { - pal1 = 19; - } - - aux1 = Palettes.overworld_AuxPalettes[pal1]; - } else { - aux1 = Palettes.overworld_AuxPalettes[0]; - } - - if (pal2 == 255) { - pal2 = rom_.GetRawData()[Constants::overworldMapPaletteGroup + - (previousPalId * 4) + 1]; - } - if (pal2 != 255) { - if (pal2 >= 20) { - pal2 = 19; - } - - aux2 = Palettes.overworld_AuxPalettes[pal2]; - } else { - aux2 = Palettes.overworld_AuxPalettes[0]; - } - - if (pal3 == 255) { - pal3 = rom_.GetRawData()[Constants::overworldMapPaletteGroup + - (previousPalId * 4) + 2]; - } - - if (parent < 0x40) { - // default LW Palette - pal0 = 0; - bgr = Palettes.overworld_GrassPalettes[0]; - // hardcoded LW DM palettes if we are on one of those maps (might change - // it to read game code) - if ((parent >= 0x03 && parent <= 0x07)) { - pal0 = 2; - } else if (parent >= 0x0B && parent <= 0x0E) { - pal0 = 2; - } - } else if (parent >= 0x40 && parent < 0x80) { - bgr = Palettes.overworld_GrassPalettes[1]; - // default DW Palette - pal0 = 1; - // hardcoded DW DM palettes if we are on one of those maps (might change - // it to read game code) - if (parent >= 0x43 && parent <= 0x47) { - pal0 = 3; - } else if (parent >= 0x4B && parent <= 0x4E) { - pal0 = 3; - } - } - - if (parent == 0x88) { - pal0 = 4; - } - /*else if (parent >= 128) //special area like Zora's domain, etc... - { - bgr = Palettes.overworld_GrassPalettes[2]; - pal0 = 4; - } - - if (pal0 != 255) { - main = Palettes.overworld_MainPalettes[pal0]; - } else { - main = Palettes.overworld_MainPalettes[0]; - } - - if (pal3 >= 14) { - pal3 = 13; - } - animated = Palettes.overworld_AnimatedPalettes[(pal3)]; - - hud = Palettes.HudPalettes[0]; - if (pal4 == 255) { - pal4 = rom_.GetRawData()[Constants::overworldSpritePaletteGroup + - (previousSprPalId * 2)]; // spr3 - } - if (pal4 == 255) { - pal4 = 0; - } - if (pal4 >= 24) { - pal4 = 23; - } - spr = Palettes.spritesAux3_Palettes[pal4]; - - if (pal5 == 255) { - pal5 = rom_.GetRawData()[Constants::overworldSpritePaletteGroup + - (previousSprPalId * 2) + 1]; // spr3 - } - if (pal5 == 255) { - pal5 = 0; - } - if (pal5 >= 24) { - pal5 = 23; - } - spr2 = Palettes.spritesAux3_Palettes[pal5]; - - SetColorsPalette(parent, main, animated, aux1, aux2, hud, bgr, spr, spr2); -} - - -void OverworldMap::SetColorsPalette(int index, ImVec4 main, ImVec4 animated, - ImVec4 aux1, ImVec4 aux2, ImVec4 hud, - Color bgrcolor, ImVec4 spr, ImVec4 spr2) { - // Palettes infos, color 0 of a palette is always transparent (the arrays - // contains 7 colors width wide) there is 16 color per line so 16*Y - - // Left side of the palette - Main, Animated - ImVec4 currentPalette = new Color[256]; - // Main Palette, Location 0,2 : 35 colors [7x5] - int k = 0; - for (int y = 2; y < 7; y++) { - for (int x = 1; x < 8; x++) { - currentPalette[x + (16 * y)] = main[k]; - k++; - } - } - - // Animated Palette, Location 0,7 : 7colors - for (int x = 1; x < 8; x++) { - currentPalette[(16 * 7) + (x)] = animated[(x - 1)]; - } - - // Right side of the palette - Aux1, Aux2 - - // Aux1 Palette, Location 8,2 : 21 colors [7x3] - k = 0; - for (int y = 2; y < 5; y++) { - for (int x = 9; x < 16; x++) { - currentPalette[x + (16 * y)] = aux1[k]; - k++; - } - } - - // Aux2 Palette, Location 8,5 : 21 colors [7x3] - k = 0; - for (int y = 5; y < 8; y++) { - for (int x = 9; x < 16; x++) { - currentPalette[x + (16 * y)] = aux2[k]; - k++; - } - } - - // Hud Palette, Location 0,0 : 32 colors [16x2] - k = 0; - for (int i = 0; i < 32; i++) { - currentPalette[i] = hud[i]; - } - - // Hardcoded grass color (that might change to become invisible instead) - for (int i = 0; i < 8; i++) { - currentPalette[(i * 16)] = bgrcolor; - currentPalette[(i * 16) + 8] = bgrcolor; - } - - // Sprite Palettes - k = 0; - for (int y = 8; y < 9; y++) { - for (int x = 1; x < 8; x++) { - currentPalette[x + (16 * y)] = Palettes.spritesAux1_Palettes[1][k]; - k++; - } - } - - // Sprite Palettes - k = 0; - for (int y = 8; y < 9; y++) { - for (int x = 9; x < 16; x++) { - currentPalette[x + (16 * y)] = Palettes.spritesAux3_Palettes[0][k]; - k++; - } - } - - // Sprite Palettes - k = 0; - for (int y = 9; y < 13; y++) { - for (int x = 1; x < 16; x++) { - currentPalette[x + (16 * y)] = Palettes.globalSprite_Palettes[0][k]; - k++; - } - } - - // Sprite Palettes - k = 0; - for (int y = 13; y < 14; y++) { - for (int x = 1; x < 8; x++) { - currentPalette[x + (16 * y)] = spr[k]; - k++; - } - } - - // Sprite Palettes - k = 0; - for (int y = 14; y < 15; y++) { - for (int x = 1; x < 8; x++) { - currentPalette[x + (16 * y)] = spr2[k]; - k++; - } - } - - // Sprite Palettes - k = 0; - for (int y = 15; y < 16; y++) { - for (int x = 1; x < 16; x++) { - currentPalette[x + (16 * y)] = Palettes.armors_Palettes[0][k]; - k++; - } - } - - try { - ColorPalette pal = GFX.editort16Bitmap.Palette; - for (int i = 0; i < 256; i++) { - pal.Entries[i] = currentPalette[i]; - pal.Entries[(i / 16) * 16] = Color.Transparent; - } - - GFX.mapgfx16Bitmap.Palette = pal; - GFX.mapblockset16Bitmap.Palette = pal; - - for (int i = 0; i < 256; i++) - { - if (index == 3) - { - - } - else if (index == 4) - { - pal.Entries[(i / 16) * 16] = Color.Transparent; - } - } - gfxBitmap.Palette = pal; - } catch (Exception e) { - // TODO: Add exception message. - } -} -*/ - void OverworldMap::BuildTileset(int gameState) { int indexWorld = 0x20; if (parent < 0x40) {