コード例 #1
0
ファイル: main.cpp プロジェクト: Tenderfoot/CopyCraft
int get_number_of_faces(int i, int j, int k)
{
	int number_to_return = 0;
	
	if(check_block_exists(i,j,k+1) == false)
	{
		number_to_return++;
	}

	if(check_block_exists(i,j,k-1) == false)
	{
		number_to_return++;
	}

	if(check_block_exists(i,j-1,k) == false)
	{
		number_to_return++;
	}

	if(check_block_exists(i,j+1,k) == false)
	{
		number_to_return++;
	}

	if(check_block_exists(i-1,j,k) == false)
	{
		number_to_return++;
	}

	if(check_block_exists(i+1,j,k) == false)
	{
		number_to_return++;
	}

	return number_to_return;
}
コード例 #2
0
ファイル: main.cpp プロジェクト: Tenderfoot/CopyCraft
// This isn't used
// drawing in immediate mode
void draw_cube(int i, int j, int k)
{
	glBindTexture(GL_TEXTURE_2D, NULL);

	// draw different faces of the cube
	// only if there isn't another cube
	// adjacent on that side

	glBegin(GL_QUADS);
		
		if(world[i][j][k].type == DIRT)
		{
			glColor3f(1.0f,0.5f,0.1f);
		}
		else if(world[i][j][k].type == TOPSOIL)
		{
			glColor3f(0.0f,0.8f,0.0f);
		}		

		if(check_block_exists(i,j,k+1) == false)
		{
			//front
			glVertex3f(0.5f,0.5f,0.5f);
			glVertex3f(-0.5f,0.5f,0.5f);
			glVertex3f(-0.5f,-0.5f,0.5f);
			glVertex3f(0.5f,-0.5f,0.5f);
		}

		if(check_block_exists(i,j,k-1) == false)
		{
			//back
			glVertex3f(0.5f,0.5f,-0.5f);
			glVertex3f(-0.5f,0.5f,-0.5f);
			glVertex3f(-0.5f,-0.5f,-0.5f);
			glVertex3f(0.5f,-0.5f,-0.5f);
		}

		if(check_block_exists(i,j-1,k) == false)
		{
			//top
			glVertex3f(0.5f,-0.5f,0.5f);
			glVertex3f(-0.5f,-0.5f,0.5f);
			glVertex3f(-0.5f,-0.5f,-0.5f);
			glVertex3f(0.5f,-0.5f,-0.5f);
		}

		if(check_block_exists(i,j+1,k) == false)
		{
			//bottom
			glVertex3f(0.5f,0.5f,0.5f);
			glVertex3f(-0.5f,0.5f,0.5f);
			glVertex3f(-0.5f,0.5f,-0.5f);
			glVertex3f(0.5f,0.5f,-0.5f);
		}

		if(check_block_exists(i-1,j,k) == false)
		{
			//left
			glVertex3f(-0.5f,0.5f,0.5f);
			glVertex3f(-0.5f,-0.5f,0.5f);
			glVertex3f(-0.5f,-0.5f,-0.5f);
			glVertex3f(-0.5f,0.5f,-0.5f);
		}

		if(check_block_exists(i+1,j,k) == false)
		{
			//right
			glVertex3f(0.5f,0.5f,0.5f);
			glVertex3f(0.5f,-0.5f,0.5f);
			glVertex3f(0.5f,-0.5f,-0.5f);
			glVertex3f(0.5f,0.5f,-0.5f);
		}
	glEnd();

	glColor3f(1.0f,1.0f,1.0f);
}
コード例 #3
0
ファイル: main.cpp プロジェクト: Tenderfoot/CopyCraft
int populate_verticies(float *vertex_buffer, float *color_buffer, float *texcoord_buffer)
{
	int i,j,k;
	int total=0;
	int current_face = 0;

	float *current_color;
	float brown[3];
	brown[0] = 1;
	brown[1] = 1;
	brown[2] = 1;
	current_color = brown;

	float green[3];
	green[0] = 1;
	green[1] = 1;
	green[2] = 1;

	float *current_texcoords;
	float dirt_texcoords[8];
	dirt_texcoords[0] = 0.0f;
	dirt_texcoords[1] = 0.0f;
	dirt_texcoords[2] = 0.5f;
	dirt_texcoords[3] = 0.0f;
	dirt_texcoords[4] = 0.5f;
	dirt_texcoords[5] = 1.0f;
	dirt_texcoords[6] = 0.0f;
	dirt_texcoords[7] = 1.0f;
	float grass_texcoords[8];
	grass_texcoords[0] = 0.5f;
	grass_texcoords[1] = 0.0f;
	grass_texcoords[2] = 1.0f;
	grass_texcoords[3] = 0.0f;
	grass_texcoords[4] = 1.0f;
	grass_texcoords[5] = 1.0f;
	grass_texcoords[6] = 0.5f;
	grass_texcoords[7] = 1.0f;


	for(i=0; i<WORLD_SIZE; i++)
	{
		for(j=0; j<WORLD_SIZE; j++)
		{
			for(k=0; k<WORLD_SIZE; k++)
			{
				if(world[i][j][k].type > 0)
				{
					if(world[i][j][k].type == 1)
						current_texcoords = dirt_texcoords;
					else
						current_texcoords = grass_texcoords;

					if(check_block_exists(i,j,k+1) == false)
					{
						texcoord_buffer[current_face*8] = current_texcoords[0];
						texcoord_buffer[current_face*8+1] = current_texcoords[1];
						texcoord_buffer[current_face*8+2] = current_texcoords[2];
						texcoord_buffer[current_face*8+3] = current_texcoords[3];
						texcoord_buffer[current_face*8+4] = current_texcoords[4];
						texcoord_buffer[current_face*8+5] = current_texcoords[5];
						texcoord_buffer[current_face*8+6] = current_texcoords[6];
						texcoord_buffer[current_face*8+7] = current_texcoords[7];

						color_buffer[current_face*12] = current_color[0];
						color_buffer[current_face*12+1] = current_color[1];
						color_buffer[current_face*12+2] = current_color[2];
						color_buffer[current_face*12+3] = current_color[0];
						color_buffer[current_face*12+4] = current_color[1];
						color_buffer[current_face*12+5] = current_color[2];
						color_buffer[current_face*12+6] = current_color[0];
						color_buffer[current_face*12+7] = current_color[1];
						color_buffer[current_face*12+8] = current_color[2];
						color_buffer[current_face*12+9] = current_color[0];
						color_buffer[current_face*12+10] = current_color[1];
						color_buffer[current_face*12+11] = current_color[2];

						vertex_buffer[current_face*12] = 0.5+i;
						vertex_buffer[current_face*12+1] = 0.5+j;
						vertex_buffer[current_face*12+2] = 0.5+k;
						vertex_buffer[current_face*12+3] = -0.5+i;
						vertex_buffer[current_face*12+4] = 0.5+j;
						vertex_buffer[current_face*12+5] = 0.5+k;
						vertex_buffer[current_face*12+6] = -0.5+i;
						vertex_buffer[current_face*12+7] = -0.5+j;
						vertex_buffer[current_face*12+8] = 0.5+k;
						vertex_buffer[current_face*12+9] = 0.5+i;
						vertex_buffer[current_face*12+10] = -0.5+j;
						vertex_buffer[current_face*12+11] = 0.5+k;
						current_face++;
					}

					if(check_block_exists(i,j,k-1) == false)
					{
						texcoord_buffer[current_face*8] = current_texcoords[0];
						texcoord_buffer[current_face*8+1] = current_texcoords[1];
						texcoord_buffer[current_face*8+2] = current_texcoords[2];
						texcoord_buffer[current_face*8+3] = current_texcoords[3];
						texcoord_buffer[current_face*8+4] = current_texcoords[4];
						texcoord_buffer[current_face*8+5] = current_texcoords[5];
						texcoord_buffer[current_face*8+6] = current_texcoords[6];
						texcoord_buffer[current_face*8+7] = current_texcoords[7];

						color_buffer[current_face*12] = current_color[0];
						color_buffer[current_face*12+1] = current_color[1];
						color_buffer[current_face*12+2] = current_color[2];
						color_buffer[current_face*12+3] = current_color[0];
						color_buffer[current_face*12+4] = current_color[1];
						color_buffer[current_face*12+5] = current_color[2];
						color_buffer[current_face*12+6] = current_color[0];
						color_buffer[current_face*12+7] = current_color[1];
						color_buffer[current_face*12+8] = current_color[2];
						color_buffer[current_face*12+9] = current_color[0];
						color_buffer[current_face*12+10] = current_color[1];
						color_buffer[current_face*12+11] = current_color[2];

						vertex_buffer[current_face*12] = 0.5+i;
						vertex_buffer[current_face*12+1] = 0.5+j;
						vertex_buffer[current_face*12+2] = -0.5+k;
						vertex_buffer[current_face*12+3] = -0.5+i;
						vertex_buffer[current_face*12+4] = 0.5+j;
						vertex_buffer[current_face*12+5] = -0.5+k;
						vertex_buffer[current_face*12+6] = -0.5+i;
						vertex_buffer[current_face*12+7] = -0.5+j;
						vertex_buffer[current_face*12+8] = -0.5+k;
						vertex_buffer[current_face*12+9] = 0.5+i;
						vertex_buffer[current_face*12+10] = -0.5+j;
						vertex_buffer[current_face*12+11] = -0.5+k;
						current_face++;
					}

					if(check_block_exists(i,j-1,k) == false)
					{

						texcoord_buffer[current_face*8] = current_texcoords[0];
						texcoord_buffer[current_face*8+1] = current_texcoords[1];
						texcoord_buffer[current_face*8+2] = current_texcoords[2];
						texcoord_buffer[current_face*8+3] = current_texcoords[3];
						texcoord_buffer[current_face*8+4] = current_texcoords[4];
						texcoord_buffer[current_face*8+5] = current_texcoords[5];
						texcoord_buffer[current_face*8+6] = current_texcoords[6];
						texcoord_buffer[current_face*8+7] = current_texcoords[7];

						color_buffer[current_face*12] = current_color[0];
						color_buffer[current_face*12+1] = current_color[1];
						color_buffer[current_face*12+2] = current_color[2];
						color_buffer[current_face*12+3] = current_color[0];
						color_buffer[current_face*12+4] = current_color[1];
						color_buffer[current_face*12+5] = current_color[2];
						color_buffer[current_face*12+6] = current_color[0];
						color_buffer[current_face*12+7] = current_color[1];
						color_buffer[current_face*12+8] = current_color[2];
						color_buffer[current_face*12+9] = current_color[0];
						color_buffer[current_face*12+10] = current_color[1];
						color_buffer[current_face*12+11] = current_color[2];

						vertex_buffer[current_face*12] = 0.5+i;
						vertex_buffer[current_face*12+1] = -0.5+j;
						vertex_buffer[current_face*12+2] = 0.5+k;
						vertex_buffer[current_face*12+3] = -0.5+i;
						vertex_buffer[current_face*12+4] = -0.5+j;
						vertex_buffer[current_face*12+5] = 0.5+k;
						vertex_buffer[current_face*12+6] = -0.5+i;
						vertex_buffer[current_face*12+7] = -0.5+j;
						vertex_buffer[current_face*12+8] = -0.5+k;
						vertex_buffer[current_face*12+9] = 0.5+i;
						vertex_buffer[current_face*12+10] = -0.5+j;
						vertex_buffer[current_face*12+11] = -0.5+k;
						current_face++;
					}

					if(check_block_exists(i,j+1,k) == false)
					{

						texcoord_buffer[current_face*8] = current_texcoords[0];
						texcoord_buffer[current_face*8+1] = current_texcoords[1];
						texcoord_buffer[current_face*8+2] = current_texcoords[2];
						texcoord_buffer[current_face*8+3] = current_texcoords[3];
						texcoord_buffer[current_face*8+4] = current_texcoords[4];
						texcoord_buffer[current_face*8+5] = current_texcoords[5];
						texcoord_buffer[current_face*8+6] = current_texcoords[6];
						texcoord_buffer[current_face*8+7] = current_texcoords[7];

						color_buffer[current_face*12] = current_color[0];
						color_buffer[current_face*12+1] = current_color[1];
						color_buffer[current_face*12+2] = current_color[2];
						color_buffer[current_face*12+3] = current_color[0];
						color_buffer[current_face*12+4] = current_color[1];
						color_buffer[current_face*12+5] = current_color[2];
						color_buffer[current_face*12+6] = current_color[0];
						color_buffer[current_face*12+7] = current_color[1];
						color_buffer[current_face*12+8] = current_color[2];
						color_buffer[current_face*12+9] = current_color[0];
						color_buffer[current_face*12+10] = current_color[1];
						color_buffer[current_face*12+11] = current_color[2];

						vertex_buffer[current_face*12] = 0.5+i;
						vertex_buffer[current_face*12+1] = 0.5+j;
						vertex_buffer[current_face*12+2] = 0.5+k;
						vertex_buffer[current_face*12+3] = -0.5+i;
						vertex_buffer[current_face*12+4] = 0.5+j;
						vertex_buffer[current_face*12+5] = 0.5+k;
						vertex_buffer[current_face*12+6] = -0.5+i;
						vertex_buffer[current_face*12+7] = 0.5+j;
						vertex_buffer[current_face*12+8] = -0.5+k;
						vertex_buffer[current_face*12+9] = 0.5+i;
						vertex_buffer[current_face*12+10] = 0.5+j;
						vertex_buffer[current_face*12+11] = -0.5+k;
						current_face++;
					}

					if(check_block_exists(i-1,j,k) == false)
					{
						texcoord_buffer[current_face*8] = current_texcoords[0];
						texcoord_buffer[current_face*8+1] = current_texcoords[1];
						texcoord_buffer[current_face*8+2] = current_texcoords[2];
						texcoord_buffer[current_face*8+3] = current_texcoords[3];
						texcoord_buffer[current_face*8+4] = current_texcoords[4];
						texcoord_buffer[current_face*8+5] = current_texcoords[5];
						texcoord_buffer[current_face*8+6] = current_texcoords[6];
						texcoord_buffer[current_face*8+7] = current_texcoords[7];

						color_buffer[current_face*12] = current_color[0];
						color_buffer[current_face*12+1] = current_color[1];
						color_buffer[current_face*12+2] = current_color[2];
						color_buffer[current_face*12+3] = current_color[0];
						color_buffer[current_face*12+4] = current_color[1];
						color_buffer[current_face*12+5] = current_color[2];
						color_buffer[current_face*12+6] = current_color[0];
						color_buffer[current_face*12+7] = current_color[1];
						color_buffer[current_face*12+8] = current_color[2];
						color_buffer[current_face*12+9] = current_color[0];
						color_buffer[current_face*12+10] = current_color[1];
						color_buffer[current_face*12+11] = current_color[2];

						vertex_buffer[current_face*12] = -0.5+i;
						vertex_buffer[current_face*12+1] = 0.5+j;
						vertex_buffer[current_face*12+2] = 0.5+k;
						vertex_buffer[current_face*12+3] = -0.5+i;
						vertex_buffer[current_face*12+4] = -0.5+j;
						vertex_buffer[current_face*12+5] = 0.5+k;
						vertex_buffer[current_face*12+6] = -0.5+i;
						vertex_buffer[current_face*12+7] = -0.5+j;
						vertex_buffer[current_face*12+8] = -0.5+k;
						vertex_buffer[current_face*12+9] = -0.5+i;
						vertex_buffer[current_face*12+10] = 0.5+j;
						vertex_buffer[current_face*12+11] = -0.5+k;
						current_face++;
					}

					if(check_block_exists(i+1,j,k) == false)
					{

						texcoord_buffer[current_face*8] = current_texcoords[0];
						texcoord_buffer[current_face*8+1] = current_texcoords[1];
						texcoord_buffer[current_face*8+2] = current_texcoords[2];
						texcoord_buffer[current_face*8+3] = current_texcoords[3];
						texcoord_buffer[current_face*8+4] = current_texcoords[4];
						texcoord_buffer[current_face*8+5] = current_texcoords[5];
						texcoord_buffer[current_face*8+6] = current_texcoords[6];
						texcoord_buffer[current_face*8+7] = current_texcoords[7];

						color_buffer[current_face*12] = current_color[0];
						color_buffer[current_face*12+1] = current_color[1];
						color_buffer[current_face*12+2] = current_color[2];
						color_buffer[current_face*12+3] = current_color[0];
						color_buffer[current_face*12+4] = current_color[1];
						color_buffer[current_face*12+5] = current_color[2];
						color_buffer[current_face*12+6] = current_color[0];
						color_buffer[current_face*12+7] = current_color[1];
						color_buffer[current_face*12+8] = current_color[2];
						color_buffer[current_face*12+9] = current_color[0];
						color_buffer[current_face*12+10] = current_color[1];
						color_buffer[current_face*12+11] = current_color[2];

						vertex_buffer[current_face*12] = 0.5+i;
						vertex_buffer[current_face*12+1] = 0.5+j;
						vertex_buffer[current_face*12+2] = 0.5+k;
						vertex_buffer[current_face*12+3] = 0.5+i;
						vertex_buffer[current_face*12+4] = -0.5+j;
						vertex_buffer[current_face*12+5] = 0.5+k;
						vertex_buffer[current_face*12+6] = 0.5+i;
						vertex_buffer[current_face*12+7] = -0.5+j;
						vertex_buffer[current_face*12+8] = -0.5+k;
						vertex_buffer[current_face*12+9] = 0.5+i;
						vertex_buffer[current_face*12+10] = 0.5+j;
						vertex_buffer[current_face*12+11] = -0.5+k;
						current_face++;
					}
				}
			}
		}
	}
	return current_face;
}
コード例 #4
0
ファイル: file_io.c プロジェクト: chineseneo/lessfs
unsigned long long file_read_block(unsigned long long blocknr,
                                   const char *filename, char *blockdata,
                                   unsigned long long inode)
{
    unsigned long long ret = 0;
    DBT *data = NULL;
    DBT *decrypted = NULL;
    DBT *cachedata;
    unsigned char *stiger;
    unsigned char *dtiger;
    compr *uncompdata = NULL;
    INOBNO inobno;
    BLKCACHE *blk;
    bool compressed = 1;
    QDTA *dta;
#ifndef SHA3
    word64 res[3];
#endif

    FUNC;
    inobno.inode = inode;
    inobno.blocknr = blocknr;
    data = try_block_cache(inode, blocknr, 0);
    if (NULL != data) {
        LDEBUG("file_read_block : block %llu - %llu found in cache", inode,
               blocknr);
        memcpy(blockdata, data->data, data->size);
        ret = data->size;
        DBTfree(data);
        return (ret);
    }
    data = check_block_exists(inobno);
    if (NULL == data) {
        LDEBUG("check_block_exists : Nothing found for inode %llu - %llu",
               inobno.inode, inobno.blocknr);
        LDEBUG("DONE ret = %llu",ret);
        return (ret);
    }
// Not needed to copy this.
    stiger = s_malloc(data->size);
    memcpy(stiger, data->data, data->size);
    DBTfree(data);
// First try the cache
    get_moddb_lock();
    data = search_memhash(dbdtaq, stiger, config->hashlen);
    if (NULL == data) {
        decrypted = file_tgr_read_data(stiger);
        if (NULL != decrypted) {
            LDEBUG
                ("file_read_block : found inode %llu - %llu file_io",
                 inobno.inode, inobno.blocknr);
        } else {

            cachedata =
                search_memhash(blkcache, &inobno.inode,
                               sizeof(unsigned long long));
            if (NULL != cachedata) {
                blk = (BLKCACHE *) cachedata->data;
#ifdef SHA3
                dtiger=sha_binhash(blk->blockdata, BLKSIZE);
#else
                binhash(blk->blockdata, BLKSIZE,res);
                dtiger=(unsigned char *)&res;
#endif
                if (0 == memcmp(dtiger, stiger, config->hashlen)) {
                    decrypted = s_malloc(sizeof(DBT));
                    decrypted->data = s_malloc(BLKSIZE);
                    decrypted->size = BLKSIZE;
                    memcpy(decrypted->data, blk->blockdata, BLKSIZE);
                    compressed = 0;
                }
#ifdef SHA3
                free(dtiger);
#endif
                DBTfree(cachedata);
            }
        }
    } else {
        decrypted = s_malloc(sizeof(DBT));
        dta = (QDTA *) data->data;
        decrypted->data = s_malloc(dta->size);
        memcpy(decrypted->data, dta->data, dta->size);
        decrypted->size = dta->size;
        DBTfree(data);
    }
    release_moddb_lock();
    if (decrypted->size > BLKSIZE)
        die_dataerr("file_read_block : data has grown beyond blocksize %lu",
                    decrypted->size);
    if (compressed && decrypted->size != BLKSIZE) {
#ifdef LZO
        uncompdata = lzo_decompress(decrypted->data, decrypted->size);
#else
        uncompdata = clz_decompress(decrypted->data, decrypted->size);
#endif
        memcpy(blockdata, uncompdata->data, uncompdata->size);
        ret = uncompdata->size;
        comprfree(uncompdata);
    } else {
        memcpy(blockdata, decrypted->data, decrypted->size);
        ret = decrypted->size;
    }
    DBTfree(decrypted);
    free(stiger);
    EFUNC;
    return (ret);
}