-
Notifications
You must be signed in to change notification settings - Fork 1
/
DemiseRLmain.cpp
229 lines (194 loc) · 7.4 KB
/
DemiseRLmain.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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
// --------------------------------------------------------------------------------------------------------------------------------
// DEMISERL
// Copyright 2014 Corremn
//
// $LastChangedBy$
// $LastChangedDate$
// $LastChangedRevision$
// $HeadURL: $
// --------------------------------------------------------------------------------------------------------------------------------
#include <windows.h> // Header File For Windows
#include "WorldBuilder.h"
#include "OpenGLSceneGen.h"
#include <sstream>
//general
bool keys[256]; // Array Used For The Keyboard Routine
bool active = true; // Window Active Flag Set To true By Default
bool keypress;
LRESULT CALLBACK WndProc(HWND hWnd, // Handle For This Window
UINT uMsg, // Message For This Window
WPARAM wParam, // Additional Message Information
LPARAM lParam) // Additional Message Information
{
// initial check for non-US keys
switch (wParam)
{
case 60: // '<'
keys[wParam] = TRUE; // key
keypress = true;
return 0;
case 62: // '>'
keys[wParam] = TRUE; // key
keypress = true;
return 0;
case 63: // '?'
keys[wParam] = TRUE; // help key
keypress = true;
return 0;
}
switch (uMsg) // Check For Windows Messages
{
case WM_ACTIVATE: // Watch For Window Activate Message
{
if (!HIWORD(wParam)) // Check Minimization State
{
active = true; // Program Is Active
}
else
{
active = false; // Program Is No Longer Active
}
return 0; // Return To The Message Loop
}
case WM_SYSCOMMAND: // Intercept System Commands
{
switch (wParam) // Check System Calls
{
case SC_SCREENSAVE: // Screensaver Trying To Start?
case SC_MONITORPOWER: // Monitor Trying To Enter Powersave?
return 0; // Prevent From Happening
}
break; // Exit
}
case WM_CLOSE: // Did We Receive A Close Message?
{
PostQuitMessage(0); // Send A Quit Message
return 0; // Jump Back
}
case WM_KEYDOWN: // Is A Key Being Held Down?
{
keys[wParam] = true; // If So, Mark It As true
keypress = true;
return 0; // Jump Back
}
case WM_KEYUP: // Has A Key Been Released?
{
keys[wParam] = false; // If So, Mark It As false
return 0; // Jump Back
}
case WM_SIZE: // Resize The OpenGL Window
{
World.Resize(lParam, wParam);
keypress = true;
return 0; // Jump Back
}
}
// Pass All Unhandled Messages To DefWindowProc
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
int WINAPI WinMain(HINSTANCE hInstance, // Instance
HINSTANCE hPrevInstance, // Previous Instance
LPSTR lpCmdLine, // Command Line Parameters
int nCmdShow) // Window Show State
{
MSG msg; // Windows Message Structure
BOOL done = false; // Bool Variable To Exit Loop
keypress = false;
// get seed value
int temp = -1;
//1404832263
if (__argc > 1)
{
std::stringstream str;
str << __argv[1];
str >> temp;
}
Random::reseed(temp);
try
{
std::string title = "The Warlock of Firetop Mountain: Roguelike (c) 2014 Corremn";
#ifdef _DEBUG
if (temp != -1)
{
title += " Seed: ";
title += __argv[1];
}
#endif
if (!World.Initialise(title.c_str()))
return 0;
}
catch (std::exception & ex)
{
::MessageBox(NULL, ex.what(), "Initialisation", MB_ICONERROR);
}
catch (...)
{
::MessageBox(NULL, "Unknown Error", "Initialisation", MB_ICONERROR);
}
World.Run(); //display world
while (!done) // Loop That Runs While done=false
{
//Sleep(10);
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) // Is There A Message Waiting?
{
if (msg.message == WM_QUIT) // Have We Received A Quit Message?
{
done = true; // If So done=true
}
else // If Not, Deal With Window Messages
{
TranslateMessage(&msg); // Translate The Message
DispatchMessage(&msg); // Dispatch The Message
}
}
else // If There Are No Messages
{
// Draw The Scene. Watch For Quit Messages From DrawGLScene()
// add key press handler here ??cjm
if (active) // Program Active?
{
if (keypress)
{
World.ProcessCommand(keys);
World.Run();
keypress = false;
}
else // Not Time To Quit, Update Screen
{
if (World.State() == sRunning || World.State() == sResting) //update while player is running or resting(HACK)
World.Run();
}
Sleep(10);
}
if (keys[VK_F1]) // Is F1 Being Pressed?
{
keys[VK_F1] = false; // If So Make Key false
World.ToggleFullScreen(800, 600);
}
if (keys[VK_F2]) // Is F2 Being Pressed?
{
keys[VK_F2] = false; // If So Make Key false
World.ToggleFullScreen(1024, 768);
}/*
if (keys[VK_F3]) // Is F3 Being Pressed?
{
keys[VK_F3]=false; // If So Make Key false
world.ToggleFullScreen(1024,768 );
}
if (keys[VK_F4]) // Is F4 Being Pressed?
{
keys[VK_F4]=false; // If So Make Key false
world.ToggleFullScreen(1280,1024);
}*/
}
}
// Shutdown
World.Stop();
try{
return 0; // Exit The Program
}
catch (...)
{
return 0;
}
}