Cuberite
A lightweight, fast and extensible game server for Minecraft
PieceGeneratorBFSTree.h
Go to the documentation of this file.
1 
2 // PieceGeneratorBFSTree.h
3 
4 // Declares the cPieceGeneratorBFSTree class for generating structures composed of individual "pieces" in a simple tree
5 
6 
7 
8 
9 
10 #pragma once
11 
12 #include "PiecePool.h"
13 #include "../Noise/Noise.h"
14 
15 
16 
17 
18 
20 {
21 public:
23  cPieceGeneratorBFSTree(cPiecePool & a_PiecePool, int a_Seed);
24 
25 
28  void PlacePieces(int a_BlockX, int a_BlockZ, int a_MaxDepth, cPlacedPieces & a_OutPieces);
29 
30 
31 protected:
32 
34  struct cConnection
35  {
36  cPiece * m_Piece; // The piece being connected
37  cPiece::cConnector m_Connector; // The piece's connector being used (relative non-rotated coords)
38  int m_NumCCWRotations; // Number of rotations necessary to match the two connectors
39  int m_Weight; // Relative chance that this connection will be chosen
40 
41  cConnection(cPiece & a_Piece, cPiece::cConnector & a_Connector, int a_NumCCWRotations, int a_Weight);
42  };
43  typedef std::vector<cConnection> cConnections;
44 
45 
48  {
51 
52  cFreeConnector(cPlacedPiece * a_Piece, const cPiece::cConnector & a_Connector);
53  };
54  typedef std::vector<cFreeConnector> cFreeConnectors;
55 
56 
59 
62 
64  int m_Seed;
65 
66 
69  cPlacedPiecePtr PlaceStartingPiece(int a_BlockX, int a_BlockZ, cFreeConnectors & a_OutConnectors);
70 
73  const cPlacedPiece & a_ParentPiece, // The existing piece to a new piece should be placed
74  const cPiece::cConnector & a_Connector, // The existing connector (world-coords) to which a new piece should be placed
75  cPlacedPieces & a_OutPieces, // Already placed pieces, to be checked for intersections
76  cFreeConnectors & a_OutConnectors // List of free connectors to which the new connectors will be placed
77  );
78 
85  bool CheckConnection(
86  const cPiece::cConnector & a_ExistingConnector, // The existing connector
87  const Vector3i & a_ToPos, // The position on which the new connector should be placed
88  const cPiece & a_Piece, // The new piece
89  const cPiece::cConnector & a_NewConnector, // The connector of the new piece
90  int a_NumCCWRotations, // Number of rotations for the new piece to align the connector
91  const cPlacedPieces & a_OutPieces // All the already-placed pieces to check
92  );
93 
96  void DebugConnectorPool(const cFreeConnectors & a_ConnectorPool, size_t a_NumProcessed);
97 } ;
98 
99 
100 
101 
std::unique_ptr< cPlacedPiece > cPlacedPiecePtr
Definition: PiecePool.h:369
std::vector< cPlacedPiecePtr > cPlacedPieces
Definition: PiecePool.h:370
bool CheckConnection(const cPiece::cConnector &a_ExistingConnector, const Vector3i &a_ToPos, const cPiece &a_Piece, const cPiece::cConnector &a_NewConnector, int a_NumCCWRotations, const cPlacedPieces &a_OutPieces)
Checks if the specified piece would fit with the already-placed pieces, using the specified connector...
bool TryPlacePieceAtConnector(const cPlacedPiece &a_ParentPiece, const cPiece::cConnector &a_Connector, cPlacedPieces &a_OutPieces, cFreeConnectors &a_OutConnectors)
Tries to place a new piece at the specified (placed) connector.
cPlacedPiecePtr PlaceStartingPiece(int a_BlockX, int a_BlockZ, cFreeConnectors &a_OutConnectors)
Selects a starting piece and places it, including its height and rotation.
void DebugConnectorPool(const cFreeConnectors &a_ConnectorPool, size_t a_NumProcessed)
DEBUG: Outputs all the connectors in the pool into stdout.
std::vector< cConnection > cConnections
cPieceGeneratorBFSTree(cPiecePool &a_PiecePool, int a_Seed)
Creates a new object tied to the specified PiecePool, using the specified seed.
int m_Seed
The seed used by this generator.
cPiecePool & m_PiecePool
The pool from which pieces are taken.
void PlacePieces(int a_BlockX, int a_BlockZ, int a_MaxDepth, cPlacedPieces &a_OutPieces)
Generates a placement for pieces at the specified coords.
std::vector< cFreeConnector > cFreeConnectors
cNoise m_Noise
The noise used for random number generation.
The type used for storing a connection from one piece to another, while building the piece tree.
cConnection(cPiece &a_Piece, cPiece::cConnector &a_Connector, int a_NumCCWRotations, int a_Weight)
The type used for storing a pool of connectors that will be attempted to expand by another piece.
cFreeConnector(cPlacedPiece *a_Piece, const cPiece::cConnector &a_Connector)
Represents a single piece.
Definition: PiecePool.h:21
This class is an interface that stores pieces for a generator.
Definition: PiecePool.h:278
Represents a single piece that has been placed to specific coords in the world.
Definition: PiecePool.h:328
Definition: Noise.h:20