diff options
Diffstat (limited to 'src')
45 files changed, 117 insertions, 176 deletions
diff --git a/src/actorspritemanager.cpp b/src/actorspritemanager.cpp index 75e3fcc2..5308b3ad 100644 --- a/src/actorspritemanager.cpp +++ b/src/actorspritemanager.cpp @@ -26,32 +26,6 @@ #include <algorithm> -class FindBeingFunctor -{ - public: - bool operator() (ActorSprite *actor) const - { - if (actor->getType() == ActorSprite::FLOOR_ITEM) - return false; - Game *game = Game::instance(); - if (!game) - return false; - - auto *b = static_cast<Being*>(actor); - - uint16_t other_y = y + ((b->getType() == ActorSprite::NPC) ? 1 : 0); - const Vector &pos = b->getPosition(); - return ((int) pos.x / game->getCurrentTileWidth() == x && - ((int) pos.y / game->getCurrentTileHeight() == y - || (int) pos.y / game->getCurrentTileHeight() == other_y) && - b->isAlive() && - (type == ActorSprite::UNKNOWN || b->getType() == type)); - } - - uint16_t x, y; - ActorSprite::Type type; -}; - class PlayerNamesLister : public AutoCompleteLister { void getAutoCompleteList(std::vector<std::string>& names) const override @@ -59,11 +33,11 @@ class PlayerNamesLister : public AutoCompleteLister names.clear(); for (auto actor : actorSpriteManager->getAll()) { - if (actor->getType() == ActorSprite::FLOOR_ITEM) + if (actor->getType() != ActorSprite::PLAYER) continue; auto *being = static_cast<Being *>(actor); - if (being->getType() == Being::PLAYER && !being->getName().empty()) + if (!being->getName().empty()) names.push_back(being->getName()); } } @@ -156,14 +130,30 @@ Being *ActorSpriteManager::findBeing(int id) const Being *ActorSpriteManager::findBeing(int x, int y, ActorSprite::Type type) const { - FindBeingFunctor beingFinder; - beingFinder.x = x; - beingFinder.y = y; - beingFinder.type = type; - - auto it = find_if(mActors.begin(), mActors.end(), beingFinder); + const Game *game = Game::instance(); + if (!game) + return nullptr; - return (it == mActors.end()) ? nullptr : static_cast<Being*>(*it); + const int tileWidth = game->getCurrentTileWidth(); + const int tileHeight = game->getCurrentTileHeight(); + + auto it = find_if(mActors.begin(), mActors.end(), [=] (ActorSprite *actor) { + const auto actorType = actor->getType(); + if (actorType == ActorSprite::FLOOR_ITEM) + return false; + if (type != ActorSprite::UNKNOWN && actorType != type) + return false; + + auto *b = static_cast<Being*>(actor); + uint16_t other_y = y + (actorType == ActorSprite::NPC ? 1 : 0); + const Vector &pos = b->getPosition(); + return ((int) pos.x / tileWidth == x && + ((int) pos.y / tileHeight == y + || (int) pos.y / tileHeight == other_y) && + b->isAlive()); + }); + + return it == mActors.end() ? nullptr : static_cast<Being*>(*it); } Being *ActorSpriteManager::findBeingByPixel(int x, int y) const @@ -336,12 +326,12 @@ bool ActorSpriteManager::hasActorSprite(ActorSprite *someActor) const return mActors.find(someActor) != mActors.end(); } -AutoCompleteLister *ActorSpriteManager::getPlayerNameLister() +AutoCompleteLister *ActorSpriteManager::getPlayerNameLister() const { return mPlayerNames; } -AutoCompleteLister *ActorSpriteManager::getPlayerNPCNameLister() +AutoCompleteLister *ActorSpriteManager::getPlayerNPCNameLister() const { return mPlayerNPCNames; } @@ -350,11 +340,11 @@ void ActorSpriteManager::updatePlayerNames() { for (auto actor : mActors) { - if (actor->getType() == ActorSprite::FLOOR_ITEM) + if (actor->getType() != ActorSprite::PLAYER) continue; auto *being = static_cast<Being *>(actor); - if (being->getType() == ActorSprite::PLAYER && !being->getName().empty()) + if (!being->getName().empty()) being->updateName(); } } diff --git a/src/actorspritemanager.h b/src/actorspritemanager.h index daba3356..7a5f8907 100644 --- a/src/actorspritemanager.h +++ b/src/actorspritemanager.h @@ -156,9 +156,9 @@ class ActorSpriteManager */ void clear(); - AutoCompleteLister *getPlayerNameLister(); + AutoCompleteLister *getPlayerNameLister() const; - AutoCompleteLister *getPlayerNPCNameLister(); + AutoCompleteLister *getPlayerNPCNameLister() const; void updatePlayerNames(); diff --git a/src/animatedsprite.cpp b/src/animatedsprite.cpp index 61f14550..6a5800aa 100644 --- a/src/animatedsprite.cpp +++ b/src/animatedsprite.cpp @@ -69,7 +69,7 @@ bool AnimatedSprite::reset() return ret; } -bool AnimatedSprite::play(std::string spriteAction) +bool AnimatedSprite::play(const std::string &spriteAction) { Action *action = mSprite->getAction(spriteAction); if (!action) @@ -216,7 +216,7 @@ int AnimatedSprite::getOffsetY() const return mFrame ? mFrame->offsetY : 0; } -const Image* AnimatedSprite::getImage() const +const Image *AnimatedSprite::getImage() const { return mFrame ? mFrame->image : nullptr; } diff --git a/src/animatedsprite.h b/src/animatedsprite.h index f2e7a9ff..2c7d589f 100644 --- a/src/animatedsprite.h +++ b/src/animatedsprite.h @@ -32,7 +32,7 @@ struct Frame; /** * Animates a sprite by adding playback state. */ -class AnimatedSprite : public Sprite +class AnimatedSprite final : public Sprite { public: /** @@ -55,7 +55,7 @@ class AnimatedSprite : public Sprite bool reset() override; - bool play(std::string action) override; + bool play(const std::string &action) override; bool update(int time) override; @@ -69,7 +69,7 @@ class AnimatedSprite : public Sprite int getOffsetY() const override; - const Image* getImage() const override; + const Image *getImage() const override; bool setDirection(SpriteDirection direction) override; diff --git a/src/being.cpp b/src/being.cpp index 2d198dbd..985faa83 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -477,20 +477,21 @@ void Being::addGuild(Guild *guild) guild->addMember(mId, mName); if (this == local_player && socialWindow) - { socialWindow->addTab(guild); - } } void Being::removeGuild(int id) { + const auto it = mGuilds.find(id); + assert(it != mGuilds.end()); + + auto [_, guild] = *it; + if (this == local_player && socialWindow) - { - socialWindow->removeTab(mGuilds[id]); - } + socialWindow->removeTab(guild); - mGuilds[id]->removeMember(mId); - mGuilds.erase(id); + guild->removeMember(mId); + mGuilds.erase(it); } Guild *Being::getGuild(const std::string &guildName) const @@ -504,12 +505,9 @@ Guild *Being::getGuild(const std::string &guildName) const Guild *Being::getGuild(int id) const { - std::map<int, Guild*>::const_iterator itr; - itr = mGuilds.find(id); + auto itr = mGuilds.find(id); if (itr != mGuilds.end()) - { return itr->second; - } return nullptr; } @@ -941,8 +939,7 @@ void Being::showName() mDispName = nullptr; std::string mDisplayName(mName); - auto* player = static_cast<Being*>(this); - if (player) + if (getType() == PLAYER) { if (config.getBoolValue("showgender")) { @@ -954,9 +951,9 @@ void Being::showName() // Display the IP when under tmw-Athena (GM only). if (Net::getNetworkType() == ServerType::TMWATHENA && local_player - && local_player->getShowIp() && player->getIp()) + && local_player->getShowIp() && getIp()) { - mDisplayName += strprintf(" %s", ipToString(player->getIp())); + mDisplayName += strprintf(" %s", ipToString(getIp())); } } diff --git a/src/being.h b/src/being.h index dbfd82f1..a1908f94 100644 --- a/src/being.h +++ b/src/being.h @@ -44,7 +44,6 @@ class BeingInfo; class FlashText; class Guild; class ItemInfo; -class Item; class Particle; class Party; struct Position; diff --git a/src/chatlogger.cpp b/src/chatlogger.cpp index 904da133..1fef16bf 100644 --- a/src/chatlogger.cpp +++ b/src/chatlogger.cpp @@ -54,7 +54,7 @@ void ChatLogger::setLogFile(const std::string &logFilename) if (mLogFile.is_open()) mLogFile.close(); - mLogFile.open(logFilename.c_str(), std::ios_base::app); + mLogFile.open(logFilename, std::ios_base::app); if (!mLogFile.is_open()) { diff --git a/src/client.cpp b/src/client.cpp index 8e144e8e..2a854bc0 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -226,12 +226,12 @@ Client::Client(const Options &options): chatLogger = new ChatLogger; if (options.chatLogDir.empty()) - chatLogger->setLogDir(mLocalDataDir + std::string("/logs/")); + chatLogger->setLogDir(mLocalDataDir + "/logs/"); else chatLogger->setLogDir(options.chatLogDir); // Configure logger - logger->setLogFile(mLocalDataDir + std::string("/mana.log")); + logger->setLogFile(mLocalDataDir + "/mana.log"); logger->setLogToStandardOut(config.getBoolValue("logToStandardOut")); // Log the mana version diff --git a/src/compoundsprite.cpp b/src/compoundsprite.cpp index f2621384..115cd0f6 100644 --- a/src/compoundsprite.cpp +++ b/src/compoundsprite.cpp @@ -54,7 +54,7 @@ bool CompoundSprite::reset() return ret; } -bool CompoundSprite::play(std::string action) +bool CompoundSprite::play(const std::string &action) { bool ret = false; diff --git a/src/compoundsprite.h b/src/compoundsprite.h index a309ad3d..7760da8c 100644 --- a/src/compoundsprite.h +++ b/src/compoundsprite.h @@ -34,11 +34,11 @@ public: ~CompoundSprite() override; - bool reset() override; + bool reset() final; - bool play(std::string action) override; + bool play(const std::string &action) final; - bool update(int time) override; + bool update(int time) final; bool draw(Graphics *graphics, int posX, int posY) const override; @@ -54,21 +54,21 @@ public: int getHeight() const override { return mHeight; } - int getOffsetX() const override + int getOffsetX() const final { return mOffsetX; } - int getOffsetY() const override + int getOffsetY() const final { return mOffsetY; } - const Image *getImage() const override; + const Image *getImage() const final; - bool setDirection(SpriteDirection direction) override; + bool setDirection(SpriteDirection direction) final; int getNumberOfLayers() const; virtual bool drawnWhenBehind() const; - int getDuration() const override; + int getDuration() const final; size_t size() const { return mSprites.size(); } diff --git a/src/effectmanager.cpp b/src/effectmanager.cpp index 5de0b872..3f9cf348 100644 --- a/src/effectmanager.cpp +++ b/src/effectmanager.cpp @@ -51,11 +51,10 @@ EffectManager::EffectManager() { if (xmlStrEqual(node->name, BAD_CAST "effect")) { - EffectDescription ed; + EffectDescription &ed = mEffects.emplace_back(); ed.id = XML::getProperty(node, "id", -1); ed.GFX = XML::getProperty(node, "particle", ""); ed.SFX = XML::getProperty(node, "audio", ""); - mEffects.push_back(ed); } } } diff --git a/src/game.cpp b/src/game.cpp index acf2d5a2..a9199817 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -206,9 +206,7 @@ static void destroyGuiWindows() Game *Game::mInstance = nullptr; Game::Game(): - mLastTarget(ActorSprite::UNKNOWN), - mDisconnected(false), - mCurrentMap(nullptr) + mLastTarget(ActorSprite::UNKNOWN) { assert(!mInstance); mInstance = this; @@ -946,8 +944,8 @@ void Game::changeMap(const std::string &mapPath) newMap->initializeParticleEffects(particleEngine); // Start playing new music file when necessary - std::string oldMusic = mCurrentMap ? mCurrentMap->getMusicFile() : ""; - std::string newMusic = newMap ? newMap->getMusicFile() : ""; + std::string oldMusic = mCurrentMap ? mCurrentMap->getMusicFile() : std::string(); + std::string newMusic = newMap ? newMap->getMusicFile() : std::string(); if (newMusic != oldMusic) { if (newMusic.empty()) @@ -84,11 +84,11 @@ class Game private: int mLastTarget; - bool mDisconnected; + bool mDisconnected = false; WindowMenu *mWindowMenu; - Map *mCurrentMap; + Map *mCurrentMap = nullptr; std::string mMapName; static Game *mInstance; diff --git a/src/gui/gui.h b/src/gui/gui.h index e5f5149a..62a0b3aa 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -68,7 +68,7 @@ enum class Cursor { * * \ingroup GUI */ -class Gui : public gcn::Gui, public EventListener +class Gui final : public gcn::Gui, public EventListener { public: Gui(Graphics *screen); diff --git a/src/gui/itemamountwindow.cpp b/src/gui/itemamountwindow.cpp index 285936a5..947b5bdc 100644 --- a/src/gui/itemamountwindow.cpp +++ b/src/gui/itemamountwindow.cpp @@ -79,7 +79,7 @@ void ItemAmountWindow::finish(Item *item, int amount, Usage usage) ItemAmountWindow::ItemAmountWindow(Usage usage, Window *parent, Item *item, int maxRange): - Window("", true, parent), + Window(std::string(), true, parent), mItem(item), mMax(maxRange), mUsage(usage) @@ -103,9 +103,8 @@ ItemAmountWindow::ItemAmountWindow(Usage usage, Window *parent, Item *item, mItemAmountSlide->setActionEventId("slide"); mItemAmountSlide->addActionListener(this); - //Item icon - Image *image = item->getImage(); - mItemIcon = new Icon(image); + // Item icon + mItemIcon = new Icon(item->getImage()); // Buttons auto *minusButton = new Button(_("-"), "dec", this); diff --git a/src/gui/popupmenu.h b/src/gui/popupmenu.h index 640d1d1e..c7199b78 100644 --- a/src/gui/popupmenu.h +++ b/src/gui/popupmenu.h @@ -63,7 +63,7 @@ class PopupMenu : public Popup, public LinkHandler void handleLink(const std::string &link) override; private: - BrowserBox* mBrowserBox; + BrowserBox *mBrowserBox; int mBeingId = 0; FloorItem *mFloorItem = nullptr; diff --git a/src/gui/register.h b/src/gui/register.h index a8f875cb..1996cd47 100644 --- a/src/gui/register.h +++ b/src/gui/register.h @@ -27,8 +27,6 @@ #include <guichan/actionlistener.hpp> #include <guichan/keylistener.hpp> -#include <string> - class LoginData; class OkDialog; diff --git a/src/gui/setup_keyboard.cpp b/src/gui/setup_keyboard.cpp index 0ac64447..ee6e340f 100644 --- a/src/gui/setup_keyboard.cpp +++ b/src/gui/setup_keyboard.cpp @@ -178,8 +178,7 @@ void Setup_Keyboard::refreshAssignedKey(int index) caption = keyboard.getKeyCaption(index) + ": "; else { - const char *temp = SDL_GetKeyName( - (SDL_Scancode) keyboard.getKeyValue(index)); + const char *temp = SDL_GetKeyName(keyboard.getKeyValue(index)); caption = strprintf("%-25s", (keyboard.getKeyCaption(index) + ": ").c_str()) + toString(temp); diff --git a/src/gui/specialswindow.cpp b/src/gui/specialswindow.cpp index 17705b47..340a1e41 100644 --- a/src/gui/specialswindow.cpp +++ b/src/gui/specialswindow.cpp @@ -185,7 +185,6 @@ SpecialEntry::SpecialEntry(SpecialInfo *info) : mIcon->setPosition(1, 0); add(mIcon); - mNameLabel = new Label(info->name); mNameLabel->setPosition(35, 0); add(mNameLabel); diff --git a/src/gui/unregisterdialog.cpp b/src/gui/unregisterdialog.cpp index 787865ae..94f6ef62 100644 --- a/src/gui/unregisterdialog.cpp +++ b/src/gui/unregisterdialog.cpp @@ -28,10 +28,8 @@ #include "gui/register.h" #include "gui/widgets/button.h" -#include "gui/widgets/checkbox.h" #include "gui/widgets/label.h" #include "gui/widgets/passwordfield.h" -#include "gui/widgets/textfield.h" #include "net/logindata.h" #include "net/loginhandler.h" @@ -99,10 +97,9 @@ void UnRegisterDialog::action(const gcn::ActionEvent &event) } else if (event.getId() == "unregister") { - const std::string username = mLoginData->username.c_str(); - const std::string password = mPasswordField->getText(); + const std::string &password = mPasswordField->getText(); logger->log("UnregisterDialog::unregistered, Username is %s", - username.c_str()); + mLoginData->username.c_str()); std::stringstream errorMessage; bool error = false; diff --git a/src/gui/updaterwindow.cpp b/src/gui/updaterwindow.cpp index c8ed66e1..802ce271 100644 --- a/src/gui/updaterwindow.cpp +++ b/src/gui/updaterwindow.cpp @@ -399,8 +399,6 @@ void UpdaterWindow::logic() mProgressBar->setProgress(mDownloadProgress); } - std::string filename = mUpdatesDir + "/" + mCurrentFile; - switch (mDownloadStatus) { case UPDATE_ERROR: diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index b71e6530..10c4bc1a 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -266,12 +266,11 @@ void Viewport::shakeScreen(int intensity) void Viewport::shakeScreen(float x, float y, float decay, unsigned duration) { - ShakeEffect effect; + ShakeEffect &effect = mShakeEffects.emplace_back(); effect.x = x; effect.y = y; effect.decay = decay; effect.duration = duration; - mShakeEffects.push_back(effect); } void Viewport::logic() diff --git a/src/gui/widgets/emoteshortcutcontainer.cpp b/src/gui/widgets/emoteshortcutcontainer.cpp index f4a5449f..4df0c4b9 100644 --- a/src/gui/widgets/emoteshortcutcontainer.cpp +++ b/src/gui/widgets/emoteshortcutcontainer.cpp @@ -75,7 +75,7 @@ void EmoteShortcutContainer::draw(gcn::Graphics *graphics) // Draw emote keyboard shortcut. const char *key = SDL_GetKeyName( - (SDL_Scancode) keyboard.getKeyValue(KeyboardConfig::KEY_EMOTE_1 + i)); + keyboard.getKeyValue(KeyboardConfig::KEY_EMOTE_1 + i)); graphics->setColor(Theme::getThemeColor(Theme::TEXT)); g->drawText(key, emoteX + 2, emoteY + 2, gcn::Graphics::LEFT); diff --git a/src/gui/widgets/itemshortcutcontainer.cpp b/src/gui/widgets/itemshortcutcontainer.cpp index 6c57bd00..e6db7a0b 100644 --- a/src/gui/widgets/itemshortcutcontainer.cpp +++ b/src/gui/widgets/itemshortcutcontainer.cpp @@ -81,7 +81,7 @@ void ItemShortcutContainer::draw(gcn::Graphics *graphics) // Draw item keyboard shortcut. const char *key = SDL_GetKeyName( - (SDL_Scancode) keyboard.getKeyValue(KeyboardConfig::KEY_SHORTCUT_1 + i)); + keyboard.getKeyValue(KeyboardConfig::KEY_SHORTCUT_1 + i)); graphics->setColor(Theme::getThemeColor(Theme::TEXT)); g->drawText(key, itemX + 2, itemY + 2, gcn::Graphics::LEFT); diff --git a/src/gui/widgets/listbox.cpp b/src/gui/widgets/listbox.cpp index 8e2c8311..fc4d8a8e 100644 --- a/src/gui/widgets/listbox.cpp +++ b/src/gui/widgets/listbox.cpp @@ -39,10 +39,6 @@ ListBox::ListBox(gcn::ListModel *listModel): { } -ListBox::~ListBox() -{ -} - void ListBox::updateAlpha() { float alpha = std::max(config.getFloatValue("guialpha"), @@ -81,7 +77,7 @@ void ListBox::draw(gcn::Graphics *graphics) void ListBox::keyPressed(gcn::KeyEvent& keyEvent) { - gcn::Key key = keyEvent.getKey(); + const gcn::Key key = keyEvent.getKey(); if (key.getValue() == Key::ENTER || key.getValue() == Key::SPACE) { diff --git a/src/gui/widgets/listbox.h b/src/gui/widgets/listbox.h index a453b618..d16256b1 100644 --- a/src/gui/widgets/listbox.h +++ b/src/gui/widgets/listbox.h @@ -38,18 +38,6 @@ class ListBox : public gcn::ListBox public: ListBox(gcn::ListModel *listModel); - ~ListBox() override; - - /** - * Sets the font to render the text in. - * - * @param font the font to use. - */ - void setFont(gcn::Font *font) - { - mFont = font; - } - /** * Draws the list box. */ @@ -74,9 +62,6 @@ class ListBox : public gcn::ListBox void mouseDragged(gcn::MouseEvent &event) override; - private: - gcn::Font *mFont; - protected: static float mAlpha; }; diff --git a/src/gui/windowmenu.cpp b/src/gui/windowmenu.cpp index 01194c0b..c6e52ee7 100644 --- a/src/gui/windowmenu.cpp +++ b/src/gui/windowmenu.cpp @@ -162,21 +162,21 @@ void WindowMenu::valueChanged(const gcn::SelectionEvent &event) } } -static std::string createShortcutCaption(const std::string& text, - KeyboardConfig::KeyAction key) +static std::string createShortcutCaption(const std::string &text, + KeyboardConfig::KeyAction key) { std::string caption = gettext(text.c_str()); if (key != KeyboardConfig::KEY_NO_VALUE) { caption += " ("; - caption += SDL_GetKeyName((SDL_Scancode) keyboard.getKeyValue(key)); + caption += SDL_GetKeyName(keyboard.getKeyValue(key)); caption += ")"; } return caption; } -void WindowMenu::addButton(const std::string& text, int &x, int &h, - const std::string& iconPath, +void WindowMenu::addButton(const std::string &text, int &x, int &h, + const std::string &iconPath, KeyboardConfig::KeyAction key) { auto *btn = new Button("", text, this); diff --git a/src/imagesprite.cpp b/src/imagesprite.cpp index c64d9c69..74d9bc43 100644 --- a/src/imagesprite.cpp +++ b/src/imagesprite.cpp @@ -35,7 +35,7 @@ ImageSprite::~ImageSprite() mImage->decRef(); } -bool ImageSprite::draw(Graphics* graphics, int posX, int posY) const +bool ImageSprite::draw(Graphics *graphics, int posX, int posY) const { if (mImage->getAlpha() != mAlpha) mImage->setAlpha(mAlpha); diff --git a/src/imagesprite.h b/src/imagesprite.h index ff18e215..5a04f9ed 100644 --- a/src/imagesprite.h +++ b/src/imagesprite.h @@ -27,7 +27,7 @@ class Graphics; -class ImageSprite : public Sprite +class ImageSprite final : public Sprite { public: ImageSprite(Image *image); @@ -37,7 +37,7 @@ public: bool reset() override { return false; } - bool play(std::string action) override + bool play(const std::string &action) override { return false; } bool update(int time) override diff --git a/src/inventory.cpp b/src/inventory.cpp index 2de03431..e689f8bb 100644 --- a/src/inventory.cpp +++ b/src/inventory.cpp @@ -36,8 +36,7 @@ static bool slotUsed(const Item *item) Inventory::Inventory(Type type, int size): mType(type), - mSize(size == -1 ? Net::getInventoryHandler()->getSize(type) : size), - mUsed(0) + mSize(size == -1 ? Net::getInventoryHandler()->getSize(type) : size) { mItems = new Item*[mSize]; std::fill_n(mItems, mSize, (Item*) nullptr); diff --git a/src/inventory.h b/src/inventory.h index 891a0d7b..7aea3013 100644 --- a/src/inventory.h +++ b/src/inventory.h @@ -142,7 +142,7 @@ class Inventory Type mType; Item **mItems; /**< The holder of items */ int mSize; /**< The max number of inventory items */ - int mUsed; /**< THe number of slots in use */ + int mUsed = 0; /**< THe number of slots in use */ }; #endif // INVENTORY_H diff --git a/src/itemshortcut.h b/src/itemshortcut.h index 3d067641..620973b6 100644 --- a/src/itemshortcut.h +++ b/src/itemshortcut.h @@ -24,8 +24,6 @@ #define SHORTCUT_ITEMS 12 -class Item; - /** * The class which keeps track of the item shortcuts. */ diff --git a/src/localplayer.h b/src/localplayer.h index 0013a471..aa89b3fb 100644 --- a/src/localplayer.h +++ b/src/localplayer.h @@ -31,7 +31,6 @@ class ChatTab; class FloorItem; class ImageSet; -class Item; class Map; class OkDialog; diff --git a/src/log.cpp b/src/log.cpp index 6921750e..9a5ebe8a 100644 --- a/src/log.cpp +++ b/src/log.cpp @@ -34,7 +34,7 @@ Logger::~Logger() = default; void Logger::setLogFile(const std::string &logFilename) { - mLogFile.open(logFilename.c_str(), std::ios_base::trunc); + mLogFile.open(logFilename, std::ios_base::trunc); if (!mLogFile.is_open()) { diff --git a/src/map.cpp b/src/map.cpp index 368b4e2a..77f9feb8 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -235,26 +235,22 @@ Map::~Map() } delete_all(mLayers); delete_all(mTilesets); - delete_all(mForegrounds); - delete_all(mBackgrounds); } void Map::initializeAmbientLayers() { ResourceManager *resman = ResourceManager::getInstance(); - auto addAmbientLayer = [=](const std::string &name, std::list<AmbientLayer*> &list) + auto addAmbientLayer = [=](const std::string &name, std::vector<AmbientLayer> &list) { if (Image *img = resman->getImage(getProperty(name + "image"))) { - auto ambientLayer = new AmbientLayer(img); - ambientLayer->mParallax = getFloatProperty(name + "parallax"); - ambientLayer->mSpeedX = getFloatProperty(name + "scrollX"); - ambientLayer->mSpeedY = getFloatProperty(name + "scrollY"); - ambientLayer->mMask = getIntProperty(name + "mask", 1); - ambientLayer->mKeepRatio = getBoolProperty(name + "keepratio"); - - list.push_back(ambientLayer); + auto &ambientLayer = list.emplace_back(img); + ambientLayer.mParallax = getFloatProperty(name + "parallax"); + ambientLayer.mSpeedX = getFloatProperty(name + "scrollX"); + ambientLayer.mSpeedY = getFloatProperty(name + "scrollY"); + ambientLayer.mMask = getIntProperty(name + "mask", 1); + ambientLayer.mKeepRatio = getBoolProperty(name + "keepratio"); // The AmbientLayer takes control over the image. img->decRef(); @@ -456,17 +452,17 @@ void Map::updateAmbientLayers(float scrollX, float scrollY) for (auto &background : mBackgrounds) { - if ((background->mMask & mMask) == 0) + if ((background.mMask & mMask) == 0) continue; - background->update(timePassed, dx, dy); + background.update(timePassed, dx, dy); } for (auto &foreground : mForegrounds) { - if ((foreground->mMask & mMask) == 0) + if ((foreground.mMask & mMask) == 0) continue; - foreground->update(timePassed, dx, dy); + foreground.update(timePassed, dx, dy); } mLastScrollX = scrollX; mLastScrollY = scrollY; @@ -480,7 +476,7 @@ void Map::drawAmbientLayers(Graphics *graphics, LayerType type, if (detail <= 0 && type != BACKGROUND_LAYERS) return; // find out which layer list to draw - std::list<AmbientLayer*> *layers; + std::vector<AmbientLayer> *layers; switch (type) { case FOREGROUND_LAYERS: @@ -499,10 +495,10 @@ void Map::drawAmbientLayers(Graphics *graphics, LayerType type, // Draw overlays for (auto &layer : *layers) { - if ((layer->mMask & mMask) == 0) + if ((layer.mMask & mMask) == 0) continue; - layer->draw(graphics); + layer.draw(graphics); // Detail 1: only one overlay, higher: all overlays if (detail == 1) @@ -400,8 +400,8 @@ class Map : public Properties unsigned mOnClosedList, mOnOpenList; // Overlay data - std::list<AmbientLayer*> mBackgrounds; - std::list<AmbientLayer*> mForegrounds; + std::vector<AmbientLayer> mBackgrounds; + std::vector<AmbientLayer> mForegrounds; float mLastScrollX; float mLastScrollY; diff --git a/src/net/manaserv/guildhandler.cpp b/src/net/manaserv/guildhandler.cpp index 398e9c62..1d927e30 100644 --- a/src/net/manaserv/guildhandler.cpp +++ b/src/net/manaserv/guildhandler.cpp @@ -237,8 +237,7 @@ void GuildHandler::handleMessage(MessageIn &msg) // Must remove tab first, as it wont find the guild // name after its removed from the player int guildId = msg.readInt16(); - Guild *guild = local_player->getGuild(guildId); - if (guild) + if (Guild *guild = local_player->getGuild(guildId)) { Channel *channel = channelManager->findByName(guild->getName()); channelManager->removeChannel(channel); @@ -252,8 +251,7 @@ void GuildHandler::handleMessage(MessageIn &msg) const int guildId = msg.readInt16(); std::string player = msg.readString(); - Guild *guild = local_player->getGuild(guildId); - if (guild) + if (Guild *guild = local_player->getGuild(guildId)) { Channel *channel = channelManager->findByName(guild->getName()); channelManager->removeChannel(channel); diff --git a/src/resources/dye.cpp b/src/resources/dye.cpp index 92c830dc..d594299c 100644 --- a/src/resources/dye.cpp +++ b/src/resources/dye.cpp @@ -134,7 +134,7 @@ void DyePalette::getColor(int intensity, int color[3]) const void DyePalette::getColor(double intensity, int color[3]) const { // Nothing to do here - if (mColors.size() == 0) + if (mColors.empty()) return; // Force range diff --git a/src/resources/image.cpp b/src/resources/image.cpp index ecf6a6be..328ea9b8 100644 --- a/src/resources/image.cpp +++ b/src/resources/image.cpp @@ -111,7 +111,7 @@ Resource *Image::load(SDL_RWops *rw) return image; } -Resource *Image::load(SDL_RWops *rw, Dye const &dye) +Resource *Image::load(SDL_RWops *rw, const Dye &dye) { SDL_Surface *tmpImage = IMG_Load_RW(rw, 1); diff --git a/src/resources/image.h b/src/resources/image.h index f91d2275..e2e240c3 100644 --- a/src/resources/image.h +++ b/src/resources/image.h @@ -71,7 +71,7 @@ class Image : public Resource * @return <code>NULL</code> if an error occurred, a valid pointer * otherwise. */ - static Resource *load(SDL_RWops *rw, Dye const &dye); + static Resource *load(SDL_RWops *rw, const Dye &dye); /** * Loads an image from an SDL surface. diff --git a/src/resources/itemdb.cpp b/src/resources/itemdb.cpp index 6ff3f58c..8ba80a51 100644 --- a/src/resources/itemdb.cpp +++ b/src/resources/itemdb.cpp @@ -236,9 +236,8 @@ void ItemDB::loadCommonRef(ItemInfo *itemInfo, xmlNodePtr node, const std::strin { if (xmlStrEqual(itemChild->name, BAD_CAST "sprite")) { - std::string attackParticle = XML::getProperty( - itemChild, "particle-effect", ""); - itemInfo->mParticle = attackParticle; + itemInfo->mParticle = XML::getProperty( + itemChild, "particle-effect", std::string()); loadSpriteRef(itemInfo, itemChild); } @@ -272,7 +271,6 @@ void ItemDB::addItem(ItemInfo *itemInfo) else logger->log("ItemDB: Duplicate name (%s) for item id %d found.", temp.c_str(), itemInfo->mId); - } } diff --git a/src/resources/iteminfo.h b/src/resources/iteminfo.h index 5922b6c1..c3a15376 100644 --- a/src/resources/iteminfo.h +++ b/src/resources/iteminfo.h @@ -91,7 +91,7 @@ class ItemInfo const std::string &getName() const { return mName; } - std::string getParticleEffect() const + const std::string &getParticleEffect() const { return mParticle; } const SpriteDisplay &getDisplay() const diff --git a/src/sprite.h b/src/sprite.h index 8eb366d6..d7f5f1d7 100644 --- a/src/sprite.h +++ b/src/sprite.h @@ -46,7 +46,7 @@ class Sprite * * @returns true if the sprite changed, false otherwise */ - virtual bool play(std::string action) = 0; + virtual bool play(const std::string &action) = 0; /** * Inform the animation of the passed time so that it can output the @@ -60,7 +60,7 @@ class Sprite * Draw the current animation frame at the coordinates given in screen * pixels. */ - virtual bool draw(Graphics* graphics, int posX, int posY) const = 0; + virtual bool draw(Graphics *graphics, int posX, int posY) const = 0; /** * Gets the width in pixels of the image @@ -95,7 +95,7 @@ class FlashText : public Text /** * Flash the text for so many refreshes. */ - void flash(int time) {mTime = time; } + void flash(int time) { mTime = time; } /** * Draws the text. diff --git a/src/utils/zlib.cpp b/src/utils/zlib.cpp index 8234766e..773c7484 100644 --- a/src/utils/zlib.cpp +++ b/src/utils/zlib.cpp @@ -135,7 +135,7 @@ int inflateMemory(unsigned char *in, unsigned int inLength, void *loadCompressedFile(const std::string &filename, int &filesize) { std::ifstream file; - file.open(filename.c_str(), std::ios::in); + file.open(filename, std::ios::in); if (file.is_open()) { |