Video Game Questions
Hi,
I got pointed to your project, and I like what you got, but I have some questions regarding usability for video games that aren't immediately, obviously answers by the docs or examples. Maybe you can write a doc entry or example for these problems (or answer them here):
- input device support: mouse, keyboard, possibly controller
- non-blocking rendering / decoupled rendering / "business" logic, can you this project do it? I'm thinking of calculations that take longer than one e.g. 60hz frame, will they block the rendering visibly?
- (optionally how much can imgui be "gamified' although that's not really your project, I should check out their project page.)
Cool project! thanks for making it!
There's a more low-level example here that shows how you can take full control over the graphics API, GUI layer and render loop: https://github.com/pygfx/wgpu-py/blob/main/examples/gui_direct.py
You can build anything you want with that. Video games included.
But you'll have to give up all the pygfx niceties :)
I agree that the pygfx API is not a perfect fit for video games right now. If your performance requirements aren't AAA, you can probably make it work though.
We're thinking about how to make this more flexible. I have a local branch where I'm trying to figure out how to use just pygfx rendering components, and opt out of all the interaction & GUI stuff. It's not where I want it to be yet.
input device support: mouse, keyboard, possibly controller
As Korijn pointed out, you can use a GUI directly, but you can also use rendercanvas and use the events from there: https://rendercanvas.readthedocs.io/stable/api.html#rendercanvas.EventType
non-blocking rendering / decoupled rendering / "business" logic, can you this project do it? I'm thinking of calculations that take longer than one e.g. 60hz frame, will they block the rendering visibly?
The way that most examples are written they'd block yes. But you can write such logic using an async function:
from rendercanvas.utils.asyncs import sleep
from rendercanvas.auto import RenderCanvas, loop
async def my_loop():
while True:
... do stffu
sleep(0) call this often enough so that this loop won't block the rendering loop
loop.add_task(my_loop)
This works with any GUI backend. If you want to use stuff from asyncio, make sure you use the proper asyncio loop, as shown in this example.
Another option is to use a thread, obviously. I have not played with that myself yet.