Nilorea Library

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

All Data Structures Files Functions Variables Typedefs Macros Groups
n_common.c
Go to the documentation of this file.
1
8 #include "n_common.h"
9
13 void PAUSE()
14 {
15
16 char k[ 2 ] = "" ;
17
18 printf( "Press a enter to continue..." );
19
20 fflush( stdin );
21 scanf( "%c", k );
22
23 printf( "\n" );
24 } /* PAUSE(...) */
25
26
27
33 int start_HiTimer( N_TIME *timer )
34 {
35 /* set delta to 0 */
36 timer -> delta = 0;
37
38 #if !defined( LINUX ) && !defined( SOLARIS ) && !defined( AIX )
39 if( QueryPerformanceFrequency( ( LARGE_INTEGER * ) & timer -> freq ) == 0 )
40 return FALSE ;
41 if( QueryPerformanceCounter( &timer -> startTime ) == 0 )
42 return FALSE ;
43 #else
44 if( gettimeofday( &timer -> startTime, 0 ) != 0 )
45 return FALSE ;
46 #endif
47
48 return TRUE ;
49 } /* init_HiTimer(...) */
50
51
52
58 time_t get_usec( N_TIME *timer )
59 {
60 #ifdef WIN32
61 QueryPerformanceCounter( ( LARGE_INTEGER * ) & timer -> currentTime );
62 timer -> delta = 1000000 * ( timer -> currentTime . QuadPart - timer -> startTime . QuadPart ) / timer -> freq . QuadPart ;
63 timer -> startTime = timer -> currentTime ;
64 #else
65 gettimeofday( &timer -> currentTime, 0 );
66 timer -> delta = ( timer -> currentTime . tv_sec - timer -> startTime . tv_sec ) * 1000000 + ( timer -> currentTime . tv_usec - timer -> startTime . tv_usec );
67 timer -> startTime . tv_sec = timer -> currentTime . tv_sec ;
68 timer -> startTime . tv_usec = timer -> currentTime . tv_usec ;
69 #endif
70
71 return timer -> delta;
72 } /* get_usec( ... ) */
73
74
75
81 time_t get_msec( N_TIME *timer )
82 {
83 #ifdef WIN32
84 QueryPerformanceCounter( ( LARGE_INTEGER * ) & timer -> currentTime );
85 timer -> delta = 1000 * ( timer -> currentTime . QuadPart - timer -> startTime . QuadPart ) / timer -> freq . QuadPart ;
86 timer -> startTime = timer -> currentTime ;
87 #else
88 gettimeofday( &timer -> currentTime, 0 );
89 timer -> delta = ( timer -> currentTime . tv_sec - timer -> startTime . tv_sec ) * 1000 + ( timer -> currentTime . tv_usec - timer -> startTime . tv_usec ) / 1000 ;
90 timer -> startTime . tv_sec = timer -> currentTime . tv_sec ;
91 timer -> startTime . tv_usec = timer -> currentTime . tv_usec ;
92 #endif
93
94 return timer -> delta;
95 } /* get_msec(...) */
96
97
98
104 time_t get_sec( N_TIME *timer ){
105 #ifdef WIN32
106 QueryPerformanceCounter( ( LARGE_INTEGER * ) & timer -> currentTime );
107 timer -> delta = ( timer -> currentTime . QuadPart - timer -> startTime . QuadPart ) / timer -> freq . QuadPart ;
108 timer -> startTime = timer -> currentTime ;
109 #else
110 gettimeofday( &timer -> currentTime, 0 );
111 timer -> delta = ( timer -> currentTime . tv_sec - timer -> startTime . tv_sec ) + ( timer -> currentTime . tv_usec - timer -> startTime . tv_usec ) / 1000000 ;
112 timer -> startTime . tv_sec = timer -> currentTime . tv_sec ;
113 timer -> startTime . tv_usec = timer -> currentTime . tv_usec ;
114 #endif
115 return timer -> delta;
116 }/* get_sec(...) */
117
118
119
120 #ifndef NOALLEGRO
121
128 void get_keyboard( char *keybuf , int *cur , int min , int max )
129 {
130 int k = 0;
131
132 if ( keypressed() )
133 {
134 k = ureadkey( NULL );
135
136 if ( k != 0x1b && k != 0x09 && k != 0x00 && k != 0x0d && k != 0x08 && ( *cur ) < max )
137 {
138 usprintf( keybuf + ustrsize( keybuf ) , "%c" , k );
139 ( *cur ) ++;
140 }
141
142 if ( k == 0x08 && (*cur) > min ) /* backspace */
143 {
144 ( *cur ) --;
145 uremove( keybuf , ( *cur ) );
146 }
147 } /* if( keypressed( ... ) ) */
148 } /* get_keyboard(...) */
149
150 /* #ifndef NOALLEGRO */
151 #endif
152