chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] State machine using call/cc


From: Joel Reymont
Subject: Re: [Chicken-users] State machine using call/cc
Date: Wed, 8 Dec 2004 17:55:25 +0000

I just had an epiphany about this! The C++/Scheme interface can be viewed
as a browser/web server interaction. C++ is the browser here, sending
requests/events into Scheme (web server). 

The whole thing then looks like the "Modal Web Server Example" by Chris
Double. Of course that does not have much to do with state machines but...

I could write the player "machine" as a loop like this:

(while (player-not-kicked-out-or-quits-himself)
    (process-event (request-event)))

Process event would return the sexp that C++ is looking for and request
event would do the call/cc and save the context just like "show page" in
the modal web server.

Game processing could have several sequential loops for each "state" and
within those loops it would loop through the player list. Something like
this...

(while (not-enough-players)
    ;; request event
    ;; only process player joined and player left events
    (wait-for-player-to-come-in)) 

(while (15-second-timer-is-still-running)
    ;; save as above but also check 
    ;; for player timer expiration
    (process-player-joins-and-player-leaves) 

The state functions/loops would call each other recursively like Ed
suggested. 

It does not solve the problem of how to push events from Scheme to C++
but let me start a separate thread about it. 

    Thanks, Joel






reply via email to

[Prev in Thread] Current Thread [Next in Thread]