[nostalgia] Rename common package to geo
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <ox/std/types.hpp>
|
||||
#include <nostalgia/common/point.hpp>
|
||||
#include <nostalgia/geo/point.hpp>
|
||||
|
||||
#include "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;
|
||||
|
||||
@@ -108,7 +108,7 @@ int getScreenHeight(Context*) noexcept {
|
||||
return 160;
|
||||
}
|
||||
|
||||
common::Size getScreenSize(Context*) noexcept {
|
||||
geo::Size getScreenSize(Context*) noexcept {
|
||||
return {240, 160};
|
||||
}
|
||||
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
|
||||
#include <ox/std/types.hpp>
|
||||
#include <ox/model/def.hpp>
|
||||
#include <nostalgia/common/point.hpp>
|
||||
#include <nostalgia/common/size.hpp>
|
||||
#include <nostalgia/geo/point.hpp>
|
||||
#include <nostalgia/geo/size.hpp>
|
||||
|
||||
#include "color.hpp"
|
||||
#include "context.hpp"
|
||||
@@ -47,7 +47,7 @@ struct NostalgiaGraphic {
|
||||
ox::Vector<uint8_t> 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;
|
||||
|
||||
@@ -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<GlfwImplData>();
|
||||
int w = 0, h = 0;
|
||||
glfwGetFramebufferSize(id->window, &w, &h);
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <nostalgia/common/point.hpp>
|
||||
#include <nostalgia/geo/point.hpp>
|
||||
|
||||
#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});
|
||||
|
||||
}
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
|
||||
#include <imgui.h>
|
||||
|
||||
#include <nostalgia/common/point.hpp>
|
||||
#include <nostalgia/core/media.hpp>
|
||||
#include <nostalgia/geo/point.hpp>
|
||||
|
||||
#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<int>(fbSize.x), static_cast<int>(fbSize.y));
|
||||
void TileSheetEditorImGui::drawTileSheet(const geo::Vec2 &fbSize) noexcept {
|
||||
const auto fbSizei = geo::Size(static_cast<int>(fbSize.x), static_cast<int>(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;
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
|
||||
#include <ox/model/def.hpp>
|
||||
|
||||
#include <nostalgia/common/bounds.hpp>
|
||||
#include <nostalgia/common/vec.hpp>
|
||||
#include <nostalgia/geo/bounds.hpp>
|
||||
#include <nostalgia/geo/vec.hpp>
|
||||
#include <nostalgia/core/gfx.hpp>
|
||||
#include <nostalgia/glutils/glutils.hpp>
|
||||
#include <nostalgia/studio/studio.hpp>
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <nostalgia/common/point.hpp>
|
||||
#include <nostalgia/geo/point.hpp>
|
||||
#include <nostalgia/core/consts.hpp>
|
||||
#include <nostalgia/core/media.hpp>
|
||||
#include <nostalgia/core/ptidxconv.hpp>
|
||||
@@ -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<float>(m_img.columns) * TileWidth,
|
||||
pixelSize.y * static_cast<float>(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<float>(m_img.columns) * TileWidth,
|
||||
pixelSize.y * static_cast<float>(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<int>(x * 2), static_cast<int>(y * 2));
|
||||
const auto pt = geo::Point(static_cast<int>(x * 2), static_cast<int>(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);
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
|
||||
#include <ox/model/def.hpp>
|
||||
|
||||
#include <nostalgia/common/bounds.hpp>
|
||||
#include <nostalgia/common/vec.hpp>
|
||||
#include <nostalgia/geo/bounds.hpp>
|
||||
#include <nostalgia/geo/vec.hpp>
|
||||
#include <nostalgia/core/gfx.hpp>
|
||||
#include <nostalgia/glutils/glutils.hpp>
|
||||
#include <nostalgia/studio/studio.hpp>
|
||||
@@ -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<int> 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<int> *tgt, int tgtColumns) const;
|
||||
void pastePixels(const geo::Point &pt, ox::Vector<int> *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<NostalgiaPalette> 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();
|
||||
|
||||
@@ -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<void*>(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<float>(pt1.x) * pixSize.x - 1.f;
|
||||
const auto y1 = 1.f - static_cast<float>(pt1.y) * pixSize.y;
|
||||
const auto x2 = static_cast<float>(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;
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <nostalgia/common/point.hpp>
|
||||
#include <nostalgia/common/vec.hpp>
|
||||
#include <nostalgia/core/gfx.hpp>
|
||||
#include <nostalgia/geo/point.hpp>
|
||||
#include <nostalgia/geo/vec.hpp>
|
||||
#include <nostalgia/glutils/glutils.hpp>
|
||||
#include <nostalgia/studio/studio.hpp>
|
||||
|
||||
@@ -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;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -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<GLsizei>(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<void*>(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<int>(i), img.columns);
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <nostalgia/common/vec.hpp>
|
||||
#include <nostalgia/core/gfx.hpp>
|
||||
#include <nostalgia/geo/vec.hpp>
|
||||
#include <nostalgia/glutils/glutils.hpp>
|
||||
#include <nostalgia/studio/studio.hpp>
|
||||
|
||||
@@ -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;
|
||||
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user