<!-- MHonArc v2.4.4 --> <!--X-Subject: Re: Event-driven? --> <!--X-From-R13: ptNnzv-pt.UenlEntr.Sqzbagba.OP.QO (Quevf Uenl) --> <!--X-Date: from tacitus.globecomm.net [207.51.48.7] by mx4.ibm.net id 860264051.44900-1 Sat Apr 5 18:14:11 1997 --> <!--X-Message-Id: 9704051739.7wvb@ami-cg.GraySage.Edmonton.AB.CA --> <!--X-Content-Type: text/plain --> <!--X-Head-End--> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"> <html> <head> <title>MUD-Dev message, Re: Event-driven?</title> <!-- meta name="robots" content="noindex,nofollow" --> <link rev="made" href="mailto:cg#ami-cg,GraySage.Edmonton.AB.CA"> </head> <body background="/backgrounds/paperback.gif" bgcolor="#ffffff" text="#000000" link="#0000FF" alink="#FF0000" vlink="#006000"> <font size="+4" color="#804040"> <strong><em>MUD-Dev<br>mailing list archive</em></strong> </font> <br> [ <a href="../">Other Periods</a> | <a href="../../">Other mailing lists</a> | <a href="/search.php3">Search</a> ] <br clear=all><hr> <!--X-Body-Begin--> <!--X-User-Header--> <!--X-User-Header-End--> <!--X-TopPNI--> Date: [ <a href="msg00018.html">Previous</a> | <a href="msg00021.html">Next</a> ] Thread: [ <a href="msg00015.html">Previous</a> | <a href="msg00028.html">Next</a> ] Index: [ <A HREF="author.html#00019">Author</A> | <A HREF="#00019">Date</A> | <A HREF="thread.html#00019">Thread</A> ] <!--X-TopPNI-End--> <!--X-MsgBody--> <!--X-Subject-Header-Begin--> <H1>Re: Event-driven?</H1> <HR> <!--X-Subject-Header-End--> <!--X-Head-of-Message--> <UL> <LI><em>To</em>: <A HREF="mailto:mud-dev#null,net">mud-dev#null,net</A></LI> <LI><em>Subject</em>: Re: Event-driven?</LI> <LI><em>From</em>: <A HREF="mailto:cg#ami-cg,GraySage.Edmonton.AB.CA">cg#ami-cg,GraySage.Edmonton.AB.CA</A> (Chris Gray)</LI> <LI><em>Date</em>: Sat, 5 Apr 97 10:39:21 MST</LI> </UL> <!--X-Head-of-Message-End--> <!--X-Head-Body-Sep-Begin--> <HR> <!--X-Head-Body-Sep-End--> <!--X-Body-of-Message--> <PRE> [Michael H:] :Precisely how does an event-driven mud work? I understand the idea, but :I don't see how it could be run efficiently, and be coded neatly... : :Can somebody enlighten me? Nathan's explanation was quite detailed, so I'll give a simpler arm-waving one. I have a list of events that need to be scheduled in the future. The list is sorted by increasing date/time (I use an internal seconds count). Each element also contains a pointer to the MUD code to run, and a pointer to the PC/NPC on who's behalf it is to be run. Whenever the first, or a new earliest, event is added, the server starts or modifies a timer for that time interval. The server then goes back to doing whatever it was doing before (typically, it continues executing the MUD code that just scheduled the event). When the server goes idle (does its main 'select' call), that call can be woken up by the timer signal. The server also occasionally checks the time when it is busy, to see if it is getting a long way behind. If so, it can stop processing incoming requests and do some timed events for a while. To process a timed event, it just sets the current identity to that in the request, deletes the request (important!), and then calls the MUD code of the request. It loops through the earliest events until it comes to one that isn't due to run yet (re-checking the current time occasionally, since doing all of this does consume time), or until it decides it has done enough catching up for now and should go back to input requests. So, to have an NPC that does things occasionally, the MUD code looks something like this: /* the routine which Frog executes on each "step": */ define tp_frog proc frogStep()void: int direction; if not ClientsActive() then After(60.0, frogStep); else direction := Random(12); if TryToMove(direction) then MachineMove(direction); fi; After(IntToFixed(10 + Random(10)), frogStep); fi; corp; (This is from an example file on NPC's that is part of my docs.) The key here is the 'After' calls. They schedule an event for the given time (in seconds) after the current time. Note that the MUD code they are scheduling is the same code that is currently executing - this is quite common on my system. -- Chris Gray cg#ami-cg,GraySage.Edmonton.AB.CA </PRE> <!--X-Body-of-Message-End--> <!--X-MsgBody-End--> <!--X-Follow-Ups--> <HR> <!--X-Follow-Ups-End--> <!--X-References--> <!--X-References-End--> <!--X-BotPNI--> <UL> <LI>Prev by Date: <STRONG><A HREF="msg00018.html">Re: Random thoughts</A></STRONG> </LI> <LI>Next by Date: <STRONG><A HREF="msg00021.html">database stuff</A></STRONG> </LI> <LI>Prev by thread: <STRONG><A HREF="msg00015.html">Re: Event-driven?</A></STRONG> </LI> <LI>Next by thread: <STRONG><A HREF="msg00028.html">Re: Event-driven?</A></STRONG> </LI> <LI>Index(es): <UL> <LI><A HREF="index.html#00019"><STRONG>Date</STRONG></A></LI> <LI><A HREF="thread.html#00019"><STRONG>Thread</STRONG></A></LI> </UL> </LI> </UL> <!--X-BotPNI-End--> <!--X-User-Footer--> <!--X-User-Footer-End--> <ul><li>Thread context: <BLOCKQUOTE><UL> <LI><strong><A NAME="00008" HREF="msg00008.html">Event-driven?</A></strong>, Michael Hohensee <a href="mailto:michael#sparta,mainstream.net">michael#sparta,mainstream.net</a>, Fri 04 Apr 1997, 04:49 GMT <UL> <li><Possible follow-up(s)><br> <LI><strong><A NAME="00010" HREF="msg00010.html">Re: Event-driven?</A></strong>, Adam Wiggins <a href="mailto:nightfall#user1,inficad.com">nightfall#user1,inficad.com</a>, Fri 04 Apr 1997, 11:34 GMT </LI> <LI><strong><A NAME="00011" HREF="msg00011.html">Re: Event-driven?</A></strong>, Nathan Yospe <a href="mailto:yospe#hawaii,edu">yospe#hawaii,edu</a>, Fri 04 Apr 1997, 12:23 GMT </LI> <LI><strong><A NAME="00015" HREF="msg00015.html">Re: Event-driven?</A></strong>, Shawn Halpenny <a href="mailto:rsh#dos,nortel.com">rsh#dos,nortel.com</a>, Fri 04 Apr 1997, 23:05 GMT </LI> <LI><strong><A NAME="00019" HREF="msg00019.html">Re: Event-driven?</A></strong>, Chris Gray <a href="mailto:cg#ami-cg,GraySage.Edmonton.AB.CA">cg#ami-cg,GraySage.Edmonton.AB.CA</a>, Sun 06 Apr 1997, 02:14 GMT </LI> <LI><strong><A NAME="00028" HREF="msg00028.html">Re: Event-driven?</A></strong>, coder <a href="mailto:coder#ibm,net">coder#ibm,net</a>, Mon 07 Apr 1997, 01:05 GMT </LI> <LI><strong><A NAME="00030" HREF="msg00030.html">Re: Event-driven?</A></strong>, coder <a href="mailto:coder#ibm,net">coder#ibm,net</a>, Mon 07 Apr 1997, 08:34 GMT </LI> <LI><strong><A NAME="00034" HREF="msg00034.html">Re: Event-driven?</A></strong>, Jon A. Lambert <a href="mailto:jlsysinc#ix,netcom.com">jlsysinc#ix,netcom.com</a>, Mon 07 Apr 1997, 10:53 GMT </LI> </UL> </LI> <LI><strong><A NAME="00007" HREF="msg00007.html">Introduction</A></strong>, Shawn Halpenny <a href="mailto:malachai#iname,com">malachai#iname,com</a>, Fri 04 Apr 1997, 01:37 GMT </LI> </UL></BLOCKQUOTE> </ul> <hr> <center> [ <a href="../">Other Periods</a> | <a href="../../">Other mailing lists</a> | <a href="/search.php3">Search</a> ] </center> <hr> </body> </html>