From 59f29806048ec111274404762abfe5e59ae87d7b Mon Sep 17 00:00:00 2001 From: nnicdao Date: Wed, 6 May 2026 00:02:27 -0700 Subject: [PATCH] Remove vehicles, parts, prefabs --- src/adera/activescene/VehicleBuilder.cpp | 285 ---------- src/adera/activescene/VehicleBuilder.h | 233 -------- src/adera/activescene/vehicles_vb_fn.cpp | 205 ------- src/adera/activescene/vehicles_vb_fn.h | 89 --- src/adera/machines/links.cpp | 67 --- src/adera/machines/links.h | 79 --- src/adera_app/feature_interfaces.h | 155 ----- src/adera_app/features/jolt.cpp | 340 +---------- src/adera_app/features/physics.cpp | 166 ------ src/adera_app/features/physics.h | 6 - src/adera_app/features/shapes.cpp | 1 - src/adera_app/features/vehicles.cpp | 564 ------------------- src/adera_app/features/vehicles_machines.cpp | 511 ----------------- src/adera_app/features/vehicles_machines.h | 58 -- src/adera_app/features/vehicles_prebuilt.cpp | 34 +- src/adera_app/features/vehicles_prebuilt.h | 7 +- src/gdextension/flying_scene.cpp | 51 +- src/gdextension/scenarios.cpp | 6 +- src/gdextension/sessions/godot.cpp | 1 - src/osp/activescene/prefab_fn.cpp | 270 --------- src/osp/activescene/prefab_fn.h | 105 ---- src/osp/activescene/vehicles.h | 114 ---- src/osp/drawing/prefab_draw.cpp | 259 --------- src/osp/drawing/prefab_draw.h | 71 --- src/osp/link/machines.cpp | 100 ---- src/osp/link/machines.h | 152 ----- src/osp/link/signal.h | 89 --- src/osp/vehicles/ImporterData.h | 99 ---- src/osp/vehicles/blueprints.h | 137 ----- src/osp/vehicles/load_tinygltf.cpp | 470 ---------------- src/osp/vehicles/load_tinygltf.h | 47 -- src/osp/vehicles/prefabs.h | 50 -- src/testapp/features/magnum.cpp | 1 - src/testapp/main.cpp | 9 +- src/testapp/scenarios.cpp | 41 +- src/testapp/scenarios_magnum.cpp | 24 +- 36 files changed, 35 insertions(+), 4861 deletions(-) delete mode 100644 src/adera/activescene/VehicleBuilder.cpp delete mode 100644 src/adera/activescene/VehicleBuilder.h delete mode 100644 src/adera/activescene/vehicles_vb_fn.cpp delete mode 100644 src/adera/activescene/vehicles_vb_fn.h delete mode 100644 src/adera/machines/links.cpp delete mode 100644 src/adera/machines/links.h delete mode 100644 src/adera_app/features/vehicles.cpp delete mode 100644 src/adera_app/features/vehicles_machines.cpp delete mode 100644 src/adera_app/features/vehicles_machines.h delete mode 100644 src/osp/activescene/prefab_fn.cpp delete mode 100644 src/osp/activescene/prefab_fn.h delete mode 100644 src/osp/activescene/vehicles.h delete mode 100644 src/osp/drawing/prefab_draw.cpp delete mode 100644 src/osp/drawing/prefab_draw.h delete mode 100644 src/osp/link/machines.cpp delete mode 100644 src/osp/link/machines.h delete mode 100644 src/osp/link/signal.h delete mode 100644 src/osp/vehicles/ImporterData.h delete mode 100644 src/osp/vehicles/blueprints.h delete mode 100644 src/osp/vehicles/load_tinygltf.cpp delete mode 100644 src/osp/vehicles/load_tinygltf.h delete mode 100644 src/osp/vehicles/prefabs.h diff --git a/src/adera/activescene/VehicleBuilder.cpp b/src/adera/activescene/VehicleBuilder.cpp deleted file mode 100644 index 66d4bd02..00000000 --- a/src/adera/activescene/VehicleBuilder.cpp +++ /dev/null @@ -1,285 +0,0 @@ -/** - * Open Space Program - * Copyright © 2019-2020 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 "VehicleBuilder.h" - -#include -#include -#include - -namespace adera -{ - -using osp::restypes::gc_importer; - -VehicleBuilder::~VehicleBuilder() -{ - // clear resource owners - for ([[maybe_unused]] auto && [_, value] : std::exchange(m_prefabs, {})) - { - m_pResources->owner_destroy(gc_importer, std::move(value.m_importer)); - } - - for ([[maybe_unused]] auto && rPrefabPair : std::exchange(m_data->m_partPrefabs, {})) - { - m_pResources->owner_destroy(gc_importer, std::move(rPrefabPair.m_importer)); - } -} - -void VehicleBuilder::set_prefabs(std::initializer_list const& setPrefabs) -{ - auto const& endIt = std::end(m_prefabs); - for (SetPrefab const& set : setPrefabs) - { - auto const& foundIt = m_prefabs.find(set.m_prefabName); - if (foundIt != endIt) - { - auto &rPrefabPair = m_data->m_partPrefabs[std::size_t(set.m_part)]; - rPrefabPair.m_prefabId = foundIt->second.m_prefabId; - rPrefabPair.m_importer = m_pResources->owner_create(gc_importer, foundIt->second.m_importer); - } - else - { - OSP_LOG_WARN("Prefab {} not found!", set.m_prefabName); - } - } -} - -WeldId VehicleBuilder::weld(osp::ArrayView toWeld) -{ - WeldId const weld = m_data->m_weldIds.create(); - m_data->m_weldToParts.ids_reserve(m_data->m_weldIds.capacity()); - - PartId *pPartInWeld = m_data->m_weldToParts.emplace(weld, toWeld.size()); - - for (PartToWeld const& set : toWeld) - { - m_data->m_partTransformWeld[set.m_part] = set.m_transform; - - m_data->m_partToWeld[set.m_part] = weld; - (*pPartInWeld) = set.m_part; - std::advance(pPartInWeld, 1); - } - - return weld; -} - -void VehicleBuilder::index_prefabs() -{ - for (unsigned int i = 0; i < m_pResources->ids(gc_importer).capacity(); ++i) - { - auto const resId = osp::ResId(i); - if ( ! m_pResources->ids(gc_importer).exists(resId)) - { - continue; - } - - auto const *pPrefabData = m_pResources->data_try_get(gc_importer, resId); - if (pPrefabData == nullptr) - { - continue; // No prefab data - } - - for (osp::PrefabId j = 0; j < pPrefabData->m_prefabNames.size(); ++j) - { - osp::ResIdOwner_t owner = m_pResources->owner_create(gc_importer, resId); - - m_prefabs.emplace(pPrefabData->m_prefabNames[j], - osp::PrefabPair{std::move(owner), j}); - } - } -} - -osp::link::MachAnyId VehicleBuilder::create_machine(PartId const part, - MachTypeId const machType, - std::initializer_list const& connections) -{ - auto &rData = m_data.value(); - osp::link::PerMachType &rPerMachType = rData.m_machines.perType[machType]; - - MachTypeId const mach = rData.m_machines.ids.create(); - - std::size_t const capacity = rData.m_machines.ids.capacity(); - rData.m_machines.machTypes.resize(capacity); - rData.m_machines.machToLocal.resize(capacity); - rData.m_machToPart.resize(capacity); - for (PerNodeType &rPerNodeType : rData.m_nodePerType) - { - rPerNodeType.machToNode.ids_reserve(capacity); - rPerNodeType.m_machToNodeCustom.ids_reserve(capacity); - } - - MachTypeId const local = rPerMachType.localIds.create(); - rPerMachType.localToAny.resize(rPerMachType.localIds.capacity()); - - rData.m_machines.machTypes[mach] = machType; - rData.m_machines.machToLocal[mach] = local; - rPerMachType.localToAny[local] = mach; - - m_partMachCount[std::size_t(part)] ++; - rData.m_machToPart[mach] = part; - - connect(mach, connections); - - return mach; -} - -void VehicleBuilder::connect(MachAnyId const mach, std::initializer_list const& connections) -{ - // get max port count for each node type - auto &rData = m_data.value(); - std::vector nodePortMax(rData.m_nodePerType.size(), 0); - for (Connection const& connect : connections) - { - int &rPortMax = nodePortMax[connect.m_port.type]; - rPortMax = std::max(rPortMax, connect.m_port.port + 1); - } - - for (NodeTypeId nodeType = 0; std::size_t(nodeType) < rData.m_nodePerType.size(); ++nodeType) - { - int const portMax = nodePortMax[nodeType]; - PerNodeType &rPerNodeType = rData.m_nodePerType[nodeType]; - if (portMax != 0) - { - // reallocate each time :) - rPerNodeType.machToNode.data_reserve(rPerNodeType.machToNode.data_capacity() + portMax); - rPerNodeType.m_machToNodeCustom.data_reserve(rPerNodeType.machToNode.data_capacity() + portMax); - - // emplace and fill with null - rPerNodeType.machToNode.emplace(mach, portMax); - lgrn::Span const portSpan = rPerNodeType.machToNode[mach]; - std::fill(std::begin(portSpan), std::end(portSpan), lgrn::id_null()); - rPerNodeType.m_machToNodeCustom.emplace(mach, portMax); - lgrn::Span const customSpan = rPerNodeType.m_machToNodeCustom[mach]; - std::fill(std::begin(customSpan), std::end(customSpan), 0); - - for (Connection const& connect : connections) - { - if (connect.m_port.type == nodeType) - { - customSpan[connect.m_port.port] = connect.m_port.custom; - portSpan[connect.m_port.port] = connect.m_node; - rPerNodeType.m_nodeConnectCount[connect.m_node] ++; - rPerNodeType.m_connectCountTotal ++; - } - } - } - } -} - -using osp::link::MachLocalId; -using osp::link::Junction; -using osp::link::JuncCustom; - -VehicleData VehicleBuilder::finalize_release() -{ - auto &rData = m_data.value(); - for (NodeTypeId nodeType = 0; std::size_t(nodeType) < rData.m_nodePerType.size(); ++nodeType) - { - PerNodeType &rPerNodeType = rData.m_nodePerType[nodeType]; - - // reserve node-to-machine partitions - rPerNodeType.nodeToMach.data_reserve(rPerNodeType.m_connectCountTotal); - for (NodeId node : rPerNodeType.nodeIds) - { - rPerNodeType.nodeToMach.emplace(node, rPerNodeType.m_nodeConnectCount[node]); - lgrn::Span junction = rPerNodeType.nodeToMach[node]; - std::fill(std::begin(junction), std::end(junction), Junction{}); - } - - // assign node-to-machine - for (MachAnyId const mach : rData.m_machines.ids) - { - lgrn::Span portSpan = rPerNodeType.machToNode[mach]; - lgrn::Span customSpan = rPerNodeType.m_machToNodeCustom[mach]; - - for (int i = 0; i < portSpan.size(); ++i) - { - NodeId node = portSpan[i]; - - if (node == lgrn::id_null()) - { - continue; - } - - lgrn::Span const juncSpan = rPerNodeType.nodeToMach[node]; - - // find empty spot - // should always succeed, as they were reserved a few lines ago - auto found = std::find_if( - std::begin(juncSpan), std::end(juncSpan), - [] (Junction const& pair) - { - return pair.type == lgrn::id_null(); - }); - assert(found != std::end(juncSpan)); - - MachTypeId const type = rData.m_machines.machTypes[mach]; - MachLocalId const local = rData.m_machines.machToLocal[mach]; - - found->local = local; - found->type = type; - found->custom = customSpan[i]; - } - } - } - - // Reserve part-to-machine partitions - using osp::link::MachinePair; - rData.m_partToMachines.ids_reserve(rData.m_partIds.capacity()); - rData.m_partToMachines.data_reserve(rData.m_machines.ids.capacity()); - for (PartId const part : rData.m_partIds) - { - rData.m_partToMachines.emplace(part, m_partMachCount[part]); - } - - // Assign part-to-machine partitions - for (MachAnyId const mach : rData.m_machines.ids) - { - MachLocalId const local = rData.m_machines.machToLocal[mach]; - MachTypeId const type = rData.m_machines.machTypes[mach]; - PartId const part = rData.m_machToPart[mach]; - auto const machines = lgrn::Span{rData.m_partToMachines[part]}; - - // Reuse machine count to track how many are currently added. - // By the end, these should all be zero - auto &rPartMachCount = m_partMachCount[part]; - assert(rPartMachCount != 0); - -- rPartMachCount; - - machines[rPartMachCount] = { .local = local, .type = type }; - } - - assert(std::all_of(m_partMachCount.begin(), m_partMachCount.end(), - [] (auto const& count) - { - return count == 0; - })); - - VehicleData dataOut{std::move(*m_data)}; - m_data.emplace(); - return dataOut; -} - -} // namespace adera diff --git a/src/adera/activescene/VehicleBuilder.h b/src/adera/activescene/VehicleBuilder.h deleted file mode 100644 index 3b893e2f..00000000 --- a/src/adera/activescene/VehicleBuilder.h +++ /dev/null @@ -1,233 +0,0 @@ -/** - * Open Space Program - * Copyright © 2019-2020 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 - -#include -#include - -#include -#include -#include -#include - -namespace adera -{ - -using osp::active::PartId; -using osp::active::WeldId; - - -struct StructureLink -{ - PartId m_greater; - PartId m_less; -}; - -struct PerNodeType : osp::link::Nodes -{ - using MachToNodeCustom_t = lgrn::IntArrayMultiMap; - - MachToNodeCustom_t m_machToNodeCustom; // parallel with m_machToNode - entt::any m_nodeValues; - std::vector m_nodeConnectCount; - int m_connectCountTotal{0}; -}; - -struct VehicleData -{ - using MachToNodeCustom_t = lgrn::IntArrayMultiMap; - using MapPartToMachines_t = osp::active::ACtxParts::MapPartToMachines_t; - - VehicleData() = default; - OSP_MOVE_ONLY_CTOR(VehicleData); - - lgrn::IdRegistryStl m_partIds; - std::vector m_partTransformWeld; - std::vector m_partPrefabs; - std::vector m_partToWeld; - MapPartToMachines_t m_partToMachines; - - lgrn::IdRegistryStl m_weldIds; - lgrn::IntArrayMultiMap m_weldToParts; - - osp::link::Machines m_machines; - std::vector m_machToPart; - - std::vector m_nodePerType; -}; - -/** - * Used to easily create VehicleData - */ -class VehicleBuilder -{ - using MachAnyId = osp::link::MachAnyId; - using MachTypeId = osp::link::MachTypeId; - using NodeId = osp::link::NodeId; - using NodeTypeId = osp::link::NodeTypeId; - using PortEntry = osp::link::PortEntry; - -public: - - struct PartToWeld - { - PartId m_part; - osp::Matrix4 m_transform; - }; - - using WeldVec_t = std::vector; - - VehicleBuilder(osp::Resources *pResources) - : m_pResources{pResources} - { - auto &rData = m_data.emplace(); - rData.m_machines.perType.resize(osp::link::MachTypeReg_t::size()); - rData.m_nodePerType.resize(osp::link::NodeTypeReg_t::size()); - index_prefabs(); - }; - - ~VehicleBuilder(); - - template - [[nodiscard]] std::array create_parts(); - - struct SetPrefab - { - PartId m_part; - std::string_view m_prefabName; - }; - - void set_prefabs(std::initializer_list const& setPrefab); - - - WeldId weld(osp::ArrayView toWeld); - - WeldId weld(std::initializer_list const& toWeld) - { - return weld(osp::arrayView(toWeld)); - } - - osp::Matrix4 align_attach(PartId partA, std::string_view attachA, - PartId partB, std::string_view attachB); - - template - [[nodiscard]] std::array create_nodes(NodeTypeId nodeType); - - template - [[nodiscard]] VALUES_T& node_values(NodeTypeId nodeType); - - std::size_t node_capacity(NodeTypeId nodeType) const - { - return m_data->m_nodePerType[nodeType].nodeIds.capacity(); - } - - struct Connection - { - PortEntry m_port; - NodeId m_node; - }; - - MachAnyId create_machine(PartId part, MachTypeId machType, std::initializer_list const& connections); - - void connect(MachAnyId mach, std::initializer_list const& connections); - - [[nodiscard]] VehicleData finalize_release(); - -private: - - void index_prefabs(); - - osp::Resources *m_pResources; - - entt::dense_map< std::string_view, osp::PrefabPair > m_prefabs; - - std::vector m_partMachCount; - std::optional m_data; - - // put more attachment data here -}; - - -template -std::array VehicleBuilder::create_parts() -{ - std::array out; - m_data->m_partIds.create(std::begin(out), std::end(out)); - - std::size_t const capacity = m_data->m_partIds.capacity(); - m_partMachCount .resize(capacity); - m_data->m_partPrefabs .resize(capacity); - m_data->m_partTransformWeld .resize(capacity); - m_data->m_partToWeld .resize(capacity); - m_data->m_weldToParts .data_reserve(capacity); - - return out; -} - - -template -std::array VehicleBuilder::create_nodes(NodeTypeId const nodeType) -{ - std::array out; - - PerNodeType &rPerNodeType = m_data->m_nodePerType[nodeType]; - - rPerNodeType.nodeIds.create(std::begin(out), std::end(out)); - std::size_t const capacity = rPerNodeType.nodeIds.capacity(); - rPerNodeType.nodeToMach.ids_reserve(rPerNodeType.nodeIds.capacity()); - rPerNodeType.m_nodeConnectCount.resize(capacity, 0); - - return out; -} - -template -VALUES_T& VehicleBuilder::node_values(NodeTypeId nodeType) -{ - PerNodeType &rPerNodeType = m_data->m_nodePerType[nodeType]; - - // Emplace values container if it doesn't exist - if ( ! bool(rPerNodeType.m_nodeValues)) - { - rPerNodeType.m_nodeValues.emplace(); - } - - auto &rValues = entt::any_cast(rPerNodeType.m_nodeValues); - rValues.resize(node_capacity(nodeType)); - - return rValues; -} - -} // namespace adera diff --git a/src/adera/activescene/vehicles_vb_fn.cpp b/src/adera/activescene/vehicles_vb_fn.cpp deleted file mode 100644 index ed31a38b..00000000 --- a/src/adera/activescene/vehicles_vb_fn.cpp +++ /dev/null @@ -1,205 +0,0 @@ -/** - * Open Space Program - * Copyright © 2019-2023 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 "vehicles_vb_fn.h" - -#include - -using namespace osp; -using namespace osp::active; - -namespace adera -{ - -void SysVehicleSpawnVB::create_parts_and_welds(ACtxVehicleSpawn& rVehicleSpawn, ACtxVehicleSpawnVB& rVehicleSpawnVB, ACtxParts& rScnParts) -{ - std::size_t const newVehicleCount = rVehicleSpawn.new_vehicle_count(); - ACtxVehicleSpawnVB &rVSVB = rVehicleSpawnVB; - - rVSVB.remapPartOffsets .resize(newVehicleCount); - rVSVB.remapWeldOffsets .resize(newVehicleCount); - rVehicleSpawn.spawnedPartOffsets .resize(newVehicleCount); - rVehicleSpawn.spawnedWeldOffsets .resize(newVehicleCount); - - // Count total parts and welds, and calculate offsets for remaps - - uint32_t partTotal = 0; - uint32_t remapPartTotal = 0; - - uint32_t weldTotal = 0; - uint32_t remapWeldTotal = 0; - - for (uint32_t spVhInt = 0; spVhInt < newVehicleCount; ++spVhInt) - { - auto const spVhId = SpVehicleId{spVhInt}; - VehicleData const* pVData = rVSVB.dataVB[spVhId]; - if (pVData == nullptr) - { - continue; - } - - rVehicleSpawn.spawnedPartOffsets[spVhId] = SpPartId{partTotal}; - partTotal += pVData->m_partIds.size(); - - rVSVB.remapPartOffsets[spVhId] = remapPartTotal; - remapPartTotal += pVData->m_partIds.capacity(); - - rVehicleSpawn.spawnedWeldOffsets[spVhId] = SpWeldId{weldTotal}; - weldTotal += pVData->m_weldIds.size(); - - rVSVB.remapWeldOffsets[spVhId] = remapWeldTotal; - remapWeldTotal += pVData->m_weldIds.capacity(); - } - - // Resize containers for new IDs - - rVehicleSpawn.spawnedParts .resize(partTotal); - rVehicleSpawn.spawnedWelds .resize(weldTotal); - rVehicleSpawn.spawnedPrefabs .resize(partTotal); - rVSVB.remapParts .resize(remapPartTotal, lgrn::id_null()); - rVSVB.remapWelds .resize(remapPartTotal, lgrn::id_null()); - - // Create new Scene PartIds and WeldIds - - rScnParts.partIds.create(rVehicleSpawn.spawnedParts.begin(), rVehicleSpawn.spawnedParts.end()); - rScnParts.weldIds.create(rVehicleSpawn.spawnedWelds.begin(), rVehicleSpawn.spawnedWelds.end()); - - rScnParts.partDirty.insert(rScnParts.partDirty.begin(), rVehicleSpawn.spawnedParts.begin(), rVehicleSpawn.spawnedParts.end()); - rScnParts.weldDirty.insert(rScnParts.weldDirty.begin(), rVehicleSpawn.spawnedWelds.begin(), rVehicleSpawn.spawnedWelds.end()); - - // Resize scene containers to account for new IDs - - std::size_t const maxParts = rScnParts.partIds.capacity(); - std::size_t const maxWelds = rScnParts.weldIds.capacity(); - rScnParts.partTransformWeld .resize(maxParts); - rScnParts.partToWeld .resize(maxParts); - rScnParts.weldToParts .data_reserve(maxParts); - rScnParts.weldToParts .ids_reserve(maxWelds); - rScnParts.weldToActive .resize(maxWelds); - rVehicleSpawn.partToSpawned .resize(maxParts); - - // Populate "Scene PartId -> NewPartId" map - for (uint32_t spPartInt = 0; spPartInt < rVehicleSpawn.spawnedParts.size(); ++spPartInt) - { - auto const spPart = SpPartId{spPartInt}; - rVehicleSpawn.partToSpawned[rVehicleSpawn.spawnedParts[spPart]] = spPart; - } - - // Populate remap vectors and set weld connections - - auto itDstPartIds = rVehicleSpawn.spawnedParts.cbegin(); - auto itDstWeldIds = rVehicleSpawn.spawnedWelds.cbegin(); - - for (uint32_t spVhInt = 0; spVhInt < newVehicleCount; ++spVhInt) - { - auto const spVhId = SpVehicleId{spVhInt}; - - VehicleData const* pVData = rVSVB.dataVB[spVhId]; - if (pVData == nullptr) - { - continue; - } - - std::size_t const remapPartOffset = rVSVB.remapPartOffsets[spVhId]; - std::size_t const remapWeldOffset = rVSVB.remapWeldOffsets[spVhId]; - - for (PartId const srcPart : pVData->m_partIds) - { - PartId const dstPart = *itDstPartIds; - ++itDstPartIds; - - // Populate map for "VehicleBuilder PartId -> ACtxParts PartId" - rVSVB.remapParts[remapPartOffset + srcPart] = dstPart; - } - - for (WeldId const srcWeld : pVData->m_weldIds) - { - WeldId const dstWeld = *itDstWeldIds; - ++itDstWeldIds; - - // Populate map for "VehicleBuilder WeldId -> ACtxParts WeldId" - // rVehicleSpawnVB.remapWelds - rVSVB.remapWelds[remapWeldOffset + srcWeld] = dstWeld; - - // Use remaps to connect ACtxParts WeldIds and PartIds - // rScnParts.m_partToWeld and rScnParts.m_weldToParts - - auto const srcWeldPartSpan = pVData->m_weldToParts[srcWeld]; - WeldId *pDstWeldPartOut = rScnParts.weldToParts.emplace(dstWeld, srcWeldPartSpan.size()); - - for (PartId const srcPart : srcWeldPartSpan) - { - PartId const dstPart = rVSVB.remapParts[remapPartOffset + srcPart]; - - (*pDstWeldPartOut) = dstPart; - std::advance(pDstWeldPartOut, 1); - - rScnParts.partToWeld[dstPart] = dstWeld; - } - } - } -} - - -void SysVehicleSpawnVB::request_prefabs(ACtxVehicleSpawn& rVehicleSpawn, ACtxVehicleSpawnVB const& rVehicleSpawnVB, ACtxParts& rScnParts, ACtxPrefabs& rPrefabs, Resources& rResources) -{ - std::size_t const newVehicleCount = rVehicleSpawn.new_vehicle_count(); - - auto itDstPartIds = rVehicleSpawn.spawnedParts.cbegin(); - auto itPrefabOut = rVehicleSpawn.spawnedPrefabs.begin(); - - for (uint32_t spVhInt = 0; spVhInt < newVehicleCount; ++spVhInt) - { - auto const spVhId = SpVehicleId{spVhInt}; - - VehicleData const* pVData = rVehicleSpawnVB.dataVB[spVhId]; - if (pVData == nullptr) - { - continue; - } - - // Copy Part data from VehicleBuilder to scene - for (uint32_t srcPart : pVData->m_partIds) - { - PartId const dstPart = *itDstPartIds; - ++itDstPartIds; - - PrefabPair const& prefabPairSrc = pVData->m_partPrefabs[srcPart]; - rScnParts.partTransformWeld[dstPart] = pVData->m_partTransformWeld[srcPart]; - - // Add Prefab and Part init events - (*itPrefabOut) = rPrefabs.spawnRequest.size(); - ++itPrefabOut; - - rPrefabs.spawnRequest.push_back(TmpPrefabRequest{ - .m_importerRes = prefabPairSrc.m_importer, - .m_prefabId = prefabPairSrc.m_prefabId, - .m_pTransform = &pVData->m_partTransformWeld[srcPart] - }); - } - } -} - - -} // namespace adera diff --git a/src/adera/activescene/vehicles_vb_fn.h b/src/adera/activescene/vehicles_vb_fn.h deleted file mode 100644 index 1f2efbe2..00000000 --- a/src/adera/activescene/vehicles_vb_fn.h +++ /dev/null @@ -1,89 +0,0 @@ -/** - * Open Space Program - * Copyright © 2019-2023 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 "VehicleBuilder.h" - -#include -#include - -namespace adera -{ - -struct ACtxVehicleSpawnVB -{ - using SpVehicleId = osp::active::SpVehicleId; - - // Remap vectors convert IDs from VehicleData to ACtxParts. - // A single vector for remaps is shared for all vehicles to spawn, - // so offsets are used to divide up the vector. - - // PartId srcPart = /* ID from VehicleData */ - // PartId dstPart = remapParts[remapPartOffsets[newVehicleIndex] + srcPart]; - - inline Corrade::Containers::StridedArrayView2D remap_node_offsets_2d() noexcept - { - return {Corrade::Containers::arrayView(remapNodeOffsets.data(), remapNodeOffsets.size()), - {dataVB.size(), osp::link::NodeTypeReg_t::size()}}; - } - - inline Corrade::Containers::StridedArrayView2D remap_node_offsets_2d() const noexcept - { - return {Corrade::Containers::arrayView(remapNodeOffsets.data(), remapNodeOffsets.size()), - {dataVB.size(), osp::link::NodeTypeReg_t::size()}}; - } - - osp::KeyedVec dataVB; - - std::vector remapParts; - osp::KeyedVec remapPartOffsets; - - std::vector remapWelds; - osp::KeyedVec remapWeldOffsets; - - std::vector machtypeCount; - std::vector remapMachs; - osp::KeyedVec remapMachOffsets; - - // remapNodes are both shared between all new vehicles and all node types - // An offset can exist for each pair of [New Vehicle, Node Type] - std::vector remapNodes; - osp::KeyedVec remapNodeOffsets; -}; - -class SysVehicleSpawnVB -{ - using ACtxParts = osp::active::ACtxParts; - using ACtxPrefabs = osp::active::ACtxPrefabs; - using ACtxVehicleSpawn = osp::active::ACtxVehicleSpawn; - using Resources = osp::Resources; -public: - static void create_parts_and_welds(ACtxVehicleSpawn& rVehicleSpawn, ACtxVehicleSpawnVB& rVehicleSpawnVB, ACtxParts& rScnParts); - - static void request_prefabs(ACtxVehicleSpawn& rVehicleSpawn, ACtxVehicleSpawnVB const& rVehicleSpawnVB, ACtxParts& rScnParts, ACtxPrefabs& rPrefabs, Resources& rResources); -}; - - -} // namespace adera diff --git a/src/adera/machines/links.cpp b/src/adera/machines/links.cpp deleted file mode 100644 index eb5fd6e2..00000000 --- a/src/adera/machines/links.cpp +++ /dev/null @@ -1,67 +0,0 @@ -/** - * Open Space Program - * Copyright © 2019-2023 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 "links.h" - -using namespace osp; - -using osp::link::MachTypeReg_t; -using osp::link::MachTypeId; - -namespace adera -{ - -float thruster_influence(Vector3 const pos, Vector3 const dir, Vector3 const cmdLin, Vector3 const cmdAng) noexcept -{ - using Magnum::Math::cross; - using Magnum::Math::dot; - - float influence = 0.0f; - - if (cmdAng.dot() > 0.0f) - { - Vector3 const torque = cross(pos, dir).normalized(); - influence += dot(torque, cmdAng.normalized()); - } - - if (cmdLin.dot() > 0.0f) - { - influence += dot(dir, cmdLin.normalized()); - } - - if (influence < 0.01f) - { - return 0.0f; // Ignore small contributions - } - - if (Magnum::Math::isNan(influence)) - { - return 0.0f; - } - - return std::clamp(influence, 0.0f, 1.0f); -} - - -} // namespace adera diff --git a/src/adera/machines/links.h b/src/adera/machines/links.h deleted file mode 100644 index 557c0020..00000000 --- a/src/adera/machines/links.h +++ /dev/null @@ -1,79 +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. - */ -#pragma once - -#include - -#include -#include - -namespace adera -{ - -using osp::link::PortEntry; -using osp::link::gc_ntSigFloat; -using osp::link::gc_sigIn; -using osp::link::gc_sigOut; - -inline osp::link::MachTypeId const gc_mtUserCtrl = osp::link::MachTypeReg_t::create(); -inline osp::link::MachTypeId const gc_mtMagicRocket = osp::link::MachTypeReg_t::create(); -inline osp::link::MachTypeId const gc_mtRcsDriver = osp::link::MachTypeReg_t::create(); - -constexpr osp::Vector3 gc_rocketForward{0.0f, 0.0f, 1.0f}; - -namespace ports_userctrl -{ -PortEntry const gc_throttleOut { gc_ntSigFloat, 0, gc_sigOut }; -PortEntry const gc_pitchOut { gc_ntSigFloat, 1, gc_sigOut }; -PortEntry const gc_yawOut { gc_ntSigFloat, 2, gc_sigOut }; -PortEntry const gc_rollOut { gc_ntSigFloat, 3, gc_sigOut }; -} - -namespace ports_magicrocket -{ -PortEntry const gc_throttleIn { gc_ntSigFloat, 0, gc_sigIn }; -PortEntry const gc_multiplierIn { gc_ntSigFloat, 1, gc_sigIn }; -} - -namespace ports_rcsdriver -{ -PortEntry const gc_posXIn { gc_ntSigFloat, 0, gc_sigIn }; -PortEntry const gc_posYIn { gc_ntSigFloat, 1, gc_sigIn }; -PortEntry const gc_posZIn { gc_ntSigFloat, 2, gc_sigIn }; -PortEntry const gc_dirXIn { gc_ntSigFloat, 3, gc_sigIn }; -PortEntry const gc_dirYIn { gc_ntSigFloat, 4, gc_sigIn }; -PortEntry const gc_dirZIn { gc_ntSigFloat, 5, gc_sigIn }; -PortEntry const gc_cmdLinXIn { gc_ntSigFloat, 6, gc_sigIn }; -PortEntry const gc_cmdLinYIn { gc_ntSigFloat, 7, gc_sigIn }; -PortEntry const gc_cmdLinZIn { gc_ntSigFloat, 8, gc_sigIn }; -PortEntry const gc_cmdAngXIn { gc_ntSigFloat, 9, gc_sigIn }; -PortEntry const gc_cmdAngYIn { gc_ntSigFloat, 10, gc_sigIn }; -PortEntry const gc_cmdAngZIn { gc_ntSigFloat, 11, gc_sigIn }; -PortEntry const gc_throttleOut { gc_ntSigFloat, 12, gc_sigOut }; -} - -float thruster_influence(osp::Vector3 pos, osp::Vector3 dir, osp::Vector3 cmdLin, osp::Vector3 cmdAng) noexcept; - -} // namespace adera diff --git a/src/adera_app/feature_interfaces.h b/src/adera_app/feature_interfaces.h index 2e67c203..ad16f334 100644 --- a/src/adera_app/feature_interfaces.h +++ b/src/adera_app/feature_interfaces.h @@ -160,40 +160,6 @@ inline osp::PipelineTypeInfo const gc_infoForEStgFBO }; -enum class EStgLink -{ - ScheduleLink, - NodeUpd, - MachUpd -}; -inline osp::PipelineTypeInfo const gc_infoForEStgLink -{ - .debugName = "osp::link Nested update loop", - .stages = {{ - { .name = "ScheduleLink", .isSchedule = true}, - { .name = "NodeUpd", .useCancel = true }, - { .name = "MachUpd", .useCancel = true } - }}, - .initialStage = osp::StageId{0} -}; - -enum class EStgLinkValue : uint8_t -{ - ExternalIn = 0, - LoopRunning = 1, - LoopDone = 2 -}; -inline osp::PipelineTypeInfo const gc_infoForEStgLinkValue -{ - .debugName = "EStgLinkValue", - .stages = {{ - { .name = "ExternalIn", }, - { .name = "LoopRunning", }, - { .name = "LoopDone", } - }}, - .initialStage = osp::StageId{0 /* ExternalIn */} -}; - namespace stages { using enum EStgOptn; @@ -201,8 +167,6 @@ namespace stages using enum EStgIntr; using enum EStgEvnt; using enum EStgFBO; - using enum EStgLink; - using enum EStgLinkValue; } // namespace stages inline void register_stage_enums() @@ -213,8 +177,6 @@ inline void register_stage_enums() rPltypeReg.assign_pltype_info(gc_infoForEStgIntr); rPltypeReg.assign_pltype_info(gc_infoForEStgCont); rPltypeReg.assign_pltype_info (gc_infoForEStgFBO); - rPltypeReg.assign_pltype_info(gc_infoForEStgLink); - rPltypeReg.assign_pltype_info(gc_infoForEStgLinkValue); } @@ -383,32 +345,6 @@ struct FIDroppers { }; -struct FIPrefabs { - struct DataIds { - DataId prefabs; - }; - - struct Pipelines { - PipelineDef spawnRequest {"spawnRequest"}; - PipelineDef spawnedEnts {"spawnedEnts"}; - PipelineDef ownedEnts {"ownedEnts"}; - - PipelineDef instanceInfo {"instanceInfo"}; - - PipelineDef inSubtree {"inSubtree"}; - }; -}; - - -struct FIPrefabDraw { - struct DataIds { - DataId material; - }; - - struct Pipelines { }; -}; - - struct FIBounds { struct DataIds { DataId bounds; @@ -421,85 +357,6 @@ struct FIBounds { }; -struct FILinks { - - struct LoopBlockIds { - LoopBlockId link; - }; - - struct DataIds { - DataId links; - DataId updMach; - }; - - struct Pipelines { - PipelineDef requestMachUpdExt {"requestMachUpdExt"}; - PipelineDef requestMachUpdLoop{"requestMachUpdLoop"}; - PipelineDef linkLoopExt {"linkLoopExt"}; - PipelineDef linkLoop {"linkLoop"}; - - PipelineDef machIds {"machIds"}; - PipelineDef nodeIds {"nodeIds"}; - PipelineDef connect {"connect"}; - }; -}; - - -struct FIParts { - - - struct DataIds { - DataId scnParts; - }; - - struct Pipelines { - 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 mapWeldPart {"mapPartWeld - ACtxParts::weldToParts/partToWeld"}; - PipelineDef mapPartMach {"mapPartMach - ACtxParts::partToMachines/machineToPart"}; - PipelineDef mapPartActive {"mapPartActive - ACtxParts::partToActive/activeToPart"}; - PipelineDef mapWeldActive {"mapWeldActive - ACtxParts::weldToActive"}; - - - }; -}; - - -struct FIVehicleSpawn { - struct DataIds { - DataId vehicleSpawn; - }; - - struct Pipelines { - 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"}; - }; -}; - - -struct FIVehicleSpawnVB { - struct DataIds { - DataId vehicleSpawnVB; - }; - - struct Pipelines { - 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*"}; - }; -}; - struct FITestVehicles { struct DataIds { DataId prebuiltVehicles; @@ -509,18 +366,6 @@ struct FITestVehicles { }; -struct FISignalsFloat { - struct DataIds { - DataId sigValFloat; - DataId sigUpdFloat; - }; - - struct Pipelines { - PipelineDef sigValFloatExt {"sigValFloatExt"}; ///< sigValFloat outside link loop - PipelineDef sigValFloatLoop {"sigValFloatLoop"}; ///< sigValFloat internal to link loop - }; -}; - struct FITerrain { struct DataIds { DataId terrainFrame; diff --git a/src/adera_app/features/jolt.cpp b/src/adera_app/features/jolt.cpp index 4ebb64a9..f8617b63 100644 --- a/src/adera_app/features/jolt.cpp +++ b/src/adera_app/features/jolt.cpp @@ -29,13 +29,8 @@ #include #include -#include -#include #include #include -#include - -#include #include @@ -48,7 +43,6 @@ using namespace ftr_inter::stages; using namespace ftr_inter; using namespace osp::active; using namespace osp::fw; -using namespace osp::link; using namespace osp; using namespace ospjolt; @@ -56,7 +50,6 @@ using namespace ospjolt; using ospjolt::ACtxJoltWorld; using Corrade::Containers::arrayView; -using osp::restypes::gc_importer; namespace adera { @@ -287,341 +280,14 @@ void compound_collect_recurse( } // void compound_collect_recurse -FeatureDef const ftrVehicleSpawnJolt = feature_def("VehicleSpawnJolt", [] ( - FeatureBuilder &rFB, - Implement vhclSpawnJolt, - DependOn mainApp, - DependOn comScn, - DependOn phys, - DependOn physShapes, - DependOn prefabs, - DependOn parts, - DependOn jolt, - DependOn vhclSpawn) -{ - rFB.data_emplace(vhclSpawnJolt.di.factors); - - rFB.task() - .name ("Create root ActiveEnts for each Weld") - .sync_with ({vhclSpawn.pl.spawnRequest(UseOrRun), comScn.pl.activeEnt(New), parts.pl.mapWeldActive(New), vhclSpawn.pl.rootEnts(Resize)}) - .args ({ comScn.di.basic, vhclSpawn.di.vehicleSpawn, parts.di.scnParts}) - .func ([] (ACtxBasic& rBasic, ACtxVehicleSpawn& rVehicleSpawn, ACtxParts& rScnParts) noexcept - { - LGRN_ASSERT(rVehicleSpawn.new_vehicle_count() != 0); - - rVehicleSpawn.rootEnts.resize(rVehicleSpawn.spawnedWelds.size()); - rBasic.m_activeIds.create(rVehicleSpawn.rootEnts.begin(), rVehicleSpawn.rootEnts.end()); - - // update WeldId->ActiveEnt mapping - auto itWeldEnt = rVehicleSpawn.rootEnts.begin(); - for (WeldId const weld : rVehicleSpawn.spawnedWelds) - { - rScnParts.weldToActive[weld] = *itWeldEnt; - ++itWeldEnt; - } - }); - - - rFB.task() - .name ("Add vehicle entities to Scene Graph") - .sync_with ({vhclSpawn.pl.spawnRequest(UseOrRun), vhclSpawn.pl.rootEnts(UseOrRun), - parts.pl.mapWeldActive(Ready), - prefabs.pl.spawnedEnts(UseOrRun), prefabs.pl.spawnRequest(UseOrRun), prefabs.pl.inSubtree(Run), - comScn.pl.transform(New), comScn.pl.hierarchy(New)}) - .args ({ comScn.di.basic, vhclSpawn.di.vehicleSpawn, parts.di.scnParts, prefabs.di.prefabs, mainApp.di.resources}) - .func ([] (ACtxBasic& rBasic, ACtxVehicleSpawn const& rVehicleSpawn, ACtxParts& rScnParts, ACtxPrefabs& rPrefabs, Resources& rResources) noexcept - { - LGRN_ASSERT(rVehicleSpawn.new_vehicle_count() != 0); - - // ActiveEnts created for welds + ActiveEnts created for vehicle prefabs - std::size_t const totalEnts = rVehicleSpawn.rootEnts.size() + rPrefabs.newEnts.size(); - - auto const& itWeldsFirst = rVehicleSpawn.spawnedWelds.begin(); - auto const& itWeldOffsetsLast = rVehicleSpawn.spawnedWeldOffsets.end(); - auto itWeldOffsets = rVehicleSpawn.spawnedWeldOffsets.begin(); - - rBasic.m_scnGraph.resize(rBasic.m_activeIds.capacity()); - - for (ACtxVehicleSpawn::TmpToInit const& toInit : rVehicleSpawn.spawnRequest) - { - auto const itWeldOffsetsNext = std::next(itWeldOffsets); - SpWeldId const weldOffsetNext = (itWeldOffsetsNext != itWeldOffsetsLast) - ? (*itWeldOffsetsNext) - : SpWeldId(uint32_t(rVehicleSpawn.spawnedWelds.size())); - - std::for_each(itWeldsFirst + std::ptrdiff_t{*itWeldOffsets}, - itWeldsFirst + std::ptrdiff_t{weldOffsetNext}, - [&rBasic, &rScnParts, &rVehicleSpawn, &rPrefabs, &rResources, &toInit] (WeldId const weld) - { - // Count parts in this weld first - std::size_t entCount = 0; - for (PartId const part : rScnParts.weldToParts[weld]) - { - SpPartId const newPart = rVehicleSpawn.partToSpawned[part]; - uint32_t const prefabInit = rVehicleSpawn.spawnedPrefabs[newPart]; - entCount += rPrefabs.spawnedEntsOffset[prefabInit].size(); - } - - ActiveEnt const weldEnt = rScnParts.weldToActive[weld]; - - rBasic.m_transform.emplace(weldEnt, Matrix4::from(toInit.rotation.toMatrix(), toInit.position)); - - SubtreeBuilder bldRoot = SysSceneGraph::add_descendants(rBasic.m_scnGraph, entCount + 1); - SubtreeBuilder bldWeld = bldRoot.add_child(weldEnt, entCount); - - for (PartId const part : rScnParts.weldToParts[weld]) - { - SpPartId const newPart = rVehicleSpawn.partToSpawned[part]; - uint32_t const prefabInit = rVehicleSpawn.spawnedPrefabs[newPart]; - auto const& basic = rPrefabs.spawnRequest[prefabInit]; - auto const& ents = rPrefabs.spawnedEntsOffset[prefabInit]; - - SysPrefabInit::add_to_subtree(basic, ents, rResources, bldWeld); - } - }); - - itWeldOffsets = itWeldOffsetsNext; - } - }); - - - rFB.task() - .name ("Add Jolt physics to Weld entities") - .sync_with ({vhclSpawn.pl.spawnRequest(UseOrRun), vhclSpawn.pl.rootEnts(UseOrRun), prefabs.pl.spawnedEnts(UseOrRun), comScn.pl.transform(Ready), phys.pl.mass(Ready), jolt.pl.joltBody(New), comScn.pl.hierarchy(Ready)}) - .args ({ comScn.di.basic, phys.di.phys, jolt.di.jolt, vhclSpawn.di.vehicleSpawn, parts.di.scnParts, vhclSpawnJolt.di.factors}) - .func ([] (ACtxBasic const& rBasic, ACtxPhysics& rPhys, ACtxJoltWorld& rJolt, ACtxVehicleSpawn const& rVehicleSpawn, ACtxParts const& rScnParts, ForceFactors_t const factors) noexcept - { - LGRN_ASSERT(rVehicleSpawn.new_vehicle_count() != 0); - - rPhys.m_hasColliders.resize(rBasic.m_activeIds.capacity()); - - auto const& itWeldsFirst = std::begin(rVehicleSpawn.spawnedWelds); - auto const& itWeldOffsetsLast = std::end(rVehicleSpawn.spawnedWeldOffsets); - auto itWeldOffsets = std::begin(rVehicleSpawn.spawnedWeldOffsets); - - JPH::BodyInterface &bodyInterface = rJolt.m_physicsSystem.GetBodyInterface(); - - std::vector addedBodies; - - for (ACtxVehicleSpawn::TmpToInit const& toInit : rVehicleSpawn.spawnRequest) - { - auto const itWeldOffsetsNext = std::next(itWeldOffsets); - SpWeldId const weldOffsetNext = (itWeldOffsetsNext != itWeldOffsetsLast) - ? (*itWeldOffsetsNext) - : SpWeldId(uint32_t(rVehicleSpawn.spawnedWelds.size())); - - std::for_each(itWeldsFirst + std::ptrdiff_t{*itWeldOffsets}, - itWeldsFirst + std::ptrdiff_t{weldOffsetNext}, - [&rBasic, &rScnParts, &rVehicleSpawn, &toInit, &rPhys, &rJolt, &addedBodies, factors] (WeldId const weld) - { - ActiveEnt const weldEnt = rScnParts.weldToActive[weld]; - - JPH::MutableCompoundShapeSettings compound; - - rPhys.m_hasColliders.insert(weldEnt); - - // Collect all colliders from hierarchy. - compound_collect_recurse( rPhys, rJolt, rBasic, weldEnt, Matrix4{}, compound ); - - JPH::Ref compoundShape = compound.Create().Get(); - JPH::BodyCreationSettings bodyCreation(compoundShape, JPH::Vec3Arg::sZero(), JPH::Quat::sZero(), JPH::EMotionType::Dynamic, Layers::MOVING); - bodyCreation.mMaxLinearVelocity = 65536.0f; - - BodyId const bodyId = rJolt.m_bodyIds.create(); - - rJolt.m_bodyUseOriginTranslate.resize(rJolt.m_bodyIds.capacity()); - rJolt.m_bodyUseOriginTranslate.emplace(bodyId); - - rJolt.m_bodyToEnt[bodyId] = weldEnt; - rJolt.m_bodyFactors[bodyId] = factors; - rJolt.m_entToBody.emplace(weldEnt, bodyId); - - float totalMass = 0.0f; - Vector3 massPos{0.0f}; - SysPhysics::calculate_subtree_mass_center(rBasic.m_transform, rPhys, rBasic.m_scnGraph, weldEnt, massPos, totalMass); - - Vector3 const com = massPos / totalMass; - auto const comToOrigin = Matrix4::translation( - com ); - - Matrix3 inertiaTensor{0.0f}; - SysPhysics::calculate_subtree_mass_inertia(rBasic.m_transform, rPhys, rBasic.m_scnGraph, weldEnt, inertiaTensor, comToOrigin); - - Matrix4 const inertiaTensorMat4{inertiaTensor}; - - JPH::MassProperties massProp; - massProp.mMass = totalMass; - massProp.mInertia = JPH::Mat44::sLoadFloat4x4((JPH::Float4*) inertiaTensorMat4.data()); - - bodyCreation.mMassPropertiesOverride = massProp; - bodyCreation.mOverrideMassProperties = JPH::EOverrideMassProperties::MassAndInertiaProvided; - - bodyCreation.mLinearDamping = 0.0f; - - // TODO: temporary, suppose to be zero. This makes it easier to steer - bodyCreation.mAngularDamping = 0.8f; - - bodyCreation.mPosition = Vec3MagnumToJolt(toInit.position); - - auto rawQuat = toInit.rotation.data(); - JPH::Quat joltRotation(rawQuat[0], rawQuat[1], rawQuat[2], rawQuat[3]); - - bodyCreation.mRotation = joltRotation; - - JPH::BodyInterface &bodyInterface = rJolt.m_physicsSystem.GetBodyInterface(); - JPH::BodyID joltBodyId = BToJolt(bodyId); - bodyInterface.CreateBodyWithID(joltBodyId, bodyCreation); - addedBodies.push_back(joltBodyId); - rPhys.m_setVelocity.emplace_back(weldEnt, toInit.velocity); - }); - - itWeldOffsets = itWeldOffsetsNext; - } - //Bodies are added all at once for performance reasons. - int numBodies = static_cast(addedBodies.size()); - JPH::BodyInterface::AddState addState = bodyInterface.AddBodiesPrepare(addedBodies.data(), numBodies); - bodyInterface.AddBodiesFinalize(addedBodies.data(), numBodies, addState, JPH::EActivation::Activate); - }); -}); // ftrVehicleSpawnJolt - - -void set_vehicle_default_factors( - ForceFactors_t factors, - osp::fw::Framework &rFW, - osp::fw::ContextId sceneCtx) -{ - rFW.data_get( - rFW.get_interface(sceneCtx).di.factors) = factors; -} - -struct BodyRocket -{ - Quaternion m_rotation; - Vector3 m_offset; - - MachLocalId m_local {lgrn::id_null()}; - NodeId m_throttleIn {lgrn::id_null()}; - NodeId m_multiplierIn {lgrn::id_null()}; -}; - struct ACtxRocketsJolt { // map each bodyId to a {machine, offset} //TODO: make an IdMultiMap or something. - lgrn::IntArrayMultiMap m_bodyRockets; std::uint8_t factorIndex; }; -/** - * @brief Search for Rockets in a newly added vehicle rigid body (a Weld), calculate offset and - * rotation, then assign the right force factors to them. - */ -static void assign_weld_rockets( - WeldId const weld, - ACtxBasic const &rBasic, - ACtxParts const &rScnParts, - ACtxJoltWorld &rJolt, - ACtxRocketsJolt &rRocketsJolt, - Nodes const &rFloatNodes, - PerMachType const &machtypeRocket, - std::vector &rRocketsFoundTemp) -{ - using adera::gc_mtMagicRocket; - using adera::ports_magicrocket::gc_throttleIn; - using adera::ports_magicrocket::gc_multiplierIn; - - rRocketsFoundTemp.clear(); - - ActiveEnt const weldEnt = rScnParts.weldToActive[weld]; - BodyId const body = rJolt.m_entToBody.at(weldEnt); - - if (rRocketsJolt.m_bodyRockets.contains(body.value)) - { - rRocketsJolt.m_bodyRockets.erase(body.value); - } - - // Each weld consists of multiple parts, iterate them all. Note that each part has their own - // individual transforms, so math is needed to calculate stuff with thrust direction and - // center-of-mass. - for (PartId const part : rScnParts.weldToParts[weld]) - { - auto const sizeBefore = rRocketsFoundTemp.size(); - - // Each part contains Machines, some of which may be rockets. - for (MachinePair const pair : rScnParts.partToMachines[part]) - { - if (pair.type != gc_mtMagicRocket) - { - continue; // This machine is not a rocket - } - - MachAnyId const mach = machtypeRocket.localToAny[pair.local]; - auto const& portSpan = rFloatNodes.machToNode[mach]; - NodeId const throttleIn = connected_node(portSpan, gc_throttleIn.port); - NodeId const multiplierIn = connected_node(portSpan, gc_multiplierIn.port); - - if ( (throttleIn == lgrn::id_null()) - || (multiplierIn == lgrn::id_null()) ) - { - continue; // Throttle and/or multiplier is not connected - } - - BodyRocket &rBodyRocket = rRocketsFoundTemp.emplace_back(); - rBodyRocket.m_local = pair.local; - rBodyRocket.m_throttleIn = throttleIn; - rBodyRocket.m_multiplierIn = multiplierIn; - } - - auto const rocketsFoundForPart = arrayView(rRocketsFoundTemp).exceptPrefix(sizeBefore); - - if (rocketsFoundForPart.isEmpty()) - { - continue; // No rockets found on this part - } - - // calculate transform relative to body root - // start from part, then walk parents up - ActiveEnt const partEnt = rScnParts.partToActive[part]; - - Matrix4 transform = rBasic.m_transform.get(partEnt).m_transform; - ActiveEnt parent = rBasic.m_scnGraph.m_entParent[partEnt]; - - while (parent != weldEnt) - { - Matrix4 const& parentTransform = rBasic.m_transform.get(parent).m_transform; - transform = parentTransform * transform; - parent = rBasic.m_scnGraph.m_entParent[parent]; - } - - auto const rotation = Quaternion::fromMatrix(transform.rotation()); - Vector3 const offset = transform.translation(); - - for (BodyRocket &rBodyRocket : rocketsFoundForPart) - { - rBodyRocket.m_rotation = rotation; - rBodyRocket.m_offset = offset; - } - } - - ForceFactors_t &rBodyFactors = rJolt.m_bodyFactors[body]; - - if ( rRocketsFoundTemp.empty() ) - { - rBodyFactors.reset(rRocketsJolt.factorIndex); - } - else - { - rBodyFactors.set(rRocketsJolt.factorIndex); - rRocketsJolt.m_bodyRockets.emplace(body.value, rRocketsFoundTemp.begin(), rRocketsFoundTemp.end()); - } -} - -struct RocketThrustUserData -{ - ACtxRocketsJolt const &rRocketsJolt; - Machines const &rMachines; - SignalValues_t const &rSigValFloat; -}; - +/* // ACtxjoltWorld::ForceFactorFunc::Func_t static void rocket_thrust_force(BodyId const bodyId, ACtxJoltWorld const& rJolt, entt::any userData, Vector3& rForce, Vector3& rTorque) noexcept { @@ -669,6 +335,7 @@ static void rocket_thrust_force(BodyId const bodyId, ACtxJoltWorld const& rJolt, } } + FeatureDef const ftrRocketThrustJolt = feature_def("RocketThrustJolt", [] ( FeatureBuilder &rFB, Implement rktJolt, @@ -686,6 +353,7 @@ FeatureDef const ftrRocketThrustJolt = feature_def("RocketThrustJolt", [] ( { auto &rRocketsJolt = rFB.data_emplace< ACtxRocketsJolt >(rktJolt.di.rocketsJolt); + rFB.task() .name ("Assign rockets to Jolt bodies") .sync_with ({parts.pl.weldIds(Ready), jolt.pl.joltBody(Ready), links.pl.connect(Ready)}) @@ -725,7 +393,9 @@ FeatureDef const ftrRocketThrustJolt = feature_def("RocketThrustJolt", [] ( rJolt.m_factors.emplace_back(factor); rRocketsJolt.factorIndex = static_cast(index); + }); // ftrRocketThrustJolt +*/ struct ACtxTerrainJolt { diff --git a/src/adera_app/features/physics.cpp b/src/adera_app/features/physics.cpp index 19999fee..ed7420f9 100644 --- a/src/adera_app/features/physics.cpp +++ b/src/adera_app/features/physics.cpp @@ -28,10 +28,7 @@ #include #include -#include #include -#include -#include #include #include @@ -71,167 +68,4 @@ FeatureDef const ftrPhysics = feature_def("Physics", [] ( }); // ftrPhysics -//----------------------------------------------------------------------------- - - -FeatureDef const ftrPrefabs = feature_def("Prefabs", [] ( - FeatureBuilder &rFB, - Implement prefabs, - DependOn mainApp, - DependOn scn, - DependOn comScn, - DependOn phys) -{ - rFB.pipeline(prefabs.pl.spawnRequest).parent(mainApp.loopblks.mainLoop); - rFB.pipeline(prefabs.pl.spawnedEnts) .parent(mainApp.loopblks.mainLoop); - rFB.pipeline(prefabs.pl.ownedEnts) .parent(mainApp.loopblks.mainLoop); - rFB.pipeline(prefabs.pl.instanceInfo).parent(mainApp.loopblks.mainLoop); - rFB.pipeline(prefabs.pl.inSubtree) .parent(mainApp.loopblks.mainLoop); - - rFB.data_emplace< ACtxPrefabs > (prefabs.di.prefabs); - - rFB.task() - .name ("Schedule Prefab spawn") - .schedules (prefabs.pl.spawnRequest) - .args ({ prefabs.di.prefabs }) - .func ([] (ACtxPrefabs const &rPrefabs) noexcept -> TaskActions - { - return {.cancel = rPrefabs.spawnRequest.empty()}; - }); - - rFB.task() - .name ("Schedule spawnedEnts") - .schedules (prefabs.pl.spawnedEnts) - .args ({ prefabs.di.prefabs }) - .func ([] (ACtxPrefabs const &rPrefabs) noexcept -> TaskActions - { - return {.cancel = rPrefabs.newEnts.empty()}; - }); - - rFB.task() - .name ("Create Prefab entities") - .sync_with ({prefabs.pl.spawnRequest(UseOrRun), comScn.pl.activeEnt(New), prefabs.pl.spawnedEnts(Resize)}) - .args ({ prefabs.di.prefabs, comScn.di.basic, mainApp.di.resources}) - .func ([] (ACtxPrefabs &rPrefabs, ACtxBasic &rBasic, Resources &rResources) noexcept - { - SysPrefabInit::create_activeents(rPrefabs, rBasic, rResources); - }); - - rFB.task() - .name ("Init Prefab transforms") - .sync_with ({prefabs.pl.spawnRequest(UseOrRun), prefabs.pl.spawnedEnts(UseOrRun), comScn.pl.transform(New)}) - .args ({ comScn.di.basic, mainApp.di.resources, prefabs.di.prefabs}) - .func ([] (ACtxBasic &rBasic, Resources &rResources, ACtxPrefabs &rPrefabs) noexcept - { - SysPrefabInit::init_transforms(rPrefabs, rResources, rBasic.m_transform); - }); - - rFB.task() - .name ("Init Prefab instance info") - .sync_with ({prefabs.pl.spawnRequest(UseOrRun), prefabs.pl.spawnedEnts(UseOrRun), prefabs.pl.instanceInfo(Modify)}) - .args ({ comScn.di.basic, mainApp.di.resources, prefabs.di.prefabs}) - .func ([] (ACtxBasic &rBasic, Resources &rResources, ACtxPrefabs &rPrefabs) noexcept - { - rPrefabs.instanceInfo.resize(rBasic.m_activeIds.capacity(), PrefabInstanceInfo{.prefab = lgrn::id_null()}); - rPrefabs.roots.resize(rBasic.m_activeIds.capacity()); - SysPrefabInit::init_info(rPrefabs, rResources); - }); - - rFB.task() - .name ("Init Prefab physics") - .sync_with ({prefabs.pl.spawnRequest(UseOrRun), prefabs.pl.spawnedEnts(UseOrRun), phys.pl.mass(New), phys.pl.physUpdate(Done)}) - .args ({ comScn.di.basic, mainApp.di.resources, phys.di.phys, prefabs.di.prefabs}) - .func ([] (ACtxBasic &rBasic, Resources &rResources, ACtxPhysics &rPhys, ACtxPrefabs &rPrefabs) noexcept - { - rPhys.m_hasColliders.resize(rBasic.m_activeIds.capacity()); - //rPhys.m_massDirty.resize(rActiveIds.capacity()); - rPhys.m_shape.resize(rBasic.m_activeIds.capacity()); - SysPrefabInit::init_physics(rPrefabs, rResources, rPhys); - }); - - rFB.task() - .name ("Clear Prefab vector") - .sync_with ({prefabs.pl.spawnRequest(Clear)}) - .args ({ prefabs.di.prefabs}) - .func ([] (ACtxPrefabs &rPrefabs) noexcept - { - rPrefabs.spawnRequest.clear(); - }); - - rFB.task() - .name ("Clear spawned entities after use") - .sync_with ({prefabs.pl.spawnedEnts(Clear)}) - .args ({ prefabs.di.prefabs }) - .func ([] (ACtxPrefabs &rPrefabs) noexcept - { - rPrefabs.newEnts.clear(); - }); -}); // ftrPrefabs - - - -FeatureDef const ftrPrefabDraw = feature_def("PrefabDraw", [] ( - FeatureBuilder &rFB, - Implement prefabDraw, - DependOn mainApp, - DependOn scn, - DependOn comScn, - DependOn phys, - DependOn prefabs, - DependOn windowApp, - DependOn scnRender, - entt::any userData) -{ - rFB.data_emplace(prefabDraw.di.material, entt::any_cast(userData)); - - rFB.task() - .name ("Create DrawEnts for prefabs") - .sync_with ({prefabs.pl.spawnRequest(UseOrRun), prefabs.pl.spawnedEnts(UseOrRun), scnRender.pl.drawEnt(New), scnRender.pl.activeDrawTfs(New)}) - .args ({ prefabs.di.prefabs, mainApp.di.resources, scnRender.di.scnRender}) - .func ([] (ACtxPrefabs &rPrefabs, Resources &rResources, ACtxSceneRender &rScnRender) noexcept - { - SysPrefabDraw::init_drawents(rPrefabs, rResources, rScnRender); - }); - rFB.task() - .name ("Resync prefab DrawEnts") - .sync_with ({windowApp.pl.resync(Run), comScn.pl.hierarchy(Ready), scnRender.pl.drawEnt(New), scnRender.pl.activeDrawTfs(New)}) - .args ({ prefabs.di.prefabs, mainApp.di.resources, comScn.di.basic, comScn.di.drawing, scnRender.di.scnRender}) - .func ([] (ACtxPrefabs &rPrefabs, Resources &rResources, ACtxBasic const &rBasic, ACtxDrawing &rDrawing, ACtxSceneRender &rScnRender) noexcept - { - SysPrefabDraw::resync_drawents(rPrefabs, rResources, rBasic, rScnRender); - }); - - rFB.task() - .name ("Add mesh and material to prefabs") - .sync_with ({prefabs.pl.spawnRequest(UseOrRun), prefabs.pl.spawnedEnts(UseOrRun), - comScn.pl.texToRes(New), comScn.pl.meshToRes(New), comScn.pl.meshIds(New), comScn.pl.texIds(New), - scnRender.pl.drawEnt(Ready), scnRender.pl.activeDrawTfs(Ready), scnRender.pl.misc(New), - scnRender.pl.mesh (New), scnRender.pl.meshDirty (Modify_), - scnRender.pl.diffuseTex(New), scnRender.pl.diffuseTexDirty(Modify_), - scnRender.pl.material (New), scnRender.pl.materialDirty (Modify_)}) - .args ({ prefabs.di.prefabs, mainApp.di.resources, comScn.di.drawing, comScn.di.drawingRes, scnRender.di.scnRender, prefabDraw.di.material}) - .func ([] (ACtxPrefabs &rPrefabs, Resources &rResources, ACtxDrawing &rDrawing, ACtxDrawingRes &rDrawingRes, ACtxSceneRender &rScnRender, MaterialId material) noexcept - { - SysPrefabDraw::init_mesh_texture_material(rPrefabs, rResources, rDrawing, rDrawingRes, rScnRender, material); - }); - rFB.task() - .name ("Resync prefab mesh and material") - .sync_with ({windowApp.pl.resync(Run), - comScn.pl.texToRes(New), comScn.pl.meshToRes(New), comScn.pl.meshIds(New), comScn.pl.texIds(New), - scnRender.pl.drawEnt(Ready), scnRender.pl.activeDrawTfs(New), scnRender.pl.misc(New), - scnRender.pl.mesh (New), scnRender.pl.meshDirty (Modify_), - scnRender.pl.diffuseTex(New), scnRender.pl.diffuseTexDirty(Modify_), - scnRender.pl.material (New), scnRender.pl.materialDirty (Modify_)}) - .args ({ prefabs.di.prefabs, mainApp.di.resources, comScn.di.basic, comScn.di.drawing, comScn.di.drawingRes, scnRender.di.scnRender, prefabDraw.di.material}) - .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); - }); - - - - -}); // ftrPrefabDraw - - } // namespace adera diff --git a/src/adera_app/features/physics.h b/src/adera_app/features/physics.h index 0fd2bc78..7a081b00 100644 --- a/src/adera_app/features/physics.h +++ b/src/adera_app/features/physics.h @@ -37,11 +37,5 @@ namespace adera */ extern osp::fw::FeatureDef const ftrPhysics; -/** - * @brief Queues and logic for spawning Prefab resources - */ -extern osp::fw::FeatureDef const ftrPrefabs; - -extern osp::fw::FeatureDef const ftrPrefabDraw; } // namespace adera diff --git a/src/adera_app/features/shapes.cpp b/src/adera_app/features/shapes.cpp index e7af644c..19f4b97f 100644 --- a/src/adera_app/features/shapes.cpp +++ b/src/adera_app/features/shapes.cpp @@ -31,7 +31,6 @@ #include #include #include -#include using namespace adera; using namespace ftr_inter::stages; diff --git a/src/adera_app/features/vehicles.cpp b/src/adera_app/features/vehicles.cpp deleted file mode 100644 index 82d072b2..00000000 --- a/src/adera_app/features/vehicles.cpp +++ /dev/null @@ -1,564 +0,0 @@ -/** - * 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 "vehicles.h" -#include "../feature_interfaces.h" - -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -using namespace adera; -using namespace ftr_inter::stages; -using namespace ftr_inter; -using namespace osp::active; -using namespace osp::draw; -using namespace osp::fw; -using namespace osp::link; -using namespace osp; - -using osp::restypes::gc_importer; - -using namespace Magnum::Math::Literals; - -namespace adera -{ - - -FeatureDef const ftrParts = feature_def("Parts", [] ( - FeatureBuilder &rFB, - Implement links, - Implement parts, - DependOn cleanup, - DependOn mainApp, - DependOn scn) -{ - rFB.loopblk(links.loopblks.link) .parent(mainApp.loopblks.mainLoop); - rFB.pipeline(links.pl.requestMachUpdExt) .parent(mainApp.loopblks.mainLoop); - rFB.pipeline(links.pl.requestMachUpdLoop) .parent(links.loopblks.link); - rFB.pipeline(links.pl.linkLoopExt) .parent(mainApp.loopblks.mainLoop); - rFB.pipeline(links.pl.linkLoop) .parent(links.loopblks.link); - - rFB.pipeline(links.pl.machIds) .parent(mainApp.loopblks.mainLoop); - rFB.pipeline(links.pl.nodeIds) .parent(mainApp.loopblks.mainLoop); - rFB.pipeline(links.pl.connect) .parent(mainApp.loopblks.mainLoop); - - rFB.pipeline(parts.pl.partIds) .parent(mainApp.loopblks.mainLoop); - rFB.pipeline(parts.pl.partPrefabs) .parent(mainApp.loopblks.mainLoop); - rFB.pipeline(parts.pl.partTransformWeld) .parent(mainApp.loopblks.mainLoop); - rFB.pipeline(parts.pl.partDirty) .parent(mainApp.loopblks.mainLoop); - rFB.pipeline(parts.pl.weldIds) .parent(mainApp.loopblks.mainLoop); - rFB.pipeline(parts.pl.weldDirty) .parent(mainApp.loopblks.mainLoop); - rFB.pipeline(parts.pl.mapWeldPart) .parent(mainApp.loopblks.mainLoop); - rFB.pipeline(parts.pl.mapPartMach) .parent(mainApp.loopblks.mainLoop); - rFB.pipeline(parts.pl.mapPartActive) .parent(mainApp.loopblks.mainLoop); - rFB.pipeline(parts.pl.mapWeldActive) .parent(mainApp.loopblks.mainLoop); - - auto &rLinks = rFB.data_emplace< ACtxLinks > (links.di.links); - auto &rUpdMach = rFB.data_emplace< MachineUpdater > (links.di.updMach); - auto &rScnParts = rFB.data_emplace< ACtxParts > (parts.di.scnParts); - - // Resize containers to fit all existing MachTypeIds and NodeTypeIds - // These Global IDs are dynamically initialized just as the program starts - rUpdMach.machTypesDirty.resize(MachTypeReg_t::size()); - rUpdMach.localDirty .resize(MachTypeReg_t::size()); - rLinks.machines.perType.resize(MachTypeReg_t::size()); - rLinks.nodePerType .resize(NodeTypeReg_t::size()); - - rFB.task() - .name ("Clear Part dirty vectors after use") - .sync_with ({parts.pl.partDirty(Clear)}) - .args ({ parts.di.scnParts}) - .func ([] (ACtxParts& rScnParts) noexcept - { - rScnParts.partDirty.clear(); - }); - - rFB.task() - .name ("Clear Weld dirty vectors after use") - .sync_with ({parts.pl.weldDirty(Clear)}) - .args ({ parts.di.scnParts}) - .func ([] (ACtxParts& rScnParts) noexcept - { - rScnParts.weldDirty.clear(); - }); - - rFB.task() - .name ("Schedule Link update") - .schedules (links.pl.linkLoop) - .sync_with ({links.pl.requestMachUpdExt(UseOrRun), links.pl.linkLoopExt(Run_)}) - .args ({ links.di.updMach}) - .func ([] (MachineUpdater& rUpdMach) noexcept -> TaskActions - { - if (rUpdMach.requestMachineUpdateLoop) - { - rUpdMach.requestMachineUpdateLoop = false; - return {}; - } - else - { - return {.cancel = true}; - } - }); -}); // ftrParts - - - - -FeatureDef const ftrVehicleSpawn = feature_def("VehicleSpawn", [] ( - FeatureBuilder &rFB, - Implement vhclSpawn, - DependOn mainApp, - DependOn scn) -{ - rFB.pipeline(vhclSpawn.pl.spawnRequest) .parent(mainApp.loopblks.mainLoop); - rFB.pipeline(vhclSpawn.pl.spawnedParts) .parent(mainApp.loopblks.mainLoop); - rFB.pipeline(vhclSpawn.pl.spawnedWelds) .parent(mainApp.loopblks.mainLoop); - rFB.pipeline(vhclSpawn.pl.rootEnts) .parent(mainApp.loopblks.mainLoop); - rFB.pipeline(vhclSpawn.pl.spawnedMachs) .parent(mainApp.loopblks.mainLoop); - - rFB.data_emplace< ACtxVehicleSpawn > (vhclSpawn.di.vehicleSpawn); - - rFB.task() - .name ("Schedule Vehicle spawn") - .schedules (vhclSpawn.pl.spawnRequest) - .sync_with ({scn.pl.update(Run)}) - .args ({ vhclSpawn.di.vehicleSpawn }) - .func([] (ACtxVehicleSpawn const& rVehicleSpawn) noexcept -> TaskActions - { - return {.cancel = rVehicleSpawn.spawnRequest.empty()}; - }); - - - - rFB.task() - .name ("Clear Vehicle Spawning vector after use") - .sync_with ({vhclSpawn.pl.spawnRequest(Clear)}) - .args ({ vhclSpawn.di.vehicleSpawn}) - .func([] (ACtxVehicleSpawn& rVehicleSpawn) noexcept - { - rVehicleSpawn.spawnRequest.clear(); - }); -}); // ftrVehicleSpawn - - -FeatureDef const ftrVehicleSpawnVBData = feature_def("VehicleSpawnVBData", [] ( - FeatureBuilder &rFB, - Implement vhclSpawnVB, - DependOn links, - DependOn mainApp, - DependOn scn, - DependOn comScn, - DependOn prefabs, - DependOn parts, - DependOn vhclSpawn, - DependOn sigFloat) -{ - rFB.pipeline(vhclSpawnVB.pl.dataVB) .parent(mainApp.loopblks.mainLoop); - rFB.pipeline(vhclSpawnVB.pl.remapParts) .parent(mainApp.loopblks.mainLoop); - rFB.pipeline(vhclSpawnVB.pl.remapWelds) .parent(mainApp.loopblks.mainLoop); - rFB.pipeline(vhclSpawnVB.pl.remapMachs) .parent(mainApp.loopblks.mainLoop); - rFB.pipeline(vhclSpawnVB.pl.remapNodes) .parent(mainApp.loopblks.mainLoop); - - rFB.data_emplace< ACtxVehicleSpawnVB >(vhclSpawnVB.di.vehicleSpawnVB); - - rFB.task() - .name ("Create PartIds and WeldIds for vehicles to spawn from VehicleData") - .sync_with ({vhclSpawn.pl.spawnRequest(UseOrRun), vhclSpawn.pl.spawnedParts(Resize), vhclSpawnVB.pl.remapParts(Modify_), vhclSpawnVB.pl.remapWelds(Modify_), parts.pl.partIds(New), parts.pl.weldIds(New), parts.pl.mapWeldActive(Resize_)}) - .args ({ vhclSpawn.di.vehicleSpawn, vhclSpawnVB.di.vehicleSpawnVB, parts.di.scnParts}) - .func([] (ACtxVehicleSpawn& rVehicleSpawn, ACtxVehicleSpawnVB& rVehicleSpawnVB, ACtxParts& rScnParts) noexcept - { - SysVehicleSpawnVB::create_parts_and_welds(rVehicleSpawn, rVehicleSpawnVB, rScnParts); - }); - - rFB.task() - .name ("Request prefabs for vehicle parts from VehicleBuilder") - .sync_with ({vhclSpawn.pl.spawnRequest(UseOrRun), prefabs.pl.spawnRequest(Modify_), vhclSpawn.pl.spawnedParts(UseOrRun)}) - .args ({ vhclSpawn.di.vehicleSpawn, vhclSpawnVB.di.vehicleSpawnVB, parts.di.scnParts, prefabs.di.prefabs, mainApp.di.resources}) - .func([] (ACtxVehicleSpawn& rVehicleSpawn, ACtxVehicleSpawnVB const& rVehicleSpawnVB, ACtxParts& rScnParts, ACtxPrefabs& rPrefabs, Resources& rResources) noexcept - { - SysVehicleSpawnVB::request_prefabs(rVehicleSpawn, rVehicleSpawnVB, rScnParts, rPrefabs, rResources); - }); - - rFB.task() - .name ("Create Machine IDs copied from VehicleData") - .sync_with ({vhclSpawn.pl.spawnRequest(UseOrRun), vhclSpawnVB.pl.dataVB(UseOrRun), vhclSpawnVB.pl.remapMachs(Modify_), vhclSpawn.pl.spawnedMachs(Resize), links.pl.machIds(New)}) - .args ({ vhclSpawn.di.vehicleSpawn, vhclSpawnVB.di.vehicleSpawnVB, parts.di.scnParts, links.di.links}) - .func ([] (ACtxVehicleSpawn& rVehicleSpawn, ACtxVehicleSpawnVB& rVehicleSpawnVB, ACtxParts& rScnParts, ACtxLinks &rLinks) noexcept - { - std::size_t const newVehicleCount = rVehicleSpawn.new_vehicle_count(); - ACtxVehicleSpawnVB &rVSVB = rVehicleSpawnVB; - - // Count total machines, and calculate offsets for remaps. - - std::size_t machTotal = 0; - std::size_t remapMachTotal = 0; - - rVSVB.machtypeCount.clear(); - rVSVB.machtypeCount.resize(MachTypeReg_t::size(), 0); - - rVSVB.remapMachOffsets.resize(newVehicleCount); - - for (SpVehicleId vhId{0}; vhId.value < newVehicleCount; ++vhId.value) - { - VehicleData const* pVData = rVSVB.dataVB[vhId]; - if (pVData == nullptr) - { - continue; - } - - Machines const &srcMachines = pVData->m_machines; - std::size_t const bounds = srcMachines.ids.capacity(); - - rVSVB.remapMachOffsets[vhId] = remapMachTotal; - - remapMachTotal += bounds; - machTotal += srcMachines.ids.size(); - - for (MachTypeId type = 0; type < MachTypeReg_t::largest(); ++type) - { - rVSVB.machtypeCount[type] += srcMachines.perType[type].localIds.size(); - } - } - - rVehicleSpawn.spawnedMachs.resize(machTotal); - rVSVB.remapMachs.resize(remapMachTotal); - - // Create ACtxParts MachAny/LocalIDs and populate remaps - - // MachAnyIDs created here - rLinks.machines.ids.create(rVehicleSpawn.spawnedMachs.begin(), - rVehicleSpawn.spawnedMachs.end()); - - rLinks.machines.machToLocal.resize(rLinks.machines.ids.capacity()); - - auto itDstMachIds = rVehicleSpawn.spawnedMachs.cbegin(); - - for (SpVehicleId vhId{0}; vhId.value < newVehicleCount; ++vhId.value) - { - VehicleData const* pVData = rVSVB.dataVB[vhId]; - if (pVData == nullptr) - { - continue; - } - - Machines const &srcMachines = pVData->m_machines; - - std::size_t const remapMachOffset = rVSVB.remapMachOffsets[vhId]; - - for (MachAnyId const srcMach : srcMachines.ids) - { - MachAnyId const dstMach = *itDstMachIds; - ++itDstMachIds; - - // Populate map for "VehicleBuilder MachAnyId -> ACtxParts MachAnyId" - rVSVB.remapMachs[remapMachOffset + srcMach] = dstMach; - - // Create ACtxParts MachLocalIds - // MachLocalIds don't need a remap, since they can be obtained - // from a MachAnyId. - // TODO: This can be optimized later, where all local IDs are - // created at once with ids.create(first, last), and make - // resize(..) called once per type too - MachTypeId const type = srcMachines.machTypes[srcMach]; - PerMachType& rDstPerType = rLinks.machines.perType[type]; - - MachLocalId const dstLocal = rDstPerType.localIds.create(); - rDstPerType.localToAny.resize(rDstPerType.localIds.capacity()); - - rDstPerType.localToAny[dstLocal] = dstMach; - rLinks.machines.machToLocal[dstMach] = dstLocal; - } - } - }); - - rFB.task() - .name ("Update Part<->Machine maps") - .sync_with ({vhclSpawn.pl.spawnRequest(UseOrRun), vhclSpawnVB.pl.dataVB(UseOrRun), vhclSpawnVB.pl.remapMachs(UseOrRun), vhclSpawnVB.pl.remapParts(UseOrRun), parts.pl.mapPartMach(New)}) - .args ({ vhclSpawn.di.vehicleSpawn, vhclSpawnVB.di.vehicleSpawnVB, parts.di.scnParts, links.di.links, prefabs.di.prefabs, mainApp.di.resources}) - .func ([] (ACtxVehicleSpawn& rVehicleSpawn, ACtxVehicleSpawnVB const& rVehicleSpawnVB, ACtxParts& rScnParts, ACtxLinks &rLinks, ACtxPrefabs& rPrefabs, Resources& rResources) noexcept - { - std::size_t const newVehicleCount = rVehicleSpawn.new_vehicle_count(); - ACtxVehicleSpawnVB const& rVSVB = rVehicleSpawnVB; - - for (SpVehicleId vhId{0}; vhId.value < newVehicleCount; ++vhId.value) - { - VehicleData const* pVData = rVSVB.dataVB[vhId]; - if (pVData == nullptr) - { - continue; - } - - rScnParts.machineToPart.resize(rLinks.machines.ids.capacity()); - rScnParts.partToMachines.ids_reserve(rScnParts.partIds.capacity()); - rScnParts.partToMachines.data_reserve(rLinks.machines.ids.capacity()); - - std::size_t const remapMachOffset = rVSVB.remapMachOffsets[vhId]; - std::size_t const remapPartOffset = rVSVB.remapPartOffsets[vhId]; - - // Update rScnParts machine->part map - for (MachAnyId const srcMach : pVData->m_machines.ids) - { - MachAnyId const dstMach = rVSVB.remapMachs[remapMachOffset + srcMach]; - PartId const srcPart = pVData->m_machToPart[srcMach]; - PartId const dstPart = rVSVB.remapParts[remapPartOffset + srcPart]; - - rScnParts.machineToPart[dstMach] = dstPart; - } - - // Update rScnParts part->machine multimap - for (PartId const srcPart : pVData->m_partIds) - { - PartId const dstPart = rVSVB.remapParts[remapPartOffset + srcPart]; - - auto const& srcPairs = pVData->m_partToMachines[srcPart]; - - rScnParts.partToMachines.emplace(dstPart, srcPairs.size()); - auto dstPairs = rScnParts.partToMachines[dstPart]; - - for (int i = 0; i < srcPairs.size(); ++i) - { - MachinePair const& srcPair = srcPairs[i]; - MachinePair& rDstPair = dstPairs[i]; - MachAnyId const srcMach = pVData->m_machines.perType[srcPair.type].localToAny[srcPair.local]; - MachAnyId const dstMach = rVSVB.remapMachs[remapMachOffset + srcMach]; - MachTypeId const dstType = srcPair.type; - MachLocalId const dstLocal = rLinks.machines.machToLocal[dstMach]; - - rDstPair = { .local = dstLocal, .type = dstType }; - } - } - } - }); - - rFB.task() - .name ("Create (and connect) Node IDs copied from VehicleBuilder") - .sync_with ({vhclSpawn.pl.spawnRequest(UseOrRun), vhclSpawnVB.pl.dataVB(UseOrRun), vhclSpawnVB.pl.remapMachs(UseOrRun), vhclSpawnVB.pl.remapNodes(Modify_), - links.pl.nodeIds(New), links.pl.connect(New)}) - .args ({ vhclSpawn.di.vehicleSpawn, vhclSpawnVB.di.vehicleSpawnVB, parts.di.scnParts, links.di.links}) - .func ([] (ACtxVehicleSpawn& rVehicleSpawn, ACtxVehicleSpawnVB& rVehicleSpawnVB, ACtxParts& rScnParts, ACtxLinks &rLinks) noexcept - { - std::size_t const newVehicleCount = rVehicleSpawn.new_vehicle_count(); - ACtxVehicleSpawnVB &rVSVB = rVehicleSpawnVB; - - rVSVB.remapNodeOffsets.resize(newVehicleCount * NodeTypeReg_t::size()); - auto remapNodeOffsets2d = rVSVB.remap_node_offsets_2d(); - - // Add up bounds needed for all nodes of every type for remaps - std::size_t remapNodeTotal = 0; - for (VehicleData const* pVData : rVSVB.dataVB) - { - if (pVData == nullptr) - { - continue; - } - for (PerNodeType const &rSrcNodeType : pVData->m_nodePerType) - { - remapNodeTotal += rSrcNodeType.nodeIds.capacity(); - } - } - rVSVB.remapNodes.resize(remapNodeTotal); - - std::size_t nodeRemapUsed = 0; - - for (SpVehicleId vhId{0}; vhId.value < newVehicleCount; ++vhId.value) - { - VehicleData const* pVData = rVSVB.dataVB[vhId]; - if (pVData == nullptr) - { - continue; - } - - auto machRemap = arrayView(std::as_const(rVSVB.remapMachs)).exceptPrefix(rVSVB.remapMachOffsets[vhId]); - - for (NodeTypeId nodeType = 0; nodeType < NodeTypeReg_t::largest(); ++nodeType) - { - PerNodeType const &rSrcNodeType = pVData->m_nodePerType[nodeType]; - - std::size_t const remapSize = rSrcNodeType.nodeIds.capacity(); - auto nodeRemapOut = arrayView(rVSVB.remapNodes).sliceSize(nodeRemapUsed, remapSize); - remapNodeOffsets2d[vhId.value][nodeType] = nodeRemapUsed; - nodeRemapUsed += remapSize; - copy_nodes(rSrcNodeType, pVData->m_machines, machRemap, - rLinks.nodePerType[nodeType], rLinks.machines, nodeRemapOut); - } - } - }); - - rFB.task() - .name ("Update PartId<->ActiveEnt mapping") - .sync_with ({vhclSpawn.pl.spawnRequest(UseOrRun), vhclSpawn.pl.spawnedParts(UseOrRun), prefabs.pl.spawnedEnts(UseOrRun), parts.pl.mapPartActive(Modify)}) - .args ({ vhclSpawn.di.vehicleSpawn, comScn.di.basic, parts.di.scnParts, prefabs.di.prefabs}) - .func ([] (ACtxVehicleSpawn& rVehicleSpawn, ACtxBasic const& rBasic, ACtxParts& rScnParts, ACtxPrefabs& rPrefabs) noexcept - { - rScnParts.partToActive.resize(rScnParts.partIds.capacity()); - rScnParts.activeToPart.resize(rBasic.m_activeIds.capacity()); - - // Populate PartId<->ActiveEnt mapping, now that the prefabs exist - - auto itPrefab = rVehicleSpawn.spawnedPrefabs.begin(); - - for (PartId const partId : rVehicleSpawn.spawnedParts) - { - ActiveEnt const root = rPrefabs.spawnedEntsOffset[*itPrefab].front(); - ++itPrefab; - - rScnParts.partToActive[partId] = root; - rScnParts.activeToPart[root] = partId; - } - }); - - rFB.task() - .name ("Copy float signal values from VehicleBuilder") - .sync_with ({vhclSpawn.pl.spawnRequest(UseOrRun), vhclSpawn.pl.spawnedParts(UseOrRun), vhclSpawnVB.pl.remapNodes(UseOrRun), sigFloat.pl.sigValFloatExt(ExternalIn)}) - .args ({ vhclSpawn.di.vehicleSpawn, vhclSpawnVB.di.vehicleSpawnVB, parts.di.scnParts, links.di.links, sigFloat.di.sigValFloat, sigFloat.di.sigUpdFloat}) - .func ([] (ACtxVehicleSpawn& rVehicleSpawn, ACtxVehicleSpawnVB const& rVehicleSpawnVB, ACtxParts& rScnParts, ACtxLinks &rLinks, SignalValues_t& rSigValFloat, UpdateNodes& rSigUpdFloat) noexcept - { - Nodes const &rFloatNodes = rLinks.nodePerType[gc_ntSigFloat]; - std::size_t const maxNodes = rFloatNodes.nodeIds.capacity(); - rSigUpdFloat.nodeNewValues.resize(maxNodes); - rSigUpdFloat.nodeDirty.resize(maxNodes); - rSigValFloat.resize(maxNodes); - - std::size_t const newVehicleCount = rVehicleSpawn.new_vehicle_count(); - ACtxVehicleSpawnVB const &rVSVB = rVehicleSpawnVB; - - auto const remapNodeOffsets2d = rVSVB.remap_node_offsets_2d(); - for (SpVehicleId vhId{0}; vhId.value < newVehicleCount; ++vhId.value) - { - VehicleData const* pVData = rVSVB.dataVB[vhId]; - if (pVData == nullptr) - { - continue; - } - - PerNodeType const& srcFloatNodes = pVData->m_nodePerType[gc_ntSigFloat]; - entt::any const& srcFloatValuesAny = srcFloatNodes.m_nodeValues; - auto const& srcFloatValues = entt::any_cast< SignalValues_t >(srcFloatValuesAny); - std::size_t const nodeRemapOffset = remapNodeOffsets2d[vhId.value][gc_ntSigFloat]; - auto const nodeRemap = arrayView(rVSVB.remapNodes).exceptPrefix(nodeRemapOffset); - - for (NodeId const srcNode : srcFloatNodes.nodeIds) - { - NodeId const dstNode = nodeRemap[srcNode]; - rSigValFloat[dstNode] = srcFloatValues[srcNode]; - } - } - }); -}); // ftrVehicleSpawnVBData - - -FeatureDef const ftrVehicleSpawnDraw = feature_def("VehicleSpawnDraw", [] ( - FeatureBuilder &rFB, - DependOn scnRender, - DependOn vhclSpawn) -{ - rFB.task() - .name ("Enable Draw Transforms for spawned vehicle root entities") - .sync_with ({vhclSpawn.pl.spawnRequest(UseOrRun), vhclSpawn.pl.rootEnts(UseOrRun), scnRender.pl.activeDrawTfs(New), scnRender.pl.drawEnt(ReadyB4New)}) - .args ({ scnRender.di.scnRender, vhclSpawn.di.vehicleSpawn}) - .func([] (ACtxSceneRender& rScnRender, ACtxVehicleSpawn const& rVehicleSpawn) noexcept - { - for (ActiveEnt const ent : rVehicleSpawn.rootEnts) - { - rScnRender.m_needDrawTf.insert(ent); - } - }); - -}); // ftrVehicleSpawnDraw - - -FeatureDef const ftrSignalsFloat = feature_def("SignalsFloat", [] ( - FeatureBuilder &rFB, - Implement sigFloat, - DependOn mainApp, - DependOn scn, - DependOn links) -{ - - rFB.pipeline(sigFloat.pl.sigValFloatExt) .parent(mainApp.loopblks.mainLoop); - rFB.pipeline(sigFloat.pl.sigValFloatLoop) .parent(links.loopblks.link); - - rFB.data_emplace< SignalValues_t > (sigFloat.di.sigValFloat); - rFB.data_emplace< UpdateNodes > (sigFloat.di.sigUpdFloat); - - // NOTE: Consider supporting per-thread UpdateNodes to allow multiple threads to write - // new float values in parallel. - - rFB.task() - .name ("Update Signal Nodes") - .sync_with ({links.pl.linkLoop(EStgLink::NodeUpd), sigFloat.pl.sigValFloatLoop(Modify), links.pl.requestMachUpdLoop(Modify_)}) - .args ({ sigFloat.di.sigUpdFloat, sigFloat.di.sigValFloat, links.di.updMach, links.di.links}) - .func ([] (UpdateNodes& rSigUpdFloat, SignalValues_t& rSigValFloat, MachineUpdater& rUpdMach, ACtxLinks const& rLinks) noexcept - { - if ( ! rSigUpdFloat.dirty ) - { - return; // Not dirty, nothing to do - } - - Nodes const &rFloatNodes = rLinks.nodePerType[gc_ntSigFloat]; - - // NOTE: The various use of reset() clear entire bit arrays, which may or may - // not be expensive. They likely optimize to memset - - for (MachTypeId const machTypeDirty : rUpdMach.machTypesDirty) - { - rUpdMach.localDirty[machTypeDirty].clear(); - } - rUpdMach.machTypesDirty.clear(); - - // Sees which nodes changed, and writes into rUpdMach set dirty which MACHINES - // must be updated next - update_signal_nodes( - rSigUpdFloat.nodeDirty, - rFloatNodes.nodeToMach, - rLinks.machines, - arrayView(rSigUpdFloat.nodeNewValues), - rSigValFloat, - rUpdMach); - rSigUpdFloat.nodeDirty.clear(); - rSigUpdFloat.dirty = false; - - // Run tasks needed to update machine types that are dirty - bool anyMachineNotified = false; - for (MachTypeId const type : rUpdMach.machTypesDirty) - { - anyMachineNotified = true; - } - if (anyMachineNotified && rUpdMach.requestMachineUpdateLoop.load()) - { - rUpdMach.requestMachineUpdateLoop.store(true); - } - }); -}); // ftrSignalsFloat - - -} // namespace adera diff --git a/src/adera_app/features/vehicles_machines.cpp b/src/adera_app/features/vehicles_machines.cpp deleted file mode 100644 index b361c2ae..00000000 --- a/src/adera_app/features/vehicles_machines.cpp +++ /dev/null @@ -1,511 +0,0 @@ -/** - * 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 "vehicles_machines.h" -#include "misc.h" - -#include "../feature_interfaces.h" - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace adera; -using namespace ftr_inter::stages; -using namespace ftr_inter; -using namespace osp::active; -using namespace osp::draw; -using namespace osp::fw; -using namespace osp::link; -using namespace osp; - -namespace adera -{ - -FeatureDef const ftrMachMagicRockets = feature_def("MachMagicRockets", [] ( - FeatureBuilder &rFB, - DependOn scn, - DependOn parts, - DependOn links, - DependOn sigFloat) -{ - rFB.task() - .name ("Allocate Machine update bitset for MagicRocket") - .sync_with ({links.pl.machIds(Ready), links.pl.linkLoopExt(Before)}) - .args ({ links.di.links, links.di.updMach}) - .func ([] (ACtxLinks& rLinks, MachineUpdater& rUpdMach) - { - rUpdMach.localDirty[gc_mtMagicRocket].resize(rLinks.machines.perType[gc_mtMagicRocket].localIds.capacity()); - }); -}); // setup_mach_rocket - - -struct ThrustIndicator -{ - MaterialId material; - Magnum::Color4 color; - MeshIdOwner_t mesh; - - KeyedVec rktToDrawEnt; - - float indicatorScale {0.0001f}; -}; - -FeatureDef const ftrMagicRocketThrustIndicator = feature_def("MagicRocketThrustIndicator", [] ( - FeatureBuilder &rFB, - Implement rktIndicate, - DependOn cleanup, - DependOn mainApp, - DependOn comScn, - DependOn parts, - DependOn links, - DependOn sigFloat, - DependOn windowApp, - DependOn scnRender, - entt::any userData) -{ - auto const [pkg, material] = entt::any_cast(userData); - - auto &rResources = rFB.data_get< Resources > (mainApp.di.resources); - auto &rBasic = rFB.data_get< ACtxBasic > (comScn.di.basic); - auto &rDrawing = rFB.data_get< ACtxDrawing > (comScn.di.drawing); - auto &rDrawingRes = rFB.data_get< ACtxDrawingRes > (comScn.di.drawingRes); - auto &rScnRender = rFB.data_get< ACtxSceneRender >(scnRender.di.scnRender); - auto &rDrawTfObservers = rFB.data_get< DrawTfObservers >(scnRender.di.drawTfObservers); - auto &rScnParts = rFB.data_get< ACtxParts > (parts.di.scnParts); - auto &rLinks = rFB.data_get< ACtxLinks > (links.di.links); - auto &rSigValFloat = rFB.data_get< SignalValues_t > (sigFloat.di.sigValFloat); - auto &rThrustIndicator = rFB.data_emplace(rktIndicate.di.indicator); - - rThrustIndicator.material = material; - rThrustIndicator.color = { 1.0f, 0.2f, 0.8f, 1.0f }; - rThrustIndicator.mesh = SysRender::add_drawable_mesh(rDrawing, rDrawingRes, rResources, pkg, "cone"); - - rFB.task() - .name ("Create DrawEnts for Thrust indicators") - .sync_with ({windowApp.pl.sync(Run), scnRender.pl.drawEnt(New), links.pl.machIds(Ready)}) - .args ({ scnRender.di.scnRender, parts.di.scnParts, links.di.links, rktIndicate.di.indicator}) - .func([] (ACtxSceneRender &rScnRender, ACtxParts const& rScnParts, ACtxLinks const& rLinks, ThrustIndicator& rIndicator) noexcept - { - PerMachType const& rockets = rLinks.machines.perType[gc_mtMagicRocket]; - - rIndicator.rktToDrawEnt.resize(rockets.localIds.capacity()); - - for (MachLocalId const localId : rockets.localIds) - { - DrawEnt& rDrawEnt = rIndicator.rktToDrawEnt[localId]; - if (rDrawEnt == lgrn::id_null()) - { - rDrawEnt = rScnRender.m_drawIds.create(); - } - } - }); - - rFB.task() - .name ("Add mesh and materials to Thrust indicators") - .sync_with ({windowApp.pl.sync(Run), scnRender.pl.drawEnt(Ready), comScn.pl.meshToRes(New), scnRender.pl.mesh(New), scnRender.pl.material(New), scnRender.pl.materialDirty(Modify_), scnRender.pl.meshDirty(Modify_)}) - .args ({ comScn.di.basic, scnRender.di.scnRender, comScn.di.drawing, comScn.di.drawingRes, parts.di.scnParts, links.di.links, sigFloat.di.sigValFloat, rktIndicate.di.indicator}) - .func([] (ACtxBasic& rBasic, ACtxSceneRender &rScnRender, ACtxDrawing& rDrawing, ACtxDrawingRes const& rDrawingRes, ACtxParts const& rScnParts, ACtxLinks const& rLinks, SignalValues_t const& rSigValFloat, ThrustIndicator& rIndicator) noexcept - { - Material &rMat = rScnRender.m_materials[rIndicator.material]; - PerMachType const &rockets = rLinks.machines.perType[gc_mtMagicRocket]; - Nodes const &floats = rLinks.nodePerType[gc_ntSigFloat]; - - for (MachLocalId const localId : rockets.localIds) - { - DrawEnt const drawEnt = rIndicator.rktToDrawEnt[localId]; - - MachAnyId const anyId = rockets.localToAny[localId]; - PartId const part = rScnParts.machineToPart[anyId]; - ActiveEnt const partEnt = rScnParts.partToActive[part]; - - auto const& portSpan = floats.machToNode[anyId]; - NodeId const throttleIn = connected_node(portSpan, ports_magicrocket::gc_throttleIn.port); - NodeId const multiplierIn = connected_node(portSpan, ports_magicrocket::gc_multiplierIn.port); - - float const throttle = std::clamp(rSigValFloat[throttleIn], 0.0f, 1.0f); - float const multiplier = rSigValFloat[multiplierIn]; - float const thrustMag = throttle * multiplier; - - if (thrustMag == 0.0f) - { - rScnRender.m_visible.erase(drawEnt); - rMat.m_dirty.push_back(drawEnt); - continue; - } - - if (!rMat.m_ents.contains(drawEnt)) - { - rMat.m_ents.insert(drawEnt); - rMat.m_dirty.push_back(drawEnt); - } - - MeshIdOwner_t &rMeshOwner = rScnRender.m_mesh[drawEnt]; - if ( ! rMeshOwner.has_value() ) - { - rScnRender.m_mesh[drawEnt] = rDrawing.m_meshRefCounts.ref_add(rIndicator.mesh.value()); - rScnRender.m_meshDirty.push_back(drawEnt); - } - - rScnRender.m_visible.insert(drawEnt); - rScnRender.m_opaque .insert(drawEnt); - - rScnRender.m_color [drawEnt] = rIndicator.color; - rScnRender.drawTfObserverEnable [partEnt] = 1; - - SysRender::needs_draw_transforms(rBasic.m_scnGraph, rScnRender.m_needDrawTf, partEnt); - } - }); - - using UserData_t = DrawTfObservers::UserData_t; - - DrawTfObservers::Observer &rObserver = rDrawTfObservers.observers[0]; - - rObserver.data = { &rThrustIndicator, &rScnParts, &rLinks, &rSigValFloat }; - rObserver.func = [] (ACtxSceneRender& rCtxScnRdr, Matrix4 const& drawTf, active::ActiveEnt ent, int depth, UserData_t data) noexcept - { - auto &rThrustIndicator = *static_cast< ThrustIndicator* > (data[0]); - auto &rScnParts = *static_cast< ACtxParts* > (data[1]); - auto &rLinks = *static_cast< ACtxLinks* > (data[2]); - auto &rSigValFloat = *static_cast< SignalValues_t* > (data[3]); - - PerMachType const &rockets = rLinks.machines.perType[gc_mtMagicRocket]; - Nodes const &floats = rLinks.nodePerType[gc_ntSigFloat]; - - PartId const part = rScnParts.activeToPart[ent]; - ActiveEnt const partEnt = rScnParts.partToActive[part]; - - for (MachinePair const pair : rScnParts.partToMachines[part]) - { - if (pair.type == gc_mtMagicRocket) - { - DrawEnt const drawEnt = rThrustIndicator.rktToDrawEnt[pair.local]; - MachAnyId const anyId = rockets.localToAny[pair.local]; - - auto const& portSpan = floats.machToNode[anyId]; - NodeId const throttleIn = connected_node(portSpan, ports_magicrocket::gc_throttleIn.port); - NodeId const multiplierIn = connected_node(portSpan, ports_magicrocket::gc_multiplierIn.port); - - float const throttle = std::clamp(rSigValFloat[throttleIn], 0.0f, 1.0f); - float const multiplier = rSigValFloat[multiplierIn]; - float const thrustMag = throttle * multiplier; - - rCtxScnRdr.m_drawTransform[drawEnt] - = drawTf - * Matrix4::scaling({1.0f, 1.0f, thrustMag * rThrustIndicator.indicatorScale}) - * Matrix4::translation({0.0f, 0.0f, -1.0f}) - * Matrix4::scaling({0.2f, 0.2f, 1.0f}); } - } - }; - - rFB.task() - .name ("Clean up ThrustIndicator") - .sync_with ({cleanup.pl.cleanup(Run_)}) - .args ({ mainApp.di.resources, comScn.di.drawing, rktIndicate.di.indicator}) - .func([] (Resources& rResources, ACtxDrawing& rDrawing, ThrustIndicator& rThrustIndicator) noexcept - { - rDrawing.m_meshRefCounts.ref_release(std::move(rThrustIndicator.mesh)); - }); -}); // ftrMagicRocketThrustIndicator - - - -FeatureDef const ftrMachRCSDriver = feature_def("RCSDriver", [] ( - FeatureBuilder &rFB, - DependOn scn, - DependOn parts, - DependOn links, - DependOn sigFloat) -{ - rFB.task() - .name ("Allocate Machine update bitset for RcsDriver") - .sync_with ({scn.pl.update(Run), links.pl.machIds(Ready), links.pl.linkLoopExt(Before)}) - .args ({ links.di.links, links.di.updMach}) - .func ([] (ACtxLinks& rLinks, MachineUpdater& rUpdMach) - { - rUpdMach.localDirty[gc_mtRcsDriver].resize(rLinks.machines.perType[gc_mtRcsDriver].localIds.capacity()); - }); - - rFB.task() - .name ("RCS Drivers calculate new values") - .sync_with ({links.pl.linkLoop(MachUpd), sigFloat.pl.sigValFloatExt(LoopRunning), sigFloat.pl.sigValFloatLoop(Modify)}) - .args ({ links.di.links, links.di.updMach, sigFloat.di.sigValFloat, sigFloat.di.sigUpdFloat}) - .func ([] (ACtxLinks& rLinks, MachineUpdater& rUpdMach, SignalValues_t& rSigValFloat, UpdateNodes& rSigUpdFloat) noexcept - { - Nodes const &rFloatNodes = rLinks.nodePerType[gc_ntSigFloat]; - PerMachType &rRockets = rLinks.machines.perType[gc_mtRcsDriver]; - - for (MachLocalId const local : rUpdMach.localDirty[gc_mtRcsDriver]) - { - MachAnyId const mach = rRockets.localToAny[local]; - auto const portSpan = lgrn::Span{rFloatNodes.machToNode[mach]}; - - NodeId const thrNode = connected_node(portSpan, ports_rcsdriver::gc_throttleOut.port); - if (thrNode == lgrn::id_null()) - { - continue; // Throttle Output not connected, calculations below are useless - } - - auto const rcs_read = [&rSigValFloat, portSpan] (float& rDstVar, PortEntry const& entry) - { - NodeId const node = connected_node(portSpan, entry.port); - - if (node != lgrn::id_null()) - { - rDstVar = rSigValFloat[node]; - } - }; - - Vector3 pos {0.0f}; - Vector3 dir {0.0f}; - Vector3 cmdLin {0.0f}; - Vector3 cmdAng {0.0f}; - - rcs_read( pos.x(), ports_rcsdriver::gc_posXIn ); - rcs_read( pos.y(), ports_rcsdriver::gc_posYIn ); - rcs_read( pos.z(), ports_rcsdriver::gc_posZIn ); - rcs_read( dir.x(), ports_rcsdriver::gc_dirXIn ); - rcs_read( dir.y(), ports_rcsdriver::gc_dirYIn ); - rcs_read( dir.z(), ports_rcsdriver::gc_dirZIn ); - rcs_read( cmdLin.x(), ports_rcsdriver::gc_cmdLinXIn ); - rcs_read( cmdLin.y(), ports_rcsdriver::gc_cmdLinYIn ); - rcs_read( cmdLin.z(), ports_rcsdriver::gc_cmdLinZIn ); - rcs_read( cmdAng.x(), ports_rcsdriver::gc_cmdAngXIn ); - rcs_read( cmdAng.y(), ports_rcsdriver::gc_cmdAngYIn ); - rcs_read( cmdAng.z(), ports_rcsdriver::gc_cmdAngZIn ); - - OSP_LOG_TRACE("RCS controller {} pitch = {}", local, cmdAng.x()); - OSP_LOG_TRACE("RCS controller {} yaw = {}", local, cmdAng.y()); - OSP_LOG_TRACE("RCS controller {} roll = {}", local, cmdAng.z()); - - float const thrCurr = rSigValFloat[thrNode]; - float const thrNew = thruster_influence(pos, dir, cmdLin, cmdAng); - - if (thrCurr != thrNew) - { - rSigUpdFloat.assign(thrNode, thrNew); - rUpdMach.requestMachineUpdateLoop = true; - } - } - }); -}); // ftrRCSDriver - - - -struct VehicleControls -{ - MachLocalId selectedUsrCtrl{lgrn::id_null()}; - - input::EButtonControlIndex btnSwitch; - input::EButtonControlIndex btnThrMax; - input::EButtonControlIndex btnThrMin; - input::EButtonControlIndex btnThrMore; - input::EButtonControlIndex btnThrLess; - input::EButtonControlIndex btnPitchUp; - input::EButtonControlIndex btnPitchDn; - input::EButtonControlIndex btnYawLf; - input::EButtonControlIndex btnYawRt; - input::EButtonControlIndex btnRollLf; - input::EButtonControlIndex btnRollRt; -}; - -FeatureDef const ftrVehicleControl = feature_def("VehicleControl", [] ( - FeatureBuilder &rFB, - Implement vhclCtrl, - Implement camCtrlSpecial, - DependOn camCtrlBase, - DependOn mainApp, - DependOn windowApp, - DependOn scn, - DependOn comScn, - DependOn parts, - DependOn links, - DependOn phys, - DependOn sigFloat) -{ - rFB.pipeline(vhclCtrl.pl.selectedVehicle).parent(mainApp.loopblks.mainLoop); - - auto &rUserInput = rFB.data_get< input::UserInputHandler >(windowApp.di.userInput); - - // TODO: add cleanup task - rFB.data_emplace(vhclCtrl.di.vhControls, VehicleControls{ - .btnSwitch = rUserInput.button_subscribe("game_switch"), - .btnThrMax = rUserInput.button_subscribe("vehicle_thr_max"), - .btnThrMin = rUserInput.button_subscribe("vehicle_thr_min"), - .btnThrMore = rUserInput.button_subscribe("vehicle_thr_more"), - .btnThrLess = rUserInput.button_subscribe("vehicle_thr_less"), - .btnPitchUp = rUserInput.button_subscribe("vehicle_pitch_up"), - .btnPitchDn = rUserInput.button_subscribe("vehicle_pitch_dn"), - .btnYawLf = rUserInput.button_subscribe("vehicle_yaw_lf"), - .btnYawRt = rUserInput.button_subscribe("vehicle_yaw_rt"), - .btnRollLf = rUserInput.button_subscribe("vehicle_roll_lf"), - .btnRollRt = rUserInput.button_subscribe("vehicle_roll_rt") - }); - - rFB.task() - .name ("Select vehicle") - .sync_with ({windowApp.pl.inputs(Run), vhclCtrl.pl.selectedVehicle(Modify)}) - .args ({ parts.di.scnParts, links.di.links, windowApp.di.userInput, vhclCtrl.di.vhControls}) - .func ([] (ACtxParts& rScnParts, ACtxLinks& rLinks, input::UserInputHandler const &rUserInput, VehicleControls &rVhControls) noexcept - { - PerMachType &rUsrCtrl = rLinks.machines.perType[gc_mtUserCtrl]; - - // Select a UsrCtrl machine when pressing the switch button - if (rUserInput.button_state(rVhControls.btnSwitch).m_triggered) - { - ++rVhControls.selectedUsrCtrl; - bool found = false; - for (MachLocalId local = rVhControls.selectedUsrCtrl; local < rUsrCtrl.localIds.capacity(); ++local) - { - if (rUsrCtrl.localIds.exists(local)) - { - found = true; - rVhControls.selectedUsrCtrl = local; - break; - } - } - - if ( ! found ) - { - rVhControls.selectedUsrCtrl = lgrn::id_null(); - OSP_LOG_INFO("Unselected vehicles"); - } - else - { - OSP_LOG_INFO("Selected User Control: {}", rVhControls.selectedUsrCtrl); - } - } - }); - - rFB.task() - .name ("Write inputs to UserControl Machines") - .sync_with ({windowApp.pl.inputs(Run), sigFloat.pl.sigValFloatExt(ExternalIn)}) - .args ({ parts.di.scnParts, links.di.links, links.di.updMach, sigFloat.di.sigValFloat, sigFloat.di.sigUpdFloat, windowApp.di.userInput, vhclCtrl.di.vhControls, scn.di.deltaTimeIn}) - .func ([] (ACtxParts& rScnParts, ACtxLinks& rLinks, MachineUpdater& rUpdMach, SignalValues_t& rSigValFloat, UpdateNodes& rSigUpdFloat, input::UserInputHandler const& rUserInput, VehicleControls& rVhControls, float const deltaTimeIn) noexcept - { - VehicleControls& rVC = rVhControls; - auto const held = [&rUserInput] (input::EButtonControlIndex idx, float val) -> float - { - return rUserInput.button_state(idx).m_held ? val : 0.0f; - }; - - if (rVC.selectedUsrCtrl == lgrn::id_null()) - { - return; // No vehicle selected - } - - Nodes const &rFloatNodes = rLinks.nodePerType[gc_ntSigFloat]; - float const thrRate = deltaTimeIn; - - float const thrChange - = held(rVC.btnThrMore, thrRate) - held(rVC.btnThrLess, thrRate) - + held(rVC.btnThrMax, 1.0f) - held(rVC.btnThrMin, 1.0f); - - Vector3 const attitude - { - held(rVC.btnPitchDn, 1.0f) - held(rVC.btnPitchUp, 1.0f), - held(rVC.btnYawLf, 1.0f) - held(rVC.btnYawRt, 1.0f), - held(rVC.btnRollRt, 1.0f) - held(rVC.btnRollLf, 1.0f) - }; - - PerMachType &rUsrCtrl = rLinks.machines.perType[gc_mtUserCtrl]; - MachAnyId const mach = rUsrCtrl.localToAny[rVC.selectedUsrCtrl]; - auto const portSpan = lgrn::Span{rFloatNodes.machToNode[mach]}; - - bool changed = false; - auto const write_control = [&rSigValFloat, &rSigUpdFloat, &changed, portSpan] (PortEntry const& entry, float write, bool replace = true, float min = 0.0f, float max = 1.0f) - { - NodeId const node = connected_node(portSpan, entry.port); - if (node == lgrn::id_null()) - { - return; // not connected - } - - float const oldVal = rSigValFloat[node]; - float const newVal = replace ? write : Magnum::Math::clamp(oldVal + write, min, max); - - if (oldVal != newVal) - { - rSigUpdFloat.assign(node, newVal); - changed = true; - } - }; - - write_control(ports_userctrl::gc_throttleOut, thrChange, false); - write_control(ports_userctrl::gc_pitchOut, attitude.x()); - write_control(ports_userctrl::gc_yawOut, attitude.y()); - write_control(ports_userctrl::gc_rollOut, attitude.z()); - - if (changed) - { - rUpdMach.requestMachineUpdateLoop = true; - } - }); - - rFB.task() - .name ("Update vehicle camera") - .sync_with ({windowApp.pl.sync(Run), windowApp.pl.inputs(Run), camCtrlBase.pl.camTarget(Modify), phys.pl.physUpdate(Done), parts.pl.mapWeldActive(Ready)}) - .args ({ camCtrlBase.di.camCtrl, camCtrlBase.di.camButtons, scn.di.deltaTimeIn, comScn.di.basic, vhclCtrl.di.vhControls, parts.di.scnParts, links.di.links}) - .func ([] (ACtxCameraController& rCamCtrl, ACtxCameraButtons const& camButtons, float const deltaTimeIn, ACtxBasic const& rBasic, VehicleControls& rVhControls, ACtxParts const& rScnParts, ACtxLinks const& rLinks) noexcept - { - CameraCommands cmds = camButtons.read_button_inputs(deltaTimeIn); - - if (rVhControls.selectedUsrCtrl != lgrn::id_null()) - { - // Follow selected UserControl machine - - // Obtain associated ActiveEnt - // MachLocalId -> MachAnyId -> PartId -> RigidGroup -> ActiveEnt - PerMachType const& rUsrCtrls = rLinks.machines.perType.at(adera::gc_mtUserCtrl); - MachAnyId const selectedMach = rUsrCtrls.localToAny .at(rVhControls.selectedUsrCtrl); - PartId const selectedPart = rScnParts.machineToPart .at(selectedMach); - WeldId const weld = rScnParts.partToWeld .at(selectedPart); - ActiveEnt const selectedEnt = rScnParts.weldToActive .at(weld); - - if (rBasic.m_transform.contains(selectedEnt)) - { - rCamCtrl.m_target = rBasic.m_transform.get(selectedEnt).m_transform.translation(); - } - - cmds.moveRelative = {}; // Locked to vehicle, ignore freecam translation - } - // else, freecam - - rCamCtrl.apply(cmds); - }); - -}); // ftrVehicleControl - - - -} // namespace adera diff --git a/src/adera_app/features/vehicles_machines.h b/src/adera_app/features/vehicles_machines.h deleted file mode 100644 index 5d11c556..00000000 --- a/src/adera_app/features/vehicles_machines.h +++ /dev/null @@ -1,58 +0,0 @@ -/** - * 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 adera -{ - -/** - * @brief Links for Magic Rockets - * - * This only sets up links and does not apply forces, see setup_rocket_thrust_newton - */ -extern osp::fw::FeatureDef const ftrMachMagicRockets; - - -/** - * @brief Links for RCS Drivers, which output thrust levels given pitch/yaw/roll controls - */ -extern osp::fw::FeatureDef const ftrMachRCSDriver; - - -/** - * @brief Controls to select and control a UserControl Machine - */ -extern osp::fw::FeatureDef const ftrVehicleControl; - - -/** - * @brief Red indicators over Magic Rockets - */ -extern osp::fw::FeatureDef const ftrMagicRocketThrustIndicator; - - -} // namespace adera diff --git a/src/adera_app/features/vehicles_prebuilt.cpp b/src/adera_app/features/vehicles_prebuilt.cpp index fe437a84..9ad518a9 100644 --- a/src/adera_app/features/vehicles_prebuilt.cpp +++ b/src/adera_app/features/vehicles_prebuilt.cpp @@ -26,9 +26,10 @@ #include "../feature_interfaces.h" -#include - #include +#include + +#if 0 using namespace Magnum::Math::Literals; using namespace adera; @@ -124,7 +125,6 @@ FeatureDef const ftrPrebuiltVehicles = feature_def("PrebuiltVehicles", [] ( auto &rResources = rFB.data_get(mainApp.di.resources); auto &rPrebuiltVehicles = rFB.data_emplace(testVhcls.di.prebuiltVehicles); - rPrebuiltVehicles.resize(PrebuiltVhIdReg_t::size()); using namespace adera; @@ -202,39 +202,19 @@ FeatureDef const ftrPrebuiltVehicles = feature_def("PrebuiltVehicles", [] ( for (Rad ang = 0.0_degf; ang < Rad(360.0_degf); ang += Rad(360.0_degf)/rcsRingBlocks) { Quaternion const rotZ = Quaternion::rotation(ang, {0.0f, 0.0f, 1.0f}); - add_rcs_block(vbuilder, toWeld, rcsInputs, rcsThrust, rotZ.transformVector(rcsOset), rotZ); + //add_rcs_block(vbuilder, toWeld, rcsInputs, rcsThrust, rotZ.transformVector(rcsOset), rotZ); } } - - vbuilder.weld(toWeld); - - rPrebuiltVehicles[gc_pbvSimpleCommandServiceModule] = std::make_unique(std::move(vbuilder.finalize_release())); } // Put more prebuilt vehicles here! - rFB.task() - .name ("Clean up prebuilt vehicles") - .sync_with ({cleanup.pl.cleanup(Run_)}) - .args ({ testVhcls.di.prebuiltVehicles, mainApp.di.resources}) - .func ([] (PrebuiltVehicles &rPrebuildVehicles, Resources& rResources) noexcept - { - for (std::unique_ptr &rpData : rPrebuildVehicles) - { - if (rpData != nullptr) - { - for (PrefabPair &rPrefabPair : rpData->m_partPrefabs) - { - rResources.owner_destroy(gc_importer, std::move(rPrefabPair.m_importer)); - } - } - } - rPrebuildVehicles.clear(); - }); - }); // setup_prebuilt_vehicles } // namespace adera + + +#endif diff --git a/src/adera_app/features/vehicles_prebuilt.h b/src/adera_app/features/vehicles_prebuilt.h index 5061e58f..f50b10ee 100644 --- a/src/adera_app/features/vehicles_prebuilt.h +++ b/src/adera_app/features/vehicles_prebuilt.h @@ -26,8 +26,6 @@ #include -#include - #include #include #include @@ -40,10 +38,9 @@ namespace adera using PrebuiltVhId = osp::StrongId; using PrebuiltVhIdReg_t = osp::GlobalIdReg; -struct PrebuiltVehicles : osp::KeyedVec< PrebuiltVhId, std::unique_ptr > +struct PrebuiltVehicles { - PrebuiltVehicles() = default; - OSP_MOVE_ONLY_CTOR_ASSIGN(PrebuiltVehicles); + }; inline PrebuiltVhId const gc_pbvSimpleCommandServiceModule = PrebuiltVhIdReg_t::create(); diff --git a/src/gdextension/flying_scene.cpp b/src/gdextension/flying_scene.cpp index 96060bd2..8709240e 100644 --- a/src/gdextension/flying_scene.cpp +++ b/src/gdextension/flying_scene.cpp @@ -34,7 +34,6 @@ #include #include #include -#include #include #include @@ -42,8 +41,6 @@ #include #include #include -#include -#include #include #include @@ -259,25 +256,6 @@ void FlyingScene::clear_resource_owners() { } }; - // Importer data own a lot of other resources - for (osp::ResId const id : rResources.ids(gc_importer)) { - auto *const pData = - rResources.data_try_get(gc_importer, id); - if (pData != nullptr) { - for (osp::ResIdOwner_t &rOwner : std::move(pData->m_images)) { - rResources.owner_destroy(gc_image, std::move(rOwner)); - } - - for (osp::ResIdOwner_t &rOwner : std::move(pData->m_textures)) { - rResources.owner_destroy(gc_texture, std::move(rOwner)); - } - - for (osp::ResIdOwner_t &rOwner : std::move(pData->m_meshes)) { - rResources.owner_destroy(gc_mesh, std::move(rOwner)); - } - } - }; - godot::RenderingServer *rs = godot::RenderingServer::get_singleton(); rs->free_rid(m_lightInstance); rs->free_rid(m_light); @@ -300,9 +278,6 @@ void FlyingScene::load_a_bunch_of_stuff() { 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 // FIXME this works in editor, but probably not for exported game. const std::string_view datapath = {"OSPData/adera/"}; @@ -315,13 +290,13 @@ void FlyingScene::load_a_bunch_of_stuff() { }; // 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) { - auto str = osp::string_concat(datapath, meshName); - osp::ResId res = osp::load_tinygltf_file(str, rResources, m_defaultPkg); - if (res != lgrn::id_null()) { - osp::assigns_prefabs_tinygltf(rResources, res); - } - } +// for (auto const &meshName : meshes) { +// auto str = osp::string_concat(datapath, meshName); +// osp::ResId res = osp::load_tinygltf_file(str, rResources, m_defaultPkg); +// if (res != lgrn::id_null()) { +// osp::assigns_prefabs_tinygltf(rResources, res); +// } +// } // Add a default primitives auto const add_mesh_quick = [&rResources = rResources, @@ -382,19 +357,9 @@ ContextId make_scene_renderer(Framework &rFW, ContextId mainCtx, scnRdrCB.add_feature(ftrPhysicsShapesDraw, matFlat); scnRdrCB.add_feature(ftrCursor, TplPkgIdMaterialId{defaultPkg, matFlat}); - if (rFW.get_interface_id(sceneCtx).has_value()) { - scnRdrCB.add_feature(ftrPrefabDraw, matFlat); - } - - if (rFW.get_interface_id(sceneCtx).has_value()) { - scnRdrCB.add_feature(ftrVehicleControl); - scnRdrCB.add_feature(ftrVehicleSpawnDraw); - } else { - scnRdrCB.add_feature(ftrCameraFree); - } if (rFW.get_interface_id(sceneCtx).has_value()) { - scnRdrCB.add_feature(ftrMagicRocketThrustIndicator, TplPkgIdMaterialId{defaultPkg, matFlat}); + //scnRdrCB.add_feature(ftrMagicRocketThrustIndicator, TplPkgIdMaterialId{defaultPkg, matFlat}); } auto &rScnRenderGd = rFW.data_get(gdScn.di.scnRenderGd); diff --git a/src/gdextension/scenarios.cpp b/src/gdextension/scenarios.cpp index 7caa3e1d..032a8c78 100644 --- a/src/gdextension/scenarios.cpp +++ b/src/gdextension/scenarios.cpp @@ -34,11 +34,8 @@ #include #include #include -#include #include -#include - #include using namespace adera; using namespace ftr_inter; @@ -94,6 +91,7 @@ static ScenarioMap_t make_scenarios() add_floor(rFW, sceneCtx, pkg, 4); }}); +/* add_scenario({ .name = "vehicles", .brief = "Physics scenario but with Vehicles", @@ -175,7 +173,7 @@ static ScenarioMap_t make_scenarios() } }}); - +*/ return scenarioMap; } diff --git a/src/gdextension/sessions/godot.cpp b/src/gdextension/sessions/godot.cpp index 0c02b3be..a6d5bea8 100644 --- a/src/gdextension/sessions/godot.cpp +++ b/src/gdextension/sessions/godot.cpp @@ -40,7 +40,6 @@ #include #include -#include #include #include diff --git a/src/osp/activescene/prefab_fn.cpp b/src/osp/activescene/prefab_fn.cpp deleted file mode 100644 index 4204f46b..00000000 --- a/src/osp/activescene/prefab_fn.cpp +++ /dev/null @@ -1,270 +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 "prefab_fn.h" -#include "basic_fn.h" - -#include "../core/Resources.h" -#include "../vehicles/ImporterData.h" - -#include -#include - -using Corrade::Containers::ArrayView; - -using osp::restypes::gc_importer; - -namespace osp::active -{ - -void SysPrefabInit::create_activeents( - ACtxPrefabs& rPrefabs, - ACtxBasic& rBasic, - Resources& rResources) -{ - // Count number of entities needed to be created - std::size_t totalEnts = 0; - for (TmpPrefabRequest const& rPfBasic : rPrefabs.spawnRequest) - { - auto const& rPrefabData = rResources.data_get(gc_importer, rPfBasic.m_importerRes); - auto const& objects = rPrefabData.m_prefabs[rPfBasic.m_prefabId]; - - totalEnts += objects.size(); - } - - // Create entities - rPrefabs.newEnts.resize(totalEnts); - rBasic.m_activeIds.create(std::begin(rPrefabs.newEnts), std::end(rPrefabs.newEnts)); - - // Assign new entities to each prefab to create - rPrefabs.spawnedEntsOffset.resize(rPrefabs.spawnRequest.size()); - auto itEntAvailable = std::begin(rPrefabs.newEnts); - auto itPfEntSpanOut = std::begin(rPrefabs.spawnedEntsOffset); - for (TmpPrefabRequest& rPfBasic : rPrefabs.spawnRequest) - { - auto const& rPrefabData = rResources.data_get(gc_importer, rPfBasic.m_importerRes); - auto const& objects = rPrefabData.m_prefabs[rPfBasic.m_prefabId]; - - (*itPfEntSpanOut) = { &(*itEntAvailable), objects.size() }; - - std::advance(itEntAvailable, objects.size()); - std::advance(itPfEntSpanOut, 1); - } - - assert(itEntAvailable == std::end(rPrefabs.newEnts)); -} - -void SysPrefabInit::add_to_subtree( - TmpPrefabRequest const& basic, - ArrayView ents, - Resources const& rResources, - SubtreeBuilder& bldPrefab) noexcept -{ - auto const &rImportData = rResources.data_get( - gc_importer, basic.m_importerRes); - auto const &rPrefabData = rResources.data_get( - gc_importer, basic.m_importerRes); - - auto const& objs = rPrefabData.m_prefabs[basic.m_prefabId]; - auto const& parents = rPrefabData.m_prefabParents[basic.m_prefabId]; - - auto itObj = std::begin(objs); - auto itEnt = std::begin(ents); - - auto const add_child_recurse - = [&rImportData, &itObj, &itEnt, &parents] (auto&& self, SubtreeBuilder& bldParent) -> void - { - std::size_t const descendants = rImportData.m_objDescendants[*itObj]; - auto bldChildren = bldParent.add_child(*itEnt, descendants); - auto children = rImportData.m_objChildren[*itObj]; - - std::advance(itObj, 1); - std::advance(itEnt, 1); - - for ([[maybe_unused]] ObjId const child : children) - { - self(self, bldChildren); - } - }; - - add_child_recurse(add_child_recurse, bldPrefab); - - assert(itObj == std::end(objs)); - assert(itEnt == std::end(ents)); -} - -void SysPrefabInit::init_transforms( - ACtxPrefabs const& rPrefabs, - Resources const& rResources, - ACompTransformStorage_t& rTransform) noexcept -{ - auto itPfEnts = rPrefabs.spawnedEntsOffset.begin(); - - for (TmpPrefabRequest const& rPfBasic : rPrefabs.spawnRequest) - { - auto const &rImportData = rResources.data_get( - gc_importer, rPfBasic.m_importerRes); - auto const &rPrefabData = rResources.data_get( - gc_importer, rPfBasic.m_importerRes); - - auto const objects = rPrefabData.m_prefabs[rPfBasic.m_prefabId]; - auto const parents = rPrefabData.m_prefabParents[rPfBasic.m_prefabId]; - - for (std::size_t i = 0; i < objects.size(); ++i) - { - Matrix4 const& transform = (parents[i] == -1) - ? *rPfBasic.m_pTransform - : rImportData.m_objTransforms[objects[i]]; - ActiveEnt const ent = (*itPfEnts)[i]; - rTransform.emplace(ent, transform); - } - - ++itPfEnts; - } -} - -void SysPrefabInit::init_info( - ACtxPrefabs& rPrefabs, - Resources const& rResources) noexcept -{ - auto itPfEnts = rPrefabs.spawnedEntsOffset.begin(); - - for (TmpPrefabRequest const& rPfBasic : rPrefabs.spawnRequest) - { - auto const &rImportData = rResources.data_get( - gc_importer, rPfBasic.m_importerRes); - auto const &rPrefabData = rResources.data_get( - gc_importer, rPfBasic.m_importerRes); - - auto const ents = ArrayView{*itPfEnts}; - auto const objects = rPrefabData.m_prefabs[rPfBasic.m_prefabId]; - auto const parents = rPrefabData.m_prefabParents[rPfBasic.m_prefabId]; - - for (std::size_t i = 0; i < objects.size(); ++i) - { - ActiveEnt const ent = ents[i]; - PrefabInstanceInfo &rInfo = rPrefabs.instanceInfo[ent]; - rInfo.importer = rPfBasic.m_importerRes; - rInfo.prefab = rPfBasic.m_prefabId; - rInfo.obj = static_cast(i); - - if (parents[i] == -1) - { - rPrefabs.roots.insert(ent); - } - } - - ++itPfEnts; - } -} - -void SysPrefabInit::init_physics( - ACtxPrefabs const& rPrefabs, - Resources const& rResources, - ACtxPhysics& rCtxPhys) noexcept -{ - - auto itPfEnts = rPrefabs.spawnedEntsOffset.begin(); - - for (TmpPrefabRequest const& rPfBasic : rPrefabs.spawnRequest) - { - auto const &rImportData = rResources.data_get( - gc_importer, rPfBasic.m_importerRes); - auto const &rPrefabData = rResources.data_get( - gc_importer, rPfBasic.m_importerRes); - - auto const ents = ArrayView{*itPfEnts}; - auto const objects = lgrn::Span {rPrefabData.m_prefabs[rPfBasic.m_prefabId]}; - auto const parents = lgrn::Span {rPrefabData.m_prefabParents[rPfBasic.m_prefabId]}; - -#if 0 - auto const assign_dyn_recurse = [&rCtxPhys, ents, objects, parents] (auto const& self, int objectId, ActiveEnt ent) -> void - { - int const parentId = parents[objectId]; - if (parentId == -1) - { - return; - } - - ActiveEnt const parentEnt = ents[parentId]; - - if ( ! rCtxPhys.m_totalDyn.contains(parentEnt) ) - { - rCtxPhys.m_totalDyn.emplace(parentEnt); - } - - self(self, parentId, parentEnt); - }; -#endif - - auto const assign_collider_recurse - = [&rHasColliders = rCtxPhys.m_hasColliders, ents, objects, parents] - (auto const& self, int objectId, ActiveEnt ent) -> void - { - if (rHasColliders.contains(ent)) - { - return; // HasColliders bit already set, this means all ancestors have it set too - } - rHasColliders.insert(ent); - - int const parentId = parents[objectId]; - - if (parentId != -1) - { - self(self, parentId, ents[parentId]); - } - }; - - for (std::size_t i = 0; i < objects.size(); ++i) - { - ActiveEnt const ent = ents[i]; - int const objectId = objects[i]; - float const mass = rPrefabData.m_objMass[objectId]; - EShape const shape = rPrefabData.m_objShape[objectId]; - - - rCtxPhys.m_shape[ent] = shape; - - if (mass != 0.0f) - { - Vector3 const scale = rImportData.m_objTransforms[objectId].scaling(); - Vector3 const inertia = collider_inertia_tensor(shape, scale, mass); - Vector3 const offset{0.0f, 0.0f, 0.0f}; - rCtxPhys.m_mass.emplace( ent, ACompMass{ offset, inertia, mass } ); - - //assign_dyn_recurse(assign_dyn_recurse, objectId, ent); - } - - if ( (mass != 0.0f) || (shape != EShape::None) ) - { - assign_collider_recurse(assign_collider_recurse, objectId, ent); - } - } - - std::advance(itPfEnts, 1); - } -} - - -} // namespace osp::active diff --git a/src/osp/activescene/prefab_fn.h b/src/osp/activescene/prefab_fn.h deleted file mode 100644 index 7e407b6a..00000000 --- a/src/osp/activescene/prefab_fn.h +++ /dev/null @@ -1,105 +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 OTHEfR DEALINGS IN THE - * SOFTWARE. - */ -#pragma once - -#include "basic_fn.h" -#include "physics.h" - -#include "../core/array_view.h" -#include "../core/resourcetypes.h" -#include "../vehicles/prefabs.h" - -#include -#include - -namespace osp::active -{ - -/** - * @brief Data needed to initialize a Prefab - * - * This allows separate systems (doing physics, hierarchy, drawables, ...) to - * work in parallel on initializing a prefab. - * - * Intended to be created and quickly destroyed once the prefab is created. - * This is often the span of a single frame. - */ -struct TmpPrefabRequest -{ - ResId m_importerRes{lgrn::id_null()}; - PrefabId m_prefabId; - Matrix4 const* m_pTransform{nullptr}; -}; - -struct PrefabInstanceInfo -{ - ResId importer { lgrn::id_null() }; - PrefabId prefab { lgrn::id_null() }; - ObjId obj { lgrn::id_null() }; -}; - -struct ACtxPrefabs -{ - std::vector spawnRequest; - std::vector< ArrayView > spawnedEntsOffset; - std::vector newEnts; - - osp::active::ActiveEntSet_t roots; - KeyedVec instanceInfo; -}; - -class SysPrefabInit -{ -public: - - static void create_activeents( - ACtxPrefabs& rPrefabs, - ACtxBasic& rBasic, - Resources& rResources); - - static void add_to_subtree( - TmpPrefabRequest const& basic, - ArrayView ents, - Resources const& rResources, - SubtreeBuilder& rSubtree) noexcept; - - static void init_transforms( - ACtxPrefabs const& rPrefabs, - Resources const& rResources, - ACompTransformStorage_t& rTransform) noexcept; - - static void init_info( - ACtxPrefabs& rPrefabs, - Resources const& rResources) noexcept; - - static void init_physics( - ACtxPrefabs const& rPrefabs, - Resources const& rResources, - ACtxPhysics& rCtxPhys) noexcept; - -}; - - -} // namespace osp::active diff --git a/src/osp/activescene/vehicles.h b/src/osp/activescene/vehicles.h deleted file mode 100644 index 6a913c45..00000000 --- a/src/osp/activescene/vehicles.h +++ /dev/null @@ -1,114 +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. - */ -#pragma once - -#include "active_ent.h" - -#include "../core/array_view.h" -#include "../core/keyed_vector.h" -#include "../core/math_types.h" -#include "../link/machines.h" -#include "../vehicles/prefabs.h" - -#include -#include - -#include - -namespace osp::active -{ - -using PartId = uint32_t; -using WeldId = uint32_t; - -struct ACtxLinks -{ - ACtxLinks() = default; - OSP_MOVE_ONLY_CTOR_ASSIGN(ACtxLinks); - link::Machines machines; - KeyedVec nodePerType; -}; - -struct ACtxParts -{ - using MapPartToMachines_t = lgrn::IntArrayMultiMap; - - lgrn::IdRegistryStl partIds; - //KeyedVec partPrefabs; - KeyedVec partTransformWeld; ///< Part's transform relative to the weld it's part of - std::vector partDirty; - - lgrn::IdRegistryStl weldIds; - std::vector weldDirty; - - lgrn::IntArrayMultiMap weldToParts; - KeyedVec partToWeld; - - MapPartToMachines_t partToMachines; - KeyedVec machineToPart; - - KeyedVec partToActive; - KeyedVec activeToPart; - - KeyedVec weldToActive; -}; - - -using SpVehicleId = StrongId; -using SpPartId = StrongId; -using SpWeldId = StrongId; -using SpMachAnyId = StrongId; - -struct ACtxVehicleSpawn -{ - struct TmpToInit - { - Vector3 position; - Vector3 velocity; - Quaternion rotation; - }; - - std::size_t new_vehicle_count() const noexcept - { - return spawnRequest.size(); - } - - KeyedVec spawnRequest; - - KeyedVec spawnedParts; - KeyedVec spawnedPartOffsets; - - KeyedVec partToSpawned; - KeyedVec spawnedPrefabs; - - KeyedVec spawnedWelds; - KeyedVec spawnedWeldOffsets; - - KeyedVec rootEnts; - - KeyedVec spawnedMachs; -}; - -} // namespace osp::active diff --git a/src/osp/drawing/prefab_draw.cpp b/src/osp/drawing/prefab_draw.cpp deleted file mode 100644 index 649b328a..00000000 --- a/src/osp/drawing/prefab_draw.cpp +++ /dev/null @@ -1,259 +0,0 @@ -/** - * Open Space Program - * Copyright © 2019-2023 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 OTHEfR DEALINGS IN THE - * SOFTWARE. - */ - -#include "prefab_draw.h" -#include "drawing_fn.h" - -#include -#include - -#include -#include - -using namespace osp; -using namespace osp::active; -using namespace osp::draw; - -using osp::restypes::gc_importer; - -void SysPrefabDraw::init_drawents( - ACtxPrefabs& rPrefabs, - Resources& rResources, - ACtxSceneRender& rScnRender) -{ - auto itPfEnts = rPrefabs.spawnedEntsOffset.begin(); - - for (TmpPrefabRequest const& request : rPrefabs.spawnRequest) - { - auto const &rImportData = rResources.data_get(gc_importer, request.m_importerRes); - auto const &rPrefabData = rResources.data_get (gc_importer, request.m_importerRes); - auto const objects = rPrefabData.m_prefabs[request.m_prefabId]; - auto const ents = ArrayView{*itPfEnts}; - - for (std::size_t i = 0; i < objects.size(); ++i) - { - int const meshImportId = rImportData.m_objMeshes[objects[i]]; - if (meshImportId == -1) - { - continue; - } - - ActiveEnt const ent = ents[i]; - rScnRender.m_activeToDraw[ent] = rScnRender.m_drawIds.create(); - } - - ++itPfEnts; - } -} - -void SysPrefabDraw::resync_drawents( - ACtxPrefabs& rPrefabs, - Resources& rResources, - ACtxBasic const& rBasic, - ACtxSceneRender& rScnRender) -{ - for (ActiveEnt const root : rPrefabs.roots) - { - PrefabInstanceInfo const &rRootInfo = rPrefabs.instanceInfo[root]; - - LGRN_ASSERT(rRootInfo.prefab != lgrn::id_null()); - LGRN_ASSERT(rRootInfo.importer != lgrn::id_null()); - - auto const &rImportData = rResources.data_get(gc_importer, rRootInfo.importer); - auto const &rPrefabData = rResources.data_get (gc_importer, rRootInfo.importer); - auto const objects = rPrefabData.m_prefabs[rRootInfo.prefab]; - - for (ActiveEnt const ent : SysSceneGraph::descendants(rBasic.m_scnGraph, root)) - { - PrefabInstanceInfo const &rInfo = rPrefabs.instanceInfo[ent]; - - int const meshImportId = rImportData.m_objMeshes[objects[rInfo.obj]]; - if (meshImportId == -1) - { - continue; - } - - if ( ! rScnRender.m_activeToDraw[ent].has_value() ) - { - rScnRender.m_activeToDraw[ent] = rScnRender.m_drawIds.create(); - } - } - } -} - -void SysPrefabDraw::init_mesh_texture_material( - ACtxPrefabs& rPrefabs, - Resources& rResources, - ACtxDrawing& rDrawing, - ACtxDrawingRes& rDrawingRes, - ACtxSceneRender& rScnRender, - MaterialId material) -{ - auto itPfEnts = rPrefabs.spawnedEntsOffset.begin(); - - for (TmpPrefabRequest const& request : rPrefabs.spawnRequest) - { - auto const &rImportData = rResources.data_get(gc_importer, request.m_importerRes); - auto const &rPrefabData = rResources.data_get (gc_importer, request.m_importerRes); - auto const objects = lgrn::Span{rPrefabData.m_prefabs[request.m_prefabId]}; - auto const parents = lgrn::Span{rPrefabData.m_prefabParents[request.m_prefabId]}; - auto const ents = ArrayView{*itPfEnts}; - - // All ancestors of each entity that has a mesh - auto const needs_draw_transform - = [&parents, &ents, &rDrawing, &needDrawTf = rScnRender.m_needDrawTf] - (auto&& self, int const object, ActiveEnt const ent) noexcept -> void - { - needDrawTf.insert(ent); - - int const parentObj = parents[object]; - - if (parentObj != -1) - { - self(self, parentObj, ents[parentObj]); - } - }; - - for (std::size_t i = 0; i < objects.size(); ++i) - { - ActiveEnt const ent = ents[i]; - - // Check if object has mesh - int const meshImportId = rImportData.m_objMeshes[objects[i]]; - if (meshImportId == -1) - { - continue; - } - - needs_draw_transform(needs_draw_transform, objects[i], ent); - - DrawEnt const drawEnt = rScnRender.m_activeToDraw[ent]; - - if (rScnRender.m_mesh[drawEnt].has_value()) { continue; }; - - osp::ResId const meshRes = rImportData.m_meshes[meshImportId]; - MeshId const meshId = SysRender::own_mesh_resource(rDrawing, rDrawingRes, rResources, meshRes); - rScnRender.m_mesh[drawEnt] = rDrawing.m_meshRefCounts.ref_add(meshId); - rScnRender.m_meshDirty.push_back(drawEnt); - - int const matImportId = rImportData.m_objMaterials[objects[i]]; - - if (Magnum::Trade::MaterialData const &mat = *rImportData.m_materials.at(matImportId); - mat.types() & Magnum::Trade::MaterialType::PbrMetallicRoughness) - { - auto const& matPbr = mat.as(); - if (auto const baseColor = matPbr.baseColorTexture(); - baseColor != -1) - { - osp::ResId const texRes = rImportData.m_textures[baseColor]; - TexId const texId = SysRender::own_texture_resource(rDrawing, rDrawingRes, rResources, texRes); - rScnRender.m_diffuseTex[drawEnt] = rDrawing.m_texRefCounts.ref_add(texId); - rScnRender.m_diffuseTexDirty.push_back(drawEnt); - } - } - - rScnRender.m_opaque.insert(drawEnt); - rScnRender.m_visible.insert(drawEnt); - - if (material != lgrn::id_null()) - { - rScnRender.m_materials[material].m_dirty.push_back(drawEnt); - rScnRender.m_materials[material].m_ents.insert(drawEnt); - } - } - - ++itPfEnts; - } -} - - -void SysPrefabDraw::resync_mesh_texture_material( - ACtxPrefabs& rPrefabs, - Resources& rResources, - ACtxBasic const& rBasic, - ACtxDrawing& rDrawing, - ACtxDrawingRes& rDrawingRes, - ACtxSceneRender& rScnRender, - MaterialId material) -{ - for (ActiveEnt const root : rPrefabs.roots) - { - PrefabInstanceInfo const &rRootInfo = rPrefabs.instanceInfo[root]; - - LGRN_ASSERT(rRootInfo.prefab != lgrn::id_null()); - LGRN_ASSERT(rRootInfo.importer != lgrn::id_null()); - - auto const &rImportData = rResources.data_get(gc_importer, rRootInfo.importer); - auto const &rPrefabData = rResources.data_get (gc_importer, rRootInfo.importer); - auto const objects = lgrn::Span{rPrefabData.m_prefabs[rRootInfo.prefab]}; - - for (ActiveEnt const ent : SysSceneGraph::descendants(rBasic.m_scnGraph, root)) - { - PrefabInstanceInfo const &rInfo = rPrefabs.instanceInfo[ent]; - - int const meshImportId = rImportData.m_objMeshes[objects[rInfo.obj]]; - if (meshImportId == -1) - { - continue; - } - - SysRender::needs_draw_transforms(rBasic.m_scnGraph, rScnRender.m_needDrawTf, ent); - - DrawEnt const drawEnt = rScnRender.m_activeToDraw[ent]; - - if (rScnRender.m_mesh[drawEnt].has_value()) { continue; }; - - osp::ResId const meshRes = rImportData.m_meshes[meshImportId]; - MeshId const meshId = SysRender::own_mesh_resource(rDrawing, rDrawingRes, rResources, meshRes); - rScnRender.m_mesh[drawEnt] = rDrawing.m_meshRefCounts.ref_add(meshId); - rScnRender.m_meshDirty.push_back(drawEnt); - - int const matImportId = rImportData.m_objMaterials[objects[rPrefabs.instanceInfo[ent].obj]]; - - if (Magnum::Trade::MaterialData const &mat = *rImportData.m_materials.at(matImportId); - mat.types() & Magnum::Trade::MaterialType::PbrMetallicRoughness) - { - auto const& matPbr = mat.as(); - if (auto const baseColor = matPbr.baseColorTexture(); - baseColor != -1) - { - osp::ResId const texRes = rImportData.m_textures[baseColor]; - TexId const texId = SysRender::own_texture_resource(rDrawing, rDrawingRes, rResources, texRes); - rScnRender.m_diffuseTex[drawEnt] = rDrawing.m_texRefCounts.ref_add(texId); - rScnRender.m_diffuseTexDirty.push_back(drawEnt); - } - } - - rScnRender.m_opaque.insert(drawEnt); - rScnRender.m_visible.insert(drawEnt); - - if (material != lgrn::id_null()) - { - rScnRender.m_materials[material].m_dirty.push_back(drawEnt); - rScnRender.m_materials[material].m_ents.insert(drawEnt); - } - } - } -} diff --git a/src/osp/drawing/prefab_draw.h b/src/osp/drawing/prefab_draw.h deleted file mode 100644 index 9694e3e2..00000000 --- a/src/osp/drawing/prefab_draw.h +++ /dev/null @@ -1,71 +0,0 @@ -/** - * Open Space Program - * Copyright © 2019-2023 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 OTHEfR DEALINGS IN THE - * SOFTWARE. - */ -#pragma once - -#include "drawing.h" -#include "../activescene/prefab_fn.h" -#include "../core/array_view.h" - -namespace osp::draw -{ - -class SysPrefabDraw -{ - using ACtxBasic = osp::active::ACtxBasic; - using ACtxPrefabs = osp::active::ACtxPrefabs; - using ActiveEnt = osp::active::ActiveEnt; - using TmpPrefabRequest = osp::active::TmpPrefabRequest; -public: - - static void init_drawents( - ACtxPrefabs& rPrefabs, - Resources& rResources, - ACtxSceneRender& rScnRender); - - static void resync_drawents( - ACtxPrefabs& rPrefabs, - Resources& rResources, - ACtxBasic const& rBasic, - ACtxSceneRender& rScnRender); - - static void init_mesh_texture_material( - ACtxPrefabs& rPrefabs, - Resources& rResources, - ACtxDrawing& rDrawing, - ACtxDrawingRes& rDrawingRes, - ACtxSceneRender& rScnRender, - MaterialId material = lgrn::id_null()); - - static void resync_mesh_texture_material( - ACtxPrefabs& rPrefabs, - Resources& rResources, - ACtxBasic const& rBasic, - ACtxDrawing& rDrawing, - ACtxDrawingRes& rDrawingRes, - ACtxSceneRender& rScnRender, - MaterialId material = lgrn::id_null()); -}; - -} // namespace osp::active diff --git a/src/osp/link/machines.cpp b/src/osp/link/machines.cpp deleted file mode 100644 index 696354e8..00000000 --- a/src/osp/link/machines.cpp +++ /dev/null @@ -1,100 +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 "machines.h" - -namespace osp::link -{ - -void copy_nodes( - Nodes const &rSrcNodes, - Machines const &rSrcMach, - Corrade::Containers::ArrayView remapMach, - Nodes &rDstNodes, - Machines &rDstMach, - Corrade::Containers::ArrayView remapNode) -{ - using lgrn::Span; - - // Create new node IDs - for (NodeId const srcNode : rSrcNodes.nodeIds) - { - NodeId const dstNode = rDstNodes.nodeIds.create(); - remapNode[srcNode] = dstNode; - } - - // Copy node-to-machine connections - rDstNodes.nodeToMach.ids_reserve(rDstNodes.nodeIds.capacity()); - rDstNodes.nodeToMach.data_reserve(rDstNodes.nodeToMach.data_size() - + rSrcNodes.nodeToMach.data_size()); - for (NodeId const srcNode : rSrcNodes.nodeIds) - { - NodeId const dstNode = remapNode[srcNode]; - Span srcJunction = rSrcNodes.nodeToMach[srcNode]; - rDstNodes.nodeToMach.emplace(dstNode, srcJunction.size()); - Span dstJuncton = rDstNodes.nodeToMach[dstNode]; - - auto dstJuncIt = std::begin(dstJuncton); - for (Junction const& srcJunc : srcJunction) - { - MachTypeId const machType = srcJunc.type; - MachAnyId const srcMach = rSrcMach.perType[machType].localToAny[srcJunc.local]; - MachAnyId const dstMach = remapMach[srcMach]; - MachLocalId const dstLocal = rDstMach.machToLocal[dstMach]; - - dstJuncIt->local = dstLocal; - dstJuncIt->type = machType; - dstJuncIt->custom = srcJunc.custom; - - std::advance(dstJuncIt, 1); - } - } - - // copy mach-to-node connections - rDstNodes.machToNode.ids_reserve(rDstMach.ids.capacity()); - rDstNodes.machToNode.data_reserve(rDstNodes.machToNode.data_size() - + rSrcNodes.machToNode.data_size()); - for (MachAnyId const srcMach : rSrcMach.ids) - { - if (rSrcNodes.machToNode.contains(srcMach)) - { - Span srcPorts = rSrcNodes.machToNode[srcMach]; - MachAnyId const dstMach = remapMach[srcMach]; - rDstNodes.machToNode.emplace(dstMach, srcPorts.size()); - Span dstPorts = rDstNodes.machToNode[dstMach]; - - auto dstPortIt = std::begin(dstPorts); - for (NodeId const srcNode : srcPorts) - { - *dstPortIt = (srcNode != lgrn::id_null()) - ? remapNode[srcNode] - : lgrn::id_null(); - - std::advance(dstPortIt, 1); - } - } - } -} - -} // namespace osp::link diff --git a/src/osp/link/machines.h b/src/osp/link/machines.h deleted file mode 100644 index 86d4ddd9..00000000 --- a/src/osp/link/machines.h +++ /dev/null @@ -1,152 +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. - */ -#pragma once - -#include "../core/array_view.h" -#include "../core/copymove_macros.h" -#include "../core/global_id.h" -#include "../core/keyed_vector.h" - - -#include -#include -#include -#include - -#include -#include - -namespace osp::link -{ - -using MachTypeId = uint16_t; -using MachAnyId = uint32_t; -using MachLocalId = uint32_t; - -using NodeTypeId = uint16_t; -using NodeId = uint32_t; - -using PortId = uint16_t; -using JunctionId = uint16_t; -using JuncCustom = uint16_t; - -using MachTypeReg_t = GlobalIdReg; -using NodeTypeReg_t = GlobalIdReg; - -inline NodeTypeId const gc_ntSigFloat = NodeTypeReg_t::create(); - -/** - * @brief Keeps track of Machines of a certain type that exists - */ -struct PerMachType -{ - lgrn::IdRegistryStl localIds; - std::vector localToAny; -}; - -/** - * @brief Keeps track of all Machines that exist and what type they are - */ -struct Machines -{ - lgrn::IdRegistryStl ids; - - std::vector machTypes; - std::vector machToLocal; - - std::vector perType; -}; - -struct MachineUpdater -{ - alignas(64) std::atomic requestMachineUpdateLoop {false}; - - lgrn::IdSetStl machTypesDirty; - - // [MachTypeId][MachLocalId] - osp::KeyedVec> localDirty; -}; - -struct MachinePair -{ - MachLocalId local {lgrn::id_null()}; - MachTypeId type {lgrn::id_null()}; -}; - -struct Junction -{ - MachLocalId local {lgrn::id_null()}; - MachTypeId type {lgrn::id_null()}; - JuncCustom custom {0}; -}; - -/** - * @brief Connects Machines together with intermediate Nodes - */ -struct Nodes -{ - // reminder: IntArrayMultiMap is kind of like an - // std::vector< std::vector<...> > but more memory efficient - using NodeToMach_t = lgrn::IntArrayMultiMap; - using MachToNode_t = lgrn::IntArrayMultiMap; - - lgrn::IdRegistryStl nodeIds; - - // Node-to-Machine connections - // [NodeId][JunctionIndex] -> Junction (type, MachLocalId, custom int) - NodeToMach_t nodeToMach; - - // Corresponding Machine-to-Node connections - // [MachAnyId][PortIndex] -> NodeId - MachToNode_t machToNode; -}; - -struct PortEntry -{ - NodeTypeId type; - PortId port; - JuncCustom custom; -}; - -inline NodeId connected_node(lgrn::Span portSpan, PortId port) noexcept -{ - return (portSpan.size() > port) ? portSpan[port] : lgrn::id_null(); -} - -void copy_machines( - Machines const &rSrc, - Machines &rDst, - ArrayView remapMachOut); - -void copy_nodes( - Nodes const &rSrcNodes, - Machines const &rSrcMach, - ArrayView remapMach, - Nodes &rDstNodes, - Machines &rDstMach, - ArrayView remapNodeOut); - - -} // namespace osp::wire diff --git a/src/osp/link/signal.h b/src/osp/link/signal.h deleted file mode 100644 index 39249faf..00000000 --- a/src/osp/link/signal.h +++ /dev/null @@ -1,89 +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. - */ -#pragma once - -#include "machines.h" - -namespace osp::link -{ - -constexpr JuncCustom gc_sigIn = 0; -constexpr JuncCustom gc_sigOut = 1; - -template -using SignalValues_t = std::vector; - -template -struct UpdateNodes -{ - lgrn::IdSetStl nodeDirty; - SignalValues_t nodeNewValues; - - bool dirty{false}; - - void assign(NodeId node, VALUE_T value) - { - dirty = true; - nodeDirty.insert(node); - nodeNewValues[node] = std::forward(value); - } -}; - -template -bool update_signal_nodes( - RANGE_T const& toUpdate, - Nodes::NodeToMach_t const& nodeToMach, - Machines const& machines, - ArrayView newValues, - ArrayView currentValues, - MachineUpdater& rUpdMach) -{ - bool somethingNotified = false; - - for (uint32_t const node : toUpdate) - { - // Apply node value changes - currentValues[node] = newValues[node]; - - // Notify connected inputs - for (Junction junc : nodeToMach[node]) - { - if (junc.custom == gc_sigIn) - { - somethingNotified = true; - - // A machine of type "junc.m_type" has new values to read - rUpdMach.machTypesDirty.insert(junc.type); - - // Specify using local Id on which machine needs to update - rUpdMach.localDirty[junc.type].insert(junc.local); - } - } - } - - return somethingNotified; -} - -} // namespace osp::wire diff --git a/src/osp/vehicles/ImporterData.h b/src/osp/vehicles/ImporterData.h deleted file mode 100644 index 85c7513b..00000000 --- a/src/osp/vehicles/ImporterData.h +++ /dev/null @@ -1,99 +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. - */ -#pragma once - -#include "prefabs.h" - -#include "../core/resourcetypes.h" -#include "../scientific/shapes.h" - - -#include -#include - -#include -#include - -#include - -#include -#include - -namespace osp -{ - -/** - * @brief Describes a set of scene graphs that share data with each other - * - * Intended to be loaded from glTF files through any Magnum glTF loader - */ -struct ImporterData -{ - using OptMaterialData_t = Corrade::Containers::Optional; - using String = Corrade::Containers::String; - - // Owned resources - std::vector m_images; - std::vector m_textures; - std::vector m_meshes; - - std::vector m_materials; - - // Object data - // note: terminology for 'things' vary - // * Magnum: Object * glTF: Node * OSP & EnTT: Entity - - // Top-level nodes of each scene - // [scene Id][child object] - lgrn::IntArrayMultiMap m_scnTopLevel; - - std::vector m_objParents; - lgrn::IntArrayMultiMap m_objChildren; - std::vector m_objDescendants; - - std::vector m_objNames; - std::vector m_objTransforms; - - std::vector m_objMeshes; - std::vector m_objMaterials; -}; - -/** - * @brief Groups objects in an ImporterData intended to make them instantiable - */ -struct Prefabs -{ - // [prefab Id][object] - lgrn::IntArrayMultiMap m_prefabs; - lgrn::IntArrayMultiMap m_prefabParents; - - // Points to ImporterData::m_objNames - std::vector m_prefabNames; - - std::vector m_objShape; - std::vector m_objMass; -}; - -} // namespace osp diff --git a/src/osp/vehicles/blueprints.h b/src/osp/vehicles/blueprints.h deleted file mode 100644 index 9baab6a9..00000000 --- a/src/osp/vehicles/blueprints.h +++ /dev/null @@ -1,137 +0,0 @@ -/** - * Open Space Program - * Copyright © 2019-2020 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 "../core/math_types.h" -#include "../core/resourcetypes.h" - -namespace osp -{ - - -struct BlueprintMachine -{ - //NodeMap_t m_config; - - // Index to a BlueprintPart in BlueprintVehicle's m_blueprints - uint32_t m_partIndex; - // Index to a m_protoMachines in PrototypePart - uint16_t m_protoMachineIndex; -}; - -/** - * Specific information on a part in a vehicle: - * * Which kind of part - * * Enabled/disabled properties - * * Transformation - */ -struct BlueprintPart -{ - - BlueprintPart(uint32_t protoIndex, uint16_t machineCount, - Vector3 translation, Quaternion rotation, Vector3 scale) - : m_protoIndex(protoIndex) - , m_translation(translation) - , m_rotation(rotation) - , m_scale(scale) - , m_machineCount(machineCount) - { } - - uint32_t m_protoIndex; // index to BlueprintVehicle's m_partsUsed - - Vector3 m_translation; - Quaternion m_rotation; - Vector3 m_scale; - - uint16_t m_machineCount; -}; - -struct BlueprintWireLink -{ - // ie. Input/output; fuel flow priority - //NodeMap_t m_config; - - // Index to a BlueprintPart in BlueprintVehicle's m_blueprints - uint32_t m_partIndex; - - // Machine to link to, index to m_protoMachines in PrototypePart - uint16_t m_protoMachineIndex; - - // Machine's port to connect to - uint16_t m_port; -}; - -/** - * - */ -struct BlueprintWireNode -{ - - //NodeMap_t m_config; - - std::vector m_links; -}; - -struct BlueprintWirePanel -{ - // Index to a BlueprintPart in BlueprintVehicle's m_blueprints - uint32_t m_partIndex; - - // Machine to link to, index to m_protoMachines in PrototypePart - uint16_t m_protoMachineIndex; - - // Number of ports - uint16_t m_portCount; -}; - -/** - * Specific information on a vehicle - * * List of part blueprints - * * Attachments - * * Wiring - */ -struct BlueprintVehicle -{ - // Unique part Resources used - std::vector m_prototypes; - - // Arrangement of Individual Parts - std::vector m_blueprints; - - // Wire panels each machine has - // panel = m_wirePanels[wiretype id][i] - std::vector< std::vector > m_wirePanels; - - // Wires to connect - // wire = m_wireNodes[wiretype id][i] - std::vector< std::vector > m_wireNodes; - - // All machines in the vehicle - // machine = m_machines[machine id][i] - std::vector< std::vector > m_machines; - -}; - -} diff --git a/src/osp/vehicles/load_tinygltf.cpp b/src/osp/vehicles/load_tinygltf.cpp deleted file mode 100644 index 17dcc2e3..00000000 --- a/src/osp/vehicles/load_tinygltf.cpp +++ /dev/null @@ -1,470 +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 "load_tinygltf.h" -#include "ImporterData.h" - -#include "../core/Resources.h" -#include "../drawing/own_restypes.h" -#include "../util/logging.h" - -#include -#include - -#include -#include -#include -#include - -#include -#include -#include -#include - -using namespace osp; - -using Magnum::Trade::TinyGltfImporter; - -using Magnum::Trade::ImageData2D; -using Magnum::Trade::TextureData; -using Magnum::Trade::MeshData; -using Magnum::Trade::MaterialData; -using Magnum::Trade::SceneData; -using Magnum::Trade::SceneField; - -using Magnum::Int; -using Magnum::UnsignedInt; - -using PluginManager = Corrade::PluginManager::Manager; -using Corrade::Containers::Optional; -using Corrade::Containers::Pointer; -using Corrade::Containers::Array; -using Corrade::Containers::StridedArrayView1D; -using Corrade::Containers::Pair; - -using TinyGltfNodeExtras_t = std::vector; - -void osp::register_tinygltf_resources(Resources &rResources) -{ - rResources.data_register(restypes::gc_importer); -} - -static void load_gltf(TinyGltfImporter &rImporter, ResId res, std::string_view name, Resources &rResources, PkgId pkg) -{ - using namespace restypes; - - // Combine resource names. Maybe make this customizable - // ie: name = "dir/file.gltf" and resName = "mytexture" - // "dir/file.gltf:mytexture" - // "unnamed-[id]" is used as the resource name if it's empty - auto format_name = [name](std::string_view resName, UnsignedInt id) - { - if ( ! resName.empty()) - { - return SharedString::create_from_parts(name, ":", resName); - } - else - { - // i don't like std::to_string but screw it, fix it later - return SharedString::create_from_parts(name, ":unnamed-", std::to_string(id)); - } - }; - - auto &rImportData = rResources.data_add(restypes::gc_importer, res); - auto &rNodeExtras = rResources.data_add(restypes::gc_importer, res); - - // Allocate various data - rImportData.m_images .resize(rImporter.image2DCount()); - rImportData.m_textures .resize(rImporter.textureCount()); - rImportData.m_meshes .resize(rImporter.meshCount()); - rImportData.m_materials .resize(rImporter.materialCount()); - - // Allocate object data - UnsignedInt const objCount = rImporter.objectCount(); - rNodeExtras .resize(objCount); - rImportData.m_objNames .resize(objCount); - rImportData.m_objMeshes .resize(objCount, -1); - rImportData.m_objMaterials .resize(objCount, -1); - rImportData.m_objTransforms .resize(objCount); - rImportData.m_objParents .resize(objCount, -1); - rImportData.m_objDescendants.resize(objCount, 0); - - // Allocate object parent to children multimap - rImportData.m_objChildren.ids_reserve(objCount); - rImportData.m_objChildren.data_reserve(objCount); - - // Allocate for storing top-level nodes for each scene - rImportData.m_scnTopLevel.ids_reserve(rImporter.sceneCount()); - rImportData.m_scnTopLevel.data_reserve(rImporter.objectCount()); - - // Store images - for (UnsignedInt i = 0; i < rImporter.image2DCount(); i ++) - { - Optional img = rImporter.image2D(i); - - if ( ! bool(img) ) - { - continue; - } - - // Create and keep track of resource Id - ResId const imgRes = rResources.create(gc_image, pkg, format_name(rImporter.image2DName(i), i)); - rImportData.m_images[i] = rResources.owner_create(gc_image, imgRes); - - // Add image data to resource - rResources.data_add(gc_image, imgRes, std::move(*img)); - } - - // Store textures - for (UnsignedInt i = 0; i < rImporter.textureCount(); i ++) - { - Optional tex = rImporter.texture(i); - - if ( ! bool(tex) ) - { - continue; - } - - // Create and keep track of resource Id - ResId const texRes = rResources.create(gc_texture, pkg, format_name(rImporter.textureName(i), i)); - rImportData.m_textures[i] = rResources.owner_create(gc_texture, texRes); - - // Add data to resource - rResources.data_add(gc_texture, texRes, std::move(*tex)); - - // Keep track of which image this texture uses - if (ResIdOwner_t const& imgRes = rImportData.m_images.at(tex->image()); - imgRes.has_value()) - { - ResIdOwner_t imgOwner = rResources.owner_create(gc_image, imgRes); - rResources.data_add(gc_texture, texRes, TextureImgSource{std::move(imgOwner)} ); - } - } - - // Store meshes - for (UnsignedInt i = 0; i < rImporter.meshCount(); i ++) - { - Optional mesh = rImporter.mesh(i); - - if ( ! bool(mesh) ) - { - continue; - } - - ResId const meshRes = rResources.create(gc_mesh, pkg, format_name(rImporter.meshName(i), i)); - rResources.data_add(gc_mesh, meshRes, std::move(*mesh)); - rImportData.m_meshes[i] = rResources.owner_create(gc_mesh, meshRes); - } - - // Store materials - for (UnsignedInt i = 0; i < rImporter.materialCount(); i ++) - { - rImportData.m_materials[i] = rImporter.material(i); - } - - // Iterate objects to store names and custom properties - for (UnsignedInt obj = 0; obj < rImporter.objectCount(); obj ++) - { - tinygltf::Model const *pModel = rImporter.importerState(); - - rImportData.m_objNames[obj] = rImporter.objectName(obj); - rNodeExtras[obj] = pModel->nodes[obj].extras; - } - - // Temporary child count of each object. Later stored in m_objChildren - Array objChildCount(Corrade::ValueInit, objCount); - - // Temporary vector of children for current object being iterated - std::vector topLevel; - topLevel.reserve(rImporter.objectCount()); - - // Iterate scenes and their objects - for (UnsignedInt scn = 0; scn < rImporter.sceneCount(); scn ++) - { - Optional const scene = rImporter.scene(scn); - - if ( ! bool(scene)) - { - rImportData.m_scnTopLevel.emplace(scn, {}); - continue; - } - - // Iterate scene objects with parents - // Stores parents, transforms, and top-level objects for this scene - { - StridedArrayView1D const parentsMap - = scene->mapping(SceneField::Parent); - StridedArrayView1D const parents - = scene->field(SceneField::Parent); - - for (UnsignedInt j = 0; j < parentsMap.size(); j ++) - { - UnsignedInt const obj = parentsMap[j]; - Int const objParent = parents[j]; - - // Store object parents - rImportData.m_objParents[obj] = objParent; - - if (objParent != -1) - { - objChildCount[objParent] ++; - } - else - { - topLevel.push_back(obj); - } - - // Also store transforms here - if (Optional objTf = scene->transformation3DFor(obj); - bool(objTf)) - { - rImportData.m_objTransforms[obj] = *objTf; - } - } - - // Store top-level objects - rImportData.m_scnTopLevel.emplace( - scn, std::begin(topLevel), std::end(topLevel)); - topLevel.clear(); - } - - // Iterate scene objects with meshes and materials - { - - StridedArrayView1D const meshMap - = scene->mapping(SceneField::Mesh); - - // Assign meshes if present - if (Optional const meshesFieldId - = scene->findFieldId(SceneField::Mesh); - bool(meshesFieldId)) - { - StridedArrayView1D const meshes - = scene->field(SceneField::Mesh); - for (UnsignedInt j = 0; j < meshMap.size(); j ++) - { - rImportData.m_objMeshes[meshMap[j]] = meshes[j]; - } - } - - // Assign materials if present - if (Optional const matsFieldId - = scene->findFieldId(SceneField::MeshMaterial); - bool(matsFieldId)) - { - StridedArrayView1D const materials - = scene->field(SceneField::MeshMaterial); - - for (UnsignedInt j = 0; j < meshMap.size(); j ++) - { - rImportData.m_objMaterials[meshMap[j]] = materials[j]; - } - } - - } - - } - - // Reserve partitions for all objects with children, initialize to -1 - for (UnsignedInt obj = 0; obj < objCount; obj ++) - { - if (int childCount = objChildCount[obj]; - childCount != 0) - { - ObjId *pChildren = rImportData.m_objChildren.emplace(obj, childCount); - std::fill_n(pChildren, childCount, -1); - - // Also total up descendant counts here - ObjId parent = obj; - while (parent != -1) - { - rImportData.m_objDescendants[parent] += childCount; - parent = rImportData.m_objParents[parent]; - } - } - } - - // Add children to their parent's list of children - for (UnsignedInt obj = 0; obj < objCount; obj ++) - { - if (ObjId objParent = rImportData.m_objParents[obj]; - objParent != -1) - { - // Get parent's span of children - auto siblings = rImportData.m_objChildren[objParent]; - - // Linear search for an empty spot (-1) - auto pSpot = std::find(std::begin(siblings), std::end(siblings), -1); - assert(pSpot != std::end(siblings)); - - *pSpot = obj; // add self to parent's children - } - } -} - - -ResId osp::load_tinygltf_file(std::string_view filepath, Resources &rResources, PkgId pkg) -{ - PluginManager pluginManager; - - - // Create Importer resource - ResId const res = rResources.create(restypes::gc_importer, pkg, SharedString::create(filepath)); - TinyGltfImporter importer{pluginManager}; - - importer.openFile(filepath); - - if (!importer.isOpened() || importer.defaultScene() == -1) - { - // TODO: delete resource (not yet implemented) - OSP_LOG_ERROR("Could not open file {}", filepath); - return lgrn::id_null(); - } - - load_gltf(importer, res, filepath, rResources, pkg); - - importer.close(); - - return res; -} - -static EShape shape_from_name(std::string_view name) noexcept -{ - if (name == "cube") { return EShape::Box; } - else if (name == "cylinder") { return EShape::Cylinder; } - - OSP_LOG_WARN("Unknown shape: {}", name); - return EShape::None; -} - -void osp::assigns_prefabs_tinygltf(Resources &rResources, ResId importer) -{ - - auto const *pImportData = rResources.data_try_get(restypes::gc_importer, importer); - auto const *pNodeExtras = rResources.data_try_get(restypes::gc_importer, importer); - - if (pImportData == nullptr || pNodeExtras == nullptr) - { - OSP_LOG_WARN("Resource {} (gc_importer #{}) does not contain the correct data for loading prefabs.", - rResources.name(restypes::gc_importer, importer), std::size_t(importer)); - OSP_LOG_WARN("* has ImporterData: {}", pImportData != nullptr); - OSP_LOG_WARN("* has TinyGltf Extras: {}", pNodeExtras != nullptr); - return; - } - - if (pImportData->m_scnTopLevel.ids_count() == 0) - { - OSP_LOG_WARN("Resource {} (gc_importer #{}) has no scenes!"); - return; - } - - auto const topLevelSpan = pImportData->m_scnTopLevel[0]; - - auto &rPrefabs = rResources.data_add(restypes::gc_importer, importer); - - int const objCount = pImportData->m_objParents.size(); - rPrefabs.m_objMass .resize(objCount, 0.0f); - rPrefabs.m_objShape .resize(objCount, EShape::None); - - rPrefabs.m_prefabs .data_reserve(objCount); - rPrefabs.m_prefabs .ids_reserve(topLevelSpan.size()); - - rPrefabs.m_prefabParents.data_reserve(objCount); - rPrefabs.m_prefabParents.ids_reserve(topLevelSpan.size()); - - rPrefabs.m_prefabNames .reserve(topLevelSpan.size()); - - // OSP parts are specified as top-level gltf nodes on the first scene - // with a name that starts with "part_" - // these rules may change - - std::vector prefabObjs; - std::vector prefabParents; - prefabObjs.reserve(objCount); - prefabParents.reserve(objCount); - - auto const process_obj_recurse - = [&prefabObjs, &prefabParents, &rPrefabs, - &rNodeExtras = *pNodeExtras, &rImportData = *pImportData] - (auto&& self, ObjId obj, int32_t parent) -> void - { - auto const &name = rImportData.m_objNames[obj]; - tinygltf::Value const &extras = rNodeExtras[obj]; - - if (extras.IsObject()) - { - if (name.hasPrefix("col_")) - { - // is Collider - auto const &shapeName = extras.Get("shape").Get(); - - rPrefabs.m_objShape[obj] = shape_from_name(shapeName); - } - - - if (tinygltf::Value massValue = extras.Get("massdry"); - massValue.IsNumber()) - { - rPrefabs.m_objMass[obj] = massValue.GetNumberAsDouble(); - } - } - - int32_t const prefabIndex = prefabParents.size(); - prefabParents.push_back(parent); - prefabObjs.push_back(obj); - - // recurse into children - for (ObjId child : rImportData.m_objChildren[obj]) - { - self(self, child, prefabIndex); - } - }; - - PrefabId prefabIdNext = 0; - - for (ObjId const obj : topLevelSpan) - { - auto const &name = pImportData->m_objNames[obj]; - if ( ! name.hasPrefix("part_")) - { - continue; - } - - rPrefabs.m_prefabNames.emplace_back(name.exceptPrefix("part_")); - - // Read descendants and populate prefabObjs and prefabParents - process_obj_recurse(process_obj_recurse, obj, -1); - assert(prefabObjs.size() == (1 + pImportData->m_objDescendants[obj])); - - rPrefabs.m_prefabs.emplace( - prefabIdNext, std::begin(prefabObjs), std::end(prefabObjs)); - rPrefabs.m_prefabParents.emplace( - prefabIdNext, std::begin(prefabParents), std::end(prefabParents)); - ++prefabIdNext; - - prefabObjs.clear(); - prefabParents.clear(); - } -} diff --git a/src/osp/vehicles/load_tinygltf.h b/src/osp/vehicles/load_tinygltf.h deleted file mode 100644 index ec015ecd..00000000 --- a/src/osp/vehicles/load_tinygltf.h +++ /dev/null @@ -1,47 +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. - */ -#pragma once - -#include "../core/resourcetypes.h" - -#include - -namespace osp -{ - -void register_tinygltf_resources(Resources &rResources); -ResId load_tinygltf_file(std::string_view filepath, Resources &rResources, PkgId pkg); - -/** - * @brief Assign prefabs (potentially Parts) and add physical properties to an - * ImporterData loaded from tinygltf - * - * @param rResources - * @param pkg - * @param importer - */ -void assigns_prefabs_tinygltf(Resources &rResources, ResId importer); - -} diff --git a/src/osp/vehicles/prefabs.h b/src/osp/vehicles/prefabs.h deleted file mode 100644 index 116047f0..00000000 --- a/src/osp/vehicles/prefabs.h +++ /dev/null @@ -1,50 +0,0 @@ -/** - * Open Space Program - * Copyright © 2019-2023 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 "../core/math_types.h" -#include "../core/resourcetypes.h" - -namespace osp -{ - -namespace restypes -{ - -inline ResTypeId const gc_importer = ResTypeIdReg_t::create(); - -} // namespace restypes - - -using ObjId = int32_t; -using PrefabId = uint32_t; - -struct PrefabPair -{ - ResIdOwner_t m_importer; - PrefabId m_prefabId; -}; - -} // namespace osp diff --git a/src/testapp/features/magnum.cpp b/src/testapp/features/magnum.cpp index ca08a734..4af8b05f 100644 --- a/src/testapp/features/magnum.cpp +++ b/src/testapp/features/magnum.cpp @@ -29,7 +29,6 @@ #include -#include #include #include #include diff --git a/src/testapp/main.cpp b/src/testapp/main.cpp index f40a3fa8..47495c16 100644 --- a/src/testapp/main.cpp +++ b/src/testapp/main.cpp @@ -48,8 +48,6 @@ #include #include #include -#include -#include #include #include @@ -404,9 +402,6 @@ void load_a_bunch_of_stuff() 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/" }; @@ -426,8 +421,8 @@ void load_a_bunch_of_stuff() // 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, g_defaultPkg); - osp::assigns_prefabs_tinygltf(rResources, res); + //osp::ResId res = osp::load_tinygltf_file(osp::string_concat(datapath, meshName), rResources, g_defaultPkg); + //osp::assigns_prefabs_tinygltf(rResources, res); } // Add a default primitives diff --git a/src/testapp/scenarios.cpp b/src/testapp/scenarios.cpp index a3c72d48..e69803ae 100644 --- a/src/testapp/scenarios.cpp +++ b/src/testapp/scenarios.cpp @@ -37,12 +37,10 @@ #include #include #include -#include #include #include #include -#include #include #include @@ -142,7 +140,7 @@ static ScenarioMap_t make_scenarios() }}); - +/* add_scenario({ .name = "vehicles", .brief = "Physics scenario but with Vehicles", @@ -220,7 +218,7 @@ static ScenarioMap_t make_scenarios() rVehicleSpawnVB.dataVB.push_back(rPrebuiltVehicles[gc_pbvSimpleCommandServiceModule].get()); } }}); - +*/ add_scenario({ @@ -413,21 +411,12 @@ static ScenarioMap_t make_scenarios() //sceneCB.add_feature(ftrDroppers); sceneCB.add_feature(ftrBounds); - sceneCB.add_feature(ftrPrefabs); - sceneCB.add_feature(ftrParts); - sceneCB.add_feature(ftrSignalsFloat); - sceneCB.add_feature(ftrVehicleSpawn); - sceneCB.add_feature(ftrVehicleSpawnVBData); - sceneCB.add_feature(ftrPrebuiltVehicles); - - sceneCB.add_feature(ftrMachMagicRockets); - sceneCB.add_feature(ftrMachRCSDriver); + //sceneCB.add_feature(ftrPrebuiltVehicles); sceneCB.add_feature(ftrJolt); sceneCB.add_feature(ftrJoltConstAccel); sceneCB.add_feature(ftrPhysicsShapesJolt); - sceneCB.add_feature(ftrVehicleSpawnJolt); - sceneCB.add_feature(ftrRocketThrustJolt); + //sceneCB.add_feature(ftrRocketThrustJolt); sceneCB.add_feature(ftrTerrainJolt); @@ -438,28 +427,6 @@ static ScenarioMap_t make_scenarios() ospjolt::ForceFactors_t const gravity = add_constant_acceleration(sc_gravityForce, args.rFW, sceneCtx); set_phys_shape_factors(gravity, args.rFW, sceneCtx); - set_vehicle_default_factors(gravity, args.rFW, sceneCtx); - - //add_floor(args.rFW, sceneCtx, args.defaultPkg, 4); - - auto vhclSpawn = args.rFW.get_interface(sceneCtx); - auto vhclSpawnVB = args.rFW.get_interface(sceneCtx); - auto testVhcls = args.rFW.get_interface(sceneCtx); - - auto &rVehicleSpawn = args.rFW.data_get (vhclSpawn.di.vehicleSpawn); - auto &rVehicleSpawnVB = args.rFW.data_get (vhclSpawnVB.di.vehicleSpawnVB); - auto &rPrebuiltVehicles = args.rFW.data_get (testVhcls.di.prebuiltVehicles); - - for (int i = 0; i < 10; ++i) - { - rVehicleSpawn.spawnRequest.push_back( - { - .position = {float(i - 2) * 8.0f, 30.0f, 10.0f}, - .velocity = {0.0, 0.0f, 50.0f * float(i)}, - .rotation = {} - }); - rVehicleSpawnVB.dataVB.push_back(rPrebuiltVehicles[gc_pbvSimpleCommandServiceModule].get()); - } }}); return scenarioMap; diff --git a/src/testapp/scenarios_magnum.cpp b/src/testapp/scenarios_magnum.cpp index ddb2ce97..40295c28 100644 --- a/src/testapp/scenarios_magnum.cpp +++ b/src/testapp/scenarios_magnum.cpp @@ -39,7 +39,6 @@ #include #include #include -#include #include @@ -141,25 +140,12 @@ ContextId make_scene_renderer(Framework &rFW, PkgId defaultPkg, ContextId mainCo scnRdrCB.add_feature(ftrCursor, TplPkgIdMaterialId{ defaultPkg, matFlat }); - if (rFW.get_interface_id(sceneCtx).has_value()) - { - scnRdrCB.add_feature(ftrPrefabDraw, matPhong); - } + scnRdrCB.add_feature(ftrCameraFree); - if (rFW.get_interface_id(sceneCtx).has_value()) - { - scnRdrCB.add_feature(ftrVehicleSpawnDraw); - scnRdrCB.add_feature(ftrVehicleControl); - } - else - { - scnRdrCB.add_feature(ftrCameraFree); - } - - if (rFW.get_interface_id(sceneCtx).has_value()) - { - scnRdrCB.add_feature(ftrMagicRocketThrustIndicator, TplPkgIdMaterialId{ defaultPkg, matFlat }); - } +// if (rFW.get_interface_id(sceneCtx).has_value()) +// { +// scnRdrCB.add_feature(ftrMagicRocketThrustIndicator, TplPkgIdMaterialId{ defaultPkg, matFlat }); +// } if ( ! scnRdrCB.has_error() && rFW.get_interface_id(sceneCtx).has_value() ) {