-
Notifications
You must be signed in to change notification settings - Fork 2
/
Application.cpp
336 lines (259 loc) · 9.74 KB
/
Application.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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
//-----------------------------------------------------------------------------
// File: Application.cpp
//
// Desc:
//
// Copyright (c) 2002 Dan
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// Includes
#include <windows.h>
#include <math.h>
#include <gl\gl.h>
#include <gl\glu.h>
#include <gl\glaux.h>
#include "Application.h"
#include "main.h"
#include "dxutil.h"
#include "dinput.h"
#include "TextureManager.h"
#include "PolygonManager.h"
#include "Vertex.h"
#include "MessageProcs.h"
#include "resource.h"
#include "Window.h"
#include "Util.h"
#include "CustomMsg.h"
#include "Tracer.h"
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// Construction/Destruction
//-----------------------------------------------------------------------------
CApplication::CApplication()
{
TRACE_ENTER_FN( CApplication::CApplication() )
Log( "CApplication::CApplication()\n" );
m_hInstance = NULL;
m_hWndTCtrl = NULL;
// this is a test
TRACE_LEAVE_FN()
}
CApplication::~CApplication()
{
TRACE_ENTER_FN( CApplication::~CApplication() )
Log( "CApplication::~CApplication()\n" );
Release();
TRACE_LEAVE_FN()
}
//-----------------------------------------------------------------------------
// Name: Init()
// Desc:
//-----------------------------------------------------------------------------
bool CApplication::Init( HINSTANCE hInstance, char* strAppName, double Version )
{
TRACE_ENTER_FN( CApplication::Init )
Log( "CApplication::Init()\n" );
Log( "CPU Speed: " ); Log( (int)GetCpuSpeed() ); Log( "MHz\n" );
Settings->Open();
m_hInstance = hInstance;
Profile->Begin( "m_Engine.Init()" );
m_Engine.Init( hInstance, false, strAppName, Version );
Profile->End( "m_Engine.Init()" );
Profile->DumpOutputToBuffer();
m_Engine.AlignViews();
RET( true )
}
//-----------------------------------------------------------------------------
// Name: Run()
// Desc: Application's main loop Renders the scene when all messages have been
// dealt with
//-----------------------------------------------------------------------------
int CApplication::Run()
{
TRACE_ENTER_FN( CApplication::Run() )
Log( "CApplication::Run()\n" );
MSG msg;
DXUtil_Timer( TIMER_RESET );
while( true )
{
if( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) )
{
if( msg.message == WM_QUIT )
break;
TranslateMessage( &msg );
DispatchMessage( &msg );
}
else
RenderScene();
}
RET( msg.wParam )
}
//-----------------------------------------------------------------------------
// Name: MsgProc()
// Desc:
//-----------------------------------------------------------------------------
LRESULT CApplication::MsgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
switch( uMsg )
{
case WM_CREATE: OnWMCreate( hWnd ); break;
case WM_COMMAND: OnWMCommand( wParam, hWnd ); break;
case WM_SIZE: m_Engine.ResizeWindow( LOWORD( lParam ), HIWORD( lParam ) ); break;
case WM_PAINT: OnWMPaint( wParam, lParam ); break;
/*
case WM_RBUTTONDOWN:
{
POINT pt;
HMENU hMenu, hSubMenu;
ClientToScreen( hWnd, &pt );
hMenu = LoadMenu( m_hInstance, "IDR_MENU_FACE" );
//hSubMenu = GetSubMenu( hMenu, 0 );
TrackPopupMenuEx( hMenu, 0, pt.x, pt.y, hWnd, NULL );
}
break;
*/
case WM_RBUTTONDOWN:
case WM_LBUTTONDOWN:
{
m_Engine.LeftClick( LOWORD( lParam ), HIWORD( lParam ) );
}
break;
case WM_KEYDOWN: OnWMKeydown( wParam, hWnd ); break;
case WM_CLOSE: PostQuitMessage( 0 ); break;
case CMSG_ALIGNVIEWS: m_Engine.AlignViews(); break;
case CMSG_CHANGE_TAB: m_Engine.ChangeTab( lParam ); break;
default: return DefWindowProc( hWnd, uMsg, wParam, lParam );
}
return 0;
}
//-----------------------------------------------------------------------------
// Name: RenderScene()
// Desc:
//-----------------------------------------------------------------------------
bool CApplication::RenderScene()
{
TRACE_ENTER_FN( CApplication::RenderScene )
static float t1, t2, t3, t4, t5, t6, t7, t8, t9, t10;
static float fSecond = 0.0f;
static int iFrame = 0;
m_fAppTime = DXUtil_Timer( TIMER_GETAPPTIME );
m_fElapsedTime = DXUtil_Timer( TIMER_GETELAPSEDTIME );
iFrame++;
fSecond += m_fElapsedTime;
if( fSecond >= 1.0f )
{
Log( "FPS: " ); Log( iFrame ); Log( "\n" );
fSecond = 0.0f;
iFrame = 0;
}
// Averages time elapsed in the last 10 frames
t1 = t2; t2 = t3; t3 = t4; t4 = t5; t5 = t6;
t6 = t7; t7 = t8; t8 = t9; t9 = t10; t10 = m_fElapsedTime;
m_fElapsedTime = ( t1 + t2 + t3 + t4 + t5 + t6 + t7 + t8 + t9 + t10 ) / 10.0f;
m_Engine.FrameMove( m_fElapsedTime );
m_Engine.Render();
RET( true )
}
//-----------------------------------------------------------------------------
// Name: Release()
// Desc:
//-----------------------------------------------------------------------------
BOOL CApplication::Release()
{
TRACE_ENTER_FN( CApplication::Release )
Log( "CApplication::Release()\n" );
Settings->Save();
RET( true )
}
//-----------------------------------------------------------------------------
// Name: OnWMCommand()
// Desc:
//-----------------------------------------------------------------------------
void CApplication::OnWMCommand( WPARAM wParam, HWND hWnd )
{
switch( LOWORD( wParam ) )
{
/* Menu */
// File
case ID_NEW: m_Engine.LoadLevel( "newlevel" ); break;
case ID_OPEN: m_Engine.LoadLevel( NULL ); break;
case ID_CLOSE: break;
case ID_FILE_SAVEMAPAS: break;
case ID_SAVE_MAP: m_Engine.SaveLevel( NULL ); break;
case ID_EXIT: PostQuitMessage( 0 ); break;
case ID_FILE_RUNLEVEL:
{
ShellExecute( hWnd, "open", "D:\\Apps\\OpenGL\\EnigmaEngine\\Release\\EnigmaEngine.exe",
NULL, NULL, SW_SHOW );
}
break;
// PROCESS_INFORMATION
// Edit
case ID_CUT: break;
case ID_COPY: break;
case ID_PASTE: break;
case ID_REDO: break;
case ID_UNDO: break;
case ID_SELECT_ALL: break;
// Textures
case ID_TEXTURES_ALIGNALLTEXTURES: PM->AlignAllTextures(); break;
// Vertex
case ID_ADD_VERTEX: break;
case ID_DELETE_VERTEX: break;
case ID_VERTEX_PROPERTIES: break;
case ID_VERTEX_COMPUTEVERTEXCONNECTIONS: PM->ComputeVertexConnections(); break;
case ID_VERTEX_SNAPVERTSTOGRID: PM->SnapVertsToGrid(); break;
// Face
case ID_FACE_REMOVECOENCIDINGFACES: PM->RemoveCoencidingFaces(); break;
// Polygon
case ID_DELETE_POLYGON: break;
case ID_ADD_POLYGON: break;
case ID_LOAD_POLYGON: break;
case ID_SAVE_POLYGON: break;
case ID_SAVE_AS: break;
// Camera
case ID_CAMERA_PROPERTIES: DialogBox( m_hInstance, "CameraDB", hWnd, (DLGPROC) CameraDB ); break;
// Options
case ID_MAP_PROPERTIES: DialogBox( m_hInstance, "MapDB", hWnd, (DLGPROC) MapDB ); break; break;
case ID_EDITOR_PROPERTIES: DialogBox( m_hInstance, "SettingsDB", hWnd, (DLGPROC) SettingsDB ); break;
// Window
case ID_WINDOW_RESETVIEWS: m_Engine.ResetViews(); break;
case ID_WINDOW_TOGGLEACTIVESTATE_3DWINDOW: Settings->m_bEditor_3DViewActive = !Settings->m_bEditor_3DViewActive; break;
case ID_WINDOW_TOGGLEACTIVESTATE_2DLEFTWINDOW: Settings->m_bEditor_LeftViewActive = !Settings->m_bEditor_LeftViewActive; break;
case ID_WINDOW_TOGGLEACTIVESTATE_2DCENTERWINDOW: Settings->m_bEditor_CenterViewActive = !Settings->m_bEditor_CenterViewActive; break;
case ID_WINDOW_TOGGLEACTIVESTATE_2DRIGHTWINDOW: Settings->m_bEditor_RightViewActive = !Settings->m_bEditor_RightViewActive; break;
// Help
case ID_ABOUT: DialogBox( m_hInstance, "AboutDB", hWnd, (DLGPROC) AboutDB ); break;
}
}
//-----------------------------------------------------------------------------
// Name: OnWMKeydown()
// Desc:
//-----------------------------------------------------------------------------
void CApplication::OnWMKeydown( WPARAM wParam, HWND hWnd )
{
switch( wParam )
{
case VK_ESCAPE: PostQuitMessage( 0 ); break;
}
}
//-----------------------------------------------------------------------------
// Name: OnWMCreate()
// Desc:
//-----------------------------------------------------------------------------
void CApplication::OnWMCreate( HWND hWnd )
{
TRACE_ENTER_FN( CApplication::OnWMCreate )
m_Engine.OnWMCreate( hWnd );
TRACE_LEAVE_FN()
}
//-----------------------------------------------------------------------------
// Name: OnWMPaint()
// Desc:
//-----------------------------------------------------------------------------
void CApplication::OnWMPaint( WPARAM wParam, LPARAM lParam )
{
TRACE_ENTER_FN( CApplication::OnWMPaint )
m_Engine.Repaint( wParam, lParam );
TRACE_LEAVE_FN()
}