From 4f71bf29574d4e8ed62e9c0fd4983a4af88847d3 Mon Sep 17 00:00:00 2001 From: scawful Date: Mon, 13 Jun 2022 20:14:59 -0400 Subject: [PATCH] housekeeping and style --- src/Application/Core/window.cc | 2 +- src/Application/Graphics/palette.cc | 12 ++-- src/Application/Graphics/palette.h | 5 +- src/Application/Graphics/scene.cc | 11 +++- src/Application/Graphics/style.cc | 12 ++-- src/Application/Graphics/style.h | 4 +- src/Application/Graphics/tile.cc | 92 ++++++++++++++--------------- src/Application/Graphics/tile.h | 23 ++++---- 8 files changed, 85 insertions(+), 76 deletions(-) diff --git a/src/Application/Core/window.cc b/src/Application/Core/window.cc index 73e68dbc..b2815876 100644 --- a/src/Application/Core/window.cc +++ b/src/Application/Core/window.cc @@ -1,4 +1,4 @@ -#include "Window.h" +#include "window.h" #include diff --git a/src/Application/Graphics/palette.cc b/src/Application/Graphics/palette.cc index eefb5e9e..df7a9cc7 100644 --- a/src/Application/Graphics/palette.cc +++ b/src/Application/Graphics/palette.cc @@ -53,12 +53,12 @@ SNESPalette::SNESPalette(char* data) { } SNESPalette::SNESPalette(std::vector cols) { - // foreach (ImVec4 col, cols) { - // SNESColor scol; - // scol.setRgb(col); - // colors.push_back(scol); - // } - // size = cols.size(); + for (const auto& each : cols) { + SNESColor scol; + scol.setRgb(each); + colors.push_back(scol); + } + size = cols.size(); } char* SNESPalette::encode() { diff --git a/src/Application/Graphics/palette.h b/src/Application/Graphics/palette.h index 1bc37ad1..98eac546 100644 --- a/src/Application/Graphics/palette.h +++ b/src/Application/Graphics/palette.h @@ -8,6 +8,7 @@ #include #include +#include #include namespace yaze { @@ -27,7 +28,7 @@ struct SNESColor { class SNESPalette { public: - SNESPalette()=default; + SNESPalette() = default; explicit SNESPalette(uint8_t mSize); explicit SNESPalette(char* snesPal); explicit SNESPalette(std::vector); @@ -35,7 +36,7 @@ class SNESPalette { char* encode(); SDL_Palette* GetSDL_Palette(); - uint8_t size = 0; + int size = 0; std::vector colors; std::vector sdl_palettes_; std::vector colors_arrays_; diff --git a/src/Application/Graphics/scene.cc b/src/Application/Graphics/scene.cc index 30013438..3f31dc55 100644 --- a/src/Application/Graphics/scene.cc +++ b/src/Application/Graphics/scene.cc @@ -1,4 +1,13 @@ -#include "Scene.h" +#include "scene.h" + +#include +#include + +#include +#include + +#include "Core/renderer.h" +#include "Graphics/tile.h" namespace yaze { namespace Application { diff --git a/src/Application/Graphics/style.cc b/src/Application/Graphics/style.cc index c762f915..b0e16085 100644 --- a/src/Application/Graphics/style.cc +++ b/src/Application/Graphics/style.cc @@ -1,4 +1,4 @@ -#include "Style.h" +#include "style.h" #include "imgui/imgui.h" #include "imgui/imgui_internal.h" @@ -30,14 +30,14 @@ void ColorsYaze() { style->WindowRounding = 0.f; style->ChildRounding = 0.f; - style->FrameRounding = 5.4; + style->FrameRounding = 5.f; style->PopupRounding = 0.f; style->ScrollbarRounding = 5.f; - ImVec4 alttpDarkGreen = ImVec4(0.18f, 0.26f, 0.18f, 1.0f); - ImVec4 alttpMidGreen = ImVec4(0.28f, 0.36f, 0.28f, 1.0f); - ImVec4 allttpLightGreen = ImVec4(0.36f, 0.45f, 0.36f, 1.0f); - ImVec4 allttpLightestGreen = ImVec4(0.49f, 0.57f, 0.49f, 1.0f); + auto alttpDarkGreen = ImVec4(0.18f, 0.26f, 0.18f, 1.0f); + auto alttpMidGreen = ImVec4(0.28f, 0.36f, 0.28f, 1.0f); + auto allttpLightGreen = ImVec4(0.36f, 0.45f, 0.36f, 1.0f); + auto allttpLightestGreen = ImVec4(0.49f, 0.57f, 0.49f, 1.0f); colors[ImGuiCol_MenuBarBg] = alttpDarkGreen; colors[ImGuiCol_TitleBg] = alttpMidGreen; diff --git a/src/Application/Graphics/style.h b/src/Application/Graphics/style.h index f51cf116..520329d7 100644 --- a/src/Application/Graphics/style.h +++ b/src/Application/Graphics/style.h @@ -1,8 +1,8 @@ #ifndef YAZE_APPLICATION_CORE_STYLE_H #define YAZE_APPLICATION_CORE_STYLE_H -#include "imgui/imgui.h" -#include "imgui/imgui_internal.h" +#include +#include namespace yaze { namespace Application { diff --git a/src/Application/Graphics/tile.cc b/src/Application/Graphics/tile.cc index 4f4a7bcf..e108c92a 100644 --- a/src/Application/Graphics/tile.cc +++ b/src/Application/Graphics/tile.cc @@ -1,6 +1,7 @@ -#include "Tile.h" +#include "tile.h" #include +#include #include #include #include @@ -12,15 +13,15 @@ namespace Application { namespace Graphics { TilesPattern::TilesPattern() { - tilesPerRow = 16; - numberOfTiles = 16; + tiles_per_row_ = 16; + number_of_tiles_ = 16; // std::vector{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 9, 11, 12, 13, 14, 15, // 16}); - transformVector.push_back(std::vector{0, 1, 2, 3}); - transformVector.push_back(std::vector{4, 5, 6, 7}); - transformVector.push_back(std::vector{8, 9, 11, 12}); - transformVector.push_back(std::vector{13, 14, 15, 16}); + transform_vector_.push_back(std::vector{0, 1, 2, 3}); + transform_vector_.push_back(std::vector{4, 5, 6, 7}); + transform_vector_.push_back(std::vector{8, 9, 11, 12}); + transform_vector_.push_back(std::vector{13, 14, 15, 16}); } // [pattern] @@ -28,11 +29,11 @@ TilesPattern::TilesPattern() { // number_of_tile = 16 // pattern = void TilesPattern::default_settings() { - numberOfTiles = 16; + number_of_tiles_ = 16; std::string patternString = "[0, 1, 2, 3], [4, 5, 6, 7], [8, 9, A, B], [C, D, E, F]"; - transformVector.clear(); + transform_vector_.clear(); std::smatch cm; std::regex arrayRegExp("(\\[[\\s|0-F|a-f|,]+\\])"); @@ -41,7 +42,7 @@ void TilesPattern::default_settings() { while (std::regex_search(patternString, cm, arrayRegExp)) { std::string arrayString = cm[1]; std::vector tmpVect; - unsigned int stringPos = 1; + uint stringPos = 1; while (arrayString[stringPos] != ']') { while (arrayString[stringPos] == ' ') stringPos++; @@ -59,48 +60,47 @@ void TilesPattern::default_settings() { } pos += cm.size(); - transformVector.push_back(tmpVect); + transform_vector_.push_back(tmpVect); } - std::cout << transformVector.size() << std::endl; + std::cout << transform_vector_.size() << std::endl; } std::vector > TilesPattern::transform( const std::vector &tiles) const { - unsigned int repeatOffsetY = 0; - unsigned int repeatOffsetX = 0; - unsigned int tVectHeight = transformVector.size(); - unsigned int tVectWidth = transformVector[0].size(); - unsigned int repeat = 0; + uint repeatOffsetY = 0; + uint repeatOffsetX = 0; + uint tVectHeight = transform_vector_.size(); + uint tVectWidth = transform_vector_[0].size(); + uint repeat = 0; std::vector > toret; - unsigned int transPerRow = tilesPerRow / tVectWidth; - unsigned int nbTransform = tiles.size() / numberOfTiles; + uint transPerRow = tiles_per_row_ / tVectWidth; + uint nbTransform = tiles.size() / number_of_tiles_; printf("Tiles size : %d\nnbtransform : %d\npattern number of tiles : %d\n", - tiles.size(), nbTransform, numberOfTiles); + tiles.size(), nbTransform, number_of_tiles_); if (transPerRow > nbTransform) toret.resize(tVectHeight); else - toret.resize( - ((unsigned int)(((double)nbTransform / (double)transPerRow) + 0.5)) * - tVectHeight); + toret.resize(((uint)(((double)nbTransform / (double)transPerRow) + 0.5)) * + tVectHeight); for (auto &each : toret) { - each.resize(tilesPerRow); + each.resize(tiles_per_row_); } std::cout << toret[0].size() << " x " << toret.size(); while (repeat != nbTransform) { std::cout << "repeat" << repeat; - for (unsigned int j = 0; j < tVectHeight; j++) { - for (unsigned int i = 0; i < tVectWidth; i++) { - unsigned int posTile = transformVector[j][i] + numberOfTiles * repeat; - unsigned int posX = i + repeatOffsetX; - unsigned int posY = j + repeatOffsetY; + for (uint j = 0; j < tVectHeight; j++) { + for (uint i = 0; i < tVectWidth; i++) { + uint posTile = transform_vector_[j][i] + number_of_tiles_ * repeat; + uint posX = i + repeatOffsetX; + uint posY = j + repeatOffsetY; printf("X: %d - Y: %d - posTile : %d", posX, posY, posTile); toret.at(posY).at(posX) = tiles[posTile]; } } - if (repeatOffsetX + tVectWidth == tilesPerRow) { + if (repeatOffsetX + tVectWidth == tiles_per_row_) { repeatOffsetX = 0; repeatOffsetY += tVectHeight; } else @@ -113,27 +113,27 @@ std::vector > TilesPattern::transform( std::vector TilesPattern::reverse( const std::vector &tiles) const { - unsigned int repeatOffsetY = 0; - unsigned int repeatOffsetX = 0; - unsigned int tVectHeight = transformVector.size(); - unsigned int tVectWidth = transformVector[0].size(); - unsigned int repeat = 0; - unsigned int nbTransPerRow = tilesPerRow / tVectWidth; - unsigned int nbTiles = tiles.size(); + uint repeatOffsetY = 0; + uint repeatOffsetX = 0; + uint tVectHeight = transform_vector_.size(); + uint tVectWidth = transform_vector_[0].size(); + uint repeat = 0; + uint nbTransPerRow = tiles_per_row_ / tVectWidth; + uint nbTiles = tiles.size(); std::vector toretVec(tiles.size()); - for (unsigned int i = 0; i < nbTiles; i++) { - unsigned int lineNb = i / tilesPerRow; - unsigned int lineInTab = lineNb % tVectHeight; - unsigned int colInTab = i % tVectWidth; - unsigned int tileNb = transformVector[lineInTab][colInTab]; + for (uint i = 0; i < nbTiles; i++) { + uint lineNb = i / tiles_per_row_; + uint lineInTab = lineNb % tVectHeight; + uint colInTab = i % tVectWidth; + uint tileNb = transform_vector_[lineInTab][colInTab]; - unsigned int lineBlock = i / (nbTransPerRow * numberOfTiles); - unsigned int blockNB = - (i % (nbTransPerRow * numberOfTiles) % tilesPerRow) / tVectWidth; + uint lineBlock = i / (nbTransPerRow * number_of_tiles_); + uint blockNB = + (i % (nbTransPerRow * number_of_tiles_) % tiles_per_row_) / tVectWidth; std::cout << colInTab << lineInTab << " = " << tileNb; - unsigned int pos = tileNb + (lineBlock + blockNB) * numberOfTiles; + uint pos = tileNb + (lineBlock + blockNB) * number_of_tiles_; std::cout << i << "Goes to : " << pos; toretVec[pos] = tiles[i]; } diff --git a/src/Application/Graphics/tile.h b/src/Application/Graphics/tile.h index 694580f0..30fdafc2 100644 --- a/src/Application/Graphics/tile.h +++ b/src/Application/Graphics/tile.h @@ -3,6 +3,7 @@ #include +#include #include #include #include @@ -13,10 +14,6 @@ namespace yaze { namespace Application { namespace Graphics { - -using ushort = unsigned short; -using uint = unsigned int; - // vhopppcc cccccccc // [0, 1] // [2, 3] @@ -27,13 +24,13 @@ class TileInfo { ushort vertical_mirror_; ushort horizontal_mirror_; uchar palette_; - TileInfo() {} + TileInfo() = default; TileInfo(ushort id, uchar palette, ushort v, ushort h, ushort o) : id_(id), - palette_(palette), + over_(o), vertical_mirror_(v), horizontal_mirror_(h), - over_(o) {} + palette_(palette) {} }; class Tile32 { @@ -70,20 +67,22 @@ class TilesPattern { std::string name; std::string description; bool custom; - unsigned int tilesPerRow; - unsigned int numberOfTiles; + unsigned int tiles_per_row_; + unsigned int number_of_tiles_; void default_settings(); static TilesPattern pattern(std::string name); - static std::vector > transform( + static std::vector> transform( const TilesPattern& pattern, const std::vector& tiles); protected: - std::vector > transform( + std::vector> transform( const std::vector& tiles) const; std::vector reverse(const std::vector& tiles) const; - std::vector > transformVector; + + private: + std::vector> transform_vector_; }; class TilePreset {