Main Page | Data Structures | Directories | File List | Data Fields | Globals

timer.c File Reference

#include <time.h>
#include "cliglobs.h"
#include "mouse.h"
#include "geometry.h"
#include "lchelp.h"
#include "timer.h"

Go to the source code of this file.

Functions

void pause_handler (int x, int y, int button)
void slow_handler (int x, int y, int button)
void medium_handler (int x, int y, int button)
void fast_handler (int x, int y, int button)
void lc_usleep (unsigned long t)
void reset_start_time (void)
void get_real_time (void)
void init_timer_buttons (void)
void select_fast (void)
void select_medium (void)
void select_slow (void)
void select_pause (void)

Variables

timeval lc_timeval
int real_start_time
Mouse_Handlepause_handle
Mouse_Handleslow_handle
Mouse_Handlemedium_handle
Mouse_Handlefast_handle
long real_time = 0


Function Documentation

void fast_handler int  x,
int  y,
int  button
 

Definition at line 151 of file timer.c.

00152 {
00153     if (button == LC_MOUSE_RIGHTBUTTON) {
00154         activate_help ("fast.hlp");
00155     } else {
00156         select_fast ();
00157     }
00158 }

void get_real_time void   ) 
 

Definition at line 95 of file timer.c.

00096 {
00097 #if defined (WIN32)
00098   const int CLOCKS_PER_MILLISECOND = CLOCKS_PER_SEC / 1000;
00099   real_time = (long) (clock () / CLOCKS_PER_MILLISECOND);
00100 #else
00101   gettimeofday (&lc_timeval, 0);
00102   real_time = (lc_timeval.tv_sec - real_start_time) * 1000
00103     + (lc_timeval.tv_usec / 1000);
00104 #endif
00105 }

void init_timer_buttons void   ) 
 

Definition at line 110 of file timer.c.

00111 {
00112     pause_handle = mouse_register(&scr.pause_button, &pause_handler);
00113     slow_handle = mouse_register(&scr.slow_button, &slow_handler);
00114     medium_handle = mouse_register(&scr.med_button, &medium_handler);
00115     fast_handle = mouse_register(&scr.fast_button, &fast_handler);
00116 }

void lc_usleep unsigned long  t  ) 
 

Definition at line 67 of file timer.c.

00068 {
00069 #if defined (WIN32)
00070   /* This function will usually sleep too long.  For example, if t == 0 
00071      (e.g. 1 usec), thread will sleep for the remainder of its timeslice, 
00072      which might be 20 ms.
00073    */
00074   SleepEx (t / 1000, FALSE);
00075 #else
00076   struct timeval timeout;
00077   timeout.tv_sec = t / 1000000;
00078   timeout.tv_usec = t - 1000000 * timeout.tv_sec;
00079   select (1, NULL, NULL, NULL, &timeout);
00080 #endif
00081 }

void medium_handler int  x,
int  y,
int  button
 

Definition at line 141 of file timer.c.

00142 {
00143     if (button == LC_MOUSE_RIGHTBUTTON) {
00144         activate_help ("medium.hlp");
00145     } else {
00146         select_medium ();
00147     }
00148 }

void pause_handler int  x,
int  y,
int  button
 

Definition at line 121 of file timer.c.

00122 {
00123     if (button == LC_MOUSE_RIGHTBUTTON) {
00124         activate_help ("pause.hlp");
00125     } else {
00126         select_pause ();
00127     }
00128 }

void reset_start_time void   ) 
 

Definition at line 84 of file timer.c.

00085 {
00086 #if !defined (WIN32)
00087   if (gettimeofday (&lc_timeval, 0) != 0)
00088     do_error ("Can't get timeofday");
00089   real_start_time = lc_timeval.tv_sec;
00090 #endif
00091 }

void select_fast void   ) 
 

Definition at line 161 of file timer.c.

00162 {
00163     hide_mouse ();
00164     pause_flag = 0;
00165     draw_pause (0);
00166     slow_flag = 0;
00167     draw_slow (0);
00168     med_flag = 0;
00169     draw_med (0);
00170     fast_flag = 1;
00171     draw_fast (1);
00172     redraw_mouse ();
00173 }

void select_medium void   ) 
 

Definition at line 176 of file timer.c.

00177 {
00178     hide_mouse ();
00179     pause_flag = 0;
00180     draw_pause (0);
00181     slow_flag = 0;
00182     draw_slow (0);
00183     med_flag = 1;
00184     draw_med (1);
00185     fast_flag = 0;
00186     draw_fast (0);
00187     redraw_mouse ();
00188 }

void select_pause void   ) 
 

Definition at line 206 of file timer.c.

00207 {
00208     if (pause_flag) {
00209         /* unpause it */
00210         if (fast_flag)
00211             select_fast ();
00212         else if (med_flag)
00213             select_medium ();
00214         else if (slow_flag)
00215             select_slow ();
00216         else
00217             select_medium ();
00218     } else {
00219         /* pause it */
00220         hide_mouse ();
00221         pause_flag = 1;
00222         draw_pause (1);
00223         draw_slow (0);
00224         draw_med (0);
00225         draw_fast (0);
00226         redraw_mouse ();
00227     }
00228 }

void select_slow void   ) 
 

Definition at line 191 of file timer.c.

00192 {
00193     hide_mouse ();
00194     pause_flag = 0;
00195     draw_pause (0);
00196     slow_flag = 1;
00197     draw_slow (1);
00198     med_flag = 0;
00199     draw_med (0);
00200     fast_flag = 0;
00201     draw_fast (0);
00202     redraw_mouse ();
00203 }

void slow_handler int  x,
int  y,
int  button
 

Definition at line 131 of file timer.c.

00132 {
00133     if (button == LC_MOUSE_RIGHTBUTTON) {
00134         activate_help ("slow.hlp");
00135     } else {
00136         select_slow ();
00137     }
00138 }


Variable Documentation

Mouse_Handle* fast_handle
 

Definition at line 46 of file timer.c.

struct timeval lc_timeval
 

Definition at line 39 of file timer.c.

Mouse_Handle* medium_handle
 

Definition at line 45 of file timer.c.

Mouse_Handle* pause_handle
 

Definition at line 43 of file timer.c.

int real_start_time
 

Definition at line 40 of file timer.c.

long real_time = 0
 

Definition at line 51 of file timer.c.

Mouse_Handle* slow_handle
 

Definition at line 44 of file timer.c.


Generated on Sun Dec 26 11:23:42 2004 for lincity by  doxygen 1.3.9.1