type cleaning and housekeeping

This commit is contained in:
scawful
2022-06-13 18:43:19 -04:00
parent da7a202130
commit 32d19edbfc
12 changed files with 92 additions and 106 deletions

View File

@@ -16,7 +16,7 @@
ImGui::EndMenuBar(); \
}
using byte = unsigned char;
namespace yaze {
namespace Application {

View File

@@ -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;
}
}

View File

@@ -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)

View File

@@ -12,7 +12,7 @@ using namespace Graphics;
OverworldMap::OverworldMap(Data::ROM rom,
const std::vector<Graphics::Tile16> 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:

View File

@@ -1,5 +1,6 @@
#include <imgui/imgui.h>
#include <cstddef>
#include <memory>
#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<Graphics::Tile16> tiles16_;
OverworldMap(Data::ROM rom, const std::vector<Graphics::Tile16> 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();

View File

@@ -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;
}

View File

@@ -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<tile8> 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_;

View File

@@ -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", &current_set_.pcTilesLocation);
// 1, 100, ImGuiInputTextFlags_CharsHexadecimal

View File

@@ -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;

View File

@@ -1,4 +1,4 @@
#include "Palette.h"
#include "palette.h"
#include <cstdlib>
#include <cstring>
@@ -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;

View File

@@ -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<ImVec4>);
@@ -35,7 +35,7 @@ class SNESPalette {
char* encode();
SDL_Palette* GetSDL_Palette();
uint8_t size;
uint8_t size = 0;
std::vector<SNESColor> colors;
std::vector<SDL_Palette*> sdl_palettes_;
std::vector<SDL_Color*> colors_arrays_;

View File

@@ -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),