[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Pygame for SDL 2, and how it may look.



Hi Greg,

On 17-04-19 11:06 PM, Greg Ewing wrote:
Lenard Lindstrom wrote:
Extension type WindowSurface would add an SDL window C pointer to its pygame.Surface parent. This window pointer cannot be factored out into a separate WindowBase parent class. And any methods which access that pointer will be specific to WindowSurface's C structure type.

And consequently, it would be impossible to write code that
generically works with either type of window at the C level
without going through Python method or property dispatch.

* Cython has an include statement. Unfortunately, include statements are not allowed in class declarations.

Even if it worked, the effect would be no different from
writing out a copy of the code in each class. You would still
have two unrelated sets of fields with different offsets.

Splitting it into two objects sounds like the best solution
to me. Then you can have a Window object with the same interface
whether it has a Renderer or a Surface attached, and a Renderer
with the same interface whether it's attached to a Window
or something else.

I was thinking of a generic mixin rather than a shared functions mixin. Code written in one place, a .pxi file, gets duplicated in multiple classes by including it in each class declaration body. Unfortunately, the special parser machinery to support Cython includes is only implemented at the module level. It was never generalized to work in any code block. What irked me is this restriction is not mentioned in the Cython docs. So with anticipation of having found a simple solution to my problem I am greeted with a "include statement not allowed here" compiler error.

Lenard