From ed169eb9b8e418238d642b1394c2c1a3c52fcff6 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Sat, 3 Jun 2023 14:44:33 -0500 Subject: [PATCH] [nostalgia,studio] Make module handling consistent --- src/nostalgia/appmodules/CMakeLists.txt | 33 +++++--- src/nostalgia/appmodules/appmodules.cpp | 22 ------ src/nostalgia/appmodules/keelmodules.cpp | 22 ++++++ .../{appmodules.hpp => keelmodules.hpp} | 2 +- src/nostalgia/appmodules/studiomodules.cpp | 24 ++++++ src/nostalgia/appmodules/studiomodules.hpp | 11 +++ src/nostalgia/core/CMakeLists.txt | 2 +- src/nostalgia/core/keelmodule.cpp | 71 +++++++++++++++++ .../core/{module.hpp => keelmodule.hpp} | 2 +- src/nostalgia/core/module.cpp | 77 ------------------- src/nostalgia/core/studio/CMakeLists.txt | 2 +- src/nostalgia/core/studio/module.hpp | 17 ---- .../studio/{module.cpp => studiomodule.cpp} | 17 +++- src/nostalgia/core/studio/studiomodule.hpp | 13 ++++ src/nostalgia/player/CMakeLists.txt | 2 +- src/nostalgia/player/main.cpp | 4 +- src/nostalgia/scene/CMakeLists.txt | 4 +- .../scene/{scenemodule.cpp => keelmodule.cpp} | 6 +- .../scene/{scenemodule.hpp => keelmodule.hpp} | 2 +- src/nostalgia/scene/studio/CMakeLists.txt | 2 +- src/nostalgia/scene/studio/module.hpp | 18 ----- .../studio/{module.cpp => studiomodule.cpp} | 17 +++- src/nostalgia/scene/studio/studiomodule.hpp | 14 ++++ src/nostalgia/studio/CMakeLists.txt | 7 +- src/nostalgia/studio/main.cpp | 24 ++---- src/nostalgia/tools/CMakeLists.txt | 2 +- src/nostalgia/tools/pack.cpp | 4 +- .../applib/include/studioapp/studioapp.hpp | 8 +- src/studio/applib/src/CMakeLists.txt | 2 - src/studio/applib/src/main.cpp | 8 +- src/studio/applib/src/studioapp.cpp | 17 +++- src/studio/applib/src/studioapp.hpp | 2 +- src/studio/modlib/include/studio/module.hpp | 4 +- src/studio/modlib/src/module.cpp | 4 +- 34 files changed, 257 insertions(+), 209 deletions(-) delete mode 100644 src/nostalgia/appmodules/appmodules.cpp create mode 100644 src/nostalgia/appmodules/keelmodules.cpp rename src/nostalgia/appmodules/{appmodules.hpp => keelmodules.hpp} (77%) create mode 100644 src/nostalgia/appmodules/studiomodules.cpp create mode 100644 src/nostalgia/appmodules/studiomodules.hpp create mode 100644 src/nostalgia/core/keelmodule.cpp rename src/nostalgia/core/{module.hpp => keelmodule.hpp} (79%) delete mode 100644 src/nostalgia/core/module.cpp delete mode 100644 src/nostalgia/core/studio/module.hpp rename src/nostalgia/core/studio/{module.cpp => studiomodule.cpp} (69%) create mode 100644 src/nostalgia/core/studio/studiomodule.hpp rename src/nostalgia/scene/{scenemodule.cpp => keelmodule.cpp} (89%) rename src/nostalgia/scene/{scenemodule.hpp => keelmodule.hpp} (79%) delete mode 100644 src/nostalgia/scene/studio/module.hpp rename src/nostalgia/scene/studio/{module.cpp => studiomodule.cpp} (54%) create mode 100644 src/nostalgia/scene/studio/studiomodule.hpp diff --git a/src/nostalgia/appmodules/CMakeLists.txt b/src/nostalgia/appmodules/CMakeLists.txt index 23bc4e321..d63c2ae29 100644 --- a/src/nostalgia/appmodules/CMakeLists.txt +++ b/src/nostalgia/appmodules/CMakeLists.txt @@ -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() \ No newline at end of file diff --git a/src/nostalgia/appmodules/appmodules.cpp b/src/nostalgia/appmodules/appmodules.cpp deleted file mode 100644 index cac111f50..000000000 --- a/src/nostalgia/appmodules/appmodules.cpp +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved. - */ - -#include - -#include -#include - -namespace nostalgia { - -static bool modulesLoaded = false; -void loadModules() noexcept { - if (modulesLoaded) { - return; - } - keel::registerModule(core::module()); - keel::registerModule(scene::module()); - modulesLoaded = true; -} - -} diff --git a/src/nostalgia/appmodules/keelmodules.cpp b/src/nostalgia/appmodules/keelmodules.cpp new file mode 100644 index 000000000..cff299582 --- /dev/null +++ b/src/nostalgia/appmodules/keelmodules.cpp @@ -0,0 +1,22 @@ +/* + * Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved. + */ + +#include + +#include +#include + +namespace nostalgia { + +static bool modulesRegistered = false; +void registerKeelModules() noexcept { + if (modulesRegistered) { + return; + } + keel::registerModule(core::keelModule()); + keel::registerModule(scene::keelModule()); + modulesRegistered = true; +} + +} diff --git a/src/nostalgia/appmodules/appmodules.hpp b/src/nostalgia/appmodules/keelmodules.hpp similarity index 77% rename from src/nostalgia/appmodules/appmodules.hpp rename to src/nostalgia/appmodules/keelmodules.hpp index cf82c6d6f..6c8ea012f 100644 --- a/src/nostalgia/appmodules/appmodules.hpp +++ b/src/nostalgia/appmodules/keelmodules.hpp @@ -6,6 +6,6 @@ namespace nostalgia { -void loadModules() noexcept; +void registerKeelModules() noexcept; } diff --git a/src/nostalgia/appmodules/studiomodules.cpp b/src/nostalgia/appmodules/studiomodules.cpp new file mode 100644 index 000000000..f22c7c231 --- /dev/null +++ b/src/nostalgia/appmodules/studiomodules.cpp @@ -0,0 +1,24 @@ +/* + * Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved. + */ + +#include + +#include + +#include +#include + +namespace nostalgia { + +static bool modulesRegistered = false; +void registerStudioModules() noexcept { + if (modulesRegistered) { + return; + } + studio::registerModule(core::studioModule()); + studio::registerModule(scene::studioModule()); + modulesRegistered = true; +} + +} diff --git a/src/nostalgia/appmodules/studiomodules.hpp b/src/nostalgia/appmodules/studiomodules.hpp new file mode 100644 index 000000000..86328df98 --- /dev/null +++ b/src/nostalgia/appmodules/studiomodules.hpp @@ -0,0 +1,11 @@ +/* + * Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved. + */ + +#pragma once + +namespace nostalgia { + +void registerStudioModules() noexcept; + +} \ No newline at end of file diff --git a/src/nostalgia/core/CMakeLists.txt b/src/nostalgia/core/CMakeLists.txt index 3c6035c7e..e8288180f 100644 --- a/src/nostalgia/core/CMakeLists.txt +++ b/src/nostalgia/core/CMakeLists.txt @@ -2,7 +2,7 @@ add_library( NostalgiaCore context.cpp gfx.cpp - module.cpp + keelmodule.cpp tilesheet.cpp typeconv.cpp ) diff --git a/src/nostalgia/core/keelmodule.cpp b/src/nostalgia/core/keelmodule.cpp new file mode 100644 index 000000000..622e4b3ec --- /dev/null +++ b/src/nostalgia/core/keelmodule.cpp @@ -0,0 +1,71 @@ +/* + * Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved. + */ + +#include + +#include +#include + +#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 types() const noexcept final { + return { + keel::generateTypeDesc, + keel::generateTypeDesc, + keel::generateTypeDesc, + keel::generateTypeDesc, + keel::generateTypeDesc, + keel::generateTypeDesc, + }; + } + + [[nodiscard]] + ox::Vector converters() const noexcept final { + return { + &nostalgiaPaletteToPaletteConverter, + &nostalgiaGraphicToTileSheetConverter, + &tileSheetToCompactTileSheetConverter, + &tileSheetV2ToTileSheetConverter, + }; + } + + [[nodiscard]] + ox::Vector 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() || + typeId == ox::buildTypeId() || + typeId == ox::buildTypeId()) { + oxReturnError(keel::convertBuffToBuff( + ctx, *buff, ox::ClawFormat::Metal).moveTo(buff)); + } + return {}; + }, + }; + } +}; + +static CoreModule mod; +const keel::Module *keelModule() noexcept { + return &mod; +} + +} diff --git a/src/nostalgia/core/module.hpp b/src/nostalgia/core/keelmodule.hpp similarity index 79% rename from src/nostalgia/core/module.hpp rename to src/nostalgia/core/keelmodule.hpp index 447fefb46..fb692b7a8 100644 --- a/src/nostalgia/core/module.hpp +++ b/src/nostalgia/core/keelmodule.hpp @@ -8,6 +8,6 @@ namespace nostalgia::core { -const keel::Module *module() noexcept; +const keel::Module *keelModule() noexcept; } diff --git a/src/nostalgia/core/module.cpp b/src/nostalgia/core/module.cpp deleted file mode 100644 index a6bb768dd..000000000 --- a/src/nostalgia/core/module.cpp +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved. - */ - -#include - -#include -#include - -#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 types() const noexcept override; - [[nodiscard]] - ox::Vector converters() const noexcept override; - [[nodiscard]] - ox::Vector packTransforms() const noexcept override; -}; - -CoreModule CoreModule::mod; - -const keel::Module *module() noexcept { - return &CoreModule::mod; -} - -ox::Vector CoreModule::types() const noexcept { - return { - keel::generateTypeDesc, - keel::generateTypeDesc, - keel::generateTypeDesc, - keel::generateTypeDesc, - keel::generateTypeDesc, - keel::generateTypeDesc, - }; -} - -ox::Vector CoreModule::converters() const noexcept { - return { - &nostalgiaPaletteToPaletteConverter, - &nostalgiaGraphicToTileSheetConverter, - &tileSheetToCompactTileSheetConverter, - &tileSheetV2ToTileSheetConverter, - }; -} - -ox::Vector 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() || - typeId == ox::buildTypeId() || - typeId == ox::buildTypeId()) { - oxReturnError(keel::convertBuffToBuff( - ctx, *buff, ox::ClawFormat::Metal).moveTo(buff)); - } - return {}; - }, - }; -} - -} diff --git a/src/nostalgia/core/studio/CMakeLists.txt b/src/nostalgia/core/studio/CMakeLists.txt index b9a4cc65c..d7f6629e5 100644 --- a/src/nostalgia/core/studio/CMakeLists.txt +++ b/src/nostalgia/core/studio/CMakeLists.txt @@ -1,6 +1,6 @@ add_library( NostalgiaCore-Studio OBJECT - module.cpp + studiomodule.cpp paletteeditor.cpp paletteeditor-imgui.cpp tilesheeteditor-imgui.cpp diff --git a/src/nostalgia/core/studio/module.hpp b/src/nostalgia/core/studio/module.hpp deleted file mode 100644 index bee37421c..000000000 --- a/src/nostalgia/core/studio/module.hpp +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved. - */ - -#pragma once - -#include - -namespace nostalgia::core { - -class StudioModule: public studio::Module { - public: - ox::Vector editors(turbine::Context *ctx) noexcept override; - ox::Vector> itemMakers(turbine::Context*) noexcept override; -}; - -} diff --git a/src/nostalgia/core/studio/module.cpp b/src/nostalgia/core/studio/studiomodule.cpp similarity index 69% rename from src/nostalgia/core/studio/module.cpp rename to src/nostalgia/core/studio/studiomodule.cpp index 54f47ce30..2b665a201 100644 --- a/src/nostalgia/core/studio/module.cpp +++ b/src/nostalgia/core/studio/studiomodule.cpp @@ -7,11 +7,17 @@ #include "paletteeditor-imgui.hpp" #include "tilesheeteditor-imgui.hpp" -#include "module.hpp" +#include "studiomodule.hpp" namespace nostalgia::core { -ox::Vector StudioModule::editors(turbine::Context *ctx) noexcept { +class StudioModule: public studio::Module { + public: + ox::Vector editors(turbine::Context *ctx) const noexcept override; + ox::Vector> itemMakers(turbine::Context*) const noexcept override; +}; + +ox::Vector StudioModule::editors(turbine::Context *ctx) const noexcept { return { { {FileExt_ng}, @@ -32,11 +38,16 @@ ox::Vector StudioModule::editors(turbine::Context *ctx) noe }; } -ox::Vector> StudioModule::itemMakers(turbine::Context*) noexcept { +ox::Vector> StudioModule::itemMakers(turbine::Context*) const noexcept { ox::Vector> out; out.emplace_back(ox::make>("Tile Sheet", "TileSheets", "ng")); out.emplace_back(ox::make>("Palette", "Palettes", "npal")); return out; } +static StudioModule mod; +const studio::Module *studioModule() noexcept { + return &mod; +} + } diff --git a/src/nostalgia/core/studio/studiomodule.hpp b/src/nostalgia/core/studio/studiomodule.hpp new file mode 100644 index 000000000..c14b11ce8 --- /dev/null +++ b/src/nostalgia/core/studio/studiomodule.hpp @@ -0,0 +1,13 @@ +/* + * Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved. + */ + +#pragma once + +#include + +namespace nostalgia::core { + +const studio::Module *studioModule() noexcept; + +} diff --git a/src/nostalgia/player/CMakeLists.txt b/src/nostalgia/player/CMakeLists.txt index ea2252920..06dced642 100644 --- a/src/nostalgia/player/CMakeLists.txt +++ b/src/nostalgia/player/CMakeLists.txt @@ -22,7 +22,7 @@ endif() target_link_libraries( nostalgia - NostalgiaAppModules + NostalgiaKeelModules OxLogConn ) diff --git a/src/nostalgia/player/main.cpp b/src/nostalgia/player/main.cpp index 5417ceb6c..1da2bd871 100644 --- a/src/nostalgia/player/main.cpp +++ b/src/nostalgia/player/main.cpp @@ -8,7 +8,7 @@ #include -#include +#include #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"); diff --git a/src/nostalgia/scene/CMakeLists.txt b/src/nostalgia/scene/CMakeLists.txt index 565cf22fe..7af14f353 100644 --- a/src/nostalgia/scene/CMakeLists.txt +++ b/src/nostalgia/scene/CMakeLists.txt @@ -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 diff --git a/src/nostalgia/scene/scenemodule.cpp b/src/nostalgia/scene/keelmodule.cpp similarity index 89% rename from src/nostalgia/scene/scenemodule.cpp rename to src/nostalgia/scene/keelmodule.cpp index 478b5f49f..730a671f8 100644 --- a/src/nostalgia/scene/scenemodule.cpp +++ b/src/nostalgia/scene/keelmodule.cpp @@ -2,12 +2,10 @@ * Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved. */ -#include - #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; } diff --git a/src/nostalgia/scene/scenemodule.hpp b/src/nostalgia/scene/keelmodule.hpp similarity index 79% rename from src/nostalgia/scene/scenemodule.hpp rename to src/nostalgia/scene/keelmodule.hpp index 397591cc5..8e1c46c1f 100644 --- a/src/nostalgia/scene/scenemodule.hpp +++ b/src/nostalgia/scene/keelmodule.hpp @@ -8,6 +8,6 @@ namespace nostalgia::scene { -const keel::Module *module() noexcept; +const keel::Module *keelModule() noexcept; } diff --git a/src/nostalgia/scene/studio/CMakeLists.txt b/src/nostalgia/scene/studio/CMakeLists.txt index 8a5512821..c3df02806 100644 --- a/src/nostalgia/scene/studio/CMakeLists.txt +++ b/src/nostalgia/scene/studio/CMakeLists.txt @@ -1,6 +1,6 @@ add_library( NostalgiaScene-Studio OBJECT - module.cpp + studiomodule.cpp sceneeditor-imgui.cpp sceneeditor.cpp sceneeditorview.cpp diff --git a/src/nostalgia/scene/studio/module.hpp b/src/nostalgia/scene/studio/module.hpp deleted file mode 100644 index 5c8a194d3..000000000 --- a/src/nostalgia/scene/studio/module.hpp +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved. - */ - -#pragma once - -#include -#include - -namespace nostalgia::scene { - -class StudioModule: public studio::Module { - public: - ox::Vector editors(turbine::Context *ctx) noexcept override; - ox::Vector> itemMakers(turbine::Context*) noexcept override; -}; - -} diff --git a/src/nostalgia/scene/studio/module.cpp b/src/nostalgia/scene/studio/studiomodule.cpp similarity index 54% rename from src/nostalgia/scene/studio/module.cpp rename to src/nostalgia/scene/studio/studiomodule.cpp index a3ae188df..834ae32e9 100644 --- a/src/nostalgia/scene/studio/module.cpp +++ b/src/nostalgia/scene/studio/studiomodule.cpp @@ -3,11 +3,17 @@ */ #include "sceneeditor-imgui.hpp" -#include "module.hpp" +#include "studiomodule.hpp" namespace nostalgia::scene { -ox::Vector StudioModule::editors(turbine::Context *ctx) noexcept { +class StudioModule: public studio::Module { + public: + ox::Vector editors(turbine::Context *ctx) const noexcept override; + ox::Vector> itemMakers(turbine::Context*) const noexcept override; +}; + +ox::Vector StudioModule::editors(turbine::Context *ctx) const noexcept { return { { {"nscn"}, @@ -18,9 +24,14 @@ ox::Vector StudioModule::editors(turbine::Context *ctx) noe }; } -ox::Vector> StudioModule::itemMakers(turbine::Context*) noexcept { +ox::Vector> StudioModule::itemMakers(turbine::Context*) const noexcept { ox::Vector> out; return out; } +static StudioModule mod; +const studio::Module *studioModule() noexcept { + return &mod; +} + } diff --git a/src/nostalgia/scene/studio/studiomodule.hpp b/src/nostalgia/scene/studio/studiomodule.hpp new file mode 100644 index 000000000..0d83e3ed3 --- /dev/null +++ b/src/nostalgia/scene/studio/studiomodule.hpp @@ -0,0 +1,14 @@ +/* + * Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved. + */ + +#pragma once + +#include +#include + +namespace nostalgia::scene { + +const studio::Module *studioModule() noexcept; + +} diff --git a/src/nostalgia/studio/CMakeLists.txt b/src/nostalgia/studio/CMakeLists.txt index 4d1b12ebf..167ab7387 100644 --- a/src/nostalgia/studio/CMakeLists.txt +++ b/src/nostalgia/studio/CMakeLists.txt @@ -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 . -) \ No newline at end of file +) diff --git a/src/nostalgia/studio/main.cpp b/src/nostalgia/studio/main.cpp index d990ef9dd..e47919cc4 100644 --- a/src/nostalgia/studio/main.cpp +++ b/src/nostalgia/studio/main.cpp @@ -2,27 +2,13 @@ * Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved. */ -#include - -#include -#include -#include +#include +#include #include -using namespace nostalgia; - -[[maybe_unused]] // GCC warns about the existence of this "unused" inline list in a header file... -ox::Vector()>> BuiltinModules = { - []() -> ox::UPtr { - return ox::UPtr(new core::StudioModule()); - }, - []() -> ox::UPtr { - return ox::UPtr(new scene::StudioModule()); - }, -}; - int main(int argc, const char **argv) { - nostalgia::loadModules(); + nostalgia::registerKeelModules(); + nostalgia::registerStudioModules(); return studio::main("Nostalgia Studio", ".nostalgia", argc, argv); -} \ No newline at end of file +} diff --git a/src/nostalgia/tools/CMakeLists.txt b/src/nostalgia/tools/CMakeLists.txt index 7bca9bd60..5a966c16b 100644 --- a/src/nostalgia/tools/CMakeLists.txt +++ b/src/nostalgia/tools/CMakeLists.txt @@ -5,7 +5,7 @@ target_link_libraries( OxClArgs OxLogConn Keel - NostalgiaAppModules + NostalgiaKeelModules ) if(CMAKE_BUILD_TYPE STREQUAL "Release" AND NOT WIN32) diff --git a/src/nostalgia/tools/pack.cpp b/src/nostalgia/tools/pack.cpp index 5c758f32b..c9e0f7d54 100644 --- a/src/nostalgia/tools/pack.cpp +++ b/src/nostalgia/tools/pack.cpp @@ -10,7 +10,7 @@ #include -#include +#include 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 == "") { diff --git a/src/studio/applib/include/studioapp/studioapp.hpp b/src/studio/applib/include/studioapp/studioapp.hpp index a1d2f398c..8935a6313 100644 --- a/src/studio/applib/include/studioapp/studioapp.hpp +++ b/src/studio/applib/include/studioapp/studioapp.hpp @@ -6,12 +6,16 @@ #include +#include + 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); } diff --git a/src/studio/applib/src/CMakeLists.txt b/src/studio/applib/src/CMakeLists.txt index cdeaf253f..1301156ed 100644 --- a/src/studio/applib/src/CMakeLists.txt +++ b/src/studio/applib/src/CMakeLists.txt @@ -1,5 +1,3 @@ -set(CMAKE_INCLUDE_CURRENT_DIR ON) - add_library( StudioAppLib aboutpopup.cpp diff --git a/src/studio/applib/src/main.cpp b/src/studio/applib/src/main.cpp index 735f6b9f1..03cc052ff 100644 --- a/src/studio/applib/src/main.cpp +++ b/src/studio/applib/src/main.cpp @@ -10,8 +10,6 @@ #include #include -#include - #include #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(err); } -} \ No newline at end of file +} diff --git a/src/studio/applib/src/studioapp.cpp b/src/studio/applib/src/studioapp.cpp index 8dc62bff2..1b64625d4 100644 --- a/src/studio/applib/src/studioapp.cpp +++ b/src/studio/applib/src/studioapp.cpp @@ -13,6 +13,8 @@ #include "filedialogmanager.hpp" #include "studioapp.hpp" +ox::Vector 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); +} + +} diff --git a/src/studio/applib/src/studioapp.hpp b/src/studio/applib/src/studioapp.hpp index e63059aba..0be512b02 100644 --- a/src/studio/applib/src/studioapp.hpp +++ b/src/studio/applib/src/studioapp.hpp @@ -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; diff --git a/src/studio/modlib/include/studio/module.hpp b/src/studio/modlib/include/studio/module.hpp index 3688c3cdc..c0b302f3d 100644 --- a/src/studio/modlib/include/studio/module.hpp +++ b/src/studio/modlib/include/studio/module.hpp @@ -25,9 +25,9 @@ class Module { public: virtual ~Module() noexcept = default; - virtual ox::Vector editors(turbine::Context *ctx); + virtual ox::Vector editors(turbine::Context *ctx) const; - virtual ox::Vector> itemMakers(turbine::Context*); + virtual ox::Vector> itemMakers(turbine::Context*) const; }; diff --git a/src/studio/modlib/src/module.cpp b/src/studio/modlib/src/module.cpp index c733a6278..18f3a001e 100644 --- a/src/studio/modlib/src/module.cpp +++ b/src/studio/modlib/src/module.cpp @@ -6,11 +6,11 @@ namespace studio { -ox::Vector Module::editors(turbine::Context*) { +ox::Vector Module::editors(turbine::Context*) const { return {}; } -ox::Vector> Module::itemMakers(turbine::Context*) { +ox::Vector> Module::itemMakers(turbine::Context*) const { return {}; }