summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorNiels Breuker <niels.breuker@hotmail.nl>2023-03-31 14:27:14 +0200
committerNiels Breuker <niels.breuker@hotmail.nl>2023-03-31 14:27:14 +0200
commitc3dfa60882d94bbf5893b5c4e91384ff57a21e8b (patch)
tree7e9a217cac3425f29f8b2bc4dc664dda8b2bdd73 /src
parentPieceGenerator: Added functionality to end a structure with a custom prefab. (diff)
downloadcuberite-PieceGenClosurePieces.tar
cuberite-PieceGenClosurePieces.tar.gz
cuberite-PieceGenClosurePieces.tar.bz2
cuberite-PieceGenClosurePieces.tar.lz
cuberite-PieceGenClosurePieces.tar.xz
cuberite-PieceGenClosurePieces.tar.zst
cuberite-PieceGenClosurePieces.zip
Diffstat (limited to '')
-rw-r--r--src/Generating/PieceGeneratorBFSTree.cpp41
-rw-r--r--src/Generating/PiecePool.h3
-rw-r--r--src/Generating/PrefabPiecePool.cpp36
-rw-r--r--src/Generating/PrefabPiecePool.h1
-rw-r--r--src/Generating/VillageGen.cpp7
5 files changed, 29 insertions, 59 deletions
diff --git a/src/Generating/PieceGeneratorBFSTree.cpp b/src/Generating/PieceGeneratorBFSTree.cpp
index cf6e82ca3..7aaebe75c 100644
--- a/src/Generating/PieceGeneratorBFSTree.cpp
+++ b/src/Generating/PieceGeneratorBFSTree.cpp
@@ -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);
diff --git a/src/Generating/PiecePool.h b/src/Generating/PiecePool.h
index 2e027e354..5897f32c7 100644
--- a/src/Generating/PiecePool.h
+++ b/src/Generating/PiecePool.h
@@ -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;
diff --git a/src/Generating/PrefabPiecePool.cpp b/src/Generating/PrefabPiecePool.cpp
index b78251d78..1fbdac8af 100644
--- a/src/Generating/PrefabPiecePool.cpp
+++ b/src/Generating/PrefabPiecePool.cpp
@@ -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())
diff --git a/src/Generating/PrefabPiecePool.h b/src/Generating/PrefabPiecePool.h
index 36aaf8bae..27bcf1965 100644
--- a/src/Generating/PrefabPiecePool.h
+++ b/src/Generating/PrefabPiecePool.h
@@ -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;
diff --git a/src/Generating/VillageGen.cpp b/src/Generating/VillageGen.cpp
index 281d49541..6575b2f3a 100644
--- a/src/Generating/VillageGen.cpp
+++ b/src/Generating/VillageGen.cpp
@@ -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();