2 * $Logfile: /Freespace2/code/Io/Timer.h $
7 * Include file for timer stuff
10 * Revision 1.1 2002/05/03 03:28:12 root
14 * 3 5/17/99 6:03p Dave
15 * Added new timing code. Put in code to allow camera speed zooming.
17 * 2 10/07/98 10:53a Dave
20 * 1 10/07/98 10:49a Dave
22 * 11 4/14/98 2:26p Hoffoss
23 * Removed function prototype that doesn't exist anymore.
25 * 10 9/11/97 7:12p Hoffoss
26 * Added more functionality to training sexp handling code.
28 * 9 8/05/97 10:18a Lawrance
29 * my_rand() being used temporarily instead of rand()
31 * 8 7/29/97 5:30p Lawrance
32 * move gettime() from keyboard module to timer module
34 * 7 7/16/97 4:42p Mike
35 * Make afterburner shake viewer, not ship.
36 * Shake for limited time.
37 * Add timestamp_until() function to timer library.
39 * 6 6/26/97 12:05p Allender
40 * fixed timestamp_valid macro
42 * 5 2/17/97 5:18p John
43 * Added a bunch of RCS headers to a bunch of old files that don't have
54 //==========================================================================
55 // This installs the timer services and interrupts at the rate specified by
56 // count_val. If 'function' isn't 0, the function pointed to by function will
57 // be called 'freq' times per second. Should be > 19 and anything around
58 // 2-3000 is gonna start slowing down the system. Count_val should be
59 // 1,193,180 divided by your target frequency. Use 0 for the normal 18.2 Hz
62 #define TIMER_FREQUENCY 1193180
64 extern void timer_init();
65 extern void timer_close();
66 extern void timer_set_rate(int count_val);
67 extern void timer_set_function( void * function );
69 //==========================================================================
70 // These functions return the time since the timer was initialized in
71 // some various units. The total length of reading time varies for each
72 // one. They will roll around after they read 2^32.
73 // There are milliseconds, milliseconds times 10, milliseconds times 100,
74 // and microseconds. They time out after 1000 hrs, 100 hrs, 10 hrs, and
75 // 1 hr, respectively.
77 extern fix timer_get_fixed_seconds(); // Rolls about every 9 hours...
78 extern fix timer_get_fixed_secondsX(); // Assume interrupts already disabled
79 extern fix timer_get_approx_seconds(); // Returns time since program started... accurate to 1/120th of a second
80 extern int timer_get_milliseconds(); //
81 extern int timer_get_microseconds();
83 //==========================================================================
84 // Use to access the BIOS ticker... ie... i = TICKER
85 void timer_delay(fix seconds);
88 //=================================================================
89 //=================================================================
90 // T I M E S T A M P F U N C T I O N S
91 //=================================================================
92 //=================================================================
94 // NEVER USE THIS DIRECTLY!!! IF YOU REALLY NEED IT, THEN:
95 // call timestamp(0) and use TIMESTAMP_FREQUENCY to scale it.
96 extern int timestamp_ticker;
98 // You shouldn't use the output of timestamp() directly,
99 // but if you have to, use the TIMESTAMP_FREQUENCY to
100 // scale it correctly.
101 #define TIMESTAMP_FREQUENCY 1000
103 // Call this at least every 600 hours, I would
104 // say at the start of each level should do it.
105 extern void timestamp_reset();
107 // Call this once every frame with the frametime.
108 extern void timestamp_inc(float frametime);
110 // To do timing, call this with the interval you
111 // want to check. Then, pass this to timestamp_elapsed
112 // to see if delta_ms time has elapsed. If delta_ms is
113 // zero, the next call to timestamp_elapsed will always
114 // return 1. If delta_ms is less than zero, then this is
115 // considered an invalid timestamp and all calls to
116 // timestamp_elapsed will return 0.
118 // pass -1 for an invalid timestamp that will never time out
119 // pass 0 for a timestamp that is instantly timed out
120 // pass n > 0 for timestamp n milliseconds in the future.
121 int timestamp(int delta_ms );
123 // use this call to get the current counter value (which represents the time at the time
124 // this function is called). I.e. it doesn't return a count that would be in the future,
125 // but the count that is right now.
128 // gets a timestamp randomly between a and b milliseconds in
130 #define timestamp_rand(a,b) timestamp((myrand()%((b)-(a)+1))+(a))
132 // Example that makes a ship fire in 1/2 second
135 // ship->next_fire = timestamp(500);
137 // if (fire && timestamp_elapsed(ship->next_fire))
140 #define timestamp_elapsed( stamp ) ( (stamp!=0) ? (timestamp_ticker >= (stamp) ? 1 : 0) : 0 )
142 #define timestamp_valid(stamp) ((stamp==0) ? 0 : 1 )
144 // Returns millliseconds until timestamp will elapse.
145 int timestamp_until(int stamp);
147 // checks if a specified time (in milliseconds) has elapsed past the given timestamp (which
148 // should be obtained from timestamp() or timestamp(x) with a positive x)
149 int timestamp_has_time_elapsed(int stamp, int time);
152 // timing functions -------------------------------------------------------------------------------
154 // start timing frame stuff
155 void timing_frame_start();
157 // done timing the frame
158 void timing_frame_stop();
160 // get the total frame time in microseconds
161 int timing_frame_total();
163 // time an individual event
164 void timing_event_start(char *event_name);
166 // stop timing an event
167 void timing_event_stop(char *event_name);
169 // get the total time for an event in microseconds
170 int timing_event_total(char *event_name);
172 // get the percentage of total frametime for the event (0.0 to 1.0)
173 float timing_event_pct(char *event_name);
176 void timing_display(int x, int y);