diff --git a/bin/OSPData/adera/solvalot.png b/bin/OSPData/adera/solvalot.png new file mode 100644 index 00000000..8ff6c935 Binary files /dev/null and b/bin/OSPData/adera/solvalot.png differ diff --git a/bin/OSPData/adera/solvalot.sturdy.bin b/bin/OSPData/adera/solvalot.sturdy.bin new file mode 100644 index 00000000..510ab29c Binary files /dev/null and b/bin/OSPData/adera/solvalot.sturdy.bin differ diff --git a/bin/OSPData/adera/solvalot.sturdy.gltf b/bin/OSPData/adera/solvalot.sturdy.gltf new file mode 100644 index 00000000..3698f6b6 --- /dev/null +++ b/bin/OSPData/adera/solvalot.sturdy.gltf @@ -0,0 +1,230 @@ +{ + "asset":{ + "generator":"Khronos glTF Blender I/O v4.5.49", + "version":"2.0" + }, + "scene":0, + "scenes":[ + { + "name":"Scene", + "nodes":[ + 5 + ] + } + ], + "nodes":[ + { + "extras":{ + "shape":"cube", + "massdry":1000.0 + }, + "name":"col_fusalage", + "scale":[ + 0.886086642742157, + 2.495450973510742, + 6.2181172370910645 + ], + "translation":[ + 0, + 0.0039101243019104, + 0.9583339095115662 + ] + }, + { + "extras":{ + "shape":"cube", + "massdry":1000.0 + }, + "name":"col_left", + "rotation":[ + 0.017452405765652657, + 0, + 0, + 0.9998477101325989 + ], + "scale":[ + 0.6479361057281494, + 2.646085262298584, + 2.323085308074951 + ], + "translation":[ + 5.002408027648926, + 0.1590890884399414, + -3.7140254974365234 + ] + }, + { + "extras":{ + "shape":"cube", + "massdry":1000.0 + }, + "name":"col_right", + "rotation":[ + 0.017452405765652657, + 0, + 0, + 0.9998477101325989 + ], + "scale":[ + 0.6479361057281494, + 2.646085262298584, + 2.323085308074951 + ], + "translation":[ + -5.002409934997559, + 0.1590890884399414, + -3.7140254974365234 + ] + }, + { + "extras":{ + "shape":"cube", + "massdry":1000.0 + }, + "name":"col_wings", + "scale":[ + 4.787597179412842, + 0.3123275935649872, + 3.603761672973633 + ], + "translation":[ + 0, + 0.0039101243019104, + -2.002084732055664 + ] + }, + { + "mesh":0, + "name":"solvalot" + }, + { + "children":[ + 0, + 1, + 2, + 3, + 4 + ], + "extras":{ + "massdry":10.0 + }, + "name":"part_solvalot1" + } + ], + "materials":[ + { + "doubleSided":true, + "name":"solvalot-material", + "pbrMetallicRoughness":{ + "baseColorTexture":{ + "index":0 + }, + "metallicFactor":0, + "roughnessFactor":0.5 + } + } + ], + "meshes":[ + { + "name":"Cube", + "primitives":[ + { + "attributes":{ + "POSITION":0, + "NORMAL":1, + "TEXCOORD_0":2 + }, + "indices":3, + "material":0 + } + ] + } + ], + "textures":[ + { + "sampler":0, + "source":0 + } + ], + "images":[ + { + "mimeType":"image/png", + "name":"solvalot", + "uri":"solvalot.png" + } + ], + "accessors":[ + { + "bufferView":0, + "componentType":5126, + "count":1335, + "max":[ + 5.2794013023376465, + 2.8245668411254883, + 7.075264930725098 + ], + "min":[ + -5.2794013023376465, + -2.377899408340454, + -6.056069374084473 + ], + "type":"VEC3" + }, + { + "bufferView":1, + "componentType":5126, + "count":1335, + "type":"VEC3" + }, + { + "bufferView":2, + "componentType":5126, + "count":1335, + "type":"VEC2" + }, + { + "bufferView":3, + "componentType":5123, + "count":2364, + "type":"SCALAR" + } + ], + "bufferViews":[ + { + "buffer":0, + "byteLength":16020, + "byteOffset":0, + "target":34962 + }, + { + "buffer":0, + "byteLength":16020, + "byteOffset":16020, + "target":34962 + }, + { + "buffer":0, + "byteLength":10680, + "byteOffset":32040, + "target":34962 + }, + { + "buffer":0, + "byteLength":4728, + "byteOffset":42720, + "target":34963 + } + ], + "samplers":[ + { + "magFilter":9729, + "minFilter":9987 + } + ], + "buffers":[ + { + "byteLength":47448, + "uri":"solvalot.sturdy.bin" + } + ] +} diff --git a/src/adera/activescene/VehicleBuilder.cpp b/src/adera/activescene/VehicleBuilder.cpp index 66d4bd02..e8f3d2ff 100644 --- a/src/adera/activescene/VehicleBuilder.cpp +++ b/src/adera/activescene/VehicleBuilder.cpp @@ -24,13 +24,37 @@ */ #include "VehicleBuilder.h" +#include + +#include +#include + #include #include #include +using namespace osp::fw; + namespace adera { +struct VehicleBuilderImpl +{ + ContextId main; + Framework fw; + osp::exec::SinglethreadFWExecutor exec; +}; + + +VehicleBuilder::VehicleBuilder(Framework fw, ContextId ctx) + : m_impl{std::make_unique(ctx, std::move(fw), osp::exec::SinglethreadFWExecutor{})} +{ } + +VehicleBuilder::~VehicleBuilder() = default; + + +#if 0 + using osp::restypes::gc_importer; VehicleBuilder::~VehicleBuilder() @@ -71,13 +95,13 @@ 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()); + PartId *pPartInWeld = m_data->m_weldToParts.emplace(weld.value, toWeld.size()); for (PartToWeld const& set : toWeld) { - m_data->m_partTransformWeld[set.m_part] = set.m_transform; + m_data->m_partTransformWeld[set.m_part.value] = set.m_transform; - m_data->m_partToWeld[set.m_part] = weld; + m_data->m_partToWeld[set.m_part.value] = weld; (*pPartInWeld) = set.m_part; std::advance(pPartInWeld, 1); } @@ -116,26 +140,25 @@ osp::link::MachAnyId VehicleBuilder::create_machine(PartId const part, std::initializer_list const& connections) { auto &rData = m_data.value(); - osp::link::PerMachType &rPerMachType = rData.m_machines.perType[machType]; + osp::link::MachType &rPerMachType = rData.m_links.machtype[machType]; - MachTypeId const mach = rData.m_machines.ids.create(); + MachAnyId const mach = rData.m_links.machIds.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) + std::size_t const capacity = rData.m_links.machIds.capacity(); + rData.m_links.machTypeOf .resize(capacity); + rData.m_links.machlocalidOf .resize(capacity); + rData.m_machToPart .resize(capacity); + for (osp::link::NodeType &rPerNodeType : rData.m_links.nodetype) { rPerNodeType.machToNode.ids_reserve(capacity); - rPerNodeType.m_machToNodeCustom.ids_reserve(capacity); } - MachTypeId const local = rPerMachType.localIds.create(); - rPerMachType.localToAny.resize(rPerMachType.localIds.capacity()); + MachLocalId const local = rPerMachType.localIds.create(); + rPerMachType.machanyIdOf.resize(rPerMachType.localIds.capacity()); - rData.m_machines.machTypes[mach] = machType; - rData.m_machines.machToLocal[mach] = local; - rPerMachType.localToAny[local] = mach; + rData.m_links.machTypeOf[mach] = machType; + rData.m_links.machlocalidOf[mach] = local; + rPerMachType.machanyIdOf[local] = mach; m_partMachCount[std::size_t(part)] ++; rData.m_machToPart[mach] = part; @@ -147,19 +170,21 @@ osp::link::MachAnyId VehicleBuilder::create_machine(PartId const part, void VehicleBuilder::connect(MachAnyId const mach, std::initializer_list const& connections) { + auto const& linkInfo = osp::link::GlobalLinkInfo::instance(); + // get max port count for each node type auto &rData = m_data.value(); - std::vector nodePortMax(rData.m_nodePerType.size(), 0); + osp::KeyedVec portSizeRequired(linkInfo.nodetypeIds.capacity(), 0); for (Connection const& connect : connections) { - int &rPortMax = nodePortMax[connect.m_port.type]; - rPortMax = std::max(rPortMax, connect.m_port.port + 1); + int &rPortMax = portSizeRequired[connect.m_port.type]; + rPortMax = std::max(rPortMax, connect.m_port.port.value + 1); } - for (NodeTypeId nodeType = 0; std::size_t(nodeType) < rData.m_nodePerType.size(); ++nodeType) + for (NodeTypeId const nodeType : linkInfo.nodetypeIds) { - int const portMax = nodePortMax[nodeType]; - PerNodeType &rPerNodeType = rData.m_nodePerType[nodeType]; + int const portMax = portSizeRequired[nodeType]; + osp::link::NodeType &rPerNodeType = rData.m_links.nodetype[nodeType]; if (portMax != 0) { // reallocate each time :) @@ -167,19 +192,20 @@ void VehicleBuilder::connect(MachAnyId const mach, std::initializer_list const portSpan = rPerNodeType.machToNode[mach]; + rPerNodeType.machToNode.emplace(mach.value, portMax); + lgrn::Span const portSpan = rPerNodeType.machToNode[mach.value]; 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]; + rPerNodeType.m_machToNodeCustom.emplace(mach.value, portMax); + lgrn::Span const customSpan = rPerNodeType.m_machToNodeCustom[mach.value]; 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; + customSpan[connect.m_port.port.value] = connect.m_port.custom; + portSpan[connect.m_port.port.value] = connect.m_node; + rPerNodeType.m_nodeConnectCount[connect.m_node] ++; rPerNodeType.m_connectCountTotal ++; } @@ -195,24 +221,26 @@ 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) + for (std::uint16_t nodeTypeInt = 0; nodeTypeInt < rData.m_nodePerType.size(); ++nodeTypeInt) { + NodeTypeId const nodeType{nodeTypeInt}; + 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]; + rPerNodeType.nodeToMach.emplace(node.value, rPerNodeType.m_nodeConnectCount[node]); + lgrn::Span junction = rPerNodeType.nodeToMach[node.value]; std::fill(std::begin(junction), std::end(junction), Junction{}); } // assign node-to-machine - for (MachAnyId const mach : rData.m_machines.ids) + for (MachAnyId const mach : rData.m_machines.machIds) { - lgrn::Span portSpan = rPerNodeType.machToNode[mach]; - lgrn::Span customSpan = rPerNodeType.m_machToNodeCustom[mach]; + lgrn::Span portSpan = rPerNodeType.machToNode[mach.value]; + lgrn::Span customSpan = rPerNodeType.m_machToNodeCustom[mach.value]; for (int i = 0; i < portSpan.size(); ++i) { @@ -223,7 +251,7 @@ VehicleData VehicleBuilder::finalize_release() continue; } - lgrn::Span const juncSpan = rPerNodeType.nodeToMach[node]; + lgrn::Span const juncSpan = rPerNodeType.nodeToMach[node.value]; // find empty spot // should always succeed, as they were reserved a few lines ago @@ -235,8 +263,8 @@ VehicleData VehicleBuilder::finalize_release() }); assert(found != std::end(juncSpan)); - MachTypeId const type = rData.m_machines.machTypes[mach]; - MachLocalId const local = rData.m_machines.machToLocal[mach]; + MachTypeId const type = rData.m_machines.machTypeOf[mach]; + MachLocalId const local = rData.m_machines.machlocalidOf[mach]; found->local = local; found->type = type; @@ -248,23 +276,23 @@ VehicleData VehicleBuilder::finalize_release() // 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()); + rData.m_partToMachines.data_reserve(rData.m_machines.machIds.capacity()); for (PartId const part : rData.m_partIds) { - rData.m_partToMachines.emplace(part, m_partMachCount[part]); + rData.m_partToMachines.emplace(part.value, m_partMachCount[part.value]); } // Assign part-to-machine partitions - for (MachAnyId const mach : rData.m_machines.ids) + for (MachAnyId const mach : rData.m_machines.machIds) { - MachLocalId const local = rData.m_machines.machToLocal[mach]; - MachTypeId const type = rData.m_machines.machTypes[mach]; + MachLocalId const local = rData.m_machines.machlocalidOf[mach]; + MachTypeId const type = rData.m_machines.machTypeOf[mach]; PartId const part = rData.m_machToPart[mach]; - auto const machines = lgrn::Span{rData.m_partToMachines[part]}; + auto const machines = lgrn::Span{rData.m_partToMachines[part.value]}; // Reuse machine count to track how many are currently added. // By the end, these should all be zero - auto &rPartMachCount = m_partMachCount[part]; + auto &rPartMachCount = m_partMachCount[part.value]; assert(rPartMachCount != 0); -- rPartMachCount; @@ -282,4 +310,6 @@ VehicleData VehicleBuilder::finalize_release() return dataOut; } +#endif + } // namespace adera diff --git a/src/adera/activescene/VehicleBuilder.h b/src/adera/activescene/VehicleBuilder.h index 3b893e2f..ebdcf597 100644 --- a/src/adera/activescene/VehicleBuilder.h +++ b/src/adera/activescene/VehicleBuilder.h @@ -24,10 +24,13 @@ */ #pragma once +#include + #include +#include +#include #include #include -#include #include @@ -44,6 +47,55 @@ namespace adera { +struct VehicleBuilderImpl; + +class VehicleBuilder +{ +public: + + VehicleBuilder(osp::fw::Framework fw, osp::fw::ContextId ctx); + ~VehicleBuilder(); + + struct Connection + { + osp::link::PortEntry m_port; + osp::link::NodeId m_node; + }; + + template + [[nodiscard]] std::array create_nodes(osp::link::NodeTypeId nodeType); + + osp::link::MachAnyId create_machine(osp::link::MachTypeId machType, std::initializer_list const& connections); + + void connect(osp::link::MachAnyId mach, std::initializer_list const& connections); + + void update(); + + osp::link::Links& links(); + +private: + + std::unique_ptr m_impl; +}; + + +template +std::array VehicleBuilder::create_nodes(osp::link::NodeTypeId const nodeType) +{ + std::array out; + + osp::link::NodeType &rNodeType = *links().nodetype[nodeType]; + + rNodeType.nodeIds.create(std::begin(out), std::end(out)); + std::size_t const capacity = rNodeType.nodeIds.capacity(); + rNodeType.nodeToMach.ids_reserve(rNodeType.nodeIds.capacity()); + + return out; +} + + +#if 0 + using osp::active::PartId; using osp::active::WeldId; @@ -54,22 +106,10 @@ struct StructureLink 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; + using MapWeldToParts_t = lgrn::IntArrayMultiMap; VehicleData() = default; OSP_MOVE_ONLY_CTOR(VehicleData); @@ -81,12 +121,11 @@ struct VehicleData MapPartToMachines_t m_partToMachines; lgrn::IdRegistryStl m_weldIds; - lgrn::IntArrayMultiMap m_weldToParts; + MapWeldToParts_t m_weldToParts; - osp::link::Machines m_machines; - std::vector m_machToPart; + osp::link::Links m_links; - std::vector m_nodePerType; + osp::KeyedVec m_machToPart; }; /** @@ -95,6 +134,7 @@ struct VehicleData class VehicleBuilder { using MachAnyId = osp::link::MachAnyId; + using MachLocalId = osp::link::MachLocalId; using MachTypeId = osp::link::MachTypeId; using NodeId = osp::link::NodeId; using NodeTypeId = osp::link::NodeTypeId; @@ -113,9 +153,10 @@ class VehicleBuilder VehicleBuilder(osp::Resources *pResources) : m_pResources{pResources} { + auto const& info = osp::link::GlobalLinkInfo::instance(); auto &rData = m_data.emplace(); - rData.m_machines.perType.resize(osp::link::MachTypeReg_t::size()); - rData.m_nodePerType.resize(osp::link::NodeTypeReg_t::size()); + rData.m_links.machtype.resize(info.machtypeIds.capacity()); + rData.m_links.nodetype.resize(info.nodetypeIds.capacity()); index_prefabs(); }; @@ -151,7 +192,7 @@ class VehicleBuilder std::size_t node_capacity(NodeTypeId nodeType) const { - return m_data->m_nodePerType[nodeType].nodeIds.capacity(); + return m_data->m_links.nodetype[nodeType].capacity; } struct Connection @@ -203,12 +244,11 @@ std::array VehicleBuilder::create_nodes(NodeTypeId const n { std::array out; - PerNodeType &rPerNodeType = m_data->m_nodePerType[nodeType]; + osp::link::NodeType &rNodeType = m_data->m_links.nodetype[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); + rNodeType.nodeIds.create(std::begin(out), std::end(out)); + std::size_t const capacity = rNodeType.nodeIds.capacity(); + rNodeType.nodeToMach.ids_reserve(rNodeType.nodeIds.capacity()); return out; } @@ -230,4 +270,6 @@ VALUES_T& VehicleBuilder::node_values(NodeTypeId nodeType) return rValues; } +#endif + } // namespace adera diff --git a/src/adera/activescene/vehicles_vb_fn.cpp b/src/adera/activescene/vehicles_vb_fn.cpp index ed31a38b..8a348a62 100644 --- a/src/adera/activescene/vehicles_vb_fn.cpp +++ b/src/adera/activescene/vehicles_vb_fn.cpp @@ -32,6 +32,8 @@ using namespace osp::active; namespace adera { +#if 0 + void SysVehicleSpawnVB::create_parts_and_welds(ACtxVehicleSpawn& rVehicleSpawn, ACtxVehicleSpawnVB& rVehicleSpawnVB, ACtxParts& rScnParts) { std::size_t const newVehicleCount = rVehicleSpawn.new_vehicle_count(); @@ -130,7 +132,7 @@ void SysVehicleSpawnVB::create_parts_and_welds(ACtxVehicleSpawn& rVehicleSpawn, ++itDstPartIds; // Populate map for "VehicleBuilder PartId -> ACtxParts PartId" - rVSVB.remapParts[remapPartOffset + srcPart] = dstPart; + rVSVB.remapParts[remapPartOffset + srcPart.value] = dstPart; } for (WeldId const srcWeld : pVData->m_weldIds) @@ -140,17 +142,17 @@ void SysVehicleSpawnVB::create_parts_and_welds(ACtxVehicleSpawn& rVehicleSpawn, // Populate map for "VehicleBuilder WeldId -> ACtxParts WeldId" // rVehicleSpawnVB.remapWelds - rVSVB.remapWelds[remapWeldOffset + srcWeld] = dstWeld; + rVSVB.remapWelds[remapWeldOffset + srcWeld.value] = 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()); + auto const srcWeldPartSpan = pVData->m_weldToParts[srcWeld.value]; + PartId *pDstWeldPartOut = rScnParts.weldToParts.emplace(dstWeld.value, srcWeldPartSpan.size()); for (PartId const srcPart : srcWeldPartSpan) { - PartId const dstPart = rVSVB.remapParts[remapPartOffset + srcPart]; + PartId const dstPart = rVSVB.remapParts[remapPartOffset + srcPart.value]; (*pDstWeldPartOut) = dstPart; std::advance(pDstWeldPartOut, 1); @@ -180,13 +182,13 @@ void SysVehicleSpawnVB::request_prefabs(ACtxVehicleSpawn& rVehicleSpawn, ACtxVeh } // Copy Part data from VehicleBuilder to scene - for (uint32_t srcPart : pVData->m_partIds) + for (PartId srcPart : pVData->m_partIds) { PartId const dstPart = *itDstPartIds; ++itDstPartIds; - PrefabPair const& prefabPairSrc = pVData->m_partPrefabs[srcPart]; - rScnParts.partTransformWeld[dstPart] = pVData->m_partTransformWeld[srcPart]; + PrefabPair const& prefabPairSrc = pVData->m_partPrefabs[srcPart.value]; + rScnParts.partTransformWeld[dstPart] = pVData->m_partTransformWeld[srcPart.value]; // Add Prefab and Part init events (*itPrefabOut) = rPrefabs.spawnRequest.size(); @@ -195,11 +197,12 @@ void SysVehicleSpawnVB::request_prefabs(ACtxVehicleSpawn& rVehicleSpawn, ACtxVeh rPrefabs.spawnRequest.push_back(TmpPrefabRequest{ .m_importerRes = prefabPairSrc.m_importer, .m_prefabId = prefabPairSrc.m_prefabId, - .m_pTransform = &pVData->m_partTransformWeld[srcPart] + .m_pTransform = &pVData->m_partTransformWeld[srcPart.value] }); } } } +#endif } // namespace adera diff --git a/src/adera/activescene/vehicles_vb_fn.h b/src/adera/activescene/vehicles_vb_fn.h index 1f2efbe2..8b954c2f 100644 --- a/src/adera/activescene/vehicles_vb_fn.h +++ b/src/adera/activescene/vehicles_vb_fn.h @@ -32,6 +32,8 @@ namespace adera { +#if 0 + struct ACtxVehicleSpawnVB { using SpVehicleId = osp::active::SpVehicleId; @@ -46,13 +48,13 @@ struct ACtxVehicleSpawnVB inline Corrade::Containers::StridedArrayView2D remap_node_offsets_2d() noexcept { return {Corrade::Containers::arrayView(remapNodeOffsets.data(), remapNodeOffsets.size()), - {dataVB.size(), osp::link::NodeTypeReg_t::size()}}; + {dataVB.size(), remapNodeOffsetStride}}; } 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()}}; + {dataVB.size(), remapNodeOffsetStride}}; } osp::KeyedVec dataVB; @@ -60,10 +62,10 @@ struct ACtxVehicleSpawnVB std::vector remapParts; osp::KeyedVec remapPartOffsets; - std::vector remapWelds; + std::vector remapWelds; osp::KeyedVec remapWeldOffsets; - std::vector machtypeCount; + osp::KeyedVec machtypeCount; std::vector remapMachs; osp::KeyedVec remapMachOffsets; @@ -71,6 +73,7 @@ struct ACtxVehicleSpawnVB // An offset can exist for each pair of [New Vehicle, Node Type] std::vector remapNodes; osp::KeyedVec remapNodeOffsets; + std::size_t remapNodeOffsetStride; }; class SysVehicleSpawnVB @@ -85,5 +88,6 @@ class SysVehicleSpawnVB static void request_prefabs(ACtxVehicleSpawn& rVehicleSpawn, ACtxVehicleSpawnVB const& rVehicleSpawnVB, ACtxParts& rScnParts, ACtxPrefabs& rPrefabs, Resources& rResources); }; +#endif } // namespace adera diff --git a/src/adera/machines/links.cpp b/src/adera/links.cpp similarity index 96% rename from src/adera/machines/links.cpp rename to src/adera/links.cpp index eb5fd6e2..c59f314c 100644 --- a/src/adera/machines/links.cpp +++ b/src/adera/links.cpp @@ -26,9 +26,6 @@ using namespace osp; -using osp::link::MachTypeReg_t; -using osp::link::MachTypeId; - namespace adera { diff --git a/src/adera/machines/links.h b/src/adera/links.h similarity index 53% rename from src/adera/machines/links.h rename to src/adera/links.h index 557c0020..af188eec 100644 --- a/src/adera/machines/links.h +++ b/src/adera/links.h @@ -26,52 +26,51 @@ #include -#include +#include #include namespace adera { using osp::link::PortEntry; -using osp::link::gc_ntSigFloat; -using osp::link::gc_sigIn; -using osp::link::gc_sigOut; +using osp::link::sigfloat_input; +using osp::link::sigfloat_output; -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(); +inline osp::link::MachTypeId const gc_mtUserCtrl = osp::link::GlobalLinkInfo::instance().create_machtype(); +inline osp::link::MachTypeId const gc_mtMagicRocket = osp::link::GlobalLinkInfo::instance().create_machtype(); +inline osp::link::MachTypeId const gc_mtRcsDriver = osp::link::GlobalLinkInfo::instance().create_machtype(); 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 }; +PortEntry const gc_throttleOut = sigfloat_output(0); +PortEntry const gc_pitchOut = sigfloat_output(1); +PortEntry const gc_yawOut = sigfloat_output(2); +PortEntry const gc_rollOut = sigfloat_output(3); } namespace ports_magicrocket { -PortEntry const gc_throttleIn { gc_ntSigFloat, 0, gc_sigIn }; -PortEntry const gc_multiplierIn { gc_ntSigFloat, 1, gc_sigIn }; +PortEntry const gc_throttleIn = sigfloat_input(0); +PortEntry const gc_multiplierIn = sigfloat_input(1); } 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 }; +PortEntry const gc_posXIn = sigfloat_input(0); +PortEntry const gc_posYIn = sigfloat_input(1); +PortEntry const gc_posZIn = sigfloat_input(2); +PortEntry const gc_dirXIn = sigfloat_input(3); +PortEntry const gc_dirYIn = sigfloat_input(4); +PortEntry const gc_dirZIn = sigfloat_input(5); +PortEntry const gc_cmdLinXIn = sigfloat_input(6); +PortEntry const gc_cmdLinYIn = sigfloat_input(7); +PortEntry const gc_cmdLinZIn = sigfloat_input(8); +PortEntry const gc_cmdAngXIn = sigfloat_input(9); +PortEntry const gc_cmdAngYIn = sigfloat_input(10); +PortEntry const gc_cmdAngZIn = sigfloat_input(11); +PortEntry const gc_throttleOut = sigfloat_output(12); } float thruster_influence(osp::Vector3 pos, osp::Vector3 dir, osp::Vector3 cmdLin, osp::Vector3 cmdAng) noexcept; diff --git a/src/adera_app/features/jolt.cpp b/src/adera_app/features/jolt.cpp index 4ebb64a9..b7db8688 100644 --- a/src/adera_app/features/jolt.cpp +++ b/src/adera_app/features/jolt.cpp @@ -35,7 +35,7 @@ #include #include -#include +#include #include @@ -355,7 +355,7 @@ FeatureDef const ftrVehicleSpawnJolt = feature_def("VehicleSpawnJolt", [] ( { // Count parts in this weld first std::size_t entCount = 0; - for (PartId const part : rScnParts.weldToParts[weld]) + for (PartId const part : rScnParts.weldToParts[weld.value]) { SpPartId const newPart = rVehicleSpawn.partToSpawned[part]; uint32_t const prefabInit = rVehicleSpawn.spawnedPrefabs[newPart]; @@ -369,7 +369,7 @@ FeatureDef const ftrVehicleSpawnJolt = feature_def("VehicleSpawnJolt", [] ( SubtreeBuilder bldRoot = SysSceneGraph::add_descendants(rBasic.m_scnGraph, entCount + 1); SubtreeBuilder bldWeld = bldRoot.add_child(weldEnt, entCount); - for (PartId const part : rScnParts.weldToParts[weld]) + for (PartId const part : rScnParts.weldToParts[weld.value]) { SpPartId const newPart = rVehicleSpawn.partToSpawned[part]; uint32_t const prefabInit = rVehicleSpawn.spawnedPrefabs[newPart]; @@ -521,8 +521,8 @@ static void assign_weld_rockets( ACtxParts const &rScnParts, ACtxJoltWorld &rJolt, ACtxRocketsJolt &rRocketsJolt, - Nodes const &rFloatNodes, - PerMachType const &machtypeRocket, + NodeType const &rFloatNodes, + MachType const &machtypeRocket, std::vector &rRocketsFoundTemp) { using adera::gc_mtMagicRocket; @@ -542,20 +542,20 @@ static void assign_weld_rockets( // 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]) + for (PartId const part : rScnParts.weldToParts[weld.value]) { auto const sizeBefore = rRocketsFoundTemp.size(); // Each part contains Machines, some of which may be rockets. - for (MachinePair const pair : rScnParts.partToMachines[part]) + for (MachinePair const pair : rScnParts.partToMachines[part.value]) { 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]; + MachAnyId const mach = machtypeRocket.machanyIdOf[pair.local]; + auto const& portSpan = rFloatNodes.machToNode[mach.value]; NodeId const throttleIn = connected_node(portSpan, gc_throttleIn.port); NodeId const multiplierIn = connected_node(portSpan, gc_multiplierIn.port); @@ -615,6 +615,8 @@ static void assign_weld_rockets( } } +#if 0 + struct RocketThrustUserData { ACtxRocketsJolt const &rRocketsJolt; @@ -694,8 +696,8 @@ FeatureDef const ftrRocketThrustJolt = feature_def("RocketThrustJolt", [] ( { using adera::gc_mtMagicRocket; - Nodes const &rFloatNodes = rLinks.nodePerType[gc_ntSigFloat]; - PerMachType const &machtypeRocket = rLinks.machines.perType[gc_mtMagicRocket]; + NodeType const &rFloatNodes = rLinks.nodePerType[gc_ntSigFloat]; + MachType const &machtypeRocket = rLinks.machines.perType[gc_mtMagicRocket]; rRocketsJolt.m_bodyRockets.ids_reserve(rJolt.m_bodyIds.size()); rRocketsJolt.m_bodyRockets.data_reserve(rLinks.machines.perType[gc_mtMagicRocket].localIds.capacity()); @@ -727,6 +729,9 @@ FeatureDef const ftrRocketThrustJolt = feature_def("RocketThrustJolt", [] ( rRocketsJolt.factorIndex = static_cast(index); }); // ftrRocketThrustJolt +#endif + + struct ACtxTerrainJolt { BodyId bodyId; @@ -738,6 +743,7 @@ struct ACtxTerrainJolt std::vector positions; }; + FeatureDef const ftrTerrainJolt = feature_def("ftrTerrainJolt", [] ( FeatureBuilder &rFB, Implement terrainJolt, diff --git a/src/adera_app/features/vehicles.cpp b/src/adera_app/features/vehicles.cpp index 82d072b2..56f394ef 100644 --- a/src/adera_app/features/vehicles.cpp +++ b/src/adera_app/features/vehicles.cpp @@ -27,7 +27,7 @@ #include #include -#include +#include #include #include @@ -52,6 +52,13 @@ using namespace Magnum::Math::Literals; namespace adera { +FeatureDef const ftrLinks = feature_def("Links", [] ( + FeatureBuilder &rFB, + Implement links, + DependOn cleanup) +{ + auto &rLinks = rFB.data_emplace< Links > (links.di.links); +}); FeatureDef const ftrParts = feature_def("Parts", [] ( FeatureBuilder &rFB, @@ -82,16 +89,20 @@ FeatureDef const ftrParts = feature_def("Parts", [] ( 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 &rLinks = rFB.data_emplace< Links > (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()); + GlobalLinkInfo const& linkInfo = GlobalLinkInfo::instance(); + + std::size_t const machTypeIdCapacity = linkInfo.machtypeIds.capacity(); + rUpdMach.machTypesDirty.resize(machTypeIdCapacity); + rUpdMach.localDirty .resize(machTypeIdCapacity); + rLinks .machtype .resize(machTypeIdCapacity); + + std::size_t const nodeTypeIdCapacity = linkInfo.nodetypeIds.capacity(); + rLinks.nodetype.resize(nodeTypeIdCapacity); rFB.task() .name ("Clear Part dirty vectors after use") @@ -170,6 +181,8 @@ FeatureDef const ftrVehicleSpawn = feature_def("VehicleSpawn", [] ( }); // ftrVehicleSpawn +#if 0 + FeatureDef const ftrVehicleSpawnVBData = feature_def("VehicleSpawnVBData", [] ( FeatureBuilder &rFB, Implement vhclSpawnVB, @@ -188,7 +201,9 @@ FeatureDef const ftrVehicleSpawnVBData = feature_def("VehicleSpawnVBData", [] ( 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); + auto& rVehicleSpawnVB = rFB.data_emplace< ACtxVehicleSpawnVB >(vhclSpawnVB.di.vehicleSpawnVB); + + rVehicleSpawnVB.machtypeCount.resize(GlobalLinkInfo::instance().machtypeIds.capacity()); rFB.task() .name ("Create PartIds and WeldIds for vehicles to spawn from VehicleData") @@ -217,13 +232,14 @@ FeatureDef const ftrVehicleSpawnVBData = feature_def("VehicleSpawnVBData", [] ( std::size_t const newVehicleCount = rVehicleSpawn.new_vehicle_count(); ACtxVehicleSpawnVB &rVSVB = rVehicleSpawnVB; + GlobalLinkInfo const& linkInfo = GlobalLinkInfo::instance(); + // 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); + std::fill(rVSVB.machtypeCount.begin(), rVSVB.machtypeCount.end(), 0); rVSVB.remapMachOffsets.resize(newVehicleCount); @@ -236,16 +252,16 @@ FeatureDef const ftrVehicleSpawnVBData = feature_def("VehicleSpawnVBData", [] ( } Machines const &srcMachines = pVData->m_machines; - std::size_t const bounds = srcMachines.ids.capacity(); + std::size_t const bounds = srcMachines.machIds.capacity(); rVSVB.remapMachOffsets[vhId] = remapMachTotal; remapMachTotal += bounds; - machTotal += srcMachines.ids.size(); + machTotal += srcMachines.machIds.size(); - for (MachTypeId type = 0; type < MachTypeReg_t::largest(); ++type) + for (MachTypeId const typeId : linkInfo.machtypeIds) { - rVSVB.machtypeCount[type] += srcMachines.perType[type].localIds.size(); + rVSVB.machtypeCount[typeId] += srcMachines.perType[typeId].localIds.size(); } } @@ -255,10 +271,10 @@ FeatureDef const ftrVehicleSpawnVBData = feature_def("VehicleSpawnVBData", [] ( // Create ACtxParts MachAny/LocalIDs and populate remaps // MachAnyIDs created here - rLinks.machines.ids.create(rVehicleSpawn.spawnedMachs.begin(), - rVehicleSpawn.spawnedMachs.end()); + rLinks.machines.machIds.create(rVehicleSpawn.spawnedMachs.begin(), + rVehicleSpawn.spawnedMachs.end()); - rLinks.machines.machToLocal.resize(rLinks.machines.ids.capacity()); + rLinks.machines.machlocalidOf.resize(rLinks.machines.machIds.capacity()); auto itDstMachIds = rVehicleSpawn.spawnedMachs.cbegin(); @@ -274,13 +290,13 @@ FeatureDef const ftrVehicleSpawnVBData = feature_def("VehicleSpawnVBData", [] ( std::size_t const remapMachOffset = rVSVB.remapMachOffsets[vhId]; - for (MachAnyId const srcMach : srcMachines.ids) + for (MachAnyId const srcMach : srcMachines.machIds) { MachAnyId const dstMach = *itDstMachIds; ++itDstMachIds; // Populate map for "VehicleBuilder MachAnyId -> ACtxParts MachAnyId" - rVSVB.remapMachs[remapMachOffset + srcMach] = dstMach; + rVSVB.remapMachs[remapMachOffset + srcMach.value] = dstMach; // Create ACtxParts MachLocalIds // MachLocalIds don't need a remap, since they can be obtained @@ -288,14 +304,14 @@ FeatureDef const ftrVehicleSpawnVBData = feature_def("VehicleSpawnVBData", [] ( // 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]; + MachTypeId const type = srcMachines.machTypeOf[srcMach]; + MachType& rDstPerType = rLinks.machines.perType[type]; MachLocalId const dstLocal = rDstPerType.localIds.create(); - rDstPerType.localToAny.resize(rDstPerType.localIds.capacity()); + rDstPerType.machanyIdOf.resize(rDstPerType.localIds.capacity()); - rDstPerType.localToAny[dstLocal] = dstMach; - rLinks.machines.machToLocal[dstMach] = dstLocal; + rDstPerType.machanyIdOf[dstLocal] = dstMach; + rLinks.machines.machlocalidOf[dstMach] = dstLocal; } } }); @@ -317,19 +333,19 @@ FeatureDef const ftrVehicleSpawnVBData = feature_def("VehicleSpawnVBData", [] ( continue; } - rScnParts.machineToPart.resize(rLinks.machines.ids.capacity()); + rScnParts.machineToPart.resize(rLinks.machines.machIds.capacity()); rScnParts.partToMachines.ids_reserve(rScnParts.partIds.capacity()); - rScnParts.partToMachines.data_reserve(rLinks.machines.ids.capacity()); + rScnParts.partToMachines.data_reserve(rLinks.machines.machIds.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) + for (MachAnyId const srcMach : pVData->m_machines.machIds) { - MachAnyId const dstMach = rVSVB.remapMachs[remapMachOffset + srcMach]; + MachAnyId const dstMach = rVSVB.remapMachs[remapMachOffset + srcMach.value]; PartId const srcPart = pVData->m_machToPart[srcMach]; - PartId const dstPart = rVSVB.remapParts[remapPartOffset + srcPart]; + PartId const dstPart = rVSVB.remapParts[remapPartOffset + srcPart.value]; rScnParts.machineToPart[dstMach] = dstPart; } @@ -337,21 +353,21 @@ FeatureDef const ftrVehicleSpawnVBData = feature_def("VehicleSpawnVBData", [] ( // Update rScnParts part->machine multimap for (PartId const srcPart : pVData->m_partIds) { - PartId const dstPart = rVSVB.remapParts[remapPartOffset + srcPart]; + PartId const dstPart = rVSVB.remapParts[remapPartOffset + srcPart.value]; - auto const& srcPairs = pVData->m_partToMachines[srcPart]; + auto const& srcPairs = pVData->m_partToMachines[srcPart.value]; - rScnParts.partToMachines.emplace(dstPart, srcPairs.size()); - auto dstPairs = rScnParts.partToMachines[dstPart]; + rScnParts.partToMachines.emplace(dstPart.value, srcPairs.size()); + auto dstPairs = rScnParts.partToMachines[dstPart.value]; 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]; + MachAnyId const srcMach = pVData->m_machines.perType[srcPair.type].machanyIdOf[srcPair.local]; + MachAnyId const dstMach = rVSVB.remapMachs[remapMachOffset + srcMach.value]; MachTypeId const dstType = srcPair.type; - MachLocalId const dstLocal = rLinks.machines.machToLocal[dstMach]; + MachLocalId const dstLocal = rLinks.machines.machlocalidOf[dstMach]; rDstPair = { .local = dstLocal, .type = dstType }; } @@ -369,7 +385,11 @@ FeatureDef const ftrVehicleSpawnVBData = feature_def("VehicleSpawnVBData", [] ( std::size_t const newVehicleCount = rVehicleSpawn.new_vehicle_count(); ACtxVehicleSpawnVB &rVSVB = rVehicleSpawnVB; - rVSVB.remapNodeOffsets.resize(newVehicleCount * NodeTypeReg_t::size()); + GlobalLinkInfo const& linkInfo = GlobalLinkInfo::instance(); + + rVSVB.remapNodeOffsetStride = GlobalLinkInfo::instance().nodetypeIds.capacity(); + rVSVB.remapNodeOffsets.resize(newVehicleCount * rVSVB.remapNodeOffsetStride); + auto remapNodeOffsets2d = rVSVB.remap_node_offsets_2d(); // Add up bounds needed for all nodes of every type for remaps @@ -399,13 +419,13 @@ FeatureDef const ftrVehicleSpawnVBData = feature_def("VehicleSpawnVBData", [] ( auto machRemap = arrayView(std::as_const(rVSVB.remapMachs)).exceptPrefix(rVSVB.remapMachOffsets[vhId]); - for (NodeTypeId nodeType = 0; nodeType < NodeTypeReg_t::largest(); ++nodeType) + for (NodeTypeId const nodeType : linkInfo.nodetypeIds) { 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; + remapNodeOffsets2d[vhId.value][nodeType.value] = nodeRemapUsed; nodeRemapUsed += remapSize; copy_nodes(rSrcNodeType, pVData->m_machines, machRemap, rLinks.nodePerType[nodeType], rLinks.machines, nodeRemapOut); @@ -442,8 +462,8 @@ FeatureDef const ftrVehicleSpawnVBData = feature_def("VehicleSpawnVBData", [] ( .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(); + NodeType 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); @@ -463,12 +483,12 @@ FeatureDef const ftrVehicleSpawnVBData = feature_def("VehicleSpawnVBData", [] ( 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]; + std::size_t const nodeRemapOffset = remapNodeOffsets2d[vhId.value][gc_ntSigFloat.value]; auto const nodeRemap = arrayView(rVSVB.remapNodes).exceptPrefix(nodeRemapOffset); for (NodeId const srcNode : srcFloatNodes.nodeIds) { - NodeId const dstNode = nodeRemap[srcNode]; + NodeId const dstNode = nodeRemap[srcNode.value]; rSigValFloat[dstNode] = srcFloatValues[srcNode]; } } @@ -524,7 +544,7 @@ FeatureDef const ftrSignalsFloat = feature_def("SignalsFloat", [] ( return; // Not dirty, nothing to do } - Nodes const &rFloatNodes = rLinks.nodePerType[gc_ntSigFloat]; + NodeType 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 @@ -535,16 +555,14 @@ FeatureDef const ftrSignalsFloat = feature_def("SignalsFloat", [] ( } 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); + // Apply new node values and notify connected inputs + for (NodeId const nodeId : rSigUpdFloat.nodeDirty) + { + rSigValFloat[nodeId] = rSigUpdFloat.nodeNewValues[nodeId]; + notify_connected_inputs(nodeId, rFloatNodes.nodeToMach, rUpdMach); + } rSigUpdFloat.nodeDirty.clear(); + rSigUpdFloat.dirty = false; // Run tasks needed to update machine types that are dirty @@ -560,5 +578,7 @@ FeatureDef const ftrSignalsFloat = feature_def("SignalsFloat", [] ( }); }); // ftrSignalsFloat +#endif + } // namespace adera diff --git a/src/adera_app/features/vehicles.h b/src/adera_app/features/vehicles.h index ba99a7b2..873dd470 100644 --- a/src/adera_app/features/vehicles.h +++ b/src/adera_app/features/vehicles.h @@ -29,8 +29,14 @@ namespace adera { + +/** + * @brief TODO + */ +extern osp::fw::FeatureDef const ftrLinks; + /** - * @brief Support for Parts, Machines, and Links + * @brief TODO */ extern osp::fw::FeatureDef const ftrParts; diff --git a/src/adera_app/features/vehicles_machines.cpp b/src/adera_app/features/vehicles_machines.cpp index b361c2ae..2c0fffd4 100644 --- a/src/adera_app/features/vehicles_machines.cpp +++ b/src/adera_app/features/vehicles_machines.cpp @@ -29,7 +29,7 @@ #include #include -#include +#include #include #include @@ -52,6 +52,8 @@ using namespace osp; namespace adera { +#if 0 + FeatureDef const ftrMachMagicRockets = feature_def("MachMagicRockets", [] ( FeatureBuilder &rFB, DependOn scn, @@ -104,7 +106,6 @@ FeatureDef const ftrMagicRocketThrustIndicator = feature_def("MagicRocketThrustI 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; @@ -117,7 +118,7 @@ FeatureDef const ftrMagicRocketThrustIndicator = feature_def("MagicRocketThrustI .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]; + MachType const& rockets = rLinks.machines.perType[gc_mtMagicRocket]; rIndicator.rktToDrawEnt.resize(rockets.localIds.capacity()); @@ -137,19 +138,19 @@ FeatureDef const ftrMagicRocketThrustIndicator = feature_def("MagicRocketThrustI .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]; + Material &rMat = rScnRender.m_materials[rIndicator.material]; + MachType const &rockets = rLinks.machines.perType[gc_mtMagicRocket]; + NodeType const &floats = rLinks.nodePerType[gc_ntSigFloat]; for (MachLocalId const localId : rockets.localIds) { DrawEnt const drawEnt = rIndicator.rktToDrawEnt[localId]; - MachAnyId const anyId = rockets.localToAny[localId]; + MachAnyId const anyId = rockets.machanyIdOf[localId]; PartId const part = rScnParts.machineToPart[anyId]; ActiveEnt const partEnt = rScnParts.partToActive[part]; - auto const& portSpan = floats.machToNode[anyId]; + auto const& portSpan = floats.machToNode[anyId.value]; NodeId const throttleIn = connected_node(portSpan, ports_magicrocket::gc_throttleIn.port); NodeId const multiplierIn = connected_node(portSpan, ports_magicrocket::gc_multiplierIn.port); @@ -199,20 +200,20 @@ FeatureDef const ftrMagicRocketThrustIndicator = feature_def("MagicRocketThrustI 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]; + MachType const &rockets = rLinks.machines.perType[gc_mtMagicRocket]; + NodeType 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]) + for (MachinePair const pair : rScnParts.partToMachines[part.value]) { if (pair.type == gc_mtMagicRocket) { DrawEnt const drawEnt = rThrustIndicator.rktToDrawEnt[pair.local]; - MachAnyId const anyId = rockets.localToAny[pair.local]; + MachAnyId const anyId = rockets.machanyIdOf[pair.local]; - auto const& portSpan = floats.machToNode[anyId]; + auto const& portSpan = floats.machToNode[anyId.value]; NodeId const throttleIn = connected_node(portSpan, ports_magicrocket::gc_throttleIn.port); NodeId const multiplierIn = connected_node(portSpan, ports_magicrocket::gc_multiplierIn.port); @@ -262,13 +263,13 @@ FeatureDef const ftrMachRCSDriver = feature_def("RCSDriver", [] ( .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]; + NodeType const &rFloatNodes = rLinks.nodePerType[gc_ntSigFloat]; + MachType &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]}; + MachAnyId const mach = rRockets.machanyIdOf[local]; + auto const portSpan = lgrn::Span{rFloatNodes.machToNode[mach.value]}; NodeId const thrNode = connected_node(portSpan, ports_rcsdriver::gc_throttleOut.port); if (thrNode == lgrn::id_null()) @@ -378,14 +379,15 @@ FeatureDef const ftrVehicleControl = feature_def("VehicleControl", [] ( .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]; + MachType &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; + ++rVhControls.selectedUsrCtrl.value; bool found = false; - for (MachLocalId local = rVhControls.selectedUsrCtrl; local < rUsrCtrl.localIds.capacity(); ++local) + auto const capacity = std::uint32_t(rUsrCtrl.localIds.capacity()); + for (MachLocalId local = rVhControls.selectedUsrCtrl; local.value < capacity; ++local.value) { if (rUsrCtrl.localIds.exists(local)) { @@ -402,7 +404,7 @@ FeatureDef const ftrVehicleControl = feature_def("VehicleControl", [] ( } else { - OSP_LOG_INFO("Selected User Control: {}", rVhControls.selectedUsrCtrl); + OSP_LOG_INFO("Selected User Control: {}", rVhControls.selectedUsrCtrl.value); } } }); @@ -424,8 +426,8 @@ FeatureDef const ftrVehicleControl = feature_def("VehicleControl", [] ( return; // No vehicle selected } - Nodes const &rFloatNodes = rLinks.nodePerType[gc_ntSigFloat]; - float const thrRate = deltaTimeIn; + NodeType const &rFloatNodes = rLinks.nodePerType[gc_ntSigFloat]; + float const thrRate = deltaTimeIn; float const thrChange = held(rVC.btnThrMore, thrRate) - held(rVC.btnThrLess, thrRate) @@ -438,9 +440,9 @@ FeatureDef const ftrVehicleControl = feature_def("VehicleControl", [] ( 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]}; + MachType &rUsrCtrl = rLinks.machines.perType[gc_mtUserCtrl]; + MachAnyId const mach = rUsrCtrl.machanyIdOf[rVC.selectedUsrCtrl]; + auto const portSpan = lgrn::Span{rFloatNodes.machToNode[mach.value]}; 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) @@ -486,11 +488,11 @@ FeatureDef const ftrVehicleControl = feature_def("VehicleControl", [] ( // 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); + MachType const& rUsrCtrls = rLinks.machines.perType.at(adera::gc_mtUserCtrl); + MachAnyId const selectedMach = rUsrCtrls.machanyIdOf .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)) { @@ -506,6 +508,7 @@ FeatureDef const ftrVehicleControl = feature_def("VehicleControl", [] ( }); // ftrVehicleControl +#endif } // namespace adera diff --git a/src/adera_app/features/vehicles_prebuilt.cpp b/src/adera_app/features/vehicles_prebuilt.cpp index fe437a84..555b3569 100644 --- a/src/adera_app/features/vehicles_prebuilt.cpp +++ b/src/adera_app/features/vehicles_prebuilt.cpp @@ -23,10 +23,12 @@ * SOFTWARE. */ #include "vehicles_prebuilt.h" +#include "vehicles.h" + #include "../feature_interfaces.h" -#include +#include #include @@ -56,6 +58,7 @@ struct RCSInputs NodeId m_roll {lgrn::id_null()}; }; +/* static void add_rcs_machines(VehicleBuilder& rFB, RCSInputs const& inputs, PartId part, float thrustMul, Matrix4 const& tf) { namespace ports_rcsdriver = adera::ports_rcsdriver; @@ -114,6 +117,31 @@ static void add_rcs_block(VehicleBuilder& rFB, VehicleBuilder::WeldVec_t& rWeldT rWeldTo.push_back({ nozzleB, nozzleTfB }); } +static void add_rcs_mirrored(VehicleBuilder& rFB, VehicleBuilder::WeldVec_t& rWeldTo, RCSInputs const& inputs, float thrustMul, Vector3 pos, Quaternion rot) +{ + auto const [ nozzleA, nozzleB ] = rFB.create_parts<2>(); + rFB.set_prefabs({ + { nozzleA, "phLinRCS" }, + { nozzleB, "phLinRCS" } + }); + + constexpr Vector3 mirrorX = Vector3{-1.0f, 1.0f, 1.0f}; + + // sort of just guessed, and this happened to work + Quaternion const rotMirrored{rot.vector() * mirrorX, -rot.scalar() }; + + Matrix4 const nozzleTfA = quick_transform(pos, rot); + Matrix4 const nozzleTfB = quick_transform(pos * mirrorX, rotMirrored); + + + add_rcs_machines(rFB, inputs, nozzleA, thrustMul, nozzleTfA); + add_rcs_machines(rFB, inputs, nozzleB, thrustMul, nozzleTfB); + + rWeldTo.push_back({ nozzleA, nozzleTfA }); + rWeldTo.push_back({ nozzleB, nozzleTfB }); +} +*/ + FeatureDef const ftrPrebuiltVehicles = feature_def("PrebuiltVehicles", [] ( FeatureBuilder &rFB, Implement testVhcls, @@ -123,11 +151,30 @@ 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()); + //auto &rPrebuiltVehicles = rFB.data_emplace(testVhcls.di.prebuiltVehicles); + //rPrebuiltVehicles.resize(PrebuiltVhIdReg_t::size()); using namespace adera; + + Framework fw; + + // Contexts adds a way to separate major sections of the Framework. + // Feature Interfaces are added per-context. A context can't have two of the same + // implementations of a Feature Interface. If we were to add two aquariums that are logically + // separated and can run in parallel, we can use two contexts. + ContextId const ctx = fw.m_contextIds.create(); + + ContextBuilder cb{ctx, {}, fw}; + cb.add_feature(ftrLinks); + ContextBuilder::finalize(std::move(cb)); + + VehicleBuilder vb(std::move(fw), ctx); + + + + /* +asdf // Build "PartVehicle" { VehicleBuilder vbuilder{&rResources}; @@ -212,8 +259,84 @@ FeatureDef const ftrPrebuiltVehicles = feature_def("PrebuiltVehicles", [] ( } + // Build "Solvalot-1" + { + VehicleBuilder vbuilder{&rResources}; + VehicleBuilder::WeldVec_t toWeld; + + auto const [ fusalage, engineA, engineB ] = vbuilder.create_parts<3>(); + vbuilder.set_prefabs({ + { fusalage, "solvalot1" }, + { engineA, "phEngine" }, + { engineB, "phEngine" }, + }); + + toWeld.push_back( {fusalage, quick_transform({ 0.0f, 0.0f, 0.0f}, {})} ); + toWeld.push_back( {engineA, quick_transform({ 0.0f, -0.12f, -3.76f}, {} )} ); + toWeld.push_back( {engineB, quick_transform({ 0.0f, 1.1f, -3.70f}, Quaternion::rotation(17.8_degf, {1.0f, 0.0f, 0.0f}))} ); + namespace ports_magicrocket = adera::ports_magicrocket; + namespace ports_userctrl = adera::ports_userctrl; + + auto const [ pitch, yaw, roll, throttle, thrustMul ] = vbuilder.create_nodes<5>(gc_ntSigFloat); + + auto &rFloatValues = vbuilder.node_values< SignalValues_t >(gc_ntSigFloat); + rFloatValues[thrustMul] = 120000.0f; + + vbuilder.create_machine(fusalage, gc_mtUserCtrl, { + { ports_userctrl::gc_throttleOut, throttle }, + { ports_userctrl::gc_pitchOut, pitch }, + { ports_userctrl::gc_yawOut, yaw }, + { ports_userctrl::gc_rollOut, roll } + } ); + + vbuilder.create_machine(engineA, gc_mtMagicRocket, { + { ports_magicrocket::gc_throttleIn, throttle }, + { ports_magicrocket::gc_multiplierIn, thrustMul } + } ); + + vbuilder.create_machine(engineB, gc_mtMagicRocket, { + { ports_magicrocket::gc_throttleIn, throttle }, + { ports_magicrocket::gc_multiplierIn, thrustMul } + } ); + + + RCSInputs rcsInputs{pitch, yaw, roll}; + + // for roll + add_rcs_mirrored(vbuilder, toWeld, rcsInputs, 12000.0f, Vector3{4.952f, -0.351f, -1.492f}, Quaternion::rotation(90.0_degf, {1.0f, 0.0f, 0.0f})); + add_rcs_mirrored(vbuilder, toWeld, rcsInputs, 12000.0f, Vector3{4.952f, -0.827f, -1.492f}, Quaternion::rotation(-90.0_degf, {1.0f, 0.0f, 0.0f})); + + // for pitch + add_rcs_mirrored(vbuilder, toWeld, rcsInputs, 5000.0f, Vector3{0.506f, 0.545f, 3.412f}, Quaternion::rotation(90.0_degf, {1.0f, 0.0f, 0.0f})); + add_rcs_mirrored(vbuilder, toWeld, rcsInputs, 5000.0f, Vector3{0.506f, -1.441f, 3.412f}, Quaternion::rotation(-90.0_degf, {1.0f, 0.0f, 0.0f})); + + add_rcs_mirrored(vbuilder, toWeld, rcsInputs, 4000.0f, Vector3{0.5061700940132141, + -1.4411895275115967, + -3.2911040782928467}, Quaternion::rotation(-90.0_degf, {1.0f, 0.0f, 0.0f})); + add_rcs_mirrored(vbuilder, toWeld, rcsInputs, 4000.0f, Vector3{0.5061700940132141f, + 2.2311899662017822f, + -3.2911040782928467f}, Quaternion::rotation(90.0_degf, {1.0f, 0.0f, 0.0f})); + + + // for yaw + add_rcs_mirrored(vbuilder, toWeld, rcsInputs, 15000.0f, Vector3{0.6308508515357971, + -0.6648790836334229, + 4.920871734619141}, Quaternion::rotation(-90.0_degf, {0.0f, 1.0f, 0.0f})); + add_rcs_mirrored(vbuilder, toWeld, rcsInputs, 15000.0f, Vector3{ 5.238207817077637, + -0.6648790836334229, + -5.217004776000977}, Quaternion::rotation(-90.0_degf, {0.0f, 1.0f, 0.0f})); + + + vbuilder.weld(toWeld); + + rPrebuiltVehicles[gc_pbvSolvalot1] = std::make_unique(std::move(vbuilder.finalize_release())); + } +*/ + + // Put more prebuilt vehicles here! + /* rFB.task() .name ("Clean up prebuilt vehicles") @@ -233,6 +356,7 @@ FeatureDef const ftrPrebuiltVehicles = feature_def("PrebuiltVehicles", [] ( } rPrebuildVehicles.clear(); }); +*/ }); // setup_prebuilt_vehicles diff --git a/src/adera_app/features/vehicles_prebuilt.h b/src/adera_app/features/vehicles_prebuilt.h index 5061e58f..6526fa82 100644 --- a/src/adera_app/features/vehicles_prebuilt.h +++ b/src/adera_app/features/vehicles_prebuilt.h @@ -40,13 +40,14 @@ namespace adera using PrebuiltVhId = osp::StrongId; using PrebuiltVhIdReg_t = osp::GlobalIdReg; -struct PrebuiltVehicles : osp::KeyedVec< PrebuiltVhId, std::unique_ptr > -{ - PrebuiltVehicles() = default; - OSP_MOVE_ONLY_CTOR_ASSIGN(PrebuiltVehicles); -}; - -inline PrebuiltVhId const gc_pbvSimpleCommandServiceModule = PrebuiltVhIdReg_t::create(); +// struct PrebuiltVehicles : osp::KeyedVec< PrebuiltVhId, std::unique_ptr > +// { +// PrebuiltVehicles() = default; +// OSP_MOVE_ONLY_CTOR_ASSIGN(PrebuiltVehicles); +// }; + +inline PrebuiltVhId const gc_pbvSimpleCommandServiceModule = PrebuiltVhIdReg_t::create(); +inline PrebuiltVhId const gc_pbvSolvalot1 = PrebuiltVhIdReg_t::create(); extern osp::fw::FeatureDef const ftrPrebuiltVehicles; diff --git a/src/gdextension/scenarios.cpp b/src/gdextension/scenarios.cpp index 7caa3e1d..87884d94 100644 --- a/src/gdextension/scenarios.cpp +++ b/src/gdextension/scenarios.cpp @@ -155,6 +155,7 @@ static ScenarioMap_t make_scenarios() add_floor(rFW, sceneCtx, pkg, 4); +#if 0 auto vhclSpawn = rFW.get_interface(sceneCtx); auto vhclSpawnVB = rFW.get_interface(sceneCtx); auto testVhcls = rFW.get_interface(sceneCtx); @@ -173,7 +174,7 @@ static ScenarioMap_t make_scenarios() }); rVehicleSpawnVB.dataVB.push_back(rPrebuiltVehicles[gc_pbvSimpleCommandServiceModule].get()); } - +#endif }}); return scenarioMap; diff --git a/src/gdextension/sessions/godot.cpp b/src/gdextension/sessions/godot.cpp index 0c02b3be..61042fd6 100644 --- a/src/gdextension/sessions/godot.cpp +++ b/src/gdextension/sessions/godot.cpp @@ -40,7 +40,7 @@ #include #include -#include +#include #include #include diff --git a/src/osp/activescene/vehicles.h b/src/osp/activescene/vehicles.h index 6a913c45..226d74b0 100644 --- a/src/osp/activescene/vehicles.h +++ b/src/osp/activescene/vehicles.h @@ -26,44 +26,40 @@ #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 "../link/link.h" #include #include -#include - namespace osp::active { -using PartId = uint32_t; -using WeldId = uint32_t; +using PartId = osp::StrongId; +using WeldId = osp::StrongId; -struct ACtxLinks -{ - ACtxLinks() = default; - OSP_MOVE_ONLY_CTOR_ASSIGN(ACtxLinks); - link::Machines machines; - KeyedVec nodePerType; -}; +//struct ACtxLinks +//{ +// ACtxLinks() = default; +// OSP_MOVE_ONLY_CTOR_ASSIGN(ACtxLinks); +// link::Machines machines; +// KeyedVec nodePerType; +//}; struct ACtxParts { - using MapPartToMachines_t = lgrn::IntArrayMultiMap; + using MapPartToMachines_t = lgrn::IntArrayMultiMap; + using MapWeldToPart_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; + MapWeldToPart_t weldToParts; KeyedVec partToWeld; MapPartToMachines_t partToMachines; @@ -76,10 +72,10 @@ struct ACtxParts }; -using SpVehicleId = StrongId; -using SpPartId = StrongId; -using SpWeldId = StrongId; -using SpMachAnyId = StrongId; +using SpVehicleId = StrongId; +using SpPartId = StrongId; +using SpWeldId = StrongId; +using SpMachAnyId = StrongId; struct ACtxVehicleSpawn { diff --git a/src/osp/core/keyed_vector.h b/src/osp/core/keyed_vector.h index de374b4b..ec1c69dd 100644 --- a/src/osp/core/keyed_vector.h +++ b/src/osp/core/keyed_vector.h @@ -55,6 +55,8 @@ class KeyedVec : public std::vector using difference_type = typename vector_t::difference_type; using size_type = typename vector_t::size_type; + using vector_t::vector_t; + constexpr vector_t& base() noexcept { return *this; } constexpr vector_t const& base() const noexcept { return *this; } diff --git a/src/osp/core/strong_id.h b/src/osp/core/strong_id.h index 4b5452f9..e252106f 100644 --- a/src/osp/core/strong_id.h +++ b/src/osp/core/strong_id.h @@ -45,6 +45,7 @@ namespace osp template struct StrongId { + using int_t = INT_T; using entity_type = INT_T; // Name used for entt compatibility constexpr StrongId() noexcept = default; diff --git a/src/osp/link/machines.cpp b/src/osp/link/link.cpp similarity index 63% rename from src/osp/link/machines.cpp rename to src/osp/link/link.cpp index 696354e8..b8222b6b 100644 --- a/src/osp/link/machines.cpp +++ b/src/osp/link/link.cpp @@ -22,18 +22,24 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -#include "machines.h" +#include "link.h" namespace osp::link { +GlobalLinkInfo& GlobalLinkInfo::instance() +{ + static GlobalLinkInfo info; + return info; +} + void copy_nodes( - Nodes const &rSrcNodes, - Machines const &rSrcMach, - Corrade::Containers::ArrayView remapMach, - Nodes &rDstNodes, - Machines &rDstMach, - Corrade::Containers::ArrayView remapNode) + NodeType const &rSrcNodes, + Links const &rSrcMach, + Corrade::Containers::ArrayView remapMach, + NodeType &rDstNodes, + Links &rDstMach, + Corrade::Containers::ArrayView remapNode) { using lgrn::Span; @@ -41,7 +47,7 @@ void copy_nodes( for (NodeId const srcNode : rSrcNodes.nodeIds) { NodeId const dstNode = rDstNodes.nodeIds.create(); - remapNode[srcNode] = dstNode; + remapNode[srcNode.value] = dstNode; } // Copy node-to-machine connections @@ -50,21 +56,21 @@ void copy_nodes( + 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]; + NodeId const dstNode = remapNode[srcNode.value]; + Span srcJunction = rSrcNodes.nodeToMach[srcNode.value]; + rDstNodes.nodeToMach.emplace(dstNode.value, srcJunction.size()); + Span dstJuncton = rDstNodes.nodeToMach[dstNode.value]; 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]; + MachTypeId const machType = MachTypeId{srcJunc.type}; + MachAnyId const srcMach = rSrcMach.machtype[machType].machanyIdOf[MachLocalId{srcJunc.local}]; + MachAnyId const dstMach = remapMach[srcMach.value]; + MachLocalId const dstLocal = rDstMach.machlocalidOf[dstMach]; - dstJuncIt->local = dstLocal; - dstJuncIt->type = machType; + dstJuncIt->local = dstLocal.value; + dstJuncIt->type = machType.value; dstJuncIt->custom = srcJunc.custom; std::advance(dstJuncIt, 1); @@ -72,23 +78,23 @@ void copy_nodes( } // copy mach-to-node connections - rDstNodes.machToNode.ids_reserve(rDstMach.ids.capacity()); + rDstNodes.machToNode.ids_reserve(rDstMach.machIds.capacity()); rDstNodes.machToNode.data_reserve(rDstNodes.machToNode.data_size() + rSrcNodes.machToNode.data_size()); - for (MachAnyId const srcMach : rSrcMach.ids) + for (MachAnyId const srcMach : rSrcMach.machIds) { - if (rSrcNodes.machToNode.contains(srcMach)) + if (rSrcNodes.machToNode.contains(srcMach.value)) { - Span srcPorts = rSrcNodes.machToNode[srcMach]; - MachAnyId const dstMach = remapMach[srcMach]; - rDstNodes.machToNode.emplace(dstMach, srcPorts.size()); - Span dstPorts = rDstNodes.machToNode[dstMach]; + Span srcPorts = rSrcNodes.machToNode[srcMach.value]; + MachAnyId const dstMach = remapMach[srcMach.value]; + rDstNodes.machToNode.emplace(dstMach.value, srcPorts.size()); + Span dstPorts = rDstNodes.machToNode[dstMach.value]; auto dstPortIt = std::begin(dstPorts); for (NodeId const srcNode : srcPorts) { *dstPortIt = (srcNode != lgrn::id_null()) - ? remapNode[srcNode] + ? remapNode[srcNode.value] : lgrn::id_null(); std::advance(dstPortIt, 1); diff --git a/src/osp/link/link.h b/src/osp/link/link.h new file mode 100644 index 00000000..45461b93 --- /dev/null +++ b/src/osp/link/link.h @@ -0,0 +1,224 @@ +/** + * 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 "../core/strong_id.h" + +#include +#include +#include +#include + +#include +#include +#include + + +namespace osp::link +{ + +using MachTypeId = osp::StrongId< std::uint16_t, struct DummyForMachTypeId >; +using MachAnyId = osp::StrongId< std::uint32_t, struct DummyForMachAnyId >; +using MachLocalId = osp::StrongId< std::uint32_t, struct DummyForMachLocalId >; + +using NodeTypeId = osp::StrongId< std::uint16_t, struct DummyForNodeTypeId >; +using TransmitModeId = osp::StrongId< std::uint16_t, struct DummyForTransmitModeId >; +using NodeId = osp::StrongId< std::uint32_t, struct DummyForNodeId >; + +using PortId = osp::StrongId< std::uint16_t, struct DummyForPortId >; +using JunctionId = osp::StrongId< std::uint16_t, struct DummyForJunctionId >; +using JuncCustom = std::uint16_t; + +struct NodeTypeInfo +{ + TransmitModeId transmitMode; + std::size_t nodeDataSize; +}; + +struct GlobalLinkInfo +{ + // TODO: maybe put some private or more encapsulation stuff here; just made this work for now + + static GlobalLinkInfo& instance(); + + MachTypeId create_machtype() { return machtypeIds.create(); }; + + TransmitModeId create_transmitmode() { return transmitmodeIds.create(); }; + + NodeTypeId create_nodetype(NodeTypeInfo info) + { + NodeTypeId const id = nodetypeIds.create(); + infoOfNodetype.resize(nodetypeIds.capacity()); + infoOfNodetype[id] = info; + return id; + } + + osp::KeyedVec infoOfNodetype; + + lgrn::IdRegistryStl machtypeIds; + lgrn::IdRegistryStl transmitmodeIds; + lgrn::IdRegistryStl nodetypeIds; +}; + +// Not yet used, for example only +inline TransmitModeId const gc_tmStructure = GlobalLinkInfo::instance().create_transmitmode(); +inline TransmitModeId const gc_tmSimpleFluid = GlobalLinkInfo::instance().create_transmitmode(); + + +/** + * @brief Keeps track of Machines of a certain type that exists + */ +struct MachType +{ + lgrn::IdRegistryStl localIds; + osp::KeyedVec machanyIdOf; +}; + +struct Junction +{ + MachLocalId::int_t local; + MachTypeId::int_t type; + JuncCustom custom {0}; +}; + +struct NodeType +{ + NodeType() = default; + OSP_MOVE_ONLY_CTOR(NodeType); +// NodeType(NodeType const& copy) = delete; +// NodeType(NodeType&& move) = delete; +// NodeType& operator= (NodeType const& copy) = delete; +// NodeType& operator= (NodeType&& move) = delete; + + static constexpr std::size_t smc_blockSize = 64; + static constexpr std::size_t smc_blockAlign = 64; + struct alignas(smc_blockAlign) Block + { + std::byte data[smc_blockAlign]; + }; + + // 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; + + std::size_t stride; // copy of NodeTypeInfo::nodeDataSize + std::vector data; + std::size_t capacity; +}; + +struct Links +{ + Links() = default; + OSP_MOVE_ONLY_CTOR_ASSIGN(Links); + + lgrn::IdRegistryStl machIds; + + osp::KeyedVec machTypeOf; + osp::KeyedVec machlocalidOf; + + osp::KeyedVec machtype; + osp::KeyedVec< NodeTypeId, std::unique_ptr > nodetype; +}; + +/** + * @brief Machine Local and type ID. Equivalent to a MachAnyId + */ +struct MachinePair +{ + MachLocalId local; + MachTypeId type; +}; + +struct PortEntry +{ + NodeTypeId type; + PortId port; + JuncCustom custom; +}; + +using RequestMachId = osp::StrongId< std::uint32_t, struct DummyForRequestMachId >; +using RequestNodeId = osp::StrongId< std::uint32_t, struct DummyForRequestNodeId >; + +struct RequestMachine +{ + MachTypeId type; +}; + +struct RequestNode +{ + NodeTypeId type; +}; + +struct RequestConnect +{ + NodeId node; + NodeTypeId nodeType; +}; + + +struct PartType +{ + +}; + + +struct MachineUpdater +{ + alignas(64) std::atomic requestMachineUpdateLoop {false}; + + lgrn::IdSetStl machTypesDirty; + + osp::KeyedVec> localDirty; +}; + +inline NodeId connected_node(lgrn::Span portSpan, PortId port) noexcept +{ + return (portSpan.size() > port.value) ? portSpan[port.value] : NodeId{}; +} + +void copy_nodes( + NodeType const &rSrcNodes, + Links const &rSrcMach, + ArrayView remapMach, + NodeType &rDstNodes, + Links &rDstMach, + ArrayView remapNodeOut); + +} // namespace osp::wire 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 index 39249faf..0d638bf5 100644 --- a/src/osp/link/signal.h +++ b/src/osp/link/signal.h @@ -24,16 +24,28 @@ */ #pragma once -#include "machines.h" +#include "link.h" namespace osp::link { + +inline TransmitModeId const gc_tmLogicSignal = GlobalLinkInfo::instance().create_transmitmode(); + +inline NodeTypeId const gc_ntSigFloat = GlobalLinkInfo::instance().create_nodetype(NodeTypeInfo{ + .transmitMode = gc_tmLogicSignal, .nodeDataSize = sizeof(float) +}); + + + constexpr JuncCustom gc_sigIn = 0; constexpr JuncCustom gc_sigOut = 1; +inline PortEntry sigfloat_input(std::uint16_t portId) { return PortEntry{gc_ntSigFloat, PortId{portId}, gc_sigIn}; } +inline PortEntry sigfloat_output(std::uint16_t portId) { return PortEntry{gc_ntSigFloat, PortId{portId}, gc_sigOut}; } + template -using SignalValues_t = std::vector; +using SignalValues_t = osp::KeyedVec; template struct UpdateNodes @@ -51,39 +63,19 @@ struct UpdateNodes } }; -template -bool update_signal_nodes( - RANGE_T const& toUpdate, - Nodes::NodeToMach_t const& nodeToMach, - Machines const& machines, - ArrayView newValues, - ArrayView currentValues, - MachineUpdater& rUpdMach) +inline void notify_connected_inputs(NodeId const nodeId, NodeType::NodeToMach_t const& nodeToMach, MachineUpdater& rUpdMach) { - bool somethingNotified = false; - - for (uint32_t const node : toUpdate) + for (Junction junc : nodeToMach[nodeId.value]) { - // Apply node value changes - currentValues[node] = newValues[node]; - - // Notify connected inputs - for (Junction junc : nodeToMach[node]) + if (junc.custom == gc_sigIn) { - if (junc.custom == gc_sigIn) - { - somethingNotified = true; + // A machine of type "junc.m_type" has new values to read + rUpdMach.machTypesDirty.insert(MachTypeId{junc.type}); - // 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); - } + // Specify using local Id on which machine needs to update + rUpdMach.localDirty[MachTypeId{junc.type}].insert(MachLocalId{junc.local}); } } - - return somethingNotified; } } // namespace osp::wire diff --git a/src/testapp/features/magnum.cpp b/src/testapp/features/magnum.cpp index ca08a734..5cf3b560 100644 --- a/src/testapp/features/magnum.cpp +++ b/src/testapp/features/magnum.cpp @@ -29,7 +29,7 @@ #include -#include +#include #include #include #include diff --git a/src/testapp/main.cpp b/src/testapp/main.cpp index f40a3fa8..b215096c 100644 --- a/src/testapp/main.cpp +++ b/src/testapp/main.cpp @@ -417,9 +417,8 @@ void load_a_bunch_of_stuff() "ph_capsule.sturdy.gltf", "ph_fuselage.sturdy.gltf", "ph_engine.sturdy.gltf", - //"ph_plume.sturdy.gltf", - "ph_rcs.sturdy.gltf" - //"ph_rcs_plume.sturdy.gltf" + "ph_rcs.sturdy.gltf", + "solvalot.sturdy.gltf" }; // TODO: Make new gltf loader. This will read gltf files and dump meshes, diff --git a/src/testapp/scenarios.cpp b/src/testapp/scenarios.cpp index a3c72d48..1701720f 100644 --- a/src/testapp/scenarios.cpp +++ b/src/testapp/scenarios.cpp @@ -178,29 +178,30 @@ static ScenarioMap_t make_scenarios() 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(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(ftrMachMagicRockets); +// sceneCB.add_feature(ftrMachRCSDriver); sceneCB.add_feature(ftrJolt); sceneCB.add_feature(ftrJoltConstAccel); sceneCB.add_feature(ftrPhysicsShapesJolt); - sceneCB.add_feature(ftrVehicleSpawnJolt); - sceneCB.add_feature(ftrRocketThrustJolt); +// sceneCB.add_feature(ftrVehicleSpawnJolt); +// sceneCB.add_feature(ftrRocketThrustJolt); ContextBuilder::finalize(std::move(sceneCB)); 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); +// set_vehicle_default_factors(gravity, args.rFW, sceneCtx); add_floor(args.rFW, sceneCtx, args.defaultPkg, 4); +#if 0 auto vhclSpawn = args.rFW.get_interface(sceneCtx); auto vhclSpawnVB = args.rFW.get_interface(sceneCtx); auto testVhcls = args.rFW.get_interface(sceneCtx); @@ -219,6 +220,7 @@ static ScenarioMap_t make_scenarios() }); rVehicleSpawnVB.dataVB.push_back(rPrebuiltVehicles[gc_pbvSimpleCommandServiceModule].get()); } +#endif }}); @@ -414,20 +416,20 @@ static ScenarioMap_t make_scenarios() 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(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(ftrMachMagicRockets); +// sceneCB.add_feature(ftrMachRCSDriver); sceneCB.add_feature(ftrJolt); sceneCB.add_feature(ftrJoltConstAccel); sceneCB.add_feature(ftrPhysicsShapesJolt); - sceneCB.add_feature(ftrVehicleSpawnJolt); - sceneCB.add_feature(ftrRocketThrustJolt); +// sceneCB.add_feature(ftrVehicleSpawnJolt); +// sceneCB.add_feature(ftrRocketThrustJolt); sceneCB.add_feature(ftrTerrainJolt); @@ -438,10 +440,11 @@ 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); +// set_vehicle_default_factors(gravity, args.rFW, sceneCtx); //add_floor(args.rFW, sceneCtx, args.defaultPkg, 4); +#if 0 auto vhclSpawn = args.rFW.get_interface(sceneCtx); auto vhclSpawnVB = args.rFW.get_interface(sceneCtx); auto testVhcls = args.rFW.get_interface(sceneCtx); @@ -450,16 +453,28 @@ static ScenarioMap_t make_scenarios() 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) + for (int i = 0; i < 2; ++i) { rVehicleSpawn.spawnRequest.push_back( { - .position = {float(i - 2) * 8.0f, 30.0f, 10.0f}, - .velocity = {0.0, 0.0f, 50.0f * float(i)}, + .position = {float(i - 2) * 15.0f, 30.0f, 10.0f}, + .velocity = {0.0, 0.0f, 0.0f}, + .rotation = {} + }); + rVehicleSpawnVB.dataVB.push_back(rPrebuiltVehicles[gc_pbvSolvalot1].get()); + } + + for (int i = 0; i < 2; ++i) + { + rVehicleSpawn.spawnRequest.push_back( + { + .position = {float(i - 2) * 15.0f, 0.0f, 10.0f}, + .velocity = {0.0, 0.0f, 0.0f}, .rotation = {} }); rVehicleSpawnVB.dataVB.push_back(rPrebuiltVehicles[gc_pbvSimpleCommandServiceModule].get()); } +#endif }}); return scenarioMap; diff --git a/src/testapp/scenarios_magnum.cpp b/src/testapp/scenarios_magnum.cpp index ddb2ce97..25ee1afc 100644 --- a/src/testapp/scenarios_magnum.cpp +++ b/src/testapp/scenarios_magnum.cpp @@ -148,8 +148,8 @@ ContextId make_scene_renderer(Framework &rFW, PkgId defaultPkg, ContextId mainCo if (rFW.get_interface_id(sceneCtx).has_value()) { - scnRdrCB.add_feature(ftrVehicleSpawnDraw); - scnRdrCB.add_feature(ftrVehicleControl); +// scnRdrCB.add_feature(ftrVehicleSpawnDraw); +// scnRdrCB.add_feature(ftrVehicleControl); } else { @@ -158,7 +158,7 @@ ContextId make_scene_renderer(Framework &rFW, PkgId defaultPkg, ContextId mainCo if (rFW.get_interface_id(sceneCtx).has_value()) { - scnRdrCB.add_feature(ftrMagicRocketThrustIndicator, TplPkgIdMaterialId{ defaultPkg, matFlat }); +// scnRdrCB.add_feature(ftrMagicRocketThrustIndicator, TplPkgIdMaterialId{ defaultPkg, matFlat }); } if ( ! scnRdrCB.has_error() && rFW.get_interface_id(sceneCtx).has_value() )