more lowercase stuff
This commit is contained in:
259
src/Application/Graphics/bitmap.cc
Normal file
259
src/Application/Graphics/bitmap.cc
Normal file
@@ -0,0 +1,259 @@
|
||||
#include "Bitmap.h"
|
||||
|
||||
#include "data/rom.h"
|
||||
#include "rommapping.h"
|
||||
|
||||
namespace yaze {
|
||||
namespace Application {
|
||||
namespace Graphics {
|
||||
|
||||
int GetPCGfxAddress(char *romData, char id) {
|
||||
char **info1, **info2, **info3, **info4;
|
||||
int gfxPointer1 =
|
||||
lorom_snes_to_pc((romData[Core::Constants::gfx_1_pointer + 1] << 8) +
|
||||
(romData[Core::Constants::gfx_1_pointer]),
|
||||
info1);
|
||||
int gfxPointer2 =
|
||||
lorom_snes_to_pc((romData[Core::Constants::gfx_2_pointer + 1] << 8) +
|
||||
(romData[Core::Constants::gfx_2_pointer]),
|
||||
info2);
|
||||
int gfxPointer3 =
|
||||
lorom_snes_to_pc((romData[Core::Constants::gfx_3_pointer + 1] << 8) +
|
||||
(romData[Core::Constants::gfx_3_pointer]),
|
||||
info3);
|
||||
|
||||
char gfxGamePointer1 = romData[gfxPointer1 + id];
|
||||
char gfxGamePointer2 = romData[gfxPointer2 + id];
|
||||
char gfxGamePointer3 = romData[gfxPointer3 + id];
|
||||
|
||||
return lorom_snes_to_pc(
|
||||
Data::AddressFromBytes(gfxGamePointer1, gfxGamePointer2, gfxGamePointer3),
|
||||
info4);
|
||||
}
|
||||
|
||||
char *CreateAllGfxDataRaw(char *romData) {
|
||||
// 0-112 -> compressed 3bpp bgr -> (decompressed each) 0x600 chars
|
||||
// 113-114 -> compressed 2bpp -> (decompressed each) 0x800 chars
|
||||
// 115-126 -> uncompressed 3bpp sprites -> (each) 0x600 chars
|
||||
// 127-217 -> compressed 3bpp sprites -> (decompressed each) 0x600 chars
|
||||
// 218-222 -> compressed 2bpp -> (decompressed each) 0x800 chars
|
||||
|
||||
char *buffer = new char[346624];
|
||||
int bufferPos = 0;
|
||||
char *data = new char[2048];
|
||||
unsigned int uncompressedSize = 0;
|
||||
unsigned int compressedSize = 0;
|
||||
|
||||
for (int i = 0; i < Core::Constants::NumberOfSheets; i++) {
|
||||
isbpp3[i] = ((i >= 0 && i <= 112) || // Compressed 3bpp bg
|
||||
(i >= 115 && i <= 126) || // Uncompressed 3bpp sprites
|
||||
(i >= 127 && i <= 217) // Compressed 3bpp sprites
|
||||
);
|
||||
|
||||
// uncompressed sheets
|
||||
if (i >= 115 && i <= 126) {
|
||||
data = new char[Core::Constants::Uncompressed3BPPSize];
|
||||
int startAddress = GetPCGfxAddress(romData, (char)i);
|
||||
for (int j = 0; j < Core::Constants::Uncompressed3BPPSize; j++) {
|
||||
data[j] = romData[j + startAddress];
|
||||
}
|
||||
} else {
|
||||
data = alttp_decompress_gfx((char *)romData,
|
||||
GetPCGfxAddress(romData, (char)i),
|
||||
Core::Constants::UncompressedSheetSize,
|
||||
&uncompressedSize, &compressedSize);
|
||||
}
|
||||
|
||||
for (int j = 0; j < sizeof(data); j++) {
|
||||
buffer[j + bufferPos] = data[j];
|
||||
}
|
||||
|
||||
bufferPos += sizeof(data);
|
||||
}
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
void CreateAllGfxData(char *romData, char *allgfx16Ptr) {
|
||||
char *data = CreateAllGfxDataRaw(romData);
|
||||
char *newData =
|
||||
new char[0x6F800]; // NEED TO GET THE APPROPRIATE SIZE FOR THAT
|
||||
unsigned char *mask =
|
||||
new unsigned char[]{0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01};
|
||||
int sheetPosition = 0;
|
||||
|
||||
// 8x8 tile
|
||||
for (int s = 0; s < Core::Constants::NumberOfSheets; s++) // Per Sheet
|
||||
{
|
||||
for (int j = 0; j < 4; j++) // Per Tile Line Y
|
||||
{
|
||||
for (int i = 0; i < 16; i++) // Per Tile Line X
|
||||
{
|
||||
for (int y = 0; y < 8; y++) // Per Pixel Line
|
||||
{
|
||||
if (isbpp3[s]) {
|
||||
char lineBits0 =
|
||||
data[(y * 2) + (i * 24) + (j * 384) + sheetPosition];
|
||||
char lineBits1 =
|
||||
data[(y * 2) + (i * 24) + (j * 384) + 1 + sheetPosition];
|
||||
char lineBits2 =
|
||||
data[(y) + (i * 24) + (j * 384) + 16 + sheetPosition];
|
||||
|
||||
for (int x = 0; x < 4; x++) // Per Pixel X
|
||||
{
|
||||
char pixdata = 0;
|
||||
char pixdata2 = 0;
|
||||
|
||||
if ((lineBits0 & mask[(x * 2)]) == mask[(x * 2)]) {
|
||||
pixdata += 1;
|
||||
}
|
||||
if ((lineBits1 & mask[(x * 2)]) == mask[(x * 2)]) {
|
||||
pixdata += 2;
|
||||
}
|
||||
if ((lineBits2 & mask[(x * 2)]) == mask[(x * 2)]) {
|
||||
pixdata += 4;
|
||||
}
|
||||
|
||||
if ((lineBits0 & mask[(x * 2) + 1]) == mask[(x * 2) + 1]) {
|
||||
pixdata2 += 1;
|
||||
}
|
||||
if ((lineBits1 & mask[(x * 2) + 1]) == mask[(x * 2) + 1]) {
|
||||
pixdata2 += 2;
|
||||
}
|
||||
if ((lineBits2 & mask[(x * 2) + 1]) == mask[(x * 2) + 1]) {
|
||||
pixdata2 += 4;
|
||||
}
|
||||
|
||||
newData[(y * 64) + (x) + (i * 4) + (j * 512) + (s * 2048)] =
|
||||
(char)((pixdata << 4) | pixdata2);
|
||||
}
|
||||
} else {
|
||||
char lineBits0 =
|
||||
data[(y * 2) + (i * 16) + (j * 256) + sheetPosition];
|
||||
char lineBits1 =
|
||||
data[(y * 2) + (i * 16) + (j * 256) + 1 + sheetPosition];
|
||||
|
||||
for (int x = 0; x < 4; x++) // Per Pixel X
|
||||
{
|
||||
char pixdata = 0;
|
||||
char pixdata2 = 0;
|
||||
|
||||
if ((lineBits0 & mask[(x * 2)]) == mask[(x * 2)]) {
|
||||
pixdata += 1;
|
||||
}
|
||||
if ((lineBits1 & mask[(x * 2)]) == mask[(x * 2)]) {
|
||||
pixdata += 2;
|
||||
}
|
||||
|
||||
if ((lineBits0 & mask[(x * 2) + 1]) == mask[(x * 2) + 1]) {
|
||||
pixdata2 += 1;
|
||||
}
|
||||
if ((lineBits1 & mask[(x * 2) + 1]) == mask[(x * 2) + 1]) {
|
||||
pixdata2 += 2;
|
||||
}
|
||||
|
||||
newData[(y * 64) + (x) + (i * 4) + (j * 512) + (s * 2048)] =
|
||||
(char)((pixdata << 4) | pixdata2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isbpp3[s]) {
|
||||
sheetPosition += Core::Constants::Uncompressed3BPPSize;
|
||||
} else {
|
||||
sheetPosition += Core::Constants::UncompressedSheetSize;
|
||||
}
|
||||
}
|
||||
|
||||
char *allgfx16Data = (char *)allgfx16Ptr;
|
||||
|
||||
for (int i = 0; i < 0x6F800; i++) {
|
||||
allgfx16Data[i] = newData[i];
|
||||
}
|
||||
}
|
||||
|
||||
Bitmap::Bitmap(int width, int height, char *data)
|
||||
: width_(width), height_(height), pixel_data_(data) {}
|
||||
|
||||
void Bitmap::Create(GLuint *out_texture) {
|
||||
// // Read the pixel data from the ROM
|
||||
// SDL_RWops * src = SDL_RWFromMem(pixel_data_, 0);
|
||||
// // Create the surface from that RW stream
|
||||
// SDL_Surface* surface = SDL_LoadBMP_RW(src, SDL_FALSE);
|
||||
// GLenum mode = 0;
|
||||
// Uint8 bpp = surface->format->charsPerPixel;
|
||||
// Uint32 rm = surface->format->Rmask;
|
||||
// if (bpp == 3 && rm == 0x000000ff) mode = GL_RGB;
|
||||
// if (bpp == 3 && rm == 0x00ff0000) mode = GL_BGR;
|
||||
// if (bpp == 4 && rm == 0x000000ff) mode = GL_RGBA;
|
||||
// if (bpp == 4 && rm == 0xff000000) mode = GL_BGRA;
|
||||
|
||||
// GLsizei width = surface->w;
|
||||
// GLsizei height = surface->h;
|
||||
// GLenum format = mode;
|
||||
// GLvoid* pixels = surface->pixels;
|
||||
|
||||
// Create a OpenGL texture identifier
|
||||
GLuint image_texture;
|
||||
glGenTextures(1, &image_texture);
|
||||
glBindTexture(GL_TEXTURE_2D, image_texture);
|
||||
|
||||
// Setup filtering parameters for display
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
|
||||
// Upload pixels into texture
|
||||
#if defined(GL_UNPACK_ROW_LENGTH) && !defined(__EMSCRIPTEN__)
|
||||
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
|
||||
#endif
|
||||
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width_, height_, 0, GL_RGBA,
|
||||
GL_UNSIGNED_BYTE, pixel_data_);
|
||||
|
||||
*out_texture = image_texture;
|
||||
}
|
||||
|
||||
int Bitmap::GetWidth() { return width_; }
|
||||
int Bitmap::GetHeight() { return height_; }
|
||||
|
||||
// Simple helper function to load an image into a OpenGL texture with common
|
||||
// settings
|
||||
bool Bitmap::LoadBitmapFromROM(unsigned char *texture_data, GLuint *out_texture,
|
||||
int *out_width, int *out_height) {
|
||||
// Load from file
|
||||
int image_width = 0;
|
||||
int image_height = 0;
|
||||
if (texture_data == NULL) return false;
|
||||
|
||||
// Create a OpenGL texture identifier
|
||||
GLuint image_texture;
|
||||
glGenTextures(1, &image_texture);
|
||||
glBindTexture(GL_TEXTURE_2D, image_texture);
|
||||
|
||||
// Setup filtering parameters for display
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
|
||||
GL_CLAMP_TO_EDGE); // This is required on WebGL for non
|
||||
// power-of-two textures
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); // Same
|
||||
|
||||
// Upload pixels into texture
|
||||
#if defined(GL_UNPACK_ROW_LENGTH) && !defined(__EMSCRIPTEN__)
|
||||
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
|
||||
#endif
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image_width, image_height, 0, GL_RGBA,
|
||||
GL_UNSIGNED_BYTE, texture_data);
|
||||
|
||||
*out_texture = image_texture;
|
||||
*out_width = image_width;
|
||||
*out_height = image_height;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace Graphics
|
||||
} // namespace Application
|
||||
} // namespace yaze
|
||||
43
src/Application/Graphics/bitmap.h
Normal file
43
src/Application/Graphics/bitmap.h
Normal file
@@ -0,0 +1,43 @@
|
||||
#ifndef YAZE_APPLICATION_UTILS_BITMAP_H
|
||||
#define YAZE_APPLICATION_UTILS_BITMAP_H
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include <SDL_opengl.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "Core/Constants.h"
|
||||
|
||||
namespace yaze {
|
||||
namespace Application {
|
||||
namespace Graphics {
|
||||
|
||||
class Bitmap {
|
||||
public:
|
||||
Bitmap() = default;
|
||||
Bitmap(int width, int height, char *data);
|
||||
|
||||
void Create(GLuint *out_texture);
|
||||
int GetWidth();
|
||||
int GetHeight();
|
||||
|
||||
bool LoadBitmapFromROM(unsigned char *texture_data, GLuint *out_texture,
|
||||
int *out_width, int *out_height);
|
||||
|
||||
private:
|
||||
int width_;
|
||||
int height_;
|
||||
char *pixel_data_;
|
||||
};
|
||||
|
||||
static bool isbpp3[Core::Constants::NumberOfSheets];
|
||||
|
||||
int GetPCGfxAddress(char *romData, char id);
|
||||
char *CreateAllGfxDataRaw(char *romData);
|
||||
void CreateAllGfxData(char *romData, char *allgfx16Ptr);
|
||||
|
||||
} // namespace Graphics
|
||||
} // namespace Application
|
||||
} // namespace yaze
|
||||
|
||||
#endif
|
||||
2192
src/Application/Graphics/icons.h
Normal file
2192
src/Application/Graphics/icons.h
Normal file
File diff suppressed because it is too large
Load Diff
102
src/Application/Graphics/palette.cc
Normal file
102
src/Application/Graphics/palette.cc
Normal file
@@ -0,0 +1,102 @@
|
||||
#include "Palette.h"
|
||||
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
|
||||
namespace yaze {
|
||||
namespace Application {
|
||||
namespace Graphics {
|
||||
|
||||
SNESColor::SNESColor() {
|
||||
rgb = ImVec4(0.f, 0.f, 0.f, 0.f);
|
||||
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;
|
||||
col.red = val.x;
|
||||
col.blue = val.y;
|
||||
col.green = val.z;
|
||||
snes = convertcolor_rgb_to_snes(col);
|
||||
}
|
||||
|
||||
void SNESColor::setSNES(uint16_t val) {
|
||||
snes = val;
|
||||
m_color col = convertcolor_snes_to_rgb(val);
|
||||
rgb = ImVec4(col.red, col.green, col.blue, 1.f);
|
||||
}
|
||||
|
||||
SNESPalette::SNESPalette() { size = 0; }
|
||||
|
||||
SNESPalette::SNESPalette(uint8_t mSize) {
|
||||
size = mSize;
|
||||
for (unsigned int i = 0; i < mSize; i++) {
|
||||
SNESColor col;
|
||||
colors.push_back(col);
|
||||
}
|
||||
}
|
||||
|
||||
SNESPalette::SNESPalette(char* data) {
|
||||
assert((sizeof(data) % 4 == 0) && (sizeof(data) <= 32));
|
||||
size = sizeof(data) / 2;
|
||||
for (unsigned i = 0; i < sizeof(data); i += 2) {
|
||||
SNESColor col;
|
||||
col.snes = static_cast<uchar>(data[i + 1]) << 8;
|
||||
col.snes = col.snes | static_cast<uchar>(data[i]);
|
||||
m_color mColor = convertcolor_snes_to_rgb(col.snes);
|
||||
col.rgb = ImVec4(mColor.red, mColor.green, mColor.blue, 1.f);
|
||||
colors.push_back(col);
|
||||
}
|
||||
}
|
||||
|
||||
SNESPalette::SNESPalette(std::vector<ImVec4> cols) {
|
||||
// foreach (ImVec4 col, cols) {
|
||||
// SNESColor scol;
|
||||
// scol.setRgb(col);
|
||||
// colors.push_back(scol);
|
||||
// }
|
||||
// size = cols.size();
|
||||
}
|
||||
|
||||
char* SNESPalette::encode() {
|
||||
// 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);
|
||||
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
|
||||
48
src/Application/Graphics/palette.h
Normal file
48
src/Application/Graphics/palette.h
Normal file
@@ -0,0 +1,48 @@
|
||||
#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>
|
||||
|
||||
#include <cstdint>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
namespace yaze {
|
||||
namespace Application {
|
||||
namespace Graphics {
|
||||
|
||||
struct SNESColor {
|
||||
SNESColor();
|
||||
SNESColor(ImVec4);
|
||||
uint16_t snes;
|
||||
ImVec4 rgb;
|
||||
void setRgb(ImVec4);
|
||||
void setSNES(uint16_t);
|
||||
uint8_t approxSNES();
|
||||
ImVec4 approxRGB();
|
||||
};
|
||||
|
||||
class SNESPalette {
|
||||
public:
|
||||
SNESPalette();
|
||||
SNESPalette(uint8_t mSize);
|
||||
SNESPalette(char* snesPal);
|
||||
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
|
||||
} // namespace Application
|
||||
} // namespace yaze
|
||||
|
||||
#endif // YAZE_APPLICATION_GRAPHICS_PALETTE_H
|
||||
104
src/Application/Graphics/scene.cc
Normal file
104
src/Application/Graphics/scene.cc
Normal file
@@ -0,0 +1,104 @@
|
||||
#include "Scene.h"
|
||||
|
||||
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);
|
||||
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];
|
||||
// QImage newImage(8, 8, QImage::Format_Indexed8);
|
||||
// newImage.setColorCount(mPalette.size);
|
||||
// for (int i = 0; i < mPalette.size; i++) {
|
||||
// newImage.setColor(i, mPalette.colors.at(i).rgb);
|
||||
// }
|
||||
// for (int i = 0; i < 8; i++) {
|
||||
// for (int j = 0; j < 8; j++)
|
||||
// newImage.setPixel(i, j, tile.data[i + j * 8]);
|
||||
// }
|
||||
// QPixmap m;
|
||||
// m.convertFromImage(newImage);
|
||||
// imagesCache[tile.id] = m;
|
||||
// GraphicsTileItem *newTileItem = new GraphicsTileItem(m, tile);
|
||||
// addItem(newTileItem);
|
||||
// newTileItem->setTileZoom(tilesZoom);
|
||||
// newTileItem->setPos(i * newTileItem->boundingRect().width() + i,
|
||||
// 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));
|
||||
}
|
||||
|
||||
void Scene::updateScene() {
|
||||
std::cout << "Update scene";
|
||||
unsigned int itemCpt = 0;
|
||||
for (unsigned int j = 0; j < arrangedTiles.size(); j++) {
|
||||
for (unsigned int i = 0; i < arrangedTiles[0].size(); i++) {
|
||||
tile8 tile = arrangedTiles[j][i];
|
||||
// QPixmap m = imagesCache[tile.id];
|
||||
// GraphicsTileItem *tileItem = (GraphicsTileItem *)items()[itemCpt];
|
||||
// tileItem->image = m;
|
||||
// tileItem->rawTile = tile;
|
||||
// tileItem->setTileZoom(tilesZoom);
|
||||
// tileItem->setPos(i * tileItem->boundingRect().width() + i,
|
||||
// j * tileItem->boundingRect().width() + j);
|
||||
itemCpt++;
|
||||
}
|
||||
}
|
||||
// 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::setTilesZoom(unsigned int tileZoom) {
|
||||
tilesZoom = tileZoom;
|
||||
// if (!items().isEmpty()) updateScene();
|
||||
}
|
||||
|
||||
void Scene::setTilesPattern(TilesPattern tp) { tilesPattern = tp; }
|
||||
|
||||
} // namespace Graphics
|
||||
} // namespace Application
|
||||
} // namespace yaze
|
||||
44
src/Application/Graphics/scene.h
Normal file
44
src/Application/Graphics/scene.h
Normal file
@@ -0,0 +1,44 @@
|
||||
#ifndef YAZE_APPLICATION_GRAPHICS_SCENE_H
|
||||
#define YAZE_APPLICATION_GRAPHICS_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 {
|
||||
namespace Graphics {
|
||||
|
||||
class Scene {
|
||||
public:
|
||||
Scene() = default;
|
||||
void buildScene(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:
|
||||
unsigned int tilesZoom;
|
||||
TilesPattern tilesPattern;
|
||||
std::vector<tile8> allTiles;
|
||||
std::vector<std::vector<tile8> > arrangedTiles;
|
||||
|
||||
};
|
||||
|
||||
} // namespace Graphics
|
||||
} // namespace Application
|
||||
} // namespace yaze
|
||||
|
||||
#endif
|
||||
19
src/Application/Graphics/style.h
Normal file
19
src/Application/Graphics/style.h
Normal file
@@ -0,0 +1,19 @@
|
||||
#ifndef YAZE_APPLICATION_CORE_STYLE_H
|
||||
#define YAZE_APPLCIATION_CORE_STYLE_H
|
||||
|
||||
#include "imgui/imgui.h"
|
||||
#include "imgui/imgui_internal.h"
|
||||
|
||||
namespace yaze {
|
||||
namespace Application {
|
||||
namespace Core {
|
||||
namespace Style {
|
||||
|
||||
void ColorsYaze();
|
||||
|
||||
} // namespace Style
|
||||
} // namespace Core
|
||||
} // namespace Application
|
||||
} // namespace yaze
|
||||
|
||||
#endif
|
||||
219
src/Application/Graphics/tile.cc
Normal file
219
src/Application/Graphics/tile.cc
Normal file
@@ -0,0 +1,219 @@
|
||||
#include "Tile.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <regex>
|
||||
|
||||
namespace yaze {
|
||||
namespace Application {
|
||||
namespace Graphics {
|
||||
|
||||
TilesPattern::TilesPattern() {
|
||||
tilesPerRow = 16;
|
||||
numberOfTiles = 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});
|
||||
}
|
||||
|
||||
// [pattern]
|
||||
// name = "32x32 B (4x4)"
|
||||
// number_of_tile = 16
|
||||
// pattern =
|
||||
void TilesPattern::default_settings() {
|
||||
numberOfTiles = 16;
|
||||
std::string patternString =
|
||||
"[0, 1, 2, 3], [4, 5, 6, 7], [8, 9, A, B], [C, D, E, F]";
|
||||
|
||||
transformVector.clear();
|
||||
|
||||
std::smatch cm;
|
||||
std::regex arrayRegExp("(\\[[\\s|0-F|a-f|,]+\\])");
|
||||
|
||||
int pos = 0;
|
||||
while (std::regex_search(patternString, cm, arrayRegExp)) {
|
||||
// while (arrayRegExp.indexIn(patternString, pos) != -1) {
|
||||
std::string arrayString = cm[1];
|
||||
std::vector<int> tmpVect;
|
||||
// std::cout << arrayString;
|
||||
unsigned int stringPos = 1;
|
||||
|
||||
while (arrayString[stringPos] != ']') {
|
||||
while (arrayString[stringPos] == ' ') stringPos++;
|
||||
std::smatch cm_;
|
||||
std::regex hex("([0-F|a-f]+)");
|
||||
bool ok;
|
||||
|
||||
std::regex_search(arrayString, cm, hex);
|
||||
if (cm[1] == stringPos) {
|
||||
std::cout << "here" << std::endl;
|
||||
// tmpVect.push_back(stoi(cm[1]));
|
||||
}
|
||||
while (arrayString[stringPos] == ' ') stringPos++;
|
||||
stringPos++; // should be the comma
|
||||
}
|
||||
|
||||
pos += cm.size();
|
||||
transformVector.push_back(tmpVect);
|
||||
}
|
||||
std::cout << transformVector.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;
|
||||
std::vector<std::vector<tile8> > toret;
|
||||
unsigned int transPerRow = tilesPerRow / tVectWidth;
|
||||
unsigned int nbTransform = tiles.size() / numberOfTiles;
|
||||
printf("Tiles size : %d\nnbtransform : %d\npattern number of tiles : %d\n",
|
||||
tiles.size(), nbTransform, numberOfTiles);
|
||||
|
||||
if (transPerRow > nbTransform)
|
||||
toret.resize(tVectHeight);
|
||||
else
|
||||
toret.resize(
|
||||
((unsigned int)(((double)nbTransform / (double)transPerRow) + 0.5)) *
|
||||
tVectHeight);
|
||||
|
||||
for (auto &each : toret) {
|
||||
each.resize(tilesPerRow);
|
||||
}
|
||||
|
||||
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;
|
||||
printf("X: %d - Y: %d - posTile : %d", posX, posY, posTile);
|
||||
// toret[posY][posX] = tiles[posTile];
|
||||
toret.at(posY).at(posX) = tiles[posTile];
|
||||
}
|
||||
}
|
||||
if (repeatOffsetX + tVectWidth == tilesPerRow) {
|
||||
repeatOffsetX = 0;
|
||||
repeatOffsetY += tVectHeight;
|
||||
} else
|
||||
repeatOffsetX += tVectWidth;
|
||||
repeat++;
|
||||
}
|
||||
std::cout << "End of transform";
|
||||
return toret;
|
||||
}
|
||||
|
||||
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();
|
||||
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];
|
||||
|
||||
unsigned int lineBlock = i / (nbTransPerRow * numberOfTiles);
|
||||
unsigned int blockNB =
|
||||
(i % (nbTransPerRow * numberOfTiles) % tilesPerRow) / tVectWidth;
|
||||
|
||||
// std::cout << colInTab << lineInTab << " = " << tileNb;
|
||||
// unsigned int pos = tileNb + ((i % tilesPerRow) / nbTransPerRow) *
|
||||
// numberOfTiles;
|
||||
unsigned int pos = tileNb + (lineBlock + blockNB) * numberOfTiles;
|
||||
// std::cout << i << "Goes to : " << pos;
|
||||
toretVec[pos] = tiles[i];
|
||||
}
|
||||
return toretVec;
|
||||
}
|
||||
|
||||
std::vector<std::vector<tile8> > TilesPattern::transform(
|
||||
const TilesPattern &pattern, const std::vector<tile8> &tiles) {
|
||||
return pattern.transform(tiles);
|
||||
}
|
||||
|
||||
TilePreset::TilePreset() {
|
||||
pcTilesLocation = -1;
|
||||
SNESTilesLocation = 0;
|
||||
length = 0;
|
||||
bpp = 0;
|
||||
compression = "None";
|
||||
pcPaletteLocation = 0;
|
||||
SNESPaletteLocation = 0;
|
||||
paletteNoZeroColor = false;
|
||||
}
|
||||
|
||||
bool TilePreset::save(const std::string &file) {
|
||||
// QSettings pFile(file, QSettings::IniFormat);
|
||||
|
||||
// if (pFile.isWritable() == false)
|
||||
// return false;
|
||||
|
||||
// pFile.setValue("_/name", name);
|
||||
// pFile.setValue("rom/name", romName);
|
||||
// pFile.setValue("rom/type", romType);
|
||||
|
||||
// pFile.setValue("tiles/pc_location", QString::number(pcTilesLocation, 16));
|
||||
// pFile.setValue("tiles/snes_location", QString::number(SNESTilesLocation,
|
||||
// 16)); pFile.setValue("tiles/length", length); pFile.setValue("tiles/bpp",
|
||||
// bpp); pFile.setValue("tiles/compression", compression);
|
||||
// pFile.setValue("tiles/pattern", tilesPattern.name);
|
||||
|
||||
// pFile.setValue("palette/pc_location", QString::number(pcPaletteLocation,
|
||||
// 16)); pFile.setValue("palette/snes_location",
|
||||
// QString::number(SNESPaletteLocation, 16));
|
||||
// pFile.setValue("palette/nozerocolor", paletteNoZeroColor);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TilePreset::load(const std::string &file) {
|
||||
// QSettings pFile(file, QSettings::IniFormat);
|
||||
|
||||
// /* Meh solution to know if the file is right*/
|
||||
// if (pFile.value("_/name").toString().isEmpty())
|
||||
// return false;
|
||||
// name = pFile.value("_/name").toString();
|
||||
// romName = pFile.value("rom/name").toString();
|
||||
// romType = pFile.value("rom/type").toString();
|
||||
|
||||
// /* Locations are stored in a hex string */
|
||||
// bool ok;
|
||||
// pcTilesLocation = pFile.value("tiles/pc_location").toString().toUInt(&ok,
|
||||
// 16); SNESTilesLocation =
|
||||
// pFile.value("tiles/snes_location").toString().toUInt(&ok, 16); length =
|
||||
// pFile.value("tiles/length").toInt(); bpp =
|
||||
// pFile.value("tiles/bpp").toInt(); compression =
|
||||
// pFile.value("tiles/compression").toString(); QString patternName =
|
||||
// pFile.value("tiles/pattern").toString(); if (patternName.isEmpty())
|
||||
// patternName = "normal";
|
||||
// tilesPattern = TilesPattern::pattern(patternName);
|
||||
|
||||
// pcPaletteLocation =
|
||||
// pFile.value("palette/pc_location").toString().toUInt(&ok, 16);
|
||||
// SNESPaletteLocation =
|
||||
// pFile.value("palette/snes_location").toString().toUInt(&ok, 16);
|
||||
// paletteNoZeroColor = pFile.value("palette/nozerocolor").toBool();
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace Graphics
|
||||
} // namespace Application
|
||||
} // namespace yaze
|
||||
112
src/Application/Graphics/tile.h
Normal file
112
src/Application/Graphics/tile.h
Normal file
@@ -0,0 +1,112 @@
|
||||
#ifndef YAZE_APPLICATION_DATA_TILE_H
|
||||
#define YAZE_APPLICATION_DATA_TILE_H
|
||||
|
||||
#include <tile.h>
|
||||
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include "Palette.h"
|
||||
|
||||
namespace yaze {
|
||||
namespace Application {
|
||||
namespace Graphics {
|
||||
|
||||
using byte = unsigned char;
|
||||
using ushort = unsigned short;
|
||||
using uint = unsigned int;
|
||||
|
||||
// vhopppcc cccccccc
|
||||
// [0, 1]
|
||||
// [2, 3]
|
||||
class TileInfo {
|
||||
public:
|
||||
ushort id_;
|
||||
ushort over_;
|
||||
ushort vertical_mirror_;
|
||||
ushort horizontal_mirror_;
|
||||
byte palette_;
|
||||
TileInfo() {}
|
||||
TileInfo(ushort id, byte palette, ushort v, ushort h, ushort o)
|
||||
: id_(id),
|
||||
palette_(palette),
|
||||
vertical_mirror_(v),
|
||||
horizontal_mirror_(h),
|
||||
over_(o) {}
|
||||
};
|
||||
|
||||
class Tile32 {
|
||||
public:
|
||||
ushort tile0_;
|
||||
ushort tile1_;
|
||||
ushort tile2_;
|
||||
ushort tile3_;
|
||||
|
||||
Tile32(ushort t0, ushort t1, ushort t2, ushort t3)
|
||||
: tile0_(t0), tile1_(t1), tile2_(t2), tile3_(t3) {}
|
||||
};
|
||||
|
||||
class Tile16 {
|
||||
public:
|
||||
TileInfo tile0_;
|
||||
TileInfo tile1_;
|
||||
TileInfo tile2_;
|
||||
TileInfo tile3_;
|
||||
std::vector<TileInfo> tiles_info;
|
||||
|
||||
Tile16(TileInfo t0, TileInfo t1, TileInfo t2, TileInfo t3)
|
||||
: tile0_(t0), tile1_(t1), tile2_(t2), tile3_(t3) {
|
||||
tiles_info.push_back(tile0_);
|
||||
tiles_info.push_back(tile1_);
|
||||
tiles_info.push_back(tile2_);
|
||||
tiles_info.push_back(tile3_);
|
||||
}
|
||||
};
|
||||
|
||||
class TilesPattern {
|
||||
public:
|
||||
TilesPattern();
|
||||
std::string name;
|
||||
std::string description;
|
||||
bool custom;
|
||||
unsigned int tilesPerRow;
|
||||
unsigned int numberOfTiles;
|
||||
|
||||
void default_settings();
|
||||
|
||||
static TilesPattern pattern(std::string name);
|
||||
static std::vector<std::vector<tile8> > transform(
|
||||
const TilesPattern& pattern, const std::vector<tile8>& tiles);
|
||||
|
||||
protected:
|
||||
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;
|
||||
};
|
||||
|
||||
class TilePreset {
|
||||
public:
|
||||
TilePreset();
|
||||
|
||||
bool save(const std::string& file);
|
||||
bool load(const std::string& file);
|
||||
|
||||
bool paletteNoZeroColor;
|
||||
int pcTilesLocation;
|
||||
uint16_t SNESTilesLocation;
|
||||
uint16_t SNESPaletteLocation;
|
||||
uint32_t pcPaletteLocation;
|
||||
uint32_t length;
|
||||
uint32_t bpp;
|
||||
|
||||
TilesPattern tilesPattern;
|
||||
std::string compression;
|
||||
};
|
||||
|
||||
} // namespace Graphics
|
||||
} // namespace Application
|
||||
} // namespace yaze
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user