Quellcode durchsuchen

Getting rid of TimerData class

legacy
Guillaume Bittoun Sam Hocevar <sam@hocevar.net> vor 8 Jahren
Ursprung
Commit
28031dac1e
1 geänderte Dateien mit 12 neuen und 30 gelöschten Zeilen
  1. +12
    -30
      src/lol/sys/timer.h

+ 12
- 30
src/lol/sys/timer.h Datei anzeigen

@@ -25,15 +25,9 @@ namespace lol
* Timer implementation class
*/

class TimerData
class Timer
{
friend class Timer;

private:
TimerData()
{
(void)GetSeconds(true);
}

float GetSeconds(bool reset)
{
@@ -47,55 +41,43 @@ private:
return std::chrono::duration_cast<std::chrono::duration<float>>(tp - tp0).count();
}

static void WaitSeconds(float seconds)
{
if (seconds > 0.0f)
std::this_thread::sleep_for(std::chrono::duration<float>(seconds));
}

std::chrono::steady_clock::time_point m_tp;
};

class Timer
{
public:
Timer()
: data(new TimerData())
: m_tp()
{
(void)GetSeconds(true);
}

~Timer()
{
delete data;
}

void Reset()
{
(void)data->GetSeconds(true);
(void)GetSeconds(true);
}

float Get()
{
return data->GetSeconds(true);
return GetSeconds(true);
}

float Poll()
{
return data->GetSeconds(false);
return GetSeconds(false);
}

void Wait(float seconds)
{
float secs_elapsed = data->GetSeconds(false);
data->WaitSeconds(seconds - secs_elapsed);
if (seconds > 0.0f)
{
float secs_elapsed = GetSeconds(false);
std::this_thread::sleep_for(std::chrono::duration<float>(seconds - secs_elapsed));
}
}

private:
TimerData *data;

/* Copying timers is forbidden for now. */
Timer(Timer const &t);
Timer operator =(Timer const &t);
std::chrono::steady_clock::time_point m_tp;
};

} /* namespace lol */


Laden…
Abbrechen
Speichern