Exemplo n.º 1
0
void start_radiosity(long val)
#endif
{
    static long state = 0 ;
    long i;
    long total_rad_time, max_rad_time, min_rad_time;
    long total_refine_time, max_refine_time, min_refine_time;
    long total_wait_time, max_wait_time, min_wait_time;
    long total_vertex_time, max_vertex_time, min_vertex_time;

#if defined(SGI_GL) && defined(GL_NASA)
    long val ;

    val = g_get_choice_val( ap, &choices[0] ) ;
#endif

    if( val == CHOICE_RAD_RUN )
        {
            if( state == -1 )
                {
                    printf( "Please reset first\007\n" ) ;
                    return ;
                }

            /* Time stamp */
            CLOCK( time_rad_start ) ;


            global->index = 0;

            /* Create slave processes */
            for (i = 0 ; i < n_processors ; i++ )
                {
                    taskqueue_id[i] = assign_taskq(0) ;
                }

            /* And start processing */
            CREATE(radiosity, n_processors);
            WAIT_FOR_END(n_processors);
            /* Time stamp */
            CLOCK( time_rad_end );

            /* Print out running time */
            /* Print out running time */
            printf("TIMING STATISTICS MEASURED BY MAIN PROCESS:\n");

            print_running_time(0);

            if (dostats) {
                printf("\n\n\nPER-PROCESS STATISTICS:\n");

                printf("%8s%20s%20s%12s%12s\n","Proc","Total","Refine","Wait","Smooth");
                printf("%8s%20s%20s%12s%12s\n\n","","Time","Time","Time","Time")
                    ;
                for (i = 0; i < n_processors; i++)
                    printf("%8ld%20lu%20lu%12lu%12lu\n",i,timing[i]->rad_time, timing[i]->refine_time, timing[i]->wait_time, timing[i]->vertex_time);

                total_rad_time = timing[0]->rad_time;
                max_rad_time = timing[0]->rad_time;
                min_rad_time = timing[0]->rad_time;

                total_refine_time = timing[0]->refine_time;
                max_refine_time = timing[0]->refine_time;
                min_refine_time = timing[0]->refine_time;

                total_wait_time = timing[0]->wait_time;
                max_wait_time = timing[0]->wait_time;
                min_wait_time = timing[0]->wait_time;

                total_vertex_time = timing[0]->vertex_time;
                max_vertex_time = timing[0]->vertex_time;
                min_vertex_time = timing[0]->vertex_time;

                for (i = 1; i < n_processors; i++) {
                    total_rad_time += timing[i]->rad_time;
                    if (timing[i]->rad_time > max_rad_time)
                        max_rad_time = timing[i]->rad_time;
                    if (timing[i]->rad_time < min_rad_time)
                        min_rad_time = timing[i]->rad_time;

                    total_refine_time += timing[i]->refine_time;
                    if (timing[i]->refine_time > max_refine_time)
                        max_refine_time = timing[i]->refine_time;
                    if (timing[i]->refine_time < min_refine_time)
                        min_refine_time = timing[i]->refine_time;

                    total_wait_time += timing[i]->wait_time;
                    if (timing[i]->wait_time > max_wait_time)
                        max_wait_time = timing[i]->wait_time;
                    if (timing[i]->wait_time < min_wait_time)
                        min_wait_time = timing[i]->wait_time;

                    total_vertex_time += timing[i]->vertex_time;
                    if (timing[i]->vertex_time > max_vertex_time)
                        max_vertex_time = timing[i]->vertex_time;
                    if (timing[i]->vertex_time < min_vertex_time)
                        min_vertex_time = timing[i]->vertex_time;
                }


                printf("\n\n%8s%20lu%20lu%12lu%12lu\n","Max", max_rad_time, max_refine_time, max_wait_time, max_vertex_time);
                printf("\n%8s%20lu%20lu%12lu%12lu\n","Min", min_rad_time, min_refine_time, min_wait_time, min_vertex_time);
                printf("\n%8s%20lu%20lu%12lu%12lu\n","Avg", (long) (((double) total_rad_time) / ((double) (1.0 * n_processors))), (long) (((double) total_refine_time) / ((double) (1.0 * n_processors))), (long) (((double) total_wait_time) / ((double) (1.0 * n_processors))), (long) (((double) total_vertex_time) / ((double) (1.0 * n_processors))));
                printf("\n\n");

            }

            /*      print_fork_time(0) ; */

            print_statistics( stdout, 0 ) ;

            /* Display image */
            display_scene( disp_fill_mode, disp_patch_switch,
                          disp_mesh_switch, disp_interaction_switch, 0) ;

            state = -1 ;
        }

    else if( val == CHOICE_RAD_STEP )
        {
            if( state == -1 )
                {
                    printf( "Please reset first\007\n" ) ;
                    return ;
                }

            /* Step execution */
            switch( state )
                {
                case 0:
                    /* Step execute as a single process */

                    global->index = 1;
                    /* Create slave processes */
                    for ( i = 0 ; i < n_processors ; i++ )
                        {
                            taskqueue_id[i] = assign_taskq(0) ;
                        }

                    CREATE(radiosity, n_processors/* - 1*/);

                    /* Decompose model objects into patches and build
                       the BSP tree */
                    /* Create the first tasks (MASTER only) */
                    init_modeling_tasks(0) ;
                    process_tasks(0) ;
                    state ++ ;
                    break ;

                case 1:
                    if( init_ray_tasks(0) )
                        {
                            BARRIER(global->barrier, n_processors);
                            process_tasks(0) ;
                        }
                    else
                        state++ ;
                    break ;
                default:
                    BARRIER(global->barrier, n_processors);
                    init_radavg_tasks( RAD_AVERAGING_MODE, 0 ) ;
                    process_tasks(0) ;
                    init_radavg_tasks( RAD_NORMALIZING_MODE, 0 ) ;
                    process_tasks(0) ;

                    WAIT_FOR_END(n_processors/* - 1*/)
                        state = -1 ;
                }

            /* Display image */
            display_scene( disp_fill_mode, disp_patch_switch,
                          disp_mesh_switch, disp_interaction_switch, 0) ;
        }

    else if( val == CHOICE_RAD_RESET )
        {
            /* Initialize global variables again */
            init_global(0) ;
            init_visibility_module(0) ;
            g_clear() ;
            state = 0 ;
        }
}
Exemplo n.º 2
0
void g_updateGame()
{
	if (game.state == STATE_IDLE)
	{
		//do nothing
	}
	else if (game.state == STATE_MENU)
	{	
		//menuSound = m_move;
		
		switch ( m_move() )
		{
			case SND_MENUMOVE:
				s_playSound(menuMove);
				break;
			case SND_MENUSELECT:
				s_playSound(menuSelect);
				break;
			case SND_NONE:
			default:
				break;
		}
		/*
		if ( !m_move() )
		{
			//too much output
			//printf("[g_updateGame]: m_move returned false!\n");
		}
		*/
	}
	else if (game.state == STATE_PLAYING)
	{	
		//game.currentTime = SDL_GetTicks();
		
		//take note of the frame here, see if it is time to move the current tetro
		//1 notch down
		if ( dropFrameInterval >= dropIntervalPerRow[game.level] && !game.isSoftDropping ) //time to drop down 1, only if down arrow not already held down
		{
			dropFrameInterval = 0;

			if ( !tetro_move(game.current, DIR_SOUTH) ) //the periodic drop down was blocked
			{
				//printf("[g_updateGame]: periodic drop down blocked!\n");
				g_onDownBlocked();
			}
			//game.lastDropTime = game.currentTime;
		}
		
		
			
		//rotate has priority
		if ( game.current->tryRotate )
		{
			debug_msg("[g_updateGame]: trying rotate...\n");
			if ( tetro_rotate(game.current) )
			{
				debug_msg("[g_updateGame]: rotate success!\n");
				s_playSound(rotate);
			}
			else
				debug_msg("[g_updateGame]: rotate failed!\n");
		}
		
		//for delayed auto shifting
		if ( game.dasDir != DIR_NONE )
		{
			game.current->nextMoveY = DIR_NONE;
			if ( game.dasDelaying )
			{
				if ( game.dasFrame >= DAS_DELAY )
				{
					game.dasDelaying = false;
					game.current->nextMoveX = game.dasDir;
					game.dasFrame = 0;
				}
			}
			else
			{
				if ( game.dasFrame >= DAS_PERIOD )
				{
					game.current->nextMoveX = game.dasDir;
					game.dasFrame = 0;
				}
			}
			game.dasFrame++;
		}
		//printf("game.dasFrame = %d\n", game.dasFrame);
		
		if ( game.isSoftDropping )
		{
			if ( game.softDropFrame >= SOFT_DROP_FRAMES ) //time to move down a notch
			{
				game.softDropFrame = 0;
				if ( !tetro_move(game.current, DIR_SOUTH) )
				{
					//printf("[g_updateGame]: periodic drop down blocked!\n");
					g_onDownBlocked();
					game.softDropFrame = SOFT_DROP_FRAMES; //next block insta drop down
					game.score += game.softDropDistanceCount;
					game.softDropDistanceCount = 0;
				}
				else
					game.softDropDistanceCount++;
			}
			game.softDropFrame++;
		}
		else
		{
			//create resultant move direction
			if ( game.current->nextMoveX == DIR_NONE )
				game.current->nextMoveDir = game.current->nextMoveY;
			else if ( game.current->nextMoveY == DIR_NONE )
				game.current->nextMoveDir = game.current->nextMoveX;
			else if ( game.current->nextMoveY == DIR_NORTH )
			{
				if ( game.current->nextMoveX == DIR_WEST )
					game.current->nextMoveDir = DIR_NORTHWEST;
				else
					game.current->nextMoveDir = DIR_NORTHEAST;
			}
			else //nextMoveY == south
			{
				if ( game.current->nextMoveX == DIR_WEST )
					game.current->nextMoveDir = DIR_SOUTHWEST;
				else
					game.current->nextMoveDir = DIR_SOUTHEAST;
			}
		
			//attempt to move tetro in this direction
			if ( !tetro_move(game.current, game.current->nextMoveDir) )
			{
				printf("move failed no sound\n");
				//printf("[g_updateGame]: tetro_move failed!\n");
				if ( game.current->nextMoveDir == DIR_SOUTH  || game.current->nextMoveDir == DIR_SOUTHWEST || game.current->nextMoveDir == DIR_SOUTHEAST )
				{
					g_onDownBlocked();
				}
			}
			else if ( game.current->nextMoveDir == DIR_WEST || game.current->nextMoveDir == DIR_EAST ) //successful move, check to see if i should play a sound
			{
				printf("play move because move succeeded west or east\n");
				//if ( game.dasFrame == 0 && game.dasDelaying == true )
					s_playSound(moveSideways);
			}
		}
		
		game.current->nextMoveX = DIR_NONE;
		game.current->nextMoveY = DIR_NONE;
		game.current->nextMoveDir = DIR_NONE;
		game.current->tryRotate = false;

		dropFrameInterval++;
	}
	else if (game.state == STATE_LOSS)
	{
		//the idea: every frame fill up one of the spaces with a "dead" block. so in 180 frames the whole screen will be filled
		short i;
		block * b;
		
		if (game.lossFrame == -1)
		{
			//do nothing
		}
		else
		{
			if (game.lossCurrentRow >= SIZE_Y)
			{
				g_clear(REASON_LOSS);
			}
			else
			{
				if (game.lossFrame == 0)
					SDL_Delay(LOSS_PAUSE);
				
				if (game.lossFrame % 3 == 0)
				{
					for ( i = 0; i < SIZE_X; i++ )
					{
						b = g_getBlockAtPos(i, game.lossCurrentRow);
						if (b != NULL)
							g_removeBlockFromPos(b);
						b = NULL;
					
						b = block_create(TETRO_DEAD, NULL);
						if ( !block_teleport(b, i, game.lossCurrentRow) )
							debug_msg("[g_updateGame]: STATE_LOSS- error teleporting dead block into position!\n");
						b = NULL;
					}
					game.lossCurrentRow++;
				}
			}
		}
		
		game.lossFrame++;
	}		
	else
		debug_msg("[g_updateGame]: unknown game.state!\n");
	
	menu.nextMoveDir = DIR_NONE;
}