www.delorie.com/gnu/docs/xaos/xaos_40.html   search  
Buy GNU books!

An fast realtime interactive fractal zoomer

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.5.1 What is what

Timer library operates with timers. They should be created, you should measuere time since last reset, pause them or set handler and interval. But handler is not activat at gived interval yet. Since timer library is not asynchronous, you must activate them.

For activating is used groups. You should provess group at some place in your program. Then all timers in group are checked and their handlers activated if required. When time spent since last activation is higher than interval, handler is activated more times. Also interval to next invocation is calculated to keep freqency. Simple scheduling is performed at handler -- handler is activated just once and then all other timers are checked before it is activated again. You should also define an multihandler -- handler that is activated just once and receives argument how many intervals has left.

There is two special groups -- asyncgroup. Timers in this group are activated asynchornously like from interrupt. It is not recomended to use it, since it brings many problems and usually isn't required. Also it does not work at many platforms. Syncgroup is the default group. Program is expected to process is quite often. In case you don't need to use more groups, you should use this one.

Time in timerlib is bit strange, since it does not flow continuously but jumps. It is updated every time you call tl_updatetime. I used this way in order to minimize context switches but later I found this scheme very usefull, since you should lookup timer, do something and then reset it and don't wory about time spend between lookup and reset since it is 0 in case you did not called tl_updatetime. This helps to keep freqency of timers exact w/o any errors caused by such situations. At the other hand you need to call tl_updatetime at least once in your main loop.

Maybe you don't know why to create more groups, but I found it quite usefull. For example an autopilot in XaoS has such special group -- I need to call it approx. every 1/20 of second but just at one place in program. Invoking of autopilot when caluclation is active should produce incorrect results, so I have special group for autopilot and process just at one place where I am sure it is safe.

Timers should be also emulated. You should stop them and then control flow of time for given timer. This should be quite usefull for example when you want precalculate animation at given framerate.

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

  webmaster     delorie software   privacy  
  Copyright 2003   by The Free Software Foundation     Updated Jun 2003