I have to say, that would be good idea.
This isnt simple solution, but basically you could use what i use to halt the program a bit from running too fast. For thing is, when you make a game, and you make the movement based upon how much time have passed, it can happen with faster machines, that since smallest time measurement in hollywood is 1 MicroSecond, it might take less than half of that to make the cycle, and in that case it rounds it down to 0, which means that nothing moves anywhere as everytime cycle keeps going, it keeps multiplying the movement by 0 (which is the recorded time that have passed).
Hence what i roughly do is (I dont remember exact commands right now):
Code: Select all
continue = 0
repeat
timepassed = gettimepassed()
if timepassed > 1 then continue = 1
until continue=1
This could be used differently as well, you could check that if certain amount of time have not passed yet, then it would jump to function idlefunctions()
this idlefunctions, would consist of a list of subfunctions which are to be executed one at a time until time have been reached.
in practice it would be about like this:
Code: Select all
p_idlefunctions()
function1()
gettimepassed()
checkifthereisstilltime()
if timeleft < 50 then break
function2()
ettimepassed()
checkifthereisstilltime()
if timeleft < 50 then break
This alone isnt very good yet, since then it would keep checking the first functions all the time, and maybe never get to run the last, hence you would need either to use multiple if else statments perhaps, or some sort of list solution, where list contains all your functions.
I am not sure how this actually works, but in theory:
Code: Select all
idlefunctions_table = {function1(), function(2), function3()}
p_idlefunctions()
repeat
idlefunctions_table[ nextfunction ]
nextfunction = nextfunction + 1
if nextfunction > amount of functions in list then nextfunction=1
if timeleft < 1 break
forever
endfunction
This would work about the way that nextfunction would keep track of which function to execute next on idle time. For example, if you have 5 functions, and you are able to execute 3 of them, then next time you come to this idlefunction place, it would execute function number 4.
This way everytime you would have idle time, it would use that time to execute idlefunctions in order without skipping them or repeating the same all the time.
However, I am not sure how does that using function on a list actually work. I know list can contain functions, but how do you use functions inside a list, that i have never tried.