mirror of
https://github.com/cuberite/cuberite.git
synced 2025-01-07 03:16:55 +08:00
Instead of explicit closure pieces try to place pieces with a single connector.
This commit is contained in:
parent
4af1f3ac35
commit
c3dfa60882
@ -108,14 +108,33 @@ bool cPieceGeneratorBFSTree::TryPlacePieceAtConnector(
|
||||
// Get a list of available connections:
|
||||
cConnections Connections;
|
||||
int WantedConnectorType = -a_Connector.m_Type;
|
||||
cPieces AvailablePieces;
|
||||
cPieces AvailablePieces = m_PiecePool.GetPiecesWithConnector(WantedConnectorType);
|
||||
if (a_OnlyClosurePieces)
|
||||
{
|
||||
AvailablePieces = m_PiecePool.GetClosurePiecesWithConnector(WantedConnectorType);
|
||||
}
|
||||
else
|
||||
{
|
||||
AvailablePieces = m_PiecePool.GetPiecesWithConnector(WantedConnectorType);
|
||||
cPieces closurePieces;
|
||||
closurePieces.reserve(AvailablePieces.size());
|
||||
for (auto & piece : AvailablePieces)
|
||||
{
|
||||
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());
|
||||
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);
|
||||
if (Connections.empty())
|
||||
{
|
||||
// If there are no available connections try to place a closure connector.
|
||||
AvailablePieces = m_PiecePool.GetClosurePiecesWithConnector(WantedConnectorType);
|
||||
FindPieceForConnector(AvailablePieces, a_ParentPiece, a_Connector, WantedConnectorType, ConnPos, a_OutPieces, Connections, WeightTotal);
|
||||
if (Connections.empty())
|
||||
{
|
||||
// No available connections, bail out
|
||||
return false;
|
||||
}
|
||||
// No available connections, bail out
|
||||
return false;
|
||||
}
|
||||
ASSERT(WeightTotal > 0);
|
||||
|
||||
|
@ -284,9 +284,6 @@ public:
|
||||
The cPiece pointers returned are managed by the pool and the caller doesn't free them. */
|
||||
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.
|
||||
Multiple starting points are supported, one of the returned piece will be chosen. */
|
||||
virtual cPieces GetStartingPieces(void) = 0;
|
||||
|
@ -350,18 +350,8 @@ bool cPrefabPiecePool::LoadCubesetPieceVer1(const AString & a_FileName, cLuaStat
|
||||
else
|
||||
{
|
||||
auto p = prefab.release();
|
||||
|
||||
int IsClosurePiece = 0;
|
||||
a_LuaState.GetNamedValue("Metadata.IsClosurePiece", IsClosurePiece);
|
||||
if (IsClosurePiece != 0)
|
||||
{
|
||||
m_ClosurePieces.push_back(p);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_AllPieces.push_back(p);
|
||||
AddToPerConnectorMap(p);
|
||||
}
|
||||
m_AllPieces.push_back(p);
|
||||
AddToPerConnectorMap(p);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
if (m_StartingPieces.empty())
|
||||
|
@ -112,7 +112,6 @@ public:
|
||||
|
||||
// cPiecePool overrides:
|
||||
virtual cPieces GetPiecesWithConnector(int a_ConnectorType) override;
|
||||
virtual cPieces GetClosurePiecesWithConnector(int a_ConnectorType) 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 GetStartingPieceWeight(const cPiece & a_NewPiece) override;
|
||||
|
@ -258,13 +258,6 @@ protected:
|
||||
}
|
||||
|
||||
|
||||
virtual cPieces GetClosurePiecesWithConnector(int a_ConnectorType) override
|
||||
{
|
||||
cPieces pieces;
|
||||
return pieces;
|
||||
}
|
||||
|
||||
|
||||
virtual cPieces GetStartingPieces(void) override
|
||||
{
|
||||
return m_Prefabs.GetStartingPieces();
|
||||
|
Loading…
Reference in New Issue
Block a user