Giter VIP home page Giter VIP logo

Comments (8)

AndersMalmgren avatar AndersMalmgren commented on June 8, 2024

The default rate is 64hz not including the overhead of the script it self. And you must take into account hat windows is not a real time system.

Timing in FreePIE is not easy, we cant just let the script have all CPU time it can get because then we will throttle that Core and you will run into performance problem. So we have a pattern for timing the script cycle. Default we use the system clock which is at 64hz. You can override this using system.setThreadTiming and system.threadExecutionInterval

We have some different strategies for timing, if you know C# you can check them out here

https://github.com/AndersMalmgren/FreePIE/tree/master/FreePIE.Core/ScriptEngine/ThreadTiming

If you want the most accurate one (If we ignore that Windows is not a real time system and that FreePIE is managed code) you should use TimingTypes.ThreadYieldMicroSeconds. It will however eat more resources than for example TimingTypes.HighresSystemTimer

from freepie.

AndersMalmgren avatar AndersMalmgren commented on June 8, 2024

Also,

    diagnostics.watch(prevTime)
    diagnostics.watch(now)
    diagnostics.watch(fps)

will real time update UI, this will impact performance (While UI is in focus)

from freepie.

SystemParadox avatar SystemParadox commented on June 8, 2024

Thanks that's helpful, looks like some of the other timing strategies should solve the problem.

I still don't understand why the timing changes though, even with the default timing strategy. How does it end up at 1000Hz?!

from freepie.

SystemParadox avatar SystemParadox commented on June 8, 2024

From what I can work out:

  • SystemTimer sleeps for ThreadExecutionInterval milliseconds, without regard for how long the script took
  • ThreadYield repeatedly yields in a spin loop until enough time has passed (I think it takes account of script time but not entirely sure)
  • ThreadYieldMicroSeconds same as above
  • HighresSystemTimer (BeginPeriodSystemTimerStrategy) - I don't understand what this is doing

Is there not just a simple timer that calls Thread.Sleep for the right amount of time, taking into account how much time the script took?

Also, the default ThreadExecutionInterval is 1, which would mean a default rate of 1000Hz. Where does the 64Hz come from? My suspicion at the moment is that this is not really defined properly, and is instead just rate limited by the thread scheduler or something.

from freepie.

AndersMalmgren avatar AndersMalmgren commented on June 8, 2024

None of the strategies take into account the time taken for the script sadly. Shouldn't be a problem in normal cases though since the overhead in the script should be minimal. The system clock runs at 64hz, so you can't sleep shorter than 16ms (1000/64). Really strange that you get 1000hz, do you have another program that changes the speed of the system clock? That's how the Highres strategy work, it changes the system clock from 64hz to 1000hz

from freepie.

AndersMalmgren avatar AndersMalmgren commented on June 8, 2024

Sorry, the yield strategies do take into account the time of the script :)

from freepie.

SystemParadox avatar SystemParadox commented on June 8, 2024

Ok. May I suggest that the default threadExecutionInterval be set to 16 then? That would avoid the confusing behaviour in the case that the clock rate isn't 64Hz for some reason! :)

from freepie.

AndersMalmgren avatar AndersMalmgren commented on June 8, 2024

Could have side effects on systems that override default clock speeds.
edit: Basicly Thread.Sleep(1) means that you sleep as short time as the OS lets you.

from freepie.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.