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>

View File

@@ -53,12 +53,12 @@ SNESPalette::SNESPalette(char* data) {
}
SNESPalette::SNESPalette(std::vector<ImVec4> 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() {

View File

@@ -8,6 +8,7 @@
#include <cstdint>
#include <iostream>
#include <memory>
#include <vector>
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<ImVec4>);
@@ -35,7 +36,7 @@ class SNESPalette {
char* encode();
SDL_Palette* GetSDL_Palette();
uint8_t size = 0;
int size = 0;
std::vector<SNESColor> colors;
std::vector<SDL_Palette*> sdl_palettes_;
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 Application {

View File

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

View File

@@ -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 <imgui/imgui.h>
#include <imgui/imgui_internal.h>
namespace yaze {
namespace Application {

View File

@@ -1,6 +1,7 @@
#include "Tile.h"
#include "tile.h"
#include <cassert>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
@@ -12,15 +13,15 @@ namespace Application {
namespace Graphics {
TilesPattern::TilesPattern() {
tilesPerRow = 16;
numberOfTiles = 16;
tiles_per_row_ = 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,
// 16});
transformVector.push_back(std::vector<int>{0, 1, 2, 3});
transformVector.push_back(std::vector<int>{4, 5, 6, 7});
transformVector.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>{0, 1, 2, 3});
transform_vector_.push_back(std::vector<int>{4, 5, 6, 7});
transform_vector_.push_back(std::vector<int>{8, 9, 11, 12});
transform_vector_.push_back(std::vector<int>{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<int> 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<std::vector<tile8> > TilesPattern::transform(
const std::vector<tile8> &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<std::vector<tile8> > 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<std::vector<tile8> > TilesPattern::transform(
std::vector<tile8> TilesPattern::reverse(
const std::vector<tile8> &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<tile8> 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];
}

View File

@@ -3,6 +3,7 @@
#include <tile.h>
#include <cstdint>
#include <string>
#include <unordered_map>
#include <vector>
@@ -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<std::vector<tile8> > transform(
static std::vector<std::vector<tile8>> transform(
const TilesPattern& pattern, const std::vector<tile8>& tiles);
protected:
std::vector<std::vector<tile8> > transform(
std::vector<std::vector<tile8>> transform(
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 {