1 //
2 //  SuperTuxKart - a fun racing game with go-kart
3 //  Copyright (C) 2006-2019 SuperTuxKart-Team
4 //
5 //  This program is free software; you can redistribute it and/or
6 //  modify it under the terms of the GNU General Public License
7 //  as published by the Free Software Foundation; either version 3
8 //  of the License, or (at your option) any later version.
9 //
10 //  This program is distributed in the hope that it will be useful,
11 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
12 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 //  GNU General Public License for more details.
14 //
15 //  You should have received a copy of the GNU General Public License
16 //  along with this program; if not, write to the Free Software
17 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18 
19 #ifndef HEADER_STORY_MODE_TIMER_HPP
20 #define HEADER_STORY_MODE_TIMER_HPP
21 
22 #include "utils/types.hpp"
23 #include <iomanip>
24 
25 class StoryModeTimer
26 {
27 private:
28     bool m_valid_speedrun_started, m_valid_speedrun_ended;
29     bool m_story_mode_started, m_story_mode_ended;
30     bool m_speedrun_pause_active, m_story_mode_pause_active;
31     bool m_loading_pause;
32     bool m_player_tested;
33     bool m_player_can_speedrun;
34 
35     //This stores the number of milliseconds to display with the counter
36     int m_speedrun_milliseconds;
37     int m_story_mode_milliseconds;
38 
39     int m_stored_speedrun_milliseconds;
40     int m_stored_story_mode_milliseconds;
41 
42     uint64_t m_speedrun_start;
43     uint64_t m_speedrun_end;
44     uint64_t m_speedrun_pause_start;
45 
46     uint64_t m_story_mode_start;
47     uint64_t m_story_mode_end;
48     uint64_t m_story_mode_pause_start;
49 
50     uint64_t m_speedrun_total_pause_time;
51     uint64_t m_story_mode_total_pause_time;
52 
53     void testPlayerRun();
54 
55     void pauseSpeedrunTimer();
56     void pauseStoryModeTimer();
57     void unpauseSpeedrunTimer();
58     void unpauseStoryModeTimer();
59     void updateSpeedrunTimer();
60     void updateStoryModeTimer();
61 public:
62 
63     StoryModeTimer();
64 
65     // ------------------------------------------------------------------------
66     /** Speedrun timer functions. */
67     void startTimer();
68     void stopTimer();
69     void pauseTimer(bool loading);
70     void unpauseTimer(bool loading);
71     void updateTimer();
72     void reset();
73 
74     void playerHasChanged();
75     std::string getTimerString();
playerLoaded() const76     bool playerLoaded() const { return m_player_tested; }
isStoryModePaused() const77     bool isStoryModePaused() const { return m_story_mode_pause_active; }
playerCanRun() const78     bool playerCanRun() const { return m_player_can_speedrun; }
isSpeedrunning() const79     bool isSpeedrunning() const { return m_valid_speedrun_started; }
speedrunIsFinished() const80     bool speedrunIsFinished() const { return m_valid_speedrun_ended; }
getStoryModeTime() const81     int getStoryModeTime() const { return m_story_mode_milliseconds; }
getSpeedrunTime() const82     int getSpeedrunTime() const { return m_speedrun_milliseconds; }
83 };   // StoryModeTimer
84 
85 extern StoryModeTimer* story_mode_timer;
86 
87 #endif
88 
89 /* EOF */
90