fork download
  1. // main.cpp : Defines the entry point for the application.
  2. //
  3.  
  4. // include the Direct3D Library file
  5. #pragma comment (lib, "d3d9.lib")
  6. #pragma comment (lib, "d3dx9.lib")
  7. //#pragma comment(lib, "dsound.lib")
  8. //#pragma comment (lib, "dinput8.lib")
  9. //#pragma comment (lib, "dxguid.lib")
  10.  
  11.  
  12. //#pragma comment(lib, "ddraw.lib")
  13. //#pragma comment(lib, "dxguid.lib")
  14.  
  15. #define _CRT_SECURE_NO_WARNINGS
  16. #define STRICT
  17. #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
  18. //#define VC_EXTRALEAN
  19. // Windows Header Files:
  20. //#include <ddraw.h>
  21. #include <windows.h>
  22. #include <windowsx.h>
  23. //#include <MMSystem.h>
  24.  
  25. #include <D3dx9.h>
  26. #include <d3d9.h>
  27. #include "Direct3D9.h"
  28.  
  29. #include "Vector2D.h"
  30. #include "SceneNavigation.h"
  31. #include "main.h"
  32. #include "Timer.h"
  33. #include "Game.h"
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40. ////////////////////////////////////////////////////////////////
  41. //Global Functions Decarations
  42. ////////////////////////////////////////////////////////////////
  43.  
  44.  
  45. LRESULT CALLBACK WndProc(HWND hWindow,UINT msg, WPARAM wParam, LPARAM lParam);
  46.  
  47. bool m_fullScreen = false;
  48.  
  49. bool m_running;
  50.  
  51. Game* m_game;
  52.  
  53. Timer m_timer;
  54. unsigned __int64 m_lastTime;
  55. unsigned __int64 m_timerFrequency;
  56. float m_timeCounter;
  57. float m_frameTime;
  58. float secPerCent;
  59.  
  60.  
  61. ////////////////////////////////////////////////////////////////
  62. //Global Functions
  63. ////////////////////////////////////////////////////////////////
  64.  
  65. void CleanUp()
  66. {
  67.  
  68. delete m_game;
  69. Direct3D9::Destroy();
  70. //DirectDraw::Destroy();
  71. }
  72.  
  73. //////////////////////////////////////////////////////
  74. //The render method for the program,
  75. //everything that need to be rendered will be placed here.
  76. //////////////////////////////////////////////////////
  77. void
  78. Render(HWND hWindow)
  79. {
  80. //cleans the screen
  81.  
  82. Direct3D9::GetInstance()->ClearSurface();
  83.  
  84. m_game->Render(Direct3D9::GetInstance()->GetD3dDevice());
  85.  
  86.  
  87.  
  88. Direct3D9::GetInstance()->GetD3dDevice()->Present(NULL,NULL,NULL,NULL);
  89.  
  90. //D3dx9::GetD3dDevice()->Present(0,0,0,0);
  91. //
  92. //DirectDraw::GetInstance()->ClearSurface(hWindow);
  93.  
  94. //m_game->Render(DirectDraw::GetInstance()->GetBackBuffer());
  95.  
  96. //DirectDraw::GetInstance()->PresentBackBuffer(hWindow);
  97.  
  98. }
  99. ///////////////////////////////////////////////////////////
  100. //Update method that controls all things checked per
  101. //program cycle
  102. ///////////////////////////////////////////////////////////
  103. void
  104. Update()
  105. {
  106. float timeNow = (float)m_timer.GetTime();
  107. float timeDiff = timeNow -(float)m_lastTime;
  108. m_lastTime = (unsigned __int64)timeNow;
  109. float timeDiffFloat = timeDiff * secPerCent;
  110. //DirectDraw::GetInstance()->RestoreSurfaces();
  111.  
  112. m_game->Update(timeDiffFloat);
  113.  
  114. }
  115.  
  116. ////////////////////////////////////////////////////////////////
  117. //This is the WinMain Function, Like the Main Function of a console application
  118. //The WinMain Function is the entry point of a windows program,
  119. //It is mainly used to set up the window then within a while loop,
  120. //process the windows messages recieved by the system,
  121. ////////////////////////////////////////////////////////////////
  122. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,PSTR szCmdLine,int iCmdShow)
  123. {
  124.  
  125. //m_enviromentPosition = Vector2D(900,0);
  126. //This is the name of the application
  127. static TCHAR szAppName[] = TEXT("Direct3D9 Behaviour Systems");
  128. //WNDCLASSEX structure contains window class information
  129. WNDCLASSEX wndclass;
  130. //HWND is the window handle
  131. HWND hWindow;
  132. //Is contains the latest windows message
  133. MSG msg;
  134.  
  135. wndclass.cbSize = sizeof(WNDCLASSEX);
  136. wndclass.style = CS_HREDRAW | CS_VREDRAW;
  137. wndclass.lpfnWndProc = WndProc;
  138. wndclass.cbClsExtra = 0;
  139. wndclass.cbWndExtra = 0;
  140. wndclass.hInstance = hInstance;
  141. wndclass.hIcon = NULL;
  142. wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
  143. wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  144. wndclass.lpszMenuName = NULL;
  145. wndclass.lpszClassName = szAppName;
  146. wndclass.hIconSm = NULL;
  147.  
  148. //This Registers the windows class with the system, if any parameter is invalid
  149. //the program will terminate here
  150. if(!RegisterClassEx(&wndclass))
  151. return 0;
  152.  
  153. RECT rc;
  154.  
  155. // Calculate size of window based on desired client window size
  156. rc.left = 0;
  157. rc.top = 0;
  158. rc.right = 800;
  159. rc.bottom = 600;
  160.  
  161. if (m_fullScreen)
  162. {
  163. hWindow = CreateWindowEx(0, szAppName, szAppName, WS_POPUP,
  164. 0, 0,rc.right-rc.left, rc.bottom-rc.top,NULL, NULL, hInstance, NULL );
  165. }
  166. else
  167. {
  168. AdjustWindowRect( &rc, WS_OVERLAPPEDWINDOW, FALSE );
  169.  
  170. hWindow = CreateWindowEx(0, szAppName, szAppName, WS_OVERLAPPEDWINDOW,
  171. 100, 100,rc.right-rc.left, rc.bottom-rc.top,NULL, NULL, hInstance, NULL );
  172. }
  173.  
  174. //Now show and update the window for the first time
  175. ShowWindow(hWindow,iCmdShow);
  176. UpdateWindow(hWindow);
  177. m_running = true;
  178.  
  179. //DirectDraw::Create();
  180. Direct3D9::Create();
  181.  
  182. //if (DirectDraw::GetInstance()->CreateDevice( hWindow ,800 , 600 ,m_fullScreen) != 1)
  183. //{
  184. // MessageBox( hWindow, "Failed to create surfaces", "Error", MB_OK );
  185. // return 0;
  186. //}
  187.  
  188. if (Direct3D9::GetInstance()->InitialiseDirect3D(hWindow) != 1)
  189. {
  190. MessageBox( hWindow, "Failed to create surfaces", "Error", MB_OK );
  191. return 0;
  192. }
  193.  
  194. InvalidateRect( hWindow, NULL, TRUE );
  195.  
  196. //we create a timer to force the game to update every 1/60th of a second
  197. //otherwise there could be preformance issues as the buffers are being swapped
  198. //too quickly
  199. SetTimer(hWindow,Refresh,1000/200,NULL);
  200.  
  201. m_game = new Game(Direct3D9::GetInstance()->GetD3dDevice());
  202.  
  203. m_timerFrequency = m_timer.GetFrequency();
  204. secPerCent = 1.0f / (float)m_timerFrequency;
  205. m_lastTime = m_timer.GetTime();
  206.  
  207. //this is the main look of the windows application , while the window is open
  208. //its processes and translates windows messages into something useable,
  209. //then sends the message to the relivent location.
  210. //when the program closes, the program exits the loop and the messages will end, resulting on the exit of this loop.
  211. while(m_running)
  212. {
  213. while(PeekMessage(&msg, NULL, 0,0, PM_NOREMOVE))
  214. {
  215. BOOL bGetResult = GetMessage(&msg, NULL, 0, 0);
  216. TranslateMessage(&msg);
  217. DispatchMessage(&msg);
  218. }
  219.  
  220. Update();
  221.  
  222. }
  223.  
  224. CleanUp();
  225. return (int)msg.wParam;
  226. }
  227.  
  228. //////////////////////////////////////////////////////////////////////////
  229. //The WndProc method processes the messages sent through windows,
  230. //each message contains WM_ and then the message, for example, if the user clicks the left mouse button
  231. //the message WM_LBUTTONDOWN is sent.
  232. //////////////////////////////////////////////////////////////////////////
  233. LRESULT CALLBACK WndProc(HWND hWindow,UINT msg,WPARAM wParam,LPARAM lParam)
  234. {
  235. //this switch statement processes the message sent, here you can program the code
  236. //for each type of message's reaction
  237. switch(msg)
  238. {
  239. //WM_PAINT is a render command
  240. case WM_PAINT:
  241. ValidateRect( hWindow, NULL );
  242. return 0;
  243. break;
  244. //WM_LBUTTONDOWN is a message send every time the left mouse button is clicked over the Client area
  245. case WM_TIMER:
  246. switch(wParam)
  247. {
  248. case Refresh:
  249. Render(hWindow);
  250. break;
  251. }
  252. return 0;
  253. break;
  254.  
  255. case WM_LBUTTONDOWN:
  256. float x = (float)GET_X_LPARAM(lParam);
  257. float y = (float)GET_Y_LPARAM(lParam);
  258. m_game->scene->sceneEditor.SetMouseDownPosition(x, y);
  259. return 0;
  260. break;
  261. //case WM_LBUTTONDOWN:
  262. // //m_BackGround->SetScrollVelocity(Vector2D(-m_BackGround->GetScrollVelocity().x,0));
  263. // return 0;
  264. // break;
  265.  
  266. //the WM_DESTROY message is the message sent when the program is going to terminate
  267. case WM_DESTROY:
  268. DestroyWindow( hWindow );
  269. m_running = false;
  270. PostQuitMessage(0);
  271. return 0;
  272. break;
  273. case WM_KEYDOWN:
  274. if (wParam == 0x57)
  275. {
  276. m_game->scene->sceneEditor.isWKeyPressed = true;
  277. }
  278. if (wParam == 0x51)
  279. {
  280. m_game->scene->sceneEditor.isQKeyPressed = true;
  281. }
  282. break;
  283. case WM_KEYUP:
  284. if (wParam == 0x57)
  285. {
  286. m_game->scene->sceneEditor.isWKeyReleased = true;
  287. }
  288. if (wParam == 0x51)
  289. {
  290. m_game->scene->sceneEditor.isQKeyReleased = true;
  291. }
  292. break;
  293.  
  294. case WM_MOUSEMOVE:
  295. float xPos = (float)GET_X_LPARAM(lParam);
  296. float yPos = (float)GET_Y_LPARAM(lParam);
  297. m_game->scene->SetMousePosition(xPos, yPos);
  298. //return 0;
  299. break;
  300.  
  301.  
  302.  
  303. }
  304. //it returns default processing for any window message that an switch statement does not process
  305. return DefWindowProc(hWindow,msg,wParam,lParam);
  306. }
  307.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
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:29: error: SceneNavigation.h: No such file or directory
prog.cpp:31:18: error: main.h: No such file or directory
prog.cpp:32:19: error: Timer.h: No such file or directory
prog.cpp:33:18: error: Game.h: No such file or directory
prog.cpp:45: error: ‘LRESULT’ does not name a type
prog.cpp:51: error: expected constructor, destructor, or type conversion before ‘*’ token
prog.cpp:53: error: ‘Timer’ does not name a type
prog.cpp:54: error: ‘__int64’ does not name a type
prog.cpp:55: error: ‘__int64’ does not name a type
prog.cpp: In function ‘void CleanUp()’:
prog.cpp:68: error: ‘m_game’ was not declared in this scope
prog.cpp:69: error: ‘Direct3D9’ has not been declared
prog.cpp: At global scope:
prog.cpp:78: error: variable or field ‘Render’ declared void
prog.cpp:78: error: ‘HWND’ was not declared in this scope
prog.cpp: In function ‘void Update()’:
prog.cpp:106: error: ‘m_timer’ was not declared in this scope
prog.cpp:107: error: ‘m_lastTime’ was not declared in this scope
prog.cpp:108: error: expected primary-expression before ‘unsigned’
prog.cpp:108: error: expected `)' before ‘unsigned’
prog.cpp:112: error: ‘m_game’ was not declared in this scope
prog.cpp: At global scope:
prog.cpp:122: error: expected initializer before ‘WinMain’
stdout
Standard output is empty