diff --git a/lib/irrlicht/CMakeLists.txt b/lib/irrlicht/CMakeLists.txt index debd4b8e6..d85a415b6 100644 --- a/lib/irrlicht/CMakeLists.txt +++ b/lib/irrlicht/CMakeLists.txt @@ -30,6 +30,11 @@ if(APPLE) endif() add_definitions(-DNDEBUG=1 -DIRRLICHT_EXPORTS=1 -DPNG_THREAD_UNSAFE_OK -DPNG_NO_MMX_CODE -DPNG_NO_MNG_FEATURES) + +if(UNIX OR MINGW) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++0x") +endif() + if(MSVC) add_definitions(/D_IRR_STATIC_LIB_) add_definitions(/D_CRT_SECURE_NO_WARNINGS) # Shut up about unsafe stuff diff --git a/lib/irrlicht/include/heapsort.h b/lib/irrlicht/include/heapsort.h index 6f87665cd..26d8cd95d 100644 --- a/lib/irrlicht/include/heapsort.h +++ b/lib/irrlicht/include/heapsort.h @@ -12,18 +12,25 @@ namespace irr namespace core { -//! Sinks an element into the heap. +//! Function object which can be used for sorting (default) template -inline void heapsink(T*array, s32 element, s32 max) +inline bool sortless(const T& a, const T& b) +{ + return a < b; +} + +//! Sinks an element into the heap with a custom compare function +template +inline void heapsink(T*array, s32 element, s32 max, Compare cmp) { while ((element<<1) < max) // there is a left child { s32 j = (element<<1); - if (j+1 < max && array[j] < array[j+1]) + if (j+1 < max && cmp(array[j], array[j+1])) j = j+1; // take right child - if (array[element] < array[j]) + if (cmp(array[element], array[j])) { T t = array[j]; // swap elements array[j] = array[element]; @@ -35,10 +42,9 @@ inline void heapsink(T*array, s32 element, s32 max) } } - -//! Sorts an array with size 'size' using heapsort. -template -inline void heapsort(T* array_, s32 size) +//! Sorts an array with size 'size' using heapsort with a custom compare function +template +inline void heapsort(T* array_, s32 size, Compare cmp) { // for heapsink we pretent this is not c++, where // arrays start with index 0. So we decrease the array pointer, @@ -51,7 +57,7 @@ inline void heapsort(T* array_, s32 size) // build heap for (i=((size-1)/2); i>=0; --i) - heapsink(virtualArray, i+1, virtualSize-1); + heapsink(virtualArray, i+1, virtualSize-1, cmp); // sort array, leave out the last element (0) for (i=size-1; i>0; --i) @@ -59,7 +65,7 @@ inline void heapsort(T* array_, s32 size) T t = array_[0]; array_[0] = array_[i]; array_[i] = t; - heapsink(virtualArray, 1, i + 1); + heapsink(virtualArray, 1, i + 1, cmp); } } diff --git a/lib/irrlicht/include/irrArray.h b/lib/irrlicht/include/irrArray.h index 7dab5937a..afd4bb82c 100644 --- a/lib/irrlicht/include/irrArray.h +++ b/lib/irrlicht/include/irrArray.h @@ -394,10 +394,17 @@ public: void sort() { if (!is_sorted && used>1) - heapsort(data, used); + heapsort(data, used, sortless); is_sorted = true; } + template + void sort(Compare cmp) + { + if (!is_sorted && used>1) + heapsort(data, used, cmp); + is_sorted = true; + } //! Performs a binary search for an element, returns -1 if not found. /** The array will be sorted before the binary search if it is not diff --git a/lib/irrlicht/source/Irrlicht/CSkinnedMesh.cpp b/lib/irrlicht/source/Irrlicht/CSkinnedMesh.cpp index a90000f98..8f54b0a15 100644 --- a/lib/irrlicht/source/Irrlicht/CSkinnedMesh.cpp +++ b/lib/irrlicht/source/Irrlicht/CSkinnedMesh.cpp @@ -1439,7 +1439,9 @@ void CSkinnedMesh::convertForSkinning() { core::array this_influence; core::array reported_weight = wi[b][i]; - reported_weight.sort(); + reported_weight.sort([] + (const JointInfluence& a, const JointInfluence& b) + { return a.weight > b.weight; }); float remaining_weight = 1.0f; for (u32 j = 0; j < 4; j++) { diff --git a/lib/irrlicht/source/Irrlicht/CSkinnedMesh.h b/lib/irrlicht/source/Irrlicht/CSkinnedMesh.h index 7e6311faf..00d924d09 100644 --- a/lib/irrlicht/source/Irrlicht/CSkinnedMesh.h +++ b/lib/irrlicht/source/Irrlicht/CSkinnedMesh.h @@ -19,10 +19,6 @@ class JointInfluence public: int joint_idx; float weight; - bool operator < (const JointInfluence& other) const - { - return weight < other.weight; - } }; typedef irr::core::array