-
Notifications
You must be signed in to change notification settings - Fork 1
/
PolyMain.cpp
159 lines (125 loc) · 3.2 KB
/
PolyMain.cpp
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#ifndef _POLYMAIN_CPP_
#define _POLYMAIN_CPP_
#include <windows.h>
#include <WinUser.h>
#include <stdio.h>
#include <stdlib.h>
#include <cwchar>
#include <future>
#include <memory>
#include <thread>
#include <clocale>
#include <iostream>
#include <inttypes.h>
#include <vector>
#include "PolyDraw.cpp"
#include "PolyWindow.cpp"
#include "PolyUtils.h"
#include <chrono>
#include <vector>
#include <list>
#include <atomic>
#include <condition_variable>
float FPS = 1/60.0f * 1000.0f;
using namespace std;
bool DebugGrid = false;
extern void setcursor(bool visible, DWORD size);
SHORT isKeyPressed(int vk) {
return (GetAsyncKeyState(vk));
}
static int i = 0;
HANDLE curScreenBufferHandle;
static std::atomic<bool> AtomActive;
void ChangeScreenSize (int x, int y )
{
HANDLE hOut = GetStdHandle( STD_OUTPUT_HANDLE );
SMALL_RECT DisplayArea = { 0, 0, 0, 0 };
CONSOLE_SCREEN_BUFFER_INFO SBInfo;
GetConsoleScreenBufferInfo( hOut, &SBInfo );
DisplayArea.Bottom = y;
DisplayArea.Right = x;
SetConsoleWindowInfo( hOut, true, &DisplayArea );
}
void GetDesktopResolution(int& horizontal, int& vertical)
{
RECT desktop;
const HWND hDesktop = GetDesktopWindow();
GetWindowRect(hDesktop, &desktop);
horizontal = desktop.right;
vertical = desktop.bottom;
}
extern int Window(void (*scene)(), int ps)
{
AtomActive = true;
std::thread threadDraw(scene);
std::thread threadWin(CreatePWindow);
threadWin.join();
threadDraw.join();
int sw;
int sh;
GetDesktopResolution(sw, sh);
while(AtomActive)
{
MoveWindow(console, 300, 300, WIDTH, HEIGHT, TRUE);
setPixelSize(ps);
if(i%2==0){
curScreenBufferHandle = hNewScreenBuffer;
} else {
curScreenBufferHandle = hNewScreenBuffer2;
}
// clear
if(DebugGrid == true)
{
for (int y = 0; y < HEIGHT; ++y)
{
for (int x = 0; x < WIDTH; ++x)
{
chiBuffer[x + WIDTH * y].Char.UnicodeChar = '.';
chiBuffer[x + WIDTH * y].Attributes = FG_WHITE;
}
}
}
else
{
for (int y = 0; y < HEIGHT; ++y)
{
for (int x = 0; x < WIDTH; ++x)
{
chiBuffer[x + WIDTH * y].Char.UnicodeChar = ' ';
chiBuffer[x + WIDTH * y].Attributes = FG_WHITE;
}
}
}
// present
scene();
fSuccess = WriteConsoleOutput(
curScreenBufferHandle, // screen buffer to write to
chiBuffer, // buffer to copy from
{ (short)WIDTH, (short)HEIGHT },
{ 0,0 }, // top left src cell in chiBuffer
&srctWriteRect);
if (! SetConsoleActiveScreenBuffer(curScreenBufferHandle)) {
printf("SetConsoleActiveScreenBuffer failed - (%d)\n", GetLastError());
system("pause");
exit(0);
}
memset(chiBuffer, 0, sizeof(CHAR_INFO) * WIDTH * HEIGHT);
Sleep(FPS);
i++;
}
//memset(curScreenBufferHandle, 0, sizeof(HANDLE));
return 0;
}
/*
extern void initThread(int n)
{
std::vector<thread> threads(n);
// spawn n threads:
for (int i = 0; i < n; i++) {
threads[i] = thread(Window, i + 1);
}
for (auto& th : threads) {
th.join();
}
}*/
#endif