refactor: JD8_* a namespace Jd8::
This commit is contained in:
+39
-39
@@ -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`).
|
||||
|
||||
Reference in New Issue
Block a user