Skip to content

Add the picogame game engine module - #11199

Open
lynt-smitka wants to merge 3 commits into
adafruit:mainfrom
MakerClassCZ:add-picogame
Open

Add the picogame game engine module#11199
lynt-smitka wants to merge 3 commits into
adafruit:mainfrom
MakerClassCZ:add-picogame

Conversation

@lynt-smitka

Copy link
Copy Markdown

First step of #11198: the picogame core C module.

The module itself is self-contained (shared-bindings/picogame, shared-module/picogame, optional port backends in common-hal/picogame). Outside of it this PR only touches:

  • py/circuitpy_mpconfig.mk / py/circuitpy_defns.mk / ports/raspberrypi/Makefile - build wiring, gated by CIRCUITPY_PICOGAME (off by default).
  • pajenicko_picopad - enables the engine. To fit it next to the Wi-Fi stack the board drops peripherals it physically lacks (_EVE, qrio, picodvi) and switches from -O3 to -O2 plus a few measured loop flags (engine kernels within ±1 % of -O3, ~150 KB smaller). 87.9 % of the firmware region used.
  • adafruit_fruit_jam - enables the engine with the RAM-framebuffer target (DVI/HSTX scanout). 92.2 % used.
  • locale/circuitpython.pot - regenerated.

Left out for follow-up PRs (per the issue discussion): core1 rendering and the ROMFS asset region.

Both board builds, sphinx docs and translations pass locally.

Retained-mode 2D engine for writing games in CircuitPython: a Scene
with dirty-rect rendering over Sprite/Tilemap/Canvas/StripDraw/
Particles/Triangles layers, plus collision, noise and text helpers -
and enough pseudo-3D primitives (project, raycast, mode-7, triangle
batches) for simple 3D games. Renders portably through any
BusDisplay; optional port backends add an async-DMA SPI path
(raspberrypi, espressif) and a RAM-framebuffer target for DVI/HSTX
scanout boards. Gated by CIRCUITPY_PICOGAME (off by default);
enabled on pajenicko_picopad and adafruit_fruit_jam.

@tannewt tannewt left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the PR! I've got a few organizational comments but most of the self-contained stuff is totally fine as-is.

Comment thread locale/circuitpython.pot Outdated
Comment on lines +70 to +71
//| """Get the tile at (tx, ty) -> int; with ``value``, set it (and mark dirty) -> None.
//| The optional keyword ``flip_x``/``flip_y``/``transpose`` flags orient the tile - together

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd split this into two different functions. This is a weird get/set pattern that I'm not a fan of.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

This is a complex change that alter the API. I need to think about it further. It's one of the first features in the engine and is used extensively in many places.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What did you decide for this?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I'm in favor of splitting it into tile() and set_tile() - it adds a verb when the state changes and results in slightly fewer changes overall (it's used in more than 200 places in the engine, games, docs and tutorials). It might even be a bit faster, since the read won't have to parse extra arguments.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd have it get_tile() to match set_tile() but that sounds fine to me.

Comment thread shared-bindings/picogame/__init__.c Outdated
Review feedback. The types that were consolidated in __init__.c (Bitmap,
Sprite, StripDraw, Triangles, Framebuffer) each get their own shared-bindings
file, matching Canvas/Scene/Tilemap/Particles/Display, so __init__.c is the
module level only: its docstring, the module functions and the globals table.
The docstring now also says how picogame relates to displayio - same display
object, different way to drive it, no retained pixels - which is the first
thing a reader of that file should learn.

The eight error messages the module added are replaced with ones CircuitPython
already ships (mp_arg_validate_type / mp_arg_error_invalid /
mp_arg_validate_length_min, and m_malloc_fail for the unreachable scene-cap
guard): the module now contributes no new strings to the translations.

@tannewt tannewt left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for splitting these apart. Many of the primitives are giving me "displayio" vibes so I think we could work to integrate more of this in the long term. Totally fine to have it separate now.

Comment thread shared-bindings/picogame/__init__.c Outdated
Comment thread shared-bindings/picogame/__init__.c Outdated
Comment on lines +751 to +753
#if CIRCUITPY_PICOGAME_FAST_DISPLAY
{ MP_ROM_QSTR(MP_QSTR_Display), MP_ROM_PTR(&picogame_display_type) },
#endif

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Generally I don't like attributes only added in some cases. The way we do this is by raising NotImplementedError from the shared-module/common-hal implementation to give a clearer error message. I think it'd be good to do here too.

The file header still said the types were consolidated here, which stopped being true when they
moved into their own files, and the displayio paragraph now names the shared object instead of
calling it "the seam".

Splitting Sprite out also left `bitmap` documented twice - once in the attribute summary and again
at its property - which mypy rejects, so `make check-stubs` (the docs job) failed. The summary
entry is gone; the fuller description at the property stays.
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