<commit_before>#include "Chunk.h"
#include "BaseBlock.h"
#include "BlockFactory.h"
#include "LightingManager.h"

#include "MagnetiteCore.h"
#include "Renderer.h"

Chunk::Chunk( ChunkIndex index )
: mGeometry (NULL),
mPhysicsBody( NULL ),
mPhysicsMesh( NULL ),
mPhysicsShape( NULL ),
mPhysicsState( NULL )
{
	mVisibleFaces = 0;
	mWorldIndex = index;
	// Allocate block memory
	_allocateArray( CHUNK_SIZE );
	
	for(int x = 0; x < CHUNK_WIDTH; x++)
	{
		for(int z = 0; z < CHUNK_WIDTH; z++)
		{
			for(int y = 0; y < CHUNK_HEIGHT; y++)
			{
				BaseBlock* block = NULL;
				block = FactoryManager::getManager().createBlock("stone");
				setBlockAt( block, x, y, z  );
			}
		}
	}
}

Chunk::~Chunk()
{
	delete[] mBlocks;
}

long Chunk::getX()
{
	return mWorldIndex.x;
}

long Chunk::getY()
{
	return mWorldIndex.y;
}

long Chunk::getZ()
{
	return mWorldIndex.z;
}

size_t Chunk::getLightLevel( short x, short y, short z )
{
	return 100;
}

void Chunk::_allocateArray( size_t size )
{
	mBlocks = new BlockPtr[size];
	memset( mBlocks, 0, sizeof( BlockPtr ) * size );
}

BlockPtr* Chunk::getBlocks()
{
	return mBlocks;
}

void Chunk::setBlockAt( BlockPtr block, short x, short y, short z )
{
	setBlockAt( block, BLOCK_INDEX_2( x, y, z ) );
}

void Chunk::setBlockAt( BlockPtr block, short index )
{
	if( index < 0 || index > CHUNK_SIZE )
		return;
	mBlocks[ index ] = block;
	_raiseChunkFlag( DataUpdated );
}

BlockPtr Chunk::getBlockAt( short x, short y, short z )
{
	if( x < 0 || x >= CHUNK_WIDTH || y < 0 || y >= CHUNK_HEIGHT || z < 0 || z >= CHUNK_WIDTH )
		return NULL;
	return getBlockAt( BLOCK_INDEX_2( x, y, z ) );
}

BlockPtr Chunk::getBlockAt( size_t index )
{
	if( index < 0 || index > CHUNK_SIZE - 1 )
		return NULL;
	return mBlocks[ index ];
}

void Chunk::removeBlockAt( short x, short y, short z )
{
	removeBlockAt( BLOCK_INDEX_2( x, y, z ) );
}

void Chunk::removeBlockAt( short index )
{
	if( index < 0 || index > CHUNK_SIZE )
		return;
	delete mBlocks[index];
	mBlocks[index] = NULL;
	_raiseChunkFlag( DataUpdated );
}

bool Chunk::hasNeighbours( short x, short y, short z )
{
	if( getBlockAt(x - 1, y, z) ) return true;
	if( getBlockAt(x + 1, y, z) ) return true;
	if( getBlockAt(x, y - 1, z) ) return true;
	if( getBlockAt(x, y + 1, z ) ) return true;
	if( getBlockAt(x, y, z - 1) ) return true;
	if( getBlockAt(x, y, z + 1) ) return true;
	return false;
}

void Chunk::updateVisibility( )
{
	if( _hasChunkFlag( DataUpdated ) )
	{
		for( size_t x = 0; x < CHUNK_WIDTH; x++ ) {
			for( size_t y = 0; y < CHUNK_HEIGHT; y++ ) {
				for( size_t z = 0; z < CHUNK_WIDTH; z++ ) {
					if( mBlocks[BLOCK_INDEX_2( x, y, z)] == NULL ) continue;
					BaseBlock* b = mBlocks[BLOCK_INDEX_2( x, y, z)];
					short visFlags = 0;
					short visOrig = b->getVisFlags();
					//Check All axes for adjacent blocks.
					BaseBlock* cb = getBlockAt( x + 1, y, z );
					if( cb == NULL || !cb->isOpaque() ) {
						mVisibleFaces++;
						visFlags = visFlags | FACE_RIGHT;
					}
					cb = getBlockAt( x - 1, y, z );
					if( cb == NULL || !cb->isOpaque() ) {
						mVisibleFaces++;
						visFlags = visFlags | FACE_LEFT;
					}
					cb = getBlockAt( x, y + 1, z );
					if( cb == NULL || !cb->isOpaque() ) {
						mVisibleFaces++;
						visFlags = visFlags | FACE_TOP;
					}
					cb = getBlockAt( x, y - 1, z );
					if( cb == NULL || !cb->isOpaque() ) {
						mVisibleFaces++;
						visFlags = visFlags | FACE_BOTTOM;<commit_msg>It\'s just a comment<commit_after>#include "Chunk.h"
#include "BaseBlock.h"
#include "BlockFactory.h"
#include "LightingManager.h"

#include "MagnetiteCore.h"
#include "Renderer.h"

Chunk::Chunk( ChunkIndex index )
: mGeometry (NULL),
mPhysicsBody( NULL ),
mPhysicsMesh( NULL ),
mPhysicsShape( NULL ),
mPhysicsState( NULL )
{
	mVisibleFaces = 0;
	mWorldIndex = index;
	
	// Allocates the internal block array 
	_allocateArray( CHUNK_SIZE );
	
	for(int x = 0; x < CHUNK_WIDTH; x++)
	{
		for(int z = 0; z < CHUNK_WIDTH; z++)
		{
			for(int y = 0; y < CHUNK_HEIGHT; y++)
			{
				BaseBlock* block = NULL;
				block = FactoryManager::getManager().createBlock("stone");
				setBlockAt( block, x, y, z  );
			}
		}
	}
}

Chunk::~Chunk()
{
	delete[] mBlocks;
}

long Chunk::getX()
{
	return mWorldIndex.x;
}

long Chunk::getY()
{
	return mWorldIndex.y;
}

long Chunk::getZ()
{
	return mWorldIndex.z;
}

size_t Chunk::getLightLevel( short x, short y, short z )
{
	return 100;
}

void Chunk::_allocateArray( size_t size )
{
	mBlocks = new BlockPtr[size];
	memset( mBlocks, 0, sizeof( BlockPtr ) * size );
}

BlockPtr* Chunk::getBlocks()
{
	return mBlocks;
}

void Chunk::setBlockAt( BlockPtr block, short x, short y, short z )
{
	setBlockAt( block, BLOCK_INDEX_2( x, y, z ) );
}

void Chunk::setBlockAt( BlockPtr block, short index )
{
	if( index < 0 || index > CHUNK_SIZE )
		return;
	mBlocks[ index ] = block;
	_raiseChunkFlag( DataUpdated );
}

BlockPtr Chunk::getBlockAt( short x, short y, short z )
{
	if( x < 0 || x >= CHUNK_WIDTH || y < 0 || y >= CHUNK_HEIGHT || z < 0 || z >= CHUNK_WIDTH )
		return NULL;
	return getBlockAt( BLOCK_INDEX_2( x, y, z ) );
}

BlockPtr Chunk::getBlockAt( size_t index )
{
	if( index < 0 || index > CHUNK_SIZE - 1 )
		return NULL;
	return mBlocks[ index ];
}

void Chunk::removeBlockAt( short x, short y, short z )
{
	removeBlockAt( BLOCK_INDEX_2( x, y, z ) );
}

void Chunk::removeBlockAt( short index )
{
	if( index < 0 || index > CHUNK_SIZE )
		return;
	delete mBlocks[index];
	mBlocks[index] = NULL;
	_raiseChunkFlag( DataUpdated );
}

bool Chunk::hasNeighbours( short x, short y, short z )
{
	if( getBlockAt(x - 1, y, z) ) return true;
	if( getBlockAt(x + 1, y, z) ) return true;
	if( getBlockAt(x, y - 1, z) ) return true;
	if( getBlockAt(x, y + 1, z ) ) return true;
	if( getBlockAt(x, y, z - 1) ) return true;
	if( getBlockAt(x, y, z + 1) ) return true;
	return false;
}

void Chunk::updateVisibility( )
{
	MagnetiteCore* core = CoreSingleton;
	
	if( _hasChunkFlag( DataUpdated ) )
	{
		for( size_t x = 0; x < CHUNK_WIDTH; x++ ) {
			for( size_t y = 0; y < CHUNK_HEIGHT; y++ ) {
				for( size_t z = 0; z < CHUNK_WIDTH; z++ ) {
					if( mBlocks[BLOCK_INDEX_2( x, y, z)] == NULL ) continue;
					BaseBlock* b = mBlocks[BLOCK_INDEX_2( x, y, z)];
					short visFlags = 0;
					short visOrig = b->getVisFlags();
					//Check All axes for adjacent blocks.
					BaseBlock* cb = getBlockAt( x + 1, y, z );
					if( cb == NULL || !cb->isOpaque() ) {
						mVisibleFaces++;
						visFlags = visFlags | FACE_RIGHT;
					}
					cb = getBlockAt( x - 1, y, z );
					if( cb == NULL || !cb->isOpaque() ) {
						mVisibleFaces++;
						visFlags = visFlags | FACE_LEFT;
					}
					cb = getBlockAt( x, y + 1, z );
					if( cb == NULL || !cb->isOpaque() ) {
						mVisibleFaces++;
						visFlags = visFlags | FACE_TOP;
					}
					cb = getBlockAt( x, y - 1, z );
					if( cb == NULL || !cb->isOpaque() ) {
						mVisibleFaces++;
						visFlags = visFlags | FACE_BOTTOM;
{'fraction_non_alphanumeric': 0.15559415255463888, 'fraction_numerical': 0.009842234766246924, 'mean_word_length': 3.25754775107825, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2308391', 'n_tokens_mistral': 3061, 'n_tokens_neox': 2744, 'n_words': 747}