-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
161 lines (120 loc) · 3.9 KB
/
main.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
#include "Graphics.h"
//#include "GameController.h"
#include <thread>
#include <Windowsx.h>
#include <Windows.h>
#include "Controller.h"
#include "TitleScreen.h"
Graphics* graphics;
bool running;
std::vector<IA>* inputQue;
void StopRendering() {
running = false;
}
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
HDC hdc; // handle to device context
RECT rcClient; // client area rectangle
POINT ptClientUL; // client upper left corner
POINT ptClientLR; // client lower right corner
static POINTS ptsBegin; // beginning point
static POINTS ptsEnd; // new endpoint
static POINTS ptsPrevEnd; // previous endpoint
static BOOL fPrevLine = FALSE; // previous line flag
switch (uMsg) {
case WM_DESTROY:
StopRendering();
PostQuitMessage(0);
return 0;
case WM_LBUTTONDOWN:
inputQue->push_back({ PRIMARY_CLICK,0 });
//GameController::Update(GameLevel::GameAction::MOUSE_LCLICK, lParam, wParam);
return 0;
case WM_RBUTTONDOWN:
//GameController::Update(GameLevel::GameAction::MOUSE_RCLICK, lParam, wParam);
inputQue->push_back({ SECONDARY_CLICK,0 });
return 0;
case WM_LBUTTONUP:
//GameController::Update(GameLevel::GameAction::MOUSE_LRELEASE, lParam, wParam);
inputQue->push_back({ PRIMARY_RELEASE,0 });
return 0;
case WM_RBUTTONUP:
//GameController::Update(GameLevel::GameAction::MOUSE_RRELEASE, lParam, wParam);
inputQue->push_back({ SECONDARY_RELEASE,0 });
return 0;
case WM_KEYDOWN:
inputQue->push_back({ KEY_DOWN,0 });
//GameController::Update(GameLevel::GameAction::KEYBOARD_PRESS, lParam, wParam);
return 0;
case WM_KEYUP:
inputQue->push_back({ KEY_RELEASE,0 });
//GameController::Update(GameLevel::GameAction::KEYBOARD_RELEASE, lParam, wParam);
return 0;
case WM_MOUSEMOVE:
inputQue->push_back({ MOUSE_MOVE,0 });
//GameController::Update(GameLevel::GameAction::MOUSE_MOVE, lParam, wParam);
return 0;
}
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
void Render(Graphics* g) {
//TODO add a variable to the while loop
while (running) {
Controller::Update(inputQue);
g->BeginDraw();
Controller::Render();
g->EndDraw();
}
//delete g;
}
/*void Update() {
while (running) {
//GameController::Update();
}
}*/
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE prevInstance, LPWSTR cmd, int nCmdShow)
{
WNDCLASSEX windowclass;
ZeroMemory(&windowclass, sizeof(WNDCLASSEX));
windowclass.cbSize = sizeof(WNDCLASSEX);
windowclass.hbrBackground = (HBRUSH)COLOR_WINDOW;
windowclass.hInstance = hInstance;
windowclass.lpfnWndProc = WindowProc;
windowclass.lpszClassName = "MainWindow";
windowclass.style = CS_HREDRAW | CS_VREDRAW;
windowclass.hCursor = LoadCursor(NULL, IDC_ARROW);
RegisterClassEx(&windowclass);
//HCURSOR cursor1 = LoadCursor(NULL, IDC_ARROW);
//SetCursor(hCurs3);
RECT rect = { 0,0,800,600 };
AdjustWindowRectEx(&rect, WS_OVERLAPPED, false, WS_EX_OVERLAPPEDWINDOW);
HWND hwnd = CreateWindowEx(WS_EX_OVERLAPPEDWINDOW, "MainWindow", "Gerrods Program", WS_OVERLAPPEDWINDOW, 100, 100, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, hInstance, 0);
if (!hwnd) { return -1; }
graphics = new Graphics();
if (!graphics->Init(hwnd)) {
delete graphics;
return -1;
}
inputQue = new std::vector<IA>{};
State::Init(graphics,hwnd);
ShowWindow(hwnd, nCmdShow);
Controller::Init();
Controller::LoadInitialState(new TitleScreen());
running = true;
MSG message;
message.message = WM_NULL;
//Creates RenderingGraphics thread to render the graphics seperately.
std::thread RenderingGraphics(Render, graphics);
//std::thread UpdateGame(Update);
while (message.message != WM_QUIT) {
if (PeekMessage(&message, NULL, 0, 0, PM_REMOVE)) {
DispatchMessage(&message);
}
else {
}
}
//graphics thread rejoins main thread
RenderingGraphics.join();
//UpdateGame.join();
delete graphics;
return 0;
}