Squashed 'deps/nostalgia/' changes from 6a523191..84205879

84205879 [olympic] Cleanup ItemMaker, remove unnecessary copy
ebf3a696 [ox/std] Add String constructor that takes a StringLiteral
dfd27afd [ox/std] Add implicit String constructor for str literals
6bfe1842 [ox/std] Remove unnecessary copying from HashMap::expand
700d7016 [nostalgia] Update for Ox changes
92232383 [ox] Cleanup
3b8d13dc [nostalgia,olympic] Fixes for Ox update
a20d7fd9 [ox] Cleanup
2c0e0227 [ox/std] Add assert to AnyPtr::Wrap::copyTo to ensure sufficiently large buff
e3c74637 [turbine] Make applicationData return const&
41e08d67 [turbine] Make keyEventHandler nodiscard
50f3479d [ox/std] Make AnyPtr constexpr
1616ca70 [turbine] Replace WrapPtr with ox::AnyPtr
3fa247e3 [ox/std] Add AnyPtr
27f1df8f [nostalgia,olympic] Further reduce use of applicationData
a4f0c7cd [nostalgia/core/studio] Remove applicationData usages

git-subtree-dir: deps/nostalgia
git-subtree-split: 84205879d46610dfe08098d1265c0398f2215d3d
This commit is contained in:
2024-04-21 10:33:10 -05:00
parent 5627a63572
commit c0baf7efca
76 changed files with 544 additions and 453 deletions

View File

@ -15,10 +15,11 @@
namespace nostalgia::core {
PaletteEditorImGui::PaletteEditorImGui(studio::StudioContext &ctx, ox::CRStringView path):
PaletteEditorImGui::PaletteEditorImGui(studio::StudioContext &sctx, ox::CRStringView path):
Editor(path),
m_ctx(ctx.tctx),
m_pal(*keel::readObj<Palette>(keelCtx(m_ctx), ox::FileAddress(itemPath())).unwrapThrow()) {
m_sctx(sctx),
m_tctx(sctx.tctx),
m_pal(*keel::readObj<Palette>(keelCtx(m_tctx), ox::FileAddress(itemPath())).unwrapThrow()) {
undoStack()->changeTriggered.connect(this, &PaletteEditorImGui::handleCommand);
}
@ -27,12 +28,12 @@ void PaletteEditorImGui::keyStateChanged(turbine::Key key, bool down) {
return;
}
if (key >= turbine::Key::Num_1 && key <= turbine::Key::Num_9) {
if (turbine::buttonDown(m_ctx, turbine::Key::Mod_Alt)) {
if (turbine::buttonDown(m_tctx, turbine::Key::Mod_Alt)) {
m_page = ox::min<std::size_t>(
static_cast<uint32_t>(key - turbine::Key::Num_1), m_pal.pages.size() - 1);
}
} else if (key == turbine::Key::Num_0) {
if (turbine::buttonDown(m_ctx, turbine::Key::Mod_Alt)) {
if (turbine::buttonDown(m_tctx, turbine::Key::Mod_Alt)) {
m_selectedColorRow =
ox::min<std::size_t>(
static_cast<uint32_t>(key - turbine::Key::Num_1 + 9), m_pal.pages.size() - 1);
@ -41,7 +42,7 @@ void PaletteEditorImGui::keyStateChanged(turbine::Key key, bool down) {
}
void PaletteEditorImGui::draw(turbine::Context&) noexcept {
void PaletteEditorImGui::draw(studio::StudioContext&) noexcept {
auto const paneSize = ImGui::GetContentRegionAvail();
{
ImGui::BeginChild("Pages", ImVec2(250, paneSize.y), true);
@ -57,8 +58,7 @@ void PaletteEditorImGui::draw(turbine::Context&) noexcept {
}
ox::Error PaletteEditorImGui::saveItem() noexcept {
const auto sctx = applicationData<studio::StudioContext>(m_ctx);
return sctx->project->writeObj(itemPath(), m_pal);
return m_sctx.project->writeObj(itemPath(), m_pal);
}
void PaletteEditorImGui::drawColumn(ox::CStringView txt) noexcept {
@ -70,7 +70,7 @@ void PaletteEditorImGui::drawColumn(ox::CStringView txt) noexcept {
void PaletteEditorImGui::drawColumn(uint64_t i) noexcept {
ox::Array<char, 10> numStr;
ox_itoa(i, numStr.data());
ox::itoa(i, numStr.data());
drawColumn(numStr.data());
}

View File

@ -14,17 +14,18 @@ namespace nostalgia::core {
class PaletteEditorImGui: public studio::Editor {
private:
turbine::Context &m_ctx;
studio::StudioContext &m_sctx;
turbine::Context &m_tctx;
Palette m_pal;
size_t m_selectedColorRow = 0;
size_t m_page = 0;
public:
PaletteEditorImGui(studio::StudioContext &ctx, ox::CRStringView path);
PaletteEditorImGui(studio::StudioContext &sctx, ox::CRStringView path);
void keyStateChanged(turbine::Key key, bool down) override;
void draw(turbine::Context&) noexcept final;
void draw(studio::StudioContext&) noexcept final;
protected:
ox::Error saveItem() noexcept final;

View File

@ -24,7 +24,7 @@ core::DeleteTilesCommand::DeleteTilesCommand(
auto dst = m_deletedPixels.data();
auto src = p.data() + m_deletePos;
const auto sz = m_deleteSz * sizeof(decltype(p[0]));
ox_memcpy(dst, src, sz);
ox::memcpy(dst, src, sz);
}
}
@ -35,8 +35,8 @@ void core::DeleteTilesCommand::redo() noexcept {
const auto src = p.data() + srcPos;
const auto dst1 = p.data() + m_deletePos;
const auto dst2 = p.data() + (p.size() - m_deleteSz);
ox_memmove(dst1, src, p.size() - srcPos);
ox_memset(dst2, 0, m_deleteSz * sizeof(decltype(p[0])));
ox::memmove(dst1, src, p.size() - srcPos);
ox::memset(dst2, 0, m_deleteSz * sizeof(decltype(p[0])));
}
void DeleteTilesCommand::undo() noexcept {
@ -46,8 +46,8 @@ void DeleteTilesCommand::undo() noexcept {
const auto dst1 = p.data() + m_deletePos + m_deleteSz;
const auto dst2 = src;
const auto sz = p.size() - m_deletePos - m_deleteSz;
ox_memmove(dst1, src, sz);
ox_memcpy(dst2, m_deletedPixels.data(), m_deletedPixels.size());
ox::memmove(dst1, src, sz);
ox::memcpy(dst2, m_deletedPixels.data(), m_deletedPixels.size());
}
int DeleteTilesCommand::commandId() const noexcept {

View File

@ -24,7 +24,7 @@ core::InsertTilesCommand::InsertTilesCommand(
auto dst = m_deletedPixels.data();
auto src = p.data() + p.size() - m_insertCnt;
const auto sz = m_insertCnt * sizeof(decltype(p[0]));
ox_memcpy(dst, src, sz);
ox::memcpy(dst, src, sz);
}
}
@ -34,8 +34,8 @@ void InsertTilesCommand::redo() noexcept {
auto dstPos = m_insertPos + m_insertCnt;
const auto dst = p.data() + dstPos;
const auto src = p.data() + m_insertPos;
ox_memmove(dst, src, p.size() - dstPos);
ox_memset(src, 0, m_insertCnt * sizeof(decltype(p[0])));
ox::memmove(dst, src, p.size() - dstPos);
ox::memset(src, 0, m_insertCnt * sizeof(decltype(p[0])));
}
void InsertTilesCommand::undo() noexcept {
@ -46,8 +46,8 @@ void InsertTilesCommand::undo() noexcept {
const auto dst1 = p.data() + m_insertPos;
const auto dst2 = p.data() + p.size() - m_insertCnt;
const auto sz = p.size() - srcIdx;
ox_memmove(dst1, src, sz);
ox_memcpy(dst2, m_deletedPixels.data(), m_deletedPixels.size());
ox::memmove(dst1, src, sz);
ox::memcpy(dst2, m_deletedPixels.data(), m_deletedPixels.size());
}
int InsertTilesCommand::commandId() const noexcept {

View File

@ -75,10 +75,11 @@ static ox::Error toPngFile(
8)));
}
TileSheetEditorImGui::TileSheetEditorImGui(studio::StudioContext &ctx, ox::CRStringView path):
TileSheetEditorImGui::TileSheetEditorImGui(studio::StudioContext &sctx, ox::CRStringView path):
Editor(path),
m_ctx(ctx.tctx),
m_view(m_ctx, path, *undoStack()),
m_sctx(sctx),
m_tctx(m_sctx.tctx),
m_view(m_sctx, path, *undoStack()),
m_model(m_view.model()) {
oxIgnoreError(setPaletteSelection());
// connect signal/slots
@ -134,7 +135,7 @@ void TileSheetEditorImGui::keyStateChanged(turbine::Key key, bool down) {
setPasteEnabled(false);
m_model.clearSelection();
} else if (key >= turbine::Key::Num_1 && key <= turbine::Key::Num_9) {
if (turbine::buttonDown(m_ctx, turbine::Key::Mod_Alt)) {
if (turbine::buttonDown(m_tctx, turbine::Key::Mod_Alt)) {
auto const idx = ox::min<std::size_t>(
static_cast<uint32_t>(key - turbine::Key::Num_1), m_model.pal().pages.size() - 1);
m_model.setPalettePage(idx);
@ -143,7 +144,7 @@ void TileSheetEditorImGui::keyStateChanged(turbine::Key key, bool down) {
m_view.setPalIdx(idx);
}
} else if (key == turbine::Key::Num_0) {
if (turbine::buttonDown(m_ctx, turbine::Key::Mod_Alt)) {
if (turbine::buttonDown(m_tctx, turbine::Key::Mod_Alt)) {
auto const idx = ox::min<std::size_t>(
static_cast<uint32_t>(key - turbine::Key::Num_1 + 9), m_model.pal().pages.size() - 1);
m_model.setPalettePage(idx);
@ -156,7 +157,7 @@ void TileSheetEditorImGui::keyStateChanged(turbine::Key key, bool down) {
}
}
void TileSheetEditorImGui::draw(turbine::Context&) noexcept {
void TileSheetEditorImGui::draw(studio::StudioContext&) noexcept {
auto const paneSize = ImGui::GetContentRegionAvail();
auto const tileSheetParentSize = ImVec2(paneSize.x - m_palViewWidth, paneSize.y);
auto const fbSize = ox::Vec2(tileSheetParentSize.x - 16, tileSheetParentSize.y - 16);
@ -235,8 +236,8 @@ void TileSheetEditorImGui::draw(turbine::Context&) noexcept {
ImGui::EndChild();
}
ImGui::EndChild();
m_subsheetEditor.draw(m_ctx);
m_exportMenu.draw(m_ctx);
m_subsheetEditor.draw(m_tctx);
m_exportMenu.draw(m_sctx);
}
void TileSheetEditorImGui::drawSubsheetSelector(
@ -359,7 +360,7 @@ void TileSheetEditorImGui::drawTileSheet(ox::Vec2 const&fbSize) noexcept {
auto const wheelh = io.MouseWheelH;
if (wheel != 0) {
const auto zoomMod = ox::defines::OS == ox::OS::Darwin ?
io.KeySuper : turbine::buttonDown(m_ctx, turbine::Key::Mod_Ctrl);
io.KeySuper : turbine::buttonDown(m_tctx, turbine::Key::Mod_Ctrl);
m_view.scrollV(fbSize, wheel, zoomMod);
}
if (wheelh != 0) {
@ -399,8 +400,7 @@ void TileSheetEditorImGui::drawTileSheet(ox::Vec2 const&fbSize) noexcept {
}
void TileSheetEditorImGui::drawPaletteSelector() noexcept {
auto &sctx = *applicationData<studio::StudioContext>(m_ctx);
auto const&files = sctx.project->fileList(core::FileExt_npal);
auto const&files = m_sctx.project->fileList(core::FileExt_npal);
auto const comboWidthSub = 62;
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x - comboWidthSub);
if (ig::ComboBox("Palette", files, m_selectedPaletteIdx)) {
@ -410,12 +410,12 @@ void TileSheetEditorImGui::drawPaletteSelector() noexcept {
if (pages > 1) {
ImGui::Indent(20);
ox::Array<char, 10> numStr;
ox_itoa(m_model.palettePage() + 1, numStr.data());
ox::itoa(m_model.palettePage() + 1, numStr.data());
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x - comboWidthSub);
if (ImGui::BeginCombo("Page", numStr.data(), 0)) {
for (auto n = 0u; n < pages; ++n) {
auto const selected = (m_model.palettePage() == n);
ox_itoa(n + 1, numStr.data());
ox::itoa(n + 1, numStr.data());
if (ImGui::Selectable(numStr.data(), selected) && m_model.palettePage() != n) {
m_model.setPalettePage(n);
}
@ -465,8 +465,7 @@ ox::Error TileSheetEditorImGui::updateActiveSubsheet(ox::StringView const&name,
ox::Error TileSheetEditorImGui::setPaletteSelection() noexcept {
auto const&palPath = m_model.palPath();
auto &sctx = *applicationData<studio::StudioContext>(m_ctx);
auto const&palList = sctx.project->fileList(core::FileExt_npal);
auto const&palList = m_sctx.project->fileList(core::FileExt_npal);
for (std::size_t i = 0; auto const&pal : palList) {
if (palPath == pal) {
m_selectedPaletteIdx = i;
@ -482,7 +481,7 @@ ox::Error TileSheetEditorImGui::markUnsavedChanges(studio::UndoCommand const*) n
return {};
}
void TileSheetEditorImGui::SubSheetEditor::draw(turbine::Context &ctx) noexcept {
void TileSheetEditorImGui::SubSheetEditor::draw(turbine::Context &sctx) noexcept {
constexpr auto popupName = "Edit Subsheet";
if (!m_show) {
return;
@ -491,7 +490,7 @@ void TileSheetEditorImGui::SubSheetEditor::draw(turbine::Context &ctx) noexcept
auto constexpr popupWidth = 235.f;
auto const popupHeight = modSize ? 130.f : 85.f;
auto const popupSz = ImVec2(popupWidth, popupHeight);
if (ig::BeginPopup(ctx, popupName, m_show, popupSz)) {
if (ig::BeginPopup(sctx, popupName, m_show, popupSz)) {
ImGui::InputText("Name", m_name.data(), m_name.cap());
if (modSize) {
ImGui::InputInt("Columns", &m_cols);
@ -508,7 +507,7 @@ void TileSheetEditorImGui::SubSheetEditor::close() noexcept {
m_show = false;
}
void TileSheetEditorImGui::ExportMenu::draw(turbine::Context &ctx) noexcept {
void TileSheetEditorImGui::ExportMenu::draw(studio::StudioContext &sctx) noexcept {
constexpr auto popupName = "Export Tile Sheet";
if (!m_show) {
return;
@ -516,7 +515,7 @@ void TileSheetEditorImGui::ExportMenu::draw(turbine::Context &ctx) noexcept {
constexpr auto popupWidth = 235.f;
constexpr auto popupHeight = 85.f;
constexpr auto popupSz = ImVec2(popupWidth, popupHeight);
if (ig::BeginPopup(ctx, popupName, m_show, popupSz)) {
if (ig::BeginPopup(sctx.tctx, popupName, m_show, popupSz)) {
ImGui::InputInt("Scale", &m_scale);
m_scale = ox::clamp(m_scale, 1, 50);
if (ig::PopupControlsOkCancel(popupWidth, m_show) == ig::PopupResponse::OK) {

View File

@ -40,7 +40,7 @@ class TileSheetEditorImGui: public studio::Editor {
m_cols = cols;
m_rows = rows;
}
void draw(turbine::Context &ctx) noexcept;
void draw(turbine::Context &sctx) noexcept;
void close() noexcept;
[[nodiscard]]
inline bool isOpen() const noexcept { return m_show; }
@ -55,13 +55,14 @@ class TileSheetEditorImGui: public studio::Editor {
m_show = true;
m_scale = 5;
}
void draw(turbine::Context &ctx) noexcept;
void draw(studio::StudioContext &sctx) noexcept;
void close() noexcept;
[[nodiscard]]
inline bool isOpen() const noexcept { return m_show; }
};
std::size_t m_selectedPaletteIdx = 0;
turbine::Context &m_ctx;
studio::StudioContext &m_sctx;
turbine::Context &m_tctx;
ox::Vector<ox::String> m_paletteList;
SubSheetEditor m_subsheetEditor;
ExportMenu m_exportMenu;
@ -73,7 +74,7 @@ class TileSheetEditorImGui: public studio::Editor {
Tool m_tool = Tool::Draw;
public:
TileSheetEditorImGui(studio::StudioContext &ctx, ox::CRStringView path);
TileSheetEditorImGui(studio::StudioContext &sctx, ox::CRStringView path);
~TileSheetEditorImGui() override = default;
@ -87,7 +88,7 @@ class TileSheetEditorImGui: public studio::Editor {
void keyStateChanged(turbine::Key key, bool down) override;
void draw(turbine::Context&) noexcept override;
void draw(studio::StudioContext&) noexcept override;
void drawSubsheetSelector(TileSheet::SubSheet&, TileSheet::SubSheetIdx &path);

View File

@ -41,12 +41,13 @@ static void normalizeSubsheets(TileSheet::SubSheet &ss) noexcept {
}
}
TileSheetEditorModel::TileSheetEditorModel(turbine::Context &ctx, ox::StringView path, studio::UndoStack &undoStack):
m_ctx(ctx),
TileSheetEditorModel::TileSheetEditorModel(studio::StudioContext &sctx, ox::StringView path, studio::UndoStack &undoStack):
m_sctx(sctx),
m_tctx(m_sctx.tctx),
m_path(path),
m_img(*readObj<TileSheet>(keelCtx(m_ctx), m_path).unwrapThrow()),
m_img(*readObj<TileSheet>(keelCtx(m_tctx), m_path).unwrapThrow()),
// ignore failure to load palette
m_pal(readObj<Palette>(keelCtx(m_ctx), m_img.defaultPalette).value),
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);
@ -70,7 +71,7 @@ void TileSheetEditorModel::cut() {
}
const auto pt1 = m_selectionOrigin == ox::Point(-1, -1) ? ox::Point(0, 0) : m_selectionOrigin;
const auto pt2 = ox::Point(s.columns * TileWidth, s.rows * TileHeight);
turbine::setClipboardObject(m_ctx, std::move(cb));
turbine::setClipboardObject(m_tctx, std::move(cb));
pushCommand(ox::make<CutPasteCommand>(CommandId::Cut, m_img, m_activeSubsSheetIdx, pt1, pt2, blankCb));
}
@ -87,11 +88,11 @@ void TileSheetEditorModel::copy() {
cb->addPixel(pt, c);
}
}
turbine::setClipboardObject(m_ctx, std::move(cb));
turbine::setClipboardObject(m_tctx, std::move(cb));
}
void TileSheetEditorModel::paste() {
auto [cb, err] = turbine::getClipboardObject<TileSheetClipboard>(m_ctx);
auto [cb, err] = turbine::getClipboardObject<TileSheetClipboard>(m_tctx);
if (err) {
oxLogError(err);
oxErrf("Could not read clipboard: {}", toStr(err));
@ -111,7 +112,7 @@ ox::StringView TileSheetEditorModel::palPath() const noexcept {
constexpr ox::StringView uuidPrefix = "uuid://";
if (ox::beginsWith(path, uuidPrefix)) {
auto uuid = ox::StringView(path.data() + uuidPrefix.bytes(), path.bytes() - uuidPrefix.bytes());
auto out = keelCtx(m_ctx).uuidToPath.at(uuid);
auto out = keelCtx(m_tctx).uuidToPath.at(uuid);
if (out.error) {
return {};
}
@ -122,7 +123,7 @@ ox::StringView TileSheetEditorModel::palPath() const noexcept {
}
ox::Error TileSheetEditorModel::setPalette(ox::StringView path) noexcept {
oxRequire(uuid, keelCtx(m_ctx).pathToUuid.at(path));
oxRequire(uuid, keelCtx(m_tctx).pathToUuid.at(path));
pushCommand(ox::make<PaletteChangeCommand>(activeSubSheetIdx(), m_img, uuid->toString()));
return {};
}
@ -239,7 +240,7 @@ ox::Error TileSheetEditorModel::markUpdatedCmdId(studio::UndoCommand const*cmd)
m_updated = true;
const auto cmdId = cmd->commandId();
if (static_cast<CommandId>(cmdId) == CommandId::PaletteChange) {
oxReturnError(readObj<Palette>(keelCtx(m_ctx), m_img.defaultPalette).moveTo(m_pal));
oxReturnError(readObj<Palette>(keelCtx(m_tctx), m_img.defaultPalette).moveTo(m_pal));
m_palettePage = ox::min<size_t>(m_pal->pages.size(), 0);
paletteChanged.emit();
}
@ -261,8 +262,7 @@ void TileSheetEditorModel::ackUpdate() noexcept {
}
ox::Error TileSheetEditorModel::saveFile() noexcept {
const auto sctx = applicationData<studio::StudioContext>(m_ctx);
return sctx->project->writeObj(m_path, m_img, ox::ClawFormat::Metal);
return m_sctx.project->writeObj(m_path, m_img, ox::ClawFormat::Metal);
}
bool TileSheetEditorModel::pixelSelected(std::size_t idx) const noexcept {

View File

@ -24,7 +24,8 @@ class TileSheetEditorModel: public ox::SignalHandler {
private:
static Palette const s_defaultPalette;
turbine::Context &m_ctx;
studio::StudioContext &m_sctx;
turbine::Context &m_tctx;
ox::String m_path;
TileSheet m_img;
TileSheet::SubSheetIdx m_activeSubsSheetIdx;
@ -38,7 +39,7 @@ class TileSheetEditorModel: public ox::SignalHandler {
ox::Bounds m_selectionBounds = {{-1, -1}, {-1, -1}};
public:
TileSheetEditorModel(turbine::Context &ctx, ox::StringView path, studio::UndoStack &undoStack);
TileSheetEditorModel(studio::StudioContext &sctx, ox::StringView path, studio::UndoStack &undoStack);
~TileSheetEditorModel() override = default;

View File

@ -11,8 +11,8 @@
namespace nostalgia::core {
TileSheetEditorView::TileSheetEditorView(turbine::Context &ctx, ox::StringView path, studio::UndoStack &undoStack):
m_model(ctx, path, undoStack),
TileSheetEditorView::TileSheetEditorView(studio::StudioContext &sctx, ox::StringView path, studio::UndoStack &undoStack):
m_model(sctx, path, undoStack),
m_pixelsDrawer(m_model) {
// build shaders
oxThrowError(m_pixelsDrawer.buildShader());

View File

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

View File

@ -18,7 +18,7 @@ SceneEditorImGui::SceneEditorImGui(studio::StudioContext &ctx, ox::StringView pa
setRequiresConstantRefresh(false);
}
void SceneEditorImGui::draw(turbine::Context&) noexcept {
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();

View File

@ -23,7 +23,7 @@ class SceneEditorImGui: public studio::Editor {
public:
SceneEditorImGui(studio::StudioContext &ctx, ox::StringView path);
void draw(turbine::Context&) noexcept final;
void draw(studio::StudioContext&) noexcept final;
void onActivated() noexcept override;