[nostalgia,studio] Make module handling consistent

This commit is contained in:
Gary Talent 2023-06-03 14:44:33 -05:00
parent 2874620bc6
commit ed169eb9b8
34 changed files with 257 additions and 209 deletions

View File

@ -1,22 +1,35 @@
add_library(
NostalgiaAppModules OBJECT
appmodules.cpp
NostalgiaKeelModules OBJECT
keelmodules.cpp
)
if(NOT MSVC)
target_compile_options(NostalgiaAppModules PRIVATE -Wsign-conversion)
endif()
target_link_libraries(
NostalgiaAppModules PUBLIC
NostalgiaKeelModules PUBLIC
Keel
NostalgiaCore
NostalgiaScene
)
if(NOT MSVC)
target_compile_options(NostalgiaKeelModules PRIVATE -Wsign-conversion)
endif()
install(
FILES
appmodules.hpp
keelmodules.hpp
DESTINATION
include/nostalgia/appmodules
)
if(NOSTALGIA_BUILD_TYPE STREQUAL "Native")
add_library(
NostalgiaStudioModules
studiomodules.cpp
)
target_link_libraries(
NostalgiaStudioModules PUBLIC
StudioAppLib
NostalgiaCore-Studio
NostalgiaScene-Studio
)
if(NOT MSVC)
target_compile_options(NostalgiaStudioModules PRIVATE -Wsign-conversion)
endif()
endif()

View File

@ -1,22 +0,0 @@
/*
* Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#include <keel/module.hpp>
#include <nostalgia/core/module.hpp>
#include <nostalgia/scene/scenemodule.hpp>
namespace nostalgia {
static bool modulesLoaded = false;
void loadModules() noexcept {
if (modulesLoaded) {
return;
}
keel::registerModule(core::module());
keel::registerModule(scene::module());
modulesLoaded = true;
}
}

View File

@ -0,0 +1,22 @@
/*
* Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#include <keel/module.hpp>
#include <nostalgia/core/keelmodule.hpp>
#include <nostalgia/scene/keelmodule.hpp>
namespace nostalgia {
static bool modulesRegistered = false;
void registerKeelModules() noexcept {
if (modulesRegistered) {
return;
}
keel::registerModule(core::keelModule());
keel::registerModule(scene::keelModule());
modulesRegistered = true;
}
}

View File

@ -6,6 +6,6 @@
namespace nostalgia {
void loadModules() noexcept;
void registerKeelModules() noexcept;
}

View File

@ -0,0 +1,24 @@
/*
* Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#include <keel/module.hpp>
#include <studioapp/studioapp.hpp>
#include <nostalgia/core/studio/studiomodule.hpp>
#include <nostalgia/scene/studio/studiomodule.hpp>
namespace nostalgia {
static bool modulesRegistered = false;
void registerStudioModules() noexcept {
if (modulesRegistered) {
return;
}
studio::registerModule(core::studioModule());
studio::registerModule(scene::studioModule());
modulesRegistered = true;
}
}

View File

@ -0,0 +1,11 @@
/*
* Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#pragma once
namespace nostalgia {
void registerStudioModules() noexcept;
}

View File

@ -2,7 +2,7 @@ add_library(
NostalgiaCore
context.cpp
gfx.cpp
module.cpp
keelmodule.cpp
tilesheet.cpp
typeconv.cpp
)

View File

@ -0,0 +1,71 @@
/*
* Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#include <ox/model/model.hpp>
#include <keel/asset.hpp>
#include <keel/module.hpp>
#include "gfx.hpp"
#include "typeconv.hpp"
#include "keelmodule.hpp"
namespace nostalgia::core {
class CoreModule: public keel::Module {
private:
NostalgiaPaletteToPaletteConverter nostalgiaPaletteToPaletteConverter;
TileSheetV1ToTileSheetConverter nostalgiaGraphicToTileSheetConverter;
TileSheetToCompactTileSheetConverter tileSheetToCompactTileSheetConverter;
TileSheetV2ToTileSheetConverter tileSheetV2ToTileSheetConverter;
public:
[[nodiscard]]
ox::Vector<keel::TypeDescGenerator> types() const noexcept final {
return {
keel::generateTypeDesc<TileSheetV1>,
keel::generateTypeDesc<TileSheetV2>,
keel::generateTypeDesc<TileSheet>,
keel::generateTypeDesc<CompactTileSheet>,
keel::generateTypeDesc<NostalgiaPalette>,
keel::generateTypeDesc<Palette>,
};
}
[[nodiscard]]
ox::Vector<const keel::BaseConverter*> converters() const noexcept final {
return {
&nostalgiaPaletteToPaletteConverter,
&nostalgiaGraphicToTileSheetConverter,
&tileSheetToCompactTileSheetConverter,
&tileSheetV2ToTileSheetConverter,
};
}
[[nodiscard]]
ox::Vector<keel::PackTransform> packTransforms() const noexcept final {
return {
// convert tilesheets to CompactTileSheets
[](keel::Context *ctx, ox::Buffer *buff) -> ox::Error {
oxRequire(hdr, keel::readAssetHeader(*buff));
const auto typeId = ox::buildTypeId(hdr.clawHdr.typeName, hdr.clawHdr.typeVersion, hdr.clawHdr.typeParams);
if (typeId == ox::buildTypeId<TileSheetV1>() ||
typeId == ox::buildTypeId<TileSheetV2>() ||
typeId == ox::buildTypeId<TileSheet>()) {
oxReturnError(keel::convertBuffToBuff<core::CompactTileSheet>(
ctx, *buff, ox::ClawFormat::Metal).moveTo(buff));
}
return {};
},
};
}
};
static CoreModule mod;
const keel::Module *keelModule() noexcept {
return &mod;
}
}

View File

@ -8,6 +8,6 @@
namespace nostalgia::core {
const keel::Module *module() noexcept;
const keel::Module *keelModule() noexcept;
}

View File

@ -1,77 +0,0 @@
/*
* Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#include <ox/model/model.hpp>
#include <keel/asset.hpp>
#include <keel/module.hpp>
#include "gfx.hpp"
#include "typeconv.hpp"
#include "module.hpp"
namespace nostalgia::core {
class CoreModule: public keel::Module {
private:
NostalgiaPaletteToPaletteConverter nostalgiaPaletteToPaletteConverter;
TileSheetV1ToTileSheetConverter nostalgiaGraphicToTileSheetConverter;
TileSheetToCompactTileSheetConverter tileSheetToCompactTileSheetConverter;
TileSheetV2ToTileSheetConverter tileSheetV2ToTileSheetConverter;
public:
static CoreModule mod;
[[nodiscard]]
ox::Vector<keel::TypeDescGenerator> types() const noexcept override;
[[nodiscard]]
ox::Vector<const keel::BaseConverter*> converters() const noexcept override;
[[nodiscard]]
ox::Vector<keel::PackTransform> packTransforms() const noexcept override;
};
CoreModule CoreModule::mod;
const keel::Module *module() noexcept {
return &CoreModule::mod;
}
ox::Vector<keel::TypeDescGenerator> CoreModule::types() const noexcept {
return {
keel::generateTypeDesc<TileSheetV1>,
keel::generateTypeDesc<TileSheetV2>,
keel::generateTypeDesc<TileSheet>,
keel::generateTypeDesc<CompactTileSheet>,
keel::generateTypeDesc<NostalgiaPalette>,
keel::generateTypeDesc<Palette>,
};
}
ox::Vector<const keel::BaseConverter*> CoreModule::converters() const noexcept {
return {
&nostalgiaPaletteToPaletteConverter,
&nostalgiaGraphicToTileSheetConverter,
&tileSheetToCompactTileSheetConverter,
&tileSheetV2ToTileSheetConverter,
};
}
ox::Vector<keel::PackTransform> CoreModule::packTransforms() const noexcept {
return {
// convert tilesheets to CompactTileSheets
[](keel::Context *ctx, ox::Buffer *buff) -> ox::Error {
oxRequire(hdr, keel::readAssetHeader(*buff));
const auto typeId = ox::buildTypeId(hdr.clawHdr.typeName, hdr.clawHdr.typeVersion, hdr.clawHdr.typeParams);
if (typeId == ox::buildTypeId<TileSheetV1>() ||
typeId == ox::buildTypeId<TileSheetV2>() ||
typeId == ox::buildTypeId<TileSheet>()) {
oxReturnError(keel::convertBuffToBuff<core::CompactTileSheet>(
ctx, *buff, ox::ClawFormat::Metal).moveTo(buff));
}
return {};
},
};
}
}

View File

@ -1,6 +1,6 @@
add_library(
NostalgiaCore-Studio OBJECT
module.cpp
studiomodule.cpp
paletteeditor.cpp
paletteeditor-imgui.cpp
tilesheeteditor-imgui.cpp

View File

@ -1,17 +0,0 @@
/*
* Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#pragma once
#include <studio/studio.hpp>
namespace nostalgia::core {
class StudioModule: public studio::Module {
public:
ox::Vector<studio::EditorMaker> editors(turbine::Context *ctx) noexcept override;
ox::Vector<ox::UniquePtr<studio::ItemMaker>> itemMakers(turbine::Context*) noexcept override;
};
}

View File

@ -7,11 +7,17 @@
#include "paletteeditor-imgui.hpp"
#include "tilesheeteditor-imgui.hpp"
#include "module.hpp"
#include "studiomodule.hpp"
namespace nostalgia::core {
ox::Vector<studio::EditorMaker> StudioModule::editors(turbine::Context *ctx) noexcept {
class StudioModule: public studio::Module {
public:
ox::Vector<studio::EditorMaker> editors(turbine::Context *ctx) const noexcept override;
ox::Vector<ox::UniquePtr<studio::ItemMaker>> itemMakers(turbine::Context*) const noexcept override;
};
ox::Vector<studio::EditorMaker> StudioModule::editors(turbine::Context *ctx) const noexcept {
return {
{
{FileExt_ng},
@ -32,11 +38,16 @@ ox::Vector<studio::EditorMaker> StudioModule::editors(turbine::Context *ctx) noe
};
}
ox::Vector<ox::UniquePtr<studio::ItemMaker>> StudioModule::itemMakers(turbine::Context*) noexcept {
ox::Vector<ox::UniquePtr<studio::ItemMaker>> StudioModule::itemMakers(turbine::Context*) const noexcept {
ox::Vector<ox::UniquePtr<studio::ItemMaker>> out;
out.emplace_back(ox::make<studio::ItemMakerT<core::TileSheet>>("Tile Sheet", "TileSheets", "ng"));
out.emplace_back(ox::make<studio::ItemMakerT<core::Palette>>("Palette", "Palettes", "npal"));
return out;
}
static StudioModule mod;
const studio::Module *studioModule() noexcept {
return &mod;
}
}

View File

@ -0,0 +1,13 @@
/*
* Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#pragma once
#include <studio/studio.hpp>
namespace nostalgia::core {
const studio::Module *studioModule() noexcept;
}

View File

@ -22,7 +22,7 @@ endif()
target_link_libraries(
nostalgia
NostalgiaAppModules
NostalgiaKeelModules
OxLogConn
)

View File

@ -8,7 +8,7 @@
#include <nostalgia/core/core.hpp>
#include <nostalgia/appmodules/appmodules.hpp>
#include <nostalgia/appmodules/keelmodules.hpp>
#include "app.hpp"
@ -17,7 +17,7 @@ static ox::Error run(int argc, const char **argv) noexcept {
#ifdef OX_USE_STDLIB
// GBA doesn't need the modules and calling this doubles the size of the
// binary.
nostalgia::loadModules();
nostalgia::registerKeelModules();
#endif
if (argc < 2) {
oxErr("Please provide path to project directory or OxFS file.\n");

View File

@ -3,7 +3,7 @@ add_library(
NostalgiaScene
scene.cpp
scenestatic.cpp
scenemodule.cpp
keelmodule.cpp
typeconv.cpp
)
@ -15,7 +15,7 @@ target_link_libraries(
install(
FILES
scenestatic.hpp
scenemodule.hpp
keelmodule.hpp
typeconv.hpp
DESTINATION
include/nostalgia/scene

View File

@ -2,12 +2,10 @@
* Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#include <ox/model/model.hpp>
#include "scenestatic.hpp"
#include "typeconv.hpp"
#include "scenemodule.hpp"
#include "keelmodule.hpp"
namespace nostalgia::scene {
@ -41,7 +39,7 @@ class SceneModule: public keel::Module {
};
static SceneModule mod;
const keel::Module *module() noexcept {
const keel::Module *keelModule() noexcept {
return &mod;
}

View File

@ -8,6 +8,6 @@
namespace nostalgia::scene {
const keel::Module *module() noexcept;
const keel::Module *keelModule() noexcept;
}

View File

@ -1,6 +1,6 @@
add_library(
NostalgiaScene-Studio OBJECT
module.cpp
studiomodule.cpp
sceneeditor-imgui.cpp
sceneeditor.cpp
sceneeditorview.cpp

View File

@ -1,18 +0,0 @@
/*
* Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#pragma once
#include <turbine/turbine.hpp>
#include <studio/studio.hpp>
namespace nostalgia::scene {
class StudioModule: public studio::Module {
public:
ox::Vector<studio::EditorMaker> editors(turbine::Context *ctx) noexcept override;
ox::Vector<ox::UPtr<studio::ItemMaker>> itemMakers(turbine::Context*) noexcept override;
};
}

View File

@ -3,11 +3,17 @@
*/
#include "sceneeditor-imgui.hpp"
#include "module.hpp"
#include "studiomodule.hpp"
namespace nostalgia::scene {
ox::Vector<studio::EditorMaker> StudioModule::editors(turbine::Context *ctx) noexcept {
class StudioModule: public studio::Module {
public:
ox::Vector<studio::EditorMaker> editors(turbine::Context *ctx) const noexcept override;
ox::Vector<ox::UPtr<studio::ItemMaker>> itemMakers(turbine::Context*) const noexcept override;
};
ox::Vector<studio::EditorMaker> StudioModule::editors(turbine::Context *ctx) const noexcept {
return {
{
{"nscn"},
@ -18,9 +24,14 @@ ox::Vector<studio::EditorMaker> StudioModule::editors(turbine::Context *ctx) noe
};
}
ox::Vector<ox::UPtr<studio::ItemMaker>> StudioModule::itemMakers(turbine::Context*) noexcept {
ox::Vector<ox::UPtr<studio::ItemMaker>> StudioModule::itemMakers(turbine::Context*) const noexcept {
ox::Vector<ox::UPtr<studio::ItemMaker>> out;
return out;
}
static StudioModule mod;
const studio::Module *studioModule() noexcept {
return &mod;
}
}

View File

@ -0,0 +1,14 @@
/*
* Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#pragma once
#include <turbine/turbine.hpp>
#include <studio/studio.hpp>
namespace nostalgia::scene {
const studio::Module *studioModule() noexcept;
}

View File

@ -7,9 +7,8 @@ add_executable(
target_link_libraries(
nostalgia-studio
NostalgiaAppModules
NostalgiaCore-Studio
NostalgiaScene-Studio
NostalgiaStudioModules
NostalgiaKeelModules
StudioAppLib
)
@ -35,4 +34,4 @@ install(
RUNTIME DESTINATION
${NOSTALGIA_DIST_BIN}
BUNDLE DESTINATION .
)
)

View File

@ -2,27 +2,13 @@
* Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#include <ox/std/memory.hpp>
#include <nostalgia/appmodules/appmodules.hpp>
#include <nostalgia/core/studio/module.hpp>
#include <nostalgia/scene/studio/module.hpp>
#include <nostalgia/appmodules/keelmodules.hpp>
#include <nostalgia/appmodules/studiomodules.hpp>
#include <studioapp/studioapp.hpp>
using namespace nostalgia;
[[maybe_unused]] // GCC warns about the existence of this "unused" inline list in a header file...
ox::Vector<std::function<ox::UPtr<studio::Module>()>> BuiltinModules = {
[]() -> ox::UPtr<studio::Module> {
return ox::UPtr<studio::Module>(new core::StudioModule());
},
[]() -> ox::UPtr<studio::Module> {
return ox::UPtr<studio::Module>(new scene::StudioModule());
},
};
int main(int argc, const char **argv) {
nostalgia::loadModules();
nostalgia::registerKeelModules();
nostalgia::registerStudioModules();
return studio::main("Nostalgia Studio", ".nostalgia", argc, argv);
}
}

View File

@ -5,7 +5,7 @@ target_link_libraries(
OxClArgs
OxLogConn
Keel
NostalgiaAppModules
NostalgiaKeelModules
)
if(CMAKE_BUILD_TYPE STREQUAL "Release" AND NOT WIN32)

View File

@ -10,7 +10,7 @@
#include <keel/keel.hpp>
#include <nostalgia/appmodules/appmodules.hpp>
#include <nostalgia/appmodules/keelmodules.hpp>
using namespace nostalgia;
@ -52,7 +52,7 @@ static ox::Error generateTypes(ox::TypeStore *ts) noexcept {
}
static ox::Error run(const ox::ClArgs &args) noexcept {
loadModules();
registerKeelModules();
const auto argSrc = args.getString("src", "");
const auto argRomBin = args.getString("rom-bin", "");
if (argSrc == "") {

View File

@ -6,12 +6,16 @@
#include <ox/std/string.hpp>
#include <studio/module.hpp>
namespace studio {
void registerModule(const studio::Module*) noexcept;
int main(
const char *appName,
ox::String projectDataDir,
[[maybe_unused]] int argc,
[[maybe_unused]] const char **argv);
int argc,
const char **argv);
}

View File

@ -1,5 +1,3 @@
set(CMAKE_INCLUDE_CURRENT_DIR ON)
add_library(
StudioAppLib
aboutpopup.cpp

View File

@ -10,8 +10,6 @@
#include <keel/media.hpp>
#include <turbine/turbine.hpp>
#include <nostalgia/appmodules/appmodules.hpp>
#include <studio/context.hpp>
#include "studioapp.hpp"
@ -65,8 +63,8 @@ namespace studio {
int main(
const char *appName,
ox::String projectDataDir,
[[maybe_unused]] int argc,
[[maybe_unused]] const char **argv) {
int,
const char **) {
#ifdef DEBUG
ox::LoggerConn loggerConn;
const auto loggerErr = loggerConn.initConn(appName);
@ -88,4 +86,4 @@ int main(
return static_cast<int>(err);
}
}
}

View File

@ -13,6 +13,8 @@
#include "filedialogmanager.hpp"
#include "studioapp.hpp"
ox::Vector<const studio::Module*> modules;
struct StudioConfig {
static constexpr auto TypeName = "net.drinkingtea.studio.StudioConfig";
static constexpr auto TypeVersion = 1;
@ -246,7 +248,7 @@ void StudioUI::loadEditorMaker(const studio::EditorMaker &editorMaker) noexcept
}
}
void StudioUI::loadModule(studio::Module *mod) noexcept {
void StudioUI::loadModule(const studio::Module *mod) noexcept {
for (const auto &editorMaker : mod->editors(m_ctx)) {
loadEditorMaker(editorMaker);
}
@ -256,9 +258,8 @@ void StudioUI::loadModule(studio::Module *mod) noexcept {
}
void StudioUI::loadModules() noexcept {
for (auto &moduleMaker : BuiltinModules) {
const auto mod = moduleMaker();
loadModule(mod.get());
for (auto &mod : modules) {
loadModule(mod);
}
}
@ -369,3 +370,11 @@ ox::Error StudioUI::closeFile(const ox::String &path) noexcept {
});
return OxError(0);
}
namespace studio {
void registerModule(const studio::Module *mod) noexcept {
modules.emplace_back(mod);
}
}

View File

@ -65,7 +65,7 @@ class StudioUI: public ox::SignalHandler {
void loadEditorMaker(const studio::EditorMaker &editorMaker) noexcept;
void loadModule(studio::Module *mod) noexcept;
void loadModule(const studio::Module *mod) noexcept;
void loadModules() noexcept;

View File

@ -25,9 +25,9 @@ class Module {
public:
virtual ~Module() noexcept = default;
virtual ox::Vector<EditorMaker> editors(turbine::Context *ctx);
virtual ox::Vector<EditorMaker> editors(turbine::Context *ctx) const;
virtual ox::Vector<ox::UniquePtr<ItemMaker>> itemMakers(turbine::Context*);
virtual ox::Vector<ox::UniquePtr<ItemMaker>> itemMakers(turbine::Context*) const;
};

View File

@ -6,11 +6,11 @@
namespace studio {
ox::Vector<EditorMaker> Module::editors(turbine::Context*) {
ox::Vector<EditorMaker> Module::editors(turbine::Context*) const {
return {};
}
ox::Vector<ox::UniquePtr<ItemMaker>> Module::itemMakers(turbine::Context*) {
ox::Vector<ox::UniquePtr<ItemMaker>> Module::itemMakers(turbine::Context*) const {
return {};
}