Source/ThunderBeast/QuakeToonProto1/ref_gl/gl_image.c
int Scrap_AllocBlock (int w, int h, int *x, int *y)
{
	int		i, j;
	int		best, best2;
	int		texnum;

	for (texnum=0 ; texnum<MAX_SCRAPS ; texnum++)
	{
		best = BLOCK_HEIGHT;

		for (i=0 ; i<BLOCK_WIDTH-w ; i++)
		{
			best2 = 0;

			for (j=0 ; j<w ; j++)
			{
				if (scrap_allocated[texnum][i+j] >= best)
					break;
				if (scrap_allocated[texnum][i+j] > best2)
					best2 = scrap_allocated[texnum][i+j];
			}
			if (j == w)
			{	// this is a valid spot
				*x = i;
				*y = best = best2;
			}
		}

		if (best + h > BLOCK_HEIGHT)
			continue;

		for (i=0 ; i<w ; i++)
			scrap_allocated[texnum][*x + i] = best + h;

		return texnum;
	}

	return -1;
//	Sys_Error ("Scrap_AllocBlock: full");
}
// returns a texture number and the position inside it
returns a texture number and the position inside it
returns a texture number and the position inside it
int Scrap_AllocBlock (int w, int h, int *x, int *y)
{
	int		i, j;
	int		best, best2;
	int		texnum;
	for (texnum=0 ; texnum<MAX_SCRAPS ; texnum++)
	{
		best = BLOCK_HEIGHT;
		for (i=0 ; i<BLOCK_WIDTH-w ; i++)
		{
			best2 = 0;
			for (j=0 ; j<w ; j++)
			{
				if (scrap_allocated[texnum][i+j] >= best)
					break;
				if (scrap_allocated[texnum][i+j] > best2)
					best2 = scrap_allocated[texnum][i+j];
			}
			if (j == w)
			{	
				*x = i;
				*y = best = best2;
			}
		}
		if (best + h > BLOCK_HEIGHT)
			continue;
		for (i=0 ; i<w ; i++)
			scrap_allocated[texnum][*x + i] = best + h;
		return texnum;
	}
	return -1;
}
int Scrap_AllocBlock ( int w , int h , int * x , int * y ) { int i , j ; int best , best2 ; int texnum ; for ( texnum = 0 ; texnum < MAX_SCRAPS ; texnum ++ ) { best = BLOCK_HEIGHT ; for ( i = 0 ; i < BLOCK_WIDTH - w ; i ++ ) { best2 = 0 ; for ( j = 0 ; j < w ; j ++ ) { if ( scrap_allocated [ texnum ] [ i + j ] >= best ) break ; if ( scrap_allocated [ texnum ] [ i + j ] > best2 ) best2 = scrap_allocated [ texnum ] [ i + j ] ; } if ( j == w ) { * x = i ; * y = best = best2 ; } } if ( best + h > BLOCK_HEIGHT ) continue ; for ( i = 0 ; i < w ; i ++ ) scrap_allocated [ texnum ] [ * x + i ] = best + h ; return texnum ; } return -1 ; }
returns a texture number and the position inside it
returns a texture number and the position inside it
// this is a valid spot //	Sys_Error ("Scrap_AllocBlock: full");