Rewrite the code to attain O(1) time-complexity by the following simple changette:
while (true) {
if (not Paused) {
tick(); // container for each game-tick's worth of processing
// This includes temperature propogation, liquid flow, any pathfinding requests, checking for miasma production, etc
// Some of these things are O(N), maybe O(NlogN), could be O(N^exponential)!
// The most significant of these is generally what governs the subsequent Order of processing time
}
... // anything user-interactive goes here in its own little handler
// Acts upon any input that entered the buffer in the background whilst servicing the tick() phase
// or before control goes back around the true-loop again...
}
while (true) {
epochSeconds=now();
if (not Paused) {
tick(); // container for each game-tick's worth of processing
}
while (now()-epochSeconds < 315567360) {
... // anything user-interactive goes here
// Otherwise, do nothing. Just ensure a constant duration of sufficient length has elapsed before continuing.
// This makes it virtually guaranteed to be an O(1) algorithm!
}
}
NB.: If I've actually been optimistic with the epochSeconds loop, I'm sure you can double it and cover problematic edge conditions!