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