GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/game.h Lines: 0 7 0.0 %
Date: 2021-03-17 Branches: 0 0 0.0 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2004-2009  The Mana World Development Team
4
 *  Copyright (C) 2009-2010  The Mana Developers
5
 *  Copyright (C) 2011-2019  The ManaPlus Developers
6
 *  Copyright (C) 2019-2021  Andrei Karas
7
 *
8
 *  This file is part of The ManaPlus Client.
9
 *
10
 *  This program is free software; you can redistribute it and/or modify
11
 *  it under the terms of the GNU General Public License as published by
12
 *  the Free Software Foundation; either version 2 of the License, or
13
 *  any later version.
14
 *
15
 *  This program is distributed in the hope that it will be useful,
16
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 *  GNU General Public License for more details.
19
 *
20
 *  You should have received a copy of the GNU General Public License
21
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
22
 */
23
24
#ifndef GAME_H
25
#define GAME_H
26
27
#include "enums/input/inputaction.h"
28
29
#include <string>
30
31
#include "localconsts.h"
32
33
PRAGMA48(GCC diagnostic push)
34
PRAGMA48(GCC diagnostic ignored "-Wshadow")
35
#include <SDL_events.h>
36
PRAGMA48(GCC diagnostic pop)
37
38
static const int MAX_LASTKEYS = 10;
39
40
extern volatile time_t cur_time;
41
42
class Map;
43
44
struct LastKey final
45
{
46
    A_DELETE_COPY(LastKey)
47
48
    LastKey() :
49
        time(0),
50
        key(InputAction::NO_VALUE),
51
        cnt(0)
52
    { }
53
54
    time_t time;
55
    InputActionT key;
56
    int cnt;
57
};
58
59
/**
60
 * The main class responsible for running the game. The game starts after you
61
 * have selected your character.
62
 */
63
class Game final
64
{
65
    public:
66
        /**
67
         * Constructs the game, creating all the managers, handlers, engines
68
         * and GUI windows that make up the game.
69
         */
70
        Game();
71
72
        A_DELETE_COPY(Game)
73
74
        /**
75
         * Destructor, cleans up the game.
76
         */
77
        ~Game();
78
79
        /**
80
         * Provides access to the game instance.
81
         */
82
        static Game *instance() A_WARN_UNUSED
83
        { return mInstance; }
84
85
        constexpr2 static void clearInstance() noexcept2
86
        { mInstance = nullptr; }
87
88
        /**
89
         * This method takes the game a small step further. It is called 100
90
         * times per second.
91
         */
92
        void logic();
93
94
        void slowLogic();
95
96
        void handleInput();
97
98
        void handleMove();
99
100
        void changeMap(const std::string &mapName);
101
102
        void updateFrameRate(int fpsLimit);
103
104
        /**
105
         * Returns the currently active map.
106
         */
107
        Map *getCurrentMap() const noexcept2 A_WARN_UNUSED
108
        { return mCurrentMap; }
109
110
        const std::string &getCurrentMapName() const noexcept2 A_WARN_UNUSED
111
        { return mMapName; }
112
113
        void setValidSpeed();
114
115
        void adjustPerfomance();
116
117
        void resetAdjustLevel();
118
119
        void setAdjustLevel(const int n)
120
        { mAdjustLevel = n; }
121
122
        static void videoResized(const int width, const int height);
123
124
        bool getValidSpeed() const noexcept2 A_WARN_UNUSED
125
        { return mValidSpeed; }
126
127
        static void moveInDirection(const unsigned char direction);
128
129
        static bool createScreenshot(const std::string &prefix);
130
131
        static void addWatermark();
132
133
        static bool saveScreenshot(SDL_Surface *const screenshot,
134
                                   const std::string &prefix);
135
136
        void updateHistory(const SDL_Event &event);
137
138
        void checkKeys();
139
140
    private:
141
        void clearKeysArray();
142
143
        Map *mCurrentMap;
144
        std::string mMapName;
145
        bool mValidSpeed;
146
        LastKey mLastKeys[MAX_LASTKEYS];
147
        time_t mNextAdjustTime;
148
        int mAdjustLevel;
149
        bool mAdjustPerfomance;
150
        int mLowerCounter;
151
        int mPing;
152
        time_t mTime;
153
        time_t mTime2;
154
155
        static Game *mInstance;
156
};
157
158
extern bool mStatsReUpdated;
159
160
#endif  // GAME_H