예제 #1
0
파일: volume.c 프로젝트: clyde7/iv
Brick * volume_create_brick(Image const * volume, Vector ratio)
{
    Image_Format format = volume->format;
    float const size_x = (format.size.x - 1) * ratio.x;
    float const size_y = (format.size.y - 1) * ratio.y;
    float const size_z = (format.size.z - 1) * ratio.z;
    float const max_size = fmax(fmax(size_x, size_y), size_z);

    Brick * brick = malloc_size(Brick);
    brick->texture = 0;
    brick->level = 0;
    brick->tex.min.x = 0.5 / format.size.x;
    brick->tex.min.y = 0.5 / format.size.y;
    brick->tex.min.z = 0.5 / format.size.z;
    brick->tex.max.x = 1 - brick->tex.min.x;
    brick->tex.max.y = 1 - brick->tex.min.y;
    brick->tex.max.z = 1 - brick->tex.min.z;
    brick->box.min = ORIGIN;
    brick->box.max.x = size_x / max_size;
    brick->box.max.y = size_y / max_size;
    brick->box.max.z = size_z / max_size;

    printf("box = \n");
    box_print(brick->box);
    printf("tex = \n");
    box_print(brick->tex);

    return brick;
}
예제 #2
0
파일: pac.c 프로젝트: stig/pac
/* Just output some information/feedback as to whether the user
 * lost or chickened out... */
static void finish(int won, int lives)
{
        int c;
        if (lives == 0) {
                box_print(0, 0, "Sorry, you lost :(");
        }
        else if (!won) {
                box_print(0, 0, "So you don't want to play, eh? Meanie!");
        }
        while ((c = blocking_input()) && c != ' ' && c != 'q')
                ;
}
예제 #3
0
static void test_box( const int box[3][2] , const int np )
{
  const int ncell_box = box[0][1] * box[1][1] * box[2][1] ;
  int ncell_total = 0 ;
  int ncell_min = ncell_box ;
  int ncell_max = 0 ;
  int (*pbox)[3][2] ;
  int i , j ;

  pbox = (int (*)[3][2]) malloc( sizeof(int) * np * 3 * 2 );

  box_partition( 0 , np , 2 , box , pbox );

  for ( i = 0 ; i < np ; ++i ) {
    const int ncell = ( pbox[i][0][1] - pbox[i][0][0] ) *
                      ( pbox[i][1][1] - pbox[i][1][0] ) *
                      ( pbox[i][2][1] - pbox[i][2][0] );

    if ( ! box_contain( box , (const int (*)[2]) pbox[i] ) ) {
      fprintf(stdout,"  OUT OF BOUNDS pbox[%d/%d] = ",i,np);
      box_print(stdout,(const int (*)[2]) pbox[i]);
      fprintf(stdout,"\n");
      abort();
    }

    for ( j = i + 1 ; j < np ; ++j ) {
      if ( ! box_disjoint( (const int (*)[2]) pbox[i] ,
                           (const int (*)[2]) pbox[j] ) ) {
        fprintf(stdout,"  NOT DISJOINT pbox[%d/%d] = ",i,np);
        box_print(stdout, (const int (*)[2]) pbox[i]);
        fprintf(stdout,"\n");
        fprintf(stdout,"               pbox[%d/%d] = ",j,np);
        box_print(stdout, (const int (*)[2]) pbox[j]);
        fprintf(stdout,"\n");
        abort();
      }
    }
    ncell_total += ncell ;

    if ( ncell_max < ncell ) { ncell_max = ncell ; }
    if ( ncell < ncell_min ) { ncell_min = ncell ; }
  }

  if ( ncell_total != ncell_box ) {
    fprintf(stdout,"  WRONG CELL COUNT NP = %d\n",np);
    abort();
  }
  fprintf(stdout,"NP = %d, total = %d, avg = %d, min = %d, max = %d\n",
          np,ncell_box,ncell_box/np,ncell_min,ncell_max);

  free( pbox );
}
예제 #4
0
파일: gnmc.c 프로젝트: dsheeler/krad_radio
static void gnmc_texts_screen_update (screen_t *screen, uint32_t id) {

  cr_cache_t *cache;
  kr_crate_t *crate;
  box_t *box;
  kr_comp_controls_t ctls;
  kr_text_t *text;
  box_list_t **bxs;

  cache = screen->cache;
  crate = cache->read (cache,id);
  bxs = screen->boxes;

  if (crate != NULL) {
    text = &crate->rep.text;
    ctls = text->controls;
    box = box_get_by_id (*bxs,id);
    if (box != NULL) {
      box_clear (box);
      box_print (box,"ID: %d X: %d Y: %d Text: %s",id,ctls.x,ctls.y,text->text);
    }
  }

  return;
}
예제 #5
0
파일: pac.c 프로젝트: stig/pac
static int game_won(const struct env *board)
{
        if (cherry_cnt(board) <= 0) {
                box_print(0, 0, "YOU WON!");
                return 1;
        }
        else 
                return 0;
}
예제 #6
0
파일: gnmc.c 프로젝트: dsheeler/krad_radio
static void gnmc_sprites_screen_populate (scr_t *scr, sprite_t *spr, uint32_t id) {

	box_t *box;

	box = box_create (scr,ID,1);
  box_set_id (box,id);
	box_print (box,"ID: %d Filename: %s",id,spr->filename);

	return;
}
예제 #7
0
파일: gnmc.c 프로젝트: dsheeler/krad_radio
static int32_t gnmc_krstation_handler (gnmc_t *mon, kr_crate_t *crate) {

	screen_t *screen;
	box_t *rbox;
	kr_subunit_t subunit;
	kr_radio_t *radio;
	kr_remote_t *remote;
  screen_t **main_scrs;

	subunit = crate->addr->path.subunit;
	radio = crate->inside.radio;
	remote = crate->inside.remote;

  main_scrs = mon->main_scrs;
  screen = main_scrs[STAT_SCR];


	if (subunit.zero == KR_TAGS) {
      // printf ("Station Tags");
	}


	switch (subunit.station_subunit) {

		case KR_CPU:
				// if (kr_crate_has_int (crate)) {
				// 	mvwprintw (win,5,5,"CPU %d%%",crate->integer);
				// 	update_panels ();
				// 	doupdate ();
				// }
			break;
		case KR_REMOTE:
			
			rbox = box_get_by_id (screen_boxes (screen),remote->port);

			if (rbox == NULL) {
				rbox = box_create (screen,ID,1);
				box_set_id (rbox,remote->port);
			}

			box_clear (rbox);
			box_reset_cur (rbox);
			box_print (rbox,"Remote: %s %d",remote->interface,remote->port);

			break;
		default:
			if (gnmc_sysinfo_show (screen,radio,mon->info) < 0) {
				return -1;
			}
			break;
	}
    
	return 0;
}
예제 #8
0
파일: gnmc.c 프로젝트: dsheeler/krad_radio
static void gnmc_texts_screen_populate (scr_t *scr, kr_text_t *text, uint32_t id) {

	box_t *box;

  kr_comp_controls_t ctls = text->controls;

	box = box_create (scr,ID,1);
  box_set_id (box,id);
	box_print (box,"ID: %d X: %d Y: %d Text: %s",id,ctls.x,ctls.y,text->text);

	return;
}
예제 #9
0
파일: gnmc.c 프로젝트: dsheeler/krad_radio
static int32_t gnmc_portgroup_show (port_t *port, screen_t *scr) {

	box_t *port_box;

	port_box = box_create (scr,NAME,1);
	box_set_name (port_box,port->sysname);

	switch (port->direction) {
		case INPUT:
			box_print (port_box,"Input %s , Vol: %0.2f%%",
      port->sysname,port->volume[0]);
			box_set_info (port_box,"Input");
      port_box->ro = 1;
			break;
		case OUTPUT:
			if (port->output_type == DIRECT) {
				box_print (port_box,"Output %s , Vol: %0.2f%%",
        port->sysname,port->volume[0]);
				box_set_info (port_box,"Output");
        port_box->ro = 1;
			}
			else {
				box_print (port_box,"Aux Output %s , Vol: %0.2f%%",
        port->sysname,port->volume[0]);
				box_set_info (port_box,"Aux Output");
        port_box->ro = 1;
			}
			break;
		case MIX:
			box_print (port_box,"Bus %s , Vol: %0.2f%%",
      port->sysname,port->volume[0]);
			box_set_info (port_box,"Bus");
      port_box->ro = 1;
			break;
	}

	return 0;
}
예제 #10
0
파일: pac.c 프로젝트: stig/pac
/* returns 1 if we want to play again, 0 if we don't */
static int play_again(void)
{
        int ch;
        char *s = "Hit space to continue, or q to quit";

        box_print(0, 0, s);
        while ((ch = blocking_input()) && ch != ' ' && ch != 'q')
                ;

        if (ch == 'q')
                return 0;
        else
                return 1;
}
예제 #11
0
파일: gnmc.c 프로젝트: dsheeler/krad_radio
static int32_t gnmc_sysinfo_show (screen_t *scr, 
  kr_radio_t *radio, info_t *info) {

	char *str;
	char *tmpstr;
	char *token;
	char uptime[32];

	box_t *sysinfo_box,*moninfo_box;
	box_list_t **bxs;
	box_list_t *boxes;

	s_to_hhmmss (uptime, radio->uptime);

	bxs = scr->boxes;
	boxes = *bxs;

	sysinfo_box = box_get_by_name (boxes,"sysinfo");
  moninfo_box = box_get_by_name (boxes,"moninfo");

	box_clear (sysinfo_box);

	box_reset_cur (sysinfo_box);

	box_print (sysinfo_box,"Uptime: %s",uptime);

	box_nl (sysinfo_box,0);

	box_print (sysinfo_box,"CPU: %u%%",radio->cpu_usage);

	box_nl (sysinfo_box,0);

	str = strdup (radio->sysinfo);
	tmpstr = str;
	while ( (token = strsep (&str,"\n")) != NULL ) {
		box_print (sysinfo_box,"%s",token);
		box_nl (sysinfo_box,0);
	}
	free (tmpstr);

	if (radio->logname[0] != '\0') {
		box_print (sysinfo_box,"Log: %s",radio->logname);
	}

  box_clear (moninfo_box);
  box_print (moninfo_box,"Deliveries: %d",info->deliveries);
  box_nl (moninfo_box,0);
  box_print (moninfo_box,"Crates: %dS %dM %dC %dT",
  info->crates[0],info->crates[1],info->crates[2],info->crates[3]);

	return 0;
}
예제 #12
0
파일: gnmc.c 프로젝트: dsheeler/krad_radio
static void gnmc_krmixer_updatevol (screen_t *screen, char *name, float vol) {

	box_t *box;
	box_list_t **boxes;
	box_list_t *bxs;

	boxes = screen->boxes;
	bxs = *boxes;

	box = box_get_by_name (bxs, name);

	if (box != NULL) {
		box_clear (box);
		box_print (box,"%s %s , Vol: %0.2f%%",box->info,name,vol);
	}

	return;
}
예제 #13
0
파일: gnmc.c 프로젝트: dsheeler/krad_radio
static int32_t gnmc_krvideoport_show (comp_t *comp, screen_t *scr) {


	box_t *box;

	box = box_get_by_name (screen_boxes (scr), "res");
	box_clear (box);
	box_reset_cur (box);

	box_print (box,"Res: %dx%d",comp->width,comp->height);

	box = box_get_by_name (screen_boxes (scr), "fps");
	box_clear (box);
	box_reset_cur (box);

	box_print (box,"Fps: %d",comp->fps_numerator / comp->fps_denominator);

	box = box_get_by_name (screen_boxes (scr),"texts");
	box_clear (box);
	box_reset_cur (box);

	box_print (box,"Texts: %d",comp->texts);

	box = box_get_by_name (screen_boxes (scr), "sprites");
	box_clear (box);
	box_reset_cur (box);

	box_print (box,"Sprites %d",comp->sprites);

	box = box_get_by_name (screen_boxes (scr), "vectors");
	box_clear (box);
	box_reset_cur (box);

	box_print (box,"Vectors: %d ",comp->vectors);

	box = box_get_by_name (screen_boxes (scr), "frames");
	box_clear (box);
	box_reset_cur (box);

	box_print (box,"Frames: %d ",comp->frames);


	return 0;
}
예제 #14
0
파일: pac.c 프로젝트: stig/pac
static int main_game_loop(struct env *board, 
                struct creature *pac,
                struct creature *ghost, 
                int cnt)
{
        unsigned long time_to_sleep;
        enum dir_t direction;
        int i, won = 0;
        
        draw_board(board);
        box_print(0, 0, "Welcome. Hit any key to start :)");
        update_view();
        blocking_input();

        do {
                /* set up and place the players (ghosts etc) */
                if (!init_players(board, pac, ghost, cnt))
                        return 0;

                /* blank out screen, ready for action */
                reset_view();
		draw_board(board);

                time_to_sleep = INITIAL_DELAY;
                for (;;) {
			/* check for user input */
                        direction = get_user_input();
                        if (direction == QUIT) break;

                        move_pac(board, pac, direction);
                        draw_creature(board, pac);
			erase_tail(board, pac);

                        /* Move and draw N ghosts. */
                        for (i=0; i<cnt; i++) {
                                ghost_move(board, &(ghost[i]), i);
                                draw_creature(board, &(ghost[i]));
				erase_tail(board, &(ghost[i]));
                        }

                        /* Up the score if we got any cherries,
                         * then print the new (or old) score. */
                        pick_up_cherries(board, pac);
                        print_stat(board);

                        /* update the whole screen */
                        update_view();

                        /* Check if there's any more cherries to
                         * pick, otherwise the game is won. */
                        won = game_won(board);
                        if (won) break;

                        if (pac_caught(pac, ghost, cnt)) {
                                down_lives(board);
                                break;
                        }

                        /* 
			 * Sleep for a short while. This function is not
			 * ANSI/ISO-C.
                         */
                        usleep(time_to_sleep);
                        if (time_to_sleep > MIN_DELAY)
                                time_to_sleep -= DEC_DELAY;
                } 
        } while (direction != QUIT && !won && lives_left(board) > 0 && play_again());
        
        finish(won, lives_left(board));
        return 1;
}