Skip to content

picogame3d: move the perspective and 3D functions out of picogame - #11961

Merged
dhalbert merged 2 commits into
adafruit:mainfrom
MakerClassCZ:picogame3d
Nov 25, 2026
Merged

dhalbert merged 2 commits into
adafruit:mainfrom
MakerClassCZ:picogame3d

Conversation

@lynt-smitka

Copy link
Copy Markdown

picogame has turned out to be useful beyond games, as a fast general drawing engine, and I want to keep developing it without worry about flash for every new feature. The 3D/perspective functions are a different kind of code: they are mostly for demos, wow effects and finding out how far CircuitPython can go, so fewer people use them. Splitting them into their own module, as suggested in #11198, lets both parts grow independently: new 3D features don't make the 2D core bigger, and a board short on flash can keep the 2D engine and drop the 3D one.

This moves mode7, road, road_edges, raycast and project from picogame into a new picogame3d module. CIRCUITPY_PICOGAME3D defaults to CIRCUITPY_PICOGAME, so all seven boards that have picogame get both modules; picogame3d without picogame stops the build with an #error. The CIRCUITPY_PICOGAME_FPU make variable is gone; no board set it, and a build can still force the float path with -DCIRCUITPY_PICOGAME3D_FLOAT=0/1.

This is a breaking change for code written against 10.3 and 11.0.0-beta.0. Existing code migrates like this:

  • canvas.mode7(...) → picogame3d.mode7(canvas, ...)
  • canvas.road(...) → picogame3d.road(canvas, ...)
  • picogame.raycast, road_edges, project → picogame3d.raycast, road_edges, project
  • picogame.FPU → picogame3d.FLOAT

There are no aliases in picogame, because they would cost flash on every board and keep the 3D code linked in. The picogame_mode7, picogame_road and picogame_ray helper libraries get a matching release.

road now clips each row itself and fills it with picogame_fill565, so it no longer needs span565 from Canvas.c; it is about 10 % faster than before (PicoPad, 160x120 canvas). The second commit makes project and raycast check every buffer length. Before, they checked only one output buffer, so a shorter buffer was read or written past its end.

Size: +232 B on PicoPad, +216 B on Fruit Jam, +224 B on PyBadge; the buffer checks are 56-72 B of
that. Building with CIRCUITPY_PICOGAME3D = 0 saves 3.8 kB on PicoPad.

Tested on PicoPad, Fruit Jam and PyBadge: the output of all five functions is identical to main for the same inputs.

@dhalbert dhalbert left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems fine, and certainly 11.0.0 is the right time to make this change. Take out the autogen_board_info.toml changes. Updates to those files are triggered automatically by a separate CI task.

mode7, road, road_edges, raycast and project move to a new picogame3d
module, enabled by default wherever picogame is. Canvas.mode7 and
Canvas.road become functions that take the canvas as their first
argument, and picogame.FPU becomes picogame3d.FLOAT.
project limited n only by out_sx and raycast limited ncols only by top,
so a shorter out_sy, pts, bot, col, dist or map was written or read past
its end. Both now limit the count by every buffer, and a cam or wcolors
buffer that is too short raises ValueError.
@dhalbert
dhalbert merged commit 4138a14 into adafruit:main Nov 25, 2026
717 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants