[nostalgia] Replace C strings with ox::StringView
This commit is contained in:
parent
55ea405a54
commit
679226ef73
@ -14,7 +14,7 @@ namespace nostalgia::core {
|
|||||||
|
|
||||||
ox::String getClipboardText(class Context *ctx) noexcept;
|
ox::String getClipboardText(class Context *ctx) noexcept;
|
||||||
|
|
||||||
void setClipboardText(class Context *ctx, const ox::String &text) noexcept;
|
void setClipboardText(class Context *ctx, ox::CRStringView text) noexcept;
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void setClipboardObject([[maybe_unused]] class Context *ctx, [[maybe_unused]] ox::UniquePtr<T> obj) noexcept {
|
void setClipboardObject([[maybe_unused]] class Context *ctx, [[maybe_unused]] ox::UniquePtr<T> obj) noexcept {
|
||||||
|
@ -63,7 +63,7 @@ class Context {
|
|||||||
const ox::FileAddress &palettePath) noexcept;
|
const ox::FileAddress &palettePath) noexcept;
|
||||||
friend ox::Error run(Context *ctx) noexcept;
|
friend ox::Error run(Context *ctx) noexcept;
|
||||||
friend void shutdown(Context *ctx) noexcept;
|
friend void shutdown(Context *ctx) noexcept;
|
||||||
friend ox::Result<ox::UniquePtr<Context>> init(ox::UniquePtr<ox::FileSystem> fs, const char *appName) noexcept;
|
friend ox::Result<ox::UniquePtr<Context>> init(ox::UniquePtr<ox::FileSystem> fs, ox::CRStringView appName) noexcept;
|
||||||
friend ox::String getClipboardText(Context *ctx) noexcept;
|
friend ox::String getClipboardText(Context *ctx) noexcept;
|
||||||
friend uint64_t ticksMs(Context *ctx) noexcept;
|
friend uint64_t ticksMs(Context *ctx) noexcept;
|
||||||
friend uint8_t bgStatus(Context *ctx) noexcept;
|
friend uint8_t bgStatus(Context *ctx) noexcept;
|
||||||
@ -73,17 +73,15 @@ class Context {
|
|||||||
friend void setBgCbb(Context *ctx, unsigned bgIdx, unsigned cbb) noexcept;
|
friend void setBgCbb(Context *ctx, unsigned bgIdx, unsigned cbb) noexcept;
|
||||||
friend void setBgStatus(Context *ctx, uint32_t status) noexcept;
|
friend void setBgStatus(Context *ctx, uint32_t status) noexcept;
|
||||||
friend void setBgStatus(Context *ctx, unsigned bg, bool status) noexcept;
|
friend void setBgStatus(Context *ctx, unsigned bg, bool status) noexcept;
|
||||||
friend void setClipboardText(Context *ctx, const ox::String &text) noexcept;
|
|
||||||
friend void setUpdateHandler(Context *ctx, UpdateHandler h) noexcept;
|
friend void setUpdateHandler(Context *ctx, UpdateHandler h) noexcept;
|
||||||
friend constexpr void setKeyEventHandler(Context *ctx, KeyEventHandler h) noexcept;
|
friend constexpr void setKeyEventHandler(Context *ctx, KeyEventHandler h) noexcept;
|
||||||
friend constexpr KeyEventHandler keyEventHandler(Context *ctx) noexcept;
|
friend constexpr KeyEventHandler keyEventHandler(Context *ctx) noexcept;
|
||||||
friend void setTile(Context *ctx, unsigned bgIdx, int column, int row, uint8_t tile) noexcept;
|
friend void setTile(Context *ctx, unsigned bgIdx, int column, int row, uint8_t tile) noexcept;
|
||||||
friend void setWindowTitle(Context *ctx, const char *title) noexcept;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ox::UniquePtr<ox::FileSystem> rom;
|
ox::UniquePtr<ox::FileSystem> rom;
|
||||||
ox::Vector<Drawer*, 5> drawers;
|
ox::Vector<Drawer*, 5> drawers;
|
||||||
const char *appName = "Nostalgia";
|
ox::StringView appName = "Nostalgia";
|
||||||
|
|
||||||
#ifndef OX_BARE_METAL
|
#ifndef OX_BARE_METAL
|
||||||
AssetManager assetManager;
|
AssetManager assetManager;
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
namespace nostalgia::core {
|
namespace nostalgia::core {
|
||||||
|
|
||||||
ox::Result<ox::UniquePtr<Context>> init(ox::UniquePtr<ox::FileSystem> fs, const char *appName = "Nostalgia") noexcept;
|
ox::Result<ox::UniquePtr<Context>> init(ox::UniquePtr<ox::FileSystem> fs, ox::CRStringView appName = "Nostalgia") noexcept;
|
||||||
|
|
||||||
ox::Error run(Context *ctx) noexcept;
|
ox::Error run(Context *ctx) noexcept;
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@ static ox::Result<std::size_t> findPreloadSection() noexcept {
|
|||||||
return OxError(1);
|
return OxError(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
ox::Result<ox::UniquePtr<Context>> init(ox::UniquePtr<ox::FileSystem> fs, const char *appName) noexcept {
|
ox::Result<ox::UniquePtr<Context>> init(ox::UniquePtr<ox::FileSystem> fs, ox::CRStringView appName) noexcept {
|
||||||
auto ctx = ox::make_unique<Context>();
|
auto ctx = ox::make_unique<Context>();
|
||||||
ctx->rom = std::move(fs);
|
ctx->rom = std::move(fs);
|
||||||
ctx->appName = appName;
|
ctx->appName = appName;
|
||||||
|
@ -85,7 +85,7 @@ ox::Error shutdownGfx(Context*) noexcept {
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
void setWindowTitle(Context*, const char*) noexcept {
|
void setWindowTitle(Context*, ox::CRStringView) noexcept {
|
||||||
}
|
}
|
||||||
|
|
||||||
void focusWindow(Context*) noexcept {
|
void focusWindow(Context*) noexcept {
|
||||||
@ -210,10 +210,11 @@ ox::Error loadSpritePalette(Context *ctx, unsigned cbb, const ox::FileAddress &p
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Do NOT use Context in the GBA version of this function.
|
// Do NOT use Context in the GBA version of this function.
|
||||||
void puts(Context *ctx, int column, int row, const char *str) noexcept {
|
void puts(Context *ctx, int column, int row, ox::CRStringView str) noexcept {
|
||||||
for (int i = 0; str[i]; i++) {
|
const auto col = static_cast<unsigned>(column);
|
||||||
|
for (auto i = 0u; i < str.bytes(); i++) {
|
||||||
const auto c = charMap[static_cast<unsigned>(str[i])];
|
const auto c = charMap[static_cast<unsigned>(str[i])];
|
||||||
setTile(ctx, 0, column + i, row, static_cast<uint8_t>(c));
|
setTile(ctx, 0, static_cast<int>(col + i), row, static_cast<uint8_t>(c));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
namespace nostalgia::core {
|
namespace nostalgia::core {
|
||||||
|
|
||||||
ox::Result<char*> loadRom(const char*) noexcept {
|
ox::Result<char*> loadRom(ox::CRStringView) noexcept {
|
||||||
// put the header in the wrong order to prevent mistaking this code for the
|
// put the header in the wrong order to prevent mistaking this code for the
|
||||||
// media section
|
// media section
|
||||||
constexpr auto headerP2 = "HEADER__________";
|
constexpr auto headerP2 = "HEADER__________";
|
||||||
|
@ -27,7 +27,7 @@ void panic(const char*, int, const char *msg, const ox::Error &err) noexcept {
|
|||||||
puts(nullptr, 32 + 1, 4, "UNEXPECTED STATE:");
|
puts(nullptr, 32 + 1, 4, "UNEXPECTED STATE:");
|
||||||
puts(nullptr, 32 + 2, 6, msg);
|
puts(nullptr, 32 + 2, 6, msg);
|
||||||
if (err) {
|
if (err) {
|
||||||
puts(nullptr, 32 + 2, 8, serr.c_str());
|
puts(nullptr, 32 + 2, 8, serr);
|
||||||
}
|
}
|
||||||
puts(nullptr, 32 + 1, 15, "PLEASE RESTART THE SYSTEM");
|
puts(nullptr, 32 + 1, 15, "PLEASE RESTART THE SYSTEM");
|
||||||
// disable all interrupt handling and IntrWait on no interrupts
|
// disable all interrupt handling and IntrWait on no interrupts
|
||||||
|
@ -93,11 +93,11 @@ struct TileSheet {
|
|||||||
other.columns = 0;
|
other.columns = 0;
|
||||||
other.rows = 0;
|
other.rows = 0;
|
||||||
}
|
}
|
||||||
constexpr SubSheet(const char *pName, int pColumns, int pRows, int bpp) noexcept:
|
constexpr SubSheet(ox::CRStringView pName, int pColumns, int pRows, int bpp) noexcept:
|
||||||
name(pName), columns(pColumns), rows(pRows),
|
name(pName), columns(pColumns), rows(pRows),
|
||||||
pixels(static_cast<std::size_t>(columns * rows * PixelsPerTile) / (bpp == 4 ? 2u : 1u)) {
|
pixels(static_cast<std::size_t>(columns * rows * PixelsPerTile) / (bpp == 4 ? 2u : 1u)) {
|
||||||
}
|
}
|
||||||
constexpr SubSheet(const char *pName, int pColumns, int pRows, ox::Vector<uint8_t> pPixels) noexcept:
|
constexpr SubSheet(ox::CRStringView pName, int pColumns, int pRows, ox::Vector<uint8_t> pPixels) noexcept:
|
||||||
name(pName), columns(pColumns), rows(pRows), pixels(std::move(pPixels)) {
|
name(pName), columns(pColumns), rows(pRows), pixels(std::move(pPixels)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -375,7 +375,7 @@ struct TileSheet {
|
|||||||
constexpr ox::Error addSubSheet(const SubSheetIdx &idx) noexcept {
|
constexpr ox::Error addSubSheet(const SubSheetIdx &idx) noexcept {
|
||||||
auto &parent = getSubSheet(idx);
|
auto &parent = getSubSheet(idx);
|
||||||
if (parent.subsheets.size() < 2) {
|
if (parent.subsheets.size() < 2) {
|
||||||
parent.subsheets.emplace_back(ox::sfmt("Subsheet {}", parent.subsheets.size()).c_str(), 1, 1, bpp);
|
parent.subsheets.emplace_back(ox::sfmt("Subsheet {}", parent.subsheets.size()), 1, 1, bpp);
|
||||||
} else {
|
} else {
|
||||||
parent.subsheets.emplace_back("Subsheet 0", parent.columns, parent.rows, bpp);
|
parent.subsheets.emplace_back("Subsheet 0", parent.columns, parent.rows, bpp);
|
||||||
parent.subsheets.emplace_back("Subsheet 1", 1, 1, bpp);
|
parent.subsheets.emplace_back("Subsheet 1", 1, 1, bpp);
|
||||||
@ -482,7 +482,7 @@ void addCustomDrawer(Context *ctx, Drawer *cd) noexcept;
|
|||||||
|
|
||||||
void removeCustomDrawer(Context *ctx, Drawer *cd) noexcept;
|
void removeCustomDrawer(Context *ctx, Drawer *cd) noexcept;
|
||||||
|
|
||||||
void setWindowTitle(Context *ctx, const char *title) noexcept;
|
void setWindowTitle(Context *ctx, ox::CRStringView title) noexcept;
|
||||||
|
|
||||||
void focusWindow(Context *ctx) noexcept;
|
void focusWindow(Context *ctx) noexcept;
|
||||||
|
|
||||||
@ -518,7 +518,7 @@ ox::Error loadSpriteTileSheet(Context *ctx,
|
|||||||
const ox::FileAddress &tilesheetAddr,
|
const ox::FileAddress &tilesheetAddr,
|
||||||
const ox::FileAddress &paletteAddr) noexcept;
|
const ox::FileAddress &paletteAddr) noexcept;
|
||||||
|
|
||||||
void puts(Context *ctx, int column, int row, const char *str) noexcept;
|
void puts(Context *ctx, int column, int row, ox::CRStringView str) noexcept;
|
||||||
|
|
||||||
void setTile(Context *ctx, unsigned bgIdx, int column, int row, uint8_t tile) noexcept;
|
void setTile(Context *ctx, unsigned bgIdx, int column, int row, uint8_t tile) noexcept;
|
||||||
|
|
||||||
|
@ -17,9 +17,11 @@ ox::String getClipboardText(Context *ctx) noexcept {
|
|||||||
return glfwGetClipboardString(id->window);
|
return glfwGetClipboardString(id->window);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setClipboardText(Context *ctx, const ox::String &text) noexcept {
|
void setClipboardText(Context *ctx, ox::CRStringView text) noexcept {
|
||||||
const auto id = ctx->windowerData<GlfwImplData>();
|
const auto id = ctx->windowerData<GlfwImplData>();
|
||||||
glfwSetClipboardString(id->window, text.c_str());
|
auto cstr = ox_malloca(text.bytes() + 1, char);
|
||||||
|
ox_strncpy(cstr.get(), text.data(), text.bytes());
|
||||||
|
glfwSetClipboardString(id->window, cstr);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
|
|
||||||
namespace nostalgia::core {
|
namespace nostalgia::core {
|
||||||
|
|
||||||
ox::Result<ox::UniquePtr<Context>> init(ox::UniquePtr<ox::FileSystem> fs, const char *appName) noexcept {
|
ox::Result<ox::UniquePtr<Context>> init(ox::UniquePtr<ox::FileSystem> fs, ox::CRStringView appName) noexcept {
|
||||||
auto ctx = ox::make_unique<Context>();
|
auto ctx = ox::make_unique<Context>();
|
||||||
ctx->rom = std::move(fs);
|
ctx->rom = std::move(fs);
|
||||||
ctx->appName = appName;
|
ctx->appName = appName;
|
||||||
|
@ -192,7 +192,9 @@ ox::Error initGfx(Context *ctx) noexcept {
|
|||||||
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GLFW_TRUE);
|
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GLFW_TRUE);
|
||||||
}
|
}
|
||||||
glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE);
|
glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE);
|
||||||
id->window = glfwCreateWindow(240 * Scale, 160 * Scale, ctx->appName, nullptr, nullptr);
|
auto cstr = ox_malloca(ctx->appName.bytes() + 1, char);
|
||||||
|
ox_strncpy(cstr.get(), ctx->appName.data(), ctx->appName.bytes());
|
||||||
|
id->window = glfwCreateWindow(240 * Scale, 160 * Scale, cstr, nullptr, nullptr);
|
||||||
if (id->window == nullptr) {
|
if (id->window == nullptr) {
|
||||||
return OxError(1, "Could not open GLFW window");
|
return OxError(1, "Could not open GLFW window");
|
||||||
}
|
}
|
||||||
@ -220,9 +222,11 @@ ox::Error initGfx(Context *ctx) noexcept {
|
|||||||
return OxError(0);
|
return OxError(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setWindowTitle(Context *ctx, const char *title) noexcept {
|
void setWindowTitle(Context *ctx, ox::CRStringView title) noexcept {
|
||||||
const auto id = ctx->windowerData<GlfwImplData>();
|
const auto id = ctx->windowerData<GlfwImplData>();
|
||||||
glfwSetWindowTitle(id->window, title);
|
auto cstr = ox_malloca(title.bytes() + 1, char);
|
||||||
|
ox_strncpy(cstr.get(), title.data(), title.bytes());
|
||||||
|
glfwSetWindowTitle(id->window, cstr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void focusWindow(Context *ctx) noexcept {
|
void focusWindow(Context *ctx) noexcept {
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
namespace nostalgia::core {
|
namespace nostalgia::core {
|
||||||
|
|
||||||
ox::Result<ox::UniquePtr<Context>> init(ox::UniquePtr<ox::FileSystem>, const char*) noexcept {
|
ox::Result<ox::UniquePtr<Context>> init(ox::UniquePtr<ox::FileSystem>, ox::CRStringView) noexcept {
|
||||||
return OxError(1);
|
return OxError(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ ox::Error shutdownGfx(Context*) noexcept {
|
|||||||
return OxError(0);
|
return OxError(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setWindowTitle(Context*, const char*) noexcept {
|
void setWindowTitle(Context*, ox::CRStringView) noexcept {
|
||||||
}
|
}
|
||||||
|
|
||||||
void focusWindow(Context*) noexcept {
|
void focusWindow(Context*) noexcept {
|
||||||
@ -75,7 +75,7 @@ ox::Error loadSpritePalette(Context*, int, const ox::FileAddress&) noexcept {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Do NOT use Context in the GBA version of this function.
|
// Do NOT use Context in the GBA version of this function.
|
||||||
void puts(Context*, int, int, const char*) noexcept {
|
void puts(Context*, int, int, ox::CRStringView) noexcept {
|
||||||
}
|
}
|
||||||
|
|
||||||
void setTile(Context*, int, int, int, uint8_t) noexcept {
|
void setTile(Context*, int, int, int, uint8_t) noexcept {
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
namespace nostalgia::core {
|
namespace nostalgia::core {
|
||||||
|
|
||||||
ox::Result<char*> loadRom(const char*) noexcept {
|
ox::Result<char*> loadRom(ox::CRStringView) noexcept {
|
||||||
return OxError(1);
|
return OxError(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,9 +6,9 @@
|
|||||||
|
|
||||||
namespace nostalgia::core {
|
namespace nostalgia::core {
|
||||||
|
|
||||||
ox::Result<ox::UniquePtr<ox::FileSystem>> loadRomFs(const char *path) noexcept {
|
ox::Result<ox::UniquePtr<ox::FileSystem>> loadRomFs(ox::CRStringView path) noexcept {
|
||||||
const auto lastDot = ox_lastIndexOf(path, '.');
|
const auto lastDot = ox_lastIndexOf(path, '.');
|
||||||
const auto fsExt = lastDot != -1 ? path + lastDot : "";
|
const auto fsExt = lastDot != -1 ? path.substr(static_cast<std::size_t>(lastDot)) : "";
|
||||||
if (ox_strcmp(fsExt, ".oxfs") == 0) {
|
if (ox_strcmp(fsExt, ".oxfs") == 0) {
|
||||||
oxRequire(rom, core::loadRom(path));
|
oxRequire(rom, core::loadRom(path));
|
||||||
return {ox::make_unique<ox::FileSystem32>(rom, 32 * ox::units::MB, unloadRom)};
|
return {ox::make_unique<ox::FileSystem32>(rom, 32 * ox::units::MB, unloadRom)};
|
||||||
|
@ -89,9 +89,9 @@ ox::Error writeObj(Context *ctx, const ox::FileAddress &file, const T &obj,
|
|||||||
return ctx->rom->write(file, objBuff.data(), objBuff.size());
|
return ctx->rom->write(file, objBuff.data(), objBuff.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
ox::Result<ox::UniquePtr<ox::FileSystem>> loadRomFs(const char *path) noexcept;
|
ox::Result<ox::UniquePtr<ox::FileSystem>> loadRomFs(ox::CRStringView path) noexcept;
|
||||||
|
|
||||||
ox::Result<char*> loadRom(const char *path = "") noexcept;
|
ox::Result<char*> loadRom(ox::CRStringView path = "") noexcept;
|
||||||
|
|
||||||
void unloadRom(char*) noexcept;
|
void unloadRom(char*) noexcept;
|
||||||
|
|
||||||
|
@ -416,7 +416,7 @@ void TileSheetEditorImGui::SubSheetEditor::draw() noexcept {
|
|||||||
if (ImGui::Button("OK")) {
|
if (ImGui::Button("OK")) {
|
||||||
ImGui::CloseCurrentPopup();
|
ImGui::CloseCurrentPopup();
|
||||||
m_show = false;
|
m_show = false;
|
||||||
inputSubmitted.emit(m_name.c_str(), m_cols, m_rows);
|
inputSubmitted.emit(m_name, m_cols, m_rows);
|
||||||
}
|
}
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
if (ImGui::Button("Cancel")) {
|
if (ImGui::Button("Cancel")) {
|
||||||
|
@ -32,7 +32,7 @@ class TileSheetEditorImGui: public studio::BaseEditor {
|
|||||||
int m_rows = 0;
|
int m_rows = 0;
|
||||||
bool m_show = false;
|
bool m_show = false;
|
||||||
public:
|
public:
|
||||||
ox::Signal<ox::Error(const ox::String &name, int cols, int rows)> inputSubmitted;
|
ox::Signal<ox::Error(const ox::StringView &name, int cols, int rows)> inputSubmitted;
|
||||||
constexpr void show(const ox::String &name, int cols, int rows) noexcept {
|
constexpr void show(const ox::String &name, int cols, int rows) noexcept {
|
||||||
m_show = true;
|
m_show = true;
|
||||||
m_name = name.c_str();
|
m_name = name.c_str();
|
||||||
|
@ -256,7 +256,7 @@ class AddSubSheetCommand: public TileSheetCommand {
|
|||||||
auto &parent = m_img->getSubSheet(m_parentIdx);
|
auto &parent = m_img->getSubSheet(m_parentIdx);
|
||||||
if (m_addedSheets.size() < 2) {
|
if (m_addedSheets.size() < 2) {
|
||||||
auto i = parent.subsheets.size();
|
auto i = parent.subsheets.size();
|
||||||
parent.subsheets.emplace_back(ox::sfmt("Subsheet {}", i).c_str(), 1, 1, m_img->bpp);
|
parent.subsheets.emplace_back(ox::sfmt("Subsheet {}", i), 1, 1, m_img->bpp);
|
||||||
} else {
|
} else {
|
||||||
parent.subsheets.emplace_back("Subsheet 0", parent.columns, parent.rows, std::move(parent.pixels));
|
parent.subsheets.emplace_back("Subsheet 0", parent.columns, parent.rows, std::move(parent.pixels));
|
||||||
parent.rows = 0;
|
parent.rows = 0;
|
||||||
|
@ -49,8 +49,8 @@ static const auto converters = [] {
|
|||||||
}();
|
}();
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
static auto findConverter(const char *srcTypeName, int srcTypeVersion,
|
static auto findConverter(ox::CRStringView srcTypeName, int srcTypeVersion,
|
||||||
const char *dstTypeName, int dstTypeVersion) noexcept -> ox::Result<BaseConverter*> {
|
ox::CRStringView dstTypeName, int dstTypeVersion) noexcept -> ox::Result<BaseConverter*> {
|
||||||
for (auto &c : converters) {
|
for (auto &c : converters) {
|
||||||
if (c->matches(srcTypeName, srcTypeVersion, dstTypeName, dstTypeVersion)) {
|
if (c->matches(srcTypeName, srcTypeVersion, dstTypeName, dstTypeVersion)) {
|
||||||
return c.get();
|
return c.get();
|
||||||
@ -60,8 +60,8 @@ static auto findConverter(const char *srcTypeName, int srcTypeVersion,
|
|||||||
};
|
};
|
||||||
|
|
||||||
static ox::Result<ox::UniquePtr<Wrap>> convert(const ox::Buffer &srcBuffer,
|
static ox::Result<ox::UniquePtr<Wrap>> convert(const ox::Buffer &srcBuffer,
|
||||||
const char *srcTypeName, int srcTypeVersion,
|
ox::CRStringView srcTypeName, int srcTypeVersion,
|
||||||
const char *dstTypeName, int dstTypeVersion) noexcept {
|
ox::CRStringView dstTypeName, int dstTypeVersion) noexcept {
|
||||||
// look for direct converter
|
// look for direct converter
|
||||||
auto [c, err] = findConverter(srcTypeName, srcTypeVersion, dstTypeName, dstTypeVersion);
|
auto [c, err] = findConverter(srcTypeName, srcTypeVersion, dstTypeName, dstTypeVersion);
|
||||||
if (!err) {
|
if (!err) {
|
||||||
@ -82,9 +82,9 @@ static ox::Result<ox::UniquePtr<Wrap>> convert(const ox::Buffer &srcBuffer,
|
|||||||
return OxError(1, "Could not convert between types");
|
return OxError(1, "Could not convert between types");
|
||||||
}
|
}
|
||||||
|
|
||||||
ox::Result<ox::UniquePtr<Wrap>> convert(const ox::Buffer &srcBuffer, const char *dstTypeName, int dstTypeVersion) noexcept {
|
ox::Result<ox::UniquePtr<Wrap>> convert(const ox::Buffer &srcBuffer, ox::CRStringView dstTypeName, int dstTypeVersion) noexcept {
|
||||||
oxRequire(hdr, ox::readClawHeader(srcBuffer));
|
oxRequire(hdr, ox::readClawHeader(srcBuffer));
|
||||||
return convert(srcBuffer, hdr.typeName.c_str(), hdr.typeVersion, dstTypeName, dstTypeVersion);
|
return convert(srcBuffer, hdr.typeName, hdr.typeVersion, dstTypeName, dstTypeVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -51,24 +51,24 @@ struct BaseConverter {
|
|||||||
virtual ~BaseConverter() noexcept = default;
|
virtual ~BaseConverter() noexcept = default;
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
virtual const char *srcTypeName() noexcept = 0;
|
virtual ox::StringView srcTypeName() noexcept = 0;
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
virtual int srcTypeVersion() noexcept = 0;
|
virtual int srcTypeVersion() noexcept = 0;
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
virtual bool srcMatches(const char *srcTypeName, int srcTypeVersion) const noexcept = 0;
|
virtual bool srcMatches(ox::CRStringView srcTypeName, int srcTypeVersion) const noexcept = 0;
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
virtual bool dstMatches(const char *dstTypeName, int dstTypeVersion) const noexcept = 0;
|
virtual bool dstMatches(ox::CRStringView dstTypeName, int dstTypeVersion) const noexcept = 0;
|
||||||
|
|
||||||
virtual ox::Result<ox::UniquePtr<Wrap>> convertPtrToPtr(Wrap *src) noexcept = 0;
|
virtual ox::Result<ox::UniquePtr<Wrap>> convertPtrToPtr(Wrap *src) noexcept = 0;
|
||||||
|
|
||||||
virtual ox::Result<ox::UniquePtr<Wrap>> convertBuffToPtr(const ox::Buffer &srcBuff) noexcept = 0;
|
virtual ox::Result<ox::UniquePtr<Wrap>> convertBuffToPtr(const ox::Buffer &srcBuff) noexcept = 0;
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
inline bool matches(const char *srcTypeName, int srcTypeVersion,
|
inline bool matches(ox::CRStringView srcTypeName, int srcTypeVersion,
|
||||||
const char *dstTypeName, int dstTypeVersion) const noexcept {
|
ox::CRStringView dstTypeName, int dstTypeVersion) const noexcept {
|
||||||
return srcMatches(srcTypeName, srcTypeVersion)
|
return srcMatches(srcTypeName, srcTypeVersion)
|
||||||
&& dstMatches(dstTypeName, dstTypeVersion);
|
&& dstMatches(dstTypeName, dstTypeVersion);
|
||||||
}
|
}
|
||||||
@ -81,7 +81,7 @@ struct Converter: public BaseConverter {
|
|||||||
virtual ox::Error convert(SrcType*, DstType*) noexcept = 0;
|
virtual ox::Error convert(SrcType*, DstType*) noexcept = 0;
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
const char *srcTypeName() noexcept final {
|
ox::StringView srcTypeName() noexcept final {
|
||||||
return ox::requireModelTypeName<SrcType>();
|
return ox::requireModelTypeName<SrcType>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,7 +91,7 @@ struct Converter: public BaseConverter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
bool srcMatches(const char *srcTypeName, int srcTypeVersion) const noexcept final {
|
bool srcMatches(ox::CRStringView srcTypeName, int srcTypeVersion) const noexcept final {
|
||||||
static constexpr auto SrcTypeName = ox::requireModelTypeName<SrcType>();
|
static constexpr auto SrcTypeName = ox::requireModelTypeName<SrcType>();
|
||||||
static constexpr auto SrcTypeVersion = ox::requireModelTypeVersion<SrcType>();
|
static constexpr auto SrcTypeVersion = ox::requireModelTypeVersion<SrcType>();
|
||||||
return ox_strcmp(srcTypeName, SrcTypeName) == 0
|
return ox_strcmp(srcTypeName, SrcTypeName) == 0
|
||||||
@ -99,7 +99,7 @@ struct Converter: public BaseConverter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
bool dstMatches(const char *dstTypeName, int dstTypeVersion) const noexcept final {
|
bool dstMatches(ox::CRStringView dstTypeName, int dstTypeVersion) const noexcept final {
|
||||||
static constexpr auto DstTypeName = ox::requireModelTypeName<DstType>();
|
static constexpr auto DstTypeName = ox::requireModelTypeName<DstType>();
|
||||||
static constexpr auto DstTypeVersion = ox::requireModelTypeVersion<DstType>();
|
static constexpr auto DstTypeVersion = ox::requireModelTypeVersion<DstType>();
|
||||||
return ox_strcmp(dstTypeName, DstTypeName) == 0
|
return ox_strcmp(dstTypeName, DstTypeName) == 0
|
||||||
@ -122,7 +122,7 @@ struct Converter: public BaseConverter {
|
|||||||
};
|
};
|
||||||
|
|
||||||
ox::Result<ox::UniquePtr<Wrap>> convert(const ox::Buffer &srcBuffer,
|
ox::Result<ox::UniquePtr<Wrap>> convert(const ox::Buffer &srcBuffer,
|
||||||
const char *dstTypeName, int dstTypeVersion) noexcept;
|
ox::CRStringView dstTypeName, int dstTypeVersion) noexcept;
|
||||||
|
|
||||||
template<typename DstType>
|
template<typename DstType>
|
||||||
ox::Result<DstType> convert(const ox::Buffer &srcBuffer) noexcept {
|
ox::Result<DstType> convert(const ox::Buffer &srcBuffer) noexcept {
|
||||||
|
@ -52,9 +52,10 @@ ox::Error loadSpriteTileSheet(Context*,
|
|||||||
return OxError(0);
|
return OxError(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void puts(Context *ctx, int column, int row, const char *str) noexcept {
|
void puts(Context *ctx, int column, int row, ox::CRStringView str) noexcept {
|
||||||
for (int i = 0; str[i]; ++i) {
|
const auto col = static_cast<unsigned>(column);
|
||||||
setTile(ctx, 0, column + i, row, static_cast<uint8_t>(charMap[static_cast<uint8_t>(str[i])]));
|
for (auto i = 0u; i < str.bytes(); ++i) {
|
||||||
|
setTile(ctx, 0, static_cast<int>(col + i), row, static_cast<uint8_t>(charMap[static_cast<uint8_t>(str[i])]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,8 +10,8 @@
|
|||||||
|
|
||||||
namespace nostalgia::core {
|
namespace nostalgia::core {
|
||||||
|
|
||||||
ox::Result<char*> loadRom(const char *path) noexcept {
|
ox::Result<char*> loadRom(ox::CRStringView path) noexcept {
|
||||||
std::ifstream file(path, std::ios::binary | std::ios::ate);
|
std::ifstream file(toStdStringView(path), std::ios::binary | std::ios::ate);
|
||||||
if (!file.good()) {
|
if (!file.good()) {
|
||||||
oxErrorf("Could not find ROM file: {}", path);
|
oxErrorf("Could not find ROM file: {}", path);
|
||||||
return OxError(1, "Could not find ROM file");
|
return OxError(1, "Could not find ROM file");
|
||||||
|
@ -47,7 +47,7 @@ template struct GLObject<deleteProgram>;
|
|||||||
template struct GLObject<deleteShader>;
|
template struct GLObject<deleteShader>;
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
static ox::Result<GLShader> buildShader(GLuint shaderType, const GLchar *src, const char *shaderName) noexcept {
|
static ox::Result<GLShader> buildShader(GLuint shaderType, const GLchar *src, ox::CRStringView shaderName) noexcept {
|
||||||
GLShader shader(glCreateShader(shaderType));
|
GLShader shader(glCreateShader(shaderType));
|
||||||
glShaderSource(shader, 1, &src, nullptr);
|
glShaderSource(shader, 1, &src, nullptr);
|
||||||
glCompileShader(shader);
|
glCompileShader(shader);
|
||||||
|
@ -38,7 +38,7 @@ constexpr auto ConfigDir = [] {
|
|||||||
}();
|
}();
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
ox::Result<T> readConfig(core::Context *ctx, const char *name) noexcept {
|
ox::Result<T> readConfig(core::Context *ctx, ox::CRStringView name) noexcept {
|
||||||
oxAssert(ox_strcmp(name, ""), "Config type has no TypeName");
|
oxAssert(ox_strcmp(name, ""), "Config type has no TypeName");
|
||||||
const auto homeDir = std::getenv(ox::defines::OS == ox::OS::Windows ? "USERPROFILE" : "HOME");
|
const auto homeDir = std::getenv(ox::defines::OS == ox::OS::Windows ? "USERPROFILE" : "HOME");
|
||||||
const auto configPath = ox::sfmt(ConfigDir, homeDir, ctx->appName).toStdString();
|
const auto configPath = ox::sfmt(ConfigDir, homeDir, ctx->appName).toStdString();
|
||||||
@ -70,16 +70,16 @@ template<typename T>
|
|||||||
ox::Error writeConfig(core::Context *ctx, const auto &name, T *data) noexcept {
|
ox::Error writeConfig(core::Context *ctx, const auto &name, T *data) noexcept {
|
||||||
oxAssert(ox_strcmp(name, ""), "Config type has no TypeName");
|
oxAssert(ox_strcmp(name, ""), "Config type has no TypeName");
|
||||||
const auto homeDir = std::getenv(ox::defines::OS == ox::OS::Windows ? "USERPROFILE" : "HOME");
|
const auto homeDir = std::getenv(ox::defines::OS == ox::OS::Windows ? "USERPROFILE" : "HOME");
|
||||||
const auto configPath = ox::sfmt(ConfigDir, homeDir, ctx->appName).toStdString();
|
const auto configPath = ox::sfmt(ConfigDir, homeDir, ctx->appName);
|
||||||
const auto path = ox::sfmt("{}.json", name).toStdString();
|
const auto path = ox::sfmt("{}.json", name);
|
||||||
ox::PassThroughFS fs(configPath.c_str());
|
ox::PassThroughFS fs(configPath);
|
||||||
if (auto err = fs.mkdir("/", true)) {
|
if (auto err = fs.mkdir("/", true)) {
|
||||||
oxErrf("Could not create config directory: {}\n", toStr(err));
|
oxErrf("Could not create config directory: {}\n", toStr(err));
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
oxRequireM(buff, ox::writeOC(data));
|
oxRequireM(buff, ox::writeOC(data));
|
||||||
buff.back().value = '\n';
|
buff.back().value = '\n';
|
||||||
if (auto err = fs.write(path.c_str(), buff.data(), buff.size())) {
|
if (auto err = fs.write(path, buff.data(), buff.size())) {
|
||||||
oxErrf("Could not read config file: {}\n", toStr(err));
|
oxErrf("Could not read config file: {}\n", toStr(err));
|
||||||
return OxError(2, "Could not read config file");
|
return OxError(2, "Could not read config file");
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ class ItemMaker {
|
|||||||
fileExt(std::move(pFileExt)) {
|
fileExt(std::move(pFileExt)) {
|
||||||
}
|
}
|
||||||
virtual ~ItemMaker() noexcept = default;
|
virtual ~ItemMaker() noexcept = default;
|
||||||
virtual ox::Error write(core::Context *ctx, const char *pName) const noexcept = 0;
|
virtual ox::Error write(core::Context *ctx, ox::CRStringView pName) const noexcept = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
@ -44,7 +44,7 @@ class ItemMakerT: public ItemMaker {
|
|||||||
item(std::forward(pItem)),
|
item(std::forward(pItem)),
|
||||||
fmt(pFmt) {
|
fmt(pFmt) {
|
||||||
}
|
}
|
||||||
ox::Error write(core::Context *ctx, const char *pName) const noexcept override {
|
ox::Error write(core::Context *ctx, ox::CRStringView pName) const noexcept override {
|
||||||
const auto path = ox::sfmt("{}/{}.{}", parentDir, pName, fileExt);
|
const auto path = ox::sfmt("{}/{}.{}", parentDir, pName, fileExt);
|
||||||
auto sctx = core::applicationData<studio::StudioContext>(ctx);
|
auto sctx = core::applicationData<studio::StudioContext>(ctx);
|
||||||
return sctx->project->writeObj(path, &item, fmt);
|
return sctx->project->writeObj(path, &item, fmt);
|
||||||
|
@ -108,7 +108,7 @@ void NewMenu::drawLastPageButtons(core::Context *ctx) noexcept {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void NewMenu::finish(core::Context *ctx) noexcept {
|
void NewMenu::finish(core::Context *ctx) noexcept {
|
||||||
const auto err = m_types[static_cast<std::size_t>(m_selectedType)]->write(ctx, m_itemName.c_str());
|
const auto err = m_types[static_cast<std::size_t>(m_selectedType)]->write(ctx, m_itemName);
|
||||||
if (err) {
|
if (err) {
|
||||||
oxLogError(err);
|
oxLogError(err);
|
||||||
return;
|
return;
|
||||||
|
@ -283,10 +283,10 @@ void StudioUI::save() noexcept {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ox::Error StudioUI::openProject(const ox::String &path) noexcept {
|
ox::Error StudioUI::openProject(ox::CRStringView path) noexcept {
|
||||||
oxRequireM(fs, core::loadRomFs(path.c_str()));
|
oxRequireM(fs, core::loadRomFs(path));
|
||||||
m_ctx->rom = std::move(fs);
|
m_ctx->rom = std::move(fs);
|
||||||
core::setWindowTitle(m_ctx, ox::sfmt("Nostalgia Studio - {}", path).c_str());
|
core::setWindowTitle(m_ctx, ox::sfmt("Nostalgia Studio - {}", path));
|
||||||
m_project = ox::make_unique<studio::Project>(m_ctx->rom.get(), path);
|
m_project = ox::make_unique<studio::Project>(m_ctx->rom.get(), path);
|
||||||
auto sctx = applicationData<studio::StudioContext>(m_ctx);
|
auto sctx = applicationData<studio::StudioContext>(m_ctx);
|
||||||
sctx->project = m_project.get();
|
sctx->project = m_project.get();
|
||||||
|
@ -77,7 +77,7 @@ class StudioUI: public ox::SignalHandler {
|
|||||||
|
|
||||||
void save() noexcept;
|
void save() noexcept;
|
||||||
|
|
||||||
ox::Error openProject(const ox::String &path) noexcept;
|
ox::Error openProject(ox::CRStringView path) noexcept;
|
||||||
|
|
||||||
ox::Error openFile(ox::CRStringView path) noexcept;
|
ox::Error openFile(ox::CRStringView path) noexcept;
|
||||||
|
|
||||||
|
@ -13,9 +13,9 @@
|
|||||||
|
|
||||||
using namespace nostalgia;
|
using namespace nostalgia;
|
||||||
|
|
||||||
static ox::Error writeFileBuff(ox::CRString path, const ox::Buffer &buff) noexcept {
|
static ox::Error writeFileBuff(ox::CRStringView path, const ox::Buffer &buff) noexcept {
|
||||||
try {
|
try {
|
||||||
std::ofstream f(path.c_str(), std::ios::binary);
|
std::ofstream f(toStdStringView(path), std::ios::binary);
|
||||||
f.write(buff.data(), static_cast<intptr_t>(buff.size()));
|
f.write(buff.data(), static_cast<intptr_t>(buff.size()));
|
||||||
} catch (const std::fstream::failure&) {
|
} catch (const std::fstream::failure&) {
|
||||||
return OxError(2, "failed to write file");
|
return OxError(2, "failed to write file");
|
||||||
@ -23,8 +23,8 @@ static ox::Error writeFileBuff(ox::CRString path, const ox::Buffer &buff) noexce
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
static ox::Result<ox::Buffer> readFileBuff(const char *path) noexcept {
|
static ox::Result<ox::Buffer> readFileBuff(ox::CRStringView path) noexcept {
|
||||||
std::ifstream file(path, std::ios::binary | std::ios::ate);
|
std::ifstream file(toStdStringView(path), std::ios::binary | std::ios::ate);
|
||||||
if (!file.good()) {
|
if (!file.good()) {
|
||||||
oxErrorf("Could not find OxFS file: {}", path);
|
oxErrorf("Could not find OxFS file: {}", path);
|
||||||
return OxError(1, "Could not find OxFS file");
|
return OxError(1, "Could not find OxFS file");
|
||||||
@ -55,7 +55,7 @@ static ox::Error run(const ox::ClArgs &args) noexcept {
|
|||||||
}
|
}
|
||||||
ox::Buffer dstBuff(32 * ox::units::MB);
|
ox::Buffer dstBuff(32 * ox::units::MB);
|
||||||
oxReturnError(ox::FileSystem32::format(dstBuff.data(), dstBuff.size()));
|
oxReturnError(ox::FileSystem32::format(dstBuff.data(), dstBuff.size()));
|
||||||
ox::PassThroughFS src(argSrc.c_str());
|
ox::PassThroughFS src(argSrc);
|
||||||
ox::FileSystem32 dst(ox::FileStore32(dstBuff.data(), dstBuff.size()));
|
ox::FileSystem32 dst(ox::FileStore32(dstBuff.data(), dstBuff.size()));
|
||||||
core::TypeStore ts(&src);
|
core::TypeStore ts(&src);
|
||||||
oxReturnError(pack(&ts, &src, &dst));
|
oxReturnError(pack(&ts, &src, &dst));
|
||||||
@ -66,7 +66,7 @@ static ox::Error run(const ox::ClArgs &args) noexcept {
|
|||||||
oxRequire(dstSize, dst.size());
|
oxRequire(dstSize, dst.size());
|
||||||
dstBuff.resize(dstSize);
|
dstBuff.resize(dstSize);
|
||||||
|
|
||||||
oxRequireM(romBuff, readFileBuff(argRomBin.c_str()));
|
oxRequireM(romBuff, readFileBuff(argRomBin));
|
||||||
oxReturnError(appendBinary(&romBuff, &dstBuff, pl.get()));
|
oxReturnError(appendBinary(&romBuff, &dstBuff, pl.get()));
|
||||||
|
|
||||||
oxOutf("Dest FS size: {} bytes\n", dstSize);
|
oxOutf("Dest FS size: {} bytes\n", dstSize);
|
||||||
|
@ -123,7 +123,7 @@ static ox::Error copy(ox::FileSystem *src, ox::FileSystem *dest, ox::CRStringVie
|
|||||||
oxOutf("reading {}\n", currentFile);
|
oxOutf("reading {}\n", currentFile);
|
||||||
oxRequire(stat, src->stat(ox::StringView(currentFile)));
|
oxRequire(stat, src->stat(ox::StringView(currentFile)));
|
||||||
if (stat.fileType == ox::FileType::Directory) {
|
if (stat.fileType == ox::FileType::Directory) {
|
||||||
oxReturnError(dest->mkdir(currentFile.c_str(), true));
|
oxReturnError(dest->mkdir(currentFile, true));
|
||||||
oxReturnError(copy(src, dest, currentFile + '/'));
|
oxReturnError(copy(src, dest, currentFile + '/'));
|
||||||
} else {
|
} else {
|
||||||
// load file
|
// load file
|
||||||
|
Loading…
Reference in New Issue
Block a user