Workflows in Ruby

I am writing a simple memory game using ruby ​​+ qt (trying to get away from C ++ for a while ...)
To allow the X-second timeout to view two open parts, I need either timers or do work in the background thread.

What is the easiest way to realize this without reinventing the wheel?
Ruby flows? Qt threads? Qt timers?

+6
ruby qtruby
source share
3 answers

I don't know if this is the best solution, but:

block=Proc.new{ Thread.pass } timer=Qt::Timer.new(window) invoke=Qt::BlockInvocation.new(timer, block, "invoke()") Qt::Object.connect(timer, SIGNAL("timeout()"), invoke, SLOT("invoke()")) timer.start(1) 

Makes ruby ​​flows! Customize start (x) for your needs.

+4
source share

The decision to choose QT or Ruby threads / timers is probably personal, but you should remember that Ruby threads are green. This means that they are implemented by the Ruby interpreter and cannot scale across multiple processor cores. Although for a simple timer game, I assume you probably don't need to worry about that.

Despite the somewhat unrelated Midiator , the Ruby interface for MIDI devices uses Ruby threads to implement a timer .

Also, check out Leslie Wiljoen 's article , he says that Ruby threads are blocked when QT form widgets wait for input. It also provides some sample code for implementing QT timers (which look pretty easy and are suitable for what you are doing).

+2
source share

Thanks.

Solved it using QTimer :: singleShot. Enough - in my case, the timer fires once every time when two tiles are displayed.

0
source share

All Articles