Difference between revisions of "Manual:DIL Manual/heartbeat"

From DikuMUD Wiki
Jump to navigation Jump to search
(XML import)
 
(checked against the compiler and the interpreter; example compiles)
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
 +
= heartbeat =
 +
'''Variable''' (integer, read/write).
  
 +
heartbeat : integer
  
−
<span id="hb"></span>
+
How often the program's tick comes, in quarter seconds: <code>PULSE_SEC</code> (4, vme.h) is one second. A program waiting for SFB_TICK, and every <code>pause</code>, waits for it. Each program has its own heartbeat; a new one starts at <code>PULSE_SEC</code>.
−
'heartbeat'
 
−
    This is the DIL programs heartbeat. It can be assigned runtime to
 
−
    change the rate with which SFB_TICK is activated. Do not set it
 
−
    too low, and remember that it is specified in 1/4th of a second.
 
−
    use the constant PULSE_SEC to multiply your wanted delay, for
 
−
    Example:
 
−
      heartbeat := PULSE_SEC*25; /* Tick every 25 seconds */
 
  
−
---~---~---~---~---~---~---~---~---
+
== Notes ==
 +
* Write it as a multiple of <code>PULSE_SEC</code> (or <code>WAIT_SEC</code>, the same 4): <code>heartbeat := PULSE_SEC * 30;</code> is 30 seconds.
 +
* The new value takes effect when the program next waits. Anything below <code>PULSE_SEC</code> is raised to <code>PULSE_SEC</code>: no program ticks more than once a second.
 +
* It is kept in 16 bits without a sign: the longest heartbeat is 65535 (about 4.5 hours), larger values wrap round, and a negative one becomes a very long heartbeat. Reading it back gives a negative number for values from 32768 up.
 +
* <code>pause</code> waits for the next tick, so with <code>heartbeat := PULSE_SEC * 90</code> a pause can take 90 seconds, and under <code>priority</code> the unit's other programs wait all that time. Shorten the heartbeat around pauses, as the example does. Just after a change the next tick comes at a random point between half and one and a half heartbeats (<code>SFB_RANTIME</code> in <code>pause</code>).
 +
* A function called as <code>name@zone</code> shares its caller's heartbeat; quests.zon's functions save it and put it back (<code>heartbeat := phb;</code>).
 +
* On a running game a god's <code>wtimewarp</code> makes the ticks come without delay, to try out long heartbeats.
 +
 
 +
== Example ==
 +
<pre>
 +
dilbegin broom_seller();
 +
code
 +
{
 +
  heartbeat := PULSE_SEC * 60;
 +
 
 +
  :start:
 +
  wait(SFB_TICK, TRUE);
 +
  heartbeat := PULSE_SEC * 3;
 +
  exec("say Brooms! Fine brooms!", self);
 +
  pause;
 +
  exec("say Two copper each!", self);
 +
  heartbeat := PULSE_SEC * 60;
 +
  goto start;
 +
}
 +
dilend
 +
</pre>
 +
A street seller who calls out once a minute, with a three second pause between the two lines.
 +
 
 +
== See also ==
 +
* [[Manual:DIL Manual/wait()|wait()]]
 +
* [[Manual:DIL Manual/priority|priority]]
 +
* [[Manual:DIL Manual/SFB TICK|SFB TICK]]
 +
* [[Manual:DIL Manual/mudhour|mudhour]]

Latest revision as of 23:19, 14 November 2026

heartbeat

Variable (integer, read/write).

heartbeat : integer

How often the program's tick comes, in quarter seconds: PULSE_SEC (4, vme.h) is one second. A program waiting for SFB_TICK, and every pause, waits for it. Each program has its own heartbeat; a new one starts at PULSE_SEC.

Notes

  • Write it as a multiple of PULSE_SEC (or WAIT_SEC, the same 4): heartbeat := PULSE_SEC * 30; is 30 seconds.
  • The new value takes effect when the program next waits. Anything below PULSE_SEC is raised to PULSE_SEC: no program ticks more than once a second.
  • It is kept in 16 bits without a sign: the longest heartbeat is 65535 (about 4.5 hours), larger values wrap round, and a negative one becomes a very long heartbeat. Reading it back gives a negative number for values from 32768 up.
  • pause waits for the next tick, so with heartbeat := PULSE_SEC * 90 a pause can take 90 seconds, and under priority the unit's other programs wait all that time. Shorten the heartbeat around pauses, as the example does. Just after a change the next tick comes at a random point between half and one and a half heartbeats (SFB_RANTIME in pause).
  • A function called as name@zone shares its caller's heartbeat; quests.zon's functions save it and put it back (heartbeat := phb;).
  • On a running game a god's wtimewarp makes the ticks come without delay, to try out long heartbeats.

Example

dilbegin broom_seller();
code
{
   heartbeat := PULSE_SEC * 60;

   :start:
   wait(SFB_TICK, TRUE);
   heartbeat := PULSE_SEC * 3;
   exec("say Brooms! Fine brooms!", self);
   pause;
   exec("say Two copper each!", self);
   heartbeat := PULSE_SEC * 60;
   goto start;
}
dilend

A street seller who calls out once a minute, with a three second pause between the two lines.

See also