vendredi 9 août 2019

Limit frame rate in hooked function

Im having problems understanding why my code is not limiting the frames to the time i put in if i set it to 10.0 it limits it to 100fps I was expecting it to be limited to 10fps.

HRESULT __stdcall Hook::BeginScene(LPDIRECT3DDEVICE9 pDevice)
{
    a = std::chrono::system_clock::now();
    std::chrono::duration<double, std::milli> work_time = a - b;

    if (work_time.count() < 10.0)
    {
        std::chrono::duration<double, std::milli> delta_ms(10.0 - work_time.count());
        auto delta_ms_duration = std::chrono::duration_cast<std::chrono::milliseconds>(delta_ms);
        std::this_thread::sleep_for(delta_ms_duration);
    }

    b = std::chrono::system_clock::now();
    std::chrono::duration<double, std::milli> sleep_time = b - a;

Aucun commentaire:

Enregistrer un commentaire