[Reality] Autonomous Events

Glyph Lefkowitz glyph@twistedmatrix.com
Wed, 22 Dec 1999 22:43:31 -0500 (EST)


On Wed, 22 Dec 1999 sneftel@popmail.com wrote:

> Is there any way to make a handler or something run 

Yes.

> at short intervals?

No.

> calling HandleDelayedEvent() from within the handler itself might work
> (would it?)

Yes.

> but the smallest resolution is 1 tick.

Yes.

OK, now for the explanations :-)

First of all, Twisted Reality and the games that I intended to design with
it were supposed to be relatively independant of typing speed.  It might
sometimes require you to react to something (being idle can be bad for
you) but the idea is that you shouldn't have to bang out a long sentence
quickly.  Some reactions might be as complex as 'untie rope; stand up; go
north'.

Second, handling events that often is really inefficient and usually
annoying.  Why would you want to see a duck quack every 3 seconds? Every
30 seconds is QUITE enough, and you get the impression it's really
quacking a lot that way, without cluttering up the event window and
spewing 10x as much bandwidth.  It's always been sufficient (in the games
we've worked on so far) to do something else.

> e.g., what about a butler taking a player's coat about 3 seconds after
> they walk in? or a duck quacking every 1-8 seconds randomly?

For your first example: what if I don't want the butler to take my coat? I
sure would like it if I had the opportunity to dodge him, or react in some
way to his declared intention of coat-taking.  10*PI seconds is plenty
time for even a slow typist, but not so horribly long that you'll have to
sit around and wait for things to happen.

For your second: this is why I made this decision in the first place =).
Of course, the first time I implemented event handlers, the first thing I
did was make a little repeating ditty, to run once a second.  I try not to
be authoritative with the API, but in this case:

If you want something to happen every 3 seconds in a world where someone
has to type to respond, you are probably writing a bad game.

I will stick by that statement.

If I ever have to eat my words, though, you can use the undocumented
capacity for using a handleDelayedEvent of 0 ticks -- this will probably
handle your event every 3 seconds or so =)

> Ben Sunshine-Hill

> P.S. I notice from the API docs that a tick is 10*pi seconds. Just out
> of curiosity, why?

It's easier to implement quantum flux capacity w/o disturbing the
space/time/datastream that way.  And you get an increased influx of
bogons.  In case you were curious, the event-checking thread runs every E
seconds.

----
The Tao is like a glob pattern:             It is masked but always present.
used but never used up.                     I don't know who built to it.
It is like the extern void:                 It came before the first kernel.
filled with infinite possibilities.         [glyph@twistedmatrix.com]