Allow array to capture lambada
Also use a correct sorting function, will be useful later if we only need the more influetial bones.
This commit is contained in:
parent
ceef7495d2
commit
f6490b6fa6
@ -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
|
||||
|
@ -12,18 +12,25 @@ namespace irr
|
||||
namespace core
|
||||
{
|
||||
|
||||
//! Sinks an element into the heap.
|
||||
//! Function object which can be used for sorting (default)
|
||||
template<class T>
|
||||
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<class T, class Compare>
|
||||
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<class T>
|
||||
inline void heapsort(T* array_, s32 size)
|
||||
//! Sorts an array with size 'size' using heapsort with a custom compare function
|
||||
template<class T, class Compare>
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -394,10 +394,17 @@ public:
|
||||
void sort()
|
||||
{
|
||||
if (!is_sorted && used>1)
|
||||
heapsort(data, used);
|
||||
heapsort(data, used, sortless<T>);
|
||||
is_sorted = true;
|
||||
}
|
||||
|
||||
template<class Compare>
|
||||
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
|
||||
|
@ -1439,7 +1439,9 @@ void CSkinnedMesh::convertForSkinning()
|
||||
{
|
||||
core::array<JointInfluence> this_influence;
|
||||
core::array<JointInfluence> 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++)
|
||||
{
|
||||
|
@ -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<irr::core::array
|
||||
|
Loading…
x
Reference in New Issue
Block a user