| 1 | #include "Library/Area/AreaObjGroup.h" |
|---|---|
| 2 | |
| 3 | #include "Library/Area/AreaObj.h" |
| 4 | |
| 5 | namespace al { |
| 6 | AreaObjGroup::AreaObjGroup(const char* groupName, const s32 capacity) |
| 7 | : mGroupName(groupName), mCapacity(capacity) {} |
| 8 | |
| 9 | void AreaObjGroup::createBuffer() { |
| 10 | if (mCapacity < 1) |
| 11 | return; |
| 12 | mBuffer = new AreaObj*[mCapacity]; |
| 13 | } |
| 14 | |
| 15 | void AreaObjGroup::createBuffer(s32 capacity) { |
| 16 | mCapacity = capacity; |
| 17 | createBuffer(); |
| 18 | } |
| 19 | |
| 20 | AreaObj* AreaObjGroup::getAreaObj(const s32 index) const { |
| 21 | return mBuffer[index]; |
| 22 | } |
| 23 | |
| 24 | AreaObj* AreaObjGroup::getInVolumeAreaObj(const sead::Vector3f& position) const { |
| 25 | AreaObj* bestInVolumeAreaObj = nullptr; |
| 26 | for (s32 i = 0; i < mCount; i++) { |
| 27 | AreaObj* currentAreaObj = mBuffer[i]; |
| 28 | if (!bestInVolumeAreaObj || |
| 29 | bestInVolumeAreaObj->getPriority() <= currentAreaObj->getPriority()) { |
| 30 | if (currentAreaObj->isInVolume(pos: position)) |
| 31 | bestInVolumeAreaObj = currentAreaObj; |
| 32 | } |
| 33 | } |
| 34 | return bestInVolumeAreaObj; |
| 35 | } |
| 36 | |
| 37 | void AreaObjGroup::incrementCount() { |
| 38 | // BUG: dev mistake? |
| 39 | mCapacity += 1; |
| 40 | } |
| 41 | |
| 42 | void AreaObjGroup::registerAreaObj(AreaObj* newAreaObj) { |
| 43 | if (mCount >= mCapacity) |
| 44 | return; |
| 45 | mBuffer[mCount] = newAreaObj; |
| 46 | mCount += 1; |
| 47 | } |
| 48 | |
| 49 | } // namespace al |
| 50 |