Switch from Float to Integer Time Values
- Use fast data types where possible so the compiler can optimize for speed based on platform
- for example, 128 bits might be fastest on ARM
- good future-proofing
- Refactor GetTimeSinceStart() to be a bit faster
- multiplication is much faster than division
- Implement a RageTimer method to get the seconds value as a plain int, for the places which cast the seconds value to an int
- Changing from GetTimeSinceStartFast() to GetTimeSinceStart() where accuracy is important
- Changing from GetTimeSinceStart() to GetUsecsSinceStart() for timestamp diffs
- Adjust RageThreads to accomodate an unsigned timestamp value
- a constant for the maximum value of `uint_fast64_t` replaces `-1` to accommodate the change from signed to unsigned for the `locked_at` variable
- i have separate constants for `std::numeric_limits<std::uint_fast64_t>::max()` and `static_cast<std::uint_fast64_t>(-1)`, so the reader understands -1 represents an error code, though they evaluate to the same value, so i could remove one of the two
- Add two methods to calculate the MMSSMsMs / MMSSMsMsMs time value from usecs directly instead of inferring it from a seconds value, in RageUtil
- Use a similar counter/modulo based method for WheelNotifyIcon, similar to what i did for text_glow in NoteField in 2eeee03
- Make `g_iStartTime` static const for safety
Rename two timer functions:
GetUsecsSinceStart -> GetTimeSinceStartMicroseconds
GetMicrosecondsSinceStart -> GetSystemTimeAsMicroseconds
Remove std prefix from uint_fast64_t
This commit is contained in:
+9
-9
@@ -48,9 +48,9 @@ static Preference<float> g_iDefaultRecordLength( "DefaultRecordLength", 4 );
|
||||
static Preference<bool> g_bEditorShowBGChangesPlay( "EditorShowBGChangesPlay", true );
|
||||
|
||||
/** @brief How long must the button be held to generate a hold in record mode? */
|
||||
const float record_hold_default= 0.3f;
|
||||
float record_hold_seconds = record_hold_default;
|
||||
const float time_between_autosave= 300.0f; // 5 minutes. -Kyz
|
||||
constexpr uint_fast64_t record_hold_default = 300000; // 0.3 seconds in microseconds
|
||||
uint_fast64_t record_hold_seconds = record_hold_default;
|
||||
constexpr uint_fast64_t time_between_autosave = 300000000; // 300 seconds in microseconds
|
||||
|
||||
#define PLAYER_X (SCREEN_CENTER_X)
|
||||
#define PLAYER_Y (SCREEN_CENTER_Y)
|
||||
@@ -1666,8 +1666,8 @@ void ScreenEdit::Update( float fDeltaTime )
|
||||
|
||||
if(m_EditState == STATE_EDITING)
|
||||
{
|
||||
if(IsDirty() && m_next_autosave_time > -1.0f &&
|
||||
RageTimer::GetTimeSinceStartFast() > m_next_autosave_time)
|
||||
if(IsDirty() && m_next_autosave_time > -1000000 &&
|
||||
RageTimer::GetTimeSinceStartMicroseconds() > m_next_autosave_time)
|
||||
{
|
||||
PerformSave(true);
|
||||
}
|
||||
@@ -4362,7 +4362,7 @@ void ScreenEdit::HandleScreenMessage( const ScreenMessage SM )
|
||||
else if( SM == SM_AutoSaveSuccessful )
|
||||
{
|
||||
LOG->Trace("AutoSave successful.");
|
||||
m_next_autosave_time= RageTimer::GetTimeSinceStartFast() + time_between_autosave;
|
||||
m_next_autosave_time= RageTimer::GetTimeSinceStartMicroseconds() + time_between_autosave;
|
||||
SCREENMAN->SystemMessage(AUTOSAVE_SUCCESSFUL);
|
||||
}
|
||||
else if( SM == SM_SaveFailed ) // save failed; stay in the editor
|
||||
@@ -4438,19 +4438,19 @@ void ScreenEdit::SetDirty(bool dirty)
|
||||
if(EDIT_MODE.GetValue() != EditMode_Full)
|
||||
{
|
||||
m_dirty= false;
|
||||
m_next_autosave_time= -1.0f;
|
||||
m_next_autosave_time= -1000000;
|
||||
return;
|
||||
}
|
||||
if(dirty)
|
||||
{
|
||||
if(!m_dirty)
|
||||
{
|
||||
m_next_autosave_time= RageTimer::GetTimeSinceStartFast() + time_between_autosave;
|
||||
m_next_autosave_time= RageTimer::GetTimeSinceStartMicroseconds() + time_between_autosave;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_next_autosave_time= -1.0f;
|
||||
m_next_autosave_time= -1000000;
|
||||
}
|
||||
m_dirty= dirty;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user