Compare commits
5 Commits
98ddb08abd
...
ef92c8df13
Author | SHA1 | Date | |
---|---|---|---|
ef92c8df13 | |||
849d50be8e | |||
845092f114 | |||
75819a1797 | |||
d66da85753 |
14
deps/ox/src/ox/std/algorithm.hpp
vendored
14
deps/ox/src/ox/std/algorithm.hpp
vendored
@ -9,13 +9,25 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "def.hpp"
|
#include "def.hpp"
|
||||||
|
#include "error.hpp"
|
||||||
|
|
||||||
OX_CLANG_NOWARN_BEGIN(-Wunsafe-buffer-usage)
|
OX_CLANG_NOWARN_BEGIN(-Wunsafe-buffer-usage)
|
||||||
|
|
||||||
namespace ox {
|
namespace ox {
|
||||||
|
|
||||||
template<typename It, typename T>
|
template<typename It, typename T>
|
||||||
constexpr It find(It begin, It end, const T &value) {
|
constexpr ox::Result<size_t> findIdx(It begin, It end, T const&value) {
|
||||||
|
auto it = begin;
|
||||||
|
for (; it != end; ++it) {
|
||||||
|
if (*it == value) {
|
||||||
|
return it.offset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ox::Error{1, "item not found"};
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename It, typename T>
|
||||||
|
constexpr It find(It begin, It end, T const&value) {
|
||||||
for (; begin != end; ++begin) {
|
for (; begin != end; ++begin) {
|
||||||
if (*begin == value) {
|
if (*begin == value) {
|
||||||
return begin;
|
return begin;
|
||||||
|
54
deps/ox/src/ox/std/smallmap.hpp
vendored
54
deps/ox/src/ox/std/smallmap.hpp
vendored
@ -62,6 +62,9 @@ class SmallMap {
|
|||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
constexpr Vector<K> keys() const noexcept;
|
constexpr Vector<K> keys() const noexcept;
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
|
constexpr Vector<T> values() const noexcept;
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
constexpr K const&key(size_t i) const noexcept;
|
constexpr K const&key(size_t i) const noexcept;
|
||||||
|
|
||||||
@ -86,10 +89,13 @@ class SmallMap {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
template<typename KK>
|
template<typename KK>
|
||||||
constexpr Pair const&access(PairVector const&pairs, KK const&key, bool &isNew) const;
|
constexpr Pair const*access(PairVector const&pairs, KK const&key, bool &isNew) const;
|
||||||
|
|
||||||
template<typename KK>
|
template<typename KK>
|
||||||
constexpr Pair &access(PairVector &pairs, KK const&key, bool &isNew);
|
constexpr Pair *access(PairVector &pairs, KK const&key, bool &isNew);
|
||||||
|
|
||||||
|
template<typename KK>
|
||||||
|
constexpr Pair *accessNoCreate(PairVector &pairs, KK const&key);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -129,7 +135,7 @@ constexpr SmallMap<K, T, SmallSz> &SmallMap<K, T, SmallSz>::operator=(SmallMap<K
|
|||||||
template<typename K, typename T, size_t SmallSz>
|
template<typename K, typename T, size_t SmallSz>
|
||||||
constexpr T &SmallMap<K, T, SmallSz>::operator[](MaybeView_t<K> const&k) {
|
constexpr T &SmallMap<K, T, SmallSz>::operator[](MaybeView_t<K> const&k) {
|
||||||
bool isNew{};
|
bool isNew{};
|
||||||
auto p = &access(m_pairs, k, isNew);
|
auto p = access(m_pairs, k, isNew);
|
||||||
if (isNew) {
|
if (isNew) {
|
||||||
p->key = k;
|
p->key = k;
|
||||||
}
|
}
|
||||||
@ -138,7 +144,7 @@ constexpr T &SmallMap<K, T, SmallSz>::operator[](MaybeView_t<K> const&k) {
|
|||||||
|
|
||||||
template<typename K, typename T, size_t SmallSz>
|
template<typename K, typename T, size_t SmallSz>
|
||||||
constexpr Result<T*> SmallMap<K, T, SmallSz>::at(MaybeView_t<K> const&k) noexcept {
|
constexpr Result<T*> SmallMap<K, T, SmallSz>::at(MaybeView_t<K> const&k) noexcept {
|
||||||
auto p = access(m_pairs, k);
|
auto const p = accessNoCreate(m_pairs, k);
|
||||||
if (!p) {
|
if (!p) {
|
||||||
return {nullptr, ox::Error(1, "value not found for given key")};
|
return {nullptr, ox::Error(1, "value not found for given key")};
|
||||||
}
|
}
|
||||||
@ -147,7 +153,8 @@ constexpr Result<T*> SmallMap<K, T, SmallSz>::at(MaybeView_t<K> const&k) noexcep
|
|||||||
|
|
||||||
template<typename K, typename T, size_t SmallSz>
|
template<typename K, typename T, size_t SmallSz>
|
||||||
constexpr Result<const T*> SmallMap<K, T, SmallSz>::at(MaybeView_t<K> const&k) const noexcept {
|
constexpr Result<const T*> SmallMap<K, T, SmallSz>::at(MaybeView_t<K> const&k) const noexcept {
|
||||||
auto p = access(m_pairs, k);
|
bool isNew{};
|
||||||
|
auto p = access(m_pairs, k, isNew);
|
||||||
if (!p) {
|
if (!p) {
|
||||||
return {nullptr, ox::Error(1, "value not found for given key")};
|
return {nullptr, ox::Error(1, "value not found for given key")};
|
||||||
}
|
}
|
||||||
@ -168,7 +175,8 @@ constexpr void SmallMap<K, T, SmallSz>::erase(MaybeView_t<K> const&k) {
|
|||||||
|
|
||||||
template<typename K, typename T, size_t SmallSz>
|
template<typename K, typename T, size_t SmallSz>
|
||||||
constexpr bool SmallMap<K, T, SmallSz>::contains(MaybeView_t<K> const&k) const noexcept {
|
constexpr bool SmallMap<K, T, SmallSz>::contains(MaybeView_t<K> const&k) const noexcept {
|
||||||
return access(m_pairs, k) != nullptr;
|
bool isNew{};
|
||||||
|
return access(m_pairs, k, isNew) != nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename K, typename T, size_t SmallSz>
|
template<typename K, typename T, size_t SmallSz>
|
||||||
@ -186,6 +194,16 @@ constexpr Vector<K> SmallMap<K, T, SmallSz>::keys() const noexcept {
|
|||||||
return keys;
|
return keys;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename K, typename T, size_t SmallSz>
|
||||||
|
constexpr Vector<T> SmallMap<K, T, SmallSz>::values() const noexcept {
|
||||||
|
ox::Vector<T> keys;
|
||||||
|
keys.reserve(m_pairs.size());
|
||||||
|
for (auto const&p : m_pairs) {
|
||||||
|
keys.emplace_back(p.key);
|
||||||
|
}
|
||||||
|
return keys;
|
||||||
|
}
|
||||||
|
|
||||||
template<typename K, typename T, size_t SmallSz>
|
template<typename K, typename T, size_t SmallSz>
|
||||||
constexpr K const&SmallMap<K, T, SmallSz>::key(size_t i) const noexcept {
|
constexpr K const&SmallMap<K, T, SmallSz>::key(size_t i) const noexcept {
|
||||||
return m_pairs[i].key;
|
return m_pairs[i].key;
|
||||||
@ -218,30 +236,42 @@ constexpr void SmallMap<K, T, SmallSz>::clear() {
|
|||||||
|
|
||||||
template<typename K, typename T, size_t SmallSz>
|
template<typename K, typename T, size_t SmallSz>
|
||||||
template<typename KK>
|
template<typename KK>
|
||||||
constexpr typename SmallMap<K, T, SmallSz>::Pair const&SmallMap<K, T, SmallSz>::access(
|
constexpr typename SmallMap<K, T, SmallSz>::Pair const*SmallMap<K, T, SmallSz>::access(
|
||||||
PairVector const&pairs, KK const&k, bool &isNew) const {
|
PairVector const&pairs, KK const&k, bool &isNew) const {
|
||||||
for (auto const&p : pairs) {
|
for (auto const&p : pairs) {
|
||||||
if (p.key == k) {
|
if (p.key == k) {
|
||||||
isNew = false;
|
isNew = false;
|
||||||
return p;
|
return &p;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
isNew = true;
|
isNew = true;
|
||||||
return pairs.emplace_back();
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename K, typename T, size_t SmallSz>
|
template<typename K, typename T, size_t SmallSz>
|
||||||
template<typename KK>
|
template<typename KK>
|
||||||
constexpr typename SmallMap<K, T, SmallSz>::Pair &SmallMap<K, T, SmallSz>::access(
|
constexpr typename SmallMap<K, T, SmallSz>::Pair *SmallMap<K, T, SmallSz>::access(
|
||||||
PairVector &pairs, KK const&k, bool &isNew) {
|
PairVector &pairs, KK const&k, bool &isNew) {
|
||||||
for (auto &p : pairs) {
|
for (auto &p : pairs) {
|
||||||
if (p.key == k) {
|
if (p.key == k) {
|
||||||
isNew = false;
|
isNew = false;
|
||||||
return p;
|
return &p;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
isNew = true;
|
isNew = true;
|
||||||
return pairs.emplace_back();
|
return &pairs.emplace_back();
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename K, typename T, size_t SmallSz>
|
||||||
|
template<typename KK>
|
||||||
|
constexpr typename SmallMap<K, T, SmallSz>::Pair *SmallMap<K, T, SmallSz>::accessNoCreate(
|
||||||
|
PairVector &pairs, KK const&k) {
|
||||||
|
for (auto &p : pairs) {
|
||||||
|
if (p.key == k) {
|
||||||
|
return &p;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T, typename K, typename V, size_t SmallSz>
|
template<typename T, typename K, typename V, size_t SmallSz>
|
||||||
|
1
deps/ox/src/ox/std/test/CMakeLists.txt
vendored
1
deps/ox/src/ox/std/test/CMakeLists.txt
vendored
@ -18,6 +18,7 @@ add_test("[ox/std] SmallMap" ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/StdTest "SmallMap
|
|||||||
add_test("[ox/std] SmallMap2" ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/StdTest "SmallMap2")
|
add_test("[ox/std] SmallMap2" ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/StdTest "SmallMap2")
|
||||||
add_test("[ox/std] Vector" ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/StdTest "Vector")
|
add_test("[ox/std] Vector" ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/StdTest "Vector")
|
||||||
add_test("[ox/std] Vector::shrink_to_fit" ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/StdTest "Vector::shrink_to_fit")
|
add_test("[ox/std] Vector::shrink_to_fit" ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/StdTest "Vector::shrink_to_fit")
|
||||||
|
add_test("[ox/std] findIdx" ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/StdTest "findIdx")
|
||||||
add_test("[ox/std] HashMap" ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/StdTest "HashMap")
|
add_test("[ox/std] HashMap" ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/StdTest "HashMap")
|
||||||
add_test("[ox/std] HeapMgr" ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/StdTest malloc)
|
add_test("[ox/std] HeapMgr" ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/StdTest malloc)
|
||||||
add_test("[ox/std] Serialize-Int" ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/StdTest "Serialize-Int")
|
add_test("[ox/std] Serialize-Int" ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/StdTest "Serialize-Int")
|
||||||
|
27
deps/ox/src/ox/std/test/tests.cpp
vendored
27
deps/ox/src/ox/std/test/tests.cpp
vendored
@ -267,6 +267,20 @@ OX_CLANG_NOWARN_END
|
|||||||
return ox::Error{};
|
return ox::Error{};
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"findIdx",
|
||||||
|
[] {
|
||||||
|
ox::Vector<ox::IString<8>> const v {"zero", "one", "two", "three", "four"};
|
||||||
|
oxExpect(ox::findIdx(v.begin(), v.end(), "zero").or_value(5), 0u);
|
||||||
|
oxExpect(ox::findIdx(v.begin(), v.end(), "one").or_value(5), 1u);
|
||||||
|
oxExpect(ox::findIdx(v.begin(), v.end(), "two").or_value(5), 2u);
|
||||||
|
oxExpect(ox::findIdx(v.begin(), v.end(), "three").or_value(5), 3u);
|
||||||
|
oxExpect(ox::findIdx(v.begin(), v.end(), "four").or_value(5), 4u);
|
||||||
|
oxExpect(ox::findIdx(v.begin(), v.end(), "five").or_value(5), 5u);
|
||||||
|
oxExpect(ox::findIdx(v.begin(), v.end(), "six").or_value(6), 6u);
|
||||||
|
return ox::Error{};
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"SmallMap",
|
"SmallMap",
|
||||||
[] {
|
[] {
|
||||||
@ -276,7 +290,18 @@ OX_CLANG_NOWARN_END
|
|||||||
oxExpect(map.size(), 1u);
|
oxExpect(map.size(), 1u);
|
||||||
oxExpect(map["aoeu"], "");
|
oxExpect(map["aoeu"], "");
|
||||||
oxExpect(map.size(), 2u);
|
oxExpect(map.size(), 2u);
|
||||||
return ox::Error(0);
|
ox::SmallMap<ox::String, ox::String> cmap;
|
||||||
|
cmap["asdf"] = "aoeu";
|
||||||
|
auto constexpr constTest = [](ox::SmallMap<ox::String, ox::String> const&map) {
|
||||||
|
OX_REQUIRE(asdf, map.at("asdf"));
|
||||||
|
oxExpect(*asdf, "aoeu");
|
||||||
|
oxExpect(map.size(), 1u);
|
||||||
|
auto const aoeu = map.at("aoeu");
|
||||||
|
oxExpect(aoeu.ok(), false);
|
||||||
|
oxExpect(map.size(), 1u);
|
||||||
|
return ox::Error{};
|
||||||
|
};
|
||||||
|
return constTest(cmap);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -212,6 +212,10 @@ struct TileSheetV4 {
|
|||||||
pixels(std::move(pPixels)) {
|
pixels(std::move(pPixels)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return the dimensional size of the SubSheet (e.g. width * height)
|
||||||
|
*/
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
constexpr std::size_t size() const noexcept {
|
constexpr std::size_t size() const noexcept {
|
||||||
return static_cast<std::size_t>(columns) * static_cast<std::size_t>(rows);
|
return static_cast<std::size_t>(columns) * static_cast<std::size_t>(rows);
|
||||||
@ -273,7 +277,7 @@ size_t getTileCnt(TileSheet const&ts) noexcept;
|
|||||||
TileSheet::SubSheet const*getSubsheet(TileSheet const&ts, SubSheetId id) noexcept;
|
TileSheet::SubSheet const*getSubsheet(TileSheet const&ts, SubSheetId id) noexcept;
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
size_t getTileIdx(TileSheet const&ts, SubSheetId id) noexcept;
|
ox::Optional<size_t> getTileIdx(TileSheet const&ts, SubSheetId id) noexcept;
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
uint8_t getPixel4Bpp(TileSheet::SubSheet const&ss, std::size_t idx) noexcept;
|
uint8_t getPixel4Bpp(TileSheet::SubSheet const&ss, std::size_t idx) noexcept;
|
||||||
@ -392,6 +396,8 @@ ox::Result<SubSheetId> getIdFor(TileSheet const&ts, ox::StringViewCR path) noexc
|
|||||||
|
|
||||||
ox::Result<unsigned> getTileOffset(TileSheet const&ts, ox::StringViewCR pNamePath) noexcept;
|
ox::Result<unsigned> getTileOffset(TileSheet const&ts, ox::StringViewCR pNamePath) noexcept;
|
||||||
|
|
||||||
|
ox::Result<uint32_t> getTileOffset(TileSheet const&ts, SubSheetId pId) noexcept;
|
||||||
|
|
||||||
ox::Result<ox::StringView> getNameFor(TileSheet::SubSheet const&ss, SubSheetId pId) noexcept;
|
ox::Result<ox::StringView> getNameFor(TileSheet::SubSheet const&ss, SubSheetId pId) noexcept;
|
||||||
|
|
||||||
ox::Result<ox::StringView> getNameFor(TileSheet const&ts, SubSheetId pId) noexcept;
|
ox::Result<ox::StringView> getNameFor(TileSheet const&ts, SubSheetId pId) noexcept;
|
||||||
|
@ -66,10 +66,10 @@ static ox::Optional<size_t> getPixelIdx(
|
|||||||
return ox::Optional<size_t>{};
|
return ox::Optional<size_t>{};
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t getTileIdx(TileSheet const&ts, SubSheetId const id) noexcept {
|
ox::Optional<size_t> getTileIdx(TileSheet const&ts, SubSheetId const id) noexcept {
|
||||||
size_t idx{};
|
size_t idx{};
|
||||||
auto const out = getPixelIdx(ts.subsheet, id, idx, ts.bpp);
|
auto const out = getPixelIdx(ts.subsheet, id, idx, ts.bpp);
|
||||||
return out.or_value(0) / PixelsPerTile;
|
return out ? ox::Optional<size_t>{ox::in_place, *out / PixelsPerTile} : out;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t getPixel4Bpp(TileSheet::SubSheet const&ss, std::size_t idx) noexcept {
|
uint8_t getPixel4Bpp(TileSheet::SubSheet const&ss, std::size_t idx) noexcept {
|
||||||
@ -355,12 +355,12 @@ ox::Result<SubSheetId> getIdFor(TileSheet const&ts, ox::StringViewCR path) noexc
|
|||||||
/**
|
/**
|
||||||
* Gets the offset in tiles of the desired subsheet.
|
* Gets the offset in tiles of the desired subsheet.
|
||||||
*/
|
*/
|
||||||
static ox::Result<unsigned> getTileOffset(
|
static ox::Result<uint32_t> getTileOffset(
|
||||||
TileSheet::SubSheet const&ss,
|
TileSheet::SubSheet const&ss,
|
||||||
ox::SpanView<ox::StringView> const&pNamePath,
|
ox::SpanView<ox::StringView> const&pNamePath,
|
||||||
int8_t pBpp,
|
int8_t pBpp,
|
||||||
std::size_t pIt = 0,
|
std::size_t pIt = 0,
|
||||||
unsigned pCurrentTotal = 0) noexcept {
|
uint32_t pCurrentTotal = 0) noexcept {
|
||||||
// pIt == pNamePath.size() - 1 &&
|
// pIt == pNamePath.size() - 1 &&
|
||||||
if (ss.name != pNamePath[pIt]) {
|
if (ss.name != pNamePath[pIt]) {
|
||||||
return ox::Error(2, "Wrong branch");
|
return ox::Error(2, "Wrong branch");
|
||||||
@ -374,12 +374,14 @@ static ox::Result<unsigned> getTileOffset(
|
|||||||
if (!err) {
|
if (!err) {
|
||||||
return offset;
|
return offset;
|
||||||
}
|
}
|
||||||
|
// Possible bug? Shoud this be usinga a recursive version of
|
||||||
|
// pixelCnt will count pixels in subsheets of sub as well.
|
||||||
pCurrentTotal += pixelCnt(sub, pBpp) / PixelsPerTile;
|
pCurrentTotal += pixelCnt(sub, pBpp) / PixelsPerTile;
|
||||||
}
|
}
|
||||||
return ox::Error(1, "SubSheet not found");
|
return ox::Error(1, "SubSheet not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
ox::Result<unsigned> getTileOffset(TileSheet const&ts, ox::StringViewCR pNamePath) noexcept {
|
ox::Result<uint32_t> getTileOffset(TileSheet const&ts, ox::StringViewCR pNamePath) noexcept {
|
||||||
return core::getTileOffset(ts.subsheet, ox::split<8>(pNamePath, '.'), ts.bpp);
|
return core::getTileOffset(ts.subsheet, ox::split<8>(pNamePath, '.'), ts.bpp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ target_include_directories(
|
|||||||
)
|
)
|
||||||
|
|
||||||
target_sources(
|
target_sources(
|
||||||
Turbine PUBLIC
|
Turbine PRIVATE
|
||||||
turbine.cpp
|
turbine.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -28,11 +28,11 @@ project_name = sys.argv[2]
|
|||||||
bin = f'./build/{host_env}-{current_build}/bin/'
|
bin = f'./build/{host_env}-{current_build}/bin/'
|
||||||
project_bin = f'build/gba-release/bin/{project_name}.bin'
|
project_bin = f'build/gba-release/bin/{project_name}.bin'
|
||||||
project_gba = f'{project_name}.gba'
|
project_gba = f'{project_name}.gba'
|
||||||
project_manifest = f'{project_name}-manifest.json'
|
project_manifest = f'{project_name.lower()}-manifest.json'
|
||||||
|
|
||||||
shutil.copyfile(project_bin, project_gba)
|
shutil.copyfile(project_bin, project_gba)
|
||||||
subprocess.run([
|
subprocess.run([
|
||||||
f'{bin}/{project_name}-pack',
|
f'{bin}/{project_name.lower()}-pack',
|
||||||
'-src', project_dir,
|
'-src', project_dir,
|
||||||
'-rom-bin', project_gba,
|
'-rom-bin', project_gba,
|
||||||
'-manifest', project_manifest])
|
'-manifest', project_manifest])
|
||||||
|
Loading…
Reference in New Issue
Block a user