Compare commits
105 Commits
release-d2
...
abcf2adc56
Author | SHA1 | Date | |
---|---|---|---|
abcf2adc56 | |||
05f9023550 | |||
5ba0bcf963 | |||
3ccadba2f5 | |||
00e52b6491 | |||
ae40487990 | |||
84b612c693 | |||
3c2a6b047e | |||
626da322d9 | |||
0de428a2e5 | |||
8a52df4f76 | |||
efec6eb3c8 | |||
56eeb24900 | |||
ae81f6b3de | |||
c1108301c0 | |||
83fbe6ac74 | |||
80b452833f | |||
0fa394333b | |||
cae7535034 | |||
df87832324 | |||
d585794cbe | |||
209658549c | |||
02383a4aed | |||
185a76282a | |||
b722b4f701 | |||
459ab5aad9 | |||
565f621cfc | |||
9589ca9148 | |||
164db5007b | |||
cbfb167d29 | |||
e7b83be867 | |||
649da5fca8 | |||
aa095f7680 | |||
bb99c99f01 | |||
7f0dcdd280 | |||
6029ad5d47 | |||
26fe266b09 | |||
091eda7b44 | |||
9676ea5978 | |||
de8ac10653 | |||
88a6cd59f3 | |||
cd43fb7f38 | |||
136f422401 | |||
e773d6f0ee | |||
7da2f68d30 | |||
d20889aef1 | |||
50c8302f4a | |||
d8195d300d | |||
a8c1387d5a | |||
ff1e8f260b | |||
d4329981e7 | |||
0003454311 | |||
8c6b2234ec | |||
aad4b8a44c | |||
7cab133127 | |||
640ac85de4 | |||
b8d7658626 | |||
2503bb3b2c | |||
e5dd448fe7 | |||
4770bb6a93 | |||
c0bac696dc | |||
95f7c33419 | |||
535d8876d3 | |||
845e433221 | |||
5169a607cf | |||
8f03af99a7 | |||
ee63a4a1e4 | |||
ac29f7a0f2 | |||
89ae226b1d | |||
477834ac04 | |||
97b707b61c | |||
e86180e842 | |||
035ba8810f | |||
f1c2113dd3 | |||
56b79f414d | |||
844656d557 | |||
849aceb86d | |||
eef51a6d2b | |||
c84b85102c | |||
3fe62464c3 | |||
db55fc722f | |||
2094450898 | |||
889bec04b1 | |||
ac1e34d4cd | |||
55ed75f44d | |||
2751872c59 | |||
2a3cd35cc4 | |||
b66f459f75 | |||
3910f4e77c | |||
c0e96216ae | |||
f9512d72e8 | |||
b7f2c169ec | |||
1e5057d6e6 | |||
c6255e3224 | |||
02230ef619 | |||
9b6b60e4d1 | |||
b9a26ab61e | |||
a521887ddd | |||
5ca7e2f226 | |||
125a235dd1 | |||
91a7129f8f | |||
df48a232ec | |||
ab11b885e6 | |||
36fc25fb7e | |||
4803cca334 |
15
Makefile
@@ -15,7 +15,16 @@ PROJECT_PLAYER=./build/${BC_VAR_CURRENT_BUILD}/bin/${BC_VAR_PROJECT_NAME_CAP}
|
||||
|
||||
.PHONY: pkg-gba
|
||||
pkg-gba: build
|
||||
${BC_CMD_ENVRUN} ${BC_PY3} ./util/scripts/pkg-gba.py sample_project ${BC_VAR_PROJECT_NAME}
|
||||
${BC_CMD_ENVRUN} ${BC_PY3} ./util/scripts/pkg-gba.py sample_project ${BC_VAR_PROJECT_NAME_CAP}
|
||||
|
||||
.PHONY: pkg-mac
|
||||
pkg-mac: install
|
||||
${BC_CMD_ENVRUN} ${BC_PY3} ./util/scripts/pkg-dmg.py NostalgiaStudio
|
||||
|
||||
.PHONY: generate-studio-rsrc
|
||||
generate-studio-rsrc:
|
||||
${BC_CMD_ENVRUN} ${BC_PY3} ./util/scripts/file-to-cpp.py --rsrc src/olympic/studio/applib/src/rsrc.json
|
||||
${BC_CMD_ENVRUN} ${BC_PY3} ./util/scripts/file-to-cpp.py --rsrc src/nostalgia/studio/rsrc.json
|
||||
|
||||
.PHONY: build-player
|
||||
build-player:
|
||||
@@ -28,10 +37,10 @@ run-studio: build
|
||||
${PROJECT_STUDIO}
|
||||
.PHONY: gba-run
|
||||
gba-run: pkg-gba
|
||||
${MGBA} ${BC_VAR_PROJECT_NAME}.gba
|
||||
${MGBA} ${BC_VAR_PROJECT_NAME_CAP}.gba
|
||||
.PHONY: debug
|
||||
debug: build
|
||||
${BC_CMD_HOST_DEBUGGER} ./build/${BC_VAR_CURRENT_BUILD}/bin/${BC_VAR_PROJECT_NAME} sample_project
|
||||
${BC_CMD_HOST_DEBUGGER} ${PROJECT_PLAYER} sample_project
|
||||
.PHONY: debug-studio
|
||||
debug-studio: build
|
||||
${BC_CMD_HOST_DEBUGGER} ${PROJECT_STUDIO}
|
||||
|
2
deps/ox/src/ox/clargs/clargs.cpp
vendored
@@ -29,7 +29,7 @@ ClArgs::ClArgs(ox::SpanView<const char*> args) noexcept {
|
||||
m_bools[arg] = false;
|
||||
}
|
||||
m_strings[arg] = val;
|
||||
if (auto r = ox::atoi(val.c_str()); r.error == 0) {
|
||||
if (auto r = ox::strToInt(val); r.error == 0) {
|
||||
m_ints[arg] = r.value;
|
||||
}
|
||||
++i;
|
||||
|
2
deps/ox/src/ox/claw/read.cpp
vendored
@@ -81,7 +81,7 @@ Result<ClawHeader> readClawHeader(ox::BufferView buff) noexcept {
|
||||
return ox::Error(4, "Claw format does not match any supported format/version combo");
|
||||
}
|
||||
hdr.typeName = typeName;
|
||||
std::ignore = ox::atoi(versionStr).copyTo(hdr.typeVersion);
|
||||
std::ignore = ox::strToInt(versionStr).copyTo(hdr.typeVersion);
|
||||
hdr.data = buffRaw;
|
||||
hdr.dataSize = buffLen;
|
||||
return hdr;
|
||||
|
@@ -433,14 +433,14 @@ Error FileStoreTemplate<size_t>::resize() {
|
||||
template<typename size_t>
|
||||
Error FileStoreTemplate<size_t>::resize(std::size_t size, void *newBuff) {
|
||||
if (m_buffer->size() > size) {
|
||||
return ox::Error(1);
|
||||
return ox::Error{1, "new buffer is too small for existing data"};
|
||||
}
|
||||
m_buffSize = static_cast<size_t>(size);
|
||||
if (newBuff) {
|
||||
m_buffer = reinterpret_cast<Buffer*>(newBuff);
|
||||
m_buffer = static_cast<Buffer*>(newBuff);
|
||||
OX_RETURN_ERROR(m_buffer->setSize(static_cast<size_t>(size)));
|
||||
}
|
||||
return ox::Error(0);
|
||||
return {};
|
||||
}
|
||||
|
||||
template<typename size_t>
|
||||
|
@@ -31,10 +31,10 @@ FileAddress::FileAddress(uint64_t inode) noexcept {
|
||||
FileAddress::FileAddress(ox::StringViewCR path) noexcept {
|
||||
auto pathSize = path.bytes();
|
||||
m_data.path = new char[pathSize + 1];
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
memcpy(m_data.path, path.data(), pathSize);
|
||||
OX_CLANG_NOWARN_BEGIN(-Wunsafe-buffer-usage)
|
||||
m_data.path[pathSize] = 0;
|
||||
OX_CLANG_NOWARN_END
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
m_type = FileAddressType::Path;
|
||||
}
|
||||
|
||||
@@ -48,9 +48,11 @@ FileAddress &FileAddress::operator=(const FileAddress &other) noexcept {
|
||||
case FileAddressType::Path:
|
||||
{
|
||||
if (other.m_data.path) {
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
auto strSize = ox::strlen(other.m_data.path) + 1;
|
||||
m_data.path = new char[strSize];
|
||||
ox::memcpy(m_data.path, other.m_data.path, strSize);
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
} else {
|
||||
m_data.constPath = "";
|
||||
m_type = FileAddressType::ConstPath;
|
||||
|
29
deps/ox/src/ox/fs/filesystem/filesystem.hpp
vendored
@@ -20,7 +20,7 @@
|
||||
namespace ox {
|
||||
|
||||
namespace detail {
|
||||
static inline void fsBuffFree(char *buff) noexcept {
|
||||
inline void fsBuffFree(char *buff) noexcept {
|
||||
safeDelete(buff);
|
||||
}
|
||||
}
|
||||
@@ -49,11 +49,11 @@ class FileSystem {
|
||||
|
||||
Result<Buffer> read(StringViewCR path) noexcept;
|
||||
|
||||
inline Error read(StringViewCR path, void *buffer, std::size_t buffSize) noexcept {
|
||||
Error read(StringViewCR path, void *buffer, std::size_t buffSize) noexcept {
|
||||
return readFilePath(path, buffer, buffSize);
|
||||
}
|
||||
|
||||
inline Error read(uint64_t inode, void *buffer, std::size_t buffSize) noexcept {
|
||||
Error read(uint64_t inode, void *buffer, std::size_t buffSize) noexcept {
|
||||
return readFileInode(inode, buffer, buffSize);
|
||||
}
|
||||
|
||||
@@ -69,8 +69,7 @@ class FileSystem {
|
||||
* @param path
|
||||
* @param readStart
|
||||
* @param readSize
|
||||
* @param buffer
|
||||
* @param size
|
||||
* @param buff
|
||||
* @return error or number of bytes read
|
||||
*/
|
||||
Result<size_t> read(
|
||||
@@ -102,36 +101,36 @@ class FileSystem {
|
||||
|
||||
Error write(const FileAddress &addr, const void *buffer, uint64_t size, FileType fileType = FileType::NormalFile) noexcept;
|
||||
|
||||
inline Error write(StringViewCR path, const void *buffer, uint64_t size, FileType fileType) noexcept {
|
||||
Error write(StringViewCR path, const void *buffer, uint64_t size, FileType fileType) noexcept {
|
||||
return writeFilePath(path, buffer, size, fileType);
|
||||
}
|
||||
|
||||
inline Error write(uint64_t inode, const void *buffer, uint64_t size, FileType fileType) noexcept {
|
||||
Error write(uint64_t inode, const void *buffer, uint64_t size, FileType fileType) noexcept {
|
||||
return writeFileInode(inode, buffer, size, fileType);
|
||||
}
|
||||
|
||||
inline Result<FileStat> stat(uint64_t inode) const noexcept {
|
||||
Result<FileStat> stat(uint64_t inode) const noexcept {
|
||||
return statInode(inode);
|
||||
}
|
||||
|
||||
inline Result<FileStat> stat(StringViewCR path) const noexcept {
|
||||
Result<FileStat> stat(StringViewCR path) const noexcept {
|
||||
return statPath(path);
|
||||
}
|
||||
|
||||
Result<FileStat> stat(const FileAddress &addr) const noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
inline bool exists(uint64_t inode) const noexcept {
|
||||
bool exists(uint64_t inode) const noexcept {
|
||||
return statInode(inode).ok();
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline bool exists(ox::StringView path) const noexcept {
|
||||
bool exists(ox::StringView path) const noexcept {
|
||||
return statPath(path).ok();
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline bool exists(FileAddress const&addr) const noexcept {
|
||||
bool exists(FileAddress const&addr) const noexcept {
|
||||
return stat(addr).ok();
|
||||
}
|
||||
|
||||
@@ -178,11 +177,11 @@ class MemFS: public FileSystem {
|
||||
public:
|
||||
Result<const char*> directAccess(const FileAddress &addr) const noexcept;
|
||||
|
||||
inline Result<const char*> directAccess(StringViewCR path) const noexcept {
|
||||
Result<const char*> directAccess(StringViewCR path) const noexcept {
|
||||
return directAccessPath(path);
|
||||
}
|
||||
|
||||
inline Result<const char*> directAccess(uint64_t inode) const noexcept {
|
||||
Result<const char*> directAccess(uint64_t inode) const noexcept {
|
||||
return directAccessInode(inode);
|
||||
}
|
||||
|
||||
@@ -469,7 +468,7 @@ Error FileSystemTemplate<FileStore, Directory>::writeFilePath(
|
||||
|
||||
template<typename FileStore, typename Directory>
|
||||
Error FileSystemTemplate<FileStore, Directory>::writeFileInode(uint64_t inode, const void *buffer, uint64_t size, FileType fileType) noexcept {
|
||||
oxTrace("ox.fs.FileSystemTemplate.writeFileInode", ox::itoa(inode));
|
||||
oxTrace("ox.fs.FileSystemTemplate.writeFileInode", ox::intToStr(inode));
|
||||
return m_fs.write(inode, buffer, static_cast<size_t>(size), static_cast<uint8_t>(fileType));
|
||||
}
|
||||
|
||||
|
6
deps/ox/src/ox/fs/test/tests.cpp
vendored
@@ -119,7 +119,9 @@ const std::map<ox::StringView, std::function<ox::Error(ox::StringView)>> tests =
|
||||
auto constexpr path = ox::StringLiteral("/usr/share/charset.gbag");
|
||||
ox::PathIterator it(path.c_str(), path.len());
|
||||
auto buff = static_cast<char*>(ox_alloca(path.len() + 1));
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
oxAssert(it.dirPath(buff, path.len()) == 0 && ox::strcmp(buff, "/usr/share/") == 0, "PathIterator shows incorrect dir path");
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
return ox::Error(0);
|
||||
}
|
||||
},
|
||||
@@ -127,7 +129,9 @@ const std::map<ox::StringView, std::function<ox::Error(ox::StringView)>> tests =
|
||||
"PathIterator::hasNext",
|
||||
[](ox::StringView) {
|
||||
const auto path = "/file1";
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
ox::PathIterator it(path, ox::strlen(path));
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
oxAssert(it.hasNext(), "PathIterator shows incorrect hasNext");
|
||||
oxAssert(!it.next().hasNext(), "PathIterator shows incorrect hasNext");
|
||||
return ox::Error(0);
|
||||
@@ -163,9 +167,11 @@ const std::map<ox::StringView, std::function<ox::Error(ox::StringView)>> tests =
|
||||
[](ox::StringView) {
|
||||
constexpr auto buffLen = 5000;
|
||||
constexpr auto str1 = "Hello, World!";
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
constexpr auto str1Len = ox::strlen(str1) + 1;
|
||||
constexpr auto str2 = "Hello, Moon!";
|
||||
constexpr auto str2Len = ox::strlen(str2) + 1;
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
auto list = new (ox_alloca(buffLen)) ox::ptrarith::NodeBuffer<uint32_t, ox::FileStoreItem<uint32_t>>(buffLen);
|
||||
oxAssert(ox::FileStore32::format(list, buffLen), "FileStore::format failed.");
|
||||
ox::FileStore32 fileStore(list, buffLen);
|
||||
|
2
deps/ox/src/ox/fs/tool.cpp
vendored
@@ -57,7 +57,9 @@ static ox::Error runRead(ox::FileSystem *fs, ox::Span<const char*> args) noexcep
|
||||
return ox::Error(1);
|
||||
}
|
||||
OX_REQUIRE(buff, fs->read(ox::StringView(args[1])));
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
std::ignore = fwrite(buff.data(), sizeof(decltype(buff)::value_type), buff.size(), stdout);
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
return ox::Error(0);
|
||||
}
|
||||
|
||||
|
64
deps/ox/src/ox/mc/intops.hpp
vendored
@@ -71,7 +71,9 @@ constexpr McInt encodeInteger(I pInput) noexcept {
|
||||
// move input to uint64_t to allow consistent bit manipulation, and to avoid
|
||||
// overflow concerns
|
||||
uint64_t val = 0;
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
ox::memcpy(&val, &input, sizeof(input));
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
if (val) {
|
||||
// bits needed to represent number factoring in space possibly
|
||||
// needed for signed bit
|
||||
@@ -94,7 +96,9 @@ constexpr McInt encodeInteger(I pInput) noexcept {
|
||||
}
|
||||
if (bytes == 9) {
|
||||
out.data[0] = bytesIndicator;
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
ox::memcpy(&out.data[1], &leVal, 8);
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
if (inputNegative) {
|
||||
out.data[1] |= 0b1000'0000;
|
||||
}
|
||||
@@ -104,7 +108,9 @@ constexpr McInt encodeInteger(I pInput) noexcept {
|
||||
auto intermediate =
|
||||
static_cast<uint64_t>(leVal.raw() | (negBit << (valBits - 1))) << bytes |
|
||||
static_cast<uint64_t>(bytesIndicator);
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
ox::memcpy(&out.data[0], &intermediate, sizeof(intermediate));
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
}
|
||||
out.length = bytes;
|
||||
}
|
||||
@@ -151,33 +157,37 @@ constexpr Result<I> decodeInteger(Reader_c auto&rdr, std::size_t *bytesRead) noe
|
||||
decoded >>= bytes;
|
||||
// move sign bit
|
||||
if constexpr(is_signed_v<I>) {
|
||||
const auto negBit = bytes * 8 - bytes - 1;
|
||||
// move sign
|
||||
const auto negative = (decoded >> negBit) == 1;
|
||||
if (negative) {
|
||||
// fill in all bits between encoded sign and real sign with 1s
|
||||
// split it up because the 32-bit ARM can't shift more than 32 bits
|
||||
ox::Array<uint32_t, 2> d = {};
|
||||
//d[0] = decoded & 0xffff'ffff;
|
||||
//d[1] = decoded >> 32;
|
||||
ox::memcpy(&d[0], &decoded, sizeof(decoded));
|
||||
auto bit = negBit;
|
||||
for (; bit < ox::min<std::size_t>(Bits<I>, 32); ++bit) {
|
||||
d[0] |= 1 << bit;
|
||||
}
|
||||
bit -= 32;
|
||||
for (; bit < Bits<I>; ++bit) {
|
||||
d[1] |= 1 << bit;
|
||||
}
|
||||
I out = 0;
|
||||
if constexpr(ox::defines::BigEndian) {
|
||||
const auto d0Tmp = d[0];
|
||||
d[0] = d[1];
|
||||
d[1] = d0Tmp;
|
||||
}
|
||||
ox::memcpy(&out, &d[0], sizeof(out));
|
||||
return out;
|
||||
}
|
||||
const auto negBit = bytes * 8 - bytes - 1;
|
||||
// move sign
|
||||
const auto negative = (decoded >> negBit) == 1;
|
||||
if (negative) {
|
||||
// fill in all bits between encoded sign and real sign with 1s
|
||||
// split it up because the 32-bit ARM can't shift more than 32 bits
|
||||
ox::Array<uint32_t, 2> d = {};
|
||||
//d[0] = decoded & 0xffff'ffff;
|
||||
//d[1] = decoded >> 32;
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
ox::memcpy(&d[0], &decoded, sizeof(decoded));
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
auto bit = negBit;
|
||||
for (; bit < ox::min<std::size_t>(Bits<I>, 32); ++bit) {
|
||||
d[0] |= 1 << bit;
|
||||
}
|
||||
bit -= 32;
|
||||
for (; bit < Bits<I>; ++bit) {
|
||||
d[1] |= 1 << bit;
|
||||
}
|
||||
I out = 0;
|
||||
if constexpr(ox::defines::BigEndian) {
|
||||
const auto d0Tmp = d[0];
|
||||
d[0] = d[1];
|
||||
d[1] = d0Tmp;
|
||||
}
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
ox::memcpy(&out, &d[0], sizeof(out));
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
return out;
|
||||
}
|
||||
}
|
||||
return static_cast<I>(decoded);
|
||||
}
|
||||
|
5
deps/ox/src/ox/mc/write.hpp
vendored
@@ -214,7 +214,12 @@ template<Writer_c Writer>
|
||||
constexpr Error MetalClawWriter<Writer>::fieldCString(const char*, const char *const*val, std::size_t) noexcept {
|
||||
bool fieldSet = false;
|
||||
if (!m_unionIdx.has_value() || *m_unionIdx == m_field) {
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
// this strlen is tolerated because sometimes 0 gets passed to
|
||||
// the size param, which is a lie
|
||||
// this code should be cleaned up at some point...
|
||||
const auto strLen = *val ? ox::strlen(*val) : 0;
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
// write the length
|
||||
const auto strLenBuff = mc::encodeInteger(strLen);
|
||||
OX_RETURN_ERROR(m_writer.write(reinterpret_cast<const char*>(strLenBuff.data.data()), strLenBuff.length));
|
||||
|
12
deps/ox/src/ox/model/modelvalue.hpp
vendored
@@ -997,7 +997,7 @@ constexpr ModelValue::ModelValue(const ModelValue &other) noexcept {
|
||||
case Type::SignedInteger16:
|
||||
case Type::SignedInteger32:
|
||||
case Type::SignedInteger64:
|
||||
ox::memcpy(&m_data, &other.m_data, sizeof(m_data));
|
||||
m_data = other.m_data;
|
||||
break;
|
||||
case Type::String:
|
||||
m_data.str = new String(other.get<String>());
|
||||
@@ -1030,8 +1030,8 @@ constexpr ModelValue::ModelValue(ModelValue &&other) noexcept {
|
||||
case Type::SignedInteger16:
|
||||
case Type::SignedInteger32:
|
||||
case Type::SignedInteger64:
|
||||
ox::memcpy(&m_data, &other.m_data, sizeof(m_data));
|
||||
ox::memset(&other.m_data, 0, sizeof(m_data));
|
||||
m_data = other.m_data;
|
||||
other.m_data.ui64 = 0;
|
||||
break;
|
||||
case Type::String:
|
||||
m_data.str = other.m_data.str;
|
||||
@@ -1223,7 +1223,7 @@ constexpr ModelValue &ModelValue::operator=(const ModelValue &other) noexcept {
|
||||
case Type::SignedInteger16:
|
||||
case Type::SignedInteger32:
|
||||
case Type::SignedInteger64:
|
||||
ox::memcpy(&m_data, &other.m_data, sizeof(m_data));
|
||||
m_data = other.m_data;
|
||||
break;
|
||||
case Type::String:
|
||||
m_data.str = new String(other.get<String>());
|
||||
@@ -1261,8 +1261,8 @@ constexpr ModelValue &ModelValue::operator=(ModelValue &&other) noexcept {
|
||||
case Type::SignedInteger16:
|
||||
case Type::SignedInteger32:
|
||||
case Type::SignedInteger64:
|
||||
ox::memcpy(&m_data, &other.m_data, sizeof(m_data));
|
||||
ox::memset(&other.m_data, 0, sizeof(m_data));
|
||||
m_data = other.m_data;
|
||||
other.m_data = {};
|
||||
break;
|
||||
case Type::String:
|
||||
m_data.str = other.m_data.str;
|
||||
|
2
deps/ox/src/ox/oc/read.cpp
vendored
@@ -15,7 +15,7 @@ namespace ox {
|
||||
|
||||
OrganicClawReader::OrganicClawReader(const uint8_t *buff, std::size_t buffSize) {
|
||||
auto json = reinterpret_cast<const char*>(buff);
|
||||
auto jsonLen = ox::strnlen(json, buffSize);
|
||||
auto jsonLen = ox::strnlen_s(json, buffSize);
|
||||
Json::CharReaderBuilder parserBuilder;
|
||||
auto parser = std::unique_ptr<Json::CharReader>(parserBuilder.newCharReader());
|
||||
if (!parser->parse(json, json + jsonLen, &m_json, nullptr)) {
|
||||
|
4
deps/ox/src/ox/oc/read.hpp
vendored
@@ -8,7 +8,11 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ox/std/def.hpp>
|
||||
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
#include <json/json.h>
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
|
||||
#include <ox/model/fieldcounter.hpp>
|
||||
#include <ox/model/modelhandleradaptor.hpp>
|
||||
|
8
deps/ox/src/ox/oc/write.hpp
vendored
@@ -8,7 +8,11 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ox/std/def.hpp>
|
||||
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
#include <json/json.h>
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
|
||||
#include <ox/model/fieldcounter.hpp>
|
||||
#include <ox/model/modelhandleradaptor.hpp>
|
||||
@@ -258,7 +262,9 @@ Result<ox::Buffer> writeOC(const auto &val) noexcept {
|
||||
const auto str = Json::writeString(jsonBuilder, writer.m_json);
|
||||
Result<Buffer> buff;
|
||||
buff.value.resize(str.size() + 1);
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
memcpy(buff.value.data(), str.data(), str.size() + 1);
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
return buff;
|
||||
}
|
||||
|
||||
@@ -270,7 +276,9 @@ Result<ox::String> writeOCString(const auto &val) noexcept {
|
||||
const auto str = Json::writeString(jsonBuilder, writer.m_json);
|
||||
Result<ox::String> buff;
|
||||
buff.value.resize(str.size());
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
memcpy(buff.value.data(), str.data(), str.size() + 1);
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
return buff;
|
||||
}
|
||||
|
||||
|
9
deps/ox/src/ox/std/cstrops.hpp
vendored
@@ -30,9 +30,12 @@ constexpr T1 strncpy(T1 dest, T2 src, std::size_t maxLen) noexcept {
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr auto strnlen(const char *str1, std::size_t maxLen) noexcept {
|
||||
std::size_t len = 0;
|
||||
for (; len < maxLen && str1[len]; len++);
|
||||
constexpr size_t strnlen_s(const char *str, size_t const maxLen) noexcept {
|
||||
if (!str) [[unlikely]] {
|
||||
return 0;
|
||||
}
|
||||
size_t len = 0;
|
||||
for (; len < maxLen && str[len]; len++);
|
||||
return len;
|
||||
}
|
||||
|
||||
|
2
deps/ox/src/ox/std/istring.hpp
vendored
@@ -245,7 +245,7 @@ struct MaybeView<ox::IString<sz>> {
|
||||
|
||||
template<Integer_c Integer>
|
||||
[[nodiscard]]
|
||||
constexpr auto itoa(Integer v) noexcept {
|
||||
constexpr auto intToStr(Integer v) noexcept {
|
||||
constexpr auto Cap = [] {
|
||||
auto out = 0;
|
||||
switch (sizeof(Integer)) {
|
||||
|
25
deps/ox/src/ox/std/span.hpp
vendored
@@ -8,6 +8,10 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#if __has_include(<array>)
|
||||
#include <array>
|
||||
#endif
|
||||
|
||||
#include "array.hpp"
|
||||
#include "bit.hpp"
|
||||
#include "def.hpp"
|
||||
@@ -35,6 +39,20 @@ class Span {
|
||||
|
||||
constexpr Span() noexcept = default;
|
||||
|
||||
#if __has_include(<array>)
|
||||
template<std::size_t sz>
|
||||
constexpr Span(std::array<T, sz> &a) noexcept:
|
||||
m_items(a.data()),
|
||||
m_size(a.size()) {
|
||||
}
|
||||
|
||||
template<std::size_t sz>
|
||||
constexpr Span(std::array<ox::remove_const_t<T>, sz> const&a) noexcept:
|
||||
m_items(a.data()),
|
||||
m_size(a.size()) {
|
||||
}
|
||||
#endif
|
||||
|
||||
template<std::size_t sz>
|
||||
constexpr Span(ox::Array<T, sz> &a) noexcept:
|
||||
m_items(a.data()),
|
||||
@@ -128,12 +146,7 @@ class Span {
|
||||
return iterator<const T&, const T*, true>(m_items, MaxValue<size_type>, m_size);
|
||||
}
|
||||
|
||||
constexpr T &operator[](std::size_t i) noexcept {
|
||||
boundsCheck(__FILE__, __LINE__, i, size(), "Span access overflow");
|
||||
return m_items[i];
|
||||
}
|
||||
|
||||
constexpr T const&operator[](std::size_t i) const noexcept {
|
||||
constexpr T &operator[](std::size_t i) const noexcept {
|
||||
boundsCheck(__FILE__, __LINE__, i, size(), "Span access overflow");
|
||||
return m_items[i];
|
||||
}
|
||||
|
18
deps/ox/src/ox/std/string.hpp
vendored
@@ -28,7 +28,7 @@ OX_CLANG_NOWARN_BEGIN(-Wunsafe-buffer-usage)
|
||||
namespace ox {
|
||||
|
||||
template<typename Integer>
|
||||
constexpr ox::IString<21> itoa(Integer v) noexcept;
|
||||
constexpr ox::IString<21> intToStr(Integer v) noexcept;
|
||||
|
||||
template<std::size_t SmallStringSize_v>
|
||||
class BasicString {
|
||||
@@ -213,22 +213,22 @@ class BasicString {
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr const char *c_str() const noexcept {
|
||||
return static_cast<const char*>(m_buff.data());
|
||||
return m_buff.data();
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline explicit operator const char*() const {
|
||||
constexpr explicit operator const char*() const {
|
||||
return c_str();
|
||||
}
|
||||
|
||||
#if __has_include(<string>)
|
||||
[[nodiscard]]
|
||||
inline std::string toStdString() const {
|
||||
std::string toStdString() const {
|
||||
return c_str();
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline explicit operator std::string() const {
|
||||
explicit operator std::string() const {
|
||||
return c_str();
|
||||
}
|
||||
#endif
|
||||
@@ -317,13 +317,13 @@ constexpr BasicString<SmallStringSize_v> &BasicString<SmallStringSize_v>::operat
|
||||
|
||||
template<std::size_t SmallStringSize_v>
|
||||
constexpr BasicString<SmallStringSize_v> &BasicString<SmallStringSize_v>::operator=(int64_t i) noexcept {
|
||||
set(ox::itoa(i));
|
||||
set(ox::intToStr(i));
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<std::size_t SmallStringSize_v>
|
||||
constexpr BasicString<SmallStringSize_v> &BasicString<SmallStringSize_v>::operator=(uint64_t i) noexcept {
|
||||
set(ox::itoa(i));
|
||||
set(ox::intToStr(i));
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -371,7 +371,7 @@ constexpr BasicString<SmallStringSize_v> &BasicString<SmallStringSize_v>::operat
|
||||
|
||||
template<std::size_t SmallStringSize_v>
|
||||
constexpr BasicString<SmallStringSize_v> &BasicString<SmallStringSize_v>::operator+=(Integer_c auto i) noexcept {
|
||||
auto const str = ox::itoa(i);
|
||||
auto const str = ox::intToStr(i);
|
||||
return this->operator+=(str.c_str());
|
||||
}
|
||||
|
||||
@@ -414,7 +414,7 @@ constexpr BasicString<SmallStringSize_v> BasicString<SmallStringSize_v>::operato
|
||||
|
||||
template<std::size_t SmallStringSize_v>
|
||||
constexpr BasicString<SmallStringSize_v> BasicString<SmallStringSize_v>::operator+(Integer_c auto i) const noexcept {
|
||||
auto const str = ox::itoa(i);
|
||||
auto const str = ox::intToStr(i);
|
||||
return *this + str;
|
||||
}
|
||||
|
||||
|
2
deps/ox/src/ox/std/stringliteral.hpp
vendored
@@ -32,7 +32,9 @@ class StringLiteral: public detail::BaseStringView {
|
||||
|
||||
constexpr explicit StringLiteral(const char *str, std::size_t len) noexcept: BaseStringView(str, len) {}
|
||||
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
constexpr explicit StringLiteral(char const *str) noexcept: StringLiteral(str, ox::strlen(str)) {}
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
|
||||
constexpr StringLiteral &operator=(StringLiteral const&other) noexcept {
|
||||
if (&other != this) {
|
||||
|
2
deps/ox/src/ox/std/stringparam.hpp
vendored
@@ -20,6 +20,8 @@ class StringParam {
|
||||
constexpr StringParam(StringParam &&o) noexcept: m_value{std::move(o.m_value)} {}
|
||||
constexpr StringParam(char const*value) noexcept: m_value{value} {}
|
||||
constexpr StringParam(detail::BaseStringView const&value) noexcept: m_value{value} {}
|
||||
template<size_t sz>
|
||||
constexpr StringParam(ox::IString<sz> const&value) noexcept: m_value{value} {}
|
||||
constexpr StringParam(ox::String const&value) noexcept: m_value{value} {}
|
||||
constexpr StringParam(ox::String &&value) noexcept: m_value{std::move(value)} {}
|
||||
constexpr operator ox::String() && noexcept { return std::move(m_value); }
|
||||
|
4
deps/ox/src/ox/std/stringview.hpp
vendored
@@ -100,7 +100,8 @@ constexpr auto toStdStringView(StringViewCR sv) noexcept {
|
||||
#endif
|
||||
|
||||
|
||||
constexpr ox::Result<int> atoi(ox::StringViewCR str) noexcept {
|
||||
constexpr ox::Result<int> strToInt(ox::StringViewCR str) noexcept {
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
int total = 0;
|
||||
int multiplier = 1;
|
||||
for (auto i = static_cast<int64_t>(str.len()) - 1; i != -1; --i) {
|
||||
@@ -113,6 +114,7 @@ constexpr ox::Result<int> atoi(ox::StringViewCR str) noexcept {
|
||||
}
|
||||
}
|
||||
return total;
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
}
|
||||
|
||||
|
||||
|
4
deps/ox/src/ox/std/strops.cpp
vendored
@@ -9,6 +9,8 @@
|
||||
#include "def.hpp"
|
||||
#include "strops.hpp"
|
||||
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
|
||||
static_assert(ox::strcmp("asdf", "hijk") < 0, "asdf < hijk");
|
||||
static_assert(ox::strcmp("hijk", "asdf") > 0, "hijk > asdf");
|
||||
static_assert(ox::strcmp("resize", "read") > 0, "resize > read");
|
||||
@@ -42,3 +44,5 @@ std::size_t strlen(const char *str) {
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
2
deps/ox/src/ox/std/test/tests.cpp
vendored
@@ -145,6 +145,7 @@ OX_CLANG_NOWARN_END
|
||||
return ox::Error{};
|
||||
}
|
||||
},
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
{
|
||||
"ABCDEFG != HIJKLMN",
|
||||
[]() {
|
||||
@@ -169,6 +170,7 @@ OX_CLANG_NOWARN_END
|
||||
return ox::Error(ox::memcmp("ABCDEFGHI", "ABCDEFG", 7) != 0);
|
||||
}
|
||||
},
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
{
|
||||
"IString",
|
||||
[]() {
|
||||
|
4
deps/ox/src/ox/std/tracehook.cpp
vendored
@@ -39,6 +39,8 @@ enum LogChan {
|
||||
Debug = 4,
|
||||
};
|
||||
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
|
||||
template<LogChan chan>
|
||||
static void log(ox::StringViewCR str) {
|
||||
const auto sz = ox::min<std::size_t>(0x100, str.bytes());
|
||||
@@ -103,5 +105,7 @@ void oxTraceHook([[maybe_unused]] const char *file, [[maybe_unused]] int line,
|
||||
#endif
|
||||
}
|
||||
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
|
||||
}
|
||||
|
||||
|
4
deps/ox/src/ox/std/uuid.hpp
vendored
@@ -105,6 +105,10 @@ class UUID {
|
||||
ox::Array<uint8_t, 16> m_value{};
|
||||
|
||||
public:
|
||||
|
||||
static constexpr auto TypeName = "net.drinkingtea.ox.UUID";
|
||||
static constexpr auto TypeVersion = 1;
|
||||
|
||||
static void seedGenerator(const RandomSeed &seed) noexcept;
|
||||
|
||||
static ox::Result<UUID> generate() noexcept;
|
||||
|
@@ -1,4 +1,31 @@
|
||||
# d2025.02
|
||||
# d2025.06.0
|
||||
|
||||
* PaletteEditor: Add RGB key shortcuts for focusing color channels
|
||||
|
||||
# d2025.05.0
|
||||
|
||||
* Add app icon for both window and file
|
||||
* Change application font to Roboto Medium
|
||||
* Closing application will now confirm with user if any files have unsaved
|
||||
changes.
|
||||
* UUID duplicates will now be reported when opening a project.
|
||||
* Deleting a directory now closes files in that directory.
|
||||
* Delete key now initiates deletion of selected directory.
|
||||
* Remove ability to re-order tabs. There were bugs associated with that.
|
||||
* Mac: Menu bar shortcuts now say Cmd instead of Ctrl.
|
||||
* TileSheetEditor: Fix selection clearing to work when clicking outside image.
|
||||
* TileSheetEditor: Fix Delete Tile functionality, which was completely broken
|
||||
* TileSheetEditor: Fix Insert Tile functionality, which was completely broken
|
||||
* PaletteEditor: Fix color number key range. Previously, pressing A caused the
|
||||
editor to jump to the last color.
|
||||
* PaletteEditor: Page rename will now take effect upon pressing enter if the
|
||||
text input has focus
|
||||
|
||||
# d2025.02.1
|
||||
|
||||
* Fix closing tab with unsaved changes (a44c5acc4b)
|
||||
|
||||
# d2025.02.0
|
||||
|
||||
* Rename core namespace to gfx.
|
||||
* Add PaletteV5 to accommodate namespace change.
|
||||
|
28
sample_project/Palettes/SC9K_Logo.npal
Normal file
@@ -0,0 +1,28 @@
|
||||
K1;3d1a77ec-265f-4905-2061-4f1003ee2189;O1;net.drinkingtea.nostalgia.gfx.Palette;5;{
|
||||
"colorNames" :
|
||||
[
|
||||
"Color 1",
|
||||
"Color 2",
|
||||
"Color 3"
|
||||
],
|
||||
"pages" :
|
||||
[
|
||||
{
|
||||
"colors" :
|
||||
[
|
||||
{
|
||||
"b" : 10,
|
||||
"g" : 5,
|
||||
"r" : 5
|
||||
},
|
||||
{},
|
||||
{
|
||||
"b" : 31,
|
||||
"g" : 31,
|
||||
"r" : 31
|
||||
}
|
||||
],
|
||||
"name" : "Page 1"
|
||||
}
|
||||
]
|
||||
}
|
269
sample_project/TileSheets/NS_Logo16.nts
Normal file
@@ -0,0 +1,269 @@
|
||||
K1;e7ae945e-d6c5-4444-5738-be95b4e5937a;O1;net.drinkingtea.nostalgia.gfx.TileSheet;5;{
|
||||
"bpp" : 4,
|
||||
"defaultPalette" : "uuid://c79f21e2-f74f-4ad9-90ed-32b0ef7da6ed",
|
||||
"subsheet" :
|
||||
{
|
||||
"columns" : 2,
|
||||
"name" : "Root",
|
||||
"pixels" :
|
||||
[
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
3,
|
||||
3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
2,
|
||||
3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
3,
|
||||
2,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
3,
|
||||
3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
"rows" : 2
|
||||
}
|
||||
}
|
1039
sample_project/TileSheets/NS_Logo32.nts
Normal file
4111
sample_project/TileSheets/NS_Logo64.nts
Normal file
@@ -1,14 +0,0 @@
|
||||
/*
|
||||
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "color.hpp"
|
||||
#include "context.hpp"
|
||||
#include "gfx.hpp"
|
||||
#include "initparams.hpp"
|
||||
#include "keelmodule.hpp"
|
||||
#include "palette.hpp"
|
||||
#include "ptidxconv.hpp"
|
||||
#include "tilesheet.hpp"
|
@@ -9,8 +9,14 @@
|
||||
#include <ox/std/types.hpp>
|
||||
#include <ox/model/def.hpp>
|
||||
|
||||
#include "color.hpp"
|
||||
#include "context.hpp"
|
||||
#include "context.hpp"
|
||||
#include "initparams.hpp"
|
||||
#include "keelmodule.hpp"
|
||||
#include "palette.hpp"
|
||||
#include "palette.hpp"
|
||||
#include "ptidxconv.hpp"
|
||||
#include "tilesheet.hpp"
|
||||
|
||||
namespace nostalgia::gfx {
|
||||
@@ -223,7 +229,7 @@ bool bgStatus(Context &ctx, unsigned bg) noexcept;
|
||||
|
||||
void setBgStatus(Context &ctx, unsigned bg, bool status) noexcept;
|
||||
|
||||
void setBgCbb(Context &ctx, unsigned bgIdx, unsigned cbb) noexcept;
|
||||
void setBgCbb(Context &ctx, unsigned bgIdx, unsigned cbbIdx) noexcept;
|
||||
|
||||
void setBgPriority(Context &ctx, uint_t bgIdx, uint_t priority) noexcept;
|
||||
|
||||
@@ -231,14 +237,14 @@ void hideSprite(Context &ctx, unsigned) noexcept;
|
||||
|
||||
void showSprite(Context &ctx, unsigned) noexcept;
|
||||
|
||||
void setSprite(Context &c, uint_t idx, Sprite const&s) noexcept;
|
||||
void setSprite(Context &ctx, uint_t idx, Sprite const&sprite) noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
uint_t spriteCount(Context &ctx) noexcept;
|
||||
uint_t spriteCount(Context const &ctx) noexcept;
|
||||
|
||||
ox::Error initConsole(Context &ctx) noexcept;
|
||||
|
||||
void puts(Context &ctx, int column, int row, ox::StringViewCR str) noexcept;
|
||||
void consoleWrite(Context &ctx, int column, int row, ox::StringViewCR str) noexcept;
|
||||
|
||||
}
|
||||
|
||||
|
@@ -426,6 +426,8 @@ ox::Error resizeSubsheet(TileSheet::SubSheet &ss, ox::Size const&sz) noexcept;
|
||||
[[nodiscard]]
|
||||
TileSheet::SubSheetIdx validateSubSheetIdx(TileSheet const&ts, TileSheet::SubSheetIdx idx) noexcept;
|
||||
|
||||
ox::Result<TileSheet::SubSheetIdx> getSubSheetIdx(TileSheet const &ts, SubSheetId pId) noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
TileSheet::SubSheet &getSubSheet(
|
||||
ox::SpanView<uint32_t> const&idx,
|
||||
|
@@ -4,8 +4,6 @@
|
||||
|
||||
#include <turbine/turbine.hpp>
|
||||
|
||||
#include <nostalgia/gfx/gfx.hpp>
|
||||
|
||||
#include "context.hpp"
|
||||
|
||||
namespace nostalgia::gfx {
|
||||
@@ -22,7 +20,7 @@ ox::Error initGfx(Context &ctx, InitParams const&) noexcept;
|
||||
ox::Result<ox::UPtr<Context>> init(turbine::Context &tctx, InitParams const¶ms) noexcept {
|
||||
auto ctx = ox::make_unique<Context>(tctx);
|
||||
OX_RETURN_ERROR(initGfx(*ctx, params));
|
||||
return ox::UPtr<Context>(std::move(ctx));
|
||||
return ctx;
|
||||
}
|
||||
|
||||
keel::Context &keelCtx(Context &ctx) noexcept {
|
||||
|
@@ -36,9 +36,9 @@ ox::Error initGfx(Context&, InitParams const&) noexcept {
|
||||
|
||||
ox::Error loadBgPalette(
|
||||
Context&,
|
||||
size_t palBank,
|
||||
size_t const palBank,
|
||||
CompactPalette const&palette,
|
||||
size_t page) noexcept {
|
||||
size_t const page) noexcept {
|
||||
if (palette.pages.empty()) {
|
||||
return {};
|
||||
}
|
||||
@@ -52,7 +52,7 @@ ox::Error loadBgPalette(
|
||||
ox::Error loadSpritePalette(
|
||||
Context&,
|
||||
CompactPalette const&palette,
|
||||
size_t page) noexcept {
|
||||
size_t const page) noexcept {
|
||||
if (palette.pages.empty()) {
|
||||
return {};
|
||||
}
|
||||
@@ -133,7 +133,7 @@ ox::Error loadBgTileSheet(
|
||||
|
||||
ox::Error loadBgTileSheet(
|
||||
Context &ctx,
|
||||
unsigned cbb,
|
||||
unsigned const cbb,
|
||||
CompactTileSheet const&ts,
|
||||
ox::Optional<unsigned> const&paletteBank) noexcept {
|
||||
auto const cnt = (ts.pixels.size() * PixelsPerTile) / (1 + (ts.bpp == 4));
|
||||
@@ -184,7 +184,7 @@ static void setSpritesBpp(unsigned const bpp) noexcept {
|
||||
ox::Error loadSpriteTileSheet(
|
||||
Context &ctx,
|
||||
CompactTileSheet const&ts,
|
||||
bool loadDefaultPalette) noexcept {
|
||||
bool const loadDefaultPalette) noexcept {
|
||||
for (size_t i = 0; i < ts.pixels.size(); i += 2) {
|
||||
uint16_t v = ts.pixels[i];
|
||||
v |= static_cast<uint16_t>(ts.pixels[i + 1] << 8);
|
||||
@@ -206,7 +206,8 @@ ox::Error loadSpriteTileSheet(
|
||||
return {};
|
||||
}
|
||||
|
||||
void setBgTile(Context &ctx, uint_t bgIdx, int column, int row, BgTile const&tile) noexcept {
|
||||
void setBgTile(
|
||||
Context &ctx, uint_t const bgIdx, int const column, int const row, BgTile const&tile) noexcept {
|
||||
auto const tileIdx = static_cast<std::size_t>(row * tileColumns(ctx) + column);
|
||||
// see Tonc 9.3
|
||||
MEM_BG_MAP[bgIdx][tileIdx] =
|
||||
@@ -216,7 +217,7 @@ void setBgTile(Context &ctx, uint_t bgIdx, int column, int row, BgTile const&til
|
||||
static_cast<uint16_t>(tile.palBank << 0xc);
|
||||
}
|
||||
|
||||
void clearBg(Context &ctx, uint_t bgIdx) noexcept {
|
||||
void clearBg(Context &ctx, uint_t const bgIdx) noexcept {
|
||||
memset(MEM_BG_MAP[bgIdx].data(), 0, static_cast<size_t>(tileRows(ctx) * tileColumns(ctx)));
|
||||
}
|
||||
|
||||
@@ -224,39 +225,39 @@ uint8_t bgStatus(Context&) noexcept {
|
||||
return (REG_DISPCTL >> 8u) & 0b1111u;
|
||||
}
|
||||
|
||||
void setBgStatus(Context&, uint32_t status) noexcept {
|
||||
void setBgStatus(Context&, uint32_t const status) noexcept {
|
||||
constexpr auto BgStatus = 8;
|
||||
REG_DISPCTL = (REG_DISPCTL & ~0b111100000000u) | status << BgStatus;
|
||||
}
|
||||
|
||||
bool bgStatus(Context&, unsigned bg) noexcept {
|
||||
bool bgStatus(Context&, unsigned const bg) noexcept {
|
||||
return (REG_DISPCTL >> (8 + bg)) & 1;
|
||||
}
|
||||
|
||||
void setBgStatus(Context&, unsigned bg, bool status) noexcept {
|
||||
void setBgStatus(Context&, unsigned const bg, bool const status) noexcept {
|
||||
constexpr auto Bg0Status = 8;
|
||||
const auto mask = static_cast<uint32_t>(status) << (Bg0Status + bg);
|
||||
REG_DISPCTL = REG_DISPCTL | ((REG_DISPCTL & ~mask) | mask);
|
||||
}
|
||||
|
||||
void setBgBpp(Context&, unsigned bgIdx, unsigned bpp) noexcept {
|
||||
void setBgBpp(Context&, unsigned const bgIdx, unsigned const bpp) noexcept {
|
||||
auto &bgCtl = regBgCtl(bgIdx);
|
||||
teagba::bgSetBpp(bgCtl, bpp);
|
||||
}
|
||||
|
||||
void setBgCbb(Context &ctx, unsigned bgIdx, unsigned cbb) noexcept {
|
||||
void setBgCbb(Context &ctx, unsigned const bgIdx, unsigned const cbbIdx) noexcept {
|
||||
auto &bgCtl = regBgCtl(bgIdx);
|
||||
const auto &cbbData = ctx.cbbData[cbb];
|
||||
const auto &cbbData = ctx.cbbData[cbbIdx];
|
||||
teagba::bgSetBpp(bgCtl, cbbData.bpp);
|
||||
teagba::bgSetCbb(bgCtl, cbb);
|
||||
teagba::bgSetCbb(bgCtl, cbbIdx);
|
||||
}
|
||||
|
||||
void setBgPriority(Context&, uint_t bgIdx, uint_t priority) noexcept {
|
||||
void setBgPriority(Context&, uint_t const bgIdx, uint_t const priority) noexcept {
|
||||
auto &bgCtl = regBgCtl(bgIdx);
|
||||
bgCtl = (bgCtl & 0b1111'1111'1111'1100u) | (priority & 0b11);
|
||||
}
|
||||
|
||||
void hideSprite(Context&, unsigned idx) noexcept {
|
||||
void hideSprite(Context&, unsigned const idx) noexcept {
|
||||
//oxAssert(g_spriteUpdates < config::GbaSpriteBufferLen, "Sprite update buffer overflow");
|
||||
teagba::addSpriteUpdate({
|
||||
.attr0 = uint16_t{0b11 << 8},
|
||||
@@ -264,7 +265,7 @@ void hideSprite(Context&, unsigned idx) noexcept {
|
||||
});
|
||||
}
|
||||
|
||||
void showSprite(Context&, unsigned idx) noexcept {
|
||||
void showSprite(Context&, unsigned const idx) noexcept {
|
||||
//oxAssert(g_spriteUpdates < config::GbaSpriteBufferLen, "Sprite update buffer overflow");
|
||||
teagba::addSpriteUpdate({
|
||||
.attr0 = 0,
|
||||
@@ -272,7 +273,7 @@ void showSprite(Context&, unsigned idx) noexcept {
|
||||
});
|
||||
}
|
||||
|
||||
void setSprite(Context&, uint_t idx, Sprite const&s) noexcept {
|
||||
void setSprite(Context&, uint_t const idx, Sprite const&s) noexcept {
|
||||
//oxAssert(g_spriteUpdates < config::GbaSpriteBufferLen, "Sprite update buffer overflow");
|
||||
uint16_t const eightBpp = s.bpp == 8;
|
||||
teagba::addSpriteUpdate({
|
||||
@@ -293,7 +294,7 @@ void setSprite(Context&, uint_t idx, Sprite const&s) noexcept {
|
||||
});
|
||||
}
|
||||
|
||||
uint_t spriteCount(Context&) noexcept {
|
||||
uint_t spriteCount(Context const&) noexcept {
|
||||
return SpriteCount;
|
||||
}
|
||||
|
||||
|
@@ -12,7 +12,7 @@
|
||||
#include <teagba/addresses.hpp>
|
||||
#include <teagba/bios.hpp>
|
||||
|
||||
#include <nostalgia/gfx/core.hpp>
|
||||
#include <nostalgia/gfx/gfx.hpp>
|
||||
|
||||
#include "gfx.hpp"
|
||||
|
||||
@@ -36,13 +36,13 @@ OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
setBgStatus(*ctx, 0, true);
|
||||
clearBg(*ctx, 0);
|
||||
auto const serr = ox::sfmt<ox::IString<23>>("Error code: {}", static_cast<int64_t>(err));
|
||||
puts(*ctx, 32 + 1, 1, "SADNESS...");
|
||||
puts(*ctx, 32 + 1, 4, "UNEXPECTED STATE:");
|
||||
puts(*ctx, 32 + 2, 6, panicMsg);
|
||||
consoleWrite(*ctx, 32 + 1, 1, "SADNESS...");
|
||||
consoleWrite(*ctx, 32 + 1, 4, "UNEXPECTED STATE:");
|
||||
consoleWrite(*ctx, 32 + 2, 6, panicMsg);
|
||||
if (err) {
|
||||
puts(*ctx, 32 + 2, 8, serr);
|
||||
consoleWrite(*ctx, 32 + 2, 8, serr);
|
||||
}
|
||||
puts(*ctx, 32 + 1, 15, "PLEASE RESTART THE SYSTEM");
|
||||
consoleWrite(*ctx, 32 + 1, 15, "PLEASE RESTART THE SYSTEM");
|
||||
// print to terminal if in mGBA
|
||||
oxErrf("\033[31;1;1mPANIC:\033[0m [{}:{}]: {}\n", file, line, panicMsg);
|
||||
if (err.msg) {
|
||||
|
@@ -251,7 +251,7 @@ ox::Error initConsole(Context &ctx) noexcept {
|
||||
return loadBgPalette(ctx, 0, PaletteAddr);
|
||||
}
|
||||
|
||||
void puts(
|
||||
void consoleWrite(
|
||||
Context &ctx,
|
||||
int const column,
|
||||
int const row,
|
||||
|
@@ -14,19 +14,6 @@
|
||||
namespace nostalgia::gfx {
|
||||
|
||||
static class: public keel::Module {
|
||||
private:
|
||||
NostalgiaPaletteToPaletteV1Converter m_nostalgiaPaletteToPaletteV1Converter;
|
||||
PaletteV1ToPaletteV2Converter m_paletteV1ToPaletteV2Converter;
|
||||
PaletteV2ToPaletteV3Converter m_paletteV2ToPaletteV3Converter;
|
||||
PaletteV3ToPaletteV4Converter m_paletteV3ToPaletteV4Converter;
|
||||
PaletteV4ToPaletteV5Converter m_paletteV4ToPaletteV5Converter;
|
||||
PaletteToCompactPaletteConverter m_paletteToCompactPaletteConverter;
|
||||
TileSheetV1ToTileSheetV2Converter m_tileSheetV1ToTileSheetV2Converter;
|
||||
TileSheetV2ToTileSheetV3Converter m_tileSheetV2ToTileSheetV3Converter;
|
||||
TileSheetV3ToTileSheetV4Converter m_tileSheetV3ToTileSheetV4Converter;
|
||||
TileSheetV4ToTileSheetV5Converter m_tileSheetV4ToTileSheetV5Converter;
|
||||
TileSheetToCompactTileSheetConverter m_tileSheetToCompactTileSheetConverter;
|
||||
|
||||
public:
|
||||
[[nodiscard]]
|
||||
ox::String id() const noexcept override {
|
||||
@@ -52,19 +39,19 @@ static class: public keel::Module {
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
ox::Vector<keel::BaseConverter const*> converters() const noexcept final {
|
||||
ox::Vector<keel::Converter> converters() const noexcept final {
|
||||
return {
|
||||
&m_nostalgiaPaletteToPaletteV1Converter,
|
||||
&m_paletteV1ToPaletteV2Converter,
|
||||
&m_paletteV2ToPaletteV3Converter,
|
||||
&m_paletteV3ToPaletteV4Converter,
|
||||
&m_paletteV4ToPaletteV5Converter,
|
||||
&m_paletteToCompactPaletteConverter,
|
||||
&m_tileSheetV1ToTileSheetV2Converter,
|
||||
&m_tileSheetV2ToTileSheetV3Converter,
|
||||
&m_tileSheetV3ToTileSheetV4Converter,
|
||||
&m_tileSheetV4ToTileSheetV5Converter,
|
||||
&m_tileSheetToCompactTileSheetConverter,
|
||||
keel::Converter::make<convertNostalgiaPaletteToPaletteV1>(),
|
||||
keel::Converter::make<convertPaletteV1ToPaletteV2>(),
|
||||
keel::Converter::make<convertPaletteV2ToPaletteV3>(),
|
||||
keel::Converter::make<convertPaletteV3ToPaletteV4>(),
|
||||
keel::Converter::make<convertPaletteV4ToPaletteV5>(),
|
||||
keel::Converter::make<convertPaletteToCompactPalette>(),
|
||||
keel::Converter::make<convertTileSheetV1ToTileSheetV2>(),
|
||||
keel::Converter::make<convertTileSheetV2ToTileSheetV3>(),
|
||||
keel::Converter::make<convertTileSheetV3ToTileSheetV4>(),
|
||||
keel::Converter::make<convertTileSheetV4ToTileSheetV5>(),
|
||||
keel::Converter::make<convertTileSheetToCompactTileSheet>(),
|
||||
};
|
||||
}
|
||||
|
||||
|
@@ -6,26 +6,26 @@
|
||||
|
||||
namespace nostalgia::gfx {
|
||||
|
||||
ox::Error NostalgiaPaletteToPaletteV1Converter::convert(
|
||||
ox::Error convertNostalgiaPaletteToPaletteV1(
|
||||
keel::Context&,
|
||||
NostalgiaPalette &src,
|
||||
PaletteV1 &dst) const noexcept {
|
||||
PaletteV1 &dst) noexcept {
|
||||
dst.colors = std::move(src.colors);
|
||||
return {};
|
||||
}
|
||||
|
||||
ox::Error PaletteV1ToPaletteV2Converter::convert(
|
||||
ox::Error convertPaletteV1ToPaletteV2(
|
||||
keel::Context&,
|
||||
PaletteV1 &src,
|
||||
PaletteV2 &dst) const noexcept {
|
||||
PaletteV2 &dst) noexcept {
|
||||
dst.pages.emplace_back(std::move(src.colors));
|
||||
return {};
|
||||
}
|
||||
|
||||
ox::Error PaletteV2ToPaletteV3Converter::convert(
|
||||
ox::Error convertPaletteV2ToPaletteV3(
|
||||
keel::Context&,
|
||||
PaletteV2 &src,
|
||||
PaletteV3 &dst) const noexcept {
|
||||
PaletteV3 &dst) noexcept {
|
||||
dst.pages = std::move(src.pages);
|
||||
if (!dst.pages.empty()) {
|
||||
dst.colorInfo.reserve(dst.pages[0].size());
|
||||
@@ -36,10 +36,10 @@ ox::Error PaletteV2ToPaletteV3Converter::convert(
|
||||
return {};
|
||||
}
|
||||
|
||||
ox::Error PaletteV3ToPaletteV4Converter::convert(
|
||||
ox::Error convertPaletteV3ToPaletteV4(
|
||||
keel::Context&,
|
||||
PaletteV3 &src,
|
||||
PaletteV4 &dst) const noexcept {
|
||||
PaletteV4 &dst) noexcept {
|
||||
dst.pages.reserve(src.pages.size());
|
||||
for (auto i = 1; auto &page : src.pages) {
|
||||
dst.pages.emplace_back(ox::sfmt("Page {}", i), std::move(page));
|
||||
@@ -52,10 +52,10 @@ ox::Error PaletteV3ToPaletteV4Converter::convert(
|
||||
return {};
|
||||
}
|
||||
|
||||
ox::Error PaletteV4ToPaletteV5Converter::convert(
|
||||
ox::Error convertPaletteV4ToPaletteV5(
|
||||
keel::Context&,
|
||||
PaletteV4 &src,
|
||||
PaletteV5 &dst) const noexcept {
|
||||
PaletteV5 &dst) noexcept {
|
||||
dst.colorNames = std::move(src.colorNames);
|
||||
dst.pages.reserve(src.pages.size());
|
||||
for (auto &s : src.pages) {
|
||||
@@ -72,10 +72,10 @@ ox::Error PaletteV4ToPaletteV5Converter::convert(
|
||||
return {};
|
||||
}
|
||||
|
||||
ox::Error PaletteToCompactPaletteConverter::convert(
|
||||
ox::Error convertPaletteToCompactPalette(
|
||||
keel::Context&,
|
||||
Palette &src,
|
||||
CompactPalette &dst) const noexcept {
|
||||
CompactPalette &dst) noexcept {
|
||||
dst.pages.reserve(src.pages.size());
|
||||
for (auto &page : src.pages) {
|
||||
auto &p = dst.pages.emplace_back();
|
||||
@@ -86,10 +86,10 @@ ox::Error PaletteToCompactPaletteConverter::convert(
|
||||
return {};
|
||||
}
|
||||
|
||||
ox::Error TileSheetV1ToTileSheetV2Converter::convert(
|
||||
ox::Error convertTileSheetV1ToTileSheetV2(
|
||||
keel::Context&,
|
||||
TileSheetV1 &src,
|
||||
TileSheetV2 &dst) const noexcept {
|
||||
TileSheetV2 &dst) noexcept {
|
||||
dst.bpp = src.bpp;
|
||||
dst.defaultPalette = std::move(src.defaultPalette);
|
||||
dst.subsheet.name = "Root";
|
||||
@@ -99,7 +99,7 @@ ox::Error TileSheetV1ToTileSheetV2Converter::convert(
|
||||
return {};
|
||||
}
|
||||
|
||||
void TileSheetV2ToTileSheetV3Converter::convertSubsheet(
|
||||
static void convertSubsheet(
|
||||
TileSheetV2::SubSheet &src,
|
||||
TileSheetV3::SubSheet &dst,
|
||||
SubSheetId &idIt) noexcept {
|
||||
@@ -115,10 +115,10 @@ void TileSheetV2ToTileSheetV3Converter::convertSubsheet(
|
||||
}
|
||||
}
|
||||
|
||||
ox::Error TileSheetV2ToTileSheetV3Converter::convert(
|
||||
ox::Error convertTileSheetV2ToTileSheetV3(
|
||||
keel::Context&,
|
||||
TileSheetV2 &src,
|
||||
TileSheetV3 &dst) const noexcept {
|
||||
TileSheetV3 &dst) noexcept {
|
||||
dst.bpp = src.bpp;
|
||||
dst.defaultPalette = std::move(src.defaultPalette);
|
||||
convertSubsheet(src.subsheet, dst.subsheet, dst.idIt);
|
||||
@@ -126,7 +126,7 @@ ox::Error TileSheetV2ToTileSheetV3Converter::convert(
|
||||
}
|
||||
|
||||
|
||||
void TileSheetV3ToTileSheetV4Converter::convertSubsheet(
|
||||
static void convertSubsheet(
|
||||
TileSheetV3::SubSheet &src,
|
||||
TileSheetV4::SubSheet &dst,
|
||||
SubSheetId &idIt) noexcept {
|
||||
@@ -142,10 +142,10 @@ void TileSheetV3ToTileSheetV4Converter::convertSubsheet(
|
||||
}
|
||||
}
|
||||
|
||||
ox::Error TileSheetV3ToTileSheetV4Converter::convert(
|
||||
ox::Error convertTileSheetV3ToTileSheetV4(
|
||||
keel::Context&,
|
||||
TileSheetV3 &src,
|
||||
TileSheetV4 &dst) const noexcept {
|
||||
TileSheetV4 &dst) noexcept {
|
||||
dst.bpp = src.bpp;
|
||||
dst.idIt = src.idIt;
|
||||
dst.defaultPalette = std::move(src.defaultPalette);
|
||||
@@ -154,7 +154,7 @@ ox::Error TileSheetV3ToTileSheetV4Converter::convert(
|
||||
}
|
||||
|
||||
|
||||
void TileSheetV4ToTileSheetV5Converter::convertSubsheet(
|
||||
static void convertSubsheet(
|
||||
int const bpp,
|
||||
TileSheetV4::SubSheet &src,
|
||||
TileSheetV5::SubSheet &dst) noexcept {
|
||||
@@ -179,22 +179,22 @@ void TileSheetV4ToTileSheetV5Converter::convertSubsheet(
|
||||
}
|
||||
}
|
||||
|
||||
ox::Error TileSheetV4ToTileSheetV5Converter::convert(
|
||||
ox::Error convertTileSheetV4ToTileSheetV5(
|
||||
keel::Context&,
|
||||
TileSheetV4 &src,
|
||||
TileSheetV5 &dst) const noexcept {
|
||||
dst.bpp = src.bpp;
|
||||
dst.idIt = src.idIt;
|
||||
TileSheetV5 &dst) noexcept {
|
||||
dst.bpp = src.bpp;
|
||||
dst.idIt = src.idIt;
|
||||
OX_RETURN_ERROR(src.defaultPalette.getPath().moveTo(dst.defaultPalette));
|
||||
convertSubsheet(dst.bpp, src.subsheet, dst.subsheet);
|
||||
return {};
|
||||
}
|
||||
|
||||
|
||||
ox::Error TileSheetToCompactTileSheetConverter::convert(
|
||||
ox::Error convertTileSheetToCompactTileSheet(
|
||||
keel::Context&,
|
||||
TileSheet &src,
|
||||
CompactTileSheet &dst) const noexcept {
|
||||
CompactTileSheet &dst) noexcept {
|
||||
dst.bpp = src.bpp;
|
||||
dst.defaultPalette = ox::FileAddress{src.defaultPalette};
|
||||
dst.pixels = pixels(src);
|
||||
|
@@ -16,60 +16,26 @@ namespace nostalgia::gfx {
|
||||
|
||||
// Type converters
|
||||
|
||||
class NostalgiaPaletteToPaletteV1Converter: public keel::Converter<NostalgiaPalette, PaletteV1> {
|
||||
ox::Error convert(keel::Context&, NostalgiaPalette &src, PaletteV1 &dst) const noexcept final;
|
||||
};
|
||||
ox::Error convertNostalgiaPaletteToPaletteV1(keel::Context&, NostalgiaPalette &src, PaletteV1 &dst) noexcept;
|
||||
|
||||
class PaletteV1ToPaletteV2Converter: public keel::Converter<PaletteV1, PaletteV2> {
|
||||
ox::Error convert(keel::Context&, PaletteV1 &src, PaletteV2 &dst) const noexcept final;
|
||||
};
|
||||
ox::Error convertPaletteV1ToPaletteV2(keel::Context&, PaletteV1 &src, PaletteV2 &dst) noexcept;
|
||||
|
||||
class PaletteV2ToPaletteV3Converter: public keel::Converter<PaletteV2, PaletteV3> {
|
||||
ox::Error convert(keel::Context&, PaletteV2 &src, PaletteV3 &dst) const noexcept final;
|
||||
};
|
||||
ox::Error convertPaletteV2ToPaletteV3(keel::Context&, PaletteV2 &src, PaletteV3 &dst) noexcept;
|
||||
|
||||
class PaletteV3ToPaletteV4Converter: public keel::Converter<PaletteV3, PaletteV4> {
|
||||
ox::Error convert(keel::Context&, PaletteV3 &src, PaletteV4 &dst) const noexcept final;
|
||||
};
|
||||
ox::Error convertPaletteV3ToPaletteV4(keel::Context&, PaletteV3 &src, PaletteV4 &dst) noexcept;
|
||||
|
||||
class PaletteV4ToPaletteV5Converter: public keel::Converter<PaletteV4, PaletteV5> {
|
||||
ox::Error convert(keel::Context&, PaletteV4 &src, PaletteV5 &dst) const noexcept final;
|
||||
};
|
||||
ox::Error convertPaletteV4ToPaletteV5(keel::Context&, PaletteV4 &src, PaletteV5 &dst) noexcept;
|
||||
|
||||
class PaletteToCompactPaletteConverter: public keel::Converter<Palette, CompactPalette> {
|
||||
ox::Error convert(keel::Context&, Palette &src, CompactPalette &dst) const noexcept final;
|
||||
};
|
||||
ox::Error convertPaletteToCompactPalette(keel::Context&, Palette &src, CompactPalette &dst) noexcept;
|
||||
|
||||
class TileSheetV1ToTileSheetV2Converter: public keel::Converter<TileSheetV1, TileSheetV2> {
|
||||
ox::Error convert(keel::Context&, TileSheetV1 &src, TileSheetV2 &dst) const noexcept final;
|
||||
};
|
||||
ox::Error convertTileSheetV1ToTileSheetV2(keel::Context&, TileSheetV1 &src, TileSheetV2 &dst) noexcept;
|
||||
|
||||
class TileSheetV2ToTileSheetV3Converter: public keel::Converter<TileSheetV2, TileSheetV3> {
|
||||
static void convertSubsheet(
|
||||
TileSheetV2::SubSheet &src,
|
||||
TileSheetV3::SubSheet &dst,
|
||||
SubSheetId &idIt) noexcept;
|
||||
ox::Error convert(keel::Context&, TileSheetV2 &src, TileSheetV3 &dst) const noexcept final;
|
||||
};
|
||||
ox::Error convertTileSheetV2ToTileSheetV3(keel::Context&, TileSheetV2 &src, TileSheetV3 &dst) noexcept;
|
||||
|
||||
class TileSheetV3ToTileSheetV4Converter: public keel::Converter<TileSheetV3, TileSheetV4> {
|
||||
static void convertSubsheet(
|
||||
TileSheetV3::SubSheet &src,
|
||||
TileSheetV4::SubSheet &dst,
|
||||
SubSheetId &idIt) noexcept;
|
||||
ox::Error convert(keel::Context&, TileSheetV3 &src, TileSheetV4 &dst) const noexcept final;
|
||||
};
|
||||
ox::Error convertTileSheetV3ToTileSheetV4(keel::Context&, TileSheetV3 &src, TileSheetV4 &dst) noexcept;
|
||||
|
||||
class TileSheetV4ToTileSheetV5Converter final: public keel::Converter<TileSheetV4, TileSheetV5> {
|
||||
static void convertSubsheet(
|
||||
int bpp,
|
||||
TileSheetV4::SubSheet &src,
|
||||
TileSheetV5::SubSheet &dst) noexcept;
|
||||
ox::Error convert(keel::Context&, TileSheetV4 &src, TileSheetV5 &dst) const noexcept override;
|
||||
};
|
||||
ox::Error convertTileSheetV4ToTileSheetV5(keel::Context&, TileSheetV4 &src, TileSheetV5 &dst) noexcept;
|
||||
|
||||
class TileSheetToCompactTileSheetConverter: public keel::Converter<TileSheet, CompactTileSheet> {
|
||||
ox::Error convert(keel::Context&, TileSheet &src, CompactTileSheet &dst) const noexcept final;
|
||||
};
|
||||
ox::Error convertTileSheetToCompactTileSheet(keel::Context&, TileSheet &src, CompactTileSheet &dst) noexcept;
|
||||
|
||||
}
|
||||
|
@@ -26,7 +26,7 @@ Context::~Context() noexcept {
|
||||
ox::Result<ox::UPtr<Context>> init(turbine::Context &tctx, InitParams const¶ms) noexcept {
|
||||
auto ctx = ox::make_unique<Context>(tctx, params);
|
||||
OX_RETURN_ERROR(initGfx(*ctx, params));
|
||||
return ox::UPtr<Context>(ctx.release());
|
||||
return ctx;
|
||||
}
|
||||
|
||||
keel::Context &keelCtx(Context &ctx) noexcept {
|
||||
|
@@ -28,7 +28,7 @@ static constexpr auto PriorityScale = 0.01f;
|
||||
Drawer::Drawer(Context &ctx) noexcept: m_ctx(ctx) {}
|
||||
|
||||
void Drawer::draw(turbine::Context &tctx) noexcept {
|
||||
gfx::gl::draw(m_ctx, turbine::getScreenSize(tctx));
|
||||
gl::draw(m_ctx, turbine::getScreenSize(tctx));
|
||||
}
|
||||
|
||||
static constexpr ox::CStringView bgvshadTmpl = R"glsl(
|
||||
@@ -106,7 +106,7 @@ static constexpr ox::CStringView spritefshadTmpl = R"glsl(
|
||||
})glsl";
|
||||
|
||||
[[nodiscard]]
|
||||
static constexpr auto bgVertexRow(uint_t x, uint_t y) noexcept {
|
||||
static constexpr auto bgVertexRow(uint_t const x, uint_t const y) noexcept {
|
||||
return y * TileRows + x;
|
||||
}
|
||||
|
||||
@@ -183,7 +183,7 @@ static void setTileBufferObject(
|
||||
ox::spancpy<GLuint>(ebo, elms);
|
||||
}
|
||||
|
||||
static void initSpriteBufferObjects(Context &ctx, glutils::BufferSet &bs) noexcept {
|
||||
static void initSpriteBufferObjects(Context const &ctx, glutils::BufferSet &bs) noexcept {
|
||||
for (auto i = 0u; i < ctx.spriteCount; ++i) {
|
||||
auto const vbo = ox::Span{bs.vertices}
|
||||
+ i * static_cast<std::size_t>(SpriteVertexVboLength);
|
||||
@@ -256,7 +256,7 @@ static void initSpritesBufferset(Context &ctx) noexcept {
|
||||
}
|
||||
|
||||
static void initBackgroundBufferset(
|
||||
GLuint shader,
|
||||
GLuint const shader,
|
||||
glutils::BufferSet &bs) noexcept {
|
||||
// vao
|
||||
bs.vao = glutils::generateVertexArrayObject();
|
||||
@@ -290,8 +290,8 @@ static void initBackgroundBufferset(
|
||||
}
|
||||
|
||||
static glutils::GLTexture createTexture(
|
||||
GLsizei w,
|
||||
GLsizei h,
|
||||
GLsizei const w,
|
||||
GLsizei const h,
|
||||
void const*pixels) noexcept {
|
||||
GLuint texId = 0;
|
||||
glGenTextures(1, &texId);
|
||||
@@ -375,10 +375,10 @@ static void drawSprites(Context &ctx, ox::Size const&renderSz) noexcept {
|
||||
|
||||
static void loadPalette(
|
||||
ox::Array<GLfloat, 1024> &palette,
|
||||
size_t palOffset,
|
||||
GLuint shaderPgrm,
|
||||
size_t const palOffset,
|
||||
GLuint const shaderPgrm,
|
||||
CompactPalette const&pal,
|
||||
size_t page = 0) noexcept {
|
||||
size_t const page = 0) noexcept {
|
||||
static constexpr std::size_t ColorCnt = 256;
|
||||
for (auto i = palOffset; auto const c : pal.pages[page]) {
|
||||
palette[i++] = redf(c);
|
||||
@@ -523,14 +523,18 @@ static ox::Result<TileSheetData> normalizeTileSheet(
|
||||
pixels[i * 2 + 1] = ts.pixels[i] >> 4;
|
||||
}
|
||||
}
|
||||
return TileSheetData{std::move(pixels), width, height};
|
||||
return TileSheetData{
|
||||
.pixels = std::move(pixels),
|
||||
.width = width,
|
||||
.height = height
|
||||
};
|
||||
}
|
||||
|
||||
ox::Error loadBgPalette(
|
||||
Context &ctx,
|
||||
size_t palBank,
|
||||
size_t const palBank,
|
||||
CompactPalette const&palette,
|
||||
size_t page) noexcept {
|
||||
size_t const page) noexcept {
|
||||
renderer::loadPalette(ctx.bgPalette, palBank * 16 * 4, ctx.bgShader, palette, page);
|
||||
return {};
|
||||
}
|
||||
@@ -538,14 +542,14 @@ ox::Error loadBgPalette(
|
||||
ox::Error loadSpritePalette(
|
||||
Context &ctx,
|
||||
CompactPalette const&palette,
|
||||
size_t page) noexcept {
|
||||
size_t const page) noexcept {
|
||||
ox::Array<GLfloat, 1024> pal;
|
||||
renderer::loadPalette(pal, 0, ctx.spriteShader, palette, page);
|
||||
return {};
|
||||
}
|
||||
|
||||
static ox::Result<TileSheetData> buildSetTsd(
|
||||
Context &ctx,
|
||||
Context const &ctx,
|
||||
TileSheetSet const&set) noexcept {
|
||||
auto &kctx = keelCtx(ctx.turbineCtx);
|
||||
TileSheetData setTsd;
|
||||
@@ -567,7 +571,7 @@ static ox::Result<TileSheetData> buildSetTsd(
|
||||
|
||||
static void copyPixels(
|
||||
CompactTileSheet const&ts,
|
||||
ox::Span<uint32_t> dst,
|
||||
ox::Span<uint32_t> const dst,
|
||||
size_t const srcPxIdx,
|
||||
size_t const pxlCnt) noexcept {
|
||||
size_t idx{};
|
||||
@@ -624,7 +628,7 @@ ox::Error loadBgTileSheet(
|
||||
|
||||
ox::Error loadBgTileSheet(
|
||||
Context &ctx,
|
||||
uint_t cbb,
|
||||
uint_t const cbb,
|
||||
CompactTileSheet const&ts,
|
||||
ox::Optional<unsigned> const&paletteBank) noexcept {
|
||||
auto const bytesPerTile = static_cast<uint64_t>(PixelsPerTile / (1 + (ts.bpp == 4)));
|
||||
@@ -638,7 +642,7 @@ ox::Error loadBgTileSheet(
|
||||
|
||||
ox::Error loadBgTileSheet(
|
||||
Context &ctx,
|
||||
unsigned cbb,
|
||||
unsigned const cbb,
|
||||
TileSheetSet const&set) noexcept {
|
||||
OX_REQUIRE(setTsd, buildSetTsd(ctx, set));
|
||||
ctx.cbbs[cbb].tex = renderer::createTexture(setTsd.width, setTsd.height, setTsd.pixels.data());
|
||||
@@ -648,7 +652,7 @@ ox::Error loadBgTileSheet(
|
||||
ox::Error loadSpriteTileSheet(
|
||||
Context &ctx,
|
||||
CompactTileSheet const&ts,
|
||||
bool loadDefaultPalette) noexcept {
|
||||
bool const loadDefaultPalette) noexcept {
|
||||
OX_REQUIRE(tsd, normalizeTileSheet(ts));
|
||||
oxTracef("nostalgia.gfx.gl", "loadSpriteTexture: { w: {}, h: {} }", tsd.width, tsd.height);
|
||||
ctx.spriteBlocks.tex = renderer::createTexture(tsd.width, tsd.height, tsd.pixels.data());
|
||||
@@ -668,9 +672,9 @@ ox::Error loadSpriteTileSheet(
|
||||
|
||||
void setBgTile(
|
||||
Context &ctx,
|
||||
uint_t bgIdx,
|
||||
int column,
|
||||
int row,
|
||||
uint_t const bgIdx,
|
||||
int const column,
|
||||
int const row,
|
||||
BgTile const&tile) noexcept {
|
||||
oxTracef(
|
||||
"nostalgia.gfx.setBgTile",
|
||||
@@ -698,7 +702,7 @@ void setBgTile(
|
||||
cbb.updated = true;
|
||||
}
|
||||
|
||||
void clearBg(Context &ctx, uint_t bgIdx) noexcept {
|
||||
void clearBg(Context &ctx, uint_t const bgIdx) noexcept {
|
||||
auto &cbb = ctx.cbbs[static_cast<std::size_t>(bgIdx)];
|
||||
initBackgroundBufferObjects(cbb);
|
||||
cbb.updated = true;
|
||||
@@ -714,61 +718,59 @@ uint8_t bgStatus(Context &ctx) noexcept {
|
||||
return out;
|
||||
}
|
||||
|
||||
void setBgStatus(Context &ctx, uint32_t status) noexcept {
|
||||
void setBgStatus(Context &ctx, uint32_t const status) noexcept {
|
||||
for (uint_t i = 0; i < ctx.cbbs.size(); ++i) {
|
||||
ctx.backgrounds[i].enabled = (status >> i) & 1;
|
||||
}
|
||||
}
|
||||
|
||||
bool bgStatus(Context &ctx, uint_t bg) noexcept {
|
||||
bool bgStatus(Context &ctx, uint_t const bg) noexcept {
|
||||
return ctx.backgrounds[bg].enabled;
|
||||
}
|
||||
|
||||
void setBgStatus(Context&ctx, uint_t bg, bool status) noexcept {
|
||||
void setBgStatus(Context&ctx, uint_t const bg, bool const status) noexcept {
|
||||
ctx.backgrounds[bg].enabled = status;
|
||||
}
|
||||
|
||||
void setBgBpp(Context&, unsigned, unsigned) noexcept {}
|
||||
|
||||
void setBgCbb(Context &ctx, uint_t bgIdx, uint_t cbbIdx) noexcept {
|
||||
void setBgCbb(Context &ctx, uint_t const bgIdx, uint_t const cbbIdx) noexcept {
|
||||
auto &bg = ctx.backgrounds[bgIdx];
|
||||
bg.cbbIdx = cbbIdx;
|
||||
}
|
||||
|
||||
void setBgPriority(Context &ctx, uint_t bgIdx, uint_t priority) noexcept {
|
||||
void setBgPriority(Context &ctx, uint_t const bgIdx, uint_t const priority) noexcept {
|
||||
auto &bg = ctx.backgrounds[bgIdx];
|
||||
bg.priority = static_cast<float>(priority & 0b11);
|
||||
}
|
||||
|
||||
void hideSprite(Context &ctx, uint_t idx) noexcept {
|
||||
void hideSprite(Context &ctx, uint_t const idx) noexcept {
|
||||
auto &s = ctx.spriteStates[idx];
|
||||
s.enabled = false;
|
||||
renderer::setSprite(ctx, idx, s);
|
||||
}
|
||||
|
||||
void showSprite(Context &ctx, uint_t idx) noexcept {
|
||||
void showSprite(Context &ctx, uint_t const idx) noexcept {
|
||||
auto &s = ctx.spriteStates[idx];
|
||||
s.enabled = true;
|
||||
renderer::setSprite(ctx, idx, s);
|
||||
}
|
||||
|
||||
void setSprite(Context &ctx, uint_t idx, Sprite const&sprite) noexcept {
|
||||
void setSprite(Context &ctx, uint_t const idx, Sprite const&sprite) noexcept {
|
||||
auto &s = ctx.spriteStates[idx];
|
||||
s = sprite;
|
||||
renderer::setSprite(ctx, idx, s);
|
||||
}
|
||||
|
||||
uint_t spriteCount(Context &ctx) noexcept {
|
||||
uint_t spriteCount(Context const &ctx) noexcept {
|
||||
return ctx.spriteCount;
|
||||
}
|
||||
|
||||
namespace gl {
|
||||
|
||||
ox::Size drawSize(int scale) noexcept {
|
||||
ox::Size drawSize(int const scale) noexcept {
|
||||
return {240 * scale, 160 * scale};
|
||||
}
|
||||
|
||||
void draw(gfx::Context &ctx, ox::Size const&renderSz) noexcept {
|
||||
void draw(Context &ctx, ox::Size const&renderSz) noexcept {
|
||||
glViewport(0, 0, renderSz.width, renderSz.height);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glEnable(GL_BLEND);
|
||||
@@ -783,7 +785,7 @@ void draw(gfx::Context &ctx, ox::Size const&renderSz) noexcept {
|
||||
glDisable(GL_BLEND);
|
||||
}
|
||||
|
||||
void draw(gfx::Context &ctx, int scale) noexcept {
|
||||
void draw(Context &ctx, int const scale) noexcept {
|
||||
draw(ctx, drawSize(scale));
|
||||
}
|
||||
|
||||
|
@@ -50,22 +50,25 @@ void PaletteEditorImGui::PageRenameDialog::draw(turbine::Context &tctx) noexcept
|
||||
return;
|
||||
}
|
||||
if (ig::BeginPopup(tctx, "Rename Page", m_show)) {
|
||||
if (ImGui::IsWindowAppearing()) {
|
||||
ImGui::SetKeyboardFocusHere();
|
||||
}
|
||||
ig::InputText("Name", m_name);
|
||||
switch (ig::PopupControlsOkCancel(m_show)) {
|
||||
case ig::PopupResponse::OK:
|
||||
inputSubmitted.emit(m_name);
|
||||
[[fallthrough]];
|
||||
case ig::PopupResponse::Cancel:
|
||||
close();
|
||||
default:
|
||||
break;
|
||||
auto const nameInputFocused = ImGui::IsItemFocused();
|
||||
auto const resp = ig::PopupControlsOkCancel(m_show);
|
||||
if ((nameInputFocused && ImGui::IsKeyPressed(ImGuiKey_Enter))
|
||||
|| resp == ig::PopupResponse::OK) {
|
||||
inputSubmitted.emit(m_name);
|
||||
close();
|
||||
} else if (resp == ig::PopupResponse::Cancel) {
|
||||
close();
|
||||
}
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
PaletteEditorImGui::PaletteEditorImGui(studio::StudioContext &sctx, ox::StringParam path):
|
||||
PaletteEditorImGui::PaletteEditorImGui(studio::Context &sctx, ox::StringParam path):
|
||||
Editor(sctx, std::move(path)),
|
||||
m_sctx(sctx),
|
||||
m_tctx(sctx.tctx),
|
||||
@@ -74,7 +77,7 @@ PaletteEditorImGui::PaletteEditorImGui(studio::StudioContext &sctx, ox::StringPa
|
||||
m_pageRenameDlg.inputSubmitted.connect(this, &PaletteEditorImGui::renamePage);
|
||||
}
|
||||
|
||||
void PaletteEditorImGui::draw(studio::StudioContext&) noexcept {
|
||||
void PaletteEditorImGui::draw(studio::Context&) noexcept {
|
||||
auto const paneSize = ImGui::GetContentRegionAvail();
|
||||
{
|
||||
ImGui::BeginChild("Pages", {280, paneSize.y}, true);
|
||||
@@ -102,25 +105,25 @@ void PaletteEditorImGui::navigateTo(ox::StringViewCR arg) noexcept {
|
||||
auto const &color = args[0];
|
||||
auto const &page = args[1];
|
||||
{
|
||||
auto const [c, err] = atoi(color);
|
||||
auto const [c, err] = strToInt(color);
|
||||
if (!err && static_cast<size_t>(c) < colorCnt(m_pal)) {
|
||||
m_selectedColorRow = static_cast<size_t>(c);
|
||||
}
|
||||
}
|
||||
{
|
||||
auto const [pg, err] = atoi(page);
|
||||
auto const [pg, err] = strToInt(page);
|
||||
if (!err && static_cast<size_t>(pg) < m_pal.pages.size()) {
|
||||
m_page = static_cast<size_t>(pg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PaletteEditorImGui::drawColumnLeftAlign(ox::CStringView txt) noexcept {
|
||||
void PaletteEditorImGui::drawColumnLeftAlign(ox::CStringViewCR txt) noexcept {
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("%s", txt.c_str());
|
||||
}
|
||||
|
||||
void PaletteEditorImGui::drawColumn(ox::CStringView txt) noexcept {
|
||||
void PaletteEditorImGui::drawColumn(ox::CStringViewCR txt) noexcept {
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::SetCursorPosX(
|
||||
ImGui::GetCursorPosX() + ImGui::GetColumnWidth() - ImGui::CalcTextSize(txt.data()).x);
|
||||
@@ -131,7 +134,7 @@ void PaletteEditorImGui::numShortcuts(size_t &val, size_t const sizeRange) noexc
|
||||
auto const lastElem = sizeRange - 1;
|
||||
if (ImGui::IsKeyPressed(ImGuiKey_0)) {
|
||||
val = ox::min<size_t>(9, lastElem);
|
||||
} else for (auto i = 9u; i < 10; --i) {
|
||||
} else for (auto i = 8u; i < 9; --i) {
|
||||
auto const key = static_cast<ImGuiKey>(ImGuiKey_1 + i);
|
||||
if (ImGui::IsKeyPressed(key)) {
|
||||
val = ox::min<size_t>(i, lastElem);
|
||||
@@ -140,7 +143,15 @@ void PaletteEditorImGui::numShortcuts(size_t &val, size_t const sizeRange) noexc
|
||||
}
|
||||
}
|
||||
|
||||
void PaletteEditorImGui::colorInput(ox::CStringView label, int &v, bool &inputFocused) noexcept {
|
||||
void PaletteEditorImGui::colorInput(
|
||||
ox::CStringViewCR label,
|
||||
int &v,
|
||||
bool &inputFocused,
|
||||
FocusCmd const colorChannel) noexcept {
|
||||
if (colorChannel == m_focusCmd) [[unlikely]] {
|
||||
ImGui::SetKeyboardFocusHere();
|
||||
m_focusCmd = FocusCmd::None;
|
||||
}
|
||||
ImGui::InputInt(label.c_str(), &v, 1, 5);
|
||||
inputFocused = inputFocused || ImGui::IsItemFocused();
|
||||
v = ox::max(v, 0);
|
||||
@@ -293,9 +304,9 @@ void PaletteEditorImGui::drawColorEditor() noexcept {
|
||||
"Name", m_pal.colorNames[m_selectedColorRow]);
|
||||
bool inputFocused = ImGui::IsItemFocused();
|
||||
ImGui::Separator();
|
||||
colorInput("Red", r, inputFocused);
|
||||
colorInput("Green", g, inputFocused);
|
||||
colorInput("Blue", b, inputFocused);
|
||||
colorInput("Red", r, inputFocused, FocusCmd::Red);
|
||||
colorInput("Green", g, inputFocused, FocusCmd::Green);
|
||||
colorInput("Blue", b, inputFocused, FocusCmd::Blue);
|
||||
if (ig::PushButton("Apply to all pages", {-1, ig::BtnSz.y})) {
|
||||
std::ignore = pushCommand<ApplyColorAllPagesCommand>(
|
||||
m_pal, m_page, m_selectedColorRow);
|
||||
@@ -306,6 +317,15 @@ void PaletteEditorImGui::drawColorEditor() noexcept {
|
||||
} else {
|
||||
numShortcuts(m_page, m_pal.pages.size());
|
||||
}
|
||||
if (ImGui::IsKeyDown(ImGuiKey_R)) {
|
||||
m_focusCmd = FocusCmd::Red;
|
||||
}
|
||||
if (ImGui::IsKeyDown(ImGuiKey_G)) {
|
||||
m_focusCmd = FocusCmd::Green;
|
||||
}
|
||||
if (ImGui::IsKeyDown(ImGuiKey_B)) {
|
||||
m_focusCmd = FocusCmd::Blue;
|
||||
}
|
||||
}
|
||||
auto const newColor = color16(r, g, b, a);
|
||||
if (c != newColor) {
|
||||
@@ -317,7 +337,7 @@ void PaletteEditorImGui::drawColorEditor() noexcept {
|
||||
}
|
||||
}
|
||||
|
||||
ox::Error PaletteEditorImGui::renamePage(ox::StringView name) noexcept {
|
||||
ox::Error PaletteEditorImGui::renamePage(ox::StringViewCR name) noexcept {
|
||||
return pushCommand<RenamePageCommand>(m_pal, m_page, name);
|
||||
}
|
||||
|
||||
|
@@ -31,16 +31,23 @@ class PaletteEditorImGui: public studio::Editor {
|
||||
constexpr bool isOpen() const noexcept { return m_show; }
|
||||
void draw(turbine::Context &tctx) noexcept;
|
||||
} m_pageRenameDlg;
|
||||
studio::StudioContext &m_sctx;
|
||||
studio::Context &m_sctx;
|
||||
turbine::Context &m_tctx;
|
||||
Palette m_pal;
|
||||
size_t m_selectedColorRow = 0;
|
||||
size_t m_page = 0;
|
||||
enum class FocusCmd {
|
||||
None,
|
||||
Red,
|
||||
Green,
|
||||
Blue,
|
||||
};
|
||||
FocusCmd m_focusCmd;
|
||||
|
||||
public:
|
||||
PaletteEditorImGui(studio::StudioContext &sctx, ox::StringParam path);
|
||||
PaletteEditorImGui(studio::Context &sctx, ox::StringParam path);
|
||||
|
||||
void draw(studio::StudioContext&) noexcept final;
|
||||
void draw(studio::Context&) noexcept final;
|
||||
|
||||
protected:
|
||||
ox::Error saveItem() noexcept final;
|
||||
@@ -48,17 +55,17 @@ class PaletteEditorImGui: public studio::Editor {
|
||||
void navigateTo(ox::StringViewCR arg) noexcept override;
|
||||
|
||||
private:
|
||||
static void drawColumnLeftAlign(ox::CStringView txt) noexcept;
|
||||
static void drawColumnLeftAlign(ox::CStringViewCR txt) noexcept;
|
||||
|
||||
static void drawColumn(ox::CStringView txt) noexcept;
|
||||
static void drawColumn(ox::CStringViewCR txt) noexcept;
|
||||
|
||||
static void drawColumn(ox::Integer_c auto i) noexcept {
|
||||
drawColumn(ox::itoa(i));
|
||||
drawColumn(ox::intToStr(i));
|
||||
}
|
||||
|
||||
static void numShortcuts(size_t &val, size_t sizeRange) noexcept;
|
||||
|
||||
static void colorInput(ox::CStringView label, int &v, bool &inputFocused) noexcept;
|
||||
void colorInput(ox::CStringViewCR label, int &v, bool &inputFocused, FocusCmd colorChannel) noexcept;
|
||||
|
||||
void drawColorsEditor() noexcept;
|
||||
|
||||
@@ -66,7 +73,7 @@ class PaletteEditorImGui: public studio::Editor {
|
||||
|
||||
void drawColorEditor() noexcept;
|
||||
|
||||
ox::Error renamePage(ox::StringView name) noexcept;
|
||||
ox::Error renamePage(ox::StringViewCR name) noexcept;
|
||||
|
||||
ox::Error handleCommand(studio::UndoCommand const*) noexcept;
|
||||
};
|
||||
|
@@ -12,15 +12,15 @@
|
||||
namespace nostalgia::gfx {
|
||||
|
||||
static class: public studio::Module {
|
||||
ox::Vector<studio::EditorMaker> editors(studio::StudioContext &ctx) const noexcept final {
|
||||
ox::Vector<studio::EditorMaker> editors(studio::Context &ctx) const noexcept final {
|
||||
return {
|
||||
studio::editorMaker<TileSheetEditorImGui>(ctx, {FileExt_ng, FileExt_nts}),
|
||||
studio::editorMaker<PaletteEditorImGui>(ctx, FileExt_npal),
|
||||
};
|
||||
}
|
||||
|
||||
ox::Vector<ox::UPtr<studio::ItemMaker>> itemMakers(studio::StudioContext&) const noexcept final {
|
||||
ox::Vector<ox::UniquePtr<studio::ItemMaker>> out;
|
||||
ox::Vector<ox::UPtr<studio::ItemMaker>> itemMakers(studio::Context&) const noexcept final {
|
||||
ox::Vector<ox::UPtr<studio::ItemMaker>> out;
|
||||
out.emplace_back(ox::make<studio::ItemMakerT<TileSheet>>("Tile Sheet", "TileSheets", FileExt_nts));
|
||||
out.emplace_back(ox::make<studio::ItemMakerT<Palette>>("Palette", "Palettes", FileExt_npal, Palette{
|
||||
.colorNames = {},
|
||||
|
@@ -8,14 +8,14 @@
|
||||
|
||||
namespace nostalgia::gfx {
|
||||
|
||||
gfx::DeleteTilesCommand::DeleteTilesCommand(
|
||||
DeleteTilesCommand::DeleteTilesCommand(
|
||||
TileSheet &img,
|
||||
TileSheet::SubSheetIdx idx,
|
||||
std::size_t tileIdx,
|
||||
std::size_t tileCnt) noexcept:
|
||||
std::size_t const tileIdx,
|
||||
std::size_t const tileCnt) noexcept:
|
||||
m_img(img),
|
||||
m_idx(std::move(idx)) {
|
||||
const unsigned bytesPerTile = m_img.bpp == 4 ? PixelsPerTile / 2 : PixelsPerTile;
|
||||
constexpr unsigned bytesPerTile = PixelsPerTile;
|
||||
m_deletePos = tileIdx * bytesPerTile;
|
||||
m_deleteSz = tileCnt * bytesPerTile;
|
||||
m_deletedPixels.resize(m_deleteSz);
|
||||
@@ -28,15 +28,21 @@ gfx::DeleteTilesCommand::DeleteTilesCommand(
|
||||
}
|
||||
}
|
||||
|
||||
ox::Error gfx::DeleteTilesCommand::redo() noexcept {
|
||||
ox::Error DeleteTilesCommand::redo() noexcept {
|
||||
auto &s = getSubSheet(m_img, m_idx);
|
||||
auto &p = s.pixels;
|
||||
auto srcPos = m_deletePos + m_deleteSz;
|
||||
auto const src = &p[srcPos];
|
||||
auto const srcPos = m_deletePos + m_deleteSz;
|
||||
auto const dst1 = &p[m_deletePos];
|
||||
auto const dst2 = &p[(p.size() - m_deleteSz)];
|
||||
ox::memmove(dst1, src, p.size() - srcPos);
|
||||
ox::memset(dst2, 0, m_deleteSz * sizeof(decltype(p[0])));
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
if (srcPos < p.size()) {
|
||||
auto const src = &p[srcPos];
|
||||
ox::memmove(dst1, src, p.size() - srcPos);
|
||||
ox::memset(dst2, 0, m_deleteSz * sizeof(decltype(p[0])));
|
||||
} else {
|
||||
ox::memset(dst1, 0, p.size() - m_deletePos);
|
||||
}
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
return {};
|
||||
}
|
||||
|
||||
@@ -44,11 +50,16 @@ ox::Error DeleteTilesCommand::undo() noexcept {
|
||||
auto &s = getSubSheet(m_img, m_idx);
|
||||
auto &p = s.pixels;
|
||||
auto const src = &p[m_deletePos];
|
||||
auto const dst1 = &p[m_deletePos + m_deleteSz];
|
||||
auto const dst2 = src;
|
||||
auto const sz = p.size() - m_deletePos - m_deleteSz;
|
||||
ox::memmove(dst1, src, sz);
|
||||
auto const srcPos = m_deletePos + m_deleteSz;
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
if (srcPos < p.size()) {
|
||||
auto const dst1 = &p[m_deletePos + m_deleteSz];
|
||||
ox::memmove(dst1, src, sz);
|
||||
}
|
||||
auto const dst2 = src;
|
||||
ox::memcpy(dst2, m_deletedPixels.data(), m_deletedPixels.size());
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
return {};
|
||||
}
|
||||
|
||||
|
@@ -9,28 +9,29 @@ namespace nostalgia::gfx {
|
||||
InsertTilesCommand::InsertTilesCommand(
|
||||
TileSheet &img,
|
||||
TileSheet::SubSheetIdx idx,
|
||||
std::size_t tileIdx,
|
||||
std::size_t tileCnt) noexcept:
|
||||
m_img(img),
|
||||
m_idx(std::move(idx)) {
|
||||
const unsigned bytesPerTile = m_img.bpp == 4 ? PixelsPerTile / 2 : PixelsPerTile;
|
||||
m_insertPos = tileIdx * bytesPerTile;
|
||||
m_insertCnt = tileCnt * bytesPerTile;
|
||||
std::size_t const tileIdx,
|
||||
std::size_t const tileCnt) noexcept:
|
||||
m_img{img},
|
||||
m_idx{std::move(idx)} {
|
||||
m_insertPos = tileIdx * PixelsPerTile;
|
||||
m_insertCnt = tileCnt * PixelsPerTile;
|
||||
m_deletedPixels.resize(m_insertCnt);
|
||||
// copy pixels to be erased
|
||||
{
|
||||
auto &s = getSubSheet(m_img, m_idx);
|
||||
auto &p = s.pixels;
|
||||
auto dst = m_deletedPixels.begin();
|
||||
auto src = p.begin() + p.size() - m_insertCnt;
|
||||
auto const dst = m_deletedPixels.begin();
|
||||
auto const src = p.begin() + p.size() - m_insertCnt;
|
||||
ox::copy_n(src, m_insertCnt, dst);
|
||||
}
|
||||
}
|
||||
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
|
||||
ox::Error InsertTilesCommand::redo() noexcept {
|
||||
auto &s = getSubSheet(m_img, m_idx);
|
||||
auto &p = s.pixels;
|
||||
auto dstPos = m_insertPos + m_insertCnt;
|
||||
auto const dstPos = m_insertPos + m_insertCnt;
|
||||
auto const src = &p[m_insertPos];
|
||||
if (dstPos < p.size()) {
|
||||
auto const dst = &p[dstPos];
|
||||
@@ -55,6 +56,8 @@ ox::Error InsertTilesCommand::undo() noexcept {
|
||||
return {};
|
||||
}
|
||||
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
|
||||
int InsertTilesCommand::commandId() const noexcept {
|
||||
return static_cast<int>(CommandId::InsertTile);
|
||||
}
|
||||
|
@@ -6,14 +6,14 @@
|
||||
|
||||
namespace nostalgia::gfx {
|
||||
|
||||
gfx::PaletteChangeCommand::PaletteChangeCommand(
|
||||
PaletteChangeCommand::PaletteChangeCommand(
|
||||
TileSheet::SubSheetIdx idx,
|
||||
TileSheet &img,
|
||||
ox::StringViewCR newPalette) noexcept:
|
||||
m_img(img),
|
||||
m_idx(std::move(idx)),
|
||||
m_oldPalette(m_img.defaultPalette),
|
||||
m_newPalette(ox::sfmt<ox::IString<43>>("uuid://{}", newPalette)) {
|
||||
m_img{img},
|
||||
m_idx{std::move(idx)},
|
||||
m_oldPalette{m_img.defaultPalette},
|
||||
m_newPalette{ox::sfmt<ox::IString<43>>("uuid://{}", newPalette)} {
|
||||
}
|
||||
|
||||
ox::Error PaletteChangeCommand::redo() noexcept {
|
||||
|
@@ -6,7 +6,7 @@
|
||||
|
||||
namespace nostalgia::gfx {
|
||||
|
||||
gfx::UpdateSubSheetCommand::UpdateSubSheetCommand(
|
||||
UpdateSubSheetCommand::UpdateSubSheetCommand(
|
||||
TileSheet &img,
|
||||
TileSheet::SubSheetIdx idx,
|
||||
ox::StringParam name,
|
||||
|
@@ -87,7 +87,7 @@ static ox::Error toPngFile(
|
||||
8)));
|
||||
}
|
||||
|
||||
TileSheetEditorImGui::TileSheetEditorImGui(studio::StudioContext &sctx, ox::StringParam path):
|
||||
TileSheetEditorImGui::TileSheetEditorImGui(studio::Context &sctx, ox::StringParam path):
|
||||
Editor(sctx, std::move(path)),
|
||||
m_sctx{sctx},
|
||||
m_tctx{m_sctx.tctx},
|
||||
@@ -96,7 +96,7 @@ TileSheetEditorImGui::TileSheetEditorImGui(studio::StudioContext &sctx, ox::Stri
|
||||
m_model{m_view.model()} {
|
||||
// connect signal/slots
|
||||
m_subsheetEditor.inputSubmitted.connect(this, &TileSheetEditorImGui::updateActiveSubsheet);
|
||||
m_exportMenu.inputSubmitted.connect(this, &TileSheetEditorImGui::exportSubhseetToPng);
|
||||
m_exportMenu.inputSubmitted.connect(this, &TileSheetEditorImGui::exportSubsheetToPng);
|
||||
// load config
|
||||
auto const&config = studio::readConfig<TileSheetEditorConfig>(
|
||||
keelCtx(m_sctx), itemPath());
|
||||
@@ -129,7 +129,7 @@ void TileSheetEditorImGui::keyStateChanged(turbine::Key const key, bool const do
|
||||
if (!down) {
|
||||
return;
|
||||
}
|
||||
if (key == turbine::Key::Escape) {
|
||||
if (ig::mainWinHasFocus() && key == turbine::Key::Escape) {
|
||||
m_subsheetEditor.close();
|
||||
m_exportMenu.close();
|
||||
m_palPicker.close();
|
||||
@@ -188,7 +188,7 @@ void TileSheetEditorImGui::keyStateChanged(turbine::Key const key, bool const do
|
||||
}
|
||||
}
|
||||
|
||||
void TileSheetEditorImGui::draw(studio::StudioContext&) noexcept {
|
||||
void TileSheetEditorImGui::draw(studio::Context&) noexcept {
|
||||
if (ig::mainWinHasFocus() && m_tool == TileSheetTool::Select) {
|
||||
if (ImGui::IsKeyDown(ImGuiKey_ModCtrl) && !m_palPathFocused) {
|
||||
if (ImGui::IsKeyPressed(ImGuiKey_A)) {
|
||||
@@ -388,6 +388,17 @@ ox::Error TileSheetEditorImGui::saveItem() noexcept {
|
||||
return m_model.saveFile();
|
||||
}
|
||||
|
||||
void TileSheetEditorImGui::navigateTo(ox::StringViewCR arg) noexcept {
|
||||
auto const subSheetId = strToInt(arg);
|
||||
if (subSheetId.error) {
|
||||
return;
|
||||
}
|
||||
if (auto const [val, err] = getSubSheetIdx(m_model.img(), subSheetId.value);
|
||||
!err) {
|
||||
setActiveSubsheet(val);
|
||||
}
|
||||
}
|
||||
|
||||
void TileSheetEditorImGui::showSubsheetEditor() noexcept {
|
||||
auto const&sheet = m_model.activeSubSheet();
|
||||
if (!sheet.subsheets.empty()) {
|
||||
@@ -397,7 +408,7 @@ void TileSheetEditorImGui::showSubsheetEditor() noexcept {
|
||||
}
|
||||
}
|
||||
|
||||
ox::Error TileSheetEditorImGui::exportSubhseetToPng(int const scale) const noexcept {
|
||||
ox::Error TileSheetEditorImGui::exportSubsheetToPng(int const scale) const noexcept {
|
||||
OX_REQUIRE(path, studio::saveFile({{"PNG", "png"}}));
|
||||
// subsheet to png
|
||||
auto const&s = m_model.activeSubSheet();
|
||||
@@ -414,7 +425,7 @@ ox::Error TileSheetEditorImGui::exportSubhseetToPng(int const scale) const noexc
|
||||
static_cast<unsigned>(width * scale),
|
||||
static_cast<unsigned>(height * scale));
|
||||
if (err) {
|
||||
oxErrorf("Tilesheet export failed: {}", toStr(err));
|
||||
oxErrorf("TileSheet export failed: {}", toStr(err));
|
||||
}
|
||||
return err;
|
||||
}
|
||||
@@ -451,7 +462,10 @@ void TileSheetEditorImGui::drawTileSheet(ox::Vec2 const&fbSize) noexcept {
|
||||
if (wheelh != 0) {
|
||||
m_view.scrollH(fbSize, wheelh);
|
||||
}
|
||||
if (ImGui::IsMouseDown(0) && m_prevMouseDownPos != mousePos) {
|
||||
using ImGui::IsMouseClicked;
|
||||
using ImGui::IsMouseDragging;
|
||||
if ((IsMouseDragging(ImGuiMouseButton_Left) || IsMouseClicked(ImGuiMouseButton_Left))
|
||||
&& m_prevMouseDownPos != mousePos) {
|
||||
m_prevMouseDownPos = mousePos;
|
||||
switch (m_tool) {
|
||||
case TileSheetTool::Draw:
|
||||
@@ -549,7 +563,7 @@ void TileSheetEditorImGui::drawPaletteMenu() noexcept {
|
||||
ImGui::PushID(static_cast<int>(i));
|
||||
// Column: color idx
|
||||
ImGui::TableNextColumn();
|
||||
auto const label = ox::itoa(i + 1);
|
||||
auto const label = ox::intToStr(i + 1);
|
||||
auto const rowSelected = i == m_view.palIdx();
|
||||
if (ImGui::Selectable(
|
||||
label.c_str(), rowSelected, ImGuiSelectableFlags_SpanAllColumns)) {
|
||||
|
@@ -10,7 +10,6 @@
|
||||
#include <studio/editor.hpp>
|
||||
#include <studio/filepickerpopup.hpp>
|
||||
|
||||
#include "tilesheetpixelgrid.hpp"
|
||||
#include "tilesheetpixels.hpp"
|
||||
#include "tilesheeteditorview.hpp"
|
||||
|
||||
@@ -46,7 +45,7 @@ class TileSheetEditorImGui: public studio::Editor {
|
||||
constexpr bool isOpen() const noexcept { return m_show; }
|
||||
};
|
||||
static constexpr float s_palViewWidth = 335;
|
||||
studio::StudioContext &m_sctx;
|
||||
studio::Context &m_sctx;
|
||||
turbine::Context &m_tctx;
|
||||
ox::Vector<ox::String> m_paletteList;
|
||||
SubSheetEditor m_subsheetEditor;
|
||||
@@ -61,7 +60,7 @@ class TileSheetEditorImGui: public studio::Editor {
|
||||
ox::Vector<ox::UPtr<studio::UndoCommand>, 1> m_deferredCmds;
|
||||
|
||||
public:
|
||||
TileSheetEditorImGui(studio::StudioContext &sctx, ox::StringParam path);
|
||||
TileSheetEditorImGui(studio::Context &sctx, ox::StringParam path);
|
||||
|
||||
~TileSheetEditorImGui() override = default;
|
||||
|
||||
@@ -78,7 +77,7 @@ class TileSheetEditorImGui: public studio::Editor {
|
||||
|
||||
void keyStateChanged(turbine::Key key, bool down) override;
|
||||
|
||||
void draw(studio::StudioContext&) noexcept override;
|
||||
void draw(studio::Context&) noexcept override;
|
||||
|
||||
void drawSubsheetSelector(TileSheet::SubSheet&, TileSheet::SubSheetIdx &path);
|
||||
|
||||
@@ -88,10 +87,12 @@ class TileSheetEditorImGui: public studio::Editor {
|
||||
protected:
|
||||
ox::Error saveItem() noexcept override;
|
||||
|
||||
void navigateTo(ox::StringViewCR arg) noexcept override;
|
||||
|
||||
private:
|
||||
void showSubsheetEditor() noexcept;
|
||||
|
||||
ox::Error exportSubhseetToPng(int scale) const noexcept;
|
||||
ox::Error exportSubsheetToPng(int scale) const noexcept;
|
||||
|
||||
void drawTileSheet(ox::Vec2 const&fbSize) noexcept;
|
||||
|
||||
@@ -99,8 +100,6 @@ class TileSheetEditorImGui: public studio::Editor {
|
||||
|
||||
ox::Error updateActiveSubsheet(ox::StringView const&name, int cols, int rows) noexcept;
|
||||
|
||||
// slots
|
||||
private:
|
||||
void setActiveSubsheet(TileSheet::SubSheetIdx path) noexcept;
|
||||
|
||||
};
|
||||
|
@@ -45,7 +45,7 @@ Palette const TileSheetEditorModel::s_defaultPalette = {
|
||||
};
|
||||
|
||||
TileSheetEditorModel::TileSheetEditorModel(
|
||||
studio::StudioContext &sctx, ox::StringParam path, studio::UndoStack &undoStack):
|
||||
studio::Context &sctx, ox::StringParam path, studio::UndoStack &undoStack):
|
||||
m_sctx(sctx),
|
||||
m_tctx(m_sctx.tctx),
|
||||
m_path(std::move(path)),
|
||||
@@ -120,7 +120,7 @@ bool TileSheetEditorModel::acceptsClipboardPayload() const noexcept {
|
||||
return cb.ok();
|
||||
}
|
||||
|
||||
ox::StringView TileSheetEditorModel::palPath() const noexcept {
|
||||
ox::String const &TileSheetEditorModel::palPath() const & noexcept {
|
||||
return m_palPath;
|
||||
}
|
||||
|
||||
@@ -263,7 +263,13 @@ ox::Error TileSheetEditorModel::rotateRight() noexcept {
|
||||
}
|
||||
|
||||
void TileSheetEditorModel::setSelection(studio::Selection const&sel) noexcept {
|
||||
m_selection.emplace(sel);
|
||||
auto const &ss = activeSubSheet();
|
||||
if (sel.a.x < ss.columns * TileWidth && sel.a.y < ss.rows * TileHeight) {
|
||||
m_selection.emplace(sel);
|
||||
} else {
|
||||
m_selTracker.finishSelection();
|
||||
m_selection.reset();
|
||||
}
|
||||
m_updated = true;
|
||||
}
|
||||
|
||||
|
@@ -22,7 +22,7 @@ class TileSheetEditorModel: public ox::SignalHandler {
|
||||
|
||||
private:
|
||||
static Palette const s_defaultPalette;
|
||||
studio::StudioContext &m_sctx;
|
||||
studio::Context &m_sctx;
|
||||
turbine::Context &m_tctx;
|
||||
ox::String m_path;
|
||||
ox::String m_palPath;
|
||||
@@ -39,7 +39,7 @@ class TileSheetEditorModel: public ox::SignalHandler {
|
||||
bool m_updated = false;
|
||||
|
||||
public:
|
||||
TileSheetEditorModel(studio::StudioContext &sctx, ox::StringParam path, studio::UndoStack &undoStack);
|
||||
TileSheetEditorModel(studio::Context &sctx, ox::StringParam path, studio::UndoStack &undoStack);
|
||||
|
||||
~TileSheetEditorModel() override = default;
|
||||
|
||||
@@ -62,7 +62,7 @@ class TileSheetEditorModel: public ox::SignalHandler {
|
||||
constexpr Palette const&pal() const noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
ox::StringView palPath() const noexcept;
|
||||
ox::String const &palPath() const & noexcept;
|
||||
|
||||
ox::Error setPalette(ox::StringViewCR path) noexcept;
|
||||
|
||||
|
@@ -12,7 +12,7 @@
|
||||
namespace nostalgia::gfx {
|
||||
|
||||
TileSheetEditorView::TileSheetEditorView(
|
||||
studio::StudioContext &sctx, ox::StringViewCR path, studio::UndoStack &undoStack):
|
||||
studio::Context &sctx, ox::StringViewCR path, studio::UndoStack &undoStack):
|
||||
m_model(sctx, path, undoStack),
|
||||
m_pixelsDrawer(m_model) {
|
||||
glBindVertexArray(0);
|
||||
|
@@ -56,7 +56,7 @@ class TileSheetEditorView: public ox::SignalHandler {
|
||||
std::size_t m_palIdx = 0;
|
||||
|
||||
public:
|
||||
TileSheetEditorView(studio::StudioContext &sctx, ox::StringViewCR path, studio::UndoStack &undoStack);
|
||||
TileSheetEditorView(studio::Context &sctx, ox::StringViewCR path, studio::UndoStack &undoStack);
|
||||
|
||||
~TileSheetEditorView() override = default;
|
||||
|
||||
|
@@ -5,12 +5,13 @@
|
||||
#include <ox/claw/write.hpp>
|
||||
|
||||
#include <nostalgia/gfx/consts.hpp>
|
||||
#include <nostalgia/gfx/gfx.hpp>
|
||||
|
||||
#include "tilesheetpixelgrid.hpp"
|
||||
|
||||
namespace nostalgia::gfx {
|
||||
|
||||
void TileSheetGrid::setPixelSizeMod(float sm) noexcept {
|
||||
void TileSheetGrid::setPixelSizeMod(float const sm) noexcept {
|
||||
m_pixelSizeMod = sm;
|
||||
}
|
||||
|
||||
@@ -18,10 +19,11 @@ ox::Error TileSheetGrid::buildShader() noexcept {
|
||||
auto const pixelLineVshad = ox::sfmt(VShad, gl::GlslVersion);
|
||||
auto const pixelLineFshad = ox::sfmt(FShad, gl::GlslVersion);
|
||||
auto const pixelLineGshad = ox::sfmt(GShad, gl::GlslVersion);
|
||||
return glutils::buildShaderProgram(pixelLineVshad, pixelLineFshad, pixelLineGshad).moveTo(m_shader);
|
||||
return glutils::buildShaderProgram(
|
||||
pixelLineVshad, pixelLineFshad, pixelLineGshad).moveTo(m_shader);
|
||||
}
|
||||
|
||||
void TileSheetGrid::draw(bool update, ox::Vec2 const&scroll) noexcept {
|
||||
void TileSheetGrid::draw(bool const update, ox::Vec2 const&scroll) noexcept {
|
||||
// the lines just show up bigger on Windows for some reason
|
||||
if constexpr(ox::defines::OS == ox::OS::Windows) {
|
||||
glLineWidth(3 * m_pixelSizeMod * 0.25f);
|
||||
@@ -51,7 +53,8 @@ void TileSheetGrid::initBufferSet(ox::Vec2 const&paneSize, TileSheet::SubSheet c
|
||||
// vbo layout
|
||||
auto const pt1Attr = static_cast<GLuint>(glGetAttribLocation(m_shader, "vPt1"));
|
||||
glEnableVertexAttribArray(pt1Attr);
|
||||
glVertexAttribPointer(pt1Attr, 2, GL_FLOAT, GL_FALSE, VertexVboRowLength * sizeof(float), nullptr);
|
||||
glVertexAttribPointer(
|
||||
pt1Attr, 2, GL_FLOAT, GL_FALSE, VertexVboRowLength * sizeof(float), nullptr);
|
||||
auto const pt2Attr = static_cast<GLuint>(glGetAttribLocation(m_shader, "vPt2"));
|
||||
glEnableVertexAttribArray(pt2Attr);
|
||||
glVertexAttribPointer(pt2Attr, 2, GL_FLOAT, GL_FALSE, VertexVboRowLength * sizeof(float),
|
||||
@@ -70,18 +73,18 @@ void TileSheetGrid::update(ox::Vec2 const&paneSize, TileSheet::SubSheet const&su
|
||||
}
|
||||
|
||||
void TileSheetGrid::setBufferObject(
|
||||
ox::Point pt1,
|
||||
ox::Point pt2,
|
||||
Color32 c,
|
||||
float *vbo,
|
||||
ox::Point const pt1,
|
||||
ox::Point const pt2,
|
||||
Color32 const c,
|
||||
ox::Span<float> const vbo,
|
||||
ox::Vec2 const&pixSize) noexcept {
|
||||
auto const x1 = static_cast<float>(pt1.x) * pixSize.x - 1.f;
|
||||
auto const y1 = 1.f - static_cast<float>(pt1.y) * pixSize.y;
|
||||
auto const x2 = static_cast<float>(pt2.x) * pixSize.x - 1.f;
|
||||
auto const y2 = 1.f - static_cast<float>(pt2.y) * pixSize.y;
|
||||
// don't worry, this memcpy gets optimized to something much more ideal
|
||||
// don't worry, this gets optimized to something much more ideal
|
||||
ox::Array<float, VertexVboLength> const vertices = {x1, y1, x2, y2, redf(c), greenf(c), bluef(c)};
|
||||
memcpy(vbo, vertices.data(), sizeof(vertices));
|
||||
ox::spancpy(vbo, ox::SpanView<float>{vertices});
|
||||
}
|
||||
|
||||
void TileSheetGrid::setBufferObjects(ox::Vec2 const&paneSize, TileSheet::SubSheet const&subsheet) noexcept {
|
||||
@@ -92,7 +95,8 @@ void TileSheetGrid::setBufferObjects(ox::Vec2 const&paneSize, TileSheet::SubShee
|
||||
}
|
||||
auto const pixSize = pixelSize(paneSize);
|
||||
auto const set = [&](std::size_t i, ox::Point pt1, ox::Point pt2, Color32 c) {
|
||||
auto const vbo = &m_bufferSet.vertices[i * VertexVboLength];
|
||||
auto const idx = i * VertexVboLength;
|
||||
auto const vbo = ox::Span{m_bufferSet.vertices} + idx;
|
||||
setBufferObject(pt1, pt2, c, vbo, pixSize);
|
||||
};
|
||||
// set buffer length
|
||||
|
@@ -7,7 +7,6 @@
|
||||
#include <glutils/glutils.hpp>
|
||||
#include <studio/studio.hpp>
|
||||
|
||||
#include <nostalgia/gfx/gfx.hpp>
|
||||
#include <nostalgia/gfx/tilesheet.hpp>
|
||||
|
||||
namespace nostalgia::gfx {
|
||||
@@ -74,7 +73,7 @@ class TileSheetGrid {
|
||||
void update(ox::Vec2 const&paneSize, TileSheet::SubSheet const&subsheet) noexcept;
|
||||
|
||||
private:
|
||||
static void setBufferObject(ox::Point pt1, ox::Point pt2, Color32 c, float *vbo, ox::Vec2 const&pixSize) noexcept;
|
||||
static void setBufferObject(ox::Point pt1, ox::Point pt2, Color32 c, ox::Span<float> vbo, ox::Vec2 const&pixSize) noexcept;
|
||||
|
||||
void setBufferObjects(ox::Vec2 const&paneSize, TileSheet::SubSheet const&subsheet) noexcept;
|
||||
|
||||
|
@@ -2,8 +2,6 @@
|
||||
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#include <nostalgia/gfx/consts.hpp>
|
||||
#include <nostalgia/gfx/ptidxconv.hpp>
|
||||
#include "tilesheeteditormodel.hpp"
|
||||
#include "tilesheetpixels.hpp"
|
||||
|
||||
@@ -88,11 +86,11 @@ ox::Vec2 TileSheetPixels::pixelSize(ox::Vec2 const&paneSize) const noexcept {
|
||||
|
||||
void TileSheetPixels::setPixelBufferObject(
|
||||
ox::Vec2 const&paneSize,
|
||||
unsigned vertexRow,
|
||||
unsigned const vertexRow,
|
||||
float x, float y,
|
||||
Color16 color,
|
||||
float *vbo,
|
||||
GLuint *ebo) const noexcept {
|
||||
Color16 const color,
|
||||
ox::Span<float> const vbo,
|
||||
ox::Span<GLuint> const ebo) const noexcept {
|
||||
auto const [xmod, ymod] = pixelSize(paneSize);
|
||||
x *= xmod;
|
||||
y *= -ymod;
|
||||
@@ -106,12 +104,12 @@ void TileSheetPixels::setPixelBufferObject(
|
||||
x + xmod, y + ymod, r, g, b, // top right
|
||||
x, y + ymod, r, g, b, // top left
|
||||
};
|
||||
memcpy(vbo, vertices.data(), sizeof(vertices));
|
||||
ox::spancpy(vbo, ox::SpanView<float>{vertices});
|
||||
std::array const elms = {
|
||||
vertexRow + 0, vertexRow + 1, vertexRow + 2,
|
||||
vertexRow + 2, vertexRow + 3, vertexRow + 0,
|
||||
};
|
||||
memcpy(ebo, elms.data(), sizeof(elms));
|
||||
ox::spancpy(ebo, ox::SpanView<GLuint>{elms});
|
||||
}
|
||||
|
||||
void TileSheetPixels::setBufferObjects(ox::Vec2 const&paneSize) noexcept {
|
||||
@@ -137,8 +135,8 @@ void TileSheetPixels::setBufferObjects(ox::Vec2 const&paneSize) noexcept {
|
||||
auto const pt = idxToPt(static_cast<int>(i), subSheet.columns);
|
||||
auto const fx = static_cast<float>(pt.x);
|
||||
auto const fy = static_cast<float>(pt.y);
|
||||
auto const vbo = &m_bufferSet.vertices[i * vboLen];
|
||||
auto const ebo = &m_bufferSet.elements[i * VertexEboLength];
|
||||
auto const vbo = ox::Span{m_bufferSet.vertices} + i * vboLen;
|
||||
auto const ebo = ox::Span{m_bufferSet.elements} + i * VertexEboLength;
|
||||
if (i * vboLen + vboLen > m_bufferSet.vertices.size()) {
|
||||
return;
|
||||
}
|
||||
|
@@ -6,11 +6,9 @@
|
||||
|
||||
#include <ox/std/vec.hpp>
|
||||
|
||||
#include <glutils/glutils.hpp>
|
||||
#include <studio/studio.hpp>
|
||||
|
||||
#include <nostalgia/gfx/color.hpp>
|
||||
#include <nostalgia/gfx/gfx.hpp>
|
||||
|
||||
#include <glutils/glutils.hpp>
|
||||
|
||||
namespace nostalgia::gfx {
|
||||
|
||||
@@ -44,15 +42,15 @@ class TileSheetPixels {
|
||||
|
||||
private:
|
||||
void setPixelBufferObject(
|
||||
ox::Vec2 const&paneS,
|
||||
ox::Vec2 const&paneSize,
|
||||
unsigned vertexRow,
|
||||
float x,
|
||||
float y,
|
||||
Color16 color,
|
||||
float *vbo,
|
||||
GLuint *ebo) const noexcept;
|
||||
ox::Span<float> vbo,
|
||||
ox::Span<GLuint> ebo) const noexcept;
|
||||
|
||||
void setBufferObjects(ox::Vec2 const&paneS) noexcept;
|
||||
void setBufferObjects(ox::Vec2 const&paneSize) noexcept;
|
||||
|
||||
};
|
||||
|
||||
|
@@ -2,6 +2,8 @@
|
||||
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#include "nostalgia/gfx/tilesheet.hpp"
|
||||
|
||||
#include <ox/std/size.hpp>
|
||||
#include <ox/std/vector.hpp>
|
||||
|
||||
@@ -187,6 +189,28 @@ TileSheet::SubSheetIdx validateSubSheetIdx(TileSheet const&ts, TileSheet::SubShe
|
||||
return validateSubSheetIdx(std::move(idx), 0, ts.subsheet);
|
||||
}
|
||||
|
||||
static ox::Error getSubSheetIdx(TileSheet::SubSheet const &ss, SubSheetId const pId, TileSheet::SubSheetIdx &idx) noexcept {
|
||||
if (ss.id == pId) {
|
||||
return {};
|
||||
}
|
||||
for (uint32_t i{}; auto const &sub : ss.subsheets) {
|
||||
idx.emplace_back(i);
|
||||
auto const err = getSubSheetIdx(sub, pId, idx);
|
||||
if (!err) {
|
||||
return {};
|
||||
}
|
||||
idx.pop_back();
|
||||
++i;
|
||||
}
|
||||
return ox::Error{1, "SubSheet not found"};
|
||||
}
|
||||
|
||||
ox::Result<TileSheet::SubSheetIdx> getSubSheetIdx(TileSheet const &ts, SubSheetId const pId) noexcept {
|
||||
ox::Result<TileSheet::SubSheetIdx> out;
|
||||
OX_RETURN_ERROR(getSubSheetIdx(ts.subsheet, pId, out.value));
|
||||
return out;
|
||||
}
|
||||
|
||||
#if defined(__GNUC__) && __GNUC__ >= 13
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wdangling-reference"
|
||||
|
@@ -6,8 +6,8 @@
|
||||
|
||||
#include <map>
|
||||
#include <ox/std/error.hpp>
|
||||
#include <ox/mc/mc.hpp>
|
||||
#include <nostalgia/gfx/core.hpp>
|
||||
#include <ox/mc/write.hpp>
|
||||
#include <nostalgia/gfx/gfx.hpp>
|
||||
|
||||
using namespace nostalgia;
|
||||
|
||||
@@ -15,7 +15,7 @@ static std::map<ox::StringView, ox::Error(*)()> tests = {
|
||||
{
|
||||
"readWriteTileSheet",
|
||||
[]() -> ox::Error {
|
||||
gfx::TileSheet in;
|
||||
gfx::TileSheet const in;
|
||||
OX_REQUIRE(buff, ox::writeMC(in));
|
||||
OX_REQUIRE(out, ox::readMC<gfx::TileSheet>(buff));
|
||||
oxAssert(in.subsheet.name == out.subsheet.name, "subsheet.name serialization broken");
|
||||
|
@@ -26,7 +26,7 @@ static class: public keel::Module {
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
ox::Vector<keel::BaseConverter const*> converters() const noexcept final {
|
||||
ox::Vector<keel::Converter> converters() const noexcept final {
|
||||
return {
|
||||
};
|
||||
}
|
||||
|
@@ -9,13 +9,13 @@
|
||||
namespace nostalgia::sound {
|
||||
|
||||
static class: public studio::Module {
|
||||
ox::Vector<studio::EditorMaker> editors(studio::StudioContext&) const noexcept final {
|
||||
ox::Vector<studio::EditorMaker> editors(studio::Context&) const noexcept final {
|
||||
return {
|
||||
};
|
||||
}
|
||||
|
||||
ox::Vector<ox::UPtr<studio::ItemMaker>> itemMakers(studio::StudioContext&) const noexcept final {
|
||||
ox::Vector<ox::UniquePtr<studio::ItemMaker>> out;
|
||||
ox::Vector<ox::UPtr<studio::ItemMaker>> itemMakers(studio::Context&) const noexcept final {
|
||||
ox::Vector<ox::UPtr<studio::ItemMaker>> out;
|
||||
return out;
|
||||
}
|
||||
} const mod;
|
||||
|
@@ -5,7 +5,7 @@
|
||||
#include <keel/media.hpp>
|
||||
#include <turbine/turbine.hpp>
|
||||
|
||||
#include <nostalgia/gfx/core.hpp>
|
||||
#include <nostalgia/gfx/gfx.hpp>
|
||||
|
||||
using namespace nostalgia;
|
||||
|
||||
@@ -64,15 +64,12 @@ static void testKeyEventHandler(turbine::Context &tctx, turbine::Key key, bool d
|
||||
|
||||
[[maybe_unused]]
|
||||
static ox::Error runTest(turbine::Context &tctx) {
|
||||
constexpr ox::StringView TileSheetAddr{"/TileSheets/Charset.nts"};
|
||||
constexpr ox::StringView PaletteAddr{"/Palettes/Chester.npal"};
|
||||
OX_REQUIRE_M(cctx, gfx::init(tctx));
|
||||
turbine::setApplicationData(tctx, cctx.get());
|
||||
OX_REQUIRE(tsStat, turbine::rom(tctx)->stat(PaletteAddr));
|
||||
OX_RETURN_ERROR(gfx::loadSpriteTileSheet(*cctx, TileSheetAddr));
|
||||
OX_RETURN_ERROR(gfx::loadSpritePalette(*cctx, PaletteAddr));
|
||||
OX_RETURN_ERROR(gfx::loadSpriteTileSheet(*cctx, "/TileSheets/Charset.nts"));
|
||||
OX_RETURN_ERROR(gfx::loadSpritePalette(*cctx, "/Palettes/Chester.npal"));
|
||||
OX_RETURN_ERROR(gfx::initConsole(*cctx));
|
||||
gfx::puts(*cctx, 10, 9, "DOPENESS!!!");
|
||||
gfx::consoleWrite(*cctx, 10, 9, "DOPENESS!!!");
|
||||
turbine::setUpdateHandler(tctx, testUpdateHandler);
|
||||
turbine::setKeyEventHandler(tctx, testKeyEventHandler);
|
||||
return turbine::run(tctx);
|
||||
@@ -86,7 +83,6 @@ static ox::Error runTileSheetSetTest(turbine::Context &tctx) {
|
||||
constexpr ox::StringView PaletteAddr{"/Palettes/Charset.npal"};
|
||||
OX_REQUIRE_M(cctx, gfx::init(tctx));
|
||||
turbine::setApplicationData(tctx, cctx.get());
|
||||
OX_REQUIRE(tsStat, turbine::rom(tctx)->stat(PaletteAddr));
|
||||
gfx::TileSheetSet const set{
|
||||
.bpp = 4,
|
||||
.entries = {
|
||||
@@ -134,7 +130,6 @@ ox::Error run(
|
||||
return ox::Error{1, "Please provide path to project directory or OxFS file."};
|
||||
}
|
||||
auto const path = args[1];
|
||||
OX_REQUIRE_M(fs, keel::loadRomFs(path));
|
||||
OX_REQUIRE_M(tctx, turbine::init(std::move(fs), project));
|
||||
OX_REQUIRE_M(tctx, turbine::init(path, project));
|
||||
return runTileSheetSetTest(*tctx);
|
||||
}
|
||||
|
@@ -1,4 +1,8 @@
|
||||
add_executable(NostalgiaStudio WIN32 MACOSX_BUNDLE)
|
||||
add_executable(
|
||||
NostalgiaStudio WIN32 MACOSX_BUNDLE
|
||||
ns.rc
|
||||
icondata.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(
|
||||
NostalgiaStudio
|
||||
|
1495
src/nostalgia/studio/icondata.cpp
Normal file
1
src/nostalgia/studio/ns.rc
Normal file
@@ -0,0 +1 @@
|
||||
IDI_ICON1 ICON DISCARDABLE "ns_logo.ico"
|
BIN
src/nostalgia/studio/ns_logo.ico
Normal file
After Width: | Height: | Size: 162 KiB |
BIN
src/nostalgia/studio/ns_logo1080.png
Normal file
After Width: | Height: | Size: 851 B |
BIN
src/nostalgia/studio/ns_logo16.png
Normal file
After Width: | Height: | Size: 134 B |
BIN
src/nostalgia/studio/ns_logo24.png
Normal file
After Width: | Height: | Size: 149 B |
BIN
src/nostalgia/studio/ns_logo264.png
Normal file
After Width: | Height: | Size: 275 B |
BIN
src/nostalgia/studio/ns_logo32.png
Normal file
After Width: | Height: | Size: 4.1 KiB |
BIN
src/nostalgia/studio/ns_logo40.png
Normal file
After Width: | Height: | Size: 334 B |
BIN
src/nostalgia/studio/ns_logo48.png
Normal file
After Width: | Height: | Size: 163 B |
39
src/nostalgia/studio/rsrc.json
Normal file
@@ -0,0 +1,39 @@
|
||||
{
|
||||
"cpp": "icondata.cpp",
|
||||
"namespace": "studio",
|
||||
"all_files": "WindowIcons",
|
||||
"files": [
|
||||
{
|
||||
"path": "ns_logo16.png",
|
||||
"cpp_name": "WindowIcon16"
|
||||
},
|
||||
{
|
||||
"path": "ns_logo24.png",
|
||||
"cpp_name": "WindowIcon24"
|
||||
},
|
||||
{
|
||||
"path": "ns_logo32.png",
|
||||
"cpp_name": "WindowIcon32"
|
||||
},
|
||||
{
|
||||
"path": "ns_logo40.png",
|
||||
"cpp_name": "WindowIcon40"
|
||||
},
|
||||
{
|
||||
"path": "ns_logo48.png",
|
||||
"cpp_name": "WindowIcon48"
|
||||
},
|
||||
{
|
||||
"path": "ns_logo128.png",
|
||||
"cpp_name": "WindowIcon128"
|
||||
},
|
||||
{
|
||||
"path": "ns_logo264.png",
|
||||
"cpp_name": "WindowIcon264"
|
||||
},
|
||||
{
|
||||
"path": "ns_logo1080.png",
|
||||
"cpp_name": "WindowIcon1080"
|
||||
}
|
||||
]
|
||||
}
|
@@ -4,7 +4,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ox/claw/claw.hpp>
|
||||
#include <ox/claw/read.hpp>
|
||||
#include <ox/fs/fs.hpp>
|
||||
|
||||
#include "validation.hpp"
|
||||
|
@@ -8,12 +8,10 @@
|
||||
#include <ox/std/memory.hpp>
|
||||
|
||||
#include "assetmanager.hpp"
|
||||
#include "typeconv.hpp"
|
||||
|
||||
namespace keel {
|
||||
|
||||
class Context;
|
||||
using PackTransform = ox::Result<bool>(*)(Context&, ox::Buffer &clawData, ox::StringViewCR);
|
||||
|
||||
class Context {
|
||||
public:
|
||||
ox::UPtr<ox::FileSystem> rom;
|
||||
@@ -22,7 +20,7 @@ class Context {
|
||||
AssetManager assetManager;
|
||||
ox::HashMap<ox::String, ox::UUID> pathToUuid;
|
||||
ox::HashMap<ox::UUIDStr, ox::String> uuidToPath;
|
||||
ox::Vector<class BaseConverter const*> converters;
|
||||
ox::Vector<Converter> converters;
|
||||
ox::Vector<PackTransform> packTransforms;
|
||||
#else
|
||||
std::size_t preloadSectionOffset = 0;
|
||||
@@ -45,7 +43,7 @@ constexpr ox::SpanView<PackTransform> packTransforms(
|
||||
#endif
|
||||
}
|
||||
|
||||
constexpr ox::SpanView<class BaseConverter const*> converters(
|
||||
constexpr ox::SpanView<Converter> converters(
|
||||
[[maybe_unused]] Context const&ctx) noexcept {
|
||||
#ifndef OX_BARE_METAL
|
||||
return ctx.converters;
|
||||
|
@@ -15,7 +15,18 @@
|
||||
namespace keel {
|
||||
|
||||
ox::Error init(
|
||||
keel::Context &ctx,
|
||||
Context &ctx,
|
||||
ox::UPtr<ox::FileSystem> &&fs,
|
||||
ox::StringViewCR appName,
|
||||
DuplicateSet &duplicateSet) noexcept;
|
||||
|
||||
ox::Result<ox::UPtr<Context>> init(
|
||||
ox::UPtr<ox::FileSystem> &&fs,
|
||||
ox::StringViewCR appName,
|
||||
DuplicateSet &duplicateSet) noexcept;
|
||||
|
||||
ox::Error init(
|
||||
Context &ctx,
|
||||
ox::UPtr<ox::FileSystem> &&fs,
|
||||
ox::StringViewCR appName) noexcept;
|
||||
|
||||
|
@@ -29,13 +29,14 @@ OX_MODEL_BEGIN(PreloadPtr)
|
||||
OX_MODEL_FIELD(preloadAddr)
|
||||
OX_MODEL_END()
|
||||
|
||||
ox::Result<std::size_t> getPreloadAddr(keel::Context &ctx, ox::FileAddress const&addr) noexcept;
|
||||
ox::Result<std::size_t> getPreloadAddr(keel::Context &ctx, ox::StringViewCR path) noexcept;
|
||||
ox::Result<std::size_t> getPreloadAddr(Context &ctx, ox::FileAddress const&addr) noexcept;
|
||||
ox::Result<std::size_t> getPreloadAddr(Context &ctx, ox::StringViewCR path) noexcept;
|
||||
|
||||
|
||||
void createUuidMapping(Context &ctx, ox::StringViewCR filePath, ox::UUID const&uuid) noexcept;
|
||||
|
||||
ox::Error buildUuidMap(Context &ctx) noexcept;
|
||||
// map of UUIDs to paths
|
||||
using DuplicateSet = ox::HashMap<ox::UUID, ox::Vector<ox::String>>;
|
||||
|
||||
ox::Result<ox::UUID> pathToUuid(Context &ctx, ox::StringViewCR path) noexcept;
|
||||
|
||||
@@ -68,7 +69,7 @@ constexpr auto makeLoader(Context &ctx) {
|
||||
if (!beginsWith(assetId, "/")) {
|
||||
auto const p = ctx.uuidToPath.at(assetId);
|
||||
if (p.error) {
|
||||
oxErrf("Could not find asset: {}", assetId);
|
||||
oxErrf("Could not find asset: {}\n", assetId);
|
||||
return ox::Error{1, "Asset ID not found"};
|
||||
}
|
||||
assetId = *p.value;
|
||||
@@ -87,8 +88,8 @@ constexpr auto makeLoader(Context &ctx) {
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
ox::Result<keel::AssetRef<T>> readObjFile(
|
||||
keel::Context &ctx,
|
||||
ox::Result<AssetRef<T>> readObjFile(
|
||||
Context &ctx,
|
||||
ox::StringViewCR assetId,
|
||||
bool const forceLoad) noexcept {
|
||||
static constexpr auto load = [](
|
||||
@@ -135,11 +136,11 @@ ox::Result<keel::AssetRef<T>> readObjNoCache(
|
||||
|
||||
#endif
|
||||
|
||||
ox::Error reloadAsset(keel::Context &ctx, ox::StringViewCR assetId) noexcept;
|
||||
ox::Error reloadAsset(Context &ctx, ox::StringViewCR assetId) noexcept;
|
||||
|
||||
template<typename T>
|
||||
ox::Result<keel::AssetRef<T>> readObj(
|
||||
keel::Context &ctx,
|
||||
ox::Result<AssetRef<T>> readObj(
|
||||
Context &ctx,
|
||||
ox::StringViewCR assetId,
|
||||
[[maybe_unused]] bool forceLoad = false) noexcept {
|
||||
#ifndef OX_BARE_METAL
|
||||
@@ -150,8 +151,8 @@ ox::Result<keel::AssetRef<T>> readObj(
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
ox::Result<keel::AssetRef<T>> readObj(
|
||||
keel::Context &ctx,
|
||||
ox::Result<AssetRef<T>> readObj(
|
||||
Context &ctx,
|
||||
ox::FileAddress const&file,
|
||||
[[maybe_unused]] bool forceLoad = false) noexcept {
|
||||
#ifndef OX_BARE_METAL
|
||||
@@ -169,7 +170,7 @@ ox::Result<keel::AssetRef<T>> readObj(
|
||||
|
||||
template<typename T>
|
||||
ox::Error writeObj(
|
||||
keel::Context &ctx,
|
||||
Context &ctx,
|
||||
ox::FileAddress const&file,
|
||||
T const&obj,
|
||||
ox::ClawFormat fmt = ox::ClawFormat::Metal) noexcept {
|
||||
@@ -177,6 +178,8 @@ ox::Error writeObj(
|
||||
return ctx.rom->write(file, objBuff.data(), objBuff.size());
|
||||
}
|
||||
|
||||
ox::Error setRomFs(Context &ctx, ox::UPtr<ox::FileSystem> &&fs, DuplicateSet &duplicateSet) noexcept;
|
||||
|
||||
ox::Error setRomFs(Context &ctx, ox::UPtr<ox::FileSystem> &&fs) noexcept;
|
||||
|
||||
ox::Result<ox::UPtr<ox::FileSystem>> loadRomFs(ox::StringViewCR path) noexcept;
|
||||
|
@@ -32,7 +32,7 @@ class Module {
|
||||
[[nodiscard]]
|
||||
virtual ox::Vector<TypeDescGenerator> types() const noexcept;
|
||||
[[nodiscard]]
|
||||
virtual ox::Vector<const keel::BaseConverter*> converters() const noexcept;
|
||||
virtual ox::Vector<Converter> converters() const noexcept;
|
||||
[[nodiscard]]
|
||||
virtual ox::Vector<PackTransform> packTransforms() const noexcept;
|
||||
};
|
||||
|
@@ -4,15 +4,17 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ox/claw/write.hpp>
|
||||
#include <ox/std/def.hpp>
|
||||
#include <ox/std/error.hpp>
|
||||
#include <ox/std/string.hpp>
|
||||
|
||||
#include "asset.hpp"
|
||||
#include "context.hpp"
|
||||
|
||||
namespace keel {
|
||||
|
||||
class Context;
|
||||
|
||||
class Wrap {
|
||||
public:
|
||||
virtual ~Wrap() = default;
|
||||
@@ -30,6 +32,7 @@ class WrapT: public Wrap {
|
||||
[[nodiscard]]
|
||||
virtual constexpr T &obj() noexcept = 0;
|
||||
|
||||
[[nodiscard]]
|
||||
ox::UAnyPtr moveToCopy() noexcept final {
|
||||
return new T{std::move(obj())};
|
||||
}
|
||||
@@ -44,14 +47,17 @@ class WrapRef final: public WrapT<T> {
|
||||
public:
|
||||
constexpr explicit WrapRef(T &obj): m_obj{obj} {}
|
||||
|
||||
[[nodiscard]]
|
||||
ox::CStringView typeName() const noexcept override {
|
||||
return ox::ModelTypeName_v<T>;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
int typeVersion() const noexcept override {
|
||||
return ox::ModelTypeVersion_v<T>;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr T &obj() noexcept override {
|
||||
return m_obj;
|
||||
}
|
||||
@@ -70,14 +76,17 @@ class WrapInline final: public WrapT<T> {
|
||||
constexpr explicit WrapInline(Args &&...args): m_obj(ox::forward<Args>(args)...) {
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
ox::CStringView typeName() const noexcept override {
|
||||
return ox::ModelTypeName_v<T>;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
int typeVersion() const noexcept override {
|
||||
return ox::ModelTypeVersion_v<T>;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr T &obj() noexcept override {
|
||||
return m_obj;
|
||||
}
|
||||
@@ -113,7 +122,7 @@ class BaseConverter {
|
||||
virtual ox::Result<ox::UPtr<Wrap>> convertPtrToPtr(keel::Context &ctx, Wrap &src) const noexcept = 0;
|
||||
|
||||
virtual ox::Result<ox::UPtr<Wrap>> convertBuffToPtr(
|
||||
keel::Context &ctx, ox::BufferView const&srcBuff) const noexcept = 0;
|
||||
Context &ctx, ox::BufferView const&srcBuff) const noexcept = 0;
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr bool matches(
|
||||
@@ -125,21 +134,37 @@ class BaseConverter {
|
||||
|
||||
};
|
||||
|
||||
template<typename SrcType, typename DstType>
|
||||
class Converter: public BaseConverter {
|
||||
|
||||
template<auto Func>
|
||||
class ConverterFunc final: public BaseConverter {
|
||||
private:
|
||||
template<typename SrcType, typename DstType>
|
||||
struct ParamPack {
|
||||
using Src = SrcType;
|
||||
using Dst = DstType;
|
||||
};
|
||||
|
||||
template<typename Src, typename Dst>
|
||||
static ParamPack<Src, Dst> extractParams(ox::Error (*)(Context&, Src&, Dst&)) {
|
||||
return {};
|
||||
}
|
||||
|
||||
public:
|
||||
using SrcType = typename decltype(extractParams(Func))::Src;
|
||||
using DstType = typename decltype(extractParams(Func))::Dst;
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr ox::StringView srcTypeName() const noexcept final {
|
||||
constexpr ox::StringView srcTypeName() const noexcept override {
|
||||
return ox::ModelTypeName_v<SrcType>;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr int srcTypeVersion() const noexcept final {
|
||||
constexpr int srcTypeVersion() const noexcept override {
|
||||
return ox::ModelTypeVersion_v<SrcType>;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr bool srcMatches(ox::StringViewCR pSrcTypeName, int pSrcTypeVersion) const noexcept final {
|
||||
constexpr bool srcMatches(ox::StringViewCR pSrcTypeName, int pSrcTypeVersion) const noexcept override {
|
||||
constexpr auto SrcTypeName = ox::requireModelTypeName<SrcType>();
|
||||
constexpr auto SrcTypeVersion = ox::requireModelTypeVersion<SrcType>();
|
||||
return pSrcTypeName == SrcTypeName
|
||||
@@ -147,7 +172,7 @@ class Converter: public BaseConverter {
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr bool dstMatches(ox::StringViewCR dstTypeName, int dstTypeVersion) const noexcept final {
|
||||
constexpr bool dstMatches(ox::StringViewCR dstTypeName, int dstTypeVersion) const noexcept override {
|
||||
constexpr auto DstTypeName = ox::StringView{ox::requireModelTypeName<DstType>()};
|
||||
constexpr auto DstTypeVersion = ox::requireModelTypeVersion<DstType>();
|
||||
return dstTypeName == DstTypeName
|
||||
@@ -155,14 +180,14 @@ class Converter: public BaseConverter {
|
||||
}
|
||||
|
||||
ox::Result<ox::UPtr<Wrap>> convertPtrToPtr(
|
||||
keel::Context &ctx, Wrap &src) const noexcept final {
|
||||
Context &ctx, Wrap &src) const noexcept override {
|
||||
ox::Result<ox::UPtr<Wrap>> dst{makeWrap<DstType>()};
|
||||
OX_RETURN_ERROR(convert(ctx, wrapCast<SrcType>(src), wrapCast<DstType>(*dst.value)));
|
||||
return dst;
|
||||
}
|
||||
|
||||
ox::Result<ox::UPtr<Wrap>> convertBuffToPtr(
|
||||
keel::Context &ctx, ox::BufferView const&srcBuff) const noexcept final {
|
||||
Context &ctx, ox::BufferView const&srcBuff) const noexcept override {
|
||||
OX_REQUIRE_M(src, readAsset<SrcType>(srcBuff));
|
||||
ox::Result<ox::UPtr<Wrap>> dst{makeWrap<DstType>()};
|
||||
OX_RETURN_ERROR(convert(ctx, src, wrapCast<DstType>(*dst.value)));
|
||||
@@ -170,24 +195,43 @@ class Converter: public BaseConverter {
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual ox::Error convert(keel::Context &ctx, SrcType&, DstType&) const noexcept = 0;
|
||||
static ox::Error convert(Context &ctx, SrcType &src, DstType &dst) noexcept {
|
||||
return Func(ctx, src, dst);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
class Converter {
|
||||
private:
|
||||
ox::AllocAlias<BaseConverter> m_buff{};
|
||||
public:
|
||||
template<auto Func>
|
||||
static Converter make() noexcept {
|
||||
Converter out;
|
||||
static_assert(sizeof(ConverterFunc<Func>) <= sizeof(out.m_buff));
|
||||
new (out.m_buff.data()) ConverterFunc<Func>{};
|
||||
return out;
|
||||
}
|
||||
[[nodiscard]]
|
||||
BaseConverter const &converter() const noexcept {
|
||||
return *m_buff.data();
|
||||
}
|
||||
};
|
||||
|
||||
ox::Result<ox::UPtr<Wrap>> convert(
|
||||
keel::Context &ctx,
|
||||
Context &ctx,
|
||||
ox::BufferView const&srcBuffer,
|
||||
ox::StringViewCR dstTypeName,
|
||||
int dstTypeVersion) noexcept;
|
||||
|
||||
ox::Result<ox::UPtr<Wrap>> convert(
|
||||
keel::Context &ctx,
|
||||
Context &ctx,
|
||||
Wrap &src,
|
||||
ox::StringViewCR dstTypeName,
|
||||
int dstTypeVersion) noexcept;
|
||||
|
||||
ox::Result<ox::UPtr<Wrap>> convert(
|
||||
keel::Context &ctx,
|
||||
Context &ctx,
|
||||
auto &src,
|
||||
ox::StringViewCR dstTypeName,
|
||||
int const dstTypeVersion) noexcept {
|
||||
@@ -196,7 +240,7 @@ ox::Result<ox::UPtr<Wrap>> convert(
|
||||
}
|
||||
|
||||
ox::Result<ox::UPtr<Wrap>> convert(
|
||||
keel::Context &ctx,
|
||||
Context &ctx,
|
||||
auto const&src,
|
||||
ox::StringViewCR dstTypeName,
|
||||
int const dstTypeVersion) noexcept {
|
||||
@@ -207,27 +251,27 @@ ox::Result<ox::UPtr<Wrap>> convert(
|
||||
|
||||
template<typename DstType>
|
||||
ox::Result<DstType> convertObjToObj(
|
||||
keel::Context &ctx,
|
||||
Context &ctx,
|
||||
auto &src) noexcept {
|
||||
OX_REQUIRE_M(out, convert(ctx, WrapRef{src}, ox::ModelTypeName_v<DstType>, ox::ModelTypeVersion_v<DstType>));
|
||||
return std::move(wrapCast(*out));
|
||||
}
|
||||
|
||||
template<typename DstType>
|
||||
ox::Result<DstType> convert(keel::Context &ctx, ox::BufferView const&src) noexcept {
|
||||
ox::Result<DstType> convert(Context &ctx, ox::BufferView const&src) noexcept {
|
||||
OX_REQUIRE(out, convert(ctx, src, ox::ModelTypeName_v<DstType>, ox::ModelTypeVersion_v<DstType>));
|
||||
return std::move(wrapCast<DstType>(out));
|
||||
}
|
||||
|
||||
template<typename DstType>
|
||||
ox::Error convert(keel::Context &ctx, ox::BufferView const&buff, DstType &outObj) noexcept {
|
||||
ox::Error convert(Context &ctx, ox::BufferView const&buff, DstType &outObj) noexcept {
|
||||
OX_REQUIRE(out, convert(ctx, buff, ox::ModelTypeName_v<DstType>, ox::ModelTypeVersion_v<DstType>));
|
||||
outObj = std::move(wrapCast<DstType>(*out));
|
||||
return {};
|
||||
}
|
||||
|
||||
template<typename DstType>
|
||||
ox::Error convertObjToObj(keel::Context &ctx, auto &src, DstType &outObj) noexcept {
|
||||
ox::Error convertObjToObj(Context &ctx, auto &src, DstType &outObj) noexcept {
|
||||
OX_REQUIRE(outPtr, convert(ctx, src, ox::ModelTypeName_v<DstType>, ox::ModelTypeVersion_v<DstType>));
|
||||
outObj = std::move(wrapCast<DstType>(*outPtr));
|
||||
return {};
|
||||
@@ -235,13 +279,13 @@ ox::Error convertObjToObj(keel::Context &ctx, auto &src, DstType &outObj) noexce
|
||||
|
||||
template<typename DstType>
|
||||
ox::Result<ox::Buffer> convertBuffToBuff(
|
||||
keel::Context &ctx, ox::BufferView const&src, ox::ClawFormat const fmt) noexcept {
|
||||
Context &ctx, ox::BufferView const&src, ox::ClawFormat const fmt) noexcept {
|
||||
OX_REQUIRE(out, convert(ctx, src, ox::ModelTypeName_v<DstType>, ox::ModelTypeVersion_v<DstType>));
|
||||
return ox::writeClaw<DstType>(wrapCast<DstType>(*out), fmt);
|
||||
}
|
||||
|
||||
template<typename From, typename To, ox::ClawFormat fmt = ox::ClawFormat::Metal>
|
||||
ox::Result<bool> transformRule(keel::Context &ctx, ox::Buffer &buff, ox::StringViewCR typeId) noexcept {
|
||||
ox::Result<bool> transformRule(Context &ctx, ox::Buffer &buff, ox::StringViewCR typeId) noexcept {
|
||||
if (typeId == ox::ModelTypeId_v<From>) {
|
||||
OX_RETURN_ERROR(keel::convertBuffToBuff<To>(ctx, buff, fmt).moveTo(buff));
|
||||
return true;
|
||||
@@ -249,4 +293,6 @@ ox::Result<bool> transformRule(keel::Context &ctx, ox::Buffer &buff, ox::StringV
|
||||
return false;
|
||||
};
|
||||
|
||||
using PackTransform = ox::Result<bool>(*)(Context&, ox::Buffer &clawData, ox::StringViewCR);
|
||||
|
||||
}
|
||||
|
@@ -28,7 +28,7 @@ install(
|
||||
DIRECTORY
|
||||
../include/keel
|
||||
DESTINATION
|
||||
include/keel
|
||||
include
|
||||
)
|
||||
|
||||
install(
|
||||
@@ -60,4 +60,11 @@ if(TURBINE_BUILD_TYPE STREQUAL "Native")
|
||||
OxClaw
|
||||
OxLogConn
|
||||
)
|
||||
install(
|
||||
TARGETS
|
||||
KeelPack-AppLib
|
||||
DESTINATION
|
||||
LIBRARY DESTINATION lib
|
||||
ARCHIVE DESTINATION lib
|
||||
)
|
||||
endif()
|
||||
|
@@ -36,7 +36,7 @@ ox::Result<ox::ModelObject> readAsset(ox::TypeStore &ts, ox::BufferView buff) no
|
||||
return ox::readClaw(ts, buff);
|
||||
}
|
||||
|
||||
ox::Result<ox::StringView> readAssetTypeId(ox::BufferView buff) noexcept {
|
||||
ox::Result<ox::StringView> readAssetTypeId(ox::BufferView const buff) noexcept {
|
||||
const auto err = readUuidHeader(buff).error;
|
||||
const auto offset = err ? 0u : K1HdrSz;
|
||||
if (offset >= buff.size()) [[unlikely]] {
|
||||
|
@@ -6,21 +6,24 @@
|
||||
|
||||
namespace keel {
|
||||
|
||||
ox::Error init(
|
||||
keel::Context &ctx,
|
||||
static ox::Error init(
|
||||
Context &ctx,
|
||||
ox::UPtr<ox::FileSystem> &&fs,
|
||||
ox::StringViewCR appName) noexcept {
|
||||
ox::StringViewCR appName,
|
||||
DuplicateSet *duplicateSet) noexcept {
|
||||
ctx.appName = appName;
|
||||
std::ignore = setRomFs(ctx, std::move(fs));
|
||||
std::ignore = duplicateSet ?
|
||||
setRomFs(ctx, std::move(fs), *duplicateSet) :
|
||||
setRomFs(ctx, std::move(fs));
|
||||
#ifndef OX_BARE_METAL
|
||||
auto const&mods = modules();
|
||||
for (auto &mod : mods) {
|
||||
// register type converters
|
||||
for (auto c : mod->converters()) {
|
||||
for (auto const c : mod->converters()) {
|
||||
ctx.converters.emplace_back(c);
|
||||
}
|
||||
// register pack transforms
|
||||
for (auto c : mod->packTransforms()) {
|
||||
for (auto const c : mod->packTransforms()) {
|
||||
ctx.packTransforms.emplace_back(c);
|
||||
}
|
||||
}
|
||||
@@ -28,6 +31,30 @@ ox::Error init(
|
||||
return {};
|
||||
}
|
||||
|
||||
ox::Error init(
|
||||
Context &ctx,
|
||||
ox::UPtr<ox::FileSystem> &&fs,
|
||||
ox::StringViewCR appName,
|
||||
DuplicateSet &duplicateSet) noexcept {
|
||||
return init(ctx, std::move(fs), appName, &duplicateSet);
|
||||
}
|
||||
|
||||
ox::Result<ox::UPtr<Context>> init(
|
||||
ox::UPtr<ox::FileSystem> &&fs,
|
||||
ox::StringViewCR appName,
|
||||
DuplicateSet &duplicateSet) noexcept {
|
||||
auto ctx = ox::make_unique<Context>();
|
||||
OX_RETURN_ERROR(keel::init(*ctx, std::move(fs), appName, &duplicateSet));
|
||||
return ctx;
|
||||
}
|
||||
|
||||
ox::Error init(
|
||||
Context &ctx,
|
||||
ox::UPtr<ox::FileSystem> &&fs,
|
||||
ox::StringViewCR appName) noexcept {
|
||||
return init(ctx, std::move(fs), appName, nullptr);
|
||||
}
|
||||
|
||||
ox::Result<ox::UPtr<Context>> init(ox::UPtr<ox::FileSystem> &&fs, ox::StringViewCR appName) noexcept {
|
||||
auto ctx = ox::make_unique<Context>();
|
||||
OX_RETURN_ERROR(keel::init(*ctx, std::move(fs), appName));
|
||||
|
@@ -47,7 +47,7 @@ void createUuidMapping(Context &ctx, ox::StringViewCR filePath, ox::UUID const&u
|
||||
ctx.uuidToPath[uuid.toString()] = filePath;
|
||||
}
|
||||
|
||||
static ox::Error buildUuidMap(Context &ctx, ox::StringViewCR path) noexcept {
|
||||
static ox::Error buildUuidMap(Context &ctx, ox::StringViewCR path, DuplicateSet *duplicates) noexcept {
|
||||
OX_REQUIRE(files, ctx.rom->ls(path));
|
||||
for (auto const&f : files) {
|
||||
OX_REQUIRE_M(filePath, ox::join("/", ox::Array<ox::StringView, 2>{path, f}));
|
||||
@@ -58,22 +58,31 @@ static ox::Error buildUuidMap(Context &ctx, ox::StringViewCR path) noexcept {
|
||||
ctx.rom->read(filePath, 0, buff.size(), buff));
|
||||
auto const [uuid, err] = readUuidHeader(buff);
|
||||
if (!err) {
|
||||
createUuidMapping(ctx, filePath, uuid);
|
||||
// check for duplication
|
||||
if (duplicates && ctx.uuidToPath[uuid.toString()].len()) {
|
||||
auto &dl = (*duplicates)[uuid];
|
||||
if (dl.empty()) {
|
||||
dl.emplace_back(ctx.uuidToPath[uuid.toString()]);
|
||||
}
|
||||
dl.emplace_back(filePath);
|
||||
} else {
|
||||
createUuidMapping(ctx, filePath, uuid);
|
||||
}
|
||||
}
|
||||
} else if (stat.fileType == ox::FileType::Directory) {
|
||||
if (!beginsWith(f, ".")) {
|
||||
OX_RETURN_ERROR(buildUuidMap(ctx, filePath));
|
||||
OX_RETURN_ERROR(buildUuidMap(ctx, filePath, duplicates));
|
||||
}
|
||||
}
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
ox::Error buildUuidMap(Context &ctx) noexcept {
|
||||
static ox::Error buildUuidMap(Context &ctx, DuplicateSet *duplicates) noexcept {
|
||||
if (!ctx.rom) {
|
||||
return ox::Error(1, "No ROM FS");
|
||||
return ox::Error{1, "No ROM FS"};
|
||||
}
|
||||
return buildUuidMap(ctx, "");
|
||||
return buildUuidMap(ctx, "", duplicates);
|
||||
}
|
||||
|
||||
ox::Result<ox::UUID> pathToUuid(Context &ctx, ox::StringViewCR path) noexcept {
|
||||
@@ -173,7 +182,7 @@ ox::Result<ox::CStringView> uuidToPath(Context &ctx, ox::UUID const&uuid) noexce
|
||||
#endif
|
||||
}
|
||||
|
||||
ox::Error reloadAsset(keel::Context &ctx, ox::StringViewCR assetId) noexcept {
|
||||
ox::Error reloadAsset(Context &ctx, ox::StringViewCR assetId) noexcept {
|
||||
if (beginsWith(assetId, "uuid://")) {
|
||||
return ctx.assetManager.reloadAsset(substr(assetId, 7));
|
||||
} else {
|
||||
@@ -199,7 +208,7 @@ namespace keel {
|
||||
static void clearUuidMap(Context&) noexcept {
|
||||
}
|
||||
|
||||
ox::Error buildUuidMap(Context&) noexcept {
|
||||
static ox::Error buildUuidMap(Context&, DuplicateSet*) noexcept {
|
||||
return {};
|
||||
}
|
||||
|
||||
@@ -249,10 +258,16 @@ ox::Error reloadAsset(keel::Context&, ox::StringView) noexcept {
|
||||
|
||||
namespace keel {
|
||||
|
||||
ox::Error setRomFs(Context &ctx, ox::UPtr<ox::FileSystem> &&fs, DuplicateSet &duplicateSet) noexcept {
|
||||
ctx.rom = std::move(fs);
|
||||
clearUuidMap(ctx);
|
||||
return buildUuidMap(ctx, &duplicateSet);
|
||||
}
|
||||
|
||||
ox::Error setRomFs(Context &ctx, ox::UPtr<ox::FileSystem> &&fs) noexcept {
|
||||
ctx.rom = std::move(fs);
|
||||
clearUuidMap(ctx);
|
||||
return buildUuidMap(ctx);
|
||||
return buildUuidMap(ctx, nullptr);
|
||||
}
|
||||
|
||||
ox::Result<ox::UPtr<ox::FileSystem>> loadRomFs(ox::StringViewCR path) noexcept {
|
||||
|
@@ -24,7 +24,7 @@ ox::Vector<TypeDescGenerator> Module::types() const noexcept {
|
||||
return {};
|
||||
}
|
||||
|
||||
ox::Vector<keel::BaseConverter const*> Module::converters() const noexcept {
|
||||
ox::Vector<Converter> Module::converters() const noexcept {
|
||||
return {};
|
||||
}
|
||||
|
||||
|
@@ -6,13 +6,11 @@
|
||||
|
||||
#include <ox/clargs/clargs.hpp>
|
||||
#include <ox/fs/fs.hpp>
|
||||
#include <ox/logconn/def.hpp>
|
||||
#include <ox/logconn/logconn.hpp>
|
||||
#include <ox/oc/write.hpp>
|
||||
|
||||
#include <keel/keel.hpp>
|
||||
|
||||
static ox::Error writeFileBuff(ox::StringView path, ox::BufferView const buff) noexcept {
|
||||
static ox::Error writeFileBuff(ox::StringViewCR path, ox::BufferView const &buff) noexcept {
|
||||
try {
|
||||
std::ofstream f(std::string(toStdStringView(path)), std::ios::binary);
|
||||
f.write(buff.data(), static_cast<intptr_t>(buff.size()));
|
||||
@@ -22,7 +20,7 @@ static ox::Error writeFileBuff(ox::StringView path, ox::BufferView const buff) n
|
||||
return {};
|
||||
}
|
||||
|
||||
static ox::Result<ox::Buffer> readFileBuff(ox::StringView path) noexcept {
|
||||
static ox::Result<ox::Buffer> readFileBuff(ox::StringViewCR path) noexcept {
|
||||
std::ifstream file(std::string(toStdStringView(path)), std::ios::binary | std::ios::ate);
|
||||
if (!file.good()) {
|
||||
oxErrorf("Could not find OxFS file: {}", path);
|
||||
@@ -42,7 +40,7 @@ static ox::Result<ox::Buffer> readFileBuff(ox::StringView path) noexcept {
|
||||
|
||||
static ox::Error generateTypes(ox::TypeStore &ts) noexcept {
|
||||
for (auto const mod : keel::modules()) {
|
||||
for (auto gen : mod->types()) {
|
||||
for (auto const gen : mod->types()) {
|
||||
OX_RETURN_ERROR(gen(ts));
|
||||
}
|
||||
}
|
||||
@@ -50,14 +48,27 @@ static ox::Error generateTypes(ox::TypeStore &ts) noexcept {
|
||||
}
|
||||
|
||||
static ox::Error pack(
|
||||
ox::StringView argSrc,
|
||||
ox::StringView argRomBin,
|
||||
ox::StringView argManifest,
|
||||
ox::StringView projectDataDir) noexcept {
|
||||
ox::StringViewCR argSrc,
|
||||
ox::StringViewCR argRomBin,
|
||||
ox::StringViewCR argManifest,
|
||||
ox::StringViewCR projectDataDir) noexcept {
|
||||
ox::Buffer dstBuff(32 * ox::units::MB);
|
||||
OX_RETURN_ERROR(ox::FileSystem32::format(dstBuff.data(), dstBuff.size()));
|
||||
ox::FileSystem32 dst(dstBuff);
|
||||
OX_REQUIRE(ctx, keel::init(ox::make_unique<ox::PassThroughFS>(argSrc), "keel-pack"));
|
||||
keel::DuplicateSet duplicateSet;
|
||||
OX_REQUIRE(ctx, keel::init(
|
||||
ox::make_unique<ox::PassThroughFS>(argSrc), "keel-pack", duplicateSet));
|
||||
if (duplicateSet.size()) {
|
||||
oxErr("Multiple files have the same UUID:\n");
|
||||
for (auto const &k : duplicateSet.keys()) {
|
||||
oxErrf("\n\t{}:\n", k.toString());
|
||||
for (auto const &v : duplicateSet[k]) {
|
||||
oxErrf("\t\t{}\n", v);
|
||||
}
|
||||
}
|
||||
oxErr("\n");
|
||||
std::exit(1);
|
||||
}
|
||||
keel::TypeStore ts(*ctx->rom, ox::sfmt("{}/type_descriptors", projectDataDir));
|
||||
OX_RETURN_ERROR(generateTypes(ts));
|
||||
keel::Manifest manifest;
|
||||
@@ -82,10 +93,10 @@ static ox::Error pack(
|
||||
}
|
||||
|
||||
ox::Error run(
|
||||
[[maybe_unused]] ox::StringView project,
|
||||
[[maybe_unused]] ox::StringView appName,
|
||||
ox::StringView projectDataDir,
|
||||
ox::SpanView<ox::CString> argv) noexcept {
|
||||
[[maybe_unused]] ox::StringView const project,
|
||||
[[maybe_unused]] ox::StringView const appName,
|
||||
ox::StringView const projectDataDir,
|
||||
ox::SpanView<ox::CString> const argv) noexcept {
|
||||
ox::ClArgs const args(argv);
|
||||
auto const argSrc = args.getString("src", "");
|
||||
auto const argRomBin = args.getString("rom-bin", "");
|
||||
|
@@ -11,13 +11,12 @@
|
||||
namespace keel {
|
||||
|
||||
static ox::Error pathToInode(
|
||||
keel::Context &ctx,
|
||||
ox::FileSystem &dest,
|
||||
Context &ctx,
|
||||
ox::FileSystem const &dest,
|
||||
ox::ModelObject &obj) noexcept {
|
||||
auto &o = obj;
|
||||
OX_REQUIRE(typeVal, o.at("type"));
|
||||
OX_REQUIRE(typeVal, obj.at("type"));
|
||||
auto const type = static_cast<ox::FileAddressType>(typeVal->get<int8_t>());
|
||||
OX_REQUIRE(dataVal, o.at("data"));
|
||||
OX_REQUIRE(dataVal, obj.at("data"));
|
||||
auto &data = dataVal->get<ox::ModelUnion>();
|
||||
ox::String path;
|
||||
switch (type) {
|
||||
@@ -47,13 +46,17 @@ static ox::Error pathToInode(
|
||||
}
|
||||
|
||||
static ox::Error transformFileAddressesObj(
|
||||
keel::Context &ctx, ox::FileSystem &dest, ox::ModelObject &obj) noexcept;
|
||||
Context &ctx,
|
||||
ox::FileSystem const &dest,
|
||||
ox::ModelObject &obj) noexcept;
|
||||
static ox::Error transformFileAddressesVec(
|
||||
keel::Context &ctx, ox::FileSystem &dest, ox::ModelValueVector &v) noexcept;
|
||||
Context &ctx,
|
||||
ox::FileSystem const &dest,
|
||||
ox::ModelValueVector &v) noexcept;
|
||||
|
||||
static ox::Error transformFileAddresses(
|
||||
keel::Context &ctx,
|
||||
ox::FileSystem &dest,
|
||||
Context &ctx,
|
||||
ox::FileSystem const &dest,
|
||||
ox::ModelValue &v) noexcept {
|
||||
if (v.type() == ox::ModelValue::Type::Object) {
|
||||
auto &obj = v.get<ox::ModelObject>();
|
||||
@@ -66,8 +69,8 @@ static ox::Error transformFileAddresses(
|
||||
}
|
||||
|
||||
static ox::Error transformFileAddressesVec(
|
||||
keel::Context &ctx,
|
||||
ox::FileSystem &dest,
|
||||
Context &ctx,
|
||||
ox::FileSystem const &dest,
|
||||
ox::ModelValueVector &v) noexcept {
|
||||
for (auto &f : v) {
|
||||
OX_RETURN_ERROR(transformFileAddresses(ctx, dest, f));
|
||||
@@ -80,13 +83,13 @@ static ox::Error transformFileAddressesVec(
|
||||
* @return error
|
||||
*/
|
||||
static ox::Error transformFileAddressesObj(
|
||||
keel::Context &ctx,
|
||||
ox::FileSystem &dest,
|
||||
Context &ctx,
|
||||
ox::FileSystem const &dest,
|
||||
ox::ModelObject &obj) noexcept {
|
||||
if (obj.typeName() == "net.drinkingtea.ox.FileAddress" && obj.typeVersion() == 1) {
|
||||
return pathToInode(ctx, dest, obj);
|
||||
}
|
||||
for (auto &f : obj) {
|
||||
for (auto const &f : obj) {
|
||||
auto &v = f->value;
|
||||
OX_RETURN_ERROR(transformFileAddresses(ctx, dest, v));
|
||||
}
|
||||
@@ -111,7 +114,7 @@ static ox::Error performPackTransforms(
|
||||
|
||||
static ox::Error doTransformations(
|
||||
Manifest &manifest,
|
||||
keel::Context &ctx,
|
||||
Context &ctx,
|
||||
ox::TypeStore &ts,
|
||||
ox::FileSystem &dest,
|
||||
ox::StringViewCR filePath) noexcept {
|
||||
@@ -134,7 +137,7 @@ static ox::Error doTransformations(
|
||||
// transformations need to be done after the copy to the new FS is complete
|
||||
static ox::Error transformClaw(
|
||||
Manifest &manifest,
|
||||
keel::Context &ctx,
|
||||
Context &ctx,
|
||||
ox::TypeStore &ts,
|
||||
ox::FileSystem &dest,
|
||||
ox::StringViewCR path) noexcept {
|
||||
@@ -200,7 +203,7 @@ static ox::Error copy(
|
||||
|
||||
ox::Error pack(
|
||||
Manifest &manifest,
|
||||
keel::Context &ctx,
|
||||
Context &ctx,
|
||||
ox::TypeStore &ts,
|
||||
ox::FileSystem &dest) noexcept {
|
||||
OX_RETURN_ERROR(copy(manifest, *ctx.rom, dest, "/"));
|
||||
|
@@ -2,20 +2,21 @@
|
||||
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#include <keel/context.hpp>
|
||||
#include <keel/media.hpp>
|
||||
#include <keel/typeconv.hpp>
|
||||
|
||||
namespace keel {
|
||||
|
||||
static ox::Result<BaseConverter const*> findConverter(
|
||||
ox::SpanView<BaseConverter const*> const&converters,
|
||||
ox::SpanView<Converter> const&converters,
|
||||
ox::StringViewCR srcTypeName,
|
||||
int const srcTypeVersion,
|
||||
ox::StringViewCR dstTypeName,
|
||||
int const dstTypeVersion) noexcept {
|
||||
for (auto const&c : converters) {
|
||||
if (c->matches(srcTypeName, srcTypeVersion, dstTypeName, dstTypeVersion)) {
|
||||
return c;
|
||||
if (c.converter().matches(srcTypeName, srcTypeVersion, dstTypeName, dstTypeVersion)) {
|
||||
return &c.converter();
|
||||
}
|
||||
}
|
||||
return ox::Error{1, "Could not find converter"};
|
||||
@@ -31,7 +32,7 @@ static ox::Result<ox::UPtr<Wrap>> convert(BaseConverter const&c, Context &ctx, W
|
||||
|
||||
static ox::Result<ox::UPtr<Wrap>> convert(
|
||||
Context &ctx,
|
||||
ox::SpanView<BaseConverter const*> const&converters,
|
||||
ox::SpanView<Converter> const&converters,
|
||||
auto &src,
|
||||
ox::StringViewCR srcTypeName,
|
||||
int const srcTypeVersion,
|
||||
@@ -45,14 +46,14 @@ static ox::Result<ox::UPtr<Wrap>> convert(
|
||||
}
|
||||
// try to chain multiple converters
|
||||
for (auto const&subConverter : converters) {
|
||||
if (!subConverter->dstMatches(dstTypeName, dstTypeVersion)) {
|
||||
if (!subConverter.converter().dstMatches(dstTypeName, dstTypeVersion)) {
|
||||
continue;
|
||||
}
|
||||
const auto [intermediate, chainErr] =
|
||||
convert(ctx, converters, src, srcTypeName, srcTypeVersion,
|
||||
subConverter->srcTypeName(), subConverter->srcTypeVersion());
|
||||
subConverter.converter().srcTypeName(), subConverter.converter().srcTypeVersion());
|
||||
if (!chainErr) {
|
||||
return subConverter->convertPtrToPtr(ctx, *intermediate);
|
||||
return subConverter.converter().convertPtrToPtr(ctx, *intermediate);
|
||||
}
|
||||
}
|
||||
return ox::Error{1, "Could not convert between types"};
|
||||
|
@@ -5,6 +5,7 @@ add_library(
|
||||
clawviewer.cpp
|
||||
deleteconfirmation.cpp
|
||||
filedialogmanager.cpp
|
||||
font.cpp
|
||||
makecopypopup.cpp
|
||||
newdir.cpp
|
||||
newmenu.cpp
|
||||
|
BIN
src/olympic/studio/applib/src/Roboto-Medium.ttf
Normal file
@@ -13,23 +13,16 @@ extern ox::String appVersion;
|
||||
|
||||
namespace studio {
|
||||
|
||||
AboutPopup::AboutPopup(turbine::Context &ctx) noexcept {
|
||||
m_text = ox::sfmt("{} - {}", keelCtx(ctx).appName, olympic::appVersion);
|
||||
AboutPopup::AboutPopup(turbine::Context &ctx) noexcept:
|
||||
Popup("About"),
|
||||
m_text{sfmt("{} - {}", keelCtx(ctx).appName, olympic::appVersion)} {
|
||||
}
|
||||
|
||||
void AboutPopup::open() noexcept {
|
||||
m_stage = Stage::Opening;
|
||||
}
|
||||
|
||||
void AboutPopup::close() noexcept {
|
||||
m_stage = Stage::Closed;
|
||||
}
|
||||
|
||||
bool AboutPopup::isOpen() const noexcept {
|
||||
return m_stage == Stage::Open;
|
||||
}
|
||||
|
||||
void AboutPopup::draw(StudioContext &sctx) noexcept {
|
||||
void AboutPopup::draw(Context &sctx) noexcept {
|
||||
if (ImGui::IsKeyPressed(ImGuiKey_Escape)) {
|
||||
close();
|
||||
return;
|
||||
}
|
||||
switch (m_stage) {
|
||||
case Stage::Closed:
|
||||
break;
|
||||
@@ -43,7 +36,7 @@ void AboutPopup::draw(StudioContext &sctx) noexcept {
|
||||
ig::centerNextWindow(sctx.tctx);
|
||||
auto open = true;
|
||||
if (ImGui::BeginPopupModal("About", &open, modalFlags)) {
|
||||
ImGui::Text("%s", m_text.c_str());
|
||||
ImGui::Text("%s\n\nBuild date: %s", m_text.c_str(), __DATE__);
|
||||
ImGui::NewLine();
|
||||
ImGui::Dummy({148.0f, 0.0f});
|
||||
ImGui::SameLine();
|
||||
|
@@ -13,29 +13,14 @@
|
||||
|
||||
namespace studio {
|
||||
|
||||
class AboutPopup: public studio::Popup {
|
||||
public:
|
||||
enum class Stage {
|
||||
Closed,
|
||||
Opening,
|
||||
Open,
|
||||
};
|
||||
|
||||
class AboutPopup final: public ig::Popup {
|
||||
private:
|
||||
Stage m_stage = Stage::Closed;
|
||||
ox::String m_text;
|
||||
ox::String const m_text;
|
||||
|
||||
public:
|
||||
explicit AboutPopup(turbine::Context &ctx) noexcept;
|
||||
|
||||
void open() noexcept override;
|
||||
|
||||
void close() noexcept override;
|
||||
|
||||
[[nodiscard]]
|
||||
bool isOpen() const noexcept override;
|
||||
|
||||
void draw(studio::StudioContext &sctx) noexcept override;
|
||||
void draw(Context &sctx) noexcept override;
|
||||
|
||||
};
|
||||
|
||||
|
@@ -28,15 +28,19 @@ class StudioUIDrawer: public turbine::gl::Drawer {
|
||||
};
|
||||
|
||||
static void keyEventHandler(turbine::Context &ctx, turbine::Key key, bool down) noexcept {
|
||||
auto sctx = turbine::applicationData<studio::StudioContext>(ctx);
|
||||
auto sctx = turbine::applicationData<studio::Context>(ctx);
|
||||
sctx->ui.handleKeyEvent(key, down);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
ox::Vector<ox::SpanView<uint8_t>> WindowIcons() noexcept;
|
||||
|
||||
static ox::Error runApp(
|
||||
ox::StringViewCR appName,
|
||||
ox::StringViewCR projectDataDir,
|
||||
ox::UPtr<ox::FileSystem> &&fs) noexcept {
|
||||
OX_REQUIRE_M(ctx, turbine::init(std::move(fs), appName));
|
||||
oxLogError(turbine::setWindowIcon(*ctx, WindowIcons()));
|
||||
turbine::setWindowTitle(*ctx, keelCtx(*ctx).appName);
|
||||
turbine::setKeyEventHandler(*ctx, keyEventHandler);
|
||||
turbine::setRefreshWithin(*ctx, 0);
|
||||
|
@@ -8,12 +8,12 @@
|
||||
|
||||
namespace studio {
|
||||
|
||||
ClawEditor::ClawEditor(StudioContext &sctx, ox::StringParam path):
|
||||
ClawEditor::ClawEditor(Context &sctx, ox::StringParam path):
|
||||
Editor(sctx, std::move(path)),
|
||||
m_obj(sctx.project->loadObj<ox::ModelObject>(itemPath()).unwrapThrow()) {
|
||||
}
|
||||
|
||||
void ClawEditor::draw(StudioContext&) noexcept {
|
||||
void ClawEditor::draw(Context&) noexcept {
|
||||
ImGui::BeginChild("PaletteEditor");
|
||||
static constexpr auto flags = ImGuiTableFlags_RowBg | ImGuiTableFlags_NoBordersInBody;
|
||||
if (ImGui::BeginTable("ObjTree", 3, flags)) {
|
||||
|
@@ -16,9 +16,9 @@ class ClawEditor: public Editor {
|
||||
using ObjPath = ox::Vector<ox::StringView, 8>;
|
||||
ox::ModelObject m_obj;
|
||||
public:
|
||||
ClawEditor(StudioContext &sctx, ox::StringParam path);
|
||||
ClawEditor(Context &sctx, ox::StringParam path);
|
||||
|
||||
void draw(StudioContext&) noexcept final;
|
||||
void draw(Context&) noexcept final;
|
||||
|
||||
private:
|
||||
static void drawRow(ox::ModelValue const&value) noexcept;
|
||||
|
@@ -31,7 +31,11 @@ bool DeleteConfirmation::isOpen() const noexcept {
|
||||
return m_open;
|
||||
}
|
||||
|
||||
void DeleteConfirmation::draw(StudioContext &ctx) noexcept {
|
||||
void DeleteConfirmation::draw(Context &ctx) noexcept {
|
||||
if (ImGui::IsKeyPressed(ImGuiKey_Escape)) {
|
||||
close();
|
||||
return;
|
||||
}
|
||||
switch (m_stage) {
|
||||
case Stage::Closed:
|
||||
break;
|
||||
|