From b8fbba5eb92cda32b13d65f3704adf778da82f38 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Wed, 11 Nov 2015 10:32:42 +0100 Subject: Added PieceStructures generator. --- src/Generating/PrefabPiecePool.h | 62 ++++++++++++++++++++++++++++++++-------- 1 file changed, 50 insertions(+), 12 deletions(-) (limited to 'src/Generating/PrefabPiecePool.h') diff --git a/src/Generating/PrefabPiecePool.h b/src/Generating/PrefabPiecePool.h index f7bf41994..1c51c4963 100644 --- a/src/Generating/PrefabPiecePool.h +++ b/src/Generating/PrefabPiecePool.h @@ -36,10 +36,13 @@ public: 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(). */ + 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). */ cPrefabPiecePool( const cPrefab::sDef * a_PieceDefs, size_t a_NumPieceDefs, - const cPrefab::sDef * a_StartingPieceDefs, size_t a_NumStartingPieceDefs + const cPrefab::sDef * a_StartingPieceDefs, size_t a_NumStartingPieceDefs, + int a_DefaultStartingPieceHeight = -1 ); /** Creates a pool and loads the contents of the specified file into it. @@ -59,16 +62,30 @@ public: /** 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); + 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). */ + void AddStartingPieceDefs( + const cPrefab::sDef * a_StartingPieceDefs, + size_t a_NumStartingPieceDefs, + int a_DefaultPieceHeight = -1 + ); /** 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. */ bool LoadFromFile(const AString & a_FileName, bool a_LogWarnings); - /** Loads the pieces from the specified Cubeset file. Returns true if successful, false on error. + /** 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. */ + bool LoadFromString(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. */ - bool LoadFromCubesetFile(const AString & a_FileName, bool a_LogWarnings); + bool LoadFromCubeset(const AString & a_Contents, const AString & a_FileName, bool a_LogWarnings); /** Returns the number of regular (non-starting) pieces. */ size_t GetAllPiecesCount(void) const { return m_AllPieces.size(); } @@ -88,6 +105,16 @@ public: /** Returns true if a_Biome is among the accepted biomes in the m_AcceptedBiomes metadata member. */ bool IsBiomeAllowed(EMCSBiome a_Biome) const { return (m_AllowedBiomes.find(a_Biome) != m_AllowedBiomes.end()); } + /** Returns the specified value from the metadata map. + Returns an empty string if no such value had been read. */ + AString GetMetadata(const AString & a_ParamName) const; + + const AStringMap & GetAllMetadata(void) const { return m_Metadata; } + + /** Called when the piece pool is assigned to a generator, + so that the individual starting pieces' vertical strategies may bind to the underlying subgenerators. */ + void AssignGens(int a_Seed, cBiomeGenPtr & a_BiomeGen, cTerrainHeightGenPtr & a_HeightGen, int a_SeaLevel); + // cPiecePool overrides: virtual cPieces GetPiecesWithConnector(int a_ConnectorType) override; virtual cPieces GetStartingPieces(void) override; @@ -100,7 +127,8 @@ protected: /** The type used to map a connector type to the list of pieces with that connector */ typedef std::map 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; @@ -137,14 +165,18 @@ protected: /** A set of allowed biomes for the pool. The pool will only be used within the specified biomes. */ std::unordered_set m_AllowedBiomes; + /** A dictionary of pool-wide metadata, as read from the cubeset file. */ + AStringMap m_Metadata; + /** Adds the prefab to the m_PiecesByConnector map for all its connectors. */ void AddToPerConnectorMap(cPrefab * a_Prefab); /** 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. */ - bool LoadFromCubesetFileVer1(const AString & a_FileName, cLuaState & a_LuaState, bool a_LogWarnings); + bool LoadFromCubesetVer1(const AString & a_FileName, cLuaState & a_LuaState, bool a_LogWarnings); /** 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. @@ -187,7 +219,7 @@ protected: 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. */ - bool ApplyPieceMetadataCubesetVer1( + bool ReadPieceMetadataCubesetVer1( const AString & a_FileName, cLuaState & a_LuaState, const AString & a_PieceName, @@ -195,15 +227,21 @@ protected: bool a_LogWarnings ); - /** Reads the metadata for the entire pool from the cubeset file parsed into the specified Lua state. + /** 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. - The metadata is applied into "this". If a_LogWarnings is true, logs a warning to console when loading fails. */ - bool ApplyPoolMetadataCubesetVer1( + bool ReadPoolMetadataCubesetVer1( const AString & a_FileName, cLuaState & a_LuaState, bool a_LogWarnings ); + + /** 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. */ + void ApplyBaseMetadataCubesetVer1( + const AString & a_FileName, + bool a_LogWarnings + ); } ; -- cgit v1.2.3