2018-10-07 03:42:33 +00:00
|
|
|
#pragma once
|
2015-08-17 20:33:58 +00:00
|
|
|
|
2017-10-25 07:47:49 +00:00
|
|
|
#include <functional>
|
2019-09-28 02:53:03 +00:00
|
|
|
#include <optional>
|
|
|
|
#include <string>
|
|
|
|
#include <utility>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "Runtime/GCNTypes.hpp"
|
|
|
|
#include "Runtime/IOStreams.hpp"
|
|
|
|
#include "Runtime/rstl.hpp"
|
|
|
|
|
|
|
|
#include <hecl/hecl.hpp>
|
|
|
|
#include <zeus/CMatrix3f.hpp>
|
|
|
|
#include <zeus/CMatrix4f.hpp>
|
|
|
|
#include <zeus/CTransform.hpp>
|
|
|
|
#include <zeus/CVector2f.hpp>
|
|
|
|
#include <zeus/CVector3f.hpp>
|
2015-08-17 20:33:58 +00:00
|
|
|
|
2017-12-30 01:09:45 +00:00
|
|
|
#undef min
|
|
|
|
#undef max
|
|
|
|
|
2017-11-24 08:23:28 +00:00
|
|
|
using namespace std::literals;
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
namespace urde {
|
2015-08-17 22:05:00 +00:00
|
|
|
|
2016-03-04 23:04:53 +00:00
|
|
|
using FourCC = hecl::FourCC;
|
2017-08-13 05:26:14 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
class CAssetId {
|
|
|
|
u64 id = UINT64_MAX;
|
|
|
|
|
2017-08-13 05:26:14 +00:00
|
|
|
public:
|
2019-09-30 12:58:32 +00:00
|
|
|
constexpr CAssetId() noexcept = default;
|
|
|
|
constexpr CAssetId(u64 v) noexcept { Assign(v); }
|
2018-12-08 05:30:43 +00:00
|
|
|
explicit CAssetId(CInputStream& in);
|
2019-09-30 12:58:32 +00:00
|
|
|
constexpr bool IsValid() const noexcept { return id != UINT64_MAX; }
|
|
|
|
constexpr u64 Value() const noexcept { return id; }
|
|
|
|
constexpr void Assign(u64 v) noexcept { id = (v == UINT32_MAX ? UINT64_MAX : (v == 0 ? UINT64_MAX : v)); }
|
|
|
|
constexpr void Reset() noexcept { id = UINT64_MAX; }
|
2018-12-08 05:30:43 +00:00
|
|
|
void PutTo(COutputStream& out);
|
2019-09-30 12:58:32 +00:00
|
|
|
constexpr bool operator==(const CAssetId& other) const noexcept { return id == other.id; }
|
|
|
|
constexpr bool operator!=(const CAssetId& other) const noexcept { return !operator==(other); }
|
|
|
|
constexpr bool operator<(const CAssetId& other) const noexcept { return id < other.id; }
|
2017-08-13 05:26:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//#define kInvalidAssetId CAssetId()
|
2015-08-23 06:42:29 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
struct SObjectTag {
|
|
|
|
FourCC type;
|
|
|
|
CAssetId id;
|
|
|
|
|
2019-09-30 13:00:15 +00:00
|
|
|
constexpr explicit operator bool() const noexcept { return id.IsValid(); }
|
2019-09-30 12:58:32 +00:00
|
|
|
constexpr bool operator==(const SObjectTag& other) const noexcept { return id == other.id; }
|
|
|
|
constexpr bool operator!=(const SObjectTag& other) const noexcept { return !operator==(other); }
|
|
|
|
constexpr bool operator<(const SObjectTag& other) const noexcept { return id < other.id; }
|
|
|
|
constexpr SObjectTag() noexcept = default;
|
|
|
|
constexpr SObjectTag(FourCC tp, CAssetId rid) noexcept : type(tp), id(rid) {}
|
2018-12-08 05:30:43 +00:00
|
|
|
SObjectTag(CInputStream& in) {
|
|
|
|
in.readBytesToBuf(&type, 4);
|
|
|
|
id = CAssetId(in);
|
|
|
|
}
|
|
|
|
void readMLVL(CInputStream& in) {
|
|
|
|
id = CAssetId(in);
|
|
|
|
in.readBytesToBuf(&type, 4);
|
|
|
|
}
|
2015-08-22 01:58:41 +00:00
|
|
|
};
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
struct TEditorId {
|
|
|
|
u32 id = u32(-1);
|
2019-08-14 09:15:08 +00:00
|
|
|
|
2019-09-30 12:58:32 +00:00
|
|
|
constexpr TEditorId() noexcept = default;
|
|
|
|
constexpr TEditorId(u32 idin) noexcept : id(idin) {}
|
|
|
|
constexpr u8 LayerNum() const noexcept { return u8((id >> 26) & 0x3f); }
|
|
|
|
constexpr u16 AreaNum() const noexcept { return u16((id >> 16) & 0x3ff); }
|
|
|
|
constexpr u16 Id() const noexcept { return u16(id & 0xffff); }
|
|
|
|
constexpr bool operator<(const TEditorId& other) const noexcept { return (id & 0x3ffffff) < (other.id & 0x3ffffff); }
|
|
|
|
constexpr bool operator==(const TEditorId& other) const noexcept {
|
|
|
|
return (id & 0x3ffffff) == (other.id & 0x3ffffff);
|
|
|
|
}
|
|
|
|
constexpr bool operator!=(const TEditorId& other) const noexcept { return !operator==(other); }
|
2016-08-14 03:00:58 +00:00
|
|
|
};
|
2017-10-25 07:47:49 +00:00
|
|
|
|
2017-08-13 05:26:14 +00:00
|
|
|
#define kInvalidEditorId TEditorId()
|
2016-08-14 03:00:58 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
struct TUniqueId {
|
|
|
|
u16 id = u16(-1);
|
2019-08-14 09:15:08 +00:00
|
|
|
|
2019-09-30 12:58:32 +00:00
|
|
|
constexpr TUniqueId() noexcept = default;
|
|
|
|
constexpr TUniqueId(u16 value, u16 version) noexcept : id(value | (version << 10)) {}
|
|
|
|
constexpr u16 Version() const noexcept { return u16((id >> 10) & 0x3f); }
|
|
|
|
constexpr u16 Value() const noexcept { return u16(id & 0x3ff); }
|
|
|
|
constexpr bool operator<(const TUniqueId& other) const noexcept { return id < other.id; }
|
|
|
|
constexpr bool operator==(const TUniqueId& other) const noexcept { return id == other.id; }
|
|
|
|
constexpr bool operator!=(const TUniqueId& other) const noexcept { return !operator==(other); }
|
2017-08-10 13:40:07 +00:00
|
|
|
};
|
|
|
|
|
2017-08-13 05:26:14 +00:00
|
|
|
#define kInvalidUniqueId TUniqueId()
|
|
|
|
|
2017-01-15 03:59:37 +00:00
|
|
|
using TAreaId = s32;
|
|
|
|
|
2015-08-20 02:52:07 +00:00
|
|
|
#define kInvalidAreaId TAreaId(-1)
|
|
|
|
|
2016-09-10 04:50:00 +00:00
|
|
|
#if 0
|
|
|
|
template <class T, size_t N>
|
|
|
|
class TRoundRobin
|
|
|
|
{
|
|
|
|
rstl::reserved_vector<T, N> vals;
|
|
|
|
|
|
|
|
public:
|
|
|
|
TRoundRobin(const T& val) : vals(N, val) {}
|
|
|
|
|
|
|
|
void PushBack(const T& val) { vals.push_back(val); }
|
|
|
|
|
|
|
|
size_t Size() const { return vals.size(); }
|
|
|
|
|
|
|
|
const T& GetLastValue() const { return vals.back(); }
|
|
|
|
|
|
|
|
void Clear() { vals.clear(); }
|
|
|
|
|
|
|
|
const T& GetValue(s32) const {}
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
template <class T>
|
2019-09-30 12:58:32 +00:00
|
|
|
T GetAverage(const T* v, s32 count) noexcept {
|
2018-12-08 05:30:43 +00:00
|
|
|
T r = v[0];
|
|
|
|
for (s32 i = 1; i < count; ++i)
|
|
|
|
r += v[i];
|
2016-09-25 16:45:22 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
return r / count;
|
2016-09-25 16:45:22 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
template <class T, size_t N>
|
|
|
|
class TReservedAverage : rstl::reserved_vector<T, N> {
|
2016-09-16 22:21:19 +00:00
|
|
|
public:
|
2018-12-08 05:30:43 +00:00
|
|
|
TReservedAverage() = default;
|
2016-09-16 22:21:19 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
TReservedAverage(const T& t) { rstl::reserved_vector<T, N>::resize(N, t); }
|
2016-09-25 16:45:22 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void AddValue(const T& t) {
|
|
|
|
if (this->size() < N) {
|
|
|
|
this->insert(this->begin(), t);
|
|
|
|
} else {
|
|
|
|
this->pop_back();
|
|
|
|
this->insert(this->begin(), t);
|
2016-09-16 22:21:19 +00:00
|
|
|
}
|
2019-06-19 21:11:13 +00:00
|
|
|
}
|
2016-09-16 22:21:19 +00:00
|
|
|
|
2019-06-12 02:05:17 +00:00
|
|
|
std::optional<T> GetAverage() const {
|
2018-12-08 05:30:43 +00:00
|
|
|
if (this->empty())
|
|
|
|
return {};
|
|
|
|
|
|
|
|
return {urde::GetAverage<T>(this->data(), this->size())};
|
|
|
|
}
|
2017-07-31 05:19:05 +00:00
|
|
|
|
2019-06-12 02:05:17 +00:00
|
|
|
std::optional<T> GetEntry(int i) const {
|
2018-12-08 05:30:43 +00:00
|
|
|
if (i >= this->size())
|
|
|
|
return {};
|
|
|
|
return this->operator[](i);
|
|
|
|
}
|
2017-09-30 03:45:57 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void Clear() { this->clear(); }
|
|
|
|
|
|
|
|
size_t Size() const { return this->size(); }
|
2016-09-25 16:45:22 +00:00
|
|
|
};
|
2016-09-16 22:21:19 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
} // namespace urde
|
2017-10-25 07:47:49 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
namespace std {
|
2016-09-10 04:50:00 +00:00
|
|
|
template <>
|
2018-12-08 05:30:43 +00:00
|
|
|
struct hash<urde::SObjectTag> {
|
|
|
|
size_t operator()(const urde::SObjectTag& tag) const noexcept { return tag.id.Value(); }
|
2017-08-13 05:26:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
2018-12-08 05:30:43 +00:00
|
|
|
struct hash<urde::CAssetId> {
|
|
|
|
size_t operator()(const urde::CAssetId& id) const noexcept { return id.Value(); }
|
2015-08-23 06:42:29 +00:00
|
|
|
};
|
2018-12-08 05:30:43 +00:00
|
|
|
} // namespace std
|
2019-04-07 05:14:48 +00:00
|
|
|
|
2019-07-28 01:21:31 +00:00
|
|
|
FMT_CUSTOM_FORMATTER(urde::CAssetId, "{:08X}", obj.Value())
|
|
|
|
FMT_CUSTOM_FORMATTER(urde::TEditorId, "{:08X}", obj.id)
|
|
|
|
FMT_CUSTOM_FORMATTER(urde::TUniqueId, "{:04X}", obj.id)
|
|
|
|
FMT_CUSTOM_FORMATTER(urde::SObjectTag, "{} {}", obj.type, obj.id)
|
|
|
|
|
|
|
|
FMT_CUSTOM_FORMATTER(zeus::CVector3f, "({} {} {})", float(obj.x()), float(obj.y()), float(obj.z()))
|
|
|
|
FMT_CUSTOM_FORMATTER(zeus::CVector2f, "({} {})", float(obj.x()), float(obj.y()))
|
|
|
|
FMT_CUSTOM_FORMATTER(zeus::CMatrix3f, "\n({} {} {})"
|
|
|
|
"\n({} {} {})"
|
|
|
|
"\n({} {} {})",
|
2019-07-20 04:27:21 +00:00
|
|
|
float(obj[0][0]), float(obj[1][0]), float(obj[2][0]),
|
|
|
|
float(obj[0][1]), float(obj[1][1]), float(obj[2][1]),
|
|
|
|
float(obj[0][2]), float(obj[1][2]), float(obj[2][2]))
|
2019-07-28 01:21:31 +00:00
|
|
|
FMT_CUSTOM_FORMATTER(zeus::CMatrix4f, "\n({} {} {} {})"
|
|
|
|
"\n({} {} {} {})"
|
|
|
|
"\n({} {} {} {})"
|
|
|
|
"\n({} {} {} {})",
|
2019-07-20 04:27:21 +00:00
|
|
|
float(obj[0][0]), float(obj[1][0]), float(obj[2][0]), float(obj[3][0]),
|
|
|
|
float(obj[0][1]), float(obj[1][1]), float(obj[2][1]), float(obj[3][1]),
|
|
|
|
float(obj[0][2]), float(obj[1][2]), float(obj[2][2]), float(obj[3][2]),
|
|
|
|
float(obj[0][3]), float(obj[1][3]), float(obj[2][3]), float(obj[3][3]))
|
2019-07-28 01:21:31 +00:00
|
|
|
FMT_CUSTOM_FORMATTER(zeus::CTransform, "\n({} {} {} {})"
|
|
|
|
"\n({} {} {} {})"
|
|
|
|
"\n({} {} {} {})",
|
2019-07-20 04:27:21 +00:00
|
|
|
float(obj.basis[0][0]), float(obj.basis[1][0]), float(obj.basis[2][0]), float(obj.origin[0]),
|
|
|
|
float(obj.basis[0][1]), float(obj.basis[1][1]), float(obj.basis[2][1]), float(obj.origin[1]),
|
|
|
|
float(obj.basis[0][2]), float(obj.basis[1][2]), float(obj.basis[2][2]), float(obj.origin[2]))
|
|
|
|
|
2019-04-07 05:14:48 +00:00
|
|
|
#if defined(__has_feature)
|
|
|
|
#if __has_feature(memory_sanitizer)
|
|
|
|
#define URDE_MSAN 1
|
|
|
|
#endif
|
|
|
|
#endif
|