mirror of https://github.com/AxioDL/metaforce.git
CWorld: Make use of std::find_if in IGetAreaId
Removes explicit mutable state. This can be further simplified in the future with ranges.
This commit is contained in:
parent
655805ffcb
commit
86b94ad915
|
@ -1,5 +1,8 @@
|
|||
#include "Runtime/World/CWorld.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
|
||||
#include "Runtime/CGameState.hpp"
|
||||
#include "Runtime/CInGameTweakManagerBase.hpp"
|
||||
#include "Runtime/CSimplePool.hpp"
|
||||
|
@ -44,17 +47,19 @@ const IGameArea* CDummyWorld::IGetAreaAlways(TAreaId id) const { return &x18_are
|
|||
TAreaId CDummyWorld::IGetCurrentAreaId() const { return x3c_curAreaId; }
|
||||
|
||||
TAreaId CDummyWorld::IGetAreaId(CAssetId id) const {
|
||||
int ret = 0;
|
||||
if (!id.IsValid())
|
||||
if (!id.IsValid()) {
|
||||
return kInvalidAreaId;
|
||||
for (const CDummyGameArea& area : x18_areas) {
|
||||
if (area.xc_mrea == id)
|
||||
return ret;
|
||||
++ret;
|
||||
}
|
||||
|
||||
const auto iter =
|
||||
std::find_if(x18_areas.cbegin(), x18_areas.cend(), [id](const auto& area) { return area->xc_mrea == id; });
|
||||
if (iter == x18_areas.cend()) {
|
||||
return kInvalidAreaId;
|
||||
}
|
||||
|
||||
return TAreaId(std::distance(x18_areas.cbegin(), iter));
|
||||
}
|
||||
|
||||
CWorld::CRelay::CRelay(CInputStream& in) {
|
||||
x0_relay = in.readUint32Big();
|
||||
x4_target = in.readUint32Big();
|
||||
|
@ -226,17 +231,19 @@ const IGameArea* CWorld::IGetAreaAlways(TAreaId id) const { return GetAreaAlways
|
|||
TAreaId CWorld::IGetCurrentAreaId() const { return x68_curAreaId; }
|
||||
|
||||
TAreaId CWorld::IGetAreaId(CAssetId id) const {
|
||||
int ret = 0;
|
||||
if (!id.IsValid())
|
||||
if (!id.IsValid()) {
|
||||
return kInvalidAreaId;
|
||||
for (const std::unique_ptr<CGameArea>& area : x18_areas) {
|
||||
if (area->x84_mrea == id)
|
||||
return ret;
|
||||
++ret;
|
||||
}
|
||||
|
||||
const auto iter =
|
||||
std::find_if(x18_areas.cbegin(), x18_areas.cend(), [id](const auto& area) { return area->x84_mrea == id; });
|
||||
if (iter == x18_areas.cend()) {
|
||||
return kInvalidAreaId;
|
||||
}
|
||||
|
||||
return TAreaId(std::distance(x18_areas.cbegin(), iter));
|
||||
}
|
||||
|
||||
void CWorld::MoveToChain(CGameArea* area, EChain chain) {
|
||||
if (area->x138_curChain == chain) {
|
||||
return;
|
||||
|
|
Loading…
Reference in New Issue