Archived

This topic is now archived and is closed to further replies.

My game engine idea

This topic is 5013 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

First of all, I've been trying to think of an easy way to create a game engine, but until now I couldn't figure out how to include the message pump in the class (without using inheritance anyway). I think I've figured it out, and was just wondering if anybody had thought of it or a better way. Its pretty simple, its setup like this:
class DFWindow
{
public:
// code here

void MessagePump(int (*pRender)())
{
	MSG mMsg;
	ZeroMemory(&mMsg, sizeof(MSG));

	while(mMsg.message != WM_QUIT)
	{
		if(PeekMessage(&mMsg, NULL, 0, 0, PM_REMOVE))
		{
			TranslateMessage(&mMsg);
			DispatchMessage(&mMsg);
		}
		else
		{
			if(!(*pRender)())
				PostQuitMessage(WM_QUIT);
		}
	}
}
Then you can call it with any function (as long as its an int and has no arguments of course). Second, how customizable should you make a window/direct3D class. I want to make it somewhat customizable, but I don't want to overdo it. I have had it setup where the class has a variable for everything (ie: for a window i had a class name, caption, icon, small icon, etc). And then in the constructor I set it all (except the char*'s) to a default value and you could customize the window by calling a set function, like this: g_Window.SetTitle("Dragonfire Class"); g_Window.SetCursor(LoadCursor(NULL, IDC_CROSSHAIR)); g_Window.Create(hInstance); But that's a pain in the but (especially for a Direct3D class). Any better ideas? I've also thought of just having a function that you supply a filename and the class would load the info from that file, but then anybody that wanted to use it would have to use that (or I could implement both a single call for files and a call to set the variables by hand). Thanks in advance! /* I use DirectX 8.1 and C++ (Microsoft Visual C++ 6.0 Professional edition) */ [edited by - Programmer16 on March 21, 2004 1:48:57 AM]

Share this post


Link to post
Share on other sites
the way I did it is I do not have the msg pump in the d3d class
I made it in a seperate class for the game
each level can be one of these classes or you could make a base class


class CGame
{

protected:

CDirect3D* m_pDirect3D;

CDirectInput* m_pInput;
CTimer* m_pTimer;
CFont* m_pFont;

CCamera m_Camera;
CFrustum m_Frustum;

bool m_bRunning;

void Render(LPD3DXSPRITE pd3dxSprite);

void Update(float FrameTime);

void Load();
void Unload();

void DrawStats();

float m_TimeTrack;

// Level specific stuff


CAvi m_AviTexture;

CWorld m_TokaWorld;

CTokamakTerrain m_TokaTerrain;

CRigidBox* m_Boxes;
CMesh m_BoxMesh;

CRigidSphere* m_Spheres;
CMesh m_SphereMesh;

public:

int Run(CDirect3D* pDirect3D);

};


Edit: You might want to see WinMain also


int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int)
{

CDirect3D Direct3D;

CGame Scene01;

// Initialize COM

CoInitialize(NULL);

// Initialize Direct3D

Direct3D.Init(800, 600, D3DFMT_X8R8G8B8, FALSE);

// Play Scene 01

Scene01.Run(&Direct3D);

// Shutdown Direct3D

Direct3D.Cleanup();

// Shutdown COM

CoUninitialize();

return 0;
}


[edited by - eFoDay on March 21, 2004 2:54:41 AM]

Share this post


Link to post
Share on other sites
I don''t want to sound offensive, but if the windows message pump is making you think so much, you should sit down and really think about what you should be working on. In your case, programming in a Windows environment should be number one. When you are ready to program the engine, you will have a complete understanding of the OS you are programming for, and your main focus will be on algorithms pertaining to the engine/game.

As for your message pump idea, other than having more than one window per application instance, I really see no serious problem. In my opinion, it should be in the WinMain function just before your engine''s "frame" code. That is simply how Win32 application are "supposed" to be coded (according to MSDN docs).

Intro Engine

Share this post


Link to post
Share on other sites
I haven''t thinking about it at all, but just like all of windows, reprogramming it is just a pain and repetetive. My ability to program in windows isn''t the problem its my ability to organise code so that it is clean and effective is.

And my call to MessagePump(GameLoop); calls my game code because it calls GameLoop(). So in three function calls I have my window setup, my game''s code running, and the window destroying, and without cluttering my WinMain function with all of my windows code.

/*
I use DirectX 8.1 and C++ (Microsoft Visual C++ 6.0 Professional edition)
*/

Share this post


Link to post
Share on other sites
Deebo -- I beg to differ on the importance of knowing your OS. I mean, if you're writing the next (insert multi-million-dollar-sales-per-year title here), then you'll need to know your target platform and OS inside and out, but, let's be realistic -- any project that's starting out with a question in the beginner's forum at gamedev.net will leave its creator plenty of time to learn his OS's before it starts raking in the millions, on the off-chance it rakes in the millions at all.

The most important aspects of game programming -- building, storing and rendering models and levels, collision detection, AI, &c, &c -- are platform-independent, and can be learned without having too strong a base of knowledge about the underlying operating system.

My advice to you, programmer16 -- get the message pump pumping well enough that you can forget about it for now, and start playing around with the more gameish stuff. After you've worked on your engine for a few months, you'll probably have learned so much that you'll want re-do all your original code and redesign things from the ground up anyway, at which point, you'll also probably be able to answer your current questions about where the message pump fits into the overall architecture of the engine.

[edit: my bad, Programmer, we're in the Game Programming forum. What can I say -- it's late, and my own recalcitrant engine and accompanying tools have pummeled my brain to a pulp]

[edited by - CautionMan on March 21, 2004 6:27:11 AM]

Share this post


Link to post
Share on other sites
Had me worried there for a minute, thought maybe I posted in the wrong forum. I try to start over and catch this little snag everytime. I guess I''ll just keep it like this for now. Thanks for the advice.

/*
I use DirectX 8.1 and C++ (Microsoft Visual C++ 6.0 Professional edition)
*/

Share this post


Link to post
Share on other sites
Youre right CautionMan, thats nothing that a beginner must know in order to program simple games because, like I said, main focus should be on algorithms pertaining to the engine/game. But having an understanding about the OS will open doors for better performance in general (resouce management, time slices, threading, etc...) as well as helping you become a better programmer. People planning to take programming, or an engine project, to the next level will most likely have to code tools that will run on that OS, or will change focus to non-graphics related applications.
All in all, understanding the OS isn''t necessary, but taking the time to understand it will not be in vain.

Intro Engine

Share this post


Link to post
Share on other sites