diff options
author | Andrei Karas <akaras@inbox.ru> | 2014-08-03 00:46:38 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2014-08-03 13:17:37 +0300 |
commit | 8b2464a723f7039a3efbc0c7d2e883729b3fa7dd (patch) | |
tree | 0564c85d8f6301d8a0b916f37612e27788d82853 | |
parent | 63054bddcc1a306787250209b03c04086b9b472f (diff) | |
download | ManaVerse-8b2464a723f7039a3efbc0c7d2e883729b3fa7dd.tar.gz ManaVerse-8b2464a723f7039a3efbc0c7d2e883729b3fa7dd.tar.bz2 ManaVerse-8b2464a723f7039a3efbc0c7d2e883729b3fa7dd.tar.xz ManaVerse-8b2464a723f7039a3efbc0c7d2e883729b3fa7dd.zip |
Fix some casts.
-rw-r--r-- | src/being/actorsprite.cpp | 2 | ||||
-rw-r--r-- | src/being/being.cpp | 15 | ||||
-rw-r--r-- | src/being/being.h | 5 | ||||
-rw-r--r-- | src/gamemodifiers.cpp | 2 | ||||
-rw-r--r-- | src/graphicsmanager.cpp | 2 | ||||
-rw-r--r-- | src/gui/gui.cpp | 5 | ||||
-rw-r--r-- | src/gui/popupmanager.cpp | 2 | ||||
-rw-r--r-- | src/gui/popupmanager.h | 14 | ||||
-rw-r--r-- | src/gui/popups/popupmenu.cpp | 3 | ||||
-rw-r--r-- | src/gui/viewport.cpp | 4 | ||||
-rw-r--r-- | src/gui/widgets/avatarlistbox.cpp | 23 | ||||
-rw-r--r-- | src/gui/widgets/dropdown.cpp | 2 | ||||
-rw-r--r-- | src/gui/widgets/dropshortcutcontainer.cpp | 2 | ||||
-rw-r--r-- | src/gui/widgets/itemcontainer.cpp | 2 | ||||
-rw-r--r-- | src/gui/widgets/itemlinkhandler.cpp | 2 | ||||
-rw-r--r-- | src/gui/widgets/scrollarea.cpp | 2 | ||||
-rw-r--r-- | src/gui/widgets/spellshortcutcontainer.cpp | 4 | ||||
-rw-r--r-- | src/gui/widgets/window.cpp | 2 | ||||
-rw-r--r-- | src/render/shaders/shadersmanager.cpp | 4 | ||||
-rw-r--r-- | src/resources/action.h | 2 | ||||
-rw-r--r-- | src/resources/beinginfo.cpp | 2 | ||||
-rw-r--r-- | src/resources/map/map.cpp | 4 | ||||
-rw-r--r-- | src/resources/map/map.h | 11 |
23 files changed, 65 insertions, 51 deletions
diff --git a/src/being/actorsprite.cpp b/src/being/actorsprite.cpp index c26d33d7e..24c8779c0 100644 --- a/src/being/actorsprite.cpp +++ b/src/being/actorsprite.cpp @@ -157,7 +157,7 @@ void ActorSprite::setTargetType(const TargetCursorType::Type type) } else { - const TargetCursorSize::Size sz = getTargetCursorSize(); + const size_t sz = static_cast<size_t>(getTargetCursorSize()); mUsedTargetCursor = targetCursor[static_cast<int>(type)][sz]; if (mUsedTargetCursor) { diff --git a/src/being/being.cpp b/src/being/being.cpp index 4d45d19bd..f45fa4ec8 100644 --- a/src/being/being.cpp +++ b/src/being/being.cpp @@ -718,7 +718,7 @@ int Being::getHitEffect(const Being *const attacker, return hitEffectId; } -int Being::getDefaultEffectId(const int type) +int Being::getDefaultEffectId(const AttackType &type) { if (type == MISS) return paths.getIntValue("missEffectId"); @@ -2638,7 +2638,7 @@ void Being::recalcSpritesOrder() { // slot unknown. Search for real slot, this can be slow FOR_EACH (IntMapCIter, repIt, itemReplacer) { - for (unsigned slot2 = 0; slot2 < sz; slot2 ++) + for (unsigned int slot2 = 0; slot2 < sz; slot2 ++) { if (mSpriteIDs[slot2] == repIt->first) { @@ -2723,7 +2723,7 @@ void Being::recalcSpritesOrder() cnt ++; // logger->log("iteration"); - for (unsigned slot0 = 0; slot0 < sz; slot0 ++) + for (unsigned int slot0 = 0; slot0 < sz; slot0 ++) { const int slot = searchSlotValue(slotRemap, slot0); const int val = slotRemap.at(slot); @@ -2788,7 +2788,7 @@ void Being::recalcSpritesOrder() } // logger->log("after remap"); - for (unsigned slot = 0; slot < sz; slot ++) + for (unsigned int slot = 0; slot < sz; slot ++) { mSpriteRemap[slot] = slotRemap[slot]; if (mSpriteHide[slot] == 0) @@ -2899,7 +2899,8 @@ void Being::updateComment() mComment = loadComment(mName, mType); } -std::string Being::loadComment(const std::string &name, const int type) +std::string Being::loadComment(const std::string &name, + const ActorType::Type &type) { std::string str; switch (type) @@ -3056,7 +3057,7 @@ Gender::Type Being::intToGender(const uint8_t sex) int Being::getSpriteID(const int slot) const { - if (slot < 0 || static_cast<unsigned>(slot) >= mSpriteIDs.size()) + if (slot < 0 || static_cast<size_t>(slot) >= mSpriteIDs.size()) return -1; return mSpriteIDs[slot]; @@ -3064,7 +3065,7 @@ int Being::getSpriteID(const int slot) const unsigned char Being::getSpriteColor(const int slot) const { - if (slot < 0 || static_cast<unsigned>(slot) >= mSpriteColorsIds.size()) + if (slot < 0 || static_cast<size_t>(slot) >= mSpriteColorsIds.size()) return 1; return mSpriteColorsIds[slot]; diff --git a/src/being/being.h b/src/being/being.h index fc7f27bb7..929ebf8d9 100644 --- a/src/being/being.h +++ b/src/being/being.h @@ -756,7 +756,8 @@ class Being notfinal : public ActorSprite, static void clearCache(); static std::string loadComment(const std::string &name, - const int type) A_WARN_UNUSED; + const ActorType::Type &type) + A_WARN_UNUSED; static void saveComment(const std::string &restrict name, const std::string &restrict comment, @@ -908,7 +909,7 @@ class Being notfinal : public ActorSprite, void createSpeechBubble(); - static int getDefaultEffectId(const int type); + static int getDefaultEffectId(const AttackType &type); BeingInfo *mInfo; AnimatedSprite *mEmotionSprite; diff --git a/src/gamemodifiers.cpp b/src/gamemodifiers.cpp index b96f9f4d6..fc60211e0 100644 --- a/src/gamemodifiers.cpp +++ b/src/gamemodifiers.cpp @@ -466,7 +466,7 @@ void GameModifiers::resetModifiers() viewport->toggleCameraMode(); Map *const map = viewport->getMap(); if (map) - map->setDrawLayersFlags(0); + map->setDrawLayersFlags(MapType::NORMAL); } settings.imitationMode = config.resetIntValue("imitationMode"); settings.disableGameModifiers = config.resetBoolValue( diff --git a/src/graphicsmanager.cpp b/src/graphicsmanager.cpp index 54f27417a..ed5983715 100644 --- a/src/graphicsmanager.cpp +++ b/src/graphicsmanager.cpp @@ -246,7 +246,7 @@ void GraphicsManager::createRenderers() if (settings.options.renderer < 0) { useOpenGL = intToRenderType(config.getIntValue("opengl")); - settings.options.renderer = useOpenGL; + settings.options.renderer = static_cast<int>(useOpenGL); } else { diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 7ac1273bd..0f8561643 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -488,7 +488,8 @@ void Gui::draw() const int posY = mouseY - (image->mBounds.h / 2); mGraphics->drawImage(image, posX, posY); } - Image *const mouseCursor = mMouseCursors->get(mCursorType); + Image *const mouseCursor = mMouseCursors->get( + static_cast<int>(mCursorType)); if (mouseCursor) { mouseCursor->setAlpha(mMouseCursorAlpha); @@ -845,7 +846,7 @@ void Gui::distributeMouseEvent(Widget *const source, std::list<MouseListener*> mouseListeners = widget->getMouseListeners(); - unsigned int mouseType = event.getType(); + const MouseEventType::Type mouseType = event.getType(); // Send the event to all mouse listeners of the widget. FOR_EACH (std::list<MouseListener*>::const_iterator, it, mouseListeners) diff --git a/src/gui/popupmanager.cpp b/src/gui/popupmanager.cpp index 24c816008..45899a380 100644 --- a/src/gui/popupmanager.cpp +++ b/src/gui/popupmanager.cpp @@ -168,7 +168,7 @@ void PopupManager::showPopup(const int x, const int y, } void PopupManager::showAttackMonsterPopup(const std::string &name, - const int type) + const ActorType::Type &type) { mPopupMenu->showAttackMonsterPopup(viewport->getMouseX(), viewport->getMouseY(), diff --git a/src/gui/popupmanager.h b/src/gui/popupmanager.h index fcd0f0919..3e54b1742 100644 --- a/src/gui/popupmanager.h +++ b/src/gui/popupmanager.h @@ -23,6 +23,13 @@ #ifndef GUI_POPUPMANAGER_H #define GUI_POPUPMANAGER_H +#include "being/actortype.h" + +#include <string> +#include <vector> + +#include "localconsts.h" + class ActorSprite; class Button; class Being; @@ -38,11 +45,6 @@ class TextField; class TextPopup; class Window; -#include <string> -#include <vector> - -#include "localconsts.h" - class PopupManager final { public: @@ -115,7 +117,7 @@ class PopupManager final void showSpellPopup(TextCommand *const cmd); void showAttackMonsterPopup(const std::string &name, - const int type); + const ActorType::Type &type); void showPickupItemPopup(const std::string &name); diff --git a/src/gui/popups/popupmenu.cpp b/src/gui/popups/popupmenu.cpp index bd8ed9206..aac6c1b21 100644 --- a/src/gui/popups/popupmenu.cpp +++ b/src/gui/popups/popupmenu.cpp @@ -1419,7 +1419,8 @@ void PopupMenu::handleLink(const std::string &link, } else { - dialog->setText(Being::loadComment(mNick, mType)); + dialog->setText(Being::loadComment(mNick, + static_cast<ActorType::Type>(mType))); } dialog->setActionEventId("ok"); dialog->addActionListener(&mPlayerListener); diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index d0ac02d4c..353a5595f 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -500,7 +500,7 @@ void Viewport::mousePressed(MouseEvent &event) mMousePressX = event.getX(); mMousePressY = event.getY(); - const unsigned int eventButton = event.getButton(); + const MouseButton::Type eventButton = event.getButton(); const int pixelX = mMousePressX + mPixelViewX; const int pixelY = mMousePressY + mPixelViewY; @@ -697,7 +697,7 @@ void Viewport::mouseReleased(MouseEvent &event) mMouseClicked = false; if (event.getSource() != this || event.isConsumed()) return; - const unsigned int eventButton = event.getButton(); + const MouseButton::Type eventButton = event.getButton(); if (eventButton == MouseButton::LEFT) { // long button press diff --git a/src/gui/widgets/avatarlistbox.cpp b/src/gui/widgets/avatarlistbox.cpp index 6369efce8..36c6592fd 100644 --- a/src/gui/widgets/avatarlistbox.cpp +++ b/src/gui/widgets/avatarlistbox.cpp @@ -129,7 +129,9 @@ void AvatarListBox::draw(Graphics *graphics) if (!a) continue; - if (a->getType() != MapItemType::SEPARATOR) + const MapItemType::Type type = static_cast<MapItemType::Type>( + a->getType()); + if (type != MapItemType::SEPARATOR) { // Draw online status const Image *const icon = a->getOnline() @@ -165,6 +167,8 @@ void AvatarListBox::draw(Graphics *graphics) if (!a) continue; + const MapItemType::Type type = static_cast<MapItemType::Type>( + a->getType()); std::string text; if (a->getMaxHp() > 0) @@ -304,7 +308,7 @@ void AvatarListBox::draw(Graphics *graphics) // Draw Name if (a->getDisplayBold()) { - if (a->getType() == MapItemType::SEPARATOR) + if (type == MapItemType::SEPARATOR) { boldFont->drawString(graphics, text, mImagePadding + mPadding, y + mPadding); @@ -317,7 +321,7 @@ void AvatarListBox::draw(Graphics *graphics) } else { - if (a->getType() == MapItemType::SEPARATOR) + if (type == MapItemType::SEPARATOR) { font->drawString(graphics, text, mImagePadding + mPadding, y + mPadding); @@ -357,11 +361,14 @@ void AvatarListBox::mousePressed(MouseEvent &event) if (!ava) return; + const MapItemType::Type type = static_cast<MapItemType::Type>( + ava->getType()); + event.consume(); const unsigned int eventButton = event.getButton(); if (eventButton == MouseButton::LEFT) { - if (ava->getType() == AVATAR_PLAYER) + if (type == MapItemType::EMPTY) { const Being *const being = actorManager->findBeingByName( ava->getName(), ActorType::PLAYER); @@ -375,9 +382,8 @@ void AvatarListBox::mousePressed(MouseEvent &event) } else if (eventButton == MouseButton::RIGHT) { - switch (ava->getType()) + switch (type) { - // AVATAR_PLAYER case MapItemType::EMPTY: { const Avatar *const avatar = model->getAvatarAt(selected); @@ -403,7 +409,8 @@ void AvatarListBox::mousePressed(MouseEvent &event) name = model->getAvatarAt(selected)->getName(); popupManager->showAttackMonsterPopup(name, - model->getAvatarAt(selected)->getType()); + static_cast<ActorType::Type>(model->getAvatarAt( + selected)->getType())); break; } case MapItemType::PICKUP: @@ -434,7 +441,7 @@ void AvatarListBox::mousePressed(MouseEvent &event) } else if (eventButton == MouseButton::MIDDLE) { - if (ava->getType() == AVATAR_PLAYER && chatWindow) + if (type == MapItemType::EMPTY && chatWindow) { const WhisperTab *const tab = chatWindow->addWhisperTab( model->getAvatarAt(selected)->getName(), true); diff --git a/src/gui/widgets/dropdown.cpp b/src/gui/widgets/dropdown.cpp index 6647a768f..7957b0587 100644 --- a/src/gui/widgets/dropdown.cpp +++ b/src/gui/widgets/dropdown.cpp @@ -380,7 +380,7 @@ void DropDown::mouseReleased(MouseEvent &event) if (mIsDragged) mPushed = false; - const int button = event.getButton(); + const MouseButton::Type button = event.getButton(); const int x = event.getX(); const int y = event.getY(); // Released outside of widget. Can happen when we have modal diff --git a/src/gui/widgets/dropshortcutcontainer.cpp b/src/gui/widgets/dropshortcutcontainer.cpp index 5ec847922..b57c98273 100644 --- a/src/gui/widgets/dropshortcutcontainer.cpp +++ b/src/gui/widgets/dropshortcutcontainer.cpp @@ -189,7 +189,7 @@ void DropShortcutContainer::mousePressed(MouseEvent &event) event.consume(); - const int eventButton = event.getButton(); + const MouseButton::Type eventButton = event.getButton(); if (eventButton == MouseButton::LEFT) { if (dropShortcut->getItem(index) > 0) diff --git a/src/gui/widgets/itemcontainer.cpp b/src/gui/widgets/itemcontainer.cpp index ef00913e7..3842daf17 100644 --- a/src/gui/widgets/itemcontainer.cpp +++ b/src/gui/widgets/itemcontainer.cpp @@ -403,7 +403,7 @@ void ItemContainer::mousePressed(MouseEvent &event) if (!mInventory) return; - const int button = event.getButton(); + const MouseButton::Type button = event.getButton(); mClicks = event.getClickCount(); if (button == MouseButton::LEFT || button == MouseButton::RIGHT) diff --git a/src/gui/widgets/itemlinkhandler.cpp b/src/gui/widgets/itemlinkhandler.cpp index e8976da67..2217b051f 100644 --- a/src/gui/widgets/itemlinkhandler.cpp +++ b/src/gui/widgets/itemlinkhandler.cpp @@ -68,7 +68,7 @@ void ItemLinkHandler::handleLink(const std::string &link, MouseEvent *event) std::string url = link; replaceAll(url, " ", ""); listener.url = url; - const int button = event->getButton(); + const MouseButton::Type button = event->getButton(); if (button == MouseButton::LEFT) { ConfirmDialog *const confirmDlg = new ConfirmDialog( diff --git a/src/gui/widgets/scrollarea.cpp b/src/gui/widgets/scrollarea.cpp index 028c2e7b1..12b9a8e7f 100644 --- a/src/gui/widgets/scrollarea.cpp +++ b/src/gui/widgets/scrollarea.cpp @@ -486,7 +486,7 @@ Image *ScrollArea::getImageByState(Rect &dim, const BUTTON_DIR dir) + toString(static_cast<unsigned>(dir))); return nullptr; } - return buttons[dir][state]; + return buttons[static_cast<size_t>(dir)][state]; } void ScrollArea::drawButton(Graphics *const graphics, diff --git a/src/gui/widgets/spellshortcutcontainer.cpp b/src/gui/widgets/spellshortcutcontainer.cpp index 33579b5a9..8960725d5 100644 --- a/src/gui/widgets/spellshortcutcontainer.cpp +++ b/src/gui/widgets/spellshortcutcontainer.cpp @@ -164,7 +164,7 @@ void SpellShortcutContainer::mousePressed(MouseEvent &event) if (index == -1) return; - const unsigned int eventButton = event.getButton(); + const MouseButton::Type eventButton = event.getButton(); if (eventButton == MouseButton::LEFT) { const int itemId = getItemByIndex(index); @@ -200,7 +200,7 @@ void SpellShortcutContainer::mouseReleased(MouseEvent &event) } const int itemId = getItemByIndex(index); - const unsigned int eventButton = event.getButton(); + const MouseButton::Type eventButton = event.getButton(); if (eventButton == MouseButton::LEFT) { diff --git a/src/gui/widgets/window.cpp b/src/gui/widgets/window.cpp index a4fb2d57f..2078c4cef 100644 --- a/src/gui/widgets/window.cpp +++ b/src/gui/widgets/window.cpp @@ -727,7 +727,7 @@ void Window::mousePressed(MouseEvent &event) mMoved = event.getY() <= static_cast<int>(mTitleBarHeight); } - const unsigned int button = event.getButton(); + const MouseButton::Type button = event.getButton(); if (button == MouseButton::LEFT) { const int x = event.getX(); diff --git a/src/render/shaders/shadersmanager.cpp b/src/render/shaders/shadersmanager.cpp index 7102bb747..98c54012c 100644 --- a/src/render/shaders/shadersmanager.cpp +++ b/src/render/shaders/shadersmanager.cpp @@ -53,7 +53,7 @@ Shader *ShadersManager::createShader(const unsigned int type, return new Shader(shaderId); GLint len = 0; mglGetShaderiv(shaderId, GL_INFO_LOG_LENGTH, &len); - char *buf = new char[len + 1]; + char *buf = new char[static_cast<size_t>(len) + 1]; mglGetShaderInfoLog(shaderId, len, &len, buf); buf[len] = 0; logger->log("Shader '%s' compilation error: %s", fileName.c_str(), buf); @@ -107,7 +107,7 @@ ShaderProgram *ShadersManager::createProgram(const std::string &vertex, GLint len = 0; mglGetProgramiv(programId, GL_INFO_LOG_LENGTH, &len); - char *buf = new char[len + 1]; + char *buf = new char[static_cast<size_t>(len) + 1]; mglGetProgramInfoLog(programId, len, &len, buf); buf[len] = 0; logger->log("Program '%s, %s' compilation error: %s", diff --git a/src/resources/action.h b/src/resources/action.h index 86a3740d1..edc2ea6ed 100644 --- a/src/resources/action.h +++ b/src/resources/action.h @@ -58,7 +58,7 @@ class Action final void setLastFrameDelay(const int delay) noexcept; protected: - typedef std::map<int, Animation*> Animations; + typedef std::map<SpriteDirection::Type, Animation*> Animations; typedef Animations::iterator AnimationIter; Animations mAnimations; diff --git a/src/resources/beinginfo.cpp b/src/resources/beinginfo.cpp index e3cf9bb91..bd4359144 100644 --- a/src/resources/beinginfo.cpp +++ b/src/resources/beinginfo.cpp @@ -154,7 +154,7 @@ const SoundInfo &BeingInfo::getSound(const ItemSoundEvent::Type event) const if (!vect || vect->empty()) return emptySound; else - return vect->at(static_cast<unsigned int>(rand()) % vect->size()); + return vect->at(static_cast<size_t>(rand()) % vect->size()); } const Attack *BeingInfo::getAttack(const int id) const diff --git a/src/resources/map/map.cpp b/src/resources/map/map.cpp index 99344e0fd..f7f4b900f 100644 --- a/src/resources/map/map.cpp +++ b/src/resources/map/map.cpp @@ -497,7 +497,7 @@ void Map::draw(Graphics *const graphics, int scrollX, int scrollY) void Map::drawCollision(Graphics *const graphics, const int scrollX, const int scrollY, - const int debugFlags) const + const MapType::MapType drawFlags) const { const int endPixelY = graphics->mHeight + scrollY + mTileHeight - 1; int startX = scrollX / mTileWidth; @@ -514,7 +514,7 @@ void Map::drawCollision(Graphics *const graphics, if (endY > mHeight) endY = mHeight; - if (debugFlags < MapType::SPECIAL) + if (drawFlags < MapType::SPECIAL) { graphics->setColor(userPalette->getColorWithAlpha(UserPalette::NET)); graphics->drawNet( diff --git a/src/resources/map/map.h b/src/resources/map/map.h index cf2d0c1e9..21976d38a 100644 --- a/src/resources/map/map.h +++ b/src/resources/map/map.h @@ -29,6 +29,7 @@ #include "resources/map/blockmask.h" #include "resources/map/blocktype.h" +#include "resources/map/maptype.h" #include "resources/map/properties.h" #include "listeners/configlistener.h" @@ -115,7 +116,7 @@ class Map final : public Properties, public ConfigListener */ void drawCollision(Graphics *const graphics, const int scrollX, const int scrollY, - const int debugFlags) const; + const MapType::MapType drawFlags) const; /** * Adds a layer to this map. The map takes ownership of the layer. @@ -217,10 +218,10 @@ class Map final : public Properties, public ConfigListener void addAnimation(const int gid, TileAnimation *const animation) { mTileAnimations[gid] = animation; } - void setDrawLayersFlags(const int n) + void setDrawLayersFlags(const MapType::MapType &n) { mDrawLayersFlags = n; } - int getDrawLayersFlags() const A_WARN_UNUSED + MapType::MapType getDrawLayersFlags() const A_WARN_UNUSED { return mDrawLayersFlags; } void addExtraLayer(); @@ -379,8 +380,8 @@ class Map final : public Properties, public ConfigListener Actors mActors; bool mHasWarps; - // debug flags - int mDrawLayersFlags; + // draw flags + MapType::MapType mDrawLayersFlags; // Pathfinding members unsigned int mOnClosedList; |