Compare commits

...

107 Commits

Author SHA1 Message Date
65df731abb [buildcore] Make pybb cmake_build specify --config debug/release
All checks were successful
Build / build (push) Successful in 1m20s
2025-05-22 20:48:53 -05:00
a098cb5ce7 [nostalgia] Update release-d2025.05.2 release notes
All checks were successful
Build / build (push) Successful in 1m22s
2025-05-22 20:46:56 -05:00
8c0b0263db [ox/fs] Fix new build error in MSVC (VS 17.14) 2025-05-22 20:06:36 -05:00
7f6c453345 [nostalgia/studio] Bump version to d2025.05.1
All checks were successful
Build / build (push) Successful in 1m14s
2025-05-21 22:20:56 -05:00
261e324acd [nostalgia/gfx/studio/tilesheet] Fix overrun errors when switching subsheets, clear selection on switch 2025-05-21 22:17:28 -05:00
f5573e06da [nostalgia/studio] Set version to d2025.05.0
All checks were successful
Build / build (push) Successful in 1m13s
2025-05-10 00:23:30 -05:00
df87832324 [studio] Add build date to About
All checks were successful
Build / build (push) Successful in 1m15s
2025-05-10 00:21:54 -05:00
d585794cbe [nostalgia/gfx/studio/tilesheet] Fix Insert tile command 2025-05-09 20:34:42 -05:00
209658549c [nostalgia/gfx/studio/tilesheet] Cleanup 2025-05-09 20:34:04 -05:00
02383a4aed [ox/std] Cleanup 2025-05-09 01:22:29 -05:00
185a76282a [nostalgia] Make pkg-dmg delete bundle after archive created
All checks were successful
Build / build (push) Successful in 1m15s
2025-05-08 23:29:36 -05:00
b722b4f701 [nostalgia] Update release notes
Some checks failed
Build / build (push) Has been cancelled
2025-05-08 23:28:58 -05:00
459ab5aad9 [studio] Remove ability to re-order Editor tabs 2025-05-08 23:28:51 -05:00
565f621cfc [nostalgia/gfx/studio/tilesheet] Fix Delete Tile functionality
All checks were successful
Build / build (push) Successful in 1m15s
2025-05-08 01:57:59 -05:00
9589ca9148 [keel] Cleanup 2025-05-08 01:37:18 -05:00
164db5007b [keel] Cleanup
All checks were successful
Build / build (push) Successful in 1m25s
2025-05-08 00:49:50 -05:00
cbfb167d29 [nostalgia] Remove unused project directory
All checks were successful
Build / build (push) Successful in 1m33s
2025-05-07 20:23:48 -05:00
e7b83be867 [nostalgia] Update release notes
All checks were successful
Build / build (push) Successful in 2m28s
2025-05-07 20:18:08 -05:00
649da5fca8 [nostalgia/sample_project] Delete Scenes directory 2025-05-07 20:16:35 -05:00
aa095f7680 [studio] Make Delete key initiate deletion of selected directory 2025-05-07 20:15:38 -05:00
bb99c99f01 [studio] Make deleting a directory close files in that directory 2025-05-07 20:10:34 -05:00
7f0dcdd280 [nostalgia/gfx/studio/tilesheet] Cleanup
All checks were successful
Build / build (push) Successful in 1m20s
2025-05-07 19:57:27 -05:00
6029ad5d47 [nostalgia/studio] Add command for bundling Mac app 2025-05-07 02:48:14 -05:00
26fe266b09 [ox/mc] Fix break from using strnlen_s inappropriately
All checks were successful
Build / build (push) Successful in 1m16s
2025-05-07 01:18:14 -05:00
091eda7b44 Merge commit 'ce53be92716b0f5201882d6959c398b61c6cc93c'
All checks were successful
Build / build (push) Successful in 1m23s
2025-05-07 00:12:52 -05:00
9676ea5978 [turbine/glfw] Fix programmatic shutdown to invoke shutdownHandler
All checks were successful
Build / build (push) Successful in 1m50s
2025-05-07 00:06:21 -05:00
de8ac10653 [turbine/glfw] Fix closing when no shutdown handler is set
All checks were successful
Build / build (push) Successful in 1m53s
2025-05-07 00:01:49 -05:00
88a6cd59f3 [turbine/glfw] Treat close window event like other events with regard to a mandatory refresh period
Some checks are pending
Build / build (push) Waiting to run
2025-05-06 23:56:49 -05:00
cd43fb7f38 [turbine,studio] Fix confirm app close pop up to work with Ctrl-Q
All checks were successful
Build / build (push) Successful in 2m1s
2025-05-06 23:25:00 -05:00
136f422401 [nostalgia] Update release notes
All checks were successful
Build / build (push) Successful in 1m16s
2025-05-06 23:11:06 -05:00
e773d6f0ee [studio] Rename StudioContext to Context
All checks were successful
Build / build (push) Successful in 1m16s
2025-05-06 22:37:21 -05:00
7da2f68d30 [nostalgia/sample_project] Add assets
All checks were successful
Build / build (push) Successful in 1m22s
2025-05-06 22:30:28 -05:00
d20889aef1 [nostalgia/gfx/studio] Update for Ox changes 2025-05-06 22:29:51 -05:00
50c8302f4a [ox] Rename itoa to intToStr 2025-05-06 22:29:31 -05:00
d8195d300d [olympic,nostalgia] Address unsafe buffer warnings 2025-05-06 22:25:36 -05:00
a8c1387d5a [ox] Address unsafe buffer warnings 2025-05-06 22:25:13 -05:00
ff1e8f260b [studio] Add popup to warn about UUID duplication 2025-05-06 22:22:26 -05:00
d4329981e7 [studio,nostalgia] Cleanup
All checks were successful
Build / build (push) Successful in 1m14s
2025-05-06 01:11:47 -05:00
0003454311 [studio,nostalgia/gfx/studio] Cleanup
All checks were successful
Build / build (push) Successful in 1m14s
2025-05-06 01:00:04 -05:00
8c6b2234ec [olympic/util] Make pkg-gba script check return code of subprocesses
All checks were successful
Build / build (push) Successful in 1m14s
2025-05-05 23:11:37 -05:00
aad4b8a44c [studio] Cleanup 2025-05-05 23:10:18 -05:00
7cab133127 [keel] Add ability to log UUID duplication
All checks were successful
Build / build (push) Successful in 1m14s
2025-05-05 21:54:24 -05:00
640ac85de4 [nostalgia/gfx/studio/palette] Make page rename dialog accept on enter if input focused
All checks were successful
Build / build (push) Successful in 1m19s
2025-05-04 00:15:30 -05:00
b8d7658626 [nostalgia/studio] Update generated icondata.cpp with Clang fix
All checks were successful
Build / build (push) Successful in 1m26s
2025-05-02 21:05:21 -05:00
2503bb3b2c [nostalgia/sample_project] Update type descriptors 2025-05-02 21:04:36 -05:00
e5dd448fe7 [turbine,studio] Make Studio confirm with user before closing app if any unsaved changes
All checks were successful
Build / build (push) Successful in 1m15s
2025-05-01 23:15:06 -05:00
4770bb6a93 [olympic/util] Cleanup
All checks were successful
Build / build (push) Successful in 1m17s
2025-04-20 21:44:36 -05:00
c0bac696dc [nostalgia/gfx/studio/paletteeditor] Fix color number key range
All checks were successful
Build / build (push) Successful in 1m16s
2025-04-19 14:43:07 -05:00
95f7c33419 [studio] Change Studio font
All checks were successful
Build / build (push) Successful in 1m16s
2025-04-19 00:23:36 -05:00
535d8876d3 [keel] Cleanup 2025-04-19 00:22:28 -05:00
845e433221 [turbine] Fix Mac build 2025-04-18 01:38:32 -05:00
5169a607cf [turbine] Disable useless window icon on Mac, it causes GLFW warning
All checks were successful
Build / build (push) Successful in 1m16s
2025-04-17 21:36:56 -05:00
8f03af99a7 [keel] Style updates 2025-04-17 21:36:24 -05:00
ee63a4a1e4 [keel] Cleanup
All checks were successful
Build / build (push) Successful in 1m17s
2025-04-17 21:04:43 -05:00
ac29f7a0f2 Merge commit 'ec6cf92c4763be5933ee6debbf97bce25b9fcfc9' 2025-04-17 20:12:48 -05:00
89ae226b1d [keel] Improve correctness
All checks were successful
Build / build (push) Successful in 1m18s
2025-04-17 01:17:40 -05:00
477834ac04 [keel] Cleanup
All checks were successful
Build / build (push) Successful in 1m16s
2025-04-17 01:06:08 -05:00
97b707b61c [keel] Fix MSVC build
All checks were successful
Build / build (push) Successful in 1m16s
2025-04-17 01:01:22 -05:00
e86180e842 [nostalgia/core/keel] Consistency cleanup
All checks were successful
Build / build (push) Successful in 1m16s
2025-04-17 00:39:34 -05:00
035ba8810f [keel,nostalgia] Fix converter type names 2025-04-17 00:37:05 -05:00
f1c2113dd3 [keel] Fix some completely incomprehensible build break in GCC12...
All checks were successful
Build / build (push) Successful in 1m16s
2025-04-17 00:32:38 -05:00
56b79f414d [keel,nostalgia] Further simplify writing type converters
Some checks failed
Build / build (push) Failing after 14s
2025-04-17 00:22:47 -05:00
844656d557 [nostalgia/gfx/keel] Update type converter style
All checks were successful
Build / build (push) Successful in 1m14s
2025-04-16 23:12:24 -05:00
849aceb86d [keel] Add cleaner way to write type converters 2025-04-16 23:11:47 -05:00
eef51a6d2b [olympic] Improve error handling in file-to-cpp 2025-04-16 20:11:28 -05:00
c84b85102c [nostalgia/gfx/studio] Cleanup
All checks were successful
Build / build (push) Successful in 1m15s
2025-04-15 22:05:46 -05:00
3fe62464c3 [nostalgia/sample_project] Add NS_Logo32
All checks were successful
Build / build (push) Successful in 1m18s
2025-04-14 22:20:06 -05:00
db55fc722f [nostalgia/player] Cleanup 2025-04-14 22:05:23 -05:00
2094450898 [studio] Cleanup
All checks were successful
Build / build (push) Successful in 1m22s
2025-04-14 22:00:05 -05:00
889bec04b1 [nostalgia/gfx/studio/tilesheet] Cleanup 2025-04-13 23:20:49 -05:00
ac1e34d4cd [nostalgia] Update release notes
All checks were successful
Build / build (push) Successful in 1m19s
2025-04-13 00:37:32 -05:00
55ed75f44d [nostalgia/gfx/studio/tilesheet] Fix selection clearing to work when clicking outside image
All checks were successful
Build / build (push) Successful in 1m19s
2025-04-13 00:33:06 -05:00
2751872c59 [nostalgia] Cleanup file-to-cpp output
All checks were successful
Build / build (push) Successful in 1m15s
2025-04-12 16:50:09 -05:00
2a3cd35cc4 [nostalgia] Fix release notes version, add d2025.02.1
Some checks are pending
Build / build (push) Waiting to run
2025-04-12 16:45:58 -05:00
b66f459f75 [nostalgia] Cleanup icon rsrc generation
Some checks are pending
Build / build (push) Waiting to run
2025-04-12 16:40:49 -05:00
3910f4e77c [nostalgia] Fix debug and gba-run commands in Makefile
Some checks are pending
Build / build (push) Waiting to run
2025-04-12 14:04:41 -05:00
c0e96216ae [turbine] Make accessor functions take const ref to Context
Some checks are pending
Build / build (push) Waiting to run
2025-04-12 13:49:43 -05:00
f9512d72e8 [turbine/glfw] Fix implicit conversion
Some checks are pending
Build / build (push) Waiting to run
2025-04-12 00:22:49 -05:00
b7f2c169ec [nostalgia/studio/gfx] Fix typo
Some checks are pending
Build / build (push) Waiting to run
2025-04-11 23:14:57 -05:00
1e5057d6e6 [nostalgia] Add app icon note to release notes
Some checks are pending
Build / build (push) Waiting to run
2025-04-11 23:12:36 -05:00
c6255e3224 [nostalgia/studio] Add icon 16 src
Some checks are pending
Build / build (push) Waiting to run
2025-04-11 23:06:42 -05:00
02230ef619 [turbine,studio,nostalgia/studio] Add support for window icon scaling, expand icons sizes for Nostalgia Studio
Some checks are pending
Build / build (push) Waiting to run
2025-04-11 22:45:11 -05:00
9b6b60e4d1 [turbine] Cleanup
Some checks are pending
Build / build (push) Waiting to run
2025-04-11 21:47:26 -05:00
b9a26ab61e [turbine] Fix GLFWimage member init order
Some checks are pending
Build / build (push) Waiting to run
2025-04-11 21:44:52 -05:00
a521887ddd [studio,turbine] Add support for window icons
Some checks are pending
Build / build (push) Waiting to run
2025-04-11 21:41:30 -05:00
5ca7e2f226 [ox/fs] Cleanup
All checks were successful
Build / build (push) Successful in 1m14s
2025-04-02 01:30:58 -05:00
125a235dd1 [ox/fs] Cleanup
All checks were successful
Build / build (push) Successful in 1m26s
2025-04-02 01:29:02 -05:00
91a7129f8f [nostalgia/gfx/keel] Cleanup 2025-04-02 01:07:26 -05:00
df48a232ec [nostalgia/studio] Add icon to Windows executable
All checks were successful
Build / build (push) Successful in 1m28s
2025-04-02 00:49:13 -05:00
ab11b885e6 [keel] Add missing new line to log message
All checks were successful
Build / build (push) Successful in 1m25s
2025-03-24 21:02:20 -05:00
36fc25fb7e [studio] Fix closing tab with unsaved changes 2025-03-24 21:02:20 -05:00
4803cca334 [nostalgia/player] Cleanup
All checks were successful
Build / build (push) Successful in 1m29s
2025-03-08 22:28:29 -06:00
6bd74611cd [nostalgia] Update release notes
All checks were successful
Build / build (push) Successful in 1m28s
2025-02-25 20:02:52 -06:00
c3f9cf9a64 [studio] Fix New Project opening project, disable New if no project open
Some checks failed
Build / build (push) Has been cancelled
2025-02-25 20:01:33 -06:00
646ab1283f [nostalgia/gfx] Cleanup
All checks were successful
Build / build (push) Successful in 1m26s
2025-02-24 21:45:45 -06:00
74cf055610 [nostalgia] Cleanup
All checks were successful
Build / build (push) Successful in 1m32s
2025-02-24 19:43:10 -06:00
0d8ba1b154 [nostalgia/gfx] Cleanup formatting mistake
All checks were successful
Build / build (push) Successful in 1m26s
2025-02-23 23:21:59 -06:00
20edbb7f38 [buildcore] Map aarch64 to arm64
All checks were successful
Build / build (push) Successful in 1m27s
2025-02-23 01:00:12 -06:00
6febc7cc73 [nostalgia] Fix build
All checks were successful
Build / build (push) Successful in 1m32s
2025-02-23 00:51:30 -06:00
b94d6b5061 [nostalgia] Remove scene package, finish stubbing out sound
Some checks failed
Build / build (push) Failing after 21s
2025-02-23 00:49:58 -06:00
b3952cabbc [nostalgia] Add build upload step to CI
All checks were successful
Build / build (push) Successful in 1m39s
2025-02-22 21:30:35 -06:00
2ffc11b04e Merge commit 'e723ead864edb4bc160e4d69713309174ad9e82e'
All checks were successful
Build / build (push) Successful in 1m34s
2025-02-22 20:55:17 -06:00
96cace2cbb [studio] Cleanup 2025-02-22 19:51:55 -06:00
472f5702bd [nostalgia/gfx/studio/tilesheet] Change max export scale to 135
All checks were successful
Build / build (push) Successful in 1m32s
2025-02-22 15:31:39 -06:00
c0ac4345d3 [studio] Cleanup
All checks were successful
Build / build (push) Successful in 1m30s
2025-02-22 15:16:26 -06:00
fbebf4ef83 [nostalgia/gfx/studio/tilesheet] Fix export for 4bpp images
All checks were successful
Build / build (push) Successful in 1m27s
2025-02-22 00:58:12 -06:00
20513f7749 [nostalgia/sample_project] Add type descriptors 2025-02-21 00:41:04 -06:00
178 changed files with 24780 additions and 1513 deletions

View File

@ -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

View File

@ -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}

View File

@ -11,6 +11,7 @@
# "Python Busy Box" - adds cross-platform equivalents to Unix commands that
# don't translate well to that other operating system
import multiprocessing
import os
import platform
import shutil
@ -57,7 +58,11 @@ def cmake_build(base_path: str, target: Optional[str]) -> int:
path = os.path.join(base_path, d)
if not os.path.isdir(path):
continue
args = ['cmake', '--build', path]
args = ['cmake', '--build', path, f'-j{multiprocessing.cpu_count()}']
if path.endswith('release'):
args.append('--config=release')
elif path.endswith('debug'):
args.append('--config=debug')
if target is not None:
args.extend(['--target', target])
err = subprocess.run(args).returncode

View File

@ -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

View File

@ -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;

View File

@ -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;

View File

@ -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>

View File

@ -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;

View File

@ -24,9 +24,6 @@ enum class FileAddressType: int8_t {
Inode,
};
template<typename T>
constexpr Error model(T *h, CommonPtrWith<class FileAddress> auto *fa) noexcept;
class FileAddress {
template<typename T>

View File

@ -20,7 +20,7 @@
namespace ox {
namespace detail {
static inline void fsBuffFree(char *buff) noexcept {
inline void fsBuffFree(char *buff) noexcept {
safeDelete(buff);
}
}
@ -49,11 +49,11 @@ class FileSystem {
Result<Buffer> read(StringViewCR path) noexcept;
inline Error read(StringViewCR path, void *buffer, std::size_t buffSize) noexcept {
Error read(StringViewCR path, void *buffer, std::size_t buffSize) noexcept {
return readFilePath(path, buffer, buffSize);
}
inline Error read(uint64_t inode, void *buffer, std::size_t buffSize) noexcept {
Error read(uint64_t inode, void *buffer, std::size_t buffSize) noexcept {
return readFileInode(inode, buffer, buffSize);
}
@ -69,8 +69,7 @@ class FileSystem {
* @param path
* @param readStart
* @param readSize
* @param buffer
* @param size
* @param buff
* @return error or number of bytes read
*/
Result<size_t> read(
@ -102,36 +101,36 @@ class FileSystem {
Error write(const FileAddress &addr, const void *buffer, uint64_t size, FileType fileType = FileType::NormalFile) noexcept;
inline Error write(StringViewCR path, const void *buffer, uint64_t size, FileType fileType) noexcept {
Error write(StringViewCR path, const void *buffer, uint64_t size, FileType fileType) noexcept {
return writeFilePath(path, buffer, size, fileType);
}
inline Error write(uint64_t inode, const void *buffer, uint64_t size, FileType fileType) noexcept {
Error write(uint64_t inode, const void *buffer, uint64_t size, FileType fileType) noexcept {
return writeFileInode(inode, buffer, size, fileType);
}
inline Result<FileStat> stat(uint64_t inode) const noexcept {
Result<FileStat> stat(uint64_t inode) const noexcept {
return statInode(inode);
}
inline Result<FileStat> stat(StringViewCR path) const noexcept {
Result<FileStat> stat(StringViewCR path) const noexcept {
return statPath(path);
}
Result<FileStat> stat(const FileAddress &addr) const noexcept;
[[nodiscard]]
inline bool exists(uint64_t inode) const noexcept {
bool exists(uint64_t inode) const noexcept {
return statInode(inode).ok();
}
[[nodiscard]]
inline bool exists(ox::StringView path) const noexcept {
bool exists(ox::StringView path) const noexcept {
return statPath(path).ok();
}
[[nodiscard]]
inline bool exists(FileAddress const&addr) const noexcept {
bool exists(FileAddress const&addr) const noexcept {
return stat(addr).ok();
}
@ -178,11 +177,11 @@ class MemFS: public FileSystem {
public:
Result<const char*> directAccess(const FileAddress &addr) const noexcept;
inline Result<const char*> directAccess(StringViewCR path) const noexcept {
Result<const char*> directAccess(StringViewCR path) const noexcept {
return directAccessPath(path);
}
inline Result<const char*> directAccess(uint64_t inode) const noexcept {
Result<const char*> directAccess(uint64_t inode) const noexcept {
return directAccessInode(inode);
}
@ -469,7 +468,7 @@ Error FileSystemTemplate<FileStore, Directory>::writeFilePath(
template<typename FileStore, typename Directory>
Error FileSystemTemplate<FileStore, Directory>::writeFileInode(uint64_t inode, const void *buffer, uint64_t size, FileType fileType) noexcept {
oxTrace("ox.fs.FileSystemTemplate.writeFileInode", ox::itoa(inode));
oxTrace("ox.fs.FileSystemTemplate.writeFileInode", ox::intToStr(inode));
return m_fs.write(inode, buffer, static_cast<size_t>(size), static_cast<uint8_t>(fileType));
}

View File

@ -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);

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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));

View File

@ -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;

View File

@ -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)) {

View File

@ -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>

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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)) {

View File

@ -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()),

View File

@ -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;
}

View File

@ -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) {

View File

@ -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
}

View File

@ -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

View File

@ -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",
[]() {

View File

@ -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
}

View File

@ -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;

View File

@ -1,4 +1,32 @@
# d2025.02
# d2025.05.1
* TileSheetEditor: Fix overrun errors when switching subsheets, clear selection
on switch (261e324acd)
* Fix new build error that occurs in MSVC (26d5048e6720c4c2d52508a6ee44c67dd9fe3ee5)
# 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.
@ -10,6 +38,8 @@
* 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.

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}

View 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.

View 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
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -2,7 +2,6 @@
add_subdirectory(gfx)
add_subdirectory(sound)
add_subdirectory(scene)
# module libraries
@ -15,7 +14,7 @@ target_link_libraries(
NostalgiaKeelModules PUBLIC
Keel
NostalgiaGfx-Keel
NostalgiaScene-Keel
NostalgiaSound-Keel
)
install(
FILES
@ -35,7 +34,6 @@ if(NOSTALGIA_BUILD_STUDIO)
StudioAppLib
NostalgiaGfx-Studio-ImGui
NostalgiaSound-Studio-ImGui
NostalgiaScene-Studio
)
install(
FILES

View File

@ -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;
}

View File

@ -16,23 +16,6 @@
namespace nostalgia::gfx {
struct SubSheetTemplate {
static constexpr auto TypeName = "net.drinkingtea.nostalgia.gfx.SubSheetTemplate";
static constexpr auto TypeVersion = 1;
ox::String name;
int32_t width{};
int32_t height{};
ox::Vector<SubSheetTemplate> subsheets;
};
OX_MODEL_BEGIN(SubSheetTemplate)
OX_MODEL_FIELD(name)
OX_MODEL_FIELD(width)
OX_MODEL_FIELD(height)
OX_MODEL_FIELD(subsheets)
OX_MODEL_END()
// Predecessor to TileSheet, kept for backward compatibility
struct TileSheetV1 {
static constexpr auto TypeName = "net.drinkingtea.nostalgia.core.NostalgiaGraphic";
@ -52,7 +35,7 @@ constexpr bool valid(TileSheetV1 const&ts) noexcept {
return (ts.bpp == 4 || ts.bpp == 8) && ts.pixels.size() == bytes;
}
constexpr ox::Error repair(TileSheetV1 &ts, int bpp) noexcept {
constexpr ox::Error repair(TileSheetV1 &ts, int const bpp) noexcept {
auto const bytes = static_cast<size_t>(ts.columns * ts.rows * PixelsPerTile) / (bpp == 4 ? 2 : 1);
ts.pixels.resize(bytes);
return {};
@ -101,7 +84,7 @@ constexpr bool valid(TileSheetV2 const&ts) noexcept {
return (ts.bpp == 4 || ts.bpp == 8) && valid(ts.subsheet, ts.bpp);
}
constexpr void repair(TileSheetV2::SubSheet &ss, int bpp) noexcept {
constexpr void repair(TileSheetV2::SubSheet &ss, int const bpp) noexcept {
auto const bytes = static_cast<size_t>(ss.columns * ss.rows * PixelsPerTile) / (bpp == 4 ? 2 : 1);
ss.pixels.resize(bytes);
for (auto &s : ss.subsheets) {
@ -171,7 +154,7 @@ constexpr bool valid(TileSheetV3 const&ts) noexcept {
return (ts.bpp == 4 || ts.bpp == 8) && valid(ts.subsheet, ts.bpp);
}
constexpr void repair(TileSheetV3::SubSheet &ss, int bpp) noexcept {
constexpr void repair(TileSheetV3::SubSheet &ss, int const bpp) noexcept {
auto const bytes = static_cast<size_t>(ss.columns * ss.rows * PixelsPerTile) / (bpp == 4 ? 2 : 1);
ss.pixels.resize(bytes);
for (auto &s : ss.subsheets) {
@ -265,7 +248,7 @@ constexpr bool valid(TileSheetV4 const&ts) noexcept {
return (ts.bpp == 4 || ts.bpp == 8) && valid(ts.subsheet, ts.bpp);
}
constexpr void repair(TileSheetV4::SubSheet &ss, int bpp) noexcept {
constexpr void repair(TileSheetV4::SubSheet &ss, int const bpp) noexcept {
if (ss.subsheets.empty()) {
auto const bytes = static_cast<size_t>(ss.columns * ss.rows * PixelsPerTile) / (bpp == 4 ? 2 : 1);
ss.pixels.resize(bytes);
@ -367,7 +350,7 @@ constexpr bool valid(TileSheetV5 const&ts) noexcept {
return (ts.bpp == 4 || ts.bpp == 8) && valid(ts.subsheet);
}
constexpr void repair(TileSheetV5::SubSheet &ss, int const bpp) noexcept {
constexpr void repair(TileSheetV5::SubSheet &ss) noexcept {
if (ss.subsheets.empty()) {
auto const bytes = static_cast<size_t>(ss.columns * ss.rows * PixelsPerTile);
ss.pixels.resize(bytes);
@ -377,7 +360,7 @@ constexpr void repair(TileSheetV5::SubSheet &ss, int const bpp) noexcept {
ss.rows = -1;
}
for (auto &s : ss.subsheets) {
repair(s, bpp);
repair(s);
}
}
@ -385,7 +368,7 @@ constexpr ox::Error repair(TileSheetV5 &ts) noexcept {
if (ts.bpp != 4 && ts.bpp != 8) {
return ox::Error{1, "Unable to repair TileSheet"};
}
repair(ts.subsheet, ts.bpp);
repair(ts.subsheet);
return {};
}

View File

@ -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) {

View File

@ -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,

View File

@ -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>(),
};
}

View File

@ -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);

View File

@ -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;
}

View File

@ -50,22 +50,25 @@ void PaletteEditorImGui::PageRenameDialog::draw(turbine::Context &tctx) noexcept
return;
}
if (ig::BeginPopup(tctx, "Rename Page", m_show)) {
if (ImGui::IsWindowAppearing()) {
ImGui::SetKeyboardFocusHere();
}
ig::InputText("Name", m_name);
switch (ig::PopupControlsOkCancel(m_show)) {
case ig::PopupResponse::OK:
inputSubmitted.emit(m_name);
[[fallthrough]];
case ig::PopupResponse::Cancel:
close();
default:
break;
auto const nameInputFocused = ImGui::IsItemFocused();
auto const resp = ig::PopupControlsOkCancel(m_show);
if ((nameInputFocused && ImGui::IsKeyPressed(ImGuiKey_Enter))
|| resp == ig::PopupResponse::OK) {
inputSubmitted.emit(m_name);
close();
} else if (resp == ig::PopupResponse::Cancel) {
close();
}
ImGui::EndPopup();
}
}
PaletteEditorImGui::PaletteEditorImGui(studio::StudioContext &sctx, ox::StringParam path):
PaletteEditorImGui::PaletteEditorImGui(studio::Context &sctx, ox::StringParam path):
Editor(sctx, std::move(path)),
m_sctx(sctx),
m_tctx(sctx.tctx),
@ -74,7 +77,7 @@ PaletteEditorImGui::PaletteEditorImGui(studio::StudioContext &sctx, ox::StringPa
m_pageRenameDlg.inputSubmitted.connect(this, &PaletteEditorImGui::renamePage);
}
void PaletteEditorImGui::draw(studio::StudioContext&) noexcept {
void PaletteEditorImGui::draw(studio::Context&) noexcept {
auto const paneSize = ImGui::GetContentRegionAvail();
{
ImGui::BeginChild("Pages", {280, paneSize.y}, true);
@ -102,13 +105,13 @@ void PaletteEditorImGui::navigateTo(ox::StringViewCR arg) noexcept {
auto const &color = args[0];
auto const &page = args[1];
{
auto const [c, err] = atoi(color);
auto const [c, err] = strToInt(color);
if (!err && static_cast<size_t>(c) < colorCnt(m_pal)) {
m_selectedColorRow = static_cast<size_t>(c);
}
}
{
auto const [pg, err] = atoi(page);
auto const [pg, err] = strToInt(page);
if (!err && static_cast<size_t>(pg) < m_pal.pages.size()) {
m_page = static_cast<size_t>(pg);
}
@ -131,7 +134,7 @@ void PaletteEditorImGui::numShortcuts(size_t &val, size_t const sizeRange) noexc
auto const lastElem = sizeRange - 1;
if (ImGui::IsKeyPressed(ImGuiKey_0)) {
val = ox::min<size_t>(9, lastElem);
} else for (auto i = 9u; i < 10; --i) {
} else for (auto i = 8u; i < 9; --i) {
auto const key = static_cast<ImGuiKey>(ImGuiKey_1 + i);
if (ImGui::IsKeyPressed(key)) {
val = ox::min<size_t>(i, lastElem);

View File

@ -31,16 +31,16 @@ 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;
@ -53,7 +53,7 @@ class PaletteEditorImGui: public studio::Editor {
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;

View File

@ -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 = {},

View File

@ -27,11 +27,14 @@ CutPasteCommand::CutPasteCommand(
TileSheet::SubSheetIdx subSheetIdx,
ox::Point const&dstStart,
ox::Point dstEnd,
TileSheetClipboard const&cb) noexcept:
TileSheetClipboard const&cb):
m_commandId(commandId),
m_img(img),
m_subSheetIdx(std::move(subSheetIdx)) {
auto const&ss = getSubSheet(m_img, m_subSheetIdx);
if (dstStart.x >= ss.columns * TileWidth || dstStart.y >= ss.rows * TileHeight) {
throw ox::Exception{1, "paste starts beyond the bounds of target"};
}
dstEnd.x = std::min(ss.columns * TileWidth - 1, dstEnd.x);
dstEnd.y = std::min(ss.rows * TileHeight - 1, dstEnd.y);
for (auto const&p : cb.pixels()) {

View File

@ -69,7 +69,7 @@ class CutPasteCommand: public TileSheetCommand {
TileSheet::SubSheetIdx subSheetIdx,
ox::Point const&dstStart,
ox::Point dstEnd,
TileSheetClipboard const&cb) noexcept;
TileSheetClipboard const&cb);
ox::Error redo() noexcept final;

View File

@ -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 {};
}

View File

@ -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);
}

View File

@ -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 {

View File

@ -6,7 +6,7 @@
namespace nostalgia::gfx {
gfx::UpdateSubSheetCommand::UpdateSubSheetCommand(
UpdateSubSheetCommand::UpdateSubSheetCommand(
TileSheet &img,
TileSheet::SubSheetIdx idx,
ox::StringParam name,

View File

@ -36,21 +36,12 @@ OX_MODEL_BEGIN(TileSheetEditorConfig)
OX_MODEL_END()
static ox::Vector<uint32_t> normalizePixelSizes(
ox::Vector<uint8_t> const&inPixels,
int const bpp) noexcept {
uint_t const bytesPerTile = bpp == 8 ? PixelsPerTile : PixelsPerTile / 2;
ox::Vector<uint8_t> const&inPixels) noexcept {
ox::Vector<uint32_t> outPixels;
if (bytesPerTile == 64) { // 8 BPP
outPixels.resize(inPixels.size());
for (std::size_t i = 0; i < inPixels.size(); ++i) {
outPixels[i] = inPixels[i];
}
} else { // 4 BPP
outPixels.resize(inPixels.size() * 2);
for (std::size_t i = 0; i < inPixels.size(); ++i) {
outPixels[i * 2 + 0] = inPixels[i] & 0xF;
outPixels[i * 2 + 1] = inPixels[i] >> 4;
}
outPixels.reserve(inPixels.size());
outPixels.resize(inPixels.size());
for (std::size_t i = 0; i < inPixels.size(); ++i) {
outPixels[i] = inPixels[i];
}
return outPixels;
}
@ -96,7 +87,7 @@ static ox::Error toPngFile(
8)));
}
TileSheetEditorImGui::TileSheetEditorImGui(studio::StudioContext &sctx, ox::StringParam path):
TileSheetEditorImGui::TileSheetEditorImGui(studio::Context &sctx, ox::StringParam path):
Editor(sctx, std::move(path)),
m_sctx{sctx},
m_tctx{m_sctx.tctx},
@ -105,7 +96,7 @@ TileSheetEditorImGui::TileSheetEditorImGui(studio::StudioContext &sctx, ox::Stri
m_model{m_view.model()} {
// connect signal/slots
m_subsheetEditor.inputSubmitted.connect(this, &TileSheetEditorImGui::updateActiveSubsheet);
m_exportMenu.inputSubmitted.connect(this, &TileSheetEditorImGui::exportSubhseetToPng);
m_exportMenu.inputSubmitted.connect(this, &TileSheetEditorImGui::exportSubsheetToPng);
// load config
auto const&config = studio::readConfig<TileSheetEditorConfig>(
keelCtx(m_sctx), itemPath());
@ -138,7 +129,7 @@ void TileSheetEditorImGui::keyStateChanged(turbine::Key const key, bool const do
if (!down) {
return;
}
if (key == turbine::Key::Escape) {
if (ig::mainWinHasFocus() && key == turbine::Key::Escape) {
m_subsheetEditor.close();
m_exportMenu.close();
m_palPicker.close();
@ -197,7 +188,7 @@ void TileSheetEditorImGui::keyStateChanged(turbine::Key const key, bool const do
}
}
void TileSheetEditorImGui::draw(studio::StudioContext&) noexcept {
void TileSheetEditorImGui::draw(studio::Context&) noexcept {
if (ig::mainWinHasFocus() && m_tool == TileSheetTool::Select) {
if (ImGui::IsKeyDown(ImGuiKey_ModCtrl) && !m_palPathFocused) {
if (ImGui::IsKeyPressed(ImGuiKey_A)) {
@ -406,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,
@ -424,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;
}
@ -559,7 +549,7 @@ void TileSheetEditorImGui::drawPaletteMenu() noexcept {
ImGui::PushID(static_cast<int>(i));
// Column: color idx
ImGui::TableNextColumn();
auto const label = ox::itoa(i + 1);
auto const label = ox::intToStr(i + 1);
auto const rowSelected = i == m_view.palIdx();
if (ImGui::Selectable(
label.c_str(), rowSelected, ImGuiSelectableFlags_SpanAllColumns)) {
@ -652,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);
}

View File

@ -10,7 +10,6 @@
#include <studio/editor.hpp>
#include <studio/filepickerpopup.hpp>
#include "tilesheetpixelgrid.hpp"
#include "tilesheetpixels.hpp"
#include "tilesheeteditorview.hpp"
@ -46,7 +45,7 @@ class TileSheetEditorImGui: public studio::Editor {
constexpr bool isOpen() const noexcept { return m_show; }
};
static constexpr float s_palViewWidth = 335;
studio::StudioContext &m_sctx;
studio::Context &m_sctx;
turbine::Context &m_tctx;
ox::Vector<ox::String> m_paletteList;
SubSheetEditor m_subsheetEditor;
@ -61,7 +60,7 @@ class TileSheetEditorImGui: public studio::Editor {
ox::Vector<ox::UPtr<studio::UndoCommand>, 1> m_deferredCmds;
public:
TileSheetEditorImGui(studio::StudioContext &sctx, ox::StringParam path);
TileSheetEditorImGui(studio::Context &sctx, ox::StringParam path);
~TileSheetEditorImGui() override = default;
@ -78,7 +77,7 @@ class TileSheetEditorImGui: public studio::Editor {
void keyStateChanged(turbine::Key key, bool down) override;
void draw(studio::StudioContext&) noexcept override;
void draw(studio::Context&) noexcept override;
void drawSubsheetSelector(TileSheet::SubSheet&, TileSheet::SubSheetIdx &path);
@ -91,7 +90,7 @@ class TileSheetEditorImGui: public studio::Editor {
private:
void showSubsheetEditor() noexcept;
ox::Error exportSubhseetToPng(int scale) const noexcept;
ox::Error exportSubsheetToPng(int scale) const noexcept;
void drawTileSheet(ox::Vec2 const&fbSize) noexcept;
@ -99,8 +98,6 @@ class TileSheetEditorImGui: public studio::Editor {
ox::Error updateActiveSubsheet(ox::StringView const&name, int cols, int rows) noexcept;
// slots
private:
void setActiveSubsheet(TileSheet::SubSheetIdx path) noexcept;
};

View File

@ -45,14 +45,14 @@ Palette const TileSheetEditorModel::s_defaultPalette = {
};
TileSheetEditorModel::TileSheetEditorModel(
studio::StudioContext &sctx, ox::StringParam path, studio::UndoStack &undoStack):
m_sctx(sctx),
m_tctx(m_sctx.tctx),
m_path(std::move(path)),
m_img(*readObj<TileSheet>(keelCtx(m_tctx), m_path).unwrapThrow()),
studio::Context &sctx, ox::StringParam path, studio::UndoStack &undoStack):
m_sctx{sctx},
m_tctx{m_sctx.tctx},
m_path{std::move(path)},
m_img{*readObj<TileSheet>(keelCtx(m_tctx), m_path).unwrapThrow()},
// ignore failure to load palette
m_pal(readObj<Palette>(keelCtx(m_tctx), m_img.defaultPalette).value),
m_undoStack(undoStack) {
m_pal{readObj<Palette>(keelCtx(m_tctx), m_img.defaultPalette).value},
m_undoStack{undoStack} {
normalizeSubsheets(m_img.subsheet);
m_pal.updated.connect(this, &TileSheetEditorModel::markUpdated);
m_undoStack.changeTriggered.connect(this, &TileSheetEditorModel::markUpdatedCmdId);
@ -67,19 +67,27 @@ void TileSheetEditorModel::cut() {
TileSheetClipboard blankCb;
auto cb = ox::make_unique<TileSheetClipboard>();
auto const&s = activeSubSheet();
iterateSelectionRows(*m_selection, [&](int const x, int const y) {
if (iterateSelectionRows(*m_selection, [&](int const x, int const y) {
auto pt = ox::Point{x, y};
auto const idx = gfx::idx(s, pt);
auto const c = getPixel(s, idx);
if (idx >= s.pixels.size()) {
return ox::Error{1, "invalid idx"};
}
auto const c = s.pixels[idx];
pt -= m_selection->a;
cb->addPixel(pt, c);
blankCb.addPixel(pt, 0);
});
return ox::Error{};
})) {
return;
}
auto const pt1 = m_selection->a;
auto const pt2 = ox::Point{s.columns * TileWidth, s.rows * TileHeight};
turbine::setClipboardObject(m_tctx, std::move(cb));
std::ignore = pushCommand(ox::make<CutPasteCommand>(
CommandId::Cut, m_img, m_activeSubsSheetIdx, pt1, pt2, blankCb));
if (auto const cmd = ox::makeCatch<CutPasteCommand>(
CommandId::Cut, m_img, m_activeSubsSheetIdx, pt1, pt2, blankCb); cmd.ok()) {
std::ignore = pushCommand(cmd.value);
}
}
void TileSheetEditorModel::copy() {
@ -87,14 +95,20 @@ void TileSheetEditorModel::copy() {
return;
}
auto cb = ox::make_unique<TileSheetClipboard>();
iterateSelectionRows(*m_selection, [&](int const x, int const y) {
if (iterateSelectionRows(*m_selection, [&](int const x, int const y) {
auto pt = ox::Point{x, y};
auto const&s = activeSubSheet();
auto const idx = gfx::idx(s, pt);
auto const c = getPixel(s, idx);
if (idx >= s.pixels.size()) {
return ox::Error{1, "invalid idx"};
}
auto const c = s.pixels[idx];
pt -= m_selection->a;
cb->addPixel(pt, c);
});
return ox::Error{};
})) {
return;
}
turbine::setClipboardObject(m_tctx, std::move(cb));
}
@ -111,8 +125,10 @@ void TileSheetEditorModel::paste() {
auto const&s = activeSubSheet();
auto const pt1 = m_selection->a;
auto const pt2 = ox::Point{s.columns * TileWidth, s.rows * TileHeight};
std::ignore = pushCommand(ox::make<CutPasteCommand>(
CommandId::Paste, m_img, m_activeSubsSheetIdx, pt1, pt2, *cb));
if (auto const cmd = ox::makeCatch<CutPasteCommand>(
CommandId::Paste, m_img, m_activeSubsSheetIdx, pt1, pt2, *cb); cmd.ok()) {
std::ignore = pushCommand(cmd.value);
}
}
bool TileSheetEditorModel::acceptsClipboardPayload() const noexcept {
@ -120,7 +136,7 @@ bool TileSheetEditorModel::acceptsClipboardPayload() const noexcept {
return cb.ok();
}
ox::StringView TileSheetEditorModel::palPath() const noexcept {
ox::String const &TileSheetEditorModel::palPath() const & noexcept {
return m_palPath;
}
@ -152,7 +168,7 @@ void TileSheetEditorModel::drawCommand(ox::Point const &pt, std::size_t const pa
auto const idx = gfx::idx(activeSubSheet, pt);
if (m_ongoingDrawCommand) {
m_updated = m_updated || m_ongoingDrawCommand->append(idx);
} else if (getPixel(activeSubSheet, idx) != palIdx) {
} else if (activeSubSheet.pixels[idx] != palIdx) {
std::ignore = pushCommand(ox::make<DrawCommand>(
m_img, m_activeSubsSheetIdx, idx, static_cast<int>(palIdx)));
}
@ -213,6 +229,7 @@ ox::Error TileSheetEditorModel::updateSubsheet(
void TileSheetEditorModel::setActiveSubsheet(TileSheet::SubSheetIdx const&idx) noexcept {
m_activeSubsSheetIdx = idx;
this->activeSubsheetChanged.emit(m_activeSubsSheetIdx);
clearSelection();
}
void TileSheetEditorModel::fill(ox::Point const&pt, int const palIdx) noexcept {
@ -263,7 +280,13 @@ ox::Error TileSheetEditorModel::rotateRight() noexcept {
}
void TileSheetEditorModel::setSelection(studio::Selection const&sel) noexcept {
m_selection.emplace(sel);
auto const &ss = activeSubSheet();
if (sel.a.x < ss.columns * TileWidth && sel.a.y < ss.rows * TileHeight) {
m_selection.emplace(sel);
} else {
m_selTracker.finishSelection();
m_selection.reset();
}
m_updated = true;
}
@ -375,7 +398,7 @@ void TileSheetEditorModel::getFillPixels(
int const oldColor) const noexcept {
auto const idx = ptToIdx(pt, activeSubSheet.columns);
auto const relIdx = idx % PixelsPerTile;
if (pixels[relIdx] || getPixel(activeSubSheet, idx) != oldColor) {
if (pixels[relIdx] || activeSubSheet.pixels[idx] != oldColor) {
return;
}
// mark pixels to update
@ -413,7 +436,7 @@ void TileSheetEditorModel::setPalPath() noexcept {
}
ox::Error TileSheetEditorModel::pushCommand(studio::UndoCommand *cmd) noexcept {
std::ignore = m_undoStack.push(ox::UPtr<studio::UndoCommand>{cmd});
std::ignore = m_undoStack.push(ox::UPtr{cmd});
m_ongoingDrawCommand = dynamic_cast<DrawCommand*>(cmd);
m_updated = true;
return {};

View File

@ -22,7 +22,7 @@ class TileSheetEditorModel: public ox::SignalHandler {
private:
static Palette const s_defaultPalette;
studio::StudioContext &m_sctx;
studio::Context &m_sctx;
turbine::Context &m_tctx;
ox::String m_path;
ox::String m_palPath;
@ -39,7 +39,7 @@ class TileSheetEditorModel: public ox::SignalHandler {
bool m_updated = false;
public:
TileSheetEditorModel(studio::StudioContext &sctx, ox::StringParam path, studio::UndoStack &undoStack);
TileSheetEditorModel(studio::Context &sctx, ox::StringParam path, studio::UndoStack &undoStack);
~TileSheetEditorModel() override = default;
@ -62,7 +62,7 @@ class TileSheetEditorModel: public ox::SignalHandler {
constexpr Palette const&pal() const noexcept;
[[nodiscard]]
ox::StringView palPath() const noexcept;
ox::String const &palPath() const & noexcept;
ox::Error setPalette(ox::StringViewCR path) noexcept;

View File

@ -12,7 +12,7 @@
namespace nostalgia::gfx {
TileSheetEditorView::TileSheetEditorView(
studio::StudioContext &sctx, ox::StringViewCR path, studio::UndoStack &undoStack):
studio::Context &sctx, ox::StringViewCR path, studio::UndoStack &undoStack):
m_model(sctx, path, undoStack),
m_pixelsDrawer(m_model) {
glBindVertexArray(0);

View File

@ -56,7 +56,7 @@ class TileSheetEditorView: public ox::SignalHandler {
std::size_t m_palIdx = 0;
public:
TileSheetEditorView(studio::StudioContext &sctx, ox::StringViewCR path, studio::UndoStack &undoStack);
TileSheetEditorView(studio::Context &sctx, ox::StringViewCR path, studio::UndoStack &undoStack);
~TileSheetEditorView() override = default;

View File

@ -5,12 +5,13 @@
#include <ox/claw/write.hpp>
#include <nostalgia/gfx/consts.hpp>
#include <nostalgia/gfx/gfx.hpp>
#include "tilesheetpixelgrid.hpp"
namespace nostalgia::gfx {
void TileSheetGrid::setPixelSizeMod(float sm) noexcept {
void TileSheetGrid::setPixelSizeMod(float const sm) noexcept {
m_pixelSizeMod = sm;
}
@ -18,10 +19,11 @@ ox::Error TileSheetGrid::buildShader() noexcept {
auto const pixelLineVshad = ox::sfmt(VShad, gl::GlslVersion);
auto const pixelLineFshad = ox::sfmt(FShad, gl::GlslVersion);
auto const pixelLineGshad = ox::sfmt(GShad, gl::GlslVersion);
return glutils::buildShaderProgram(pixelLineVshad, pixelLineFshad, pixelLineGshad).moveTo(m_shader);
return glutils::buildShaderProgram(
pixelLineVshad, pixelLineFshad, pixelLineGshad).moveTo(m_shader);
}
void TileSheetGrid::draw(bool update, ox::Vec2 const&scroll) noexcept {
void TileSheetGrid::draw(bool const update, ox::Vec2 const&scroll) noexcept {
// the lines just show up bigger on Windows for some reason
if constexpr(ox::defines::OS == ox::OS::Windows) {
glLineWidth(3 * m_pixelSizeMod * 0.25f);
@ -51,7 +53,8 @@ void TileSheetGrid::initBufferSet(ox::Vec2 const&paneSize, TileSheet::SubSheet c
// vbo layout
auto const pt1Attr = static_cast<GLuint>(glGetAttribLocation(m_shader, "vPt1"));
glEnableVertexAttribArray(pt1Attr);
glVertexAttribPointer(pt1Attr, 2, GL_FLOAT, GL_FALSE, VertexVboRowLength * sizeof(float), nullptr);
glVertexAttribPointer(
pt1Attr, 2, GL_FLOAT, GL_FALSE, VertexVboRowLength * sizeof(float), nullptr);
auto const pt2Attr = static_cast<GLuint>(glGetAttribLocation(m_shader, "vPt2"));
glEnableVertexAttribArray(pt2Attr);
glVertexAttribPointer(pt2Attr, 2, GL_FLOAT, GL_FALSE, VertexVboRowLength * sizeof(float),
@ -70,18 +73,18 @@ void TileSheetGrid::update(ox::Vec2 const&paneSize, TileSheet::SubSheet const&su
}
void TileSheetGrid::setBufferObject(
ox::Point pt1,
ox::Point pt2,
Color32 c,
float *vbo,
ox::Point const pt1,
ox::Point const pt2,
Color32 const c,
ox::Span<float> const vbo,
ox::Vec2 const&pixSize) noexcept {
auto const x1 = static_cast<float>(pt1.x) * pixSize.x - 1.f;
auto const y1 = 1.f - static_cast<float>(pt1.y) * pixSize.y;
auto const x2 = static_cast<float>(pt2.x) * pixSize.x - 1.f;
auto const y2 = 1.f - static_cast<float>(pt2.y) * pixSize.y;
// don't worry, this memcpy gets optimized to something much more ideal
// don't worry, this gets optimized to something much more ideal
ox::Array<float, VertexVboLength> const vertices = {x1, y1, x2, y2, redf(c), greenf(c), bluef(c)};
memcpy(vbo, vertices.data(), sizeof(vertices));
ox::spancpy(vbo, ox::SpanView<float>{vertices});
}
void TileSheetGrid::setBufferObjects(ox::Vec2 const&paneSize, TileSheet::SubSheet const&subsheet) noexcept {
@ -92,7 +95,8 @@ void TileSheetGrid::setBufferObjects(ox::Vec2 const&paneSize, TileSheet::SubShee
}
auto const pixSize = pixelSize(paneSize);
auto const set = [&](std::size_t i, ox::Point pt1, ox::Point pt2, Color32 c) {
auto const vbo = &m_bufferSet.vertices[i * VertexVboLength];
auto const idx = i * VertexVboLength;
auto const vbo = ox::Span{m_bufferSet.vertices} + idx;
setBufferObject(pt1, pt2, c, vbo, pixSize);
};
// set buffer length

View File

@ -7,7 +7,6 @@
#include <glutils/glutils.hpp>
#include <studio/studio.hpp>
#include <nostalgia/gfx/gfx.hpp>
#include <nostalgia/gfx/tilesheet.hpp>
namespace nostalgia::gfx {
@ -74,7 +73,7 @@ class TileSheetGrid {
void update(ox::Vec2 const&paneSize, TileSheet::SubSheet const&subsheet) noexcept;
private:
static void setBufferObject(ox::Point pt1, ox::Point pt2, Color32 c, float *vbo, ox::Vec2 const&pixSize) noexcept;
static void setBufferObject(ox::Point pt1, ox::Point pt2, Color32 c, ox::Span<float> vbo, ox::Vec2 const&pixSize) noexcept;
void setBufferObjects(ox::Vec2 const&paneSize, TileSheet::SubSheet const&subsheet) noexcept;

View File

@ -2,8 +2,6 @@
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#include <nostalgia/gfx/consts.hpp>
#include <nostalgia/gfx/ptidxconv.hpp>
#include "tilesheeteditormodel.hpp"
#include "tilesheetpixels.hpp"
@ -88,11 +86,11 @@ ox::Vec2 TileSheetPixels::pixelSize(ox::Vec2 const&paneSize) const noexcept {
void TileSheetPixels::setPixelBufferObject(
ox::Vec2 const&paneSize,
unsigned vertexRow,
unsigned const vertexRow,
float x, float y,
Color16 color,
float *vbo,
GLuint *ebo) const noexcept {
Color16 const color,
ox::Span<float> const vbo,
ox::Span<GLuint> const ebo) const noexcept {
auto const [xmod, ymod] = pixelSize(paneSize);
x *= xmod;
y *= -ymod;
@ -106,12 +104,12 @@ void TileSheetPixels::setPixelBufferObject(
x + xmod, y + ymod, r, g, b, // top right
x, y + ymod, r, g, b, // top left
};
memcpy(vbo, vertices.data(), sizeof(vertices));
ox::spancpy(vbo, ox::SpanView<float>{vertices});
std::array const elms = {
vertexRow + 0, vertexRow + 1, vertexRow + 2,
vertexRow + 2, vertexRow + 3, vertexRow + 0,
};
memcpy(ebo, elms.data(), sizeof(elms));
ox::spancpy(ebo, ox::SpanView<GLuint>{elms});
}
void TileSheetPixels::setBufferObjects(ox::Vec2 const&paneSize) noexcept {
@ -137,8 +135,8 @@ void TileSheetPixels::setBufferObjects(ox::Vec2 const&paneSize) noexcept {
auto const pt = idxToPt(static_cast<int>(i), subSheet.columns);
auto const fx = static_cast<float>(pt.x);
auto const fy = static_cast<float>(pt.y);
auto const vbo = &m_bufferSet.vertices[i * vboLen];
auto const ebo = &m_bufferSet.elements[i * VertexEboLength];
auto const vbo = ox::Span{m_bufferSet.vertices} + i * vboLen;
auto const ebo = ox::Span{m_bufferSet.elements} + i * VertexEboLength;
if (i * vboLen + vboLen > m_bufferSet.vertices.size()) {
return;
}

View File

@ -6,11 +6,9 @@
#include <ox/std/vec.hpp>
#include <glutils/glutils.hpp>
#include <studio/studio.hpp>
#include <nostalgia/gfx/color.hpp>
#include <nostalgia/gfx/gfx.hpp>
#include <glutils/glutils.hpp>
namespace nostalgia::gfx {
@ -44,15 +42,15 @@ class TileSheetPixels {
private:
void setPixelBufferObject(
ox::Vec2 const&paneS,
ox::Vec2 const&paneSize,
unsigned vertexRow,
float x,
float y,
Color16 color,
float *vbo,
GLuint *ebo) const noexcept;
ox::Span<float> vbo,
ox::Span<GLuint> ebo) const noexcept;
void setBufferObjects(ox::Vec2 const&paneS) noexcept;
void setBufferObjects(ox::Vec2 const&paneSize) noexcept;
};

View File

@ -3,7 +3,7 @@
*/
#include <nostalgia/gfx/keelmodule.hpp>
#include <nostalgia/scene/keelmodule.hpp>
#include <nostalgia/sound/keelmodule.hpp>
namespace nostalgia {
@ -14,7 +14,7 @@ void registerKeelModules() noexcept {
}
modulesRegistered = true;
keel::registerModule(gfx::keelModule());
keel::registerModule(scene::keelModule());
keel::registerModule(sound::keelModule());
}
}

View File

@ -1,13 +0,0 @@
add_subdirectory(src)
target_include_directories(
NostalgiaScene PUBLIC
include
)
install(
DIRECTORY
include/nostalgia
DESTINATION
include
)

View File

@ -1,27 +0,0 @@
/*
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#pragma once
#include <nostalgia/gfx/context.hpp>
#include "scenestatic.hpp"
namespace nostalgia::scene {
class Scene {
private:
SceneStatic const&m_sceneStatic;
public:
explicit Scene(SceneStatic const&sceneStatic) noexcept;
ox::Error setupDisplay(gfx::Context &ctx) const noexcept;
private:
void setupLayer(gfx::Context&, ox::Vector<uint16_t> const&layer, unsigned layerNo) const noexcept;
};
}

View File

@ -1,228 +0,0 @@
/*
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#pragma once
#include <ox/fs/fs.hpp>
#include <ox/std/error.hpp>
#include <ox/std/size.hpp>
#include <ox/std/types.hpp>
#include <ox/std/vector.hpp>
#include <nostalgia/gfx/tilesheet.hpp>
namespace nostalgia::scene {
struct SpriteDoc {
constexpr static auto TypeName = "net.drinkingtea.nostalgia.scene.SpriteDoc";
constexpr static auto TypeVersion = 1;
constexpr static auto Preloadable = true;
ox::String tilesheetPath;
ox::Vector<gfx::SubSheetId> subsheetId;
};
struct TileDoc {
constexpr static auto TypeName = "net.drinkingtea.nostalgia.scene.TileDoc";
constexpr static auto TypeVersion = 1;
constexpr static auto Preloadable = true;
gfx::SubSheetId subsheetId = -1;
ox::String subsheetPath;
uint8_t type = 0;
ox::Array<uint8_t, 4> layerAttachments;
[[nodiscard]]
constexpr ox::Result<gfx::SubSheetId> getSubsheetId(gfx::TileSheet const&ts) const noexcept {
// prefer the already present ID
if (subsheetId > -1) {
return subsheetId;
}
return getIdFor(ts, subsheetPath);
}
[[nodiscard]]
constexpr ox::Result<ox::StringView> getSubsheetPath(
gfx::TileSheet const&ts) const noexcept {
// prefer the already present path
if (!subsheetPath.len()) {
return gfx::getNameFor(ts, subsheetId);
}
return ox::StringView(subsheetPath);
}
};
OX_MODEL_BEGIN(TileDoc)
OX_MODEL_FIELD_RENAME(subsheetId, subsheet_id)
OX_MODEL_FIELD_RENAME(subsheetPath, subsheet_path)
OX_MODEL_FIELD(type)
OX_MODEL_FIELD_RENAME(layerAttachments, layer_attachments)
OX_MODEL_END()
struct SceneDoc {
using TileMapRow = ox::Vector<TileDoc>;
using TileMapLayer = ox::Vector<TileMapRow>;
using TileMap = ox::Vector<TileMapLayer>;
constexpr static auto TypeName = "net.drinkingtea.nostalgia.scene.SceneDoc";
constexpr static auto TypeVersion = 1;
constexpr static auto Preloadable = true;
ox::String tilesheet; // path
ox::Vector<ox::String> palettes; // paths
TileMap tiles;
[[nodiscard]]
constexpr ox::Size size(std::size_t layerIdx) const noexcept {
const auto &layer = this->tiles[layerIdx];
const auto rowCnt = static_cast<int>(layer.size());
if (!rowCnt) {
return {};
}
auto colCnt = layer[0].size();
// find shortest row (they should all be the same, but you know this data
// could come from a file)
for (auto const&row : layer) {
colCnt = ox::min(colCnt, row.size());
}
return {static_cast<int>(colCnt), rowCnt};
}
};
OX_MODEL_BEGIN(SceneDoc)
OX_MODEL_FIELD(tilesheet)
OX_MODEL_FIELD(palettes)
OX_MODEL_FIELD(tiles)
OX_MODEL_END()
constexpr void setTopEdge(uint8_t &layerAttachments, unsigned val) noexcept {
const auto val8 = static_cast<uint8_t>(val);
layerAttachments = (layerAttachments & 0b11111100) | val8;
}
constexpr void setBottomEdge(uint8_t &layerAttachments, unsigned val) noexcept {
const auto val8 = static_cast<uint8_t>(val);
layerAttachments = (layerAttachments & 0b11110011) | static_cast<uint8_t>(val8 << 2);
}
constexpr void setLeftEdge(uint8_t &layerAttachments, unsigned val) noexcept {
const auto val8 = static_cast<uint8_t>(val);
layerAttachments = (layerAttachments & 0b11001111) | static_cast<uint8_t>(val8 << 4);
}
constexpr void setRightEdge(uint8_t &layerAttachments, unsigned val) noexcept {
const auto val8 = static_cast<uint8_t>(val);
layerAttachments = (layerAttachments & 0b00111111) | static_cast<uint8_t>(val8 << 6);
}
[[nodiscard]]
constexpr unsigned topEdge(uint8_t layerAttachments) noexcept {
return layerAttachments & 0b11;
}
[[nodiscard]]
constexpr unsigned bottomEdge(uint8_t layerAttachments) noexcept {
return (layerAttachments >> 2) & 0b11;
}
[[nodiscard]]
constexpr unsigned leftEdge(uint8_t layerAttachments) noexcept {
return (layerAttachments >> 4) & 0b11;
}
[[nodiscard]]
constexpr unsigned rightEdge(uint8_t layerAttachments) noexcept {
return (layerAttachments >> 6) & 0b11;
}
struct SceneStatic {
constexpr static auto TypeName = "net.drinkingtea.nostalgia.scene.SceneStatic";
constexpr static auto TypeVersion = 1;
constexpr static auto Preloadable = true;
struct Tile {
uint16_t &tileMapIdx;
uint8_t &tileType;
uint8_t &layerAttachments;
constexpr Tile(uint16_t &pTileMapIdx, uint8_t &pTileType, uint8_t &pLayerAttachments) noexcept:
tileMapIdx(pTileMapIdx),
tileType(pTileType),
layerAttachments(pLayerAttachments) {
}
};
struct Layer {
uint16_t &columns;
uint16_t &rows;
ox::Vector<uint16_t> &tileMapIdx;
ox::Vector<uint8_t> &tileType;
ox::Vector<uint8_t> &layerAttachments;
constexpr Layer(
uint16_t &pColumns,
uint16_t &pRows,
ox::Vector<uint16_t> &pTileMapIdx,
ox::Vector<uint8_t> &pTileType,
ox::Vector<uint8_t> &pLayerAttachments) noexcept:
columns(pColumns),
rows(pRows),
tileMapIdx(pTileMapIdx),
tileType(pTileType),
layerAttachments(pLayerAttachments) {
}
[[nodiscard]]
constexpr Tile tile(std::size_t i) noexcept {
return {tileMapIdx[i], tileType[i], layerAttachments[i]};
}
constexpr auto setDimensions(ox::Size dim) noexcept {
columns = static_cast<uint16_t>(dim.width);
rows = static_cast<uint16_t>(dim.height);
const auto tileCnt = static_cast<unsigned>(columns * rows);
tileMapIdx.resize(tileCnt);
tileType.resize(tileCnt);
layerAttachments.resize(tileCnt);
}
};
ox::FileAddress tilesheet;
ox::Vector<ox::FileAddress> palettes;
// tile layer data
ox::Vector<uint16_t> columns;
ox::Vector<uint16_t> rows;
ox::Vector<ox::Vector<uint16_t>> tileMapIdx;
ox::Vector<ox::Vector<uint8_t>> tileType;
ox::Vector<ox::Vector<uint8_t>> layerAttachments;
[[nodiscard]]
constexpr Layer layer(std::size_t i) noexcept {
return {
columns[i],
rows[i],
tileMapIdx[i],
tileType[i],
layerAttachments[i],
};
}
constexpr auto setLayerCnt(std::size_t layerCnt) noexcept {
this->layerAttachments.resize(layerCnt);
this->columns.resize(layerCnt);
this->rows.resize(layerCnt);
this->tileMapIdx.resize(layerCnt);
this->tileType.resize(layerCnt);
}
};
OX_MODEL_BEGIN(SceneStatic)
OX_MODEL_FIELD(tilesheet)
OX_MODEL_FIELD(palettes)
OX_MODEL_FIELD(columns)
OX_MODEL_FIELD(rows)
OX_MODEL_FIELD(tileMapIdx)
OX_MODEL_FIELD(tileType)
OX_MODEL_FIELD(layerAttachments)
OX_MODEL_END()
}

View File

@ -1,29 +0,0 @@
add_library(
NostalgiaScene
scene.cpp
scenestatic.cpp
)
target_include_directories(
NostalgiaScene PUBLIC
../include
)
target_link_libraries(
NostalgiaScene PUBLIC
NostalgiaGfx
)
add_subdirectory(keel)
if(NOSTALGIA_BUILD_STUDIO)
add_subdirectory(studio)
endif()
install(
TARGETS
NostalgiaScene
DESTINATION
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
)

View File

@ -1,17 +0,0 @@
add_library(
NostalgiaScene-Keel
keelmodule.cpp
typeconv.cpp
)
target_link_libraries(
NostalgiaScene-Keel PUBLIC
Keel
NostalgiaScene
)
install(
TARGETS
NostalgiaScene-Keel
LIBRARY DESTINATION
${NOSTALGIA_DIST_MODULE}
)

View File

@ -1,51 +0,0 @@
/*
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#include <keel/module.hpp>
#include <nostalgia/scene/scenestatic.hpp>
#include "typeconv.hpp"
namespace nostalgia::scene {
static class: public keel::Module {
private:
SceneDocToSceneStaticConverter m_sceneDocToSceneStaticConverter;
public:
[[nodiscard]]
ox::String id() const noexcept override {
return ox::String("net.drinkingtea.nostalgia.scene");
}
[[nodiscard]]
ox::Vector<keel::TypeDescGenerator> types() const noexcept override {
return {
keel::generateTypeDesc<SceneDoc>,
keel::generateTypeDesc<SceneStatic>,
};
}
[[nodiscard]]
ox::Vector<const keel::BaseConverter*> converters() const noexcept override {
return {
&m_sceneDocToSceneStaticConverter,
};
}
[[nodiscard]]
ox::Vector<keel::PackTransform> packTransforms() const noexcept override {
return {
keel::transformRule<SceneDoc, SceneStatic>,
};
}
} mod;
const keel::Module *keelModule() noexcept {
return &mod;
}
}

View File

@ -1,68 +0,0 @@
/*
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#include <nostalgia/gfx/gfx.hpp>
#include <keel/media.hpp>
#include "typeconv.hpp"
namespace nostalgia::scene {
[[nodiscard]]
constexpr unsigned adjustLayerAttachment(unsigned layer, unsigned attachment) noexcept {
if (attachment == 0) {
return layer;
} else {
return attachment - 1;
}
}
constexpr void setLayerAttachments(unsigned layer, TileDoc const&srcTile, SceneStatic::Tile &dstTile) noexcept {
setTopEdge(
dstTile.layerAttachments,
adjustLayerAttachment(layer, srcTile.layerAttachments[0]));
setBottomEdge(
dstTile.layerAttachments,
adjustLayerAttachment(layer, srcTile.layerAttachments[1]));
setLeftEdge(
dstTile.layerAttachments,
adjustLayerAttachment(layer, srcTile.layerAttachments[2]));
setRightEdge(
dstTile.layerAttachments,
adjustLayerAttachment(layer, srcTile.layerAttachments[3]));
}
ox::Error SceneDocToSceneStaticConverter::convert(
keel::Context &ctx,
SceneDoc &src,
SceneStatic &dst) const noexcept {
OX_REQUIRE(ts, keel::readObj<gfx::TileSheet>(ctx, src.tilesheet));
const auto layerCnt = src.tiles.size();
dst.setLayerCnt(layerCnt);
dst.tilesheet = ox::FileAddress(src.tilesheet);
dst.palettes.reserve(src.palettes.size());
for (const auto &pal : src.palettes) {
dst.palettes.emplace_back(pal);
}
for (auto layerIdx = 0u; const auto &layer : src.tiles) {
const auto layerDim = src.size(layerIdx);
auto dstLayer = dst.layer(layerIdx);
dstLayer.setDimensions(layerDim);
for (auto tileIdx = 0u; const auto &row : layer) {
for (const auto &srcTile : row) {
auto dstTile = dstLayer.tile(tileIdx);
dstTile.tileType = srcTile.type;
OX_REQUIRE(path, srcTile.getSubsheetPath(*ts));
OX_REQUIRE(mapIdx, getTileOffset(*ts, path));
dstTile.tileMapIdx = static_cast<uint16_t>(mapIdx);
setLayerAttachments(layerIdx, srcTile, dstTile);
++tileIdx;
}
}
++layerIdx;
}
return {};
}
}

View File

@ -1,17 +0,0 @@
/*
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#pragma once
#include <keel/typeconv.hpp>
#include <nostalgia/scene/scenestatic.hpp>
namespace nostalgia::scene {
class SceneDocToSceneStaticConverter: public keel::Converter<SceneDoc, SceneStatic> {
ox::Error convert(keel::Context&, SceneDoc &src, SceneStatic &dst) const noexcept final;
};
}

View File

@ -1,54 +0,0 @@
/*
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#include <nostalgia/gfx/gfx.hpp>
#include <nostalgia/scene/scene.hpp>
namespace nostalgia::scene {
Scene::Scene(SceneStatic const&sceneStatic) noexcept:
m_sceneStatic(sceneStatic) {
}
ox::Error Scene::setupDisplay(gfx::Context &ctx) const noexcept {
if (m_sceneStatic.palettes.empty()) {
return ox::Error(1, "Scene has no palettes");
}
auto const&palette = m_sceneStatic.palettes[0];
OX_RETURN_ERROR(gfx::loadBgTileSheet(ctx, 0, m_sceneStatic.tilesheet));
OX_RETURN_ERROR(gfx::loadBgPalette(ctx, 0, palette));
// disable all backgrounds
gfx::setBgStatus(ctx, 0);
for (auto layerNo = 0u; auto const&layer : m_sceneStatic.tileMapIdx) {
setupLayer(ctx, layer, layerNo);
++layerNo;
}
return {};
}
void Scene::setupLayer(
gfx::Context &ctx,
ox::Vector<uint16_t> const&layer,
unsigned layerNo) const noexcept {
gfx::setBgStatus(ctx, layerNo, true);
gfx::setBgCbb(ctx, layerNo, 0);
auto x = 0;
auto y = 0;
const auto width = m_sceneStatic.rows[layerNo];
for (auto const&tile : layer) {
const auto tile8 = static_cast<uint8_t>(tile);
gfx::setBgTile(ctx, layerNo, x, y, tile8);
gfx::setBgTile(ctx, layerNo, x + 1, y, tile8 + 1);
gfx::setBgTile(ctx, layerNo, x, y + 1, tile8 + 2);
gfx::setBgTile(ctx, layerNo, x + 1, y + 1, tile8 + 3);
x += 2;
if (x >= width * 2) {
x = 0;
y += 2;
}
}
}
}

View File

@ -1,11 +0,0 @@
/*
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#include <nostalgia/scene/scenestatic.hpp>
namespace nostalgia::scene {
}

View File

@ -1,20 +0,0 @@
add_library(
NostalgiaScene-Studio
studiomodule.cpp
sceneeditor-imgui.cpp
sceneeditor.cpp
sceneeditorview.cpp
)
target_link_libraries(
NostalgiaScene-Studio PUBLIC
NostalgiaScene
Studio
)
install(
TARGETS
NostalgiaScene-Studio
LIBRARY DESTINATION
${NOSTALGIA_DIST_MODULE}
)

View File

@ -1,55 +0,0 @@
/*
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#include <imgui.h>
#include <keel/media.hpp>
#include "sceneeditor-imgui.hpp"
namespace nostalgia::scene {
SceneEditorImGui::SceneEditorImGui(studio::StudioContext &ctx, ox::StringView path):
Editor(ctx, path),
m_ctx(ctx.tctx),
m_editor(m_ctx, path),
m_view(m_ctx, m_editor.scene()) {
}
void SceneEditorImGui::draw(studio::StudioContext&) noexcept {
auto const paneSize = ImGui::GetContentRegionAvail();
m_view.draw(ox::Size{static_cast<int>(paneSize.x), static_cast<int>(paneSize.y)});
auto &fb = m_view.framebuffer();
auto const srcH = static_cast<float>(fb.height) / static_cast<float>(fb.width);
auto const dstH = paneSize.y / paneSize.x;
float xScale{}, yScale{};
if (dstH > srcH) {
// crop off width
xScale = srcH / dstH;
yScale = 1;
} else {
auto const srcW = static_cast<float>(fb.width) / static_cast<float>(fb.height);
auto const dstW = (paneSize.x / paneSize.y);
xScale = 1;
yScale = srcW / dstW;
}
uintptr_t const buffId = fb.color.id;
ImGui::Image(
std::bit_cast<void*>(buffId),
paneSize,
ImVec2(0, 1),
ImVec2(xScale, 1 - yScale));
}
void SceneEditorImGui::onActivated() noexcept {
oxLogError(m_view.setupScene());
}
ox::Error SceneEditorImGui::saveItem() noexcept {
const auto sctx = applicationData<studio::StudioContext>(m_ctx);
OX_RETURN_ERROR(sctx->project->writeObj(itemPath(), m_editor.scene()));
return {};
}
}

View File

@ -1,35 +0,0 @@
/*
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#pragma once
#include <studio/studio.hpp>
#include <turbine/context.hpp>
#include "sceneeditor.hpp"
#include "sceneeditorview.hpp"
namespace nostalgia::scene {
class SceneEditorImGui: public studio::Editor {
private:
turbine::Context &m_ctx;
SceneEditor m_editor;
SceneEditorView m_view;
public:
SceneEditorImGui(studio::StudioContext &ctx, ox::StringView path);
void draw(studio::StudioContext&) noexcept final;
void onActivated() noexcept override;
protected:
ox::Error saveItem() noexcept final;
};
}

View File

@ -1,16 +0,0 @@
/*
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#include <keel/keel.hpp>
#include "sceneeditor.hpp"
namespace nostalgia::scene {
SceneEditor::SceneEditor(turbine::Context &ctx, ox::StringViewCR path):
m_ctx(ctx),
m_scene(*keel::readObj<SceneStatic>(keelCtx(m_ctx), path).unwrapThrow()) {
}
}

View File

@ -1,34 +0,0 @@
/*
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#pragma once
#include <turbine/context.hpp>
#include <nostalgia/scene/scene.hpp>
namespace nostalgia::scene {
class SceneEditor {
private:
turbine::Context &m_ctx;
ox::String m_itemName;
ox::String m_itemPath;
SceneStatic m_scene;
public:
SceneEditor(turbine::Context &ctx, ox::StringViewCR path);
[[nodiscard]]
SceneStatic const&scene() const noexcept {
return m_scene;
}
protected:
ox::Error saveItem() noexcept;
};
}

View File

@ -1,36 +0,0 @@
/*
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#include <nostalgia/gfx/gfx.hpp>
#include "sceneeditorview.hpp"
namespace nostalgia::scene {
SceneEditorView::SceneEditorView(turbine::Context &tctx, SceneStatic const&sceneStatic):
m_cctx(gfx::init(tctx, {.glInstallDrawer = false}).unwrapThrow()),
m_sceneStatic(sceneStatic),
m_scene(m_sceneStatic) {
}
ox::Error SceneEditorView::setupScene() noexcept {
glutils::resizeInitFrameBuffer(m_frameBuffer, gfx::gl::drawSize(m_scale));
return m_scene.setupDisplay(*m_cctx);
}
void SceneEditorView::draw(ox::Size const&targetSz) noexcept {
auto const scaleSz = targetSz / gfx::gl::drawSize(1);
if (m_scaleSz != scaleSz) [[unlikely]] {
m_scale = ox::max(1, ox::max(scaleSz.width, scaleSz.height));
glutils::resizeInitFrameBuffer(m_frameBuffer, gfx::gl::drawSize(m_scale));
}
glutils::FrameBufferBind const frameBufferBind(m_frameBuffer);
gfx::gl::draw(*m_cctx, m_scale);
}
glutils::FrameBuffer const&SceneEditorView::framebuffer() const noexcept {
return m_frameBuffer;
}
}

View File

@ -1,37 +0,0 @@
/*
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#pragma once
#include <glutils/glutils.hpp>
#include <nostalgia/gfx/context.hpp>
#include <nostalgia/gfx/gfx.hpp>
#include <nostalgia/scene/scene.hpp>
namespace nostalgia::scene {
class SceneEditorView {
private:
ox::UPtr<gfx::Context> m_cctx;
SceneStatic const&m_sceneStatic;
Scene m_scene;
glutils::FrameBuffer m_frameBuffer;
int m_scale = 1;
ox::Size m_scaleSz = gfx::gl::drawSize(m_scale);
public:
SceneEditorView(turbine::Context &ctx, SceneStatic const&sceneStatic);
ox::Error setupScene() noexcept;
void draw(ox::Size const&targetSz) noexcept;
[[nodiscard]]
glutils::FrameBuffer const&framebuffer() const noexcept;
};
}

View File

@ -1,30 +0,0 @@
/*
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#include <studio/studio.hpp>
#include "sceneeditor-imgui.hpp"
namespace nostalgia::scene {
constexpr ox::StringLiteral FileExt_nscn("nscn");
static class: public studio::Module {
public:
ox::Vector<studio::EditorMaker> editors(studio::StudioContext &ctx) const noexcept override {
return {
studio::editorMaker<SceneEditorImGui>(ctx, FileExt_nscn),
};
}
ox::Vector<ox::UPtr<studio::ItemMaker>> itemMakers(studio::StudioContext&) const noexcept override {
ox::Vector<ox::UPtr<studio::ItemMaker>> out;
return out;
}
} mod;
const studio::Module *studioModule() noexcept {
return &mod;
}
}

View File

@ -6,7 +6,7 @@
#include <keel/module.hpp>
namespace nostalgia::scene {
namespace nostalgia::sound {
const keel::Module *keelModule() noexcept;

View File

@ -6,7 +6,7 @@
#include <studio/studio.hpp>
namespace nostalgia::scene {
namespace nostalgia::sound {
const studio::Module *studioModule() noexcept;

View File

@ -26,7 +26,7 @@ static class: public keel::Module {
}
[[nodiscard]]
ox::Vector<keel::BaseConverter const*> converters() const noexcept final {
ox::Vector<keel::Converter> converters() const noexcept final {
return {
};
}

View File

@ -6,16 +6,16 @@
#include <studio/studio.hpp>
namespace nostalgia::gfx {
namespace nostalgia::sound {
static class: public studio::Module {
ox::Vector<studio::EditorMaker> editors(studio::StudioContext&) const noexcept final {
ox::Vector<studio::EditorMaker> editors(studio::Context&) const noexcept final {
return {
};
}
ox::Vector<ox::UPtr<studio::ItemMaker>> itemMakers(studio::StudioContext&) const noexcept final {
ox::Vector<ox::UniquePtr<studio::ItemMaker>> out;
ox::Vector<ox::UPtr<studio::ItemMaker>> itemMakers(studio::Context&) const noexcept final {
ox::Vector<ox::UPtr<studio::ItemMaker>> out;
return out;
}
} const mod;

View File

@ -5,7 +5,7 @@
#include <studioapp/studioapp.hpp>
#include <nostalgia/gfx/studiomodule.hpp>
#include <nostalgia/scene/studiomodule.hpp>
#include <nostalgia/sound/studiomodule.hpp>
namespace nostalgia {
@ -16,7 +16,7 @@ void registerStudioModules() noexcept {
}
modulesRegistered = true;
studio::registerModule(gfx::studioModule());
studio::registerModule(scene::studioModule());
studio::registerModule(sound::studioModule());
}
}

View File

@ -6,7 +6,6 @@
#include <turbine/turbine.hpp>
#include <nostalgia/gfx/core.hpp>
#include <nostalgia/scene/scene.hpp>
using namespace nostalgia;
@ -65,15 +64,12 @@ static void testKeyEventHandler(turbine::Context &tctx, turbine::Key key, bool d
[[maybe_unused]]
static ox::Error runTest(turbine::Context &tctx) {
constexpr ox::StringView TileSheetAddr{"/TileSheets/Charset.nts"};
constexpr ox::StringView PaletteAddr{"/Palettes/Chester.npal"};
OX_REQUIRE_M(cctx, gfx::init(tctx));
turbine::setApplicationData(tctx, cctx.get());
OX_REQUIRE(tsStat, turbine::rom(tctx)->stat(PaletteAddr));
OX_RETURN_ERROR(gfx::loadSpriteTileSheet(*cctx, TileSheetAddr));
OX_RETURN_ERROR(gfx::loadSpritePalette(*cctx, PaletteAddr));
OX_RETURN_ERROR(gfx::loadSpriteTileSheet(*cctx, "/TileSheets/Charset.nts"));
OX_RETURN_ERROR(gfx::loadSpritePalette(*cctx, "/Palettes/Chester.npal"));
OX_RETURN_ERROR(gfx::initConsole(*cctx));
gfx::puts(*cctx, 10, 9, "DOPENESS!!!");
gfx::consoleWrite(*cctx, 10, 9, "DOPENESS!!!");
turbine::setUpdateHandler(tctx, testUpdateHandler);
turbine::setKeyEventHandler(tctx, testKeyEventHandler);
return turbine::run(tctx);
@ -87,7 +83,6 @@ static ox::Error runTileSheetSetTest(turbine::Context &tctx) {
constexpr ox::StringView PaletteAddr{"/Palettes/Charset.npal"};
OX_REQUIRE_M(cctx, gfx::init(tctx));
turbine::setApplicationData(tctx, cctx.get());
OX_REQUIRE(tsStat, turbine::rom(tctx)->stat(PaletteAddr));
gfx::TileSheetSet const set{
.bpp = 4,
.entries = {
@ -126,46 +121,15 @@ static ox::Error runTileSheetSetTest(turbine::Context &tctx) {
}
static int sceneUpdateHandler(turbine::Context&) noexcept {
constexpr auto sleepTime = 16;
if (s_paused) {
return sleepTime;
}
// do stuff
return sleepTime;
}
static void sceneKeyEventHandler(turbine::Context &tctx, turbine::Key key, bool down) noexcept {
if (down) {
if (key == turbine::Key::Alpha_Q) {
turbine::requestShutdown(tctx);
} else if (key == turbine::Key::Alpha_P) {
s_paused = !s_paused;
}
}
}
[[maybe_unused]]
static ox::Error runScene(turbine::Context &tctx) {
OX_REQUIRE_M(cctx, gfx::init(tctx));
OX_REQUIRE(scn, keel::readObj<scene::SceneStatic>(keelCtx(tctx), "/Scenes/Chester.nscn"));
turbine::setUpdateHandler(tctx, sceneUpdateHandler);
turbine::setKeyEventHandler(tctx, sceneKeyEventHandler);
scene::Scene const scene(*scn);
OX_RETURN_ERROR(scene.setupDisplay(*cctx));
return turbine::run(tctx);
}
ox::Error run(
[[maybe_unused]] ox::StringView project,
[[maybe_unused]] ox::StringView appName,
[[maybe_unused]] ox::StringView projectDataDir,
ox::SpanView<char const*> args) noexcept {
ox::SpanView<ox::CString> args) noexcept {
if (args.size() < 2) {
return ox::Error{1, "Please provide path to project directory or OxFS file."};
}
auto const path = args[1];
OX_REQUIRE_M(fs, keel::loadRomFs(path));
OX_REQUIRE_M(tctx, turbine::init(std::move(fs), project));
OX_REQUIRE_M(tctx, turbine::init(path, project));
return runTileSheetSetTest(*tctx);
}

View File

@ -1,4 +1,8 @@
add_executable(NostalgiaStudio WIN32 MACOSX_BUNDLE)
add_executable(
NostalgiaStudio WIN32 MACOSX_BUNDLE
ns.rc
icondata.cpp
)
target_link_libraries(
NostalgiaStudio
@ -11,7 +15,7 @@ target_link_libraries(
target_compile_definitions(
NostalgiaStudio PUBLIC
OLYMPIC_APP_VERSION="dev build"
OLYMPIC_APP_VERSION="d2025.05.1"
)
install(

View File

@ -18,7 +18,7 @@
<string>APPL</string>
<key>CFBundleVersion</key>
<string>dev build</string>
<string>d2025.05.1</string>
<key>LSMinimumSystemVersion</key>
<string>12.0.0</string>

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1 @@
IDI_ICON1 ICON DISCARDABLE "ns_logo.ico"

Binary file not shown.

After

Width:  |  Height:  |  Size: 162 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 851 B

Some files were not shown because too many files have changed in this diff Show More