-
Notifications
You must be signed in to change notification settings - Fork 49
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
Missing module sdl2.ext.time #168
Comments
Looks like that module was added in an unofficial fork of this project that seems to now be abandoned. You can find the full source for the module here: https://github.com/LukeMS/py-sdl2/blob/master/sdl2/ext/time.py Luckily, it looks like that module is largely self-contained and should be easily added to any mainline pysdl2 project: all you should need to do is change the As for adding the module officially to pysdl2: I'd have to check, but there might be problems with the licensing since the person who forked it based it off source from a different project. Hope that helps! |
This module looks to be rather similar to the PyGame time module. Would a PR to add this to PySDL2 be welcome? |
@iKarith Yes, definitely! |
LukeMS has this added to his personal sdl2 repo on GitHub, but hasn't offered the patch upstream. Enough people seem to want it that I've decided ti offer it as a PR. I didn't take time to write unit tests for it, sorry. Closes py-sdl#168.
I see one minor problem with my own PR depending on how pedantic y'all are feeling about licensing. Zlib isn't public domain—you've gotta maintain a Copyright notice and you'd need to add a blurb about it somewhere. I think Luke put it under Zlib license because he admittedly used PyGame's source to do it. Well … if you've done this kind of stuff before (and I have), there's really "only one right way to do it" given PyGame's API found here:
Dunno how accurate you're gonna get without Cython for the busy loop version. Doing without PyGame's code is pretty simple: elapsed_ticks = 0
then = 0
# rest of your init
while running:
now = SDL_GetTicks()
elapsed_ticks = now - then
# Rest of your loop
then = now
# Shutdown code Creating a Clock() object is just encapsulating that, adding the ability to delay until so that 1000//framerate >= elapsed_time, and deciding whether to try an implement a busy loop or not. shrug Clock is a convenient reduction in boilerplate or a set of training wheels for those starting out, but if you'd prefer a more "clean room" implementation (not in the purest legal sense since obviously I submitted Luke's port as a PR) to keep PySDL2 purely public domain, I just all but wrote it from scratch in this comment. I can do it for real and you can freely CC0/public domain it. This kind of elapsed time look, either in msec or double precision fractions of a second are the basis of just about every game programming guide, tutorial, or book you'll find. I don't want to see its exclusion ever be the basis for someone to stick with SDL 1.2 for access to PyGame over SDL 2.0. (PyGame2 is not available on Ubuntu focal, I note.) |
Where in PySDL2 is sdl2.ext.time? This module is documented but missing from the pypi package and the github repo. Contains basic useful stuff for regulating frame rate or using delta time.
The text was updated successfully, but these errors were encountered: