Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set limit framerate #107

Closed
e1e5en-gd opened this issue Oct 30, 2020 · 3 comments
Closed

Set limit framerate #107

e1e5en-gd opened this issue Oct 30, 2020 · 3 comments

Comments

@e1e5en-gd
Copy link
Contributor

e1e5en-gd commented Oct 30, 2020

I would like to be able to change the number of frames per second, because for web applications and for smartphones 60 frames is a lot (Vsync- 60 or no limit, it is known).
I studied the source code of the Armory engine and its abstraction levels (Armory, Iron, Kha) and came to the following conclusions:

  1. there is currently no way to change the number of frames via Armoryand Iron;
  2. there are also no settings via Kha:
  • the render function that is registered to execute as kha.System.notifyOnFrames() and will run with a limit of 60. Because it depends on the call event on the chosen platform;
  • adds the update function to the Scheduler and you can specify the frequency of more execution. You can specify a value of 30 and it turns out that the scene is render 2 times, and updated 1 time. Because neither are executed in parallel.
    To specify this setting, either in the Display class (it is located in ArmorySDK\Kha\Backends\[target_name]\kha), you need to specify a value for the platform in the get_frequency() function. Or, in the Time class of the Iron engine (ArmorySDK\iron\Sources\iron\system) in the init() function, specify the frequency value instead of what is there.

Can make changes to Iron:
To make the render function run with the same frequency as update, you can register an “empty function” in kha.System.notifyOnFrames() (only to store the value from the frames[0] array passed in the framebuffer field). And execute the real function in update. In this case, the empty function will still be executed 60 times, but the “workers” will only be 30.
And for the “correct” display of the FPS value in the DebugConsole and in the Get FPS node, it is necessary to correct that the time during the calculation was used from Scheduler, and not the real one (which will produce 60 FPS).
I haven’t been able to find any other way to limit the frames per second other than upgrading the Iron. In this case, you can display settings in the nodes or the Blender interface. But this is a limitation at the level of one of the abstraction layers. And make it optional, if the user left the FPS limit at 60, then everything will work according to the current algorithm.

The developers Kha are in no hurry to introduce such a possibility (judging by the topics on the forum (http://forum.kode.tech/topic/329/building-a-desktop-app-render-on-demand) and the request in git (Kode/Kha#320)).

I wrote the results of my searches here (https://forums.armory3d.org/t/set-limit-framerate-ln-for-get-fps/4286/8).

What do you think about this? Is there any other way to solve this problem?

@luboslenco
Copy link
Member

Sorry but it would be the best to implement this feature in Kha, especially since Robert is in favor of it at Kode/Kha#320. He might not get into implementing it yet but it usually also means he would accept the pull request. Kha already has a way to set frequency via https://github.com/Kode/Kha/blob/master/Sources/kha/FramebufferOptions.hx#L5, so I guess it is 'only' missing the implementation in the html5 backend.

@e1e5en-gd
Copy link
Contributor Author

e1e5en-gd commented Oct 30, 2020

  1. FramebufferOptions - I can't figure out how to get the current instance in the code to set its settings. If you tell me, I will be very grateful.
    I ask through the Starter class from Armory, but it does not work.
    And in the Kha\Backends folders I did not find that the frequency value was used.

  2. And can make it possible to set the frequency for the update function when added to the Scheduler? Iron already does this.

    kha.Scheduler.addTimeTask(update, 0, iron.system.Time.delta);

    frequency = kha.Display.primary != null ? kha.Display.primary.frequency : 60;

    The logic of working with Kha will not change here, but only the setting.

@moisesjpelaez
Copy link

moisesjpelaez commented Jul 1, 2024

I'm not a software developer but I think if the end user wants to actually make a game this user shouldn't be modifying lower level libraries like Kha and the engine should adapt to what Kha currently offers. I think this issue should be reopened and I propose to set the fps cap should be set on here:
image

While I'll be investigating and giving it a try on my own I'll appreciate if someone can point me out which source files I can read to speed up and see what I can do.

Edit: sorry, I realized I'm in the Iron repo, opened an issue in the Armory repo here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants