;; -*- Mode: LISP; Syntax: Common-Lisp; Package: (USER); -*-


;*****************************
;* TIMING FUNCTIONS
;*****************************

(in-package 'USER)

(defvar *time-offset* 0 "Maintains diff. betw. speech and local clock.")

(defun reactive-time-base ()
  "Returns time in hundreds of seconds (centiceconds).
   Changed to hundredth of a second 5/23/95." ;for compatibility.
  (-  (round (/ (get-internal-real-time) 
		(/ internal-time-units-per-second 100)))
      *time-offset*)) ;This is subtracted to synchronize to speech & body.

(defun rtb ()
  "Returns time in hundreds of seconds (centiseconds)."
  (reactive-time-base))

(defun dialogue-time ()
  (reactive-time-base))

(defun dt ()
  (reactive-time-base))

(defun time-stamp ()
  "Returns time in hundreds of seconds (centiceconds).
   Changed to hundredth of a second 5/23/95." ;for compatibility.
  (-  (round (/ (get-internal-real-time) 
		(/ internal-time-units-per-second 100)))
      *time-offset*)) ;This is subtracted to synchronize to speech & body.

(defun local-sec-time ()
  (round (/ (get-internal-real-time)
            internal-time-units-per-second)))

(defun get-the-time-now ()
  (round (/ (get-internal-real-time)
	    (/ internal-time-units-per-second 1000))))

(defun local-msec-time () ;Return local time in ms.
  (round (/ (get-internal-real-time)
	    (/ internal-time-units-per-second 100))))

(defun AHIG-time-base ()
  "Returns time in 100/sec."
  (round (/ (get-internal-real-time)
            (/ internal-time-units-per-second 1000))))

;(defun get-AHIG-style-time ()
;  (setf *now* (/ (get-internal-real-time) 10000))  ; read the current time and change it to 1/100 sec.
;  (setf curr-time (truncate (- *now* *t-constant*)))     ; make the two times identical in form
;  (if (>= curr-time (second (first script-buff)))  ; script-buff is global
;      (pop script-buff)))                          ; remove the first word and time from script-buff

;*************************************************************
; This is the timer used for replaying an interaction verbatim.
;*************************************************************
; Kris, 7/14/93
; Kris, 5/22/95

; *t-constant* is the difference betw real-time and current event
;(setf *t-constant* first time-code to be received)

(defun poll-script ()  
  (setf *now* (/ (get-internal-real-time) 10000))  ; read the current time and change it to 1/100 sec.
  (setf curr-time (truncate (- *now* *t-constant*)))     ; make the two times identical in form
  (if (>= curr-time (second (first script-buff))) ; script-buff is global
      (pop script-buff)))                         ; remove the first word and time from script-buff
       
;*************************************************************
