-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSource.cpp
184 lines (148 loc) · 4.32 KB
/
Source.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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#include "RenderClass.h"
#include "Cell.h"
#include "Model.h"
#include "Input.h"
#include "World.h"
#include "InfoWindow.h"
#include "Chunk.h"
#include "ChemicalContainer.h"
#include "Camera.h"
#include "CellInfoWindow.h"
#include "Time.h"
RenderClass* render = nullptr;
InfoWindow* infoWindow = nullptr;
CellInfoWindow* cellInfoWindow = nullptr;
World* world = nullptr;
LRESULT CALLBACK EveProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_KEYDOWN:
render->GetInput()->Key(true, wParam);
break;
case WM_KEYUP:
render->GetInput()->Key(false, wParam);
break;
case WM_MOUSEMOVE:
render->GetInput()->Mouse(wParam, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), hWnd);
break;
default:
return DefWindowProc(hWnd, uMsg, wParam, lParam);
break;
}
return 0;
}
long long milliseconds_now()
{
LARGE_INTEGER frequency;
BOOL use_qpc = QueryPerformanceFrequency(&frequency);
if (use_qpc)
{
LARGE_INTEGER now;
QueryPerformanceCounter(&now);
return (1000LL * now.QuadPart) / frequency.QuadPart;
}
else
{
return GetTickCount();
}
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR CMDLine, int CmdShow)
{
srand(time(NULL));
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = EveProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APPLICATION));
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = "eve";
wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_APPLICATION));
//the main DirectX window
if (!RegisterClassEx(&wcex))
{
MessageBox(NULL, "Call to RegisterClassEx failed!", "Eve", NULL);
return 1;
}
HWND hWnd = CreateWindow("eve", "Eve", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 1200, 750, NULL, NULL, hInstance, NULL);
render = new RenderClass(hWnd);
if (!hWnd)
{
MessageBox(NULL, "Call to CreateWindow failed!", "Eve", NULL);
return 1;
}
RECT desktop;
GetWindowRect(GetDesktopWindow(), &desktop);
SetWindowPos(hWnd, HWND_TOP, (desktop.right / 2) - 600, (desktop.bottom / 2) - 375, 0, 0, SWP_NOSIZE || SWP_SHOWWINDOW);
world = new World(render, 50, 10);
render->GetCamera()->SetWorld(world);
render->SetWorld(world);
infoWindow = new InfoWindow(hInstance, world);
cellInfoWindow = new CellInfoWindow(hInstance, world, render);
render->GetInput()->SetCellInfoWindow(cellInfoWindow);
ShowWindow(hWnd, CmdShow);
UpdateWindow(hWnd);
//world->AddCell(new Cell(render, world, nullptr, rand() % (world->GetSizeX() * world->GetChunkSize()), rand() % (world->GetSizeY() * world->GetChunkSize()), rand() % (world->GetSizeZ() * world->GetChunkSize())));
//Initalising the Message loop
cellInfoWindow->SetClosestCellAsCurrentCell();
MSG Msg;
ZeroMemory(&Msg, sizeof(MSG));
long long t = milliseconds_now();
long long NewTime;
int DeltaTime;
int counterForInfoWindowUpdates = 0;
int counterForLog = 0;
int FPS = 0;
CreateDirectory(world->GetCurrentTestRunName().c_str(), NULL);
while (true)
{
NewTime = milliseconds_now();
DeltaTime = NewTime - t;
counterForInfoWindowUpdates += DeltaTime;
counterForLog += DeltaTime;
FPS++;
if (PeekMessage(&Msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
if (Msg.message == WM_QUIT || (Msg.message == WM_KEYDOWN && Msg.wParam == VK_ESCAPE))
break;
}
render->GetInput()->RunTick(DeltaTime);
world->Tick(DeltaTime);
render->RenderFrame();
if (counterForInfoWindowUpdates > 500)
{
infoWindow->WriteInfoData(FPS * (1000.0f / counterForInfoWindowUpdates));
cellInfoWindow->WriteInfoData();
counterForInfoWindowUpdates = 0;
FPS = 0;
}
if (counterForLog > 30000)
{
counterForLog = 0;
world->WriteLog();
}
if (world->GetCellVec()->size() == 0)
{
world->OpenOutputAndIncreaseTry();
world->Reset();
for (int i = 0; i < 50; i++)
{
world->AddCell(new Cell(render, world, nullptr, rand() % (world->GetSizeX() * world->GetChunkSize()), rand() % (world->GetSizeY() * world->GetChunkSize()), rand() % (world->GetSizeZ() * world->GetChunkSize())));
}
counterForLog = 0;
world->WriteLog();
}
t = NewTime;
}
return 0;
}