示例#1
0
/**
* "Got frame" callback.
* Fills the texture with the given frame, and displays it on the window.
*/
int video_display_frame(uint8_t* frame, int width, int height, int size) {

	//if we get a NULL frame, stop displaying.
	if(frame == NULL) {
		video_display_clean();
		return 0;
	}

	//first time called ? Initialize things.
	if(!initialized) {
		if(video_display_init_size(width, height) < 0) {
			fprintf(stderr, "Display : Failed initialization.\n");
			return -1;
		}
		if(video_display_set_size(width, height) < 0)
			return -1;

		initialized = 1;
	}

	//check whether the size of the video has changed
	if(width != current_width || height != current_height)
		if(video_display_set_size(width, height) < 0)
			return -1;
			
	//check whether there's new stuff in the input com buffer
	double new_update = jakopter_com_get_timestamp(com_in);
	if(new_update > prev_update) {
		update_infos();
		prev_update = new_update;
	}

	//update the texture with our new frame
	if(SDL_UpdateTexture(frameTex, NULL, frame, width) < 0) {
		fprintf(stderr, "Display : failed to update frame texture : %s\n", SDL_GetError());
		return -1;
	}

	//clear the renderer, then update it so that we get the new frame displayed.
	SDL_RenderClear(renderer);
	SDL_RenderCopy(renderer, frameTex, NULL, NULL);
	//SDL_RenderFillRect(renderer, &rectangle);
	//draw all overlay elements, when they exist
	int i=0;
	for(i=0 ; i<VIDEO_NB_NAV_INFOS ; i++)
		if(graphs[i].tex != NULL)
			SDL_RenderCopy(renderer, graphs[i].tex, NULL, &graphs[i].pos);
	draw_attitude_indic();
	draw_compass();
	SDL_RenderPresent(renderer);

	return 0;
}
示例#2
0
int			check_keystroke(t_arena *a)
{
	char	c;
	int		*cps;

	cps = &(a->display->cps);
	c = wgetch(a->display->w_info);
	if (c == 's')
		return (1);
	else if (c == ' ')
		a->display->running = !a->display->running;
	else if (c == 'j')
		*cps += (*cps < 1000) ? 10 : 1000 - *cps;
	else if (c == 'k')
		*cps -= (*cps >= 11) ? 10 : *cps - 1;
	else if (c == 'l')
		*cps += (*cps < 1000) ? 1 : 0;
	else if (c == ';')
		*cps -= (*cps > 1) ? 1 : 0;
	else if (c == 'q')
		a->display->quitting = 1;
	update_infos(a);
	return (0);
}
示例#3
0
void		print_winner_display(t_arena *a)
{
	t_player	*p;
	t_player	*best;

	best = a->players;
	p = a->players;
	while (p != NULL)
	{
		if (p->last_live >= best->last_live)
			best = p;
		p = p->next;
	}
	a->display->running = 0;
	update_infos(a);
	wtimeout(a->display->w_info, -1);
	wprintw(a->display->w_info, "\n\n\nThe fight as ended.\n\n");
	wprintw(a->display->w_info, "The winner is ");
	wattron(a->display->w_info, COLOR_PAIR(best->id));
	wprintw(a->display->w_info, "%s\n\n", best->name);
	wattroff(a->display->w_info, COLOR_PAIR(best->id));
	wprintw(a->display->w_info, "Press any key to exit");
	wgetch(a->display->w_info);
}
示例#4
0
int video_display_process(uint8_t* frame, int width, int height, int size) {

	//if we get a NULL frame, stop displaying.
	if(frame == NULL) {
		video_display_destroy();
		return 0;
	}

	//first time called ? Initialize things.
	if(!initialized) {
		if(video_display_init_size(width, height) < 0) {
			fprintf(stderr, "[~][Display] Failed initialization.\n");
			return -1;
		}
		if(video_display_set_size(width, height) < 0)
			return -1;
		initialized = 1;
	}

	//check whether the size of the video has changed
	if (width != current_width || height != current_height)
		if (video_display_set_size(width, height) < 0)
			return -1;

	//check whether there's new stuff in the input com buffer
	double new_update = jakopter_com_get_timestamp(com_in);
	if (new_update > prev_update) {
		update_infos();
		if (want_screenshot) {
			take_screenshot(frame, size);
			want_screenshot = 0;
			jakopter_com_write_int(com_in, 24, 0);
		}
		prev_update = new_update;
	}
	pthread_mutex_lock(&mutex_process);

	if (current_process != NULL) {
		current_process(frame, width, height, size);
	}
	pthread_mutex_unlock(&mutex_process);

	unload_element();

	if (load_element() < 0)
		fprintf(stderr, "Couldn't load graphic element\n");

	// update the texture with our new frame
	if (SDL_UpdateTexture(frameTex, NULL, frame, width) < 0) {
		fprintf(stderr, "[~][Display] Failed to update frame texture : %s\n", SDL_GetError());
		return -1;
	}

	//clear the renderer, then update it so that we get the new frame displayed.
	SDL_RenderClear(renderer);
	SDL_RenderCopy(renderer, frameTex, NULL, NULL);
	//SDL_RenderFillRect(renderer, &rectangle);
	//draw all overlay elements, when they exist
	int i = 0;
	for (i = 0 ; i < VIDEO_NB_NAV_INFOS ; i++)
		if (graphs[i].tex != NULL)
			SDL_RenderCopy(renderer, graphs[i].tex, NULL, &graphs[i].pos);

	pthread_mutex_lock(&mutex_graphics_list);
	struct graphics_list *current = icon_registry;
	while (current != NULL) {
		if (current->graphic != NULL && current->graphic->tex != NULL){
			int ret = SDL_RenderCopy(renderer, current->graphic->tex, NULL, &current->graphic->pos);
			if (ret < 0)
				fprintf(stderr, "[~][display] RenderCopy() failed: %s\n", SDL_GetError());
		}

		current = current->next;
	}
	pthread_mutex_unlock(&mutex_graphics_list);

	draw_attitude_indic();
	draw_compass();
	SDL_RenderPresent(renderer);

	return 0;
}