Difference between revisions of "Manual:DIL Manual/heartbeat"
Jump to navigation
Jump to search
(XML import) |
(checked against the compiler and the interpreter; example compiles) |
||
| Line 1: | Line 1: | ||
| − | + | = heartbeat = | |
| − | + | '''Variable''' (integer, read/write). | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | + | heartbeat : integer | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | + | 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>. | |
| + | |||
| + | == 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
Contents
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(orWAIT_SEC, the same 4):heartbeat := PULSE_SEC * 30;is 30 seconds. - The new value takes effect when the program next waits. Anything below
PULSE_SECis raised toPULSE_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.
pausewaits for the next tick, so withheartbeat := PULSE_SEC * 90a pause can take 90 seconds, and underprioritythe 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_RANTIMEinpause).- A function called as
name@zoneshares its caller's heartbeat; quests.zon's functions save it and put it back (heartbeat := phb;). - On a running game a god's
wtimewarpmakes 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.