Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualwarnexus

Posted 10 February 2013 - 04:29 PM

 

..snip...

what do you mean by input logic? on a side note, isn't a game loop consider to be an infinite loop if runs constantly to do handling tasks like drawing objects and testing collisions?
looking at you main game loop, you make absolutly zero calls to the function keyPress, or any indication that your call a function which query's input to potentially call the keyPress function.

so what does that mean? it means that in your initializing code, java spawned another thread that catch's input, and call's the keyPress function when you've done some type of input.

so, basically, you have 2 threads going:

thread 1: drawing/updating objects.
thread 2: getting input.

so, when you set the isRunning flag to false to pause, this is what your threads look like:

thread 1: finished(since you broke out of the loop, it completed the run() function, and the thread finished running since it reached the bottom of execution of run, and then reached the end of main).
thread 2: still looking for input.

so, when you go to unpause, this is what happens:

thread 1: still finished
thread 2: is now in a loop, doing what thread 1 used to do.

their are two problems with this.

first of all, you no longer get input.

second, openGL is built to receive commands from a single thread, and only one thread, this is the default thread that main is executed in. because it is now submitting commands from thread 2, the commands are essentially invalidated, and don't do anything. this is why once you unpause the game, you have to force it to close, the game is still technically updating, it just can't draw anything, because openGL refuses all commands from the second thread.
you also can't break out of it because you no longer can receive inputs, since you've stalled the input managed since you never go back to it.

hope this helps you understand what's going on better=-).

Now that I have a clear head, I understand it and got it to work. Thanks! Lesson learned: Never code with a tired mind.


#2warnexus

Posted 10 February 2013 - 03:38 PM


..snip...

what do you mean by input logic? on a side note, isn't a game loop consider to be an infinite loop if runs constantly to do handling tasks like drawing objects and testing collisions?
looking at you main game loop, you make absolutly zero calls to the function keyPress, or any indication that your call a function which query's input to potentially call the keyPress function.

so what does that mean? it means that in your initializing code, java spawned another thread that catch's input, and call's the keyPress function when you've done some type of input.

so, basically, you have 2 threads going:

thread 1: drawing/updating objects.
thread 2: getting input.

so, when you set the isRunning flag to false to pause, this is what your threads look like:

thread 1: finished(since you broke out of the loop, it completed the run() function, and the thread finished running since it reached the bottom of execution of run, and then reached the end of main).
thread 2: still looking for input.

so, when you go to unpause, this is what happens:

thread 1: still finished
thread 2: is now in a loop, doing what thread 1 used to do.

their are two problems with this.

first of all, you no longer get input.

second, openGL is built to receive commands from a single thread, and only one thread, this is the default thread that main is executed in. because it is now submitting commands from thread 2, the commands are essentially invalidated, and don't do anything. this is why once you unpause the game, you have to force it to close, the game is still technically updating, it just can't draw anything, because openGL refuses all commands from the second thread.
you also can't break out of it because you no longer can receive inputs, since you've stalled the input managed since you never go back to it.

hope this helps you understand what's going on better=-).
Now that I have a clear head, I understand it now. Thanks!

#1warnexus

Posted 10 February 2013 - 03:38 PM

 

..snip...

what do you mean by input logic? on a side note, isn't a game loop consider to be an infinite loop if runs constantly to do handling tasks like drawing objects and testing collisions?

looking at you main game loop, you make absolutly zero calls to the function keyPress, or any indication that your call a function which query's input to potentially call the keyPress function.

 

so what does that mean? it means that in your initializing code, java spawned another thread that catch's input, and call's the keyPress function when you've done some type of input.

 

so, basically, you have 2 threads going:

 

thread 1: drawing/updating objects.

thread 2: getting input.

 

so, when you set the isRunning flag to false to pause, this is what your threads look like:

 

thread 1: finished(since you broke out of the loop, it completed the run() function, and the thread finished running since it reached the bottom of execution of run, and then reached the end of main).

thread 2: still looking for input.

 

so, when you go to unpause, this is what happens:

 

thread 1: still finished

thread 2: is now in a loop, doing what thread 1 used to do.

 

their are two problems with this.

 

first of all, you no longer get input.

 

second, openGL is built to receive commands from a single thread, and only one thread, this is the default thread that main is executed in. because it is now submitting commands from thread 2, the commands are essentially invalidated, and don't do anything.  this is why once you unpause the game, you have to force it to close, the game is still technically updating, it just can't draw anything, because openGL refuses all commands from the second thread.

you also can't break out of it because you no longer can receive inputs, since you've stalled the input managed since you never go back to it.

 

hope this helps you understand what's going on better=-).

Now that I have a clear head, I understand it now. Thanks!


PARTNERS