mirror of
https://github.com/vcmi/vcmi.git
synced 2025-01-02 00:10:22 +02:00
Converted attributes to use c++17 functionality
This commit is contained in:
parent
2150eabfc5
commit
63b197b78a
@ -136,7 +136,7 @@ ui64 FuzzyHelper::evaluateDanger(const CGObjectInstance * obj)
|
||||
{
|
||||
if(!vstd::contains(ai->memory->alreadyVisited, obj))
|
||||
return 0;
|
||||
FALLTHROUGH;
|
||||
[[fallthrough]];
|
||||
}
|
||||
case Obj::MONSTER:
|
||||
case Obj::HERO:
|
||||
|
20
Global.h
20
Global.h
@ -71,22 +71,6 @@ static_assert(sizeof(bool) == 1, "Bool needs to be 1 byte in size.");
|
||||
#define VCMI_MOBILE
|
||||
#endif
|
||||
|
||||
// Each compiler uses own way to supress fall through warning. Try to find it.
|
||||
// TODO: replace with c++17 [[fallthrough]]
|
||||
#ifdef __has_cpp_attribute
|
||||
# if __has_cpp_attribute(fallthrough)
|
||||
# define FALLTHROUGH [[fallthrough]];
|
||||
# elif __has_cpp_attribute(gnu::fallthrough)
|
||||
# define FALLTHROUGH [[gnu::fallthrough]];
|
||||
# elif __has_cpp_attribute(clang::fallthrough)
|
||||
# define FALLTHROUGH [[clang::fallthrough]];
|
||||
# else
|
||||
# define FALLTHROUGH
|
||||
# endif
|
||||
#else
|
||||
# define FALLTHROUGH
|
||||
#endif
|
||||
|
||||
/* ---------------------------------------------------------------------------- */
|
||||
/* Commonly used C++, Boost headers */
|
||||
/* ---------------------------------------------------------------------------- */
|
||||
@ -256,10 +240,6 @@ using TLockGuardRec = std::lock_guard<std::recursive_mutex>;
|
||||
template<typename T, size_t N> char (&_ArrayCountObj(const T (&)[N]))[N];
|
||||
#define ARRAY_COUNT(arr) (sizeof(_ArrayCountObj(arr)))
|
||||
|
||||
// should be used for variables that becomes unused in release builds (e.g. only used for assert checks)
|
||||
// TODO: replace with c++17 [[maybe_unused]]
|
||||
#define MAYBE_UNUSED(VAR) ((void)VAR)
|
||||
|
||||
// old iOS SDKs compatibility
|
||||
#ifdef VCMI_IOS
|
||||
#include <AvailabilityVersions.h>
|
||||
|
@ -80,7 +80,6 @@ void CHeroSwitcher::clickLeft(tribool down, bool previousState)
|
||||
#if 0
|
||||
owner->update(hero, true);
|
||||
#else
|
||||
MAYBE_UNUSED(owner);
|
||||
const CGHeroInstance * buf = hero;
|
||||
GH.popInts(1);
|
||||
GH.pushIntT<CHeroWindow>(buf);
|
||||
|
@ -65,7 +65,7 @@ InfoBox::InfoBox(Point position, InfoPos Pos, InfoSize Size, std::shared_ptr<IIn
|
||||
break;
|
||||
case POS_UP_DOWN:
|
||||
name = std::make_shared<CLabel>(pos.w/2, -12, font, ETextAlignment::CENTER, Colors::WHITE, data->getNameText());
|
||||
FALLTHROUGH;
|
||||
[[fallthrough]];
|
||||
case POS_DOWN:
|
||||
value = std::make_shared<CLabel>(pos.w/2, pos.h+8, font, ETextAlignment::CENTER, Colors::WHITE, data->getValueText());
|
||||
break;
|
||||
|
@ -133,8 +133,7 @@ void CSettingsView::fillValidResolutionsForScreen(int screenIndex)
|
||||
|
||||
const auto screens = qGuiApp->screens();
|
||||
const auto currentScreen = screenIndex < screens.size() ? screens[screenIndex] : qGuiApp->primaryScreen();
|
||||
const auto screenSize = currentScreen->size();
|
||||
MAYBE_UNUSED(screenSize);
|
||||
[[maybe_unused]] const auto screenSize = currentScreen->size();
|
||||
|
||||
for(const auto & entry : resolutions)
|
||||
{
|
||||
|
@ -514,10 +514,9 @@ void CCreatureSet::putStack(const SlotID & slot, CStackInstance * stack)
|
||||
|
||||
void CCreatureSet::joinStack(const SlotID & slot, CStackInstance * stack)
|
||||
{
|
||||
const CCreature *c = getCreature(slot);
|
||||
[[maybe_unused]] const CCreature *c = getCreature(slot);
|
||||
assert(c == stack->type);
|
||||
assert(c);
|
||||
MAYBE_UNUSED(c);
|
||||
|
||||
//TODO move stuff
|
||||
changeStackCount(slot, stack->count);
|
||||
|
@ -1805,10 +1805,9 @@ void CGameState::initTowns()
|
||||
vti->builtBuildings.erase(BuildingID::SHIPYARD);//if we have harbor without water - erase it (this is H3 behaviour)
|
||||
|
||||
//Early check for #1444-like problems
|
||||
for(const auto & building : vti->builtBuildings)
|
||||
for([[maybe_unused]] const auto & building : vti->builtBuildings)
|
||||
{
|
||||
assert(vti->getTown()->buildings.at(building) != nullptr);
|
||||
MAYBE_UNUSED(building);
|
||||
}
|
||||
|
||||
//town events
|
||||
@ -2223,7 +2222,7 @@ void CGameState::updateRumor()
|
||||
}
|
||||
else
|
||||
rumor.type = RumorState::TYPE_RAND;
|
||||
FALLTHROUGH
|
||||
[[fallthrough]];
|
||||
|
||||
case RumorState::TYPE_RAND:
|
||||
auto vector = VLC->generaltexth->findStringsWithPrefix("core.randtvrn");
|
||||
|
@ -803,7 +803,7 @@ void DestinationActionRule::process(
|
||||
}
|
||||
|
||||
/// don't break - next case shared for both land and sail layers
|
||||
FALLTHROUGH
|
||||
[[fallthrough]];
|
||||
|
||||
case EPathfindingLayer::SAIL:
|
||||
if(destination.isNodeObjectVisitable())
|
||||
|
@ -296,7 +296,6 @@ std::vector<BattleHex> CStack::meleeAttackHexes(const battle::Unit * attacker, c
|
||||
res.push_back(otherDefenderPos);
|
||||
}
|
||||
}
|
||||
MAYBE_UNUSED(mask);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
@ -1463,9 +1463,8 @@ void NewObject::applyGs(CGameState *gs)
|
||||
testObject.pos = pos;
|
||||
testObject.appearance = VLC->objtypeh->getHandlerFor(ID, subID)->getTemplates(ETerrainId::WATER).front();
|
||||
|
||||
const int3 previousXAxisTile = int3(pos.x - 1, pos.y, pos.z);
|
||||
[[maybe_unused]] const int3 previousXAxisTile = int3(pos.x - 1, pos.y, pos.z);
|
||||
assert(gs->isInTheMap(previousXAxisTile) && (testObject.visitablePos() == previousXAxisTile));
|
||||
MAYBE_UNUSED(previousXAxisTile);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1689,10 +1688,9 @@ void RebalanceStacks::applyGs(CGameState * gs)
|
||||
|
||||
if(srcCount == count) //moving whole stack
|
||||
{
|
||||
if(const CCreature *c = dst.army->getCreature(dst.slot)) //stack at dest -> merge
|
||||
if([[maybe_unused]] const CCreature *c = dst.army->getCreature(dst.slot)) //stack at dest -> merge
|
||||
{
|
||||
assert(c == srcType);
|
||||
MAYBE_UNUSED(c);
|
||||
auto alHere = ArtifactLocation (src.getStack(), ArtifactPosition::CREATURE_SLOT);
|
||||
auto alDest = ArtifactLocation (dst.getStack(), ArtifactPosition::CREATURE_SLOT);
|
||||
auto * artHere = alHere.getArt();
|
||||
@ -1744,10 +1742,9 @@ void RebalanceStacks::applyGs(CGameState * gs)
|
||||
}
|
||||
else
|
||||
{
|
||||
if(const CCreature *c = dst.army->getCreature(dst.slot)) //stack at dest -> rebalance
|
||||
if([[maybe_unused]] const CCreature *c = dst.army->getCreature(dst.slot)) //stack at dest -> rebalance
|
||||
{
|
||||
assert(c == srcType);
|
||||
MAYBE_UNUSED(c);
|
||||
if (stackExp)
|
||||
{
|
||||
ui64 totalExp = srcCount * src.army->getStackExperience(src.slot) + dst.army->getStackCount(dst.slot) * dst.army->getStackExperience(dst.slot);
|
||||
@ -1912,14 +1909,13 @@ void BulkMoveArtifacts::applyGs(CGameState * gs)
|
||||
void AssembledArtifact::applyGs(CGameState *gs)
|
||||
{
|
||||
CArtifactSet * artSet = al.getHolderArtSet();
|
||||
const CArtifactInstance *transformedArt = al.getArt();
|
||||
[[maybe_unused]] const CArtifactInstance *transformedArt = al.getArt();
|
||||
assert(transformedArt);
|
||||
bool combineEquipped = !ArtifactUtils::isSlotBackpack(al.slot);
|
||||
assert(vstd::contains_if(transformedArt->assemblyPossibilities(artSet, combineEquipped), [=](const CArtifact * art)->bool
|
||||
{
|
||||
return art->getId() == builtArt->getId();
|
||||
}));
|
||||
MAYBE_UNUSED(transformedArt);
|
||||
|
||||
auto * combinedArt = new CCombinedArtifactInstance(builtArt);
|
||||
gs->map->addNewArtifactInstance(combinedArt);
|
||||
|
@ -38,9 +38,8 @@ public:
|
||||
std::unique_ptr<ui8[]> data(new ui8[getSize()]);
|
||||
|
||||
seek(0);
|
||||
auto readSize = read(data.get(), getSize());
|
||||
[[maybe_unused]] auto readSize = read(data.get(), getSize());
|
||||
assert(readSize == getSize());
|
||||
MAYBE_UNUSED(readSize);
|
||||
|
||||
return std::make_pair(std::move(data), getSize());
|
||||
}
|
||||
|
@ -41,9 +41,8 @@ void WaterProxy::process()
|
||||
paintZoneTerrain(zone, generator.rand, map, zone.getTerrainType());
|
||||
|
||||
//check terrain type
|
||||
for(const auto & t : zone.area().getTilesVector())
|
||||
for([[maybe_unused]] const auto & t : zone.area().getTilesVector())
|
||||
{
|
||||
MAYBE_UNUSED(t);
|
||||
assert(map.isOnMap(t));
|
||||
assert(map.map().getTile(t).terType->getId() == zone.getTerrainType());
|
||||
}
|
||||
|
@ -419,11 +419,10 @@ std::string MapSettings::getHeroName(int townObjectIdx)
|
||||
std::string MapSettings::getMonsterName(int monsterObjectIdx)
|
||||
{
|
||||
std::string name;
|
||||
if(auto monster = dynamic_cast<CGCreature*>(controller.map()->objects[monsterObjectIdx].get()))
|
||||
if([[maybe_unused]] auto monster = dynamic_cast<CGCreature*>(controller.map()->objects[monsterObjectIdx].get()))
|
||||
{
|
||||
//TODO: get proper name
|
||||
//name = hero->name;
|
||||
MAYBE_UNUSED(monster);
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
@ -4643,7 +4643,7 @@ bool CGameHandler::makeBattleAction(BattleAction &ba)
|
||||
sendAndApply(&message);
|
||||
//don't break - we share code with next case
|
||||
}
|
||||
FALLTHROUGH
|
||||
[[fallthrough]];
|
||||
case EActionType::WAIT:
|
||||
{
|
||||
auto wrapper = wrapAction(ba);
|
||||
|
Loading…
Reference in New Issue
Block a user