#include "GeneratedStructure.h" #include "GenerationTemplate.h" GeneratedStructure::GeneratedStructure( GenerationTemplate* t, Framework::Vec3 originPos, Framework::Vec3 size, Framework::Vec3 minAffectedPos ) : ReferenceCounter(), size( size ), minAffectedPos( minAffectedPos ), originPos( originPos ), t( t ) { blockIds = new int[ size.x * size.y * size.z ]; blocks = new Block * [ size.x * size.y * size.z ]; memset( blockIds, 0, sizeof( int ) * size.x * size.y * size.z ); memset( blocks, 0, sizeof( Block* ) * size.x * size.y * size.z ); } GeneratedStructure::~GeneratedStructure() { for( int i = 0; i < size.x * size.y * size.z; i++ ) { if( blocks[ i ] ) blocks[ i ]->release(); } delete[] blockIds; delete[] blocks; t->release(); } void GeneratedStructure::setBlockAt( Framework::Either block, Framework::Vec3 localPos ) { assert( localPos.x >= 0 && localPos.y >= 0 && localPos.z >= 0 && localPos.x < size.x&& localPos.y < size.y&& localPos.z < size.z ); int index = ((localPos.x * size.y) + localPos.y) * size.z + localPos.z; if( block.isA() ) blocks[ index ] = block; else blockIds[ index ] = block; } bool GeneratedStructure::isBlockAffected( Framework::Vec3 location ) const { Framework::Vec3 localPos = location - minAffectedPos; if( localPos.x >= 0 && localPos.y >= 0 && localPos.z >= 0 && localPos.x < size.x && localPos.y < size.y && localPos.z < size.z ) { int index = ((localPos.x * size.y) + localPos.y) * size.z + localPos.z; return blocks[ index ] || blockIds[ index ]; } return 0; } Framework::Either GeneratedStructure::generateBlockAt( Framework::Vec3 location ) const { Framework::Vec3 localPos = location - minAffectedPos; if( localPos.x >= 0 && localPos.y >= 0 && localPos.z >= 0 && localPos.x < size.x && localPos.y < size.y && localPos.z < size.z ) { int index = ((localPos.x * size.y) + localPos.y) * size.z + localPos.z; if( blocks[ index ] ) return blocks[ index ]; return blockIds[ index ]; } return 0; } Framework::Vec3 GeneratedStructure::getOriginPos() const { return originPos; } GenerationTemplate* GeneratedStructure::zTemplate() const { return t; }