mirror of
https://github.com/abakh/nbsdgames.git
synced 2024-12-04 14:46:22 -05:00
attempt at providing usleep() and round() for Plan9
This commit is contained in:
parent
baea9ad60c
commit
5b46b348c1
@ -16,7 +16,15 @@
|
|||||||
#define HWID WID/2
|
#define HWID WID/2
|
||||||
|
|
||||||
#ifdef Plan9
|
#ifdef Plan9
|
||||||
#define usleep(x) sleep(x/1000000)
|
int usleep(long usec) {
|
||||||
|
int seconds = usec/1000000;
|
||||||
|
long nano = usec*1000 - seconds*1000000;
|
||||||
|
struct timespec sleepy = {0};
|
||||||
|
sleepy.ts_sec = second;
|
||||||
|
sleepy.ts_nsec = nano;
|
||||||
|
nanosleep(&sleepy, (struct timespec *) NULL);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef signed char byte;
|
typedef signed char byte;
|
||||||
|
@ -28,7 +28,15 @@ compile with -lncurses
|
|||||||
#ifdef Plan9
|
#ifdef Plan9
|
||||||
#define len 10
|
#define len 10
|
||||||
#define wid 40
|
#define wid 40
|
||||||
#define usleep(x) sleep(x/1000000)
|
int usleep(long usec) {
|
||||||
|
int seconds = usec/1000000;
|
||||||
|
long nano = usec*1000 - seconds*1000000;
|
||||||
|
struct timespec sleepy = {0};
|
||||||
|
sleepy.ts_sec = second;
|
||||||
|
sleepy.ts_nsec = nano;
|
||||||
|
nanosleep(&sleepy, (struct timespec *) NULL);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef signed char byte;
|
typedef signed char byte;
|
||||||
|
@ -26,7 +26,15 @@ compile with -lncurses
|
|||||||
#ifdef Plan9
|
#ifdef Plan9
|
||||||
#define len 10
|
#define len 10
|
||||||
#define wid 40
|
#define wid 40
|
||||||
#define usleep(x) sleep(x/1000000)
|
int usleep(long usec) {
|
||||||
|
int seconds = usec/1000000;
|
||||||
|
long nano = usec*1000 - seconds*1000000;
|
||||||
|
struct timespec sleepy = {0};
|
||||||
|
sleepy.ts_sec = second;
|
||||||
|
sleepy.ts_nsec = nano;
|
||||||
|
nanosleep(&sleepy, (struct timespec *) NULL);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef signed char byte;
|
typedef signed char byte;
|
||||||
|
@ -22,6 +22,21 @@ NOTE: This program is only made for entertainment porpuses. The puzzles are gene
|
|||||||
#if defined Plan9
|
#if defined Plan9
|
||||||
#define size 3
|
#define size 3
|
||||||
#define s 9
|
#define s 9
|
||||||
|
/* I hope this is approximately right */
|
||||||
|
int round(float x)
|
||||||
|
{
|
||||||
|
int y=(int) x;
|
||||||
|
if x>0
|
||||||
|
if x-y >0.5
|
||||||
|
return (int)(x + 0.5);
|
||||||
|
else
|
||||||
|
return y;
|
||||||
|
if x<0
|
||||||
|
if x-y <-0.5
|
||||||
|
return int(x -0.5);
|
||||||
|
else
|
||||||
|
return y;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef signed char byte;
|
typedef signed char byte;
|
||||||
@ -247,9 +262,7 @@ void mouseinput(int sy, int sx){
|
|||||||
getmouse(&m);
|
getmouse(&m);
|
||||||
#endif
|
#endif
|
||||||
if( m.y < (3+1+size+s)-sy && m.x<(2*s+1)-sx ){//it's a shame to include math.h only for round() but it was the only moral way to make gcc shut up
|
if( m.y < (3+1+size+s)-sy && m.x<(2*s+1)-sx ){//it's a shame to include math.h only for round() but it was the only moral way to make gcc shut up
|
||||||
#ifndef Plan9
|
|
||||||
py= round( (float)(size*(m.y-4-sy))/(size+1) );//these are derived from the formulas in draw() by simple algebra
|
py= round( (float)(size*(m.y-4-sy))/(size+1) );//these are derived from the formulas in draw() by simple algebra
|
||||||
#endif
|
|
||||||
px=(m.x-1-sx)/2;
|
px=(m.x-1-sx)/2;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
Loading…
Reference in New Issue
Block a user