Open gresm opened 1 month ago
This seems to work in my testing, per the original issue:
I think it would be much simpler to implement as much as possible in pure python code, and having minimal C code changes. event.c is pretty messy as it is, and IMO we should be focused on making it more maintainable by offloading more things to the python side.
@ankith26 I agree that event.c
is already messy, but I worry that using pure python implementation for implementing event classes would be too slow (I didn't check this). I think that splitting the logic between pygame._event
and pygame.event
is a good idea, but something far outside the scope of "Events as types PR" and would require its own pull request.
I think it would be much simpler to implement as much as possible in pure python code, and having minimal C code changes. event.c is pretty messy as it is, and IMO we should be focused on making it more maintainable by offloading more things to the python side.
@ankith26 I agree that
event.c
is already messy, but I worry that using pure python implementation for implementing event classes would be too slow (I didn't check this). I think that splitting the logic betweenpygame._event
andpygame.event
is a good idea, but something far outside the scope of "Events as types PR" and would require its own pull request.
I think that there will be some opportunities in the future to rewrite things in Python and have them be both easier to maintain as well as faster. As the faster-cpython team gets the interpreter faster, the overhead of going between C and Python will be more significant.
In the below test script, Python is faster than C to implement a pygame API function (in 3.12 but not in 3.9, which are the only versions I tested)
List comprehensions are just too good.
@Starbuck5 this looks interesting, but isn't a good measure for speed comparison in this case. I assume that python version could probably have similar speed as this C implementation, in some places probably a bit slower, but I'm not sure if it is worth re-implementing this in python, is there enough interest for it, that it would make sense for me to work on this. Is there enough interest in this for me to go on writing a new implementation, when there is one already?
@ankith26 Understandable, this is another reason why splitting event logic between _event
and event
would be useful, as it would decrease logic in _event.c
and would make transitions easier. That's enough for me to see this worth the effort.
Closes #2759