game pause - ho should be done?

Started by
23 comments, last by SeraphLance 9 years, 9 months ago

Are you serious? I thought this was a friendly forum.

There are certain people who often come across as abusing the forums.
If you see just this topic and my reply, you may think I am being a bit harsh, but it actually stems from something of a history in which fir posts questions of variable merit but almost always follows with, “Yes I asked this question but I don’t like your answer.” He gets a good answer on the first reply but 3 pages later, with many people backing the first answer he got, he keeps the discussion alive beyond its grave constantly insisting what basically boils down to, “Yes, that’s the answer, but that’s not the answer I want to see.”

So it’s not just me randomly being an ass. There is a precedence with this particular person.
I tend to avoid fir topics for a reason, so you can be sure there is a reason I replied in the first place, but as you can see I do have little patience for people who appear to be literally abusing the forums, and I am not the only one who believes so. His reputation is as it is for a reason.


L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

Advertisement

well, sometimes i would like to debate things not just got first answer ' - like there in those drawlina arg name topic - some people seem do not understand this. as to this topic in general i can do this pause by exposing this RunFrameButtNotAdvance and partialy switching off the input - switching this 'input path' presents to me a bit obscure (as i was used to mix draw advance and input quite together) but it was worth mentioning

pausing is interesting as it is quite separate whole game state not just 1 line of code

The reason I replied is because I struggled with over-engineering pause mechanics when I was a kid (in my first attempt I kept track of actual time and paused time and the current game time was total time - paused time), and regardless of how I feel about your topics my devotion towards helping others not struggle with the problems I had in my youth virtually forced my hand here.

I am trying to save you from the headaches I had years ago, not engage in a discussion/debate over something I’ve established to be correct enough that I would recommend it to you in the first place.

In this case, you are very clearly over-engineering pause mechanics, and not only that but your proposed idea indicates that you have flawed approaches to other problems in general game mechanics.

I am going to answer 1 more time, very slowly and very clearly.



Every frame of the game you calculate how much time has passed and then add that amount to your “game time”.
By keeping track of the current game time and the last frame’s game time you can derive a delta. The time since the last update.

Fine.
When you want to pause, all you do is update the game time by 0 microseconds/milliseconds/seconds/whatever. 0 is 0, no matter the unit.
By definition you have created a delta time of 0.

UpdateBy( DELTA ) {
    LastTime = CurTime;
    CurTime += DELTA; // If DELTA is 0, CurTime does not change.
}

LastTime = 3987687, CurTime = 3987687, Delta = (CurTime - LastTime = 0).

This works in every case because:

  • If my position is directly derived from the current time, the current time is no longer changing and so neither is my position (I am “paused”).
  • If my position is cumulative (adds change over time each frame), the delta is 0, so anything I add over time is just 0 while paused.

So:

pausing is interesting as it is quite separate whole game state not just 1 line of code

No, it literally is 1 line of code. You either advance the timer or you don’t, and it’s a single if() to implement this. You will need another line for the closing } on that statement, but that’s not a line of “code”.


It’s 1 thing to not know what pausing is, but it is another thing to “know what it is not”.
When you assume it is not just 1 line of code it means you have an idea as to what it should be. Since you seem to have an idea about it, but in fact it actually is literally 1 line of code, it indicates you have a much larger problem somewhere else within your overall approach to game development—1 line of code should work perfectly but because of your approach it won’t.


It is really this simple:

  • All game objects move based on the time since the last update (velocity * time).
  • All game objects are updated within the scene manager. The scene manager receives a value indicating the time since the last update (by how much each object should update).
  • All objects update by the given time. If that time is 0, then all motion those objects have is cancelled out and all objects stop moving.

The delta time you pass to the scene manager is just derived from the timer’s current time and its last time, and it is literally 1 line of code to add a check within the timer to not update when paused, which creates implicitly a 0 delta, which causes all objects to freeze.

The reason I replied is to make sure this is clear. No one needs to endure what I did in my youth by over-engineering pauses.

If you have a specific question about this, ask it. This is not a debate.

L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

To be fair, pausing can often be a totally separate game state. Yes, you could just stop the timer, but pause menus are usually more sophsticated than that. You might want to show a menu. You might want to change the background color to grayscale, apply a radial blur, and then show the word "pause" on the screen. I'd argue that it's worthwhile to create a state for something like that.

Obviously you still want to not advance the timer, so as a barebones answer this is still correct.

This is why I said in my first post that you maintain 2 timers.
The second one is for visual effects.

But if you pause Conker’s Bad Fur Day yes you see some nice visuals.
That is basically a state on top of the gameplay state (if you implement states as a stack).
You have many options in regards to what you display during pausing, states or no states, but the mechanic for pausing along with a rendering timer are unchanged.


L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

That is really a great answer on pause mechanics.

I got a +0 points popup for my post above, so I am assuming that the system here didn't catch the case where you positives and negatives add up to zero on a post.

I am sorry for lashing out on you L Spiro. To be fair, I guess it is equally frustrating to be on both ends: one end answering a lot of 'simple' questions about one topic, but it is equally frustrating to struggle with a topic you want to learn more about too. I guess we are different in where our 'bottle necks' in learning are. 20 years ago, it was me struggling understanding pointers in Turbo Pascal. Today, fir was struggling with pause functionality here, and actually, L. Spiro's answer taught me a bit too. It is a clever way to pause rather than skipping parts of your code or having different states in a state machine.

Everybody starts from the beginning.


To be fair, I guess it is equally frustrating to be on both ends: one end answering a lot of 'simple' questions about one topic, but it is equally frustrating to struggle with a topic you want to learn more about too.

Actually, if you look through fir's posting history, you'll see people are frustrated with him not because he asks a lot of questions (which is an ok thing to do), but because of the way he treats the people who answer his questions. He's very lucky he gets any responses at all these days as he doesn't really deserve any.

Answering is free.. I do not force anyone to answer - this is big forum and if even 20 people would not want to answer some other my find to talk..

So feel free to not answer, if you dont like my questions or statements (or mistypes, im doin to much of it but i had some problem with that even in my native language and here in english it is 3 times worse) feel free to ignore me at all than i can talk with some rest who not shares this view

ps. dont exaggerate the value of some answers, im not a 100% newbie, im about moderately experienced, (about 6 hard years of hard c coding in my back) and sometimes i find a situation when some forum user gives me an answers worse than my knowledge - when im searching for some more advanced talk (then im a bit bored or angry - but what should i do in such case? answer that ;\


ps. dont exaggerate the value of some answers, im not a 100% newbie, im about moderately experienced, (about 6 hard years of hard c coding in my back) and sometimes i find a situation when some forum user gives me an answers worse than my knowledge - when im searching for some more advanced talk (then im a bit bored or angry - but what should i do in such case? answer that ;\

You should take it as the constructive feedback to your question that it is, and thank the person for at least answering - thats what you should do. Seriously, there is just so much wrong with that whole statement of yours. If you think you have more knowledge than 99% of the forum users, why are you even asking? To get different opinions I quess, but if you reject most of them because you think the user knows much less than you and the answer is crap, than you clearly do not care about seeing different points of views. It appears to me you just want to hear answers that exactly match with whatever you yourself have in mind.

See, there is nothing wrong with disagreeing with an answer you have been given - I also used to discuss on some of the topics I asked with the repliers, but try to at least pretend to value that people took time to answer you, and don't act all like "I know better than you, so p*ss off". Also, I can quarantee you that if you really have to ask a question about "how to implement game-pause" and can't figure it out yourself that almost every answer you get is going to be better that what you might think is.

PS: Not trying to be offensive, apologies if it sounded that way.

@Topic: It might also be worth mentioning that depending on the type of game, there is not only rendering that can run while paused. Tower-defense games e.g. sometimes allow you to pause the action, but still keep placing towers, upgrading, etc... In RTS, you can sometimes still move the camera, select units, give commands... this also is true for other kinds of games like the Kotor-Series, where you can give commands to your characters while everything else freezes in a pause mode. So depending the type of your game, you might want to be able to selectively pause/unpause parts of it.

Also:

1) how it should behave for the player ? should game be paused automatic on alt+tab or maybe even on mouse going out of window and automaticaly restarted again on second alt_tab ? or are there some reasons to leave it unpaused in

such cases?

This IMHO has nothing to do with pausing per se, in that case you could probably just stop the game-loop:


	void BaseEngine::GameLoop(void)
	{
		while(!m_bQuit)
		{
			MessageLoop();
			if(!m_bMessage)
			{    
				const double dt = m_tGameLoopTimer.Duration();
				m_tGameLoopTimer.Reset();

				if(GetForegroundWindow() == m_pWindow->GethWnd()) // windows-function to get the current active window, don't progress in case thats not this apps window handle.
				{
					if(!m_bQuit)
						Render();

					Update(dt);

					m_pRenderer->Finish();
				}
			}
		}
	}

Reasons to leave it run in the background? Everything multiplayer-related comes to mind, from MMORPG to RTS.

Reasons to leave it run in the background? Everything multiplayer-related comes to mind, from MMORPG to RTS.

i rarely see the pause maybe this is becouse im playing heavy

games and when I alt + tam them i dont even se what this games

do - are they pausing or not? can i assume they pausing? ;/ this alt_tabbing is always some probloem usually it works ok - but not so rare cases it crashes the game (even if this is AAA title) and if not crashes it can take a bit slow

what is the reason of this? windows swpaping mechanizm (this is probably activated on alt_tab?

This topic is closed to new replies.

Advertisement