ManaPlus
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes
Game Class Reference

#include <game.h>

Public Member Functions

 Game ()
 
 ~Game ()
 
void logic ()
 
void slowLogic ()
 
void handleInput ()
 
void handleMove ()
 
void changeMap (const std::string &mapName)
 
void updateFrameRate (int fpsLimit)
 
MapgetCurrentMap () const
 
const std::string & getCurrentMapName () const
 
void setValidSpeed ()
 
void adjustPerfomance ()
 
void resetAdjustLevel ()
 
void setAdjustLevel (const int n)
 
bool getValidSpeed () const
 
void updateHistory (const SDL_Event &event)
 
void checkKeys ()
 

Static Public Member Functions

static Gameinstance ()
 
static void clearInstance ()
 
static void videoResized (const int width, const int height)
 
static void moveInDirection (const unsigned char direction)
 
static bool createScreenshot (const std::string &prefix)
 
static void addWatermark ()
 
static bool saveScreenshot (SDL_Surface *const screenshot, const std::string &prefix)
 

Private Member Functions

void clearKeysArray ()
 

Private Attributes

MapmCurrentMap
 
std::string mMapName
 
bool mValidSpeed
 
LastKey mLastKeys [MAX_LASTKEYS]
 
time_t mNextAdjustTime
 
int mAdjustLevel
 
bool mAdjustPerfomance
 
int mLowerCounter
 
int mPing
 
time_t mTime
 
time_t mTime2
 

Static Private Attributes

static GamemInstance = 0
 

Detailed Description

The main class responsible for running the game. The game starts after you have selected your character.

Definition at line 62 of file game.h.

Constructor & Destructor Documentation

◆ Game()

Game::Game ( )

Constructs the game, creating all the managers, handlers, engines and GUI windows that make up the game.

Definition at line 398 of file game.cpp.

References actorManager, BasicContainer2::add(), chatWindow, PlayerInfo::clear(), clearKeysArray(), config, createGuiWindows(), Settings::disableLoggingInGame, emptyBeingSlot, gameHandler, Configuration::getBoolValue(), GuildManager::getEnableGuildBot(), Graphics::getOpenGL(), Gui::getTop(), gui, guildManager, Configuration::incValue(), initEngines(), MapReader::loadEmptyAtlas(), localPlayer, Logger::log(), logger, mailWindow, mainGraphics, Graphics::mHeight, mInstance, Graphics::mWidth, Net::GameHandler::ping(), MailWindow::postConnection(), ChatWindow::postConnection(), RENDER_SOFTWARE, GuildManager::requestGuildInfo(), Widget::requestMoveToBottom(), AnimatedSprite::setEnableCache(), CompoundSprite::setEnableDelay(), SetupWindow::setInGame(), TouchManager::setInGame(), ActorManager::setPlayer(), Widget::setSize(), settings, setupWindow, tick_time, top, touchManager, viewport, windowContainer, and windowMenu.

398  :
399  mCurrentMap(nullptr),
400  mMapName(""),
401  mValidSpeed(true),
403  mAdjustLevel(0),
404  mAdjustPerfomance(config.getBoolValue("adjustPerfomance")),
405  mLowerCounter(0),
406  mPing(0),
407  mTime(cur_time + 1),
408  mTime2(cur_time + 10)
409 {
410  touchManager.setInGame(true);
411 
412 // assert(!mInstance);
413  if (mInstance != nullptr)
414  logger->log("error: double game creation");
415  mInstance = this;
416 
417  config.incValue("gamecount");
418 
419  disconnectedDialog = nullptr;
420 
421  // Create the viewport
422  viewport = new Viewport;
425 
427 
428  BasicContainer2 *const top = static_cast<BasicContainer2*>(gui->getTop());
429  if (top != nullptr)
430  top->add(viewport);
432 
435  config.getBoolValue("enableDelayedAnimations"));
436 
438  config.getBoolValue("enableCompoundSpriteDelay"));
439 
441  windowMenu = new WindowMenu(nullptr);
442 
443  if (windowContainer != nullptr)
445 
446 #ifdef USE_OPENGL
448 #endif // USE_OPENGL
449 
450  initEngines();
451 
454 
455  // Initialize beings
456  if (actorManager != nullptr)
458 
460 
461  if (setupWindow != nullptr)
462  setupWindow->setInGame(true);
463  clearKeysArray();
464 
465 #ifdef TMWA_SUPPORT
466  if (guildManager != nullptr && GuildManager::getEnableGuildBot())
468 #endif // TMWA_SUPPORT
469 
471  "disableLoggingInGame");
472 }
void setSize(const int width, const int height)
Definition: widget.cpp:366
ChatWindow * chatWindow
Definition: chatwindow.cpp:88
bool mAdjustPerfomance
Definition: game.h:148
volatile int tick_time
Definition: timer.cpp:52
Gui * gui
Definition: gui.cpp:110
static Game * mInstance
Definition: game.h:154
WindowContainer * windowContainer
int mWidth
Definition: graphics.h:483
void setPlayer(LocalPlayer *const player)
void postConnection()
Configuration config
void postConnection()
Definition: mailwindow.cpp:340
void clear()
Definition: playerinfo.cpp:449
time_t mTime2
Definition: game.h:152
int mLowerCounter
Definition: game.h:149
bool mValidSpeed
Definition: game.h:144
const Image *restrict const top
WindowMenu * windowMenu
Definition: windowmenu.cpp:47
BeingSlot * emptyBeingSlot
Definition: beingslot.cpp:25
static void setEnableDelay(bool b)
Logger * logger
Definition: logger.cpp:95
time_t mNextAdjustTime
Definition: game.h:146
Settings settings
Definition: settings.cpp:31
bool getBoolValue(const std::string &key) const
void setInGame(const bool inGame)
int mAdjustLevel
Definition: game.h:147
void requestGuildInfo()
LocalPlayer * localPlayer
GuildManager * guildManager
virtual void add(Widget *const widget)
static bool getEnableGuildBot()
Definition: guildmanager.h:55
std::string mMapName
Definition: game.h:143
RenderType getOpenGL() const
Definition: graphics.h:307
Graphics * mainGraphics
Definition: graphics.cpp:108
int mHeight
Definition: graphics.h:484
volatile time_t cur_time
Definition: timer.cpp:57
virtual void ping(const int tick) const =0
static void loadEmptyAtlas()
Definition: mapreader.cpp:1304
bool disableLoggingInGame
Definition: settings.h:158
void setInGame(const bool b)
Widget * getTop() const
Definition: gui.h:247
virtual void requestMoveToBottom()
Definition: widget.cpp:218
static void initEngines()
Definition: game.cpp:162
Map * mCurrentMap
Definition: game.h:142
Window * disconnectedDialog
Definition: game.cpp:154
time_t mTime
Definition: game.h:151
int mPing
Definition: game.h:150
SetupWindow * setupWindow
Definition: setupwindow.cpp:63
TouchManager touchManager
static void createGuiWindows()
Definition: game.cpp:190
MailWindow * mailWindow
Definition: mailwindow.cpp:53
void log(const char *const log_text,...)
Definition: logger.cpp:243
Net::GameHandler * gameHandler
Definition: net.cpp:84
void incValue(const std::string &key)
void clearKeysArray()
Definition: game.cpp:1270
static void setEnableCache(const bool b)
ActorManager * actorManager
Viewport * viewport
Definition: viewport.cpp:35
const time_t adjustDelay
Definition: game.cpp:157

◆ ~Game()

Game::~Game ( )

Destructor, cleans up the game.

Definition at line 474 of file game.cpp.

References actorManager, State::CHANGE_MAP, EffectManager::clear(), Being::clearCache(), client, config, crazyMoves, delete2, destroyGuiWindows(), Settings::disableLoggingInGame, effectManager, emptyBeingSlot, PlayerInfo::gameDestroyed(), Client::getState(), guildManager, localPlayer, mCurrentMap, mInstance, particleEngine, resetAdjustLevel(), serverConfig, AnimatedSprite::setEnableCache(), TouchManager::setInGame(), settings, touchManager, MapReader::unloadEmptyAtlas(), viewport, and Configuration::write().

475 {
476 #ifdef USE_OPENGL
478 #endif // USE_OPENGL
479 
481  touchManager.setInGame(false);
482  config.write();
486 
488 
492  if (effectManager != nullptr)
493  effectManager->clear();
498 #ifdef TMWA_SUPPORT
500 #endif // TMWA_SUPPORT
501 #ifdef USE_MUMBLE
502  delete2(mumbleManager)
503 #endif // USE_MUMBLE
504 
507 
509  mInstance = nullptr;
511 }
void gameDestroyed()
Definition: playerinfo.cpp:460
static Game * mInstance
Definition: game.h:154
ParticleEngine * particleEngine
Configuration config
Client * client
Definition: client.cpp:113
#define delete2(var)
Definition: delete2.h:24
Configuration serverConfig
static void unloadEmptyAtlas()
Definition: mapreader.cpp:1320
BeingSlot * emptyBeingSlot
Definition: beingslot.cpp:25
Settings settings
Definition: settings.cpp:31
CrazyMoves * crazyMoves
Definition: crazymoves.cpp:46
static void destroyGuiWindows()
Definition: game.cpp:343
LocalPlayer * localPlayer
GuildManager * guildManager
bool disableLoggingInGame
Definition: settings.h:158
void setInGame(const bool b)
StateT getState() const
Definition: client.h:68
Map * mCurrentMap
Definition: game.h:142
static void clearCache()
Definition: being.cpp:4690
TouchManager touchManager
EffectManager * effectManager
static void setEnableCache(const bool b)
ActorManager * actorManager
Viewport * viewport
Definition: viewport.cpp:35
void resetAdjustLevel()
Definition: game.cpp:882

Member Function Documentation

◆ addWatermark()

void Game::addWatermark ( )
static

Definition at line 513 of file game.cpp.

References boldFont, config, Font::drawString(), Configuration::getBoolValue(), Theme::getColor(), mainGraphics, Settings::serverName, settings, ThemeColorId::TEXT, ThemeColorId::TEXT_OUTLINE, and theme.

Referenced by createScreenshot(), and getValidSpeed().

514 {
515  if ((boldFont == nullptr) || !config.getBoolValue("addwatermark"))
516  return;
517 
518  const Color &color1 = theme->getColor(ThemeColorId::TEXT, 255);
519  const Color &color2 = theme->getColor(ThemeColorId::TEXT_OUTLINE, 255);
520 
522  color1,
523  color2,
525  100, 50);
526 }
Font * boldFont
Definition: gui.cpp:111
std::string serverName
Definition: settings.h:112
Configuration config
Settings settings
Definition: settings.cpp:31
bool getBoolValue(const std::string &key) const
void drawString(Graphics *const graphics, Color col, const Color &col2, const std::string &text, const int x, const int y)
Definition: font.cpp:253
Graphics * mainGraphics
Definition: graphics.cpp:108
const Color & getColor(ThemeColorIdT type, const unsigned int alpha)
Definition: theme.h:135
Theme * theme
Definition: theme.cpp:61
Definition: color.h:74

◆ adjustPerfomance()

void Game::adjustPerfomance ( )

Definition at line 775 of file game.cpp.

References _, adjustDelay, Settings::awayMode, ChatMsgType::BY_SERVER, ChatTab::chatLog(), config, cur_time, ParticleEngine::emitterSkip, fps, FUNC_BLOCK, Configuration::getBoolValue(), WindowManager::getFramerate(), LocalPlayer::getHalfAway(), Configuration::getIntValue(), IgnoreRecord_false, localChatTab, localPlayer, mAdjustLevel, mLowerCounter, mNextAdjustTime, Configuration::setSilent(), settings, Configuration::setValue(), ServerCommandType::time, and TryRemoveColors_true.

Referenced by getCurrentMapName(), and slowLogic().

776 {
777  FUNC_BLOCK("Game::adjustPerfomance", 1)
778  const time_t time = cur_time;
780  {
782  }
783  else if (mNextAdjustTime < time)
784  {
786 
787  if (mAdjustLevel > 3 ||
788  localPlayer == nullptr ||
791  {
792  return;
793  }
794 
795  int maxFps = WindowManager::getFramerate();
796  if (maxFps != config.getIntValue("fpslimit"))
797  return;
798 
799  if (maxFps == 0)
800  maxFps = 30;
801  else if (maxFps < 10)
802  return;
803 
804  if (fps < maxFps - 10)
805  {
806  if (mLowerCounter < 2)
807  {
808  mLowerCounter ++;
810  return;
811  }
812  mLowerCounter = 0;
813  mAdjustLevel ++;
814  switch (mAdjustLevel)
815  {
816  case 1:
817  {
818  if (config.getBoolValue("beingopacity"))
819  {
820  config.setValue("beingopacity", false);
821  config.setSilent("beingopacity", true);
822  if (localChatTab != nullptr)
823  {
825  // TRANSLATORS: auto adjust settings message
826  _("Auto disable Show beings transparency"),
830  }
831  }
832  else
833  {
834  mNextAdjustTime = time + 1;
835  mLowerCounter = 2;
836  }
837  break;
838  }
839  case 2:
841  {
843  if (localChatTab != nullptr)
844  {
846  // TRANSLATORS: auto adjust settings message
847  _("Auto lower Particle effects"),
851  }
852  }
853  else
854  {
855  mNextAdjustTime = time + 1;
856  mLowerCounter = 2;
857  }
858  break;
859  case 3:
860  if (!config.getBoolValue("alphaCache"))
861  {
862  config.setValue("alphaCache", true);
863  config.setSilent("alphaCache", false);
864  if (localChatTab != nullptr)
865  {
867  // TRANSLATORS: auto adjust settings message
868  _("Auto enable opacity cache"),
872  }
873  }
874  break;
875  default:
876  break;
877  }
878  }
879  }
880 }
#define _(s)
Definition: gettext.h:34
ChatTab * localChatTab
Definition: chattab.cpp:61
Configuration config
int mLowerCounter
Definition: game.h:149
if(!vert) return
const bool TryRemoveColors_true
void chatLog(std::string line, ChatMsgTypeT own, const IgnoreRecord ignoreRecord, const TryRemoveColors tryRemoveColors)
Definition: chattab.cpp:110
static int emitterSkip
int getIntValue(const std::string &key) const
volatile int fps
Definition: timer.cpp:53
void setSilent(const std::string &key, const std::string &value)
time_t mNextAdjustTime
Definition: game.h:146
Settings settings
Definition: settings.cpp:31
bool getBoolValue(const std::string &key) const
int mAdjustLevel
Definition: game.h:147
LocalPlayer * localPlayer
const bool IgnoreRecord_false
Definition: ignorerecord.h:29
volatile time_t cur_time
Definition: timer.cpp:57
#define FUNC_BLOCK(name, id)
Definition: perfomance.h:80
bool awayMode
Definition: settings.h:155
void setValue(const std::string &key, const std::string &value)
const time_t adjustDelay
Definition: game.cpp:157
bool getHalfAway() const
Definition: localplayer.h:238

◆ changeMap()

void Game::changeMap ( const std::string &  mapPath)

Changes the currently active map. Should only be called while the game is running.

Definition at line 1086 of file game.cpp.

References actorManager, Map::addExtraLayer(), BLOCK_END, BLOCK_START, Viewport::cleanHoverItems(), ResourceManager::cleanProtected(), ParticleEngine::clear(), ActorManager::clear(), PopupManager::clearPopup(), PopupManager::closePopupMenu(), VirtFs::exists(), SoundManager::fadeOutAndPlayMusic(), SoundManager::fadeOutMusic(), gameHandler, MapDB::getMapName(), Map::getMusicFile(), ConfigurationObject::getValue(), Map::initializeParticleEffects(), localPlayer, Net::GameHandler::mapLoadedEvent(), mCurrentMap, minimap, mMapName, particleEngine, pathJoin(), paths, questsWindow, MapReader::readMap(), Being::recreateItemParticles(), resetAdjustLevel(), Map::saveExtraLayer(), Minimap::setMap(), Viewport::setMap(), QuestsWindow::setMap(), ActorManager::setMap(), SocialWindow::setMap(), ParticleEngine::setMap(), LocalPlayer::setMap(), socialWindow, soundManager, and viewport.

Referenced by clearInstance(), Ea::GameHandler::initEngines(), and Ea::PlayerRecv::processPlayerWarp().

1087 {
1088  BLOCK_START("Game::changeMap")
1089 
1090  resetAdjustLevel();
1092 
1093  PopupManager::clearPopup();
1094  PopupManager::closePopupMenu();
1095 
1096  // Clean up floor items, beings and particles
1097  if (actorManager != nullptr)
1098  actorManager->clear();
1099 
1100  // Close the popup menu on map change so that invalid options can't be
1101  // executed.
1102  if (viewport != nullptr)
1103  viewport->cleanHoverItems();
1104 
1105  // Unset the map of the player so that its particles are cleared before
1106  // being deleted in the next step
1107  if (localPlayer != nullptr)
1108  localPlayer->setMap(nullptr);
1109 
1110  if (particleEngine != nullptr)
1111  particleEngine->clear();
1112 
1113  mMapName = mapPath;
1114 
1115  std::string fullMap = pathJoin(paths.getValue("maps", "maps/"),
1116  mMapName).append(".tmx");
1117  std::string realFullMap = pathJoin(paths.getValue("maps", "maps/"),
1118  MapDB::getMapName(mMapName)).append(".tmx");
1119 
1120  if (!VirtFs::exists(realFullMap))
1121  realFullMap.append(".gz");
1122 
1123  // Attempt to load the new map
1124  Map *const newMap = MapReader::readMap(fullMap, realFullMap);
1125 
1126  if (mCurrentMap != nullptr)
1127  mCurrentMap->saveExtraLayer();
1128 
1129  if (newMap != nullptr)
1130  newMap->addExtraLayer();
1131 
1132  if (socialWindow != nullptr)
1133  socialWindow->setMap(newMap);
1134 
1135  // Notify the minimap and actorManager about the map change
1136  if (minimap != nullptr)
1137  minimap->setMap(newMap);
1138  if (actorManager != nullptr)
1139  actorManager->setMap(newMap);
1140  if (particleEngine != nullptr)
1141  particleEngine->setMap(newMap);
1142  if (viewport != nullptr)
1143  viewport->setMap(newMap);
1144 
1145  // Initialize map-based particle effects
1146  if (newMap != nullptr)
1147  newMap->initializeParticleEffects();
1148 
1149  // Start playing new music file when necessary
1150  const std::string oldMusic = mCurrentMap != nullptr
1151  ? mCurrentMap->getMusicFile() : "";
1152  const std::string newMusic = newMap != nullptr ?
1153  newMap->getMusicFile() : "";
1154  if (newMusic != oldMusic)
1155  {
1156  if (newMusic.empty())
1157  soundManager.fadeOutMusic(1000);
1158  else
1159  soundManager.fadeOutAndPlayMusic(newMusic, 1000);
1160  }
1161 
1162  if (mCurrentMap != nullptr)
1164 
1165  delete mCurrentMap;
1166  mCurrentMap = newMap;
1167 
1168  if (questsWindow != nullptr)
1170 
1171 #ifdef USE_MUMBLE
1172  if (mumbleManager)
1173  mumbleManager->setMap(mapPath);
1174 #endif // USE_MUMBLE
1175 
1176  if (localPlayer != nullptr)
1178 
1180  BLOCK_END("Game::changeMap")
1181 }
void readMap(xmlNode *const node)
Definition: mapdb.cpp:103
QuestsWindow * questsWindow
std::string pathJoin(std::string str1, const std::string &str2)
#define BLOCK_START(name)
Definition: perfomance.h:78
SoundManager soundManager
ParticleEngine * particleEngine
void clear()
Definition: playerinfo.cpp:449
void fadeOutMusic(const int ms)
if(!vert) return
#define BLOCK_END(name)
Definition: perfomance.h:79
Definition: mapdb.cpp:39
LocalPlayer * localPlayer
std::string mMapName
Definition: game.h:143
const std::string getMapName(const std::string &name)
Definition: mapdb.cpp:193
void setMap(const Map *const map)
SocialWindow * socialWindow
Definition: map.h:68
void saveExtraLayer() const
Definition: map.cpp:1213
Configuration paths
virtual void mapLoadedEvent() const =0
bool exists(std::string name)
Definition: fs.cpp:123
Map * mCurrentMap
Definition: game.h:142
Net::GameHandler * gameHandler
Definition: net.cpp:84
void fadeOutAndPlayMusic(const std::string &fileName, const int ms)
void recreateItemParticles()
Definition: being.cpp:5134
ActorManager * actorManager
Viewport * viewport
Definition: viewport.cpp:35
Minimap * minimap
Definition: minimap.cpp:61
void resetAdjustLevel()
Definition: game.cpp:882

◆ checkKeys()

void Game::checkKeys ( )

Definition at line 1240 of file game.cpp.

References Settings::attackType, LastKey::cnt, cur_time, LastKey::key, localPlayer, MAX_LASTKEYS, mLastKeys, mValidSpeed, InputAction::NO_VALUE, settings, LastKey::time, and ServerCommandType::time.

Referenced by getValidSpeed().

1241 {
1242  const int timeRange = 120;
1243  const int cntInTime = 130;
1244 
1245  if ((localPlayer == nullptr) || (settings.attackType == 0u))
1246  return;
1247 
1248  const time_t time = cur_time;
1249  for (int f = 0; f < MAX_LASTKEYS; f ++)
1250  {
1251  LastKey &lastKey = mLastKeys[f];
1252  if (lastKey.key != InputAction::NO_VALUE)
1253  {
1254  if (lastKey.time + timeRange < time)
1255  {
1256  if (lastKey.cnt > cntInTime)
1257  mValidSpeed = false;
1258  lastKey.key = InputAction::NO_VALUE;
1259  }
1260  }
1261  }
1262 }
unsigned int attackType
Definition: settings.h:136
time_t time
Definition: game.h:53
bool mValidSpeed
Definition: game.h:144
Settings settings
Definition: settings.cpp:31
LocalPlayer * localPlayer
volatile time_t cur_time
Definition: timer.cpp:57
static const int MAX_LASTKEYS
Definition: game.h:37
Definition: game.h:43
LastKey mLastKeys[MAX_LASTKEYS]
Definition: game.h:145
int cnt
Definition: game.h:55
InputActionT key
Definition: game.h:54

◆ clearInstance()

static void Game::clearInstance ( )
inlinestatic

Definition at line 84 of file game.h.

References changeMap(), handleInput(), handleMove(), logic(), mInstance, slowLogic(), and updateFrameRate().

Referenced by Client::stateSwitchLogin1().

85  { mInstance = nullptr; }
static Game * mInstance
Definition: game.h:154

◆ clearKeysArray()

void Game::clearKeysArray ( )
private

Definition at line 1270 of file game.cpp.

References LastKey::cnt, LastKey::key, MAX_LASTKEYS, mLastKeys, InputAction::NO_VALUE, and LastKey::time.

Referenced by Game(), getValidSpeed(), and setValidSpeed().

1271 {
1272  for (int f = 0; f < MAX_LASTKEYS; f ++)
1273  {
1274  mLastKeys[f].time = 0;
1276  mLastKeys[f].cnt = 0;
1277  }
1278 }
time_t time
Definition: game.h:53
static const int MAX_LASTKEYS
Definition: game.h:37
LastKey mLastKeys[MAX_LASTKEYS]
Definition: game.h:145
int cnt
Definition: game.h:55
InputActionT key
Definition: game.h:54

◆ createScreenshot()

bool Game::createScreenshot ( const std::string &  prefix)
static

Definition at line 528 of file game.cpp.

References addWatermark(), config, Gui::draw(), Configuration::getBoolValue(), ScreenshotHelper::getScreenshot(), gui, mainGraphics, ScreenshotHelper::prepare(), saveScreenshot(), screenshortHelper, Actions::screenshot(), and Graphics::setSecure().

Referenced by TradeWindow::completeTrade(), Actions::doSit(), and getValidSpeed().

529 {
530  if ((mainGraphics == nullptr) || (screenshortHelper == nullptr))
531  return false;
532 
533  SDL_Surface *screenshot = nullptr;
534 
535  if (!config.getBoolValue("showip") && (gui != nullptr))
536  {
537  mainGraphics->setSecure(true);
539  gui->draw();
540  addWatermark();
541  screenshot = screenshortHelper->getScreenshot();
542  mainGraphics->setSecure(false);
543  }
544  else
545  {
546  addWatermark();
547  screenshot = screenshortHelper->getScreenshot();
548  }
549 
550  if (screenshot == nullptr)
551  return false;
552 
553  return saveScreenshot(screenshot, prefix);
554 }
Gui * gui
Definition: gui.cpp:110
Configuration config
static void addWatermark()
Definition: game.cpp:513
bool screenshot(InputEvent &event)
Definition: actions.cpp:50
void draw()
Definition: gui.cpp:469
virtual void prepare()=0
bool getBoolValue(const std::string &key) const
static bool saveScreenshot(SDL_Surface *const screenshot, const std::string &prefix)
Definition: game.cpp:556
void setSecure(const bool n)
Definition: graphics.h:289
Graphics * mainGraphics
Definition: graphics.cpp:108
ScreenshotHelper * screenshortHelper
virtual SDL_Surface * getScreenshot()=0

◆ getCurrentMap()

Map* Game::getCurrentMap ( ) const
inline

◆ getCurrentMapName()

const std::string& Game::getCurrentMapName ( ) const
inline

Definition at line 109 of file game.h.

References adjustPerfomance(), mMapName, resetAdjustLevel(), and setValidSpeed().

Referenced by Actions::doSit(), and Ea::PlayerRecv::processPlayerWarp().

110  { return mMapName; }
std::string mMapName
Definition: game.h:143

◆ getValidSpeed()

bool Game::getValidSpeed ( ) const
inline

◆ handleInput()

void Game::handleInput ( )

The huge input handling method.

Definition at line 1053 of file game.cpp.

References Settings::awayMode, BLOCK_END, BLOCK_START, InputAction::COPY_OUTFIT, eventsManager, EventsManager::handleGameEvents(), handleMove(), InputManager::handleRepeat(), inputManager, InputManager::isActionActive(), KeyboardConfig::isEnabled(), Window::isWindowVisible(), joystick, keyboard, Joystick::logic(), settings, setupWindow, and InputAction::WEAR_OUTFIT.

Referenced by clearInstance(), EventsManager::handleEvents(), and logic().

1054 {
1055  BLOCK_START("Game::handleInput 1")
1056  if (joystick != nullptr)
1057  joystick->logic();
1058 
1059  eventsManager.handleGameEvents();
1060 
1061  // If the user is configuring the keys then don't respond.
1062  if (!keyboard.isEnabled() || settings.awayMode)
1063  {
1064  BLOCK_END("Game::handleInput 1")
1065  return;
1066  }
1067 
1068  // If pressed outfits keys, stop processing keys.
1069  if (inputManager.isActionActive(InputAction::WEAR_OUTFIT)
1070  || inputManager.isActionActive(InputAction::COPY_OUTFIT)
1071  || ((setupWindow != nullptr) && setupWindow->isWindowVisible()))
1072  {
1073  BLOCK_END("Game::handleInput 1")
1074  return;
1075  }
1076 
1077  handleMove();
1078  InputManager::handleRepeat();
1079  BLOCK_END("Game::handleInput 1")
1080 }
Joystick * joystick
Definition: joystick.cpp:42
void handleInput()
Definition: game.cpp:1053
#define BLOCK_START(name)
Definition: perfomance.h:78
if(!vert) return
#define BLOCK_END(name)
Definition: perfomance.h:79
void logic()
Definition: game.cpp:656
Settings settings
Definition: settings.cpp:31
Definition: game.h:62
void handleMove()
Definition: game.cpp:913
EventsManager eventsManager
KeyboardConfig keyboard
SetupWindow * setupWindow
Definition: setupwindow.cpp:63
InputManager inputManager

◆ handleMove()

void Game::handleMove ( )

Definition at line 913 of file game.cpp.

References BLOCK_END, BLOCK_START, LocalPlayer::cancelFollow(), LocalPlayer::canMove(), chatWindow, BeingDirection::DOWN, InputAction::EMOTE, NpcDialog::getActive(), Being::getDirection(), InputAction::HOMUN_EMOTE, InputAction::IGNORE_INPUT_1, InputAction::IGNORE_INPUT_2, inputManager, InputManager::isActionActive(), InventoryWindow::isAnyInputFocused(), Joystick::isDown(), ChatWindow::isInputFocused(), Joystick::isLeft(), Popup::isPopupVisible(), Joystick::isRight(), Joystick::isUp(), joystick, BeingDirection::LEFT, localPlayer, InputAction::MOVE_DOWN, InputAction::MOVE_FORWARD, InputAction::MOVE_LEFT, InputAction::MOVE_RIGHT, InputAction::MOVE_UP, moveInDirection(), InputAction::PET_EMOTE, popupMenu, BeingDirection::RIGHT, setValidSpeed(), InputAction::STOP_ATTACK, and BeingDirection::UP.

Referenced by clearInstance(), and handleInput().

914 {
915  BLOCK_START("Game::handleMove")
916  if (localPlayer == nullptr)
917  {
918  BLOCK_END("Game::handleMove")
919  return;
920  }
921 
922  // Moving player around
923  if ((chatWindow != nullptr) &&
924  (quitDialog == nullptr) &&
925  localPlayer->canMove() &&
926  !chatWindow->isInputFocused() &&
927  !InventoryWindow::isAnyInputFocused() &&
928  !popupMenu->isPopupVisible())
929  {
930  NpcDialog *const dialog = NpcDialog::getActive();
931  if (dialog != nullptr)
932  {
933  BLOCK_END("Game::handleMove")
934  return;
935  }
936 
937  // Ignore input if either "ignore" key is pressed
938  // Stops the character moving about if the user's window manager
939  // uses "ignore+arrow key" to switch virtual desktops.
940  if (inputManager.isActionActive(InputAction::IGNORE_INPUT_1) ||
941  inputManager.isActionActive(InputAction::IGNORE_INPUT_2))
942  {
943  BLOCK_END("Game::handleMove")
944  return;
945  }
946 
947  unsigned char direction = 0;
948 
949  // Translate pressed keys to movement and direction
950  if (inputManager.isActionActive(InputAction::MOVE_UP) ||
951  ((joystick != nullptr) && joystick->isUp()))
952  {
953  direction |= BeingDirection::UP;
954  setValidSpeed();
956  }
958  ((joystick != nullptr) && joystick->isDown()))
959  {
960  direction |= BeingDirection::DOWN;
961  setValidSpeed();
963  }
964 
966  ((joystick != nullptr) && joystick->isLeft()))
967  {
968  direction |= BeingDirection::LEFT;
969  setValidSpeed();
971  }
973  ((joystick != nullptr) && joystick->isRight()))
974  {
975  direction |= BeingDirection::RIGHT;
976  setValidSpeed();
978  }
980  {
981  direction = localPlayer->getDirection();
982  setValidSpeed();
984  }
985 
990  || direction == 0)
991  {
992  moveInDirection(direction);
993  }
994  }
995  BLOCK_END("Game::handleMove")
996 }
ChatWindow * chatWindow
Definition: chatwindow.cpp:88
void setValidSpeed()
Definition: game.cpp:1264
Joystick * joystick
Definition: joystick.cpp:42
QuitDialog * quitDialog
Definition: game.cpp:153
static NpcDialog * getActive()
Definition: npcdialog.cpp:851
#define BLOCK_START(name)
Definition: perfomance.h:78
if(!vert) return
void cancelFollow()
#define BLOCK_END(name)
Definition: perfomance.h:79
uint8_t getDirection() const
Definition: being.h:487
bool isLeft() const
Definition: joystick.h:110
bool isActionActive(const InputActionT index) const
LocalPlayer * localPlayer
PopupMenu * popupMenu
Definition: popupmenu.cpp:102
bool isRight() const
Definition: joystick.h:113
bool isDown() const
Definition: joystick.h:107
InputManager inputManager
static void moveInDirection(const unsigned char direction)
Definition: game.cpp:998

◆ instance()

static Game* Game::instance ( )
inlinestatic

◆ logic()

void Game::logic ( )

This method takes the game a small step further. It is called 100 times per second.

Definition at line 656 of file game.cpp.

References actorManager, BLOCK_END, BLOCK_START, handleInput(), ActorManager::logic(), mCurrentMap, particleEngine, ParticleEngine::update(), and Map::update().

Referenced by clearInstance().

657 {
658  BLOCK_START("Game::logic")
659  handleInput();
660 
661  // Handle all necessary game logic
662  if (actorManager != nullptr)
663  actorManager->logic();
664  if (particleEngine != nullptr)
666  if (mCurrentMap != nullptr)
667  mCurrentMap->update(1);
668 
669  BLOCK_END("Game::logic")
670 }
void handleInput()
Definition: game.cpp:1053
#define BLOCK_START(name)
Definition: perfomance.h:78
ParticleEngine * particleEngine
if(!vert) return
#define BLOCK_END(name)
Definition: perfomance.h:79
void logic()
Definition: game.cpp:656
Definition: game.h:62
Map * mCurrentMap
Definition: game.h:142
void update()
Definition: useragent.cpp:31
ActorManager * actorManager

◆ moveInDirection()

void Game::moveInDirection ( const unsigned char  direction)
static

Definition at line 998 of file game.cpp.

References Settings::cameraMode, BeingDirection::DOWN, BeingDirection::LEFT, localPlayer, Viewport::moveCamera(), BeingDirection::RIGHT, settings, LocalPlayer::specialMove(), BeingDirection::UP, and viewport.

Referenced by getValidSpeed(), and handleMove().

999 {
1000  if (viewport == nullptr)
1001  return;
1002 
1003  if (settings.cameraMode == 0u)
1004  {
1005  if (localPlayer != nullptr)
1006  localPlayer->specialMove(direction);
1007  }
1008  else
1009  {
1010  int dx = 0;
1011  int dy = 0;
1012  if ((direction & BeingDirection::LEFT) != 0)
1013  dx = -5;
1014  else if ((direction & BeingDirection::RIGHT) != 0)
1015  dx = 5;
1016 
1017  if ((direction & BeingDirection::UP) != 0)
1018  dy = -5;
1019  else if ((direction & BeingDirection::DOWN) != 0)
1020  dy = 5;
1021  viewport->moveCamera(dx, dy);
1022  }
1023 }
Settings settings
Definition: settings.cpp:31
LocalPlayer * localPlayer
void moveCamera(const int dx, const int dy)
Definition: viewport.cpp:1069
unsigned int cameraMode
Definition: settings.h:142
void specialMove(const unsigned char direction)
Viewport * viewport
Definition: viewport.cpp:35

◆ resetAdjustLevel()

void Game::resetAdjustLevel ( )

Definition at line 882 of file game.cpp.

References adjustDelay, config, cur_time, ParticleEngine::emitterSkip, Configuration::getBoolValue(), Configuration::getIntValue(), mAdjustLevel, mAdjustPerfomance, mNextAdjustTime, and Configuration::setValue().

Referenced by SetupWindow::action(), changeMap(), getCurrentMapName(), and ~Game().

883 {
884  if (!mAdjustPerfomance)
885  return;
886 
888  switch (mAdjustLevel)
889  {
890  case 1:
891  config.setValue("beingopacity",
892  config.getBoolValue("beingopacity"));
893  break;
894  case 2:
895  config.setValue("beingopacity",
896  config.getBoolValue("beingopacity"));
898  "particleEmitterSkip") + 1;
899  break;
900  default:
901  case 3:
902  config.setValue("beingopacity",
903  config.getBoolValue("beingopacity"));
905  "particleEmitterSkip") + 1;
906  config.setValue("alphaCache",
907  config.getBoolValue("alphaCache"));
908  break;
909  }
910  mAdjustLevel = 0;
911 }
bool mAdjustPerfomance
Definition: game.h:148
Configuration config
static int emitterSkip
int getIntValue(const std::string &key) const
time_t mNextAdjustTime
Definition: game.h:146
bool getBoolValue(const std::string &key) const
int mAdjustLevel
Definition: game.h:147
volatile time_t cur_time
Definition: timer.cpp:57
void setValue(const std::string &key, const std::string &value)
const time_t adjustDelay
Definition: game.cpp:157

◆ saveScreenshot()

bool Game::saveScreenshot ( SDL_Surface *const  screenshot,
const std::string &  prefix 
)
static

Definition at line 556 of file game.cpp.

References _, branding, ChatMsgType::BY_SERVER, ChatTab::chatLog(), cutFirst(), VirtFs::getUserDir(), ConfigurationObject::getValue(), IgnoreRecord_false, localChatTab, Logger::log(), Logger::log1(), logger, mkdir_r(), MSDL_FreeSurface, Settings::screenshotDir, Settings::serverName, settings, ServerCommandType::str, strprintf(), ServerCommandType::time, TryRemoveColors_true, and PngLib::writePNG().

Referenced by createScreenshot(), and getValidSpeed().

558 {
559  std::string screenshotDirectory = settings.screenshotDir;
560  if (mkdir_r(screenshotDirectory.c_str()) != 0)
561  {
562  logger->log("Directory %s doesn't exist and can't be created! "
563  "Setting screenshot directory to home.",
564  screenshotDirectory.c_str());
565  screenshotDirectory = std::string(VirtFs::getUserDir());
566  }
567 
568  // Search for an unused screenshot name
569  std::stringstream filename;
570  std::fstream testExists;
571 
572  time_t rawtime;
573  char buffer [100];
574  time(&rawtime);
575  struct tm *const timeinfo = localtime(&rawtime);
576  strftime(buffer, 99, "%Y-%m-%d_%H-%M-%S", timeinfo);
577 
578  const std::string serverName = settings.serverName;
579  std::string screenShortStr;
580  if (prefix.empty())
581  {
582  if (serverName.empty())
583  {
584  screenShortStr = strprintf("%s_Screenshot_%s_",
585  branding.getValue("appName", "ManaPlus").c_str(),
586  buffer);
587  }
588  else
589  {
590  screenShortStr = strprintf("%s_Screenshot_%s_%s_",
591  branding.getValue("appName", "ManaPlus").c_str(),
592  serverName.c_str(), buffer);
593  }
594 
595  bool found = false;
596  static unsigned int screenshotCount = 0;
597  do
598  {
599  screenshotCount++;
600  filename.str("");
601  filename << screenshotDirectory << "/";
602  filename << screenShortStr << screenshotCount << ".png";
603  testExists.open(filename.str().c_str(), std::ios::in);
604  found = !testExists.is_open();
605  testExists.close();
606  }
607  while (!found);
608  }
609  else
610  {
611  screenShortStr = prefix;
612  filename.str("");
613  filename << screenshotDirectory << "/";
614  filename << screenShortStr;
615  }
616 
617  const std::string fileNameStr = filename.str();
618  const bool success = PngLib::writePNG(screenshot, fileNameStr);
619 #ifdef __native_client__
620  std::string nacScreenshotlDir = fileNameStr;
621  cutFirst(nacScreenshotlDir, "/persistent");
622  naclPostMessage("copy-from-persistent", nacScreenshotlDir);
623  logger->log("nacl screenshot path: " + nacScreenshotlDir);
624 #endif // __native_client__
625 
626  if (success)
627  {
628  if (localChatTab != nullptr)
629  {
630  // TRANSLATORS: save file message
631  std::string str = strprintf(_("Screenshot saved as %s"),
632  fileNameStr.c_str());
633  localChatTab->chatLog(str,
637  }
638  }
639  else
640  {
641  if (localChatTab != nullptr)
642  {
643  // TRANSLATORS: save file message
644  localChatTab->chatLog(_("Saving screenshot failed!"),
648  }
649  logger->log1("Error: could not save screenshot.");
650  }
651 
653  return success;
654 }
Configuration branding
#define _(s)
Definition: gettext.h:34
void log1(const char *const log_text)
Definition: logger.cpp:222
std::string serverName
Definition: settings.h:112
ChatTab * localChatTab
Definition: chattab.cpp:61
int mkdir_r(const char *const pathname)
Create a directory, making leading components first if necessary.
Definition: mkdir.cpp:108
#define MSDL_FreeSurface(surface)
Definition: debug.h:53
bool screenshot(InputEvent &event)
Definition: actions.cpp:50
const bool TryRemoveColors_true
void chatLog(std::string line, ChatMsgTypeT own, const IgnoreRecord ignoreRecord, const TryRemoveColors tryRemoveColors)
Definition: chattab.cpp:110
const char * getUserDir()
Definition: fs.cpp:83
Logger * logger
Definition: logger.cpp:95
Settings settings
Definition: settings.cpp:31
std::string screenshotDir
Definition: settings.h:113
bool writePNG(SDL_Surface *const surface, const std::string &filename)
Definition: pnglib.cpp:36
std::string strprintf(const char *const format,...)
Definition: stringutils.cpp:99
const bool IgnoreRecord_false
Definition: ignorerecord.h:29
void cutFirst(std::string &str1, const std::string &str2)
std::string getValue(const std::string &key, const std::string &deflt) const
void log(const char *const log_text,...)
Definition: logger.cpp:243

◆ setAdjustLevel()

void Game::setAdjustLevel ( const int  n)
inline

Definition at line 118 of file game.h.

References mAdjustLevel, and videoResized().

119  { mAdjustLevel = n; }
int mAdjustLevel
Definition: game.h:147

◆ setValidSpeed()

void Game::setValidSpeed ( )

◆ slowLogic()

void Game::slowLogic ( )

Definition at line 672 of file game.cpp.

References _, Widget::addActionListener(), adjustDelay, adjustPerfomance(), BLOCK_END, BLOCK_START, State::CHANGE_MAP, client, DialogsManager::closeDialogs(), config, cur_time, debugWindow, DelayedManager::delayedLoad(), effectManager, State::ERROR, errorListener, errorMessage, gameHandler, get_elapsed_time1(), Configuration::getIntValue(), Viewport::getMap(), Graphics::getOpenGL(), Client::getState(), guildManager, Net::GameHandler::isConnected(), killStats, localPlayer, EffectManager::logic(), mAdjustPerfomance, mainGraphics, mNextAdjustTime, Modal_false, mPing, mTime, mTime2, Net::GameHandler::mustPing(), mValidSpeed, DialogsManager::openErrorDialog(), Net::GameHandler::ping(), KillStats::recalcStats(), RENDER_SOFTWARE, Widget::requestMoveToTop(), Being::reReadConfig(), Map::saveExtraLayer(), Window::scheduleDelete(), serverConfig, WindowManager::setFramerate(), shopWindow, skillDialog, DebugWindow::slowLogic(), LocalPlayer::slowLogic(), WhoIsOnline::slowLogic(), GuildManager::slowLogic(), SocialWindow::slowLogic(), SkillDialog::slowLogic(), socialWindow, tick_time, ServerCommandType::time, PacketCounters::update(), KillStats::update(), ShopWindow::updateTimes(), valTest, viewport, whoIsOnline, and Configuration::writeUpdated().

Referenced by clearInstance().

673 {
674  BLOCK_START("Game::slowLogic")
675  if (localPlayer != nullptr)
677  const time_t time = cur_time;
678  if (mTime != time)
679  {
680  if (valTest(Updated))
681  mValidSpeed = false;
682 
683  mTime = time + 1;
684  if (debugWindow != nullptr)
686  if (killStats != nullptr)
687  killStats->update();
688  if (socialWindow != nullptr)
690  if (whoIsOnline != nullptr)
693  if (killStats != nullptr)
694  cilk_spawn killStats->recalcStats();
695 
696  if (time > mTime2 || mTime2 - time > 10)
697  {
698  mTime2 = time + 10;
701  }
702  if (effectManager != nullptr)
703  effectManager->logic();
704  }
705 
708 
709 #ifdef TMWA_SUPPORT
710  if (shopWindow != nullptr)
711  cilk_spawn shopWindow->updateTimes();
712  if (guildManager != nullptr)
714 #endif // TMWA_SUPPORT
715 
716  if (skillDialog != nullptr)
717  cilk_spawn skillDialog->slowLogic();
718 
719  cilk_spawn PacketCounters::update();
720 
721  // Handle network stuff
722  if (!gameHandler->isConnected())
723  {
725  return; // Not a problem here
726 
727  if (client->getState() != State::ERROR)
728  {
729  if (disconnectedDialog == nullptr)
730  {
731  // TRANSLATORS: error message text
732  errorMessage = _("The connection to the server was lost.");
734  // TRANSLATORS: error message header
735  _("Network Error"),
736  errorMessage,
737  Modal_false);
740  }
741  }
742 
743  if ((viewport != nullptr) && !errorMessage.empty())
744  {
745  const Map *const map = viewport->getMap();
746  if (map != nullptr)
747  map->saveExtraLayer();
748  }
751  mNextAdjustTime = cur_time + adjustDelay;
752  if (client->getState() != State::ERROR)
753  errorMessage.clear();
754  }
755  else
756  {
757  if (gameHandler->mustPing()
758  && get_elapsed_time1(mPing) > 3000)
759  {
760  mPing = tick_time;
762  }
763 
764  if (mAdjustPerfomance)
766  if (disconnectedDialog != nullptr)
767  {
769  disconnectedDialog = nullptr;
770  }
771  }
772  BLOCK_END("Game::slowLogic")
773 }
DebugWindow * debugWindow
Definition: debugwindow.cpp:39
bool mAdjustPerfomance
Definition: game.h:148
#define _(s)
Definition: gettext.h:34
#define valTest(num)
volatile int tick_time
Definition: timer.cpp:52
void slowLogic()
void addActionListener(ActionListener *const actionListener)
Definition: widget.cpp:251
virtual void requestMoveToTop()
Definition: widget.cpp:212
#define BLOCK_START(name)
Definition: perfomance.h:78
Configuration config
time_t mTime2
Definition: game.h:152
if(!vert) return
WhoIsOnline * whoIsOnline
Definition: whoisonline.cpp:78
#define BLOCK_END(name)
Definition: perfomance.h:79
int getIntValue(const std::string &key) const
bool mValidSpeed
Definition: game.h:144
Client * client
Definition: client.cpp:113
Configuration serverConfig
static void update()
void slowLogic()
Definition: debugwindow.cpp:94
void slowLogic()
Definition: game.cpp:672
KillStats * killStats
Definition: killstats.cpp:45
time_t mNextAdjustTime
Definition: game.h:146
std::string errorMessage
Definition: client.cpp:111
int get_elapsed_time1(const int startTime)
Definition: timer.cpp:104
void setFramerate(const unsigned int fpsLimit)
void updateTimes()
LocalPlayer * localPlayer
GuildManager * guildManager
RenderType getOpenGL() const
Definition: graphics.h:307
ErrorListener errorListener
Graphics * mainGraphics
Definition: graphics.cpp:108
static void closeDialogs()
volatile time_t cur_time
Definition: timer.cpp:57
SocialWindow * socialWindow
Definition: map.h:68
virtual void ping(const int tick) const =0
virtual void scheduleDelete()
Definition: window.cpp:826
void saveExtraLayer() const
Definition: map.cpp:1213
ShopWindow * shopWindow
Definition: shopwindow.cpp:99
SkillDialog * skillDialog
Definition: skilldialog.cpp:65
static void reReadConfig()
Definition: being.cpp:3405
void adjustPerfomance()
Definition: game.cpp:775
StateT getState() const
Definition: client.h:68
virtual bool mustPing() const =0
Window * disconnectedDialog
Definition: game.cpp:154
virtual bool isConnected() const =0
void recalcStats()
Definition: killstats.cpp:309
time_t mTime
Definition: game.h:151
int mPing
Definition: game.h:150
void update()
Definition: killstats.cpp:363
static void delayedLoad()
Map * getMap() const
Definition: viewport.h:134
static Window * openErrorDialog(const std::string &header, const std::string &message, const Modal modal)
void slowLogic()
Net::GameHandler * gameHandler
Definition: net.cpp:84
EffectManager * effectManager
Viewport * viewport
Definition: viewport.cpp:35
const time_t adjustDelay
Definition: game.cpp:157

◆ updateFrameRate()

void Game::updateFrameRate ( int  fpsLimit)

Definition at line 1025 of file game.cpp.

References adjustDelay, Settings::awayMode, config, cur_time, Configuration::getIntValue(), Settings::inputFocused, mNextAdjustTime, Settings::mouseFocused, WindowManager::setFramerate(), settings, and KeyboardFocus::Unfocused.

Referenced by GameModifiers::changeAwayMode(), clearInstance(), EventsManager::handleActive(), and EventsManager::logEvent().

1026 {
1027  if (fpsLimit == 0)
1028  {
1029  if (settings.awayMode)
1030  {
1033  {
1034  fpsLimit = config.getIntValue("fpslimit");
1035  }
1036  else
1037  {
1038  fpsLimit = config.getIntValue("altfpslimit");
1039  }
1040  }
1041  else
1042  {
1043  fpsLimit = config.getIntValue("fpslimit");
1044  }
1045  }
1046  WindowManager::setFramerate(fpsLimit);
1048 }
Configuration config
int getIntValue(const std::string &key) const
time_t mNextAdjustTime
Definition: game.h:146
Settings settings
Definition: settings.cpp:31
void setFramerate(const unsigned int fpsLimit)
KeyboardFocusT inputFocused
Definition: settings.h:152
volatile time_t cur_time
Definition: timer.cpp:57
bool awayMode
Definition: settings.h:155
bool mouseFocused
Definition: settings.h:153
const time_t adjustDelay
Definition: game.cpp:157

◆ updateHistory()

void Game::updateHistory ( const SDL_Event &  event)

Definition at line 1183 of file game.cpp.

References Settings::attackType, CAST_S32, LastKey::cnt, cur_time, KeyboardConfig::getKeyIndex(), LastKey::key, localPlayer, MAX_LASTKEYS, mLastKeys, InputAction::NO_VALUE, settings, LastKey::time, and ServerCommandType::time.

Referenced by getValidSpeed().

1184 {
1185  if ((localPlayer == nullptr) || (settings.attackType == 0u))
1186  return;
1187 
1188  if (CAST_S32(event.key.keysym.sym) != -1)
1189  {
1190  bool old = false;
1191 
1192  const InputActionT key = KeyboardConfig::getKeyIndex(event, 1);
1193  const time_t time = cur_time;
1194  int idx = -1;
1195  for (int f = 0; f < MAX_LASTKEYS; f ++)
1196  {
1197  LastKey &lastKey = mLastKeys[f];
1198  if (lastKey.key == key)
1199  {
1200  idx = f;
1201  old = true;
1202  break;
1203  }
1204  else if (idx >= 0 && lastKey.time < mLastKeys[idx].time)
1205  {
1206  idx = f;
1207  }
1208  }
1209  if (idx < 0)
1210  {
1211  idx = 0;
1212  for (int f = 0; f < MAX_LASTKEYS; f ++)
1213  {
1214  LastKey &lastKey = mLastKeys[f];
1215  if (lastKey.key == InputAction::NO_VALUE ||
1216  lastKey.time < mLastKeys[idx].time)
1217  {
1218  idx = f;
1219  }
1220  }
1221  }
1222 
1223  if (idx < 0)
1224  idx = 0;
1225 
1226  LastKey &keyIdx = mLastKeys[idx];
1227  if (!old)
1228  {
1229  keyIdx.time = time;
1230  keyIdx.key = key;
1231  keyIdx.cnt = 0;
1232  }
1233  else
1234  {
1235  keyIdx.cnt++;
1236  }
1237  }
1238 }
unsigned int attackType
Definition: settings.h:136
time_t time
Definition: game.h:53
Settings settings
Definition: settings.cpp:31
#define CAST_S32
Definition: cast.h:29
LocalPlayer * localPlayer
InputAction ::T InputActionT
Definition: inputaction.h:714
volatile time_t cur_time
Definition: timer.cpp:57
static const int MAX_LASTKEYS
Definition: game.h:37
Definition: game.h:43
static InputActionT getKeyIndex(const SDL_Event &event, const int grp)
LastKey mLastKeys[MAX_LASTKEYS]
Definition: game.h:145
int cnt
Definition: game.h:55
InputActionT key
Definition: game.h:54

◆ videoResized()

void Game::videoResized ( const int  width,
const int  height 
)
static

Definition at line 1280 of file game.cpp.

References Widget::getWidth(), Widget::setPosition(), Widget::setSize(), viewport, and windowMenu.

Referenced by WindowManager::resizeVideo(), and setAdjustLevel().

1281 {
1282  if (viewport != nullptr)
1283  viewport->setSize(width, height);
1284  if (windowMenu != nullptr)
1285  windowMenu->setPosition(width - windowMenu->getWidth(), 0);
1286 }
void setSize(const int width, const int height)
Definition: widget.cpp:366
int getWidth() const
Definition: widget.h:220
WindowMenu * windowMenu
Definition: windowmenu.cpp:47
void setPosition(const int x, const int y)
Definition: widget.cpp:160
Viewport * viewport
Definition: viewport.cpp:35

Field Documentation

◆ mAdjustLevel

int Game::mAdjustLevel
private

Definition at line 147 of file game.h.

Referenced by adjustPerfomance(), resetAdjustLevel(), and setAdjustLevel().

◆ mAdjustPerfomance

bool Game::mAdjustPerfomance
private

Definition at line 148 of file game.h.

Referenced by resetAdjustLevel(), and slowLogic().

◆ mCurrentMap

Map* Game::mCurrentMap
private

Definition at line 142 of file game.h.

Referenced by changeMap(), getCurrentMap(), logic(), and ~Game().

◆ mInstance

Game * Game::mInstance = 0
staticprivate

Definition at line 154 of file game.h.

Referenced by clearInstance(), destroyGuiWindows(), Game(), instance(), and ~Game().

◆ mLastKeys

LastKey Game::mLastKeys[MAX_LASTKEYS]
private

Definition at line 145 of file game.h.

Referenced by checkKeys(), clearKeysArray(), and updateHistory().

◆ mLowerCounter

int Game::mLowerCounter
private

Definition at line 149 of file game.h.

Referenced by adjustPerfomance().

◆ mMapName

std::string Game::mMapName
private

Definition at line 143 of file game.h.

Referenced by changeMap(), and getCurrentMapName().

◆ mNextAdjustTime

time_t Game::mNextAdjustTime
private

Definition at line 146 of file game.h.

Referenced by adjustPerfomance(), resetAdjustLevel(), slowLogic(), and updateFrameRate().

◆ mPing

int Game::mPing
private

Definition at line 150 of file game.h.

Referenced by slowLogic().

◆ mTime

time_t Game::mTime
private

Definition at line 151 of file game.h.

Referenced by slowLogic().

◆ mTime2

time_t Game::mTime2
private

Definition at line 152 of file game.h.

Referenced by slowLogic().

◆ mValidSpeed

bool Game::mValidSpeed
private

Definition at line 144 of file game.h.

Referenced by checkKeys(), getValidSpeed(), setValidSpeed(), and slowLogic().


The documentation for this class was generated from the following files: