[Home] [Downloads] [Search] [Help/forum]

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Suggestions
. . -> [Subject]  Timer resolution in milliseconds
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Timer resolution in milliseconds

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by Kahenraz   (42 posts)  [Biography] bio
Date Wed 05 Oct 2016 10:36 PM (UTC)
Message
It would be nice to be able to create timers with resolution in the milliseconds. This would be useful for one-off timers to go off in the future rather than perform a busy loop in Lua which locks up the client.
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Thu 06 Oct 2016 04:29 AM (UTC)
Message
The underlying messages from the operating system don't have that granularity. This isn't a real-time game client.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Kahenraz   (42 posts)  [Biography] bio
Date Reply #2 on Thu 06 Oct 2016 05:56 AM (UTC)
Message
What are you using to create a timer? Win32 SetTimer() has millisecond granularity.
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #3 on Thu 06 Oct 2016 06:23 AM (UTC)
Message
Yes, I use SetTimer.

https://github.com/nickgammon/mushclient/blob/master/mainfrm.cpp#L394

But here's the thing ... there is a difference between precision and accuracy. You can specify millisecond precision. But accuracy?

See: WM_TIMER message

When the timer expires you get a WM_TIMER message. From that page:

Quote:

The WM_TIMER message is a low-priority message. The GetMessage and PeekMessage functions post this message only when no other higher-priority messages are in the thread's message queue.


So, you can put in a request that you get a message after 10 milliseconds. But if the Windows message queue is full of incoming data from the MUD, you might wait 10 seconds!

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Kahenraz   (42 posts)  [Biography] bio
Date Reply #4 on Thu 06 Oct 2016 06:37 AM (UTC)

Amended on Thu 06 Oct 2016 06:38 AM (UTC) by Kahenraz

Message
There's no guarantee that any timer will fire at the expected time. But there is a big difference between 500ms and 1s which shouldn't be an issue.

Timers aren't great for my use case in general but it's the closest thing available to a scheduler and would still be better than halting the client on a busy wait. Providing perceived accuracy in the milliseconds would go a long way.
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #5 on Thu 06 Oct 2016 08:34 AM (UTC)
Message
The timer already has a resolution of 0.1 seconds. That is 100 ms.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


2,775 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]