summaryrefslogtreecommitdiff
path: root/src/KingSystem/Physics/System/physLayerContactPointInfo.cpp
diff options
context:
space:
mode:
authorLéo Lam <leo@leolam.fr>2022-03-02 01:18:25 +0100
committerLéo Lam <leo@leolam.fr>2022-03-02 01:25:11 +0100
commitb2a66ca8586d435dc417d0d9aa65e6b445fe9855 (patch)
treeef64560ad069e99e7773ab905671222b3b8ea163 /src/KingSystem/Physics/System/physLayerContactPointInfo.cpp
parent220cb534689303a2ef4df51a41b6142cfe9b7ee2 (diff)
ksys/phys: ContactPointInfoEx -> ContactLayerContactPointInfo
Turns out it's the equivalent to ContactLayerCollisionInfo.
Diffstat (limited to 'src/KingSystem/Physics/System/physLayerContactPointInfo.cpp')
-rw-r--r--src/KingSystem/Physics/System/physLayerContactPointInfo.cpp112
1 files changed, 112 insertions, 0 deletions
diff --git a/src/KingSystem/Physics/System/physLayerContactPointInfo.cpp b/src/KingSystem/Physics/System/physLayerContactPointInfo.cpp
new file mode 100644
index 00000000..881b4d08
--- /dev/null
+++ b/src/KingSystem/Physics/System/physLayerContactPointInfo.cpp
@@ -0,0 +1,112 @@
+#include "KingSystem/Physics/System/physLayerContactPointInfo.h"
+#include "KingSystem/Physics/System/physContactMgr.h"
+#include "KingSystem/Physics/System/physSystem.h"
+
+namespace ksys::phys {
+
+LayerContactPointInfo* LayerContactPointInfo::make(sead::Heap* heap, int num, int num2,
+ const sead::SafeString& name, int a, int b,
+ int c) {
+ return System::instance()->allocLayerContactPointInfo(heap, num, num2, name, a, b, c);
+}
+
+void LayerContactPointInfo::free(LayerContactPointInfo* instance) {
+ System::instance()->freeLayerContactPointInfo(instance);
+}
+
+bool LayerContactPointInfo::registerLayerPair(ContactLayer layer1, ContactLayer layer2,
+ bool enabled) {
+ if (mLayerType == ContactLayerType::Invalid)
+ mLayerType = getContactLayerType(layer1);
+
+ if (!isPairUnknown(layer1, layer2))
+ return false;
+
+ // Add a new one.
+ auto* entry = mLayerEntries.emplaceBack();
+ if (entry == nullptr)
+ return false;
+
+ entry->layer1 = layer1;
+ entry->layer2 = layer2;
+ entry->enabled = enabled;
+ [&] { System::instance()->registerContactPointLayerPair(this, layer1, layer2, enabled); }();
+ return true;
+}
+
+bool LayerContactPointInfo::isPairUnknown(ContactLayer layer1, ContactLayer layer2) const {
+ for (int i = 0; i < mLayerEntries.size(); ++i) {
+ const auto* entry = mLayerEntries[i];
+ if (int(layer1) == entry->layer1 && int(layer2) == entry->layer2)
+ return false;
+ if (int(layer1) == entry->layer2 && int(layer2) == entry->layer1)
+ return false;
+ }
+ return true;
+}
+
+LayerContactPointInfo::LayerContactPointInfo(const sead::SafeString& name, int a, int b, int c)
+ : ContactPointInfoBase(name, a, b, c) {}
+
+LayerContactPointInfo::~LayerContactPointInfo() = default;
+
+void LayerContactPointInfo::allocPoints(sead::Heap* heap, int num, int num2) {
+ mPoints.allocBufferAssert(num, heap);
+ mLayerEntries.allocBuffer(num2, heap);
+}
+
+void LayerContactPointInfo::freePoints() {
+ mPoints.freeBuffer();
+ mLayerEntries.freeBuffer();
+}
+
+void LayerContactPointInfo::Iterator::getData(sead::Vector3f* out,
+ LayerContactPointInfo::Iterator::Mode mode) const {
+ const float scale = getPoint()->scale;
+ out->e = getPoint()->_10.e;
+
+ switch (mode) {
+ case Mode::_0: {
+ if (getPoint()->flags.isOn(ContactPoint::Flag::_2))
+ return;
+ *out += getPoint()->_1c * -scale;
+ break;
+ }
+
+ case Mode::_1: {
+ if (!getPoint()->flags.isOn(ContactPoint::Flag::_2))
+ return;
+ *out += getPoint()->_1c * scale;
+ break;
+ }
+
+ case Mode::_2:
+ default: {
+ *out += getPoint()->_1c * scale * 0.5f;
+ break;
+ }
+ }
+}
+
+sead::Vector3f
+LayerContactPointInfo::Iterator::getData(LayerContactPointInfo::Iterator::Mode mode) const {
+ sead::Vector3f out;
+ getData(&out, mode);
+ return out;
+}
+
+LayerContactPointInfo::Iterator::Iterator(const LayerContactPointInfo::Points& points, int count)
+ : mPoints(points.getBufferPtr()), mPointsNum(count), mPointsStart(points.getBufferPtr()) {
+ for (int i = 0; i != count; ++i) {
+ if (!mPoints[i]->flags.isOn(ContactPoint::Flag::_1))
+ break;
+ ++mIdx;
+ }
+}
+
+LayerContactPointInfo::IteratorEnd::IteratorEnd(const LayerContactPointInfo::Points& points,
+ int count)
+ : mIdx(count), mPoints(points.getBufferPtr()), mPointsNum(count),
+ mPointsStart(points.getBufferPtr()) {}
+
+} // namespace ksys::phys