-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathConsole.cpp
More file actions
77 lines (57 loc) · 2.37 KB
/
Copy pathConsole.cpp
File metadata and controls
77 lines (57 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include "Console.h"
CONSOLE_FONT_INFOEX setPixelFont(int fontw, int fonth);
//CONSOLE_SCREEN_BUFFER_INFO buildScreenBuffer(int width, int height, HANDLE consoleHandle);
void SetScreenBufferSize(int width, int height, HANDLE consoleHandle);
Console::Console()
{
m_nScreenWidth = 256;
m_nScreenHeight = 200;
m_hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
m_hConsoleIn = GetStdHandle(STD_INPUT_HANDLE);
m_sAppName = L"Default Game Engine";
}
void Console::SetConsole(int width, int height, int fontw, int fonth)
{
assert(m_hConsole != INVALID_HANDLE_VALUE);
m_nScreenWidth = width;
m_nScreenHeight = height;
m_screenBufferCorners = { 0, 0, 1, 1 };
SetConsoleWindowInfo(m_hConsole, TRUE, &m_screenBufferCorners);
SetScreenBufferSize(width, height, m_hConsole);
assert(SetConsoleActiveScreenBuffer(m_hConsole));
CONSOLE_FONT_INFOEX cfi = setPixelFont(fontw, fonth);
assert(SetCurrentConsoleFontEx(m_hConsole, false, &cfi));
m_screenBufferCorners = { 0, 0, (short)m_nScreenWidth - 1, (short)m_nScreenHeight - 1 }; // Set physical console window size
assert(SetConsoleWindowInfo(m_hConsole, TRUE, &m_screenBufferCorners));
m_screenBuffer = new CHAR_INFO[m_nScreenWidth*m_nScreenHeight];
}
void Console::Start()
{
m_bAtomActive = true; // Start the thread
std::thread t = std::thread(&Console::GameThread, this);
// This is the only place we ever call GameThread(). So, the call to OnUserCreate isn't as bad as it once looked.
// Note GameThread is a function, and GameThread() is, like, the result of running it. Look at the syntax here:
// I guess a std::thread wants a function to run, eh? Which is why we pass GameThread without the parentheses.
t.join(); // Wait for thread to be exited
}
CONSOLE_FONT_INFOEX setPixelFont(int fontw, int fonth)
{
CONSOLE_FONT_INFOEX cfi;
cfi.cbSize = sizeof(cfi);
cfi.nFont = 0;
cfi.dwFontSize.X = fontw;
cfi.dwFontSize.Y = fonth;
cfi.FontFamily = FF_DONTCARE;
cfi.FontWeight = FW_NORMAL;
wcscpy_s(cfi.FaceName, L"Consolas"); // Consolas is a font
return cfi;
}
void SetScreenBufferSize(int width, int height, HANDLE consoleHandle)
{
COORD coord = { (short)width, (short)height };
assert(SetConsoleScreenBufferSize(consoleHandle, coord));
}
// Define our static variables
std::atomic<bool> Console::m_bAtomActive(false);
std::condition_variable Console::m_cvGameFinished;
std::mutex Console::m_muxGame;