housekeeping and style

This commit is contained in:
scawful
2022-06-13 20:14:59 -04:00
parent 32d19edbfc
commit 4f71bf2957
8 changed files with 85 additions and 76 deletions

View File

@@ -1,4 +1,4 @@
#include "Window.h" #include "window.h"
#include <SDL2/SDL.h> #include <SDL2/SDL.h>

View File

@@ -53,12 +53,12 @@ SNESPalette::SNESPalette(char* data) {
} }
SNESPalette::SNESPalette(std::vector<ImVec4> cols) { SNESPalette::SNESPalette(std::vector<ImVec4> cols) {
// foreach (ImVec4 col, cols) { for (const auto& each : cols) {
// SNESColor scol; SNESColor scol;
// scol.setRgb(col); scol.setRgb(each);
// colors.push_back(scol); colors.push_back(scol);
// } }
// size = cols.size(); size = cols.size();
} }
char* SNESPalette::encode() { char* SNESPalette::encode() {

View File

@@ -8,6 +8,7 @@
#include <cstdint> #include <cstdint>
#include <iostream> #include <iostream>
#include <memory>
#include <vector> #include <vector>
namespace yaze { namespace yaze {
@@ -27,7 +28,7 @@ struct SNESColor {
class SNESPalette { class SNESPalette {
public: public:
SNESPalette()=default; SNESPalette() = default;
explicit SNESPalette(uint8_t mSize); explicit SNESPalette(uint8_t mSize);
explicit SNESPalette(char* snesPal); explicit SNESPalette(char* snesPal);
explicit SNESPalette(std::vector<ImVec4>); explicit SNESPalette(std::vector<ImVec4>);
@@ -35,7 +36,7 @@ class SNESPalette {
char* encode(); char* encode();
SDL_Palette* GetSDL_Palette(); SDL_Palette* GetSDL_Palette();
uint8_t size = 0; int size = 0;
std::vector<SNESColor> colors; std::vector<SNESColor> colors;
std::vector<SDL_Palette*> sdl_palettes_; std::vector<SDL_Palette*> sdl_palettes_;
std::vector<SDL_Color*> colors_arrays_; std::vector<SDL_Color*> colors_arrays_;

View File

@@ -1,4 +1,13 @@
#include "Scene.h" #include "scene.h"
#include <SDL2/SDL.h>
#include <tile.h>
#include <iostream>
#include <vector>
#include "Core/renderer.h"
#include "Graphics/tile.h"
namespace yaze { namespace yaze {
namespace Application { namespace Application {

View File

@@ -1,4 +1,4 @@
#include "Style.h" #include "style.h"
#include "imgui/imgui.h" #include "imgui/imgui.h"
#include "imgui/imgui_internal.h" #include "imgui/imgui_internal.h"
@@ -30,14 +30,14 @@ void ColorsYaze() {
style->WindowRounding = 0.f; style->WindowRounding = 0.f;
style->ChildRounding = 0.f; style->ChildRounding = 0.f;
style->FrameRounding = 5.4; style->FrameRounding = 5.f;
style->PopupRounding = 0.f; style->PopupRounding = 0.f;
style->ScrollbarRounding = 5.f; style->ScrollbarRounding = 5.f;
ImVec4 alttpDarkGreen = ImVec4(0.18f, 0.26f, 0.18f, 1.0f); auto alttpDarkGreen = ImVec4(0.18f, 0.26f, 0.18f, 1.0f);
ImVec4 alttpMidGreen = ImVec4(0.28f, 0.36f, 0.28f, 1.0f); auto alttpMidGreen = ImVec4(0.28f, 0.36f, 0.28f, 1.0f);
ImVec4 allttpLightGreen = ImVec4(0.36f, 0.45f, 0.36f, 1.0f); auto allttpLightGreen = ImVec4(0.36f, 0.45f, 0.36f, 1.0f);
ImVec4 allttpLightestGreen = ImVec4(0.49f, 0.57f, 0.49f, 1.0f); auto allttpLightestGreen = ImVec4(0.49f, 0.57f, 0.49f, 1.0f);
colors[ImGuiCol_MenuBarBg] = alttpDarkGreen; colors[ImGuiCol_MenuBarBg] = alttpDarkGreen;
colors[ImGuiCol_TitleBg] = alttpMidGreen; colors[ImGuiCol_TitleBg] = alttpMidGreen;

View File

@@ -1,8 +1,8 @@
#ifndef YAZE_APPLICATION_CORE_STYLE_H #ifndef YAZE_APPLICATION_CORE_STYLE_H
#define YAZE_APPLICATION_CORE_STYLE_H #define YAZE_APPLICATION_CORE_STYLE_H
#include "imgui/imgui.h" #include <imgui/imgui.h>
#include "imgui/imgui_internal.h" #include <imgui/imgui_internal.h>
namespace yaze { namespace yaze {
namespace Application { namespace Application {

View File

@@ -1,6 +1,7 @@
#include "Tile.h" #include "tile.h"
#include <cassert> #include <cassert>
#include <cstdint>
#include <cstdio> #include <cstdio>
#include <cstdlib> #include <cstdlib>
#include <cstring> #include <cstring>
@@ -12,15 +13,15 @@ namespace Application {
namespace Graphics { namespace Graphics {
TilesPattern::TilesPattern() { TilesPattern::TilesPattern() {
tilesPerRow = 16; tiles_per_row_ = 16;
numberOfTiles = 16; number_of_tiles_ = 16;
// std::vector<int>{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 9, 11, 12, 13, 14, 15, // std::vector<int>{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 9, 11, 12, 13, 14, 15,
// 16}); // 16});
transformVector.push_back(std::vector<int>{0, 1, 2, 3}); transform_vector_.push_back(std::vector<int>{0, 1, 2, 3});
transformVector.push_back(std::vector<int>{4, 5, 6, 7}); transform_vector_.push_back(std::vector<int>{4, 5, 6, 7});
transformVector.push_back(std::vector<int>{8, 9, 11, 12}); transform_vector_.push_back(std::vector<int>{8, 9, 11, 12});
transformVector.push_back(std::vector<int>{13, 14, 15, 16}); transform_vector_.push_back(std::vector<int>{13, 14, 15, 16});
} }
// [pattern] // [pattern]
@@ -28,11 +29,11 @@ TilesPattern::TilesPattern() {
// number_of_tile = 16 // number_of_tile = 16
// pattern = // pattern =
void TilesPattern::default_settings() { void TilesPattern::default_settings() {
numberOfTiles = 16; number_of_tiles_ = 16;
std::string patternString = std::string patternString =
"[0, 1, 2, 3], [4, 5, 6, 7], [8, 9, A, B], [C, D, E, F]"; "[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::smatch cm;
std::regex arrayRegExp("(\\[[\\s|0-F|a-f|,]+\\])"); std::regex arrayRegExp("(\\[[\\s|0-F|a-f|,]+\\])");
@@ -41,7 +42,7 @@ void TilesPattern::default_settings() {
while (std::regex_search(patternString, cm, arrayRegExp)) { while (std::regex_search(patternString, cm, arrayRegExp)) {
std::string arrayString = cm[1]; std::string arrayString = cm[1];
std::vector<int> tmpVect; std::vector<int> tmpVect;
unsigned int stringPos = 1; uint stringPos = 1;
while (arrayString[stringPos] != ']') { while (arrayString[stringPos] != ']') {
while (arrayString[stringPos] == ' ') stringPos++; while (arrayString[stringPos] == ' ') stringPos++;
@@ -59,48 +60,47 @@ void TilesPattern::default_settings() {
} }
pos += cm.size(); 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<std::vector<tile8> > TilesPattern::transform( std::vector<std::vector<tile8> > TilesPattern::transform(
const std::vector<tile8> &tiles) const { const std::vector<tile8> &tiles) const {
unsigned int repeatOffsetY = 0; uint repeatOffsetY = 0;
unsigned int repeatOffsetX = 0; uint repeatOffsetX = 0;
unsigned int tVectHeight = transformVector.size(); uint tVectHeight = transform_vector_.size();
unsigned int tVectWidth = transformVector[0].size(); uint tVectWidth = transform_vector_[0].size();
unsigned int repeat = 0; uint repeat = 0;
std::vector<std::vector<tile8> > toret; std::vector<std::vector<tile8> > toret;
unsigned int transPerRow = tilesPerRow / tVectWidth; uint transPerRow = tiles_per_row_ / tVectWidth;
unsigned int nbTransform = tiles.size() / numberOfTiles; uint nbTransform = tiles.size() / number_of_tiles_;
printf("Tiles size : %d\nnbtransform : %d\npattern number of tiles : %d\n", 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) if (transPerRow > nbTransform)
toret.resize(tVectHeight); toret.resize(tVectHeight);
else else
toret.resize( toret.resize(((uint)(((double)nbTransform / (double)transPerRow) + 0.5)) *
((unsigned int)(((double)nbTransform / (double)transPerRow) + 0.5)) * tVectHeight);
tVectHeight);
for (auto &each : toret) { for (auto &each : toret) {
each.resize(tilesPerRow); each.resize(tiles_per_row_);
} }
std::cout << toret[0].size() << " x " << toret.size(); std::cout << toret[0].size() << " x " << toret.size();
while (repeat != nbTransform) { while (repeat != nbTransform) {
std::cout << "repeat" << repeat; std::cout << "repeat" << repeat;
for (unsigned int j = 0; j < tVectHeight; j++) { for (uint j = 0; j < tVectHeight; j++) {
for (unsigned int i = 0; i < tVectWidth; i++) { for (uint i = 0; i < tVectWidth; i++) {
unsigned int posTile = transformVector[j][i] + numberOfTiles * repeat; uint posTile = transform_vector_[j][i] + number_of_tiles_ * repeat;
unsigned int posX = i + repeatOffsetX; uint posX = i + repeatOffsetX;
unsigned int posY = j + repeatOffsetY; uint posY = j + repeatOffsetY;
printf("X: %d - Y: %d - posTile : %d", posX, posY, posTile); printf("X: %d - Y: %d - posTile : %d", posX, posY, posTile);
toret.at(posY).at(posX) = tiles[posTile]; toret.at(posY).at(posX) = tiles[posTile];
} }
} }
if (repeatOffsetX + tVectWidth == tilesPerRow) { if (repeatOffsetX + tVectWidth == tiles_per_row_) {
repeatOffsetX = 0; repeatOffsetX = 0;
repeatOffsetY += tVectHeight; repeatOffsetY += tVectHeight;
} else } else
@@ -113,27 +113,27 @@ std::vector<std::vector<tile8> > TilesPattern::transform(
std::vector<tile8> TilesPattern::reverse( std::vector<tile8> TilesPattern::reverse(
const std::vector<tile8> &tiles) const { const std::vector<tile8> &tiles) const {
unsigned int repeatOffsetY = 0; uint repeatOffsetY = 0;
unsigned int repeatOffsetX = 0; uint repeatOffsetX = 0;
unsigned int tVectHeight = transformVector.size(); uint tVectHeight = transform_vector_.size();
unsigned int tVectWidth = transformVector[0].size(); uint tVectWidth = transform_vector_[0].size();
unsigned int repeat = 0; uint repeat = 0;
unsigned int nbTransPerRow = tilesPerRow / tVectWidth; uint nbTransPerRow = tiles_per_row_ / tVectWidth;
unsigned int nbTiles = tiles.size(); uint nbTiles = tiles.size();
std::vector<tile8> toretVec(tiles.size()); std::vector<tile8> toretVec(tiles.size());
for (unsigned int i = 0; i < nbTiles; i++) { for (uint i = 0; i < nbTiles; i++) {
unsigned int lineNb = i / tilesPerRow; uint lineNb = i / tiles_per_row_;
unsigned int lineInTab = lineNb % tVectHeight; uint lineInTab = lineNb % tVectHeight;
unsigned int colInTab = i % tVectWidth; uint colInTab = i % tVectWidth;
unsigned int tileNb = transformVector[lineInTab][colInTab]; uint tileNb = transform_vector_[lineInTab][colInTab];
unsigned int lineBlock = i / (nbTransPerRow * numberOfTiles); uint lineBlock = i / (nbTransPerRow * number_of_tiles_);
unsigned int blockNB = uint blockNB =
(i % (nbTransPerRow * numberOfTiles) % tilesPerRow) / tVectWidth; (i % (nbTransPerRow * number_of_tiles_) % tiles_per_row_) / tVectWidth;
std::cout << colInTab << lineInTab << " = " << tileNb; 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; std::cout << i << "Goes to : " << pos;
toretVec[pos] = tiles[i]; toretVec[pos] = tiles[i];
} }

View File

@@ -3,6 +3,7 @@
#include <tile.h> #include <tile.h>
#include <cstdint>
#include <string> #include <string>
#include <unordered_map> #include <unordered_map>
#include <vector> #include <vector>
@@ -13,10 +14,6 @@ namespace yaze {
namespace Application { namespace Application {
namespace Graphics { namespace Graphics {
using ushort = unsigned short;
using uint = unsigned int;
// vhopppcc cccccccc // vhopppcc cccccccc
// [0, 1] // [0, 1]
// [2, 3] // [2, 3]
@@ -27,13 +24,13 @@ class TileInfo {
ushort vertical_mirror_; ushort vertical_mirror_;
ushort horizontal_mirror_; ushort horizontal_mirror_;
uchar palette_; uchar palette_;
TileInfo() {} TileInfo() = default;
TileInfo(ushort id, uchar palette, ushort v, ushort h, ushort o) TileInfo(ushort id, uchar palette, ushort v, ushort h, ushort o)
: id_(id), : id_(id),
palette_(palette), over_(o),
vertical_mirror_(v), vertical_mirror_(v),
horizontal_mirror_(h), horizontal_mirror_(h),
over_(o) {} palette_(palette) {}
}; };
class Tile32 { class Tile32 {
@@ -70,20 +67,22 @@ class TilesPattern {
std::string name; std::string name;
std::string description; std::string description;
bool custom; bool custom;
unsigned int tilesPerRow; unsigned int tiles_per_row_;
unsigned int numberOfTiles; unsigned int number_of_tiles_;
void default_settings(); void default_settings();
static TilesPattern pattern(std::string name); static TilesPattern pattern(std::string name);
static std::vector<std::vector<tile8> > transform( static std::vector<std::vector<tile8>> transform(
const TilesPattern& pattern, const std::vector<tile8>& tiles); const TilesPattern& pattern, const std::vector<tile8>& tiles);
protected: protected:
std::vector<std::vector<tile8> > transform( std::vector<std::vector<tile8>> transform(
const std::vector<tile8>& tiles) const; const std::vector<tile8>& tiles) const;
std::vector<tile8> reverse(const std::vector<tile8>& tiles) const; std::vector<tile8> reverse(const std::vector<tile8>& tiles) const;
std::vector<std::vector<int> > transformVector;
private:
std::vector<std::vector<int>> transform_vector_;
}; };
class TilePreset { class TilePreset {