librelist archives

« back to archive

timers and threads in red and green shoes

timers and threads in red and green shoes

From:
J. Kaiden
Date:
2012-03-08 @ 03:17
hey folks,

  i've been fooling around with a (dumb) little snake game, and i've
noticed a couple of differences between red and green shoes that i wanted
to comment on and ask about...

  here are the gists for the guts of the game:

  on red shoes:https://gist.github.com/1998219

  on green shoes:https://gist.github.com/1998224

  at first i was drawing the snake in an `animate` loop, but that quickly
jammed up the cpu in both red and green shoes.

  i then used a GLib::Timeout loop under green shoes, and everything ran
smoothly, without jacking the cpu.

  they way the gists are now, i draw the snake in a ruby Thread, and
there's an interesting difference between red and green shoes handling the
Thread.

  green runs without much cpu drain, but red starts to eat up the processor
and lag after a short time.

  so my questions are, what's the difference here - and why?  how do the
built in `animate` and `every` loops work, and why do they chew up the
processor so much?  is there a way to make them more efficient?

  i know there are a lot more important and interesting issues going on
right now, but any ideas would be appreciated!

  thanks - Shoes On!

 - j

Re: [shoes] timers and threads in red and green shoes

From:
ashbb
Date:
2012-03-08 @ 12:20
Hi J,

Thank you for sharing interesting snippets. :)

I tried them out with Red Shoes 3 (0.r1514) and Green Shoes 1.1.357 on my
Windows 7.

But,
> green runs without much cpu drain, but red starts to eat up the
> processor and lag after a short time.
Umm,... both seem the same, at first eat up cpu and lag shortly.

> how do the built in `animate` and `every` loops work?
On Linux, both Red and Green use GLib::Timeout loop.
Although Red is written in C, so calls `g_timeout_add`.
On Windows, Red uses native SetTimer and Green uses GLib::Timeout.

ashbb

Re: [shoes] timers and threads in red and green shoes

From:
J. Kaiden
Date:
2012-03-09 @ 13:20
hi ash,

  thanks for giving the gists a try....

I tried them out with Red Shoes 3 (0.r1514) and Green Shoes 1.1.357 on my
> Windows 7.
>
> ... both seem the same, at first eat up cpu and lag shortly.
>

  interesting...  on my ubuntu 10.04lts there is a significant difference
between red and green, and green runs without eating up the cpu or any lags
- hmmm.  must be a platform specific issue?


> > how do the built in `animate` and `every` loops work?
> On Linux, both Red and Green use GLib::Timeout loop.
> Although Red is written in C, so calls `g_timeout_add`.
> On Windows, Red uses native SetTimer and Green uses GLib::Timeout.


  thanks for the info - i'll keep fooling around and see if i can come up
with a better way to make this work without draining the cpu...

  Shoes On,

  - j