示例#1
0
/* We need to make pixels using reg's generate function, and write the result
 * to dest.
 */
static int
im_prepare_to_generate( REGION *reg, REGION *dest, Rect *r, int x, int y )
{
	IMAGE *im = reg->im;
	char *p;

	if( !im->generate ) {
		im_error( "im_prepare_to", _( "incomplete header" ) );
		return( -1 );
	}

	if( im_region_region( reg, dest, r, x, y ) )
		return( -1 );

	/* Remember where reg is pointing now.
	 */
	p = IM_REGION_ADDR( reg, reg->valid.left, reg->valid.top );

	/* Run sequence into reg.
	 */
	if( fill_region( reg ) )
		return( -1 );

	/* The generate function may not have actually made any pixels ... it
	 * might just have redirected reg to point somewhere else. If it has,
	 * we need an extra copy operation.
	 */
	if( IM_REGION_ADDR( reg, reg->valid.left, reg->valid.top ) != p )
		im__copy_region( reg, dest, r, x, y );

	return( 0 );
}
示例#2
0
文件: ogenmap.cpp 项目: mecirt/7k2
//---------- Begin of function World::fill_region -----//
void World::fill_region(short x, short y)
{
	err_when( x < 0 || x >= max_x_loc || y < 0 || y >= max_y_loc);

	short left, right;
	// Location *locPtr;

	// extent x to left and right
	for( left = x; left >= 0 && !get_loc(left,y)->region_id && get_loc(left,y)->region_type() == walkable; --left)
	{
		get_loc(left,y)->region_id = regionId;
	}
	++left;

	for( right=x+1; right < max_x_loc && !get_loc(right,y)->region_id && get_loc(right,y)->region_type() == walkable; ++right)
	{
		get_loc(right,y)->region_id = regionId;
	}
	--right;

	// ------- scan line below ---------//
	y++;
	if( y < max_y_loc )
	{
		for( x = left>0?left-1:0 ; x <= right+1 && x < max_x_loc; ++x )
		{
			if( !get_loc(x,y)->region_id && get_loc(x,y)->region_type() == walkable)
			{
				fill_region(x,y);
			}
		}
	}

	// ------- scan line above -------- //
	y -= 2;
	if( y >= 0)
	{
		for( x = left>0?left-1:0 ; x <= right+1 && x < max_x_loc; ++x )
		{
			if( !get_loc(x,y)->region_id && get_loc(x,y)->region_type() == walkable)
			{
				fill_region(x,y);
			}
		}
	}
}
示例#3
0
文件: ogenmap.cpp 项目: mecirt/7k2
void World::set_region_id()
{
	int            i,x,y;
	int            totalLoc=max_x_loc * max_y_loc;
	Location*      locPtr=loc_matrix;

	// -------- reset region_id to zero
	for( i=0 ; i<totalLoc ; i++, locPtr++ )
	{
		locPtr->region_id = 0;
	}

	regionId = 0;
	for( y = 0; y < max_y_loc; ++y)
	{
		locPtr = get_loc(0,y);
		for( x = 0; x < max_x_loc; ++x, ++locPtr)
		{
			if( !locPtr->region_id && locPtr->region_type() != REGION_INPASSABLE)
			{
				walkable = locPtr->region_type();
				++regionId;
				fill_region(x,y);
				err_when( regionId == 255);
			}
		}
	}

	region_array.init(regionId);

	// ------ update adjacency information and region area ------//

	regionId = 0;
	for( y = 0; y < max_y_loc; ++y)
	{
		locPtr = get_loc(0,y);
		for( x = 0; x < max_x_loc; ++x, ++locPtr)
		{
			int thisRegionId = locPtr->region_id;
			// #### begin Gilbert 19/2 ######//
			if( thisRegionId > 0)
			{
				region_array.inc_size( thisRegionId );
			}
			// #### end Gilbert 19/2 ######//
			if( thisRegionId > regionId)
			{
				if(thisRegionId == regionId+1)
					regionId++;
				region_array.set_region( thisRegionId, locPtr->region_type());
			}

			int adjRegionId;
			if( y > 0)
			{
				if( x > 0 && (adjRegionId = get_loc(x-1,y-1)->region_id) < thisRegionId )
					region_array.set_adjacent( thisRegionId, adjRegionId);
				if( (adjRegionId = get_loc(x,y-1)->region_id) < thisRegionId )
					region_array.set_adjacent( thisRegionId, adjRegionId);
				if( x < max_x_loc-1 && (adjRegionId = get_loc(x+1,y-1)->region_id) < thisRegionId )
					region_array.set_adjacent( thisRegionId, adjRegionId);
			}

			if( x > 0 && (adjRegionId = get_loc(x-1,y)->region_id) < thisRegionId )
				region_array.set_adjacent( thisRegionId, adjRegionId);
			if( x < max_x_loc-1 && (adjRegionId = get_loc(x+1,y)->region_id) < thisRegionId )
				region_array.set_adjacent( thisRegionId, adjRegionId);

			if( y < max_y_loc-1)
			{
				if( x > 0 && (adjRegionId = get_loc(x-1,y+1)->region_id) < thisRegionId )
					region_array.set_adjacent( thisRegionId, adjRegionId);
				if( (adjRegionId = get_loc(x,y+1)->region_id) < thisRegionId )
					region_array.set_adjacent( thisRegionId, adjRegionId);
				if( x < max_x_loc-1 && (adjRegionId = get_loc(x+1,y+1)->region_id) < thisRegionId )
					region_array.set_adjacent( thisRegionId, adjRegionId);
			}
		}
	}

   //---- sort the region after setting its size ----//

	region_array.sort_region();

	//-------- initialize region_stat_array ----------//

	region_array.init_region_stat();
}
示例#4
0
//**********************************************
//Game 3. Press buttons as the terms pop up to
//fill the screen. First one to fill the screen
//wins. Fills 6 pages (text on pages 1 and 2)
//**********************************************
float game3(void){
	int buttonPresses = 0;
	int page;
	int col = 0;
	int colFinished = 0;
	int i;
	float ticks;
	float mHz = 50000000;
	int seconds = 0;
	int colLED = 0;
	TIMER0_Type *gp_timer;
	init_squares = 8;
	squares_caught = 0;
	gp_timer = (TIMER0_Type *) TIMER1_BASE;
	lcd_write_string_10pts(0,"Game 3!");
	lcd_write_string_10pts(1, "Fill screen");
	lcd_write_string_10pts(2, "by hitting");
	lcd_write_string_10pts(3, "top Button");
	for(i = 0; i < 10000000; i++){};
	lcd_clear();
		
	f14_timer1_Init(1);
	//f14_timer0_start(1);
		while(1){
			if(sendPackets){
			sendPackets = false;
			if(wireless_send_32(false,false,0) != NRF24L01_TX_SUCCESS){
				packetsDropped++;
			}
		}
			WATCHDOG0->ICR = 0;
			if(matrixWrite){
				matrixWrite = false;
				ledMatrixWriteData(I2C_I2C_BASE, colLED, Led_LUT[init_squares-squares_caught][colLED]);
				colLED++;
				colLED = colLED % 5;
		 }
		 button = -1;
			if(AlertSysTick){
				data = GPIOF->DATA;
				if( (data & PA1) == 0)
				{
					up++;
					if(up == 7)
						button = 0;
				}
				else
					up = 0;
				
				if( (data & PA4) == 0)
				{
					down++;
					if(down == 7)
						button = 3;
						
				}
				else
					down = 0;
				
				if( (data & PA2) == 0)
				{
					right++;
					if(right == 7)
						button = 1;
				}
				else
					right = 0;
				
				if( (data & PA3) == 0)
				{
					left++;
					if(left == 7)
						button = 2;
				}
				else
					left = 0;

				AlertSysTick = false;
			}
						
			if(gp_timer->RIS == 1){
				gp_timer->ICR = 1;
				seconds++;
			}
		
			if(button == 0){
				page = (buttonPresses % 8);
				fill_region(page,col);
				fill_region(page+1,col);
				buttonPresses+=2;
				if(buttonPresses % 8 == 0){
					squares_caught++;
					col+=13;
				}
			}
			if(buttonPresses == 64){
				ticks = f14_timer1_stop();
				lcd_clear();
				lcd_write_string_10pts(0,"Good job!");
				lcd_write_string_10pts(1,"Time:    ");
				lcd_write_string_10pts(2,"You win!");
				for(i = 0; i < 10000000; i++){};
				lcd_clear();
				return (seconds+roundF(ticks/mHz));
			}
		}
}