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