[nostalgia] Move geo types to Ox

This commit is contained in:
Gary Talent 2023-05-30 20:33:06 -05:00
parent 4e0ce57594
commit 03a1a8abca
34 changed files with 147 additions and 973 deletions

View File

@ -3,7 +3,6 @@
add_subdirectory(appmodules) add_subdirectory(appmodules)
add_subdirectory(core) add_subdirectory(core)
add_subdirectory(geo)
add_subdirectory(scene) add_subdirectory(scene)
if(NOSTALGIA_BUILD_PLAYER) if(NOSTALGIA_BUILD_PLAYER)

View File

@ -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 #pragma once
#include <ox/std/types.hpp> #include <ox/std/types.hpp>
#include <nostalgia/geo/point.hpp> #include <ox/std/point.hpp>
#include "context.hpp" #include "context.hpp"

View File

@ -7,9 +7,9 @@
#include <ox/fs/fs.hpp> #include <ox/fs/fs.hpp>
#include <ox/model/desctypes.hpp> #include <ox/model/desctypes.hpp>
#include <ox/std/buffer.hpp> #include <ox/std/buffer.hpp>
#include <ox/std/size.hpp>
#include <keel/context.hpp> #include <keel/context.hpp>
#include <nostalgia/geo/size.hpp>
#include "event.hpp" #include "event.hpp"
#include "input.hpp" #include "input.hpp"
@ -18,7 +18,7 @@ namespace nostalgia::core::gl {
void setMainViewEnabled(core::Context *ctx, bool enabled) noexcept; void setMainViewEnabled(core::Context *ctx, bool enabled) noexcept;
void drawMainView(core::Context*) noexcept; void drawMainView(core::Context*) noexcept;
void setRenderSize(core::Context*, int width, int height) 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; void clearRenderSize(core::Context *ctx) noexcept;
} }
@ -26,7 +26,7 @@ namespace nostalgia::core::renderer {
ox::Error init(Context *ctx) noexcept; ox::Error init(Context *ctx) noexcept;
} }
namespace nostalgia::geo { namespace ox {
class Size; class Size;
} }
@ -67,7 +67,7 @@ class Context: public keel::Context {
friend constexpr void setConstantRefresh(Context *ctx, bool) noexcept; friend constexpr void setConstantRefresh(Context *ctx, bool) noexcept;
friend bool bgStatus(Context *ctx, unsigned bg) noexcept; friend bool bgStatus(Context *ctx, unsigned bg) noexcept;
friend bool buttonDown(Context *ctx, Key) 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 getScreenHeight(Context *ctx) noexcept;
friend int getScreenWidth(Context *ctx) noexcept; friend int getScreenWidth(Context *ctx) noexcept;
friend ox::Error initGfx(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::setMainViewEnabled(core::Context *ctx, bool enabled) noexcept;
friend void gl::drawMainView(core::Context*) noexcept; friend void gl::drawMainView(core::Context*) noexcept;
friend void gl::setRenderSize(core::Context*, int width, int height) 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; friend void gl::clearRenderSize(core::Context *ctx) noexcept;
public: public:

View File

@ -7,9 +7,9 @@
#include <ox/fs/fs.hpp> #include <ox/fs/fs.hpp>
#include <ox/model/desctypes.hpp> #include <ox/model/desctypes.hpp>
#include <ox/std/buffer.hpp> #include <ox/std/buffer.hpp>
#include <ox/std/size.hpp>
#include <keel/context.hpp> #include <keel/context.hpp>
#include <nostalgia/geo/size.hpp>
#include <nostalgia/core/context.hpp> #include <nostalgia/core/context.hpp>

View File

@ -100,7 +100,7 @@ int getScreenHeight(Context*) noexcept {
return 160; return 160;
} }
geo::Size getScreenSize(Context*) noexcept { ox::Size getScreenSize(Context*) noexcept {
return {240, 160}; return {240, 160};
} }

View File

@ -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 #pragma once
#include <ox/std/array.hpp> #include <ox/std/array.hpp>
#include <ox/std/point.hpp>
#include <ox/std/size.hpp>
#include <ox/std/types.hpp> #include <ox/std/types.hpp>
#include <ox/model/def.hpp> #include <ox/model/def.hpp>
#include <nostalgia/geo/point.hpp>
#include <nostalgia/geo/size.hpp>
#include "color.hpp" #include "color.hpp"
#include "context.hpp" #include "context.hpp"
#include "ptidxconv.hpp" #include "ptidxconv.hpp"
@ -69,7 +68,7 @@ int getScreenWidth(Context *ctx) noexcept;
int getScreenHeight(Context *ctx) noexcept; int getScreenHeight(Context *ctx) noexcept;
[[nodiscard]] [[nodiscard]]
geo::Size getScreenSize(Context *ctx) noexcept; ox::Size getScreenSize(Context *ctx) noexcept;
[[nodiscard]] [[nodiscard]]
uint8_t bgStatus(Context *ctx) noexcept; uint8_t bgStatus(Context *ctx) noexcept;

View File

@ -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 <glad/glad.h> #include <glad/glad.h>
@ -246,7 +246,7 @@ int getScreenHeight(Context *ctx) noexcept {
return h; return h;
} }
geo::Size getScreenSize(Context *ctx) noexcept { ox::Size getScreenSize(Context *ctx) noexcept {
auto id = ctx->windowerData<GlfwImplData>(); auto id = ctx->windowerData<GlfwImplData>();
int w = 0, h = 0; int w = 0, h = 0;
glfwGetFramebufferSize(id->window, &w, &h); glfwGetFramebufferSize(id->window, &w, &h);

View File

@ -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 <imgui_impl_opengl3.h> #include <imgui_impl_opengl3.h>
#include <ox/std/array.hpp> #include <ox/std/array.hpp>
#include <ox/std/fmt.hpp> #include <ox/std/fmt.hpp>
#include <ox/std/vec.hpp>
#include <nostalgia/geo/vec.hpp>
#include <nostalgia/glutils/glutils.hpp> #include <nostalgia/glutils/glutils.hpp>
#include <nostalgia/core/context.hpp> #include <nostalgia/core/context.hpp>
@ -18,10 +18,6 @@ namespace nostalgia::core {
void ImGui_Impl_NewFrame() noexcept; void ImGui_Impl_NewFrame() noexcept;
namespace gl {
}
namespace renderer { namespace renderer {
constexpr uint64_t TileRows = 128; constexpr uint64_t TileRows = 128;
@ -72,7 +68,7 @@ struct GlImplData {
SpriteBlockset spriteBlocks; SpriteBlockset spriteBlocks;
ox::Array<Sprite, 128> spriteStates; ox::Array<Sprite, 128> spriteStates;
ox::Array<Background, 4> backgrounds; ox::Array<Background, 4> backgrounds;
ox::Optional<geo::Size> renderSize; ox::Optional<ox::Size> renderSize;
}; };
constexpr ox::StringView bgvshadTmpl = R"( constexpr ox::StringView bgvshadTmpl = R"(
@ -482,7 +478,7 @@ void setSprite(Context *ctx,
//oxTracef("nostalgia::core::gfx::gl", "setSprite(ctx, {}, {}, {}, {}, {}, {}, {})", //oxTracef("nostalgia::core::gfx::gl", "setSprite(ctx, {}, {}, {}, {}, {}, {}, {})",
// idx, x, y, tileIdx, spriteShape, spriteSize, flipX); // idx, x, y, tileIdx, spriteShape, spriteSize, flipX);
// Tonc Table 8.4 // Tonc Table 8.4
static constexpr ox::Array<geo::Vec<unsigned>, 12> dimensions{ static constexpr ox::Array<ox::Vec<unsigned>, 12> dimensions{
// col 0 // col 0
{1, 1}, // 0, 0 {1, 1}, // 0, 0
{2, 2}, // 0, 1 {2, 2}, // 0, 1
@ -575,7 +571,7 @@ void clearRenderSize(core::Context *ctx) noexcept {
id->renderSize.reset(); id->renderSize.reset();
} }
geo::Size getRenderSize(core::Context *ctx) noexcept { ox::Size getRenderSize(core::Context *ctx) noexcept {
const auto id = ctx->rendererData<renderer::GlImplData>(); const auto id = ctx->rendererData<renderer::GlImplData>();
if (id->renderSize.has_value()) { if (id->renderSize.has_value()) {
return id->renderSize.value(); return id->renderSize.value();

View File

@ -5,11 +5,11 @@
#pragma once #pragma once
#include <ox/std/array.hpp> #include <ox/std/array.hpp>
#include <ox/std/point.hpp>
#include <ox/std/size.hpp>
#include <ox/std/types.hpp> #include <ox/std/types.hpp>
#include <ox/model/def.hpp> #include <ox/model/def.hpp>
#include <nostalgia/geo/point.hpp>
#include <nostalgia/geo/size.hpp>
#include "color.hpp" #include "color.hpp"
#include "context.hpp" #include "context.hpp"

View File

@ -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 #pragma once
#include <nostalgia/geo/point.hpp> #include <ox/std/point.hpp>
#include "consts.hpp" #include "consts.hpp"
@ -22,12 +22,12 @@ constexpr std::size_t ptToIdx(int x, int y, int c) noexcept {
} }
[[nodiscard]] [[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); return ptToIdx(pt.x, pt.y, c * TileWidth);
} }
[[nodiscard]] [[nodiscard]]
constexpr geo::Point idxToPt(int i, int c) noexcept { constexpr ox::Point idxToPt(int i, int c) noexcept {
// prevent divide by zeros // prevent divide by zeros
if (!c) { if (!c) {
++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(4, 1) == ox::Point{4, 0});
static_assert(idxToPt(8, 1) == geo::Point{0, 1}); static_assert(idxToPt(8, 1) == ox::Point{0, 1});
static_assert(idxToPt(8, 2) == geo::Point{0, 1}); static_assert(idxToPt(8, 2) == ox::Point{0, 1});
static_assert(idxToPt(64, 2) == geo::Point{8, 0}); static_assert(idxToPt(64, 2) == ox::Point{8, 0});
static_assert(idxToPt(128, 2) == geo::Point{0, 8}); static_assert(idxToPt(128, 2) == ox::Point{0, 8});
static_assert(idxToPt(129, 2) == geo::Point{1, 8}); static_assert(idxToPt(129, 2) == ox::Point{1, 8});
static_assert(idxToPt(192, 2) == geo::Point{8, 8}); static_assert(idxToPt(192, 2) == ox::Point{8, 8});
static_assert(idxToPt(384, 8) == geo::Point{48, 0}); static_assert(idxToPt(384, 8) == ox::Point{48, 0});
} }

View File

@ -5,8 +5,8 @@
#include <imgui.h> #include <imgui.h>
#include <lodepng.h> #include <lodepng.h>
#include <ox/std/point.hpp>
#include <keel/media.hpp> #include <keel/media.hpp>
#include <nostalgia/geo/point.hpp>
#include "tilesheeteditor-imgui.hpp" #include "tilesheeteditor-imgui.hpp"
@ -114,7 +114,7 @@ void TileSheetEditorImGui::keyStateChanged(core::Key key, bool down) {
void TileSheetEditorImGui::draw(core::Context*) noexcept { void TileSheetEditorImGui::draw(core::Context*) noexcept {
const auto paneSize = ImGui::GetContentRegionAvail(); const auto paneSize = ImGui::GetContentRegionAvail();
const auto tileSheetParentSize = ImVec2(paneSize.x - m_palViewWidth, paneSize.y); 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); ImGui::BeginChild("TileSheetView", tileSheetParentSize, true);
{ {
drawTileSheet(fbSize); drawTileSheet(fbSize);
@ -240,7 +240,7 @@ studio::UndoStack *TileSheetEditorImGui::undoStack() noexcept {
} }
[[nodiscard]] [[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.x -= winPos.x + 10;
clickPos.y -= winPos.y + 10; clickPos.y -= winPos.y + 10;
return clickPos; 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 winPos = ImGui::GetWindowPos();
const auto fbSizei = geo::Size(static_cast<int>(fbSize.x), static_cast<int>(fbSize.y)); const auto fbSizei = ox::Size(static_cast<int>(fbSize.x), static_cast<int>(fbSize.y));
if (m_framebuffer.width != fbSizei.width || m_framebuffer.height != fbSizei.height) { if (m_framebuffer.width != fbSizei.width || m_framebuffer.height != fbSizei.height) {
glutils::resizeInitFrameBuffer(&m_framebuffer, fbSizei.width, fbSizei.height); glutils::resizeInitFrameBuffer(&m_framebuffer, fbSizei.width, fbSizei.height);
m_tileSheetEditor.resizeView(fbSize); m_tileSheetEditor.resizeView(fbSize);
@ -296,7 +296,7 @@ void TileSheetEditorImGui::drawTileSheet(const geo::Vec2 &fbSize) noexcept {
ImVec2(1, 0)); ImVec2(1, 0));
// handle input, this must come after drawing // handle input, this must come after drawing
const auto &io = ImGui::GetIO(); const auto &io = ImGui::GetIO();
const auto mousePos = geo::Vec2(io.MousePos); const auto mousePos = ox::Vec2(io.MousePos);
if (ImGui::IsItemHovered()) { if (ImGui::IsItemHovered()) {
const auto wheel = io.MouseWheel; const auto wheel = io.MouseWheel;
const auto wheelh = io.MouseWheelH; const auto wheelh = io.MouseWheelH;
@ -326,7 +326,7 @@ void TileSheetEditorImGui::drawTileSheet(const geo::Vec2 &fbSize) noexcept {
} }
} }
if (ImGui::BeginPopupContextItem("TileMenu", ImGuiPopupFlags_MouseButtonRight)) { 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")) { if (ImGui::MenuItem("Insert Tile")) {
m_tileSheetEditor.insertTile(fbSize, clickPos(winPos, popupPos)); m_tileSheetEditor.insertTile(fbSize, clickPos(winPos, popupPos));
} }

View File

@ -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 #pragma once
#include <ox/model/def.hpp> #include <ox/model/def.hpp>
#include <ox/std/vec.hpp>
#include <nostalgia/geo/vec.hpp>
#include <nostalgia/glutils/glutils.hpp> #include <nostalgia/glutils/glutils.hpp>
#include <nostalgia/studio/studio.hpp> #include <nostalgia/studio/studio.hpp>
@ -51,7 +51,7 @@ class TileSheetEditorImGui: public studio::BaseEditor {
glutils::FrameBuffer m_framebuffer; glutils::FrameBuffer m_framebuffer;
TileSheetEditorView m_tileSheetEditor; TileSheetEditorView m_tileSheetEditor;
float m_palViewWidth = 300; float m_palViewWidth = 300;
geo::Vec2 m_prevMouseDownPos; ox::Vec2 m_prevMouseDownPos;
Tool m_tool = Tool::Draw; Tool m_tool = Tool::Draw;
public: public:
@ -80,7 +80,7 @@ class TileSheetEditorImGui: public studio::BaseEditor {
studio::UndoStack *undoStack() noexcept final; studio::UndoStack *undoStack() noexcept final;
[[nodiscard]] [[nodiscard]]
static geo::Vec2 clickPos(const ImVec2 &winPos, geo::Vec2 clickPos) noexcept; static ox::Vec2 clickPos(const ImVec2 &winPos, ox::Vec2 clickPos) noexcept;
protected: protected:
ox::Error saveItem() noexcept override; ox::Error saveItem() noexcept override;
@ -112,7 +112,7 @@ class TileSheetEditorImGui: public studio::BaseEditor {
[[nodiscard]] [[nodiscard]]
ox::String palettePath(const ox::String &palettePath) const; 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; void drawPaletteSelector() noexcept;

View File

@ -30,8 +30,8 @@ class TileSheetClipboard: public ClipboardObject<TileSheetClipboard> {
static constexpr auto TypeName = "net.drinkingtea.nostalgia.core.studio.TileSheetClipboard.Pixel"; static constexpr auto TypeName = "net.drinkingtea.nostalgia.core.studio.TileSheetClipboard.Pixel";
static constexpr auto TypeVersion = 1; static constexpr auto TypeVersion = 1;
uint16_t colorIdx = 0; uint16_t colorIdx = 0;
geo::Point pt; ox::Point pt;
constexpr Pixel(uint16_t pColorIdx, geo::Point pPt) noexcept { constexpr Pixel(uint16_t pColorIdx, ox::Point pPt) noexcept {
colorIdx = pColorIdx; colorIdx = pColorIdx;
pt = pPt; pt = pPt;
} }
@ -40,7 +40,7 @@ class TileSheetClipboard: public ClipboardObject<TileSheetClipboard> {
ox::Vector<Pixel> m_pixels; ox::Vector<Pixel> m_pixels;
public: 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); m_pixels.emplace_back(colorIdx, pt);
} }
@ -189,7 +189,7 @@ class CutPasteCommand: public TileSheetCommand {
ox::Vector<Change> m_changes; ox::Vector<Change> m_changes;
public: 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_img = img;
m_subSheetIdx = subSheetIdx; m_subSheetIdx = subSheetIdx;
const auto &subsheet = m_img->getSubSheet(subSheetIdx); const auto &subsheet = m_img->getSubSheet(subSheetIdx);
@ -553,7 +553,7 @@ void TileSheetEditorModel::cut() {
const auto s = activeSubSheet(); const auto s = activeSubSheet();
for (int y = m_selectionBounds.y; y <= m_selectionBounds.y2(); ++y) { for (int y = m_selectionBounds.y; y <= m_selectionBounds.y2(); ++y) {
for (int x = m_selectionBounds.x; x <= m_selectionBounds.x2(); ++x) { 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 idx = s->idx(pt);
const auto c = s->getPixel(m_img.bpp, idx); const auto c = s->getPixel(m_img.bpp, idx);
pt.x -= m_selectionBounds.x; pt.x -= m_selectionBounds.x;
@ -562,8 +562,8 @@ void TileSheetEditorModel::cut() {
blankCb.addPixel(pt, 0); blankCb.addPixel(pt, 0);
} }
} }
const auto pt1 = m_selectionOrigin == geo::Point(-1, -1) ? geo::Point(0, 0) : m_selectionOrigin; const auto pt1 = m_selectionOrigin == ox::Point(-1, -1) ? ox::Point(0, 0) : m_selectionOrigin;
const auto pt2 = geo::Point(s->columns * TileWidth, s->rows * TileHeight); const auto pt2 = ox::Point(s->columns * TileWidth, s->rows * TileHeight);
setClipboardObject(m_ctx, std::move(cb)); setClipboardObject(m_ctx, std::move(cb));
pushCommand(ox::make<CutPasteCommand<CommandId::Cut>>(&m_img, m_activeSubsSheetIdx, pt1, pt2, blankCb)); pushCommand(ox::make<CutPasteCommand<CommandId::Cut>>(&m_img, m_activeSubsSheetIdx, pt1, pt2, blankCb));
} }
@ -572,7 +572,7 @@ void TileSheetEditorModel::copy() {
auto cb = ox::make_unique<TileSheetClipboard>(); auto cb = ox::make_unique<TileSheetClipboard>();
for (int y = m_selectionBounds.y; y <= m_selectionBounds.y2(); ++y) { for (int y = m_selectionBounds.y; y <= m_selectionBounds.y2(); ++y) {
for (int x = m_selectionBounds.x; x <= m_selectionBounds.x2(); ++x) { 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 s = activeSubSheet();
const auto idx = s->idx(pt); const auto idx = s->idx(pt);
const auto c = s->getPixel(m_img.bpp, idx); const auto c = s->getPixel(m_img.bpp, idx);
@ -592,8 +592,8 @@ void TileSheetEditorModel::paste() {
return; return;
} }
const auto s = activeSubSheet(); const auto s = activeSubSheet();
const auto pt1 = m_selectionOrigin == geo::Point(-1, -1) ? geo::Point(0, 0) : m_selectionOrigin; const auto pt1 = m_selectionOrigin == ox::Point(-1, -1) ? ox::Point(0, 0) : m_selectionOrigin;
const auto pt2 = geo::Point(s->columns * TileWidth, s->rows * TileHeight); const auto pt2 = ox::Point(s->columns * TileWidth, s->rows * TileHeight);
pushCommand(ox::make<CutPasteCommand<CommandId::Paste>>(&m_img, m_activeSubsSheetIdx, pt1, pt2, *cb)); pushCommand(ox::make<CutPasteCommand<CommandId::Paste>>(&m_img, m_activeSubsSheetIdx, pt1, pt2, *cb));
} }
@ -621,7 +621,7 @@ ox::Error TileSheetEditorModel::setPalette(const ox::String &path) noexcept {
return OxError(0); 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); const auto &activeSubSheet = m_img.getSubSheet(m_activeSubsSheetIdx);
if (pt.x >= activeSubSheet.columns * TileWidth || pt.y >= activeSubSheet.rows * TileHeight) { if (pt.x >= activeSubSheet.columns * TileWidth || pt.y >= activeSubSheet.rows * TileHeight) {
return; return;
@ -664,7 +664,7 @@ void TileSheetEditorModel::setActiveSubsheet(const TileSheet::SubSheetIdx &idx)
this->activeSubsheetChanged.emit(m_activeSubsSheetIdx); 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); const auto &s = m_img.getSubSheet(m_activeSubsSheetIdx);
// build idx list // build idx list
ox::Array<bool, PixelsPerTile> updateMap = {}; ox::Array<bool, PixelsPerTile> 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) { if (!m_selectionOngoing) {
m_selectionOrigin = pt; m_selectionOrigin = pt;
m_selectionOngoing = true; m_selectionOngoing = true;
@ -755,16 +755,16 @@ bool TileSheetEditorModel::pixelSelected(std::size_t idx) const noexcept {
return m_selectionBounds.contains(pt); 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 &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; return ptToIdx(pt, activeSubSheet.columns) / PixelsPerTile;
}; };
// get points // get points
const auto leftPt = pt + geo::Point(-1, 0); const auto leftPt = pt + ox::Point(-1, 0);
const auto rightPt = pt + geo::Point(1, 0); const auto rightPt = pt + ox::Point(1, 0);
const auto topPt = pt + geo::Point(0, -1); const auto topPt = pt + ox::Point(0, -1);
const auto bottomPt = pt + geo::Point(0, 1); const auto bottomPt = pt + ox::Point(0, 1);
// calculate indices // calculate indices
const auto idx = ptToIdx(pt, activeSubSheet.columns); const auto idx = ptToIdx(pt, activeSubSheet.columns);
const auto leftIdx = ptToIdx(leftPt, activeSubSheet.columns); const auto leftIdx = ptToIdx(leftPt, activeSubSheet.columns);

View File

@ -4,12 +4,12 @@
#pragma once #pragma once
#include <ox/std/bounds.hpp>
#include <ox/std/point.hpp>
#include <ox/std/trace.hpp> #include <ox/std/trace.hpp>
#include <ox/std/string.hpp> #include <ox/std/string.hpp>
#include <nostalgia/core/gfx.hpp> #include <nostalgia/core/gfx.hpp>
#include <nostalgia/geo/bounds.hpp>
#include <nostalgia/geo/point.hpp>
#include <nostalgia/studio/studio.hpp> #include <nostalgia/studio/studio.hpp>
namespace nostalgia::core { namespace nostalgia::core {
@ -30,8 +30,8 @@ class TileSheetEditorModel: public ox::SignalHandler {
Context *m_ctx = nullptr; Context *m_ctx = nullptr;
ox::String m_path; ox::String m_path;
bool m_selectionOngoing = false; bool m_selectionOngoing = false;
geo::Point m_selectionOrigin = {-1, -1}; ox::Point m_selectionOrigin = {-1, -1};
geo::Bounds m_selectionBounds = {{-1, -1}, {-1, -1}}; ox::Bounds m_selectionBounds = {{-1, -1}, {-1, -1}};
public: public:
TileSheetEditorModel(Context *ctx, ox::String path); TileSheetEditorModel(Context *ctx, ox::String path);
@ -58,7 +58,7 @@ class TileSheetEditorModel: public ox::SignalHandler {
ox::Error setPalette(const ox::String &path) noexcept; 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; void endDrawCommand() noexcept;
@ -91,9 +91,9 @@ class TileSheetEditorModel: public ox::SignalHandler {
return m_activeSubsSheetIdx; 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; void completeSelection() noexcept;
@ -116,7 +116,7 @@ class TileSheetEditorModel: public ox::SignalHandler {
bool pixelSelected(std::size_t idx) const noexcept; bool pixelSelected(std::size_t idx) const noexcept;
protected: 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: private:
void pushCommand(studio::UndoCommand *cmd) noexcept; void pushCommand(studio::UndoCommand *cmd) noexcept;

View File

@ -2,9 +2,10 @@
* Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved. * Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/ */
#include <nostalgia/core/consts.hpp> #include <ox/std/point.hpp>
#include <keel/media.hpp> #include <keel/media.hpp>
#include <nostalgia/geo/point.hpp>
#include <nostalgia/core/consts.hpp>
#include "tilesheeteditorview.hpp" #include "tilesheeteditorview.hpp"
@ -25,7 +26,7 @@ void TileSheetEditorView::draw() noexcept {
m_pixelGridDrawer.draw(updated(), m_scrollOffset); 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 auto pixelSize = m_pixelsDrawer.pixelSize(paneSz);
const ImVec2 sheetSize(pixelSize.x * static_cast<float>(m_model.activeSubSheet()->columns) * TileWidth, const ImVec2 sheetSize(pixelSize.x * static_cast<float>(m_model.activeSubSheet()->columns) * TileWidth,
pixelSize.y * static_cast<float>(m_model.activeSubSheet()->rows) * TileHeight); pixelSize.y * static_cast<float>(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); 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 auto pixelSize = m_pixelsDrawer.pixelSize(paneSz);
const ImVec2 sheetSize(pixelSize.x * static_cast<float>(m_model.activeSubSheet()->columns) * TileWidth, const ImVec2 sheetSize(pixelSize.x * static_cast<float>(m_model.activeSubSheet()->columns) * TileWidth,
pixelSize.y * static_cast<float>(m_model.activeSubSheet()->rows) * TileHeight); pixelSize.y * static_cast<float>(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); 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 pt = clickPoint(paneSize, clickPos);
const auto s = m_model.activeSubSheet(); const auto s = m_model.activeSubSheet();
const auto tileIdx = ptToIdx(pt, s->columns) / PixelsPerTile; const auto tileIdx = ptToIdx(pt, s->columns) / PixelsPerTile;
m_model.insertTiles(m_model.activeSubSheetIdx(), tileIdx, 1); 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 pt = clickPoint(paneSize, clickPos);
const auto s = m_model.activeSubSheet(); const auto s = m_model.activeSubSheet();
const auto tileIdx = ptToIdx(pt, s->columns) / PixelsPerTile; const auto tileIdx = ptToIdx(pt, s->columns) / PixelsPerTile;
m_model.deleteTiles(m_model.activeSubSheetIdx(), tileIdx, 1); 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); const auto pt = clickPoint(paneSize, clickPos);
m_model.drawCommand(pt, m_palIdx); 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); const auto pt = clickPoint(paneSize, clickPos);
m_model.select(pt); 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); const auto pt = clickPoint(paneSize, clickPos);
m_model.fill(pt, static_cast<int>(m_palIdx)); m_model.fill(pt, static_cast<int>(m_palIdx));
} }
@ -84,7 +85,7 @@ void TileSheetEditorView::releaseMouseButton() noexcept {
m_model.completeSelection(); m_model.completeSelection();
} }
void TileSheetEditorView::resizeView(const geo::Vec2 &sz) noexcept { void TileSheetEditorView::resizeView(const ox::Vec2 &sz) noexcept {
m_viewSize = sz; m_viewSize = sz;
initView(); initView();
} }
@ -109,7 +110,7 @@ void TileSheetEditorView::initView() noexcept {
m_pixelGridDrawer.initBufferSet(m_viewSize, *m_model.activeSubSheet()); 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; auto [x, y] = clickPos;
const auto pixDrawSz = m_pixelsDrawer.pixelSize(paneSize); const auto pixDrawSz = m_pixelsDrawer.pixelSize(paneSize);
x /= paneSize.x; x /= paneSize.x;

View File

@ -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 #pragma once
#include <ox/std/vec.hpp>
#include <ox/model/def.hpp> #include <ox/model/def.hpp>
#include <nostalgia/core/gfx.hpp> #include <nostalgia/core/gfx.hpp>
#include <nostalgia/geo/vec.hpp>
#include <nostalgia/glutils/glutils.hpp> #include <nostalgia/glutils/glutils.hpp>
#include <nostalgia/studio/studio.hpp> #include <nostalgia/studio/studio.hpp>
@ -42,10 +42,10 @@ class TileSheetEditorView: public ox::SignalHandler {
TileSheetEditorModel m_model; TileSheetEditorModel m_model;
TileSheetGrid m_pixelGridDrawer; TileSheetGrid m_pixelGridDrawer;
TileSheetPixels m_pixelsDrawer; TileSheetPixels m_pixelsDrawer;
geo::Vec2 m_viewSize; ox::Vec2 m_viewSize;
float m_pixelSizeMod = 1; float m_pixelSizeMod = 1;
bool m_updated = false; bool m_updated = false;
geo::Vec2 m_scrollOffset; ox::Vec2 m_scrollOffset;
std::size_t m_palIdx = 0; std::size_t m_palIdx = 0;
public: public:
@ -55,23 +55,23 @@ class TileSheetEditorView: public ox::SignalHandler {
void draw() noexcept; 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 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]] [[nodiscard]]
constexpr const TileSheet &img() const noexcept; constexpr const TileSheet &img() const noexcept;
@ -111,7 +111,7 @@ class TileSheetEditorView: public ox::SignalHandler {
private: private:
void initView() noexcept; 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; ox::Error setActiveSubsheet(const TileSheet::SubSheetIdx &idx) noexcept;

View File

@ -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 <nostalgia/core/consts.hpp> #include <nostalgia/core/consts.hpp>
@ -18,7 +18,7 @@ ox::Error TileSheetGrid::buildShader() noexcept {
return glutils::buildShaderProgram(pixelLineVshad, pixelLineFshad, pixelLineGshad).moveTo(&m_shader); 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); glLineWidth(3 * m_pixelSizeMod * 0.5f);
glUseProgram(m_shader); glUseProgram(m_shader);
glBindVertexArray(m_bufferSet.vao); glBindVertexArray(m_bufferSet.vao);
@ -32,7 +32,7 @@ void TileSheetGrid::draw(bool update, const geo::Vec2 &scroll) noexcept {
glUseProgram(0); 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 // vao
m_bufferSet.vao = glutils::generateVertexArrayObject(); m_bufferSet.vao = glutils::generateVertexArrayObject();
glBindVertexArray(m_bufferSet.vao); glBindVertexArray(m_bufferSet.vao);
@ -54,7 +54,7 @@ void TileSheetGrid::initBufferSet(const geo::Vec2 &paneSize, const TileSheet::Su
reinterpret_cast<void*>(4 * sizeof(float))); reinterpret_cast<void*>(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<float>(pt1.x) * pixSize.x - 1.f; const auto x1 = static_cast<float>(pt1.x) * pixSize.x - 1.f;
const auto y1 = 1.f - static_cast<float>(pt1.y) * pixSize.y; const auto y1 = 1.f - static_cast<float>(pt1.y) * pixSize.y;
const auto x2 = static_cast<float>(pt2.x) * pixSize.x - 1.f; const auto x2 = static_cast<float>(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)); 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 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]; const auto vbo = &m_bufferSet.vertices[i * VertexVboLength];
setBufferObject(pt1, pt2, c, vbo, pixSize); 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; const auto [sw, sh] = paneSize;
constexpr float ymod = 0.35f / 10.0f; constexpr float ymod = 0.35f / 10.0f;
const auto xmod = ymod * sh / sw; const auto xmod = ymod * sh / sw;

View File

@ -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 #pragma once
#include <nostalgia/core/gfx.hpp> #include <nostalgia/core/gfx.hpp>
#include <nostalgia/geo/point.hpp>
#include <nostalgia/geo/vec.hpp>
#include <nostalgia/glutils/glutils.hpp> #include <nostalgia/glutils/glutils.hpp>
#include <nostalgia/studio/studio.hpp> #include <nostalgia/studio/studio.hpp>
@ -67,17 +65,17 @@ class TileSheetGrid {
ox::Error buildShader() noexcept; 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: 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]] [[nodiscard]]
geo::Vec2 pixelSize(const geo::Vec2 &paneSize) const noexcept; ox::Vec2 pixelSize(const ox::Vec2 &paneSize) const noexcept;
}; };

View File

@ -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 <nostalgia/core/consts.hpp> #include <nostalgia/core/consts.hpp>
@ -22,7 +22,7 @@ ox::Error TileSheetPixels::buildShader() noexcept {
return glutils::buildShaderProgram(Vshad, Fshad).moveTo(&m_shader); 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); glUseProgram(m_shader);
glBindVertexArray(m_bufferSet.vao); glBindVertexArray(m_bufferSet.vao);
if (update) { if (update) {
@ -35,7 +35,7 @@ void TileSheetPixels::draw(bool update, const geo::Vec2 &scroll) noexcept {
glUseProgram(0); 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.vao = glutils::generateVertexArrayObject();
m_bufferSet.vbo = glutils::generateBuffer(); m_bufferSet.vbo = glutils::generateBuffer();
m_bufferSet.ebo = glutils::generateBuffer(); m_bufferSet.ebo = glutils::generateBuffer();
@ -50,14 +50,14 @@ void TileSheetPixels::initBufferSet(geo::Vec2 const&paneSize) noexcept {
reinterpret_cast<void*>(2 * sizeof(float))); reinterpret_cast<void*>(2 * sizeof(float)));
} }
void TileSheetPixels::update(geo::Vec2 const&paneSize) noexcept { void TileSheetPixels::update(ox::Vec2 const&paneSize) noexcept {
glBindVertexArray(m_bufferSet.vao); glBindVertexArray(m_bufferSet.vao);
setBufferObjects(paneSize); setBufferObjects(paneSize);
glutils::sendVbo(m_bufferSet); glutils::sendVbo(m_bufferSet);
glutils::sendEbo(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; const auto [sw, sh] = paneSize;
constexpr float ymod = 0.35f / 10.0f; constexpr float ymod = 0.35f / 10.0f;
const auto xmod = ymod * sh / sw; const auto xmod = ymod * sh / sw;
@ -65,7 +65,7 @@ geo::Vec2 TileSheetPixels::pixelSize(const geo::Vec2 &paneSize) const noexcept {
} }
void TileSheetPixels::setPixelBufferObject( void TileSheetPixels::setPixelBufferObject(
geo::Vec2 const&paneSize, ox::Vec2 const&paneSize,
unsigned vertexRow, unsigned vertexRow,
float x, float y, float x, float y,
Color16 color, Color16 color,
@ -92,7 +92,7 @@ void TileSheetPixels::setPixelBufferObject(
memcpy(ebo, elms.data(), sizeof(elms)); 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 // set buffer lengths
const auto subSheet = m_model->activeSubSheet(); const auto subSheet = m_model->activeSubSheet();
const auto pal = m_model->pal(); const auto pal = m_model->pal();

View File

@ -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 #pragma once
#include <ox/std/vec.hpp>
#include <nostalgia/core/gfx.hpp> #include <nostalgia/core/gfx.hpp>
#include <nostalgia/geo/vec.hpp>
#include <nostalgia/glutils/glutils.hpp> #include <nostalgia/glutils/glutils.hpp>
#include <nostalgia/studio/studio.hpp> #include <nostalgia/studio/studio.hpp>
@ -49,19 +50,19 @@ class TileSheetPixels {
ox::Error buildShader() noexcept; 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]] [[nodiscard]]
geo::Vec2 pixelSize(const geo::Vec2 &paneSize) const noexcept; ox::Vec2 pixelSize(const ox::Vec2 &paneSize) const noexcept;
private: 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;
}; };

View File

@ -5,11 +5,11 @@
#pragma once #pragma once
#include <ox/std/array.hpp> #include <ox/std/array.hpp>
#include <ox/std/point.hpp>
#include <ox/std/size.hpp>
#include <ox/std/types.hpp> #include <ox/std/types.hpp>
#include <ox/model/def.hpp> #include <ox/model/def.hpp>
#include <nostalgia/geo/point.hpp>
#include <nostalgia/geo/size.hpp>
#include "color.hpp" #include "color.hpp"
#include "context.hpp" #include "context.hpp"
@ -122,7 +122,7 @@ struct TileSheet {
} }
[[nodiscard]] [[nodiscard]]
constexpr auto idx(const geo::Point &pt) const noexcept { constexpr auto idx(const ox::Point &pt) const noexcept {
return ptToIdx(pt, columns); return ptToIdx(pt, columns);
} }
@ -203,19 +203,19 @@ struct TileSheet {
} }
[[nodiscard]] [[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); const auto idx = ptToIdx(pt, columns);
return getPixel4Bpp(idx); return getPixel4Bpp(idx);
} }
[[nodiscard]] [[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); const auto idx = ptToIdx(pt, columns);
return getPixel8Bpp(idx); return getPixel8Bpp(idx);
} }
[[nodiscard]] [[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); const auto idx = ptToIdx(pt, columns);
return getPixel(pBpp, idx); 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); const auto idx = ptToIdx(pt, columns);
setPixel(pBpp, idx, palIdx); setPixel(pBpp, idx, palIdx);
} }
@ -471,7 +471,7 @@ struct TileSheet {
[[nodiscard]] [[nodiscard]]
constexpr auto getPixel4Bpp( constexpr auto getPixel4Bpp(
const geo::Point &pt, const ox::Point &pt,
const SubSheetIdx &subsheetIdx) const noexcept { const SubSheetIdx &subsheetIdx) const noexcept {
oxAssert(bpp == 4, "TileSheet::getPixel4Bpp: wrong bpp"); oxAssert(bpp == 4, "TileSheet::getPixel4Bpp: wrong bpp");
auto &s = this->getSubSheet(subsheetIdx); auto &s = this->getSubSheet(subsheetIdx);
@ -481,7 +481,7 @@ struct TileSheet {
[[nodiscard]] [[nodiscard]]
constexpr auto getPixel8Bpp( constexpr auto getPixel8Bpp(
const geo::Point &pt, const ox::Point &pt,
const SubSheetIdx &subsheetIdx) const noexcept { const SubSheetIdx &subsheetIdx) const noexcept {
oxAssert(bpp == 8, "TileSheet::getPixel8Bpp: wrong bpp"); oxAssert(bpp == 8, "TileSheet::getPixel8Bpp: wrong bpp");
auto &s = this->getSubSheet(subsheetIdx); auto &s = this->getSubSheet(subsheetIdx);

View File

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

View File

@ -1,131 +0,0 @@
/*
* Copyright 2016 - 2022 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#pragma once
#include <ox/model/def.hpp>
#include <ox/std/error.hpp>
#include <ox/std/new.hpp>
#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()
}

View File

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

View File

@ -1,188 +0,0 @@
/*
* Copyright 2016 - 2022 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#pragma once
#include <ox/model/def.hpp>
#include <ox/std/error.hpp>
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()
}

View File

@ -1,188 +0,0 @@
/*
* Copyright 2016 - 2022 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#pragma once
#include <ox/std/error.hpp>
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()
}

View File

@ -1,16 +0,0 @@
/*
* Copyright 2016 - 2022 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#include <ox/std/defines.hpp>
#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;
}());
}

View File

@ -1,264 +0,0 @@
/*
* Copyright 2016 - 2022 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#pragma once
#if __has_include(<imgui.h>)
#include <imgui.h>
#endif
#include <ox/model/def.hpp>
#include <ox/std/assert.hpp>
#include <ox/std/bit.hpp>
#include <ox/std/def.hpp>
#include <ox/std/error.hpp>
#include <ox/std/iterator.hpp>
#include <ox/std/math.hpp>
#include <ox/std/types.hpp>
namespace nostalgia::geo {
template<typename T>
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<typename RefType = value_type&, typename PtrType = value_type*, bool reverse = false>
struct iterator: public ox::Iterator<std::bidirectional_iterator_tag, value_type> {
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<size_type>(m_offset - s, 0), m_max);
} else {
return iterator(m_t, ox::min<size_type>(m_offset + s, m_max), m_max);
}
}
constexpr typename ox::Iterator<std::bidirectional_iterator_tag, value_type>::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<size_type>(m_offset + s, m_max), m_max);
} else {
return iterator(m_t, ox::max<size_type>(m_offset - s, 0), m_max);
}
}
constexpr iterator &operator+=(size_type s) noexcept {
if constexpr(reverse) {
m_offset = ox::max<size_type>(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<size_type>(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<typename ...Args>
constexpr Vec(T pX, T pY) noexcept: x(pX), y(pY) {
}
#if __has_include(<imgui.h>)
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<const value_type&, const value_type*> begin() const noexcept {
return {start(), 0, size()};
}
[[nodiscard]]
constexpr iterator<const value_type&, const value_type*> end() const noexcept {
return {start(), size(), size()};
}
[[nodiscard]]
constexpr iterator<value_type&, value_type*, true> rbegin() noexcept {
return {start(), size() - 1, size()};
}
[[nodiscard]]
constexpr iterator<value_type&, value_type*, true> rend() noexcept {
return {start(), ox::MaxValue<size_type>, size()};
}
[[nodiscard]]
constexpr iterator<const value_type&, const value_type*, true> rbegin() const noexcept {
return {start(), size() - 1, size()};
}
[[nodiscard]]
constexpr iterator<const value_type&, const value_type*, true> rend() const noexcept {
return {start(), ox::MaxValue<size_type>, 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<float>;
oxModelBegin(Vec2)
oxModelField(x)
oxModelField(y)
oxModelEnd()
}

View File

@ -10,7 +10,6 @@ add_library(
target_link_libraries( target_link_libraries(
NostalgiaScene PUBLIC NostalgiaScene PUBLIC
NostalgiaCore NostalgiaCore
NostalgiaGeo
) )
install( install(

View File

@ -6,11 +6,11 @@
#include <ox/fs/fs.hpp> #include <ox/fs/fs.hpp>
#include <ox/std/error.hpp> #include <ox/std/error.hpp>
#include <ox/std/size.hpp>
#include <ox/std/types.hpp> #include <ox/std/types.hpp>
#include <ox/std/vector.hpp> #include <ox/std/vector.hpp>
#include <nostalgia/core/tilesheet.hpp> #include <nostalgia/core/tilesheet.hpp>
#include <nostalgia/geo/size.hpp>
namespace nostalgia::scene { namespace nostalgia::scene {
@ -78,7 +78,7 @@ struct SceneDoc {
TileMap tiles; TileMap tiles;
[[nodiscard]] [[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 &layer = this->tiles[layerIdx];
const auto rowCnt = static_cast<int>(layer.size()); const auto rowCnt = static_cast<int>(layer.size());
if (!rowCnt) { if (!rowCnt) {
@ -170,7 +170,7 @@ struct SceneStatic {
constexpr Tile tile(std::size_t i) noexcept { constexpr Tile tile(std::size_t i) noexcept {
return {tileMapIdx[i], tileType[i], layerAttachments[i]}; return {tileMapIdx[i], tileType[i], layerAttachments[i]};
} }
constexpr auto setDimensions(geo::Size dim) noexcept { constexpr auto setDimensions(ox::Size dim) noexcept {
columns = dim.width; columns = dim.width;
rows = dim.height; rows = dim.height;
const auto tileCnt = static_cast<unsigned>(columns * rows); const auto tileCnt = static_cast<unsigned>(columns * rows);

View File

@ -32,7 +32,7 @@ ox::CRString SceneEditorImGui::itemDisplayName() const noexcept {
void SceneEditorImGui::draw(core::Context*) noexcept { void SceneEditorImGui::draw(core::Context*) noexcept {
const auto paneSize = ImGui::GetContentRegionAvail(); const auto paneSize = ImGui::GetContentRegionAvail();
const geo::Size fbSize{ const ox::Size fbSize{
static_cast<int>(paneSize.x), static_cast<int>(paneSize.x),
static_cast<int>(paneSize.y)}; static_cast<int>(paneSize.y)};
m_view.draw(fbSize.width, fbSize.height); m_view.draw(fbSize.width, fbSize.height);

View File

@ -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 #pragma once
#include <ox/event/signal.hpp> #include <ox/event/signal.hpp>
#include <ox/std/string.hpp> #include <ox/std/string.hpp>
#include <ox/std/vec.hpp>
#include <nostalgia/geo/vec.hpp>
#include <nostalgia/core/context.hpp> #include <nostalgia/core/context.hpp>
#include "imguiuitl.hpp" #include "imguiuitl.hpp"
@ -17,7 +17,7 @@ namespace nostalgia::studio {
class Popup { class Popup {
private: private:
geo::Vec2 m_size; ox::Vec2 m_size;
ox::String m_title; ox::String m_title;
public: public:
// emits path parameter // emits path parameter
@ -35,7 +35,7 @@ class Popup {
virtual void draw(core::Context *ctx) noexcept = 0; virtual void draw(core::Context *ctx) noexcept = 0;
protected: protected:
constexpr void setSize(geo::Size sz) noexcept { constexpr void setSize(ox::Size sz) noexcept {
m_size = {static_cast<float>(sz.width), static_cast<float>(sz.height)}; m_size = {static_cast<float>(sz.width), static_cast<float>(sz.height)};
} }

View File

@ -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 <algorithm> #include <algorithm>
#include <imgui.h> #include <imgui.h>
#include <nostalgia/geo/bounds.hpp>
#include "projectexplorer.hpp" #include "projectexplorer.hpp"
namespace nostalgia { namespace nostalgia {