summaryrefslogtreecommitdiffstats
path: root/src/Generating/PrefabPiecePool.cpp
diff options
context:
space:
mode:
authorTycho <work.tycho+git@gmail.com>2014-05-25 19:02:33 +0200
committerTycho <work.tycho+git@gmail.com>2014-05-25 19:02:33 +0200
commit8133efd7f9def01b81ef2a52c05d8ec5b7f89632 (patch)
treea56f6889aea8de8759fab87abdee2eef778873ed /src/Generating/PrefabPiecePool.cpp
parentFixed bug in freeing NULL pointers (diff)
parentinject TestGlobals.h correctly (diff)
downloadcuberite-8133efd7f9def01b81ef2a52c05d8ec5b7f89632.tar
cuberite-8133efd7f9def01b81ef2a52c05d8ec5b7f89632.tar.gz
cuberite-8133efd7f9def01b81ef2a52c05d8ec5b7f89632.tar.bz2
cuberite-8133efd7f9def01b81ef2a52c05d8ec5b7f89632.tar.lz
cuberite-8133efd7f9def01b81ef2a52c05d8ec5b7f89632.tar.xz
cuberite-8133efd7f9def01b81ef2a52c05d8ec5b7f89632.tar.zst
cuberite-8133efd7f9def01b81ef2a52c05d8ec5b7f89632.zip
Diffstat (limited to 'src/Generating/PrefabPiecePool.cpp')
-rw-r--r--src/Generating/PrefabPiecePool.cpp121
1 files changed, 121 insertions, 0 deletions
diff --git a/src/Generating/PrefabPiecePool.cpp b/src/Generating/PrefabPiecePool.cpp
new file mode 100644
index 000000000..ed9340815
--- /dev/null
+++ b/src/Generating/PrefabPiecePool.cpp
@@ -0,0 +1,121 @@
+
+// PrefabPiecePool.cpp
+
+// Implements the cPrefabPiecePool class that represents a cPiecePool descendant that uses cPrefab instances as the pieces
+
+#include "Globals.h"
+#include "PrefabPiecePool.h"
+
+
+
+
+
+cPrefabPiecePool::cPrefabPiecePool(
+ const cPrefab::sDef * a_PieceDefs, size_t a_NumPieceDefs,
+ const cPrefab::sDef * a_StartingPieceDefs, size_t a_NumStartingPieceDefs
+)
+{
+ AddPieceDefs(a_PieceDefs, a_NumPieceDefs);
+ if (a_StartingPieceDefs != NULL)
+ {
+ AddStartingPieceDefs(a_StartingPieceDefs, a_NumStartingPieceDefs);
+ }
+}
+
+
+
+
+
+void cPrefabPiecePool::AddPieceDefs(const cPrefab::sDef * a_PieceDefs, size_t a_NumPieceDefs)
+{
+ ASSERT(a_PieceDefs != NULL);
+ for (size_t i = 0; i < a_NumPieceDefs; i++)
+ {
+ cPrefab * Prefab = new cPrefab(a_PieceDefs[i]);
+ m_AllPieces.push_back(Prefab);
+ AddToPerConnectorMap(Prefab);
+ }
+}
+
+
+
+
+
+void cPrefabPiecePool::AddStartingPieceDefs(const cPrefab::sDef * a_StartingPieceDefs, size_t a_NumStartingPieceDefs)
+{
+ ASSERT(a_StartingPieceDefs != NULL);
+ for (size_t i = 0; i < a_NumStartingPieceDefs; i++)
+ {
+ cPrefab * Prefab = new cPrefab(a_StartingPieceDefs[i]);
+ m_StartingPieces.push_back(Prefab);
+ }
+}
+
+
+
+
+
+void cPrefabPiecePool::AddToPerConnectorMap(cPrefab * a_Prefab)
+{
+ cPiece::cConnectors Connectors = ((const cPiece *)a_Prefab)->GetConnectors();
+ for (cPiece::cConnectors::const_iterator itr = Connectors.begin(), end = Connectors.end(); itr != end; ++itr)
+ {
+ m_PiecesByConnector[itr->m_Type].push_back(a_Prefab);
+ }
+}
+
+
+
+
+cPieces cPrefabPiecePool::GetPiecesWithConnector(int a_ConnectorType)
+{
+ return m_PiecesByConnector[a_ConnectorType];
+}
+
+
+
+
+
+cPieces cPrefabPiecePool::GetStartingPieces(void)
+{
+ if (m_StartingPieces.empty())
+ {
+ return m_AllPieces;
+ }
+ else
+ {
+ return m_StartingPieces;
+ }
+}
+
+
+
+
+
+int cPrefabPiecePool::GetPieceWeight(const cPlacedPiece & a_PlacedPiece, const cPiece::cConnector & a_ExistingConnector, const cPiece & a_NewPiece)
+{
+ return ((const cPrefab &)a_NewPiece).GetPieceWeight(a_PlacedPiece, a_ExistingConnector);
+}
+
+
+
+
+
+void cPrefabPiecePool::PiecePlaced(const cPiece & a_Piece)
+{
+ // Do nothing
+ UNUSED(a_Piece);
+}
+
+
+
+
+
+void cPrefabPiecePool::Reset(void)
+{
+ // Do nothing
+}
+
+
+
+