Code: Select all
#include <irrlicht.h>
#ifndef _IRR_WINDOWS_
#error Windows Only
#else
#include <windows.h>
#include "Game.h"
using namespace irr;
#pragma comment(lib, "irrlicht.lib")
#define FRAME_RATE 5
HWND hWnd;
Game* myGame;
static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_CREATE:
return 0;
case WM_CLOSE:
PostQuitMessage(0);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
case WM_KEYDOWN:
myGame->handleKeypress(wParam, 1);
switch ( wParam )
{
case VK_ESCAPE:
PostQuitMessage(0);
return 0;
}
return 0;
default:
return DefWindowProc( hWnd, message, wParam, lParam );
}
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hpre, LPSTR cmd, int cc)
{
MSG msg;
BOOL quit = FALSE;
const char* Win32ClassName = "Game";
float timeLast = GetTickCount();
float currentTime;
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = DLGWINDOWEXTRA;
wcex.hInstance = hInstance;
wcex.hIcon = NULL;
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW);
wcex.lpszMenuName = 0;
wcex.lpszClassName = Win32ClassName;
wcex.hIconSm = 0;
RegisterClassEx(&wcex);
DWORD style = WS_SYSMENU | WS_BORDER | WS_CAPTION |
WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_MAXIMIZEBOX | WS_MINIMIZEBOX | WS_SIZEBOX;
int windowWidth = 1024;
int windowHeight = 768;
hWnd = CreateWindow( Win32ClassName, "Game",
style, 0, 0, windowWidth, windowHeight,
NULL, NULL, hInstance, NULL);
RECT clientRect;
GetClientRect(hWnd, &clientRect);
windowWidth = clientRect.right;
windowHeight = clientRect.bottom;
HWND hIrrlichtWindow = CreateWindow("BUTTON", "", WS_CHILD | WS_VISIBLE | BS_OWNERDRAW,
0, 0, windowWidth, windowHeight, hWnd, NULL, hInstance, NULL);
// IRRLICHT INIT -
irr::SIrrlichtCreationParameters param;
param.WindowId = reinterpret_cast<void*>(hIrrlichtWindow);
param.DriverType = video::EDT_DIRECT3D9;
irr::IrrlichtDevice* device = irr::createDeviceEx(param);
irr::scene::ISceneManager* smgr = device->getSceneManager();
video::IVideoDriver* driver = device->getVideoDriver();
//
myGame = new Game(device, driver, smgr);
myGame->loadLevel();
myGame->initialiseGameplay();
ShowWindow(hWnd , SW_SHOW);
UpdateWindow(hWnd);
while(true)
{
currentTime = GetTickCount();
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
if (msg.message == WM_QUIT)
break;
}
if(currentTime-timeLast > FRAME_RATE)
{
myGame->update(currentTime-timeLast/FRAME_RATE);
myGame->draw();
timeLast = currentTime;
}
}
delete(myGame);
device->closeDevice();
device->drop();
return 0;
}
#endif // if windows