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-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 
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 {
47 
48  LastKey() :
49  time(0),
50  key(InputAction::NO_VALUE),
51  cnt(0)
52  { }
53 
54  time_t time;
56  int cnt;
57 };
58 
63 class Game final
64 {
65  public:
70  Game();
71 
73 
74 
77  ~Game();
78 
83  { return mInstance; }
84 
86  { mInstance = nullptr; }
87 
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 
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 
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 
144  std::string mMapName;
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
Definition: game.h:64
Map * mCurrentMap
Definition: game.h:143
int mLowerCounter
Definition: game.h:150
void setAdjustLevel(const int n)
Definition: game.h:119
void updateFrameRate(int fpsLimit)
Definition: game.cpp:1032
LastKey mLastKeys[MAX_LASTKEYS]
Definition: game.h:146
std::string mMapName
Definition: game.h:144
void adjustPerfomance()
Definition: game.cpp:782
void slowLogic()
Definition: game.cpp:679
static void addWatermark()
Definition: game.cpp:520
time_t mNextAdjustTime
Definition: game.h:147
bool mAdjustPerfomance
Definition: game.h:149
void checkKeys()
Definition: game.cpp:1249
int mPing
Definition: game.h:151
Map * getCurrentMap() const
Definition: game.h:107
bool getValidSpeed() const
Definition: game.h:124
bool mValidSpeed
Definition: game.h:145
static Game * instance()
Definition: game.h:82
void handleMove()
Definition: game.cpp:920
static bool saveScreenshot(SDL_Surface *const screenshot, const std::string &prefix)
Definition: game.cpp:563
void handleInput()
Definition: game.cpp:1060
time_t mTime2
Definition: game.h:153
int mAdjustLevel
Definition: game.h:148
static Game * mInstance
Definition: game.h:155
void resetAdjustLevel()
Definition: game.cpp:889
void updateHistory(const SDL_Event &event)
Definition: game.cpp:1192
static void moveInDirection(const unsigned char direction)
Definition: game.cpp:1005
Game()
Definition: game.cpp:405
void clearKeysArray()
Definition: game.cpp:1279
static bool createScreenshot(const std::string &prefix)
Definition: game.cpp:535
static void clearInstance()
Definition: game.h:85
void changeMap(const std::string &mapName)
Definition: game.cpp:1093
~Game()
Definition: game.cpp:481
static void videoResized(const int width, const int height)
Definition: game.cpp:1289
void logic()
Definition: game.cpp:663
const std::string & getCurrentMapName() const
Definition: game.h:110
time_t mTime
Definition: game.h:152
void setValidSpeed()
Definition: game.cpp:1273
Definition: map.h:75
static const int MAX_LASTKEYS
Definition: game.h:38
bool mStatsReUpdated
Definition: game.cpp:161
volatile time_t cur_time
Definition: timer.cpp:58
InputAction ::T InputActionT
Definition: inputaction.h:717
#define constexpr2
Definition: localconsts.h:49
#define A_WARN_UNUSED
Definition: localconsts.h:161
#define noexcept2
Definition: localconsts.h:50
#define final
Definition: localconsts.h:46
#define PRAGMA48(str)
Definition: localconsts.h:199
#define A_DELETE_COPY(func)
Definition: localconsts.h:53
bool screenshot(InputEvent &event)
Definition: actions.cpp:51
Definition: game.h:45
InputActionT key
Definition: game.h:55
int cnt
Definition: game.h:56
time_t time
Definition: game.h:54