Instead of explicit closure pieces try to place pieces with a single connector.

This commit is contained in:
Niels Breuker 2023-03-31 14:27:14 +02:00
parent 4af1f3ac35
commit c3dfa60882
5 changed files with 29 additions and 59 deletions

View File

@ -108,14 +108,33 @@ bool cPieceGeneratorBFSTree::TryPlacePieceAtConnector(
// Get a list of available connections: // Get a list of available connections:
cConnections Connections; cConnections Connections;
int WantedConnectorType = -a_Connector.m_Type; int WantedConnectorType = -a_Connector.m_Type;
cPieces AvailablePieces; cPieces AvailablePieces = m_PiecePool.GetPiecesWithConnector(WantedConnectorType);
if (a_OnlyClosurePieces) if (a_OnlyClosurePieces)
{ {
AvailablePieces = m_PiecePool.GetClosurePiecesWithConnector(WantedConnectorType); cPieces closurePieces;
} closurePieces.reserve(AvailablePieces.size());
else for (auto & piece : AvailablePieces)
{ {
AvailablePieces = m_PiecePool.GetPiecesWithConnector(WantedConnectorType); auto hitBox = piece->GetHitBox();
hitBox.Sort();
auto pieceSize = hitBox.p2 - hitBox.p1;
auto connectors = piece->GetConnectors();
Vector3i lastCoord = connectors[0].m_Pos;
bool hasMultipleConnectors = false;
for (const auto & connector : connectors)
{
if (connector.m_Pos != lastCoord)
{
hasMultipleConnectors = true;
break;
}
}
if (!hasMultipleConnectors)
{
closurePieces.push_back(piece);
}
}
AvailablePieces = closurePieces;
} }
Connections.reserve(AvailablePieces.size()); Connections.reserve(AvailablePieces.size());
Vector3i ConnPos = cPiece::cConnector::AddDirection(a_Connector.m_Pos, a_Connector.m_Direction); // The position at which the new connector should be placed - 1 block away from the current connector Vector3i ConnPos = cPiece::cConnector::AddDirection(a_Connector.m_Pos, a_Connector.m_Direction); // The position at which the new connector should be placed - 1 block away from the current connector
@ -123,14 +142,8 @@ bool cPieceGeneratorBFSTree::TryPlacePieceAtConnector(
FindPieceForConnector(AvailablePieces, a_ParentPiece, a_Connector, WantedConnectorType, ConnPos, a_OutPieces, Connections, WeightTotal); FindPieceForConnector(AvailablePieces, a_ParentPiece, a_Connector, WantedConnectorType, ConnPos, a_OutPieces, Connections, WeightTotal);
if (Connections.empty()) if (Connections.empty())
{ {
// If there are no available connections try to place a closure connector. // No available connections, bail out
AvailablePieces = m_PiecePool.GetClosurePiecesWithConnector(WantedConnectorType); return false;
FindPieceForConnector(AvailablePieces, a_ParentPiece, a_Connector, WantedConnectorType, ConnPos, a_OutPieces, Connections, WeightTotal);
if (Connections.empty())
{
// No available connections, bail out
return false;
}
} }
ASSERT(WeightTotal > 0); ASSERT(WeightTotal > 0);

View File

@ -284,9 +284,6 @@ public:
The cPiece pointers returned are managed by the pool and the caller doesn't free them. */ The cPiece pointers returned are managed by the pool and the caller doesn't free them. */
virtual cPieces GetPiecesWithConnector(int a_ConnectorType) = 0; virtual cPieces GetPiecesWithConnector(int a_ConnectorType) = 0;
/** Returns a list of closure pieces that contain the specified connector type. */
virtual cPieces GetClosurePiecesWithConnector(int a_ConnectorType) = 0;
/** Returns the pieces that should be used as the starting point. /** Returns the pieces that should be used as the starting point.
Multiple starting points are supported, one of the returned piece will be chosen. */ Multiple starting points are supported, one of the returned piece will be chosen. */
virtual cPieces GetStartingPieces(void) = 0; virtual cPieces GetStartingPieces(void) = 0;

View File

@ -350,18 +350,8 @@ bool cPrefabPiecePool::LoadCubesetPieceVer1(const AString & a_FileName, cLuaStat
else else
{ {
auto p = prefab.release(); auto p = prefab.release();
m_AllPieces.push_back(p);
int IsClosurePiece = 0; AddToPerConnectorMap(p);
a_LuaState.GetNamedValue("Metadata.IsClosurePiece", IsClosurePiece);
if (IsClosurePiece != 0)
{
m_ClosurePieces.push_back(p);
}
else
{
m_AllPieces.push_back(p);
AddToPerConnectorMap(p);
}
} }
return true; return true;
@ -773,28 +763,6 @@ cPieces cPrefabPiecePool::GetPiecesWithConnector(int a_ConnectorType)
cPieces cPrefabPiecePool::GetClosurePiecesWithConnector(int a_ConnectorType)
{
cPieces pieces;
for (auto& piece : m_ClosurePieces)
{
auto connectors = piece->GetConnectors();
for (auto& connector : connectors)
{
if (connector.m_Type == a_ConnectorType)
{
pieces.push_back(piece);
break;
}
}
}
return pieces;
}
cPieces cPrefabPiecePool::GetStartingPieces(void) cPieces cPrefabPiecePool::GetStartingPieces(void)
{ {
if (m_StartingPieces.empty()) if (m_StartingPieces.empty())

View File

@ -112,7 +112,6 @@ public:
// cPiecePool overrides: // cPiecePool overrides:
virtual cPieces GetPiecesWithConnector(int a_ConnectorType) override; virtual cPieces GetPiecesWithConnector(int a_ConnectorType) override;
virtual cPieces GetClosurePiecesWithConnector(int a_ConnectorType) override;
virtual cPieces GetStartingPieces(void) override; virtual cPieces GetStartingPieces(void) override;
virtual int GetPieceWeight(const cPlacedPiece & a_PlacedPiece, const cPiece::cConnector & a_ExistingConnector, const cPiece & a_NewPiece) override; virtual int GetPieceWeight(const cPlacedPiece & a_PlacedPiece, const cPiece::cConnector & a_ExistingConnector, const cPiece & a_NewPiece) override;
virtual int GetStartingPieceWeight(const cPiece & a_NewPiece) override; virtual int GetStartingPieceWeight(const cPiece & a_NewPiece) override;

View File

@ -258,13 +258,6 @@ protected:
} }
virtual cPieces GetClosurePiecesWithConnector(int a_ConnectorType) override
{
cPieces pieces;
return pieces;
}
virtual cPieces GetStartingPieces(void) override virtual cPieces GetStartingPieces(void) override
{ {
return m_Prefabs.GetStartingPieces(); return m_Prefabs.GetStartingPieces();