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

Re: [pygame] extending pygame masks



Mike

Ah, very interesting. Can I see the source on that?  I would love to
see that included in the Mask module.

Nirav

On Tue, Oct 14, 2008 at 10:44 AM, Michael George
<mdgeorge@xxxxxxxxxxxxxx> wrote:
> Thanks,
>
> what I need is different - I need to compute overlap_mask for each possible
> offset, so that I can search for an optimal placement.  Of course I could
> write a loop and call overlap_mask for each offset, but I think that would
> be prohibitively slow - I'm computing it all in one pass.
>
> To move the #defines into pygame.h you wouldn't need to include the PyObject
> stuff in bitmask.h.  If anything, pygame.h would have to include bitmask.h,
> not the other way around (although you could just add a forward declaration
> of bitmask_t).  In the mean time, I guess I'll just copy the defs into my
> source.
>
> --Mike
>
> Nirav Patel wrote:
>>
>> Mike,
>>
>> I'm not sure if this is what you mean, but the Mask module has a
>> function in SVN called Mask.overlap_mask, which returns a mask of the
>> overlapping pixels between two masks by an offset.
>>
>> The internals of most of the bitmask stuff is exposed in bitmask.h.
>> It could be useful to move the defines and typedef from mask.c to
>> there.  I think the reason it wasn't is that what's in bitmask.h
>> currently is purely C, while the typedef has a PyObject_HEAD in it.
>> Alternately, if you're making an external module, you could just
>> import bitmask.h and copy the typedef and defines into your file.
>>
>> Nirav
>>
>> On Tue, Oct 14, 2008 at 9:11 AM, Michael George <mdgeorge@xxxxxxxxxxxxxx>
>> wrote:
>>
>>>
>>> hello,
>>>
>>> I've been working on some code that generates what I've been calling a
>>> "hitmask", namely a mask with the (x,y) bit set if placing one mask on
>>> another offset by (x,y) would cause a collision.  It's part of a slick
>>> algorithm I'm working on for drag-and-drop collision response.  I've
>>> implemented it in C against the bitmask api.  I have n questions:
>>>
>>> 1. Is there any interest in putting this in pygame?  I suspect no,
>>> because
>>> it's only useful for situations where you may freely drag oddly-shaped
>>> objects around but need to avoid collisions between them.  It would be
>>> good
>>> for things like map editors.  However if there is interest, I'd be happy
>>> to
>>> contribute it.
>>>
>>> 2. If not, I'd like to avoid shipping a modified pygame with my game.  Is
>>> it
>>> possible for me to build and ship extensions that link against pygame
>>> internals (really just the bitmask stuff, and maybe rects at some point)?
>>>  I
>>> haven't dug into the python/C boundary too much, although glancing over
>>> the
>>> pygame source it doesn't seem too bad.  Can someone point me in the right
>>> direction?
>>>
>>> 3. If I do build my code separately, it currently looks impossible to
>>> actually get at the internals of a PyMaskObject without doing something
>>> hacky.  In particular, the data structure and the PyMask_AsBitmap macro
>>> are
>>> only defined in mask.c, rather than in a separate header file.  Is it
>>> reasonable for you to move that into pygame.h, or is it hidden for a
>>> reason?
>>>
>>>
>>> ...where n = 3.
>>>
>>> Thanks!
>>>
>>> --Mike
>>>
>>>
>
>