overhaul directory structure
This commit is contained in:
349
src/application/Data/OW/overworld.cc
Normal file
349
src/application/Data/OW/overworld.cc
Normal file
@@ -0,0 +1,349 @@
|
||||
#include "overworld.h"
|
||||
|
||||
#include "Graphics/tile.h"
|
||||
|
||||
namespace yaze {
|
||||
namespace application {
|
||||
namespace Data {
|
||||
|
||||
using namespace Core;
|
||||
using namespace Graphics;
|
||||
|
||||
Overworld::~Overworld() {
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static TileInfo GetTilesInfo(ushort tile) {
|
||||
// vhopppcc cccccccc
|
||||
ushort o = 0;
|
||||
ushort v = 0;
|
||||
ushort h = 0;
|
||||
ushort tid = (ushort)(tile & 0x3FF);
|
||||
uchar p = (uchar)((tile >> 10) & 0x07);
|
||||
|
||||
o = (ushort)((tile & 0x2000) >> 13);
|
||||
h = (ushort)((tile & 0x4000) >> 14);
|
||||
v = (ushort)((tile & 0x8000) >> 15);
|
||||
|
||||
return TileInfo(tid, p, v, h, o);
|
||||
}
|
||||
|
||||
void Overworld::Load(Data::ROM rom) {
|
||||
rom_ = rom;
|
||||
for (int i = 0; i < 0x2B; i++) {
|
||||
// tileLeftEntrance.push_back(
|
||||
// rom_.ReadShort(Constants::overworldEntranceAllowedTilesLeft + (i *
|
||||
// 2)));
|
||||
// tileRightEntrance.push_back(rom_.ReadShort(
|
||||
// Constants::overworldEntranceAllowedTilesRight + (i * 2)));
|
||||
}
|
||||
|
||||
AssembleMap32Tiles();
|
||||
AssembleMap16Tiles();
|
||||
DecompressAllMapTiles();
|
||||
|
||||
// Map Initialization :
|
||||
for (int i = 0; i < 160; i++) {
|
||||
allmaps.push_back(OverworldMap(rom_, tiles16, (uchar)i));
|
||||
}
|
||||
FetchLargeMaps();
|
||||
LoadOverworldMap();
|
||||
|
||||
auto size = tiles16.size();
|
||||
for (int i = 0; i < 160; i++) {
|
||||
allmaps[i].BuildMap(mapParent, size, gameState, allmapsTilesLW,
|
||||
allmapsTilesDW, allmapsTilesSP);
|
||||
}
|
||||
|
||||
isLoaded = true;
|
||||
}
|
||||
|
||||
ushort Overworld::GenerateTile32(int i, int k, int dimension) {
|
||||
return (ushort)(rom_.GetRawData()[map32address[dimension] + k + (i)] +
|
||||
(((rom_.GetRawData()[map32address[dimension] + (i) +
|
||||
(k <= 1 ? 4 : 5)] >>
|
||||
(k % 2 == 0 ? 4 : 0)) &
|
||||
0x0F) *
|
||||
256));
|
||||
}
|
||||
|
||||
void Overworld::AssembleMap32Tiles() {
|
||||
for (int i = 0; i < 0x33F0; i += 6) {
|
||||
ushort tl, tr, bl, br;
|
||||
for (int k = 0; k < 4; k++) {
|
||||
tl = GenerateTile32(i, k, (int)Dimension::map32TilesTL);
|
||||
tr = GenerateTile32(i, k, (int)Dimension::map32TilesTR);
|
||||
bl = GenerateTile32(i, k, (int)Dimension::map32TilesBL);
|
||||
br = GenerateTile32(i, k, (int)Dimension::map32TilesBR);
|
||||
tiles32.push_back(Tile32(tl, tr, bl, br));
|
||||
}
|
||||
}
|
||||
|
||||
allmapsTilesLW = (ushort**)malloc(tiles32.size() * sizeof(ushort*));
|
||||
for (int i = 0; i < tiles32.size(); i++)
|
||||
allmapsTilesLW[i] = (ushort*)malloc(tiles32.size() * sizeof(ushort));
|
||||
|
||||
allmapsTilesDW = (ushort**)malloc(tiles32.size() * sizeof(ushort*));
|
||||
for (int i = 0; i < tiles32.size(); i++)
|
||||
allmapsTilesDW[i] = (ushort*)malloc(tiles32.size() * sizeof(ushort));
|
||||
|
||||
allmapsTilesSP = (ushort**)malloc(tiles32.size() * sizeof(ushort*));
|
||||
for (int i = 0; i < tiles32.size(); i++)
|
||||
allmapsTilesSP[i] = (ushort*)malloc(tiles32.size() * sizeof(ushort));
|
||||
}
|
||||
|
||||
void Overworld::AssembleMap16Tiles() {
|
||||
int tpos = Core::Constants::map16Tiles;
|
||||
for (int i = 0; i < 4096; i += 1) // 3760
|
||||
{
|
||||
TileInfo t0 = GetTilesInfo((uintptr_t)rom_.GetRawData() + tpos);
|
||||
tpos += 2;
|
||||
TileInfo t1 = GetTilesInfo((uintptr_t)rom_.GetRawData() + tpos);
|
||||
tpos += 2;
|
||||
TileInfo t2 = GetTilesInfo((uintptr_t)rom_.GetRawData() + tpos);
|
||||
tpos += 2;
|
||||
TileInfo t3 = GetTilesInfo((uintptr_t)rom_.GetRawData() + tpos);
|
||||
tpos += 2;
|
||||
tiles16.push_back(Tile16(t0, t1, t2, t3));
|
||||
}
|
||||
}
|
||||
|
||||
void Overworld::DecompressAllMapTiles() {
|
||||
int lowest = 0x0FFFFF;
|
||||
int highest = 0x0F8000;
|
||||
int sx = 0;
|
||||
int sy = 0;
|
||||
int c = 0;
|
||||
for (int i = 0; i < 160; i++) {
|
||||
int p1 = (rom_.GetRawData()[(Constants::compressedAllMap32PointersHigh) +
|
||||
2 + (int)(3 * i)]
|
||||
<< 16) +
|
||||
(rom_.GetRawData()[(Constants::compressedAllMap32PointersHigh) +
|
||||
1 + (int)(3 * i)]
|
||||
<< 8) +
|
||||
(rom_.GetRawData()[(Constants::compressedAllMap32PointersHigh +
|
||||
(int)(3 * i))]);
|
||||
|
||||
char* tmp = new char[256];
|
||||
p1 = lorom_snes_to_pc(p1, &tmp);
|
||||
std::cout << tmp << std::endl;
|
||||
int p2 = (rom_.GetRawData()[(Constants::compressedAllMap32PointersLow) + 2 +
|
||||
(int)(3 * i)]
|
||||
<< 16) +
|
||||
(rom_.GetRawData()[(Constants::compressedAllMap32PointersLow) + 1 +
|
||||
(int)(3 * i)]
|
||||
<< 8) +
|
||||
(rom_.GetRawData()[(Constants::compressedAllMap32PointersLow +
|
||||
(int)(3 * i))]);
|
||||
p2 = lorom_snes_to_pc(p2, &tmp);
|
||||
std::cout << tmp << std::endl;
|
||||
delete[] tmp;
|
||||
|
||||
int ttpos = 0;
|
||||
unsigned int compressedSize1 = 0;
|
||||
unsigned int compressedSize2 = 0;
|
||||
unsigned int compressedLength1 = 0;
|
||||
unsigned int compressedLength2 = 0;
|
||||
|
||||
if (p1 >= highest) {
|
||||
highest = p1;
|
||||
}
|
||||
if (p2 >= highest) {
|
||||
highest = p2;
|
||||
}
|
||||
|
||||
if (p1 <= lowest) {
|
||||
if (p1 > 0x0F8000) {
|
||||
lowest = p1;
|
||||
}
|
||||
}
|
||||
if (p2 <= lowest) {
|
||||
if (p2 > 0x0F8000) {
|
||||
lowest = p2;
|
||||
}
|
||||
}
|
||||
|
||||
auto bytes =
|
||||
alttp_decompress_overworld((char*)rom_.GetRawData(), p2, 1000,
|
||||
&compressedSize1, &compressedLength1);
|
||||
auto bytes2 =
|
||||
alttp_decompress_overworld((char*)rom_.GetRawData(), p1, 1000,
|
||||
&compressedSize2, &compressedLength2);
|
||||
|
||||
for (int y = 0; y < 16; y++) {
|
||||
for (int x = 0; x < 16; x++) {
|
||||
ushort tidD = (ushort)((bytes2[ttpos] << 8) + bytes[ttpos]);
|
||||
|
||||
int tpos = tidD;
|
||||
if (tpos < tiles32.size()) {
|
||||
if (i < 64) {
|
||||
allmapsTilesLW[(x * 2) + (sx * 32)][(y * 2) + (sy * 32)] =
|
||||
tiles32[tpos].tile0_;
|
||||
allmapsTilesLW[(x * 2) + 1 + (sx * 32)][(y * 2) + (sy * 32)] =
|
||||
tiles32[tpos].tile1_;
|
||||
allmapsTilesLW[(x * 2) + (sx * 32)][(y * 2) + 1 + (sy * 32)] =
|
||||
tiles32[tpos].tile2_;
|
||||
allmapsTilesLW[(x * 2) + 1 + (sx * 32)][(y * 2) + 1 + (sy * 32)] =
|
||||
tiles32[tpos].tile3_;
|
||||
} else if (i < 128 && i >= 64) {
|
||||
allmapsTilesDW[(x * 2) + (sx * 32)][(y * 2) + (sy * 32)] =
|
||||
tiles32[tpos].tile0_;
|
||||
allmapsTilesDW[(x * 2) + 1 + (sx * 32)][(y * 2) + (sy * 32)] =
|
||||
tiles32[tpos].tile1_;
|
||||
allmapsTilesDW[(x * 2) + (sx * 32)][(y * 2) + 1 + (sy * 32)] =
|
||||
tiles32[tpos].tile2_;
|
||||
allmapsTilesDW[(x * 2) + 1 + (sx * 32)][(y * 2) + 1 + (sy * 32)] =
|
||||
tiles32[tpos].tile3_;
|
||||
} else {
|
||||
allmapsTilesSP[(x * 2) + (sx * 32)][(y * 2) + (sy * 32)] =
|
||||
tiles32[tpos].tile0_;
|
||||
allmapsTilesSP[(x * 2) + 1 + (sx * 32)][(y * 2) + (sy * 32)] =
|
||||
tiles32[tpos].tile1_;
|
||||
allmapsTilesSP[(x * 2) + (sx * 32)][(y * 2) + 1 + (sy * 32)] =
|
||||
tiles32[tpos].tile2_;
|
||||
allmapsTilesSP[(x * 2) + 1 + (sx * 32)][(y * 2) + 1 + (sy * 32)] =
|
||||
tiles32[tpos].tile3_;
|
||||
}
|
||||
}
|
||||
|
||||
ttpos += 1;
|
||||
}
|
||||
}
|
||||
|
||||
sx++;
|
||||
if (sx >= 8) {
|
||||
sy++;
|
||||
sx = 0;
|
||||
}
|
||||
|
||||
c++;
|
||||
if (c >= 64) {
|
||||
sx = 0;
|
||||
sy = 0;
|
||||
c = 0;
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "MapPointers(lowest) : " << lowest << std::endl;
|
||||
std::cout << "MapPointers(highest) : " << highest << std::endl;
|
||||
}
|
||||
|
||||
void Overworld::FetchLargeMaps() {
|
||||
for (int i = 128; i < 145; i++) {
|
||||
mapParent[i] = 0;
|
||||
}
|
||||
|
||||
mapParent[128] = 128;
|
||||
mapParent[129] = 129;
|
||||
mapParent[130] = 129;
|
||||
mapParent[137] = 129;
|
||||
mapParent[138] = 129;
|
||||
mapParent[136] = 136;
|
||||
allmaps[136].largeMap = false;
|
||||
|
||||
bool mapChecked[64];
|
||||
for (int i = 0; i < 64; i++) {
|
||||
mapChecked[i] = false;
|
||||
}
|
||||
int xx = 0;
|
||||
int yy = 0;
|
||||
while (true) {
|
||||
int i = xx + (yy * 8);
|
||||
if (mapChecked[i] == false) {
|
||||
if (allmaps[i].largeMap == true) {
|
||||
mapChecked[i] = true;
|
||||
mapParent[i] = (uchar)i;
|
||||
mapParent[i + 64] = (uchar)(i + 64);
|
||||
|
||||
mapChecked[i + 1] = true;
|
||||
mapParent[i + 1] = (uchar)i;
|
||||
mapParent[i + 65] = (uchar)(i + 64);
|
||||
|
||||
mapChecked[i + 8] = true;
|
||||
mapParent[i + 8] = (uchar)i;
|
||||
mapParent[i + 72] = (uchar)(i + 64);
|
||||
|
||||
mapChecked[i + 9] = true;
|
||||
mapParent[i + 9] = (uchar)i;
|
||||
mapParent[i + 73] = (uchar)(i + 64);
|
||||
xx++;
|
||||
} else {
|
||||
mapParent[i] = (uchar)i;
|
||||
mapParent[i + 64] = (uchar)(i + 64);
|
||||
mapChecked[i] = true;
|
||||
}
|
||||
}
|
||||
|
||||
xx++;
|
||||
if (xx >= 8) {
|
||||
xx = 0;
|
||||
yy += 1;
|
||||
if (yy >= 8) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Overworld::LoadOverworldMap() {
|
||||
overworldMapBitmap = new Bitmap(128, 128, overworldMapPointer);
|
||||
owactualMapBitmap = new Bitmap(512, 512, owactualMapPointer);
|
||||
|
||||
// Mode 7
|
||||
char* ptr = overworldMapPointer;
|
||||
|
||||
int pos = 0;
|
||||
for (int sy = 0; sy < 16; sy++) {
|
||||
for (int sx = 0; sx < 16; sx++) {
|
||||
for (int y = 0; y < 8; y++) {
|
||||
for (int x = 0; x < 8; x++) {
|
||||
ptr[x + (sx * 8) + (y * 128) + (sy * 1024)] =
|
||||
rom_.GetRawData()[0x0C4000 + pos];
|
||||
pos++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ColorPalette cp = overworldMapBitmap.Palette;
|
||||
// for (int i = 0; i < 256; i += 2)
|
||||
// {
|
||||
// //55B27 = US LW
|
||||
// //55C27 = US DW
|
||||
// cp.Entries[i / 2] = getColor((short)((ROM.DATA[0x55B27 + i + 1] << 8) +
|
||||
// ROM.DATA[0x55B27 + i]));
|
||||
|
||||
// int k = 0;
|
||||
// int j = 0;
|
||||
// for (int y = 10; y < 14; y++)
|
||||
// {
|
||||
// for (int x = 0; x < 15; x++)
|
||||
// {
|
||||
// cp.Entries[145 + k] = Palettes.globalSprite_Palettes[0][j];
|
||||
// k++;
|
||||
// j++;
|
||||
// }
|
||||
// k++;
|
||||
// }
|
||||
// }
|
||||
|
||||
// overworldMapBitmap.Palette = cp;
|
||||
// owactualMapBitmap.Palette = cp;
|
||||
}
|
||||
|
||||
} // namespace Data
|
||||
} // namespace application
|
||||
} // namespace yaze
|
||||
74
src/application/Data/OW/overworld.h
Normal file
74
src/application/Data/OW/overworld.h
Normal file
@@ -0,0 +1,74 @@
|
||||
#ifndef YAZE_APPLICATION_DATA_OVERWORLD_H
|
||||
#define YAZE_APPLICATION_DATA_OVERWORLD_H
|
||||
|
||||
#include <rommapping.h>
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "Core/constants.h"
|
||||
#include "Data/rom.h"
|
||||
#include "Graphics/bitmap.h"
|
||||
#include "Graphics/tile.h"
|
||||
#include "overworld_map.h"
|
||||
|
||||
namespace yaze {
|
||||
namespace application {
|
||||
namespace Data {
|
||||
|
||||
class Overworld {
|
||||
public:
|
||||
Overworld() = default;
|
||||
~Overworld();
|
||||
|
||||
void Load(Data::ROM rom);
|
||||
|
||||
char* overworldMapPointer = new char[0x40000];
|
||||
Graphics::Bitmap* overworldMapBitmap;
|
||||
|
||||
char* owactualMapPointer = new char[0x40000];
|
||||
Graphics::Bitmap* owactualMapBitmap;
|
||||
|
||||
private:
|
||||
Data::ROM rom_;
|
||||
int gameState = 1;
|
||||
bool isLoaded = false;
|
||||
uchar mapParent[160];
|
||||
|
||||
ushort** allmapsTilesLW; // 64 maps * (32*32 tiles)
|
||||
ushort** allmapsTilesDW; // 64 maps * (32*32 tiles)
|
||||
ushort** allmapsTilesSP; // 32 maps * (32*32 tiles)
|
||||
|
||||
std::vector<Graphics::Tile16> tiles16;
|
||||
std::vector<Graphics::Tile32> tiles32;
|
||||
std::vector<Graphics::Tile32> map16tiles;
|
||||
|
||||
std::vector<OverworldMap> allmaps;
|
||||
|
||||
std::vector<ushort> tileLeftEntrance;
|
||||
std::vector<ushort> tileRightEntrance;
|
||||
|
||||
int map32address[4] = {
|
||||
Core::Constants::map32TilesTL, Core::Constants::map32TilesTR,
|
||||
Core::Constants::map32TilesBL, Core::Constants::map32TilesBR};
|
||||
|
||||
enum Dimension {
|
||||
map32TilesTL = 0,
|
||||
map32TilesTR = 1,
|
||||
map32TilesBL = 2,
|
||||
map32TilesBR = 3
|
||||
};
|
||||
|
||||
ushort GenerateTile32(int i, int k, int dimension);
|
||||
void AssembleMap32Tiles();
|
||||
void AssembleMap16Tiles();
|
||||
void DecompressAllMapTiles();
|
||||
void FetchLargeMaps();
|
||||
void LoadOverworldMap();
|
||||
};
|
||||
|
||||
} // namespace Data
|
||||
} // namespace application
|
||||
} // namespace yaze
|
||||
|
||||
#endif
|
||||
359
src/application/Data/OW/overworld_map.cc
Normal file
359
src/application/Data/OW/overworld_map.cc
Normal file
@@ -0,0 +1,359 @@
|
||||
#include "overworld_map.h"
|
||||
|
||||
#include "Data/rom.h"
|
||||
#include "Graphics/tile.h"
|
||||
|
||||
namespace yaze {
|
||||
namespace application {
|
||||
namespace Data {
|
||||
|
||||
using namespace Core;
|
||||
using namespace Graphics;
|
||||
|
||||
OverworldMap::OverworldMap(Data::ROM rom,
|
||||
const std::vector<Graphics::Tile16> tiles16,
|
||||
uchar index)
|
||||
: rom_(rom), index(index), tiles16_(tiles16), parent(index) {
|
||||
if (index != 0x80) {
|
||||
if (index <= 150) {
|
||||
if (rom_.GetRawData()[Constants::overworldMapSize + (index & 0x3F)] !=
|
||||
0) {
|
||||
largeMap = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (index < 64) {
|
||||
sprgfx[0] = rom_.GetRawData()[Constants::overworldSpriteset + parent];
|
||||
sprgfx[1] = rom_.GetRawData()[Constants::overworldSpriteset + parent + 64];
|
||||
sprgfx[2] = rom_.GetRawData()[Constants::overworldSpriteset + parent + 128];
|
||||
gfx = rom_.GetRawData()[Constants::mapGfx + parent];
|
||||
palette = rom_.GetRawData()[Constants::overworldMapPalette + parent];
|
||||
sprpalette[0] =
|
||||
rom_.GetRawData()[Constants::overworldSpritePalette + parent];
|
||||
sprpalette[1] =
|
||||
rom_.GetRawData()[Constants::overworldSpritePalette + parent + 64];
|
||||
sprpalette[2] =
|
||||
rom_.GetRawData()[Constants::overworldSpritePalette + parent + 128];
|
||||
musics[0] = rom_.GetRawData()[Constants::overworldMusicBegining + parent];
|
||||
musics[1] = rom_.GetRawData()[Constants::overworldMusicZelda + parent];
|
||||
musics[2] =
|
||||
rom_.GetRawData()[Constants::overworldMusicMasterSword + parent];
|
||||
musics[3] = rom_.GetRawData()[Constants::overworldMusicAgahim + parent];
|
||||
} else if (index < 128) {
|
||||
sprgfx[0] = rom_.GetRawData()[Constants::overworldSpriteset + parent + 128];
|
||||
sprgfx[1] = rom_.GetRawData()[Constants::overworldSpriteset + parent + 128];
|
||||
sprgfx[2] = rom_.GetRawData()[Constants::overworldSpriteset + parent + 128];
|
||||
gfx = rom_.GetRawData()[Constants::mapGfx + parent];
|
||||
palette = rom_.GetRawData()[Constants::overworldMapPalette + parent];
|
||||
sprpalette[0] =
|
||||
rom_.GetRawData()[Constants::overworldSpritePalette + parent + 128];
|
||||
sprpalette[1] =
|
||||
rom_.GetRawData()[Constants::overworldSpritePalette + parent + 128];
|
||||
sprpalette[2] =
|
||||
rom_.GetRawData()[Constants::overworldSpritePalette + parent + 128];
|
||||
|
||||
musics[0] = rom_.GetRawData()[Constants::overworldMusicDW + (parent - 64)];
|
||||
} else {
|
||||
if (index == 0x94) {
|
||||
parent = 128;
|
||||
} else if (index == 0x95) {
|
||||
parent = 03;
|
||||
} else if (index == 0x96) // pyramid bg use 0x5B map
|
||||
{
|
||||
parent = 0x5B;
|
||||
} else if (index == 0x97) // pyramid bg use 0x5B map
|
||||
{
|
||||
parent = 0x00;
|
||||
} else if (index == 156) {
|
||||
parent = 67;
|
||||
} else if (index == 157) {
|
||||
parent = 0;
|
||||
} else if (index == 158) {
|
||||
parent = 0;
|
||||
} else if (index == 159) {
|
||||
parent = 44;
|
||||
} else if (index == 136) {
|
||||
parent = 136;
|
||||
}
|
||||
|
||||
messageID = rom_.GetRawData()[Constants::overworldMessages + parent];
|
||||
|
||||
sprgfx[0] = rom_.GetRawData()[Constants::overworldSpriteset + parent + 128];
|
||||
sprgfx[1] = rom_.GetRawData()[Constants::overworldSpriteset + parent + 128];
|
||||
sprgfx[2] = rom_.GetRawData()[Constants::overworldSpriteset + parent + 128];
|
||||
sprpalette[0] =
|
||||
rom_.GetRawData()[Constants::overworldSpritePalette + parent + 128];
|
||||
sprpalette[1] =
|
||||
rom_.GetRawData()[Constants::overworldSpritePalette + parent + 128];
|
||||
sprpalette[2] =
|
||||
rom_.GetRawData()[Constants::overworldSpritePalette + parent + 128];
|
||||
|
||||
palette =
|
||||
rom_.GetRawData()[Constants::overworldSpecialPALGroup + parent - 128];
|
||||
if (index >= 0x80 && index <= 0x8A && index != 0x88) {
|
||||
gfx = rom_.GetRawData()[Constants::overworldSpecialGFXGroup +
|
||||
(parent - 128)];
|
||||
palette = rom_.GetRawData()[Constants::overworldSpecialPALGroup + 1];
|
||||
} else if (index == 0x88) {
|
||||
gfx = 81;
|
||||
palette = 0;
|
||||
} else // pyramid bg use 0x5B map
|
||||
{
|
||||
gfx = rom_.GetRawData()[Constants::mapGfx + parent];
|
||||
palette = rom_.GetRawData()[Constants::overworldMapPalette + parent];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OverworldMap::BuildMap(uchar* mapParent, int count, int gameState,
|
||||
ushort** allmapsTilesLW, ushort** allmapsTilesDW,
|
||||
ushort** allmapsTilesSP) {
|
||||
tilesUsed = new ushort*[32];
|
||||
for (int i = 0; i < 32; i++) tilesUsed[i] = new ushort;
|
||||
|
||||
if (largeMap) {
|
||||
this->parent = mapParent[index];
|
||||
|
||||
if (parent != index) {
|
||||
if (!firstLoad) {
|
||||
gfx = rom_.GetRawData()[Constants::mapGfx + parent];
|
||||
palette = rom_.GetRawData()[Constants::overworldMapPalette + parent];
|
||||
firstLoad = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BuildTileset(gameState);
|
||||
BuildTiles16Gfx(count); // build on GFX.mapgfx16Ptr
|
||||
|
||||
int world = 0;
|
||||
|
||||
if (index < 64) {
|
||||
tilesUsed = allmapsTilesLW;
|
||||
} else if (index < 128 && index >= 64) {
|
||||
tilesUsed = allmapsTilesDW;
|
||||
world = 1;
|
||||
} else {
|
||||
tilesUsed = allmapsTilesSP;
|
||||
world = 2;
|
||||
}
|
||||
|
||||
int superY = ((index - (world * 64)) / 8);
|
||||
int superX = index - (world * 64) - (superY * 8);
|
||||
|
||||
for (int y = 0; y < 32; y++) {
|
||||
for (int x = 0; x < 32; x++) {
|
||||
CopyTile8bpp16((x * 16), (y * 16),
|
||||
tilesUsed[x + (superX * 32)][y + (superY * 32)], gfxPtr,
|
||||
mapblockset16);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OverworldMap::CopyTile8bpp16(int x, int y, int tile, int* destbmpPtr,
|
||||
int* sourcebmpPtr) {
|
||||
int sourceY = (tile / 8);
|
||||
int sourceX = (tile) - ((sourceY)*8);
|
||||
int sourcePtrPos = ((tile - ((tile / 8) * 8)) * 16) +
|
||||
((tile / 8) * 2048); //(sourceX * 16) + (sourceY * 128);
|
||||
uchar* sourcePtr = (uchar*)sourcebmpPtr;
|
||||
|
||||
int destPtrPos = (x + (y * 512));
|
||||
uchar* destPtr = (uchar*)destbmpPtr;
|
||||
|
||||
for (int ystrip = 0; ystrip < 16; ystrip++) {
|
||||
for (int xstrip = 0; xstrip < 16; xstrip++) {
|
||||
destPtr[destPtrPos + xstrip + (ystrip * 512)] =
|
||||
sourcePtr[sourcePtrPos + xstrip + (ystrip * 128)];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OverworldMap::CopyTile8bpp16From8(int xP, int yP, int tileID,
|
||||
int* destbmpPtr, int* sourcebmpPtr) {
|
||||
auto gfx16Data = (uchar*)destbmpPtr;
|
||||
|
||||
auto gfx8Data = currentOWgfx16Ptr;
|
||||
|
||||
int offsets[] = {0, 8, 4096, 4104};
|
||||
|
||||
auto tiles = tiles16_[tileID];
|
||||
|
||||
for (auto tile = 0; tile < 4; tile++) {
|
||||
TileInfo info = tiles.tiles_info[tile];
|
||||
int offset = offsets[tile];
|
||||
|
||||
for (auto y = 0; y < 8; y++) {
|
||||
for (auto x = 0; x < 4; x++) {
|
||||
CopyTileToMap(x, y, xP, yP, offset, info, gfx16Data, gfx8Data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OverworldMap::BuildTiles16Gfx(int count) {
|
||||
uchar* gfx16Data = (uchar*)mapblockset16;
|
||||
uchar* gfx8Data = currentOWgfx16Ptr;
|
||||
|
||||
int offsets[] = {0, 8, 1024, 1032};
|
||||
auto yy = 0;
|
||||
auto xx = 0;
|
||||
|
||||
for (auto i = 0; i < count; i++) // number of tiles16 3748?
|
||||
{
|
||||
// 8x8 tile draw
|
||||
// gfx8 = 4bpp so everyting is /2F
|
||||
auto tiles = tiles16_[i];
|
||||
|
||||
for (auto tile = 0; tile < 4; tile++) {
|
||||
TileInfo info = tiles16_[i].tiles_info[tile];
|
||||
int offset = offsets[tile];
|
||||
|
||||
for (auto y = 0; y < 8; y++) {
|
||||
for (auto x = 0; x < 4; x++) {
|
||||
CopyTile(x, y, xx, yy, offset, info, gfx16Data, gfx8Data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
xx += 16;
|
||||
if (xx >= 128) {
|
||||
yy += 2048;
|
||||
xx = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OverworldMap::CopyTile(int x, int y, int xx, int yy, int offset,
|
||||
TileInfo tile, uchar* gfx16Pointer,
|
||||
uchar* gfx8Pointer) // map,current
|
||||
{
|
||||
int mx = x;
|
||||
int my = y;
|
||||
uchar r = 0;
|
||||
|
||||
if (tile.horizontal_mirror_ != 0) {
|
||||
mx = 3 - x;
|
||||
r = 1;
|
||||
}
|
||||
|
||||
if (tile.vertical_mirror_ != 0) {
|
||||
my = 7 - y;
|
||||
}
|
||||
|
||||
int tx = ((tile.id_ / 16) * 512) + ((tile.id_ - ((tile.id_ / 16) * 16)) * 4);
|
||||
auto index = xx + yy + offset + (mx * 2) + (my * 128);
|
||||
auto pixel = gfx8Pointer[tx + (y * 64) + x];
|
||||
|
||||
gfx16Pointer[index + r ^ 1] = (uchar)((pixel & 0x0F) + tile.palette_ * 16);
|
||||
gfx16Pointer[index + r] = (uchar)(((pixel >> 4) & 0x0F) + tile.palette_ * 16);
|
||||
}
|
||||
|
||||
void OverworldMap::CopyTileToMap(int x, int y, int xx, int yy, int offset,
|
||||
TileInfo tile, uchar* gfx16Pointer,
|
||||
uchar* gfx8Pointer) // map,current
|
||||
{
|
||||
int mx = x;
|
||||
int my = y;
|
||||
uchar r = 0;
|
||||
|
||||
if (tile.horizontal_mirror_ != 0) {
|
||||
mx = 3 - x;
|
||||
r = 1;
|
||||
}
|
||||
|
||||
if (tile.vertical_mirror_ != 0) {
|
||||
my = 7 - y;
|
||||
}
|
||||
|
||||
int tx = ((tile.id_ / 16) * 512) + ((tile.id_ - ((tile.id_ / 16) * 16)) * 4);
|
||||
auto index = xx + (yy * 512) + offset + (mx * 2) + (my * 512);
|
||||
auto pixel = gfx8Pointer[tx + (y * 64) + x];
|
||||
|
||||
gfx16Pointer[index + r ^ 1] = (uchar)((pixel & 0x0F) + tile.palette_ * 16);
|
||||
gfx16Pointer[index + r] = (uchar)(((pixel >> 4) & 0x0F) + tile.palette_ * 16);
|
||||
}
|
||||
|
||||
void OverworldMap::BuildTileset(int gameState) {
|
||||
int indexWorld = 0x20;
|
||||
if (parent < 0x40) {
|
||||
indexWorld = 0x20;
|
||||
} else if (parent >= 0x40 && parent < 0x80) {
|
||||
indexWorld = 0x21;
|
||||
} else if (parent == 0x88) {
|
||||
indexWorld = 36;
|
||||
}
|
||||
|
||||
// Sprites Blocksets
|
||||
staticgfx[8] = 115 + 0;
|
||||
staticgfx[9] = 115 + 1;
|
||||
staticgfx[10] = 115 + 6;
|
||||
staticgfx[11] = 115 + 7;
|
||||
for (int i = 0; i < 4; i++) {
|
||||
staticgfx[12 + i] =
|
||||
(uchar)(rom_.GetRawData()[Constants::sprite_blockset_pointer +
|
||||
(sprgfx[gameState] * 4) + i] +
|
||||
115);
|
||||
}
|
||||
|
||||
// Main Blocksets
|
||||
for (int i = 0; i < 8; i++) {
|
||||
staticgfx[i] = rom_.GetRawData()[Constants::overworldgfxGroups2 +
|
||||
(indexWorld * 8) + i];
|
||||
}
|
||||
|
||||
if (rom_.GetRawData()[Constants::overworldgfxGroups + (gfx * 4)] != 0) {
|
||||
staticgfx[3] = rom_.GetRawData()[Constants::overworldgfxGroups + (gfx * 4)];
|
||||
}
|
||||
if (rom_.GetRawData()[Constants::overworldgfxGroups + (gfx * 4) + 1] != 0) {
|
||||
staticgfx[4] =
|
||||
rom_.GetRawData()[Constants::overworldgfxGroups + (gfx * 4) + 1];
|
||||
}
|
||||
if (rom_.GetRawData()[Constants::overworldgfxGroups + (gfx * 4) + 2] != 0) {
|
||||
staticgfx[5] =
|
||||
rom_.GetRawData()[Constants::overworldgfxGroups + (gfx * 4) + 2];
|
||||
}
|
||||
if (rom_.GetRawData()[Constants::overworldgfxGroups + (gfx * 4) + 3] != 0) {
|
||||
staticgfx[6] =
|
||||
rom_.GetRawData()[Constants::overworldgfxGroups + (gfx * 4) + 3];
|
||||
}
|
||||
|
||||
// Hardcoded overworld GFX Values, for death mountain
|
||||
if ((parent >= 0x03 && parent <= 0x07) ||
|
||||
(parent >= 0x0B && parent <= 0x0E)) {
|
||||
staticgfx[7] = 89;
|
||||
} else if ((parent >= 0x43 && parent <= 0x47) ||
|
||||
(parent >= 0x4B && parent <= 0x4E)) {
|
||||
staticgfx[7] = 89;
|
||||
} else {
|
||||
staticgfx[7] = 91;
|
||||
}
|
||||
|
||||
uchar* currentmapgfx8Data = new uchar[(128 * 512) / 2];
|
||||
// (uchar*)GFX.currentOWgfx16Ptr.ToPointer(); // loaded gfx for the current
|
||||
// // map (empty at this point)
|
||||
uchar* allgfxData = new uchar[(128 * 7136) / 2];
|
||||
// (uchar*)GFX.allgfx16Ptr
|
||||
// .ToPointer(); // all gfx of the game pack of 2048 uchars (4bpp)
|
||||
|
||||
for (int i = 0; i < 16; i++) {
|
||||
for (int j = 0; j < 2048; j++) {
|
||||
uchar mapByte = allgfxData[j + (staticgfx[i] * 2048)];
|
||||
switch (i) {
|
||||
case 0:
|
||||
case 3:
|
||||
case 4:
|
||||
case 5:
|
||||
mapByte += 0x88;
|
||||
break;
|
||||
}
|
||||
|
||||
currentmapgfx8Data[(i * 2048) + j] = mapByte; // Upload used gfx data
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Data
|
||||
} // namespace application
|
||||
} // namespace yaze
|
||||
77
src/application/Data/OW/overworld_map.h
Normal file
77
src/application/Data/OW/overworld_map.h
Normal file
@@ -0,0 +1,77 @@
|
||||
#include <imgui/imgui.h>
|
||||
|
||||
#include <cstddef>
|
||||
#include <memory>
|
||||
|
||||
#include "Data/rom.h"
|
||||
#include "Graphics/bitmap.h"
|
||||
#include "Graphics/tile.h"
|
||||
|
||||
namespace yaze {
|
||||
namespace application {
|
||||
namespace Data {
|
||||
|
||||
using ushort = unsigned short;
|
||||
|
||||
class OverworldMap {
|
||||
public:
|
||||
uchar parent = 0;
|
||||
uchar index = 0;
|
||||
uchar gfx = 0;
|
||||
uchar palette = 0;
|
||||
bool firstLoad = false;
|
||||
short messageID = 0;
|
||||
bool largeMap = false;
|
||||
|
||||
uchar sprgfx[3];
|
||||
uchar sprpalette[3];
|
||||
uchar musics[4];
|
||||
|
||||
int* gfxPtr = new int[512 * 512];
|
||||
int* mapblockset16 = new int[1048576];
|
||||
Graphics::Bitmap mapblockset16Bitmap;
|
||||
Graphics::Bitmap gfxBitmap;
|
||||
|
||||
uchar* staticgfx =
|
||||
new uchar[16]; // Need to be used to display map and not pre render it!
|
||||
ushort** tilesUsed;
|
||||
|
||||
bool needRefresh = false;
|
||||
Data::ROM rom_;
|
||||
|
||||
uchar* currentOWgfx16Ptr = new uchar[(128 * 512) / 2];
|
||||
std::vector<Graphics::Tile16> tiles16_;
|
||||
|
||||
OverworldMap(Data::ROM rom, const std::vector<Graphics::Tile16> tiles16,
|
||||
uchar index);
|
||||
void BuildMap(uchar* mapParent, int count, int gameState,
|
||||
ushort** allmapsTilesLW, ushort** allmapsTilesDW,
|
||||
ushort** allmapsTilesSP);
|
||||
void CopyTile8bpp16(int x, int y, int tile, int* destbmpPtr,
|
||||
int* sourcebmpPtr);
|
||||
void CopyTile8bpp16From8(int xP, int yP, int tileID, int* destbmpPtr,
|
||||
int* sourcebmpPtr);
|
||||
|
||||
private:
|
||||
void BuildTiles16Gfx(int count);
|
||||
// void ReloadPalettes() { LoadPalette(); }
|
||||
|
||||
void CopyTile(int x, int y, int xx, int yy, int offset,
|
||||
Graphics::TileInfo tile, uchar* gfx16Pointer,
|
||||
uchar* gfx8Pointer);
|
||||
void CopyTileToMap(int x, int y, int xx, int yy, int offset,
|
||||
Graphics::TileInfo tile, uchar* gfx16Pointer,
|
||||
uchar* gfx8Pointer);
|
||||
|
||||
void LoadPalette();
|
||||
|
||||
void SetColorsPalette(int index, ImVec4 main, ImVec4 animated, ImVec4 aux1,
|
||||
ImVec4 aux2, ImVec4 hud, ImVec4 bgrcolor, ImVec4 spr,
|
||||
ImVec4 spr2);
|
||||
|
||||
void BuildTileset(int gameState);
|
||||
};
|
||||
|
||||
} // namespace Data
|
||||
} // namespace application
|
||||
} // namespace yaze
|
||||
Reference in New Issue
Block a user