How can I get the Frames per second, "FPS", of the game with Gdnative C++?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By ariel

get the label text to be the FPS with GDnative or C++ “frames per secons”
I see that you cannot do OS.get_frames_per_second () when you are using C ++ with Gdnative.
Lastly, how can I concatenate the text with the result of the OS.get_frames_per_second () in Gdnative using C ++

void InstanciarCubos::_process(const double p_delta) 
{
    // Godot::print( String::num_real( p_delta ) );
    // measure average frames per second
    ContadorText->set_text( "FPS" + OS.get_frames_per_second() ); // <--no work!
}

I work this way, although it converts from "real_t" to "double"

String::num_real( Engine::get_singleton()->get_frames_per_second() )

Godot::print( String::num_real( Engine::get_singleton()->get_frames_per_second() ) );

Thanks for the Engine tip Engine::get_singleton()->get_frames_per_second(), I didn’t even imagine it.
I leave the complete code where I do the casting in the Node of type Label.

void InstanciarCubos::_process(const double p_delta) 
{
    if(FpsText == nullptr) return;
    FpsText->set_text("FPS= " + String::num_real( Engine::get_singleton()->get_frames_per_second() ) );
    Godot::print( String::num_real( Engine::get_singleton()->get_frames_per_second() ) );
}

ariel | 2021-08-26 22:03

For the record, this question was cross-posted on the Godot forums: https://godotforums.org/discussion/27279/how-can-i-get-the-frames-per-second-fps-of-the-game-with-gdnative-c

Calinou | 2021-08-27 20:04

:bust_in_silhouette: Reply From: sash-rc
float fps = Engine::get_singleton()->get_frames_per_second(); // Now it's not in OS anymore
label->set_text( String("FPS:  {0}").format( Array::make(fps) ) );
// or
label->set_text( "FPS: " + String::num(fps) );

I work this way, although it converts from "real_t" to "double"

String::num_real( Engine::get_singleton()->get_frames_per_second() )

Console message from godot …

Godot::print( String::num_real( Engine::get_singleton()->get_frames_per_second() ) );

Thanks for the Engine tip Engine::get_singleton()->get_frames_per_second(), I didn’t even imagine it.
I leave the complete code where I do the casting in the Node of type Label.

void InstanciarCubos::_process(const double p_delta) 
{
    if(FpsText == nullptr) return;
    FpsText->set_text("FPS= " + String::num_real( Engine::get_singleton()->get_frames_per_second() ) );
    Godot::print( String::num_real( Engine::get_singleton()->get_frames_per_second() ) );
}

ariel | 2021-08-26 22:01