Alright... so I found numerous examples on the proper way to suspend and pause threads but none really relate to my problem.
I have a thread which runs in the background of my game which does all the simulation of moving players, calculating spaces and ect... I have a pause button for the user if they need to take a break, but I can't find a way to pause the thread nicely without bugs.
run() {
while(true)
{
function1();
function2();
function3();
function4();
function5();
}
}
To try and pause the thread I inserted a while loop which polls a bit whether to continue or not inbetween each function. This doesn't really work good because 1) I have a lot of functions (more than listed in this example) 2) It doesn't work well with thread.sleep(x)'s.
Lots of people suggest having it poll at the end of the run method before it loops back up, but that doesn't make sense since I need it to freeze on the stop as quickly as possible.
Thanks for taking the time to read this.