[nostalgia] Add external palettes to tilesheet system

This commit is contained in:
2019-10-22 19:23:14 -05:00
parent fbdb48a1ee
commit 92103bfc41
31 changed files with 802 additions and 105 deletions

View File

@ -6,6 +6,10 @@ if(NOSTALGIA_BUILD_STUDIO)
set(CMAKE_AUTOMOC ON)
endif()
if(NOSTALGIA_BUILD_TYPE STREQUAL "Native")
find_package(SDL2 REQUIRED)
endif()
#project packages
add_subdirectory(core)

View File

@ -13,14 +13,14 @@ elseif(NOSTALGIA_BUILD_STUDIO)
set(
CPP
qt/gfx.cpp
#qt/gfx.cpp
userland/media.cpp
userland/mem.cpp
)
else()
set(
CPP
qt/gfx.cpp # does not currently use any Qt stuff, but will need to replace with SDL version
#qt/gfx.cpp # does not currently use any Qt stuff, but will need to replace with SDL version
userland/media.cpp
userland/mem.cpp
)
@ -32,12 +32,21 @@ add_library(
core.cpp
)
target_link_libraries(
NostalgiaCore PUBLIC
NostalgiaCommon
)
if(NOSTALGIA_BUILD_TYPE STREQUAL "Native")
add_subdirectory(sdl)
endif()
if(NOSTALGIA_BUILD_STUDIO)
add_subdirectory(studio)
endif()
install(
FILES
consts.hpp
core.hpp
gfx.hpp
media.hpp

View File

@ -0,0 +1,9 @@
#pragma once
namespace nostalgia::core {
constexpr auto FileExt_ng = ".ng";
constexpr auto FileExt_npal = ".npal";
}

View File

@ -10,6 +10,7 @@
#include <ox/fs/fs.hpp>
#include "consts.hpp"
#include "gfx.hpp"
#include "media.hpp"
#include "types.hpp"
@ -18,4 +19,6 @@ namespace nostalgia::core {
ox::Error init(Context *ctx);
ox::Error run();
}

View File

@ -16,9 +16,9 @@ typedef struct { uint32_t data[8]; } __attribute__((aligned(4))) Tile, Tile4;
// d-tile: double-sized tile (8bpp)
typedef struct { uint32_t data[16]; } __attribute__((aligned(4))) Tile8;
// tile block: 32x16 tiles, 16x16 d-tiles
typedef uint16_t Palette[256];
typedef Tile CharBlock[512];
typedef Tile8 CharBlock8[256];
using Palette = uint16_t[256];
using CharBlock = Tile[512];
using CharBlock8 = Tile8[256];
struct __attribute__((packed)) GbaImageDataHeader {
uint8_t bpp = 0;
@ -27,6 +27,7 @@ struct __attribute__((packed)) GbaImageDataHeader {
struct __attribute__((packed)) GbaImageData {
GbaImageDataHeader header;
uint8_t colors = 0; // colors in the palette
Palette __attribute__((packed)) pal = {};
uint8_t tiles[1];
};

View File

@ -204,7 +204,7 @@ ox::Error initConsole(Context*) {
return err;
}
ox::Error loadTileSheet(Context*, InodeId_t inode) {
ox::Error loadTileSheet(Context*, ox::FileAddress inode) {
ox::Error err(0);
const auto PaletteStart = sizeof(GbaImageDataHeader);
GbaImageDataHeader imgData;
@ -217,15 +217,15 @@ ox::Error loadTileSheet(Context*, InodeId_t inode) {
// load palette
err |= fs.read(inode, PaletteStart,
512, (uint16_t*) &MEM_PALLETE_BG[0], nullptr);
512, (uint16_t*) &MEM_PALLETE_BG[0], nullptr);
if (imgData.bpp == 4) {
err |= fs.read(inode, __builtin_offsetof(GbaImageData, tiles),
sizeof(Tile) * imgData.tileCount, (uint16_t*) &TILE_ADDR[0][1], nullptr);
sizeof(Tile) * imgData.tileCount, (uint16_t*) &TILE_ADDR[0][1], nullptr);
} else if (imgData.bpp == 8) {
REG_BG0CNT |= (1 << 7); // set to use 8 bits per pixel
err |= fs.read(inode, __builtin_offsetof(GbaImageData, tiles),
sizeof(Tile8) * imgData.tileCount, (uint16_t*) &TILE8_ADDR[0][1], nullptr);
sizeof(Tile8) * imgData.tileCount, (uint16_t*) &TILE8_ADDR[0][1], nullptr);
} else {
err = OxError(1);
}

View File

@ -15,11 +15,43 @@
namespace nostalgia::core {
using Color = uint16_t;
struct NostalgiaPalette {
static constexpr auto Fields = 1;
ox::Vector<Color> colors;
};
struct NostalgiaGraphic {
static constexpr auto Fields = 4;
uint8_t bpp = 0;
ox::FileAddress defaultPalette;
ox::Vector<Color> pal;
ox::Vector<uint8_t> tiles;
};
template<typename T>
ox::Error modelWrite(T *io, NostalgiaGraphic *ng) {
io->setTypeInfo("nostalgia::core::NostalgiaGraphic", NostalgiaGraphic::Fields);
oxReturnError(io->field("bpp", &ng->bpp));
oxReturnError(io->field("defaultPalette", &ng->defaultPalette));
oxReturnError(io->field("pal", &ng->pal));
oxReturnError(io->field("tiles", &ng->tiles));
return OxError(0);
}
template<typename T>
ox::Error modelWrite(T *io, NostalgiaPalette *pal) {
io->setTypeInfo("nostalgia::core::NostalgiaPalette", NostalgiaPalette::Fields);
oxReturnError(io->field("colors", &pal->colors));
return OxError(0);
}
ox::Error initGfx(Context *ctx);
ox::Error initConsole(Context *ctx);
ox::Error loadTileSheet(Context *ctx, InodeId_t inode);
ox::Error loadTileSheet(Context *ctx, ox::FileAddress file);
void puts(Context *ctx, int loc, const char *str);

View File

@ -0,0 +1,18 @@
add_library(
NostalgiaCore-Qt SHARED
gfx.cpp
)
target_link_libraries(
NostalgiaCore-Qt PUBLIC
NostalgiaStudio
OxFS
OxStd
)
install(
TARGETS
NostalgiaCore-Qt
LIBRARY DESTINATION
${NOSTALGIA_DIST_PLUGIN}
)

View File

@ -0,0 +1,19 @@
add_library(
NostalgiaCore-SDL
core.cpp
gfx.cpp
)
target_link_libraries(
NostalgiaCore-SDL PUBLIC
SDL2::Main
OxFS
OxStd
)
install(
TARGETS
NostalgiaCore-SDL
DESTINATION
${NOSTALGIA_DIST_PLUGIN}
)

View File

@ -0,0 +1,36 @@
/*
* Copyright 2016 - 2019 gtalent2@gmail.com
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <SDL.h>
#include <nostalgia/core/core.hpp>
namespace nostalgia::core {
ox::Error run() {
for (auto running = true; running;) {
SDL_Event event;
while (SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_KEYDOWN:
if (event.key.keysym.sym == SDLK_q) {
running = false;
}
break;
case SDL_QUIT: {
running = false;
break;
}
}
}
SDL_Delay(1);
}
return OxError(0);
}
}

View File

@ -0,0 +1,36 @@
/*
* Copyright 2016 - 2019 gtalent2@gmail.com
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <SDL.h>
#include "../gfx.hpp"
namespace nostalgia::core {
static SDL_Window *window = nullptr;
ox::Error initGfx(Context*) {
window = SDL_CreateWindow("nostalgia", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 1024, 768, SDL_WINDOW_SHOWN);
return OxError(window == nullptr);
}
ox::Error initConsole(Context*) {
return OxError(1);
}
ox::Error loadTileSheet(Context*, ox::FileAddress) {
return OxError(1);
}
void puts(Context*, int, const char*) {
}
void setTile(Context*, int, int, int, uint8_t) {
}
}

View File

@ -3,6 +3,7 @@ if(NOSTALGIA_BUILD_TYPE STREQUAL "Native")
add_library(
NostalgiaCore-Studio SHARED
import_tilesheet_wizard.cpp
new_tilesheet_wizard.cpp
plugin.cpp
)
endif()
@ -12,6 +13,7 @@ target_link_libraries(
Qt5::Core
Qt5::Widgets
NostalgiaStudio
NostalgiaPack
OxFS
OxStd
)

View File

@ -7,13 +7,21 @@
*/
#include <QBuffer>
#include <QDebug>
#include <QFile>
#include <nostalgia/core/consts.hpp>
#include <nostalgia/tools/pack/imgconv.hpp>
#include "import_tilesheet_wizard.hpp"
namespace nostalgia::core {
ImportTilesheetWizardPage::ImportTilesheetWizardPage(const studio::Context *ctx) {
static const auto PaletteOption_Bundle = QObject::tr("Bundle");
static const auto PaletteOption_New = QObject::tr("New");
static const auto PaletteOptions = QStringList{PaletteOption_Bundle, PaletteOption_New};
ImportTilesheetWizardMainPage::ImportTilesheetWizardMainPage(const studio::Context *ctx) {
m_ctx = ctx;
addLineEdit(tr("&Tile Sheet Name:"), QString(TileSheetName) + "*", "", [this](QString) {
auto importPath = field(ImportPath).toString();
@ -28,44 +36,52 @@ ImportTilesheetWizardPage::ImportTilesheetWizardPage(const studio::Context *ctx)
auto fileTypes = "(*.png);;(*.bmp);;(*.jpg);;(*.jpeg)";
addPathBrowse(tr("Tile Sheet &Path:"), QString(ImportPath) + "*", "",
QFileDialog::ExistingFile, fileTypes);
//addComboBox(tr("Bits Per Pixe&l:"), BPP, {tr("Auto"), "4", "8"});
addLineEdit(tr("Til&es:"), QString(TileCount), "");
}
int ImportTilesheetWizardPage::accept() {
auto tilesheetName = field(TileSheetName).toString();
auto importPath = field(ImportPath).toString();
QFile importFile(importPath);
if (importFile.exists()) {
return importImage(importFile, field(TileSheetName).toString());
} else {
return 1;
}
}
ImportTilesheetWizardPalettePage::ImportTilesheetWizardPalettePage(const studio::Context *ctx) {
m_ctx = ctx;
auto cb = addComboBox(tr("P&alette:"), Palette, PaletteOptions);
auto name = addLineEdit(tr("Palette &Name:"), PaletteName);
name->setDisabled(true);
int ImportTilesheetWizardPage::importImage(QFile &srcFile, QString tilesheetName) {
if (srcFile.exists()) {
srcFile.open(QIODevice::ReadOnly);
auto buff = srcFile.readAll();
QImage srcImg;
if (srcImg.loadFromData(buff)) {
int err = 0;
// ensure image is PNG
QByteArray out;
QBuffer outBuffer(&out);
outBuffer.open(QIODevice::WriteOnly);
srcImg.save(&outBuffer, "PNG");
// make sure tile sheet directory exists
m_ctx->project->mkdir(TileSheetDir);
// write image
err |= m_ctx->project->write(TileSheetDir + tilesheetName + ".png", reinterpret_cast<uint8_t*>(out.data()), out.size());
err |= m_ctx->project->saveRomFs();
return err;
} else {
return 1;
connect(cb, QOverload<int>::of(&QComboBox::currentIndexChanged), [name](int idx) {
if (idx == 1) {
name->setDisabled(false);
} else {
name->setDisabled(true);
}
}
} else {
return 2;
);
cb->setCurrentIndex(0);
}
int ImportTilesheetWizardPalettePage::accept() {
const auto tilesheetName = field(TileSheetName).toString();
const auto importPath = field(ImportPath).toString();
const auto tileCount = field(TileCount).toInt();
const auto palette = field(Palette).toInt();
const auto paletteName = field(PaletteName).toString();
const auto outPath = TileSheetDir + tilesheetName + FileExt_ng;
if (!QFile(importPath).exists()) {
return OxError(1);
}
auto ng = imgToNg(importPath, tileCount, 0);
if (!ng) {
return OxError(1);
}
if (palette != PaletteOptions.indexOf(PaletteOption_Bundle)) {
const auto outPath = PaletteDir + paletteName + FileExt_npal;
core::NostalgiaPalette pal;
pal.colors = std::move(ng->pal);
auto [buff, err] = toBuffer(&pal);
oxReturnError(err);
oxReturnError(m_ctx->project->write(outPath, buff.data(), buff.size()));
}
auto [buff, err] = toBuffer(ng.get());
oxReturnError(err);
oxReturnError(m_ctx->project->write(outPath, buff.data(), buff.size()));
return m_ctx->project->saveRomFs();
}
}

View File

@ -12,21 +12,32 @@
namespace nostalgia::core {
class ImportTilesheetWizardPage: public studio::WizardFormPage {
constexpr auto TileSheetDir = "/TileSheets/";
constexpr auto PaletteDir = "/Palettes/";
constexpr auto TileSheetName = "tilesheetName";
constexpr auto ImportPath = "importPath";
constexpr auto Palette = "palette";
constexpr auto PaletteName = "paletteName";
constexpr auto TileCount = "tileCount";
class ImportTilesheetWizardMainPage: public studio::WizardFormPage {
private:
static constexpr auto TileSheetDir = "/TileSheets/";
static constexpr auto TileSheetName = "projectName";
static constexpr auto ImportPath = "projectPath";
//static constexpr auto BPP = "bpp";
const studio::Context *m_ctx = nullptr;
public:
ImportTilesheetWizardPage(const studio::Context *args);
ImportTilesheetWizardMainPage(const studio::Context *args);
};
class ImportTilesheetWizardPalettePage: public studio::WizardFormPage {
private:
//static constexpr auto BPP = "bpp";
const studio::Context *m_ctx = nullptr;
public:
ImportTilesheetWizardPalettePage(const studio::Context *args);
int accept();
private:
int importImage(QFile &srcFile, QString dest);
};
}

View File

@ -0,0 +1,29 @@
/*
* Copyright 2016 - 2019 gtalent2@gmail.com
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <QBuffer>
#include <QFile>
#include "new_tilesheet_wizard.hpp"
namespace nostalgia::core {
NewTilesheetWizardPage::NewTilesheetWizardPage(const studio::Context *ctx) {
m_ctx = ctx;
addLineEdit(tr("&Tile Sheet Name:"), QString(TileSheetName) + "*", "", [](QString) {
return 0;
}
);
}
int NewTilesheetWizardPage::accept() {
auto tilesheetName = field(TileSheetName).toString();
return 0;
}
}

View File

@ -0,0 +1,29 @@
/*
* Copyright 2016 - 2019 gtalent2@gmail.com
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#pragma once
#include <nostalgia/studio/studio.hpp>
namespace nostalgia::core {
class NewTilesheetWizardPage: public studio::WizardFormPage {
private:
static constexpr auto TileSheetDir = "/TileSheets/";
static constexpr auto TileSheetName = "projectName";
const studio::Context *m_ctx = nullptr;
public:
NewTilesheetWizardPage(const studio::Context *args);
int accept();
private:
};
}

View File

@ -6,6 +6,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include "new_tilesheet_wizard.hpp"
#include "import_tilesheet_wizard.hpp"
#include "plugin.hpp"
@ -17,13 +18,27 @@ namespace nostalgia::core {
Plugin::Plugin() {
}
QVector<studio::WizardMaker> Plugin::importWizards(const studio::Context *args) {
QVector<studio::WizardMaker> Plugin::newWizards(const Context *ctx) {
return {
{
tr("Tile Sheet"),
[args]() {
[ctx]() {
QVector<QWizardPage*> pgs;
pgs.push_back(new ImportTilesheetWizardPage(args));
pgs.push_back(new NewTilesheetWizardPage(ctx));
return pgs;
}
}
};
}
QVector<studio::WizardMaker> Plugin::importWizards(const studio::Context *ctx) {
return {
{
tr("Tile Sheet"),
[ctx]() {
QVector<QWizardPage*> pgs;
pgs.push_back(new ImportTilesheetWizardMainPage(ctx));
pgs.push_back(new ImportTilesheetWizardPalettePage(ctx));
return pgs;
}
}

View File

@ -22,6 +22,8 @@ class Plugin: public QObject, studio::Plugin {
public:
Plugin();
QVector<studio::WizardMaker> newWizards(const studio::Context *ctx) override;
QVector<studio::WizardMaker> importWizards(const studio::Context *args) override;
};

View File

@ -6,11 +6,13 @@ if(NOSTALGIA_BUILD_TYPE STREQUAL "GBA")
main.cpp
startup.s
)
set(NOSTALGIA_PLAYER_DEPS "")
else()
add_executable(
nostalgia
main.cpp
)
set(NOSTALGIA_PLAYER_DEPS "NostalgiaCore-SDL")
endif()
if(COMMAND OBJCOPY_FILE)
@ -27,11 +29,8 @@ endif()
target_link_libraries(
nostalgia
NostalgiaWorld
NostalgiaCommon
NostalgiaCore
OxFS
OxStd
OxMetalClaw
${NOSTALGIA_PLAYER_DEPS}
)
add_custom_target("nostalgia.bin")

View File

@ -13,28 +13,27 @@ using namespace nostalgia::common;
using namespace nostalgia::core;
using namespace nostalgia::world;
int run() {
while(1);
ox::FileSystem32 fs(ox::FileStore32(loadRom(), 32 * ox::units::MB));
int run(ox::FileSystem *fs) {
Context ctx;
init(&ctx);
ctx.rom = &fs;
//Zone zone(&ctx, Bounds{0, 0, 40, 40}, 102);
//zone.draw(&ctx);
while (1);
ctx.rom = fs;
Zone zone(&ctx, Bounds{0, 0, 40, 40}, "/TileSheets/GeneralWorld");
zone.draw(&ctx);
run();
return 0;
}
#ifndef OX_USE_STDLIB
extern "C" void _start() {
run();
ox::FileSystem32 fs(ox::FileStore32(loadRom(), 32 * ox::units::MB));
run(&fs);
}
#else
int main() {
return run();
return run(nullptr);
}
#endif

View File

@ -0,0 +1,9 @@
_entry:
reset:
@ disable interrupts
@ cpsid if
@ vim:ft=arm

View File

@ -169,7 +169,7 @@ bool WizardFormPage::validatePage() {
return retval;
}
void WizardFormPage::addComboBox(QString displayName, QString fieldName, QVector<QString> options) {
QComboBox *WizardFormPage::addComboBox(QString displayName, QString fieldName, QStringList options) {
auto lbl = new QLabel(displayName, this);
auto cb = new QComboBox(this);
lbl->setBuddy(cb);
@ -199,9 +199,11 @@ void WizardFormPage::addComboBox(QString displayName, QString fieldName, QVector
);
m_currentLine++;
return cb;
}
void WizardFormPage::addLineEdit(QString displayName, QString fieldName, QString defaultVal, function<int(QString)> validator) {
QLineEdit *WizardFormPage::addLineEdit(QString displayName, QString fieldName, QString defaultVal, function<int(QString)> validator) {
auto lbl = new QLabel(displayName, this);
auto le = new QLineEdit(this);
lbl->setBuddy(le);
@ -229,6 +231,7 @@ void WizardFormPage::addLineEdit(QString displayName, QString fieldName, QString
);
m_currentLine++;
return le;
}
void WizardFormPage::addPathBrowse(QString displayName, QString fieldName, QString defaultVal,

View File

@ -10,10 +10,12 @@
#include <functional>
#include <QComboBox>
#include <QDir>
#include <QFileDialog>
#include <QGridLayout>
#include <QLabel>
#include <QLineEdit>
#include <QListWidget>
#include <QMap>
#include <QVector>
@ -86,9 +88,9 @@ class WizardFormPage: public QWizardPage {
bool validatePage() override;
void addComboBox(QString displayName, QString fieldName, QVector<QString> options);
QComboBox *addComboBox(QString displayName, QString fieldName, QStringList options);
void addLineEdit(QString displayName, QString fieldName,
QLineEdit *addLineEdit(QString displayName, QString fieldName,
QString defaultVal = "",
std::function<int(QString)> validator = [](QString) { return 0; });

View File

@ -56,28 +56,34 @@ namespace {
return colors.size();
}
[[nodiscard]] std::vector<char> pngToGba(QString argInPath, int argTiles, int argBpp) {
QImage src(argInPath);
[[nodiscard]] std::unique_ptr<core::NostalgiaGraphic> imgToNg(QString argSrc, int argTiles, int argBpp) {
constexpr auto TilePixels = 64;
QImage src(argSrc);
if (src.isNull()) {
return {};
}
const auto Pixels = argTiles ? argTiles * TilePixels : src.width() * src.height();
if (argTiles == 0) {
argTiles = (src.width() * src.height()) / 64;
argTiles = Pixels / 64;
}
const auto Colors = countColors(src, argTiles);
if (argBpp != 4 && argBpp != 8) {
argBpp = countColors(src, argTiles) > 16 ? 8 : 4;
argBpp = Colors > 16 ? 8 : 4;
}
QMap<QRgb, int> colors;
const auto imgDataBuffSize = sizeof(core::GbaImageData) + 1 + argTiles * 64;
std::vector<char> imgDataBuff(imgDataBuffSize);
auto id = new (imgDataBuff.data()) core::GbaImageData;
id->header.bpp = argBpp;
id->header.tileCount = argTiles;
int colorId = 0;
auto ng = std::make_unique<core::NostalgiaGraphic>();
ng->pal.resize(countColors(src, argTiles));
if (argBpp == 4) {
ng->tiles.resize(Pixels / 2);
} else {
ng->tiles.resize(Pixels);
}
ng->bpp = argBpp;
int colorIdx = 0;
// copy pixels as color ids
for (int x = 0; x < src.width(); x++) {
for (int y = 0; y < src.height(); y++) {
@ -86,18 +92,18 @@ namespace {
const auto c = src.pixel(x, y);
// assign color a color id for the palette
if (!colors.contains(c)) {
colors[c] = colorId;
colorId++;
colors[c] = colorIdx;
colorIdx++;
}
// set pixel color
if (argBpp == 4) {
if (destI % 2) { // is odd number pixel
id->tiles[destI / 2] |= colors[c] << 4;
ng->tiles[destI / 2] |= colors[c] << 4;
} else {
id->tiles[destI / 2] |= colors[c];
ng->tiles[destI / 2] |= colors[c];
}
} else {
id->tiles[destI] = colors[c];
ng->tiles[destI] = colors[c];
}
}
}
@ -106,10 +112,10 @@ namespace {
// store colors in palette with the corresponding color id
for (auto key : colors.keys()) {
auto colorId = colors[key];
id->pal[colorId] = toGbaColor(key);
ng->pal[colorId] = toGbaColor(key);
}
return imgDataBuff;
return ng;
}
}

View File

@ -11,8 +11,24 @@
#include <ox/std/error.hpp>
#include <ox/std/types.hpp>
#include <ox/mc/mc.hpp>
#include <nostalgia/core/gfx.hpp>
namespace nostalgia {
[[nodiscard]] std::vector<char> pngToGba(QString argInPath, int argTiles, int argBpp = -1);
template<typename T>
[[nodiscard]] ox::ValErr<std::vector<uint8_t>> toBuffer(T *data, std::size_t buffSize = ox::units::MB) {
std::vector<uint8_t> buff(buffSize);
std::size_t sz = 0;
oxReturnError(ox::writeMC(buff.data(), buff.size(), data, &sz));
if (sz > buffSize) {
return OxError(1);
}
buff.resize(sz);
return buff;
}
[[nodiscard]] std::unique_ptr<core::NostalgiaGraphic> imgToNg(QString argInPath, int argTiles, int argBpp = -1);
}

View File

@ -27,12 +27,12 @@ namespace {
* @return error
* stub for now
*/
[[nodiscard]] ox::Error pathToInode(std::vector<char>*) {
[[nodiscard]] ox::Error pathToInode(std::vector<uint8_t>*) {
return OxError(0);
}
// stub for now
[[nodiscard]] ox::Error toMetalClaw(std::vector<char>*) {
[[nodiscard]] ox::Error toMetalClaw(std::vector<uint8_t>*) {
return OxError(0);
}
@ -50,7 +50,7 @@ namespace {
// do transforms
if (endsWith(path, ".claw")) {
// load file
std::vector<char> buff(stat.size);
std::vector<uint8_t> buff(stat.size);
oxReturnError(dest->read(path.c_str(), buff.data(), buff.size()));
// do transformations
oxReturnError(pathToInode(&buff));
@ -63,8 +63,8 @@ namespace {
});
}
[[nodiscard]] ox::Error verifyFile(ox::FileSystem32 *fs, const std::string &path, const std::vector<char> &expected) noexcept {
std::vector<char> buff(expected.size());
[[nodiscard]] ox::Error verifyFile(ox::FileSystem32 *fs, const std::string &path, const std::vector<uint8_t> &expected) noexcept {
std::vector<uint8_t> buff(expected.size());
oxReturnError(fs->read(path.c_str(), buff.data(), buff.size()));
return OxError(buff == expected ? 0 : 1);
}
@ -81,15 +81,15 @@ namespace {
oxReturnError(dest->mkdir(currentFile.c_str(), true));
oxReturnError(copy(src, dest, currentFile + '/'));
} else {
std::vector<char> buff;
std::vector<uint8_t> buff;
// do transforms
constexpr std::string_view PngExt = ".png";
constexpr std::string_view GbagExt = ".ng";
if (endsWith(currentFile, PngExt)) {
const std::string OldExt = path.substr(path.find_last_of('.'));
constexpr std::string_view NgExt = ".ng";
if (OldExt != NgExt) {
// load file from full path and transform
const auto fullPath = src->basePath() + currentFile;
buff = pngToGba(fullPath.c_str(), 0, 0);
currentFile = currentFile.substr(0, currentFile.size() - PngExt.size()) + GbagExt.data();
oxReturnError(toBuffer(imgToNg(fullPath.c_str(), 0, 0).get()).get(&buff));
currentFile = currentFile.substr(0, currentFile.size() - OldExt.size()) + NgExt.data();
if (!buff.size()) {
return OxError(1);
}

View File

@ -4,6 +4,12 @@ add_library(
world.cpp
)
target_link_libraries(
NostalgiaWorld PUBLIC
NostalgiaCore
OxMetalClaw
)
#install(TARGETS NostalgiaCommon DESTINATION lib)
install(
FILES

View File

@ -13,7 +13,7 @@ namespace nostalgia::world {
using namespace common;
using namespace core;
Zone::Zone(Context *ctx, Bounds bnds, InodeId_t tileSheet) {
Zone::Zone(Context *ctx, Bounds bnds, ox::FileAddress tileSheet) {
const auto size = bnds.width * bnds.height;
m_tiles = new Tile[size];
m_bounds = bnds;

View File

@ -17,11 +17,10 @@
namespace nostalgia::world {
struct Tile {
static constexpr auto Fields = 3;
static constexpr auto Fields = 2;
uint8_t bgTile = 0;
uint8_t type = 0;
void *occupant = nullptr;
};
template<typename T>
@ -48,7 +47,7 @@ struct Zone {
Tile *m_tiles = nullptr;
public:
Zone(core::Context *ctx, common::Bounds bnds, core::InodeId_t tileSheet);
Zone(core::Context *ctx, common::Bounds bnds, ox::FileAddress tileSheet);
void draw(core::Context *ctx);