Expand description
The one-bit renderer (game ADR-0074): draws a GlyphBuffer the size of
the Playdate’s screen (50 × 15 cells of 8 × 16 pixels,
ConsoleSpec::text) into a 400 × 240
one-bit Frame laid out as the Playdate’s own frame buffer, so its
front end copies it to the screen as it is.
Colours become Shades, 8 × 8 patterns fixed to the screen’s pixels
(so neighbouring tiles line up and patterns don’t swim when things
move), as a Shades says. Two say it:
- The game’s inks (
InkShades, game ADR-0074): a colour that is an ink’s reserved code (the Playdate’s palette is made of them) is drawn in that ink, any other one white or black by its brightness.renderdraws with them. - Roles’ patterns (
PatternMap, ADR-0008 §4): the skin’s palette names its colours by role, and its pattern map gives each role a foreground and a backgroundPattern. A colour of no role is dithered by itsluminance; a glyph’s is solid, white or black, as text is never dithered.to_one_bitdraws with them.
The order: the white ground; a backdrop’s scene in its window
(game ADR-0048), drawn the same way; then the cell backgrounds, Under
items, the white edges of Ink::BlackEdged glyphs, the glyphs (each
half of a wide one in its own cell: the font’s one-bit atlas keeps the
halves as two cells),
Over items, and last the Ink::Invert rectangles, which flip what
is under them. Pictures are one-bit Images (docs/design/playdate.md,
One-bit pictures). A painted picture (ADR-0078) is looked up in the
frame’s table: a one-bit one is drawn as a one-bit sprite, an RGBA or
indexed one dithered as it is drawn (dither_row). Nothing here
allocates.
Made for the device’s speed (ticket 1055, game ADR-0077): 32-bit
coordinates, a pattern’s byte looked up, whole bytes written whole
(a sprite’s too, ticket 3056), only the cells near the part being
drawn visited, and
render_changed redraws only where a frame differs from the last.
reference is the plain renderer this one must equal.
Structs§
- Font
- The font as the one-bit renderer reads it: the glyph map and the one-bit atlas the game gives.
- Image
- A one-bit picture:
heightrows ofstridebytes, a byte’s highest bit its left pixel, a set bit white; and optionally a mask of the same shape, a set bit where the picture is drawn (the Playdate’s own bitmap layout). Without a mask every pixel is drawn. - InkShades
- The game’s inks (game ADR-0074): everything in
rgbis drawn inink_of(rgb). - OneBit
Frame - A one-bit picture of the display, 400 × 240, in the Playdate’s layout:
each row
ROW_BYTESbytes (padded to a whole number of 32-bit words, as its display takes them), a byte’s highest bit its left pixel, a set bit white. - Pattern
- A pattern of 8 × 8 pixels: one of the
Basepatterns, or one of them inverted. A pattern map spells itDither50orInverted(Dither50). - Pattern
Map - What each colour of a skin’s palette is drawn in on a one-bit target:
the patterns of its role, by the skin’s pattern map. A colour that is
no role’s is dithered by its
luminance(Bayer 8 × 8, asditherdoes); a glyph in it is white or black, whichever is nearer, as text is never dithered. - Pattern
MapDef - A pattern map: each palette role’s patterns on a one-bit target, the groups of roles that must stay distinct, and the roles text is drawn in.
- Role
Patterns - A role’s two patterns:
fgfor what is drawn in its colour (a glyph, a rectangle, a sprite painted in it),bgfor a cell’s background in it (fgagain, if the map doesn’t say). - RowMask
- A set of the display’s rows, a bit each.
- Shade
- How a colour is drawn: an 8 × 8 pattern fixed to the screen, and what two of the game’s inks do besides.
Enums§
- Base
- One of the fixed patterns, before any inversion: black and white solids, three ordered dithers, and four kinds of line.
- Phase
- The steps of a render, in order, for timing them on the device
(
render_marked).
Constants§
- FRAME_
BYTES - Bytes in a
Frame. - HEIGHT
- The screen’s height in pixels.
- ROW_
BYTES - Bytes per row of a
Frame: the Playdate’s stride (50 bytes of pixels, 2 unused). - WIDTH
- The screen’s width in pixels.
Traits§
- Images
- Where the renderer finds a sprite’s one-bit picture.
- Shades
- What a frame’s colours are drawn in.
Functions§
- changed_
rows - The rows
newdiffers fromoldin. - dither_
row - The eight pixels of a frame byte on screen row
y(a byte’s first pixel is always at a multiple of 8 across) whose brightnesses arelight(0 black to 255 white, the first the leftmost), dithered as ADR-0078 says: pixeliis white where4 × BAYER[y % 8][i] + 2 ≥ 255 − light[i](shuyi_assets::onebit::BAYER), the Bayer dither ofshuyi bakeat the screen’s pixels. Its highest bit is the leftmost pixel, a set bit white. Integers only: the same on every platform. - ink_
is_ white - Whether
inkmakes screen pixel(x, y)white.Ink::BlackEdgedandInk::Invertare black here: the edge is drawn around glyphs, and only rectangles flip. - ink_of
- The ink a colour is drawn in: the ink it is the code of, or else white if it is at least half bright (in the eye’s weighting of red, green and blue), black if not.
- is_
white - Whether pixel
(x, y)offrameis white; off the screen,false. - luminance
- A colour’s luminance, 0 (black) to 255 (white), in integer Rec. 601
weights:
(77 r + 150 g + 29 b) >> 8. - render
- Draws
bufintooutin the game’s inks (InkShades), from its top-left corner; whatever lies past 400 × 240 pixels is cut off. See the module for the order. - render_
changed - Makes
out, which holdsoldasrenderdrew it, holdnewasrenderwould draw it, redrawing only the 8 × 16 pixel tiles of the screen where they may differ: around a changed cell (one pixel more for a glyph’s edge), under a changed item (the old and the new one), the window of a changed backdrop, and a painted item whose picture changed. - render_
changed_ with render_changed, the colours drawn asshadessays (as they were forold).- render_
marked render, callingmarkas eachPhaseends (the Playdate’s bench build times them).- render_
marked_ with render_with, callingmarkas eachPhaseends.- render_
with render, its colours drawn asshadessays.- to_
one_ bit - Draws
frameas a one-bit target shows it: its colours in their roles’ patterns bymap, glyphs fromfont, sprites’ one-bit pictures fromimages(render_with). The frame is drawn from the display’s top-left corner, and what lies past 400 × 240 pixels is cut off.