summaryrefslogtreecommitdiff
path: root/src/KingSystem/Ecosystem/ecoSystem.cpp
diff options
context:
space:
mode:
authorLéo Lam <leo@leolam.fr>2021-11-23 23:13:40 +0100
committerLéo Lam <leo@leolam.fr>2021-11-24 01:30:23 +0100
commit022f029db1ef03d900fb54bad0807939c9695720 (patch)
tree8eb3db08a4e88a1f0ef58153fcce287b7f9386f3 /src/KingSystem/Ecosystem/ecoSystem.cpp
parent8ac282db2a1523bc2d1c8b76addccb6927edaa4e (diff)
ksys/eco: Match Ecosystem::getMapArea
Diffstat (limited to 'src/KingSystem/Ecosystem/ecoSystem.cpp')
-rw-r--r--src/KingSystem/Ecosystem/ecoSystem.cpp32
1 files changed, 13 insertions, 19 deletions
diff --git a/src/KingSystem/Ecosystem/ecoSystem.cpp b/src/KingSystem/Ecosystem/ecoSystem.cpp
index fd08443c..7a5f2156 100644
--- a/src/KingSystem/Ecosystem/ecoSystem.cpp
+++ b/src/KingSystem/Ecosystem/ecoSystem.cpp
@@ -48,7 +48,7 @@ SEAD_SINGLETON_DISPOSER_IMPL(Ecosystem)
static void setEcoMapInfo(EcoMapInfo& info, const u8* data) {
info.mHeader = reinterpret_cast<const EcoMapHeader*>(data);
- info.mRowOffsets = reinterpret_cast<const u32*>(info.mHeader + 1);
+ info.mRowOffsets = reinterpret_cast<const s32*>(info.mHeader + 1);
info.mRows =
reinterpret_cast<const char*>(info.mRowOffsets) + sizeof(int) * info.mHeader->num_rows;
}
@@ -97,41 +97,35 @@ void Ecosystem::init(sead::Heap* heap) {
void Ecosystem::calc() {}
-// FP instructions rearranged.
-#ifdef NON_MATCHING
s32 Ecosystem::getMapArea(const EcoMapInfo& info, f32 posX, f32 posZ) const {
- posX = sead::Mathf::clamp(posX, -5000.0F, 4999.0F);
- posZ = sead::Mathf::clamp(posZ, -4000.0F, 4000.0F);
- f32 epsilon1 = (posX + 5000.0F >= 0.0F) ? 0.5F : -0.5F;
- f32 epsilon2 = (posZ + 4000.0F >= 0.0F) ? 0.5F : -0.5F;
- s32 x = posX + 5000.0F + epsilon1;
- s32 z = (posZ + 4000.0F + epsilon2) / info.mHeader->divisor;
+ posX = sead::Mathf::clamp(posX, -5000.0f, 4999.0f);
+ posZ = sead::Mathf::clamp(posZ, -4000.0f, 4000.0f);
+
+ const auto epsilon = [](float n) { return n >= 0.0f ? 0.5f : -0.5f; };
+ s32 x = s32(posX + 5000.0f + epsilon(posX + 5000.0f));
+ s32 z = s32(posZ + 4000.0f + epsilon(posZ + 4000.0f)) / info.mHeader->divisor;
s32 row = sead::Mathi::clamp(z, 0, info.mHeader->num_rows - 2);
if (info.mHeader->divisor == 10)
- x = x / 10;
+ x /= 10;
- s32* offsets = (s32*)info.mRowOffsets + row;
- s32 val0 = offsets[0];
- s32 val1 = offsets[1];
-
- if (val0 >= val1)
+ if (info.mRowOffsets[row] >= info.mRowOffsets[row + 1])
return -1;
- auto* segmentEnd = reinterpret_cast<const Segment*>(info.mRows + 2 * val1);
- auto* segment = reinterpret_cast<const Segment*>(info.mRows + 2 * val0);
+ auto* segmentEnd = reinterpret_cast<const Segment*>(info.mRows + 2 * info.mRowOffsets[row + 1]);
+ auto* segment = reinterpret_cast<const Segment*>(info.mRows + 2 * info.mRowOffsets[row]);
s32 totalLength = 0;
while (true) {
totalLength += segment->length;
if (x < totalLength)
- return segment->value;
+ break;
++segment;
if (segment >= segmentEnd)
return -1;
}
+ return segment->value;
}
-#endif
void Ecosystem::getAreaItems(s32 areaNum, AreaItemType type, AreaItemSet* out) const {
out->count = 0;