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?