summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLéo Lam <leo@leolam.fr>2020-10-15 22:31:45 +0200
committerLéo Lam <leo@leolam.fr>2020-10-16 00:06:18 +0200
commitdbaac9cb7834f7408287df9ef833175aa1d43bc9 (patch)
tree8ebdd38b5d6eeccccc7e928693264fcdef52b6cf /src
parent2d721f8969bfc06a7b1c21024477f7621a5f2d79 (diff)
ksys/act: Add InstParamPack
Diffstat (limited to 'src')
-rw-r--r--src/KingSystem/ActorSystem/CMakeLists.txt2
-rw-r--r--src/KingSystem/ActorSystem/actInstParamPack.cpp79
-rw-r--r--src/KingSystem/ActorSystem/actInstParamPack.h110
3 files changed, 191 insertions, 0 deletions
diff --git a/src/KingSystem/ActorSystem/CMakeLists.txt b/src/KingSystem/ActorSystem/CMakeLists.txt
index a7a5b4f4..4e59d0cc 100644
--- a/src/KingSystem/ActorSystem/CMakeLists.txt
+++ b/src/KingSystem/ActorSystem/CMakeLists.txt
@@ -31,5 +31,7 @@ target_sources(uking PRIVATE
actBaseProcMgr.h
actBaseProcUnit.cpp
actBaseProcUnit.h
+ actInstParamPack.cpp
+ actInstParamPack.h
actTag.h
)
diff --git a/src/KingSystem/ActorSystem/actInstParamPack.cpp b/src/KingSystem/ActorSystem/actInstParamPack.cpp
new file mode 100644
index 00000000..566cb7be
--- /dev/null
+++ b/src/KingSystem/ActorSystem/actInstParamPack.cpp
@@ -0,0 +1,79 @@
+#include "KingSystem/ActorSystem/actInstParamPack.h"
+#include <prim/seadMemUtil.h>
+
+namespace ksys::act {
+
+void InstParamPack::Buffer::clear() {
+ mNumItems = 0;
+ mPosition = 0;
+ mData.fill(0);
+}
+
+// NON_MATCHING: write()
+void InstParamPack::Buffer::add(const void* data, const sead::SafeString& name, s32 byte_size,
+ InstParamPack::EntryType type) {
+ if (byte_size + mPosition + u32(sizeof(const char*)) + 1 > mData.getByteSize()) {
+ SEAD_ASSERT_MSG(false, "InstParamPack::Buffer::add: Buffer overflow");
+ return;
+ }
+
+ write(name.cstr());
+ write(u8(type));
+ writeBytes(data, byte_size);
+ ++mNumItems;
+}
+
+// NON_MATCHING: write()
+void InstParamPack::Buffer::add(ActorCallback* callback, const sead::SafeString& name) {
+ add(callback, name, sizeof(callback), EntryType::UInt64);
+}
+
+// NON_MATCHING
+bool InstParamPack::Buffer::pop(s32* position, InstParamPack::Entry* out_entry) {
+ if (!read(out_entry->key, position))
+ return false;
+
+ if (!read(out_entry->type.mValue, position))
+ return false;
+
+ switch (out_entry->type) {
+ case EntryType::Int:
+ return read(out_entry->data.i, position);
+ case EntryType::_1:
+ return read(out_entry->data.type1, position);
+ case EntryType::Float:
+ return read(out_entry->data.f, position);
+ case EntryType::Bool:
+ return read(out_entry->data.b, position);
+ case EntryType::Vec3:
+ return read(out_entry->data.vec3, position);
+ case EntryType::String: {
+ const s32 start_pos = *position;
+ char c;
+ do {
+ if (!read(c, position)) {
+ out_entry->data.str = nullptr;
+ return false;
+ }
+ } while (c != sead::SafeString::cNullChar);
+ out_entry->data.str = reinterpret_cast<const char*>(&mData[start_pos]);
+ return true;
+ }
+ case EntryType::UInt64:
+ return read(out_entry->data.l, position);
+ case EntryType::Matrix34:
+ return read(out_entry->data.mtx34, position);
+ default:
+ return false;
+ }
+}
+
+InstParamPack::Buffer& InstParamPack::Buffer::operator=(const InstParamPack::Buffer& other) {
+ size_t pos = other.mPosition;
+ mPosition = pos;
+ mNumItems = other.mNumItems;
+ sead::MemUtil::copy(mData.getBufferPtr(), other.mData.getBufferPtr(), pos);
+ return *this;
+}
+
+} // namespace ksys::act
diff --git a/src/KingSystem/ActorSystem/actInstParamPack.h b/src/KingSystem/ActorSystem/actInstParamPack.h
new file mode 100644
index 00000000..dbb5d868
--- /dev/null
+++ b/src/KingSystem/ActorSystem/actInstParamPack.h
@@ -0,0 +1,110 @@
+#pragma once
+
+#include <basis/seadTypes.h>
+#include <container/seadSafeArray.h>
+#include <math/seadMatrix.h>
+#include <math/seadVector.h>
+#include <prim/seadDelegate.h>
+#include <prim/seadMemUtil.h>
+#include <prim/seadSafeString.h>
+#include <prim/seadSizedEnum.h>
+#include "KingSystem/Utils/Types.h"
+
+namespace ksys::act {
+
+class BaseProc;
+
+class InstParamPack {
+public:
+ enum class EntryType {
+ /// Signed(?) 32-bit integer.
+ Int = 0,
+ /// Unknown.
+ _1 = 1,
+ /// Single-precision float.
+ Float = 2,
+ /// Boolean.
+ Bool = 3,
+ /// Vector3f.
+ Vec3 = 4,
+ /// String (stored inline).
+ String = 5,
+ /// Unsigned 64-bit integer. Can be used to store pointers.
+ UInt64 = 6,
+ /// 3x4 matrix (sead::Matrix34).
+ Matrix34 = 7,
+ };
+
+ using ActorCallback = sead::IDelegate1<BaseProc*>;
+
+ struct Entry {
+ union Data {
+ s32 i;
+ f32 f;
+ u32 type1;
+ u64 l;
+ bool b;
+ sead::Vector3f vec3;
+ sead::Matrix34f mtx34;
+ const char* str;
+ ActorCallback* cb;
+ };
+ KSYS_CHECK_SIZE_NX150(Data, 0x30);
+
+ const char* key;
+ sead::SizedEnum<EntryType, s8> type;
+ Data data;
+ };
+ KSYS_CHECK_SIZE_NX150(Entry, 0x40);
+
+ class Buffer {
+ public:
+ Buffer() { clear(); }
+ Buffer& operator=(const Buffer& other);
+
+ void clear();
+ void add(const void* data, const sead::SafeString& name, s32 byte_size, EntryType type);
+ void add(ActorCallback* callback, const sead::SafeString& name);
+
+ bool pop(s32* position, Entry* out_entry);
+
+ private:
+ void writeBytes(const void* value, s32 size) {
+ sead::MemUtil::copy(&mData[mPosition], value, size);
+ mPosition += size;
+ }
+
+ template <typename T>
+ void write(const T& value) {
+ writeBytes(&value, sizeof(value));
+ }
+
+ template <typename T>
+ bool read(T& value, s32* position) {
+ if (*position + s32(sizeof(T)) > mData.size())
+ return false;
+
+ sead::MemUtil::copy(&value, &mData[*position], sizeof(T));
+ *position += s32(sizeof(T));
+ return true;
+ }
+
+ u16 mNumItems;
+ s16 mPosition;
+ sead::SafeArray<u8, 0xc0> mData;
+ };
+ KSYS_CHECK_SIZE_NX150(Buffer, 0xc4);
+
+ InstParamPack() = default;
+ virtual ~InstParamPack() = default;
+
+ Buffer& getBuffer() { return mBuffer; }
+ const Buffer& getBuffer() const { return mBuffer; }
+
+private:
+ BaseProc* mProc = nullptr;
+ Buffer mBuffer;
+};
+KSYS_CHECK_SIZE_NX150(InstParamPack, 0xd8);
+
+} // namespace ksys::act