xpenguins cont'd - repainting a window after penguins walk on it, and when penguins overlap.

Amy C mathematical.coffee at gmail.com
Sun Jun 5 23:32:13 PDT 2011


Hi all,

After a few days' break I've returned to modifying the xpenguins source to
run in a window of my choosing (e.g. terminal).

I've finally (partially) resolved the problem of restoring the background
behind the penguins (so they don't leave trails where they've walked over
icons and such) with as little flickering as possible.

I ended up keeping a penguin-bounding-box-sized pixmap of the original
background behind the penguin, and selectively sending a clear/expose event
to the strip that the penguin-rectangle had just left, while updating the
background pixmap with the strip that the penguin-rectangle would move to
next.

Then this updated background pixmap is painted onto the window where the
penguin will go and the penguin is plonked on top.

It means that instead of clear/exposing the entire penguin-rectangle for
each frame of the animation, only the little strip that is exposed when the
penguin-rectangle moves is.

Sounds a bit confusing but I don't know how else to explain it.

One problem remains and that happens when penguins overlap each other --
suppose penguin A overlaps penguin B and they're heading towards each other
(in xpenguins penguins just go through each other). Then when penguin A's
background pixmap is updated, it will contain a little slice of penguin B in
it (in the wrong position) and vice versa.
This little slice of penguin propogates through the background pixmap as the
penguin moves, which looks a little odd.

Can anyone think of a nice way to handle this?  The only thing I can think
of is to do some sort of collision/overlapping detection and then be careful
about the bits of background that gets copied between the penguins in
question.
However I'm not a computer scientist and the only way that makes sense for
me to implement this is lots of inefficient loops to check every penguin
against every other penguin.

A related question -- do you think it's viable to make one (transparent)
window per penguin? It would be easier than drawing them directly onto an
existing window (Famous Last Words), but say I had 25 penguins -- would 25
new windows be a big memory drain or is X good at that sort of thing?
(Thanks for that suggestion Xavier. I would rather not assume a compositor
though, I have Fedora at work and Ubuntu at home but it's too sucky to have
Compiz on it).

cheers,
Amy
-------------
By the way, if anyone can make a Grug theme for xpenguins ... I would be so
happy :D
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.x.org/archives/xorg/attachments/20110606/70d9775b/attachment.html>


More information about the xorg mailing list