Jump to content

How to: Pause "Game"


MasteR
 Share

Recommended Posts

Now, what is the right way to pause a 3d application, this could be pausing an RTS or RPG or even pausing the application whilst the in game menu is opened.

 

What is the logic behind achieving pause and resume functionality?

AMD Athlon 64 X2 Dual Core 6000+ (3.0 GHz)

4 GB DDR2 RAM

2 x NVIDIA GeForce 9500 GT 512 MB (SLI 1.0 GB)

Windows XP Pro

Link to comment
Share on other sites

PauseApp() and ResumeApp() will pause and resume the application time.

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

PauseApp() and ResumeApp() will pause and resume the application time.

 

int main(int argc, char** argv)
{
Initialize();

// Create a graphics window
Graphics(800,600);

//Load the SDK directory
RegisterAbstractPath("C:\Leadwerks Engine SDK");

// Create a world
if (!CreateWorld())
{
	MessageBoxA(0,"Error","Failed to create world.",0);
	goto exitapp;
}
TBuffer buffer=CreateBuffer(800,600,BUFFER_COLOR0|BUFFER_DEPTH|BUFFER_NORMAL);

// Create a camera
TEntity cam = CreateCamera();
MoveEntity (cam, Vec3(0,0,-5) );

// Create a visual mesh
TEntity mesh = CreateCube();

//Create another mesh to cast a shadow on
TMesh ground=CreateCube();
ScaleMesh(ground,Vec3(10,0.1,10));
PositionEntity(ground,Vec3(0,-2,0));

//Create a spotlight
TLight light=CreateSpotLight();
PositionEntity(light,Vec3(2,2,-2));
RotateEntity(light,Vec3(45,45,0));

// Main program loop
while(!KeyHit(KEY_ESCAPE))
{
	UpdateAppTime();
	PauseApp();

	// Make the visual mesh spin
	TurnEntity (mesh, Vec3(0.0,0.5,0.0));

	// Update timing and physics
	UpdateWorld(AppTime());	

	//Make our render buffer the current buffer
	SetBuffer(buffer);

	//Render the world to the render buffer
	RenderWorld();

	//Make the back buffer the current buffer
	SetBuffer(BackBuffer());

	//Call the RenderLights command, passing our buffer which
	//contains color, depth, and normal data
	RenderLights(buffer);

	//Swap the buffers so we can see what was drawn
	Flip ();
}
exitapp:
Terminate();
return 0;
}

 

This does not pause the application for me. It takes a while to load up and the cube still rotates, slowly, but still rotates.

AMD Athlon 64 X2 Dual Core 6000+ (3.0 GHz)

4 GB DDR2 RAM

2 x NVIDIA GeForce 9500 GT 512 MB (SLI 1.0 GB)

Windows XP Pro

Link to comment
Share on other sites

I'm just shooting in the dark here but first, I am not sure that PauseApp will also stop objects from loading, and second, I think you need to call PauseApp only once. I think it only pauses updating, but most certainly not the entire code execution.

 

Cheers!

Link to comment
Share on other sites

I'm just shooting in the dark here but first, I am not sure that PauseApp will also stop objects from loading, and second, I think you need to call PauseApp only once. I think it only pauses updating, but most certainly not the entire code execution.

 

Cheers!

 

Now we're getting somewhere,

 

Should pause/resume be performed outside the main loop?

the logic of one solution would be to * every in game objects movement, animation, etc by a value and change that value to 0 when you want the game paused, but surly there is a better way.

AMD Athlon 64 X2 Dual Core 6000+ (3.0 GHz)

4 GB DDR2 RAM

2 x NVIDIA GeForce 9500 GT 512 MB (SLI 1.0 GB)

Windows XP Pro

Link to comment
Share on other sites

This does not pause the application for me ..

 

 

well it would not when called there in the main loop, PauseApp() pauses the application time .. then in your code you perform "things" in a loop and then at the start of the loop you update the Apptime! and then pause it again .. call it as a function outside of the main loop .. in Bmax I have used ..

 

Function PauseGame()
PauseApp()
ShowMouse()
SetBlend(BLEND_ALPHA)
DrawText("PAUSED", (GraphicsWidth()/2)-TextWidth("PAUSED")/2, GraphicsHeight()-14)
SetBlend(0)
Flip(0)
WaitKey()
HideMouse()
ResumeApp()	
End Function

 

Simply prints a PAUSED notification ... pauses the app .. waits for a key to be pressed and resumes the app.

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

Why don't you just exit the main loop while pausing by jumping into a second loop?

 

int pause = 1;

// Main program loop
while(!KeyHit(KEY_ESCAPE))
{
	UpdateAppTime();

	// Make the visual mesh spin
	TurnEntity (mesh, Vec3(0.0,0.5,0.0));

	while pause
	{
		// paused, do some stuff here
	}


	// Update timing and physics
	UpdateWorld(AppTime()); 

	//Make our render buffer the current buffer
	SetBuffer(buffer);

	//Render the world to the render buffer
	RenderWorld();

	//Make the back buffer the current buffer
	SetBuffer(BackBuffer());

	//Call the RenderLights command, passing our buffer which
	//contains color, depth, and normal data
	RenderLights(buffer);

	//Swap the buffers so we can see what was drawn
	Flip ();
}


desktop: Quad core Q6600 + 4GB + ATI HD4890 + XP

laptop: Dual core T6400 + 4 GB + NVidia 9600M GT + Vista 32

Link to comment
Share on other sites

well it would not when called there in the main loop, PauseApp() pauses the application time .. then in your code you perform "things" in a loop and then at the start of the loop you update the Apptime! and then pause it again .. call it as a function outside of the main loop .. in Bmax I have used ..

 

Function PauseGame()
PauseApp()
ShowMouse()
SetBlend(BLEND_ALPHA)
DrawText("PAUSED", (GraphicsWidth()/2)-TextWidth("PAUSED")/2, GraphicsHeight()-14)
SetBlend(0)
Flip(0)
WaitKey()
HideMouse()
ResumeApp()	
End Function

 

Simply prints a PAUSED notification ... pauses the app .. waits for a key to be pressed and resumes the app.

 

understood thanks alot, nice and simple

AMD Athlon 64 X2 Dual Core 6000+ (3.0 GHz)

4 GB DDR2 RAM

2 x NVIDIA GeForce 9500 GT 512 MB (SLI 1.0 GB)

Windows XP Pro

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...