summaryrefslogtreecommitdiffhomepage
path: root/Stars45/Clock.h
blob: 4f51330aea9c0a4546709b48edc853a8671ade90 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*  Starshatter: The Open Source Project
    Copyright (c) 2021-2022, Starshatter: The Open Source Project Contributors
    Copyright (c) 2011-2012, Starshatter OpenSource Distribution Contributors
    Copyright (c) 1997-2006, Destroyer Studios LLC.
*/

#ifndef Clock_h
#define Clock_h

#include <chrono>


class Clock
{
public:
    using inner_clock = std::chrono::high_resolution_clock;
    using elapsed_duration = std::chrono::milliseconds;
    using count_type = elapsed_duration::rep;

    static Clock* GetInstance();
    static bool Init();
    static void Close();

    void Set();
    double Step();
    void ResetGameTime();
    void SkipGameTime(double seconds);

    double Delta() const;
    double GuiDelta() const;
    double Rate() const;
    double TimeCompression() const;
    count_type GameTime() const;
    count_type RealTime() const;

    void SetTimeCompression(double compression);

protected:
    Clock();

    inner_clock::time_point m_point;
    inner_clock::duration m_game_elapsed;
    inner_clock::duration m_real_elapsed;
    double m_compression;
    double m_delta;
    double m_gui_delta;
    double m_rate;

private:
    static Clock* instance;
};


#endif  // Clock_h