Snoke
common.cpp
Go to the documentation of this file.
1 
11 #include "common.h"
12 
20 {
21  return (this->x == p.x && this->y == p.y);
22 }
23 
30 std::ostream& operator<< (std::ostream &s, Point p)
31 {
32  s << '(' << p.x << ',' << p.y << ')';
33  return s;
34 }
35 
36 #ifdef __unix__
37 #pragma pack(push,1)
38 struct timespec req;
39 #pragma pack(pop)
40 #pragma pack(push,1)
41 struct timespec rem;
42 #pragma pack(pop)
43 #endif
44 
49 void mSleep(int time)
50 {
51 #ifdef _WIN32
52  Sleep(time);
53 
54 #elif defined(_WIN64)
55  Sleep(time);
56 #endif
57 
58 #ifdef __unix__
59  req.tv_sec = time / 1000;
60  req.tv_nsec = (time % 1000) * 1000000;
61  nanosleep(&req, &rem);
62 #endif
63 }
64 
65 #ifndef __unix__
66 
71 void set_escdelay(short delay)
72 {}
73 #endif
74 
79 {
80 #ifdef __unix__
81  req = rem;
82  rem.tv_sec = 0;
83  rem.tv_nsec = 0;
84 #endif
85 }
86 
90 void addSleep()
91 {
92 #ifdef __unix__
93  nanosleep(&req, &rem);
94 #endif
95 }
96 
101 {
102  Point size;
103  getmaxyx(stdscr, size.y, size.x);
104 
105  return size;
106 }
void mSleep(int time)
Cross-platform sleep function cover.
Definition: common.cpp:49
short x
Definition: common.h:55
std::ostream & operator<<(std::ostream &s, Point p)
Operation &#39;<<&#39; override for the Point class.
Definition: common.cpp:30
bool operator==(Point p)
Operation "==" override for the Point class.
Definition: common.cpp:19
void sleepHandler()
setting new values for sleep function on signal interrupt
Definition: common.cpp:78
void set_escdelay(short delay)
Definition: common.cpp:71
Point getConsoleSize()
Gets size of current console screen in symdols.
Definition: common.cpp:100
short y
Definition: common.h:56
shared functions prototypes, structures, main classes declarations
void addSleep()
For unix-based systems interrupted sleep must be continued.
Definition: common.cpp:90
Coordinates and style of the cell in console window.
Definition: common.h:52