123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- #include "GeneratedStructure.h"
- #include "GenerationTemplate.h"
- GeneratedStructure::GeneratedStructure( GenerationTemplate* t, Framework::Vec3<int> originPos, Framework::Vec3<int> size, Framework::Vec3<int> 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*, int> block, Framework::Vec3<int> 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<int> location ) const
- {
- Framework::Vec3<int> 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<Block*, int> GeneratedStructure::generateBlockAt( Framework::Vec3<int> location ) const
- {
- Framework::Vec3<int> 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<int> GeneratedStructure::getOriginPos() const
- {
- return originPos;
- }
- GenerationTemplate* GeneratedStructure::zTemplate() const
- {
- return t;
- }
|