From c88734cc2b8a0785c23531ce70bf703887aa0c4b Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Fri, 23 Aug 2013 23:17:19 +0300 Subject: remove most static methods from Client. --- src/actionmanager.cpp | 8 ++++---- src/actorspritemanager.cpp | 16 ++++++++-------- src/being.cpp | 2 +- src/client.cpp | 43 ++++++++++++------------------------------- src/client.h | 21 ++++++++------------- src/dropshortcut.cpp | 4 ++-- src/game.cpp | 8 ++++---- src/gui/npcdialog.cpp | 10 +++++----- src/gui/whoisonline.cpp | 4 ++-- src/gui/widgets/window.cpp | 2 +- src/guildmanager.cpp | 6 +++--- src/localplayer.cpp | 42 +++++++++++++++++++++--------------------- 12 files changed, 71 insertions(+), 95 deletions(-) (limited to 'src') diff --git a/src/actionmanager.cpp b/src/actionmanager.cpp index 7a562c96e..b0018f670 100644 --- a/src/actionmanager.cpp +++ b/src/actionmanager.cpp @@ -873,7 +873,7 @@ impHandler0(directUp) { if (player_node->getDirection() != Being::UP) { -// if (Client::limitPackets(PACKET_DIRECTION)) +// if (client->limitPackets(PACKET_DIRECTION)) { player_node->setDirection(Being::UP); if (Net::getPlayerHandler()) @@ -891,7 +891,7 @@ impHandler0(directDown) { if (player_node->getDirection() != Being::DOWN) { -// if (Client::limitPackets(PACKET_DIRECTION)) +// if (client->limitPackets(PACKET_DIRECTION)) { player_node->setDirection(Being::DOWN); if (Net::getPlayerHandler()) @@ -909,7 +909,7 @@ impHandler0(directLeft) { if (player_node->getDirection() != Being::LEFT) { -// if (Client::limitPackets(PACKET_DIRECTION)) +// if (client->limitPackets(PACKET_DIRECTION)) { player_node->setDirection(Being::LEFT); if (Net::getPlayerHandler()) @@ -927,7 +927,7 @@ impHandler0(directRight) { if (player_node->getDirection() != Being::RIGHT) { -// if (Client::limitPackets(PACKET_DIRECTION)) +// if (client->limitPackets(PACKET_DIRECTION)) { player_node->setDirection(Being::RIGHT); if (Net::getPlayerHandler()) diff --git a/src/actorspritemanager.cpp b/src/actorspritemanager.cpp index ed76f34e2..cd2a62e04 100644 --- a/src/actorspritemanager.cpp +++ b/src/actorspritemanager.cpp @@ -557,7 +557,7 @@ bool ActorSpriteManager::pickUpAll(const int x1, const int y1, } } } - else if (Client::checkPackets(PACKET_PICKUP)) + else if (client->checkPackets(PACKET_PICKUP)) { FloorItem *item = nullptr; unsigned cnt = 65535; @@ -1137,7 +1137,7 @@ void ActorSpriteManager::heal(const Being *const target) const && PlayerInfo::getAttribute(PlayerInfo::HP) != PlayerInfo::getAttribute(PlayerInfo::MAX_HP)) { - if (!Client::limitPackets(PACKET_CHAT)) + if (!client->limitPackets(PACKET_CHAT)) return; chatWindow->localChatInput(mSpellHeal1); } @@ -1150,7 +1150,7 @@ void ActorSpriteManager::heal(const Being *const target) const { if (target && target->getType() != Being::MONSTER) { - if (!Client::limitPackets(PACKET_CHAT)) + if (!client->limitPackets(PACKET_CHAT)) return; chatWindow->localChatInput(mSpellHeal1 + " " + target->getName()); @@ -1158,7 +1158,7 @@ void ActorSpriteManager::heal(const Being *const target) const else if (PlayerInfo::getAttribute(PlayerInfo::HP) != PlayerInfo::getAttribute(PlayerInfo::MAX_HP)) { - if (!Client::limitPackets(PACKET_CHAT)) + if (!client->limitPackets(PACKET_CHAT)) return; chatWindow->localChatInput(mSpellHeal1); } @@ -1175,7 +1175,7 @@ void ActorSpriteManager::heal(const Being *const target) const if (player_relations.getRelation(target->getName()) != PlayerRelation::ENEMY2) { - if (!Client::limitPackets(PACKET_CHAT)) + if (!client->limitPackets(PACKET_CHAT)) return; chatWindow->localChatInput(mSpellHeal2 + " " + target->getName()); @@ -1183,7 +1183,7 @@ void ActorSpriteManager::heal(const Being *const target) const // target enemy else { - if (!Client::limitPackets(PACKET_CHAT)) + if (!client->limitPackets(PACKET_CHAT)) return; chatWindow->localChatInput(mSpellHeal1); } @@ -1194,7 +1194,7 @@ void ActorSpriteManager::heal(const Being *const target) const && PlayerInfo::getAttribute(PlayerInfo::HP) != PlayerInfo::getAttribute(PlayerInfo::MAX_HP)) { - if (!Client::limitPackets(PACKET_CHAT)) + if (!client->limitPackets(PACKET_CHAT)) return; chatWindow->localChatInput(mSpellHeal1); } @@ -1209,7 +1209,7 @@ void ActorSpriteManager::itenplz() const return; } - if (!Client::limitPackets(PACKET_CHAT)) + if (!client->limitPackets(PACKET_CHAT)) return; chatWindow->localChatInput(mSpellItenplz); diff --git a/src/being.cpp b/src/being.cpp index 1a1ae6477..7003e0de3 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -2171,7 +2171,7 @@ void Being::setGM(const bool gm) void Being::talkTo() const { - if (!Client::limitPackets(PACKET_NPC_TALK)) + if (!client->limitPackets(PACKET_NPC_TALK)) return; Net::getNpcHandler()->talk(mId); diff --git a/src/client.cpp b/src/client.cpp index 6a65fa700..76f12d021 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -264,9 +264,6 @@ class LoginListener final : public gcn::ActionListener } } loginListener; - -Client *Client::mInstance = nullptr; - Client::Client(const Options &options) : gcn::ActionListener(), mOptions(options), @@ -321,8 +318,6 @@ Client::Client(const Options &options) : mNewMessageFlag(false), mLogInput(false) { - mInstance = this; - // Initialize frame limiting mFpsManager.framecount = 0; mFpsManager.rateticks = 0; @@ -881,7 +876,6 @@ void Client::gameClear() delete chatLogger; chatLogger = nullptr; TranslationManager::close(); - mInstance = nullptr; } int Client::testsExec() const @@ -2645,7 +2639,7 @@ void Client::writePacketLimits(const std::string &packetLimitsName) const outPacketFile.close(); } -bool Client::checkPackets(const int type) +bool Client::checkPackets(const int type) const { if (type > PACKET_SIZE) return false; @@ -2653,7 +2647,7 @@ bool Client::checkPackets(const int type) if (!serverConfig.getValueBool("enableBuggyServers", true)) return true; - const PacketLimit &limit = instance()->mPacketLimits[type]; + const PacketLimit &limit = mPacketLimits[type]; const int timeLimit = limit.timeLimit; if (!timeLimit) @@ -2696,7 +2690,7 @@ bool Client::limitPackets(const int type) if (!serverConfig.getValueBool("enableBuggyServers", true)) return true; - PacketLimit &pack = instance()->mPacketLimits[type]; + PacketLimit &pack = mPacketLimits[type]; const int timeLimit = pack.timeLimit; if (!timeLimit) @@ -2735,17 +2729,15 @@ void Client::setFramerate(const int fpsLimit) if (!fpsLimit) return; - Client *const client = instance(); - if (!client->mLimitFps) + if (!mLimitFps) return; SDL_setFramerate(&client->mFpsManager, fpsLimit); } -int Client::getFramerate() +int Client::getFramerate() const { - Client *const client = instance(); - if (!client->mLimitFps) + if (!mLimitFps) return 0; return SDL_getFramerate(&client->mFpsManager); @@ -2760,7 +2752,7 @@ void Client::closeDialogs() SellDialog::closeAll(); } -bool Client::isTmw() +bool Client::isTmw() const { const std::string &name = getServerName(); if (name == "server.themanaworld.org" @@ -2873,16 +2865,11 @@ void Client::applyKeyRepeat() void Client::setIsMinimized(const bool n) { - Client *const client = instance(); - if (!client) - return; - - client->mIsMinimized = n; + mIsMinimized = n; if (!n && client->mNewMessageFlag) { - client->mNewMessageFlag = false; - SDL::SetWindowTitle(mainGraphics->getWindow(), - client->mCaption.c_str()); + mNewMessageFlag = false; + SDL::SetWindowTitle(mainGraphics->getWindow(), mCaption.c_str()); } } @@ -3044,14 +3031,8 @@ void Client::logEvent(const SDL_Event &event) void Client::windowRemoved(const Window *const window) { - Client *const inst = instance(); - if (inst->mCurrentDialog == window) - inst->mCurrentDialog = nullptr; -} - -void Client::updateScreenKeyboard(int height) -{ - instance()->mKeyboardHeight = height; + if (mCurrentDialog == window) + mCurrentDialog = nullptr; } void Client::checkConfigVersion() diff --git a/src/client.h b/src/client.h index 17b0372fa..4b550ad16 100644 --- a/src/client.h +++ b/src/client.h @@ -218,12 +218,6 @@ public: ~Client(); - /** - * Provides access to the client instance. - */ - static Client *instance() A_WARN_UNUSED - { return mInstance; } - void gameInit(); void testsInit(); @@ -304,11 +298,11 @@ public: static void closeDialogs(); - static void setFramerate(const int fpsLimit); + void setFramerate(const int fpsLimit); - static int getFramerate() A_WARN_UNUSED; + int getFramerate() const A_WARN_UNUSED; - bool isTmw() A_WARN_UNUSED; + bool isTmw() const A_WARN_UNUSED; static void applyGrabMode(); @@ -336,17 +330,18 @@ public: void resizeVideo(int width, int height, const bool always = false); - static bool limitPackets(const int type) A_WARN_UNUSED; + bool limitPackets(const int type) A_WARN_UNUSED; - static bool checkPackets(const int type) A_WARN_UNUSED; + bool checkPackets(const int type) const A_WARN_UNUSED; static void logEvent(const SDL_Event &event); PacketLimit mPacketLimits[PACKET_SIZE + 1]; - static void windowRemoved(const Window *const window); + void windowRemoved(const Window *const window); - static void updateScreenKeyboard(int height); + void updateScreenKeyboard(const int height) + { mKeyboardHeight = height; } Window *openErrorDialog(const std::string &header, const std::string &message, diff --git a/src/dropshortcut.cpp b/src/dropshortcut.cpp index 87e992b78..325014823 100644 --- a/src/dropshortcut.cpp +++ b/src/dropshortcut.cpp @@ -98,7 +98,7 @@ void DropShortcut::dropFirst() const if (!player_node) return; - if (!Client::limitPackets(PACKET_DROP)) + if (!client->limitPackets(PACKET_DROP)) return; const int itemId = getItem(0); @@ -143,7 +143,7 @@ void DropShortcut::dropItems(const int cnt) { for (int i = 0; i < sz; i++) { - if (!Client::limitPackets(PACKET_DROP)) + if (!client->limitPackets(PACKET_DROP)) return; if (dropItem()) n++; diff --git a/src/game.cpp b/src/game.cpp index 446b3fbfd..d15c79a36 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -638,7 +638,7 @@ void Game::slowLogic() } } closeDialogs(); - Client::setFramerate(config.getIntValue("fpslimit")); + client->setFramerate(config.getIntValue("fpslimit")); mNextAdjustTime = cur_time + adjustDelay; if (client->getState() != STATE_ERROR) errorMessage.clear(); @@ -681,7 +681,7 @@ void Game::adjustPerfomance() return; } - int maxFps = Client::getFramerate(); + int maxFps = client->getFramerate(); if (maxFps != config.getIntValue("fpslimit")) return; @@ -935,7 +935,7 @@ void Game::handleActive(const SDL_Event &event) fpsLimit = config.getIntValue("fpslimit"); } } - Client::setFramerate(fpsLimit); + client->setFramerate(fpsLimit); mNextAdjustTime = cur_time + adjustDelay; #endif } @@ -992,7 +992,7 @@ void Game::handleInput() break; #ifdef ANDROID case SDL_KEYBOARDSHOW: - Client::updateScreenKeyboard(event.user.code); + client->updateScreenKeyboard(event.user.code); break; #endif default: diff --git a/src/gui/npcdialog.cpp b/src/gui/npcdialog.cpp index 576db564b..bddbbaf46 100644 --- a/src/gui/npcdialog.cpp +++ b/src/gui/npcdialog.cpp @@ -291,7 +291,7 @@ void NpcDialog::action(const gcn::ActionEvent &event) { if (mActionState == NPC_ACTION_NEXT) { - if (!Client::limitPackets(PACKET_NPC_NEXT)) + if (!client->limitPackets(PACKET_NPC_NEXT)) return; nextDialog(); @@ -316,7 +316,7 @@ void NpcDialog::action(const gcn::ActionEvent &event) if (selectedIndex >= static_cast(mItems.size()) || selectedIndex < 0 - || !Client::limitPackets(PACKET_NPC_INPUT)) + || !client->limitPackets(PACKET_NPC_INPUT)) { return; } @@ -329,14 +329,14 @@ void NpcDialog::action(const gcn::ActionEvent &event) } case NPC_INPUT_STRING: { - if (!Client::limitPackets(PACKET_NPC_INPUT)) + if (!client->limitPackets(PACKET_NPC_INPUT)) return; printText = mTextField->getText(); Net::getNpcHandler()->stringInput(mNpcId, printText); } case NPC_INPUT_INTEGER: { - if (!Client::limitPackets(PACKET_NPC_INPUT)) + if (!client->limitPackets(PACKET_NPC_INPUT)) return; printText = strprintf("%d", mIntField->getValue()); Net::getNpcHandler()->integerInput( @@ -344,7 +344,7 @@ void NpcDialog::action(const gcn::ActionEvent &event) } case NPC_INPUT_ITEM: { - if (!Client::limitPackets(PACKET_NPC_INPUT)) + if (!client->limitPackets(PACKET_NPC_INPUT)) return; const Item *const item = mInventory->getItem(0); diff --git a/src/gui/whoisonline.cpp b/src/gui/whoisonline.cpp index d454eb2f3..4b1c638ca 100644 --- a/src/gui/whoisonline.cpp +++ b/src/gui/whoisonline.cpp @@ -593,7 +593,7 @@ void WhoIsOnline::download() } else { - if (Client::limitPackets(PACKET_ONLINELIST)) + if (client->limitPackets(PACKET_ONLINELIST)) Net::getPlayerHandler()->requestOnlineList(); } } @@ -691,7 +691,7 @@ void WhoIsOnline::action(const gcn::ActionEvent &event) } else { - if (Client::limitPackets(PACKET_ONLINELIST)) + if (client->limitPackets(PACKET_ONLINELIST)) { mUpdateTimer = cur_time; Net::getPlayerHandler()->requestOnlineList(); diff --git a/src/gui/widgets/window.cpp b/src/gui/widgets/window.cpp index 485f875fc..38fd315fb 100644 --- a/src/gui/widgets/window.cpp +++ b/src/gui/widgets/window.cpp @@ -168,7 +168,7 @@ Window::~Window() if (gui) gui->removeDragged(this); - Client::windowRemoved(this); + client->windowRemoved(this); saveWindowState(); diff --git a/src/guildmanager.cpp b/src/guildmanager.cpp index 7057aa311..57c687e12 100644 --- a/src/guildmanager.cpp +++ b/src/guildmanager.cpp @@ -136,7 +136,7 @@ void GuildManager::requestGuildInfo() if (!mGotName && !mSentNameRequest) { - if (!Client::limitPackets(PACKET_WHISPER)) + if (!client->limitPackets(PACKET_WHISPER)) return; send("!info " + toString(tick_time)); mRequest = true; @@ -145,7 +145,7 @@ void GuildManager::requestGuildInfo() } else if (!mGotInfo && !mSentInfoRequest && !mSentNameRequest) { - if (!Client::limitPackets(PACKET_WHISPER)) + if (!client->limitPackets(PACKET_WHISPER)) return; send("!getonlineinfo " + toString(tick_time)); mRequest = true; @@ -158,7 +158,7 @@ void GuildManager::slowLogic() { if (!mGotOnlineInfo && mGotName && mRequestTime < cur_time) { - if (!Client::limitPackets(PACKET_WHISPER)) + if (!client->limitPackets(PACKET_WHISPER)) return; send("!getonlineinfo " + toString(tick_time)); mRequest = true; diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 820295570..e642b0048 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -888,7 +888,7 @@ bool LocalPlayer::pickUp(FloorItem *const item) if (!item) return false; - if (!Client::limitPackets(PACKET_PICKUP)) + if (!client->limitPackets(PACKET_PICKUP)) return false; const int dx = item->getTileX() - mX; @@ -1009,7 +1009,7 @@ void LocalPlayer::setDestination(const int x, const int y) Net::getPlayerHandler()->setDestination(x, y, newDir); -// if (Client::limitPackets(PACKET_DIRECTION)) +// if (client->limitPackets(PACKET_DIRECTION)) { setDirection(newDir); Net::getPlayerHandler()->setDirection(newDir); @@ -1143,7 +1143,7 @@ void LocalPlayer::startWalking(const unsigned char dir) { // If the being can't move, just change direction -// if (Client::limitPackets(PACKET_DIRECTION)) +// if (client->limitPackets(PACKET_DIRECTION)) { Net::getPlayerHandler()->setDirection(dir); setDirection(dir); @@ -1186,7 +1186,7 @@ void LocalPlayer::stopWalking(const bool sendToServer) bool LocalPlayer::toggleSit() const { - if (!Client::limitPackets(PACKET_SIT)) + if (!client->limitPackets(PACKET_SIT)) return false; Being::Action newAction; @@ -1213,7 +1213,7 @@ bool LocalPlayer::toggleSit() const bool LocalPlayer::updateSit() const { - if (!Client::limitPackets(PACKET_SIT)) + if (!client->limitPackets(PACKET_SIT)) return false; Net::getPlayerHandler()->changeAction(mAction); @@ -1222,7 +1222,7 @@ bool LocalPlayer::updateSit() const bool LocalPlayer::emote(const uint8_t emotion) { - if (!Client::limitPackets(PACKET_EMOTE)) + if (!client->limitPackets(PACKET_EMOTE)) return false; Net::getPlayerHandler()->emote(emotion); @@ -1309,7 +1309,7 @@ void LocalPlayer::attack(Being *const target, const bool keep, { setAction(ATTACK); - if (!Client::limitPackets(PACKET_ATTACK)) + if (!client->limitPackets(PACKET_ATTACK)) return; if (!dontChangeEquipment) @@ -1328,7 +1328,7 @@ void LocalPlayer::attack(Being *const target, const bool keep, void LocalPlayer::stopAttack(const bool keepAttack) { - if (!Client::limitPackets(PACKET_STOPATTACK)) + if (!client->limitPackets(PACKET_STOPATTACK)) return; if (mServerAttack && mAction == ATTACK) @@ -2432,7 +2432,7 @@ void LocalPlayer::crazyMove1() if (mAction == MOVE) return; -// if (!Client::limitPackets(PACKET_DIRECTION)) +// if (!client->limitPackets(PACKET_DIRECTION)) // return; if (mDirection == Being::UP) @@ -2466,7 +2466,7 @@ void LocalPlayer::crazyMove2() if (mAction == MOVE) return; -// if (!Client::limitPackets(PACKET_DIRECTION)) +// if (!client->limitPackets(PACKET_DIRECTION)) // return; if (mDirection == Being::UP) @@ -2522,7 +2522,7 @@ void LocalPlayer::crazyMove3() break; } -// if (!Client::limitPackets(PACKET_DIRECTION)) +// if (!client->limitPackets(PACKET_DIRECTION)) // return; setDirection(Being::DOWN); @@ -2853,35 +2853,35 @@ void LocalPlayer::crazyMoveA() { case 'd': -// if (Client::limitPackets(PACKET_DIRECTION)) +// if (client->limitPackets(PACKET_DIRECTION)) { setDirection(Being::DOWN); Net::getPlayerHandler()->setDirection(Being::DOWN); } break; case 'u': -// if (Client::limitPackets(PACKET_DIRECTION)) +// if (client->limitPackets(PACKET_DIRECTION)) { setDirection(Being::UP); Net::getPlayerHandler()->setDirection(Being::UP); } break; case 'l': -// if (Client::limitPackets(PACKET_DIRECTION)) +// if (client->limitPackets(PACKET_DIRECTION)) { setDirection(Being::LEFT); Net::getPlayerHandler()->setDirection(Being::LEFT); } break; case 'r': -// if (Client::limitPackets(PACKET_DIRECTION)) +// if (client->limitPackets(PACKET_DIRECTION)) { setDirection(Being::RIGHT); Net::getPlayerHandler()->setDirection(Being::RIGHT); } break; case 'L': -// if (Client::limitPackets(PACKET_DIRECTION)) +// if (client->limitPackets(PACKET_DIRECTION)) { uint8_t dir = 0; switch (mDirection) @@ -2897,7 +2897,7 @@ void LocalPlayer::crazyMoveA() } break; case 'R': -// if (Client::limitPackets(PACKET_DIRECTION)) +// if (client->limitPackets(PACKET_DIRECTION)) { uint8_t dir = 0; switch (mDirection) @@ -2913,7 +2913,7 @@ void LocalPlayer::crazyMoveA() } break; case 'b': -// if (Client::limitPackets(PACKET_DIRECTION)) +// if (client->limitPackets(PACKET_DIRECTION)) { uint8_t dir = 0; switch (mDirection) @@ -3278,7 +3278,7 @@ void LocalPlayer::tryMagic(const std::string &spell, const int baseMagic, { if (PlayerInfo::getAttribute(PlayerInfo::MP) >= mana) { - if (!Client::limitPackets(PACKET_CHAT)) + if (!client->limitPackets(PACKET_CHAT)) return; chatWindow->localChatInput(spell); @@ -3736,7 +3736,7 @@ void LocalPlayer::targetMoved() const if (mTarget && mServerAttack) { logger->log("LocalPlayer::targetMoved0"); - if (!Client::limitPackets(PACKET_ATTACK)) + if (!client->limitPackets(PACKET_ATTACK)) return; logger->log("LocalPlayer::targetMoved"); Net::getPlayerHandler()->attack(mTarget->getId(), mServerAttack); @@ -3910,7 +3910,7 @@ void LocalPlayer::imitateDirection(const Being *const being, if (!mPlayerImitated.empty() && being->getName() == mPlayerImitated) { - if (!Client::limitPackets(PACKET_DIRECTION)) + if (!client->limitPackets(PACKET_DIRECTION)) return; if (mFollowMode == 2) -- cgit v1.2.3-60-g2f50