Cuberite
A lightweight, fast and extensible game server for Minecraft
|
#include <PrefabPiecePool.h>
Public Member Functions | |
void | AddPieceDefs (const cPrefab::sDef *a_PieceDefs, size_t a_NumPieceDefs) |
Adds pieces from the specified definitions into m_AllPieces. More... | |
void | AddStartingPieceDefs (const cPrefab::sDef *a_StartingPieceDefs, size_t a_NumStartingPieceDefs, int a_DefaultPieceHeight=-1) |
Adds pieces from the specified definitions into m_StartingPieces. More... | |
void | AssignGens (int a_Seed, cBiomeGen &a_BiomeGen, cTerrainHeightGen &a_HeightGen, int a_SeaLevel) |
Called when the piece pool is assigned to a generator, so that the individual starting pieces' vertical strategies may bind to the underlying subgenerators. More... | |
void | Clear (void) |
Removes and frees all pieces from this pool. More... | |
cPrefabPiecePool (const cPrefab::sDef *a_PieceDefs, size_t a_NumPieceDefs, const cPrefab::sDef *a_StartingPieceDefs, size_t a_NumStartingPieceDefs, int a_DefaultStartingPieceHeight=-1) | |
Creates a piece pool with prefabs from the specified definitions. More... | |
cPrefabPiecePool (void) | |
Creates an empty instance. More... | |
const AStringMap & | GetAllMetadata (void) const |
size_t | GetAllPiecesCount (void) const |
Returns the number of regular (non-starting) pieces. More... | |
const AString & | GetIntendedUse (void) const |
int | GetMaxDensity (void) const |
AString | GetMetadata (const AString &a_ParamName) const |
Returns the specified value from the metadata map. More... | |
int | GetMinDensity (void) const |
virtual cPieces | GetPiecesWithConnector (int a_ConnectorType) override |
Returns a list of pieces that contain the specified connector type. More... | |
virtual int | GetPieceWeight (const cPlacedPiece &a_PlacedPiece, const cPiece::cConnector &a_ExistingConnector, const cPiece &a_NewPiece) override |
Returns the relative weight with which the a_NewPiece is to be selected for placing under a_PlacedPiece through a_ExistingConnector. More... | |
virtual cPieces | GetStartingPieces (void) override |
Returns the pieces that should be used as the starting point. More... | |
size_t | GetStartingPiecesCount (void) const |
Returns the number of starting pieces. More... | |
virtual int | GetStartingPieceWeight (const cPiece &a_NewPiece) override |
Returns the relative weight with which the a_NewPiece is to be selected for placing as the first piece. More... | |
NIBBLETYPE | GetVillageRoadBlockMeta (void) const |
BLOCKTYPE | GetVillageRoadBlockType (void) const |
NIBBLETYPE | GetVillageWaterRoadBlockMeta (void) const |
BLOCKTYPE | GetVillageWaterRoadBlockType (void) const |
bool | IsBiomeAllowed (EMCSBiome a_Biome) const |
Returns true if a_Biome is among the accepted biomes in the m_AcceptedBiomes metadata member. More... | |
bool | LoadFromCubeset (const AString &a_Contents, const AString &a_FileName, bool a_LogWarnings) |
Loads the pieces from the specified string containing Cubeset file data. More... | |
bool | LoadFromFile (const AString &a_FileName, bool a_LogWarnings) |
Loads the pieces from the specified file. More... | |
bool | LoadFromString (const AString &a_Contents, const AString &a_FileName, bool a_LogWarnings) |
Loads the pieces from the specified string. More... | |
virtual void | PiecePlaced (const cPiece &a_Piece) override |
Called after a piece is placed, to notify the pool that it has been used. More... | |
virtual void | Reset (void) override |
Called when the pool has finished the current structure and should reset any piece-counters it has for a new structure. More... | |
virtual | ~cPrefabPiecePool () override |
Destroys the pool, freeing all pieces. More... | |
Public Member Functions inherited from cPiecePool | |
virtual | ~cPiecePool () |
Protected Types | |
typedef std::map< int, cPieces > | cPiecesMap |
The type used to map a connector type to the list of pieces with that connector. More... | |
Protected Member Functions | |
void | AddToPerConnectorMap (cPrefab *a_Prefab) |
Adds the prefab to the m_PiecesByConnector map for all its connectors. More... | |
void | ApplyBaseMetadataCubesetVer1 (const AString &a_FileName, bool a_LogWarnings) |
Applies the base known metadata from the m_Metadata map into this pool. More... | |
bool | LoadCubesetPieceVer1 (const AString &a_FileName, cLuaState &a_LuaState, int a_PieceIndex, bool a_LogWarnings) |
Loads a single piece from the cubeset file parsed into the specified Lua state. More... | |
bool | LoadFromCubesetVer1 (const AString &a_FileName, cLuaState &a_LuaState, bool a_LogWarnings) |
Loads the pieces from the cubeset file parsed into the specified Lua state. More... | |
std::unique_ptr< cPrefab > | LoadPrefabFromCubesetVer1 (const AString &a_FileName, cLuaState &a_LuaState, const AString &a_PieceName, bool a_LogWarnings) |
Loads a single piece's prefab from the cubeset file parsed into the specified Lua state. More... | |
bool | ReadConnectorsCubesetVer1 (const AString &a_FileName, cLuaState &a_LuaState, const AString &a_PieceName, cPrefab *a_Prefab, bool a_LogWarnings) |
Reads a single piece's connectors from the cubeset file parsed into the specified Lua state. More... | |
bool | ReadPieceMetadataCubesetVer1 (const AString &a_FileName, cLuaState &a_LuaState, const AString &a_PieceName, cPrefab *a_Prefab, bool a_LogWarnings) |
Reads a single piece's metadata from the cubeset file parsed into the specified Lua state. More... | |
bool | ReadPoolMetadataCubesetVer1 (const AString &a_FileName, cLuaState &a_LuaState, bool a_LogWarnings) |
Reads the metadata for the entire pool from the cubeset file, stores it in the m_Metadata map. More... | |
Protected Attributes | |
std::unordered_set< EMCSBiome, BiomeHasher > | m_AllowedBiomes |
A set of allowed biomes for the pool. More... | |
cPieces | m_AllPieces |
All the pieces that are allowed for building. More... | |
AString | m_IntendedUse |
The intended use of this piece pool, as specified by the pool's metadata. More... | |
int | m_MaxDensity |
The maximum density, as read from the metadata. More... | |
AStringMap | m_Metadata |
A dictionary of pool-wide metadata, as read from the cubeset file. More... | |
int | m_MinDensity |
The minimum density, as read from the metadata. More... | |
cPiecesMap | m_PiecesByConnector |
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. More... | |
cPieces | m_StartingPieces |
The pieces that are used as starting pieces. More... | |
NIBBLETYPE | m_VillageRoadBlockMeta |
The block meta to use for the village roads. More... | |
BLOCKTYPE | m_VillageRoadBlockType |
The block type to use for the village roads. More... | |
NIBBLETYPE | m_VillageWaterRoadBlockMeta |
The block meta used for the village roads if the road is on water. More... | |
BLOCKTYPE | m_VillageWaterRoadBlockType |
The block type used for the village roads if the road is on water. More... | |
Definition at line 26 of file PrefabPiecePool.h.
|
protected |
The type used to map a connector type to the list of pieces with that connector.
Definition at line 124 of file PrefabPiecePool.h.
cPrefabPiecePool::cPrefabPiecePool | ( | void | ) |
Creates an empty instance.
Prefabs can be added by calling AddPieceDefs() and AddStartingPieceDefs().
Definition at line 40 of file PrefabPiecePool.cpp.
cPrefabPiecePool::cPrefabPiecePool | ( | const cPrefab::sDef * | a_PieceDefs, |
size_t | a_NumPieceDefs, | ||
const cPrefab::sDef * | a_StartingPieceDefs, | ||
size_t | a_NumStartingPieceDefs, | ||
int | a_DefaultStartingPieceHeight = -1 |
||
) |
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(). If a_DefaultStartingPieceHeight is non-negative, it is applied to each starting piece as its fixed height (for the GetStartingPieceHeight() call).
Definition at line 48 of file PrefabPiecePool.cpp.
|
overridevirtual |
Destroys the pool, freeing all pieces.
Definition at line 65 of file PrefabPiecePool.cpp.
void cPrefabPiecePool::AddPieceDefs | ( | const cPrefab::sDef * | a_PieceDefs, |
size_t | a_NumPieceDefs | ||
) |
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.
Definition at line 93 of file PrefabPiecePool.cpp.
void cPrefabPiecePool::AddStartingPieceDefs | ( | const cPrefab::sDef * | a_StartingPieceDefs, |
size_t | a_NumStartingPieceDefs, | ||
int | a_DefaultPieceHeight = -1 |
||
) |
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. If a_DefaultPieceHeight is non-negative, it is applied to each piece as its fixed height (for the GetStartingPieceHeight() call).
Definition at line 108 of file PrefabPiecePool.cpp.
|
protected |
Adds the prefab to the m_PiecesByConnector map for all its connectors.
Definition at line 221 of file PrefabPiecePool.cpp.
|
protected |
Applies the base known metadata from the m_Metadata map into this pool.
If a_LogWarnings is true, logs a warning to console when loading fails.
Definition at line 615 of file PrefabPiecePool.cpp.
void cPrefabPiecePool::AssignGens | ( | int | a_Seed, |
cBiomeGen & | a_BiomeGen, | ||
cTerrainHeightGen & | a_HeightGen, | ||
int | a_SeaLevel | ||
) |
Called when the piece pool is assigned to a generator, so that the individual starting pieces' vertical strategies may bind to the underlying subgenerators.
Definition at line 717 of file PrefabPiecePool.cpp.
void cPrefabPiecePool::Clear | ( | void | ) |
Removes and frees all pieces from this pool.
Definition at line 74 of file PrefabPiecePool.cpp.
|
inline |
Definition at line 107 of file PrefabPiecePool.h.
|
inline |
Returns the number of regular (non-starting) pieces.
Definition at line 86 of file PrefabPiecePool.h.
|
inline |
Definition at line 92 of file PrefabPiecePool.h.
|
inline |
Definition at line 94 of file PrefabPiecePool.h.
Returns the specified value from the metadata map.
Returns an empty string if no such value had been read.
Definition at line 703 of file PrefabPiecePool.cpp.
|
inline |
Definition at line 93 of file PrefabPiecePool.h.
|
overridevirtual |
Returns a list of pieces that contain the specified connector type.
The cPiece pointers returned are managed by the pool and the caller doesn't free them.
Implements cPiecePool.
Definition at line 752 of file PrefabPiecePool.cpp.
|
overridevirtual |
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.
Reimplemented from cPiecePool.
Reimplemented in cVillagePiecePool.
Definition at line 777 of file PrefabPiecePool.cpp.
|
overridevirtual |
Returns the pieces that should be used as the starting point.
Multiple starting points are supported, one of the returned piece will be chosen.
Implements cPiecePool.
Definition at line 761 of file PrefabPiecePool.cpp.
|
inline |
Returns the number of starting pieces.
Definition at line 89 of file PrefabPiecePool.h.
|
overridevirtual |
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.
Reimplemented from cPiecePool.
Definition at line 786 of file PrefabPiecePool.cpp.
|
inline |
Definition at line 96 of file PrefabPiecePool.h.
|
inline |
Definition at line 95 of file PrefabPiecePool.h.
|
inline |
Definition at line 98 of file PrefabPiecePool.h.
|
inline |
Definition at line 97 of file PrefabPiecePool.h.
|
inline |
Returns true if a_Biome is among the accepted biomes in the m_AcceptedBiomes metadata member.
Definition at line 101 of file PrefabPiecePool.h.
|
protected |
Loads a single piece from the cubeset file parsed into the specified Lua state.
The piece's definition table is expected to be at the top of the Lua stack. Returns true on success, false on error. a_PieceIndex is the index of the piece, in the Pieces table. It is used for logging only. If a_LogWarnings is true, logs a warning to console when loading fails.
Definition at line 275 of file PrefabPiecePool.cpp.
bool cPrefabPiecePool::LoadFromCubeset | ( | const AString & | a_Contents, |
const AString & | a_FileName, | ||
bool | a_LogWarnings | ||
) |
Loads the pieces from the specified string containing Cubeset file data.
Returns true if successful, false on error. a_FileName is used only logging. If a_LogWarnings is true, logs a warning to console when loading fails.
Definition at line 186 of file PrefabPiecePool.cpp.
|
protected |
Loads the pieces from the cubeset file parsed into the specified Lua state.
Returns true on success, false on error. a_FileName is used only logging. If a_LogWarnings is true, logs a warning to console when loading fails.
Definition at line 234 of file PrefabPiecePool.cpp.
bool cPrefabPiecePool::LoadFromFile | ( | const AString & | a_FileName, |
bool | a_LogWarnings | ||
) |
Loads the pieces from the specified file.
Returns true if successful, false on error. If a_LogWarnings is true, logs a warning to console when loading fails.
Definition at line 131 of file PrefabPiecePool.cpp.
bool cPrefabPiecePool::LoadFromString | ( | const AString & | a_Contents, |
const AString & | a_FileName, | ||
bool | a_LogWarnings | ||
) |
Loads the pieces from the specified string.
Returns true if successful, false on error. a_FileName is used only logging. If a_LogWarnings is true, logs a warning to console when loading fails.
Definition at line 147 of file PrefabPiecePool.cpp.
|
protected |
Loads a single piece's prefab from the cubeset file parsed into the specified Lua state.
The piece's definition table is expected to be at the top of the Lua stack. Returns the prefab on success, nullptr on failure. a_PieceName is the identification of the piece, used for logging only. If a_LogWarnings is true, logs a warning to console when loading fails.
Definition at line 359 of file PrefabPiecePool.cpp.
|
overridevirtual |
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.
Implements cPiecePool.
Definition at line 795 of file PrefabPiecePool.cpp.
|
protected |
Reads a single piece's connectors from the cubeset file parsed into the specified Lua state.
The piece's definition table is expected to be at the top of the Lua stack. Returns true on success, false on failure. The connectors are added into the a_Prefab object. No Connectors table is considered a failure, empty Connectors table is considered a success. If any of the connectors are malformed, it is considered a failure, although the rest of the connectors will still load. a_PieceName is the identification of the piece, used for logging only. If a_LogWarnings is true, logs a warning to console when loading fails.
Definition at line 448 of file PrefabPiecePool.cpp.
|
protected |
Reads a single piece's metadata from the cubeset file parsed into the specified Lua state.
The piece's definition table is expected to be at the top of the Lua stack. Returns true on success, false on failure. The metadata is applied into the a_Prefab object. a_PieceName is the identification of the piece, used for logging only. If a_LogWarnings is true, logs a warning to console when loading fails.
Definition at line 511 of file PrefabPiecePool.cpp.
|
protected |
Reads the metadata for the entire pool from the cubeset file, stores it in the m_Metadata map.
Returns true on success, false on failure. If a_LogWarnings is true, logs a warning to console when loading fails.
Definition at line 673 of file PrefabPiecePool.cpp.
|
overridevirtual |
Called when the pool has finished the current structure and should reset any piece-counters it has for a new structure.
Implements cPiecePool.
Definition at line 805 of file PrefabPiecePool.cpp.
|
protected |
A set of allowed biomes for the pool.
The pool will only be used within the specified biomes.
Definition at line 161 of file PrefabPiecePool.h.
|
protected |
All the pieces that are allowed for building.
This is the list that's used for memory allocation and deallocation for the pieces.
Definition at line 129 of file PrefabPiecePool.h.
|
protected |
The intended use of this piece pool, as specified by the pool's metadata.
Definition at line 140 of file PrefabPiecePool.h.
|
protected |
The maximum density, as read from the metadata.
Definition at line 146 of file PrefabPiecePool.h.
|
protected |
A dictionary of pool-wide metadata, as read from the cubeset file.
Definition at line 164 of file PrefabPiecePool.h.
|
protected |
The minimum density, as read from the metadata.
Definition at line 143 of file PrefabPiecePool.h.
|
protected |
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.
Definition at line 137 of file PrefabPiecePool.h.
|
protected |
The pieces that are used as starting pieces.
This list is not shared and the pieces need deallocation.
Definition at line 133 of file PrefabPiecePool.h.
|
protected |
The block meta to use for the village roads.
Definition at line 152 of file PrefabPiecePool.h.
|
protected |
The block type to use for the village roads.
Definition at line 149 of file PrefabPiecePool.h.
|
protected |
The block meta used for the village roads if the road is on water.
Definition at line 158 of file PrefabPiecePool.h.
|
protected |
The block type used for the village roads if the road is on water.
Definition at line 155 of file PrefabPiecePool.h.