refactor: JD8_* a namespace Jd8::

This commit is contained in:
2026-05-16 14:24:22 +02:00
parent 1ce0d9c56c
commit f37308a5f0
41 changed files with 394 additions and 396 deletions
+39 -39
View File
@@ -21,17 +21,17 @@
#pragma GCC diagnostic pop
#endif
JD8_Surface screen = nullptr;
JD8_Palette main_palette = nullptr;
Jd8::Surface screen = nullptr;
Jd8::Palette main_palette = nullptr;
Uint32* pixel_data = nullptr;
void JD8_Init() {
void Jd8::init() {
screen = new Uint8[64000]{};
main_palette = new Color[256]{};
pixel_data = new Uint32[std::size_t{320} * 200]{};
}
void JD8_Quit() {
void Jd8::quit() {
delete[] screen;
delete[] main_palette;
delete[] pixel_data;
@@ -40,30 +40,30 @@ void JD8_Quit() {
pixel_data = nullptr;
}
void JD8_ClearScreen(Uint8 color) {
void Jd8::clearScreen(Uint8 color) {
memset(screen, color, 64000);
}
auto JD8_NewSurface() -> JD8_Surface {
auto Jd8::newSurface() -> Jd8::Surface {
return new Uint8[64000]{};
}
// Helper intern: deriva el basename d'una ruta per a buscar al Cache.
static auto jd8_basename(const char* file) -> std::string {
static auto pathBasename(const char* file) -> std::string {
std::string s = file;
auto pos = s.find_last_of("/\\");
return pos == std::string::npos ? s : s.substr(pos + 1);
}
auto JD8_LoadSurface(const char* file) -> JD8_Surface {
auto Jd8::loadSurface(const char* file) -> Jd8::Surface {
// Prova primer el Resource::Cache. Si l'asset és precarregat, copiem
// els 64KB des del cache (microsegons) i ens estalviem la decodificació
// GIF. Mantenim el contracte de la funció: el caller rep un buffer
// fresc que ha d'alliberar amb JD8_FreeSurface.
// fresc que ha d'alliberar amb Jd8::freeSurface.
if (Resource::Cache::get() != nullptr) {
try {
const auto& cached = Resource::Cache::get()->getSurfacePixels(jd8_basename(file));
JD8_Surface image = JD8_NewSurface();
const auto& cached = Resource::Cache::get()->getSurfacePixels(pathBasename(file));
Jd8::Surface image = Jd8::newSurface();
memcpy(image, cached.data(), 64000);
return image;
} catch (const std::exception&) {
@@ -79,21 +79,21 @@ auto JD8_LoadSurface(const char* file) -> JD8_Surface {
printf("Unable to load bitmap: %s\n", SDL_GetError());
exit(1);
}
JD8_Surface image = JD8_NewSurface();
Jd8::Surface image = Jd8::newSurface();
memcpy(image, pixels, 64000);
free(pixels);
return image;
}
auto JD8_LoadPalette(const char* file) -> JD8_Palette {
auto Jd8::loadPalette(const char* file) -> Jd8::Palette {
// Sempre retorna un buffer de 256 colors reservat amb `new Color[256]`
// — el caller és responsable d'alliberar-lo amb `delete[]` (o lliurar-ne
// l'ownership a `JD8_SetScreenPalette`).
// l'ownership a `Jd8::setScreenPalette`).
auto* palette = new Color[256];
if (Resource::Cache::get() != nullptr) {
try {
const auto& cached = Resource::Cache::get()->getPaletteBytes(jd8_basename(file));
const auto& cached = Resource::Cache::get()->getPaletteBytes(pathBasename(file));
memcpy(palette, cached.data(), 768);
return palette;
} catch (const std::exception&) {
@@ -108,7 +108,7 @@ auto JD8_LoadPalette(const char* file) -> JD8_Palette {
return palette;
}
void JD8_SetScreenPalette(JD8_Palette palette) {
void Jd8::setScreenPalette(Jd8::Palette palette) {
if (main_palette == palette) {
return;
}
@@ -116,13 +116,13 @@ void JD8_SetScreenPalette(JD8_Palette palette) {
main_palette = palette;
}
void JD8_FillSquare(int ini, int height, Uint8 color) {
void Jd8::fillSquare(int ini, int height, Uint8 color) {
const int offset = ini * 320;
const int size = height * 320;
memset(&screen[offset], color, size);
}
void JD8_FillRect(int x, int y, int w, int h, Uint8 color) {
void Jd8::fillRect(int x, int y, int w, int h, Uint8 color) {
if (x < 0) {
w += x;
x = 0;
@@ -145,11 +145,11 @@ void JD8_FillRect(int x, int y, int w, int h, Uint8 color) {
}
}
void JD8_Blit(const Uint8* surface) {
void Jd8::blit(const Uint8* surface) {
memcpy(screen, surface, 64000);
}
void JD8_Blit(int x, int y, const Uint8* surface, int sx, int sy, int sw, int sh) {
void Jd8::blit(int x, int y, const Uint8* surface, int sx, int sy, int sw, int sh) {
int src_pointer = sx + (sy * 320);
int dst_pointer = x + (y * 320);
for (int i = 0; i < sh; i++) {
@@ -159,7 +159,7 @@ void JD8_Blit(int x, int y, const Uint8* surface, int sx, int sy, int sw, int sh
}
}
void JD8_BlitToSurface(int x, int y, const Uint8* surface, int sx, int sy, int sw, int sh, JD8_Surface dest) {
void Jd8::blitToSurface(int x, int y, const Uint8* surface, int sx, int sy, int sw, int sh, Jd8::Surface dest) {
int src_pointer = sx + (sy * 320);
int dst_pointer = x + (y * 320);
for (int i = 0; i < sh; i++) {
@@ -169,7 +169,7 @@ void JD8_BlitToSurface(int x, int y, const Uint8* surface, int sx, int sy, int s
}
}
void JD8_BlitCK(int x, int y, const Uint8* surface, int sx, int sy, int sw, int sh, Uint8 colorkey) {
void Jd8::blitCK(int x, int y, const Uint8* surface, int sx, int sy, int sw, int sh, Uint8 colorkey) {
int src_pointer = sx + (sy * 320);
int dst_pointer = x + (y * 320);
for (int j = 0; j < sh; j++) {
@@ -183,7 +183,7 @@ void JD8_BlitCK(int x, int y, const Uint8* surface, int sx, int sy, int sw, int
}
}
void JD8_BlitCKCut(int x, int y, const Uint8* surface, int sx, int sy, int sw, int sh, Uint8 colorkey) {
void Jd8::blitCKCut(int x, int y, const Uint8* surface, int sx, int sy, int sw, int sh, Uint8 colorkey) {
int src_pointer = sx + (sy * 320);
int dst_pointer = x + (y * 320);
for (int j = 0; j < sh; j++) {
@@ -197,7 +197,7 @@ void JD8_BlitCKCut(int x, int y, const Uint8* surface, int sx, int sy, int sw, i
}
}
void JD8_BlitCKScroll(int y, const Uint8* surface, int sx, int sy, int sh, Uint8 colorkey) {
void Jd8::blitCKScroll(int y, const Uint8* surface, int sx, int sy, int sh, Uint8 colorkey) {
int dst_pointer = y * 320;
for (int j = sy; j < sy + sh; j++) {
for (int i = 0; i < 320; i++) {
@@ -210,7 +210,7 @@ void JD8_BlitCKScroll(int y, const Uint8* surface, int sx, int sy, int sh, Uint8
}
}
void JD8_BlitCKToSurface(int x, int y, const Uint8* surface, int sx, int sy, int sw, int sh, JD8_Surface dest, Uint8 colorkey) {
void Jd8::blitCKToSurface(int x, int y, const Uint8* surface, int sx, int sy, int sw, int sh, Jd8::Surface dest, Uint8 colorkey) {
int src_pointer = sx + (sy * 320);
int dst_pointer = x + (y * 320);
for (int j = 0; j < sh; j++) {
@@ -224,7 +224,7 @@ void JD8_BlitCKToSurface(int x, int y, const Uint8* surface, int sx, int sy, int
}
}
void JD8_Flip() {
void Jd8::flip() {
// Converteix el framebuffer indexat (paletted) a ARGB (pixel_data).
// El Director crida aquesta funció després del tick de cada escena
// per preparar el frame abans de presentar-lo. Ja no fa yield —
@@ -237,23 +237,23 @@ void JD8_Flip() {
}
}
auto JD8_GetFramebuffer() -> Uint32* {
auto Jd8::getFramebuffer() -> Uint32* {
return pixel_data;
}
void JD8_FreeSurface(JD8_Surface surface) { // NOLINT(readability-non-const-parameter): allibera memòria, no pot ser const
void Jd8::freeSurface(Jd8::Surface surface) { // NOLINT(readability-non-const-parameter): allibera memòria, no pot ser const
delete[] surface;
}
auto JD8_GetPixel(const Uint8* surface, int x, int y) -> Uint8 {
auto Jd8::getPixel(const Uint8* surface, int x, int y) -> Uint8 {
return surface[x + (y * 320)];
}
void JD8_PutPixel(JD8_Surface surface, int x, int y, Uint8 pixel) {
void Jd8::putPixel(Jd8::Surface surface, int x, int y, Uint8 pixel) {
surface[x + (y * 320)] = pixel;
}
void JD8_SetPaletteColor(Uint8 index, Uint8 r, Uint8 g, Uint8 b) {
void Jd8::setPaletteColor(Uint8 index, Uint8 r, Uint8 g, Uint8 b) {
main_palette[index].r = r << 2;
main_palette[index].g = g << 2;
main_palette[index].b = b << 2;
@@ -300,22 +300,22 @@ namespace {
} // namespace
void JD8_FadeStartOut() {
void Jd8::fadeStartOut() {
fade_type = FadeType::Out;
fade_step = 0;
}
void JD8_FadeStartToPal(const Color* pal) {
void Jd8::fadeStartToPal(const Color* pal) {
fade_type = FadeType::ToPal;
memcpy(fade_target, pal, sizeof(Color) * 256);
fade_step = 0;
}
auto JD8_FadeIsActive() -> bool {
auto Jd8::fadeIsActive() -> bool {
return fade_type != FadeType::None;
}
auto JD8_FadeTickStep() -> bool {
auto Jd8::fadeTickStep() -> bool {
if (fade_type == FadeType::None) {
return true;
}
@@ -331,8 +331,8 @@ auto JD8_FadeTickStep() -> bool {
}
// Els shims bloquejants `JD8_FadeOut` i `JD8_FadeToPal` han estat
// eliminats a Phase B.2: feien un bucle de 32 iteracions amb `JD8_Flip`
// eliminats a Phase B.2: feien un bucle de 32 iteracions amb `Jd8::flip`
// entre cada una que només funcionava mentre l'entorn tenia fibers i
// `JD8_Flip` cedia el control al Director. Ara tot fade es fa tick a
// tick via `scenes::PaletteFade` (que encapsula `JD8_FadeStartOut` /
// `JD8_FadeStartToPal` + `JD8_FadeTickStep`).
// `Jd8::flip` cedia el control al Director. Ara tot fade es fa tick a
// tick via `scenes::PaletteFade` (que encapsula `Jd8::fadeStartOut` /
// `Jd8::fadeStartToPal` + `Jd8::fadeTickStep`).
+78 -80
View File
@@ -1,80 +1,78 @@
#pragma once
#include <SDL3/SDL.h>
struct Color {
Uint8 r;
Uint8 g;
Uint8 b;
};
using JD8_Surface = Uint8*;
using JD8_Palette = Color*;
void JD8_Init();
void JD8_Quit();
void JD8_ClearScreen(Uint8 color);
auto JD8_NewSurface() -> JD8_Surface;
auto JD8_LoadSurface(const char* file) -> JD8_Surface;
auto JD8_LoadPalette(const char* file) -> JD8_Palette;
void JD8_SetScreenPalette(JD8_Palette palette);
void JD8_FillSquare(int ini, int height, Uint8 color);
// Omple un rectangle arbitrari de la pantalla amb un color paletat.
// Pensat per a UI senzilla (barra de progrés del BootLoader, etc.).
void JD8_FillRect(int x, int y, int w, int h, Uint8 color);
void JD8_Blit(const Uint8* surface);
void JD8_Blit(int x, int y, const Uint8* surface, int sx, int sy, int sw, int sh);
void JD8_BlitToSurface(int x, int y, const Uint8* surface, int sx, int sy, int sw, int sh, JD8_Surface dest);
void JD8_BlitCK(int x, int y, const Uint8* surface, int sx, int sy, int sw, int sh, Uint8 colorkey);
void JD8_BlitCKCut(int x, int y, const Uint8* surface, int sx, int sy, int sw, int sh, Uint8 colorkey);
void JD8_BlitCKScroll(int y, const Uint8* surface, int sx, int sy, int sh, Uint8 colorkey);
void JD8_BlitCKToSurface(int x, int y, const Uint8* surface, int sx, int sy, int sw, int sh, JD8_Surface dest, Uint8 colorkey);
// Converteix la pantalla indexada a ARGB. El Director crida aquesta
// funció al final de cada tick i després llegeix el framebuffer via
// JD8_GetFramebuffer() per presentar-lo.
void JD8_Flip();
// Accés al framebuffer ARGB de 320x200 actualitzat per l'última crida a
// JD8_Flip(). Propietat de jdraw8 — el caller no ha de lliberar-lo.
auto JD8_GetFramebuffer() -> Uint32*;
void JD8_FreeSurface(JD8_Surface surface);
auto JD8_GetPixel(const Uint8* surface, int x, int y) -> Uint8;
void JD8_PutPixel(JD8_Surface surface, int x, int y, Uint8 pixel);
void JD8_SetPaletteColor(Uint8 index, Uint8 r, Uint8 g, Uint8 b);
// API de fade no bloquejant (màquina d'estats). `FadeStart*` inicia el
// fade; `FadeTickStep` aplica un pas i retorna `true` quan el fade ha
// acabat. Un pas correspon visualment a una iteració del fade original
// (32 passos en total). El caller és responsable de fer el Flip entre
// passos si el vol veure animat. `FadeIsActive` permet saber si hi ha
// un fade en curs per a enllaçar-lo amb un altre subsistema.
// L'embolcall `scenes::PaletteFade` ho fa més idiomàtic per a escenes.
void JD8_FadeStartOut();
void JD8_FadeStartToPal(const Color* pal);
auto JD8_FadeTickStep() -> bool;
auto JD8_FadeIsActive() -> bool;
// JD_Font JD_LoadFont( char *file, int width, int height);
// void JD_DrawText( int x, int y, JD_Font *source, char *text);
// char *JD_GetFPS();
#pragma once
#include <SDL3/SDL.h>
struct Color {
Uint8 r;
Uint8 g;
Uint8 b;
};
namespace Jd8 {
using Surface = Uint8*;
using Palette = Color*;
void init();
void quit();
void clearScreen(Uint8 color);
auto newSurface() -> Surface;
auto loadSurface(const char* file) -> Surface;
auto loadPalette(const char* file) -> Palette;
void setScreenPalette(Palette palette);
void fillSquare(int ini, int height, Uint8 color);
// Omple un rectangle arbitrari de la pantalla amb un color paletat.
// Pensat per a UI senzilla (barra de progrés del BootLoader, etc.).
void fillRect(int x, int y, int w, int h, Uint8 color);
void blit(const Uint8* surface);
void blit(int x, int y, const Uint8* surface, int sx, int sy, int sw, int sh);
void blitToSurface(int x, int y, const Uint8* surface, int sx, int sy, int sw, int sh, Surface dest);
void blitCK(int x, int y, const Uint8* surface, int sx, int sy, int sw, int sh, Uint8 colorkey);
void blitCKCut(int x, int y, const Uint8* surface, int sx, int sy, int sw, int sh, Uint8 colorkey);
void blitCKScroll(int y, const Uint8* surface, int sx, int sy, int sh, Uint8 colorkey);
void blitCKToSurface(int x, int y, const Uint8* surface, int sx, int sy, int sw, int sh, Surface dest, Uint8 colorkey);
// Converteix la pantalla indexada a ARGB. El Director crida aquesta
// funció al final de cada tick i després llegeix el framebuffer via
// getFramebuffer() per presentar-lo.
void flip();
// Accés al framebuffer ARGB de 320x200 actualitzat per l'última crida a
// flip(). Propietat de jdraw8 — el caller no ha de lliberar-lo.
auto getFramebuffer() -> Uint32*;
void freeSurface(Surface surface);
auto getPixel(const Uint8* surface, int x, int y) -> Uint8;
void putPixel(Surface surface, int x, int y, Uint8 pixel);
void setPaletteColor(Uint8 index, Uint8 r, Uint8 g, Uint8 b);
// API de fade no bloquejant (màquina d'estats). `fadeStart*` inicia el
// fade; `fadeTickStep` aplica un pas i retorna `true` quan el fade ha
// acabat. Un pas correspon visualment a una iteració del fade original
// (32 passos en total). El caller és responsable de fer el Flip entre
// passos si el vol veure animat. `fadeIsActive` permet saber si hi ha
// un fade en curs per a enllaçar-lo amb un altre subsistema.
// L'embolcall `scenes::PaletteFade` ho fa més idiomàtic per a escenes.
void fadeStartOut();
void fadeStartToPal(const Color* pal);
auto fadeTickStep() -> bool;
auto fadeIsActive() -> bool;
} // namespace Jd8
+3 -3
View File
@@ -236,10 +236,10 @@ auto Director::iterate() -> bool {
current_scene_->tick(delta_ms);
// Converteix `screen` indexat → `pixel_data` ARGB amb la paleta
// actual. JD8_Flip ja no fa yield (Phase B.2 eliminà els fibers);
// actual. Jd8::flip ja no fa yield (Phase B.2 eliminà els fibers);
// ara només omple el framebuffer perquè el Director l'aprofite.
JD8_Flip();
std::memcpy(game_frame_, JD8_GetFramebuffer(), sizeof(game_frame_));
Jd8::flip();
std::memcpy(game_frame_, Jd8::getFramebuffer(), sizeof(game_frame_));
has_frame_ = true;
}
+1 -1
View File
@@ -9,7 +9,7 @@
#include "game/scenes/scene.hpp"
// El Director és l'únic thread del runtime. Cada iterate() fa input →
// tick de l'escena actual → JD8_Flip → overlay → present → sleep al frame
// tick de l'escena actual → Jd8::flip → overlay → present → sleep al frame
// target. Totes les escenes (`scenes::Scene` i `ModuleGame`) són
// tick-based i no bloquegen — no hi ha fibers, mutex ni condition_variable.
// Compatible amb SDL_AppIterate i amb el futur port a emscripten.
+1 -1
View File
@@ -4,7 +4,7 @@
#include "core/jail/jgame.hpp"
Bola::Bola(JD8_Surface gfx, Prota* sam)
Bola::Bola(Jd8::Surface gfx, Prota* sam)
: Sprite(gfx) {
this->sam = sam;
+1 -1
View File
@@ -6,7 +6,7 @@
class Bola : public Sprite {
public:
explicit Bola(JD8_Surface gfx, Prota* sam);
explicit Bola(Jd8::Surface gfx, Prota* sam);
void draw() override;
void update();
+1 -1
View File
@@ -4,7 +4,7 @@
#include "core/jail/jgame.hpp"
Engendro::Engendro(JD8_Surface gfx, Uint16 x, Uint16 y)
Engendro::Engendro(Jd8::Surface gfx, Uint16 x, Uint16 y)
: Sprite(gfx) {
entitat.frames.reserve(4);
for (int py = 50; py <= 65; py += 15) {
+1 -1
View File
@@ -4,7 +4,7 @@
class Engendro : public Sprite {
public:
explicit Engendro(JD8_Surface gfx, Uint16 x, Uint16 y);
explicit Engendro(Jd8::Surface gfx, Uint16 x, Uint16 y);
auto update() -> bool;
+36 -36
View File
@@ -6,7 +6,7 @@
#include "core/jail/jgame.hpp"
#include "core/jail/jinput.hpp"
Mapa::Mapa(JD8_Surface gfx, Prota* sam) {
Mapa::Mapa(Jd8::Surface gfx, Prota* sam) {
this->gfx = gfx;
this->sam = sam;
@@ -23,42 +23,42 @@ Mapa::Mapa(JD8_Surface gfx, Prota* sam) {
}
Mapa::~Mapa() {
JD8_FreeSurface(this->fondo);
Jd8::freeSurface(this->fondo);
}
void Mapa::draw() {
if (info::ctx.num_piramide != 4) {
switch (sam->o) {
case 0: // Down
JD8_BlitCKToSurface(sam->x, sam->y, this->gfx, 15, 125 + sam->frame_pejades, 15, 1, this->fondo, 255);
Jd8::blitCKToSurface(sam->x, sam->y, this->gfx, 15, 125 + sam->frame_pejades, 15, 1, this->fondo, 255);
break;
case 1: // Up
JD8_BlitCKToSurface(sam->x, sam->y + 15, this->gfx, 0, 125 + (14 - sam->frame_pejades), 15, 1, this->fondo, 255);
Jd8::blitCKToSurface(sam->x, sam->y + 15, this->gfx, 0, 125 + (14 - sam->frame_pejades), 15, 1, this->fondo, 255);
break;
case 2: // Right
JD8_BlitCKToSurface(sam->x + 7, sam->y, this->gfx, 30 + sam->frame_pejades, 125, 1, 15, this->fondo, 255);
Jd8::blitCKToSurface(sam->x + 7, sam->y, this->gfx, 30 + sam->frame_pejades, 125, 1, 15, this->fondo, 255);
break;
case 3: // Left
JD8_BlitCKToSurface(sam->x + 8, sam->y, this->gfx, 45 + (14 - sam->frame_pejades), 125, 1, 15, this->fondo, 255);
Jd8::blitCKToSurface(sam->x + 8, sam->y, this->gfx, 45 + (14 - sam->frame_pejades), 125, 1, 15, this->fondo, 255);
break;
default:
break;
}
}
JD8_Blit(this->fondo);
Jd8::blit(this->fondo);
// Pinta tombes
for (int y = 0; y < 4; y++) {
for (int x = 0; x < 4; x++) {
JD8_BlitCK(35 + (x * 65), 45 + (y * 35), this->gfx, this->tombes[x + (y * 4)].x, this->tombes[x + (y * 4)].y, 50, 20, 255);
Jd8::blitCK(35 + (x * 65), 45 + (y * 35), this->gfx, this->tombes[x + (y * 4)].x, this->tombes[x + (y * 4)].y, 50, 20, 255);
}
}
JD8_BlitCK(45, 15, this->gfx, 30 + (this->frame_torxes * 25), 80, 25, 15, 255);
JD8_BlitCK(95, 15, this->gfx, 30 + (this->frame_torxes * 25), 80, 25, 15, 255);
JD8_BlitCK(195, 15, this->gfx, 30 + (this->frame_torxes * 25), 80, 25, 15, 255);
JD8_BlitCK(245, 15, this->gfx, 30 + (this->frame_torxes * 25), 80, 25, 15, 255);
Jd8::blitCK(45, 15, this->gfx, 30 + (this->frame_torxes * 25), 80, 25, 15, 255);
Jd8::blitCK(95, 15, this->gfx, 30 + (this->frame_torxes * 25), 80, 25, 15, 255);
Jd8::blitCK(195, 15, this->gfx, 30 + (this->frame_torxes * 25), 80, 25, 15, 255);
Jd8::blitCK(245, 15, this->gfx, 30 + (this->frame_torxes * 25), 80, 25, 15, 255);
};
void Mapa::update() {
@@ -92,17 +92,17 @@ auto Mapa::novaMomia() -> bool {
void Mapa::preparaFondoEstatic() {
// Prepara el fondo esttic de l'habitaci
this->fondo = JD8_NewSurface();
this->fondo = Jd8::newSurface();
if (info::ctx.num_piramide == 6) {
JD8_BlitToSurface(9, 2, this->gfx, 227, 185, 92, 7, this->fondo); // Text "SECRETA"
Jd8::blitToSurface(9, 2, this->gfx, 227, 185, 92, 7, this->fondo); // Text "SECRETA"
} else {
JD8_BlitToSurface(9, 2, this->gfx, 60, 185, 39, 7, this->fondo); // Text "NIVELL"
JD8_BlitToSurface(72, 6, this->gfx, 153, 189, 3, 1, this->fondo); // Ralleta entre num piramide i num habitacio
Jd8::blitToSurface(9, 2, this->gfx, 60, 185, 39, 7, this->fondo); // Text "NIVELL"
Jd8::blitToSurface(72, 6, this->gfx, 153, 189, 3, 1, this->fondo); // Ralleta entre num piramide i num habitacio
}
JD8_BlitToSurface(130, 2, this->gfx, 225, 192, 19, 8, this->fondo); // Montonet de monedes + signe '='
JD8_BlitToSurface(220, 2, this->gfx, 160, 185, 48, 7, this->fondo); // Text "ENERGIA"
Jd8::blitToSurface(130, 2, this->gfx, 225, 192, 19, 8, this->fondo); // Montonet de monedes + signe '='
Jd8::blitToSurface(220, 2, this->gfx, 160, 185, 48, 7, this->fondo); // Text "ENERGIA"
if (info::ctx.diners >= 200) {
JD8_BlitToSurface(175, 3, this->gfx, 60, 193, 7, 6, this->fondo);
Jd8::blitToSurface(175, 3, this->gfx, 60, 193, 7, 6, this->fondo);
}
// Pinta taulells
@@ -110,22 +110,22 @@ void Mapa::preparaFondoEstatic() {
for (int x = 0; x < 19; x++) {
switch (info::ctx.num_piramide) {
case 1:
JD8_BlitToSurface(20 + (x * 15), 30 + (y * 15), this->gfx, 0, 80, 15, 15, this->fondo);
Jd8::blitToSurface(20 + (x * 15), 30 + (y * 15), this->gfx, 0, 80, 15, 15, this->fondo);
break;
case 2:
JD8_BlitToSurface(20 + (x * 15), 30 + (y * 15), this->gfx, 25, 95, 15, 15, this->fondo);
Jd8::blitToSurface(20 + (x * 15), 30 + (y * 15), this->gfx, 25, 95, 15, 15, this->fondo);
break;
case 3:
JD8_BlitToSurface(20 + (x * 15), 30 + (y * 15), this->gfx, 40, 95, 15, 15, this->fondo);
Jd8::blitToSurface(20 + (x * 15), 30 + (y * 15), this->gfx, 40, 95, 15, 15, this->fondo);
break;
case 4:
JD8_BlitToSurface(20 + (x * 15), 30 + (y * 15), this->gfx, 175 + ((rand() % 3) * 15), 80, 15, 15, this->fondo);
Jd8::blitToSurface(20 + (x * 15), 30 + (y * 15), this->gfx, 175 + ((rand() % 3) * 15), 80, 15, 15, this->fondo);
break;
case 5:
JD8_BlitToSurface(20 + (x * 15), 30 + (y * 15), this->gfx, 130, 80, 15, 15, this->fondo);
Jd8::blitToSurface(20 + (x * 15), 30 + (y * 15), this->gfx, 130, 80, 15, 15, this->fondo);
break;
case 6:
JD8_BlitToSurface(20 + (x * 15), 30 + (y * 15), this->gfx, 145, 80, 15, 15, this->fondo);
Jd8::blitToSurface(20 + (x * 15), 30 + (y * 15), this->gfx, 145, 80, 15, 15, this->fondo);
break;
default:
break;
@@ -134,28 +134,28 @@ void Mapa::preparaFondoEstatic() {
}
// Pinta vores de les parets
JD8_BlitCKToSurface(5, 15, this->gfx, 30, 110, 15, 15, this->fondo, 255);
JD8_BlitCKToSurface(295, 15, this->gfx, 45, 110, 15, 15, this->fondo, 255);
JD8_BlitCKToSurface(5, 180, this->gfx, 0, 155, 15, 20, this->fondo, 255);
JD8_BlitCKToSurface(295, 180, this->gfx, 15, 155, 15, 20, this->fondo, 255);
Jd8::blitCKToSurface(5, 15, this->gfx, 30, 110, 15, 15, this->fondo, 255);
Jd8::blitCKToSurface(295, 15, this->gfx, 45, 110, 15, 15, this->fondo, 255);
Jd8::blitCKToSurface(5, 180, this->gfx, 0, 155, 15, 20, this->fondo, 255);
Jd8::blitCKToSurface(295, 180, this->gfx, 15, 155, 15, 20, this->fondo, 255);
// Pinta parets verticals
for (int i = 0; i < 10; i++) {
JD8_BlitToSurface(5, 30 + (i * 15), this->gfx, 0, 110, 15, 15, this->fondo);
JD8_BlitToSurface(295, 30 + (i * 15), this->gfx, 15, 110, 15, 15, this->fondo);
Jd8::blitToSurface(5, 30 + (i * 15), this->gfx, 0, 110, 15, 15, this->fondo);
Jd8::blitToSurface(295, 30 + (i * 15), this->gfx, 15, 110, 15, 15, this->fondo);
}
// Pinta parets hortzintals
for (int i = 0; i < 11; i++) {
JD8_BlitToSurface(20 + (i * 25), 185, this->gfx, 0, 95, 25, 15, this->fondo);
JD8_BlitToSurface(20 + (i * 25), 15, this->gfx, 0, 95, 25, 15, this->fondo);
Jd8::blitToSurface(20 + (i * 25), 185, this->gfx, 0, 95, 25, 15, this->fondo);
Jd8::blitToSurface(20 + (i * 25), 15, this->gfx, 0, 95, 25, 15, this->fondo);
}
// Pinta la porta
JD8_BlitCKToSurface(150, 18, this->gfx, 0, 143, 15, 12, this->fondo, 255);
Jd8::blitCKToSurface(150, 18, this->gfx, 0, 143, 15, 12, this->fondo, 255);
if (info::ctx.num_piramide == 2) {
JD8_BlitToSurface(5, 100, this->gfx, 30, 140, 15, 15, this->fondo);
Jd8::blitToSurface(5, 100, this->gfx, 30, 140, 15, 15, this->fondo);
}
}
@@ -296,7 +296,7 @@ void Mapa::comprovaCaixa(Uint8 num) {
void Mapa::comprovaPorta() {
if (this->clau && this->farao) {
JD8_BlitCKToSurface(150, 18, this->gfx, 15, 143, 15, 12, this->fondo, 255);
Jd8::blitCKToSurface(150, 18, this->gfx, 15, 143, 15, 12, this->fondo, 255);
porta_oberta = true;
}
}
+3 -3
View File
@@ -31,7 +31,7 @@ struct Vertex {
class Mapa {
public:
explicit Mapa(JD8_Surface gfx, Prota* sam);
explicit Mapa(Jd8::Surface gfx, Prota* sam);
~Mapa();
Mapa(const Mapa&) = delete;
@@ -53,8 +53,8 @@ class Mapa {
void comprovaUltimCami();
void comprovaPorta();
JD8_Surface gfx;
JD8_Surface fondo;
Jd8::Surface gfx;
Jd8::Surface fondo;
Vertex vertex;
Vertex ultim_vertex;
Uint8 frame_torxes;
+14 -14
View File
@@ -1,6 +1,6 @@
#include "game/marcador.hpp"
Marcador::Marcador(JD8_Surface gfx, Prota* sam) {
Marcador::Marcador(Jd8::Surface gfx, Prota* sam) {
this->gfx = gfx;
this->sam = sam;
}
@@ -16,46 +16,46 @@ void Marcador::draw() {
this->pintaNumero(163, 2, info::ctx.diners % 10);
if (this->sam->pergami) {
JD8_BlitCK(190, 1, this->gfx, 209, 185, 15, 14, 255);
Jd8::blitCK(190, 1, this->gfx, 209, 185, 15, 14, 255);
}
JD8_BlitCK(271, 1, this->gfx, 0, 20, 15, info::ctx.vida * 3, 255);
Jd8::blitCK(271, 1, this->gfx, 0, 20, 15, info::ctx.vida * 3, 255);
if (info::ctx.vida < 5) {
JD8_BlitCK(271, 1 + (info::ctx.vida * 3), this->gfx, 75, 20, 15, 15 - (info::ctx.vida * 3), 255);
Jd8::blitCK(271, 1 + (info::ctx.vida * 3), this->gfx, 75, 20, 15, 15 - (info::ctx.vida * 3), 255);
}
}
void Marcador::pintaNumero(Uint16 x, Uint16 y, Uint8 num) {
switch (num) {
case 0:
JD8_BlitCK(x, y, this->gfx, 141, 193, 10, 7, 255);
Jd8::blitCK(x, y, this->gfx, 141, 193, 10, 7, 255);
break;
case 1:
JD8_BlitCK(x, y, this->gfx, 100, 185, 10, 7, 255);
Jd8::blitCK(x, y, this->gfx, 100, 185, 10, 7, 255);
break;
case 2:
JD8_BlitCK(x, y, this->gfx, 110, 185, 10, 7, 255);
Jd8::blitCK(x, y, this->gfx, 110, 185, 10, 7, 255);
break;
case 3:
JD8_BlitCK(x, y, this->gfx, 120, 185, 10, 7, 255);
Jd8::blitCK(x, y, this->gfx, 120, 185, 10, 7, 255);
break;
case 4:
JD8_BlitCK(x, y, this->gfx, 130, 185, 10, 7, 255);
Jd8::blitCK(x, y, this->gfx, 130, 185, 10, 7, 255);
break;
case 5:
JD8_BlitCK(x, y, this->gfx, 140, 185, 10, 7, 255);
Jd8::blitCK(x, y, this->gfx, 140, 185, 10, 7, 255);
break;
case 6:
JD8_BlitCK(x, y, this->gfx, 101, 193, 10, 7, 255);
Jd8::blitCK(x, y, this->gfx, 101, 193, 10, 7, 255);
break;
case 7:
JD8_BlitCK(x, y, this->gfx, 111, 193, 10, 7, 255);
Jd8::blitCK(x, y, this->gfx, 111, 193, 10, 7, 255);
break;
case 8:
JD8_BlitCK(x, y, this->gfx, 121, 193, 10, 7, 255);
Jd8::blitCK(x, y, this->gfx, 121, 193, 10, 7, 255);
break;
case 9:
JD8_BlitCK(x, y, this->gfx, 131, 193, 10, 7, 255);
Jd8::blitCK(x, y, this->gfx, 131, 193, 10, 7, 255);
break;
default:
break;
+2 -2
View File
@@ -6,7 +6,7 @@
class Marcador {
public:
explicit Marcador(JD8_Surface gfx, Prota* sam);
explicit Marcador(Jd8::Surface gfx, Prota* sam);
~Marcador() = default;
void draw();
@@ -14,6 +14,6 @@ class Marcador {
protected:
void pintaNumero(Uint16 x, Uint16 y, Uint8 num);
JD8_Surface gfx;
Jd8::Surface gfx;
Prota* sam;
};
+5 -5
View File
@@ -8,7 +8,7 @@
#include "core/jail/jinput.hpp"
ModuleGame::ModuleGame() {
this->gfx = JD8_LoadSurface(info::ctx.pepe_activat ? "gfx/frames2.gif" : "gfx/frames.gif");
this->gfx = Jd8::loadSurface(info::ctx.pepe_activat ? "gfx/frames2.gif" : "gfx/frames.gif");
JG_SetUpdateTicks(10);
this->sam = std::make_unique<Prota>(this->gfx);
@@ -22,7 +22,7 @@ ModuleGame::ModuleGame() {
}
ModuleGame::~ModuleGame() {
JD8_FreeSurface(this->gfx);
Jd8::freeSurface(this->gfx);
}
void ModuleGame::onEnter() {
@@ -47,7 +47,7 @@ void ModuleGame::onEnter() {
// Arranca el fade-in tick-based. El `PaletteFade` avança un pas (de
// 32) per cada tick; durant aquesta fase el gameplay no corre,
// només Draw+fade. Substituïx la crida bloquejant `JD8_FadeToPal`.
fade_.startFadeTo(JD8_LoadPalette(info::ctx.pepe_activat ? "gfx/frames2.gif" : "gfx/frames.gif"));
fade_.startFadeTo(Jd8::loadPalette(info::ctx.pepe_activat ? "gfx/frames2.gif" : "gfx/frames.gif"));
phase_ = Phase::FadingIn;
}
@@ -55,7 +55,7 @@ void ModuleGame::tick(int delta_ms) {
switch (phase_) {
case Phase::FadingIn:
// No redibuixem durant el fade: el `screen` ja va ser omplit
// per la Draw() d'onEnter. Només el JD8_Flip del caller muta
// per la Draw() d'onEnter. Només el Jd8::flip del caller muta
// pixel_data segons la paleta que avança pas a pas.
fade_.tick(delta_ms);
if (fade_.done()) {
@@ -119,7 +119,7 @@ void ModuleGame::applyFinalTransitions() const {
}
void ModuleGame::Draw() {
// No crida JD8_Flip — el caller (mini-loop del fiber, o Director a
// No crida Jd8::flip — el caller (mini-loop del fiber, o Director a
// Phase B.2) ho fa després de cada tick.
this->mapa->draw();
this->marcador->draw();
+2 -2
View File
@@ -50,7 +50,7 @@ class ModuleGame : public scenes::Scene {
Done,
};
void Draw(); // render a `screen`; no crida JD8_Flip (ho fa el caller)
void Draw(); // render a `screen`; no crida Jd8::flip (ho fa el caller)
void Update(); // gated per JG_ShouldUpdate
void iniciarMomies();
@@ -59,7 +59,7 @@ class ModuleGame : public scenes::Scene {
Phase phase_{Phase::FadingIn};
scenes::PaletteFade fade_;
Uint8 final_{0};
JD8_Surface gfx{nullptr};
Jd8::Surface gfx{nullptr};
std::unique_ptr<Mapa> mapa;
std::unique_ptr<Prota> sam;
+3 -3
View File
@@ -4,7 +4,7 @@
#include "core/jail/jgame.hpp"
Momia::Momia(JD8_Surface gfx, bool dimoni, Uint16 x, Uint16 y, Prota* sam)
Momia::Momia(Jd8::Surface gfx, bool dimoni, Uint16 x, Uint16 y, Prota* sam)
: Sprite(gfx) {
this->dimoni = dimoni;
this->sam = sam;
@@ -75,9 +75,9 @@ void Momia::draw() {
if (info::ctx.num_piramide == 4) {
if ((JG_GetCycleCounter() % 40) < 20) {
JD8_BlitCK(this->x, this->y, this->gfx, 220, 80, 15, 15, 255);
Jd8::blitCK(this->x, this->y, this->gfx, 220, 80, 15, 15, 255);
} else {
JD8_BlitCK(this->x, this->y, this->gfx, 235, 80, 15, 15, 255);
Jd8::blitCK(this->x, this->y, this->gfx, 235, 80, 15, 15, 255);
}
}
}
+1 -1
View File
@@ -9,7 +9,7 @@
class Momia : public Sprite {
public:
explicit Momia(JD8_Surface gfx, bool dimoni, Uint16 x, Uint16 y, Prota* sam);
explicit Momia(Jd8::Surface gfx, bool dimoni, Uint16 x, Uint16 y, Prota* sam);
void draw() override;
auto update() -> bool;
+3 -3
View File
@@ -5,7 +5,7 @@
#include "core/jail/jgame.hpp"
#include "core/jail/jinput.hpp"
Prota::Prota(JD8_Surface gfx)
Prota::Prota(Jd8::Surface gfx)
: Sprite(gfx) {
entitat.frames.reserve(82);
@@ -92,9 +92,9 @@ void Prota::draw() {
if (info::ctx.num_piramide == 4 && this->o != 4) {
if ((JG_GetCycleCounter() % 40) < 20) {
JD8_BlitCK(this->x, this->y, this->gfx, 220, 80, 15, 15, 255);
Jd8::blitCK(this->x, this->y, this->gfx, 220, 80, 15, 15, 255);
} else {
JD8_BlitCK(this->x, this->y, this->gfx, 235, 80, 15, 15, 255);
Jd8::blitCK(this->x, this->y, this->gfx, 235, 80, 15, 15, 255);
}
}
}
+1 -1
View File
@@ -5,7 +5,7 @@
class Prota : public Sprite {
public:
explicit Prota(JD8_Surface gfx);
explicit Prota(Jd8::Surface gfx);
void draw() override;
auto update() -> Uint8;
+5 -5
View File
@@ -15,10 +15,10 @@ namespace scenes {
gfx_ = SurfaceHandle("gfx/ffase.gif");
JD8_ClearScreen(0);
Jd8::clearScreen(0);
// Títols superior i inferior del banner (compartits per tots els nivells)
JD8_Blit(81, 24, gfx_, 81, 155, 168, 21);
JD8_Blit(39, 150, gfx_, 39, 175, 248, 20);
Jd8::blit(81, 24, gfx_, 81, 155, 168, 21);
Jd8::blit(39, 150, gfx_, 39, 175, 248, 20);
// Número de piràmide: les 4 variants del vell `doBanner` es reduïxen
// a coordenades (sx,sy) calculades a partir de l'índex 0..3.
@@ -26,11 +26,11 @@ namespace scenes {
if (idx >= 0 && idx <= 3) {
const int sx = (idx % 2) * 160;
const int sy = (idx / 2) * 75;
JD8_Blit(82, 60, gfx_, sx, sy, 160, 75);
Jd8::blit(82, 60, gfx_, sx, sy, 160, 75);
}
// PaletteFade copia internament amb memcpy; alliberem la paleta temporal.
JD8_Palette pal = JD8_LoadPalette("gfx/ffase.gif");
Jd8::Palette pal = Jd8::loadPalette("gfx/ffase.gif");
fade_.startFadeTo(pal);
delete[] pal;
+8 -8
View File
@@ -24,8 +24,8 @@ namespace scenes {
// Inicialitza la paleta mínima per a la barra. La resta de
// colors queden a negre — després cada escena del joc carregarà
// la seua pròpia paleta.
JD8_SetPaletteColor(BG_COLOR, 0, 0, 0);
JD8_SetPaletteColor(BAR_COLOR, 63, 63, 63);
Jd8::setPaletteColor(BG_COLOR, 0, 0, 0);
Jd8::setPaletteColor(BAR_COLOR, 63, 63, 63);
}
void BootLoaderScene::tick(int /*delta_ms*/) {
@@ -36,7 +36,7 @@ namespace scenes {
}
void BootLoaderScene::render() {
JD8_ClearScreen(BG_COLOR);
Jd8::clearScreen(BG_COLOR);
if (!Options::game.show_preload) {
return;
@@ -46,14 +46,14 @@ namespace scenes {
const int filled = static_cast<int>(static_cast<float>(BAR_W) * pct);
// Vora de la barra (línia 1 píxel a dalt i a baix).
JD8_FillRect(BAR_X - 1, BAR_Y - 1, BAR_W + 2, 1, BAR_COLOR);
JD8_FillRect(BAR_X - 1, BAR_Y + BAR_H, BAR_W + 2, 1, BAR_COLOR);
JD8_FillRect(BAR_X - 1, BAR_Y, 1, BAR_H, BAR_COLOR);
JD8_FillRect(BAR_X + BAR_W, BAR_Y, 1, BAR_H, BAR_COLOR);
Jd8::fillRect(BAR_X - 1, BAR_Y - 1, BAR_W + 2, 1, BAR_COLOR);
Jd8::fillRect(BAR_X - 1, BAR_Y + BAR_H, BAR_W + 2, 1, BAR_COLOR);
Jd8::fillRect(BAR_X - 1, BAR_Y, 1, BAR_H, BAR_COLOR);
Jd8::fillRect(BAR_X + BAR_W, BAR_Y, 1, BAR_H, BAR_COLOR);
// Ompliment proporcional al progrés.
if (filled > 0) {
JD8_FillRect(BAR_X, BAR_Y, filled, BAR_H, BAR_COLOR);
Jd8::fillRect(BAR_X, BAR_Y, filled, BAR_H, BAR_COLOR);
}
}
+15 -15
View File
@@ -52,8 +52,8 @@ namespace scenes {
vaddr2_ = SurfaceHandle("gfx/final.gif");
vaddr3_ = SurfaceHandle("gfx/finals.gif");
JD8_Palette pal = JD8_LoadPalette("gfx/final.gif");
JD8_SetScreenPalette(pal);
Jd8::Palette pal = Jd8::loadPalette("gfx/final.gif");
Jd8::setScreenPalette(pal);
// `pal` passa a ser propietat de main_palette — no l'alliberem.
phase_ = Phase::Rolling;
@@ -62,40 +62,40 @@ namespace scenes {
}
void CreditsScene::render() {
JD8_ClearScreen(BG_INDEX);
Jd8::clearScreen(BG_INDEX);
// Columna 1: scroll vertical del bloc (0,0,80,200) pujant des de
// y=200 fins que el contador supera 2750.
if (contador_ < 2750) {
JD8_BlitCKCut(115, 200 - (contador_ / 6), vaddr2_, 0, 0, 80, 200, 0);
Jd8::blitCKCut(115, 200 - (contador_ / 6), vaddr2_, 0, 0, 80, 200, 0);
}
// Columna 2: scroll vertical del bloc (85,0,120,140), arrenca
// a contador 1200 i s'atura (fix en y=20) a partir de 2250.
if ((contador_ > 1200) && (contador_ < 2280)) {
JD8_BlitCKCut(100, 200 - ((contador_ - 1200) / 6), vaddr2_, 85, 0, 120, 140, 0);
Jd8::blitCKCut(100, 200 - ((contador_ - 1200) / 6), vaddr2_, 85, 0, 120, 140, 0);
} else if (contador_ >= 2250) {
JD8_BlitCK(100, 20, vaddr2_, 85, 0, 120, 140, 0);
Jd8::blitCK(100, 20, vaddr2_, 85, 0, 120, 140, 0);
}
// Fons: 4 capes parallax + cotxe només si l'usuari ha aconseguit
// tots els diamants (final "bo"). Altrament fons estàtic.
if (info::ctx.diamants == 16) {
JD8_BlitCKScroll(50, vaddr3_, ((contador_ >> 3) % 320) + 1, 0, 50, 255);
JD8_BlitCKScroll(50, vaddr3_, ((contador_ >> 2) % 320) + 1, 50, 50, 255);
JD8_BlitCKScroll(50, vaddr3_, ((contador_ >> 1) % 320) + 1, 100, 50, 255);
JD8_BlitCKScroll(50, vaddr3_, (contador_ % 320) + 1, 150, 50, 255);
Jd8::blitCKScroll(50, vaddr3_, ((contador_ >> 3) % 320) + 1, 0, 50, 255);
Jd8::blitCKScroll(50, vaddr3_, ((contador_ >> 2) % 320) + 1, 50, 50, 255);
Jd8::blitCKScroll(50, vaddr3_, ((contador_ >> 1) % 320) + 1, 100, 50, 255);
Jd8::blitCKScroll(50, vaddr3_, (contador_ % 320) + 1, 150, 50, 255);
const CocheFrame& cf = COCHE_FRAMES[coche_.frame()];
JD8_BlitCK(100, 50, vaddr2_, cf.x, cf.y, 106, 48, 255);
Jd8::blitCK(100, 50, vaddr2_, cf.x, cf.y, 106, 48, 255);
} else {
JD8_BlitCK(0, 50, vaddr3_, 0, 0, 320, 50, 255);
JD8_BlitCK(0, 50, vaddr3_, 0, 50, 320, 50, 255);
Jd8::blitCK(0, 50, vaddr3_, 0, 0, 320, 50, 255);
Jd8::blitCK(0, 50, vaddr3_, 0, 50, 320, 50, 255);
}
// Barres de marc que cobreixen els extrems del scroll vertical.
JD8_FillSquare(0, 50, BG_INDEX);
JD8_FillSquare(100, 10, BG_INDEX);
Jd8::fillSquare(0, 50, BG_INDEX);
Jd8::fillSquare(100, 10, BG_INDEX);
}
void CreditsScene::writeTrickIni() {
+14 -14
View File
@@ -41,7 +41,7 @@ namespace scenes {
IntroNewLogoScene::IntroNewLogoScene() = default;
// No alliberem `pal_`: JD8_SetScreenPalette n'ha pres ownership i el
// No alliberem `pal_`: Jd8::setScreenPalette n'ha pres ownership i el
// proper SetScreenPalette / FadeToPal el lliurarà. Alliberar-lo ací
// provocaria double free.
IntroNewLogoScene::~IntroNewLogoScene() = default;
@@ -50,15 +50,15 @@ namespace scenes {
playMusic("music/menu.ogg");
gfx_ = SurfaceHandle("gfx/logo_new.gif");
pal_ = JD8_LoadPalette("gfx/logo_new.gif");
JD8_SetScreenPalette(pal_);
pal_ = Jd8::loadPalette("gfx/logo_new.gif");
Jd8::setScreenPalette(pal_);
// Surface auxiliar omplida amb el color del cursor — permet pintar
// el "subratllat" amb un blit normal.
cursor_surf_.adopt(JD8_NewSurface());
cursor_surf_.adopt(Jd8::newSurface());
std::memset(cursor_surf_.get(), CURSOR_COLOR, 64000);
JD8_ClearScreen(0);
Jd8::clearScreen(0);
phase_ = Phase::Initial;
phase_acc_ms_ = 0;
@@ -70,30 +70,30 @@ namespace scenes {
void IntroNewLogoScene::render() {
switch (phase_) {
case Phase::Initial:
JD8_ClearScreen(0);
Jd8::clearScreen(0);
break;
case Phase::Revealing: {
JD8_ClearScreen(0);
JD8_Blit(LOGO_DST_X, LOGO_DST_Y, gfx_, LOGO_SRC_X, LOGO_SRC_Y, LETTER_WIDTHS[reveal_letter_], LOGO_HEIGHT);
Jd8::clearScreen(0);
Jd8::blit(LOGO_DST_X, LOGO_DST_Y, gfx_, LOGO_SRC_X, LOGO_SRC_Y, LETTER_WIDTHS[reveal_letter_], LOGO_HEIGHT);
if (reveal_cursor_visible_) {
JD8_Blit(CURSOR_X[reveal_letter_], CURSOR_Y, cursor_surf_, 0, 0, CURSOR_W, CURSOR_H);
Jd8::blit(CURSOR_X[reveal_letter_], CURSOR_Y, cursor_surf_, 0, 0, CURSOR_W, CURSOR_H);
}
break;
}
case Phase::FullLogoFlash:
JD8_ClearScreen(0);
JD8_Blit(LOGO_DST_X, LOGO_DST_Y, gfx_, LOGO_SRC_X, LOGO_SRC_Y, LETTER_WIDTHS[8], LOGO_HEIGHT);
JD8_Blit(CURSOR_X[8], CURSOR_Y, cursor_surf_, 0, 0, CURSOR_W, CURSOR_H);
Jd8::clearScreen(0);
Jd8::blit(LOGO_DST_X, LOGO_DST_Y, gfx_, LOGO_SRC_X, LOGO_SRC_Y, LETTER_WIDTHS[8], LOGO_HEIGHT);
Jd8::blit(CURSOR_X[8], CURSOR_Y, cursor_surf_, 0, 0, CURSOR_W, CURSOR_H);
break;
case Phase::PaletteCycle:
case Phase::FinalWait:
// Logo complet sense cursor — els pixels del cursor
// ciclarien de color durant el cicle de paleta.
JD8_ClearScreen(0);
JD8_Blit(LOGO_DST_X, LOGO_DST_Y, gfx_, LOGO_SRC_X, LOGO_SRC_Y, LETTER_WIDTHS[8], LOGO_HEIGHT);
Jd8::clearScreen(0);
Jd8::blit(LOGO_DST_X, LOGO_DST_Y, gfx_, LOGO_SRC_X, LOGO_SRC_Y, LETTER_WIDTHS[8], LOGO_HEIGHT);
break;
case Phase::Sprites:
+1 -1
View File
@@ -55,7 +55,7 @@ namespace scenes {
SurfaceHandle gfx_;
SurfaceHandle cursor_surf_;
JD8_Palette pal_{nullptr}; // propietat transferida a main_palette via SetScreenPalette
Jd8::Palette pal_{nullptr}; // propietat transferida a main_palette via SetScreenPalette
std::unique_ptr<IntroSpritesScene> sprites_scene_;
Phase phase_{Phase::Initial};
+10 -10
View File
@@ -50,7 +50,7 @@ namespace {
// IntroScene només s'activa quan use_new_logo == false, així que la
// branca use_new_logo d'aquell helper aquí no es necessita.
void drawWordmark(const Uint8* gfx) {
JD8_Blit(43, 78, gfx, 43, 155, 231, 45);
Jd8::blit(43, 78, gfx, 43, 155, 231, 45);
}
} // namespace
@@ -59,7 +59,7 @@ namespace scenes {
IntroScene::IntroScene() = default;
// No alliberem `pal_`: JD8_SetScreenPalette n'ha pres ownership i el
// No alliberem `pal_`: Jd8::setScreenPalette n'ha pres ownership i el
// proper SetScreenPalette / FadeToPal la lliurarà. Alliberar-la ací
// provocaria double free.
IntroScene::~IntroScene() = default;
@@ -68,10 +68,10 @@ namespace scenes {
playMusic("music/menu.ogg");
gfx_ = SurfaceHandle("gfx/logo.gif");
pal_ = JD8_LoadPalette("gfx/logo.gif");
JD8_SetScreenPalette(pal_);
pal_ = Jd8::loadPalette("gfx/logo.gif");
Jd8::setScreenPalette(pal_);
JD8_ClearScreen(0);
Jd8::clearScreen(0);
phase_ = Phase::InitialWait;
phase_acc_ms_ = 0;
@@ -82,21 +82,21 @@ namespace scenes {
void IntroScene::render() {
switch (phase_) {
case Phase::InitialWait:
JD8_ClearScreen(0);
Jd8::clearScreen(0);
break;
case Phase::Reveal: {
const RevealStep& s = REVEAL_STEPS[reveal_index_];
if (s.clear) {
JD8_ClearScreen(0);
Jd8::clearScreen(0);
}
if (s.wordmark) {
drawWordmark(gfx_);
} else if (s.body_w > 0) {
JD8_Blit(43, 78, gfx_, 43, 155, s.body_w, 45);
Jd8::blit(43, 78, gfx_, 43, 155, s.body_w, 45);
}
if (s.plane_x >= 0) {
JD8_Blit(s.plane_x, 78, gfx_, 274, 155, 27, 45);
Jd8::blit(s.plane_x, 78, gfx_, 274, 155, 27, 45);
}
break;
}
@@ -106,7 +106,7 @@ namespace scenes {
// Wordmark complet fix mentre cicla la paleta — l'últim
// pas del revelat (PAS 15) deixa la pantalla en aquest mateix
// estat, i el vell doIntro no redibuixava durant el cicle.
JD8_ClearScreen(0);
Jd8::clearScreen(0);
drawWordmark(gfx_);
break;
+1 -1
View File
@@ -54,7 +54,7 @@ namespace scenes {
void advancePaletteCycle();
SurfaceHandle gfx_;
JD8_Palette pal_{nullptr}; // propietat transferida a main_palette via SetScreenPalette
Jd8::Palette pal_{nullptr}; // propietat transferida a main_palette via SetScreenPalette
std::unique_ptr<IntroSpritesScene> sprites_scene_;
Phase phase_{Phase::InitialWait};
+70 -70
View File
@@ -55,9 +55,9 @@ namespace {
void drawWordmark(const Uint8* gfx) {
if (Options::game.use_new_logo) {
// Centrat: (320 188) / 2 = 66 (IntroNewLogoScene usa la mateixa x).
JD8_Blit(66, 78, gfx, 60, 158, 188, 28);
Jd8::blit(66, 78, gfx, 60, 158, 188, 28);
} else {
JD8_Blit(43, 78, gfx, 43, 155, 231, 45);
Jd8::blit(43, 78, gfx, 43, 155, 231, 45);
}
}
@@ -79,70 +79,70 @@ namespace {
// =========================================================================
void v0_walk_right(const Uint8* gfx, int i) {
JD8_ClearScreen(0);
Jd8::clearScreen(0);
drawWordmark(gfx);
JD8_BlitCK(i, 150, gfx, fr1[(i / 5) % 13], 0, 15, 15, 0);
Jd8::blitCK(i, 150, gfx, fr1[(i / 5) % 13], 0, 15, 15, 0);
}
void v0_pull_map_right(const Uint8* gfx, int i) {
JD8_ClearScreen(0);
Jd8::clearScreen(0);
drawWordmark(gfx);
JD8_BlitCK(200, 150, gfx, fr3[std::min(i / 5, 10)], 30, 15, 15, 0);
Jd8::blitCK(200, 150, gfx, fr3[std::min(i / 5, 10)], 30, 15, 15, 0);
}
void v0_walk_left_to_80(const Uint8* gfx, int i) {
JD8_ClearScreen(0);
Jd8::clearScreen(0);
drawWordmark(gfx);
JD8_BlitCK(i, 150, gfx, fr2[(i / 5) % 13], 15, 15, 15, 0);
Jd8::blitCK(i, 150, gfx, fr2[(i / 5) % 13], 15, 15, 15, 0);
}
void v0_pull_map_left(const Uint8* gfx, int i) {
JD8_ClearScreen(0);
Jd8::clearScreen(0);
drawWordmark(gfx);
JD8_BlitCK(80, 150, gfx, fr4[std::min(i / 5, 10)], 45, 15, 15, 0);
Jd8::blitCK(80, 150, gfx, fr4[std::min(i / 5, 10)], 45, 15, 15, 0);
}
void v0_momia_left(const Uint8* gfx, int i) {
JD8_ClearScreen(0);
Jd8::clearScreen(0);
drawWordmark(gfx);
JD8_BlitCK(i, 150, gfx, fr6[(i / 5) % 8], 60, 15, 15, 0);
JD8_BlitCK(80, 150, gfx, fr4[10], 45, 15, 15, 0);
Jd8::blitCK(i, 150, gfx, fr6[(i / 5) % 8], 60, 15, 15, 0);
Jd8::blitCK(80, 150, gfx, fr4[10], 45, 15, 15, 0);
}
void v0_turn(const Uint8* gfx, int /*i*/) {
JD8_ClearScreen(0);
Jd8::clearScreen(0);
drawWordmark(gfx);
JD8_BlitCK(80, 150, gfx, fr1[1], 0, 15, 15, 0);
JD8_BlitCK(95, 150, gfx, fr6[4], 60, 15, 15, 0);
JD8_BlitCK(80, 133, gfx, 0, INTERROGANT, 15, 15, 0);
Jd8::blitCK(80, 150, gfx, fr1[1], 0, 15, 15, 0);
Jd8::blitCK(95, 150, gfx, fr6[4], 60, 15, 15, 0);
Jd8::blitCK(80, 133, gfx, 0, INTERROGANT, 15, 15, 0);
}
void v0_jump1(const Uint8* gfx, int i) {
JD8_ClearScreen(0);
Jd8::clearScreen(0);
drawWordmark(gfx);
JD8_BlitCK(80, 150 - ((i % 50) / 5), gfx, fr5[std::min(i / 5, 19)], 45, 15, 15, 0);
JD8_BlitCK(95, 150, gfx, fr6[4], 60, 15, 15, 0);
Jd8::blitCK(80, 150 - ((i % 50) / 5), gfx, fr5[std::min(i / 5, 19)], 45, 15, 15, 0);
Jd8::blitCK(95, 150, gfx, fr6[4], 60, 15, 15, 0);
}
void v0_jump2(const Uint8* gfx, int i) {
JD8_ClearScreen(0);
Jd8::clearScreen(0);
drawWordmark(gfx);
JD8_BlitCK(80, 140 + ((i % 50) / 5), gfx, fr5[std::min(i / 5, 19)], 45, 15, 15, 0);
JD8_BlitCK(95, 150, gfx, fr6[4], 60, 15, 15, 0);
Jd8::blitCK(80, 140 + ((i % 50) / 5), gfx, fr5[std::min(i / 5, 19)], 45, 15, 15, 0);
Jd8::blitCK(95, 150, gfx, fr6[4], 60, 15, 15, 0);
}
void v0_walk_final(const Uint8* gfx, int i) {
JD8_ClearScreen(0);
Jd8::clearScreen(0);
drawWordmark(gfx);
JD8_BlitCK(i, 150, gfx, fr2[(i / 5) % 13], 15, 15, 15, 0);
JD8_BlitCK(95, 150, gfx, fr6[4], 60, 15, 15, 0);
Jd8::blitCK(i, 150, gfx, fr2[(i / 5) % 13], 15, 15, 15, 0);
Jd8::blitCK(95, 150, gfx, fr6[4], 60, 15, 15, 0);
}
void v0_final(const Uint8* gfx, int /*i*/) {
JD8_ClearScreen(0);
Jd8::clearScreen(0);
drawWordmark(gfx);
JD8_BlitCK(95, 150, gfx, fr6[4], 60, 15, 15, 0);
JD8_BlitCK(95, 133, gfx, 0, INTERROGANT, 15, 15, 0);
Jd8::blitCK(95, 150, gfx, fr6[4], 60, 15, 15, 0);
Jd8::blitCK(95, 133, gfx, 0, INTERROGANT, 15, 15, 0);
}
constexpr SpritePhase variant_0[] = {
@@ -164,63 +164,63 @@ namespace {
// =========================================================================
void v1_walk_right(const Uint8* gfx, int i) {
JD8_ClearScreen(0);
Jd8::clearScreen(0);
drawWordmark(gfx);
JD8_BlitCK(200, 155, gfx, 0, CREU, 15, 15, 255);
JD8_BlitCK(i, 150, gfx, fr1[(i / 5) % 13], 0, 15, 15, 255);
Jd8::blitCK(200, 155, gfx, 0, CREU, 15, 15, 255);
Jd8::blitCK(i, 150, gfx, fr1[(i / 5) % 13], 0, 15, 15, 255);
}
void v1_pull_map(const Uint8* gfx, int i) {
JD8_ClearScreen(0);
Jd8::clearScreen(0);
drawWordmark(gfx);
JD8_BlitCK(200, 155, gfx, 0, CREU, 15, 15, 255);
JD8_BlitCK(200, 150, gfx, fr3[std::min(i / 5, 10)], 30, 15, 15, 255);
Jd8::blitCK(200, 155, gfx, 0, CREU, 15, 15, 255);
Jd8::blitCK(200, 150, gfx, fr3[std::min(i / 5, 10)], 30, 15, 15, 255);
}
void v1_interrogant(const Uint8* gfx, int /*i*/) {
JD8_ClearScreen(0);
Jd8::clearScreen(0);
drawWordmark(gfx);
JD8_BlitCK(200, 155, gfx, 0, CREU, 15, 15, 255);
JD8_BlitCK(200, 134, gfx, 0, INTERROGANT, 15, 15, 255);
JD8_BlitCK(200, 150, gfx, fr3[10], 30, 15, 15, 255);
Jd8::blitCK(200, 155, gfx, 0, CREU, 15, 15, 255);
Jd8::blitCK(200, 134, gfx, 0, INTERROGANT, 15, 15, 255);
Jd8::blitCK(200, 150, gfx, fr3[10], 30, 15, 15, 255);
}
void v1_drop_map(const Uint8* gfx, int i) {
JD8_ClearScreen(0);
Jd8::clearScreen(0);
drawWordmark(gfx);
JD8_BlitCK(200, 155, gfx, 0, CREU, 15, 15, 255);
Jd8::blitCK(200, 155, gfx, 0, CREU, 15, 15, 255);
const int idx = std::min(i / 5, 28);
// fr7 té 29 frames dividits en dos grups: paper (idx 0..13, src_y=75)
// i sombra (idx 14..28, src_y=105). El vell feia una branca al bucle.
if (idx <= 13) {
JD8_BlitCK(200, 150, gfx, fr7[idx], 75, 15, 15, 255);
Jd8::blitCK(200, 150, gfx, fr7[idx], 75, 15, 15, 255);
} else {
JD8_BlitCK(200, 150, gfx, fr7[idx], 105, 15, 15, 255);
Jd8::blitCK(200, 150, gfx, fr7[idx], 105, 15, 15, 255);
}
}
void v1_stone_fall(const Uint8* gfx, int i) {
JD8_ClearScreen(0);
Jd8::clearScreen(0);
drawWordmark(gfx);
JD8_BlitCK(200, 155, gfx, 0, CREU, 15, 15, 255);
JD8_BlitCK(200, 150, gfx, fr7[28], 105, 15, 15, 255);
JD8_BlitCK(200, i * 2, gfx, fr8[0], 75, 15, 15, 255);
Jd8::blitCK(200, 155, gfx, 0, CREU, 15, 15, 255);
Jd8::blitCK(200, 150, gfx, fr7[28], 105, 15, 15, 255);
Jd8::blitCK(200, i * 2, gfx, fr8[0], 75, 15, 15, 255);
}
void v1_stone_break(const Uint8* gfx, int i) {
JD8_ClearScreen(0);
Jd8::clearScreen(0);
drawWordmark(gfx);
JD8_BlitCK(200, 155, gfx, 0, CREU, 15, 15, 255);
JD8_BlitCK(200, 150, gfx, fr8[i / 10], 75, 15, 15, 255);
Jd8::blitCK(200, 155, gfx, 0, CREU, 15, 15, 255);
Jd8::blitCK(200, 150, gfx, fr8[i / 10], 75, 15, 15, 255);
}
void v1_final(const Uint8* gfx, int /*i*/) {
JD8_ClearScreen(0);
Jd8::clearScreen(0);
drawWordmark(gfx);
JD8_BlitCK(200, 155, gfx, 0, CREU, 15, 15, 255);
JD8_BlitCK(200, 150, gfx, fr8[1], 75, 15, 15, 255);
JD8_BlitCK(185, 150, gfx, fr8[2], 75, 15, 15, 255);
JD8_BlitCK(215, 150, gfx, fr8[3], 75, 15, 15, 255);
Jd8::blitCK(200, 155, gfx, 0, CREU, 15, 15, 255);
Jd8::blitCK(200, 150, gfx, fr8[1], 75, 15, 15, 255);
Jd8::blitCK(185, 150, gfx, fr8[2], 75, 15, 15, 255);
Jd8::blitCK(215, 150, gfx, fr8[3], 75, 15, 15, 255);
}
constexpr SpritePhase variant_1[] = {
@@ -238,33 +238,33 @@ namespace {
// =========================================================================
void v2_approach(const Uint8* gfx, int i) {
JD8_ClearScreen(0);
Jd8::clearScreen(0);
drawWordmark(gfx);
JD8_BlitCK(i, 150, gfx, fr1[(i / 5) % 13], 0, 15, 15, 255);
JD8_BlitCK(304 - i, 150, gfx, fr6[(i / 10) % 8], 60, 15, 15, 255);
Jd8::blitCK(i, 150, gfx, fr1[(i / 5) % 13], 0, 15, 15, 255);
Jd8::blitCK(304 - i, 150, gfx, fr6[(i / 10) % 8], 60, 15, 15, 255);
}
void v2_still(const Uint8* gfx, int /*i*/) {
JD8_ClearScreen(0);
Jd8::clearScreen(0);
drawWordmark(gfx);
JD8_BlitCK(145, 150, gfx, fr1[1], 0, 15, 15, 255);
JD8_BlitCK(160, 150, gfx, fr6[1], 60, 15, 15, 255);
Jd8::blitCK(145, 150, gfx, fr1[1], 0, 15, 15, 255);
Jd8::blitCK(160, 150, gfx, fr6[1], 60, 15, 15, 255);
}
void v2_horn(const Uint8* gfx, int i) {
JD8_ClearScreen(0);
Jd8::clearScreen(0);
drawWordmark(gfx);
JD8_BlitCK(125, 150, gfx, fr11[(i / 10) % 2], 90, 15, 15, 255);
JD8_BlitCK(145, 150, gfx, fr1[1], 0, 15, 15, 255);
JD8_BlitCK(160, 150, gfx, fr6[1], 60, 15, 15, 255);
Jd8::blitCK(125, 150, gfx, fr11[(i / 10) % 2], 90, 15, 15, 255);
Jd8::blitCK(145, 150, gfx, fr1[1], 0, 15, 15, 255);
Jd8::blitCK(160, 150, gfx, fr6[1], 60, 15, 15, 255);
}
void v2_ball(const Uint8* gfx, int i) {
JD8_ClearScreen(0);
Jd8::clearScreen(0);
drawWordmark(gfx);
JD8_BlitCK(145, 150, gfx, fr9[(i / 10) % 16], 120, 15, 15, 255);
JD8_BlitCK(160, 150, gfx, fr10[(i / 10) % 16], 135, 15, 15, 255);
JD8_BlitCK(125, 150, gfx, fr11[((i / 5) % 4) + 2], 90, 15, 15, 255);
Jd8::blitCK(145, 150, gfx, fr9[(i / 10) % 16], 120, 15, 15, 255);
Jd8::blitCK(160, 150, gfx, fr10[(i / 10) % 16], 135, 15, 15, 255);
Jd8::blitCK(125, 150, gfx, fr11[((i / 5) % 4) + 2], 90, 15, 15, 255);
}
constexpr SpritePhase variant_2[] = {
@@ -330,7 +330,7 @@ namespace scenes {
done_ = false;
// Renderitzem ja el primer frame (step 0 de la primera fase) perquè
// el JD8_Flip del mini-loop del fiber el pinte al primer cicle.
// el Jd8::flip del mini-loop del fiber el pinte al primer cicle.
const SpritePhase* phases = variant_table(variant_);
phases[0].render(gfx_.get(), phase_current_i(phases[0], 0));
}
+16 -16
View File
@@ -14,12 +14,12 @@ namespace scenes {
// Pintat inicial (congelat durant el fade-in de paleta). El loop
// d'animació repintarà tot des de zero en el primer tick de Showing.
JD8_Blit(fondo_);
JD8_BlitCK(100, 25, gfx_, 0, 74, 124, 68, 255); // logo
JD8_BlitCK(130, 100, gfx_, 0, 0, 80, 74, 255); // camell (frame 0)
JD8_BlitCK(0, 150, gfx_, 0, 150, 320, 50, 255); // base "jdes"
Jd8::blit(fondo_);
Jd8::blitCK(100, 25, gfx_, 0, 74, 124, 68, 255); // logo
Jd8::blitCK(130, 100, gfx_, 0, 0, 80, 74, 255); // camell (frame 0)
Jd8::blitCK(0, 150, gfx_, 0, 150, 320, 50, 255); // base "jdes"
JD8_Palette pal = JD8_LoadPalette("gfx/menu2.gif");
Jd8::Palette pal = Jd8::loadPalette("gfx/menu2.gif");
fade_.startFadeTo(pal);
delete[] pal;
@@ -28,32 +28,32 @@ namespace scenes {
void MenuScene::render() {
// Cel estàtic (els primers 100 pixels verticals)
JD8_Blit(0, 0, fondo_, 0, 0, 320, 100);
Jd8::blit(0, 0, fondo_, 0, 0, 320, 100);
// Fondo mòvil (horitzó) amb wrap a 320
JD8_BlitCK(horitzo_, 100, fondo_, 0, 100, 320 - horitzo_, 100, 255);
JD8_BlitCK(0, 100, fondo_, 320 - horitzo_, 100, horitzo_, 100, 255);
Jd8::blitCK(horitzo_, 100, fondo_, 0, 100, 320 - horitzo_, 100, 255);
Jd8::blitCK(0, 100, fondo_, 320 - horitzo_, 100, horitzo_, 100, 255);
// Logo i camell animat
JD8_BlitCK(100, 25, gfx_, 0, 74, 124, 68, 255);
JD8_BlitCK(130, 100, gfx_, camello_.frame() * 80, 0, 80, 74, 255);
Jd8::blitCK(100, 25, gfx_, 0, 74, 124, 68, 255);
Jd8::blitCK(130, 100, gfx_, camello_.frame() * 80, 0, 80, 74, 255);
// Palmeres mòvils amb wrap a 320
JD8_BlitCK(palmeres_, 150, gfx_, 0, 150, 320 - palmeres_, 50, 255);
JD8_BlitCK(0, 150, gfx_, 320 - palmeres_, 150, palmeres_, 50, 255);
Jd8::blitCK(palmeres_, 150, gfx_, 0, 150, 320 - palmeres_, 50, 255);
Jd8::blitCK(0, 150, gfx_, 320 - palmeres_, 150, palmeres_, 50, 255);
// "jdes" estàtic (davant dels scrollers) i versió a la cantonada
JD8_BlitCK(87, 167, gfx_, 127, 124, 150, 24, 255);
JD8_BlitCK(303, 193, gfx_, 305, 143, 15, 5, 255);
Jd8::blitCK(87, 167, gfx_, 127, 124, 150, 24, 255);
Jd8::blitCK(303, 193, gfx_, 305, 143, 15, 5, 255);
// "Polsa tecla" parpallejant. Al vell `contador % 100 > 30` amb
// updateTicks=20 ms, el cicle són 2000 ms amb un llindar de 600 ms:
// amagat els primers 600 ms, visible els següents 1400 ms.
const bool blink_on = (blink_ms_ % 2000) > 600;
if (blink_on) {
JD8_BlitCK(98, 130, gfx_, 161, 92, 127, 9, 255);
Jd8::blitCK(98, 130, gfx_, 161, 92, 127, 9, 255);
if (info::ctx.nou_personatge) {
JD8_BlitCK(68, 141, gfx_, 128, 105, 189, 9, 255);
Jd8::blitCK(68, 141, gfx_, 128, 105, 189, 9, 255);
}
}
}
+3 -3
View File
@@ -15,12 +15,12 @@ namespace scenes {
info::ctx.vida = 5;
gfx_ = SurfaceHandle("gfx/gameover.gif");
JD8_ClearScreen(0);
JD8_Blit(gfx_);
Jd8::clearScreen(0);
Jd8::blit(gfx_);
// PaletteFade en fa una còpia interna via memcpy, així que alliberem
// la paleta temporal immediatament.
JD8_Palette pal = JD8_LoadPalette("gfx/gameover.gif");
Jd8::Palette pal = Jd8::loadPalette("gfx/gameover.gif");
fade_.startFadeTo(pal);
delete[] pal;
+3 -3
View File
@@ -3,12 +3,12 @@
namespace scenes {
void PaletteFade::startFadeOut() {
JD8_FadeStartOut();
Jd8::fadeStartOut();
active_ = true;
}
void PaletteFade::startFadeTo(const Color* target) {
JD8_FadeStartToPal(target);
Jd8::fadeStartToPal(target);
active_ = true;
}
@@ -22,7 +22,7 @@ namespace scenes {
// de 500ms exactes independent del framerate") podem convertir la
// màquina d'estats de jdraw8 a time-based ací sense tocar cap altre
// call site.
if (JD8_FadeTickStep()) {
if (Jd8::fadeTickStep()) {
active_ = false;
}
}
+1 -1
View File
@@ -5,7 +5,7 @@
namespace scenes {
// Embolcall fi damunt de la màquina d'estats de fade de jdraw8
// (`JD8_FadeStart*` / `JD8_FadeTickStep`). Exposa una API time-based
// (`JD8_FadeStart*` / `Jd8::fadeTickStep`). Exposa una API time-based
// però internament avança un pas del fade per cada crida a `tick()`.
// La raó de tindre-ho com a classe a banda: que una escena no puga
// cridar accidentalment a `JD8_FadeOut`/`JD8_FadeToPal` (els shims
+1 -1
View File
@@ -6,7 +6,7 @@
// cert, i llavors consulta `nextState()` per decidir la següent.
//
// Contracte:
// - `tick(delta_ms)` no pot bloquejar ni cridar JD8_Flip — el caller
// - `tick(delta_ms)` no pot bloquejar ni cridar Jd8::flip — el caller
// s'encarrega de fer el flip després del tick.
// - `done()` es consulta just després de cada tick.
// - Els assets són propietat de l'escena (normalment via SurfaceHandle)
+14 -14
View File
@@ -50,7 +50,7 @@ namespace scenes {
fade_.startFadeOut();
gfx_ = SurfaceHandle("gfx/tomba1.gif");
pal_aux_ = JD8_LoadPalette("gfx/tomba1.gif");
pal_aux_ = Jd8::loadPalette("gfx/tomba1.gif");
pal_active_ = new Color[256];
std::memcpy(pal_active_, pal_aux_, 768);
@@ -59,20 +59,20 @@ namespace scenes {
}
void SecretaScene::swapToTomba2() {
JD8_ClearScreen(255);
Jd8::clearScreen(255);
gfx_.reset("gfx/tomba2.gif");
delete[] pal_aux_;
pal_aux_ = JD8_LoadPalette("gfx/tomba2.gif");
pal_aux_ = Jd8::loadPalette("gfx/tomba2.gif");
// pal_active_ continua sent el mateix buffer: només actualitzem
// el seu contingut. main_palette ja apunta ací.
std::memcpy(pal_active_, pal_aux_, 768);
}
void SecretaScene::beginRedPulseSetup() {
JD8_ClearScreen(0);
JD8_SetPaletteColor(254, 12, 11, 11);
JD8_SetPaletteColor(253, 12, 11, 11);
Jd8::clearScreen(0);
Jd8::setPaletteColor(254, 12, 11, 11);
Jd8::setPaletteColor(253, 12, 11, 11);
}
void SecretaScene::beginFinalFade() {
@@ -98,8 +98,8 @@ namespace scenes {
// SetScreenPalette allibera la vella i adopta pal_active_
// — des d'ara main_palette == pal_active_, així que les
// futures escriptures a pal_active_ afecten la pantalla.
JD8_SetScreenPalette(pal_active_);
JD8_ClearScreen(255);
Jd8::setScreenPalette(pal_active_);
Jd8::clearScreen(255);
phase_ = Phase::Tomba1ScrollIn;
phase_acc_ms_ = 0;
}
@@ -110,8 +110,8 @@ namespace scenes {
const int contador = std::min(128, (phase_acc_ms_ / TICK_MS) + 1);
// Dos blits solapats: el primer avança a velocitat completa,
// el segon (contingut de la dreta del src) a meitat (contador>>1).
JD8_Blit(70, 60, gfx_, 0, contador, 178, 70);
JD8_BlitCK(70, 60, gfx_, 178, contador >> 1, 142, 70, 255);
Jd8::blit(70, 60, gfx_, 0, contador, 178, 70);
Jd8::blitCK(70, 60, gfx_, 178, contador >> 1, 142, 70, 255);
if (phase_acc_ms_ >= TOMBA1_SCROLL_MS) {
phase_ = Phase::Tomba1Hold;
phase_acc_ms_ = 0;
@@ -131,7 +131,7 @@ namespace scenes {
case Phase::Tomba2ScrollIn: {
phase_acc_ms_ += delta_ms;
const int contador = std::min(94, (phase_acc_ms_ / TICK_MS) + 1);
JD8_Blit(55, 53, gfx_, 0, 158 - contador, 211, contador);
Jd8::blit(55, 53, gfx_, 0, 158 - contador, 211, contador);
if (phase_acc_ms_ >= TOMBA2_SCROLL_MS) {
phase_ = Phase::Tomba2Hold;
phase_acc_ms_ = 0;
@@ -153,7 +153,7 @@ namespace scenes {
const int contador = std::min(80, (phase_acc_ms_ / TICK_MS) + 1);
// Revelat horitzontal simètric: l'amplada creix 2px per tick
// i el src_x es desplaça a l'esquerra el mateix.
JD8_Blit(80, 68, gfx_, 160 - (contador * 2), 0, contador * 2, 64);
Jd8::blit(80, 68, gfx_, 160 - (contador * 2), 0, contador * 2, 64);
if (phase_acc_ms_ >= TOMBA2_REVEAL_MS) {
phase_ = Phase::Tomba2RevealHold;
phase_acc_ms_ = 0;
@@ -174,8 +174,8 @@ namespace scenes {
const int contador = std::min(51, phase_acc_ms_ / TICK_MS);
// Anima el canal R dels índexs 254 i 253 (aquest a la meitat
// de brillantor). Va de (12,11,11) fins a (63,11,11) / (31,11,11).
JD8_SetPaletteColor(254, contador + 12, 11, 11);
JD8_SetPaletteColor(253, (contador + 12) >> 1, 11, 11);
Jd8::setPaletteColor(254, contador + 12, 11, 11);
Jd8::setPaletteColor(253, (contador + 12) >> 1, 11, 11);
if (phase_acc_ms_ >= RED_PULSE_MS) {
phase_ = Phase::RedPulseHold;
phase_acc_ms_ = 0;
+2 -2
View File
@@ -56,8 +56,8 @@ namespace scenes {
void beginFinalFade();
SurfaceHandle gfx_;
JD8_Palette pal_aux_{nullptr};
JD8_Palette pal_active_{nullptr}; // propietat transferida a main_palette
Jd8::Palette pal_aux_{nullptr};
Jd8::Palette pal_active_{nullptr}; // propietat transferida a main_palette
PaletteFade fade_;
Phase phase_{Phase::InitialFadeOut};
+5 -5
View File
@@ -48,7 +48,7 @@ namespace scenes {
}
gfx_ = SurfaceHandle(arxiu);
pal_aux_ = JD8_LoadPalette(arxiu);
pal_aux_ = Jd8::loadPalette(arxiu);
// Còpia editable de la paleta. `pal_active_` comparteix memòria amb
// main_palette després del SetScreenPalette — modificar-la modifica
@@ -56,9 +56,9 @@ namespace scenes {
// restaurar després de cada fade-out intermedi.
pal_active_ = new Color[256];
std::memcpy(pal_active_, pal_aux_, 768);
JD8_SetScreenPalette(pal_active_);
Jd8::setScreenPalette(pal_active_);
JD8_ClearScreen(BG_COLOR_INDEX);
Jd8::clearScreen(BG_COLOR_INDEX);
phase_ = Phase::Slide1Enter;
phase_acc_ms_ = 0;
@@ -83,7 +83,7 @@ namespace scenes {
}
if (w > 0) {
JD8_Blit(dst_x, SLIDE_Y, gfx_, src_x, src_y, w, SLIDE_H);
Jd8::blit(dst_x, SLIDE_Y, gfx_, src_x, src_y, w, SLIDE_H);
}
}
@@ -169,7 +169,7 @@ namespace scenes {
fade_.tick(delta_ms);
if (fade_.done()) {
restorePalette();
JD8_ClearScreen(BG_COLOR_INDEX);
Jd8::clearScreen(BG_COLOR_INDEX);
if (phase_ == Phase::FadeOut1) {
phase_ = Phase::Slide2Enter;
} else {
+2 -2
View File
@@ -67,8 +67,8 @@ namespace scenes {
void beginFinalFade();
SurfaceHandle gfx_;
JD8_Palette pal_aux_{nullptr}; // còpia "neta" que preservem
JD8_Palette pal_active_{nullptr}; // propietat transferida a main_palette
Jd8::Palette pal_aux_{nullptr}; // còpia "neta" que preservem
Jd8::Palette pal_active_{nullptr}; // propietat transferida a main_palette
PaletteFade fade_;
Phase phase_{Phase::Slide1Enter};
+9 -9
View File
@@ -3,11 +3,11 @@
namespace scenes {
SurfaceHandle::SurfaceHandle(const char* file)
: surface_(JD8_LoadSurface(file)) {}
: surface_(Jd8::loadSurface(file)) {}
SurfaceHandle::~SurfaceHandle() {
if (surface_ != nullptr) {
JD8_FreeSurface(surface_);
Jd8::freeSurface(surface_);
}
}
@@ -19,7 +19,7 @@ namespace scenes {
auto SurfaceHandle::operator=(SurfaceHandle&& other) noexcept -> SurfaceHandle& {
if (this != &other) {
if (surface_ != nullptr) {
JD8_FreeSurface(surface_);
Jd8::freeSurface(surface_);
}
surface_ = other.surface_;
other.surface_ = nullptr;
@@ -29,20 +29,20 @@ namespace scenes {
void SurfaceHandle::reset(const char* file) {
if (surface_ != nullptr) {
JD8_FreeSurface(surface_);
Jd8::freeSurface(surface_);
}
surface_ = (file != nullptr) ? JD8_LoadSurface(file) : nullptr;
surface_ = (file != nullptr) ? Jd8::loadSurface(file) : nullptr;
}
void SurfaceHandle::adopt(JD8_Surface raw) {
void SurfaceHandle::adopt(Jd8::Surface raw) {
if (surface_ != nullptr) {
JD8_FreeSurface(surface_);
Jd8::freeSurface(surface_);
}
surface_ = raw;
}
auto SurfaceHandle::release() -> JD8_Surface {
JD8_Surface r = surface_;
auto SurfaceHandle::release() -> Jd8::Surface {
Jd8::Surface r = surface_;
surface_ = nullptr;
return r;
}
+12 -12
View File
@@ -4,10 +4,10 @@
namespace scenes {
// Wrapper RAII damunt de `JD8_Surface`. Allibera automàticament amb
// `JD8_FreeSurface` al destructor. Move-only per evitar dobles alliberaments.
// Converteix implícitament a `JD8_Surface` per a poder passar-lo
// directament a `JD8_Blit*` sense haver de cridar `.get()`.
// Wrapper RAII damunt de `Jd8::Surface`. Allibera automàticament amb
// `Jd8::freeSurface` al destructor. Move-only per evitar dobles alliberaments.
// Converteix implícitament a `Jd8::Surface` per a poder passar-lo
// directament a `Jd8::blit*` sense haver de cridar `.get()`.
class SurfaceHandle {
public:
SurfaceHandle() = default;
@@ -25,25 +25,25 @@ namespace scenes {
// (p.ex. doSecreta que passa de tomba1 a tomba2).
void reset(const char* file);
// Adopta una surface ja creada (p.ex. amb JD8_NewSurface). Pren ownership
// Adopta una surface ja creada (p.ex. amb Jd8::newSurface). Pren ownership
// — la surface adoptada s'allibera al destructor o al següent reset/adopt.
void adopt(JD8_Surface raw);
void adopt(Jd8::Surface raw);
// Allibera ownership sense destruir la surface. Retorna el pointer cru;
// el caller passa a ser responsable d'alliberar-lo (o de passar-lo a un
// altre propietari). Usat quan una escena delega a codi legacy que
// també allibera la mateixa surface — cal "soltar" el ownership per
// evitar double free.
[[nodiscard]] auto release() -> JD8_Surface;
[[nodiscard]] auto release() -> Jd8::Surface;
// Conversió implícita per al confort d'ús: JD8_Blit(handle)
// en lloc de JD8_Blit(handle.get()).
operator JD8_Surface() const { return surface_; }
[[nodiscard]] auto get() const -> JD8_Surface { return surface_; }
// Conversió implícita per al confort d'ús: Jd8::blit(handle)
// en lloc de Jd8::blit(handle.get()).
operator Jd8::Surface() const { return surface_; }
[[nodiscard]] auto get() const -> Jd8::Surface { return surface_; }
[[nodiscard]] auto valid() const -> bool { return surface_ != nullptr; }
private:
JD8_Surface surface_{nullptr};
Jd8::Surface surface_{nullptr};
};
} // namespace scenes
+1 -1
View File
@@ -9,7 +9,7 @@ namespace scenes {
// ms i un callback. Exemple d'ús:
//
// timeline_
// .once([this] { JD8_ClearScreen(0); fade_.startFadeTo(pal); })
// .once([this] { Jd8::clearScreen(0); fade_.startFadeTo(pal); })
// .step(5000) // espera pura
// .step(1000, [this](float p) { /*...*/ }) // animat amb progress
// .once([this] { Ja::fadeOutMusic(250); });
+2 -2
View File
@@ -1,9 +1,9 @@
#include "game/sprite.hpp"
Sprite::Sprite(JD8_Surface gfx)
Sprite::Sprite(Jd8::Surface gfx)
: gfx(gfx) {}
void Sprite::draw() {
const Frame& f = entitat.frames[entitat.animacions[o].frames[cur_frame]];
JD8_BlitCK(x, y, gfx, f.x, f.y, f.w, f.h, 255);
Jd8::blitCK(x, y, gfx, f.x, f.y, f.w, f.h, 255);
}
+2 -2
View File
@@ -22,7 +22,7 @@ struct Entitat {
class Sprite {
public:
explicit Sprite(JD8_Surface gfx);
explicit Sprite(Jd8::Surface gfx);
virtual ~Sprite() = default;
virtual void draw();
@@ -34,6 +34,6 @@ class Sprite {
Uint16 o = 0;
protected:
JD8_Surface gfx;
Jd8::Surface gfx;
Uint8 cycles_per_frame = 1;
};
+2 -2
View File
@@ -91,7 +91,7 @@ auto SDL_AppInit(void** /*appstate*/, int /*argc*/, char* /*argv*/[]) -> SDL_App
JG_Init();
Screen::init();
JD8_Init();
Jd8::init();
Audio::init(); // crida internament Ja::init i aplica Options::audio
Overlay::init();
Menu::init();
@@ -147,7 +147,7 @@ void SDL_AppQuit(void* /*appstate*/, SDL_AppResult /*result*/) {
Resource::Cache::destroy();
Resource::List::destroy();
Audio::destroy(); // el destructor del singleton crida Ja::quit
JD8_Quit();
Jd8::quit();
Screen::destroy();
JG_Finalize();
ResourceHelper::shutdownResourceSystem();