ManaPlus
game.h
Go to the documentation of this file.
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-2018 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 
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 {
46 
47  LastKey() :
48  time(0),
49  key(InputAction::NO_VALUE),
50  cnt(0)
51  { }
52 
53  time_t time;
55  int cnt;
56 };
57 
62 class Game final
63 {
64  public:
69  Game();
70 
72 
73 
76  ~Game();
77 
82  { return mInstance; }
83 
85  { mInstance = nullptr; }
86 
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 
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 
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 
143  std::string mMapName;
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
#define A_DELETE_COPY(func)
Definition: localconsts.h:52
bool mAdjustPerfomance
Definition: game.h:148
void checkKeys()
Definition: game.cpp:1240
void updateFrameRate(int fpsLimit)
Definition: game.cpp:1025
static bool createScreenshot(const std::string &prefix)
Definition: game.cpp:528
bool getValidSpeed() const
Definition: game.h:123
static Game * mInstance
Definition: game.h:154
void setValidSpeed()
Definition: game.cpp:1264
time_t time
Definition: game.h:53
const std::string & getCurrentMapName() const
Definition: game.h:109
#define constexpr2
Definition: localconsts.h:48
void handleInput()
Definition: game.cpp:1053
#define A_WARN_UNUSED
Definition: localconsts.h:172
#define final
Definition: localconsts.h:45
time_t mTime2
Definition: game.h:152
int mLowerCounter
Definition: game.h:149
static void addWatermark()
Definition: game.cpp:513
bool screenshot(InputEvent &event)
Definition: actions.cpp:50
bool mValidSpeed
Definition: game.h:144
Map * getCurrentMap() const
Definition: game.h:106
void slowLogic()
Definition: game.cpp:672
time_t mNextAdjustTime
Definition: game.h:146
void logic()
Definition: game.cpp:656
~Game()
Definition: game.cpp:474
static void clearInstance()
Definition: game.h:84
void changeMap(const std::string &mapName)
Definition: game.cpp:1086
static void videoResized(const int width, const int height)
Definition: game.cpp:1280
static bool saveScreenshot(SDL_Surface *const screenshot, const std::string &prefix)
Definition: game.cpp:556
Definition: game.h:62
void handleMove()
Definition: game.cpp:913
int mAdjustLevel
Definition: game.h:147
std::string mMapName
Definition: game.h:143
InputAction ::T InputActionT
Definition: inputaction.h:714
void updateHistory(const SDL_Event &event)
Definition: game.cpp:1183
Game()
Definition: game.cpp:398
#define PRAGMA48(str)
Definition: localconsts.h:214
static const int MAX_LASTKEYS
Definition: game.h:37
Definition: map.h:68
Definition: game.h:43
volatile time_t cur_time
Definition: timer.cpp:57
void adjustPerfomance()
Definition: game.cpp:775
void setAdjustLevel(const int n)
Definition: game.h:118
Map * mCurrentMap
Definition: game.h:142
time_t mTime
Definition: game.h:151
static Game * instance()
Definition: game.h:81
int mPing
Definition: game.h:150
LastKey mLastKeys[MAX_LASTKEYS]
Definition: game.h:145
static void moveInDirection(const unsigned char direction)
Definition: game.cpp:998
bool mStatsReUpdated
Definition: game.cpp:156
void clearKeysArray()
Definition: game.cpp:1270
#define noexcept2
Definition: localconsts.h:49
void resetAdjustLevel()
Definition: game.cpp:882
int cnt
Definition: game.h:55
InputActionT key
Definition: game.h:54