Sign in to follow this  
emforce

help game engine

Recommended Posts

emforce    191
hi guys i am having trouble with my game engine can u guys please help me :D

#include "GameEngine.h"

GameEngine *GameEngine::m_pGameEngine = NULL;


int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
	MSG			msg;
	static int iTickTrigger = 0;
	int iTickCount;

	if (GameInitialize(hInstance))
	{
	//initialize the game engine
	if(!GameEngine::GetEngine() ->Initialize(iCmdShow))
		return FALSE;

	while (TRUE)
	{
		if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
		{
			if(msg.message == WM_QUIT)
				break;
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
		else
		{
			if(!GameEngine::GetEngine()->GetSleep())
			{

				iTickCount = GetTickCount();
				if(iTickCount > iTickTrigger)
				{
					iTickTrigger = iTickCount +
						GameEngine::GetEngine() ->GetFrameDelay();
					GameCycle();
				}
			}
		}
	}
	return (int)msg.wParam;
}
GameEnd();

return TRUE;
}

LRESULT CALLBACK WndProc(HWND hWindow, UINT msg, WPARAM wParam, LPARAM lParam)
{
	return GameEngine::GetEngine() ->HandleEvent(hWindow, msg, wParam, lParam);
}


GameEngine::GameEngine(HINSTANCE hInstance, LPTSTR szWindowClass, LPTSTR szTitle,
					   WORD wIcon, WORD wSmallIcon, int iWidth, int iHeight)
{

	m_pGameEngine = this;
	m_hInstance = hInstance;
	m_hWindow = NULL;
	if (lstrlen(szWindowClass) > 0)
		lstrcpy(m_szWindowClass, szWindowClass);
	if (lstrlen(szTitle) > 0)
		lstrcpy(m_szTitle, szTitle);
	m_wIcon = wIcon;
	m_wSmallIcon = wSmallIcon;
	m_iWidth = iWidth;
	m_iHeight = iHeight;
	m_iFrameDelay = 50;
	m_bSleep = TRUE;
}

GameEngine::~GameEngine()
{
}

BOOL GameEngine::Initialize(int iCmdShow)
{
	WNDCLASSEX  wndclass;

	wndclass.cbSize  = sizeof(wndclass);
	wndclass.style   = CS_HREDRAW ¦ CS_VREDRAW; //error C2146, error C2065, error C2143
	wndclass.lpfnWndProc = WndProc;
	wndclass.cbClsExtra = 0;
	wndclass.cbWndExtra = 0;
	wndclass.hInstance = m_hInstance;
	wndclass.hIcon = LoadIcon(m_hInstance, MAKEINTRESOURCE(GetIcon()));
	wndclass.hIconSm = LoadIcon(m_hInstance, MAKEINTRESOURCE(GetSmallIcon()));
	wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
	wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
	wndclass.lpszMenuName = NULL;
	wndclass.lpszClassName = m_szWindowClass;

	if (!RegisterClassEx(&wndclass))
		return FALSE;

	int iWindowWidth = m_iWidth + GetSystemMetrics(SM_CXFIXEDFRAME) * 2,
		iWindowHeight = m_iHeight + GetSystemMetrics(SM_CYFIXEDFRAME) * 2 + 
		GetSystemMetrics(SM_CYCAPTION);
	if (wndclass.lpszMenuName != NULL)
		iWindowHeight += GetSystemMetrics(SM_CYMENU);
	int iXWindowPos = (GetSystemMetrics(SM_CXSCREEN) - iWindowWidth) / 2,
		iYWindowPos = (GetSystemMetrics(SM_CYSCREEN) - iWindowHeight) / 2;

	m_hWindow = CreateWindow(m_szWindowClass, m_szTitle, WS_POPUPWINDOW ¦
		WS_CAPTION ¦ WS_MINIMIZEBOX, iXWindowPos, iYWindowPos, iWindowHeight, iWindowWidth, NULL , NULL, m_hInstance, NULL);
	// this is errorr line error C2146, C2660, C2059
	if (!m_hWindow)
		return FALSE;

	ShowWindow(m_hWindow, iCmdShow);
	UpdateWindow(m_hWindow);

	return TRUE;
}

LRESULT GameEngine::HandleEvent(HWND hWindow, UINT msg, WPARAM wParam,
								LPARAM lParam)
{
	switch(msg)
	{
	case WM_CREATE:
		SetWindow(hWindow);
		GameStart(hWindow);
		return 0;

	case WM_SETFOCUS:
		GameActivate(hWindow);
		SetSleep(FALSE);
		return 0;
	case WM_KILLFOCUS:
		GameDeactivate(hWindow);
		SetSleep(TRUE);
		return 0;
	case WM_PAINT:
		HDC			hDC;
		PAINTSTRUCT ps;
		hDC = BeginPaint(hWindow, &ps);

		GamePaint(hDC);

		EndPaint(hWindow, &ps);
		return 0;

	case WM_DESTROY:
		GameEnd();
		PostQuitMessage(0);
		return 0;
	}
	return DefWindowProc(hWindow, msg, wParam, lParam);
}

please can u help

Share this post


Link to post
Share on other sites
Drew_Benton    1861
Your bitwise or operators are not the right character.

If you look carefully at your code you have this symbol: ¦ (Broken pipe in half) and it should be a solid bar, this symbol: | (Solid pipe)

Share this post


Link to post
Share on other sites
emforce    191
thanks alot :D it fixed it. btw this is my first empty game engine is it supposed to bring up about 10 linker errors if it has no syntax errors and the like?

Share this post


Link to post
Share on other sites
jyk    2094
Quote:
btw this is my first empty game engine is it supposed to bring up about 10 linker errors if it has no syntax errors and the like?
You can have linker errors without having any compiler errors. Furthermore, if you do have linker errors, it means that something is wrong (just as with compiler errors). If you're not sure what's wrong, or what the errors mean, post them and someone can probably help point you in the right direction.

That code is from the book Beginning Game Programming, right? Or maybe Sams Teach Yourself Game Programming In 24 Hrs? If so, you may be getting linker errors because the definitions of the functions in question aren't presented until later in the book (at least this is what I picked up by Googling around a bit).

This is completely IMHO, but I would question whether this is the best reference to be using (and whether this is the best way to go about introducing oneself to C++ or to game programming in general). Even if you're intent on starting with C++ rather than a more user-friendly language such as C#, I think there are easier (and more educational) ways to get into it then copying some Windows-specific 'game engine' code out of a book.

For one thing, this mires you in the details of WinAPI programming from the get-go, which really isn't a very good way to be introduced to the language or to game development in general, and can stick you with some bad habits as well (such as using Hungarian notation).

IMO, you'd be better off starting with a library such as SFML, which hides all of these nasty platform-specific details behind a more modern object-oriented interface. This allows you to focus on developing good programming habits and learning the basic concepts behind game development and software design, without getting distracted by low-level details. (Also, using the code from the book more or less ties you to Windows, whereas using a cross-platform API would leave open the possibility of porting your code to other OSs, such as OS X and Linux.)

Again, this is all IMHO.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this