Compare commits
77 Commits
6298ac3a21
...
release-d2
Author | SHA1 | Date | |
---|---|---|---|
13e256b3a9 | |||
6bd74611cd | |||
c3f9cf9a64 | |||
646ab1283f | |||
74cf055610 | |||
0d8ba1b154 | |||
20edbb7f38 | |||
6febc7cc73 | |||
b94d6b5061 | |||
b3952cabbc | |||
2ffc11b04e | |||
96cace2cbb | |||
472f5702bd | |||
c0ac4345d3 | |||
fbebf4ef83 | |||
20513f7749 | |||
25a7873ea2 | |||
d0a32e247e | |||
03d4a5736e | |||
a2e41e6527 | |||
40a7caff90 | |||
26fc5565e8 | |||
388541ce32 | |||
6c194667b9 | |||
62d0579f40 | |||
202595b2a6 | |||
cb21ff3f04 | |||
2a8e3c2dc4 | |||
998066d377 | |||
fefb876fe7 | |||
5979e9885e | |||
a17abe4639 | |||
d62f913855 | |||
12bb7475fc | |||
df2c7e2b67 | |||
713aec887b | |||
3089cd7afc | |||
00638bc812 | |||
e002109829 | |||
b4798fd2ab | |||
3c804bf62a | |||
d39d552bd9 | |||
b7202a2b0d | |||
4e27a4c1f5 | |||
4ef31762d0 | |||
8b22a8f339 | |||
d45ff05bcd | |||
671dd86206 | |||
0abadc1850 | |||
4e068d628c | |||
4461f99fa4 | |||
cd1f4bdaa3 | |||
4728699585 | |||
105a1e5559 | |||
1bc18e34a8 | |||
fb8d295fcb | |||
8459d3baea | |||
804d78e116 | |||
5351e9aa0a | |||
b5954f15c5 | |||
5dce9dd377 | |||
0570f76236 | |||
e22b658a67 | |||
56b9cb6ebf | |||
eaa9a2415e | |||
95256a9a0d | |||
2286238abc | |||
13f0bf57e4 | |||
8eb1ac215b | |||
e132f2fd1b | |||
12f6b22c8b | |||
6c858e0c4e | |||
c6b58f7c63 | |||
a22aafaf96 | |||
8d04af691e | |||
6c34198f58 | |||
f63c58169f |
@ -4,7 +4,7 @@ on: [push]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: nostalgia
|
||||
runs-on: olympic
|
||||
steps:
|
||||
- name: Check out repository code
|
||||
uses: actions/checkout@v3
|
||||
@ -17,3 +17,10 @@ jobs:
|
||||
- run: make purge configure-release
|
||||
- run: make build
|
||||
- run: make test
|
||||
- run: make install
|
||||
- run: mv dist/linux-x86_64-release nostalgia-linux-x86_64
|
||||
- run: tar cf nostalgia-linux-x86_64.tar nostalgia-linux-x86_64
|
||||
- uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: nostalgia-linux-x86_64
|
||||
path: nostalgia-linux-x86_64.tar
|
||||
|
2
deps/buildcore/base.mk
vendored
2
deps/buildcore/base.mk
vendored
@ -93,7 +93,7 @@ purge:
|
||||
${BC_CMD_RM_RF} compile_commands.json
|
||||
.PHONY: test
|
||||
test: build
|
||||
${BC_CMD_ENVRUN} mypy ${BC_VAR_SCRIPTS}
|
||||
${BC_CMD_ENVRUN} ${BC_CMD_PY3} -m mypy ${BC_VAR_SCRIPTS}
|
||||
${BC_CMD_CMAKE_BUILD} ${BC_VAR_BUILD_PATH} test
|
||||
.PHONY: test-verbose
|
||||
test-verbose: build
|
||||
|
2
deps/buildcore/scripts/util.py
vendored
2
deps/buildcore/scripts/util.py
vendored
@ -35,4 +35,6 @@ def get_arch() -> str:
|
||||
arch = platform.machine().lower()
|
||||
if arch == 'amd64':
|
||||
arch = 'x86_64'
|
||||
elif arch == 'aarch64':
|
||||
arch = 'arm64'
|
||||
return arch
|
||||
|
2
deps/nfde/CMakeLists.txt
vendored
2
deps/nfde/CMakeLists.txt
vendored
@ -1,4 +1,4 @@
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
cmake_minimum_required(VERSION 3.19)
|
||||
project(nativefiledialog-extended VERSION 1.1.1)
|
||||
|
||||
set(nfd_ROOT_PROJECT OFF)
|
||||
|
2
deps/ox/deps/jsoncpp/CMakeLists.txt
vendored
2
deps/ox/deps/jsoncpp/CMakeLists.txt
vendored
@ -12,7 +12,7 @@
|
||||
# CMake versions greater than the JSONCPP_NEWEST_VALIDATED_POLICIES_VERSION policies will
|
||||
# continue to generate policy warnings "CMake Warning (dev)...Policy CMP0XXX is not set:"
|
||||
#
|
||||
set(JSONCPP_OLDEST_VALIDATED_POLICIES_VERSION "3.8.0")
|
||||
set(JSONCPP_OLDEST_VALIDATED_POLICIES_VERSION "3.13.2")
|
||||
set(JSONCPP_NEWEST_VALIDATED_POLICIES_VERSION "3.13.2")
|
||||
cmake_minimum_required(VERSION ${JSONCPP_OLDEST_VALIDATED_POLICIES_VERSION})
|
||||
if("${CMAKE_VERSION}" VERSION_LESS "${JSONCPP_NEWEST_VALIDATED_POLICIES_VERSION}")
|
||||
|
45
deps/ox/src/ox/fs/filesystem/filesystem.cpp
vendored
45
deps/ox/src/ox/fs/filesystem/filesystem.cpp
vendored
@ -37,6 +37,30 @@ Error FileSystem::read(const FileAddress &addr, void *buffer, std::size_t size)
|
||||
}
|
||||
}
|
||||
|
||||
Result<Buffer> FileSystem::read(FileAddress const &addr, size_t const size) noexcept {
|
||||
Result<Buffer> out;
|
||||
out.value.resize(size);
|
||||
switch (addr.type()) {
|
||||
case FileAddressType::Inode:
|
||||
OX_RETURN_ERROR(readFileInode(addr.getInode().value, out.value.data(), size));
|
||||
break;
|
||||
case FileAddressType::ConstPath:
|
||||
case FileAddressType::Path:
|
||||
OX_RETURN_ERROR(readFilePath(StringView{addr.getPath().value}, out.value.data(), size));
|
||||
break;
|
||||
default:
|
||||
return ox::Error{1};
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
Result<Buffer> FileSystem::read(StringViewCR path, size_t const size) noexcept {
|
||||
Result<Buffer> out;
|
||||
out.value.resize(size);
|
||||
OX_RETURN_ERROR(readFilePath(path, out.value.data(), size));
|
||||
return out;
|
||||
}
|
||||
|
||||
Result<Buffer> FileSystem::read(const FileAddress &addr) noexcept {
|
||||
OX_REQUIRE(s, stat(addr));
|
||||
Buffer buff(static_cast<std::size_t>(s.size));
|
||||
@ -51,18 +75,33 @@ Result<Buffer> FileSystem::read(StringViewCR path) noexcept {
|
||||
return buff;
|
||||
}
|
||||
|
||||
Error FileSystem::read(const FileAddress &addr, std::size_t readStart, std::size_t readSize, void *buffer, std::size_t *size) noexcept {
|
||||
Error FileSystem::read(
|
||||
FileAddress const &addr,
|
||||
std::size_t const readStart,
|
||||
std::size_t const readSize,
|
||||
void *buffer,
|
||||
std::size_t *size) noexcept {
|
||||
switch (addr.type()) {
|
||||
case FileAddressType::Inode:
|
||||
return read(addr.getInode().value, readStart, readSize, buffer, size);
|
||||
return readFileInodeRange(addr.getInode().value, readStart, readSize, buffer, size);
|
||||
case FileAddressType::ConstPath:
|
||||
case FileAddressType::Path:
|
||||
return ox::Error(2, "Unsupported for path lookups");
|
||||
return readFilePathRange(addr.getPath().value, readStart, readSize, buffer, size);
|
||||
default:
|
||||
return ox::Error(1);
|
||||
}
|
||||
}
|
||||
|
||||
Result<size_t> FileSystem::read(
|
||||
StringViewCR path,
|
||||
std::size_t const readStart,
|
||||
std::size_t const readSize,
|
||||
Span<char> buff) noexcept {
|
||||
size_t szOut{buff.size()};
|
||||
OX_RETURN_ERROR(readFilePathRange(path, readStart, readSize, buff.data(), &szOut));
|
||||
return szOut;
|
||||
}
|
||||
|
||||
Error FileSystem::write(const FileAddress &addr, const void *buffer, uint64_t size, FileType fileType) noexcept {
|
||||
switch (addr.type()) {
|
||||
case FileAddressType::Inode:
|
||||
|
38
deps/ox/src/ox/fs/filesystem/filesystem.hpp
vendored
38
deps/ox/src/ox/fs/filesystem/filesystem.hpp
vendored
@ -41,6 +41,10 @@ class FileSystem {
|
||||
|
||||
Error read(const FileAddress &addr, void *buffer, std::size_t size) noexcept;
|
||||
|
||||
Result<Buffer> read(FileAddress const &addr, size_t size) noexcept;
|
||||
|
||||
Result<Buffer> read(StringViewCR path, size_t size) noexcept;
|
||||
|
||||
Result<Buffer> read(const FileAddress &addr) noexcept;
|
||||
|
||||
Result<Buffer> read(StringViewCR path) noexcept;
|
||||
@ -53,7 +57,24 @@ class FileSystem {
|
||||
return readFileInode(inode, buffer, buffSize);
|
||||
}
|
||||
|
||||
Error read(const FileAddress &addr, std::size_t readStart, std::size_t readSize, void *buffer, std::size_t *size) noexcept;
|
||||
Error read(
|
||||
FileAddress const &addr,
|
||||
size_t readStart,
|
||||
size_t readSize,
|
||||
void *buffer,
|
||||
size_t *size) noexcept;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param path
|
||||
* @param readStart
|
||||
* @param readSize
|
||||
* @param buffer
|
||||
* @param size
|
||||
* @return error or number of bytes read
|
||||
*/
|
||||
Result<size_t> read(
|
||||
StringViewCR path, size_t readStart, size_t readSize, ox::Span<char> buff) noexcept;
|
||||
|
||||
virtual Result<Vector<String>> ls(StringViewCR dir) const noexcept = 0;
|
||||
|
||||
@ -140,7 +161,10 @@ class FileSystem {
|
||||
|
||||
virtual Error readFileInode(uint64_t inode, void *buffer, std::size_t size) noexcept = 0;
|
||||
|
||||
virtual Error readFileInodeRange(uint64_t inode, std::size_t readStart, std::size_t readSize, void *buffer, std::size_t *size) noexcept = 0;
|
||||
virtual Error readFilePathRange(
|
||||
StringViewCR path, size_t readStart, size_t readSize, void *buffer, size_t *buffSize) noexcept = 0;
|
||||
|
||||
virtual Error readFileInodeRange(uint64_t inode, size_t readStart, size_t readSize, void *buffer, size_t *size) noexcept = 0;
|
||||
|
||||
virtual Error removePath(StringViewCR path, bool recursive) noexcept = 0;
|
||||
|
||||
@ -211,6 +235,9 @@ class FileSystemTemplate: public MemFS {
|
||||
|
||||
Error readFileInodeRange(uint64_t inode, std::size_t readStart, std::size_t readSize, void *buffer, std::size_t *size) noexcept override;
|
||||
|
||||
Error readFilePathRange(
|
||||
StringViewCR path, size_t readStart, size_t readSize, void *buffer, size_t *buffSize) noexcept override;
|
||||
|
||||
Error removePath(StringViewCR path, bool recursive) noexcept override;
|
||||
|
||||
Result<const char*> directAccessInode(uint64_t) const noexcept override;
|
||||
@ -358,6 +385,13 @@ Error FileSystemTemplate<FileStore, Directory>::readFileInodeRange(uint64_t inod
|
||||
return m_fs.read(inode, readStart, readSize, reinterpret_cast<uint8_t*>(buffer), size);
|
||||
}
|
||||
|
||||
template<typename FileStore, typename Directory>
|
||||
Error FileSystemTemplate<FileStore, Directory>::readFilePathRange(
|
||||
StringViewCR path, size_t readStart, size_t readSize, void *buffer, size_t *buffSize) noexcept {
|
||||
OX_REQUIRE(s, stat(path));
|
||||
return readFileInodeRange(s.inode, readStart, readSize, buffer, buffSize);
|
||||
}
|
||||
|
||||
template<typename FileStore, typename Directory>
|
||||
Error FileSystemTemplate<FileStore, Directory>::removePath(StringViewCR path, bool recursive) noexcept {
|
||||
OX_REQUIRE(fd, fileSystemData());
|
||||
|
26
deps/ox/src/ox/fs/filesystem/passthroughfs.cpp
vendored
26
deps/ox/src/ox/fs/filesystem/passthroughfs.cpp
vendored
@ -93,7 +93,9 @@ Result<FileStat> PassThroughFS::statPath(StringViewCR path) const noexcept {
|
||||
oxTracef("ox.fs.PassThroughFS.statInode", "{} {}", ec.message(), path);
|
||||
const uint64_t size = type == FileType::Directory ? 0 : std::filesystem::file_size(p, ec);
|
||||
oxTracef("ox.fs.PassThroughFS.statInode.size", "{} {}", path, size);
|
||||
OX_RETURN_ERROR(ox::Error(static_cast<ox::ErrorCode>(ec.value()), "PassThroughFS: stat failed"));
|
||||
if (auto err = ec.value()) {
|
||||
return ox::Error{static_cast<ox::ErrorCode>(err), "PassThroughFS: stat failed"};
|
||||
}
|
||||
return FileStat{0, 0, size, type};
|
||||
}
|
||||
|
||||
@ -154,6 +156,25 @@ Error PassThroughFS::readFileInode(uint64_t, void*, std::size_t) noexcept {
|
||||
return ox::Error(1, "readFileInode(uint64_t, void*, std::size_t) is not supported by PassThroughFS");
|
||||
}
|
||||
|
||||
Error PassThroughFS::readFilePathRange(
|
||||
StringViewCR path, size_t const readStart, size_t readSize, void *buffer, size_t *buffSize) noexcept {
|
||||
try {
|
||||
std::ifstream file(m_path / stripSlash(path), std::ios::binary | std::ios::ate);
|
||||
auto const size = static_cast<size_t>(file.tellg());
|
||||
readSize = ox::min(readSize, size);
|
||||
file.seekg(static_cast<off_t>(readStart), std::ios::beg);
|
||||
if (readSize > *buffSize) {
|
||||
oxTracef("ox.fs.PassThroughFS.read.error", "Read failed: Buffer too small: {}", path);
|
||||
return ox::Error{1};
|
||||
}
|
||||
file.read(static_cast<char*>(buffer), static_cast<std::streamsize>(readSize));
|
||||
return {};
|
||||
} catch (std::fstream::failure const &f) {
|
||||
oxTracef("ox.fs.PassThroughFS.read.error", "Read of {} failed: {}", path, f.what());
|
||||
return ox::Error{2};
|
||||
}
|
||||
}
|
||||
|
||||
Error PassThroughFS::readFileInodeRange(uint64_t, std::size_t, std::size_t, void*, std::size_t*) noexcept {
|
||||
// unsupported
|
||||
return ox::Error(1, "read(uint64_t, std::size_t, std::size_t, void*, std::size_t*) is not supported by PassThroughFS");
|
||||
@ -185,8 +206,7 @@ Error PassThroughFS::writeFileInode(uint64_t, const void*, uint64_t, FileType) n
|
||||
}
|
||||
|
||||
std::string_view PassThroughFS::stripSlash(StringView path) noexcept {
|
||||
const auto pathLen = ox::strlen(path);
|
||||
for (auto i = 0u; i < pathLen && path[0] == '/'; i++) {
|
||||
for (auto i = 0u; i < path.len() && path[0] == '/'; i++) {
|
||||
path = substr(path, 1);
|
||||
}
|
||||
return {path.data(), path.bytes()};
|
||||
|
@ -71,6 +71,9 @@ class PassThroughFS: public FileSystem {
|
||||
|
||||
Error readFileInode(uint64_t inode, void *buffer, std::size_t size) noexcept override;
|
||||
|
||||
Error readFilePathRange(
|
||||
StringViewCR path, size_t readStart, size_t readSize, void *buffer, size_t *buffSize) noexcept override;
|
||||
|
||||
Error readFileInodeRange(uint64_t inode, std::size_t readStart, std::size_t readSize, void *buffer, std::size_t *size) noexcept override;
|
||||
|
||||
Error removePath(StringViewCR path, bool recursive) noexcept override;
|
||||
|
4
deps/ox/src/ox/std/array.hpp
vendored
4
deps/ox/src/ox/std/array.hpp
vendored
@ -181,13 +181,13 @@ constexpr Array<T, ArraySize> &Array<T, ArraySize>::operator=(Array &&other) noe
|
||||
|
||||
template<typename T, std::size_t ArraySize>
|
||||
constexpr T &Array<T, ArraySize>::operator[](std::size_t i) noexcept {
|
||||
ox::primitiveAssert(__FILE__, __LINE__, i < size(), "Array access overflow");
|
||||
boundsCheck(__FILE__, __LINE__, i, size(), "Array access overflow");
|
||||
return m_items[i];
|
||||
}
|
||||
|
||||
template<typename T, std::size_t ArraySize>
|
||||
constexpr const T &Array<T, ArraySize>::operator[](std::size_t i) const noexcept {
|
||||
ox::primitiveAssert(__FILE__, __LINE__, i < size(), "Array access overflow");
|
||||
boundsCheck(__FILE__, __LINE__, i, size(), "Array access overflow");
|
||||
return m_items[i];
|
||||
}
|
||||
|
||||
|
6
deps/ox/src/ox/std/defines.hpp
vendored
6
deps/ox/src/ox/std/defines.hpp
vendored
@ -41,6 +41,12 @@ constexpr auto Debug = true;
|
||||
constexpr auto Debug = false;
|
||||
#endif
|
||||
|
||||
#if defined(OX_CHECK_BOUNDS)
|
||||
constexpr auto CheckBounds = true;
|
||||
#else
|
||||
constexpr auto CheckBounds = Debug;
|
||||
#endif
|
||||
|
||||
#if defined(NDEBUG)
|
||||
constexpr auto NDebug = true;
|
||||
#else
|
||||
|
13
deps/ox/src/ox/std/error.hpp
vendored
13
deps/ox/src/ox/std/error.hpp
vendored
@ -330,4 +330,17 @@ constexpr void primitiveAssert(char const*file, int line, bool pass, char const*
|
||||
}
|
||||
}
|
||||
|
||||
constexpr void boundsCheck(
|
||||
char const*file,
|
||||
int const line,
|
||||
size_t const i,
|
||||
size_t const sz,
|
||||
char const*msg) noexcept {
|
||||
if constexpr(defines::CheckBounds) {
|
||||
if (i >= sz) [[unlikely]] {
|
||||
panic(file, line, msg, ox::Error{1});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
6
deps/ox/src/ox/std/iterator.hpp
vendored
6
deps/ox/src/ox/std/iterator.hpp
vendored
@ -133,17 +133,17 @@ struct SpanIterator {
|
||||
}
|
||||
|
||||
constexpr PtrType operator->() const noexcept {
|
||||
ox::primitiveAssert(__FILE__, __LINE__, m_offset < m_max, "SpanIterator access overflow");
|
||||
boundsCheck(__FILE__, __LINE__, m_offset, m_max, "SpanIterator access overflow");
|
||||
return &m_t[m_offset];
|
||||
}
|
||||
|
||||
constexpr RefType operator*() const noexcept {
|
||||
ox::primitiveAssert(__FILE__, __LINE__, m_offset < m_max, "SpanIterator access overflow");
|
||||
boundsCheck(__FILE__, __LINE__, m_offset, m_max, "SpanIterator access overflow");
|
||||
return m_t[m_offset];
|
||||
}
|
||||
|
||||
constexpr RefType operator[](std::size_t s) const noexcept {
|
||||
ox::primitiveAssert(__FILE__, __LINE__, s < m_max, "SpanIterator access overflow");
|
||||
boundsCheck(__FILE__, __LINE__, s, m_max, "SpanIterator access overflow");
|
||||
return m_t[s];
|
||||
}
|
||||
|
||||
|
8
deps/ox/src/ox/std/span.hpp
vendored
8
deps/ox/src/ox/std/span.hpp
vendored
@ -129,22 +129,22 @@ class Span {
|
||||
}
|
||||
|
||||
constexpr T &operator[](std::size_t i) noexcept {
|
||||
ox::primitiveAssert(__FILE__, __LINE__, i < size(), "Span access overflow");
|
||||
boundsCheck(__FILE__, __LINE__, i, size(), "Span access overflow");
|
||||
return m_items[i];
|
||||
}
|
||||
|
||||
constexpr T const&operator[](std::size_t i) const noexcept {
|
||||
ox::primitiveAssert(__FILE__, __LINE__, i < size(), "Span access overflow");
|
||||
boundsCheck(__FILE__, __LINE__, i, size(), "Span access overflow");
|
||||
return m_items[i];
|
||||
}
|
||||
|
||||
constexpr Span operator+(size_t i) const noexcept {
|
||||
ox::primitiveAssert(__FILE__, __LINE__, i < size(), "Span access overflow");
|
||||
boundsCheck(__FILE__, __LINE__, i, size(), "Span access overflow");
|
||||
return {m_items + i, m_size - i};
|
||||
}
|
||||
|
||||
constexpr Span operator+=(size_t i) noexcept {
|
||||
ox::primitiveAssert(__FILE__, __LINE__, i < size(), "Span access overflow");
|
||||
boundsCheck(__FILE__, __LINE__, i, size(), "Span access overflow");
|
||||
m_items += i;
|
||||
m_size -= i;
|
||||
return *this;
|
||||
|
42
deps/ox/src/ox/std/utility.hpp
vendored
42
deps/ox/src/ox/std/utility.hpp
vendored
@ -27,6 +27,48 @@ constexpr void swap(T &a, T &b) noexcept {
|
||||
b = std::move(temp);
|
||||
}
|
||||
|
||||
template<typename T, typename U>
|
||||
constexpr bool cmp_equal(T const t, U const u) noexcept {
|
||||
if constexpr(ox::is_signed_v<T> == ox::is_signed_v<U>) {
|
||||
return t == u;
|
||||
} else if constexpr(ox::is_signed_v<T>) {
|
||||
return ox::Signed<T>{t} == u;
|
||||
} else {
|
||||
return t == ox::Signed<U>{u};
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T, typename U>
|
||||
constexpr bool cmp_less(T const t, U const u) noexcept {
|
||||
if constexpr(ox::is_signed_v<T> == ox::is_signed_v<U>) {
|
||||
return t < u;
|
||||
} else if constexpr(ox::is_signed_v<T>) {
|
||||
return ox::Signed<T>{t} < u;
|
||||
} else {
|
||||
return t < ox::Signed<U>{u};
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T, typename U>
|
||||
constexpr bool cmp_not_equal(T const t, U const u) noexcept {
|
||||
return !std::cmp_equal(t, u);
|
||||
}
|
||||
|
||||
template<typename T, typename U>
|
||||
constexpr bool cmp_greater(T const t, U const u) noexcept {
|
||||
return std::cmp_less(u, t);
|
||||
}
|
||||
|
||||
template<typename T, typename U>
|
||||
constexpr bool cmp_less_equal(T const t, U const u) noexcept {
|
||||
return !std::cmp_less(u, t);
|
||||
}
|
||||
|
||||
template<typename T, typename U>
|
||||
constexpr bool cmp_greater_equal(T const t, U const u) noexcept {
|
||||
return !std::cmp_less(t, u);
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
|
17
deps/ox/src/ox/std/vector.hpp
vendored
17
deps/ox/src/ox/std/vector.hpp
vendored
@ -311,6 +311,8 @@ class Vector: detail::VectorAllocator<T, Allocator, SmallVectorSize> {
|
||||
*/
|
||||
constexpr Error unordered_erase(std::size_t pos) noexcept(useNoexcept);
|
||||
|
||||
constexpr Error remove(T const &val);
|
||||
|
||||
constexpr void reserve(std::size_t cap) noexcept(useNoexcept);
|
||||
|
||||
constexpr void shrink_to_fit() noexcept(useNoexcept);
|
||||
@ -427,13 +429,13 @@ constexpr Vector<T, SmallVectorSize, Allocator> &Vector<T, SmallVectorSize, Allo
|
||||
|
||||
template<typename T, std::size_t SmallVectorSize, typename Allocator>
|
||||
constexpr T &Vector<T, SmallVectorSize, Allocator>::operator[](std::size_t i) noexcept {
|
||||
ox::primitiveAssert(__FILE__, __LINE__, i < size(), "Vector access overflow");
|
||||
boundsCheck(__FILE__, __LINE__, i, size(), "Vector access overflow");
|
||||
return m_items[i];
|
||||
}
|
||||
|
||||
template<typename T, std::size_t SmallVectorSize, typename Allocator>
|
||||
constexpr const T &Vector<T, SmallVectorSize, Allocator>::operator[](std::size_t i) const noexcept {
|
||||
ox::primitiveAssert(__FILE__, __LINE__, i < size(), "Vector access overflow");
|
||||
boundsCheck(__FILE__, __LINE__, i, size(), "Vector access overflow");
|
||||
return m_items[i];
|
||||
}
|
||||
|
||||
@ -659,6 +661,17 @@ constexpr Error Vector<T, SmallVectorSize, Allocator>::unordered_erase(std::size
|
||||
return ox::Error(0);
|
||||
}
|
||||
|
||||
template<typename T, std::size_t SmallVectorSize, typename Allocator>
|
||||
constexpr ox::Error Vector<T, SmallVectorSize, Allocator>::remove(T const &val) {
|
||||
for (size_t i{}; auto const &v : *this) {
|
||||
if (v == val) {
|
||||
return erase(i).error;
|
||||
}
|
||||
++i;
|
||||
}
|
||||
return ox::Error{1, "element not found"};
|
||||
}
|
||||
|
||||
template<typename T, std::size_t SmallVectorSize, typename Allocator>
|
||||
constexpr void Vector<T, SmallVectorSize, Allocator>::reserve(std::size_t cap) noexcept(useNoexcept) {
|
||||
if (cap <= m_cap) {
|
||||
|
@ -5,12 +5,19 @@
|
||||
* Add TileSheetV5. TileSheetV5 retains the bpp field for the sake of
|
||||
CompactTileSheet, but always store it pixel as 8 bpp for itself.
|
||||
* Add ability to move subsheets in the subsheet tree.
|
||||
* Add Flip X and Flip Y button for TileSheet Editor.
|
||||
* Add Flip X and Flip Y functionality to TileSheet Editor.
|
||||
* Add rotate functionality to TileSheet Editor.
|
||||
* Add draw line tool to TileSheet editor
|
||||
* Replace file picker combo boxes with a browse button and file picker, and
|
||||
support for dragging files from the project explorer.
|
||||
* Add ability to jump to a color in a Palette by double clicking on the
|
||||
color from the TileSheet editor
|
||||
* Add ability to create directories.
|
||||
* Add ability to add files to specific directories.
|
||||
* Add ability to delete files from the project explorer.
|
||||
* Ctrl-<num key> keyboard shortcuts for jumping between tabs.
|
||||
* Fix Palette Editor to ignore keyboard input when popups are open.
|
||||
* Palette Editor move color mechanism now uses drag and drop.
|
||||
* Add ability to reorder Palette pages.
|
||||
* Add warning for closing a tab with unsaved changes.
|
||||
* Add ability to close a tab with Ctrl/Cmd-W
|
||||
|
@ -0,0 +1,23 @@
|
||||
O1;net.drinkingtea.ox.TypeDescriptor;1;{
|
||||
"fieldList" :
|
||||
[
|
||||
{
|
||||
"fieldName" : "pages",
|
||||
"subscriptLevels" : 2,
|
||||
"subscriptStack" :
|
||||
[
|
||||
{
|
||||
"subscriptType" : 4
|
||||
},
|
||||
{
|
||||
"subscriptType" : 4
|
||||
}
|
||||
],
|
||||
"typeId" : "B.uint16;0"
|
||||
}
|
||||
],
|
||||
"preloadable" : true,
|
||||
"primitiveType" : 5,
|
||||
"typeName" : "net.drinkingtea.nostalgia.gfx.CompactPalette",
|
||||
"typeVersion" : 1
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
O1;net.drinkingtea.ox.TypeDescriptor;1;{
|
||||
"fieldList" :
|
||||
[
|
||||
{
|
||||
"fieldName" : "bpp",
|
||||
"typeId" : "B.int8;0"
|
||||
},
|
||||
{
|
||||
"fieldName" : "defaultPalette",
|
||||
"typeId" : "net.drinkingtea.ox.FileAddress;1"
|
||||
},
|
||||
{
|
||||
"fieldName" : "pixels",
|
||||
"subscriptLevels" : 1,
|
||||
"subscriptStack" :
|
||||
[
|
||||
{
|
||||
"subscriptType" : 4
|
||||
}
|
||||
],
|
||||
"typeId" : "B.uint8;0"
|
||||
}
|
||||
],
|
||||
"preloadable" : true,
|
||||
"primitiveType" : 5,
|
||||
"typeName" : "net.drinkingtea.nostalgia.gfx.CompactTileSheet",
|
||||
"typeVersion" : 1
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
O1;net.drinkingtea.ox.TypeDescriptor;1;{
|
||||
"fieldList" :
|
||||
[
|
||||
{
|
||||
"fieldName" : "name",
|
||||
"typeId" : "net.drinkingtea.ox.BasicString#8#;1"
|
||||
},
|
||||
{
|
||||
"fieldName" : "colors",
|
||||
"subscriptLevels" : 1,
|
||||
"subscriptStack" :
|
||||
[
|
||||
{
|
||||
"subscriptType" : 4
|
||||
}
|
||||
],
|
||||
"typeId" : "net.drinkingtea.nostalgia.gfx.PaletteColor;2"
|
||||
}
|
||||
],
|
||||
"primitiveType" : 5,
|
||||
"typeName" : "net.drinkingtea.nostalgia.gfx.Palette.PalettePage",
|
||||
"typeVersion" : 2
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
O1;net.drinkingtea.ox.TypeDescriptor;1;{
|
||||
"fieldList" :
|
||||
[
|
||||
{
|
||||
"fieldName" : "colorNames",
|
||||
"subscriptLevels" : 1,
|
||||
"subscriptStack" :
|
||||
[
|
||||
{
|
||||
"subscriptType" : 4
|
||||
}
|
||||
],
|
||||
"typeId" : "net.drinkingtea.ox.BasicString#8#;1"
|
||||
},
|
||||
{
|
||||
"fieldName" : "pages",
|
||||
"subscriptLevels" : 1,
|
||||
"subscriptStack" :
|
||||
[
|
||||
{
|
||||
"subscriptType" : 4
|
||||
}
|
||||
],
|
||||
"typeId" : "net.drinkingtea.nostalgia.gfx.Palette.PalettePage;2"
|
||||
}
|
||||
],
|
||||
"preloadable" : true,
|
||||
"primitiveType" : 5,
|
||||
"typeName" : "net.drinkingtea.nostalgia.gfx.Palette",
|
||||
"typeVersion" : 5
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
O1;net.drinkingtea.ox.TypeDescriptor;1;{
|
||||
"fieldList" :
|
||||
[
|
||||
{
|
||||
"fieldName" : "r",
|
||||
"typeId" : "B.uint8;0"
|
||||
},
|
||||
{
|
||||
"fieldName" : "g",
|
||||
"typeId" : "B.uint8;0"
|
||||
},
|
||||
{
|
||||
"fieldName" : "b",
|
||||
"typeId" : "B.uint8;0"
|
||||
},
|
||||
{
|
||||
"fieldName" : "a",
|
||||
"typeId" : "B.uint8;0"
|
||||
}
|
||||
],
|
||||
"primitiveType" : 5,
|
||||
"typeName" : "net.drinkingtea.nostalgia.gfx.PaletteColor",
|
||||
"typeVersion" : 2
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
O1;net.drinkingtea.ox.TypeDescriptor;1;{
|
||||
"fieldList" :
|
||||
[
|
||||
{
|
||||
"fieldName" : "id",
|
||||
"typeId" : "B.int32;0"
|
||||
},
|
||||
{
|
||||
"fieldName" : "name",
|
||||
"typeId" : "net.drinkingtea.ox.BasicString#8#;1"
|
||||
},
|
||||
{
|
||||
"fieldName" : "rows",
|
||||
"typeId" : "B.int32;0"
|
||||
},
|
||||
{
|
||||
"fieldName" : "columns",
|
||||
"typeId" : "B.int32;0"
|
||||
},
|
||||
{
|
||||
"fieldName" : "subsheets",
|
||||
"subscriptLevels" : 1,
|
||||
"subscriptStack" :
|
||||
[
|
||||
{
|
||||
"subscriptType" : 4
|
||||
}
|
||||
],
|
||||
"typeId" : "net.drinkingtea.nostalgia.gfx.TileSheet.SubSheet;5"
|
||||
},
|
||||
{
|
||||
"fieldName" : "pixels",
|
||||
"subscriptLevels" : 1,
|
||||
"subscriptStack" :
|
||||
[
|
||||
{
|
||||
"subscriptType" : 4
|
||||
}
|
||||
],
|
||||
"typeId" : "B.uint8;0"
|
||||
}
|
||||
],
|
||||
"primitiveType" : 5,
|
||||
"typeName" : "net.drinkingtea.nostalgia.gfx.TileSheet.SubSheet",
|
||||
"typeVersion" : 5
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
O1;net.drinkingtea.ox.TypeDescriptor;1;{
|
||||
"fieldList" :
|
||||
[
|
||||
{
|
||||
"fieldName" : "bpp",
|
||||
"typeId" : "B.int8;0"
|
||||
},
|
||||
{
|
||||
"fieldName" : "idIt",
|
||||
"typeId" : "B.int32;0"
|
||||
},
|
||||
{
|
||||
"fieldName" : "defaultPalette",
|
||||
"typeId" : "net.drinkingtea.ox.BasicString#8#;1"
|
||||
},
|
||||
{
|
||||
"fieldName" : "subsheet",
|
||||
"typeId" : "net.drinkingtea.nostalgia.gfx.TileSheet.SubSheet;5"
|
||||
}
|
||||
],
|
||||
"primitiveType" : 5,
|
||||
"typeName" : "net.drinkingtea.nostalgia.gfx.TileSheet",
|
||||
"typeVersion" : 5
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
# module dir list
|
||||
|
||||
add_subdirectory(gfx)
|
||||
add_subdirectory(scene)
|
||||
add_subdirectory(sound)
|
||||
|
||||
# module libraries
|
||||
|
||||
@ -13,8 +13,8 @@ add_library(
|
||||
target_link_libraries(
|
||||
NostalgiaKeelModules PUBLIC
|
||||
Keel
|
||||
NostalgiaCore-Keel
|
||||
NostalgiaScene-Keel
|
||||
NostalgiaGfx-Keel
|
||||
NostalgiaSound-Keel
|
||||
)
|
||||
install(
|
||||
FILES
|
||||
@ -32,8 +32,8 @@ if(NOSTALGIA_BUILD_STUDIO)
|
||||
target_link_libraries(
|
||||
NostalgiaStudioModules PUBLIC
|
||||
StudioAppLib
|
||||
NostalgiaCore-Studio-ImGui
|
||||
NostalgiaScene-Studio
|
||||
NostalgiaGfx-Studio-ImGui
|
||||
NostalgiaSound-Studio-ImGui
|
||||
)
|
||||
install(
|
||||
FILES
|
||||
|
@ -16,23 +16,6 @@
|
||||
|
||||
namespace nostalgia::gfx {
|
||||
|
||||
struct SubSheetTemplate {
|
||||
static constexpr auto TypeName = "net.drinkingtea.nostalgia.gfx.SubSheetTemplate";
|
||||
static constexpr auto TypeVersion = 1;
|
||||
ox::String name;
|
||||
int32_t width{};
|
||||
int32_t height{};
|
||||
ox::Vector<SubSheetTemplate> subsheets;
|
||||
};
|
||||
|
||||
OX_MODEL_BEGIN(SubSheetTemplate)
|
||||
OX_MODEL_FIELD(name)
|
||||
OX_MODEL_FIELD(width)
|
||||
OX_MODEL_FIELD(height)
|
||||
OX_MODEL_FIELD(subsheets)
|
||||
OX_MODEL_END()
|
||||
|
||||
|
||||
// Predecessor to TileSheet, kept for backward compatibility
|
||||
struct TileSheetV1 {
|
||||
static constexpr auto TypeName = "net.drinkingtea.nostalgia.core.NostalgiaGraphic";
|
||||
@ -52,7 +35,7 @@ constexpr bool valid(TileSheetV1 const&ts) noexcept {
|
||||
return (ts.bpp == 4 || ts.bpp == 8) && ts.pixels.size() == bytes;
|
||||
}
|
||||
|
||||
constexpr ox::Error repair(TileSheetV1 &ts, int bpp) noexcept {
|
||||
constexpr ox::Error repair(TileSheetV1 &ts, int const bpp) noexcept {
|
||||
auto const bytes = static_cast<size_t>(ts.columns * ts.rows * PixelsPerTile) / (bpp == 4 ? 2 : 1);
|
||||
ts.pixels.resize(bytes);
|
||||
return {};
|
||||
@ -101,7 +84,7 @@ constexpr bool valid(TileSheetV2 const&ts) noexcept {
|
||||
return (ts.bpp == 4 || ts.bpp == 8) && valid(ts.subsheet, ts.bpp);
|
||||
}
|
||||
|
||||
constexpr void repair(TileSheetV2::SubSheet &ss, int bpp) noexcept {
|
||||
constexpr void repair(TileSheetV2::SubSheet &ss, int const bpp) noexcept {
|
||||
auto const bytes = static_cast<size_t>(ss.columns * ss.rows * PixelsPerTile) / (bpp == 4 ? 2 : 1);
|
||||
ss.pixels.resize(bytes);
|
||||
for (auto &s : ss.subsheets) {
|
||||
@ -171,7 +154,7 @@ constexpr bool valid(TileSheetV3 const&ts) noexcept {
|
||||
return (ts.bpp == 4 || ts.bpp == 8) && valid(ts.subsheet, ts.bpp);
|
||||
}
|
||||
|
||||
constexpr void repair(TileSheetV3::SubSheet &ss, int bpp) noexcept {
|
||||
constexpr void repair(TileSheetV3::SubSheet &ss, int const bpp) noexcept {
|
||||
auto const bytes = static_cast<size_t>(ss.columns * ss.rows * PixelsPerTile) / (bpp == 4 ? 2 : 1);
|
||||
ss.pixels.resize(bytes);
|
||||
for (auto &s : ss.subsheets) {
|
||||
@ -265,7 +248,7 @@ constexpr bool valid(TileSheetV4 const&ts) noexcept {
|
||||
return (ts.bpp == 4 || ts.bpp == 8) && valid(ts.subsheet, ts.bpp);
|
||||
}
|
||||
|
||||
constexpr void repair(TileSheetV4::SubSheet &ss, int bpp) noexcept {
|
||||
constexpr void repair(TileSheetV4::SubSheet &ss, int const bpp) noexcept {
|
||||
if (ss.subsheets.empty()) {
|
||||
auto const bytes = static_cast<size_t>(ss.columns * ss.rows * PixelsPerTile) / (bpp == 4 ? 2 : 1);
|
||||
ss.pixels.resize(bytes);
|
||||
@ -367,7 +350,7 @@ constexpr bool valid(TileSheetV5 const&ts) noexcept {
|
||||
return (ts.bpp == 4 || ts.bpp == 8) && valid(ts.subsheet);
|
||||
}
|
||||
|
||||
constexpr void repair(TileSheetV5::SubSheet &ss, int const bpp) noexcept {
|
||||
constexpr void repair(TileSheetV5::SubSheet &ss) noexcept {
|
||||
if (ss.subsheets.empty()) {
|
||||
auto const bytes = static_cast<size_t>(ss.columns * ss.rows * PixelsPerTile);
|
||||
ss.pixels.resize(bytes);
|
||||
@ -377,7 +360,7 @@ constexpr void repair(TileSheetV5::SubSheet &ss, int const bpp) noexcept {
|
||||
ss.rows = -1;
|
||||
}
|
||||
for (auto &s : ss.subsheets) {
|
||||
repair(s, bpp);
|
||||
repair(s);
|
||||
}
|
||||
}
|
||||
|
||||
@ -385,7 +368,7 @@ constexpr ox::Error repair(TileSheetV5 &ts) noexcept {
|
||||
if (ts.bpp != 4 && ts.bpp != 8) {
|
||||
return ox::Error{1, "Unable to repair TileSheet"};
|
||||
}
|
||||
repair(ts.subsheet, ts.bpp);
|
||||
repair(ts.subsheet);
|
||||
return {};
|
||||
}
|
||||
|
||||
@ -443,23 +426,24 @@ ox::Error resizeSubsheet(TileSheet::SubSheet &ss, ox::Size const&sz) noexcept;
|
||||
[[nodiscard]]
|
||||
TileSheet::SubSheetIdx validateSubSheetIdx(TileSheet const&ts, TileSheet::SubSheetIdx idx) noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
TileSheet::SubSheet const&getSubSheet(
|
||||
ox::SpanView<uint32_t> const&idx,
|
||||
std::size_t idxIt,
|
||||
TileSheet::SubSheet const&pSubsheet) noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
TileSheet::SubSheet &getSubSheet(
|
||||
ox::SpanView<uint32_t> const&idx,
|
||||
std::size_t idxIt,
|
||||
TileSheet::SubSheet &pSubsheet) noexcept;
|
||||
|
||||
#if defined(__GNUC__) && __GNUC__ >= 13
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wdangling-reference"
|
||||
#endif
|
||||
[[nodiscard]]
|
||||
TileSheet::SubSheet const&getSubSheet(TileSheet const&ts, ox::SpanView<uint32_t> const &idx) noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
TileSheet::SubSheet &getSubSheet(TileSheet &ts, ox::SpanView<uint32_t> const &idx) noexcept;
|
||||
#if defined(__GNUC__) && __GNUC__ >= 13
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
ox::Error addSubSheet(TileSheet &ts, TileSheet::SubSheetIdx const &idx) noexcept;
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
add_library(
|
||||
NostalgiaCore
|
||||
NostalgiaGfx
|
||||
gfx.cpp
|
||||
tilesheet.cpp
|
||||
)
|
||||
@ -10,12 +10,12 @@ if(NOT BUILDCORE_TARGET STREQUAL "gba")
|
||||
endif()
|
||||
|
||||
target_include_directories(
|
||||
NostalgiaCore PUBLIC
|
||||
NostalgiaGfx PUBLIC
|
||||
../include
|
||||
)
|
||||
|
||||
target_link_libraries(
|
||||
NostalgiaCore PUBLIC
|
||||
NostalgiaGfx PUBLIC
|
||||
Turbine
|
||||
)
|
||||
|
||||
@ -26,7 +26,7 @@ endif()
|
||||
|
||||
install(
|
||||
TARGETS
|
||||
NostalgiaCore
|
||||
NostalgiaGfx
|
||||
DESTINATION
|
||||
LIBRARY DESTINATION lib
|
||||
ARCHIVE DESTINATION lib
|
||||
|
@ -1,15 +1,15 @@
|
||||
add_library(
|
||||
NostalgiaCore-GBA OBJECT
|
||||
NostalgiaGfx-GBA OBJECT
|
||||
context.cpp
|
||||
gfx.cpp
|
||||
panic.cpp
|
||||
)
|
||||
target_include_directories(
|
||||
NostalgiaCore-GBA PUBLIC
|
||||
NostalgiaGfx-GBA PUBLIC
|
||||
../../include
|
||||
)
|
||||
target_link_libraries(
|
||||
NostalgiaCore-GBA PUBLIC
|
||||
NostalgiaGfx-GBA PUBLIC
|
||||
TeaGBA
|
||||
Keel
|
||||
Turbine
|
||||
@ -17,5 +17,5 @@ target_link_libraries(
|
||||
|
||||
if(BUILDCORE_TARGET STREQUAL "gba")
|
||||
set_source_files_properties(gfx.cpp PROPERTIES COMPILE_FLAGS -marm)
|
||||
target_link_libraries(NostalgiaCore PUBLIC NostalgiaCore-GBA)
|
||||
target_link_libraries(NostalgiaGfx PUBLIC NostalgiaGfx-GBA)
|
||||
endif()
|
||||
|
@ -1,18 +1,18 @@
|
||||
add_library(
|
||||
NostalgiaCore-Keel
|
||||
NostalgiaGfx-Keel
|
||||
keelmodule.cpp
|
||||
typeconv.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(
|
||||
NostalgiaCore-Keel PUBLIC
|
||||
NostalgiaGfx-Keel PUBLIC
|
||||
Keel
|
||||
NostalgiaCore
|
||||
NostalgiaGfx
|
||||
)
|
||||
|
||||
install(
|
||||
TARGETS
|
||||
NostalgiaCore-Keel
|
||||
NostalgiaGfx-Keel
|
||||
DESTINATION
|
||||
LIBRARY DESTINATION lib
|
||||
ARCHIVE DESTINATION lib
|
||||
|
@ -169,7 +169,7 @@ void TileSheetV4ToTileSheetV5Converter::convertSubsheet(
|
||||
dst.pixels.emplace_back(static_cast<uint8_t>(p & 0xf));
|
||||
dst.pixels.emplace_back(static_cast<uint8_t>(p >> 4));
|
||||
}
|
||||
oxAssert(dst.pixels.size() == src.pixels.size() *2, "mismatch");
|
||||
oxAssert(dst.pixels.size() == src.pixels.size() * 2, "mismatch");
|
||||
} else {
|
||||
dst.pixels = std::move(src.pixels);
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
target_sources(
|
||||
NostalgiaCore PRIVATE
|
||||
NostalgiaGfx PRIVATE
|
||||
context.cpp
|
||||
gfx.cpp
|
||||
)
|
||||
target_link_libraries(
|
||||
NostalgiaCore PUBLIC
|
||||
NostalgiaGfx PUBLIC
|
||||
GlUtils
|
||||
)
|
||||
|
@ -449,7 +449,7 @@ static void setSprite(
|
||||
++i;
|
||||
};
|
||||
if (!s.flipX) {
|
||||
for (auto yIt = 0; yIt < static_cast<int>(dim.y); ++yIt) {
|
||||
for (auto yIt = 0u; yIt < dim.y; ++yIt) {
|
||||
for (auto xIt = 0u; xIt < dim.x; ++xIt) {
|
||||
set(static_cast<int>(xIt), static_cast<int>(yIt), s.enabled);
|
||||
}
|
||||
|
@ -1,25 +1,25 @@
|
||||
add_library(NostalgiaCore-Studio)
|
||||
add_library(NostalgiaGfx-Studio)
|
||||
|
||||
add_library(
|
||||
NostalgiaCore-Studio-ImGui
|
||||
NostalgiaGfx-Studio-ImGui
|
||||
studiomodule.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(
|
||||
NostalgiaCore-Studio PUBLIC
|
||||
NostalgiaCore
|
||||
NostalgiaGfx-Studio PUBLIC
|
||||
NostalgiaGfx
|
||||
Studio
|
||||
)
|
||||
|
||||
target_link_libraries(
|
||||
NostalgiaCore-Studio-ImGui PUBLIC
|
||||
NostalgiaCore-Studio
|
||||
NostalgiaGfx-Studio-ImGui PUBLIC
|
||||
NostalgiaGfx-Studio
|
||||
)
|
||||
|
||||
install(
|
||||
TARGETS
|
||||
NostalgiaCore-Studio-ImGui
|
||||
NostalgiaCore-Studio
|
||||
NostalgiaGfx-Studio-ImGui
|
||||
NostalgiaGfx-Studio
|
||||
LIBRARY DESTINATION
|
||||
${NOSTALGIA_DIST_MODULE}
|
||||
)
|
||||
|
@ -1,18 +1,6 @@
|
||||
target_sources(
|
||||
NostalgiaCore-Studio PRIVATE
|
||||
commands/addcolorcommand.cpp
|
||||
commands/addpagecommand.cpp
|
||||
commands/applycolorallpagescommand.cpp
|
||||
commands/duplicatepagecommand.cpp
|
||||
commands/movecolorcommand.cpp
|
||||
commands/removecolorcommand.cpp
|
||||
commands/removepagecommand.cpp
|
||||
commands/renamepagecommand.cpp
|
||||
commands/updatecolorcommand.cpp
|
||||
commands/updatecolorinfocommand.cpp
|
||||
)
|
||||
|
||||
target_sources(
|
||||
NostalgiaCore-Studio-ImGui PRIVATE
|
||||
NostalgiaGfx-Studio-ImGui PRIVATE
|
||||
paletteeditor-imgui.cpp
|
||||
)
|
||||
|
||||
add_subdirectory(commands)
|
@ -0,0 +1,15 @@
|
||||
|
||||
target_sources(
|
||||
NostalgiaGfx-Studio PRIVATE
|
||||
addcolorcommand.cpp
|
||||
addpagecommand.cpp
|
||||
applycolorallpagescommand.cpp
|
||||
duplicatepagecommand.cpp
|
||||
movecolorcommand.cpp
|
||||
movepagecommand.cpp
|
||||
removecolorcommand.cpp
|
||||
removepagecommand.cpp
|
||||
renamepagecommand.cpp
|
||||
updatecolorcommand.cpp
|
||||
updatecolorinfocommand.cpp
|
||||
)
|
@ -12,6 +12,7 @@ enum class PaletteEditorCommandId {
|
||||
AddPage,
|
||||
DuplicatePage,
|
||||
RemovePage,
|
||||
MovePage,
|
||||
AddColor,
|
||||
RemoveColor,
|
||||
UpdateColorInfo,
|
||||
|
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#include "commands.hpp"
|
||||
|
||||
#include "movepagecommand.hpp"
|
||||
|
||||
namespace nostalgia::gfx {
|
||||
|
||||
MovePageCommand::MovePageCommand(
|
||||
Palette &pal,
|
||||
size_t const srcIdx,
|
||||
size_t const dstIdx) noexcept:
|
||||
m_pal(pal),
|
||||
m_srcIdx(srcIdx),
|
||||
m_dstIdx(dstIdx) {}
|
||||
|
||||
int MovePageCommand::commandId() const noexcept {
|
||||
return static_cast<int>(PaletteEditorCommandId::MovePage);
|
||||
}
|
||||
|
||||
ox::Error MovePageCommand::redo() noexcept {
|
||||
movePage(m_srcIdx, m_dstIdx);
|
||||
return {};
|
||||
}
|
||||
|
||||
ox::Error MovePageCommand::undo() noexcept {
|
||||
movePage(m_dstIdx, m_srcIdx);
|
||||
return {};
|
||||
}
|
||||
|
||||
void MovePageCommand::movePage(
|
||||
size_t const srcIdx, size_t const dstIdx) noexcept {
|
||||
auto page = std::move(m_pal.pages[srcIdx]);
|
||||
std::ignore = m_pal.pages.erase(srcIdx);
|
||||
m_pal.pages.emplace(dstIdx, std::move(page));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <studio/studio.hpp>
|
||||
|
||||
#include <nostalgia/gfx/palette.hpp>
|
||||
|
||||
namespace nostalgia::gfx {
|
||||
|
||||
class MovePageCommand: public studio::UndoCommand {
|
||||
private:
|
||||
Palette &m_pal;
|
||||
std::size_t const m_srcIdx = 0;
|
||||
std::size_t const m_dstIdx = 0;
|
||||
|
||||
public:
|
||||
MovePageCommand(Palette &pal, size_t srcIdx, size_t dstIdx) noexcept;
|
||||
|
||||
~MovePageCommand() noexcept override = default;
|
||||
|
||||
[[nodiscard]]
|
||||
int commandId() const noexcept override;
|
||||
|
||||
ox::Error redo() noexcept override;
|
||||
|
||||
ox::Error undo() noexcept override;
|
||||
|
||||
private:
|
||||
void movePage(size_t srcIdx, size_t dstIdx) noexcept;
|
||||
};
|
||||
|
||||
}
|
@ -11,6 +11,7 @@
|
||||
#include "commands/applycolorallpagescommand.hpp"
|
||||
#include "commands/duplicatepagecommand.hpp"
|
||||
#include "commands/movecolorcommand.hpp"
|
||||
#include "commands/movepagecommand.hpp"
|
||||
#include "commands/removecolorcommand.hpp"
|
||||
#include "commands/removepagecommand.hpp"
|
||||
#include "commands/renamepagecommand.hpp"
|
||||
@ -19,6 +20,7 @@
|
||||
|
||||
#include "paletteeditor-imgui.hpp"
|
||||
|
||||
|
||||
namespace nostalgia::gfx {
|
||||
|
||||
namespace ig = studio::ig;
|
||||
@ -33,6 +35,16 @@ OX_MODEL_BEGIN(ColorDragDrop)
|
||||
OX_MODEL_FIELD(i)
|
||||
OX_MODEL_END()
|
||||
|
||||
struct PageDragDrop {
|
||||
static constexpr auto TypeName = "nostalgia.gfx.PageDragDrop";
|
||||
static constexpr auto TypeVersion = 1;
|
||||
uint32_t page{};
|
||||
};
|
||||
|
||||
OX_MODEL_BEGIN(PageDragDrop)
|
||||
OX_MODEL_FIELD(page)
|
||||
OX_MODEL_END()
|
||||
|
||||
void PaletteEditorImGui::PageRenameDialog::draw(turbine::Context &tctx) noexcept {
|
||||
if (!m_show) {
|
||||
return;
|
||||
@ -82,6 +94,27 @@ ox::Error PaletteEditorImGui::saveItem() noexcept {
|
||||
return m_sctx.project->writeObj(itemPath(), m_pal, ox::ClawFormat::Organic);
|
||||
}
|
||||
|
||||
void PaletteEditorImGui::navigateTo(ox::StringViewCR arg) noexcept {
|
||||
auto const args = ox::split<2>(arg, ';');
|
||||
if (args.size() < 2) {
|
||||
return;
|
||||
}
|
||||
auto const &color = args[0];
|
||||
auto const &page = args[1];
|
||||
{
|
||||
auto const [c, err] = atoi(color);
|
||||
if (!err && static_cast<size_t>(c) < colorCnt(m_pal)) {
|
||||
m_selectedColorRow = static_cast<size_t>(c);
|
||||
}
|
||||
}
|
||||
{
|
||||
auto const [pg, err] = atoi(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 {
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("%s", txt.c_str());
|
||||
@ -235,6 +268,16 @@ void PaletteEditorImGui::drawPagesEditor() noexcept {
|
||||
if (ImGui::Selectable("##PageRow", i == m_page, ImGuiSelectableFlags_SpanAllColumns)) {
|
||||
m_page = i;
|
||||
}
|
||||
std::ignore = ig::dragDropSource([this, i] {
|
||||
ImGui::Text("%s", m_pal.pages[i].name.c_str());
|
||||
return ig::setDragDropPayload(PageDragDrop{i});
|
||||
}, ImGuiDragDropFlags_SourceAllowNullID);
|
||||
if (ig::DragDropTarget const d; d) {
|
||||
auto const [src, err] = ig::getDragDropPayload<PageDragDrop>();
|
||||
if (!err) {
|
||||
std::ignore = pushCommand<MovePageCommand>(m_pal, src.page, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ImGui::EndTable();
|
||||
|
@ -45,6 +45,8 @@ class PaletteEditorImGui: public studio::Editor {
|
||||
protected:
|
||||
ox::Error saveItem() noexcept final;
|
||||
|
||||
void navigateTo(ox::StringViewCR arg) noexcept override;
|
||||
|
||||
private:
|
||||
static void drawColumnLeftAlign(ox::CStringView txt) noexcept;
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
target_sources(
|
||||
NostalgiaCore-Studio PRIVATE
|
||||
NostalgiaGfx-Studio PRIVATE
|
||||
tilesheeteditorview.cpp
|
||||
tilesheeteditormodel.cpp
|
||||
tilesheetpixelgrid.cpp
|
||||
@ -7,12 +7,12 @@ target_sources(
|
||||
)
|
||||
|
||||
target_sources(
|
||||
NostalgiaCore-Studio-ImGui PRIVATE
|
||||
NostalgiaGfx-Studio-ImGui PRIVATE
|
||||
tilesheeteditor-imgui.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(
|
||||
NostalgiaCore-Studio-ImGui PUBLIC
|
||||
NostalgiaGfx-Studio-ImGui PUBLIC
|
||||
lodepng
|
||||
)
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
target_sources(
|
||||
NostalgiaCore-Studio PRIVATE
|
||||
NostalgiaGfx-Studio PRIVATE
|
||||
addsubsheetcommand.cpp
|
||||
cutpastecommand.cpp
|
||||
deletetilescommand.cpp
|
||||
@ -9,5 +9,6 @@ target_sources(
|
||||
inserttilescommand.cpp
|
||||
palettechangecommand.cpp
|
||||
rmsubsheetcommand.cpp
|
||||
rotatecommand.cpp
|
||||
updatesubsheetcommand.cpp
|
||||
)
|
||||
|
@ -17,6 +17,7 @@ enum class CommandId {
|
||||
DeleteTile,
|
||||
FlipX,
|
||||
FlipY,
|
||||
Rotate,
|
||||
InsertTile,
|
||||
MoveSubSheet,
|
||||
UpdateSubSheet,
|
||||
|
@ -2,15 +2,68 @@
|
||||
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include "drawcommand.hpp"
|
||||
|
||||
namespace nostalgia::gfx {
|
||||
|
||||
constexpr void iterateLine(ox::Point const &a, ox::Point const &b, auto const &f) noexcept {
|
||||
auto const rise = b.y - a.y;
|
||||
auto const run = b.x - a.x;
|
||||
auto const slope = static_cast<double>(rise) / static_cast<double>(run);
|
||||
auto y = static_cast<double>(a.y);
|
||||
auto const w = abs(run);
|
||||
if (rise > 0) {
|
||||
if (run > 0) {
|
||||
auto constexpr xmod = 1;
|
||||
for (int32_t i = 0; i < w; ++i) {
|
||||
auto const climb = static_cast<int32_t>(ceil(y + slope - y));
|
||||
f(a.x + i * xmod, static_cast<int32_t>(y), climb * xmod);
|
||||
y += slope * xmod;
|
||||
}
|
||||
} else if (run < 0) {
|
||||
auto constexpr xmod = -1;
|
||||
for (int32_t i = 0; i < w; ++i) {
|
||||
auto const climb = static_cast<int32_t>(floor(y + slope - y));
|
||||
f(a.x + i * xmod, static_cast<int32_t>(y), climb * xmod);
|
||||
y += slope * xmod;
|
||||
}
|
||||
} else {
|
||||
f(a.x, a.y, rise);
|
||||
}
|
||||
} else if (rise < 0) {
|
||||
if (run > 0) {
|
||||
auto constexpr xmod = 1;
|
||||
for (int32_t i = 0; i < w; ++i) {
|
||||
auto const climb = static_cast<int32_t>(floor(y + slope - y));
|
||||
f(a.x + i * xmod, static_cast<int32_t>(y), climb * xmod);
|
||||
y += slope * xmod;
|
||||
}
|
||||
} else if (run < 0) {
|
||||
auto constexpr xmod = -1;
|
||||
for (int32_t i = 0; i < w; ++i) {
|
||||
auto const climb = static_cast<int32_t>(ceil(y + slope - y));
|
||||
f(a.x + i * xmod, static_cast<int32_t>(y), climb * xmod);
|
||||
y += slope * xmod;
|
||||
}
|
||||
} else {
|
||||
f(a.x, a.y, rise - 1);
|
||||
}
|
||||
} else {
|
||||
auto const xmod = run > 0 ? 1 : -1;
|
||||
for (int32_t i = 0; i < w; ++i) {
|
||||
f(a.x + i * xmod, static_cast<int32_t>(y), 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
DrawCommand::DrawCommand(
|
||||
TileSheet &img,
|
||||
TileSheet::SubSheetIdx subSheetIdx,
|
||||
std::size_t idx,
|
||||
int palIdx) noexcept:
|
||||
int const palIdx) noexcept:
|
||||
m_img(img),
|
||||
m_subSheetIdx(std::move(subSheetIdx)),
|
||||
m_palIdx(palIdx) {
|
||||
@ -21,8 +74,8 @@ DrawCommand::DrawCommand(
|
||||
DrawCommand::DrawCommand(
|
||||
TileSheet &img,
|
||||
TileSheet::SubSheetIdx subSheetIdx,
|
||||
ox::Vector<std::size_t> const&idxList,
|
||||
int palIdx) noexcept:
|
||||
ox::SpanView<std::size_t> const&idxList,
|
||||
int const palIdx) noexcept:
|
||||
m_img(img),
|
||||
m_subSheetIdx(std::move(subSheetIdx)),
|
||||
m_palIdx(palIdx) {
|
||||
@ -32,11 +85,12 @@ DrawCommand::DrawCommand(
|
||||
}
|
||||
}
|
||||
|
||||
bool DrawCommand::append(std::size_t idx) noexcept {
|
||||
bool DrawCommand::append(std::size_t const idx) noexcept {
|
||||
auto &subsheet = getSubSheet(m_img, m_subSheetIdx);
|
||||
if (m_changes.back().value->idx != idx && getPixel(subsheet, idx) != m_palIdx) {
|
||||
// duplicate entries are bad
|
||||
auto existing = ox::find_if(m_changes.cbegin(), m_changes.cend(), [idx](auto const&c) {
|
||||
auto existing = find_if(
|
||||
m_changes.cbegin(), m_changes.cend(), [idx](auto const&c) {
|
||||
return c.idx == idx;
|
||||
});
|
||||
if (existing == m_changes.cend()) {
|
||||
@ -48,7 +102,7 @@ bool DrawCommand::append(std::size_t idx) noexcept {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool DrawCommand::append(ox::Vector<std::size_t> const&idxList) noexcept {
|
||||
bool DrawCommand::append(ox::SpanView<std::size_t> const&idxList) noexcept {
|
||||
auto out = false;
|
||||
for (auto idx : idxList) {
|
||||
out = append(idx) || out;
|
||||
@ -56,6 +110,28 @@ bool DrawCommand::append(ox::Vector<std::size_t> const&idxList) noexcept {
|
||||
return out;
|
||||
}
|
||||
|
||||
void DrawCommand::lineUpdate(ox::Point a, ox::Point b) noexcept {
|
||||
std::ignore = undo();
|
||||
m_changes.clear();
|
||||
auto &ss = getSubSheet(m_img, m_subSheetIdx);
|
||||
if (a.x < b.x) { ++b.x; }
|
||||
if (a.y < b.y) { ++b.y; }
|
||||
if (a.x > b.x) { --b.x; }
|
||||
iterateLine(a, b, [this, &ss](int32_t const x, int32_t const y, int32_t const h) {
|
||||
int const mod = h < 0 ? -1 : 1;
|
||||
auto const range = h * mod;
|
||||
for (int32_t i{}; i < range; ++i) {
|
||||
auto const idx = ptToIdx(x, y + i * mod, ss.columns * TileWidth);
|
||||
if (idx < ss.pixels.size()) {
|
||||
if (m_palIdx != getPixel(ss, idx)) {
|
||||
m_changes.emplace_back(static_cast<uint32_t>(idx), getPixel(ss, idx));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
std::ignore = redo();
|
||||
}
|
||||
|
||||
ox::Error DrawCommand::redo() noexcept {
|
||||
auto &subsheet = getSubSheet(m_img, m_subSheetIdx);
|
||||
for (auto const&c : m_changes) {
|
||||
@ -80,4 +156,8 @@ TileSheet::SubSheetIdx const&DrawCommand::subsheetIdx() const noexcept {
|
||||
return m_subSheetIdx;
|
||||
}
|
||||
|
||||
void DrawCommand::finish() noexcept {
|
||||
setObsolete(m_changes.empty());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -33,12 +33,14 @@ class DrawCommand: public TileSheetCommand {
|
||||
DrawCommand(
|
||||
TileSheet &img,
|
||||
TileSheet::SubSheetIdx subSheetIdx,
|
||||
ox::Vector<std::size_t> const&idxList,
|
||||
ox::SpanView<std::size_t> const&idxList,
|
||||
int palIdx) noexcept;
|
||||
|
||||
bool append(std::size_t idx) noexcept;
|
||||
|
||||
bool append(ox::Vector<std::size_t> const&idxList) noexcept;
|
||||
bool append(ox::SpanView<std::size_t> const&idxList) noexcept;
|
||||
|
||||
void lineUpdate(ox::Point a, ox::Point b) noexcept;
|
||||
|
||||
ox::Error redo() noexcept final;
|
||||
|
||||
@ -50,6 +52,8 @@ class DrawCommand: public TileSheetCommand {
|
||||
[[nodiscard]]
|
||||
TileSheet::SubSheetIdx const&subsheetIdx() const noexcept override;
|
||||
|
||||
void finish() noexcept;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
namespace nostalgia::gfx {
|
||||
|
||||
gfx::RmSubSheetCommand::RmSubSheetCommand(TileSheet &img, TileSheet::SubSheetIdx idx) noexcept:
|
||||
RmSubSheetCommand::RmSubSheetCommand(TileSheet &img, TileSheet::SubSheetIdx idx) noexcept:
|
||||
m_img(img),
|
||||
m_idx(std::move(idx)),
|
||||
m_parentIdx(m_idx) {
|
||||
|
@ -0,0 +1,126 @@
|
||||
/*
|
||||
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#include "rotatecommand.hpp"
|
||||
|
||||
namespace nostalgia::gfx {
|
||||
|
||||
static void rotateLeft(
|
||||
TileSheet::SubSheet &ss,
|
||||
ox::Point const &pt,
|
||||
ox::Point const &pt1,
|
||||
ox::Point const &pt2,
|
||||
int const depth = 0) noexcept {
|
||||
if (depth >= 4) {
|
||||
return;
|
||||
}
|
||||
auto const dstPt = ox::Point{pt1.x + pt.y, pt2.y - pt.x};
|
||||
auto const srcIdx = ptToIdx(pt + pt1, ss.columns);
|
||||
auto const dstIdx = ptToIdx(dstPt, ss.columns);
|
||||
auto const src = ss.pixels[srcIdx];
|
||||
auto &dst = ss.pixels[dstIdx];
|
||||
rotateLeft(ss, dstPt - pt1, pt1, pt2, depth + 1);
|
||||
dst = src;
|
||||
}
|
||||
|
||||
static void rotateLeft(TileSheet::SubSheet &ss, ox::Point const &pt1, ox::Point const &pt2) noexcept {
|
||||
auto const w = pt2.x - pt1.x;
|
||||
auto const h = pt2.y - pt1.y;
|
||||
for (int x = 0; x <= w / 2; ++x) {
|
||||
for (int y = 0; y <= h / 2; ++y) {
|
||||
rotateLeft(ss, {x, y}, pt1, pt2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void rotateRight(
|
||||
TileSheet::SubSheet &ss,
|
||||
ox::Point const &pt,
|
||||
ox::Point const &pt1,
|
||||
ox::Point const &pt2,
|
||||
int const depth = 0) noexcept {
|
||||
if (depth >= 4) {
|
||||
return;
|
||||
}
|
||||
auto const dstPt = ox::Point{pt2.x - pt.y, pt1.y + pt.x};
|
||||
auto const srcIdx = ptToIdx(pt + pt1, ss.columns);
|
||||
auto const dstIdx = ptToIdx(dstPt, ss.columns);
|
||||
auto const src = ss.pixels[srcIdx];
|
||||
auto &dst = ss.pixels[dstIdx];
|
||||
rotateRight(ss, dstPt - pt1, pt1, pt2, depth + 1);
|
||||
dst = src;
|
||||
}
|
||||
|
||||
static void rotateRight(TileSheet::SubSheet &ss, ox::Point const &pt1, ox::Point const &pt2) noexcept {
|
||||
auto const w = pt2.x - pt1.x;
|
||||
auto const h = pt2.y - pt1.y;
|
||||
for (int x = 0; x <= w / 2; ++x) {
|
||||
for (int y = 0; y <= h / 2; ++y) {
|
||||
rotateRight(ss, {x, y}, pt1, pt2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
RotateCommand::RotateCommand(
|
||||
TileSheet &img,
|
||||
TileSheet::SubSheetIdx idx,
|
||||
Direction const dir) noexcept:
|
||||
m_img(img),
|
||||
m_idx(std::move(idx)),
|
||||
m_pt2{[this] {
|
||||
auto &ss = getSubSheet(m_img, m_idx);
|
||||
return ox::Point{ss.columns * TileWidth - 1, ss.rows * TileHeight - 1};
|
||||
}()},
|
||||
m_dir{dir} {
|
||||
}
|
||||
|
||||
RotateCommand::RotateCommand(
|
||||
TileSheet &img,
|
||||
TileSheet::SubSheetIdx idx,
|
||||
ox::Point const &pt1,
|
||||
ox::Point const &pt2,
|
||||
Direction const dir) noexcept:
|
||||
m_img(img),
|
||||
m_idx(std::move(idx)),
|
||||
m_pt1{pt1},
|
||||
m_pt2{pt2},
|
||||
m_dir{dir} {
|
||||
}
|
||||
|
||||
ox::Error RotateCommand::redo() noexcept {
|
||||
auto &ss = getSubSheet(m_img, m_idx);
|
||||
switch (m_dir) {
|
||||
case Direction::Left:
|
||||
rotateLeft(ss, m_pt1, m_pt2);
|
||||
break;
|
||||
case Direction::Right:
|
||||
rotateRight(ss, m_pt1, m_pt2);
|
||||
break;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
ox::Error RotateCommand::undo() noexcept {
|
||||
auto &ss = getSubSheet(m_img, m_idx);
|
||||
switch (m_dir) {
|
||||
case Direction::Left:
|
||||
rotateRight(ss, m_pt1, m_pt2);
|
||||
break;
|
||||
case Direction::Right:
|
||||
rotateLeft(ss, m_pt1, m_pt2);
|
||||
break;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
int RotateCommand::commandId() const noexcept {
|
||||
return static_cast<int>(CommandId::Rotate);
|
||||
}
|
||||
|
||||
TileSheet::SubSheetIdx const&RotateCommand::subsheetIdx() const noexcept {
|
||||
return m_idx;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "commands.hpp"
|
||||
|
||||
namespace nostalgia::gfx {
|
||||
|
||||
class RotateCommand: public TileSheetCommand {
|
||||
public:
|
||||
enum class Direction {
|
||||
Right,
|
||||
Left,
|
||||
};
|
||||
|
||||
private:
|
||||
TileSheet &m_img;
|
||||
TileSheet::SubSheetIdx m_idx;
|
||||
ox::Point const m_pt1;
|
||||
ox::Point const m_pt2;
|
||||
Direction const m_dir;
|
||||
|
||||
public:
|
||||
RotateCommand(TileSheet &img, TileSheet::SubSheetIdx idx, Direction dir) noexcept;
|
||||
|
||||
RotateCommand(
|
||||
TileSheet &img,
|
||||
TileSheet::SubSheetIdx idx,
|
||||
ox::Point const &pt1,
|
||||
ox::Point const &pt2,
|
||||
Direction dir) noexcept;
|
||||
|
||||
ox::Error redo() noexcept final;
|
||||
|
||||
ox::Error undo() noexcept final;
|
||||
|
||||
[[nodiscard]]
|
||||
int commandId() const noexcept final;
|
||||
|
||||
[[nodiscard]]
|
||||
TileSheet::SubSheetIdx const&subsheetIdx() const noexcept override;
|
||||
|
||||
};
|
||||
|
||||
}
|
@ -36,21 +36,12 @@ OX_MODEL_BEGIN(TileSheetEditorConfig)
|
||||
OX_MODEL_END()
|
||||
|
||||
static ox::Vector<uint32_t> normalizePixelSizes(
|
||||
ox::Vector<uint8_t> const&inPixels,
|
||||
int const bpp) noexcept {
|
||||
uint_t const bytesPerTile = bpp == 8 ? PixelsPerTile : PixelsPerTile / 2;
|
||||
ox::Vector<uint8_t> const&inPixels) noexcept {
|
||||
ox::Vector<uint32_t> outPixels;
|
||||
if (bytesPerTile == 64) { // 8 BPP
|
||||
outPixels.resize(inPixels.size());
|
||||
for (std::size_t i = 0; i < inPixels.size(); ++i) {
|
||||
outPixels[i] = inPixels[i];
|
||||
}
|
||||
} else { // 4 BPP
|
||||
outPixels.resize(inPixels.size() * 2);
|
||||
for (std::size_t i = 0; i < inPixels.size(); ++i) {
|
||||
outPixels[i * 2 + 0] = inPixels[i] & 0xF;
|
||||
outPixels[i * 2 + 1] = inPixels[i] >> 4;
|
||||
}
|
||||
outPixels.reserve(inPixels.size());
|
||||
outPixels.resize(inPixels.size());
|
||||
for (std::size_t i = 0; i < inPixels.size(); ++i) {
|
||||
outPixels[i] = inPixels[i];
|
||||
}
|
||||
return outPixels;
|
||||
}
|
||||
@ -152,6 +143,12 @@ void TileSheetEditorImGui::keyStateChanged(turbine::Key const key, bool const do
|
||||
setCutEnabled(false);
|
||||
setPasteEnabled(false);
|
||||
m_model.clearSelection();
|
||||
} else if (key == turbine::Key::Alpha_E) {
|
||||
m_tool = TileSheetTool::Line;
|
||||
setCopyEnabled(false);
|
||||
setCutEnabled(false);
|
||||
setPasteEnabled(false);
|
||||
m_model.clearSelection();
|
||||
} else if (key == turbine::Key::Alpha_S) {
|
||||
m_tool = TileSheetTool::Select;
|
||||
setCopyEnabled(true);
|
||||
@ -214,7 +211,7 @@ void TileSheetEditorImGui::draw(studio::StudioContext&) noexcept {
|
||||
ImGui::BeginChild("Controls", {s_palViewWidth - 8, paneSize.y}, true);
|
||||
{
|
||||
auto const controlsSize = ImGui::GetContentRegionAvail();
|
||||
ImGui::BeginChild("ToolBox", {s_palViewWidth - 24, 30}, true);
|
||||
ImGui::BeginChild("ToolBox", {0, 32}, true);
|
||||
{
|
||||
auto const btnSz = ImVec2{45, 14};
|
||||
if (ImGui::Selectable("Select", m_tool == TileSheetTool::Select, 0, btnSz)) {
|
||||
@ -230,17 +227,34 @@ void TileSheetEditorImGui::draw(studio::StudioContext&) noexcept {
|
||||
m_tool = TileSheetTool::Fill;
|
||||
m_model.clearSelection();
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Selectable("Line", m_tool == TileSheetTool::Line, 0, btnSz)) {
|
||||
m_tool = TileSheetTool::Line;
|
||||
m_model.clearSelection();
|
||||
}
|
||||
//ImGui::SameLine();
|
||||
//size_t i{};
|
||||
//ig::ComboBox("##Operations", ox::Array<ox::CStringView, 1>{"Operations"}, i);
|
||||
}
|
||||
ImGui::EndChild();
|
||||
ImGui::BeginChild("OperationsBox", {s_palViewWidth - 24, ig::BtnSz.y + 17}, true);
|
||||
ImGui::BeginChild("OperationsBox", {0, 35}, ImGuiWindowFlags_NoTitleBar);
|
||||
{
|
||||
auto constexpr btnSz = ImVec2{55, ig::BtnSz.y};
|
||||
if (ig::PushButton("Flip X", btnSz)) {
|
||||
oxLogError(m_model.flipX());
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if (ig::PushButton("Flip Y", btnSz)) {
|
||||
oxLogError(m_model.flipY());
|
||||
if (ImGui::BeginCombo("##Operations", "Operations", 0)) {
|
||||
if (ImGui::Selectable("Flip X", false)) {
|
||||
oxLogError(m_model.flipX());
|
||||
}
|
||||
if (ImGui::Selectable("Flip Y", false)) {
|
||||
oxLogError(m_model.flipY());
|
||||
}
|
||||
ImGui::BeginDisabled(!m_model.rotateEligible());
|
||||
if (ImGui::Selectable("Rotate Left", false)) {
|
||||
oxLogError(m_model.rotateLeft());
|
||||
}
|
||||
if (ImGui::Selectable("Rotate Right", false)) {
|
||||
oxLogError(m_model.rotateRight());
|
||||
}
|
||||
ImGui::EndDisabled();
|
||||
ImGui::EndCombo();
|
||||
}
|
||||
}
|
||||
ImGui::EndChild();
|
||||
@ -386,12 +400,11 @@ void TileSheetEditorImGui::showSubsheetEditor() noexcept {
|
||||
ox::Error TileSheetEditorImGui::exportSubhseetToPng(int const scale) const noexcept {
|
||||
OX_REQUIRE(path, studio::saveFile({{"PNG", "png"}}));
|
||||
// subsheet to png
|
||||
auto const&img = m_model.img();
|
||||
auto const&s = m_model.activeSubSheet();
|
||||
auto const&pal = m_model.pal();
|
||||
auto const width = s.columns * TileWidth;
|
||||
auto const height = s.rows * TileHeight;
|
||||
auto pixels = normalizePixelSizes(s.pixels, img.bpp);
|
||||
auto pixels = normalizePixelSizes(s.pixels);
|
||||
pixels = normalizePixelArrangement(pixels, s.columns, scale);
|
||||
auto const err = toPngFile(
|
||||
path,
|
||||
@ -447,6 +460,9 @@ void TileSheetEditorImGui::drawTileSheet(ox::Vec2 const&fbSize) noexcept {
|
||||
case TileSheetTool::Fill:
|
||||
m_view.clickFill(fbSize, clickPos(winPos, mousePos));
|
||||
break;
|
||||
case TileSheetTool::Line:
|
||||
m_view.clickLine(fbSize, clickPos(winPos, mousePos));
|
||||
break;
|
||||
case TileSheetTool::Select:
|
||||
m_view.clickSelect(fbSize, clickPos(winPos, mousePos));
|
||||
break;
|
||||
@ -539,9 +555,15 @@ void TileSheetEditorImGui::drawPaletteMenu() noexcept {
|
||||
label.c_str(), rowSelected, ImGuiSelectableFlags_SpanAllColumns)) {
|
||||
m_view.setPalIdx(i);
|
||||
}
|
||||
if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(0)) {
|
||||
studio::navigateTo(
|
||||
m_sctx,
|
||||
m_model.palPath(),
|
||||
ox::sfmt("{};{}", i, m_model.palettePage()));
|
||||
}
|
||||
// Column: color RGB
|
||||
ImGui::TableNextColumn();
|
||||
auto ic = ImGui::GetColorU32(ImVec4(redf(c), greenf(c), bluef(c), 1));
|
||||
auto const ic = ImGui::GetColorU32({redf(c), greenf(c), bluef(c), 1});
|
||||
ImGui::TableSetBgColor(ImGuiTableBgTarget_CellBg, ic);
|
||||
ImGui::TableNextColumn();
|
||||
auto const&name = i < pal.colorNames.size() ? pal.colorNames[i].c_str() : "";
|
||||
@ -620,7 +642,7 @@ void TileSheetEditorImGui::ExportMenu::draw(turbine::Context &tctx) noexcept {
|
||||
constexpr auto popupSz = ImVec2{popupWidth, popupHeight};
|
||||
if (ig::BeginPopup(tctx, popupName, m_show, popupSz)) {
|
||||
ImGui::InputInt("Scale", &m_scale);
|
||||
m_scale = ox::clamp(m_scale, 1, 50);
|
||||
m_scale = ox::clamp(m_scale, 1, 135);
|
||||
if (ig::PopupControlsOkCancel(popupWidth, m_show) == ig::PopupResponse::OK) {
|
||||
inputSubmitted.emit(m_scale);
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ class TileSheetEditorImGui: public studio::Editor {
|
||||
[[nodiscard]]
|
||||
constexpr bool isOpen() const noexcept { return m_show; }
|
||||
};
|
||||
static constexpr float s_palViewWidth = 300;
|
||||
static constexpr float s_palViewWidth = 335;
|
||||
studio::StudioContext &m_sctx;
|
||||
turbine::Context &m_tctx;
|
||||
ox::Vector<ox::String> m_paletteList;
|
||||
|
@ -18,13 +18,13 @@
|
||||
#include "commands/drawcommand.hpp"
|
||||
#include "commands/flipcommand.hpp"
|
||||
#include "commands/inserttilescommand.hpp"
|
||||
#include "commands/movesubsheetcommand.hpp"
|
||||
#include "commands/palettechangecommand.hpp"
|
||||
#include "commands/rmsubsheetcommand.hpp"
|
||||
#include "commands/rotatecommand.hpp"
|
||||
#include "commands/updatesubsheetcommand.hpp"
|
||||
#include "tilesheeteditormodel.hpp"
|
||||
|
||||
#include "commands/movesubsheetcommand.hpp"
|
||||
|
||||
namespace nostalgia::gfx {
|
||||
|
||||
// delete pixels of all non-leaf nodes
|
||||
@ -140,11 +140,15 @@ size_t TileSheetEditorModel::palettePage() const noexcept {
|
||||
return m_palettePage;
|
||||
}
|
||||
|
||||
void TileSheetEditorModel::drawCommand(ox::Point const&pt, std::size_t const palIdx) noexcept {
|
||||
void TileSheetEditorModel::drawCommand(ox::Point const &pt, std::size_t const palIdx) noexcept {
|
||||
if (m_lastDrawUpdatePt == pt) {
|
||||
return;
|
||||
}
|
||||
auto const &activeSubSheet = getSubSheet(m_img, m_activeSubsSheetIdx);
|
||||
if (pt.x >= activeSubSheet.columns * TileWidth || pt.y >= activeSubSheet.rows * TileHeight) {
|
||||
return;
|
||||
}
|
||||
m_lastDrawUpdatePt = pt;
|
||||
auto const idx = gfx::idx(activeSubSheet, pt);
|
||||
if (m_ongoingDrawCommand) {
|
||||
m_updated = m_updated || m_ongoingDrawCommand->append(idx);
|
||||
@ -154,8 +158,31 @@ void TileSheetEditorModel::drawCommand(ox::Point const&pt, std::size_t const pal
|
||||
}
|
||||
}
|
||||
|
||||
void TileSheetEditorModel::drawLineCommand(ox::Point const &pt, std::size_t const palIdx) noexcept {
|
||||
if (m_lastDrawUpdatePt == pt) {
|
||||
return;
|
||||
}
|
||||
auto const &activeSubSheet = getSubSheet(m_img, m_activeSubsSheetIdx);
|
||||
if (pt.x >= activeSubSheet.columns * TileWidth || pt.y >= activeSubSheet.rows * TileHeight) {
|
||||
return;
|
||||
}
|
||||
m_lastDrawUpdatePt = pt;
|
||||
auto const idx = gfx::idx(activeSubSheet, pt);
|
||||
if (m_ongoingDrawCommand) {
|
||||
m_ongoingDrawCommand->lineUpdate(m_lineStartPt, pt);
|
||||
m_updated = true;
|
||||
} else {
|
||||
std::ignore = pushCommand(ox::make<DrawCommand>(
|
||||
m_img, m_activeSubsSheetIdx, idx, static_cast<int>(palIdx)));
|
||||
m_lineStartPt = pt;
|
||||
}
|
||||
}
|
||||
|
||||
void TileSheetEditorModel::endDrawCommand() noexcept {
|
||||
m_ongoingDrawCommand = nullptr;
|
||||
if (m_ongoingDrawCommand) {
|
||||
m_ongoingDrawCommand->finish();
|
||||
m_ongoingDrawCommand = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void TileSheetEditorModel::addSubsheet(TileSheet::SubSheetIdx const&parentIdx) noexcept {
|
||||
@ -213,6 +240,28 @@ void TileSheetEditorModel::fill(ox::Point const&pt, int const palIdx) noexcept {
|
||||
}
|
||||
}
|
||||
|
||||
ox::Error TileSheetEditorModel::rotateLeft() noexcept {
|
||||
auto &ss = activeSubSheet();
|
||||
ox::Point pt1, pt2{ss.columns * TileWidth - 1, ss.rows * TileHeight - 1};
|
||||
if (m_selection) {
|
||||
pt1 = m_selection->a;
|
||||
pt2 = m_selection->b;
|
||||
}
|
||||
return pushCommand(ox::make<RotateCommand>(
|
||||
m_img, m_activeSubsSheetIdx, pt1, pt2, RotateCommand::Direction::Left));
|
||||
}
|
||||
|
||||
ox::Error TileSheetEditorModel::rotateRight() noexcept {
|
||||
auto &ss = activeSubSheet();
|
||||
ox::Point pt1, pt2{ss.columns * TileWidth - 1, ss.rows * TileHeight - 1};
|
||||
if (m_selection) {
|
||||
pt1 = m_selection->a;
|
||||
pt2 = m_selection->b;
|
||||
}
|
||||
return pushCommand(ox::make<RotateCommand>(
|
||||
m_img, m_activeSubsSheetIdx, pt1, pt2, RotateCommand::Direction::Right));
|
||||
}
|
||||
|
||||
void TileSheetEditorModel::setSelection(studio::Selection const&sel) noexcept {
|
||||
m_selection.emplace(sel);
|
||||
m_updated = true;
|
||||
@ -253,6 +302,7 @@ ox::Error TileSheetEditorModel::markUpdatedCmdId(studio::UndoCommand const*cmd)
|
||||
m_pal = keel::AssetRef<Palette>{};
|
||||
}
|
||||
m_palettePage = ox::min<size_t>(pal().pages.size(), 0);
|
||||
setPalPath();
|
||||
paletteChanged.emit();
|
||||
}
|
||||
auto const tsCmd = dynamic_cast<TileSheetCommand const*>(cmd);
|
||||
@ -304,6 +354,16 @@ ox::Error TileSheetEditorModel::flipY() noexcept {
|
||||
return pushCommand(ox::make<FlipYCommand>(m_img, m_activeSubsSheetIdx, a, b));
|
||||
}
|
||||
|
||||
bool TileSheetEditorModel::rotateEligible() const noexcept {
|
||||
if (m_selection) {
|
||||
auto const w = m_selection->b.x - m_selection->a.x;
|
||||
auto const h = m_selection->b.y - m_selection->a.y;
|
||||
return w == h;
|
||||
}
|
||||
auto const &ss = activeSubSheet();
|
||||
return ss.rows == ss.columns;
|
||||
}
|
||||
|
||||
ox::Error TileSheetEditorModel::moveSubSheet(TileSheet::SubSheetIdx src, TileSheet::SubSheetIdx dst) noexcept {
|
||||
return pushCommand(ox::make<MoveSubSheetCommand>(m_img, std::move(src), std::move(dst)));
|
||||
}
|
||||
|
@ -34,6 +34,8 @@ class TileSheetEditorModel: public ox::SignalHandler {
|
||||
class DrawCommand *m_ongoingDrawCommand = nullptr;
|
||||
studio::SelectionTracker m_selTracker;
|
||||
ox::Optional<studio::Selection> m_selection;
|
||||
ox::Point m_lineStartPt;
|
||||
ox::Point m_lastDrawUpdatePt;
|
||||
bool m_updated = false;
|
||||
|
||||
public:
|
||||
@ -71,6 +73,8 @@ class TileSheetEditorModel: public ox::SignalHandler {
|
||||
|
||||
void drawCommand(ox::Point const&pt, std::size_t palIdx) noexcept;
|
||||
|
||||
void drawLineCommand(ox::Point const&pt, std::size_t palIdx) noexcept;
|
||||
|
||||
void endDrawCommand() noexcept;
|
||||
|
||||
void addSubsheet(TileSheet::SubSheetIdx const&parentIdx) noexcept;
|
||||
@ -102,6 +106,10 @@ class TileSheetEditorModel: public ox::SignalHandler {
|
||||
|
||||
void fill(ox::Point const&pt, int palIdx) noexcept;
|
||||
|
||||
ox::Error rotateLeft() noexcept;
|
||||
|
||||
ox::Error rotateRight() noexcept;
|
||||
|
||||
void setSelection(studio::Selection const&sel) noexcept;
|
||||
|
||||
void select(ox::Point const&pt) noexcept;
|
||||
@ -130,6 +138,9 @@ class TileSheetEditorModel: public ox::SignalHandler {
|
||||
|
||||
ox::Error flipY() noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
bool rotateEligible() const noexcept;
|
||||
|
||||
ox::Error moveSubSheet(TileSheet::SubSheetIdx src, TileSheet::SubSheetIdx dst) noexcept;
|
||||
|
||||
private:
|
||||
|
@ -11,7 +11,8 @@
|
||||
|
||||
namespace nostalgia::gfx {
|
||||
|
||||
TileSheetEditorView::TileSheetEditorView(studio::StudioContext &sctx, ox::StringView path, studio::UndoStack &undoStack):
|
||||
TileSheetEditorView::TileSheetEditorView(
|
||||
studio::StudioContext &sctx, ox::StringViewCR path, studio::UndoStack &undoStack):
|
||||
m_model(sctx, path, undoStack),
|
||||
m_pixelsDrawer(m_model) {
|
||||
glBindVertexArray(0);
|
||||
@ -76,6 +77,11 @@ void TileSheetEditorView::clickDraw(ox::Vec2 const&paneSize, ox::Vec2 const&clic
|
||||
m_model.drawCommand(pt, m_palIdx);
|
||||
}
|
||||
|
||||
void TileSheetEditorView::clickLine(ox::Vec2 const&paneSize, ox::Vec2 const&clickPos) noexcept {
|
||||
auto const pt = clickPoint(paneSize, clickPos);
|
||||
m_model.drawLineCommand(pt, m_palIdx);
|
||||
}
|
||||
|
||||
void TileSheetEditorView::clickSelect(ox::Vec2 const&paneSize, ox::Vec2 const&clickPos) noexcept {
|
||||
auto const pt = clickPoint(paneSize, clickPos);
|
||||
m_model.select(pt);
|
||||
@ -90,6 +96,7 @@ void TileSheetEditorView::releaseMouseButton(TileSheetTool tool) noexcept {
|
||||
switch (tool) {
|
||||
case TileSheetTool::Draw:
|
||||
case TileSheetTool::Fill:
|
||||
case TileSheetTool::Line:
|
||||
m_model.endDrawCommand();
|
||||
break;
|
||||
case TileSheetTool::Select:
|
||||
|
@ -23,6 +23,7 @@ enum class TileSheetTool {
|
||||
Select,
|
||||
Draw,
|
||||
Fill,
|
||||
Line,
|
||||
};
|
||||
|
||||
[[nodiscard]]
|
||||
@ -34,6 +35,8 @@ constexpr auto toString(TileSheetTool t) noexcept {
|
||||
return "Draw";
|
||||
case TileSheetTool::Fill:
|
||||
return "Fill";
|
||||
case TileSheetTool::Line:
|
||||
return "Line";
|
||||
case TileSheetTool::None:
|
||||
return "None";
|
||||
}
|
||||
@ -53,7 +56,7 @@ class TileSheetEditorView: public ox::SignalHandler {
|
||||
std::size_t m_palIdx = 0;
|
||||
|
||||
public:
|
||||
TileSheetEditorView(studio::StudioContext &sctx, ox::StringView path, studio::UndoStack &undoStack);
|
||||
TileSheetEditorView(studio::StudioContext &sctx, ox::StringViewCR path, studio::UndoStack &undoStack);
|
||||
|
||||
~TileSheetEditorView() override = default;
|
||||
|
||||
@ -65,6 +68,8 @@ class TileSheetEditorView: public ox::SignalHandler {
|
||||
|
||||
void clickDraw(ox::Vec2 const&paneSize, ox::Vec2 const&clickPos) noexcept;
|
||||
|
||||
void clickLine(ox::Vec2 const&paneSize, ox::Vec2 const&clickPos) noexcept;
|
||||
|
||||
void clickSelect(ox::Vec2 const&paneSize, ox::Vec2 const&clickPos) noexcept;
|
||||
|
||||
void clickFill(ox::Vec2 const&paneSize, ox::Vec2 const&clickPos) noexcept;
|
||||
|
@ -22,7 +22,12 @@ ox::Error TileSheetGrid::buildShader() noexcept {
|
||||
}
|
||||
|
||||
void TileSheetGrid::draw(bool update, ox::Vec2 const&scroll) noexcept {
|
||||
glLineWidth(3 * m_pixelSizeMod * 0.5f);
|
||||
// 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);
|
||||
} else {
|
||||
glLineWidth(3 * m_pixelSizeMod * 0.5f);
|
||||
}
|
||||
glUseProgram(m_shader);
|
||||
glBindVertexArray(m_bufferSet.vao);
|
||||
if (update) {
|
||||
|
@ -187,7 +187,11 @@ TileSheet::SubSheetIdx validateSubSheetIdx(TileSheet const&ts, TileSheet::SubShe
|
||||
return validateSubSheetIdx(std::move(idx), 0, ts.subsheet);
|
||||
}
|
||||
|
||||
TileSheet::SubSheet const&getSubSheet(
|
||||
#if defined(__GNUC__) && __GNUC__ >= 13
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wdangling-reference"
|
||||
#endif
|
||||
static TileSheet::SubSheet const&getSubSheet(
|
||||
ox::SpanView<uint32_t> const &idx,
|
||||
std::size_t const idxIt,
|
||||
TileSheet::SubSheet const &pSubsheet) noexcept {
|
||||
@ -200,6 +204,9 @@ TileSheet::SubSheet const&getSubSheet(
|
||||
}
|
||||
return getSubSheet(idx, idxIt + 1, pSubsheet.subsheets[currentIdx]);
|
||||
}
|
||||
#if defined(__GNUC__) && __GNUC__ >= 13
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
TileSheet::SubSheet &getSubSheet(
|
||||
ox::SpanView<uint32_t> const &idx,
|
||||
@ -211,13 +218,20 @@ TileSheet::SubSheet &getSubSheet(
|
||||
return getSubSheet(idx, idxIt + 1, pSubsheet.subsheets[idx[idxIt]]);
|
||||
}
|
||||
|
||||
#if defined(__GNUC__) && __GNUC__ >= 13
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wdangling-reference"
|
||||
#endif
|
||||
TileSheet::SubSheet const&getSubSheet(TileSheet const &ts, ox::SpanView<uint32_t> const &idx) noexcept {
|
||||
return gfx::getSubSheet(idx, 0, ts.subsheet);
|
||||
}
|
||||
|
||||
TileSheet::SubSheet &getSubSheet(TileSheet &ts, ox::SpanView<uint32_t> const&idx) noexcept {
|
||||
TileSheet::SubSheet &getSubSheet(TileSheet &ts, ox::SpanView<uint32_t> const &idx) noexcept {
|
||||
return gfx::getSubSheet(idx, 0, ts.subsheet);
|
||||
}
|
||||
#if defined(__GNUC__) && __GNUC__ >= 13
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
ox::Error addSubSheet(TileSheet &ts, TileSheet::SubSheetIdx const&idx) noexcept {
|
||||
auto &parent = getSubSheet(ts, idx);
|
||||
|
@ -1,11 +1,11 @@
|
||||
add_executable(
|
||||
NostalgiaCoreTest
|
||||
NostalgiaGfxTest
|
||||
tests.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(
|
||||
NostalgiaCoreTest
|
||||
NostalgiaCore
|
||||
NostalgiaGfxTest
|
||||
NostalgiaGfx
|
||||
)
|
||||
|
||||
add_test("[NostalgiaCore] readWriteTileSheet" ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/NostalgiaCoreTest readWriteTileSheet)
|
||||
add_test("[NostalgiaGfx] readWriteTileSheet" ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/NostalgiaGfxTest readWriteTileSheet)
|
||||
|
@ -3,7 +3,7 @@
|
||||
*/
|
||||
|
||||
#include <nostalgia/gfx/keelmodule.hpp>
|
||||
#include <nostalgia/scene/keelmodule.hpp>
|
||||
#include <nostalgia/sound/keelmodule.hpp>
|
||||
|
||||
namespace nostalgia {
|
||||
|
||||
@ -14,7 +14,7 @@ void registerKeelModules() noexcept {
|
||||
}
|
||||
modulesRegistered = true;
|
||||
keel::registerModule(gfx::keelModule());
|
||||
keel::registerModule(scene::keelModule());
|
||||
keel::registerModule(sound::keelModule());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,27 +0,0 @@
|
||||
/*
|
||||
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <nostalgia/gfx/context.hpp>
|
||||
|
||||
#include "scenestatic.hpp"
|
||||
|
||||
namespace nostalgia::scene {
|
||||
|
||||
class Scene {
|
||||
private:
|
||||
SceneStatic const&m_sceneStatic;
|
||||
|
||||
public:
|
||||
explicit Scene(SceneStatic const&sceneStatic) noexcept;
|
||||
|
||||
ox::Error setupDisplay(gfx::Context &ctx) const noexcept;
|
||||
|
||||
private:
|
||||
void setupLayer(gfx::Context&, ox::Vector<uint16_t> const&layer, unsigned layerNo) const noexcept;
|
||||
|
||||
};
|
||||
|
||||
}
|
@ -1,228 +0,0 @@
|
||||
/*
|
||||
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ox/fs/fs.hpp>
|
||||
#include <ox/std/error.hpp>
|
||||
#include <ox/std/size.hpp>
|
||||
#include <ox/std/types.hpp>
|
||||
#include <ox/std/vector.hpp>
|
||||
|
||||
#include <nostalgia/gfx/tilesheet.hpp>
|
||||
|
||||
namespace nostalgia::scene {
|
||||
|
||||
struct SpriteDoc {
|
||||
|
||||
constexpr static auto TypeName = "net.drinkingtea.nostalgia.scene.SpriteDoc";
|
||||
constexpr static auto TypeVersion = 1;
|
||||
constexpr static auto Preloadable = true;
|
||||
|
||||
ox::String tilesheetPath;
|
||||
ox::Vector<gfx::SubSheetId> subsheetId;
|
||||
|
||||
};
|
||||
|
||||
struct TileDoc {
|
||||
|
||||
constexpr static auto TypeName = "net.drinkingtea.nostalgia.scene.TileDoc";
|
||||
constexpr static auto TypeVersion = 1;
|
||||
constexpr static auto Preloadable = true;
|
||||
|
||||
gfx::SubSheetId subsheetId = -1;
|
||||
ox::String subsheetPath;
|
||||
uint8_t type = 0;
|
||||
ox::Array<uint8_t, 4> layerAttachments;
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr ox::Result<gfx::SubSheetId> getSubsheetId(gfx::TileSheet const&ts) const noexcept {
|
||||
// prefer the already present ID
|
||||
if (subsheetId > -1) {
|
||||
return subsheetId;
|
||||
}
|
||||
return getIdFor(ts, subsheetPath);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr ox::Result<ox::StringView> getSubsheetPath(
|
||||
gfx::TileSheet const&ts) const noexcept {
|
||||
// prefer the already present path
|
||||
if (!subsheetPath.len()) {
|
||||
return gfx::getNameFor(ts, subsheetId);
|
||||
}
|
||||
return ox::StringView(subsheetPath);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
OX_MODEL_BEGIN(TileDoc)
|
||||
OX_MODEL_FIELD_RENAME(subsheetId, subsheet_id)
|
||||
OX_MODEL_FIELD_RENAME(subsheetPath, subsheet_path)
|
||||
OX_MODEL_FIELD(type)
|
||||
OX_MODEL_FIELD_RENAME(layerAttachments, layer_attachments)
|
||||
OX_MODEL_END()
|
||||
|
||||
struct SceneDoc {
|
||||
|
||||
using TileMapRow = ox::Vector<TileDoc>;
|
||||
using TileMapLayer = ox::Vector<TileMapRow>;
|
||||
using TileMap = ox::Vector<TileMapLayer>;
|
||||
|
||||
constexpr static auto TypeName = "net.drinkingtea.nostalgia.scene.SceneDoc";
|
||||
constexpr static auto TypeVersion = 1;
|
||||
constexpr static auto Preloadable = true;
|
||||
|
||||
ox::String tilesheet; // path
|
||||
ox::Vector<ox::String> palettes; // paths
|
||||
TileMap tiles;
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr ox::Size size(std::size_t layerIdx) const noexcept {
|
||||
const auto &layer = this->tiles[layerIdx];
|
||||
const auto rowCnt = static_cast<int>(layer.size());
|
||||
if (!rowCnt) {
|
||||
return {};
|
||||
}
|
||||
auto colCnt = layer[0].size();
|
||||
// find shortest row (they should all be the same, but you know this data
|
||||
// could come from a file)
|
||||
for (auto const&row : layer) {
|
||||
colCnt = ox::min(colCnt, row.size());
|
||||
}
|
||||
return {static_cast<int>(colCnt), rowCnt};
|
||||
}
|
||||
};
|
||||
|
||||
OX_MODEL_BEGIN(SceneDoc)
|
||||
OX_MODEL_FIELD(tilesheet)
|
||||
OX_MODEL_FIELD(palettes)
|
||||
OX_MODEL_FIELD(tiles)
|
||||
OX_MODEL_END()
|
||||
|
||||
|
||||
constexpr void setTopEdge(uint8_t &layerAttachments, unsigned val) noexcept {
|
||||
const auto val8 = static_cast<uint8_t>(val);
|
||||
layerAttachments = (layerAttachments & 0b11111100) | val8;
|
||||
}
|
||||
constexpr void setBottomEdge(uint8_t &layerAttachments, unsigned val) noexcept {
|
||||
const auto val8 = static_cast<uint8_t>(val);
|
||||
layerAttachments = (layerAttachments & 0b11110011) | static_cast<uint8_t>(val8 << 2);
|
||||
}
|
||||
constexpr void setLeftEdge(uint8_t &layerAttachments, unsigned val) noexcept {
|
||||
const auto val8 = static_cast<uint8_t>(val);
|
||||
layerAttachments = (layerAttachments & 0b11001111) | static_cast<uint8_t>(val8 << 4);
|
||||
}
|
||||
constexpr void setRightEdge(uint8_t &layerAttachments, unsigned val) noexcept {
|
||||
const auto val8 = static_cast<uint8_t>(val);
|
||||
layerAttachments = (layerAttachments & 0b00111111) | static_cast<uint8_t>(val8 << 6);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr unsigned topEdge(uint8_t layerAttachments) noexcept {
|
||||
return layerAttachments & 0b11;
|
||||
}
|
||||
[[nodiscard]]
|
||||
constexpr unsigned bottomEdge(uint8_t layerAttachments) noexcept {
|
||||
return (layerAttachments >> 2) & 0b11;
|
||||
}
|
||||
[[nodiscard]]
|
||||
constexpr unsigned leftEdge(uint8_t layerAttachments) noexcept {
|
||||
return (layerAttachments >> 4) & 0b11;
|
||||
}
|
||||
[[nodiscard]]
|
||||
constexpr unsigned rightEdge(uint8_t layerAttachments) noexcept {
|
||||
return (layerAttachments >> 6) & 0b11;
|
||||
}
|
||||
|
||||
|
||||
struct SceneStatic {
|
||||
|
||||
constexpr static auto TypeName = "net.drinkingtea.nostalgia.scene.SceneStatic";
|
||||
constexpr static auto TypeVersion = 1;
|
||||
constexpr static auto Preloadable = true;
|
||||
|
||||
struct Tile {
|
||||
uint16_t &tileMapIdx;
|
||||
uint8_t &tileType;
|
||||
uint8_t &layerAttachments;
|
||||
constexpr Tile(uint16_t &pTileMapIdx, uint8_t &pTileType, uint8_t &pLayerAttachments) noexcept:
|
||||
tileMapIdx(pTileMapIdx),
|
||||
tileType(pTileType),
|
||||
layerAttachments(pLayerAttachments) {
|
||||
}
|
||||
};
|
||||
struct Layer {
|
||||
uint16_t &columns;
|
||||
uint16_t &rows;
|
||||
ox::Vector<uint16_t> &tileMapIdx;
|
||||
ox::Vector<uint8_t> &tileType;
|
||||
ox::Vector<uint8_t> &layerAttachments;
|
||||
constexpr Layer(
|
||||
uint16_t &pColumns,
|
||||
uint16_t &pRows,
|
||||
ox::Vector<uint16_t> &pTileMapIdx,
|
||||
ox::Vector<uint8_t> &pTileType,
|
||||
ox::Vector<uint8_t> &pLayerAttachments) noexcept:
|
||||
columns(pColumns),
|
||||
rows(pRows),
|
||||
tileMapIdx(pTileMapIdx),
|
||||
tileType(pTileType),
|
||||
layerAttachments(pLayerAttachments) {
|
||||
}
|
||||
[[nodiscard]]
|
||||
constexpr Tile tile(std::size_t i) noexcept {
|
||||
return {tileMapIdx[i], tileType[i], layerAttachments[i]};
|
||||
}
|
||||
constexpr auto setDimensions(ox::Size dim) noexcept {
|
||||
columns = static_cast<uint16_t>(dim.width);
|
||||
rows = static_cast<uint16_t>(dim.height);
|
||||
const auto tileCnt = static_cast<unsigned>(columns * rows);
|
||||
tileMapIdx.resize(tileCnt);
|
||||
tileType.resize(tileCnt);
|
||||
layerAttachments.resize(tileCnt);
|
||||
}
|
||||
};
|
||||
|
||||
ox::FileAddress tilesheet;
|
||||
ox::Vector<ox::FileAddress> palettes;
|
||||
// tile layer data
|
||||
ox::Vector<uint16_t> columns;
|
||||
ox::Vector<uint16_t> rows;
|
||||
ox::Vector<ox::Vector<uint16_t>> tileMapIdx;
|
||||
ox::Vector<ox::Vector<uint8_t>> tileType;
|
||||
ox::Vector<ox::Vector<uint8_t>> layerAttachments;
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr Layer layer(std::size_t i) noexcept {
|
||||
return {
|
||||
columns[i],
|
||||
rows[i],
|
||||
tileMapIdx[i],
|
||||
tileType[i],
|
||||
layerAttachments[i],
|
||||
};
|
||||
}
|
||||
|
||||
constexpr auto setLayerCnt(std::size_t layerCnt) noexcept {
|
||||
this->layerAttachments.resize(layerCnt);
|
||||
this->columns.resize(layerCnt);
|
||||
this->rows.resize(layerCnt);
|
||||
this->tileMapIdx.resize(layerCnt);
|
||||
this->tileType.resize(layerCnt);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
OX_MODEL_BEGIN(SceneStatic)
|
||||
OX_MODEL_FIELD(tilesheet)
|
||||
OX_MODEL_FIELD(palettes)
|
||||
OX_MODEL_FIELD(columns)
|
||||
OX_MODEL_FIELD(rows)
|
||||
OX_MODEL_FIELD(tileMapIdx)
|
||||
OX_MODEL_FIELD(tileType)
|
||||
OX_MODEL_FIELD(layerAttachments)
|
||||
OX_MODEL_END()
|
||||
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
add_library(
|
||||
NostalgiaScene-Keel
|
||||
keelmodule.cpp
|
||||
typeconv.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(
|
||||
NostalgiaScene-Keel PUBLIC
|
||||
Keel
|
||||
NostalgiaScene
|
||||
)
|
||||
install(
|
||||
TARGETS
|
||||
NostalgiaScene-Keel
|
||||
LIBRARY DESTINATION
|
||||
${NOSTALGIA_DIST_MODULE}
|
||||
)
|
@ -1,51 +0,0 @@
|
||||
/*
|
||||
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#include <keel/module.hpp>
|
||||
|
||||
#include <nostalgia/scene/scenestatic.hpp>
|
||||
|
||||
#include "typeconv.hpp"
|
||||
|
||||
namespace nostalgia::scene {
|
||||
|
||||
static class: public keel::Module {
|
||||
private:
|
||||
SceneDocToSceneStaticConverter m_sceneDocToSceneStaticConverter;
|
||||
|
||||
public:
|
||||
[[nodiscard]]
|
||||
ox::String id() const noexcept override {
|
||||
return ox::String("net.drinkingtea.nostalgia.scene");
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
ox::Vector<keel::TypeDescGenerator> types() const noexcept override {
|
||||
return {
|
||||
keel::generateTypeDesc<SceneDoc>,
|
||||
keel::generateTypeDesc<SceneStatic>,
|
||||
};
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
ox::Vector<const keel::BaseConverter*> converters() const noexcept override {
|
||||
return {
|
||||
&m_sceneDocToSceneStaticConverter,
|
||||
};
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
ox::Vector<keel::PackTransform> packTransforms() const noexcept override {
|
||||
return {
|
||||
keel::transformRule<SceneDoc, SceneStatic>,
|
||||
};
|
||||
}
|
||||
|
||||
} mod;
|
||||
|
||||
const keel::Module *keelModule() noexcept {
|
||||
return &mod;
|
||||
}
|
||||
|
||||
}
|
@ -1,68 +0,0 @@
|
||||
/*
|
||||
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#include <nostalgia/gfx/gfx.hpp>
|
||||
#include <keel/media.hpp>
|
||||
|
||||
#include "typeconv.hpp"
|
||||
|
||||
namespace nostalgia::scene {
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr unsigned adjustLayerAttachment(unsigned layer, unsigned attachment) noexcept {
|
||||
if (attachment == 0) {
|
||||
return layer;
|
||||
} else {
|
||||
return attachment - 1;
|
||||
}
|
||||
}
|
||||
|
||||
constexpr void setLayerAttachments(unsigned layer, TileDoc const&srcTile, SceneStatic::Tile &dstTile) noexcept {
|
||||
setTopEdge(
|
||||
dstTile.layerAttachments,
|
||||
adjustLayerAttachment(layer, srcTile.layerAttachments[0]));
|
||||
setBottomEdge(
|
||||
dstTile.layerAttachments,
|
||||
adjustLayerAttachment(layer, srcTile.layerAttachments[1]));
|
||||
setLeftEdge(
|
||||
dstTile.layerAttachments,
|
||||
adjustLayerAttachment(layer, srcTile.layerAttachments[2]));
|
||||
setRightEdge(
|
||||
dstTile.layerAttachments,
|
||||
adjustLayerAttachment(layer, srcTile.layerAttachments[3]));
|
||||
}
|
||||
|
||||
ox::Error SceneDocToSceneStaticConverter::convert(
|
||||
keel::Context &ctx,
|
||||
SceneDoc &src,
|
||||
SceneStatic &dst) const noexcept {
|
||||
OX_REQUIRE(ts, keel::readObj<gfx::TileSheet>(ctx, src.tilesheet));
|
||||
const auto layerCnt = src.tiles.size();
|
||||
dst.setLayerCnt(layerCnt);
|
||||
dst.tilesheet = ox::FileAddress(src.tilesheet);
|
||||
dst.palettes.reserve(src.palettes.size());
|
||||
for (const auto &pal : src.palettes) {
|
||||
dst.palettes.emplace_back(pal);
|
||||
}
|
||||
for (auto layerIdx = 0u; const auto &layer : src.tiles) {
|
||||
const auto layerDim = src.size(layerIdx);
|
||||
auto dstLayer = dst.layer(layerIdx);
|
||||
dstLayer.setDimensions(layerDim);
|
||||
for (auto tileIdx = 0u; const auto &row : layer) {
|
||||
for (const auto &srcTile : row) {
|
||||
auto dstTile = dstLayer.tile(tileIdx);
|
||||
dstTile.tileType = srcTile.type;
|
||||
OX_REQUIRE(path, srcTile.getSubsheetPath(*ts));
|
||||
OX_REQUIRE(mapIdx, getTileOffset(*ts, path));
|
||||
dstTile.tileMapIdx = static_cast<uint16_t>(mapIdx);
|
||||
setLayerAttachments(layerIdx, srcTile, dstTile);
|
||||
++tileIdx;
|
||||
}
|
||||
}
|
||||
++layerIdx;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
/*
|
||||
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <keel/typeconv.hpp>
|
||||
|
||||
#include <nostalgia/scene/scenestatic.hpp>
|
||||
|
||||
namespace nostalgia::scene {
|
||||
|
||||
class SceneDocToSceneStaticConverter: public keel::Converter<SceneDoc, SceneStatic> {
|
||||
ox::Error convert(keel::Context&, SceneDoc &src, SceneStatic &dst) const noexcept final;
|
||||
};
|
||||
|
||||
}
|
@ -1,54 +0,0 @@
|
||||
/*
|
||||
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#include <nostalgia/gfx/gfx.hpp>
|
||||
|
||||
#include <nostalgia/scene/scene.hpp>
|
||||
|
||||
namespace nostalgia::scene {
|
||||
|
||||
Scene::Scene(SceneStatic const&sceneStatic) noexcept:
|
||||
m_sceneStatic(sceneStatic) {
|
||||
}
|
||||
|
||||
ox::Error Scene::setupDisplay(gfx::Context &ctx) const noexcept {
|
||||
if (m_sceneStatic.palettes.empty()) {
|
||||
return ox::Error(1, "Scene has no palettes");
|
||||
}
|
||||
auto const&palette = m_sceneStatic.palettes[0];
|
||||
OX_RETURN_ERROR(gfx::loadBgTileSheet(ctx, 0, m_sceneStatic.tilesheet));
|
||||
OX_RETURN_ERROR(gfx::loadBgPalette(ctx, 0, palette));
|
||||
// disable all backgrounds
|
||||
gfx::setBgStatus(ctx, 0);
|
||||
for (auto layerNo = 0u; auto const&layer : m_sceneStatic.tileMapIdx) {
|
||||
setupLayer(ctx, layer, layerNo);
|
||||
++layerNo;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
void Scene::setupLayer(
|
||||
gfx::Context &ctx,
|
||||
ox::Vector<uint16_t> const&layer,
|
||||
unsigned layerNo) const noexcept {
|
||||
gfx::setBgStatus(ctx, layerNo, true);
|
||||
gfx::setBgCbb(ctx, layerNo, 0);
|
||||
auto x = 0;
|
||||
auto y = 0;
|
||||
const auto width = m_sceneStatic.rows[layerNo];
|
||||
for (auto const&tile : layer) {
|
||||
const auto tile8 = static_cast<uint8_t>(tile);
|
||||
gfx::setBgTile(ctx, layerNo, x, y, tile8);
|
||||
gfx::setBgTile(ctx, layerNo, x + 1, y, tile8 + 1);
|
||||
gfx::setBgTile(ctx, layerNo, x, y + 1, tile8 + 2);
|
||||
gfx::setBgTile(ctx, layerNo, x + 1, y + 1, tile8 + 3);
|
||||
x += 2;
|
||||
if (x >= width * 2) {
|
||||
x = 0;
|
||||
y += 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
add_library(
|
||||
NostalgiaScene-Studio
|
||||
studiomodule.cpp
|
||||
sceneeditor-imgui.cpp
|
||||
sceneeditor.cpp
|
||||
sceneeditorview.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(
|
||||
NostalgiaScene-Studio PUBLIC
|
||||
NostalgiaScene
|
||||
Studio
|
||||
)
|
||||
|
||||
install(
|
||||
TARGETS
|
||||
NostalgiaScene-Studio
|
||||
LIBRARY DESTINATION
|
||||
${NOSTALGIA_DIST_MODULE}
|
||||
)
|
@ -1,55 +0,0 @@
|
||||
/*
|
||||
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#include <imgui.h>
|
||||
|
||||
#include <keel/media.hpp>
|
||||
|
||||
#include "sceneeditor-imgui.hpp"
|
||||
|
||||
namespace nostalgia::scene {
|
||||
|
||||
SceneEditorImGui::SceneEditorImGui(studio::StudioContext &ctx, ox::StringView path):
|
||||
Editor(ctx, path),
|
||||
m_ctx(ctx.tctx),
|
||||
m_editor(m_ctx, path),
|
||||
m_view(m_ctx, m_editor.scene()) {
|
||||
}
|
||||
|
||||
void SceneEditorImGui::draw(studio::StudioContext&) noexcept {
|
||||
auto const paneSize = ImGui::GetContentRegionAvail();
|
||||
m_view.draw(ox::Size{static_cast<int>(paneSize.x), static_cast<int>(paneSize.y)});
|
||||
auto &fb = m_view.framebuffer();
|
||||
auto const srcH = static_cast<float>(fb.height) / static_cast<float>(fb.width);
|
||||
auto const dstH = paneSize.y / paneSize.x;
|
||||
float xScale{}, yScale{};
|
||||
if (dstH > srcH) {
|
||||
// crop off width
|
||||
xScale = srcH / dstH;
|
||||
yScale = 1;
|
||||
} else {
|
||||
auto const srcW = static_cast<float>(fb.width) / static_cast<float>(fb.height);
|
||||
auto const dstW = (paneSize.x / paneSize.y);
|
||||
xScale = 1;
|
||||
yScale = srcW / dstW;
|
||||
}
|
||||
uintptr_t const buffId = fb.color.id;
|
||||
ImGui::Image(
|
||||
std::bit_cast<void*>(buffId),
|
||||
paneSize,
|
||||
ImVec2(0, 1),
|
||||
ImVec2(xScale, 1 - yScale));
|
||||
}
|
||||
|
||||
void SceneEditorImGui::onActivated() noexcept {
|
||||
oxLogError(m_view.setupScene());
|
||||
}
|
||||
|
||||
ox::Error SceneEditorImGui::saveItem() noexcept {
|
||||
const auto sctx = applicationData<studio::StudioContext>(m_ctx);
|
||||
OX_RETURN_ERROR(sctx->project->writeObj(itemPath(), m_editor.scene()));
|
||||
return {};
|
||||
}
|
||||
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
/*
|
||||
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <studio/studio.hpp>
|
||||
|
||||
#include <turbine/context.hpp>
|
||||
|
||||
#include "sceneeditor.hpp"
|
||||
#include "sceneeditorview.hpp"
|
||||
|
||||
namespace nostalgia::scene {
|
||||
|
||||
class SceneEditorImGui: public studio::Editor {
|
||||
|
||||
private:
|
||||
turbine::Context &m_ctx;
|
||||
SceneEditor m_editor;
|
||||
SceneEditorView m_view;
|
||||
|
||||
public:
|
||||
SceneEditorImGui(studio::StudioContext &ctx, ox::StringView path);
|
||||
|
||||
void draw(studio::StudioContext&) noexcept final;
|
||||
|
||||
void onActivated() noexcept override;
|
||||
|
||||
protected:
|
||||
ox::Error saveItem() noexcept final;
|
||||
|
||||
};
|
||||
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
/*
|
||||
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#include <keel/keel.hpp>
|
||||
|
||||
#include "sceneeditor.hpp"
|
||||
|
||||
namespace nostalgia::scene {
|
||||
|
||||
SceneEditor::SceneEditor(turbine::Context &ctx, ox::StringViewCR path):
|
||||
m_ctx(ctx),
|
||||
m_scene(*keel::readObj<SceneStatic>(keelCtx(m_ctx), path).unwrapThrow()) {
|
||||
}
|
||||
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
/*
|
||||
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <turbine/context.hpp>
|
||||
|
||||
#include <nostalgia/scene/scene.hpp>
|
||||
|
||||
namespace nostalgia::scene {
|
||||
|
||||
class SceneEditor {
|
||||
|
||||
private:
|
||||
turbine::Context &m_ctx;
|
||||
ox::String m_itemName;
|
||||
ox::String m_itemPath;
|
||||
SceneStatic m_scene;
|
||||
|
||||
public:
|
||||
SceneEditor(turbine::Context &ctx, ox::StringViewCR path);
|
||||
|
||||
[[nodiscard]]
|
||||
SceneStatic const&scene() const noexcept {
|
||||
return m_scene;
|
||||
}
|
||||
|
||||
protected:
|
||||
ox::Error saveItem() noexcept;
|
||||
|
||||
};
|
||||
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
/*
|
||||
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#include <nostalgia/gfx/gfx.hpp>
|
||||
|
||||
#include "sceneeditorview.hpp"
|
||||
|
||||
namespace nostalgia::scene {
|
||||
|
||||
SceneEditorView::SceneEditorView(turbine::Context &tctx, SceneStatic const&sceneStatic):
|
||||
m_cctx(gfx::init(tctx, {.glInstallDrawer = false}).unwrapThrow()),
|
||||
m_sceneStatic(sceneStatic),
|
||||
m_scene(m_sceneStatic) {
|
||||
}
|
||||
|
||||
ox::Error SceneEditorView::setupScene() noexcept {
|
||||
glutils::resizeInitFrameBuffer(m_frameBuffer, gfx::gl::drawSize(m_scale));
|
||||
return m_scene.setupDisplay(*m_cctx);
|
||||
}
|
||||
|
||||
void SceneEditorView::draw(ox::Size const&targetSz) noexcept {
|
||||
auto const scaleSz = targetSz / gfx::gl::drawSize(1);
|
||||
if (m_scaleSz != scaleSz) [[unlikely]] {
|
||||
m_scale = ox::max(1, ox::max(scaleSz.width, scaleSz.height));
|
||||
glutils::resizeInitFrameBuffer(m_frameBuffer, gfx::gl::drawSize(m_scale));
|
||||
}
|
||||
glutils::FrameBufferBind const frameBufferBind(m_frameBuffer);
|
||||
gfx::gl::draw(*m_cctx, m_scale);
|
||||
}
|
||||
|
||||
glutils::FrameBuffer const&SceneEditorView::framebuffer() const noexcept {
|
||||
return m_frameBuffer;
|
||||
}
|
||||
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
/*
|
||||
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <glutils/glutils.hpp>
|
||||
|
||||
#include <nostalgia/gfx/context.hpp>
|
||||
#include <nostalgia/gfx/gfx.hpp>
|
||||
#include <nostalgia/scene/scene.hpp>
|
||||
|
||||
namespace nostalgia::scene {
|
||||
|
||||
class SceneEditorView {
|
||||
|
||||
private:
|
||||
ox::UPtr<gfx::Context> m_cctx;
|
||||
SceneStatic const&m_sceneStatic;
|
||||
Scene m_scene;
|
||||
glutils::FrameBuffer m_frameBuffer;
|
||||
int m_scale = 1;
|
||||
ox::Size m_scaleSz = gfx::gl::drawSize(m_scale);
|
||||
|
||||
public:
|
||||
SceneEditorView(turbine::Context &ctx, SceneStatic const&sceneStatic);
|
||||
|
||||
ox::Error setupScene() noexcept;
|
||||
|
||||
void draw(ox::Size const&targetSz) noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
glutils::FrameBuffer const&framebuffer() const noexcept;
|
||||
|
||||
};
|
||||
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
/*
|
||||
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#include <studio/studio.hpp>
|
||||
|
||||
#include "sceneeditor-imgui.hpp"
|
||||
|
||||
namespace nostalgia::scene {
|
||||
|
||||
constexpr ox::StringLiteral FileExt_nscn("nscn");
|
||||
|
||||
static class: public studio::Module {
|
||||
public:
|
||||
ox::Vector<studio::EditorMaker> editors(studio::StudioContext &ctx) const noexcept override {
|
||||
return {
|
||||
studio::editorMaker<SceneEditorImGui>(ctx, FileExt_nscn),
|
||||
};
|
||||
}
|
||||
ox::Vector<ox::UPtr<studio::ItemMaker>> itemMakers(studio::StudioContext&) const noexcept override {
|
||||
ox::Vector<ox::UPtr<studio::ItemMaker>> out;
|
||||
return out;
|
||||
}
|
||||
} mod;
|
||||
|
||||
const studio::Module *studioModule() noexcept {
|
||||
return &mod;
|
||||
}
|
||||
|
||||
}
|
@ -1,13 +1,12 @@
|
||||
add_subdirectory(src)
|
||||
|
||||
target_include_directories(
|
||||
NostalgiaScene PUBLIC
|
||||
include
|
||||
)
|
||||
if(NOT BUILDCORE_TARGET STREQUAL "gba")
|
||||
add_subdirectory(test)
|
||||
endif()
|
||||
|
||||
install(
|
||||
DIRECTORY
|
||||
include/nostalgia
|
||||
DESTINATION
|
||||
include
|
||||
)
|
||||
)
|
@ -6,7 +6,7 @@
|
||||
|
||||
#include <keel/module.hpp>
|
||||
|
||||
namespace nostalgia::scene {
|
||||
namespace nostalgia::sound {
|
||||
|
||||
const keel::Module *keelModule() noexcept;
|
||||
|
@ -0,0 +1,8 @@
|
||||
/*
|
||||
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace nostalgia::sound {
|
||||
}
|
@ -6,7 +6,7 @@
|
||||
|
||||
#include <studio/studio.hpp>
|
||||
|
||||
namespace nostalgia::scene {
|
||||
namespace nostalgia::sound {
|
||||
|
||||
const studio::Module *studioModule() noexcept;
|
||||
|
@ -1,18 +1,16 @@
|
||||
|
||||
add_library(
|
||||
NostalgiaScene
|
||||
scene.cpp
|
||||
scenestatic.cpp
|
||||
NostalgiaSound
|
||||
sound.cpp
|
||||
)
|
||||
|
||||
target_include_directories(
|
||||
NostalgiaScene PUBLIC
|
||||
NostalgiaSound PUBLIC
|
||||
../include
|
||||
)
|
||||
|
||||
target_link_libraries(
|
||||
NostalgiaScene PUBLIC
|
||||
NostalgiaCore
|
||||
NostalgiaSound PUBLIC
|
||||
Turbine
|
||||
)
|
||||
|
||||
add_subdirectory(keel)
|
||||
@ -22,7 +20,7 @@ endif()
|
||||
|
||||
install(
|
||||
TARGETS
|
||||
NostalgiaScene
|
||||
NostalgiaSound
|
||||
DESTINATION
|
||||
LIBRARY DESTINATION lib
|
||||
ARCHIVE DESTINATION lib
|
19
src/nostalgia/modules/sound/src/keel/CMakeLists.txt
Normal file
19
src/nostalgia/modules/sound/src/keel/CMakeLists.txt
Normal file
@ -0,0 +1,19 @@
|
||||
add_library(
|
||||
NostalgiaSound-Keel
|
||||
keelmodule.cpp
|
||||
typeconv.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(
|
||||
NostalgiaSound-Keel PUBLIC
|
||||
Keel
|
||||
NostalgiaSound
|
||||
)
|
||||
|
||||
install(
|
||||
TARGETS
|
||||
NostalgiaSound-Keel
|
||||
DESTINATION
|
||||
LIBRARY DESTINATION lib
|
||||
ARCHIVE DESTINATION lib
|
||||
)
|
46
src/nostalgia/modules/sound/src/keel/keelmodule.cpp
Normal file
46
src/nostalgia/modules/sound/src/keel/keelmodule.cpp
Normal file
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#include <ox/model/model.hpp>
|
||||
|
||||
#include <keel/module.hpp>
|
||||
|
||||
#include "typeconv.hpp"
|
||||
|
||||
namespace nostalgia::sound {
|
||||
|
||||
static class: public keel::Module {
|
||||
private:
|
||||
|
||||
public:
|
||||
[[nodiscard]]
|
||||
ox::String id() const noexcept override {
|
||||
return ox::String{"net.drinkingtea.nostalgia.sound"};
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
ox::Vector<keel::TypeDescGenerator> types() const noexcept final {
|
||||
return {
|
||||
};
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
ox::Vector<keel::BaseConverter const*> converters() const noexcept final {
|
||||
return {
|
||||
};
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
ox::Vector<keel::PackTransform> packTransforms() const noexcept final {
|
||||
return {
|
||||
};
|
||||
}
|
||||
|
||||
} const mod;
|
||||
|
||||
keel::Module const*keelModule() noexcept {
|
||||
return &mod;
|
||||
}
|
||||
|
||||
}
|
@ -2,10 +2,8 @@
|
||||
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#include <nostalgia/scene/scenestatic.hpp>
|
||||
|
||||
namespace nostalgia::scene {
|
||||
|
||||
#include "typeconv.hpp"
|
||||
|
||||
namespace nostalgia::sound {
|
||||
|
||||
}
|
15
src/nostalgia/modules/sound/src/keel/typeconv.hpp
Normal file
15
src/nostalgia/modules/sound/src/keel/typeconv.hpp
Normal file
@ -0,0 +1,15 @@
|
||||
/*
|
||||
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ox/std/def.hpp>
|
||||
|
||||
#include <keel/typeconv.hpp>
|
||||
|
||||
namespace nostalgia::sound {
|
||||
|
||||
// Type converters
|
||||
|
||||
}
|
6
src/nostalgia/modules/sound/src/sound.cpp
Normal file
6
src/nostalgia/modules/sound/src/sound.cpp
Normal file
@ -0,0 +1,6 @@
|
||||
/*
|
||||
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
namespace nostalgia::sound {
|
||||
}
|
17
src/nostalgia/modules/sound/src/studio/CMakeLists.txt
Normal file
17
src/nostalgia/modules/sound/src/studio/CMakeLists.txt
Normal file
@ -0,0 +1,17 @@
|
||||
add_library(
|
||||
NostalgiaSound-Studio-ImGui
|
||||
studiomodule.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(
|
||||
NostalgiaSound-Studio-ImGui PUBLIC
|
||||
NostalgiaSound
|
||||
Studio
|
||||
)
|
||||
|
||||
install(
|
||||
TARGETS
|
||||
NostalgiaSound-Studio-ImGui
|
||||
LIBRARY DESTINATION
|
||||
${NOSTALGIA_DIST_MODULE}
|
||||
)
|
27
src/nostalgia/modules/sound/src/studio/studiomodule.cpp
Normal file
27
src/nostalgia/modules/sound/src/studio/studiomodule.cpp
Normal file
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#include <ox/std/memory.hpp>
|
||||
|
||||
#include <studio/studio.hpp>
|
||||
|
||||
namespace nostalgia::sound {
|
||||
|
||||
static class: public studio::Module {
|
||||
ox::Vector<studio::EditorMaker> editors(studio::StudioContext&) const noexcept final {
|
||||
return {
|
||||
};
|
||||
}
|
||||
|
||||
ox::Vector<ox::UPtr<studio::ItemMaker>> itemMakers(studio::StudioContext&) const noexcept final {
|
||||
ox::Vector<ox::UniquePtr<studio::ItemMaker>> out;
|
||||
return out;
|
||||
}
|
||||
} const mod;
|
||||
|
||||
const studio::Module *studioModule() noexcept {
|
||||
return &mod;
|
||||
}
|
||||
|
||||
}
|
10
src/nostalgia/modules/sound/test/CMakeLists.txt
Normal file
10
src/nostalgia/modules/sound/test/CMakeLists.txt
Normal file
@ -0,0 +1,10 @@
|
||||
add_executable(
|
||||
NostalgiaSoundTest
|
||||
tests.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(
|
||||
NostalgiaSoundTest
|
||||
NostalgiaSound
|
||||
)
|
||||
|
26
src/nostalgia/modules/sound/test/tests.cpp
Normal file
26
src/nostalgia/modules/sound/test/tests.cpp
Normal file
@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#undef NDEBUG
|
||||
|
||||
#include <map>
|
||||
#include <ox/std/error.hpp>
|
||||
#include <ox/mc/mc.hpp>
|
||||
|
||||
static std::map<ox::StringView, ox::Error(*)()> tests = {
|
||||
};
|
||||
|
||||
int main(int argc, const char **argv) {
|
||||
int retval = -1;
|
||||
if (argc > 0) {
|
||||
auto const args = ox::Span{argv, static_cast<size_t>(argc)};
|
||||
auto const testName = ox::StringView(args[1]);
|
||||
if (tests.find(testName) != tests.end()) {
|
||||
retval = static_cast<int>(tests[testName]());
|
||||
} else {
|
||||
retval = 1;
|
||||
}
|
||||
}
|
||||
return retval;
|
||||
}
|
@ -5,7 +5,7 @@
|
||||
#include <studioapp/studioapp.hpp>
|
||||
|
||||
#include <nostalgia/gfx/studiomodule.hpp>
|
||||
#include <nostalgia/scene/studiomodule.hpp>
|
||||
#include <nostalgia/sound/studiomodule.hpp>
|
||||
|
||||
namespace nostalgia {
|
||||
|
||||
@ -16,7 +16,7 @@ void registerStudioModules() noexcept {
|
||||
}
|
||||
modulesRegistered = true;
|
||||
studio::registerModule(gfx::studioModule());
|
||||
studio::registerModule(scene::studioModule());
|
||||
studio::registerModule(sound::studioModule());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ if(NOT WIN32)
|
||||
endif()
|
||||
|
||||
if(COMMAND OBJCOPY_FILE)
|
||||
set(LOAD_KEEL_MODS FALSE)
|
||||
set_target_properties(Nostalgia
|
||||
PROPERTIES
|
||||
LINK_FLAGS ${LINKER_FLAGS}
|
||||
@ -17,8 +18,16 @@ if(COMMAND OBJCOPY_FILE)
|
||||
|
||||
OBJCOPY_FILE(Nostalgia)
|
||||
#PADBIN_FILE(Nostalgia)
|
||||
else()
|
||||
set(LOAD_KEEL_MODS TRUE)
|
||||
endif()
|
||||
|
||||
target_compile_definitions(
|
||||
Nostalgia PRIVATE
|
||||
OLYMPIC_LOAD_KEEL_MODULES=$<BOOL:${LOAD_KEEL_MODS}>
|
||||
OLYMPIC_GUI_APP=1
|
||||
)
|
||||
|
||||
target_link_libraries(
|
||||
Nostalgia
|
||||
NostalgiaKeelModules
|
||||
|
@ -6,7 +6,6 @@
|
||||
#include <turbine/turbine.hpp>
|
||||
|
||||
#include <nostalgia/gfx/core.hpp>
|
||||
#include <nostalgia/scene/scene.hpp>
|
||||
|
||||
using namespace nostalgia;
|
||||
|
||||
@ -126,44 +125,13 @@ static ox::Error runTileSheetSetTest(turbine::Context &tctx) {
|
||||
}
|
||||
|
||||
|
||||
static int sceneUpdateHandler(turbine::Context&) noexcept {
|
||||
constexpr auto sleepTime = 16;
|
||||
if (s_paused) {
|
||||
return sleepTime;
|
||||
}
|
||||
// do stuff
|
||||
return sleepTime;
|
||||
}
|
||||
|
||||
static void sceneKeyEventHandler(turbine::Context &tctx, turbine::Key key, bool down) noexcept {
|
||||
if (down) {
|
||||
if (key == turbine::Key::Alpha_Q) {
|
||||
turbine::requestShutdown(tctx);
|
||||
} else if (key == turbine::Key::Alpha_P) {
|
||||
s_paused = !s_paused;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[[maybe_unused]]
|
||||
static ox::Error runScene(turbine::Context &tctx) {
|
||||
constexpr ox::StringView SceneAddr{"/Scenes/Chester.nscn"};
|
||||
OX_REQUIRE_M(cctx, gfx::init(tctx));
|
||||
OX_REQUIRE(scn, keel::readObj<scene::SceneStatic>(keelCtx(tctx), SceneAddr));
|
||||
turbine::setUpdateHandler(tctx, sceneUpdateHandler);
|
||||
turbine::setKeyEventHandler(tctx, sceneKeyEventHandler);
|
||||
scene::Scene const scene(*scn);
|
||||
OX_RETURN_ERROR(scene.setupDisplay(*cctx));
|
||||
return turbine::run(tctx);
|
||||
}
|
||||
|
||||
ox::Error run(
|
||||
[[maybe_unused]] ox::StringView project,
|
||||
[[maybe_unused]] ox::StringView appName,
|
||||
[[maybe_unused]] ox::StringView projectDataDir,
|
||||
ox::SpanView<char const*> args) noexcept {
|
||||
ox::SpanView<ox::CString> args) noexcept {
|
||||
if (args.size() < 2) {
|
||||
return ox::Error(1, "Please provide path to project directory or OxFS file.");
|
||||
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));
|
||||
|
@ -11,7 +11,7 @@ target_link_libraries(
|
||||
|
||||
target_compile_definitions(
|
||||
NostalgiaStudio PUBLIC
|
||||
OLYMPIC_APP_VERSION="dev build"
|
||||
OLYMPIC_APP_VERSION="d2025.02.0"
|
||||
)
|
||||
|
||||
install(
|
||||
@ -33,7 +33,7 @@ endif()
|
||||
|
||||
install(
|
||||
FILES
|
||||
ns.icns
|
||||
ns_logo.icns
|
||||
DESTINATION
|
||||
${NOSTALGIA_DIST_RESOURCES}/icons
|
||||
)
|
||||
|
@ -9,7 +9,7 @@
|
||||
<string>Nostalgia Studio</string>
|
||||
|
||||
<key>CFBundleIconFile</key>
|
||||
<string>icons/ns.icns</string>
|
||||
<string>icons/ns_logo.icns</string>
|
||||
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>net.drinkingtea.nostalgia.studio</string>
|
||||
@ -18,7 +18,7 @@
|
||||
<string>APPL</string>
|
||||
|
||||
<key>CFBundleVersion</key>
|
||||
<string>0.0.0</string>
|
||||
<string>d2025.02.0</string>
|
||||
|
||||
<key>LSMinimumSystemVersion</key>
|
||||
<string>12.0.0</string>
|
||||
@ -30,6 +30,6 @@
|
||||
<string>True</string>
|
||||
|
||||
<key>NSHumanReadableCopyright</key>
|
||||
<string>Copyright (c) 2016-2023 Gary Talent <gary@drinkingtea.net></string>
|
||||
<string>Copyright (c) 2016-2025 Gary Talent <gary@drinkingtea.net></string>
|
||||
</dict>
|
||||
</plist>
|
||||
|
BIN
src/nostalgia/studio/ns_logo.icns
Normal file
BIN
src/nostalgia/studio/ns_logo.icns
Normal file
Binary file not shown.
@ -15,6 +15,8 @@ constexpr auto K1HdrSz = 40;
|
||||
|
||||
ox::Result<ox::UUID> readUuidHeader(ox::BufferView buff) noexcept;
|
||||
|
||||
ox::Result<ox::UUID> regenerateUuidHeader(ox::Buffer &buff) noexcept;
|
||||
|
||||
ox::Error writeUuidHeader(ox::Writer_c auto &writer, ox::UUID const&uuid) noexcept {
|
||||
OX_RETURN_ERROR(write(writer, "K1;"));
|
||||
OX_RETURN_ERROR(uuid.toString(writer));
|
||||
|
@ -295,7 +295,9 @@ class AssetManager {
|
||||
}
|
||||
|
||||
ox::Error reloadAsset(ox::StringViewCR assetId) noexcept {
|
||||
m_fileUpdated[assetId]->emit(assetId);
|
||||
if (m_fileUpdated.contains(assetId)) {
|
||||
m_fileUpdated[assetId]->emit(assetId);
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
|
@ -64,12 +64,16 @@ ox::Result<ox::CStringView> uuidToPath(Context &ctx, ox::UUID const&uuid) noexce
|
||||
namespace detail {
|
||||
template<typename T>
|
||||
constexpr auto makeLoader(Context &ctx) {
|
||||
return [&ctx](ox::StringViewCR assetId) -> ox::Result<T> {
|
||||
auto const p = ctx.uuidToPath.at(assetId);
|
||||
if (p.error) {
|
||||
return ox::Error{1, "Asset ID not found"};
|
||||
return [&ctx](ox::StringView assetId) -> ox::Result<T> {
|
||||
if (!beginsWith(assetId, "/")) {
|
||||
auto const p = ctx.uuidToPath.at(assetId);
|
||||
if (p.error) {
|
||||
oxErrf("Could not find asset: {}", assetId);
|
||||
return ox::Error{1, "Asset ID not found"};
|
||||
}
|
||||
assetId = *p.value;
|
||||
}
|
||||
OX_REQUIRE(buff, ctx.rom->read(*p.value));
|
||||
OX_REQUIRE(buff, ctx.rom->read(assetId));
|
||||
auto [obj, err] = readAsset<T>(buff);
|
||||
if (err) {
|
||||
if (err != ox::Error_ClawTypeVersionMismatch && err != ox::Error_ClawTypeMismatch) {
|
||||
|
@ -8,15 +8,25 @@ namespace keel {
|
||||
|
||||
ox::Result<ox::UUID> readUuidHeader(ox::BufferView buff) noexcept {
|
||||
if (buff.size() < K1HdrSz) [[unlikely]] {
|
||||
return ox::Error(1, "Insufficient data to contain complete Keel header");
|
||||
return ox::Error{1, "Insufficient data to contain complete Keel header"};
|
||||
}
|
||||
constexpr ox::StringView k1Hdr = "K1;";
|
||||
if (k1Hdr != ox::StringView(buff.data(), k1Hdr.bytes())) [[unlikely]] {
|
||||
return ox::Error(2, "No Keel asset header data");
|
||||
if (k1Hdr != ox::StringView{buff.data(), k1Hdr.bytes()}) [[unlikely]] {
|
||||
return ox::Error{2, "No Keel asset header data"};
|
||||
}
|
||||
return ox::UUID::fromString(ox::StringView(&buff[k1Hdr.bytes()], 36));
|
||||
}
|
||||
|
||||
ox::Result<ox::UUID> regenerateUuidHeader(ox::Buffer &buff) noexcept {
|
||||
OX_RETURN_ERROR(readUuidHeader(buff));
|
||||
OX_REQUIRE(id, ox::UUID::generate());
|
||||
auto const str = id.toString();
|
||||
for (size_t i = 0; i < ox::UUIDStr::cap(); ++i) {
|
||||
buff[i + 3] = str[i];
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
ox::Result<ox::ModelObject> readAsset(ox::TypeStore &ts, ox::BufferView buff) noexcept {
|
||||
std::size_t offset = 0;
|
||||
if (!readUuidHeader(buff).error) {
|
||||
|
@ -53,10 +53,12 @@ static ox::Error buildUuidMap(Context &ctx, ox::StringViewCR path) noexcept {
|
||||
OX_REQUIRE_M(filePath, ox::join("/", ox::Array<ox::StringView, 2>{path, f}));
|
||||
OX_REQUIRE(stat, ctx.rom->stat(filePath));
|
||||
if (stat.fileType == ox::FileType::NormalFile) {
|
||||
OX_REQUIRE(data, ctx.rom->read(filePath));
|
||||
auto const [hdr, err] = readAssetHeader(data);
|
||||
ox::Array<char, K1HdrSz> buff;
|
||||
OX_RETURN_ERROR(
|
||||
ctx.rom->read(filePath, 0, buff.size(), buff));
|
||||
auto const [uuid, err] = readUuidHeader(buff);
|
||||
if (!err) {
|
||||
createUuidMapping(ctx, filePath, hdr.uuid);
|
||||
createUuidMapping(ctx, filePath, uuid);
|
||||
}
|
||||
} else if (stat.fileType == ox::FileType::Directory) {
|
||||
if (!beginsWith(f, ".")) {
|
||||
|
@ -1,16 +1,17 @@
|
||||
add_library(
|
||||
StudioAppLib
|
||||
aboutpopup.cpp
|
||||
app.cpp
|
||||
clawviewer.cpp
|
||||
deleteconfirmation.cpp
|
||||
filedialogmanager.cpp
|
||||
main.cpp
|
||||
makecopypopup.cpp
|
||||
newdir.cpp
|
||||
newmenu.cpp
|
||||
newproject.cpp
|
||||
projectexplorer.cpp
|
||||
renamefile.cpp
|
||||
studioapp.cpp
|
||||
studioui.cpp
|
||||
)
|
||||
target_compile_definitions(
|
||||
StudioAppLib PUBLIC
|
||||
|
@ -11,8 +11,7 @@
|
||||
#include <turbine/turbine.hpp>
|
||||
|
||||
#include <studio/context.hpp>
|
||||
#include <studioapp/studioapp.hpp>
|
||||
#include "studioapp.hpp"
|
||||
#include "studioui.hpp"
|
||||
|
||||
namespace studio {
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user