From 0a95d04ab38b81f87d4fa421601d25f37df1f6a1 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sat, 21 Jun 2014 20:19:44 +0200 Subject: Added a TestRails generator. This is for debugging purposes only. --- src/Generating/TestRailsGen.cpp | 116 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 src/Generating/TestRailsGen.cpp (limited to 'src/Generating/TestRailsGen.cpp') diff --git a/src/Generating/TestRailsGen.cpp b/src/Generating/TestRailsGen.cpp new file mode 100644 index 000000000..c40c1a9b6 --- /dev/null +++ b/src/Generating/TestRailsGen.cpp @@ -0,0 +1,116 @@ + +// TestRailsGen.cpp + +// Implements the cTestRailsGen class representing the testing rails generator + +#include "Globals.h" +#include "TestRailsGen.h" +#include "Prefabs/TestRailsPrefabs.h" +#include "PieceGenerator.h" + + + + + +static cPrefabPiecePool g_TestRails(g_TestRailsPrefabs, g_TestRailsPrefabsCount, g_TestRailsStartingPrefabs, g_TestRailsStartingPrefabsCount); + + + + + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// cTestRailsGen::cTestRails: + +class cTestRailsGen::cTestRails : + public cGridStructGen::cStructure +{ + typedef cGridStructGen::cStructure super; + +public: + cTestRails( + int a_Seed, + int a_GridX, int a_GridZ, + int a_OriginX, int a_OriginZ, + int a_MaxDepth, + int a_MaxSize + ) : + super(a_GridX, a_GridZ, a_OriginX, a_OriginZ), + m_Seed(a_Seed), + m_Noise(a_Seed), + m_MaxSize(a_MaxSize), + m_Borders(a_OriginX - a_MaxSize, 0, a_OriginZ - a_MaxSize, a_OriginX + a_MaxSize, 255, a_OriginZ + a_MaxSize) + { + // Generate the pieces for this test: + cBFSPieceGenerator pg(g_TestRails, a_Seed); + pg.PlacePieces(a_OriginX, 150, a_OriginZ, a_MaxDepth, m_Pieces); + if (m_Pieces.empty()) + { + return; + } + } + + ~cTestRails() + { + cPieceGenerator::FreePieces(m_Pieces); + } + +protected: + /** Seed for the random functions */ + int m_Seed; + + /** The noise used as a pseudo-random generator */ + cNoise m_Noise; + + /** Maximum size, in X/Z blocks, of the structure (radius from the origin) */ + int m_MaxSize; + + /** Borders of the structure - no item may reach out of this cuboid. */ + cCuboid m_Borders; + + /** The rails pieces, placed by the generator. */ + cPlacedPieces m_Pieces; + + + // cGridStructGen::cStructure overrides: + virtual void DrawIntoChunk(cChunkDesc & a_Chunk) override + { + for (cPlacedPieces::iterator itr = m_Pieces.begin(), end = m_Pieces.end(); itr != end; ++itr) + { + cPrefab & Prefab = (cPrefab &)((*itr)->GetPiece()); + Prefab.Draw(a_Chunk, *itr); + } // for itr - m_PlacedPieces[] + } +} ; + + + + + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// cTestRailsGen: + + + + + +cTestRailsGen::cTestRailsGen(int a_Seed, int a_GridSize, int a_MaxOffset, int a_MaxDepth, int a_MaxSize) : + super(a_Seed, a_GridSize, a_GridSize, a_MaxOffset, a_MaxOffset, a_MaxSize, a_MaxSize, 100), + m_Noise(a_Seed + 1000), + m_MaxDepth(a_MaxDepth), + m_MaxSize(a_MaxSize) +{ +} + + + + + +cGridStructGen::cStructurePtr cTestRailsGen::CreateStructure(int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ) +{ + // Create a base based on the chosen prefabs: + return cStructurePtr(new cTestRails(m_Seed, a_GridX, a_GridZ, a_OriginX, a_OriginZ, m_MaxDepth, m_MaxSize)); +} + + + + -- cgit v1.2.3 From 2423fbf2efa39e28cc348acc11b9269e573dcdef Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 17 Jul 2014 22:15:34 +0200 Subject: Normalized comments. This was mostly done automatically and then visually inspected for obvious errors. All //-style comments should have a 2-space separation from the code, and 1 space after the comment sign. --- src/Generating/TestRailsGen.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/Generating/TestRailsGen.cpp') diff --git a/src/Generating/TestRailsGen.cpp b/src/Generating/TestRailsGen.cpp index c40c1a9b6..66ab8b33f 100644 --- a/src/Generating/TestRailsGen.cpp +++ b/src/Generating/TestRailsGen.cpp @@ -18,7 +18,7 @@ static cPrefabPiecePool g_TestRails(g_TestRailsPrefabs, g_TestRailsPrefabsCount, -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// // cTestRailsGen::cTestRails: class cTestRailsGen::cTestRails : @@ -86,7 +86,7 @@ protected: -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// // cTestRailsGen: -- cgit v1.2.3