Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 35 additions & 12 deletions src/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,25 +39,48 @@ Game::~Game() {
bIsRunning.store(false);
}
void Game::initWindow() {
int LINE_WIDTH = 0;

#ifdef _WIN64
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_SCREEN_BUFFER_INFO csbi;
GetConsoleScreenBufferInfo(hConsole, &csbi);
LINE_HEIGHT = csbi.srWindow.Bottom - csbi.srWindow.Top + 1;
if (GetConsoleScreenBufferInfo(hConsole, &csbi)) {
LINE_HEIGHT = csbi.srWindow.Bottom - csbi.srWindow.Top + 1;
LINE_WIDTH = csbi.srWindow.Right - csbi.srWindow.Left + 1;
} else {
LINE_HEIGHT = 25;
LINE_WIDTH = 80;
}
#else
struct winsize win;
ioctl(STDOUT_FILENO, TIOCGWINSZ, &win);
LINE_HEIGHT = win.ws_row;
int LINE_WIDTH = win.ws_col;
if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &win) == 0) {
LINE_HEIGHT = win.ws_row;
LINE_WIDTH = win.ws_col;
} else {
LINE_HEIGHT = 25;
LINE_WIDTH = 80;
}
#endif

while (LINE_HEIGHT < 18 || LINE_WIDTH < 40) {
std::cout<<MAGENTA<<"this terminal window seems too small"<<nl;
std::cout<<MAGENTA<<"current window size is "<<LINE_WIDTH<<"*"<<LINE_HEIGHT<<nl;
std::cout<<MAGENTA<<"try resize this window to continue?"<<nl<<nl;
std::this_thread::sleep_for(std::chrono::milliseconds(50));
ioctl(STDOUT_FILENO, TIOCGWINSZ, &win);
LINE_HEIGHT = win.ws_row;
LINE_WIDTH = win.ws_col;
std::cout << MAGENTA << "this terminal window seems too small" << nl;
std::cout << MAGENTA << "current window size is "
<< LINE_WIDTH << "*" << LINE_HEIGHT << nl;
std::cout << MAGENTA << "try resize this window to continue?" << nl << nl;

std::this_thread::sleep_for(std::chrono::milliseconds(200));

#ifdef _WIN64
if (GetConsoleScreenBufferInfo(hConsole, &csbi)) {
LINE_HEIGHT = csbi.srWindow.Bottom - csbi.srWindow.Top + 1;
LINE_WIDTH = csbi.srWindow.Right - csbi.srWindow.Left + 1;
}
#else
if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &win) == 0) {
LINE_HEIGHT = win.ws_row;
LINE_WIDTH = win.ws_col;
}
#endif
clear_screen();
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/InputMonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
#ifdef _WIN64
#include <conio.h>
#include <windows.h>
#define WIN32_LEAN_AND_MEAN
#ifdef store
#undef store
#endif
#endif

void InputMonitor::start(const Callback& callback)
Expand Down
Loading