Game Engine(design)

Started by
0 comments, last by ToohrVyk 15 years, 6 months ago
I am wondering about where to go with the engine. So far I have designed it like this

std::vector<baseGameState*> States;
States.push_back(new MENU_STATE);
DWORD StartTime = timeGetTime();
DWORD LastTime = StartTime;
while(done!=true)												// Loop That Runs While done=FALSE
	{
		if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))				// Is There A Message Waiting?
		{
			if (msg.message==WM_QUIT)							// Have We Received A Quit Message?
			{
				done=true;										// If So done=TRUE
			}
			else												// If Not, Deal With Window Messages
			{
				TranslateMessage(&msg);							// Translate The Message
				DispatchMessage(&msg);							// Dispatch The Message
			}
		}
		else													// If There Are No Messages
		{
		if(resize==true){
				States.back()->resize();
				resize=false;
			}
			ElapsedTime = timeGetTime()- LastTime;
			if(ElapsedTime < DesiredFrameLength)
			{
				Sleep(DesiredFrameLength - ElapsedTime);
				ElapsedTime = DesiredFrameLength;
			}
			LastTime = timeGetTime();

			// Draw The Scene.  Watch For ESC Key And Quit Messages From DrawGLScene()
			if ((active && States.back()->update(States)) || keys[VK_ESCAPE])	// Active?  Was There A Quit Received?			
			{
				done=true;										// ESC or DrawGLScene Signalled A Quit
			}
			else												// Not Time To Quit, Update Screen
			{
			States.back()->render();
				SwapBuffers(hDC);								// Swap Buffers (Double Buffering)
			}


			if (keys[VK_F1])									// Is F1 Being Pressed?
			{
				keys[VK_F1]=FALSE;								// If So Make Key FALSE
				KillGLWindow();									// Kill Our Current Window
				fullscreen=!fullscreen;							// Toggle Fullscreen / Windowed Mode
				// Recreate Our OpenGL Window
				if (!CreateGLWindow("NeHe & Evan 'terminate' Pipho's TGA Loading Tutorial",640,480,16,fullscreen))
				{
					return 0;									// Quit If Window Was Not Created
				}
			}
		}
	}

So if I want to switch to another state I would push it on top of the vector and then let it run. But then it occurred to me about global variables. Things like characters stats and world time etc. things that wouldn't be in one individual state. So then I began to think about an Engine class. This is my pseudo code attempt at what I think it should do

public:
vector  states=new state;
vector Hero;
int worldTime;
run(){
States.back()->update(this);

States.back()->render();
}

I think that this is a constant which means you can't change anything in the class that your referencing to(But I may be wrong) so I have no idea on how to pass the engine itself to the states. So should I continue and try to make this work or is there a better way?
Advertisement
An engine is functionality which is commonly found in games, grouped together for simpler reuse. Different engines tend to choose different functionality sets. So, before you can write an engine, you need to decide what functionality that engine will provide. Once this functionality is chosen, you will need to decide how the engine user will invoke that functionality from his or her code. And when all of that is done, you can start writing the engine code.

So, what functionality do you intend to put in your engine? Write a complete and detailed list. Then, how will the user invoke that functionality? Write a code sample for every piece. If you still have any doubts about the implementation once you've done that, come back here and show us the list and sample code, and we'll provide suggestions.

Until then, we don't know what you want your engine to do.

This topic is closed to new replies.

Advertisement