Compare commits
196 Commits
5fe7c14ccb
...
release-d2
Author | SHA1 | Date | |
---|---|---|---|
f5573e06da | |||
df87832324 | |||
d585794cbe | |||
209658549c | |||
02383a4aed | |||
185a76282a | |||
b722b4f701 | |||
459ab5aad9 | |||
565f621cfc | |||
9589ca9148 | |||
164db5007b | |||
cbfb167d29 | |||
e7b83be867 | |||
649da5fca8 | |||
aa095f7680 | |||
bb99c99f01 | |||
7f0dcdd280 | |||
6029ad5d47 | |||
26fe266b09 | |||
091eda7b44 | |||
9676ea5978 | |||
de8ac10653 | |||
88a6cd59f3 | |||
cd43fb7f38 | |||
136f422401 | |||
e773d6f0ee | |||
7da2f68d30 | |||
d20889aef1 | |||
50c8302f4a | |||
d8195d300d | |||
a8c1387d5a | |||
ff1e8f260b | |||
d4329981e7 | |||
0003454311 | |||
8c6b2234ec | |||
aad4b8a44c | |||
7cab133127 | |||
640ac85de4 | |||
b8d7658626 | |||
2503bb3b2c | |||
e5dd448fe7 | |||
4770bb6a93 | |||
c0bac696dc | |||
95f7c33419 | |||
535d8876d3 | |||
845e433221 | |||
5169a607cf | |||
8f03af99a7 | |||
ee63a4a1e4 | |||
ac29f7a0f2 | |||
89ae226b1d | |||
477834ac04 | |||
97b707b61c | |||
e86180e842 | |||
035ba8810f | |||
f1c2113dd3 | |||
56b79f414d | |||
844656d557 | |||
849aceb86d | |||
eef51a6d2b | |||
c84b85102c | |||
3fe62464c3 | |||
db55fc722f | |||
2094450898 | |||
889bec04b1 | |||
ac1e34d4cd | |||
55ed75f44d | |||
2751872c59 | |||
2a3cd35cc4 | |||
b66f459f75 | |||
3910f4e77c | |||
c0e96216ae | |||
f9512d72e8 | |||
b7f2c169ec | |||
1e5057d6e6 | |||
c6255e3224 | |||
02230ef619 | |||
9b6b60e4d1 | |||
b9a26ab61e | |||
a521887ddd | |||
5ca7e2f226 | |||
125a235dd1 | |||
91a7129f8f | |||
df48a232ec | |||
ab11b885e6 | |||
36fc25fb7e | |||
4803cca334 | |||
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 | |||
6298ac3a21 | |||
cd63afacfe | |||
2859183742 | |||
8d04af691e | |||
055165974e | |||
be51838775 | |||
1207dadee8 | |||
109e1898cc | |||
a24bf7ffb9 | |||
046834c2b9 | |||
f840240aac | |||
cfa91d3d39 | |||
f7a7a66a6a | |||
5145595d57 | |||
f01d303381 | |||
098c8cb844 | |||
04ad0f0264 | |||
695e7a4561 | |||
7d53028faf | |||
6c34198f58 | |||
7e3e046109 | |||
f63c58169f | |||
e40b11246d | |||
161194c8b2 | |||
48603ea2c5 | |||
e2f2a17315 | |||
e8a0ce88c5 | |||
82e2ea747f | |||
ff666eda9b | |||
0d8b82ba49 | |||
5598dfdd87 | |||
6ef462adcc | |||
9511cb5719 | |||
1cc1d561e2 | |||
d15a0df7da | |||
e1282b6bae |
@ -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
|
||||
|
15
Makefile
15
Makefile
@ -15,7 +15,16 @@ PROJECT_PLAYER=./build/${BC_VAR_CURRENT_BUILD}/bin/${BC_VAR_PROJECT_NAME_CAP}
|
||||
|
||||
.PHONY: pkg-gba
|
||||
pkg-gba: build
|
||||
${BC_CMD_ENVRUN} ${BC_PY3} ./util/scripts/pkg-gba.py sample_project ${BC_VAR_PROJECT_NAME}
|
||||
${BC_CMD_ENVRUN} ${BC_PY3} ./util/scripts/pkg-gba.py sample_project ${BC_VAR_PROJECT_NAME_CAP}
|
||||
|
||||
.PHONY: pkg-mac
|
||||
pkg-mac: install
|
||||
${BC_CMD_ENVRUN} ${BC_PY3} ./util/scripts/pkg-dmg.py
|
||||
|
||||
.PHONY: generate-studio-rsrc
|
||||
generate-studio-rsrc:
|
||||
${BC_CMD_ENVRUN} ${BC_PY3} ./util/scripts/file-to-cpp.py --rsrc src/olympic/studio/applib/src/rsrc.json
|
||||
${BC_CMD_ENVRUN} ${BC_PY3} ./util/scripts/file-to-cpp.py --rsrc src/nostalgia/studio/rsrc.json
|
||||
|
||||
.PHONY: build-player
|
||||
build-player:
|
||||
@ -28,10 +37,10 @@ run-studio: build
|
||||
${PROJECT_STUDIO}
|
||||
.PHONY: gba-run
|
||||
gba-run: pkg-gba
|
||||
${MGBA} ${BC_VAR_PROJECT_NAME}.gba
|
||||
${MGBA} ${BC_VAR_PROJECT_NAME_CAP}.gba
|
||||
.PHONY: debug
|
||||
debug: build
|
||||
${BC_CMD_HOST_DEBUGGER} ./build/${BC_VAR_CURRENT_BUILD}/bin/${BC_VAR_PROJECT_NAME} sample_project
|
||||
${BC_CMD_HOST_DEBUGGER} ${PROJECT_PLAYER} sample_project
|
||||
.PHONY: debug-studio
|
||||
debug-studio: build
|
||||
${BC_CMD_HOST_DEBUGGER} ${PROJECT_STUDIO}
|
||||
|
2
deps/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}")
|
||||
|
2
deps/ox/src/ox/clargs/clargs.cpp
vendored
2
deps/ox/src/ox/clargs/clargs.cpp
vendored
@ -29,7 +29,7 @@ ClArgs::ClArgs(ox::SpanView<const char*> args) noexcept {
|
||||
m_bools[arg] = false;
|
||||
}
|
||||
m_strings[arg] = val;
|
||||
if (auto r = ox::atoi(val.c_str()); r.error == 0) {
|
||||
if (auto r = ox::strToInt(val); r.error == 0) {
|
||||
m_ints[arg] = r.value;
|
||||
}
|
||||
++i;
|
||||
|
2
deps/ox/src/ox/claw/read.cpp
vendored
2
deps/ox/src/ox/claw/read.cpp
vendored
@ -81,7 +81,7 @@ Result<ClawHeader> readClawHeader(ox::BufferView buff) noexcept {
|
||||
return ox::Error(4, "Claw format does not match any supported format/version combo");
|
||||
}
|
||||
hdr.typeName = typeName;
|
||||
std::ignore = ox::atoi(versionStr).copyTo(hdr.typeVersion);
|
||||
std::ignore = ox::strToInt(versionStr).copyTo(hdr.typeVersion);
|
||||
hdr.data = buffRaw;
|
||||
hdr.dataSize = buffLen;
|
||||
return hdr;
|
||||
|
10
deps/ox/src/ox/event/signal.hpp
vendored
10
deps/ox/src/ox/event/signal.hpp
vendored
@ -143,6 +143,11 @@ class Signal {
|
||||
|
||||
Error disconnectObject(const void *receiver) const noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
size_t connectionCnt() const noexcept {
|
||||
return m_slots.size();
|
||||
}
|
||||
|
||||
void emit(Args... args) const;
|
||||
|
||||
Error emitCheckError(Args... args) const noexcept;
|
||||
@ -319,6 +324,11 @@ class Signal<Error(Args...)> {
|
||||
|
||||
Error disconnectObject(const void *receiver) const noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
size_t connectionCnt() const noexcept {
|
||||
return m_slots.size();
|
||||
}
|
||||
|
||||
void emit(Args... args) const noexcept;
|
||||
|
||||
Error emitCheckError(Args... args) const noexcept;
|
||||
|
@ -433,14 +433,14 @@ Error FileStoreTemplate<size_t>::resize() {
|
||||
template<typename size_t>
|
||||
Error FileStoreTemplate<size_t>::resize(std::size_t size, void *newBuff) {
|
||||
if (m_buffer->size() > size) {
|
||||
return ox::Error(1);
|
||||
return ox::Error{1, "new buffer is too small for existing data"};
|
||||
}
|
||||
m_buffSize = static_cast<size_t>(size);
|
||||
if (newBuff) {
|
||||
m_buffer = reinterpret_cast<Buffer*>(newBuff);
|
||||
m_buffer = static_cast<Buffer*>(newBuff);
|
||||
OX_RETURN_ERROR(m_buffer->setSize(static_cast<size_t>(size)));
|
||||
}
|
||||
return ox::Error(0);
|
||||
return {};
|
||||
}
|
||||
|
||||
template<typename size_t>
|
||||
|
@ -31,10 +31,10 @@ FileAddress::FileAddress(uint64_t inode) noexcept {
|
||||
FileAddress::FileAddress(ox::StringViewCR path) noexcept {
|
||||
auto pathSize = path.bytes();
|
||||
m_data.path = new char[pathSize + 1];
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
memcpy(m_data.path, path.data(), pathSize);
|
||||
OX_CLANG_NOWARN_BEGIN(-Wunsafe-buffer-usage)
|
||||
m_data.path[pathSize] = 0;
|
||||
OX_CLANG_NOWARN_END
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
m_type = FileAddressType::Path;
|
||||
}
|
||||
|
||||
@ -48,9 +48,11 @@ FileAddress &FileAddress::operator=(const FileAddress &other) noexcept {
|
||||
case FileAddressType::Path:
|
||||
{
|
||||
if (other.m_data.path) {
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
auto strSize = ox::strlen(other.m_data.path) + 1;
|
||||
m_data.path = new char[strSize];
|
||||
ox::memcpy(m_data.path, other.m_data.path, strSize);
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
} else {
|
||||
m_data.constPath = "";
|
||||
m_type = FileAddressType::ConstPath;
|
||||
|
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:
|
||||
|
63
deps/ox/src/ox/fs/filesystem/filesystem.hpp
vendored
63
deps/ox/src/ox/fs/filesystem/filesystem.hpp
vendored
@ -20,7 +20,7 @@
|
||||
namespace ox {
|
||||
|
||||
namespace detail {
|
||||
static inline void fsBuffFree(char *buff) noexcept {
|
||||
inline void fsBuffFree(char *buff) noexcept {
|
||||
safeDelete(buff);
|
||||
}
|
||||
}
|
||||
@ -41,19 +41,39 @@ 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;
|
||||
|
||||
inline Error read(StringViewCR path, void *buffer, std::size_t buffSize) noexcept {
|
||||
Error read(StringViewCR path, void *buffer, std::size_t buffSize) noexcept {
|
||||
return readFilePath(path, buffer, buffSize);
|
||||
}
|
||||
|
||||
inline Error read(uint64_t inode, void *buffer, std::size_t buffSize) noexcept {
|
||||
Error read(uint64_t inode, void *buffer, std::size_t buffSize) noexcept {
|
||||
return readFileInode(inode, buffer, buffSize);
|
||||
}
|
||||
|
||||
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 buff
|
||||
* @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;
|
||||
|
||||
@ -81,36 +101,36 @@ class FileSystem {
|
||||
|
||||
Error write(const FileAddress &addr, const void *buffer, uint64_t size, FileType fileType = FileType::NormalFile) noexcept;
|
||||
|
||||
inline Error write(StringViewCR path, const void *buffer, uint64_t size, FileType fileType) noexcept {
|
||||
Error write(StringViewCR path, const void *buffer, uint64_t size, FileType fileType) noexcept {
|
||||
return writeFilePath(path, buffer, size, fileType);
|
||||
}
|
||||
|
||||
inline Error write(uint64_t inode, const void *buffer, uint64_t size, FileType fileType) noexcept {
|
||||
Error write(uint64_t inode, const void *buffer, uint64_t size, FileType fileType) noexcept {
|
||||
return writeFileInode(inode, buffer, size, fileType);
|
||||
}
|
||||
|
||||
inline Result<FileStat> stat(uint64_t inode) const noexcept {
|
||||
Result<FileStat> stat(uint64_t inode) const noexcept {
|
||||
return statInode(inode);
|
||||
}
|
||||
|
||||
inline Result<FileStat> stat(StringViewCR path) const noexcept {
|
||||
Result<FileStat> stat(StringViewCR path) const noexcept {
|
||||
return statPath(path);
|
||||
}
|
||||
|
||||
Result<FileStat> stat(const FileAddress &addr) const noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
inline bool exists(uint64_t inode) const noexcept {
|
||||
bool exists(uint64_t inode) const noexcept {
|
||||
return statInode(inode).ok();
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline bool exists(ox::StringView path) const noexcept {
|
||||
bool exists(ox::StringView path) const noexcept {
|
||||
return statPath(path).ok();
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline bool exists(FileAddress const&addr) const noexcept {
|
||||
bool exists(FileAddress const&addr) const noexcept {
|
||||
return stat(addr).ok();
|
||||
}
|
||||
|
||||
@ -140,7 +160,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;
|
||||
|
||||
@ -154,11 +177,11 @@ class MemFS: public FileSystem {
|
||||
public:
|
||||
Result<const char*> directAccess(const FileAddress &addr) const noexcept;
|
||||
|
||||
inline Result<const char*> directAccess(StringViewCR path) const noexcept {
|
||||
Result<const char*> directAccess(StringViewCR path) const noexcept {
|
||||
return directAccessPath(path);
|
||||
}
|
||||
|
||||
inline Result<const char*> directAccess(uint64_t inode) const noexcept {
|
||||
Result<const char*> directAccess(uint64_t inode) const noexcept {
|
||||
return directAccessInode(inode);
|
||||
}
|
||||
|
||||
@ -211,6 +234,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 +384,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());
|
||||
@ -435,7 +468,7 @@ Error FileSystemTemplate<FileStore, Directory>::writeFilePath(
|
||||
|
||||
template<typename FileStore, typename Directory>
|
||||
Error FileSystemTemplate<FileStore, Directory>::writeFileInode(uint64_t inode, const void *buffer, uint64_t size, FileType fileType) noexcept {
|
||||
oxTrace("ox.fs.FileSystemTemplate.writeFileInode", ox::itoa(inode));
|
||||
oxTrace("ox.fs.FileSystemTemplate.writeFileInode", ox::intToStr(inode));
|
||||
return m_fs.write(inode, buffer, static_cast<size_t>(size), static_cast<uint8_t>(fileType));
|
||||
}
|
||||
|
||||
|
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;
|
||||
|
6
deps/ox/src/ox/fs/test/tests.cpp
vendored
6
deps/ox/src/ox/fs/test/tests.cpp
vendored
@ -119,7 +119,9 @@ const std::map<ox::StringView, std::function<ox::Error(ox::StringView)>> tests =
|
||||
auto constexpr path = ox::StringLiteral("/usr/share/charset.gbag");
|
||||
ox::PathIterator it(path.c_str(), path.len());
|
||||
auto buff = static_cast<char*>(ox_alloca(path.len() + 1));
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
oxAssert(it.dirPath(buff, path.len()) == 0 && ox::strcmp(buff, "/usr/share/") == 0, "PathIterator shows incorrect dir path");
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
return ox::Error(0);
|
||||
}
|
||||
},
|
||||
@ -127,7 +129,9 @@ const std::map<ox::StringView, std::function<ox::Error(ox::StringView)>> tests =
|
||||
"PathIterator::hasNext",
|
||||
[](ox::StringView) {
|
||||
const auto path = "/file1";
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
ox::PathIterator it(path, ox::strlen(path));
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
oxAssert(it.hasNext(), "PathIterator shows incorrect hasNext");
|
||||
oxAssert(!it.next().hasNext(), "PathIterator shows incorrect hasNext");
|
||||
return ox::Error(0);
|
||||
@ -163,9 +167,11 @@ const std::map<ox::StringView, std::function<ox::Error(ox::StringView)>> tests =
|
||||
[](ox::StringView) {
|
||||
constexpr auto buffLen = 5000;
|
||||
constexpr auto str1 = "Hello, World!";
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
constexpr auto str1Len = ox::strlen(str1) + 1;
|
||||
constexpr auto str2 = "Hello, Moon!";
|
||||
constexpr auto str2Len = ox::strlen(str2) + 1;
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
auto list = new (ox_alloca(buffLen)) ox::ptrarith::NodeBuffer<uint32_t, ox::FileStoreItem<uint32_t>>(buffLen);
|
||||
oxAssert(ox::FileStore32::format(list, buffLen), "FileStore::format failed.");
|
||||
ox::FileStore32 fileStore(list, buffLen);
|
||||
|
2
deps/ox/src/ox/fs/tool.cpp
vendored
2
deps/ox/src/ox/fs/tool.cpp
vendored
@ -57,7 +57,9 @@ static ox::Error runRead(ox::FileSystem *fs, ox::Span<const char*> args) noexcep
|
||||
return ox::Error(1);
|
||||
}
|
||||
OX_REQUIRE(buff, fs->read(ox::StringView(args[1])));
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
std::ignore = fwrite(buff.data(), sizeof(decltype(buff)::value_type), buff.size(), stdout);
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
return ox::Error(0);
|
||||
}
|
||||
|
||||
|
64
deps/ox/src/ox/mc/intops.hpp
vendored
64
deps/ox/src/ox/mc/intops.hpp
vendored
@ -71,7 +71,9 @@ constexpr McInt encodeInteger(I pInput) noexcept {
|
||||
// move input to uint64_t to allow consistent bit manipulation, and to avoid
|
||||
// overflow concerns
|
||||
uint64_t val = 0;
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
ox::memcpy(&val, &input, sizeof(input));
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
if (val) {
|
||||
// bits needed to represent number factoring in space possibly
|
||||
// needed for signed bit
|
||||
@ -94,7 +96,9 @@ constexpr McInt encodeInteger(I pInput) noexcept {
|
||||
}
|
||||
if (bytes == 9) {
|
||||
out.data[0] = bytesIndicator;
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
ox::memcpy(&out.data[1], &leVal, 8);
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
if (inputNegative) {
|
||||
out.data[1] |= 0b1000'0000;
|
||||
}
|
||||
@ -104,7 +108,9 @@ constexpr McInt encodeInteger(I pInput) noexcept {
|
||||
auto intermediate =
|
||||
static_cast<uint64_t>(leVal.raw() | (negBit << (valBits - 1))) << bytes |
|
||||
static_cast<uint64_t>(bytesIndicator);
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
ox::memcpy(&out.data[0], &intermediate, sizeof(intermediate));
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
}
|
||||
out.length = bytes;
|
||||
}
|
||||
@ -151,33 +157,37 @@ constexpr Result<I> decodeInteger(Reader_c auto&rdr, std::size_t *bytesRead) noe
|
||||
decoded >>= bytes;
|
||||
// move sign bit
|
||||
if constexpr(is_signed_v<I>) {
|
||||
const auto negBit = bytes * 8 - bytes - 1;
|
||||
// move sign
|
||||
const auto negative = (decoded >> negBit) == 1;
|
||||
if (negative) {
|
||||
// fill in all bits between encoded sign and real sign with 1s
|
||||
// split it up because the 32-bit ARM can't shift more than 32 bits
|
||||
ox::Array<uint32_t, 2> d = {};
|
||||
//d[0] = decoded & 0xffff'ffff;
|
||||
//d[1] = decoded >> 32;
|
||||
ox::memcpy(&d[0], &decoded, sizeof(decoded));
|
||||
auto bit = negBit;
|
||||
for (; bit < ox::min<std::size_t>(Bits<I>, 32); ++bit) {
|
||||
d[0] |= 1 << bit;
|
||||
}
|
||||
bit -= 32;
|
||||
for (; bit < Bits<I>; ++bit) {
|
||||
d[1] |= 1 << bit;
|
||||
}
|
||||
I out = 0;
|
||||
if constexpr(ox::defines::BigEndian) {
|
||||
const auto d0Tmp = d[0];
|
||||
d[0] = d[1];
|
||||
d[1] = d0Tmp;
|
||||
}
|
||||
ox::memcpy(&out, &d[0], sizeof(out));
|
||||
return out;
|
||||
}
|
||||
const auto negBit = bytes * 8 - bytes - 1;
|
||||
// move sign
|
||||
const auto negative = (decoded >> negBit) == 1;
|
||||
if (negative) {
|
||||
// fill in all bits between encoded sign and real sign with 1s
|
||||
// split it up because the 32-bit ARM can't shift more than 32 bits
|
||||
ox::Array<uint32_t, 2> d = {};
|
||||
//d[0] = decoded & 0xffff'ffff;
|
||||
//d[1] = decoded >> 32;
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
ox::memcpy(&d[0], &decoded, sizeof(decoded));
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
auto bit = negBit;
|
||||
for (; bit < ox::min<std::size_t>(Bits<I>, 32); ++bit) {
|
||||
d[0] |= 1 << bit;
|
||||
}
|
||||
bit -= 32;
|
||||
for (; bit < Bits<I>; ++bit) {
|
||||
d[1] |= 1 << bit;
|
||||
}
|
||||
I out = 0;
|
||||
if constexpr(ox::defines::BigEndian) {
|
||||
const auto d0Tmp = d[0];
|
||||
d[0] = d[1];
|
||||
d[1] = d0Tmp;
|
||||
}
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
ox::memcpy(&out, &d[0], sizeof(out));
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
return out;
|
||||
}
|
||||
}
|
||||
return static_cast<I>(decoded);
|
||||
}
|
||||
|
5
deps/ox/src/ox/mc/write.hpp
vendored
5
deps/ox/src/ox/mc/write.hpp
vendored
@ -214,7 +214,12 @@ template<Writer_c Writer>
|
||||
constexpr Error MetalClawWriter<Writer>::fieldCString(const char*, const char *const*val, std::size_t) noexcept {
|
||||
bool fieldSet = false;
|
||||
if (!m_unionIdx.has_value() || *m_unionIdx == m_field) {
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
// this strlen is tolerated because sometimes 0 gets passed to
|
||||
// the size param, which is a lie
|
||||
// this code should be cleaned up at some point...
|
||||
const auto strLen = *val ? ox::strlen(*val) : 0;
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
// write the length
|
||||
const auto strLenBuff = mc::encodeInteger(strLen);
|
||||
OX_RETURN_ERROR(m_writer.write(reinterpret_cast<const char*>(strLenBuff.data.data()), strLenBuff.length));
|
||||
|
12
deps/ox/src/ox/model/modelvalue.hpp
vendored
12
deps/ox/src/ox/model/modelvalue.hpp
vendored
@ -997,7 +997,7 @@ constexpr ModelValue::ModelValue(const ModelValue &other) noexcept {
|
||||
case Type::SignedInteger16:
|
||||
case Type::SignedInteger32:
|
||||
case Type::SignedInteger64:
|
||||
ox::memcpy(&m_data, &other.m_data, sizeof(m_data));
|
||||
m_data = other.m_data;
|
||||
break;
|
||||
case Type::String:
|
||||
m_data.str = new String(other.get<String>());
|
||||
@ -1030,8 +1030,8 @@ constexpr ModelValue::ModelValue(ModelValue &&other) noexcept {
|
||||
case Type::SignedInteger16:
|
||||
case Type::SignedInteger32:
|
||||
case Type::SignedInteger64:
|
||||
ox::memcpy(&m_data, &other.m_data, sizeof(m_data));
|
||||
ox::memset(&other.m_data, 0, sizeof(m_data));
|
||||
m_data = other.m_data;
|
||||
other.m_data.ui64 = 0;
|
||||
break;
|
||||
case Type::String:
|
||||
m_data.str = other.m_data.str;
|
||||
@ -1223,7 +1223,7 @@ constexpr ModelValue &ModelValue::operator=(const ModelValue &other) noexcept {
|
||||
case Type::SignedInteger16:
|
||||
case Type::SignedInteger32:
|
||||
case Type::SignedInteger64:
|
||||
ox::memcpy(&m_data, &other.m_data, sizeof(m_data));
|
||||
m_data = other.m_data;
|
||||
break;
|
||||
case Type::String:
|
||||
m_data.str = new String(other.get<String>());
|
||||
@ -1261,8 +1261,8 @@ constexpr ModelValue &ModelValue::operator=(ModelValue &&other) noexcept {
|
||||
case Type::SignedInteger16:
|
||||
case Type::SignedInteger32:
|
||||
case Type::SignedInteger64:
|
||||
ox::memcpy(&m_data, &other.m_data, sizeof(m_data));
|
||||
ox::memset(&other.m_data, 0, sizeof(m_data));
|
||||
m_data = other.m_data;
|
||||
other.m_data = {};
|
||||
break;
|
||||
case Type::String:
|
||||
m_data.str = other.m_data.str;
|
||||
|
6
deps/ox/src/ox/model/typestore.hpp
vendored
6
deps/ox/src/ox/model/typestore.hpp
vendored
@ -58,7 +58,11 @@ class TypeStore {
|
||||
if (!std::is_constant_evaluated()) {
|
||||
OX_REQUIRE_M(dt, loadDescriptor(typeId));
|
||||
for (auto &f : dt->fieldList) {
|
||||
OX_RETURN_ERROR(this->getLoad(f.typeId).moveTo(f.type));
|
||||
if (typeId == f.typeId) {
|
||||
f.type = dt.get();
|
||||
} else {
|
||||
OX_RETURN_ERROR(this->getLoad(f.typeId).moveTo(f.type));
|
||||
}
|
||||
}
|
||||
auto &out = m_cache[typeId];
|
||||
out = std::move(dt);
|
||||
|
2
deps/ox/src/ox/oc/read.cpp
vendored
2
deps/ox/src/ox/oc/read.cpp
vendored
@ -15,7 +15,7 @@ namespace ox {
|
||||
|
||||
OrganicClawReader::OrganicClawReader(const uint8_t *buff, std::size_t buffSize) {
|
||||
auto json = reinterpret_cast<const char*>(buff);
|
||||
auto jsonLen = ox::strnlen(json, buffSize);
|
||||
auto jsonLen = ox::strnlen_s(json, buffSize);
|
||||
Json::CharReaderBuilder parserBuilder;
|
||||
auto parser = std::unique_ptr<Json::CharReader>(parserBuilder.newCharReader());
|
||||
if (!parser->parse(json, json + jsonLen, &m_json, nullptr)) {
|
||||
|
4
deps/ox/src/ox/oc/read.hpp
vendored
4
deps/ox/src/ox/oc/read.hpp
vendored
@ -8,7 +8,11 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ox/std/def.hpp>
|
||||
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
#include <json/json.h>
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
|
||||
#include <ox/model/fieldcounter.hpp>
|
||||
#include <ox/model/modelhandleradaptor.hpp>
|
||||
|
8
deps/ox/src/ox/oc/write.hpp
vendored
8
deps/ox/src/ox/oc/write.hpp
vendored
@ -8,7 +8,11 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ox/std/def.hpp>
|
||||
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
#include <json/json.h>
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
|
||||
#include <ox/model/fieldcounter.hpp>
|
||||
#include <ox/model/modelhandleradaptor.hpp>
|
||||
@ -258,7 +262,9 @@ Result<ox::Buffer> writeOC(const auto &val) noexcept {
|
||||
const auto str = Json::writeString(jsonBuilder, writer.m_json);
|
||||
Result<Buffer> buff;
|
||||
buff.value.resize(str.size() + 1);
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
memcpy(buff.value.data(), str.data(), str.size() + 1);
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
return buff;
|
||||
}
|
||||
|
||||
@ -270,7 +276,9 @@ Result<ox::String> writeOCString(const auto &val) noexcept {
|
||||
const auto str = Json::writeString(jsonBuilder, writer.m_json);
|
||||
Result<ox::String> buff;
|
||||
buff.value.resize(str.size());
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
memcpy(buff.value.data(), str.data(), str.size() + 1);
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
return buff;
|
||||
}
|
||||
|
||||
|
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];
|
||||
}
|
||||
|
||||
|
9
deps/ox/src/ox/std/cstrops.hpp
vendored
9
deps/ox/src/ox/std/cstrops.hpp
vendored
@ -30,9 +30,12 @@ constexpr T1 strncpy(T1 dest, T2 src, std::size_t maxLen) noexcept {
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr auto strnlen(const char *str1, std::size_t maxLen) noexcept {
|
||||
std::size_t len = 0;
|
||||
for (; len < maxLen && str1[len]; len++);
|
||||
constexpr size_t strnlen_s(const char *str, size_t const maxLen) noexcept {
|
||||
if (!str) [[unlikely]] {
|
||||
return 0;
|
||||
}
|
||||
size_t len = 0;
|
||||
for (; len < maxLen && str[len]; len++);
|
||||
return len;
|
||||
}
|
||||
|
||||
|
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});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
132
deps/ox/src/ox/std/hashmap.hpp
vendored
132
deps/ox/src/ox/std/hashmap.hpp
vendored
@ -11,6 +11,7 @@
|
||||
#include "algorithm.hpp"
|
||||
#include "hash.hpp"
|
||||
#include "ignore.hpp"
|
||||
#include "optional.hpp"
|
||||
#include "stringview.hpp"
|
||||
#include "strops.hpp"
|
||||
#include "vector.hpp"
|
||||
@ -26,11 +27,12 @@ class HashMap {
|
||||
|
||||
private:
|
||||
struct Pair {
|
||||
UPtr<Pair> next;
|
||||
K key = {};
|
||||
T value{};
|
||||
};
|
||||
Vector<K> m_keys;
|
||||
Vector<Pair*> m_pairs;
|
||||
Vector<UPtr<Pair>> m_pairs;
|
||||
|
||||
public:
|
||||
explicit constexpr HashMap(std::size_t size = 127);
|
||||
@ -73,10 +75,10 @@ class HashMap {
|
||||
constexpr void expand();
|
||||
|
||||
template<typename KK>
|
||||
constexpr Pair *const&access(Vector<Pair*> const&pairs, KK const&key) const;
|
||||
constexpr UPtr<Pair> const &access(Vector<UPtr<Pair>> const &pairs, KK const &key) const;
|
||||
|
||||
template<typename KK>
|
||||
constexpr Pair *&access(Vector<Pair*> &pairs, KK const&key);
|
||||
constexpr UPtr<Pair> &access(Vector<UPtr<Pair>> &pairs, KK const &key);
|
||||
|
||||
};
|
||||
|
||||
@ -85,14 +87,13 @@ constexpr HashMap<K, T>::HashMap(std::size_t size): m_pairs(size) {
|
||||
}
|
||||
|
||||
template<typename K, typename T>
|
||||
constexpr HashMap<K, T>::HashMap(HashMap<K, T> const&other) {
|
||||
m_pairs = other.m_pairs;
|
||||
constexpr HashMap<K, T>::HashMap(HashMap const &other) {
|
||||
operator=(other);
|
||||
}
|
||||
|
||||
template<typename K, typename T>
|
||||
constexpr HashMap<K, T>::HashMap(HashMap<K, T> &&other) noexcept {
|
||||
m_keys = std::move(other.m_keys);
|
||||
m_pairs = std::move(other.m_pairs);
|
||||
constexpr HashMap<K, T>::HashMap(HashMap &&other) noexcept {
|
||||
operator=(std::move(other));
|
||||
}
|
||||
|
||||
template<typename K, typename T>
|
||||
@ -101,7 +102,7 @@ constexpr HashMap<K, T>::~HashMap() {
|
||||
}
|
||||
|
||||
template<typename K, typename T>
|
||||
constexpr bool HashMap<K, T>::operator==(HashMap const&other) const {
|
||||
constexpr bool HashMap<K, T>::operator==(HashMap const &other) const {
|
||||
if (m_keys != other.m_keys) {
|
||||
return false;
|
||||
}
|
||||
@ -115,19 +116,25 @@ constexpr bool HashMap<K, T>::operator==(HashMap const&other) const {
|
||||
}
|
||||
|
||||
template<typename K, typename T>
|
||||
constexpr HashMap<K, T> &HashMap<K, T>::operator=(HashMap<K, T> const&other) {
|
||||
constexpr HashMap<K, T> &HashMap<K, T>::operator=(HashMap const &other) {
|
||||
if (this != &other) {
|
||||
clear();
|
||||
m_keys = other.m_keys;
|
||||
m_pairs = other.m_pairs;
|
||||
m_pairs.resize(other.m_pairs.size());
|
||||
for (auto const&k : m_keys) {
|
||||
auto const &src = access(other.m_pairs, k);
|
||||
auto &dst = access(m_pairs, k);
|
||||
dst = ox::make_unique<Pair>();
|
||||
dst->key = src->key;
|
||||
dst->value = src->value;
|
||||
}
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename K, typename T>
|
||||
constexpr HashMap<K, T> &HashMap<K, T>::operator=(HashMap<K, T> &&other) noexcept {
|
||||
constexpr HashMap<K, T> &HashMap<K, T>::operator=(HashMap &&other) noexcept {
|
||||
if (this != &other) {
|
||||
clear();
|
||||
m_keys = std::move(other.m_keys);
|
||||
m_pairs = std::move(other.m_pairs);
|
||||
}
|
||||
@ -135,60 +142,52 @@ constexpr HashMap<K, T> &HashMap<K, T>::operator=(HashMap<K, T> &&other) noexcep
|
||||
}
|
||||
|
||||
template<typename K, typename T>
|
||||
constexpr T &HashMap<K, T>::operator[](MaybeView_t<K> const&k) {
|
||||
auto p = &access(m_pairs, k);
|
||||
constexpr T &HashMap<K, T>::operator[](MaybeView_t<K> const &key) {
|
||||
auto p = &access(m_pairs, key);
|
||||
if (*p == nullptr) {
|
||||
if (static_cast<double>(m_pairs.size()) * 0.7 <
|
||||
static_cast<double>(m_keys.size())) {
|
||||
expand();
|
||||
p = &access(m_pairs, k);
|
||||
p = &access(m_pairs, key);
|
||||
}
|
||||
*p = new Pair;
|
||||
(*p)->key = k;
|
||||
m_keys.emplace_back(k);
|
||||
*p = ox::make_unique<Pair>();
|
||||
(*p)->key = key;
|
||||
m_keys.emplace_back(key);
|
||||
}
|
||||
return (*p)->value;
|
||||
}
|
||||
|
||||
template<typename K, typename T>
|
||||
constexpr Result<T*> HashMap<K, T>::at(MaybeView_t<K> const&k) noexcept {
|
||||
auto p = access(m_pairs, k);
|
||||
constexpr Result<T*> HashMap<K, T>::at(MaybeView_t<K> const &key) noexcept {
|
||||
auto &p = access(m_pairs, key);
|
||||
if (!p) {
|
||||
return {nullptr, ox::Error(1, "value not found for given key")};
|
||||
return ox::Error{1, "value not found for given key"};
|
||||
}
|
||||
return &p->value;
|
||||
}
|
||||
|
||||
template<typename K, typename T>
|
||||
constexpr Result<const T*> HashMap<K, T>::at(MaybeView_t<K> const&k) const noexcept {
|
||||
auto p = access(m_pairs, k);
|
||||
constexpr Result<const T*> HashMap<K, T>::at(MaybeView_t<K> const &key) const noexcept {
|
||||
auto &p = access(m_pairs, key);
|
||||
if (!p) {
|
||||
return {nullptr, ox::Error(1, "value not found for given key")};
|
||||
return ox::Error{1, "value not found for given key"};
|
||||
}
|
||||
return &p->value;
|
||||
}
|
||||
|
||||
template<typename K, typename T>
|
||||
constexpr void HashMap<K, T>::erase(MaybeView_t<K> const&k) {
|
||||
if (!contains(k)) {
|
||||
constexpr void HashMap<K, T>::erase(MaybeView_t<K> const &key) {
|
||||
if (!contains(key)) {
|
||||
return;
|
||||
}
|
||||
auto h = ox::hash<MaybeView_t<K>>{}(k) % m_pairs.size();
|
||||
while (true) {
|
||||
const auto &p = m_pairs[h];
|
||||
if (p == nullptr || p->key == k) {
|
||||
std::ignore = m_pairs.erase(h);
|
||||
break;
|
||||
} else {
|
||||
h = ox::hash<MaybeView_t<K>>{}(k) % m_pairs.size();
|
||||
}
|
||||
}
|
||||
std::ignore = m_keys.erase(ox::find(m_keys.begin(), m_keys.end(), k));
|
||||
auto &c = access(m_pairs, key);
|
||||
c = std::move(c->next);
|
||||
std::ignore = m_keys.erase(ox::find(m_keys.begin(), m_keys.end(), key));
|
||||
}
|
||||
|
||||
template<typename K, typename T>
|
||||
constexpr bool HashMap<K, T>::contains(MaybeView_t<K> const&k) const noexcept {
|
||||
return access(m_pairs, k) != nullptr;
|
||||
constexpr bool HashMap<K, T>::contains(MaybeView_t<K> const &key) const noexcept {
|
||||
return access(m_pairs, key).get() != nullptr;
|
||||
}
|
||||
|
||||
template<typename K, typename T>
|
||||
@ -204,27 +203,26 @@ constexpr Vector<K> const&HashMap<K, T>::keys() const noexcept {
|
||||
template<typename K, typename T>
|
||||
constexpr Vector<T> HashMap<K, T>::values() const noexcept {
|
||||
Vector<T> out;
|
||||
out.reserve(m_pairs.size());
|
||||
for (auto const&p : m_pairs) {
|
||||
out.emplace_back(p->value);
|
||||
out.reserve(m_keys.size());
|
||||
for (auto const &p : m_pairs) {
|
||||
if (out) {
|
||||
out.emplace_back(p->value);
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
template<typename K, typename T>
|
||||
constexpr void HashMap<K, T>::clear() {
|
||||
for (std::size_t i = 0; i < m_pairs.size(); i++) {
|
||||
delete m_pairs[i];
|
||||
}
|
||||
m_pairs.clear();
|
||||
m_pairs.resize(127);
|
||||
}
|
||||
|
||||
template<typename K, typename T>
|
||||
constexpr void HashMap<K, T>::expand() {
|
||||
Vector<Pair*> r(m_pairs.size() * 2);
|
||||
Vector<UPtr<Pair>> r{m_pairs.size() * 2};
|
||||
for (std::size_t i = 0; i < m_keys.size(); ++i) {
|
||||
auto const&k = m_keys[i];
|
||||
auto const &k = m_keys[i];
|
||||
access(r, k) = std::move(access(m_pairs, k));
|
||||
}
|
||||
m_pairs = std::move(r);
|
||||
@ -232,29 +230,39 @@ constexpr void HashMap<K, T>::expand() {
|
||||
|
||||
template<typename K, typename T>
|
||||
template<typename KK>
|
||||
constexpr typename HashMap<K, T>::Pair *const&HashMap<K, T>::access(Vector<Pair*> const&pairs, KK const&k) const {
|
||||
auto h = static_cast<std::size_t>(ox::hash<KK>{}(k) % pairs.size());
|
||||
constexpr UPtr<typename HashMap<K, T>::Pair> const &HashMap<K, T>::access(
|
||||
Vector<UPtr<Pair>> const& pairs,
|
||||
KK const &key) const {
|
||||
auto const h = static_cast<std::size_t>(ox::hash<KK>{}(key) % pairs.size());
|
||||
auto const &p = *pairs.at(h).unwrap();
|
||||
if (p == nullptr || p->key == key) {
|
||||
return p;
|
||||
}
|
||||
auto c = &p->next;
|
||||
while (true) {
|
||||
auto const&p = *pairs.at(h).unwrap();
|
||||
if (p == nullptr || p->key == k) {
|
||||
return p;
|
||||
} else {
|
||||
h = (h + 1) % pairs.size();
|
||||
if (*c == nullptr || (*c)->key == key) {
|
||||
return *c;
|
||||
}
|
||||
c = &(*c)->next;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename K, typename T>
|
||||
template<typename KK>
|
||||
constexpr typename HashMap<K, T>::Pair *&HashMap<K, T>::access(Vector<Pair*> &pairs, KK const&k) {
|
||||
auto h = static_cast<std::size_t>(ox::hash<KK>{}(k) % pairs.size());
|
||||
constexpr UPtr<typename HashMap<K, T>::Pair> &HashMap<K, T>::access(
|
||||
Vector<UPtr<Pair>> &pairs,
|
||||
KK const &key) {
|
||||
auto const h = static_cast<std::size_t>(ox::hash<KK>{}(key) % pairs.size());
|
||||
auto &p = *pairs.at(h).unwrap();
|
||||
if (p == nullptr || p->key == key) {
|
||||
return p;
|
||||
}
|
||||
auto c = &p->next;
|
||||
while (true) {
|
||||
auto &p = *pairs.at(h).unwrap();
|
||||
if (p == nullptr || p->key == k) {
|
||||
return p;
|
||||
} else {
|
||||
h = (h + 1) % pairs.size();
|
||||
if (*c == nullptr || (*c)->key == key) {
|
||||
return *c;
|
||||
}
|
||||
c = &(*c)->next;
|
||||
}
|
||||
}
|
||||
|
||||
|
2
deps/ox/src/ox/std/istring.hpp
vendored
2
deps/ox/src/ox/std/istring.hpp
vendored
@ -245,7 +245,7 @@ struct MaybeView<ox::IString<sz>> {
|
||||
|
||||
template<Integer_c Integer>
|
||||
[[nodiscard]]
|
||||
constexpr auto itoa(Integer v) noexcept {
|
||||
constexpr auto intToStr(Integer v) noexcept {
|
||||
constexpr auto Cap = [] {
|
||||
auto out = 0;
|
||||
switch (sizeof(Integer)) {
|
||||
|
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];
|
||||
}
|
||||
|
||||
|
4
deps/ox/src/ox/std/memory.hpp
vendored
4
deps/ox/src/ox/std/memory.hpp
vendored
@ -260,12 +260,12 @@ constexpr bool operator==(const UniquePtr<T> &p1, const UniquePtr<T> &p2) noexce
|
||||
|
||||
template<typename T>
|
||||
constexpr bool operator==(const UniquePtr<T> &p1, std::nullptr_t) noexcept {
|
||||
return p1.get();
|
||||
return p1.get() == nullptr;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
constexpr bool operator==(std::nullptr_t, const UniquePtr<T> &p2) noexcept {
|
||||
return p2.get();
|
||||
return p2.get() == nullptr;
|
||||
}
|
||||
|
||||
|
||||
|
26
deps/ox/src/ox/std/span.hpp
vendored
26
deps/ox/src/ox/std/span.hpp
vendored
@ -8,6 +8,10 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#if __has_include(<array>)
|
||||
#include <array>
|
||||
#endif
|
||||
|
||||
#include "array.hpp"
|
||||
#include "bit.hpp"
|
||||
#include "def.hpp"
|
||||
@ -35,6 +39,20 @@ class Span {
|
||||
|
||||
constexpr Span() noexcept = default;
|
||||
|
||||
#if __has_include(<array>)
|
||||
template<std::size_t sz>
|
||||
constexpr Span(std::array<T, sz> &a) noexcept:
|
||||
m_items(a.data()),
|
||||
m_size(a.size()) {
|
||||
}
|
||||
|
||||
template<std::size_t sz>
|
||||
constexpr Span(std::array<ox::remove_const_t<T>, sz> const&a) noexcept:
|
||||
m_items(a.data()),
|
||||
m_size(a.size()) {
|
||||
}
|
||||
#endif
|
||||
|
||||
template<std::size_t sz>
|
||||
constexpr Span(ox::Array<T, sz> &a) noexcept:
|
||||
m_items(a.data()),
|
||||
@ -129,22 +147,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;
|
||||
|
18
deps/ox/src/ox/std/string.hpp
vendored
18
deps/ox/src/ox/std/string.hpp
vendored
@ -28,7 +28,7 @@ OX_CLANG_NOWARN_BEGIN(-Wunsafe-buffer-usage)
|
||||
namespace ox {
|
||||
|
||||
template<typename Integer>
|
||||
constexpr ox::IString<21> itoa(Integer v) noexcept;
|
||||
constexpr ox::IString<21> intToStr(Integer v) noexcept;
|
||||
|
||||
template<std::size_t SmallStringSize_v>
|
||||
class BasicString {
|
||||
@ -213,22 +213,22 @@ class BasicString {
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr const char *c_str() const noexcept {
|
||||
return static_cast<const char*>(m_buff.data());
|
||||
return m_buff.data();
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline explicit operator const char*() const {
|
||||
constexpr explicit operator const char*() const {
|
||||
return c_str();
|
||||
}
|
||||
|
||||
#if __has_include(<string>)
|
||||
[[nodiscard]]
|
||||
inline std::string toStdString() const {
|
||||
std::string toStdString() const {
|
||||
return c_str();
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline explicit operator std::string() const {
|
||||
explicit operator std::string() const {
|
||||
return c_str();
|
||||
}
|
||||
#endif
|
||||
@ -317,13 +317,13 @@ constexpr BasicString<SmallStringSize_v> &BasicString<SmallStringSize_v>::operat
|
||||
|
||||
template<std::size_t SmallStringSize_v>
|
||||
constexpr BasicString<SmallStringSize_v> &BasicString<SmallStringSize_v>::operator=(int64_t i) noexcept {
|
||||
set(ox::itoa(i));
|
||||
set(ox::intToStr(i));
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<std::size_t SmallStringSize_v>
|
||||
constexpr BasicString<SmallStringSize_v> &BasicString<SmallStringSize_v>::operator=(uint64_t i) noexcept {
|
||||
set(ox::itoa(i));
|
||||
set(ox::intToStr(i));
|
||||
return *this;
|
||||
}
|
||||
|
||||
@ -371,7 +371,7 @@ constexpr BasicString<SmallStringSize_v> &BasicString<SmallStringSize_v>::operat
|
||||
|
||||
template<std::size_t SmallStringSize_v>
|
||||
constexpr BasicString<SmallStringSize_v> &BasicString<SmallStringSize_v>::operator+=(Integer_c auto i) noexcept {
|
||||
auto const str = ox::itoa(i);
|
||||
auto const str = ox::intToStr(i);
|
||||
return this->operator+=(str.c_str());
|
||||
}
|
||||
|
||||
@ -414,7 +414,7 @@ constexpr BasicString<SmallStringSize_v> BasicString<SmallStringSize_v>::operato
|
||||
|
||||
template<std::size_t SmallStringSize_v>
|
||||
constexpr BasicString<SmallStringSize_v> BasicString<SmallStringSize_v>::operator+(Integer_c auto i) const noexcept {
|
||||
auto const str = ox::itoa(i);
|
||||
auto const str = ox::intToStr(i);
|
||||
return *this + str;
|
||||
}
|
||||
|
||||
|
2
deps/ox/src/ox/std/stringliteral.hpp
vendored
2
deps/ox/src/ox/std/stringliteral.hpp
vendored
@ -32,7 +32,9 @@ class StringLiteral: public detail::BaseStringView {
|
||||
|
||||
constexpr explicit StringLiteral(const char *str, std::size_t len) noexcept: BaseStringView(str, len) {}
|
||||
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
constexpr explicit StringLiteral(char const *str) noexcept: StringLiteral(str, ox::strlen(str)) {}
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
|
||||
constexpr StringLiteral &operator=(StringLiteral const&other) noexcept {
|
||||
if (&other != this) {
|
||||
|
4
deps/ox/src/ox/std/stringview.hpp
vendored
4
deps/ox/src/ox/std/stringview.hpp
vendored
@ -100,7 +100,8 @@ constexpr auto toStdStringView(StringViewCR sv) noexcept {
|
||||
#endif
|
||||
|
||||
|
||||
constexpr ox::Result<int> atoi(ox::StringViewCR str) noexcept {
|
||||
constexpr ox::Result<int> strToInt(ox::StringViewCR str) noexcept {
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
int total = 0;
|
||||
int multiplier = 1;
|
||||
for (auto i = static_cast<int64_t>(str.len()) - 1; i != -1; --i) {
|
||||
@ -113,6 +114,7 @@ constexpr ox::Result<int> atoi(ox::StringViewCR str) noexcept {
|
||||
}
|
||||
}
|
||||
return total;
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
}
|
||||
|
||||
|
||||
|
4
deps/ox/src/ox/std/strops.cpp
vendored
4
deps/ox/src/ox/std/strops.cpp
vendored
@ -9,6 +9,8 @@
|
||||
#include "def.hpp"
|
||||
#include "strops.hpp"
|
||||
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
|
||||
static_assert(ox::strcmp("asdf", "hijk") < 0, "asdf < hijk");
|
||||
static_assert(ox::strcmp("hijk", "asdf") > 0, "hijk > asdf");
|
||||
static_assert(ox::strcmp("resize", "read") > 0, "resize > read");
|
||||
@ -42,3 +44,5 @@ std::size_t strlen(const char *str) {
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
12
deps/ox/src/ox/std/test/tests.cpp
vendored
12
deps/ox/src/ox/std/test/tests.cpp
vendored
@ -145,6 +145,7 @@ OX_CLANG_NOWARN_END
|
||||
return ox::Error{};
|
||||
}
|
||||
},
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
{
|
||||
"ABCDEFG != HIJKLMN",
|
||||
[]() {
|
||||
@ -169,6 +170,7 @@ OX_CLANG_NOWARN_END
|
||||
return ox::Error(ox::memcmp("ABCDEFGHI", "ABCDEFG", 7) != 0);
|
||||
}
|
||||
},
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
{
|
||||
"IString",
|
||||
[]() {
|
||||
@ -328,6 +330,16 @@ OX_CLANG_NOWARN_END
|
||||
si["aoeu"] = 100;
|
||||
oxAssert(si["asdf"] == 42, "asdf != 42");
|
||||
oxAssert(si["aoeu"] == 100, "aoeu != 100");
|
||||
si.erase("asdf");
|
||||
oxAssert(!si.contains("asdf"), "wrongly contains asdf");
|
||||
oxAssert(si.contains("aoeu"), "does not contains aoeu");
|
||||
oxAssert(!si.at("asdf").ok(), "asdf != 0");
|
||||
oxExpect(si["asdf"], 0);
|
||||
oxAssert(si["aoeu"] == 100, "aoeu != 100");
|
||||
auto si2 = si;
|
||||
oxDebugf("{}", si2["asdf"]);
|
||||
oxExpect(si2["asdf"], 0);
|
||||
oxAssert(si2["aoeu"] == 100, "aoeu != 100");
|
||||
ox::HashMap<int, int> ii;
|
||||
ii[4] = 42;
|
||||
ii[5] = 100;
|
||||
|
4
deps/ox/src/ox/std/tracehook.cpp
vendored
4
deps/ox/src/ox/std/tracehook.cpp
vendored
@ -39,6 +39,8 @@ enum LogChan {
|
||||
Debug = 4,
|
||||
};
|
||||
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
|
||||
template<LogChan chan>
|
||||
static void log(ox::StringViewCR str) {
|
||||
const auto sz = ox::min<std::size_t>(0x100, str.bytes());
|
||||
@ -103,5 +105,7 @@ void oxTraceHook([[maybe_unused]] const char *file, [[maybe_unused]] int line,
|
||||
#endif
|
||||
}
|
||||
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
|
||||
}
|
||||
|
||||
|
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
|
||||
|
||||
|
4
deps/ox/src/ox/std/uuid.hpp
vendored
4
deps/ox/src/ox/std/uuid.hpp
vendored
@ -105,6 +105,10 @@ class UUID {
|
||||
ox::Array<uint8_t, 16> m_value{};
|
||||
|
||||
public:
|
||||
|
||||
static constexpr auto TypeName = "net.drinkingtea.ox.UUID";
|
||||
static constexpr auto TypeVersion = 1;
|
||||
|
||||
static void seedGenerator(const RandomSeed &seed) noexcept;
|
||||
|
||||
static ox::Result<UUID> generate() noexcept;
|
||||
|
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) {
|
||||
|
@ -1,13 +1,45 @@
|
||||
# d2025.02
|
||||
# d2025.05.0
|
||||
|
||||
* Add app icon for both window and file
|
||||
* Change application font to Roboto Medium
|
||||
* Closing application will now confirm with user if any files have unsaved
|
||||
changes.
|
||||
* UUID duplicates will now be reported when opening a project
|
||||
* Deleting a directory now closes files in that directory
|
||||
* Delete key now initiates deletion of selected directory
|
||||
* Remove ability to re-order tabs. There were bugs associated with that.
|
||||
* TileSheetEditor: Fix selection clearing in to work when clicking outside
|
||||
image.
|
||||
* TileSheetEditor: Fix Delete Tile functionality, which was completely broken
|
||||
* PaletteEditor: Fix color number key range in. Previously, pressing A caused
|
||||
the editor to jump to the last color.
|
||||
* PaletteEditor: page rename will now take effect upon pressing enter if the
|
||||
text input has focus
|
||||
|
||||
# d2025.02.1
|
||||
|
||||
* Fix closing tab with unsaved changes (a44c5acc4b)
|
||||
|
||||
# d2025.02.0
|
||||
|
||||
* Rename core namespace to gfx.
|
||||
* Add PaletteV5 to accommodate namespace change.
|
||||
* Add TileSheetV5. TileSheetV5 retains the bpp field for the sake of
|
||||
CompactTileSheet, but always store it pixel as 8 bpp for itself.
|
||||
* Replace file picker combo boxes with support for dragging files from the
|
||||
project explorer.
|
||||
* Add ability to move subsheets in the subsheet tree.
|
||||
* 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 +1,28 @@
|
||||
K1;0f75977f-1c52-45f8-9793-52ea2dc200a0;M2;net.drinkingtea.nostalgia.core.Palette;1;<03><><07><>
|
||||
K1;0f75977f-1c52-45f8-9793-52ea2dc200a0;O1;net.drinkingtea.nostalgia.gfx.Palette;5;{
|
||||
"colorNames" :
|
||||
[
|
||||
"Color 1",
|
||||
"Color 2"
|
||||
],
|
||||
"pages" :
|
||||
[
|
||||
{
|
||||
"colors" :
|
||||
[
|
||||
{
|
||||
"a" : 1,
|
||||
"b" : 31,
|
||||
"g" : 31,
|
||||
"r" : 31
|
||||
},
|
||||
{
|
||||
"a" : 1,
|
||||
"b" : 22,
|
||||
"g" : 22,
|
||||
"r" : 22
|
||||
}
|
||||
],
|
||||
"name" : "Page 1"
|
||||
}
|
||||
]
|
||||
}
|
@ -1 +1,36 @@
|
||||
K1;c79f21e2-f74f-4ad9-90ed-32b0ef7da6ed;M2;net.drinkingtea.nostalgia.core.Palette;1;P<>{<03><>C<>
|
||||
K1;c79f21e2-f74f-4ad9-90ed-32b0ef7da6ed;O1;net.drinkingtea.nostalgia.gfx.Palette;5;{
|
||||
"colorNames" :
|
||||
[
|
||||
"Color 1",
|
||||
"Color 2",
|
||||
"Color 3",
|
||||
"Color 4"
|
||||
],
|
||||
"pages" :
|
||||
[
|
||||
{
|
||||
"colors" :
|
||||
[
|
||||
{
|
||||
"b" : 5
|
||||
},
|
||||
{
|
||||
"b" : 22,
|
||||
"g" : 22,
|
||||
"r" : 22
|
||||
},
|
||||
{
|
||||
"b" : 27,
|
||||
"g" : 27,
|
||||
"r" : 27
|
||||
},
|
||||
{
|
||||
"b" : 20,
|
||||
"g" : 8,
|
||||
"r" : 8
|
||||
}
|
||||
],
|
||||
"name" : "Page 1"
|
||||
}
|
||||
]
|
||||
}
|
28
sample_project/Palettes/SC9K_Logo.npal
Normal file
28
sample_project/Palettes/SC9K_Logo.npal
Normal file
@ -0,0 +1,28 @@
|
||||
K1;3d1a77ec-265f-4905-2061-4f1003ee2189;O1;net.drinkingtea.nostalgia.gfx.Palette;5;{
|
||||
"colorNames" :
|
||||
[
|
||||
"Color 1",
|
||||
"Color 2",
|
||||
"Color 3"
|
||||
],
|
||||
"pages" :
|
||||
[
|
||||
{
|
||||
"colors" :
|
||||
[
|
||||
{
|
||||
"b" : 10,
|
||||
"g" : 5,
|
||||
"r" : 5
|
||||
},
|
||||
{},
|
||||
{
|
||||
"b" : 31,
|
||||
"g" : 31,
|
||||
"r" : 31
|
||||
}
|
||||
],
|
||||
"name" : "Page 1"
|
||||
}
|
||||
]
|
||||
}
|
Binary file not shown.
Binary file not shown.
269
sample_project/TileSheets/NS_Logo16.nts
Normal file
269
sample_project/TileSheets/NS_Logo16.nts
Normal file
@ -0,0 +1,269 @@
|
||||
K1;e7ae945e-d6c5-4444-5738-be95b4e5937a;O1;net.drinkingtea.nostalgia.gfx.TileSheet;5;{
|
||||
"bpp" : 4,
|
||||
"defaultPalette" : "uuid://c79f21e2-f74f-4ad9-90ed-32b0ef7da6ed",
|
||||
"subsheet" :
|
||||
{
|
||||
"columns" : 2,
|
||||
"name" : "Root",
|
||||
"pixels" :
|
||||
[
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
3,
|
||||
3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
2,
|
||||
3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
3,
|
||||
2,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
3,
|
||||
3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
"rows" : 2
|
||||
}
|
||||
}
|
1039
sample_project/TileSheets/NS_Logo32.nts
Normal file
1039
sample_project/TileSheets/NS_Logo32.nts
Normal file
File diff suppressed because it is too large
Load Diff
4111
sample_project/TileSheets/NS_Logo64.nts
Normal file
4111
sample_project/TileSheets/NS_Logo64.nts
Normal file
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@ -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
|
||||
|
@ -238,7 +238,7 @@ uint_t spriteCount(Context &ctx) noexcept;
|
||||
|
||||
ox::Error initConsole(Context &ctx) noexcept;
|
||||
|
||||
void puts(Context &ctx, int column, int row, ox::StringViewCR str) noexcept;
|
||||
void consoleWrite(Context &ctx, int column, int row, ox::StringViewCR str) noexcept;
|
||||
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
@ -289,7 +272,7 @@ constexpr ox::Error repair(TileSheetV4 &ts) noexcept {
|
||||
|
||||
|
||||
struct TileSheetV5 {
|
||||
using SubSheetIdx = ox::Vector<std::size_t, 4>;
|
||||
using SubSheetIdx = ox::Vector<uint32_t, 4>;
|
||||
|
||||
struct SubSheet {
|
||||
static constexpr auto TypeName = "net.drinkingtea.nostalgia.gfx.TileSheet.SubSheet";
|
||||
@ -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 {};
|
||||
}
|
||||
|
||||
@ -414,6 +397,10 @@ void setPixel(TileSheet::SubSheet &ss, ox::Point const&pt, uint8_t palIdx) noexc
|
||||
|
||||
ox::Error setPixelCount(TileSheet::SubSheet &ss, std::size_t cnt) noexcept;
|
||||
|
||||
void flipX(TileSheet::SubSheet &ss, ox::Point const &a, ox::Point const &b) noexcept;
|
||||
|
||||
void flipY(TileSheet::SubSheet &ss, ox::Point const &a, ox::Point const &b) noexcept;
|
||||
|
||||
/**
|
||||
* Gets a count of the pixels in this sheet, and not that of its children.
|
||||
* @return a count of the pixels in this sheet
|
||||
@ -439,25 +426,28 @@ 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(
|
||||
TileSheet::SubSheetIdx const&idx,
|
||||
std::size_t idxIt,
|
||||
TileSheet::SubSheet const&pSubsheet) noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
TileSheet::SubSheet &getSubSheet(
|
||||
TileSheet::SubSheetIdx const&idx,
|
||||
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, TileSheet::SubSheetIdx const&idx) noexcept;
|
||||
TileSheet::SubSheet const&getSubSheet(TileSheet const&ts, ox::SpanView<uint32_t> const &idx) noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
TileSheet::SubSheet &getSubSheet(TileSheet &ts, TileSheet::SubSheetIdx const&idx) noexcept;
|
||||
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;
|
||||
ox::Error addSubSheet(TileSheet &ts, TileSheet::SubSheetIdx const &idx) noexcept;
|
||||
|
||||
ox::Error insertSubSheet(TileSheet &ts, ox::SpanView<uint32_t> const &idx, TileSheet::SubSheet ss) noexcept;
|
||||
|
||||
ox::Error rmSubSheet(
|
||||
TileSheet &ts,
|
||||
|
@ -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()
|
||||
|
@ -36,13 +36,13 @@ OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
setBgStatus(*ctx, 0, true);
|
||||
clearBg(*ctx, 0);
|
||||
auto const serr = ox::sfmt<ox::IString<23>>("Error code: {}", static_cast<int64_t>(err));
|
||||
puts(*ctx, 32 + 1, 1, "SADNESS...");
|
||||
puts(*ctx, 32 + 1, 4, "UNEXPECTED STATE:");
|
||||
puts(*ctx, 32 + 2, 6, panicMsg);
|
||||
consoleWrite(*ctx, 32 + 1, 1, "SADNESS...");
|
||||
consoleWrite(*ctx, 32 + 1, 4, "UNEXPECTED STATE:");
|
||||
consoleWrite(*ctx, 32 + 2, 6, panicMsg);
|
||||
if (err) {
|
||||
puts(*ctx, 32 + 2, 8, serr);
|
||||
consoleWrite(*ctx, 32 + 2, 8, serr);
|
||||
}
|
||||
puts(*ctx, 32 + 1, 15, "PLEASE RESTART THE SYSTEM");
|
||||
consoleWrite(*ctx, 32 + 1, 15, "PLEASE RESTART THE SYSTEM");
|
||||
// print to terminal if in mGBA
|
||||
oxErrf("\033[31;1;1mPANIC:\033[0m [{}:{}]: {}\n", file, line, panicMsg);
|
||||
if (err.msg) {
|
||||
|
@ -251,7 +251,7 @@ ox::Error initConsole(Context &ctx) noexcept {
|
||||
return loadBgPalette(ctx, 0, PaletteAddr);
|
||||
}
|
||||
|
||||
void puts(
|
||||
void consoleWrite(
|
||||
Context &ctx,
|
||||
int const column,
|
||||
int const row,
|
||||
|
@ -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
|
||||
|
@ -14,19 +14,6 @@
|
||||
namespace nostalgia::gfx {
|
||||
|
||||
static class: public keel::Module {
|
||||
private:
|
||||
NostalgiaPaletteToPaletteV1Converter m_nostalgiaPaletteToPaletteV1Converter;
|
||||
PaletteV1ToPaletteV2Converter m_paletteV1ToPaletteV2Converter;
|
||||
PaletteV2ToPaletteV3Converter m_paletteV2ToPaletteV3Converter;
|
||||
PaletteV3ToPaletteV4Converter m_paletteV3ToPaletteV4Converter;
|
||||
PaletteV4ToPaletteV5Converter m_paletteV4ToPaletteV5Converter;
|
||||
PaletteToCompactPaletteConverter m_paletteToCompactPaletteConverter;
|
||||
TileSheetV1ToTileSheetV2Converter m_tileSheetV1ToTileSheetV2Converter;
|
||||
TileSheetV2ToTileSheetV3Converter m_tileSheetV2ToTileSheetV3Converter;
|
||||
TileSheetV3ToTileSheetV4Converter m_tileSheetV3ToTileSheetV4Converter;
|
||||
TileSheetV4ToTileSheetV5Converter m_tileSheetV4ToTileSheetV5Converter;
|
||||
TileSheetToCompactTileSheetConverter m_tileSheetToCompactTileSheetConverter;
|
||||
|
||||
public:
|
||||
[[nodiscard]]
|
||||
ox::String id() const noexcept override {
|
||||
@ -52,19 +39,19 @@ static class: public keel::Module {
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
ox::Vector<keel::BaseConverter const*> converters() const noexcept final {
|
||||
ox::Vector<keel::Converter> converters() const noexcept final {
|
||||
return {
|
||||
&m_nostalgiaPaletteToPaletteV1Converter,
|
||||
&m_paletteV1ToPaletteV2Converter,
|
||||
&m_paletteV2ToPaletteV3Converter,
|
||||
&m_paletteV3ToPaletteV4Converter,
|
||||
&m_paletteV4ToPaletteV5Converter,
|
||||
&m_paletteToCompactPaletteConverter,
|
||||
&m_tileSheetV1ToTileSheetV2Converter,
|
||||
&m_tileSheetV2ToTileSheetV3Converter,
|
||||
&m_tileSheetV3ToTileSheetV4Converter,
|
||||
&m_tileSheetV4ToTileSheetV5Converter,
|
||||
&m_tileSheetToCompactTileSheetConverter,
|
||||
keel::Converter::make<convertNostalgiaPaletteToPaletteV1>(),
|
||||
keel::Converter::make<convertPaletteV1ToPaletteV2>(),
|
||||
keel::Converter::make<convertPaletteV2ToPaletteV3>(),
|
||||
keel::Converter::make<convertPaletteV3ToPaletteV4>(),
|
||||
keel::Converter::make<convertPaletteV4ToPaletteV5>(),
|
||||
keel::Converter::make<convertPaletteToCompactPalette>(),
|
||||
keel::Converter::make<convertTileSheetV1ToTileSheetV2>(),
|
||||
keel::Converter::make<convertTileSheetV2ToTileSheetV3>(),
|
||||
keel::Converter::make<convertTileSheetV3ToTileSheetV4>(),
|
||||
keel::Converter::make<convertTileSheetV4ToTileSheetV5>(),
|
||||
keel::Converter::make<convertTileSheetToCompactTileSheet>(),
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -6,26 +6,26 @@
|
||||
|
||||
namespace nostalgia::gfx {
|
||||
|
||||
ox::Error NostalgiaPaletteToPaletteV1Converter::convert(
|
||||
ox::Error convertNostalgiaPaletteToPaletteV1(
|
||||
keel::Context&,
|
||||
NostalgiaPalette &src,
|
||||
PaletteV1 &dst) const noexcept {
|
||||
PaletteV1 &dst) noexcept {
|
||||
dst.colors = std::move(src.colors);
|
||||
return {};
|
||||
}
|
||||
|
||||
ox::Error PaletteV1ToPaletteV2Converter::convert(
|
||||
ox::Error convertPaletteV1ToPaletteV2(
|
||||
keel::Context&,
|
||||
PaletteV1 &src,
|
||||
PaletteV2 &dst) const noexcept {
|
||||
PaletteV2 &dst) noexcept {
|
||||
dst.pages.emplace_back(std::move(src.colors));
|
||||
return {};
|
||||
}
|
||||
|
||||
ox::Error PaletteV2ToPaletteV3Converter::convert(
|
||||
ox::Error convertPaletteV2ToPaletteV3(
|
||||
keel::Context&,
|
||||
PaletteV2 &src,
|
||||
PaletteV3 &dst) const noexcept {
|
||||
PaletteV3 &dst) noexcept {
|
||||
dst.pages = std::move(src.pages);
|
||||
if (!dst.pages.empty()) {
|
||||
dst.colorInfo.reserve(dst.pages[0].size());
|
||||
@ -36,10 +36,10 @@ ox::Error PaletteV2ToPaletteV3Converter::convert(
|
||||
return {};
|
||||
}
|
||||
|
||||
ox::Error PaletteV3ToPaletteV4Converter::convert(
|
||||
ox::Error convertPaletteV3ToPaletteV4(
|
||||
keel::Context&,
|
||||
PaletteV3 &src,
|
||||
PaletteV4 &dst) const noexcept {
|
||||
PaletteV4 &dst) noexcept {
|
||||
dst.pages.reserve(src.pages.size());
|
||||
for (auto i = 1; auto &page : src.pages) {
|
||||
dst.pages.emplace_back(ox::sfmt("Page {}", i), std::move(page));
|
||||
@ -52,10 +52,10 @@ ox::Error PaletteV3ToPaletteV4Converter::convert(
|
||||
return {};
|
||||
}
|
||||
|
||||
ox::Error PaletteV4ToPaletteV5Converter::convert(
|
||||
ox::Error convertPaletteV4ToPaletteV5(
|
||||
keel::Context&,
|
||||
PaletteV4 &src,
|
||||
PaletteV5 &dst) const noexcept {
|
||||
PaletteV5 &dst) noexcept {
|
||||
dst.colorNames = std::move(src.colorNames);
|
||||
dst.pages.reserve(src.pages.size());
|
||||
for (auto &s : src.pages) {
|
||||
@ -72,10 +72,10 @@ ox::Error PaletteV4ToPaletteV5Converter::convert(
|
||||
return {};
|
||||
}
|
||||
|
||||
ox::Error PaletteToCompactPaletteConverter::convert(
|
||||
ox::Error convertPaletteToCompactPalette(
|
||||
keel::Context&,
|
||||
Palette &src,
|
||||
CompactPalette &dst) const noexcept {
|
||||
CompactPalette &dst) noexcept {
|
||||
dst.pages.reserve(src.pages.size());
|
||||
for (auto &page : src.pages) {
|
||||
auto &p = dst.pages.emplace_back();
|
||||
@ -86,10 +86,10 @@ ox::Error PaletteToCompactPaletteConverter::convert(
|
||||
return {};
|
||||
}
|
||||
|
||||
ox::Error TileSheetV1ToTileSheetV2Converter::convert(
|
||||
ox::Error convertTileSheetV1ToTileSheetV2(
|
||||
keel::Context&,
|
||||
TileSheetV1 &src,
|
||||
TileSheetV2 &dst) const noexcept {
|
||||
TileSheetV2 &dst) noexcept {
|
||||
dst.bpp = src.bpp;
|
||||
dst.defaultPalette = std::move(src.defaultPalette);
|
||||
dst.subsheet.name = "Root";
|
||||
@ -99,7 +99,7 @@ ox::Error TileSheetV1ToTileSheetV2Converter::convert(
|
||||
return {};
|
||||
}
|
||||
|
||||
void TileSheetV2ToTileSheetV3Converter::convertSubsheet(
|
||||
static void convertSubsheet(
|
||||
TileSheetV2::SubSheet &src,
|
||||
TileSheetV3::SubSheet &dst,
|
||||
SubSheetId &idIt) noexcept {
|
||||
@ -115,10 +115,10 @@ void TileSheetV2ToTileSheetV3Converter::convertSubsheet(
|
||||
}
|
||||
}
|
||||
|
||||
ox::Error TileSheetV2ToTileSheetV3Converter::convert(
|
||||
ox::Error convertTileSheetV2ToTileSheetV3(
|
||||
keel::Context&,
|
||||
TileSheetV2 &src,
|
||||
TileSheetV3 &dst) const noexcept {
|
||||
TileSheetV3 &dst) noexcept {
|
||||
dst.bpp = src.bpp;
|
||||
dst.defaultPalette = std::move(src.defaultPalette);
|
||||
convertSubsheet(src.subsheet, dst.subsheet, dst.idIt);
|
||||
@ -126,7 +126,7 @@ ox::Error TileSheetV2ToTileSheetV3Converter::convert(
|
||||
}
|
||||
|
||||
|
||||
void TileSheetV3ToTileSheetV4Converter::convertSubsheet(
|
||||
static void convertSubsheet(
|
||||
TileSheetV3::SubSheet &src,
|
||||
TileSheetV4::SubSheet &dst,
|
||||
SubSheetId &idIt) noexcept {
|
||||
@ -142,10 +142,10 @@ void TileSheetV3ToTileSheetV4Converter::convertSubsheet(
|
||||
}
|
||||
}
|
||||
|
||||
ox::Error TileSheetV3ToTileSheetV4Converter::convert(
|
||||
ox::Error convertTileSheetV3ToTileSheetV4(
|
||||
keel::Context&,
|
||||
TileSheetV3 &src,
|
||||
TileSheetV4 &dst) const noexcept {
|
||||
TileSheetV4 &dst) noexcept {
|
||||
dst.bpp = src.bpp;
|
||||
dst.idIt = src.idIt;
|
||||
dst.defaultPalette = std::move(src.defaultPalette);
|
||||
@ -154,7 +154,7 @@ ox::Error TileSheetV3ToTileSheetV4Converter::convert(
|
||||
}
|
||||
|
||||
|
||||
void TileSheetV4ToTileSheetV5Converter::convertSubsheet(
|
||||
static void convertSubsheet(
|
||||
int const bpp,
|
||||
TileSheetV4::SubSheet &src,
|
||||
TileSheetV5::SubSheet &dst) noexcept {
|
||||
@ -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);
|
||||
}
|
||||
@ -179,22 +179,22 @@ void TileSheetV4ToTileSheetV5Converter::convertSubsheet(
|
||||
}
|
||||
}
|
||||
|
||||
ox::Error TileSheetV4ToTileSheetV5Converter::convert(
|
||||
ox::Error convertTileSheetV4ToTileSheetV5(
|
||||
keel::Context&,
|
||||
TileSheetV4 &src,
|
||||
TileSheetV5 &dst) const noexcept {
|
||||
dst.bpp = src.bpp;
|
||||
dst.idIt = src.idIt;
|
||||
TileSheetV5 &dst) noexcept {
|
||||
dst.bpp = src.bpp;
|
||||
dst.idIt = src.idIt;
|
||||
OX_RETURN_ERROR(src.defaultPalette.getPath().moveTo(dst.defaultPalette));
|
||||
convertSubsheet(dst.bpp, src.subsheet, dst.subsheet);
|
||||
return {};
|
||||
}
|
||||
|
||||
|
||||
ox::Error TileSheetToCompactTileSheetConverter::convert(
|
||||
ox::Error convertTileSheetToCompactTileSheet(
|
||||
keel::Context&,
|
||||
TileSheet &src,
|
||||
CompactTileSheet &dst) const noexcept {
|
||||
CompactTileSheet &dst) noexcept {
|
||||
dst.bpp = src.bpp;
|
||||
dst.defaultPalette = ox::FileAddress{src.defaultPalette};
|
||||
dst.pixels = pixels(src);
|
||||
|
@ -16,60 +16,26 @@ namespace nostalgia::gfx {
|
||||
|
||||
// Type converters
|
||||
|
||||
class NostalgiaPaletteToPaletteV1Converter: public keel::Converter<NostalgiaPalette, PaletteV1> {
|
||||
ox::Error convert(keel::Context&, NostalgiaPalette &src, PaletteV1 &dst) const noexcept final;
|
||||
};
|
||||
ox::Error convertNostalgiaPaletteToPaletteV1(keel::Context&, NostalgiaPalette &src, PaletteV1 &dst) noexcept;
|
||||
|
||||
class PaletteV1ToPaletteV2Converter: public keel::Converter<PaletteV1, PaletteV2> {
|
||||
ox::Error convert(keel::Context&, PaletteV1 &src, PaletteV2 &dst) const noexcept final;
|
||||
};
|
||||
ox::Error convertPaletteV1ToPaletteV2(keel::Context&, PaletteV1 &src, PaletteV2 &dst) noexcept;
|
||||
|
||||
class PaletteV2ToPaletteV3Converter: public keel::Converter<PaletteV2, PaletteV3> {
|
||||
ox::Error convert(keel::Context&, PaletteV2 &src, PaletteV3 &dst) const noexcept final;
|
||||
};
|
||||
ox::Error convertPaletteV2ToPaletteV3(keel::Context&, PaletteV2 &src, PaletteV3 &dst) noexcept;
|
||||
|
||||
class PaletteV3ToPaletteV4Converter: public keel::Converter<PaletteV3, PaletteV4> {
|
||||
ox::Error convert(keel::Context&, PaletteV3 &src, PaletteV4 &dst) const noexcept final;
|
||||
};
|
||||
ox::Error convertPaletteV3ToPaletteV4(keel::Context&, PaletteV3 &src, PaletteV4 &dst) noexcept;
|
||||
|
||||
class PaletteV4ToPaletteV5Converter: public keel::Converter<PaletteV4, PaletteV5> {
|
||||
ox::Error convert(keel::Context&, PaletteV4 &src, PaletteV5 &dst) const noexcept final;
|
||||
};
|
||||
ox::Error convertPaletteV4ToPaletteV5(keel::Context&, PaletteV4 &src, PaletteV5 &dst) noexcept;
|
||||
|
||||
class PaletteToCompactPaletteConverter: public keel::Converter<Palette, CompactPalette> {
|
||||
ox::Error convert(keel::Context&, Palette &src, CompactPalette &dst) const noexcept final;
|
||||
};
|
||||
ox::Error convertPaletteToCompactPalette(keel::Context&, Palette &src, CompactPalette &dst) noexcept;
|
||||
|
||||
class TileSheetV1ToTileSheetV2Converter: public keel::Converter<TileSheetV1, TileSheetV2> {
|
||||
ox::Error convert(keel::Context&, TileSheetV1 &src, TileSheetV2 &dst) const noexcept final;
|
||||
};
|
||||
ox::Error convertTileSheetV1ToTileSheetV2(keel::Context&, TileSheetV1 &src, TileSheetV2 &dst) noexcept;
|
||||
|
||||
class TileSheetV2ToTileSheetV3Converter: public keel::Converter<TileSheetV2, TileSheetV3> {
|
||||
static void convertSubsheet(
|
||||
TileSheetV2::SubSheet &src,
|
||||
TileSheetV3::SubSheet &dst,
|
||||
SubSheetId &idIt) noexcept;
|
||||
ox::Error convert(keel::Context&, TileSheetV2 &src, TileSheetV3 &dst) const noexcept final;
|
||||
};
|
||||
ox::Error convertTileSheetV2ToTileSheetV3(keel::Context&, TileSheetV2 &src, TileSheetV3 &dst) noexcept;
|
||||
|
||||
class TileSheetV3ToTileSheetV4Converter: public keel::Converter<TileSheetV3, TileSheetV4> {
|
||||
static void convertSubsheet(
|
||||
TileSheetV3::SubSheet &src,
|
||||
TileSheetV4::SubSheet &dst,
|
||||
SubSheetId &idIt) noexcept;
|
||||
ox::Error convert(keel::Context&, TileSheetV3 &src, TileSheetV4 &dst) const noexcept final;
|
||||
};
|
||||
ox::Error convertTileSheetV3ToTileSheetV4(keel::Context&, TileSheetV3 &src, TileSheetV4 &dst) noexcept;
|
||||
|
||||
class TileSheetV4ToTileSheetV5Converter final: public keel::Converter<TileSheetV4, TileSheetV5> {
|
||||
static void convertSubsheet(
|
||||
int bpp,
|
||||
TileSheetV4::SubSheet &src,
|
||||
TileSheetV5::SubSheet &dst) noexcept;
|
||||
ox::Error convert(keel::Context&, TileSheetV4 &src, TileSheetV5 &dst) const noexcept override;
|
||||
};
|
||||
ox::Error convertTileSheetV4ToTileSheetV5(keel::Context&, TileSheetV4 &src, TileSheetV5 &dst) noexcept;
|
||||
|
||||
class TileSheetToCompactTileSheetConverter: public keel::Converter<TileSheet, CompactTileSheet> {
|
||||
ox::Error convert(keel::Context&, TileSheet &src, CompactTileSheet &dst) const noexcept final;
|
||||
};
|
||||
ox::Error convertTileSheetToCompactTileSheet(keel::Context&, TileSheet &src, CompactTileSheet &dst) noexcept;
|
||||
|
||||
}
|
||||
|
@ -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,
|
||||
|
@ -9,9 +9,10 @@
|
||||
namespace nostalgia::gfx {
|
||||
|
||||
MoveColorCommand::MoveColorCommand(
|
||||
Palette &pal, size_t page, size_t srcIdx, size_t dstIdx) noexcept:
|
||||
Palette &pal,
|
||||
size_t const srcIdx,
|
||||
size_t const dstIdx) noexcept:
|
||||
m_pal(pal),
|
||||
m_page(page),
|
||||
m_srcIdx(srcIdx),
|
||||
m_dstIdx(dstIdx) {}
|
||||
|
||||
@ -29,10 +30,18 @@ ox::Error MoveColorCommand::undo() noexcept {
|
||||
return {};
|
||||
}
|
||||
|
||||
void MoveColorCommand::moveColor(size_t srcIdx, size_t dstIdx) noexcept {
|
||||
auto const c = color(m_pal, m_page, srcIdx);
|
||||
std::ignore = colors(m_pal, m_page).erase(srcIdx);
|
||||
colors(m_pal, m_page).emplace(dstIdx, c);
|
||||
void MoveColorCommand::moveColor(
|
||||
size_t const srcIdx, size_t const dstIdx) noexcept {
|
||||
for (size_t page{}; page < m_pal.pages.size(); ++page) {
|
||||
auto const c = color(m_pal, page, srcIdx);
|
||||
std::ignore = colors(m_pal, page).erase(srcIdx);
|
||||
colors(m_pal, page).emplace(dstIdx, c);
|
||||
}
|
||||
{
|
||||
auto name = std::move(m_pal.colorNames[srcIdx]);
|
||||
std::ignore = m_pal.colorNames.erase(srcIdx);
|
||||
m_pal.colorNames.emplace(dstIdx, std::move(name));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -13,12 +13,11 @@ namespace nostalgia::gfx {
|
||||
class MoveColorCommand: public studio::UndoCommand {
|
||||
private:
|
||||
Palette &m_pal;
|
||||
size_t const m_page = 0;
|
||||
std::size_t const m_srcIdx = 0;
|
||||
std::size_t const m_dstIdx = 0;
|
||||
|
||||
public:
|
||||
MoveColorCommand(Palette &pal, size_t page, size_t srcIdx, size_t dstIdx) noexcept;
|
||||
MoveColorCommand(Palette &pal, size_t srcIdx, size_t dstIdx) noexcept;
|
||||
|
||||
~MoveColorCommand() noexcept override = default;
|
||||
|
||||
|
@ -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,33 +20,56 @@
|
||||
|
||||
#include "paletteeditor-imgui.hpp"
|
||||
|
||||
|
||||
namespace nostalgia::gfx {
|
||||
|
||||
namespace ig = studio::ig;
|
||||
|
||||
struct ColorDragDrop {
|
||||
static constexpr auto TypeName = "nostalgia.gfx.ColorDragDrop";
|
||||
static constexpr auto TypeVersion = 1;
|
||||
uint32_t i{};
|
||||
};
|
||||
|
||||
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;
|
||||
}
|
||||
if (ig::BeginPopup(tctx, "Rename Page", m_show)) {
|
||||
if (ImGui::IsWindowAppearing()) {
|
||||
ImGui::SetKeyboardFocusHere();
|
||||
}
|
||||
ig::InputText("Name", m_name);
|
||||
switch (ig::PopupControlsOkCancel(m_show)) {
|
||||
case ig::PopupResponse::OK:
|
||||
inputSubmitted.emit(m_name);
|
||||
[[fallthrough]];
|
||||
case ig::PopupResponse::Cancel:
|
||||
close();
|
||||
default:
|
||||
break;
|
||||
auto const nameInputFocused = ImGui::IsItemFocused();
|
||||
auto const resp = ig::PopupControlsOkCancel(m_show);
|
||||
if ((nameInputFocused && ImGui::IsKeyPressed(ImGuiKey_Enter))
|
||||
|| resp == ig::PopupResponse::OK) {
|
||||
inputSubmitted.emit(m_name);
|
||||
close();
|
||||
} else if (resp == ig::PopupResponse::Cancel) {
|
||||
close();
|
||||
}
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
PaletteEditorImGui::PaletteEditorImGui(studio::StudioContext &sctx, ox::StringParam path):
|
||||
Editor(std::move(path)),
|
||||
PaletteEditorImGui::PaletteEditorImGui(studio::Context &sctx, ox::StringParam path):
|
||||
Editor(sctx, std::move(path)),
|
||||
m_sctx(sctx),
|
||||
m_tctx(sctx.tctx),
|
||||
m_pal(*keel::readObj<Palette>(keelCtx(m_tctx), itemPath()).unwrapThrow()) {
|
||||
@ -53,7 +77,7 @@ PaletteEditorImGui::PaletteEditorImGui(studio::StudioContext &sctx, ox::StringPa
|
||||
m_pageRenameDlg.inputSubmitted.connect(this, &PaletteEditorImGui::renamePage);
|
||||
}
|
||||
|
||||
void PaletteEditorImGui::draw(studio::StudioContext&) noexcept {
|
||||
void PaletteEditorImGui::draw(studio::Context&) noexcept {
|
||||
auto const paneSize = ImGui::GetContentRegionAvail();
|
||||
{
|
||||
ImGui::BeginChild("Pages", {280, paneSize.y}, true);
|
||||
@ -73,6 +97,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] = strToInt(color);
|
||||
if (!err && static_cast<size_t>(c) < colorCnt(m_pal)) {
|
||||
m_selectedColorRow = static_cast<size_t>(c);
|
||||
}
|
||||
}
|
||||
{
|
||||
auto const [pg, err] = strToInt(page);
|
||||
if (!err && static_cast<size_t>(pg) < m_pal.pages.size()) {
|
||||
m_page = static_cast<size_t>(pg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PaletteEditorImGui::drawColumnLeftAlign(ox::CStringView txt) noexcept {
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("%s", txt.c_str());
|
||||
@ -89,7 +134,7 @@ void PaletteEditorImGui::numShortcuts(size_t &val, size_t const sizeRange) noexc
|
||||
auto const lastElem = sizeRange - 1;
|
||||
if (ImGui::IsKeyPressed(ImGuiKey_0)) {
|
||||
val = ox::min<size_t>(9, lastElem);
|
||||
} else for (auto i = 9u; i < 10; --i) {
|
||||
} else for (auto i = 8u; i < 9; --i) {
|
||||
auto const key = static_cast<ImGuiKey>(ImGuiKey_1 + i);
|
||||
if (ImGui::IsKeyPressed(key)) {
|
||||
val = ox::min<size_t>(i, lastElem);
|
||||
@ -125,26 +170,6 @@ void PaletteEditorImGui::drawColorsEditor() noexcept {
|
||||
m_selectedColorRow = ox::min(colorCnt(m_pal, m_page) - 1, m_selectedColorRow);
|
||||
colorEditor = m_selectedColorRow < colorCnt(m_pal, m_page);
|
||||
}
|
||||
ImGui::SameLine();
|
||||
ImGui::BeginDisabled(m_selectedColorRow <= 0);
|
||||
{
|
||||
if (ImGui::Button("Move Up", sz)) {
|
||||
std::ignore = pushCommand<MoveColorCommand>(
|
||||
m_pal, m_page, m_selectedColorRow, m_selectedColorRow - 1);
|
||||
--m_selectedColorRow;
|
||||
}
|
||||
}
|
||||
ImGui::EndDisabled();
|
||||
ImGui::SameLine();
|
||||
ImGui::BeginDisabled(m_selectedColorRow >= colorCnt(m_pal, m_page) - 1);
|
||||
{
|
||||
if (ImGui::Button("Move Down", sz)) {
|
||||
std::ignore = pushCommand<MoveColorCommand>(
|
||||
m_pal, m_page, m_selectedColorRow, m_selectedColorRow + 1);
|
||||
++m_selectedColorRow;
|
||||
}
|
||||
}
|
||||
ImGui::EndDisabled();
|
||||
}
|
||||
ImGui::EndDisabled();
|
||||
}
|
||||
@ -179,6 +204,16 @@ void PaletteEditorImGui::drawColorsEditor() noexcept {
|
||||
"##ColorRow", i == m_selectedColorRow, ImGuiSelectableFlags_SpanAllColumns)) {
|
||||
m_selectedColorRow = i;
|
||||
}
|
||||
std::ignore = ig::dragDropSource([this, i] {
|
||||
ImGui::Text("%s", m_pal.colorNames[i].c_str());
|
||||
return ig::setDragDropPayload(ColorDragDrop{i});
|
||||
}, ImGuiDragDropFlags_SourceAllowNullID);
|
||||
if (ig::DragDropTarget const d; d) {
|
||||
auto const [src, err] = ig::getDragDropPayload<ColorDragDrop>();
|
||||
if (!err) {
|
||||
std::ignore = pushCommand<MoveColorCommand>(m_pal, src.i, i);
|
||||
}
|
||||
}
|
||||
++i;
|
||||
}
|
||||
}
|
||||
@ -236,6 +271,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();
|
||||
@ -258,7 +303,7 @@ void PaletteEditorImGui::drawColorEditor() noexcept {
|
||||
std::ignore = pushCommand<ApplyColorAllPagesCommand>(
|
||||
m_pal, m_page, m_selectedColorRow);
|
||||
}
|
||||
if (ig::mainWinHasFocus() && !inputFocused) {
|
||||
if (ig::mainWinHasFocus() && !inputFocused && !ImGui::IsKeyDown(ImGuiKey_ModCtrl)) {
|
||||
if (!ImGui::IsKeyDown(ImGuiKey_ModAlt)) {
|
||||
numShortcuts(m_selectedColorRow, largestPage(m_pal));
|
||||
} else {
|
||||
|
@ -31,27 +31,29 @@ class PaletteEditorImGui: public studio::Editor {
|
||||
constexpr bool isOpen() const noexcept { return m_show; }
|
||||
void draw(turbine::Context &tctx) noexcept;
|
||||
} m_pageRenameDlg;
|
||||
studio::StudioContext &m_sctx;
|
||||
studio::Context &m_sctx;
|
||||
turbine::Context &m_tctx;
|
||||
Palette m_pal;
|
||||
size_t m_selectedColorRow = 0;
|
||||
size_t m_page = 0;
|
||||
|
||||
public:
|
||||
PaletteEditorImGui(studio::StudioContext &sctx, ox::StringParam path);
|
||||
PaletteEditorImGui(studio::Context &sctx, ox::StringParam path);
|
||||
|
||||
void draw(studio::StudioContext&) noexcept final;
|
||||
void draw(studio::Context&) noexcept final;
|
||||
|
||||
protected:
|
||||
ox::Error saveItem() noexcept final;
|
||||
|
||||
void navigateTo(ox::StringViewCR arg) noexcept override;
|
||||
|
||||
private:
|
||||
static void drawColumnLeftAlign(ox::CStringView txt) noexcept;
|
||||
|
||||
static void drawColumn(ox::CStringView txt) noexcept;
|
||||
|
||||
static void drawColumn(ox::Integer_c auto i) noexcept {
|
||||
drawColumn(ox::itoa(i));
|
||||
drawColumn(ox::intToStr(i));
|
||||
}
|
||||
|
||||
static void numShortcuts(size_t &val, size_t sizeRange) noexcept;
|
||||
|
@ -12,15 +12,15 @@
|
||||
namespace nostalgia::gfx {
|
||||
|
||||
static class: public studio::Module {
|
||||
ox::Vector<studio::EditorMaker> editors(studio::StudioContext &ctx) const noexcept final {
|
||||
ox::Vector<studio::EditorMaker> editors(studio::Context &ctx) const noexcept final {
|
||||
return {
|
||||
studio::editorMaker<TileSheetEditorImGui>(ctx, {FileExt_ng, FileExt_nts}),
|
||||
studio::editorMaker<PaletteEditorImGui>(ctx, FileExt_npal),
|
||||
};
|
||||
}
|
||||
|
||||
ox::Vector<ox::UPtr<studio::ItemMaker>> itemMakers(studio::StudioContext&) const noexcept final {
|
||||
ox::Vector<ox::UniquePtr<studio::ItemMaker>> out;
|
||||
ox::Vector<ox::UPtr<studio::ItemMaker>> itemMakers(studio::Context&) const noexcept final {
|
||||
ox::Vector<ox::UPtr<studio::ItemMaker>> out;
|
||||
out.emplace_back(ox::make<studio::ItemMakerT<TileSheet>>("Tile Sheet", "TileSheets", FileExt_nts));
|
||||
out.emplace_back(ox::make<studio::ItemMakerT<Palette>>("Palette", "Palettes", FileExt_npal, Palette{
|
||||
.colorNames = {},
|
||||
|
@ -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,11 +1,14 @@
|
||||
target_sources(
|
||||
NostalgiaCore-Studio PRIVATE
|
||||
NostalgiaGfx-Studio PRIVATE
|
||||
addsubsheetcommand.cpp
|
||||
cutpastecommand.cpp
|
||||
deletetilescommand.cpp
|
||||
drawcommand.cpp
|
||||
flipcommand.cpp
|
||||
movesubsheetcommand.cpp
|
||||
inserttilescommand.cpp
|
||||
palettechangecommand.cpp
|
||||
rmsubsheetcommand.cpp
|
||||
rotatecommand.cpp
|
||||
updatesubsheetcommand.cpp
|
||||
)
|
||||
|
@ -12,14 +12,18 @@ namespace nostalgia::gfx {
|
||||
// Command IDs to use with QUndoCommand::id()
|
||||
enum class CommandId {
|
||||
Draw = 1,
|
||||
AddSubSheet = 2,
|
||||
RmSubSheet = 3,
|
||||
DeleteTile = 4,
|
||||
InsertTile = 4,
|
||||
UpdateSubSheet = 5,
|
||||
Cut = 6,
|
||||
Paste = 7,
|
||||
PaletteChange = 8,
|
||||
AddSubSheet,
|
||||
RmSubSheet,
|
||||
DeleteTile,
|
||||
FlipX,
|
||||
FlipY,
|
||||
Rotate,
|
||||
InsertTile,
|
||||
MoveSubSheet,
|
||||
UpdateSubSheet,
|
||||
Cut,
|
||||
Paste,
|
||||
PaletteChange,
|
||||
};
|
||||
|
||||
constexpr bool operator==(CommandId c, int i) noexcept {
|
||||
|
@ -8,14 +8,14 @@
|
||||
|
||||
namespace nostalgia::gfx {
|
||||
|
||||
gfx::DeleteTilesCommand::DeleteTilesCommand(
|
||||
DeleteTilesCommand::DeleteTilesCommand(
|
||||
TileSheet &img,
|
||||
TileSheet::SubSheetIdx idx,
|
||||
std::size_t tileIdx,
|
||||
std::size_t tileCnt) noexcept:
|
||||
std::size_t const tileIdx,
|
||||
std::size_t const tileCnt) noexcept:
|
||||
m_img(img),
|
||||
m_idx(std::move(idx)) {
|
||||
const unsigned bytesPerTile = m_img.bpp == 4 ? PixelsPerTile / 2 : PixelsPerTile;
|
||||
constexpr unsigned bytesPerTile = PixelsPerTile;
|
||||
m_deletePos = tileIdx * bytesPerTile;
|
||||
m_deleteSz = tileCnt * bytesPerTile;
|
||||
m_deletedPixels.resize(m_deleteSz);
|
||||
@ -28,15 +28,21 @@ gfx::DeleteTilesCommand::DeleteTilesCommand(
|
||||
}
|
||||
}
|
||||
|
||||
ox::Error gfx::DeleteTilesCommand::redo() noexcept {
|
||||
ox::Error DeleteTilesCommand::redo() noexcept {
|
||||
auto &s = getSubSheet(m_img, m_idx);
|
||||
auto &p = s.pixels;
|
||||
auto srcPos = m_deletePos + m_deleteSz;
|
||||
auto const src = &p[srcPos];
|
||||
auto const srcPos = m_deletePos + m_deleteSz;
|
||||
auto const dst1 = &p[m_deletePos];
|
||||
auto const dst2 = &p[(p.size() - m_deleteSz)];
|
||||
ox::memmove(dst1, src, p.size() - srcPos);
|
||||
ox::memset(dst2, 0, m_deleteSz * sizeof(decltype(p[0])));
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
if (srcPos < p.size()) {
|
||||
auto const src = &p[srcPos];
|
||||
ox::memmove(dst1, src, p.size() - srcPos);
|
||||
ox::memset(dst2, 0, m_deleteSz * sizeof(decltype(p[0])));
|
||||
} else {
|
||||
ox::memset(dst1, 0, p.size() - m_deletePos);
|
||||
}
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
return {};
|
||||
}
|
||||
|
||||
@ -44,11 +50,16 @@ ox::Error DeleteTilesCommand::undo() noexcept {
|
||||
auto &s = getSubSheet(m_img, m_idx);
|
||||
auto &p = s.pixels;
|
||||
auto const src = &p[m_deletePos];
|
||||
auto const dst1 = &p[m_deletePos + m_deleteSz];
|
||||
auto const dst2 = src;
|
||||
auto const sz = p.size() - m_deletePos - m_deleteSz;
|
||||
ox::memmove(dst1, src, sz);
|
||||
auto const srcPos = m_deletePos + m_deleteSz;
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
if (srcPos < p.size()) {
|
||||
auto const dst1 = &p[m_deletePos + m_deleteSz];
|
||||
ox::memmove(dst1, src, sz);
|
||||
}
|
||||
auto const dst2 = src;
|
||||
ox::memcpy(dst2, m_deletedPixels.data(), m_deletedPixels.size());
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
return {};
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#include "flipcommand.hpp"
|
||||
|
||||
#include <utility>
|
||||
|
||||
namespace nostalgia::gfx {
|
||||
|
||||
FlipXCommand::FlipXCommand(
|
||||
TileSheet &img,
|
||||
TileSheet::SubSheetIdx subSheetIdx,
|
||||
ox::Point const &a,
|
||||
ox::Point const &b) noexcept:
|
||||
m_img{img},
|
||||
m_subSheetIdx{std::move(subSheetIdx)},
|
||||
m_ptA{a},
|
||||
m_ptB{b} {}
|
||||
|
||||
ox::Error FlipXCommand::redo() noexcept {
|
||||
auto &ss = getSubSheet(m_img, m_subSheetIdx);
|
||||
flipX(ss, m_ptA, m_ptB);
|
||||
return {};
|
||||
}
|
||||
|
||||
ox::Error FlipXCommand::undo() noexcept {
|
||||
auto &ss = getSubSheet(m_img, m_subSheetIdx);
|
||||
flipX(ss, m_ptA, m_ptB);
|
||||
return {};
|
||||
}
|
||||
|
||||
int FlipXCommand::commandId() const noexcept {
|
||||
return static_cast<int>(CommandId::FlipX);
|
||||
}
|
||||
|
||||
TileSheet::SubSheetIdx const &FlipXCommand::subsheetIdx() const noexcept {
|
||||
return m_subSheetIdx;
|
||||
}
|
||||
|
||||
|
||||
FlipYCommand::FlipYCommand(
|
||||
TileSheet &img,
|
||||
TileSheet::SubSheetIdx subSheetIdx,
|
||||
ox::Point const &a,
|
||||
ox::Point const &b) noexcept:
|
||||
m_img{img},
|
||||
m_subSheetIdx{std::move(subSheetIdx)},
|
||||
m_ptA{a},
|
||||
m_ptB{b} {}
|
||||
|
||||
ox::Error FlipYCommand::redo() noexcept {
|
||||
auto &ss = getSubSheet(m_img, m_subSheetIdx);
|
||||
flipY(ss, m_ptA, m_ptB);
|
||||
return {};
|
||||
}
|
||||
|
||||
ox::Error FlipYCommand::undo() noexcept {
|
||||
auto &ss = getSubSheet(m_img, m_subSheetIdx);
|
||||
flipY(ss, m_ptA, m_ptB);
|
||||
return {};
|
||||
}
|
||||
|
||||
int FlipYCommand::commandId() const noexcept {
|
||||
return static_cast<int>(CommandId::FlipY);
|
||||
}
|
||||
|
||||
TileSheet::SubSheetIdx const &FlipYCommand::subsheetIdx() const noexcept {
|
||||
return m_subSheetIdx;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "commands.hpp"
|
||||
|
||||
namespace nostalgia::gfx {
|
||||
|
||||
class FlipXCommand: public TileSheetCommand {
|
||||
private:
|
||||
TileSheet &m_img;
|
||||
TileSheet::SubSheetIdx m_subSheetIdx;
|
||||
ox::Point const m_ptA;
|
||||
ox::Point const m_ptB;
|
||||
|
||||
public:
|
||||
FlipXCommand(
|
||||
TileSheet &img,
|
||||
TileSheet::SubSheetIdx subSheetIdx,
|
||||
ox::Point const &a,
|
||||
ox::Point const &b) 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;
|
||||
|
||||
};
|
||||
|
||||
class FlipYCommand: public TileSheetCommand {
|
||||
private:
|
||||
TileSheet &m_img;
|
||||
TileSheet::SubSheetIdx m_subSheetIdx;
|
||||
ox::Point const m_ptA;
|
||||
ox::Point const m_ptB;
|
||||
|
||||
public:
|
||||
FlipYCommand(
|
||||
TileSheet &img,
|
||||
TileSheet::SubSheetIdx subSheetIdx,
|
||||
ox::Point const &a,
|
||||
ox::Point const &b) 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;
|
||||
|
||||
};
|
||||
|
||||
}
|
@ -9,28 +9,29 @@ namespace nostalgia::gfx {
|
||||
InsertTilesCommand::InsertTilesCommand(
|
||||
TileSheet &img,
|
||||
TileSheet::SubSheetIdx idx,
|
||||
std::size_t tileIdx,
|
||||
std::size_t tileCnt) noexcept:
|
||||
m_img(img),
|
||||
m_idx(std::move(idx)) {
|
||||
const unsigned bytesPerTile = m_img.bpp == 4 ? PixelsPerTile / 2 : PixelsPerTile;
|
||||
m_insertPos = tileIdx * bytesPerTile;
|
||||
m_insertCnt = tileCnt * bytesPerTile;
|
||||
std::size_t const tileIdx,
|
||||
std::size_t const tileCnt) noexcept:
|
||||
m_img{img},
|
||||
m_idx{std::move(idx)} {
|
||||
m_insertPos = tileIdx * PixelsPerTile;
|
||||
m_insertCnt = tileCnt * PixelsPerTile;
|
||||
m_deletedPixels.resize(m_insertCnt);
|
||||
// copy pixels to be erased
|
||||
{
|
||||
auto &s = getSubSheet(m_img, m_idx);
|
||||
auto &p = s.pixels;
|
||||
auto dst = m_deletedPixels.begin();
|
||||
auto src = p.begin() + p.size() - m_insertCnt;
|
||||
auto const dst = m_deletedPixels.begin();
|
||||
auto const src = p.begin() + p.size() - m_insertCnt;
|
||||
ox::copy_n(src, m_insertCnt, dst);
|
||||
}
|
||||
}
|
||||
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
|
||||
ox::Error InsertTilesCommand::redo() noexcept {
|
||||
auto &s = getSubSheet(m_img, m_idx);
|
||||
auto &p = s.pixels;
|
||||
auto dstPos = m_insertPos + m_insertCnt;
|
||||
auto const dstPos = m_insertPos + m_insertCnt;
|
||||
auto const src = &p[m_insertPos];
|
||||
if (dstPos < p.size()) {
|
||||
auto const dst = &p[dstPos];
|
||||
@ -55,6 +56,8 @@ ox::Error InsertTilesCommand::undo() noexcept {
|
||||
return {};
|
||||
}
|
||||
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
|
||||
int InsertTilesCommand::commandId() const noexcept {
|
||||
return static_cast<int>(CommandId::InsertTile);
|
||||
}
|
||||
|
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#include "movesubsheetcommand.hpp"
|
||||
|
||||
namespace nostalgia::gfx {
|
||||
|
||||
MoveSubSheetCommand::MoveSubSheetCommand(
|
||||
TileSheet &img,
|
||||
TileSheet::SubSheetIdx src,
|
||||
TileSheet::SubSheetIdx dst) noexcept:
|
||||
m_img{img},
|
||||
m_src{std::move(src)},
|
||||
m_dst{std::move(dst)} {
|
||||
}
|
||||
|
||||
ox::Error MoveSubSheetCommand::redo() noexcept {
|
||||
m_active = &m_dst;
|
||||
TileSheet::SubSheet ss = std::move(getSubSheet(m_img, m_src));
|
||||
OX_RETURN_ERROR(rmSubSheet(m_img, m_src));
|
||||
return insertSubSheet(m_img, m_dst, std::move(ss));
|
||||
}
|
||||
|
||||
ox::Error MoveSubSheetCommand::undo() noexcept {
|
||||
m_active = &m_src;
|
||||
TileSheet::SubSheet ss = std::move(getSubSheet(m_img, m_dst));
|
||||
OX_RETURN_ERROR(rmSubSheet(m_img, m_dst));
|
||||
return insertSubSheet(m_img, m_src, std::move(ss));
|
||||
}
|
||||
|
||||
int MoveSubSheetCommand::commandId() const noexcept {
|
||||
return static_cast<int>(CommandId::MoveSubSheet);
|
||||
}
|
||||
|
||||
TileSheet::SubSheetIdx const&MoveSubSheetCommand::subsheetIdx() const noexcept {
|
||||
return *m_active;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "commands.hpp"
|
||||
|
||||
namespace nostalgia::gfx {
|
||||
|
||||
class MoveSubSheetCommand: public TileSheetCommand {
|
||||
private:
|
||||
TileSheet &m_img;
|
||||
TileSheet::SubSheetIdx m_src;
|
||||
TileSheet::SubSheetIdx m_dst;
|
||||
TileSheet::SubSheetIdx *m_active = &m_dst;
|
||||
|
||||
public:
|
||||
MoveSubSheetCommand(TileSheet &img, TileSheet::SubSheetIdx src, TileSheet::SubSheetIdx dst) 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;
|
||||
|
||||
};
|
||||
|
||||
}
|
@ -6,14 +6,14 @@
|
||||
|
||||
namespace nostalgia::gfx {
|
||||
|
||||
gfx::PaletteChangeCommand::PaletteChangeCommand(
|
||||
PaletteChangeCommand::PaletteChangeCommand(
|
||||
TileSheet::SubSheetIdx idx,
|
||||
TileSheet &img,
|
||||
ox::StringViewCR newPalette) noexcept:
|
||||
m_img(img),
|
||||
m_idx(std::move(idx)),
|
||||
m_oldPalette(m_img.defaultPalette),
|
||||
m_newPalette(ox::sfmt<ox::IString<43>>("uuid://{}", newPalette)) {
|
||||
m_img{img},
|
||||
m_idx{std::move(idx)},
|
||||
m_oldPalette{m_img.defaultPalette},
|
||||
m_newPalette{ox::sfmt<ox::IString<43>>("uuid://{}", newPalette)} {
|
||||
}
|
||||
|
||||
ox::Error PaletteChangeCommand::redo() noexcept {
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
namespace nostalgia::gfx {
|
||||
|
||||
gfx::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;
|
||||
|
||||
};
|
||||
|
||||
}
|
@ -6,7 +6,7 @@
|
||||
|
||||
namespace nostalgia::gfx {
|
||||
|
||||
gfx::UpdateSubSheetCommand::UpdateSubSheetCommand(
|
||||
UpdateSubSheetCommand::UpdateSubSheetCommand(
|
||||
TileSheet &img,
|
||||
TileSheet::SubSheetIdx idx,
|
||||
ox::StringParam name,
|
||||
|
@ -15,6 +15,16 @@ namespace nostalgia::gfx {
|
||||
|
||||
namespace ig = studio::ig;
|
||||
|
||||
struct SubSheetRef {
|
||||
static constexpr auto TypeName = "nostalgia.gfx.studio.SubSheetRef";
|
||||
static constexpr auto TypeVersion = 1;
|
||||
TileSheet::SubSheetIdx subsheet{};
|
||||
};
|
||||
|
||||
OX_MODEL_BEGIN(SubSheetRef)
|
||||
OX_MODEL_FIELD(subsheet)
|
||||
OX_MODEL_END()
|
||||
|
||||
struct TileSheetEditorConfig {
|
||||
static constexpr auto TypeName = "net.drinkingtea.nostalgia.gfx.studio.TileSheetEditorConfig";
|
||||
static constexpr auto TypeVersion = 1;
|
||||
@ -26,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;
|
||||
}
|
||||
@ -70,8 +71,8 @@ static ox::Error toPngFile(
|
||||
ox::Vector<uint32_t> &&pixels,
|
||||
Palette const&pal,
|
||||
size_t page,
|
||||
unsigned width,
|
||||
unsigned height) noexcept {
|
||||
unsigned const width,
|
||||
unsigned const height) noexcept {
|
||||
for (auto &c : pixels) {
|
||||
c = color32(color(pal, page, c)) | static_cast<Color32>(0XFF << 24);
|
||||
}
|
||||
@ -86,17 +87,16 @@ static ox::Error toPngFile(
|
||||
8)));
|
||||
}
|
||||
|
||||
TileSheetEditorImGui::TileSheetEditorImGui(studio::StudioContext &sctx, ox::StringParam path):
|
||||
Editor(std::move(path)),
|
||||
m_sctx(sctx),
|
||||
m_tctx(m_sctx.tctx),
|
||||
m_view(m_sctx, itemPath(), *undoStack()),
|
||||
m_model(m_view.model()) {
|
||||
std::ignore = setPaletteSelection();
|
||||
TileSheetEditorImGui::TileSheetEditorImGui(studio::Context &sctx, ox::StringParam path):
|
||||
Editor(sctx, std::move(path)),
|
||||
m_sctx{sctx},
|
||||
m_tctx{m_sctx.tctx},
|
||||
m_palPicker{"Palette Chooser", keelCtx(sctx), FileExt_npal},
|
||||
m_view{m_sctx, itemPath(), *undoStack()},
|
||||
m_model{m_view.model()} {
|
||||
// connect signal/slots
|
||||
m_subsheetEditor.inputSubmitted.connect(this, &TileSheetEditorImGui::updateActiveSubsheet);
|
||||
m_exportMenu.inputSubmitted.connect(this, &TileSheetEditorImGui::exportSubhseetToPng);
|
||||
m_model.paletteChanged.connect(this, &TileSheetEditorImGui::setPaletteSelection);
|
||||
m_exportMenu.inputSubmitted.connect(this, &TileSheetEditorImGui::exportSubsheetToPng);
|
||||
// load config
|
||||
auto const&config = studio::readConfig<TileSheetEditorConfig>(
|
||||
keelCtx(m_sctx), itemPath());
|
||||
@ -125,17 +125,17 @@ bool TileSheetEditorImGui::acceptsClipboardPayload() const noexcept {
|
||||
return m_model.acceptsClipboardPayload();
|
||||
}
|
||||
|
||||
void TileSheetEditorImGui::keyStateChanged(turbine::Key key, bool down) {
|
||||
void TileSheetEditorImGui::keyStateChanged(turbine::Key const key, bool const down) {
|
||||
if (!down) {
|
||||
return;
|
||||
}
|
||||
if (key == turbine::Key::Escape) {
|
||||
if (ig::mainWinHasFocus() && key == turbine::Key::Escape) {
|
||||
m_subsheetEditor.close();
|
||||
m_exportMenu.close();
|
||||
m_palPicker.close();
|
||||
}
|
||||
auto const popupOpen = m_subsheetEditor.isOpen() || m_exportMenu.isOpen();
|
||||
auto const pal = m_model.pal();
|
||||
if (!popupOpen) {
|
||||
if (ig::mainWinHasFocus() && !m_palPathFocused) {
|
||||
auto const colorCnt = gfx::colorCnt(pal, m_model.palettePage());
|
||||
if (key == turbine::Key::Alpha_D) {
|
||||
m_tool = TileSheetTool::Draw;
|
||||
@ -143,6 +143,12 @@ void TileSheetEditorImGui::keyStateChanged(turbine::Key key, bool down) {
|
||||
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);
|
||||
@ -182,10 +188,9 @@ void TileSheetEditorImGui::keyStateChanged(turbine::Key key, bool down) {
|
||||
}
|
||||
}
|
||||
|
||||
void TileSheetEditorImGui::draw(studio::StudioContext&) noexcept {
|
||||
auto const popupOpen = m_subsheetEditor.isOpen() || m_exportMenu.isOpen();
|
||||
if (!popupOpen && m_tool == TileSheetTool::Select) {
|
||||
if (ImGui::IsKeyDown(ImGuiKey_ModCtrl)) {
|
||||
void TileSheetEditorImGui::draw(studio::Context&) noexcept {
|
||||
if (ig::mainWinHasFocus() && m_tool == TileSheetTool::Select) {
|
||||
if (ImGui::IsKeyDown(ImGuiKey_ModCtrl) && !m_palPathFocused) {
|
||||
if (ImGui::IsKeyPressed(ImGuiKey_A)) {
|
||||
auto const&img = m_model.activeSubSheet();
|
||||
m_model.setSelection({{}, {img.columns * TileWidth - 1, img.rows * TileHeight - 1}});
|
||||
@ -206,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)) {
|
||||
@ -222,9 +227,38 @@ 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();
|
||||
auto const ySize = controlsSize.y - 38;
|
||||
ImGui::BeginChild("OperationsBox", {0, 35}, ImGuiWindowFlags_NoTitleBar);
|
||||
{
|
||||
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();
|
||||
auto const ySize = controlsSize.y - (38 + ig::BtnSz.y + 21);
|
||||
// draw palette/color picker
|
||||
ImGui::BeginChild("Palette", {s_palViewWidth - 24, ySize / 2.f}, true);
|
||||
{
|
||||
@ -277,6 +311,11 @@ void TileSheetEditorImGui::draw(studio::StudioContext&) noexcept {
|
||||
ImGui::EndChild();
|
||||
m_subsheetEditor.draw(m_tctx);
|
||||
m_exportMenu.draw(m_tctx);
|
||||
if (auto pal = m_palPicker.draw(m_sctx)) {
|
||||
if (*pal != m_model.palPath()) {
|
||||
oxLogError(m_model.setPalette(*pal));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TileSheetEditorImGui::drawSubsheetSelector(
|
||||
@ -294,6 +333,16 @@ void TileSheetEditorImGui::drawSubsheetSelector(
|
||||
| (rowSelected ? ImGuiTreeNodeFlags_Selected : 0);
|
||||
ImGui::TableNextColumn();
|
||||
auto const open = ImGui::TreeNodeEx(lbl.c_str(), flags);
|
||||
std::ignore = ig::dragDropSource([&subsheet, &path] {
|
||||
ImGui::Text("%s", subsheet.name.c_str());
|
||||
return ig::setDragDropPayload(SubSheetRef{path});
|
||||
});
|
||||
if (ig::DragDropTarget const dragDropTarget; dragDropTarget) {
|
||||
auto const [ref, err] = ig::getDragDropPayload<SubSheetRef>();
|
||||
if (!err) {
|
||||
oxLogError(m_model.moveSubSheet(ref.subsheet, path));
|
||||
}
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if (ImGui::IsItemClicked()) {
|
||||
setActiveSubsheet(path);
|
||||
@ -315,7 +364,7 @@ void TileSheetEditorImGui::drawSubsheetSelector(
|
||||
ImGui::Text("--");
|
||||
}
|
||||
if (open) {
|
||||
for (auto i = 0ul; auto &child : subsheet.subsheets) {
|
||||
for (uint32_t i{}; auto &child : subsheet.subsheets) {
|
||||
path.push_back(i);
|
||||
ImGui::PushID(static_cast<int>(i));
|
||||
ig::IndentStackItem const indentStackItem{-indentReduce};
|
||||
@ -348,15 +397,14 @@ void TileSheetEditorImGui::showSubsheetEditor() noexcept {
|
||||
}
|
||||
}
|
||||
|
||||
ox::Error TileSheetEditorImGui::exportSubhseetToPng(int const scale) const noexcept {
|
||||
ox::Error TileSheetEditorImGui::exportSubsheetToPng(int const scale) const noexcept {
|
||||
OX_REQUIRE(path, studio::saveFile({{"PNG", "png"}}));
|
||||
// subsheet to png
|
||||
auto const&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,
|
||||
@ -366,7 +414,7 @@ ox::Error TileSheetEditorImGui::exportSubhseetToPng(int const scale) const noexc
|
||||
static_cast<unsigned>(width * scale),
|
||||
static_cast<unsigned>(height * scale));
|
||||
if (err) {
|
||||
oxErrorf("Tilesheet export failed: {}", toStr(err));
|
||||
oxErrorf("TileSheet export failed: {}", toStr(err));
|
||||
}
|
||||
return err;
|
||||
}
|
||||
@ -412,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;
|
||||
@ -437,20 +488,26 @@ void TileSheetEditorImGui::drawTileSheet(ox::Vec2 const&fbSize) noexcept {
|
||||
}
|
||||
|
||||
void TileSheetEditorImGui::drawPaletteMenu() noexcept {
|
||||
ig::IDStackItem const idStackItem{"PaletteMenu"};
|
||||
auto constexpr comboWidthSub = 62;
|
||||
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x - comboWidthSub);
|
||||
auto constexpr palTags = ImGuiInputTextFlags_ReadOnly;
|
||||
if (ig::InputText("Palette", m_selectedPalette, palTags)) {
|
||||
oxLogError(m_model.setPalette(m_selectedPalette));
|
||||
if (ig::InputTextWithHint("##Palette", "Path to Palette", m_model.palPath(), palTags)) {
|
||||
oxLogError(m_model.setPalette(m_model.palPath()));
|
||||
}
|
||||
m_palPathFocused = ImGui::IsItemFocused();
|
||||
if (ig::DragDropTarget const dragDropTarget; dragDropTarget) {
|
||||
auto const [ref, err] = ig::getDragDropPayload<studio::FileRef>("FileRef");
|
||||
if (!err && endsWith(ref.path, FileExt_npal)) {
|
||||
if (ref.path != m_selectedPalette) {
|
||||
if (ref.path != m_model.palPath()) {
|
||||
oxLogError(m_model.setPalette(ref.path));
|
||||
}
|
||||
}
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("Browse")) {
|
||||
m_palPicker.open();
|
||||
}
|
||||
auto const pages = m_model.pal().pages.size();
|
||||
if (pages > 1) {
|
||||
ig::IndentStackItem const indentStackItem{20};
|
||||
@ -492,15 +549,21 @@ void TileSheetEditorImGui::drawPaletteMenu() noexcept {
|
||||
ImGui::PushID(static_cast<int>(i));
|
||||
// Column: color idx
|
||||
ImGui::TableNextColumn();
|
||||
auto const label = ox::itoa(i + 1);
|
||||
auto const label = ox::intToStr(i + 1);
|
||||
auto const rowSelected = i == m_view.palIdx();
|
||||
if (ImGui::Selectable(
|
||||
label.c_str(), rowSelected, ImGuiSelectableFlags_SpanAllColumns)) {
|
||||
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() : "";
|
||||
@ -516,15 +579,11 @@ void TileSheetEditorImGui::drawPaletteMenu() noexcept {
|
||||
}
|
||||
}
|
||||
|
||||
ox::Error TileSheetEditorImGui::updateActiveSubsheet(ox::StringView const&name, int cols, int rows) noexcept {
|
||||
ox::Error TileSheetEditorImGui::updateActiveSubsheet(
|
||||
ox::StringView const&name, int const cols, int const rows) noexcept {
|
||||
return m_model.updateSubsheet(m_model.activeSubSheetIdx(), name, cols, rows);
|
||||
}
|
||||
|
||||
ox::Error TileSheetEditorImGui::setPaletteSelection() noexcept {
|
||||
m_selectedPalette = m_model.palPath();
|
||||
return {};
|
||||
}
|
||||
|
||||
void TileSheetEditorImGui::setActiveSubsheet(TileSheet::SubSheetIdx path) noexcept {
|
||||
m_model.setActiveSubsheet(path);
|
||||
studio::editConfig<TileSheetEditorConfig>(keelCtx(m_sctx), itemPath(),
|
||||
@ -583,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);
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user