⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 timelines.cpp

📁 彩信浏览器
💻 CPP
📖 第 1 页 / 共 2 页
字号:
}#endifvoidtimeline_node::build_index(detail::dependency_index_generator& indexer){	std::vector<timeline_node_transition*>::iterator trans;		for(trans=m_transitions.begin(); trans<m_transitions.end(); trans++) {		(*trans)->build_index(indexer);	}}void timeline_node::build_actions(detail::active_action_vector& actions,		detail::dependency_index_generator& indexer, int node_index){	std::vector<timeline_node_transition*>::iterator trans;		for(trans=m_transitions.begin(); trans<m_transitions.end(); trans++) {		(*trans)->build_actions(actions, indexer, node_index);	}}inttimeline_node::get_playdone_index(detail::dependency_index_generator& indexer, int node_index){	detail::timeline_event done_event = detail::timeline_event(DONE_PLAY_RENDERER, 			static_cast<detail::event_uid>(m_node));	return indexer.get_index(done_event);}void timeline_node::build_dependencies(detail::active_dependency_vector& dependencies){	std::vector<timeline_node_transition*>::iterator trans;		for(trans=m_transitions.begin(); trans<m_transitions.end(); trans++) {		(*trans)->build_dependencies(dependencies);	}}/* ---------------- */const int START_PREROLL_TIMELINE_INDEX = 0;const int START_PLAY_TIMELINE_INDEX = 1;const int DONE_PLAY_TIMELINE_INDEX = 2;passive_timeline::passive_timeline(lib::node *rootnode):	m_rootnode(rootnode),	m_is_built(0),	m_playdone_indices(NULL){	// Initial transitions. Note that there is interaction	// between this code and the preroll(), start() and methods	// of the active_timeline: those expect the events to	// be at locations 0 and 1 of the dependecy vector.	// This may need rethinking at some point		timeline_node *outer = add_node(NULL);	timeline_node_transition *tmp = outer->add_transition();	tmp->add_lhs(START_PREROLL_TIMELINE);	tmp->add_rhs(START_PREROLL, rootnode);	tmp = outer->add_transition();	tmp->add_lhs(START_PLAY_TIMELINE);	tmp->add_rhs(START_PLAY, rootnode);		// XXXX Or should we add the DONE_PLAY_TIMELINE dummy event?	tmp = outer->add_transition();	tmp->add_lhs(DONE_PLAY, rootnode);}passive_timeline::~passive_timeline(){	if (m_playdone_indices)		delete m_playdone_indices;	m_playdone_indices = NULL;}timeline_node *passive_timeline::add_node(const lib::node *the_node){	timeline_node *rv = new timeline_node(the_node);	m_timeline_nodes.push_back(rv);	return rv;}timeline_delay *passive_timeline::add_delay(int timeout){	timeline_delay *rv = new timeline_delay(timeout);	m_delays.push_back(rv);	return rv;}void passive_timeline::build(){	detail::dependency_index_generator indexer;	detail::timeline_node_vector::iterator node;	// Step one - Give each (event_class, id) tuple use on a LHS	// a unique sequence number.	for(node=m_timeline_nodes.begin(); node < m_timeline_nodes.end(); node++) {		(*node)->build_index(indexer);	}//	indexer.dump();	// Step two - Flatten all events on the RHS into a long	// list. The transitions will remember begin- and end positions in	// this list, and fill m_playdone_indices with a mapping from node numbers	// to PLAYDONE_EVENT index numbers	m_playdone_indices = new int[m_timeline_nodes.size()];//(-1);	for(size_t i=0;i<m_timeline_nodes.size();i++) m_playdone_indices[i] = -1;	for(node=m_timeline_nodes.begin(); node < m_timeline_nodes.end(); node++) {		int node_index = (int)(node - m_timeline_nodes.begin());		(*node)->build_actions(m_actions, indexer, node_index);		int playdone_index = (*node)->get_playdone_index(indexer, node_index);		m_playdone_indices[node_index] = playdone_index;	}	// Step three - Build the dependencies vector by collecting all	// the needed information from the transitions	for(node=m_timeline_nodes.begin(); node < m_timeline_nodes.end(); node++) {		(*node)->build_dependencies(m_dependencies);	}	m_is_built = true;}active_timeline *passive_timeline::activate(lib::event_processor *const evp, common::playable_factory *rf, common::layout_manager *lm){#ifndef AMBULANT_NO_IOSTREAMS	AM_DBG std::cout << "activate(), #dep=" << int(m_dependencies.size()) << " #act=" << int(m_actions.size()) << std::endl;#endif	return new active_timeline(evp, this, m_dependencies, m_actions, int(m_timeline_nodes.size()), rf, lm);}#ifndef AMBULANT_NO_IOSTREAMSvoid passive_timeline::dump(std::ostream& os){	detail::timeline_node_vector::iterator i;	detail::delay_vector::iterator j;	int num = 0;		os << "-------Passive timeline:"  << std::endl;	for(j=m_delays.begin(); j<m_delays.end(); j++)		os << (**j) << std::endl;	for(i=m_timeline_nodes.begin(); i<m_timeline_nodes.end(); i++)		(**i).dump(os, num);	os << "-------End of assive timeline:"  << std::endl;	}#endif/* ---------------- */active_timeline::active_timeline(lib::event_processor *const evp,	passive_timeline *const source, 	const detail::active_dependency_vector& dependencies,	const detail::active_action_vector& actions,	int nregion,	common::playable_factory *rf,	common::layout_manager *lm):	m_event_processor(evp),	m_playable_factory(rf),	m_source(source),	m_layout_manager(lm),	m_dependencies(dependencies),	m_actions(actions),	m_playables(std::vector<common::playable *>(nregion, (common::playable *)NULL)),	m_playdone(NULL){	m_source->add_ref();}voidactive_timeline::preroll(){	detail::active_dependency& dep = m_dependencies[START_PREROLL_TIMELINE_INDEX];	int i;		dep.m_depcount--;#ifndef AMBULANT_NO_IOSTREAMS	AM_DBG std::cout << "preroll: count=" << dep.m_depcount << std::endl;#endif	if (dep.m_depcount == 0) {		for (i=dep.m_first; i<dep.m_last; i++) {			m_actions[i]->fire(this);		}	}}voidactive_timeline::start(lib::event *playdone){	detail::active_dependency& dep = m_dependencies[START_PLAY_TIMELINE_INDEX];	int i;		m_playdone = playdone;	dep.m_depcount--;#ifndef AMBULANT_NO_IOSTREAMS	AM_DBG std::cout << "start: count=" << dep.m_depcount << std::endl;#endif	if (dep.m_depcount == 0) {		for (i=dep.m_first; i<dep.m_last; i++) {			m_actions[i]->fire(this);		}	}}voidactive_timeline::stop(){	std::vector<common::playable *>::iterator it;	for(it = m_playables.begin();it != m_playables.end();it++) {		if(*it != 0 && *it != &dead_playable) {			(*it)->stop();			(*it)->release();			(*it) = &dead_playable;		}	}}voidactive_timeline::pause(){	std::vector<common::playable *>::iterator it;	for(it = m_playables.begin();it != m_playables.end();it++) {		if(*it != 0 && *it != &dead_playable) {			(*it)->pause();		}	}}voidactive_timeline::resume(){	std::vector<common::playable *>::iterator it;	for(it = m_playables.begin();it != m_playables.end();it++) {		if(*it != 0 && *it != &dead_playable) {			(*it)->resume();		}	}}voidactive_timeline::dependency_callback(detail::dependency_callback_arg arg){	detail::active_dependency& dep = m_dependencies[arg];	int i;		dep.m_depcount--;#ifndef AMBULANT_NO_IOSTREAMS	AM_DBG std::cout << "active_timeline.dependency_callback(" << arg << ") -> " << dep.m_depcount << std::endl;#endif	if (dep.m_depcount == 0) {		for (i=dep.m_first; i<dep.m_last; i++) {			m_actions[i]->fire(this);		}	}	// And special-case the final event:	if (arg == DONE_PLAY_TIMELINE_INDEX) {#ifndef AMBULANT_NO_IOSTREAMS		AM_DBG std::cout << "DONE_PLAY_TIMELINE()" << std::endl;#endif		if (m_playdone) {#ifndef AMBULANT_NO_IOSTREAMS			AM_DBG std::cout << "firing playdone event to parent" << std::endl;#endif			m_event_processor->add_event(m_playdone, 0, lib::ep_low);		}		// Other cleanup	}}voidactive_timeline::ext_dependency_callback(detail::dependency_callback_arg arg){	m_actions[arg]->delayed_fire(this);}voidactive_timeline::ext_preroll(int node_index){	if (m_playables[node_index] == &dead_playable)		return;	if (m_playables[node_index] != NULL) {		return;	}	timeline_node *tln = m_source->m_timeline_nodes[node_index];	const lib::node *the_node = tln->m_node;	common::playable *pl = m_playable_factory->new_playable(		this, node_index, the_node, m_event_processor);	// Connect the playable/renderer to its output surface, if applicable	if (pl) {		common::renderer *rend = pl->get_renderer();		if (rend) {			common::surface *dest = m_layout_manager->get_surface(the_node);			rend->set_surface(dest);		}	}	m_playables[node_index] = pl;}voidactive_timeline::ext_play(int node_index){	if (m_playables[node_index] == NULL) {		ext_preroll(node_index);	}	if (m_playables[node_index] == &dead_playable) {		// It was STOPPLAY-ed before this PLAY came in.		// Fire the playdone event		lib::logger::get_logger()->error("Internal error: active_timeline::ext_play(%d) after ext_stop()!", node_index);	} else {		m_playables[node_index]->start(0);#if JACK_DEBUG_MOUSEREGIONS                // Temporary code to enable mous clicking in every second node played		static int counter;		if (counter++ & 1) m_playables[node_index]->wantclicks(true);#endif	}}voidactive_timeline::ext_stop(int node_index){	if (m_playables[node_index] == &dead_playable)		return;	if (m_playables[node_index]) {		m_playables[node_index]->stop();		m_playables[node_index]->release();	}	m_playables[node_index] = &dead_playable;}#ifndef AMBULANT_NO_IOSTREAMSvoid active_timeline::dump(std::ostream& os){		os << "dumping active timeline, #dep=" << int(m_dependencies.size()) << " #act=" << int(m_actions.size()) << std::endl;	detail::active_dependency_vector::iterator i;	int c;	for(c=0,i=m_dependencies.begin(); i<m_dependencies.end(); c++, i++)		os << "dep " << c << " " << *i << std::endl;	detail::active_action_vector::const_iterator j;	for(c=0, j=m_actions.begin(); j<m_actions.end(); c++, j++)		os << "act " << c << " " << **j << std::endl;}#endifvoid active_timeline::started(int n, double t){	AM_DBG lib::logger::get_logger()->debug("active_timeline::started(%d)", n);}void active_timeline::stopped(int n, double t){	// XXXX This should call dependency_callback(playdone_index)	int playdone_index = m_source->m_playdone_indices[n];	AM_DBG lib::logger::get_logger()->debug("active_timeline::stopped(%d) playdone %d", n, playdone_index);	if (playdone_index < 0)		lib::logger::get_logger()->fatal("active_timeline::stopped(node %d): playdone_index=%d", n, playdone_index);	typedef lib::scalar_arg_callback<active_timeline, detail::dependency_callback_arg> mycallback;	lib::event *e = new mycallback(this, &active_timeline::dependency_callback, playdone_index);	m_event_processor->add_event(e, 0, lib::ep_high);}void active_timeline::clicked(int n, double t){	AM_DBG lib::logger::get_logger()->debug("active_timeline::clicked(%d)", n);}} // namespace mms} // namespace ambulant

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -