Skip to content

Free games for graphing calculators: NumWorks, TI-Nspire CX, Casio fx-CG50 and soon TI-84 Plus CE. Balatro, Celeste, Hollow Knight, Minecraft and more.

Merge remote-tracking branch 'origin/main' into pvz-v2

Mason363061524e9d8d2
diff --cc games/pvz/src/gfx.c
index 38b2160e,87299bab..7041b429
--- a/games/pvz/src/gfx.c
+++ b/games/pvz/src/gfx.c
@@@ -314,31 -302,12 +314,31 @@@ static void blit_frame(const Item *it,
int ya = imax(y0, oy), yb = imin(y1, oy + f.h);
if (ya >= yb) return;
const uint8_t *e, *p = row_at(&f, bpp, ya - oy, &e);
+ /* PVZ_SHARED_RLE_ROWS_V1: streaming cursor avoids quadratic row rescans. */
+ const uint8_t *cursor = NULL;
+ if (bpp == 4 && f.shared_rows) {
+ cursor = f.rows + f.h;
+ for (int r = 0; r < ya - oy; r++) cursor += f.rows[r] == 255 ? 4 : f.rows[r];
+ }
for (int y = ya; y < yb; y++) {
int r = y - oy;
- if (bpp == 4) e = p + f.rows[r];
- else {
+ if (bpp == 4) {
+ if (f.shared_rows) {
+ int length = f.rows[r];
+ if (length == 255) {
+ uint32_t ref = rd32(cursor);
+ p = pvz_bin + (ref & 0x00ffffffu);
+ e = p + (ref >> 24);
+ cursor += 4;
+ } else {
+ p = cursor;
+ e = p + length;
+ cursor += length;
+ }
+ } else e = p + f.rows[r];
+ } else {
p = f.rows + rd16(f.rows + 2 * r);
- e = r + 1 < f.h ? f.rows + rd16(f.rows + 2 * r + 2) : p + 4 * f.w + 8;
+ e = r + 1 < f.h ? f.rows + rd16(f.rows + 2 * r + 2) : f.end; /* (the last row: up to the next frame) */
}
uint16_t *out = band + (y % GFX_BAND) * SCREEN_W;
int x = 0, w = f.w;
diff --cc games/pvz/src/res.h
index bd762807,b5b11592..8c5fb2fd
--- a/games/pvz/src/res.h
+++ b/games/pvz/src/res.h
@@@ -32,14 -31,13 +32,15 @@@ int anim_frame_at(int a, uint32_t t)
typedef struct {
int16_t x, y; /* top-left from the anchor */
uint16_t w, h;
- const uint8_t *rows;
+ const uint8_t *rows, *end; /* end: past its last row (data.bin keeps the frames in order, then the palettes) */
+ uint8_t shared_rows;
} Frame;
static inline Frame frame_info(int f) {
const uint8_t *p = table(T_FRAMES) + 12 * f;
+ int n = (int)rd32(pvz_bin + 32); /* (the header: 6 tables, the animations, the frames) */
- return (Frame){rds16(p), rds16(p + 2), rd16(p + 4), rd16(p + 6), pvz_bin + rd32(p + 8),
- f + 1 < n ? pvz_bin + rd32(p + 20) : table(T_PALS)};
+ uint32_t off = rd32(p + 8);
- return (Frame){rds16(p), rds16(p + 2), rd16(p + 4), rd16(p + 6),
- pvz_bin + (off & 0x7fffffffu), (uint8_t)(off >> 31)};
++ return (Frame){rds16(p), rds16(p + 2), rd16(p + 4), rd16(p + 6), pvz_bin + (off & 0x7fffffffu),
++ f + 1 < n ? pvz_bin + (rd32(p + 20) & 0x7fffffffu) : table(T_PALS), (uint8_t)(off >> 31)};
}
/* a palette: its colours (RGB565, aligned) */
static inline const uint16_t *pal_colors(int p, int *n) {