From 7bc10905dc7e13db299c7a0093d79ffd36d14dde Mon Sep 17 00:00:00 2001 From: Neal_Nicdao Date: Sun, 18 Aug 2024 01:19:10 -0700 Subject: [PATCH] Move and reorganize more testapp stuff into adera_app --- src/{adera => adera_app}/application.h | 20 +- src/adera_app/feature_interfaces.h | 498 +++++++++++++++++ src/adera_app/features/common.cpp | 486 +++++++++++++++++ src/adera_app/features/common.h | 50 ++ .../sessions => adera_app/features}/jolt.cpp | 96 ++-- .../sessions => adera_app/features}/jolt.h | 20 +- .../sessions => adera_app/features}/misc.cpp | 52 +- .../sessions => adera_app/features}/misc.h | 8 +- .../features}/newton.cpp | 92 ++-- .../sessions => adera_app/features}/newton.h | 16 +- .../features}/physics.cpp | 116 ++-- .../sessions => adera_app/features}/physics.h | 10 +- .../features}/shapes.cpp | 166 +++--- .../sessions => adera_app/features}/shapes.h | 12 +- .../features}/terrain.cpp | 96 ++-- .../sessions => adera_app/features}/terrain.h | 12 +- .../features}/universe.cpp | 120 ++--- .../features}/universe.h | 14 +- .../features}/vehicles.cpp | 154 +++--- .../features}/vehicles.h | 16 +- .../features}/vehicles_machines.cpp | 108 ++-- .../features}/vehicles_machines.h | 10 +- .../features}/vehicles_prebuilt.cpp | 40 +- .../features}/vehicles_prebuilt.h | 6 +- src/osp/drawing/drawing.h | 13 +- src/osp/framework/framework.h | 8 + src/osp/tasks/execute2r.h | 46 ++ src/osp/tasks/tasks.cpp | 22 +- ...numApplication.cpp => MagnumWindowApp.cpp} | 30 +- ...{MagnumApplication.h => MagnumWindowApp.h} | 23 +- src/testapp/enginetest.cpp | 10 +- src/testapp/enginetest.h | 6 +- src/testapp/feature_interfaces.h | 459 +--------------- src/testapp/features/console.cpp | 109 ++++ src/testapp/features/console.h | 37 ++ src/testapp/{sessions => features}/magnum.cpp | 25 +- src/testapp/{sessions => features}/magnum.h | 11 +- src/testapp/main.cpp | 415 +++----------- src/testapp/scenarios.cpp | 69 +-- src/testapp/scenarios.h | 24 +- src/testapp/scenarios_magnum.cpp | 239 ++++++++ src/testapp/scenarios_magnum.h | 36 ++ src/testapp/sessions/common.cpp | 508 ------------------ src/testapp/sessions/common.h | 78 --- src/testapp/testapp.cpp | 117 ++-- src/testapp/testapp.h | 69 +-- 46 files changed, 2407 insertions(+), 2165 deletions(-) rename src/{adera => adera_app}/application.h (82%) create mode 100644 src/adera_app/feature_interfaces.h create mode 100644 src/adera_app/features/common.cpp create mode 100644 src/adera_app/features/common.h rename src/{testapp/sessions => adera_app/features}/jolt.cpp (89%) rename src/{testapp/sessions => adera_app/features}/jolt.h (89%) rename src/{testapp/sessions => adera_app/features}/misc.cpp (77%) rename src/{testapp/sessions => adera_app/features}/misc.h (93%) rename src/{testapp/sessions => adera_app/features}/newton.cpp (88%) rename src/{testapp/sessions => adera_app/features}/newton.h (89%) rename src/{testapp/sessions => adera_app/features}/physics.cpp (64%) rename src/{testapp/sessions => adera_app/features}/physics.h (92%) rename src/{testapp/sessions => adera_app/features}/shapes.cpp (77%) rename src/{testapp/sessions => adera_app/features}/shapes.h (93%) rename src/{testapp/sessions => adera_app/features}/terrain.cpp (91%) rename src/{testapp/sessions => adera_app/features}/terrain.h (95%) rename src/{testapp/sessions => adera_app/features}/universe.cpp (89%) rename src/{testapp/sessions => adera_app/features}/universe.h (92%) rename src/{testapp/sessions => adera_app/features}/vehicles.cpp (85%) rename src/{testapp/sessions => adera_app/features}/vehicles.h (92%) rename src/{testapp/sessions => adera_app/features}/vehicles_machines.cpp (86%) rename src/{testapp/sessions => adera_app/features}/vehicles_machines.h (93%) rename src/{testapp/sessions => adera_app/features}/vehicles_prebuilt.cpp (86%) rename src/{testapp/sessions => adera_app/features}/vehicles_prebuilt.h (95%) create mode 100644 src/osp/tasks/execute2r.h rename src/testapp/{MagnumApplication.cpp => MagnumWindowApp.cpp} (90%) rename src/testapp/{MagnumApplication.h => MagnumWindowApp.h} (81%) create mode 100644 src/testapp/features/console.cpp create mode 100644 src/testapp/features/console.h rename src/testapp/{sessions => features}/magnum.cpp (98%) rename src/testapp/{sessions => features}/magnum.h (92%) create mode 100644 src/testapp/scenarios_magnum.cpp create mode 100644 src/testapp/scenarios_magnum.h delete mode 100644 src/testapp/sessions/common.cpp delete mode 100644 src/testapp/sessions/common.h diff --git a/src/adera/application.h b/src/adera_app/application.h similarity index 82% rename from src/adera/application.h rename to src/adera_app/application.h index a918f5ff..56e6dc84 100644 --- a/src/adera/application.h +++ b/src/adera_app/application.h @@ -33,28 +33,36 @@ namespace adera { - - struct MainLoopControl { bool doUpdate; }; +struct WindowAppLoopControl +{ + bool doResync; + + bool doSync; + + bool doRender; +}; + struct AppContexts { osp::fw::ContextId main; osp::fw::ContextId window; osp::fw::ContextId universe; - osp::fw::ContextId scenes; + osp::fw::ContextId scene; }; struct FrameworkModify { struct Command { - using Func_t = void(*)(entt::any); - entt::any userData; - Func_t func; + using Func_t = void(*)(osp::fw::Framework &rFW, osp::fw::ContextId ctx, entt::any userData); + entt::any userData; + osp::fw::ContextId ctx; + Func_t func; }; std::vector commands; diff --git a/src/adera_app/feature_interfaces.h b/src/adera_app/feature_interfaces.h new file mode 100644 index 00000000..416f8b03 --- /dev/null +++ b/src/adera_app/feature_interfaces.h @@ -0,0 +1,498 @@ +/** + * Open Space Program + * Copyright © 2019-2024 Open Space Program Project + * + * MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#pragma once + +#include + +namespace ftr_inter +{ + + +enum class EStgOptn : uint8_t +{ + ModifyOrSignal, + Schedule, + Run, + Done +}; +OSP_DECLARE_STAGE_NAMES(EStgOptn, "Modify/Signal", "Schedule", "Run", "Done"); +OSP_DECLARE_STAGE_SCHEDULE(EStgOptn, EStgOptn::Schedule); + + +enum class EStgEvnt : uint8_t +{ + Run_, + Done_ +}; +OSP_DECLARE_STAGE_NAMES(EStgEvnt, "Run", "Done"); +OSP_DECLARE_STAGE_NO_SCHEDULE(EStgEvnt); + +/** + * @brief Intermediate container that is filled, used, then cleared right away + */ +enum class EStgIntr : uint8_t +{ + Resize, + Modify_, + Schedule_, + UseOrRun, + Clear +}; +OSP_DECLARE_STAGE_NAMES(EStgIntr, "Resize", "Modify", "Schedule", "Use/Run", "Clear"); +OSP_DECLARE_STAGE_SCHEDULE(EStgIntr, EStgIntr::Schedule_); + +/** + * @brief 'Reversed' Intermediate container + * + * This is used as a workaround for flaws in osp/tasks/execute.cpp being incapable of handling + * certain patterns of task dependencies + */ +enum class EStgRevd : uint8_t +{ + Schedule__, + UseOrRun_, + Clear_, + Resize_, + Modify__, +}; +OSP_DECLARE_STAGE_NAMES(EStgRevd, "Schedule", "Use/Run", "Clear", "Resize", "Modify"); +OSP_DECLARE_STAGE_SCHEDULE(EStgRevd, EStgRevd::Schedule__); + +/** + * @brief Continuous Containers, data that persists and is modified over time + * + */ +enum class EStgCont : uint8_t +{ + Prev, + ///< Previous state of container + + Delete, + ///< Remove elements from a container or mark them for deletion. This often involves reading + ///< a set of elements to delete. This is run first since it leaves empty spaces for new + ///< elements to fill directly after + + New, + ///< Add new elements. Potentially resize the container to fit more elements + + Modify, + ///< Modify existing elements + + Ready + ///< Container is ready to use +}; +OSP_DECLARE_STAGE_NAMES(EStgCont, "Prev", "Delete", "New", "Modify", "Use"); +OSP_DECLARE_STAGE_NO_SCHEDULE(EStgCont); + +enum class EStgFBO +{ + Bind, + Draw, + Unbind +}; +OSP_DECLARE_STAGE_NAMES(EStgFBO, "Bind", "Draw", "Unbind"); +OSP_DECLARE_STAGE_NO_SCHEDULE(EStgFBO); + + +enum class EStgLink +{ + ScheduleLink, + NodeUpd, + MachUpd +}; +OSP_DECLARE_STAGE_NAMES(EStgLink, "Schedule", "NodeUpd", "MachUpd"); +OSP_DECLARE_STAGE_SCHEDULE(EStgLink, EStgLink::ScheduleLink); + +namespace stages +{ + using enum EStgOptn; + using enum EStgCont; + using enum EStgIntr; + using enum EStgRevd; + using enum EStgEvnt; + using enum EStgFBO; + using enum EStgLink; +} // namespace stages + + +//----------------------------------------------------------------------------- + +inline void register_stage_enums() +{ + osp::PipelineInfo::sm_stageNames.resize(32); + osp::PipelineInfo::register_stage_enum(); + osp::PipelineInfo::register_stage_enum(); + osp::PipelineInfo::register_stage_enum(); + osp::PipelineInfo::register_stage_enum(); + osp::PipelineInfo::register_stage_enum(); + osp::PipelineInfo::register_stage_enum(); + osp::PipelineInfo::register_stage_enum(); +} + +using osp::PipelineDef; +using osp::fw::DataId; + +//----------------------------------------------------------------------------- + +struct FIMainApp { + struct DataIds { + DataId appContexts; + DataId resources; + DataId mainLoopCtrl; + DataId frameworkModify; + }; + + struct Pipelines { + PipelineDef mainLoop {"mainLoop"}; + }; +}; + +//----------------------------------------------------------------------------- + +struct FIEngineTest { + struct DataIds { + DataId bigStruct; + }; + + struct Pipelines { }; +}; + +struct FIScene { + struct DataIds { + DataId deltaTimeIn; + }; + + struct Pipelines { + PipelineDef cleanup {"cleanup - Scene cleanup before destruction"}; + PipelineDef update {"update"}; + }; +}; + + +struct FICommonScene { + struct DataIds { + DataId basic; + DataId drawing; + DataId drawingRes; + DataId activeEntDel; + DataId drawEntDel; + DataId namedMeshes; + }; + + struct Pipelines { + PipelineDef activeEnt {"activeEnt - ACtxBasic::m_activeIds"}; + PipelineDef activeEntResized {"activeEntResized - ACtxBasic::m_activeIds option to resize"}; + PipelineDef activeEntDelete {"activeEntDelete - commonScene.di.activeEntDel, vector of ActiveEnts that need to be deleted"}; + + PipelineDef transform {"transform - ACtxBasic::m_transform"}; + PipelineDef hierarchy {"hierarchy - ACtxBasic::m_scnGraph"}; + }; +}; + +#define TESTAPP_DATA_PHYSICS 3, \ + idPhys, idHierBody, idPhysIn +struct PlPhysics +{ + PipelineDef physBody {"physBody"}; + PipelineDef physUpdate {"physUpdate"}; +}; + + + +#define TESTAPP_DATA_PHYS_SHAPES 1, \ + idPhysShapes +struct PlPhysShapes +{ + PipelineDef spawnRequest {"spawnRequest - Spawned shapes"}; + PipelineDef spawnedEnts {"spawnedEnts"}; + PipelineDef ownedEnts {"ownedEnts"}; +}; + + + +#define TESTAPP_DATA_PREFABS 1, \ + idPrefabs +struct PlPrefabs +{ + PipelineDef spawnRequest {"spawnRequest"}; + PipelineDef spawnedEnts {"spawnedEnts"}; + PipelineDef ownedEnts {"ownedEnts"}; + + PipelineDef instanceInfo {"instanceInfo"}; + + PipelineDef inSubtree {"inSubtree"}; +}; + + + +#define TESTAPP_DATA_BOUNDS 2, \ + idBounds, idOutOfBounds +struct PlBounds +{ + PipelineDef boundsSet {"boundsSet"}; + PipelineDef outOfBounds {"outOfBounds"}; +}; + + + +#define TESTAPP_DATA_PARTS 2, \ + idScnParts, idUpdMach +struct PlParts +{ + PipelineDef partIds {"partIds - ACtxParts::partIds"}; + PipelineDef partPrefabs {"partPrefabs - ACtxParts::partPrefabs"}; + PipelineDef partTransformWeld {"partTransformWeld - ACtxParts::partTransformWeld"}; + PipelineDef partDirty {"partDirty - ACtxParts::partDirty"}; + + PipelineDef weldIds {"weldIds - ACtxParts::weldIds"}; + PipelineDef weldDirty {"weldDirty - ACtxParts::weldDirty"}; + + PipelineDef machIds {"machIds - ACtxParts::machines.ids"}; + PipelineDef nodeIds {"nodeIds - ACtxParts::nodePerType[*].nodeIds"}; + PipelineDef connect {"connect - ACtxParts::nodePerType[*].nodeToMach/machToNode"}; + + PipelineDef mapWeldPart {"mapPartWeld - ACtxParts::weldToParts/partToWeld"}; + PipelineDef mapPartMach {"mapPartMach - ACtxParts::partToMachines/machineToPart"}; + PipelineDef mapPartActive {"mapPartActive - ACtxParts::partToActive/activeToPart"}; + PipelineDef mapWeldActive {"mapWeldActive - ACtxParts::weldToActive"}; + + PipelineDef machUpdExtIn {"machUpdExtIn -"}; + + PipelineDef linkLoop {"linkLoop - Link update loop"}; +}; + + + +#define TESTAPP_DATA_VEHICLE_SPAWN 1, \ + idVehicleSpawn +struct PlVehicleSpawn +{ + PipelineDef spawnRequest {"spawnRequest - ACtxVehicleSpawn::spawnRequest"}; + PipelineDef spawnedParts {"spawnedParts - ACtxVehicleSpawn::spawnedPart*"}; + PipelineDef spawnedWelds {"spawnedWelds - ACtxVehicleSpawn::spawnedWeld*"}; + PipelineDef rootEnts {"rootEnts - ACtxVehicleSpawn::rootEnts"}; + PipelineDef spawnedMachs {"spawnedMachs - ACtxVehicleSpawn::spawnedMachs"}; +}; + + + +#define TESTAPP_DATA_VEHICLE_SPAWN_VB 1, \ + idVehicleSpawnVB +struct PlVehicleSpawnVB +{ + PipelineDef dataVB {"dataVB - ACtxVehicleSpawnVB::dataVB"}; + PipelineDef remapParts {"remapParts - ACtxVehicleSpawnVB::remapPart*"}; + PipelineDef remapWelds {"remapWelds - ACtxVehicleSpawnVB::remapWeld*"}; + PipelineDef remapMachs {"remapMachs - ACtxVehicleSpawnVB::remapMach*"}; + PipelineDef remapNodes {"remapNodes - ACtxVehicleSpawnVB::remapNode*"}; +}; + + + +#define TESTAPP_DATA_TEST_VEHICLES 1, \ + idPrebuiltVehicles + + + +#define TESTAPP_DATA_SIGNALS_FLOAT 2, \ + idSigValFloat, idSigUpdFloat +struct PlSignalsFloat +{ + PipelineDef sigFloatValues {"sigFloatValues -"}; + PipelineDef sigFloatUpdExtIn {"sigFloatUpdExtIn -"}; + PipelineDef sigFloatUpdLoop {"sigFloatUpdLoop -"}; +}; + + + +#define TESTAPP_DATA_NEWTON 1, \ + idNwt +struct PlNewton +{ + PipelineDef nwtBody {"nwtBody"}; +}; + +#define TESTAPP_DATA_NEWTON_FORCES 1, \ + idNwtFactors + + + +#define TESTAPP_DATA_NEWTON_ACCEL 1, \ + idAcceleration + + +#define TESTAPP_DATA_JOLT 1, \ + idJolt +struct PlJolt +{ + PipelineDef joltBody {"joltBody"}; +}; + +#define TESTAPP_DATA_JOLT_FORCES 1, \ + idJoltFactors + + + +#define TESTAPP_DATA_JOLT_ACCEL 1, \ + idAcceleration + + + +#define TESTAPP_DATA_ROCKETS_NWT 1, \ + idRocketsNwt + + +#define TESTAPP_DATA_ROCKETS_JOLT 1, \ + idRocketsJolt + + +#define TESTAPP_DATA_TERRAIN 2, \ + idTerrainFrame, idTerrain +struct PlTerrain +{ + PipelineDef skeleton {"skeleton"}; + PipelineDef surfaceChanges {"surfaceChanges"}; + PipelineDef chunkMesh {"chunkMesh"}; + PipelineDef terrainFrame {"terrainFrame"}; +}; + +#define TESTAPP_DATA_TERRAIN_ICO 1, \ + idTerrainIco + + +//----------------------------------------------------------------------------- + +// Universe sessions + +#define TESTAPP_DATA_UNI_CORE 2, \ + idUniverse, tgUniDeltaTimeIn +struct PlUniCore +{ + PipelineDef update {"update - Universe update"}; + PipelineDef transfer {"transfer"}; +}; + +#define TESTAPP_DATA_UNI_SCENEFRAME 1, \ + idScnFrame +struct PlUniSceneFrame +{ + PipelineDef sceneFrame {"sceneFrame"}; +}; + +#define TESTAPP_DATA_UNI_PLANETS 2, \ + idPlanetMainSpace, idSatSurfaceSpaces + +//----------------------------------------------------------------------------- + +// Solar System sessions + +#define TESTAPP_DATA_SOLAR_SYSTEM_PLANETS 3, \ + idPlanetMainSpace, idSatSurfaceSpaces, idCoordNBody + +//----------------------------------------------------------------------------- + +// Renderer sessions, tend to exist only when the window is open + +struct FIWindowApp { + struct DataIds { + DataId windowAppLoopCtrl; + DataId userInput; + }; + + struct Pipelines { + PipelineDef inputs {"inputs"}; + PipelineDef sync {"sync"}; + PipelineDef resync {"resync"}; + + PipelineDef cleanup {"cleanup - Cleanup renderer resources before destruction"}; + }; +}; + + +#define TESTAPP_DATA_SCENE_RENDERER 2, \ + idScnRender, idDrawTfObservers +struct PlSceneRenderer +{ + PipelineDef render {"render - "}; + + PipelineDef drawEnt {"drawEnt - "}; + PipelineDef drawEntResized {"drawEntResized - "}; + PipelineDef drawEntDelete {"drawEntDelete - Vector of DrawEnts that need to be deleted"}; + + PipelineDef entTextureDirty {"entTextureDirty"}; + PipelineDef entMeshDirty {"entMeshDirty"}; + + PipelineDef material {"material"}; + PipelineDef materialDirty {"materialDirty"}; + + PipelineDef drawTransforms {"drawTransforms"}; + + PipelineDef group {"group"}; + PipelineDef groupEnts {"groupEnts"}; + PipelineDef entMesh {"entMesh"}; + PipelineDef entTexture {"entTexture"}; + + PipelineDef mesh {"mesh"}; + PipelineDef texture {"texture"}; + + PipelineDef meshResDirty {"meshResDirty"}; + PipelineDef textureResDirty {"textureResDirty"}; +}; + + + +#define TESTAPP_DATA_MAGNUM_SCENE 3, \ + idScnRenderGl, idGroupFwd, idCamera +struct PlMagnumScene +{ + PipelineDef fbo {"fboRender"}; + + PipelineDef camera {"camera"}; + +}; + + + +#define TESTAPP_DATA_CAMERA_CTRL 1, \ + idCamCtrl +struct PlCameraCtrl +{ + PipelineDef camCtrl {"camCtrl"}; +}; + + +#define TESTAPP_DATA_INDICATOR 1, \ + idIndicator + + + +#define TESTAPP_DATA_VEHICLE_CONTROL 1, \ + idVhControls +struct PlVehicleCtrl +{ + PipelineDef selectedVehicle {"selectedVehicle"}; +}; + +} // namespace ftr_inter diff --git a/src/adera_app/features/common.cpp b/src/adera_app/features/common.cpp new file mode 100644 index 00000000..208d878f --- /dev/null +++ b/src/adera_app/features/common.cpp @@ -0,0 +1,486 @@ +/** + * Open Space Program + * Copyright © 2019-2022 Open Space Program Project + * + * MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "common.h" + +#include "../feature_interfaces.h" +#include "../application.h" + +#include +#include +#include +#include +#include +#include + +using namespace adera; +using namespace ftr_inter; +using namespace ftr_inter::stages; +using namespace osp; +using namespace osp::active; +using namespace osp::draw; +using namespace osp::fw; + +namespace adera +{ + +FeatureDef const ftrMain = feature_def("Main", [] (FeatureBuilder& rFB, Implement mainApp, entt::any pkg) +{ + rFB.data_emplace< AppContexts > (mainApp.di.appContexts); + rFB.data_emplace< MainLoopControl > (mainApp.di.mainLoopCtrl); + rFB.data_emplace< osp::Resources > (mainApp.di.resources); + rFB.data_emplace< FrameworkModify > (mainApp.di.frameworkModify); + + rFB.pipeline(mainApp.pl.mainLoop).loops(true).wait_for_signal(ModifyOrSignal); + + rFB.task() + .name ("Schedule Main Loop") + .schedules ({mainApp.pl.mainLoop(Schedule)}) + .args ({ mainApp.di.mainLoopCtrl}) + .func([] (MainLoopControl const& rMainLoopCtrl) noexcept -> osp::TaskActions + { + return rMainLoopCtrl.doUpdate ? osp::TaskActions{} : osp::TaskAction::Cancel; + }); +}); + + +FeatureDef const ftrScene = feature_def("Scene", [] ( + FeatureBuilder& rFB, Implement scene, DependOn mainApp) +{ + rFB.data_emplace(scene.di.deltaTimeIn, 1.0f / 60.0f); + rFB.pipeline(scene.pl.update).parent(mainApp.pl.mainLoop).wait_for_signal(ModifyOrSignal); + + rFB.task() + .name ("Schedule Scene update") + .schedules ({scene.pl.update(Schedule)}) + .args ({ mainApp.di.mainLoopCtrl}) + .func ([] (MainLoopControl const& rMainLoopCtrl) noexcept -> osp::TaskActions + { + return rMainLoopCtrl.doUpdate ? osp::TaskActions{} : osp::TaskAction::Cancel; + }); +}); // ftrScene + + +FeatureDef const ftrCommonScene = feature_def("CommonScene", [] ( + FeatureBuilder& rFB, Implement commonScene, DependOn scene, + DependOn mainApp, entt::any data) +{ + + // TODO: out.m_cleanup = scene.pl.cleanup; + + /* not used here */ rFB.data_emplace< ActiveEntVec_t >(commonScene.di.activeEntDel); + /* not used here */ rFB.data_emplace< DrawEntVec_t > (commonScene.di.drawEntDel); + auto &rBasic = rFB.data_emplace< ACtxBasic > (commonScene.di.basic); + auto &rDrawing = rFB.data_emplace< ACtxDrawing > (commonScene.di.drawing); + auto &rDrawingRes = rFB.data_emplace< ACtxDrawingRes >(commonScene.di.drawingRes); + auto &rNamedMeshes = rFB.data_emplace< NamedMeshes > (commonScene.di.namedMeshes); + + rFB.pipeline(commonScene.pl.activeEnt) .parent(scene.pl.update); + rFB.pipeline(commonScene.pl.activeEntResized) .parent(scene.pl.update); + rFB.pipeline(commonScene.pl.activeEntDelete) .parent(scene.pl.update); + rFB.pipeline(commonScene.pl.transform) .parent(scene.pl.update); + rFB.pipeline(commonScene.pl.hierarchy) .parent(scene.pl.update); + + rFB.task() + .name ("Cancel entity delete tasks stuff if no entities were deleted") + .run_on ({commonScene.pl.activeEntDelete(Schedule_)}) + .args ({commonScene.di.basic, commonScene.di.activeEntDel }) + .func ([] (ACtxBasic &rBasic, ActiveEntVec_t const &rActiveEntDel) noexcept + { + return rActiveEntDel.empty() ? TaskAction::Cancel : TaskActions{}; + }); + + rFB.task() + .name ("Delete ActiveEnt IDs") + .run_on ({commonScene.pl.activeEntDelete(EStgIntr::UseOrRun)}) + .sync_with ({commonScene.pl.activeEnt(Delete)}) + .args ({commonScene.di.basic, commonScene.di.activeEntDel }) + .func ([] (ACtxBasic &rBasic, ActiveEntVec_t const &rActiveEntDel) noexcept + { + for (ActiveEnt const ent : rActiveEntDel) + { + if (rBasic.m_activeIds.exists(ent)) + { + rBasic.m_activeIds.remove(ent); + } + } + }); + + rFB.task() + .name ("Delete basic components") + .run_on ({commonScene.pl.activeEntDelete(UseOrRun)}) + .sync_with ({commonScene.pl.transform(Delete)}) + .args ({commonScene.di.basic, commonScene.di.activeEntDel }) + .func([] ( ACtxBasic &rBasic, ActiveEntVec_t const &rActiveEntDel) noexcept + { + update_delete_basic(rBasic, rActiveEntDel.cbegin(), rActiveEntDel.cend()); + }); + + rFB.task() + .name ("Clear ActiveEnt delete vector once we're done with it") + .run_on ({commonScene.pl.activeEntDelete(Clear)}) + .args ({ commonScene.di.activeEntDel }) + .func([] (ActiveEntVec_t &rActiveEntDel) noexcept + { + rActiveEntDel.clear(); + }); + + // Clean up tasks + + rFB.task() + .name ("Clean up resource owners") + .run_on ({scene.pl.cleanup(Run_)}) + .args ({ commonScene.di.drawing, commonScene.di.drawingRes, mainApp.di.resources}) + .func ([] (ACtxDrawing &rDrawing, ACtxDrawingRes &rDrawingRes, Resources &rResources) noexcept + { + SysRender::clear_resource_owners(rDrawingRes, rResources); + }); + + rFB.task() + .name ("Clean up NamedMeshes mesh and texture owners") + .run_on ({scene.pl.cleanup(Run_)}) + .args ({ commonScene.di.drawing, commonScene.di.namedMeshes }) + .func([] (ACtxDrawing &rDrawing, NamedMeshes &rNMesh) noexcept + { + for ([[maybe_unused]] auto && [_, rOwner] : std::exchange(rNMesh.m_shapeToMesh, {})) + { + rDrawing.m_meshRefCounts.ref_release(std::move(rOwner)); + } + + for ([[maybe_unused]] auto && [_, rOwner] : std::exchange(rNMesh.m_namedMeshs, {})) + { + rDrawing.m_meshRefCounts.ref_release(std::move(rOwner)); + } + }); + + auto &rResources = rFB.data_get(mainApp.di.resources); + + + // Convenient functor to get a reference-counted mesh owner + auto const quick_add_mesh = SysRender::gen_drawable_mesh_adder(rDrawing, rDrawingRes, rResources, entt::any_cast(data)); + + // Acquire mesh resources from Package + rNamedMeshes.m_shapeToMesh.emplace(EShape::Box, quick_add_mesh("cube")); + rNamedMeshes.m_shapeToMesh.emplace(EShape::Cylinder, quick_add_mesh("cylinder")); + rNamedMeshes.m_shapeToMesh.emplace(EShape::Sphere, quick_add_mesh("sphere")); + rNamedMeshes.m_namedMeshs.emplace("floor", quick_add_mesh("grid64solid")); + +}); // ftrCommonScene + + +FeatureDef const ftrWindowApp = feature_def("WindowApp", [] ( + FeatureBuilder& rFB, Implement windowApp, DependOn mainApp) +{ + rFB.pipeline(windowApp.pl.inputs).parent(mainApp.pl.mainLoop);//.wait_for_signal(ModifyOrSignal); + rFB.pipeline(windowApp.pl.sync) .parent(mainApp.pl.mainLoop);//.wait_for_signal(ModifyOrSignal); + rFB.pipeline(windowApp.pl.resync).parent(mainApp.pl.mainLoop);//.wait_for_signal(ModifyOrSignal); + + auto &rUserInput = rFB.data_emplace(windowApp.di.userInput, 12); + auto &rWindowAppCtrl = rFB.data_emplace (windowApp.di.windowAppLoopCtrl); + + // TODO: out.m_cleanup = windowApp.pl.cleanup; + + rFB.task() + .name ("Schedule Renderer Sync") + .schedules ({windowApp.pl.sync(Schedule)}) + .args ({ windowApp.di.windowAppLoopCtrl}) + .func ([] (WindowAppLoopControl const& rWindowAppLoopCtrl) noexcept -> osp::TaskActions + { + return rWindowAppLoopCtrl.doSync ? osp::TaskActions{} : osp::TaskAction::Cancel; + }); + + rFB.task() + .name ("Schedule Renderer Resync") + .schedules ({windowApp.pl.resync(Schedule)}) + .args ({ windowApp.di.windowAppLoopCtrl}) + .func ([] (WindowAppLoopControl const& rWindowAppLoopCtrl) noexcept -> osp::TaskActions + { + return rWindowAppLoopCtrl.doResync ? osp::TaskActions{} : osp::TaskAction::Cancel; + }); + +}); // ftrWindowApp + + +#if 0 + +Session setup_scene_renderer( + TopTaskBuilder& rFB, + ArrayView const topData, + Session const& application, + Session const& windowApp, + Session const& commonScene) +{ + OSP_DECLARE_GET_DATA_IDS(windowApp, TESTAPP_DATA_WINDOW_APP); + OSP_DECLARE_GET_DATA_IDS(commonScene, TESTAPP_DATA_COMMON_SCENE); + auto const mainApp.pl = application .get_pipelines< PlApplication >(); + auto const windowApp.pl = windowApp .get_pipelines< PlWindowApp >(); + auto const commonScene.pl = commonScene .get_pipelines< PlCommonScene >(); + + + Session out; + OSP_DECLARE_CREATE_DATA_IDS(out, topData, TESTAPP_DATA_SCENE_RENDERER); + auto const scene.plRdr = out.create_pipelines(rFB); + + rFB.pipeline(scene.plRdr.render).parent(mainApp.pl.mainLoop).wait_for_signal(ModifyOrSignal); + + rFB.pipeline(scene.plRdr.drawEnt) .parent(windowApp.pl.sync); + rFB.pipeline(scene.plRdr.drawEntResized) .parent(windowApp.pl.sync); + rFB.pipeline(scene.plRdr.drawEntDelete) .parent(windowApp.pl.sync); + rFB.pipeline(scene.plRdr.entMesh) .parent(windowApp.pl.sync); + rFB.pipeline(scene.plRdr.entTexture) .parent(windowApp.pl.sync); + rFB.pipeline(scene.plRdr.entTextureDirty) .parent(windowApp.pl.sync); + rFB.pipeline(scene.plRdr.entMeshDirty) .parent(windowApp.pl.sync); + rFB.pipeline(scene.plRdr.drawTransforms) .parent(scene.plRdr.render); + rFB.pipeline(scene.plRdr.material) .parent(windowApp.pl.sync); + rFB.pipeline(scene.plRdr.materialDirty) .parent(windowApp.pl.sync); + rFB.pipeline(scene.plRdr.group) .parent(windowApp.pl.sync); + rFB.pipeline(scene.plRdr.groupEnts) .parent(windowApp.pl.sync); + rFB.pipeline(scene.plRdr.entMesh) .parent(windowApp.pl.sync); + rFB.pipeline(scene.plRdr.entTexture) .parent(windowApp.pl.sync); + rFB.pipeline(scene.plRdr.mesh) .parent(windowApp.pl.sync); + rFB.pipeline(scene.plRdr.texture) .parent(windowApp.pl.sync); + rFB.pipeline(scene.plRdr.meshResDirty) .parent(windowApp.pl.sync); + rFB.pipeline(scene.plRdr.textureResDirty) .parent(windowApp.pl.sync); + + auto &rScnRender = osp::rFB.data_emplace(topData, idScnRender); + /* unused */ osp::rFB.data_emplace(topData, idDrawTfObservers); + + rFB.task() + .name ("Resize ACtxSceneRender containers to fit all DrawEnts") + .run_on ({scene.plRdr.drawEntResized(Run)}) + .sync_with ({scene.plRdr.entMesh(New), scene.plRdr.entTexture(New)}) + .push_to (out.m_tasks) + .args ({idScnRender}) + .func ([] (ACtxSceneRender& rScnRender) noexcept + { + rScnRender.resize_draw(); + }); + + rFB.task() + .name ("Resize ACtxSceneRender to fit ActiveEnts") + .run_on ({commonScene.pl.activeEntResized(Run)}) + .push_to (out.m_tasks) + .args ({ commonScene.di.basic, idScnRender}) + .func([] (ACtxBasic const &rBasic, ACtxSceneRender& rScnRender) noexcept + { + rScnRender.resize_active(rBasic.m_activeIds.capacity()); + }); + + // Duplicate task needed for resync to account for existing ActiveEnts when the renderer opens, + // as activeEntResized doesn't run during resync + rFB.task() + .name ("Resync ACtxSceneRender to fit ActiveEnts") + .run_on ({windowApp.pl.resync(Run)}) + .sync_with ({commonScene.pl.activeEntResized(Run)}) + .push_to (out.m_tasks) + .args ({ commonScene.di.basic, idScnRender}) + .func([] (ACtxBasic const &rBasic, ACtxSceneRender& rScnRender) noexcept + { + rScnRender.resize_active(rBasic.m_activeIds.capacity()); + }); + + rFB.task() + .name ("Schedule Assign GL textures") + .schedules ({scene.plRdr.entTextureDirty(Schedule_)}) + .sync_with ({scene.plRdr.texture(Ready), scene.plRdr.entTexture(Ready)}) + .push_to (out.m_tasks) + .args ({ idScnRender }) + .func([] (ACtxSceneRender& rScnRender) noexcept -> TaskActions + { + return rScnRender.m_diffuseDirty.empty() ? TaskAction::Cancel : TaskActions{}; + }); + + rFB.task() + .name ("Schedule Assign GL meshes") + .schedules ({scene.plRdr.entMeshDirty(Schedule_)}) + .sync_with ({scene.plRdr.mesh(Ready), scene.plRdr.entMesh(Ready)}) + .push_to (out.m_tasks) + .args ({ idScnRender }) + .func([] (ACtxSceneRender& rScnRender) noexcept -> TaskActions + { + return rScnRender.m_meshDirty.empty() ? TaskAction::Cancel : TaskActions{}; + }); + + rFB.task() + .name ("Calculate draw transforms") + .run_on ({scene.plRdr.render(Run)}) + .sync_with ({commonScene.pl.hierarchy(Ready), commonScene.pl.transform(Ready), commonScene.pl.activeEnt(Ready), scene.plRdr.drawTransforms(Modify_), scene.plRdr.drawEnt(Ready), scene.plRdr.drawEntResized(Done), commonScene.pl.activeEntResized(Done)}) + .push_to (out.m_tasks) + .args ({ commonScene.di.basic, commonScene.di.drawing, idScnRender, idDrawTfObservers }) + .func([] (ACtxBasic const& rBasic, ACtxDrawing const& rDrawing, ACtxSceneRender& rScnRender, DrawTfObservers &rDrawTfObservers) noexcept + { + auto rootChildren = SysSceneGraph::children(rBasic.m_scnGraph); + SysRender::update_draw_transforms( + { + .scnGraph = rBasic .m_scnGraph, + .transforms = rBasic .m_transform, + .activeToDraw = rScnRender.m_activeToDraw, + .needDrawTf = rScnRender.m_needDrawTf, + .rDrawTf = rScnRender.m_drawTransform + }, + rootChildren.begin(), + rootChildren.end(), + [&rDrawTfObservers, &rScnRender] (Matrix4 const& transform, active::ActiveEnt ent, int depth) + { + auto const enableInt = std::array{rScnRender.drawTfObserverEnable[ent]}; + auto const enableBits = lgrn::bit_view(enableInt); + + for (std::size_t idx : enableBits.ones()) + { + DrawTfObservers::Observer const &rObserver = rDrawTfObservers.observers[idx]; + rObserver.func(rScnRender, transform, ent, depth, rObserver.data); + } + }); + }); + + rFB.task() + .name ("Delete DrawEntity of deleted ActiveEnts") + .run_on ({commonScene.di.activeEntDel(UseOrRun)}) + .sync_with ({scene.plRdr.drawEntDelete(Modify_)}) + .push_to (out.m_tasks) + .args ({ idScnRender, commonScene.di.activeEntDel, idDrawEntDel }) + .func([] (ACtxSceneRender& rScnRender, ActiveEntVec_t const& rActiveEntDel, DrawEntVec_t& rDrawEntDel) noexcept + { + for (ActiveEnt const ent : rActiveEntDel) + { + if (rScnRender.m_activeToDraw.size() < std::size_t(ent)) + { + continue; + } + DrawEnt const drawEnt = std::exchange(rScnRender.m_activeToDraw[ent], lgrn::id_null()); + if (drawEnt != lgrn::id_null()) + { + rDrawEntDel.push_back(drawEnt); + } + } + }); + + rFB.task() + .name ("Delete drawing components") + .run_on ({scene.plRdr.drawEntDelete(UseOrRun)}) + .sync_with ({scene.plRdr.entTexture(Delete), scene.plRdr.entMesh(Delete)}) + .push_to (out.m_tasks) + .args ({ commonScene.di.drawing, idScnRender, idDrawEntDel }) + .func([] (ACtxDrawing& rDrawing, ACtxSceneRender& rScnRender, DrawEntVec_t const& rDrawEntDel) noexcept + { + SysRender::update_delete_drawing(rScnRender, rDrawing, rDrawEntDel.cbegin(), rDrawEntDel.cend()); + }); + + rFB.task() + .name ("Delete DrawEntity IDs") + .run_on ({scene.plRdr.drawEntDelete(UseOrRun)}) + .sync_with ({scene.plRdr.drawEnt(Delete)}) + .push_to (out.m_tasks) + .args ({ idScnRender, idDrawEntDel }) + .func([] (ACtxSceneRender& rScnRender, DrawEntVec_t const& rDrawEntDel) noexcept + { + for (DrawEnt const drawEnt : rDrawEntDel) + { + if (rScnRender.m_drawIds.exists(drawEnt)) + { + rScnRender.m_drawIds.remove(drawEnt); + } + } + }); + + rFB.task() + .name ("Delete DrawEnt from materials") + .run_on ({scene.plRdr.drawEntDelete(UseOrRun)}) + .sync_with ({scene.plRdr.material(Delete)}) + .push_to (out.m_tasks) + .args ({ idScnRender, idDrawEntDel }) + .func([] (ACtxSceneRender& rScnRender, DrawEntVec_t const& rDrawEntDel) noexcept + { + for (DrawEnt const ent : rDrawEntDel) + { + for (Material &rMat : rScnRender.m_materials) + { + if (std::size_t(ent) < rMat.m_ents.size()) + { + rMat.m_ents.erase(ent); + } + } + } + }); + + rFB.task() + .name ("Clear DrawEnt delete vector once we're done with it") + .run_on ({scene.plRdr.drawEntDelete(Clear)}) + .push_to (out.m_tasks) + .args ({ idDrawEntDel }) + .func([] (DrawEntVec_t& rDrawEntDel) noexcept + { + rDrawEntDel.clear(); + }); + + rFB.task() + .name ("Clear dirty DrawEnt's textures once we're done with it") + .run_on ({scene.plRdr.entMeshDirty(Clear)}) + .push_to (out.m_tasks) + .args ({ idScnRender}) + .func([] (ACtxSceneRender& rScnRender) noexcept + { + rScnRender.m_meshDirty.clear(); + }); + + rFB.task() + .name ("Clear dirty DrawEnt's textures once we're done with it") + .run_on ({scene.plRdr.entTextureDirty(Clear)}) + .push_to (out.m_tasks) + .args ({ idScnRender}) + .func([] (ACtxSceneRender& rScnRender) noexcept + { + rScnRender.m_diffuseDirty.clear(); + }); + + rFB.task() + .name ("Clear dirty materials once we're done with it") + .run_on ({scene.plRdr.materialDirty(Clear)}) + .push_to (out.m_tasks) + .args ({ idScnRender}) + .func([] (ACtxSceneRender& rScnRender) noexcept + { + for (Material &rMat : rScnRender.m_materials) + { + rMat.m_dirty.clear(); + } + }); + + rFB.task() + .name ("Clean up scene owners") + .run_on ({windowApp.pl.cleanup(Run_)}) + .push_to (out.m_tasks) + .args ({ commonScene.di.drawing, idScnRender}) + .func([] (ACtxDrawing& rDrawing, ACtxSceneRender& rScnRender) noexcept + { + SysRender::clear_owners(rScnRender, rDrawing); + }); + + return out; +} // setup_scene_renderer + +#endif + +} // namespace adera diff --git a/src/adera_app/features/common.h b/src/adera_app/features/common.h new file mode 100644 index 00000000..7f254758 --- /dev/null +++ b/src/adera_app/features/common.h @@ -0,0 +1,50 @@ +/** + * Open Space Program + * Copyright © 2019-2022 Open Space Program Project + * + * MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#pragma once + + +#include + +#include +#include +#include +#include + +#include + +namespace adera +{ + +extern osp::fw::FeatureDef const ftrMain; + +extern osp::fw::FeatureDef const ftrScene; + +extern osp::fw::FeatureDef const ftrCommonScene; + +extern osp::fw::FeatureDef const ftrWindowApp; + +extern osp::fw::FeatureDef const ftrRenderer; + +} // namespace adera diff --git a/src/testapp/sessions/jolt.cpp b/src/adera_app/features/jolt.cpp similarity index 89% rename from src/testapp/sessions/jolt.cpp rename to src/adera_app/features/jolt.cpp index 35e22334..b4c793e7 100644 --- a/src/testapp/sessions/jolt.cpp +++ b/src/adera_app/features/jolt.cpp @@ -22,6 +22,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ + +#if 0 #include "jolt.h" #include "physics.h" #include "shapes.h" @@ -46,12 +48,12 @@ using namespace ospjolt; using osp::restypes::gc_importer; using Corrade::Containers::arrayView; -namespace testapp::scenes +namespace adera { Session setup_jolt( - TopTaskBuilder& rBuilder, + TopTaskBuilder& rFB, ArrayView const topData, osp::Session const& scene, Session const& commonScene, @@ -66,43 +68,43 @@ Session setup_jolt( OSP_DECLARE_GET_DATA_IDS(commonScene, TESTAPP_DATA_COMMON_SCENE); OSP_DECLARE_GET_DATA_IDS(physics, TESTAPP_DATA_PHYSICS); - auto const tgScn = scene .get_pipelines(); - auto const tgCS = commonScene .get_pipelines(); + auto const scene.pl = scene .get_pipelines(); + auto const commonScene.pl = commonScene .get_pipelines(); auto const tgPhy = physics .get_pipelines(); Session out; OSP_DECLARE_CREATE_DATA_IDS(out, topData, TESTAPP_DATA_JOLT); - auto const tgJolt = out.create_pipelines(rBuilder); + auto const tgJolt = out.create_pipelines(rFB); - rBuilder.pipeline(tgJolt.joltBody).parent(tgScn.update); + rFB.pipeline(tgJolt.joltBody).parent(scene.pl.update); - top_emplace< ACtxJoltWorld >(topData, idJolt, 2); + rFB.data_emplace< ACtxJoltWorld >(topData, idJolt, 2); using ospjolt::SysJolt; - rBuilder.task() + rFB.task() .name ("Delete Jolt components") - .run_on ({tgCS.activeEntDelete(UseOrRun)}) + .run_on ({commonScene.di.activeEntDel(UseOrRun)}) .sync_with ({tgJolt.joltBody(Delete)}) .push_to (out.m_tasks) - .args({ idJolt, idActiveEntDel }) + .args({ idJolt, commonScene.di.activeEntDel }) .func([] (ACtxJoltWorld& rJolt, ActiveEntVec_t const& rActiveEntDel) noexcept { SysJolt::update_delete (rJolt, rActiveEntDel.cbegin(), rActiveEntDel.cend()); }); - rBuilder.task() + rFB.task() .name ("Update Jolt world") - .run_on ({tgScn.update(Run)}) - .sync_with ({tgJolt.joltBody(Prev), tgCS.hierarchy(Prev), tgPhy.physBody(Prev), tgPhy.physUpdate(Run), tgCS.transform(Prev)}) + .run_on ({scene.pl.update(Run)}) + .sync_with ({tgJolt.joltBody(Prev), commonScene.pl.hierarchy(Prev), tgPhy.physBody(Prev), tgPhy.physUpdate(Run), commonScene.pl.transform(Prev)}) .push_to (out.m_tasks) - .args({ idBasic, idPhys, idJolt, idDeltaTimeIn }) + .args({ commonScene.di.basic, idPhys, idJolt, idDeltaTimeIn }) .func([] (ACtxBasic& rBasic, ACtxPhysics& rPhys, ACtxJoltWorld& rJolt, float const deltaTimeIn, WorkerContext ctx) noexcept { SysJolt::update_world(rPhys, rJolt, deltaTimeIn, rBasic.m_transform); }); - top_emplace< ACtxJoltWorld >(topData, idJolt, 2); + rFB.data_emplace< ACtxJoltWorld >(topData, idJolt, 2); return out; } // setup_jolt @@ -111,13 +113,13 @@ Session setup_jolt( osp::Session setup_jolt_factors( - TopTaskBuilder& rBuilder, + TopTaskBuilder& rFB, ArrayView topData) { Session out; OSP_DECLARE_CREATE_DATA_IDS(out, topData, TESTAPP_DATA_JOLT_FORCES); - auto &rFactors = top_emplace(topData, idJoltFactors); + auto &rFactors = rFB.data_emplace(topData, idJoltFactors); std::fill(rFactors.begin(), rFactors.end(), 0); @@ -128,7 +130,7 @@ osp::Session setup_jolt_factors( osp::Session setup_jolt_force_accel( - TopTaskBuilder& rBuilder, + TopTaskBuilder& rFB, ArrayView topData, Session const& jolt, Session const& joltFactors, @@ -138,12 +140,12 @@ osp::Session setup_jolt_force_accel( OSP_DECLARE_GET_DATA_IDS(jolt, TESTAPP_DATA_JOLT); OSP_DECLARE_GET_DATA_IDS(joltFactors, TESTAPP_DATA_JOLT_FORCES); - auto &rJolt = top_get(topData, idJolt); + auto &rJolt = rFB.data_get(topData, idJolt); Session joltAccel; OSP_DECLARE_CREATE_DATA_IDS(joltAccel, topData, TESTAPP_DATA_JOLT_ACCEL); - auto &rAccel = top_emplace(topData, idAcceleration, accel); + auto &rAccel = rFB.data_emplace(topData, idAcceleration, accel); ACtxJoltWorld::ForceFactorFunc const factor { @@ -164,7 +166,7 @@ osp::Session setup_jolt_force_accel( std::size_t const index = rJolt.m_factors.size(); rJolt.m_factors.emplace_back(factor); - auto factorBits = lgrn::bit_view(top_get(topData, idJoltFactors)); + auto factorBits = lgrn::bit_view(rFB.data_get(topData, idJoltFactors)); factorBits.set(index); return joltAccel; @@ -174,7 +176,7 @@ osp::Session setup_jolt_force_accel( Session setup_phys_shapes_jolt( - TopTaskBuilder& rBuilder, + TopTaskBuilder& rFB, ArrayView const topData, Session const& commonScene, Session const& physics, @@ -195,12 +197,12 @@ Session setup_phys_shapes_jolt( Session out; - rBuilder.task() + rFB.task() .name ("Add Jolt physics to spawned shapes") .run_on ({tgShSp.spawnRequest(UseOrRun)}) .sync_with ({tgShSp.spawnedEnts(UseOrRun), tgJolt.joltBody(New), tgPhy.physUpdate(Done)}) .push_to (out.m_tasks) - .args({ idBasic, idPhysShapes, idPhys, idJolt, idJoltFactors }) + .args({ commonScene.di.basic, idPhysShapes, idPhys, idJolt, idJoltFactors }) .func([] (ACtxBasic const &rBasic, ACtxPhysShapes& rPhysShapes, ACtxPhysics& rPhys, ACtxJoltWorld& rJolt, ForceFactors_t joltFactors) noexcept { @@ -317,7 +319,7 @@ void compound_collect_recurse( Session setup_vehicle_spawn_jolt( - TopTaskBuilder& rBuilder, + TopTaskBuilder& rFB, ArrayView const topData, Session const& application, Session const& commonScene, @@ -334,7 +336,7 @@ Session setup_vehicle_spawn_jolt( OSP_DECLARE_GET_DATA_IDS(vehicleSpawn, TESTAPP_DATA_VEHICLE_SPAWN); OSP_DECLARE_GET_DATA_IDS(jolt, TESTAPP_DATA_JOLT); OSP_DECLARE_GET_DATA_IDS(parts, TESTAPP_DATA_PARTS); - auto const tgCS = commonScene .get_pipelines(); + auto const commonScene.pl = commonScene .get_pipelines(); auto const tgPhy = physics .get_pipelines(); auto const tgPf = prefabs .get_pipelines(); auto const tgParts = parts .get_pipelines(); @@ -343,12 +345,12 @@ Session setup_vehicle_spawn_jolt( Session out; - rBuilder.task() + rFB.task() .name ("Create root ActiveEnts for each Weld") .run_on ({tgVhSp.spawnRequest(UseOrRun)}) - .sync_with ({tgCS.activeEnt(New), tgCS.activeEntResized(Schedule), tgParts.mapWeldActive(Modify), tgVhSp.rootEnts(Resize)}) + .sync_with ({commonScene.pl.activeEnt(New), commonScene.pl.activeEntResized(Schedule), tgParts.mapWeldActive(Modify), tgVhSp.rootEnts(Resize)}) .push_to (out.m_tasks) - .args ({ idBasic, idVehicleSpawn, idScnParts}) + .args ({ commonScene.di.basic, idVehicleSpawn, idScnParts}) .func([] (ACtxBasic& rBasic, ACtxVehicleSpawn& rVehicleSpawn, ACtxParts& rScnParts) noexcept { LGRN_ASSERT(rVehicleSpawn.new_vehicle_count() != 0); @@ -365,12 +367,12 @@ Session setup_vehicle_spawn_jolt( } }); - rBuilder.task() + rFB.task() .name ("Add vehicle entities to Scene Graph") .run_on ({tgVhSp.spawnRequest(UseOrRun)}) - .sync_with ({tgVhSp.rootEnts(UseOrRun), tgParts.mapWeldActive(Ready), tgPf.spawnedEnts(UseOrRun), tgPf.spawnRequest(UseOrRun), tgPf.inSubtree(Run), tgCS.transform(Ready), tgCS.hierarchy(Modify)}) + .sync_with ({tgVhSp.rootEnts(UseOrRun), tgParts.mapWeldActive(Ready), tgPf.spawnedEnts(UseOrRun), tgPf.spawnRequest(UseOrRun), tgPf.inSubtree(Run), commonScene.pl.transform(Ready), commonScene.pl.hierarchy(Modify)}) .push_to (out.m_tasks) - .args ({ idBasic, idVehicleSpawn, idScnParts, idPrefabs, idResources}) + .args ({ commonScene.di.basic, idVehicleSpawn, idScnParts, idPrefabs, mainApp.di.resources}) .func([] (ACtxBasic& rBasic, ACtxVehicleSpawn const& rVehicleSpawn, ACtxParts& rScnParts, ACtxPrefabs& rPrefabs, Resources& rResources) noexcept { LGRN_ASSERT(rVehicleSpawn.new_vehicle_count() != 0); @@ -426,12 +428,12 @@ Session setup_vehicle_spawn_jolt( } }); - rBuilder.task() + rFB.task() .name ("Add Jolt physics to Weld entities") .run_on ({tgVhSp.spawnRequest(UseOrRun)}) - .sync_with ({tgVhSp.rootEnts(UseOrRun), tgPf.spawnedEnts(UseOrRun), tgCS.transform(Ready), tgPhy.physBody(Ready), tgJolt.joltBody(New), tgPhy.physUpdate(Done), tgCS.hierarchy(Ready)}) + .sync_with ({tgVhSp.rootEnts(UseOrRun), tgPf.spawnedEnts(UseOrRun), commonScene.pl.transform(Ready), tgPhy.physBody(Ready), tgJolt.joltBody(New), tgPhy.physUpdate(Done), commonScene.pl.hierarchy(Ready)}) .push_to (out.m_tasks) - .args ({ idBasic, idPhys, idJolt, idVehicleSpawn, idScnParts}) + .args ({ commonScene.di.basic, idPhys, idJolt, idVehicleSpawn, idScnParts}) .func([] (ACtxBasic& rBasic, ACtxPhysics& rPhys, ACtxJoltWorld& rJolt, ACtxVehicleSpawn const& rVehicleSpawn, ACtxParts const& rScnParts) noexcept { LGRN_ASSERT(rVehicleSpawn.new_vehicle_count() != 0); @@ -689,7 +691,7 @@ static void rocket_thrust_force(BodyId const bodyId, ACtxJoltWorld const& rJolt, } Session setup_rocket_thrust_jolt( - TopTaskBuilder& rBuilder, + TopTaskBuilder& rFB, ArrayView const topData, Session const& scene, Session const& commonScene, @@ -707,21 +709,21 @@ Session setup_rocket_thrust_jolt( OSP_DECLARE_GET_DATA_IDS(signalsFloat, TESTAPP_DATA_SIGNALS_FLOAT) OSP_DECLARE_GET_DATA_IDS(jolt, TESTAPP_DATA_JOLT); OSP_DECLARE_GET_DATA_IDS(joltFactors, TESTAPP_DATA_JOLT_FORCES); - auto const tgScn = scene .get_pipelines(); + auto const scene.pl = scene .get_pipelines(); auto const tgParts = parts .get_pipelines(); auto const tgJolt = jolt .get_pipelines(); Session out; OSP_DECLARE_CREATE_DATA_IDS(out, topData, TESTAPP_DATA_ROCKETS_JOLT); - auto &rRocketsJolt = top_emplace< ACtxRocketsJolt >(topData, idRocketsJolt); + auto &rRocketsJolt = rFB.data_emplace< ACtxRocketsJolt >(topData, idRocketsJolt); - rBuilder.task() + rFB.task() .name ("Assign rockets to Jolt bodies") - .run_on ({tgScn.update(Run)}) + .run_on ({scene.pl.update(Run)}) .sync_with ({tgParts.weldIds(Ready), tgJolt.joltBody(Ready), tgParts.connect(Ready)}) .push_to (out.m_tasks) - .args ({ idBasic, idPhys, idJolt, idScnParts, idRocketsJolt, idJoltFactors}) + .args ({ commonScene.di.basic, idPhys, idJolt, idScnParts, idRocketsJolt, idJoltFactors}) .func([] (ACtxBasic& rBasic, ACtxPhysics& rPhys, ACtxJoltWorld& rJolt, ACtxParts const& rScnParts, ACtxRocketsJolt& rRocketsJolt, ForceFactors_t const& rJoltFactors) noexcept { using adera::gc_mtMagicRocket; @@ -740,8 +742,8 @@ Session setup_rocket_thrust_jolt( } }); - auto &rScnParts = top_get< ACtxParts > (topData, idScnParts); - auto &rSigValFloat = top_get< SignalValues_t > (topData, idSigValFloat); + auto &rScnParts = rFB.data_get< ACtxParts > (topData, idScnParts); + auto &rSigValFloat = rFB.data_get< SignalValues_t > (topData, idSigValFloat); Machines &rMachines = rScnParts.machines; @@ -751,16 +753,18 @@ Session setup_rocket_thrust_jolt( .m_userData = { &rRocketsJolt, &rMachines, &rSigValFloat } }; - auto &rJolt = top_get(topData, idJolt); + auto &rJolt = rFB.data_get(topData, idJolt); std::size_t const index = rJolt.m_factors.size(); rJolt.m_factors.emplace_back(factor); - auto factorBits = lgrn::bit_view(top_get(topData, idJoltFactors)); + auto factorBits = lgrn::bit_view(rFB.data_get(topData, idJoltFactors)); factorBits.set(index); return out; } // setup_rocket_thrust_jolt -} // namespace testapp::scenes +} // namespace adera + +#endif diff --git a/src/testapp/sessions/jolt.h b/src/adera_app/features/jolt.h similarity index 89% rename from src/testapp/sessions/jolt.h rename to src/adera_app/features/jolt.h index 03d8077d..49fa044d 100644 --- a/src/testapp/sessions/jolt.h +++ b/src/adera_app/features/jolt.h @@ -24,6 +24,8 @@ */ #pragma once +#if 0 + #include "../scenarios.h" #include @@ -36,14 +38,14 @@ #include -namespace testapp::scenes +namespace adera { /** * @brief Jolt physics integration */ osp::Session setup_jolt( - osp::TopTaskBuilder& rBuilder, + osp::TopTaskBuilder& rFB, osp::ArrayView topData, osp::Session const& scene, osp::Session const& commonScene, @@ -56,14 +58,14 @@ osp::Session setup_jolt( * functions contribute to its force and torque */ osp::Session setup_jolt_factors( - osp::TopTaskBuilder& rBuilder, + osp::TopTaskBuilder& rFB, osp::ArrayView topData); /** * @brief Setup constant acceleration force, add to a force factor bitset */ osp::Session setup_jolt_force_accel( - osp::TopTaskBuilder& rBuilder, + osp::TopTaskBuilder& rFB, osp::ArrayView topData, osp::Session const& jolt, osp::Session const& joltFactors, @@ -73,7 +75,7 @@ osp::Session setup_jolt_force_accel( * @brief Support for Shape Spawner physics using Jolt Physics */ osp::Session setup_phys_shapes_jolt( - osp::TopTaskBuilder& rBuilder, + osp::TopTaskBuilder& rFB, osp::ArrayView topData, osp::Session const& commonScene, osp::Session const& physics, @@ -85,7 +87,7 @@ osp::Session setup_phys_shapes_jolt( * @brief Support for Vehicle physics using Jolt Physics */ osp::Session setup_vehicle_spawn_jolt( - osp::TopTaskBuilder& rBuilder, + osp::TopTaskBuilder& rFB, osp::ArrayView topData, osp::Session const& application, osp::Session const& commonScene, @@ -99,7 +101,7 @@ osp::Session setup_vehicle_spawn_jolt( * @brief Add thrust forces to Magic Rockets from setup_mach_rocket */ osp::Session setup_rocket_thrust_jolt( - osp::TopTaskBuilder& rBuilder, + osp::TopTaskBuilder& rFB, osp::ArrayView topData, osp::Session const& scene, osp::Session const& commonScene, @@ -110,4 +112,6 @@ osp::Session setup_rocket_thrust_jolt( osp::Session const& jolt, osp::Session const& joltFactors); -} // namespace testapp::scenes +} // namespace adera + +#endif diff --git a/src/testapp/sessions/misc.cpp b/src/adera_app/features/misc.cpp similarity index 77% rename from src/testapp/sessions/misc.cpp rename to src/adera_app/features/misc.cpp index 03f06245..e64bcb9d 100644 --- a/src/testapp/sessions/misc.cpp +++ b/src/adera_app/features/misc.cpp @@ -43,7 +43,7 @@ using osp::input::EButtonControlIndex; // for the 0xrrggbb_rgbf and angle literalss using namespace Magnum::Math::Literals; -namespace testapp::scenes +namespace adera { void create_materials( @@ -52,7 +52,7 @@ void create_materials( int const count) { OSP_DECLARE_GET_DATA_IDS(sceneRenderer, TESTAPP_DATA_SCENE_RENDERER); - auto &rScnRender = top_get< ACtxSceneRender >(topData, idScnRender); + auto &rScnRender = rFB.data_get< ACtxSceneRender >(topData, idScnRender); for (int i = 0; i < count; ++i) { @@ -66,7 +66,7 @@ void create_materials( Session setup_camera_ctrl( - TopTaskBuilder& rBuilder, + TopTaskBuilder& rFB, ArrayView const topData, Session const& windowApp, Session const& sceneRenderer, @@ -74,23 +74,23 @@ Session setup_camera_ctrl( { OSP_DECLARE_GET_DATA_IDS(windowApp, TESTAPP_DATA_WINDOW_APP); OSP_DECLARE_GET_DATA_IDS(magnumScene, TESTAPP_DATA_MAGNUM_SCENE); - auto const tgScnRdr = sceneRenderer .get_pipelines(); + auto const scene.plRdr = sceneRenderer .get_pipelines(); auto const tgSR = magnumScene .get_pipelines(); - auto const tgWin = windowApp .get_pipelines(); + auto const windowApp.pl = windowApp .get_pipelines(); - auto &rUserInput = top_get< osp::input::UserInputHandler >(topData, idUserInput); + auto &rUserInput = rFB.data_get< osp::input::UserInputHandler >(topData, windowApp.di.userInput); Session out; OSP_DECLARE_CREATE_DATA_IDS(out, topData, TESTAPP_DATA_CAMERA_CTRL); - auto const tgCmCt = out.create_pipelines(rBuilder); + auto const tgCmCt = out.create_pipelines(rFB); - top_emplace< ACtxCameraController > (topData, idCamCtrl, rUserInput); + rFB.data_emplace< ACtxCameraController > (topData, idCamCtrl, rUserInput); - rBuilder.pipeline(tgCmCt.camCtrl).parent(tgWin.sync); + rFB.pipeline(tgCmCt.camCtrl).parent(windowApp.pl.sync); - rBuilder.task() + rFB.task() .name ("Position Rendering Camera according to Camera Controller") - .run_on ({tgScnRdr.render(Run)}) + .run_on ({scene.plRdr.render(Run)}) .sync_with ({tgCmCt.camCtrl(Ready), tgSR.camera(Modify)}) .push_to (out.m_tasks) .args ({ idCamCtrl, idCamera }) @@ -106,7 +106,7 @@ Session setup_camera_ctrl( Session setup_camera_free( - TopTaskBuilder& rBuilder, + TopTaskBuilder& rFB, ArrayView const topData, Session const& windowApp, Session const& scene, @@ -115,14 +115,14 @@ Session setup_camera_free( OSP_DECLARE_GET_DATA_IDS(scene, TESTAPP_DATA_SCENE); OSP_DECLARE_GET_DATA_IDS(cameraCtrl, TESTAPP_DATA_CAMERA_CTRL); - auto const tgWin = windowApp .get_pipelines(); + auto const windowApp.pl = windowApp .get_pipelines(); auto const tgCmCt = cameraCtrl .get_pipelines(); Session out; - rBuilder.task() + rFB.task() .name ("Move Camera controller") - .run_on ({tgWin.inputs(Run)}) + .run_on ({windowApp.pl.inputs(Run)}) .sync_with ({tgCmCt.camCtrl(Modify)}) .push_to (out.m_tasks) .args ({ idCamCtrl, idDeltaTimeIn }) @@ -139,7 +139,7 @@ Session setup_camera_free( Session setup_cursor( - TopTaskBuilder& rBuilder, + TopTaskBuilder& rFB, ArrayView const topData, Session const& application, Session const& sceneRenderer, @@ -153,17 +153,17 @@ Session setup_cursor( OSP_DECLARE_GET_DATA_IDS(commonScene, TESTAPP_DATA_COMMON_SCENE); OSP_DECLARE_GET_DATA_IDS(cameraCtrl, TESTAPP_DATA_CAMERA_CTRL); auto const tgCmCt = cameraCtrl .get_pipelines(); - auto const tgScnRdr = sceneRenderer .get_pipelines(); + auto const scene.plRdr = sceneRenderer .get_pipelines(); - auto &rResources = top_get< Resources > (topData, idResources); - auto &rScnRender = top_get< ACtxSceneRender > (topData, idScnRender); - auto &rDrawing = top_get< ACtxDrawing > (topData, idDrawing); - auto &rDrawingRes = top_get< ACtxDrawingRes > (topData, idDrawingRes); + auto &rResources = rFB.data_get< Resources > (topData, mainApp.di.resources); + auto &rScnRender = rFB.data_get< ACtxSceneRender > (topData, idScnRender); + auto &rDrawing = rFB.data_get< ACtxDrawing > (topData, commonScene.di.drawing); + auto &rDrawingRes = rFB.data_get< ACtxDrawingRes > (topData, commonScene.di.drawingRes); Session out; auto const [idCursorEnt] = out.acquire_data<1>(topData); - auto const cursorEnt = top_emplace(topData, idCursorEnt, rScnRender.m_drawIds.create()); + auto const cursorEnt = rFB.data_emplace(topData, idCursorEnt, rScnRender.m_drawIds.create()); rScnRender.resize_draw(); rScnRender.m_mesh[cursorEnt] = SysRender::add_drawable_mesh(rDrawing, rDrawingRes, rResources, pkg, "cubewire"); @@ -174,10 +174,10 @@ Session setup_cursor( Material &rMat = rScnRender.m_materials[material]; rMat.m_ents.insert(cursorEnt); - rBuilder.task() + rFB.task() .name ("Move cursor") - .run_on ({tgScnRdr.render(Run)}) - .sync_with ({tgCmCt.camCtrl(Ready), tgScnRdr.drawTransforms(Modify_), tgScnRdr.drawEntResized(Done)}) + .run_on ({scene.plRdr.render(Run)}) + .sync_with ({tgCmCt.camCtrl(Ready), scene.plRdr.drawTransforms(Modify_), scene.plRdr.drawEntResized(Done)}) .push_to (out.m_tasks) .args ({ idCursorEnt, idCamCtrl, idScnRender }) .func([] (DrawEnt const cursorEnt, ACtxCameraController const& rCamCtrl, ACtxSceneRender& rScnRender) noexcept @@ -189,5 +189,5 @@ Session setup_cursor( } // setup_cursor -} // namespace testapp::scenes +} // namespace adera #endif diff --git a/src/testapp/sessions/misc.h b/src/adera_app/features/misc.h similarity index 93% rename from src/testapp/sessions/misc.h rename to src/adera_app/features/misc.h index 0e3cf891..3fedc7d8 100644 --- a/src/testapp/sessions/misc.h +++ b/src/adera_app/features/misc.h @@ -30,7 +30,7 @@ #include #include -namespace testapp::scenes +namespace adera { void create_materials( @@ -42,7 +42,7 @@ void create_materials( * @brief Create CameraController connected to an app's UserInputHandler */ osp::Session setup_camera_ctrl( - osp::TopTaskBuilder& rBuilder, + osp::TopTaskBuilder& rFB, osp::ArrayView topData, osp::Session const& windowApp, osp::Session const& sceneRenderer, @@ -52,7 +52,7 @@ osp::Session setup_camera_ctrl( * @brief Adds free cam controls to a CameraController */ osp::Session setup_camera_free( - osp::TopTaskBuilder& rBuilder, + osp::TopTaskBuilder& rFB, osp::ArrayView topData, osp::Session const& windowApp, osp::Session const& scene, @@ -62,7 +62,7 @@ osp::Session setup_camera_free( * @brief Wireframe cube over the camera controller's target */ osp::Session setup_cursor( - osp::TopTaskBuilder& rBuilder, + osp::TopTaskBuilder& rFB, osp::ArrayView topData, osp::Session const& application, osp::Session const& sceneRenderer, diff --git a/src/testapp/sessions/newton.cpp b/src/adera_app/features/newton.cpp similarity index 88% rename from src/testapp/sessions/newton.cpp rename to src/adera_app/features/newton.cpp index 63816bc7..a4391fbf 100644 --- a/src/testapp/sessions/newton.cpp +++ b/src/adera_app/features/newton.cpp @@ -47,12 +47,12 @@ using namespace ospnewton; using osp::restypes::gc_importer; using Corrade::Containers::arrayView; -namespace testapp::scenes +namespace adera { Session setup_newton( - TopTaskBuilder& rBuilder, + TopTaskBuilder& rFB, ArrayView const topData, osp::Session const& scene, Session const& commonScene, @@ -62,43 +62,43 @@ Session setup_newton( OSP_DECLARE_GET_DATA_IDS(commonScene, TESTAPP_DATA_COMMON_SCENE); OSP_DECLARE_GET_DATA_IDS(physics, TESTAPP_DATA_PHYSICS); - auto const tgScn = scene .get_pipelines(); - auto const tgCS = commonScene .get_pipelines(); + auto const scene.pl = scene .get_pipelines(); + auto const commonScene.pl = commonScene .get_pipelines(); auto const tgPhy = physics .get_pipelines(); Session out; OSP_DECLARE_CREATE_DATA_IDS(out, topData, TESTAPP_DATA_NEWTON); - auto const tgNwt = out.create_pipelines(rBuilder); + auto const tgNwt = out.create_pipelines(rFB); - rBuilder.pipeline(tgNwt.nwtBody).parent(tgScn.update); + rFB.pipeline(tgNwt.nwtBody).parent(scene.pl.update); - top_emplace< ACtxNwtWorld >(topData, idNwt, 2); + rFB.data_emplace< ACtxNwtWorld >(topData, idNwt, 2); using ospnewton::SysNewton; - rBuilder.task() + rFB.task() .name ("Delete Newton components") - .run_on ({tgCS.activeEntDelete(UseOrRun)}) + .run_on ({commonScene.di.activeEntDel(UseOrRun)}) .sync_with ({tgNwt.nwtBody(Delete)}) .push_to (out.m_tasks) - .args({ idNwt, idActiveEntDel }) + .args({ idNwt, commonScene.di.activeEntDel }) .func([] (ACtxNwtWorld& rNwt, ActiveEntVec_t const& rActiveEntDel) noexcept { SysNewton::update_delete (rNwt, rActiveEntDel.cbegin(), rActiveEntDel.cend()); }); - rBuilder.task() + rFB.task() .name ("Update Newton world") - .run_on ({tgScn.update(Run)}) - .sync_with ({tgNwt.nwtBody(Prev), tgCS.hierarchy(Prev), tgPhy.physBody(Prev), tgPhy.physUpdate(Run), tgCS.transform(Prev)}) + .run_on ({scene.pl.update(Run)}) + .sync_with ({tgNwt.nwtBody(Prev), commonScene.pl.hierarchy(Prev), tgPhy.physBody(Prev), tgPhy.physUpdate(Run), commonScene.pl.transform(Prev)}) .push_to (out.m_tasks) - .args({ idBasic, idPhys, idNwt, idDeltaTimeIn }) + .args({ commonScene.di.basic, idPhys, idNwt, idDeltaTimeIn }) .func([] (ACtxBasic& rBasic, ACtxPhysics& rPhys, ACtxNwtWorld& rNwt, float const deltaTimeIn, WorkerContext ctx) noexcept { SysNewton::update_world(rPhys, rNwt, deltaTimeIn, rBasic.m_scnGraph, rBasic.m_transform); }); - top_emplace< ACtxNwtWorld >(topData, idNwt, 2); + rFB.data_emplace< ACtxNwtWorld >(topData, idNwt, 2); return out; } // setup_newton @@ -107,13 +107,13 @@ Session setup_newton( osp::Session setup_newton_factors( - TopTaskBuilder& rBuilder, + TopTaskBuilder& rFB, ArrayView topData) { Session out; OSP_DECLARE_CREATE_DATA_IDS(out, topData, TESTAPP_DATA_NEWTON_FORCES); - auto &rFactors = top_emplace(topData, idNwtFactors); + auto &rFactors = rFB.data_emplace(topData, idNwtFactors); std::fill(rFactors.begin(), rFactors.end(), 0); @@ -124,7 +124,7 @@ osp::Session setup_newton_factors( osp::Session setup_newton_force_accel( - TopTaskBuilder& rBuilder, + TopTaskBuilder& rFB, ArrayView topData, Session const& newton, Session const& nwtFactors, @@ -134,12 +134,12 @@ osp::Session setup_newton_force_accel( OSP_DECLARE_GET_DATA_IDS(newton, TESTAPP_DATA_NEWTON); OSP_DECLARE_GET_DATA_IDS(nwtFactors, TESTAPP_DATA_NEWTON_FORCES); - auto &rNwt = top_get(topData, idNwt); + auto &rNwt = rFB.data_get(topData, idNwt); Session nwtAccel; OSP_DECLARE_CREATE_DATA_IDS(nwtAccel, topData, TESTAPP_DATA_NEWTON_ACCEL); - auto &rAccel = top_emplace(topData, idAcceleration, accel); + auto &rAccel = rFB.data_emplace(topData, idAcceleration, accel); ACtxNwtWorld::ForceFactorFunc const factor { @@ -160,7 +160,7 @@ osp::Session setup_newton_force_accel( std::size_t const index = rNwt.m_factors.size(); rNwt.m_factors.emplace_back(factor); - auto factorBits = lgrn::bit_view(top_get(topData, idNwtFactors)); + auto factorBits = lgrn::bit_view(rFB.data_get(topData, idNwtFactors)); factorBits.set(index); return nwtAccel; @@ -170,7 +170,7 @@ osp::Session setup_newton_force_accel( Session setup_phys_shapes_newton( - TopTaskBuilder& rBuilder, + TopTaskBuilder& rFB, ArrayView const topData, Session const& commonScene, Session const& physics, @@ -191,12 +191,12 @@ Session setup_phys_shapes_newton( Session out; - rBuilder.task() + rFB.task() .name ("Add Newton physics to spawned shapes") .run_on ({tgShSp.spawnRequest(UseOrRun)}) .sync_with ({tgShSp.spawnedEnts(UseOrRun), tgNwt.nwtBody(New), tgPhy.physUpdate(Done)}) .push_to (out.m_tasks) - .args({ idBasic, idPhysShapes, idPhys, idNwt, idNwtFactors }) + .args({ commonScene.di.basic, idPhysShapes, idPhys, idNwt, idNwtFactors }) .func([] (ACtxBasic const &rBasic, ACtxPhysShapes& rPhysShapes, ACtxPhysics& rPhys, ACtxNwtWorld& rNwt, ForceFactors_t nwtFactors) noexcept { for (std::size_t i = 0; i < rPhysShapes.m_spawnRequest.size(); ++i) @@ -284,7 +284,7 @@ void compound_collect_recurse( Session setup_vehicle_spawn_newton( - TopTaskBuilder& rBuilder, + TopTaskBuilder& rFB, ArrayView const topData, Session const& application, Session const& commonScene, @@ -301,7 +301,7 @@ Session setup_vehicle_spawn_newton( OSP_DECLARE_GET_DATA_IDS(vehicleSpawn, TESTAPP_DATA_VEHICLE_SPAWN); OSP_DECLARE_GET_DATA_IDS(newton, TESTAPP_DATA_NEWTON); OSP_DECLARE_GET_DATA_IDS(parts, TESTAPP_DATA_PARTS); - auto const tgCS = commonScene .get_pipelines(); + auto const commonScene.pl = commonScene .get_pipelines(); auto const tgPhy = physics .get_pipelines(); auto const tgPf = prefabs .get_pipelines(); auto const tgParts = parts .get_pipelines(); @@ -310,12 +310,12 @@ Session setup_vehicle_spawn_newton( Session out; - rBuilder.task() + rFB.task() .name ("Create root ActiveEnts for each Weld") .run_on ({tgVhSp.spawnRequest(UseOrRun)}) - .sync_with ({tgCS.activeEnt(New), tgCS.activeEntResized(Schedule), tgParts.mapWeldActive(Modify), tgVhSp.rootEnts(Resize)}) + .sync_with ({commonScene.pl.activeEnt(New), commonScene.pl.activeEntResized(Schedule), tgParts.mapWeldActive(Modify), tgVhSp.rootEnts(Resize)}) .push_to (out.m_tasks) - .args ({ idBasic, idVehicleSpawn, idScnParts}) + .args ({ commonScene.di.basic, idVehicleSpawn, idScnParts}) .func([] (ACtxBasic& rBasic, ACtxVehicleSpawn& rVehicleSpawn, ACtxParts& rScnParts) noexcept { LGRN_ASSERT(rVehicleSpawn.new_vehicle_count() != 0); @@ -332,12 +332,12 @@ Session setup_vehicle_spawn_newton( } }); - rBuilder.task() + rFB.task() .name ("Add vehicle entities to Scene Graph") .run_on ({tgVhSp.spawnRequest(UseOrRun)}) - .sync_with ({tgVhSp.rootEnts(UseOrRun), tgParts.mapWeldActive(Ready), tgPf.spawnedEnts(UseOrRun), tgPf.spawnRequest(UseOrRun), tgPf.inSubtree(Run), tgCS.transform(Ready), tgCS.hierarchy(Modify)}) + .sync_with ({tgVhSp.rootEnts(UseOrRun), tgParts.mapWeldActive(Ready), tgPf.spawnedEnts(UseOrRun), tgPf.spawnRequest(UseOrRun), tgPf.inSubtree(Run), commonScene.pl.transform(Ready), commonScene.pl.hierarchy(Modify)}) .push_to (out.m_tasks) - .args ({ idBasic, idVehicleSpawn, idScnParts, idPrefabs, idResources}) + .args ({ commonScene.di.basic, idVehicleSpawn, idScnParts, idPrefabs, mainApp.di.resources}) .func([] (ACtxBasic& rBasic, ACtxVehicleSpawn const& rVehicleSpawn, ACtxParts& rScnParts, ACtxPrefabs& rPrefabs, Resources& rResources) noexcept { LGRN_ASSERT(rVehicleSpawn.new_vehicle_count() != 0); @@ -393,12 +393,12 @@ Session setup_vehicle_spawn_newton( } }); - rBuilder.task() + rFB.task() .name ("Add Newton physics to Weld entities") .run_on ({tgVhSp.spawnRequest(UseOrRun)}) - .sync_with ({tgVhSp.rootEnts(UseOrRun), tgPf.spawnedEnts(UseOrRun), tgCS.transform(Ready), tgPhy.physBody(Ready), tgNwt.nwtBody(New), tgPhy.physUpdate(Done), tgCS.hierarchy(Ready)}) + .sync_with ({tgVhSp.rootEnts(UseOrRun), tgPf.spawnedEnts(UseOrRun), commonScene.pl.transform(Ready), tgPhy.physBody(Ready), tgNwt.nwtBody(New), tgPhy.physUpdate(Done), commonScene.pl.hierarchy(Ready)}) .push_to (out.m_tasks) - .args ({ idBasic, idPhys, idNwt, idVehicleSpawn, idScnParts}) + .args ({ commonScene.di.basic, idPhys, idNwt, idVehicleSpawn, idScnParts}) .func([] (ACtxBasic& rBasic, ACtxPhysics& rPhys, ACtxNwtWorld& rNwt, ACtxVehicleSpawn const& rVehicleSpawn, ACtxParts const& rScnParts) noexcept { LGRN_ASSERT(rVehicleSpawn.new_vehicle_count() != 0); @@ -637,7 +637,7 @@ static void rocket_thrust_force(NewtonBody const* pBody, BodyId const body, ACtx } Session setup_rocket_thrust_newton( - TopTaskBuilder& rBuilder, + TopTaskBuilder& rFB, ArrayView const topData, Session const& scene, Session const& commonScene, @@ -655,21 +655,21 @@ Session setup_rocket_thrust_newton( OSP_DECLARE_GET_DATA_IDS(signalsFloat, TESTAPP_DATA_SIGNALS_FLOAT) OSP_DECLARE_GET_DATA_IDS(newton, TESTAPP_DATA_NEWTON); OSP_DECLARE_GET_DATA_IDS(nwtFactors, TESTAPP_DATA_NEWTON_FORCES); - auto const tgScn = scene .get_pipelines(); + auto const scene.pl = scene .get_pipelines(); auto const tgParts = parts .get_pipelines(); auto const tgNwt = newton .get_pipelines(); Session out; OSP_DECLARE_CREATE_DATA_IDS(out, topData, TESTAPP_DATA_ROCKETS_NWT); - auto &rRocketsNwt = top_emplace< ACtxRocketsNwt >(topData, idRocketsNwt); + auto &rRocketsNwt = rFB.data_emplace< ACtxRocketsNwt >(topData, idRocketsNwt); - rBuilder.task() + rFB.task() .name ("Assign rockets to Newton bodies") - .run_on ({tgScn.update(Run)}) + .run_on ({scene.pl.update(Run)}) .sync_with ({tgParts.weldIds(Ready), tgNwt.nwtBody(Ready), tgParts.connect(Ready)}) .push_to (out.m_tasks) - .args ({ idBasic, idPhys, idNwt, idScnParts, idRocketsNwt, idNwtFactors}) + .args ({ commonScene.di.basic, idPhys, idNwt, idScnParts, idRocketsNwt, idNwtFactors}) .func([] (ACtxBasic& rBasic, ACtxPhysics& rPhys, ACtxNwtWorld& rNwt, ACtxParts const& rScnParts, ACtxRocketsNwt& rRocketsNwt, ForceFactors_t const& rNwtFactors) noexcept { using adera::gc_mtMagicRocket; @@ -688,8 +688,8 @@ Session setup_rocket_thrust_newton( } }); - auto &rScnParts = top_get< ACtxParts > (topData, idScnParts); - auto &rSigValFloat = top_get< SignalValues_t > (topData, idSigValFloat); + auto &rScnParts = rFB.data_get< ACtxParts > (topData, idScnParts); + auto &rSigValFloat = rFB.data_get< SignalValues_t > (topData, idSigValFloat); Machines &rMachines = rScnParts.machines; @@ -699,19 +699,19 @@ Session setup_rocket_thrust_newton( .m_userData = { &rRocketsNwt, &rMachines, &rSigValFloat } }; - auto &rNwt = top_get(topData, idNwt); + auto &rNwt = rFB.data_get(topData, idNwt); std::size_t const index = rNwt.m_factors.size(); rNwt.m_factors.emplace_back(factor); - auto factorBits = lgrn::bit_view(top_get(topData, idNwtFactors)); + auto factorBits = lgrn::bit_view(rFB.data_get(topData, idNwtFactors)); factorBits.set(index); return out; } // setup_rocket_thrust_newton -} // namespace testapp::scenes +} // namespace adera #endif diff --git a/src/testapp/sessions/newton.h b/src/adera_app/features/newton.h similarity index 89% rename from src/testapp/sessions/newton.h rename to src/adera_app/features/newton.h index 4d2ec3bf..a192595b 100644 --- a/src/testapp/sessions/newton.h +++ b/src/adera_app/features/newton.h @@ -36,14 +36,14 @@ #include -namespace testapp::scenes +namespace adera { /** * @brief Newton Dynamics physics integration */ osp::Session setup_newton( - osp::TopTaskBuilder& rBuilder, + osp::TopTaskBuilder& rFB, osp::ArrayView topData, osp::Session const& scene, osp::Session const& commonScene, @@ -56,14 +56,14 @@ osp::Session setup_newton( * functions contribute to its force and torque */ osp::Session setup_newton_factors( - osp::TopTaskBuilder& rBuilder, + osp::TopTaskBuilder& rFB, osp::ArrayView topData); /** * @brief Setup constant acceleration force, add to a force factor bitset */ osp::Session setup_newton_force_accel( - osp::TopTaskBuilder& rBuilder, + osp::TopTaskBuilder& rFB, osp::ArrayView topData, osp::Session const& newton, osp::Session const& nwtFactors, @@ -73,7 +73,7 @@ osp::Session setup_newton_force_accel( * @brief Support for Shape Spawner physics using Newton Dynamics */ osp::Session setup_phys_shapes_newton( - osp::TopTaskBuilder& rBuilder, + osp::TopTaskBuilder& rFB, osp::ArrayView topData, osp::Session const& commonScene, osp::Session const& physics, @@ -85,7 +85,7 @@ osp::Session setup_phys_shapes_newton( * @brief Support for Vehicle physics using Newton Dynamics */ osp::Session setup_vehicle_spawn_newton( - osp::TopTaskBuilder& rBuilder, + osp::TopTaskBuilder& rFB, osp::ArrayView topData, osp::Session const& application, osp::Session const& commonScene, @@ -99,7 +99,7 @@ osp::Session setup_vehicle_spawn_newton( * @brief Add thrust forces to Magic Rockets from setup_mach_rocket */ osp::Session setup_rocket_thrust_newton( - osp::TopTaskBuilder& rBuilder, + osp::TopTaskBuilder& rFB, osp::ArrayView topData, osp::Session const& scene, osp::Session const& commonScene, @@ -110,5 +110,5 @@ osp::Session setup_rocket_thrust_newton( osp::Session const& newton, osp::Session const& nwtFactors); -} // namespace testapp::scenes +} // namespace adera #endif diff --git a/src/testapp/sessions/physics.cpp b/src/adera_app/features/physics.cpp similarity index 64% rename from src/testapp/sessions/physics.cpp rename to src/adera_app/features/physics.cpp index abe8d7ea..4e256daf 100644 --- a/src/testapp/sessions/physics.cpp +++ b/src/adera_app/features/physics.cpp @@ -44,36 +44,36 @@ using namespace osp::draw; using osp::restypes::gc_importer; using Corrade::Containers::arrayView; -namespace testapp::scenes +namespace adera { Session setup_physics( - TopTaskBuilder& rBuilder, + TopTaskBuilder& rFB, ArrayView const topData, Session const& scene, Session const& commonScene) { OSP_DECLARE_GET_DATA_IDS(commonScene, TESTAPP_DATA_COMMON_SCENE); - auto const tgScn = scene .get_pipelines(); - auto const tgCS = commonScene.get_pipelines(); + auto const scene.pl = scene .get_pipelines(); + auto const commonScene.pl = commonScene.get_pipelines(); Session out; OSP_DECLARE_CREATE_DATA_IDS(out, topData, TESTAPP_DATA_PHYSICS); - auto const tgPhy = out.create_pipelines(rBuilder); + auto const tgPhy = out.create_pipelines(rFB); - rBuilder.pipeline(tgPhy.physBody) .parent(tgScn.update); - rBuilder.pipeline(tgPhy.physUpdate).parent(tgScn.update); + rFB.pipeline(tgPhy.physBody) .parent(scene.pl.update); + rFB.pipeline(tgPhy.physUpdate).parent(scene.pl.update); - top_emplace< ACtxPhysics > (topData, idPhys); + rFB.data_emplace< ACtxPhysics > (topData, idPhys); - rBuilder.task() + rFB.task() .name ("Delete Physics components") - .run_on ({tgCS.activeEntDelete(UseOrRun)}) + .run_on ({commonScene.di.activeEntDel(UseOrRun)}) .sync_with ({tgPhy.physBody(Delete)}) .push_to (out.m_tasks) - .args ({ idPhys, idActiveEntDel }) + .args ({ idPhys, commonScene.di.activeEntDel }) .func([] (ACtxPhysics& rPhys, ActiveEntVec_t const& rActiveEntDel) noexcept { SysPhysics::update_delete_phys(rPhys, rActiveEntDel.cbegin(), rActiveEntDel.cend()); @@ -87,7 +87,7 @@ Session setup_physics( Session setup_prefabs( - TopTaskBuilder& rBuilder, + TopTaskBuilder& rFB, ArrayView const topData, Session const& application, Session const& scene, @@ -97,26 +97,26 @@ Session setup_prefabs( OSP_DECLARE_GET_DATA_IDS(application, TESTAPP_DATA_APPLICATION); OSP_DECLARE_GET_DATA_IDS(commonScene, TESTAPP_DATA_COMMON_SCENE); OSP_DECLARE_GET_DATA_IDS(physics, TESTAPP_DATA_PHYSICS); - auto const tgScn = scene .get_pipelines(); - auto const tgCS = commonScene .get_pipelines(); + auto const scene.pl = scene .get_pipelines(); + auto const commonScene.pl = commonScene .get_pipelines(); auto const tgPhy = physics .get_pipelines(); Session out; OSP_DECLARE_CREATE_DATA_IDS(out, topData, TESTAPP_DATA_PREFABS); - auto const tgPf = out.create_pipelines(rBuilder); + auto const tgPf = out.create_pipelines(rFB); - rBuilder.pipeline(tgPf.spawnRequest).parent(tgScn.update); - rBuilder.pipeline(tgPf.spawnedEnts) .parent(tgScn.update); - rBuilder.pipeline(tgPf.ownedEnts) .parent(tgScn.update); - rBuilder.pipeline(tgPf.instanceInfo).parent(tgScn.update); - rBuilder.pipeline(tgPf.inSubtree) .parent(tgScn.update); + rFB.pipeline(tgPf.spawnRequest).parent(scene.pl.update); + rFB.pipeline(tgPf.spawnedEnts) .parent(scene.pl.update); + rFB.pipeline(tgPf.ownedEnts) .parent(scene.pl.update); + rFB.pipeline(tgPf.instanceInfo).parent(scene.pl.update); + rFB.pipeline(tgPf.inSubtree) .parent(scene.pl.update); - top_emplace< ACtxPrefabs > (topData, idPrefabs); + rFB.data_emplace< ACtxPrefabs > (topData, idPrefabs); - rBuilder.task() + rFB.task() .name ("Schedule Prefab spawn") .schedules ({tgPf.spawnRequest(Schedule_)}) - .sync_with ({tgScn.update(Run)}) + .sync_with ({scene.pl.update(Run)}) .push_to (out.m_tasks) .args ({ idPrefabs }) .func([] (ACtxPrefabs const& rPrefabs) noexcept -> TaskActions @@ -124,34 +124,34 @@ Session setup_prefabs( return rPrefabs.spawnRequest.empty() ? TaskAction::Cancel : TaskActions{}; }); - rBuilder.task() + rFB.task() .name ("Create Prefab entities") .run_on ({tgPf.spawnRequest(UseOrRun)}) - .sync_with ({tgCS.activeEnt(New), tgCS.activeEntResized(Schedule), tgPf.spawnedEnts(Resize)}) + .sync_with ({commonScene.pl.activeEnt(New), commonScene.pl.activeEntResized(Schedule), tgPf.spawnedEnts(Resize)}) .push_to (out.m_tasks) - .args ({ idPrefabs, idBasic, idResources}) + .args ({ idPrefabs, commonScene.di.basic, mainApp.di.resources}) .func([] (ACtxPrefabs& rPrefabs, ACtxBasic& rBasic, Resources& rResources) noexcept { SysPrefabInit::create_activeents(rPrefabs, rBasic, rResources); }); - rBuilder.task() + rFB.task() .name ("Init Prefab transforms") .run_on ({tgPf.spawnRequest(UseOrRun)}) - .sync_with ({tgPf.spawnedEnts(UseOrRun), tgCS.transform(New)}) + .sync_with ({tgPf.spawnedEnts(UseOrRun), commonScene.pl.transform(New)}) .push_to (out.m_tasks) - .args ({ idBasic, idResources, idPrefabs}) + .args ({ commonScene.di.basic, mainApp.di.resources, idPrefabs}) .func([] (ACtxBasic& rBasic, Resources& rResources, ACtxPrefabs& rPrefabs) noexcept { SysPrefabInit::init_transforms(rPrefabs, rResources, rBasic.m_transform); }); - rBuilder.task() + rFB.task() .name ("Init Prefab instance info") .run_on ({tgPf.spawnRequest(UseOrRun)}) .sync_with ({tgPf.spawnedEnts(UseOrRun), tgPf.instanceInfo(Modify)}) .push_to (out.m_tasks) - .args ({ idBasic, idResources, idPrefabs}) + .args ({ commonScene.di.basic, mainApp.di.resources, idPrefabs}) .func([] (ACtxBasic& rBasic, Resources& rResources, ACtxPrefabs& rPrefabs) noexcept { rPrefabs.instanceInfo.resize(rBasic.m_activeIds.capacity(), PrefabInstanceInfo{.prefab = lgrn::id_null()}); @@ -159,12 +159,12 @@ Session setup_prefabs( SysPrefabInit::init_info(rPrefabs, rResources); }); - rBuilder.task() + rFB.task() .name ("Init Prefab physics") .run_on ({tgPf.spawnRequest(UseOrRun)}) .sync_with ({tgPf.spawnedEnts(UseOrRun), tgPhy.physBody(Modify), tgPhy.physUpdate(Done)}) .push_to (out.m_tasks) - .args ({ idBasic, idResources, idPhys, idPrefabs}) + .args ({ commonScene.di.basic, mainApp.di.resources, idPhys, idPrefabs}) .func([] (ACtxBasic& rBasic, Resources& rResources, ACtxPhysics& rPhys, ACtxPrefabs& rPrefabs) noexcept { rPhys.m_hasColliders.resize(rBasic.m_activeIds.capacity()); @@ -173,7 +173,7 @@ Session setup_prefabs( SysPrefabInit::init_physics(rPrefabs, rResources, rPhys); }); - rBuilder.task() + rFB.task() .name ("Clear Prefab vector") .run_on ({tgPf.spawnRequest(Clear)}) .push_to (out.m_tasks) @@ -190,7 +190,7 @@ Session setup_prefabs( Session setup_prefab_draw( - TopTaskBuilder& rBuilder, + TopTaskBuilder& rFB, ArrayView const topData, Session const& application, Session const& windowApp, @@ -203,60 +203,60 @@ Session setup_prefab_draw( OSP_DECLARE_GET_DATA_IDS(sceneRenderer, TESTAPP_DATA_SCENE_RENDERER); OSP_DECLARE_GET_DATA_IDS(commonScene, TESTAPP_DATA_COMMON_SCENE); OSP_DECLARE_GET_DATA_IDS(prefabs, TESTAPP_DATA_PREFABS); - auto const tgWin = windowApp .get_pipelines< PlWindowApp >(); - auto const tgScnRdr = sceneRenderer .get_pipelines< PlSceneRenderer >(); - auto const tgCS = commonScene .get_pipelines< PlCommonScene >(); + auto const windowApp.pl = windowApp .get_pipelines< PlWindowApp >(); + auto const scene.plRdr = sceneRenderer .get_pipelines< PlSceneRenderer >(); + auto const commonScene.pl = commonScene .get_pipelines< PlCommonScene >(); auto const tgPf = prefabs .get_pipelines< PlPrefabs >(); Session out; auto const [idMaterial] = out.acquire_data<1>(topData); - top_emplace(topData, idMaterial, material); + rFB.data_emplace(topData, idMaterial, material); - rBuilder.task() + rFB.task() .name ("Create DrawEnts for prefabs") .run_on ({tgPf.spawnRequest(UseOrRun)}) - .sync_with ({tgPf.spawnedEnts(UseOrRun), tgCS.activeEntResized(Done), tgScnRdr.drawEntResized(ModifyOrSignal)}) + .sync_with ({tgPf.spawnedEnts(UseOrRun), commonScene.pl.activeEntResized(Done), scene.plRdr.drawEntResized(ModifyOrSignal)}) .push_to (out.m_tasks) - .args ({ idPrefabs, idResources, idBasic, idDrawing, idScnRender}) + .args ({ idPrefabs, mainApp.di.resources, commonScene.di.basic, commonScene.di.drawing, idScnRender}) .func([] (ACtxPrefabs& rPrefabs, Resources& rResources, ACtxBasic const& rBasic, ACtxDrawing& rDrawing, ACtxSceneRender& rScnRender) noexcept { SysPrefabDraw::init_drawents(rPrefabs, rResources, rBasic, rDrawing, rScnRender); }); - rBuilder.task() + rFB.task() .name ("Add mesh and material to prefabs") .run_on ({tgPf.spawnRequest(UseOrRun)}) - .sync_with ({tgPf.spawnedEnts(UseOrRun), tgScnRdr.drawEnt(New), tgScnRdr.drawEntResized(Done), - tgScnRdr .entMesh(New), tgScnRdr .entMeshDirty(Modify_), tgScnRdr .meshResDirty(Modify_), - tgScnRdr.entTexture(New), tgScnRdr.entTextureDirty(Modify_), tgScnRdr.textureResDirty(Modify_), - tgScnRdr .material(New), tgScnRdr .materialDirty(Modify_)}) + .sync_with ({tgPf.spawnedEnts(UseOrRun), scene.plRdr.drawEnt(New), scene.plRdr.drawEntResized(Done), + scene.plRdr .entMesh(New), scene.plRdr .entMeshDirty(Modify_), scene.plRdr .meshResDirty(Modify_), + scene.plRdr.entTexture(New), scene.plRdr.entTextureDirty(Modify_), scene.plRdr.textureResDirty(Modify_), + scene.plRdr .material(New), scene.plRdr .materialDirty(Modify_)}) .push_to (out.m_tasks) - .args ({ idPrefabs, idResources, idBasic, idDrawing, idDrawingRes, idScnRender, idMaterial}) + .args ({ idPrefabs, mainApp.di.resources, commonScene.di.basic, commonScene.di.drawing, commonScene.di.drawingRes, idScnRender, idMaterial}) .func([] (ACtxPrefabs& rPrefabs, Resources& rResources, ACtxBasic const& rBasic, ACtxDrawing& rDrawing, ACtxDrawingRes& rDrawingRes, ACtxSceneRender& rScnRender, MaterialId material) noexcept { SysPrefabDraw::init_mesh_texture_material(rPrefabs, rResources, rBasic, rDrawing, rDrawingRes, rScnRender, material); }); - rBuilder.task() + rFB.task() .name ("Resync spawned shapes DrawEnts") - .run_on ({tgWin.resync(Run)}) - .sync_with ({tgPf.ownedEnts(UseOrRun_), tgCS.hierarchy(Ready), tgCS.activeEntResized(Done), tgScnRdr.drawEntResized(ModifyOrSignal)}) + .run_on ({windowApp.pl.resync(Run)}) + .sync_with ({tgPf.ownedEnts(UseOrRun_), commonScene.pl.hierarchy(Ready), commonScene.pl.activeEntResized(Done), scene.plRdr.drawEntResized(ModifyOrSignal)}) .push_to (out.m_tasks) - .args ({ idPrefabs, idResources, idBasic, idDrawing, idScnRender}) + .args ({ idPrefabs, mainApp.di.resources, commonScene.di.basic, commonScene.di.drawing, idScnRender}) .func([] (ACtxPrefabs& rPrefabs, Resources& rResources, ACtxBasic const& rBasic, ACtxDrawing& rDrawing, ACtxSceneRender& rScnRender) noexcept { SysPrefabDraw::resync_drawents(rPrefabs, rResources, rBasic, rDrawing, rScnRender); }); - rBuilder.task() + rFB.task() .name ("Resync spawned shapes mesh and material") - .run_on ({tgWin.resync(Run)}) - .sync_with ({tgPf.ownedEnts(UseOrRun_), tgScnRdr.entMesh(New), tgScnRdr.material(New), tgScnRdr.drawEnt(New), tgScnRdr.drawEntResized(Done), - tgScnRdr.materialDirty(Modify_), tgScnRdr.entMeshDirty(Modify_)}) + .run_on ({windowApp.pl.resync(Run)}) + .sync_with ({tgPf.ownedEnts(UseOrRun_), scene.plRdr.entMesh(New), scene.plRdr.material(New), scene.plRdr.drawEnt(New), scene.plRdr.drawEntResized(Done), + scene.plRdr.materialDirty(Modify_), scene.plRdr.entMeshDirty(Modify_)}) .push_to (out.m_tasks) - .args ({ idPrefabs, idResources, idBasic, idDrawing, idDrawingRes, idScnRender, idMaterial}) + .args ({ idPrefabs, mainApp.di.resources, commonScene.di.basic, commonScene.di.drawing, commonScene.di.drawingRes, idScnRender, idMaterial}) .func([] (ACtxPrefabs& rPrefabs, Resources& rResources, ACtxBasic const& rBasic, ACtxDrawing& rDrawing, ACtxDrawingRes& rDrawingRes, ACtxSceneRender& rScnRender, MaterialId material) noexcept { SysPrefabDraw::resync_mesh_texture_material(rPrefabs, rResources, rBasic, rDrawing, rDrawingRes, rScnRender, material); @@ -267,5 +267,5 @@ Session setup_prefab_draw( } // setup_phys_shapes_draw -} // namespace testapp::scenes +} // namespace adera #endif diff --git a/src/testapp/sessions/physics.h b/src/adera_app/features/physics.h similarity index 92% rename from src/testapp/sessions/physics.h rename to src/adera_app/features/physics.h index 7a313648..c65c5e21 100644 --- a/src/testapp/sessions/physics.h +++ b/src/adera_app/features/physics.h @@ -35,7 +35,7 @@ #include -namespace testapp::scenes +namespace adera { @@ -45,7 +45,7 @@ namespace testapp::scenes * Independent of whichever physics engine is used */ osp::Session setup_physics( - osp::TopTaskBuilder& rBuilder, + osp::TopTaskBuilder& rFB, osp::ArrayView topData, osp::Session const& scene, osp::Session const& commonScene); @@ -54,7 +54,7 @@ osp::Session setup_physics( * @brief Queues and logic for spawning Prefab resources */ osp::Session setup_prefabs( - osp::TopTaskBuilder& rBuilder, + osp::TopTaskBuilder& rFB, osp::ArrayView topData, osp::Session const& application, osp::Session const& scene, @@ -62,7 +62,7 @@ osp::Session setup_prefabs( osp::Session const& physics); osp::Session setup_prefab_draw( - osp::TopTaskBuilder& rBuilder, + osp::TopTaskBuilder& rFB, osp::ArrayView topData, osp::Session const& application, osp::Session const& windowApp, @@ -71,5 +71,5 @@ osp::Session setup_prefab_draw( osp::Session const& prefabs, osp::draw::MaterialId material); -} // namespace testapp::scenes +} // namespace adera #endif diff --git a/src/testapp/sessions/shapes.cpp b/src/adera_app/features/shapes.cpp similarity index 77% rename from src/testapp/sessions/shapes.cpp rename to src/adera_app/features/shapes.cpp index 925a2e40..427fdbaf 100644 --- a/src/testapp/sessions/shapes.cpp +++ b/src/adera_app/features/shapes.cpp @@ -42,7 +42,7 @@ using namespace osp::draw; using osp::input::EButtonControlIndex; -namespace testapp::scenes +namespace adera { void add_floor( @@ -54,7 +54,7 @@ void add_floor( { OSP_DECLARE_GET_DATA_IDS(physShapes, TESTAPP_DATA_PHYS_SHAPES); - auto &rPhysShapes = top_get(topData, idPhysShapes); + auto &rPhysShapes = rFB.data_get(topData, idPhysShapes); std::mt19937 randGen(69); auto distSizeX = std::uniform_real_distribution{20.0, 80.0}; @@ -82,7 +82,7 @@ void add_floor( Session setup_phys_shapes( - TopTaskBuilder& rBuilder, + TopTaskBuilder& rFB, ArrayView const topData, Session const& scene, Session const& commonScene, @@ -91,24 +91,24 @@ Session setup_phys_shapes( { OSP_DECLARE_GET_DATA_IDS(commonScene, TESTAPP_DATA_COMMON_SCENE); OSP_DECLARE_GET_DATA_IDS(physics, TESTAPP_DATA_PHYSICS); - auto const tgScn = scene .get_pipelines(); - auto const tgCS = commonScene .get_pipelines(); + auto const scene.pl = scene .get_pipelines(); + auto const commonScene.pl = commonScene .get_pipelines(); auto const tgPhy = physics .get_pipelines(); Session out; OSP_DECLARE_CREATE_DATA_IDS(out, topData, TESTAPP_DATA_PHYS_SHAPES); - auto const tgShSp = out.create_pipelines(rBuilder); + auto const tgShSp = out.create_pipelines(rFB); - rBuilder.pipeline(tgShSp.spawnRequest) .parent(tgScn.update); - rBuilder.pipeline(tgShSp.spawnedEnts) .parent(tgScn.update); - rBuilder.pipeline(tgShSp.ownedEnts) .parent(tgScn.update); + rFB.pipeline(tgShSp.spawnRequest) .parent(scene.pl.update); + rFB.pipeline(tgShSp.spawnedEnts) .parent(scene.pl.update); + rFB.pipeline(tgShSp.ownedEnts) .parent(scene.pl.update); - top_emplace< ACtxPhysShapes > (topData, idPhysShapes, ACtxPhysShapes{ .m_materialId = materialId }); + rFB.data_emplace< ACtxPhysShapes > (topData, idPhysShapes, ACtxPhysShapes{ .m_materialId = materialId }); - rBuilder.task() + rFB.task() .name ("Schedule Shape spawn") .schedules ({tgShSp.spawnRequest(Schedule_)}) - .sync_with ({tgScn.update(Run)}) + .sync_with ({scene.pl.update(Run)}) .push_to (out.m_tasks) .args ({ idPhysShapes }) .func([] (ACtxPhysShapes& rPhysShapes) noexcept -> TaskActions @@ -116,12 +116,12 @@ Session setup_phys_shapes( return rPhysShapes.m_spawnRequest.empty() ? TaskAction::Cancel : TaskActions{}; }); - rBuilder.task() + rFB.task() .name ("Create ActiveEnts for requested shapes to spawn") .run_on ({tgShSp.spawnRequest(UseOrRun)}) - .sync_with ({tgCS.activeEnt(New), tgCS.activeEntResized(Schedule), tgShSp.spawnedEnts(Resize)}) + .sync_with ({commonScene.pl.activeEnt(New), commonScene.pl.activeEntResized(Schedule), tgShSp.spawnedEnts(Resize)}) .push_to (out.m_tasks) - .args ({ idBasic, idPhysShapes}) + .args ({ commonScene.di.basic, idPhysShapes}) .func([] (ACtxBasic& rBasic, ACtxPhysShapes& rPhysShapes) noexcept { LGRN_ASSERTM(!rPhysShapes.m_spawnRequest.empty(), "spawnRequest Use_ shouldn't run if rPhysShapes.m_spawnRequest is empty!"); @@ -130,12 +130,12 @@ Session setup_phys_shapes( rBasic.m_activeIds.create(rPhysShapes.m_ents.begin(), rPhysShapes.m_ents.end()); }); - rBuilder.task() + rFB.task() .name ("Add hierarchy and transform to spawned shapes") .run_on ({tgShSp.spawnRequest(UseOrRun)}) - .sync_with ({tgShSp.spawnedEnts(UseOrRun), tgShSp.ownedEnts(Modify__), tgCS.hierarchy(New), tgCS.transform(New)}) + .sync_with ({tgShSp.spawnedEnts(UseOrRun), tgShSp.ownedEnts(Modify__), commonScene.pl.hierarchy(New), commonScene.pl.transform(New)}) .push_to (out.m_tasks) - .args ({ idBasic, idPhysShapes }) + .args ({ commonScene.di.basic, idPhysShapes }) .func([] (ACtxBasic& rBasic, ACtxPhysShapes& rPhysShapes) noexcept { rPhysShapes.ownedEnts.resize(rBasic.m_activeIds.capacity()); @@ -158,12 +158,12 @@ Session setup_phys_shapes( } }); - rBuilder.task() + rFB.task() .name ("Add physics to spawned shapes") .run_on ({tgShSp.spawnRequest(UseOrRun)}) .sync_with ({tgShSp.spawnedEnts(UseOrRun), tgPhy.physBody(Modify), tgPhy.physUpdate(Done)}) .push_to (out.m_tasks) - .args ({ idBasic, idPhysShapes, idPhys }) + .args ({ commonScene.di.basic, idPhysShapes, idPhys }) .func([] (ACtxBasic const& rBasic, ACtxPhysShapes& rPhysShapes, ACtxPhysics& rPhys) noexcept { rPhys.m_hasColliders.resize(rBasic.m_activeIds.capacity()); @@ -190,18 +190,18 @@ Session setup_phys_shapes( }); //TODO - rBuilder.task() + rFB.task() .name ("Delete basic components") - .run_on ({tgCS.activeEntDelete(UseOrRun)}) + .run_on ({commonScene.di.activeEntDel(UseOrRun)}) .sync_with ({tgShSp.ownedEnts(Modify__)}) .push_to (out.m_tasks) - .args ({ idBasic, idActiveEntDel }) + .args ({ commonScene.di.basic, commonScene.di.activeEntDel }) .func([] (ACtxBasic& rBasic, ActiveEntVec_t const& rActiveEntDel) noexcept { update_delete_basic(rBasic, rActiveEntDel.cbegin(), rActiveEntDel.cend()); }); - rBuilder.task() + rFB.task() .name ("Clear Shape Spawning vector after use") .run_on ({tgShSp.spawnRequest(Clear)}) .push_to (out.m_tasks) @@ -219,7 +219,7 @@ Session setup_phys_shapes( Session setup_phys_shapes_draw( - TopTaskBuilder& rBuilder, + TopTaskBuilder& rFB, ArrayView const topData, Session const& windowApp, Session const& sceneRenderer, @@ -231,19 +231,19 @@ Session setup_phys_shapes_draw( OSP_DECLARE_GET_DATA_IDS(commonScene, TESTAPP_DATA_COMMON_SCENE); OSP_DECLARE_GET_DATA_IDS(physics, TESTAPP_DATA_PHYSICS); OSP_DECLARE_GET_DATA_IDS(physShapes, TESTAPP_DATA_PHYS_SHAPES); - auto const tgWin = windowApp .get_pipelines< PlWindowApp >(); - auto const tgScnRdr = sceneRenderer .get_pipelines< PlSceneRenderer >(); - auto const tgCS = commonScene .get_pipelines< PlCommonScene >(); + auto const windowApp.pl = windowApp .get_pipelines< PlWindowApp >(); + auto const scene.plRdr = sceneRenderer .get_pipelines< PlSceneRenderer >(); + auto const commonScene.pl = commonScene .get_pipelines< PlCommonScene >(); auto const tgShSp = physShapes .get_pipelines< PlPhysShapes >(); Session out; - rBuilder.task() + rFB.task() .name ("Create DrawEnts for spawned shapes") .run_on ({tgShSp.spawnRequest(UseOrRun)}) - .sync_with ({tgShSp.spawnedEnts(UseOrRun), tgCS.activeEntResized(Done), tgScnRdr.drawEntResized(ModifyOrSignal), tgScnRdr.drawEnt(New)}) + .sync_with ({tgShSp.spawnedEnts(UseOrRun), commonScene.pl.activeEntResized(Done), scene.plRdr.drawEntResized(ModifyOrSignal), scene.plRdr.drawEnt(New)}) .push_to (out.m_tasks) - .args ({ idBasic, idDrawing, idScnRender, idPhysShapes, idNMesh }) + .args ({ commonScene.di.basic, commonScene.di.drawing, idScnRender, idPhysShapes, commonScene.di.namedMeshes }) .func([] (ACtxBasic const& rBasic, ACtxDrawing& rDrawing, ACtxSceneRender& rScnRender, ACtxPhysShapes& rPhysShapes, NamedMeshes& rNMesh) noexcept { for (std::size_t i = 0; i < rPhysShapes.m_spawnRequest.size(); ++i) @@ -253,14 +253,14 @@ Session setup_phys_shapes_draw( } }); - rBuilder.task() + rFB.task() .name ("Add mesh and material to spawned shapes") .run_on ({tgShSp.spawnRequest(UseOrRun)}) .sync_with ({tgShSp.spawnedEnts(UseOrRun), - tgScnRdr.entMesh(New), tgScnRdr.material(New), tgScnRdr.drawEnt(New), tgScnRdr.drawEntResized(Done), - tgScnRdr.materialDirty(Modify_), tgScnRdr.entMeshDirty(Modify_)}) + scene.plRdr.entMesh(New), scene.plRdr.material(New), scene.plRdr.drawEnt(New), scene.plRdr.drawEntResized(Done), + scene.plRdr.materialDirty(Modify_), scene.plRdr.entMeshDirty(Modify_)}) .push_to (out.m_tasks) - .args ({ idBasic, idDrawing, idScnRender, idPhysShapes, idNMesh }) + .args ({ commonScene.di.basic, commonScene.di.drawing, idScnRender, idPhysShapes, commonScene.di.namedMeshes }) .func([] (ACtxBasic const& rBasic, ACtxDrawing& rDrawing, ACtxSceneRender& rScnRender, ACtxPhysShapes& rPhysShapes, NamedMeshes& rNMesh) noexcept { Material &rMat = rScnRender.m_materials[rPhysShapes.m_materialId]; @@ -288,12 +288,12 @@ Session setup_phys_shapes_draw( // When does resync run relative to deletes? - rBuilder.task() + rFB.task() .name ("Resync spawned shapes DrawEnts") - .run_on ({tgWin.resync(Run)}) - .sync_with ({tgShSp.ownedEnts(UseOrRun_), tgCS.hierarchy(Ready), tgCS.activeEntResized(Done), tgScnRdr.drawEntResized(ModifyOrSignal)}) + .run_on ({windowApp.pl.resync(Run)}) + .sync_with ({tgShSp.ownedEnts(UseOrRun_), commonScene.pl.hierarchy(Ready), commonScene.pl.activeEntResized(Done), scene.plRdr.drawEntResized(ModifyOrSignal)}) .push_to (out.m_tasks) - .args ({ idBasic, idDrawing, idScnRender, idPhysShapes, idNMesh }) + .args ({ commonScene.di.basic, commonScene.di.drawing, idScnRender, idPhysShapes, commonScene.di.namedMeshes }) .func([] (ACtxBasic const& rBasic, ACtxDrawing& rDrawing, ACtxSceneRender& rScnRender, ACtxPhysShapes& rPhysShapes, NamedMeshes& rNMesh) noexcept { for (ActiveEnt root : rPhysShapes.ownedEnts) @@ -304,13 +304,13 @@ Session setup_phys_shapes_draw( } }); - rBuilder.task() + rFB.task() .name ("Resync spawned shapes mesh and material") - .run_on ({tgWin.resync(Run)}) - .sync_with ({tgShSp.ownedEnts(UseOrRun_), tgScnRdr.entMesh(New), tgScnRdr.material(New), tgScnRdr.drawEnt(New), tgScnRdr.drawEntResized(Done), - tgScnRdr.materialDirty(Modify_), tgScnRdr.entMeshDirty(Modify_)}) + .run_on ({windowApp.pl.resync(Run)}) + .sync_with ({tgShSp.ownedEnts(UseOrRun_), scene.plRdr.entMesh(New), scene.plRdr.material(New), scene.plRdr.drawEnt(New), scene.plRdr.drawEntResized(Done), + scene.plRdr.materialDirty(Modify_), scene.plRdr.entMeshDirty(Modify_)}) .push_to (out.m_tasks) - .args ({ idBasic, idDrawing, idPhys, idPhysShapes, idScnRender, idNMesh }) + .args ({ commonScene.di.basic, commonScene.di.drawing, idPhys, idPhysShapes, idScnRender, commonScene.di.namedMeshes }) .func([] (ACtxBasic const& rBasic, ACtxDrawing& rDrawing, ACtxPhysics& rPhys, ACtxPhysShapes& rPhysShapes, ACtxSceneRender& rScnRender, NamedMeshes& rNMesh) noexcept { Material &rMat = rScnRender.m_materials[rPhysShapes.m_materialId]; @@ -337,12 +337,12 @@ Session setup_phys_shapes_draw( } }); - rBuilder.task() + rFB.task() .name ("Remove deleted ActiveEnts from ACtxPhysShapeser") - .run_on ({tgCS.activeEntDelete(UseOrRun)}) + .run_on ({commonScene.di.activeEntDel(UseOrRun)}) .sync_with ({tgShSp.ownedEnts(Modify__)}) .push_to (out.m_tasks) - .args ({ idPhysShapes, idActiveEntDel }) + .args ({ idPhysShapes, commonScene.di.activeEntDel }) .func([] (ACtxPhysShapes& rPhysShapes, ActiveEntVec_t const& rActiveEntDel) noexcept { for (ActiveEnt const deleted : rActiveEntDel) @@ -358,7 +358,7 @@ Session setup_phys_shapes_draw( Session setup_thrower( - TopTaskBuilder& rBuilder, + TopTaskBuilder& rFB, ArrayView const topData, Session const& windowApp, Session const& cameraCtrl, @@ -366,20 +366,20 @@ Session setup_thrower( { OSP_DECLARE_GET_DATA_IDS(physShapes, TESTAPP_DATA_PHYS_SHAPES); OSP_DECLARE_GET_DATA_IDS(cameraCtrl, TESTAPP_DATA_CAMERA_CTRL); - auto &rCamCtrl = top_get< ACtxCameraController > (topData, idCamCtrl); + auto &rCamCtrl = rFB.data_get< ACtxCameraController > (topData, idCamCtrl); - auto const tgWin = windowApp .get_pipelines(); + auto const windowApp.pl = windowApp .get_pipelines(); auto const tgCmCt = cameraCtrl.get_pipelines(); auto const tgShSp = physShapes.get_pipelines(); Session out; auto const [idBtnThrow] = out.acquire_data<1>(topData); - top_emplace< EButtonControlIndex > (topData, idBtnThrow, rCamCtrl.m_controls.button_subscribe("debug_throw")); + rFB.data_emplace< EButtonControlIndex > (topData, idBtnThrow, rCamCtrl.m_controls.button_subscribe("debug_throw")); - rBuilder.task() + rFB.task() .name ("Throw spheres when pressing space") - .run_on ({tgWin.inputs(Run)}) + .run_on ({windowApp.pl.inputs(Run)}) .sync_with ({tgCmCt.camCtrl(Ready), tgShSp.spawnRequest(Modify_)}) .push_to (out.m_tasks) .args ({ idCamCtrl, idPhysShapes, idBtnThrow }) @@ -415,7 +415,7 @@ Session setup_thrower( Session setup_droppers( - TopTaskBuilder& rBuilder, + TopTaskBuilder& rFB, ArrayView const topData, Session const& scene, Session const& commonScene, @@ -425,18 +425,18 @@ Session setup_droppers( 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(); + auto const scene.pl = scene .get_pipelines(); auto const tgShSp = physShapes .get_pipelines(); Session out; auto const [idSpawnTimerA, idSpawnTimerB] = out.acquire_data<2>(topData); - top_emplace< float > (topData, idSpawnTimerA, 0.0f); - top_emplace< float > (topData, idSpawnTimerB, 0.0f); + rFB.data_emplace< float > (topData, idSpawnTimerA, 0.0f); + rFB.data_emplace< float > (topData, idSpawnTimerB, 0.0f); - rBuilder.task() + rFB.task() .name ("Spawn blocks every 2 seconds") - .run_on ({tgScn.update(Run)}) + .run_on ({scene.pl.update(Run)}) .sync_with ({tgShSp.spawnRequest(Modify_)}) .push_to (out.m_tasks) .args({ idPhysShapes, idSpawnTimerA, idDeltaTimeIn }) @@ -458,9 +458,9 @@ Session setup_droppers( } }); - rBuilder.task() + rFB.task() .name ("Spawn cylinders every 1 second") - .run_on ({tgScn.update(Run)}) + .run_on ({scene.pl.update(Run)}) .sync_with ({tgShSp.spawnRequest(Modify_)}) .push_to (out.m_tasks) .args({ idPhysShapes, idSpawnTimerB, idDeltaTimeIn }) @@ -488,7 +488,7 @@ Session setup_droppers( Session setup_bounds( - TopTaskBuilder& rBuilder, + TopTaskBuilder& rFB, ArrayView const topData, Session const& scene, Session const& commonScene, @@ -496,26 +496,26 @@ Session setup_bounds( { 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(); - auto const tgCS = commonScene .get_pipelines(); + auto const scene.pl = scene .get_pipelines(); + auto const commonScene.pl = commonScene .get_pipelines(); auto const tgShSp = physShapes .get_pipelines(); Session out; OSP_DECLARE_CREATE_DATA_IDS(out, topData, TESTAPP_DATA_BOUNDS); - auto const tgBnds = out.create_pipelines(rBuilder); + auto const tgBnds = out.create_pipelines(rFB); - rBuilder.pipeline(tgBnds.boundsSet) .parent(tgScn.update); - rBuilder.pipeline(tgBnds.outOfBounds) .parent(tgScn.update); + rFB.pipeline(tgBnds.boundsSet) .parent(scene.pl.update); + rFB.pipeline(tgBnds.outOfBounds) .parent(scene.pl.update); - top_emplace< ActiveEntSet_t > (topData, idBounds); - top_emplace< ActiveEntVec_t > (topData, idOutOfBounds); + rFB.data_emplace< ActiveEntSet_t > (topData, idBounds); + rFB.data_emplace< ActiveEntVec_t > (topData, idOutOfBounds); - rBuilder.task() + rFB.task() .name ("Check for out-of-bounds entities") - .run_on ({tgScn.update(Run)}) - .sync_with ({tgCS.transform(Ready), tgBnds.boundsSet(Ready), tgBnds.outOfBounds(Modify__)}) + .run_on ({scene.pl.update(Run)}) + .sync_with ({commonScene.pl.transform(Ready), tgBnds.boundsSet(Ready), tgBnds.outOfBounds(Modify__)}) .push_to (out.m_tasks) - .args ({ idBasic, idBounds, idOutOfBounds }) + .args ({ commonScene.di.basic, idBounds, idOutOfBounds }) .func([] (ACtxBasic const& rBasic, ActiveEntSet_t const& rBounds, ActiveEntVec_t& rOutOfBounds) noexcept { for (ActiveEnt const ent : rBounds) @@ -528,18 +528,18 @@ Session setup_bounds( } }); - rBuilder.task() + rFB.task() .name ("Queue-Delete out-of-bounds entities") .run_on ({tgBnds.outOfBounds(UseOrRun_)}) - .sync_with ({tgCS.activeEntDelete(Modify_), tgCS.hierarchy(Delete)}) + .sync_with ({commonScene.di.activeEntDel(Modify_), commonScene.pl.hierarchy(Delete)}) .push_to (out.m_tasks) - .args ({ idBasic, idActiveEntDel, idOutOfBounds }) + .args ({ commonScene.di.basic, commonScene.di.activeEntDel, idOutOfBounds }) .func([] (ACtxBasic& rBasic, ActiveEntVec_t& rActiveEntDel, ActiveEntVec_t& rOutOfBounds) noexcept { SysSceneGraph::queue_delete_entities(rBasic.m_scnGraph, rActiveEntDel, rOutOfBounds.begin(), rOutOfBounds.end()); }); - rBuilder.task() + rFB.task() .name ("Clear out-of-bounds vector once we're done with it") .run_on ({tgBnds.outOfBounds(Clear_)}) .push_to (out.m_tasks) @@ -549,12 +549,12 @@ Session setup_bounds( rOutOfBounds.clear(); }); - rBuilder.task() + rFB.task() .name ("Add bounds to spawned shapes") .run_on ({tgShSp.spawnRequest(UseOrRun)}) .sync_with ({tgShSp.spawnedEnts(UseOrRun), tgBnds.boundsSet(Modify)}) .push_to (out.m_tasks) - .args ({ idBasic, idPhysShapes, idBounds }) + .args ({ commonScene.di.basic, idPhysShapes, idBounds }) .func([] (ACtxBasic& rBasic, ACtxPhysShapes& rPhysShapes, ActiveEntSet_t& rBounds) noexcept { rBounds.resize(rBasic.m_activeIds.capacity()); @@ -573,12 +573,12 @@ Session setup_bounds( } }); - rBuilder.task() + rFB.task() .name ("Delete bounds components") - .run_on ({tgCS.activeEntDelete(UseOrRun)}) + .run_on ({commonScene.di.activeEntDel(UseOrRun)}) .sync_with ({tgBnds.boundsSet(Delete)}) .push_to (out.m_tasks) - .args ({ idActiveEntDel, idBounds }) + .args ({ commonScene.di.activeEntDel, idBounds }) .func([] (ActiveEntVec_t const& rActiveEntDel, ActiveEntSet_t& rBounds) noexcept { for (osp::active::ActiveEnt const ent : rActiveEntDel) @@ -591,5 +591,5 @@ Session setup_bounds( } // setup_bounds -} // namespace testapp::scenes +} // namespace adera #endif diff --git a/src/testapp/sessions/shapes.h b/src/adera_app/features/shapes.h similarity index 93% rename from src/testapp/sessions/shapes.h rename to src/adera_app/features/shapes.h index ec245b85..a9477a27 100644 --- a/src/testapp/sessions/shapes.h +++ b/src/adera_app/features/shapes.h @@ -31,7 +31,7 @@ #include #include -namespace testapp::scenes +namespace adera { struct SpawnShape @@ -64,7 +64,7 @@ void add_floor( * @brief Queues and logic for spawning physics shapes */ osp::Session setup_phys_shapes( - osp::TopTaskBuilder& rBuilder, + osp::TopTaskBuilder& rFB, osp::ArrayView topData, osp::Session const& scene, osp::Session const& commonScene, @@ -72,7 +72,7 @@ osp::Session setup_phys_shapes( osp::draw::MaterialId materialId); osp::Session setup_phys_shapes_draw( - osp::TopTaskBuilder& rBuilder, + osp::TopTaskBuilder& rFB, osp::ArrayView topData, osp::Session const& windowApp, osp::Session const& sceneRenderer, @@ -84,7 +84,7 @@ osp::Session setup_phys_shapes_draw( * @brief Throws spheres when pressing space */ osp::Session setup_thrower( - osp::TopTaskBuilder& rBuilder, + osp::TopTaskBuilder& rFB, osp::ArrayView topData, osp::Session const& windowApp, osp::Session const& cameraCtrl, @@ -94,7 +94,7 @@ osp::Session setup_thrower( * @brief Spawn blocks every 2 seconds and spheres every 1 second */ osp::Session setup_droppers( - osp::TopTaskBuilder& rBuilder, + osp::TopTaskBuilder& rFB, osp::ArrayView topData, osp::Session const& scene, osp::Session const& commonScene, @@ -104,7 +104,7 @@ osp::Session setup_droppers( * @brief Entity set to delete entities under Z = -10, added to spawned shapes */ osp::Session setup_bounds( - osp::TopTaskBuilder& rBuilder, + osp::TopTaskBuilder& rFB, osp::ArrayView topData, osp::Session const& scene, osp::Session const& commonScene, diff --git a/src/testapp/sessions/terrain.cpp b/src/adera_app/features/terrain.cpp similarity index 91% rename from src/testapp/sessions/terrain.cpp rename to src/adera_app/features/terrain.cpp index 140ce418..4886d751 100644 --- a/src/testapp/sessions/terrain.cpp +++ b/src/adera_app/features/terrain.cpp @@ -47,35 +47,35 @@ using namespace osp; using namespace osp::math; using namespace osp::draw; -namespace testapp::scenes +namespace adera { Session setup_terrain( - TopTaskBuilder& rBuilder, + TopTaskBuilder& rFB, ArrayView const topData, Session const &scene, Session const &commonScene) { OSP_DECLARE_GET_DATA_IDS(commonScene, TESTAPP_DATA_COMMON_SCENE); - auto const tgScn = scene.get_pipelines(); + auto const scene.pl = scene.get_pipelines(); - auto &rDrawing = top_get(topData, idDrawing); + auto &rDrawing = rFB.data_get(topData, commonScene.di.drawing); Session out; OSP_DECLARE_CREATE_DATA_IDS(out, topData, TESTAPP_DATA_TERRAIN); - auto const tgTrn = out.create_pipelines(rBuilder); + auto const tgTrn = out.create_pipelines(rFB); - rBuilder.pipeline(tgTrn.skeleton) .parent(tgScn.update); - rBuilder.pipeline(tgTrn.surfaceChanges) .parent(tgScn.update); - rBuilder.pipeline(tgTrn.terrainFrame) .parent(tgScn.update); - rBuilder.pipeline(tgTrn.chunkMesh) .parent(tgScn.update); + rFB.pipeline(tgTrn.skeleton) .parent(scene.pl.update); + rFB.pipeline(tgTrn.surfaceChanges) .parent(scene.pl.update); + rFB.pipeline(tgTrn.terrainFrame) .parent(scene.pl.update); + rFB.pipeline(tgTrn.chunkMesh) .parent(scene.pl.update); - auto &rTerrainFrame = top_emplace< ACtxTerrainFrame >(topData, idTerrainFrame); - auto &rTerrain = top_emplace< ACtxTerrain > (topData, idTerrain); + auto &rTerrainFrame = rFB.data_emplace< ACtxTerrainFrame >(topData, idTerrainFrame); + auto &rTerrain = rFB.data_emplace< ACtxTerrain > (topData, idTerrain); rTerrain.terrainMesh = rDrawing.m_meshRefCounts.ref_add(rDrawing.m_meshIds.create()); - rBuilder.task() + rFB.task() .name ("Clear surfaceAdded & surfaceRemoved once we're done with it") .run_on ({tgTrn.surfaceChanges(Clear)}) .push_to (out.m_tasks) @@ -86,11 +86,11 @@ Session setup_terrain( rTerrain.scratchpad.surfaceRemoved.clear(); }); - rBuilder.task() + rFB.task() .name ("Clean up terrain-related IdOwners") - .run_on ({tgScn.cleanup(Run_)}) + .run_on ({scene.pl.cleanup(Run_)}) .push_to (out.m_tasks) - .args ({ idTerrain, idDrawing}) + .args ({ idTerrain, commonScene.di.drawing}) .func([] (ACtxTerrain &rTerrain, ACtxDrawing &rDrawing) noexcept { // rTerrain.skChunks has owners referring to rTerrain.skeleton. A reference to @@ -107,18 +107,18 @@ Session setup_terrain( } Session setup_terrain_icosahedron( - TopTaskBuilder& rBuilder, + TopTaskBuilder& rFB, ArrayView const topData, Session const &terrain) { Session out; OSP_DECLARE_CREATE_DATA_IDS(out, topData, TESTAPP_DATA_TERRAIN_ICO); - top_emplace< ACtxTerrainIco > (topData, idTerrainIco); + rFB.data_emplace< ACtxTerrainIco > (topData, idTerrainIco); return out; } Session setup_terrain_subdiv_dist( - TopTaskBuilder& rBuilder, + TopTaskBuilder& rFB, ArrayView const topData, Session const &scene, Session const &terrain, @@ -128,13 +128,13 @@ Session setup_terrain_subdiv_dist( OSP_DECLARE_GET_DATA_IDS(terrainIco, TESTAPP_DATA_TERRAIN_ICO); auto const tgTrn = terrain .get_pipelines(); - auto const tgScn = scene .get_pipelines(); + auto const scene.pl = scene .get_pipelines(); Session out; - rBuilder.task() + rFB.task() .name ("Subdivide triangle skeleton") - .run_on ({tgScn.update(Run)}) + .run_on ({scene.pl.update(Run)}) .sync_with ({tgTrn.terrainFrame(Ready), tgTrn.skeleton(New), tgTrn.surfaceChanges(Resize)}) .push_to (out.m_tasks) .args({ idTerrainFrame, idTerrain, idTerrainIco }) @@ -197,9 +197,9 @@ Session setup_terrain_subdiv_dist( //rSkel.debug_check_invariants(); }); - rBuilder.task() + rFB.task() .name ("Update Terrain Chunks") - .run_on ({tgScn.update(Run)}) + .run_on ({scene.pl.update(Run)}) .sync_with ({tgTrn.terrainFrame(Ready), tgTrn.skeleton(Ready), tgTrn.surfaceChanges(UseOrRun), tgTrn.chunkMesh(Modify)}) .push_to (out.m_tasks) .args({ idTerrainFrame, idTerrain, idTerrainIco }) @@ -481,9 +481,9 @@ void initialize_ico_terrain( OSP_DECLARE_GET_DATA_IDS(terrain, TESTAPP_DATA_TERRAIN); OSP_DECLARE_GET_DATA_IDS(terrainIco, TESTAPP_DATA_TERRAIN_ICO); - auto &rTerrain = top_get (topData, idTerrain); - auto &rTerrainFrame = top_get (topData, idTerrainFrame); - auto &rTerrainIco = top_get (topData, idTerrainIco); + auto &rTerrain = rFB.data_get (topData, idTerrain); + auto &rTerrainFrame = rFB.data_get (topData, idTerrainFrame); + auto &rTerrainIco = rFB.data_get (topData, idTerrainIco); rTerrainFrame.active = true; @@ -626,7 +626,7 @@ struct TerrainDebugDraw }; Session setup_terrain_debug_draw( - TopTaskBuilder& rBuilder, + TopTaskBuilder& rFB, ArrayView const topData, Session const &scene, Session const &sceneRenderer, @@ -643,20 +643,20 @@ Session setup_terrain_debug_draw( OSP_DECLARE_GET_DATA_IDS(terrain, TESTAPP_DATA_TERRAIN); OSP_DECLARE_GET_DATA_IDS(terrainIco, TESTAPP_DATA_TERRAIN_ICO); - auto const tgScn = scene .get_pipelines(); - auto const tgScnRdr = sceneRenderer .get_pipelines(); + auto const scene.pl = scene .get_pipelines(); + auto const scene.plRdr = sceneRenderer .get_pipelines(); auto const tgCmCt = cameraCtrl .get_pipelines(); auto const tgTrn = terrain .get_pipelines(); Session out; auto const [idTrnDbgDraw] = out.acquire_data<1>(topData); - auto &rTrnDbgDraw = top_emplace< TerrainDebugDraw > (topData, idTrnDbgDraw, + auto &rTrnDbgDraw = rFB.data_emplace< TerrainDebugDraw > (topData, idTrnDbgDraw, TerrainDebugDraw{.mat = mat}); - auto &rDrawing = top_get< ACtxDrawing > (topData, idDrawing); - auto &rScnRender = top_get< ACtxSceneRender > (topData, idScnRender); - auto &rTerrain = top_get< ACtxTerrain > (topData, idTerrain); + auto &rDrawing = rFB.data_get< ACtxDrawing > (topData, commonScene.di.drawing); + auto &rScnRender = rFB.data_get< ACtxSceneRender > (topData, idScnRender); + auto &rTerrain = rFB.data_get< ACtxTerrain > (topData, idTerrain); rTrnDbgDraw.surface = rScnRender.m_drawIds.create(); rScnRender.resize_draw(); @@ -667,9 +667,9 @@ Session setup_terrain_debug_draw( rScnRender.m_materials[mat].m_dirty.push_back(rTrnDbgDraw.surface); rScnRender.m_mesh[rTrnDbgDraw.surface] = rDrawing.m_meshRefCounts.ref_add(rTerrain.terrainMesh); - rBuilder.task() + rFB.task() .name ("Handle Scene<-->Terrain positioning and floating origin") - .run_on ({tgScn.update(Run)}) + .run_on ({scene.pl.update(Run)}) .sync_with ({tgCmCt.camCtrl(Modify), tgTrn.terrainFrame(Modify)}) .push_to (out.m_tasks) .args ({ idCamCtrl, idDeltaTimeIn, idTerrainFrame, idTerrain, idTerrainIco }) @@ -748,10 +748,10 @@ Session setup_terrain_debug_draw( SysCameraController::update_view(rCamCtrl, deltaTimeIn); }); - rBuilder.task() + rFB.task() .name ("Reposition terrain surface mesh") - .run_on ({tgScnRdr.render(Run)}) - .sync_with ({tgTrn.terrainFrame(Ready), tgTrn.chunkMesh(Ready), tgScnRdr.drawEnt(Ready), tgScnRdr.drawTransforms(Modify_), tgScnRdr.drawEntResized(Done)}) + .run_on ({scene.plRdr.render(Run)}) + .sync_with ({tgTrn.terrainFrame(Ready), tgTrn.chunkMesh(Ready), scene.plRdr.drawEnt(Ready), scene.plRdr.drawTransforms(Modify_), scene.plRdr.drawEntResized(Done)}) .push_to (out.m_tasks) .args ({ idTrnDbgDraw, idTerrainFrame, idTerrain, idScnRender }) .func([] (TerrainDebugDraw& rTrnDbgDraw, ACtxTerrainFrame &rTerrainFrame, ACtxTerrain &rTerrain, ACtxSceneRender &rScnRender) noexcept @@ -766,12 +766,12 @@ Session setup_terrain_debug_draw( #if 0 // Setup skeleton vertex visualizer - rBuilder.task() + rFB.task() .name ("Create or delete DrawEnts for each SkVrtxId in the terrain skeleton") - .run_on ({tgScnRdr.render(Run)}) - .sync_with ({tgTrn.skeleton(Ready), tgScnRdr.drawEnt(Delete), tgScnRdr.entMeshDirty(Modify_), tgScnRdr.materialDirty(Modify_), tgScnRdr.drawEntResized(ModifyOrSignal)}) + .run_on ({scene.plRdr.render(Run)}) + .sync_with ({tgTrn.skeleton(Ready), scene.plRdr.drawEnt(Delete), scene.plRdr.entMeshDirty(Modify_), scene.plRdr.materialDirty(Modify_), scene.plRdr.drawEntResized(ModifyOrSignal)}) .push_to (out.m_tasks) - .args ({ idDrawing, idScnRender, idNMesh, idTrnDbgDraw, idTerrain, idTerrainIco }) + .args ({ commonScene.di.drawing, idScnRender, commonScene.di.namedMeshes, idTrnDbgDraw, idTerrain, idTerrainIco }) .func([] (ACtxDrawing& rDrawing, ACtxSceneRender& rScnRender, NamedMeshes& rNMesh, TerrainDebugDraw& rTrnDbgDraw, ACtxTerrain const &rTerrain, ACtxTerrainIco const &rTerrainIco) noexcept { Material &rMatPlanet = rScnRender.m_materials[rTrnDbgDraw.mat]; @@ -813,16 +813,16 @@ Session setup_terrain_debug_draw( // New DrawEnts may have been created. We can't access rScnRender's members with the new // entities yet, since they have not yet been resized. // - // rScnRender will be resized afterwards by a task with tgScnRdr.drawEntResized(Run), + // rScnRender will be resized afterwards by a task with scene.plRdr.drawEntResized(Run), // before moving on to "Manage DrawEnts for each terrain SkVrtxId" }); - rBuilder.task() + rFB.task() .name ("Arrange SkVrtxId DrawEnts as tiny cubes") - .run_on ({tgScnRdr.render(Run)}) - .sync_with ({tgTrn.skeleton(Ready), tgScnRdr.drawEnt(Ready), tgScnRdr.drawTransforms(Modify_), tgScnRdr.entMeshDirty(Modify_), tgScnRdr.materialDirty(Modify_), tgScnRdr.drawEntResized(Done)}) + .run_on ({scene.plRdr.render(Run)}) + .sync_with ({tgTrn.skeleton(Ready), scene.plRdr.drawEnt(Ready), scene.plRdr.drawTransforms(Modify_), scene.plRdr.entMeshDirty(Modify_), scene.plRdr.materialDirty(Modify_), scene.plRdr.drawEntResized(Done)}) .push_to (out.m_tasks) - .args ({ idDrawing, idScnRender, idNMesh, idTrnDbgDraw, idTerrain, idTerrainIco }) + .args ({ commonScene.di.drawing, idScnRender, commonScene.di.namedMeshes, idTrnDbgDraw, idTerrain, idTerrainIco }) .func([] (ACtxDrawing& rDrawing, ACtxSceneRender& rScnRender, NamedMeshes& rNMesh, TerrainDebugDraw const& rTrnDbgDraw, ACtxTerrain const &rTerrain, ACtxTerrainIco const &rTerrainIco) noexcept { Material &rMatPlanet = rScnRender.m_materials[rTrnDbgDraw.mat]; @@ -854,5 +854,5 @@ Session setup_terrain_debug_draw( } -} // namespace testapp::scenes +} // namespace adera #endif diff --git a/src/testapp/sessions/terrain.h b/src/adera_app/features/terrain.h similarity index 95% rename from src/testapp/sessions/terrain.h rename to src/adera_app/features/terrain.h index 472b817c..f80e720c 100644 --- a/src/testapp/sessions/terrain.h +++ b/src/adera_app/features/terrain.h @@ -35,7 +35,7 @@ #include #include -namespace testapp::scenes +namespace adera { /** @@ -87,7 +87,7 @@ struct ACtxTerrainIco * @brief Skeleton, mesh data, and scratchpads to support a single terrain surface within a scene */ osp::Session setup_terrain( - osp::TopTaskBuilder &rBuilder, + osp::TopTaskBuilder &rFB, osp::ArrayView topData, osp::Session const &scene, osp::Session const &commonScene); @@ -96,7 +96,7 @@ osp::Session setup_terrain( * @brief Icosahedron-specific data for spherical planet terrains */ osp::Session setup_terrain_icosahedron( - osp::TopTaskBuilder& rBuilder, + osp::TopTaskBuilder& rFB, osp::ArrayView topData, osp::Session const &terrain); @@ -104,7 +104,7 @@ osp::Session setup_terrain_icosahedron( * @brief Subdivide-by-distance logic for icosahedron sphere planets */ osp::Session setup_terrain_subdiv_dist( - osp::TopTaskBuilder& rBuilder, + osp::TopTaskBuilder& rFB, osp::ArrayView topData, osp::Session const &scene, osp::Session const &terrain, @@ -145,7 +145,7 @@ void initialize_ico_terrain( * @brief Uses camera target as position relative to planet, and visualizes terrain skeleton. */ osp::Session setup_terrain_debug_draw( - osp::TopTaskBuilder& rBuilder, + osp::TopTaskBuilder& rFB, osp::ArrayView topData, osp::Session const &scene, osp::Session const &sceneRenderer, @@ -155,5 +155,5 @@ osp::Session setup_terrain_debug_draw( osp::Session const &terrainIco, osp::draw::MaterialId mat); -} // namespace testapp::scenes +} // namespace adera #endif diff --git a/src/testapp/sessions/universe.cpp b/src/adera_app/features/universe.cpp similarity index 89% rename from src/testapp/sessions/universe.cpp rename to src/adera_app/features/universe.cpp index d39b5928..e0cb5d2a 100644 --- a/src/testapp/sessions/universe.cpp +++ b/src/adera_app/features/universe.cpp @@ -42,26 +42,26 @@ using namespace osp::draw; using namespace osp::universe; using namespace osp; -namespace testapp::scenes +namespace adera { // Universe Scenario Session setup_uni_core( - TopTaskBuilder& rBuilder, + TopTaskBuilder& rFB, ArrayView topData, PipelineId const updateOn) { Session out; OSP_DECLARE_CREATE_DATA_IDS(out, topData, TESTAPP_DATA_UNI_CORE); - top_emplace< Universe > (topData, idUniverse); + rFB.data_emplace< Universe > (topData, idUniverse); - auto const tgUCore = out.create_pipelines(rBuilder); + auto const tgUCore = out.create_pipelines(rFB); - rBuilder.pipeline(tgUCore.update).parent(updateOn);//.wait_for_signal(EStgOptn::ModifyOrSignal); + rFB.pipeline(tgUCore.update).parent(updateOn);//.wait_for_signal(EStgOptn::ModifyOrSignal); - rBuilder.pipeline(tgUCore.transfer).parent(tgUCore.update); + rFB.pipeline(tgUCore.transfer).parent(tgUCore.update); return out; } // setup_uni_core @@ -70,7 +70,7 @@ Session setup_uni_core( Session setup_uni_sceneframe( - TopTaskBuilder& rBuilder, + TopTaskBuilder& rFB, ArrayView topData, Session const& uniCore) { @@ -79,11 +79,11 @@ Session setup_uni_sceneframe( Session out; OSP_DECLARE_CREATE_DATA_IDS(out, topData, TESTAPP_DATA_UNI_SCENEFRAME); - top_emplace< SceneFrame > (topData, idScnFrame); + rFB.data_emplace< SceneFrame > (topData, idScnFrame); - auto const tgUSFrm = out.create_pipelines(rBuilder); + auto const tgUSFrm = out.create_pipelines(rFB); - rBuilder.pipeline(tgUSFrm.sceneFrame).parent(tgUCore.update); + rFB.pipeline(tgUSFrm.sceneFrame).parent(tgUCore.update); return out; } // setup_uni_sceneframe @@ -92,7 +92,7 @@ Session setup_uni_sceneframe( Session setup_uni_testplanets( - TopTaskBuilder& rBuilder, + TopTaskBuilder& rFB, ArrayView topData, Session const& uniCore, Session const& uniScnFrame) @@ -106,7 +106,7 @@ Session setup_uni_testplanets( auto const tgUCore = uniCore .get_pipelines(); auto const tgUSFrm = uniScnFrame.get_pipelines(); - auto &rUniverse = top_get< Universe >(topData, idUniverse); + auto &rUniverse = rFB.data_get< Universe >(topData, idUniverse); constexpr int precision = 10; constexpr int planetCount = 64; @@ -185,18 +185,18 @@ Session setup_uni_testplanets( // Set initial scene frame - auto &rScnFrame = top_get(topData, idScnFrame); + auto &rScnFrame = rFB.data_get(topData, idScnFrame); rScnFrame.m_parent = mainSpace; rScnFrame.m_position = math::mul_2pow({400, 400, 400}, precision); Session out; OSP_DECLARE_CREATE_DATA_IDS(out, topData, TESTAPP_DATA_UNI_PLANETS); - top_emplace< CoSpaceId > (topData, idPlanetMainSpace, mainSpace); - top_emplace< float > (topData, tgUniDeltaTimeIn, 1.0f / 60.0f); - top_emplace< CoSpaceIdVec_t > (topData, idSatSurfaceSpaces, std::move(satSurfaceSpaces)); + rFB.data_emplace< CoSpaceId > (topData, idPlanetMainSpace, mainSpace); + rFB.data_emplace< float > (topData, tgUniDeltaTimeIn, 1.0f / 60.0f); + rFB.data_emplace< CoSpaceIdVec_t > (topData, idSatSurfaceSpaces, std::move(satSurfaceSpaces)); - rBuilder.task() + rFB.task() .name ("Update planets") .run_on (tgUCore.update(Run)) .sync_with ({tgUSFrm.sceneFrame(Modify)}) @@ -322,7 +322,7 @@ struct PlanetDraw }; Session setup_testplanets_draw( - TopTaskBuilder& rBuilder, + TopTaskBuilder& rFB, ArrayView const topData, Session const& windowApp, Session const& sceneRenderer, @@ -341,8 +341,8 @@ Session setup_testplanets_draw( OSP_DECLARE_GET_DATA_IDS(uniScnFrame, TESTAPP_DATA_UNI_SCENEFRAME); OSP_DECLARE_GET_DATA_IDS(uniTestPlanets, TESTAPP_DATA_UNI_PLANETS); - auto const tgWin = windowApp .get_pipelines(); - auto const tgScnRdr = sceneRenderer .get_pipelines(); + auto const windowApp.pl = windowApp .get_pipelines(); + auto const scene.plRdr = sceneRenderer .get_pipelines(); auto const tgCmCt = cameraCtrl .get_pipelines(); auto const tgUSFrm = uniScnFrame .get_pipelines(); @@ -350,14 +350,14 @@ Session setup_testplanets_draw( auto const [idPlanetDraw] = out.acquire_data<1>(topData); - auto &rPlanetDraw = top_emplace(topData, idPlanetDraw); + auto &rPlanetDraw = rFB.data_emplace(topData, idPlanetDraw); rPlanetDraw.matPlanets = matPlanets; rPlanetDraw.matAxis = matAxis; - rBuilder.task() + rFB.task() .name ("Position SceneFrame center to Camera Controller target") - .run_on ({tgWin.inputs(Run)}) + .run_on ({windowApp.pl.inputs(Run)}) .sync_with ({tgCmCt.camCtrl(Ready), tgUSFrm.sceneFrame(Modify)}) .push_to (out.m_tasks) .args ({ idCamCtrl, idScnFrame }) @@ -388,10 +388,10 @@ Session setup_testplanets_draw( }); - rBuilder.task() + rFB.task() .name ("Resync test planets, create DrawEnts") - .run_on ({tgWin.resync(Run)}) - .sync_with ({tgScnRdr.drawEntResized(ModifyOrSignal)}) + .run_on ({windowApp.pl.resync(Run)}) + .sync_with ({scene.plRdr.drawEntResized(ModifyOrSignal)}) .push_to (out.m_tasks) .args ({ idScnRender, idPlanetDraw, idUniverse, idPlanetMainSpace}) .func([] (ACtxSceneRender& rScnRender, PlanetDraw& rPlanetDraw, Universe& rUniverse, CoSpaceId const planetMainSpace) noexcept @@ -405,12 +405,12 @@ Session setup_testplanets_draw( rPlanetDraw.attractor = rScnRender.m_drawIds.create(); }); - rBuilder.task() + rFB.task() .name ("Resync test planets, add mesh and material") - .run_on ({tgWin.resync(Run)}) - .sync_with ({tgScnRdr.drawEntResized(Done), tgScnRdr.materialDirty(Modify_), tgScnRdr.entMeshDirty(Modify_)}) + .run_on ({windowApp.pl.resync(Run)}) + .sync_with ({scene.plRdr.drawEntResized(Done), scene.plRdr.materialDirty(Modify_), scene.plRdr.entMeshDirty(Modify_)}) .push_to (out.m_tasks) - .args ({ idDrawing, idScnRender, idNMesh, idPlanetDraw, idUniverse, idPlanetMainSpace}) + .args ({ commonScene.di.drawing, idScnRender, commonScene.di.namedMeshes, idPlanetDraw, idUniverse, idPlanetMainSpace}) .func([] (ACtxDrawing& rDrawing, ACtxSceneRender& rScnRender, NamedMeshes& rNMesh, PlanetDraw& rPlanetDraw, Universe& rUniverse, CoSpaceId const planetMainSpace) noexcept { CoSpaceCommon &rMainSpace = rUniverse.m_coordCommon[planetMainSpace]; @@ -455,12 +455,12 @@ Session setup_testplanets_draw( rScnRender.m_color[rPlanetDraw.axis[2]] = {0.0f, 0.0f, 1.0f, 1.0f}; }); - rBuilder.task() + rFB.task() .name ("Reposition test planet DrawEnts") - .run_on ({tgScnRdr.render(Run)}) - .sync_with ({tgScnRdr.drawTransforms(Modify_), tgScnRdr.drawEntResized(Done), tgCmCt.camCtrl(Ready), tgUSFrm.sceneFrame(Modify)}) + .run_on ({scene.plRdr.render(Run)}) + .sync_with ({scene.plRdr.drawTransforms(Modify_), scene.plRdr.drawEntResized(Done), tgCmCt.camCtrl(Ready), tgUSFrm.sceneFrame(Modify)}) .push_to (out.m_tasks) - .args ({ idDrawing, idScnRender, idPlanetDraw, idUniverse, idScnFrame, idPlanetMainSpace}) + .args ({ commonScene.di.drawing, idScnRender, idPlanetDraw, idUniverse, idScnFrame, idPlanetMainSpace}) .func([] (ACtxDrawing& rDrawing, ACtxSceneRender& rScnRender, PlanetDraw& rPlanetDraw, Universe& rUniverse, SceneFrame const& rScnFrame, CoSpaceId const planetMainSpace) noexcept { @@ -540,7 +540,7 @@ Session setup_testplanets_draw( constexpr unsigned int c_planetCount = 5; Session setup_solar_system_testplanets( - TopTaskBuilder& rBuilder, + TopTaskBuilder& rFB, ArrayView topData, Session const& solarSystemCore, Session const& solarSystemScnFrame) @@ -554,7 +554,7 @@ Session setup_solar_system_testplanets( auto const tgUCore = solarSystemCore.get_pipelines(); auto const tgUSFrm = solarSystemScnFrame.get_pipelines(); - auto& rUniverse = top_get< Universe >(topData, idUniverse); + auto& rUniverse = rFB.data_get< Universe >(topData, idUniverse); constexpr int precision = 10; @@ -572,7 +572,7 @@ Session setup_solar_system_testplanets( Session out; OSP_DECLARE_CREATE_DATA_IDS(out, topData, TESTAPP_DATA_SOLAR_SYSTEM_PLANETS); - auto& rCoordNBody = top_emplace< osp::KeyedVec >(topData, idCoordNBody); + auto& rCoordNBody = rFB.data_emplace< osp::KeyedVec >(topData, idCoordNBody); rCoordNBody.resize(rUniverse.m_coordIds.capacity()); // Associate each planet satellite with their surface coordinate space @@ -693,17 +693,17 @@ Session setup_solar_system_testplanets( 550.0f, { 1.0f, 0.5f, 0.0f }); - top_emplace< CoSpaceId >(topData, idPlanetMainSpace, mainSpace); - top_emplace< float >(topData, tgUniDeltaTimeIn, 1.0f / 60.0f); - top_emplace< CoSpaceIdVec_t >(topData, idSatSurfaceSpaces, std::move(satSurfaceSpaces)); + rFB.data_emplace< CoSpaceId >(topData, idPlanetMainSpace, mainSpace); + rFB.data_emplace< float >(topData, tgUniDeltaTimeIn, 1.0f / 60.0f); + rFB.data_emplace< CoSpaceIdVec_t >(topData, idSatSurfaceSpaces, std::move(satSurfaceSpaces)); // Set initial scene frame - auto& rScnFrame = top_get(topData, idScnFrame); + auto& rScnFrame = rFB.data_get(topData, idScnFrame); rScnFrame.m_parent = mainSpace; rScnFrame.m_position = math::mul_2pow({ 400, 400, 400 }, precision); - rBuilder.task() + rFB.task() .name("Update planets") .run_on(tgUCore.update(Run)) .sync_with({ tgUSFrm.sceneFrame(Modify) }) @@ -755,7 +755,7 @@ Session setup_solar_system_testplanets( Session setup_solar_system_planets_draw( - TopTaskBuilder& rBuilder, + TopTaskBuilder& rFB, ArrayView const topData, Session const& windowApp, Session const& sceneRenderer, @@ -773,8 +773,8 @@ Session setup_solar_system_planets_draw( OSP_DECLARE_GET_DATA_IDS(solarSystemScnFrame, TESTAPP_DATA_UNI_SCENEFRAME); OSP_DECLARE_GET_DATA_IDS(solarSystemTestPlanets, TESTAPP_DATA_SOLAR_SYSTEM_PLANETS); - auto const tgWin = windowApp.get_pipelines(); - auto const tgScnRdr = sceneRenderer.get_pipelines(); + auto const windowApp.pl = windowApp.get_pipelines(); + auto const scene.plRdr = sceneRenderer.get_pipelines(); auto const tgCmCt = cameraCtrl.get_pipelines(); auto const tgUSFrm = solarSystemScnFrame.get_pipelines(); @@ -782,13 +782,13 @@ Session setup_solar_system_planets_draw( auto const [idPlanetDraw] = out.acquire_data<1>(topData); - auto& rPlanetDraw = top_emplace(topData, idPlanetDraw); + auto& rPlanetDraw = rFB.data_emplace(topData, idPlanetDraw); rPlanetDraw.matPlanets = matPlanets; - rBuilder.task() + rFB.task() .name("Position SceneFrame center to Camera Controller target") - .run_on({ tgWin.inputs(Run) }) + .run_on({ windowApp.pl.inputs(Run) }) .sync_with({ tgCmCt.camCtrl(Ready), tgUSFrm.sceneFrame(Modify) }) .push_to(out.m_tasks) .args({ idCamCtrl, idScnFrame }) @@ -818,10 +818,10 @@ Session setup_solar_system_planets_draw( rScnFrame.m_scenePosition = Vector3g(math::mul_2pow(rCamCtrl.m_target.value(), rScnFrame.m_precision)); }); - rBuilder.task() + rFB.task() .name("Resync test planets, create DrawEnts") - .run_on({ tgWin.resync(Run) }) - .sync_with({ tgScnRdr.drawEntResized(ModifyOrSignal) }) + .run_on({ windowApp.pl.resync(Run) }) + .sync_with({ scene.plRdr.drawEntResized(ModifyOrSignal) }) .push_to(out.m_tasks) .args({ idScnRender, idPlanetDraw, idUniverse, idPlanetMainSpace }) .func([](ACtxSceneRender& rScnRender, PlanetDraw& rPlanetDraw, Universe& rUniverse, CoSpaceId const planetMainSpace) noexcept @@ -832,12 +832,12 @@ Session setup_solar_system_planets_draw( rScnRender.m_drawIds.create(rPlanetDraw.drawEnts.begin(), rPlanetDraw.drawEnts.end()); }); - rBuilder.task() + rFB.task() .name("Resync test planets, add mesh and material") - .run_on({ tgWin.resync(Run) }) - .sync_with({ tgScnRdr.drawEntResized(Done), tgScnRdr.materialDirty(Modify_), tgScnRdr.entMeshDirty(Modify_) }) + .run_on({ windowApp.pl.resync(Run) }) + .sync_with({ scene.plRdr.drawEntResized(Done), scene.plRdr.materialDirty(Modify_), scene.plRdr.entMeshDirty(Modify_) }) .push_to(out.m_tasks) - .args({ idDrawing, idScnRender, idNMesh, idPlanetDraw, idUniverse, idPlanetMainSpace, idCoordNBody }) + .args({ commonScene.di.drawing, idScnRender, commonScene.di.namedMeshes, idPlanetDraw, idUniverse, idPlanetMainSpace, idCoordNBody }) .func([](ACtxDrawing& rDrawing, ACtxSceneRender& rScnRender, NamedMeshes& rNMesh, PlanetDraw& rPlanetDraw, Universe& rUniverse, CoSpaceId const planetMainSpace, osp::KeyedVec& rCoordNBody) noexcept { CoSpaceCommon& rMainSpace = rUniverse.m_coordCommon[planetMainSpace]; @@ -864,12 +864,12 @@ Session setup_solar_system_planets_draw( } }); - rBuilder.task() + rFB.task() .name("Reposition test planet DrawEnts") - .run_on({ tgScnRdr.render(Run) }) - .sync_with({ tgScnRdr.drawTransforms(Modify_), tgScnRdr.drawEntResized(Done), tgCmCt.camCtrl(Ready), tgUSFrm.sceneFrame(Modify) }) + .run_on({ scene.plRdr.render(Run) }) + .sync_with({ scene.plRdr.drawTransforms(Modify_), scene.plRdr.drawEntResized(Done), tgCmCt.camCtrl(Ready), tgUSFrm.sceneFrame(Modify) }) .push_to(out.m_tasks) - .args({ idDrawing, idScnRender, idPlanetDraw, idUniverse, idScnFrame, idPlanetMainSpace, idCoordNBody }) + .args({ commonScene.di.drawing, idScnRender, idPlanetDraw, idUniverse, idScnFrame, idPlanetMainSpace, idCoordNBody }) .func([](ACtxDrawing& rDrawing, ACtxSceneRender& rScnRender, PlanetDraw& rPlanetDraw, Universe& rUniverse, SceneFrame const& rScnFrame, CoSpaceId const planetMainSpace, osp::KeyedVec& rCoordNBody) noexcept { CoSpaceCommon& rMainSpace = rUniverse.m_coordCommon[planetMainSpace]; @@ -925,5 +925,5 @@ Session setup_solar_system_planets_draw( } // setup_solar_system_planets_draw -} // namespace testapp::scenes +} // namespace adera #endif diff --git a/src/testapp/sessions/universe.h b/src/adera_app/features/universe.h similarity index 92% rename from src/testapp/sessions/universe.h rename to src/adera_app/features/universe.h index 3520a9c8..bf64e75e 100644 --- a/src/testapp/sessions/universe.h +++ b/src/adera_app/features/universe.h @@ -30,7 +30,7 @@ #include "osp/universe/universe.h" #include -namespace testapp::scenes +namespace adera { // Universe Scenario @@ -39,7 +39,7 @@ namespace testapp::scenes * @brief Core Universe struct with addressable Coordinate Spaces */ osp::Session setup_uni_core( - osp::TopTaskBuilder& rBuilder, + osp::TopTaskBuilder& rFB, osp::ArrayView topData, osp::PipelineId updateOn); @@ -47,7 +47,7 @@ osp::Session setup_uni_core( * @brief Represents the physics scene's presence in a Universe */ osp::Session setup_uni_sceneframe( - osp::TopTaskBuilder& rBuilder, + osp::TopTaskBuilder& rFB, osp::ArrayView topData, osp::Session const& uniCore); @@ -55,7 +55,7 @@ osp::Session setup_uni_sceneframe( * @brief Unrealistic planets test, allows SceneFrame to move around and get captured into planets */ osp::Session setup_uni_testplanets( - osp::TopTaskBuilder& rBuilder, + osp::TopTaskBuilder& rFB, osp::ArrayView topData, osp::Session const& uniCore, osp::Session const& uniScnFrame); @@ -65,7 +65,7 @@ osp::Session setup_uni_testplanets( * @brief Draw universe, specifically designed for setup_uni_test_planets */ osp::Session setup_testplanets_draw( - osp::TopTaskBuilder& rBuilder, + osp::TopTaskBuilder& rFB, osp::ArrayView topData, osp::Session const& windowApp, osp::Session const& sceneRenderer, @@ -90,7 +90,7 @@ struct CoSpaceNBody * @brief Initializes planet information, position, mass etc... */ osp::Session setup_solar_system_testplanets( - osp::TopTaskBuilder& rBuilder, + osp::TopTaskBuilder& rFB, osp::ArrayView topData, osp::Session const& solarSystemCore, osp::Session const& solarSystemScnFrame); @@ -100,7 +100,7 @@ osp::Session setup_solar_system_testplanets( * @brief Draw Solar System, specifically designed for setup_solar_system_test_planets */ osp::Session setup_solar_system_planets_draw( - osp::TopTaskBuilder& rBuilder, + osp::TopTaskBuilder& rFB, osp::ArrayView topData, osp::Session const& windowApp, osp::Session const& sceneRenderer, diff --git a/src/testapp/sessions/vehicles.cpp b/src/adera_app/features/vehicles.cpp similarity index 85% rename from src/testapp/sessions/vehicles.cpp rename to src/adera_app/features/vehicles.cpp index 71985712..31aea9d8 100644 --- a/src/testapp/sessions/vehicles.cpp +++ b/src/adera_app/features/vehicles.cpp @@ -47,43 +47,43 @@ using osp::restypes::gc_importer; using namespace Magnum::Math::Literals; -namespace testapp::scenes +namespace adera { Session setup_parts( - TopTaskBuilder& rBuilder, + TopTaskBuilder& rFB, ArrayView const topData, Session const& application, Session const& scene) { OSP_DECLARE_GET_DATA_IDS(application, TESTAPP_DATA_APPLICATION); - auto const tgScn = scene.get_pipelines(); + auto const scene.pl = scene.get_pipelines(); Session out; OSP_DECLARE_CREATE_DATA_IDS(out, topData, TESTAPP_DATA_PARTS); - auto const tgParts = out.create_pipelines(rBuilder); - - out.m_cleanup = tgScn.cleanup; - - rBuilder.pipeline(tgParts.partIds) .parent(tgScn.update); - rBuilder.pipeline(tgParts.partPrefabs) .parent(tgScn.update); - rBuilder.pipeline(tgParts.partTransformWeld).parent(tgScn.update); - rBuilder.pipeline(tgParts.partDirty) .parent(tgScn.update); - rBuilder.pipeline(tgParts.weldIds) .parent(tgScn.update); - rBuilder.pipeline(tgParts.weldDirty) .parent(tgScn.update); - rBuilder.pipeline(tgParts.machIds) .parent(tgScn.update); - rBuilder.pipeline(tgParts.nodeIds) .parent(tgScn.update); - rBuilder.pipeline(tgParts.connect) .parent(tgScn.update); - rBuilder.pipeline(tgParts.mapWeldPart) .parent(tgScn.update); - rBuilder.pipeline(tgParts.mapPartMach) .parent(tgScn.update); - rBuilder.pipeline(tgParts.mapPartActive) .parent(tgScn.update); - rBuilder.pipeline(tgParts.mapWeldActive) .parent(tgScn.update); - rBuilder.pipeline(tgParts.machUpdExtIn) .parent(tgScn.update); - rBuilder.pipeline(tgParts.linkLoop) .parent(tgScn.update).loops(true); - - auto &rScnParts = top_emplace< ACtxParts > (topData, idScnParts); - auto &rUpdMach = top_emplace< MachineUpdater > (topData, idUpdMach); + auto const tgParts = out.create_pipelines(rFB); + + out.m_cleanup = scene.pl.cleanup; + + rFB.pipeline(tgParts.partIds) .parent(scene.pl.update); + rFB.pipeline(tgParts.partPrefabs) .parent(scene.pl.update); + rFB.pipeline(tgParts.partTransformWeld).parent(scene.pl.update); + rFB.pipeline(tgParts.partDirty) .parent(scene.pl.update); + rFB.pipeline(tgParts.weldIds) .parent(scene.pl.update); + rFB.pipeline(tgParts.weldDirty) .parent(scene.pl.update); + rFB.pipeline(tgParts.machIds) .parent(scene.pl.update); + rFB.pipeline(tgParts.nodeIds) .parent(scene.pl.update); + rFB.pipeline(tgParts.connect) .parent(scene.pl.update); + rFB.pipeline(tgParts.mapWeldPart) .parent(scene.pl.update); + rFB.pipeline(tgParts.mapPartMach) .parent(scene.pl.update); + rFB.pipeline(tgParts.mapPartActive) .parent(scene.pl.update); + rFB.pipeline(tgParts.mapWeldActive) .parent(scene.pl.update); + rFB.pipeline(tgParts.machUpdExtIn) .parent(scene.pl.update); + rFB.pipeline(tgParts.linkLoop) .parent(scene.pl.update).loops(true); + + auto &rScnParts = rFB.data_emplace< ACtxParts > (topData, idScnParts); + auto &rUpdMach = rFB.data_emplace< MachineUpdater > (topData, idUpdMach); // Resize containers to fit all existing MachTypeIds and NodeTypeIds // These Global IDs are dynamically initialized just as the program starts @@ -92,11 +92,11 @@ Session setup_parts( rScnParts.machines.perType.resize(MachTypeReg_t::size()); rScnParts.nodePerType .resize(NodeTypeReg_t::size()); - rBuilder.task() + rFB.task() .name ("Clear Resource owners") - .run_on ({tgScn.cleanup(Run_)}) + .run_on ({scene.pl.cleanup(Run_)}) .push_to (out.m_tasks) - .args ({ idScnParts, idResources}) + .args ({ idScnParts, mainApp.di.resources}) .func([] (ACtxParts& rScnParts, Resources& rResources) noexcept { for (osp::PrefabPair &rPrefabPair : rScnParts.partPrefabs) @@ -105,7 +105,7 @@ Session setup_parts( } }); - rBuilder.task() + rFB.task() .name ("Clear Part dirty vectors after use") .run_on ({tgParts.partDirty(Clear)}) .push_to (out.m_tasks) @@ -115,7 +115,7 @@ Session setup_parts( rScnParts.partDirty.clear(); }); - rBuilder.task() + rFB.task() .name ("Clear Weld dirty vectors after use") .run_on ({tgParts.weldDirty(Clear)}) .push_to (out.m_tasks) @@ -125,10 +125,10 @@ Session setup_parts( rScnParts.weldDirty.clear(); }); - rBuilder.task() + rFB.task() .name ("Schedule Link update") .schedules ({tgParts.linkLoop(ScheduleLink)}) - .sync_with ({tgScn.update(Run)}) + .sync_with ({scene.pl.update(Run)}) .push_to (out.m_tasks) .args ({ idUpdMach}) .func([] (MachineUpdater& rUpdMach) noexcept -> TaskActions @@ -148,28 +148,28 @@ Session setup_parts( } // setup_parts Session setup_vehicle_spawn( - TopTaskBuilder& rBuilder, + TopTaskBuilder& rFB, ArrayView const topData, Session const& scene) { - auto const tgScn = scene.get_pipelines(); + auto const scene.pl = scene.get_pipelines(); Session out; OSP_DECLARE_CREATE_DATA_IDS(out, topData, TESTAPP_DATA_VEHICLE_SPAWN); - auto const tgVhSp = out.create_pipelines(rBuilder); + auto const tgVhSp = out.create_pipelines(rFB); - rBuilder.pipeline(tgVhSp.spawnRequest) .parent(tgScn.update); - rBuilder.pipeline(tgVhSp.spawnedParts) .parent(tgScn.update); - rBuilder.pipeline(tgVhSp.spawnedWelds) .parent(tgScn.update); - rBuilder.pipeline(tgVhSp.rootEnts) .parent(tgScn.update); - rBuilder.pipeline(tgVhSp.spawnedMachs) .parent(tgScn.update); + rFB.pipeline(tgVhSp.spawnRequest) .parent(scene.pl.update); + rFB.pipeline(tgVhSp.spawnedParts) .parent(scene.pl.update); + rFB.pipeline(tgVhSp.spawnedWelds) .parent(scene.pl.update); + rFB.pipeline(tgVhSp.rootEnts) .parent(scene.pl.update); + rFB.pipeline(tgVhSp.spawnedMachs) .parent(scene.pl.update); - top_emplace< ACtxVehicleSpawn > (topData, idVehicleSpawn); + rFB.data_emplace< ACtxVehicleSpawn > (topData, idVehicleSpawn); - rBuilder.task() + rFB.task() .name ("Schedule Vehicle spawn") .schedules ({tgVhSp.spawnRequest(Schedule_)}) - .sync_with ({tgScn.update(Run)}) + .sync_with ({scene.pl.update(Run)}) .push_to (out.m_tasks) .args ({ idVehicleSpawn }) .func([] (ACtxVehicleSpawn const& rVehicleSpawn) noexcept -> TaskActions @@ -177,7 +177,7 @@ Session setup_vehicle_spawn( return rVehicleSpawn.spawnRequest.empty() ? TaskAction::Cancel : TaskActions{}; }); - rBuilder.task() + rFB.task() .name ("Clear Vehicle Spawning vector after use") .run_on ({tgVhSp.spawnRequest(Clear)}) .push_to (out.m_tasks) @@ -191,7 +191,7 @@ Session setup_vehicle_spawn( } // setup_vehicle_spawn Session setup_vehicle_spawn_vb( - TopTaskBuilder& rBuilder, + TopTaskBuilder& rFB, ArrayView const topData, Session const& application, Session const& scene, @@ -208,24 +208,24 @@ Session setup_vehicle_spawn_vb( OSP_DECLARE_GET_DATA_IDS(signalsFloat, TESTAPP_DATA_SIGNALS_FLOAT); OSP_DECLARE_GET_DATA_IDS(vehicleSpawn, TESTAPP_DATA_VEHICLE_SPAWN); auto const tgPf = prefabs .get_pipelines(); - auto const tgScn = scene .get_pipelines(); + auto const scene.pl = scene .get_pipelines(); auto const tgParts = parts .get_pipelines(); auto const tgSgFlt = signalsFloat .get_pipelines(); auto const tgVhSp = vehicleSpawn .get_pipelines(); Session out; OSP_DECLARE_CREATE_DATA_IDS(out, topData, TESTAPP_DATA_VEHICLE_SPAWN_VB); - auto const tgVhSpVB = out.create_pipelines(rBuilder); + auto const tgVhSpVB = out.create_pipelines(rFB); - rBuilder.pipeline(tgVhSpVB.dataVB) .parent(tgScn.update); - rBuilder.pipeline(tgVhSpVB.remapParts) .parent(tgScn.update); - rBuilder.pipeline(tgVhSpVB.remapWelds) .parent(tgScn.update); - rBuilder.pipeline(tgVhSpVB.remapMachs) .parent(tgScn.update); - rBuilder.pipeline(tgVhSpVB.remapNodes) .parent(tgScn.update); + rFB.pipeline(tgVhSpVB.dataVB) .parent(scene.pl.update); + rFB.pipeline(tgVhSpVB.remapParts) .parent(scene.pl.update); + rFB.pipeline(tgVhSpVB.remapWelds) .parent(scene.pl.update); + rFB.pipeline(tgVhSpVB.remapMachs) .parent(scene.pl.update); + rFB.pipeline(tgVhSpVB.remapNodes) .parent(scene.pl.update); - top_emplace< ACtxVehicleSpawnVB >(topData, idVehicleSpawnVB); + rFB.data_emplace< ACtxVehicleSpawnVB >(topData, idVehicleSpawnVB); - rBuilder.task() + rFB.task() .name ("Create PartIds and WeldIds for vehicles to spawn from VehicleData") .run_on ({tgVhSp.spawnRequest(UseOrRun)}) .sync_with ({tgVhSp.spawnedParts(Resize), tgVhSpVB.remapParts(Modify_), tgVhSpVB.remapWelds(Modify_), tgParts.partIds(New), tgParts.weldIds(New), tgParts.mapWeldActive(New)}) @@ -236,18 +236,18 @@ Session setup_vehicle_spawn_vb( SysVehicleSpawnVB::create_parts_and_welds(rVehicleSpawn, rVehicleSpawnVB, rScnParts); }); - rBuilder.task() + rFB.task() .name ("Request prefabs for vehicle parts from VehicleBuilder") .run_on ({tgVhSp.spawnRequest(UseOrRun)}) .sync_with ({tgPf.spawnRequest(Modify_), tgVhSp.spawnedParts(UseOrRun)}) .push_to (out.m_tasks) - .args ({ idVehicleSpawn, idVehicleSpawnVB, idScnParts, idPrefabs, idResources}) + .args ({ idVehicleSpawn, idVehicleSpawnVB, idScnParts, idPrefabs, mainApp.di.resources}) .func([] (ACtxVehicleSpawn& rVehicleSpawn, ACtxVehicleSpawnVB const& rVehicleSpawnVB, ACtxParts& rScnParts, ACtxPrefabs& rPrefabs, Resources& rResources) noexcept { SysVehicleSpawnVB::request_prefabs(rVehicleSpawn, rVehicleSpawnVB, rScnParts, rPrefabs, rResources); }); - rBuilder.task() + rFB.task() .name ("Create Machine IDs copied from VehicleData") .run_on ({tgVhSp.spawnRequest(UseOrRun)}) .sync_with ({tgVhSpVB.dataVB(UseOrRun), tgVhSpVB.remapMachs(Modify_), tgVhSp.spawnedMachs(Resize), tgParts.machIds(New)}) @@ -341,12 +341,12 @@ Session setup_vehicle_spawn_vb( } }); - rBuilder.task() + rFB.task() .name ("Update Part<->Machine maps") .run_on ({tgVhSp.spawnRequest(UseOrRun)}) .sync_with ({tgVhSpVB.dataVB(UseOrRun), tgVhSpVB.remapMachs(UseOrRun), tgVhSpVB.remapParts(UseOrRun), tgParts.mapPartMach(New)}) .push_to (out.m_tasks) - .args ({ idVehicleSpawn, idVehicleSpawnVB, idScnParts, idPrefabs, idResources}) + .args ({ idVehicleSpawn, idVehicleSpawnVB, idScnParts, idPrefabs, mainApp.di.resources}) .func([] (ACtxVehicleSpawn& rVehicleSpawn, ACtxVehicleSpawnVB const& rVehicleSpawnVB, ACtxParts& rScnParts, ACtxPrefabs& rPrefabs, Resources& rResources) noexcept { std::size_t const newVehicleCount = rVehicleSpawn.new_vehicle_count(); @@ -402,7 +402,7 @@ Session setup_vehicle_spawn_vb( } }); - rBuilder.task() + rFB.task() .name ("Create (and connect) Node IDs copied from VehicleBuilder") .run_on ({tgVhSp.spawnRequest(UseOrRun)}) .sync_with ({tgVhSpVB.dataVB(UseOrRun), tgVhSpVB.remapMachs(UseOrRun), tgVhSpVB.remapNodes(Modify_), tgParts.nodeIds(New), tgParts.connect(New)}) @@ -457,12 +457,12 @@ Session setup_vehicle_spawn_vb( } }); - rBuilder.task() + rFB.task() .name ("Update PartId<->ActiveEnt mapping") .run_on ({tgVhSp.spawnRequest(UseOrRun)}) .sync_with ({tgVhSp.spawnedParts(UseOrRun), tgPf.spawnedEnts(UseOrRun), tgParts.mapPartActive(Modify)}) .push_to (out.m_tasks) - .args ({ idVehicleSpawn, idBasic, idScnParts, idPrefabs}) + .args ({ idVehicleSpawn, commonScene.di.basic, idScnParts, idPrefabs}) .func([] (ACtxVehicleSpawn& rVehicleSpawn, ACtxBasic const& rBasic, ACtxParts& rScnParts, ACtxPrefabs& rPrefabs) noexcept { rScnParts.partToActive.resize(rScnParts.partIds.capacity()); @@ -482,7 +482,7 @@ Session setup_vehicle_spawn_vb( } }); - rBuilder.task() + rFB.task() .name ("Copy float signal values from VehicleBuilder") .run_on ({tgVhSp.spawnRequest(UseOrRun)}) .sync_with ({tgVhSp.spawnedParts(UseOrRun), tgVhSpVB.remapNodes(UseOrRun), tgSgFlt.sigFloatValues(New), tgSgFlt.sigFloatUpdExtIn(New)}) @@ -526,22 +526,22 @@ Session setup_vehicle_spawn_vb( } // setup_vehicle_spawn_vb Session setup_vehicle_spawn_draw( - TopTaskBuilder& rBuilder, + TopTaskBuilder& rFB, ArrayView const topData, Session const& sceneRenderer, Session const& vehicleSpawn) { OSP_DECLARE_GET_DATA_IDS(sceneRenderer, TESTAPP_DATA_SCENE_RENDERER); OSP_DECLARE_GET_DATA_IDS(vehicleSpawn, TESTAPP_DATA_VEHICLE_SPAWN); - auto const tgScnRdr = sceneRenderer .get_pipelines< PlSceneRenderer >(); + auto const scene.plRdr = sceneRenderer .get_pipelines< PlSceneRenderer >(); auto const tgVhSp = vehicleSpawn .get_pipelines< PlVehicleSpawn >(); Session out; - rBuilder.task() + rFB.task() .name ("Enable Draw Transforms for spawned vehicle root entities") .run_on ({tgVhSp.spawnRequest(UseOrRun)}) - .sync_with ({tgVhSp.rootEnts(UseOrRun), tgScnRdr.drawEntResized(Done)}) + .sync_with ({tgVhSp.rootEnts(UseOrRun), scene.plRdr.drawEntResized(Done)}) .push_to (out.m_tasks) .args ({ idScnRender, idVehicleSpawn}) .func([] (ACtxSceneRender& rScnRender, ACtxVehicleSpawn const& rVehicleSpawn) noexcept @@ -557,30 +557,30 @@ Session setup_vehicle_spawn_draw( Session setup_signals_float( - TopTaskBuilder& rBuilder, + TopTaskBuilder& rFB, ArrayView const topData, Session const& scene, Session const& parts) { OSP_DECLARE_GET_DATA_IDS(parts, TESTAPP_DATA_PARTS); - auto const tgScn = scene.get_pipelines(); + auto const scene.pl = scene.get_pipelines(); auto const tgParts = parts.get_pipelines(); Session out; OSP_DECLARE_CREATE_DATA_IDS(out, topData, TESTAPP_DATA_SIGNALS_FLOAT); - auto const tgSgFlt = out.create_pipelines(rBuilder); + auto const tgSgFlt = out.create_pipelines(rFB); - rBuilder.pipeline(tgSgFlt.sigFloatValues) .parent(tgScn.update); - rBuilder.pipeline(tgSgFlt.sigFloatUpdExtIn) .parent(tgScn.update); - rBuilder.pipeline(tgSgFlt.sigFloatUpdLoop) .parent(tgParts.linkLoop); + rFB.pipeline(tgSgFlt.sigFloatValues) .parent(scene.pl.update); + rFB.pipeline(tgSgFlt.sigFloatUpdExtIn) .parent(scene.pl.update); + rFB.pipeline(tgSgFlt.sigFloatUpdLoop) .parent(tgParts.linkLoop); - top_emplace< SignalValues_t > (topData, idSigValFloat); - top_emplace< UpdateNodes > (topData, idSigUpdFloat); + rFB.data_emplace< SignalValues_t > (topData, idSigValFloat); + rFB.data_emplace< UpdateNodes > (topData, idSigUpdFloat); // NOTE: Consider supporting per-thread UpdateNodes to allow multiple threads to write // new float values in parallel. - rBuilder.task() + rFB.task() .name ("Update Signal Nodes") .run_on ({tgParts.linkLoop(EStgLink::NodeUpd)}) .sync_with ({tgSgFlt.sigFloatUpdExtIn(Ready), tgParts.machUpdExtIn(Ready), tgSgFlt.sigFloatUpdLoop(Modify), tgSgFlt.sigFloatValues(Modify)}) @@ -632,5 +632,5 @@ Session setup_signals_float( } // setup_signals_float -} // namespace testapp::scenes +} // namespace adera #endif diff --git a/src/testapp/sessions/vehicles.h b/src/adera_app/features/vehicles.h similarity index 92% rename from src/testapp/sessions/vehicles.h rename to src/adera_app/features/vehicles.h index 993664b3..4a5edccb 100644 --- a/src/testapp/sessions/vehicles.h +++ b/src/adera_app/features/vehicles.h @@ -27,14 +27,14 @@ #include "../scenarios.h" -namespace testapp::scenes +namespace adera { /** * @brief Support for Parts, Machines, and Links */ osp::Session setup_parts( - osp::TopTaskBuilder& rBuilder, + osp::TopTaskBuilder& rFB, osp::ArrayView topData, osp::Session const& application, osp::Session const& scene); @@ -69,7 +69,7 @@ osp::Session setup_parts( * another float signal, all running within a single frame. */ osp::Session setup_signals_float( - osp::TopTaskBuilder& rBuilder, + osp::TopTaskBuilder& rFB, osp::ArrayView topData, osp::Session const& scene, osp::Session const& parts); @@ -80,7 +80,7 @@ osp::Session setup_signals_float( * This only sets up links and does not apply forces, see setup_rocket_thrust_newton */ osp::Session setup_mach_rocket( - osp::TopTaskBuilder& rBuilder, + osp::TopTaskBuilder& rFB, osp::ArrayView topData, osp::Session const& scene, osp::Session const& parts, @@ -90,7 +90,7 @@ osp::Session setup_mach_rocket( * @brief Links for RCS Drivers, which output thrust levels given pitch/yaw/roll controls */ osp::Session setup_mach_rcsdriver( - osp::TopTaskBuilder& rBuilder, + osp::TopTaskBuilder& rFB, osp::ArrayView topData, osp::Session const& scene, osp::Session const& parts, @@ -103,12 +103,12 @@ osp::Session setup_mach_rcsdriver( * of conencted Parts */ osp::Session setup_vehicle_spawn( - osp::TopTaskBuilder& rBuilder, + osp::TopTaskBuilder& rFB, osp::ArrayView topData, osp::Session const& scene); osp::Session setup_vehicle_spawn_draw( - osp::TopTaskBuilder& rBuilder, + osp::TopTaskBuilder& rFB, osp::ArrayView topData, osp::Session const& sceneRenderer, osp::Session const& vehicleSpawn); @@ -117,7 +117,7 @@ osp::Session setup_vehicle_spawn_draw( * @brief Support VehicleBuilder data to be used to spawn vehicles */ osp::Session setup_vehicle_spawn_vb( - osp::TopTaskBuilder& rBuilder, + osp::TopTaskBuilder& rFB, osp::ArrayView topData, osp::Session const& application, osp::Session const& scene, diff --git a/src/testapp/sessions/vehicles_machines.cpp b/src/adera_app/features/vehicles_machines.cpp similarity index 86% rename from src/testapp/sessions/vehicles_machines.cpp rename to src/adera_app/features/vehicles_machines.cpp index f663b38a..8c86798e 100644 --- a/src/testapp/sessions/vehicles_machines.cpp +++ b/src/adera_app/features/vehicles_machines.cpp @@ -44,11 +44,11 @@ using namespace osp::draw; using namespace osp::link; using namespace osp; -namespace testapp::scenes +namespace adera { Session setup_mach_rocket( - TopTaskBuilder& rBuilder, + TopTaskBuilder& rFB, ArrayView const topData, Session const& scene, Session const& parts, @@ -56,14 +56,14 @@ Session setup_mach_rocket( { OSP_DECLARE_GET_DATA_IDS(signalsFloat, TESTAPP_DATA_SIGNALS_FLOAT) OSP_DECLARE_GET_DATA_IDS(parts, TESTAPP_DATA_PARTS); - auto const tgScn = scene .get_pipelines(); + auto const scene.pl = scene .get_pipelines(); auto const tgParts = parts .get_pipelines(); Session out; - rBuilder.task() + rFB.task() .name ("Allocate Machine update bitset for MagicRocket") - .run_on ({tgScn.update(Run)}) + .run_on ({scene.pl.update(Run)}) .sync_with ({tgParts.machIds(Ready), tgParts.machUpdExtIn(New)}) .push_to (out.m_tasks) .args ({idScnParts, idUpdMach}) @@ -90,7 +90,7 @@ struct ThrustIndicator }; Session setup_thrust_indicators( - TopTaskBuilder& rBuilder, + TopTaskBuilder& rFB, ArrayView const topData, Session const& application, Session const& windowApp, @@ -106,31 +106,31 @@ Session setup_thrust_indicators( OSP_DECLARE_GET_DATA_IDS(parts, TESTAPP_DATA_PARTS); OSP_DECLARE_GET_DATA_IDS(signalsFloat, TESTAPP_DATA_SIGNALS_FLOAT) OSP_DECLARE_GET_DATA_IDS(sceneRenderer, TESTAPP_DATA_SCENE_RENDERER); - auto const tgWin = windowApp .get_pipelines(); - auto const tgScnRdr = sceneRenderer .get_pipelines(); + auto const windowApp.pl = windowApp .get_pipelines(); + auto const scene.plRdr = sceneRenderer .get_pipelines(); auto const tgParts = parts .get_pipelines(); - auto &rResources = top_get< Resources > (topData, idResources); - auto &rBasic = top_get< ACtxBasic > (topData, idBasic); - auto &rDrawing = top_get< ACtxDrawing > (topData, idDrawing); - auto &rDrawingRes = top_get< ACtxDrawingRes > (topData, idDrawingRes); - auto &rScnRender = top_get< ACtxSceneRender >(topData, idScnRender); - auto &rDrawTfObservers = top_get< DrawTfObservers >(topData, idDrawTfObservers); - auto &rScnParts = top_get< ACtxParts > (topData, idScnParts); - auto &rSigValFloat = top_get< SignalValues_t > (topData, idSigValFloat); + auto &rResources = rFB.data_get< Resources > (topData, mainApp.di.resources); + auto &rBasic = rFB.data_get< ACtxBasic > (topData, commonScene.di.basic); + auto &rDrawing = rFB.data_get< ACtxDrawing > (topData, commonScene.di.drawing); + auto &rDrawingRes = rFB.data_get< ACtxDrawingRes > (topData, commonScene.di.drawingRes); + auto &rScnRender = rFB.data_get< ACtxSceneRender >(topData, idScnRender); + auto &rDrawTfObservers = rFB.data_get< DrawTfObservers >(topData, idDrawTfObservers); + auto &rScnParts = rFB.data_get< ACtxParts > (topData, idScnParts); + auto &rSigValFloat = rFB.data_get< SignalValues_t > (topData, idSigValFloat); Session out; auto const [idThrustIndicator] = out.acquire_data<1>(topData); - auto &rThrustIndicator = top_emplace(topData, idThrustIndicator); + auto &rThrustIndicator = rFB.data_emplace(topData, idThrustIndicator); rThrustIndicator.material = material; rThrustIndicator.color = { 1.0f, 0.2f, 0.8f, 1.0f }; rThrustIndicator.mesh = SysRender::add_drawable_mesh(rDrawing, rDrawingRes, rResources, pkg, "cone"); - rBuilder.task() + rFB.task() .name ("Create DrawEnts for Thrust indicators") - .run_on ({tgWin.sync(Run)}) - .sync_with ({tgScnRdr.drawEntResized(ModifyOrSignal), tgScnRdr.drawEnt(New), tgParts.machIds(Ready)}) + .run_on ({windowApp.pl.sync(Run)}) + .sync_with ({scene.plRdr.drawEntResized(ModifyOrSignal), scene.plRdr.drawEnt(New), tgParts.machIds(Ready)}) .push_to (out.m_tasks) .args ({ idScnRender, idScnParts, idThrustIndicator}) .func([] (ACtxSceneRender &rScnRender, ACtxParts const& rScnParts, ThrustIndicator& rThrustIndicator) noexcept @@ -149,12 +149,12 @@ Session setup_thrust_indicators( } }); - rBuilder.task() + rFB.task() .name ("Add mesh and materials to Thrust indicators") - .run_on ({tgWin.sync(Run)}) - .sync_with ({tgScnRdr.drawEntResized(Done), tgScnRdr.drawEnt(Ready), tgScnRdr.entMesh(New), tgScnRdr.material(New), tgScnRdr.materialDirty(Modify_), tgScnRdr.entMeshDirty(Modify_)}) + .run_on ({windowApp.pl.sync(Run)}) + .sync_with ({scene.plRdr.drawEntResized(Done), scene.plRdr.drawEnt(Ready), scene.plRdr.entMesh(New), scene.plRdr.material(New), scene.plRdr.materialDirty(Modify_), scene.plRdr.entMeshDirty(Modify_)}) .push_to (out.m_tasks) - .args ({ idBasic, idScnRender, idDrawing, idDrawingRes, idScnParts, idSigValFloat, idThrustIndicator}) + .args ({ commonScene.di.basic, idScnRender, commonScene.di.drawing, commonScene.di.drawingRes, idScnParts, idSigValFloat, idThrustIndicator}) .func([] (ACtxBasic& rBasic, ACtxSceneRender &rScnRender, ACtxDrawing& rDrawing, ACtxDrawingRes const& rDrawingRes, ACtxParts const& rScnParts, SignalValues_t const& rSigValFloat, ThrustIndicator& rThrustIndicator) noexcept { Material &rMat = rScnRender.m_materials[rThrustIndicator.material]; @@ -245,11 +245,11 @@ Session setup_thrust_indicators( } }; - rBuilder.task() + rFB.task() .name ("Clean up ThrustIndicator") - .run_on ({tgWin.cleanup(Run_)}) + .run_on ({windowApp.pl.cleanup(Run_)}) .push_to (out.m_tasks) - .args ({ idResources, idDrawing, idThrustIndicator}) + .args ({ mainApp.di.resources, commonScene.di.drawing, idThrustIndicator}) .func([] (Resources& rResources, ACtxDrawing& rDrawing, ThrustIndicator& rThrustIndicator) noexcept { rDrawing.m_meshRefCounts.ref_release(std::move(rThrustIndicator.mesh)); @@ -262,7 +262,7 @@ Session setup_thrust_indicators( Session setup_mach_rcsdriver( - TopTaskBuilder& rBuilder, + TopTaskBuilder& rFB, ArrayView const topData, Session const& scene, Session const& parts, @@ -270,14 +270,14 @@ Session setup_mach_rcsdriver( { OSP_DECLARE_GET_DATA_IDS(signalsFloat, TESTAPP_DATA_SIGNALS_FLOAT) OSP_DECLARE_GET_DATA_IDS(parts, TESTAPP_DATA_PARTS); - auto const tgScn = scene .get_pipelines(); + auto const scene.pl = scene .get_pipelines(); auto const tgParts = parts .get_pipelines(); Session out; - rBuilder.task() + rFB.task() .name ("Allocate Machine update bitset for RcsDriver") - .run_on ({tgScn.update(Run)}) + .run_on ({scene.pl.update(Run)}) .sync_with ({tgParts.machIds(Ready), tgParts.machUpdExtIn(New)}) .push_to (out.m_tasks) .args ({idScnParts, idUpdMach}) @@ -286,7 +286,7 @@ Session setup_mach_rcsdriver( rUpdMach.localDirty[gc_mtRcsDriver].resize(rScnParts.machines.perType[gc_mtRcsDriver].localIds.capacity()); }); - rBuilder.task() + rFB.task() .name ("RCS Drivers calculate new values") .run_on ({tgParts.linkLoop(MachUpd)}) .sync_with ({tgParts.machUpdExtIn(Ready)}) @@ -375,7 +375,7 @@ struct VehicleControls }; Session setup_vehicle_control( - TopTaskBuilder& rBuilder, + TopTaskBuilder& rFB, ArrayView const topData, Session const& windowApp, Session const& scene, @@ -386,20 +386,20 @@ Session setup_vehicle_control( OSP_DECLARE_GET_DATA_IDS(parts, TESTAPP_DATA_PARTS); OSP_DECLARE_GET_DATA_IDS(windowApp, TESTAPP_DATA_WINDOW_APP); OSP_DECLARE_GET_DATA_IDS(signalsFloat, TESTAPP_DATA_SIGNALS_FLOAT); - auto const tgWin = windowApp .get_pipelines(); - auto const tgScn = scene .get_pipelines(); + auto const windowApp.pl = windowApp .get_pipelines(); + auto const scene.pl = scene .get_pipelines(); auto const tgSgFlt = signalsFloat .get_pipelines(); Session out; OSP_DECLARE_CREATE_DATA_IDS(out, topData, TESTAPP_DATA_VEHICLE_CONTROL); - auto const tgVhCtrl = out.create_pipelines(rBuilder); + auto const tgVhCtrl = out.create_pipelines(rFB); - rBuilder.pipeline(tgVhCtrl.selectedVehicle).parent(tgScn.update); + rFB.pipeline(tgVhCtrl.selectedVehicle).parent(scene.pl.update); - auto &rUserInput = top_get< input::UserInputHandler >(topData, idUserInput); + auto &rUserInput = rFB.data_get< input::UserInputHandler >(topData, windowApp.di.userInput); // TODO: add cleanup task - top_emplace(topData, idVhControls, VehicleControls{ + rFB.data_emplace(topData, idVhControls, VehicleControls{ .btnSwitch = rUserInput.button_subscribe("game_switch"), .btnThrMax = rUserInput.button_subscribe("vehicle_thr_max"), .btnThrMin = rUserInput.button_subscribe("vehicle_thr_min"), @@ -413,12 +413,12 @@ Session setup_vehicle_control( .btnRollRt = rUserInput.button_subscribe("vehicle_roll_rt") }); - rBuilder.task() + rFB.task() .name ("Select vehicle") - .run_on ({tgWin.inputs(Run)}) + .run_on ({windowApp.pl.inputs(Run)}) .sync_with ({tgVhCtrl.selectedVehicle(Modify)}) .push_to (out.m_tasks) - .args ({ idScnParts, idUserInput, idVhControls}) + .args ({ idScnParts, windowApp.di.userInput, idVhControls}) .func([] (ACtxParts& rScnParts, input::UserInputHandler const &rUserInput, VehicleControls &rVhControls) noexcept { PerMachType &rUsrCtrl = rScnParts.machines.perType[gc_mtUserCtrl]; @@ -450,12 +450,12 @@ Session setup_vehicle_control( } }); - rBuilder.task() + rFB.task() .name ("Write inputs to UserControl Machines") - .run_on ({tgScn.update(Run)}) - .sync_with ({tgWin.inputs(Run), tgSgFlt.sigFloatUpdExtIn(Modify)}) + .run_on ({scene.pl.update(Run)}) + .sync_with ({windowApp.pl.inputs(Run), tgSgFlt.sigFloatUpdExtIn(Modify)}) .push_to (out.m_tasks) - .args ({ idScnParts, idUpdMach, idSigValFloat, idSigUpdFloat, idUserInput, idVhControls, idDeltaTimeIn}) + .args ({ idScnParts, idUpdMach, idSigValFloat, idSigUpdFloat, windowApp.di.userInput, idVhControls, idDeltaTimeIn}) .func([] (ACtxParts& rScnParts, MachineUpdater& rUpdMach, SignalValues_t& rSigValFloat, UpdateNodes& rSigUpdFloat, input::UserInputHandler const& rUserInput, VehicleControls& rVhControls, float const deltaTimeIn) noexcept { VehicleControls& rVC = rVhControls; @@ -523,7 +523,7 @@ Session setup_vehicle_control( Session setup_camera_vehicle( - TopTaskBuilder& rBuilder, + TopTaskBuilder& rFB, [[maybe_unused]] ArrayView const topData, Session const& windowApp, Session const& scene, @@ -540,25 +540,25 @@ Session setup_camera_vehicle( OSP_DECLARE_GET_DATA_IDS(cameraCtrl, TESTAPP_DATA_CAMERA_CTRL); OSP_DECLARE_GET_DATA_IDS(vehicleCtrl, TESTAPP_DATA_VEHICLE_CONTROL); - auto const tgWin = windowApp .get_pipelines(); + auto const windowApp.pl = windowApp .get_pipelines(); auto const tgCmCt = cameraCtrl .get_pipelines(); auto const tgPhys = physics .get_pipelines(); auto const tgParts = parts .get_pipelines(); Session out; - // Don't add tgCS.transform(Modify) to sync_with, even though this uses transforms. + // Don't add commonScene.pl.transform(Modify) to sync_with, even though this uses transforms. // tgPhys.physUpdate(Done) assures physics transforms are done. // - // tgCmCt.camCtrl(Ready) is needed by the shape thrower, which needs tgCS.transform(New), + // tgCmCt.camCtrl(Ready) is needed by the shape thrower, which needs commonScene.pl.transform(New), // causing a circular dependency. The transform pipeline probably needs to be split into // a few separate ones. - rBuilder.task() + rFB.task() .name ("Update vehicle camera") - .run_on ({tgWin.sync(Run)}) + .run_on ({windowApp.pl.sync(Run)}) .sync_with ({tgCmCt.camCtrl(Modify), tgPhys.physUpdate(Done), tgParts.mapWeldActive(Ready)}) .push_to (out.m_tasks) - .args ({ idCamCtrl, idDeltaTimeIn, idBasic, idVhControls, idScnParts}) + .args ({ idCamCtrl, idDeltaTimeIn, commonScene.di.basic, idVhControls, idScnParts}) .func([] (ACtxCameraController& rCamCtrl, float const deltaTimeIn, ACtxBasic const& rBasic, VehicleControls& rVhControls, ACtxParts const& rScnParts) noexcept { if (rVhControls.selectedUsrCtrl != lgrn::id_null()) @@ -594,5 +594,5 @@ Session setup_camera_vehicle( -} // namespace testapp::scenes +} // namespace adera #endif diff --git a/src/testapp/sessions/vehicles_machines.h b/src/adera_app/features/vehicles_machines.h similarity index 93% rename from src/testapp/sessions/vehicles_machines.h rename to src/adera_app/features/vehicles_machines.h index 943994d3..a9352258 100644 --- a/src/testapp/sessions/vehicles_machines.h +++ b/src/adera_app/features/vehicles_machines.h @@ -29,14 +29,14 @@ #include -namespace testapp::scenes +namespace adera { /** * @brief Controls to select and control a UserControl Machine */ osp::Session setup_vehicle_control( - osp::TopTaskBuilder& rBuilder, + osp::TopTaskBuilder& rFB, osp::ArrayView topData, osp::Session const& windowApp, osp::Session const& scene, @@ -47,7 +47,7 @@ osp::Session setup_vehicle_control( * @brief Camera which can free cam or follow a selected vehicle */ osp::Session setup_camera_vehicle( - osp::TopTaskBuilder& rBuilder, + osp::TopTaskBuilder& rFB, osp::ArrayView topData, osp::Session const& windowApp, osp::Session const& scene, @@ -62,7 +62,7 @@ osp::Session setup_camera_vehicle( * @brief Red indicators over Magic Rockets */ osp::Session setup_thrust_indicators( - osp::TopTaskBuilder& rBuilder, + osp::TopTaskBuilder& rFB, osp::ArrayView topData, osp::Session const& application, osp::Session const& windowApp, @@ -73,5 +73,5 @@ osp::Session setup_thrust_indicators( osp::PkgId const pkg, osp::draw::MaterialId material); -} // namespace testapp::scenes +} // namespace adera #endif diff --git a/src/testapp/sessions/vehicles_prebuilt.cpp b/src/adera_app/features/vehicles_prebuilt.cpp similarity index 86% rename from src/testapp/sessions/vehicles_prebuilt.cpp rename to src/adera_app/features/vehicles_prebuilt.cpp index 18647d03..aa9ac622 100644 --- a/src/testapp/sessions/vehicles_prebuilt.cpp +++ b/src/adera_app/features/vehicles_prebuilt.cpp @@ -38,7 +38,7 @@ using osp::restypes::gc_importer; using namespace Magnum::Math::Literals; -namespace testapp::scenes +namespace adera { @@ -54,14 +54,14 @@ struct RCSInputs NodeId m_roll {lgrn::id_null()}; }; -static void add_rcs_machines(VehicleBuilder& rBuilder, RCSInputs const& inputs, PartId part, float thrustMul, Matrix4 const& tf) +static void add_rcs_machines(VehicleBuilder& rFB, RCSInputs const& inputs, PartId part, float thrustMul, Matrix4 const& tf) { namespace ports_rcsdriver = adera::ports_rcsdriver; namespace ports_magicrocket = adera::ports_magicrocket; - auto const [posX, posY, posZ, dirX, dirY, dirZ, driverOut, thrMul] = rBuilder.create_nodes<8>(gc_ntSigFloat); + auto const [posX, posY, posZ, dirX, dirY, dirZ, driverOut, thrMul] = rFB.create_nodes<8>(gc_ntSigFloat); - rBuilder.create_machine(part, gc_mtRcsDriver, { + rFB.create_machine(part, gc_mtRcsDriver, { { ports_rcsdriver::gc_posXIn, posX }, { ports_rcsdriver::gc_posYIn, posY }, { ports_rcsdriver::gc_posZIn, posZ }, @@ -74,14 +74,14 @@ static void add_rcs_machines(VehicleBuilder& rBuilder, RCSInputs const& inputs, { ports_rcsdriver::gc_throttleOut, driverOut } } ); - rBuilder.create_machine(part, gc_mtMagicRocket, { + rFB.create_machine(part, gc_mtMagicRocket, { { ports_magicrocket::gc_throttleIn, driverOut }, { ports_magicrocket::gc_multiplierIn, thrMul } } ); Vector3 const dir = tf.rotation() * gc_rocketForward; - auto &rFloatValues = rBuilder.node_values< SignalValues_t >(gc_ntSigFloat); + auto &rFloatValues = rFB.node_values< SignalValues_t >(gc_ntSigFloat); rFloatValues[posX] = tf.translation().x(); rFloatValues[posY] = tf.translation().y(); @@ -92,12 +92,12 @@ static void add_rcs_machines(VehicleBuilder& rBuilder, RCSInputs const& inputs, rFloatValues[thrMul] = thrustMul; } -static void add_rcs_block(VehicleBuilder& rBuilder, VehicleBuilder::WeldVec_t& rWeldTo, RCSInputs const& inputs, float thrustMul, Vector3 pos, Quaternion rot) +static void add_rcs_block(VehicleBuilder& rFB, VehicleBuilder::WeldVec_t& rWeldTo, RCSInputs const& inputs, float thrustMul, Vector3 pos, Quaternion rot) { constexpr Vector3 xAxis{1.0f, 0.0f, 0.0f}; - auto const [ nozzleA, nozzleB ] = rBuilder.create_parts<2>(); - rBuilder.set_prefabs({ + auto const [ nozzleA, nozzleB ] = rFB.create_parts<2>(); + rFB.set_prefabs({ { nozzleA, "phLinRCS" }, { nozzleB, "phLinRCS" } }); @@ -105,29 +105,29 @@ static void add_rcs_block(VehicleBuilder& rBuilder, VehicleBuilder::WeldVec_t& r Matrix4 const nozzleTfA = quick_transform(pos, rot * Quaternion::rotation(90.0_degf, xAxis)); Matrix4 const nozzleTfB = quick_transform(pos, rot * Quaternion::rotation(-90.0_degf, xAxis)); - add_rcs_machines(rBuilder, inputs, nozzleA, thrustMul, nozzleTfA); - add_rcs_machines(rBuilder, inputs, nozzleB, thrustMul, nozzleTfB); + add_rcs_machines(rFB, inputs, nozzleA, thrustMul, nozzleTfA); + add_rcs_machines(rFB, inputs, nozzleB, thrustMul, nozzleTfB); rWeldTo.push_back({ nozzleA, nozzleTfA }); rWeldTo.push_back({ nozzleB, nozzleTfB }); } Session setup_prebuilt_vehicles( - TopTaskBuilder& rBuilder, + TopTaskBuilder& rFB, ArrayView const topData, Session const& application, Session const& scene) { OSP_DECLARE_GET_DATA_IDS(application, TESTAPP_DATA_APPLICATION); - auto const tgScn = scene.get_pipelines(); + auto const scene.pl = scene.get_pipelines(); - auto &rResources = top_get(topData, idResources); + auto &rResources = rFB.data_get(topData, mainApp.di.resources); Session out; OSP_DECLARE_CREATE_DATA_IDS(out, topData, TESTAPP_DATA_TEST_VEHICLES); - out.m_cleanup = tgScn.cleanup; + out.m_cleanup = scene.pl.cleanup; - auto &rPrebuiltVehicles = top_emplace(topData, idPrebuiltVehicles); + auto &rPrebuiltVehicles = rFB.data_emplace(topData, idPrebuiltVehicles); rPrebuiltVehicles.resize(PrebuiltVhIdReg_t::size()); using namespace adera; @@ -204,11 +204,11 @@ Session setup_prebuilt_vehicles( // Put more prebuilt vehicles here! - rBuilder.task() + rFB.task() .name ("Clean up prebuilt vehicles") - .run_on ({tgScn.cleanup(Run_)}) + .run_on ({scene.pl.cleanup(Run_)}) .push_to (out.m_tasks) - .args ({ idPrebuiltVehicles, idResources}) + .args ({ idPrebuiltVehicles, mainApp.di.resources}) .func([] (PrebuiltVehicles &rPrebuildVehicles, Resources& rResources) noexcept { for (std::unique_ptr &rpData : rPrebuildVehicles) @@ -228,5 +228,5 @@ Session setup_prebuilt_vehicles( } // setup_prebuilt_vehicles -} // namespace testapp::scenes +} // namespace adera #endif diff --git a/src/testapp/sessions/vehicles_prebuilt.h b/src/adera_app/features/vehicles_prebuilt.h similarity index 95% rename from src/testapp/sessions/vehicles_prebuilt.h rename to src/adera_app/features/vehicles_prebuilt.h index 8f5860af..e9ce9d27 100644 --- a/src/testapp/sessions/vehicles_prebuilt.h +++ b/src/adera_app/features/vehicles_prebuilt.h @@ -36,7 +36,7 @@ #include -namespace testapp::scenes +namespace adera { using PrebuiltVhId = osp::StrongId; @@ -51,11 +51,11 @@ struct PrebuiltVehicles : osp::KeyedVec< PrebuiltVhId, std::unique_ptr topData, osp::Session const& application, osp::Session const& scene); -} // namespace testapp::scenes +} // namespace adera #endif diff --git a/src/osp/drawing/drawing.h b/src/osp/drawing/drawing.h index bf4431e3..425e7eef 100644 --- a/src/osp/drawing/drawing.h +++ b/src/osp/drawing/drawing.h @@ -31,11 +31,12 @@ #include "../core/keyed_vector.h" #include "../core/math_types.h" #include "../core/resourcetypes.h" -#include "../core/storage.h" #include "../activescene/active_ent.h" #include "../activescene/basic.h" +#include "../scientific/shapes.h" + #include #include @@ -189,5 +190,15 @@ struct Camera } }; + +struct NamedMeshes +{ + NamedMeshes() = default; + OSP_MOVE_ONLY_CTOR_ASSIGN(NamedMeshes) // Huge compile errors without this. MeshIdOwner_t is move-only. + + entt::dense_map m_shapeToMesh; + entt::dense_map m_namedMeshs; +}; + } // namespace osp::draw diff --git a/src/osp/framework/framework.h b/src/osp/framework/framework.h index 0dbdd5f0..da5c57ab 100644 --- a/src/osp/framework/framework.h +++ b/src/osp/framework/framework.h @@ -340,12 +340,20 @@ struct Framework [[nodiscard]] inline FIInstanceId get_interface_id(FITypeId type, ContextId ctx) noexcept { + if ( ! ctx.has_value() ) + { + return {}; + } return contextData[ctx].finterSlots[type]; } template [[nodiscard]] inline FIInstanceId get_interface_id(ContextId ctx) noexcept { + if ( ! ctx.has_value() ) + { + return {}; + } return contextData[ctx].finterSlots[FITypeInfoRegistry::get_or_register()]; } diff --git a/src/osp/tasks/execute2r.h b/src/osp/tasks/execute2r.h new file mode 100644 index 00000000..61aadae9 --- /dev/null +++ b/src/osp/tasks/execute2r.h @@ -0,0 +1,46 @@ +/** + * Open Space Program + * Copyright © 2019-2024 Open Space Program Project + * + * MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#pragma once + +/* + +s +expects an odd or even task? + +in order to move to the next stage, certain conditions must be met: + +each pipeline has a current stage and an odd/even. + + + +restrictions to entering a stage: +* one of the tasks depends on a stage that hasn't yet looped around + + +now how the hell do we do the case where there's only two tasks? + +when advancing one pipeline, it would be blocked becuase the other pipeline wants t + +*/ diff --git a/src/osp/tasks/tasks.cpp b/src/osp/tasks/tasks.cpp index 9d2f5913..0a484bd3 100644 --- a/src/osp/tasks/tasks.cpp +++ b/src/osp/tasks/tasks.cpp @@ -64,10 +64,8 @@ TaskGraph make_exec_graph(Tasks const& tasks) KeyedVec plCounts; KeyedVec taskCounts; - lgrn::IdSetStl plInTree; out.pipelineToFirstAnystg .resize(maxPipelines); - plInTree.resize(maxPipelines); plCounts .resize(maxPipelines+1); taskCounts .resize(maxTasks+1); @@ -140,9 +138,6 @@ TaskGraph make_exec_graph(Tasks const& tasks) if (parent != lgrn::id_null()) { - plInTree.insert(parent); - plInTree.insert(child); - PipelineCounts &rChildCounts = plCounts[child]; PipelineCounts &rParentCounts = plCounts[parent]; @@ -155,7 +150,7 @@ TaskGraph make_exec_graph(Tasks const& tasks) } } - std::size_t const treeSize = plInTree.size(); + std::size_t const treeSize = tasks.m_pipelineIds.size();//plInTree.size(); // 4. Allocate @@ -361,20 +356,15 @@ TaskGraph make_exec_graph(Tasks const& tasks) PipelineTreePos_t rootPos = 0; + // iterate roots only for (PipelineId const pipeline : tasks.m_pipelineIds) { - if ( ! plInTree.contains(pipeline) || tasks.m_pipelineParents[pipeline] != lgrn::id_null()) + if (tasks.m_pipelineParents[pipeline] == lgrn::id_null()) { - continue; // Not in tree or not a root + PipelineCounts const& rRootCounts = plCounts[pipeline]; + std::uint32_t const rootDescendantCount = add_subtree(add_subtree, pipeline, rRootCounts.firstChild, lgrn::id_null(), rootPos); + rootPos += 1 + rootDescendantCount; } - - // For each root pipeline - - PipelineCounts const& rRootCounts = plCounts[pipeline]; - - uint32_t const rootDescendantCount = add_subtree(add_subtree, pipeline, rRootCounts.firstChild, lgrn::id_null(), rootPos); - - rootPos += 1 + rootDescendantCount; } return out; diff --git a/src/testapp/MagnumApplication.cpp b/src/testapp/MagnumWindowApp.cpp similarity index 90% rename from src/testapp/MagnumApplication.cpp rename to src/testapp/MagnumWindowApp.cpp index a579b4ac..949a72e0 100644 --- a/src/testapp/MagnumApplication.cpp +++ b/src/testapp/MagnumWindowApp.cpp @@ -23,7 +23,7 @@ * SOFTWARE. */ -#include "MagnumApplication.h" +#include "MagnumWindowApp.h" #include #include @@ -33,8 +33,8 @@ using namespace testapp; -using Key_t = MagnumApplication::KeyEvent::Key; -using Mouse_t = MagnumApplication::MouseEvent::Button; +using Key_t = MagnumWindowApp::KeyEvent::Key; +using Mouse_t = MagnumWindowApp::MouseEvent::Button; using osp::input::sc_keyboard; using osp::input::sc_mouse; @@ -47,7 +47,7 @@ using osp::input::EVarOperator; using Magnum::Platform::Application; -MagnumApplication::MagnumApplication(const Application::Arguments& arguments, +MagnumWindowApp::MagnumWindowApp(const Application::Arguments& arguments, UserInputHandler& rUserInput) : Application{arguments, Configuration{}.setTitle("OSP-Magnum").setSize({1280, 720})} , m_rUserInput(rUserInput) @@ -58,12 +58,12 @@ MagnumApplication::MagnumApplication(const Application::Arguments& arguments, m_timeline.start(); } -MagnumApplication::~MagnumApplication() +MagnumWindowApp::~MagnumWindowApp() { m_ospApp.reset(nullptr); } -void MagnumApplication::drawEvent() +void MagnumWindowApp::drawEvent() { m_rUserInput.update_controls(); @@ -79,38 +79,38 @@ void MagnumApplication::drawEvent() redraw(); } -void MagnumApplication::keyPressEvent(KeyEvent& event) +void MagnumWindowApp::keyPressEvent(KeyEvent& event) { if (event.isRepeated()) { return; } m_rUserInput.event_raw(osp::input::sc_keyboard, (int) event.key(), osp::input::EButtonEvent::Pressed); } -void MagnumApplication::keyReleaseEvent(KeyEvent& event) +void MagnumWindowApp::keyReleaseEvent(KeyEvent& event) { if (event.isRepeated()) { return; } m_rUserInput.event_raw(osp::input::sc_keyboard, (int) event.key(), osp::input::EButtonEvent::Released); } -void MagnumApplication::mousePressEvent(MouseEvent& event) +void MagnumWindowApp::mousePressEvent(MouseEvent& event) { m_rUserInput.event_raw(osp::input::sc_mouse, (int) event.button(), osp::input::EButtonEvent::Pressed); } -void MagnumApplication::mouseReleaseEvent(MouseEvent& event) +void MagnumWindowApp::mouseReleaseEvent(MouseEvent& event) { m_rUserInput.event_raw(osp::input::sc_mouse, (int) event.button(), osp::input::EButtonEvent::Released); } -void MagnumApplication::mouseMoveEvent(MouseMoveEvent& event) +void MagnumWindowApp::mouseMoveEvent(MouseMoveEvent& event) { m_rUserInput.mouse_delta(event.relativePosition()); } -void MagnumApplication::mouseScrollEvent(MouseScrollEvent & event) +void MagnumWindowApp::mouseScrollEvent(MouseScrollEvent & event) { m_rUserInput.scroll_delta(static_cast(event.offset())); } @@ -220,9 +220,9 @@ const std::map> gc_buttonMap = { {"F12", {sc_keyboard, (int)Key_t::F12 }}, //Mouse - {"RMouse", {sc_mouse, (int)MagnumApplication::MouseEvent::Button::Right }}, - {"LMouse", {sc_mouse, (int)MagnumApplication::MouseEvent::Button::Left }}, - {"MMouse", {sc_mouse, (int)MagnumApplication::MouseEvent::Button::Middle }} + {"RMouse", {sc_mouse, (int)MagnumWindowApp::MouseEvent::Button::Right }}, + {"LMouse", {sc_mouse, (int)MagnumWindowApp::MouseEvent::Button::Left }}, + {"MMouse", {sc_mouse, (int)MagnumWindowApp::MouseEvent::Button::Middle }} }; ControlExprConfig_t parse_control(std::string_view str) noexcept diff --git a/src/testapp/MagnumApplication.h b/src/testapp/MagnumWindowApp.h similarity index 81% rename from src/testapp/MagnumApplication.h rename to src/testapp/MagnumWindowApp.h index c4f01318..dfed1be3 100644 --- a/src/testapp/MagnumApplication.h +++ b/src/testapp/MagnumWindowApp.h @@ -38,34 +38,39 @@ namespace testapp { -class MagnumApplication; +class MagnumWindowApp; class IOspApplication { public: virtual ~IOspApplication() = default; - virtual void run(MagnumApplication& rApp) = 0; - virtual void draw(MagnumApplication& rApp, float delta) = 0; - virtual void exit(MagnumApplication& rApp) = 0; + virtual void run(MagnumWindowApp& rApp) = 0; + virtual void draw(MagnumWindowApp& rApp, float delta) = 0; + virtual void exit(MagnumWindowApp& rApp) = 0; }; /** - * @brief An interactive Magnum application + * @brief Magnum-powered window application with GL context, main/render loop, and user input. * - * This is intended to run a flight scene, map view, vehicle editor, or menu. + * Opens an OS gui window on construction, and closes it on destruction. + * + * Customize using \c IOspApplication. Internal IOspApplication can be changed while the window is + * still open. + * + * This must run on the main thread. */ -class MagnumApplication : public Magnum::Platform::Application +class MagnumWindowApp : public Magnum::Platform::Application { public: using AppPtr_t = std::unique_ptr; - explicit MagnumApplication( + explicit MagnumWindowApp( const Magnum::Platform::Application::Arguments& arguments, osp::input::UserInputHandler& rUserInput); - ~MagnumApplication(); + ~MagnumWindowApp(); void keyPressEvent(KeyEvent& event) override; void keyReleaseEvent(KeyEvent& event) override; diff --git a/src/testapp/enginetest.cpp b/src/testapp/enginetest.cpp index 0a1c7bfa..cd4592f4 100644 --- a/src/testapp/enginetest.cpp +++ b/src/testapp/enginetest.cpp @@ -22,7 +22,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -#include "MagnumApplication.h" +#include "MagnumWindowApp.h" #include #include @@ -336,10 +336,10 @@ class EngineTestApp : public IOspApplication , m_rRenderGl {rRenderGl} { } - void run(MagnumApplication& rApp) override + void run(MagnumWindowApp& rApp) override { } - void draw(MagnumApplication& rApp, float delta) override + void draw(MagnumWindowApp& rApp, float delta) override { update_test_scene(m_rScene, delta); @@ -352,7 +352,7 @@ class EngineTestApp : public IOspApplication render_test_scene(m_rRenderGl, m_rScene, m_renderer); } - void exit(MagnumApplication& rApp) override + void exit(MagnumWindowApp& rApp) override { osp::draw::SysRenderGL::clear_resource_owners(m_rRenderGl, *m_rScene.m_pResources); m_rRenderGl = {}; // clear all GPU resources @@ -364,7 +364,7 @@ class EngineTestApp : public IOspApplication RenderGL &m_rRenderGl; }; -MagnumApplication::AppPtr_t generate_osp_magnum_app(EngineTestScene& rScene, MagnumApplication &rApp, RenderGL& rRenderGl, UserInputHandler& rUserInput) +MagnumWindowApp::AppPtr_t generate_osp_magnum_app(EngineTestScene& rScene, MagnumWindowApp &rApp, RenderGL& rRenderGl, UserInputHandler& rUserInput) { using namespace osp::active; using namespace osp::draw; diff --git a/src/testapp/enginetest.h b/src/testapp/enginetest.h index 2961deb8..163006f4 100644 --- a/src/testapp/enginetest.h +++ b/src/testapp/enginetest.h @@ -24,7 +24,7 @@ */ #pragma once -#include "MagnumApplication.h" +#include "MagnumWindowApp.h" #include @@ -44,9 +44,9 @@ struct EngineTestScene; entt::any setup_scene(osp::Resources& rResources, osp::PkgId pkg); /** - * @brief Generate IOspApplication for MagnumApplication + * @brief Generate IOspApplication for MagnumWindowApp */ -MagnumApplication::AppPtr_t generate_osp_magnum_app(EngineTestScene& rScene, MagnumApplication& rApp, osp::draw::RenderGL& rRenderGl, osp::input::UserInputHandler& rUserInput); +MagnumWindowApp::AppPtr_t generate_osp_magnum_app(EngineTestScene& rScene, MagnumWindowApp& rApp, osp::draw::RenderGL& rRenderGl, osp::input::UserInputHandler& rUserInput); } // namespace testapp::enginetest diff --git a/src/testapp/feature_interfaces.h b/src/testapp/feature_interfaces.h index aeda660a..2f86746a 100644 --- a/src/testapp/feature_interfaces.h +++ b/src/testapp/feature_interfaces.h @@ -1,6 +1,6 @@ /** * Open Space Program - * Copyright © 2019-2022 Open Space Program Project + * Copyright © 2019-2024 Open Space Program Project * * MIT License * @@ -24,435 +24,21 @@ */ #pragma once -#include -#include +#include -#include - -namespace testapp -{ - - -enum class EStgOptn : uint8_t -{ - ModifyOrSignal, - Schedule, - Run, - Done -}; -OSP_DECLARE_STAGE_NAMES(EStgOptn, "Modify/Signal", "Schedule", "Run", "Done"); -OSP_DECLARE_STAGE_SCHEDULE(EStgOptn, EStgOptn::Schedule); - - -enum class EStgEvnt : uint8_t -{ - Run_, - Done_ -}; -OSP_DECLARE_STAGE_NAMES(EStgEvnt, "Run", "Done"); -OSP_DECLARE_STAGE_NO_SCHEDULE(EStgEvnt); - -/** - * @brief Intermediate container that is filled, used, then cleared right away - */ -enum class EStgIntr : uint8_t -{ - Resize, - Modify_, - Schedule_, - UseOrRun, - Clear -}; -OSP_DECLARE_STAGE_NAMES(EStgIntr, "Resize", "Modify", "Schedule", "Use/Run", "Clear"); -OSP_DECLARE_STAGE_SCHEDULE(EStgIntr, EStgIntr::Schedule_); - -/** - * @brief 'Reversed' Intermediate container - */ -enum class EStgRevd : uint8_t -{ - Schedule__, - UseOrRun_, - Clear_, - Resize_, - Modify__, -}; -OSP_DECLARE_STAGE_NAMES(EStgRevd, "Schedule", "Use/Run", "Clear", "Resize", "Modify"); -OSP_DECLARE_STAGE_SCHEDULE(EStgRevd, EStgRevd::Schedule__); - -/** - * @brief Continuous Containers, data that persists and is modified over time - * - */ -enum class EStgCont : uint8_t -{ - Prev, - ///< Previous state of container - - Delete, - ///< Remove elements from a container or mark them for deletion. This often involves reading - ///< a set of elements to delete. This is run first since it leaves empty spaces for new - ///< elements to fill directly after - - New, - ///< Add new elements. Potentially resize the container to fit more elements - - Modify, - ///< Modify existing elements - - Ready - ///< Container is ready to use -}; -OSP_DECLARE_STAGE_NAMES(EStgCont, "Prev", "Delete", "New", "Modify", "Use"); -OSP_DECLARE_STAGE_NO_SCHEDULE(EStgCont); - -enum class EStgFBO -{ - Bind, - Draw, - Unbind -}; -OSP_DECLARE_STAGE_NAMES(EStgFBO, "Bind", "Draw", "Unbind"); -OSP_DECLARE_STAGE_NO_SCHEDULE(EStgFBO); - - -enum class EStgLink -{ - ScheduleLink, - NodeUpd, - MachUpd -}; -OSP_DECLARE_STAGE_NAMES(EStgLink, "Schedule", "NodeUpd", "MachUpd"); -OSP_DECLARE_STAGE_SCHEDULE(EStgLink, EStgLink::ScheduleLink); - -//----------------------------------------------------------------------------- - -inline void register_stage_enums() -{ - osp::PipelineInfo::sm_stageNames.resize(32); - osp::PipelineInfo::register_stage_enum(); - osp::PipelineInfo::register_stage_enum(); - osp::PipelineInfo::register_stage_enum(); - osp::PipelineInfo::register_stage_enum(); - osp::PipelineInfo::register_stage_enum(); - osp::PipelineInfo::register_stage_enum(); - osp::PipelineInfo::register_stage_enum(); -} - -using osp::PipelineDef; -using osp::fw::DataId; - -//----------------------------------------------------------------------------- - -struct FIMainApp { - struct DataIds { - DataId appContexts; - DataId resources; - DataId mainLoopCtrl; - DataId frameworkModify; - DataId cin; - }; - - struct Pipelines { - PipelineDef mainLoop {"mainLoop"}; - PipelineDef cin {"cin"}; - }; -}; - -//----------------------------------------------------------------------------- - -struct FIEngineTest { - struct DataIds { - DataId bigStruct; - }; - - struct Pipelines { }; -}; - -struct FIScene { - struct DataIds { - DataId deltaTimeIn; - }; - - struct Pipelines { - PipelineDef cleanup {"cleanup - Scene cleanup before destruction"}; - PipelineDef update {"update"}; - }; -}; - - -struct FICommonScene { - struct DataIds { - DataId basic; - DataId drawing; - DataId drawingRes; - DataId activeEntDel; - DataId drawEntDel; - DataId namedMeshes; - }; - - struct Pipelines { - PipelineDef activeEnt {"activeEnt - ACtxBasic::m_activeIds"}; - PipelineDef activeEntResized {"activeEntResized - ACtxBasic::m_activeIds option to resize"}; - PipelineDef activeEntDelete {"activeEntDelete - commonScene.di.activeEntDel, vector of ActiveEnts that need to be deleted"}; - - PipelineDef transform {"transform - ACtxBasic::m_transform"}; - PipelineDef hierarchy {"hierarchy - ACtxBasic::m_scnGraph"}; - }; -}; - -#define TESTAPP_DATA_PHYSICS 3, \ - idPhys, idHierBody, idPhysIn -struct PlPhysics -{ - PipelineDef physBody {"physBody"}; - PipelineDef physUpdate {"physUpdate"}; -}; - - - -#define TESTAPP_DATA_PHYS_SHAPES 1, \ - idPhysShapes -struct PlPhysShapes -{ - PipelineDef spawnRequest {"spawnRequest - Spawned shapes"}; - PipelineDef spawnedEnts {"spawnedEnts"}; - PipelineDef ownedEnts {"ownedEnts"}; -}; - - - -#define TESTAPP_DATA_PREFABS 1, \ - idPrefabs -struct PlPrefabs -{ - PipelineDef spawnRequest {"spawnRequest"}; - PipelineDef spawnedEnts {"spawnedEnts"}; - PipelineDef ownedEnts {"ownedEnts"}; - - PipelineDef instanceInfo {"instanceInfo"}; - - PipelineDef inSubtree {"inSubtree"}; -}; - - - -#define TESTAPP_DATA_BOUNDS 2, \ - idBounds, idOutOfBounds -struct PlBounds -{ - PipelineDef boundsSet {"boundsSet"}; - PipelineDef outOfBounds {"outOfBounds"}; -}; - - - -#define TESTAPP_DATA_PARTS 2, \ - idScnParts, idUpdMach -struct PlParts -{ - PipelineDef partIds {"partIds - ACtxParts::partIds"}; - PipelineDef partPrefabs {"partPrefabs - ACtxParts::partPrefabs"}; - PipelineDef partTransformWeld {"partTransformWeld - ACtxParts::partTransformWeld"}; - PipelineDef partDirty {"partDirty - ACtxParts::partDirty"}; - - PipelineDef weldIds {"weldIds - ACtxParts::weldIds"}; - PipelineDef weldDirty {"weldDirty - ACtxParts::weldDirty"}; - - PipelineDef machIds {"machIds - ACtxParts::machines.ids"}; - PipelineDef nodeIds {"nodeIds - ACtxParts::nodePerType[*].nodeIds"}; - PipelineDef connect {"connect - ACtxParts::nodePerType[*].nodeToMach/machToNode"}; - - PipelineDef mapWeldPart {"mapPartWeld - ACtxParts::weldToParts/partToWeld"}; - PipelineDef mapPartMach {"mapPartMach - ACtxParts::partToMachines/machineToPart"}; - PipelineDef mapPartActive {"mapPartActive - ACtxParts::partToActive/activeToPart"}; - PipelineDef mapWeldActive {"mapWeldActive - ACtxParts::weldToActive"}; - - PipelineDef machUpdExtIn {"machUpdExtIn -"}; - - PipelineDef linkLoop {"linkLoop - Link update loop"}; -}; - - - -#define TESTAPP_DATA_VEHICLE_SPAWN 1, \ - idVehicleSpawn -struct PlVehicleSpawn -{ - PipelineDef spawnRequest {"spawnRequest - ACtxVehicleSpawn::spawnRequest"}; - PipelineDef spawnedParts {"spawnedParts - ACtxVehicleSpawn::spawnedPart*"}; - PipelineDef spawnedWelds {"spawnedWelds - ACtxVehicleSpawn::spawnedWeld*"}; - PipelineDef rootEnts {"rootEnts - ACtxVehicleSpawn::rootEnts"}; - PipelineDef spawnedMachs {"spawnedMachs - ACtxVehicleSpawn::spawnedMachs"}; -}; - - - -#define TESTAPP_DATA_VEHICLE_SPAWN_VB 1, \ - idVehicleSpawnVB -struct PlVehicleSpawnVB -{ - PipelineDef dataVB {"dataVB - ACtxVehicleSpawnVB::dataVB"}; - PipelineDef remapParts {"remapParts - ACtxVehicleSpawnVB::remapPart*"}; - PipelineDef remapWelds {"remapWelds - ACtxVehicleSpawnVB::remapWeld*"}; - PipelineDef remapMachs {"remapMachs - ACtxVehicleSpawnVB::remapMach*"}; - PipelineDef remapNodes {"remapNodes - ACtxVehicleSpawnVB::remapNode*"}; -}; - - - -#define TESTAPP_DATA_TEST_VEHICLES 1, \ - idPrebuiltVehicles - - - -#define TESTAPP_DATA_SIGNALS_FLOAT 2, \ - idSigValFloat, idSigUpdFloat -struct PlSignalsFloat -{ - PipelineDef sigFloatValues {"sigFloatValues -"}; - PipelineDef sigFloatUpdExtIn {"sigFloatUpdExtIn -"}; - PipelineDef sigFloatUpdLoop {"sigFloatUpdLoop -"}; -}; - - - -#define TESTAPP_DATA_NEWTON 1, \ - idNwt -struct PlNewton -{ - PipelineDef nwtBody {"nwtBody"}; -}; - -#define TESTAPP_DATA_NEWTON_FORCES 1, \ - idNwtFactors - - - -#define TESTAPP_DATA_NEWTON_ACCEL 1, \ - idAcceleration - - -#define TESTAPP_DATA_JOLT 1, \ - idJolt -struct PlJolt +namespace ftr_inter { - PipelineDef joltBody {"joltBody"}; -}; -#define TESTAPP_DATA_JOLT_FORCES 1, \ - idJoltFactors - - - -#define TESTAPP_DATA_JOLT_ACCEL 1, \ - idAcceleration - - - -#define TESTAPP_DATA_ROCKETS_NWT 1, \ - idRocketsNwt - - -#define TESTAPP_DATA_ROCKETS_JOLT 1, \ - idRocketsJolt - - -#define TESTAPP_DATA_TERRAIN 2, \ - idTerrainFrame, idTerrain -struct PlTerrain -{ - PipelineDef skeleton {"skeleton"}; - PipelineDef surfaceChanges {"surfaceChanges"}; - PipelineDef chunkMesh {"chunkMesh"}; - PipelineDef terrainFrame {"terrainFrame"}; -}; - -#define TESTAPP_DATA_TERRAIN_ICO 1, \ - idTerrainIco - - -//----------------------------------------------------------------------------- - -// Universe sessions - -#define TESTAPP_DATA_UNI_CORE 2, \ - idUniverse, tgUniDeltaTimeIn -struct PlUniCore -{ - PipelineDef update {"update - Universe update"}; - PipelineDef transfer {"transfer"}; -}; - -#define TESTAPP_DATA_UNI_SCENEFRAME 1, \ - idScnFrame -struct PlUniSceneFrame -{ - PipelineDef sceneFrame {"sceneFrame"}; -}; - -#define TESTAPP_DATA_UNI_PLANETS 2, \ - idPlanetMainSpace, idSatSurfaceSpaces - -//----------------------------------------------------------------------------- - -// Solar System sessions - -#define TESTAPP_DATA_SOLAR_SYSTEM_PLANETS 3, \ - idPlanetMainSpace, idSatSurfaceSpaces, idCoordNBody - -//----------------------------------------------------------------------------- - -// Renderer sessions, tend to exist only when the window is open - -struct FIWindowApp { +struct FICinREPL { struct DataIds { - DataId windowAppLoopCtrl; - DataId userInput; + DataId cinLines; }; struct Pipelines { - PipelineDef inputs {"inputs"}; - PipelineDef sync {"sync"}; - PipelineDef resync {"resync"}; - - PipelineDef cleanup {"cleanup - Cleanup renderer resources before destruction"}; + PipelineDef cinLines {"cmdIn"}; }; }; - -#define TESTAPP_DATA_SCENE_RENDERER 2, \ - idScnRender, idDrawTfObservers -struct PlSceneRenderer -{ - PipelineDef render {"render - "}; - - PipelineDef drawEnt {"drawEnt - "}; - PipelineDef drawEntResized {"drawEntResized - "}; - PipelineDef drawEntDelete {"drawEntDelete - Vector of DrawEnts that need to be deleted"}; - - PipelineDef entTextureDirty {"entTextureDirty"}; - PipelineDef entMeshDirty {"entMeshDirty"}; - - PipelineDef material {"material"}; - PipelineDef materialDirty {"materialDirty"}; - - PipelineDef drawTransforms {"drawTransforms"}; - - PipelineDef group {"group"}; - PipelineDef groupEnts {"groupEnts"}; - PipelineDef entMesh {"entMesh"}; - PipelineDef entTexture {"entTexture"}; - - PipelineDef mesh {"mesh"}; - PipelineDef texture {"texture"}; - - PipelineDef meshResDirty {"meshResDirty"}; - PipelineDef textureResDirty {"textureResDirty"}; -}; - - - struct FIMagnum { struct DataIds { DataId magnumApp; @@ -469,36 +55,5 @@ struct FIMagnum { }; -#define TESTAPP_DATA_MAGNUM_SCENE 3, \ - idScnRenderGl, idGroupFwd, idCamera -struct PlMagnumScene -{ - PipelineDef fbo {"fboRender"}; - - PipelineDef camera {"camera"}; - -}; - - - -#define TESTAPP_DATA_CAMERA_CTRL 1, \ - idCamCtrl -struct PlCameraCtrl -{ - PipelineDef camCtrl {"camCtrl"}; -}; - - -#define TESTAPP_DATA_INDICATOR 1, \ - idIndicator - - - -#define TESTAPP_DATA_VEHICLE_CONTROL 1, \ - idVhControls -struct PlVehicleCtrl -{ - PipelineDef selectedVehicle {"selectedVehicle"}; -}; -} // namespace testapp +} // namespace ftr_inter diff --git a/src/testapp/features/console.cpp b/src/testapp/features/console.cpp new file mode 100644 index 00000000..b2959654 --- /dev/null +++ b/src/testapp/features/console.cpp @@ -0,0 +1,109 @@ +/** + * Open Space Program + * Copyright © 2019-2024 Open Space Program Project + * + * MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#include "console.h" + + + +#include "../feature_interfaces.h" + +#include + +#include + +#include +#include + +using namespace adera; +using namespace osp::fw; +using namespace osp; + +using namespace ftr_inter; +using namespace ftr_inter::stages; + + +namespace testapp +{ + +class NonBlockingCinReader +{ +public: + void start_thread() + { + thread = std::thread{[this] + { + while(true) + { + std::string strIn; + std::getline(std::cin, strIn); + + std::lock_guard guard(mutex); + messages.emplace_back(std::move(strIn)); + } + }}; + } + + //void stop(); // TODO + + [[nodiscard]] std::vector read() + { + std::lock_guard guard(mutex); + return std::exchange(messages, {}); + } + + static NonBlockingCinReader& instance() + { + static NonBlockingCinReader thing; + return thing; + } + +private: + std::thread thread; + std::mutex mutex; + std::vector messages; +}; + + +FeatureDef const ftrREPL = feature_def("REPL", [] (FeatureBuilder &rFB, Implement cinREPL, DependOn mainApp, entt::any) +{ + rFB.data_emplace< std::vector >(cinREPL.di.cinLines); + rFB.pipeline(cinREPL.pl.cinLines).parent(mainApp.pl.mainLoop); + + rFB.task() + .name ("Read stdin buffer") + .run_on ({mainApp.pl.mainLoop(Run)}) + .sync_with ({cinREPL.pl.cinLines(Modify_)}) + .args ({ cinREPL.di.cinLines}) + .func([] (std::vector &rCinLines) noexcept + { + rCinLines = NonBlockingCinReader::instance().read(); + }); + + NonBlockingCinReader::instance().start_thread(); +}); + + + + +} // namespace testapp diff --git a/src/testapp/features/console.h b/src/testapp/features/console.h new file mode 100644 index 00000000..27171bcd --- /dev/null +++ b/src/testapp/features/console.h @@ -0,0 +1,37 @@ +/** + * Open Space Program + * Copyright © 2019-2024 Open Space Program Project + * + * MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#pragma once + +#include + +namespace testapp +{ + +/** + * "Read-Evaluate-Print Loop" + */ +extern osp::fw::FeatureDef const ftrREPL; + +} // namespace testapp diff --git a/src/testapp/sessions/magnum.cpp b/src/testapp/features/magnum.cpp similarity index 98% rename from src/testapp/sessions/magnum.cpp rename to src/testapp/features/magnum.cpp index 77221e74..60682eab 100644 --- a/src/testapp/sessions/magnum.cpp +++ b/src/testapp/features/magnum.cpp @@ -23,11 +23,11 @@ * SOFTWARE. */ #include "magnum.h" -#include "terrain.h" -#include "common.h" +//#include "terrain.h" +//#include "common.h" -#include "../MagnumApplication.h" +#include "../MagnumWindowApp.h" #include #include @@ -42,6 +42,8 @@ #include #include +#include "../feature_interfaces.h" + #include #include @@ -56,12 +58,13 @@ using namespace osp::draw; using namespace osp::universe; using namespace osp::fw; using namespace osp; - -using osp::input::UserInputHandler; +using namespace ftr_inter; +using namespace ftr_inter::stages; using Magnum::GL::Mesh; +using osp::input::UserInputHandler; -namespace testapp::scenes +namespace testapp { @@ -77,10 +80,12 @@ FeatureDef const ftrMagnum = feature_def("Magnum", [] ( rFB.pipeline(magnum.pl.entMeshGL) .parent(windowApp.pl.sync); rFB.pipeline(magnum.pl.entTextureGL) .parent(windowApp.pl.sync); - auto const& args = entt::any_cast(data); + auto const& args = entt::any_cast(data); + + OSP_LOG_INFO("Starting Magnum Window Application..."); - // Order-dependent; MagnumApplication construction starts OpenGL context, needed by RenderGL - /* not used here */ rFB.data_emplace(magnum.di.magnumApp, args, rUserInput); + // Order-dependent; MagnumWindowApp construction starts OpenGL context, needed by RenderGL + /* not used here */ rFB.data_emplace(magnum.di.magnumApp, args, rUserInput); auto &rRenderGl = rFB.data_emplace (magnum.di.renderGl); SysRenderGL::setup_context(rRenderGl); @@ -671,5 +676,5 @@ Session setup_terrain_draw_magnum( } // setup_terrain_draw_magnum #endif -} // namespace testapp::scenes +} // namespace testapp diff --git a/src/testapp/sessions/magnum.h b/src/testapp/features/magnum.h similarity index 92% rename from src/testapp/sessions/magnum.h rename to src/testapp/features/magnum.h index 7420a451..1c993090 100644 --- a/src/testapp/sessions/magnum.h +++ b/src/testapp/features/magnum.h @@ -24,13 +24,9 @@ */ #pragma once -#include "../scenarios.h" -#include "../MagnumApplication.h" +#include -#include -#include - -namespace testapp::scenes +namespace testapp { extern osp::fw::FeatureDef const ftrMagnum; @@ -56,4 +52,5 @@ extern osp::fw::FeatureDef const ftrShaderFlat; extern osp::fw::FeatureDef const ftrShaderPhong; extern osp::fw::FeatureDef const ftrShaderDrawMagnum; -} + +} // namespace testapp diff --git a/src/testapp/main.cpp b/src/testapp/main.cpp index f4c94e76..c5e16764 100644 --- a/src/testapp/main.cpp +++ b/src/testapp/main.cpp @@ -22,300 +22,98 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ - -#include "Magnum/GL/DefaultFramebuffer.h" -#include "osp_drawing_gl/rendergl.h" - #include "testapp.h" #include "scenarios.h" #include "feature_interfaces.h" -#include "sessions/common.h" -#include "sessions/magnum.h" -#include "testapp/MagnumApplication.h" +#include "scenarios_magnum.h" +#include "features/console.h" -#include +#include +#include -#include -#include -#include #include #include #include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include +#include #include -#include #include -#include -#include -#include -#include using namespace testapp; - -using adera::MainLoopControl; -using adera::FrameworkModify; - -/** - * @brief As the name implies - * - * This should only be called once for the entire lifetime - * of the program. - * - * prefer not to use names like this outside of testapp - */ -void load_a_bunch_of_stuff(); +using namespace adera; +using namespace osp::fw; +using namespace ftr_inter; +using namespace ftr_inter::stages; // called only from commands to display information void print_help(); void print_resources(); -std::optional g_testApp; - osp::fw::SingleThreadedExecutor g_executor; +std::optional g_testApp; osp::Logger_t g_mainThreadLogger; osp::Logger_t g_logExecutor; osp::Logger_t g_logMagnumApp; -using namespace osp::fw; - -int g_argc; -char** g_argv; - -struct MainLoopSignals -{ - osp::PipelineId mainLoop; - osp::PipelineId inputs; - osp::PipelineId renderSync; - osp::PipelineId renderResync; - osp::PipelineId sceneUpdate; - osp::PipelineId sceneRender; -}; - -/** - * @brief Runs Task/Pipeline main loop within MagnumApplication - */ -class CommonMagnumApp : public IOspApplication -{ -public: - CommonMagnumApp(TestApp &rTestApp, MainLoopControl &rMainLoopCtrl, MainLoopSignals signals) noexcept - : m_rTestApp { rTestApp } - , m_rMainLoopCtrl { rMainLoopCtrl } - , m_signals { signals } - { } - - void run(MagnumApplication& rApp) override - { - // Start the main loop - -// PipelineId const mainLoop = m_rTestApp.m_application.get_pipelines().mainLoop; -// m_rTestApp.m_pExecutor->run(m_rTestApp, mainLoop); - -// // Resyncronize renderer - -// m_rMainLoopCtrl = MainLoopControl{ -// .doUpdate = false, -// .doSync = true, -// .doResync = true, -// .doRender = false, -// }; - -// signal_all(); - -// m_rTestApp.m_pExecutor->wait(m_rTestApp); - } - - void draw(MagnumApplication& rApp, float delta) override - { - // Magnum Application's main loop calls this - m_rTestApp.drive_main_loop(); - -// auto const magnum = g_testApp->m_framework.get_interface (g_testApp->m_mainContext); -// auto &rRenderGl = entt::any_cast (g_testApp->m_framework.data[magnum.di.renderGl]); - - -// Magnum::GL::defaultFramebuffer.bind(); -// auto &rFboColor = rRenderGl.m_texGl.get(rRenderGl.m_fboColor); -// osp::draw::SysRenderGL::display_texture(rRenderGl, rFboColor); - -// m_rMainLoopCtrl = MainLoopControl{ -// .doUpdate = true, -// .doSync = true, -// .doResync = false, -// .doRender = true, -// }; - -// signal_all(); -// m_rTestApp.m_pExecutor->wait(m_rTestApp); - } - - void exit(MagnumApplication& rApp) override - { -// m_rMainLoopCtrl = MainLoopControl{ -// .doUpdate = false, -// .doSync = false, -// .doResync = false, -// .doRender = false, -// }; - -// signal_all(); - -// m_rTestApp.m_pExecutor->wait(m_rTestApp); - -// if (m_rTestApp.m_pExecutor->is_running(m_rTestApp)) -// { -// // Main loop must have stopped, but didn't! -// m_rTestApp.m_pExecutor->wait(m_rTestApp); -// std::abort(); -// } - } -private: - - void signal_all() - { -// m_rTestApp.m_pExecutor->signal(m_rTestApp, m_signals.mainLoop); -// m_rTestApp.m_pExecutor->signal(m_rTestApp, m_signals.inputs); -// m_rTestApp.m_pExecutor->signal(m_rTestApp, m_signals.renderSync); -// m_rTestApp.m_pExecutor->signal(m_rTestApp, m_signals.renderResync); -// m_rTestApp.m_pExecutor->signal(m_rTestApp, m_signals.sceneUpdate); -// m_rTestApp.m_pExecutor->signal(m_rTestApp, m_signals.sceneRender); - } - - TestApp &m_rTestApp; - MainLoopControl &m_rMainLoopCtrl; - - MainLoopSignals m_signals; -}; - -void eval_command(std::string_view const command, FrameworkModify &rFrameworkModify) +osp::fw::FeatureDef const ftrMainCommands = feature_def("MainCommands", [] (FeatureBuilder& rFB, DependOn mainApp, DependOn cinREPL) { - // First check to see if command is the name of a scenario. - auto const it = scenarios().find(command); - if (it != std::end(scenarios())) - { - ScenarioOption const &rSro = it->second; - - rSro.loadFunc(g_testApp.value()); - } - else // Otherwise check all other commands. + rFB.task() + .name ("Poll and evaluate commands") + .run_on ({mainApp.pl.mainLoop(Run)}) + .sync_with ({cinREPL.pl.cinLines(UseOrRun)}) + .args ({ cinREPL.di.cinLines, mainApp.di.frameworkModify, mainApp.di.appContexts}) + .func ([] (std::vector const &rCinLines, FrameworkModify &rFrameworkModify, AppContexts const& appContexts) noexcept { - if (command == "help") + for (std::string const& cmdStr : rCinLines) { - print_help(); - } - else if (command == "reopen") - { - rFrameworkModify.commands.push_back({.func = [] (entt::any) + // First check to see if command is the name of a scenario. + auto const it = scenarios().find(cmdStr); + if (it != std::end(scenarios())) { - std::cout << "fish :3\n"; - - auto const mainApp = g_testApp->m_framework.get_interface(g_testApp->m_mainContext); - auto &rAppCtxs = entt::any_cast (g_testApp->m_framework.data[mainApp.di.appContexts]); - - rAppCtxs.window = g_testApp->m_framework.contextIds.create(); - - ContextBuilder cb { .m_ctxScope = { g_testApp->m_mainContext}, .m_ctx = rAppCtxs.window, .m_rFW = g_testApp->m_framework }; - cb.add_feature(scenes::ftrWindowApp); - cb.add_feature(scenes::ftrMagnum, MagnumApplication::Arguments{g_argc, g_argv}); - LGRN_ASSERTM(cb.m_errors.empty(), "Error adding main feature"); - ContextBuilder::apply(std::move(cb)); - - main_loop_stack().push_back([] () -> bool { - auto &rTestApp = *g_testApp; - - auto const mainApp = g_testApp->m_framework.get_interface (g_testApp->m_mainContext); - auto const &rAppCtxs = entt::any_cast (g_testApp->m_framework.data[mainApp.di.appContexts]); - - auto const windowApp = g_testApp->m_framework.get_interface(rAppCtxs.window); - auto const magnum = g_testApp->m_framework.get_interface (rAppCtxs.window); - auto &rMainLoopCtrl = entt::any_cast (g_testApp->m_framework.data[mainApp.di.mainLoopCtrl]); - auto &rMagnumApp = entt::any_cast(g_testApp->m_framework.data[magnum.di.magnumApp]); - - MainLoopSignals const signals - { - .mainLoop = mainApp .pl.mainLoop, - .inputs = windowApp .pl.inputs, - .renderSync = windowApp .pl.sync, - .renderResync = windowApp .pl.resync, - //.sceneUpdate = scene .get_pipelines() .update, - //.sceneRender = sceneRenderer .get_pipelines() .render, - }; - rMagnumApp.set_osp_app( std::make_unique(g_testApp.value(), rMainLoopCtrl, signals) ); - - // Blocking. Main loop runs in MagnumApplication::drawEvent continues when the close button is pressed - rMagnumApp.exec(); - - rMagnumApp.set_osp_app({}); - - // Destructing MagnumApplication will close the window - g_testApp->m_framework.data[magnum.di.magnumApp].reset(); - - return false; - }); - - }}); - - } - else if (command == "list_pkg") - { - print_resources(); - } - else if (command == "exit") - { - std::exit(0); - } - else - { - std::cout << "That command doesn't do anything ._.\n"; - } - } -} + rFrameworkModify.commands.push_back({ + .userData = entt::make_any(it->second), + .func = [] (Framework &rFW, ContextId ctx, entt::any userData) + { + auto const& rScenario = entt::any_cast(userData); + rSro.loadFunc(g_testApp.value()); + + std::cout << "Loaded scenario: " << + + }, }); + } + else if (cmdStr == "help") // Otherwise check all other commands. + { + print_help(); + } + else if (cmdStr == "reopen") + { + rFrameworkModify.commands.push_back({ + .userData = entt::make_any(g_testApp.value()), + .ctx = g_testApp->m_mainContext, + .func = &start_magnum_renderer }); -/** - * Read-Eval-Print Loop - */ -auto const ftrREPL = feature_def("REPL", [] (FeatureBuilder& rFB, DependOn mainApp) -{ - rFB.task() - .name ("poll and evaluate commands") - .run_on ({mainApp.pl.mainLoop(EStgOptn::Run)}) - .sync_with ({mainApp.pl.cin(EStgIntr::UseOrRun)}) - .args ({ mainApp.di.cin, mainApp.di.frameworkModify}) - .func ([] (std::vector const &rCin, FrameworkModify &rFrameworkModify) noexcept - { - // Poll - for (std::string const& str : rCin) - { - eval_command(str, rFrameworkModify); + } + else if (cmdStr == "exit") + { + std::exit(0); + } + else + { + std::cout << "That command doesn't do anything ._.\n"; + } } }); }); int main(int argc, char** argv) { - g_argc = argc; - g_argv = argv; + // Command line argument parsing Corrade::Utility::Arguments args; args.addSkippedPrefix("magnum", "Magnum options") @@ -337,6 +135,9 @@ int main(int argc, char** argv) // Set thread-local logger used by OSP_LOG_* macros osp::set_thread_logger(g_mainThreadLogger); + osp::fw::SingleThreadedExecutor g_executor; + //std::optional g_testApp; + if (args.isSet("log-exec")) { g_executor.m_log = g_logExecutor; @@ -357,23 +158,26 @@ int main(int argc, char** argv) register_stage_enums(); - NonBlockingStdInReader::instance().start_thread(); - TestApp &rTestApp = g_testApp.emplace(); + rTestApp.m_argc = argc; + rTestApp.m_argv = argv; + rTestApp.m_pExecutor = &g_executor; rTestApp.init(); - load_a_bunch_of_stuff(); if( ! args.isSet("norepl")) { auto const fiMain = rTestApp.m_framework.get_interface(rTestApp.m_mainContext); auto &rFWModify = entt::any_cast(rTestApp.m_framework.data[fiMain.di.frameworkModify]); - rFWModify.commands.push_back({.func = [] (entt::any) + rFWModify.commands.push_back({ + .ctx = rTestApp.m_mainContext, + .func = [] (Framework &rFW, ContextId ctx, entt::any userData) { - ContextBuilder cb { .m_ctx = g_testApp->m_mainContext, .m_rFW = g_testApp->m_framework }; + ContextBuilder cb { .m_ctx = ctx, .m_rFW = rFW }; cb.add_feature(ftrREPL); + cb.add_feature(ftrMainCommands); LGRN_ASSERTM(cb.m_errors.empty(), "Error adding REPL feature"); ContextBuilder::apply(std::move(cb)); print_help(); @@ -381,21 +185,23 @@ int main(int argc, char** argv) } std::vector &rMainLoopStack = main_loop_stack(); - rMainLoopStack.push_back( [] () -> bool - { - g_testApp->drive_main_loop(); - std::this_thread::sleep_for (std::chrono::milliseconds(100)); - return true; - }); // Main (thread) loop - while ( ! rMainLoopStack.empty() ) + while (true) { - MainLoopFunc_t func = rMainLoopStack.back(); - bool const keep = func(); - if ( ! keep ) + if ( rMainLoopStack.empty() ) + { + g_testApp->drive_main_loop(); + std::this_thread::sleep_for (std::chrono::milliseconds(100)); + } + else { - rMainLoopStack.pop_back(); + MainLoopFunc_t func = rMainLoopStack.back(); + bool const keep = func(); + if ( ! keep ) + { + rMainLoopStack.pop_back(); + } } } @@ -403,67 +209,6 @@ int main(int argc, char** argv) return 0; } -void load_a_bunch_of_stuff() -{ - using namespace osp::restypes; - using namespace Magnum; - using Primitives::ConeFlag; - using Primitives::CylinderFlag; - - TestApp &rTestApp = g_testApp.value(); - - auto const fiMain = rTestApp.m_framework.get_interface(rTestApp.m_mainContext); - auto &rResources = entt::any_cast(rTestApp.m_framework.data[fiMain.di.resources]); - - rResources.data_register(gc_image); - rResources.data_register(gc_texture); - rResources.data_register(gc_texture); - rResources.data_register(gc_mesh); - rResources.data_register(gc_importer); - rResources.data_register(gc_importer); - osp::register_tinygltf_resources(rResources); - - // Load sturdy glTF files - const std::string_view datapath = { "OSPData/adera/" }; - const std::vector meshes = - { - "spamcan.sturdy.gltf", - "stomper.sturdy.gltf", - "ph_capsule.sturdy.gltf", - "ph_fuselage.sturdy.gltf", - "ph_engine.sturdy.gltf", - //"ph_plume.sturdy.gltf", - "ph_rcs.sturdy.gltf" - //"ph_rcs_plume.sturdy.gltf" - }; - - // TODO: Make new gltf loader. This will read gltf files and dump meshes, - // images, textures, and other relevant data into osp::Resources - for (auto const& meshName : meshes) - { - osp::ResId res = osp::load_tinygltf_file(osp::string_concat(datapath, meshName), rResources, rTestApp.m_defaultPkg); - osp::assigns_prefabs_tinygltf(rResources, res); - } - - // Add a default primitives - auto const add_mesh_quick = [&rResources = rResources, &rTestApp] (std::string_view const name, Trade::MeshData&& data) - { - osp::ResId const meshId = rResources.create(gc_mesh, rTestApp.m_defaultPkg, osp::SharedString::create(name)); - rResources.data_add(gc_mesh, meshId, std::move(data)); - }; - - Trade::MeshData &&cylinder = Magnum::MeshTools::transform3D( Primitives::cylinderSolid(3, 16, 1.0f, CylinderFlag::CapEnds), Matrix4::rotationX(Deg(90)), 0); - Trade::MeshData &&cone = Magnum::MeshTools::transform3D( Primitives::coneSolid(3, 16, 1.0f, ConeFlag::CapEnd), Matrix4::rotationX(Deg(90)), 0); - - add_mesh_quick("cube", Primitives::cubeSolid()); - add_mesh_quick("cubewire", Primitives::cubeWireframe()); - add_mesh_quick("sphere", Primitives::icosphereSolid(2)); - add_mesh_quick("cylinder", std::move(cylinder)); - add_mesh_quick("cone", std::move(cone)); - add_mesh_quick("grid64solid", Primitives::grid3DSolid({63, 63})); - - OSP_LOG_INFO("Resource loading complete"); -} //----------------------------------------------------------------------------- @@ -482,7 +227,7 @@ void print_help() for (auto const& [rName, rScenerio] : scenarios()) { std::string spaces(longestName - rName.length(), ' '); - std::cout << "* " << rName << spaces << " - " << rScenerio.description << "\n"; + std::cout << "* " << rName << spaces << " - " << rScenerio.brief << "\n"; } std::cout @@ -492,9 +237,3 @@ void print_help() << "* reopen - Re-open Magnum Application\n" << "* exit - Deallocate everything and return memory to OS\n"; } - -void print_resources() -{ - // TODO: Add features to list resources in osp::Resources - std::cout << "Not yet implemented!\n"; -} diff --git a/src/testapp/scenarios.cpp b/src/testapp/scenarios.cpp index 10e72b4d..4015ad25 100644 --- a/src/testapp/scenarios.cpp +++ b/src/testapp/scenarios.cpp @@ -25,23 +25,21 @@ #include "scenarios.h" #include "enginetest.h" -#include "feature_interfaces.h" - -#include "sessions/common.h" -#include "sessions/magnum.h" -#include "sessions/misc.h" -#include "sessions/jolt.h" -#include "sessions/physics.h" -#include "sessions/shapes.h" -#include "sessions/terrain.h" -#include "sessions/universe.h" -#include "sessions/vehicles.h" -#include "sessions/vehicles_machines.h" -#include "sessions/vehicles_prebuilt.h" - -#include "MagnumApplication.h" - -#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +#include #include #include @@ -54,13 +52,14 @@ #include -#include using namespace adera; using namespace osp; using namespace osp::fw; using namespace osp::active; +using namespace ftr_inter; + namespace testapp { @@ -72,10 +71,12 @@ static constexpr auto sc_matFlat = draw::MaterialId(1); static constexpr auto sc_matPhong = draw::MaterialId(2); static constexpr int sc_materialCount = 4; +/** + * Enginetest itself doesn't depend on the framework, but we need to store it somewhere. + */ FeatureDef const ftrEngineTest = feature_def("EngineTest", [] (FeatureBuilder& rFB, Implement engineTest, DependOn mainApp, entt::any data) { auto &rResources = rFB.data_get(mainApp.di.resources); - rFB.data(engineTest.di.bigStruct) = enginetest::setup_scene(rResources, entt::any_cast(data)); }); @@ -84,23 +85,25 @@ static ScenarioMap_t make_scenarios() ScenarioMap_t scenarioMap; - auto const add_scenario = [&scenarioMap] (std::string_view name, ScenarioOption owo) + auto const add_scenario = [&scenarioMap] (ScenarioOption scenario) { - scenarioMap.emplace(name, owo); + scenarioMap.emplace(scenario.name, scenario); }; - add_scenario("enginetest", { - .description = "Simple rotating cube scenario without relying on Framework", + add_scenario({ + .name = "enginetest", + .brief = "Simple rotating cube scenario ", + .description = "even more explaination", .loadFunc = [] (TestApp& rTestApp) { - auto &rFw = rTestApp.m_framework; - auto const mainApp = rFw.get_interface (rTestApp.m_mainContext); - auto const &rAppCtxs = entt::any_cast(rFw.data[mainApp.di.appContexts]); + auto &rFw = rTestApp.m_framework; + auto const mainApp = rFw.get_interface (rTestApp.m_mainContext); + auto &rAppCtxs = entt::any_cast(rFw.data[mainApp.di.appContexts]); - ContextId const uwu = rFw.contextIds.create(); - ContextBuilder cb { .m_ctxScope = {rTestApp.m_mainContext}, .m_ctx = uwu, .m_rFW = rFw }; + rAppCtxs.scene = rFw.contextIds.create(); + ContextBuilder cb { .m_ctxScope = {rTestApp.m_mainContext}, .m_ctx = rAppCtxs.scene, .m_rFW = rFw }; cb.add_feature(ftrEngineTest, rTestApp.m_defaultPkg); - LGRN_ASSERTM(cb.m_errors.empty(), "Error adding main feature"); + LGRN_ASSERTM(cb.m_errors.empty(), "Error adding engine test feature"); ContextBuilder::apply(std::move(cb)); }}); @@ -132,8 +135,8 @@ static ScenarioMap_t make_scenarios() // containing all the scene data: a spinning cube. top_assign(rTestApp.m_topData, idSceneData, ); - // Called when the MagnumApplication / window is opened, called again if the window is - // re-opened after its closed. Closing the window completely destructs MagnumApplication + // Called when the MagnumWindowApp / window is opened, called again if the window is + // re-opened after its closed. Closing the window completely destructs MagnumWindowApp // and all GPU resources. EngineTestScene will remain untouched in the background. RendererSetupFunc_t const setup_renderer = [] (TestApp& rTestApp) -> void { @@ -142,7 +145,7 @@ static ScenarioMap_t make_scenarios() OSP_DECLARE_GET_DATA_IDS(rTestApp.m_magnum, TESTAPP_DATA_MAGNUM); OSP_DECLARE_GET_DATA_IDS(rTestApp.m_windowApp, TESTAPP_DATA_WINDOW_APP); - auto &rActiveApp = rFB.data_get< MagnumApplication > (rTestApp.m_topData, idActiveApp); + auto &rActiveApp = rFB.data_get< MagnumWindowApp > (rTestApp.m_topData, idActiveApp); auto &rRenderGl = rFB.data_get< draw::RenderGL > (rTestApp.m_topData, magnum.di.renderGl); auto &rUserInput = rFB.data_get< input::UserInputHandler >(rTestApp.m_topData, windowApp.di.userInput); @@ -657,7 +660,7 @@ ScenarioMap_t const& scenarios() // OSP_DECLARE_GET_DATA_IDS(magnumScene, TESTAPP_DATA_MAGNUM_SCENE); // auto &rMainLoopCtrl = rFB.data_get (rTestApp.m_topData, mainApp.di.mainLoopCtrl); -// auto &rActiveApp = rFB.data_get(rTestApp.m_topData, idActiveApp); +// auto &rActiveApp = rFB.data_get(rTestApp.m_topData, idActiveApp); // auto &rCamera = rFB.data_get (rTestApp.m_topData, idCamera); // rCamera.set_aspect_ratio(Vector2{Magnum::GL::defaultFramebuffer.viewport().size()}); diff --git a/src/testapp/scenarios.h b/src/testapp/scenarios.h index fc48eb70..754cdb8b 100644 --- a/src/testapp/scenarios.h +++ b/src/testapp/scenarios.h @@ -24,7 +24,6 @@ */ #pragma once -#include "feature_interfaces.h" #include "testapp.h" // IWYU pragma: begin_exports @@ -37,32 +36,13 @@ namespace testapp { -namespace scenes -{ - using enum EStgOptn; - using enum EStgCont; - using enum EStgIntr; - using enum EStgRevd; - using enum EStgEvnt; - using enum EStgFBO; - using enum EStgLink; -} - - - -struct WindowAppLoopControl -{ - bool doResync; - - bool doSync; - - bool doRender; -}; struct ScenarioOption { using Func_t = void(*)(TestApp&); + std::string_view name; + std::string_view brief; std::string_view description; Func_t loadFunc; }; diff --git a/src/testapp/scenarios_magnum.cpp b/src/testapp/scenarios_magnum.cpp new file mode 100644 index 00000000..e3ced750 --- /dev/null +++ b/src/testapp/scenarios_magnum.cpp @@ -0,0 +1,239 @@ +/** + * Open Space Program + * Copyright © 2019-2024 Open Space Program Project + * + * MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#include "scenarios_magnum.h" + +#include "enginetest.h" +#include "feature_interfaces.h" + +#include "features/magnum.h" +#include "MagnumWindowApp.h" +#include +#include +#include + +using osp::input::UserInputHandler; +using namespace adera; + +using namespace ftr_inter; + +using namespace osp::fw; + +namespace testapp +{ + + + +struct MainLoopSignals +{ + osp::PipelineId mainLoop; + osp::PipelineId inputs; + osp::PipelineId renderSync; + osp::PipelineId renderResync; + osp::PipelineId sceneUpdate; + osp::PipelineId sceneRender; +}; + +/** + * @brief Runs Task/Pipeline main loop within MagnumWindowApp + */ +class CommonMagnumApp : public IOspApplication +{ +public: + CommonMagnumApp(TestApp &rTestApp, MainLoopControl &rMainLoopCtrl, MainLoopSignals signals) noexcept + : m_rTestApp { rTestApp } + , m_rMainLoopCtrl { rMainLoopCtrl } + , m_signals { signals } + { } + + void run(MagnumWindowApp& rApp) override + { + // Start the main loop + +// PipelineId const mainLoop = m_rTestApp.m_application.get_pipelines().mainLoop; +// m_rTestApp.m_pExecutor->run(m_rTestApp, mainLoop); + +// // Resyncronize renderer + +// m_rMainLoopCtrl = MainLoopControl{ +// .doUpdate = false, +// .doSync = true, +// .doResync = true, +// .doRender = false, +// }; + +// signal_all(); + +// m_rTestApp.m_pExecutor->wait(m_rTestApp); + } + + void draw(MagnumWindowApp& rApp, float delta) override + { + // Magnum Application's main loop calls this + m_rTestApp.drive_main_loop(); + +// auto const magnum = g_testApp->m_framework.get_interface (g_testApp->m_mainContext); +// auto &rRenderGl = entt::any_cast (g_testApp->m_framework.data[magnum.di.renderGl]); + + +// Magnum::GL::defaultFramebuffer.bind(); +// auto &rFboColor = rRenderGl.m_texGl.get(rRenderGl.m_fboColor); +// osp::draw::SysRenderGL::display_texture(rRenderGl, rFboColor); + +// m_rMainLoopCtrl = MainLoopControl{ +// .doUpdate = true, +// .doSync = true, +// .doResync = false, +// .doRender = true, +// }; + +// signal_all(); + +// m_rTestApp.m_pExecutor->wait(m_rTestApp); + } + + void exit(MagnumWindowApp& rApp) override + { +// m_rMainLoopCtrl = MainLoopControl{ +// .doUpdate = false, +// .doSync = false, +// .doResync = false, +// .doRender = false, +// }; + +// signal_all(); + +// m_rTestApp.m_pExecutor->wait(m_rTestApp); + +// if (m_rTestApp.m_pExecutor->is_running(m_rTestApp)) +// { +// // Main loop must have stopped, but didn't! +// m_rTestApp.m_pExecutor->wait(m_rTestApp); +// std::abort(); +// } + } + +private: + + void signal_all() + { +// m_rTestApp.m_pExecutor->signal(m_rTestApp, m_signals.mainLoop); +// m_rTestApp.m_pExecutor->signal(m_rTestApp, m_signals.inputs); +// m_rTestApp.m_pExecutor->signal(m_rTestApp, m_signals.renderSync); +// m_rTestApp.m_pExecutor->signal(m_rTestApp, m_signals.renderResync); +// m_rTestApp.m_pExecutor->signal(m_rTestApp, m_signals.sceneUpdate); +// m_rTestApp.m_pExecutor->signal(m_rTestApp, m_signals.sceneRender); + } + + TestApp &m_rTestApp; + MainLoopControl &m_rMainLoopCtrl; + MainLoopSignals m_signals; +}; + + + +void setup_magnum_renderer( + TestApp &rTestApp, + FInterfaceShorthand const mainApp, + AppContexts const &rAppCtxs, + FInterfaceShorthand const windowApp, + FInterfaceShorthand const magnum, + MagnumWindowApp &rMagnumApp) +{ + Framework &rFW = rTestApp.m_framework; + + auto &rMainLoopCtrl = entt::any_cast (rFW.data[mainApp.di.mainLoopCtrl]); + auto &rUserInput = entt::any_cast (rFW.data[windowApp.di.userInput]); + auto &rRenderGL = entt::any_cast (rFW.data[magnum.di.renderGl]); + + if (auto engineTest = rFW.get_interface(rAppCtxs.scene); + engineTest.id.has_value()) + { + auto &rEngineTest = entt::any_cast(rFW.data[engineTest.di.bigStruct]); + + // This creates the renderer actually updates and draws the scene. + rMagnumApp.set_osp_app(enginetest::generate_osp_magnum_app(rEngineTest, rMagnumApp, rRenderGL, rUserInput)); + return; + } + + + MainLoopSignals const signals + { + .mainLoop = mainApp .pl.mainLoop, + .inputs = windowApp.pl.inputs, + .renderSync = windowApp.pl.sync, + .renderResync = windowApp.pl.resync, + //.sceneUpdate = scene .get_pipelines() .update, + //.sceneRender = sceneRenderer .get_pipelines() .render, + }; + + + rMagnumApp.set_osp_app( std::make_unique(rTestApp, rMainLoopCtrl, signals) ); +} + + + +void start_magnum_renderer(Framework &rFW, ContextId ctx, entt::any userData) +{ + std::cout << "fish :3\n"; + + TestApp &rTestApp = entt::any_cast(userData); + auto const mainApp = rFW.get_interface(ctx); + auto &rAppCtxs = entt::any_cast (rFW.data[mainApp.di.appContexts]); + + rAppCtxs.window = rFW.contextIds.create(); + + ContextBuilder cb { .m_ctxScope = { ctx }, .m_ctx = rAppCtxs.window, .m_rFW = rFW }; + cb.add_feature(adera::ftrWindowApp); + cb.add_feature(ftrMagnum, MagnumWindowApp::Arguments{rTestApp.m_argc, rTestApp.m_argv}); + LGRN_ASSERTM(cb.m_errors.empty(), "Error adding main feature"); + ContextBuilder::apply(std::move(cb)); + + main_loop_stack().push_back([&rTestApp] () -> bool { + + Framework &rFW = rTestApp.m_framework; + + auto const mainApp = rFW.get_interface(rTestApp.m_mainContext); + auto &rAppCtxs = entt::any_cast (rFW.data[mainApp.di.appContexts]); + auto const windowApp = rFW.get_interface(rAppCtxs.window); + auto const magnum = rFW.get_interface (rAppCtxs.window); + auto &rMagnumApp = entt::any_cast(rFW.data[magnum.di.magnumApp]); + + setup_magnum_renderer(rTestApp, mainApp, rAppCtxs, windowApp, magnum, rMagnumApp); + + // Blocking. Main loop runs in MagnumWindowApp::drawEvent continues when the close button is pressed + rMagnumApp.exec(); + + rMagnumApp.set_osp_app({}); + + // Destructing MagnumWindowApp will close the window + rFW.data[magnum.di.magnumApp].reset(); + + return false; + }); +} + + + +} // namespace testapp diff --git a/src/testapp/scenarios_magnum.h b/src/testapp/scenarios_magnum.h new file mode 100644 index 00000000..07b11e8d --- /dev/null +++ b/src/testapp/scenarios_magnum.h @@ -0,0 +1,36 @@ +/** + * Open Space Program + * Copyright © 2019-2024 Open Space Program Project + * + * MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#pragma once + +#include + + +namespace testapp +{ + +void start_magnum_renderer(osp::fw::Framework &rFW, osp::fw::ContextId ctx, entt::any userData); + + +} // namespace testapp diff --git a/src/testapp/sessions/common.cpp b/src/testapp/sessions/common.cpp deleted file mode 100644 index 6d83a128..00000000 --- a/src/testapp/sessions/common.cpp +++ /dev/null @@ -1,508 +0,0 @@ - -/** - * Open Space Program - * Copyright © 2019-2022 Open Space Program Project - * - * MIT License - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include "common.h" -#include "../scenarios.h" - -#include -#include -#include -#include -#include -#include - -using namespace adera; -using namespace osp; -using namespace osp::active; -using namespace osp::draw; -#if 0 -namespace testapp::scenes -{ - -Session setup_scene( - TopTaskBuilder& rBuilder, - ArrayView const topData, - Session const& application) -{ - OSP_DECLARE_GET_DATA_IDS(application, TESTAPP_DATA_APPLICATION); - auto const tgApp = application.get_pipelines< PlApplication >(); - - osp::Session out; - OSP_DECLARE_CREATE_DATA_IDS(out, topData, TESTAPP_DATA_SCENE); - - top_emplace< float >(topData, idDeltaTimeIn, 1.0f / 60.0f); - - auto const plScn = out.create_pipelines(rBuilder); - - rBuilder.pipeline(plScn.update).parent(tgApp.mainLoop).wait_for_signal(ModifyOrSignal); - - rBuilder.task() - .name ("Schedule Scene update") - .schedules ({plScn.update(Schedule)}) - .push_to (out.m_tasks) - .args ({ idMainLoopCtrl}) - .func([] (MainLoopControl const& rMainLoopCtrl) noexcept -> osp::TaskActions - { - return rMainLoopCtrl.doUpdate ? osp::TaskActions{} : osp::TaskAction::Cancel; - }); - - return out; -} // setup_scene - - - - -Session setup_common_scene( - TopTaskBuilder& rBuilder, - ArrayView const topData, - Session const& scene, - Session const& application, - PkgId const pkg) -{ - OSP_DECLARE_GET_DATA_IDS(application, TESTAPP_DATA_APPLICATION); - - auto const tgScn = scene.get_pipelines(); - auto &rResources = top_get< Resources > (topData, idResources); - - Session out; - OSP_DECLARE_CREATE_DATA_IDS(out, topData, TESTAPP_DATA_COMMON_SCENE); - auto const tgCS = out.create_pipelines(rBuilder); - - out.m_cleanup = tgScn.cleanup; - - /* unused */ top_emplace< ActiveEntVec_t > (topData, idActiveEntDel); - /* unused */ top_emplace< DrawEntVec_t > (topData, idDrawEntDel); - auto &rBasic = top_emplace< ACtxBasic > (topData, idBasic); - auto &rDrawing = top_emplace< ACtxDrawing > (topData, idDrawing); - auto &rDrawingRes = top_emplace< ACtxDrawingRes > (topData, idDrawingRes); - auto &rNMesh = top_emplace< NamedMeshes > (topData, idNMesh); - - rBuilder.pipeline(tgCS.activeEnt) .parent(tgScn.update); - rBuilder.pipeline(tgCS.activeEntResized) .parent(tgScn.update); - rBuilder.pipeline(tgCS.activeEntDelete) .parent(tgScn.update); - rBuilder.pipeline(tgCS.transform) .parent(tgScn.update); - rBuilder.pipeline(tgCS.hierarchy) .parent(tgScn.update); - - - - rBuilder.task() - .name ("Cancel entity delete tasks stuff if no entities were deleted") - .run_on ({tgCS.activeEntDelete(Schedule_)}) - .push_to (out.m_tasks) - .args ({ idBasic, idActiveEntDel }) - .func([] (ACtxBasic& rBasic, ActiveEntVec_t const& rActiveEntDel) noexcept - { - return rActiveEntDel.empty() ? TaskAction::Cancel : TaskActions{}; - }); - - rBuilder.task() - .name ("Delete ActiveEnt IDs") - .run_on ({tgCS.activeEntDelete(EStgIntr::UseOrRun)}) - .sync_with ({tgCS.activeEnt(Delete)}) - .push_to (out.m_tasks) - .args ({ idBasic, idActiveEntDel }) - .func([] (ACtxBasic& rBasic, ActiveEntVec_t const& rActiveEntDel) noexcept - { - for (ActiveEnt const ent : rActiveEntDel) - { - if (rBasic.m_activeIds.exists(ent)) - { - rBasic.m_activeIds.remove(ent); - } - } - }); - - rBuilder.task() - .name ("Delete basic components") - .run_on ({tgCS.activeEntDelete(UseOrRun)}) - .sync_with ({tgCS.transform(Delete)}) - .push_to (out.m_tasks) - .args ({ idBasic, idActiveEntDel }) - .func([] (ACtxBasic& rBasic, ActiveEntVec_t const& rActiveEntDel) noexcept - { - update_delete_basic(rBasic, rActiveEntDel.cbegin(), rActiveEntDel.cend()); - }); - - rBuilder.task() - .name ("Clear ActiveEnt delete vector once we're done with it") - .run_on ({tgCS.activeEntDelete(Clear)}) - .push_to (out.m_tasks) - .args ({ idActiveEntDel }) - .func([] (ActiveEntVec_t& idActiveEntDel) noexcept - { - idActiveEntDel.clear(); - }); - - - // Clean up tasks - - rBuilder.task() - .name ("Clean up resource owners") - .run_on ({tgScn.cleanup(Run_)}) - .push_to (out.m_tasks) - .args ({ idDrawing, idDrawingRes, idResources}) - .func([] (ACtxDrawing& rDrawing, ACtxDrawingRes& rDrawingRes, Resources& rResources) noexcept - { - SysRender::clear_resource_owners(rDrawingRes, rResources); - }); - - rBuilder.task() - .name ("Clean up NamedMeshes mesh and texture owners") - .run_on ({tgScn.cleanup(Run_)}) - .push_to (out.m_tasks) - .args ({ idDrawing, idNMesh }) - .func([] (ACtxDrawing& rDrawing, NamedMeshes& rNMesh) noexcept - { - for ([[maybe_unused]] auto && [_, rOwner] : std::exchange(rNMesh.m_shapeToMesh, {})) - { - rDrawing.m_meshRefCounts.ref_release(std::move(rOwner)); - } - - for ([[maybe_unused]] auto && [_, rOwner] : std::exchange(rNMesh.m_namedMeshs, {})) - { - rDrawing.m_meshRefCounts.ref_release(std::move(rOwner)); - } - }); - - // Convenient functor to get a reference-counted mesh owner - auto const quick_add_mesh = SysRender::gen_drawable_mesh_adder(rDrawing, rDrawingRes, rResources, pkg); - - // Acquire mesh resources from Package - rNMesh.m_shapeToMesh.emplace(EShape::Box, quick_add_mesh("cube")); - rNMesh.m_shapeToMesh.emplace(EShape::Cylinder, quick_add_mesh("cylinder")); - rNMesh.m_shapeToMesh.emplace(EShape::Sphere, quick_add_mesh("sphere")); - rNMesh.m_namedMeshs.emplace("floor", quick_add_mesh("grid64solid")); - - return out; -} // setup_common_scene - - - - -Session setup_window_app( - TopTaskBuilder& rBuilder, - ArrayView const topData, - Session const& application) -{ - OSP_DECLARE_GET_DATA_IDS(application, TESTAPP_DATA_APPLICATION); - auto const tgApp = application .get_pipelines< PlApplication >(); - - Session out; - OSP_DECLARE_CREATE_DATA_IDS(out, topData, TESTAPP_DATA_WINDOW_APP); - auto const tgWin = out.create_pipelines(rBuilder); - - rBuilder.pipeline(tgWin.inputs).parent(tgApp.mainLoop).wait_for_signal(ModifyOrSignal); - rBuilder.pipeline(tgWin.sync) .parent(tgApp.mainLoop).wait_for_signal(ModifyOrSignal); - rBuilder.pipeline(tgWin.resync).parent(tgApp.mainLoop).wait_for_signal(ModifyOrSignal); - - auto &rUserInput = top_emplace(topData, idUserInput, 12); - - out.m_cleanup = tgWin.cleanup; - - rBuilder.task() - .name ("Schedule Renderer Sync") - .schedules ({tgWin.sync(Schedule)}) - .push_to (out.m_tasks) - .args ({ idMainLoopCtrl}) - .func([] (MainLoopControl const& rMainLoopCtrl) noexcept -> osp::TaskActions - { - return rMainLoopCtrl.doSync ? osp::TaskActions{} : osp::TaskAction::Cancel; - }); - - rBuilder.task() - .name ("Schedule Renderer Resync") - .schedules ({tgWin.resync(Schedule)}) - .push_to (out.m_tasks) - .args ({ idMainLoopCtrl}) - .func([] (MainLoopControl const& rMainLoopCtrl) noexcept -> osp::TaskActions - { - return rMainLoopCtrl.doResync ? osp::TaskActions{} : osp::TaskAction::Cancel; - }); - - return out; -} // setup_window_app - - - - -Session setup_scene_renderer( - TopTaskBuilder& rBuilder, - ArrayView const topData, - Session const& application, - Session const& windowApp, - Session const& commonScene) -{ - OSP_DECLARE_GET_DATA_IDS(windowApp, TESTAPP_DATA_WINDOW_APP); - OSP_DECLARE_GET_DATA_IDS(commonScene, TESTAPP_DATA_COMMON_SCENE); - auto const tgApp = application .get_pipelines< PlApplication >(); - auto const tgWin = windowApp .get_pipelines< PlWindowApp >(); - auto const tgCS = commonScene .get_pipelines< PlCommonScene >(); - - - Session out; - OSP_DECLARE_CREATE_DATA_IDS(out, topData, TESTAPP_DATA_SCENE_RENDERER); - auto const tgScnRdr = out.create_pipelines(rBuilder); - - rBuilder.pipeline(tgScnRdr.render).parent(tgApp.mainLoop).wait_for_signal(ModifyOrSignal); - - rBuilder.pipeline(tgScnRdr.drawEnt) .parent(tgWin.sync); - rBuilder.pipeline(tgScnRdr.drawEntResized) .parent(tgWin.sync); - rBuilder.pipeline(tgScnRdr.drawEntDelete) .parent(tgWin.sync); - rBuilder.pipeline(tgScnRdr.entMesh) .parent(tgWin.sync); - rBuilder.pipeline(tgScnRdr.entTexture) .parent(tgWin.sync); - rBuilder.pipeline(tgScnRdr.entTextureDirty) .parent(tgWin.sync); - rBuilder.pipeline(tgScnRdr.entMeshDirty) .parent(tgWin.sync); - rBuilder.pipeline(tgScnRdr.drawTransforms) .parent(tgScnRdr.render); - rBuilder.pipeline(tgScnRdr.material) .parent(tgWin.sync); - rBuilder.pipeline(tgScnRdr.materialDirty) .parent(tgWin.sync); - rBuilder.pipeline(tgScnRdr.group) .parent(tgWin.sync); - rBuilder.pipeline(tgScnRdr.groupEnts) .parent(tgWin.sync); - rBuilder.pipeline(tgScnRdr.entMesh) .parent(tgWin.sync); - rBuilder.pipeline(tgScnRdr.entTexture) .parent(tgWin.sync); - rBuilder.pipeline(tgScnRdr.mesh) .parent(tgWin.sync); - rBuilder.pipeline(tgScnRdr.texture) .parent(tgWin.sync); - rBuilder.pipeline(tgScnRdr.meshResDirty) .parent(tgWin.sync); - rBuilder.pipeline(tgScnRdr.textureResDirty) .parent(tgWin.sync); - - auto &rScnRender = osp::top_emplace(topData, idScnRender); - /* unused */ osp::top_emplace(topData, idDrawTfObservers); - - rBuilder.task() - .name ("Resize ACtxSceneRender containers to fit all DrawEnts") - .run_on ({tgScnRdr.drawEntResized(Run)}) - .sync_with ({tgScnRdr.entMesh(New), tgScnRdr.entTexture(New)}) - .push_to (out.m_tasks) - .args ({idScnRender}) - .func ([] (ACtxSceneRender& rScnRender) noexcept - { - rScnRender.resize_draw(); - }); - - rBuilder.task() - .name ("Resize ACtxSceneRender to fit ActiveEnts") - .run_on ({tgCS.activeEntResized(Run)}) - .push_to (out.m_tasks) - .args ({ idBasic, idScnRender}) - .func([] (ACtxBasic const &rBasic, ACtxSceneRender& rScnRender) noexcept - { - rScnRender.resize_active(rBasic.m_activeIds.capacity()); - }); - - // Duplicate task needed for resync to account for existing ActiveEnts when the renderer opens, - // as activeEntResized doesn't run during resync - rBuilder.task() - .name ("Resync ACtxSceneRender to fit ActiveEnts") - .run_on ({tgWin.resync(Run)}) - .sync_with ({tgCS.activeEntResized(Run)}) - .push_to (out.m_tasks) - .args ({ idBasic, idScnRender}) - .func([] (ACtxBasic const &rBasic, ACtxSceneRender& rScnRender) noexcept - { - rScnRender.resize_active(rBasic.m_activeIds.capacity()); - }); - - rBuilder.task() - .name ("Schedule Assign GL textures") - .schedules ({tgScnRdr.entTextureDirty(Schedule_)}) - .sync_with ({tgScnRdr.texture(Ready), tgScnRdr.entTexture(Ready)}) - .push_to (out.m_tasks) - .args ({ idScnRender }) - .func([] (ACtxSceneRender& rScnRender) noexcept -> TaskActions - { - return rScnRender.m_diffuseDirty.empty() ? TaskAction::Cancel : TaskActions{}; - }); - - rBuilder.task() - .name ("Schedule Assign GL meshes") - .schedules ({tgScnRdr.entMeshDirty(Schedule_)}) - .sync_with ({tgScnRdr.mesh(Ready), tgScnRdr.entMesh(Ready)}) - .push_to (out.m_tasks) - .args ({ idScnRender }) - .func([] (ACtxSceneRender& rScnRender) noexcept -> TaskActions - { - return rScnRender.m_meshDirty.empty() ? TaskAction::Cancel : TaskActions{}; - }); - - rBuilder.task() - .name ("Calculate draw transforms") - .run_on ({tgScnRdr.render(Run)}) - .sync_with ({tgCS.hierarchy(Ready), tgCS.transform(Ready), tgCS.activeEnt(Ready), tgScnRdr.drawTransforms(Modify_), tgScnRdr.drawEnt(Ready), tgScnRdr.drawEntResized(Done), tgCS.activeEntResized(Done)}) - .push_to (out.m_tasks) - .args ({ idBasic, idDrawing, idScnRender, idDrawTfObservers }) - .func([] (ACtxBasic const& rBasic, ACtxDrawing const& rDrawing, ACtxSceneRender& rScnRender, DrawTfObservers &rDrawTfObservers) noexcept - { - auto rootChildren = SysSceneGraph::children(rBasic.m_scnGraph); - SysRender::update_draw_transforms( - { - .scnGraph = rBasic .m_scnGraph, - .transforms = rBasic .m_transform, - .activeToDraw = rScnRender.m_activeToDraw, - .needDrawTf = rScnRender.m_needDrawTf, - .rDrawTf = rScnRender.m_drawTransform - }, - rootChildren.begin(), - rootChildren.end(), - [&rDrawTfObservers, &rScnRender] (Matrix4 const& transform, active::ActiveEnt ent, int depth) - { - auto const enableInt = std::array{rScnRender.drawTfObserverEnable[ent]}; - auto const enableBits = lgrn::bit_view(enableInt); - - for (std::size_t idx : enableBits.ones()) - { - DrawTfObservers::Observer const &rObserver = rDrawTfObservers.observers[idx]; - rObserver.func(rScnRender, transform, ent, depth, rObserver.data); - } - }); - }); - - rBuilder.task() - .name ("Delete DrawEntity of deleted ActiveEnts") - .run_on ({tgCS.activeEntDelete(UseOrRun)}) - .sync_with ({tgScnRdr.drawEntDelete(Modify_)}) - .push_to (out.m_tasks) - .args ({ idScnRender, idActiveEntDel, idDrawEntDel }) - .func([] (ACtxSceneRender& rScnRender, ActiveEntVec_t const& rActiveEntDel, DrawEntVec_t& rDrawEntDel) noexcept - { - for (ActiveEnt const ent : rActiveEntDel) - { - if (rScnRender.m_activeToDraw.size() < std::size_t(ent)) - { - continue; - } - DrawEnt const drawEnt = std::exchange(rScnRender.m_activeToDraw[ent], lgrn::id_null()); - if (drawEnt != lgrn::id_null()) - { - rDrawEntDel.push_back(drawEnt); - } - } - }); - - rBuilder.task() - .name ("Delete drawing components") - .run_on ({tgScnRdr.drawEntDelete(UseOrRun)}) - .sync_with ({tgScnRdr.entTexture(Delete), tgScnRdr.entMesh(Delete)}) - .push_to (out.m_tasks) - .args ({ idDrawing, idScnRender, idDrawEntDel }) - .func([] (ACtxDrawing& rDrawing, ACtxSceneRender& rScnRender, DrawEntVec_t const& rDrawEntDel) noexcept - { - SysRender::update_delete_drawing(rScnRender, rDrawing, rDrawEntDel.cbegin(), rDrawEntDel.cend()); - }); - - rBuilder.task() - .name ("Delete DrawEntity IDs") - .run_on ({tgScnRdr.drawEntDelete(UseOrRun)}) - .sync_with ({tgScnRdr.drawEnt(Delete)}) - .push_to (out.m_tasks) - .args ({ idScnRender, idDrawEntDel }) - .func([] (ACtxSceneRender& rScnRender, DrawEntVec_t const& rDrawEntDel) noexcept - { - for (DrawEnt const drawEnt : rDrawEntDel) - { - if (rScnRender.m_drawIds.exists(drawEnt)) - { - rScnRender.m_drawIds.remove(drawEnt); - } - } - }); - - rBuilder.task() - .name ("Delete DrawEnt from materials") - .run_on ({tgScnRdr.drawEntDelete(UseOrRun)}) - .sync_with ({tgScnRdr.material(Delete)}) - .push_to (out.m_tasks) - .args ({ idScnRender, idDrawEntDel }) - .func([] (ACtxSceneRender& rScnRender, DrawEntVec_t const& rDrawEntDel) noexcept - { - for (DrawEnt const ent : rDrawEntDel) - { - for (Material &rMat : rScnRender.m_materials) - { - if (std::size_t(ent) < rMat.m_ents.size()) - { - rMat.m_ents.erase(ent); - } - } - } - }); - - rBuilder.task() - .name ("Clear DrawEnt delete vector once we're done with it") - .run_on ({tgScnRdr.drawEntDelete(Clear)}) - .push_to (out.m_tasks) - .args ({ idDrawEntDel }) - .func([] (DrawEntVec_t& rDrawEntDel) noexcept - { - rDrawEntDel.clear(); - }); - - rBuilder.task() - .name ("Clear dirty DrawEnt's textures once we're done with it") - .run_on ({tgScnRdr.entMeshDirty(Clear)}) - .push_to (out.m_tasks) - .args ({ idScnRender}) - .func([] (ACtxSceneRender& rScnRender) noexcept - { - rScnRender.m_meshDirty.clear(); - }); - - rBuilder.task() - .name ("Clear dirty DrawEnt's textures once we're done with it") - .run_on ({tgScnRdr.entTextureDirty(Clear)}) - .push_to (out.m_tasks) - .args ({ idScnRender}) - .func([] (ACtxSceneRender& rScnRender) noexcept - { - rScnRender.m_diffuseDirty.clear(); - }); - - rBuilder.task() - .name ("Clear dirty materials once we're done with it") - .run_on ({tgScnRdr.materialDirty(Clear)}) - .push_to (out.m_tasks) - .args ({ idScnRender}) - .func([] (ACtxSceneRender& rScnRender) noexcept - { - for (Material &rMat : rScnRender.m_materials) - { - rMat.m_dirty.clear(); - } - }); - - rBuilder.task() - .name ("Clean up scene owners") - .run_on ({tgWin.cleanup(Run_)}) - .push_to (out.m_tasks) - .args ({ idDrawing, idScnRender}) - .func([] (ACtxDrawing& rDrawing, ACtxSceneRender& rScnRender) noexcept - { - SysRender::clear_owners(rScnRender, rDrawing); - }); - - return out; -} // setup_scene_renderer - -} // namespace testapp::scenes -#endif diff --git a/src/testapp/sessions/common.h b/src/testapp/sessions/common.h deleted file mode 100644 index 34898c73..00000000 --- a/src/testapp/sessions/common.h +++ /dev/null @@ -1,78 +0,0 @@ -#if 0 -/** - * Open Space Program - * Copyright © 2019-2022 Open Space Program Project - * - * MIT License - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#pragma once - -#include "../scenarios.h" - -#include -#include -#include -#include - -#include - -namespace testapp::scenes -{ - -struct NamedMeshes -{ - NamedMeshes() = default; - OSP_MOVE_ONLY_CTOR_ASSIGN(NamedMeshes) // Huge compile errors without this. MeshIdOwner_t is move-only. - - entt::dense_map m_shapeToMesh; - entt::dense_map m_namedMeshs; -}; - -osp::Session setup_scene( - osp::TopTaskBuilder& rBuilder, - osp::ArrayView topData, - osp::Session const& application); - -/** - * @brief Support for Time, ActiveEnts, Hierarchy, Transforms, Drawing, and more... - */ -osp::Session setup_common_scene( - osp::TopTaskBuilder& rBuilder, - osp::ArrayView topData, - osp::Session const& scene, - osp::Session const& application, - osp::PkgId pkg); - -osp::Session setup_window_app( - osp::TopTaskBuilder& rBuilder, - osp::ArrayView topData, - osp::Session const& application); - -osp::Session setup_scene_renderer( - osp::TopTaskBuilder& rBuilder, - osp::ArrayView topData, - osp::Session const& application, - osp::Session const& windowApp, - osp::Session const& commonScene); - - -} // namespace testapp::scenes -#endif diff --git a/src/testapp/testapp.cpp b/src/testapp/testapp.cpp index 1eeb552c..3e7f7563 100644 --- a/src/testapp/testapp.cpp +++ b/src/testapp/testapp.cpp @@ -23,53 +23,39 @@ * SOFTWARE. */ #include "testapp.h" -#include "feature_interfaces.h" -#include +#include "features/console.h" + +#include +#include +#include #include +#include #include - #include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + #include using namespace adera; + using namespace osp::fw; +using namespace ftr_inter; namespace testapp { -FeatureDef const ftrMain = feature_def("Main", [] (FeatureBuilder& rFB, Implement mainApp, entt::any pkg) -{ - rFB.data_emplace< AppContexts > (mainApp.di.appContexts); - rFB.data_emplace< MainLoopControl > (mainApp.di.mainLoopCtrl); - rFB.data_emplace< osp::Resources > (mainApp.di.resources); - rFB.data_emplace< FrameworkModify > (mainApp.di.frameworkModify); - rFB.data_emplace< std::vector >(mainApp.di.cin); - - rFB.pipeline(mainApp.pl.mainLoop).loops(true).wait_for_signal(EStgOptn::ModifyOrSignal); - rFB.pipeline(mainApp.pl.cin).parent(mainApp.pl.mainLoop); - - rFB.task() - .name ("Schedule Main Loop") - .schedules ({mainApp.pl.mainLoop(EStgOptn::Schedule)}) - .args ({ mainApp.di.mainLoopCtrl}) - .func([] (MainLoopControl const& rMainLoopCtrl) noexcept -> osp::TaskActions - { - return rMainLoopCtrl.doUpdate ? osp::TaskActions{} : osp::TaskAction::Cancel; - }); - - rFB.task() - .name ("Read stdin buffer") - .run_on ({mainApp.pl.mainLoop(EStgOptn::Run)}) - .sync_with ({mainApp.pl.cin(EStgIntr::Modify_)}) - .args ({ mainApp.di.cin}) - .func([] (std::vector &rCin) noexcept - { - rCin = NonBlockingStdInReader::instance().read(); - }); -}); - void TestApp::init() { LGRN_ASSERTM( ! m_mainContext.has_value(), "Call init() only once. pretty please!"); @@ -85,6 +71,8 @@ void TestApp::init() rResources.resize_types(osp::ResTypeIdReg_t::size()); m_defaultPkg = rResources.pkg_create(); + load_a_bunch_of_stuff(); + m_pExecutor->load(m_framework); m_pExecutor->run(m_framework, fiMain.pl.mainLoop); } @@ -110,7 +98,7 @@ void TestApp::drive_main_loop() for (FrameworkModify::Command &rCmd : rFWModify.commands) { - rCmd.func(std::move(rCmd.userData)); + rCmd.func(m_framework, rCmd.ctx, std::move(rCmd.userData)); } rFWModify.commands.clear(); @@ -231,6 +219,65 @@ void TestApp::clear_resource_owners() +void TestApp::load_a_bunch_of_stuff() +{ + using namespace osp::restypes; + using namespace Magnum; + using Primitives::ConeFlag; + using Primitives::CylinderFlag; + + auto const fiMain = m_framework.get_interface(m_mainContext); + auto &rResources = entt::any_cast(m_framework.data[fiMain.di.resources]); + + rResources.data_register(gc_image); + rResources.data_register(gc_texture); + rResources.data_register(gc_texture); + rResources.data_register(gc_mesh); + rResources.data_register(gc_importer); + rResources.data_register(gc_importer); + osp::register_tinygltf_resources(rResources); + + // Load sturdy glTF files + const std::string_view datapath = { "OSPData/adera/" }; + const std::vector meshes = + { + "spamcan.sturdy.gltf", + "stomper.sturdy.gltf", + "ph_capsule.sturdy.gltf", + "ph_fuselage.sturdy.gltf", + "ph_engine.sturdy.gltf", + //"ph_plume.sturdy.gltf", + "ph_rcs.sturdy.gltf" + //"ph_rcs_plume.sturdy.gltf" + }; + + // TODO: Make new gltf loader. This will read gltf files and dump meshes, + // images, textures, and other relevant data into osp::Resources + for (auto const& meshName : meshes) + { + osp::ResId res = osp::load_tinygltf_file(osp::string_concat(datapath, meshName), rResources, m_defaultPkg); + osp::assigns_prefabs_tinygltf(rResources, res); + } + + // Add a default primitives + auto const add_mesh_quick = [&rResources = rResources, this] (std::string_view const name, Trade::MeshData&& data) + { + osp::ResId const meshId = rResources.create(gc_mesh, m_defaultPkg, osp::SharedString::create(name)); + rResources.data_add(gc_mesh, meshId, std::move(data)); + }; + + Trade::MeshData &&cylinder = Magnum::MeshTools::transform3D( Primitives::cylinderSolid(3, 16, 1.0f, CylinderFlag::CapEnds), Matrix4::rotationX(Deg(90)), 0); + Trade::MeshData &&cone = Magnum::MeshTools::transform3D( Primitives::coneSolid(3, 16, 1.0f, ConeFlag::CapEnd), Matrix4::rotationX(Deg(90)), 0); + + add_mesh_quick("cube", Primitives::cubeSolid()); + add_mesh_quick("cubewire", Primitives::cubeWireframe()); + add_mesh_quick("sphere", Primitives::icosphereSolid(2)); + add_mesh_quick("cylinder", std::move(cylinder)); + add_mesh_quick("cone", std::move(cone)); + add_mesh_quick("grid64solid", Primitives::grid3DSolid({63, 63})); + + OSP_LOG_INFO("Resource loading complete"); +} } // namespace testapp diff --git a/src/testapp/testapp.h b/src/testapp/testapp.h index fdfca3cb..048bc16e 100644 --- a/src/testapp/testapp.h +++ b/src/testapp/testapp.h @@ -34,52 +34,14 @@ #include -#include -#include -namespace testapp -{ +#include +#include -class NonBlockingStdInReader +namespace testapp { -public: - void start_thread() - { - thread = std::thread{[this] - { - while(true) - { - std::string strIn; - std::cin >> strIn; - - std::lock_guard guard(mutex); - messages.emplace_back(std::move(strIn)); - } - }}; - } - - //void stop(); // TODO - - [[nodiscard]] std::vector read() - { - std::lock_guard guard(mutex); - return std::exchange(messages, {}); - } - - static NonBlockingStdInReader& instance() - { - static NonBlockingStdInReader thing; - return thing; - } - -private: - std::thread thread; - std::mutex mutex; - std::vector messages; -}; - -using MainLoopFunc_t = bool(*)(); +using MainLoopFunc_t = std::function; inline std::vector& main_loop_stack() { @@ -89,13 +51,6 @@ inline std::vector& main_loop_stack() struct TestApp; -//using RendererSetupFunc_t = void(*)(TestApp&); -//using SceneSetupFunc_t = RendererSetupFunc_t(*)(TestApp&); - - - -extern osp::fw::FeatureDef const ftrMain; - struct TestApp { @@ -113,6 +68,8 @@ struct TestApp void init(); + + osp::fw::Framework m_framework; osp::fw::ContextId m_mainContext; @@ -132,6 +89,20 @@ struct TestApp osp::fw::IExecutor *m_pExecutor { nullptr }; osp::PkgId m_defaultPkg { lgrn::id_null() }; + + int m_argc; + char** m_argv; + + + private: + + /** + * @brief As the name implies + * + * + * prefer not to use names like this outside of testapp + */ + void load_a_bunch_of_stuff(); };