Exemplo n.º 1
0
display_context_t lockVideo(int wait)
{
    display_context_t dc;

    if (wait)
        while (!(dc = display_lock()));
    else
        dc = display_lock();
    return dc;
}
Exemplo n.º 2
0
/**
 * @brief Helper function to render the console
 */
static void __console_render()
{
    if(!render_buffer) { return; }

    static display_context_t dc = 0;

    /* Wait until we get a valid context */
    while(!(dc = display_lock()));

    /* Background color! */
    graphics_fill_screen( dc, 0 );

    for(int y = 0; y < CONSOLE_HEIGHT; y++)
    {
        for(int x = 0; x < CONSOLE_WIDTH; x++)
        {
            char t_buf = render_buffer[y * CONSOLE_WIDTH + x];

            if(t_buf == 0)
            {
                display_show(dc);
                return;
            }

            /* Draw to the screen using the forecolor and backcolor set in the graphics
             * subsystem */
            graphics_draw_character( dc, 20 + 8 * x, 16 + 8 * y, t_buf );
        }
    }

    display_show(dc);
}
Exemplo n.º 3
0
void display_print_page(void)
{
	int n_lines = 0;
	int cur_idx_prev = cur_idx;

	if (cur_idx >= (int)pages_len) {
		return;
	}

	display_lock();
	for (size_t i = cur_idx; i < pages_len; ++i) {
		if (pages[i] == '\n') {
			n_lines++;
			if (n_lines == win_txt_height - 2) {
				pages[i] = 0;
				cur_idx = i + 1;
				break;
			}
		}
	}

	waddstr(win_txt, pages + cur_idx_prev);
	if (cur_idx != cur_idx_prev && cur_idx < (int)pages_len)
		waddstr(win_txt, "\nPRESS ENTER FOR MORE...\n");
	else {
		pages_len = 0;
	}
	wrefresh(win_txt);
	display_unlock();
}
Exemplo n.º 4
0
void display_cmd(const char *cmd, int cl, int cursor_pos)
{
	cmd_len = cl;
	if (cursor_pos == -1 || cursor_pos > cmd_len)
		cursor_pos = cmd_len;
	cmd_cursor_pos = cursor_pos;
	cmd_cmd = cmd;

	display_lock();
	werase(win_cmd);
	if (cursor_pos < cmd_len) {
		waddnstr(win_cmd, cmd, cursor_pos);
		wbkgdset(win_cmd, COLOR_PAIR(YELLOW_ON_BLACK));
		waddnstr(win_cmd, cmd + cursor_pos, 1);
		wbkgdset(win_cmd, COLOR_PAIR(BLACK_ON_YELLOW));
		waddnstr(win_cmd, cmd + cursor_pos + 1, cmd_len - (cursor_pos + 1));
	}
	else {
		waddnstr(win_cmd, cmd, cmd_len);
		wmove(win_cmd, cursor_pos, 0);
		wbkgdset(win_cmd, COLOR_PAIR(YELLOW_ON_BLACK));
		waddstr(win_cmd, " ");
		wbkgdset(win_cmd, COLOR_PAIR(BLACK_ON_YELLOW));
	}

	wattroff(win_stat, A_UNDERLINE);
	wrefresh(win_cmd);
	display_unlock();
}
Exemplo n.º 5
0
void display_stats(void)
{
	display_lock();
	current_screen->draw_stats(&screen_state);
	display_stats_general();
	wrefresh(win_stat);
	display_unlock();
}
Exemplo n.º 6
0
int display_getch(void)
{
	int ret;

	display_lock();
	ret = wgetch(scr);
	display_unlock();

	return ret;
}
Exemplo n.º 7
0
static void stats_display_layout(uint8_t in_place)
{
	uint8_t cur_stats_height;

	cur_stats_height = current_screen->get_height();
	cur_stats_height = cur_stats_height > max_n_lines? max_n_lines: cur_stats_height;

	display_lock();
	if (!in_place) {
		// moving existing windows does not work
		delwin(win_txt);
		delwin(win_general);
		delwin(win_title);
		delwin(win_tabs);
		delwin(win_cmd);
		delwin(win_txt);
		delwin(win_help);

		clear();
	}

	if (!in_place) {
		win_stat = create_subwindow(cur_stats_height + 2, 0, 4, 0);
		win_tabs = create_subwindow(1, 0, 1, 0);
		win_general = create_subwindow(2, 0, 2, 0);
		win_title = create_subwindow(1, 0, 0, 0);
		win_cmd = create_subwindow(1, 0, cur_stats_height + 2 + 4,  0);
		win_txt_height = LINES - cur_stats_height - 2 - 3 - 3;
		win_txt = create_subwindow(win_txt_height, 0, cur_stats_height + 4 + 3, 0);
		win_help = create_subwindow(1, 0, LINES - 1, 0);
	}

	draw_title();
	draw_general_frame();
	/* Command line */
	wbkgd(win_cmd, COLOR_PAIR(BLACK_ON_YELLOW));
	idlok(win_cmd, FALSE);
	/* Move cursor at insertion point */
	leaveok(win_cmd, FALSE);

	draw_status_bar();
	draw_log_window();

	/* Draw everything to the screen */
	refresh();
	current_screen->draw_frame(&screen_state);
	display_unlock();

	refresh_cmd_win();
	display_stats();
}
Exemplo n.º 8
0
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Update render project on the render-server
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void Session::update(BufferParams& buffer_params) {
	// Block for buffer acces and reset immediately. we can't do this
	// in the thread, because we need to allocate an OpenGL buffer, and
	// that only works in the main thread
	thread_scoped_lock display_lock(display_mutex);
	thread_scoped_lock render_buffer_lock(render_buffer_mutex);

	display_outdated    = true;
	reset_time          = time_dt();

	reset_parameters(buffer_params);
    //server->update();
	pause_cond.notify_all();
} //update()
Exemplo n.º 9
0
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Reset all session data buffers
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void Session::reset(BufferParams& buffer_params, float mb_frame_time_sampling, float fps) {
	// Block for buffer acces and reset immediately. we can't do this
	// in the thread, because we need to allocate an OpenGL buffer, and
	// that only works in the main thread
	thread_scoped_lock display_lock(display_mutex);
	thread_scoped_lock render_buffer_lock(render_buffer_mutex);

	display_outdated    = true;
	reset_time          = time_dt();

	reset_parameters(buffer_params);
    server->reset(params.export_type, scene->kernel->uiGPUs, mb_frame_time_sampling, fps, params.deep_image);
	pause_cond.notify_all();
} //reset()
Exemplo n.º 10
0
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Interactive drawing
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool Session::draw(BufferParams& buffer_params) {
	// Block for display buffer access
	thread_scoped_lock display_lock(display_mutex);

    // First check we already rendered something
	// then verify the buffers have the expected size, so we don't
	// draw previous results in a resized window
	if(!buffer_params.modified(display->params)) {
		return display->draw();

		if(display_outdated)// && (time_dt() - reset_time) > params.text_timeout)
			return false;

		return true;
	}
	else return false;
} //draw()
Exemplo n.º 11
0
void display_print(const char *str)
{
	display_lock();

	if (scr == NULL) {
		fputs(str, stdout);
		fflush(stdout);
		display_unlock();
		return;
	}

	/* Check if the whole string can fit on the screen. */
	pages_len = strlen(str);
	int n_lines = 0;
	memset(pages, 0, sizeof(pages));
	memcpy(pages, str, pages_len);
	cur_idx = 0;
	for (size_t i = 0; i < pages_len; ++i) {
		if (pages[i] == '\n') {
			n_lines++;
			if (n_lines == win_txt_height - 2) {
				pages[i] = 0;
				cur_idx = i + 1;
				break;
			}
		}
	}

	waddstr(win_txt, pages);
	if (cur_idx != 0)
		waddstr(win_txt, "\nPRESS ENTER FOR MORE...\n");
	else
		pages_len = 0;

	wrefresh(win_txt);
	display_unlock();
}
Exemplo n.º 12
0
/*
 * Displays message(s) form publisher(s)
 */
void Subscriber::DisplayMessages()
{
    while(com_->Running())
    {
        boost::mutex::scoped_lock display_lock(message_mutex_);

        // wait until a message is read
        while (!com_->is_set_message())
        {
            com_->setting_message_condition()->wait(display_lock);
        }

        if (com_->Running())
        {
            // get message from com
            message_ = com_->message();

            // append this sub's id and this thread's id
            message_.append("to ");
            message_.append(id_);
            message_.append(" [thr_ID: ");
            message_.append(boost::lexical_cast<std::string>(boost::this_thread::get_id()));
            message_.append("]");

            // display message
            std::cout << message_ << std::endl;

            com_->set_is_picked_message(true);
            com_->set_is_set_message(false);
            com_->getting_message_condition()->notify_one();

            // re-initialise message
            message_ = "";
        }
    }
}
Exemplo n.º 13
0
int main (int argc, char **argv)
{
	SADisplay *display;
	VisVideo *video;

	VisInput *input;
	VisActor *actor;
	VisEventQueue *localqueue;
	VisVideoAttributeOptions *vidoptions;

	int running = TRUE;
	int fullscreen = FALSE;
	int visible = TRUE;

	int depth;

	//visual_mem_alloc_install_vtable (visual_mem_alloc_vtable_profile ());

	visual_init (&argc, &argv);

	display = display_new (sdl_driver_new ());

	/* Libvisual stuff */
	if (argc > 1)
		actor = visual_actor_new (argv[1]);
	else
		actor = visual_actor_new ("projectM");


	if (argc > 3) {
		depth = visual_video_depth_enum_from_value (atoi (argv[3]));
	} else
		depth = visual_video_depth_get_highest (visual_actor_get_supported_depth (actor));

	vidoptions = visual_actor_get_video_attribute_options (actor);

	display_create (display, depth, vidoptions, 480, 360, TRUE);

	visual_actor_realize (actor);

	video = display_get_video (display);

        visual_actor_set_video (actor, video);
	visual_actor_video_negotiate (actor, 0, FALSE, FALSE);

	if (argc > 2)
		input = visual_input_new (argv[2]);
	else
		input = visual_input_new ("alsa");

	visual_input_realize (input);

	localqueue = visual_event_queue_new ();

	while (running) {
		VisEventQueue *pluginqueue;
		VisEvent *ev;

		/* Handle all events */
		display_drain_events (display, localqueue);

		pluginqueue = visual_plugin_get_eventqueue (visual_actor_get_plugin (actor));
		while (visual_event_queue_poll_by_reference (localqueue, &ev)) {

			if (ev->type != VISUAL_EVENT_RESIZE)
				visual_event_queue_add (pluginqueue, ev);

			switch (ev->type) {
				case VISUAL_EVENT_RESIZE:
					video = display_get_video (display);
					visual_actor_set_video (actor, video);

					visual_actor_video_negotiate (actor, depth, FALSE, FALSE);
					break;

				case VISUAL_EVENT_MOUSEMOTION:
					break;

				case VISUAL_EVENT_MOUSEBUTTONDOWN:

					break;

				case VISUAL_EVENT_MOUSEBUTTONUP:
					break;

				case VISUAL_EVENT_KEYDOWN:
					switch (ev->event.keyboard.keysym.sym) {
						case VKEY_ESCAPE:
							running = FALSE;
							break;

						case VKEY_TAB:
							fullscreen = !fullscreen;

							display_set_fullscreen (display, fullscreen, TRUE);

							/* Resync video */
							video = display_get_video (display);
							visual_actor_set_video (actor, video);

							visual_actor_video_negotiate (actor, depth, FALSE, FALSE);

							break;

						default:
							printf ("key: %c\n", ev->event.keyboard.keysym.sym);
							break;
					}

					break;

				case VISUAL_EVENT_KEYUP:
					break;

				case VISUAL_EVENT_QUIT:
					running = FALSE;
					break;

				case VISUAL_EVENT_VISIBILITY:
					visible = ev->event.visibility.is_visible;
					break;

				default:
					break;
			}
		}

		if (visible == FALSE) {
			visual_input_run (input);

			visual_time_usleep (10000);

			continue;
		}

		/* Do a run cycle */
		visual_input_run (input);

		display_lock (display);
		visual_actor_run (actor, input->audio);
		display_unlock (display);

		display_update_all (display);

		display_fps_limit (display, 30);
	}

	/* Termination procedure */
	display_set_fullscreen (display, FALSE, TRUE);
	display_close (display);

	visual_quit ();

	//visual_mem_alloc_profile ();

	printf ("Total frames: %d, average fps: %f\n", display_fps_total (display), display_fps_average (display));

	return 0;
}
Exemplo n.º 14
0
static void
game_update_full (bool wait)
{
  const int max_fps = 16;
  const int32_t frame_duration = 1000 / max_fps;

  static int32_t last_frame_ticks;
  int32_t start_ticks;

  display_unlock ();

  sound_update ();
  display_update ();
  game_handle_sdl_events ();

  start_ticks = SDL_GetTicks ();

  if (wait && last_frame_ticks != 0)
    {
      int32_t last_frame_duration;

      last_frame_duration = (int32_t) (start_ticks - last_frame_ticks + 2);

      if (last_frame_duration < frame_duration)
	{
	  int32_t total_sleep_time = frame_duration - last_frame_duration;
	  const int32_t min_sleep_time = 1000 / 40;
	  const int32_t max_sleep_time = 1000 / 20;

	  total_sleep_time = frame_duration - last_frame_duration;

	  if (total_sleep_time > 0)
	    {
	      float f = (float) total_sleep_time
			* (min_sleep_time + max_sleep_time)
			/ (2 * min_sleep_time * max_sleep_time);
	      int32_t base_sleep_time = (int32_t) (total_sleep_time / f + .5f);

	      while (total_sleep_time > 0)
		{
		  int32_t sleep_time = MIN (base_sleep_time, total_sleep_time);
		  int32_t ticks = SDL_GetTicks ();

		  SDL_Delay (sleep_time);

		  display_lock ();
		  game_handle_sdl_events ();
		  sound_update ();
		  display_unlock ();

		  display_update_mouse_pointer ();

		  total_sleep_time -= SDL_GetTicks () - ticks;
		}
	    }
	}
    }

  last_frame_ticks = SDL_GetTicks ();

  display_lock ();
}
Exemplo n.º 15
0
Arquivo: io.c Projeto: Fornax/RS485
void io_loop() {
	
	//Button decrement
	if ( BTN_DEC == 1u && old_btn_dec == 0u && cnt_dec == 0u ) {
		cnt_dec= 100;
		old_btn_dec= 1u;
		display_on(); //Show current address
	} else 	if ( BTN_DEC == 0u && old_btn_dec == 1u && cnt_dec == 0u ) {
		cnt_dec= 100;
		old_btn_dec= 0u;
		delay_unlock= 0u; //Reset unlocking time
		
		if (old_btn_inc == 0u) {
			if (!btn_ignore) {
				display_dec();
			}
			btn_ignore= 0u;
		} else {
			btn_ignore= 1u;
		}
	}
	//Button increment
	if ( BTN_INC == 1u && old_btn_inc == 0u && cnt_inc == 0u ) {
		cnt_inc= 100;
		old_btn_inc= 1u;
		display_on(); //Show current address
	} else if ( BTN_INC == 0u && old_btn_inc == 1u && cnt_inc == 0u ) {
		cnt_inc= 100;
		old_btn_inc= 0u;
		delay_unlock= 0u; //Reset unlocking time
		
		if (old_btn_dec == 0u) {
			if (!btn_ignore) {
				display_inc();
			}
			btn_ignore= 0u;
		} else {
			btn_ignore= 1u;
		}
	}
	
	//Input buttons
	if ( buttons_input == 0u && (INPUT1 == 0u && INPUT2 == 0u) && cnt_input == 0u ) {
		cnt_input= 100;
		buttons_input= 1u;
	} else if (buttons_input == 1u && (INPUT1 != 0u || INPUT2 != 0u) && cnt_input == 0u ) {
		cnt_input= 100;
		buttons_input= 0u;
		if (INPUT1&0x01) {inputs=9;}
		if (INPUT1&0x02) {inputs=8;}
		if (INPUT1&0x04) {inputs=7;}
		if (INPUT1&0x08) {inputs=6;}
		if (INPUT1&0x10) {inputs=5;}
		if (INPUT1&0x20) {inputs=4;}
		if (INPUT2&0x01) {inputs=3;}
		if (INPUT2&0x02) {inputs=2;}
		if (INPUT2&0x04) {inputs=1;}
	}
	//Input capture
	if ( CAPT1 == 1u && capt1 == 0u && cnt_capt == 0u ) {
		cnt_capt= 100;
		capt1= 1;
	} else if ( CAPT1 == 0u && capt1 == 1u && cnt_capt == 0u ) {
		cnt_capt= 100;
		capt1= 0;
		puls_counter++;
	}
	//both switches pressed
	if ( BTN_INC != 0u && BTN_DEC != 0u ) {
		if (cnt_dec == 0u && cnt_inc == 0u && delay_unlock == 0u) {
			delay_unlock= 2000;
		}
		
		//Unlock up/down counting.
		if (cnt_dec == 0u && cnt_inc == 0u && delay_unlock <= 200u) {
			display_unlock();
		}
	}
	
	//Display on
	if ( BTN_INC != 0u || BTN_DEC != 0u) {
		delay_off= 3000;
	}
	
	//Display off
	if ( delay_off == 0u ) {
		display_lock();
	}
}
Exemplo n.º 16
0
int main(void)
{
    int mode = 0;

    /* enable interrupts (on the CPU) */
    init_interrupts();

    /* Initialize peripherals */
    display_init( RESOLUTION_320x240, DEPTH_16_BPP, 2, GAMMA_NONE, ANTIALIAS_RESAMPLE );
    dfs_init( DFS_DEFAULT_LOCATION );
    rdp_init();
    controller_init();
    timer_init();

    /* Read in single sprite */
    int fp = dfs_open("/mudkip.sprite");
    sprite_t *mudkip = malloc( dfs_size( fp ) );
    dfs_read( mudkip, 1, dfs_size( fp ), fp );
    dfs_close( fp );
    
    fp = dfs_open("/earthbound.sprite");
    sprite_t *earthbound = malloc( dfs_size( fp ) );
    dfs_read( earthbound, 1, dfs_size( fp ), fp );
    dfs_close( fp );

    fp = dfs_open("/plane.sprite");
    sprite_t *plane = malloc( dfs_size( fp ) );
    dfs_read( plane, 1, dfs_size( fp ), fp );
    dfs_close( fp );

    /* Kick off animation update timer to fire thirty times a second */
    new_timer(TIMER_TICKS(1000000 / 30), TF_CONTINUOUS, update_counter);

    /* Main loop test */
    while(1) 
    {
        static display_context_t disp = 0;

        /* Grab a render buffer */
        while( !(disp = display_lock()) );
       
        /*Fill the screen */
        graphics_fill_screen( disp, 0xFFFFFFFF );

        /* Set the text output color */
        graphics_set_color( 0x0, 0xFFFFFFFF );
    
        switch( mode )
        {
            case 0:
                /* Software spritemap test */
                graphics_draw_text( disp, 20, 20, "Software spritemap test" );

                /* Display a stationary sprite of adequate size to fit in TMEM */
                graphics_draw_sprite_trans( disp, 20, 50, plane );

                /* Display a stationary sprite to demonstrate backwards compatibility */
                graphics_draw_sprite_trans( disp, 50, 50, mudkip );

                /* Display walking NESS animation */
                graphics_draw_sprite_stride( disp, 20, 100, earthbound, ((animcounter / 15) & 1) ? 1: 0 );

                /* Display rotating NESS animation */
                graphics_draw_sprite_stride( disp, 50, 100, earthbound, ((animcounter / 8) & 0x7) * 2 );

                break;
            case 1:
            {
                /* Hardware spritemap test */
                graphics_draw_text( disp, 20, 20, "Hardware spritemap test" );

                /* Assure RDP is ready for new commands */
                rdp_sync( SYNC_PIPE );

                /* Remove any clipping windows */
                rdp_set_default_clipping();

                /* Enable sprite display instead of solid color fill */
                rdp_enable_texture_copy();

                /* Attach RDP to display */
                rdp_attach_display( disp );
                    
                /* Ensure the RDP is ready to receive sprites */
                rdp_sync( SYNC_PIPE );

                /* Load the sprite into texture slot 0, at the beginning of memory, without mirroring */
                rdp_load_texture( 0, 0, MIRROR_DISABLED, plane );
                
                /* Display a stationary sprite of adequate size to fit in TMEM */
                rdp_draw_sprite( 0, 20, 50 );

                /* Since the RDP is very very limited in texture memory, we will use the spritemap feature to display
                   all four pieces of this sprite individually in order to use the RDP at all */
                for( int i = 0; i < 4; i++ )
                {
                    /* Ensure the RDP is ready to receive sprites */
                    rdp_sync( SYNC_PIPE );

                    /* Load the sprite into texture slot 0, at the beginning of memory, without mirroring */
                    rdp_load_texture_stride( 0, 0, MIRROR_DISABLED, mudkip, i );
                
                    /* Display a stationary sprite to demonstrate backwards compatibility */
                    rdp_draw_sprite( 0, 50 + (20 * (i % 2)), 50 + (20 * (i / 2)) );
                }

                /* Ensure the RDP is ready to receive sprites */
                rdp_sync( SYNC_PIPE );

                /* Load the sprite into texture slot 0, at the beginning of memory, without mirroring */
                rdp_load_texture_stride( 0, 0, MIRROR_DISABLED, earthbound, ((animcounter / 15) & 1) ? 1: 0 );
                
                /* Display walking NESS animation */
                rdp_draw_sprite( 0, 20, 100 );

                /* Ensure the RDP is ready to receive sprites */
                rdp_sync( SYNC_PIPE );

                /* Load the sprite into texture slot 0, at the beginning of memory, without mirroring */
                rdp_load_texture_stride( 0, 0, MIRROR_DISABLED, earthbound, ((animcounter / 8) & 0x7) * 2 );
                
                /* Display rotating NESS animation */
                rdp_draw_sprite( 0, 50, 100 );

                /* Inform the RDP we are finished drawing and that any pending operations should be flushed */
                rdp_detach_display();

                break;
            }
        }

        /* Force backbuffer flip */
        display_show(disp);

        /* Do we need to switch video displays? */
        controller_scan();
        struct controller_data keys = get_keys_down();

        if( keys.c[0].A )
        {
            /* Lazy switching */
            mode = 1 - mode;
        }
    }
}