Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PKG Add pygame-ce #4602

Merged
merged 32 commits into from Mar 29, 2024
Merged

PKG Add pygame-ce #4602

merged 32 commits into from Mar 29, 2024

Conversation

ryanking13
Copy link
Member

@ryanking13 ryanking13 commented Mar 11, 2024

Description

Resolve: #289

Adds pygame-ce 2.4.1.

Demo: https://ryanking13.github.io/pyodide-pygame-demo/

Known Issues

Porting existing pygame-based codes

Following changes are required to run the existing pygame code in the Pyodide.

  1. set the canvas to draw on

This is already described in the docs.

  1. yield inside the infinite loop

Usually, pygame codes looks like this:

def run_game():
    while True:
        do_something()
        draw()
        pygame.timer.delay(...)

In Pyodide, this needs to be changed to the following:

import asyncio
async def run_game():
    while True:
        do_something()
        draw()
        await asyncio.sleep(...)

so that the browser can take control and draw animations on the canvas.

Checklists

  • Add a CHANGELOG entry
  • Add / update tests
  • Add new / update outdated documentation

-// SDL_Init + TTF_Init() are made in main before CPython process the module
-// inittab so the emscripten handler knows it will use SDL2 next cycle.
-static int font_initialized = 1;
+static int font_initialized = 0;
Copy link
Member Author

Choose a reason for hiding this comment

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

This comment is true for pygame-web but not true for Pyodide.

cc: @pmp-p

Copy link
Contributor

Choose a reason for hiding this comment

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

i'm making pygame-community/pygame-ce#2748 so both pygame-web and pyodide do not require patching

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you so much! I don't know anything about pygame internals, so I really appreciate the various things you do for WASM support.

Copy link
Member

Choose a reason for hiding this comment

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

Agreed, we appreciate all the work you've done on this @pmp-p -- it seems like quite a lot of effort.

@hoodmane hoodmane self-requested a review March 25, 2024 22:36
Copy link
Member

@hoodmane hoodmane left a comment

Choose a reason for hiding this comment

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

Thanks @ryanking13 and @pmp-p! Looks good to me.

@pmp-p
Copy link
Contributor

pmp-p commented Mar 28, 2024

note that pygame-ce/Panda3D can also render directly in Terminal( like xterm.js with IIP iterm2 image protocol ) with no canvas/webgl requirements at all ( gpu implemented in software via WASM )
shot-2024-03-29_1711670160
( screenshot of Panda3D/Python 3.13 WASI running via wasmtime in WezTerm )

@ryanking13 ryanking13 merged commit bd643ae into pyodide:main Mar 29, 2024
38 of 39 checks passed
@ryanking13 ryanking13 deleted the pygame-ce branch March 29, 2024 08:55
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.

port pygame
3 participants