Compare commits
No commits in common. "cd60c4abaf8955400fb93ed417ab10b545d046e0" and "17f28d43d12c12389d409fec1c7e322af5335855" have entirely different histories.
cd60c4abaf
...
17f28d43d1
17
deps/ox/src/ox/std/hashmap.hpp
vendored
17
deps/ox/src/ox/std/hashmap.hpp
vendored
@ -133,18 +133,17 @@ constexpr HashMap<K, T> &HashMap<K, T>::operator=(HashMap<K, T> &&other) noexcep
|
|||||||
|
|
||||||
template<typename K, typename T>
|
template<typename K, typename T>
|
||||||
constexpr T &HashMap<K, T>::operator[](MaybeView_t<K> const&k) {
|
constexpr T &HashMap<K, T>::operator[](MaybeView_t<K> const&k) {
|
||||||
auto p = &access(m_pairs, k);
|
auto &p = access(m_pairs, k);
|
||||||
if (*p == nullptr) {
|
if (p == nullptr) {
|
||||||
if (static_cast<double>(m_pairs.size()) * 0.7 <
|
if (static_cast<double>(m_pairs.size()) * 0.7 <
|
||||||
static_cast<double>(m_keys.size())) {
|
static_cast<double>(m_keys.size())) {
|
||||||
expand();
|
expand();
|
||||||
p = &access(m_pairs, k);
|
|
||||||
}
|
}
|
||||||
*p = new Pair;
|
p = new Pair;
|
||||||
(*p)->key = k;
|
p->key = k;
|
||||||
m_keys.emplace_back(k);
|
m_keys.emplace_back(k);
|
||||||
}
|
}
|
||||||
return (*p)->value;
|
return p->value;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename K, typename T>
|
template<typename K, typename T>
|
||||||
@ -209,7 +208,7 @@ constexpr void HashMap<K, T>::clear() {
|
|||||||
|
|
||||||
template<typename K, typename T>
|
template<typename K, typename T>
|
||||||
constexpr void HashMap<K, T>::expand() {
|
constexpr void HashMap<K, T>::expand() {
|
||||||
Vector<Pair*> r(m_pairs.size() * 2);
|
Vector<Pair*> r;
|
||||||
for (std::size_t i = 0; i < m_keys.size(); ++i) {
|
for (std::size_t i = 0; i < m_keys.size(); ++i) {
|
||||||
auto const&k = m_keys[i];
|
auto const&k = m_keys[i];
|
||||||
access(r, k) = std::move(access(m_pairs, k));
|
access(r, k) = std::move(access(m_pairs, k));
|
||||||
@ -222,7 +221,7 @@ template<typename KK>
|
|||||||
constexpr typename HashMap<K, T>::Pair *const&HashMap<K, T>::access(Vector<Pair*> const&pairs, KK const&k) const {
|
constexpr typename HashMap<K, T>::Pair *const&HashMap<K, T>::access(Vector<Pair*> const&pairs, KK const&k) const {
|
||||||
auto h = static_cast<std::size_t>(ox::hash<KK>{}(k) % pairs.size());
|
auto h = static_cast<std::size_t>(ox::hash<KK>{}(k) % pairs.size());
|
||||||
while (true) {
|
while (true) {
|
||||||
auto const&p = *pairs.at(h).unwrap();
|
const auto &p = pairs[h];
|
||||||
if (p == nullptr || p->key == k) {
|
if (p == nullptr || p->key == k) {
|
||||||
return p;
|
return p;
|
||||||
} else {
|
} else {
|
||||||
@ -236,7 +235,7 @@ template<typename KK>
|
|||||||
constexpr typename HashMap<K, T>::Pair *&HashMap<K, T>::access(Vector<Pair*> &pairs, KK const&k) {
|
constexpr typename HashMap<K, T>::Pair *&HashMap<K, T>::access(Vector<Pair*> &pairs, KK const&k) {
|
||||||
auto h = static_cast<std::size_t>(ox::hash<KK>{}(k) % pairs.size());
|
auto h = static_cast<std::size_t>(ox::hash<KK>{}(k) % pairs.size());
|
||||||
while (true) {
|
while (true) {
|
||||||
auto &p = *pairs.at(h).unwrap();
|
auto &p = pairs[h];
|
||||||
if (p == nullptr || p->key == k) {
|
if (p == nullptr || p->key == k) {
|
||||||
return p;
|
return p;
|
||||||
} else {
|
} else {
|
||||||
|
65
deps/ox/src/ox/std/smallmap.hpp
vendored
65
deps/ox/src/ox/std/smallmap.hpp
vendored
@ -67,11 +67,13 @@ class SmallMap {
|
|||||||
constexpr void clear();
|
constexpr void clear();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
template<typename KK>
|
constexpr void expand();
|
||||||
constexpr Pair const&access(Vector<Pair> const&pairs, KK const&key, bool &isNew) const;
|
|
||||||
|
|
||||||
template<typename KK>
|
template<typename KK>
|
||||||
constexpr Pair &access(Vector<Pair> &pairs, KK const&key, bool &isNew);
|
constexpr Pair *const&access(Vector<Pair> const&pairs, KK const&key) const;
|
||||||
|
|
||||||
|
template<typename KK>
|
||||||
|
constexpr Pair *&access(Vector<Pair> &pairs, KK const&key);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -131,10 +133,15 @@ constexpr SmallMap<K, T> &SmallMap<K, T>::operator=(SmallMap<K, T> &&other) noex
|
|||||||
|
|
||||||
template<typename K, typename T>
|
template<typename K, typename T>
|
||||||
constexpr T &SmallMap<K, T>::operator[](MaybeView_t<K> const&k) {
|
constexpr T &SmallMap<K, T>::operator[](MaybeView_t<K> const&k) {
|
||||||
bool isNew{};
|
auto &p = access(m_pairs, k);
|
||||||
auto p = &access(m_pairs, k, isNew);
|
if (p == nullptr) {
|
||||||
if (isNew) {
|
if (static_cast<double>(m_pairs.size()) * 0.7 <
|
||||||
|
static_cast<double>(m_keys.size())) {
|
||||||
|
expand();
|
||||||
|
}
|
||||||
|
p = new Pair;
|
||||||
p->key = k;
|
p->key = k;
|
||||||
|
m_keys.emplace_back(k);
|
||||||
}
|
}
|
||||||
return p->value;
|
return p->value;
|
||||||
}
|
}
|
||||||
@ -187,41 +194,45 @@ constexpr Vector<K> const&SmallMap<K, T>::keys() const noexcept {
|
|||||||
|
|
||||||
template<typename K, typename T>
|
template<typename K, typename T>
|
||||||
constexpr void SmallMap<K, T>::clear() {
|
constexpr void SmallMap<K, T>::clear() {
|
||||||
|
for (std::size_t i = 0; i < m_pairs.size(); i++) {
|
||||||
|
delete m_pairs[i];
|
||||||
|
}
|
||||||
m_pairs.clear();
|
m_pairs.clear();
|
||||||
m_pairs.resize(127);
|
m_pairs.resize(127);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename K, typename T>
|
template<typename K, typename T>
|
||||||
template<typename KK>
|
constexpr void SmallMap<K, T>::expand() {
|
||||||
constexpr typename SmallMap<K, T>::Pair const&SmallMap<K, T>::access(
|
Vector<Pair*> r;
|
||||||
Vector<Pair> const&pairs, KK const&k, bool &isNew) const {
|
for (std::size_t i = 0; i < m_keys.size(); ++i) {
|
||||||
for (auto const&p : pairs) {
|
auto const&k = m_keys[i];
|
||||||
if (p.key == k) {
|
access(r, k) = std::move(access(m_pairs, k));
|
||||||
isNew = false;
|
|
||||||
return p;
|
|
||||||
}
|
}
|
||||||
}
|
m_pairs = std::move(r);
|
||||||
isNew = true;
|
|
||||||
m_keys.emplace_back(K(k));
|
|
||||||
return pairs.emplace_back();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename K, typename T>
|
template<typename K, typename T>
|
||||||
template<typename KK>
|
template<typename KK>
|
||||||
constexpr typename SmallMap<K, T>::Pair &SmallMap<K, T>::access(
|
constexpr typename SmallMap<K, T>::Pair *const&SmallMap<K, T>::access(
|
||||||
Vector<Pair> &pairs, KK const&k, bool &isNew) {
|
Vector<Pair> const&pairs, KK const&k) const {
|
||||||
|
for (auto const&p : pairs) {
|
||||||
|
if (p.key == k) {
|
||||||
|
return &p;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename K, typename T>
|
||||||
|
template<typename KK>
|
||||||
|
constexpr typename SmallMap<K, T>::Pair *&SmallMap<K, T>::access(
|
||||||
|
Vector<Pair> &pairs, KK const&k) {
|
||||||
for (auto &p : pairs) {
|
for (auto &p : pairs) {
|
||||||
if (p.key == k) {
|
if (p.key == k) {
|
||||||
isNew = false;
|
return &p;
|
||||||
return p;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
isNew = true;
|
return nullptr;
|
||||||
if (static_cast<double>(m_pairs.size()) * 0.7 <
|
|
||||||
static_cast<double>(m_keys.size())) {
|
|
||||||
}
|
|
||||||
m_keys.emplace_back(K(k));
|
|
||||||
return pairs.emplace_back();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
8
deps/ox/src/ox/std/uuid.hpp
vendored
8
deps/ox/src/ox/std/uuid.hpp
vendored
@ -146,14 +146,6 @@ class UUID {
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr bool operator==(UUID const&o) const noexcept {
|
|
||||||
return m_value == o.m_value;
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr bool operator!=(UUID const&o) const noexcept {
|
|
||||||
return !operator==(o);
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
constexpr ox::Error toString(Writer_c auto &writer) const noexcept {
|
constexpr ox::Error toString(Writer_c auto &writer) const noexcept {
|
||||||
auto valueI = 0u;
|
auto valueI = 0u;
|
||||||
|
@ -58,25 +58,23 @@ static class: public keel::Module {
|
|||||||
ox::Vector<keel::PackTransform> packTransforms() const noexcept final {
|
ox::Vector<keel::PackTransform> packTransforms() const noexcept final {
|
||||||
return {
|
return {
|
||||||
// convert tilesheets to CompactTileSheets
|
// convert tilesheets to CompactTileSheets
|
||||||
[](keel::Context &ctx, ox::Buffer &buff, ox::StringView typeId) -> ox::Result<bool> {
|
[](keel::Context &ctx, ox::Buffer &buff, ox::StringView typeId) -> ox::Error {
|
||||||
if (typeId == ox::ModelTypeId_v<TileSheetV1> ||
|
if (typeId == ox::ModelTypeId_v<TileSheetV1> ||
|
||||||
typeId == ox::ModelTypeId_v<TileSheetV2> ||
|
typeId == ox::ModelTypeId_v<TileSheetV2> ||
|
||||||
typeId == ox::ModelTypeId_v<TileSheetV3> ||
|
typeId == ox::ModelTypeId_v<TileSheetV3> ||
|
||||||
typeId == ox::ModelTypeId_v<TileSheetV4>) {
|
typeId == ox::ModelTypeId_v<TileSheetV4>) {
|
||||||
oxReturnError(keel::convertBuffToBuff<CompactTileSheet>(
|
return keel::convertBuffToBuff<CompactTileSheet>(
|
||||||
ctx, buff, ox::ClawFormat::Metal).moveTo(buff));
|
ctx, buff, ox::ClawFormat::Metal).moveTo(buff);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
return false;
|
return {};
|
||||||
},
|
},
|
||||||
[](keel::Context &ctx, ox::Buffer &buff, ox::StringView typeId) -> ox::Result<bool> {
|
[](keel::Context &ctx, ox::Buffer &buff, ox::StringView typeId) -> ox::Error {
|
||||||
if (typeId == ox::ModelTypeId_v<NostalgiaPalette> ||
|
if (typeId == ox::ModelTypeId_v<NostalgiaPalette> ||
|
||||||
typeId == ox::ModelTypeId_v<PaletteV1>) {
|
typeId == ox::ModelTypeId_v<PaletteV1>) {
|
||||||
oxReturnError(keel::convertBuffToBuff<Palette>(
|
return keel::convertBuffToBuff<Palette>(
|
||||||
ctx, buff, ox::ClawFormat::Metal).moveTo(buff));
|
ctx, buff, ox::ClawFormat::Metal).moveTo(buff);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
return false;
|
return {};
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
namespace keel {
|
namespace keel {
|
||||||
|
|
||||||
class Context;
|
class Context;
|
||||||
using PackTransform = ox::Result<bool>(*)(Context&, ox::Buffer &clawData, ox::StringView);
|
using PackTransform = ox::Error(*)(Context&, ox::Buffer &clawData, ox::StringView);
|
||||||
|
|
||||||
class Context {
|
class Context {
|
||||||
public:
|
public:
|
||||||
|
@ -162,12 +162,11 @@ ox::Result<ox::Buffer> convertBuffToBuff(
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename From, typename To, ox::ClawFormat fmt = ox::ClawFormat::Metal>
|
template<typename From, typename To, ox::ClawFormat fmt = ox::ClawFormat::Metal>
|
||||||
ox::Result<bool> transformRule(keel::Context &ctx, ox::Buffer &buff, ox::StringView typeId) noexcept {
|
auto transformRule(keel::Context &ctx, ox::Buffer &buff, ox::StringView typeId) noexcept -> ox::Error {
|
||||||
if (typeId == ox::ModelTypeId_v<From>) {
|
if (typeId == ox::ModelTypeId_v<From>) {
|
||||||
oxReturnError(keel::convertBuffToBuff<To>(ctx, buff, fmt).moveTo(buff));
|
oxReturnError(keel::convertBuffToBuff<To>(ctx, buff, fmt).moveTo(buff));
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
return false;
|
return {};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -102,13 +102,9 @@ ox::Result<ox::String> uuidToPath(Context &ctx, ox::UUID const&uuid) noexcept {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ox::Error performPackTransforms(Context &ctx, ox::Buffer &clawData) noexcept {
|
ox::Error performPackTransforms(Context &ctx, ox::Buffer &clawData) noexcept {
|
||||||
oxRequireM(typeId, readAssetTypeId(clawData));
|
oxRequire(typeId, readAssetTypeId(clawData).to<ox::String>());
|
||||||
for (auto const tr : packTransforms(ctx)) {
|
for (auto const tr : packTransforms(ctx)) {
|
||||||
bool changed{};
|
oxReturnError(tr(ctx, clawData, typeId));
|
||||||
oxReturnError(tr(ctx, clawData, typeId).moveTo(changed));
|
|
||||||
if (changed) {
|
|
||||||
oxReturnError(readAssetTypeId(clawData).moveTo(typeId));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user