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 "main.h"
  31. #include "Timer.h"
  32. #include "Game.h"
  33. //#include "DirectDraw.h"
  34.  
  35.  
  36. //#include "Singleton.h"
  37.  
  38.  
  39. ////////////////////////////////////////////////////////////////
  40. //Global Functions Decarations
  41. ////////////////////////////////////////////////////////////////
  42.  
  43.  
  44. LRESULT CALLBACK WndProc(HWND hWindow,UINT msg, WPARAM wParam, LPARAM lParam);
  45.  
  46. bool m_fullScreen = false;
  47.  
  48. bool m_running;
  49.  
  50. Game* m_game;
  51.  
  52. Timer m_timer;
  53. unsigned __int64 m_lastTime;
  54. unsigned __int64 m_timerFrequency;
  55. float m_timeCounter;
  56. float m_frameTime;
  57. float secPerCent;
  58.  
  59. ////////////////////////////////////////////////////////////////
  60. //Global Functions
  61. ////////////////////////////////////////////////////////////////
  62.  
  63. void CleanUp()
  64. {
  65.  
  66. delete m_game;
  67. Direct3D9::Destroy();
  68. //DirectDraw::Destroy();
  69. }
  70.  
  71. //////////////////////////////////////////////////////
  72. //The render method for the program,
  73. //everything that need to be rendered will be placed here.
  74. //////////////////////////////////////////////////////
  75. void
  76. Render(HWND hWindow)
  77. {
  78. //cleans the screen
  79.  
  80. Direct3D9::GetInstance()->ClearSurface();
  81.  
  82. m_game->Render(Direct3D9::GetInstance()->GetD3dDevice());
  83.  
  84. Direct3D9::GetInstance()->GetD3dDevice()->Present(NULL,NULL,NULL,NULL);
  85.  
  86. //D3dx9::GetD3dDevice()->Present(0,0,0,0);
  87. //
  88. //DirectDraw::GetInstance()->ClearSurface(hWindow);
  89.  
  90. //m_game->Render(DirectDraw::GetInstance()->GetBackBuffer());
  91.  
  92. //DirectDraw::GetInstance()->PresentBackBuffer(hWindow);
  93.  
  94. }
  95. ///////////////////////////////////////////////////////////
  96. //Update method that controls all things checked per
  97. //program cycle
  98. ///////////////////////////////////////////////////////////
  99. void
  100. Update()
  101. {
  102. float timeNow = (float)m_timer.GetTime();
  103. float timeDiff = timeNow -(float)m_lastTime;
  104. m_lastTime = (unsigned __int64)timeNow;
  105. float timeDiffFloat = timeDiff * secPerCent;
  106. //DirectDraw::GetInstance()->RestoreSurfaces();
  107.  
  108. m_game->Update(timeDiffFloat);
  109. }
  110.  
  111. ////////////////////////////////////////////////////////////////
  112. //This is the WinMain Function, Like the Main Function of a console application
  113. //The WinMain Function is the entry point of a windows program,
  114. //It is mainly used to set up the window then within a while loop,
  115. //process the windows messages recieved by the system,
  116. ////////////////////////////////////////////////////////////////
  117. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,PSTR szCmdLine,int iCmdShow)
  118. {
  119.  
  120. //m_enviromentPosition = Vector2D(900,0);
  121. //This is the name of the application
  122. static TCHAR szAppName[] = TEXT("Direct3D9 Behaviour Systems");
  123. //WNDCLASSEX structure contains window class information
  124. WNDCLASSEX wndclass;
  125. //HWND is the window handle
  126. HWND hWindow;
  127. //Is contains the latest windows message
  128. MSG msg;
  129.  
  130. wndclass.cbSize = sizeof(WNDCLASSEX);
  131. wndclass.style = CS_HREDRAW | CS_VREDRAW;
  132. wndclass.lpfnWndProc = WndProc;
  133. wndclass.cbClsExtra = 0;
  134. wndclass.cbWndExtra = 0;
  135. wndclass.hInstance = hInstance;
  136. wndclass.hIcon = NULL;
  137. wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
  138. wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  139. wndclass.lpszMenuName = NULL;
  140. wndclass.lpszClassName = szAppName;
  141. wndclass.hIconSm = NULL;
  142.  
  143. //This Registers the windows class with the system, if any parameter is invalid
  144. //the program will terminate here
  145. if(!RegisterClassEx(&wndclass))
  146. return 0;
  147.  
  148. RECT rc;
  149.  
  150. // Calculate size of window based on desired client window size
  151. rc.left = 0;
  152. rc.top = 0;
  153. rc.right = 800;
  154. rc.bottom = 600;
  155.  
  156. if (m_fullScreen)
  157. {
  158. hWindow = CreateWindowEx(0, szAppName, szAppName, WS_POPUP,
  159. 0, 0,rc.right-rc.left, rc.bottom-rc.top,NULL, NULL, hInstance, NULL );
  160. }
  161. else
  162. {
  163. AdjustWindowRect( &rc, WS_OVERLAPPEDWINDOW, FALSE );
  164.  
  165. hWindow = CreateWindowEx(0, szAppName, szAppName, WS_OVERLAPPEDWINDOW,
  166. 100, 100,rc.right-rc.left, rc.bottom-rc.top,NULL, NULL, hInstance, NULL );
  167. }
  168.  
  169. //Now show and update the window for the first time
  170. ShowWindow(hWindow,iCmdShow);
  171. UpdateWindow(hWindow);
  172. m_running = true;
  173.  
  174. //DirectDraw::Create();
  175. Direct3D9::Create();
  176.  
  177. //if (DirectDraw::GetInstance()->CreateDevice( hWindow ,800 , 600 ,m_fullScreen) != 1)
  178. //{
  179. // MessageBox( hWindow, "Failed to create surfaces", "Error", MB_OK );
  180. // return 0;
  181. //}
  182.  
  183. if (Direct3D9::GetInstance()->InitialiseDirect3D(hWindow) != 1)
  184. {
  185. MessageBox( hWindow, "Failed to create surfaces", "Error", MB_OK );
  186. return 0;
  187. }
  188.  
  189. InvalidateRect( hWindow, NULL, TRUE );
  190.  
  191. //we create a timer to force the game to update every 1/60th of a second
  192. //otherwise there could be preformance issues as the buffers are being swapped
  193. //too quickly
  194. SetTimer(hWindow,Refresh,1000/200,NULL);
  195.  
  196. m_game = new Game(Direct3D9::GetInstance()->GetD3dDevice());
  197.  
  198. m_timerFrequency = m_timer.GetFrequency();
  199. secPerCent = 1.0f / (float)m_timerFrequency;
  200. m_lastTime = m_timer.GetTime();
  201.  
  202. //this is the main look of the windows application , while the window is open
  203. //its processes and translates windows messages into something useable,
  204. //then sends the message to the relivent location.
  205. //when the program closes, the program exits the loop and the messages will end, resulting on the exit of this loop.
  206. while(m_running)
  207. {
  208. while(PeekMessage(&msg, NULL, 0,0, PM_NOREMOVE))
  209. {
  210. BOOL bGetResult = GetMessage(&msg, NULL, 0, 0);
  211. TranslateMessage(&msg);
  212. DispatchMessage(&msg);
  213. }
  214.  
  215. Update();
  216.  
  217. }
  218.  
  219. CleanUp();
  220. return (int)msg.wParam;
  221. }
  222.  
  223. //////////////////////////////////////////////////////////////////////////
  224. //The WndProc method processes the messages sent through windows,
  225. //each message contains WM_ and then the message, for example, if the user clicks the left mouse button
  226. //the message WM_LBUTTONDOWN is sent.
  227. //////////////////////////////////////////////////////////////////////////
  228. LRESULT CALLBACK WndProc(HWND hWindow,UINT msg,WPARAM wParam,LPARAM lParam)
  229. {
  230. //this switch statement processes the message sent, here you can program the code
  231. //for each type of message's reaction
  232. switch(msg)
  233. {
  234. //WM_PAINT is a render command
  235. case WM_PAINT:
  236. ValidateRect( hWindow, NULL );
  237. return 0;
  238. break;
  239. //WM_LBUTTONDOWN is a message send every time the left mouse button is clicked over the Client area
  240. case WM_TIMER:
  241. switch(wParam)
  242. {
  243. case Refresh:
  244. Render(hWindow);
  245. break;
  246. }
  247. return 0;
  248. break;
  249. case WM_LBUTTONDOWN:
  250. //m_BackGround->SetScrollVelocity(Vector2D(-m_BackGround->GetScrollVelocity().x,0));
  251. return 0;
  252. break;
  253. //the WM_DESTROY message is the message sent when the program is going to terminate
  254. case WM_DESTROY:
  255. DestroyWindow( hWindow );
  256. m_running = false;
  257. PostQuitMessage(0);
  258. return 0;
  259. break;
  260. }
  261. //it returns default processing for any window message that an switch statement does not process
  262. return DefWindowProc(hWindow,msg,wParam,lParam);
  263. }
  264.  
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: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’
stdout
Standard output is empty