diff --git a/src/nostalgia/CMakeLists.txt b/src/nostalgia/CMakeLists.txt index c0052c33..50a8ad6e 100644 --- a/src/nostalgia/CMakeLists.txt +++ b/src/nostalgia/CMakeLists.txt @@ -2,7 +2,7 @@ #project packages add_subdirectory(core) -add_subdirectory(common) +add_subdirectory(geo) add_subdirectory(scene) add_subdirectory(world) diff --git a/src/nostalgia/core/color.hpp b/src/nostalgia/core/color.hpp index 63d87db7..ae26b731 100644 --- a/src/nostalgia/core/color.hpp +++ b/src/nostalgia/core/color.hpp @@ -5,7 +5,7 @@ #pragma once #include -#include +#include #include "context.hpp" diff --git a/src/nostalgia/core/context.hpp b/src/nostalgia/core/context.hpp index 95dfbaa2..39c36ac5 100644 --- a/src/nostalgia/core/context.hpp +++ b/src/nostalgia/core/context.hpp @@ -10,7 +10,7 @@ #include "event.hpp" #include "input.hpp" -namespace nostalgia::common { +namespace nostalgia::geo { class Size; } @@ -27,7 +27,7 @@ class 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 common::Size getScreenSize(Context *ctx) noexcept; + friend geo::Size getScreenSize(Context *ctx) noexcept; friend int getScreenHeight(Context *ctx) noexcept; friend int getScreenWidth(Context *ctx) noexcept; friend ox::Error initGfx(Context *ctx) noexcept; diff --git a/src/nostalgia/core/gba/gfx.cpp b/src/nostalgia/core/gba/gfx.cpp index 58acfc22..40785363 100644 --- a/src/nostalgia/core/gba/gfx.cpp +++ b/src/nostalgia/core/gba/gfx.cpp @@ -108,7 +108,7 @@ int getScreenHeight(Context*) noexcept { return 160; } -common::Size getScreenSize(Context*) noexcept { +geo::Size getScreenSize(Context*) noexcept { return {240, 160}; } diff --git a/src/nostalgia/core/gfx.hpp b/src/nostalgia/core/gfx.hpp index c4a59b8d..ab887a99 100644 --- a/src/nostalgia/core/gfx.hpp +++ b/src/nostalgia/core/gfx.hpp @@ -6,8 +6,8 @@ #include #include -#include -#include +#include +#include #include "color.hpp" #include "context.hpp" @@ -47,7 +47,7 @@ struct NostalgiaGraphic { ox::Vector pixels; [[nodiscard]] - constexpr auto getPixel4Bpp(const common::Point &pt) const noexcept { + constexpr auto getPixel4Bpp(const geo::Point &pt) const noexcept { oxAssert(bpp == 4, "NostalgiaGraphic::getPixel4Bpp: wrong bpp"); const auto idx = ptToIdx(pt, this->columns); if (idx & 1) { @@ -58,14 +58,14 @@ struct NostalgiaGraphic { } [[nodiscard]] - constexpr auto getPixel8Bpp(const common::Point &pt) const noexcept { + constexpr auto getPixel8Bpp(const geo::Point &pt) const noexcept { oxAssert(bpp == 8, "NostalgiaGraphic::getPixel8Bpp: wrong bpp"); const auto idx = ptToIdx(pt, this->columns); return this->pixels[idx]; } [[nodiscard]] - constexpr auto getPixel(const common::Point &pt) const noexcept { + constexpr auto getPixel(const geo::Point &pt) const noexcept { if (this->bpp == 4) { return getPixel4Bpp(pt); } else { @@ -73,7 +73,7 @@ struct NostalgiaGraphic { } } - constexpr void setPixel(const common::Point &pt, uint8_t palIdx) noexcept { + constexpr void setPixel(const geo::Point &pt, uint8_t palIdx) noexcept { const auto idx = ptToIdx(pt, this->columns); if (bpp == 4) { if (idx & 1) { @@ -127,7 +127,7 @@ int getScreenWidth(Context *ctx) noexcept; int getScreenHeight(Context *ctx) noexcept; [[nodiscard]] -common::Size getScreenSize(Context *ctx) noexcept; +geo::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 f687e862..e539d2fa 100644 --- a/src/nostalgia/core/glfw/gfx.cpp +++ b/src/nostalgia/core/glfw/gfx.cpp @@ -99,7 +99,7 @@ int getScreenHeight(Context *ctx) noexcept { return h; } -common::Size getScreenSize(Context *ctx) noexcept { +geo::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/ptidxconv.hpp b/src/nostalgia/core/ptidxconv.hpp index fe8d4744..6b5ec7f9 100644 --- a/src/nostalgia/core/ptidxconv.hpp +++ b/src/nostalgia/core/ptidxconv.hpp @@ -4,7 +4,7 @@ #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 common::Point &pt, int c) noexcept { +constexpr std::size_t ptToIdx(const geo::Point &pt, int c) noexcept { return ptToIdx(pt.x, pt.y, c * TileWidth); } [[nodiscard]] -constexpr common::Point idxToPt(int i, int c) noexcept { +constexpr geo::Point idxToPt(int i, int c) noexcept { const auto t = i / PixelsPerTile; // tile number const auto iti = i % PixelsPerTile; // in tile index const auto tc = t % c; // tile column @@ -40,13 +40,13 @@ constexpr common::Point idxToPt(int i, int c) noexcept { }; } -static_assert(idxToPt(4, 1) == common::Point{4, 0}); -static_assert(idxToPt(8, 1) == common::Point{0, 1}); -static_assert(idxToPt(8, 2) == common::Point{0, 1}); -static_assert(idxToPt(64, 2) == common::Point{8, 0}); -static_assert(idxToPt(128, 2) == common::Point{0, 8}); -static_assert(idxToPt(129, 2) == common::Point{1, 8}); -static_assert(idxToPt(192, 2) == common::Point{8, 8}); -static_assert(idxToPt(384, 8) == common::Point{48, 0}); +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}); } diff --git a/src/nostalgia/core/studio/tilesheeteditor-imgui.cpp b/src/nostalgia/core/studio/tilesheeteditor-imgui.cpp index b2a787fc..28e659b2 100644 --- a/src/nostalgia/core/studio/tilesheeteditor-imgui.cpp +++ b/src/nostalgia/core/studio/tilesheeteditor-imgui.cpp @@ -6,8 +6,8 @@ #include -#include #include +#include #include "tilesheeteditor-imgui.hpp" @@ -45,7 +45,7 @@ void TileSheetEditorImGui::paste() { void TileSheetEditorImGui::draw(core::Context*) noexcept { const auto paneSize = ImGui::GetContentRegionAvail(); const auto tileSheetParentSize = ImVec2(paneSize.x - m_palViewWidth, paneSize.y); - const auto fbSize = common::Vec2(tileSheetParentSize.x - 16, tileSheetParentSize.y - 16); + const auto fbSize = geo::Vec2(tileSheetParentSize.x - 16, tileSheetParentSize.y - 16); ImGui::BeginChild("child1", ImVec2(tileSheetParentSize.x, tileSheetParentSize.y), true); drawTileSheet(fbSize); ImGui::EndChild(); @@ -59,8 +59,8 @@ void TileSheetEditorImGui::draw(core::Context*) noexcept { void TileSheetEditorImGui::saveItem() { } -void TileSheetEditorImGui::drawTileSheet(const common::Vec2 &fbSize) noexcept { - const auto fbSizei = common::Size(static_cast(fbSize.x), static_cast(fbSize.y)); +void TileSheetEditorImGui::drawTileSheet(const geo::Vec2 &fbSize) noexcept { + const auto fbSizei = geo::Size(static_cast(fbSize.x), static_cast(fbSize.y)); if (m_framebuffer.width != fbSizei.width || m_framebuffer.height != fbSizei.height) { m_framebuffer = glutils::generateFrameBuffer(fbSizei.width, fbSizei.height); m_tileSheetEditor.resize(fbSize); @@ -87,7 +87,7 @@ void TileSheetEditorImGui::drawTileSheet(const common::Vec2 &fbSize) noexcept { m_tileSheetEditor.scrollH(fbSize, wheelh); } if (io.MouseDown[0]) { - auto clickPos = common::Vec2(io.MousePos); + auto clickPos = geo::Vec2(io.MousePos); const auto &winPos = ImGui::GetWindowPos(); clickPos.x -= winPos.x + 10; clickPos.y -= winPos.y + 10; diff --git a/src/nostalgia/core/studio/tilesheeteditor-imgui.hpp b/src/nostalgia/core/studio/tilesheeteditor-imgui.hpp index 8a578e45..4d7b372b 100644 --- a/src/nostalgia/core/studio/tilesheeteditor-imgui.hpp +++ b/src/nostalgia/core/studio/tilesheeteditor-imgui.hpp @@ -6,8 +6,8 @@ #include -#include -#include +#include +#include #include #include #include @@ -62,7 +62,7 @@ class TileSheetEditorImGui: public studio::Editor { [[nodiscard]] ox::String palettePath(const ox::String &palettePath) const; - void drawTileSheet(const common::Vec2 &fbSize) noexcept; + void drawTileSheet(const geo::Vec2 &fbSize) noexcept; void drawPalettePicker() noexcept; diff --git a/src/nostalgia/core/studio/tilesheeteditor.cpp b/src/nostalgia/core/studio/tilesheeteditor.cpp index 420d5891..99aed085 100644 --- a/src/nostalgia/core/studio/tilesheeteditor.cpp +++ b/src/nostalgia/core/studio/tilesheeteditor.cpp @@ -4,7 +4,7 @@ #include -#include +#include #include #include #include @@ -40,7 +40,7 @@ void TileSheetEditor::draw() noexcept { m_updated = false; } -void TileSheetEditor::scrollV(const common::Vec2 paneSz, float wheel, bool zoomMod) noexcept { +void TileSheetEditor::scrollV(const geo::Vec2 paneSz, float wheel, bool zoomMod) noexcept { const auto pixelSize = m_pixelsDrawer.pixelSize(paneSz); const ImVec2 sheetSize(pixelSize.x * static_cast(m_img.columns) * TileWidth, pixelSize.y * static_cast(m_img.rows) * TileHeight); @@ -57,7 +57,7 @@ void TileSheetEditor::scrollV(const common::Vec2 paneSz, float wheel, bool zoomM m_scrollOffset.y = ox::clamp(m_scrollOffset.y, 0.f, sheetSize.y / 2); } -void TileSheetEditor::scrollH(const common::Vec2 paneSz, float wheelh) noexcept { +void TileSheetEditor::scrollH(const geo::Vec2 paneSz, float wheelh) noexcept { const auto pixelSize = m_pixelsDrawer.pixelSize(paneSz); const ImVec2 sheetSize(pixelSize.x * static_cast(m_img.columns) * TileWidth, pixelSize.y * static_cast(m_img.rows) * TileHeight); @@ -65,7 +65,7 @@ void TileSheetEditor::scrollH(const common::Vec2 paneSz, float wheelh) noexcept m_scrollOffset.x = ox::clamp(m_scrollOffset.x, -(sheetSize.x / 2), 0.f); } -void TileSheetEditor::clickPixel(const common::Vec2 &paneSize, const common::Vec2 &clickPos) noexcept { +void TileSheetEditor::clickPixel(const geo::Vec2 &paneSize, const geo::Vec2 &clickPos) noexcept { auto [x, y] = clickPos; const auto pixDrawSz = m_pixelsDrawer.pixelSize(paneSize); x /= paneSize.x; @@ -74,13 +74,13 @@ void TileSheetEditor::clickPixel(const common::Vec2 &paneSize, const common::Vec y += m_scrollOffset.y / 2; x /= pixDrawSz.x; y /= pixDrawSz.y; - const auto pt = common::Point(static_cast(x * 2), static_cast(y * 2)); + const auto pt = geo::Point(static_cast(x * 2), static_cast(y * 2)); const uint8_t palIdx = 0; m_img.setPixel(pt, palIdx); m_updated = true; } -void TileSheetEditor::resize(const common::Vec2 &sz) noexcept { +void TileSheetEditor::resize(const geo::Vec2 &sz) noexcept { m_pixelsDrawer.initBufferSet(sz, m_img, *m_pal); m_pixelGridDrawer.initBufferSet(sz, m_img); } @@ -104,15 +104,15 @@ void TileSheetEditor::ackUpdate() noexcept { void TileSheetEditor::saveItem() { } -void TileSheetEditor::getFillPixels(bool *pixels, common::Point pt, int oldColor) const { - const auto tileIdx = [this](const common::Point &pt) noexcept { +void TileSheetEditor::getFillPixels(bool *pixels, geo::Point pt, int oldColor) const { + const auto tileIdx = [this](const geo::Point &pt) noexcept { return ptToIdx(pt, m_img.columns) / PixelsPerTile; }; // get points - const auto leftPt = pt + common::Point(-1, 0); - const auto rightPt = pt + common::Point(1, 0); - const auto topPt = pt + common::Point(0, -1); - const auto bottomPt = pt + common::Point(0, 1); + 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); // calculate indices const auto idx = ptToIdx(pt, m_img.columns); const auto leftIdx = ptToIdx(leftPt, m_img.columns); diff --git a/src/nostalgia/core/studio/tilesheeteditor.hpp b/src/nostalgia/core/studio/tilesheeteditor.hpp index 6de7790f..53b76892 100644 --- a/src/nostalgia/core/studio/tilesheeteditor.hpp +++ b/src/nostalgia/core/studio/tilesheeteditor.hpp @@ -6,8 +6,8 @@ #include -#include -#include +#include +#include #include #include #include @@ -48,7 +48,7 @@ constexpr auto toString(TileSheetTool t) noexcept { struct PixelChunk { static constexpr auto TypeName = "net.drinkingtea.nostalgia.core.studio.PixelChunk"; static constexpr auto TypeVersion = 1; - common::Point pt; + geo::Point pt; int size = 0; }; @@ -65,8 +65,8 @@ struct TileSheetClipboard { protected: ox::Vector m_pixels; - common::Point m_p1; - common::Point m_p2; + geo::Point m_p1; + geo::Point m_p2; public: void addPixel(int color); @@ -74,15 +74,15 @@ struct TileSheetClipboard { [[nodiscard]] bool empty() const; - void pastePixels(const common::Point &pt, ox::Vector *tgt, int tgtColumns) const; + void pastePixels(const geo::Point &pt, ox::Vector *tgt, int tgtColumns) const; - void setPoints(const common::Point &p1, const common::Point &p2); + void setPoints(const geo::Point &p1, const geo::Point &p2); [[nodiscard]] - common::Point point1() const; + geo::Point point1() const; [[nodiscard]] - common::Point point2() const; + geo::Point point2() const; }; @@ -104,7 +104,7 @@ class TileSheetEditor { NostalgiaGraphic m_img; AssetRef m_pal; float m_pixelSizeMod = 1; - common::Vec2 m_scrollOffset; + geo::Vec2 m_scrollOffset; public: TileSheetEditor(Context *ctx, const ox::String &path); @@ -119,13 +119,13 @@ class TileSheetEditor { void draw() noexcept; - void clickPixel(const common::Vec2 &paneSize, const common::Vec2 &clickPos) noexcept; + void clickPixel(const geo::Vec2 &paneSize, const geo::Vec2 &clickPos) noexcept; - void scrollV(const common::Vec2 paneSz, float wheel, bool zoomMod) noexcept; + void scrollV(const geo::Vec2 paneSz, float wheel, bool zoomMod) noexcept; - void scrollH(const common::Vec2 paneSz, float wheel) noexcept; + void scrollH(const geo::Vec2 paneSz, float wheel) noexcept; - void resize(const common::Vec2 &sz) noexcept; + void resize(const geo::Vec2 &sz) noexcept; const NostalgiaGraphic &img() const; @@ -138,7 +138,7 @@ class TileSheetEditor { protected: void saveItem(); - void getFillPixels(bool *pixels, common::Point pt, int oldColor) const; + void getFillPixels(bool *pixels, geo::Point pt, int oldColor) const; private: void setPalette(); diff --git a/src/nostalgia/core/studio/tilesheetpixelgrid.cpp b/src/nostalgia/core/studio/tilesheetpixelgrid.cpp index f9b4e572..abedf1d8 100644 --- a/src/nostalgia/core/studio/tilesheetpixelgrid.cpp +++ b/src/nostalgia/core/studio/tilesheetpixelgrid.cpp @@ -18,7 +18,7 @@ ox::Error TileSheetGrid::buildShader() noexcept { return glutils::buildShaderProgram(pixelLineVshad, pixelLineFshad, pixelLineGshad).moveTo(&m_shader); } -void TileSheetGrid::draw(bool update, const common::Vec2 &scroll) noexcept { +void TileSheetGrid::draw(bool update, const geo::Vec2 &scroll) noexcept { glLineWidth(3 * m_pixelSizeMod * 0.5f); glUseProgram(m_shader); glBindVertexArray(m_bufferSet.vao); @@ -30,7 +30,7 @@ void TileSheetGrid::draw(bool update, const common::Vec2 &scroll) noexcept { glDrawArrays(GL_POINTS, 0, m_bufferSet.vertices.size() / VertexVboRowLength); } -void TileSheetGrid::initBufferSet(const common::Vec2 &paneSize, const NostalgiaGraphic &img) noexcept { +void TileSheetGrid::initBufferSet(const geo::Vec2 &paneSize, const NostalgiaGraphic &img) noexcept { // vao m_bufferSet.vao = glutils::generateVertexArrayObject(); glBindVertexArray(m_bufferSet.vao); @@ -52,7 +52,7 @@ void TileSheetGrid::initBufferSet(const common::Vec2 &paneSize, const NostalgiaG reinterpret_cast(4 * sizeof(float))); } -void TileSheetGrid::setBufferObject(common::Point pt1, common::Point pt2, Color32 c, float *vbo, const common::Vec2 &pixSize) noexcept { +void TileSheetGrid::setBufferObject(geo::Point pt1, geo::Point pt2, Color32 c, float *vbo, const geo::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; @@ -62,9 +62,9 @@ void TileSheetGrid::setBufferObject(common::Point pt1, common::Point pt2, Color3 memcpy(vbo, vertices, sizeof(vertices)); } -void TileSheetGrid::setBufferObjects(const common::Vec2 &paneSize, const NostalgiaGraphic &img, glutils::BufferSet *bg) noexcept { +void TileSheetGrid::setBufferObjects(const geo::Vec2 &paneSize, const NostalgiaGraphic &img, glutils::BufferSet *bg) noexcept { const auto pixSize = pixelSize(paneSize); - const auto set = [bg, pixSize](unsigned i, common::Point pt1, common::Point pt2, Color32 c) { + const auto set = [bg, pixSize](unsigned i, geo::Point pt1, geo::Point pt2, Color32 c) { const auto vbo = &bg->vertices[i * VertexVboLength]; setBufferObject(pt1, pt2, c, vbo, pixSize); }; @@ -98,7 +98,7 @@ void TileSheetGrid::setBufferObjects(const common::Vec2 &paneSize, const Nostalg } } -common::Vec2 TileSheetGrid::pixelSize(const common::Vec2 &paneSize) const noexcept { +geo::Vec2 TileSheetGrid::pixelSize(const geo::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 7e12a0a9..2b7c1db7 100644 --- a/src/nostalgia/core/studio/tilesheetpixelgrid.hpp +++ b/src/nostalgia/core/studio/tilesheetpixelgrid.hpp @@ -4,9 +4,9 @@ #pragma once -#include -#include #include +#include +#include #include #include @@ -67,17 +67,17 @@ class TileSheetGrid { ox::Error buildShader() noexcept; - void draw(bool update, const common::Vec2 &scroll) noexcept; + void draw(bool update, const geo::Vec2 &scroll) noexcept; - void initBufferSet(const common::Vec2 &paneSize, const NostalgiaGraphic &img) noexcept; + void initBufferSet(const geo::Vec2 &paneSize, const NostalgiaGraphic &img) noexcept; private: - static void setBufferObject(common::Point pt1, common::Point pt2, Color32 c, float *vbo, const common::Vec2 &pixSize) noexcept; + static void setBufferObject(geo::Point pt1, geo::Point pt2, Color32 c, float *vbo, const geo::Vec2 &pixSize) noexcept; - void setBufferObjects(const common::Vec2 &paneSize, const NostalgiaGraphic &img, glutils::BufferSet *bg) noexcept; + void setBufferObjects(const geo::Vec2 &paneSize, const NostalgiaGraphic &img, glutils::BufferSet *bg) noexcept; [[nodiscard]] - common::Vec2 pixelSize(const common::Vec2 &paneSize) const noexcept; + geo::Vec2 pixelSize(const geo::Vec2 &paneSize) const noexcept; }; diff --git a/src/nostalgia/core/studio/tilesheetpixels.cpp b/src/nostalgia/core/studio/tilesheetpixels.cpp index 089b1c25..0b3a61a6 100644 --- a/src/nostalgia/core/studio/tilesheetpixels.cpp +++ b/src/nostalgia/core/studio/tilesheetpixels.cpp @@ -18,7 +18,7 @@ ox::Error TileSheetPixels::buildShader() noexcept { return glutils::buildShaderProgram(Vshad, Fshad).moveTo(&m_shader); } -void TileSheetPixels::draw(bool update, const common::Vec2 &scroll) noexcept { +void TileSheetPixels::draw(bool update, const geo::Vec2 &scroll) noexcept { glUseProgram(m_shader); glBindVertexArray(m_bufferSet.vao); if (update) { @@ -29,7 +29,7 @@ void TileSheetPixels::draw(bool update, const common::Vec2 &scroll) noexcept { glDrawElements(GL_TRIANGLES, static_cast(m_bufferSet.elements.size()), GL_UNSIGNED_INT, nullptr); } -void TileSheetPixels::initBufferSet(const common::Vec2 &paneSize, const NostalgiaGraphic &img, const NostalgiaPalette &pal) noexcept { +void TileSheetPixels::initBufferSet(const geo::Vec2 &paneSize, const NostalgiaGraphic &img, const NostalgiaPalette &pal) noexcept { // vao m_bufferSet.vao = glutils::generateVertexArrayObject(); glBindVertexArray(m_bufferSet.vao); @@ -49,14 +49,14 @@ void TileSheetPixels::initBufferSet(const common::Vec2 &paneSize, const Nostalgi reinterpret_cast(2 * sizeof(float))); } -common::Vec2 TileSheetPixels::pixelSize(const common::Vec2 &paneSize) const noexcept { +geo::Vec2 TileSheetPixels::pixelSize(const geo::Vec2 &paneSize) const noexcept { const auto [sw, sh] = paneSize; constexpr float ymod = 0.35f / 10.0f; const auto xmod = ymod * sh / sw; return {xmod * m_pixelSizeMod, ymod * m_pixelSizeMod}; } -void TileSheetPixels::setPixelBufferObject(const common::Vec2 &paneSize, unsigned vertexRow, float x, float y, Color16 color, float *vbo, GLuint *ebo) noexcept { +void TileSheetPixels::setPixelBufferObject(const geo::Vec2 &paneSize, unsigned vertexRow, float x, float y, Color16 color, float *vbo, GLuint *ebo) noexcept { const auto [xmod, ymod] = pixelSize(paneSize); x *= xmod; y *= -ymod; @@ -78,7 +78,7 @@ void TileSheetPixels::setPixelBufferObject(const common::Vec2 &paneSize, unsigne memcpy(ebo, elms, sizeof(elms)); } -void TileSheetPixels::setBufferObjects(const common::Vec2 &paneSize, const NostalgiaGraphic &img, const NostalgiaPalette &pal, glutils::BufferSet *bg) noexcept { +void TileSheetPixels::setBufferObjects(const geo::Vec2 &paneSize, const NostalgiaGraphic &img, const NostalgiaPalette &pal, glutils::BufferSet *bg) noexcept { const auto setPixel = [this, paneSize, bg, img, pal](std::size_t i, uint8_t p) { const auto color = pal.colors[p]; const auto pt = idxToPt(static_cast(i), img.columns); diff --git a/src/nostalgia/core/studio/tilesheetpixels.hpp b/src/nostalgia/core/studio/tilesheetpixels.hpp index 82727c14..7a2c5053 100644 --- a/src/nostalgia/core/studio/tilesheetpixels.hpp +++ b/src/nostalgia/core/studio/tilesheetpixels.hpp @@ -4,8 +4,8 @@ #pragma once -#include #include +#include #include #include @@ -46,17 +46,17 @@ class TileSheetPixels { ox::Error buildShader() noexcept; - void draw(bool update, const common::Vec2 &scroll) noexcept; + void draw(bool update, const geo::Vec2 &scroll) noexcept; - void initBufferSet(const common::Vec2 &paneSize, const NostalgiaGraphic &img, const NostalgiaPalette &pal) noexcept; + void initBufferSet(const geo::Vec2 &paneSize, const NostalgiaGraphic &img, const NostalgiaPalette &pal) noexcept; [[nodiscard]] - common::Vec2 pixelSize(const common::Vec2 &paneSize) const noexcept; + geo::Vec2 pixelSize(const geo::Vec2 &paneSize) const noexcept; private: - void setPixelBufferObject(const common::Vec2 &paneS, unsigned vertexRow, float x, float y, Color16 color, float *vbo, GLuint *ebo) noexcept; + void setPixelBufferObject(const geo::Vec2 &paneS, unsigned vertexRow, float x, float y, Color16 color, float *vbo, GLuint *ebo) noexcept; - void setBufferObjects(const common::Vec2 &paneS, const NostalgiaGraphic &img, const NostalgiaPalette &pal, glutils::BufferSet *bg) noexcept; + void setBufferObjects(const geo::Vec2 &paneS, const NostalgiaGraphic &img, const NostalgiaPalette &pal, glutils::BufferSet *bg) noexcept; }; diff --git a/src/nostalgia/common/CMakeLists.txt b/src/nostalgia/geo/CMakeLists.txt similarity index 94% rename from src/nostalgia/common/CMakeLists.txt rename to src/nostalgia/geo/CMakeLists.txt index 842b0776..759963b4 100644 --- a/src/nostalgia/common/CMakeLists.txt +++ b/src/nostalgia/geo/CMakeLists.txt @@ -16,7 +16,7 @@ install( install( FILES bounds.hpp - common.hpp + geo.hpp point.hpp size.hpp vec.hpp diff --git a/src/nostalgia/common/bounds.cpp b/src/nostalgia/geo/bounds.cpp similarity index 95% rename from src/nostalgia/common/bounds.cpp rename to src/nostalgia/geo/bounds.cpp index ea8d3358..14a63977 100644 --- a/src/nostalgia/common/bounds.cpp +++ b/src/nostalgia/geo/bounds.cpp @@ -1,9 +1,10 @@ /* * Copyright 2016 - 2022 Gary Talent (gary@drinkingtea.net). All rights reserved. */ + #include "bounds.hpp" -namespace nostalgia::common { +namespace nostalgia::geo { Bounds::Bounds(int x, int y, int w, int h) noexcept { this->x = x; diff --git a/src/nostalgia/common/bounds.hpp b/src/nostalgia/geo/bounds.hpp similarity index 90% rename from src/nostalgia/common/bounds.hpp rename to src/nostalgia/geo/bounds.hpp index caafd2c9..e735279d 100644 --- a/src/nostalgia/common/bounds.hpp +++ b/src/nostalgia/geo/bounds.hpp @@ -6,12 +6,12 @@ #include "point.hpp" -namespace nostalgia::common { +namespace nostalgia::geo { class Bounds { public: - static constexpr auto TypeName = "net.drinkingtea.nostalgia.common.Bounds"; + static constexpr auto TypeName = "net.drinkingtea.nostalgia.geo.Bounds"; static constexpr auto TypeVersion = 1; int x = 0; int y = 0; diff --git a/src/nostalgia/common/common.hpp b/src/nostalgia/geo/geo.hpp similarity index 100% rename from src/nostalgia/common/common.hpp rename to src/nostalgia/geo/geo.hpp diff --git a/src/nostalgia/common/point.hpp b/src/nostalgia/geo/point.hpp similarity index 68% rename from src/nostalgia/common/point.hpp rename to src/nostalgia/geo/point.hpp index 2e8ba1d9..0d4e4cc6 100644 --- a/src/nostalgia/common/point.hpp +++ b/src/nostalgia/geo/point.hpp @@ -6,11 +6,11 @@ #include -namespace nostalgia::common { +namespace nostalgia::geo { class Point { public: - static constexpr auto TypeName = "net.drinkingtea.nostalgia.common.Point"; + static constexpr auto TypeName = "net.drinkingtea.nostalgia.geo.Point"; static constexpr auto TypeVersion = 1; int x = 0; int y = 0; @@ -19,22 +19,22 @@ class Point { constexpr Point(int x, int y) noexcept; - constexpr Point operator+(const common::Point &p) const noexcept; + constexpr Point operator+(const geo::Point &p) const noexcept; - constexpr Point operator-(const common::Point &p) const noexcept; + constexpr Point operator-(const geo::Point &p) const noexcept; - constexpr Point operator*(const common::Point &p) const noexcept; + constexpr Point operator*(const geo::Point &p) const noexcept; - constexpr Point operator/(const common::Point &p) const noexcept; + constexpr Point operator/(const geo::Point &p) const noexcept; - constexpr Point operator+=(const common::Point &p) noexcept; + constexpr Point operator+=(const geo::Point &p) noexcept; - constexpr Point operator-=(const common::Point &p) noexcept; + constexpr Point operator-=(const geo::Point &p) noexcept; - constexpr Point operator*=(const common::Point &p) noexcept; + constexpr Point operator*=(const geo::Point &p) noexcept; - constexpr Point operator/=(const common::Point &p) noexcept; + constexpr Point operator/=(const geo::Point &p) noexcept; constexpr Point operator+(int i) const noexcept; @@ -66,53 +66,53 @@ constexpr Point::Point(int x, int y) noexcept { this->y = y; } -constexpr Point Point::operator+(const common::Point &p) const noexcept { +constexpr Point Point::operator+(const geo::Point &p) const noexcept { auto out = *this; out.x += x; out.y += y; return p; } -constexpr Point Point::operator-(const common::Point &p) const noexcept { +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 common::Point &p) const noexcept { +constexpr Point Point::operator*(const geo::Point &p) const noexcept { auto out = *this; out.x *= x; out.y *= y; return p; } -constexpr Point Point::operator/(const common::Point &p) const noexcept { +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 common::Point &p) noexcept { +constexpr Point Point::operator+=(const geo::Point &p) noexcept { x += p.x; y += p.y; return *this; } -constexpr Point Point::operator-=(const common::Point &p) noexcept { +constexpr Point Point::operator-=(const geo::Point &p) noexcept { x -= p.x; y -= p.y; return *this; } -constexpr Point Point::operator*=(const common::Point &p) noexcept { +constexpr Point Point::operator*=(const geo::Point &p) noexcept { x *= p.x; y *= p.y; return *this; } -constexpr Point Point::operator/=(const common::Point &p) noexcept { +constexpr Point Point::operator/=(const geo::Point &p) noexcept { x /= p.x; y /= p.y; return *this; diff --git a/src/nostalgia/common/size.hpp b/src/nostalgia/geo/size.hpp similarity index 72% rename from src/nostalgia/common/size.hpp rename to src/nostalgia/geo/size.hpp index ae6345f1..67f14b1b 100644 --- a/src/nostalgia/common/size.hpp +++ b/src/nostalgia/geo/size.hpp @@ -6,11 +6,11 @@ #include -namespace nostalgia::common { +namespace nostalgia::geo { class Size { public: - static constexpr auto TypeName = "net.drinkingtea.nostalgia.common.Size"; + static constexpr auto TypeName = "net.drinkingtea.nostalgia.geo.Size"; static constexpr auto TypeVersion = 1; int width = 0; int height = 0; @@ -19,22 +19,22 @@ class Size { constexpr Size(int width, int height) noexcept; - constexpr Size operator+(common::Size p) const noexcept; + constexpr Size operator+(geo::Size p) const noexcept; - constexpr Size operator-(common::Size p) const noexcept; + constexpr Size operator-(geo::Size p) const noexcept; - constexpr Size operator*(common::Size p) const noexcept; + constexpr Size operator*(geo::Size p) const noexcept; - constexpr Size operator/(common::Size p) const noexcept; + constexpr Size operator/(geo::Size p) const noexcept; - constexpr Size operator+=(common::Size p) noexcept; + constexpr Size operator+=(geo::Size p) noexcept; - constexpr Size operator-=(common::Size p) noexcept; + constexpr Size operator-=(geo::Size p) noexcept; - constexpr Size operator*=(common::Size p) noexcept; + constexpr Size operator*=(geo::Size p) noexcept; - constexpr Size operator/=(common::Size p) noexcept; + constexpr Size operator/=(geo::Size p) noexcept; constexpr Size operator+(int i) const noexcept; @@ -66,51 +66,51 @@ constexpr Size::Size(int width, int height) noexcept { this->height = height; } -constexpr Size Size::operator+(common::Size p) const noexcept { +constexpr Size Size::operator+(geo::Size p) const noexcept { p.width += width; p.height += height; return p; } -constexpr Size Size::operator-(common::Size p) const noexcept { +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*(common::Size p) const noexcept { +constexpr Size Size::operator*(geo::Size p) const noexcept { p.width *= width; p.height *= height; return p; } -constexpr Size Size::operator/(common::Size p) const noexcept { +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+=(common::Size p) noexcept { +constexpr Size Size::operator+=(geo::Size p) noexcept { width += p.width; height += p.height; return *this; } -constexpr Size Size::operator-=(common::Size p) noexcept { +constexpr Size Size::operator-=(geo::Size p) noexcept { width -= p.width; height -= p.height; return *this; } -constexpr Size Size::operator*=(common::Size p) noexcept { +constexpr Size Size::operator*=(geo::Size p) noexcept { width *= p.width; height *= p.height; return *this; } -constexpr Size Size::operator/=(common::Size p) noexcept { +constexpr Size Size::operator/=(geo::Size p) noexcept { width /= p.width; height /= p.height; return *this; diff --git a/src/nostalgia/common/vec.cpp b/src/nostalgia/geo/vec.cpp similarity index 91% rename from src/nostalgia/common/vec.cpp rename to src/nostalgia/geo/vec.cpp index 731b2460..31d4a0c3 100644 --- a/src/nostalgia/common/vec.cpp +++ b/src/nostalgia/geo/vec.cpp @@ -6,7 +6,7 @@ #include "vec.hpp" -namespace nostalgia::common { +namespace nostalgia::geo { #ifndef OX_OS_BareMetal // doesn't compile in devKitPro for some reason static_assert([] { diff --git a/src/nostalgia/common/vec.hpp b/src/nostalgia/geo/vec.hpp similarity index 95% rename from src/nostalgia/common/vec.hpp rename to src/nostalgia/geo/vec.hpp index 943eda0a..37960557 100644 --- a/src/nostalgia/common/vec.hpp +++ b/src/nostalgia/geo/vec.hpp @@ -10,7 +10,7 @@ #include -namespace nostalgia::common { +namespace nostalgia::geo { struct Vec2 { float x = 0; diff --git a/src/nostalgia/studio/projectexplorer.cpp b/src/nostalgia/studio/projectexplorer.cpp index 729035f9..0c9dca04 100644 --- a/src/nostalgia/studio/projectexplorer.cpp +++ b/src/nostalgia/studio/projectexplorer.cpp @@ -6,7 +6,7 @@ #include -#include +#include #include "projectexplorer.hpp" diff --git a/src/nostalgia/world/world.cpp b/src/nostalgia/world/world.cpp index 8ce2a0cc..5bcf9421 100644 --- a/src/nostalgia/world/world.cpp +++ b/src/nostalgia/world/world.cpp @@ -6,7 +6,7 @@ namespace nostalgia::world { -using namespace common; +using namespace geo; using namespace core; ox::Error Zone::init(Context *ctx, Bounds bnds, ox::FileAddress tileSheet, ox::FileAddress palette) { diff --git a/src/nostalgia/world/world.hpp b/src/nostalgia/world/world.hpp index d535913f..88192289 100644 --- a/src/nostalgia/world/world.hpp +++ b/src/nostalgia/world/world.hpp @@ -7,8 +7,8 @@ #include #include -#include #include +#include namespace nostalgia::world { @@ -39,7 +39,7 @@ struct Zone { protected: static constexpr auto Fields = 2; - common::Bounds m_bounds; + geo::Bounds m_bounds; Tile *m_tiles = nullptr; public: @@ -47,7 +47,7 @@ struct Zone { ~Zone(); - ox::Error init(core::Context *ctx, common::Bounds bnds, ox::FileAddress tileSheet, ox::FileAddress palette = {}); + ox::Error init(core::Context *ctx, geo::Bounds bnds, ox::FileAddress tileSheet, ox::FileAddress palette = {}); void draw(core::Context *ctx);