Skip to content

Commit

Permalink
Fix tileset leakage
Browse files Browse the repository at this point in the history
Merge pull request #83 from haroldo-ok/tileset-leakage
This fixes #82
  • Loading branch information
haroldo-ok authored Nov 27, 2022
2 parents 21bcbc4 + dfc4f9f commit b9fd7cc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
27 changes: 22 additions & 5 deletions base/src/vn_engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ struct {
char** lines;
} msgLines;

struct {
u16 baseTileNumber;
Image *image;
} backgroundInfo;

char *bufferWrappedTextLine(char *s, int x, int y, int w) {
char *o, ch;
int tx = x;
Expand Down Expand Up @@ -193,15 +198,18 @@ void VN_init() {

SPR_init(0, 0, 0);

backgroundInfo.image = NULL;
backgroundInfo.baseTileNumber = 256;

imageInfo.x = 0;
imageInfo.y = 0;
imageInfo.tileNumber = 256;
imageInfo.tileNumber = backgroundInfo.baseTileNumber;

XGM_setLoopNumber(-1);
XGM_setForceDelayDMA(TRUE);

VDP_setTextPalette(TEXT_PAL);
VDP_drawText("choice4genesis v0.11.1", 17, 27);
VDP_drawText("choice4genesis v0.11.2", 17, 27);
}


Expand All @@ -216,7 +224,8 @@ void VN_showImage(const Image *image, VDPPlane plane, u16 palNum, u16 x, u16 y)
}

void VN_background(const Image *image) {
imageInfo.tileNumber = 256;
imageInfo.tileNumber = backgroundInfo.baseTileNumber;
backgroundInfo.image = image;
VN_showImage(image, BG_B, BACKGROUND_PAL, 0, 0);
}

Expand Down Expand Up @@ -321,8 +330,16 @@ void VN_flush(const u8 flags) {
}

void VN_clear(const u8 flags) {
if (flags & LAYER_FOREGROUND) VDP_clearPlane(BG_A, TRUE);
if (flags & LAYER_BACKGROUND) VDP_clearPlane(BG_B, TRUE);
if (flags & LAYER_FOREGROUND) {
VDP_clearPlane(BG_A, TRUE);
imageInfo.tileNumber = backgroundInfo.baseTileNumber +
(backgroundInfo.image ? backgroundInfo.image->tileset->numTile : 0);
}
if (flags & LAYER_BACKGROUND) {
VDP_clearPlane(BG_B, TRUE);
imageInfo.tileNumber = backgroundInfo.baseTileNumber;
backgroundInfo.image = NULL;
}
if (flags & LAYER_WINDOW) VN_clearWindow();
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "choice4genesis",
"version": "0.11.1",
"version": "0.11.2",
"description": "A ChoiceScript clone that generates SGDK-compatible C source for the Sega Genesis ",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit b9fd7cc

Please sign in to comment.