It is currently Thu Aug 22, 2019 4:31 pm



Reply to topic  [ 5 posts ] 
 Sampling Rate 
Author Message
Petrif-Eyed
User avatar

Joined: Sat Sep 17, 2011 9:23 pm
Posts: 2220
Location: Menlo Park, CA
Reply with quote
One thing that I recently noticed is that the sampling/update frequency in FreePIE is much higher than GlovePIE. This is great for things like head-tracker emulation but has some unintended consequences elsewhere. In particular with mouse emulation the GlovePIE command

mouse.DirectInputX += 5;

and the FreePIE command

mouse.DeltaX = 5;

act very differently. The FreePIE mouse will "fly" across the screen super fast. Even setting DeltaX = 1 (the lowest value) moves the mouse so quickly that it is sometimes difficult to aim it and stop precisely on screen elements like title-bars and menu items.

I am not even sure if the frequency is capped. If not, then the same script on one machine may act differently on a slower machine. We should consider picking a default frequency (60Hz ?), allowing a configurable polling frequency, and enforcing that frequency so that scripts will act the same from machine to machine.


Mon Aug 27, 2012 8:40 am
Profile
Petrif-Eyed
User avatar

Joined: Sat Sep 17, 2011 9:23 pm
Posts: 2220
Location: Menlo Park, CA
Reply with quote
Other possibilities in regards to mouse emulation:

- It might be useful to accept and process fractional values for mouse.DeltaX, so that at high sampling frequencies you can easily generate slow mouse movements.

- It might be useful to provide frequency normalized functions. For example, "mouse.XPixPerSec = 50" would set a fixed motion rate regardless of the sampling frequency. Also "mouse.XInchPerSec = 1" would set a fixed motion rate for all frequencies and for all monitor resolutions.

Maybe there is a more elegant way to accomplish this using the filters() library? Like "mouse.DeltaX = filters:InchesPerSec(1)" or something like that?


Mon Aug 27, 2012 9:21 am
Profile
Petrif-Eyed

Joined: Mon Jun 22, 2009 8:36 am
Posts: 2160
Location: Stockholm, Sweden
Reply with quote
Hmm pretty complex, right now the lua worker sleeps one ms per iteration to avoid starving a CPU core. That's means around about 16ms which means a freq of 1000/16. To get a stable and reliable frequency we would need to utilize the real time clock and that introduces a lot of complexity also could create problems if the game running In foreground uses it.


I will think some on this topic :)

_________________
FreePIE
My blog


Mon Aug 27, 2012 9:30 am
Profile
Petrif-Eyed
User avatar

Joined: Sat Sep 17, 2011 9:23 pm
Posts: 2220
Location: Menlo Park, CA
Reply with quote
Not sure about the C# syntax but I do things like this in C to maintain a processing frequency.

Code:
#include <time.h>

void main() {

   long FREQUENCY = 30;
   
   while (true) {
      clock_t start = clock();   // returns milliseconds
           
      // Do some processing

      long processing_time = (long)(clock() - start);
      long delay = (1000 / FREQUENCY) - processing_time;    // precision can be improved with sub-millisecond timers
      Sleep(delay);
   }
}




** The algorithm can be improved since it doesn't take into account inaccuracies in the Sleep() call and inconsistencies in thread scheduling.


Mon Aug 27, 2012 9:54 am
Profile
Petrif-Eyed

Joined: Mon Jun 22, 2009 8:36 am
Posts: 2160
Location: Stockholm, Sweden
Reply with quote
Problem with sleeping a thread is that its not accurate enough, it will sleep a minimum of ~16ms, but how long it will sleep is not guaranteed. When the time has elapsed it will be put in the OS ready queue and idle their until its turn to be resumed. Its not language specific but OS specific.

but maybe its good enough, could have it as an option under settings

edit: Lol didnt see your comment under the code example, you state the very exact thing :D

edit2: Btw, using the Update event on the Plugin will enforce the same update frequence on the emulation as on the input. I use this with Freetrack > Mouse and it works very well

_________________
FreePIE
My blog


Tue Aug 28, 2012 1:02 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 5 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group
Designed by STSoftware.