The improved Clock code is more or less done now (it's currently in my next branch on Github, if you're curious). The changes so far:
Clock.delaywork better in multithreaded apps (when given a yield value).
Clock#yieldattributes to tweak the delay used in
Clock#calibrate_granularity(whee, long English method names) to calculate a good granularity for the current system. This reduces unnecessary CPU usage a lot on systems with accurate timers, especially Linux and Mac.
- The framerate monitoring code for
Clock#framerateis much improved, giving more accurate and responsive results.
- Added the
ClockTickedevent class. Use
Clock#tickreturn events instead of raw millisecond times. ClockTicked has methods for getting the tick time as milliseconds or seconds.
- Added a new TickTrigger event trigger class. You can use it in your event hooks to detect ClockTicked events.
- You can use the symbol
:tickas a trigger in
HasEventHandler#make_magic_hooksto easily create a TickTrigger.
One further improvement I'm considering is caching ClockTicked events in
Clock#tick. So, basically, Clock would keep a hash of ClockTicked events for each distinct value (integer milliseconds) and just return references to the existing one instead of creating a new one. That should help keep Ruby's garbage collector happy.
I should probably create some specs/regression tests for Clock, too.
I also need to look at other changes to possibly include in 2.5:
- shawn42 created a cool method for drawing thick lines that might be worth including, possibly ported to C.
- singpolyma made a function to get the resolution of the user's display, but due to the sillyness of the underlying SDL function, it only works the way we want it to if there's not a Screen open. I'm not sure how I'll manage to impose consistency on it. Maybe have it return nil or raise an error when there's an open Screen?
- I've had a couple event hook/handler improvements floating around in my head, like named hooks and
make_magic_hooks_for(which works like
make_magic_hooks, but with a hook owner other than self).
- I might write a brief guide to using Clock most effectively.
Anyway, I have some free time this weekend, so Rubygame 2.5 should be out Saturday or Sunday evening.