summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2016-02-07 16:18:13 +0300
committerAndrei Karas <akaras@inbox.ru>2016-02-07 16:18:13 +0300
commit9fe21fcd8883b37bdc30224822e6e42afb35b8f0 (patch)
tree798117abd4dc7e610997d59d530a96ddc1509f53
parent4429cb14e9e187edef27aba692a4266733f79c17 (diff)
downloadManaVerse-9fe21fcd8883b37bdc30224822e6e42afb35b8f0.tar.gz
ManaVerse-9fe21fcd8883b37bdc30224822e6e42afb35b8f0.tar.bz2
ManaVerse-9fe21fcd8883b37bdc30224822e6e42afb35b8f0.tar.xz
ManaVerse-9fe21fcd8883b37bdc30224822e6e42afb35b8f0.zip
Replace most static_cast<Type> to shorter versions from defines.
-rw-r--r--src/actions/actions.cpp6
-rw-r--r--src/actions/commands.cpp6
-rw-r--r--src/actions/pets.cpp2
-rw-r--r--src/actormanager.cpp18
-rw-r--r--src/actormanager.h6
-rw-r--r--src/being/actor.h6
-rw-r--r--src/being/actorsprite.cpp26
-rw-r--r--src/being/actorsprite.h4
-rw-r--r--src/being/being.cpp58
-rw-r--r--src/being/being.h8
-rw-r--r--src/being/compoundsprite.cpp6
-rw-r--r--src/being/crazymoves.cpp8
-rw-r--r--src/being/localplayer.cpp102
-rw-r--r--src/being/playerrelations.cpp10
-rw-r--r--src/beingequipbackend.cpp2
-rw-r--r--src/chatlogger.cpp2
-rw-r--r--src/client.cpp14
-rw-r--r--src/commandline.cpp4
-rw-r--r--src/configmanager.cpp24
-rw-r--r--src/configuration.cpp6
-rw-r--r--src/debug/debug_new.cpp12
-rw-r--r--src/defaults.cpp28
-rw-r--r--src/dirs.cpp8
-rw-r--r--src/dyetool/client.cpp4
-rw-r--r--src/enums/enums_unittest.cc4
-rw-r--r--src/eventsmanager.cpp22
-rw-r--r--src/game.cpp4
-rw-r--r--src/gamemodifiers.cpp6
-rw-r--r--src/graphicsmanager.cpp18
-rw-r--r--src/graphicsvertexes.cpp18
-rw-r--r--src/gui/color.cpp6
-rw-r--r--src/gui/focushandler.cpp10
-rw-r--r--src/gui/fonts/font.cpp6
-rw-r--r--src/gui/fonts/textchunk.cpp12
-rw-r--r--src/gui/gui.cpp4
-rw-r--r--src/gui/models/beingslistmodel.h2
-rw-r--r--src/gui/models/colormodel.cpp8
-rw-r--r--src/gui/models/extendednamesmodel.cpp8
-rw-r--r--src/gui/models/iconsmodel.h2
-rw-r--r--src/gui/models/ignorechoiceslistmodel.h2
-rw-r--r--src/gui/models/itemsmodel.h2
-rw-r--r--src/gui/models/modelistmodel.h4
-rw-r--r--src/gui/models/namesmodel.cpp4
-rw-r--r--src/gui/models/playertablemodel.cpp8
-rw-r--r--src/gui/models/serverslistmodel.h4
-rw-r--r--src/gui/models/shopitems.cpp10
-rw-r--r--src/gui/models/shopitems.h2
-rw-r--r--src/gui/models/skillmodel.cpp2
-rw-r--r--src/gui/models/skillmodel.h2
-rw-r--r--src/gui/models/updatelistmodel.h2
-rw-r--r--src/gui/models/worldlistmodel.h2
-rw-r--r--src/gui/palette.cpp16
-rw-r--r--src/gui/palette.h2
-rw-r--r--src/gui/popups/itempopup.cpp6
-rw-r--r--src/gui/popups/popupmenu.cpp14
-rw-r--r--src/gui/sdlinput.cpp2
-rw-r--r--src/gui/shortcut/emoteshortcut.cpp8
-rw-r--r--src/gui/shortcut/itemshortcut.cpp4
-rw-r--r--src/gui/theme.cpp118
-rw-r--r--src/gui/theme.h8
-rw-r--r--src/gui/themecolorsidoperators.cpp2
-rw-r--r--src/gui/userpalette.cpp44
-rw-r--r--src/gui/userpalette.h28
-rw-r--r--src/gui/viewport.cpp30
-rw-r--r--src/gui/widgets/basiccontainer.cpp4
-rw-r--r--src/gui/widgets/browserbox.cpp114
-rw-r--r--src/gui/widgets/characterdisplay.cpp2
-rw-r--r--src/gui/widgets/characterviewnormal.cpp6
-rw-r--r--src/gui/widgets/characterviewsmall.cpp6
-rw-r--r--src/gui/widgets/colorpage.cpp10
-rw-r--r--src/gui/widgets/dropdown.cpp10
-rw-r--r--src/gui/widgets/emotepage.cpp2
-rw-r--r--src/gui/widgets/emoteshortcutcontainer.cpp6
-rw-r--r--src/gui/widgets/extendedlistbox.cpp8
-rw-r--r--src/gui/widgets/flowcontainer.cpp2
-rw-r--r--src/gui/widgets/guitable.cpp56
-rw-r--r--src/gui/widgets/inttextfield.cpp2
-rw-r--r--src/gui/widgets/itemcontainer.cpp4
-rw-r--r--src/gui/widgets/layoutarray.cpp86
-rw-r--r--src/gui/widgets/listbox.cpp14
-rw-r--r--src/gui/widgets/passwordfield.cpp4
-rw-r--r--src/gui/widgets/progressbar.cpp12
-rw-r--r--src/gui/widgets/scrollarea.cpp12
-rw-r--r--src/gui/widgets/selldialog.cpp2
-rw-r--r--src/gui/widgets/serverslistbox.h4
-rw-r--r--src/gui/widgets/setupitem.cpp4
-rw-r--r--src/gui/widgets/setuptouchitem.cpp2
-rw-r--r--src/gui/widgets/shoplistbox.cpp2
-rw-r--r--src/gui/widgets/shortcutcontainer.cpp4
-rw-r--r--src/gui/widgets/skillinfo.cpp2
-rw-r--r--src/gui/widgets/skilllistbox.h2
-rw-r--r--src/gui/widgets/slider.cpp4
-rw-r--r--src/gui/widgets/spellshortcutcontainer.cpp4
-rw-r--r--src/gui/widgets/tabbedarea.cpp24
-rw-r--r--src/gui/widgets/tabs/chat/chattab.cpp4
-rw-r--r--src/gui/widgets/tabs/setup_colors.cpp20
-rw-r--r--src/gui/widgets/tabs/setup_joystick.cpp2
-rw-r--r--src/gui/widgets/tabs/setup_relations.cpp2
-rw-r--r--src/gui/widgets/tabs/setup_theme.cpp4
-rw-r--r--src/gui/widgets/tabs/setup_video.cpp18
-rw-r--r--src/gui/widgets/tabs/socialfriendstab.h4
-rw-r--r--src/gui/widgets/tabs/socialguildtab.h8
-rw-r--r--src/gui/widgets/tabs/socialguildtab2.h4
-rw-r--r--src/gui/widgets/tabs/socialnavigationtab.h6
-rw-r--r--src/gui/widgets/tabs/socialpartytab.h4
-rw-r--r--src/gui/widgets/tabs/socialplayerstab.h2
-rw-r--r--src/gui/widgets/tabstrip.cpp2
-rw-r--r--src/gui/widgets/textbox.cpp46
-rw-r--r--src/gui/widgets/textbox.h2
-rw-r--r--src/gui/widgets/textfield.cpp36
-rw-r--r--src/gui/widgets/textpreview.cpp16
-rw-r--r--src/gui/widgets/widget2.h4
-rw-r--r--src/gui/widgets/window.cpp14
-rw-r--r--src/gui/windowmenu.cpp2
-rw-r--r--src/gui/windows/buydialog.cpp2
-rw-r--r--src/gui/windows/charcreatedialog.cpp26
-rw-r--r--src/gui/windows/charselectdialog.cpp24
-rw-r--r--src/gui/windows/chatwindow.cpp36
-rw-r--r--src/gui/windows/editserverdialog.cpp2
-rw-r--r--src/gui/windows/emotewindow.cpp4
-rw-r--r--src/gui/windows/equipmentwindow.cpp6
-rw-r--r--src/gui/windows/itemamountwindow.cpp10
-rw-r--r--src/gui/windows/logindialog.cpp4
-rw-r--r--src/gui/windows/mailwindow.cpp2
-rw-r--r--src/gui/windows/minimap.cpp16
-rw-r--r--src/gui/windows/ministatuswindow.cpp4
-rw-r--r--src/gui/windows/npcdialog.cpp12
-rw-r--r--src/gui/windows/outfitwindow.cpp34
-rw-r--r--src/gui/windows/questswindow.cpp4
-rw-r--r--src/gui/windows/quitdialog.cpp2
-rw-r--r--src/gui/windows/registerdialog.cpp2
-rw-r--r--src/gui/windows/serverdialog.cpp12
-rw-r--r--src/gui/windows/skilldialog.cpp8
-rw-r--r--src/gui/windows/textcommandeditor.cpp4
-rw-r--r--src/gui/windows/textdialog.cpp2
-rw-r--r--src/gui/windows/textselectdialog.cpp2
-rw-r--r--src/gui/windows/updaterwindow.cpp32
-rw-r--r--src/gui/windows/whoisonline.cpp8
-rw-r--r--src/guild.h2
-rw-r--r--src/input/inputactionmap.h2
-rw-r--r--src/input/inputactionoperators.cpp6
-rw-r--r--src/input/inputactionsortfunctor.h4
-rw-r--r--src/input/inputmanager.cpp56
-rw-r--r--src/input/inputmanager.h2
-rw-r--r--src/input/keyboardconfig.cpp6
-rw-r--r--src/input/touch/touchmanager.cpp6
-rw-r--r--src/input/touch/touchmanager.h8
-rw-r--r--src/localconsts.h9
-rw-r--r--src/logger.cpp18
-rw-r--r--src/mumblemanager.cpp4
-rw-r--r--src/net/download.cpp10
-rw-r--r--src/net/ea/guildrecv.cpp4
-rw-r--r--src/net/ea/inventoryrecv.cpp2
-rw-r--r--src/net/ea/loginhandler.cpp2
-rw-r--r--src/net/ea/loginrecv.cpp4
-rw-r--r--src/net/ea/network.cpp14
-rw-r--r--src/net/ea/npcrecv.cpp2
-rw-r--r--src/net/eathena/adminhandler.cpp22
-rw-r--r--src/net/eathena/auctionhandler.cpp6
-rw-r--r--src/net/eathena/bankrecv.cpp6
-rw-r--r--src/net/eathena/battlegroundhandler.cpp4
-rw-r--r--src/net/eathena/beinghandler.cpp2
-rw-r--r--src/net/eathena/beingrecv.cpp62
-rw-r--r--src/net/eathena/buyingstorehandler.cpp12
-rw-r--r--src/net/eathena/cashshophandler.cpp6
-rw-r--r--src/net/eathena/charserverhandler.cpp16
-rw-r--r--src/net/eathena/charserverrecv.cpp6
-rw-r--r--src/net/eathena/chathandler.cpp44
-rw-r--r--src/net/eathena/generalrecv.cpp2
-rw-r--r--src/net/eathena/guildhandler.cpp8
-rw-r--r--src/net/eathena/guildrecv.cpp4
-rw-r--r--src/net/eathena/homunculushandler.cpp10
-rw-r--r--src/net/eathena/inventoryhandler.cpp26
-rw-r--r--src/net/eathena/inventoryrecv.cpp2
-rw-r--r--src/net/eathena/itemrecv.cpp16
-rw-r--r--src/net/eathena/mailhandler.cpp12
-rw-r--r--src/net/eathena/markethandler.cpp16
-rw-r--r--src/net/eathena/mercenaryhandler.cpp10
-rw-r--r--src/net/eathena/messagein.cpp24
-rw-r--r--src/net/eathena/messageout.cpp36
-rw-r--r--src/net/eathena/network.cpp4
-rw-r--r--src/net/eathena/npchandler.cpp48
-rw-r--r--src/net/eathena/partyhandler.cpp16
-rw-r--r--src/net/eathena/pethandler.cpp4
-rw-r--r--src/net/eathena/playerhandler.cpp18
-rw-r--r--src/net/eathena/playerrecv.cpp2
-rw-r--r--src/net/eathena/questhandler.cpp2
-rw-r--r--src/net/eathena/searchstorehandler.cpp6
-rw-r--r--src/net/eathena/skillhandler.cpp22
-rw-r--r--src/net/eathena/skillrecv.cpp10
-rw-r--r--src/net/eathena/tradehandler.cpp4
-rw-r--r--src/net/eathena/vendinghandler.cpp16
-rw-r--r--src/net/ipc.cpp2
-rw-r--r--src/net/messagein.cpp76
-rw-r--r--src/net/messageout.cpp22
-rw-r--r--src/net/messageout.h2
-rw-r--r--src/net/packetlimiter.cpp116
-rw-r--r--src/net/tmwa/adminhandler.cpp8
-rw-r--r--src/net/tmwa/beingrecv.cpp70
-rw-r--r--src/net/tmwa/charserverhandler.cpp10
-rw-r--r--src/net/tmwa/charserverrecv.cpp4
-rw-r--r--src/net/tmwa/chathandler.cpp22
-rw-r--r--src/net/tmwa/chatrecv.cpp2
-rw-r--r--src/net/tmwa/generalrecv.cpp2
-rw-r--r--src/net/tmwa/guildhandler.cpp4
-rw-r--r--src/net/tmwa/guildrecv.cpp2
-rw-r--r--src/net/tmwa/inventoryhandler.cpp16
-rw-r--r--src/net/tmwa/inventoryrecv.cpp4
-rw-r--r--src/net/tmwa/itemrecv.cpp8
-rw-r--r--src/net/tmwa/messagein.cpp24
-rw-r--r--src/net/tmwa/messageout.cpp34
-rw-r--r--src/net/tmwa/network.cpp4
-rw-r--r--src/net/tmwa/npchandler.cpp12
-rw-r--r--src/net/tmwa/partyhandler.cpp12
-rw-r--r--src/net/tmwa/pethandler.cpp4
-rw-r--r--src/net/tmwa/playerhandler.cpp8
-rw-r--r--src/net/tmwa/skillhandler.cpp22
-rw-r--r--src/net/tmwa/skillrecv.cpp12
-rw-r--r--src/net/tmwa/tradehandler.cpp4
-rw-r--r--src/net/updatetypeoperators.cpp6
-rw-r--r--src/particle/imageparticle.cpp4
-rw-r--r--src/particle/particle.cpp12
-rw-r--r--src/particle/particle.h4
-rw-r--r--src/particle/particleemitter.cpp18
-rw-r--r--src/particle/particlevector.cpp6
-rw-r--r--src/particle/textparticle.cpp8
-rw-r--r--src/particle/textparticle.h4
-rw-r--r--src/party.h2
-rw-r--r--src/render/graphics.cpp16
-rw-r--r--src/render/mobileopengl2graphics.cpp2
-rw-r--r--src/render/mobileopenglgraphics.cpp8
-rw-r--r--src/render/modernopenglgraphics.cpp2
-rw-r--r--src/render/sdl2graphics.cpp152
-rw-r--r--src/render/sdl2softwaregraphics.cpp242
-rw-r--r--src/render/sdlgraphics.cpp282
-rw-r--r--src/render/shaders/shadersmanager.cpp4
-rw-r--r--src/render/surfacegraphics.cpp36
-rw-r--r--src/resources/ambientlayer.cpp20
-rw-r--r--src/resources/animation/simpleanimation.cpp8
-rw-r--r--src/resources/beingcommon.cpp2
-rw-r--r--src/resources/beinginfo.cpp2
-rw-r--r--src/resources/db/colordb.cpp2
-rw-r--r--src/resources/dye/dye.cpp4
-rw-r--r--src/resources/dye/dyepalette.cpp24
-rw-r--r--src/resources/image.cpp22
-rw-r--r--src/resources/imagehelper.cpp16
-rw-r--r--src/resources/imageset.cpp2
-rw-r--r--src/resources/imagewriter.cpp4
-rw-r--r--src/resources/inventory/complexinventory.cpp4
-rw-r--r--src/resources/inventory/inventory.cpp24
-rw-r--r--src/resources/item/item.cpp2
-rw-r--r--src/resources/iteminfo.cpp10
-rw-r--r--src/resources/iteminfo.h4
-rw-r--r--src/resources/map/map.cpp16
-rw-r--r--src/resources/map/map.h2
-rw-r--r--src/resources/map/mapheights.h2
-rw-r--r--src/resources/map/maplayer.cpp10
-rw-r--r--src/resources/mapreader.cpp6
-rw-r--r--src/resources/resourcemanager.h2
-rw-r--r--src/resources/sdlimagehelper.cpp6
-rw-r--r--src/resources/sprite/animatedsprite.cpp14
-rw-r--r--src/resources/subimage.cpp24
-rw-r--r--src/resources/wallpaper.cpp4
-rw-r--r--src/spellmanager.cpp26
-rw-r--r--src/test/testlauncher.cpp2
-rw-r--r--src/test/testmain.cpp32
-rw-r--r--src/units.cpp4
-rw-r--r--src/utils/base64.cpp20
-rw-r--r--src/utils/copynpaste.cpp4
-rw-r--r--src/utils/mathutils.h8
-rw-r--r--src/utils/mathutils_unittest.cc2
-rw-r--r--src/utils/mkdir.cpp4
-rw-r--r--src/utils/physfsrwops.cpp14
-rw-r--r--src/utils/physfstools.cpp2
-rw-r--r--src/utils/sdlhelper.cpp8
-rw-r--r--src/utils/sdlpixel.h48
-rw-r--r--src/utils/stringutils.cpp40
-rw-r--r--src/utils/stringutils_unittest.cc4
-rw-r--r--src/utils/xml/libxml.cpp2
-rw-r--r--src/utils/xml/pugixml.cpp2
280 files changed, 2072 insertions, 2063 deletions
diff --git a/src/actions/actions.cpp b/src/actions/actions.cpp
index 472ea2b6d..a7289e300 100644
--- a/src/actions/actions.cpp
+++ b/src/actions/actions.cpp
@@ -398,7 +398,7 @@ impHandler(shortcut)
if (itemShortcutWindow)
{
const int num = itemShortcutWindow->getTabIndex();
- if (num >= 0 && num < static_cast<int>(SHORTCUT_TABS))
+ if (num >= 0 && num < CAST_S32(SHORTCUT_TABS))
{
if (itemShortcut[num])
{
@@ -1120,7 +1120,7 @@ impHandler0(cacheInfo)
{
if (!cache[f].size)
{
- const unsigned int sz = static_cast<int>(cache[f].size);
+ const unsigned int sz = CAST_S32(cache[f].size);
all += sz;
str.append(strprintf("%d: %u, ", f, sz));
}
@@ -1683,7 +1683,7 @@ impHandler0(testInfo)
{
if (actorManager)
{
- logger->log("actors count: %d", static_cast<int>(
+ logger->log("actors count: %d", CAST_S32(
actorManager->size()));
return true;
}
diff --git a/src/actions/commands.cpp b/src/actions/commands.cpp
index 4b967c873..b9482ba32 100644
--- a/src/actions/commands.cpp
+++ b/src/actions/commands.cpp
@@ -392,7 +392,7 @@ impHandler(commandEmote)
{
if (localPlayer)
{
- localPlayer->emote(static_cast<uint8_t>(atoi(event.args.c_str())));
+ localPlayer->emote(CAST_U8(atoi(event.args.c_str())));
return true;
}
return false;
@@ -965,7 +965,7 @@ impHandler(commandHomunEmote)
if (homunculusHandler)
{
- homunculusHandler->emote(static_cast<uint8_t>(
+ homunculusHandler->emote(CAST_U8(
atoi(event.args.c_str())));
return true;
}
@@ -1100,7 +1100,7 @@ impHandler(skill)
StringVect vect;
splitToStringVector(vect, event.args, ' ');
- const int sz = static_cast<int>(vect.size());
+ const int sz = CAST_S32(vect.size());
if (sz < 1)
return true;
const int skillId = atoi(vect[0].c_str());
diff --git a/src/actions/pets.cpp b/src/actions/pets.cpp
index d69618356..84b3d412d 100644
--- a/src/actions/pets.cpp
+++ b/src/actions/pets.cpp
@@ -82,7 +82,7 @@ static const Being *getPet()
impHandler(commandEmotePet)
{
// need use actual pet id
- petHandler->emote(static_cast<uint8_t>(
+ petHandler->emote(CAST_U8(
atoi(event.args.c_str())), 0);
return true;
}
diff --git a/src/actormanager.cpp b/src/actormanager.cpp
index 1152324c2..c41f97c71 100644
--- a/src/actormanager.cpp
+++ b/src/actormanager.cpp
@@ -87,9 +87,9 @@ class FindBeingFunctor final
const unsigned other_y = y
+ ((b->getType() == ActorType::Npc) ? 1 : 0);
const Vector &pos = b->getPosition();
- return (static_cast<unsigned>(pos.x) / mapTileSize == x &&
- (static_cast<unsigned>(pos.y) / mapTileSize == y
- || static_cast<unsigned>(pos.y) / mapTileSize == other_y) &&
+ return (CAST_U32(pos.x) / mapTileSize == x &&
+ (CAST_U32(pos.y) / mapTileSize == y
+ || CAST_U32(pos.y) / mapTileSize == other_y) &&
b->isAlive() && (type == ActorType::Unknown
|| b->getType() == type));
}
@@ -397,8 +397,8 @@ Being *ActorManager::findBeing(const BeingId id) const
Being *ActorManager::findBeing(const int x, const int y,
const ActorTypeT type) const
{
- beingActorFinder.x = static_cast<uint16_t>(x);
- beingActorFinder.y = static_cast<uint16_t>(y);
+ beingActorFinder.x = CAST_U16(x);
+ beingActorFinder.y = CAST_U16(y);
beingActorFinder.type = type;
const ActorSpritesConstIterator it = std::find_if(
@@ -1697,7 +1697,7 @@ void ActorManager::parseLevels(std::string levels) const
being->addToCache();
}
}
- f = static_cast<size_t>(pos + brkEnd.length());
+ f = CAST_SIZE(pos + brkEnd.length());
pos = levels.find(brkEnd, f);
}
updatePlayerNames();
@@ -1977,7 +1977,7 @@ Being *ActorManager::cloneBeing(const Being *const srcBeing,
srcBeing->getTileY() + dy);
dstBeing->setName(srcBeing->getName());
dstBeing->setDirection(srcBeing->getDirection());
- const int sz = static_cast<int>(srcBeing->getSpritesCount());
+ const int sz = CAST_S32(srcBeing->getSpritesCount());
for (int slot = 0; slot < sz; slot ++)
{
const int spriteId = srcBeing->getSpriteID(slot);
@@ -1995,7 +1995,7 @@ Being *ActorManager::cloneBeing(const Being *const srcBeing,
void ActorManager::updateBadges()
{
- const uint8_t showBadges = static_cast<uint8_t>(
+ const uint8_t showBadges = CAST_U8(
config.getIntValue("showBadges"));
Being::mShowBadges = showBadges;
for_actors
@@ -2014,7 +2014,7 @@ void ActorManager::updateNameId(const std::string &name,
{
if (!mEnableIdCollecting)
return;
- const int id = static_cast<int>(beingId);
+ const int id = CAST_S32(beingId);
if (id &&
(id < 2000000 ||
id >= 110000000))
diff --git a/src/actormanager.h b/src/actormanager.h
index 60a0bec00..28aa25417 100644
--- a/src/actormanager.h
+++ b/src/actormanager.h
@@ -309,13 +309,13 @@ class ActorManager final: public ConfigListener
{ mAttackMobs = mobs; }
int getPriorityAttackMobsSize() const A_WARN_UNUSED
- { return static_cast<int>(mPriorityAttackMobs.size()); }
+ { return CAST_S32(mPriorityAttackMobs.size()); }
int getAttackMobsSize() const A_WARN_UNUSED
- { return static_cast<int>(mAttackMobs.size()); }
+ { return CAST_S32(mAttackMobs.size()); }
int getPickupItemsSize() const A_WARN_UNUSED
- { return static_cast<int>(mPickupItems.size()); }
+ { return CAST_S32(mPickupItems.size()); }
#define defList(list1, mob) \
bool isIn##list1##List(const std::string &name) const A_WARN_UNUSED\
diff --git a/src/being/actor.h b/src/being/actor.h
index ab79c6935..3e004c419 100644
--- a/src/being/actor.h
+++ b/src/being/actor.h
@@ -83,19 +83,19 @@ class Actor notfinal
* Returns the pixels X coordinate of the actor.
*/
int getPixelX() const A_WARN_UNUSED
- { return static_cast<int>(mPos.x); }
+ { return CAST_S32(mPos.x); }
/**
* Returns the pixel Y coordinate of the actor.
*/
virtual int getPixelY() const A_WARN_UNUSED
- { return static_cast<int>(mPos.y); }
+ { return CAST_S32(mPos.y); }
/**
* Returns the pixel Y coordinate of the actor for sorting only.
*/
virtual int getSortPixelY() const A_WARN_UNUSED
- { return static_cast<int>(mPos.y) - mYDiff; }
+ { return CAST_S32(mPos.y) - mYDiff; }
/**
* Returns the x coordinate in tiles of the actor.
diff --git a/src/being/actorsprite.cpp b/src/being/actorsprite.cpp
index d31bb9317..02da33367 100644
--- a/src/being/actorsprite.cpp
+++ b/src/being/actorsprite.cpp
@@ -47,12 +47,12 @@
#include "debug.h"
#define for_each_cursors() \
- for (int size = static_cast<int>(TargetCursorSize::SMALL); \
- size < static_cast<int>(TargetCursorSize::NUM_TC); \
+ for (int size = CAST_S32(TargetCursorSize::SMALL); \
+ size < CAST_S32(TargetCursorSize::NUM_TC); \
size ++) \
{ \
- for (int type = static_cast<int>(TargetCursorType::NORMAL); \
- type < static_cast<int>(TargetCursorType::NUM_TCT); \
+ for (int type = CAST_S32(TargetCursorType::NORMAL); \
+ type < CAST_S32(TargetCursorType::NUM_TCT); \
type ++) \
#define end_foreach }
@@ -60,8 +60,8 @@
static const unsigned int STATUS_EFFECTS = 32;
AnimatedSprite *ActorSprite::targetCursor
- [static_cast<size_t>(TargetCursorType::NUM_TCT)]
- [static_cast<size_t>(TargetCursorSize::NUM_TC)];
+ [CAST_SIZE(TargetCursorType::NUM_TCT)]
+ [CAST_SIZE(TargetCursorSize::NUM_TC)];
bool ActorSprite::loaded = false;
ActorSprite::ActorSprite(const BeingId id) :
@@ -163,19 +163,19 @@ void ActorSprite::setTargetType(const TargetCursorTypeT type)
}
else
{
- const size_t sz = static_cast<size_t>(getTargetCursorSize());
- mUsedTargetCursor = targetCursor[static_cast<int>(type)][sz];
+ const size_t sz = CAST_SIZE(getTargetCursorSize());
+ mUsedTargetCursor = targetCursor[CAST_S32(type)][sz];
if (mUsedTargetCursor)
{
- static const int targetWidths[static_cast<size_t>(
+ static const int targetWidths[CAST_SIZE(
TargetCursorSize::NUM_TC)]
= {0, 0, 0};
- static const int targetHeights[static_cast<size_t>(
+ static const int targetHeights[CAST_SIZE(
TargetCursorSize::NUM_TC)]
= {-mapTileSize / 2, -mapTileSize / 2, -mapTileSize};
- mCursorPaddingX = static_cast<int>(targetWidths[sz]);
- mCursorPaddingY = static_cast<int>(targetHeights[sz]);
+ mCursorPaddingX = CAST_S32(targetWidths[sz]);
+ mCursorPaddingY = CAST_S32(targetHeights[sz]);
}
}
}
@@ -219,7 +219,7 @@ void ActorSprite::setStatusEffectBlock(const int offset,
const std::string str = strprintf(
"Error: unknown effect by block-index. "
"Offset: %d, effect int: %d, i: %u",
- offset, static_cast<int>(newEffects), i);
+ offset, CAST_S32(newEffects), i);
logger->log(str);
DebugMessageListener::distributeEvent(str);
}
diff --git a/src/being/actorsprite.h b/src/being/actorsprite.h
index 314fff9fb..2ca5065ef 100644
--- a/src/being/actorsprite.h
+++ b/src/being/actorsprite.h
@@ -225,8 +225,8 @@ class ActorSprite notfinal : public CompoundSprite, public Actor
/** Animated target cursors. */
static AnimatedSprite *targetCursor
- [static_cast<size_t>(TargetCursorType::NUM_TCT)]
- [static_cast<size_t>(TargetCursorSize::NUM_TC)];
+ [CAST_SIZE(TargetCursorType::NUM_TCT)]
+ [CAST_SIZE(TargetCursorSize::NUM_TC)];
static bool loaded;
diff --git a/src/being/being.cpp b/src/being/being.cpp
index 2de362365..50875878b 100644
--- a/src/being/being.cpp
+++ b/src/being/being.cpp
@@ -517,8 +517,8 @@ void Being::setPosition(const Vector &restrict pos) restrict2
if (mText)
{
- mText->adviseXY(static_cast<int>(pos.x),
- static_cast<int>(pos.y) - getHeight() - mText->getHeight() - 6,
+ mText->adviseXY(CAST_S32(pos.x),
+ CAST_S32(pos.y) - getHeight() - mText->getHeight() - 6,
mMoveNames);
}
}
@@ -581,11 +581,11 @@ void Being::setSpeech(const std::string &restrict text,
{
const size_t sz = mSpeech.size();
if (sz < 200)
- time = static_cast<int>(SPEECH_TIME - 300 + (3 * sz));
+ time = CAST_S32(SPEECH_TIME - 300 + (3 * sz));
}
- if (time < static_cast<int>(SPEECH_MIN_TIME))
- time = static_cast<int>(SPEECH_MIN_TIME);
+ if (time < CAST_S32(SPEECH_MIN_TIME))
+ time = CAST_S32(SPEECH_MIN_TIME);
// Check for links
size_t start = mSpeech.find('[');
@@ -620,8 +620,8 @@ void Being::setSpeech(const std::string &restrict text,
if (!mSpeech.empty())
{
- mSpeechTime = time <= static_cast<int>(SPEECH_MAX_TIME)
- ? time : static_cast<int>(SPEECH_MAX_TIME);
+ mSpeechTime = time <= CAST_S32(SPEECH_MAX_TIME)
+ ? time : CAST_S32(SPEECH_MAX_TIME);
}
const int speech = mSpeechType;
@@ -1545,7 +1545,7 @@ void Being::setAction(const BeingActionT &restrict action,
case BeingAction::PRESTAND:
default:
logger->log("Being::setAction unknown action: "
- + toString(static_cast<unsigned>(action)));
+ + toString(CAST_U32(action)));
break;
}
@@ -1696,7 +1696,7 @@ void Being::nextTile() restrict2
return;
}
- mActionTime += static_cast<int>(mSpeed / 10);
+ mActionTime += CAST_S32(mSpeed / 10);
if ((mType != ActorType::Player || mUseDiagonal)
&& mX != pos.x && mY != pos.y)
{
@@ -1752,7 +1752,7 @@ void Being::logic() restrict2
sprite->update(time);
}
- int frameCount = static_cast<int>(getFrameCount());
+ int frameCount = CAST_S32(getFrameCount());
switch (mAction)
{
@@ -1845,7 +1845,7 @@ void Being::logic() restrict2
frameCount = 10;
if (!isAlive() && mSpeed && gameHandler->removeDeadBeings()
- && static_cast<int> ((static_cast<float>(get_elapsed_time(mActionTime))
+ && CAST_S32 ((static_cast<float>(get_elapsed_time(mActionTime))
/ mSpeed)) >= frameCount)
{
if (mType != ActorType::Player && actorManager)
@@ -1882,7 +1882,7 @@ void Being::petLogic() restrict2
const int time = tick_time;
const int thinkTime = mInfo->getThinkTime();
- if (abs(static_cast<int>(mMoveTime) - time) < thinkTime)
+ if (abs(CAST_S32(mMoveTime) - time) < thinkTime)
return;
mMoveTime = time;
@@ -2161,9 +2161,9 @@ int Being::getOffset(const signed char pos,
const int time = get_elapsed_time(mActionTime);
offset = (pos == BeingDirection::LEFT
&& neg == BeingDirection::RIGHT) ?
- static_cast<int>((static_cast<float>(time)
+ CAST_S32((static_cast<float>(time)
* static_cast<float>(mMap->getTileWidth())) / mSpeed) :
- static_cast<int>((static_cast<float>(time)
+ CAST_S32((static_cast<float>(time)
* static_cast<float>(mMap->getTileHeight())) / mSpeed);
}
@@ -2440,7 +2440,7 @@ void Being::updateSprite(const unsigned int slot,
if (!charServerHandler || slot >= charServerHandler->maxSprite())
return;
- if (slot >= static_cast<unsigned int>(mSpriteIDs.size()))
+ if (slot >= CAST_U32(mSpriteIDs.size()))
mSpriteIDs.resize(slot + 1, 0);
if (slot && mSpriteIDs[slot] == id)
@@ -2458,16 +2458,16 @@ void Being::setSprite(const unsigned int slot,
if (!charServerHandler || slot >= charServerHandler->maxSprite())
return;
- if (slot >= static_cast<unsigned int>(size()))
+ if (slot >= CAST_U32(size()))
ensureSize(slot + 1);
- if (slot >= static_cast<unsigned int>(mSpriteIDs.size()))
+ if (slot >= CAST_U32(mSpriteIDs.size()))
mSpriteIDs.resize(slot + 1, 0);
- if (slot >= static_cast<unsigned int>(mSpriteColors.size()))
+ if (slot >= CAST_U32(mSpriteColors.size()))
mSpriteColors.resize(slot + 1, "");
- if (slot >= static_cast<unsigned int>(mSpriteColorsIds.size()))
+ if (slot >= CAST_U32(mSpriteColorsIds.size()))
mSpriteColorsIds.resize(slot + 1, ItemColor_one);
// disabled for now, because it may broke replace/reorder sprites logic
@@ -2654,7 +2654,7 @@ void Being::reReadConfig()
mHideErased = config.getBoolValue("hideErased");
mMoveNames = fromBool(config.getBoolValue("moveNames"), Move);
mUseDiagonal = config.getBoolValue("useDiagonalSpeed");
- mShowBadges = static_cast<uint8_t>(config.getIntValue("showBadges"));
+ mShowBadges = CAST_U8(config.getIntValue("showBadges"));
mUpdateConfigTime = cur_time;
}
@@ -2783,7 +2783,7 @@ void Being::setGender(const GenderT gender) restrict2
// Reload all subsprites
for (unsigned int i = 0;
- i < static_cast<unsigned int>(mSpriteIDs.size());
+ i < CAST_U32(mSpriteIDs.size());
i++)
{
if (mSpriteIDs.at(i) != 0)
@@ -2901,7 +2901,7 @@ void Being::drawSprites(Graphics *restrict const graphics,
void Being::drawSpritesSDL(Graphics *restrict const graphics,
int posX, int posY) const restrict2
{
- const unsigned int sz = static_cast<unsigned int>(size());
+ const unsigned int sz = CAST_U32(size());
for (unsigned int f = 0; f < sz; f ++)
{
const int rSprite = mSpriteHide[mSpriteRemap[f]];
@@ -3134,7 +3134,7 @@ void Being::recalcSpritesOrder() restrict2
for (size_t slot = 0; slot < sz; slot ++)
{
- slotRemap.push_back(static_cast<int>(slot));
+ slotRemap.push_back(CAST_S32(slot));
if (spriteIdSize <= slot)
continue;
@@ -3177,7 +3177,7 @@ void Being::recalcSpritesOrder() restrict2
mSpriteHide[remSprite] = repIt->second;
if (repIt->second != 1)
{
- if (static_cast<unsigned>(remSprite)
+ if (CAST_U32(remSprite)
!= hairSlot)
{
setSprite(remSprite, repIt->second,
@@ -3299,7 +3299,7 @@ void Being::recalcSpritesOrder() restrict2
const int val = slotRemap.at(slot);
int id = 0;
- if (static_cast<int>(spriteIdSize) > val)
+ if (CAST_S32(spriteIdSize) > val)
id = mSpriteIDs[val];
int idx = -1;
@@ -3404,7 +3404,7 @@ int Being::searchSlotValue(const std::vector<int> &restrict slotRemap,
for (size_t slot = 0; slot < sz; slot ++)
{
if (slotRemap[slot] == val)
- return static_cast<int>(slot);
+ return CAST_S32(slot);
}
return getNumberOfLayers() - 1;
}
@@ -3461,7 +3461,7 @@ void Being::undressItemById(const int id) restrict2
{
if (id == mSpriteIDs[f])
{
- setSprite(static_cast<unsigned int>(f), 0);
+ setSprite(CAST_U32(f), 0);
break;
}
}
@@ -3677,7 +3677,7 @@ GenderT Being::intToGender(const uint8_t sex)
int Being::getSpriteID(const int slot) const restrict2
{
- if (slot < 0 || static_cast<size_t>(slot) >= mSpriteIDs.size())
+ if (slot < 0 || CAST_SIZE(slot) >= mSpriteIDs.size())
return -1;
return mSpriteIDs[slot];
@@ -3685,7 +3685,7 @@ int Being::getSpriteID(const int slot) const restrict2
ItemColor Being::getSpriteColor(const int slot) const restrict2
{
- if (slot < 0 || static_cast<size_t>(slot) >= mSpriteColorsIds.size())
+ if (slot < 0 || CAST_SIZE(slot) >= mSpriteColorsIds.size())
return ItemColor_one;
return mSpriteColorsIds[slot];
diff --git a/src/being/being.h b/src/being/being.h
index c91cac5b9..ee073977b 100644
--- a/src/being/being.h
+++ b/src/being/being.h
@@ -286,7 +286,7 @@ class Being notfinal : public ActorSprite,
* Get number of guilds the being belongs to.
*/
int16_t getNumberOfGuilds() const restrict2 A_WARN_UNUSED
- { return static_cast<int16_t>(mGuilds.size()); }
+ { return CAST_S16(mGuilds.size()); }
bool isInParty() const restrict2 noexcept A_WARN_UNUSED
{ return mParty; }
@@ -301,7 +301,7 @@ class Being notfinal : public ActorSprite,
{ return mParty; }
int getSpritesCount() const restrict2 A_WARN_UNUSED
- { return static_cast<int>(size()); }
+ { return CAST_S32(size()); }
/**
* Sets visible equipments for this being.
@@ -891,8 +891,8 @@ class Being notfinal : public ActorSprite,
void setPath(const Path &restrict path) restrict2;
int getSortPixelY() const restrict2 override A_WARN_UNUSED
- { return static_cast<int>(mPos.y) - mYDiff - mSortOffsetY; }
-// { return static_cast<int>(mPos.y) - mYDiff - mSortOffsetY + 16; }
+ { return CAST_S32(mPos.y) - mYDiff - mSortOffsetY; }
+// { return CAST_S32(mPos.y) - mYDiff - mSortOffsetY + 16; }
void setMap(Map *restrict const map) restrict2 override;
diff --git a/src/being/compoundsprite.cpp b/src/being/compoundsprite.cpp
index df3cfcec0..110870c07 100644
--- a/src/being/compoundsprite.cpp
+++ b/src/being/compoundsprite.cpp
@@ -232,7 +232,7 @@ int CompoundSprite::getNumberOfLayers() const
if (mImage || mAlphaImage)
return 1;
else
- return static_cast<int>(size());
+ return CAST_S32(size());
}
unsigned int CompoundSprite::getCurrentFrame() const
@@ -312,7 +312,7 @@ void CompoundSprite::ensureSize(size_t layerCount)
*/
unsigned int CompoundSprite::getCurrentFrame(unsigned int layer) const
{
- if (layer >= static_cast<unsigned int>(mSprites.size()))
+ if (layer >= CAST_U32(mSprites.size()))
return 0;
const Sprite *const s = getSprite(layer);
@@ -327,7 +327,7 @@ unsigned int CompoundSprite::getCurrentFrame(unsigned int layer) const
*/
unsigned int CompoundSprite::getFrameCount(unsigned int layer)
{
- if (layer >= static_cast<unsigned int>(mSprites.size()))
+ if (layer >= CAST_U32(mSprites.size()))
return 0;
const Sprite *const s = getSprite(layer);
diff --git a/src/being/crazymoves.cpp b/src/being/crazymoves.cpp
index 34441d6e6..3eb3fd3f4 100644
--- a/src/being/crazymoves.cpp
+++ b/src/being/crazymoves.cpp
@@ -738,17 +738,17 @@ void CrazyMoves::crazyMoveAe()
if (emo == '?')
{
srand(tick_time);
- emoteId = static_cast<unsigned char>(
+ emoteId = CAST_U8(
1 + (rand() % EmoteDB::size()));
}
else
{
if (emo >= '0' && emo <= '9')
- emoteId = static_cast<unsigned char>(emo - '0' + 1);
+ emoteId = CAST_U8(emo - '0' + 1);
else if (emo >= 'a' && emo <= 'z')
- emoteId = static_cast<unsigned char>(emo - 'a' + 11);
+ emoteId = CAST_U8(emo - 'a' + 11);
else if (emo >= 'A' && emo <= 'Z')
- emoteId = static_cast<unsigned char>(emo - 'A' + 37);
+ emoteId = CAST_U8(emo - 'A' + 37);
}
if (mMoveProgram[settings.crazyMoveState - 1] == 'e')
localPlayer->emote(emoteId);
diff --git a/src/being/localplayer.cpp b/src/being/localplayer.cpp
index 1d0fd92aa..f59af9c10 100644
--- a/src/being/localplayer.cpp
+++ b/src/being/localplayer.cpp
@@ -190,7 +190,7 @@ LocalPlayer::LocalPlayer(const BeingId id,
mNameColor = nullptr;
PlayerInfo::setStatBase(Attributes::WALK_SPEED,
- static_cast<int>(getWalkSpeed().x));
+ CAST_S32(getWalkSpeed().x));
PlayerInfo::setStatMod(Attributes::WALK_SPEED, 0);
loadHomes();
@@ -300,9 +300,9 @@ void LocalPlayer::logic()
else
{
// Find whether target is in range
- const int rangeX = static_cast<int>(
+ const int rangeX = CAST_S32(
abs(mTarget->getTileX() - getTileX()));
- const int rangeY = static_cast<int>(
+ const int rangeY = CAST_S32(
abs(mTarget->getTileY() - getTileY()));
const int attackRange = getAttackRange();
const TargetCursorTypeT targetType
@@ -391,7 +391,7 @@ void LocalPlayer::setAction(const BeingActionT &action,
Being::setAction(action, attackType);
#ifdef USE_MUMBLE
if (mumbleManager)
- mumbleManager->setAction(static_cast<int>(action));
+ mumbleManager->setAction(CAST_S32(action));
#endif
}
@@ -498,8 +498,8 @@ bool LocalPlayer::pickUp(FloorItem *const item)
{
const Vector &playerPos = getPosition();
const Path debugPath = mMap->findPath(
- static_cast<int>(playerPos.x - mapTileSize / 2) / mapTileSize,
- static_cast<int>(playerPos.y - mapTileSize) / mapTileSize,
+ CAST_S32(playerPos.x - mapTileSize / 2) / mapTileSize,
+ CAST_S32(playerPos.y - mapTileSize) / mapTileSize,
item->getTileX(), item->getTileY(), getBlockWalkMask(), 0);
if (!debugPath.empty())
navigateTo(item->getTileX(), item->getTileY());
@@ -684,13 +684,13 @@ void LocalPlayer::stopWalking(const bool sendToServer)
mWalkingDir = 0;
mPickUpTarget = nullptr;
- setDestination(static_cast<int>(getPosition().x),
- static_cast<int>(getPosition().y));
+ setDestination(CAST_S32(getPosition().x),
+ CAST_S32(getPosition().y));
if (sendToServer)
{
playerHandler->setDestination(
- static_cast<int>(getPosition().x),
- static_cast<int>(getPosition().y), -1);
+ CAST_S32(getPosition().x),
+ CAST_S32(getPosition().y), -1);
}
setAction(BeingAction::STAND);
}
@@ -968,8 +968,8 @@ bool LocalPlayer::withinAttackRange(const Being *const target,
if (fixDistance && range == 1)
range = 2;
- dx = static_cast<int>(abs(target->getTileX() - mX));
- dy = static_cast<int>(abs(target->getTileY() - mY));
+ dx = CAST_S32(abs(target->getTileX() - mX));
+ dy = CAST_S32(abs(target->getTileY() - mY));
return !(dx > range || dy > range);
}
@@ -1005,7 +1005,7 @@ void LocalPlayer::handleStatusEffect(const StatusEffect *const effect,
{
mStatusEffectIcons.erase(mStatusEffectIcons.begin() + i);
if (miniStatusWindow)
- miniStatusWindow->eraseIcon(static_cast<int>(i));
+ miniStatusWindow->eraseIcon(CAST_S32(i));
}
else
{
@@ -1023,7 +1023,7 @@ void LocalPlayer::handleStatusEffect(const StatusEffect *const effect,
if (mStatusEffectIcons[i] == effectId)
{
if (miniStatusWindow)
- miniStatusWindow->setIcon(static_cast<int>(i), sprite);
+ miniStatusWindow->setIcon(CAST_S32(i), sprite);
found = true;
break;
}
@@ -1031,7 +1031,7 @@ void LocalPlayer::handleStatusEffect(const StatusEffect *const effect,
if (!found)
{ // add new
- const int offset = static_cast<int>(mStatusEffectIcons.size());
+ const int offset = CAST_S32(mStatusEffectIcons.size());
if (miniStatusWindow)
miniStatusWindow->setIcon(offset, sprite);
mStatusEffectIcons.push_back(effectId);
@@ -1228,9 +1228,9 @@ void LocalPlayer::moveToTarget(int dist)
{
if (mMap)
{
- debugPath = mMap->findPath(static_cast<int>(
+ debugPath = mMap->findPath(CAST_S32(
playerPos.x - mapTileSize / 2) / mapTileSize,
- static_cast<int>(playerPos.y - mapTileSize) / mapTileSize,
+ CAST_S32(playerPos.y - mapTileSize) / mapTileSize,
mTarget->getTileX(),
mTarget->getTileY(),
getBlockWalkMask(),
@@ -1238,9 +1238,9 @@ void LocalPlayer::moveToTarget(int dist)
}
const size_t sz = debugPath.size();
- if (sz < static_cast<size_t>(dist))
+ if (sz < CAST_SIZE(dist))
return;
- limit = static_cast<int>(sz) - dist;
+ limit = CAST_S32(sz) - dist;
gotPos = true;
}
else if (mNavigateX || mNavigateY)
@@ -1295,13 +1295,13 @@ void LocalPlayer::moveToHome()
if (mX == pos.x && mY == pos.y)
{
playerHandler->setDestination(
- static_cast<int>(pos.x),
- static_cast<int>(pos.y),
- static_cast<int>(mDirection));
+ CAST_S32(pos.x),
+ CAST_S32(pos.y),
+ CAST_S32(mDirection));
}
else
{
- navigateTo(static_cast<int>(pos.x), static_cast<int>(pos.y));
+ navigateTo(CAST_S32(pos.x), CAST_S32(pos.y));
}
}
}
@@ -1416,11 +1416,11 @@ bool LocalPlayer::isReachable(Being *const being,
const Vector &playerPos = getPosition();
const Path debugPath = mMap->findPath(
- static_cast<int>(playerPos.x - mapTileSize / 2) / mapTileSize,
- static_cast<int>(playerPos.y - mapTileSize) / mapTileSize,
+ CAST_S32(playerPos.x - mapTileSize / 2) / mapTileSize,
+ CAST_S32(playerPos.y - mapTileSize) / mapTileSize,
being->getTileX(), being->getTileY(), getBlockWalkMask(), maxCost);
- being->setDistance(static_cast<int>(debugPath.size()));
+ being->setDistance(CAST_S32(debugPath.size()));
if (!debugPath.empty())
{
being->setReachable(Reachable::REACH_YES);
@@ -1704,26 +1704,26 @@ void LocalPlayer::setHome()
if (iter != mHomes.end())
{
- socialWindow->removePortal(static_cast<int>(pos.x),
- static_cast<int>(pos.y));
+ socialWindow->removePortal(CAST_S32(pos.x),
+ CAST_S32(pos.y));
}
- if (iter != mHomes.end() && mX == static_cast<int>(pos.x)
- && mY == static_cast<int>(pos.y))
+ if (iter != mHomes.end() && mX == CAST_S32(pos.x)
+ && mY == CAST_S32(pos.y))
{
mMap->updatePortalTile("", MapItemType::EMPTY,
- static_cast<int>(pos.x), static_cast<int>(pos.y));
+ CAST_S32(pos.x), CAST_S32(pos.y));
mHomes.erase(key);
- socialWindow->removePortal(static_cast<int>(pos.x),
- static_cast<int>(pos.y));
+ socialWindow->removePortal(CAST_S32(pos.x),
+ CAST_S32(pos.y));
}
else
{
if (iter != mHomes.end())
{
- specialLayer->setTile(static_cast<int>(pos.x),
- static_cast<int>(pos.y), MapItemType::EMPTY);
+ specialLayer->setTile(CAST_S32(pos.x),
+ CAST_S32(pos.y), MapItemType::EMPTY);
}
pos.x = static_cast<float>(mX);
@@ -1958,8 +1958,8 @@ bool LocalPlayer::navigateTo(const int x, const int y)
const Vector &playerPos = getPosition();
mShowNavigePath = true;
- mOldX = static_cast<int>(playerPos.x);
- mOldY = static_cast<int>(playerPos.y);
+ mOldX = CAST_S32(playerPos.x);
+ mOldY = CAST_S32(playerPos.y);
mOldTileX = mX;
mOldTileY = mY;
mNavigateX = x;
@@ -1967,8 +1967,8 @@ bool LocalPlayer::navigateTo(const int x, const int y)
mNavigateId = BeingId_zero;
mNavigatePath = mMap->findPath(
- static_cast<int>(playerPos.x - mapTileSize / 2) / mapTileSize,
- static_cast<int>(playerPos.y - mapTileSize) / mapTileSize,
+ CAST_S32(playerPos.x - mapTileSize / 2) / mapTileSize,
+ CAST_S32(playerPos.y - mapTileSize) / mapTileSize,
x, y, getBlockWalkMask(), 0);
if (mDrawPath)
@@ -2042,9 +2042,9 @@ void LocalPlayer::updateCoords()
if (!tmpLayer)
return;
- const int x = static_cast<int>(playerPos.x - mapTileSize / 2)
+ const int x = CAST_S32(playerPos.x - mapTileSize / 2)
/ mapTileSize;
- const int y = static_cast<int>(playerPos.y - mapTileSize)
+ const int y = CAST_S32(playerPos.y - mapTileSize)
/ mapTileSize;
if (mNavigateId != BeingId_zero)
{
@@ -2090,8 +2090,8 @@ void LocalPlayer::updateCoords()
}
}
}
- mOldX = static_cast<int>(playerPos.x);
- mOldY = static_cast<int>(playerPos.y);
+ mOldX = CAST_S32(playerPos.x);
+ mOldY = CAST_S32(playerPos.y);
mOldTileX = mX;
mOldTileY = mY;
}
@@ -2132,16 +2132,16 @@ int LocalPlayer::getPathLength(const Being *const being) const
if (mTargetOnlyReachable)
{
const Path debugPath = mMap->findPath(
- static_cast<int>(playerPos.x - mapTileSize / 2) / mapTileSize,
- static_cast<int>(playerPos.y - mapTileSize) / mapTileSize,
+ CAST_S32(playerPos.x - mapTileSize / 2) / mapTileSize,
+ CAST_S32(playerPos.y - mapTileSize) / mapTileSize,
being->getTileX(), being->getTileY(),
getBlockWalkMask(), 0);
- return static_cast<int>(debugPath.size());
+ return CAST_S32(debugPath.size());
}
else
{
- const int dx = static_cast<int>(abs(being->mX - mX));
- const int dy = static_cast<int>(abs(being->mY - mY));
+ const int dx = CAST_S32(abs(being->mX - mX));
+ const int dy = CAST_S32(abs(being->mY - mY));
if (dx > dy)
return dx;
return dy;
@@ -2513,8 +2513,8 @@ void LocalPlayer::fixAttackTarget()
const Vector &playerPos = getPosition();
const Path debugPath = mMap->findPath(
- static_cast<int>(playerPos.x - mapTileSize / 2) / mapTileSize,
- static_cast<int>(playerPos.y - mapTileSize) / mapTileSize,
+ CAST_S32(playerPos.x - mapTileSize / 2) / mapTileSize,
+ CAST_S32(playerPos.y - mapTileSize) / mapTileSize,
mTarget->getTileX(), mTarget->getTileY(),
getBlockWalkMask(), 0);
@@ -2548,7 +2548,7 @@ void LocalPlayer::updateNavigateList()
if (pos.x && pos.y)
{
mMap->addPortalTile("home", MapItemType::HOME,
- static_cast<int>(pos.x), static_cast<int>(pos.y));
+ CAST_S32(pos.x), CAST_S32(pos.y));
}
}
}
diff --git a/src/being/playerrelations.cpp b/src/being/playerrelations.cpp
index d124ba1dd..d996b03e3 100644
--- a/src/being/playerrelations.cpp
+++ b/src/being/playerrelations.cpp
@@ -86,7 +86,7 @@ namespace
return nullptr;
cobj->setValue(NAME, value.first);
cobj->setValue(RELATION, toString(
- static_cast<int>(value.second->mRelation)));
+ CAST_S32(value.second->mRelation)));
return cobj;
}
@@ -105,7 +105,7 @@ namespace
if (!(*container)[name])
{
const int v = cobj->getValueInt(RELATION,
- static_cast<int>(Relation::NEUTRAL));
+ CAST_S32(Relation::NEUTRAL));
(*container)[name] = new PlayerRelation(
static_cast<RelationT>(v));
@@ -175,7 +175,7 @@ int PlayerRelationsManager::getPlayerIgnoreStrategyIndex(
for (size_t i = 0; i < sz; i++)
{
if ((*strategies)[i]->mShortName == name)
- return static_cast<int>(i);
+ return CAST_S32(i);
}
return -1;
@@ -191,7 +191,7 @@ void PlayerRelationsManager::load(const bool oldConfig)
clear();
mPersistIgnores = cfg->getValue(PERSIST_IGNORE_LIST, 1);
- mDefaultPermissions = static_cast<int>(cfg->getValue(DEFAULT_PERMISSIONS,
+ mDefaultPermissions = CAST_S32(cfg->getValue(DEFAULT_PERMISSIONS,
mDefaultPermissions));
const std::string ignore_strategy_name = cfg->getValue(
@@ -271,7 +271,7 @@ unsigned int PlayerRelationsManager::checkPermissionSilently(
{
const PlayerRelation *const r = (*it).second;
unsigned int permissions = PlayerRelation::RELATION_PERMISSIONS[
- static_cast<int>(r->mRelation)];
+ CAST_S32(r->mRelation)];
switch (r->mRelation)
{
diff --git a/src/beingequipbackend.cpp b/src/beingequipbackend.cpp
index a12e961db..c078f9b7e 100644
--- a/src/beingequipbackend.cpp
+++ b/src/beingequipbackend.cpp
@@ -40,7 +40,7 @@ BeingEquipBackend::BeingEquipBackend(Being *const being)
for (size_t f = 0; f < sz; f ++)
{
const int idx = inventoryHandler->
- convertFromServerSlot(static_cast<int>(f));
+ convertFromServerSlot(CAST_S32(f));
const int id = being->mSpriteIDs[f];
if (id > 0 && idx >= 0 && idx < EQUIPMENT_SIZE)
{
diff --git a/src/chatlogger.cpp b/src/chatlogger.cpp
index 4fa17c5bb..9e3329f9a 100644
--- a/src/chatlogger.cpp
+++ b/src/chatlogger.cpp
@@ -208,7 +208,7 @@ void ChatLogger::loadLast(std::string name,
return;
char line[710];
- unsigned sz = static_cast<unsigned>(list.size());
+ unsigned sz = CAST_U32(list.size());
while (logFile.getline(line, 700))
{
list.push_back(line);
diff --git a/src/client.cpp b/src/client.cpp
index c4d879355..9a2494bc0 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -439,8 +439,8 @@ void Client::gameInit()
if (mCurrentServer.port == 0)
{
- mCurrentServer.port = static_cast<uint16_t>(branding.getValue(
- "defaultPort", static_cast<int>(DEFAULT_PORT)));
+ mCurrentServer.port = CAST_U16(branding.getValue(
+ "defaultPort", CAST_S32(DEFAULT_PORT)));
mCurrentServer.type = ServerInfo::parseType(
branding.getValue("defaultServerType", "tmwathena"));
}
@@ -465,7 +465,7 @@ void Client::gameInit()
settings.guiAlpha = config.getFloatValue("guialpha");
optionChanged("fpslimit");
- start_time = static_cast<int>(time(nullptr));
+ start_time = CAST_S32(time(nullptr));
PlayerInfo::init();
@@ -880,7 +880,7 @@ int Client::gameExec()
BLOCK_START("Client::gameExec 4")
if (gui)
gui->logic();
- cur_time = static_cast<int>(time(nullptr));
+ cur_time = CAST_S32(time(nullptr));
int k = 0;
while (lastTickTime != tick_time &&
k < 40)
@@ -1094,7 +1094,7 @@ int Client::gameExec()
mSearchHash = Net::Download::adlerBuffer(
const_cast<char*>(mCurrentServer.hostname.c_str()),
- static_cast<int>(mCurrentServer.hostname.size()));
+ CAST_S32(mCurrentServer.hostname.size()));
if (settings.options.username.empty() ||
settings.options.password.empty())
{
@@ -1929,8 +1929,8 @@ void Client::extractAssets()
for (int f = 0; f < 100; f ++)
{
std::string part = strprintf("manaplus-data.zip%u%u",
- static_cast<unsigned int>(f / 10),
- static_cast<unsigned int>(f % 10));
+ CAST_U32(f / 10),
+ CAST_U32(f % 10));
logger->log("testing asset: " + part);
SDL_RWops *const rw = SDL_RWFromFile(part.c_str(), "r");
if (rw)
diff --git a/src/commandline.cpp b/src/commandline.cpp
index 95d336d34..110aa60f5 100644
--- a/src/commandline.cpp
+++ b/src/commandline.cpp
@@ -204,7 +204,7 @@ void parseOptions(const int argc, char *const argv[])
options.serverName = optarg;
break;
case 'p':
- options.serverPort = static_cast<uint16_t>(atoi(optarg));
+ options.serverPort = CAST_U16(atoi(optarg));
break;
case 'u':
options.skipUpdate = true;
@@ -242,7 +242,7 @@ void parseOptions(const int argc, char *const argv[])
options.test = std::string(optarg);
break;
case 'r':
- options.renderer = static_cast<int>(atoi(optarg));
+ options.renderer = CAST_S32(atoi(optarg));
break;
case 'y':
options.serverType = optarg;
diff --git a/src/configmanager.cpp b/src/configmanager.cpp
index b5e80e5e9..b412d1044 100644
--- a/src/configmanager.cpp
+++ b/src/configmanager.cpp
@@ -89,16 +89,16 @@ void ConfigManager::initConfiguration()
config.setValue("hwaccel", false);
#ifdef USE_OPENGL
#if (defined __APPLE__)
- config.setValue("opengl", static_cast<int>(RENDER_NORMAL_OPENGL));
+ config.setValue("opengl", CAST_S32(RENDER_NORMAL_OPENGL));
#elif (defined ANDROID)
- config.setValue("opengl", static_cast<int>(RENDER_GLES_OPENGL));
+ config.setValue("opengl", CAST_S32(RENDER_GLES_OPENGL));
#elif (defined WIN32)
- config.setValue("opengl", static_cast<int>(RENDER_SAFE_OPENGL));
+ config.setValue("opengl", CAST_S32(RENDER_SAFE_OPENGL));
#else
- config.setValue("opengl", static_cast<int>(RENDER_SOFTWARE));
+ config.setValue("opengl", CAST_S32(RENDER_SOFTWARE));
#endif
#else
- config.setValue("opengl", static_cast<int>(RENDER_SOFTWARE));
+ config.setValue("opengl", CAST_S32(RENDER_SOFTWARE));
#endif
config.setValue("screen", false);
config.setValue("sound", true);
@@ -174,7 +174,7 @@ void ConfigManager::storeSafeParameters()
tmpOpengl = intToRenderType(config.getIntValue("opengl"));
- config.setValue("opengl", static_cast<int>(RENDER_SOFTWARE));
+ config.setValue("opengl", CAST_S32(RENDER_SOFTWARE));
config.write();
@@ -185,7 +185,7 @@ void ConfigManager::storeSafeParameters()
}
config.setValue("safemode", false);
- config.setValue("opengl", static_cast<int>(tmpOpengl));
+ config.setValue("opengl", CAST_S32(tmpOpengl));
}
#elif !defined(ANDROID)
void ConfigManager::storeSafeParameters()
@@ -264,9 +264,9 @@ void ConfigManager::storeSafeParameters()
config.setValue("screenheight", 480);
}
#if defined(__APPLE__)
- config.setValue("opengl", static_cast<int>(RENDER_NORMAL_OPENGL));
+ config.setValue("opengl", CAST_S32(RENDER_NORMAL_OPENGL));
#else
- config.setValue("opengl", static_cast<int>(RENDER_SOFTWARE));
+ config.setValue("opengl", CAST_S32(RENDER_SOFTWARE));
#endif
config.write();
@@ -281,7 +281,7 @@ void ConfigManager::storeSafeParameters()
if (!tmpOpengl)
{
config.setValue("hwaccel", tmpHwaccel);
- config.setValue("opengl", static_cast<int>(tmpOpengl));
+ config.setValue("opengl", CAST_S32(tmpOpengl));
config.setValue("fpslimit", tmpFpslimit);
config.setValue("altfpslimit", tmpAltFpslimit);
config.setValue("sound", tmpSound);
@@ -301,7 +301,7 @@ void ConfigManager::storeSafeParameters()
}
else
{
- config.setValue("opengl", static_cast<int>(tmpOpengl));
+ config.setValue("opengl", CAST_S32(tmpOpengl));
config.setValue("screenwidth", width);
config.setValue("screenheight", height);
}
@@ -346,7 +346,7 @@ void ConfigManager::checkConfigVersion()
{
if (config.getIntValue("speech") == BeingSpeech::TEXT_OVERHEAD)
{
- config.setValue("speech", static_cast<int>(
+ config.setValue("speech", CAST_S32(
BeingSpeech::NO_NAME_IN_BUBBLE));
}
}
diff --git a/src/configuration.cpp b/src/configuration.cpp
index da80e9f8f..f70af1c3e 100644
--- a/src/configuration.cpp
+++ b/src/configuration.cpp
@@ -300,7 +300,7 @@ unsigned ConfigurationObject::getValue(const std::string &key,
{
GETLOG();
const Options::const_iterator iter = mOptions.find(key);
- return (iter != mOptions.end()) ? static_cast<unsigned>(
+ return (iter != mOptions.end()) ? CAST_U32(
atol(iter->second.c_str())) : deflt;
}
@@ -441,7 +441,7 @@ int Configuration::getIntValue(const std::string &key) const
}
else if (type == VariableData::DATA_FLOAT)
{
- defaultValue = static_cast<int>(
+ defaultValue = CAST_S32(
(static_cast<const FloatData*>(data))->getData());
}
}
@@ -635,7 +635,7 @@ bool Configuration::getBoolValue(const std::string &key) const
}
if (type == VariableData::DATA_FLOAT)
{
- if (static_cast<int>((static_cast<const FloatData*>(
+ if (CAST_S32((static_cast<const FloatData*>(
data))->getData()) != 0)
{
defaultValue = true;
diff --git a/src/debug/debug_new.cpp b/src/debug/debug_new.cpp
index f8c9dc73c..1a8f79a64 100644
--- a/src/debug/debug_new.cpp
+++ b/src/debug/debug_new.cpp
@@ -516,7 +516,7 @@ static void* alloc_mem(size_t size, const char* file, int line, bool is_array)
fprintf(new_output_fp,
"new%s: allocated %p (size %u, ",
is_array ? "[]" : "",
- pointer, static_cast<unsigned>(size));
+ pointer, CAST_U32(size));
if (line != 0)
print_position(ptr->file, ptr->line);
else
@@ -566,7 +566,7 @@ static void free_pointer(void* pointer, void* addr, bool is_array)
"%s: pointer %p (size %u)\n\tat ",
msg,
reinterpret_cast<char*>(ptr) + ALIGNED_LIST_ITEM_SIZE,
- static_cast<unsigned>(ptr->size));
+ CAST_U32(ptr->size));
print_position(addr, 0);
fprintf(new_output_fp, "\n\toriginally allocated at ");
if (ptr->line != 0)
@@ -599,8 +599,8 @@ static void free_pointer(void* pointer, void* addr, bool is_array)
"delete%s: freed %p (size %u, %u bytes still allocated)\n",
is_array ? "[]" : "",
reinterpret_cast<char*>(ptr) + ALIGNED_LIST_ITEM_SIZE,
- static_cast<unsigned>(ptr->size),
- static_cast<unsigned>(total_mem_alloc));
+ CAST_U32(ptr->size),
+ CAST_U32(total_mem_alloc));
}
free(ptr);
return;
@@ -646,7 +646,7 @@ int check_leaks()
{
fprintf(new_output_fp,
"Leaked object at %p (size %u, dump %u, ",
- pointer, static_cast<unsigned>(ptr->size), ptr->dumped);
+ pointer, CAST_U32(ptr->size), ptr->dumped);
if (ptr->line != 0)
print_position(ptr->file, ptr->line);
else
@@ -704,7 +704,7 @@ int check_mem_corruption()
fprintf(new_output_fp,
"Heap data corrupt near %p (size %u, ",
pointer,
- static_cast<unsigned>(ptr->size));
+ CAST_U32(ptr->size));
#if M_DEBUG_NEW_TAILCHECK
}
else
diff --git a/src/defaults.cpp b/src/defaults.cpp
index f8bf51394..095bf6c74 100644
--- a/src/defaults.cpp
+++ b/src/defaults.cpp
@@ -83,7 +83,7 @@ DefaultsData* getConfigDefaults()
AddDEF("speechBubbleAlpha", 1.0F);
AddDEF("MostUsedServerName0", "server.themanaworld.org");
AddDEF("visiblenames", true);
- AddDEF("speech", static_cast<int>(BeingSpeech::NO_NAME_IN_BUBBLE));
+ AddDEF("speech", CAST_S32(BeingSpeech::NO_NAME_IN_BUBBLE));
AddDEF("showgender", true);
AddDEF("showlevel", false);
AddDEF("showMonstersTakedDamage", true);
@@ -325,25 +325,25 @@ DefaultsData* getConfigDefaults()
AddDEF("selfMouseHeal", true);
AddDEF("serverslistupdate", "");
AddDEF("fadeoutmusic", true);
- AddDEF("screenActionKeyboard", static_cast<int>(
+ AddDEF("screenActionKeyboard", CAST_S32(
InputAction::SHOW_KEYBOARD));
- AddDEF("screenActionButton0", static_cast<int>(InputAction::TALK));
- AddDEF("screenActionButton1", static_cast<int>(
+ AddDEF("screenActionButton0", CAST_S32(InputAction::TALK));
+ AddDEF("screenActionButton1", CAST_S32(
InputAction::TARGET_ATTACK));
- AddDEF("screenActionButton2", static_cast<int>(InputAction::PICKUP));
- AddDEF("screenActionButton3", static_cast<int>(InputAction::STOP_SIT));
- AddDEF("screenActionButton4", static_cast<int>(InputAction::TARGET_NPC));
- AddDEF("screenActionButton5", static_cast<int>(
+ AddDEF("screenActionButton2", CAST_S32(InputAction::PICKUP));
+ AddDEF("screenActionButton3", CAST_S32(InputAction::STOP_SIT));
+ AddDEF("screenActionButton4", CAST_S32(InputAction::TARGET_NPC));
+ AddDEF("screenActionButton5", CAST_S32(
InputAction::WINDOW_STATUS));
- AddDEF("screenActionButton6", static_cast<int>(
+ AddDEF("screenActionButton6", CAST_S32(
InputAction::WINDOW_INVENTORY));
- AddDEF("screenActionButton7", static_cast<int>(InputAction::WINDOW_SKILL));
- AddDEF("screenActionButton8", static_cast<int>(
+ AddDEF("screenActionButton7", CAST_S32(InputAction::WINDOW_SKILL));
+ AddDEF("screenActionButton8", CAST_S32(
InputAction::WINDOW_SOCIAL));
- AddDEF("screenActionButton9", static_cast<int>(InputAction::WINDOW_DEBUG));
- AddDEF("screenActionButton10", static_cast<int>(
+ AddDEF("screenActionButton9", CAST_S32(InputAction::WINDOW_DEBUG));
+ AddDEF("screenActionButton10", CAST_S32(
InputAction::CHANGE_TRADE));
- AddDEF("screenActionButton11", static_cast<int>(InputAction::DIRECT_DOWN));
+ AddDEF("screenActionButton11", CAST_S32(InputAction::DIRECT_DOWN));
AddDEF("screenButtonsFormat", 0);
AddDEF("autoresizeminimaps", false);
AddDEF("showGuildOnline", false);
diff --git a/src/dirs.cpp b/src/dirs.cpp
index daf332b54..5f99ebd0e 100644
--- a/src/dirs.cpp
+++ b/src/dirs.cpp
@@ -108,8 +108,8 @@ void extractAssets()
for (int f = 0; f < 100; f ++)
{
std::string part = strprintf("manaplus-data.zip%u%u",
- static_cast<unsigned int>(f / 10),
- static_cast<unsigned int>(f % 10));
+ CAST_U32(f / 10),
+ CAST_U32(f % 10));
logger->log("testing asset: " + part);
SDL_RWops *const rw = SDL_RWFromFile(part.c_str(), "r");
if (rw)
@@ -236,9 +236,9 @@ void Dirs::mountDataDir()
#ifdef WIN32
const int loc1 = path.find_last_of('/');
const int loc2 = path.find_last_of('\\');
- const int loc = static_cast<int>(std::max(loc1, loc2));
+ const int loc = CAST_S32(std::max(loc1, loc2));
#else
- const int loc = static_cast<int>(path.find_last_of('/'));
+ const int loc = CAST_S32(path.find_last_of('/'));
#endif
if (loc > 0)
{
diff --git a/src/dyetool/client.cpp b/src/dyetool/client.cpp
index 8812b770b..fa4924df6 100644
--- a/src/dyetool/client.cpp
+++ b/src/dyetool/client.cpp
@@ -304,7 +304,7 @@ void Client::gameInit()
SDL_initFramerate(&fpsManager);
WindowManager::setFramerate(fpsLimit);
- start_time = static_cast<int>(time(nullptr));
+ start_time = CAST_S32(time(nullptr));
// PlayerInfo::init();
@@ -513,7 +513,7 @@ int Client::gameExec()
BLOCK_START("Client::gameExec 4")
if (gui)
gui->logic();
- cur_time = static_cast<int>(time(nullptr));
+ cur_time = CAST_S32(time(nullptr));
int k = 0;
while (lastTickTime != tick_time && k < 40)
{
diff --git a/src/enums/enums_unittest.cc b/src/enums/enums_unittest.cc
index 5c416a495..b1052908d 100644
--- a/src/enums/enums_unittest.cc
+++ b/src/enums/enums_unittest.cc
@@ -28,8 +28,8 @@
TEST_CASE("Gender", "Enums")
{
- REQUIRE(static_cast<int>(Gender::FEMALE) == 1);
+ REQUIRE(CAST_S32(Gender::FEMALE) == 1);
REQUIRE(Gender::FEMALE == static_cast<GenderT>(1));
- REQUIRE(static_cast<int>(Gender::MALE) == 0);
+ REQUIRE(CAST_S32(Gender::MALE) == 0);
REQUIRE(Gender::MALE == static_cast<GenderT>(0));
}
diff --git a/src/eventsmanager.cpp b/src/eventsmanager.cpp
index 8f3e7bdd4..a8d3ea582 100644
--- a/src/eventsmanager.cpp
+++ b/src/eventsmanager.cpp
@@ -220,8 +220,8 @@ void EventsManager::logEvent(const SDL_Event &event)
case SDL_MOUSEMOTION:
logger->log("event: SDL_MOUSEMOTION: %u,%d,%d",
event.motion.state,
- static_cast<int>(event.motion.x),
- static_cast<int>(event.motion.y));
+ CAST_S32(event.motion.x),
+ CAST_S32(event.motion.y));
break;
case SDL_FINGERDOWN:
{
@@ -229,8 +229,8 @@ void EventsManager::logEvent(const SDL_Event &event)
const int w = mainGraphics->mWidth;
const int h = mainGraphics->mHeight;
logger->log("event: SDL_FINGERDOWN: %u,%u (%f,%f) (%f,%f)",
- static_cast<unsigned int>(touch.touchId),
- static_cast<unsigned int>(touch.fingerId),
+ CAST_U32(touch.touchId),
+ CAST_U32(touch.fingerId),
touch.x * w, touch.y * w,
touch.dx * w, touch.dy * h);
break;
@@ -241,8 +241,8 @@ void EventsManager::logEvent(const SDL_Event &event)
const int w = mainGraphics->mWidth;
const int h = mainGraphics->mHeight;
logger->log("event: SDL_FINGERUP: %u,%u (%f,%f) (%f,%f)",
- static_cast<unsigned int>(touch.touchId),
- static_cast<unsigned int>(touch.fingerId),
+ CAST_U32(touch.touchId),
+ CAST_U32(touch.fingerId),
touch.x * w, touch.y * w,
touch.dx * w, touch.dy * h);
break;
@@ -253,8 +253,8 @@ void EventsManager::logEvent(const SDL_Event &event)
const int w = mainGraphics->mWidth;
const int h = mainGraphics->mHeight;
logger->log("event: SDL_FINGERMOTION: %u,%u (%f,%f) (%f,%f)",
- static_cast<unsigned int>(touch.touchId),
- static_cast<unsigned int>(touch.fingerId),
+ CAST_U32(touch.touchId),
+ CAST_U32(touch.fingerId),
touch.x * w, touch.y * h,
touch.dx * w, touch.dy * h);
break;
@@ -265,11 +265,11 @@ void EventsManager::logEvent(const SDL_Event &event)
const int w = mainGraphics->mWidth;
const int h = mainGraphics->mHeight;
logger->log("event: SDL_MULTIGESTURE: %u %f,%f (%f,%f) %d,%d",
- static_cast<unsigned int>(gesture.touchId),
+ CAST_U32(gesture.touchId),
gesture.dTheta, gesture.dDist,
gesture.x * w, gesture.y * h,
- static_cast<int>(gesture.numFingers),
- static_cast<int>(gesture.padding));
+ CAST_S32(gesture.numFingers),
+ CAST_S32(gesture.padding));
break;
}
case SDL_KEYDOWN:
diff --git a/src/game.cpp b/src/game.cpp
index ef60b67c9..40d5478af 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -726,7 +726,7 @@ void Game::adjustPerfomance()
{
mNextAdjustTime = time + adjustDelay;
}
- else if (mNextAdjustTime < static_cast<unsigned>(time))
+ else if (mNextAdjustTime < CAST_U32(time))
{
mNextAdjustTime = time + adjustDelay;
@@ -1115,7 +1115,7 @@ void Game::updateHistory(const SDL_Event &event)
if (!localPlayer || !settings.attackType)
return;
- if (static_cast<int>(event.key.keysym.sym) != -1)
+ if (CAST_S32(event.key.keysym.sym) != -1)
{
bool old = false;
diff --git a/src/gamemodifiers.cpp b/src/gamemodifiers.cpp
index 774a68955..614ea1504 100644
--- a/src/gamemodifiers.cpp
+++ b/src/gamemodifiers.cpp
@@ -55,7 +55,7 @@
std::string GameModifiers::get##name1##String() \
{ \
return gettext(getVarItem(&m##name1##Strings[0], \
- static_cast<unsigned>(settings.name2), m##name1##Size)); \
+ CAST_U32(settings.name2), m##name1##Size)); \
}
#define addModifier2(name1, name2, str, sz, ...) \
@@ -289,7 +289,7 @@ std::string GameModifiers::getQuickDropCounterString()
const unsigned int cnt = settings.quickDropCounter;
if (cnt > 9)
{
- return strprintf("(%c) drop counter %u", static_cast<signed char>(
+ return strprintf("(%c) drop counter %u", CAST_S8(
'a' + cnt - 10), cnt);
}
else
@@ -300,7 +300,7 @@ std::string GameModifiers::getQuickDropCounterString()
void GameModifiers::setQuickDropCounter(const int n)
{
- if (n < 1 || n >= static_cast<signed>(mQuickDropCounterSize))
+ if (n < 1 || n >= CAST_S32(mQuickDropCounterSize))
return;
settings.quickDropCounter = n;
config.setValue("quickDropCounter", n);
diff --git a/src/graphicsmanager.cpp b/src/graphicsmanager.cpp
index 5ecc96fcc..ad099842d 100644
--- a/src/graphicsmanager.cpp
+++ b/src/graphicsmanager.cpp
@@ -250,12 +250,12 @@ int GraphicsManager::detectGraphics()
compressTextures = 0;
}
- config.setValue("opengl", static_cast<int>(mode));
+ config.setValue("opengl", CAST_S32(mode));
config.setValue("videoconfigured", true);
config.write();
logger->log("detection complete");
- return static_cast<unsigned int>(mode)
+ return CAST_U32(mode)
| (1024 * textureSampler) | (2048 * compressTextures);
}
@@ -336,7 +336,7 @@ void GraphicsManager::createRenderers()
if (settings.options.renderer < 0)
{
useOpenGL = intToRenderType(config.getIntValue("opengl"));
- settings.options.renderer = static_cast<int>(useOpenGL);
+ settings.options.renderer = CAST_S32(useOpenGL);
}
else
{
@@ -570,7 +570,7 @@ void GraphicsManager::initGraphics()
if (openGLMode != oldOpenGLMode)
{
deleteRenderers();
- settings.options.renderer = static_cast<int>(openGLMode);
+ settings.options.renderer = CAST_S32(openGLMode);
config.setValue("opengl", settings.options.renderer);
createRenderers();
detectPixelSize();
@@ -580,7 +580,7 @@ void GraphicsManager::initGraphics()
const std::string str = config.getStringValue("textureSize");
std::vector<int> sizes;
splitToIntVector(sizes, str, ',');
- const size_t pos = static_cast<size_t>(openGLMode);
+ const size_t pos = CAST_SIZE(openGLMode);
if (sizes.size() <= pos)
settings.textureSize = 1024;
else
@@ -743,10 +743,10 @@ void GraphicsManager::updateTextureCompressionFormat() const
mglGetIntegerv(GL_NUM_COMPRESSED_TEXTURE_FORMATS, &num);
logger->log("support %d compressed formats", num);
GLint *const formats = new GLint[num > 10
- ? static_cast<size_t>(num) : 10];
+ ? CAST_SIZE(num) : 10];
mglGetIntegerv(GL_COMPRESSED_TEXTURE_FORMATS, formats);
for (int f = 0; f < num; f ++)
- logger->log(" 0x%x", static_cast<unsigned int>(formats[f]));
+ logger->log(" 0x%x", CAST_U32(formats[f]));
if (compressionFormat)
{
@@ -1487,7 +1487,7 @@ void GraphicsManager::detectVideoSettings()
{
const Configuration &conf = test->getConfig();
int val = conf.getValueInt("opengl", -1);
- if (val >= 0 && val < static_cast<int>(RENDER_LAST))
+ if (val >= 0 && val < CAST_S32(RENDER_LAST))
{
config.setValue("opengl", val);
val = conf.getValue("useTextureSampler", -1);
@@ -1585,7 +1585,7 @@ static CALLBACK void debugCallback(GLenum source, GLenum type, GLuint id,
message.append(" ?").append(toString(type));
break;
}
- char *const buf = new char[static_cast<size_t>(length + 1)];
+ char *const buf = new char[CAST_SIZE(length + 1)];
memcpy(buf, text, length);
buf[length] = 0;
message.append(" ").append(buf);
diff --git a/src/graphicsvertexes.cpp b/src/graphicsvertexes.cpp
index 21461f052..fd4213e0e 100644
--- a/src/graphicsvertexes.cpp
+++ b/src/graphicsvertexes.cpp
@@ -100,7 +100,7 @@ void OpenGLGraphicsVertexes::clear() restrict2
}
mIntTexPool.clear();
- const int sz = static_cast<int>(mVbo.size());
+ const int sz = CAST_S32(mVbo.size());
if (sz > 0)
{
mainGraphics->removeArray(sz, &mVbo[0]);
@@ -129,28 +129,28 @@ void OpenGLGraphicsVertexes::init() restrict2
GLfloat *OpenGLGraphicsVertexes::switchFloatTexArray() restrict2
{
- mFloatTexArray = new GLfloat[static_cast<size_t>(vertexBufSize * 4 + 30)];
+ mFloatTexArray = new GLfloat[CAST_SIZE(vertexBufSize * 4 + 30)];
mFloatTexPool.push_back(mFloatTexArray);
return mFloatTexArray;
}
GLint *OpenGLGraphicsVertexes::switchIntVertArray() restrict2
{
- mIntVertArray = new GLint[static_cast<size_t>(vertexBufSize * 4 + 30)];
+ mIntVertArray = new GLint[CAST_SIZE(vertexBufSize * 4 + 30)];
mIntVertPool.push_back(mIntVertArray);
return mIntVertArray;
}
GLshort *OpenGLGraphicsVertexes::switchShortVertArray() restrict2
{
- mShortVertArray = new GLshort[static_cast<size_t>(vertexBufSize * 4 + 30)];
+ mShortVertArray = new GLshort[CAST_SIZE(vertexBufSize * 4 + 30)];
mShortVertPool.push_back(mShortVertArray);
return mShortVertArray;
}
GLint *OpenGLGraphicsVertexes::switchIntTexArray() restrict2
{
- mIntTexArray = new GLint[static_cast<size_t>(vertexBufSize * 4 + 30)];
+ mIntTexArray = new GLint[CAST_SIZE(vertexBufSize * 4 + 30)];
mIntTexPool.push_back(mIntTexArray);
return mIntTexArray;
}
@@ -185,7 +185,7 @@ GLfloat *OpenGLGraphicsVertexes::continueFloatTexArray() restrict2
{
if (mFloatTexPool.empty())
{
- mFloatTexArray = new GLfloat[static_cast<size_t>(
+ mFloatTexArray = new GLfloat[CAST_SIZE(
vertexBufSize * 4 + 30)];
mFloatTexPool.push_back(mFloatTexArray);
}
@@ -200,7 +200,7 @@ GLint *OpenGLGraphicsVertexes::continueIntVertArray() restrict2
{
if (mIntVertPool.empty())
{
- mIntVertArray = new GLint[static_cast<size_t>(vertexBufSize * 4 + 30)];
+ mIntVertArray = new GLint[CAST_SIZE(vertexBufSize * 4 + 30)];
mIntVertPool.push_back(mIntVertArray);
}
else
@@ -214,7 +214,7 @@ GLshort *OpenGLGraphicsVertexes::continueShortVertArray() restrict2
{
if (mShortVertPool.empty())
{
- mShortVertArray = new GLshort[static_cast<size_t>(
+ mShortVertArray = new GLshort[CAST_SIZE(
vertexBufSize * 4 + 30)];
mShortVertPool.push_back(mShortVertArray);
}
@@ -229,7 +229,7 @@ GLint *OpenGLGraphicsVertexes::continueIntTexArray() restrict2
{
if (mIntTexPool.empty())
{
- mIntTexArray = new GLint[static_cast<size_t>(vertexBufSize * 4 + 30)];
+ mIntTexArray = new GLint[CAST_SIZE(vertexBufSize * 4 + 30)];
mIntTexPool.push_back(mIntTexArray);
}
else
diff --git a/src/gui/color.cpp b/src/gui/color.cpp
index 3e82a1210..6d0e3037e 100644
--- a/src/gui/color.cpp
+++ b/src/gui/color.cpp
@@ -126,9 +126,9 @@ Color Color::operator-(const Color& color) const
Color Color::operator*(const float value) const
{
- Color result(static_cast<unsigned int>(static_cast<float>(r) * value),
- static_cast<unsigned int>(static_cast<float>(g) * value),
- static_cast<unsigned int>(static_cast<float>(b) * value),
+ Color result(CAST_U32(static_cast<float>(r) * value),
+ CAST_U32(static_cast<float>(g) * value),
+ CAST_U32(static_cast<float>(b) * value),
a);
result.r = (result.r > 255U ? 255U : result.r);
diff --git a/src/gui/focushandler.cpp b/src/gui/focushandler.cpp
index 50aeb9738..02588a353 100644
--- a/src/gui/focushandler.cpp
+++ b/src/gui/focushandler.cpp
@@ -185,7 +185,7 @@ void FocusHandler::tabNext()
int i;
int focusedWidget = -1;
- const int sz = static_cast<int>(mWidgets.size());
+ const int sz = CAST_S32(mWidgets.size());
for (i = 0; i < sz; ++ i)
{
if (mWidgets[i] == mFocusedWidget)
@@ -256,7 +256,7 @@ void FocusHandler::tabPrevious()
int i;
int focusedWidget = -1;
- const int sz = static_cast<int>(mWidgets.size());
+ const int sz = CAST_S32(mWidgets.size());
for (i = 0; i < sz; ++ i)
{
if (mWidgets[i] == mFocusedWidget)
@@ -360,7 +360,7 @@ void FocusHandler::requestFocus(const Widget *const widget)
return;
int toBeFocusedIndex = -1;
- for (unsigned int i = 0, sz = static_cast<unsigned int>(
+ for (unsigned int i = 0, sz = CAST_U32(
mWidgets.size()); i < sz; ++i)
{
if (mWidgets[i] == widget)
@@ -426,7 +426,7 @@ void FocusHandler::focusNext()
{
int i;
int focusedWidget = -1;
- const int sz = static_cast<int>(mWidgets.size());
+ const int sz = CAST_S32(mWidgets.size());
for (i = 0; i < sz; ++i)
{
if (mWidgets[i] == mFocusedWidget)
@@ -482,7 +482,7 @@ void FocusHandler::focusPrevious()
int i;
int focusedWidget = -1;
- const int sz = static_cast<int>(mWidgets.size());
+ const int sz = CAST_S32(mWidgets.size());
for (i = 0; i < sz; ++ i)
{
if (mWidgets[i] == mFocusedWidget)
diff --git a/src/gui/fonts/font.cpp b/src/gui/fonts/font.cpp
index b476de976..0f36e5f0e 100644
--- a/src/gui/fonts/font.cpp
+++ b/src/gui/fonts/font.cpp
@@ -317,7 +317,7 @@ void Font::doClean()
for (unsigned int f = 0; f < CACHES_NUMBER; f ++)
{
TextChunkList *const cache = &mCache[f];
- const size_t size = static_cast<size_t>(cache->size);
+ const size_t size = CAST_SIZE(cache->size);
#ifdef DEBUG_FONT_COUNTERS
logger->log("ptr: %u, size: %ld", f, size);
#endif
@@ -360,10 +360,10 @@ int Font::getStringIndexAt(const std::string& text, const int x) const
for (size_t i = 0; i < sz; ++i)
{
if (getWidth(text.substr(0, i)) > x)
- return static_cast<int>(i);
+ return CAST_S32(i);
}
- return static_cast<int>(sz);
+ return CAST_S32(sz);
}
const TextChunkList *Font::getCache() const noexcept
diff --git a/src/gui/fonts/textchunk.cpp b/src/gui/fonts/textchunk.cpp
index ca22d3ee5..63c70acdb 100644
--- a/src/gui/fonts/textchunk.cpp
+++ b/src/gui/fonts/textchunk.cpp
@@ -97,9 +97,9 @@ void TextChunk::generate(TTF_Font *restrict const font,
{
BLOCK_START("TextChunk::generate")
SDL_Color sdlCol;
- sdlCol.b = static_cast<uint8_t>(color.b);
- sdlCol.r = static_cast<uint8_t>(color.r);
- sdlCol.g = static_cast<uint8_t>(color.g);
+ sdlCol.b = CAST_U8(color.b);
+ sdlCol.r = CAST_U8(color.r);
+ sdlCol.g = CAST_U8(color.g);
#ifdef USE_SDL2
sdlCol.a = 255;
#else
@@ -134,9 +134,9 @@ void TextChunk::generate(TTF_Font *restrict const font,
BLOCK_END("TextChunk::generate")
return;
}
- sdlCol2.b = static_cast<uint8_t>(color2.b);
- sdlCol2.r = static_cast<uint8_t>(color2.r);
- sdlCol2.g = static_cast<uint8_t>(color2.g);
+ sdlCol2.b = CAST_U8(color2.b);
+ sdlCol2.r = CAST_U8(color2.r);
+ sdlCol2.g = CAST_U8(color2.g);
#ifdef USE_SDL2
sdlCol2.a = 255;
#else
diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp
index f10b386af..db03887fb 100644
--- a/src/gui/gui.cpp
+++ b/src/gui/gui.cpp
@@ -501,7 +501,7 @@ void Gui::draw()
}
#endif
Image *const mouseCursor = mMouseCursors->get(
- static_cast<size_t>(mCursorType));
+ CAST_SIZE(mCursorType));
if (mouseCursor)
{
mouseCursor->setAlpha(mMouseCursorAlpha);
@@ -648,7 +648,7 @@ void Gui::handleMouseMoved(const MouseInput &mouseInput)
}
widgetWithMouseQueueCheckDone =
- (static_cast<size_t>(iterations) == mWidgetWithMouseQueue.size());
+ (CAST_SIZE(iterations) == mWidgetWithMouseQueue.size());
}
// Check all widgets below the mouse to see if they are
diff --git a/src/gui/models/beingslistmodel.h b/src/gui/models/beingslistmodel.h
index 953c78119..ccf0338c7 100644
--- a/src/gui/models/beingslistmodel.h
+++ b/src/gui/models/beingslistmodel.h
@@ -55,7 +55,7 @@ class BeingsListModel final : public AvatarListModel
int getNumberOfElements() override final
{
- return static_cast<int>(mMembers.size());
+ return CAST_S32(mMembers.size());
}
std::vector<Avatar*> mMembers;
diff --git a/src/gui/models/colormodel.cpp b/src/gui/models/colormodel.cpp
index 88dee3c93..046d69a92 100644
--- a/src/gui/models/colormodel.cpp
+++ b/src/gui/models/colormodel.cpp
@@ -38,22 +38,22 @@ ColorModel::~ColorModel()
int ColorModel::getNumberOfElements()
{
- return static_cast<int>(mNames.size());
+ return CAST_S32(mNames.size());
}
std::string ColorModel::getElementAt(int i)
{
if (i >= getNumberOfElements() || i < 0)
return "???";
- return mNames[static_cast<size_t>(i)];
+ return mNames[CAST_SIZE(i)];
}
const ColorPair *ColorModel::getColorAt(const int i) const
{
- if (i >= static_cast<int>(mColors.size()) || i < 0)
+ if (i >= CAST_S32(mColors.size()) || i < 0)
return &mColors[0];
- return &mColors[static_cast<size_t>(i)];
+ return &mColors[CAST_SIZE(i)];
}
void ColorModel::add(const std::string &name, const Color *const color1,
diff --git a/src/gui/models/extendednamesmodel.cpp b/src/gui/models/extendednamesmodel.cpp
index ac65c8b21..28eececc4 100644
--- a/src/gui/models/extendednamesmodel.cpp
+++ b/src/gui/models/extendednamesmodel.cpp
@@ -35,22 +35,22 @@ ExtendedNamesModel::~ExtendedNamesModel()
int ExtendedNamesModel::getNumberOfElements()
{
- return static_cast<int>(mNames.size());
+ return CAST_S32(mNames.size());
}
std::string ExtendedNamesModel::getElementAt(int i)
{
if (i >= getNumberOfElements() || i < 0)
return "???";
- return mNames[static_cast<size_t>(i)];
+ return mNames[CAST_SIZE(i)];
}
const Image *ExtendedNamesModel::getImageAt(int i)
{
- if (i >= static_cast<int>(mImages.size()) || i < 0)
+ if (i >= CAST_S32(mImages.size()) || i < 0)
return nullptr;
- return mImages[static_cast<size_t>(i)];
+ return mImages[CAST_SIZE(i)];
}
void ExtendedNamesModel::clear()
diff --git a/src/gui/models/iconsmodel.h b/src/gui/models/iconsmodel.h
index d9cb0be5a..a04703149 100644
--- a/src/gui/models/iconsmodel.h
+++ b/src/gui/models/iconsmodel.h
@@ -70,7 +70,7 @@ class IconsModel final : public ListModel
int getNumberOfElements() override final
{
- return static_cast<int>(mStrings.size());
+ return CAST_S32(mStrings.size());
}
std::string getElementAt(int i) override final
diff --git a/src/gui/models/ignorechoiceslistmodel.h b/src/gui/models/ignorechoiceslistmodel.h
index fc87a7690..8a8a7f053 100644
--- a/src/gui/models/ignorechoiceslistmodel.h
+++ b/src/gui/models/ignorechoiceslistmodel.h
@@ -39,7 +39,7 @@ class IgnoreChoicesListModel final : public ListModel
int getNumberOfElements() override final
{
- return static_cast<int>(player_relations.
+ return CAST_S32(player_relations.
getPlayerIgnoreStrategies()->size());
}
diff --git a/src/gui/models/itemsmodel.h b/src/gui/models/itemsmodel.h
index 96fe37b7c..032a090eb 100644
--- a/src/gui/models/itemsmodel.h
+++ b/src/gui/models/itemsmodel.h
@@ -69,7 +69,7 @@ class ItemsModal final : public ListModel
int getNumberOfElements() override final
{
- return static_cast<int>(mStrings.size());
+ return CAST_S32(mStrings.size());
}
std::string getElementAt(int i) override final
diff --git a/src/gui/models/modelistmodel.h b/src/gui/models/modelistmodel.h
index e74dcb69f..9e5339a3d 100644
--- a/src/gui/models/modelistmodel.h
+++ b/src/gui/models/modelistmodel.h
@@ -43,13 +43,13 @@ class ModeListModel final : public ListModel
* Returns the number of elements in container.
*/
int getNumberOfElements() override final
- { return static_cast<int>(mVideoModes.size()); }
+ { return CAST_S32(mVideoModes.size()); }
/**
* Returns element from container.
*/
std::string getElementAt(int i) override final
- { return mVideoModes[static_cast<size_t>(i)]; }
+ { return mVideoModes[CAST_SIZE(i)]; }
/**
* Returns the index corresponding to the given video mode.
diff --git a/src/gui/models/namesmodel.cpp b/src/gui/models/namesmodel.cpp
index a66cea6b2..2e7606274 100644
--- a/src/gui/models/namesmodel.cpp
+++ b/src/gui/models/namesmodel.cpp
@@ -35,14 +35,14 @@ NamesModel::~NamesModel()
int NamesModel::getNumberOfElements()
{
- return static_cast<int>(mNames.size());
+ return CAST_S32(mNames.size());
}
std::string NamesModel::getElementAt(int i)
{
if (i >= getNumberOfElements() || i < 0)
return "???";
- return mNames[static_cast<size_t>(i)];
+ return mNames[CAST_SIZE(i)];
}
void NamesModel::fillFromArray(const char *const *const arr, std::size_t sz)
diff --git a/src/gui/models/playertablemodel.cpp b/src/gui/models/playertablemodel.cpp
index c4a438c4c..80eab3694 100644
--- a/src/gui/models/playertablemodel.cpp
+++ b/src/gui/models/playertablemodel.cpp
@@ -67,7 +67,7 @@ PlayerTableModel::~PlayerTableModel()
int PlayerTableModel::getRows() const
{
if (mPlayers)
- return static_cast<int>(mPlayers->size());
+ return CAST_S32(mPlayers->size());
else
return 0;
}
@@ -100,7 +100,7 @@ void PlayerTableModel::playerRelationsUpdated()
mPlayers = player_names;
// set up widgets
- for (unsigned int r = 0, sz = static_cast<unsigned int>(
+ for (unsigned int r = 0, sz = CAST_U32(
player_names->size()); r < sz; ++r)
{
const std::string name = (*player_names)[r];
@@ -108,7 +108,7 @@ void PlayerTableModel::playerRelationsUpdated()
mWidgets.push_back(widget);
DropDown *const choicebox = new DropDown(this, mListModel);
- choicebox->setSelected(static_cast<int>(
+ choicebox->setSelected(CAST_S32(
player_relations.getRelation(name)));
mWidgets.push_back(choicebox);
}
@@ -140,7 +140,7 @@ void PlayerTableModel::freeWidgets()
std::string PlayerTableModel::getPlayerAt(const int index) const
{
if (!mPlayers || index < 0
- || index >= static_cast<signed>(mPlayers->size()))
+ || index >= CAST_S32(mPlayers->size()))
{
return std::string();
}
diff --git a/src/gui/models/serverslistmodel.h b/src/gui/models/serverslistmodel.h
index d41f54bf9..15d3d7e9a 100644
--- a/src/gui/models/serverslistmodel.h
+++ b/src/gui/models/serverslistmodel.h
@@ -56,7 +56,7 @@ class ServersListModel final : public ListModel
int getNumberOfElements() override final A_WARN_UNUSED
{
MutexLocker lock = mParent->lock();
- return static_cast<int>(mServers->size());
+ return CAST_S32(mServers->size());
}
/**
@@ -80,7 +80,7 @@ class ServersListModel final : public ListModel
void setVersionString(const int index, const std::string &version)
{
- if (index < 0 || index >= static_cast<int>(mVersionStrings.size()))
+ if (index < 0 || index >= CAST_S32(mVersionStrings.size()))
return;
if (version.empty() || !gui)
diff --git a/src/gui/models/shopitems.cpp b/src/gui/models/shopitems.cpp
index 52515ea5b..952e5fe19 100644
--- a/src/gui/models/shopitems.cpp
+++ b/src/gui/models/shopitems.cpp
@@ -42,8 +42,8 @@ ShopItems::~ShopItems()
std::string ShopItems::getElementAt(int i)
{
- if (i < 0 || static_cast<unsigned>(i)
- >= static_cast<unsigned int>(mShopItems.size()) || !mShopItems.at(i))
+ if (i < 0 || CAST_U32(i)
+ >= CAST_U32(mShopItems.size()) || !mShopItems.at(i))
{
return "";
}
@@ -105,7 +105,7 @@ ShopItem *ShopItems::addItem2(const int inventoryIndex,
ShopItem *ShopItems::at(unsigned int i) const
{
- if (i >= static_cast<unsigned int>(mShopItems.size()))
+ if (i >= CAST_U32(mShopItems.size()))
return nullptr;
return mShopItems.at(i);
@@ -125,7 +125,7 @@ bool ShopItems::findInAllItems(std::vector<ShopItem*>::iterator &it,
void ShopItems::erase(const unsigned int i)
{
- if (i >= static_cast<unsigned int>(mShopItems.size()))
+ if (i >= CAST_U32(mShopItems.size()))
return;
const ShopItem *const item = *(mShopItems.begin() + i);
@@ -137,7 +137,7 @@ void ShopItems::erase(const unsigned int i)
void ShopItems::del(const unsigned int i)
{
- if (i >= static_cast<unsigned int>(mShopItems.size()))
+ if (i >= CAST_U32(mShopItems.size()))
return;
ShopItem *item = *(mShopItems.begin() + i);
diff --git a/src/gui/models/shopitems.h b/src/gui/models/shopitems.h
index 5224566e5..c75fee7e1 100644
--- a/src/gui/models/shopitems.h
+++ b/src/gui/models/shopitems.h
@@ -92,7 +92,7 @@ class ShopItems final : public ListModel
* Returns the number of items in the shop.
*/
int getNumberOfElements() override final A_WARN_UNUSED
- { return static_cast<int>(mShopItems.size()); }
+ { return CAST_S32(mShopItems.size()); }
bool empty() const A_WARN_UNUSED
{ return mShopItems.empty(); }
diff --git a/src/gui/models/skillmodel.cpp b/src/gui/models/skillmodel.cpp
index d26283ef0..7e49de9a3 100644
--- a/src/gui/models/skillmodel.cpp
+++ b/src/gui/models/skillmodel.cpp
@@ -34,7 +34,7 @@ SkillModel::SkillModel() :
SkillInfo *SkillModel::getSkillAt(const int i) const
{
- if (i < 0 || i >= static_cast<int>(mVisibleSkills.size()))
+ if (i < 0 || i >= CAST_S32(mVisibleSkills.size()))
return nullptr;
return mVisibleSkills.at(i);
}
diff --git a/src/gui/models/skillmodel.h b/src/gui/models/skillmodel.h
index fd75c4ea7..d7695253d 100644
--- a/src/gui/models/skillmodel.h
+++ b/src/gui/models/skillmodel.h
@@ -38,7 +38,7 @@ class SkillModel final : public ListModel
std::string getElementAt(int i) override final;
int getNumberOfElements() override final
- { return static_cast<int>(mVisibleSkills.size()); }
+ { return CAST_S32(mVisibleSkills.size()); }
void addSkill(SkillInfo *const info)
{ mSkills.push_back(info); }
diff --git a/src/gui/models/updatelistmodel.h b/src/gui/models/updatelistmodel.h
index 194812958..67fffc34e 100644
--- a/src/gui/models/updatelistmodel.h
+++ b/src/gui/models/updatelistmodel.h
@@ -47,7 +47,7 @@ class UpdateListModel final : public ListModel
{
if (!mLoginData)
return 0;
- return static_cast<int>(mLoginData->updateHosts.size());
+ return CAST_S32(mLoginData->updateHosts.size());
}
std::string getElementAt(int i) override final
diff --git a/src/gui/models/worldlistmodel.h b/src/gui/models/worldlistmodel.h
index 1c78232cc..035824cb4 100644
--- a/src/gui/models/worldlistmodel.h
+++ b/src/gui/models/worldlistmodel.h
@@ -47,7 +47,7 @@ class WorldListModel final : public ListModel
int getNumberOfElements() override final
{
- return static_cast<int>(mWorlds.size());
+ return CAST_S32(mWorlds.size());
}
std::string getElementAt(int i) override final
diff --git a/src/gui/palette.cpp b/src/gui/palette.cpp
index a56388120..0e3f9560c 100644
--- a/src/gui/palette.cpp
+++ b/src/gui/palette.cpp
@@ -120,7 +120,7 @@ void Palette::advanceGradient()
if (grad == GradientType::PULSE)
{
- colVal = static_cast<int>(255.0 *
+ colVal = CAST_S32(255.0 *
sin(M_PI * colIndex / numOfColors));
const Color &col = elem->testColor;
@@ -135,12 +135,12 @@ void Palette::advanceGradient()
{ // falling curve
if (delay)
{
- colVal = static_cast<int>(255.0 *
+ colVal = CAST_S32(255.0 *
(cos(M_PI * pos / delay) + 1) / 2);
}
else
{
- colVal = static_cast<int>(255.0 *
+ colVal = CAST_S32(255.0 *
(cos(M_PI * pos) + 1) / 2);
}
}
@@ -148,12 +148,12 @@ void Palette::advanceGradient()
{ // ascending curve
if (delay)
{
- colVal = static_cast<int>(255.0 * (cos(M_PI *
+ colVal = CAST_S32(255.0 * (cos(M_PI *
(delay - pos) / delay) + 1) / 2);
}
else
{
- colVal = static_cast<int>(255.0 * (cos(M_PI *
+ colVal = CAST_S32(255.0 * (cos(M_PI *
(delay - pos)) + 1) / 2);
}
}
@@ -180,13 +180,13 @@ void Palette::advanceGradient()
destColVal = 1 - startColVal;
- color.r = static_cast<int>(startColVal
+ color.r = CAST_S32(startColVal
* startCol.r + destColVal * destCol.r);
- color.g = static_cast<int>(startColVal
+ color.g = CAST_S32(startColVal
* startCol.g + destColVal * destCol.g);
- color.b = static_cast<int>(startColVal
+ color.b = CAST_S32(startColVal
* startCol.b + destColVal * destCol.b);
}
}
diff --git a/src/gui/palette.h b/src/gui/palette.h
index ca5ab08ab..ebcc2936f 100644
--- a/src/gui/palette.h
+++ b/src/gui/palette.h
@@ -73,7 +73,7 @@ class Palette notfinal
* @return the color char of the color with the given index
*/
inline char getColorChar(const int type) const A_WARN_UNUSED
- { return mColors[static_cast<size_t>(type)].ch; }
+ { return mColors[CAST_SIZE(type)].ch; }
/**
* Updates all colors, that are non-static.
diff --git a/src/gui/popups/itempopup.cpp b/src/gui/popups/itempopup.cpp
index 8f8a07b71..f0ab5d167 100644
--- a/src/gui/popups/itempopup.cpp
+++ b/src/gui/popups/itempopup.cpp
@@ -138,19 +138,19 @@ void ItemPopup::setItem(const Item *const item,
{
mItemName->setCaption(strprintf("%s (+%u), %d",
ii.getName(item->getColor()).c_str(),
- static_cast<unsigned int>(item->getRefine()),
+ CAST_U32(item->getRefine()),
ii.getId()));
}
else
{
mItemName->setCaption(strprintf("%s (+%u), %d",
ii.getName().c_str(),
- static_cast<unsigned int>(item->getRefine()),
+ CAST_U32(item->getRefine()),
ii.getId()));
}
mItemName->adjustSize();
const unsigned minWidth = mItemName->getWidth() + 8;
- if (static_cast<unsigned>(getWidth()) < minWidth)
+ if (CAST_U32(getWidth()) < minWidth)
setWidth(minWidth);
}
}
diff --git a/src/gui/popups/popupmenu.cpp b/src/gui/popups/popupmenu.cpp
index e319ba7fd..b9fc252b8 100644
--- a/src/gui/popups/popupmenu.cpp
+++ b/src/gui/popups/popupmenu.cpp
@@ -441,7 +441,7 @@ void PopupMenu::showPopup(const int x, const int y,
if (being && !being->getName().empty())
{
mBrowserBox->addRow(strprintf("@@player_%u|%s >@@",
- static_cast<unsigned>(being->getId()), (being->getName()
+ CAST_U32(being->getId()), (being->getName()
+ being->getGenderSignWithSpace()).c_str()));
}
else if (actor->getType() == ActorType::FloorItem)
@@ -449,7 +449,7 @@ void PopupMenu::showPopup(const int x, const int y,
const FloorItem *const floorItem
= static_cast<const FloorItem*>(actor);
mBrowserBox->addRow(strprintf("@@flooritem_%u|%s >@@",
- static_cast<unsigned>(actor->getId()),
+ CAST_U32(actor->getId()),
floorItem->getName().c_str()));
}
}
@@ -799,7 +799,7 @@ void PopupMenu::showChatPopup(const int x, const int y, ChatTab *const tab)
mBrowserBox->addRow("disable away", _("Disable away"));
}
mBrowserBox->addRow("##3---");
- if (tab->getType() == static_cast<int>(ChatTabType::PARTY))
+ if (tab->getType() == CAST_S32(ChatTabType::PARTY))
{
// TRANSLATORS: popup menu item
// TRANSLATORS: enable away messages in chat tab
@@ -1041,11 +1041,11 @@ void PopupMenu::handleLink(const std::string &link,
if (specialLayer)
{
const bool isHome = (mMapItem->getType()
- == static_cast<int>(MapItemType::HOME));
+ == CAST_S32(MapItemType::HOME));
const int x = static_cast<const int>(mMapItem->getX());
const int y = static_cast<const int>(mMapItem->getY());
specialLayer->setTile(x, y,
- static_cast<int>(MapItemType::EMPTY));
+ CAST_S32(MapItemType::EMPTY));
if (socialWindow)
socialWindow->removePortal(x, y);
if (isHome && localPlayer)
@@ -1493,7 +1493,7 @@ void PopupMenu::handleLink(const std::string &link,
replaceAll(cmd, "'FLOORID'", toString(toInt(mFloorItemId, int)));
replaceAll(cmd, "'ITEMID'", toString(mItemId));
replaceAll(cmd, "'ITEMCOLOR'", toString(toInt(mItemColor, int)));
- replaceAll(cmd, "'BEINGTYPEID'", toString(static_cast<int>(mType)));
+ replaceAll(cmd, "'BEINGTYPEID'", toString(CAST_S32(mType)));
replaceAll(cmd, "'PLAYER'", localPlayer->getName());
if (mItemIndex >= 0)
replaceAll(cmd, "'INVINDEX'", toString(mItemIndex));
@@ -2163,7 +2163,7 @@ void PopupMenu::showWindowsPopup()
continue;
mBrowserBox->addRow(strprintf("show window_%d",
- static_cast<int>(btn->key)),
+ CAST_S32(btn->key)),
btn->text.c_str());
}
mBrowserBox->addRow("##3---");
diff --git a/src/gui/sdlinput.cpp b/src/gui/sdlinput.cpp
index c6f29a6e3..4850f3227 100644
--- a/src/gui/sdlinput.cpp
+++ b/src/gui/sdlinput.cpp
@@ -495,7 +495,7 @@ int SDLInput::convertKeyCharacter(const SDL_Event &event)
break;
}
- if (!(static_cast<unsigned int>(keysym.mod) & KMOD_NUM))
+ if (!(CAST_U32(keysym.mod) & KMOD_NUM))
{
switch (keysym.sym)
{
diff --git a/src/gui/shortcut/emoteshortcut.cpp b/src/gui/shortcut/emoteshortcut.cpp
index 1079076f6..c49dc2ab8 100644
--- a/src/gui/shortcut/emoteshortcut.cpp
+++ b/src/gui/shortcut/emoteshortcut.cpp
@@ -46,14 +46,14 @@ EmoteShortcut::~EmoteShortcut()
void EmoteShortcut::load()
{
for (unsigned char i = 0, j = 0,
- sz = static_cast<unsigned char>(EmoteDB::getLast());
+ sz = CAST_U8(EmoteDB::getLast());
i <= sz && j < SHORTCUT_EMOTES;
i++)
{
const EmoteSprite *const sprite = EmoteDB::getSprite(i, true);
if (sprite)
{
- mEmotes[j] = static_cast<unsigned char>(i + 1);
+ mEmotes[j] = CAST_U8(i + 1);
j ++;
}
}
@@ -64,9 +64,9 @@ void EmoteShortcut::save() const
for (int i = 0; i < SHORTCUT_EMOTES; i++)
{
const unsigned char emoteId = mEmotes[i] ? mEmotes[i]
- : static_cast<unsigned char>(0);
+ : CAST_U8(0);
serverConfig.setValue("emoteshortcut" + toString(i),
- static_cast<unsigned int>(emoteId));
+ CAST_U32(emoteId));
}
}
diff --git a/src/gui/shortcut/itemshortcut.cpp b/src/gui/shortcut/itemshortcut.cpp
index 7166fddf5..4349f1c44 100644
--- a/src/gui/shortcut/itemshortcut.cpp
+++ b/src/gui/shortcut/itemshortcut.cpp
@@ -226,8 +226,8 @@ void ItemShortcut::setItem(const int index,
void ItemShortcut::swap(const int index1, const int index2)
{
if (index1 < 0 || index2 < 0
- || static_cast<unsigned int>(index1) >= SHORTCUT_ITEMS
- || static_cast<unsigned int>(index2) >= SHORTCUT_ITEMS)
+ || CAST_U32(index1) >= SHORTCUT_ITEMS
+ || CAST_U32(index2) >= SHORTCUT_ITEMS)
{
return;
}
diff --git a/src/gui/theme.cpp b/src/gui/theme.cpp
index d588ecdb3..20ec774dc 100644
--- a/src/gui/theme.cpp
+++ b/src/gui/theme.cpp
@@ -70,72 +70,72 @@ static void initDefaultThemePath()
}
Theme::Theme() :
- Palette(static_cast<int>(ThemeColorId::THEME_COLORS_END) * THEME_PALETTES),
+ Palette(CAST_S32(ThemeColorId::THEME_COLORS_END) * THEME_PALETTES),
mSkins(),
mMinimumOpacity(-1.0F),
- mProgressColors(ProgressColors(static_cast<size_t>(
+ mProgressColors(ProgressColors(CAST_SIZE(
ProgressColorId::THEME_PROG_END)))
{
initDefaultThemePath();
config.addListener("guialpha", this);
- mColors[static_cast<size_t>(ThemeColorId::HIGHLIGHT)].ch = 'H';
- mColors[static_cast<size_t>(ThemeColorId::CHAT)].ch = 'C';
- mColors[static_cast<size_t>(ThemeColorId::GM)].ch = 'G';
- mColors[static_cast<size_t>(ThemeColorId::GLOBAL)].ch = 'g';
- mColors[static_cast<size_t>(ThemeColorId::PLAYER)].ch = 'Y';
- mColors[static_cast<size_t>(ThemeColorId::WHISPER_TAB)].ch = 'W';
- mColors[static_cast<size_t>(ThemeColorId::WHISPER_TAB_OFFLINE)].ch = 'w';
- mColors[static_cast<size_t>(ThemeColorId::IS)].ch = 'I';
- mColors[static_cast<size_t>(ThemeColorId::PARTY_CHAT_TAB)].ch = 'P';
- mColors[static_cast<size_t>(ThemeColorId::GUILD_CHAT_TAB)].ch = 'U';
- mColors[static_cast<size_t>(ThemeColorId::SERVER)].ch = 'S';
- mColors[static_cast<size_t>(ThemeColorId::LOGGER)].ch = 'L';
- mColors[static_cast<size_t>(ThemeColorId::HYPERLINK)].ch = '<';
- mColors[static_cast<size_t>(ThemeColorId::SELFNICK)].ch = 's';
- mColors[static_cast<size_t>(ThemeColorId::OLDCHAT)].ch = 'o';
- mColors[static_cast<size_t>(ThemeColorId::AWAYCHAT)].ch = 'a';
- mCharColors['H'] = static_cast<int>(ThemeColorId::HIGHLIGHT);
- mCharColors['C'] = static_cast<int>(ThemeColorId::CHAT);
- mCharColors['G'] = static_cast<int>(ThemeColorId::GM);
- mCharColors['g'] = static_cast<int>(ThemeColorId::GLOBAL);
- mCharColors['Y'] = static_cast<int>(ThemeColorId::PLAYER);
- mCharColors['W'] = static_cast<int>(ThemeColorId::WHISPER_TAB);
- mCharColors['w'] = static_cast<int>(ThemeColorId::WHISPER_TAB_OFFLINE);
- mCharColors['I'] = static_cast<int>(ThemeColorId::IS);
- mCharColors['P'] = static_cast<int>(ThemeColorId::PARTY_CHAT_TAB);
- mCharColors['U'] = static_cast<int>(ThemeColorId::GUILD_CHAT_TAB);
- mCharColors['S'] = static_cast<int>(ThemeColorId::SERVER);
- mCharColors['L'] = static_cast<int>(ThemeColorId::LOGGER);
- mCharColors['<'] = static_cast<int>(ThemeColorId::HYPERLINK);
- mCharColors['s'] = static_cast<int>(ThemeColorId::SELFNICK);
- mCharColors['o'] = static_cast<int>(ThemeColorId::OLDCHAT);
- mCharColors['a'] = static_cast<int>(ThemeColorId::AWAYCHAT);
+ mColors[CAST_SIZE(ThemeColorId::HIGHLIGHT)].ch = 'H';
+ mColors[CAST_SIZE(ThemeColorId::CHAT)].ch = 'C';
+ mColors[CAST_SIZE(ThemeColorId::GM)].ch = 'G';
+ mColors[CAST_SIZE(ThemeColorId::GLOBAL)].ch = 'g';
+ mColors[CAST_SIZE(ThemeColorId::PLAYER)].ch = 'Y';
+ mColors[CAST_SIZE(ThemeColorId::WHISPER_TAB)].ch = 'W';
+ mColors[CAST_SIZE(ThemeColorId::WHISPER_TAB_OFFLINE)].ch = 'w';
+ mColors[CAST_SIZE(ThemeColorId::IS)].ch = 'I';
+ mColors[CAST_SIZE(ThemeColorId::PARTY_CHAT_TAB)].ch = 'P';
+ mColors[CAST_SIZE(ThemeColorId::GUILD_CHAT_TAB)].ch = 'U';
+ mColors[CAST_SIZE(ThemeColorId::SERVER)].ch = 'S';
+ mColors[CAST_SIZE(ThemeColorId::LOGGER)].ch = 'L';
+ mColors[CAST_SIZE(ThemeColorId::HYPERLINK)].ch = '<';
+ mColors[CAST_SIZE(ThemeColorId::SELFNICK)].ch = 's';
+ mColors[CAST_SIZE(ThemeColorId::OLDCHAT)].ch = 'o';
+ mColors[CAST_SIZE(ThemeColorId::AWAYCHAT)].ch = 'a';
+ mCharColors['H'] = CAST_S32(ThemeColorId::HIGHLIGHT);
+ mCharColors['C'] = CAST_S32(ThemeColorId::CHAT);
+ mCharColors['G'] = CAST_S32(ThemeColorId::GM);
+ mCharColors['g'] = CAST_S32(ThemeColorId::GLOBAL);
+ mCharColors['Y'] = CAST_S32(ThemeColorId::PLAYER);
+ mCharColors['W'] = CAST_S32(ThemeColorId::WHISPER_TAB);
+ mCharColors['w'] = CAST_S32(ThemeColorId::WHISPER_TAB_OFFLINE);
+ mCharColors['I'] = CAST_S32(ThemeColorId::IS);
+ mCharColors['P'] = CAST_S32(ThemeColorId::PARTY_CHAT_TAB);
+ mCharColors['U'] = CAST_S32(ThemeColorId::GUILD_CHAT_TAB);
+ mCharColors['S'] = CAST_S32(ThemeColorId::SERVER);
+ mCharColors['L'] = CAST_S32(ThemeColorId::LOGGER);
+ mCharColors['<'] = CAST_S32(ThemeColorId::HYPERLINK);
+ mCharColors['s'] = CAST_S32(ThemeColorId::SELFNICK);
+ mCharColors['o'] = CAST_S32(ThemeColorId::OLDCHAT);
+ mCharColors['a'] = CAST_S32(ThemeColorId::AWAYCHAT);
// here need use outlined colors
mCharColors['H' | 0x80]
- = static_cast<int>(ThemeColorId::HIGHLIGHT_OUTLINE);
- mCharColors['C' | 0x80] = static_cast<int>(ThemeColorId::CHAT_OUTLINE);
- mCharColors['G' | 0x80] = static_cast<int>(ThemeColorId::GM_OUTLINE);
- mCharColors['g' | 0x80] = static_cast<int>(ThemeColorId::GLOBAL_OUTLINE);
- mCharColors['Y' | 0x80] = static_cast<int>(ThemeColorId::PLAYER_OUTLINE);
+ = CAST_S32(ThemeColorId::HIGHLIGHT_OUTLINE);
+ mCharColors['C' | 0x80] = CAST_S32(ThemeColorId::CHAT_OUTLINE);
+ mCharColors['G' | 0x80] = CAST_S32(ThemeColorId::GM_OUTLINE);
+ mCharColors['g' | 0x80] = CAST_S32(ThemeColorId::GLOBAL_OUTLINE);
+ mCharColors['Y' | 0x80] = CAST_S32(ThemeColorId::PLAYER_OUTLINE);
mCharColors['W' | 0x80]
- = static_cast<int>(ThemeColorId::WHISPER_TAB_OUTLINE);
+ = CAST_S32(ThemeColorId::WHISPER_TAB_OUTLINE);
mCharColors['w' | 0x80]
- = static_cast<int>(ThemeColorId::WHISPER_TAB_OFFLINE_OUTLINE);
- mCharColors['I' | 0x80] = static_cast<int>(ThemeColorId::IS_OUTLINE);
+ = CAST_S32(ThemeColorId::WHISPER_TAB_OFFLINE_OUTLINE);
+ mCharColors['I' | 0x80] = CAST_S32(ThemeColorId::IS_OUTLINE);
mCharColors['P' | 0x80]
- = static_cast<int>(ThemeColorId::PARTY_CHAT_TAB_OUTLINE);
+ = CAST_S32(ThemeColorId::PARTY_CHAT_TAB_OUTLINE);
mCharColors['U' | 0x80]
- = static_cast<int>(ThemeColorId::GUILD_CHAT_TAB_OUTLINE);
- mCharColors['S' | 0x80] = static_cast<int>(ThemeColorId::SERVER_OUTLINE);
- mCharColors['L' | 0x80] = static_cast<int>(ThemeColorId::LOGGER_OUTLINE);
+ = CAST_S32(ThemeColorId::GUILD_CHAT_TAB_OUTLINE);
+ mCharColors['S' | 0x80] = CAST_S32(ThemeColorId::SERVER_OUTLINE);
+ mCharColors['L' | 0x80] = CAST_S32(ThemeColorId::LOGGER_OUTLINE);
mCharColors['<' | 0x80]
- = static_cast<int>(ThemeColorId::HYPERLINK_OUTLINE);
- mCharColors['s' | 0x80] = static_cast<int>(ThemeColorId::SELFNICK_OUTLINE);
- mCharColors['o' | 0x80] = static_cast<int>(ThemeColorId::OLDCHAT_OUTLINE);
- mCharColors['a' | 0x80] = static_cast<int>(ThemeColorId::AWAYCHAT_OUTLINE);
+ = CAST_S32(ThemeColorId::HYPERLINK_OUTLINE);
+ mCharColors['s' | 0x80] = CAST_S32(ThemeColorId::SELFNICK_OUTLINE);
+ mCharColors['o' | 0x80] = CAST_S32(ThemeColorId::OLDCHAT_OUTLINE);
+ mCharColors['a' | 0x80] = CAST_S32(ThemeColorId::AWAYCHAT_OUTLINE);
}
Theme::~Theme()
@@ -154,7 +154,7 @@ Color Theme::getProgressColor(const ProgressColorIdT type,
if (theme)
{
const DyePalette *const dye
- = theme->mProgressColors[static_cast<size_t>(type)];
+ = theme->mProgressColors[CAST_SIZE(type)];
if (dye)
{
@@ -163,7 +163,7 @@ Color Theme::getProgressColor(const ProgressColorIdT type,
else
{
logger->log("color not found: "
- + toString(static_cast<int>(type)));
+ + toString(CAST_S32(type)));
}
}
@@ -610,7 +610,7 @@ void Theme::prepareThemePath()
std::string Theme::resolveThemePath(const std::string &path)
{
// Need to strip off any dye info for the existence tests
- const int pos = static_cast<int>(path.find('|'));
+ const int pos = CAST_S32(path.find('|'));
std::string file;
if (pos > 0)
file = path.substr(0, pos);
@@ -648,7 +648,7 @@ ImageSet *Theme::getImageSetFromTheme(const std::string &path,
static int readColorType(const std::string &type)
{
- static const std::string colors[static_cast<size_t>(
+ static const std::string colors[CAST_SIZE(
ThemeColorId::THEME_COLORS_END)] =
{
"BROWSERBOX",
@@ -878,7 +878,7 @@ static int readColorType(const std::string &type)
if (type.empty())
return -1;
- for (int i = 0; i < static_cast<int>(ThemeColorId::THEME_COLORS_END); i++)
+ for (int i = 0; i < CAST_S32(ThemeColorId::THEME_COLORS_END); i++)
{
if (compareStrI(type, colors[i]) == 0)
return i;
@@ -952,7 +952,7 @@ static GradientTypeT readColorGradient(const std::string &grad)
static int readProgressType(const std::string &type)
{
- static const std::string colors[static_cast<size_t>(
+ static const std::string colors[CAST_SIZE(
ProgressColorId::THEME_PROG_END)] =
{
"HP",
@@ -972,7 +972,7 @@ static int readProgressType(const std::string &type)
if (type.empty())
return -1;
- for (int i = 0; i < static_cast<int>(ProgressColorId::THEME_PROG_END); i++)
+ for (int i = 0; i < CAST_S32(ProgressColorId::THEME_PROG_END); i++)
{
if (compareStrI(type, colors[i]) == 0)
return i;
@@ -1036,7 +1036,7 @@ void Theme::loadColors(std::string file)
const Color color = readColor(temp);
const GradientTypeT grad = readColorGradient(
XML::getProperty(node, "effect", ""));
- mColors[paletteId * static_cast<size_t>(
+ mColors[paletteId * CAST_SIZE(
ThemeColorId::THEME_COLORS_END) + type].set(
type, color, grad, 10);
@@ -1046,7 +1046,7 @@ void Theme::loadColors(std::string file)
if (type2 < 0)
continue;
const int idx = paletteId
- * static_cast<int>(ThemeColorId::THEME_COLORS_END);
+ * CAST_S32(ThemeColorId::THEME_COLORS_END);
mColors[idx + type2] = mColors[idx + type];
}
}
diff --git a/src/gui/theme.h b/src/gui/theme.h
index 9e9badffa..91d1064be 100644
--- a/src/gui/theme.h
+++ b/src/gui/theme.h
@@ -136,14 +136,14 @@ class Theme final : public Palette,
const unsigned int alpha = 255U)
A_WARN_UNUSED
{
- if (static_cast<size_t>(type) >= mColors.size())
+ if (CAST_SIZE(type) >= mColors.size())
{
logger->log("incorrect color request type: %d from %u",
- static_cast<int>(type),
- static_cast<unsigned int>(mColors.size()));
+ CAST_S32(type),
+ CAST_U32(mColors.size()));
type = ThemeColorId::BROWSERBOX;
}
- Color* col = &mColors[static_cast<size_t>(type)].color;
+ Color* col = &mColors[CAST_SIZE(type)].color;
col->a = alpha;
return *col;
}
diff --git a/src/gui/themecolorsidoperators.cpp b/src/gui/themecolorsidoperators.cpp
index badd20b69..753512cc0 100644
--- a/src/gui/themecolorsidoperators.cpp
+++ b/src/gui/themecolorsidoperators.cpp
@@ -24,5 +24,5 @@
ThemeColorIdT operator+(const ThemeColorIdT &id, const int& i)
{
- return static_cast<ThemeColorIdT>(static_cast<int>(id) + i);
+ return static_cast<ThemeColorIdT>(CAST_S32(id) + i);
}
diff --git a/src/gui/userpalette.cpp b/src/gui/userpalette.cpp
index cf0e5da05..a7fba6399 100644
--- a/src/gui/userpalette.cpp
+++ b/src/gui/userpalette.cpp
@@ -31,7 +31,7 @@
UserPalette *userPalette = nullptr;
-const std::string ColorTypeNames[static_cast<size_t>(
+const std::string ColorTypeNames[CAST_SIZE(
UserColorId::USER_COLOR_LAST)] =
{
"",
@@ -107,7 +107,7 @@ std::string UserPalette::getConfigName(const std::string &typeName)
}
else
{
- res[pos] = static_cast<signed char>(tolower(typeName[i]));
+ res[pos] = CAST_S8(tolower(typeName[i]));
}
pos ++;
}
@@ -116,14 +116,14 @@ std::string UserPalette::getConfigName(const std::string &typeName)
}
UserPalette::UserPalette() :
- Palette(static_cast<int>(UserColorId::USER_COLOR_LAST))
+ Palette(CAST_S32(UserColorId::USER_COLOR_LAST))
{
- mColors[static_cast<size_t>(UserColorId::BEING)] = ColorElem();
- mColors[static_cast<size_t>(UserColorId::PC)] = ColorElem();
- mColors[static_cast<size_t>(UserColorId::SELF)] = ColorElem();
- mColors[static_cast<size_t>(UserColorId::GM)] = ColorElem();
- mColors[static_cast<size_t>(UserColorId::NPC)] = ColorElem();
- mColors[static_cast<size_t>(UserColorId::MONSTER)] = ColorElem();
+ mColors[CAST_SIZE(UserColorId::BEING)] = ColorElem();
+ mColors[CAST_SIZE(UserColorId::PC)] = ColorElem();
+ mColors[CAST_SIZE(UserColorId::SELF)] = ColorElem();
+ mColors[CAST_SIZE(UserColorId::GM)] = ColorElem();
+ mColors[CAST_SIZE(UserColorId::NPC)] = ColorElem();
+ mColors[CAST_SIZE(UserColorId::MONSTER)] = ColorElem();
addLabel(UserColorId::LABEL_BEING,
// TRANSLATORS: palette label
@@ -415,7 +415,7 @@ UserPalette::~UserPalette()
continue;
const std::string &configName = ColorTypeNames[col->type];
config.setValue(configName + "Gradient",
- static_cast<int>(col->committedGrad));
+ CAST_S32(col->committedGrad));
config.setValue(configName + "Delay", col->delay);
if (col->grad == GradientType::STATIC ||
@@ -434,7 +434,7 @@ void UserPalette::setColor(const UserColorIdT type,
const int g,
const int b)
{
- Color &color = mColors[static_cast<size_t>(type)].color;
+ Color &color = mColors[CAST_SIZE(type)].color;
color.r = r;
color.g = g;
color.b = b;
@@ -443,7 +443,7 @@ void UserPalette::setColor(const UserColorIdT type,
void UserPalette::setGradient(const UserColorIdT type,
const GradientTypeT grad)
{
- ColorElem *const elem = &mColors[static_cast<size_t>(type)];
+ ColorElem *const elem = &mColors[CAST_SIZE(type)];
if (elem->grad != GradientType::STATIC && grad == GradientType::STATIC)
{
@@ -530,10 +530,10 @@ void UserPalette::addColor(const UserColorIdT type,
const unsigned maxType = sizeof(ColorTypeNames)
/ sizeof(ColorTypeNames[0]);
- if (static_cast<unsigned>(type) >= maxType)
+ if (CAST_U32(type) >= maxType)
return;
- const std::string &configName = ColorTypeNames[static_cast<size_t>(type)];
+ const std::string &configName = ColorTypeNames[CAST_SIZE(type)];
char buffer[20];
snprintf(buffer, sizeof(buffer), "0x%06x", rgb);
buffer[19] = 0;
@@ -548,14 +548,14 @@ void UserPalette::addColor(const UserColorIdT type,
const Color &trueCol = Color(rgbValue);
grad = static_cast<GradientTypeT>(config.getValue(
configName + "Gradient",
- static_cast<int>(grad)));
+ CAST_S32(grad)));
delay = config.getValueInt(configName + "Delay", delay);
- mColors[static_cast<size_t>(type)].set(static_cast<int>(type),
+ mColors[CAST_SIZE(type)].set(CAST_S32(type),
trueCol, grad, delay);
- mColors[static_cast<size_t>(type)].text = text;
+ mColors[CAST_SIZE(type)].text = text;
if (grad != GradientType::STATIC)
- mGradVector.push_back(&mColors[static_cast<size_t>(type)]);
+ mGradVector.push_back(&mColors[CAST_SIZE(type)]);
}
void UserPalette::addLabel(const UserColorIdT type,
@@ -564,15 +564,15 @@ void UserPalette::addLabel(const UserColorIdT type,
const unsigned maxType = sizeof(ColorTypeNames)
/ sizeof(ColorTypeNames[0]);
- if (static_cast<unsigned>(type) >= maxType)
+ if (CAST_U32(type) >= maxType)
return;
- mColors[static_cast<size_t>(type)] = ColorElem();
+ mColors[CAST_SIZE(type)] = ColorElem();
const std::string str(" \342\200\225\342\200\225\342\200\225"
"\342\200\225\342\200\225 ");
- mColors[static_cast<size_t>(type)].grad = GradientType::LABEL;
- mColors[static_cast<size_t>(type)].text =
+ mColors[CAST_SIZE(type)].grad = GradientType::LABEL;
+ mColors[CAST_SIZE(type)].text =
std::string(str).append(text).append(str);
}
diff --git a/src/gui/userpalette.h b/src/gui/userpalette.h
index 49c9fce31..9f0566198 100644
--- a/src/gui/userpalette.h
+++ b/src/gui/userpalette.h
@@ -60,7 +60,7 @@ class UserPalette final : public Palette, public ListModel
inline const Color &getCommittedColor(const UserColorIdT type)
const A_WARN_UNUSED
{
- return mColors[static_cast<size_t>(type)].committedColor;
+ return mColors[CAST_SIZE(type)].committedColor;
}
/**
@@ -72,7 +72,7 @@ class UserPalette final : public Palette, public ListModel
*/
inline const Color &getTestColor(const UserColorIdT type)
const A_WARN_UNUSED
- { return mColors[static_cast<size_t>(type)].testColor; }
+ { return mColors[CAST_SIZE(type)].testColor; }
/**
* Sets the test color associated with the specified type.
@@ -82,7 +82,7 @@ class UserPalette final : public Palette, public ListModel
*/
inline void setTestColor(const UserColorIdT type,
const Color &color)
- { mColors[static_cast<size_t>(type)].testColor = color; }
+ { mColors[CAST_SIZE(type)].testColor = color; }
/**
* Sets the color for the specified type.
@@ -112,7 +112,7 @@ class UserPalette final : public Palette, public ListModel
*/
void setGradientDelay(const UserColorIdT type,
const int delay)
- { mColors[static_cast<size_t>(type)].delay = delay; }
+ { mColors[CAST_SIZE(type)].delay = delay; }
/**
* Returns the number of colors known.
@@ -120,7 +120,7 @@ class UserPalette final : public Palette, public ListModel
* @return the number of colors known
*/
inline int getNumberOfElements() override final A_WARN_UNUSED
- { return static_cast<int>(mColors.size()); }
+ { return CAST_S32(mColors.size()); }
/**
* Returns the name of the ith color.
@@ -165,14 +165,14 @@ class UserPalette final : public Palette, public ListModel
const unsigned int alpha = 255U)
A_WARN_UNUSED
{
- if (static_cast<size_t>(type) >= mColors.size())
+ if (CAST_SIZE(type) >= mColors.size())
{
logger->log("incorrect color request type: %d from %u",
- static_cast<int>(type),
- static_cast<unsigned int>(mColors.size()));
+ CAST_S32(type),
+ CAST_U32(mColors.size()));
type = UserColorId::BEING;
}
- Color* col = &mColors[static_cast<size_t>(type)].color;
+ Color* col = &mColors[CAST_SIZE(type)].color;
col->a = alpha;
return *col;
}
@@ -188,7 +188,7 @@ class UserPalette final : public Palette, public ListModel
*/
inline GradientTypeT getGradientType(const UserColorIdT type)
const A_WARN_UNUSED
- { return mColors[static_cast<size_t>(type)].grad; }
+ { return mColors[CAST_SIZE(type)].grad; }
/**
* Gets the gradient delay for the specified type.
@@ -199,14 +199,14 @@ class UserPalette final : public Palette, public ListModel
*/
inline int getGradientDelay(const UserColorIdT type)
const A_WARN_UNUSED
- { return mColors[static_cast<size_t>(type)].delay; }
+ { return mColors[CAST_SIZE(type)].delay; }
inline const Color &getColorWithAlpha(const UserColorIdT type)
A_WARN_UNUSED
{
- Color *const col = &mColors[static_cast<size_t>(type)].color;
- col->a = static_cast<unsigned int>(
- mColors[static_cast<size_t>(type)].delay);
+ Color *const col = &mColors[CAST_SIZE(type)].color;
+ col->a = CAST_U32(
+ mColors[CAST_SIZE(type)].delay);
return *col;
}
diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp
index 8f2940824..c7483b8a2 100644
--- a/src/gui/viewport.cpp
+++ b/src/gui/viewport.cpp
@@ -138,9 +138,9 @@ void Viewport::draw(Graphics *graphics)
const int midTileY = (graphics->mHeight + mScrollCenterOffsetY) / 2;
const Vector &playerPos = localPlayer->getPosition();
- const int player_x = static_cast<int>(playerPos.x)
+ const int player_x = CAST_S32(playerPos.x)
- midTileX + mCameraRelativeX;
- const int player_y = static_cast<int>(playerPos.y)
+ const int player_y = CAST_S32(playerPos.y)
- midTileY + mCameraRelativeY;
if (mScrollLaziness < 1)
@@ -155,28 +155,28 @@ void Viewport::draw(Graphics *graphics)
{
if (player_x > mPixelViewX + mScrollRadius)
{
- mPixelViewX += static_cast<int>(
+ mPixelViewX += CAST_S32(
static_cast<float>(player_x
- mPixelViewX - mScrollRadius) /
static_cast<float>(mScrollLaziness));
}
if (player_x < mPixelViewX - mScrollRadius)
{
- mPixelViewX += static_cast<int>(
+ mPixelViewX += CAST_S32(
static_cast<float>(player_x
- mPixelViewX + mScrollRadius) /
static_cast<float>(mScrollLaziness));
}
if (player_y > mPixelViewY + mScrollRadius)
{
- mPixelViewY += static_cast<int>(
+ mPixelViewY += CAST_S32(
static_cast<float>(player_y
- mPixelViewY - mScrollRadius) /
static_cast<float>(mScrollLaziness));
}
if (player_y < mPixelViewY - mScrollRadius)
{
- mPixelViewY += static_cast<int>(
+ mPixelViewY += CAST_S32(
static_cast<float>(player_y
- mPixelViewY + mScrollRadius) /
static_cast<float>(mScrollLaziness));
@@ -321,8 +321,8 @@ void Viewport::drawDebugPath(Graphics *const graphics)
const Vector &playerPos = localPlayer->getPosition();
debugPath = mMap->findPath(
- static_cast<int>(playerPos.x - mapTileSize / 2) / mapTileSize,
- static_cast<int>(playerPos.y - mapTileSize) / mapTileSize,
+ CAST_S32(playerPos.x - mapTileSize / 2) / mapTileSize,
+ CAST_S32(playerPos.y - mapTileSize) / mapTileSize,
mousePosX / mapTileSize, mousePosY / mapTileSize,
localPlayer->getBlockWalkMask(),
500);
@@ -584,7 +584,7 @@ void Viewport::getMouseTile(const int x, int y,
{
const int tw = mMap->getTileWidth();
const int th = mMap->getTileHeight();
- destX = static_cast<int>(x + mPixelViewX)
+ destX = CAST_S32(x + mPixelViewX)
/ static_cast<float>(tw);
if (mMap->isHeightsPresent())
@@ -614,7 +614,7 @@ void Viewport::getMouseTile(const int x, int y,
}
else
{
- destY = static_cast<int>((y + mPixelViewY) / static_cast<float>(th));
+ destY = CAST_S32((y + mPixelViewY) / static_cast<float>(th));
}
}
@@ -924,7 +924,7 @@ void Viewport::mouseMoved(MouseEvent &event)
void Viewport::toggleMapDrawType()
{
settings.mapDrawType = static_cast<MapTypeT>(
- static_cast<int>(settings.mapDrawType) + 1);
+ CAST_S32(settings.mapDrawType) + 1);
if (settings.mapDrawType > MapType::BLACKWHITE)
settings.mapDrawType = MapType::NORMAL;
if (mMap)
@@ -978,8 +978,8 @@ void Viewport::moveCameraToActor(const BeingId actorId,
const Vector &actorPos = actor->getPosition();
const Vector &playerPos = localPlayer->getPosition();
settings.cameraMode = 1;
- mCameraRelativeX = static_cast<int>(actorPos.x - playerPos.x) + x;
- mCameraRelativeY = static_cast<int>(actorPos.y - playerPos.y) + y;
+ mCameraRelativeX = CAST_S32(actorPos.x - playerPos.x) + x;
+ mCameraRelativeY = CAST_S32(actorPos.y - playerPos.y) + y;
}
void Viewport::moveCameraToPosition(const int x, const int y)
@@ -990,8 +990,8 @@ void Viewport::moveCameraToPosition(const int x, const int y)
const Vector &playerPos = localPlayer->getPosition();
settings.cameraMode = 1;
- mCameraRelativeX = x - static_cast<int>(playerPos.x);
- mCameraRelativeY = y - static_cast<int>(playerPos.y);
+ mCameraRelativeX = x - CAST_S32(playerPos.x);
+ mCameraRelativeY = y - CAST_S32(playerPos.y);
}
void Viewport::moveCameraRelative(const int x, const int y)
diff --git a/src/gui/widgets/basiccontainer.cpp b/src/gui/widgets/basiccontainer.cpp
index f867518a7..15042b971 100644
--- a/src/gui/widgets/basiccontainer.cpp
+++ b/src/gui/widgets/basiccontainer.cpp
@@ -312,7 +312,7 @@ void BasicContainer::drawChildren(Graphics *restrict graphics) restrict2
if (widget->mFrameSize > 0)
{
Rect rec = widget->mDimension;
- const int frame = static_cast<int>(widget->mFrameSize);
+ const int frame = CAST_S32(widget->mFrameSize);
const int frame2 = frame * 2;
rec.x -= frame;
rec.y -= frame;
@@ -352,7 +352,7 @@ void BasicContainer::safeDrawChildren(Graphics *restrict graphics) restrict2
if (widget->mFrameSize > 0)
{
Rect rec = widget->mDimension;
- const int frame = static_cast<int>(widget->mFrameSize);
+ const int frame = CAST_S32(widget->mFrameSize);
const int frame2 = frame * 2;
rec.x -= frame;
rec.y -= frame;
diff --git a/src/gui/widgets/browserbox.cpp b/src/gui/widgets/browserbox.cpp
index 2a85748b2..eec2547ee 100644
--- a/src/gui/widgets/browserbox.cpp
+++ b/src/gui/widgets/browserbox.cpp
@@ -132,7 +132,7 @@ BrowserBox::BrowserBox(const Widget2 *const widget,
if (mSkin)
{
mPadding = mSkin->getPadding();
- mNewLinePadding = static_cast<unsigned int>(
+ mNewLinePadding = CAST_U32(
mSkin->getOption("newLinePadding", 15));
mItemPadding = mSkin->getOption("itemPadding");
if (mSkin->getOption("highlightBackground"))
@@ -235,7 +235,7 @@ void BrowserBox::addRow(const std::string &row, const bool atTop)
break;
bLink.link = tmp.substr(idx1 + 2, idx2 - (idx1 + 2));
bLink.caption = tmp.substr(idx2 + 1, idx3 - (idx2 + 1));
- bLink.y1 = static_cast<int>(sz) * font->getHeight();
+ bLink.y1 = CAST_S32(sz) * font->getHeight();
bLink.y2 = bLink.y1 + font->getHeight();
if (bLink.caption.empty())
{
@@ -311,7 +311,7 @@ void BrowserBox::addRow(const std::string &row, const bool atTop)
if (idx2 == std::string::npos)
break;
- const unsigned int newSize = static_cast<unsigned int>(
+ const unsigned int newSize = CAST_U32(
atoi(newRow.substr(
idx1 + 2, idx2 - idx1 - 2).c_str()));
std::string str = newRow.substr(0, idx1);
@@ -337,7 +337,7 @@ void BrowserBox::addRow(const std::string &row, const bool atTop)
// discard older rows when a row limit has been set
if (mMaxRows > 0 && !mTextRows.empty())
{
- while (mTextRows.size() > static_cast<size_t>(mMaxRows))
+ while (mTextRows.size() > CAST_SIZE(mMaxRows))
{
mTextRows.pop_front();
int cnt = mTextRowLinksCount.front();
@@ -374,7 +374,7 @@ void BrowserBox::addRow(const std::string &row, const bool atTop)
unsigned int y = 0;
unsigned int nextChar;
const char *const hyphen = "~";
- const unsigned int hyphenWidth = static_cast<unsigned int>(
+ const unsigned int hyphenWidth = CAST_U32(
font->getWidth(hyphen));
unsigned int x = 0;
@@ -384,24 +384,24 @@ void BrowserBox::addRow(const std::string &row, const bool atTop)
for (unsigned int j = 0, sz = tempRow.size(); j < sz; j++)
{
const std::string character = tempRow.substr(j, 1);
- x += static_cast<unsigned int>(font->getWidth(character));
+ x += CAST_U32(font->getWidth(character));
nextChar = j + 1;
// Wraping between words (at blank spaces)
if (nextChar < sz && tempRow.at(nextChar) == ' ')
{
- unsigned int nextSpacePos = static_cast<unsigned int>(
+ unsigned int nextSpacePos = CAST_U32(
tempRow.find(" ", (nextChar + 1)));
if (nextSpacePos <= 0)
- nextSpacePos = static_cast<unsigned int>(sz) - 1U;
+ nextSpacePos = CAST_U32(sz) - 1U;
const unsigned int nextWordWidth =
- static_cast<unsigned int>(font->getWidth(
+ CAST_U32(font->getWidth(
tempRow.substr(nextChar,
(nextSpacePos - nextChar))));
if ((x + nextWordWidth + 10)
- > static_cast<unsigned>(getWidth()))
+ > CAST_U32(getWidth()))
{
x = mNewLinePadding; // Ident in new line
y += 1;
@@ -410,7 +410,7 @@ void BrowserBox::addRow(const std::string &row, const bool atTop)
}
// Wrapping looong lines (brutal force)
else if ((x + 2 * hyphenWidth)
- > static_cast<unsigned>(getWidth()))
+ > CAST_U32(getWidth()))
{
x = mNewLinePadding; // Ident in new line
y += 1;
@@ -418,12 +418,12 @@ void BrowserBox::addRow(const std::string &row, const bool atTop)
}
}
- setHeight(fontHeight * (static_cast<int>(
- static_cast<unsigned int>(mTextRows.size()) + y)));
+ setHeight(fontHeight * (CAST_S32(
+ CAST_U32(mTextRows.size()) + y)));
}
else
{
- setHeight(fontHeight * static_cast<int>(mTextRows.size()));
+ setHeight(fontHeight * CAST_S32(mTextRows.size()));
}
mUpdateTime = 0;
updateHeight();
@@ -478,7 +478,7 @@ void BrowserBox::mouseMoved(MouseEvent &event)
MouseOverLink(event.getX(), event.getY()));
mSelectedLink = (i != mLinks.end())
- ? static_cast<int>(i - mLinks.begin()) : -1;
+ ? CAST_S32(i - mLinks.begin()) : -1;
}
void BrowserBox::mouseExited(MouseEvent &event A_UNUSED)
@@ -506,11 +506,11 @@ void BrowserBox::draw(Graphics *graphics)
}
if (mSelectedLink >= 0 && mSelectedLink
- < static_cast<signed>(mLinks.size()))
+ < CAST_S32(mLinks.size()))
{
if ((mHighMode & BACKGROUND))
{
- BrowserLink &link = mLinks[static_cast<size_t>(mSelectedLink)];
+ BrowserLink &link = mLinks[CAST_SIZE(mSelectedLink)];
graphics->setColor(mHighlightColor);
graphics->fillRectangle(Rect(
link.x1,
@@ -521,7 +521,7 @@ void BrowserBox::draw(Graphics *graphics)
if ((mHighMode & UNDERLINE))
{
- BrowserLink &link = mLinks[static_cast<size_t>(mSelectedLink)];
+ BrowserLink &link = mLinks[CAST_SIZE(mSelectedLink)];
graphics->setColor(mHyperLinkColor);
graphics->drawLine(
link.x1,
@@ -575,13 +575,13 @@ void BrowserBox::safeDraw(Graphics *graphics)
int BrowserBox::calcHeight()
{
- unsigned int y = static_cast<unsigned int>(mPadding);
+ unsigned int y = CAST_U32(mPadding);
int wrappedLines = 0;
int moreHeight = 0;
int maxWidth = mDimension.width - mPadding;
int link = 0;
bool bold = false;
- unsigned int wWidth = static_cast<unsigned int>(maxWidth);
+ unsigned int wWidth = CAST_U32(maxWidth);
if (maxWidth < 0)
return 1;
@@ -598,7 +598,7 @@ int BrowserBox::calcHeight()
FOR_EACH (TextRowCIter, i, mTextRows)
{
- unsigned int x = static_cast<unsigned int>(mPadding);
+ unsigned int x = CAST_U32(mPadding);
const std::string row = *(i);
bool wrapped = false;
int objects = 0;
@@ -607,16 +607,16 @@ int BrowserBox::calcHeight()
if (row.find("---", 0) == 0)
{
const int dashWidth = fontWidthMinus;
- for (x = static_cast<unsigned int>(mPadding); x < wWidth; x ++)
+ for (x = CAST_U32(mPadding); x < wWidth; x ++)
{
- mLineParts.push_back(LinePart(static_cast<int>(x),
- static_cast<int>(y) + mItemPadding,
+ mLineParts.push_back(LinePart(CAST_S32(x),
+ CAST_S32(y) + mItemPadding,
selColor[0], selColor[1], "-", false));
- x += static_cast<unsigned int>(static_cast<int>(
+ x += CAST_U32(CAST_S32(
dashWidth) - 2);
}
- y += static_cast<unsigned int>(fontHeight);
+ y += CAST_U32(fontHeight);
continue;
}
else if (mEnableImages && row.find("~~~", 0) == 0)
@@ -629,10 +629,10 @@ int BrowserBox::calcHeight()
if (img)
{
img->incRef();
- mLineParts.push_back(LinePart(static_cast<int>(x),
- static_cast<int>(y) + mItemPadding,
+ mLineParts.push_back(LinePart(CAST_S32(x),
+ CAST_S32(y) + mItemPadding,
selColor[0], selColor[1], img));
- y += static_cast<unsigned int>(img->getHeight() + 2);
+ y += CAST_U32(img->getHeight() + 2);
moreHeight += img->getHeight();
if (img->getWidth() > maxWidth)
maxWidth = img->getWidth() + 2;
@@ -645,7 +645,7 @@ int BrowserBox::calcHeight()
prevColor[1] = selColor[1];
bold = false;
- const int xPadding = static_cast<int>(mNewLinePadding) + mPadding;
+ const int xPadding = CAST_S32(mNewLinePadding) + mPadding;
for (size_t start = 0, end = std::string::npos;
start != std::string::npos;
@@ -656,8 +656,8 @@ int BrowserBox::calcHeight()
// Wrapped line continuation shall be indented
if (wrapped)
{
- y += static_cast<unsigned int>(fontHeight);
- x = static_cast<unsigned int>(xPadding);
+ y += CAST_U32(fontHeight);
+ x = CAST_U32(xPadding);
wrapped = false;
}
@@ -683,7 +683,7 @@ int BrowserBox::calcHeight()
const Color col[2] =
{
getThemeCharColor(c, valid),
- getThemeCharColor(static_cast<signed char>(
+ getThemeCharColor(CAST_S8(
c | 0x80), valid)
};
@@ -763,17 +763,17 @@ int BrowserBox::calcHeight()
}
}
- if (c == '<' && link < static_cast<signed>(mLinks.size()))
+ if (c == '<' && link < CAST_S32(mLinks.size()))
{
const int size = font->getWidth(
- mLinks[static_cast<size_t>(link)].caption) + 1;
+ mLinks[CAST_SIZE(link)].caption) + 1;
- BrowserLink &linkRef = mLinks[static_cast<size_t>(
+ BrowserLink &linkRef = mLinks[CAST_SIZE(
link)];
- linkRef.x1 = static_cast<int>(x);
- linkRef.y1 = static_cast<int>(y);
+ linkRef.x1 = CAST_S32(x);
+ linkRef.y1 = CAST_S32(y);
linkRef.x2 = linkRef.x1 + size;
- linkRef.y2 = static_cast<int>(y) + fontHeight - 1;
+ linkRef.y2 = CAST_S32(y) + fontHeight - 1;
link++;
}
@@ -802,15 +802,15 @@ int BrowserBox::calcHeight()
if (mEmotes)
{
const size_t sz = mEmotes->size();
- if (static_cast<size_t>(cid) < sz)
+ if (CAST_SIZE(cid) < sz)
{
Image *const img = mEmotes->get(
- static_cast<size_t>(cid));
+ CAST_SIZE(cid));
if (img)
{
mLineParts.push_back(LinePart(
- static_cast<int>(x),
- static_cast<int>(y) + mItemPadding,
+ CAST_S32(x),
+ CAST_S32(y) + mItemPadding,
selColor[0], selColor[1], img));
x += 18;
}
@@ -844,7 +844,7 @@ int BrowserBox::calcHeight()
// Auto wrap mode
if (mMode == AUTO_WRAP && wWidth > 0 && width > 0
- && (x + static_cast<unsigned int>(width) + 10) > wWidth)
+ && (x + CAST_U32(width) + 10) > wWidth)
{
bool forced = false;
@@ -862,7 +862,7 @@ int BrowserBox::calcHeight()
{
forced = true;
end = row.size();
- x += static_cast<unsigned int>(hyphenWidth);
+ x += CAST_U32(hyphenWidth);
continue;
}
@@ -879,14 +879,14 @@ int BrowserBox::calcHeight()
}
while (end > start &&
width > 0 &&
- (x + static_cast<unsigned int>(width) + 10) > wWidth);
+ (x + CAST_U32(width) + 10) > wWidth);
if (forced)
{
- x -= static_cast<unsigned int>(hyphenWidth);
+ x -= CAST_U32(hyphenWidth);
mLineParts.push_back(LinePart(
- static_cast<int>(wWidth) - hyphenWidth,
- static_cast<int>(y) + mItemPadding,
+ CAST_S32(wWidth) - hyphenWidth,
+ CAST_S32(y) + mItemPadding,
selColor[0], selColor[1], hyphen, bold));
end++; // Skip to the next character
}
@@ -899,8 +899,8 @@ int BrowserBox::calcHeight()
wrappedLines++;
}
- mLineParts.push_back(LinePart(static_cast<int>(x),
- static_cast<int>(y) + mItemPadding,
+ mLineParts.push_back(LinePart(CAST_S32(x),
+ CAST_S32(y) + mItemPadding,
selColor[0], selColor[1], part.c_str(), bold));
if (bold)
@@ -911,16 +911,16 @@ int BrowserBox::calcHeight()
if (mMode == AUTO_WRAP && (width == 0 && !processed))
break;
- x += static_cast<unsigned int>(width);
+ x += CAST_U32(width);
if (x > mDataWidth)
mDataWidth = x;
}
- y += static_cast<unsigned int>(fontHeight);
+ y += CAST_U32(fontHeight);
}
- if (static_cast<signed>(wWidth) != maxWidth)
+ if (CAST_S32(wWidth) != maxWidth)
setWidth(maxWidth);
- return (static_cast<int>(mTextRows.size()) + wrappedLines)
+ return (CAST_S32(mTextRows.size()) + wrappedLines)
* fontHeight + moreHeight + 2 * mPadding;
}
@@ -981,7 +981,7 @@ void BrowserBox::setForegroundColorAll(const Color &color1,
void BrowserBox::moveSelectionUp()
{
if (mSelectedLink <= 0)
- mSelectedLink = static_cast<signed>(mLinks.size()) - 1;
+ mSelectedLink = CAST_S32(mLinks.size()) - 1;
else
mSelectedLink --;
}
@@ -1002,6 +1002,6 @@ void BrowserBox::selectSelection()
return;
}
- mLinkHandler->handleLink(mLinks[static_cast<size_t>(mSelectedLink)].link,
+ mLinkHandler->handleLink(mLinks[CAST_SIZE(mSelectedLink)].link,
nullptr);
}
diff --git a/src/gui/widgets/characterdisplay.cpp b/src/gui/widgets/characterdisplay.cpp
index b74ec842f..7aed3469c 100644
--- a/src/gui/widgets/characterdisplay.cpp
+++ b/src/gui/widgets/characterdisplay.cpp
@@ -134,7 +134,7 @@ void CharacterDisplay::mouseMoved(MouseEvent &event A_UNUSED)
name,
// TRANSLATORS: character level
strprintf(_("Level: %u"),
- static_cast<uint32_t>(
+ CAST_U32(
mCharacter->data.mAttributes[Attributes::LEVEL])),
// TRANSLATORS: character money
strprintf(_("Money: %s"), Units::formatCurrency(
diff --git a/src/gui/widgets/characterviewnormal.cpp b/src/gui/widgets/characterviewnormal.cpp
index 10469adac..8d374fc4c 100644
--- a/src/gui/widgets/characterviewnormal.cpp
+++ b/src/gui/widgets/characterviewnormal.cpp
@@ -44,7 +44,7 @@ CharacterViewNormal::CharacterViewNormal(CharSelectDialog *const widget,
character->setVisible(Visible_true);
}
const size_t sz = mCharacterEntries->size();
- if (mSelected >= 0 && mSelected < static_cast<signed>(sz))
+ if (mSelected >= 0 && mSelected < CAST_S32(sz))
{
CharacterDisplay *const display = (*mCharacterEntries)[mSelected];
if (display)
@@ -72,7 +72,7 @@ CharacterViewNormal::~CharacterViewNormal()
void CharacterViewNormal::show(const int i)
{
- const int sz = static_cast<signed>(mCharacterEntries->size());
+ const int sz = CAST_S32(mCharacterEntries->size());
if (i >= 0 && i < sz)
{
if (mSelected >= 0)
@@ -84,7 +84,7 @@ void CharacterViewNormal::show(const int i)
void CharacterViewNormal::resize()
{
- const int sz = static_cast<signed>(mCharacterEntries->size());
+ const int sz = CAST_S32(mCharacterEntries->size());
if (sz <= 0)
return;
const CharacterDisplay *const firtChar = (*mCharacterEntries)[0];
diff --git a/src/gui/widgets/characterviewsmall.cpp b/src/gui/widgets/characterviewsmall.cpp
index 3ae0229c9..24961f3ce 100644
--- a/src/gui/widgets/characterviewsmall.cpp
+++ b/src/gui/widgets/characterviewsmall.cpp
@@ -47,7 +47,7 @@ CharacterViewSmall::CharacterViewSmall(CharSelectDialog *const widget,
{
add(*it);
}
- const int sz = static_cast<signed>(mCharacterEntries->size());
+ const int sz = CAST_S32(mCharacterEntries->size());
if (sz > 0)
{
mSelected = 0;
@@ -78,7 +78,7 @@ CharacterViewSmall::~CharacterViewSmall()
void CharacterViewSmall::show(const int i)
{
- const int sz = static_cast<signed>(mCharacterEntries->size());
+ const int sz = CAST_S32(mCharacterEntries->size());
if (sz <= 0)
return;
if (mSelectedEntry)
@@ -97,7 +97,7 @@ void CharacterViewSmall::show(const int i)
void CharacterViewSmall::resize()
{
- const int sz = static_cast<signed>(mCharacterEntries->size());
+ const int sz = CAST_S32(mCharacterEntries->size());
if (sz <= 0)
return;
const CharacterDisplay *const firtChar = (*mCharacterEntries)[0];
diff --git a/src/gui/widgets/colorpage.cpp b/src/gui/widgets/colorpage.cpp
index 078f5bb48..a668f2d6f 100644
--- a/src/gui/widgets/colorpage.cpp
+++ b/src/gui/widgets/colorpage.cpp
@@ -36,11 +36,11 @@ ColorPage::ColorPage(const Widget2 *const widget,
mItemPadding = mSkin ? mSkin->getOption("itemPadding") : 1;
mRowHeight = 13;
const Font *const font = getFont();
- mRowHeight = static_cast<unsigned int>(font->getHeight() +
+ mRowHeight = CAST_U32(font->getHeight() +
2 * mItemPadding);
if (mListModel)
{
- setHeight(static_cast<int>(getRowHeight()) *
+ setHeight(CAST_S32(getRowHeight()) *
mListModel->getNumberOfElements()
+ 2 * mPadding + 20);
}
@@ -57,11 +57,11 @@ void ColorPage::draw(Graphics *graphics)
const ColorModel *const model = static_cast<ColorModel* const>(
mListModel);
- mHighlightColor.a = static_cast<unsigned int>(mAlpha * 255.0F);
+ mHighlightColor.a = CAST_U32(mAlpha * 255.0F);
updateAlpha();
Font *const font = getFont();
- const int rowHeight = static_cast<int>(getRowHeight());
+ const int rowHeight = CAST_S32(getRowHeight());
const int width = mDimension.width;
if (mSelected >= 0)
@@ -115,7 +115,7 @@ void ColorPage::adjustSize()
BLOCK_START("ColorPage::adjustSize")
if (mListModel)
{
- setHeight(static_cast<int>(getRowHeight()) *
+ setHeight(CAST_S32(getRowHeight()) *
mListModel->getNumberOfElements() +
2 * mPadding + 20);
}
diff --git a/src/gui/widgets/dropdown.cpp b/src/gui/widgets/dropdown.cpp
index 629bda46b..506503e01 100644
--- a/src/gui/widgets/dropdown.cpp
+++ b/src/gui/widgets/dropdown.cpp
@@ -150,7 +150,7 @@ DropDown::DropDown(const Widget2 *const widget,
if (mSkin)
{
mSpacing = mSkin->getOption("spacing");
- mFrameSize = static_cast<unsigned int>(mSkin->getOption("frameSize"));
+ mFrameSize = CAST_U32(mSkin->getOption("frameSize"));
mPadding = mSkin->getPadding();
mImagePadding = mSkin->getOption("imagePadding");
}
@@ -219,7 +219,7 @@ void DropDown::draw(Graphics* graphics)
updateAlpha();
- const unsigned int alpha = static_cast<unsigned int>(mAlpha * 255.0F);
+ const unsigned int alpha = CAST_U32(mAlpha * 255.0F);
const int pad = 2 * mPadding;
mHighlightColor.a = alpha;
mShadowColor.a = alpha;
@@ -294,7 +294,7 @@ void DropDown::safeDraw(Graphics* graphics)
void DropDown::drawFrame(Graphics *graphics)
{
BLOCK_START("DropDown::drawFrame")
- const int bs2 = static_cast<int>(getFrameSize());
+ const int bs2 = CAST_S32(getFrameSize());
const Rect &rect = mDimension;
graphics->drawImageRect(0, 0,
rect.width + bs2, rect.height + bs2,
@@ -305,7 +305,7 @@ void DropDown::drawFrame(Graphics *graphics)
void DropDown::safeDrawFrame(Graphics *graphics)
{
BLOCK_START("DropDown::drawFrame")
- const int bs2 = static_cast<int>(getFrameSize());
+ const int bs2 = CAST_S32(getFrameSize());
const Rect &rect = mDimension;
graphics->drawImageRect(0, 0,
rect.width + bs2, rect.height + bs2,
@@ -476,7 +476,7 @@ void DropDown::dropDown()
int x = 0;
int y = 0;
getAbsolutePosition(x, y);
- const int frame = static_cast<int>(mParent->getFrameSize());
+ const int frame = CAST_S32(mParent->getFrameSize());
const int pad = mPopup->getPadding();
const int pad2 = pad * 2;
diff --git a/src/gui/widgets/emotepage.cpp b/src/gui/widgets/emotepage.cpp
index 92c10f8a9..6e3732413 100644
--- a/src/gui/widgets/emotepage.cpp
+++ b/src/gui/widgets/emotepage.cpp
@@ -142,7 +142,7 @@ int EmotePage::getIndexFromGrid(const int x, const int y) const
return -1;
const int cols = width / emoteWidth;
const int index = (y / emoteHeight) * cols + (x / emoteWidth);
- if (index >= static_cast<int>(mEmotes->size()))
+ if (index >= CAST_S32(mEmotes->size()))
return -1;
return index;
}
diff --git a/src/gui/widgets/emoteshortcutcontainer.cpp b/src/gui/widgets/emoteshortcutcontainer.cpp
index 1a7f73b95..6df0cd398 100644
--- a/src/gui/widgets/emoteshortcutcontainer.cpp
+++ b/src/gui/widgets/emoteshortcutcontainer.cpp
@@ -97,7 +97,7 @@ void EmoteShortcutContainer::draw(Graphics *restrict graphics) restrict2
Font *const font = getFont();
drawBackground(graphics);
- unsigned sz = static_cast<unsigned>(mEmoteImg.size());
+ unsigned sz = CAST_U32(mEmoteImg.size());
if (sz > mMaxItems)
sz = mMaxItems;
for (unsigned i = 0; i < sz; i++)
@@ -149,7 +149,7 @@ void EmoteShortcutContainer::safeDraw(Graphics *restrict graphics) restrict2
Font *const font = getFont();
safeDrawBackground(graphics);
- unsigned sz = static_cast<unsigned>(mEmoteImg.size());
+ unsigned sz = CAST_U32(mEmoteImg.size());
if (sz > mMaxItems)
sz = mMaxItems;
for (unsigned i = 0; i < sz; i++)
@@ -258,7 +258,7 @@ void EmoteShortcutContainer::mouseMoved(MouseEvent &restrict event) restrict2
textPopup->setVisible(Visible_false);
- if (static_cast<size_t>(index) < mEmoteImg.size() && mEmoteImg[index])
+ if (CAST_SIZE(index) < mEmoteImg.size() && mEmoteImg[index])
{
const EmoteSprite *restrict const sprite = mEmoteImg[index];
textPopup->show(viewport->mMouseX, viewport->mMouseY,
diff --git a/src/gui/widgets/extendedlistbox.cpp b/src/gui/widgets/extendedlistbox.cpp
index 23daafb8e..fd9b4c660 100644
--- a/src/gui/widgets/extendedlistbox.cpp
+++ b/src/gui/widgets/extendedlistbox.cpp
@@ -59,7 +59,7 @@ void ExtendedListBox::draw(Graphics *graphics)
updateAlpha();
Font *const font = getFont();
- const int height = static_cast<int>(mRowHeight);
+ const int height = CAST_S32(mRowHeight);
const int pad2 = 2 + mPadding;
const int width = mDimension.width;
int textPos = (height - font->getHeight()) / 2 + mPadding;
@@ -89,7 +89,7 @@ void ExtendedListBox::draw(Graphics *graphics)
{
const size_t strSize = str.size();
size_t divPos = strSize / 2;
- if (divPos > 0 && static_cast<unsigned char>(
+ if (divPos > 0 && CAST_U8(
str[divPos - 1]) >= 0xc0)
{
divPos --;
@@ -130,7 +130,7 @@ void ExtendedListBox::draw(Graphics *graphics)
if (minY != -1)
{
- mHighlightColor.a = static_cast<unsigned int>(mAlpha * 255.0F);
+ mHighlightColor.a = CAST_U32(mAlpha * 255.0F);
graphics->setColor(mHighlightColor);
graphics->fillRectangle(Rect(mPadding, minY + mPadding,
width - pad2, maxY - minY + height));
@@ -233,7 +233,7 @@ int ExtendedListBox::getSelectionByMouse(const int y) const
if (mListItems.empty() && mSelectedItems.empty())
return ListBox::getSelectionByMouse(y);
- const int height = static_cast<int>(mRowHeight);
+ const int height = CAST_S32(mRowHeight);
const size_t itemsSz = mListItems.size();
for (size_t f = 0; f < itemsSz; f ++)
{
diff --git a/src/gui/widgets/flowcontainer.cpp b/src/gui/widgets/flowcontainer.cpp
index 7984ef0f7..d6f10248e 100644
--- a/src/gui/widgets/flowcontainer.cpp
+++ b/src/gui/widgets/flowcontainer.cpp
@@ -48,7 +48,7 @@ void FlowContainer::widgetResized(const Event &event A_UNUSED)
return;
}
- const int itemCount = static_cast<int>(mWidgets.size());
+ const int itemCount = CAST_S32(mWidgets.size());
if (!mBoxWidth)
mGridWidth = getWidth();
diff --git a/src/gui/widgets/guitable.cpp b/src/gui/widgets/guitable.cpp
index 00f925aff..c41d4886c 100644
--- a/src/gui/widgets/guitable.cpp
+++ b/src/gui/widgets/guitable.cpp
@@ -235,7 +235,7 @@ void GuiTable::draw(Graphics* graphics)
const int y = rect.y;
if (mOpaque)
{
- mBackgroundColor.a = static_cast<unsigned int>(mAlpha * 255.0F);
+ mBackgroundColor.a = CAST_U32(mAlpha * 255.0F);
graphics->setColor(mBackgroundColor);
graphics->fillRectangle(Rect(0, 0, width, height));
}
@@ -250,7 +250,7 @@ void GuiTable::draw(Graphics* graphics)
if (first_row < 0)
first_row = 0;
- unsigned int rows_nr = static_cast<unsigned int>(1 +
+ unsigned int rows_nr = CAST_U32(1 +
height / rHeight); // May overestimate by one.
unsigned int max_rows_nr;
if (mModel->getRows() < first_row)
@@ -259,7 +259,7 @@ void GuiTable::draw(Graphics* graphics)
}
else
{
- max_rows_nr = static_cast<unsigned int>(
+ max_rows_nr = CAST_U32(
mModel->getRows() - first_row); // clip if neccessary:
}
if (max_rows_nr < rows_nr)
@@ -268,23 +268,23 @@ void GuiTable::draw(Graphics* graphics)
// Now determine the first and last column
// Take the easy way out; these are usually bounded and all visible.
const unsigned first_column = 0;
- const unsigned last_column1 = static_cast<unsigned int>(
+ const unsigned last_column1 = CAST_U32(
mModel->getColumns());
int y_offset = first_row * rHeight;
- for (unsigned int r = static_cast<unsigned int>(first_row);
- r < static_cast<unsigned int>(first_row) + rows_nr;
+ for (unsigned int r = CAST_U32(first_row);
+ r < CAST_U32(first_row) + rows_nr;
++r)
{
int x_offset = 0;
for (unsigned c = first_column; c + 1 <= last_column1; ++c)
{
- Widget *const widget = mModel->getElementAt(static_cast<int>(r),
- static_cast<int>(c));
- const int cWidth = static_cast<int>(getColumnWidth(
- static_cast<int>(c)));
+ Widget *const widget = mModel->getElementAt(CAST_S32(r),
+ CAST_S32(c));
+ const int cWidth = CAST_S32(getColumnWidth(
+ CAST_S32(c)));
if (widget)
{
Rect bounds(x_offset, y_offset, cWidth, rHeight);
@@ -299,19 +299,19 @@ void GuiTable::draw(Graphics* graphics)
if (mSelectedRow > -1)
{
- mHighlightColor.a = static_cast<unsigned int>(
+ mHighlightColor.a = CAST_U32(
mAlpha * 255.0F);
graphics->setColor(mHighlightColor);
- if (mLinewiseMode && r == static_cast<unsigned>(
+ if (mLinewiseMode && r == CAST_U32(
mSelectedRow) && c == 0)
{
graphics->fillRectangle(Rect(0, y_offset,
width, rHeight));
}
else if (!mLinewiseMode && mSelectedColumn > 0
- && c == static_cast<unsigned>(mSelectedColumn)
- && r == static_cast<unsigned>(mSelectedRow))
+ && c == CAST_U32(mSelectedColumn)
+ && r == CAST_U32(mSelectedRow))
{
graphics->fillRectangle(Rect(
x_offset, y_offset, cWidth, rHeight));
@@ -353,7 +353,7 @@ void GuiTable::safeDraw(Graphics* graphics)
const int y = rect.y;
if (mOpaque)
{
- mBackgroundColor.a = static_cast<unsigned int>(mAlpha * 255.0F);
+ mBackgroundColor.a = CAST_U32(mAlpha * 255.0F);
graphics->setColor(mBackgroundColor);
graphics->fillRectangle(Rect(0, 0, width, height));
}
@@ -368,7 +368,7 @@ void GuiTable::safeDraw(Graphics* graphics)
if (first_row < 0)
first_row = 0;
- unsigned int rows_nr = static_cast<unsigned int>(
+ unsigned int rows_nr = CAST_U32(
1 + height / rHeight); // May overestimate by one.
unsigned int max_rows_nr;
if (mModel->getRows() < first_row)
@@ -377,7 +377,7 @@ void GuiTable::safeDraw(Graphics* graphics)
}
else
{
- max_rows_nr = static_cast<unsigned int>(
+ max_rows_nr = CAST_U32(
mModel->getRows() - first_row); // clip if neccessary:
}
if (max_rows_nr < rows_nr)
@@ -386,23 +386,23 @@ void GuiTable::safeDraw(Graphics* graphics)
// Now determine the first and last column
// Take the easy way out; these are usually bounded and all visible.
const unsigned int first_column = 0;
- const unsigned int last_column1 = static_cast<unsigned int>(
+ const unsigned int last_column1 = CAST_U32(
mModel->getColumns());
int y_offset = first_row * rHeight;
- for (unsigned int r = static_cast<unsigned int>(first_row);
- r < static_cast<unsigned int>(first_row + static_cast<int>(rows_nr));
+ for (unsigned int r = CAST_U32(first_row);
+ r < CAST_U32(first_row + CAST_S32(rows_nr));
++r)
{
int x_offset = 0;
for (unsigned c = first_column; c + 1 <= last_column1; ++c)
{
- Widget *const widget = mModel->getElementAt(static_cast<int>(r),
- static_cast<int>(c));
- const int cWidth = static_cast<int>(getColumnWidth(
- static_cast<int>(c)));
+ Widget *const widget = mModel->getElementAt(CAST_S32(r),
+ CAST_S32(c));
+ const int cWidth = CAST_S32(getColumnWidth(
+ CAST_S32(c)));
if (widget)
{
Rect bounds(x_offset, y_offset, cWidth, rHeight);
@@ -417,19 +417,19 @@ void GuiTable::safeDraw(Graphics* graphics)
if (mSelectedRow > -1)
{
- mHighlightColor.a = static_cast<unsigned int>(
+ mHighlightColor.a = CAST_U32(
mAlpha * 255.0F);
graphics->setColor(mHighlightColor);
- if (mLinewiseMode && r == static_cast<unsigned>(
+ if (mLinewiseMode && r == CAST_U32(
mSelectedRow) && c == 0)
{
graphics->fillRectangle(Rect(0, y_offset,
width, rHeight));
}
else if (!mLinewiseMode && mSelectedColumn > 0
- && c == static_cast<unsigned>(mSelectedColumn)
- && r == static_cast<unsigned>(mSelectedRow))
+ && c == CAST_U32(mSelectedColumn)
+ && r == CAST_U32(mSelectedRow))
{
graphics->fillRectangle(Rect(
x_offset, y_offset, cWidth, rHeight));
diff --git a/src/gui/widgets/inttextfield.cpp b/src/gui/widgets/inttextfield.cpp
index 925ff34b4..cb01c12a3 100644
--- a/src/gui/widgets/inttextfield.cpp
+++ b/src/gui/widgets/inttextfield.cpp
@@ -130,7 +130,7 @@ void IntTextField::setValue(const int i)
const std::string valStr = toString(mValue);
setText(valStr);
- setCaretPosition(static_cast<unsigned>(valStr.length()) + 1);
+ setCaretPosition(CAST_U32(valStr.length()) + 1);
}
void IntTextField::setDefaultValue(const int value)
diff --git a/src/gui/widgets/itemcontainer.cpp b/src/gui/widgets/itemcontainer.cpp
index 4c183d87d..9bb1f0da3 100644
--- a/src/gui/widgets/itemcontainer.cpp
+++ b/src/gui/widgets/itemcontainer.cpp
@@ -638,7 +638,7 @@ void ItemContainer::mousePressed(MouseEvent &event)
if (itemShortcutWindow)
{
const int num = itemShortcutWindow->getTabIndex();
- if (num >= 0 && num < static_cast<int>(SHORTCUT_TABS))
+ if (num >= 0 && num < CAST_S32(SHORTCUT_TABS))
{
if (itemShortcut[num])
itemShortcut[num]->setItemSelected(item);
@@ -1047,7 +1047,7 @@ void ItemContainer::updateMatrix()
mRedraw = true;
delete []mShowMatrix;
- mShowMatrix = new int[static_cast<size_t>(mGridRows * mGridColumns)];
+ mShowMatrix = new int[CAST_SIZE(mGridRows * mGridColumns)];
std::vector<ItemIdPair*> sortedItems;
int i = 0;
diff --git a/src/gui/widgets/layoutarray.cpp b/src/gui/widgets/layoutarray.cpp
index 74bbebd87..5b726b9cc 100644
--- a/src/gui/widgets/layoutarray.cpp
+++ b/src/gui/widgets/layoutarray.cpp
@@ -59,7 +59,7 @@ LayoutCell &LayoutArray::at(const int x, const int y,
const int w, const int h)
{
resizeGrid(x + w, y + h);
- LayoutCell *&cell = mCells[static_cast<size_t>(y)][static_cast<size_t>(x)];
+ LayoutCell *&cell = mCells[CAST_SIZE(y)][static_cast<size_t>(x)];
if (!cell)
cell = new LayoutCell;
return *cell;
@@ -67,22 +67,22 @@ LayoutCell &LayoutArray::at(const int x, const int y,
void LayoutArray::resizeGrid(int w, const int h)
{
- const bool extW = w && w > static_cast<int>(mSizes[0].size());
- const bool extH = h && h > static_cast<int>(mSizes[1].size());
+ const bool extW = w && w > CAST_S32(mSizes[0].size());
+ const bool extH = h && h > CAST_S32(mSizes[1].size());
if (!extW && !extH)
return;
if (extH)
{
- mSizes[1].resize(static_cast<size_t>(h), LayoutType::DEF);
- mCells.resize(static_cast<size_t>(h));
+ mSizes[1].resize(CAST_SIZE(h), LayoutType::DEF);
+ mCells.resize(CAST_SIZE(h));
if (!extW)
- w = static_cast<int>(mSizes[0].size());
+ w = CAST_S32(mSizes[0].size());
}
if (extW)
- mSizes[0].resize(static_cast<size_t>(w), LayoutType::DEF);
+ mSizes[0].resize(CAST_SIZE(w), LayoutType::DEF);
std::vector <std::vector <LayoutCell *> >::iterator
i = mCells.begin();
@@ -90,7 +90,7 @@ void LayoutArray::resizeGrid(int w, const int h)
i_end = mCells.end();
while (i != i_end)
{
- i->resize(static_cast<size_t>(w), nullptr);
+ i->resize(CAST_SIZE(w), nullptr);
++i;
}
}
@@ -98,23 +98,23 @@ void LayoutArray::resizeGrid(int w, const int h)
void LayoutArray::setColWidth(const int n, const int w)
{
resizeGrid(n + 1, 0);
- mSizes[0U][static_cast<size_t>(n)] = w;
+ mSizes[0U][CAST_SIZE(n)] = w;
}
void LayoutArray::setRowHeight(const int n, const int h)
{
resizeGrid(0, n + 1);
- mSizes[1][static_cast<size_t>(n)] = h;
+ mSizes[1][CAST_SIZE(n)] = h;
}
void LayoutArray::matchColWidth(const int n1, const int n2)
{
resizeGrid(std::max(n1, n2) + 1, 0);
const std::vector<int> widths = getSizes(0, LayoutType::DEF);
- const int s = std::max(widths[static_cast<size_t>(n1)],
- widths[static_cast<size_t>(n2)]);
- mSizes[0][static_cast<size_t>(n1)] = s;
- mSizes[0][static_cast<size_t>(n2)] = s;
+ const int s = std::max(widths[CAST_SIZE(n1)],
+ widths[CAST_SIZE(n2)]);
+ mSizes[0][CAST_SIZE(n1)] = s;
+ mSizes[0][CAST_SIZE(n2)] = s;
}
void LayoutArray::extend(const int x, const int y, const int w, const int h)
@@ -147,8 +147,8 @@ LayoutCell &LayoutArray::place(Widget *const widget, const int x,
cell.mVPadding = 0;
cell.mAlign[0] = LayoutCell::FILL;
cell.mAlign[1] = LayoutCell::FILL;
- int &cs = mSizes[0][static_cast<size_t>(x)];
- int &rs = mSizes[1][static_cast<size_t>(y)];
+ int &cs = mSizes[0][CAST_SIZE(x)];
+ int &rs = mSizes[1][CAST_SIZE(y)];
if (cs == LayoutType::DEF && w == 1)
cs = 0;
if (rs == LayoutType::DEF && h == 1)
@@ -196,8 +196,8 @@ std::vector<int> LayoutArray::getSizes(const int dim, int upp) const
if (dim < 0 || dim >= 2)
return mSizes[1];
- const int gridW = static_cast<int>(mSizes[0].size());
- const int gridH = static_cast<int>(mSizes[1].size());
+ const int gridW = CAST_S32(mSizes[0].size());
+ const int gridH = CAST_S32(mSizes[1].size());
std::vector<int> sizes = mSizes[dim];
// Compute minimum sizes.
@@ -205,8 +205,8 @@ std::vector<int> LayoutArray::getSizes(const int dim, int upp) const
{
for (int gridX = 0; gridX < gridW; ++gridX)
{
- const LayoutCell *const cell = mCells[static_cast<size_t>(gridY)]
- [static_cast<size_t>(gridX)];
+ const LayoutCell *const cell = mCells[CAST_SIZE(gridY)]
+ [CAST_SIZE(gridX)];
if (!cell || cell->mType == LayoutCell::NONE)
continue;
@@ -214,8 +214,8 @@ std::vector<int> LayoutArray::getSizes(const int dim, int upp) const
{
const int n = (dim == 0 ? gridX : gridY);
const int s = cell->mSize[dim] + cell->mVPadding * 2;
- if (s > sizes[static_cast<size_t>(n)])
- sizes[static_cast<size_t>(n)] = s;
+ if (s > sizes[CAST_SIZE(n)])
+ sizes[CAST_SIZE(n)] = s;
}
}
}
@@ -224,22 +224,22 @@ std::vector<int> LayoutArray::getSizes(const int dim, int upp) const
return sizes;
// Compute the FILL sizes.
- const int nb = static_cast<int>(sizes.size());
+ const int nb = CAST_S32(sizes.size());
int nbFill = 0;
for (int i = 0; i < nb; ++i)
{
- if (mSizes[static_cast<size_t>(dim)][static_cast<size_t>(i)]
+ if (mSizes[CAST_SIZE(dim)][static_cast<size_t>(i)]
<= LayoutType::DEF)
{
++nbFill;
- if (mSizes[static_cast<size_t>(dim)][static_cast<size_t>(i)] ==
+ if (mSizes[CAST_SIZE(dim)][static_cast<size_t>(i)] ==
LayoutType::SET ||
- sizes[static_cast<size_t>(i)] <= LayoutType::DEF)
+ sizes[CAST_SIZE(i)] <= LayoutType::DEF)
{
- sizes[static_cast<size_t>(i)] = 0;
+ sizes[CAST_SIZE(i)] = 0;
}
}
- upp -= sizes[static_cast<size_t>(i)] + mSpacing;
+ upp -= sizes[CAST_SIZE(i)] + mSpacing;
}
upp = upp + mSpacing;
@@ -248,14 +248,14 @@ std::vector<int> LayoutArray::getSizes(const int dim, int upp) const
for (int i = 0; i < nb; ++i)
{
- if (mSizes[static_cast<size_t>(dim)][static_cast<size_t>(i)] >
+ if (mSizes[CAST_SIZE(dim)][static_cast<size_t>(i)] >
LayoutType::DEF)
{
continue;
}
const int s = upp / nbFill;
- sizes[static_cast<size_t>(i)] += s;
+ sizes[CAST_SIZE(i)] += s;
upp -= s;
--nbFill;
}
@@ -267,11 +267,11 @@ int LayoutArray::getSize(const int dim) const
{
std::vector<int> sizes = getSizes(dim, LayoutType::DEF);
int size = 0;
- const int nb = static_cast<int>(sizes.size());
+ const int nb = CAST_S32(sizes.size());
for (int i = 0; i < nb; ++i)
{
- if (sizes[static_cast<size_t>(i)] > LayoutType::DEF)
- size += sizes[static_cast<size_t>(i)];
+ if (sizes[CAST_SIZE(i)] > LayoutType::DEF)
+ size += sizes[CAST_SIZE(i)];
size += mSpacing;
}
return size - mSpacing;
@@ -280,33 +280,33 @@ int LayoutArray::getSize(const int dim) const
void LayoutArray::reflow(const int nx, const int ny,
const int nw, const int nh)
{
- const int gridW = static_cast<int>(mSizes[0].size());
- const int gridH = static_cast<int>(mSizes[1].size());
+ const int gridW = CAST_S32(mSizes[0].size());
+ const int gridH = CAST_S32(mSizes[1].size());
std::vector<int> widths = getSizes(0, nw);
std::vector<int> heights = getSizes(1, nh);
- const int szW = static_cast<int>(widths.size());
- const int szH = static_cast<int>(heights.size());
+ const int szW = CAST_S32(widths.size());
+ const int szH = CAST_S32(heights.size());
int y = ny;
for (int gridY = 0; gridY < gridH; ++gridY)
{
int x = nx;
for (int gridX = 0; gridX < gridW; ++gridX)
{
- LayoutCell *const cell = mCells[static_cast<size_t>(gridY)]
- [static_cast<size_t>(gridX)];
+ LayoutCell *const cell = mCells[CAST_SIZE(gridY)]
+ [CAST_SIZE(gridX)];
if (cell && cell->mType != LayoutCell::NONE)
{
int dx = x, dy = y, dw = 0, dh = 0;
align(dx, dw, 0, *cell,
- &widths[static_cast<size_t>(gridX)], szW - gridX);
+ &widths[CAST_SIZE(gridX)], szW - gridX);
align(dy, dh, 1, *cell,
- &heights[static_cast<size_t>(gridY)], szH - gridY);
+ &heights[CAST_SIZE(gridY)], szH - gridY);
cell->reflow(dx, dy, dw, dh);
}
- x += widths[static_cast<size_t>(gridX)] + mSpacing;
+ x += widths[CAST_SIZE(gridX)] + mSpacing;
}
- y += heights[static_cast<size_t>(gridY)] + mSpacing;
+ y += heights[CAST_SIZE(gridY)] + mSpacing;
}
}
diff --git a/src/gui/widgets/listbox.cpp b/src/gui/widgets/listbox.cpp
index c827911eb..ced9dcb99 100644
--- a/src/gui/widgets/listbox.cpp
+++ b/src/gui/widgets/listbox.cpp
@@ -122,7 +122,7 @@ ListBox::ListBox(const Widget2 *const widget,
}
const Font *const font = getFont();
- mRowHeight = static_cast<unsigned int>(
+ mRowHeight = CAST_U32(
font->getHeight() + 2 * mItemPadding);
}
@@ -157,10 +157,10 @@ void ListBox::draw(Graphics *graphics)
BLOCK_START("ListBox::draw")
updateAlpha();
- mHighlightColor.a = static_cast<unsigned int>(mAlpha * 255.0F);
+ mHighlightColor.a = CAST_U32(mAlpha * 255.0F);
graphics->setColor(mHighlightColor);
Font *const font = getFont();
- const int rowHeight = static_cast<int>(getRowHeight());
+ const int rowHeight = CAST_S32(getRowHeight());
const int width = mDimension.width;
if (mCenterText)
@@ -359,7 +359,7 @@ void ListBox::adjustSize()
BLOCK_START("ListBox::adjustSize")
if (mListModel)
{
- setHeight(static_cast<int>(getRowHeight()) *
+ setHeight(CAST_S32(getRowHeight()) *
mListModel->getNumberOfElements() + 2 * mPadding);
}
BLOCK_END("ListBox::adjustSize")
@@ -376,7 +376,7 @@ int ListBox::getSelectionByMouse(const int y) const
{
if (y < mPadding)
return -1;
- return (y - mPadding) / static_cast<int>(getRowHeight());
+ return (y - mPadding) / CAST_S32(getRowHeight());
}
void ListBox::setSelected(const int selected)
@@ -400,9 +400,9 @@ void ListBox::setSelected(const int selected)
if (mSelected < 0)
scroll.y = 0;
else
- scroll.y = static_cast<int>(getRowHeight()) * mSelected;
+ scroll.y = CAST_S32(getRowHeight()) * mSelected;
- scroll.height = static_cast<int>(getRowHeight());
+ scroll.height = CAST_S32(getRowHeight());
showPart(scroll);
distributeValueChangedEvent();
diff --git a/src/gui/widgets/passwordfield.cpp b/src/gui/widgets/passwordfield.cpp
index a385e8387..ae47d4500 100644
--- a/src/gui/widgets/passwordfield.cpp
+++ b/src/gui/widgets/passwordfield.cpp
@@ -29,9 +29,9 @@
PasswordField::PasswordField(const Widget2 *const widget,
const std::string &text) :
TextField(widget, text),
- mPasswordChar(mSkin ? static_cast<char>(
+ mPasswordChar(mSkin ? CAST_8(
mSkin->getOption("passwordChar", 42))
- : static_cast<char>(42))
+ : CAST_8(42))
{
}
diff --git a/src/gui/widgets/progressbar.cpp b/src/gui/widgets/progressbar.cpp
index 03db3f97e..455ccc31c 100644
--- a/src/gui/widgets/progressbar.cpp
+++ b/src/gui/widgets/progressbar.cpp
@@ -161,7 +161,7 @@ void ProgressBar::draw(Graphics *graphics)
}
updateAlpha();
- mBackgroundColor.a = static_cast<unsigned int>(mAlpha * 255);
+ mBackgroundColor.a = CAST_U32(mAlpha * 255);
if (mRedraw || graphics->getRedraw())
{
@@ -173,7 +173,7 @@ void ProgressBar::draw(Graphics *graphics)
{
const unsigned int pad = 2 * mFillPadding;
const int maxWidth = mDimension.width - pad;
- int width = static_cast<int>(mProgress
+ int width = CAST_S32(mProgress
* static_cast<float>(maxWidth));
if (width > 0)
{
@@ -194,7 +194,7 @@ void ProgressBar::draw(Graphics *graphics)
graphics->setColor(mBackgroundColor);
const unsigned int pad = 2 * mFillPadding;
const int maxWidth = mDimension.width - pad;
- int width = static_cast<int>(mProgress * static_cast<float>(maxWidth));
+ int width = CAST_S32(mProgress * static_cast<float>(maxWidth));
if (width > 0)
{
if (width > maxWidth)
@@ -240,7 +240,7 @@ void ProgressBar::safeDraw(Graphics *graphics)
}
updateAlpha();
- mBackgroundColor.a = static_cast<unsigned int>(mAlpha * 255);
+ mBackgroundColor.a = CAST_U32(mAlpha * 255);
graphics->drawImageRect(0, 0, mDimension.width, mDimension.height,
mSkin->getBorder());
@@ -248,7 +248,7 @@ void ProgressBar::safeDraw(Graphics *graphics)
{
const unsigned int pad = 2 * mFillPadding;
const int maxWidth = mDimension.width - pad;
- int width = static_cast<int>(mProgress
+ int width = CAST_S32(mProgress
* static_cast<float>(maxWidth));
if (width > 0)
{
@@ -265,7 +265,7 @@ void ProgressBar::safeDraw(Graphics *graphics)
graphics->setColor(mBackgroundColor);
const unsigned int pad = 2 * mFillPadding;
const int maxWidth = mDimension.width - pad;
- int width = static_cast<int>(mProgress * static_cast<float>(maxWidth));
+ int width = CAST_S32(mProgress * static_cast<float>(maxWidth));
if (width > 0)
{
if (width > maxWidth)
diff --git a/src/gui/widgets/scrollarea.cpp b/src/gui/widgets/scrollarea.cpp
index 4edd5b1a0..5bf67bfda 100644
--- a/src/gui/widgets/scrollarea.cpp
+++ b/src/gui/widgets/scrollarea.cpp
@@ -496,10 +496,10 @@ Image *ScrollArea::getImageByState(Rect &dim, const BUTTON_DIR dir)
case BUTTONS_DIR:
default:
logger->log("ScrollArea::drawButton unknown dir: "
- + toString(static_cast<unsigned>(dir)));
+ + toString(CAST_U32(dir)));
return nullptr;
}
- return buttons[static_cast<size_t>(dir)][state];
+ return buttons[CAST_SIZE(dir)][state];
}
void ScrollArea::drawButton(Graphics *const graphics,
@@ -790,12 +790,12 @@ void ScrollArea::mousePressed(MouseEvent& event)
if (y < getVerticalMarkerDimension().y)
{
setVerticalScrollAmount(mVScroll
- - static_cast<int>(getChildrenArea().height * 0.95));
+ - CAST_S32(getChildrenArea().height * 0.95));
}
else
{
setVerticalScrollAmount(mVScroll
- + static_cast<int>(getChildrenArea().height * 0.95));
+ + CAST_S32(getChildrenArea().height * 0.95));
}
event.consume();
}
@@ -811,12 +811,12 @@ void ScrollArea::mousePressed(MouseEvent& event)
if (x < getHorizontalMarkerDimension().x)
{
setHorizontalScrollAmount(mHScroll
- - static_cast<int>(getChildrenArea().width * 0.95));
+ - CAST_S32(getChildrenArea().width * 0.95));
}
else
{
setHorizontalScrollAmount(mHScroll
- + static_cast<int>(getChildrenArea().width * 0.95));
+ + CAST_S32(getChildrenArea().width * 0.95));
}
event.consume();
}
diff --git a/src/gui/widgets/selldialog.cpp b/src/gui/widgets/selldialog.cpp
index 7716c9a9c..189babc89 100644
--- a/src/gui/widgets/selldialog.cpp
+++ b/src/gui/widgets/selldialog.cpp
@@ -256,7 +256,7 @@ void SellDialog::action(const ActionEvent &event)
if (eventId == "slider")
{
- mAmountItems = static_cast<int>(mSlider->getValue());
+ mAmountItems = CAST_S32(mSlider->getValue());
updateButtonsAndLabels();
}
else if (eventId == "inc" && mSlider && mAmountItems < mMaxItems)
diff --git a/src/gui/widgets/serverslistbox.h b/src/gui/widgets/serverslistbox.h
index 15295f0a8..444e70c9b 100644
--- a/src/gui/widgets/serverslistbox.h
+++ b/src/gui/widgets/serverslistbox.h
@@ -53,11 +53,11 @@ class ServersListBox final : public ListBox
updateAlpha();
- mHighlightColor.a = static_cast<int>(mAlpha * 255.0F);
+ mHighlightColor.a = CAST_S32(mAlpha * 255.0F);
graphics->setColor(mHighlightColor);
const int height = getRowHeight();
- mNotSupportedColor.a = static_cast<int>(mAlpha * 255.0F);
+ mNotSupportedColor.a = CAST_S32(mAlpha * 255.0F);
// Draw filled rectangle around the selected list element
if (mSelected >= 0)
diff --git a/src/gui/widgets/setupitem.cpp b/src/gui/widgets/setupitem.cpp
index 87ea1c908..be9f2000f 100644
--- a/src/gui/widgets/setupitem.cpp
+++ b/src/gui/widgets/setupitem.cpp
@@ -993,14 +993,14 @@ void SetupItemSlider2::action(const ActionEvent &event A_UNUSED)
void SetupItemSlider2::updateLabel()
{
- int val = static_cast<int>(mSlider->getValue()) - mMin;
+ int val = CAST_S32(mSlider->getValue()) - mMin;
if (val < 0)
{
val = 0;
}
else
{
- const int sz = static_cast<signed>(mValues->size());
+ const int sz = CAST_S32(mValues->size());
if (val >= sz)
val = sz - 1;
}
diff --git a/src/gui/widgets/setuptouchitem.cpp b/src/gui/widgets/setuptouchitem.cpp
index 8c14d9f19..fb6cca184 100644
--- a/src/gui/widgets/setuptouchitem.cpp
+++ b/src/gui/widgets/setuptouchitem.cpp
@@ -118,7 +118,7 @@ void SetupActionDropDown::fromWidget()
if (!mDropDown || !mModel)
return;
- mValue = toString(static_cast<int>(mModel->getActionFromSelection(
+ mValue = toString(CAST_S32(mModel->getActionFromSelection(
mDropDown->getSelected())));
}
diff --git a/src/gui/widgets/shoplistbox.cpp b/src/gui/widgets/shoplistbox.cpp
index 1477f94e7..ce5f5f8e9 100644
--- a/src/gui/widgets/shoplistbox.cpp
+++ b/src/gui/widgets/shoplistbox.cpp
@@ -91,7 +91,7 @@ void ShopListBox::draw(Graphics *graphics)
if (settings.guiAlpha != mAlpha)
mAlpha = settings.guiAlpha;
- const unsigned int alpha = static_cast<unsigned int>(mAlpha * 255.0F);
+ const unsigned int alpha = CAST_U32(mAlpha * 255.0F);
Font *const font = getFont();
const int sz = mListModel->getNumberOfElements();
diff --git a/src/gui/widgets/shortcutcontainer.cpp b/src/gui/widgets/shortcutcontainer.cpp
index dbbbaceba..8470d0b57 100644
--- a/src/gui/widgets/shortcutcontainer.cpp
+++ b/src/gui/widgets/shortcutcontainer.cpp
@@ -92,7 +92,7 @@ void ShortcutContainer::widgetResized(const Event &event A_UNUSED)
if (mGridWidth < 1)
mGridWidth = 1;
- mGridHeight = mMaxItems / static_cast<unsigned int>(mGridWidth);
+ mGridHeight = mMaxItems / CAST_U32(mGridWidth);
if (mMaxItems % mGridWidth != 0 || mGridHeight < 1)
++mGridHeight;
@@ -110,7 +110,7 @@ int ShortcutContainer::getIndexFromGrid(const int pointX,
int index = ((pointY / mBoxHeight) * mGridWidth) + pointX / mBoxWidth;
if (!tRect.isPointInRect(pointX, pointY) ||
- index >= static_cast<int>(mMaxItems) || index < 0)
+ index >= CAST_S32(mMaxItems) || index < 0)
{
index = -1;
}
diff --git a/src/gui/widgets/skillinfo.cpp b/src/gui/widgets/skillinfo.cpp
index dd8863206..4174146e2 100644
--- a/src/gui/widgets/skillinfo.cpp
+++ b/src/gui/widgets/skillinfo.cpp
@@ -152,7 +152,7 @@ void SkillInfo::update()
default:
// TRANSLATORS: Skill type
skillEffect = strprintf(typeStr, _("Unknown:"));
- skillEffect.append(" ").append(toString(static_cast<int>(type)));
+ skillEffect.append(" ").append(toString(CAST_S32(type)));
break;
}
diff --git a/src/gui/widgets/skilllistbox.h b/src/gui/widgets/skilllistbox.h
index 74aff1636..e0d1b2d91 100644
--- a/src/gui/widgets/skilllistbox.h
+++ b/src/gui/widgets/skilllistbox.h
@@ -93,7 +93,7 @@ class SkillListBox final : public ListBox
SkillModel *const model = static_cast<SkillModel*>(mListModel);
updateAlpha();
- mHighlightColor.a = static_cast<int>(mAlpha * 255.0F);
+ mHighlightColor.a = CAST_S32(mAlpha * 255.0F);
graphics->setColor(mHighlightColor);
const int width1 = getWidth();
diff --git a/src/gui/widgets/slider.cpp b/src/gui/widgets/slider.cpp
index 0ec6d64dc..d642354bc 100644
--- a/src/gui/widgets/slider.cpp
+++ b/src/gui/widgets/slider.cpp
@@ -468,7 +468,7 @@ void Slider::setValue(const double value)
mValue = mScaleStart;
else
mValue = value;
- mValue = static_cast<int>((mValue - mScaleStart) / mStepLength)
+ mValue = CAST_S32((mValue - mScaleStart) / mStepLength)
* mStepLength + mScaleStart;
}
@@ -492,7 +492,7 @@ int Slider::valueToMarkerPosition(const double value) const
else
v = mDimension.height;
- const int w = static_cast<int>((v - mMarkerLength)
+ const int w = CAST_S32((v - mMarkerLength)
* (value - mScaleStart)
/ (mScaleEnd - mScaleStart));
diff --git a/src/gui/widgets/spellshortcutcontainer.cpp b/src/gui/widgets/spellshortcutcontainer.cpp
index f01a5ba7a..4b67977dd 100644
--- a/src/gui/widgets/spellshortcutcontainer.cpp
+++ b/src/gui/widgets/spellshortcutcontainer.cpp
@@ -290,7 +290,7 @@ void SpellShortcutContainer::mouseReleased(MouseEvent &event)
if (spell && !spell->isEmpty())
{
const int num = itemShortcutWindow->getTabIndex();
- if (num >= 0 && num < static_cast<int>(SHORTCUT_TABS)
+ if (num >= 0 && num < CAST_S32(SHORTCUT_TABS)
&& itemShortcut[num])
{
itemShortcut[num]->setItemSelected(
@@ -302,7 +302,7 @@ void SpellShortcutContainer::mouseReleased(MouseEvent &event)
else
{
const int num = itemShortcutWindow->getTabIndex();
- if (num >= 0 && num < static_cast<int>(SHORTCUT_TABS)
+ if (num >= 0 && num < CAST_S32(SHORTCUT_TABS)
&& itemShortcut[num])
{
itemShortcut[num]->setItemSelected(-1);
diff --git a/src/gui/widgets/tabbedarea.cpp b/src/gui/widgets/tabbedarea.cpp
index e50f6aefa..aea5bf252 100644
--- a/src/gui/widgets/tabbedarea.cpp
+++ b/src/gui/widgets/tabbedarea.cpp
@@ -158,7 +158,7 @@ void TabbedArea::enableScrollButtons(const bool enable)
int TabbedArea::getNumberOfTabs() const
{
- return static_cast<int>(mTabs.size());
+ return CAST_S32(mTabs.size());
}
Tab *TabbedArea::getTab(const std::string &name) const
@@ -318,7 +318,7 @@ void TabbedArea::removeTab(Tab *const tab)
{
const int index = getSelectedTabIndex();
const size_t sz = mTabs.size();
- if (index == static_cast<int>(sz) - 1 && sz == 1)
+ if (index == CAST_S32(sz) - 1 && sz == 1)
tabIndexToBeSelected = -1;
else
tabIndexToBeSelected = index - 1;
@@ -346,7 +346,7 @@ void TabbedArea::removeTab(Tab *const tab)
}
}
- const int tabsSize = static_cast<int>(mTabs.size());
+ const int tabsSize = CAST_S32(mTabs.size());
if (tabIndexToBeSelected >= tabsSize)
tabIndexToBeSelected = tabsSize - 1;
if (tabIndexToBeSelected < -1)
@@ -421,7 +421,7 @@ void TabbedArea::setSelectedTab(Tab *const tab)
int TabbedArea::getSelectedTabIndex() const
{
- for (unsigned int i = 0, sz = static_cast<unsigned int>(mTabs.size());
+ for (unsigned int i = 0, sz = CAST_U32(mTabs.size());
i < sz; i++)
{
if (mTabs[i].first == mSelectedTab)
@@ -527,7 +527,7 @@ void TabbedArea::updateVisibleTabsWidth()
for (size_t i = mTabScrollIndex, sz = mTabs.size(); i < sz; ++i)
{
if (mTabs[i].first)
- mVisibleTabsWidth += static_cast<int>(mTabs[i].first->getWidth());
+ mVisibleTabsWidth += CAST_S32(mTabs[i].first->getWidth());
}
}
@@ -625,7 +625,7 @@ void TabbedArea::action(const ActionEvent& actionEvent)
}
else if (eventId == "shift_right")
{
- if (static_cast<size_t>(mTabScrollIndex) < mTabs.size() - 1)
+ if (CAST_SIZE(mTabScrollIndex) < mTabs.size() - 1)
++mTabScrollIndex;
}
adjustTabPositions();
@@ -675,14 +675,14 @@ void TabbedArea::updateArrowEnableState()
Tab *TabbedArea::getTabByIndex(const int index) const
{
- if (index < 0 || index >= static_cast<int>(mTabs.size()))
+ if (index < 0 || index >= CAST_S32(mTabs.size()))
return nullptr;
return static_cast<Tab*>(mTabs[index].first);
}
Widget *TabbedArea::getWidgetByIndex(const int index) const
{
- if (index < 0 || index >= static_cast<int>(mTabs.size()))
+ if (index < 0 || index >= CAST_S32(mTabs.size()))
return nullptr;
return mTabs[index].second;
}
@@ -691,7 +691,7 @@ void TabbedArea::removeAll(const bool del)
{
if (getSelectedTabIndex() != -1)
{
- setSelectedTabByIndex(static_cast<unsigned int>(0));
+ setSelectedTabByIndex(CAST_U32(0));
}
while (getNumberOfTabs() > 0)
{
@@ -755,7 +755,7 @@ void TabbedArea::keyPressed(KeyEvent& event)
int index = getSelectedTabIndex();
index++;
- if (index >= static_cast<int>(mTabs.size()))
+ if (index >= CAST_S32(mTabs.size()))
return;
else
setSelectedTab(mTabs[index].first);
@@ -778,7 +778,7 @@ void TabbedArea::selectNextTab()
{
int tab = getSelectedTabIndex();
tab++;
- if (tab == static_cast<int>(mTabs.size()))
+ if (tab == CAST_S32(mTabs.size()))
tab = 0;
setSelectedTab(mTabs[tab].first);
}
@@ -788,7 +788,7 @@ void TabbedArea::selectPrevTab()
int tab = getSelectedTabIndex();
if (tab == 0)
- tab = static_cast<int>(mTabs.size());
+ tab = CAST_S32(mTabs.size());
if (tab < 0)
return;
tab--;
diff --git a/src/gui/widgets/tabs/chat/chattab.cpp b/src/gui/widgets/tabs/chat/chattab.cpp
index e3af82d2a..942ade320 100644
--- a/src/gui/widgets/tabs/chat/chattab.cpp
+++ b/src/gui/widgets/tabs/chat/chattab.cpp
@@ -264,9 +264,9 @@ void ChatTab::chatLog(std::string line,
// Format the time string properly
std::stringstream timeStr;
timeStr << "[" << ((((t / 60) / 60) % 24 < 10) ? "0" : "")
- << static_cast<int>(((t / 60) / 60) % 24)
+ << CAST_S32(((t / 60) / 60) % 24)
<< ":" << (((t / 60) % 60 < 10) ? "0" : "")
- << static_cast<int>((t / 60) % 60)
+ << CAST_S32((t / 60) % 60)
<< "] ";
line = std::string(lineColor).append(timeStr.str()).append(
tmp.nick).append(tmp.text);
diff --git a/src/gui/widgets/tabs/setup_colors.cpp b/src/gui/widgets/tabs/setup_colors.cpp
index 22a07f23d..00ab33bcc 100644
--- a/src/gui/widgets/tabs/setup_colors.cpp
+++ b/src/gui/widgets/tabs/setup_colors.cpp
@@ -377,7 +377,7 @@ void Setup_Colors::valueChanged(const SelectionEvent &event A_UNUSED)
setEntry(mGreenSlider, mGreenText, col->g);
setEntry(mBlueSlider, mBlueText, col->b);
- mGradTypeSlider->setValue(static_cast<int>(grad));
+ mGradTypeSlider->setValue(CAST_S32(grad));
updateGradType();
mGradTypeSlider->setEnabled(true);
}
@@ -406,7 +406,7 @@ void Setup_Colors::cancel()
const UserColorIdT type = static_cast<UserColorIdT>(
userPalette->getColorTypeAt(mSelected));
const Color *const col = &userPalette->getColor(type);
- mGradTypeSlider->setValue(static_cast<int>(
+ mGradTypeSlider->setValue(CAST_S32(
userPalette->getGradientType(type)));
const int delay = userPalette->getGradientDelay(type);
setEntry(mGradDelaySlider, mGradDelayText, delay);
@@ -456,23 +456,23 @@ void Setup_Colors::updateColor()
const UserColorIdT type = static_cast<UserColorIdT>(
userPalette->getColorTypeAt(mSelected));
const GradientTypeT grad = static_cast<GradientTypeT>(
- static_cast<int>(mGradTypeSlider->getValue()));
- const int delay = static_cast<int>(mGradDelaySlider->getValue());
+ CAST_S32(mGradTypeSlider->getValue()));
+ const int delay = CAST_S32(mGradDelaySlider->getValue());
userPalette->setGradient(type, grad);
userPalette->setGradientDelay(type, delay);
if (grad == GradientType::STATIC)
{
userPalette->setColor(type,
- static_cast<int>(mRedSlider->getValue()),
- static_cast<int>(mGreenSlider->getValue()),
- static_cast<int>(mBlueSlider->getValue()));
+ CAST_S32(mRedSlider->getValue()),
+ CAST_S32(mGreenSlider->getValue()),
+ CAST_S32(mBlueSlider->getValue()));
}
else if (grad == GradientType::PULSE)
{
userPalette->setTestColor(type, Color(
- static_cast<int>(mRedSlider->getValue()),
- static_cast<int>(mGreenSlider->getValue()),
- static_cast<int>(mBlueSlider->getValue())));
+ CAST_S32(mRedSlider->getValue()),
+ CAST_S32(mGreenSlider->getValue()),
+ CAST_S32(mBlueSlider->getValue())));
}
}
diff --git a/src/gui/widgets/tabs/setup_joystick.cpp b/src/gui/widgets/tabs/setup_joystick.cpp
index 861a2d3ee..64282ac1e 100644
--- a/src/gui/widgets/tabs/setup_joystick.cpp
+++ b/src/gui/widgets/tabs/setup_joystick.cpp
@@ -80,7 +80,7 @@ Setup_Joystick::Setup_Joystick(const Widget2 *const widget) :
else
{
unsigned int sel = config.getIntValue("selectedJoystick");
- if (sel >= static_cast<unsigned int>(mNamesModel->size()))
+ if (sel >= CAST_U32(mNamesModel->size()))
sel = 0;
mNamesDropDown->setSelected(sel);
}
diff --git a/src/gui/widgets/tabs/setup_relations.cpp b/src/gui/widgets/tabs/setup_relations.cpp
index 87a491116..844532278 100644
--- a/src/gui/widgets/tabs/setup_relations.cpp
+++ b/src/gui/widgets/tabs/setup_relations.cpp
@@ -160,7 +160,7 @@ void Setup_Relations::reset()
if ((*player_relations.getPlayerIgnoreStrategies())[i] ==
player_relations.getPlayerIgnoreStrategy())
{
- selection = static_cast<int>(i);
+ selection = CAST_S32(i);
break;
}
}
diff --git a/src/gui/widgets/tabs/setup_theme.cpp b/src/gui/widgets/tabs/setup_theme.cpp
index 55f68548d..dced19225 100644
--- a/src/gui/widgets/tabs/setup_theme.cpp
+++ b/src/gui/widgets/tabs/setup_theme.cpp
@@ -393,9 +393,9 @@ void Setup_Theme::apply()
|| config.getValue("chinaFont", "fonts/wqy-microhei.ttf")
!= mChinaFont
|| config.getIntValue("fontSize")
- != static_cast<int>(mFontSizeDropDown->getSelected()) + 9
+ != CAST_S32(mFontSizeDropDown->getSelected()) + 9
|| config.getIntValue("npcfontSize")
- != static_cast<int>(mNpcFontSizeDropDown->getSelected()) + 9)
+ != CAST_S32(mNpcFontSizeDropDown->getSelected()) + 9)
{
config.setValue("font", "fonts/" + getFileName(mFont));
config.setValue("boldFont", "fonts/" + getFileName(mBoldFont));
diff --git a/src/gui/widgets/tabs/setup_video.cpp b/src/gui/widgets/tabs/setup_video.cpp
index fad7f3ba2..591093bc8 100644
--- a/src/gui/widgets/tabs/setup_video.cpp
+++ b/src/gui/widgets/tabs/setup_video.cpp
@@ -263,13 +263,13 @@ void Setup_Video::apply()
const int sel = mOpenGLDropDown->getSelected();
RenderType mode = RENDER_SOFTWARE;
- if (sel >= 0 && static_cast<unsigned int>(sel) < sizeof(indexToRender))
+ if (sel >= 0 && CAST_U32(sel) < sizeof(indexToRender))
mode = indexToRender[mOpenGLDropDown->getSelected()];
// OpenGL change
if (mode != mOpenGLEnabled)
{
- config.setValue("opengl", static_cast<int>(mode));
+ config.setValue("opengl", CAST_S32(mode));
// OpenGL can currently only be changed by restarting, notify user.
CREATEWIDGET(OkDialog,
@@ -287,9 +287,9 @@ void Setup_Video::apply()
}
mFps = mFpsCheckBox->isSelected() ?
- static_cast<int>(mFpsSlider->getValue()) : 0;
+ CAST_S32(mFpsSlider->getValue()) : 0;
- mAltFps = static_cast<int>(mAltFpsSlider->getValue());
+ mAltFps = CAST_S32(mAltFpsSlider->getValue());
mFpsSlider->setEnabled(mFps > 0);
@@ -336,7 +336,7 @@ void Setup_Video::cancel()
config.setValue("screenheight", mainGraphics->mActualHeight);
config.setValue("customcursor", mCustomCursorEnabled);
- config.setValue("opengl", static_cast<int>(mOpenGLEnabled));
+ config.setValue("opengl", CAST_S32(mOpenGLEnabled));
config.setValue("enableresize", mEnableResize);
config.setValue("noframe", mNoFrame);
}
@@ -443,7 +443,7 @@ void Setup_Video::action(const ActionEvent &event)
}
else if (id == "fpslimitcheckbox" || id == "fpslimitslider")
{
- int tempFps = static_cast<int>(mFpsSlider->getValue());
+ int tempFps = CAST_S32(mFpsSlider->getValue());
if (id == "fpslimitcheckbox" && !mFpsSlider->isEnabled())
tempFps = 60;
else
@@ -458,8 +458,8 @@ void Setup_Video::action(const ActionEvent &event)
}
else if (id == "altfpslimitslider")
{
- int tempFps = static_cast<int>(mAltFpsSlider->getValue());
- tempFps = tempFps > 0 ? tempFps : static_cast<int>(
+ int tempFps = CAST_S32(mAltFpsSlider->getValue());
+ tempFps = tempFps > 0 ? tempFps : CAST_S32(
mAltFpsSlider->getScaleStart());
mAltFps = tempFps;
// TRANSLATORS: video settings label
@@ -486,7 +486,7 @@ void Setup_Video::action(const ActionEvent &event)
{
Configuration &conf = test->getConfig();
const int val = conf.getValueInt("opengl", -1);
- if (val >= 0 && static_cast<unsigned int>(val)
+ if (val >= 0 && CAST_U32(val)
< sizeof(renderToIndex) / sizeof(int))
{
mOpenGLDropDown->setSelected(renderToIndex[val]);
diff --git a/src/gui/widgets/tabs/socialfriendstab.h b/src/gui/widgets/tabs/socialfriendstab.h
index d4543a46b..b53138e10 100644
--- a/src/gui/widgets/tabs/socialfriendstab.h
+++ b/src/gui/widgets/tabs/socialfriendstab.h
@@ -112,8 +112,8 @@ class SocialFriendsTab final : public SocialTab
// TRANSLATORS: social window label
mCounterString = strprintf(_("Friends: %u/%u"),
- static_cast<uint32_t>(online),
- static_cast<uint32_t>(total));
+ CAST_U32(online),
+ CAST_U32(total));
updateCounter();
}
diff --git a/src/gui/widgets/tabs/socialguildtab.h b/src/gui/widgets/tabs/socialguildtab.h
index a76b3d58b..942ce9d59 100644
--- a/src/gui/widgets/tabs/socialguildtab.h
+++ b/src/gui/widgets/tabs/socialguildtab.h
@@ -140,8 +140,8 @@ class SocialGuildTab final : public SocialTab,
{
// TRANSLATORS: social window label
mCounterString = strprintf(_("Members: %u/%u"),
- static_cast<uint32_t>(online0),
- static_cast<uint32_t>(total0));
+ CAST_U32(online0),
+ CAST_U32(total0));
}
else
{
@@ -164,8 +164,8 @@ class SocialGuildTab final : public SocialTab,
// TRANSLATORS: social window label
mCounterString = strprintf(_("Players: %u/%u"),
- static_cast<uint32_t>(online),
- static_cast<uint32_t>(total));
+ CAST_U32(online),
+ CAST_U32(total));
}
updateCounter();
}
diff --git a/src/gui/widgets/tabs/socialguildtab2.h b/src/gui/widgets/tabs/socialguildtab2.h
index 67aa2ee08..c216c6d36 100644
--- a/src/gui/widgets/tabs/socialguildtab2.h
+++ b/src/gui/widgets/tabs/socialguildtab2.h
@@ -95,8 +95,8 @@ class SocialGuildTab2 final : public SocialTab,
// TRANSLATORS: social window label
mCounterString = strprintf(_("Players: %u/%u"),
- static_cast<uint32_t>(online),
- static_cast<uint32_t>(total));
+ CAST_U32(online),
+ CAST_U32(total));
updateCounter();
}
};
diff --git a/src/gui/widgets/tabs/socialnavigationtab.h b/src/gui/widgets/tabs/socialnavigationtab.h
index 6d9a5e9f0..e673c689b 100644
--- a/src/gui/widgets/tabs/socialnavigationtab.h
+++ b/src/gui/widgets/tabs/socialnavigationtab.h
@@ -159,8 +159,8 @@ class SocialNavigationTab final : public SocialTab
// TRANSLATORS: social window label
mCounterString = strprintf(_("Portals: %u/%u"),
- static_cast<uint32_t>(online),
- static_cast<uint32_t>(total));
+ CAST_U32(online),
+ CAST_U32(total));
updateCounter();
}
@@ -170,7 +170,7 @@ class SocialNavigationTab final : public SocialTab
return;
std::vector<Avatar*> *const avatars = mBeings->getMembers();
- if (avatars->size() <= static_cast<size_t>(num))
+ if (avatars->size() <= CAST_SIZE(num))
return;
const Avatar *const ava = avatars->at(num);
diff --git a/src/gui/widgets/tabs/socialpartytab.h b/src/gui/widgets/tabs/socialpartytab.h
index 6202e537a..153c1b3ec 100644
--- a/src/gui/widgets/tabs/socialpartytab.h
+++ b/src/gui/widgets/tabs/socialpartytab.h
@@ -157,8 +157,8 @@ class SocialPartyTab final : public SocialTab,
// TRANSLATORS: social window label
mCounterString = strprintf(_("Players: %u/%u"),
- static_cast<uint32_t>(online),
- static_cast<uint32_t>(total));
+ CAST_U32(online),
+ CAST_U32(total));
updateCounter();
}
diff --git a/src/gui/widgets/tabs/socialplayerstab.h b/src/gui/widgets/tabs/socialplayerstab.h
index b3a234301..50d86e33c 100644
--- a/src/gui/widgets/tabs/socialplayerstab.h
+++ b/src/gui/widgets/tabs/socialplayerstab.h
@@ -186,7 +186,7 @@ class SocialPlayersTab final : public SocialTab
}
// TRANSLATORS: social window label
mCounterString = strprintf(_("Visible players: %d"),
- static_cast<int>(avatars->size()));
+ CAST_S32(avatars->size()));
updateCounter();
}
diff --git a/src/gui/widgets/tabstrip.cpp b/src/gui/widgets/tabstrip.cpp
index 035acbb70..26a4feac0 100644
--- a/src/gui/widgets/tabstrip.cpp
+++ b/src/gui/widgets/tabstrip.cpp
@@ -52,7 +52,7 @@ Widget *TabStrip::createWidget(const std::string &text,
widget->adjustSize();
if ((!mCount && mPressFirst) || pressed)
widget->setPressed(true);
- widget->setTag(static_cast<int>(mWidgets.size()));
+ widget->setTag(CAST_S32(mWidgets.size()));
return widget;
}
diff --git a/src/gui/widgets/textbox.cpp b/src/gui/widgets/textbox.cpp
index b49562673..8478e767e 100644
--- a/src/gui/widgets/textbox.cpp
+++ b/src/gui/widgets/textbox.cpp
@@ -241,9 +241,9 @@ void TextBox::setText(const std::string& text)
pos = text.find("\n", lastPos);
if (pos != std::string::npos)
- length = static_cast<int>(pos - lastPos);
+ length = CAST_S32(pos - lastPos);
else
- length = static_cast<int>(text.size() - lastPos);
+ length = CAST_S32(text.size() - lastPos);
std::string sub = text.substr(lastPos, length);
mTextRows.push_back(sub);
lastPos = pos + 1;
@@ -273,7 +273,7 @@ void TextBox::keyPressed(KeyEvent& event)
}
else
{
- mCaretColumn = static_cast<int>(
+ mCaretColumn = CAST_S32(
mTextRows[mCaretRow].size());
}
}
@@ -283,18 +283,18 @@ void TextBox::keyPressed(KeyEvent& event)
case InputAction::GUI_RIGHT:
{
++mCaretColumn;
- if (mCaretColumn > static_cast<int>(mTextRows[mCaretRow].size()))
+ if (mCaretColumn > CAST_S32(mTextRows[mCaretRow].size()))
{
++ mCaretRow;
- const int sz = static_cast<int>(mTextRows.size());
+ const int sz = CAST_S32(mTextRows.size());
if (mCaretRow >= sz)
{
mCaretRow = sz - 1;
if (mCaretRow < 0)
mCaretRow = 0;
- mCaretColumn = static_cast<int>(
+ mCaretColumn = CAST_S32(
mTextRows[mCaretRow].size());
}
else
@@ -322,7 +322,7 @@ void TextBox::keyPressed(KeyEvent& event)
}
case InputAction::GUI_END:
{
- mCaretColumn = static_cast<int>(mTextRows[mCaretRow].size());
+ mCaretColumn = CAST_S32(mTextRows[mCaretRow].size());
break;
}
@@ -349,7 +349,7 @@ void TextBox::keyPressed(KeyEvent& event)
}
else if (mCaretColumn == 0 && mCaretRow != 0 && mEditable)
{
- mCaretColumn = static_cast<int>(
+ mCaretColumn = CAST_S32(
mTextRows[mCaretRow - 1].size());
mTextRows[mCaretRow - 1] += mTextRows[mCaretRow];
mTextRows.erase(mTextRows.begin() + mCaretRow);
@@ -360,14 +360,14 @@ void TextBox::keyPressed(KeyEvent& event)
case InputAction::GUI_DELETE:
{
- if (mCaretColumn < static_cast<int>(
+ if (mCaretColumn < CAST_S32(
mTextRows[mCaretRow].size()) && mEditable)
{
mTextRows[mCaretRow].erase(mCaretColumn, 1);
}
- else if (mCaretColumn == static_cast<int>(
+ else if (mCaretColumn == CAST_S32(
mTextRows[mCaretRow].size()) &&
- mCaretRow < (static_cast<int>(mTextRows.size()) - 1) &&
+ mCaretRow < (CAST_S32(mTextRows.size()) - 1) &&
mEditable)
{
mTextRows[mCaretRow] += mTextRows[mCaretRow + 1];
@@ -402,7 +402,7 @@ void TextBox::keyPressed(KeyEvent& event)
/ getFont()->getHeight();
mCaretRow += rowsPerPage;
- const int sz = static_cast<int>(mTextRows.size());
+ const int sz = CAST_S32(mTextRows.size());
if (mCaretRow >= sz)
mCaretRow = sz - 1;
}
@@ -424,7 +424,7 @@ void TextBox::keyPressed(KeyEvent& event)
if (key.isCharacter() && mEditable)
{
mTextRows[mCaretRow].insert(mCaretColumn,
- std::string(1, static_cast<signed char>(key.getValue())));
+ std::string(1, CAST_S8(key.getValue())));
++ mCaretColumn;
}
break;
@@ -463,7 +463,7 @@ void TextBox::draw(Graphics* graphics)
mForegroundColor,
mForegroundColor2,
mTextRows[i], 1,
- static_cast<int>(i * static_cast<size_t>(fontHeight)));
+ CAST_S32(i * CAST_SIZE(fontHeight)));
}
BLOCK_END("TextBox::draw")
}
@@ -494,7 +494,7 @@ std::string TextBox::getText() const
int i;
std::string text;
- const int sz = static_cast<int>(mTextRows.size());
+ const int sz = CAST_S32(mTextRows.size());
for (i = 0; i < sz - 1; ++ i)
text.append(mTextRows[i]).append("\n");
text.append(mTextRows[i]);
@@ -514,7 +514,7 @@ void TextBox::setTextRow(const int row, const std::string& text)
void TextBox::setCaretPosition(unsigned int position)
{
- for (int row = 0, sz = static_cast<int>(mTextRows.size());
+ for (int row = 0, sz = CAST_S32(mTextRows.size());
row < sz; row ++)
{
if (position <= mTextRows[row].size())
@@ -530,15 +530,15 @@ void TextBox::setCaretPosition(unsigned int position)
}
// position beyond end of text
- mCaretRow = static_cast<int>(mTextRows.size() - 1);
- mCaretColumn = static_cast<int>(mTextRows[mCaretRow].size());
+ mCaretRow = CAST_S32(mTextRows.size() - 1);
+ mCaretColumn = CAST_S32(mTextRows[mCaretRow].size());
}
void TextBox::setCaretRow(const int row)
{
mCaretRow = row;
- const int sz = static_cast<int>(mTextRows.size());
+ const int sz = CAST_S32(mTextRows.size());
if (mCaretRow >= sz)
mCaretRow = sz - 1;
@@ -553,7 +553,7 @@ unsigned int TextBox::getCaretPosition() const
int pos = 0, row;
for (row = 0; row < mCaretRow; row++)
- pos += static_cast<int>(mTextRows[row].size());
+ pos += CAST_S32(mTextRows[row].size());
return pos + mCaretColumn;
}
@@ -562,7 +562,7 @@ void TextBox::setCaretColumn(const int column)
{
mCaretColumn = column;
- const int sz = static_cast<int>(mTextRows[mCaretRow].size());
+ const int sz = CAST_S32(mTextRows[mCaretRow].size());
if (mCaretColumn > sz)
mCaretColumn = sz;
@@ -605,7 +605,7 @@ void TextBox::mousePressed(MouseEvent& event)
event.consume();
mCaretRow = event.getY() / height;
- const int sz = static_cast<int>(mTextRows.size());
+ const int sz = CAST_S32(mTextRows.size());
if (mCaretRow >= sz)
mCaretRow = sz - 1;
@@ -637,5 +637,5 @@ void TextBox::adjustSize()
}
setWidth(width + 1);
- setHeight(font->getHeight() * static_cast<int>(mTextRows.size()));
+ setHeight(font->getHeight() * CAST_S32(mTextRows.size()));
}
diff --git a/src/gui/widgets/textbox.h b/src/gui/widgets/textbox.h
index 5bfec42a1..bdeca3c5d 100644
--- a/src/gui/widgets/textbox.h
+++ b/src/gui/widgets/textbox.h
@@ -157,7 +157,7 @@ class TextBox final : public Widget,
* @return The number of rows in the text.
*/
unsigned int getNumberOfRows() const
- { return static_cast<int>(mTextRows.size()); }
+ { return CAST_S32(mTextRows.size()); }
/**
* Gets the caret position in the text.
diff --git a/src/gui/widgets/textfield.cpp b/src/gui/widgets/textfield.cpp
index b9f90c949..291a5fa22 100644
--- a/src/gui/widgets/textfield.cpp
+++ b/src/gui/widgets/textfield.cpp
@@ -298,7 +298,7 @@ void TextField::keyPressed(KeyEvent &event)
std::string str = event.getText();
mText.insert(mCaretPosition, str);
mTextChanged = true;
- mCaretPosition += static_cast<unsigned int>(str.size());
+ mCaretPosition += CAST_U32(str.size());
event.consume();
fixScroll();
if (mSendAlwaysEvents)
@@ -314,7 +314,7 @@ void TextField::keyPressed(KeyEvent &event)
if ((val >= '0' && val <= '9') || (val == '-' && !mCaretPosition))
{
char buf[2];
- buf[0] = static_cast<char>(val);
+ buf[0] = CAST_8(val);
buf[1] = 0;
mText.insert(mCaretPosition, std::string(buf));
mTextChanged = true;
@@ -327,7 +327,7 @@ void TextField::keyPressed(KeyEvent &event)
}
}
else if (!mMaximum ||
- static_cast<int>(mText.size()) < mMaximum)
+ CAST_S32(mText.size()) < mMaximum)
{
int len;
if (val < 128)
@@ -342,13 +342,13 @@ void TextField::keyPressed(KeyEvent &event)
char buf[4];
for (int i = 0; i < len; ++ i)
{
- buf[i] = static_cast<char>(val >> (6 * (len - i - 1)));
+ buf[i] = CAST_8(val >> (6 * (len - i - 1)));
if (i > 0)
- buf[i] = static_cast<char>((buf[i] & 63) | 128);
+ buf[i] = CAST_8((buf[i] & 63) | 128);
}
if (len > 1)
- buf[0] |= static_cast<char>(255U << (8 - len));
+ buf[0] |= CAST_8(255U << (8 - len));
mText.insert(mCaretPosition, std::string(buf, buf + len));
mCaretPosition += len;
@@ -413,7 +413,7 @@ bool TextField::handleNormalKeys(const InputActionT action, bool &consumed)
case InputAction::GUI_RIGHT:
{
consumed = true;
- const unsigned sz = static_cast<unsigned>(mText.size());
+ const unsigned sz = CAST_U32(mText.size());
while (mCaretPosition < sz)
{
++mCaretPosition;
@@ -429,7 +429,7 @@ bool TextField::handleNormalKeys(const InputActionT action, bool &consumed)
case InputAction::GUI_DELETE:
{
consumed = true;
- unsigned sz = static_cast<unsigned>(mText.size());
+ unsigned sz = CAST_U32(mText.size());
while (mCaretPosition < sz)
{
--sz;
@@ -462,7 +462,7 @@ bool TextField::handleNormalKeys(const InputActionT action, bool &consumed)
break;
case InputAction::GUI_END:
- mCaretPosition = static_cast<unsigned>(mText.size());
+ mCaretPosition = CAST_U32(mText.size());
consumed = true;
break;
@@ -517,7 +517,7 @@ void TextField::handleCtrlKeys(const InputActionT action, bool &consumed)
}
case InputAction::GUI_E:
{
- mCaretPosition = static_cast<int>(mText.size());
+ mCaretPosition = CAST_S32(mText.size());
consumed = true;
break;
}
@@ -584,7 +584,7 @@ void TextField::moveCaretBack()
void TextField::moveCaretForward()
{
- const unsigned sz = static_cast<unsigned>(mText.size());
+ const unsigned sz = CAST_U32(mText.size());
while (mCaretPosition < sz)
{
++mCaretPosition;
@@ -595,7 +595,7 @@ void TextField::moveCaretForward()
void TextField::caretDelete()
{
- unsigned sz = static_cast<unsigned>(mText.size());
+ unsigned sz = CAST_U32(mText.size());
while (mCaretPosition < sz)
{
--sz;
@@ -609,12 +609,12 @@ void TextField::caretDelete()
void TextField::handlePaste()
{
std::string text = getText();
- size_t caretPos = static_cast<size_t>(getCaretPosition());
+ size_t caretPos = CAST_SIZE(getCaretPosition());
if (retrieveBuffer(text, caretPos))
{
setText(text);
- setCaretPosition(static_cast<unsigned int>(caretPos));
+ setCaretPosition(CAST_U32(caretPos));
}
}
@@ -649,7 +649,7 @@ void TextField::moveCaretWordBack()
void TextField::moveCaretWordForward()
{
- const unsigned sz = static_cast<unsigned>(mText.size());
+ const unsigned sz = CAST_U32(mText.size());
const unsigned int oldCaret = mCaretPosition;
while (mCaretPosition < sz)
{
@@ -731,9 +731,9 @@ void TextField::fixScroll()
void TextField::setCaretPosition(unsigned int position)
{
- const unsigned int sz = static_cast<unsigned int>(mText.size());
+ const unsigned int sz = CAST_U32(mText.size());
if (position > sz)
- mCaretPosition = static_cast<int>(sz);
+ mCaretPosition = CAST_S32(sz);
else
mCaretPosition = position;
@@ -781,7 +781,7 @@ void TextField::focusLost(const Event &event A_UNUSED)
void TextField::setText(const std::string& text)
{
- const unsigned int sz = static_cast<unsigned int>(text.size());
+ const unsigned int sz = CAST_U32(text.size());
if (sz < mCaretPosition)
mCaretPosition = sz;
mText = text;
diff --git a/src/gui/widgets/textpreview.cpp b/src/gui/widgets/textpreview.cpp
index a0b504065..6e61a16a5 100644
--- a/src/gui/widgets/textpreview.cpp
+++ b/src/gui/widgets/textpreview.cpp
@@ -88,15 +88,15 @@ void TextPreview::draw(Graphics* graphics)
if (settings.guiAlpha != mAlpha)
mAlpha = settings.guiAlpha;
- const int intAlpha = static_cast<int>(mAlpha * 255.0F);
+ const int intAlpha = CAST_S32(mAlpha * 255.0F);
const int alpha = mTextAlpha ? intAlpha : 255;
if (mOpaque)
{
- graphics->setColor(Color(static_cast<int>(mBGColor->r),
- static_cast<int>(mBGColor->g),
- static_cast<int>(mBGColor->b),
- static_cast<int>(mAlpha * 255.0F)));
+ graphics->setColor(Color(CAST_S32(mBGColor->r),
+ CAST_S32(mBGColor->g),
+ CAST_S32(mBGColor->b),
+ CAST_S32(mAlpha * 255.0F)));
graphics->fillRectangle(Rect(0, 0,
mDimension.width, mDimension.height));
}
@@ -107,9 +107,9 @@ void TextPreview::draw(Graphics* graphics)
+ 2 * ((mOutline || mShadow) ? 1 :0);
const int y = mFont->getHeight() + 1
+ 2 * ((mOutline || mShadow) ? 1 : 0);
- graphics->setColor(Color(static_cast<int>(mTextBGColor->r),
- static_cast<int>(mTextBGColor->g),
- static_cast<int>(mTextBGColor->b),
+ graphics->setColor(Color(CAST_S32(mTextBGColor->r),
+ CAST_S32(mTextBGColor->g),
+ CAST_S32(mTextBGColor->b),
intAlpha));
graphics->fillRectangle(Rect(mPadding, mPadding, x, y));
}
diff --git a/src/gui/widgets/widget2.h b/src/gui/widgets/widget2.h
index 8e56a2477..bbf9beff6 100644
--- a/src/gui/widgets/widget2.h
+++ b/src/gui/widgets/widget2.h
@@ -62,7 +62,7 @@ class Widget2 notfinal
void setPalette(int palette)
{
- mPaletteOffset = palette * static_cast<int>(
+ mPaletteOffset = palette * CAST_S32(
ThemeColorId::THEME_COLORS_END);
checkPalette();
setWidget2(this);
@@ -71,7 +71,7 @@ class Widget2 notfinal
void checkPalette()
{
if (mPaletteOffset < 0 ||
- mPaletteOffset >= THEME_PALETTES * static_cast<int>(
+ mPaletteOffset >= THEME_PALETTES * CAST_S32(
ThemeColorId::THEME_COLORS_END))
{
mPaletteOffset = 0;
diff --git a/src/gui/widgets/window.cpp b/src/gui/widgets/window.cpp
index 02a13a249..450c2e025 100644
--- a/src/gui/widgets/window.cpp
+++ b/src/gui/widgets/window.cpp
@@ -202,7 +202,7 @@ Window::Window(const std::string &caption,
{
mCaptionAlign = Graphics::LEFT;
}
- setTitleBarHeight(static_cast<unsigned int>(
+ setTitleBarHeight(CAST_U32(
getOption("titlebarHeight")));
if (!mTitleBarHeight)
mTitleBarHeight = mCaptionFont->getHeight() + mPadding;
@@ -821,7 +821,7 @@ void Window::mousePressed(MouseEvent &event)
mDragOffsetX = event.getX();
mDragOffsetY = event.getY();
- mMoved = event.getY() <= static_cast<int>(mTitleBarHeight);
+ mMoved = event.getY() <= CAST_S32(mTitleBarHeight);
}
const MouseButtonT button = event.getButton();
@@ -1290,8 +1290,8 @@ int Window::getResizeHandles(const MouseEvent &event)
{
if (mGrip &&
(y > mTitleBarHeight ||
- (static_cast<int>(y) < mPadding &&
- static_cast<int>(mTitleBarHeight) > mPadding)))
+ (CAST_S32(y) < mPadding &&
+ CAST_S32(mTitleBarHeight) > mPadding)))
{
if (!getWindowArea().isPointInRect(x, y)
&& event.getSource() == this)
@@ -1301,8 +1301,8 @@ int Window::getResizeHandles(const MouseEvent &event)
resizeHandles |= (y > mDimension.height - resizeBorderWidth)
? BOTTOM : (y < resizeBorderWidth) ? TOP : 0;
}
- if (x >= static_cast<unsigned>(mGripRect.x)
- && y >= static_cast<unsigned>(mGripRect.y))
+ if (x >= CAST_U32(mGripRect.x)
+ && y >= CAST_U32(mGripRect.y))
{
mDragOffsetX = x;
mDragOffsetY = y;
@@ -1319,7 +1319,7 @@ bool Window::isResizeAllowed(const MouseEvent &event) const
const int y = event.getY();
if (mGrip &&
- (y > static_cast<int>(mTitleBarHeight) ||
+ (y > CAST_S32(mTitleBarHeight) ||
y < mPadding))
{
const int x = event.getX();
diff --git a/src/gui/windowmenu.cpp b/src/gui/windowmenu.cpp
index 9d9f9a213..6633fcb90 100644
--- a/src/gui/windowmenu.cpp
+++ b/src/gui/windowmenu.cpp
@@ -256,7 +256,7 @@ void WindowMenu::addButton(const char *const text,
Button *const btn = new Button(this, gettext(text), text, this);
btn->setPosition(x, mPadding);
btn->setDescription(description);
- btn->setTag(static_cast<int>(key));
+ btn->setTag(CAST_S32(key));
add(btn);
btn->setFocusable(false);
x += btn->getWidth() + mSpacing;
diff --git a/src/gui/windows/buydialog.cpp b/src/gui/windows/buydialog.cpp
index 644e8c5ce..82f49421b 100644
--- a/src/gui/windows/buydialog.cpp
+++ b/src/gui/windows/buydialog.cpp
@@ -482,7 +482,7 @@ void BuyDialog::action(const ActionEvent &event)
if (eventId == "slider")
{
- mAmountItems = static_cast<int>(mSlider->getValue());
+ mAmountItems = CAST_S32(mSlider->getValue());
mAmountField->setValue(mAmountItems);
updateButtonsAndLabels();
}
diff --git a/src/gui/windows/charcreatedialog.cpp b/src/gui/windows/charcreatedialog.cpp
index 6e8120373..0f693aa45 100644
--- a/src/gui/windows/charcreatedialog.cpp
+++ b/src/gui/windows/charcreatedialog.cpp
@@ -163,7 +163,7 @@ CharCreateDialog::CharCreateDialog(CharSelectDialog *const parent,
if (maxHairStyle)
{
- mHairStyle = (static_cast<unsigned int>(rand())
+ mHairStyle = (CAST_U32(rand())
% maxHairStyle) + minHairStyle;
}
else
@@ -172,7 +172,7 @@ CharCreateDialog::CharCreateDialog(CharSelectDialog *const parent,
}
if (maxHairColor)
{
- mHairColor = (static_cast<unsigned int>(rand())
+ mHairColor = (CAST_U32(rand())
% maxHairColor) + minHairColor;
}
else
@@ -440,7 +440,7 @@ void CharCreateDialog::action(const ActionEvent &event)
std::vector<int> atts;
for (size_t i = 0, sz = mAttributeSlider.size(); i < sz; i++)
{
- atts.push_back(static_cast<int>(
+ atts.push_back(CAST_S32(
mAttributeSlider[i]->getValue()));
}
@@ -451,8 +451,8 @@ void CharCreateDialog::action(const ActionEvent &event)
mGender,
mHairStyle,
mHairColor,
- static_cast<unsigned char>(mRace),
- static_cast<unsigned char>(mLook),
+ CAST_U8(mRace),
+ CAST_U8(mLook),
atts);
}
else
@@ -568,7 +568,7 @@ void CharCreateDialog::updateSliders()
{
// Update captions
mAttributeValue[i]->setCaption(
- toString(static_cast<int>(mAttributeSlider[i]->getValue())));
+ toString(CAST_S32(mAttributeSlider[i]->getValue())));
mAttributeValue[i]->adjustSize();
}
@@ -610,7 +610,7 @@ int CharCreateDialog::getDistributedPoints() const
int points = 0;
for (size_t i = 0, sz = mAttributeSlider.size(); i < sz; i++)
- points += static_cast<int>(mAttributeSlider[i]->getValue());
+ points += CAST_S32(mAttributeSlider[i]->getValue());
return points;
}
@@ -642,7 +642,7 @@ void CharCreateDialog::setAttributes(const StringVect &labels,
if (serverFeatures->haveRaceSelection() && mMinRace < mMaxRace)
y += 29;
- for (unsigned i = 0, sz = static_cast<unsigned>(labels.size());
+ for (unsigned i = 0, sz = CAST_U32(labels.size());
i < sz; i++)
{
mAttributeLabel[i] = new Label(this, labels[i]);
@@ -704,8 +704,8 @@ void CharCreateDialog::updateHair()
mHairStyle = Being::getNumOfHairstyles() - 1;
else
mHairStyle %= Being::getNumOfHairstyles();
- if (mHairStyle < static_cast<signed>(minHairStyle)
- || mHairStyle > static_cast<signed>(maxHairStyle))
+ if (mHairStyle < CAST_S32(minHairStyle)
+ || mHairStyle > CAST_S32(maxHairStyle))
{
mHairStyle = minHairStyle;
}
@@ -722,8 +722,8 @@ void CharCreateDialog::updateHair()
mHairColor = 0;
if (mHairColor < 0)
mHairColor += ColorDB::getHairSize();
- if (mHairColor < static_cast<signed>(minHairColor)
- || mHairColor > static_cast<signed>(maxHairColor))
+ if (mHairColor < CAST_S32(minHairColor)
+ || mHairColor > CAST_S32(maxHairColor))
{
mHairColor = minHairColor;
}
@@ -767,7 +767,7 @@ void CharCreateDialog::updateLook()
mLook = 0;
}
mPlayer->setSubtype(fromInt(mRace, BeingTypeId),
- static_cast<uint8_t>(mLook));
+ CAST_U8(mLook));
if (mRaceNameLabel)
{
mRaceNameLabel->setCaption(item.getName());
diff --git a/src/gui/windows/charselectdialog.cpp b/src/gui/windows/charselectdialog.cpp
index ac5f3b291..57cc7ceb5 100644
--- a/src/gui/windows/charselectdialog.cpp
+++ b/src/gui/windows/charselectdialog.cpp
@@ -113,7 +113,7 @@ CharSelectDialog::CharSelectDialog(LoginData &data) :
placer(n, 0, mInfoButton);
n ++;
- for (int i = 0; i < static_cast<int>(mLoginData->characterSlots); i++)
+ for (int i = 0; i < CAST_S32(mLoginData->characterSlots); i++)
{
CharacterDisplay *const character = new CharacterDisplay(this, this);
character->setVisible(Visible_false);
@@ -183,7 +183,7 @@ void CharSelectDialog::action(const ActionEvent &event)
// Check if a button of a character was pressed
const Widget *const sourceParent = event.getSource()->getParent();
int selected = -1;
- for (unsigned int i = 0, sz = static_cast<unsigned int>(
+ for (unsigned int i = 0, sz = CAST_U32(
mCharacterEntries.size()); i < sz; ++i)
{
if (mCharacterEntries[i] == sourceParent)
@@ -241,17 +241,17 @@ void CharSelectDialog::action(const ActionEvent &event)
// TRANSLATORS: char select dialog. player info message.
_("Hp: %u/%u\nMp: %u/%u\nLevel: %u\n"
"Experience: %u\nMoney: %s"),
- static_cast<uint32_t>(
+ CAST_U32(
character->data.mAttributes[Attributes::HP]),
- static_cast<uint32_t>(
+ CAST_U32(
character->data.mAttributes[Attributes::MAX_HP]),
- static_cast<uint32_t>(
+ CAST_U32(
character->data.mAttributes[Attributes::MP]),
- static_cast<uint32_t>(
+ CAST_U32(
character->data.mAttributes[Attributes::MAX_MP]),
- static_cast<uint32_t>(
+ CAST_U32(
character->data.mAttributes[Attributes::LEVEL]),
- static_cast<uint32_t>(
+ CAST_U32(
character->data.mAttributes[Attributes::EXP]),
Units::formatCurrency(
character->data.mAttributes[Attributes::MONEY]).c_str());
@@ -506,7 +506,7 @@ void CharSelectDialog::setCharacter(Net::Character *const character)
if (!character)
return;
const int characterSlot = character->slot;
- if (characterSlot >= static_cast<int>(mCharacterEntries.size()))
+ if (characterSlot >= CAST_S32(mCharacterEntries.size()))
{
logger->log("Warning: slot out of range: %d", character->slot);
return;
@@ -562,10 +562,10 @@ bool CharSelectDialog::selectByName(const std::string &name,
{
if (character->dummy && character->dummy->getName() == name)
{
- mCharacterView->show(static_cast<int>(i));
+ mCharacterView->show(CAST_S32(i));
updateState();
if (selAction == Choose)
- attemptCharacterSelect(static_cast<int>(i));
+ attemptCharacterSelect(CAST_S32(i));
return true;
}
}
@@ -616,7 +616,7 @@ void CharSelectDialog::updateState()
void CharSelectDialog::setName(const BeingId id, const std::string &newName)
{
- for (unsigned int i = 0, sz = static_cast<unsigned int>(
+ for (unsigned int i = 0, sz = CAST_U32(
mCharacterEntries.size()); i < sz; ++i)
{
if (!mCharacterEntries[i])
diff --git a/src/gui/windows/chatwindow.cpp b/src/gui/windows/chatwindow.cpp
index 8f74a6877..e15f68f35 100644
--- a/src/gui/windows/chatwindow.cpp
+++ b/src/gui/windows/chatwindow.cpp
@@ -403,7 +403,7 @@ void ChatWindow::closeTab() const
void ChatWindow::defaultTab()
{
if (mChatTabs)
- mChatTabs->setSelectedTabByIndex(static_cast<unsigned>(0));
+ mChatTabs->setSelectedTabByIndex(CAST_U32(0));
}
void ChatWindow::action(const ActionEvent &event)
@@ -773,7 +773,7 @@ void ChatWindow::keyPressed(KeyEvent &event)
if (mCurHist != mHistory.end())
{
mChatInput->setText(*mCurHist);
- mChatInput->setCaretPosition(static_cast<unsigned>(
+ mChatInput->setCaretPosition(CAST_U32(
mChatInput->getText().length()));
}
else
@@ -797,7 +797,7 @@ void ChatWindow::keyPressed(KeyEvent &event)
--mCurHist;
addCurrentToHistory();
mChatInput->setText(*mCurHist);
- mChatInput->setCaretPosition(static_cast<unsigned>(
+ mChatInput->setCaretPosition(CAST_U32(
mChatInput->getText().length()));
}
else if (actionId == InputAction::GUI_INSERT &&
@@ -828,7 +828,7 @@ void ChatWindow::keyPressed(KeyEvent &event)
{
if (!mChatHistoryIndex)
{
- mChatHistoryIndex = static_cast<unsigned>(
+ mChatHistoryIndex = CAST_U32(
tab->getRows().size());
mChatInput->setText("");
@@ -848,7 +848,7 @@ void ChatWindow::keyPressed(KeyEvent &event)
if (f == mChatHistoryIndex)
mChatInput->setText(*it);
}
- mChatInput->setCaretPosition(static_cast<unsigned>(
+ mChatInput->setCaretPosition(CAST_U32(
mChatInput->getText().length()));
}
}
@@ -860,11 +860,11 @@ void ChatWindow::keyPressed(KeyEvent &event)
{
const std::list<std::string> &rows = tab->getRows();
const size_t &tabSize = rows.size();
- if (static_cast<size_t>(mChatHistoryIndex) + 1 < tabSize)
+ if (CAST_SIZE(mChatHistoryIndex) + 1 < tabSize)
{
mChatHistoryIndex ++;
}
- else if (static_cast<size_t>(mChatHistoryIndex) < tabSize)
+ else if (CAST_SIZE(mChatHistoryIndex) < tabSize)
{
mChatHistoryIndex ++;
mChatInput->setText("");
@@ -884,7 +884,7 @@ void ChatWindow::keyPressed(KeyEvent &event)
if (f == mChatHistoryIndex)
mChatInput->setText(*it);
}
- mChatInput->setCaretPosition(static_cast<unsigned>(
+ mChatInput->setCaretPosition(CAST_U32(
mChatInput->getText().length()));
}
}
@@ -1014,8 +1014,8 @@ void ChatWindow::addInputText(const std::string &text, const bool space)
ss << inputText.substr(caretPos);
mChatInput->setText(ss.str());
- mChatInput->setCaretPosition(caretPos + static_cast<int>(
- text.length()) + static_cast<int>(space));
+ mChatInput->setCaretPosition(caretPos + CAST_S32(
+ text.length()) + CAST_S32(space));
requestChatFocus();
}
@@ -1298,7 +1298,7 @@ void ChatWindow::postConnection()
skip --; \
continue; \
} \
- const unsigned char ch = static_cast<unsigned char>(msg.at(f)); \
+ const unsigned char ch = CAST_U8(msg.at(f)); \
if (f + 2 < sz && msg.substr(f, 2) == "%%") \
{ \
newMsg += msg.at(f); \
@@ -1419,8 +1419,8 @@ void ChatWindow::autoComplete()
.append(inputText.substr(caretPos,
inputText.length() - caretPos)));
- const int len = caretPos - static_cast<int>(name.length())
- + static_cast<int>(newName.length());
+ const int len = caretPos - CAST_S32(name.length())
+ + CAST_S32(newName.length());
if (startName > 0)
mChatInput->setCaretPosition(len + 1);
@@ -1592,7 +1592,7 @@ bool ChatWindow::resortChatLog(std::string line,
{
const std::string nick = line.substr(0, idx2 - 1);
line = line.substr(idx2 + 6);
- localPetEmote(nick, static_cast<uint8_t>(
+ localPetEmote(nick, CAST_U8(
atoi(line.c_str())));
}
else if (line.find(": \302\202\302m") != std::string::npos)
@@ -1608,7 +1608,7 @@ bool ChatWindow::resortChatLog(std::string line,
{
const std::string nick = line.substr(0, idx2 - 1);
line = line.substr(idx2 + 6);
- localPetDirection(nick, static_cast<uint8_t>(
+ localPetDirection(nick, CAST_U8(
atoi(line.c_str())));
}
else if (line.find(": \302\202\302a") != std::string::npos)
@@ -1946,9 +1946,9 @@ bool ChatWindow::saveTab(const int num, ChatTab *const tab) const
tab->getChannelName());
serverConfig.setValue("chatWhisperFlags" + toString(num),
- static_cast<int>(tab->getAllowHighlight())
- + (2 * static_cast<int>(tab->getRemoveNames()))
- + (4 * static_cast<int>(tab->getNoAway())));
+ CAST_S32(tab->getAllowHighlight())
+ + (2 * CAST_S32(tab->getRemoveNames()))
+ + (4 * CAST_S32(tab->getNoAway())));
return true;
}
diff --git a/src/gui/windows/editserverdialog.cpp b/src/gui/windows/editserverdialog.cpp
index e456533cb..d45d46be3 100644
--- a/src/gui/windows/editserverdialog.cpp
+++ b/src/gui/windows/editserverdialog.cpp
@@ -230,7 +230,7 @@ void EditServerDialog::action(const ActionEvent &event)
mServer.description = mDescriptionField->getText();
mServer.onlineListUrl = mOnlineListUrlField->getText();
mServer.hostname = mServerAddressField->getText();
- mServer.port = static_cast<int16_t>(atoi(
+ mServer.port = CAST_S16(atoi(
mPortField->getText().c_str()));
mServer.persistentIp = mPersistentIp->isSelected();
diff --git a/src/gui/windows/emotewindow.cpp b/src/gui/windows/emotewindow.cpp
index fe2ab432b..7acbad13d 100644
--- a/src/gui/windows/emotewindow.cpp
+++ b/src/gui/windows/emotewindow.cpp
@@ -158,7 +158,7 @@ std::string EmoteWindow::getSelectedEmote() const
return std::string();
char chr[2];
- chr[0] = static_cast<char>('0' + index);
+ chr[0] = CAST_8('0' + index);
chr[1] = 0;
return std::string("%%").append(&chr[0]);
}
@@ -178,7 +178,7 @@ std::string EmoteWindow::getSelectedColor() const
return std::string();
char chr[2];
- chr[0] = static_cast<char>('0' + index);
+ chr[0] = CAST_8('0' + index);
chr[1] = 0;
return std::string("##").append(&chr[0]);
}
diff --git a/src/gui/windows/equipmentwindow.cpp b/src/gui/windows/equipmentwindow.cpp
index a32f80c3e..ddde610eb 100644
--- a/src/gui/windows/equipmentwindow.cpp
+++ b/src/gui/windows/equipmentwindow.cpp
@@ -713,7 +713,7 @@ void EquipmentWindow::loadSlot(const XmlNodePtr slotNode,
const int imageIndex = XML::getProperty(slotNode, "image", -1);
Image *image = nullptr;
- if (imageIndex >= 0 && imageIndex < static_cast<signed>(imageset->size()))
+ if (imageIndex >= 0 && imageIndex < CAST_S32(imageset->size()))
image = imageset->get(imageIndex);
std::vector<EquipmentBox*> &boxes = mPages[page]->boxes;
@@ -786,7 +786,7 @@ void EquipmentWindow::addBox(const int idx, int x, int y, const int imageIndex)
Image *image = nullptr;
if (mImageSet && imageIndex >= 0 && imageIndex
- < static_cast<signed>(mImageSet->size()))
+ < CAST_S32(mImageSet->size()))
{
image = mImageSet->get(imageIndex);
}
@@ -826,5 +826,5 @@ int EquipmentWindow::addPage(const std::string &name)
boxes.push_back(nullptr);
mTabs->addButton(name, name, false);
- return static_cast<int>(mPages.size()) - 1;
+ return CAST_S32(mPages.size()) - 1;
}
diff --git a/src/gui/windows/itemamountwindow.cpp b/src/gui/windows/itemamountwindow.cpp
index cefeaca7b..8ad79ecab 100644
--- a/src/gui/windows/itemamountwindow.cpp
+++ b/src/gui/windows/itemamountwindow.cpp
@@ -413,7 +413,7 @@ void ItemAmountWindow::action(const ActionEvent &event)
else if (eventId == "all")
amount = mMax;
else if (eventId == "slide")
- amount = static_cast<int>(mItemAmountSlide->getValue());
+ amount = CAST_S32(mItemAmountSlide->getValue());
mItemAmountTextField->setValue(amount);
mItemAmountSlide->setValue(amount);
@@ -429,22 +429,22 @@ void ItemAmountWindow::action(const ActionEvent &event)
if (eventId == "incPrice")
{
mPrice++;
- price = static_cast<int>(pow(10.0, mPrice));
+ price = CAST_S32(pow(10.0, mPrice));
mItemPriceTextField->setValue(price);
mItemPriceSlide->setValue(price);
}
else if (eventId == "decPrice")
{
mPrice--;
- price = static_cast<int>(pow(10.0, mPrice));
+ price = CAST_S32(pow(10.0, mPrice));
mItemPriceTextField->setValue(price);
mItemPriceSlide->setValue(price);
}
else if (eventId == "slidePrice")
{
- price = static_cast<int>(mItemPriceSlide->getValue());
+ price = CAST_S32(mItemPriceSlide->getValue());
if (price)
- mPrice = static_cast<int>(log(static_cast<float>(price)));
+ mPrice = CAST_S32(log(static_cast<float>(price)));
else
mPrice = 0;
mItemPriceTextField->setValue(price);
diff --git a/src/gui/windows/logindialog.cpp b/src/gui/windows/logindialog.cpp
index 3a0fd56ef..c39486dda 100644
--- a/src/gui/windows/logindialog.cpp
+++ b/src/gui/windows/logindialog.cpp
@@ -130,7 +130,7 @@ LoginDialog::LoginDialog(LoginData &data,
mUpdateTypeDropDown->setActionEventId("updatetype");
mUpdateTypeDropDown->setSelected((mLoginData->updateType
- | UpdateType::Custom) ^ static_cast<int>(UpdateType::Custom));
+ | UpdateType::Custom) ^ CAST_S32(UpdateType::Custom));
if (!mCustomUpdateHost->isSelected())
mUpdateHostText->setVisible(Visible_false);
@@ -339,7 +339,7 @@ void LoginDialog::prepareUpdate()
}
mLoginData->updateType = updateType;
- serverConfig.setValue("updateType", static_cast<int>(updateType));
+ serverConfig.setValue("updateType", CAST_S32(updateType));
mRegisterButton->setEnabled(false);
mServerButton->setEnabled(false);
diff --git a/src/gui/windows/mailwindow.cpp b/src/gui/windows/mailwindow.cpp
index 2d52a2e99..071a1ecee 100644
--- a/src/gui/windows/mailwindow.cpp
+++ b/src/gui/windows/mailwindow.cpp
@@ -252,7 +252,7 @@ void MailWindow::viewPrev(const int id)
if (it == mMessages.begin())
{
it = mMessages.end();
- mListBox->setSelected(static_cast<int>(mMessages.size()) - 1);
+ mListBox->setSelected(CAST_S32(mMessages.size()) - 1);
}
else
{
diff --git a/src/gui/windows/minimap.cpp b/src/gui/windows/minimap.cpp
index ae93c9190..797427c50 100644
--- a/src/gui/windows/minimap.cpp
+++ b/src/gui/windows/minimap.cpp
@@ -375,9 +375,9 @@ void Minimap::draw2(Graphics *const graphics)
if (userPalette)
graphics->setColor(userPalette->getColor(type));
- const int offsetHeight = static_cast<int>(static_cast<float>(
+ const int offsetHeight = CAST_S32(static_cast<float>(
dotSize - 1) * mHeightProportion);
- const int offsetWidth = static_cast<int>(static_cast<float>(
+ const int offsetWidth = CAST_S32(static_cast<float>(
dotSize - 1) * mWidthProportion);
const Vector &pos = being->getPosition();
@@ -414,15 +414,15 @@ void Minimap::draw2(Graphics *const graphics)
UserColorId::PARTY));
}
- const int offsetHeight = static_cast<int>(
+ const int offsetHeight = CAST_S32(
mHeightProportion);
- const int offsetWidth = static_cast<int>(
+ const int offsetWidth = CAST_S32(
mWidthProportion);
graphics->fillRectangle(Rect(
- static_cast<int>(member->getX()
+ CAST_S32(member->getX()
* mWidthProportion) + mMapOriginX - offsetWidth,
- static_cast<int>(member->getY()
+ CAST_S32(member->getY()
* mHeightProportion) + mMapOriginY - offsetHeight,
2, 2));
}
@@ -443,9 +443,9 @@ void Minimap::draw2(Graphics *const graphics)
+ viewport->getCameraRelativeY())
* mHeightProportion) / 32 + mMapOriginY;
- const int w = static_cast<int>(static_cast<float>(
+ const int w = CAST_S32(static_cast<float>(
gw) * mWidthProportion / 32);
- const int h = static_cast<int>(static_cast<float>(
+ const int h = CAST_S32(static_cast<float>(
gh) * mHeightProportion / 32);
if (w <= a.width)
diff --git a/src/gui/windows/ministatuswindow.cpp b/src/gui/windows/ministatuswindow.cpp
index 3ca9b8e35..1e43ce3b5 100644
--- a/src/gui/windows/ministatuswindow.cpp
+++ b/src/gui/windows/ministatuswindow.cpp
@@ -226,7 +226,7 @@ void MiniStatusWindow::updateBars()
void MiniStatusWindow::setIcon(const int index, AnimatedSprite *const sprite)
{
- if (index >= static_cast<int>(mIcons.size()))
+ if (index >= CAST_S32(mIcons.size()))
mIcons.resize(index + 1, nullptr);
delete mIcons[index];
@@ -235,7 +235,7 @@ void MiniStatusWindow::setIcon(const int index, AnimatedSprite *const sprite)
void MiniStatusWindow::eraseIcon(const int index)
{
- if (index < static_cast<int>(mIcons.size()))
+ if (index < CAST_S32(mIcons.size()))
{
delete mIcons[index];
mIcons.erase(mIcons.begin() + index);
diff --git a/src/gui/windows/npcdialog.cpp b/src/gui/windows/npcdialog.cpp
index dc991097b..27386af5b 100644
--- a/src/gui/windows/npcdialog.cpp
+++ b/src/gui/windows/npcdialog.cpp
@@ -348,14 +348,14 @@ void NpcDialog::action(const ActionEvent &event)
gui->resetClickCount();
const int selectedIndex = mItemList->getSelected();
- if (selectedIndex >= static_cast<int>(mItems.size())
+ if (selectedIndex >= CAST_S32(mItems.size())
|| selectedIndex < 0
|| !PacketLimiter::limitPackets(
PacketType::PACKET_NPC_INPUT))
{
return;
}
- unsigned char choice = static_cast<unsigned char>(
+ unsigned char choice = CAST_U8(
selectedIndex + 1);
printText = mItems[selectedIndex];
@@ -678,7 +678,7 @@ void NpcDialog::closeDialog()
int NpcDialog::getNumberOfElements()
{
- return static_cast<int>(mItems.size());
+ return CAST_S32(mItems.size());
}
std::string NpcDialog::getElementAt(int i)
@@ -1118,7 +1118,7 @@ void NpcDialog::saveCamera()
if (!viewport || mCameraMode >= 0)
return;
- mCameraMode = static_cast<int>(settings.cameraMode);
+ mCameraMode = CAST_S32(settings.cameraMode);
mCameraX = viewport->getCameraRelativeX();
mCameraY = viewport->getCameraRelativeY();
}
@@ -1128,7 +1128,7 @@ void NpcDialog::restoreCamera()
if (!viewport || mCameraMode == -1)
return;
- if (static_cast<int>(settings.cameraMode) != mCameraMode)
+ if (CAST_S32(settings.cameraMode) != mCameraMode)
viewport->toggleCameraMode();
if (mCameraMode)
{
@@ -1206,7 +1206,7 @@ void NpcDialog::logic()
if (mShowAvatar && mAvatarBeing)
{
mAvatarBeing->logic();
- if (mPlayerBox->getWidth() < static_cast<signed>(3 * getPadding()))
+ if (mPlayerBox->getWidth() < CAST_S32(3 * getPadding()))
{
const Sprite *const sprite = mAvatarBeing->getSprite(0);
if (sprite)
diff --git a/src/gui/windows/outfitwindow.cpp b/src/gui/windows/outfitwindow.cpp
index 73cc5101d..83874f4c3 100644
--- a/src/gui/windows/outfitwindow.cpp
+++ b/src/gui/windows/outfitwindow.cpp
@@ -169,7 +169,7 @@ void OutfitWindow::load(const bool oldConfig)
std::vector<unsigned char> tokens2;
while (ss2 >> buf)
- tokens2.push_back(static_cast<unsigned char>(atoi(buf.c_str())));
+ tokens2.push_back(CAST_U8(atoi(buf.c_str())));
for (size_t i = 0, sz = tokens2.size();
i < sz && i < OUTFIT_ITEM_COUNT; i++)
@@ -181,8 +181,8 @@ void OutfitWindow::load(const bool oldConfig)
true);
}
mAwayOutfit = cfg->getValue("OutfitAwayIndex", OUTFITS_COUNT - 1);
- if (mAwayOutfit >= static_cast<int>(OUTFITS_COUNT))
- mAwayOutfit = static_cast<int>(OUTFITS_COUNT) - 1;
+ if (mAwayOutfit >= CAST_S32(OUTFITS_COUNT))
+ mAwayOutfit = CAST_S32(OUTFITS_COUNT) - 1;
if (mAwayOutfitCheck)
mAwayOutfitCheck->setSelected(mAwayOutfit == mCurrentOutfit);
@@ -204,7 +204,7 @@ void OutfitWindow::save() const
outfitStr.append(toString(res));
if (i < OUTFIT_ITEM_COUNT - 1)
outfitStr.append(" ");
- outfitColorsStr.append(toString(static_cast<int>(
+ outfitColorsStr.append(toString(CAST_S32(
toInt(mItemColors[o][i], int))));
if (i < OUTFIT_ITEM_COUNT - 1)
outfitColorsStr.append(" ");
@@ -249,7 +249,7 @@ void OutfitWindow::action(const ActionEvent &event)
}
else if (eventId == "unequip")
{
- if (mCurrentOutfit >= 0 && mCurrentOutfit < static_cast<int>(
+ if (mCurrentOutfit >= 0 && mCurrentOutfit < CAST_S32(
OUTFITS_COUNT))
{
mItemsUnequip[mCurrentOutfit] = mUnequipCheck->isSelected();
@@ -274,7 +274,7 @@ void OutfitWindow::wearOutfit(const int outfit, const bool unwearEmpty,
{
bool isEmpty = true;
- if (outfit < 0 || outfit > static_cast<int>(OUTFITS_COUNT))
+ if (outfit < 0 || outfit > CAST_S32(OUTFITS_COUNT))
return;
for (unsigned i = 0; i < OUTFIT_ITEM_COUNT; i++)
@@ -294,7 +294,7 @@ void OutfitWindow::wearOutfit(const int outfit, const bool unwearEmpty,
}
}
- if ((!isEmpty || unwearEmpty) && outfit < static_cast<int>(OUTFITS_COUNT)
+ if ((!isEmpty || unwearEmpty) && outfit < CAST_S32(OUTFITS_COUNT)
&& mItemsUnequip[outfit])
{
unequipNotInOutfit(outfit);
@@ -313,8 +313,8 @@ void OutfitWindow::copyOutfit(const int outfit)
void OutfitWindow::copyOutfit(const int src, const int dst)
{
- if (src < 0 || src > static_cast<int>(OUTFITS_COUNT)
- || dst < 0 || dst > static_cast<int>(OUTFITS_COUNT))
+ if (src < 0 || src > CAST_S32(OUTFITS_COUNT)
+ || dst < 0 || dst > CAST_S32(OUTFITS_COUNT))
{
return;
}
@@ -339,7 +339,7 @@ void OutfitWindow::draw(Graphics *graphics)
{
const int itemX = mPadding + ((i % mGridWidth) * mBoxWidth);
const int itemY = mPadding + mTitleBarHeight
- + ((i / static_cast<unsigned int>(mGridWidth)) * mBoxHeight);
+ + ((i / CAST_U32(mGridWidth)) * mBoxHeight);
graphics->setColor(mBorderColor);
graphics->drawRectangle(Rect(itemX, itemY, 32, 32));
@@ -395,7 +395,7 @@ void OutfitWindow::safeDraw(Graphics *graphics)
{
const int itemX = mPadding + ((i % mGridWidth) * mBoxWidth);
const int itemY = mPadding + mTitleBarHeight
- + ((i / static_cast<unsigned int>(mGridWidth)) * mBoxHeight);
+ + ((i / CAST_U32(mGridWidth)) * mBoxHeight);
graphics->setColor(mBorderColor);
graphics->drawRectangle(Rect(itemX, itemY, 32, 32));
@@ -558,7 +558,7 @@ int OutfitWindow::getIndexFromGrid(const int pointX, const int pointY) const
return -1;
const int index = (((pointY - mTitleBarHeight) / mBoxHeight) * mGridWidth)
+ (pointX - mPadding) / mBoxWidth;
- if (index >= static_cast<int>(OUTFIT_ITEM_COUNT) || index < 0)
+ if (index >= CAST_S32(OUTFIT_ITEM_COUNT) || index < 0)
return -1;
return index;
}
@@ -601,7 +601,7 @@ std::string OutfitWindow::keyName(const int number)
void OutfitWindow::next()
{
- if (mCurrentOutfit < (static_cast<int>(OUTFITS_COUNT) - 1))
+ if (mCurrentOutfit < (CAST_S32(OUTFITS_COUNT) - 1))
mCurrentOutfit++;
else
mCurrentOutfit = 0;
@@ -621,7 +621,7 @@ void OutfitWindow::showCurrentOutfit()
{
// TRANSLATORS: outfits window label
mCurrentLabel->setCaption(strprintf(_("Outfit: %d"), mCurrentOutfit + 1));
- if (mCurrentOutfit < static_cast<int>(OUTFITS_COUNT))
+ if (mCurrentOutfit < CAST_S32(OUTFITS_COUNT))
mUnequipCheck->setSelected(mItemsUnequip[mCurrentOutfit]);
else
mUnequipCheck->setSelected(false);
@@ -635,7 +635,7 @@ void OutfitWindow::wearNextOutfit(const bool all)
{
next();
if (!all && mCurrentOutfit >= 0 && mCurrentOutfit
- < static_cast<int>(OUTFITS_COUNT))
+ < CAST_S32(OUTFITS_COUNT))
{
bool fromStart = false;
while (!mItemsUnequip[mCurrentOutfit])
@@ -657,7 +657,7 @@ void OutfitWindow::wearPreviousOutfit(const bool all)
{
previous();
if (!all && mCurrentOutfit >= 0 && mCurrentOutfit
- < static_cast<int>(OUTFITS_COUNT))
+ < CAST_S32(OUTFITS_COUNT))
{
bool fromStart = false;
while (!mItemsUnequip[mCurrentOutfit])
@@ -694,7 +694,7 @@ void OutfitWindow::copyFromEquiped(const int dst)
{
mItems[dst][outfitCell] = item->getId();
mItemColors[dst][outfitCell++] = item->getColor();
- if (outfitCell >= static_cast<int>(OUTFIT_ITEM_COUNT))
+ if (outfitCell >= CAST_S32(OUTFIT_ITEM_COUNT))
break;
}
}
diff --git a/src/gui/windows/questswindow.cpp b/src/gui/windows/questswindow.cpp
index 3bea8577f..9e46c1793 100644
--- a/src/gui/windows/questswindow.cpp
+++ b/src/gui/windows/questswindow.cpp
@@ -369,10 +369,10 @@ void QuestsWindow::rebuild(const bool playSound)
FOR_EACH (std::vector<QuestItem*>::const_iterator, it, hidden)
(*it)->completeFlag = -1;
- if (updatedQuest == -1 || updatedQuest >= static_cast<int>(
+ if (updatedQuest == -1 || updatedQuest >= CAST_S32(
mQuestLinks.size()))
{
- updatedQuest = static_cast<int>(mQuestLinks.size() - 1);
+ updatedQuest = CAST_S32(mQuestLinks.size() - 1);
}
if (updatedQuest >= 0)
{
diff --git a/src/gui/windows/quitdialog.cpp b/src/gui/windows/quitdialog.cpp
index 1ef878aae..ff12795d4 100644
--- a/src/gui/windows/quitdialog.cpp
+++ b/src/gui/windows/quitdialog.cpp
@@ -141,7 +141,7 @@ QuitDialog::~QuitDialog()
void QuitDialog::placeOption(ContainerPlacer &placer,
RadioButton *const option)
{
- placer(0, static_cast<int>(mOptions.size()), option, 3);
+ placer(0, CAST_S32(mOptions.size()), option, 3);
mOptions.push_back(option);
}
diff --git a/src/gui/windows/registerdialog.cpp b/src/gui/windows/registerdialog.cpp
index 601f16aa8..3c4fe5ed2 100644
--- a/src/gui/windows/registerdialog.cpp
+++ b/src/gui/windows/registerdialog.cpp
@@ -149,7 +149,7 @@ void RegisterDialog::postInit()
Window::postInit();
setVisible(Visible_true);
mUserField->requestFocus();
- mUserField->setCaretPosition(static_cast<unsigned>(
+ mUserField->setCaretPosition(CAST_U32(
mUserField->getText().length()));
mRegisterButton->setEnabled(canSubmit());
diff --git a/src/gui/windows/serverdialog.cpp b/src/gui/windows/serverdialog.cpp
index 1049085b4..f4cd045c3 100644
--- a/src/gui/windows/serverdialog.cpp
+++ b/src/gui/windows/serverdialog.cpp
@@ -521,7 +521,7 @@ void ServerDialog::loadServers(const bool addNew)
server.hostname = XML::getProperty(subNode, "hostname", "");
server.althostname = XML::getProperty(
subNode, "althostname", "");
- server.port = static_cast<uint16_t>(
+ server.port = CAST_U16(
XML::getProperty(subNode, "port", 0));
if (server.port == 0)
@@ -570,7 +570,7 @@ void ServerDialog::loadServers(const bool addNew)
MutexLocker tempLock(&mMutex);
// Add the server to the local list if it's not already present
bool found = false;
- for (unsigned int i = 0, sz = static_cast<unsigned int>(
+ for (unsigned int i = 0, sz = CAST_U32(
mServers.size()); i < sz; i++)
{
if (mServers[i] == server)
@@ -622,7 +622,7 @@ void ServerDialog::loadCustomServers()
persistentIpKey, 0) ? true : false;
const int defaultPort = defaultPortForServerType(server.type);
- server.port = static_cast<uint16_t>(
+ server.port = CAST_U16(
config.getValue(portKey, defaultPort));
// skip invalid server
@@ -640,7 +640,7 @@ void ServerDialog::saveCustomServers(const ServerInfo &currentServer,
// Make sure the current server is mentioned first
if (currentServer.isValid())
{
- if (index >= 0 && static_cast<size_t>(index) < mServers.size())
+ if (index >= 0 && CAST_SIZE(index) < mServers.size())
{
mServers[index] = currentServer;
}
@@ -660,7 +660,7 @@ void ServerDialog::saveCustomServers(const ServerInfo &currentServer,
int savedServerCount = 0;
- for (unsigned i = 0, sz = static_cast<unsigned>(mServers.size());
+ for (unsigned i = 0, sz = CAST_U32(mServers.size());
i < sz && savedServerCount < MAX_SERVERLIST; ++ i)
{
const ServerInfo &server = mServers.at(i);
@@ -712,7 +712,7 @@ int ServerDialog::downloadUpdate(void *ptr,
{
finished = true;
}
- else if (static_cast<int>(status) < 0)
+ else if (CAST_S32(status) < 0)
{
logger->log("Error retreiving server list: %s\n",
sd->mDownload->getError());
diff --git a/src/gui/windows/skilldialog.cpp b/src/gui/windows/skilldialog.cpp
index b80f6d5fe..d8ae3ef2d 100644
--- a/src/gui/windows/skilldialog.cpp
+++ b/src/gui/windows/skilldialog.cpp
@@ -135,7 +135,7 @@ void SkillDialog::action(const ActionEvent &event)
if (tab)
{
if (const SkillInfo *const info = tab->getSelectedInfo())
- playerHandler->increaseSkill(static_cast<uint16_t>(info->id));
+ playerHandler->increaseSkill(CAST_U16(info->id));
}
}
else if (eventId == "sel")
@@ -150,7 +150,7 @@ void SkillDialog::action(const ActionEvent &event)
mUseButton->setCaption(info->useButton);
mIncreaseButton->setEnabled(info->id < SKILL_VAR_MIN_ID);
const int num = itemShortcutWindow->getTabIndex();
- if (num >= 0 && num < static_cast<int>(SHORTCUT_TABS)
+ if (num >= 0 && num < CAST_S32(SHORTCUT_TABS)
&& itemShortcut[num])
{
itemShortcut[num]->setItemSelected(
@@ -329,7 +329,7 @@ void SkillDialog::loadXmlFile(const std::string &fileName)
if (!skill)
{
skill = new SkillInfo;
- skill->id = static_cast<unsigned int>(id);
+ skill->id = CAST_U32(id);
skill->modifiable = Modifiable_false;
skill->model = model;
skill->update();
@@ -482,7 +482,7 @@ void SkillDialog::addSkill(const SkillOwner::Type owner,
if (mDefaultModel)
{
SkillInfo *const skill = new SkillInfo;
- skill->id = static_cast<unsigned int>(id);
+ skill->id = CAST_U32(id);
skill->type = type;
skill->owner = owner;
SkillData *const data = skill->data;
diff --git a/src/gui/windows/textcommandeditor.cpp b/src/gui/windows/textcommandeditor.cpp
index 799456fe0..c2a5d66c9 100644
--- a/src/gui/windows/textcommandeditor.cpp
+++ b/src/gui/windows/textcommandeditor.cpp
@@ -151,11 +151,11 @@ TextCommandEditor::TextCommandEditor(TextCommand *const command) :
mSymbolTextField->setText(command->getSymbol());
mCommandTextField->setText(command->getCommand());
mCommentTextField->setText(command->getComment());
- mTypeDropDown->setSelected(static_cast<int>(command->getTargetType()));
+ mTypeDropDown->setSelected(CAST_S32(command->getTargetType()));
#ifdef TMWA_SUPPORT
mManaField->setValue(command->getMana());
mMagicLvlField->setValue(command->getBaseLvl());
- mSchoolDropDown->setSelected(static_cast<int>(command->getSchool())
+ mSchoolDropDown->setSelected(CAST_S32(command->getSchool())
- MAGIC_START_ID);
mSchoolLvlField->setValue(command->getSchoolLvl());
#endif
diff --git a/src/gui/windows/textdialog.cpp b/src/gui/windows/textdialog.cpp
index e777cf6a8..442cd5c67 100644
--- a/src/gui/windows/textdialog.cpp
+++ b/src/gui/windows/textdialog.cpp
@@ -71,7 +71,7 @@ TextDialog::TextDialog(const std::string &restrict title,
int width = getFont()->getWidth(title);
if (width < textLabel->getWidth())
width = textLabel->getWidth();
- reflowLayout(static_cast<int>(width + 20));
+ reflowLayout(CAST_S32(width + 20));
}
void TextDialog::postInit()
diff --git a/src/gui/windows/textselectdialog.cpp b/src/gui/windows/textselectdialog.cpp
index bac3ac0e4..dbc34bfaf 100644
--- a/src/gui/windows/textselectdialog.cpp
+++ b/src/gui/windows/textselectdialog.cpp
@@ -136,7 +136,7 @@ void TextSelectDialog::action(const ActionEvent &event)
else if (eventId == "select")
{
const int index = mItemList->getSelected();
- if (index < 0 || index >= static_cast<int>(mModel->size()))
+ if (index < 0 || index >= CAST_S32(mModel->size()))
return;
mText = mModel->getElementAt(index);
distributeActionEvent();
diff --git a/src/gui/windows/updaterwindow.cpp b/src/gui/windows/updaterwindow.cpp
index bf4814a03..e6e97553a 100644
--- a/src/gui/windows/updaterwindow.cpp
+++ b/src/gui/windows/updaterwindow.cpp
@@ -531,7 +531,7 @@ int UpdaterWindow::updateProgress(void *ptr,
progress = 1.0F;
uw->setLabel(std::string(uw->mCurrentFile).append(" (")
- .append(toString(static_cast<int>(progress * 100))).append("%)"));
+ .append(toString(CAST_S32(progress * 100))).append("%)"));
uw->setProgress(progress);
@@ -554,11 +554,11 @@ size_t UpdaterWindow::memoryWrite(void *ptr, size_t size,
if (!uw)
return 0;
uw->mMemoryBuffer = static_cast<char*>(realloc(uw->mMemoryBuffer,
- static_cast<size_t>(uw->mDownloadedBytes) + totalMem));
+ CAST_SIZE(uw->mDownloadedBytes) + totalMem));
if (uw->mMemoryBuffer)
{
memcpy(&(uw->mMemoryBuffer[uw->mDownloadedBytes]), ptr, totalMem);
- uw->mDownloadedBytes += static_cast<int>(totalMem);
+ uw->mDownloadedBytes += CAST_S32(totalMem);
}
return totalMem;
@@ -655,7 +655,7 @@ void UpdaterWindow::loadUpdates()
}
std::string fixPath = mUpdatesDir + "/fix";
- const unsigned sz = static_cast<unsigned>(mUpdateFiles.size());
+ const unsigned sz = CAST_U32(mUpdateFiles.size());
for (mUpdateIndex = 0; mUpdateIndex < sz; mUpdateIndex++)
{
const UpdateFile &file = mUpdateFiles[mUpdateIndex];
@@ -685,7 +685,7 @@ void UpdaterWindow::loadLocalUpdates(const std::string &dir)
}
const std::string fixPath = dir + "/fix";
- for (unsigned int updateIndex = 0, sz = static_cast<unsigned int>(
+ for (unsigned int updateIndex = 0, sz = CAST_U32(
updateFiles.size()); updateIndex < sz; updateIndex ++)
{
const UpdateFile &file = updateFiles[updateIndex];
@@ -712,7 +712,7 @@ void UpdaterWindow::unloadUpdates(const std::string &dir)
}
const std::string fixPath = dir + "/fix";
- for (unsigned int updateIndex = 0, sz = static_cast<unsigned int>(
+ for (unsigned int updateIndex = 0, sz = CAST_U32(
updateFiles.size()); updateIndex < sz; updateIndex ++)
{
UpdaterWindow::removeUpdateFile(dir,
@@ -728,7 +728,7 @@ void UpdaterWindow::loadManaPlusUpdates(const std::string &dir)
std::vector<UpdateFile> updateFiles = loadXMLFile(
std::string(fixPath).append("/").append(xmlUpdateFile), false);
- for (unsigned int updateIndex = 0, sz = static_cast<unsigned int>(
+ for (unsigned int updateIndex = 0, sz = CAST_U32(
updateFiles.size()); updateIndex < sz; updateIndex ++)
{
const UpdateFile &file = updateFiles[updateIndex];
@@ -752,7 +752,7 @@ void UpdaterWindow::unloadManaPlusUpdates(const std::string &dir)
const std::vector<UpdateFile> updateFiles = loadXMLFile(
std::string(fixPath).append("/").append(xmlUpdateFile), true);
- for (unsigned int updateIndex = 0, sz = static_cast<unsigned int>(
+ for (unsigned int updateIndex = 0, sz = CAST_U32(
updateFiles.size()); updateIndex < sz; updateIndex ++)
{
std::string name = updateFiles[updateIndex].name;
@@ -815,11 +815,11 @@ void UpdaterWindow::logic()
mProgressBar->setProgress(mDownloadProgress);
if (mUpdateFiles.size()
- && static_cast<size_t>(mUpdateIndex) <= mUpdateFiles.size())
+ && CAST_SIZE(mUpdateIndex) <= mUpdateFiles.size())
{
mProgressBar->setText(strprintf("%u/%u", mUpdateIndex
- + mUpdateIndexOffset + 1, static_cast<unsigned>(
- mUpdateFiles.size()) + static_cast<int>(
+ + mUpdateIndexOffset + 1, CAST_U32(
+ mUpdateFiles.size()) + CAST_S32(
mTempUpdateFiles.size()) + 1));
}
else
@@ -911,7 +911,7 @@ void UpdaterWindow::logic()
case UPDATE_RESOURCES:
if (mDownloadComplete)
{
- if (static_cast<size_t>(mUpdateIndex) < mUpdateFiles.size())
+ if (CAST_SIZE(mUpdateIndex) < mUpdateFiles.size())
{
UpdateFile thisFile = mUpdateFiles[mUpdateIndex];
if (thisFile.type == "music"
@@ -983,7 +983,7 @@ void UpdaterWindow::logic()
if (mDownloadComplete)
{
mValidateXml = false;
- if (static_cast<size_t>(mUpdateIndex)
+ if (CAST_SIZE(mUpdateIndex)
< mTempUpdateFiles.size())
{
const UpdateFile thisFile = mTempUpdateFiles[mUpdateIndex];
@@ -1027,7 +1027,7 @@ void UpdaterWindow::logic()
break;
default:
logger->log("UpdaterWindow::logic unknown status: "
- + toString(static_cast<unsigned>(mDownloadStatus)));
+ + toString(CAST_U32(mDownloadStatus)));
break;
}
BLOCK_END("UpdaterWindow::logic")
@@ -1085,7 +1085,7 @@ void UpdaterWindow::loadMods(const std::string &dir,
splitToStringSet(modsList, modsString, '|');
const std::string fixPath = dir + "/fix";
- for (unsigned int updateIndex = 0, sz = static_cast<unsigned int>(
+ for (unsigned int updateIndex = 0, sz = CAST_U32(
updateFiles.size()); updateIndex < sz; updateIndex ++)
{
const UpdateFile &file = updateFiles[updateIndex];
@@ -1105,7 +1105,7 @@ void UpdaterWindow::loadMods(const std::string &dir,
std::vector<UpdateFile> updateFiles2 = loadXMLFile(
std::string(fixPath).append("/").append(xmlUpdateFile), true);
- for (unsigned int updateIndex = 0, sz = static_cast<unsigned int>(
+ for (unsigned int updateIndex = 0, sz = CAST_U32(
updateFiles2.size()); updateIndex < sz; updateIndex ++)
{
const UpdateFile &file = updateFiles2[updateIndex];
diff --git a/src/gui/windows/whoisonline.cpp b/src/gui/windows/whoisonline.cpp
index d51af6b05..e5a803a29 100644
--- a/src/gui/windows/whoisonline.cpp
+++ b/src/gui/windows/whoisonline.cpp
@@ -459,7 +459,7 @@ void WhoIsOnline::loadWebList()
level = 0;
OnlinePlayer *const player = new OnlinePlayer(nick,
- static_cast<unsigned char>(255), level,
+ CAST_U8(255), level,
Gender::UNSPECIFIED, -1);
mOnlinePlayers.insert(player);
mOnlineNicks.insert(nick);
@@ -502,11 +502,11 @@ size_t WhoIsOnline::memoryWrite(void *restrict ptr,
reinterpret_cast<WhoIsOnline *restrict>(stream);
const size_t totalMem = size * nmemb;
wio->mMemoryBuffer = static_cast<char*>(realloc(wio->mMemoryBuffer,
- static_cast<size_t>(wio->mDownloadedBytes) + totalMem));
+ CAST_SIZE(wio->mDownloadedBytes) + totalMem));
if (wio->mMemoryBuffer)
{
memcpy(&(wio->mMemoryBuffer[wio->mDownloadedBytes]), ptr, totalMem);
- wio->mDownloadedBytes += static_cast<int>(totalMem);
+ wio->mDownloadedBytes += CAST_S32(totalMem);
}
return totalMem;
@@ -570,7 +570,7 @@ int WhoIsOnline::downloadThread(void *ptr)
case CURLE_COULDNT_CONNECT:
default:
std::cerr << "curl error "
- << static_cast<unsigned>(res) << ": "
+ << CAST_U32(res) << ": "
<< wio->mCurlError << " host: "
<< url.c_str() << std::endl;
break;
diff --git a/src/guild.h b/src/guild.h
index 1621ff359..7e5b63a40 100644
--- a/src/guild.h
+++ b/src/guild.h
@@ -151,7 +151,7 @@ class Guild final : public AvatarListModel
* @return Returns the number of members in the guild.
*/
int getNumberOfElements() override final A_WARN_UNUSED
- { return static_cast<int>(mMembers.size()); }
+ { return CAST_S32(mMembers.size()); }
Avatar *getAvatarAt(const int i) override final A_WARN_UNUSED;
diff --git a/src/input/inputactionmap.h b/src/input/inputactionmap.h
index 91b8d8368..1bd74708d 100644
--- a/src/input/inputactionmap.h
+++ b/src/input/inputactionmap.h
@@ -56,7 +56,7 @@
// keyData must be in same order as enum keyAction.
static const InputActionData inputActionData
- [static_cast<size_t>(InputAction::TOTAL)] = {
+ [CAST_SIZE(InputAction::TOTAL)] = {
{"keyMoveUp",
addKey(SDLK_UP),
emptyKey,
diff --git a/src/input/inputactionoperators.cpp b/src/input/inputactionoperators.cpp
index 23d742544..39de5b782 100644
--- a/src/input/inputactionoperators.cpp
+++ b/src/input/inputactionoperators.cpp
@@ -24,17 +24,17 @@
InputActionT operator+(InputActionT action, const int& i)
{
- action = static_cast<InputActionT>(static_cast<int>(action) + i);
+ action = static_cast<InputActionT>(CAST_S32(action) + i);
return action;
}
InputActionT operator+(InputActionT action, const unsigned int& i)
{
- action = static_cast<InputActionT>(static_cast<unsigned int>(action) + i);
+ action = static_cast<InputActionT>(CAST_U32(action) + i);
return action;
}
int operator-(const InputActionT &action1, const InputActionT &action2)
{
- return static_cast<int>(action1) - static_cast<int>(action2);
+ return CAST_S32(action1) - CAST_S32(action2);
}
diff --git a/src/input/inputactionsortfunctor.h b/src/input/inputactionsortfunctor.h
index 334185977..6a3a72245 100644
--- a/src/input/inputactionsortfunctor.h
+++ b/src/input/inputactionsortfunctor.h
@@ -31,8 +31,8 @@ class InputActionSortFunctor final
bool operator() (const InputActionT key1,
const InputActionT key2) const
{
- return keys[static_cast<size_t>(key1)].priority
- >= keys[static_cast<size_t>(key2)].priority;
+ return keys[CAST_SIZE(key1)].priority
+ >= keys[CAST_SIZE(key2)].priority;
}
const InputActionData *keys A_NONNULLPOINTER;
diff --git a/src/input/inputmanager.cpp b/src/input/inputmanager.cpp
index 46d97b836..b6ed13524 100644
--- a/src/input/inputmanager.cpp
+++ b/src/input/inputmanager.cpp
@@ -85,7 +85,7 @@ InputManager::InputManager() :
void InputManager::init() restrict2
{
for (unsigned int i = 0;
- i < static_cast<unsigned int>(InputAction::TOTAL);
+ i < CAST_U32(InputAction::TOTAL);
i ++)
{
InputFunction &kf = mKey[i];
@@ -113,7 +113,7 @@ void InputManager::update()
void InputManager::retrieve() restrict2
{
- for (int i = 0; i < static_cast<int>(InputAction::TOTAL); i ++)
+ for (int i = 0; i < CAST_S32(InputAction::TOTAL); i ++)
{
const std::string &restrict cmd = inputActionData[i].chatCommand;
if (!cmd.empty())
@@ -177,7 +177,7 @@ void InputManager::retrieve() restrict2
void InputManager::store() const restrict2
{
- for (int i = 0; i < static_cast<int>(InputAction::TOTAL); i ++)
+ for (int i = 0; i < CAST_S32(InputAction::TOTAL); i ++)
{
#ifdef USE_SDL2
const std::string cf = std::string("sdl2")
@@ -233,7 +233,7 @@ void InputManager::store() const restrict2
void InputManager::resetKey(const InputActionT i) restrict2
{
- InputFunction &restrict key = mKey[static_cast<size_t>(i)];
+ InputFunction &restrict key = mKey[CAST_SIZE(i)];
for (size_t i2 = 1; i2 < inputFunctionSize; i2 ++)
{
InputItem &restrict ki2 = key.values[i2];
@@ -241,7 +241,7 @@ void InputManager::resetKey(const InputActionT i) restrict2
ki2.value = -1;
}
const InputActionData &restrict kd =
- inputActionData[static_cast<size_t>(i)];
+ inputActionData[CAST_SIZE(i)];
InputItem &restrict val0 = key.values[0];
val0.type = kd.defaultType1;
InputItem &restrict val1 = key.values[1];
@@ -263,7 +263,7 @@ void InputManager::resetKey(const InputActionT i) restrict2
void InputManager::resetKeys() restrict2
{
- for (int i = 0; i < static_cast<int>(InputAction::TOTAL); i++)
+ for (int i = 0; i < CAST_S32(InputAction::TOTAL); i++)
resetKey(static_cast<InputActionT>(i));
}
@@ -283,7 +283,7 @@ bool InputManager::hasConflicts(InputActionT &restrict key1,
* No need to parse the square matrix: only check one triangle
* that's enough to detect conflicts
*/
- for (int i = 0; i < static_cast<int>(InputAction::TOTAL); i++)
+ for (int i = 0; i < CAST_S32(InputAction::TOTAL); i++)
{
const InputActionData &restrict kdi = inputActionData[i];
if (!*kdi.configField)
@@ -297,7 +297,7 @@ bool InputManager::hasConflicts(InputActionT &restrict key1,
continue;
size_t j;
- for (j = i, j++; j < static_cast<int>(InputAction::TOTAL); j++)
+ for (j = i, j++; j < CAST_S32(InputAction::TOTAL); j++)
{
if ((kdi.grp & inputActionData[j].grp) == 0
|| !*kdi.configField)
@@ -338,7 +338,7 @@ bool InputManager::isActionActive(const InputActionT index) const restrict2
return false;
const InputActionData &restrict key =
- inputActionData[static_cast<size_t>(index)];
+ inputActionData[CAST_SIZE(index)];
// logger->log("isActionActive mask=%d, condition=%d, index=%d",
// mMask, key.condition, index);
if ((key.condition & mMask) != key.condition)
@@ -357,16 +357,16 @@ bool InputManager::isActionActive0(const InputActionT index)
InputFunction &InputManager::getKey(InputActionT index) restrict2
{
- if (static_cast<int>(index) < 0 || index >= InputAction::TOTAL)
+ if (CAST_S32(index) < 0 || index >= InputAction::TOTAL)
index = InputAction::MOVE_UP;
- return mKey[static_cast<size_t>(index)];
+ return mKey[CAST_SIZE(index)];
}
std::string InputManager::getKeyStringLong(const InputActionT index) const
restrict2
{
std::string keyStr;
- const InputFunction &restrict ki = mKey[static_cast<size_t>(index)];
+ const InputFunction &restrict ki = mKey[CAST_SIZE(index)];
for (size_t i = 0; i < inputFunctionSize; i ++)
{
@@ -410,7 +410,7 @@ std::string InputManager::getKeyValueString(const InputActionT index) const
restrict2
{
std::string keyStr;
- const InputFunction &restrict ki = mKey[static_cast<size_t>(index)];
+ const InputFunction &restrict ki = mKey[CAST_SIZE(index)];
for (size_t i = 0; i < inputFunctionSize; i ++)
{
@@ -475,18 +475,18 @@ void InputManager::addActionKey(const InputActionT action,
const InputTypeT type,
const int val) restrict2
{
- if (static_cast<int>(action) < 0 || action >= InputAction::TOTAL)
+ if (CAST_S32(action) < 0 || action >= InputAction::TOTAL)
return;
int idx = -1;
- InputFunction &restrict key = mKey[static_cast<size_t>(action)];
+ InputFunction &restrict key = mKey[CAST_SIZE(action)];
for (size_t i = 0; i < inputFunctionSize; i ++)
{
const InputItem &restrict val2 = key.values[i];
if (val2.type == InputType::UNKNOWN ||
(val2.type == type && val2.value == val))
{
- idx = static_cast<int>(i);
+ idx = CAST_S32(i);
break;
}
}
@@ -523,7 +523,7 @@ void InputManager::setNewKey(const SDL_Event &event,
void InputManager::unassignKey() restrict2
{
- InputFunction &restrict key = mKey[static_cast<size_t>(mNewKeyIndex)];
+ InputFunction &restrict key = mKey[CAST_SIZE(mNewKeyIndex)];
for (size_t i = 0; i < inputFunctionSize; i ++)
{
InputItem &restrict val = key.values[i];
@@ -796,7 +796,7 @@ bool InputManager::invokeKey(const InputActionData *restrict const key,
{
InputEvent evt(keyNum, mMask);
ActionFuncPtr func = *(inputActionData[
- static_cast<size_t>(keyNum)].action);
+ CAST_SIZE(keyNum)].action);
if (func && func(evt))
return true;
}
@@ -809,7 +809,7 @@ void InputManager::executeAction(const InputActionT keyNum) restrict2
return;
InputEvent evt(keyNum, mMask);
- ActionFuncPtr func = *(inputActionData[static_cast<size_t>(
+ ActionFuncPtr func = *(inputActionData[CAST_SIZE(
keyNum)].action);
if (func)
func(evt);
@@ -859,9 +859,9 @@ bool InputManager::executeChatCommand(const InputActionT keyNum,
const std::string &restrict args,
ChatTab *restrict const tab) restrict2
{
- if (static_cast<int>(keyNum) < 0 || keyNum >= InputAction::TOTAL)
+ if (CAST_S32(keyNum) < 0 || keyNum >= InputAction::TOTAL)
return false;
- ActionFuncPtr func = *(inputActionData[static_cast<size_t>(
+ ActionFuncPtr func = *(inputActionData[CAST_SIZE(
keyNum)].action);
if (func)
{
@@ -880,7 +880,7 @@ void InputManager::updateKeyActionMap(KeyToActionMap &restrict actionMap,
actionMap.clear();
keyTimeMap.clear();
- for (size_t i = 0; i < static_cast<size_t>(InputAction::TOTAL); i ++)
+ for (size_t i = 0; i < CAST_SIZE(InputAction::TOTAL); i ++)
{
const InputFunction &restrict key = mKey[i];
const InputActionData &restrict kd = inputActionData[i];
@@ -936,10 +936,10 @@ bool InputManager::triggerAction(const KeysVector *restrict const ptrs)
FOR_EACHP (KeysVectorCIter, it, ptrs)
{
const InputActionT keyNum = *it;
- if (static_cast<int>(keyNum) < 0 || keyNum >= InputAction::TOTAL)
+ if (CAST_S32(keyNum) < 0 || keyNum >= InputAction::TOTAL)
continue;
- if (invokeKey(&inputActionData[static_cast<size_t>(keyNum)], keyNum))
+ if (invokeKey(&inputActionData[CAST_SIZE(keyNum)], keyNum))
return true;
}
return false;
@@ -949,7 +949,7 @@ InputActionT InputManager::getKeyIndex(const int value,
const int grp,
const InputTypeT type) const restrict2
{
- for (size_t i = 0; i < static_cast<size_t>(InputAction::TOTAL); i++)
+ for (size_t i = 0; i < CAST_SIZE(InputAction::TOTAL); i++)
{
const InputFunction &restrict key = mKey[i];
const InputActionData &restrict kd = inputActionData[i];
@@ -973,8 +973,8 @@ InputActionT InputManager::getActionByKey(const SDL_Event &restrict event)
if (event.type == SDL_KEYDOWN || event.type == SDL_KEYUP)
{
const InputActionT idx = keyboard.getActionId(event);
- if (static_cast<int>(idx) >= 0 &&
- checkKey(&inputActionData[static_cast<size_t>(idx)]))
+ if (CAST_S32(idx) >= 0 &&
+ checkKey(&inputActionData[CAST_SIZE(idx)]))
{
return idx;
}
@@ -985,7 +985,7 @@ InputActionT InputManager::getActionByKey(const SDL_Event &restrict event)
void InputManager::addChatCommands(std::list<std::string> &restrict arr)
restrict
{
- const int sz = static_cast<int>(InputAction::TOTAL);
+ const int sz = CAST_S32(InputAction::TOTAL);
for (int i = 0; i < sz; i++)
{
const InputActionData &restrict ad = inputActionData[i];
diff --git a/src/input/inputmanager.h b/src/input/inputmanager.h
index 306de4df6..8b2d3ae84 100644
--- a/src/input/inputmanager.h
+++ b/src/input/inputmanager.h
@@ -170,7 +170,7 @@ class InputManager final
StringInpActionMap mNameMap;
StringIntMap mChatMap;
- InputFunction mKey[static_cast<size_t>(InputAction::TOTAL)];
+ InputFunction mKey[CAST_SIZE(InputAction::TOTAL)];
};
extern InputManager inputManager;
diff --git a/src/input/keyboardconfig.cpp b/src/input/keyboardconfig.cpp
index 9c82dd0d0..2c821807b 100644
--- a/src/input/keyboardconfig.cpp
+++ b/src/input/keyboardconfig.cpp
@@ -65,7 +65,7 @@ int KeyboardConfig::getKeyValueFromEvent(const SDL_Event &event)
return event.key.keysym.scancode;
#else
if (event.key.keysym.sym)
- return static_cast<int>(event.key.keysym.sym);
+ return CAST_S32(event.key.keysym.sym);
else if (event.key.keysym.scancode > 1)
return -event.key.keysym.scancode;
return 0;
@@ -98,7 +98,7 @@ std::string KeyboardConfig::getKeyName(const int key)
}
// TRANSLATORS: long key name, should be short
- return strprintf(_("key_%d"), static_cast<int>(key));
+ return strprintf(_("key_%d"), CAST_S32(key));
}
std::string KeyboardConfig::getKeyShortString(const std::string &key)
@@ -266,7 +266,7 @@ void KeyboardConfig::handleRepeat(const int time)
{
int &keyTime = (*it).second;
if (time > keyTime && abs(time - keyTime)
- > static_cast<signed>(mRepeatTime))
+ > CAST_S32(mRepeatTime))
{
keyTime = time;
inputManager.triggerAction(getActionVectorByKey(key));
diff --git a/src/input/touch/touchmanager.cpp b/src/input/touch/touchmanager.cpp
index e0c08b16c..5c7de8189 100644
--- a/src/input/touch/touchmanager.cpp
+++ b/src/input/touch/touchmanager.cpp
@@ -328,12 +328,12 @@ bool TouchManager::processEvent(const MouseInput &mouseInput) restrict2
bool TouchManager::isActionActive(const InputActionT index) restrict2 const
{
- if (static_cast<int>(index) < 0 ||
- static_cast<int>(index) >= actionsSize)
+ if (CAST_S32(index) < 0 ||
+ CAST_S32(index) >= actionsSize)
{
return false;
}
- return mActions[static_cast<size_t>(index)];
+ return mActions[CAST_SIZE(index)];
}
void TouchManager::resize(const int width, const int height) restrict2
diff --git a/src/input/touch/touchmanager.h b/src/input/touch/touchmanager.h
index 3e88c4f6a..676167e13 100644
--- a/src/input/touch/touchmanager.h
+++ b/src/input/touch/touchmanager.h
@@ -38,7 +38,7 @@ class MouseInput;
typedef void (*TouchFuncPtr) (const MouseInput &restrict mouseInput);
-const int actionsSize = static_cast<int>(InputAction::TOTAL);
+const int actionsSize = CAST_S32(InputAction::TOTAL);
const int buttonsCount = 12;
struct TouchItem final
@@ -145,10 +145,10 @@ class TouchManager final : public ConfigListener
void setActionActive(const InputActionT index,
const bool value) restrict2
{
- if (static_cast<int>(index) >= 0 &&
- static_cast<int>(index) < actionsSize)
+ if (CAST_S32(index) >= 0 &&
+ CAST_S32(index) < actionsSize)
{
- mActions[static_cast<size_t>(index)] = value;
+ mActions[CAST_SIZE(index)] = value;
}
}
diff --git a/src/localconsts.h b/src/localconsts.h
index 3d6864042..62c6bcfbe 100644
--- a/src/localconsts.h
+++ b/src/localconsts.h
@@ -33,6 +33,15 @@
#endif
#endif
+#define CAST_8 static_cast<char>
+#define CAST_S8 static_cast<int8_t>
+#define CAST_U8 static_cast<uint8_t>
+#define CAST_S16 static_cast<int16_t>
+#define CAST_U16 static_cast<uint16_t>
+#define CAST_S32 static_cast<int32_t>
+#define CAST_U32 static_cast<uint32_t>
+#define CAST_SIZE static_cast<size_t>
+
#define GCC_VERSION (__GNUC__ * 10000 \
+ __GNUC_MINOR__ * 100 \
+ __GNUC_PATCHLEVEL__)
diff --git a/src/logger.cpp b/src/logger.cpp
index 3ec26a6db..5b8b7819b 100644
--- a/src/logger.cpp
+++ b/src/logger.cpp
@@ -72,16 +72,16 @@
#define DATESTREAM \
timeStr << "[" \
<< ((((tv.tv_sec / 60) / 60) % 24 < 10) ? "0" : "") \
- << static_cast<int>(((tv.tv_sec / 60) / 60) % 24) \
+ << CAST_S32(((tv.tv_sec / 60) / 60) % 24) \
<< ":" \
<< (((tv.tv_sec / 60) % 60 < 10) ? "0" : "") \
- << static_cast<int>((tv.tv_sec / 60) % 60) \
+ << CAST_S32((tv.tv_sec / 60) % 60) \
<< ":" \
<< ((tv.tv_sec % 60 < 10) ? "0" : "") \
- << static_cast<int>(tv.tv_sec % 60) \
+ << CAST_S32(tv.tv_sec % 60) \
<< "." \
<< (((tv.tv_usec / 10000) % 100) < 10 ? "0" : "") \
- << static_cast<int>((tv.tv_usec / 10000) % 100) \
+ << CAST_S32((tv.tv_usec / 10000) % 100) \
<< "] ";
Logger *logger = nullptr; // Log object
@@ -234,9 +234,9 @@ void Logger::log(const char *const log_text, ...)
unsigned size = 1024;
if (strlen(log_text) * 3 > size)
- size = static_cast<unsigned>(strlen(log_text) * 3);
+ size = CAST_U32(strlen(log_text) * 3);
- char* buf = new char[static_cast<size_t>(size + 1)];
+ char* buf = new char[CAST_SIZE(size + 1)];
va_list ap;
// Use a temporary buffer to fill in the variables
@@ -273,9 +273,9 @@ void Logger::log_r(const char *const log_text, ...)
unsigned size = 1024;
if (strlen(log_text) * 3 > size)
- size = static_cast<unsigned>(strlen(log_text) * 3);
+ size = CAST_U32(strlen(log_text) * 3);
- char* buf = new char[static_cast<size_t>(size + 1)];
+ char* buf = new char[CAST_SIZE(size + 1)];
va_list ap;
// Use a temporary buffer to fill in the variables
@@ -384,7 +384,7 @@ void Logger::unimplimented(const int id)
return;
const std::string str = strprintf("Unimplimented packet: %d (0x%x)",
- id, static_cast<unsigned int>(id));
+ id, CAST_U32(id));
DebugMessageListener::distributeEvent(str);
log(str);
}
diff --git a/src/mumblemanager.cpp b/src/mumblemanager.cpp
index 7b38d4c73..c55f3dd26 100644
--- a/src/mumblemanager.cpp
+++ b/src/mumblemanager.cpp
@@ -70,7 +70,7 @@ uint16_t MumbleManager::getMapId(std::string mapName)
else
{
mapName = mapName.substr(0, 3) + mapName[4];
- res = static_cast<uint16_t>(atoi(mapName.c_str()));
+ res = CAST_U16(atoi(mapName.c_str()));
}
return res;
}
@@ -280,7 +280,7 @@ void MumbleManager::setServer(const std::string &serverName)
if (!mLinkedMem)
return;
- unsigned size = static_cast<unsigned>(serverName.size());
+ unsigned size = CAST_U32(serverName.size());
if (size > sizeof(mLinkedMemCache.context) - 1)
size = sizeof(mLinkedMemCache.context) - 1;
diff --git a/src/net/download.cpp b/src/net/download.cpp
index dd3b9eaeb..209b6085e 100644
--- a/src/net/download.cpp
+++ b/src/net/download.cpp
@@ -144,7 +144,7 @@ unsigned long Download::fadler32(FILE *const file)
rewind(file);
// Calculate Adler-32 checksum
- char *const buffer = new char[static_cast<size_t>(fileSize)];
+ char *const buffer = new char[CAST_SIZE(fileSize)];
const uInt read = static_cast<uInt>(fread(buffer, 1, fileSize, file));
unsigned long adler = adler32(0L, Z_NULL, 0);
adler = adler32(static_cast<uInt>(adler),
@@ -242,13 +242,13 @@ int Download::downloadProgress(void *clientp, double dltotal, double dlnow,
if (d->mOptions.cancel)
{
return d->mUpdateFunction(d->mPtr, DownloadStatus::Cancelled,
- static_cast<size_t>(dltotal),
- static_cast<size_t>(dlnow));
+ CAST_SIZE(dltotal),
+ CAST_SIZE(dlnow));
}
return d->mUpdateFunction(d->mPtr, DownloadStatus::Idle,
- static_cast<size_t>(dltotal),
- static_cast<size_t>(dlnow));
+ CAST_SIZE(dltotal),
+ CAST_SIZE(dlnow));
}
int Download::downloadThread(void *ptr)
diff --git a/src/net/ea/guildrecv.cpp b/src/net/ea/guildrecv.cpp
index af215876c..f952ae2d2 100644
--- a/src/net/ea/guildrecv.cpp
+++ b/src/net/ea/guildrecv.cpp
@@ -141,7 +141,7 @@ void GuildRecv::processGuildBasicInfo(Net::MessageIn &msg)
castle.c_str()), ChatMsgType::BY_SERVER);
}
- Guild *const g = Guild::getGuild(static_cast<int16_t>(guildId));
+ Guild *const g = Guild::getGuild(CAST_S16(guildId));
if (!g)
return;
g->setName(name);
@@ -200,7 +200,7 @@ void GuildRecv::processGuildMemberList(Net::MessageIn &msg)
m->setOnline(online);
m->setID(id);
m->setCharId(charId);
- m->setGender(Being::intToGender(static_cast<uint8_t>(gender)));
+ m->setGender(Being::intToGender(CAST_U8(gender)));
m->setLevel(level);
m->setExp(exp);
m->setPos(pos);
diff --git a/src/net/ea/inventoryrecv.cpp b/src/net/ea/inventoryrecv.cpp
index d1f43d0bb..f1593bf51 100644
--- a/src/net/ea/inventoryrecv.cpp
+++ b/src/net/ea/inventoryrecv.cpp
@@ -232,7 +232,7 @@ int InventoryRecv::getSlot(const int eAthenaSlot)
mask <<= 1;
position++;
}
- return static_cast<int>(EQUIP_POINTS[position]);
+ return CAST_S32(EQUIP_POINTS[position]);
}
} // namespace Ea
diff --git a/src/net/ea/loginhandler.cpp b/src/net/ea/loginhandler.cpp
index 3119b0ab6..20034f9f8 100644
--- a/src/net/ea/loginhandler.cpp
+++ b/src/net/ea/loginhandler.cpp
@@ -76,7 +76,7 @@ void LoginHandler::loginAccount(LoginData *const loginData1) const
void LoginHandler::chooseServer(const unsigned int server,
const bool persistentIp) const
{
- if (static_cast<size_t>(server) >= LoginRecv::mWorlds.size() ||
+ if (CAST_SIZE(server) >= LoginRecv::mWorlds.size() ||
!LoginRecv::mWorlds[server])
{
return;
diff --git a/src/net/ea/loginrecv.cpp b/src/net/ea/loginrecv.cpp
index 4b25c80d6..84899476b 100644
--- a/src/net/ea/loginrecv.cpp
+++ b/src/net/ea/loginrecv.cpp
@@ -82,7 +82,7 @@ void LoginRecv::processLoginData(Net::MessageIn &msg)
msg.readInt16("unused");
// reserve bits for future usage
- mToken.sex = Being::intToGender(static_cast<uint8_t>(
+ mToken.sex = Being::intToGender(CAST_U8(
msg.readUInt8("gender") & 3U));
for (int i = 0; i < worldCount; i++)
@@ -109,7 +109,7 @@ void LoginRecv::processLoginData(Net::MessageIn &msg)
void LoginRecv::processLoginError(Net::MessageIn &msg)
{
const uint8_t code = msg.readUInt8("error");
- logger->log("Login::error code: %u", static_cast<unsigned int>(code));
+ logger->log("Login::error code: %u", CAST_U32(code));
std::string date = msg.readString(20, "date");
switch (code)
diff --git a/src/net/ea/network.cpp b/src/net/ea/network.cpp
index 66115b789..9efc807c7 100644
--- a/src/net/ea/network.cpp
+++ b/src/net/ea/network.cpp
@@ -165,7 +165,7 @@ void Network::flush()
toString(mOutSize)).append(" bytes"));
}
*/
- if (ret < static_cast<int>(mOutSize))
+ if (ret < CAST_S32(mOutSize))
{
SDL_mutexV(mMutexOut);
setError("Error in TcpNet::send(): " +
@@ -188,7 +188,7 @@ void Network::skip(const int len)
if (mInSize >= mToSkip)
{
mInSize -= mToSkip;
- memmove(mInBuffer, mInBuffer + static_cast<size_t>(mToSkip), mInSize);
+ memmove(mInBuffer, mInBuffer + CAST_SIZE(mToSkip), mInSize);
mToSkip = 0;
}
else
@@ -258,7 +258,7 @@ void Network::receive()
while (mState == CONNECTED)
{
const int numReady = TcpNet::checkSockets(
- set, (static_cast<uint32_t>(500)));
+ set, (CAST_U32(500)));
switch (numReady)
{
case -1:
@@ -280,7 +280,7 @@ void Network::receive()
}
const int ret = TcpNet::recv(mSocket,
- mInBuffer + static_cast<size_t>(mInSize),
+ mInBuffer + CAST_SIZE(mInSize),
BUFFER_SIZE - mInSize);
if (!ret)
@@ -305,7 +305,7 @@ void Network::receive()
{
mInSize -= mToSkip;
memmove(mInBuffer,
- mInBuffer + static_cast<size_t>(mToSkip),
+ mInBuffer + CAST_SIZE(mToSkip),
mInSize);
mToSkip = 0;
}
@@ -348,10 +348,10 @@ uint16_t Network::readWord(const int pos) const
{
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
return SDL_Swap16(*reinterpret_cast<uint16_t*>(
- mInBuffer + static_cast<size_t>(pos)));
+ mInBuffer + CAST_SIZE(pos)));
#else
return (*reinterpret_cast<uint16_t*>(
- mInBuffer + static_cast<size_t>(pos)));
+ mInBuffer + CAST_SIZE(pos)));
#endif
}
diff --git a/src/net/ea/npcrecv.cpp b/src/net/ea/npcrecv.cpp
index c447fd5c5..89bacfd2d 100644
--- a/src/net/ea/npcrecv.cpp
+++ b/src/net/ea/npcrecv.cpp
@@ -173,7 +173,7 @@ void NpcRecv::processNpcCommand(Net::MessageIn &msg)
{
mDialog->setAvatarDirection(
Net::MessageIn::fromServerDirection(
- static_cast<uint8_t>(id)));
+ CAST_U8(id)));
}
break;
case 8: // set avatar action
diff --git a/src/net/eathena/adminhandler.cpp b/src/net/eathena/adminhandler.cpp
index 14afde54c..6c7914a32 100644
--- a/src/net/eathena/adminhandler.cpp
+++ b/src/net/eathena/adminhandler.cpp
@@ -45,15 +45,15 @@ AdminHandler::AdminHandler() :
void AdminHandler::announce(const std::string &text) const
{
createOutPacket(CMSG_ADMIN_ANNOUNCE);
- outMsg.writeInt16(static_cast<int16_t>(text.length() + 4), "len");
- outMsg.writeString(text, static_cast<int>(text.length()), "message");
+ outMsg.writeInt16(CAST_S16(text.length() + 4), "len");
+ outMsg.writeString(text, CAST_S32(text.length()), "message");
}
void AdminHandler::localAnnounce(const std::string &text) const
{
createOutPacket(CMSG_ADMIN_LOCAL_ANNOUNCE);
- outMsg.writeInt16(static_cast<int16_t>(text.length() + 4), "len");
- outMsg.writeString(text, static_cast<int>(text.length()), "message");
+ outMsg.writeInt16(CAST_S16(text.length() + 4), "len");
+ outMsg.writeString(text, CAST_S32(text.length()), "message");
}
void AdminHandler::hide(const bool h A_UNUSED) const
@@ -77,8 +77,8 @@ void AdminHandler::warp(const std::string &map, const int x, const int y) const
{
createOutPacket(CMSG_PLAYER_MAPMOVE);
outMsg.writeString(map, 16, "map");
- outMsg.writeInt16(static_cast<int16_t>(x), "x");
- outMsg.writeInt16(static_cast<int16_t>(y), "y");
+ outMsg.writeInt16(CAST_S16(x), "x");
+ outMsg.writeInt16(CAST_S16(y), "y");
}
void AdminHandler::resetStats() const
@@ -114,8 +114,8 @@ void AdminHandler::mute(const Being *const being,
createOutPacket(CMSG_ADMIN_MUTE);
outMsg.writeBeingId(being->getId(), "account id");
- outMsg.writeInt8(static_cast<int8_t>(type), "type");
- outMsg.writeInt16(static_cast<int16_t>(limit), "value");
+ outMsg.writeInt8(CAST_S8(type), "type");
+ outMsg.writeInt16(CAST_S16(limit), "value");
}
void AdminHandler::muteName(const std::string &name) const
@@ -137,9 +137,9 @@ void AdminHandler::setTileType(const int x, const int y,
const int type) const
{
createOutPacket(CMSG_ADMIN_SET_TILE_TYPE);
- outMsg.writeInt16(static_cast<int16_t>(x), "x");
- outMsg.writeInt16(static_cast<int16_t>(y), "y");
- outMsg.writeInt16(static_cast<int16_t>(type), "type");
+ outMsg.writeInt16(CAST_S16(x), "x");
+ outMsg.writeInt16(CAST_S16(y), "y");
+ outMsg.writeInt16(CAST_S16(type), "type");
}
void AdminHandler::unequipAll(const Being *const being) const
diff --git a/src/net/eathena/auctionhandler.cpp b/src/net/eathena/auctionhandler.cpp
index fdd5e901f..fb9731c95 100644
--- a/src/net/eathena/auctionhandler.cpp
+++ b/src/net/eathena/auctionhandler.cpp
@@ -51,7 +51,7 @@ void AuctionHandler::setItem(const Item *const item,
if (!item)
return;
createOutPacket(CMSG_AUCTION_SET_ITEM);
- outMsg.writeInt16(static_cast<int16_t>(
+ outMsg.writeInt16(CAST_S16(
item->getInvIndex() + INVENTORY_OFFSET), "index");
outMsg.writeInt32(amount, "amount"); // always 1
}
@@ -92,10 +92,10 @@ void AuctionHandler::search(const AuctionSearchTypeT type,
const int page) const
{
createOutPacket(CMSG_AUCTION_SEARCH);
- outMsg.writeInt16(static_cast<int16_t>(type), "search type");
+ outMsg.writeInt16(CAST_S16(type), "search type");
outMsg.writeInt32(auctionId, "auction id");
outMsg.writeString(text, 24, "search text");
- outMsg.writeInt16(static_cast<int16_t>(page), "page");
+ outMsg.writeInt16(CAST_S16(page), "page");
}
void AuctionHandler::buy() const
diff --git a/src/net/eathena/bankrecv.cpp b/src/net/eathena/bankrecv.cpp
index 6a0670229..bea7a01df 100644
--- a/src/net/eathena/bankrecv.cpp
+++ b/src/net/eathena/bankrecv.cpp
@@ -35,7 +35,7 @@ namespace EAthena
void BankRecv::processBankStatus(Net::MessageIn &msg)
{
- const int money = static_cast<int>(msg.readInt64("money"));
+ const int money = CAST_S32(msg.readInt64("money"));
msg.readInt16("reason");
BankListener::distributeEvent(money);
}
@@ -43,7 +43,7 @@ void BankRecv::processBankStatus(Net::MessageIn &msg)
void BankRecv::processBankDeposit(Net::MessageIn &msg)
{
const int reason = msg.readInt16("reason");
- const int money = static_cast<int>(msg.readInt64("money"));
+ const int money = CAST_S32(msg.readInt64("money"));
msg.readInt32("balance");
BankListener::distributeEvent(money);
if (reason)
@@ -53,7 +53,7 @@ void BankRecv::processBankDeposit(Net::MessageIn &msg)
void BankRecv::processBankWithdraw(Net::MessageIn &msg)
{
const int reason = msg.readInt16("reason");
- const int money = static_cast<int>(msg.readInt64("money"));
+ const int money = CAST_S32(msg.readInt64("money"));
msg.readInt32("balance");
BankListener::distributeEvent(money);
if (reason)
diff --git a/src/net/eathena/battlegroundhandler.cpp b/src/net/eathena/battlegroundhandler.cpp
index fa3c2d337..723ab3bfe 100644
--- a/src/net/eathena/battlegroundhandler.cpp
+++ b/src/net/eathena/battlegroundhandler.cpp
@@ -39,7 +39,7 @@ void BattleGroundHandler::registerBg(const BattleGroundTypeT &type,
const std::string &name) const
{
createOutPacket(CMSG_BATTLE_REGISTER);
- outMsg.writeInt16(static_cast<int16_t>(type), "type");
+ outMsg.writeInt16(CAST_S16(type), "type");
outMsg.writeString(name, 24, "bg name");
}
@@ -54,7 +54,7 @@ void BattleGroundHandler::beginAck(const bool result,
const std::string &gameName) const
{
createOutPacket(CMSG_BATTLE_BEGIN_ACK);
- outMsg.writeInt8(static_cast<int8_t>(result ? 1 : 0), "result");
+ outMsg.writeInt8(CAST_S8(result ? 1 : 0), "result");
outMsg.writeString(bgName, 24, "bg name");
outMsg.writeString(gameName, 24, "game name");
}
diff --git a/src/net/eathena/beinghandler.cpp b/src/net/eathena/beinghandler.cpp
index bfb72e911..143d7dc9e 100644
--- a/src/net/eathena/beinghandler.cpp
+++ b/src/net/eathena/beinghandler.cpp
@@ -69,7 +69,7 @@ void BeingHandler::undress(Being *const being) const
void BeingHandler::requestRanks(const RankT rank) const
{
createOutPacket(CMSG_REQUEST_RANKS);
- outMsg.writeInt16(static_cast<int16_t>(rank), "type");
+ outMsg.writeInt16(CAST_S16(rank), "type");
}
void BeingHandler::viewPlayerEquipment(const Being *const being)
diff --git a/src/net/eathena/beingrecv.cpp b/src/net/eathena/beingrecv.cpp
index 816b8913b..88db63c8f 100644
--- a/src/net/eathena/beingrecv.cpp
+++ b/src/net/eathena/beingrecv.cpp
@@ -189,7 +189,7 @@ void BeingRecv::processBeingChangeLookContinue(Net::MessageIn &msg,
fromInt(id, ItemColor)));
break;
case 7: // Clothes color. Now used as look
- dstBeing->setLook(static_cast<uint8_t>(id));
+ dstBeing->setLook(CAST_U8(id));
break;
case 8: // eAthena LOOK_SHIELD
dstBeing->setSprite(SPRITE_FLOOR, id, color, itemColor);
@@ -271,7 +271,7 @@ void BeingRecv::processBeingVisible(Net::MessageIn &msg)
const uint16_t stunMode = msg.readInt16("opt1");
// probably wrong effect usage
uint32_t statusEffects = msg.readInt16("opt2");
- statusEffects |= (static_cast<uint32_t>(msg.readInt32("option"))) << 16;
+ statusEffects |= (CAST_U32(msg.readInt32("option"))) << 16;
const int16_t job = msg.readInt16("class");
Being *dstBeing = actorManager->findBeing(id);
@@ -324,7 +324,7 @@ void BeingRecv::processBeingVisible(Net::MessageIn &msg)
localPlayer->checkNewName(dstBeing);
const int hairStyle = msg.readInt16("hair style");
- const uint32_t weapon = static_cast<uint32_t>(msg.readInt32("weapon"));
+ const uint32_t weapon = CAST_U32(msg.readInt32("weapon"));
const uint16_t headBottom = msg.readInt16("head bottom");
const uint16_t headTop = msg.readInt16("head top");
@@ -339,10 +339,10 @@ void BeingRecv::processBeingVisible(Net::MessageIn &msg)
msg.readInt32("guild id");
msg.readInt16("guild emblem");
dstBeing->setManner(msg.readInt16("manner"));
- dstBeing->setStatusEffectBlock(32, static_cast<uint16_t>(
+ dstBeing->setStatusEffectBlock(32, CAST_U16(
msg.readInt32("opt3")));
dstBeing->setKarma(msg.readUInt8("karma"));
- uint8_t gender = static_cast<uint8_t>(msg.readUInt8("gender") & 3);
+ uint8_t gender = CAST_U8(msg.readUInt8("gender") & 3);
if (dstBeing->getType() == ActorType::Player)
{
@@ -390,7 +390,7 @@ void BeingRecv::processBeingVisible(Net::MessageIn &msg)
dstBeing->setDirection(dir);
- const int level = static_cast<int>(msg.readInt16("level"));
+ const int level = CAST_S32(msg.readInt16("level"));
if (level)
dstBeing->setLevel(level);
msg.readInt16("font");
@@ -405,9 +405,9 @@ void BeingRecv::processBeingVisible(Net::MessageIn &msg)
msg.readInt16("body2");
dstBeing->setStunMode(stunMode);
- dstBeing->setStatusEffectBlock(0, static_cast<uint16_t>(
+ dstBeing->setStatusEffectBlock(0, CAST_U16(
(statusEffects >> 16) & 0xffffU));
- dstBeing->setStatusEffectBlock(16, static_cast<uint16_t>(
+ dstBeing->setStatusEffectBlock(16, CAST_U16(
statusEffects & 0xffffU));
}
@@ -443,7 +443,7 @@ void BeingRecv::processBeingMove(Net::MessageIn &msg)
// msg.readInt16("body state");
// msg.readInt16("health state");
// }
- statusEffects |= (static_cast<uint32_t>(msg.readInt32("option"))) << 16;
+ statusEffects |= (CAST_U32(msg.readInt32("option"))) << 16;
const int16_t job = msg.readInt16("class");
Being *dstBeing = actorManager->findBeing(id);
@@ -488,7 +488,7 @@ void BeingRecv::processBeingMove(Net::MessageIn &msg)
localPlayer->checkNewName(dstBeing);
const int hairStyle = msg.readInt16("hair style");
- const uint32_t weapon = static_cast<uint32_t>(msg.readInt32("weapon"));
+ const uint32_t weapon = CAST_U32(msg.readInt32("weapon"));
const uint16_t headBottom = msg.readInt16("head bottom");
msg.readInt32("tick");
@@ -505,10 +505,10 @@ void BeingRecv::processBeingMove(Net::MessageIn &msg)
msg.readInt32("guild id");
msg.readInt16("guild emblem");
dstBeing->setManner(msg.readInt16("manner"));
- dstBeing->setStatusEffectBlock(32, static_cast<uint16_t>(
+ dstBeing->setStatusEffectBlock(32, CAST_U16(
msg.readInt32("opt3")));
dstBeing->setKarma(msg.readUInt8("karma"));
- uint8_t gender = static_cast<uint8_t>(msg.readUInt8("gender") & 3);
+ uint8_t gender = CAST_U8(msg.readUInt8("gender") & 3);
if (dstBeing->getType() == ActorType::Player)
{
@@ -568,7 +568,7 @@ void BeingRecv::processBeingMove(Net::MessageIn &msg)
if (d && dstBeing->getDirection() != d)
dstBeing->setDirection(d);
- const int level = static_cast<int>(msg.readInt16("level"));
+ const int level = CAST_S32(msg.readInt16("level"));
if (level)
dstBeing->setLevel(level);
msg.readInt16("font");
@@ -583,9 +583,9 @@ void BeingRecv::processBeingMove(Net::MessageIn &msg)
msg.readInt16("body2");
dstBeing->setStunMode(stunMode);
- dstBeing->setStatusEffectBlock(0, static_cast<uint16_t>(
+ dstBeing->setStatusEffectBlock(0, CAST_U16(
(statusEffects >> 16) & 0xffffU));
- dstBeing->setStatusEffectBlock(16, static_cast<uint16_t>(
+ dstBeing->setStatusEffectBlock(16, CAST_U16(
statusEffects & 0xffffU));
}
@@ -617,7 +617,7 @@ void BeingRecv::processBeingSpawn(Net::MessageIn &msg)
// msg.readInt16("body state");
// msg.readInt16("health state");
// }
- statusEffects |= (static_cast<uint32_t>(msg.readInt32("option"))) << 16;
+ statusEffects |= (CAST_U32(msg.readInt32("option"))) << 16;
const int16_t job = msg.readInt16("class");
Being *dstBeing = actorManager->findBeing(id);
@@ -662,7 +662,7 @@ void BeingRecv::processBeingSpawn(Net::MessageIn &msg)
localPlayer->checkNewName(dstBeing);
const int hairStyle = msg.readInt16("hair style");
- const uint32_t weapon = static_cast<uint32_t>(msg.readInt32("weapon"));
+ const uint32_t weapon = CAST_U32(msg.readInt32("weapon"));
const uint16_t headBottom = msg.readInt16("head bottom");
const uint16_t headTop = msg.readInt16("head top");
@@ -676,10 +676,10 @@ void BeingRecv::processBeingSpawn(Net::MessageIn &msg)
msg.readInt32("guild id");
msg.readInt16("guild emblem");
dstBeing->setManner(msg.readInt16("manner"));
- dstBeing->setStatusEffectBlock(32, static_cast<uint16_t>(
+ dstBeing->setStatusEffectBlock(32, CAST_U16(
msg.readInt32("opt3")));
dstBeing->setKarma(msg.readUInt8("karma"));
- uint8_t gender = static_cast<uint8_t>(msg.readUInt8("gender") & 3);
+ uint8_t gender = CAST_U8(msg.readUInt8("gender") & 3);
if (dstBeing->getType() == ActorType::Player)
{
@@ -726,7 +726,7 @@ void BeingRecv::processBeingSpawn(Net::MessageIn &msg)
dstBeing->setDirection(dir);
- const int level = static_cast<int>(msg.readInt16("level"));
+ const int level = CAST_S32(msg.readInt16("level"));
if (level)
dstBeing->setLevel(level);
msg.readInt16("font");
@@ -741,9 +741,9 @@ void BeingRecv::processBeingSpawn(Net::MessageIn &msg)
msg.readInt16("body2");
dstBeing->setStunMode(stunMode);
- dstBeing->setStatusEffectBlock(0, static_cast<uint16_t>(
+ dstBeing->setStatusEffectBlock(0, CAST_U16(
(statusEffects >> 16) & 0xffffU));
- dstBeing->setStatusEffectBlock(16, static_cast<uint16_t>(
+ dstBeing->setStatusEffectBlock(16, CAST_U16(
statusEffects & 0xffffU));
}
@@ -755,7 +755,7 @@ void BeingRecv::processMapTypeProperty(Net::MessageIn &msg)
{
// +++ need get other flags from here
MapTypeProperty2 props;
- props.data = static_cast<uint32_t>(flags);
+ props.data = CAST_U32(flags);
Game *const game = Game::instance();
if (!game)
return;
@@ -1103,7 +1103,7 @@ void BeingRecv::processBeingChangeDirection(Net::MessageIn &msg)
msg.readInt16("head direction");
const uint8_t dir = Net::MessageIn::fromServerDirection(
- static_cast<uint8_t>(msg.readUInt8("player direction") & 0x0FU));
+ CAST_U8(msg.readUInt8("player direction") & 0x0FU));
if (!dstBeing)
{
@@ -1207,13 +1207,13 @@ void BeingRecv::processPlaterStatusChange(Net::MessageIn &msg)
const uint16_t stunMode = msg.readInt16("stun mode");
uint32_t statusEffects = msg.readInt16("status effect");
- statusEffects |= (static_cast<uint32_t>(msg.readInt32("option"))) << 16;
+ statusEffects |= (CAST_U32(msg.readInt32("option"))) << 16;
dstBeing->setKarma(msg.readUInt8("karma"));
dstBeing->setStunMode(stunMode);
- dstBeing->setStatusEffectBlock(0, static_cast<uint16_t>(
+ dstBeing->setStatusEffectBlock(0, CAST_U16(
(statusEffects >> 16) & 0xffff));
- dstBeing->setStatusEffectBlock(16, static_cast<uint16_t>(
+ dstBeing->setStatusEffectBlock(16, CAST_U16(
statusEffects & 0xffff));
BLOCK_END("BeingRecv::processPlayerStop")
}
@@ -1234,9 +1234,9 @@ void BeingRecv::processPlaterStatusChange2(Net::MessageIn &msg)
dstBeing->setLevel(msg.readInt32("level"));
msg.readInt32("showEFST");
- dstBeing->setStatusEffectBlock(0, static_cast<uint16_t>(
+ dstBeing->setStatusEffectBlock(0, CAST_U16(
(statusEffects >> 16) & 0xffff));
- dstBeing->setStatusEffectBlock(16, static_cast<uint16_t>(
+ dstBeing->setStatusEffectBlock(16, CAST_U16(
statusEffects & 0xffff));
}
@@ -1698,14 +1698,14 @@ Being *BeingRecv::createBeing2(Net::MessageIn &msg,
case BeingType::ITEM:
case BeingType::ELEMENTAL:
logger->log("not supported object type: %d, job: %d",
- static_cast<int>(beingType), static_cast<int>(job));
+ CAST_S32(beingType), CAST_S32(job));
break;
case BeingType::CHAT:
default:
UNIMPLIMENTEDPACKET;
type = ActorType::Monster;
logger->log("not supported object type: %d, job: %d",
- static_cast<int>(beingType), static_cast<int>(job));
+ CAST_S32(beingType), CAST_S32(job));
break;
}
if (job == 45 && beingType == BeingType::NPC_EVENT)
diff --git a/src/net/eathena/buyingstorehandler.cpp b/src/net/eathena/buyingstorehandler.cpp
index a850a8785..5fcc9c4aa 100644
--- a/src/net/eathena/buyingstorehandler.cpp
+++ b/src/net/eathena/buyingstorehandler.cpp
@@ -48,15 +48,15 @@ void BuyingStoreHandler::create(const std::string &name,
std::vector<ShopItem*> &items) const
{
createOutPacket(CMSG_BUYINGSTORE_CREATE);
- outMsg.writeInt16(static_cast<int16_t>(89 + items.size() * 8), "len");
+ outMsg.writeInt16(CAST_S16(89 + items.size() * 8), "len");
outMsg.writeInt32(maxMoney, "limit money");
outMsg.writeInt8(flag, "flag");
outMsg.writeString(name, 80, "store name");
FOR_EACH (std::vector<ShopItem*>::const_iterator, it, items)
{
const ShopItem *const item = *it;
- outMsg.writeInt16(static_cast<int16_t>(item->getId()), "item id");
- outMsg.writeInt16(static_cast<int16_t>(item->getQuantity()), "amount");
+ outMsg.writeInt16(CAST_S16(item->getId()), "item id");
+ outMsg.writeInt16(CAST_S16(item->getQuantity()), "amount");
outMsg.writeInt32(item->getPrice(), "price");
}
}
@@ -87,11 +87,11 @@ void BuyingStoreHandler::sell(const Being *const being,
outMsg.writeInt16(18, "len");
outMsg.writeBeingId(being->getId(), "account id");
outMsg.writeInt32(storeId, "store id");
- outMsg.writeInt16(static_cast<int16_t>(
+ outMsg.writeInt16(CAST_S16(
item->getInvIndex() + INVENTORY_OFFSET),
"index");
- outMsg.writeInt16(static_cast<int16_t>(item->getId()), "item id");
- outMsg.writeInt16(static_cast<int16_t>(amount), "amount");
+ outMsg.writeInt16(CAST_S16(item->getId()), "item id");
+ outMsg.writeInt16(CAST_S16(amount), "amount");
}
} // namespace EAthena
diff --git a/src/net/eathena/cashshophandler.cpp b/src/net/eathena/cashshophandler.cpp
index 53b9d90e2..026297673 100644
--- a/src/net/eathena/cashshophandler.cpp
+++ b/src/net/eathena/cashshophandler.cpp
@@ -46,8 +46,8 @@ void CashShopHandler::buyItem(const int points,
outMsg.writeInt16(10 + 4, "len");
outMsg.writeInt32(points, "points");
outMsg.writeInt16(1, "count");
- outMsg.writeInt16(static_cast<int16_t>(amount), "amount");
- outMsg.writeInt16(static_cast<int16_t>(itemId), "item id");
+ outMsg.writeInt16(CAST_S16(amount), "amount");
+ outMsg.writeInt16(CAST_S16(itemId), "item id");
}
void CashShopHandler::buyItems(std::vector<ShopItem*> &items A_UNUSED) const
@@ -68,7 +68,7 @@ void CashShopHandler::requestPoints() const
void CashShopHandler::requestTab(const int tab) const
{
createOutPacket(CMSG_NPC_CASH_SHOP_REQUEST_TAB);
- outMsg.writeInt16(static_cast<int16_t>(tab), "tab");
+ outMsg.writeInt16(CAST_S16(tab), "tab");
}
void CashShopHandler::schedule() const
diff --git a/src/net/eathena/charserverhandler.cpp b/src/net/eathena/charserverhandler.cpp
index 37e2e72ea..ce84840ca 100644
--- a/src/net/eathena/charserverhandler.cpp
+++ b/src/net/eathena/charserverhandler.cpp
@@ -66,7 +66,7 @@ void CharServerHandler::chooseCharacter(Net::Character *const character)
mCharSelectDialog = nullptr;
createOutPacket(CMSG_CHAR_SELECT);
- outMsg.writeInt8(static_cast<unsigned char>(
+ outMsg.writeInt8(CAST_U8(
mSelectedCharacter->slot), "slot");
}
@@ -81,11 +81,11 @@ void CharServerHandler::newCharacter(const std::string &name, const int slot,
createOutPacket(CMSG_CHAR_CREATE);
outMsg.writeString(name, 24, "login");
- outMsg.writeInt8(static_cast<unsigned char>(slot), "slot");
- outMsg.writeInt16(static_cast<int16_t>(hairColor), "hair color");
- outMsg.writeInt16(static_cast<int16_t>(hairstyle), "hair style");
+ outMsg.writeInt8(CAST_U8(slot), "slot");
+ outMsg.writeInt16(CAST_S16(hairColor), "hair color");
+ outMsg.writeInt16(CAST_S16(hairstyle), "hair style");
if (serverFeatures->haveRaceSelection())
- outMsg.writeInt16(static_cast<int16_t>(race), "race");
+ outMsg.writeInt16(CAST_S16(race), "race");
if (serverFeatures->haveCreateCharGender())
{
uint8_t sex = 0;
@@ -96,7 +96,7 @@ void CharServerHandler::newCharacter(const std::string &name, const int slot,
outMsg.writeInt8(sex, "gender");
}
if (serverFeatures->haveLookSelection())
- outMsg.writeInt16(static_cast<int16_t>(look), "look");
+ outMsg.writeInt16(CAST_S16(look), "look");
}
void CharServerHandler::deleteCharacter(Net::Character *const character,
@@ -180,8 +180,8 @@ void CharServerHandler::renameCharacter(const BeingId id,
void CharServerHandler::changeSlot(const int oldSlot, const int newSlot)
{
createOutPacket(CMSG_CHAR_CHANGE_SLOT);
- outMsg.writeInt16(static_cast<int16_t>(oldSlot), "old slot");
- outMsg.writeInt16(static_cast<int16_t>(newSlot), "new slot");
+ outMsg.writeInt16(CAST_S16(oldSlot), "old slot");
+ outMsg.writeInt16(CAST_S16(newSlot), "new slot");
outMsg.writeInt16(0, "unused");
}
diff --git a/src/net/eathena/charserverrecv.cpp b/src/net/eathena/charserverrecv.cpp
index e2b7567e3..03ca40aaa 100644
--- a/src/net/eathena/charserverrecv.cpp
+++ b/src/net/eathena/charserverrecv.cpp
@@ -166,7 +166,7 @@ void CharServerRecv::readPlayerData(Net::MessageIn &msg,
msg.readInt32("slot change");
tempPlayer->setRename(msg.readInt32("rename (inverse)"));
- const uint8_t gender = static_cast<uint8_t>(msg.readUInt8("gender"));
+ const uint8_t gender = CAST_U8(msg.readUInt8("gender"));
if (gender != 99)
tempPlayer->setGender(Being::intToGender(gender));
}
@@ -177,7 +177,7 @@ void CharServerRecv::processCharLogin(Net::MessageIn &msg)
const int slots = msg.readInt8("MAX_CHARS");
msg.readInt8("sd->char_slots");
msg.readInt8("MAX_CHARS");
- loginData.characterSlots = static_cast<uint16_t>(slots);
+ loginData.characterSlots = CAST_U16(slots);
msg.skip(20, "unused 0");
@@ -290,7 +290,7 @@ void CharServerRecv::processPincodeStatus(Net::MessageIn &msg)
{
mPinSeed = msg.readInt32("pincode seed");
mPinAccountId = msg.readBeingId("account id");
- const uint16_t state = static_cast<uint16_t>(msg.readInt16("state"));
+ const uint16_t state = CAST_U16(msg.readInt16("state"));
switch (state)
{
case 0: // pin ok
diff --git a/src/net/eathena/chathandler.cpp b/src/net/eathena/chathandler.cpp
index 236fd5895..353a82b0e 100644
--- a/src/net/eathena/chathandler.cpp
+++ b/src/net/eathena/chathandler.cpp
@@ -60,24 +60,24 @@ void ChatHandler::talk(const std::string &restrict text,
createOutPacket(CMSG_CHAT_MESSAGE);
// Added + 1 in order to let eAthena parse admin commands correctly
- outMsg.writeInt16(static_cast<int16_t>(mes.length() + 4 + 1), "len");
- outMsg.writeString(mes, static_cast<int>(mes.length() + 1), "message");
+ outMsg.writeInt16(CAST_S16(mes.length() + 4 + 1), "len");
+ outMsg.writeString(mes, CAST_S32(mes.length() + 1), "message");
}
void ChatHandler::talkRaw(const std::string &mes) const
{
createOutPacket(CMSG_CHAT_MESSAGE);
- outMsg.writeInt16(static_cast<int16_t>(mes.length() + 4), "len");
- outMsg.writeString(mes, static_cast<int>(mes.length()), "message");
+ outMsg.writeInt16(CAST_S16(mes.length() + 4), "len");
+ outMsg.writeString(mes, CAST_S32(mes.length()), "message");
}
void ChatHandler::privateMessage(const std::string &restrict recipient,
const std::string &restrict text)
{
createOutPacket(CMSG_CHAT_WHISPER);
- outMsg.writeInt16(static_cast<int16_t>(text.length() + 28 + 1), "len");
+ outMsg.writeInt16(CAST_S16(text.length() + 28 + 1), "len");
outMsg.writeString(recipient, 24, "recipient nick");
- outMsg.writeString(text, static_cast<int>(text.length()), "message");
+ outMsg.writeString(text, CAST_S32(text.length()), "message");
outMsg.writeInt8(0, "null char");
Ea::ChatRecv::mSentWhispers.push(recipient);
}
@@ -107,7 +107,7 @@ void ChatHandler::sendRaw(const std::string &args) const
{
str = line.substr(0, pos);
- const int16_t id = static_cast<int16_t>(parseNumber(str));
+ const int16_t id = CAST_S16(parseNumber(str));
outMsg = new MessageOut(id);
outMsg->writeInt16(id, "packet id");
line = line.substr(pos + 1);
@@ -115,7 +115,7 @@ void ChatHandler::sendRaw(const std::string &args) const
}
else
{
- const int16_t id = static_cast<int16_t>(parseNumber(line));
+ const int16_t id = CAST_S16(parseNumber(line));
outMsg = new MessageOut(id);
outMsg->writeInt16(id, "packet id");
delete outMsg;
@@ -145,17 +145,17 @@ void ChatHandler::processRaw(MessageOut &restrict outMsg,
{
case 'b':
{
- outMsg.writeInt8(static_cast<unsigned char>(i), "raw");
+ outMsg.writeInt8(CAST_U8(i), "raw");
break;
}
case 'w':
{
- outMsg.writeInt16(static_cast<int16_t>(i), "raw");
+ outMsg.writeInt16(CAST_S16(i), "raw");
break;
}
case 'l':
{
- outMsg.writeInt32(static_cast<int32_t>(i), "raw");
+ outMsg.writeInt32(CAST_S32(i), "raw");
break;
}
default:
@@ -201,10 +201,10 @@ void ChatHandler::createChatRoom(const std::string &title,
const bool isPublic)
{
createOutPacket(CMSG_CREAYE_CHAT_ROOM);
- outMsg.writeInt16(static_cast<int16_t>(
+ outMsg.writeInt16(CAST_S16(
7 + 8 + 36), "len");
- outMsg.writeInt16(static_cast<int16_t>(limit), "limit");
- outMsg.writeInt8(static_cast<int8_t>(isPublic ? 1 : 0), "public");
+ outMsg.writeInt16(CAST_S16(limit), "limit");
+ outMsg.writeInt8(CAST_S8(isPublic ? 1 : 0), "public");
outMsg.writeString(password, 8, "password");
outMsg.writeString(title, 36, "title");
ChatRecv::mChatRoom = title;
@@ -220,8 +220,8 @@ void ChatHandler::battleTalk(const std::string &text) const
createOutPacket(CMSG_BATTLE_CHAT_MESSAGE);
// Added + 1 in order to let eAthena parse admin commands correctly
- outMsg.writeInt16(static_cast<int16_t>(mes.length() + 4 + 1), "len");
- outMsg.writeString(mes, static_cast<int>(mes.length() + 1), "message");
+ outMsg.writeInt16(CAST_S16(mes.length() + 4 + 1), "len");
+ outMsg.writeString(mes, CAST_S32(mes.length() + 1), "message");
}
void ChatHandler::joinChat(const ChatObject *const chat,
@@ -268,8 +268,8 @@ void ChatHandler::talkPet(const std::string &restrict text,
const size_t sz = msg.size();
createOutPacket(CMSG_PET_TALK);
- outMsg.writeInt16(static_cast<int16_t>(sz + 4 + 1), "len");
- outMsg.writeString(msg, static_cast<int>(sz), "message");
+ outMsg.writeInt16(CAST_S16(sz + 4 + 1), "len");
+ outMsg.writeString(msg, CAST_S32(sz), "message");
outMsg.writeInt8(0, "zero byte");
}
@@ -284,10 +284,10 @@ void ChatHandler::setChatRoomOptions(const int limit,
const std::string &title) const
{
createOutPacket(CMSG_SET_CHAT_ROOM_OPTIONS);
- const int sz = static_cast<int>(title.size());
- outMsg.writeInt16(static_cast<int16_t>(15 + sz), "len");
- outMsg.writeInt16(static_cast<int16_t>(limit), "limit");
- outMsg.writeInt8(static_cast<int8_t>(isPublic ? 1 : 0), "type");
+ const int sz = CAST_S32(title.size());
+ outMsg.writeInt16(CAST_S16(15 + sz), "len");
+ outMsg.writeInt16(CAST_S16(limit), "limit");
+ outMsg.writeInt8(CAST_S8(isPublic ? 1 : 0), "type");
outMsg.writeString(password, 8, "password");
outMsg.writeString(title, sz, "title");
}
diff --git a/src/net/eathena/generalrecv.cpp b/src/net/eathena/generalrecv.cpp
index 48e079d09..1bba1cc3e 100644
--- a/src/net/eathena/generalrecv.cpp
+++ b/src/net/eathena/generalrecv.cpp
@@ -40,7 +40,7 @@ ServerInfo mapServer;
void GeneralRecv::processConnectionProblem(Net::MessageIn &msg)
{
const uint8_t code = msg.readUInt8("flag");
- logger->log("Connection problem: %u", static_cast<unsigned int>(code));
+ logger->log("Connection problem: %u", CAST_U32(code));
switch (code)
{
diff --git a/src/net/eathena/guildhandler.cpp b/src/net/eathena/guildhandler.cpp
index 99cf1f3f9..bc4d70f57 100644
--- a/src/net/eathena/guildhandler.cpp
+++ b/src/net/eathena/guildhandler.cpp
@@ -125,8 +125,8 @@ void GuildHandler::chat(const std::string &text) const
const std::string str = std::string(localPlayer->getName()).append(
" : ").append(text);
createOutPacket(CMSG_GUILD_MESSAGE);
- outMsg.writeInt16(static_cast<uint16_t>(str.size() + 4 + 1), "len");
- outMsg.writeString(str, static_cast<int>(str.length()), "message");
+ outMsg.writeInt16(CAST_U16(str.size() + 4 + 1), "len");
+ outMsg.writeString(str, CAST_S32(str.length()), "message");
outMsg.writeInt8(0, "zero byte");
}
@@ -245,8 +245,8 @@ void GuildHandler::changeEmblem(std::string emblem) const
createOutPacket(CMSG_GUILD_CHANGE_EMBLEM);
if (emblem.size() > 200)
emblem = emblem.substr(0, 200);
- const int sz = static_cast<int>(emblem.size());
- outMsg.writeInt16(static_cast<int16_t>(sz + 4), "len");
+ const int sz = CAST_S32(emblem.size());
+ outMsg.writeInt16(CAST_S16(sz + 4), "len");
outMsg.writeString(emblem, sz, "emblem");
}
diff --git a/src/net/eathena/guildrecv.cpp b/src/net/eathena/guildrecv.cpp
index d8c0193fb..7adfdfb27 100644
--- a/src/net/eathena/guildrecv.cpp
+++ b/src/net/eathena/guildrecv.cpp
@@ -68,7 +68,7 @@ void GuildRecv::processGuildPositionInfo(Net::MessageIn &msg)
msg.readInt32("unused");
std::string guildName = msg.readString(24, "guild name");
- Guild *const g = Guild::getGuild(static_cast<int16_t>(guildId));
+ Guild *const g = Guild::getGuild(CAST_S16(guildId));
if (!g)
return;
@@ -98,7 +98,7 @@ void GuildRecv::processGuildMemberLogin(Net::MessageIn &msg)
const BeingId accountId = msg.readBeingId("account id");
const int charId = msg.readInt32("char id");
const int online = msg.readInt32("flag");
- const GenderT gender = Being::intToGender(static_cast<uint8_t>(
+ const GenderT gender = Being::intToGender(CAST_U8(
msg.readInt16("sex")));
msg.readInt16("hair");
msg.readInt16("hair color");
diff --git a/src/net/eathena/homunculushandler.cpp b/src/net/eathena/homunculushandler.cpp
index 26b7ed618..9837eccb5 100644
--- a/src/net/eathena/homunculushandler.cpp
+++ b/src/net/eathena/homunculushandler.cpp
@@ -61,8 +61,8 @@ void HomunculusHandler::move(const int x, const int y) const
return;
createOutPacket(CMSG_HOMMERC_MOVE_TO);
outMsg.writeBeingId(id, "homunculus id");
- outMsg.writeCoordinates(static_cast<uint16_t>(x),
- static_cast<uint16_t>(y),
+ outMsg.writeCoordinates(CAST_U16(x),
+ CAST_U16(y),
0U, "position");
}
@@ -75,7 +75,7 @@ void HomunculusHandler::attack(const BeingId targetId,
createOutPacket(CMSG_HOMMERC_ATTACK);
outMsg.writeBeingId(id, "homunculus id");
outMsg.writeBeingId(targetId, "target id");
- outMsg.writeInt8(static_cast<int8_t>(keep == Keep_true ? 1 : 0), "keep");
+ outMsg.writeInt8(CAST_S8(keep == Keep_true ? 1 : 0), "keep");
}
void HomunculusHandler::feed() const
@@ -104,8 +104,8 @@ void HomunculusHandler::talk(const std::string &restrict text) const
const size_t sz = msg.size();
createOutPacket(CMSG_HOMMERC_TALK);
- outMsg.writeInt16(static_cast<int16_t>(sz + 4 + 1), "len");
- outMsg.writeString(msg, static_cast<int>(sz), "message");
+ outMsg.writeInt16(CAST_S16(sz + 4 + 1), "len");
+ outMsg.writeString(msg, CAST_S32(sz), "message");
outMsg.writeInt8(0, "zero byte");
}
diff --git a/src/net/eathena/inventoryhandler.cpp b/src/net/eathena/inventoryhandler.cpp
index fa2905c28..ce87e5660 100644
--- a/src/net/eathena/inventoryhandler.cpp
+++ b/src/net/eathena/inventoryhandler.cpp
@@ -80,7 +80,7 @@ void InventoryHandler::equipItem(const Item *const item) const
return;
createOutPacket(CMSG_PLAYER_EQUIP);
- outMsg.writeInt16(static_cast<int16_t>(
+ outMsg.writeInt16(CAST_S16(
item->getInvIndex() + INVENTORY_OFFSET), "index");
// here we set flag for any slots,
// probably better set to slot from item properties
@@ -93,7 +93,7 @@ void InventoryHandler::unequipItem(const Item *const item) const
return;
createOutPacket(CMSG_PLAYER_UNEQUIP);
- outMsg.writeInt16(static_cast<int16_t>(
+ outMsg.writeInt16(CAST_S16(
item->getInvIndex() + INVENTORY_OFFSET), "index");
}
@@ -103,7 +103,7 @@ void InventoryHandler::useItem(const Item *const item) const
return;
createOutPacket(CMSG_PLAYER_INVENTORY_USE);
- outMsg.writeInt16(static_cast<int16_t>(
+ outMsg.writeInt16(CAST_S16(
item->getInvIndex() + INVENTORY_OFFSET), "index");
outMsg.writeInt32(item->getId(), "unused");
}
@@ -114,9 +114,9 @@ void InventoryHandler::dropItem(const Item *const item, const int amount) const
return;
createOutPacket(CMSG_PLAYER_INVENTORY_DROP);
- outMsg.writeInt16(static_cast<int16_t>(
+ outMsg.writeInt16(CAST_S16(
item->getInvIndex() + INVENTORY_OFFSET), "index");
- outMsg.writeInt16(static_cast<int16_t>(amount), "amount");
+ outMsg.writeInt16(CAST_S16(amount), "amount");
}
void InventoryHandler::closeStorage() const
@@ -157,7 +157,7 @@ void InventoryHandler::moveItem2(const InventoryTypeT source,
if (packet)
{
createOutPacket(packet);
- outMsg.writeInt16(static_cast<int16_t>(slot + offset), "index");
+ outMsg.writeInt16(CAST_S16(slot + offset), "index");
outMsg.writeInt32(amount, "amount");
}
}
@@ -169,7 +169,7 @@ void InventoryHandler::useCard(const Item *const item)
mItemIndex = item->getInvIndex();
createOutPacket(CMSG_PLAYER_USE_CARD);
- outMsg.writeInt16(static_cast<int16_t>(
+ outMsg.writeInt16(CAST_S16(
mItemIndex + INVENTORY_OFFSET), "index");
}
@@ -177,9 +177,9 @@ void InventoryHandler::insertCard(const int cardIndex,
const int itemIndex) const
{
createOutPacket(CMSG_PLAYER_INSERT_CARD);
- outMsg.writeInt16(static_cast<int16_t>(cardIndex + INVENTORY_OFFSET),
+ outMsg.writeInt16(CAST_S16(cardIndex + INVENTORY_OFFSET),
"card index");
- outMsg.writeInt16(static_cast<int16_t>(itemIndex + INVENTORY_OFFSET),
+ outMsg.writeInt16(CAST_S16(itemIndex + INVENTORY_OFFSET),
"item index");
}
@@ -189,7 +189,7 @@ void InventoryHandler::favoriteItem(const Item *const item,
if (!item)
return;
createOutPacket(CMSG_PLAYER_FAVORITE_ITEM);
- outMsg.writeInt16(static_cast<int16_t>(item->getInvIndex()
+ outMsg.writeInt16(CAST_S16(item->getInvIndex()
+ INVENTORY_OFFSET),
"item index");
outMsg.writeInt8(favorite, "favorite flag");
@@ -200,7 +200,7 @@ void InventoryHandler::selectEgg(const Item *const item) const
if (!item)
return;
createOutPacket(CMSG_PET_SELECT_EGG);
- outMsg.writeInt16(static_cast<int16_t>(
+ outMsg.writeInt16(CAST_S16(
item->getInvIndex() + INVENTORY_OFFSET), "index");
menu = MenuType::Unknown;
}
@@ -210,7 +210,7 @@ int InventoryHandler::convertFromServerSlot(const int serverSlot) const
if (serverSlot < 0 || serverSlot > 15)
return 0;
- return static_cast<int>(EQUIP_CONVERT[serverSlot]);
+ return CAST_S32(EQUIP_CONVERT[serverSlot]);
}
void InventoryHandler::selectCart(const BeingId accountId,
@@ -224,7 +224,7 @@ void InventoryHandler::selectCart(const BeingId accountId,
void InventoryHandler::identifyItem(const Item *const item) const
{
createOutPacket(CMSG_QUICK_IDENTIFY_ITEM);
- outMsg.writeInt16(static_cast<int16_t>(item->getInvIndex()),
+ outMsg.writeInt16(CAST_S16(item->getInvIndex()),
"item index");
}
diff --git a/src/net/eathena/inventoryrecv.cpp b/src/net/eathena/inventoryrecv.cpp
index fcaada26a..d3b969143 100644
--- a/src/net/eathena/inventoryrecv.cpp
+++ b/src/net/eathena/inventoryrecv.cpp
@@ -97,7 +97,7 @@ void InventoryRecv::processPlayerEquipment(Net::MessageIn &msg)
const int itemType = msg.readUInt8("item type");
msg.readInt32("location");
const int equipType = msg.readInt32("wear state");
- const uint8_t refine = static_cast<uint8_t>(msg.readInt8("refine"));
+ const uint8_t refine = CAST_U8(msg.readInt8("refine"));
int cards[maxCards];
for (int f = 0; f < maxCards; f++)
cards[f] = msg.readInt16("card");
diff --git a/src/net/eathena/itemrecv.cpp b/src/net/eathena/itemrecv.cpp
index 79892ebf7..822b4684d 100644
--- a/src/net/eathena/itemrecv.cpp
+++ b/src/net/eathena/itemrecv.cpp
@@ -44,8 +44,8 @@ void ItemRecv::processItemDropped(Net::MessageIn &msg)
msg.readUInt8("identify"), Identified);
const int x = msg.readInt16("x");
const int y = msg.readInt16("y");
- const int subX = static_cast<int>(msg.readInt8("subx"));
- const int subY = static_cast<int>(msg.readInt8("suby"));
+ const int subX = CAST_S32(msg.readInt8("subx"));
+ const int subY = CAST_S32(msg.readInt8("suby"));
const int amount = msg.readInt16("count");
if (actorManager)
@@ -79,8 +79,8 @@ void ItemRecv::processItemDropped2(Net::MessageIn &msg)
const int x = msg.readInt16("x");
const int y = msg.readInt16("y");
const int amount = msg.readInt16("amount");
- const int subX = static_cast<int>(msg.readInt8("subx"));
- const int subY = static_cast<int>(msg.readInt8("suby"));
+ const int subX = CAST_S32(msg.readInt8("subx"));
+ const int subY = CAST_S32(msg.readInt8("suby"));
if (actorManager)
{
@@ -119,8 +119,8 @@ void ItemRecv::processItemVisible(Net::MessageIn &msg)
const int x = msg.readInt16("x");
const int y = msg.readInt16("y");
const int amount = msg.readInt16("amount");
- const int subX = static_cast<int>(msg.readInt8("sub x"));
- const int subY = static_cast<int>(msg.readInt8("sub y"));
+ const int subX = CAST_S32(msg.readInt8("sub x"));
+ const int subY = CAST_S32(msg.readInt8("sub y"));
if (actorManager)
{
@@ -153,8 +153,8 @@ void ItemRecv::processItemVisible2(Net::MessageIn &msg)
const int x = msg.readInt16("x");
const int y = msg.readInt16("y");
const int amount = msg.readInt16("amount");
- const int subX = static_cast<int>(msg.readInt8("sub x"));
- const int subY = static_cast<int>(msg.readInt8("sub y"));
+ const int subX = CAST_S32(msg.readInt8("sub x"));
+ const int subY = CAST_S32(msg.readInt8("sub y"));
if (actorManager)
{
diff --git a/src/net/eathena/mailhandler.cpp b/src/net/eathena/mailhandler.cpp
index d1ab80005..7bcc53088 100644
--- a/src/net/eathena/mailhandler.cpp
+++ b/src/net/eathena/mailhandler.cpp
@@ -70,21 +70,21 @@ void MailHandler::returnMessage(const int msgId) const
void MailHandler::setAttach(const int index, const int amount) const
{
createOutPacket(CMSG_MAIL_SET_ATTACH);
- outMsg.writeInt16(static_cast<int16_t>(index + INVENTORY_OFFSET), "index");
+ outMsg.writeInt16(CAST_S16(index + INVENTORY_OFFSET), "index");
outMsg.writeInt32(amount, "amount");
}
void MailHandler::setAttachMoney(const int money) const
{
createOutPacket(CMSG_MAIL_SET_ATTACH);
- outMsg.writeInt16(static_cast<int16_t>(0), "index");
+ outMsg.writeInt16(CAST_S16(0), "index");
outMsg.writeInt32(money, "money");
}
void MailHandler::resetAttach(const int flag) const
{
createOutPacket(CMSG_MAIL_RESET_ATTACH);
- outMsg.writeInt16(static_cast<int16_t>(flag), "flag");
+ outMsg.writeInt16(CAST_S16(flag), "flag");
}
void MailHandler::send(const std::string &name,
@@ -93,13 +93,13 @@ void MailHandler::send(const std::string &name,
{
if (message.size() > 255)
message = message.substr(0, 255);
- const int sz = static_cast<int>(message.size());
+ const int sz = CAST_S32(message.size());
createOutPacket(CMSG_MAIL_SEND);
- outMsg.writeInt16(static_cast<int16_t>(69 + sz), "len");
+ outMsg.writeInt16(CAST_S16(69 + sz), "len");
outMsg.writeString(name, 24, "name");
outMsg.writeString(title, 40, "title");
- outMsg.writeInt8(static_cast<int8_t>(sz), "message size");
+ outMsg.writeInt8(CAST_S8(sz), "message size");
outMsg.writeString(message, sz, "message");
}
diff --git a/src/net/eathena/markethandler.cpp b/src/net/eathena/markethandler.cpp
index de0e31345..b055d574a 100644
--- a/src/net/eathena/markethandler.cpp
+++ b/src/net/eathena/markethandler.cpp
@@ -56,11 +56,11 @@ void MarketHandler::buyItem(const int itemId,
cnt = 100;
createOutPacket(CMSG_NPC_MARKET_BUY);
- outMsg.writeInt16(static_cast<int16_t>(4 + 6 * cnt), "len");
+ outMsg.writeInt16(CAST_S16(4 + 6 * cnt), "len");
for (int f = 0; f < cnt; f ++)
{
- outMsg.writeInt16(static_cast<int16_t>(itemId), "item id");
- outMsg.writeInt32(static_cast<int16_t>(amount2), "amount");
+ outMsg.writeInt16(CAST_S16(itemId), "item id");
+ outMsg.writeInt32(CAST_S16(amount2), "amount");
}
}
@@ -86,7 +86,7 @@ void MarketHandler::buyItems(std::vector<ShopItem*> &items) const
return;
createOutPacket(CMSG_NPC_MARKET_BUY);
- outMsg.writeInt16(static_cast<int16_t>(4 + pairSize * cnt), "len");
+ outMsg.writeInt16(CAST_S16(4 + pairSize * cnt), "len");
FOR_EACH (std::vector<ShopItem*>::iterator, it, items)
{
ShopItem *const item = *it;
@@ -101,15 +101,15 @@ void MarketHandler::buyItems(std::vector<ShopItem*> &items) const
{
for (int f = 0; f < usedQuantity; f ++)
{
- outMsg.writeInt16(static_cast<int16_t>(item->getId()),
+ outMsg.writeInt16(CAST_S16(item->getId()),
"item id");
- outMsg.writeInt32(static_cast<int16_t>(1), "amount");
+ outMsg.writeInt32(CAST_S16(1), "amount");
}
}
else
{
- outMsg.writeInt16(static_cast<int16_t>(item->getId()), "item id");
- outMsg.writeInt32(static_cast<int16_t>(usedQuantity), "amount");
+ outMsg.writeInt16(CAST_S16(item->getId()), "item id");
+ outMsg.writeInt32(CAST_S16(usedQuantity), "amount");
}
}
}
diff --git a/src/net/eathena/mercenaryhandler.cpp b/src/net/eathena/mercenaryhandler.cpp
index a14eac0ac..84eb5671c 100644
--- a/src/net/eathena/mercenaryhandler.cpp
+++ b/src/net/eathena/mercenaryhandler.cpp
@@ -61,8 +61,8 @@ void MercenaryHandler::move(const int x, const int y) const
return;
createOutPacket(CMSG_HOMMERC_MOVE_TO);
outMsg.writeBeingId(id, "mercenary id");
- outMsg.writeCoordinates(static_cast<uint16_t>(x),
- static_cast<uint16_t>(y),
+ outMsg.writeCoordinates(CAST_U16(x),
+ CAST_U16(y),
0U, "position");
}
@@ -75,7 +75,7 @@ void MercenaryHandler::attack(const BeingId targetId,
createOutPacket(CMSG_HOMMERC_ATTACK);
outMsg.writeBeingId(id, "mercenary id");
outMsg.writeBeingId(targetId, "target id");
- outMsg.writeInt8(static_cast<int8_t>(keep == Keep_true ? 1 : 0), "keep");
+ outMsg.writeInt8(CAST_S8(keep == Keep_true ? 1 : 0), "keep");
}
void MercenaryHandler::talk(const std::string &restrict text) const
@@ -90,8 +90,8 @@ void MercenaryHandler::talk(const std::string &restrict text) const
const size_t sz = msg.size();
createOutPacket(CMSG_HOMMERC_TALK);
- outMsg.writeInt16(static_cast<int16_t>(sz + 4 + 1), "len");
- outMsg.writeString(msg, static_cast<int>(sz), "message");
+ outMsg.writeInt16(CAST_S16(sz + 4 + 1), "len");
+ outMsg.writeString(msg, CAST_S32(sz), "message");
outMsg.writeInt8(0, "zero byte");
}
diff --git a/src/net/eathena/messagein.cpp b/src/net/eathena/messagein.cpp
index 324666e86..fa19465a3 100644
--- a/src/net/eathena/messagein.cpp
+++ b/src/net/eathena/messagein.cpp
@@ -56,10 +56,10 @@ uint16_t MessageIn::readId()
{
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
int16_t swap;
- memcpy(&swap, mData + static_cast<size_t>(mPos), sizeof(int16_t));
+ memcpy(&swap, mData + CAST_SIZE(mPos), sizeof(int16_t));
value = SDL_Swap16(swap);
#else
- memcpy(&value, mData + static_cast<size_t>(mPos), sizeof(int16_t));
+ memcpy(&value, mData + CAST_SIZE(mPos), sizeof(int16_t));
#endif
}
return value;
@@ -72,14 +72,14 @@ int16_t MessageIn::readInt16(const char *const str)
{
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
int16_t swap;
- memcpy(&swap, mData + static_cast<size_t>(mPos), sizeof(int16_t));
+ memcpy(&swap, mData + CAST_SIZE(mPos), sizeof(int16_t));
value = SDL_Swap16(swap);
#else
- memcpy(&value, mData + static_cast<size_t>(mPos), sizeof(int16_t));
+ memcpy(&value, mData + CAST_SIZE(mPos), sizeof(int16_t));
#endif
}
- DEBUGLOG2("readInt16: " + toStringPrint(static_cast<unsigned int>(
- static_cast<uint16_t>(value))),
+ DEBUGLOG2("readInt16: " + toStringPrint(CAST_U32(
+ CAST_U16(value))),
mPos, str);
mPos += 2;
PacketCounters::incInBytes(2);
@@ -93,13 +93,13 @@ int32_t MessageIn::readInt32(const char *const str)
{
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
int32_t swap;
- memcpy(&swap, mData + static_cast<size_t>(mPos), sizeof(int32_t));
+ memcpy(&swap, mData + CAST_SIZE(mPos), sizeof(int32_t));
value = SDL_Swap32(swap);
#else
- memcpy(&value, mData + static_cast<size_t>(mPos), sizeof(int32_t));
+ memcpy(&value, mData + CAST_SIZE(mPos), sizeof(int32_t));
#endif
}
- DEBUGLOG2("readInt32: " + toStringPrint(static_cast<unsigned int>(value)),
+ DEBUGLOG2("readInt32: " + toStringPrint(CAST_U32(value)),
mPos, str);
mPos += 4;
PacketCounters::incInBytes(4);
@@ -118,13 +118,13 @@ int64_t MessageIn::readInt64(const char *const str)
{
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
int64_t swap;
- memcpy(&swap, mData + static_cast<size_t>(mPos), sizeof(int64_t));
+ memcpy(&swap, mData + CAST_SIZE(mPos), sizeof(int64_t));
value = SDL_Swap64(swap);
#else
- memcpy(&value, mData + static_cast<size_t>(mPos), sizeof(int64_t));
+ memcpy(&value, mData + CAST_SIZE(mPos), sizeof(int64_t));
#endif
}
- DEBUGLOG2("readInt64: " + toStringPrint(static_cast<unsigned int>(value)),
+ DEBUGLOG2("readInt64: " + toStringPrint(CAST_U32(value)),
mPos, str);
mPos += 8;
PacketCounters::incInBytes(8);
diff --git a/src/net/eathena/messageout.cpp b/src/net/eathena/messageout.cpp
index f97cc97d5..83be120e5 100644
--- a/src/net/eathena/messageout.cpp
+++ b/src/net/eathena/messageout.cpp
@@ -40,13 +40,13 @@ MessageOut::MessageOut(const int16_t id) :
mNetwork(EAthena::Network::instance())
{
mNetwork->fixSendBuffer();
- mData = mNetwork->mOutBuffer + static_cast<size_t>(mNetwork->mOutSize);
+ mData = mNetwork->mOutBuffer + CAST_SIZE(mNetwork->mOutSize);
}
void MessageOut::expand(const size_t bytes)
{
- mNetwork->mOutSize += static_cast<unsigned>(bytes);
- PacketCounters::incOutBytes(static_cast<int>(bytes));
+ mNetwork->mOutSize += CAST_U32(bytes);
+ PacketCounters::incOutBytes(CAST_S32(bytes));
}
void MessageOut::writeInt16(const int16_t value, const char *const str)
@@ -54,12 +54,12 @@ void MessageOut::writeInt16(const int16_t value, const char *const str)
expand(2);
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
int16_t swap = SDL_Swap16(value);
- memcpy(mData + static_cast<size_t>(mPos), &swap, sizeof(int16_t));
+ memcpy(mData + CAST_SIZE(mPos), &swap, sizeof(int16_t));
#else
- memcpy(mData + static_cast<size_t>(mPos), &value, sizeof(int16_t));
+ memcpy(mData + CAST_SIZE(mPos), &value, sizeof(int16_t));
#endif
- DEBUGLOG2("writeInt16: " + toStringPrint(static_cast<unsigned int>(
- static_cast<uint16_t>(value))),
+ DEBUGLOG2("writeInt16: " + toStringPrint(CAST_U32(
+ CAST_U16(value))),
mPos, str);
mPos += 2;
PacketCounters::incOutBytes(2);
@@ -67,14 +67,14 @@ void MessageOut::writeInt16(const int16_t value, const char *const str)
void MessageOut::writeInt32(const int32_t value, const char *const str)
{
- DEBUGLOG2("writeInt32: " + toStringPrint(static_cast<unsigned int>(value)),
+ DEBUGLOG2("writeInt32: " + toStringPrint(CAST_U32(value)),
mPos, str);
expand(4);
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
int32_t swap = SDL_Swap32(value);
- memcpy(mData + static_cast<size_t>(mPos), &swap, sizeof(int32_t));
+ memcpy(mData + CAST_SIZE(mPos), &swap, sizeof(int32_t));
#else
- memcpy(mData + static_cast<size_t>(mPos), &value, sizeof(int32_t));
+ memcpy(mData + CAST_SIZE(mPos), &value, sizeof(int32_t));
#endif
mPos += 4;
PacketCounters::incOutBytes(4);
@@ -85,9 +85,9 @@ void MessageOut::writeBeingId(const BeingId value, const char *const str)
writeInt32(toInt(value, int32_t), str);
}
-#define LOBYTE(w) (static_cast<unsigned char>(w))
-#define HIBYTE(w) (static_cast<unsigned char>(( \
-static_cast<uint16_t>(w)) >> 8))
+#define LOBYTE(w) (CAST_U8(w))
+#define HIBYTE(w) (CAST_U8(( \
+CAST_U16(w)) >> 8))
void MessageOut::writeCoordinates(const uint16_t x,
const uint16_t y,
@@ -95,11 +95,11 @@ void MessageOut::writeCoordinates(const uint16_t x,
const char *const str)
{
DEBUGLOG2(strprintf("writeCoordinates: %u,%u %u",
- static_cast<unsigned>(x),
- static_cast<unsigned>(y),
- static_cast<unsigned>(direction)), mPos, str);
+ CAST_U32(x),
+ CAST_U32(y),
+ CAST_U32(direction)), mPos, str);
unsigned char *const data = reinterpret_cast<unsigned char*>(mData)
- + static_cast<size_t>(mPos);
+ + CAST_SIZE(mPos);
mNetwork->mOutSize += 3;
mPos += 3;
@@ -109,7 +109,7 @@ void MessageOut::writeCoordinates(const uint16_t x,
data[1] = 1;
data[2] = 2;
data[0] = HIBYTE(temp);
- data[1] = static_cast<unsigned char>(temp);
+ data[1] = CAST_U8(temp);
temp = y;
temp <<= 4;
data[1] |= HIBYTE(temp);
diff --git a/src/net/eathena/network.cpp b/src/net/eathena/network.cpp
index 5d8bb6c24..934afe9f8 100644
--- a/src/net/eathena/network.cpp
+++ b/src/net/eathena/network.cpp
@@ -169,7 +169,7 @@ bool Network::messageReady()
{
const int msgId = readWord(0);
if (msgId >= 0 &&
- static_cast<unsigned int>(msgId) < packet_lengths_size)
+ CAST_U32(msgId) < packet_lengths_size)
{
len = mPackets[msgId].len;
}
@@ -178,7 +178,7 @@ bool Network::messageReady()
len = readWord(2);
}
- const bool ret = (mInSize >= static_cast<unsigned int>(len));
+ const bool ret = (mInSize >= CAST_U32(len));
SDL_mutexV(mMutexIn);
return ret;
diff --git a/src/net/eathena/npchandler.cpp b/src/net/eathena/npchandler.cpp
index 07cce2351..7d0a65abc 100644
--- a/src/net/eathena/npchandler.cpp
+++ b/src/net/eathena/npchandler.cpp
@@ -102,9 +102,9 @@ void NpcHandler::stringInput(const BeingId npcId,
const std::string &value) const
{
createOutPacket(CMSG_NPC_STR_RESPONSE);
- outMsg.writeInt16(static_cast<int16_t>(value.length() + 9), "len");
+ outMsg.writeInt16(CAST_S16(value.length() + 9), "len");
outMsg.writeBeingId(npcId, "npc id");
- outMsg.writeString(value, static_cast<int>(value.length()), "value");
+ outMsg.writeString(value, CAST_S32(value.length()), "value");
outMsg.writeInt8(0, "null byte");
}
@@ -129,8 +129,8 @@ void NpcHandler::buyItem(const BeingId beingId A_UNUSED,
{
createOutPacket(CMSG_NPC_BUY_REQUEST);
outMsg.writeInt16(8, "len");
- outMsg.writeInt16(static_cast<int16_t>(amount), "amount");
- outMsg.writeInt16(static_cast<int16_t>(itemId), "item id");
+ outMsg.writeInt16(CAST_S16(amount), "amount");
+ outMsg.writeInt16(CAST_S16(itemId), "item id");
}
void NpcHandler::buyItems(std::vector<ShopItem*> &items) const
@@ -155,7 +155,7 @@ void NpcHandler::buyItems(std::vector<ShopItem*> &items) const
return;
createOutPacket(CMSG_NPC_BUY_REQUEST);
- outMsg.writeInt16(static_cast<int16_t>(4 + pairSize * cnt), "len");
+ outMsg.writeInt16(CAST_S16(4 + pairSize * cnt), "len");
FOR_EACH (std::vector<ShopItem*>::iterator, it, items)
{
ShopItem *const item = *it;
@@ -169,15 +169,15 @@ void NpcHandler::buyItems(std::vector<ShopItem*> &items) const
{
for (int f = 0; f < usedQuantity; f ++)
{
- outMsg.writeInt16(static_cast<int16_t>(1), "amount");
- outMsg.writeInt16(static_cast<int16_t>(item->getId()),
+ outMsg.writeInt16(CAST_S16(1), "amount");
+ outMsg.writeInt16(CAST_S16(item->getId()),
"item id");
}
}
else
{
- outMsg.writeInt16(static_cast<int16_t>(usedQuantity), "amount");
- outMsg.writeInt16(static_cast<int16_t>(item->getId()), "item id");
+ outMsg.writeInt16(CAST_S16(usedQuantity), "amount");
+ outMsg.writeInt16(CAST_S16(item->getId()), "item id");
}
}
}
@@ -187,9 +187,9 @@ void NpcHandler::sellItem(const BeingId beingId A_UNUSED,
{
createOutPacket(CMSG_NPC_SELL_REQUEST);
outMsg.writeInt16(8, "len");
- outMsg.writeInt16(static_cast<int16_t>(itemId + INVENTORY_OFFSET),
+ outMsg.writeInt16(CAST_S16(itemId + INVENTORY_OFFSET),
"item index");
- outMsg.writeInt16(static_cast<int16_t>(amount), "amount");
+ outMsg.writeInt16(CAST_S16(amount), "amount");
}
void NpcHandler::sellItems(std::vector<ShopItem*> &items) const
@@ -207,7 +207,7 @@ void NpcHandler::sellItems(std::vector<ShopItem*> &items) const
}
createOutPacket(CMSG_NPC_SELL_REQUEST);
- outMsg.writeInt16(static_cast<int16_t>(4 + pairSize * cnt), "len");
+ outMsg.writeInt16(CAST_S16(4 + pairSize * cnt), "len");
FOR_EACH (std::vector<ShopItem*>::iterator, it, items)
{
ShopItem *const item = *it;
@@ -216,10 +216,10 @@ void NpcHandler::sellItems(std::vector<ShopItem*> &items) const
continue;
item->increaseUsedQuantity(-usedQuantity);
item->update();
- outMsg.writeInt16(static_cast<int16_t>(
+ outMsg.writeInt16(CAST_S16(
item->getCurrentInvIndex() + INVENTORY_OFFSET),
"item index");
- outMsg.writeInt16(static_cast<int16_t>(usedQuantity), "amount");
+ outMsg.writeInt16(CAST_S16(usedQuantity), "amount");
}
}
@@ -234,24 +234,24 @@ void NpcHandler::produceMix(const int nameId,
const int materialId3) const
{
createOutPacket(CMSG_NPC_PRODUCE_MIX);
- outMsg.writeInt16(static_cast<int16_t>(nameId), "name id");
- outMsg.writeInt16(static_cast<int16_t>(materialId1), "material 1");
- outMsg.writeInt16(static_cast<int16_t>(materialId2), "material 2");
- outMsg.writeInt16(static_cast<int16_t>(materialId3), "material 3");
+ outMsg.writeInt16(CAST_S16(nameId), "name id");
+ outMsg.writeInt16(CAST_S16(materialId1), "material 1");
+ outMsg.writeInt16(CAST_S16(materialId2), "material 2");
+ outMsg.writeInt16(CAST_S16(materialId3), "material 3");
}
void NpcHandler::cooking(const CookingTypeT type,
const int nameId) const
{
createOutPacket(CMSG_NPC_COOKING);
- outMsg.writeInt16(static_cast<int16_t>(type), "type");
- outMsg.writeInt16(static_cast<int16_t>(nameId), "name id");
+ outMsg.writeInt16(CAST_S16(type), "type");
+ outMsg.writeInt16(CAST_S16(nameId), "name id");
}
void NpcHandler::repair(const int index) const
{
createOutPacket(CMSG_NPC_REPAIR);
- outMsg.writeInt16(static_cast<int16_t>(index), "index");
+ outMsg.writeInt16(CAST_S16(index), "index");
}
void NpcHandler::refine(const int index) const
@@ -263,19 +263,19 @@ void NpcHandler::refine(const int index) const
void NpcHandler::identify(const int index) const
{
createOutPacket(CMSG_NPC_IDENTIFY);
- outMsg.writeInt16(static_cast<int16_t>(index), "index");
+ outMsg.writeInt16(CAST_S16(index), "index");
}
void NpcHandler::selectArrow(const int nameId) const
{
createOutPacket(CMSG_NPC_SELECT_ARROW);
- outMsg.writeInt16(static_cast<int16_t>(nameId), "name id");
+ outMsg.writeInt16(CAST_S16(nameId), "name id");
}
void NpcHandler::selectAutoSpell(const int skillId) const
{
createOutPacket(CMSG_NPC_SELECT_AUTO_SPELL);
- outMsg.writeInt32(static_cast<int16_t>(skillId), "skill id");
+ outMsg.writeInt32(CAST_S16(skillId), "skill id");
}
BeingId NpcHandler::getNpc(Net::MessageIn &msg,
diff --git a/src/net/eathena/partyhandler.cpp b/src/net/eathena/partyhandler.cpp
index d41b7914d..3aa26b1b5 100644
--- a/src/net/eathena/partyhandler.cpp
+++ b/src/net/eathena/partyhandler.cpp
@@ -83,7 +83,7 @@ void PartyHandler::inviteResponse(const int partyId,
{
createOutPacket(CMSG_PARTY_INVITED2);
outMsg.writeInt32(partyId, "party id");
- outMsg.writeInt8(static_cast<int8_t>(accept ? 1 : 0), "accept");
+ outMsg.writeInt8(CAST_S8(accept ? 1 : 0), "accept");
}
}
@@ -125,8 +125,8 @@ void PartyHandler::chat(const std::string &text) const
const std::string mes = std::string(localPlayer->getName()).append(
" : ").append(text);
- outMsg.writeInt16(static_cast<int16_t>(mes.length() + 4 + 1), "len");
- outMsg.writeString(mes, static_cast<int>(mes.length()), "nick : message");
+ outMsg.writeInt16(CAST_S16(mes.length() + 4 + 1), "len");
+ outMsg.writeString(mes, CAST_S32(mes.length()), "nick : message");
outMsg.writeInt8(0, "null char");
}
@@ -137,8 +137,8 @@ void PartyHandler::setShareExperience(const PartyShareT share) const
return;
createOutPacket(CMSG_PARTY_SETTINGS);
- outMsg.writeInt16(static_cast<int16_t>(share), "share exp");
- outMsg.writeInt16(static_cast<int16_t>(Ea::PartyRecv::mShareItems),
+ outMsg.writeInt16(CAST_S16(share), "share exp");
+ outMsg.writeInt16(CAST_S16(Ea::PartyRecv::mShareItems),
"share items");
}
@@ -149,9 +149,9 @@ void PartyHandler::setShareItems(const PartyShareT share) const
return;
createOutPacket(CMSG_PARTY_SETTINGS);
- outMsg.writeInt16(static_cast<int16_t>(Ea::PartyRecv::mShareExp),
+ outMsg.writeInt16(CAST_S16(Ea::PartyRecv::mShareExp),
"share exp");
- outMsg.writeInt16(static_cast<int16_t>(share), "share items");
+ outMsg.writeInt16(CAST_S16(share), "share items");
}
void PartyHandler::changeLeader(const std::string &name) const
@@ -167,7 +167,7 @@ void PartyHandler::changeLeader(const std::string &name) const
void PartyHandler::allowInvite(const bool allow) const
{
createOutPacket(CMSG_PARTY_ALLOW_INVITES);
- outMsg.writeInt8(static_cast<int8_t>(allow ? 1 : 0), "allow");
+ outMsg.writeInt8(CAST_S8(allow ? 1 : 0), "allow");
}
} // namespace EAthena
diff --git a/src/net/eathena/pethandler.cpp b/src/net/eathena/pethandler.cpp
index b7a2a3b34..55f285dc1 100644
--- a/src/net/eathena/pethandler.cpp
+++ b/src/net/eathena/pethandler.cpp
@@ -46,8 +46,8 @@ void PetHandler::move(const int petId A_UNUSED,
return;
createOutPacket(CMSG_PET_MOVE_TO);
outMsg.writeInt32(0, "pet id");
- outMsg.writeInt16(static_cast<int16_t>(x), "x");
- outMsg.writeInt16(static_cast<int16_t>(y), "y");
+ outMsg.writeInt16(CAST_S16(x), "x");
+ outMsg.writeInt16(CAST_S16(y), "y");
}
void PetHandler::spawn(const Being *const being A_UNUSED,
diff --git a/src/net/eathena/playerhandler.cpp b/src/net/eathena/playerhandler.cpp
index c319c6e8d..c07fa4d13 100644
--- a/src/net/eathena/playerhandler.cpp
+++ b/src/net/eathena/playerhandler.cpp
@@ -69,7 +69,7 @@ void PlayerHandler::increaseAttribute(const AttributesT attr) const
if (attr >= Attributes::STR && attr <= Attributes::LUK)
{
createOutPacket(CMSG_STAT_UPDATE_REQUEST);
- outMsg.writeInt16(static_cast<int16_t>(attr), "attribute id");
+ outMsg.writeInt16(CAST_S16(attr), "attribute id");
outMsg.writeInt8(1, "increase");
}
}
@@ -109,9 +109,9 @@ void PlayerHandler::setDestination(const int x, const int y,
const int direction) const
{
createOutPacket(CMSG_PLAYER_CHANGE_DEST);
- outMsg.writeCoordinates(static_cast<uint16_t>(x),
- static_cast<uint16_t>(y),
- static_cast<unsigned char>(direction), "destination");
+ outMsg.writeCoordinates(CAST_U16(x),
+ CAST_U16(y),
+ CAST_U8(direction), "destination");
}
void PlayerHandler::changeAction(const BeingActionT &action) const
@@ -165,10 +165,10 @@ void PlayerHandler::setShortcut(const int idx,
const int level) const
{
createOutPacket(CMSG_SET_SHORTCUTS);
- outMsg.writeInt16(static_cast<int16_t>(idx), "index");
- outMsg.writeInt8(static_cast<int8_t>(type), "type");
+ outMsg.writeInt16(CAST_S16(idx), "index");
+ outMsg.writeInt8(CAST_S8(type), "type");
outMsg.writeInt32(id, "id");
- outMsg.writeInt16(static_cast<int16_t>(level), "level");
+ outMsg.writeInt16(CAST_S16(level), "level");
}
void PlayerHandler::shortcutShiftRow(const int row) const
@@ -176,7 +176,7 @@ void PlayerHandler::shortcutShiftRow(const int row) const
if (serverVersion != 0 && serverVersion < 11)
return;
createOutPacket(CMSG_SHORTCUTS_ROW_SHIFT);
- outMsg.writeInt8(static_cast<int8_t>(row), "row");
+ outMsg.writeInt8(CAST_S8(row), "row");
}
void PlayerHandler::removeOption() const
@@ -187,7 +187,7 @@ void PlayerHandler::removeOption() const
void PlayerHandler::changeCart(const int type) const
{
createOutPacket(CMSG_CHANGE_CART);
- outMsg.writeInt16(static_cast<int16_t>(type), "type");
+ outMsg.writeInt16(CAST_S16(type), "type");
}
void PlayerHandler::setMemo() const
diff --git a/src/net/eathena/playerrecv.cpp b/src/net/eathena/playerrecv.cpp
index 6aa71870a..928faf45b 100644
--- a/src/net/eathena/playerrecv.cpp
+++ b/src/net/eathena/playerrecv.cpp
@@ -389,7 +389,7 @@ void PlayerRecv::processOnlineList(Net::MessageIn &msg)
int addVal = 3;
while (buf - start + 1 < size
- && *(buf + static_cast<size_t>(addVal)))
+ && *(buf + CAST_SIZE(addVal)))
{
unsigned char status = *buf;
buf ++;
diff --git a/src/net/eathena/questhandler.cpp b/src/net/eathena/questhandler.cpp
index 35a903a31..452448101 100644
--- a/src/net/eathena/questhandler.cpp
+++ b/src/net/eathena/questhandler.cpp
@@ -39,7 +39,7 @@ void QuestHandler::setQeustActiveState(const int questId,
{
createOutPacket(CMSG_QUEST_ACTIVATE);
outMsg.writeInt32(questId, "quest id");
- outMsg.writeInt8(static_cast<int8_t>(active ? 1 : 0), "activate");
+ outMsg.writeInt8(CAST_S8(active ? 1 : 0), "activate");
}
} // namespace EAthena
diff --git a/src/net/eathena/searchstorehandler.cpp b/src/net/eathena/searchstorehandler.cpp
index 64eb824cd..93e199286 100644
--- a/src/net/eathena/searchstorehandler.cpp
+++ b/src/net/eathena/searchstorehandler.cpp
@@ -42,12 +42,12 @@ void SearchStoreHandler::search(const StoreSearchTypeT type,
{
createOutPacket(CMSG_SEARCHSTORE_SEARCH);
outMsg.writeInt16(23, "len");
- outMsg.writeInt8(static_cast<uint8_t>(type), "search type");
+ outMsg.writeInt8(CAST_U8(type), "search type");
outMsg.writeInt32(maxPrice, "max price");
outMsg.writeInt32(minPrice, "min price");
outMsg.writeInt32(1, "items count");
outMsg.writeInt32(0, "cards count");
- outMsg.writeInt16(static_cast<int16_t>(itemId), "item id");
+ outMsg.writeInt16(CAST_S16(itemId), "item id");
}
void SearchStoreHandler::nextPage() const
@@ -67,7 +67,7 @@ void SearchStoreHandler::select(const int accountId,
createOutPacket(CMSG_SEARCHSTORE_CLICK);
outMsg.writeInt32(accountId, "account id");
outMsg.writeInt32(storeId, "store id");
- outMsg.writeInt16(static_cast<int16_t>(itemId), "item id");
+ outMsg.writeInt16(CAST_S16(itemId), "item id");
}
} // namespace EAthena
diff --git a/src/net/eathena/skillhandler.cpp b/src/net/eathena/skillhandler.cpp
index 9fbaab265..fb56fae4b 100644
--- a/src/net/eathena/skillhandler.cpp
+++ b/src/net/eathena/skillhandler.cpp
@@ -42,8 +42,8 @@ void SkillHandler::useBeing(const int id, const int level,
const BeingId beingId) const
{
createOutPacket(CMSG_SKILL_USE_BEING);
- outMsg.writeInt16(static_cast<int16_t>(level), "skill level");
- outMsg.writeInt16(static_cast<int16_t>(id), "skill id");
+ outMsg.writeInt16(CAST_S16(level), "skill level");
+ outMsg.writeInt16(CAST_S16(id), "skill id");
outMsg.writeInt32(toInt(beingId, int), "target id");
}
@@ -51,10 +51,10 @@ void SkillHandler::usePos(const int id, const int level,
const int x, const int y) const
{
createOutPacket(CMSG_SKILL_USE_POSITION);
- outMsg.writeInt16(static_cast<int16_t>(level), "skill level");
- outMsg.writeInt16(static_cast<int16_t>(id), "skill id");
- outMsg.writeInt16(static_cast<int16_t>(x), "x");
- outMsg.writeInt16(static_cast<int16_t>(y), "y");
+ outMsg.writeInt16(CAST_S16(level), "skill level");
+ outMsg.writeInt16(CAST_S16(id), "skill id");
+ outMsg.writeInt16(CAST_S16(x), "x");
+ outMsg.writeInt16(CAST_S16(y), "y");
}
void SkillHandler::usePos(const int id, const int level,
@@ -62,17 +62,17 @@ void SkillHandler::usePos(const int id, const int level,
const std::string &text) const
{
createOutPacket(CMSG_SKILL_USE_POSITION_MORE);
- outMsg.writeInt16(static_cast<int16_t>(level), "level");
- outMsg.writeInt16(static_cast<int16_t>(id), "id");
- outMsg.writeInt16(static_cast<int16_t>(x), "x");
- outMsg.writeInt16(static_cast<int16_t>(y), "y");
+ outMsg.writeInt16(CAST_S16(level), "level");
+ outMsg.writeInt16(CAST_S16(id), "id");
+ outMsg.writeInt16(CAST_S16(x), "x");
+ outMsg.writeInt16(CAST_S16(y), "y");
outMsg.writeString(text, 80, "text");
}
void SkillHandler::useMap(const int id, const std::string &map) const
{
createOutPacket(CMSG_SKILL_USE_MAP);
- outMsg.writeInt16(static_cast<int16_t>(id), "skill id");
+ outMsg.writeInt16(CAST_S16(id), "skill id");
outMsg.writeString(map, 16, "map name");
}
diff --git a/src/net/eathena/skillrecv.cpp b/src/net/eathena/skillrecv.cpp
index 214cd88d9..d67620e4c 100644
--- a/src/net/eathena/skillrecv.cpp
+++ b/src/net/eathena/skillrecv.cpp
@@ -203,17 +203,17 @@ void SkillRecv::processSkillFailed(Net::MessageIn &msg)
const int bskill = msg.readInt32("btype");
const signed char success = msg.readUInt8("success");
const signed char reason = msg.readUInt8("reason");
- if (success != static_cast<int>(SKILL_FAILED)
- && bskill == static_cast<int>(BSKILL_EMOTE))
+ if (success != CAST_S32(SKILL_FAILED)
+ && bskill == CAST_S32(BSKILL_EMOTE))
{
logger->log("Action: %d/%d", bskill, success);
}
std::string txt;
- if (success == static_cast<int>(SKILL_FAILED) && bskill != 0)
+ if (success == CAST_S32(SKILL_FAILED) && bskill != 0)
{
- if (localPlayer && bskill == static_cast<int>(BSKILL_EMOTE)
- && reason == static_cast<int>(RFAIL_SKILLDEP))
+ if (localPlayer && bskill == CAST_S32(BSKILL_EMOTE)
+ && reason == CAST_S32(RFAIL_SKILLDEP))
{
localPlayer->stopAdvert();
}
diff --git a/src/net/eathena/tradehandler.cpp b/src/net/eathena/tradehandler.cpp
index 52ceb0d10..417d19de4 100644
--- a/src/net/eathena/tradehandler.cpp
+++ b/src/net/eathena/tradehandler.cpp
@@ -61,7 +61,7 @@ void TradeHandler::respond(const bool accept) const
PlayerInfo::setTrading(Trading_false);
createOutPacket(CMSG_TRADE_RESPONSE);
- outMsg.writeInt8(static_cast<int8_t>(accept ? 3 : 4), "accept");
+ outMsg.writeInt8(CAST_S8(accept ? 3 : 4), "accept");
}
void TradeHandler::addItem(const Item *const item, const int amount) const
@@ -72,7 +72,7 @@ void TradeHandler::addItem(const Item *const item, const int amount) const
TradeRecv::mItemIndex = item->getInvIndex();
TradeRecv::mQuantity = amount;
createOutPacket(CMSG_TRADE_ITEM_ADD_REQUEST);
- outMsg.writeInt16(static_cast<int16_t>(
+ outMsg.writeInt16(CAST_S16(
TradeRecv::mItemIndex + INVENTORY_OFFSET),
"index");
outMsg.writeInt32(amount, "amount");
diff --git a/src/net/eathena/vendinghandler.cpp b/src/net/eathena/vendinghandler.cpp
index 4d0d75ca1..ce2b8d384 100644
--- a/src/net/eathena/vendinghandler.cpp
+++ b/src/net/eathena/vendinghandler.cpp
@@ -69,8 +69,8 @@ void VendingHandler::buy(const Being *const being,
createOutPacket(CMSG_VENDING_BUY);
outMsg.writeInt16(12, "len");
outMsg.writeBeingId(being->getId(), "account id");
- outMsg.writeInt16(static_cast<int16_t>(amount), "amount");
- outMsg.writeInt16(static_cast<int16_t>(index), "index");
+ outMsg.writeInt16(CAST_S16(amount), "amount");
+ outMsg.writeInt16(CAST_S16(index), "index");
}
void VendingHandler::buy2(const Being *const being,
@@ -85,8 +85,8 @@ void VendingHandler::buy2(const Being *const being,
outMsg.writeInt16(16, "len");
outMsg.writeBeingId(being->getId(), "account id");
outMsg.writeInt32(vendId, "vend id");
- outMsg.writeInt16(static_cast<int16_t>(amount), "amount");
- outMsg.writeInt16(static_cast<int16_t>(index), "index");
+ outMsg.writeInt16(CAST_S16(amount), "amount");
+ outMsg.writeInt16(CAST_S16(index), "index");
}
void VendingHandler::createShop(const std::string &name,
@@ -94,15 +94,15 @@ void VendingHandler::createShop(const std::string &name,
std::vector<ShopItem*> &items) const
{
createOutPacket(CMSG_VENDING_CREATE_SHOP);
- outMsg.writeInt16(static_cast<int16_t>(85 + items.size() * 8), "len");
+ outMsg.writeInt16(CAST_S16(85 + items.size() * 8), "len");
outMsg.writeString(name, 80, "shop name");
- outMsg.writeInt8(static_cast<int8_t>(flag ? 1 : 0), "flag");
+ outMsg.writeInt8(CAST_S8(flag ? 1 : 0), "flag");
FOR_EACH (std::vector<ShopItem*>::const_iterator, it, items)
{
const ShopItem *const item = *it;
- outMsg.writeInt16(static_cast<int16_t>(
+ outMsg.writeInt16(CAST_S16(
item->getInvIndex() + INVENTORY_OFFSET), "index");
- outMsg.writeInt16(static_cast<int16_t>(item->getQuantity()), "amount");
+ outMsg.writeInt16(CAST_S16(item->getQuantity()), "amount");
outMsg.writeInt32(item->getPrice(), "price");
}
}
diff --git a/src/net/ipc.cpp b/src/net/ipc.cpp
index 79020e06d..088bd3b81 100644
--- a/src/net/ipc.cpp
+++ b/src/net/ipc.cpp
@@ -129,7 +129,7 @@ int IPC::acceptLoop(void *ptr)
ipc1->mNumReqs, req.c_str());
const char *const respc = resp.c_str();
- const int len = static_cast<int>(strlen(respc)) + 1;
+ const int len = CAST_S32(strlen(respc)) + 1;
result = TcpNet::send(sock, respc, len);
if (result < len)
{
diff --git a/src/net/messagein.cpp b/src/net/messagein.cpp
index def3b1e27..f012a5e2c 100644
--- a/src/net/messagein.cpp
+++ b/src/net/messagein.cpp
@@ -31,8 +31,8 @@
#include "debug.h"
#define MAKEWORD(low, high) \
- (static_cast<uint16_t>((static_cast<unsigned char>(low)) | \
- (static_cast<uint16_t>(static_cast<unsigned char>(high))) << 8))
+ (CAST_U16((CAST_U8(low)) | \
+ (CAST_U16(CAST_U8(high))) << 8))
namespace Net
{
@@ -56,25 +56,25 @@ MessageIn::~MessageIn()
{
logger->log("Wrong actual or planned inbound packet size!");
logger->log(" packet id: %u 0x%x",
- static_cast<unsigned int>(mId),
- static_cast<unsigned int>(mId));
+ CAST_U32(mId),
+ CAST_U32(mId));
logger->log(" planned size: %u", mLength);
logger->log(" read size: %u", mPos);
}
}
else
{
- logger->log("Zero packet size: %d", static_cast<int>(mId));
+ logger->log("Zero packet size: %d", CAST_S32(mId));
}
}
unsigned char MessageIn::readUInt8(const char *const str)
{
- unsigned char value = static_cast<unsigned char>(-1);
+ unsigned char value = CAST_U8(-1);
if (mPos < mLength)
- value = static_cast<unsigned char>(mData[mPos]);
+ value = CAST_U8(mData[mPos]);
- DEBUGLOG2("readUInt8: " + toStringPrint(static_cast<unsigned int>(value)),
+ DEBUGLOG2("readUInt8: " + toStringPrint(CAST_U32(value)),
mPos, str);
mPos += 1;
PacketCounters::incInBytes(1);
@@ -83,12 +83,12 @@ unsigned char MessageIn::readUInt8(const char *const str)
signed char MessageIn::readInt8(const char *const str)
{
- signed char value = static_cast<signed char>(-1);
+ signed char value = CAST_S8(-1);
if (mPos < mLength)
- value = static_cast<signed char>(mData[mPos]);
+ value = CAST_S8(mData[mPos]);
- DEBUGLOG2("readInt8: " + toStringPrint(static_cast<unsigned int>(
- static_cast<unsigned char>(value))),
+ DEBUGLOG2("readInt8: " + toStringPrint(CAST_U32(
+ CAST_U8(value))),
mPos, str);
mPos += 1;
PacketCounters::incInBytes(1);
@@ -120,7 +120,7 @@ uint8_t MessageIn::fromServerDirection(const uint8_t serverDir)
return 8;
default:
logger->log("incorrect direction: %d",
- static_cast<int>(serverDir));
+ CAST_S32(serverDir));
return 0;
}
}
@@ -132,19 +132,19 @@ void MessageIn::readCoordinates(uint16_t &restrict x,
{
if (mPos + 3 <= mLength)
{
- const char *const data = mData + static_cast<size_t>(mPos);
+ const char *const data = mData + CAST_SIZE(mPos);
uint16_t temp = MAKEWORD(data[1] & 0x00c0, data[0] & 0x00ff);
- x = static_cast<uint16_t>(temp >> 6);
+ x = CAST_U16(temp >> 6);
temp = MAKEWORD(data[2] & 0x00f0, data[1] & 0x003f);
- y = static_cast<uint16_t>(temp >> 4);
+ y = CAST_U16(temp >> 4);
- const uint8_t serverDir = static_cast<uint8_t>(data[2] & 0x000f);
+ const uint8_t serverDir = CAST_U8(data[2] & 0x000f);
direction = fromServerDirection(serverDir);
DEBUGLOG2(std::string("readCoordinates: ").append(toString(
- static_cast<int>(x))).append(",").append(toString(
- static_cast<int>(y))).append(",").append(toString(
- static_cast<int>(serverDir))), mPos, str);
+ CAST_S32(x))).append(",").append(toString(
+ CAST_S32(y))).append(",").append(toString(
+ CAST_S32(serverDir))), mPos, str);
}
else
{
@@ -165,23 +165,23 @@ void MessageIn::readCoordinatePair(uint16_t &restrict srcX,
{
if (mPos + 5 <= mLength)
{
- const char *const data = mData + static_cast<size_t>(mPos);
+ const char *const data = mData + CAST_SIZE(mPos);
uint16_t temp = MAKEWORD(data[3], data[2] & 0x000f);
- dstX = static_cast<uint16_t>(temp >> 2);
+ dstX = CAST_U16(temp >> 2);
dstY = MAKEWORD(data[4], data[3] & 0x0003);
temp = MAKEWORD(data[1], data[0]);
- srcX = static_cast<uint16_t>(temp >> 6);
+ srcX = CAST_U16(temp >> 6);
temp = MAKEWORD(data[2], data[1] & 0x003f);
- srcY = static_cast<uint16_t>(temp >> 4);
+ srcY = CAST_U16(temp >> 4);
DEBUGLOG2(std::string("readCoordinatePair: ").append(toString(
- static_cast<int>(srcX))).append(",").append(toString(
- static_cast<int>(srcY))).append(" ").append(toString(
- static_cast<int>(dstX))).append(",").append(toString(
- static_cast<int>(dstY))), mPos, str);
+ CAST_S32(srcX))).append(",").append(toString(
+ CAST_S32(srcY))).append(" ").append(toString(
+ CAST_S32(dstX))).append(",").append(toString(
+ CAST_S32(dstY))), mPos, str);
}
else
{
@@ -197,14 +197,14 @@ void MessageIn::readCoordinatePair(uint16_t &restrict srcX,
void MessageIn::skip(const unsigned int length, const char *const str)
{
- DEBUGLOG2("skip: " + toString(static_cast<int>(length)), mPos, str);
+ DEBUGLOG2("skip: " + toString(CAST_S32(length)), mPos, str);
mPos += length;
PacketCounters::incInBytes(length);
}
void MessageIn::skipToEnd(const char *const str)
{
- const int diff = static_cast<int>(mLength - mPos);
+ const int diff = CAST_S32(mLength - mPos);
if (diff)
{
DEBUGLOG2("skip: " + toString(diff), mPos, str);
@@ -228,12 +228,12 @@ std::string MessageIn::readString(int length, const char *const dstr)
}
// Read the string
- const char *const stringBeg = mData + static_cast<size_t>(mPos);
+ const char *const stringBeg = mData + CAST_SIZE(mPos);
const char *const stringEnd
= static_cast<const char *const>(memchr(stringBeg, '\0', length));
const std::string str(stringBeg, stringEnd
- ? stringEnd - stringBeg : static_cast<size_t>(length));
+ ? stringEnd - stringBeg : CAST_SIZE(length));
DEBUGLOG2("readString: " + str, mPos, dstr);
mPos += length;
PacketCounters::incInBytes(length);
@@ -254,17 +254,17 @@ std::string MessageIn::readRawString(int length, const char *const dstr)
}
// Read the string
- const char *const stringBeg = mData + static_cast<size_t>(mPos);
+ const char *const stringBeg = mData + CAST_SIZE(mPos);
const char *const stringEnd
= static_cast<const char *const>(memchr(stringBeg, '\0', length));
std::string str(stringBeg, stringEnd
- ? stringEnd - stringBeg : static_cast<size_t>(length));
+ ? stringEnd - stringBeg : CAST_SIZE(length));
DEBUGLOG2("readString: " + str, mPos, dstr);
if (stringEnd)
{
- const size_t len2 = static_cast<size_t>(length)
+ const size_t len2 = CAST_SIZE(length)
- (stringEnd - stringBeg) - 1;
const char *const stringBeg2 = stringEnd + 1;
const char *const stringEnd2
@@ -298,9 +298,9 @@ unsigned char *MessageIn::readBytes(int length, const char *const dstr)
}
unsigned char *const buf
- = new unsigned char[static_cast<size_t>(length + 2)];
+ = new unsigned char[CAST_SIZE(length + 2)];
- memcpy(buf, mData + static_cast<size_t>(mPos), length);
+ memcpy(buf, mData + CAST_SIZE(mPos), length);
buf[length] = 0;
buf[length + 1] = 0;
mPos += length;
@@ -308,7 +308,7 @@ unsigned char *MessageIn::readBytes(int length, const char *const dstr)
#ifdef ENABLEDEBUGLOG
std::string str;
for (int f = 0; f < length; f ++)
- str.append(strprintf("%02x", static_cast<unsigned>(buf[f])));
+ str.append(strprintf("%02x", CAST_U32(buf[f])));
str += " ";
for (int f = 0; f < length; f ++)
{
diff --git a/src/net/messageout.cpp b/src/net/messageout.cpp
index 88d7911e7..c2e96335f 100644
--- a/src/net/messageout.cpp
+++ b/src/net/messageout.cpp
@@ -48,8 +48,8 @@ void MessageOut::writeInt8(const int8_t value, const char *const str)
{
expand(1);
mData[mPos] = value;
- DEBUGLOG2("writeInt8: " + toStringPrint(static_cast<unsigned int>(
- static_cast<uint8_t>(value))),
+ DEBUGLOG2("writeInt8: " + toStringPrint(CAST_U32(
+ CAST_U8(value))),
mPos, str);
mPos += 1;
PacketCounters::incOutBytes(1);
@@ -59,11 +59,11 @@ void MessageOut::writeString(const std::string &string,
int length,
const char *const str)
{
- int stringLength = static_cast<int>(string.length());
+ int stringLength = CAST_S32(string.length());
if (length < 0)
{
// Write the length at the start if not fixed
- writeInt16(static_cast<int16_t>(stringLength), "len");
+ writeInt16(CAST_S16(stringLength), "len");
length = stringLength;
}
else if (length < stringLength)
@@ -74,12 +74,12 @@ void MessageOut::writeString(const std::string &string,
expand(length);
// Write the actual string
- memcpy(mData + static_cast<size_t>(mPos), string.c_str(), stringLength);
+ memcpy(mData + CAST_SIZE(mPos), string.c_str(), stringLength);
// Pad remaining space with zeros
if (length > stringLength)
{
- memset(mData + static_cast<size_t>(mPos + stringLength),
+ memset(mData + CAST_SIZE(mPos + stringLength),
'\0',
length - stringLength);
}
@@ -93,11 +93,11 @@ void MessageOut::writeStringNoLog(const std::string &string,
int length,
const char *const str)
{
- int stringLength = static_cast<int>(string.length());
+ int stringLength = CAST_S32(string.length());
if (length < 0)
{
// Write the length at the start if not fixed
- writeInt16(static_cast<int16_t>(stringLength), "len");
+ writeInt16(CAST_S16(stringLength), "len");
length = stringLength;
}
else if (length < stringLength)
@@ -108,12 +108,12 @@ void MessageOut::writeStringNoLog(const std::string &string,
expand(length);
// Write the actual string
- memcpy(mData + static_cast<size_t>(mPos), string.c_str(), stringLength);
+ memcpy(mData + CAST_SIZE(mPos), string.c_str(), stringLength);
// Pad remaining space with zeros
if (length > stringLength)
{
- memset(mData + static_cast<size_t>(mPos + stringLength),
+ memset(mData + CAST_SIZE(mPos + stringLength),
'\0',
length - stringLength);
}
@@ -164,7 +164,7 @@ unsigned char MessageOut::toServerDirection(unsigned char direction)
break;
default:
// OOPSIE! Impossible or unknown
- direction = static_cast<unsigned char>(-1);
+ direction = CAST_U8(-1);
break;
}
return direction;
diff --git a/src/net/messageout.h b/src/net/messageout.h
index 6fcb06cc3..8771f5240 100644
--- a/src/net/messageout.h
+++ b/src/net/messageout.h
@@ -30,7 +30,7 @@
#include "localconsts.h"
#define createOutPacket(name) MessageOut outMsg(name); \
- outMsg.writeInt16(static_cast<int16_t>(name), #name)
+ outMsg.writeInt16(CAST_S16(name), #name)
namespace Net
{
diff --git a/src/net/packetlimiter.cpp b/src/net/packetlimiter.cpp
index 818d75fd8..76ec8b4f4 100644
--- a/src/net/packetlimiter.cpp
+++ b/src/net/packetlimiter.cpp
@@ -39,136 +39,136 @@ struct PacketLimit final
int cntLimit;
};
-PacketLimit mPacketLimits[static_cast<size_t>(PacketType::PACKET_SIZE) + 1];
+PacketLimit mPacketLimits[CAST_SIZE(PacketType::PACKET_SIZE) + 1];
void PacketLimiter::initPacketLimiter()
{
// here i setting packet limits. but current server is broken,
// and this limits may not help.
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_CHAT)].timeLimit = 10 + 5;
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_CHAT)].lastTime = 0;
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_CHAT)].cntLimit = 1;
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_CHAT)].cnt = 0;
// 10
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_PICKUP)].timeLimit = 10 + 5;
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_PICKUP)].lastTime = 0;
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_PICKUP)].cntLimit = 1;
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_PICKUP)].cnt = 0;
// 10 5
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_DROP)].timeLimit = 5;
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_DROP)].lastTime = 0;
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_DROP)].cntLimit = 1;
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_DROP)].cnt = 0;
// 100
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_NPC_NEXT)].timeLimit = 0;
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_NPC_NEXT)].lastTime = 0;
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_NPC_NEXT)].cntLimit = 1;
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_NPC_NEXT)].cnt = 0;
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_NPC_INPUT)].timeLimit = 100;
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_NPC_INPUT)].lastTime = 0;
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_NPC_INPUT)].cntLimit = 1;
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_NPC_INPUT)].cnt = 0;
// 50
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_NPC_TALK)].timeLimit = 60;
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_NPC_TALK)].lastTime = 0;
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_NPC_TALK)].cntLimit = 1;
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_NPC_TALK)].cnt = 0;
// 10
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_EMOTE)].timeLimit = 10 + 5;
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_EMOTE)].lastTime = 0;
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_EMOTE)].cntLimit = 1;
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_EMOTE)].cnt = 0;
// 100
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_SIT)].timeLimit = 100;
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_SIT)].lastTime = 0;
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_SIT)].cntLimit = 1;
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_SIT)].cnt = 0;
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_DIRECTION)].timeLimit = 50;
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_DIRECTION)].lastTime = 0;
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_DIRECTION)].cntLimit = 1;
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_DIRECTION)].cnt = 0;
// 2+
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_ATTACK)].timeLimit = 2 + 10;
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_ATTACK)].lastTime = 0;
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_ATTACK)].cntLimit = 1;
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_ATTACK)].cnt = 0;
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_STOPATTACK)].timeLimit = 2 + 10;
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_STOPATTACK)].lastTime = 0;
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_STOPATTACK)].cntLimit = 1;
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_STOPATTACK)].cnt = 0;
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_ONLINELIST)].timeLimit = 1800;
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_ONLINELIST)].lastTime = 0;
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_ONLINELIST)].cntLimit = 1;
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_ONLINELIST)].cnt = 0;
// 300ms + 50 fix
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_WHISPER)].timeLimit = 30 + 5;
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_WHISPER)].lastTime = 0;
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_WHISPER)].cntLimit = 1;
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_WHISPER)].cnt = 0;
if (!settings.serverConfigDir.empty())
@@ -199,7 +199,7 @@ void PacketLimiter::initPacketLimiter()
const int ver = atoi(line);
for (int f = 0;
- f < static_cast<int>(PacketType::PACKET_SIZE);
+ f < CAST_S32(PacketType::PACKET_SIZE);
f ++)
{
if (!inPacketFile.getline(line, 100))
@@ -230,7 +230,7 @@ void PacketLimiter::writePacketLimits(const std::string &packetLimitsName)
return;
}
outPacketFile << "4" << std::endl;
- for (int f = 0; f < static_cast<int>(PacketType::PACKET_SIZE); f ++)
+ for (int f = 0; f < CAST_S32(PacketType::PACKET_SIZE); f ++)
{
outPacketFile << toString(mPacketLimits[f].timeLimit)
<< std::endl;
@@ -247,7 +247,7 @@ bool PacketLimiter::checkPackets(const PacketTypeT type)
if (!serverConfig.getValueBool("enableBuggyServers", true))
return true;
- const PacketLimit &limit = mPacketLimits[static_cast<size_t>(type)];
+ const PacketLimit &limit = mPacketLimits[CAST_SIZE(type)];
const int timeLimit = limit.timeLimit;
if (!timeLimit)
@@ -284,13 +284,13 @@ bool PacketLimiter::checkPackets(const PacketTypeT type)
bool PacketLimiter::limitPackets(const PacketTypeT type)
{
- if (static_cast<int>(type) < 0 || type > PacketType::PACKET_SIZE)
+ if (CAST_S32(type) < 0 || type > PacketType::PACKET_SIZE)
return false;
if (!serverConfig.getValueBool("enableBuggyServers", true))
return true;
- PacketLimit &pack = mPacketLimits[static_cast<size_t>(type)];
+ PacketLimit &pack = mPacketLimits[CAST_SIZE(type)];
const int timeLimit = pack.timeLimit;
if (!timeLimit)
diff --git a/src/net/tmwa/adminhandler.cpp b/src/net/tmwa/adminhandler.cpp
index e77b9afdb..30c2bfe84 100644
--- a/src/net/tmwa/adminhandler.cpp
+++ b/src/net/tmwa/adminhandler.cpp
@@ -47,15 +47,15 @@ AdminHandler::AdminHandler() :
void AdminHandler::announce(const std::string &text) const
{
createOutPacket(CMSG_ADMIN_ANNOUNCE);
- outMsg.writeInt16(static_cast<int16_t>(text.length() + 4), "len");
- outMsg.writeString(text, static_cast<int>(text.length()), "message");
+ outMsg.writeInt16(CAST_S16(text.length() + 4), "len");
+ outMsg.writeString(text, CAST_S32(text.length()), "message");
}
void AdminHandler::localAnnounce(const std::string &text) const
{
createOutPacket(CMSG_ADMIN_LOCAL_ANNOUNCE);
- outMsg.writeInt16(static_cast<int16_t>(text.length() + 4), "len");
- outMsg.writeString(text, static_cast<int>(text.length()), "message");
+ outMsg.writeInt16(CAST_S16(text.length() + 4), "len");
+ outMsg.writeString(text, CAST_S32(text.length()), "message");
}
void AdminHandler::hide(const bool h A_UNUSED) const
diff --git a/src/net/tmwa/beingrecv.cpp b/src/net/tmwa/beingrecv.cpp
index 93d4a41dc..ea921f91e 100644
--- a/src/net/tmwa/beingrecv.cpp
+++ b/src/net/tmwa/beingrecv.cpp
@@ -73,7 +73,7 @@ void BeingRecv::processBeingChangeLook(Net::MessageIn &msg)
msg.readBeingId("being id"));
const uint8_t type = msg.readUInt8("type");
- const int16_t id = static_cast<int16_t>(msg.readUInt8("id"));
+ const int16_t id = CAST_S16(msg.readUInt8("id"));
const int id2 = 1;
if (!localPlayer || !dstBeing)
@@ -138,7 +138,7 @@ void BeingRecv::processBeingChangeLookContinue(Net::MessageIn &msg,
break;
case 1: // eAthena LOOK_HAIR
{
- const uint16_t look = static_cast<uint16_t>(id / 256);
+ const uint16_t look = CAST_U16(id / 256);
const int hair = id % 256;
dstBeing->setHairStyle(SPRITE_HAIR_COLOR, hair * -1);
dstBeing->setLook(look);
@@ -212,7 +212,7 @@ void BeingRecv::processBeingChangeLookContinue(Net::MessageIn &msg,
localPlayer->imitateOutfit(dstBeing, SPRITE_EVOL2);
break;
case 16:
- dstBeing->setLook(static_cast<uint16_t>(id));
+ dstBeing->setLook(CAST_U16(id));
break;
default:
UNIMPLIMENTEDPACKET;
@@ -234,7 +234,7 @@ void BeingRecv::processPlayerUpdate1(Net::MessageIn &msg)
const int16_t speed = msg.readInt16("speed");
const uint16_t stunMode = msg.readInt16("opt1");
uint32_t statusEffects = msg.readInt16("opt2");
- statusEffects |= (static_cast<uint32_t>(msg.readInt16("options")))
+ statusEffects |= (CAST_U32(msg.readInt16("options")))
<< 16;
const int16_t job = msg.readInt16("job");
int disguiseId = 0;
@@ -301,7 +301,7 @@ void BeingRecv::processPlayerUpdate1(Net::MessageIn &msg)
if (guild == 0)
dstBeing->clearGuilds();
else
- dstBeing->setGuild(Guild::getGuild(static_cast<int16_t>(guild)));
+ dstBeing->setGuild(Guild::getGuild(CAST_S16(guild)));
}
msg.readInt16("emblem");
@@ -310,7 +310,7 @@ void BeingRecv::processPlayerUpdate1(Net::MessageIn &msg)
dstBeing->setKarma(msg.readUInt8("karma"));
// reserving bit for future usage
dstBeing->setGender(Being::intToGender(
- static_cast<uint8_t>(msg.readUInt8("gender") & 3)));
+ CAST_U8(msg.readUInt8("gender") & 3)));
if (!disguiseId)
{
@@ -339,7 +339,7 @@ void BeingRecv::processPlayerUpdate1(Net::MessageIn &msg)
dstBeing->setGM(true);
applyPlayerAction(msg, dstBeing, msg.readUInt8("action type"));
- const int level = static_cast<int>(msg.readUInt8("level"));
+ const int level = CAST_S32(msg.readUInt8("level"));
if (level)
dstBeing->setLevel(level);
@@ -348,9 +348,9 @@ void BeingRecv::processPlayerUpdate1(Net::MessageIn &msg)
dstBeing->setActionTime(tick_time);
dstBeing->setStunMode(stunMode);
- dstBeing->setStatusEffectBlock(0, static_cast<uint16_t>(
+ dstBeing->setStatusEffectBlock(0, CAST_U16(
(statusEffects >> 16) & 0xffff));
- dstBeing->setStatusEffectBlock(16, static_cast<uint16_t>(
+ dstBeing->setStatusEffectBlock(16, CAST_U16(
statusEffects & 0xffff));
BLOCK_END("BeingRecv::processPlayerMoveUpdate")
@@ -370,7 +370,7 @@ void BeingRecv::processPlayerUpdate2(Net::MessageIn &msg)
const int16_t speed = msg.readInt16("speed");
const uint16_t stunMode = msg.readInt16("opt1");
uint32_t statusEffects = msg.readInt16("opt2");
- statusEffects |= (static_cast<uint32_t>(msg.readInt16("options")))
+ statusEffects |= (CAST_U32(msg.readInt16("options")))
<< 16;
const int16_t job = msg.readInt16("job");
int disguiseId = 0;
@@ -436,7 +436,7 @@ void BeingRecv::processPlayerUpdate2(Net::MessageIn &msg)
if (guild == 0)
dstBeing->clearGuilds();
else
- dstBeing->setGuild(Guild::getGuild(static_cast<int16_t>(guild)));
+ dstBeing->setGuild(Guild::getGuild(CAST_S16(guild)));
}
msg.readInt16("emblem");
@@ -445,7 +445,7 @@ void BeingRecv::processPlayerUpdate2(Net::MessageIn &msg)
dstBeing->setKarma(msg.readUInt8("karma"));
// reserving bit for future usage
dstBeing->setGender(Being::intToGender(
- static_cast<uint8_t>(msg.readUInt8("gender") & 3)));
+ CAST_U8(msg.readUInt8("gender") & 3)));
if (!disguiseId)
{
@@ -474,15 +474,15 @@ void BeingRecv::processPlayerUpdate2(Net::MessageIn &msg)
dstBeing->setGM(true);
applyPlayerAction(msg, dstBeing, msg.readUInt8("action type"));
- const int level = static_cast<int>(msg.readUInt8("level"));
+ const int level = CAST_S32(msg.readUInt8("level"));
if (level)
dstBeing->setLevel(level);
dstBeing->setActionTime(tick_time);
dstBeing->setStunMode(stunMode);
- dstBeing->setStatusEffectBlock(0, static_cast<uint16_t>(
+ dstBeing->setStatusEffectBlock(0, CAST_U16(
(statusEffects >> 16) & 0xffff));
- dstBeing->setStatusEffectBlock(16, static_cast<uint16_t>(
+ dstBeing->setStatusEffectBlock(16, CAST_U16(
statusEffects & 0xffff));
BLOCK_END("BeingRecv::processPlayerMoveUpdate")
@@ -502,7 +502,7 @@ void BeingRecv::processPlayerMove(Net::MessageIn &msg)
const int16_t speed = msg.readInt16("speed");
const uint16_t stunMode = msg.readInt16("opt1");
uint32_t statusEffects = msg.readInt16("opt2");
- statusEffects |= (static_cast<uint32_t>(msg.readInt16("options")))
+ statusEffects |= (CAST_U32(msg.readInt16("options")))
<< 16;
const int16_t job = msg.readInt16("job");
int disguiseId = 0;
@@ -571,7 +571,7 @@ void BeingRecv::processPlayerMove(Net::MessageIn &msg)
if (guild == 0)
dstBeing->clearGuilds();
else
- dstBeing->setGuild(Guild::getGuild(static_cast<int16_t>(guild)));
+ dstBeing->setGuild(Guild::getGuild(CAST_S16(guild)));
}
msg.readInt16("emblem");
@@ -580,7 +580,7 @@ void BeingRecv::processPlayerMove(Net::MessageIn &msg)
dstBeing->setKarma(msg.readUInt8("karma"));
// reserving bit for future usage
dstBeing->setGender(Being::intToGender(
- static_cast<uint8_t>(msg.readUInt8("gender") & 3)));
+ CAST_U8(msg.readUInt8("gender") & 3)));
if (!disguiseId)
{
@@ -612,7 +612,7 @@ void BeingRecv::processPlayerMove(Net::MessageIn &msg)
const int d = dstBeing->calcDirection(dstX, dstY);
if (d && dstBeing->getDirection() != d)
- dstBeing->setDirectionDelayed(static_cast<uint8_t>(d));
+ dstBeing->setDirectionDelayed(CAST_U8(d));
}
if (localPlayer->getCurrentAction() != BeingAction::STAND)
@@ -630,7 +630,7 @@ void BeingRecv::processPlayerMove(Net::MessageIn &msg)
msg.readUInt8("unused");
- const int level = static_cast<int>(msg.readUInt8("level"));
+ const int level = CAST_S32(msg.readUInt8("level"));
if (level)
dstBeing->setLevel(level);
@@ -640,9 +640,9 @@ void BeingRecv::processPlayerMove(Net::MessageIn &msg)
dstBeing->setActionTime(tick_time);
dstBeing->setStunMode(stunMode);
- dstBeing->setStatusEffectBlock(0, static_cast<uint16_t>(
+ dstBeing->setStatusEffectBlock(0, CAST_U16(
(statusEffects >> 16) & 0xffff));
- dstBeing->setStatusEffectBlock(16, static_cast<uint16_t>(
+ dstBeing->setStatusEffectBlock(16, CAST_U16(
statusEffects & 0xffff));
if (dstBeing->getType() == ActorType::Player)
@@ -671,7 +671,7 @@ void BeingRecv::processBeingVisible(Net::MessageIn &msg)
int16_t speed = msg.readInt16("speed");
const uint16_t stunMode = msg.readInt16("opt1");
uint32_t statusEffects = msg.readInt16("opt2");
- statusEffects |= (static_cast<uint32_t>(msg.readInt16("option"))) << 16;
+ statusEffects |= (CAST_U32(msg.readInt16("option"))) << 16;
const int16_t job = msg.readInt16("class");
int disguiseId = 0;
if (id == localPlayer->getId() && job >= 1000)
@@ -790,7 +790,7 @@ void BeingRecv::processBeingVisible(Net::MessageIn &msg)
if (serverFeatures->haveMonsterAttackRange()
&& dstBeing->getType() == ActorType::Monster)
{
- const int attackRange = static_cast<int>(
+ const int attackRange = CAST_S32(
msg.readUInt8("attack range (was karma)"));
dstBeing->setAttackRange(attackRange);
}
@@ -852,9 +852,9 @@ void BeingRecv::processBeingVisible(Net::MessageIn &msg)
msg.readUInt8("unknown");
dstBeing->setStunMode(stunMode);
- dstBeing->setStatusEffectBlock(0, static_cast<uint16_t>(
+ dstBeing->setStatusEffectBlock(0, CAST_U16(
(statusEffects >> 16) & 0xffff));
- dstBeing->setStatusEffectBlock(16, static_cast<uint16_t>(
+ dstBeing->setStatusEffectBlock(16, CAST_U16(
statusEffects & 0xffff));
BLOCK_END("BeingRecv::processBeingVisibleOrMove")
}
@@ -880,7 +880,7 @@ void BeingRecv::processBeingMove(Net::MessageIn &msg)
int16_t speed = msg.readInt16("speed");
const uint16_t stunMode = msg.readInt16("opt1");
uint32_t statusEffects = msg.readInt16("opt2");
- statusEffects |= (static_cast<uint32_t>(msg.readInt16("option"))) << 16;
+ statusEffects |= (CAST_U32(msg.readInt16("option"))) << 16;
const int16_t job = msg.readInt16("class");
int disguiseId = 0;
if (id == localPlayer->getId() && job >= 1000)
@@ -993,7 +993,7 @@ void BeingRecv::processBeingMove(Net::MessageIn &msg)
if (serverFeatures->haveMonsterAttackRange()
&& dstBeing->getType() == ActorType::Monster)
{
- const int attackRange = static_cast<int>(
+ const int attackRange = CAST_S32(
msg.readUInt8("attack range (was karma)"));
dstBeing->setAttackRange(attackRange);
}
@@ -1044,9 +1044,9 @@ void BeingRecv::processBeingMove(Net::MessageIn &msg)
msg.readUInt8("unknown");
dstBeing->setStunMode(stunMode);
- dstBeing->setStatusEffectBlock(0, static_cast<uint16_t>(
+ dstBeing->setStatusEffectBlock(0, CAST_U16(
(statusEffects >> 16) & 0xffff));
- dstBeing->setStatusEffectBlock(16, static_cast<uint16_t>(
+ dstBeing->setStatusEffectBlock(16, CAST_U16(
statusEffects & 0xffff));
BLOCK_END("BeingRecv::processBeingVisibleOrMove")
}
@@ -1162,7 +1162,7 @@ void BeingRecv::processBeingChangeDirection(Net::MessageIn &msg)
msg.readInt16("unused");
const uint8_t dir = Net::MessageIn::fromServerDirection(
- static_cast<uint8_t>(msg.readUInt8("direction") & 0x0FU));
+ CAST_U8(msg.readUInt8("direction") & 0x0FU));
dstBeing->setDirection(dir);
if (localPlayer)
localPlayer->imitateDirection(dstBeing, dir);
@@ -1193,13 +1193,13 @@ void BeingRecv::processPlaterStatusChange(Net::MessageIn &msg)
const uint16_t stunMode = msg.readInt16("stun mode");
uint32_t statusEffects = msg.readInt16("status effect");
- statusEffects |= (static_cast<uint32_t>(msg.readInt16("opt?"))) << 16;
+ statusEffects |= (CAST_U32(msg.readInt16("opt?"))) << 16;
msg.readUInt8("Unused?");
dstBeing->setStunMode(stunMode);
- dstBeing->setStatusEffectBlock(0, static_cast<uint16_t>(
+ dstBeing->setStatusEffectBlock(0, CAST_U16(
(statusEffects >> 16) & 0xffff));
- dstBeing->setStatusEffectBlock(16, static_cast<uint16_t>(
+ dstBeing->setStatusEffectBlock(16, CAST_U16(
statusEffects & 0xffff));
BLOCK_END("BeingRecv::processPlayerStop")
}
@@ -1342,7 +1342,7 @@ void BeingRecv::processPvpSet(Net::MessageIn &msg)
if (dstBeing)
{
dstBeing->setPvpRank(rank);
- dstBeing->setTeamId(static_cast<uint16_t>(teamId));
+ dstBeing->setTeamId(CAST_U16(teamId));
dstBeing->addToCache();
}
}
diff --git a/src/net/tmwa/charserverhandler.cpp b/src/net/tmwa/charserverhandler.cpp
index af0d4ad42..d7b92be1a 100644
--- a/src/net/tmwa/charserverhandler.cpp
+++ b/src/net/tmwa/charserverhandler.cpp
@@ -65,7 +65,7 @@ void CharServerHandler::chooseCharacter(Net::Character *const character)
mCharSelectDialog = nullptr;
createOutPacket(CMSG_CHAR_SELECT);
- outMsg.writeInt8(static_cast<unsigned char>(mSelectedCharacter->slot),
+ outMsg.writeInt8(CAST_U8(mSelectedCharacter->slot),
"slot");
}
@@ -80,12 +80,12 @@ void CharServerHandler::newCharacter(const std::string &name, const int slot,
createOutPacket(CMSG_CHAR_CREATE);
outMsg.writeString(name, 24, "name");
for (int i = 0; i < 6; i++)
- outMsg.writeInt8(static_cast<unsigned char>(stats[i]), "stat");
+ outMsg.writeInt8(CAST_U8(stats[i]), "stat");
- outMsg.writeInt8(static_cast<unsigned char>(slot), "slot");
- outMsg.writeInt8(static_cast<int8_t>(hairColor), "hair color");
+ outMsg.writeInt8(CAST_U8(slot), "slot");
+ outMsg.writeInt8(CAST_S8(hairColor), "hair color");
outMsg.writeInt8(0, "unused");
- outMsg.writeInt8(static_cast<int8_t>(hairstyle), "hair style");
+ outMsg.writeInt8(CAST_S8(hairstyle), "hair style");
outMsg.writeInt8(0, "unused");
}
diff --git a/src/net/tmwa/charserverrecv.cpp b/src/net/tmwa/charserverrecv.cpp
index 1861f8276..5032e4c39 100644
--- a/src/net/tmwa/charserverrecv.cpp
+++ b/src/net/tmwa/charserverrecv.cpp
@@ -145,7 +145,7 @@ void CharServerRecv::readPlayerData(Net::MessageIn &msg,
tempPlayer->setSprite(SPRITE_HEAD_MID, misc2);
character->slot = msg.readUInt8("slot");
- const uint8_t sex = static_cast<uint8_t>(msg.readUInt8("gender"));
+ const uint8_t sex = CAST_U8(msg.readUInt8("gender"));
if (serverFeatures->haveCreateCharGender())
tempPlayer->setGender(Being::intToGender(sex));
else
@@ -159,7 +159,7 @@ void CharServerRecv::processCharLogin(Net::MessageIn &msg)
msg.readInt16("len");
const int slots = msg.readInt16("slots");
if (slots > 0 && slots < 30)
- loginData.characterSlots = static_cast<uint16_t>(slots);
+ loginData.characterSlots = CAST_U16(slots);
msg.skip(18, "unused");
diff --git a/src/net/tmwa/chathandler.cpp b/src/net/tmwa/chathandler.cpp
index 8ac1cf2e6..61a8054ba 100644
--- a/src/net/tmwa/chathandler.cpp
+++ b/src/net/tmwa/chathandler.cpp
@@ -59,24 +59,24 @@ void ChatHandler::talk(const std::string &restrict text,
createOutPacket(CMSG_CHAT_MESSAGE);
// Added + 1 in order to let eAthena parse admin commands correctly
- outMsg.writeInt16(static_cast<int16_t>(mes.length() + 4 + 1), "len");
- outMsg.writeString(mes, static_cast<int>(mes.length() + 1), "message");
+ outMsg.writeInt16(CAST_S16(mes.length() + 4 + 1), "len");
+ outMsg.writeString(mes, CAST_S32(mes.length() + 1), "message");
}
void ChatHandler::talkRaw(const std::string &mes) const
{
createOutPacket(CMSG_CHAT_MESSAGE);
- outMsg.writeInt16(static_cast<int16_t>(mes.length() + 4), "len");
- outMsg.writeString(mes, static_cast<int>(mes.length()), "message");
+ outMsg.writeInt16(CAST_S16(mes.length() + 4), "len");
+ outMsg.writeString(mes, CAST_S32(mes.length()), "message");
}
void ChatHandler::privateMessage(const std::string &restrict recipient,
const std::string &restrict text)
{
createOutPacket(CMSG_CHAT_WHISPER);
- outMsg.writeInt16(static_cast<int16_t>(text.length() + 28), "len");
+ outMsg.writeInt16(CAST_S16(text.length() + 28), "len");
outMsg.writeString(recipient, 24, "recipient nick");
- outMsg.writeString(text, static_cast<int>(text.length()), "message");
+ outMsg.writeString(text, CAST_S32(text.length()), "message");
Ea::ChatRecv::mSentWhispers.push(recipient);
}
@@ -107,7 +107,7 @@ void ChatHandler::sendRaw(const std::string &args) const
if (pos != std::string::npos)
{
str = line.substr(0, pos);
- const int16_t id = static_cast<int16_t>(parseNumber(str));
+ const int16_t id = CAST_S16(parseNumber(str));
outMsg = new MessageOut(id);
outMsg->writeInt16(id, "packet id");
line = line.substr(pos + 1);
@@ -115,7 +115,7 @@ void ChatHandler::sendRaw(const std::string &args) const
}
else
{
- const int16_t id = static_cast<int16_t>(parseNumber(line));
+ const int16_t id = CAST_S16(parseNumber(line));
outMsg = new MessageOut(id);
outMsg->writeInt16(id, "packet id");
delete outMsg;
@@ -145,17 +145,17 @@ void ChatHandler::processRaw(MessageOut &restrict outMsg,
{
case 'b':
{
- outMsg.writeInt8(static_cast<unsigned char>(i), "raw");
+ outMsg.writeInt8(CAST_U8(i), "raw");
break;
}
case 'w':
{
- outMsg.writeInt16(static_cast<int16_t>(i), "raw");
+ outMsg.writeInt16(CAST_S16(i), "raw");
break;
}
case 'l':
{
- outMsg.writeInt32(static_cast<int32_t>(i), "raw");
+ outMsg.writeInt32(CAST_S32(i), "raw");
break;
}
default:
diff --git a/src/net/tmwa/chatrecv.cpp b/src/net/tmwa/chatrecv.cpp
index afa8c1573..27ca74a41 100644
--- a/src/net/tmwa/chatrecv.cpp
+++ b/src/net/tmwa/chatrecv.cpp
@@ -314,7 +314,7 @@ void ChatRecv::processBeingChat(Net::MessageIn &msg)
if (being)
sender_name = being->getName();
if (sender_name.empty())
- sender_name = "?" + toString(static_cast<int>(beingId));
+ sender_name = "?" + toString(CAST_S32(beingId));
}
else if (being &&
sender_name != being->getName() &&
diff --git a/src/net/tmwa/generalrecv.cpp b/src/net/tmwa/generalrecv.cpp
index d8b0c808b..2926f0ef5 100644
--- a/src/net/tmwa/generalrecv.cpp
+++ b/src/net/tmwa/generalrecv.cpp
@@ -40,7 +40,7 @@ ServerInfo mapServer;
void GeneralRecv::processConnectionProblem(Net::MessageIn &msg)
{
const uint8_t code = msg.readUInt8("flag");
- logger->log("Connection problem: %u", static_cast<unsigned int>(code));
+ logger->log("Connection problem: %u", CAST_U32(code));
switch (code)
{
diff --git a/src/net/tmwa/guildhandler.cpp b/src/net/tmwa/guildhandler.cpp
index dce3385bf..4f0db44c7 100644
--- a/src/net/tmwa/guildhandler.cpp
+++ b/src/net/tmwa/guildhandler.cpp
@@ -124,8 +124,8 @@ void GuildHandler::chat(const std::string &text) const
const std::string str = std::string(localPlayer->getName()).append(
" : ").append(text);
createOutPacket(CMSG_GUILD_MESSAGE);
- outMsg.writeInt16(static_cast<uint16_t>(str.size() + 4), "len");
- outMsg.writeString(str, static_cast<int>(str.length()), "message");
+ outMsg.writeInt16(CAST_U16(str.size() + 4), "len");
+ outMsg.writeString(str, CAST_S32(str.length()), "message");
}
void GuildHandler::memberList() const
diff --git a/src/net/tmwa/guildrecv.cpp b/src/net/tmwa/guildrecv.cpp
index 53f8aeb71..4073dd936 100644
--- a/src/net/tmwa/guildrecv.cpp
+++ b/src/net/tmwa/guildrecv.cpp
@@ -55,7 +55,7 @@ void GuildRecv::processGuildPositionInfo(Net::MessageIn &msg)
PlayerInfo::setGuildPositionFlags(GuildPositionFlags::Invite);
- Guild *const g = Guild::getGuild(static_cast<int16_t>(guildId));
+ Guild *const g = Guild::getGuild(CAST_S16(guildId));
if (!g)
return;
diff --git a/src/net/tmwa/inventoryhandler.cpp b/src/net/tmwa/inventoryhandler.cpp
index 24d76eab7..fa71484e6 100644
--- a/src/net/tmwa/inventoryhandler.cpp
+++ b/src/net/tmwa/inventoryhandler.cpp
@@ -73,7 +73,7 @@ void InventoryHandler::equipItem(const Item *const item) const
return;
createOutPacket(CMSG_PLAYER_EQUIP);
- outMsg.writeInt16(static_cast<int16_t>(
+ outMsg.writeInt16(CAST_S16(
item->getInvIndex() + INVENTORY_OFFSET), "index");
outMsg.writeInt16(0, "unused");
}
@@ -84,7 +84,7 @@ void InventoryHandler::unequipItem(const Item *const item) const
return;
createOutPacket(CMSG_PLAYER_UNEQUIP);
- outMsg.writeInt16(static_cast<int16_t>(
+ outMsg.writeInt16(CAST_S16(
item->getInvIndex() + INVENTORY_OFFSET), "index");
}
@@ -94,7 +94,7 @@ void InventoryHandler::useItem(const Item *const item) const
return;
createOutPacket(CMSG_PLAYER_INVENTORY_USE);
- outMsg.writeInt16(static_cast<int16_t>(
+ outMsg.writeInt16(CAST_S16(
item->getInvIndex() + INVENTORY_OFFSET), "index");
outMsg.writeInt32(item->getId(), "item id");
}
@@ -105,9 +105,9 @@ void InventoryHandler::dropItem(const Item *const item, const int amount) const
return;
createOutPacket(CMSG_PLAYER_INVENTORY_DROP);
- outMsg.writeInt16(static_cast<int16_t>(
+ outMsg.writeInt16(CAST_S16(
item->getInvIndex() + INVENTORY_OFFSET), "index");
- outMsg.writeInt16(static_cast<int16_t>(amount), "amount");
+ outMsg.writeInt16(CAST_S16(amount), "amount");
}
void InventoryHandler::closeStorage() const
@@ -124,7 +124,7 @@ void InventoryHandler::moveItem2(const InventoryTypeT source,
destination == InventoryType::Storage)
{
createOutPacket(CMSG_MOVE_TO_STORAGE);
- outMsg.writeInt16(static_cast<int16_t>(slot + INVENTORY_OFFSET),
+ outMsg.writeInt16(CAST_S16(slot + INVENTORY_OFFSET),
"index");
outMsg.writeInt32(amount, "amount");
}
@@ -132,7 +132,7 @@ void InventoryHandler::moveItem2(const InventoryTypeT source,
destination == InventoryType::Inventory)
{
createOutPacket(CMSG_MOVE_FROM_STORAGE);
- outMsg.writeInt16(static_cast<int16_t>(slot + STORAGE_OFFSET),
+ outMsg.writeInt16(CAST_S16(slot + STORAGE_OFFSET),
"index");
outMsg.writeInt32(amount, "amount");
}
@@ -161,7 +161,7 @@ int InventoryHandler::convertFromServerSlot(const int serverSlot) const
if (serverSlot < 0 || serverSlot > 13)
return 0;
- return static_cast<int>(EQUIP_CONVERT[serverSlot]);
+ return CAST_S32(EQUIP_CONVERT[serverSlot]);
}
void InventoryHandler::selectCart(const BeingId accountId A_UNUSED,
diff --git a/src/net/tmwa/inventoryrecv.cpp b/src/net/tmwa/inventoryrecv.cpp
index ce59dc274..2ba71b73d 100644
--- a/src/net/tmwa/inventoryrecv.cpp
+++ b/src/net/tmwa/inventoryrecv.cpp
@@ -380,9 +380,9 @@ void InventoryRecv::processPlayerStorageEquip(Net::MessageIn &msg)
logger->log("Index: %d, ID: %d, Type: %d, Identified: %u, "
"Qty: %d, Cards: %d, %d, %d, %d, Refine: %u",
index, itemId, itemType,
- static_cast<unsigned int>(identified), amount,
+ CAST_U32(identified), amount,
cards[0], cards[1], cards[2], cards[3],
- static_cast<unsigned int>(refine));
+ CAST_U32(refine));
}
Ea::InventoryRecv::mInventoryItems.push_back(Ea::InventoryItem(
diff --git a/src/net/tmwa/itemrecv.cpp b/src/net/tmwa/itemrecv.cpp
index b9a7d55b1..d7038942d 100644
--- a/src/net/tmwa/itemrecv.cpp
+++ b/src/net/tmwa/itemrecv.cpp
@@ -38,8 +38,8 @@ void ItemRecv::processItemDropped(Net::MessageIn &msg)
const Identified identify = fromInt(msg.readUInt8("identify"), Identified);
const int x = msg.readInt16("x");
const int y = msg.readInt16("y");
- const int subX = static_cast<int>(msg.readInt8("sub x"));
- const int subY = static_cast<int>(msg.readInt8("sub y"));
+ const int subX = CAST_S32(msg.readInt8("sub x"));
+ const int subY = CAST_S32(msg.readInt8("sub y"));
const int amount = msg.readInt16("amount");
if (actorManager)
@@ -67,8 +67,8 @@ void ItemRecv::processItemVisible(Net::MessageIn &msg)
const int x = msg.readInt16("x");
const int y = msg.readInt16("y");
const int amount = msg.readInt16("amount");
- const int subX = static_cast<int>(msg.readInt8("sub x"));
- const int subY = static_cast<int>(msg.readInt8("sub y"));
+ const int subX = CAST_S32(msg.readInt8("sub x"));
+ const int subY = CAST_S32(msg.readInt8("sub y"));
if (actorManager)
{
diff --git a/src/net/tmwa/messagein.cpp b/src/net/tmwa/messagein.cpp
index 21e679b25..c8cf350e7 100644
--- a/src/net/tmwa/messagein.cpp
+++ b/src/net/tmwa/messagein.cpp
@@ -56,10 +56,10 @@ uint16_t MessageIn::readId()
{
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
int16_t swap;
- memcpy(&swap, mData + static_cast<size_t>(mPos), sizeof(int16_t));
+ memcpy(&swap, mData + CAST_SIZE(mPos), sizeof(int16_t));
value = SDL_Swap16(swap);
#else
- memcpy(&value, mData + static_cast<size_t>(mPos), sizeof(int16_t));
+ memcpy(&value, mData + CAST_SIZE(mPos), sizeof(int16_t));
#endif
}
return value;
@@ -72,14 +72,14 @@ int16_t MessageIn::readInt16(const char *const str)
{
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
int16_t swap;
- memcpy(&swap, mData + static_cast<size_t>(mPos), sizeof(int16_t));
+ memcpy(&swap, mData + CAST_SIZE(mPos), sizeof(int16_t));
value = SDL_Swap16(swap);
#else
- memcpy(&value, mData + static_cast<size_t>(mPos), sizeof(int16_t));
+ memcpy(&value, mData + CAST_SIZE(mPos), sizeof(int16_t));
#endif
}
- DEBUGLOG2("readInt16: " + toStringPrint(static_cast<unsigned int>(
- static_cast<uint16_t>(value))),
+ DEBUGLOG2("readInt16: " + toStringPrint(CAST_U32(
+ CAST_U16(value))),
mPos, str);
mPos += 2;
PacketCounters::incInBytes(2);
@@ -93,13 +93,13 @@ int32_t MessageIn::readInt32(const char *const str)
{
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
int32_t swap;
- memcpy(&swap, mData + static_cast<size_t>(mPos), sizeof(int32_t));
+ memcpy(&swap, mData + CAST_SIZE(mPos), sizeof(int32_t));
value = SDL_Swap32(swap);
#else
- memcpy(&value, mData + static_cast<size_t>(mPos), sizeof(int32_t));
+ memcpy(&value, mData + CAST_SIZE(mPos), sizeof(int32_t));
#endif
}
- DEBUGLOG2("readInt32: " + toStringPrint(static_cast<unsigned int>(value)),
+ DEBUGLOG2("readInt32: " + toStringPrint(CAST_U32(value)),
mPos, str);
mPos += 4;
PacketCounters::incInBytes(4);
@@ -118,13 +118,13 @@ int64_t MessageIn::readInt64(const char *const str)
{
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
int64_t swap;
- memcpy(&swap, mData + static_cast<size_t>(mPos), sizeof(int64_t));
+ memcpy(&swap, mData + CAST_SIZE(mPos), sizeof(int64_t));
value = SDL_Swap64(swap);
#else
- memcpy(&value, mData + static_cast<size_t>(mPos), sizeof(int64_t));
+ memcpy(&value, mData + CAST_SIZE(mPos), sizeof(int64_t));
#endif
}
- DEBUGLOG2("readInt64: " + toStringPrint(static_cast<unsigned int>(value)),
+ DEBUGLOG2("readInt64: " + toStringPrint(CAST_U32(value)),
mPos, str);
mPos += 8;
PacketCounters::incInBytes(8);
diff --git a/src/net/tmwa/messageout.cpp b/src/net/tmwa/messageout.cpp
index a2c0770b7..c0ac1ef03 100644
--- a/src/net/tmwa/messageout.cpp
+++ b/src/net/tmwa/messageout.cpp
@@ -40,26 +40,26 @@ MessageOut::MessageOut(const int16_t id) :
mNetwork(TmwAthena::Network::instance())
{
mNetwork->fixSendBuffer();
- mData = mNetwork->mOutBuffer + static_cast<size_t>(mNetwork->mOutSize);
+ mData = mNetwork->mOutBuffer + CAST_SIZE(mNetwork->mOutSize);
}
void MessageOut::expand(const size_t bytes)
{
- mNetwork->mOutSize += static_cast<unsigned>(bytes);
- PacketCounters::incOutBytes(static_cast<int>(bytes));
+ mNetwork->mOutSize += CAST_U32(bytes);
+ PacketCounters::incOutBytes(CAST_S32(bytes));
}
void MessageOut::writeInt16(const int16_t value, const char *const str)
{
- DEBUGLOG2("writeInt16: " + toStringPrint(static_cast<unsigned int>(
- static_cast<uint16_t>(value))),
+ DEBUGLOG2("writeInt16: " + toStringPrint(CAST_U32(
+ CAST_U16(value))),
mPos, str);
expand(2);
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
int16_t swap = SDL_Swap16(value);
- memcpy(mData + static_cast<size_t>(mPos), &swap, sizeof(int16_t));
+ memcpy(mData + CAST_SIZE(mPos), &swap, sizeof(int16_t));
#else
- memcpy(mData + static_cast<size_t>(mPos), &value, sizeof(int16_t));
+ memcpy(mData + CAST_SIZE(mPos), &value, sizeof(int16_t));
#endif
mPos += 2;
PacketCounters::incOutBytes(2);
@@ -67,14 +67,14 @@ void MessageOut::writeInt16(const int16_t value, const char *const str)
void MessageOut::writeInt32(const int32_t value, const char *const str)
{
- DEBUGLOG2("writeInt32: " + toStringPrint(static_cast<unsigned int>(value)),
+ DEBUGLOG2("writeInt32: " + toStringPrint(CAST_U32(value)),
mPos, str);
expand(4);
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
int32_t swap = SDL_Swap32(value);
- memcpy(mData + static_cast<size_t>(mPos), &swap, sizeof(int32_t));
+ memcpy(mData + CAST_SIZE(mPos), &swap, sizeof(int32_t));
#else
- memcpy(mData + static_cast<size_t>(mPos), &value, sizeof(int32_t));
+ memcpy(mData + CAST_SIZE(mPos), &value, sizeof(int32_t));
#endif
mPos += 4;
PacketCounters::incOutBytes(4);
@@ -85,9 +85,9 @@ void MessageOut::writeBeingId(const BeingId value, const char *const str)
writeInt32(toInt(value, int32_t), str);
}
-#define LOBYTE(w) (static_cast<unsigned char>(w))
-#define HIBYTE(w) (static_cast<unsigned char>(( \
-static_cast<uint16_t>(w)) >> 8U))
+#define LOBYTE(w) (CAST_U8(w))
+#define HIBYTE(w) (CAST_U8(( \
+CAST_U16(w)) >> 8U))
void MessageOut::writeCoordinates(const uint16_t x,
const uint16_t y,
@@ -95,10 +95,10 @@ void MessageOut::writeCoordinates(const uint16_t x,
const char *const str)
{
DEBUGLOG2(strprintf("writeCoordinates: %u,%u %u",
- static_cast<unsigned>(x), static_cast<unsigned>(y),
- static_cast<unsigned>(direction)), mPos, str);
+ CAST_U32(x), static_cast<unsigned>(y),
+ CAST_U32(direction)), mPos, str);
unsigned char *const data = reinterpret_cast<unsigned char*>(mData)
- + static_cast<size_t>(mPos);
+ + CAST_SIZE(mPos);
mNetwork->mOutSize += 3;
mPos += 3;
@@ -108,7 +108,7 @@ void MessageOut::writeCoordinates(const uint16_t x,
data[1] = 1;
data[2] = 2;
data[0] = HIBYTE(temp);
- data[1] = static_cast<unsigned char>(temp);
+ data[1] = CAST_U8(temp);
temp = y;
temp <<= 4;
data[1] |= HIBYTE(temp);
diff --git a/src/net/tmwa/network.cpp b/src/net/tmwa/network.cpp
index 9be9d34b6..03a842b65 100644
--- a/src/net/tmwa/network.cpp
+++ b/src/net/tmwa/network.cpp
@@ -156,7 +156,7 @@ bool Network::messageReady()
if (mInSize >= 2)
{
const int msgId = readWord(0);
- if (msgId >= 0 && static_cast<unsigned int>(msgId)
+ if (msgId >= 0 && CAST_U32(msgId)
< packet_lengths_size)
{
len = mPackets[msgId].len;
@@ -166,7 +166,7 @@ bool Network::messageReady()
len = readWord(2);
}
- const bool ret = (mInSize >= static_cast<unsigned int>(len));
+ const bool ret = (mInSize >= CAST_U32(len));
SDL_mutexV(mMutexIn);
return ret;
diff --git a/src/net/tmwa/npchandler.cpp b/src/net/tmwa/npchandler.cpp
index a3e0ef2c3..ba1c8f7a3 100644
--- a/src/net/tmwa/npchandler.cpp
+++ b/src/net/tmwa/npchandler.cpp
@@ -100,9 +100,9 @@ void NpcHandler::stringInput(const BeingId npcId,
const std::string &value) const
{
createOutPacket(CMSG_NPC_STR_RESPONSE);
- outMsg.writeInt16(static_cast<int16_t>(value.length() + 9), "len");
+ outMsg.writeInt16(CAST_S16(value.length() + 9), "len");
outMsg.writeBeingId(npcId, "npc id");
- outMsg.writeString(value, static_cast<int>(value.length()), "value");
+ outMsg.writeString(value, CAST_S32(value.length()), "value");
outMsg.writeInt8(0, "null byte");
}
@@ -127,8 +127,8 @@ void NpcHandler::buyItem(const BeingId beingId A_UNUSED,
{
createOutPacket(CMSG_NPC_BUY_REQUEST);
outMsg.writeInt16(8, "len");
- outMsg.writeInt16(static_cast<int16_t>(amount), "amount");
- outMsg.writeInt16(static_cast<int16_t>(itemId), "item id");
+ outMsg.writeInt16(CAST_S16(amount), "amount");
+ outMsg.writeInt16(CAST_S16(itemId), "item id");
}
void NpcHandler::buyItems(std::vector<ShopItem*> &items A_UNUSED) const
@@ -141,9 +141,9 @@ void NpcHandler::sellItem(const BeingId beingId A_UNUSED,
{
createOutPacket(CMSG_NPC_SELL_REQUEST);
outMsg.writeInt16(8, "len");
- outMsg.writeInt16(static_cast<int16_t>(
+ outMsg.writeInt16(CAST_S16(
itemId + INVENTORY_OFFSET), "index");
- outMsg.writeInt16(static_cast<int16_t>(amount), "amount");
+ outMsg.writeInt16(CAST_S16(amount), "amount");
}
void NpcHandler::sellItems(std::vector<ShopItem*> &items A_UNUSED) const
diff --git a/src/net/tmwa/partyhandler.cpp b/src/net/tmwa/partyhandler.cpp
index 8c477e9ec..94471e4c3 100644
--- a/src/net/tmwa/partyhandler.cpp
+++ b/src/net/tmwa/partyhandler.cpp
@@ -117,8 +117,8 @@ void PartyHandler::kick(const std::string &name) const
void PartyHandler::chat(const std::string &text) const
{
createOutPacket(CMSG_PARTY_MESSAGE);
- outMsg.writeInt16(static_cast<int16_t>(text.length() + 4), "len");
- outMsg.writeString(text, static_cast<int>(text.length()), "text");
+ outMsg.writeInt16(CAST_S16(text.length() + 4), "len");
+ outMsg.writeString(text, CAST_S32(text.length()), "text");
}
void PartyHandler::setShareExperience(const PartyShareT share) const
@@ -127,8 +127,8 @@ void PartyHandler::setShareExperience(const PartyShareT share) const
return;
createOutPacket(CMSG_PARTY_SETTINGS);
- outMsg.writeInt16(static_cast<int16_t>(share), "share exp");
- outMsg.writeInt16(static_cast<int16_t>(Ea::PartyRecv::mShareItems),
+ outMsg.writeInt16(CAST_S16(share), "share exp");
+ outMsg.writeInt16(CAST_S16(Ea::PartyRecv::mShareItems),
"share items");
}
@@ -138,9 +138,9 @@ void PartyHandler::setShareItems(const PartyShareT share) const
return;
createOutPacket(CMSG_PARTY_SETTINGS);
- outMsg.writeInt16(static_cast<int16_t>(Ea::PartyRecv::mShareExp),
+ outMsg.writeInt16(CAST_S16(Ea::PartyRecv::mShareExp),
"share exp");
- outMsg.writeInt16(static_cast<int16_t>(share), "share items");
+ outMsg.writeInt16(CAST_S16(share), "share items");
}
void PartyHandler::changeLeader(const std::string &name A_UNUSED) const
diff --git a/src/net/tmwa/pethandler.cpp b/src/net/tmwa/pethandler.cpp
index 427ec3ba9..1aaf0e710 100644
--- a/src/net/tmwa/pethandler.cpp
+++ b/src/net/tmwa/pethandler.cpp
@@ -60,7 +60,7 @@ void PetHandler::emote(const uint8_t emoteId, const int petId A_UNUSED)
mRandCounter = 1000;
chatHandler->talk(strprintf("\302\202\302e%dz%d",
- static_cast<int>(emoteId), mRandCounter), GENERAL_CHANNEL);
+ CAST_S32(emoteId), mRandCounter), GENERAL_CHANNEL);
}
void PetHandler::catchPet(const Being *const being A_UNUSED) const
@@ -98,7 +98,7 @@ void PetHandler::unequip() const
void PetHandler::setDirection(const unsigned char type) const
{
chatHandler->talk(strprintf("\302\202\302d%dg%d",
- static_cast<int>(type), tick_time), GENERAL_CHANNEL);
+ CAST_S32(type), tick_time), GENERAL_CHANNEL);
}
void PetHandler::startAi(const bool start) const
diff --git a/src/net/tmwa/playerhandler.cpp b/src/net/tmwa/playerhandler.cpp
index f0ea94947..8f7de1e64 100644
--- a/src/net/tmwa/playerhandler.cpp
+++ b/src/net/tmwa/playerhandler.cpp
@@ -70,7 +70,7 @@ void PlayerHandler::increaseAttribute(const AttributesT attr) const
if (attr >= Attributes::STR && attr <= Attributes::LUK)
{
createOutPacket(CMSG_STAT_UPDATE_REQUEST);
- outMsg.writeInt16(static_cast<int16_t>(attr), "attribute id");
+ outMsg.writeInt16(CAST_S16(attr), "attribute id");
outMsg.writeInt8(1, "increment");
}
}
@@ -108,9 +108,9 @@ void PlayerHandler::setDestination(const int x, const int y,
const int direction) const
{
createOutPacket(CMSG_PLAYER_CHANGE_DEST);
- outMsg.writeCoordinates(static_cast<uint16_t>(x),
- static_cast<uint16_t>(y),
- static_cast<unsigned char>(direction), "destination");
+ outMsg.writeCoordinates(CAST_U16(x),
+ CAST_U16(y),
+ CAST_U8(direction), "destination");
}
void PlayerHandler::changeAction(const BeingActionT &action) const
diff --git a/src/net/tmwa/skillhandler.cpp b/src/net/tmwa/skillhandler.cpp
index abd2fd67e..87dc0e189 100644
--- a/src/net/tmwa/skillhandler.cpp
+++ b/src/net/tmwa/skillhandler.cpp
@@ -42,8 +42,8 @@ void SkillHandler::useBeing(const int id, const int level,
const BeingId beingId) const
{
createOutPacket(CMSG_SKILL_USE_BEING);
- outMsg.writeInt16(static_cast<int16_t>(id), "skill id");
- outMsg.writeInt16(static_cast<int16_t>(level), "level");
+ outMsg.writeInt16(CAST_S16(id), "skill id");
+ outMsg.writeInt16(CAST_S16(level), "level");
outMsg.writeBeingId(beingId, "target id");
}
@@ -51,10 +51,10 @@ void SkillHandler::usePos(const int id, const int level,
const int x, const int y) const
{
createOutPacket(CMSG_SKILL_USE_POSITION);
- outMsg.writeInt16(static_cast<int16_t>(level), "skill level");
- outMsg.writeInt16(static_cast<int16_t>(id), "skill id");
- outMsg.writeInt16(static_cast<int16_t>(x), "x");
- outMsg.writeInt16(static_cast<int16_t>(y), "y");
+ outMsg.writeInt16(CAST_S16(level), "skill level");
+ outMsg.writeInt16(CAST_S16(id), "skill id");
+ outMsg.writeInt16(CAST_S16(x), "x");
+ outMsg.writeInt16(CAST_S16(y), "y");
}
void SkillHandler::usePos(const int id, const int level,
@@ -62,17 +62,17 @@ void SkillHandler::usePos(const int id, const int level,
const std::string &text) const
{
createOutPacket(CMSG_SKILL_USE_POSITION_MORE);
- outMsg.writeInt16(static_cast<int16_t>(level), "skill level");
- outMsg.writeInt16(static_cast<int16_t>(id), "skill id");
- outMsg.writeInt16(static_cast<int16_t>(x), "x");
- outMsg.writeInt16(static_cast<int16_t>(y), "y");
+ outMsg.writeInt16(CAST_S16(level), "skill level");
+ outMsg.writeInt16(CAST_S16(id), "skill id");
+ outMsg.writeInt16(CAST_S16(x), "x");
+ outMsg.writeInt16(CAST_S16(y), "y");
outMsg.writeString(text, 80, "text");
}
void SkillHandler::useMap(const int id, const std::string &map) const
{
createOutPacket(CMSG_SKILL_USE_MAP);
- outMsg.writeInt16(static_cast<int16_t>(id), "skill id");
+ outMsg.writeInt16(CAST_S16(id), "skill id");
outMsg.writeString(map, 16, "map name");
}
diff --git a/src/net/tmwa/skillrecv.cpp b/src/net/tmwa/skillrecv.cpp
index d79f36422..df914568b 100644
--- a/src/net/tmwa/skillrecv.cpp
+++ b/src/net/tmwa/skillrecv.cpp
@@ -89,19 +89,19 @@ void SkillRecv::processSkillFailed(Net::MessageIn &msg)
msg.readInt16("btype");
const signed char success = msg.readUInt8("success");
const signed char reason = msg.readUInt8("reason");
- if (success != static_cast<int>(SKILL_FAILED)
- && bskill == static_cast<int>(BSKILL_EMOTE))
+ if (success != CAST_S32(SKILL_FAILED)
+ && bskill == CAST_S32(BSKILL_EMOTE))
{
logger->log("Action: %d/%d", bskill, success);
}
std::string txt;
- if (success == static_cast<int>(SKILL_FAILED)
- && skillId == static_cast<int>(SKILL_BASIC))
+ if (success == CAST_S32(SKILL_FAILED)
+ && skillId == CAST_S32(SKILL_BASIC))
{
if (localPlayer &&
- bskill == static_cast<int>(BSKILL_EMOTE) &&
- reason == static_cast<int>(RFAIL_SKILLDEP))
+ bskill == CAST_S32(BSKILL_EMOTE) &&
+ reason == CAST_S32(RFAIL_SKILLDEP))
{
localPlayer->stopAdvert();
}
diff --git a/src/net/tmwa/tradehandler.cpp b/src/net/tmwa/tradehandler.cpp
index 40f737d22..66865740e 100644
--- a/src/net/tmwa/tradehandler.cpp
+++ b/src/net/tmwa/tradehandler.cpp
@@ -61,7 +61,7 @@ void TradeHandler::respond(const bool accept) const
PlayerInfo::setTrading(Trading_false);
createOutPacket(CMSG_TRADE_RESPONSE);
- outMsg.writeInt8(static_cast<int8_t>(accept ? 3 : 4), "accept");
+ outMsg.writeInt8(CAST_S8(accept ? 3 : 4), "accept");
}
void TradeHandler::addItem(const Item *const item, const int amount) const
@@ -70,7 +70,7 @@ void TradeHandler::addItem(const Item *const item, const int amount) const
return;
createOutPacket(CMSG_TRADE_ITEM_ADD_REQUEST);
- outMsg.writeInt16(static_cast<int16_t>(
+ outMsg.writeInt16(CAST_S16(
item->getInvIndex() + INVENTORY_OFFSET), "index");
outMsg.writeInt32(amount, "amount");
}
diff --git a/src/net/updatetypeoperators.cpp b/src/net/updatetypeoperators.cpp
index 0a2444b99..1fad95ff9 100644
--- a/src/net/updatetypeoperators.cpp
+++ b/src/net/updatetypeoperators.cpp
@@ -24,15 +24,15 @@
int operator&(const UpdateTypeT &a, const UpdateTypeT &b)
{
- return static_cast<int>(a) & static_cast<int>(b);
+ return CAST_S32(a) & CAST_S32(b);
}
int operator|(const UpdateTypeT &a, const UpdateTypeT &b)
{
- return static_cast<int>(a) | static_cast<int>(b);
+ return CAST_S32(a) | CAST_S32(b);
}
int operator|(const int &a, const UpdateTypeT &b)
{
- return a | static_cast<int>(b);
+ return a | CAST_S32(b);
}
diff --git a/src/particle/imageparticle.cpp b/src/particle/imageparticle.cpp
index 651c879d7..d6914eafc 100644
--- a/src/particle/imageparticle.cpp
+++ b/src/particle/imageparticle.cpp
@@ -75,9 +75,9 @@ void ImageParticle::draw(Graphics *restrict const graphics,
if (mAlive != AliveStatus::ALIVE || !mImage)
return;
- const int screenX = static_cast<int>(mPos.x)
+ const int screenX = CAST_S32(mPos.x)
+ offsetX - mImage->mBounds.w / 2;
- const int screenY = static_cast<int>(mPos.y) - static_cast<int>(mPos.z)
+ const int screenY = CAST_S32(mPos.y) - CAST_S32(mPos.z)
+ offsetY - mImage->mBounds.h / 2;
// Check if on screen
diff --git a/src/particle/particle.cpp b/src/particle/particle.cpp
index f22f11252..73cbb4b0d 100644
--- a/src/particle/particle.cpp
+++ b/src/particle/particle.cpp
@@ -223,7 +223,7 @@ bool Particle::update() restrict2
if (mAlive != AliveStatus::ALIVE &&
mAlive != AliveStatus::DEAD_LONG_AGO)
{
- if ((static_cast<unsigned int>(mAlive) & mDeathEffectConditions)
+ if ((CAST_U32(mAlive) & mDeathEffectConditions)
> 0x00 && !mDeathEffect.empty())
{
Particle *restrict const deathEffect = particleEngine->addEffect(
@@ -396,27 +396,27 @@ Particle *Particle::addEffect(const std::string &restrict particleEffectFile,
char deathEffectConditions = 0x00;
if (XML::getBoolProperty(emitterNode, "on-floor", true))
{
- deathEffectConditions += static_cast<signed char>(
+ deathEffectConditions += CAST_S8(
AliveStatus::DEAD_FLOOR);
}
if (XML::getBoolProperty(emitterNode, "on-sky", true))
{
- deathEffectConditions += static_cast<signed char>(
+ deathEffectConditions += CAST_S8(
AliveStatus::DEAD_SKY);
}
if (XML::getBoolProperty(emitterNode, "on-other", false))
{
- deathEffectConditions += static_cast<signed char>(
+ deathEffectConditions += CAST_S8(
AliveStatus::DEAD_OTHER);
}
if (XML::getBoolProperty(emitterNode, "on-impact", true))
{
- deathEffectConditions += static_cast<signed char>(
+ deathEffectConditions += CAST_S8(
AliveStatus::DEAD_IMPACT);
}
if (XML::getBoolProperty(emitterNode, "on-timeout", true))
{
- deathEffectConditions += static_cast<signed char>(
+ deathEffectConditions += CAST_S8(
AliveStatus::DEAD_TIMEOUT);
}
newParticle->setDeathEffect(
diff --git a/src/particle/particle.h b/src/particle/particle.h
index 9c2cb1a09..72c40493d 100644
--- a/src/particle/particle.h
+++ b/src/particle/particle.h
@@ -94,13 +94,13 @@ class Particle notfinal : public Actor
* Necessary for sorting with the other sprites.
*/
int getPixelY() const restrict2 override A_WARN_UNUSED
- { return static_cast<int>(mPos.y) - 16; }
+ { return CAST_S32(mPos.y) - 16; }
/**
* Necessary for sorting with the other sprites for sorting only.
*/
int getSortPixelY() const restrict2 override A_WARN_UNUSED
- { return static_cast<int>(mPos.y) - 16; }
+ { return CAST_S32(mPos.y) - 16; }
/**
* Creates a blank particle as a child of the current particle
diff --git a/src/particle/particleemitter.cpp b/src/particle/particleemitter.cpp
index a512cff94..d82282060 100644
--- a/src/particle/particleemitter.cpp
+++ b/src/particle/particleemitter.cpp
@@ -323,27 +323,27 @@ ParticleEmitter::ParticleEmitter(const XmlNodePtrConst emitterNode,
mDeathEffectConditions = 0x00;
if (XML::getBoolProperty(propertyNode, "on-floor", true))
{
- mDeathEffectConditions += static_cast<signed char>(
+ mDeathEffectConditions += CAST_S8(
AliveStatus::DEAD_FLOOR);
}
if (XML::getBoolProperty(propertyNode, "on-sky", true))
{
- mDeathEffectConditions += static_cast<signed char>(
+ mDeathEffectConditions += CAST_S8(
AliveStatus::DEAD_SKY);
}
if (XML::getBoolProperty(propertyNode, "on-other", false))
{
- mDeathEffectConditions += static_cast<signed char>(
+ mDeathEffectConditions += CAST_S8(
AliveStatus::DEAD_OTHER);
}
if (XML::getBoolProperty(propertyNode, "on-impact", true))
{
- mDeathEffectConditions += static_cast<signed char>(
+ mDeathEffectConditions += CAST_S8(
AliveStatus::DEAD_IMPACT);
}
if (XML::getBoolProperty(propertyNode, "on-timeout", true))
{
- mDeathEffectConditions += static_cast<signed char>(
+ mDeathEffectConditions += CAST_S8(
AliveStatus::DEAD_TIMEOUT);
}
}
@@ -593,8 +593,8 @@ void ParticleEmitter::adjustSize(const int w, const int h)
return; // new dimensions are illegal
// calculate the old rectangle
- const int oldArea = static_cast<int>(
- mParticlePosX.maxVal - mParticlePosX.minVal) * static_cast<int>(
+ const int oldArea = CAST_S32(
+ mParticlePosX.maxVal - mParticlePosX.minVal) * CAST_S32(
mParticlePosX.maxVal - mParticlePosY.minVal);
if (oldArea == 0)
{
@@ -610,8 +610,8 @@ void ParticleEmitter::adjustSize(const int w, const int h)
// adjust the output so that the particle density stays the same
const float outputFactor = static_cast<float>(newArea)
/ static_cast<float>(oldArea);
- mOutput.minVal = static_cast<int>(static_cast<float>(
+ mOutput.minVal = CAST_S32(static_cast<float>(
mOutput.minVal) * outputFactor);
- mOutput.maxVal = static_cast<int>(static_cast<float>(
+ mOutput.maxVal = CAST_S32(static_cast<float>(
mOutput.maxVal) * outputFactor);
}
diff --git a/src/particle/particlevector.cpp b/src/particle/particlevector.cpp
index a09f6d7ae..d0594a2dd 100644
--- a/src/particle/particlevector.cpp
+++ b/src/particle/particlevector.cpp
@@ -41,7 +41,7 @@ void ParticleVector::setLocally(const int index, Particle *const particle)
delLocally(index);
- if (mIndexedElements.size() <= static_cast<size_t>(index))
+ if (mIndexedElements.size() <= CAST_SIZE(index))
mIndexedElements.resize(index + 1, nullptr);
if (particle)
@@ -54,7 +54,7 @@ void ParticleVector::delLocally(const int index)
if (index < 0)
return;
- if (mIndexedElements.size() <= static_cast<size_t>(index))
+ if (mIndexedElements.size() <= CAST_SIZE(index))
return;
Particle *const p = mIndexedElements[index];
@@ -68,7 +68,7 @@ void ParticleVector::delLocally(const int index)
void ParticleVector::clearLocally()
{
for (unsigned int i = 0;
- i < static_cast<unsigned int>(mIndexedElements.size());
+ i < CAST_U32(mIndexedElements.size());
i++)
{
delLocally(i);
diff --git a/src/particle/textparticle.cpp b/src/particle/textparticle.cpp
index 8a886f27d..399e00a01 100644
--- a/src/particle/textparticle.cpp
+++ b/src/particle/textparticle.cpp
@@ -55,8 +55,8 @@ void TextParticle::draw(Graphics *restrict const graphics,
return;
}
- const int screenX = static_cast<int>(mPos.x) + offsetX;
- const int screenY = static_cast<int>(mPos.y) - static_cast<int>(mPos.z)
+ const int screenX = CAST_S32(mPos.x) + offsetX;
+ const int screenY = CAST_S32(mPos.y) - CAST_S32(mPos.z)
+ offsetY;
float alpha = mAlpha * 255.0F;
@@ -74,13 +74,13 @@ void TextParticle::draw(Graphics *restrict const graphics,
}
Color color = *mColor;
- color.a = static_cast<unsigned int>(alpha);
+ color.a = CAST_U32(alpha);
graphics->setColor(color);
if (mOutline)
{
const Color &restrict color2 = theme->getColor(ThemeColorId::OUTLINE,
- static_cast<int>(alpha));
+ CAST_S32(alpha));
mTextFont->drawString(graphics,
color, color2,
mText,
diff --git a/src/particle/textparticle.h b/src/particle/textparticle.h
index 70dbad956..7064a5358 100644
--- a/src/particle/textparticle.h
+++ b/src/particle/textparticle.h
@@ -48,11 +48,11 @@ class TextParticle final : public Particle
// hack to improve text visibility
int getPixelY() const restrict2 override final A_WARN_UNUSED
- { return static_cast<int>(mPos.y + mPos.z); }
+ { return CAST_S32(mPos.y + mPos.z); }
// hack to improve text visibility (for sorting only)
int getSortPixelY() const restrict2 override final A_WARN_UNUSED
- { return static_cast<int>(mPos.y + mPos.z); }
+ { return CAST_S32(mPos.y + mPos.z); }
private:
std::string mText; /**< Text of the particle. */
diff --git a/src/party.h b/src/party.h
index d3293d871..51cfc2f3b 100644
--- a/src/party.h
+++ b/src/party.h
@@ -127,7 +127,7 @@ class Party final : public AvatarListModel
* @return Returns the number of members in the party.
*/
int getNumberOfElements() override final A_WARN_UNUSED
- { return static_cast<int>(mMembers.size()); }
+ { return CAST_S32(mMembers.size()); }
Avatar *getAvatarAt(const int i) override final;
diff --git a/src/render/graphics.cpp b/src/render/graphics.cpp
index 5052b7489..d01813fb3 100644
--- a/src/render/graphics.cpp
+++ b/src/render/graphics.cpp
@@ -281,15 +281,15 @@ bool Graphics::setOpenGLMode() restrict2
int w1 = 0;
int h1 = 0;
SDL_GetWindowSize(mWindow, &w1, &h1);
- mRect.w = static_cast<int32_t>(w1 / mScale);
- mRect.h = static_cast<int32_t>(h1 / mScale);
+ mRect.w = CAST_S32(w1 / mScale);
+ mRect.h = CAST_S32(h1 / mScale);
createGLContext();
#else // USE_SDL2
createGLContext();
- mRect.w = static_cast<uint16_t>(mWindow->w / mScale);
- mRect.h = static_cast<uint16_t>(mWindow->h / mScale);
+ mRect.w = CAST_U16(mWindow->w / mScale);
+ mRect.h = CAST_U16(mWindow->h / mScale);
#endif // USE_SDL2
@@ -514,8 +514,8 @@ bool Graphics::resizeScreen(const int width,
#ifdef USE_SDL2
endDraw();
- mRect.w = static_cast<int32_t>(width / mScale);
- mRect.h = static_cast<int32_t>(height / mScale);
+ mRect.w = CAST_S32(width / mScale);
+ mRect.h = CAST_S32(height / mScale);
mWidth = width / mScale;
mHeight = height / mScale;
mActualWidth = width;
@@ -545,8 +545,8 @@ bool Graphics::resizeScreen(const int width,
#ifdef __native_client__
if (mOpenGL != RENDER_SOFTWARE)
{
- mRect.w = static_cast<int32_t>(width / mScale);
- mRect.h = static_cast<int32_t>(height / mScale);
+ mRect.w = CAST_S32(width / mScale);
+ mRect.h = CAST_S32(height / mScale);
mWidth = width / mScale;
mHeight = height / mScale;
mActualWidth = width;
diff --git a/src/render/mobileopengl2graphics.cpp b/src/render/mobileopengl2graphics.cpp
index 262c50408..69c4c741c 100644
--- a/src/render/mobileopengl2graphics.cpp
+++ b/src/render/mobileopengl2graphics.cpp
@@ -1268,7 +1268,7 @@ void MobileOpenGL2Graphics::finalize(ImageVertexes *restrict const vert)
std::vector<GLuint> &vbos = ogl.mVbo;
std::vector<GLuint>::const_iterator ivbo;
- const int sz = static_cast<int>(floatTexPool.size());
+ const int sz = CAST_S32(floatTexPool.size());
vbos.resize(sz);
mglGenBuffers(sz, &vbos[0]);
diff --git a/src/render/mobileopenglgraphics.cpp b/src/render/mobileopenglgraphics.cpp
index 36a0ae787..f703ff667 100644
--- a/src/render/mobileopenglgraphics.cpp
+++ b/src/render/mobileopenglgraphics.cpp
@@ -1165,10 +1165,10 @@ void MobileOpenGLGraphics::drawNet(const int x1, const int y1,
const GLshort xs2 = static_cast<GLshort>(x2);
const GLshort ys1 = static_cast<GLshort>(y1);
const GLshort ys2 = static_cast<GLshort>(y2);
- const int16_t width1 = static_cast<int16_t>(width);
- const int16_t height1 = static_cast<int16_t>(height);
+ const int16_t width1 = CAST_S16(width);
+ const int16_t height1 = CAST_S16(height);
- for (int16_t y = static_cast<int16_t>(y1); y < y2; y += height1)
+ for (int16_t y = CAST_S16(y1); y < y2; y += height1)
{
mShortVertArray[vp + 0] = xs1;
mShortVertArray[vp + 1] = y;
@@ -1184,7 +1184,7 @@ void MobileOpenGLGraphics::drawNet(const int x1, const int y1,
}
}
- for (int16_t x = static_cast<int16_t>(x1); x < x2; x += width1)
+ for (int16_t x = CAST_S16(x1); x < x2; x += width1)
{
mShortVertArray[vp + 0] = x;
mShortVertArray[vp + 1] = ys1;
diff --git a/src/render/modernopenglgraphics.cpp b/src/render/modernopenglgraphics.cpp
index 0fee827be..b82b93276 100644
--- a/src/render/modernopenglgraphics.cpp
+++ b/src/render/modernopenglgraphics.cpp
@@ -1262,7 +1262,7 @@ void ModernOpenGLGraphics::finalize(ImageVertexes *restrict const vert)
std::vector<GLuint> &vbos = ogl.mVbo;
std::vector<GLuint>::const_iterator ivbo;
- const int sz = static_cast<int>(intTexPool.size());
+ const int sz = CAST_S32(intTexPool.size());
vbos.resize(sz);
mglGenBuffers(sz, &vbos[0]);
/*
diff --git a/src/render/sdl2graphics.cpp b/src/render/sdl2graphics.cpp
index 79747522d..58e636a54 100644
--- a/src/render/sdl2graphics.cpp
+++ b/src/render/sdl2graphics.cpp
@@ -113,18 +113,18 @@ static int FakeSDL_RenderCopy(SDL_Renderer *restrict const renderer,
#define setRenderDrawColor(mColor) \
SDL_SetRenderDrawColor(mRenderer, \
- static_cast<uint8_t>(mColor.r), \
- static_cast<uint8_t>(mColor.g), \
- static_cast<uint8_t>(mColor.b), \
- static_cast<uint8_t>(mColor.a))
+ CAST_U8(mColor.r), \
+ CAST_U8(mColor.g), \
+ CAST_U8(mColor.b), \
+ CAST_U8(mColor.a))
#define defRectFromArea(rect, area) \
const SDL_Rect rect = \
{ \
- static_cast<int32_t>(area.x), \
- static_cast<int32_t>(area.y), \
- static_cast<int32_t>(area.width), \
- static_cast<int32_t>(area.height) \
+ CAST_S32(area.x), \
+ CAST_S32(area.y), \
+ CAST_S32(area.width), \
+ CAST_S32(area.height) \
}
SDLGraphics::SDLGraphics() :
@@ -155,17 +155,17 @@ void SDLGraphics::drawRescaledImage(const Image *restrict const image,
const SDL_Rect &bounds = image->mBounds;
const SDL_Rect srcRect =
{
- static_cast<int32_t>(bounds.x),
- static_cast<int32_t>(bounds.y),
- static_cast<int32_t>(bounds.w),
- static_cast<int32_t>(bounds.h)
+ CAST_S32(bounds.x),
+ CAST_S32(bounds.y),
+ CAST_S32(bounds.w),
+ CAST_S32(bounds.h)
};
const SDL_Rect dstRect =
{
- static_cast<int32_t>(dstX + top.xOffset),
- static_cast<int32_t>(dstY + top.yOffset),
- static_cast<int32_t>(desiredWidth),
- static_cast<int32_t>(desiredHeight)
+ CAST_S32(dstX + top.xOffset),
+ CAST_S32(dstY + top.yOffset),
+ CAST_S32(desiredWidth),
+ CAST_S32(desiredHeight)
};
MSDL_RenderCopy(mRenderer, image->mTexture, &srcRect, &dstRect);
@@ -192,18 +192,18 @@ void SDLGraphics::drawImageInline(const Image *restrict const image,
const SDL_Rect &bounds = image->mBounds;
const SDL_Rect srcRect =
{
- static_cast<int32_t>(bounds.x),
- static_cast<int32_t>(bounds.y),
- static_cast<int32_t>(bounds.w),
- static_cast<int32_t>(bounds.h)
+ CAST_S32(bounds.x),
+ CAST_S32(bounds.y),
+ CAST_S32(bounds.w),
+ CAST_S32(bounds.h)
};
const SDL_Rect dstRect =
{
- static_cast<int32_t>(dstX + top.xOffset),
- static_cast<int32_t>(dstY + top.yOffset),
- static_cast<int32_t>(bounds.w),
- static_cast<int32_t>(bounds.h)
+ CAST_S32(dstX + top.xOffset),
+ CAST_S32(dstY + top.yOffset),
+ CAST_S32(bounds.w),
+ CAST_S32(bounds.h)
};
MSDL_RenderCopy(mRenderer, image->mTexture, &srcRect, &dstRect);
@@ -230,18 +230,18 @@ void SDLGraphics::drawImageCached(const Image *restrict const image,
const SDL_Rect &bounds = image->mBounds;
const SDL_Rect srcRect =
{
- static_cast<int32_t>(bounds.x),
- static_cast<int32_t>(bounds.y),
- static_cast<int32_t>(bounds.w),
- static_cast<int32_t>(bounds.h)
+ CAST_S32(bounds.x),
+ CAST_S32(bounds.y),
+ CAST_S32(bounds.w),
+ CAST_S32(bounds.h)
};
const SDL_Rect dstRect =
{
- static_cast<int32_t>(x + top.xOffset),
- static_cast<int32_t>(y + top.yOffset),
- static_cast<int32_t>(bounds.w),
- static_cast<int32_t>(bounds.h)
+ CAST_S32(x + top.xOffset),
+ CAST_S32(y + top.yOffset),
+ CAST_S32(bounds.w),
+ CAST_S32(bounds.h)
};
MSDL_RenderCopy(mRenderer, image->mTexture, &srcRect, &dstRect);
@@ -273,21 +273,21 @@ void SDLGraphics::drawPatternCached(const Image *restrict const image,
SDL_Rect dstRect;
SDL_Rect srcRect;
- srcRect.x = static_cast<int32_t>(bounds.x);
- srcRect.y = static_cast<int32_t>(bounds.y);
+ srcRect.x = CAST_S32(bounds.x);
+ srcRect.y = CAST_S32(bounds.y);
for (int py = 0; py < h; py += ih)
{
const int dh = (py + ih >= h) ? h - py : ih;
- dstRect.y = static_cast<int32_t>(py + yOffset);
- srcRect.h = static_cast<int32_t>(dh);
- dstRect.h = static_cast<int32_t>(dh);
+ dstRect.y = CAST_S32(py + yOffset);
+ srcRect.h = CAST_S32(dh);
+ dstRect.h = CAST_S32(dh);
for (int px = 0; px < w; px += iw)
{
const int dw = (px + iw >= w) ? w - px : iw;
- dstRect.x = static_cast<int32_t>(px + xOffset);
- srcRect.w = static_cast<int32_t>(dw);
- dstRect.w = static_cast<int32_t>(dw);
+ dstRect.x = CAST_S32(px + xOffset);
+ srcRect.w = CAST_S32(dw);
+ dstRect.w = CAST_S32(dw);
MSDL_RenderCopy(mRenderer, image->mTexture, &srcRect, &dstRect);
}
@@ -331,21 +331,21 @@ void SDLGraphics::drawPatternInline(const Image *restrict const image,
SDL_Rect dstRect;
SDL_Rect srcRect;
- srcRect.x = static_cast<int32_t>(bounds.x);
- srcRect.y = static_cast<int32_t>(bounds.y);
+ srcRect.x = CAST_S32(bounds.x);
+ srcRect.y = CAST_S32(bounds.y);
for (int py = 0; py < h; py += ih)
{
const int dh = (py + ih >= h) ? h - py : ih;
- dstRect.y = static_cast<int32_t>(py + yOffset);
- srcRect.h = static_cast<int32_t>(dh);
- dstRect.h = static_cast<int32_t>(dh);
+ dstRect.y = CAST_S32(py + yOffset);
+ srcRect.h = CAST_S32(dh);
+ dstRect.h = CAST_S32(dh);
for (int px = 0; px < w; px += iw)
{
const int dw = (px + iw >= w) ? w - px : iw;
- dstRect.x = static_cast<int32_t>(px + xOffset);
- srcRect.w = static_cast<int32_t>(dw);
- dstRect.w = static_cast<int32_t>(dw);
+ dstRect.x = CAST_S32(px + xOffset);
+ srcRect.w = CAST_S32(dw);
+ dstRect.w = CAST_S32(dw);
MSDL_RenderCopy(mRenderer, image->mTexture, &srcRect, &dstRect);
}
@@ -387,21 +387,21 @@ void SDLGraphics::drawRescaledPattern(const Image *restrict const image,
SDL_Rect dstRect;
SDL_Rect srcRect;
- srcRect.x = static_cast<int32_t>(bounds.x);
- srcRect.y = static_cast<int32_t>(bounds.y);
+ srcRect.x = CAST_S32(bounds.x);
+ srcRect.y = CAST_S32(bounds.y);
for (int py = 0; py < h; py += ih)
{
const int dh = (py + ih >= h) ? h - py : ih;
- dstRect.y = static_cast<int32_t>(py + yOffset);
- srcRect.h = static_cast<int32_t>(dh);
- dstRect.h = static_cast<int32_t>(dh);
+ dstRect.y = CAST_S32(py + yOffset);
+ srcRect.h = CAST_S32(dh);
+ dstRect.h = CAST_S32(dh);
for (int px = 0; px < w; px += iw)
{
const int dw = (px + iw >= w) ? w - px : iw;
- dstRect.x = static_cast<int32_t>(px + xOffset);
- srcRect.w = static_cast<int32_t>(dw);
- dstRect.w = static_cast<int32_t>(dw);
+ dstRect.x = CAST_S32(px + xOffset);
+ srcRect.w = CAST_S32(dw);
+ dstRect.w = CAST_S32(dw);
MSDL_RenderCopy(mRenderer, image->mTexture, &srcRect, &dstRect);
}
@@ -454,14 +454,14 @@ void SDLGraphics::calcPatternInline(ImageVertexes *restrict const vert,
DoubleRect *const r = new DoubleRect();
SDL_Rect &dstRect = r->dst;
SDL_Rect &srcRect = r->src;
- srcRect.x = static_cast<int32_t>(srcX);
- srcRect.y = static_cast<int32_t>(srcY);
- srcRect.w = static_cast<int32_t>(dw);
- srcRect.h = static_cast<int32_t>(dh);
- dstRect.x = static_cast<int32_t>(dstX);
- dstRect.y = static_cast<int32_t>(dstY);
- dstRect.w = static_cast<int32_t>(dw);
- dstRect.h = static_cast<int32_t>(dh);
+ srcRect.x = CAST_S32(srcX);
+ srcRect.y = CAST_S32(srcY);
+ srcRect.w = CAST_S32(dw);
+ srcRect.h = CAST_S32(dh);
+ dstRect.x = CAST_S32(dstX);
+ dstRect.y = CAST_S32(dstY);
+ dstRect.w = CAST_S32(dw);
+ dstRect.h = CAST_S32(dh);
vert->sdl.push_back(r);
}
@@ -527,14 +527,14 @@ void SDLGraphics::calcTileSDL(ImageVertexes *restrict const vert,
SDL_Rect &dstRect = rect->dst;
SDL_Rect &srcRect = rect->src;
- srcRect.x = static_cast<int32_t>(bounds.x);
- srcRect.y = static_cast<int32_t>(bounds.y);
- srcRect.w = static_cast<int32_t>(bounds.w);
- srcRect.h = static_cast<int32_t>(bounds.h);
- dstRect.x = static_cast<int32_t>(x);
- dstRect.y = static_cast<int32_t>(y);
- dstRect.w = static_cast<int32_t>(bounds.w);
- dstRect.h = static_cast<int32_t>(bounds.h);
+ srcRect.x = CAST_S32(bounds.x);
+ srcRect.y = CAST_S32(bounds.y);
+ srcRect.w = CAST_S32(bounds.w);
+ srcRect.h = CAST_S32(bounds.h);
+ dstRect.x = CAST_S32(x);
+ dstRect.y = CAST_S32(y);
+ dstRect.w = CAST_S32(bounds.w);
+ dstRect.h = CAST_S32(bounds.h);
vert->sdl.push_back(rect);
}
@@ -637,10 +637,10 @@ void SDLGraphics::fillRectangle(const Rect &restrict rectangle) restrict2
const ClipRect &top = mClipStack.top();
const SDL_Rect rect =
{
- static_cast<int32_t>(rectangle.x + top.xOffset),
- static_cast<int32_t>(rectangle.y + top.yOffset),
- static_cast<int32_t>(rectangle.width),
- static_cast<int32_t>(rectangle.height)
+ CAST_S32(rectangle.x + top.xOffset),
+ CAST_S32(rectangle.y + top.yOffset),
+ CAST_S32(rectangle.width),
+ CAST_S32(rectangle.height)
};
setRenderDrawColor(mColor);
diff --git a/src/render/sdl2softwaregraphics.cpp b/src/render/sdl2softwaregraphics.cpp
index eb6633598..9a61f94ca 100644
--- a/src/render/sdl2softwaregraphics.cpp
+++ b/src/render/sdl2softwaregraphics.cpp
@@ -51,10 +51,10 @@ static unsigned int *cB = nullptr;
#define defRectFromArea(rect, area) \
const SDL_Rect rect = \
{ \
- static_cast<int32_t>(area.x), \
- static_cast<int32_t>(area.y), \
- static_cast<int32_t>(area.width), \
- static_cast<int32_t>(area.height) \
+ CAST_S32(area.x), \
+ CAST_S32(area.y), \
+ CAST_S32(area.width), \
+ CAST_S32(area.height) \
}
SDL2SoftwareGraphics::SDL2SoftwareGraphics() :
@@ -93,16 +93,16 @@ void SDL2SoftwareGraphics::drawRescaledImage(const Image *restrict const image,
SDL_Rect srcRect =
{
- static_cast<int16_t>(bounds.x),
- static_cast<int16_t>(bounds.y),
- static_cast<uint16_t>(bounds.w),
- static_cast<uint16_t>(bounds.h)
+ CAST_S16(bounds.x),
+ CAST_S16(bounds.y),
+ CAST_U16(bounds.w),
+ CAST_U16(bounds.h)
};
SDL_Rect dstRect =
{
- static_cast<int16_t>(dstX + top.xOffset),
- static_cast<int16_t>(dstY + top.yOffset),
+ CAST_S16(dstX + top.xOffset),
+ CAST_S16(dstY + top.yOffset),
0,
0
};
@@ -140,7 +140,7 @@ void SDL2SoftwareGraphics::drawImageInline(const Image *restrict const image,
if (srcX < 0)
{
w += srcX;
- dstX -= static_cast<int16_t>(srcX);
+ dstX -= CAST_S16(srcX);
srcX = 0;
}
const int maxw = src->w - srcX;
@@ -150,7 +150,7 @@ void SDL2SoftwareGraphics::drawImageInline(const Image *restrict const image,
if (srcY < 0)
{
h += srcY;
- dstY -= static_cast<int16_t>(srcY);
+ dstY -= CAST_S16(srcY);
srcY = 0;
}
const int maxh = src->h - srcY;
@@ -164,7 +164,7 @@ void SDL2SoftwareGraphics::drawImageInline(const Image *restrict const image,
if (dx > 0)
{
w -= dx;
- dstX += static_cast<int16_t>(dx);
+ dstX += CAST_S16(dx);
srcX += dx;
}
dx = dstX + w - clipX - clip->w;
@@ -175,7 +175,7 @@ void SDL2SoftwareGraphics::drawImageInline(const Image *restrict const image,
if (dy > 0)
{
h -= dy;
- dstY += static_cast<int16_t>(dy);
+ dstY += CAST_S16(dy);
srcY += dy;
}
dy = dstY + h - clipY - clip->h;
@@ -186,18 +186,18 @@ void SDL2SoftwareGraphics::drawImageInline(const Image *restrict const image,
{
SDL_Rect srcRect =
{
- static_cast<int16_t>(srcX),
- static_cast<int16_t>(srcY),
- static_cast<uint16_t>(w),
- static_cast<uint16_t>(h)
+ CAST_S16(srcX),
+ CAST_S16(srcY),
+ CAST_U16(w),
+ CAST_U16(h)
};
SDL_Rect dstRect =
{
- static_cast<int16_t>(dstX),
- static_cast<int16_t>(dstY),
- static_cast<uint16_t>(w),
- static_cast<uint16_t>(h)
+ CAST_S16(dstX),
+ CAST_S16(dstY),
+ CAST_U16(w),
+ CAST_U16(h)
};
SDL_LowerBlit(src, &srcRect, mSurface, &dstRect);
@@ -233,7 +233,7 @@ void SDL2SoftwareGraphics::drawImageCached(const Image *restrict const image,
if (srcX < 0)
{
w += srcX;
- x -= static_cast<int16_t>(srcX);
+ x -= CAST_S16(srcX);
srcX = 0;
}
const int maxw = src->w - srcX;
@@ -243,7 +243,7 @@ void SDL2SoftwareGraphics::drawImageCached(const Image *restrict const image,
if (srcY < 0)
{
h += srcY;
- y -= static_cast<int16_t>(srcY);
+ y -= CAST_S16(srcY);
srcY = 0;
}
const int maxh = src->h - srcY;
@@ -257,7 +257,7 @@ void SDL2SoftwareGraphics::drawImageCached(const Image *restrict const image,
if (dx > 0)
{
w -= dx;
- x += static_cast<int16_t>(dx);
+ x += CAST_S16(dx);
srcX += dx;
}
dx = x + w - clipX - clip->w;
@@ -268,7 +268,7 @@ void SDL2SoftwareGraphics::drawImageCached(const Image *restrict const image,
if (dy > 0)
{
h -= dy;
- y += static_cast<int16_t>(dy);
+ y += CAST_S16(dy);
srcY += dy;
}
dy = y + h - clipY - clip->h;
@@ -279,18 +279,18 @@ void SDL2SoftwareGraphics::drawImageCached(const Image *restrict const image,
{
SDL_Rect srcRect =
{
- static_cast<int16_t>(srcX),
- static_cast<int16_t>(srcY),
- static_cast<uint16_t>(w),
- static_cast<uint16_t>(h)
+ CAST_S16(srcX),
+ CAST_S16(srcY),
+ CAST_U16(w),
+ CAST_U16(h)
};
SDL_Rect dstRect =
{
- static_cast<int16_t>(x),
- static_cast<int16_t>(y),
- static_cast<uint16_t>(w),
- static_cast<uint16_t>(h)
+ CAST_S16(x),
+ CAST_S16(y),
+ CAST_U16(w),
+ CAST_U16(h)
};
SDL_LowerBlit(src, &srcRect, mSurface, &dstRect);
@@ -335,7 +335,7 @@ void SDL2SoftwareGraphics::drawPatternCached(const Image *restrict const image,
if (y2 < 0)
{
h2 += y2;
- dstY -= static_cast<int16_t>(y2);
+ dstY -= CAST_S16(y2);
y2 = 0;
}
const int maxh = src->h - y2;
@@ -346,7 +346,7 @@ void SDL2SoftwareGraphics::drawPatternCached(const Image *restrict const image,
if (dy > 0)
{
h2 -= dy;
- dstY += static_cast<int16_t>(dy);
+ dstY += CAST_S16(dy);
y2 += dy;
}
dy = dstY + h2 - clipY - clip->h;
@@ -364,7 +364,7 @@ void SDL2SoftwareGraphics::drawPatternCached(const Image *restrict const image,
if (x2 < 0)
{
w2 += x2;
- dstX -= static_cast<int16_t>(x2);
+ dstX -= CAST_S16(x2);
x2 = 0;
}
const int maxw = src->w - x2;
@@ -375,7 +375,7 @@ void SDL2SoftwareGraphics::drawPatternCached(const Image *restrict const image,
if (dx > 0)
{
w2 -= dx;
- dstX += static_cast<int16_t>(dx);
+ dstX += CAST_S16(dx);
x2 += dx;
}
dx = dstX + w2 - clipX - clip->w;
@@ -386,18 +386,18 @@ void SDL2SoftwareGraphics::drawPatternCached(const Image *restrict const image,
{
SDL_Rect srcRect =
{
- static_cast<int16_t>(x2),
- static_cast<int16_t>(y2),
- static_cast<uint16_t>(w2),
- static_cast<uint16_t>(h2)
+ CAST_S16(x2),
+ CAST_S16(y2),
+ CAST_U16(w2),
+ CAST_U16(h2)
};
SDL_Rect dstRect =
{
- static_cast<int16_t>(dstX),
- static_cast<int16_t>(dstY),
- static_cast<uint16_t>(w2),
- static_cast<uint16_t>(h2)
+ CAST_S16(dstX),
+ CAST_S16(dstY),
+ CAST_U16(w2),
+ CAST_U16(h2)
};
SDL_LowerBlit(src, &srcRect, mSurface, &dstRect);
@@ -458,7 +458,7 @@ void SDL2SoftwareGraphics::drawPatternInline(const Image *restrict const image,
if (y2 < 0)
{
h2 += y2;
- dstY -= static_cast<int16_t>(y2);
+ dstY -= CAST_S16(y2);
y2 = 0;
}
const int maxh = src->h - y2;
@@ -469,7 +469,7 @@ void SDL2SoftwareGraphics::drawPatternInline(const Image *restrict const image,
if (dy > 0)
{
h2 -= dy;
- dstY += static_cast<int16_t>(dy);
+ dstY += CAST_S16(dy);
y2 += dy;
}
dy = dstY + h2 - clipY - clip->h;
@@ -487,7 +487,7 @@ void SDL2SoftwareGraphics::drawPatternInline(const Image *restrict const image,
if (x2 < 0)
{
w2 += x2;
- dstX -= static_cast<int16_t>(x2);
+ dstX -= CAST_S16(x2);
x2 = 0;
}
const int maxw = src->w - x2;
@@ -498,7 +498,7 @@ void SDL2SoftwareGraphics::drawPatternInline(const Image *restrict const image,
if (dx > 0)
{
w2 -= dx;
- dstX += static_cast<int16_t>(dx);
+ dstX += CAST_S16(dx);
x2 += dx;
}
dx = dstX + w2 - clipX - clip->w;
@@ -509,18 +509,18 @@ void SDL2SoftwareGraphics::drawPatternInline(const Image *restrict const image,
{
SDL_Rect srcRect =
{
- static_cast<int16_t>(x2),
- static_cast<int16_t>(y2),
- static_cast<uint16_t>(w2),
- static_cast<uint16_t>(h2)
+ CAST_S16(x2),
+ CAST_S16(y2),
+ CAST_U16(w2),
+ CAST_U16(h2)
};
SDL_Rect dstRect =
{
- static_cast<int16_t>(dstX),
- static_cast<int16_t>(dstY),
- static_cast<uint16_t>(w2),
- static_cast<uint16_t>(h2)
+ CAST_S16(dstX),
+ CAST_S16(dstY),
+ CAST_U16(w2),
+ CAST_U16(h2)
};
SDL_LowerBlit(src, &srcRect, mSurface, &dstRect);
@@ -578,16 +578,16 @@ void SDL2SoftwareGraphics::drawRescaledPattern(const Image *
SDL_Rect srcRect =
{
- static_cast<int16_t>(srcX),
- static_cast<int16_t>(srcY),
- static_cast<uint16_t>(dw),
- static_cast<uint16_t>(dh)
+ CAST_S16(srcX),
+ CAST_S16(srcY),
+ CAST_U16(dw),
+ CAST_U16(dh)
};
SDL_Rect dstRect =
{
- static_cast<int16_t>(dstX),
- static_cast<int16_t>(dstY),
+ CAST_S16(dstX),
+ CAST_S16(dstY),
0,
0
};
@@ -646,13 +646,13 @@ void SDL2SoftwareGraphics::calcPatternInline(ImageVertexes *
DoubleRect *const r = new DoubleRect();
SDL_Rect &srcRect = r->src;
- srcRect.x = static_cast<int16_t>(srcX);
- srcRect.y = static_cast<int16_t>(srcY);
- srcRect.w = static_cast<uint16_t>(dw);
- srcRect.h = static_cast<uint16_t>(dh);
+ srcRect.x = CAST_S16(srcX);
+ srcRect.y = CAST_S16(srcY);
+ srcRect.w = CAST_U16(dw);
+ srcRect.h = CAST_U16(dh);
SDL_Rect &dstRect = r->dst;
- dstRect.x = static_cast<int16_t>(dstX);
- dstRect.y = static_cast<int16_t>(dstY);
+ dstRect.x = CAST_S16(dstX);
+ dstRect.y = CAST_S16(dstY);
if (SDL_FakeUpperBlit(image->mSDLSurface, &srcRect,
mSurface, &dstRect) == 1)
@@ -721,12 +721,12 @@ void SDL2SoftwareGraphics::calcTileSDL(ImageVertexes *restrict const vert,
const SDL_Rect &bounds = image->mBounds;
DoubleRect *rect = new DoubleRect();
- rect->src.x = static_cast<int16_t>(bounds.x);
- rect->src.y = static_cast<int16_t>(bounds.y);
- rect->src.w = static_cast<uint16_t>(bounds.w);
- rect->src.h = static_cast<uint16_t>(bounds.h);
- rect->dst.x = static_cast<int16_t>(x + top.xOffset);
- rect->dst.y = static_cast<int16_t>(y + top.yOffset);
+ rect->src.x = CAST_S16(bounds.x);
+ rect->src.y = CAST_S16(bounds.y);
+ rect->src.w = CAST_U16(bounds.w);
+ rect->src.h = CAST_U16(bounds.h);
+ rect->dst.x = CAST_S16(x + top.xOffset);
+ rect->dst.y = CAST_S16(y + top.yOffset);
if (SDL_FakeUpperBlit(image->mSDLSurface, &rect->src,
mSurface, &rect->dst) == 1)
{
@@ -856,7 +856,7 @@ int SDL2SoftwareGraphics::SDL_FakeUpperBlit(const SDL_Surface *restrict const
if (srcx < 0)
{
w += srcx;
- dstrect->x -= static_cast<int16_t>(srcx);
+ dstrect->x -= CAST_S16(srcx);
srcx = 0;
}
int maxw = src->w - srcx;
@@ -868,7 +868,7 @@ int SDL2SoftwareGraphics::SDL_FakeUpperBlit(const SDL_Surface *restrict const
if (srcy < 0)
{
h += srcy;
- dstrect->y -= static_cast<int16_t>(srcy);
+ dstrect->y -= CAST_S16(srcy);
srcy = 0;
}
int maxh = src->h - srcy;
@@ -882,7 +882,7 @@ int SDL2SoftwareGraphics::SDL_FakeUpperBlit(const SDL_Surface *restrict const
if (dx > 0)
{
w -= dx;
- dstrect->x += static_cast<int16_t>(dx);
+ dstrect->x += CAST_S16(dx);
srcx += dx;
}
dx = dstrect->x + w - clipX - clip->w;
@@ -893,7 +893,7 @@ int SDL2SoftwareGraphics::SDL_FakeUpperBlit(const SDL_Surface *restrict const
if (dy > 0)
{
h -= dy;
- dstrect->y += static_cast<int16_t>(dy);
+ dstrect->y += CAST_S16(dy);
srcy += dy;
}
dy = dstrect->y + h - clipY - clip->h;
@@ -904,13 +904,13 @@ int SDL2SoftwareGraphics::SDL_FakeUpperBlit(const SDL_Surface *restrict const
{
if (srcrect)
{
- srcrect->x = static_cast<int16_t>(srcx);
- srcrect->y = static_cast<int16_t>(srcy);
- srcrect->w = static_cast<int16_t>(w);
- srcrect->h = static_cast<int16_t>(h);
+ srcrect->x = CAST_S16(srcx);
+ srcrect->y = CAST_S16(srcy);
+ srcrect->w = CAST_S16(w);
+ srcrect->h = CAST_S16(h);
}
- dstrect->w = static_cast<int16_t>(w);
- dstrect->h = static_cast<int16_t>(h);
+ dstrect->w = CAST_S16(w);
+ dstrect->h = CAST_S16(h);
return 1;
// return SDL_LowerBlit(src, &sr, dst, dstrect);
@@ -949,8 +949,8 @@ void SDL2SoftwareGraphics::fillRectangle(const Rect &restrict rectangle)
const int bpp = mSurface->format->BytesPerPixel;
const uint32_t pixel = SDL_MapRGB(mSurface->format,
- static_cast<uint8_t>(mColor.r), static_cast<uint8_t>(mColor.g),
- static_cast<uint8_t>(mColor.b));
+ CAST_U8(mColor.r), CAST_U8(mColor.g),
+ CAST_U8(mColor.b));
switch (bpp)
{
@@ -960,7 +960,7 @@ void SDL2SoftwareGraphics::fillRectangle(const Rect &restrict rectangle)
uint8_t *const p = static_cast<uint8_t *>(mSurface->pixels)
+ y * mSurface->pitch;
for (x = x1; x < x2; x++)
- *(p + x) = static_cast<uint8_t>(pixel);
+ *(p + x) = CAST_U8(pixel);
}
break;
case 2:
@@ -972,9 +972,9 @@ void SDL2SoftwareGraphics::fillRectangle(const Rect &restrict rectangle)
{
uint8_t *const p = p0 + x * 2;
*reinterpret_cast<uint16_t *>(p) = SDLAlpha16(
- static_cast<uint16_t>(pixel),
+ CAST_U16(pixel),
*reinterpret_cast<uint16_t *>(p),
- static_cast<uint8_t>(mColor.a), mSurface->format);
+ CAST_U8(mColor.a), mSurface->format);
}
}
break;
@@ -993,13 +993,13 @@ void SDL2SoftwareGraphics::fillRectangle(const Rect &restrict rectangle)
{
uint8_t *const p = p0 + x * 3;
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
- p[2] = static_cast<uint8_t>((p[2] * ca + cb) >> 8);
- p[1] = static_cast<uint8_t>((p[1] * ca + cg) >> 8);
- p[0] = static_cast<uint8_t>((p[0] * ca + cr) >> 8);
+ p[2] = CAST_U8((p[2] * ca + cb) >> 8);
+ p[1] = CAST_U8((p[1] * ca + cg) >> 8);
+ p[0] = CAST_U8((p[0] * ca + cr) >> 8);
#else
- p[0] = static_cast<uint8_t>((p[0] * ca + cb) >> 8);
- p[1] = static_cast<uint8_t>((p[1] * ca + cg) >> 8);
- p[2] = static_cast<uint8_t>((p[2] * ca + cr) >> 8);
+ p[0] = CAST_U8((p[0] * ca + cb) >> 8);
+ p[1] = CAST_U8((p[1] * ca + cg) >> 8);
+ p[2] = CAST_U8((p[2] * ca + cr) >> 8);
#endif
}
}
@@ -1103,10 +1103,10 @@ void SDL2SoftwareGraphics::fillRectangle(const Rect &restrict rectangle)
{
defRectFromArea(rect, area);
const uint32_t color = SDL_MapRGBA(mSurface->format,
- static_cast<int8_t>(mColor.r),
- static_cast<int8_t>(mColor.g),
- static_cast<int8_t>(mColor.b),
- static_cast<int8_t>(mColor.a));
+ CAST_S8(mColor.r),
+ CAST_S8(mColor.g),
+ CAST_S8(mColor.b),
+ CAST_S8(mColor.a));
SDL_FillRect(mSurface, &rect, color);
}
}
@@ -1210,20 +1210,20 @@ void SDL2SoftwareGraphics::drawHLine(int x1, int y, int x2) restrict2
+ y * mSurface->pitch + x1 * bpp;
const uint32_t pixel = SDL_MapRGB(mSurface->format,
- static_cast<uint8_t>(mColor.r),
- static_cast<uint8_t>(mColor.g),
- static_cast<uint8_t>(mColor.b));
+ CAST_U8(mColor.r),
+ CAST_U8(mColor.g),
+ CAST_U8(mColor.b));
switch (bpp)
{
case 1:
for (; x1 <= x2; ++x1)
- *(p++) = static_cast<uint8_t>(pixel);
+ *(p++) = CAST_U8(pixel);
break;
case 2:
{
uint16_t* q = reinterpret_cast<uint16_t*>(p);
- const uint16_t pixel1 = static_cast<uint16_t>(pixel);
+ const uint16_t pixel1 = CAST_U16(pixel);
for (; x1 <= x2; ++x1)
*(q++) = pixel1;
break;
@@ -1231,9 +1231,9 @@ void SDL2SoftwareGraphics::drawHLine(int x1, int y, int x2) restrict2
case 3:
{
- const uint8_t b0 = static_cast<uint8_t>((pixel >> 16) & 0xff);
- const uint8_t b1 = static_cast<uint8_t>((pixel >> 8) & 0xff);
- const uint8_t b2 = static_cast<uint8_t>(pixel & 0xff);
+ const uint8_t b0 = CAST_U8((pixel >> 16) & 0xff);
+ const uint8_t b1 = CAST_U8((pixel >> 8) & 0xff);
+ const uint8_t b2 = CAST_U8(pixel & 0xff);
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
for (; x1 <= x2; ++x1)
{
@@ -1259,8 +1259,8 @@ void SDL2SoftwareGraphics::drawHLine(int x1, int y, int x2) restrict2
uint32_t *q = reinterpret_cast<uint32_t*>(p);
if (mAlpha)
{
- unsigned char a = static_cast<unsigned char>(mColor.a);
- unsigned char a1 = static_cast<unsigned char>(255U - a);
+ unsigned char a = CAST_U8(mColor.a);
+ unsigned char a1 = CAST_U8(255U - a);
const int b0 = (pixel & 0xff) * a;
const int g0 = (pixel & 0xff00) * a;
const int r0 = (pixel & 0xff0000) * a;
@@ -1335,9 +1335,9 @@ void SDL2SoftwareGraphics::drawVLine(int x, int y1, int y2) restrict2
+ y1 * mSurface->pitch + x * bpp;
const uint32_t pixel = SDL_MapRGB(mSurface->format,
- static_cast<uint8_t>(mColor.r),
- static_cast<uint8_t>(mColor.g),
- static_cast<uint8_t>(mColor.b));
+ CAST_U8(mColor.r),
+ CAST_U8(mColor.g),
+ CAST_U8(mColor.b));
const int pitch = mSurface->pitch;
switch (bpp)
@@ -1345,7 +1345,7 @@ void SDL2SoftwareGraphics::drawVLine(int x, int y1, int y2) restrict2
case 1:
for (; y1 <= y2; ++y1)
{
- *p = static_cast<uint8_t>(pixel);
+ *p = CAST_U8(pixel);
p += pitch;
}
break;
@@ -1354,16 +1354,16 @@ void SDL2SoftwareGraphics::drawVLine(int x, int y1, int y2) restrict2
for (; y1 <= y2; ++ y1)
{
*reinterpret_cast<uint16_t*>(p)
- = static_cast<uint16_t>(pixel);
+ = CAST_U16(pixel);
p += pitch;
}
break;
case 3:
{
- const uint8_t b0 = static_cast<uint8_t>((pixel >> 16) & 0xff);
- const uint8_t b1 = static_cast<uint8_t>((pixel >> 8) & 0xff);
- const uint8_t b2 = static_cast<uint8_t>(pixel & 0xff);
+ const uint8_t b0 = CAST_U8((pixel >> 16) & 0xff);
+ const uint8_t b1 = CAST_U8((pixel >> 8) & 0xff);
+ const uint8_t b2 = CAST_U8(pixel & 0xff);
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
for (; y1 <= y2; ++y1)
{
@@ -1388,8 +1388,8 @@ void SDL2SoftwareGraphics::drawVLine(int x, int y1, int y2) restrict2
{
if (mAlpha)
{
- unsigned char a = static_cast<unsigned char>(mColor.a);
- unsigned char a1 = static_cast<unsigned char>(255U - a);
+ unsigned char a = CAST_U8(mColor.a);
+ unsigned char a1 = CAST_U8(255U - a);
const int b0 = (pixel & 0xff) * a;
const int g0 = (pixel & 0xff00) * a;
const int r0 = (pixel & 0xff0000) * a;
diff --git a/src/render/sdlgraphics.cpp b/src/render/sdlgraphics.cpp
index 3e71937c6..0043d1ccc 100644
--- a/src/render/sdlgraphics.cpp
+++ b/src/render/sdlgraphics.cpp
@@ -78,16 +78,16 @@ void SDLGraphics::drawRescaledImage(const Image *restrict const image,
SDL_Rect srcRect =
{
- static_cast<int16_t>(bounds.x),
- static_cast<int16_t>(bounds.y),
- static_cast<uint16_t>(bounds.w),
- static_cast<uint16_t>(bounds.h)
+ CAST_S16(bounds.x),
+ CAST_S16(bounds.y),
+ CAST_U16(bounds.w),
+ CAST_U16(bounds.h)
};
SDL_Rect dstRect =
{
- static_cast<int16_t>(dstX + top.xOffset),
- static_cast<int16_t>(dstY + top.yOffset),
+ CAST_S16(dstX + top.xOffset),
+ CAST_S16(dstY + top.yOffset),
0,
0
};
@@ -125,7 +125,7 @@ void SDLGraphics::drawImageInline(const Image *restrict const image,
if (srcX < 0)
{
w += srcX;
- dstX -= static_cast<int16_t>(srcX);
+ dstX -= CAST_S16(srcX);
srcX = 0;
}
const int maxw = src->w - srcX;
@@ -135,7 +135,7 @@ void SDLGraphics::drawImageInline(const Image *restrict const image,
if (srcY < 0)
{
h += srcY;
- dstY -= static_cast<int16_t>(srcY);
+ dstY -= CAST_S16(srcY);
srcY = 0;
}
const int maxh = src->h - srcY;
@@ -149,7 +149,7 @@ void SDLGraphics::drawImageInline(const Image *restrict const image,
if (dx > 0)
{
w -= dx;
- dstX += static_cast<int16_t>(dx);
+ dstX += CAST_S16(dx);
srcX += dx;
}
dx = dstX + w - clipX - clip->w;
@@ -160,7 +160,7 @@ void SDLGraphics::drawImageInline(const Image *restrict const image,
if (dy > 0)
{
h -= dy;
- dstY += static_cast<int16_t>(dy);
+ dstY += CAST_S16(dy);
srcY += dy;
}
dy = dstY + h - clipY - clip->h;
@@ -171,18 +171,18 @@ void SDLGraphics::drawImageInline(const Image *restrict const image,
{
SDL_Rect srcRect =
{
- static_cast<int16_t>(srcX),
- static_cast<int16_t>(srcY),
- static_cast<uint16_t>(w),
- static_cast<uint16_t>(h)
+ CAST_S16(srcX),
+ CAST_S16(srcY),
+ CAST_U16(w),
+ CAST_U16(h)
};
SDL_Rect dstRect =
{
- static_cast<int16_t>(dstX),
- static_cast<int16_t>(dstY),
- static_cast<uint16_t>(w),
- static_cast<uint16_t>(h)
+ CAST_S16(dstX),
+ CAST_S16(dstY),
+ CAST_U16(w),
+ CAST_U16(h)
};
SDL_LowerBlit(src, &srcRect, mWindow, &dstRect);
@@ -218,7 +218,7 @@ void SDLGraphics::drawImageCached(const Image *restrict const image,
if (srcX < 0)
{
w += srcX;
- x -= static_cast<int16_t>(srcX);
+ x -= CAST_S16(srcX);
srcX = 0;
}
const int maxw = src->w - srcX;
@@ -228,7 +228,7 @@ void SDLGraphics::drawImageCached(const Image *restrict const image,
if (srcY < 0)
{
h += srcY;
- y -= static_cast<int16_t>(srcY);
+ y -= CAST_S16(srcY);
srcY = 0;
}
const int maxh = src->h - srcY;
@@ -242,7 +242,7 @@ void SDLGraphics::drawImageCached(const Image *restrict const image,
if (dx > 0)
{
w -= dx;
- x += static_cast<int16_t>(dx);
+ x += CAST_S16(dx);
srcX += dx;
}
dx = x + w - clipX - clip->w;
@@ -253,7 +253,7 @@ void SDLGraphics::drawImageCached(const Image *restrict const image,
if (dy > 0)
{
h -= dy;
- y += static_cast<int16_t>(dy);
+ y += CAST_S16(dy);
srcY += dy;
}
dy = y + h - clipY - clip->h;
@@ -264,18 +264,18 @@ void SDLGraphics::drawImageCached(const Image *restrict const image,
{
SDL_Rect srcRect =
{
- static_cast<int16_t>(srcX),
- static_cast<int16_t>(srcY),
- static_cast<uint16_t>(w),
- static_cast<uint16_t>(h)
+ CAST_S16(srcX),
+ CAST_S16(srcY),
+ CAST_U16(w),
+ CAST_U16(h)
};
SDL_Rect dstRect =
{
- static_cast<int16_t>(x),
- static_cast<int16_t>(y),
- static_cast<uint16_t>(w),
- static_cast<uint16_t>(h)
+ CAST_S16(x),
+ CAST_S16(y),
+ CAST_U16(w),
+ CAST_U16(h)
};
SDL_LowerBlit(src, &srcRect, mWindow, &dstRect);
@@ -318,7 +318,7 @@ void SDLGraphics::drawPatternCached(const Image *restrict const image,
if (y2 < 0)
{
h2 += y2;
- dstY -= static_cast<int16_t>(y2);
+ dstY -= CAST_S16(y2);
y2 = 0;
}
const int maxh = src->h - y2;
@@ -329,7 +329,7 @@ void SDLGraphics::drawPatternCached(const Image *restrict const image,
if (dy > 0)
{
h2 -= dy;
- dstY += static_cast<int16_t>(dy);
+ dstY += CAST_S16(dy);
y2 += dy;
}
dy = dstY + h2 - clipY - clip->h;
@@ -347,7 +347,7 @@ void SDLGraphics::drawPatternCached(const Image *restrict const image,
if (x2 < 0)
{
w2 += x2;
- dstX -= static_cast<int16_t>(x2);
+ dstX -= CAST_S16(x2);
x2 = 0;
}
const int maxw = src->w - x2;
@@ -358,7 +358,7 @@ void SDLGraphics::drawPatternCached(const Image *restrict const image,
if (dx > 0)
{
w2 -= dx;
- dstX += static_cast<int16_t>(dx);
+ dstX += CAST_S16(dx);
x2 += dx;
}
dx = dstX + w2 - clipX - clip->w;
@@ -369,18 +369,18 @@ void SDLGraphics::drawPatternCached(const Image *restrict const image,
{
SDL_Rect srcRect =
{
- static_cast<int16_t>(x2),
- static_cast<int16_t>(y2),
- static_cast<uint16_t>(w2),
- static_cast<uint16_t>(h2)
+ CAST_S16(x2),
+ CAST_S16(y2),
+ CAST_U16(w2),
+ CAST_U16(h2)
};
SDL_Rect dstRect =
{
- static_cast<int16_t>(dstX),
- static_cast<int16_t>(dstY),
- static_cast<uint16_t>(w2),
- static_cast<uint16_t>(h2)
+ CAST_S16(dstX),
+ CAST_S16(dstY),
+ CAST_U16(w2),
+ CAST_U16(h2)
};
SDL_LowerBlit(src, &srcRect, mWindow, &dstRect);
@@ -439,7 +439,7 @@ void SDLGraphics::drawPatternInline(const Image *restrict const image,
if (y2 < 0)
{
h2 += y2;
- dstY -= static_cast<int16_t>(y2);
+ dstY -= CAST_S16(y2);
y2 = 0;
}
const int maxh = src->h - y2;
@@ -450,7 +450,7 @@ void SDLGraphics::drawPatternInline(const Image *restrict const image,
if (dy > 0)
{
h2 -= dy;
- dstY += static_cast<int16_t>(dy);
+ dstY += CAST_S16(dy);
y2 += dy;
}
dy = dstY + h2 - clipY - clip->h;
@@ -468,7 +468,7 @@ void SDLGraphics::drawPatternInline(const Image *restrict const image,
if (x2 < 0)
{
w2 += x2;
- dstX -= static_cast<int16_t>(x2);
+ dstX -= CAST_S16(x2);
x2 = 0;
}
const int maxw = src->w - x2;
@@ -479,7 +479,7 @@ void SDLGraphics::drawPatternInline(const Image *restrict const image,
if (dx > 0)
{
w2 -= dx;
- dstX += static_cast<int16_t>(dx);
+ dstX += CAST_S16(dx);
x2 += dx;
}
dx = dstX + w2 - clipX - clip->w;
@@ -490,18 +490,18 @@ void SDLGraphics::drawPatternInline(const Image *restrict const image,
{
SDL_Rect srcRect =
{
- static_cast<int16_t>(x2),
- static_cast<int16_t>(y2),
- static_cast<uint16_t>(w2),
- static_cast<uint16_t>(h2)
+ CAST_S16(x2),
+ CAST_S16(y2),
+ CAST_U16(w2),
+ CAST_U16(h2)
};
SDL_Rect dstRect =
{
- static_cast<int16_t>(dstX),
- static_cast<int16_t>(dstY),
- static_cast<uint16_t>(w2),
- static_cast<uint16_t>(h2)
+ CAST_S16(dstX),
+ CAST_S16(dstY),
+ CAST_U16(w2),
+ CAST_U16(h2)
};
SDL_LowerBlit(src, &srcRect, mWindow, &dstRect);
@@ -557,16 +557,16 @@ void SDLGraphics::drawRescaledPattern(const Image *restrict const image,
SDL_Rect srcRect =
{
- static_cast<int16_t>(srcX),
- static_cast<int16_t>(srcY),
- static_cast<uint16_t>(dw),
- static_cast<uint16_t>(dh)
+ CAST_S16(srcX),
+ CAST_S16(srcY),
+ CAST_U16(dw),
+ CAST_U16(dh)
};
SDL_Rect dstRect =
{
- static_cast<int16_t>(dstX),
- static_cast<int16_t>(dstY),
+ CAST_S16(dstX),
+ CAST_S16(dstY),
0,
0
};
@@ -620,13 +620,13 @@ void SDLGraphics::calcPatternInline(ImageVertexes *restrict const vert,
DoubleRect *const r = new DoubleRect();
SDL_Rect &srcRect = r->src;
- srcRect.x = static_cast<int16_t>(srcX);
- srcRect.y = static_cast<int16_t>(srcY);
- srcRect.w = static_cast<uint16_t>(dw);
- srcRect.h = static_cast<uint16_t>(dh);
+ srcRect.x = CAST_S16(srcX);
+ srcRect.y = CAST_S16(srcY);
+ srcRect.w = CAST_U16(dw);
+ srcRect.h = CAST_U16(dh);
SDL_Rect &dstRect = r->dst;
- dstRect.x = static_cast<int16_t>(dstX);
- dstRect.y = static_cast<int16_t>(dstY);
+ dstRect.x = CAST_S16(dstX);
+ dstRect.y = CAST_S16(dstY);
if (SDL_FakeUpperBlit(image->mSDLSurface, &srcRect,
mWindow, &dstRect) == 1)
@@ -698,12 +698,12 @@ void SDLGraphics::calcTileSDL(ImageVertexes *restrict const vert,
const SDL_Rect &bounds = image->mBounds;
DoubleRect *rect = new DoubleRect();
- rect->src.x = static_cast<int16_t>(bounds.x);
- rect->src.y = static_cast<int16_t>(bounds.y);
- rect->src.w = static_cast<uint16_t>(bounds.w);
- rect->src.h = static_cast<uint16_t>(bounds.h);
- rect->dst.x = static_cast<int16_t>(x + top.xOffset);
- rect->dst.y = static_cast<int16_t>(y + top.yOffset);
+ rect->src.x = CAST_S16(bounds.x);
+ rect->src.y = CAST_S16(bounds.y);
+ rect->src.w = CAST_U16(bounds.w);
+ rect->src.h = CAST_U16(bounds.h);
+ rect->dst.x = CAST_S16(x + top.xOffset);
+ rect->dst.y = CAST_S16(y + top.yOffset);
if (SDL_FakeUpperBlit(image->mSDLSurface, &rect->src,
mWindow, &rect->dst) == 1)
{
@@ -837,7 +837,7 @@ int SDLGraphics::SDL_FakeUpperBlit(const SDL_Surface *restrict const src,
if (srcx < 0)
{
w += srcx;
- dstrect->x -= static_cast<int16_t>(srcx);
+ dstrect->x -= CAST_S16(srcx);
srcx = 0;
}
int maxw = src->w - srcx;
@@ -849,7 +849,7 @@ int SDLGraphics::SDL_FakeUpperBlit(const SDL_Surface *restrict const src,
if (srcy < 0)
{
h += srcy;
- dstrect->y -= static_cast<int16_t>(srcy);
+ dstrect->y -= CAST_S16(srcy);
srcy = 0;
}
int maxh = src->h - srcy;
@@ -863,7 +863,7 @@ int SDLGraphics::SDL_FakeUpperBlit(const SDL_Surface *restrict const src,
if (dx > 0)
{
w -= dx;
- dstrect->x += static_cast<int16_t>(dx);
+ dstrect->x += CAST_S16(dx);
srcx += dx;
}
dx = dstrect->x + w - clipX - clip->w;
@@ -874,7 +874,7 @@ int SDLGraphics::SDL_FakeUpperBlit(const SDL_Surface *restrict const src,
if (dy > 0)
{
h -= dy;
- dstrect->y += static_cast<int16_t>(dy);
+ dstrect->y += CAST_S16(dy);
srcy += dy;
}
dy = dstrect->y + h - clipY - clip->h;
@@ -883,12 +883,12 @@ int SDLGraphics::SDL_FakeUpperBlit(const SDL_Surface *restrict const src,
if (w > 0 && h > 0)
{
- srcrect->x = static_cast<int16_t>(srcx);
- srcrect->y = static_cast<int16_t>(srcy);
- srcrect->w = static_cast<int16_t>(w);
- srcrect->h = static_cast<int16_t>(h);
- dstrect->w = static_cast<int16_t>(w);
- dstrect->h = static_cast<int16_t>(h);
+ srcrect->x = CAST_S16(srcx);
+ srcrect->y = CAST_S16(srcy);
+ srcrect->w = CAST_S16(w);
+ srcrect->h = CAST_S16(h);
+ dstrect->w = CAST_S16(w);
+ dstrect->h = CAST_S16(h);
return 1;
// return SDL_LowerBlit(src, &sr, dst, dstrect);
@@ -925,8 +925,8 @@ void SDLGraphics::fillRectangle(const Rect &restrict rectangle) restrict2
const int bpp = mWindow->format->BytesPerPixel;
const uint32_t pixel = SDL_MapRGB(mWindow->format,
- static_cast<uint8_t>(mColor.r), static_cast<uint8_t>(mColor.g),
- static_cast<uint8_t>(mColor.b));
+ CAST_U8(mColor.r), CAST_U8(mColor.g),
+ CAST_U8(mColor.b));
switch (bpp)
{
@@ -934,11 +934,11 @@ void SDLGraphics::fillRectangle(const Rect &restrict rectangle) restrict2
cilk_for (int y = y1; y < y2; y++)
{
uint8_t *const p = static_cast<uint8_t *>(mWindow->pixels)
- + static_cast<size_t>(y * mWindow->pitch);
+ + CAST_SIZE(y * mWindow->pitch);
for (int x = x1; x < x2; x++)
{
- *(p + static_cast<size_t>(x))
- = static_cast<uint8_t>(pixel);
+ *(p + CAST_SIZE(x))
+ = CAST_U8(pixel);
}
}
break;
@@ -946,14 +946,14 @@ void SDLGraphics::fillRectangle(const Rect &restrict rectangle) restrict2
cilk_for (int y = y1; y < y2; y++)
{
uint8_t *const p0 = static_cast<uint8_t *>(mWindow->pixels)
- + static_cast<size_t>(y * mWindow->pitch);
+ + CAST_SIZE(y * mWindow->pitch);
for (int x = x1; x < x2; x++)
{
- uint8_t *const p = p0 + static_cast<size_t>(x * 2);
+ uint8_t *const p = p0 + CAST_SIZE(x * 2);
*reinterpret_cast<uint16_t *>(p) = SDLAlpha16(
- static_cast<uint16_t>(pixel),
+ CAST_U16(pixel),
*reinterpret_cast<uint16_t *>(p),
- static_cast<uint8_t>(mColor.a), mWindow->format);
+ CAST_U8(mColor.a), mWindow->format);
}
}
break;
@@ -967,18 +967,18 @@ void SDLGraphics::fillRectangle(const Rect &restrict rectangle) restrict2
cilk_for (int y = y1; y < y2; y++)
{
uint8_t *const p0 = static_cast<uint8_t *>(mWindow->pixels)
- + static_cast<size_t>(y * mWindow->pitch);
+ + CAST_SIZE(y * mWindow->pitch);
for (int x = x1; x < x2; x++)
{
- uint8_t *const p = p0 + static_cast<size_t>(x * 3);
+ uint8_t *const p = p0 + CAST_SIZE(x * 3);
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
- p[2] = static_cast<uint8_t>((p[2] * ca + cb) >> 8);
- p[1] = static_cast<uint8_t>((p[1] * ca + cg) >> 8);
- p[0] = static_cast<uint8_t>((p[0] * ca + cr) >> 8);
+ p[2] = CAST_U8((p[2] * ca + cb) >> 8);
+ p[1] = CAST_U8((p[1] * ca + cg) >> 8);
+ p[0] = CAST_U8((p[0] * ca + cr) >> 8);
#else
- p[0] = static_cast<uint8_t>((p[0] * ca + cb) >> 8);
- p[1] = static_cast<uint8_t>((p[1] * ca + cg) >> 8);
- p[2] = static_cast<uint8_t>((p[2] * ca + cr) >> 8);
+ p[0] = CAST_U8((p[0] * ca + cb) >> 8);
+ p[1] = CAST_U8((p[1] * ca + cg) >> 8);
+ p[2] = CAST_U8((p[2] * ca + cr) >> 8);
#endif
}
}
@@ -1059,10 +1059,10 @@ void SDLGraphics::fillRectangle(const Rect &restrict rectangle) restrict2
{
uint32_t *const p0 = reinterpret_cast<uint32_t*>(
static_cast<uint8_t*>(mWindow->pixels)
- + static_cast<size_t>(y * mWindow->pitch));
+ + CAST_SIZE(y * mWindow->pitch));
for (int x = x1; x < x2; x++)
{
- uint32_t *const p = p0 + static_cast<size_t>(x);
+ uint32_t *const p = p0 + CAST_SIZE(x);
const uint32_t dst = *p;
*p = cB[dst & bMask / bShift]
| cG[(dst & gMask) / gShift]
@@ -1082,17 +1082,17 @@ void SDLGraphics::fillRectangle(const Rect &restrict rectangle) restrict2
{
SDL_Rect rect =
{
- static_cast<int16_t>(area.x),
- static_cast<int16_t>(area.y),
- static_cast<uint16_t>(area.width),
- static_cast<uint16_t>(area.height)
+ CAST_S16(area.x),
+ CAST_S16(area.y),
+ CAST_U16(area.width),
+ CAST_U16(area.height)
};
const uint32_t color = SDL_MapRGBA(mWindow->format,
- static_cast<int8_t>(mColor.r),
- static_cast<int8_t>(mColor.g),
- static_cast<int8_t>(mColor.b),
- static_cast<int8_t>(mColor.a));
+ CAST_S8(mColor.r),
+ CAST_S8(mColor.g),
+ CAST_S8(mColor.b),
+ CAST_S8(mColor.a));
SDL_FillRect(mWindow, &rect, color);
}
}
@@ -1113,10 +1113,10 @@ void SDLGraphics::pushClipArea(const Rect &restrict area) restrict2
const ClipRect &restrict carea = mClipStack.top();
const SDL_Rect rect =
{
- static_cast<int16_t>(carea.x),
- static_cast<int16_t>(carea.y),
- static_cast<uint16_t>(carea.width),
- static_cast<uint16_t>(carea.height)
+ CAST_S16(carea.x),
+ CAST_S16(carea.y),
+ CAST_U16(carea.width),
+ CAST_U16(carea.height)
};
SDL_SetClipRect(mWindow, &rect);
}
@@ -1131,10 +1131,10 @@ void SDLGraphics::popClipArea() restrict2
const ClipRect &restrict carea = mClipStack.top();
const SDL_Rect rect =
{
- static_cast<int16_t>(carea.x),
- static_cast<int16_t>(carea.y),
- static_cast<uint16_t>(carea.width),
- static_cast<uint16_t>(carea.height)
+ CAST_S16(carea.x),
+ CAST_S16(carea.y),
+ CAST_U16(carea.width),
+ CAST_U16(carea.height)
};
SDL_SetClipRect(mWindow, &rect);
@@ -1205,23 +1205,23 @@ void SDLGraphics::drawHLine(int x1, int y, int x2) restrict2
SDL_LockSurface(mWindow);
uint8_t *p = static_cast<uint8_t*>(mWindow->pixels)
- + static_cast<size_t>(y * mWindow->pitch + x1 * bpp);
+ + CAST_SIZE(y * mWindow->pitch + x1 * bpp);
const uint32_t pixel = SDL_MapRGB(mWindow->format,
- static_cast<uint8_t>(mColor.r),
- static_cast<uint8_t>(mColor.g),
- static_cast<uint8_t>(mColor.b));
+ CAST_U8(mColor.r),
+ CAST_U8(mColor.g),
+ CAST_U8(mColor.b));
switch (bpp)
{
case 1:
for (; x1 <= x2; ++x1)
- *(p++) = static_cast<uint8_t>(pixel);
+ *(p++) = CAST_U8(pixel);
break;
case 2:
{
uint16_t* q = reinterpret_cast<uint16_t*>(p);
- const uint16_t pixel1 = static_cast<uint16_t>(pixel);
+ const uint16_t pixel1 = CAST_U16(pixel);
for (; x1 <= x2; ++x1)
*(q++) = pixel1;
break;
@@ -1229,9 +1229,9 @@ void SDLGraphics::drawHLine(int x1, int y, int x2) restrict2
case 3:
{
- const uint8_t b0 = static_cast<uint8_t>((pixel >> 16) & 0xff);
- const uint8_t b1 = static_cast<uint8_t>((pixel >> 8) & 0xff);
- const uint8_t b2 = static_cast<uint8_t>(pixel & 0xff);
+ const uint8_t b0 = CAST_U8((pixel >> 16) & 0xff);
+ const uint8_t b1 = CAST_U8((pixel >> 8) & 0xff);
+ const uint8_t b2 = CAST_U8(pixel & 0xff);
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
for (; x1 <= x2; ++x1)
{
@@ -1257,8 +1257,8 @@ void SDLGraphics::drawHLine(int x1, int y, int x2) restrict2
uint32_t *q = reinterpret_cast<uint32_t*>(p);
if (mAlpha)
{
- unsigned char a = static_cast<unsigned char>(mColor.a);
- unsigned char a1 = static_cast<unsigned char>(255U - a);
+ unsigned char a = CAST_U8(mColor.a);
+ unsigned char a1 = CAST_U8(255U - a);
const int b0 = (pixel & 0xff) * a;
const int g0 = (pixel & 0xff00) * a;
const int r0 = (pixel & 0xff0000) * a;
@@ -1330,12 +1330,12 @@ void SDLGraphics::drawVLine(int x, int y1, int y2) restrict2
SDL_LockSurface(mWindow);
uint8_t *p = static_cast<uint8_t*>(mWindow->pixels)
- + static_cast<size_t>(y1 * mWindow->pitch + x * bpp);
+ + CAST_SIZE(y1 * mWindow->pitch + x * bpp);
const uint32_t pixel = SDL_MapRGB(mWindow->format,
- static_cast<uint8_t>(mColor.r),
- static_cast<uint8_t>(mColor.g),
- static_cast<uint8_t>(mColor.b));
+ CAST_U8(mColor.r),
+ CAST_U8(mColor.g),
+ CAST_U8(mColor.b));
const int pitch = mWindow->pitch;
switch (bpp)
@@ -1343,7 +1343,7 @@ void SDLGraphics::drawVLine(int x, int y1, int y2) restrict2
case 1:
for (; y1 <= y2; ++y1)
{
- *p = static_cast<uint8_t>(pixel);
+ *p = CAST_U8(pixel);
p += pitch;
}
break;
@@ -1352,16 +1352,16 @@ void SDLGraphics::drawVLine(int x, int y1, int y2) restrict2
for (; y1 <= y2; ++ y1)
{
*reinterpret_cast<uint16_t*>(p)
- = static_cast<uint16_t>(pixel);
+ = CAST_U16(pixel);
p += pitch;
}
break;
case 3:
{
- const uint8_t b0 = static_cast<uint8_t>((pixel >> 16) & 0xff);
- const uint8_t b1 = static_cast<uint8_t>((pixel >> 8) & 0xff);
- const uint8_t b2 = static_cast<uint8_t>(pixel & 0xff);
+ const uint8_t b0 = CAST_U8((pixel >> 16) & 0xff);
+ const uint8_t b1 = CAST_U8((pixel >> 8) & 0xff);
+ const uint8_t b2 = CAST_U8(pixel & 0xff);
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
for (; y1 <= y2; ++y1)
{
@@ -1386,8 +1386,8 @@ void SDLGraphics::drawVLine(int x, int y1, int y2) restrict2
{
if (mAlpha)
{
- unsigned char a = static_cast<unsigned char>(mColor.a);
- unsigned char a1 = static_cast<unsigned char>(255U - a);
+ unsigned char a = CAST_U8(mColor.a);
+ unsigned char a1 = CAST_U8(255U - a);
const int b0 = (pixel & 0xff) * a;
const int g0 = (pixel & 0xff00) * a;
const int r0 = (pixel & 0xff0000) * a;
@@ -1470,8 +1470,8 @@ bool SDLGraphics::setVideoMode(const int w, const int h,
return false;
}
- mRect.w = static_cast<uint16_t>(mWindow->w);
- mRect.h = static_cast<uint16_t>(mWindow->h);
+ mRect.w = CAST_U16(mWindow->w);
+ mRect.h = CAST_U16(mWindow->h);
return videoInfo();
}
diff --git a/src/render/shaders/shadersmanager.cpp b/src/render/shaders/shadersmanager.cpp
index d24405927..753cca93d 100644
--- a/src/render/shaders/shadersmanager.cpp
+++ b/src/render/shaders/shadersmanager.cpp
@@ -56,7 +56,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[static_cast<size_t>(len) + 1];
+ char *buf = new char[CAST_SIZE(len) + 1];
mglGetShaderInfoLog(shaderId, len, &len, buf);
buf[len] = 0;
logger->log("Shader '%s' compilation error: %s", fileName.c_str(), buf);
@@ -113,7 +113,7 @@ ShaderProgram *ShadersManager::createProgram(const std::string &vertex,
GLint len = 0;
mglGetProgramiv(programId, GL_INFO_LOG_LENGTH, &len);
- char *buf = new char[static_cast<size_t>(len) + 1];
+ char *buf = new char[CAST_SIZE(len) + 1];
mglGetProgramInfoLog(programId, len, &len, buf);
buf[len] = 0;
logger->log("Program '%s, %s' compilation error: %s",
diff --git a/src/render/surfacegraphics.cpp b/src/render/surfacegraphics.cpp
index bc730920b..d3083dd5c 100644
--- a/src/render/surfacegraphics.cpp
+++ b/src/render/surfacegraphics.cpp
@@ -51,12 +51,12 @@ void SurfaceGraphics::drawImage(const Image *restrict const image,
const SDL_Rect &imageRect = image->mBounds;
SDL_Rect dstRect;
SDL_Rect srcRect;
- dstRect.x = static_cast<int16_t>(dstX);
- dstRect.y = static_cast<int16_t>(dstY);
- srcRect.x = static_cast<int16_t>(imageRect.x);
- srcRect.y = static_cast<int16_t>(imageRect.y);
- srcRect.w = static_cast<uint16_t>(imageRect.w);
- srcRect.h = static_cast<uint16_t>(imageRect.h);
+ dstRect.x = CAST_S16(dstX);
+ dstRect.y = CAST_S16(dstY);
+ srcRect.x = CAST_S16(imageRect.x);
+ srcRect.y = CAST_S16(imageRect.y);
+ srcRect.w = CAST_U16(imageRect.w);
+ srcRect.h = CAST_U16(imageRect.h);
#ifdef USE_SDL2
SDL_BlitSurface(image->mSDLSurface, &srcRect, mTarget, &dstRect);
@@ -84,12 +84,12 @@ void SurfaceGraphics::copyImage(const Image *restrict const image,
const SDL_Rect &imageRect = image->mBounds;
SDL_Rect dstRect;
SDL_Rect srcRect;
- dstRect.x = static_cast<int16_t>(dstX);
- dstRect.y = static_cast<int16_t>(dstY);
- srcRect.x = static_cast<int16_t>(imageRect.x);
- srcRect.y = static_cast<int16_t>(imageRect.y);
- srcRect.w = static_cast<uint16_t>(imageRect.w);
- srcRect.h = static_cast<uint16_t>(imageRect.h);
+ dstRect.x = CAST_S16(dstX);
+ dstRect.y = CAST_S16(dstY);
+ srcRect.x = CAST_S16(imageRect.x);
+ srcRect.y = CAST_S16(imageRect.y);
+ srcRect.w = CAST_U16(imageRect.w);
+ srcRect.h = CAST_U16(imageRect.h);
#ifdef USE_SDL2
// probably need change some flags
@@ -111,12 +111,12 @@ void SurfaceGraphics::drawImageCached(const Image *restrict const image,
SDL_Rect dstRect;
SDL_Rect srcRect;
- dstRect.x = static_cast<int16_t>(x);
- dstRect.y = static_cast<int16_t>(y);
- srcRect.x = static_cast<int16_t>(rect.x);
- srcRect.y = static_cast<int16_t>(rect.y);
- srcRect.w = static_cast<uint16_t>(rect.w);
- srcRect.h = static_cast<uint16_t>(rect.h);
+ dstRect.x = CAST_S16(x);
+ dstRect.y = CAST_S16(y);
+ srcRect.x = CAST_S16(rect.x);
+ srcRect.y = CAST_S16(rect.y);
+ srcRect.w = CAST_U16(rect.w);
+ srcRect.h = CAST_U16(rect.h);
#ifdef USE_SDL2
SDL_BlitSurface(image->mSDLSurface, &srcRect, mTarget, &dstRect);
diff --git a/src/resources/ambientlayer.cpp b/src/resources/ambientlayer.cpp
index 298bdb0e1..644c71578 100644
--- a/src/resources/ambientlayer.cpp
+++ b/src/resources/ambientlayer.cpp
@@ -64,9 +64,9 @@ AmbientLayer::AmbientLayer(Image *const img,
// the default resolution...
Image *const rescaledOverlay = resourceManager->getRescaled(
mImage,
- static_cast<int>(mImage->mBounds.w) /
+ CAST_S32(mImage->mBounds.w) /
defaultScreenWidth * width,
- static_cast<int>(mImage->mBounds.h) /
+ CAST_S32(mImage->mBounds.h) /
defaultScreenHeight * height);
if (rescaledOverlay)
@@ -127,18 +127,18 @@ void AmbientLayer::draw(Graphics *const graphics, const int x,
if (imageHelper->useOpenGL() == RENDER_SOFTWARE ||
!mKeepRatio)
{
- graphics->drawPattern(mImage, static_cast<int>(-mPosX),
- static_cast<int>(-mPosY), x + static_cast<int>(mPosX),
- y + static_cast<int>(mPosY));
+ graphics->drawPattern(mImage, CAST_S32(-mPosX),
+ CAST_S32(-mPosY), x + CAST_S32(mPosX),
+ y + CAST_S32(mPosY));
}
else
{
- graphics->drawRescaledPattern(mImage, static_cast<int>(-mPosX),
- static_cast<int>(-mPosY), x + static_cast<int>(mPosX),
- y + static_cast<int>(mPosY),
- static_cast<int>(mImage->mBounds.w)
+ graphics->drawRescaledPattern(mImage, CAST_S32(-mPosX),
+ CAST_S32(-mPosY), x + CAST_S32(mPosX),
+ y + CAST_S32(mPosY),
+ CAST_S32(mImage->mBounds.w)
/ defaultScreenWidth * graphics->mWidth,
- static_cast<int>(mImage->mBounds.h) / defaultScreenHeight
+ CAST_S32(mImage->mBounds.h) / defaultScreenHeight
* graphics->mHeight);
}
}
diff --git a/src/resources/animation/simpleanimation.cpp b/src/resources/animation/simpleanimation.cpp
index 1a1d30094..e4c0d8a3f 100644
--- a/src/resources/animation/simpleanimation.cpp
+++ b/src/resources/animation/simpleanimation.cpp
@@ -98,8 +98,8 @@ void SimpleAnimation::setFrame(int frame)
if (frame < 0)
frame = 0;
- const unsigned int len = static_cast<unsigned>(mAnimation->getLength());
- if (static_cast<unsigned>(frame) >= len)
+ const unsigned int len = CAST_U32(mAnimation->getLength());
+ if (CAST_U32(frame) >= len)
frame = len - 1;
mAnimationPhase = frame;
mCurrentFrame = &mAnimation->mFrames[frame];
@@ -119,7 +119,7 @@ bool SimpleAnimation::update(const int timePassed)
mAnimationTime -= mCurrentFrame->delay;
mAnimationPhase++;
- if (static_cast<size_t>(mAnimationPhase) >= mAnimation->getLength())
+ if (CAST_SIZE(mAnimationPhase) >= mAnimation->getLength())
mAnimationPhase = 0;
mCurrentFrame = &mAnimation->mFrames[mAnimationPhase];
@@ -132,7 +132,7 @@ int SimpleAnimation::getLength() const
if (!mAnimation)
return 0;
- return static_cast<int>(mAnimation->getLength());
+ return CAST_S32(mAnimation->getLength());
}
Image *SimpleAnimation::getCurrentImage() const
diff --git a/src/resources/beingcommon.cpp b/src/resources/beingcommon.cpp
index d9b65bb02..af1f8e138 100644
--- a/src/resources/beingcommon.cpp
+++ b/src/resources/beingcommon.cpp
@@ -75,7 +75,7 @@ void BeingCommon::readBasicAttributes(BeingInfo *const info,
else if (walkStr == "walkswim" || walkStr == "swimwalk") // legacy
block |= BlockMask::GROUND | BlockMask::WATER;
}
- info->setBlockWalkMask(static_cast<unsigned char>(block ^ allFlags));
+ info->setBlockWalkMask(CAST_U8(block ^ allFlags));
}
bool BeingCommon::readObjectNodes(XmlNodePtrConst &spriteNode,
diff --git a/src/resources/beinginfo.cpp b/src/resources/beinginfo.cpp
index aa393dc72..d27339483 100644
--- a/src/resources/beinginfo.cpp
+++ b/src/resources/beinginfo.cpp
@@ -161,7 +161,7 @@ const SoundInfo &BeingInfo::getSound(const ItemSoundEvent::Type event) const
if (!vect || vect->empty())
return emptySound;
else
- return vect->at(static_cast<size_t>(rand()) % vect->size());
+ return vect->at(CAST_SIZE(rand()) % vect->size());
}
const Attack *BeingInfo::getAttack(const int id) const
diff --git a/src/resources/db/colordb.cpp b/src/resources/db/colordb.cpp
index 674f70ef6..07dd7b46e 100644
--- a/src/resources/db/colordb.cpp
+++ b/src/resources/db/colordb.cpp
@@ -63,7 +63,7 @@ void ColorDB::load()
it = mColorLists.find("hair");
if (it != mColorLists.end())
- mHairColorsSize = static_cast<int>((*it).second.size());
+ mHairColorsSize = CAST_S32((*it).second.size());
else
mHairColorsSize = 0;
mLoaded = true;
diff --git a/src/resources/dye/dye.cpp b/src/resources/dye/dye.cpp
index c6e2ddd17..129756673 100644
--- a/src/resources/dye/dye.cpp
+++ b/src/resources/dye/dye.cpp
@@ -211,7 +211,7 @@ endlabel:{}
#else // ENABLE_CILKPLUS
- for (uint32_t *p_end = pixels + static_cast<size_t>(bufSize);
+ for (uint32_t *p_end = pixels + CAST_SIZE(bufSize);
pixels != p_end;
++ pixels)
{
@@ -330,7 +330,7 @@ endlabel:{}
#else // ENABLE_CILKPLUS
- for (uint32_t *p_end = pixels + static_cast<size_t>(bufSize);
+ for (uint32_t *p_end = pixels + CAST_SIZE(bufSize);
pixels != p_end;
++ pixels)
{
diff --git a/src/resources/dye/dyepalette.cpp b/src/resources/dye/dyepalette.cpp
index 19ded4295..6ec85a399 100644
--- a/src/resources/dye/dyepalette.cpp
+++ b/src/resources/dye/dyepalette.cpp
@@ -40,7 +40,7 @@ DyePalette::DyePalette(const std::string &restrict description,
const uint8_t blockSize) :
mColors()
{
- const size_t size = static_cast<size_t>(description.length());
+ const size_t size = CAST_SIZE(description.length());
if (size == 0)
return;
@@ -100,7 +100,7 @@ void DyePalette::hexToColor(const std::string &hexStr,
i < blockSize && colorIdx < 4;
i += 2, colorIdx ++)
{
- color.value[colorIdx] = static_cast<unsigned char>((
+ color.value[colorIdx] = CAST_U8((
hexDecode(hexStr[i]) << 4)
+ hexDecode(hexStr[i + 1]));
}
@@ -129,7 +129,7 @@ void DyePalette::getColor(const unsigned int intensity,
return;
}
- const int last = static_cast<int>(mColors.size());
+ const int last = CAST_S32(mColors.size());
if (last == 0)
return;
@@ -193,8 +193,8 @@ void DyePalette::getColor(double intensity,
intensity *= static_cast<double>(mColors.size() - 1);
// Color indices
- const int i = static_cast<int>(floor(intensity));
- const int j = static_cast<int>(ceil(intensity));
+ const int i = CAST_S32(floor(intensity));
+ const int j = CAST_S32(ceil(intensity));
const DyeColor &colorI = mColors[i];
if (i == j)
@@ -211,11 +211,11 @@ void DyePalette::getColor(double intensity,
const DyeColor &colorJ = mColors[j];
// Perform the interpolation.
- color[0] = static_cast<int>(rest * colorI.value[0] +
+ color[0] = CAST_S32(rest * colorI.value[0] +
intensity * colorJ.value[0]);
- color[1] = static_cast<int>(rest * colorI.value[1] +
+ color[1] = CAST_S32(rest * colorI.value[1] +
intensity * colorJ.value[1]);
- color[2] = static_cast<int>(rest * colorI.value[2] +
+ color[2] = CAST_S32(rest * colorI.value[2] +
intensity * colorJ.value[2]);
}
@@ -277,7 +277,7 @@ void DyePalette::replaceSColor(uint32_t *restrict pixels,
}
#else // ENABLE_CILKPLUS
- for (uint32_t *p_end = pixels + static_cast<size_t>(bufSize);
+ for (uint32_t *p_end = pixels + CAST_SIZE(bufSize);
pixels != p_end;
++ pixels)
{
@@ -377,7 +377,7 @@ void DyePalette::replaceAColor(uint32_t *restrict pixels,
#else // ENABLE_CILKPLUS
- for (uint32_t *p_end = pixels + static_cast<size_t>(bufSize);
+ for (uint32_t *p_end = pixels + CAST_SIZE(bufSize);
pixels != p_end;
++pixels)
{
@@ -470,7 +470,7 @@ void DyePalette::replaceSOGLColor(uint32_t *restrict pixels,
#else // ENABLE_CILKPLUS
- for (uint32_t *p_end = pixels + static_cast<size_t>(bufSize);
+ for (uint32_t *p_end = pixels + CAST_SIZE(bufSize);
pixels != p_end;
++pixels)
{
@@ -562,7 +562,7 @@ void DyePalette::replaceAOGLColor(uint32_t *restrict pixels,
#else // ENABLE_CILKPLUS
- for (uint32_t *p_end = pixels + static_cast<size_t>(bufSize);
+ for (uint32_t *p_end = pixels + CAST_SIZE(bufSize);
pixels != p_end;
++pixels)
{
diff --git a/src/resources/image.cpp b/src/resources/image.cpp
index b16ea8939..d820adcfb 100644
--- a/src/resources/image.cpp
+++ b/src/resources/image.cpp
@@ -72,8 +72,8 @@ Image::Image(SDL_Texture *restrict const image,
if (mTexture)
{
- mBounds.w = static_cast<uint16_t>(width);
- mBounds.h = static_cast<uint16_t>(height);
+ mBounds.w = CAST_U16(width);
+ mBounds.h = CAST_U16(height);
mLoaded = true;
}
@@ -118,8 +118,8 @@ Image::Image(SDL_Surface *restrict const image, const bool hasAlphaChannel0,
if (mSDLSurface)
{
- mBounds.w = static_cast<uint16_t>(mSDLSurface->w);
- mBounds.h = static_cast<uint16_t>(mSDLSurface->h);
+ mBounds.w = CAST_U16(mSDLSurface->w);
+ mBounds.h = CAST_U16(mSDLSurface->h);
mLoaded = true;
}
@@ -159,8 +159,8 @@ Image::Image(const GLuint glimage, const int width, const int height,
mBounds.x = 0;
mBounds.y = 0;
- mBounds.w = static_cast<uint16_t>(width);
- mBounds.h = static_cast<uint16_t>(height);
+ mBounds.w = CAST_U16(width);
+ mBounds.h = CAST_U16(height);
if (mGLImage)
{
@@ -314,11 +314,11 @@ void Image::setAlpha(const float alpha)
{
#ifdef USE_SDL2
SDL_SetSurfaceAlphaMod(mSDLSurface,
- static_cast<unsigned char>(255 * mAlpha));
+ CAST_U8(255 * mAlpha));
#else
// Set the alpha value this image is drawn at
SDL_SetAlpha(mSDLSurface, SDL_SRCALPHA,
- static_cast<unsigned char>(255 * mAlpha));
+ CAST_U8(255 * mAlpha));
#endif
}
else
@@ -349,7 +349,7 @@ void Image::setAlpha(const float alpha)
const uint8_t sourceAlpha = mAlphaChannel[i];
if (sourceAlpha > 0)
{
- const uint8_t a = static_cast<uint8_t>(
+ const uint8_t a = CAST_U8(
static_cast<float>(sourceAlpha) * mAlpha);
uint32_t c = (static_cast<uint32_t*>(
@@ -372,7 +372,7 @@ void Image::setAlpha(const float alpha)
const uint8_t sourceAlpha = mAlphaChannel[i];
if (sourceAlpha > 0)
{
- const uint8_t a = static_cast<uint8_t>(
+ const uint8_t a = CAST_U8(
static_cast<float>(sourceAlpha) * mAlpha);
uint32_t c = (static_cast<uint32_t*>(
@@ -395,7 +395,7 @@ void Image::setAlpha(const float alpha)
{
mAlpha = alpha;
SDL_SetTextureAlphaMod(mTexture,
- static_cast<unsigned char>(255 * mAlpha));
+ CAST_U8(255 * mAlpha));
}
#endif
else
diff --git a/src/resources/imagehelper.cpp b/src/resources/imagehelper.cpp
index f4e09b834..af573709b 100644
--- a/src/resources/imagehelper.cpp
+++ b/src/resources/imagehelper.cpp
@@ -176,15 +176,15 @@ void ImageHelper::dumpSurfaceFormat(const SDL_Surface *const image)
logger->log("Alpha: %d", format->alpha);
#endif
logger->log("Loss: %02x, %02x, %02x, %02x",
- static_cast<unsigned int>(format->Rloss),
- static_cast<unsigned int>(format->Gloss),
- static_cast<unsigned int>(format->Bloss),
- static_cast<unsigned int>(format->Aloss));
+ CAST_U32(format->Rloss),
+ CAST_U32(format->Gloss),
+ CAST_U32(format->Bloss),
+ CAST_U32(format->Aloss));
logger->log("Shift: %02x, %02x, %02x, %02x",
- static_cast<unsigned int>(format->Rshift),
- static_cast<unsigned int>(format->Gshift),
- static_cast<unsigned int>(format->Bshift),
- static_cast<unsigned int>(format->Ashift));
+ CAST_U32(format->Rshift),
+ CAST_U32(format->Gshift),
+ CAST_U32(format->Bshift),
+ CAST_U32(format->Ashift));
logger->log("Mask: %08x, %08x, %08x, %08x", format->Rmask,
format->Gmask, format->Bmask, format->Amask);
}
diff --git a/src/resources/imageset.cpp b/src/resources/imageset.cpp
index 2580b5684..e3ce9e7d1 100644
--- a/src/resources/imageset.cpp
+++ b/src/resources/imageset.cpp
@@ -67,7 +67,7 @@ Image* ImageSet::get(const size_type i) const
if (i >= mImages.size())
{
logger->log("Warning: No sprite %d in this image set",
- static_cast<int>(i));
+ CAST_S32(i));
return nullptr;
}
else
diff --git a/src/resources/imagewriter.cpp b/src/resources/imagewriter.cpp
index 50db9b867..e599af156 100644
--- a/src/resources/imagewriter.cpp
+++ b/src/resources/imagewriter.cpp
@@ -83,7 +83,7 @@ bool ImageWriter::writePNG(SDL_Surface *const surface,
png_set_packing(png_ptr);
png_bytep *const row_pointers
- = new png_bytep[static_cast<size_t>(surface->h)];
+ = new png_bytep[CAST_SIZE(surface->h)];
/*
if (!row_pointers)
{
@@ -96,7 +96,7 @@ bool ImageWriter::writePNG(SDL_Surface *const surface,
for (int i = 0; i < surface->h; i++)
{
row_pointers[i] = static_cast<png_bytep>(static_cast<uint8_t *>(
- surface->pixels) + static_cast<size_t>(i * surface->pitch));
+ surface->pixels) + CAST_SIZE(i * surface->pitch));
}
png_write_image(png_ptr, row_pointers);
diff --git a/src/resources/inventory/complexinventory.cpp b/src/resources/inventory/complexinventory.cpp
index 06a8cf5c0..5264406cb 100644
--- a/src/resources/inventory/complexinventory.cpp
+++ b/src/resources/inventory/complexinventory.cpp
@@ -47,7 +47,7 @@ bool ComplexInventory::addVirtualItem(const Item *const item,
if (!item || PlayerInfo::isItemProtected(item->getId()))
return false;
- if (index >= 0 && index < static_cast<int>(mSize))
+ if (index >= 0 && index < CAST_S32(mSize))
{
ComplexItem *citem = nullptr;
if (mItems[index] != nullptr)
@@ -126,7 +126,7 @@ void ComplexInventory::setItem(const int index,
const Equipm equipment,
const Equipped equipped)
{
- if (index < 0 || index >= static_cast<int>(mSize))
+ if (index < 0 || index >= CAST_S32(mSize))
{
logger->log("Warning: invalid inventory index: %d", index);
return;
diff --git a/src/resources/inventory/inventory.cpp b/src/resources/inventory/inventory.cpp
index c73d9d8b6..f7f6dcaee 100644
--- a/src/resources/inventory/inventory.cpp
+++ b/src/resources/inventory/inventory.cpp
@@ -58,9 +58,9 @@ Inventory::Inventory(const InventoryTypeT type, const int size1) :
mInventoryListeners(),
mVirtualRemove(),
mType(type),
- mSize(size1 == -1 ? static_cast<unsigned>(
+ mSize(size1 == -1 ? CAST_U32(
inventoryHandler->getSize(type))
- : static_cast<unsigned>(size1)),
+ : CAST_U32(size1)),
mItems(new Item*[mSize]),
mUsed(0)
{
@@ -78,7 +78,7 @@ Inventory::~Inventory()
Item *Inventory::getItem(const int index) const
{
- if (index < 0 || index >= static_cast<int>(mSize) || !mItems[index]
+ if (index < 0 || index >= CAST_S32(mSize) || !mItems[index]
|| mItems[index]->mQuantity <= 0)
{
return nullptr;
@@ -137,7 +137,7 @@ void Inventory::setItem(const int index,
const Equipm equipment,
const Equipped equipped)
{
- if (index < 0 || index >= static_cast<int>(mSize))
+ if (index < 0 || index >= CAST_S32(mSize))
{
logger->log("Warning: invalid inventory index: %d", index);
return;
@@ -173,7 +173,7 @@ void Inventory::setCards(const int index,
const int *const cards,
const int size) const
{
- if (index < 0 || index >= static_cast<int>(mSize))
+ if (index < 0 || index >= CAST_S32(mSize))
{
logger->log("Warning: invalid inventory index: %d", index);
return;
@@ -232,7 +232,7 @@ int Inventory::getFreeSlot() const
Item **const i = std::find_if(mItems, mItems + mSize,
std::not1(SlotUsed()));
return (i == mItems + mSize) ? -1
- : static_cast<int>(i - mItems);
+ : CAST_S32(i - mItems);
}
int Inventory::getLastUsedSlot() const
@@ -355,7 +355,7 @@ void Inventory::resize(const unsigned int newSize)
delete [] mItems;
mSize = newSize;
- mItems = new Item*[static_cast<size_t>(mSize)];
+ mItems = new Item*[CAST_SIZE(mSize)];
std::fill_n(mItems, mSize, static_cast<Item*>(nullptr));
}
@@ -377,7 +377,7 @@ bool Inventory::addVirtualItem(const Item *const item,
{
if (item && !PlayerInfo::isItemProtected(item->getId()))
{
- if (index >= 0 && index < static_cast<int>(mSize))
+ if (index >= 0 && index < CAST_S32(mSize))
{
if (mItems[index] != nullptr)
return false;
@@ -434,7 +434,7 @@ void Inventory::virtualRemove(Item *const item,
void Inventory::restoreVirtuals()
{
- const int sz = static_cast<int>(mSize);
+ const int sz = CAST_S32(mSize);
logger->log("Inventory::restoreVirtuals 1");
FOR_EACH (IntMapCIter, it, mVirtualRemove)
@@ -461,7 +461,7 @@ void Inventory::virtualRestore(const Item *const item,
mVirtualRemove[index] -= amount;
if (mVirtualRemove[index] < 0)
mVirtualRemove.erase(index);
- if (index < 0 || index >= static_cast<int>(mSize) || !mItems[index])
+ if (index < 0 || index >= CAST_S32(mSize) || !mItems[index])
return;
mItems[index]->mQuantity += amount;
}
@@ -471,9 +471,9 @@ void Inventory::moveItem(const int index1,
const int index2)
{
if (index1 < 0 ||
- index1 >= static_cast<int>(mSize) ||
+ index1 >= CAST_S32(mSize) ||
index2 < 0 ||
- index2 >= static_cast<int>(mSize))
+ index2 >= CAST_S32(mSize))
{
return;
}
diff --git a/src/resources/item/item.cpp b/src/resources/item/item.cpp
index ae31dd94c..044e11fdb 100644
--- a/src/resources/item/item.cpp
+++ b/src/resources/item/item.cpp
@@ -87,7 +87,7 @@ void Item::setId(const int id,
mColor = color;
// Types 0 and 1 are not equippable items.
- mEquipment = fromBool(id && static_cast<int>(getInfo().getType())
+ mEquipment = fromBool(id && CAST_S32(getInfo().getType())
>= 2, Equipm);
if (mImage)
diff --git a/src/resources/iteminfo.cpp b/src/resources/iteminfo.cpp
index 5d96e382e..9fd4f2ba2 100644
--- a/src/resources/iteminfo.cpp
+++ b/src/resources/iteminfo.cpp
@@ -102,12 +102,12 @@ const std::string &ItemInfo::getSprite(const GenderT gender,
{
static const std::string empty;
std::map<int, std::string>::const_iterator i =
- mAnimationFiles.find(static_cast<int>(gender) +
+ mAnimationFiles.find(CAST_S32(gender) +
toInt(race, int) * 4);
if (i != mAnimationFiles.end())
return i->second;
- i = mAnimationFiles.find(static_cast<int>(gender));
+ i = mAnimationFiles.find(CAST_S32(gender));
if (i != mAnimationFiles.end())
return i->second;
return empty;
@@ -162,7 +162,7 @@ const SoundInfo &ItemInfo::getSound(const ItemSoundEvent::Type event) const
if (i == mSounds.end())
return empty;
- return (!i->second.empty()) ? i->second[static_cast<unsigned int>(rand())
+ return (!i->second.empty()) ? i->second[CAST_U32(rand())
% i->second.size()] : empty;
}
@@ -275,7 +275,7 @@ const std::string ItemInfo::replaceColors(std::string str,
str = replaceAll(str, "%color%", name);
if (!name.empty())
- name[0] = static_cast<signed char>(toupper(name[0]));
+ name[0] = CAST_S8(toupper(name[0]));
return replaceAll(str, "%Color%", name);
}
@@ -397,7 +397,7 @@ void ItemInfo::setSprite(const std::string &animationFile,
const GenderT gender,
const int race)
{
- mAnimationFiles[static_cast<int>(gender) + race * 4] = animationFile;
+ mAnimationFiles[CAST_S32(gender) + race * 4] = animationFile;
}
std::string ItemInfo::getColorName(const ItemColor idx) const
diff --git a/src/resources/iteminfo.h b/src/resources/iteminfo.h
index b58ae0b60..2bf4e7980 100644
--- a/src/resources/iteminfo.h
+++ b/src/resources/iteminfo.h
@@ -292,11 +292,11 @@ class ItemInfo final
{ return mProtected; }
int getColorsSize() const
- { return mColorsList ? static_cast<int>(mColorsList->size()) : 0; }
+ { return mColorsList ? CAST_S32(mColorsList->size()) : 0; }
int getIconColorsSize() const
{
- return mIconColorsList ? static_cast<int>(mIconColorsList->size())
+ return mIconColorsList ? CAST_S32(mIconColorsList->size())
: 0;
}
diff --git a/src/resources/map/map.cpp b/src/resources/map/map.cpp
index cb5d67583..51bb90f9d 100644
--- a/src/resources/map/map.cpp
+++ b/src/resources/map/map.cpp
@@ -1207,7 +1207,7 @@ void Map::saveExtraLayer() const restrict2
&& item->mType != MapItemType::HOME)
{
mapFile << x << " " << y << " "
- << static_cast<int>(item->mType) << " "
+ << CAST_S32(item->mType) << " "
<< item->mComment << std::endl;
}
}
@@ -1365,8 +1365,8 @@ void Map::indexTilesets() restrict2
FOR_EACH (Tilesets::const_iterator, it, mTilesets)
{
const size_t sz = (*it)->size();
- if (!s || static_cast<size_t>(s->getFirstGid()) + sSz
- < static_cast<size_t>((*it)->getFirstGid()) + sz)
+ if (!s || CAST_SIZE(s->getFirstGid()) + sSz
+ < CAST_SIZE((*it)->getFirstGid()) + sz)
{
s = *it;
sSz = sz;
@@ -1379,10 +1379,10 @@ void Map::indexTilesets() restrict2
return;
}
- const int size = static_cast<int>(s->getFirstGid())
- + static_cast<int>(s->size());
+ const int size = CAST_S32(s->getFirstGid())
+ + CAST_S32(s->size());
mIndexedTilesetsSize = size;
- mIndexedTilesets = new Tileset*[static_cast<size_t>(size)];
+ mIndexedTilesets = new Tileset*[CAST_SIZE(size)];
std::fill_n(mIndexedTilesets, size, static_cast<Tileset*>(nullptr));
FOR_EACH (Tilesets::const_iterator, it, mTilesets)
@@ -1391,7 +1391,7 @@ void Map::indexTilesets() restrict2
if (s2)
{
const int start = s2->getFirstGid();
- const int end = start + static_cast<int>(s2->size());
+ const int end = start + CAST_S32(s2->size());
for (int f = start; f < end; f ++)
{
if (f < size)
@@ -1546,7 +1546,7 @@ void Map::reduce() restrict2
++ ri;
continue;
}
- const size_t pos = static_cast<size_t>(
+ const size_t pos = CAST_SIZE(
x + y * layer2->mWidth);
img = layer2->mTiles[pos].image;
if (img)
diff --git a/src/resources/map/map.h b/src/resources/map/map.h
index ea540907a..4ee387f8f 100644
--- a/src/resources/map/map.h
+++ b/src/resources/map/map.h
@@ -290,7 +290,7 @@ class Map final : public Properties, public ConfigListener
const int y) const restrict2 A_WARN_UNUSED;
int getActorsCount() const restrict2 A_WARN_UNUSED
- { return static_cast<int>(mActors.size()); }
+ { return CAST_S32(mActors.size()); }
void setPvpMode(const int mode) restrict2;
diff --git a/src/resources/map/mapheights.h b/src/resources/map/mapheights.h
index 67e73bcc4..333e7fac4 100644
--- a/src/resources/map/mapheights.h
+++ b/src/resources/map/mapheights.h
@@ -38,7 +38,7 @@ class MapHeights final
uint8_t getHeight(const int x, const int y) const
{ return x < mWidth && y < mHeight ? mTiles[x + y * mWidth]
- : static_cast<uint8_t>(0U); }
+ : CAST_U8(0U); }
private:
int mWidth;
diff --git a/src/resources/map/maplayer.cpp b/src/resources/map/maplayer.cpp
index bedd0da35..6567b2177 100644
--- a/src/resources/map/maplayer.cpp
+++ b/src/resources/map/maplayer.cpp
@@ -135,7 +135,7 @@ void MapLayer::draw(Graphics *const graphics,
const int py0 = y32 + dy;
- TileInfo *tilePtr = &mTiles[static_cast<size_t>(startX + yWidth)];
+ TileInfo *tilePtr = &mTiles[CAST_SIZE(startX + yWidth)];
for (int x = startX; x < endX; x++, tilePtr++)
{
@@ -235,7 +235,7 @@ void MapLayer::updateSDL(const Graphics *const graphics,
const int yWidth = y * mWidth;
const int py0 = y * mapTileSize + dy;
- TileInfo *tilePtr = &mTiles[static_cast<size_t>(startX + yWidth)];
+ TileInfo *tilePtr = &mTiles[CAST_SIZE(startX + yWidth)];
for (int x = startX; x < endX; x++, tilePtr++)
{
@@ -304,7 +304,7 @@ void MapLayer::updateOGL(Graphics *const graphics,
{
const int yWidth = y * mWidth;
const int py0 = y * mapTileSize + dy;
- TileInfo *tilePtr = &mTiles[static_cast<size_t>(startX + yWidth)];
+ TileInfo *tilePtr = &mTiles[CAST_SIZE(startX + yWidth)];
for (int x = startX; x < endX; x++, tilePtr++)
{
if (!tilePtr->isEnabled)
@@ -509,7 +509,7 @@ void MapLayer::drawFringe(Graphics *const graphics,
const int py0 = y32 + dy;
const int py1 = y32 - scrollY;
- TileInfo *tilePtr = &mTiles[static_cast<size_t>(startX + yWidth)];
+ TileInfo *tilePtr = &mTiles[CAST_SIZE(startX + yWidth)];
for (int x = startX; x < endX; x++, tilePtr++)
{
if (!tilePtr->isEnabled)
@@ -598,7 +598,7 @@ void MapLayer::drawFringe(Graphics *const graphics,
const int py0 = y32 + dy;
- TileInfo *tilePtr = &mTiles[static_cast<size_t>(startX + yWidth)];
+ TileInfo *tilePtr = &mTiles[CAST_SIZE(startX + yWidth)];
for (int x = startX; x < endX; x++, tilePtr++)
{
if (!tilePtr->isEnabled)
diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp
index 40a64217d..ff0fa6a7d 100644
--- a/src/resources/mapreader.cpp
+++ b/src/resources/mapreader.cpp
@@ -159,7 +159,7 @@ int inflateMemory(unsigned char *restrict const in,
return Z_MEM_ERROR;
}
- strm.next_out = out + static_cast<size_t>(bufferSize);
+ strm.next_out = out + CAST_SIZE(bufferSize);
strm.avail_out = bufferSize;
bufferSize *= 2;
}
@@ -564,7 +564,7 @@ inline static void setTile(Map *const map,
break;
if (heights && map->getVersion() >= 2)
{
- heights->setHeight(x, y, static_cast<uint8_t>(
+ heights->setHeight(x, y, CAST_U8(
gid - set->getFirstGid() + 1));
}
else
@@ -644,7 +644,7 @@ bool MapReader::readBase64Layer(const XmlNodePtrConst childNode,
int binLen;
unsigned char *binData = php3_base64_decode(charData,
- static_cast<int>(strlen(reinterpret_cast<char*>(
+ CAST_S32(strlen(reinterpret_cast<char*>(
charData))), &binLen);
delete [] charData;
diff --git a/src/resources/resourcemanager.h b/src/resources/resourcemanager.h
index 7d173a99c..350c9b97f 100644
--- a/src/resources/resourcemanager.h
+++ b/src/resources/resourcemanager.h
@@ -229,7 +229,7 @@ class ResourceManager final
static void deleteInstance();
int size() const A_WARN_UNUSED
- { return static_cast<int>(mResources.size()); }
+ { return CAST_S32(mResources.size()); }
typedef std::map<std::string, Resource*> Resources;
typedef Resources::iterator ResourceIterator;
diff --git a/src/resources/sdlimagehelper.cpp b/src/resources/sdlimagehelper.cpp
index e0901f178..e61391d14 100644
--- a/src/resources/sdlimagehelper.cpp
+++ b/src/resources/sdlimagehelper.cpp
@@ -137,7 +137,7 @@ Image *SDLImageHelper::createTextSurface(SDL_Surface *const tmpImage,
const uint8_t a = static_cast<const uint8_t>((v << fmt->Aloss)
+ (v >> (8 - (fmt->Aloss << 1))));
- const uint8_t a2 = static_cast<uint8_t>(
+ const uint8_t a2 = CAST_U8(
static_cast<float>(a) * alpha);
c &= ~fmt->Amask;
@@ -297,8 +297,8 @@ void SDLImageHelper::copySurfaceToImage(const Image *const image,
SDL_SetAlpha(surface, 0, SDL_ALPHA_OPAQUE);
SDL_Rect rect =
{
- static_cast<int16_t>(x), static_cast<int16_t>(y),
- static_cast<uint16_t>(surface->w), static_cast<uint16_t>(surface->h)
+ CAST_S16(x), CAST_S16(y),
+ CAST_U16(surface->w), static_cast<uint16_t>(surface->h)
};
SDL_BlitSurface(surface, nullptr, image->mSDLSurface, &rect);
diff --git a/src/resources/sprite/animatedsprite.cpp b/src/resources/sprite/animatedsprite.cpp
index 5210ce626..08d73c2c5 100644
--- a/src/resources/sprite/animatedsprite.cpp
+++ b/src/resources/sprite/animatedsprite.cpp
@@ -214,16 +214,16 @@ bool AnimatedSprite::updateCurrentAnimation(const unsigned int time) restrict2
mFrameTime += time;
- while ((mFrameTime > static_cast<unsigned int>(mFrame->delay) &&
+ while ((mFrameTime > CAST_U32(mFrame->delay) &&
mFrame->delay > 0) ||
(mFrame->type != Frame::ANIMATION &&
mFrame->type != Frame::PAUSE))
{
bool fail(true);
- mFrameTime -= static_cast<unsigned int>(mFrame->delay);
+ mFrameTime -= CAST_U32(mFrame->delay);
mFrameIndex++;
- if (mFrameIndex >= static_cast<unsigned int>(mAnimation->getLength()))
+ if (mFrameIndex >= CAST_U32(mAnimation->getLength()))
mFrameIndex = 0;
mFrame = &mAnimation->mFrames[mFrameIndex];
@@ -249,8 +249,8 @@ bool AnimatedSprite::updateCurrentAnimation(const unsigned int time) restrict2
if (frame->type == Frame::LABEL &&
mFrame->nextAction == frame->nextAction)
{
- mFrameIndex = static_cast<unsigned int>(i);
- if (mFrameIndex >= static_cast<unsigned int>(
+ mFrameIndex = CAST_U32(i);
+ if (mFrameIndex >= CAST_U32(
mAnimation->getLength()))
{
mFrameIndex = 0;
@@ -293,7 +293,7 @@ bool AnimatedSprite::updateCurrentAnimation(const unsigned int time) restrict2
else
{
if (mFrame->rand == 100 || mFrameIndex
- >= static_cast<unsigned int>(mAnimation->getLength()))
+ >= CAST_U32(mAnimation->getLength()))
{
fail = false;
}
@@ -376,7 +376,7 @@ bool AnimatedSprite::setSpriteDirection(const SpriteDirection::Type direction)
unsigned int AnimatedSprite::getFrameCount() const restrict2
{
if (mAnimation)
- return static_cast<unsigned int>(mAnimation->getLength());
+ return CAST_U32(mAnimation->getLength());
else
return 0;
}
diff --git a/src/resources/subimage.cpp b/src/resources/subimage.cpp
index 33177909b..af579e4ec 100644
--- a/src/resources/subimage.cpp
+++ b/src/resources/subimage.cpp
@@ -60,10 +60,10 @@ SubImage::SubImage(Image *const parent,
}
// Set up the rectangle.
- mBounds.x = static_cast<int16_t>(x);
- mBounds.y = static_cast<int16_t>(y);
- mBounds.w = static_cast<uint16_t>(width);
- mBounds.h = static_cast<uint16_t>(height);
+ mBounds.x = CAST_S16(x);
+ mBounds.y = CAST_S16(y);
+ mBounds.w = CAST_U16(width);
+ mBounds.h = CAST_U16(height);
if (mParent)
{
mInternalBounds.x = mParent->mBounds.x;
@@ -114,10 +114,10 @@ SubImage::SubImage(Image *const parent,
}
// Set up the rectangle.
- mBounds.x = static_cast<int16_t>(x);
- mBounds.y = static_cast<int16_t>(y);
- mBounds.w = static_cast<uint16_t>(width);
- mBounds.h = static_cast<uint16_t>(height);
+ mBounds.x = CAST_S16(x);
+ mBounds.y = CAST_S16(y);
+ mBounds.w = CAST_U16(width);
+ mBounds.h = CAST_U16(height);
if (mParent)
{
mInternalBounds.x = mParent->mBounds.x;
@@ -149,10 +149,10 @@ SubImage::SubImage(Image *const parent,
mParent->incRef();
// Set up the rectangle.
- mBounds.x = static_cast<int16_t>(x);
- mBounds.y = static_cast<int16_t>(y);
- mBounds.w = static_cast<uint16_t>(width);
- mBounds.h = static_cast<uint16_t>(height);
+ mBounds.x = CAST_S16(x);
+ mBounds.y = CAST_S16(y);
+ mBounds.w = CAST_U16(width);
+ mBounds.h = CAST_U16(height);
if (mParent)
{
mInternalBounds.x = mParent->mBounds.x;
diff --git a/src/resources/wallpaper.cpp b/src/resources/wallpaper.cpp
index f6cb32e1b..e7a1b8253 100644
--- a/src/resources/wallpaper.cpp
+++ b/src/resources/wallpaper.cpp
@@ -141,8 +141,8 @@ std::string Wallpaper::getWallpaper(const int width, const int height)
{
// Return randomly a wallpaper between vector[0] and
// vector[vector.size() - 1]
- srand(static_cast<unsigned>(time(nullptr)));
- return wallPaperVector[static_cast<int>(static_cast<double>(
+ srand(CAST_U32(time(nullptr)));
+ return wallPaperVector[CAST_S32(static_cast<double>(
wallPaperVector.size()) * rand() / (RAND_MAX + 1.0))];
}
diff --git a/src/spellmanager.cpp b/src/spellmanager.cpp
index d9b8e757e..07ee344f7 100644
--- a/src/spellmanager.cpp
+++ b/src/spellmanager.cpp
@@ -59,7 +59,7 @@ SpellManager::~SpellManager()
TextCommand* SpellManager::getSpell(const int spellId) const
{
- if (spellId < 0 || static_cast<size_t>(spellId) >= mSpells.size())
+ if (spellId < 0 || CAST_SIZE(spellId) >= mSpells.size())
return nullptr;
const std::map<unsigned int, TextCommand*>::const_iterator
@@ -97,7 +97,7 @@ bool SpellManager::addSpell(TextCommand *const spell)
return false;
const int id = spell->getId();
- if (id < 0 || id >= static_cast<int>(SPELL_SHORTCUT_ITEMS
+ if (id < 0 || id >= CAST_S32(SPELL_SHORTCUT_ITEMS
* SPELL_SHORTCUT_TABS))
{
delete spell;
@@ -139,12 +139,12 @@ void SpellManager::invoke(const int spellId) const
#ifdef TMWA_SUPPORT
if (spell->getCommandType() == TextCommandType::Text ||
(playerHandler->canUseMagic() &&
- PlayerInfo::getSkillLevel(static_cast<int>(MagicSchool::SkillMagic))
- >= static_cast<signed>(spell->getBaseLvl()) &&
- PlayerInfo::getSkillLevel(static_cast<int>(
- spell->getSchool())) >= static_cast<signed>(spell->getSchoolLvl())
+ PlayerInfo::getSkillLevel(CAST_S32(MagicSchool::SkillMagic))
+ >= CAST_S32(spell->getBaseLvl()) &&
+ PlayerInfo::getSkillLevel(CAST_S32(
+ spell->getSchool())) >= CAST_S32(spell->getSchoolLvl())
&& PlayerInfo::getAttribute(Attributes::MP)
- >= static_cast<int>(spell->getMana()))
+ >= CAST_S32(spell->getMana()))
)
#endif
{
@@ -246,7 +246,7 @@ std::string SpellManager::parseCommand(std::string command,
TextCommand *SpellManager::createNewSpell() const
{
- return new TextCommand(static_cast<unsigned>(mSpellsVector.size()));
+ return new TextCommand(CAST_U32(mSpellsVector.size()));
}
void SpellManager::load(const bool oldConfig)
@@ -336,16 +336,16 @@ void SpellManager::save() const
#ifdef TMWA_SUPPORT
serverConfig.setValue("commandShortcutFlags" + toString(i),
strprintf("%u %u %u %u %u %u",
- static_cast<unsigned>(spell->getCommandType()),
- static_cast<unsigned>(spell->getTargetType()),
+ CAST_U32(spell->getCommandType()),
+ CAST_U32(spell->getTargetType()),
spell->getBaseLvl(),
- static_cast<unsigned>(spell->getSchool()),
+ CAST_U32(spell->getSchool()),
spell->getSchoolLvl(),
- static_cast<unsigned>(spell->getMana())));
+ CAST_U32(spell->getMana())));
#else
serverConfig.setValue("commandShortcutFlags" + toString(i),
strprintf("%u %u %u %u %u %u", 1U,
- static_cast<unsigned>(spell->getTargetType()),
+ CAST_U32(spell->getTargetType()),
0U,
0U,
0U,
diff --git a/src/test/testlauncher.cpp b/src/test/testlauncher.cpp
index edab9e750..53e6108e9 100644
--- a/src/test/testlauncher.cpp
+++ b/src/test/testlauncher.cpp
@@ -678,7 +678,7 @@ int TestLauncher::calcFps(const timeval &start,
if (mtime == 0)
return 100000;
- return static_cast<int>(static_cast<long>(calls) * 10000 / mtime);
+ return CAST_S32(static_cast<long>(calls) * 10000 / mtime);
}
#endif
diff --git a/src/test/testmain.cpp b/src/test/testmain.cpp
index 5613285ab..81621fb06 100644
--- a/src/test/testmain.cpp
+++ b/src/test/testmain.cpp
@@ -234,22 +234,22 @@ int TestMain::exec(const bool testAudio)
if (!invokeNormalOpenBatchTest("14"))
{
- textureSize[static_cast<size_t>(RENDER_NORMAL_OPENGL)]
+ textureSize[CAST_SIZE(RENDER_NORMAL_OPENGL)]
= readValue2(14);
}
if (!invokeModernOpenBatchTest("15"))
{
- textureSize[static_cast<size_t>(RENDER_MODERN_OPENGL)]
+ textureSize[CAST_SIZE(RENDER_MODERN_OPENGL)]
= readValue2(15);
}
if (!invokeSafeOpenBatchTest("16"))
{
- textureSize[static_cast<size_t>(RENDER_SAFE_OPENGL)]
+ textureSize[CAST_SIZE(RENDER_SAFE_OPENGL)]
= readValue2(16);
}
if (!invokeMobileOpenBatchTest("20"))
{
- textureSize[static_cast<size_t>(RENDER_GLES_OPENGL)]
+ textureSize[CAST_SIZE(RENDER_GLES_OPENGL)]
= readValue2(20);
}
for (int f = 0; f < 6; f ++)
@@ -264,7 +264,7 @@ int TestMain::exec(const bool testAudio)
if (!(detectMode & 15))
openGLMode = RENDER_SOFTWARE;
- writeConfig(openGLMode, rescaleTest[static_cast<size_t>(openGLMode)],
+ writeConfig(openGLMode, rescaleTest[CAST_SIZE(openGLMode)],
soundTest, info, batchSize, textureSizeStr, detectMode);
return 0;
}
@@ -279,10 +279,10 @@ void TestMain::writeConfig(const RenderType openGLMode,
{
mConfig.init(settings.configDir + "/config.xml");
- log->log("set mode to %d", static_cast<int>(openGLMode));
+ log->log("set mode to %d", CAST_S32(openGLMode));
// searched values
- mConfig.setValue("opengl", static_cast<int>(openGLMode));
+ mConfig.setValue("opengl", CAST_S32(openGLMode));
mConfig.setValue("showBackground", !rescale);
mConfig.setValue("sound", !sound);
@@ -341,7 +341,7 @@ int TestMain::readValue(const int ver, int def)
int TestMain::invokeTest(const std::string &test)
{
- mConfig.setValue("opengl", static_cast<int>(RENDER_SOFTWARE));
+ mConfig.setValue("opengl", CAST_S32(RENDER_SOFTWARE));
mConfig.write();
const int ret = execFileWait(fileName, fileName, "-t", test);
@@ -359,7 +359,7 @@ int TestMain::invokeTest4()
int TestMain::invokeSoftwareRenderTest(const std::string &test)
{
- mConfig.setValue("opengl", static_cast<int>(RENDER_SOFTWARE));
+ mConfig.setValue("opengl", CAST_S32(RENDER_SOFTWARE));
mConfig.write();
const int ret = execFileWait(fileName, fileName, "-t", test, 30);
log->log("%s: %d", test.c_str(), ret);
@@ -368,7 +368,7 @@ int TestMain::invokeSoftwareRenderTest(const std::string &test)
int TestMain::invokeNormalOpenGLRenderTest(const std::string &test)
{
- mConfig.setValue("opengl", static_cast<int>(RENDER_NORMAL_OPENGL));
+ mConfig.setValue("opengl", CAST_S32(RENDER_NORMAL_OPENGL));
mConfig.write();
const int ret = execFileWait(fileName, fileName, "-t", test, 30);
log->log("%s: %d", test.c_str(), ret);
@@ -377,7 +377,7 @@ int TestMain::invokeNormalOpenGLRenderTest(const std::string &test)
int TestMain::invokeModernOpenGLRenderTest(const std::string &test)
{
- mConfig.setValue("opengl", static_cast<int>(RENDER_MODERN_OPENGL));
+ mConfig.setValue("opengl", CAST_S32(RENDER_MODERN_OPENGL));
mConfig.write();
const int ret = execFileWait(fileName, fileName, "-t", test, 30);
log->log("%s: %d", test.c_str(), ret);
@@ -386,7 +386,7 @@ int TestMain::invokeModernOpenGLRenderTest(const std::string &test)
int TestMain::invokeNormalOpenBatchTest(const std::string &test)
{
- mConfig.setValue("opengl", static_cast<int>(RENDER_NORMAL_OPENGL));
+ mConfig.setValue("opengl", CAST_S32(RENDER_NORMAL_OPENGL));
mConfig.write();
const int ret = execFileWait(fileName, fileName, "-t", test, 30);
// log->log("%s: %d", test.c_str(), ret);
@@ -395,7 +395,7 @@ int TestMain::invokeNormalOpenBatchTest(const std::string &test)
int TestMain::invokeModernOpenBatchTest(const std::string &test)
{
- mConfig.setValue("opengl", static_cast<int>(RENDER_MODERN_OPENGL));
+ mConfig.setValue("opengl", CAST_S32(RENDER_MODERN_OPENGL));
mConfig.write();
const int ret = execFileWait(fileName, fileName, "-t", test, 30);
// log->log("%s: %d", test.c_str(), ret);
@@ -404,7 +404,7 @@ int TestMain::invokeModernOpenBatchTest(const std::string &test)
int TestMain::invokeMobileOpenBatchTest(const std::string &test)
{
- mConfig.setValue("opengl", static_cast<int>(RENDER_GLES_OPENGL));
+ mConfig.setValue("opengl", CAST_S32(RENDER_GLES_OPENGL));
mConfig.write();
const int ret = execFileWait(fileName, fileName, "-t", test, 30);
// log->log("%s: %d", test.c_str(), ret);
@@ -413,7 +413,7 @@ int TestMain::invokeMobileOpenBatchTest(const std::string &test)
int TestMain::invokeSafeOpenBatchTest(const std::string &test)
{
- mConfig.setValue("opengl", static_cast<int>(RENDER_SAFE_OPENGL));
+ mConfig.setValue("opengl", CAST_S32(RENDER_SAFE_OPENGL));
mConfig.write();
const int ret = execFileWait(fileName, fileName, "-t", test, 30);
// log->log("%s: %d", test.c_str(), ret);
@@ -422,7 +422,7 @@ int TestMain::invokeSafeOpenBatchTest(const std::string &test)
int TestMain::invokeSafeOpenGLRenderTest(const std::string &test)
{
- mConfig.setValue("opengl", static_cast<int>(RENDER_SAFE_OPENGL));
+ mConfig.setValue("opengl", CAST_S32(RENDER_SAFE_OPENGL));
mConfig.write();
const int ret = execFileWait(fileName, fileName, "-t", test, 30);
log->log("%s: %d", test.c_str(), ret);
diff --git a/src/units.cpp b/src/units.cpp
index 6d7e2a49c..6fa0a963a 100644
--- a/src/units.cpp
+++ b/src/units.cpp
@@ -203,7 +203,7 @@ static std::string formatUnit(const int value, const int type)
else
{
double amount = ud.conversion * value;
- const unsigned int sz = static_cast<unsigned int>(ud.levels.size());
+ const unsigned int sz = CAST_U32(ud.levels.size());
// If only the first level is needed, act like mix if false
if (ud.mix && !ud.levels.empty() && ud.levels[1].count < amount)
@@ -211,7 +211,7 @@ static std::string formatUnit(const int value, const int type)
std::string output;
UnitLevel pl = ud.levels[0];
ul = ud.levels[1];
- int levelAmount = static_cast<int>(amount);
+ int levelAmount = CAST_S32(amount);
int nextAmount = 0;
if (ul.count)
diff --git a/src/utils/base64.cpp b/src/utils/base64.cpp
index 7be63c090..ddf117ec4 100644
--- a/src/utils/base64.cpp
+++ b/src/utils/base64.cpp
@@ -50,7 +50,7 @@ unsigned char *php3_base64_encode(const unsigned char *restrict const string,
const unsigned char *current = string;
int i = 0;
unsigned char *const result = static_cast<unsigned char *>(
- calloc(static_cast<size_t>((length + 3 - length % 3) * 4 / 3 + 1)
+ calloc(CAST_SIZE((length + 3 - length % 3) * 4 / 3 + 1)
* sizeof(unsigned char), 1));
if (!result)
return nullptr;
@@ -126,23 +126,23 @@ unsigned char *php3_base64_decode(const unsigned char *restrict const string,
const char *const chp = strchr(base64_table, ch);
if (!chp)
continue;
- ch = static_cast<int>(chp - base64_table);
+ ch = CAST_S32(chp - base64_table);
switch (i % 4)
{
case 0:
- result[j] = static_cast<unsigned char>(ch << 2U);
+ result[j] = CAST_U8(ch << 2U);
break;
case 1:
- result[j++] |= static_cast<unsigned char>(ch >> 4U);
- result[j] = static_cast<unsigned char>((ch & 0x0f) << 4U);
+ result[j++] |= CAST_U8(ch >> 4U);
+ result[j] = CAST_U8((ch & 0x0f) << 4U);
break;
case 2:
- result[j++] |= static_cast<unsigned char>(ch >>2U);
- result[j] = static_cast<unsigned char>((ch & 0x03) << 6U);
+ result[j++] |= CAST_U8(ch >>2U);
+ result[j] = CAST_U8((ch & 0x03) << 6U);
break;
case 3:
- result[j++] |= static_cast<unsigned char>(ch);
+ result[j++] |= CAST_U8(ch);
break;
default:
break;
@@ -183,7 +183,7 @@ std::string encodeBase64String(std::string value)
const unsigned char *const str = reinterpret_cast<unsigned char*>(
const_cast<char*>(value.c_str()));
unsigned char *const buf = php3_base64_encode(
- str, static_cast<int>(value.size()), &sz);
+ str, CAST_S32(value.size()), &sz);
if (!buf)
return std::string();
@@ -198,7 +198,7 @@ std::string decodeBase64String(std::string value)
const unsigned char *const str = reinterpret_cast<unsigned char*>(
const_cast<char*>(value.c_str()));
unsigned char *const buf = php3_base64_decode(
- str, static_cast<int>(value.size()), &sz);
+ str, CAST_S32(value.size()), &sz);
if (buf)
value = std::string(reinterpret_cast<char*>(buf), sz);
diff --git a/src/utils/copynpaste.cpp b/src/utils/copynpaste.cpp
index 1bec05699..8a413c1f7 100644
--- a/src/utils/copynpaste.cpp
+++ b/src/utils/copynpaste.cpp
@@ -128,7 +128,7 @@ bool sendBuffer(std::string& text)
return false;
HANDLE h = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE,
- static_cast<size_t>(wCharsLen) * sizeof(WCHAR));
+ CAST_SIZE(wCharsLen) * sizeof(WCHAR));
WCHAR *const out = static_cast<WCHAR*>(GlobalLock(h));
MultiByteToWideChar(CP_UTF8, 0, text.c_str(), -1, out, wCharsLen);
@@ -460,7 +460,7 @@ static bool runxsel(std::string& text, const char *p1, const char *p2)
// parent
close(fd[0]);
- const int len = static_cast<int>(strlen(text.c_str()));
+ const int len = CAST_S32(strlen(text.c_str()));
if (write(fd[1], text.c_str(), len) != len)
{
close(fd[1]);
diff --git a/src/utils/mathutils.h b/src/utils/mathutils.h
index c5b6a515d..4bc3cf104 100644
--- a/src/utils/mathutils.h
+++ b/src/utils/mathutils.h
@@ -185,7 +185,7 @@ inline uint16_t getCrc16(const std::string &str)
while (f != 0)
{
f --;
- crc16 = static_cast<uint16_t>(
+ crc16 = CAST_U16(
crc_table[(crc16 ^ (str[f])) & 0xff] ^ (crc16 >> 8));
}
@@ -225,7 +225,7 @@ constexpr inline float weightedAverage(const float n1, const float n2,
constexpr inline int roundDouble(const double v)
{
- return (v > 0.0) ? static_cast<int>(v + 0.5) : static_cast<int>(v - 0.5);
+ return (v > 0.0) ? CAST_S32(v + 0.5) : CAST_S32(v - 0.5);
}
constexpr2 inline int powerOfTwo(const unsigned int input)
@@ -239,8 +239,8 @@ constexpr2 inline int powerOfTwo(const unsigned int input)
constexpr2 inline int fastSqrtInt(const unsigned int n)
{
if (n < 1000)
- return static_cast<int>(square_roots[n]);
- return static_cast<int>(sqrt(n));
+ return CAST_S32(square_roots[n]);
+ return CAST_S32(sqrt(n));
}
#endif // UTILS_MATHUTILS_H
diff --git a/src/utils/mathutils_unittest.cc b/src/utils/mathutils_unittest.cc
index 0b5ece474..7f0cc957c 100644
--- a/src/utils/mathutils_unittest.cc
+++ b/src/utils/mathutils_unittest.cc
@@ -98,5 +98,5 @@ TEST_CASE("MathUtils powerOfTwo")
TEST_CASE("MathUtils tests fastSqrtInt")
{
for (int f = 0; f < 1005; f ++)
- REQUIRE(fastSqrtInt(f) == static_cast<int>(sqrt(f)));
+ REQUIRE(fastSqrtInt(f) == CAST_S32(sqrt(f)));
}
diff --git a/src/utils/mkdir.cpp b/src/utils/mkdir.cpp
index 0ecd7fc31..f7a2aba37 100644
--- a/src/utils/mkdir.cpp
+++ b/src/utils/mkdir.cpp
@@ -52,7 +52,7 @@ int mkdir_r(const char *const pathname)
strncpy(tmp, pathname, sizeof(tmp) - 1);
tmp[PATH_MAX - 1] = '\0';
- const int len = static_cast<int>(strlen(tmp));
+ const int len = CAST_S32(strlen(tmp));
if (len < 1)
return -1;
@@ -117,7 +117,7 @@ int mkdir_r(const char *const pathname)
if (!pathname)
return -1;
- const size_t len = static_cast<size_t>(strlen(pathname));
+ const size_t len = CAST_SIZE(strlen(pathname));
char *tmp = new char[len + 2];
char *p = nullptr;
diff --git a/src/utils/physfsrwops.cpp b/src/utils/physfsrwops.cpp
index 3599f7f31..e5e7e8e98 100644
--- a/src/utils/physfsrwops.cpp
+++ b/src/utils/physfsrwops.cpp
@@ -66,7 +66,7 @@ static PHYSFSINT physfsrwops_seek(SDL_RWops *const rw, const PHYSFSINT offset,
return -1;
} /* if */
- pos = static_cast<int>(current);
+ pos = CAST_S32(current);
if (static_cast<PHYSFS_sint64>(pos) != current)
{
SDL_SetError("Can't fit current file position in an int!");
@@ -127,15 +127,15 @@ static PHYSFSSIZE physfsrwops_read(SDL_RWops *const rw,
PHYSFS_file *const handle = static_cast<PHYSFS_file *const>(
rw->hidden.unknown.data1);
const PHYSFS_sint64 rc = PHYSFS_read(handle, ptr,
- static_cast<unsigned int>(size),
- static_cast<unsigned int>(maxnum));
+ CAST_U32(size),
+ CAST_U32(maxnum));
if (rc != static_cast<PHYSFS_sint64>(maxnum))
{
if (!PHYSFS_eof(handle)) /* not EOF? Must be an error. */
SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError());
} /* if */
- return static_cast<int>(rc);
+ return CAST_S32(rc);
} /* physfsrwops_read */
static PHYSFSSIZE physfsrwops_write(SDL_RWops *const rw, const void *ptr,
@@ -147,12 +147,12 @@ static PHYSFSSIZE physfsrwops_write(SDL_RWops *const rw, const void *ptr,
PHYSFS_file *const handle = static_cast<PHYSFS_file *const>(
rw->hidden.unknown.data1);
const PHYSFS_sint64 rc = PHYSFS_write(handle, ptr,
- static_cast<unsigned int>(size),
- static_cast<unsigned int>(num));
+ CAST_U32(size),
+ CAST_U32(num));
if (rc != static_cast<PHYSFS_sint64>(num))
SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError());
- return static_cast<int>(rc);
+ return CAST_S32(rc);
} /* physfsrwops_write */
static int physfsrwops_close(SDL_RWops *const rw)
diff --git a/src/utils/physfstools.cpp b/src/utils/physfstools.cpp
index 6e2332709..8ee72f7b9 100644
--- a/src/utils/physfstools.cpp
+++ b/src/utils/physfstools.cpp
@@ -152,7 +152,7 @@ namespace PhysFs
logger->log("Loaded %s/%s", PhysFs::getRealDir(fileName.c_str()),
fileName.c_str());
- fileSize = static_cast<int>(PHYSFS_fileLength(file));
+ fileSize = CAST_S32(PHYSFS_fileLength(file));
// Allocate memory and load the file
void *const buffer = calloc(fileSize, 1);
PHYSFS_read(file, buffer, 1, fileSize);
diff --git a/src/utils/sdlhelper.cpp b/src/utils/sdlhelper.cpp
index 73157f15c..bc5e75a56 100644
--- a/src/utils/sdlhelper.cpp
+++ b/src/utils/sdlhelper.cpp
@@ -44,8 +44,8 @@ bool SDL::getAllVideoModes(StringVect &modeList)
#ifdef ANDROID
const std::string modeString =
- toString(static_cast<int>(modes[0]->w)).append("x")
- .append(toString(static_cast<int>(modes[0]->h)));
+ toString(CAST_S32(modes[0]->w)).append("x")
+ .append(toString(CAST_S32(modes[0]->h)));
logger->log("support mode: " + modeString);
modeList.push_back(modeString);
return true;
@@ -66,8 +66,8 @@ bool SDL::getAllVideoModes(StringVect &modeList)
for (int i = 0; modes[i]; ++ i)
{
const std::string modeString =
- toString(static_cast<int>(modes[i]->w)).append("x")
- .append(toString(static_cast<int>(modes[i]->h)));
+ toString(CAST_S32(modes[i]->w)).append("x")
+ .append(toString(CAST_S32(modes[i]->h)));
logger->log("support mode: " + modeString);
modeList.push_back(modeString);
}
diff --git a/src/utils/sdlpixel.h b/src/utils/sdlpixel.h
index bc7236334..66f4c2862 100644
--- a/src/utils/sdlpixel.h
+++ b/src/utils/sdlpixel.h
@@ -86,31 +86,31 @@ inline void SDLputPixel(SDL_Surface* surface, int x, int y,
SDL_LockSurface(surface);
Uint8 *const p = static_cast<uint8_t*>(surface->pixels)
- + static_cast<size_t>(y * surface->pitch + x * bpp);
+ + CAST_SIZE(y * surface->pitch + x * bpp);
const Uint32 pixel = SDL_MapRGB(surface->format,
- static_cast<uint8_t>(color.r), static_cast<uint8_t>(color.g),
- static_cast<uint8_t>(color.b));
+ CAST_U8(color.r), CAST_U8(color.g),
+ CAST_U8(color.b));
switch (bpp)
{
case 1:
- *p = static_cast<uint8_t>(pixel);
+ *p = CAST_U8(pixel);
break;
case 2:
- *reinterpret_cast<uint16_t*>(p) = static_cast<uint16_t>(pixel);
+ *reinterpret_cast<uint16_t*>(p) = CAST_U16(pixel);
break;
case 3:
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
- p[0] = static_cast<uint8_t>((pixel >> 16) & 0xff);
- p[1] = static_cast<uint8_t>((pixel >> 8) & 0xff);
- p[2] = static_cast<uint8_t>((pixel) & 0xff);
+ p[0] = CAST_U8((pixel >> 16) & 0xff);
+ p[1] = CAST_U8((pixel >> 8) & 0xff);
+ p[2] = CAST_U8((pixel) & 0xff);
#else
- p[0] = static_cast<uint8_t>((pixel) & 0xff);
- p[1] = static_cast<uint8_t>((pixel >> 8) & 0xff);
- p[2] = static_cast<uint8_t>((pixel >> 16) & 0xff);
+ p[0] = CAST_U8((pixel) & 0xff);
+ p[1] = CAST_U8((pixel >> 8) & 0xff);
+ p[2] = CAST_U8((pixel >> 16) & 0xff);
#endif
break;
@@ -190,40 +190,40 @@ inline void SDLputPixelAlpha(SDL_Surface* surface, int x, int y,
SDL_LockSurface(surface);
Uint8 *const p = static_cast<uint8_t*>(surface->pixels)
- + static_cast<size_t>(y * surface->pitch + x * bpp);
+ + CAST_SIZE(y * surface->pitch + x * bpp);
const Uint32 pixel = SDL_MapRGB(surface->format,
- static_cast<uint8_t>(color.r),
- static_cast<uint8_t>(color.g),
- static_cast<uint8_t>(color.b));
+ CAST_U8(color.r),
+ CAST_U8(color.g),
+ CAST_U8(color.b));
switch (bpp)
{
case 1:
- *p = static_cast<uint8_t>(pixel);
+ *p = CAST_U8(pixel);
break;
case 2:
*reinterpret_cast<Uint16*>(p) = SDLAlpha16(
static_cast<unsigned short>(pixel),
*reinterpret_cast<unsigned short*>(p),
- static_cast<unsigned char>(color.a), surface->format);
+ CAST_U8(color.a), surface->format);
break;
case 3:
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
- p[2] = static_cast<uint8_t>((p[2] * (255 - color.a)
+ p[2] = CAST_U8((p[2] * (255 - color.a)
+ color.b * color.a) >> 8);
- p[1] = static_cast<uint8_t>((p[1] * (255 - color.a)
+ p[1] = CAST_U8((p[1] * (255 - color.a)
+ color.g * color.a) >> 8);
- p[0] = static_cast<uint8_t>((p[0] * (255 - color.a)
+ p[0] = CAST_U8((p[0] * (255 - color.a)
+ color.r * color.a) >> 8);
#else
- p[0] = static_cast<uint8_t>((p[0] * (255 - color.a)
+ p[0] = CAST_U8((p[0] * (255 - color.a)
+ color.b * color.a) >> 8);
- p[1] = static_cast<uint8_t>((p[1] * (255 - color.a)
+ p[1] = CAST_U8((p[1] * (255 - color.a)
+ color.g * color.a) >> 8);
- p[2] = static_cast<uint8_t>((p[2] * (255 - color.a)
+ p[2] = CAST_U8((p[2] * (255 - color.a)
+ color.r * color.a) >> 8);
#endif
break;
@@ -231,7 +231,7 @@ inline void SDLputPixelAlpha(SDL_Surface* surface, int x, int y,
case 4:
*reinterpret_cast<Uint32*>(p) = SDLAlpha32(pixel,
*reinterpret_cast<Uint32*>(p),
- static_cast<unsigned char>(color.a));
+ CAST_U8(color.a));
break;
default:
break;
diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp
index ebaee1b4b..ba6e46ee0 100644
--- a/src/utils/stringutils.cpp
+++ b/src/utils/stringutils.cpp
@@ -85,10 +85,10 @@ const char *ipToString(const uint32_t address)
static char asciiIP[18];
snprintf(asciiIP, sizeof(asciiIP), "%i.%i.%i.%i",
- static_cast<unsigned char>(address),
- static_cast<unsigned char>(address >> 8),
- static_cast<unsigned char>(address >> 16),
- static_cast<unsigned char>(address >> 24));
+ CAST_U8(address),
+ CAST_U8(address >> 8),
+ CAST_U8(address >> 16),
+ CAST_U8(address >> 24));
asciiIP[17] = 0;
return asciiIP;
@@ -162,7 +162,7 @@ const std::string findSameSubstring(const std::string &restrict str1,
const std::string &restrict str2)
{
const int minLength = str1.length() > str2.length()
- ? static_cast<int>(str2.length()) : static_cast<int>(str1.length());
+ ? CAST_S32(str2.length()) : CAST_S32(str1.length());
for (int f = 0; f < minLength; f ++)
{
if (str1.at(f) != str2.at(f))
@@ -222,13 +222,13 @@ const std::string encodeStr(unsigned int value, const unsigned int size)
do
{
- buf += static_cast<signed char>(value % base + start);
+ buf += CAST_S8(value % base + start);
value /= base;
}
while (value);
while (buf.length() < size)
- buf += static_cast<signed char>(start);
+ buf += CAST_S8(start);
return buf;
}
@@ -261,9 +261,9 @@ std::string extractNameFromSprite(std::string str)
pos2 = pos3;
}
if (pos2 == std::string::npos)
- pos2 = static_cast<size_t>(-1);
+ pos2 = CAST_SIZE(-1);
- const int size = static_cast<int>(pos1) - static_cast<int>(pos2) - 1;
+ const int size = CAST_S32(pos1) - CAST_S32(pos2) - 1;
if (size > 0)
str = str.substr(pos2 + 1, size);
}
@@ -284,9 +284,9 @@ std::string removeSpriteIndex(std::string str)
pos2 = pos3;
}
if (pos2 == std::string::npos)
- pos2 = static_cast<size_t>(-1);
+ pos2 = CAST_SIZE(-1);
- const int size = static_cast<int>(pos1) - static_cast<int>(pos2) - 1;
+ const int size = CAST_S32(pos1) - CAST_S32(pos2) - 1;
if (size > 0)
str = str.substr(pos2 + 1, size);
}
@@ -400,7 +400,7 @@ void replaceSpecialChars(std::string &text)
if (idx + 1 < f && text[f] == ';')
{
std::string str(" ");
- str[0] = static_cast<signed char>(atoi(text.substr(
+ str[0] = CAST_S8(atoi(text.substr(
idx, f - idx).c_str()));
text = text.substr(0, pos1) + str + text.substr(f + 1);
pos1 += 1;
@@ -585,11 +585,11 @@ std::string stringToHexPath(const std::string &str)
if (str.empty())
return "";
- std::string hex = strprintf("%%%2x/", static_cast<unsigned int>(str[0]));
- for (unsigned f = 1, sz = static_cast<unsigned int>(str.size());
+ std::string hex = strprintf("%%%2x/", CAST_U32(str[0]));
+ for (unsigned f = 1, sz = CAST_U32(str.size());
f < sz; f ++)
{
- hex.append(strprintf("%%%2x", static_cast<unsigned int>(str[f])));
+ hex.append(strprintf("%%%2x", CAST_U32(str[f])));
}
return hex;
}
@@ -760,7 +760,7 @@ std::string toString(unsigned int num)
buf[29] = '\0';
size_t idx = 28;
do
- buf[idx--] = static_cast<char>((num % 10) + '0');
+ buf[idx--] = CAST_8((num % 10) + '0');
while (num /= 10);
return buf + idx + 1;
}
@@ -771,7 +771,7 @@ std::string toString(unsigned long num)
buf[99] = '\0';
size_t idx = 98;
do
- buf[idx--] = static_cast<char>((num % 10) + '0');
+ buf[idx--] = CAST_8((num % 10) + '0');
while (num /= 10);
return buf + idx + 1;
}
@@ -782,7 +782,7 @@ std::string toString(uint16_t num)
buf[9] = '\0';
size_t idx = 8;
do
- buf[idx--] = static_cast<char>((num % 10) + '0');
+ buf[idx--] = CAST_8((num % 10) + '0');
while (num /= 10);
return buf + idx + 1;
}
@@ -793,7 +793,7 @@ std::string toString(unsigned char num)
buf[4] = '\0';
size_t idx = 3;
do
- buf[idx--] = static_cast<char>((num % 10) + '0');
+ buf[idx--] = CAST_8((num % 10) + '0');
while (num /= 10);
return buf + idx + 1;
}
@@ -811,7 +811,7 @@ std::string toString(int num)
num = -num;
}
do
- buf[idx--] = static_cast<char>((num % 10) + '0');
+ buf[idx--] = CAST_8((num % 10) + '0');
while (num /= 10);
if (useSign)
buf[idx--] = '-';
diff --git a/src/utils/stringutils_unittest.cc b/src/utils/stringutils_unittest.cc
index 09120c844..f6586558c 100644
--- a/src/utils/stringutils_unittest.cc
+++ b/src/utils/stringutils_unittest.cc
@@ -127,8 +127,8 @@ TEST_CASE("stringuntils toString 1")
REQUIRE(strprintf("%d", -10000000) == toString(-10000000));
REQUIRE(strprintf("%d", 30000000) == toString(
static_cast<signed int>(30000000)));
- REQUIRE(strprintf("%d", 3000) == toString(static_cast<uint16_t>(3000)));
- REQUIRE(strprintf("%d", 123) == toString(static_cast<unsigned char>(123)));
+ REQUIRE(strprintf("%d", 3000) == toString(CAST_U16(3000)));
+ REQUIRE(strprintf("%d", 123) == toString(CAST_U8(123)));
}
TEST_CASE("stringuntils toString 2")
diff --git a/src/utils/xml/libxml.cpp b/src/utils/xml/libxml.cpp
index 29bd83b4b..46d184067 100644
--- a/src/utils/xml/libxml.cpp
+++ b/src/utils/xml/libxml.cpp
@@ -108,7 +108,7 @@ namespace XML
{
// Get length of file
file.seekg(0, std::ios::end);
- size = static_cast<int>(file.tellg());
+ size = CAST_S32(file.tellg());
if (size < 0)
{
logger->log("Error loading XML file %s", filename.c_str());
diff --git a/src/utils/xml/pugixml.cpp b/src/utils/xml/pugixml.cpp
index 9ca717d83..0f01c7f10 100644
--- a/src/utils/xml/pugixml.cpp
+++ b/src/utils/xml/pugixml.cpp
@@ -84,7 +84,7 @@ namespace XML
{
// Get length of file
file.seekg(0, std::ios::end);
- size = static_cast<int>(file.tellg());
+ size = CAST_S32(file.tellg());
if (size < 0)
{
logger->log("Error loading XML file %s", filename.c_str());