mirror of
https://github.com/nacabaro/nacapet.git
synced 2026-06-05 14:02:53 +00:00
Mierda
This commit is contained in:
parent
595faaf946
commit
ce23c44077
@ -23,18 +23,16 @@ void tft_initDisplay(TFT_eSPI &tft, uint16_t color) {
|
|||||||
void tft_initScreenBuffer(uint16_t color) {
|
void tft_initScreenBuffer(uint16_t color) {
|
||||||
composite.setAttribute(PSRAM_ENABLE, true);
|
composite.setAttribute(PSRAM_ENABLE, true);
|
||||||
|
|
||||||
|
|
||||||
// 2. Try to create the sprite
|
|
||||||
if (composite.createSprite(240, 240)) {
|
if (composite.createSprite(240, 240)) {
|
||||||
printf("SUCCESS: Composite sprite created.\n");
|
printf("SUCCESS: Composite sprite created.\n");
|
||||||
composite.fillSprite(TFT_RED); // If this works, screen should turn RED
|
composite.fillSprite(TFT_RED);
|
||||||
} else {
|
} else {
|
||||||
printf("FATAL: Composite sprite failed! No RAM/PSRAM.\n");
|
printf("FATAL: Composite sprite failed! No RAM/PSRAM.\n");
|
||||||
return; // Stop here so we don't draw "lines"
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
composite.setFreeFont(NULL); // Reset to default GLCD font
|
composite.setFreeFont(NULL);
|
||||||
composite.setTextFont(1); // Use the standard small font (scaled by size 4)
|
composite.setTextFont(1);
|
||||||
composite.setTextColor(TFT_BLUE);
|
composite.setTextColor(TFT_BLUE);
|
||||||
composite.setTextSize(4);
|
composite.setTextSize(4);
|
||||||
composite.pushSprite(0, 0);
|
composite.pushSprite(0, 0);
|
||||||
|
|||||||
@ -3,8 +3,7 @@
|
|||||||
|
|
||||||
|
|
||||||
void draw_drawAttacks(TFT_eSprite &bg, TFT_eSprite &sprite, struct SpriteData* attackSpriteData, int x, int y, uint8_t attackType, uint8_t attackSprite, bool flipped) {
|
void draw_drawAttacks(TFT_eSprite &bg, TFT_eSprite &sprite, struct SpriteData* attackSpriteData, int x, int y, uint8_t attackType, uint8_t attackSprite, bool flipped) {
|
||||||
// spriteWidth/Height are already pre-scaled at load time
|
int cleanWidth = attackSpriteData->spriteWidth + 6;
|
||||||
int cleanWidth = attackSpriteData->spriteWidth + 6; // +4 to be safe
|
|
||||||
draw_drawBackgroundSection(bg, x, y, cleanWidth, attackSpriteData->spriteHeight * 2);
|
draw_drawBackgroundSection(bg, x, y, cleanWidth, attackSpriteData->spriteHeight * 2);
|
||||||
|
|
||||||
switch(attackType) {
|
switch(attackType) {
|
||||||
|
|||||||
@ -10,13 +10,9 @@ void draw_drawBackground(TFT_eSprite& bg, int spr_w, int spr_h, int factor) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void draw_drawBackgroundSection(TFT_eSprite& bg, int x, int y, int w, int h) {
|
void draw_drawBackgroundSection(TFT_eSprite& bg, int x, int y, int w, int h) {
|
||||||
// Get the raw 16-bit pixel buffer from the background sprite
|
|
||||||
uint16_t* bgPtr = (uint16_t*)bg.getPointer();
|
uint16_t* bgPtr = (uint16_t*)bg.getPointer();
|
||||||
int bgStride = bg.width(); // Full row width — needed to advance between rows
|
int bgStride = bg.width();
|
||||||
|
|
||||||
// pushImage assumes a contiguous (packed) source buffer, so feeding the
|
|
||||||
// whole rectangle at once would read wrong pixels after the first row.
|
|
||||||
// Instead, copy one row at a time, each time jumping by bgStride pixels.
|
|
||||||
for (int row = 0; row < h; row++) {
|
for (int row = 0; row < h; row++) {
|
||||||
uint16_t* rowSrc = bgPtr + ((y + row) * bgStride) + x;
|
uint16_t* rowSrc = bgPtr + ((y + row) * bgStride) + x;
|
||||||
composite.pushImage(x, y + row, w, 1, rowSrc);
|
composite.pushImage(x, y + row, w, 1, rowSrc);
|
||||||
|
|||||||
@ -16,7 +16,6 @@ void draw_drawSprite(
|
|||||||
uint8_t spriteNumber,
|
uint8_t spriteNumber,
|
||||||
bool flipHorizontal
|
bool flipHorizontal
|
||||||
) {
|
) {
|
||||||
// Sprites are pre-scaled at load time; width/height are already final.
|
|
||||||
const int W = spriteData->spriteWidth;
|
const int W = spriteData->spriteWidth;
|
||||||
const int H = spriteData->spriteHeight;
|
const int H = spriteData->spriteHeight;
|
||||||
|
|
||||||
@ -29,10 +28,8 @@ void draw_drawSprite(
|
|||||||
uint16_t* srcBuf = spriteData->spriteData[spriteNumber];
|
uint16_t* srcBuf = spriteData->spriteData[spriteNumber];
|
||||||
|
|
||||||
if (!flipHorizontal) {
|
if (!flipHorizontal) {
|
||||||
// Fast path: one memcpy of the whole frame
|
|
||||||
memcpy(sprBuf, srcBuf, W * H * sizeof(uint16_t));
|
memcpy(sprBuf, srcBuf, W * H * sizeof(uint16_t));
|
||||||
} else {
|
} else {
|
||||||
// Mirror each row horizontally
|
|
||||||
for (int row = 0; row < H; row++) {
|
for (int row = 0; row < H; row++) {
|
||||||
const uint16_t* src = srcBuf + row * W;
|
const uint16_t* src = srcBuf + row * W;
|
||||||
uint16_t* dst = sprBuf + row * W;
|
uint16_t* dst = sprBuf + row * W;
|
||||||
|
|||||||
@ -8,9 +8,6 @@
|
|||||||
struct SpriteData* checkerboardPattern;
|
struct SpriteData* checkerboardPattern;
|
||||||
|
|
||||||
void menu_createCheckerboard() {
|
void menu_createCheckerboard() {
|
||||||
// Build the pattern pre-scaled by SPRITE_SCALE (6) so that
|
|
||||||
// draw_drawSprite can treat it identically to SPIFFS-loaded sprites.
|
|
||||||
// Logical size: 34 wide × 1 tall → Scaled: 204 wide × 6 tall
|
|
||||||
const uint8_t SCALE = 6;
|
const uint8_t SCALE = 6;
|
||||||
const uint8_t logicalW = 34;
|
const uint8_t logicalW = 34;
|
||||||
const uint8_t logicalH = 1;
|
const uint8_t logicalH = 1;
|
||||||
@ -27,7 +24,6 @@ void menu_createCheckerboard() {
|
|||||||
|
|
||||||
uint16_t* buf = checkerboardPattern->spriteData[0];
|
uint16_t* buf = checkerboardPattern->spriteData[0];
|
||||||
|
|
||||||
// Fill: repeat each logical pixel as a SCALE×SCALE block across all rows
|
|
||||||
for (uint16_t row = 0; row < scaledH; row++) {
|
for (uint16_t row = 0; row < scaledH; row++) {
|
||||||
for (uint8_t col = 0; col < logicalW; col++) {
|
for (uint8_t col = 0; col < logicalW; col++) {
|
||||||
uint16_t color = (col % 2 == 0) ? TFT_BLACK : TFT_TRANSPARENT;
|
uint16_t color = (col % 2 == 0) ? TFT_BLACK : TFT_TRANSPARENT;
|
||||||
|
|||||||
@ -8,8 +8,6 @@
|
|||||||
|
|
||||||
const char* TAG_S = "[STORAGE]";
|
const char* TAG_S = "[STORAGE]";
|
||||||
|
|
||||||
// All sprites are upscaled by this factor at load time so draw_drawSprite
|
|
||||||
// can skip the scaling loop entirely at runtime.
|
|
||||||
#define SPRITE_SCALE 6
|
#define SPRITE_SCALE 6
|
||||||
|
|
||||||
void storage_init() {
|
void storage_init() {
|
||||||
@ -41,8 +39,6 @@ void storage_readFile(const char* path, struct SpriteData* spriteData) {
|
|||||||
const uint8_t scaledW = width * SPRITE_SCALE;
|
const uint8_t scaledW = width * SPRITE_SCALE;
|
||||||
const uint8_t scaledH = height * SPRITE_SCALE;
|
const uint8_t scaledH = height * SPRITE_SCALE;
|
||||||
|
|
||||||
// Allocate scaled buffers in PSRAM (ps_malloc falls back to regular heap
|
|
||||||
// automatically if PSRAM is not available for a given allocation).
|
|
||||||
uint16_t** scaled = (uint16_t**) ps_malloc(spriteNumber * sizeof(uint16_t*));
|
uint16_t** scaled = (uint16_t**) ps_malloc(spriteNumber * sizeof(uint16_t*));
|
||||||
if (!scaled) {
|
if (!scaled) {
|
||||||
printf("%s PSRAM alloc failed for pointer table\n", TAG_S);
|
printf("%s PSRAM alloc failed for pointer table\n", TAG_S);
|
||||||
@ -60,7 +56,6 @@ void storage_readFile(const char* path, struct SpriteData* spriteData) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Temporary single-row scratch buffer in internal RAM for reading from file
|
|
||||||
uint16_t* rowBuf = (uint16_t*) malloc(width * sizeof(uint16_t));
|
uint16_t* rowBuf = (uint16_t*) malloc(width * sizeof(uint16_t));
|
||||||
if (!rowBuf) {
|
if (!rowBuf) {
|
||||||
printf("%s scratch alloc failed\n", TAG_S);
|
printf("%s scratch alloc failed\n", TAG_S);
|
||||||
@ -79,20 +74,16 @@ void storage_readFile(const char* path, struct SpriteData* spriteData) {
|
|||||||
uint16_t* dst = scaled[sprN];
|
uint16_t* dst = scaled[sprN];
|
||||||
|
|
||||||
for (int srcY = 0; srcY < height; srcY++) {
|
for (int srcY = 0; srcY < height; srcY++) {
|
||||||
// --- Read one source row, byte-swapping as we go ---
|
|
||||||
for (int srcX = 0; srcX < width; srcX++) {
|
for (int srcX = 0; srcX < width; srcX++) {
|
||||||
uint8_t hi, lo;
|
uint8_t hi, lo;
|
||||||
file.read(&hi, 1);
|
file.read(&hi, 1);
|
||||||
file.read(&lo, 1);
|
file.read(&lo, 1);
|
||||||
// File is big-endian RGB565; TFT_eSPI expects little-endian
|
|
||||||
rowBuf[srcX] = (lo << 8) | hi;
|
rowBuf[srcX] = (lo << 8) | hi;
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- Scale row vertically (repeat SPRITE_SCALE times) ---
|
|
||||||
for (int dy = 0; dy < SPRITE_SCALE; dy++) {
|
for (int dy = 0; dy < SPRITE_SCALE; dy++) {
|
||||||
uint16_t* dstRow = dst + (srcY * SPRITE_SCALE + dy) * scaledW;
|
uint16_t* dstRow = dst + (srcY * SPRITE_SCALE + dy) * scaledW;
|
||||||
|
|
||||||
// --- Scale each pixel horizontally ---
|
|
||||||
for (int srcX = 0; srcX < width; srcX++) {
|
for (int srcX = 0; srcX < width; srcX++) {
|
||||||
uint16_t color = rowBuf[srcX];
|
uint16_t color = rowBuf[srcX];
|
||||||
uint16_t* dstPixel = dstRow + srcX * SPRITE_SCALE;
|
uint16_t* dstPixel = dstRow + srcX * SPRITE_SCALE;
|
||||||
@ -107,7 +98,6 @@ void storage_readFile(const char* path, struct SpriteData* spriteData) {
|
|||||||
free(rowBuf);
|
free(rowBuf);
|
||||||
file.close();
|
file.close();
|
||||||
|
|
||||||
// Store scaled dimensions so the rest of the code sees the final size
|
|
||||||
spriteData->spriteWidth = scaledW;
|
spriteData->spriteWidth = scaledW;
|
||||||
spriteData->spriteHeight = scaledH;
|
spriteData->spriteHeight = scaledH;
|
||||||
spriteData->spriteNumber = spriteNumber;
|
spriteData->spriteNumber = spriteNumber;
|
||||||
@ -140,8 +130,6 @@ void storage_initBackground(const char* path, TFT_eSprite& bg) {
|
|||||||
uint8_t hi, lo;
|
uint8_t hi, lo;
|
||||||
file.read(&lo, 1);
|
file.read(&lo, 1);
|
||||||
file.read(&hi, 1);
|
file.read(&hi, 1);
|
||||||
// Store directly into sprite buffer – no byte swap needed here since
|
|
||||||
// background pixels are not going through the draw_drawSprite path.
|
|
||||||
bgBuf[i] = (hi << 8) | lo;
|
bgBuf[i] = (hi << 8) | lo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user