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.

NumBlocks CE: the title at once, taps between pictures, the inventory key closes it

Mason3630eda4fe2a1e3
diff --git a/games/numblocks/ce/host/plat_host.c b/games/numblocks/ce/host/plat_host.c
index 5afb6c85..5ffafa43 100644
--- a/games/numblocks/ce/host/plat_host.c
+++ b/games/numblocks/ce/host/plat_host.c
@@ -91,6 +91,7 @@ void plat_exit(void) {
void plat_palette(int first, int n, const uint8_t *rgb) { memcpy(pal + first * 3, rgb, (size_t)n * 3); }
+void plat_poll(void) {}
uint32_t plat_keys(void) {
uint32_t k = 0;
for (int i = 0; i < nholds; i++)
diff --git a/games/numblocks/ce/src/draw.c b/games/numblocks/ce/src/draw.c
index 0b6c4012..d98ae278 100644
--- a/games/numblocks/ce/src/draw.c
+++ b/games/numblocks/ce/src/draw.c
@@ -28,6 +28,16 @@ void fill(int x, int y, int w, int h, uint8_t c) {
for (int r = 0; r < h; r++) memset(cv.p + (y + r) * cv.stride + x, c, (size_t)w);
}
+/* w x h pixels of a buffer (sw a row) to (x, y) */
+void blit(const uint8_t *src, int sw, int x, int y, int w, int h) {
+ for (int r = 0; r < h; r++, src += sw) {
+ uint8_t *dr = row_at(y + r);
+ if (!dr) continue;
+ int a = x > x0 ? x : x0, b = x + w < x1 ? x + w : x1;
+ if (b > a) memcpy(dr + a, src + (a - x), (size_t)(b - a));
+ }
+}
+
/* a darker colour: Minecraft's text shadow is a quarter as bright */
uint8_t dark(uint8_t c, int level) { return shade_cm[level][c]; }
diff --git a/games/numblocks/ce/src/draw.h b/games/numblocks/ce/src/draw.h
index eb6e0ddf..9b3f95e9 100644
--- a/games/numblocks/ce/src/draw.h
+++ b/games/numblocks/ce/src/draw.h
@@ -18,6 +18,7 @@ enum {
};
void fill(int x, int y, int w, int h, uint8_t c);
+void blit(const uint8_t *src, int sw, int x, int y, int w, int h); /* a buffer's w x h pixels (sw a row) to (x, y) */
uint8_t dark(uint8_t c, int level);
void text_plain(int x, int y, const char *s, uint8_t c);
void text_center(int cx, int y, const char *s, uint8_t c);
diff --git a/games/numblocks/ce/src/gui.c b/games/numblocks/ce/src/gui.c
index 69a5c2e2..19c8b6c4 100644
--- a/games/numblocks/ce/src/gui.c
+++ b/games/numblocks/ce/src/gui.c
@@ -6,6 +6,7 @@
* half or puts one (a right click), y= with 2nd moves a whole stack across (a shift click), clear closes.
* A screen is drawn in bands of the 3D view's buffer, then copied to the screen: nothing flickers. */
#include "nb.h"
+#include "rs.h"
#include "draw.h"
int gui = GUI_NONE, menu_action;
@@ -39,7 +40,9 @@ static void offscreen(int x, int y, int w, int h, void (*fn)(void)) {
/* darkens what is on the screen (Minecraft's grey veil over the world behind a screen) */
static void veil(int level) {
- for (unsigned i = 0; i < SCREEN_W * SCREEN_H; i++) scr[i] = shade_cm[level][scr[i]];
+ /* (a row of 256 at a time, through the shade row, in assembly) */
+ const uint8_t *row = render_veil_row((uint8_t)level);
+ for (unsigned i = 0; i < SCREEN_W * SCREEN_H; i += 256) rs_shade(scr + i, row);
}
void gui_message(const char *s) {
@@ -240,8 +243,17 @@ static void layout(void) {
panel_x = (SCREEN_W - panel_w) / 2, panel_y = (SCREEN_H - panel_h) / 2;
}
+/* the darkened world where a container's names go (above its panel), kept while it is open to be put back under
+ * the next name (in the HUD's layer: not shown then) */
+#define STRIP_H 14
+static void strip_keep(void) {
+ int x = panel_x - 2, w = panel_w + 4, y = panel_y - STRIP_H;
+ for (int r = 0; r < STRIP_H; r++) memcpy(hud_layer + r * w, scr + (y + r) * SCREEN_W + x, (size_t)w);
+}
+
static void draw_panel(void) {
int px = panel_x, py = panel_y;
+ blit(hud_layer, panel_w + 4, px - 2, py - STRIP_H, panel_w + 4, STRIP_H);
sprite(panel_sprite, px, py);
if (gui != GUI_CREATIVE) sprite(SP_INV_BOTTOM, px, py + (gui == GUI_CHEST ? 80 : 79));
if (gui == GUI_INVENTORY) {
@@ -739,7 +751,7 @@ void gui_draw(void) {
if (full) {
/* the world behind a screen, darkened (Minecraft's grey veil; red-brown when you died) */
if (over_world && gui != GUI_TITLE) veil(gui == GUI_DEATH ? 12 : 14);
- if (container) offscreen(panel_x - 2, panel_y - 14, panel_w + 4, panel_h + 16, draw_panel_off);
+ if (container) strip_keep(), offscreen(panel_x - 2, panel_y - 14, panel_w + 4, panel_h + 16, draw_panel_off);
else offscreen(0, 0, SCREEN_W, SCREEN_H, draw_menu_off);
} else if (container) offscreen(panel_x - 2, panel_y - 14, panel_w + 4, panel_h + 16, draw_panel_off);
else if (over_world) offscreen(0, 0, SCREEN_W, SCREEN_H, draw_buttons_off);
diff --git a/games/numblocks/ce/src/main.c b/games/numblocks/ce/src/main.c
index 46a3d443..5ff0e384 100644
--- a/games/numblocks/ce/src/main.c
+++ b/games/numblocks/ce/src/main.c
@@ -27,10 +27,27 @@ static int look_held;
#define TITLE_SEED 20151008u /* the title's world */
+static void loading(const char *what) {
+ canvas_screen();
+ dirt_background(0, SCREEN_H);
+ text_center(SCREEN_W / 2, SCREEN_H / 2 - 4, what, C_WHITE);
+ plat_frame();
+}
+
static bool backdrop_ok;
static void title_backdrop(void) {
- /* the title's world: a view over the land, the same each time */
+ /* the title's world: a view over the land, the same each time (kept as a picture, NBCETTL, once made) */
backdrop_ok = true;
+ world_time = 3000;
+ unsigned len;
+ const uint8_t *pic = plat_load("NBCETTL", &len);
+ if (pic && len == RW * RH + RH) {
+ render_sky_palette();
+ render_picture(pic);
+ compose(false, false);
+ return;
+ }
+ loading("");
world_new(TITLE_SEED);
int x, z;
gen_spawn(&x, &z);
@@ -39,9 +56,9 @@ static void title_backdrop(void) {
world_center(x, 40, z, true);
pl.x = (fx)x * FX1 + FX1 / 2, pl.z = (fx)z * FX1 + FX1 / 2;
pl.y = (fx)world_top(x, z) * FX1 + FX1 * 2;
- world_time = 3000;
render_sky_palette();
render_title(0x3000);
+ plat_save("NBCETTL", rbuf, RW * RH, render_sky(), RH);
compose(false, false);
}
@@ -83,12 +100,6 @@ void game_save_quit(void) {
if (in_game) save_world();
}
-static void loading(const char *what) {
- canvas_screen();
- dirt_background(0, SCREEN_H);
- text_center(SCREEN_W / 2, SCREEN_H / 2 - 4, what, C_WHITE);
- plat_frame();
-}
static void act(void) {
int a = menu_action;
@@ -163,7 +174,7 @@ static void play(uint32_t keys, uint32_t pressed) {
if (tick_acc > 200) tick_acc = 0;
world_center(FXI(pl.x), FXI(pl.y) + 1, FXI(pl.z), false);
/* a row a picture, more when the view would see past them */
- for (int k = 0; world_busy() && (!k || world_behind()); k++) world_step();
+ for (int k = 0; world_busy() && (!k || world_behind()); k++) world_step(), plat_poll();
if (gui == GUI_NONE) {
if (pressed & K_INV) {
gui_open(pl.mode ? GUI_CREATIVE : GUI_INVENTORY);
@@ -174,6 +185,7 @@ static void play(uint32_t keys, uint32_t pressed) {
return;
}
render_frame();
+ plat_poll();
hud_draw();
compose(true, true);
}
@@ -239,6 +251,22 @@ int main(void) {
LAP("world");
render_sky_palette();
LAP("sky");
+#if NB_BENCH == 8
+ {
+ /* a screen opened over the world: the creative inventory */
+ in_game = true, gui = GUI_NONE;
+ pl.mode = 1;
+ render_frame();
+ compose(true, true);
+ LAP("frame");
+ gui_open(GUI_CREATIVE);
+ LAP("open");
+ gui_draw();
+ LAP("draw");
+ plat_save("NBBENCH", out, (unsigned)n, 0, 0);
+ plat_exit();
+ }
+#endif
#if NB_BENCH == 7
{
/* one picture, as the computer build makes it (to compare) */
@@ -342,7 +370,7 @@ int main(void) {
}
break;
}
- if (gui != GUI_NONE) gui_input(keys, pressed);
+ if (gui != GUI_NONE) gui_input(keys, pressed), pressed = 0; /* (a press a screen took: not the game's too) */
if (menu_action) act();
if (in_game) play(keys, pressed);
/* back on the title from another menu: its world behind it again */
diff --git a/games/numblocks/ce/src/nb.h b/games/numblocks/ce/src/nb.h
index 2833d004..a8876a5d 100644
--- a/games/numblocks/ce/src/nb.h
+++ b/games/numblocks/ce/src/nb.h
@@ -109,6 +109,9 @@ extern uint8_t *rbuf; /* the picture, RW x RH */
void render_init(void);
void render_frame(void); /* from the player's eyes */
void render_title(uint16_t yaw); /* the title's backdrop: the world turning */
+void render_picture(const uint8_t *p); /* rbuf and the sky's rows as render_title left them, again */
+const uint8_t *render_sky(void); /* the sky's rows (RH) */
+const uint8_t *render_veil_row(uint8_t level); /* shade row level with the sky's colours darkened too */
void render_show(bool hud); /* the picture onto the screen at 2x, the sky in it (and the HUD) */
void render_sky_palette(void); /* the sky's colours and the light, for the time of day */
extern uint32_t world_time; /* ticks: 24000 a day, 0 sunrise */
@@ -177,7 +180,6 @@ enum {
#define K_SLOT(n) ((uint32_t)K_SLOT1 << (n))
#define K_OK K_ATTACK /* 2nd: OK in screens */
#define K_ESC K_USE /* clear: back in screens */
-uint32_t keys_now(void);
int rnd(int n);
void game_save_quit(void);
void options_save(void);
diff --git a/games/numblocks/ce/src/plat.h b/games/numblocks/ce/src/plat.h
index 6125ed86..20899d5b 100644
--- a/games/numblocks/ce/src/plat.h
+++ b/games/numblocks/ce/src/plat.h
@@ -11,7 +11,8 @@ extern uint8_t *scr; /* the screen shown */
void plat_init(void);
void plat_exit(void);
void plat_palette(int first, int n, const uint8_t *rgb); /* entries first.., 3 bytes each */
-uint32_t plat_keys(void); /* the keys held (K_*) */
+uint32_t plat_keys(void); /* the keys held (K_*), and those pressed since the last call */
+void plat_poll(void); /* (the keys looked at while a picture is made: plat_keys has them) */
uint32_t plat_ms(void);
void plat_frame(void); /* a picture is done (the computer shows or keeps it) */
uint8_t *plat_spare(void); /* 76800 bytes of the machine's own (the CE: the second half of its screen memory) */
diff --git a/games/numblocks/ce/src/plat_ce.c b/games/numblocks/ce/src/plat_ce.c
index 59c51beb..c075f454 100644
--- a/games/numblocks/ce/src/plat_ce.c
+++ b/games/numblocks/ce/src/plat_ce.c
@@ -83,7 +83,17 @@ void plat_palette(int first, int n, const uint8_t *rgb) {
}
}
+static uint32_t read_keys(void);
+/* keys pressed while a picture is made (a tap shorter than a picture still counts) */
+static uint32_t latch;
+void plat_poll(void) { latch |= read_keys(); }
uint32_t plat_keys(void) {
+ uint32_t k = read_keys() | latch;
+ latch = 0;
+ return k;
+}
+
+static uint32_t read_keys(void) {
/* (keypadc scans on its own in continuous mode) */
uint32_t k = 0;
uint8_t g1 = kb_Data[1], g2 = kb_Data[2], g3 = kb_Data[3], g4 = kb_Data[4], g5 = kb_Data[5], g6 = kb_Data[6],
diff --git a/games/numblocks/ce/src/render.c b/games/numblocks/ce/src/render.c
index 23714c3f..3b841961 100644
--- a/games/numblocks/ce/src/render.c
+++ b/games/numblocks/ce/src/render.c
@@ -769,6 +769,26 @@ void render_frame(void) {
hand();
}
+/* shade row level, the sky's colours (1..15) darkened too: a 256-byte aligned row (the screens' veil) */
+const uint8_t *render_veil_row(uint8_t level) {
+ uint8_t *row = crack_tex; /* (free while no block is being mined) */
+ crack_for = -1;
+ memcpy(row, page(shade_ram, level), 256);
+ for (int i = 1; i < FIRST_STATIC; i++) {
+ uint8_t k[3];
+ for (int j = 0; j < 3; j++) k[j] = (uint8_t)(fog_rgb[j] + (sky_rgb[j] - fog_rgb[j]) * (i - 1) / 14);
+ row[i] = row[pal_cube[cube_of[k[0]] << 8 | cube_of[k[1]] << 4 | cube_of[k[2]]]];
+ }
+ return row;
+}
+
+/* a picture kept (render_title's, rbuf then the sky's rows) shown again; the sky's rows */
+void render_picture(const uint8_t *p) {
+ memcpy(rbuf, p, RW * RH);
+ memcpy(sky_row, p + RW * RH, RH);
+}
+const uint8_t *render_sky(void) { return sky_row; }
+
void render_title(uint16_t yaw) {
crack_stage = -1;
frame_from(pl.x, pl.y + FX1 * 162 / 100, pl.z, yaw, 1200);
diff --git a/games/numblocks/ce/src/rs.c b/games/numblocks/ce/src/rs.c
index 5e196383..e4e5ddb1 100644
--- a/games/numblocks/ce/src/rs.c
+++ b/games/numblocks/ce/src/rs.c
@@ -21,7 +21,12 @@ uint8_t RS(rs_hidden)(int x, int y, int z, int r);
int RS(rs_code)(int x, int y, int z);
void RS(rs_compose)(uint8_t *dst, const uint8_t *a, const uint8_t *f);
int RS(rs_lerp)(int a, int b, int f);
+void RS(rs_shade)(uint8_t *p, const uint8_t *row);
void RS(rs_expand)(const uint8_t *src, uint8_t *dst, const uint8_t *sky, const uint8_t *hud);
+void RS(rs_shade)(uint8_t *p, const uint8_t *row) {
+ for (int i = 0; i < 256; i++) p[i] = row[p[i]];
+}
+
int RS(rs_lerp)(int a, int b, int f) { return a + (((b - a) * f) >> 8); }
void RS(rs_compose)(uint8_t *dst, const uint8_t *a, const uint8_t *f) {
diff --git a/games/numblocks/ce/src/rs.h b/games/numblocks/ce/src/rs.h
index a6eae783..9634058a 100644
--- a/games/numblocks/ce/src/rs.h
+++ b/games/numblocks/ce/src/rs.h
@@ -23,6 +23,8 @@ uint8_t rs_hidden(int x, int y, int z, int r);
int rs_code(int x, int y, int z);
/* dst[i] = f[a[i]] for the 256 bytes, all three 256-byte aligned */
void rs_compose(uint8_t *dst, const uint8_t *a, const uint8_t *f);
+/* p[i] = row[p[i]] for 256 bytes, row 256-byte aligned */
+void rs_shade(uint8_t *p, const uint8_t *row);
/* a + floor((b - a) f / 256), a and b 0..255, f 0..256 */
int rs_lerp(int a, int b, int f);
/* the 160 x 120 picture to the screen at 2x, 0s as the row's sky colour (sky[y]); from screen row 180 on, the HUD's
diff --git a/games/numblocks/ce/src/rs.s b/games/numblocks/ce/src/rs.s
index 9b7c2e35..e324a9c7 100644
--- a/games/numblocks/ce/src/rs.s
+++ b/games/numblocks/ce/src/rs.s
@@ -1688,6 +1688,7 @@ _rs_quad:
ld (q_V), hl
jp .Lq_col
.Lq_rowend:
+ call _plat_poll ; (a key tapped while the picture is made)
; the next row out along x
ld a, (q_a)
inc a
@@ -2035,8 +2036,8 @@ nb_z:
ret
; ------------------------------------------------------------------------------------------------- w_expose
-; void w_expose(void): a window column's cells with a face to draw into xp_out (4 bytes, bit y & 31), from its cell
-; at the window's bottom (xp_p, slot xp_ys) up; a face shows unless what is next to it is opaque, the same block or
+; void w_expose(void): a window column's cells with a face to draw, levels xp_k0 to xp_k1 - 1 up from the window's
+; bottom (from the cell xp_p, slot xp_ys), into xp_out (4 bytes, bit y & 31, the other levels' kept); a face shows unless what is next to it is opaque, the same block or
; both are liquids; plants and torches always; past the window: below it as if solid, above air; the columns
; around it at xp_ox0.. (bits of xp_sides: 1 -x, 2 +x, 4 -z, 8 +z inside the window) (world.c)
.section .text._w_expose
@@ -2049,17 +2050,18 @@ nb_z:
_w_expose:
push ix
ld ix, (_xp_p)
- xor a, a
+ ld a, (_xp_k0)
ld (xp_k), a
- ld hl, xp_m
- ld (hl), a
- inc hl
- ld (hl), a
- inc hl
- ld (hl), a
- inc hl
- ld (hl), a
+ ld hl, (_xp_out) ; (the column's other levels kept)
+ ld de, xp_m
+ ld bc, 4
+ ldir
.Lxp_cell:
+ ; (this level's bit cleared first)
+ call xp_bit
+ cpl
+ and a, (hl)
+ ld (hl), a
ld a, (_xp_ys)
cp a, 31
ld de, 1024
@@ -2143,25 +2145,7 @@ _w_expose:
call xp_shows
jr z, .Lxp_next
.Lxp_show:
- ld a, (_xp_ys)
- ld c, a
- rrca
- rrca
- rrca
- and a, 3
- ld hl, xp_m
- ld de, 0
- ld e, a
- add hl, de
- ld a, c
- and a, 7
- ld b, a
- ld a, 1
- jr z, .Lxp_bit
-.Lxp_sh:
- add a, a
- djnz .Lxp_sh
-.Lxp_bit:
+ call xp_bit
or a, (hl)
ld (hl), a
.Lxp_next:
@@ -2173,7 +2157,8 @@ _w_expose:
ld a, (xp_k)
inc a
ld (xp_k), a
- cp a, 32
+ ld hl, _xp_k1
+ cp a, (hl)
jp nz, .Lxp_cell
ld hl, xp_m
ld de, (_xp_out)
@@ -2182,6 +2167,28 @@ _w_expose:
pop ix
ret
+; hl: xp_m's byte of slot xp_ys, a: its bit
+xp_bit:
+ ld a, (_xp_ys)
+ ld c, a
+ rrca
+ rrca
+ rrca
+ and a, 3
+ ld hl, xp_m
+ ld de, 0
+ ld e, a
+ add hl, de
+ ld a, c
+ and a, 7
+ ld b, a
+ ld a, 1
+ ret z
+.Lxb_sh:
+ add a, a
+ djnz .Lxb_sh
+ ret
+
; nz when the cell at hl shows xp_b's face next to it
xp_shows:
ld a, (hl)
@@ -2205,6 +2212,31 @@ xp_shows:
xor a, a
ret
+; ------------------------------------------------------------------------------------------------- rs_shade
+; void rs_shade(uint8_t *p, const uint8_t *row): p[i] = row[p[i]] for 256 bytes, row 256-byte aligned
+ .section .text._rs_shade
+ .global _rs_shade
+ .type _rs_shade, @function
+_rs_shade:
+ ld iy, 0
+ add iy, sp
+ ld de, (iy+3)
+ ld hl, (iy+6)
+ ld b, 128
+.Lsh_loop:
+ ld a, (de)
+ ld l, a
+ ld a, (hl)
+ ld (de), a
+ inc de
+ ld a, (de)
+ ld l, a
+ ld a, (hl)
+ ld (de), a
+ inc de
+ djnz .Lsh_loop
+ ret
+
; ------------------------------------------------------------------------------------------------- data
.section .data._rs_vars
r_tex: .d24 0
@@ -2409,6 +2441,10 @@ _xp_oz0: .d24 0
_xp_oz1: .d24 0
_xp_ys: .db 0
_xp_sides: .db 0
+ .global _xp_k0
+ .global _xp_k1
+_xp_k0: .db 0
+_xp_k1: .db 32
xp_up: .d24 0
xp_k: .db 0
xp_b: .db 0
@@ -2424,6 +2460,7 @@ r_rtab:
.extern _rbuf
.extern _rs_cell
+ .extern _plat_poll
.extern _wexp
.extern _w_nbr
.extern _blk_model
diff --git a/games/numblocks/ce/src/world.c b/games/numblocks/ce/src/world.c
index 669bddc4..5555ea15 100644
--- a/games/numblocks/ce/src/world.c
+++ b/games/numblocks/ce/src/world.c
@@ -251,19 +251,20 @@ static const uint8_t BYTE8[32] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1
extern const uint8_t *xp_p;
extern uint8_t *xp_out;
extern int xp_ox0, xp_ox1, xp_oz0, xp_oz1;
-extern uint8_t xp_ys, xp_sides;
+extern uint8_t xp_ys, xp_sides, xp_k0, xp_k1;
void w_expose(void);
#else
static const uint8_t *xp_p;
static uint8_t *xp_out;
static int xp_ox0, xp_ox1, xp_oz0, xp_oz1;
-static uint8_t xp_ys, xp_sides;
+static uint8_t xp_ys, xp_sides, xp_k0, xp_k1 = 32;
static void w_expose(void) {
static uint8_t m[4];
- m[0] = m[1] = m[2] = m[3] = 0;
+ memcpy(m, xp_out, 4);
const uint8_t *p = xp_p;
uint8_t ys = xp_ys;
- for (uint8_t k = 0; k < 32; k++) {
+ for (uint8_t k = xp_k0; k < xp_k1; k++) {
+ m[BYTE8[ys]] &= (uint8_t)~BIT32[ys];
uint8_t b = *p;
const uint8_t *up = ys == 31 ? p - 31 * 1024 : p + 1024;
if (b != B_AIR) {
@@ -285,25 +286,31 @@ static void w_expose(void) {
memcpy(xp_out, m, 4);
}
#endif
-static void expose_col(int x, int z) {
+/* (levels [k0, k1) up from the window's bottom, the others kept) */
+static void expose_col(int x, int z, uint8_t k0, uint8_t k1) {
if ((unsigned)(x - win_x) >= WS || (unsigned)(z - win_z) >= WS) return;
+ xp_k0 = k0, xp_k1 = k1;
int c = CI(x, z);
uint8_t sx = MOD32[x - win_x + (win_x & 31)], sz = MOD32[z - win_z + (win_z & 31)];
xp_sides = (uint8_t)((x > win_x ? 1 : 0) | (x < win_x + WS - 1 ? 2 : 0) | (z > win_z ? 4 : 0) |
(z < win_z + WS - 1 ? 8 : 0));
xp_ox0 = sx ? -1 : 31, xp_ox1 = sx != 31 ? 1 : -31, xp_oz0 = sz ? -32 : 31 * 32, xp_oz1 = sz != 31 ? 32 : -31 * 32;
- xp_ys = MOD32[win_y];
+ xp_ys = MOD32[win_y + k0];
xp_p = wblk + YOFF[xp_ys] + c;
xp_out = (uint8_t *)&wexp[c];
w_expose();
}
/* the columns around a cell that changed */
-static void expose_around(int x, int z) {
- expose_col(x, z);
- expose_col(x - 1, z);
- expose_col(x + 1, z);
- expose_col(x, z - 1);
- expose_col(x, z + 1);
+static void expose_around(int x, int y, int z) {
+ /* (its level and those above and below) */
+ int k = y - win_y;
+ uint8_t k0 = (uint8_t)(k > 0 ? k - 1 : 0), k1 = (uint8_t)(k < WH - 1 ? k + 2 : WH);
+ expose_col(x, z, k0, k1);
+ k0 = (uint8_t)k, k1 = (uint8_t)(k + 1);
+ expose_col(x - 1, z, k0, k1);
+ expose_col(x + 1, z, k0, k1);
+ expose_col(x, z - 1, k0, k1);
+ expose_col(x, z + 1, k0, k1);
}
/* ---------------------------------------------------------------- filling the window */
@@ -374,6 +381,7 @@ static void fill(int x0, int z0, int x1, int z1, int y0, int y1, bool cols) {
if (pl) p[YOFF[MOD32[py]]] = (uint8_t)pl;
}
}
+ plat_poll();
gen_decorate(x0, z0, x1, z1, y0, y1, put_cb);
for (unsigned k = 0; k < n_edits; k++) {
const Edit *e = &edits[k];
@@ -393,6 +401,7 @@ static void fill(int x0, int z0, int x1, int z1, int y0, int y1, bool cols) {
col_light((uint16_t)c, ys0, (uint8_t)y0, (uint8_t)y1, (uint8_t)top);
}
if (dq_n) light_darken();
+ plat_poll();
/* spreading it: from the lit cells next to darker ones (the region's and the cells around it) */
for (int z = z0 - 1; z <= z1; z++)
for (int x = x0 - 1; x <= x1; x++) {
@@ -423,8 +432,10 @@ static void fill(int x0, int z0, int x1, int z1, int y0, int y1, bool cols) {
if (x == x1) light_spread();
}
light_spread();
+ int ka = y0 - 1 - win_y, kb = y1 + 1 - win_y;
+ uint8_t k0 = (uint8_t)(ka < 0 ? 0 : ka), k1 = (uint8_t)(kb > WH ? WH : kb);
for (int z = z0 - 1; z <= z1; z++)
- for (int x = x0 - 1; x <= x1; x++) expose_col(x, z);
+ for (int x = x0 - 1; x <= x1; x++) expose_col(x, z, k0, k1);
}
/* ---------------------------------------------------------------- changes */
@@ -464,7 +475,7 @@ void world_set(int x, int y, int z, int b) {
for (uint8_t k = 0; k < nbr_n; k++)
if (wlight[nbr[k]]) lq_push(nbr[k]);
light_spread();
- expose_around(x, z);
+ expose_around(x, y, z);
}
/* ---------------------------------------------------------------- the window */