language: C++ 4.7.2 (gcc-4.7.2)
date: 375 days 18 hours ago
link:
visibility: public
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
// main.cpp : Defines the entry point for the application.
//
 
// include the Direct3D Library file
#pragma comment (lib, "d3d9.lib")
#pragma comment (lib, "d3dx9.lib")
//#pragma comment(lib, "dsound.lib")
//#pragma comment (lib, "dinput8.lib")
//#pragma comment (lib, "dxguid.lib")
 
 
//#pragma comment(lib, "ddraw.lib")
//#pragma comment(lib, "dxguid.lib")
 
#define _CRT_SECURE_NO_WARNINGS
#define STRICT
#define WIN32_LEAN_AND_MEAN             // Exclude rarely-used stuff from Windows headers
//#define VC_EXTRALEAN
// Windows Header Files:
//#include <ddraw.h>
#include <windows.h>
#include <windowsx.h>
//#include <MMSystem.h>
 
#include <D3dx9.h>
#include <d3d9.h>
#include "Direct3D9.h"
 
#include "Vector2D.h"
#include "main.h"
#include "Timer.h"
#include "Game.h"
//#include "DirectDraw.h"
 
 
//#include "Singleton.h"
 
 
////////////////////////////////////////////////////////////////
//Global Functions Decarations
////////////////////////////////////////////////////////////////
 
 
LRESULT CALLBACK WndProc(HWND hWindow,UINT msg, WPARAM wParam, LPARAM lParam);  
 
bool m_fullScreen = false;
 
bool m_running;
 
Game* m_game;
 
Timer m_timer;
unsigned __int64 m_lastTime;
unsigned __int64 m_timerFrequency;
float m_timeCounter;
float m_frameTime;
float secPerCent;
 
////////////////////////////////////////////////////////////////
//Global Functions
////////////////////////////////////////////////////////////////
 
void CleanUp()
{
        
        delete m_game;
        Direct3D9::Destroy();
        //DirectDraw::Destroy();
}
 
//////////////////////////////////////////////////////
//The render method for the program, 
//everything that need to be rendered will be placed here.
//////////////////////////////////////////////////////
void
Render(HWND hWindow)
{
        //cleans the screen
 
        Direct3D9::GetInstance()->ClearSurface();
 
        m_game->Render(Direct3D9::GetInstance()->GetD3dDevice());
 
        Direct3D9::GetInstance()->GetD3dDevice()->Present(NULL,NULL,NULL,NULL);
 
        //D3dx9::GetD3dDevice()->Present(0,0,0,0);
        //
        //DirectDraw::GetInstance()->ClearSurface(hWindow);
 
        //m_game->Render(DirectDraw::GetInstance()->GetBackBuffer());
 
        //DirectDraw::GetInstance()->PresentBackBuffer(hWindow);
 
}
///////////////////////////////////////////////////////////
//Update method that controls all things checked per 
//program cycle
///////////////////////////////////////////////////////////
void
Update()
{
        float timeNow = (float)m_timer.GetTime();
        float timeDiff = timeNow -(float)m_lastTime;
        m_lastTime = (unsigned __int64)timeNow;
        float timeDiffFloat = timeDiff * secPerCent;
        //DirectDraw::GetInstance()->RestoreSurfaces();
 
        m_game->Update(timeDiffFloat);
}
 
////////////////////////////////////////////////////////////////
//This is the WinMain Function, Like the Main Function of a console application 
//The WinMain Function is the entry point of a windows program,
//It is mainly used to set up the window then within a while loop, 
//process the windows messages recieved by the system,
////////////////////////////////////////////////////////////////
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,PSTR szCmdLine,int iCmdShow)
{
 
        //m_enviromentPosition = Vector2D(900,0);
        //This is the name of the application  
        static TCHAR  szAppName[] = TEXT("Direct3D9 Behaviour Systems");
        //WNDCLASSEX structure contains window class information
        WNDCLASSEX        wndclass;
        //HWND is the window handle
        HWND              hWindow;
        //Is contains the latest windows message
        MSG                       msg;
 
        wndclass.cbSize                 = sizeof(WNDCLASSEX);
        wndclass.style                  = CS_HREDRAW | CS_VREDRAW;
        wndclass.lpfnWndProc    = WndProc;
        wndclass.cbClsExtra             = 0;
        wndclass.cbWndExtra             = 0;
        wndclass.hInstance              = hInstance;
        wndclass.hIcon                  = NULL;
        wndclass.hCursor                = LoadCursor(NULL, IDC_ARROW);
        wndclass.hbrBackground  = (HBRUSH)(COLOR_WINDOW+1);
        wndclass.lpszMenuName   = NULL;
        wndclass.lpszClassName  = szAppName;
        wndclass.hIconSm                = NULL;
 
        //This Registers the windows class with the system, if any parameter is invalid
        //the program will terminate here
        if(!RegisterClassEx(&wndclass))
                return 0;
 
        RECT rc;
        
        // Calculate size of window based on desired client window size
        rc.left = 0;
        rc.top = 0;
        rc.right = 800;
        rc.bottom = 600;
        
        if (m_fullScreen)
        {
                hWindow = CreateWindowEx(0, szAppName, szAppName, WS_POPUP,
                                                                   0, 0,rc.right-rc.left, rc.bottom-rc.top,NULL, NULL, hInstance, NULL );
        }
        else
        {
                AdjustWindowRect( &rc, WS_OVERLAPPEDWINDOW, FALSE );
 
                hWindow = CreateWindowEx(0, szAppName, szAppName, WS_OVERLAPPEDWINDOW,
                                                                   100, 100,rc.right-rc.left, rc.bottom-rc.top,NULL, NULL, hInstance, NULL );
        }
 
        //Now show and update the window for the first time
        ShowWindow(hWindow,iCmdShow);
        UpdateWindow(hWindow);
        m_running = true;
 
        //DirectDraw::Create();
        Direct3D9::Create();
 
        //if (DirectDraw::GetInstance()->CreateDevice( hWindow ,800 , 600 ,m_fullScreen) != 1)
        //{
        //      MessageBox( hWindow, "Failed to create surfaces", "Error", MB_OK );
        //      return 0;
        //}
 
        if (Direct3D9::GetInstance()->InitialiseDirect3D(hWindow) != 1)
        {
                MessageBox( hWindow, "Failed to create surfaces", "Error", MB_OK );
                return 0;
        }
 
        InvalidateRect( hWindow, NULL, TRUE );
 
        //we create a timer to force the game to update every 1/60th of a second
        //otherwise there could be preformance issues as the buffers are being swapped
        //too quickly
        SetTimer(hWindow,Refresh,1000/200,NULL);
 
        m_game = new Game(Direct3D9::GetInstance()->GetD3dDevice());
 
        m_timerFrequency = m_timer.GetFrequency();
        secPerCent = 1.0f / (float)m_timerFrequency;
        m_lastTime = m_timer.GetTime();
 
        //this is the main look of the windows application , while the window is open
        //its processes and translates windows messages into something useable,
        //then sends the message to the relivent location.
        //when the program closes, the program exits the loop and the messages will end, resulting on the exit of this loop.
        while(m_running)
        {
                while(PeekMessage(&msg, NULL, 0,0, PM_NOREMOVE))
                {
                        BOOL bGetResult = GetMessage(&msg, NULL, 0, 0);
                        TranslateMessage(&msg);
                        DispatchMessage(&msg);
                }
 
                Update();
                
        }
 
        CleanUp();
        return (int)msg.wParam;
}
 
//////////////////////////////////////////////////////////////////////////
//The WndProc method processes the messages sent through windows, 
//each message contains WM_ and then the message, for example, if the user clicks the left mouse button
//the message WM_LBUTTONDOWN is sent.
//////////////////////////////////////////////////////////////////////////
LRESULT CALLBACK WndProc(HWND hWindow,UINT msg,WPARAM wParam,LPARAM lParam)
{
        //this switch statement processes the message sent, here you can program the code
        //for each type of message's reaction
        switch(msg)
        {
                //WM_PAINT is a render command
                case WM_PAINT:
                        ValidateRect( hWindow, NULL );
                        return 0;
                        break;
                //WM_LBUTTONDOWN is a message send every time the left mouse button is clicked over the Client area
                case WM_TIMER:
                        switch(wParam)
                        {
                                case Refresh:
                                        Render(hWindow);
                                break;
                        }
                        return 0;
                        break;
                case WM_LBUTTONDOWN:
                        //m_BackGround->SetScrollVelocity(Vector2D(-m_BackGround->GetScrollVelocity().x,0));
                        return 0;
                        break;
                //the WM_DESTROY message is the message sent when the program is going to terminate
                case WM_DESTROY:
                        DestroyWindow( hWindow );
                        m_running = false;
                        PostQuitMessage(0);
                        return 0;
                break;
        }
        //it returns default processing for any window message that an switch statement does not process
        return DefWindowProc(hWindow,msg,wParam,lParam);
}
 
prog.cpp:5: warning: ignoring #pragma comment 
prog.cpp:6: warning: ignoring #pragma comment 
prog.cpp:21:21: error: windows.h: No such file or directory
prog.cpp:22:22: error: windowsx.h: No such file or directory
prog.cpp:25:19: error: D3dx9.h: No such file or directory
prog.cpp:26:18: error: d3d9.h: No such file or directory
prog.cpp:27:23: error: Direct3D9.h: No such file or directory
prog.cpp:29:22: error: Vector2D.h: No such file or directory
prog.cpp:30:18: error: main.h: No such file or directory
prog.cpp:31:19: error: Timer.h: No such file or directory
prog.cpp:32:18: error: Game.h: No such file or directory
prog.cpp:44: error: ‘LRESULT’ does not name a type
prog.cpp:50: error: expected constructor, destructor, or type conversion before ‘*’ token
prog.cpp:52: error: ‘Timer’ does not name a type
prog.cpp:53: error: ‘__int64’ does not name a type
prog.cpp:54: error: ‘__int64’ does not name a type
prog.cpp: In function ‘void CleanUp()’:
prog.cpp:66: error: ‘m_game’ was not declared in this scope
prog.cpp:67: error: ‘Direct3D9’ has not been declared
prog.cpp: At global scope:
prog.cpp:76: error: variable or field ‘Render’ declared void
prog.cpp:76: error: ‘HWND’ was not declared in this scope
prog.cpp: In function ‘void Update()’:
prog.cpp:102: error: ‘m_timer’ was not declared in this scope
prog.cpp:103: error: ‘m_lastTime’ was not declared in this scope
prog.cpp:104: error: expected primary-expression before ‘unsigned’
prog.cpp:104: error: expected `)' before ‘unsigned’
prog.cpp:108: error: ‘m_game’ was not declared in this scope
prog.cpp: At global scope:
prog.cpp:117: error: expected initializer before ‘WinMain’