File: tick.tf

package info (click to toggle)
tf5 5.0beta8-7
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 3,800 kB
  • sloc: ansic: 25,492; perl: 103; makefile: 82; sh: 79
file content (49 lines) | stat: -rw-r--r-- 1,294 bytes parent folder | download | duplicates (16)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
;;;; Tick counting
;;;; This file implements several tick counting commands similar to those
;;;; found in tintin, useful on Diku muds.  To use, just /load this file.

;;;; usage:
;;; /tick		Display the time remaining until next tick.
;;; /tickon		Reset and start the tick counter.
;;; /tickoff		Stop the tick counter.
;;; /tickset		Reset and start the tick counter.
;;; /ticksize <n>	Set the tick length to <n> seconds (default is 75).

/loaded __TFLIB__/tick.tf

/set ticksize=75
/set next_tick=0
/set _tick_pid1=0
/set _tick_pid2=0

/def -i tick_warn = /echo % Next tick in 10 seconds.
/def -i tick_action = /echo % TICK

/def -i tick = \
	/if (next_tick) \
		/eval /echo %%% $$[next_tick - $(/time @)] seconds until tick%;\
	/else \
		/echo -e %% Tick counter is not running.%;\
	/endif

/def -i tickon = \
	/tickoff%;\
	/@test next_tick := $(/time @) + ticksize %;\
	/repeat -$[ticksize - 10] 1 \
		/set _tick_pid1=0%%;\
		/tick_warn%;\
        /set _tick_pid1=%?%;\
	/repeat -%ticksize 1 \
		/set _tick_pid2=0%%;\
		/tick_action%%;\
		/tickon%;\
	/set _tick_pid2=%?

/def -i tickoff = \
	/@test _tick_pid1 & (kill(_tick_pid1), _tick_pid1:=0)%;\
	/@test _tick_pid2 & (kill(_tick_pid2), _tick_pid2:=0)%;\
	/set next_tick=0

/def -i tickset	= /tickon %*

/def -i ticksize	= /set ticksize %*