2014-03-28 11:42:32 -04:00
|
|
|
|
|
|
|
// NetherFortGen.cpp
|
|
|
|
|
|
|
|
// Implements the cNetherFortGen class representing the nether fortress generator
|
|
|
|
|
|
|
|
#include "Globals.h"
|
|
|
|
#include "NetherFortGen.h"
|
|
|
|
#include "Prefabs/NetherFortPrefabs.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-07-17 16:15:34 -04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2014-03-28 11:42:32 -04:00
|
|
|
// cNetherFortGen::cNetherFort:
|
|
|
|
|
2014-05-07 16:34:06 -04:00
|
|
|
class cNetherFortGen::cNetherFort :
|
|
|
|
public cGridStructGen::cStructure
|
2014-03-28 11:42:32 -04:00
|
|
|
{
|
2014-05-07 16:34:06 -04:00
|
|
|
typedef cGridStructGen::cStructure super;
|
|
|
|
|
2014-03-28 11:42:32 -04:00
|
|
|
public:
|
|
|
|
cNetherFortGen & m_ParentGen;
|
|
|
|
int m_GridSize;
|
|
|
|
int m_Seed;
|
|
|
|
cPlacedPieces m_Pieces;
|
|
|
|
|
2014-03-28 12:09:47 -04:00
|
|
|
|
2014-06-16 10:12:50 -04:00
|
|
|
cNetherFort(cNetherFortGen & a_ParentGen, int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ, int a_GridSize, int a_MaxDepth, int a_Seed) :
|
|
|
|
super(a_GridX, a_GridZ, a_OriginX, a_OriginZ),
|
2014-03-28 11:42:32 -04:00
|
|
|
m_ParentGen(a_ParentGen),
|
|
|
|
m_GridSize(a_GridSize),
|
|
|
|
m_Seed(a_Seed)
|
|
|
|
{
|
|
|
|
// TODO: Proper Y-coord placement
|
|
|
|
int BlockY = 64;
|
|
|
|
|
|
|
|
// Generate pieces:
|
2014-03-29 19:20:06 -04:00
|
|
|
for (int i = 0; m_Pieces.size() < (size_t)(a_MaxDepth * a_MaxDepth / 8 + a_MaxDepth); i++)
|
2014-03-29 19:12:19 -04:00
|
|
|
{
|
2014-05-07 16:34:06 -04:00
|
|
|
cBFSPieceGenerator pg(cNetherFortGen::m_PiecePool, a_Seed + i);
|
|
|
|
pg.PlacePieces(a_OriginX, BlockY, a_OriginZ, a_MaxDepth, m_Pieces);
|
2014-03-29 19:12:19 -04:00
|
|
|
}
|
2014-03-28 11:42:32 -04:00
|
|
|
}
|
2014-03-28 12:09:47 -04:00
|
|
|
|
|
|
|
|
|
|
|
~cNetherFort()
|
|
|
|
{
|
|
|
|
cPieceGenerator::FreePieces(m_Pieces);
|
|
|
|
}
|
2014-03-28 11:42:32 -04:00
|
|
|
|
|
|
|
|
|
|
|
/** Carves the system into the chunk data */
|
2014-05-07 16:34:06 -04:00
|
|
|
virtual void DrawIntoChunk(cChunkDesc & a_Chunk)
|
2014-03-28 11:42:32 -04:00
|
|
|
{
|
|
|
|
for (cPlacedPieces::const_iterator itr = m_Pieces.begin(), end = m_Pieces.end(); itr != end; ++itr)
|
|
|
|
{
|
|
|
|
const cPrefab & Prefab = (const cPrefab &)((*itr)->GetPiece());
|
|
|
|
Prefab.Draw(a_Chunk, *itr);
|
|
|
|
} // for itr - m_PlacedPieces[]
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-07-17 16:15:34 -04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2014-04-18 08:35:33 -04:00
|
|
|
// Performance test of the NetherFort generator:
|
|
|
|
|
|
|
|
/*
|
|
|
|
#include "OSSupport/Timer.h"
|
|
|
|
static class cNetherFortPerfTest
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
cNetherFortPerfTest(void)
|
|
|
|
{
|
|
|
|
cTimer Timer;
|
|
|
|
long long StartTime = Timer.GetNowTime();
|
|
|
|
|
|
|
|
const int GridSize = 512;
|
|
|
|
const int MaxDepth = 12;
|
|
|
|
const int NumIterations = 100;
|
|
|
|
for (int i = 0; i < NumIterations; i++)
|
|
|
|
{
|
|
|
|
cNetherFortGen FortGen(i, GridSize, MaxDepth);
|
|
|
|
delete new cNetherFortGen::cNetherFort(FortGen, 0, 0, GridSize, MaxDepth, i);
|
|
|
|
}
|
|
|
|
|
|
|
|
long long EndTime = Timer.GetNowTime();
|
|
|
|
printf("%d forts took %lld msec (%f sec) to generate\n", NumIterations, EndTime - StartTime, ((double)(EndTime - StartTime)) / 1000);
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
} g_PerfTest;
|
|
|
|
//*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-07-17 16:15:34 -04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2014-03-28 11:42:32 -04:00
|
|
|
// cNetherFortGen:
|
|
|
|
|
2014-05-07 16:34:06 -04:00
|
|
|
cPrefabPiecePool cNetherFortGen::m_PiecePool(g_NetherFortPrefabs, g_NetherFortPrefabsCount, g_NetherFortStartingPrefabs, g_NetherFortStartingPrefabsCount);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-06-16 10:12:50 -04:00
|
|
|
cNetherFortGen::cNetherFortGen(int a_Seed, int a_GridSize, int a_MaxOffset, int a_MaxDepth) :
|
|
|
|
super(a_Seed, a_GridSize, a_GridSize, a_MaxOffset, a_MaxOffset, a_MaxDepth * 10, a_MaxDepth * 10, 200),
|
2014-03-28 11:42:32 -04:00
|
|
|
m_MaxDepth(a_MaxDepth)
|
|
|
|
{
|
2014-04-12 13:36:50 -04:00
|
|
|
/*
|
2014-03-28 11:42:32 -04:00
|
|
|
// DEBUG: Try one round of placement:
|
|
|
|
cPlacedPieces Pieces;
|
2014-05-07 16:34:06 -04:00
|
|
|
cBFSPieceGenerator pg(m_PiecePool, a_Seed);
|
2014-03-28 11:42:32 -04:00
|
|
|
pg.PlacePieces(0, 64, 0, a_MaxDepth, Pieces);
|
2014-05-07 16:34:06 -04:00
|
|
|
//*/
|
2014-03-28 11:42:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-06-16 10:12:50 -04:00
|
|
|
cGridStructGen::cStructurePtr cNetherFortGen::CreateStructure(int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ)
|
2014-03-28 11:42:32 -04:00
|
|
|
{
|
2014-06-16 10:12:50 -04:00
|
|
|
return cStructurePtr(new cNetherFort(*this, a_GridX, a_GridZ, a_OriginX, a_OriginZ, m_GridSizeX, m_MaxDepth, m_Seed));
|
2014-03-28 11:42:32 -04:00
|
|
|
}
|
|
|
|
|
2014-06-16 10:12:50 -04:00
|
|
|
|
|
|
|
|
|
|
|
|