Ejemplo n.º 1
0
/* Initialization for data that needs other units */
static void
conn_init1(void)
{
  set_var_str(&conn_unit, "version", rcsid);
  conn_main();
  add_event_handler(CE_DATA, &data_handler, "data_handler", NULL);
  add_event_handler(CE_TIMER, &timer_handler, "timer_handler", NULL);
  Debug_unit(&conn_unit, "Initialized.");
}
Ejemplo n.º 2
0
/**
 * Updates our command to @a new_command.
 */
void wml_menu_item::update_command(const config & new_command)
{
	// If there is an old command, remove it from the event handlers.
	if ( !command_.empty() ) {
		manager::iteration iter(event_name_);
		while ( handler_ptr hand = *iter ) {
			if ( hand->is_menu_item() ) {
				LOG_NG << "Removing command for " << event_name_ << ".\n";
				remove_event_handler(command_["id"].str());
			}
			++iter;
		}
	}

	// Update our stored command.
	if ( new_command.empty() )
		command_.clear();
	else {
		command_ = new_command;

		// Set some fields required by event processing.
		config::attribute_value & event_id = command_["id"];
		if ( event_id.empty() && !item_id_.empty() ) {
			event_id = item_id_;
		}
		command_["name"] = event_name_;
		command_["first_time_only"] = false;

		// Register the event.
		LOG_NG << "Setting command for " << event_name_ << " to:\n" << command_;
		add_event_handler(command_, true);
	}
}
Ejemplo n.º 3
0
void manager::read_scenario(const config& scenario_cfg)
{
	BOOST_FOREACH(const config &ev, scenario_cfg.child_range("event")) {
		add_event_handler(ev);
	}
	BOOST_FOREACH(const std::string &id, utils::split(scenario_cfg["unit_wml_ids"])) {
		unit_wml_ids_.insert(id);
	}
Ejemplo n.º 4
0
/**
 * Initializes the implicit event handler for an inlined [command].
 */
void wml_menu_item::init_handler() const
{
	// If this menu item has a [command], add a handler for it.
	if ( !command_.empty() )
		add_event_handler(command_, true);

	// Hotkey support
	if ( use_hotkey_ ) {
		hotkey::add_wml_hotkey(hotkey_id_, description_, default_hotkey_);
	}
}
Ejemplo n.º 5
0
void manager::read_scenario(const config& scenario_cfg)
{
	for(const config &ev : scenario_cfg.child_range("event")) {
		add_event_handler(ev);
	}
	for(const std::string &id : utils::split(scenario_cfg["unit_wml_ids"])) {
		unit_wml_ids_.insert(id);
	}

	wml_menu_items_.set_menu_items(scenario_cfg);
	// Create the event handlers for menu items.
	wml_menu_items_.init_handlers();
}
Ejemplo n.º 6
0
void manager::add_events(const config::const_child_itors &cfgs, const std::string& type)
{
	if(!type.empty()) {
		if(std::find(unit_wml_ids_.begin(),unit_wml_ids_.end(),type) != unit_wml_ids_.end()) return;
		unit_wml_ids_.insert(type);
	}
	for(const config &new_ev : cfgs) {
		if(type.empty() && new_ev["id"].empty())
		{
			WRN_NG << "attempt to add an [event] with empty id=, ignoring " << std::endl;
			continue;
		}
		add_event_handler(new_ev);
	}
}
Ejemplo n.º 7
0
manager::manager(const config& cfg, const boost::shared_ptr<t_context> & res)
	: event_handlers_(new t_event_handlers())
	, unit_wml_ids_()
	, used_items_()
	, pump_(new game_events::t_pump(*this, res))
	, resources_(res)
	, wml_menu_items_()
	, me_(boost::make_shared<manager * const>(this))
{
	wml_menu_items_.set_menu_items(cfg);
	BOOST_FOREACH(const config &ev, cfg.child_range("event")) {
		add_event_handler(ev);
	}
	BOOST_FOREACH(const std::string &id, utils::split(cfg["unit_wml_ids"])) {
		unit_wml_ids_.insert(id);
	}
Ejemplo n.º 8
0
   // Video thread
   void Scheduler::video_thread_fn()
   {
      auto vid = GL::shared(file->video().width, file->video().height, file->video().aspect_ratio, file->video().ctx->pix_fmt);
      video = vid;
      auto event = GLEvent::shared();

      if (file->sub().active)
         sub_renderer = ASSRenderer::shared(file->sub().fonts, file->sub().ass_data, file->video().width, file->video().height);

      AVFrame *frame = avcodec_alloc_frame();

      // Add event handler for GL.
      add_event_handler(event);

      while (video_thread_active && vid_pkt_queue.alive())
      {
         event->poll(); 
         avlock.lock();
         if (vid_pkt_queue.size() > 0 && !is_paused)
         {
            auto pkt = vid_pkt_queue.pull();
            avlock.unlock();
            process_video(pkt.get(), vid, frame);

            if (file->sub().active)
               process_subtitle(vid);

            // We have to calculate how long we should wait before swapping frame to screen.
            // We sync everything to audio clock.
            double delta = get_time();

            avlock.lock();
            delta -= audio_pts_ts;
            double sleep_time = video_pts - (audio_pts + delta);
            avlock.unlock();

            // Yes, it can happen! :(
            if (delta < 0.0)
               delta = 0.0;
            //std::cout << "Delta: " << delta << std::endl;

            if (video_pts > (audio_pts + delta) && audio_thread_active)
            {
               double last_frame_delta = get_time();
               last_frame_delta -= video_pts_ts;

               // :(
               if (last_frame_delta < 0.0)
                  last_frame_delta = 0.0;

               // We try to keep the sleep time to a somewhat small value to avoid choppy video in some cases.
               // Max sleep time should be a bit over 1 frame time to allow audio to catch up.
               double max_sleep = 1.2 * frame_time() - last_frame_delta;

               if (max_sleep < 0.0)
                  max_sleep = 0.0;

               if (sleep_time > max_sleep)
               {
                  sleep_time = max_sleep;
               }
               //std::cout << "Sleep for " << sleep_time << std::endl;
               sync_sleep(sleep_time);
            }

            video_pts_ts = get_time();
            vid->flip();
         }
         else
         {
            avlock.unlock();

            if (is_paused)
               sync_sleep(0.01);
            else
            {
               // Having some race conditions... quickfix it for now.
               vid_pkt_queue.wait();
               //sync_sleep(0.01);
               //vid_pkt_queue.signal();
            }
         }
      }
      video_thread_active = false;
      av_free(frame);
   }