Pol  Revision:cb584c9
polclock.h
Go to the documentation of this file.
1 
7 //
9 // polclock.h - clock() and time() wrappers for clock stretching
10 //
11 // This is mostly for profiling, so that timed actions (ie attacks) don't
12 // overwhelm everything else. Profiled runs seem to run at about 1/20th
13 // normal speed. This way, you can run the system such that even though
14 // the RPMs are, say, 20, the profiling is similar to an RPM=400 system.
15 //
17 #ifndef POLCLOCK_H
18 #define POLCLOCK_H
19 
20 #include <time.h>
21 
22 namespace Pol
23 {
24 namespace Core
25 {
26 typedef int polclock_t;
27 typedef int polticks_t;
28 
29 const polclock_t POLCLOCKS_PER_SEC = 100;
30 const unsigned POLCLOCK_DIV = ( CLOCKS_PER_SEC / POLCLOCKS_PER_SEC );
31 
32 void start_pol_clocks();
33 void pause_pol_clocks();
34 void restart_pol_clocks();
35 
36 void pol_sleep_ms( unsigned int millis );
37 
38 inline bool timer_expired( polclock_t timer_until, polclock_t now )
39 {
40  int remaining = timer_until - now;
41  return ( remaining < 0 );
42 }
43 inline polclock_t earliest_timer( polclock_t timer1_until, polclock_t timer2_until )
44 {
45  int diff = timer1_until - timer2_until;
46  if ( diff < 0 )
47  return timer1_until;
48  else
49  return timer2_until;
50 }
51 
52 polclock_t polclock();
53 time_t poltime();
54 
55 inline polticks_t polticks_t_to_ms( polticks_t ticks )
56 {
57  return ticks * 10;
58 }
59 
61 {
62 public:
65 };
66 
67 void polclock_checkin();
68 }
69 }
70 #endif
void pol_sleep_ms(unsigned int millis)
Definition: polclock.cpp:46
const unsigned POLCLOCK_DIV
Definition: polclock.h:30
polclock_t polclock()
Definition: polclock.cpp:72
polclock_t earliest_timer(polclock_t timer1_until, polclock_t timer2_until)
Definition: polclock.h:43
polticks_t polticks_t_to_ms(polticks_t ticks)
Definition: polclock.h:55
void start_pol_clocks()
Definition: polclock.cpp:111
int polclock_t
Definition: polclock.h:26
time_t poltime()
Definition: polclock.cpp:102
int polticks_t
Definition: polclock.h:27
void polclock_checkin()
Definition: pol.cpp:520
bool timer_expired(polclock_t timer_until, polclock_t now)
Definition: polclock.h:38
Definition: berror.cpp:12
const polclock_t POLCLOCKS_PER_SEC
Definition: polclock.h:29
void restart_pol_clocks()
Definition: polclock.cpp:126
void pause_pol_clocks()
Definition: polclock.cpp:121