mirror of https://github.com/PrimeDecomp/prime.git
Work on rstl::sort
This commit is contained in:
parent
318c1e0b7f
commit
d95736167d
|
@ -1373,7 +1373,7 @@ lbl_8020F990:
|
||||||
/* 8020FA04 0020C964 98 E1 00 14 */ stb r7, 0x14(r1)
|
/* 8020FA04 0020C964 98 E1 00 14 */ stb r7, 0x14(r1)
|
||||||
/* 8020FA08 0020C968 90 C1 00 30 */ stw r6, 0x30(r1)
|
/* 8020FA08 0020C968 90 C1 00 30 */ stw r6, 0x30(r1)
|
||||||
/* 8020FA0C 0020C96C 90 01 00 34 */ stw r0, 0x34(r1)
|
/* 8020FA0C 0020C96C 90 01 00 34 */ stw r0, 0x34(r1)
|
||||||
/* 8020FA10 0020C970 48 00 01 CD */ bl sub_8020fbdc
|
/* 8020FA10 0020C970 48 00 01 CD */ bl "__insertion_sort<Q24rstl130pointer_iterator<Q24rstl11pair<Ui,Ui>,Q24rstl55vector<Q24rstl11pair<Ui,Ui>,Q24rstl17rmemory_allocator>,Q24rstl17rmemory_allocator>,Q226@unnamed@CGameOptions_cpp@13AssetIdSorter>__4rstlFQ24rstl130pointer_iterator<Q24rstl11pair<Ui,Ui>,Q24rstl55vector<Q24rstl11pair<Ui,Ui>,Q24rstl17rmemory_allocator>,Q24rstl17rmemory_allocator>Q24rstl130pointer_iterator<Q24rstl11pair<Ui,Ui>,Q24rstl55vector<Q24rstl11pair<Ui,Ui>,Q24rstl17rmemory_allocator>,Q24rstl17rmemory_allocator>Q226@unnamed@CGameOptions_cpp@13AssetIdSorter"
|
||||||
/* 8020FA14 0020C974 48 00 01 30 */ b lbl_8020FB44
|
/* 8020FA14 0020C974 48 00 01 30 */ b lbl_8020FB44
|
||||||
lbl_8020FA18:
|
lbl_8020FA18:
|
||||||
/* 8020FA18 0020C978 54 80 0F FE */ srwi r0, r4, 0x1f
|
/* 8020FA18 0020C978 54 80 0F FE */ srwi r0, r4, 0x1f
|
||||||
|
@ -1387,7 +1387,7 @@ lbl_8020FA18:
|
||||||
/* 8020FA38 0020C998 7F 83 22 14 */ add r28, r3, r4
|
/* 8020FA38 0020C998 7F 83 22 14 */ add r28, r3, r4
|
||||||
/* 8020FA3C 0020C99C 98 01 00 10 */ stb r0, 0x10(r1)
|
/* 8020FA3C 0020C99C 98 01 00 10 */ stb r0, 0x10(r1)
|
||||||
/* 8020FA40 0020C9A0 7F 84 E3 78 */ mr r4, r28
|
/* 8020FA40 0020C9A0 7F 84 E3 78 */ mr r4, r28
|
||||||
/* 8020FA44 0020C9A4 48 00 01 21 */ bl sub_8020fb64
|
/* 8020FA44 0020C9A4 48 00 01 21 */ bl "__sort3<Q24rstl11pair<Ui,Ui>,Q226@unnamed@CGameOptions_cpp@13AssetIdSorter>__4rstlFRQ24rstl11pair<Ui,Ui>RQ24rstl11pair<Ui,Ui>RQ24rstl11pair<Ui,Ui>Q226@unnamed@CGameOptions_cpp@13AssetIdSorter"
|
||||||
/* 8020FA48 0020C9A8 80 9D 00 00 */ lwz r4, 0(r29)
|
/* 8020FA48 0020C9A8 80 9D 00 00 */ lwz r4, 0(r29)
|
||||||
/* 8020FA4C 0020C9AC 80 61 00 3C */ lwz r3, 0x3c(r1)
|
/* 8020FA4C 0020C9AC 80 61 00 3C */ lwz r3, 0x3c(r1)
|
||||||
/* 8020FA50 0020C9B0 38 84 00 08 */ addi r4, r4, 8
|
/* 8020FA50 0020C9B0 38 84 00 08 */ addi r4, r4, 8
|
||||||
|
@ -1466,8 +1466,8 @@ lbl_8020FB44:
|
||||||
/* 8020FB5C 0020CABC 38 21 00 50 */ addi r1, r1, 0x50
|
/* 8020FB5C 0020CABC 38 21 00 50 */ addi r1, r1, 0x50
|
||||||
/* 8020FB60 0020CAC0 4E 80 00 20 */ blr
|
/* 8020FB60 0020CAC0 4E 80 00 20 */ blr
|
||||||
|
|
||||||
.global sub_8020fb64
|
.global "__sort3<Q24rstl11pair<Ui,Ui>,Q226@unnamed@CGameOptions_cpp@13AssetIdSorter>__4rstlFRQ24rstl11pair<Ui,Ui>RQ24rstl11pair<Ui,Ui>RQ24rstl11pair<Ui,Ui>Q226@unnamed@CGameOptions_cpp@13AssetIdSorter"
|
||||||
sub_8020fb64:
|
"__sort3<Q24rstl11pair<Ui,Ui>,Q226@unnamed@CGameOptions_cpp@13AssetIdSorter>__4rstlFRQ24rstl11pair<Ui,Ui>RQ24rstl11pair<Ui,Ui>RQ24rstl11pair<Ui,Ui>Q226@unnamed@CGameOptions_cpp@13AssetIdSorter":
|
||||||
/* 8020FB64 0020CAC4 80 04 00 00 */ lwz r0, 0(r4)
|
/* 8020FB64 0020CAC4 80 04 00 00 */ lwz r0, 0(r4)
|
||||||
/* 8020FB68 0020CAC8 80 E3 00 00 */ lwz r7, 0(r3)
|
/* 8020FB68 0020CAC8 80 E3 00 00 */ lwz r7, 0(r3)
|
||||||
/* 8020FB6C 0020CACC 7C 00 38 40 */ cmplw r0, r7
|
/* 8020FB6C 0020CACC 7C 00 38 40 */ cmplw r0, r7
|
||||||
|
@ -1501,8 +1501,8 @@ lbl_8020FBD0:
|
||||||
/* 8020FBD4 0020CB34 90 C4 00 04 */ stw r6, 4(r4)
|
/* 8020FBD4 0020CB34 90 C4 00 04 */ stw r6, 4(r4)
|
||||||
/* 8020FBD8 0020CB38 4E 80 00 20 */ blr
|
/* 8020FBD8 0020CB38 4E 80 00 20 */ blr
|
||||||
|
|
||||||
.global sub_8020fbdc
|
.global "__insertion_sort<Q24rstl130pointer_iterator<Q24rstl11pair<Ui,Ui>,Q24rstl55vector<Q24rstl11pair<Ui,Ui>,Q24rstl17rmemory_allocator>,Q24rstl17rmemory_allocator>,Q226@unnamed@CGameOptions_cpp@13AssetIdSorter>__4rstlFQ24rstl130pointer_iterator<Q24rstl11pair<Ui,Ui>,Q24rstl55vector<Q24rstl11pair<Ui,Ui>,Q24rstl17rmemory_allocator>,Q24rstl17rmemory_allocator>Q24rstl130pointer_iterator<Q24rstl11pair<Ui,Ui>,Q24rstl55vector<Q24rstl11pair<Ui,Ui>,Q24rstl17rmemory_allocator>,Q24rstl17rmemory_allocator>Q226@unnamed@CGameOptions_cpp@13AssetIdSorter"
|
||||||
sub_8020fbdc:
|
"__insertion_sort<Q24rstl130pointer_iterator<Q24rstl11pair<Ui,Ui>,Q24rstl55vector<Q24rstl11pair<Ui,Ui>,Q24rstl17rmemory_allocator>,Q24rstl17rmemory_allocator>,Q226@unnamed@CGameOptions_cpp@13AssetIdSorter>__4rstlFQ24rstl130pointer_iterator<Q24rstl11pair<Ui,Ui>,Q24rstl55vector<Q24rstl11pair<Ui,Ui>,Q24rstl17rmemory_allocator>,Q24rstl17rmemory_allocator>Q24rstl130pointer_iterator<Q24rstl11pair<Ui,Ui>,Q24rstl55vector<Q24rstl11pair<Ui,Ui>,Q24rstl17rmemory_allocator>,Q24rstl17rmemory_allocator>Q226@unnamed@CGameOptions_cpp@13AssetIdSorter":
|
||||||
/* 8020FBDC 0020CB3C 80 A3 00 00 */ lwz r5, 0(r3)
|
/* 8020FBDC 0020CB3C 80 A3 00 00 */ lwz r5, 0(r3)
|
||||||
/* 8020FBE0 0020CB40 38 A5 00 08 */ addi r5, r5, 8
|
/* 8020FBE0 0020CB40 38 A5 00 08 */ addi r5, r5, 8
|
||||||
/* 8020FBE4 0020CB44 48 00 00 54 */ b lbl_8020FC38
|
/* 8020FBE4 0020CB44 48 00 00 54 */ b lbl_8020FC38
|
||||||
|
|
|
@ -154,7 +154,7 @@ LIBS = [
|
||||||
"MetroidPrime/ScriptObjects/CScriptWater",
|
"MetroidPrime/ScriptObjects/CScriptWater",
|
||||||
["MetroidPrime/Weapons/CWeapon", False],
|
["MetroidPrime/Weapons/CWeapon", False],
|
||||||
["MetroidPrime/CDamageVulnerability", False],
|
["MetroidPrime/CDamageVulnerability", False],
|
||||||
"MetroidPrime/CActorLights",
|
["MetroidPrime/CActorLights", False],
|
||||||
["MetroidPrime/Enemies/CPatternedInfo", True],
|
["MetroidPrime/Enemies/CPatternedInfo", True],
|
||||||
["MetroidPrime/CSimpleShadow", False],
|
["MetroidPrime/CSimpleShadow", False],
|
||||||
["MetroidPrime/CActorParameters", False],
|
["MetroidPrime/CActorParameters", False],
|
||||||
|
|
|
@ -37,6 +37,7 @@ class Dock;
|
||||||
class CToken;
|
class CToken;
|
||||||
class IDvdRequest;
|
class IDvdRequest;
|
||||||
class CScriptAreaAttributes;
|
class CScriptAreaAttributes;
|
||||||
|
class CWorldLight;
|
||||||
|
|
||||||
class CGameArea : public IGameArea {
|
class CGameArea : public IGameArea {
|
||||||
public:
|
public:
|
||||||
|
@ -134,6 +135,8 @@ public:
|
||||||
const CAreaFog* GetAreaFog() const { return x12c_postConstructed->x10c4_areaFog.get(); }
|
const CAreaFog* GetAreaFog() const { return x12c_postConstructed->x10c4_areaFog.get(); }
|
||||||
CAreaFog* AreaFog() { return x12c_postConstructed->x10c4_areaFog.get(); }
|
CAreaFog* AreaFog() { return x12c_postConstructed->x10c4_areaFog.get(); }
|
||||||
EOcclusionState GetOcclusionState() const { return x12c_postConstructed->x10dc_occlusionState; }
|
EOcclusionState GetOcclusionState() const { return x12c_postConstructed->x10dc_occlusionState; }
|
||||||
|
const rstl::vector<CWorldLight>& GetLightsA() const;
|
||||||
|
const rstl::vector<CWorldLight>& GetLightsB() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uchar x110_pad[0x1c];
|
uchar x110_pad[0x1c];
|
||||||
|
|
|
@ -23,11 +23,81 @@ inline void iter_swap(I1 a, I2 b) {
|
||||||
swap(*a, *b);
|
swap(*a, *b);
|
||||||
}
|
}
|
||||||
|
|
||||||
template < class It, class Cmp >
|
template < typename It, class Cmp >
|
||||||
void __sort3(It a, It b, It c, Cmp comp); // TODO
|
void __insertion_sort(It first, It last, Cmp cmp);
|
||||||
|
|
||||||
|
template < class T, class Cmp >
|
||||||
|
void __sort3(T& a, T& b, T& c, Cmp comp); // TODO
|
||||||
|
|
||||||
template < typename It, class Cmp >
|
template < typename It, class Cmp >
|
||||||
inline void sort(It first, It last, Cmp cmp); // TODO
|
void sort(It first, It last, Cmp cmp); // TODO
|
||||||
|
|
||||||
|
// Implementations
|
||||||
|
|
||||||
|
template < typename It, class Cmp >
|
||||||
|
void __insertion_sort(It first, It last, Cmp cmp) {
|
||||||
|
for (It next = first + 1; next < last; ++next) {
|
||||||
|
typename iterator_traits< It >::value_type value = *next;
|
||||||
|
|
||||||
|
It t1 = next;
|
||||||
|
It t2 = next;
|
||||||
|
while (first < t1 && cmp(value, *(t2 - 1))) {
|
||||||
|
*t1 = *(t2 - 1);
|
||||||
|
--t1;
|
||||||
|
--t2;
|
||||||
|
}
|
||||||
|
|
||||||
|
*t1 = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template < typename T, class Cmp >
|
||||||
|
void __sort3(T& a, T& b, T& c, Cmp comp) {
|
||||||
|
if (comp(b, a)) {
|
||||||
|
swap(a, b);
|
||||||
|
}
|
||||||
|
if (comp(c, b)) {
|
||||||
|
T tmp(c);
|
||||||
|
c = b;
|
||||||
|
if (comp(tmp, a)) {
|
||||||
|
b = a;
|
||||||
|
a = tmp;
|
||||||
|
} else {
|
||||||
|
b = tmp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template < typename It, class Cmp >
|
||||||
|
void sort(It first, It last, Cmp cmp) {
|
||||||
|
int count = last - first;
|
||||||
|
if (count > 1) {
|
||||||
|
if (count <= 20) {
|
||||||
|
__insertion_sort(first, last, cmp);
|
||||||
|
} else {
|
||||||
|
It beforeLast = last - 1;
|
||||||
|
__sort3(*first, *(first + count / 2), *(last - 1), cmp);
|
||||||
|
|
||||||
|
It middle = first + count / 2;
|
||||||
|
It it = first + 1;
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
for (; cmp(*it, *middle); ++it)
|
||||||
|
;
|
||||||
|
for (; cmp(*middle, *beforeLast); --beforeLast)
|
||||||
|
;
|
||||||
|
if (!cmp(*it, *beforeLast))
|
||||||
|
break;
|
||||||
|
rstl::swap(*it, *beforeLast);
|
||||||
|
++it;
|
||||||
|
--beforeLast;
|
||||||
|
}
|
||||||
|
sort(first, it, cmp);
|
||||||
|
sort(it, last, cmp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace rstl
|
} // namespace rstl
|
||||||
|
|
||||||
#endif // _RSTL_ALGORITHM
|
#endif // _RSTL_ALGORITHM
|
||||||
|
|
|
@ -14,7 +14,7 @@ class const_pointer_iterator {
|
||||||
public:
|
public:
|
||||||
typedef ptrdiff_t difference_type;
|
typedef ptrdiff_t difference_type;
|
||||||
typedef random_access_iterator_tag iterator_category;
|
typedef random_access_iterator_tag iterator_category;
|
||||||
typedef T* value_type;
|
typedef T value_type;
|
||||||
|
|
||||||
const_pointer_iterator() : current(nullptr) {}
|
const_pointer_iterator() : current(nullptr) {}
|
||||||
const_pointer_iterator(const T* begin) : current(const_cast< T* >(begin)) {}
|
const_pointer_iterator(const T* begin) : current(const_cast< T* >(begin)) {}
|
||||||
|
@ -133,6 +133,19 @@ inline typename It::difference_type __distance(It first, It last, random_access_
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template < typename T >
|
||||||
|
struct iterator_traits {};
|
||||||
|
|
||||||
|
template < typename T >
|
||||||
|
struct iterator_traits<T*> {
|
||||||
|
typedef T value_type;
|
||||||
|
};
|
||||||
|
|
||||||
|
template < typename T, typename Vec, typename Alloc >
|
||||||
|
struct iterator_traits< pointer_iterator<T, Vec, Alloc> > {
|
||||||
|
typedef typename pointer_iterator<T, Vec, Alloc>::value_type value_type;
|
||||||
|
};
|
||||||
|
|
||||||
} // namespace rstl
|
} // namespace rstl
|
||||||
|
|
||||||
#endif // _RSTL_POINTER_ITERATOR
|
#endif // _RSTL_POINTER_ITERATOR
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
#include "MetroidPrime/CActorLights.hpp"
|
||||||
|
|
||||||
|
#include "MetroidPrime/CGameArea.hpp"
|
||||||
|
|
||||||
|
#include "WorldFormat/CWorldLight.hpp"
|
||||||
|
|
||||||
|
#include "rstl/algorithm.hpp"
|
||||||
|
|
||||||
|
// TODO: move
|
||||||
|
enum EPVSVisSetState { kVSS_EndOfTree, kVSS_NodeFound, kVSS_OutOfBounds };
|
||||||
|
|
||||||
|
struct SLightValue {
|
||||||
|
int x0_areaLightIdx;
|
||||||
|
CColor x4_color;
|
||||||
|
uchar x8_pad[0x8];
|
||||||
|
float x10_colorMag;
|
||||||
|
float x14_accumulatedMag;
|
||||||
|
EPVSVisSetState x18_visiblity;
|
||||||
|
|
||||||
|
struct CPredicate {
|
||||||
|
bool operator()(SLightValue& a, SLightValue& b) {
|
||||||
|
return a.x10_colorMag > b.x10_colorMag ? true : false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
|
CHECK_SIZEOF(SLightValue, 0x1c);
|
||||||
|
|
||||||
|
bool CActorLights::BuildAreaLightList(const CStateManager& mgr, const CGameArea& area,
|
||||||
|
const CAABox& aabb) {
|
||||||
|
const rstl::vector< CWorldLight >& lightList =
|
||||||
|
x298_30_layer2 ? area.GetLightsB() : area.GetLightsA();
|
||||||
|
|
||||||
|
rstl::vector< SLightValue > valList;
|
||||||
|
valList.reserve(lightList.size());
|
||||||
|
|
||||||
|
rstl::sort(&*valList.begin(), &*valList.end(), SLightValue::CPredicate());
|
||||||
|
}
|
|
@ -10,7 +10,6 @@
|
||||||
#include "rstl/pair.hpp"
|
#include "rstl/pair.hpp"
|
||||||
#include "rstl/vector.hpp"
|
#include "rstl/vector.hpp"
|
||||||
|
|
||||||
|
|
||||||
CFlameWarp::CFlameWarp(float maxInfluenceDist, const CVector3f& warpPoint, bool collisionWarp)
|
CFlameWarp::CFlameWarp(float maxInfluenceDist, const CVector3f& warpPoint, bool collisionWarp)
|
||||||
: x4_collisionPoints(warpPoint)
|
: x4_collisionPoints(warpPoint)
|
||||||
, x74_warpPoint(warpPoint)
|
, x74_warpPoint(warpPoint)
|
||||||
|
@ -112,7 +111,6 @@ void CFlameWarp::ModifyParticles(int particleCount, int stripe, int*, CVector3f*
|
||||||
|
|
||||||
rstl::sort(vec.begin(), vec.end(), Comparer());
|
rstl::sort(vec.begin(), vec.end(), Comparer());
|
||||||
|
|
||||||
|
|
||||||
int vecIdx = 0;
|
int vecIdx = 0;
|
||||||
const int pitch = particleCount / 9;
|
const int pitch = particleCount / 9;
|
||||||
|
|
||||||
|
|
|
@ -13,16 +13,6 @@
|
||||||
|
|
||||||
#include "dolphin/os.h"
|
#include "dolphin/os.h"
|
||||||
|
|
||||||
namespace rstl {
|
|
||||||
#ifndef __MWERKS__
|
|
||||||
template < class It, class Cmp >
|
|
||||||
void sort(It first, It last, Cmp cmp) {
|
|
||||||
// TODO: proper implementation
|
|
||||||
cmp(*first, *last);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
} // namespace rstl
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
class AssetIdSorter {
|
class AssetIdSorter {
|
||||||
public:
|
public:
|
||||||
|
|
Loading…
Reference in New Issue