Sign in to follow this  
Shadowwoelf

Vector not updating

Recommended Posts

I cannot seem to figure out why my vector would not update correctly. I have a Basegamestate class which menu state and world state get derived from. Menustate works correctly and should have given control to worldstate but it simply creates worldstate but does not render it. Heres my main loop
	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()->run(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
			{
				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
				}
			}
		}
	}


Heres my gamestate.h file
class MENU_STATE: public baseGameState{
private:											//All of our variables that the update function and render need
	GLfloat	roll;									// Rolling Texture
	int selector, max_selector,selected;
	GLubyte Ycolor,fadeoutcolor;
	GLfloat yOffset;
	bool	Boolarrow[4];							//0=up
													//1=down
													//2=left
													//3=right
	DWORD TimeP[4];									//0=up
													//1=down
													//2=left
													//3=right
	Texture texture[2];												// Storage For 2 Textures ( NEW )
	bool colordown;
	std::vector<baseGameState*> States;
	bool fadeout,fadeoutdone;
protected:
	int render();
	int update();
public:
	MENU_STATE::MENU_STATE();
	int run(std::vector<baseGameState*> &StatesRef){
		States=StatesRef;
		update();
		render();
		return 0;
		};
	int resize();
};


This is where when the user presses enter it should push back the new world state and the main loop should run it from there.
			if (keys[VK_RETURN])									// Is F1 Being Pressed?
				{
				switch(selector){
					case 0:{States.push_back(new WORLD_STATE);
						break;}
					case 1:{
						break;}
					case 2:{
						break;}
					case 3:{
						break;}
					case 4:{ done=true;
						break;}
					}

So am I simply creating the new world_state in the menu state and when its finished creating it gets deleted? Edit: I think thats the problem. I am creating a new world state in menu state but never in the main loop so how do I fix it?

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