Skip to content

Commit

Permalink
Merge pull request #247 from Capital-Asterisk/readd-vehicles-again
Browse files Browse the repository at this point in the history
Re-add vehicles again
  • Loading branch information
Capital-Asterisk authored Oct 31, 2023
2 parents d961604 + 4ead181 commit a65640f
Show file tree
Hide file tree
Showing 45 changed files with 3,791 additions and 2,824 deletions.
4 changes: 2 additions & 2 deletions bin/settings.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ holdable = true
[vehicle_thr_max]
primary = "Z"
secondary = "None"
holdable = false
holdable = true

[vehicle_thr_min]
primary = "X"
secondary = "None"
holdable = false
holdable = true

[vehicle_thr_more]
primary = "LShift"
Expand Down
76 changes: 38 additions & 38 deletions src/adera/activescene/VehicleBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,26 +116,26 @@ osp::link::MachAnyId VehicleBuilder::create_machine(PartId const part,
std::initializer_list<Connection> const& connections)
{
auto &rData = m_data.value();
osp::link::PerMachType &rPerMachType = rData.m_machines.m_perType[machType];
osp::link::PerMachType &rPerMachType = rData.m_machines.perType[machType];

MachTypeId const mach = rData.m_machines.m_ids.create();
MachTypeId const mach = rData.m_machines.ids.create();

std::size_t const capacity = rData.m_machines.m_ids.capacity();
rData.m_machines.m_machTypes.resize(capacity);
rData.m_machines.m_machToLocal.resize(capacity);
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.m_machToNode.ids_reserve(capacity);
rPerNodeType.machToNode.ids_reserve(capacity);
rPerNodeType.m_machToNodeCustom.ids_reserve(capacity);
}

MachTypeId const local = rPerMachType.m_localIds.create();
rPerMachType.m_localToAny.resize(rPerMachType.m_localIds.capacity());
MachTypeId const local = rPerMachType.localIds.create();
rPerMachType.localToAny.resize(rPerMachType.localIds.capacity());

rData.m_machines.m_machTypes[mach] = machType;
rData.m_machines.m_machToLocal[mach] = local;
rPerMachType.m_localToAny[local] = mach;
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;
Expand All @@ -152,8 +152,8 @@ void VehicleBuilder::connect(MachAnyId const mach, std::initializer_list<Connect
std::vector<int> nodePortMax(rData.m_nodePerType.size(), 0);
for (Connection const& connect : connections)
{
int &rPortMax = nodePortMax[connect.m_port.m_type];
rPortMax = std::max<int>(rPortMax, connect.m_port.m_port + 1);
int &rPortMax = nodePortMax[connect.m_port.type];
rPortMax = std::max<int>(rPortMax, connect.m_port.port + 1);
}

for (NodeTypeId nodeType = 0; std::size_t(nodeType) < rData.m_nodePerType.size(); ++nodeType)
Expand All @@ -163,23 +163,23 @@ void VehicleBuilder::connect(MachAnyId const mach, std::initializer_list<Connect
if (portMax != 0)
{
// reallocate each time :)
rPerNodeType.m_machToNode.data_reserve(rPerNodeType.m_machToNode.data_capacity() + portMax);
rPerNodeType.m_machToNodeCustom.data_reserve(rPerNodeType.m_machToNode.data_capacity() + portMax);
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.m_machToNode.emplace(mach, portMax);
lgrn::Span<NodeId> const portSpan = rPerNodeType.m_machToNode[mach];
rPerNodeType.machToNode.emplace(mach, portMax);
lgrn::Span<NodeId> const portSpan = rPerNodeType.machToNode[mach];
std::fill(std::begin(portSpan), std::end(portSpan), lgrn::id_null<NodeId>());
rPerNodeType.m_machToNodeCustom.emplace(mach, portMax);
lgrn::Span<uint16_t> const customSpan = rPerNodeType.m_machToNodeCustom[mach];
std::fill(std::begin(customSpan), std::end(customSpan), 0);

for (Connection const& connect : connections)
{
if (connect.m_port.m_type == nodeType)
if (connect.m_port.type == nodeType)
{
customSpan[connect.m_port.m_port] = connect.m_port.m_custom;
portSpan[connect.m_port.m_port] = connect.m_node;
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 ++;
}
Expand All @@ -200,18 +200,18 @@ VehicleData VehicleBuilder::finalize_release()
PerNodeType &rPerNodeType = rData.m_nodePerType[nodeType];

// reserve node-to-machine partitions
rPerNodeType.m_nodeToMach.data_reserve(rPerNodeType.m_connectCountTotal);
for (NodeId node : rPerNodeType.m_nodeIds.bitview().zeros())
rPerNodeType.nodeToMach.data_reserve(rPerNodeType.m_connectCountTotal);
for (NodeId node : rPerNodeType.nodeIds.bitview().zeros())
{
rPerNodeType.m_nodeToMach.emplace(node, rPerNodeType.m_nodeConnectCount[node]);
lgrn::Span<Junction> junction = rPerNodeType.m_nodeToMach[node];
rPerNodeType.nodeToMach.emplace(node, rPerNodeType.m_nodeConnectCount[node]);
lgrn::Span<Junction> junction = rPerNodeType.nodeToMach[node];
std::fill(std::begin(junction), std::end(junction), Junction{});
}

// assign node-to-machine
for (MachAnyId const mach : rData.m_machines.m_ids.bitview().zeros())
for (MachAnyId const mach : rData.m_machines.ids.bitview().zeros())
{
lgrn::Span<NodeId> portSpan = rPerNodeType.m_machToNode[mach];
lgrn::Span<NodeId> portSpan = rPerNodeType.machToNode[mach];
lgrn::Span<JuncCustom> customSpan = rPerNodeType.m_machToNodeCustom[mach];

for (int i = 0; i < portSpan.size(); ++i)
Expand All @@ -223,42 +223,42 @@ VehicleData VehicleBuilder::finalize_release()
continue;
}

lgrn::Span<Junction> const juncSpan = rPerNodeType.m_nodeToMach[node];
lgrn::Span<Junction> 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.m_type == lgrn::id_null<MachTypeId>();
return pair.type == lgrn::id_null<MachTypeId>();
});
assert(found != std::end(juncSpan));

MachTypeId const type = rData.m_machines.m_machTypes[mach];
MachLocalId const local = rData.m_machines.m_machToLocal[mach];
MachTypeId const type = rData.m_machines.machTypes[mach];
MachLocalId const local = rData.m_machines.machToLocal[mach];

found->m_local = local;
found->m_type = type;
found->m_custom = customSpan[i];
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.m_ids.capacity());
rData.m_partToMachines.data_reserve(rData.m_machines.ids.capacity());
for (PartId const part : rData.m_partIds.bitview().zeros())
{
rData.m_partToMachines.emplace(part, m_partMachCount[part]);
}

// Assign part-to-machine partitions
for (MachAnyId const mach : rData.m_machines.m_ids.bitview().zeros())
for (MachAnyId const mach : rData.m_machines.ids.bitview().zeros())
{
MachLocalId const local = rData.m_machines.m_machToLocal[mach];
MachTypeId const type = rData.m_machines.m_machTypes[mach];
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<MachinePair>{rData.m_partToMachines[part]};

Expand All @@ -268,7 +268,7 @@ VehicleData VehicleBuilder::finalize_release()
assert(rPartMachCount != 0);
-- rPartMachCount;

machines[rPartMachCount] = { .m_local = local, .m_type = type };
machines[rPartMachCount] = { .local = local, .type = type };
}

assert(std::all_of(m_partMachCount.begin(), m_partMachCount.end(),
Expand Down
55 changes: 8 additions & 47 deletions src/adera/activescene/VehicleBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#pragma once

#include <osp/activescene/vehicles.h>
#include <osp/core/copymove_macros.h>
#include <osp/core/resourcetypes.h>
#include <osp/link/machines.h>

Expand Down Expand Up @@ -68,11 +69,10 @@ struct VehicleData
{
using MachToNodeCustom_t = lgrn::IntArrayMultiMap<osp::link::MachAnyId,
osp::link::JuncCustom>;
using MapPartToMachines_t = osp::active::Parts::MapPartToMachines_t;
using MapPartToMachines_t = osp::active::ACtxParts::MapPartToMachines_t;

VehicleData() = default;
VehicleData(VehicleData const& copy) = delete;
VehicleData(VehicleData&& move) = default;
OSP_MOVE_ONLY_CTOR(VehicleData);

lgrn::IdRegistryStl<PartId> m_partIds;
std::vector<osp::Matrix4> m_partTransformWeld;
Expand Down Expand Up @@ -114,7 +114,7 @@ class VehicleBuilder
: m_pResources{pResources}
{
auto &rData = m_data.emplace();
rData.m_machines.m_perType.resize(osp::link::MachTypeReg_t::size());
rData.m_machines.perType.resize(osp::link::MachTypeReg_t::size());
rData.m_nodePerType.resize(osp::link::NodeTypeReg_t::size());
index_prefabs();
};
Expand Down Expand Up @@ -151,7 +151,7 @@ class VehicleBuilder

std::size_t node_capacity(NodeTypeId nodeType) const
{
return m_data->m_nodePerType[nodeType].m_nodeIds.capacity();
return m_data->m_nodePerType[nodeType].nodeIds.capacity();
}

struct Connection
Expand Down Expand Up @@ -205,9 +205,9 @@ std::array<osp::link::NodeId, N> VehicleBuilder::create_nodes(NodeTypeId const n

PerNodeType &rPerNodeType = m_data->m_nodePerType[nodeType];

rPerNodeType.m_nodeIds.create(std::begin(out), std::end(out));
std::size_t const capacity = rPerNodeType.m_nodeIds.capacity();
rPerNodeType.m_nodeToMach.ids_reserve(rPerNodeType.m_nodeIds.capacity());
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;
Expand All @@ -230,43 +230,4 @@ VALUES_T& VehicleBuilder::node_values(NodeTypeId nodeType)
return rValues;
}

struct ACtxVehicleSpawnVB
{
std::vector<VehicleData const*> m_dataVB;

// 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 = m_remapParts[m_remapPartOffsets[newVehicleIndex] + srcPart];

inline Corrade::Containers::StridedArrayView2D<std::size_t> remap_node_offsets_2d() noexcept
{
return {Corrade::Containers::arrayView(m_remapNodeOffsets.data(), m_remapNodeOffsets.size()),
{m_dataVB.size(), osp::link::NodeTypeReg_t::size()}};
}

inline Corrade::Containers::StridedArrayView2D<std::size_t const> remap_node_offsets_2d() const noexcept
{
return {Corrade::Containers::arrayView(m_remapNodeOffsets.data(), m_remapNodeOffsets.size()),
{m_dataVB.size(), osp::link::NodeTypeReg_t::size()}};
}

std::vector<osp::active::PartId> m_remapParts;
std::vector<std::size_t> m_remapPartOffsets;

std::vector<osp::active::PartId> m_remapWelds;
std::vector<std::size_t> m_remapWeldOffsets;

std::vector<std::size_t> m_machtypeCount;
std::vector<osp::link::MachAnyId> m_remapMachs;
std::vector<std::size_t> m_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<osp::link::NodeId> m_remapNodes;
std::vector<std::size_t> m_remapNodeOffsets;
};

} // namespace testapp
Loading

0 comments on commit a65640f

Please sign in to comment.