-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
134 lines (114 loc) · 4.2 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
#include "GameWorld.h"
#include "GameTimer.h"
#include <time.h>
#include "Graphics.h"
IDirect3DDevice9* Device;
Graphics graphics;
bool g_init = false;
GameTimer timer;
SoundEngine *soundEngine = new SoundEngine( );
FILE* console_log;
///WinProc
///this class is declared in the D3D namspace(this function must be declared globally,
///so it must be a part of the namespace and not a member of the graphics class),
///then when you fill out the WNDCLASS class, a pointer is made to the function
///wc.lpfnWndProc = (WNDPROC)D3D::MsgProc; (like this)
///this is the fuction that WinMain dispatches messages to.
LRESULT CALLBACK D3D::MsgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
switch( msg )
{
case WM_DESTROY:
PostQuitMessage( 0 );
break;
case WM_SIZE:
switch( wParam )
{
case SIZE_MAXIMIZED:///you know what this does since I basically stole this code from your final project
if( !(graphics.d3dpp.Windowed) )
break;
graphics.d3dpp.BackBufferWidth = GetSystemMetrics( SM_CXSCREEN );
graphics.d3dpp.BackBufferHeight = GetSystemMetrics( SM_CYSCREEN );
graphics.SetScreenRect( );
graphics.d3dpp.Windowed = false;
break;
case SIZE_RESTORED:///ditto
// set windowed to true
graphics.d3dpp.BackBufferWidth = screenWidth;
graphics.d3dpp.BackBufferHeight = screenHeight;
graphics.SetScreenRect( );
graphics.d3dpp.Windowed = true;
break;
}break;
case WM_SETCURSOR:
SetCursor( NULL );
// return graphics.GetDevice( )->ShowCursor( true );
Device->ShowCursor(true);
break;
case WM_KEYUP:
case WM_KEYDOWN:
if (wParam == VK_ESCAPE)
DestroyWindow(hWnd);
case WM_CHAR:
//#ifndef NDEBUG
// printf( "Key Event: %d, %d\n", (int)wParam, (int)lParam );
//#endif
case WM_LBUTTONUP:
case WM_LBUTTONDOWN:
case WM_MOUSEMOVE:
///The graphics class receives the messages and sends them on to the state machine
///in the UIBase class, this is done in the PostMessage function. All of the classes
///in the UIControl files are derived from the UIBase class. The functions called within
///the PostMessage function are pure virtual functions(ex.OnMouseUp(msg, LOWORD(lParam), HIWORD(lParam));),
///and are implemented by the derived classes.
if( g_init )
graphics.RecvMessages( msg, wParam, lParam, NULL );
break;
default:
break;
}
return DefWindowProc( hWnd, msg, wParam, lParam );
}
//-----------//
// WinMain
//-----------//
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevinstances, LPSTR cmdLine, int showCmd )
{
// cast the state types from generic GameState to their true state
// reinterpret_cast<GameWorld&>(gameWorld);
srand( (unsigned int)time( NULL ) );
// This creates and attaches a console, only enabled in debug builds
#ifndef NDEBUG
AllocConsole( );
AttachConsole( GetCurrentProcessId( ) );
freopen_s( &console_log, "CON", "w", stdout );
printf( "Omni Debug Console v0.0.1!\n" );
printf("Key Legend:\n");
printf("\t 'w','a','s','d' controls knight movement\n");
printf("\t 'z','x','c','v','b' changes skeleton animations\n");
printf("\t ',' (comma),'.' (period) dragon chases knight or goes idle\n");
#endif
g_init = graphics.Initialized( screenHeight, screenWidth, hInstance );///initialize the graphics class
// initialize the sound engine
soundEngine->Initialize( );
// message for loop
MSG msg;
ZeroMemory( &msg, sizeof( MSG ) );
while( msg.message != WM_QUIT )
{
if( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) && !IsDialogMessage( NULL, &msg ) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );///Displatches messages to the WndProc function
}
else
{
timer.Tick( );
graphics.Update( );///graphics update function
graphics.Render( );///graphics class render call, this will call render for the current state
}
}
fclose( console_log );
return (int)msg.wParam;
}
///move on to the graphics class