diff options
Diffstat (limited to 'src/Generating/PiecePool.h')
-rw-r--r-- | src/Generating/PiecePool.h | 162 |
1 files changed, 91 insertions, 71 deletions
diff --git a/src/Generating/PiecePool.h b/src/Generating/PiecePool.h index 5897f32c7..adfa9204b 100644 --- a/src/Generating/PiecePool.h +++ b/src/Generating/PiecePool.h @@ -19,7 +19,7 @@ /** Represents a single piece. Can have multiple connectors of different types where other pieces can connect. */ class cPiece { -public: + public: // Force a virtual destructor in all descendants virtual ~cPiece() {} @@ -28,22 +28,25 @@ public: enum eDirection { // The following values correspond to equivalent eBlockFace values: - dirXM = BLOCK_FACE_XM, // Pointing towards the X- side of the prefab - dirXP = BLOCK_FACE_XP, // Pointing towards the X+ side of the prefab - dirYM = BLOCK_FACE_YM, // Pointing towards the Y- side of the prefab, doesn't change with rotation around the Y axis - dirYP = BLOCK_FACE_YP, // Pointing towards the Y+ side of the prefab, doesn't change with rotation around the Y axis - dirZM = BLOCK_FACE_ZM, // Pointing towards the Z- side of the prefab - dirZP = BLOCK_FACE_ZP, // Pointing towards the Z+ side of the prefab + dirXM = BLOCK_FACE_XM, // Pointing towards the X- side of the prefab + dirXP = BLOCK_FACE_XP, // Pointing towards the X+ side of the prefab + dirYM = BLOCK_FACE_YM, // Pointing towards the Y- side of the prefab, doesn't change with rotation around + // the Y axis + dirYP = BLOCK_FACE_YP, // Pointing towards the Y+ side of the prefab, doesn't change with rotation around + // the Y axis + dirZM = BLOCK_FACE_ZM, // Pointing towards the Z- side of the prefab + dirZP = BLOCK_FACE_ZP, // Pointing towards the Z+ side of the prefab // Special kind of the vertical connectors (changes with rotation around the Y axis) - dirYM_XM_ZM = BLOCK_FACE_MAX + 1, // Pointing towards the Y- side of the prefab, conceptually at the X- Z- corner of the block - dirYM_XM_ZP, // Pointing towards the Y- side of the prefab, conceptually at the X- Z+ corner of the block - dirYM_XP_ZM, // Pointing towards the Y- side of the prefab, conceptually at the X+ Z- corner of the block - dirYM_XP_ZP, // Pointing towards the Y- side of the prefab, conceptually at the X+ Z+ corner of the block - dirYP_XM_ZM, // Pointing towards the Y+ side of the prefab, conceptually at the X- Z- corner of the block - dirYP_XM_ZP, // Pointing towards the Y+ side of the prefab, conceptually at the X- Z+ corner of the block - dirYP_XP_ZM, // Pointing towards the Y+ side of the prefab, conceptually at the X+ Z- corner of the block - dirYP_XP_ZP, // Pointing towards the Y+ side of the prefab, conceptually at the X+ Z+ corner of the block + dirYM_XM_ZM = BLOCK_FACE_MAX + + 1, // Pointing towards the Y- side of the prefab, conceptually at the X- Z- corner of the block + dirYM_XM_ZP, // Pointing towards the Y- side of the prefab, conceptually at the X- Z+ corner of the block + dirYM_XP_ZM, // Pointing towards the Y- side of the prefab, conceptually at the X+ Z- corner of the block + dirYM_XP_ZP, // Pointing towards the Y- side of the prefab, conceptually at the X+ Z+ corner of the block + dirYP_XM_ZM, // Pointing towards the Y+ side of the prefab, conceptually at the X- Z- corner of the block + dirYP_XM_ZP, // Pointing towards the Y+ side of the prefab, conceptually at the X- Z+ corner of the block + dirYP_XP_ZM, // Pointing towards the Y+ side of the prefab, conceptually at the X+ Z- corner of the block + dirYP_XP_ZP, // Pointing towards the Y+ side of the prefab, conceptually at the X+ Z+ corner of the block }; /** Position relative to the piece */ @@ -80,10 +83,10 @@ public: /** Returns the direction corresponding to the given direction rotated 90 degrees CW around the Y axis. */ static eDirection RotateDirectionCW(eDirection a_Direction); - /** Returns the number of CCW rotations that a_RotatingDir requires in order to be the counter-direction of a_FixedDir. - Ie. if you have a connector with a_FixedDir and you're rotating a piece that has a connector with a_RotatingDir, - how many CCW rotations it needs to make the connectors compatible. - Returns -1 if it is impossible to fit the two directions. */ + /** Returns the number of CCW rotations that a_RotatingDir requires in order to be the counter-direction of + a_FixedDir. Ie. if you have a connector with a_FixedDir and you're rotating a piece that has a connector with + a_RotatingDir, how many CCW rotations it needs to make the connectors compatible. Returns -1 if it is impossible + to fit the two directions. */ static int GetNumCCWRotationsToFit(eDirection a_FixedDir, eDirection a_RotatingDir); /** Converts the string representation of a direction into the eDirection enum value. @@ -99,7 +102,7 @@ public: Descendants can override the GetVerticalPlacement() method to provide custom placement decisions. */ class cVerticalStrategy { - public: + public: // Force a virtual destructor in descendants virtual ~cVerticalStrategy() {} @@ -107,15 +110,21 @@ public: virtual int GetVerticalPlacement(int a_BlockX, int a_BlockZ) = 0; /** Initializes the strategy's parameters from the string representation. - a_Params is the string containing only the parameters (substring after the first pipe character in the strategy description string). - If a_LogWarnings is true, logs any problems to the console. - Returns true if successful, false if the string parsing failed. - Used when loading the strategy from a file. */ + a_Params is the string containing only the parameters (substring after the first pipe character in the strategy + description string). If a_LogWarnings is true, logs any problems to the console. Returns true if successful, + false if the string parsing failed. Used when loading the strategy from a file. */ virtual bool InitializeFromString(const AString & a_Params, bool a_LogWarnings) = 0; /** Called when the piece pool is assigned to a generator, so that the strategies may bind to the underlying subgenerators. */ - virtual void AssignGens(int a_Seed, cBiomeGen & a_BiomeGen, cTerrainHeightGen & a_TerrainHeightGen, int a_SeaLevel) {} + virtual void AssignGens( + int a_Seed, + cBiomeGen & a_BiomeGen, + cTerrainHeightGen & a_TerrainHeightGen, + int a_SeaLevel + ) + { + } }; typedef std::shared_ptr<cVerticalStrategy> cVerticalStrategyPtr; @@ -125,7 +134,7 @@ public: Each placed piece can have a limit, represented by this class, that gets queried for validity of the placement. */ class cVerticalLimit { - public: + public: virtual ~cVerticalLimit() {} /** Called to inquire whether the specified piece can be placed at the specified height. @@ -134,15 +143,21 @@ public: virtual bool CanBeAtHeight(int a_BlockX, int a_BlockZ, int a_Height) = 0; /** Initializes the limit's parameters from the string representation. - a_Params is the string containing only the parameters (substring after the first pipe character in the limit description string). - Returns true if successful, false if the string parsing failed. - If a_LogWarnings is true, any error while parsing the string is output to the server console. - Used when loading the limit from a file. */ + a_Params is the string containing only the parameters (substring after the first pipe character in the limit + description string). Returns true if successful, false if the string parsing failed. If a_LogWarnings is true, + any error while parsing the string is output to the server console. Used when loading the limit from a file. */ virtual bool InitializeFromString(const AString & a_Params, bool a_LogWarnings) = 0; /** Called when the piece pool is assigned to a generator, so that the limits may bind to the underlying subgenerators. */ - virtual void AssignGens(int a_Seed, cBiomeGen & a_BiomeGen, cTerrainHeightGen & a_TerrainHeightGen, int a_SeaLevel) {} + virtual void AssignGens( + int a_Seed, + cBiomeGen & a_BiomeGen, + cTerrainHeightGen & a_TerrainHeightGen, + int a_SeaLevel + ) + { + } }; typedef std::shared_ptr<cVerticalLimit> cVerticalLimitPtr; @@ -151,7 +166,7 @@ public: /** Base class (interface) for piece modifiers. */ class cPieceModifier { - public: + public: // Force a virtual destructor in descendants virtual ~cPieceModifier() {} @@ -215,20 +230,11 @@ public: m_VerticalStrategy = std::move(a_VerticalStrategy); } - cVerticalStrategyPtr GetVerticalStrategy(void) const - { - return m_VerticalStrategy; - } + cVerticalStrategyPtr GetVerticalStrategy(void) const { return m_VerticalStrategy; } - cVerticalLimitPtr GetVerticalLimit(void) const - { - return m_VerticalLimit; - } + cVerticalLimitPtr GetVerticalLimit(void) const { return m_VerticalLimit; } - cPieceModifiers GetModifiers(void) const - { - return m_Modifiers; - } + cPieceModifiers GetModifiers(void) const { return m_Modifiers; } /** Sets the vertical strategy based on the description in the string. If a_LogWarnings is true, logs the parsing problems into the server console. @@ -250,10 +256,21 @@ public: Vector3i RotatePos(const Vector3i & a_Pos, int a_NumCCWRotations) const; /** Returns a copy of the connector that is rotated and then moved by the specified amounts. */ - cConnector RotateMoveConnector(const cConnector & a_Connector, int a_NumCCWRotations, int a_MoveX, int a_MoveY, int a_MoveZ) const; - - /** Returns the hitbox after the specified number of rotations and moved so that a_MyConnector is placed at a_ToConnectorPos. */ - cCuboid RotateHitBoxToConnector(const cConnector & a_MyConnector, const Vector3i & a_ToConnectorPos, int a_NumCCWRotations) const; + cConnector RotateMoveConnector( + const cConnector & a_Connector, + int a_NumCCWRotations, + int a_MoveX, + int a_MoveY, + int a_MoveZ + ) const; + + /** Returns the hitbox after the specified number of rotations and moved so that a_MyConnector is placed at + * a_ToConnectorPos. */ + cCuboid RotateHitBoxToConnector( + const cConnector & a_MyConnector, + const Vector3i & a_ToConnectorPos, + int a_NumCCWRotations + ) const; /** Returns the hitbox after the specified number of CCW rotations and moved by the specified amounts. */ cCuboid RotateMoveHitBox(int a_NumCCWRotations, int a_MoveX, int a_MoveY, int a_MoveZ) const; @@ -276,7 +293,7 @@ Provides lists of pieces based on criteria (IsStarting, HasConnector). Provides per-piece weights for random distribution of individual pieces. */ class cPiecePool { -public: + public: // Force a virtual destructor in all descendants: virtual ~cPiecePool() {} @@ -288,10 +305,11 @@ public: Multiple starting points are supported, one of the returned piece will be chosen. */ virtual cPieces GetStartingPieces(void) = 0; - /** Returns the relative weight with which the a_NewPiece is to be selected for placing under a_PlacedPiece through a_ExistingConnector. - a_ExistingConnector is the original connector, before any movement or rotation is applied to it. - This allows the pool to tweak the piece's chances, based on the previous pieces in the tree and the connector used. - The higher the number returned, the higher the chance the piece will be chosen. 0 means the piece will never be chosen. */ + /** Returns the relative weight with which the a_NewPiece is to be selected for placing under a_PlacedPiece through + a_ExistingConnector. a_ExistingConnector is the original connector, before any movement or rotation is applied to + it. This allows the pool to tweak the piece's chances, based on the previous pieces in the tree and the connector + used. The higher the number returned, the higher the chance the piece will be chosen. 0 means the piece will never + be chosen. */ virtual int GetPieceWeight( const cPlacedPiece & a_PlacedPiece, const cPiece::cConnector & a_ExistingConnector, @@ -303,12 +321,9 @@ public: /** Returns the relative weight with which the a_NewPiece is to be selected for placing as the first piece. This allows the pool to tweak the piece's chances. - The higher the number returned, the higher the chance the piece will be chosen. 0 means the piece will not be chosen. - If all pieces return 0, a random piece is chosen, with all equal chances. */ - virtual int GetStartingPieceWeight(const cPiece & a_NewPiece) - { - return 1; - } + The higher the number returned, the higher the chance the piece will be chosen. 0 means the piece will not be + chosen. If all pieces return 0, a random piece is chosen, with all equal chances. */ + virtual int GetStartingPieceWeight(const cPiece & a_NewPiece) { return 1; } /** Called after a piece is placed, to notify the pool that it has been used. The pool may adjust the pieces it will return the next time. */ @@ -326,16 +341,21 @@ public: /** Represents a single piece that has been placed to specific coords in the world. */ class cPlacedPiece { -public: - cPlacedPiece(const cPlacedPiece * a_Parent, const cPiece & a_Piece, const Vector3i & a_Coords, int a_NumCCWRotations); - - const cPlacedPiece * GetParent (void) const { return m_Parent; } - const cPiece & GetPiece (void) const { return *m_Piece; } - const Vector3i & GetCoords (void) const { return m_Coords; } - int GetNumCCWRotations (void) const { return m_NumCCWRotations; } - const cCuboid & GetHitBox (void) const { return m_HitBox; } - int GetDepth (void) const { return m_Depth; } - bool HasBeenMovedToGround(void) const { return m_HasBeenMovedToGround; } + public: + cPlacedPiece( + const cPlacedPiece * a_Parent, + const cPiece & a_Piece, + const Vector3i & a_Coords, + int a_NumCCWRotations + ); + + const cPlacedPiece * GetParent(void) const { return m_Parent; } + const cPiece & GetPiece(void) const { return *m_Piece; } + const Vector3i & GetCoords(void) const { return m_Coords; } + int GetNumCCWRotations(void) const { return m_NumCCWRotations; } + const cCuboid & GetHitBox(void) const { return m_HitBox; } + int GetDepth(void) const { return m_Depth; } + bool HasBeenMovedToGround(void) const { return m_HasBeenMovedToGround; } /** Returns the coords as a modifiable object. */ Vector3i & GetCoords(void) { return m_Coords; } @@ -353,13 +373,13 @@ public: Used eg. by village houses. */ void MoveToGroundBy(int a_OffsetY); -protected: + protected: const cPlacedPiece * m_Parent; const cPiece * m_Piece; Vector3i m_Coords; int m_NumCCWRotations; cCuboid m_HitBox; // Hitbox of the placed piece, in world coords - int m_Depth; // Depth in the generated piece tree + int m_Depth; // Depth in the generated piece tree /** Set to true once the piece has been moved Y-wise. Used eg. by village houses. */ |