From 03a1a8abcaa5e306b0976efd045a4caffb571c68 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Tue, 30 May 2023 20:33:06 -0500 Subject: [PATCH] [nostalgia] Move geo types to Ox --- src/CMakeLists.txt | 2 +- src/nostalgia/CMakeLists.txt | 1 - src/nostalgia/core/color.hpp | 4 +- src/nostalgia/core/context.hpp | 10 +- src/nostalgia/core/gba/context.hpp | 2 +- src/nostalgia/core/gba/gfx.cpp | 2 +- src/nostalgia/core/gfx.hpp | 9 +- src/nostalgia/core/glfw/gfx.cpp | 4 +- src/nostalgia/core/opengl/gfx_opengl.cpp | 14 +- src/nostalgia/core/palette.hpp | 4 +- src/nostalgia/core/ptidxconv.hpp | 24 +- .../core/studio/tilesheeteditor-imgui.cpp | 14 +- .../core/studio/tilesheeteditor-imgui.hpp | 10 +- .../core/studio/tilesheeteditormodel.cpp | 38 +-- .../core/studio/tilesheeteditormodel.hpp | 16 +- .../core/studio/tilesheeteditorview.cpp | 23 +- .../core/studio/tilesheeteditorview.hpp | 26 +- .../core/studio/tilesheetpixelgrid.cpp | 14 +- .../core/studio/tilesheetpixelgrid.hpp | 14 +- src/nostalgia/core/studio/tilesheetpixels.cpp | 14 +- src/nostalgia/core/studio/tilesheetpixels.hpp | 17 +- src/nostalgia/core/tilesheet.hpp | 18 +- src/nostalgia/geo/CMakeLists.txt | 21 -- src/nostalgia/geo/bounds.hpp | 131 --------- src/nostalgia/geo/geo.hpp | 9 - src/nostalgia/geo/point.hpp | 188 ------------- src/nostalgia/geo/size.hpp | 188 ------------- src/nostalgia/geo/vec.cpp | 16 -- src/nostalgia/geo/vec.hpp | 264 ------------------ src/nostalgia/scene/CMakeLists.txt | 1 - src/nostalgia/scene/scenestatic.hpp | 6 +- .../scene/studio/sceneeditor-imgui.cpp | 2 +- src/nostalgia/studio/lib/popup.hpp | 10 +- src/nostalgia/studio/projectexplorer.cpp | 4 +- 34 files changed, 147 insertions(+), 973 deletions(-) delete mode 100644 src/nostalgia/geo/CMakeLists.txt delete mode 100644 src/nostalgia/geo/bounds.hpp delete mode 100644 src/nostalgia/geo/geo.hpp delete mode 100644 src/nostalgia/geo/point.hpp delete mode 100644 src/nostalgia/geo/size.hpp delete mode 100644 src/nostalgia/geo/vec.cpp delete mode 100644 src/nostalgia/geo/vec.hpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1ef4f24b..d455c7f6 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,4 +1,4 @@ include_directories(".") add_subdirectory(keel) -add_subdirectory(nostalgia) +add_subdirectory(nostalgia) \ No newline at end of file diff --git a/src/nostalgia/CMakeLists.txt b/src/nostalgia/CMakeLists.txt index f57f5442..ca1baa12 100644 --- a/src/nostalgia/CMakeLists.txt +++ b/src/nostalgia/CMakeLists.txt @@ -3,7 +3,6 @@ add_subdirectory(appmodules) add_subdirectory(core) -add_subdirectory(geo) add_subdirectory(scene) if(NOSTALGIA_BUILD_PLAYER) diff --git a/src/nostalgia/core/color.hpp b/src/nostalgia/core/color.hpp index 43dd8af4..d80e0bec 100644 --- a/src/nostalgia/core/color.hpp +++ b/src/nostalgia/core/color.hpp @@ -1,11 +1,11 @@ /* - * Copyright 2016 - 2022 Gary Talent (gary@drinkingtea.net). All rights reserved. + * Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved. */ #pragma once #include -#include +#include #include "context.hpp" diff --git a/src/nostalgia/core/context.hpp b/src/nostalgia/core/context.hpp index 2c158bc9..c15ed1bc 100644 --- a/src/nostalgia/core/context.hpp +++ b/src/nostalgia/core/context.hpp @@ -7,9 +7,9 @@ #include #include #include +#include #include -#include #include "event.hpp" #include "input.hpp" @@ -18,7 +18,7 @@ namespace nostalgia::core::gl { void setMainViewEnabled(core::Context *ctx, bool enabled) noexcept; void drawMainView(core::Context*) noexcept; void setRenderSize(core::Context*, int width, int height) noexcept; -geo::Size getRenderSize(core::Context*) noexcept; +ox::Size getRenderSize(core::Context*) noexcept; void clearRenderSize(core::Context *ctx) noexcept; } @@ -26,7 +26,7 @@ namespace nostalgia::core::renderer { ox::Error init(Context *ctx) noexcept; } -namespace nostalgia::geo { +namespace ox { class Size; } @@ -67,7 +67,7 @@ class Context: public keel::Context { friend constexpr void setConstantRefresh(Context *ctx, bool) noexcept; friend bool bgStatus(Context *ctx, unsigned bg) noexcept; friend bool buttonDown(Context *ctx, Key) noexcept; - friend geo::Size getScreenSize(Context *ctx) noexcept; + friend ox::Size getScreenSize(Context *ctx) noexcept; friend int getScreenHeight(Context *ctx) noexcept; friend int getScreenWidth(Context *ctx) noexcept; friend ox::Error initGfx(Context *ctx) noexcept; @@ -109,7 +109,7 @@ class Context: public keel::Context { friend void gl::setMainViewEnabled(core::Context *ctx, bool enabled) noexcept; friend void gl::drawMainView(core::Context*) noexcept; friend void gl::setRenderSize(core::Context*, int width, int height) noexcept; - friend geo::Size gl::getRenderSize(core::Context*) noexcept; + friend ox::Size gl::getRenderSize(core::Context*) noexcept; friend void gl::clearRenderSize(core::Context *ctx) noexcept; public: diff --git a/src/nostalgia/core/gba/context.hpp b/src/nostalgia/core/gba/context.hpp index aa74fa38..d78459ee 100644 --- a/src/nostalgia/core/gba/context.hpp +++ b/src/nostalgia/core/gba/context.hpp @@ -7,9 +7,9 @@ #include #include #include +#include #include -#include #include diff --git a/src/nostalgia/core/gba/gfx.cpp b/src/nostalgia/core/gba/gfx.cpp index abc56ea4..a3e80f99 100644 --- a/src/nostalgia/core/gba/gfx.cpp +++ b/src/nostalgia/core/gba/gfx.cpp @@ -100,7 +100,7 @@ int getScreenHeight(Context*) noexcept { return 160; } -geo::Size getScreenSize(Context*) noexcept { +ox::Size getScreenSize(Context*) noexcept { return {240, 160}; } diff --git a/src/nostalgia/core/gfx.hpp b/src/nostalgia/core/gfx.hpp index 57423a4d..1eca9bad 100644 --- a/src/nostalgia/core/gfx.hpp +++ b/src/nostalgia/core/gfx.hpp @@ -1,16 +1,15 @@ /* - * Copyright 2016 - 2022 Gary Talent (gary@drinkingtea.net). All rights reserved. + * Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved. */ #pragma once #include +#include +#include #include #include -#include -#include - #include "color.hpp" #include "context.hpp" #include "ptidxconv.hpp" @@ -69,7 +68,7 @@ int getScreenWidth(Context *ctx) noexcept; int getScreenHeight(Context *ctx) noexcept; [[nodiscard]] -geo::Size getScreenSize(Context *ctx) noexcept; +ox::Size getScreenSize(Context *ctx) noexcept; [[nodiscard]] uint8_t bgStatus(Context *ctx) noexcept; diff --git a/src/nostalgia/core/glfw/gfx.cpp b/src/nostalgia/core/glfw/gfx.cpp index eccdb1b8..e1b06922 100644 --- a/src/nostalgia/core/glfw/gfx.cpp +++ b/src/nostalgia/core/glfw/gfx.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2016 - 2022 Gary Talent (gary@drinkingtea.net). All rights reserved. + * Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved. */ #include @@ -246,7 +246,7 @@ int getScreenHeight(Context *ctx) noexcept { return h; } -geo::Size getScreenSize(Context *ctx) noexcept { +ox::Size getScreenSize(Context *ctx) noexcept { auto id = ctx->windowerData(); int w = 0, h = 0; glfwGetFramebufferSize(id->window, &w, &h); diff --git a/src/nostalgia/core/opengl/gfx_opengl.cpp b/src/nostalgia/core/opengl/gfx_opengl.cpp index cc0ae5ec..ecf1c3e0 100644 --- a/src/nostalgia/core/opengl/gfx_opengl.cpp +++ b/src/nostalgia/core/opengl/gfx_opengl.cpp @@ -1,13 +1,13 @@ /* - * Copyright 2016 - 2022 Gary Talent (gary@drinkingtea.net). All rights reserved. + * Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved. */ #include #include #include +#include -#include #include #include @@ -18,10 +18,6 @@ namespace nostalgia::core { void ImGui_Impl_NewFrame() noexcept; -namespace gl { - -} - namespace renderer { constexpr uint64_t TileRows = 128; @@ -72,7 +68,7 @@ struct GlImplData { SpriteBlockset spriteBlocks; ox::Array spriteStates; ox::Array backgrounds; - ox::Optional renderSize; + ox::Optional renderSize; }; constexpr ox::StringView bgvshadTmpl = R"( @@ -482,7 +478,7 @@ void setSprite(Context *ctx, //oxTracef("nostalgia::core::gfx::gl", "setSprite(ctx, {}, {}, {}, {}, {}, {}, {})", // idx, x, y, tileIdx, spriteShape, spriteSize, flipX); // Tonc Table 8.4 - static constexpr ox::Array, 12> dimensions{ + static constexpr ox::Array, 12> dimensions{ // col 0 {1, 1}, // 0, 0 {2, 2}, // 0, 1 @@ -575,7 +571,7 @@ void clearRenderSize(core::Context *ctx) noexcept { id->renderSize.reset(); } -geo::Size getRenderSize(core::Context *ctx) noexcept { +ox::Size getRenderSize(core::Context *ctx) noexcept { const auto id = ctx->rendererData(); if (id->renderSize.has_value()) { return id->renderSize.value(); diff --git a/src/nostalgia/core/palette.hpp b/src/nostalgia/core/palette.hpp index 10c06982..a2bdba01 100644 --- a/src/nostalgia/core/palette.hpp +++ b/src/nostalgia/core/palette.hpp @@ -5,11 +5,11 @@ #pragma once #include +#include +#include #include #include -#include -#include #include "color.hpp" #include "context.hpp" diff --git a/src/nostalgia/core/ptidxconv.hpp b/src/nostalgia/core/ptidxconv.hpp index 9c78b965..ca5ecb47 100644 --- a/src/nostalgia/core/ptidxconv.hpp +++ b/src/nostalgia/core/ptidxconv.hpp @@ -1,10 +1,10 @@ /* - * Copyright 2016 - 2022 Gary Talent (gary@drinkingtea.net). All rights reserved. + * Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved. */ #pragma once -#include +#include #include "consts.hpp" @@ -22,12 +22,12 @@ constexpr std::size_t ptToIdx(int x, int y, int c) noexcept { } [[nodiscard]] -constexpr std::size_t ptToIdx(const geo::Point &pt, int c) noexcept { +constexpr std::size_t ptToIdx(const ox::Point &pt, int c) noexcept { return ptToIdx(pt.x, pt.y, c * TileWidth); } [[nodiscard]] -constexpr geo::Point idxToPt(int i, int c) noexcept { +constexpr ox::Point idxToPt(int i, int c) noexcept { // prevent divide by zeros if (!c) { ++c; @@ -44,13 +44,13 @@ constexpr geo::Point idxToPt(int i, int c) noexcept { }; } -static_assert(idxToPt(4, 1) == geo::Point{4, 0}); -static_assert(idxToPt(8, 1) == geo::Point{0, 1}); -static_assert(idxToPt(8, 2) == geo::Point{0, 1}); -static_assert(idxToPt(64, 2) == geo::Point{8, 0}); -static_assert(idxToPt(128, 2) == geo::Point{0, 8}); -static_assert(idxToPt(129, 2) == geo::Point{1, 8}); -static_assert(idxToPt(192, 2) == geo::Point{8, 8}); -static_assert(idxToPt(384, 8) == geo::Point{48, 0}); +static_assert(idxToPt(4, 1) == ox::Point{4, 0}); +static_assert(idxToPt(8, 1) == ox::Point{0, 1}); +static_assert(idxToPt(8, 2) == ox::Point{0, 1}); +static_assert(idxToPt(64, 2) == ox::Point{8, 0}); +static_assert(idxToPt(128, 2) == ox::Point{0, 8}); +static_assert(idxToPt(129, 2) == ox::Point{1, 8}); +static_assert(idxToPt(192, 2) == ox::Point{8, 8}); +static_assert(idxToPt(384, 8) == ox::Point{48, 0}); } diff --git a/src/nostalgia/core/studio/tilesheeteditor-imgui.cpp b/src/nostalgia/core/studio/tilesheeteditor-imgui.cpp index e477a79e..8f80850f 100644 --- a/src/nostalgia/core/studio/tilesheeteditor-imgui.cpp +++ b/src/nostalgia/core/studio/tilesheeteditor-imgui.cpp @@ -5,8 +5,8 @@ #include #include +#include #include -#include #include "tilesheeteditor-imgui.hpp" @@ -114,7 +114,7 @@ void TileSheetEditorImGui::keyStateChanged(core::Key key, bool down) { void TileSheetEditorImGui::draw(core::Context*) noexcept { const auto paneSize = ImGui::GetContentRegionAvail(); const auto tileSheetParentSize = ImVec2(paneSize.x - m_palViewWidth, paneSize.y); - const auto fbSize = geo::Vec2(tileSheetParentSize.x - 16, tileSheetParentSize.y - 16); + const auto fbSize = ox::Vec2(tileSheetParentSize.x - 16, tileSheetParentSize.y - 16); ImGui::BeginChild("TileSheetView", tileSheetParentSize, true); { drawTileSheet(fbSize); @@ -240,7 +240,7 @@ studio::UndoStack *TileSheetEditorImGui::undoStack() noexcept { } [[nodiscard]] -geo::Vec2 TileSheetEditorImGui::clickPos(const ImVec2 &winPos, geo::Vec2 clickPos) noexcept { +ox::Vec2 TileSheetEditorImGui::clickPos(const ImVec2 &winPos, ox::Vec2 clickPos) noexcept { clickPos.x -= winPos.x + 10; clickPos.y -= winPos.y + 10; return clickPos; @@ -274,9 +274,9 @@ void TileSheetEditorImGui::exportSubhseetToPng() noexcept { } } -void TileSheetEditorImGui::drawTileSheet(const geo::Vec2 &fbSize) noexcept { +void TileSheetEditorImGui::drawTileSheet(const ox::Vec2 &fbSize) noexcept { const auto winPos = ImGui::GetWindowPos(); - const auto fbSizei = geo::Size(static_cast(fbSize.x), static_cast(fbSize.y)); + const auto fbSizei = ox::Size(static_cast(fbSize.x), static_cast(fbSize.y)); if (m_framebuffer.width != fbSizei.width || m_framebuffer.height != fbSizei.height) { glutils::resizeInitFrameBuffer(&m_framebuffer, fbSizei.width, fbSizei.height); m_tileSheetEditor.resizeView(fbSize); @@ -296,7 +296,7 @@ void TileSheetEditorImGui::drawTileSheet(const geo::Vec2 &fbSize) noexcept { ImVec2(1, 0)); // handle input, this must come after drawing const auto &io = ImGui::GetIO(); - const auto mousePos = geo::Vec2(io.MousePos); + const auto mousePos = ox::Vec2(io.MousePos); if (ImGui::IsItemHovered()) { const auto wheel = io.MouseWheel; const auto wheelh = io.MouseWheelH; @@ -326,7 +326,7 @@ void TileSheetEditorImGui::drawTileSheet(const geo::Vec2 &fbSize) noexcept { } } if (ImGui::BeginPopupContextItem("TileMenu", ImGuiPopupFlags_MouseButtonRight)) { - const auto popupPos = geo::Vec2(ImGui::GetWindowPos()); + const auto popupPos = ox::Vec2(ImGui::GetWindowPos()); if (ImGui::MenuItem("Insert Tile")) { m_tileSheetEditor.insertTile(fbSize, clickPos(winPos, popupPos)); } diff --git a/src/nostalgia/core/studio/tilesheeteditor-imgui.hpp b/src/nostalgia/core/studio/tilesheeteditor-imgui.hpp index b7631a64..9800f029 100644 --- a/src/nostalgia/core/studio/tilesheeteditor-imgui.hpp +++ b/src/nostalgia/core/studio/tilesheeteditor-imgui.hpp @@ -1,12 +1,12 @@ /* - * Copyright 2016 - 2022 Gary Talent (gary@drinkingtea.net). All rights reserved. + * Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved. */ #pragma once #include +#include -#include #include #include @@ -51,7 +51,7 @@ class TileSheetEditorImGui: public studio::BaseEditor { glutils::FrameBuffer m_framebuffer; TileSheetEditorView m_tileSheetEditor; float m_palViewWidth = 300; - geo::Vec2 m_prevMouseDownPos; + ox::Vec2 m_prevMouseDownPos; Tool m_tool = Tool::Draw; public: @@ -80,7 +80,7 @@ class TileSheetEditorImGui: public studio::BaseEditor { studio::UndoStack *undoStack() noexcept final; [[nodiscard]] - static geo::Vec2 clickPos(const ImVec2 &winPos, geo::Vec2 clickPos) noexcept; + static ox::Vec2 clickPos(const ImVec2 &winPos, ox::Vec2 clickPos) noexcept; protected: ox::Error saveItem() noexcept override; @@ -112,7 +112,7 @@ class TileSheetEditorImGui: public studio::BaseEditor { [[nodiscard]] ox::String palettePath(const ox::String &palettePath) const; - void drawTileSheet(const geo::Vec2 &fbSize) noexcept; + void drawTileSheet(const ox::Vec2 &fbSize) noexcept; void drawPaletteSelector() noexcept; diff --git a/src/nostalgia/core/studio/tilesheeteditormodel.cpp b/src/nostalgia/core/studio/tilesheeteditormodel.cpp index 3192e3a7..c72b6799 100644 --- a/src/nostalgia/core/studio/tilesheeteditormodel.cpp +++ b/src/nostalgia/core/studio/tilesheeteditormodel.cpp @@ -30,8 +30,8 @@ class TileSheetClipboard: public ClipboardObject { static constexpr auto TypeName = "net.drinkingtea.nostalgia.core.studio.TileSheetClipboard.Pixel"; static constexpr auto TypeVersion = 1; uint16_t colorIdx = 0; - geo::Point pt; - constexpr Pixel(uint16_t pColorIdx, geo::Point pPt) noexcept { + ox::Point pt; + constexpr Pixel(uint16_t pColorIdx, ox::Point pPt) noexcept { colorIdx = pColorIdx; pt = pPt; } @@ -40,7 +40,7 @@ class TileSheetClipboard: public ClipboardObject { ox::Vector m_pixels; public: - constexpr void addPixel(const geo::Point &pt, uint16_t colorIdx) noexcept { + constexpr void addPixel(const ox::Point &pt, uint16_t colorIdx) noexcept { m_pixels.emplace_back(colorIdx, pt); } @@ -189,7 +189,7 @@ class CutPasteCommand: public TileSheetCommand { ox::Vector m_changes; public: - constexpr CutPasteCommand(TileSheet *img, const TileSheet::SubSheetIdx &subSheetIdx, const geo::Point &dstStart, const geo::Point &dstEnd, const TileSheetClipboard &cb) noexcept { + constexpr CutPasteCommand(TileSheet *img, const TileSheet::SubSheetIdx &subSheetIdx, const ox::Point &dstStart, const ox::Point &dstEnd, const TileSheetClipboard &cb) noexcept { m_img = img; m_subSheetIdx = subSheetIdx; const auto &subsheet = m_img->getSubSheet(subSheetIdx); @@ -553,7 +553,7 @@ void TileSheetEditorModel::cut() { const auto s = activeSubSheet(); for (int y = m_selectionBounds.y; y <= m_selectionBounds.y2(); ++y) { for (int x = m_selectionBounds.x; x <= m_selectionBounds.x2(); ++x) { - auto pt = geo::Point(x, y); + auto pt = ox::Point(x, y); const auto idx = s->idx(pt); const auto c = s->getPixel(m_img.bpp, idx); pt.x -= m_selectionBounds.x; @@ -562,8 +562,8 @@ void TileSheetEditorModel::cut() { blankCb.addPixel(pt, 0); } } - const auto pt1 = m_selectionOrigin == geo::Point(-1, -1) ? geo::Point(0, 0) : m_selectionOrigin; - const auto pt2 = geo::Point(s->columns * TileWidth, s->rows * TileHeight); + 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); setClipboardObject(m_ctx, std::move(cb)); pushCommand(ox::make>(&m_img, m_activeSubsSheetIdx, pt1, pt2, blankCb)); } @@ -572,7 +572,7 @@ void TileSheetEditorModel::copy() { auto cb = ox::make_unique(); for (int y = m_selectionBounds.y; y <= m_selectionBounds.y2(); ++y) { for (int x = m_selectionBounds.x; x <= m_selectionBounds.x2(); ++x) { - auto pt = geo::Point(x, y); + auto pt = ox::Point(x, y); const auto s = activeSubSheet(); const auto idx = s->idx(pt); const auto c = s->getPixel(m_img.bpp, idx); @@ -592,8 +592,8 @@ void TileSheetEditorModel::paste() { return; } const auto s = activeSubSheet(); - const auto pt1 = m_selectionOrigin == geo::Point(-1, -1) ? geo::Point(0, 0) : m_selectionOrigin; - const auto pt2 = geo::Point(s->columns * TileWidth, s->rows * TileHeight); + 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); pushCommand(ox::make>(&m_img, m_activeSubsSheetIdx, pt1, pt2, *cb)); } @@ -621,7 +621,7 @@ ox::Error TileSheetEditorModel::setPalette(const ox::String &path) noexcept { return OxError(0); } -void TileSheetEditorModel::drawCommand(const geo::Point &pt, std::size_t palIdx) noexcept { +void TileSheetEditorModel::drawCommand(const ox::Point &pt, std::size_t palIdx) noexcept { const auto &activeSubSheet = m_img.getSubSheet(m_activeSubsSheetIdx); if (pt.x >= activeSubSheet.columns * TileWidth || pt.y >= activeSubSheet.rows * TileHeight) { return; @@ -664,7 +664,7 @@ void TileSheetEditorModel::setActiveSubsheet(const TileSheet::SubSheetIdx &idx) this->activeSubsheetChanged.emit(m_activeSubsSheetIdx); } -void TileSheetEditorModel::fill(const geo::Point &pt, int palIdx) noexcept { +void TileSheetEditorModel::fill(const ox::Point &pt, int palIdx) noexcept { const auto &s = m_img.getSubSheet(m_activeSubsSheetIdx); // build idx list ox::Array updateMap = {}; @@ -689,7 +689,7 @@ void TileSheetEditorModel::fill(const geo::Point &pt, int palIdx) noexcept { } } -void TileSheetEditorModel::select(const geo::Point &pt) noexcept { +void TileSheetEditorModel::select(const ox::Point &pt) noexcept { if (!m_selectionOngoing) { m_selectionOrigin = pt; m_selectionOngoing = true; @@ -755,16 +755,16 @@ bool TileSheetEditorModel::pixelSelected(std::size_t idx) const noexcept { return m_selectionBounds.contains(pt); } -void TileSheetEditorModel::getFillPixels(bool *pixels, const geo::Point &pt, int oldColor) const noexcept { +void TileSheetEditorModel::getFillPixels(bool *pixels, const ox::Point &pt, int oldColor) const noexcept { const auto &activeSubSheet = *this->activeSubSheet(); - const auto tileIdx = [activeSubSheet](const geo::Point &pt) noexcept { + const auto tileIdx = [activeSubSheet](const ox::Point &pt) noexcept { return ptToIdx(pt, activeSubSheet.columns) / PixelsPerTile; }; // get points - const auto leftPt = pt + geo::Point(-1, 0); - const auto rightPt = pt + geo::Point(1, 0); - const auto topPt = pt + geo::Point(0, -1); - const auto bottomPt = pt + geo::Point(0, 1); + const auto leftPt = pt + ox::Point(-1, 0); + const auto rightPt = pt + ox::Point(1, 0); + const auto topPt = pt + ox::Point(0, -1); + const auto bottomPt = pt + ox::Point(0, 1); // calculate indices const auto idx = ptToIdx(pt, activeSubSheet.columns); const auto leftIdx = ptToIdx(leftPt, activeSubSheet.columns); diff --git a/src/nostalgia/core/studio/tilesheeteditormodel.hpp b/src/nostalgia/core/studio/tilesheeteditormodel.hpp index 1472cc71..704e9df6 100644 --- a/src/nostalgia/core/studio/tilesheeteditormodel.hpp +++ b/src/nostalgia/core/studio/tilesheeteditormodel.hpp @@ -4,12 +4,12 @@ #pragma once +#include +#include #include #include #include -#include -#include #include namespace nostalgia::core { @@ -30,8 +30,8 @@ class TileSheetEditorModel: public ox::SignalHandler { Context *m_ctx = nullptr; ox::String m_path; bool m_selectionOngoing = false; - geo::Point m_selectionOrigin = {-1, -1}; - geo::Bounds m_selectionBounds = {{-1, -1}, {-1, -1}}; + ox::Point m_selectionOrigin = {-1, -1}; + ox::Bounds m_selectionBounds = {{-1, -1}, {-1, -1}}; public: TileSheetEditorModel(Context *ctx, ox::String path); @@ -58,7 +58,7 @@ class TileSheetEditorModel: public ox::SignalHandler { ox::Error setPalette(const ox::String &path) noexcept; - void drawCommand(const geo::Point &pt, std::size_t palIdx) noexcept; + void drawCommand(const ox::Point &pt, std::size_t palIdx) noexcept; void endDrawCommand() noexcept; @@ -91,9 +91,9 @@ class TileSheetEditorModel: public ox::SignalHandler { return m_activeSubsSheetIdx; } - void fill(const geo::Point &pt, int palIdx) noexcept; + void fill(const ox::Point &pt, int palIdx) noexcept; - void select(const geo::Point &pt) noexcept; + void select(const ox::Point &pt) noexcept; void completeSelection() noexcept; @@ -116,7 +116,7 @@ class TileSheetEditorModel: public ox::SignalHandler { bool pixelSelected(std::size_t idx) const noexcept; protected: - void getFillPixels(bool *pixels, const geo::Point &pt, int oldColor) const noexcept; + void getFillPixels(bool *pixels, const ox::Point &pt, int oldColor) const noexcept; private: void pushCommand(studio::UndoCommand *cmd) noexcept; diff --git a/src/nostalgia/core/studio/tilesheeteditorview.cpp b/src/nostalgia/core/studio/tilesheeteditorview.cpp index b0134ed0..02373c85 100644 --- a/src/nostalgia/core/studio/tilesheeteditorview.cpp +++ b/src/nostalgia/core/studio/tilesheeteditorview.cpp @@ -2,9 +2,10 @@ * Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved. */ -#include +#include #include -#include + +#include #include "tilesheeteditorview.hpp" @@ -25,7 +26,7 @@ void TileSheetEditorView::draw() noexcept { m_pixelGridDrawer.draw(updated(), m_scrollOffset); } -void TileSheetEditorView::scrollV(const geo::Vec2 &paneSz, float wheel, bool zoomMod) noexcept { +void TileSheetEditorView::scrollV(const ox::Vec2 &paneSz, float wheel, bool zoomMod) noexcept { const auto pixelSize = m_pixelsDrawer.pixelSize(paneSz); const ImVec2 sheetSize(pixelSize.x * static_cast(m_model.activeSubSheet()->columns) * TileWidth, pixelSize.y * static_cast(m_model.activeSubSheet()->rows) * TileHeight); @@ -42,7 +43,7 @@ void TileSheetEditorView::scrollV(const geo::Vec2 &paneSz, float wheel, bool zoo m_scrollOffset.y = ox::clamp(m_scrollOffset.y, 0.f, sheetSize.y / 2); } -void TileSheetEditorView::scrollH(const geo::Vec2 &paneSz, float wheelh) noexcept { +void TileSheetEditorView::scrollH(const ox::Vec2 &paneSz, float wheelh) noexcept { const auto pixelSize = m_pixelsDrawer.pixelSize(paneSz); const ImVec2 sheetSize(pixelSize.x * static_cast(m_model.activeSubSheet()->columns) * TileWidth, pixelSize.y * static_cast(m_model.activeSubSheet()->rows) * TileHeight); @@ -50,31 +51,31 @@ void TileSheetEditorView::scrollH(const geo::Vec2 &paneSz, float wheelh) noexcep m_scrollOffset.x = ox::clamp(m_scrollOffset.x, -(sheetSize.x / 2), 0.f); } -void TileSheetEditorView::insertTile(const geo::Vec2 &paneSize, const geo::Vec2 &clickPos) noexcept { +void TileSheetEditorView::insertTile(const ox::Vec2 &paneSize, const ox::Vec2 &clickPos) noexcept { const auto pt = clickPoint(paneSize, clickPos); const auto s = m_model.activeSubSheet(); const auto tileIdx = ptToIdx(pt, s->columns) / PixelsPerTile; m_model.insertTiles(m_model.activeSubSheetIdx(), tileIdx, 1); } -void TileSheetEditorView::deleteTile(const geo::Vec2 &paneSize, const geo::Vec2 &clickPos) noexcept { +void TileSheetEditorView::deleteTile(const ox::Vec2 &paneSize, const ox::Vec2 &clickPos) noexcept { const auto pt = clickPoint(paneSize, clickPos); const auto s = m_model.activeSubSheet(); const auto tileIdx = ptToIdx(pt, s->columns) / PixelsPerTile; m_model.deleteTiles(m_model.activeSubSheetIdx(), tileIdx, 1); } -void TileSheetEditorView::clickDraw(const geo::Vec2 &paneSize, const geo::Vec2 &clickPos) noexcept { +void TileSheetEditorView::clickDraw(const ox::Vec2 &paneSize, const ox::Vec2 &clickPos) noexcept { const auto pt = clickPoint(paneSize, clickPos); m_model.drawCommand(pt, m_palIdx); } -void TileSheetEditorView::clickSelect(const geo::Vec2 &paneSize, const geo::Vec2 &clickPos) noexcept { +void TileSheetEditorView::clickSelect(const ox::Vec2 &paneSize, const ox::Vec2 &clickPos) noexcept { const auto pt = clickPoint(paneSize, clickPos); m_model.select(pt); } -void TileSheetEditorView::clickFill(const geo::Vec2 &paneSize, const geo::Vec2 &clickPos) noexcept { +void TileSheetEditorView::clickFill(const ox::Vec2 &paneSize, const ox::Vec2 &clickPos) noexcept { const auto pt = clickPoint(paneSize, clickPos); m_model.fill(pt, static_cast(m_palIdx)); } @@ -84,7 +85,7 @@ void TileSheetEditorView::releaseMouseButton() noexcept { m_model.completeSelection(); } -void TileSheetEditorView::resizeView(const geo::Vec2 &sz) noexcept { +void TileSheetEditorView::resizeView(const ox::Vec2 &sz) noexcept { m_viewSize = sz; initView(); } @@ -109,7 +110,7 @@ void TileSheetEditorView::initView() noexcept { m_pixelGridDrawer.initBufferSet(m_viewSize, *m_model.activeSubSheet()); } -geo::Point TileSheetEditorView::clickPoint(const geo::Vec2 &paneSize, const geo::Vec2 &clickPos) const noexcept { +ox::Point TileSheetEditorView::clickPoint(const ox::Vec2 &paneSize, const ox::Vec2 &clickPos) const noexcept { auto [x, y] = clickPos; const auto pixDrawSz = m_pixelsDrawer.pixelSize(paneSize); x /= paneSize.x; diff --git a/src/nostalgia/core/studio/tilesheeteditorview.hpp b/src/nostalgia/core/studio/tilesheeteditorview.hpp index ecbd82cf..06d1c331 100644 --- a/src/nostalgia/core/studio/tilesheeteditorview.hpp +++ b/src/nostalgia/core/studio/tilesheeteditorview.hpp @@ -1,13 +1,13 @@ /* - * Copyright 2016 - 2022 Gary Talent (gary@drinkingtea.net). All rights reserved. + * Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved. */ #pragma once +#include #include #include -#include #include #include @@ -42,10 +42,10 @@ class TileSheetEditorView: public ox::SignalHandler { TileSheetEditorModel m_model; TileSheetGrid m_pixelGridDrawer; TileSheetPixels m_pixelsDrawer; - geo::Vec2 m_viewSize; + ox::Vec2 m_viewSize; float m_pixelSizeMod = 1; bool m_updated = false; - geo::Vec2 m_scrollOffset; + ox::Vec2 m_scrollOffset; std::size_t m_palIdx = 0; public: @@ -55,23 +55,23 @@ class TileSheetEditorView: public ox::SignalHandler { void draw() noexcept; - void insertTile(const geo::Vec2 &paneSize, const geo::Vec2 &clickPos) noexcept; + void insertTile(const ox::Vec2 &paneSize, const ox::Vec2 &clickPos) noexcept; - void deleteTile(const geo::Vec2 &paneSize, const geo::Vec2 &clickPos) noexcept; + void deleteTile(const ox::Vec2 &paneSize, const ox::Vec2 &clickPos) noexcept; - void clickDraw(const geo::Vec2 &paneSize, const geo::Vec2 &clickPos) noexcept; + void clickDraw(const ox::Vec2 &paneSize, const ox::Vec2 &clickPos) noexcept; - void clickSelect(const geo::Vec2 &paneSize, const geo::Vec2 &clickPos) noexcept; + void clickSelect(const ox::Vec2 &paneSize, const ox::Vec2 &clickPos) noexcept; - void clickFill(const geo::Vec2 &paneSize, const geo::Vec2 &clickPos) noexcept; + void clickFill(const ox::Vec2 &paneSize, const ox::Vec2 &clickPos) noexcept; void releaseMouseButton() noexcept; - void scrollV(const geo::Vec2 &paneSz, float wheel, bool zoomMod) noexcept; + void scrollV(const ox::Vec2 &paneSz, float wheel, bool zoomMod) noexcept; - void scrollH(const geo::Vec2 &paneSz, float wheel) noexcept; + void scrollH(const ox::Vec2 &paneSz, float wheel) noexcept; - void resizeView(const geo::Vec2 &sz) noexcept; + void resizeView(const ox::Vec2 &sz) noexcept; [[nodiscard]] constexpr const TileSheet &img() const noexcept; @@ -111,7 +111,7 @@ class TileSheetEditorView: public ox::SignalHandler { private: void initView() noexcept; - geo::Point clickPoint(const geo::Vec2 &paneSize, const geo::Vec2 &clickPos) const noexcept; + ox::Point clickPoint(const ox::Vec2 &paneSize, const ox::Vec2 &clickPos) const noexcept; ox::Error setActiveSubsheet(const TileSheet::SubSheetIdx &idx) noexcept; diff --git a/src/nostalgia/core/studio/tilesheetpixelgrid.cpp b/src/nostalgia/core/studio/tilesheetpixelgrid.cpp index a67a5fa1..7a40715b 100644 --- a/src/nostalgia/core/studio/tilesheetpixelgrid.cpp +++ b/src/nostalgia/core/studio/tilesheetpixelgrid.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2016 - 2022 Gary Talent (gary@drinkingtea.net). All rights reserved. + * Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved. */ #include @@ -18,7 +18,7 @@ ox::Error TileSheetGrid::buildShader() noexcept { return glutils::buildShaderProgram(pixelLineVshad, pixelLineFshad, pixelLineGshad).moveTo(&m_shader); } -void TileSheetGrid::draw(bool update, const geo::Vec2 &scroll) noexcept { +void TileSheetGrid::draw(bool update, const ox::Vec2 &scroll) noexcept { glLineWidth(3 * m_pixelSizeMod * 0.5f); glUseProgram(m_shader); glBindVertexArray(m_bufferSet.vao); @@ -32,7 +32,7 @@ void TileSheetGrid::draw(bool update, const geo::Vec2 &scroll) noexcept { glUseProgram(0); } -void TileSheetGrid::initBufferSet(const geo::Vec2 &paneSize, const TileSheet::SubSheet &subsheet) noexcept { +void TileSheetGrid::initBufferSet(const ox::Vec2 &paneSize, const TileSheet::SubSheet &subsheet) noexcept { // vao m_bufferSet.vao = glutils::generateVertexArrayObject(); glBindVertexArray(m_bufferSet.vao); @@ -54,7 +54,7 @@ void TileSheetGrid::initBufferSet(const geo::Vec2 &paneSize, const TileSheet::Su reinterpret_cast(4 * sizeof(float))); } -void TileSheetGrid::setBufferObject(geo::Point pt1, geo::Point pt2, Color32 c, float *vbo, const geo::Vec2 &pixSize) noexcept { +void TileSheetGrid::setBufferObject(ox::Point pt1, ox::Point pt2, Color32 c, float *vbo, const ox::Vec2 &pixSize) noexcept { const auto x1 = static_cast(pt1.x) * pixSize.x - 1.f; const auto y1 = 1.f - static_cast(pt1.y) * pixSize.y; const auto x2 = static_cast(pt2.x) * pixSize.x - 1.f; @@ -64,9 +64,9 @@ void TileSheetGrid::setBufferObject(geo::Point pt1, geo::Point pt2, Color32 c, f memcpy(vbo, vertices, sizeof(vertices)); } -void TileSheetGrid::setBufferObjects(const geo::Vec2 &paneSize, const TileSheet::SubSheet &subsheet) noexcept { +void TileSheetGrid::setBufferObjects(const ox::Vec2 &paneSize, const TileSheet::SubSheet &subsheet) noexcept { const auto pixSize = pixelSize(paneSize); - const auto set = [&](unsigned i, geo::Point pt1, geo::Point pt2, Color32 c) { + const auto set = [&](unsigned i, ox::Point pt1, ox::Point pt2, Color32 c) { const auto vbo = &m_bufferSet.vertices[i * VertexVboLength]; setBufferObject(pt1, pt2, c, vbo, pixSize); }; @@ -100,7 +100,7 @@ void TileSheetGrid::setBufferObjects(const geo::Vec2 &paneSize, const TileSheet: } } -geo::Vec2 TileSheetGrid::pixelSize(const geo::Vec2 &paneSize) const noexcept { +ox::Vec2 TileSheetGrid::pixelSize(const ox::Vec2 &paneSize) const noexcept { const auto [sw, sh] = paneSize; constexpr float ymod = 0.35f / 10.0f; const auto xmod = ymod * sh / sw; diff --git a/src/nostalgia/core/studio/tilesheetpixelgrid.hpp b/src/nostalgia/core/studio/tilesheetpixelgrid.hpp index 87c5a80c..4433e12c 100644 --- a/src/nostalgia/core/studio/tilesheetpixelgrid.hpp +++ b/src/nostalgia/core/studio/tilesheetpixelgrid.hpp @@ -1,12 +1,10 @@ /* - * Copyright 2016 - 2022 Gary Talent (gary@drinkingtea.net). All rights reserved. + * Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved. */ #pragma once #include -#include -#include #include #include @@ -67,17 +65,17 @@ class TileSheetGrid { ox::Error buildShader() noexcept; - void draw(bool update, const geo::Vec2 &scroll) noexcept; + void draw(bool update, const ox::Vec2 &scroll) noexcept; - void initBufferSet(const geo::Vec2 &paneSize, const TileSheet::SubSheet &subsheet) noexcept; + void initBufferSet(const ox::Vec2 &paneSize, const TileSheet::SubSheet &subsheet) noexcept; private: - static void setBufferObject(geo::Point pt1, geo::Point pt2, Color32 c, float *vbo, const geo::Vec2 &pixSize) noexcept; + static void setBufferObject(ox::Point pt1, ox::Point pt2, Color32 c, float *vbo, const ox::Vec2 &pixSize) noexcept; - void setBufferObjects(const geo::Vec2 &paneSize, const TileSheet::SubSheet &subsheet) noexcept; + void setBufferObjects(const ox::Vec2 &paneSize, const TileSheet::SubSheet &subsheet) noexcept; [[nodiscard]] - geo::Vec2 pixelSize(const geo::Vec2 &paneSize) const noexcept; + ox::Vec2 pixelSize(const ox::Vec2 &paneSize) const noexcept; }; diff --git a/src/nostalgia/core/studio/tilesheetpixels.cpp b/src/nostalgia/core/studio/tilesheetpixels.cpp index 3ad0e6cf..2e69c8dc 100644 --- a/src/nostalgia/core/studio/tilesheetpixels.cpp +++ b/src/nostalgia/core/studio/tilesheetpixels.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2016 - 2022 Gary Talent (gary@drinkingtea.net). All rights reserved. + * Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved. */ #include @@ -22,7 +22,7 @@ ox::Error TileSheetPixels::buildShader() noexcept { return glutils::buildShaderProgram(Vshad, Fshad).moveTo(&m_shader); } -void TileSheetPixels::draw(bool update, const geo::Vec2 &scroll) noexcept { +void TileSheetPixels::draw(bool update, const ox::Vec2 &scroll) noexcept { glUseProgram(m_shader); glBindVertexArray(m_bufferSet.vao); if (update) { @@ -35,7 +35,7 @@ void TileSheetPixels::draw(bool update, const geo::Vec2 &scroll) noexcept { glUseProgram(0); } -void TileSheetPixels::initBufferSet(geo::Vec2 const&paneSize) noexcept { +void TileSheetPixels::initBufferSet(ox::Vec2 const&paneSize) noexcept { m_bufferSet.vao = glutils::generateVertexArrayObject(); m_bufferSet.vbo = glutils::generateBuffer(); m_bufferSet.ebo = glutils::generateBuffer(); @@ -50,14 +50,14 @@ void TileSheetPixels::initBufferSet(geo::Vec2 const&paneSize) noexcept { reinterpret_cast(2 * sizeof(float))); } -void TileSheetPixels::update(geo::Vec2 const&paneSize) noexcept { +void TileSheetPixels::update(ox::Vec2 const&paneSize) noexcept { glBindVertexArray(m_bufferSet.vao); setBufferObjects(paneSize); glutils::sendVbo(m_bufferSet); glutils::sendEbo(m_bufferSet); } -geo::Vec2 TileSheetPixels::pixelSize(const geo::Vec2 &paneSize) const noexcept { +ox::Vec2 TileSheetPixels::pixelSize(const ox::Vec2 &paneSize) const noexcept { const auto [sw, sh] = paneSize; constexpr float ymod = 0.35f / 10.0f; const auto xmod = ymod * sh / sw; @@ -65,7 +65,7 @@ geo::Vec2 TileSheetPixels::pixelSize(const geo::Vec2 &paneSize) const noexcept { } void TileSheetPixels::setPixelBufferObject( - geo::Vec2 const&paneSize, + ox::Vec2 const&paneSize, unsigned vertexRow, float x, float y, Color16 color, @@ -92,7 +92,7 @@ void TileSheetPixels::setPixelBufferObject( memcpy(ebo, elms.data(), sizeof(elms)); } -void TileSheetPixels::setBufferObjects(const geo::Vec2 &paneSize) noexcept { +void TileSheetPixels::setBufferObjects(const ox::Vec2 &paneSize) noexcept { // set buffer lengths const auto subSheet = m_model->activeSubSheet(); const auto pal = m_model->pal(); diff --git a/src/nostalgia/core/studio/tilesheetpixels.hpp b/src/nostalgia/core/studio/tilesheetpixels.hpp index d09ceea5..dbc042c8 100644 --- a/src/nostalgia/core/studio/tilesheetpixels.hpp +++ b/src/nostalgia/core/studio/tilesheetpixels.hpp @@ -1,11 +1,12 @@ /* - * Copyright 2016 - 2022 Gary Talent (gary@drinkingtea.net). All rights reserved. + * Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved. */ #pragma once +#include + #include -#include #include #include @@ -49,19 +50,19 @@ class TileSheetPixels { ox::Error buildShader() noexcept; - void draw(bool update, const geo::Vec2 &scroll) noexcept; + void draw(bool update, const ox::Vec2 &scroll) noexcept; - void initBufferSet(geo::Vec2 const&paneSize) noexcept; + void initBufferSet(ox::Vec2 const&paneSize) noexcept; - void update(geo::Vec2 const&paneSize) noexcept; + void update(ox::Vec2 const&paneSize) noexcept; [[nodiscard]] - geo::Vec2 pixelSize(const geo::Vec2 &paneSize) const noexcept; + ox::Vec2 pixelSize(const ox::Vec2 &paneSize) const noexcept; private: - void setPixelBufferObject(const geo::Vec2 &paneS, unsigned vertexRow, float x, float y, Color16 color, float *vbo, GLuint *ebo) const noexcept; + void setPixelBufferObject(const ox::Vec2 &paneS, unsigned vertexRow, float x, float y, Color16 color, float *vbo, GLuint *ebo) const noexcept; - void setBufferObjects(const geo::Vec2 &paneS) noexcept; + void setBufferObjects(const ox::Vec2 &paneS) noexcept; }; diff --git a/src/nostalgia/core/tilesheet.hpp b/src/nostalgia/core/tilesheet.hpp index aa5270bd..ff1895f2 100644 --- a/src/nostalgia/core/tilesheet.hpp +++ b/src/nostalgia/core/tilesheet.hpp @@ -5,11 +5,11 @@ #pragma once #include +#include +#include #include #include -#include -#include #include "color.hpp" #include "context.hpp" @@ -122,7 +122,7 @@ struct TileSheet { } [[nodiscard]] - constexpr auto idx(const geo::Point &pt) const noexcept { + constexpr auto idx(const ox::Point &pt) const noexcept { return ptToIdx(pt, columns); } @@ -203,19 +203,19 @@ struct TileSheet { } [[nodiscard]] - constexpr auto getPixel4Bpp(const geo::Point &pt) const noexcept { + constexpr auto getPixel4Bpp(const ox::Point &pt) const noexcept { const auto idx = ptToIdx(pt, columns); return getPixel4Bpp(idx); } [[nodiscard]] - constexpr auto getPixel8Bpp(const geo::Point &pt) const noexcept { + constexpr auto getPixel8Bpp(const ox::Point &pt) const noexcept { const auto idx = ptToIdx(pt, columns); return getPixel8Bpp(idx); } [[nodiscard]] - constexpr auto getPixel(int8_t pBpp, const geo::Point &pt) const noexcept { + constexpr auto getPixel(int8_t pBpp, const ox::Point &pt) const noexcept { const auto idx = ptToIdx(pt, columns); return getPixel(pBpp, idx); } @@ -254,7 +254,7 @@ struct TileSheet { } } - constexpr void setPixel(int8_t pBpp, const geo::Point &pt, uint8_t palIdx) noexcept { + constexpr void setPixel(int8_t pBpp, const ox::Point &pt, uint8_t palIdx) noexcept { const auto idx = ptToIdx(pt, columns); setPixel(pBpp, idx, palIdx); } @@ -471,7 +471,7 @@ struct TileSheet { [[nodiscard]] constexpr auto getPixel4Bpp( - const geo::Point &pt, + const ox::Point &pt, const SubSheetIdx &subsheetIdx) const noexcept { oxAssert(bpp == 4, "TileSheet::getPixel4Bpp: wrong bpp"); auto &s = this->getSubSheet(subsheetIdx); @@ -481,7 +481,7 @@ struct TileSheet { [[nodiscard]] constexpr auto getPixel8Bpp( - const geo::Point &pt, + const ox::Point &pt, const SubSheetIdx &subsheetIdx) const noexcept { oxAssert(bpp == 8, "TileSheet::getPixel8Bpp: wrong bpp"); auto &s = this->getSubSheet(subsheetIdx); diff --git a/src/nostalgia/geo/CMakeLists.txt b/src/nostalgia/geo/CMakeLists.txt deleted file mode 100644 index 31e5f555..00000000 --- a/src/nostalgia/geo/CMakeLists.txt +++ /dev/null @@ -1,21 +0,0 @@ - -add_library( - NostalgiaGeo OBJECT - vec.cpp -) - -target_link_libraries( - NostalgiaGeo PUBLIC - OxStd -) - -install( - FILES - bounds.hpp - geo.hpp - point.hpp - size.hpp - vec.hpp - DESTINATION - include/nostalgia/geo -) diff --git a/src/nostalgia/geo/bounds.hpp b/src/nostalgia/geo/bounds.hpp deleted file mode 100644 index 8eccf82f..00000000 --- a/src/nostalgia/geo/bounds.hpp +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Copyright 2016 - 2022 Gary Talent (gary@drinkingtea.net). All rights reserved. - */ - -#pragma once - -#include -#include -#include - -#include "point.hpp" - -namespace nostalgia::geo { - -class Bounds { - - public: - static constexpr auto TypeName = "net.drinkingtea.nostalgia.geo.Bounds"; - static constexpr auto TypeVersion = 1; - int x = 0; - int y = 0; - int width = 0; - int height = 0; - - constexpr Bounds() noexcept = default; - - constexpr Bounds(int x, int y, int w, int h) noexcept; - - constexpr Bounds(const Point &pt1, const Point &pt2) noexcept; - - [[nodiscard]] - constexpr bool intersects(const Bounds &other) const noexcept; - - [[nodiscard]] - constexpr bool contains(int x, int y) const noexcept; - - [[nodiscard]] - constexpr bool contains(const Point &pt) const noexcept; - - [[nodiscard]] - constexpr int x2() const noexcept; - - [[nodiscard]] - constexpr int y2() const noexcept; - - [[nodiscard]] - constexpr Point pt1() const noexcept; - - [[nodiscard]] - constexpr Point pt2() const noexcept; - - constexpr void setPt2(const Point &pt) noexcept; - - private: - constexpr void set(const Point &pt1, const Point &pt2) noexcept; - -}; - -constexpr Bounds::Bounds(int x, int y, int w, int h) noexcept { - this->x = x; - this->y = y; - this->width = w; - this->height = h; -} - -constexpr Bounds::Bounds(const Point &pt1, const Point &pt2) noexcept { - set(pt1, pt2); -} - -constexpr bool Bounds::intersects(const Bounds &o) const noexcept { - return o.x2() >= x && x2() >= o.x && o.y2() >= y && y2() >= o.y; -} - -constexpr bool Bounds::contains(int x, int y) const noexcept { - return x >= this->x && y >= this->y && x <= x2() && y <= y2(); -} - -constexpr bool Bounds::contains(const Point &pt) const noexcept { - return contains(pt.x, pt.y); -} - -constexpr int Bounds::x2() const noexcept { - return x + width; -} - -constexpr int Bounds::y2() const noexcept { - return y + height; -} - -constexpr Point Bounds::pt1() const noexcept { - return {x, y}; -} - -constexpr Point Bounds::pt2() const noexcept { - return {x2(), y2()}; -} - -constexpr void Bounds::setPt2(const Point &pt) noexcept { - set(pt1(), pt); -} - -constexpr void Bounds::set(const Point &pt1, const Point &pt2) noexcept { - int x1 = 0, x2 = 0, y1 = 0, y2 = 0; - if (pt1.x <= pt2.x) { - x1 = pt1.x; - x2 = pt2.x; - } else { - x1 = pt2.x; - x2 = pt1.x; - } - if (pt1.y <= pt2.y) { - y1 = pt1.y; - y2 = pt2.y; - } else { - y1 = pt2.y; - y2 = pt1.y; - } - this->x = x1; - this->y = y1; - this->width = x2 - x1; - this->height = y2 - y1; -} - -oxModelBegin(Bounds) - oxModelField(x) - oxModelField(y) - oxModelField(width) - oxModelField(height) -oxModelEnd() - -} diff --git a/src/nostalgia/geo/geo.hpp b/src/nostalgia/geo/geo.hpp deleted file mode 100644 index e9fbc198..00000000 --- a/src/nostalgia/geo/geo.hpp +++ /dev/null @@ -1,9 +0,0 @@ -/* - * Copyright 2016 - 2022 Gary Talent (gary@drinkingtea.net). All rights reserved. - */ - -#pragma once - -#include "bounds.hpp" -#include "point.hpp" -#include "size.hpp" diff --git a/src/nostalgia/geo/point.hpp b/src/nostalgia/geo/point.hpp deleted file mode 100644 index 2ef2c25b..00000000 --- a/src/nostalgia/geo/point.hpp +++ /dev/null @@ -1,188 +0,0 @@ -/* - * Copyright 2016 - 2022 Gary Talent (gary@drinkingtea.net). All rights reserved. - */ - -#pragma once - -#include -#include - -namespace nostalgia::geo { - -class Point { - public: - static constexpr auto TypeName = "net.drinkingtea.nostalgia.geo.Point"; - static constexpr auto TypeVersion = 1; - int x = 0; - int y = 0; - - constexpr Point() noexcept = default; - - constexpr Point(int x, int y) noexcept; - - constexpr Point operator+(const geo::Point &p) const noexcept; - - constexpr Point operator-(const geo::Point &p) const noexcept; - - constexpr Point operator*(const geo::Point &p) const noexcept; - - constexpr Point operator/(const geo::Point &p) const noexcept; - - - constexpr Point operator+=(const geo::Point &p) noexcept; - - constexpr Point operator-=(const geo::Point &p) noexcept; - - constexpr Point operator*=(const geo::Point &p) noexcept; - - constexpr Point operator/=(const geo::Point &p) noexcept; - - - constexpr Point operator+(int i) const noexcept; - - constexpr Point operator-(int i) const noexcept; - - constexpr Point operator*(int i) const noexcept; - - constexpr Point operator/(int i) const noexcept; - - - constexpr Point operator+=(int i) noexcept; - - constexpr Point operator-=(int i) noexcept; - - constexpr Point operator*=(int i) noexcept; - - constexpr Point operator/=(int i) noexcept; - - - constexpr bool operator==(const Point&) const noexcept; - - constexpr bool operator!=(const Point&) const noexcept; - -}; - -constexpr Point::Point(int x, int y) noexcept { - this->x = x; - this->y = y; -} - -constexpr Point Point::operator+(const geo::Point &p) const noexcept { - auto out = *this; - out.x += p.x; - out.y += p.y; - return out; -} - -constexpr Point Point::operator-(const geo::Point &p) const noexcept { - auto out = *this; - out.x -= p.x; - out.y -= p.y; - return out; -} - -constexpr Point Point::operator*(const geo::Point &p) const noexcept { - auto out = *this; - out.x *= p.x; - out.y *= p.y; - return out; -} - -constexpr Point Point::operator/(const geo::Point &p) const noexcept { - auto out = *this; - out.x /= p.x; - out.y /= p.y; - return out; -} - -constexpr Point Point::operator+=(const geo::Point &p) noexcept { - x += p.x; - y += p.y; - return *this; -} - -constexpr Point Point::operator-=(const geo::Point &p) noexcept { - x -= p.x; - y -= p.y; - return *this; -} - -constexpr Point Point::operator*=(const geo::Point &p) noexcept { - x *= p.x; - y *= p.y; - return *this; -} - -constexpr Point Point::operator/=(const geo::Point &p) noexcept { - x /= p.x; - y /= p.y; - return *this; -} - - -constexpr Point Point::operator+(int i) const noexcept { - auto out = *this; - out.x += i; - out.y += i; - return out; -} - -constexpr Point Point::operator-(int i) const noexcept { - auto out = *this; - out.x -= i; - out.y -= i; - return out; -} - -constexpr Point Point::operator*(int i) const noexcept { - auto out = *this; - out.x *= i; - out.y *= i; - return out; -} - -constexpr Point Point::operator/(int i) const noexcept { - auto out = *this; - out.x /= i; - out.y /= i; - return out; -} - -constexpr Point Point::operator+=(int i) noexcept { - x += i; - y += i; - return *this; -} - -constexpr Point Point::operator-=(int i) noexcept { - x -= i; - y -= i; - return *this; -} - -constexpr Point Point::operator*=(int i) noexcept { - x *= i; - y *= i; - return *this; -} - -constexpr Point Point::operator/=(int i) noexcept { - x /= i; - y /= i; - return *this; -} - -constexpr bool Point::operator==(const Point &p) const noexcept { - return x == p.x && y == p.y; -} - -constexpr bool Point::operator!=(const Point &p) const noexcept { - return x != p.x || y != p.y; -} - -oxModelBegin(Point) - oxModelField(x) - oxModelField(y) -oxModelEnd() - -} diff --git a/src/nostalgia/geo/size.hpp b/src/nostalgia/geo/size.hpp deleted file mode 100644 index 9a58ca31..00000000 --- a/src/nostalgia/geo/size.hpp +++ /dev/null @@ -1,188 +0,0 @@ -/* - * Copyright 2016 - 2022 Gary Talent (gary@drinkingtea.net). All rights reserved. - */ - -#pragma once - -#include - -namespace nostalgia::geo { - -class Size { - public: - static constexpr auto TypeName = "net.drinkingtea.nostalgia.geo.Size"; - static constexpr auto TypeVersion = 1; - int width = 0; - int height = 0; - - constexpr Size() noexcept = default; - - constexpr Size(int width, int height) noexcept; - - constexpr Size operator+(geo::Size p) const noexcept; - - constexpr Size operator-(geo::Size p) const noexcept; - - constexpr Size operator*(geo::Size p) const noexcept; - - constexpr Size operator/(geo::Size p) const noexcept; - - - constexpr Size operator+=(geo::Size p) noexcept; - - constexpr Size operator-=(geo::Size p) noexcept; - - constexpr Size operator*=(geo::Size p) noexcept; - - constexpr Size operator/=(geo::Size p) noexcept; - - - constexpr Size operator+(int i) const noexcept; - - constexpr Size operator-(int i) const noexcept; - - constexpr Size operator*(int i) const noexcept; - - constexpr Size operator/(int i) const noexcept; - - - constexpr Size operator+=(int i) noexcept; - - constexpr Size operator-=(int i) noexcept; - - constexpr Size operator*=(int i) noexcept; - - constexpr Size operator/=(int i) noexcept; - - - constexpr bool operator==(const Size&) const noexcept; - - constexpr bool operator!=(const Size&) const noexcept; - -}; - -constexpr Size::Size(int width, int height) noexcept { - this->width = width; - this->height = height; -} - -constexpr Size Size::operator+(geo::Size p) const noexcept { - p.width += width; - p.height += height; - return p; -} - -constexpr Size Size::operator-(geo::Size p) const noexcept { - auto out = *this; - out.width -= p.width; - out.height -= p.height; - return out; -} - -constexpr Size Size::operator*(geo::Size p) const noexcept { - p.width *= width; - p.height *= height; - return p; -} - -constexpr Size Size::operator/(geo::Size p) const noexcept { - auto out = *this; - out.width /= p.width; - out.height /= p.height; - return out; -} - -constexpr Size Size::operator+=(geo::Size p) noexcept { - width += p.width; - height += p.height; - return *this; -} - -constexpr Size Size::operator-=(geo::Size p) noexcept { - width -= p.width; - height -= p.height; - return *this; -} - -constexpr Size Size::operator*=(geo::Size p) noexcept { - width *= p.width; - height *= p.height; - return *this; -} - -constexpr Size Size::operator/=(geo::Size p) noexcept { - width /= p.width; - height /= p.height; - return *this; -} - - -constexpr Size Size::operator+(int i) const noexcept { - auto out = *this; - out.width += i; - out.height += i; - return out; -} - -constexpr Size Size::operator-(int i) const noexcept { - auto out = *this; - out.width -= i; - out.height -= i; - return out; -} - -constexpr Size Size::operator*(int i) const noexcept { - auto out = *this; - out.width *= i; - out.height *= i; - return out; -} - -constexpr Size Size::operator/(int i) const noexcept { - auto out = *this; - out.width /= i; - out.height /= i; - return out; -} - - -constexpr Size Size::operator+=(int i) noexcept { - width += i; - height += i; - return *this; -} - -constexpr Size Size::operator-=(int i) noexcept { - width -= i; - height -= i; - return *this; -} - -constexpr Size Size::operator*=(int i) noexcept { - width *= i; - height *= i; - return *this; -} - -constexpr Size Size::operator/=(int i) noexcept { - width /= i; - height /= i; - return *this; -} - - -constexpr bool Size::operator==(const Size &p) const noexcept { - return width == p.width && height == p.height; -} - -constexpr bool Size::operator!=(const Size &p) const noexcept { - return width != p.width || height != p.height; -} - - -oxModelBegin(Size) - oxModelField(width) - oxModelField(height) -oxModelEnd() - -} diff --git a/src/nostalgia/geo/vec.cpp b/src/nostalgia/geo/vec.cpp deleted file mode 100644 index 3e56261c..00000000 --- a/src/nostalgia/geo/vec.cpp +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright 2016 - 2022 Gary Talent (gary@drinkingtea.net). All rights reserved. - */ - -#include - -#include "vec.hpp" - -namespace nostalgia::geo { - -static_assert([] { - Vec2 v(1, 2); - return v.x == 1 && v.y == 2 && v[0] == 1 && v[1] == 2 && v.size() == 2; -}()); - -} diff --git a/src/nostalgia/geo/vec.hpp b/src/nostalgia/geo/vec.hpp deleted file mode 100644 index 586297f8..00000000 --- a/src/nostalgia/geo/vec.hpp +++ /dev/null @@ -1,264 +0,0 @@ -/* - * Copyright 2016 - 2022 Gary Talent (gary@drinkingtea.net). All rights reserved. - */ - -#pragma once - -#if __has_include() -#include -#endif - -#include -#include -#include -#include -#include -#include -#include -#include - -namespace nostalgia::geo { - -template -struct Vec { - public: - using value_type = T; - using size_type = std::size_t; - - static constexpr auto TypeName = "net.drinkingtea.nostalgia.geo.Point"; - static constexpr auto TypeVersion = 1; - - T x = 0; - T y = 0; - - template - struct iterator: public ox::Iterator { - private: - PtrType m_t = nullptr; - size_type m_offset = 0; - size_type m_max = 0; - - public: - constexpr iterator() noexcept = default; - - constexpr iterator(PtrType t, size_type offset, size_type max) noexcept { - m_t = t; - m_offset = offset; - m_max = max; - } - - [[nodiscard]] - constexpr auto offset() const noexcept { - return m_offset; - } - - constexpr iterator operator+(size_type s) const noexcept { - if constexpr(reverse) { - return iterator(m_t, ox::max(m_offset - s, 0), m_max); - } else { - return iterator(m_t, ox::min(m_offset + s, m_max), m_max); - } - } - - constexpr typename ox::Iterator::difference_type - operator-(const iterator &other) const noexcept { - if constexpr(reverse) { - return m_offset + other.m_offset; - } else { - return m_offset - other.m_offset; - } - } - - constexpr iterator operator-(size_type s) const noexcept { - if constexpr(reverse) { - return iterator(m_t, ox::min(m_offset + s, m_max), m_max); - } else { - return iterator(m_t, ox::max(m_offset - s, 0), m_max); - } - } - - constexpr iterator &operator+=(size_type s) noexcept { - if constexpr(reverse) { - m_offset = ox::max(m_offset - s, 0); - } else { - m_offset = ox::min(m_offset + s, m_max); - } - return *this; - } - - constexpr iterator &operator-=(size_type s) noexcept { - if constexpr(reverse) { - m_offset = ox::min(m_offset + s, m_max); - } else { - m_offset = ox::max(m_offset - s, 0); - } - return *this; - } - - constexpr iterator &operator++() noexcept { - return operator+=(1); - } - - constexpr iterator &operator--() noexcept { - return operator-=(1); - } - - constexpr RefType operator*() const noexcept { - return m_t[m_offset]; - } - - constexpr RefType operator[](size_type s) const noexcept { - return m_t[s]; - } - - constexpr bool operator<(const iterator &other) const noexcept { - return m_offset < other.m_offset; - } - - constexpr bool operator>(const iterator &other) const noexcept { - return m_offset > other.m_offset; - } - - constexpr bool operator<=(const iterator &other) const noexcept { - return m_offset <= other.m_offset; - } - - constexpr bool operator>=(const iterator &other) const noexcept { - return m_offset >= other.m_offset; - } - - constexpr bool operator==(const iterator &other) const noexcept { - return m_t == other.m_t && m_offset == other.m_offset && m_max == other.m_max; - } - - constexpr bool operator!=(const iterator &other) const noexcept { - return m_t != other.m_t || m_offset != other.m_offset || m_max != other.m_max; - } - - }; - - constexpr Vec() noexcept = default; - - template - constexpr Vec(T pX, T pY) noexcept: x(pX), y(pY) { - } - -#if __has_include() - explicit constexpr Vec(const ImVec2 &v) noexcept: Vec(v.x, v.y) { - } - - explicit inline operator ImVec2() const noexcept { - return {x, y}; - } -#endif - - [[nodiscard]] - constexpr iterator<> begin() noexcept { - return {start(), 0, size()}; - } - - [[nodiscard]] - constexpr iterator<> end() noexcept { - return {start(), size(), size()}; - } - - [[nodiscard]] - constexpr iterator begin() const noexcept { - return {start(), 0, size()}; - } - - [[nodiscard]] - constexpr iterator end() const noexcept { - return {start(), size(), size()}; - } - - [[nodiscard]] - constexpr iterator rbegin() noexcept { - return {start(), size() - 1, size()}; - } - - [[nodiscard]] - constexpr iterator rend() noexcept { - return {start(), ox::MaxValue, size()}; - } - - [[nodiscard]] - constexpr iterator rbegin() const noexcept { - return {start(), size() - 1, size()}; - } - - [[nodiscard]] - constexpr iterator rend() const noexcept { - return {start(), ox::MaxValue, size()}; - } - - constexpr auto &operator[](std::size_t i) noexcept { - if (std::is_constant_evaluated()) { - switch (i) { - case 0: - return x; - case 1: - return y; - default: - oxAssert(false, "Read past end of Vec2"); - return y; - } - } else { - return start()[i]; - } - } - - constexpr const auto &operator[](std::size_t i) const noexcept { - if (std::is_constant_evaluated()) { - switch (i) { - case 0: - return x; - case 1: - return y; - default: - oxAssert(false, "Read past end of Vec2"); - return y; - } - } else { - return start()[i]; - } - } - - constexpr auto operator==(const Vec &v) const noexcept { - for (auto i = 0u; i < v.size(); ++i) { - if ((*this)[i] != v[i]) { - return false; - } - } - return true; - } - - constexpr auto operator!=(const Vec &v) const noexcept { - return !operator==(v); - } - - [[nodiscard]] - constexpr std::size_t size() const noexcept { - return 2; - } - - protected: - [[nodiscard]] - constexpr T *start() noexcept { - return &x; - } - - [[nodiscard]] - constexpr const T *start() const noexcept { - return &x; - } -}; - -using Vec2 = Vec; - -oxModelBegin(Vec2) - oxModelField(x) - oxModelField(y) -oxModelEnd() - -} diff --git a/src/nostalgia/scene/CMakeLists.txt b/src/nostalgia/scene/CMakeLists.txt index 60804820..565cf22f 100644 --- a/src/nostalgia/scene/CMakeLists.txt +++ b/src/nostalgia/scene/CMakeLists.txt @@ -10,7 +10,6 @@ add_library( target_link_libraries( NostalgiaScene PUBLIC NostalgiaCore - NostalgiaGeo ) install( diff --git a/src/nostalgia/scene/scenestatic.hpp b/src/nostalgia/scene/scenestatic.hpp index a66fccfd..06aa04d3 100644 --- a/src/nostalgia/scene/scenestatic.hpp +++ b/src/nostalgia/scene/scenestatic.hpp @@ -6,11 +6,11 @@ #include #include +#include #include #include #include -#include namespace nostalgia::scene { @@ -78,7 +78,7 @@ struct SceneDoc { TileMap tiles; [[nodiscard]] - constexpr geo::Size size(std::size_t layerIdx) const noexcept { + constexpr ox::Size size(std::size_t layerIdx) const noexcept { const auto &layer = this->tiles[layerIdx]; const auto rowCnt = static_cast(layer.size()); if (!rowCnt) { @@ -170,7 +170,7 @@ struct SceneStatic { constexpr Tile tile(std::size_t i) noexcept { return {tileMapIdx[i], tileType[i], layerAttachments[i]}; } - constexpr auto setDimensions(geo::Size dim) noexcept { + constexpr auto setDimensions(ox::Size dim) noexcept { columns = dim.width; rows = dim.height; const auto tileCnt = static_cast(columns * rows); diff --git a/src/nostalgia/scene/studio/sceneeditor-imgui.cpp b/src/nostalgia/scene/studio/sceneeditor-imgui.cpp index 752d74f2..e61395a7 100644 --- a/src/nostalgia/scene/studio/sceneeditor-imgui.cpp +++ b/src/nostalgia/scene/studio/sceneeditor-imgui.cpp @@ -32,7 +32,7 @@ ox::CRString SceneEditorImGui::itemDisplayName() const noexcept { void SceneEditorImGui::draw(core::Context*) noexcept { const auto paneSize = ImGui::GetContentRegionAvail(); - const geo::Size fbSize{ + const ox::Size fbSize{ static_cast(paneSize.x), static_cast(paneSize.y)}; m_view.draw(fbSize.width, fbSize.height); diff --git a/src/nostalgia/studio/lib/popup.hpp b/src/nostalgia/studio/lib/popup.hpp index 0648531a..7aeebe15 100644 --- a/src/nostalgia/studio/lib/popup.hpp +++ b/src/nostalgia/studio/lib/popup.hpp @@ -1,13 +1,13 @@ /* - * Copyright 2016 - 2022 Gary Talent (gary@drinkingtea.net). All rights reserved. + * Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved. */ #pragma once #include #include +#include -#include #include #include "imguiuitl.hpp" @@ -17,7 +17,7 @@ namespace nostalgia::studio { class Popup { private: - geo::Vec2 m_size; + ox::Vec2 m_size; ox::String m_title; public: // emits path parameter @@ -35,7 +35,7 @@ class Popup { virtual void draw(core::Context *ctx) noexcept = 0; protected: - constexpr void setSize(geo::Size sz) noexcept { + constexpr void setSize(ox::Size sz) noexcept { m_size = {static_cast(sz.width), static_cast(sz.height)}; } @@ -59,4 +59,4 @@ class Popup { }; -} \ No newline at end of file +} diff --git a/src/nostalgia/studio/projectexplorer.cpp b/src/nostalgia/studio/projectexplorer.cpp index c3fd7008..e24556bf 100644 --- a/src/nostalgia/studio/projectexplorer.cpp +++ b/src/nostalgia/studio/projectexplorer.cpp @@ -1,13 +1,11 @@ /* - * Copyright 2016 - 2022 Gary Talent (gary@drinkingtea.net). All rights reserved. + * Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved. */ #include #include -#include - #include "projectexplorer.hpp" namespace nostalgia {