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.

Hollow Knight: the UI's sprites at full resolution again (only the world's props smaller); background and foreground planes coarser to fit; an area title behind the inventory darkened with the world

Mason Chen243618a33bbd
diff --git a/games/hollowknight/src/data.bin b/games/hollowknight/src/data.bin
index b06cdc1b..5170b569 100644
Binary files a/games/hollowknight/src/data.bin and b/games/hollowknight/src/data.bin differ
diff --git a/games/hollowknight/src/game.h b/games/hollowknight/src/game.h
index 50dfdcca..085d843b 100644
--- a/games/hollowknight/src/game.h
+++ b/games/hollowknight/src/game.h
@@ -467,6 +467,7 @@ void inv_reset(void);
uint32_t inv_tick(uint32_t keys); /* -> the keys the game has (none while it is open) */
void inv_damage(void); /* (HERO DAMAGED: it closes) */
bool inv_open(void);
+float inv_behind(void); /* (what of the world behind it shows: 1 closed) */
void inv_open_map(void); /* (OPEN INVENTORY MAP: the map tapped twice) */
void inv_cursor_arrow(int which); /* (the map pane's: on the left arrow -1, the right -2; else not shown) */
float ui_key(int name, float x, float y, uint8_t white, float a); /* an action's key, by name -> its half width */
diff --git a/games/hollowknight/src/inv.c b/games/hollowknight/src/inv.c
index e345de33..3ba80b71 100644
--- a/games/hollowknight/src/inv.c
+++ b/games/hollowknight/src/inv.c
@@ -114,6 +114,12 @@ typedef struct {
bool inv_open(void) { return iv.st != IV_CLOSED; }
+/* (how much of what is behind it shows: its darkening) */
+float inv_behind(void) {
+ float ba = iv.st == IV_CLOSED && iv.border_a <= 0 ? 0 : iv.border_a < 0 ? 0 : iv.border_a;
+ return 1 - ba * DIM;
+}
+
static bool has_pane(int p) {
return p == P_INV || (p == P_CHARMS && pd_flag(PDF_HAS_CHARM)) || (p == P_MAP && pd_flag(PDF_HAS_MAP));
}
diff --git a/games/hollowknight/src/map.c b/games/hollowknight/src/map.c
index 7f963f0e..50ca48d3 100644
--- a/games/hollowknight/src/map.c
+++ b/games/hollowknight/src/map.c
@@ -3,6 +3,7 @@
* its rooms as Cornifer drew them, rough until the quill maps them, their pins, the arrows to the areas next to them,
* the compass (Wayward Compass: where the Knight is), the shade's mark. The rooms visited, mapped, where a cocoon was
* broken: PlayerData's (scenesVisited, scenesMapped, scenesEncounteredCocoon). */
+#pragma GCC optimize("Os") /* (its code small: not where a frame's time goes) */
#include <math.h>
#include "game.h"
diff --git a/games/hollowknight/src/title.c b/games/hollowknight/src/title.c
index 85e2ef88..5f4f6c9a 100644
--- a/games/hollowknight/src/title.c
+++ b/games/hollowknight/src/title.c
@@ -245,7 +245,8 @@ static void line(int text, int style, float x, float y, uint32_t a) {
void titles_draw(void) {
if (at.st == T_OFF) return;
const int16_t *row = table[at.title];
- uint32_t a = (uint32_t)(at.alpha * 255 + 0.5f);
+ /* (behind the inventory, darkened as the world is: its text drawn over what is drawn after) */
+ uint32_t a = (uint32_t)(at.alpha * inv_behind() * 255 + 0.5f);
bool shown = at.alpha > 0 || at.fade > 0;
if (at.large && shown) {
float y = TITLE_Y + at.folder_y;
diff --git a/games/hollowknight/tools/actors.py b/games/hollowknight/tools/actors.py
index 323cb87f..bd155067 100644
--- a/games/hollowknight/tools/actors.py
+++ b/games/hollowknight/tools/actors.py
@@ -243,7 +243,6 @@ K0 = scene.FOCAL / (0.004 - scene.CAMZ) # screen pixels a unit, where actors a
HUD_K = (scene.VIEW_H / 2) / 8.7107 # the HUD's (its orthographic camera)
# (actor, clip): drawn bigger or smaller than their sprites
ACTOR_RES = float(os.environ.get("HK_ACTOR_RES", "0.7")) # (to fit the flash)
-PIECE_RES = float(os.environ.get("HK_PIECE_RES", "0.7")) # (the scripts' and debris's sprites: a little less fine, to fit)
ACTOR_SCALE = {"hud": HUD_K / K0, "shopui": HUD_K / K0, "stagui": HUD_K / K0, "mapui": HUD_K / K0, "journalmsg": 0.7 * HUD_K / K0, "liquid": 1.4 * HUD_K / K0, "dialogue": text.TEXT_K * HUD_K / K0}
HUD_MASK = 0.7135
@@ -375,7 +374,6 @@ def unity_sprites(keys):
object's scale."""
out = []
for level, exts, fid, pid, scale, res in keys:
- res *= PIECE_RES
if level == "tk2d":
path, col, name = exts, fid, pid
c = tk2d.collection(path, col)
diff --git a/games/hollowknight/tools/art.py b/games/hollowknight/tools/art.py
index 158f5bde..3e959e12 100644
--- a/games/hollowknight/tools/art.py
+++ b/games/hollowknight/tools/art.py
@@ -12,10 +12,10 @@ WIDE = 32 # alpha-only tiles are 32 texels wide (2 bits each: 128 bytes too)
BLOCK_TILES = int(os.environ.get("HK_BLOCK_TILES", "16"))
LEVEL_RATIO = 0.6 # an instance this much smaller than its texture gets a smaller copy
BLUR_SIGMA = 1.2 # background blur, calculator pixels (LightBlurredBackground)
-BLUR_SCALE = float(os.environ.get("HK_BLUR_SCALE", "0.25")) # texels a screen pixel behind the blur plane
-FG_SCALE = float(os.environ.get("HK_FG_SCALE", "0.6")) # ... in front of the gameplay plane (z < FG_Z)
+BLUR_SCALE = float(os.environ.get("HK_BLUR_SCALE", "0.2")) # texels a screen pixel behind the blur plane
+FG_SCALE = float(os.environ.get("HK_FG_SCALE", "0.5")) # ... in front of the gameplay plane (z < FG_Z)
FG_Z = -2.5
-FIT_K = float(os.environ.get("HK_FIT_K", "0.8")) # (all the rooms' scenery a little less fine, to fit the flash)
+FIT_K = float(os.environ.get("HK_FIT_K", "0.77")) # (all the rooms' scenery a little less fine, to fit the flash)
BLUR_PRE = False # (the game blurs the background as a whole: the calculator does too)
LZMA_FILTERS = [{"id": lzma.FILTER_LZMA1, "lc": 0, "lp": 0, "pb": 0, "dict_size": 1 << 12, "preset": 9 | lzma.PRESET_EXTREME}]
diff --git a/games/hollowknight/tools/ents.py b/games/hollowknight/tools/ents.py
index 54c937d0..3928ce6a 100644
--- a/games/hollowknight/tools/ents.py
+++ b/games/hollowknight/tools/ents.py
@@ -2,6 +2,7 @@
that set them. Each becomes a record (src/game.h: Ent) with its trigger box (world units) and its own values; names go to
a shared string table."""
import math
+import os
import struct
import numpy as np
@@ -116,14 +117,19 @@ class Strings:
return struct.pack("<I", len(self.list)) + b"".join(struct.pack("<I", o) for o in offs) + bytes(body)
+# (the world's sprites: debris, props, the scripts' objects; a little less fine, to fit the flash)
+PIECE_RES = float(os.environ.get("HK_PIECE_RES", "0.7"))
+
+
class Sprites:
"""Unity sprites objects show as actors (debris...): pack.py makes them like the actors' frames, after those."""
def __init__(self):
self.list, self.index, self.base = [], {}, 0
- def id(self, d, ref, scale, res=1.0):
- """(res: its texture's resolution, as a part of the screen's: smooth sprites can be stretched)"""
- return self._add((d["level"], tuple(d["externals"]), ref[0], ref[1], round(scale, 3), res))
+ def id(self, d, ref, scale, res=1.0, world=False):
+ """(res: its texture's resolution, as a part of the screen's: smooth sprites can be stretched; world: one of
+ the world's, PIECE_RES)"""
+ return self._add((d["level"], tuple(d["externals"]), ref[0], ref[1], round(scale, 3), res * (PIECE_RES if world else 1)))
def tk2d(self, path, col, name, scale=1.0, res=1.0):
"""A 2D Toolkit sprite of a collection (file, path id), by name."""
@@ -371,7 +377,7 @@ def _pieces(d, o, ids, by_id, sprites):
rb = next((c.get("v") or {} for c in q["c"] if c["type"] == "Rigidbody2D"), {})
ob = next((c.get("v") or {} for c in q["c"] if c.get("class") == "ObjectBounce"), None)
sp = next((c.get("v") or {} for c in q["c"] if c.get("class") == "SpinSelf"), None)
- sid = sprites.id(d, v["m_Sprite"], max(sx, sy))
+ sid = sprites.id(d, v["m_Sprite"], max(sx, sy), world=True)
dx, dy = q["pos"][0] - o["pos"][0], q["pos"][1] - o["pos"][1]
layer = scene.layer_index(v.get("m_SortingLayerID", 0))
out.append(rec(ENT_PIECE, 1 if sp is not None else 0, (dx, dy, rot, q["pos"][2]),
@@ -1036,7 +1042,7 @@ def room(d, rooms, strings, persist, name, sprites=None, owners=None, rec_base=0
continue
import scene
m = np.array(q["m3"]).reshape(3, 3)
- sid = sprites.id(d, sr["m_Sprite"], float(np.hypot(m[0, 0], m[1, 0])))
+ sid = sprites.id(d, sr["m_Sprite"], float(np.hypot(m[0, 0], m[1, 0])), world=True)
vx, vy = flings.get(nm, (0, 0))
extra.append(rec(ENT_BOX, k, (q["pos"][0], q["pos"][1], q["pos"][2], 0), (vx, vy, 0, 0),
a=sr.get("m_SortingOrder", 0) + 32768, group=scene.layer_index(sr.get("m_SortingLayerID", 0)),
diff --git a/games/hollowknight/tools/vm.py b/games/hollowknight/tools/vm.py
index 31bd1b55..6a8b8358 100644
--- a/games/hollowknight/tools/vm.py
+++ b/games/hollowknight/tools/vm.py
@@ -81,7 +81,7 @@ def _piece(doc, q, rigid=True):
ss = {"spinFactor": sf["vars"]["Spin Factor"][1], "randomStartRotation": sf["vars"]["Random Start Rotation"][1]}
# (SpinSelf: a push of its speed times its factor, turned at random first; SpinSelfSimple: against its speed)
spin, flags = (sp.get("spinFactor", -7.5), 3) if sp is not None else (-ss.get("spinFactor", 0), 1 | (2 if ss.get("randomStartRotation") else 0)) if ss is not None else (0, 0)
- return {"sprite": PIECE_SPRITES(doc, sr["m_Sprite"], max(sx, sy)), "layer": scene.layer_index(sr.get("m_SortingLayerID", 0)),
+ return {"sprite": PIECE_SPRITES(doc, sr["m_Sprite"], max(sx, sy), world=True), "layer": scene.layer_index(sr.get("m_SortingLayerID", 0)),
"order": (sr.get("m_SortingOrder", 0) + 32768) & 0xFFFF, "flags": flags, "z": q["pos"][2], "rot": rot,
"gravity": (rb or {}).get("m_GravityScale", 1), "bounce": ob.get("bounceFactor", 0) if ob else -1,
"spin": spin, "mirror": mirror}
@@ -1771,7 +1771,7 @@ def room_blob(name, clip_index, sprites, owners=(), persist=None):
sr = next((c.get("v") for c in o["c"] if c["type"] == "SpriteRenderer" and c.get("v")), None)
if sr and sr.get("m_Sprite"):
# (its own size, drawn at its scale: its texture as fine as it is drawn)
- sprite = sprites.id(o.get("_doc") or rm.d, sr["m_Sprite"], 1.0, max(abs(sx), abs(sy)))
+ sprite = sprites.id(o.get("_doc") or rm.d, sr["m_Sprite"], 1.0, max(abs(sx), abs(sy)), world=True)
# (DeactivateIfPlayerdataTrue, False: two at most)
conds = [pdf[bn] | (0x8000 if off_if else 0) for bn, off_if in state.conditions(o) if bn in pdf]
conds = sorted(set(conds), key=conds.index)
@@ -1817,7 +1817,7 @@ def room_blob(name, clip_index, sprites, owners=(), persist=None):
sx = float(np.hypot(m[0, 0], m[1, 0])) * (1 if m[0, 0] >= 0 else -1)
sy = float(np.hypot(m[0, 1], m[1, 1])) * (1 if m[1, 1] >= 0 else -1)
sr = next(c["v"] for c in q["c"])
- spr = sprites.id(q.get("_doc") or rm.d, sr["m_Sprite"], 1.0, max(abs(sx), abs(sy)))
+ spr = sprites.id(q.get("_doc") or rm.d, sr["m_Sprite"], 1.0, max(abs(sx), abs(sy)), world=True)
layer, order = ents._sorting(q)
import scene
blend = 0