What happens when computer can't execute a program in time it has to do it

0

Consider a tick-based game, where computer needs to execute 100 operations every tick. What happens if computer can execute only 50 operations during single tick?

cdks

Posted 2014-01-03T19:49:27.573

Reputation: 13

1

see: http://gamedev.stackexchange.com/questions/56956/how-to-make-a-game-tick-method or search there for 'tick'

– horatio – 2014-01-03T19:56:34.543

A point for confusion is that you aren't defining "tick". A tick, as pointed in the previous link, can either be dynamic or fixed. Hence, if you said that ticks are fixed by operations, and that the computer was able to process 50 operations per second, each tick would be 2 seconds long.

– Doktoro Reichard – 2014-01-03T21:20:14.333

Answers

1

That depends on how the computer is done. Back then videogames ran as fast as the processor did. That's the same videogame designed for a computer getting played in a twice as fast computer would run twice as fast. So to avoid this problem, computers had the "Turbo" button, which limited the speed of the CPU so the game would be playable (imagine playing tetris at 500x the speed).

You can see what I mean in action here, where the guy plays with this gameboy's clock.

Nowadays a decent videogame will check what time it is and adjust the location of the moving cars by looking at the time. So if we're at some certain tick and on the next tick 2 seconds have elapsed... well; based on the speed of the car we can calculate where it should be now.

In first scenario, game runs slower. In the second scenario, game runs as fast but choppier.

Now, if your question really is "I'm not throttling the game speed nor lowering the framerate nor doing anything to avoid the sitiation in which the CPU can't finish all the taks. When time's up, tick is over and start all over. What's going to happen?"

Well, if the game loop is something like:

  1. Take controller input.
  2. Calculate moving object locations
  3. Calculate collisions
  4. Draw scenario and most characters
  5. Calculate damages
  6. Draw player model
  7. Draw player clothing.

and the CPU only made it to point 6.5 then you'd end up with a naked legless character, but the game could play the same (or crash).

If the CPU made it just past 4, then the car that is running you over won't kill you and just phase through you.

Of course this depends on game implementation and I'm being overly imaginative.

brunch875

Posted 2014-01-03T19:49:27.573

Reputation: 373

Actually, I think you've got this backwards. Your answer is great for when the computer is too fast. The OP is asking what happens when the computer is too slow. – a CVn – 2014-01-03T20:07:50.653

If it goes twice as fast on a 2xCPU, it goes twice as slow in a 0.5xCPU – brunch875 – 2014-01-03T20:09:26.433

What makes me not understand is: when one tick elapses and computer executes only 1/2 operations it can't execute the remaining operations in next tick (and create lag) because in next tick there are another operations waiting to be executed. This means in every tick, there are created more and more operations waiting for execution and this cant stop. Lag cant solve it. – cdks – 2014-01-03T20:36:37.793

There can't be any operations left undone between ticks. Either you slow down the game so the CPU can make it, cut the amount of operations, or use a lower framerate (the operations between frames are just as many but there are less frames to make in a given time) – brunch875 – 2014-01-03T20:45:23.797

@cdks I added some information of what I believe might be your question – brunch875 – 2014-01-03T21:05:57.860

0

Consider a tick-based game, where computer needs to execute 100 operations every tick. What happens if computer can execute only 50 operations during single tick?

Depends on what happens when the tick expires and what the operations are.

If your game is in something like Visual Basic, where a timer event fires off operations, and your operations is a procedure that runs the game, then the timer, at the end of the "tick", is going to fire off the procedure again.

Unless you've made provisions otherwise, the existing running procedure is going to keep going. There will be "overlap." If your code is not "reentrant" - i.e. static variables are used throughout the procedure, unexpected changes in variables will result in both the first running and second running procedure. This will cause the procedure to misbehave.

If the language or framework you are using terminates the first running procedure before starting another when that "tick" or timer event comes around, obviously whatever was supposed to be done in that tick won't be completed. If some variables towards the end of the tick were meant to be updated that the next tick depends on, the procedure won't work as expected.

On an old computer or game system, the "tick" was typically an IRQ or NMI generated when the video chip got to a certain line in rendering video. Good games, if they are "overloaded" and can't complete their work in a tick or "frame" in this case, would remember that fact, probably by using a flag that is checked at the start of each frame, and continue the work, introducing slowdown but not failing. When the work is completed, the flag is cleared. This would have to be checked at the start of each "tick."

LawrenceC

Posted 2014-01-03T19:49:27.573

Reputation: 63 487