From 32d19edbfcf318a53fb81dd21de8d3321501820d Mon Sep 17 00:00:00 2001 From: scawful Date: Mon, 13 Jun 2022 18:43:19 -0400 Subject: [PATCH] type cleaning and housekeeping --- src/Application/Core/constants.h | 2 +- src/Application/Data/OW/overworld.cc | 47 +++++++++++----------- src/Application/Data/OW/overworld.h | 5 +-- src/Application/Data/OW/overworld_map.cc | 48 +++++++++++------------ src/Application/Data/OW/overworld_map.h | 33 ++++++++-------- src/Application/Data/rom.cc | 4 +- src/Application/Data/rom.h | 12 +++--- src/Application/Editor/editor.cc | 4 +- src/Application/Editor/overworld_editor.h | 4 +- src/Application/Graphics/palette.cc | 27 +++++-------- src/Application/Graphics/palette.h | 6 +-- src/Application/Graphics/tile.h | 6 +-- 12 files changed, 92 insertions(+), 106 deletions(-) diff --git a/src/Application/Core/constants.h b/src/Application/Core/constants.h index aa6f6ec4..f4bfb5e6 100644 --- a/src/Application/Core/constants.h +++ b/src/Application/Core/constants.h @@ -16,7 +16,7 @@ ImGui::EndMenuBar(); \ } -using byte = unsigned char; + namespace yaze { namespace Application { diff --git a/src/Application/Data/OW/overworld.cc b/src/Application/Data/OW/overworld.cc index 5b54eba7..bff60dfb 100644 --- a/src/Application/Data/OW/overworld.cc +++ b/src/Application/Data/OW/overworld.cc @@ -11,18 +11,19 @@ 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; + 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) { @@ -31,7 +32,7 @@ static TileInfo GetTilesInfo(ushort tile) { ushort v = 0; ushort h = 0; ushort tid = (ushort)(tile & 0x3FF); - byte p = (byte)((tile >> 10) & 0x07); + uchar p = (uchar)((tile >> 10) & 0x07); o = (ushort)((tile & 0x2000) >> 13); h = (ushort)((tile & 0x4000) >> 14); @@ -56,7 +57,7 @@ void Overworld::Load(Data::ROM rom) { // Map Initialization : for (int i = 0; i < 160; i++) { - allmaps.push_back(OverworldMap(rom_, tiles16, (byte)i)); + allmaps.push_back(OverworldMap(rom_, tiles16, (uchar)i)); } FetchLargeMaps(); LoadOverworldMap(); @@ -264,24 +265,24 @@ void Overworld::FetchLargeMaps() { if (mapChecked[i] == false) { if (allmaps[i].largeMap == true) { mapChecked[i] = true; - mapParent[i] = (byte)i; - mapParent[i + 64] = (byte)(i + 64); + mapParent[i] = (uchar)i; + mapParent[i + 64] = (uchar)(i + 64); mapChecked[i + 1] = true; - mapParent[i + 1] = (byte)i; - mapParent[i + 65] = (byte)(i + 64); + mapParent[i + 1] = (uchar)i; + mapParent[i + 65] = (uchar)(i + 64); mapChecked[i + 8] = true; - mapParent[i + 8] = (byte)i; - mapParent[i + 72] = (byte)(i + 64); + mapParent[i + 8] = (uchar)i; + mapParent[i + 72] = (uchar)(i + 64); mapChecked[i + 9] = true; - mapParent[i + 9] = (byte)i; - mapParent[i + 73] = (byte)(i + 64); + mapParent[i + 9] = (uchar)i; + mapParent[i + 73] = (uchar)(i + 64); xx++; } else { - mapParent[i] = (byte)i; - mapParent[i + 64] = (byte)(i + 64); + mapParent[i] = (uchar)i; + mapParent[i + 64] = (uchar)(i + 64); mapChecked[i] = true; } } diff --git a/src/Application/Data/OW/overworld.h b/src/Application/Data/OW/overworld.h index e4c5eea4..537478b1 100644 --- a/src/Application/Data/OW/overworld.h +++ b/src/Application/Data/OW/overworld.h @@ -16,9 +16,6 @@ namespace yaze { namespace Application { namespace Data { -using ushort = unsigned short; -using byte = unsigned char; - class Overworld { public: Overworld() = default; @@ -36,7 +33,7 @@ class Overworld { Data::ROM rom_; int gameState = 1; bool isLoaded = false; - byte mapParent[160]; + uchar mapParent[160]; ushort** allmapsTilesLW; // 64 maps * (32*32 tiles) ushort** allmapsTilesDW; // 64 maps * (32*32 tiles) diff --git a/src/Application/Data/OW/overworld_map.cc b/src/Application/Data/OW/overworld_map.cc index d0c2b37a..26816ea8 100644 --- a/src/Application/Data/OW/overworld_map.cc +++ b/src/Application/Data/OW/overworld_map.cc @@ -12,7 +12,7 @@ using namespace Graphics; OverworldMap::OverworldMap(Data::ROM rom, const std::vector tiles16, - byte index) + uchar index) : rom_(rom), index(index), tiles16_(tiles16), parent(index) { if (index != 0x80) { if (index <= 150) { @@ -106,7 +106,7 @@ OverworldMap::OverworldMap(Data::ROM rom, } } -void OverworldMap::BuildMap(byte* mapParent, int count, int gameState, +void OverworldMap::BuildMap(uchar* mapParent, int count, int gameState, ushort** allmapsTilesLW, ushort** allmapsTilesDW, ushort** allmapsTilesSP) { tilesUsed = new ushort*[32]; @@ -157,10 +157,10 @@ void OverworldMap::CopyTile8bpp16(int x, int y, int tile, int* destbmpPtr, int sourceX = (tile) - ((sourceY)*8); int sourcePtrPos = ((tile - ((tile / 8) * 8)) * 16) + ((tile / 8) * 2048); //(sourceX * 16) + (sourceY * 128); - byte* sourcePtr = (byte*)sourcebmpPtr; + uchar* sourcePtr = (uchar*)sourcebmpPtr; int destPtrPos = (x + (y * 512)); - byte* destPtr = (byte*)destbmpPtr; + uchar* destPtr = (uchar*)destbmpPtr; for (int ystrip = 0; ystrip < 16; ystrip++) { for (int xstrip = 0; xstrip < 16; xstrip++) { @@ -172,7 +172,7 @@ void OverworldMap::CopyTile8bpp16(int x, int y, int tile, int* destbmpPtr, void OverworldMap::CopyTile8bpp16From8(int xP, int yP, int tileID, int* destbmpPtr, int* sourcebmpPtr) { - auto gfx16Data = (byte*)destbmpPtr; + auto gfx16Data = (uchar*)destbmpPtr; auto gfx8Data = currentOWgfx16Ptr; @@ -193,8 +193,8 @@ void OverworldMap::CopyTile8bpp16From8(int xP, int yP, int tileID, } void OverworldMap::BuildTiles16Gfx(int count) { - byte* gfx16Data = (byte*)mapblockset16; - byte* gfx8Data = currentOWgfx16Ptr; + uchar* gfx16Data = (uchar*)mapblockset16; + uchar* gfx8Data = currentOWgfx16Ptr; int offsets[] = {0, 8, 1024, 1032}; auto yy = 0; @@ -226,12 +226,12 @@ void OverworldMap::BuildTiles16Gfx(int count) { } void OverworldMap::CopyTile(int x, int y, int xx, int yy, int offset, - TileInfo tile, byte* gfx16Pointer, - byte* gfx8Pointer) // map,current + TileInfo tile, uchar* gfx16Pointer, + uchar* gfx8Pointer) // map,current { int mx = x; int my = y; - byte r = 0; + uchar r = 0; if (tile.horizontal_mirror_ != 0) { mx = 3 - x; @@ -246,17 +246,17 @@ void OverworldMap::CopyTile(int x, int y, int xx, int yy, int offset, auto index = xx + yy + offset + (mx * 2) + (my * 128); auto pixel = gfx8Pointer[tx + (y * 64) + x]; - gfx16Pointer[index + r ^ 1] = (byte)((pixel & 0x0F) + tile.palette_ * 16); - gfx16Pointer[index + r] = (byte)(((pixel >> 4) & 0x0F) + tile.palette_ * 16); + 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, byte* gfx16Pointer, - byte* gfx8Pointer) // map,current + TileInfo tile, uchar* gfx16Pointer, + uchar* gfx8Pointer) // map,current { int mx = x; int my = y; - byte r = 0; + uchar r = 0; if (tile.horizontal_mirror_ != 0) { mx = 3 - x; @@ -271,8 +271,8 @@ void OverworldMap::CopyTileToMap(int x, int y, int xx, int yy, int offset, auto index = xx + (yy * 512) + offset + (mx * 2) + (my * 512); auto pixel = gfx8Pointer[tx + (y * 64) + x]; - gfx16Pointer[index + r ^ 1] = (byte)((pixel & 0x0F) + tile.palette_ * 16); - gfx16Pointer[index + r] = (byte)(((pixel >> 4) & 0x0F) + tile.palette_ * 16); + 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) { @@ -292,7 +292,7 @@ void OverworldMap::BuildTileset(int gameState) { staticgfx[11] = 115 + 7; for (int i = 0; i < 4; i++) { staticgfx[12 + i] = - (byte)(rom_.GetRawData()[Constants::sprite_blockset_pointer + + (uchar)(rom_.GetRawData()[Constants::sprite_blockset_pointer + (sprgfx[gameState] * 4) + i] + 115); } @@ -330,16 +330,16 @@ void OverworldMap::BuildTileset(int gameState) { staticgfx[7] = 91; } - byte* currentmapgfx8Data = new byte[(128 * 512) / 2]; - // (byte*)GFX.currentOWgfx16Ptr.ToPointer(); // loaded gfx for the current + uchar* currentmapgfx8Data = new uchar[(128 * 512) / 2]; + // (uchar*)GFX.currentOWgfx16Ptr.ToPointer(); // loaded gfx for the current // // map (empty at this point) - byte* allgfxData = new byte[(128 * 7136) / 2]; - // (byte*)GFX.allgfx16Ptr - // .ToPointer(); // all gfx of the game pack of 2048 bytes (4bpp) + 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++) { - byte mapByte = allgfxData[j + (staticgfx[i] * 2048)]; + uchar mapByte = allgfxData[j + (staticgfx[i] * 2048)]; switch (i) { case 0: case 3: diff --git a/src/Application/Data/OW/overworld_map.h b/src/Application/Data/OW/overworld_map.h index c0d6ccf2..7bde40c4 100644 --- a/src/Application/Data/OW/overworld_map.h +++ b/src/Application/Data/OW/overworld_map.h @@ -1,5 +1,6 @@ #include +#include #include #include "Data/rom.h" @@ -10,41 +11,40 @@ namespace yaze { namespace Application { namespace Data { -using byte = unsigned char; using ushort = unsigned short; class OverworldMap { public: - byte parent = 0; - byte index = 0; - byte gfx = 0; - byte palette = 0; + uchar parent = 0; + uchar index = 0; + uchar gfx = 0; + uchar palette = 0; bool firstLoad = false; short messageID = 0; bool largeMap = false; - byte sprgfx[3]; - byte sprpalette[3]; - byte musics[4]; + 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; - byte* staticgfx = - new byte[16]; // Need to be used to display map and not pre render it! + 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_; - byte* currentOWgfx16Ptr = new byte[(128 * 512) / 2]; + uchar* currentOWgfx16Ptr = new uchar[(128 * 512) / 2]; std::vector tiles16_; OverworldMap(Data::ROM rom, const std::vector tiles16, - byte index); - void BuildMap(byte* mapParent, int count, int gameState, + 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, @@ -57,10 +57,11 @@ class OverworldMap { // void ReloadPalettes() { LoadPalette(); } void CopyTile(int x, int y, int xx, int yy, int offset, - Graphics::TileInfo tile, byte* gfx16Pointer, byte* gfx8Pointer); + Graphics::TileInfo tile, uchar* gfx16Pointer, + uchar* gfx8Pointer); void CopyTileToMap(int x, int y, int xx, int yy, int offset, - Graphics::TileInfo tile, byte* gfx16Pointer, - byte* gfx8Pointer); + Graphics::TileInfo tile, uchar* gfx16Pointer, + uchar* gfx8Pointer); void LoadPalette(); diff --git a/src/Application/Data/rom.cc b/src/Application/Data/rom.cc index 761233fe..25f90a9a 100644 --- a/src/Application/Data/rom.cc +++ b/src/Application/Data/rom.cc @@ -102,7 +102,7 @@ Graphics::SNESPalette ROM::ExtractPalette(Graphics::TilePreset &preset) { } uint32_t ROM::GetRomPosition(const Graphics::TilePreset &preset, int directAddr, - unsigned int snesAddr) { + unsigned int snesAddr) const { unsigned int filePos = -1; enum rom_type rType = LoROM; std::cout << "directAddr:" << directAddr << std::endl; @@ -116,7 +116,7 @@ uint32_t ROM::GetRomPosition(const Graphics::TilePreset &preset, int directAddr, return filePos; } -int AddressFromBytes(byte addr1, byte addr2, byte addr3) { +int AddressFromBytes(uchar addr1, uchar addr2, uchar addr3) { return (addr1 << 16) | (addr2 << 8) | addr3; } diff --git a/src/Application/Data/rom.h b/src/Application/Data/rom.h index cff9a11a..42c73237 100644 --- a/src/Application/Data/rom.h +++ b/src/Application/Data/rom.h @@ -20,9 +20,7 @@ namespace yaze { namespace Application { namespace Data { -using byte = unsigned char; - -int AddressFromBytes(byte addr1, byte addr2, byte addr3); +int AddressFromBytes(uchar addr1, uchar addr2, uchar addr3); class ROM { public: @@ -31,9 +29,9 @@ class ROM { void LoadFromFile(const std::string& path); std::vector ExtractTiles(Graphics::TilePreset& preset); Graphics::SNESPalette ExtractPalette(Graphics::TilePreset& preset); - uint32_t GetRomPosition(const Graphics::TilePreset& preset, - int directAddr, unsigned int snesAddr); - inline byte* GetRawData() { return current_rom_; } + uint32_t GetRomPosition(const Graphics::TilePreset& preset, int directAddr, + unsigned int snesAddr) const; + inline uchar* GetRawData() { return current_rom_; } const unsigned char* getTitle() const { return title; } long int getSize() const { return size_; } char getVersion() const { return version_; } @@ -43,7 +41,7 @@ class ROM { bool loaded = false; bool rom_has_header_ = false; - byte* current_rom_; + uchar* current_rom_; char* data_; long int size_; diff --git a/src/Application/Editor/editor.cc b/src/Application/Editor/editor.cc index 941cec44..4edf746e 100644 --- a/src/Application/Editor/editor.cc +++ b/src/Application/Editor/editor.cc @@ -252,8 +252,6 @@ void Editor::DrawHelpMenu() const { } void Editor::DrawProjectEditor() { - static bool inited = false; - if (ImGui::BeginTabItem("Project")) { if (ImGui::BeginTable("##projectTable", 2, ImGuiTableFlags_SizingStretchSame)) { @@ -263,7 +261,7 @@ void Editor::DrawProjectEditor() { ImGui::TableNextColumn(); ImGui::Text("Title: %s", rom_.getTitle()); ImGui::Text("Version: %d", rom_.getVersion()); - ImGui::Text("ROM Size: %u", rom_.getSize()); + ImGui::Text("ROM Size: %ld", rom_.getSize()); ImGui::InputInt("PC Tile Location", ¤t_set_.pcTilesLocation); // 1, 100, ImGuiInputTextFlags_CharsHexadecimal diff --git a/src/Application/Editor/overworld_editor.h b/src/Application/Editor/overworld_editor.h index efb9996a..f77c92c5 100644 --- a/src/Application/Editor/overworld_editor.h +++ b/src/Application/Editor/overworld_editor.h @@ -13,8 +13,6 @@ namespace yaze { namespace Application { namespace Editor { -using byte = unsigned char; - static constexpr unsigned int k4BPP = 4; class OverworldEditor { @@ -45,7 +43,7 @@ class OverworldEditor { int allgfx_width = 0; int allgfx_height = 0; - byte *allGfx16Ptr = new byte[(128 * 7136) / 2]; + uchar *allGfx16Ptr = new uchar[(128 * 7136) / 2]; ImGuiTableFlags toolset_table_flags = ImGuiTableFlags_SizingFixedFit; ImGuiTableFlags ow_map_settings_flags = ImGuiTableFlags_Borders; diff --git a/src/Application/Graphics/palette.cc b/src/Application/Graphics/palette.cc index 5ecc3e62..eefb5e9e 100644 --- a/src/Application/Graphics/palette.cc +++ b/src/Application/Graphics/palette.cc @@ -1,4 +1,4 @@ -#include "Palette.h" +#include "palette.h" #include #include @@ -7,17 +7,13 @@ namespace yaze { namespace Application { namespace Graphics { -SNESColor::SNESColor() { - rgb = ImVec4(0.f, 0.f, 0.f, 0.f); - snes = 0; -} +SNESColor::SNESColor() : rgb(ImVec4(0.f, 0.f, 0.f, 0.f)) {} -SNESColor::SNESColor(ImVec4 val) { - rgb = val; +SNESColor::SNESColor(ImVec4 val) : rgb(val) { m_color col; - col.red = val.x; - col.blue = val.y; - col.green = val.z; + col.red = (uchar)val.x; + col.blue = (uchar)val.y; + col.green = (uchar)val.z; snes = convertcolor_rgb_to_snes(col); } @@ -36,10 +32,7 @@ void SNESColor::setSNES(uint16_t val) { rgb = ImVec4(col.red, col.green, col.blue, 1.f); } -SNESPalette::SNESPalette() { size = 0; } - -SNESPalette::SNESPalette(uint8_t mSize) { - size = mSize; +SNESPalette::SNESPalette(uint8_t mSize) : size(mSize) { for (unsigned int i = 0; i < mSize; i++) { SNESColor col; colors.push_back(col); @@ -84,9 +77,9 @@ SDL_Palette* SNESPalette::GetSDL_Palette() { result->ncolors = size; SDL_Color* sdl_colors = new SDL_Color[size]; for (int i = 0; i < size; i++) { - sdl_colors[i].r = (uint8_t) colors[i].rgb.x * 100; - sdl_colors[i].g = (uint8_t) colors[i].rgb.y * 100; - sdl_colors[i].b = (uint8_t) colors[i].rgb.z * 100; + sdl_colors[i].r = (uint8_t)colors[i].rgb.x * 100; + sdl_colors[i].g = (uint8_t)colors[i].rgb.y * 100; + sdl_colors[i].b = (uint8_t)colors[i].rgb.z * 100; } result->colors = sdl_colors; diff --git a/src/Application/Graphics/palette.h b/src/Application/Graphics/palette.h index cd90869c..1bc37ad1 100644 --- a/src/Application/Graphics/palette.h +++ b/src/Application/Graphics/palette.h @@ -17,7 +17,7 @@ namespace Graphics { struct SNESColor { SNESColor(); explicit SNESColor(ImVec4); - uint16_t snes; + uint16_t snes = 0; ImVec4 rgb; void setRgb(ImVec4); void setSNES(uint16_t); @@ -27,7 +27,7 @@ struct SNESColor { class SNESPalette { public: - SNESPalette(); + SNESPalette()=default; explicit SNESPalette(uint8_t mSize); explicit SNESPalette(char* snesPal); explicit SNESPalette(std::vector); @@ -35,7 +35,7 @@ class SNESPalette { char* encode(); SDL_Palette* GetSDL_Palette(); - uint8_t size; + uint8_t size = 0; std::vector colors; std::vector sdl_palettes_; std::vector colors_arrays_; diff --git a/src/Application/Graphics/tile.h b/src/Application/Graphics/tile.h index e86423c8..694580f0 100644 --- a/src/Application/Graphics/tile.h +++ b/src/Application/Graphics/tile.h @@ -13,7 +13,7 @@ namespace yaze { namespace Application { namespace Graphics { -using byte = unsigned char; + using ushort = unsigned short; using uint = unsigned int; @@ -26,9 +26,9 @@ class TileInfo { ushort over_; ushort vertical_mirror_; ushort horizontal_mirror_; - byte palette_; + uchar palette_; TileInfo() {} - TileInfo(ushort id, byte palette, ushort v, ushort h, ushort o) + TileInfo(ushort id, uchar palette, ushort v, ushort h, ushort o) : id_(id), palette_(palette), vertical_mirror_(v),