Continuing the Graphics stuff and removed Events bc im not using it

This commit is contained in:
Justin Scofield
2022-06-12 12:42:35 -04:00
parent bbe95ef332
commit 9b905a48e4
17 changed files with 328 additions and 231 deletions

View File

@@ -12,6 +12,15 @@ SNESColor::SNESColor() {
snes = 0;
}
SNESColor::SNESColor(ImVec4 val) {
rgb = val;
m_color col;
col.red = val.x;
col.blue = val.y;
col.green = val.z;
snes = convertcolor_rgb_to_snes(col);
}
void SNESColor::setRgb(ImVec4 val) {
rgb = val;
m_color col;
@@ -38,8 +47,8 @@ SNESPalette::SNESPalette(uint8_t mSize) {
}
SNESPalette::SNESPalette(char* data) {
//assert((data.size() % 4 == 0) && data.size() <= 32);
//size = data.size() / 2;
// assert((data.size() % 4 == 0) && data.size() <= 32);
// size = data.size() / 2;
size = sizeof(data) / 2;
for (unsigned i = 0; i < sizeof(data); i += 2) {
SNESColor col;
@@ -61,16 +70,34 @@ SNESPalette::SNESPalette(std::vector<ImVec4> cols) {
}
char* SNESPalette::encode() {
//char* data(size * 2, 0);
// char* data(size * 2, 0);
char* data = new char[size * 2];
for (unsigned int i = 0; i < size; i++) {
//std::cout << QString::number(colors[i].snes, 16);
// std::cout << QString::number(colors[i].snes, 16);
data[i * 2] = (char)(colors[i].snes & 0xFF);
data[i * 2 + 1] = (char)(colors[i].snes >> 8);
}
return data;
}
SDL_Palette* SNESPalette::GetSDL_Palette() {
SDL_Palette* result = new SDL_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;
}
result->colors = sdl_colors;
// store the pointers to free them later
sdl_palettes_.push_back(result);
colors_arrays_.push_back(sdl_colors);
return result;
}
} // namespace Graphics
} // namespace Application
} // namespace yaze

View File

@@ -1,6 +1,7 @@
#ifndef YAZE_APPLICATION_GRAPHICS_PALETTE_H
#define YAZE_APPLICATION_GRAPHICS_PALETTE_H
#include <SDL2/SDL.h>
#include <imgui/imgui.h>
#include <palette.h>
#include <tile.h>
@@ -9,12 +10,14 @@
#include <iostream>
#include <vector>
namespace yaze {
namespace Application {
namespace Graphics {
struct SNESColor {
SNESColor();
SNESColor(ImVec4);
uint16_t snes;
ImVec4 rgb;
void setRgb(ImVec4);
@@ -31,8 +34,13 @@ class SNESPalette {
SNESPalette(std::vector<ImVec4>);
char* encode();
SDL_Palette* GetSDL_Palette();
uint8_t size;
std::vector<SNESColor> colors;
std::vector<SDL_Palette*> sdl_palettes_;
std::vector<SDL_Color*> colors_arrays_;
};
} // namespace Graphics

View File

@@ -4,6 +4,37 @@ namespace yaze {
namespace Application {
namespace Graphics {
void Scene::buildSurface(const std::vector<tile8>& tiles, SNESPalette& mPalette,
const TilesPattern& tp) {
arrangedTiles = TilesPattern::transform(tp, tiles);
tilesPattern = tp;
allTiles = tiles;
for (unsigned int j = 0; j < arrangedTiles.size(); j++) {
for (unsigned int i = 0; i < arrangedTiles[0].size(); i++) {
tile8 tile = arrangedTiles[j][i];
// SDL_PIXELFORMAT_RGB888 ?
SDL_Surface* newImage = SDL_CreateRGBSurfaceWithFormat(
0, 8, 8, SDL_BITSPERPIXEL(3), SDL_PIXELFORMAT_RGB444);
SDL_PixelFormat* format = newImage->format;
format->palette = mPalette.GetSDL_Palette();
char* ptr = (char*)newImage->pixels;
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 8; j++) {
ptr[i * 8 + j] = (char)tile.data[i * 8 + j];
}
}
SDL_Texture* texture =
SDL_CreateTextureFromSurface(Core::renderer, newImage);
imagesCache[tile.id] = texture;
}
}
}
void Scene::buildScene(const std::vector<tile8>& tiles,
const SNESPalette mPalette, const TilesPattern& tp) {
arrangedTiles = TilesPattern::transform(tp, tiles);
@@ -31,30 +62,10 @@ void Scene::buildScene(const std::vector<tile8>& tiles,
// j * newTileItem->boundingRect().width() + j);
}
}
// unsigned max_w =
// items()[0]->boundingRect().width() * arrangedTiles[0].size() +
// arrangedTiles[0].size();
// unsigned max_h = items()[0]->boundingRect().width() * arrangedTiles.size()
// +
// arrangedTiles.size();
// setSceneRect(QRect(0, 0, max_w, max_h));
}
SDL_Surface* Scene::buildSurface(const std::vector<tile8>& tiles,
const SNESPalette mPalette,
const TilesPattern& tp) {
SDL_Surface *surface = SDL_CreateRGBSurfaceWithFormat(0, 128, 7104, SDL_BITSPERPIXEL(4), SDL_PIXELFORMAT_RGB444);
arrangedTiles = TilesPattern::transform(tp, tiles);
tilesPattern = tp;
allTiles = tiles;
for (unsigned int j = 0; j < arrangedTiles.size(); j++) {
for (unsigned int i = 0; i < arrangedTiles[0].size(); i++) {
tile8 tile = arrangedTiles[j][i];
}
}
// unsigned max_w = items()[0]->boundingRect().width() *
// arrangedTiles[0].size() + arrangedTiles[0].size(); unsigned max_h =
// items()[0]->boundingRect().width() * arrangedTiles.size() +
// arrangedTiles.size(); setSceneRect(QRect(0, 0, max_w, max_h));
}
void Scene::updateScene() {

View File

@@ -10,7 +10,6 @@
#include "Core/Renderer.h"
#include "Graphics/Tile.h"
namespace yaze {
namespace Application {
namespace Graphics {
@@ -21,19 +20,21 @@ class Scene {
void buildScene(const std::vector<tile8>& tiles, const SNESPalette mPalette,
const TilesPattern& tp);
SDL_Surface* buildSurface(const std::vector<tile8>& tiles,
const SNESPalette mPalette, const TilesPattern& tp);
void buildSurface(const std::vector<tile8>& tiles,
SNESPalette& mPalette, const TilesPattern& tp);
void updateScene();
void setTilesZoom(unsigned int tileZoom);
void setTilesPattern(TilesPattern tp);
std::unordered_map<unsigned int, SDL_Texture*> imagesCache;
private:
std::vector<tile8> allTiles;
std::vector<std::vector<tile8> > arrangedTiles;
unsigned int tilesZoom;
TilesPattern tilesPattern;
// QMap<unsigned int, QPixmap> imagesCache;
std::vector<tile8> allTiles;
std::vector<std::vector<tile8> > arrangedTiles;
};
} // namespace Graphics

View File

@@ -46,13 +46,13 @@ char *hexString(const char *str, const unsigned int size) {
TilesPattern::TilesPattern() {
tilesPerRow = 16;
numberOfTiles = 16;
transformVector.push_back(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, 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});
// default_settings();
}
// [pattern]
// name = "32x32 B (4x4)"
@@ -97,43 +97,43 @@ void TilesPattern::default_settings() {
std::cout << transformVector.size() << std::endl;
}
bool TilesPattern::load(std::string patternFile) {
// QSettings pFile(patternFile, QSettings::IniFormat);
// name = pFile.value("pattern/name").toString();
// description = pFile.value("pattern/description").toString();
// numberOfTiles = pFile.value("pattern/number_of_tile").toInt();
// std::cout << name;
// // unsigned int nbOfTile = pFile.value("_/number_of_tile").toUInt();
// std::string patternString = pFile.value("pattern/pattern").toString();
// std::cout << patternString;
// bool TilesPattern::load(std::string patternFile) {
// QSettings pFile(patternFile, QSettings::IniFormat);
// name = pFile.value("pattern/name").toString();
// description = pFile.value("pattern/description").toString();
// numberOfTiles = pFile.value("pattern/number_of_tile").toInt();
// std::cout << name;
// // unsigned int nbOfTile = pFile.value("_/number_of_tile").toUInt();
// std::string patternString = pFile.value("pattern/pattern").toString();
// std::cout << patternString;
// // Pattern String is a array description
// // Pattern String is a array description
// transformVector.clear();
// QRegExp arrayRegExp("(\\[[\\s|0-F|a-f|,]+\\])");
// int pos = 0;
// while (arrayRegExp.indexIn(patternString, pos) != -1) {
// std::string arrayString = arrayRegExp.cap(1);
// std::vector<int> tmpVect;
// // std::cout << arrayString;
// unsigned int stringPos = 1;
// transformVector.clear();
// QRegExp arrayRegExp("(\\[[\\s|0-F|a-f|,]+\\])");
// int pos = 0;
// while (arrayRegExp.indexIn(patternString, pos) != -1) {
// std::string arrayString = arrayRegExp.cap(1);
// std::vector<int> tmpVect;
// // std::cout << arrayString;
// unsigned int stringPos = 1;
// while (arrayString[stringPos] != ']') {
// while (arrayString[stringPos].isSpace()) stringPos++;
// QRegExp hex("([0-F|a-f]+)");
// bool ok;
// if (hex.indexIn(arrayString, stringPos) == stringPos) {
// tmpVect.append(hex.cap(1).toInt(&ok, 16));
// }
// while (arrayString[stringPos].isSpace()) stringPos++;
// stringPos++; // should be the comma
// }
// pos += arrayRegExp.matchedLength();
// transformVector.append(tmpVect);
// }
// std::cout << transformVector.size() << transformVector;
return true;
}
// while (arrayString[stringPos] != ']') {
// while (arrayString[stringPos].isSpace()) stringPos++;
// QRegExp hex("([0-F|a-f]+)");
// bool ok;
// if (hex.indexIn(arrayString, stringPos) == stringPos) {
// tmpVect.append(hex.cap(1).toInt(&ok, 16));
// }
// while (arrayString[stringPos].isSpace()) stringPos++;
// stringPos++; // should be the comma
// }
// pos += arrayRegExp.matchedLength();
// transformVector.append(tmpVect);
// }
// std::cout << transformVector.size() << transformVector;
// return true;
// }
bool TilesPattern::loadPatterns() {
// foreach (std::string fileName, patternDirectory.entryList(QDir::Files)) {
@@ -165,6 +165,7 @@ std::vector<std::vector<tile8> > TilesPattern::transform(
unsigned int nbTransform = tiles.size() / numberOfTiles;
printf("Tiles size : %d - nbtransform : %d - pattern number of tiles : %d",
tiles.size(), nbTransform, numberOfTiles);
if (transPerRow > nbTransform)
toret.resize(tVectHeight);
else
@@ -174,7 +175,7 @@ std::vector<std::vector<tile8> > TilesPattern::transform(
std::vector<std::vector<tile8> > vec(toret);
auto it = vec.begin();
for (auto each : vec) {
for (auto &each : vec) {
each.resize(tilesPerRow);
}
// while (it.hasNext()) {
@@ -182,13 +183,13 @@ std::vector<std::vector<tile8> > TilesPattern::transform(
// }
// std::cout << toret[0].size() << "x" << toret.size();
while (repeat != nbTransform) {
// std::cout << "repeat" << repeat;
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;
// qDebug("X: %d - Y: %d - posTile : %d", posX, posY, posTile);
printf("X: %d - Y: %d - posTile : %d", posX, posY, posTile);
toret[posY][posX] = tiles[posTile];
}
}

View File

@@ -103,8 +103,6 @@ class TilesPattern {
void default_settings();
bool load(std::string patternFile);
static bool loadPatterns();
static TilesPattern pattern(std::string name);
static std::unordered_map<std::string, TilesPattern> Patterns();