diff options
author | Tycho <work.tycho+git@gmail.com> | 2014-05-25 19:02:33 +0200 |
---|---|---|
committer | Tycho <work.tycho+git@gmail.com> | 2014-05-25 19:02:33 +0200 |
commit | 8133efd7f9def01b81ef2a52c05d8ec5b7f89632 (patch) | |
tree | a56f6889aea8de8759fab87abdee2eef778873ed /src/Generating/PrefabPiecePool.h | |
parent | Fixed bug in freeing NULL pointers (diff) | |
parent | inject TestGlobals.h correctly (diff) | |
download | cuberite-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.h')
-rw-r--r-- | src/Generating/PrefabPiecePool.h | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/src/Generating/PrefabPiecePool.h b/src/Generating/PrefabPiecePool.h new file mode 100644 index 000000000..c6a5ad360 --- /dev/null +++ b/src/Generating/PrefabPiecePool.h @@ -0,0 +1,79 @@ + +// PrefabPiecePool.h + +// Declares the cPrefabPiecePool class that represents a cPiecePool descendant that uses cPrefab instances as the pieces + + + + + +#pragma once + +#include "PieceGenerator.h" +#include "Prefab.h" + + + + + +class cPrefabPiecePool : + public cPiecePool +{ +public: + /** Creates an empty instance. Prefabs can be added by calling AddPieceDefs() and AddStartingPieceDefs(). */ + cPrefabPiecePool(void); + + /** Creates a piece pool with prefabs from the specified definitions. + If both a_PieceDefs and a_StartingPieceDefs are given, only the a_StartingPieceDefs are used as starting + pieces for the pool, and they do not participate in the generation any further. + If only a_PieceDefs is given, any such piece can be chosen as a starting piece, and all the pieces are used + for generating. + More pieces can be added to the instance afterwards by calling AddPieceDefs() and AddStartingPieceDefs(). */ + cPrefabPiecePool( + const cPrefab::sDef * a_PieceDefs, size_t a_NumPieceDefs, + const cPrefab::sDef * a_StartingPieceDefs, size_t a_NumStartingPieceDefs + ); + + /** Adds pieces from the specified definitions into m_AllPieces. Also adds the pieces into + the m_PiecesByConnector map. + May be called multiple times with different PieceDefs, will add all such pieces. */ + void AddPieceDefs(const cPrefab::sDef * a_PieceDefs, size_t a_NumPieceDefs); + + /** Adds pieces from the specified definitions into m_StartingPieces. Doesn't add them to + the m_PiecesByConnector map. + May be called multiple times with different PieceDefs, will add all such pieces. */ + void AddStartingPieceDefs(const cPrefab::sDef * a_StartingPieceDefs, size_t a_NumStartingPieceDefs); + + +protected: + + /** The type used to map a connector type to the list of pieces with that connector */ + typedef std::map<int, cPieces> cPiecesMap; + + /** All the pieces that are allowed for building. + This is the list that's used for memory allocation and deallocation for the pieces. */ + cPieces m_AllPieces; + + /** The pieces that are used as starting pieces. + This list is not shared and the pieces need deallocation. */ + cPieces m_StartingPieces; + + /** The map that has all pieces by their connector types + The pieces are copies out of m_AllPieces and shouldn't be ever delete-d. */ + cPiecesMap m_PiecesByConnector; + + + /** Adds the prefab to the m_PiecesByConnector map for all its connectors. */ + void AddToPerConnectorMap(cPrefab * a_Prefab); + + // cPiecePool overrides: + virtual cPieces GetPiecesWithConnector(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 void PiecePlaced(const cPiece & a_Piece) override; + virtual void Reset(void) override; +} ; + + + + |