SuperStrict Import Datastruct.PriorityQueue Type TVirtualThread field nextExecution:int field functionToCall(data:object) field data:object global prioQueue:TPriorityQueue = TPriorityQueue.Create() global lastCheck:int function create:TVirtualThread(functionToCall(data:object), data:object, timeToWait:int) local result:TVirtualThread = new TVirtualThread result.nextExecution = millisecs() + timeToWait result.functionToCall = functionToCall result.data = data end function function updateExecution() if millisecs() - lastCheck < 1 return local curTime:int = millisecs() local thread:TVirtualThread = TVirtualThread(prioQueue.top()) while thread.nextExecution < curTime thread.functionToCall(thread.data) prioQueue.pop() thread = TVirtualThread(prioQueue.top()) wend end function end type
Datastruct PriorityQueue is a module I wrote myself. It is a high performant priorityqueue implemented with a heap under the hood
The code is not tested but should you give an idea of how to do it.
With Reflection you could even do objects with method calls using invoke.
The only thing you need to do is call TVirtualThread.updateExecution() in your mainloop (using a 1000 hz timer would be kind of worthless I feel)