diff --git a/AI/VCAI/AIUtility.cpp b/AI/VCAI/AIUtility.cpp index cbe388a1f..b7f8886ff 100644 --- a/AI/VCAI/AIUtility.cpp +++ b/AI/VCAI/AIUtility.cpp @@ -124,18 +124,25 @@ const CGHeroInstance * HeroPtr::operator*() const void foreach_tile_pos(std::function foo) { - for(int i = 0; i < cb->getMapSize().x; i++) - for(int j = 0; j < cb->getMapSize().y; j++) - for(int k = 0; k < cb->getMapSize().z; k++) + // some micro-optimizations since this function gets called a LOT + // callback pointer is thread-specific and slow to retrieve -> read map size only once + int3 mapSize = cb->getMapSize(); + + for(int i = 0; i < mapSize.x; i++) + for(int j = 0; j < mapSize.y; j++) + for(int k = 0; k < mapSize.z; k++) foo(int3(i,j,k)); + } void foreach_neighbour(const int3 &pos, std::function foo) { + CCallback * cbp = cb.get(); // avoid costly retrieval of thread-specific pointer + for(const int3 &dir : dirs) { const int3 n = pos + dir; - if(cb->isInTheMap(n)) + if(cbp->isInTheMap(n)) foo(pos+dir); } } diff --git a/AI/VCAI/VCAI.cpp b/AI/VCAI/VCAI.cpp index af0e6e27e..5fa883cce 100644 --- a/AI/VCAI/VCAI.cpp +++ b/AI/VCAI/VCAI.cpp @@ -978,7 +978,6 @@ bool VCAI::tryBuildStructure(const CGTownInstance * t, BuildingID building, unsi return false; TResources currentRes = cb->getResourceAmount(); - TResources income = estimateIncome(); //TODO: calculate if we have enough resources to build it in maxDays for(const auto & buildID : toBuild) @@ -998,10 +997,12 @@ bool VCAI::tryBuildStructure(const CGTownInstance * t, BuildingID building, unsi } else if(canBuild == EBuildingState::NO_RESOURCES) { + //TResources income = estimateIncome(); TResources cost = t->town->buildings.at(buildID)->resources; for (int i = 0; i < GameConstants::RESOURCE_QUANTITY; i++) { - int diff = currentRes[i] - cost[i] + income[i]; + //int diff = currentRes[i] - cost[i] + income[i]; + int diff = currentRes[i] - cost[i]; if(diff < 0) saving[i] = 1; } @@ -1143,13 +1144,13 @@ void VCAI::buildStructure(const CGTownInstance * t) //Possible - allow "locking" on specific building (build prerequisites and then building itself) TResources currentRes = cb->getResourceAmount(); - TResources income = estimateIncome(); + int townIncome = t->dailyIncome(); if (tryBuildAnyStructure(t, std::vector(essential, essential + ARRAY_COUNT(essential)))) return; //we're running out of gold - try to build something gold-producing. Multiplier can be tweaked, 6 is minimum due to buildings costs - if (currentRes[Res::GOLD] < income[Res::GOLD] * 6) + if (currentRes[Res::GOLD] < townIncome * 6) if (tryBuildNextStructure(t, std::vector(goldSource, goldSource + ARRAY_COUNT(goldSource)))) return; diff --git a/client/battle/CBattleAnimations.cpp b/client/battle/CBattleAnimations.cpp index 9d7d5563d..0eb3a381b 100644 --- a/client/battle/CBattleAnimations.cpp +++ b/client/battle/CBattleAnimations.cpp @@ -310,7 +310,7 @@ bool CMeleeAttackAnimation::init() return false; } - bool toReverse = owner->getCurrentPlayerInterface()->cb->isToReverse(attackingStackPosBeforeReturn, dest, owner->creDir[stack->ID], attackedStack->doubleWide(), owner->creDir[attackedStack->ID]); + bool toReverse = owner->getCurrentPlayerInterface()->cb->isToReverse(attackingStackPosBeforeReturn, attackedStack->position, owner->creDir[stack->ID], attackedStack->doubleWide(), owner->creDir[attackedStack->ID]); if (toReverse) { diff --git a/launcher/CMakeLists.txt b/launcher/CMakeLists.txt index 0fe324636..ea628cfdf 100644 --- a/launcher/CMakeLists.txt +++ b/launcher/CMakeLists.txt @@ -56,8 +56,9 @@ add_executable(vcmilauncher ${launcher_SRCS} ${launcher_UI_HEADERS}) # The Qt5Widgets_LIBRARIES variable also includes QtGui and QtCore target_link_libraries(vcmilauncher vcmi ${Qt5Widgets_LIBRARIES} ${Qt5Network_LIBRARIES}) -set_target_properties(vcmilauncher PROPERTIES ${PCH_PROPERTIES}) -cotire(vcmilauncher) +# temporary(?) disabled - generation of PCH takes too much time since cotire is trying to collect all Qt headers +#set_target_properties(vcmilauncher PROPERTIES ${PCH_PROPERTIES}) +#cotire(vcmilauncher) if (NOT APPLE) # Already inside bundle install(TARGETS vcmilauncher DESTINATION ${BIN_DIR}) diff --git a/launcher/modManager/cmodlistview_moc.cpp b/launcher/modManager/cmodlistview_moc.cpp index 8ed2001c8..15ec7228a 100644 --- a/launcher/modManager/cmodlistview_moc.cpp +++ b/launcher/modManager/cmodlistview_moc.cpp @@ -581,7 +581,9 @@ void CModListView::installMods(QStringList archives) for (int i=0; iinstallMod(modNames[i], archives[i]); - std::function enableMod = [&](QString modName) + std::function enableMod; + + enableMod = [&](QString modName) { auto mod = modModel->getMod(modName); if (mod.isInstalled() && !mod.getValue("keepDisabled").toBool()) diff --git a/lib/CBattleCallback.cpp b/lib/CBattleCallback.cpp index 67e41da28..cb23fd9bc 100644 --- a/lib/CBattleCallback.cpp +++ b/lib/CBattleCallback.cpp @@ -1455,8 +1455,14 @@ bool CBattleInfoCallback::isToReverse (BattleHex hexFrom, BattleHex hexTo, bool if (toDoubleWide) { - return (isToReverseHlp (hexFrom, hexTo, curDir)) && - (toDir ? isToReverseHlp (hexFrom, hexTo-1, curDir) : isToReverseHlp (hexFrom, hexTo+1, curDir)); + if (isToReverseHlp (hexFrom, hexTo, curDir)) + { + if (toDir) + return isToReverseHlp (hexFrom, hexTo-1, curDir); + else + return isToReverseHlp (hexFrom, hexTo+1, curDir); + } + return false; } else { diff --git a/lib/CDefObjInfoHandler.cpp b/lib/CDefObjInfoHandler.cpp index f47509a70..f715b5fd5 100644 --- a/lib/CDefObjInfoHandler.cpp +++ b/lib/CDefObjInfoHandler.cpp @@ -344,7 +344,7 @@ CDefObjInfoHandler::CDefObjInfoHandler() { readTextFile("Data/Objects.txt"); readTextFile("Data/Heroes.txt"); -/* + const JsonNode node = JsonUtils::assembleFromFiles("config/objectTemplates.json"); std::vector newTemplates; newTemplates.reserve(node.Struct().size()); @@ -363,7 +363,6 @@ CDefObjInfoHandler::CDefObjInfoHandler() // merge new templates into storage objects.insert(objects.end(), newTemplates.begin(), newTemplates.end()); -*/ } void CDefObjInfoHandler::eraseAll(Obj type, si32 subtype)