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