Browse Source

Fix tbb build

Andrii Danylchenko 4 years ago
parent
commit
bc95e4b935

+ 18 - 4
AI/Nullkiller/AIUtility.h

@@ -9,6 +9,21 @@
  */
 #pragma once
 
+/*********************** TBB.h ********************/
+
+#include "tbb/atomic.h"
+#include "tbb/blocked_range.h"
+#include "tbb/concurrent_hash_map.h"
+#include "tbb/concurrent_unordered_map.h"
+#include "tbb/concurrent_unordered_set.h"
+#include "tbb/concurrent_vector.h"
+#include "tbb/parallel_do.h"
+#include "tbb/parallel_for.h"
+#include "tbb/parallel_for_each.h"
+#include "tbb/parallel_invoke.h"
+
+/*********************** TBB.h ********************/
+
 #include "../../lib/VCMI_Lib.h"
 #include "../../lib/CBuildingHandler.h"
 #include "../../lib/CCreatureHandler.h"
@@ -18,7 +33,6 @@
 #include "../../lib/mapObjects/CObjectHandler.h"
 #include "../../lib/mapObjects/CGHeroInstance.h"
 #include "../../lib/CPathfinder.h"
-#include <tbb/tbb.h>
 
 using namespace tbb;
 
@@ -258,13 +272,13 @@ public:
 	
 	void add(std::unique_ptr<T> t)
 	{
-		std::lock_guard<std::mutex> lock(sync);
+		boost::lock_guard<boost::mutex> lock(sync);
 		pool.push_back(std::move(t));
 	}
 
 	ptr_type acquire()
 	{
-		std::lock_guard<std::mutex> lock(sync);
+		boost::lock_guard<boost::mutex> lock(sync);
 		bool poolIsEmpty = pool.empty();
 		T * element = poolIsEmpty
 			? elementFactory().release()
@@ -293,5 +307,5 @@ private:
 	std::vector<std::unique_ptr<T>> pool;
 	std::function<std::unique_ptr<T>()> elementFactory;
 	std::shared_ptr<SharedPool<T> *> instance_tracker;
-	std::mutex sync;
+	boost::mutex sync;
 };

+ 5 - 1
AI/Nullkiller/CMakeLists.txt

@@ -139,7 +139,11 @@ else()
 	target_link_libraries(VCAI PRIVATE fl-static vcmi)
 endif()
 
-target_link_libraries(VCAI PRIVATE TBB::tbb)
+if(TBB_FOUND)
+	target_link_libraries(VCAI PRIVATE ${TBB_LIBRARIES})
+else()
+	target_link_libraries(VCAI PRIVATE tbb)
+endif()
 
 vcmi_set_output_dir(VCAI "AI")
 

+ 11 - 13
AI/Nullkiller/Goals/AbstractGoal.h

@@ -82,8 +82,7 @@ namespace Goals
 	typedef std::vector<TSubgoal> TGoalVec;
 
 	//method chaining + clone pattern
-#define VSETTER(type, field) virtual AbstractGoal & set ## field(const type &rhs) {field = rhs; return *this;};
-#define OSETTER(type, field) CGoal<T> & set ## field(const type &rhs) override { field = rhs; return *this; };
+#define SETTER(type, field) AbstractGoal & set ## field(const type &rhs) {field = rhs; return *this;};
 
 #if 0
 #define SETTER
@@ -97,17 +96,16 @@ namespace Goals
 	class DLL_EXPORT AbstractGoal
 	{
 	public:
-		bool isAbstract; VSETTER(bool, isAbstract)
-		int value; VSETTER(int, value)
-		ui64 goldCost; VSETTER(ui64, goldCost)
-		int resID; VSETTER(int, resID)
-		int objid; VSETTER(int, objid)
-		int aid; VSETTER(int, aid)
-		int3 tile; VSETTER(int3, tile)
-		HeroPtr hero; VSETTER(HeroPtr, hero)
-		const CGTownInstance *town; VSETTER(CGTownInstance *, town)
-		int bid; VSETTER(int, bid)
-		TSubgoal parent; VSETTER(TSubgoal, parent)
+		bool isAbstract; SETTER(bool, isAbstract)
+		int value; SETTER(int, value)
+		ui64 goldCost; SETTER(ui64, goldCost)
+		int resID; SETTER(int, resID)
+		int objid; SETTER(int, objid)
+		int aid; SETTER(int, aid)
+		int3 tile; SETTER(int3, tile)
+		HeroPtr hero; SETTER(HeroPtr, hero)
+		const CGTownInstance *town; SETTER(CGTownInstance *, town)
+		int bid; SETTER(int, bid)
 
 		AbstractGoal(EGoals goal = EGoals::INVALID)
 			: goalType(goal), hero()

+ 1 - 11
AI/Nullkiller/Goals/CGoal.h

@@ -30,16 +30,6 @@ namespace Goals
 			town = nullptr;
 		}
 
-		OSETTER(bool, isAbstract)
-		OSETTER(int, value)
-		OSETTER(int, resID)
-		OSETTER(int, objid)
-		OSETTER(int, aid)
-		OSETTER(int3, tile)
-		OSETTER(HeroPtr, hero)
-		OSETTER(CGTownInstance *, town)
-		OSETTER(int, bid)
-
 		CGoal<T> * clone() const override
 		{
 			return new T(static_cast<T const &>(*this)); //casting enforces template instantiation
@@ -99,7 +89,7 @@ namespace Goals
 
 		virtual bool isElementar() const override { return true; }
 
-		virtual HeroPtr getHero() const override { return hero; }
+		virtual HeroPtr getHero() const override { return AbstractGoal::hero; }
 	};
 
 	class DLL_EXPORT Invalid : public ElementarGoal<Invalid>

+ 2 - 2
AI/Nullkiller/Pathfinding/AINodeStorage.cpp

@@ -499,7 +499,7 @@ bool AINodeStorage::calculateHeroChain()
 
 	if(data.size() > 100)
 	{
-		std::mutex resultMutex;
+		boost::mutex resultMutex;
 
 		std::random_shuffle(data.begin(), data.end());
 
@@ -511,7 +511,7 @@ bool AINodeStorage::calculateHeroChain()
 			task.execute(r);
 
 			{
-				std::lock_guard<std::mutex> resultLock(resultMutex);
+				boost::lock_guard<boost::mutex> resultLock(resultMutex);
 
 				task.flushResult(heroChain);
 			}