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

404  :
405  mCurrentMap(nullptr),
406  mMapName(""),
407  mValidSpeed(true),
409  mAdjustLevel(0),
410  mAdjustPerfomance(config.getBoolValue("adjustPerfomance")),
411  mLowerCounter(0),
412  mPing(0),
413  mTime(cur_time + 1),
414  mTime2(cur_time + 10)
415 {
416  touchManager.setInGame(true);
417 
418 // assert(!mInstance);
419  if (mInstance != nullptr)
420  logger->log("error: double game creation");
421  mInstance = this;
422 
423  config.incValue("gamecount");
424 
425  disconnectedDialog = nullptr;
426 
427  // Create the viewport
428  viewport = new Viewport;
431 
433 
434  BasicContainer2 *const top = static_cast<BasicContainer2*>(gui->getTop());
435  if (top != nullptr)
436  top->add(viewport);
438 
441  config.getBoolValue("enableDelayedAnimations"));
442 
444  config.getBoolValue("enableCompoundSpriteDelay"));
445 
447  windowMenu = new WindowMenu(nullptr);
448 
449  if (windowContainer != nullptr)
451 
452 #ifdef USE_OPENGL
454 #endif // USE_OPENGL
455 
456  initEngines();
457 
460 
461  // Initialize beings
462  if (actorManager != nullptr)
464 
466 
467  if (setupWindow != nullptr)
468  setupWindow->setInGame(true);
469  clearKeysArray();
470 
471 #ifdef TMWA_SUPPORT
472  if (guildManager != nullptr && GuildManager::getEnableGuildBot())
474 #endif // TMWA_SUPPORT
475 
477  "disableLoggingInGame");
478 }
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:450
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:166
Map * mCurrentMap
Definition: game.h:142
Window * disconnectedDialog
Definition: game.cpp:158
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:194
MailWindow * mailWindow
Definition: mailwindow.cpp:53
void log(const char *const log_text,...)
Definition: logger.cpp:264
Net::GameHandler * gameHandler
Definition: net.cpp:88
void incValue(const std::string &key)
void clearKeysArray()
Definition: game.cpp:1278
static void setEnableCache(const bool b)
ActorManager * actorManager
Viewport * viewport
Definition: viewport.cpp:35
const time_t adjustDelay
Definition: game.cpp:161

◆ ~Game()

Game::~Game ( )

Destructor, cleans up the game.

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

481 {
482 #ifdef USE_OPENGL
484 #endif // USE_OPENGL
485 
487  touchManager.setInGame(false);
488  config.write();
492 
494 
498  if (effectManager != nullptr)
499  effectManager->clear();
504 #ifdef TMWA_SUPPORT
506 #endif // TMWA_SUPPORT
507 #ifdef USE_MUMBLE
508  delete2(mumbleManager)
509 #endif // USE_MUMBLE
510 
513 
515  mInstance = nullptr;
517 }
void gameDestroyed()
Definition: playerinfo.cpp:461
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:348
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:888

Member Function Documentation

◆ addWatermark()

void Game::addWatermark ( )
static

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

520 {
521  if ((boldFont == nullptr) || !config.getBoolValue("addwatermark"))
522  return;
523 
524  const Color &color1 = theme->getColor(ThemeColorId::TEXT, 255);
525  const Color &color2 = theme->getColor(ThemeColorId::TEXT_OUTLINE, 255);
526 
528  color1,
529  color2,
531  100, 50);
532 }
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 781 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().

782 {
783  FUNC_BLOCK("Game::adjustPerfomance", 1)
784  const time_t time = cur_time;
786  {
788  }
789  else if (mNextAdjustTime < time)
790  {
792 
793  if (mAdjustLevel > 3 ||
794  localPlayer == nullptr ||
797  {
798  return;
799  }
800 
801  int maxFps = WindowManager::getFramerate();
802  if (maxFps != config.getIntValue("fpslimit"))
803  return;
804 
805  if (maxFps == 0)
806  maxFps = 30;
807  else if (maxFps < 10)
808  return;
809 
810  if (fps < maxFps - 10)
811  {
812  if (mLowerCounter < 2)
813  {
814  mLowerCounter ++;
816  return;
817  }
818  mLowerCounter = 0;
819  mAdjustLevel ++;
820  switch (mAdjustLevel)
821  {
822  case 1:
823  {
824  if (config.getBoolValue("beingopacity"))
825  {
826  config.setValue("beingopacity", false);
827  config.setSilent("beingopacity", true);
828  if (localChatTab != nullptr)
829  {
831  // TRANSLATORS: auto adjust settings message
832  _("Auto disable Show beings transparency"),
836  }
837  }
838  else
839  {
840  mNextAdjustTime = time + 1;
841  mLowerCounter = 2;
842  }
843  break;
844  }
845  case 2:
847  {
849  if (localChatTab != nullptr)
850  {
852  // TRANSLATORS: auto adjust settings message
853  _("Auto lower Particle effects"),
857  }
858  }
859  else
860  {
861  mNextAdjustTime = time + 1;
862  mLowerCounter = 2;
863  }
864  break;
865  case 3:
866  if (!config.getBoolValue("alphaCache"))
867  {
868  config.setValue("alphaCache", true);
869  config.setSilent("alphaCache", false);
870  if (localChatTab != nullptr)
871  {
873  // TRANSLATORS: auto adjust settings message
874  _("Auto enable opacity cache"),
878  }
879  }
880  break;
881  default:
882  break;
883  }
884  }
885  }
886 }
#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:161
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 1092 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(), Perf::init(), 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(), skipPerfFrames, socialWindow, soundManager, and viewport.

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

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

◆ checkKeys()

void Game::checkKeys ( )

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

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

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

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

1279 {
1280  for (int f = 0; f < MAX_LASTKEYS; f ++)
1281  {
1282  mLastKeys[f].time = 0;
1284  mLastKeys[f].cnt = 0;
1285  }
1286 }
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 534 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().

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

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

◆ handleMove()

void Game::handleMove ( )

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

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

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

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

Referenced by clearInstance().

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

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

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

◆ saveScreenshot()

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

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

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

679 {
680  BLOCK_START("Game::slowLogic")
681  if (localPlayer != nullptr)
683  const time_t time = cur_time;
684  if (mTime != time)
685  {
686  if (valTest(Updated))
687  mValidSpeed = false;
688 
689  mTime = time + 1;
690  if (debugWindow != nullptr)
692  if (killStats != nullptr)
693  killStats->update();
694  if (socialWindow != nullptr)
696  if (whoIsOnline != nullptr)
699  if (killStats != nullptr)
701 
702  if (time > mTime2 || mTime2 - time > 10)
703  {
704  mTime2 = time + 10;
707  }
708  if (effectManager != nullptr)
709  effectManager->logic();
710  }
711 
714 
715 #ifdef TMWA_SUPPORT
716  if (shopWindow != nullptr)
718  if (guildManager != nullptr)
720 #endif // TMWA_SUPPORT
721 
722  if (skillDialog != nullptr)
724 
726 
727  // Handle network stuff
728  if (!gameHandler->isConnected())
729  {
731  return; // Not a problem here
732 
733  if (client->getState() != State::ERROR)
734  {
735  if (disconnectedDialog == nullptr)
736  {
737  // TRANSLATORS: error message text
738  errorMessage = _("The connection to the server was lost.");
740  // TRANSLATORS: error message header
741  _("Network Error"),
742  errorMessage,
743  Modal_false);
746  }
747  }
748 
749  if ((viewport != nullptr) && !errorMessage.empty())
750  {
751  const Map *const map = viewport->getMap();
752  if (map != nullptr)
753  map->saveExtraLayer();
754  }
757  mNextAdjustTime = cur_time + adjustDelay;
758  if (client->getState() != State::ERROR)
759  errorMessage.clear();
760  }
761  else
762  {
763  if (gameHandler->mustPing()
764  && get_elapsed_time1(mPing) > 3000)
765  {
766  mPing = tick_time;
768  }
769 
770  if (mAdjustPerfomance)
772  if (disconnectedDialog != nullptr)
773  {
775  disconnectedDialog = nullptr;
776  }
777  }
778  BLOCK_END("Game::slowLogic")
779 }
DebugWindow * debugWindow
Definition: debugwindow.cpp:42
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()
void slowLogic()
Definition: game.cpp:678
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:830
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:781
StateT getState() const
Definition: client.h:68
virtual bool mustPing() const =0
Window * disconnectedDialog
Definition: game.cpp:158
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:88
EffectManager * effectManager
Viewport * viewport
Definition: viewport.cpp:35
const time_t adjustDelay
Definition: game.cpp:161

◆ updateFrameRate()

void Game::updateFrameRate ( int  fpsLimit)

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

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

◆ updateHistory()

void Game::updateHistory ( const SDL_Event &  event)

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

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

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

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

1289 {
1290  if (viewport != nullptr)
1291  viewport->setSize(width, height);
1292  if (windowMenu != nullptr)
1293  windowMenu->setPosition(width - windowMenu->getWidth(), 0);
1294 }
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: