Merge commit '54de52e6c55126b4bfd3843fbeac7a1b57cd4e10'
All checks were successful
Build / build (push) Successful in 1m54s

This commit is contained in:
Gary Talent 2025-02-24 21:48:11 -06:00
commit c4e6b833f0
34 changed files with 31 additions and 851 deletions

View File

@ -17,3 +17,10 @@ jobs:
- run: make purge configure-release
- run: make build
- run: make test
- run: make install
- run: mv dist/linux-x86_64-release nostalgia-linux-x86_64
- run: tar cf nostalgia-linux-x86_64.tar nostalgia-linux-x86_64
- uses: actions/upload-artifact@v3
with:
name: nostalgia-linux-x86_64
path: nostalgia-linux-x86_64.tar

View File

@ -35,4 +35,6 @@ def get_arch() -> str:
arch = platform.machine().lower()
if arch == 'amd64':
arch = 'x86_64'
elif arch == 'aarch64':
arch = 'arm64'
return arch

View File

@ -2,7 +2,6 @@
add_subdirectory(gfx)
add_subdirectory(sound)
add_subdirectory(scene)
# module libraries
@ -15,7 +14,7 @@ target_link_libraries(
NostalgiaKeelModules PUBLIC
Keel
NostalgiaGfx-Keel
NostalgiaScene-Keel
NostalgiaSound-Keel
)
install(
FILES
@ -35,7 +34,6 @@ if(NOSTALGIA_BUILD_STUDIO)
StudioAppLib
NostalgiaGfx-Studio-ImGui
NostalgiaSound-Studio-ImGui
NostalgiaScene-Studio
)
install(
FILES

View File

@ -16,23 +16,6 @@
namespace nostalgia::gfx {
struct SubSheetTemplate {
static constexpr auto TypeName = "net.drinkingtea.nostalgia.gfx.SubSheetTemplate";
static constexpr auto TypeVersion = 1;
ox::String name;
int32_t width{};
int32_t height{};
ox::Vector<SubSheetTemplate> subsheets;
};
OX_MODEL_BEGIN(SubSheetTemplate)
OX_MODEL_FIELD(name)
OX_MODEL_FIELD(width)
OX_MODEL_FIELD(height)
OX_MODEL_FIELD(subsheets)
OX_MODEL_END()
// Predecessor to TileSheet, kept for backward compatibility
struct TileSheetV1 {
static constexpr auto TypeName = "net.drinkingtea.nostalgia.core.NostalgiaGraphic";
@ -52,7 +35,7 @@ constexpr bool valid(TileSheetV1 const&ts) noexcept {
return (ts.bpp == 4 || ts.bpp == 8) && ts.pixels.size() == bytes;
}
constexpr ox::Error repair(TileSheetV1 &ts, int bpp) noexcept {
constexpr ox::Error repair(TileSheetV1 &ts, int const bpp) noexcept {
auto const bytes = static_cast<size_t>(ts.columns * ts.rows * PixelsPerTile) / (bpp == 4 ? 2 : 1);
ts.pixels.resize(bytes);
return {};
@ -101,7 +84,7 @@ constexpr bool valid(TileSheetV2 const&ts) noexcept {
return (ts.bpp == 4 || ts.bpp == 8) && valid(ts.subsheet, ts.bpp);
}
constexpr void repair(TileSheetV2::SubSheet &ss, int bpp) noexcept {
constexpr void repair(TileSheetV2::SubSheet &ss, int const bpp) noexcept {
auto const bytes = static_cast<size_t>(ss.columns * ss.rows * PixelsPerTile) / (bpp == 4 ? 2 : 1);
ss.pixels.resize(bytes);
for (auto &s : ss.subsheets) {
@ -171,7 +154,7 @@ constexpr bool valid(TileSheetV3 const&ts) noexcept {
return (ts.bpp == 4 || ts.bpp == 8) && valid(ts.subsheet, ts.bpp);
}
constexpr void repair(TileSheetV3::SubSheet &ss, int bpp) noexcept {
constexpr void repair(TileSheetV3::SubSheet &ss, int const bpp) noexcept {
auto const bytes = static_cast<size_t>(ss.columns * ss.rows * PixelsPerTile) / (bpp == 4 ? 2 : 1);
ss.pixels.resize(bytes);
for (auto &s : ss.subsheets) {
@ -265,7 +248,7 @@ constexpr bool valid(TileSheetV4 const&ts) noexcept {
return (ts.bpp == 4 || ts.bpp == 8) && valid(ts.subsheet, ts.bpp);
}
constexpr void repair(TileSheetV4::SubSheet &ss, int bpp) noexcept {
constexpr void repair(TileSheetV4::SubSheet &ss, int const bpp) noexcept {
if (ss.subsheets.empty()) {
auto const bytes = static_cast<size_t>(ss.columns * ss.rows * PixelsPerTile) / (bpp == 4 ? 2 : 1);
ss.pixels.resize(bytes);
@ -367,7 +350,7 @@ constexpr bool valid(TileSheetV5 const&ts) noexcept {
return (ts.bpp == 4 || ts.bpp == 8) && valid(ts.subsheet);
}
constexpr void repair(TileSheetV5::SubSheet &ss, int const bpp) noexcept {
constexpr void repair(TileSheetV5::SubSheet &ss) noexcept {
if (ss.subsheets.empty()) {
auto const bytes = static_cast<size_t>(ss.columns * ss.rows * PixelsPerTile);
ss.pixels.resize(bytes);
@ -377,7 +360,7 @@ constexpr void repair(TileSheetV5::SubSheet &ss, int const bpp) noexcept {
ss.rows = -1;
}
for (auto &s : ss.subsheets) {
repair(s, bpp);
repair(s);
}
}
@ -385,7 +368,7 @@ constexpr ox::Error repair(TileSheetV5 &ts) noexcept {
if (ts.bpp != 4 && ts.bpp != 8) {
return ox::Error{1, "Unable to repair TileSheet"};
}
repair(ts.subsheet, ts.bpp);
repair(ts.subsheet);
return {};
}

View File

@ -169,7 +169,7 @@ void TileSheetV4ToTileSheetV5Converter::convertSubsheet(
dst.pixels.emplace_back(static_cast<uint8_t>(p & 0xf));
dst.pixels.emplace_back(static_cast<uint8_t>(p >> 4));
}
oxAssert(dst.pixels.size() == src.pixels.size() *2, "mismatch");
oxAssert(dst.pixels.size() == src.pixels.size() * 2, "mismatch");
} else {
dst.pixels = std::move(src.pixels);
}

View File

@ -642,7 +642,7 @@ void TileSheetEditorImGui::ExportMenu::draw(turbine::Context &tctx) noexcept {
constexpr auto popupSz = ImVec2{popupWidth, popupHeight};
if (ig::BeginPopup(tctx, popupName, m_show, popupSz)) {
ImGui::InputInt("Scale", &m_scale);
m_scale = ox::clamp(m_scale, 1, 50);
m_scale = ox::clamp(m_scale, 1, 135);
if (ig::PopupControlsOkCancel(popupWidth, m_show) == ig::PopupResponse::OK) {
inputSubmitted.emit(m_scale);
}

View File

@ -3,7 +3,7 @@
*/
#include <nostalgia/gfx/keelmodule.hpp>
#include <nostalgia/scene/keelmodule.hpp>
#include <nostalgia/sound/keelmodule.hpp>
namespace nostalgia {
@ -14,7 +14,7 @@ void registerKeelModules() noexcept {
}
modulesRegistered = true;
keel::registerModule(gfx::keelModule());
keel::registerModule(scene::keelModule());
keel::registerModule(sound::keelModule());
}
}

View File

@ -1,13 +0,0 @@
add_subdirectory(src)
target_include_directories(
NostalgiaScene PUBLIC
include
)
install(
DIRECTORY
include/nostalgia
DESTINATION
include
)

View File

@ -1,27 +0,0 @@
/*
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#pragma once
#include <nostalgia/gfx/context.hpp>
#include "scenestatic.hpp"
namespace nostalgia::scene {
class Scene {
private:
SceneStatic const&m_sceneStatic;
public:
explicit Scene(SceneStatic const&sceneStatic) noexcept;
ox::Error setupDisplay(gfx::Context &ctx) const noexcept;
private:
void setupLayer(gfx::Context&, ox::Vector<uint16_t> const&layer, unsigned layerNo) const noexcept;
};
}

View File

@ -1,228 +0,0 @@
/*
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#pragma once
#include <ox/fs/fs.hpp>
#include <ox/std/error.hpp>
#include <ox/std/size.hpp>
#include <ox/std/types.hpp>
#include <ox/std/vector.hpp>
#include <nostalgia/gfx/tilesheet.hpp>
namespace nostalgia::scene {
struct SpriteDoc {
constexpr static auto TypeName = "net.drinkingtea.nostalgia.scene.SpriteDoc";
constexpr static auto TypeVersion = 1;
constexpr static auto Preloadable = true;
ox::String tilesheetPath;
ox::Vector<gfx::SubSheetId> subsheetId;
};
struct TileDoc {
constexpr static auto TypeName = "net.drinkingtea.nostalgia.scene.TileDoc";
constexpr static auto TypeVersion = 1;
constexpr static auto Preloadable = true;
gfx::SubSheetId subsheetId = -1;
ox::String subsheetPath;
uint8_t type = 0;
ox::Array<uint8_t, 4> layerAttachments;
[[nodiscard]]
constexpr ox::Result<gfx::SubSheetId> getSubsheetId(gfx::TileSheet const&ts) const noexcept {
// prefer the already present ID
if (subsheetId > -1) {
return subsheetId;
}
return getIdFor(ts, subsheetPath);
}
[[nodiscard]]
constexpr ox::Result<ox::StringView> getSubsheetPath(
gfx::TileSheet const&ts) const noexcept {
// prefer the already present path
if (!subsheetPath.len()) {
return gfx::getNameFor(ts, subsheetId);
}
return ox::StringView(subsheetPath);
}
};
OX_MODEL_BEGIN(TileDoc)
OX_MODEL_FIELD_RENAME(subsheetId, subsheet_id)
OX_MODEL_FIELD_RENAME(subsheetPath, subsheet_path)
OX_MODEL_FIELD(type)
OX_MODEL_FIELD_RENAME(layerAttachments, layer_attachments)
OX_MODEL_END()
struct SceneDoc {
using TileMapRow = ox::Vector<TileDoc>;
using TileMapLayer = ox::Vector<TileMapRow>;
using TileMap = ox::Vector<TileMapLayer>;
constexpr static auto TypeName = "net.drinkingtea.nostalgia.scene.SceneDoc";
constexpr static auto TypeVersion = 1;
constexpr static auto Preloadable = true;
ox::String tilesheet; // path
ox::Vector<ox::String> palettes; // paths
TileMap tiles;
[[nodiscard]]
constexpr ox::Size size(std::size_t layerIdx) const noexcept {
const auto &layer = this->tiles[layerIdx];
const auto rowCnt = static_cast<int>(layer.size());
if (!rowCnt) {
return {};
}
auto colCnt = layer[0].size();
// find shortest row (they should all be the same, but you know this data
// could come from a file)
for (auto const&row : layer) {
colCnt = ox::min(colCnt, row.size());
}
return {static_cast<int>(colCnt), rowCnt};
}
};
OX_MODEL_BEGIN(SceneDoc)
OX_MODEL_FIELD(tilesheet)
OX_MODEL_FIELD(palettes)
OX_MODEL_FIELD(tiles)
OX_MODEL_END()
constexpr void setTopEdge(uint8_t &layerAttachments, unsigned val) noexcept {
const auto val8 = static_cast<uint8_t>(val);
layerAttachments = (layerAttachments & 0b11111100) | val8;
}
constexpr void setBottomEdge(uint8_t &layerAttachments, unsigned val) noexcept {
const auto val8 = static_cast<uint8_t>(val);
layerAttachments = (layerAttachments & 0b11110011) | static_cast<uint8_t>(val8 << 2);
}
constexpr void setLeftEdge(uint8_t &layerAttachments, unsigned val) noexcept {
const auto val8 = static_cast<uint8_t>(val);
layerAttachments = (layerAttachments & 0b11001111) | static_cast<uint8_t>(val8 << 4);
}
constexpr void setRightEdge(uint8_t &layerAttachments, unsigned val) noexcept {
const auto val8 = static_cast<uint8_t>(val);
layerAttachments = (layerAttachments & 0b00111111) | static_cast<uint8_t>(val8 << 6);
}
[[nodiscard]]
constexpr unsigned topEdge(uint8_t layerAttachments) noexcept {
return layerAttachments & 0b11;
}
[[nodiscard]]
constexpr unsigned bottomEdge(uint8_t layerAttachments) noexcept {
return (layerAttachments >> 2) & 0b11;
}
[[nodiscard]]
constexpr unsigned leftEdge(uint8_t layerAttachments) noexcept {
return (layerAttachments >> 4) & 0b11;
}
[[nodiscard]]
constexpr unsigned rightEdge(uint8_t layerAttachments) noexcept {
return (layerAttachments >> 6) & 0b11;
}
struct SceneStatic {
constexpr static auto TypeName = "net.drinkingtea.nostalgia.scene.SceneStatic";
constexpr static auto TypeVersion = 1;
constexpr static auto Preloadable = true;
struct Tile {
uint16_t &tileMapIdx;
uint8_t &tileType;
uint8_t &layerAttachments;
constexpr Tile(uint16_t &pTileMapIdx, uint8_t &pTileType, uint8_t &pLayerAttachments) noexcept:
tileMapIdx(pTileMapIdx),
tileType(pTileType),
layerAttachments(pLayerAttachments) {
}
};
struct Layer {
uint16_t &columns;
uint16_t &rows;
ox::Vector<uint16_t> &tileMapIdx;
ox::Vector<uint8_t> &tileType;
ox::Vector<uint8_t> &layerAttachments;
constexpr Layer(
uint16_t &pColumns,
uint16_t &pRows,
ox::Vector<uint16_t> &pTileMapIdx,
ox::Vector<uint8_t> &pTileType,
ox::Vector<uint8_t> &pLayerAttachments) noexcept:
columns(pColumns),
rows(pRows),
tileMapIdx(pTileMapIdx),
tileType(pTileType),
layerAttachments(pLayerAttachments) {
}
[[nodiscard]]
constexpr Tile tile(std::size_t i) noexcept {
return {tileMapIdx[i], tileType[i], layerAttachments[i]};
}
constexpr auto setDimensions(ox::Size dim) noexcept {
columns = static_cast<uint16_t>(dim.width);
rows = static_cast<uint16_t>(dim.height);
const auto tileCnt = static_cast<unsigned>(columns * rows);
tileMapIdx.resize(tileCnt);
tileType.resize(tileCnt);
layerAttachments.resize(tileCnt);
}
};
ox::FileAddress tilesheet;
ox::Vector<ox::FileAddress> palettes;
// tile layer data
ox::Vector<uint16_t> columns;
ox::Vector<uint16_t> rows;
ox::Vector<ox::Vector<uint16_t>> tileMapIdx;
ox::Vector<ox::Vector<uint8_t>> tileType;
ox::Vector<ox::Vector<uint8_t>> layerAttachments;
[[nodiscard]]
constexpr Layer layer(std::size_t i) noexcept {
return {
columns[i],
rows[i],
tileMapIdx[i],
tileType[i],
layerAttachments[i],
};
}
constexpr auto setLayerCnt(std::size_t layerCnt) noexcept {
this->layerAttachments.resize(layerCnt);
this->columns.resize(layerCnt);
this->rows.resize(layerCnt);
this->tileMapIdx.resize(layerCnt);
this->tileType.resize(layerCnt);
}
};
OX_MODEL_BEGIN(SceneStatic)
OX_MODEL_FIELD(tilesheet)
OX_MODEL_FIELD(palettes)
OX_MODEL_FIELD(columns)
OX_MODEL_FIELD(rows)
OX_MODEL_FIELD(tileMapIdx)
OX_MODEL_FIELD(tileType)
OX_MODEL_FIELD(layerAttachments)
OX_MODEL_END()
}

View File

@ -1,29 +0,0 @@
add_library(
NostalgiaScene
scene.cpp
scenestatic.cpp
)
target_include_directories(
NostalgiaScene PUBLIC
../include
)
target_link_libraries(
NostalgiaScene PUBLIC
NostalgiaGfx
)
add_subdirectory(keel)
if(NOSTALGIA_BUILD_STUDIO)
add_subdirectory(studio)
endif()
install(
TARGETS
NostalgiaScene
DESTINATION
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
)

View File

@ -1,17 +0,0 @@
add_library(
NostalgiaScene-Keel
keelmodule.cpp
typeconv.cpp
)
target_link_libraries(
NostalgiaScene-Keel PUBLIC
Keel
NostalgiaScene
)
install(
TARGETS
NostalgiaScene-Keel
LIBRARY DESTINATION
${NOSTALGIA_DIST_MODULE}
)

View File

@ -1,51 +0,0 @@
/*
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#include <keel/module.hpp>
#include <nostalgia/scene/scenestatic.hpp>
#include "typeconv.hpp"
namespace nostalgia::scene {
static class: public keel::Module {
private:
SceneDocToSceneStaticConverter m_sceneDocToSceneStaticConverter;
public:
[[nodiscard]]
ox::String id() const noexcept override {
return ox::String("net.drinkingtea.nostalgia.scene");
}
[[nodiscard]]
ox::Vector<keel::TypeDescGenerator> types() const noexcept override {
return {
keel::generateTypeDesc<SceneDoc>,
keel::generateTypeDesc<SceneStatic>,
};
}
[[nodiscard]]
ox::Vector<const keel::BaseConverter*> converters() const noexcept override {
return {
&m_sceneDocToSceneStaticConverter,
};
}
[[nodiscard]]
ox::Vector<keel::PackTransform> packTransforms() const noexcept override {
return {
keel::transformRule<SceneDoc, SceneStatic>,
};
}
} mod;
const keel::Module *keelModule() noexcept {
return &mod;
}
}

View File

@ -1,68 +0,0 @@
/*
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#include <nostalgia/gfx/gfx.hpp>
#include <keel/media.hpp>
#include "typeconv.hpp"
namespace nostalgia::scene {
[[nodiscard]]
constexpr unsigned adjustLayerAttachment(unsigned layer, unsigned attachment) noexcept {
if (attachment == 0) {
return layer;
} else {
return attachment - 1;
}
}
constexpr void setLayerAttachments(unsigned layer, TileDoc const&srcTile, SceneStatic::Tile &dstTile) noexcept {
setTopEdge(
dstTile.layerAttachments,
adjustLayerAttachment(layer, srcTile.layerAttachments[0]));
setBottomEdge(
dstTile.layerAttachments,
adjustLayerAttachment(layer, srcTile.layerAttachments[1]));
setLeftEdge(
dstTile.layerAttachments,
adjustLayerAttachment(layer, srcTile.layerAttachments[2]));
setRightEdge(
dstTile.layerAttachments,
adjustLayerAttachment(layer, srcTile.layerAttachments[3]));
}
ox::Error SceneDocToSceneStaticConverter::convert(
keel::Context &ctx,
SceneDoc &src,
SceneStatic &dst) const noexcept {
OX_REQUIRE(ts, keel::readObj<gfx::TileSheet>(ctx, src.tilesheet));
const auto layerCnt = src.tiles.size();
dst.setLayerCnt(layerCnt);
dst.tilesheet = ox::FileAddress(src.tilesheet);
dst.palettes.reserve(src.palettes.size());
for (const auto &pal : src.palettes) {
dst.palettes.emplace_back(pal);
}
for (auto layerIdx = 0u; const auto &layer : src.tiles) {
const auto layerDim = src.size(layerIdx);
auto dstLayer = dst.layer(layerIdx);
dstLayer.setDimensions(layerDim);
for (auto tileIdx = 0u; const auto &row : layer) {
for (const auto &srcTile : row) {
auto dstTile = dstLayer.tile(tileIdx);
dstTile.tileType = srcTile.type;
OX_REQUIRE(path, srcTile.getSubsheetPath(*ts));
OX_REQUIRE(mapIdx, getTileOffset(*ts, path));
dstTile.tileMapIdx = static_cast<uint16_t>(mapIdx);
setLayerAttachments(layerIdx, srcTile, dstTile);
++tileIdx;
}
}
++layerIdx;
}
return {};
}
}

View File

@ -1,17 +0,0 @@
/*
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#pragma once
#include <keel/typeconv.hpp>
#include <nostalgia/scene/scenestatic.hpp>
namespace nostalgia::scene {
class SceneDocToSceneStaticConverter: public keel::Converter<SceneDoc, SceneStatic> {
ox::Error convert(keel::Context&, SceneDoc &src, SceneStatic &dst) const noexcept final;
};
}

View File

@ -1,54 +0,0 @@
/*
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#include <nostalgia/gfx/gfx.hpp>
#include <nostalgia/scene/scene.hpp>
namespace nostalgia::scene {
Scene::Scene(SceneStatic const&sceneStatic) noexcept:
m_sceneStatic(sceneStatic) {
}
ox::Error Scene::setupDisplay(gfx::Context &ctx) const noexcept {
if (m_sceneStatic.palettes.empty()) {
return ox::Error(1, "Scene has no palettes");
}
auto const&palette = m_sceneStatic.palettes[0];
OX_RETURN_ERROR(gfx::loadBgTileSheet(ctx, 0, m_sceneStatic.tilesheet));
OX_RETURN_ERROR(gfx::loadBgPalette(ctx, 0, palette));
// disable all backgrounds
gfx::setBgStatus(ctx, 0);
for (auto layerNo = 0u; auto const&layer : m_sceneStatic.tileMapIdx) {
setupLayer(ctx, layer, layerNo);
++layerNo;
}
return {};
}
void Scene::setupLayer(
gfx::Context &ctx,
ox::Vector<uint16_t> const&layer,
unsigned layerNo) const noexcept {
gfx::setBgStatus(ctx, layerNo, true);
gfx::setBgCbb(ctx, layerNo, 0);
auto x = 0;
auto y = 0;
const auto width = m_sceneStatic.rows[layerNo];
for (auto const&tile : layer) {
const auto tile8 = static_cast<uint8_t>(tile);
gfx::setBgTile(ctx, layerNo, x, y, tile8);
gfx::setBgTile(ctx, layerNo, x + 1, y, tile8 + 1);
gfx::setBgTile(ctx, layerNo, x, y + 1, tile8 + 2);
gfx::setBgTile(ctx, layerNo, x + 1, y + 1, tile8 + 3);
x += 2;
if (x >= width * 2) {
x = 0;
y += 2;
}
}
}
}

View File

@ -1,11 +0,0 @@
/*
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#include <nostalgia/scene/scenestatic.hpp>
namespace nostalgia::scene {
}

View File

@ -1,20 +0,0 @@
add_library(
NostalgiaScene-Studio
studiomodule.cpp
sceneeditor-imgui.cpp
sceneeditor.cpp
sceneeditorview.cpp
)
target_link_libraries(
NostalgiaScene-Studio PUBLIC
NostalgiaScene
Studio
)
install(
TARGETS
NostalgiaScene-Studio
LIBRARY DESTINATION
${NOSTALGIA_DIST_MODULE}
)

View File

@ -1,55 +0,0 @@
/*
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#include <imgui.h>
#include <keel/media.hpp>
#include "sceneeditor-imgui.hpp"
namespace nostalgia::scene {
SceneEditorImGui::SceneEditorImGui(studio::StudioContext &ctx, ox::StringView path):
Editor(ctx, path),
m_ctx(ctx.tctx),
m_editor(m_ctx, path),
m_view(m_ctx, m_editor.scene()) {
}
void SceneEditorImGui::draw(studio::StudioContext&) noexcept {
auto const paneSize = ImGui::GetContentRegionAvail();
m_view.draw(ox::Size{static_cast<int>(paneSize.x), static_cast<int>(paneSize.y)});
auto &fb = m_view.framebuffer();
auto const srcH = static_cast<float>(fb.height) / static_cast<float>(fb.width);
auto const dstH = paneSize.y / paneSize.x;
float xScale{}, yScale{};
if (dstH > srcH) {
// crop off width
xScale = srcH / dstH;
yScale = 1;
} else {
auto const srcW = static_cast<float>(fb.width) / static_cast<float>(fb.height);
auto const dstW = (paneSize.x / paneSize.y);
xScale = 1;
yScale = srcW / dstW;
}
uintptr_t const buffId = fb.color.id;
ImGui::Image(
std::bit_cast<void*>(buffId),
paneSize,
ImVec2(0, 1),
ImVec2(xScale, 1 - yScale));
}
void SceneEditorImGui::onActivated() noexcept {
oxLogError(m_view.setupScene());
}
ox::Error SceneEditorImGui::saveItem() noexcept {
const auto sctx = applicationData<studio::StudioContext>(m_ctx);
OX_RETURN_ERROR(sctx->project->writeObj(itemPath(), m_editor.scene()));
return {};
}
}

View File

@ -1,35 +0,0 @@
/*
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#pragma once
#include <studio/studio.hpp>
#include <turbine/context.hpp>
#include "sceneeditor.hpp"
#include "sceneeditorview.hpp"
namespace nostalgia::scene {
class SceneEditorImGui: public studio::Editor {
private:
turbine::Context &m_ctx;
SceneEditor m_editor;
SceneEditorView m_view;
public:
SceneEditorImGui(studio::StudioContext &ctx, ox::StringView path);
void draw(studio::StudioContext&) noexcept final;
void onActivated() noexcept override;
protected:
ox::Error saveItem() noexcept final;
};
}

View File

@ -1,16 +0,0 @@
/*
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#include <keel/keel.hpp>
#include "sceneeditor.hpp"
namespace nostalgia::scene {
SceneEditor::SceneEditor(turbine::Context &ctx, ox::StringViewCR path):
m_ctx(ctx),
m_scene(*keel::readObj<SceneStatic>(keelCtx(m_ctx), path).unwrapThrow()) {
}
}

View File

@ -1,34 +0,0 @@
/*
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#pragma once
#include <turbine/context.hpp>
#include <nostalgia/scene/scene.hpp>
namespace nostalgia::scene {
class SceneEditor {
private:
turbine::Context &m_ctx;
ox::String m_itemName;
ox::String m_itemPath;
SceneStatic m_scene;
public:
SceneEditor(turbine::Context &ctx, ox::StringViewCR path);
[[nodiscard]]
SceneStatic const&scene() const noexcept {
return m_scene;
}
protected:
ox::Error saveItem() noexcept;
};
}

View File

@ -1,36 +0,0 @@
/*
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#include <nostalgia/gfx/gfx.hpp>
#include "sceneeditorview.hpp"
namespace nostalgia::scene {
SceneEditorView::SceneEditorView(turbine::Context &tctx, SceneStatic const&sceneStatic):
m_cctx(gfx::init(tctx, {.glInstallDrawer = false}).unwrapThrow()),
m_sceneStatic(sceneStatic),
m_scene(m_sceneStatic) {
}
ox::Error SceneEditorView::setupScene() noexcept {
glutils::resizeInitFrameBuffer(m_frameBuffer, gfx::gl::drawSize(m_scale));
return m_scene.setupDisplay(*m_cctx);
}
void SceneEditorView::draw(ox::Size const&targetSz) noexcept {
auto const scaleSz = targetSz / gfx::gl::drawSize(1);
if (m_scaleSz != scaleSz) [[unlikely]] {
m_scale = ox::max(1, ox::max(scaleSz.width, scaleSz.height));
glutils::resizeInitFrameBuffer(m_frameBuffer, gfx::gl::drawSize(m_scale));
}
glutils::FrameBufferBind const frameBufferBind(m_frameBuffer);
gfx::gl::draw(*m_cctx, m_scale);
}
glutils::FrameBuffer const&SceneEditorView::framebuffer() const noexcept {
return m_frameBuffer;
}
}

View File

@ -1,37 +0,0 @@
/*
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#pragma once
#include <glutils/glutils.hpp>
#include <nostalgia/gfx/context.hpp>
#include <nostalgia/gfx/gfx.hpp>
#include <nostalgia/scene/scene.hpp>
namespace nostalgia::scene {
class SceneEditorView {
private:
ox::UPtr<gfx::Context> m_cctx;
SceneStatic const&m_sceneStatic;
Scene m_scene;
glutils::FrameBuffer m_frameBuffer;
int m_scale = 1;
ox::Size m_scaleSz = gfx::gl::drawSize(m_scale);
public:
SceneEditorView(turbine::Context &ctx, SceneStatic const&sceneStatic);
ox::Error setupScene() noexcept;
void draw(ox::Size const&targetSz) noexcept;
[[nodiscard]]
glutils::FrameBuffer const&framebuffer() const noexcept;
};
}

View File

@ -1,30 +0,0 @@
/*
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#include <studio/studio.hpp>
#include "sceneeditor-imgui.hpp"
namespace nostalgia::scene {
constexpr ox::StringLiteral FileExt_nscn("nscn");
static class: public studio::Module {
public:
ox::Vector<studio::EditorMaker> editors(studio::StudioContext &ctx) const noexcept override {
return {
studio::editorMaker<SceneEditorImGui>(ctx, FileExt_nscn),
};
}
ox::Vector<ox::UPtr<studio::ItemMaker>> itemMakers(studio::StudioContext&) const noexcept override {
ox::Vector<ox::UPtr<studio::ItemMaker>> out;
return out;
}
} mod;
const studio::Module *studioModule() noexcept {
return &mod;
}
}

View File

@ -6,7 +6,7 @@
#include <keel/module.hpp>
namespace nostalgia::scene {
namespace nostalgia::sound {
const keel::Module *keelModule() noexcept;

View File

@ -6,7 +6,7 @@
#include <studio/studio.hpp>
namespace nostalgia::scene {
namespace nostalgia::sound {
const studio::Module *studioModule() noexcept;

View File

@ -6,7 +6,7 @@
#include <studio/studio.hpp>
namespace nostalgia::gfx {
namespace nostalgia::sound {
static class: public studio::Module {
ox::Vector<studio::EditorMaker> editors(studio::StudioContext&) const noexcept final {

View File

@ -5,7 +5,7 @@
#include <studioapp/studioapp.hpp>
#include <nostalgia/gfx/studiomodule.hpp>
#include <nostalgia/scene/studiomodule.hpp>
#include <nostalgia/sound/studiomodule.hpp>
namespace nostalgia {
@ -16,7 +16,7 @@ void registerStudioModules() noexcept {
}
modulesRegistered = true;
studio::registerModule(gfx::studioModule());
studio::registerModule(scene::studioModule());
studio::registerModule(sound::studioModule());
}
}

View File

@ -6,7 +6,6 @@
#include <turbine/turbine.hpp>
#include <nostalgia/gfx/core.hpp>
#include <nostalgia/scene/scene.hpp>
using namespace nostalgia;
@ -126,41 +125,11 @@ static ox::Error runTileSheetSetTest(turbine::Context &tctx) {
}
static int sceneUpdateHandler(turbine::Context&) noexcept {
constexpr auto sleepTime = 16;
if (s_paused) {
return sleepTime;
}
// do stuff
return sleepTime;
}
static void sceneKeyEventHandler(turbine::Context &tctx, turbine::Key key, bool down) noexcept {
if (down) {
if (key == turbine::Key::Alpha_Q) {
turbine::requestShutdown(tctx);
} else if (key == turbine::Key::Alpha_P) {
s_paused = !s_paused;
}
}
}
[[maybe_unused]]
static ox::Error runScene(turbine::Context &tctx) {
OX_REQUIRE_M(cctx, gfx::init(tctx));
OX_REQUIRE(scn, keel::readObj<scene::SceneStatic>(keelCtx(tctx), "/Scenes/Chester.nscn"));
turbine::setUpdateHandler(tctx, sceneUpdateHandler);
turbine::setKeyEventHandler(tctx, sceneKeyEventHandler);
scene::Scene const scene(*scn);
OX_RETURN_ERROR(scene.setupDisplay(*cctx));
return turbine::run(tctx);
}
ox::Error run(
[[maybe_unused]] ox::StringView project,
[[maybe_unused]] ox::StringView appName,
[[maybe_unused]] ox::StringView projectDataDir,
ox::SpanView<char const*> args) noexcept {
ox::SpanView<ox::CString> args) noexcept {
if (args.size() < 2) {
return ox::Error{1, "Please provide path to project directory or OxFS file."};
}

View File

@ -1,17 +1,17 @@
add_library(
StudioAppLib
aboutpopup.cpp
app.cpp
clawviewer.cpp
deleteconfirmation.cpp
filedialogmanager.cpp
main.cpp
makecopypopup.cpp
newdir.cpp
newmenu.cpp
newproject.cpp
projectexplorer.cpp
renamefile.cpp
studioapp.cpp
studioui.cpp
)
target_compile_definitions(
StudioAppLib PUBLIC

View File

@ -11,8 +11,7 @@
#include <turbine/turbine.hpp>
#include <studio/context.hpp>
#include <studioapp/studioapp.hpp>
#include "studioapp.hpp"
#include "studioui.hpp"
namespace studio {

View File

@ -14,7 +14,7 @@
#include <studio/configio.hpp>
#include "clawviewer.hpp"
#include "filedialogmanager.hpp"
#include "studioapp.hpp"
#include "studioui.hpp"
namespace studio {