diff --git a/config/GM8E01_00/symbols.txt b/config/GM8E01_00/symbols.txt index 06a27501..3ad84d1c 100644 --- a/config/GM8E01_00/symbols.txt +++ b/config/GM8E01_00/symbols.txt @@ -18146,7 +18146,134 @@ __vt__14CScriptCounter = .data:0x803DAEF0; // type:object size:0x20 scope:global @290 = .data:0x803DAF10; // type:object size:0x24 scope:local lbl_803DAF38 = .data:0x803DAF38; // type:object size:0x10 lbl_803DAF48 = .data:0x803DAF48; // type:object size:0x10 -lbl_803DAF58 = .data:0x803DAF58; // type:object size:0xD74 data:4byte +...data.0 = .data:0x803DAF58; // type:label scope:local +gkStateNames = .data:0x803DAF58; // type:object size:0xDC data:4byte +lbl_803DB034 = .data:0x803DB034; // type:object size:0xC +lbl_803DB040 = .data:0x803DB040; // type:object size:0xC +lbl_803DB04C = .data:0x803DB04C; // type:object size:0xC +lbl_803DB058 = .data:0x803DB058; // type:object size:0xC +lbl_803DB064 = .data:0x803DB064; // type:object size:0xC +lbl_803DB070 = .data:0x803DB070; // type:object size:0xC +lbl_803DB07C = .data:0x803DB07C; // type:object size:0xC +lbl_803DB088 = .data:0x803DB088; // type:object size:0xC +lbl_803DB094 = .data:0x803DB094; // type:object size:0xC +lbl_803DB0A0 = .data:0x803DB0A0; // type:object size:0xC +lbl_803DB0AC = .data:0x803DB0AC; // type:object size:0xC +lbl_803DB0B8 = .data:0x803DB0B8; // type:object size:0xC +lbl_803DB0C4 = .data:0x803DB0C4; // type:object size:0xC +lbl_803DB0D0 = .data:0x803DB0D0; // type:object size:0xC +lbl_803DB0DC = .data:0x803DB0DC; // type:object size:0xC +lbl_803DB0E8 = .data:0x803DB0E8; // type:object size:0xC +lbl_803DB0F4 = .data:0x803DB0F4; // type:object size:0xC +lbl_803DB100 = .data:0x803DB100; // type:object size:0xC +lbl_803DB10C = .data:0x803DB10C; // type:object size:0xC +lbl_803DB118 = .data:0x803DB118; // type:object size:0xC +lbl_803DB124 = .data:0x803DB124; // type:object size:0xC +lbl_803DB130 = .data:0x803DB130; // type:object size:0xC +lbl_803DB13C = .data:0x803DB13C; // type:object size:0xC +lbl_803DB148 = .data:0x803DB148; // type:object size:0xC +lbl_803DB154 = .data:0x803DB154; // type:object size:0xC +lbl_803DB160 = .data:0x803DB160; // type:object size:0xC +lbl_803DB16C = .data:0x803DB16C; // type:object size:0xC +lbl_803DB178 = .data:0x803DB178; // type:object size:0xC +lbl_803DB184 = .data:0x803DB184; // type:object size:0xC +lbl_803DB190 = .data:0x803DB190; // type:object size:0xC +lbl_803DB19C = .data:0x803DB19C; // type:object size:0xC +lbl_803DB1A8 = .data:0x803DB1A8; // type:object size:0xC +lbl_803DB1B4 = .data:0x803DB1B4; // type:object size:0xC +lbl_803DB1C0 = .data:0x803DB1C0; // type:object size:0xC +lbl_803DB1CC = .data:0x803DB1CC; // type:object size:0xC +lbl_803DB1D8 = .data:0x803DB1D8; // type:object size:0xC +lbl_803DB1E4 = .data:0x803DB1E4; // type:object size:0xC +lbl_803DB1F0 = .data:0x803DB1F0; // type:object size:0xC +lbl_803DB1FC = .data:0x803DB1FC; // type:object size:0xC +lbl_803DB208 = .data:0x803DB208; // type:object size:0xC +lbl_803DB214 = .data:0x803DB214; // type:object size:0xC +lbl_803DB220 = .data:0x803DB220; // type:object size:0xC +lbl_803DB22C = .data:0x803DB22C; // type:object size:0xC +lbl_803DB238 = .data:0x803DB238; // type:object size:0xC +lbl_803DB244 = .data:0x803DB244; // type:object size:0xC +lbl_803DB250 = .data:0x803DB250; // type:object size:0xC +lbl_803DB25C = .data:0x803DB25C; // type:object size:0xC +lbl_803DB268 = .data:0x803DB268; // type:object size:0xC +lbl_803DB274 = .data:0x803DB274; // type:object size:0xC +lbl_803DB280 = .data:0x803DB280; // type:object size:0xC +lbl_803DB28C = .data:0x803DB28C; // type:object size:0xC +lbl_803DB298 = .data:0x803DB298; // type:object size:0xC +lbl_803DB2A4 = .data:0x803DB2A4; // type:object size:0xC +lbl_803DB2B0 = .data:0x803DB2B0; // type:object size:0xC +lbl_803DB2BC = .data:0x803DB2BC; // type:object size:0xC +gkStateFuncs = .data:0x803DB2C8; // type:object size:0x294 +gkTriggerNames = .data:0x803DB55C; // type:object size:0x110 +lbl_803DB66C = .data:0x803DB66C; // type:object size:0xC +lbl_803DB678 = .data:0x803DB678; // type:object size:0xC +lbl_803DB684 = .data:0x803DB684; // type:object size:0xC +lbl_803DB690 = .data:0x803DB690; // type:object size:0xC +lbl_803DB69C = .data:0x803DB69C; // type:object size:0xC +lbl_803DB6A8 = .data:0x803DB6A8; // type:object size:0xC +lbl_803DB6B4 = .data:0x803DB6B4; // type:object size:0xC +lbl_803DB6C0 = .data:0x803DB6C0; // type:object size:0xC +lbl_803DB6CC = .data:0x803DB6CC; // type:object size:0xC +lbl_803DB6D8 = .data:0x803DB6D8; // type:object size:0xC +lbl_803DB6E4 = .data:0x803DB6E4; // type:object size:0xC +lbl_803DB6F0 = .data:0x803DB6F0; // type:object size:0xC +lbl_803DB6FC = .data:0x803DB6FC; // type:object size:0xC +lbl_803DB708 = .data:0x803DB708; // type:object size:0xC +lbl_803DB714 = .data:0x803DB714; // type:object size:0xC +lbl_803DB720 = .data:0x803DB720; // type:object size:0xC +lbl_803DB72C = .data:0x803DB72C; // type:object size:0xC +lbl_803DB738 = .data:0x803DB738; // type:object size:0xC +lbl_803DB744 = .data:0x803DB744; // type:object size:0xC +lbl_803DB750 = .data:0x803DB750; // type:object size:0xC +lbl_803DB75C = .data:0x803DB75C; // type:object size:0xC +lbl_803DB768 = .data:0x803DB768; // type:object size:0xC +lbl_803DB774 = .data:0x803DB774; // type:object size:0xC +lbl_803DB780 = .data:0x803DB780; // type:object size:0xC +lbl_803DB78C = .data:0x803DB78C; // type:object size:0xC +lbl_803DB798 = .data:0x803DB798; // type:object size:0xC +lbl_803DB7A4 = .data:0x803DB7A4; // type:object size:0xC +lbl_803DB7B0 = .data:0x803DB7B0; // type:object size:0xC +lbl_803DB7BC = .data:0x803DB7BC; // type:object size:0xC +lbl_803DB7C8 = .data:0x803DB7C8; // type:object size:0xC +lbl_803DB7D4 = .data:0x803DB7D4; // type:object size:0xC +lbl_803DB7E0 = .data:0x803DB7E0; // type:object size:0xC +lbl_803DB7EC = .data:0x803DB7EC; // type:object size:0xC +lbl_803DB7F8 = .data:0x803DB7F8; // type:object size:0xC +lbl_803DB804 = .data:0x803DB804; // type:object size:0xC +lbl_803DB810 = .data:0x803DB810; // type:object size:0xC +lbl_803DB81C = .data:0x803DB81C; // type:object size:0xC +lbl_803DB828 = .data:0x803DB828; // type:object size:0xC +lbl_803DB834 = .data:0x803DB834; // type:object size:0xC +lbl_803DB840 = .data:0x803DB840; // type:object size:0xC +lbl_803DB84C = .data:0x803DB84C; // type:object size:0xC +lbl_803DB858 = .data:0x803DB858; // type:object size:0xC +lbl_803DB864 = .data:0x803DB864; // type:object size:0xC +lbl_803DB870 = .data:0x803DB870; // type:object size:0xC +lbl_803DB87C = .data:0x803DB87C; // type:object size:0xC +lbl_803DB888 = .data:0x803DB888; // type:object size:0xC +lbl_803DB894 = .data:0x803DB894; // type:object size:0xC +lbl_803DB8A0 = .data:0x803DB8A0; // type:object size:0xC +lbl_803DB8AC = .data:0x803DB8AC; // type:object size:0xC +lbl_803DB8B8 = .data:0x803DB8B8; // type:object size:0xC +lbl_803DB8C4 = .data:0x803DB8C4; // type:object size:0xC +lbl_803DB8D0 = .data:0x803DB8D0; // type:object size:0xC +lbl_803DB8DC = .data:0x803DB8DC; // type:object size:0xC +lbl_803DB8E8 = .data:0x803DB8E8; // type:object size:0xC +lbl_803DB8F4 = .data:0x803DB8F4; // type:object size:0xC +lbl_803DB900 = .data:0x803DB900; // type:object size:0xC +lbl_803DB90C = .data:0x803DB90C; // type:object size:0xC +lbl_803DB918 = .data:0x803DB918; // type:object size:0xC +lbl_803DB924 = .data:0x803DB924; // type:object size:0xC +lbl_803DB930 = .data:0x803DB930; // type:object size:0xC +lbl_803DB93C = .data:0x803DB93C; // type:object size:0xC +lbl_803DB948 = .data:0x803DB948; // type:object size:0xC +lbl_803DB954 = .data:0x803DB954; // type:object size:0xC +lbl_803DB960 = .data:0x803DB960; // type:object size:0xC +lbl_803DB96C = .data:0x803DB96C; // type:object size:0xC +lbl_803DB978 = .data:0x803DB978; // type:object size:0xC +lbl_803DB984 = .data:0x803DB984; // type:object size:0xC +lbl_803DB990 = .data:0x803DB990; // type:object size:0xC +gkTriggerFuncs = .data:0x803DB99C; // type:object size:0x330 __vt__3CAi = .data:0x803DBCCC; // type:object size:0x294 __vt__19TCastToPtr<6CActor> = .data:0x803DBF60; // type:object size:0xEC scope:weak __vt__18TCastToPtr<5CBomb> = .data:0x803DC04C; // type:object size:0xEC scope:weak diff --git a/include/Collision/CollisionUtil.hpp b/include/Collision/CollisionUtil.hpp index bb7a9ee7..17ebf5f2 100644 --- a/include/Collision/CollisionUtil.hpp +++ b/include/Collision/CollisionUtil.hpp @@ -6,6 +6,7 @@ class CMaterialList; class CCollisionInfoList; class CVector3f; class CSphere; +class CMRay; namespace CollisionUtil { @@ -18,11 +19,12 @@ bool AABoxAABoxIntersection(const CAABox& left, const CAABox& right); bool AABoxAABoxIntersection(const CAABox& left, const CMaterialList& leftFilter, const CAABox& right, const CMaterialList& rightFilter, CCollisionInfoList& list); +int RayAABoxIntersection(const CMRay& ray, const CAABox& box, CVector3f& dir, float& penetration); bool AABox_AABox_Moving(const CAABox& left, const CAABox& right, const CVector3f& dir, double& d, CVector3f& point, CVector3f& normal); -bool MovingSphereAABox(const CSphere& sphere, const CAABox& aabb, const CVector3f& dir, double& dOut, - CVector3f& point, CVector3f& normal); +bool MovingSphereAABox(const CSphere& sphere, const CAABox& aabb, const CVector3f& dir, + double& dOut, CVector3f& point, CVector3f& normal); } // namespace CollisionUtil diff --git a/include/rstl/algorithm.hpp b/include/rstl/algorithm.hpp index aef20e51..57e62f9a 100644 --- a/include/rstl/algorithm.hpp +++ b/include/rstl/algorithm.hpp @@ -52,7 +52,7 @@ void __insertion_sort(It first, It last, Cmp cmp) { } template < typename T, class Cmp > -void __sort3(T& a, T& b, T& c, Cmp comp) { +void __sort3(T& a, T& b, T& c, const Cmp comp) { if (comp(b, a)) { swap(a, b); } @@ -71,28 +71,29 @@ void __sort3(T& a, T& b, T& c, Cmp comp) { template < typename It, class Cmp > void sort(It first, It last, Cmp cmp) { int count = last - first; // use distance? - if (count > 1) { - if (count > 20) { - __insertion_sort(first, last, cmp); - } else { - It pivot = first + count / 2; - It end = last; - __sort3(*first, *pivot, *--end, cmp); - typename iterator_traits< It >::value_type value = *pivot; - It it = first + 1; - --end; - while (true) { - while (cmp(*it, value)) - ++it; - while (cmp(value, *end)) - --end; - if (it >= end) - break; - iter_swap(it++, end--); - } - sort(first, it, cmp); - sort(it, last, cmp); + if (count <= 1) { + return; + } + if (20 >= count) { + __insertion_sort(first, last, cmp); + } else { + It pivot = first + count / 2; + It end = last; + __sort3(*first, *pivot, *--end, cmp); + typename iterator_traits< It >::value_type value = *pivot; + It it = first + 1; + --end; + while (true) { + while (cmp(*it, value)) + ++it; + while (cmp(value, *end)) + --end; + if (it >= end) + break; + iter_swap(it++, end--); } + sort(first, it, cmp); + sort(it, last, cmp); } } @@ -207,7 +208,7 @@ typename T::iterator inline find_by_key_nc( } template < typename T, class Cmp > -inline void sort_by_key(T& container, Cmp cmp) { +inline void sort_by_key(T& container, const Cmp& cmp) { sort(container.begin(), container.end(), pair_sorter_finder< typename T::value_type, Cmp >(cmp)); } diff --git a/src/Collision/COBBox.cpp b/src/Collision/COBBox.cpp index 0975f79e..9fda352b 100644 --- a/src/Collision/COBBox.cpp +++ b/src/Collision/COBBox.cpp @@ -1,9 +1,14 @@ #include "Collision/COBBox.hpp" -#include "Kyoto/Streams/CInputStream.hpp" +#include "Collision/CMRay.hpp" +#include "Collision/CollisionUtil.hpp" -COBBox::COBBox(const CTransform4f& xf, const CVector3f& extents) -: mTransform(xf), mExtents(extents) {} +#include +#include + +#include +COBBox::COBBox(const CTransform4f& xf, const CVector3f& mExtents) +: mTransform(xf), mExtents(mExtents) {} COBBox::COBBox(CInputStream& in) : mTransform(in), mExtents(in) {} @@ -13,15 +18,21 @@ CAABox COBBox::CalculateAABox(const CTransform4f& xf) const { COBBox COBBox::FromAABox(const CAABox& box, const CTransform4f& xf) { CVector3f center = box.GetCenterPoint(); - CVector3f extents = box.GetMaxPoint() - center; + CVector3f mExtents = box.GetMaxPoint() - center; CTransform4f finalTransform = xf * CTransform4f::Translate(center); - return COBBox(finalTransform, extents); + return COBBox(finalTransform, mExtents); } -bool COBBox::LineIntersectsBox(const CMRay& ray, float& penetration) const { return false; } +bool COBBox::LineIntersectsBox(const CMRay& ray, float& penetration) const { + CAABox box(-mExtents, mExtents); + CMRay unscaledRay = ray.GetInvUnscaledTransformRay(mTransform); + CVector3f direction = CVector3f::Zero(); + return CollisionUtil::RayAABoxIntersection(unscaledRay, box, direction, penetration) != 0; +} bool COBBox::AABoxIntersectsBox(const CAABox& box) const { return OBBIntersectsBox(FromAABox(box, CTransform4f::Identity())); } -bool COBBox::OBBIntersectsBox(const COBBox& box) const { return false; } +bool COBBox::OBBIntersectsBox(const COBBox& other) const { +} diff --git a/src/Kyoto/Graphics/CCubeModel.cpp b/src/Kyoto/Graphics/CCubeModel.cpp index 48a71e62..adf88000 100644 --- a/src/Kyoto/Graphics/CCubeModel.cpp +++ b/src/Kyoto/Graphics/CCubeModel.cpp @@ -27,18 +27,22 @@ CCubeModel::CCubeModel(rstl::vector< void* >* surfaces, , x40_25_visible(false) , x41_visorFlags(visorFlags) , x44_idx(idx) { - for (AUTO(it, x0_instance.Surfaces().begin()); it != x0_instance.Surfaces().end(); ++it) { - static_cast< CCubeSurface::SSurfaceData* >(*it)->mParent = this; + rstl::vector< void* >& surf = x0_instance.Surfaces(); + for (AUTO(it, surf.begin()); it != surf.end(); ++it) { + CCubeSurface::SSurfaceData* data = static_cast< CCubeSurface::SSurfaceData* >(*it); + data->mParent = this; } - for (int i = x0_instance.Surfaces().size(); i > 0; i--) { - CCubeSurface surf(x0_instance.Surfaces()[i - 1]); - if (GetMaterialByIndex(surf.GetMaterialIndex()).IsFlagSet(kStateFlag_DepthSorting)) { - surf.x0_data->mNextSurface = x3c_firstSorted.x0_data; - x3c_firstSorted.x0_rawdata = surf.x0_rawdata; + for (int i = surf.size(); i > 0; i--) { + void*& data = surf[i - 1]; + uint materialIndex = static_cast< CCubeSurface::SSurfaceData* >(data)->mMaterialIndex; + if (GetMaterialByIndex(materialIndex).IsFlagSet(kStateFlag_DepthSorting)) { + static_cast< CCubeSurface::SSurfaceData* >(data)->mNextSurface = x3c_firstSorted.x0_rawdata; + x3c_firstSorted.x0_rawdata = static_cast< uchar* >(data); } else { - surf.x0_data->mNextSurface = x38_firstUnsorted.x0_data; - x38_firstUnsorted.x0_rawdata = surf.x0_rawdata; + static_cast< CCubeSurface::SSurfaceData* >(data)->mNextSurface = + x38_firstUnsorted.x0_rawdata; + x38_firstUnsorted.x0_rawdata = static_cast< uchar* >(data); } } } diff --git a/src/MetroidPrime/CStateManager.cpp b/src/MetroidPrime/CStateManager.cpp index cb31395d..e7de8bd4 100644 --- a/src/MetroidPrime/CStateManager.cpp +++ b/src/MetroidPrime/CStateManager.cpp @@ -45,17 +45,20 @@ private: }; bool area_sorter::operator()(const CGameArea* a, const CGameArea* b) const { - if (a->GetId() == b->GetId()) { + TAreaId aId = a->GetId(); + TAreaId bId = b->GetId(); + if (aId == bId) { return false; } - if (visAreaId == a->GetId()) { + if (aId == visAreaId) { return false; } - if (visAreaId == b->GetId()) { + if (b->GetId() == visAreaId) { return true; } - return CVector3f::Dot(reference, a->GetAABB().GetCenterPoint()) > - CVector3f::Dot(reference, b->GetAABB().GetCenterPoint()); + const float aDot = CVector3f::Dot(reference, a->GetAABB().GetCenterPoint()); + const float bDot = CVector3f::Dot(reference, b->GetAABB().GetCenterPoint()); + return aDot > bDot; } } // namespace diff --git a/src/MetroidPrime/Enemies/CAi.cpp b/src/MetroidPrime/Enemies/CAi.cpp index 7327cfe4..1c2d3546 100644 --- a/src/MetroidPrime/Enemies/CAi.cpp +++ b/src/MetroidPrime/Enemies/CAi.cpp @@ -16,7 +16,7 @@ namespace { struct cstr_less { - const bool operator()(const char* a, const char* b) const { return (strcmp(a, b) < 0); } + bool operator()(const char* a, const char* b) const { return (strcmp(a, b) < 0); } }; } // namespace diff --git a/src/MetroidPrime/Player/CGameOptions.cpp b/src/MetroidPrime/Player/CGameOptions.cpp index a20ed176..60263064 100644 --- a/src/MetroidPrime/Player/CGameOptions.cpp +++ b/src/MetroidPrime/Player/CGameOptions.cpp @@ -19,7 +19,7 @@ public: AssetIdSorter() {} bool operator()(const rstl::pair< CAssetId, CAssetId >& a, - const rstl::pair< CAssetId, CAssetId >& b) { + const rstl::pair< CAssetId, CAssetId >& b) const { return a.first < b.first; } }; diff --git a/src/MetroidPrime/ScriptObjects/CScriptSpecialFunction.cpp b/src/MetroidPrime/ScriptObjects/CScriptSpecialFunction.cpp index 29189590..7cafca5c 100644 --- a/src/MetroidPrime/ScriptObjects/CScriptSpecialFunction.cpp +++ b/src/MetroidPrime/ScriptObjects/CScriptSpecialFunction.cpp @@ -211,7 +211,7 @@ public: CRingSorter(CStateManager* mgr) : mgr(mgr) {} bool operator()(const CScriptSpecialFunction::SRingController& a, - const CScriptSpecialFunction::SRingController& b) { + const CScriptSpecialFunction::SRingController& b) const { const CActor* actA = TCastToConstPtr< CActor >(mgr->GetObjectById(a.x0_id)); const CActor* actB = TCastToConstPtr< CActor >(mgr->GetObjectById(b.x0_id)); if (actA && actB) {