[ox] Add StringView, Writer system, Preloader system

This commit is contained in:
2022-11-30 01:45:11 -06:00
parent 98f35140fe
commit cbb496c59f
64 changed files with 2343 additions and 417 deletions

View File

@@ -104,7 +104,7 @@ class MetalClawWriter {
template<typename T = std::nullptr_t>
constexpr void setTypeInfo(const char *name = T::TypeName, int version = T::TypeVersion,
int fields = ModelFieldCount_v<T>) noexcept;
const Vector<String>& = {}, int fields = ModelFieldCount_v<T>) noexcept;
[[nodiscard]]
constexpr std::size_t size() const noexcept;
@@ -135,10 +135,10 @@ class MetalClawWriter {
};
constexpr MetalClawWriter::MetalClawWriter(uint8_t *buff, std::size_t buffLen, int unionIdx) noexcept:
m_fieldPresence(buff, buffLen),
m_unionIdx(unionIdx),
m_buffLen(buffLen),
m_buff(buff) {
m_fieldPresence(buff, buffLen),
m_unionIdx(unionIdx),
m_buffLen(buffLen),
m_buff(buff) {
}
constexpr MetalClawWriter::~MetalClawWriter() noexcept {
@@ -330,7 +330,7 @@ constexpr Error MetalClawWriter::field(const char*, T *val, std::size_t len) noe
MetalClawWriter writer(m_buff + m_buffIt, m_buffLen - m_buffIt);
ModelHandlerInterface handler{&writer};
handler.setTypeInfo<T>("List", 0, len);
handler.setTypeInfo<T>("List", 0, {}, len);
// write the array
for (std::size_t i = 0; i < len; i++) {
@@ -363,7 +363,7 @@ constexpr Error MetalClawWriter::field(const char*, const HashMap<String, T> *va
MetalClawWriter writer(m_buff + m_buffIt, m_buffLen - m_buffIt);
ModelHandlerInterface handler{&writer};
// double len for both key and value
handler.setTypeInfo("Map", 0, len * 2);
handler.setTypeInfo("Map", 0, {}, len * 2);
// write the array
for (std::size_t i = 0; i < len; i++) {
const auto &key = keys[i];
@@ -388,7 +388,7 @@ constexpr Error MetalClawWriter::field(const char *name, HashMap<String, T> *val
}
template<typename T>
constexpr void MetalClawWriter::setTypeInfo(const char*, int, int fields) noexcept {
constexpr void MetalClawWriter::setTypeInfo(const char*, int, const Vector<String>&, int fields) noexcept {
m_fields = fields;
m_fieldPresence.setFields(fields);
m_buffIt = static_cast<std::size_t>(m_fieldPresence.getMaxLen());