![]() Prototype.i timeout_callback( *this.TIMEOUT ) User_variable.i a custom user variable, could be a pointer or anything at all, it's accessed through the instance ptr sent to the callback. *callback.i user callback pointer, we can't cast it as a timeout_callback prototype here for obvious reasons. New_time.i the new, current time in milliseconds ![]() Update_rate.i holds the update speed in times per second On timeout_update() the second parameter defines this behavior.ĭelay.i based on how many updates a second are required, this holds the delay value in ms.Ĭurrent.i the current timeout value in ms, this is the "counter" and uses the "delay" to increment. You can actually select whether the library should perform an actual sleep / delay operation to save cycles ( for example in cases where you have a waiting loop it’s ideal to sleep for a given period of time instead of wasting those cycles ) or you can have it compare old vs new time instead of performing a real delay. I even use it to send notices to every client on the server before the server actually shuts down! (game server) One of the many uses I have for this library includes waiting for a server to respond, sending timed events to clients, etc. Simple use case: Define.TIMEOUT *timeout = timeout_create( 1000 * 5, 100 ) 5 seconds maximum timeout, 100 updates a second. Of course both the callback and the user variables are optional, but they’re a handy feature. The “update_rate” sets how many updates there will be within 0 and the “maximum” in this case 1000), if we were to use 10 updates then we would experience the callback to be called every 100ms. The “maximum” is in milliseconds and corresponds to the timeout period, for example 1000 would be 1 second timeout. The library is very simple to use, you must define a maximum timeout period and an update rate when you create an instance of TIMEOUT. This simple “timeout” library allows you to easily perform timed operations in your games and applications. Thanks to the callbacks you can also perform arbitrary functions within each update cycle.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |