Files
o3de/Code/Legacy/CryCommon/Timer.h
T
Esteban Papp 9f0bbf3b74 SPEC-7531 Change Code/CryEngine to Code/Legacy (#1634)
* git mv Code\CryEngine Code\Legacy
* redirecting CMakeLists.txt
* fixing uic warning
* Some more CryEngine mentions
* validation scripts

Signed-off-by: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com>
2021-06-29 13:51:24 -07:00

38 lines
808 B
C

/*
* Copyright (c) Contributors to the Open 3D Engine Project
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
#pragma once
#ifndef CRYINCLUDE_CRYCOMMON_TIMER_H
#define CRYINCLUDE_CRYCOMMON_TIMER_H
struct Timer
{
Timer()
: endTime(-1.0f)
{
}
void Reset(float duration, float variation = 0.0f)
{
endTime = gEnv->pSystem->GetITimer()->GetFrameStartTime() + CTimeValue(duration) + CTimeValue(cry_random(0.0f, variation));
}
bool Elapsed() const
{
return endTime >= 0.0f && gEnv->pSystem->GetITimer()->GetFrameStartTime() >= endTime;
}
float GetSecondsLeft() const
{
return (endTime - gEnv->pSystem->GetITimer()->GetFrameStartTime()).GetSeconds();
}
CTimeValue endTime;
};
#endif // CRYINCLUDE_CRYCOMMON_TIMER_H