the-cold-dark / genesis

The Cold server - This implements a dynamic, object-oriented language on top of an object database, well suited for virtual environments and online servers (like games).
29 stars 7 forks source link

Add milliseconds (or lower) to time() function #7

Open tscheer86 opened 4 years ago

tscheer86 commented 4 years ago

Unable to use time() to monitor less than seconds.

waywardmonkeys commented 3 years ago

It isn't optimal really, but there is mtime() that returns microseconds ... so the code that uses that tends to look like [time(), mtime()].

Is that sufficient?

saulren commented 3 years ago

I believe he was asking due to an anti spam measure I implemented into the $player parser. Currently it limits inputs to 1/second and with this function I should be able to divide that time. Thanks for the reply!

waywardmonkeys commented 1 year ago

17 may be a useful first step to doing this.

lisdude commented 1 year ago

In MOO we've settled on separating this into an ftime() function that handily returns a float like 1668748884.14323. In that spirit, I added the method $time.ftime() with the code:

return tofloat(time() + "." + mtime());

Seems to work. It's also a nice option for not messing with the driver.

For fun, though, I also ported the ftime builtin function that I wrote for ToastStunt. It provides the same time + mtime combination, but it also includes an argument to return monotonic time. The gist of which (ho ho) can be found here if interested: https://gist.github.com/lisdude/b8f7d6ee3fc48788ba83e6b1691d7566