Compare commits

..

40 Commits

Author SHA1 Message Date
c7bc2a954f [nostalgia/gfx] Style update
All checks were successful
Build / build (push) Successful in 1m15s
2025-07-24 21:35:21 -05:00
7372036a0a [nostalgia/gfx] Add function missing from header
All checks were successful
Build / build (push) Successful in 1m14s
2025-07-24 21:25:26 -05:00
7461d832b6 [nostalgia/gfx/studio,studio] Fix CLI tool output to only show usage if no args given
All checks were successful
Build / build (push) Successful in 1m19s
2025-07-24 21:17:58 -05:00
6052798fea Merge commit 'dceeaaa9302b7e9ce85fa773fc187bc593f3c93c'
All checks were successful
Build / build (push) Successful in 1m16s
2025-07-24 01:58:27 -05:00
fae1e73e54 [nostalgia/gfx] Make getSubSheet check root subsheet name
All checks were successful
Build / build (push) Successful in 1m17s
2025-07-24 01:54:06 -05:00
51f2905c9c [nostalgia/gfx/studio] Make TileSheetEditor use export-tilesheet functions for export, fix exporting Root subsheet
All checks were successful
Build / build (push) Successful in 1m18s
2025-07-24 01:45:27 -05:00
0c866d1b96 [studio,nostalgia/gfx] Add system for adding sub-commands in Modules, add export-tilesheet command
All checks were successful
Build / build (push) Successful in 1m16s
2025-07-24 01:29:09 -05:00
fdf39d1a25 [ox/std] Add Result::transformError 2025-07-24 01:24:11 -05:00
a523a75e4b [ox/std] Add missing include to StringParam 2025-07-24 01:23:58 -05:00
cdaa64ed3f [ox/clargs] Fix arg parsing for first '-' 2025-07-24 01:23:31 -05:00
801d35c823 [keel] Make type converters work with functions that take const src arg 2025-07-23 00:41:33 -05:00
37b5fcc0f7 [teagba] Put parentheses around all registers
All checks were successful
Build / build (push) Successful in 1m18s
2025-07-07 23:36:34 -05:00
f5f2c3bee6 [studio/applib] Make Studio remove files unable to be opened from open file list in config 2025-07-07 23:35:28 -05:00
f6ef2b5acb [turbine,nostalgia] Make memory regions cast to bounded ox::Arrays
All checks were successful
Build / build (push) Successful in 1m16s
2025-06-29 23:32:36 -05:00
bf958a4a6e [teagba] Make memory regions cast to bounded ox::Arrays 2025-06-29 23:32:11 -05:00
6a70e478a6 [nostalgia/gfx] Cleanup 2025-06-29 17:46:13 -05:00
671b8edaad [ox/std] Make StringLiteral constructors consteval
All checks were successful
Build / build (push) Successful in 1m29s
2025-06-27 23:05:42 -05:00
952637a1ea Merge commit 'cbf4414fcaf00c00a2abf73b5c04a055180ad980'
All checks were successful
Build / build (push) Successful in 1m37s
2025-06-25 21:33:16 -05:00
7569698e95 [nostalgia,studio] Add FileExts_TileSheet const, and corresponding FilePickerPopup constructor 2025-06-25 21:30:49 -05:00
21713ba945 [ox/std] Fix StringLiteral::operator= to work with DevkitARM 2025-06-25 21:29:41 -05:00
73273b6fa7 [nostalgia/gfx] Add isTileSheet function for checking paths against both file extensions 2025-06-25 21:03:45 -05:00
9f040392c7 [olympic,nostalgia] Cleanup style
All checks were successful
Build / build (push) Successful in 1m18s
2025-06-24 01:59:22 -05:00
f4f7e5d053 Merge commit '9b5f7886cadc5c3dc826d00fa5b2e71696151dfd' 2025-06-23 20:49:01 -05:00
f847289bd4 [glutils] Cleanup
All checks were successful
Build / build (push) Successful in 1m20s
2025-06-23 01:39:47 -05:00
94b0020d15 [nostalgia,olympic] Cleanup
All checks were successful
Build / build (push) Successful in 1m16s
2025-06-23 01:30:33 -05:00
c54c0bad38 [teagba] Cleanup
All checks were successful
Build / build (push) Successful in 1m20s
2025-06-23 01:03:33 -05:00
b9ffae0269 [nostalgia/gfx] Cleanup
All checks were successful
Build / build (push) Successful in 1m18s
2025-06-23 00:47:46 -05:00
003f3e01c6 [nostalgia] Update release notes 2025-06-22 01:01:09 -05:00
9028e74af0 [nostalgia/gfx/studio/tilesheet] Disable paste when nothing is selected 2025-06-22 01:00:56 -05:00
f5ccab5f2c [studio] Cleanup 2025-06-21 19:19:39 -05:00
c27726a4a9 Merge commit '6bbcae10cc7b21b73171ec0ff196f4baf6304404' 2025-06-21 14:29:47 -05:00
37cfa927d1 [nostalgia/gfx] Address a couple of implicit conversions
All checks were successful
Build / build (push) Successful in 1m19s
2025-06-21 14:16:17 -05:00
0efed70b57 [studio] Fix Studio to clear editor pointers when opening a new project
All checks were successful
Build / build (push) Successful in 1m20s
2025-06-21 14:12:45 -05:00
bd24a775b2 Merge commit '7371df429534f264c179684412f6197f7968ebfa' 2025-06-21 08:48:13 -05:00
4419dff299 Merge commit '7688c05bac8c20bc267cae62ec78d55e5d0c493b' 2025-05-31 02:14:15 -05:00
536999c070 Merge commit '47eee1d56d591e3631d16e95a78ea3629ee312ee' 2025-05-30 23:38:53 -05:00
a5535ef59a Merge commit '08236fc790e711afe886b6ef545511d35e4e5c6c' 2025-05-24 01:44:07 -05:00
a90380f377 Merge commit 'e90dd887477452922f783535edb3d4c55e9a0d2c' 2025-05-23 03:23:17 -05:00
2000b2deee [nostalgia/gfx/studio] Cleanup 2025-05-17 23:35:10 -05:00
7d92400f6d [nostalgia/gfx/studio] Add type specific navigateTo functions 2025-05-17 23:26:23 -05:00
109 changed files with 1037 additions and 681 deletions

View File

@@ -89,7 +89,7 @@ struct GLObject: public Base {
return id;
}
constexpr operator const GLuint&() const noexcept {
constexpr operator GLuint const&() const noexcept {
return id;
}
@@ -135,7 +135,7 @@ struct FrameBuffer {
return fbo.id;
}
constexpr operator const GLuint&() const noexcept {
constexpr operator GLuint const&() const noexcept {
return fbo.id;
}
@@ -158,14 +158,14 @@ struct FrameBuffer {
class FrameBufferBind {
private:
static const FrameBuffer *s_activeFb;
const FrameBuffer *m_restoreFb = nullptr;
static FrameBuffer const *s_activeFb;
FrameBuffer const *m_restoreFb = nullptr;
public:
explicit FrameBufferBind(const FrameBuffer &fb) noexcept;
explicit FrameBufferBind(FrameBuffer const &fb) noexcept;
~FrameBufferBind() noexcept;
};
void bind(const FrameBuffer &fb) noexcept;
void bind(FrameBuffer const &fb) noexcept;
struct ShaderVarSet {
GLsizei len{};
@@ -201,9 +201,9 @@ void setupShaderParams(
void setupShaderParams(GLProgram const &shader, ox::Vector<ShaderVarSet> const &vars) noexcept;
glutils::GLVertexArray generateVertexArrayObject() noexcept;
GLVertexArray generateVertexArrayObject() noexcept;
glutils::GLBuffer generateBuffer() noexcept;
GLBuffer generateBuffer() noexcept;
[[nodiscard]]
FrameBuffer generateFrameBuffer(int width, int height) noexcept;
@@ -218,10 +218,10 @@ void resizeInitFrameBuffer(FrameBuffer &fb, int width, int height) noexcept;
void resizeInitFrameBuffer(FrameBuffer &fb, ox::Size const &sz) noexcept;
struct BufferSet {
glutils::GLVertexArray vao;
glutils::GLBuffer vbo;
glutils::GLBuffer ebo;
glutils::GLTexture tex;
GLVertexArray vao;
GLBuffer vbo;
GLBuffer ebo;
GLTexture tex;
ox::Vector<float> vertices;
ox::Vector<GLuint> elements;
};

View File

@@ -46,9 +46,9 @@ template struct GLObject<deleteVertexArray>;
template struct GLObject<deleteProgram>;
template struct GLObject<deleteShader>;
const FrameBuffer *FrameBufferBind::s_activeFb = nullptr;
FrameBuffer const *FrameBufferBind::s_activeFb = nullptr;
FrameBufferBind::FrameBufferBind(const FrameBuffer &fb) noexcept: m_restoreFb(s_activeFb) {
FrameBufferBind::FrameBufferBind(FrameBuffer const &fb) noexcept: m_restoreFb(s_activeFb) {
s_activeFb = &fb;
glBindFramebuffer(GL_FRAMEBUFFER, fb);
glViewport(0, 0, fb.width, fb.height);
@@ -64,15 +64,15 @@ FrameBufferBind::~FrameBufferBind() noexcept {
}
}
void bind(const FrameBuffer &fb) noexcept {
void bind(FrameBuffer const &fb) noexcept {
glBindFramebuffer(GL_FRAMEBUFFER, fb);
glViewport(0, 0, fb.width, fb.height);
}
static ox::Result<GLShader> buildShader(
GLuint shaderType,
const GLchar *src,
GLuint const shaderType,
GLchar const *src,
ox::StringViewCR shaderName) noexcept {
GLShader shader(glCreateShader(shaderType));
glShaderSource(shader, 1, &src, nullptr);
@@ -162,16 +162,30 @@ FrameBuffer generateFrameBuffer(int width, int height) noexcept {
// color texture
glGenTextures(1, &fb.color.id);
glBindTexture(GL_TEXTURE_2D, fb.color);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr);
glTexImage2D(
GL_TEXTURE_2D,
0,
GL_RGB,
width,
height,
0,
GL_RGB,
GL_UNSIGNED_BYTE,
nullptr);
glGenerateMipmap(GL_TEXTURE_2D);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, fb.color, 0);
glFramebufferTexture2D(
GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, fb.color, 0);
// depth texture
glGenRenderbuffers(1, &fb.depth.id);
glBindRenderbuffer(GL_RENDERBUFFER, fb.depth);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, width, height);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, fb.depth);
glFramebufferRenderbuffer(
GL_FRAMEBUFFER,
GL_DEPTH_STENCIL_ATTACHMENT,
GL_RENDERBUFFER,
fb.depth);
// verify FBO
oxAssert(glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE, "Frame Buffer is incomplete");
// restore primary FB
@@ -189,7 +203,16 @@ void resizeFrameBuffer(FrameBuffer &fb, int width, int height) noexcept {
glBindFramebuffer(GL_FRAMEBUFFER, fb);
// color texture
glBindTexture(GL_TEXTURE_2D, fb.color);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr);
glTexImage2D(
GL_TEXTURE_2D,
0,
GL_RGB,
width,
height,
0,
GL_RGB,
GL_UNSIGNED_BYTE,
nullptr);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
// depth texture
@@ -201,7 +224,7 @@ void resizeFrameBuffer(FrameBuffer &fb, int width, int height) noexcept {
glBindRenderbuffer(GL_RENDERBUFFER, 0);
}
void resizeInitFrameBuffer(FrameBuffer &fb, int width, int height) noexcept {
void resizeInitFrameBuffer(FrameBuffer &fb, int const width, int const height) noexcept {
if (!fb) {
fb = generateFrameBuffer(width, height);
return;
@@ -214,13 +237,13 @@ void resizeInitFrameBuffer(FrameBuffer &fb, ox::Size const&sz) noexcept {
}
void sendVbo(BufferSet const &bs) noexcept {
const auto bufferSize = static_cast<GLsizeiptr>(sizeof(decltype(bs.vertices)::value_type) * bs.vertices.size());
auto const bufferSize = static_cast<GLsizeiptr>(sizeof(decltype(bs.vertices)::value_type) * bs.vertices.size());
glBindBuffer(GL_ARRAY_BUFFER, bs.vbo);
glBufferData(GL_ARRAY_BUFFER, bufferSize, bs.vertices.data(), GL_DYNAMIC_DRAW);
}
void sendEbo(BufferSet const &bs) noexcept {
const auto bufferSize = static_cast<GLsizeiptr>(sizeof(decltype(bs.elements)::value_type) * bs.elements.size());
auto const bufferSize = static_cast<GLsizeiptr>(sizeof(decltype(bs.elements)::value_type) * bs.elements.size());
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bs.ebo);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, bufferSize, bs.elements.data(), GL_STATIC_DRAW);
}

View File

@@ -15,7 +15,7 @@ ClArgs::ClArgs(int argc, const char **args) noexcept: ClArgs({args, static_cast<
ClArgs::ClArgs(ox::SpanView<const char*> args) noexcept {
for (auto i = 0u; i < args.size(); ++i) {
auto arg = StringView(args[i]);
auto arg = StringView{args[i]};
if (arg[0] == '-') {
while (arg[0] == '-' && arg.len()) {
arg = substr(arg, 1);
@@ -23,8 +23,8 @@ ClArgs::ClArgs(ox::SpanView<const char*> args) noexcept {
m_bools[arg] = true;
// parse additional arguments
if (i < args.size() && args[i + 1]) {
auto val = String(args[i + 1]);
if (val.len() && val[i] != '-') {
auto const val = StringView{args[i + 1]};
if (val.len() && val[0] != '-') {
if (val == "false") {
m_bools[arg] = false;
}
@@ -40,17 +40,17 @@ ClArgs::ClArgs(ox::SpanView<const char*> args) noexcept {
}
bool ClArgs::getBool(ox::StringViewCR arg, bool defaultValue) const noexcept {
auto [value, err] = m_ints.at(arg);
auto const [value, err] = m_ints.at(arg);
return !err ? *value : defaultValue;
}
String ClArgs::getString(ox::StringViewCR arg, ox::StringView defaultValue) const noexcept {
auto [value, err] = m_strings.at(arg);
auto const [value, err] = m_strings.at(arg);
return !err ? ox::String(*value) : ox::String(defaultValue);
}
int ClArgs::getInt(ox::StringViewCR arg, int defaultValue) const noexcept {
auto [value, err] = m_ints.at(arg);
auto const [value, err] = m_ints.at(arg);
return !err ? *value : defaultValue;
}

View File

@@ -307,6 +307,13 @@ struct [[nodiscard]] Result {
return std::move(value);
}
constexpr Result transformError(ErrorCode const ec, CString const msg) && {
if (error) {
error = Error{ec, msg};
}
return *this;
}
};
namespace detail {

View File

@@ -16,35 +16,28 @@ namespace ox {
* StringLiteral is used for functions that want to ensure that they are taking
* string literals, and not strings outside of the data section of the program
* that might get deleted.
* This type cannot force you to use it correctly, so don't give it something
* that is not a literal.
* If you do this:
* StringLiteral(str.c_str())
* the resulting segfault is on you.
*/
class StringLiteral: public detail::BaseStringView {
public:
constexpr StringLiteral() noexcept = default;
consteval StringLiteral() noexcept = default;
constexpr StringLiteral(StringLiteral const &sv) noexcept = default;
constexpr explicit StringLiteral(std::nullptr_t) noexcept {}
consteval explicit StringLiteral(std::nullptr_t) noexcept {}
constexpr explicit StringLiteral(const char *str, std::size_t len) noexcept: BaseStringView(str, len) {}
consteval explicit StringLiteral(char const *str, std::size_t const len) noexcept: BaseStringView{str, len} {}
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
constexpr explicit StringLiteral(char const *str) noexcept: StringLiteral(str, ox::strlen(str)) {}
consteval 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) {
set(other.data(), other.len());
}
return *this;
}
[[nodiscard]]
constexpr const char *c_str() const noexcept {
constexpr char const *c_str() const noexcept {
return data();
}

View File

@@ -8,6 +8,7 @@
#pragma once
#include "cstringview.hpp"
#include "string.hpp"
namespace ox {

View File

@@ -5,103 +5,101 @@
#pragma once
#include <ox/std/array.hpp>
#include <ox/std/types.hpp>
#include <ox/std/units.hpp>
/////////////////////////////////////////////////////////////////
// Interrupt Handler
using interrupt_handler = void (*)();
#define REG_ISR *reinterpret_cast<interrupt_handler*>(0x0300'7FFC)
#define REG_IE *reinterpret_cast<volatile uint16_t*>(0x0400'0200)
#define REG_IF *reinterpret_cast<volatile uint16_t*>(0x0400'0202)
#define REG_IME *reinterpret_cast<volatile uint16_t*>(0x0400'0208)
using InterruptHandler = void(*)();
#define REG_ISR (*reinterpret_cast<InterruptHandler*>(0x0300'7FFC))
#define REG_IE (*reinterpret_cast<volatile uint16_t*>(0x0400'0200))
#define REG_IF (*reinterpret_cast<volatile uint16_t*>(0x0400'0202))
#define REG_IME (*reinterpret_cast<volatile uint16_t*>(0x0400'0208))
/////////////////////////////////////////////////////////////////
// Display Registers
#define REG_DISPCTL *reinterpret_cast<volatile uint32_t*>(0x0400'0000)
#define REG_DISPSTAT *reinterpret_cast<volatile uint32_t*>(0x0400'0004)
#define REG_VCOUNT *reinterpret_cast<volatile uint32_t*>(0x0400'0006)
#define REG_DISPCTL (*reinterpret_cast<volatile uint32_t*>(0x0400'0000))
#define REG_DISPSTAT (*reinterpret_cast<volatile uint32_t*>(0x0400'0004))
#define REG_VCOUNT (*reinterpret_cast<volatile uint32_t*>(0x0400'0006))
/////////////////////////////////////////////////////////////////
// Timers
#define REG_TIMER0 *reinterpret_cast<volatile uint16_t*>(0x0400'0100)
#define REG_TIMER0CTL *reinterpret_cast<volatile uint16_t*>(0x0400'0102)
#define REG_TIMER0 (*reinterpret_cast<volatile uint16_t*>(0x0400'0100))
#define REG_TIMER0CTL (*reinterpret_cast<volatile uint16_t*>(0x0400'0102))
#define REG_TIMER1 *reinterpret_cast<volatile uint16_t*>(0x0400'0104)
#define REG_TIMER1CTL *reinterpret_cast<volatile uint16_t*>(0x0400'0106)
#define REG_TIMER1 (*reinterpret_cast<volatile uint16_t*>(0x0400'0104))
#define REG_TIMER1CTL (*reinterpret_cast<volatile uint16_t*>(0x0400'0106))
#define REG_TIMER2 *reinterpret_cast<volatile uint16_t*>(0x0400'0108)
#define REG_TIMER2CTL *reinterpret_cast<volatile uint16_t*>(0x0400'010a)
#define REG_TIMER2 (*reinterpret_cast<volatile uint16_t*>(0x0400'0108))
#define REG_TIMER2CTL (*reinterpret_cast<volatile uint16_t*>(0x0400'010a))
#define REG_TIMER3 *reinterpret_cast<volatile uint16_t*>(0x0400'010c)
#define REG_TIMER3CTL *reinterpret_cast<volatile uint16_t*>(0x0400'010e)
#define REG_TIMER3 (*reinterpret_cast<volatile uint16_t*>(0x0400'010c))
#define REG_TIMER3CTL (*reinterpret_cast<volatile uint16_t*>(0x0400'010e))
/////////////////////////////////////////////////////////////////
// background registers
// background control registers
using BgCtl = uint16_t;
#define REG_BG0CTL *reinterpret_cast<volatile BgCtl*>(0x0400'0008)
#define REG_BG1CTL *reinterpret_cast<volatile BgCtl*>(0x0400'000a)
#define REG_BG2CTL *reinterpret_cast<volatile BgCtl*>(0x0400'000c)
#define REG_BG3CTL *reinterpret_cast<volatile BgCtl*>(0x0400'000e)
#define REG_BG0CTL (*reinterpret_cast<volatile BgCtl*>(0x0400'0008))
#define REG_BG1CTL (*reinterpret_cast<volatile BgCtl*>(0x0400'000a))
#define REG_BG2CTL (*reinterpret_cast<volatile BgCtl*>(0x0400'000c))
#define REG_BG3CTL (*reinterpret_cast<volatile BgCtl*>(0x0400'000e))
[[nodiscard]]
inline volatile BgCtl &regBgCtl(uintptr_t bgIdx) noexcept {
inline volatile BgCtl &regBgCtl(uintptr_t const bgIdx) noexcept {
return *reinterpret_cast<volatile BgCtl*>(0x0400'0008 + 2 * bgIdx);
}
// background horizontal scrolling registers
#define REG_BG0HOFS *reinterpret_cast<volatile uint32_t*>(0x0400'0010)
#define REG_BG1HOFS *reinterpret_cast<volatile uint32_t*>(0x0400'0014)
#define REG_BG2HOFS *reinterpret_cast<volatile uint32_t*>(0x0400'0018)
#define REG_BG3HOFS *reinterpret_cast<volatile uint32_t*>(0x0400'001c)
#define REG_BG0HOFS (*reinterpret_cast<volatile uint32_t*>(0x0400'0010))
#define REG_BG1HOFS (*reinterpret_cast<volatile uint32_t*>(0x0400'0014))
#define REG_BG2HOFS (*reinterpret_cast<volatile uint32_t*>(0x0400'0018))
#define REG_BG3HOFS (*reinterpret_cast<volatile uint32_t*>(0x0400'001c))
[[nodiscard]]
inline volatile uint32_t &regBgHofs(auto bgIdx) noexcept {
volatile uint32_t &regBgHofs(auto const bgIdx) noexcept {
return *reinterpret_cast<volatile uint32_t*>(0x0400'0010 + 4 * bgIdx);
}
// background vertical scrolling registers
#define REG_BG0VOFS *reinterpret_cast<volatile uint32_t*>(0x0400'0012)
#define REG_BG1VOFS *reinterpret_cast<volatile uint32_t*>(0x0400'0016)
#define REG_BG2VOFS *reinterpret_cast<volatile uint32_t*>(0x0400'001a)
#define REG_BG3VOFS *reinterpret_cast<volatile uint32_t*>(0x0400'001e)
#define REG_BG0VOFS (*reinterpret_cast<volatile uint32_t*>(0x0400'0012))
#define REG_BG1VOFS (*reinterpret_cast<volatile uint32_t*>(0x0400'0016))
#define REG_BG2VOFS (*reinterpret_cast<volatile uint32_t*>(0x0400'001a))
#define REG_BG3VOFS (*reinterpret_cast<volatile uint32_t*>(0x0400'001e))
[[nodiscard]]
inline volatile uint32_t &regBgVofs(auto bgIdx) noexcept {
volatile uint32_t &regBgVofs(auto const bgIdx) noexcept {
return *reinterpret_cast<volatile uint32_t*>(0x0400'0012 + 4 * bgIdx);
}
/////////////////////////////////////////////////////////////////
// User Input
#define REG_GAMEPAD *reinterpret_cast<volatile uint16_t*>(0x0400'0130)
#define REG_GAMEPAD (*reinterpret_cast<volatile uint16_t*>(0x0400'0130))
/////////////////////////////////////////////////////////////////
// Memory Addresses
#define MEM_EWRAM_BEGIN reinterpret_cast<uint8_t*>(0x0200'0000)
#define MEM_EWRAM_END reinterpret_cast<uint8_t*>(0x0203'FFFF)
#define MEM_EWRAM (*reinterpret_cast<ox::Array<uint16_t, 0x0203'FFFF - 0x0200'0000>*>(0x0200'0000))
#define MEM_IWRAM_BEGIN reinterpret_cast<uint8_t*>(0x0300'0000)
#define MEM_IWRAM_END reinterpret_cast<uint8_t*>(0x0300'7FFF)
#define MEM_IWRAM (*reinterpret_cast<ox::Array<uint8_t, 0x0300'7FFF - 0x0300'0000>*>(0x0300'0000))
#define REG_BLNDCTL *reinterpret_cast<uint16_t*>(0x0400'0050)
#define REG_BLNDCTL (*reinterpret_cast<uint16_t*>(0x0400'0050))
#define MEM_BG_PALETTE reinterpret_cast<uint16_t*>(0x0500'0000)
#define MEM_SPRITE_PALETTE reinterpret_cast<uint16_t*>(0x0500'0200)
using Palette = ox::Array<uint16_t, 128>;
#define MEM_BG_PALETTE (*reinterpret_cast<::Palette*>(0x0500'0000))
#define MEM_SPRITE_PALETTE (*reinterpret_cast<::Palette*>(0x0500'0200))
using BgMapTile = ox::Array<uint16_t, 8192>;
#define MEM_BG_TILES reinterpret_cast<BgMapTile*>(0x0600'0000)
#define MEM_BG_MAP reinterpret_cast<BgMapTile*>(0x0600'e000)
#define MEM_BG_TILES (*reinterpret_cast<ox::Array<BgMapTile, 4>*>(0x0600'0000))
#define MEM_BG_MAP (*reinterpret_cast<ox::Array<BgMapTile, 4>*>(0x0600'e000))
#define MEM_SPRITE_TILES reinterpret_cast<uint16_t*>(0x0601'0000)
#define MEM_OAM reinterpret_cast<uint64_t*>(0x0700'0000)
#define MEM_SPRITE_TILES (*reinterpret_cast<ox::Array<uint16_t, 32 * ox::units::KB>*>(0x0601'0000))
#define MEM_OAM (*reinterpret_cast<ox::Array<uint64_t, 64>*>(0x0700'0000))
#define MEM_ROM reinterpret_cast<char*>(0x0800'0000)
#define MEM_ROM (*reinterpret_cast<ox::Array<char, 32 * ox::units::MB>*>(0x0700'0000))
#define MEM_SRAM reinterpret_cast<char*>(0x0e00'0000)
#define MEM_SRAM_SIZE 65535
#define MEM_SRAM (*reinterpret_cast<ox::Array<char, 64 * ox::units::KB>*>(0x0e00'0000))

View File

@@ -37,7 +37,7 @@ struct OX_ALIGN8 GbaSpriteAttrUpdate {
GbaSpriteAttrUpdate &spriteAttr(size_t i) noexcept;
void addSpriteUpdate(const GbaSpriteAttrUpdate &upd) noexcept;
void addSpriteUpdate(GbaSpriteAttrUpdate const &upd) noexcept;
void applySpriteUpdates() noexcept;

View File

@@ -26,7 +26,7 @@ extern void (*__preinit_array_end[]) (void);
extern void (*__init_array_start[]) (void);
extern void (*__init_array_end[]) (void);
int main(int argc, const char **argv);
int main(int argc, char const **argv);
extern "C" {
@@ -50,7 +50,7 @@ void __libc_init_array() {
}
int c_start() {
const char *args[2] = {"", "rom.oxfs"};
char const *args[2] = {"", "rom.oxfs"};
ox::heapmgr::initHeap(HEAP_BEGIN, HEAP_END);
mgba::initConsole();
#pragma GCC diagnostic push

View File

@@ -16,7 +16,7 @@ GbaSpriteAttrUpdate &spriteAttr(size_t i) noexcept {
return g_spriteBuffer[i];
}
void addSpriteUpdate(const GbaSpriteAttrUpdate &upd) noexcept {
void addSpriteUpdate(GbaSpriteAttrUpdate const &upd) noexcept {
const auto ie = REG_IE; // disable vblank interrupt handler
REG_IE = REG_IE & static_cast<uint16_t>(~teagba::Int_vblank); // disable vblank interrupt handler
g_spriteBuffer[upd.idx] = upd;

View File

@@ -19,10 +19,10 @@ using Color32 = uint32_t;
[[nodiscard]]
constexpr Color32 toColor32(Color16 nc) noexcept {
const auto r = static_cast<Color32>(((nc & 0b0000000000011111) >> 0) * 8);
const auto g = static_cast<Color32>(((nc & 0b0000001111100000) >> 5) * 8);
const auto b = static_cast<Color32>(((nc & 0b0111110000000000) >> 10) * 8);
const auto a = static_cast<Color32>(255);
auto const r = static_cast<Color32>(((nc & 0b0000000000011111) >> 0) * 8);
auto const g = static_cast<Color32>(((nc & 0b0000001111100000) >> 5) * 8);
auto const b = static_cast<Color32>(((nc & 0b0111110000000000) >> 10) * 8);
auto const a = static_cast<Color32>(255);
return r | (g << 8) | (b << 16) | (a << 24);
}

View File

@@ -12,8 +12,18 @@ constexpr auto TileWidth = 8;
constexpr auto TileHeight = 8;
constexpr auto PixelsPerTile = TileWidth * TileHeight;
constexpr ox::StringLiteral FileExt_ng("ng");
constexpr ox::StringLiteral FileExt_nts("nts");
constexpr ox::StringLiteral FileExt_npal("npal");
constexpr ox::StringLiteral FileExt_ng{"ng"};
constexpr ox::StringLiteral FileExt_nts{"nts"};
constexpr ox::StringLiteral FileExt_npal{"npal"};
constexpr ox::Array<ox::StringLiteral, 2> FileExts_TileSheet{
FileExt_nts,
FileExt_ng,
};
[[nodiscard]]
constexpr bool isTileSheet(ox::StringViewCR path) noexcept {
return endsWith(path, FileExt_nts) || endsWith(path, FileExt_ng);
}
}

View File

@@ -114,10 +114,10 @@ struct InitParams {
ox::Result<ox::UPtr<Context>> init(turbine::Context &tctx, InitParams const &params = {}) noexcept;
[[nodiscard]]
int tileColumns(Context&) noexcept;
int tileColumns(Context const&) noexcept;
[[nodiscard]]
int tileRows(Context&) noexcept;
int tileRows(Context const&) noexcept;
ox::Error loadBgPalette(
Context &ctx,

View File

@@ -11,39 +11,39 @@
namespace nostalgia::gfx {
[[nodiscard]]
constexpr std::size_t ptToIdx(int x, int y, int c, int scale = 1) noexcept {
const auto tileWidth = TileWidth * scale;
const auto tileHeight = TileHeight * scale;
const auto pixelsPerTile = tileWidth * tileHeight;
const auto colLength = static_cast<std::size_t>(pixelsPerTile);
const auto rowLength = static_cast<std::size_t>(static_cast<std::size_t>(c / tileWidth) * colLength);
const auto colStart = static_cast<std::size_t>(colLength * static_cast<std::size_t>(x / tileWidth));
const auto rowStart = static_cast<std::size_t>(rowLength * static_cast<std::size_t>(y / tileHeight));
const auto colOffset = static_cast<std::size_t>(x % tileWidth);
const auto rowOffset = static_cast<std::size_t>((y % tileHeight) * tileHeight);
constexpr std::size_t ptToIdx(int const x, int const y, int const c, int const scale = 1) noexcept {
auto const tileWidth = TileWidth * scale;
auto const tileHeight = TileHeight * scale;
auto const pixelsPerTile = tileWidth * tileHeight;
auto const colLength = static_cast<std::size_t>(pixelsPerTile);
auto const rowLength = static_cast<std::size_t>(static_cast<std::size_t>(c / tileWidth) * colLength);
auto const colStart = static_cast<std::size_t>(colLength * static_cast<std::size_t>(x / tileWidth));
auto const rowStart = static_cast<std::size_t>(rowLength * static_cast<std::size_t>(y / tileHeight));
auto const colOffset = static_cast<std::size_t>(x % tileWidth);
auto const rowOffset = static_cast<std::size_t>((y % tileHeight) * tileHeight);
return static_cast<std::size_t>(colStart + colOffset + rowStart + rowOffset);
}
[[nodiscard]]
constexpr std::size_t ptToIdx(const ox::Point &pt, int c, int scale = 1) noexcept {
constexpr std::size_t ptToIdx(ox::Point const &pt, int const c, int const scale = 1) noexcept {
return ptToIdx(pt.x, pt.y, c * TileWidth, scale);
}
[[nodiscard]]
constexpr ox::Point idxToPt(int i, int c, int scale = 1) noexcept {
const auto tileWidth = TileWidth * scale;
const auto tileHeight = TileHeight * scale;
const auto pixelsPerTile = tileWidth * tileHeight;
constexpr ox::Point idxToPt(int const i, int c, int const scale = 1) noexcept {
auto const tileWidth = TileWidth * scale;
auto const tileHeight = TileHeight * scale;
auto const pixelsPerTile = tileWidth * tileHeight;
// prevent divide by zeros
if (!c) {
++c;
}
const auto t = i / pixelsPerTile; // tile number
const auto iti = i % pixelsPerTile; // in tile index
const auto tc = t % c; // tile column
const auto tr = t / c; // tile row
const auto itx = iti % tileWidth; // in tile x
const auto ity = iti / tileHeight; // in tile y
auto const t = i / pixelsPerTile; // tile number
auto const iti = i % pixelsPerTile; // in tile index
auto const tc = t % c; // tile column
auto const tr = t / c; // tile row
auto const itx = iti % tileWidth; // in tile x
auto const ity = iti / tileHeight; // in tile y
return {
itx + tc * tileWidth,
ity + tr * tileHeight,

View File

@@ -6,6 +6,28 @@
#include <studio/studio.hpp>
namespace nostalgia::core {
#include "tilesheet.hpp"
namespace nostalgia::gfx {
inline void navigateToTileSheet(
studio::Context &ctx, ox::StringParam path, SubSheetId const subsheetId) noexcept {
studio::navigateTo(ctx, std::move(path), ox::intToStr(subsheetId));
}
inline void navigateToPalette(studio::Context &ctx, ox::StringParam path) noexcept {
studio::navigateTo(ctx, std::move(path));
}
inline void navigateToPalette(
studio::Context &ctx,
ox::StringParam path,
size_t const colorIdx,
size_t const palPage) noexcept {
studio::navigateTo(
ctx,
std::move(path),
ox::sfmt("{};{}", colorIdx, palPage));
}
}

View File

@@ -428,6 +428,14 @@ TileSheet::SubSheetIdx validateSubSheetIdx(TileSheet const&ts, TileSheet::SubShe
ox::Result<TileSheet::SubSheetIdx> getSubSheetIdx(TileSheet const &ts, SubSheetId pId) noexcept;
ox::Result<TileSheet::SubSheet*> getSubSheet(
ox::SpanView<ox::StringView> const &idx,
TileSheet &ts) noexcept;
ox::Result<TileSheet::SubSheet const*> getSubSheet(
ox::SpanView<ox::StringView> const &idx,
TileSheet const &ts) noexcept;
[[nodiscard]]
TileSheet::SubSheet &getSubSheet(
ox::SpanView<uint32_t> const &idx,
@@ -473,6 +481,8 @@ ox::Result<uint32_t> getTileOffset(TileSheet const&ts, SubSheetId pId) noexcept;
ox::Result<ox::StringView> getNameFor(TileSheet::SubSheet const &ss, SubSheetId pId) noexcept;
ox::Result<ox::StringView> getNameFor(TileSheet &ts, SubSheetId pId) noexcept;
ox::Result<ox::StringView> getNameFor(TileSheet const &ts, SubSheetId pId) noexcept;
[[nodiscard]]

View File

@@ -35,11 +35,6 @@ class Context {
Context(Context const &&other) noexcept = delete;
virtual ~Context() noexcept = default;
[[nodiscard]]
ox::MemFS const&rom() const noexcept {
return static_cast<ox::MemFS const&>(*turbine::rom(turbineCtx));
}
};
void safeDelete(Context *ctx) noexcept {
@@ -81,7 +76,7 @@ ox::Error loadBgPalette(
if (palette.pages.empty()) {
return {};
}
auto const paletteMem = MEM_BG_PALETTE + palBank * 16;
auto const paletteMem = ox::Span{MEM_BG_PALETTE} + palBank * 16;
for (auto i = 0u; i < colorCnt(palette, page); ++i) {
paletteMem[i] = color(palette, page, i);
}
@@ -95,9 +90,8 @@ ox::Error loadSpritePalette(
if (palette.pages.empty()) {
return {};
}
auto const paletteMem = MEM_SPRITE_PALETTE;
for (auto i = 0u; i < colorCnt(palette, page); ++i) {
paletteMem[i] = color(palette, page, i);
MEM_SPRITE_PALETTE[i] = color(palette, page, i);
}
return {};
}
@@ -240,13 +234,17 @@ ox::Error loadSpriteTileSheet(
Context &ctx,
TileSheetSet const &set) noexcept {
auto const bpp = static_cast<unsigned>(set.bpp);
OX_RETURN_ERROR(loadTileSheetSet(ctx, {MEM_SPRITE_TILES, 32 * ox::units::KB}, set));
OX_RETURN_ERROR(loadTileSheetSet(ctx, MEM_SPRITE_TILES, set));
setSpritesBpp(bpp);
return {};
}
void setBgTile(
Context &ctx, uint_t const bgIdx, int const column, int const row, BgTile const&tile) noexcept {
Context &ctx,
uint_t const bgIdx,
int const column,
int const row,
BgTile const &tile) noexcept {
auto const tileIdx = static_cast<std::size_t>(row * tileColumns(ctx) + column);
// see Tonc 9.3
MEM_BG_MAP[bgIdx][tileIdx] =
@@ -275,7 +273,7 @@ bool bgStatus(Context&, unsigned const bg) noexcept {
void setBgStatus(Context&, unsigned const bg, bool const status) noexcept {
constexpr auto Bg0Status = 8;
const auto mask = static_cast<uint32_t>(status) << (Bg0Status + bg);
auto const mask = static_cast<uint32_t>(status) << (Bg0Status + bg);
REG_DISPCTL = REG_DISPCTL | ((REG_DISPCTL & ~mask) | mask);
}
@@ -286,7 +284,7 @@ void setBgBpp(Context&, unsigned const bgIdx, unsigned const bpp) noexcept {
void setBgCbb(Context &ctx, unsigned const bgIdx, unsigned const cbbIdx) noexcept {
auto &bgCtl = regBgCtl(bgIdx);
const auto &cbbData = ctx.cbbData[cbbIdx];
auto const &cbbData = ctx.cbbData[cbbIdx];
teagba::bgSetBpp(bgCtl, cbbData.bpp);
teagba::bgSetCbb(bgCtl, cbbIdx);
}
@@ -341,13 +339,13 @@ uint_t spriteCount(Context const&) noexcept {
namespace ox {
void panic(const char *file, int line, const char *panicMsg, ox::Error const&err) noexcept {
void panic(char const *file, int line, char const *panicMsg, ox::Error const &err) noexcept {
using namespace nostalgia::gfx;
// reset heap to make sure we have enough memory to allocate context data
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
const auto heapBegin = reinterpret_cast<char*>(MEM_EWRAM_BEGIN);
const auto heapSz = (MEM_EWRAM_END - MEM_EWRAM_BEGIN) / 2;
const auto heapEnd = reinterpret_cast<char*>(MEM_EWRAM_BEGIN + heapSz);
auto const heapBegin = reinterpret_cast<char*>(MEM_EWRAM.data());
auto const heapSz = MEM_EWRAM.size() / 2;
auto const heapEnd = reinterpret_cast<char*>(MEM_EWRAM.data() + heapSz);
ox::heapmgr::initHeap(heapBegin, heapEnd);
OX_ALLOW_UNSAFE_BUFFERS_END
auto tctx = turbine::init(keel::loadRomFs("").unwrap(), "Nostalgia").unwrap();

View File

@@ -287,7 +287,7 @@ static void initSpriteBufferObjects(Context const &ctx, glutils::BufferSet &bs)
static void initBackgroundBufferObjects(glutils::BufferSet &bs) noexcept {
for (auto x = 0u; x < TileColumns; ++x) {
for (auto y = 0u; y < TileRows; ++y) {
const auto i = bgVertexRow(x, y);
auto const i = bgVertexRow(x, y);
auto const vbo = ox::Span{bs.vertices}
+ i * static_cast<std::size_t>(BgVertexVboLength);
auto const ebo = ox::Span{bs.elements}
@@ -428,19 +428,19 @@ static void drawBackgrounds(
ox::Size const &renderSz) noexcept {
// load background shader and its uniforms
glUseProgram(ctx.bgShader);
const auto uniformSrcImgSz = glGetUniformLocation(ctx.bgShader, "fSrcImgSz");
const auto uniformXScale = static_cast<GLint>(glGetUniformLocation(ctx.bgShader, "vXScale"));
const auto uniformTileHeight = static_cast<GLint>(glGetUniformLocation(ctx.bgShader, "vTileHeight"));
const auto uniformBgIdx = static_cast<GLint>(glGetUniformLocation(ctx.bgShader, "vBgIdx"));
const auto [wi, hi] = renderSz;
const auto wf = static_cast<float>(wi);
const auto hf = static_cast<float>(hi);
auto const uniformSrcImgSz = glGetUniformLocation(ctx.bgShader, "fSrcImgSz");
auto const uniformXScale = static_cast<GLint>(glGetUniformLocation(ctx.bgShader, "vXScale"));
auto const uniformTileHeight = static_cast<GLint>(glGetUniformLocation(ctx.bgShader, "vTileHeight"));
auto const uniformBgIdx = static_cast<GLint>(glGetUniformLocation(ctx.bgShader, "vBgIdx"));
auto const [wi, hi] = renderSz;
auto const wf = static_cast<float>(wi);
auto const hf = static_cast<float>(hi);
glUniform1f(uniformXScale, hf / wf);
auto bgIdx = 0.f;
for (const auto &bg : ctx.backgrounds) {
for (auto const &bg : ctx.backgrounds) {
if (bg.enabled) {
auto &cbb = ctx.cbbs[bg.cbbIdx];
const auto tileRows = cbb.tex.height / (TileHeight * Scale);
auto const tileRows = cbb.tex.height / (TileHeight * Scale);
glUniform1f(uniformTileHeight, 1.0f / static_cast<float>(tileRows));
glUniform2f(
uniformSrcImgSz,
@@ -456,11 +456,11 @@ static void drawBackgrounds(
static void drawSprites(Context &ctx, ox::Size const &renderSz) noexcept {
glUseProgram(ctx.spriteShader);
auto &sb = ctx.spriteBlocks;
const auto uniformXScale = glGetUniformLocation(ctx.bgShader, "vXScale");
const auto uniformTileHeight = glGetUniformLocation(ctx.spriteShader, "vTileHeight");
const auto [wi, hi] = renderSz;
const auto wf = static_cast<float>(wi);
const auto hf = static_cast<float>(hi);
auto const uniformXScale = glGetUniformLocation(ctx.bgShader, "vXScale");
auto const uniformTileHeight = glGetUniformLocation(ctx.spriteShader, "vTileHeight");
auto const [wi, hi] = renderSz;
auto const wf = static_cast<float>(wi);
auto const hf = static_cast<float>(hi);
glUniform1f(uniformXScale, hf / wf);
// update vbo
glBindVertexArray(sb.vao);
@@ -469,7 +469,7 @@ static void drawSprites(Context &ctx, ox::Size const&renderSz) noexcept {
glutils::sendVbo(sb);
}
// set vTileHeight uniform
const auto tileRows = sb.tex.height / (TileHeight * Scale);
auto const tileRows = sb.tex.height / (TileHeight * Scale);
glUniform1f(uniformTileHeight, 1.0f / static_cast<float>(tileRows));
// draw
glBindTexture(GL_TEXTURE_2D, sb.tex);
@@ -493,7 +493,7 @@ static void loadPalette(
// make first color transparent
palette[palOffset + 3] = 0;
glUseProgram(shaderPgrm);
const auto uniformPalette = static_cast<GLint>(glGetUniformLocation(shaderPgrm, "fPalette"));
auto const uniformPalette = static_cast<GLint>(glGetUniformLocation(shaderPgrm, "fPalette"));
glUniform4fv(uniformPalette, ColorCnt, palette.data());
}
@@ -526,12 +526,12 @@ static void setSprite(
auto const uY = static_cast<int>(s.y + 8) % 255 - 8;
oxAssert(1 < ctx.spriteBlocks.vertices.size(), "vbo overflow");
oxAssert(1 < ctx.spriteBlocks.elements.size(), "ebo overflow");
const auto spriteVboSz = ctx.blocksPerSprite * renderer::SpriteVertexVboLength;
const auto spriteEboSz = ctx.blocksPerSprite * renderer::SpriteVertexEboLength;
auto const spriteVboSz = ctx.blocksPerSprite * renderer::SpriteVertexVboLength;
auto const spriteEboSz = ctx.blocksPerSprite * renderer::SpriteVertexEboLength;
auto const vboBase = spriteVboSz * idx;
auto const eboBase = spriteEboSz * idx;
auto i = 0u;
const auto set = [&](int xIt, int yIt, bool enabled) {
auto const set = [&](int xIt, int yIt, bool enabled) {
auto const fX = static_cast<float>(uX + xIt * 8) / 8;
auto const fY = static_cast<float>(uY + yIt * 8) / 8;
auto const vboIdx = vboBase + renderer::SpriteVertexVboLength * i;
@@ -576,10 +576,10 @@ static void setSprite(
ox::Result<ox::UPtr<Context>> init(turbine::Context &tctx, InitParams const &params) noexcept {
auto ctx = ox::make_unique<Context>(tctx, params);
const auto bgVshad = ox::sfmt(renderer::bgvshadTmpl, gl::GlslVersion);
const auto bgFshad = ox::sfmt(renderer::bgfshadTmpl, gl::GlslVersion);
const auto spriteVshad = ox::sfmt(renderer::spritevshadTmpl, gl::GlslVersion);
const auto spriteFshad = ox::sfmt(renderer::spritefshadTmpl, gl::GlslVersion);
auto const bgVshad = ox::sfmt(renderer::bgvshadTmpl, gl::GlslVersion);
auto const bgFshad = ox::sfmt(renderer::bgfshadTmpl, gl::GlslVersion);
auto const spriteVshad = ox::sfmt(renderer::spritevshadTmpl, gl::GlslVersion);
auto const spriteFshad = ox::sfmt(renderer::spritefshadTmpl, gl::GlslVersion);
OX_RETURN_ERROR(glutils::buildShaderProgram(bgVshad, bgFshad).moveTo(ctx->bgShader));
OX_RETURN_ERROR(
glutils::buildShaderProgram(spriteVshad, spriteFshad).moveTo(ctx->spriteShader));
@@ -603,12 +603,12 @@ struct TileSheetData {
}
};
static ox::Result<TileSheetData> normalizeTileSheet(
CompactTileSheet const&ts) noexcept {
static ox::Result<TileSheetData> normalizeTileSheet
(CompactTileSheet const &ts) noexcept {
const uint_t bytesPerTile = ts.bpp == 8 ? PixelsPerTile : PixelsPerTile / 2;
const auto tiles = ts.pixels.size() / bytesPerTile;
auto const tiles = ts.pixels.size() / bytesPerTile;
constexpr int width = 8;
const int height = 8 * static_cast<int>(tiles);
int const height = 8 * static_cast<int>(tiles);
ox::Vector<uint32_t> pixels;
if (bytesPerTile == 64) { // 8 BPP
pixels.resize(ts.pixels.size());
@@ -779,13 +779,13 @@ void setBgTile(
"nostalgia.gfx.setBgTile",
"bgIdx: {}, column: {}, row: {}, tile: {}, palBank: {}",
bgIdx, column, row, tile.tileIdx, tile.palBank);
const auto z = static_cast<uint_t>(bgIdx);
const auto y = static_cast<uint_t>(row);
const auto x = static_cast<uint_t>(column);
const auto i = renderer::bgVertexRow(x, y);
auto const z = static_cast<uint_t>(bgIdx);
auto const y = static_cast<uint_t>(row);
auto const x = static_cast<uint_t>(column);
auto const i = renderer::bgVertexRow(x, y);
auto &cbb = ctx.cbbs[z];
const auto vbo = ox::Span{cbb.vertices} + i * renderer::BgVertexVboLength;
const auto ebo = ox::Span{cbb.elements} + i * renderer::BgVertexEboLength;
auto const vbo = ox::Span{cbb.vertices} + i * renderer::BgVertexVboLength;
auto const ebo = ox::Span{cbb.elements} + i * renderer::BgVertexEboLength;
auto &bg = ctx.backgrounds[bgIdx];
renderer::setTileBufferObject(
static_cast<uint_t>(i * renderer::BgVertexVboRows),

View File

@@ -10,11 +10,11 @@ namespace nostalgia::gfx {
constexpr auto GbaTileColumns = 32;
constexpr auto GbaTileRows = 32;
int tileColumns(Context&) noexcept {
int tileColumns(Context const&) noexcept {
return GbaTileColumns;
}
int tileRows(Context&) noexcept {
int tileRows(Context const&) noexcept {
return GbaTileRows;
}

View File

@@ -8,7 +8,6 @@
#include <keel/typeconv.hpp>
#include <nostalgia/gfx/context.hpp>
#include <nostalgia/gfx/palette.hpp>
#include <nostalgia/gfx/tilesheet.hpp>

View File

@@ -26,3 +26,4 @@ install(
add_subdirectory(paletteeditor)
add_subdirectory(tilesheeteditor)
add_subdirectory(subcommands)

View File

@@ -8,10 +8,25 @@
#include "paletteeditor/paletteeditor-imgui.hpp"
#include "tilesheeteditor/tilesheeteditor-imgui.hpp"
#include "subcommands/export-tilesheet/export-tilesheet.hpp"
namespace nostalgia::gfx {
static class: public studio::Module {
static struct: studio::Module {
ox::String id() const noexcept final {
return ox::String{"net.drinkingtea.nostalgia.gfx"};
}
ox::Vector<studio::Command> commands() const final {
return {
{
"export-tilesheet",
cmdExportTilesheet,
}
};
}
ox::Vector<studio::EditorMaker> editors(studio::Context &ctx) const noexcept final {
return {
studio::editorMaker<TileSheetEditorImGui>(ctx, {FileExt_ng, FileExt_nts}),
@@ -28,9 +43,10 @@ static class: public studio::Module {
}, ox::ClawFormat::Organic));
return out;
}
} const mod;
const studio::Module *studioModule() noexcept {
studio::Module const *studioModule() noexcept {
return &mod;
}

View File

@@ -0,0 +1,10 @@
target_sources(
NostalgiaGfx-Studio PRIVATE
export-tilesheet/export-tilesheet.cpp
)
target_link_libraries(
NostalgiaGfx-Studio PUBLIC
OxClArgs
)

View File

@@ -0,0 +1,161 @@
/*
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#include <lodepng.h>
#include <ox/clargs/clargs.hpp>
#include <ox/std/trace.hpp>
#include <studio/project.hpp>
#include <nostalgia/gfx/palette.hpp>
#include <nostalgia/gfx/tilesheet.hpp>
#include "export-tilesheet.hpp"
#include "nostalgia/gfx/tilesheet.hpp"
#include "studio/context.hpp"
namespace nostalgia::gfx {
static ox::Vector<uint32_t> normalizePixelSizes(
ox::Vector<uint8_t> const &inPixels) noexcept {
ox::Vector<uint32_t> outPixels;
outPixels.reserve(inPixels.size());
outPixels.resize(inPixels.size());
for (size_t i{}; i < inPixels.size(); ++i) {
outPixels[i] = inPixels[i];
}
return outPixels;
}
static ox::Vector<uint32_t> normalizePixelArrangement(
ox::Vector<uint32_t> const &inPixels,
int const cols,
int const scale) {
auto const scalePt = ox::Point{scale, scale};
auto const width = cols * TileWidth;
auto const height = static_cast<int>(inPixels.size()) / width;
auto const dstWidth = width * scale;
ox::Vector<uint32_t> outPixels(static_cast<size_t>((width * scale) * (height * scale)));
for (size_t dstIdx{}; dstIdx < outPixels.size(); ++dstIdx) {
auto const dstPt = ox::Point{
static_cast<int>(dstIdx) % dstWidth,
static_cast<int>(dstIdx) / dstWidth};
auto const srcPt = dstPt / scalePt;
auto const srcIdx = ptToIdx(srcPt, cols);
outPixels[dstIdx] = inPixels[srcIdx];
}
return outPixels;
}
static ox::Error toPngFile(
ox::CStringViewCR path,
ox::Vector<uint32_t> &&pixels,
Palette const &pal,
size_t const page,
unsigned const width,
unsigned const height) noexcept {
for (auto &c : pixels) {
c = color32(color(pal, page, c)) | static_cast<Color32>(0XFF << 24);
}
constexpr auto fmt = LCT_RGBA;
return ox::Error(static_cast<ox::ErrorCode>(
lodepng_encode_file(
path.c_str(),
reinterpret_cast<uint8_t const*>(pixels.data()),
width,
height,
fmt,
8)));
}
ox::Error exportSubsheetToPng(
TileSheet::SubSheet const &s,
Palette const &pal,
size_t const palPage,
ox::CStringViewCR dstPath,
int const scale) noexcept {
// subsheet to png
auto const width = s.columns * TileWidth;
auto const height = s.rows * TileHeight;
auto const err = toPngFile(
dstPath,
normalizePixelArrangement(
normalizePixelSizes(s.pixels),
s.columns,
scale),
pal,
palPage,
static_cast<unsigned>(width * scale),
static_cast<unsigned>(height * scale));
if (err) {
oxErrorf("TileSheet export failed: {}", toStr(err));
return ox::Error{7, "TileSheet export failed"};
}
return {};
}
ox::Error exportSubsheetToPng(
TileSheet const &src,
Palette const &pal,
ox::StringViewCR subsheetPath,
size_t const palPage,
ox::CStringViewCR dstPath,
int const scale) noexcept {
// subsheet to png
auto const [s, ssErr] = getSubSheet(
ox::split(subsheetPath, '.'), src);
if (ssErr) {
return ox::Error{6, "failed to find SubSheet"};
}
return exportSubsheetToPng(
*s,
pal,
palPage,
dstPath,
scale);
}
ox::Error cmdExportTilesheet(studio::Project &project, ox::SpanView<ox::CString> const args) noexcept {
// parse args
ox::ClArgs const clargs{args};
bool showUsage = true;
OX_DEFER [&showUsage] {
if (showUsage) {
oxErr("usage: export-tilesheet "
"-src-path <path> "
"-dst-path <path> "
"[-pal-path <path>] "
"[-subsheet-path <path>] "
"[-scale <int>]\n");
}
};
if (args.empty()) {
return {};
}
OX_REQUIRE(srcPath, clargs.getString("src-path").transformError(1, "no src path specified"));
OX_REQUIRE(dstPath, clargs.getString("dst-path").transformError(2, "no dst path specified"));
auto const palPath = clargs.getString("pal-path", "");
auto const subsheetPath = clargs.getString("subsheet-path").or_value(ox::String{"Root"});
auto const palPage = static_cast<size_t>(clargs.getInt("pal-page", 0));
auto const scale = clargs.getInt("scale", 1);
showUsage = false;
// load objects
auto &kctx = project.kctx();
OX_REQUIRE(ts, keel::readObj<TileSheet>(kctx, srcPath).transformError(4, "could not load TileSheet"));
OX_REQUIRE(pal, keel::readObj<Palette>(kctx, palPath.len() ? palPath : ts->defaultPalette)
.transformError(5, "could not load Palette"));
// export to the destination file
return exportSubsheetToPng(
*ts,
*pal,
subsheetPath,
palPage,
dstPath,
scale);
}
}

View File

@@ -0,0 +1,28 @@
/*
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#pragma once
#include <ox/std/error.hpp>
namespace nostalgia::gfx {
ox::Error exportSubsheetToPng(
TileSheet::SubSheet const &s,
Palette const &pal,
size_t palPage,
ox::CStringViewCR dstPath,
int scale) noexcept;
ox::Error exportSubsheetToPng(
TileSheet const &src,
Palette const &pal,
ox::StringViewCR subsheetPath,
size_t palPage,
ox::CStringViewCR dstPath,
int scale) noexcept;
ox::Error cmdExportTilesheet(studio::Project& project, ox::SpanView<ox::CString> args) noexcept;
}

View File

@@ -48,7 +48,7 @@ CutPasteCommand::CutPasteCommand(
ox::Error CutPasteCommand::redo() noexcept {
auto &subsheet = getSubSheet(m_img, m_subSheetIdx);
for (const auto &c : m_changes) {
for (auto const &c : m_changes) {
subsheet.pixels[c.idx] = static_cast<uint8_t>(c.newPalIdx);
}
return {};
@@ -56,7 +56,7 @@ ox::Error CutPasteCommand::redo() noexcept {
ox::Error CutPasteCommand::undo() noexcept {
auto &subsheet = getSubSheet(m_img, m_subSheetIdx);
for (const auto &c : m_changes) {
for (auto const &c : m_changes) {
subsheet.pixels[c.idx] = static_cast<uint8_t>(c.oldPalIdx);
}
return {};

View File

@@ -9,6 +9,9 @@
#include <keel/media.hpp>
#include <studio/studio.hpp>
#include <nostalgia/gfx/studio.hpp>
#include "../subcommands/export-tilesheet/export-tilesheet.hpp"
#include "tilesheeteditor-imgui.hpp"
namespace nostalgia::gfx {
@@ -35,58 +38,6 @@ OX_MODEL_BEGIN(TileSheetEditorConfig)
OX_MODEL_FIELD_RENAME(activeSubsheet, active_subsheet)
OX_MODEL_END()
static ox::Vector<uint32_t> normalizePixelSizes(
ox::Vector<uint8_t> const &inPixels) noexcept {
ox::Vector<uint32_t> outPixels;
outPixels.reserve(inPixels.size());
outPixels.resize(inPixels.size());
for (std::size_t i = 0; i < inPixels.size(); ++i) {
outPixels[i] = inPixels[i];
}
return outPixels;
}
static ox::Vector<uint32_t> normalizePixelArrangement(
ox::Vector<uint32_t> const &inPixels,
int const cols,
int const scale) {
auto const scalePt = ox::Point{scale, scale};
auto const width = cols * TileWidth;
auto const height = static_cast<int>(inPixels.size()) / width;
auto const dstWidth = width * scale;
ox::Vector<uint32_t> outPixels(static_cast<size_t>((width * scale) * (height * scale)));
for (std::size_t dstIdx = 0; dstIdx < outPixels.size(); ++dstIdx) {
auto const dstPt = ox::Point{
static_cast<int>(dstIdx) % dstWidth,
static_cast<int>(dstIdx) / dstWidth};
auto const srcPt = dstPt / scalePt;
auto const srcIdx = ptToIdx(srcPt, cols);
outPixels[dstIdx] = inPixels[srcIdx];
}
return outPixels;
}
static ox::Error toPngFile(
ox::CStringViewCR path,
ox::Vector<uint32_t> &&pixels,
Palette const &pal,
size_t const page,
unsigned const width,
unsigned const height) noexcept {
for (auto &c : pixels) {
c = color32(color(pal, page, c)) | static_cast<Color32>(0XFF << 24);
}
constexpr auto fmt = LCT_RGBA;
return ox::Error(static_cast<ox::ErrorCode>(
lodepng_encode_file(
path.c_str(),
reinterpret_cast<uint8_t const*>(pixels.data()),
width,
height,
fmt,
8)));
}
TileSheetEditorImGui::TileSheetEditorImGui(studio::Context &sctx, ox::StringParam path):
Editor{sctx, std::move(path)},
m_sctx{sctx},
@@ -419,21 +370,7 @@ ox::Error TileSheetEditorImGui::exportSubsheetToPng(int const scale) const noexc
// subsheet to png
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);
pixels = normalizePixelArrangement(pixels, s.columns, scale);
auto const err = toPngFile(
path,
std::move(pixels),
pal,
m_model.palettePage(),
static_cast<unsigned>(width * scale),
static_cast<unsigned>(height * scale));
if (err) {
oxErrorf("TileSheet export failed: {}", toStr(err));
}
return err;
return gfx::exportSubsheetToPng(s, pal, m_model.palettePage(), path, scale);
}
void TileSheetEditorImGui::drawTileSheet(ox::Vec2 const &fbSize) noexcept {
@@ -576,10 +513,10 @@ void TileSheetEditorImGui::drawPaletteMenu() noexcept {
m_view.setPalIdx(i);
}
if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(0)) {
studio::navigateTo(
navigateToPalette(
m_sctx,
m_model.palPath(),
ox::sfmt("{};{}", i, m_model.palettePage()));
i, m_model.palettePage());
}
// Column: color RGB
ImGui::TableNextColumn();

View File

@@ -92,7 +92,7 @@ void TileSheetEditorView::clickFill(ox::Vec2 const&paneSize, ox::Vec2 const&clic
m_model.fill(pt, static_cast<uint8_t>(m_palIdx));
}
void TileSheetEditorView::releaseMouseButton(TileSheetTool tool) noexcept {
void TileSheetEditorView::releaseMouseButton(TileSheetTool const tool) noexcept {
switch (tool) {
case TileSheetTool::Draw:
case TileSheetTool::Fill:
@@ -135,7 +135,7 @@ void TileSheetEditorView::initView() noexcept {
ox::Point TileSheetEditorView::clickPoint(ox::Vec2 const &paneSize, ox::Vec2 const &clickPos) const noexcept {
auto [x, y] = clickPos;
const auto pixDrawSz = m_pixelsDrawer.pixelSize(paneSize);
auto const pixDrawSz = m_pixelsDrawer.pixelSize(paneSize);
x /= paneSize.x;
y /= paneSize.y;
x += -m_scrollOffset.x / 2;

View File

@@ -73,7 +73,8 @@ 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, ox::Span<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

@@ -86,12 +86,12 @@ static void setPixel(
int const columns,
ox::Point const &pt,
uint8_t const palIdx) noexcept {
const auto idx = ptToIdx(pt, columns);
auto const idx = ptToIdx(pt, columns);
pixels[idx] = palIdx;
}
void setPixel(TileSheet::SubSheet &ss, ox::Point const &pt, uint8_t const palIdx) noexcept {
const auto idx = ptToIdx(pt, ss.columns);
auto const idx = ptToIdx(pt, ss.columns);
ss.pixels[idx] = palIdx;
}
@@ -154,8 +154,8 @@ ox::Result<ox::StringView> getNameFor(TileSheet::SubSheet const&ss, SubSheetId c
if (ss.id == pId) {
return ox::StringView(ss.name);
}
for (const auto &sub : ss.subsheets) {
const auto [name, err] = getNameFor(sub, pId);
for (auto const &sub : ss.subsheets) {
auto const [name, err] = getNameFor(sub, pId);
if (!err) {
return name;
}
@@ -211,6 +211,47 @@ ox::Result<TileSheet::SubSheetIdx> getSubSheetIdx(TileSheet const &ts, SubSheetI
return out;
}
template<typename SubSheet>
static ox::Result<SubSheet*> getSubSheet(
ox::SpanView<ox::StringView> const &idx,
std::size_t const idxIt,
SubSheet &pSubSheet) noexcept {
if (idxIt == idx.size()) {
return &pSubSheet;
}
auto const &currentIdx = idx[idxIt];
auto const next = ox::find_if(
pSubSheet.subsheets.begin(),
pSubSheet.subsheets.end(),
[&currentIdx](TileSheet::SubSheet const &ss) {
return ss.name == currentIdx;
});
if (next == pSubSheet.subsheets.end()) {
return ox::Error{1, "SubSheet not found"};
}
return getSubSheet(idx, idxIt + 1, *next);
}
ox::Result<TileSheet::SubSheet const*> getSubSheet(
ox::SpanView<ox::StringView> const &idx,
TileSheet const &ts) noexcept {
if (!idx.empty() && idx[0] == ts.subsheet.name) {
return getSubSheet<TileSheet::SubSheet const>(idx, 1, ts.subsheet);
}
return ox::Error{1, "SubSheet not found"};
}
ox::Result<TileSheet::SubSheet*> getSubSheet(
ox::SpanView<ox::StringView> const &idx,
TileSheet &ts) noexcept {
if (!idx.empty() && idx[0] == ts.subsheet.name) {
return getSubSheet<TileSheet::SubSheet>(idx, 1, ts.subsheet);
}
return ox::Error{1, "SubSheet not found"};
}
#if defined(__GNUC__) && __GNUC__ >= 13
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdangling-reference"
@@ -222,7 +263,7 @@ static TileSheet::SubSheet const&getSubSheet(
if (idxIt == idx.size()) {
return pSubsheet;
}
const auto currentIdx = idx[idxIt];
auto const currentIdx = idx[idxIt];
if (pSubsheet.subsheets.size() < currentIdx) {
return pSubsheet;
}
@@ -437,13 +478,13 @@ ox::Vector<uint32_t> resizeTileSheetData(
ox::Vector<uint32_t> dst;
auto dstWidth = srcSize.width * scale;
auto dstHeight = srcSize.height * scale;
const auto pixelCnt = dstWidth * dstHeight;
auto const pixelCnt = dstWidth * dstHeight;
dst.resize(static_cast<std::size_t>(pixelCnt));
for (auto i = 0; i < pixelCnt; ++i) {
const auto dstPt = idxToPt(i, 1, scale);
const auto srcPt = dstPt / ox::Point{scale, scale};
const auto srcIdx = ptToIdx(srcPt, 1);
const auto srcPixel = srcPixels[srcIdx];
auto const dstPt = idxToPt(i, 1, scale);
auto const srcPt = dstPt / ox::Point{scale, scale};
auto const srcIdx = ptToIdx(srcPt, 1);
auto const srcPixel = srcPixels[srcIdx];
dst[static_cast<std::size_t>(i)] = srcPixel;
}
return dst;

View File

@@ -24,7 +24,7 @@ static std::map<ox::StringView, ox::Error(*)()> tests = {
},
};
int main(int argc, const char **argv) {
int main(int argc, char const **argv) {
int retval = -1;
if (argc > 0) {
auto const args = ox::Span{argv, static_cast<size_t>(argc)};

View File

@@ -10,6 +10,10 @@ namespace nostalgia::sound {
static struct: studio::Module {
ox::String id() const noexcept final {
return ox::String{"net.drinkingtea.nostalgia.sound"};
}
ox::Vector<studio::EditorMaker> editors(studio::Context&) const noexcept final {
return {
};
@@ -22,7 +26,7 @@ static struct: studio::Module {
} const mod;
const studio::Module *studioModule() noexcept {
studio::Module const *studioModule() noexcept {
return &mod;
}

View File

@@ -11,7 +11,7 @@
static std::map<ox::StringView, ox::Error(*)()> tests = {
};
int main(int argc, const char **argv) {
int main(int argc, char const **argv) {
int retval = -1;
if (argc > 0) {
auto const args = ox::Span{argv, static_cast<size_t>(argc)};

View File

@@ -15,7 +15,7 @@ target_link_libraries(
target_compile_definitions(
NostalgiaStudio PUBLIC
OLYMPIC_APP_VERSION="d2025.06.0"
OLYMPIC_APP_VERSION="dev build"
)
install(

View File

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

View File

@@ -55,7 +55,7 @@ void registerStudioModules() noexcept;
#if defined(_WIN32) && OLYMPIC_GUI_APP
int WinMain() {
auto const argc = __argc;
auto const argv = const_cast<const char**>(__argv);
auto const argv = const_cast<char const**>(__argv);
#else
int main(int const argc, char const **argv) {
#endif

View File

@@ -26,7 +26,7 @@ ox::Error writeUuidHeader(ox::Writer_c auto &writer, ox::UUID const&uuid) noexce
template<typename T>
ox::Result<T> readAsset(ox::BufferView buff) noexcept {
std::size_t offset = 0;
const auto err = readUuidHeader(buff).error;
auto const err = readUuidHeader(buff).error;
if (!err) {
offset = K1HdrSz; // the size of K1 headers
}

View File

@@ -140,7 +140,7 @@ class ConverterFunc final: public BaseConverter {
private:
template<typename SrcType, typename DstType>
struct ParamPack {
using Src = SrcType;
using Src = ox::remove_const_t<SrcType>;
using Dst = DstType;
};

View File

@@ -37,8 +37,8 @@ ox::Result<ox::ModelObject> readAsset(ox::TypeStore &ts, ox::BufferView buff) no
}
ox::Result<ox::StringView> readAssetTypeId(ox::BufferView const buff) noexcept {
const auto err = readUuidHeader(buff).error;
const auto offset = err ? 0u : K1HdrSz;
auto const err = readUuidHeader(buff).error;
auto const offset = err ? 0u : K1HdrSz;
if (offset >= buff.size()) [[unlikely]] {
return ox::Error(1, "Buffer too small for expected data");
}
@@ -47,8 +47,8 @@ ox::Result<ox::StringView> readAssetTypeId(ox::BufferView const buff) noexcept {
ox::Result<AssetHdr> readAssetHeader(ox::BufferView buff) noexcept {
ox::Result<AssetHdr> out;
const auto err = readUuidHeader(buff).moveTo(out.value.uuid);
const auto offset = err ? 0u : K1HdrSz;
auto const err = readUuidHeader(buff).moveTo(out.value.uuid);
auto const offset = err ? 0u : K1HdrSz;
if (offset >= buff.size()) [[unlikely]] {
return ox::Error(1, "Buffer too small for expected data");
}

View File

@@ -49,7 +49,7 @@ static ox::Result<ox::UPtr<Wrap>> convert(
if (!subConverter.converter().dstMatches(dstTypeName, dstTypeVersion)) {
continue;
}
const auto [intermediate, chainErr] =
auto const [intermediate, chainErr] =
convert(ctx, converters, src, srcTypeName, srcTypeVersion,
subConverter.converter().srcTypeName(), subConverter.converter().srcTypeVersion());
if (!chainErr) {

View File

@@ -25,7 +25,7 @@ static std::map<ox::StringView, ox::Error(*)()> tests = {
},
};
int main(int argc, const char **argv) {
int main(int argc, char const **argv) {
int retval = -1;
if (argc > 0) {
auto const args = ox::Span{argv, static_cast<size_t>(argc)};

View File

@@ -10,6 +10,9 @@
namespace studio {
[[nodiscard]]
ox::Vector<Module const*> const &modules() noexcept;
void registerModule(Module const*) noexcept;
}

View File

@@ -2,15 +2,18 @@
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#include <complex>
#include <ctime>
#include <ox/logconn/logconn.hpp>
#include <ox/std/trace.hpp>
#include <ox/std/uuid.hpp>
#include <keel/media.hpp>
#include <keel/keel.hpp>
#include <turbine/turbine.hpp>
#include <studio/context.hpp>
#include <studioapp/studioapp.hpp>
#include "studioui.hpp"
namespace studio {
@@ -40,7 +43,7 @@ static void mouseButtonEventHandler(turbine::Context &ctx, int const btn, bool c
[[nodiscard]]
ox::Vector<ox::SpanView<uint8_t>> WindowIcons() noexcept;
static ox::Error runApp(
static ox::Error runStudio(
ox::StringViewCR appName,
ox::StringViewCR projectDataDir,
ox::UPtr<ox::FileSystem> &&fs) noexcept {
@@ -61,18 +64,50 @@ static ox::Error runApp(
static ox::Error run(
ox::StringViewCR appName,
ox::StringViewCR projectDataDir,
ox::SpanView<const char*>) {
ox::SpanView<ox::CString> const &args) {
// seed UUID generator
auto const time = std::time(nullptr);
ox::UUID::seedGenerator({
static_cast<uint64_t>(time),
static_cast<uint64_t>(time << 1)
});
if (args.size() > 1 && ox::StringView{args[1]} == "cmd") {
if (args.size() < 5) {
return ox::Error{1, "insufficient arguments for sub-command"};
}
auto constexpr numCmdArgs = 5;
ox::StringView const projectDir = args[2];
ox::StringView const moduleId = args[3];
ox::StringView const subCmd = args[4];
for (auto const m : modules()) {
if (m->id() == moduleId) {
for (auto const &c : m->commands()) {
if (c.name == subCmd) {
auto kctx = keel::init(
ox::make_unique<ox::PassThroughFS>(projectDir),
c.name);
if (kctx.error) {
return ox::Error{2, "failed to load project directory"};
}
Project project{*kctx.value, projectDir, projectDataDir};
return c.func(
project,
args.size() > numCmdArgs ?
args + numCmdArgs : ox::SpanView<ox::CString>{});
}
}
return ox::Error{1, "command not found"};
}
}
return ox::Error{1, "module not found"};
} else {
// run app
auto const err = runApp(appName, projectDataDir, ox::UPtr<ox::FileSystem>{});
auto const err = runStudio(appName, projectDataDir, ox::UPtr<ox::FileSystem>{});
oxAssert(err, "Something went wrong...");
return err;
}
return {};
}
}

View File

@@ -140,14 +140,14 @@ void ClawEditor::drawVar(ObjPath &path, ox::StringViewCR name, ox::ModelValue co
void ClawEditor::drawTree(ObjPath &path, ox::ModelObject const &obj) noexcept {
using Str = ox::BasicString<100>;
for (const auto &c : obj) {
for (auto const &c : obj) {
ImGui::TableNextRow(0, 5);
auto pathStr = ox::join<Str>("##", path).unwrap();
auto lbl = ox::sfmt<Str>("{}##{}", c->name, pathStr);
const auto rowSelected = false;
const auto hasChildren = c->value.type() == ox::ModelValue::Type::Object
auto const rowSelected = false;
auto const hasChildren = c->value.type() == ox::ModelValue::Type::Object
|| c->value.type() == ox::ModelValue::Type::Vector;
const auto flags = ImGuiTreeNodeFlags_SpanFullWidth
auto const flags = ImGuiTreeNodeFlags_SpanFullWidth
| ImGuiTreeNodeFlags_OpenOnArrow
| (hasChildren ? 0 : ImGuiTreeNodeFlags_Leaf)
| (rowSelected ? ImGuiTreeNodeFlags_Selected : 0);
@@ -158,7 +158,7 @@ void ClawEditor::drawTree(ObjPath &path, ox::ModelObject const&obj) noexcept {
//}
path.push_back(c->name);
if (c->value.type() == ox::ModelValue::Type::Object) {
const auto open = ImGui::TreeNodeEx(lbl.c_str(), flags);
auto const open = ImGui::TreeNodeEx(lbl.c_str(), flags);
ImGui::SameLine();
drawRow(c->value);
if (open) {

View File

@@ -13,7 +13,7 @@
namespace studio {
class NewProject: public studio::Popup {
class NewProject: public Popup {
public:
enum class Stage {
Closed,

View File

@@ -37,11 +37,15 @@ static bool shutdownHandler(turbine::Context &ctx) {
namespace ig {
extern bool s_mainWinHasFocus;
}
static ox::Vector<Module const*> modules;
static ox::Vector<Module const*> g_modules;
ox::Vector<Module const*> const &modules() noexcept {
return g_modules;
}
void registerModule(Module const*mod) noexcept {
if (mod) {
modules.emplace_back(mod);
g_modules.emplace_back(mod);
}
}
@@ -443,7 +447,7 @@ void StudioUI::loadModule(Module const &mod) noexcept {
}
void StudioUI::loadModules() noexcept {
for (auto const mod : modules) {
for (auto const mod : g_modules) {
loadModule(*mod);
}
}
@@ -635,8 +639,7 @@ ox::Error StudioUI::openProjectPath(ox::StringParam path) noexcept {
keel::DuplicateSet ds;
OX_RETURN_ERROR(keel::setRomFs(keelCtx(m_tctx), std::move(fs), ds));
if (ds.size()) {
ox::String msg;
msg += "Multiple files have the same UUID:\n";
ox::String msg{"Multiple files have the same UUID:\n"};
for (auto const &k : ds.keys()) {
msg += ox::sfmt("\n\t{}:\n", k.toString());
for (auto const &v : ds[k]) {
@@ -674,14 +677,18 @@ ox::Error StudioUI::openProjectPath(ox::StringParam path) noexcept {
auto p = std::move(*pcIt);
std::ignore = config.projects.erase(pcIt);
auto &pc = *config.projects.emplace(0, std::move(p));
for (auto const &f: pc.openFiles) {
std::ignore = pc.openFiles.erase(
std::remove_if(
pc.openFiles.begin(), pc.openFiles.end(),
[&](ox::String const &f) {
auto const openFileErr = openFileActiveTab(f, pc.activeTabItemName == f);
if (openFileErr) {
oxErrorf("\nCould not open editor for file:\n\t{}\nReason:\n\t{}\n", f, toStr(openFileErr));
continue;
return true;
}
m_activeEditor = m_editors.back().value->get();
}
return false;
}));
} else {
config.projects.emplace(0, StudioConfig::ProjectConfig{
.projectPath = ox::String{m_project->projectPath()},

View File

@@ -24,6 +24,8 @@ class FilePickerPopup {
public:
explicit FilePickerPopup(ox::StringParam name, keel::Context &kctx, ox::StringParam fileExt) noexcept;
explicit FilePickerPopup(ox::StringParam name, keel::Context &kctx, ox::SpanView<ox::StringLiteral> fileExts) noexcept;
explicit FilePickerPopup(ox::StringParam name, keel::Context &kctx, ox::Vector<ox::String> fileExts) noexcept;
void refresh() noexcept;

View File

@@ -131,7 +131,7 @@ class ChildStackItem {
class IDStackItem {
public:
explicit IDStackItem(int id) noexcept;
explicit IDStackItem(const char *id) noexcept;
explicit IDStackItem(ox::CString const id) noexcept;
explicit IDStackItem(ox::CStringViewCR id) noexcept;
~IDStackItem() noexcept;
};
@@ -244,7 +244,7 @@ bool BeginPopup(turbine::Context &ctx, ox::CStringViewCR popupName, bool &show,
* @return true if new value selected, false otherwise
*/
bool ComboBox(
ox::CStringView lbl,
ox::CStringView const &lbl,
ox::SpanView<ox::CStringView> list,
size_t &selectedIdx) noexcept;
@@ -255,7 +255,7 @@ bool ComboBox(
* @param selectedIdx
* @return true if new value selected, false otherwise
*/
bool ComboBox(ox::CStringView lbl, ox::Span<const ox::String> list, size_t &selectedIdx) noexcept;
bool ComboBox(ox::CStringView const &lbl, ox::Span<ox::String const> list, size_t &selectedIdx) noexcept;
/**
*

View File

@@ -23,15 +23,34 @@ struct EditorMaker {
Func make;
};
struct Command {
ox::String name;
std::function<ox::Error(Project&, ox::SpanView<ox::CString>)> func;
Command(
ox::StringParam name,
std::function<ox::Error(Project&, ox::SpanView<ox::CString>)> func) noexcept:
name(std::move(name)),
func(std::move(func)) {}
};
class Module {
public:
virtual ~Module() noexcept = default;
virtual ox::Vector<EditorMaker> editors(studio::Context &ctx) const;
[[nodiscard]]
virtual ox::String id() const noexcept = 0;
virtual ox::Vector<ox::UPtr<ItemMaker>> itemMakers(studio::Context&) const;
[[nodiscard]]
virtual ox::Vector<Command> commands() const;
virtual ox::Vector<ox::UPtr<ItemTemplate>> itemTemplates(studio::Context&) const;
[[nodiscard]]
virtual ox::Vector<EditorMaker> editors(Context &ctx) const;
[[nodiscard]]
virtual ox::Vector<ox::UPtr<ItemMaker>> itemMakers(Context&) const;
[[nodiscard]]
virtual ox::Vector<ox::UPtr<ItemTemplate>> itemTemplates(Context&) const;
};

View File

@@ -59,7 +59,7 @@ class Project: public ox::SignalHandler {
ox::HashMap<ox::String, ox::Vector<ox::String>> m_fileExtFileMap;
public:
explicit Project(keel::Context &ctx, ox::String path, ox::StringViewCR projectDataDir);
explicit Project(keel::Context &ctx, ox::StringParam path, ox::StringViewCR projectDataDir);
ox::Error create() noexcept;
@@ -101,6 +101,16 @@ class Project: public ox::SignalHandler {
ox::Error deleteItem(ox::StringViewCR path) noexcept;
[[nodiscard]]
keel::Context &kctx() noexcept {
return m_kctx;
}
[[nodiscard]]
keel::Context const &kctx() const noexcept {
return m_kctx;
}
[[nodiscard]]
bool exists(ox::StringViewCR path) const noexcept;

View File

@@ -28,7 +28,7 @@ struct Selection {
}
};
constexpr auto iterateSelection(studio::Selection const&sel, auto const&cb) {
constexpr auto iterateSelection(Selection const &sel, auto const &cb) {
constexpr auto retErr = ox::is_same_v<decltype(cb(0, 0)), ox::Error>;
for (auto x = sel.a.x; x <= sel.b.x; ++x) {
for (auto y = sel.a.y; y <= sel.b.y; ++y) {
@@ -44,7 +44,7 @@ constexpr auto iterateSelection(studio::Selection const&sel, auto const&cb) {
}
};
constexpr auto iterateSelectionRows(studio::Selection const&sel, auto const&cb) {
constexpr auto iterateSelectionRows(Selection const &sel, auto const &cb) {
constexpr auto retErr = ox::is_same_v<decltype(cb(0, 0)), ox::Error>;
for (auto y = sel.a.y; y <= sel.b.y; ++y) {
for (auto x = sel.a.x; x <= sel.b.x; ++x) {

View File

@@ -12,7 +12,7 @@ namespace studio {
class NoChangesException: public ox::Exception {
public:
inline NoChangesException(std::source_location sloc = std::source_location::current()):
explicit NoChangesException(std::source_location sloc = std::source_location::current()):
ox::Exception(1, "Command makes no changes.", sloc) {}
};

View File

@@ -26,6 +26,22 @@ FilePickerPopup::FilePickerPopup(
m_fileExts{std::move(fileExt)} {
}
FilePickerPopup::FilePickerPopup(
ox::StringParam name,
keel::Context &kctx,
ox::SpanView<ox::StringLiteral> fileExts) noexcept:
m_name{std::move(name)},
m_explorer{kctx},
m_fileExts{[fileExts] {
ox::Vector<ox::String> out;
out.reserve(fileExts.size());
for (auto &s : fileExts) {
out.emplace_back(s);
}
return out;
}()} {
}
FilePickerPopup::FilePickerPopup(
ox::StringParam name,
keel::Context &kctx,

View File

@@ -18,11 +18,11 @@ ChildStackItem::~ChildStackItem() noexcept {
ImGui::EndChild();
}
IDStackItem::IDStackItem(int id) noexcept {
IDStackItem::IDStackItem(int const id) noexcept {
ImGui::PushID(id);
}
IDStackItem::IDStackItem(const char *id) noexcept {
IDStackItem::IDStackItem(ox::CString const id) noexcept {
ImGui::PushID(id);
}
@@ -55,7 +55,7 @@ bool PushButton(ox::CStringViewCR lbl, ImVec2 const &btnSz) noexcept {
}
PopupResponse PopupControlsOkCancel(
float popupWidth,
float const popupWidth,
bool &popupOpen,
ox::CStringViewCR ok,
ox::CStringViewCR cancel) {
@@ -110,14 +110,14 @@ bool BeginPopup(turbine::Context &ctx, ox::CStringViewCR popupName, bool &show,
}
bool ComboBox(
ox::CStringView lbl,
ox::SpanView<ox::CStringView> list,
ox::CStringView const &lbl,
ox::SpanView<ox::CStringView> const list,
size_t &selectedIdx) noexcept {
bool out{};
auto const first = selectedIdx < list.size() ? list[selectedIdx].c_str() : "";
if (ImGui::BeginCombo(lbl.c_str(), first, 0)) {
for (auto i = 0u; i < list.size(); ++i) {
const auto selected = (selectedIdx == i);
auto const selected = (selectedIdx == i);
if (ImGui::Selectable(list[i].c_str(), selected) && selectedIdx != i) {
selectedIdx = i;
out = true;
@@ -129,14 +129,14 @@ bool ComboBox(
}
bool ComboBox(
ox::CStringView lbl,
ox::Span<const ox::String> list,
ox::CStringView const &lbl,
ox::Span<ox::String const> const list,
size_t &selectedIdx) noexcept {
bool out{};
auto const first = selectedIdx < list.size() ? list[selectedIdx].c_str() : "";
if (ImGui::BeginCombo(lbl.c_str(), first, 0)) {
for (auto i = 0u; i < list.size(); ++i) {
const auto selected = (selectedIdx == i);
auto const selected = (selectedIdx == i);
if (ImGui::Selectable(list[i].c_str(), selected) && selectedIdx != i) {
selectedIdx = i;
out = true;
@@ -150,13 +150,13 @@ bool ComboBox(
bool ComboBox(
ox::CStringViewCR lbl,
std::function<ox::CStringView(size_t)> const &f,
size_t strCnt,
size_t const strCnt,
size_t &selectedIdx) noexcept {
bool out{};
auto const first = selectedIdx < strCnt ? f(selectedIdx).c_str() : "";
if (ImGui::BeginCombo(lbl.c_str(), first, 0)) {
for (auto i = 0u; i < strCnt; ++i) {
const auto selected = (selectedIdx == i);
auto const selected = (selectedIdx == i);
if (ImGui::Selectable(f(i).c_str(), selected) && selectedIdx != i) {
selectedIdx = i;
out = true;

View File

@@ -6,6 +6,10 @@
namespace studio {
ox::Vector<Command> Module::commands() const {
return {};
}
ox::Vector<EditorMaker> Module::editors(Context&) const {
return {};
}

View File

@@ -8,7 +8,7 @@
namespace studio {
void Popup::drawWindow(turbine::Context &ctx, bool &open, std::function<void()> const &drawContents) {
studio::ig::centerNextWindow(ctx);
ig::centerNextWindow(ctx);
ImGui::SetNextWindowSize(static_cast<ImVec2>(m_size));
constexpr auto modalFlags = ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize;
if (ImGui::BeginPopupModal(m_title.c_str(), &open, modalFlags)) {

View File

@@ -54,7 +54,7 @@ static constexpr bool isParentOf(ox::StringViewCR parent, ox::StringViewCR child
return beginsWith(sfmt("{}/", child), parent);
}
Project::Project(keel::Context &ctx, ox::String path, ox::StringViewCR projectDataDir):
Project::Project(keel::Context &ctx, ox::StringParam path, ox::StringViewCR projectDataDir):
m_kctx(ctx),
m_path(std::move(path)),
m_projectDataDir(projectDataDir),

View File

@@ -28,7 +28,7 @@ class ClipboardObject: public BaseClipboardObject {
}
};
ox::String getClipboardText(Context &ctx) noexcept;
ox::String getClipboardText(Context const &ctx) noexcept;
void setClipboardText(Context &ctx, ox::StringViewCR text) noexcept;

View File

@@ -9,7 +9,7 @@
namespace turbine {
ox::String getClipboardText(Context&) noexcept {
ox::String getClipboardText(Context const &) noexcept {
return {};
}

View File

@@ -50,7 +50,7 @@ OX_ALLOW_UNSAFE_BUFFERS_BEGIN
constexpr auto headerP1Len = ox::strlen(headerP2);
constexpr auto headerP2Len = ox::strlen(headerP1);
constexpr auto headerLen = headerP1Len + headerP2Len;
for (auto current = MEM_ROM; current < reinterpret_cast<char*>(0x0a000000); current += headerLen) {
for (auto current = MEM_ROM.data(); current < reinterpret_cast<char*>(0x0a000000); current += headerLen) {
if (memcmp(current, headerP1, headerP1Len) == 0 &&
memcmp(current + headerP1Len, headerP2, headerP2Len) == 0) {
return reinterpret_cast<std::size_t>(current + headerLen);

View File

@@ -12,7 +12,7 @@
namespace turbine {
ox::String getClipboardText(Context &ctx) noexcept {
ox::String getClipboardText(Context const &ctx) noexcept {
return ox::String(glfwGetClipboardString(ctx.window));
}