Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add framework, based on testapp #298

Merged

Conversation

Capital-Asterisk
Copy link
Contributor

@Capital-Asterisk Capital-Asterisk commented Aug 5, 2024

Heavily addresses #288, most info on these new changes are here.

This can allow the GDExtension application (#294) to not need to depend on testapp.

  • Rework "Sessions" into "Features"
  • Simplify TaskBuilder
  • Allow running Magnum on the main thread, likely fixing crashing issues on mac.
  • Separate renderer setup from scenarios. This would likely allow the GDExtension application to use the same scenarios.
  • Allow reading CLI commands while the Magnum window application is open.
  • Allow changing scenarios while the window is open
  • Restructure directories to match GDExtension branch
  • Remove a heck ton of a lot of macros and unnecessary boilerplate for for setting up Features/Sessions

@Capital-Asterisk
Copy link
Contributor Author

almost 10,000 line changes and rising 🐳 🐦...

I wrote a little unit test / tutorial that shows the important parts of using the new framework:
https://github.com/TheOpenSpaceProgram/osp-magnum/blob/5e8a0b5d3cae3aca5412ff0d90814ac481721763/test/framework/main.cpp

A ton of grunt work required to rewrite all the setup_* 'Session' functions into 'Features'. This gets rid of a bunch of macros and janky stuff and shrinks down the code a tiny bit:

Before and after for 'bounds' (click to expand)

Before:

// Header 1
#define TESTAPP_DATA_BOUNDS 2, \
    idBounds, idOutOfBounds
struct PlBounds
{
    PipelineDef<EStgCont> boundsSet         {"boundsSet"};
    PipelineDef<EStgRevd> outOfBounds       {"outOfBounds"};
};

// Header 2
osp::Session setup_bounds(
        osp::TopTaskBuilder&        rBuilder,
        osp::ArrayView<entt::any>   topData,
        osp::Session const&         scene,
        osp::Session const&         commonScene,
        osp::Session const&         physShapes);

// Source
Session setup_bounds(
        TopTaskBuilder&             rBuilder,
        ArrayView<entt::any> const  topData,
        Session const&              scene,
        Session const&              commonScene,
        Session const&              physShapes)
{
    OSP_DECLARE_GET_DATA_IDS(commonScene,   TESTAPP_DATA_COMMON_SCENE);
    OSP_DECLARE_GET_DATA_IDS(physShapes,    TESTAPP_DATA_PHYS_SHAPES);
    auto const tgScn    = scene         .get_pipelines<PlScene>();
    auto const tgCS     = commonScene   .get_pipelines<PlCommonScene>();
    auto const tgShSp   = physShapes    .get_pipelines<PlPhysShapes>();

    Session out;
    OSP_DECLARE_CREATE_DATA_IDS(out, topData, TESTAPP_DATA_BOUNDS);
    auto const tgBnds = out.create_pipelines<PlBounds>(rBuilder);

    rBuilder.pipeline(tgBnds.boundsSet)     .parent(tgScn.update);
    rBuilder.pipeline(tgBnds.outOfBounds)   .parent(tgScn.update);

    top_emplace< ActiveEntSet_t >       (topData, idBounds);
    top_emplace< ActiveEntVec_t >       (topData, idOutOfBounds);

    rBuilder.task()
        .name       ("Check for out-of-bounds entities")
        .run_on     ({tgScn.update(Run)})
        .sync_with  ({tgCS.transform(Ready), tgBnds.boundsSet(Ready), tgBnds.outOfBounds(Modify__)})
        .push_to    (out.m_tasks)
        .args       ({            idBasic,                      idBounds,                idOutOfBounds })
        .func([] (ACtxBasic const& rBasic, ActiveEntSet_t const& rBounds, ActiveEntVec_t& rOutOfBounds) noexcept
    {
...

After:

// Header 1
struct FIBounds {
    struct DataIds {
        DataId bounds;
        DataId outOfBounds;
    };

    struct Pipelines {
        PipelineDef<EStgCont> boundsSet         {"boundsSet"};
        PipelineDef<EStgRevd> outOfBounds       {"outOfBounds"};
    };
};

// Header 2
extern osp::fw::FeatureDef const ftrBounds;

// Source
FeatureDef const ftrBounds = feature_def("Bounds", [] (
        FeatureBuilder              &rFB,
        Implement<FIBounds>         bounds,
        DependOn<FIScene>           scn,
        DependOn<FICommonScene>     comScn,
        DependOn<FIPhysShapes>      physShapes)
{
    rFB.pipeline(bounds.pl.boundsSet)     .parent(scn.pl.update);
    rFB.pipeline(bounds.pl.outOfBounds)   .parent(scn.pl.update);

    rFB.data_emplace< ActiveEntSet_t >       (bounds.di.bounds);
    rFB.data_emplace< ActiveEntVec_t >       (bounds.di.outOfBounds);

    rFB.task()
        .name       ("Check for out-of-bounds entities")
        .run_on     ({scn.pl.update(Run)})
        .sync_with  ({comScn.pl.transform(Ready), bounds.pl.boundsSet(Ready), bounds.pl.outOfBounds(Modify__)})
        .args       ({    comScn.di.basic,              bounds.di.bounds,        bounds.di.outOfBounds })
        .func([] (ACtxBasic const &rBasic, ActiveEntSet_t const &rBounds, ActiveEntVec_t &rOutOfBounds) noexcept
    {
...
</details>

@Capital-Asterisk Capital-Asterisk marked this pull request as ready for review August 28, 2024 04:17
src/osp/framework/builder.h Dismissed Show dismissed Hide dismissed
src/osp/framework/builder.h Dismissed Show dismissed Hide dismissed
src/osp/framework/framework.h Fixed Show fixed Hide fixed
src/testapp/scenarios_magnum.cpp Fixed Show fixed Hide fixed
src/osp/framework/builder.h Dismissed Show dismissed Hide dismissed
@Capital-Asterisk Capital-Asterisk merged commit 1069fc0 into TheOpenSpaceProgram:master Sep 22, 2024
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant