Merge commit 'ce53be92716b0f5201882d6959c398b61c6cc93c'

This commit is contained in:
2025-05-07 00:12:52 -05:00
140 changed files with 22045 additions and 402 deletions

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

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

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

@@ -35,8 +35,10 @@ ox::Error gfx::DeleteTilesCommand::redo() noexcept {
auto const src = &p[srcPos];
auto const dst1 = &p[m_deletePos];
auto const dst2 = &p[(p.size() - m_deleteSz)];
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
ox::memmove(dst1, src, p.size() - srcPos);
ox::memset(dst2, 0, m_deleteSz * sizeof(decltype(p[0])));
OX_ALLOW_UNSAFE_BUFFERS_END
return {};
}
@@ -47,8 +49,10 @@ ox::Error DeleteTilesCommand::undo() noexcept {
auto const dst1 = &p[m_deletePos + m_deleteSz];
auto const dst2 = src;
auto const sz = p.size() - m_deletePos - m_deleteSz;
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
ox::memmove(dst1, src, sz);
ox::memcpy(dst2, m_deletedPixels.data(), m_deletedPixels.size());
OX_ALLOW_UNSAFE_BUFFERS_END
return {};
}

View File

@@ -27,6 +27,8 @@ InsertTilesCommand::InsertTilesCommand(
}
}
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
ox::Error InsertTilesCommand::redo() noexcept {
auto &s = getSubSheet(m_img, m_idx);
auto &p = s.pixels;
@@ -55,6 +57,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

@@ -87,7 +87,7 @@ static ox::Error toPngFile(
8)));
}
TileSheetEditorImGui::TileSheetEditorImGui(studio::StudioContext &sctx, ox::StringParam path):
TileSheetEditorImGui::TileSheetEditorImGui(studio::Context &sctx, ox::StringParam path):
Editor(sctx, std::move(path)),
m_sctx{sctx},
m_tctx{m_sctx.tctx},
@@ -129,7 +129,7 @@ void TileSheetEditorImGui::keyStateChanged(turbine::Key const key, bool const do
if (!down) {
return;
}
if (key == turbine::Key::Escape) {
if (ig::mainWinHasFocus() && key == turbine::Key::Escape) {
m_subsheetEditor.close();
m_exportMenu.close();
m_palPicker.close();
@@ -188,7 +188,7 @@ void TileSheetEditorImGui::keyStateChanged(turbine::Key const key, bool const do
}
}
void TileSheetEditorImGui::draw(studio::StudioContext&) noexcept {
void TileSheetEditorImGui::draw(studio::Context&) noexcept {
if (ig::mainWinHasFocus() && m_tool == TileSheetTool::Select) {
if (ImGui::IsKeyDown(ImGuiKey_ModCtrl) && !m_palPathFocused) {
if (ImGui::IsKeyPressed(ImGuiKey_A)) {
@@ -549,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)) {

View File

@@ -45,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;
@@ -60,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;
@@ -77,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);

View File

@@ -45,7 +45,7 @@ Palette const TileSheetEditorModel::s_defaultPalette = {
};
TileSheetEditorModel::TileSheetEditorModel(
studio::StudioContext &sctx, ox::StringParam path, studio::UndoStack &undoStack):
studio::Context &sctx, ox::StringParam path, studio::UndoStack &undoStack):
m_sctx(sctx),
m_tctx(m_sctx.tctx),
m_path(std::move(path)),

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;

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