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 403 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.

403  :
404  mCurrentMap(nullptr),
405  mMapName(""),
406  mValidSpeed(true),
408  mAdjustLevel(0),
409  mAdjustPerfomance(config.getBoolValue("adjustPerfomance")),
410  mLowerCounter(0),
411  mPing(0),
412  mTime(cur_time + 1),
413  mTime2(cur_time + 10)
414 {
415  touchManager.setInGame(true);
416 
417 // assert(!mInstance);
418  if (mInstance != nullptr)
419  logger->log("error: double game creation");
420  mInstance = this;
421 
422  config.incValue("gamecount");
423 
424  disconnectedDialog = nullptr;
425 
426  // Create the viewport
427  viewport = new Viewport;
430 
432 
433  BasicContainer2 *const top = static_cast<BasicContainer2*>(gui->getTop());
434  if (top != nullptr)
435  top->add(viewport);
437 
440  config.getBoolValue("enableDelayedAnimations"));
441 
443  config.getBoolValue("enableCompoundSpriteDelay"));
444 
446  windowMenu = new WindowMenu(nullptr);
447 
448  if (windowContainer != nullptr)
450 
451 #ifdef USE_OPENGL
453 #endif // USE_OPENGL
454 
455  initEngines();
456 
459 
460  // Initialize beings
461  if (actorManager != nullptr)
463 
465 
466  if (setupWindow != nullptr)
467  setupWindow->setInGame(true);
468  clearKeysArray();
469 
470 #ifdef TMWA_SUPPORT
471  if (guildManager != nullptr && GuildManager::getEnableGuildBot())
473 #endif // TMWA_SUPPORT
474 
476  "disableLoggingInGame");
477 }
void setSize(const int width, const int height)
Definition: widget.cpp:366
ChatWindow * chatWindow
Definition: chatwindow.cpp:89
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:346
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:50
BeingSlot * emptyBeingSlot
Definition: beingslot.cpp:25
static void setEnableDelay(bool b)
Logger * logger
Definition: logger.cpp:88
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:1316
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:165
Map * mCurrentMap
Definition: game.h:142
Window * disconnectedDialog
Definition: game.cpp:157
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:193
MailWindow * mailWindow
Definition: mailwindow.cpp:53
void log(const char *const log_text,...)
Definition: logger.cpp:264
Net::GameHandler * gameHandler
Definition: net.cpp:87
void incValue(const std::string &key)
void clearKeysArray()
Definition: game.cpp:1275
static void setEnableCache(const bool b)
ActorManager * actorManager
Viewport * viewport
Definition: viewport.cpp:35
const time_t adjustDelay
Definition: game.cpp:160

◆ ~Game()

Game::~Game ( )

Destructor, cleans up the game.

Definition at line 479 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().

480 {
481 #ifdef USE_OPENGL
483 #endif // USE_OPENGL
484 
486  touchManager.setInGame(false);
487  config.write();
491 
493 
497  if (effectManager != nullptr)
498  effectManager->clear();
503 #ifdef TMWA_SUPPORT
505 #endif // TMWA_SUPPORT
506 #ifdef USE_MUMBLE
507  delete2(mumbleManager)
508 #endif // USE_MUMBLE
509 
512 
514  mInstance = nullptr;
516 }
void gameDestroyed()
Definition: playerinfo.cpp:460
static Game * mInstance
Definition: game.h:154
ParticleEngine * particleEngine
Configuration config
Client * client
Definition: client.cpp:117
#define delete2(var)
Definition: delete2.h:24
Configuration serverConfig
static void unloadEmptyAtlas()
Definition: mapreader.cpp:1332
BeingSlot * emptyBeingSlot
Definition: beingslot.cpp:25
Settings settings
Definition: settings.cpp:31
CrazyMoves * crazyMoves
Definition: crazymoves.cpp:46
static void destroyGuiWindows()
Definition: game.cpp:347
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:4719
TouchManager touchManager
EffectManager * effectManager
static void setEnableCache(const bool b)
ActorManager * actorManager
Viewport * viewport
Definition: viewport.cpp:35
void resetAdjustLevel()
Definition: game.cpp:887

Member Function Documentation

◆ addWatermark()

void Game::addWatermark ( )
static

Definition at line 518 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().

519 {
520  if ((boldFont == nullptr) || !config.getBoolValue("addwatermark"))
521  return;
522 
523  const Color &color1 = theme->getColor(ThemeColorId::TEXT, 255);
524  const Color &color2 = theme->getColor(ThemeColorId::TEXT_OUTLINE, 255);
525 
527  color1,
528  color2,
530  100, 50);
531 }
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
const Color & getColor(const ThemeColorIdT type, const unsigned int alpha)
Definition: theme.h:135
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
Theme * theme
Definition: theme.cpp:61
Definition: color.h:74

◆ adjustPerfomance()

void Game::adjustPerfomance ( )

Definition at line 780 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().

781 {
782  FUNC_BLOCK("Game::adjustPerfomance", 1)
783  const time_t time = cur_time;
785  {
787  }
788  else if (mNextAdjustTime < time)
789  {
791 
792  if (mAdjustLevel > 3 ||
793  localPlayer == nullptr ||
796  {
797  return;
798  }
799 
800  int maxFps = WindowManager::getFramerate();
801  if (maxFps != config.getIntValue("fpslimit"))
802  return;
803 
804  if (maxFps == 0)
805  maxFps = 30;
806  else if (maxFps < 10)
807  return;
808 
809  if (fps < maxFps - 10)
810  {
811  if (mLowerCounter < 2)
812  {
813  mLowerCounter ++;
815  return;
816  }
817  mLowerCounter = 0;
818  mAdjustLevel ++;
819  switch (mAdjustLevel)
820  {
821  case 1:
822  {
823  if (config.getBoolValue("beingopacity"))
824  {
825  config.setValue("beingopacity", false);
826  config.setSilent("beingopacity", true);
827  if (localChatTab != nullptr)
828  {
830  // TRANSLATORS: auto adjust settings message
831  _("Auto disable Show beings transparency"),
835  }
836  }
837  else
838  {
839  mNextAdjustTime = time + 1;
840  mLowerCounter = 2;
841  }
842  break;
843  }
844  case 2:
846  {
848  if (localChatTab != nullptr)
849  {
851  // TRANSLATORS: auto adjust settings message
852  _("Auto lower Particle effects"),
856  }
857  }
858  else
859  {
860  mNextAdjustTime = time + 1;
861  mLowerCounter = 2;
862  }
863  break;
864  case 3:
865  if (!config.getBoolValue("alphaCache"))
866  {
867  config.setValue("alphaCache", true);
868  config.setSilent("alphaCache", false);
869  if (localChatTab != nullptr)
870  {
872  // TRANSLATORS: auto adjust settings message
873  _("Auto enable opacity cache"),
877  }
878  }
879  break;
880  default:
881  break;
882  }
883  }
884  }
885 }
#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:160
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 1091 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().

1092 {
1093  BLOCK_START("Game::changeMap")
1094 
1095  resetAdjustLevel();
1097 
1098  PopupManager::clearPopup();
1099  PopupManager::closePopupMenu();
1100 
1101  // Clean up floor items, beings and particles
1102  if (actorManager != nullptr)
1103  actorManager->clear();
1104 
1105  // Close the popup menu on map change so that invalid options can't be
1106  // executed.
1107  if (viewport != nullptr)
1108  viewport->cleanHoverItems();
1109 
1110  // Unset the map of the player so that its particles are cleared before
1111  // being deleted in the next step
1112  if (localPlayer != nullptr)
1113  localPlayer->setMap(nullptr);
1114 
1115  if (particleEngine != nullptr)
1116  particleEngine->clear();
1117 
1118  mMapName = mapPath;
1119 
1120  std::string fullMap = pathJoin(paths.getValue("maps", "maps/"),
1121  mMapName).append(".tmx");
1122  std::string realFullMap = pathJoin(paths.getValue("maps", "maps/"),
1123  MapDB::getMapName(mMapName)).append(".tmx");
1124 
1125  if (!VirtFs::exists(realFullMap))
1126  realFullMap.append(".gz");
1127 
1128  // Attempt to load the new map
1129  Map *const newMap = MapReader::readMap(fullMap, realFullMap);
1130 
1131  if (mCurrentMap != nullptr)
1132  mCurrentMap->saveExtraLayer();
1133 
1134  if (newMap != nullptr)
1135  newMap->addExtraLayer();
1136 
1137  if (socialWindow != nullptr)
1138  socialWindow->setMap(newMap);
1139 
1140  // Notify the minimap and actorManager about the map change
1141  if (minimap != nullptr)
1142  minimap->setMap(newMap);
1143  if (actorManager != nullptr)
1144  actorManager->setMap(newMap);
1145  if (particleEngine != nullptr)
1146  particleEngine->setMap(newMap);
1147  if (viewport != nullptr)
1148  viewport->setMap(newMap);
1149 
1150  // Initialize map-based particle effects
1151  if (newMap != nullptr)
1152  newMap->initializeParticleEffects();
1153 
1154  // Start playing new music file when necessary
1155  const std::string oldMusic = mCurrentMap != nullptr
1156  ? mCurrentMap->getMusicFile() : "";
1157  const std::string newMusic = newMap != nullptr ?
1158  newMap->getMusicFile() : "";
1159  if (newMusic != oldMusic)
1160  {
1161  if (newMusic.empty())
1162  soundManager.fadeOutMusic(1000);
1163  else
1164  soundManager.fadeOutAndPlayMusic(newMusic, 1000);
1165  }
1166 
1167  if (mCurrentMap != nullptr)
1169 
1170  delete mCurrentMap;
1171  mCurrentMap = newMap;
1172 
1173  if (questsWindow != nullptr)
1175 
1176 #ifdef USE_MUMBLE
1177  if (mumbleManager)
1178  mumbleManager->setMap(mapPath);
1179 #endif // USE_MUMBLE
1180 
1181  if (localPlayer != nullptr)
1183 
1185  BLOCK_END("Game::changeMap")
1186 }
void readMap(xmlNode *const node)
Definition: mapdb.cpp:104
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:40
LocalPlayer * localPlayer
std::string mMapName
Definition: game.h:143
const std::string getMapName(const std::string &name)
Definition: mapdb.cpp:203
void setMap(const Map *const map)
SocialWindow * socialWindow
Definition: map.h:71
void saveExtraLayer() const
Definition: map.cpp:1221
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:87
void fadeOutAndPlayMusic(const std::string &fileName, const int ms)
void recreateItemParticles()
Definition: being.cpp:5163
ActorManager * actorManager
Viewport * viewport
Definition: viewport.cpp:35
Minimap * minimap
Definition: minimap.cpp:61
void resetAdjustLevel()
Definition: game.cpp:887

◆ checkKeys()

void Game::checkKeys ( )

Definition at line 1245 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().

1246 {
1247  const int timeRange = 120;
1248  const int cntInTime = 130;
1249 
1250  if ((localPlayer == nullptr) || (settings.attackType == 0u))
1251  return;
1252 
1253  const time_t time = cur_time;
1254  for (int f = 0; f < MAX_LASTKEYS; f ++)
1255  {
1256  LastKey &lastKey = mLastKeys[f];
1257  if (lastKey.key != InputAction::NO_VALUE)
1258  {
1259  if (lastKey.time + timeRange < time)
1260  {
1261  if (lastKey.cnt > cntInTime)
1262  mValidSpeed = false;
1263  lastKey.key = InputAction::NO_VALUE;
1264  }
1265  }
1266  }
1267 }
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 1275 of file game.cpp.

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

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

1276 {
1277  for (int f = 0; f < MAX_LASTKEYS; f ++)
1278  {
1279  mLastKeys[f].time = 0;
1281  mLastKeys[f].cnt = 0;
1282  }
1283 }
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 533 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().

534 {
535  if ((mainGraphics == nullptr) || (screenshortHelper == nullptr))
536  return false;
537 
538  SDL_Surface *screenshot = nullptr;
539 
540  if (!config.getBoolValue("showip") && (gui != nullptr))
541  {
542  mainGraphics->setSecure(true);
544  gui->draw();
545  addWatermark();
546  screenshot = screenshortHelper->getScreenshot();
547  mainGraphics->setSecure(false);
548  }
549  else
550  {
551  addWatermark();
552  screenshot = screenshortHelper->getScreenshot();
553  }
554 
555  if (screenshot == nullptr)
556  return false;
557 
558  return saveScreenshot(screenshot, prefix);
559 }
Gui * gui
Definition: gui.cpp:110
Configuration config
static void addWatermark()
Definition: game.cpp:518
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:561
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 1058 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().

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

◆ handleMove()

void Game::handleMove ( )

Definition at line 918 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().

919 {
920  BLOCK_START("Game::handleMove")
921  if (localPlayer == nullptr)
922  {
923  BLOCK_END("Game::handleMove")
924  return;
925  }
926 
927  // Moving player around
928  if ((chatWindow != nullptr) &&
929  (quitDialog == nullptr) &&
930  localPlayer->canMove() &&
931  !chatWindow->isInputFocused() &&
932  !InventoryWindow::isAnyInputFocused() &&
933  !popupMenu->isPopupVisible())
934  {
935  NpcDialog *const dialog = NpcDialog::getActive();
936  if (dialog != nullptr)
937  {
938  BLOCK_END("Game::handleMove")
939  return;
940  }
941 
942  // Ignore input if either "ignore" key is pressed
943  // Stops the character moving about if the user's window manager
944  // uses "ignore+arrow key" to switch virtual desktops.
945  if (inputManager.isActionActive(InputAction::IGNORE_INPUT_1) ||
946  inputManager.isActionActive(InputAction::IGNORE_INPUT_2))
947  {
948  BLOCK_END("Game::handleMove")
949  return;
950  }
951 
952  unsigned char direction = 0;
953 
954  // Translate pressed keys to movement and direction
955  if (inputManager.isActionActive(InputAction::MOVE_UP) ||
956  ((joystick != nullptr) && joystick->isUp()))
957  {
958  direction |= BeingDirection::UP;
959  setValidSpeed();
961  }
963  ((joystick != nullptr) && joystick->isDown()))
964  {
965  direction |= BeingDirection::DOWN;
966  setValidSpeed();
968  }
969 
971  ((joystick != nullptr) && joystick->isLeft()))
972  {
973  direction |= BeingDirection::LEFT;
974  setValidSpeed();
976  }
978  ((joystick != nullptr) && joystick->isRight()))
979  {
980  direction |= BeingDirection::RIGHT;
981  setValidSpeed();
983  }
985  {
986  direction = localPlayer->getDirection();
987  setValidSpeed();
989  }
990 
995  || direction == 0)
996  {
997  moveInDirection(direction);
998  }
999  }
1000  BLOCK_END("Game::handleMove")
1001 }
ChatWindow * chatWindow
Definition: chatwindow.cpp:89
void setValidSpeed()
Definition: game.cpp:1269
Joystick * joystick
Definition: joystick.cpp:42
QuitDialog * quitDialog
Definition: game.cpp:156
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:493
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:1003

◆ 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 661 of file game.cpp.

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

Referenced by clearInstance().

662 {
663  BLOCK_START("Game::logic")
664  handleInput();
665 
666  // Handle all necessary game logic
667  if (actorManager != nullptr)
668  actorManager->logic();
669  if (particleEngine != nullptr)
671  if (mCurrentMap != nullptr)
672  mCurrentMap->update(1);
673 
674  BLOCK_END("Game::logic")
675 }
void handleInput()
Definition: game.cpp:1058
#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:661
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 1003 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().

1004 {
1005  if (viewport == nullptr)
1006  return;
1007 
1008  if (settings.cameraMode == 0u)
1009  {
1010  if (localPlayer != nullptr)
1011  localPlayer->specialMove(direction);
1012  }
1013  else
1014  {
1015  int dx = 0;
1016  int dy = 0;
1017  if ((direction & BeingDirection::LEFT) != 0)
1018  dx = -5;
1019  else if ((direction & BeingDirection::RIGHT) != 0)
1020  dx = 5;
1021 
1022  if ((direction & BeingDirection::UP) != 0)
1023  dy = -5;
1024  else if ((direction & BeingDirection::DOWN) != 0)
1025  dy = 5;
1026  viewport->moveCamera(dx, dy);
1027  }
1028 }
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 887 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().

888 {
889  if (!mAdjustPerfomance)
890  return;
891 
893  switch (mAdjustLevel)
894  {
895  case 1:
896  config.setValue("beingopacity",
897  config.getBoolValue("beingopacity"));
898  break;
899  case 2:
900  config.setValue("beingopacity",
901  config.getBoolValue("beingopacity"));
903  "particleEmitterSkip") + 1;
904  break;
905  default:
906  case 3:
907  config.setValue("beingopacity",
908  config.getBoolValue("beingopacity"));
910  "particleEmitterSkip") + 1;
911  config.setValue("alphaCache",
912  config.getBoolValue("alphaCache"));
913  break;
914  }
915  mAdjustLevel = 0;
916 }
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:160

◆ saveScreenshot()

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

Definition at line 561 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().

563 {
564  std::string screenshotDirectory = settings.screenshotDir;
565  if (mkdir_r(screenshotDirectory.c_str()) != 0)
566  {
567  logger->log("Directory %s doesn't exist and can't be created! "
568  "Setting screenshot directory to home.",
569  screenshotDirectory.c_str());
570  screenshotDirectory = std::string(VirtFs::getUserDir());
571  }
572 
573  // Search for an unused screenshot name
574  std::stringstream filename;
575  std::fstream testExists;
576 
577  time_t rawtime;
578  char buffer [100];
579  time(&rawtime);
580  struct tm *const timeinfo = localtime(&rawtime);
581  strftime(buffer, 99, "%Y-%m-%d_%H-%M-%S", timeinfo);
582 
583  const std::string serverName = settings.serverName;
584  std::string screenShortStr;
585  if (prefix.empty())
586  {
587  if (serverName.empty())
588  {
589  screenShortStr = strprintf("%s_Screenshot_%s_",
590  branding.getValue("appName", "ManaPlus").c_str(),
591  buffer);
592  }
593  else
594  {
595  screenShortStr = strprintf("%s_Screenshot_%s_%s_",
596  branding.getValue("appName", "ManaPlus").c_str(),
597  serverName.c_str(), buffer);
598  }
599 
600  bool found = false;
601  static unsigned int screenshotCount = 0;
602  do
603  {
604  screenshotCount++;
605  filename.str("");
606  filename << screenshotDirectory << "/";
607  filename << screenShortStr << screenshotCount << ".png";
608  testExists.open(filename.str().c_str(), std::ios::in);
609  found = !testExists.is_open();
610  testExists.close();
611  }
612  while (!found);
613  }
614  else
615  {
616  screenShortStr = prefix;
617  filename.str("");
618  filename << screenshotDirectory << "/";
619  filename << screenShortStr;
620  }
621 
622  const std::string fileNameStr = filename.str();
623  const bool success = PngLib::writePNG(screenshot, fileNameStr);
624 #ifdef __native_client__
625  std::string nacScreenshotlDir = fileNameStr;
626  cutFirst(nacScreenshotlDir, "/persistent");
627  naclPostMessage("copy-from-persistent", nacScreenshotlDir);
628  logger->log("nacl screenshot path: " + nacScreenshotlDir);
629 #endif // __native_client__
630 
631  if (success)
632  {
633  if (localChatTab != nullptr)
634  {
635  // TRANSLATORS: save file message
636  std::string str = strprintf(_("Screenshot saved as %s"),
637  fileNameStr.c_str());
638  localChatTab->chatLog(str,
642  }
643  }
644  else
645  {
646  if (localChatTab != nullptr)
647  {
648  // TRANSLATORS: save file message
649  localChatTab->chatLog(_("Saving screenshot failed!"),
653  }
654  logger->log1("Error: could not save screenshot.");
655  }
656 
658  return success;
659 }
Configuration branding
#define _(s)
Definition: gettext.h:34
void log1(const char *const log_text)
Definition: logger.cpp:233
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:88
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:264

◆ 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 677 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().

678 {
679  BLOCK_START("Game::slowLogic")
680  if (localPlayer != nullptr)
682  const time_t time = cur_time;
683  if (mTime != time)
684  {
685  if (valTest(Updated))
686  mValidSpeed = false;
687 
688  mTime = time + 1;
689  if (debugWindow != nullptr)
691  if (killStats != nullptr)
692  killStats->update();
693  if (socialWindow != nullptr)
695  if (whoIsOnline != nullptr)
698  if (killStats != nullptr)
700 
701  if (time > mTime2 || mTime2 - time > 10)
702  {
703  mTime2 = time + 10;
706  }
707  if (effectManager != nullptr)
708  effectManager->logic();
709  }
710 
713 
714 #ifdef TMWA_SUPPORT
715  if (shopWindow != nullptr)
717  if (guildManager != nullptr)
719 #endif // TMWA_SUPPORT
720 
721  if (skillDialog != nullptr)
723 
725 
726  // Handle network stuff
727  if (!gameHandler->isConnected())
728  {
730  return; // Not a problem here
731 
732  if (client->getState() != State::ERROR)
733  {
734  if (disconnectedDialog == nullptr)
735  {
736  // TRANSLATORS: error message text
737  errorMessage = _("The connection to the server was lost.");
739  // TRANSLATORS: error message header
740  _("Network Error"),
741  errorMessage,
742  Modal_false);
745  }
746  }
747 
748  if ((viewport != nullptr) && !errorMessage.empty())
749  {
750  const Map *const map = viewport->getMap();
751  if (map != nullptr)
752  map->saveExtraLayer();
753  }
756  mNextAdjustTime = cur_time + adjustDelay;
757  if (client->getState() != State::ERROR)
758  errorMessage.clear();
759  }
760  else
761  {
762  if (gameHandler->mustPing()
763  && get_elapsed_time1(mPing) > 3000)
764  {
765  mPing = tick_time;
767  }
768 
769  if (mAdjustPerfomance)
771  if (disconnectedDialog != nullptr)
772  {
774  disconnectedDialog = nullptr;
775  }
776  }
777  BLOCK_END("Game::slowLogic")
778 }
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:117
Configuration serverConfig
static void update()
void slowLogic()
Definition: debugwindow.cpp:94
void slowLogic()
Definition: game.cpp:677
KillStats * killStats
Definition: killstats.cpp:45
time_t mNextAdjustTime
Definition: game.h:146
std::string errorMessage
Definition: client.cpp:115
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:71
virtual void ping(const int tick) const =0
virtual void scheduleDelete()
Definition: window.cpp:826
void saveExtraLayer() const
Definition: map.cpp:1221
ShopWindow * shopWindow
Definition: shopwindow.cpp:100
SkillDialog * skillDialog
Definition: skilldialog.cpp:65
static void reReadConfig()
Definition: being.cpp:3431
void adjustPerfomance()
Definition: game.cpp:780
StateT getState() const
Definition: client.h:68
virtual bool mustPing() const =0
Window * disconnectedDialog
Definition: game.cpp:157
virtual bool isConnected() const =0
void recalcStats()
Definition: killstats.cpp:311
time_t mTime
Definition: game.h:151
int mPing
Definition: game.h:150
void update()
Definition: killstats.cpp:365
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:87
EffectManager * effectManager
Viewport * viewport
Definition: viewport.cpp:35
const time_t adjustDelay
Definition: game.cpp:160

◆ updateFrameRate()

void Game::updateFrameRate ( int  fpsLimit)

Definition at line 1030 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().

1031 {
1032  if (fpsLimit == 0)
1033  {
1034  if (settings.awayMode)
1035  {
1038  {
1039  fpsLimit = config.getIntValue("fpslimit");
1040  }
1041  else
1042  {
1043  fpsLimit = config.getIntValue("altfpslimit");
1044  }
1045  }
1046  else
1047  {
1048  fpsLimit = config.getIntValue("fpslimit");
1049  }
1050  }
1051  WindowManager::setFramerate(fpsLimit);
1053 }
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:160

◆ updateHistory()

void Game::updateHistory ( const SDL_Event &  event)

Definition at line 1188 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().

1189 {
1190  if ((localPlayer == nullptr) || (settings.attackType == 0u))
1191  return;
1192 
1193  if (CAST_S32(event.key.keysym.sym) != -1)
1194  {
1195  bool old = false;
1196 
1197  const InputActionT key = KeyboardConfig::getKeyIndex(event, 1);
1198  const time_t time = cur_time;
1199  int idx = -1;
1200  for (int f = 0; f < MAX_LASTKEYS; f ++)
1201  {
1202  LastKey &lastKey = mLastKeys[f];
1203  if (lastKey.key == key)
1204  {
1205  idx = f;
1206  old = true;
1207  break;
1208  }
1209  else if (idx >= 0 && lastKey.time < mLastKeys[idx].time)
1210  {
1211  idx = f;
1212  }
1213  }
1214  if (idx < 0)
1215  {
1216  idx = 0;
1217  for (int f = 0; f < MAX_LASTKEYS; f ++)
1218  {
1219  LastKey &lastKey = mLastKeys[f];
1220  if (lastKey.key == InputAction::NO_VALUE ||
1221  lastKey.time < mLastKeys[idx].time)
1222  {
1223  idx = f;
1224  }
1225  }
1226  }
1227 
1228  if (idx < 0)
1229  idx = 0;
1230 
1231  LastKey &keyIdx = mLastKeys[idx];
1232  if (!old)
1233  {
1234  keyIdx.time = time;
1235  keyIdx.key = key;
1236  keyIdx.cnt = 0;
1237  }
1238  else
1239  {
1240  keyIdx.cnt++;
1241  }
1242  }
1243 }
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:715
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 1285 of file game.cpp.

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

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

1286 {
1287  if (viewport != nullptr)
1288  viewport->setSize(width, height);
1289  if (windowMenu != nullptr)
1290  windowMenu->setPosition(width - windowMenu->getWidth(), 0);
1291 }
void setSize(const int width, const int height)
Definition: widget.cpp:366
int getWidth() const
Definition: widget.h:220
WindowMenu * windowMenu
Definition: windowmenu.cpp:50
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: