Compare commits
No commits in common. "696bae07212c626747edad22cff9d0b588cc0aea" and "3a149fad6de8872da4d8489cf944750a47bdca2d" have entirely different histories.
696bae0721
...
3a149fad6d
17
Makefile
17
Makefile
@ -1,12 +1,13 @@
|
||||
PROJECT_NAME=nostalgia
|
||||
BUILDCORE_PATH=deps/buildcore
|
||||
VCPKG_PKGS=sdl2 jsoncpp
|
||||
include ${BUILDCORE_PATH}/base.mk
|
||||
|
||||
ifeq ($(OS),darwin)
|
||||
NOSTALGIA_STUDIO=./build/${HOST}/${CURRENT_BUILD}/src/nostalgia/studio/nostalgia-studio.app/Contents/MacOS/nostalgia-studio
|
||||
NOSTALGIA_STUDIO=./dist/${CURRENT_BUILD}/nostalgia-studio.app/Contents/MacOS/nostalgia-studio
|
||||
MGBA=/Applications/mGBA.app/Contents/MacOS/mGBA
|
||||
else
|
||||
NOSTALGIA_STUDIO=./build/${HOST}/${CURRENT_BUILD}/src/nostalgia/studio/nostalgia-studio
|
||||
NOSTALGIA_STUDIO=./dist/${CURRENT_BUILD}/bin/nostalgia-studio
|
||||
MGBA=mgba-qt
|
||||
endif
|
||||
|
||||
@ -15,19 +16,19 @@ pkg-gba: install
|
||||
${ENV_RUN} ./scripts/pkg-gba sample_project
|
||||
|
||||
.PHONY: run
|
||||
run: build
|
||||
./build/${HOST}/${CURRENT_BUILD}/src/nostalgia/player/nostalgia sample_project
|
||||
run: install
|
||||
./dist/${CURRENT_BUILD}/bin/nostalgia sample_project
|
||||
.PHONY: run-studio
|
||||
run-studio: build
|
||||
run-studio: install
|
||||
${NOSTALGIA_STUDIO}
|
||||
.PHONY: gba-run
|
||||
gba-run: pkg-gba
|
||||
${MGBA} nostalgia.gba
|
||||
.PHONY: debug
|
||||
debug: build
|
||||
${DEBUGGER} ./build/${HOST}/${CURRENT_BUILD}/src/nostalgia/player/nostalgia sample_project
|
||||
debug: install
|
||||
${DEBUGGER} ./dist/${CURRENT_BUILD}/bin/nostalgia sample_project
|
||||
.PHONY: debug-studio
|
||||
debug-studio: build
|
||||
debug-studio: install
|
||||
${DEBUGGER} ${NOSTALGIA_STUDIO}
|
||||
|
||||
.PHONY: configure-gba
|
||||
|
@ -11,42 +11,36 @@
|
||||
namespace nostalgia::core {
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr std::size_t ptToIdx(int x, int y, int c, int scale = 1) noexcept {
|
||||
const auto tileWidth = TileWidth * scale;
|
||||
const auto tileHeight = TileHeight * scale;
|
||||
const auto pixelsPerTile = tileWidth * tileHeight;
|
||||
const auto colLength = static_cast<std::size_t>(pixelsPerTile);
|
||||
const auto rowLength = static_cast<std::size_t>(static_cast<std::size_t>(c / tileWidth) * colLength);
|
||||
const auto colStart = static_cast<std::size_t>(colLength * static_cast<std::size_t>(x / tileWidth));
|
||||
const auto rowStart = static_cast<std::size_t>(rowLength * static_cast<std::size_t>(y / tileHeight));
|
||||
const auto colOffset = static_cast<std::size_t>(x % tileWidth);
|
||||
const auto rowOffset = static_cast<std::size_t>(static_cast<std::size_t>((y % tileHeight) * tileHeight));
|
||||
constexpr std::size_t ptToIdx(int x, int y, int c) noexcept {
|
||||
constexpr auto colLength = static_cast<std::size_t>(PixelsPerTile);
|
||||
const auto rowLength = static_cast<std::size_t>(static_cast<std::size_t>(c / TileWidth) * colLength);
|
||||
const auto colStart = static_cast<std::size_t>(colLength * static_cast<std::size_t>(x / TileWidth));
|
||||
const auto rowStart = static_cast<std::size_t>(rowLength * static_cast<std::size_t>(y / TileHeight));
|
||||
const auto colOffset = static_cast<std::size_t>(x % TileWidth);
|
||||
const auto rowOffset = static_cast<std::size_t>(static_cast<std::size_t>(y % TileHeight) * TileHeight);
|
||||
return static_cast<std::size_t>(colStart + colOffset + rowStart + rowOffset);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr std::size_t ptToIdx(const ox::Point &pt, int c, int scale = 1) noexcept {
|
||||
return ptToIdx(pt.x, pt.y, c * TileWidth, scale);
|
||||
constexpr std::size_t ptToIdx(const ox::Point &pt, int c) noexcept {
|
||||
return ptToIdx(pt.x, pt.y, c * TileWidth);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr ox::Point idxToPt(int i, int c, int scale = 1) noexcept {
|
||||
const auto tileWidth = TileWidth * scale;
|
||||
const auto tileHeight = TileHeight * scale;
|
||||
const auto pixelsPerTile = tileWidth * tileHeight;
|
||||
constexpr ox::Point idxToPt(int i, int c) noexcept {
|
||||
// prevent divide by zeros
|
||||
if (!c) {
|
||||
++c;
|
||||
}
|
||||
const auto t = i / pixelsPerTile; // tile number
|
||||
const auto iti = i % pixelsPerTile; // in tile index
|
||||
const auto t = i / PixelsPerTile; // tile number
|
||||
const auto iti = i % PixelsPerTile; // in tile index
|
||||
const auto tc = t % c; // tile column
|
||||
const auto tr = t / c; // tile row
|
||||
const auto itx = iti % tileWidth; // in tile x
|
||||
const auto ity = iti / tileHeight; // in tile y
|
||||
const auto itx = iti % TileWidth; // in tile x
|
||||
const auto ity = iti / TileHeight; // in tile y
|
||||
return {
|
||||
itx + tc * tileWidth,
|
||||
ity + tr * tileHeight,
|
||||
itx + tc * TileWidth,
|
||||
ity + tr * TileHeight,
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -565,9 +565,4 @@ oxModelBegin(CompactTileSheet)
|
||||
oxModelField(pixels)
|
||||
oxModelEnd()
|
||||
|
||||
ox::Vector<uint32_t> resizeTileSheetData(
|
||||
ox::Vector<uint32_t> const&srcPixels,
|
||||
ox::Size const&srcSize,
|
||||
int scale = 2) noexcept;
|
||||
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
add_library(
|
||||
NostalgiaCore
|
||||
gfx.cpp
|
||||
tilesheet.cpp
|
||||
)
|
||||
|
||||
add_subdirectory(gba)
|
||||
|
@ -148,9 +148,8 @@ ox::Error loadSpriteTileSheet(
|
||||
const ox::FileAddress &tilesheetAddr,
|
||||
const ox::FileAddress &paletteAddr) noexcept {
|
||||
auto &gctx = static_cast<GbaContext&>(*ctx);
|
||||
auto &rom = static_cast<const ox::MemFS&>(gctx.rom());
|
||||
oxRequire(tsStat, gctx.rom().stat(tilesheetAddr));
|
||||
oxRequire(ts, rom.directAccess(tilesheetAddr));
|
||||
oxRequire(ts, static_cast<const ox::MemFS&>(gctx.rom()).directAccess(tilesheetAddr));
|
||||
GbaTileMapTarget target;
|
||||
target.pal.palette = MEM_SPRITE_PALETTE;
|
||||
target.tileMap = MEM_SPRITE_TILES;
|
||||
@ -158,7 +157,7 @@ ox::Error loadSpriteTileSheet(
|
||||
// load external palette if available
|
||||
if (paletteAddr) {
|
||||
oxRequire(palStat, gctx.rom().stat(paletteAddr));
|
||||
oxRequire(pal, rom.directAccess(paletteAddr));
|
||||
oxRequire(pal, static_cast<const ox::MemFS&>(gctx.rom()).directAccess(paletteAddr));
|
||||
oxReturnError(ox::readMC(pal, static_cast<std::size_t>(palStat.size), &target.pal));
|
||||
}
|
||||
return {};
|
||||
@ -166,11 +165,10 @@ ox::Error loadSpriteTileSheet(
|
||||
|
||||
ox::Error loadBgPalette(Context *ctx, unsigned, const ox::FileAddress &paletteAddr) noexcept {
|
||||
auto &gctx = static_cast<GbaContext&>(*ctx);
|
||||
auto &rom = static_cast<const ox::MemFS&>(gctx.rom());
|
||||
GbaPaletteTarget target;
|
||||
target.palette = MEM_BG_PALETTE;
|
||||
oxRequire(palStat, gctx.rom().stat(paletteAddr));
|
||||
oxRequire(pal, rom.directAccess(paletteAddr));
|
||||
oxRequire(pal, static_cast<const ox::MemFS&>(gctx.rom()).directAccess(paletteAddr));
|
||||
oxReturnError(ox::readMC(pal, static_cast<std::size_t>(palStat.size), &target));
|
||||
return {};
|
||||
}
|
||||
|
@ -289,11 +289,9 @@ void TileSheetEditorImGui::drawTileSheet(const ox::Vec2 &fbSize) noexcept {
|
||||
glViewport(0, 0, fbSizei.width, fbSizei.height);
|
||||
m_tileSheetEditor.draw();
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
ImTextureID buffId{};
|
||||
static_assert(sizeof(ImTextureID) >= sizeof(m_framebuffer.color.id));
|
||||
memcpy(&buffId, &m_framebuffer.color.id, sizeof(m_framebuffer.color.id));
|
||||
const uintptr_t buffId = m_framebuffer.color.id;
|
||||
ImGui::Image(
|
||||
buffId,
|
||||
reinterpret_cast<void*>(buffId),
|
||||
static_cast<ImVec2>(fbSize),
|
||||
ImVec2(0, 1),
|
||||
ImVec2(1, 0));
|
||||
|
@ -1,28 +0,0 @@
|
||||
|
||||
#include <ox/std/size.hpp>
|
||||
#include <ox/std/vector.hpp>
|
||||
|
||||
#include <nostalgia/core/ptidxconv.hpp>
|
||||
|
||||
namespace nostalgia::core {
|
||||
|
||||
ox::Vector<uint32_t> resizeTileSheetData(
|
||||
ox::Vector<uint32_t> const&srcPixels,
|
||||
ox::Size const&srcSize,
|
||||
int scale = 2) noexcept {
|
||||
ox::Vector<uint32_t> dst;
|
||||
auto dstWidth = srcSize.width * scale;
|
||||
auto dstHeight = srcSize.height * scale;
|
||||
const auto pixelCnt = dstWidth * dstHeight;
|
||||
dst.resize(static_cast<std::size_t>(pixelCnt));
|
||||
for (auto i = 0; i < pixelCnt; ++i) {
|
||||
const auto dstPt = idxToPt(i, 1, scale);
|
||||
const auto srcPt = dstPt / ox::Point{scale, scale};
|
||||
const auto srcIdx = ptToIdx(srcPt, 1);
|
||||
const auto srcPixel = srcPixels[srcIdx];
|
||||
dst[static_cast<std::size_t>(i)] = srcPixel;
|
||||
}
|
||||
return dst;
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user