-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathSystem.cpp
121 lines (92 loc) · 2.96 KB
/
System.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
// ***************************************************************
// System
// -------------------------------------------------------------
// Purpose : Main startup file. Window Creation, Initialization,
// Message loop, main WndProc gets created here.
// ***************************************************************
#include "Game/Game.h"
#include "RenderDevice/RenderDevice.h"
#include <windows.h>
//------------------------------------------------------------------------
// Purpose : Global Variables
//------------------------------------------------------------------------
HWND g_hwnd;
static TCHAR szAppName[] = TEXT ("DoD__Engine");
WNDCLASSEX wndclassex = {0};
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
void CreateMainWindow(HINSTANCE hInstance, int iCmdShow)
{
wndclassex.cbSize = sizeof(WNDCLASSEX);
wndclassex.style = CS_HREDRAW | CS_VREDRAW;
wndclassex.lpfnWndProc = WndProc;
wndclassex.cbClsExtra = 0;
wndclassex.cbWndExtra = 0;
wndclassex.hInstance = hInstance;
wndclassex.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wndclassex.hCursor = LoadCursor (NULL, IDC_ARROW);
wndclassex.hbrBackground = (HBRUSH) GetStockObject (BLACK_BRUSH);
wndclassex.lpszMenuName = NULL;
wndclassex.lpszClassName = szAppName;
wndclassex.hIconSm = wndclassex.hIcon;
if (!RegisterClassEx (&wndclassex))
{
MessageBox (NULL, TEXT ("RegisterClassEx failed!"), szAppName, MB_ICONERROR);
}
int width = 1280; //GetSystemMetrics(SM_CXSCREEN);
int height = 720; //GetSystemMetrics(SM_CYSCREEN);
RECT rect;
rect.left = 0;
rect.top = 0;
rect.right = width;
rect.bottom = height;
DWORD style = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX;;
AdjustWindowRect(&rect, style, false);
g_hwnd = CreateWindow ( szAppName,
TEXT ("iWorld®"),
style,
CW_USEDEFAULT,
CW_USEDEFAULT,
rect.right-rect.left,
rect.bottom-rect.top,
NULL,
NULL,
hInstance,
NULL);
ShowWindow (g_hwnd, iCmdShow);
UpdateWindow (g_hwnd);
}
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
MSG msg = {0};
// Create the Main Window
CreateMainWindow(hInstance, iCmdShow);
// Initialize Everything!
if(!Game::GetInstance()->Initialize(g_hwnd,hInstance))
return E_FAIL;
while (WM_QUIT != msg.message)
{
if(PeekMessage(&msg, g_hwnd, 0, 0, PM_REMOVE))
{
TranslateMessage (&msg);
DispatchMessage (&msg);
}
else
{
Game::GetInstance()->Tick();
}
}
UnregisterClass( szAppName, wndclassex.hInstance );
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_DESTROY:
Game::GetInstance()->Shutdown();
SendMessage(hwnd, WM_SYSCOMMAND, SC_CLOSE, 0);
exit(0);
break;
}
return Game::GetInstance()->HandleMessages(hwnd, message, wParam, lParam);
}