to run the demos, you go:

./umk demo

The first demo is a webserver written in Felix and is currently
broken pending resolution of the job_queue issue.

The next one is a Felix the Cat cartoon with Janis Joplin
singing. This requires a large media file:

wget http://felix.sf.net/flx_media.tgz
tar -zxvf flx_media.tgz

You also need a working copy of SDL (Simple Direct Media Layer),
and OpenGL, graphics and sound -- it runs in a window by default. 
Press F1 for full screen, and ESC to exit, press any key or mouse click
(or just wait) for the toons to advance. 

The next set of demos are stock SDL tutorial examples,
rewritten using Felix. The demos stop if the mouse isn't
over the screen. ESC to exit. Some of the demos have
control keys.. you'll need to read the code to find
out what the are.

///////////////////////////////////////////////

The use of fthreads here is just about the only demo of why 
Felix ROCKS .. :

/* make our communication channels */
var keyboard = mk_schannel[SDL_keysym] ();
var active = mk_schannel[SDL_ActiveEvent] ();
var resize = mk_schannel[SDL_ResizeEvent] ();
var clicks = mk_schannel[int] ();
var rotation = mk_schannel[int] ();

/* start up the fthreads and plug them together */
spawn_fthread { dispatch_event (keyboard, active, resize); };
spawn_fthread { resizechan resize; };
spawn_fthread { activechan active; };
spawn_fthread { keychan keyboard; };

spawn_fthread { drawchan (clicks, the Drawing); };
spawn_fthread { framerate (clicks, 0.05); };
spawn_fthread { execute (rotation, the rotate); };
spawn_fthread { framerate (rotation, 0.01); };

No callbacks. totally modular. Uses old fashioned bidirectional
fchannels.. the connection diagram is:

/* LINEAR CONTROL MODEL: CANNOT DEADLOCK 
  ~~> async/sync connection
  --> sync/sync connection
  
  SDL_event ~~> dispatcher 
                --> resize handler
                --> active handler
                --> key handler
  timer ~~> framerate --> draw                
             rotationrate --> rotate
*/

Here's the framerate controller:

/* write ticks at the desired framerate */
proc framerate (x:schannel[int], framerate:double)
{
  whilst true do
    Faio::sleep$ clock, framerate;
    write (x,1);
  done;
}

DUH.. 

notice carefully .. the sleep blocks this calling fthread.
And so does the write on the clicks channel (now, why
did I call it clicks .. it's a clock, it should be named ticks!)

proc drawchan(x:schannel[int], drawing:1->0)
{
  whilst true do 
    var &k : int <- read x;
    draw drawing;
  done;
}

synchronises drawing with the clock by reading the ticks
generated by the timer.

The point is .. the two routines are entirely independent:
the ONLY coupling is via the channel. In fact, these
are coroutines: they interleave control, and the 
async I/O systems interleaves THAT with asynchronous
events (well .. a clock is precisely not asynchronous
but you know what i mean .. :)



-- 
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Felix-language mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/felix-language

Reply via email to